Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python2..../compiler
File: future.py
"""Parser for future statements
[0] Fix | Delete
[1] Fix | Delete
"""
[2] Fix | Delete
[3] Fix | Delete
from compiler import ast, walk
[4] Fix | Delete
[5] Fix | Delete
def is_future(stmt):
[6] Fix | Delete
"""Return true if statement is a well-formed future statement"""
[7] Fix | Delete
if not isinstance(stmt, ast.From):
[8] Fix | Delete
return 0
[9] Fix | Delete
if stmt.modname == "__future__":
[10] Fix | Delete
return 1
[11] Fix | Delete
else:
[12] Fix | Delete
return 0
[13] Fix | Delete
[14] Fix | Delete
class FutureParser:
[15] Fix | Delete
[16] Fix | Delete
features = ("nested_scopes", "generators", "division",
[17] Fix | Delete
"absolute_import", "with_statement", "print_function",
[18] Fix | Delete
"unicode_literals")
[19] Fix | Delete
[20] Fix | Delete
def __init__(self):
[21] Fix | Delete
self.found = {} # set
[22] Fix | Delete
[23] Fix | Delete
def visitModule(self, node):
[24] Fix | Delete
stmt = node.node
[25] Fix | Delete
for s in stmt.nodes:
[26] Fix | Delete
if not self.check_stmt(s):
[27] Fix | Delete
break
[28] Fix | Delete
[29] Fix | Delete
def check_stmt(self, stmt):
[30] Fix | Delete
if is_future(stmt):
[31] Fix | Delete
for name, asname in stmt.names:
[32] Fix | Delete
if name in self.features:
[33] Fix | Delete
self.found[name] = 1
[34] Fix | Delete
else:
[35] Fix | Delete
raise SyntaxError, \
[36] Fix | Delete
"future feature %s is not defined" % name
[37] Fix | Delete
stmt.valid_future = 1
[38] Fix | Delete
return 1
[39] Fix | Delete
return 0
[40] Fix | Delete
[41] Fix | Delete
def get_features(self):
[42] Fix | Delete
"""Return list of features enabled by future statements"""
[43] Fix | Delete
return self.found.keys()
[44] Fix | Delete
[45] Fix | Delete
class BadFutureParser:
[46] Fix | Delete
"""Check for invalid future statements"""
[47] Fix | Delete
[48] Fix | Delete
def visitFrom(self, node):
[49] Fix | Delete
if hasattr(node, 'valid_future'):
[50] Fix | Delete
return
[51] Fix | Delete
if node.modname != "__future__":
[52] Fix | Delete
return
[53] Fix | Delete
raise SyntaxError, "invalid future statement " + repr(node)
[54] Fix | Delete
[55] Fix | Delete
def find_futures(node):
[56] Fix | Delete
p1 = FutureParser()
[57] Fix | Delete
p2 = BadFutureParser()
[58] Fix | Delete
walk(node, p1)
[59] Fix | Delete
walk(node, p2)
[60] Fix | Delete
return p1.get_features()
[61] Fix | Delete
[62] Fix | Delete
if __name__ == "__main__":
[63] Fix | Delete
import sys
[64] Fix | Delete
from compiler import parseFile, walk
[65] Fix | Delete
[66] Fix | Delete
for file in sys.argv[1:]:
[67] Fix | Delete
print file
[68] Fix | Delete
tree = parseFile(file)
[69] Fix | Delete
v = FutureParser()
[70] Fix | Delete
walk(tree, v)
[71] Fix | Delete
print v.found
[72] Fix | Delete
print
[73] Fix | Delete
[74] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function