g1 = m.group(1)
subx.append(g1)
ret = "[#%d]" % n
- # print "f1:", g1, ret
return ret
x = re.sub(r"[\['](\??\(.*?\))[\]']", f1, x)
# put expressions back
def f2(m):
g1 = m.group(1)
- # print "f2:", g1
return subx[int(g1)]
x = re.sub(r"#([0-9]+)", f2, x)
def trace(expr, obj, path):
if debug:
- print "trace", expr, "/", path
+ print("trace", expr, "/", path)
if expr:
x = expr.split(';')
loc = x[0]
x = ';'.join(x[1:])
if debug:
- print "\t", loc, type(obj)
+ print("\t", loc, type(obj))
if loc == "*":
def f03(key, loc, expr, obj, path):
if debug > 1:
- print "\tf03", key, loc, expr, path
+ print("\tf03", key, loc, expr, path)
trace(s(key, expr), obj, path)
walk(loc, x, obj, path, f03)
def f04(key, loc, expr, obj, path):
if debug > 1:
- print "\tf04", key, loc, expr, path
+ print("\tf04", key, loc, expr, path)
if isinstance(obj, dict):
if key in obj:
trace(s('..', expr), obj[key], s(path, key))
# [(index_expression)]
if loc.startswith("(") and loc.endswith(")"):
if debug > 1:
- print "index", loc
+ print("index", loc)
e = evalx(loc, obj)
trace(s(e, x), obj, path)
return
# ?(filter_expression)
if loc.startswith("?(") and loc.endswith(")"):
if debug > 1:
- print "filter", loc
+ print("filter", loc)
def f05(key, loc, expr, obj, path):
if debug > 1:
- print "f05", key, loc, expr, path
+ print("f05", key, loc, expr, path)
if isinstance(obj, dict):
eval_result = evalx(loc, obj[key])
else:
# [index,index....]
for piece in re.split(r"'?,'?", loc):
if debug > 1:
- print "piece", piece
+ print("piece", piece)
trace(s(piece, x), obj, path)
else:
store(path, obj)
"""eval expression"""
if debug:
- print "evalx", loc
+ print("evalx", loc)
# a nod to JavaScript. doesn't work for @.name.name.length
# Write len(@.name.name) instead!!!
loc = re.sub(r'(?<!\\)@', "__obj", loc).replace(r'\@', '@')
if not use_eval:
if debug:
- print "eval disabled"
+ print("eval disabled")
raise Exception("eval disabled")
if debug:
- print "eval", loc
+ print("eval", loc)
try:
# eval w/ caller globals, w/ local "__obj"!
v = eval(loc, caller_globals, {'__obj': obj})
- except Exception, e:
+ except Exception as e:
if debug:
- print e
- return False
+ print(e)
+ return False
if debug:
- print "->", v
+ print("->", v)
return v
# body of jsonpath()