From aa6170a5655853a8e64375e7abca5845bc82bec3 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Thu, 21 Feb 2019 00:45:27 +0100 Subject: test_task: reorder helper functions --- kpov_judge/test_task.py | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/kpov_judge/test_task.py b/kpov_judge/test_task.py index ad8c963..4e9561f 100755 --- a/kpov_judge/test_task.py +++ b/kpov_judge/test_task.py @@ -64,20 +64,11 @@ def add_meta_to_argparser(argparser, meta, defaults={}): argparser.add_argument('--'+k, nargs='?', type=str, help=desc, default=defaults.get(k, None)) -def http_auth(url, username, password): - password_mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm() - password_mgr.add_password(None, url, username, password) - handler = urllib.request.HTTPBasicAuthHandler(password_mgr) - opener = urllib.request.build_opener(handler) - urllib.request.install_opener(opener) # now all calls to urlopen use our opener - -def load_task(stream): - # the stream should definitions for the functions task(…), - # task_check and gen_params, and a dictionary params_meta - source = stream.read() - d = {} - exec(compile(source, 'task.py', 'exec'), globals(), d) - return d['task'], d['task_check'], d['params_meta'], d['gen_params'] +def load_params(filename): + try: + return yaml.load(open(filename)) + except: + return {} def locate_task(params, argparser, quiet=False): # first the URL where all tasks are stored @@ -104,11 +95,19 @@ def locate_task(params, argparser, quiet=False): print() return params -def load_params(filename): - try: - return yaml.load(open(filename)) - except: - return {} +def http_auth(url, username, password): + password_mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm() + password_mgr.add_password(None, url, username, password) + handler = urllib.request.HTTPBasicAuthHandler(password_mgr) + opener = urllib.request.build_opener(handler) + urllib.request.install_opener(opener) # now all calls to urlopen use our opener + +def load_task(stream): + # the stream should definitions for the functions task(…), + # task_check and gen_params, and a dictionary params_meta + d = {} + exec(compile(source, 'task.py', 'exec'), globals(), d) + return d['task'], d['task_check'], d['params_meta'], d['gen_params'] if __name__ == '__main__': -- cgit v1.2.1