eq(decision['path'], '/{bucket_readable}')
assert_raises(KeyError, lambda x: decision[x], 'key3')
+def test_expand_key():
+ prng = random.Random(1)
+ test_decision = {
+ 'key1': 'value1',
+ 'randkey': 'value-{random 10-15 printable}',
+ 'indirect': '{key1}',
+ 'dbl_indirect': '{indirect}'
+ }
+ decision = SpecialVariables(test_decision, prng)
+
+ randkey = expand_key(decision, 'randkey')
+ indirect = expand_key(decision, 'indirect')
+ dbl_indirect = expand_key(decision, 'dbl_indirect')
+
+ eq(indirect, 'value1')
+ eq(dbl_indirect, 'value1')
+ eq(randkey, 'value-[/pNI$;92@')
+
+def test_expand_loop():
+ prng = random.Random(1)
+ test_decision = {
+ 'key1': '{key2}',
+ 'key2': '{key1}',
+ }
+ decision = SpecialVariables(test_decision, prng)
+ assert_raises(RuntimeError, expand_key, decision, 'key1')
+
def test_expand_decision():
graph = build_graph()
prng = random.Random(1)
eq(request['key1'], 'value1')
eq(request['indirect_key1'], 'value1')
eq(request['path'], '/my-readable-bucket')
- eq(request['randkey'], 'value-?') #FIXME: again, how to handle the pseudorandom content?
+ eq(request['randkey'], 'value-NI$;92@H/0I') #FIXME: again, how to handle the pseudorandom content?
assert_raises(KeyError, lambda x: decision[x], 'key3')
from . import common
import traceback
+import itertools
import random
import string
import yaml
decision's values and headers until all values are fully expanded and
build a request out of the information
"""
- raise NotImplementedError
+ special_decision = SpecialVariables(decision, prng)
+ for key in special_decision:
+ decision[key] = expand_key(special_decision, key)
+
+ return decision
+
+
+def expand_key(decision, key):
+ c = itertools.count()
+ fmt = string.Formatter()
+ old = decision[key]
+ while True:
+ new = fmt.vformat(old, [], decision)
+ if new == old:
+ return old
+ if next(c) > 5:
+ raise RuntimeError
+ old = new
class SpecialVariables(dict):