added utility method to replace execfile for python2/3 support
This commit is contained in:
parent
ca28920e2d
commit
05c6233908
2 changed files with 22 additions and 1 deletions
|
@ -859,7 +859,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
thread = threading.Thread(
|
thread = threading.Thread(
|
||||||
target=execfile,
|
target=utils.execute_file,
|
||||||
args=(file_name, {"__file__": file_name, "coreemu": self.coreemu})
|
args=(file_name, {"__file__": file_name, "coreemu": self.coreemu})
|
||||||
)
|
)
|
||||||
thread.daemon = True
|
thread.daemon = True
|
||||||
|
|
|
@ -18,6 +18,27 @@ from core import CoreCommandError
|
||||||
DEVNULL = open(os.devnull, "wb")
|
DEVNULL = open(os.devnull, "wb")
|
||||||
|
|
||||||
|
|
||||||
|
def execute_file(path, exec_globals=None, exec_locals=None):
|
||||||
|
"""
|
||||||
|
Provides an alternative way to run execfile to be compatible for
|
||||||
|
both python2/3.
|
||||||
|
|
||||||
|
:param str path: path of file to execute
|
||||||
|
:param dict exec_globals: globals values to pass to execution
|
||||||
|
:param dict exec_locals: local values to pass to execution
|
||||||
|
:return: nothing
|
||||||
|
"""
|
||||||
|
if exec_globals is None:
|
||||||
|
exec_globals = {}
|
||||||
|
exec_globals.update({
|
||||||
|
"__file__": path,
|
||||||
|
"__name__": "__main__"
|
||||||
|
})
|
||||||
|
with open(path, "rb") as f:
|
||||||
|
data = compile(f.read(), path, "exec")
|
||||||
|
exec(data, exec_globals, exec_locals)
|
||||||
|
|
||||||
|
|
||||||
def hashkey(value):
|
def hashkey(value):
|
||||||
"""
|
"""
|
||||||
Provide a consistent hash that can be used in place
|
Provide a consistent hash that can be used in place
|
||||||
|
|
Loading…
Add table
Reference in a new issue