diff options
-rwxr-xr-x | kpov_judge/kpov_random_helpers.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/kpov_judge/kpov_random_helpers.py b/kpov_judge/kpov_random_helpers.py index 5646897..aadce0b 100755 --- a/kpov_judge/kpov_random_helpers.py +++ b/kpov_judge/kpov_random_helpers.py @@ -105,6 +105,9 @@ with open('random_data/slovenian_surnames.txt') as f: def username_gen(r): return r.choice(names) + r.choice(surnames) + "{0}".format(r.randint(1, 99)) +def unknown_generator(r): + return '' + default_generators = { 'IP': lambda r: IPv4_addr_gen(r, IPv4_net_gen(r))[0], 'localnet': lambda r: IPv4_net_gen(r, min_hosts = r.randint(16, 250), local=True, multicast=False), @@ -115,15 +118,17 @@ default_generators = { 'short_text': lambda r: fortune(r, 40), 'hostname': lambda r: hostname_gen(r), None: lambda r: alnum_gen(r, 8), - '': '', + '': unknown_generator, } + def default_gen(userID, param_meta): r = random.Random(userID) params = dict() for name, meta in param_meta.iteritems(): if meta.get('generated', False): - params[name] = default_generators[meta.get('type', None)](r) + params[name] = default_generators( + meta.get('type', None), unknown_generator)(r) return params if __name__ == '__main__': |