diff options
author | Alex Xu <alex_y_xu@yahoo.ca> | 2013-08-18 21:55:02 -0400 |
---|---|---|
committer | Alex Xu <alex_y_xu@yahoo.ca> | 2013-08-18 21:55:02 -0400 |
commit | de844dacb31531781e9f97ec25a52ea246f1115b (patch) | |
tree | cb80fedc9f2f49f77f2974beb0c7a78342d17527 /unrpyc | |
parent | ce961bb5865b5d16d203365159ab173e67e34556 (diff) | |
download | html5ks-de844dacb31531781e9f97ec25a52ea246f1115b.tar.xz html5ks-de844dacb31531781e9f97ec25a52ea246f1115b.zip |
prep for i18n
Diffstat (limited to 'unrpyc')
-rw-r--r-- | unrpyc/Makefile | 4 | ||||
-rw-r--r-- | unrpyc/decompiler.py | 40 |
2 files changed, 24 insertions, 20 deletions
diff --git a/unrpyc/Makefile b/unrpyc/Makefile index ea97e56..b64bb22 100644 --- a/unrpyc/Makefile +++ b/unrpyc/Makefile @@ -1,6 +1,6 @@ gzip := $(shell ./find-gzip.sh) -all: script.json script.json.gz imachine.json imachine.json.gz imachine_replay.json imachine_replay.json.gz +all: script.json script.json.gz imachine.json imachine.json.gz imachine_replay.json imachine_replay.json.gz ui-strings.json ui-strings.json.gz %.json.gz: %.json $(gzip) -c $< > $@ @@ -27,7 +27,7 @@ test: all jshint --show-non-errors *.json install: all - install -t ../www/scripts script.json script.json.gz imachine.json imachine.json.gz imachine_replay.json imachine_replay.json.gz + install -t ../www/scripts script.json script.json.gz imachine.json imachine.json.gz imachine_replay.json imachine_replay.json.gz ui-strings.json ui-strings.json.gz uninstall: rm -f ../www/scripts/* diff --git a/unrpyc/decompiler.py b/unrpyc/decompiler.py index 75aced6..38fbd52 100644 --- a/unrpyc/decompiler.py +++ b/unrpyc/decompiler.py @@ -273,6 +273,13 @@ class PrintRenPython(python_ast.NodeVisitor): def visit_Attribute(self, node): return '"%s"' % node.attr + def visit_Assign(self, node): + if not isinstance(node.targets[0], python_ast.Subscript): + self.f.write(self.visit(node.targets[0])) + self.f.write(': ') + self.f.write(self.visit(node.value)) + self.f.write(',\n') + def visit_Call(self, node): self.f.write('[') self.f.write(self.visit(node.func)) @@ -295,6 +302,16 @@ class PrintRenPython(python_ast.NodeVisitor): def visit_Dict(self, node): return self.quote(python_ast.dump(node)) + def visit_List(self, node): + ret = '[' + delim = '' + for elt in node.elts: + ret += delim + ret += self.visit(elt) + delim = ',' + ret += ']' + return ret + def visit_Num(self, node): return json.dumps(node.n) @@ -304,6 +321,9 @@ class PrintRenPython(python_ast.NodeVisitor): def visit_Str(self, node): return json.dumps(node.s) + def visit_Tuple(self, node): + return self.visit_List(node) + def visit_keyword(self, node): return self.visit(node.value) @@ -312,20 +332,8 @@ def print_Python(f, stmt, indent_level, early=False): stripped_code = code_src.strip() - if stripped_code.count('\n') == 0: - stmt = compile(code_src, '<unknown>', 'exec', python_ast.PyCF_ONLY_AST).body[0] - PrintRenPython(f).visit(stmt) - else: - f.write("python") - if early: - f.write(" early") - if stmt.hide: - f.write(" hide") - f.write(":\n") - - for line in code_src.splitlines(True): - indent(f, indent_level + 1) - f.write(line) + stmt = compile(code_src, '<unknown>', 'exec', python_ast.PyCF_ONLY_AST) + PrintRenPython(f).visit(stmt) def print_Return(f, stmt, indent_level): if stmt.expression is not None: @@ -337,10 +345,6 @@ def print_UserStatement(f, stmt, indent_level): f.write('["%s"],\n' % (escape_string(stmt.line).replace(' ', '", "'), )) def print_Init(f, stmt, indent_level): - f.write("init") - if stmt.priority != 0: - f.write(" %d" % (stmt.priority, )) - f.write(":\n") for s in stmt.block: print_statement(f, s, indent_level + 1) |