New DatabaseReader reads ledger numbers from database.

This commit is contained in:
Tom Ritchford
2014-09-24 13:01:22 -04:00
committed by Vinnie Falco
parent 6069400538
commit f54280aaad
10 changed files with 349 additions and 16 deletions

View File

@@ -20,7 +20,10 @@ REMAPPINGS = {
}
def eval_arguments(args):
tokens = tokenize.generate_tokens(StringIO(args or '()').readline)
args = args.strip()
if not args or (args == '()'):
return ()
tokens = list(tokenize.generate_tokens(StringIO(args).readline))
def remap():
for type, name, _, _, _ in tokens:
if type == tokenize.NAME and name not in REMAPPINGS:
@@ -30,7 +33,11 @@ def eval_arguments(args):
untok = tokenize.untokenize(remap())
if untok[1:-1].strip():
untok = untok[:-1] + ',)' # Force a tuple.
return eval(untok, REMAPPINGS)
try:
return eval(untok, REMAPPINGS)
except Exception as e:
raise ValueError('Couldn\'t evaluate expression "%s" (became "%s"), '
'error "%s"' % (args, untok, str(e)))
class Function(object):
def __init__(self, desc='', default_path=''):