Skip to content

Commit

Permalink
Mistakes were made
Browse files Browse the repository at this point in the history
  • Loading branch information
Xyene committed Jul 31, 2016
1 parent 2c706d4 commit fc3029b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
46 changes: 24 additions & 22 deletions dmoj/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class ConfigNode(object):
node.test_cases[0].batched[1].output_prefix_length == 0
"""

def __init__(self, raw_config=None, parent=None, defaults=None):
def __init__(self, raw_config=None, parent=None, defaults=None, dynamic=True):
self.dynamic = dynamic
if defaults:
self.raw_config = defaults
self.raw_config.update(raw_config or {})
Expand Down Expand Up @@ -78,27 +79,28 @@ def __getattr__(self, item):

def __getitem__(self, item):
try:
def run_dynamic_key(dynamic_key, run_func):
# Wrap in a ConfigNode so dynamic keys can benefit from the nice features of ConfigNode
local = {'node': ConfigNode(self.raw_config.get(item, {}), self)}
try:
cfg = run_func(self.raw_config[dynamic_key], local)
except Exception as e:
import traceback

traceback.print_exc()
raise InvalidInitException('exception executing dynamic key ' + str(dynamic_key) + ': ' + e.message)
del self.raw_config[dynamic_key]
self.raw_config[item] = cfg

if item + '++' in self.raw_config:
def full(code, local):
exec code in local
return local['node']

run_dynamic_key(item + '++', full)
elif item + '+' in self.raw_config:
run_dynamic_key(item + '+', lambda code, local: eval(code, local))
if self.dynamic:
def run_dynamic_key(dynamic_key, run_func):
# Wrap in a ConfigNode so dynamic keys can benefit from the nice features of ConfigNode
local = {'node': ConfigNode(self.raw_config.get(item, {}), self)}
try:
cfg = run_func(self.raw_config[dynamic_key], local)
except Exception as e:
import traceback

traceback.print_exc()
raise InvalidInitException('exception executing dynamic key ' + str(dynamic_key) + ': ' + e.message)
del self.raw_config[dynamic_key]
self.raw_config[item] = cfg

if item + '++' in self.raw_config:
def full(code, local):
exec code in local
return local['node']

run_dynamic_key(item + '++', full)
elif item + '+' in self.raw_config:
run_dynamic_key(item + '+', lambda code, local: eval(code, local))
cfg = self.raw_config[item]

if isinstance(cfg, list) or isinstance(cfg, dict):
Expand Down
2 changes: 1 addition & 1 deletion dmoj/judgeenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
env = ConfigNode(defaults={
'selftest_sandboxing': True,
'runtime': {},
})
}, dynamic=False)
_root = os.path.dirname(__file__)
fs_encoding = os.environ.get('DMOJ_ENCODING', sys.getfilesystemencoding())

Expand Down

0 comments on commit fc3029b

Please sign in to comment.