Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../usr/lib64/python2..../lib2to3/fixes
File: fix_execfile.py
# Copyright 2006 Google, Inc. All Rights Reserved.
[0] Fix | Delete
# Licensed to PSF under a Contributor Agreement.
[1] Fix | Delete
[2] Fix | Delete
"""Fixer for execfile.
[3] Fix | Delete
[4] Fix | Delete
This converts usages of the execfile function into calls to the built-in
[5] Fix | Delete
exec() function.
[6] Fix | Delete
"""
[7] Fix | Delete
[8] Fix | Delete
from .. import fixer_base
[9] Fix | Delete
from ..fixer_util import (Comma, Name, Call, LParen, RParen, Dot, Node,
[10] Fix | Delete
ArgList, String, syms)
[11] Fix | Delete
[12] Fix | Delete
[13] Fix | Delete
class FixExecfile(fixer_base.BaseFix):
[14] Fix | Delete
BM_compatible = True
[15] Fix | Delete
[16] Fix | Delete
PATTERN = """
[17] Fix | Delete
power< 'execfile' trailer< '(' arglist< filename=any [',' globals=any [',' locals=any ] ] > ')' > >
[18] Fix | Delete
|
[19] Fix | Delete
power< 'execfile' trailer< '(' filename=any ')' > >
[20] Fix | Delete
"""
[21] Fix | Delete
[22] Fix | Delete
def transform(self, node, results):
[23] Fix | Delete
assert results
[24] Fix | Delete
filename = results["filename"]
[25] Fix | Delete
globals = results.get("globals")
[26] Fix | Delete
locals = results.get("locals")
[27] Fix | Delete
[28] Fix | Delete
# Copy over the prefix from the right parentheses end of the execfile
[29] Fix | Delete
# call.
[30] Fix | Delete
execfile_paren = node.children[-1].children[-1].clone()
[31] Fix | Delete
# Construct open().read().
[32] Fix | Delete
open_args = ArgList([filename.clone(), Comma(), String('"rb"', ' ')],
[33] Fix | Delete
rparen=execfile_paren)
[34] Fix | Delete
open_call = Node(syms.power, [Name(u"open"), open_args])
[35] Fix | Delete
read = [Node(syms.trailer, [Dot(), Name(u'read')]),
[36] Fix | Delete
Node(syms.trailer, [LParen(), RParen()])]
[37] Fix | Delete
open_expr = [open_call] + read
[38] Fix | Delete
# Wrap the open call in a compile call. This is so the filename will be
[39] Fix | Delete
# preserved in the execed code.
[40] Fix | Delete
filename_arg = filename.clone()
[41] Fix | Delete
filename_arg.prefix = u" "
[42] Fix | Delete
exec_str = String(u"'exec'", u" ")
[43] Fix | Delete
compile_args = open_expr + [Comma(), filename_arg, Comma(), exec_str]
[44] Fix | Delete
compile_call = Call(Name(u"compile"), compile_args, u"")
[45] Fix | Delete
# Finally, replace the execfile call with an exec call.
[46] Fix | Delete
args = [compile_call]
[47] Fix | Delete
if globals is not None:
[48] Fix | Delete
args.extend([Comma(), globals.clone()])
[49] Fix | Delete
if locals is not None:
[50] Fix | Delete
args.extend([Comma(), locals.clone()])
[51] Fix | Delete
return Call(Name(u"exec"), args, prefix=node.prefix)
[52] Fix | Delete
[53] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function