Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/ExeBy/exe_root.../lib64/python2....
File: py_compile.py
"""Routine to "compile" a .py file to a .pyc (or .pyo) file.
[0] Fix | Delete
[1] Fix | Delete
This module has intimate knowledge of the format of .pyc files.
[2] Fix | Delete
"""
[3] Fix | Delete
[4] Fix | Delete
import __builtin__
[5] Fix | Delete
import imp
[6] Fix | Delete
import marshal
[7] Fix | Delete
import os
[8] Fix | Delete
import sys
[9] Fix | Delete
import traceback
[10] Fix | Delete
[11] Fix | Delete
MAGIC = imp.get_magic()
[12] Fix | Delete
[13] Fix | Delete
__all__ = ["compile", "main", "PyCompileError"]
[14] Fix | Delete
[15] Fix | Delete
[16] Fix | Delete
class PyCompileError(Exception):
[17] Fix | Delete
"""Exception raised when an error occurs while attempting to
[18] Fix | Delete
compile the file.
[19] Fix | Delete
[20] Fix | Delete
To raise this exception, use
[21] Fix | Delete
[22] Fix | Delete
raise PyCompileError(exc_type,exc_value,file[,msg])
[23] Fix | Delete
[24] Fix | Delete
where
[25] Fix | Delete
[26] Fix | Delete
exc_type: exception type to be used in error message
[27] Fix | Delete
type name can be accesses as class variable
[28] Fix | Delete
'exc_type_name'
[29] Fix | Delete
[30] Fix | Delete
exc_value: exception value to be used in error message
[31] Fix | Delete
can be accesses as class variable 'exc_value'
[32] Fix | Delete
[33] Fix | Delete
file: name of file being compiled to be used in error message
[34] Fix | Delete
can be accesses as class variable 'file'
[35] Fix | Delete
[36] Fix | Delete
msg: string message to be written as error message
[37] Fix | Delete
If no value is given, a default exception message will be given,
[38] Fix | Delete
consistent with 'standard' py_compile output.
[39] Fix | Delete
message (or default) can be accesses as class variable 'msg'
[40] Fix | Delete
[41] Fix | Delete
"""
[42] Fix | Delete
[43] Fix | Delete
def __init__(self, exc_type, exc_value, file, msg=''):
[44] Fix | Delete
exc_type_name = exc_type.__name__
[45] Fix | Delete
if exc_type is SyntaxError:
[46] Fix | Delete
tbtext = ''.join(traceback.format_exception_only(exc_type, exc_value))
[47] Fix | Delete
errmsg = tbtext.replace('File "<string>"', 'File "%s"' % file)
[48] Fix | Delete
else:
[49] Fix | Delete
errmsg = "Sorry: %s: %s" % (exc_type_name,exc_value)
[50] Fix | Delete
[51] Fix | Delete
Exception.__init__(self,msg or errmsg,exc_type_name,exc_value,file)
[52] Fix | Delete
[53] Fix | Delete
self.exc_type_name = exc_type_name
[54] Fix | Delete
self.exc_value = exc_value
[55] Fix | Delete
self.file = file
[56] Fix | Delete
self.msg = msg or errmsg
[57] Fix | Delete
[58] Fix | Delete
def __str__(self):
[59] Fix | Delete
return self.msg
[60] Fix | Delete
[61] Fix | Delete
[62] Fix | Delete
def wr_long(f, x):
[63] Fix | Delete
"""Internal; write a 32-bit int to a file in little-endian order."""
[64] Fix | Delete
f.write(chr( x & 0xff))
[65] Fix | Delete
f.write(chr((x >> 8) & 0xff))
[66] Fix | Delete
f.write(chr((x >> 16) & 0xff))
[67] Fix | Delete
f.write(chr((x >> 24) & 0xff))
[68] Fix | Delete
[69] Fix | Delete
def compile(file, cfile=None, dfile=None, doraise=False):
[70] Fix | Delete
"""Byte-compile one Python source file to Python bytecode.
[71] Fix | Delete
[72] Fix | Delete
Arguments:
[73] Fix | Delete
[74] Fix | Delete
file: source filename
[75] Fix | Delete
cfile: target filename; defaults to source with 'c' or 'o' appended
[76] Fix | Delete
('c' normally, 'o' in optimizing mode, giving .pyc or .pyo)
[77] Fix | Delete
dfile: purported filename; defaults to source (this is the filename
[78] Fix | Delete
that will show up in error messages)
[79] Fix | Delete
doraise: flag indicating whether or not an exception should be
[80] Fix | Delete
raised when a compile error is found. If an exception
[81] Fix | Delete
occurs and this flag is set to False, a string
[82] Fix | Delete
indicating the nature of the exception will be printed,
[83] Fix | Delete
and the function will return to the caller. If an
[84] Fix | Delete
exception occurs and this flag is set to True, a
[85] Fix | Delete
PyCompileError exception will be raised.
[86] Fix | Delete
[87] Fix | Delete
Note that it isn't necessary to byte-compile Python modules for
[88] Fix | Delete
execution efficiency -- Python itself byte-compiles a module when
[89] Fix | Delete
it is loaded, and if it can, writes out the bytecode to the
[90] Fix | Delete
corresponding .pyc (or .pyo) file.
[91] Fix | Delete
[92] Fix | Delete
However, if a Python installation is shared between users, it is a
[93] Fix | Delete
good idea to byte-compile all modules upon installation, since
[94] Fix | Delete
other users may not be able to write in the source directories,
[95] Fix | Delete
and thus they won't be able to write the .pyc/.pyo file, and then
[96] Fix | Delete
they would be byte-compiling every module each time it is loaded.
[97] Fix | Delete
This can slow down program start-up considerably.
[98] Fix | Delete
[99] Fix | Delete
See compileall.py for a script/module that uses this module to
[100] Fix | Delete
byte-compile all installed files (or all files in selected
[101] Fix | Delete
directories).
[102] Fix | Delete
[103] Fix | Delete
"""
[104] Fix | Delete
with open(file, 'U') as f:
[105] Fix | Delete
try:
[106] Fix | Delete
timestamp = long(os.fstat(f.fileno()).st_mtime)
[107] Fix | Delete
except AttributeError:
[108] Fix | Delete
timestamp = long(os.stat(file).st_mtime)
[109] Fix | Delete
codestring = f.read()
[110] Fix | Delete
try:
[111] Fix | Delete
codeobject = __builtin__.compile(codestring, dfile or file,'exec')
[112] Fix | Delete
except Exception,err:
[113] Fix | Delete
py_exc = PyCompileError(err.__class__, err, dfile or file)
[114] Fix | Delete
if doraise:
[115] Fix | Delete
raise py_exc
[116] Fix | Delete
else:
[117] Fix | Delete
sys.stderr.write(py_exc.msg + '\n')
[118] Fix | Delete
return
[119] Fix | Delete
if cfile is None:
[120] Fix | Delete
cfile = file + (__debug__ and 'c' or 'o')
[121] Fix | Delete
with open(cfile, 'wb') as fc:
[122] Fix | Delete
fc.write('\0\0\0\0')
[123] Fix | Delete
wr_long(fc, timestamp)
[124] Fix | Delete
marshal.dump(codeobject, fc)
[125] Fix | Delete
fc.flush()
[126] Fix | Delete
fc.seek(0, 0)
[127] Fix | Delete
fc.write(MAGIC)
[128] Fix | Delete
[129] Fix | Delete
def main(args=None):
[130] Fix | Delete
"""Compile several source files.
[131] Fix | Delete
[132] Fix | Delete
The files named in 'args' (or on the command line, if 'args' is
[133] Fix | Delete
not specified) are compiled and the resulting bytecode is cached
[134] Fix | Delete
in the normal manner. This function does not search a directory
[135] Fix | Delete
structure to locate source files; it only compiles files named
[136] Fix | Delete
explicitly. If '-' is the only parameter in args, the list of
[137] Fix | Delete
files is taken from standard input.
[138] Fix | Delete
[139] Fix | Delete
"""
[140] Fix | Delete
if args is None:
[141] Fix | Delete
args = sys.argv[1:]
[142] Fix | Delete
rv = 0
[143] Fix | Delete
if args == ['-']:
[144] Fix | Delete
while True:
[145] Fix | Delete
filename = sys.stdin.readline()
[146] Fix | Delete
if not filename:
[147] Fix | Delete
break
[148] Fix | Delete
filename = filename.rstrip('\n')
[149] Fix | Delete
try:
[150] Fix | Delete
compile(filename, doraise=True)
[151] Fix | Delete
except PyCompileError as error:
[152] Fix | Delete
rv = 1
[153] Fix | Delete
sys.stderr.write("%s\n" % error.msg)
[154] Fix | Delete
except IOError as error:
[155] Fix | Delete
rv = 1
[156] Fix | Delete
sys.stderr.write("%s\n" % error)
[157] Fix | Delete
else:
[158] Fix | Delete
for filename in args:
[159] Fix | Delete
try:
[160] Fix | Delete
compile(filename, doraise=True)
[161] Fix | Delete
except PyCompileError as error:
[162] Fix | Delete
# return value to indicate at least one failure
[163] Fix | Delete
rv = 1
[164] Fix | Delete
sys.stderr.write("%s\n" % error.msg)
[165] Fix | Delete
return rv
[166] Fix | Delete
[167] Fix | Delete
if __name__ == "__main__":
[168] Fix | Delete
sys.exit(main())
[169] Fix | Delete
[170] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function