From 0c8f41f02553a420cf6f2824bb31573ef0f9ac1b Mon Sep 17 00:00:00 2001 From: "gasperfele@fri1.uni-lj.si" Date: Tue, 20 Jan 2015 07:11:26 +0000 Subject: Added unknown_generator for default_generator git-svn-id: https://svn.lusy.fri.uni-lj.si/kpov-public-svn/kpov-public@220 5cf9fbd1-b2bc-434c-b4b7-e852f4f63414 --- kpov_judge/kpov_random_helpers.py | 9 +++++++-- 1 file 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__': -- cgit v1.2.1