Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python
- """
- Usage: cat [infile] | python deanon.py > [outfile]
- Anonymous functions will be renamed to anon_[lineno]_*
- where * is a number that gets incremented for each functionon the line
- """
- from sys import stdin, stdout, stderr, argv
- import re
- if len(argv) > 1:
- lines = open(argv[1]).readlines()
- out = open(argv[1], 'w')
- else:
- lines = stdin.readlines()
- out = stdout
- x = {}
- x["anon_count"] = 0
- def make_repl_func(lineno):
- x["anon_line_count"] = 0
- def create_id(match):
- unique_id = str(lineno + 1) + "_" + str(x["anon_line_count"])
- x["anon_line_count"] += 1
- x["anon_count"] += 1
- return "function anon_%s(" % unique_id
- return create_id
- for lineno, line in enumerate(lines):
- out.write(re.sub("function *\(", make_repl_func(lineno), line))
- stderr.write("De-anonymized %d functions.\n" % x["anon_count"])
Advertisement
Add Comment
Please, Sign In to add comment