Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python3....
File: imp.py
"""This module provides the components needed to build your own __import__
[0] Fix | Delete
function. Undocumented functions are obsolete.
[1] Fix | Delete
[2] Fix | Delete
In most cases it is preferred you consider using the importlib module's
[3] Fix | Delete
functionality over this module.
[4] Fix | Delete
[5] Fix | Delete
"""
[6] Fix | Delete
# (Probably) need to stay in _imp
[7] Fix | Delete
from _imp import (lock_held, acquire_lock, release_lock,
[8] Fix | Delete
get_frozen_object, is_frozen_package,
[9] Fix | Delete
init_frozen, is_builtin, is_frozen,
[10] Fix | Delete
_fix_co_filename)
[11] Fix | Delete
try:
[12] Fix | Delete
from _imp import create_dynamic
[13] Fix | Delete
except ImportError:
[14] Fix | Delete
# Platform doesn't support dynamic loading.
[15] Fix | Delete
create_dynamic = None
[16] Fix | Delete
[17] Fix | Delete
from importlib._bootstrap import _ERR_MSG, _exec, _load, _builtin_from_name
[18] Fix | Delete
from importlib._bootstrap_external import SourcelessFileLoader
[19] Fix | Delete
[20] Fix | Delete
from importlib import machinery
[21] Fix | Delete
from importlib import util
[22] Fix | Delete
import importlib
[23] Fix | Delete
import os
[24] Fix | Delete
import sys
[25] Fix | Delete
import tokenize
[26] Fix | Delete
import types
[27] Fix | Delete
import warnings
[28] Fix | Delete
[29] Fix | Delete
warnings.warn("the imp module is deprecated in favour of importlib; "
[30] Fix | Delete
"see the module's documentation for alternative uses",
[31] Fix | Delete
DeprecationWarning, stacklevel=2)
[32] Fix | Delete
[33] Fix | Delete
# DEPRECATED
[34] Fix | Delete
SEARCH_ERROR = 0
[35] Fix | Delete
PY_SOURCE = 1
[36] Fix | Delete
PY_COMPILED = 2
[37] Fix | Delete
C_EXTENSION = 3
[38] Fix | Delete
PY_RESOURCE = 4
[39] Fix | Delete
PKG_DIRECTORY = 5
[40] Fix | Delete
C_BUILTIN = 6
[41] Fix | Delete
PY_FROZEN = 7
[42] Fix | Delete
PY_CODERESOURCE = 8
[43] Fix | Delete
IMP_HOOK = 9
[44] Fix | Delete
[45] Fix | Delete
[46] Fix | Delete
def new_module(name):
[47] Fix | Delete
"""**DEPRECATED**
[48] Fix | Delete
[49] Fix | Delete
Create a new module.
[50] Fix | Delete
[51] Fix | Delete
The module is not entered into sys.modules.
[52] Fix | Delete
[53] Fix | Delete
"""
[54] Fix | Delete
return types.ModuleType(name)
[55] Fix | Delete
[56] Fix | Delete
[57] Fix | Delete
def get_magic():
[58] Fix | Delete
"""**DEPRECATED**
[59] Fix | Delete
[60] Fix | Delete
Return the magic number for .pyc files.
[61] Fix | Delete
"""
[62] Fix | Delete
return util.MAGIC_NUMBER
[63] Fix | Delete
[64] Fix | Delete
[65] Fix | Delete
def get_tag():
[66] Fix | Delete
"""Return the magic tag for .pyc files."""
[67] Fix | Delete
return sys.implementation.cache_tag
[68] Fix | Delete
[69] Fix | Delete
[70] Fix | Delete
def cache_from_source(path, debug_override=None):
[71] Fix | Delete
"""**DEPRECATED**
[72] Fix | Delete
[73] Fix | Delete
Given the path to a .py file, return the path to its .pyc file.
[74] Fix | Delete
[75] Fix | Delete
The .py file does not need to exist; this simply returns the path to the
[76] Fix | Delete
.pyc file calculated as if the .py file were imported.
[77] Fix | Delete
[78] Fix | Delete
If debug_override is not None, then it must be a boolean and is used in
[79] Fix | Delete
place of sys.flags.optimize.
[80] Fix | Delete
[81] Fix | Delete
If sys.implementation.cache_tag is None then NotImplementedError is raised.
[82] Fix | Delete
[83] Fix | Delete
"""
[84] Fix | Delete
with warnings.catch_warnings():
[85] Fix | Delete
warnings.simplefilter('ignore')
[86] Fix | Delete
return util.cache_from_source(path, debug_override)
[87] Fix | Delete
[88] Fix | Delete
[89] Fix | Delete
def source_from_cache(path):
[90] Fix | Delete
"""**DEPRECATED**
[91] Fix | Delete
[92] Fix | Delete
Given the path to a .pyc. file, return the path to its .py file.
[93] Fix | Delete
[94] Fix | Delete
The .pyc file does not need to exist; this simply returns the path to
[95] Fix | Delete
the .py file calculated to correspond to the .pyc file. If path does
[96] Fix | Delete
not conform to PEP 3147 format, ValueError will be raised. If
[97] Fix | Delete
sys.implementation.cache_tag is None then NotImplementedError is raised.
[98] Fix | Delete
[99] Fix | Delete
"""
[100] Fix | Delete
return util.source_from_cache(path)
[101] Fix | Delete
[102] Fix | Delete
[103] Fix | Delete
def get_suffixes():
[104] Fix | Delete
"""**DEPRECATED**"""
[105] Fix | Delete
extensions = [(s, 'rb', C_EXTENSION) for s in machinery.EXTENSION_SUFFIXES]
[106] Fix | Delete
source = [(s, 'r', PY_SOURCE) for s in machinery.SOURCE_SUFFIXES]
[107] Fix | Delete
bytecode = [(s, 'rb', PY_COMPILED) for s in machinery.BYTECODE_SUFFIXES]
[108] Fix | Delete
[109] Fix | Delete
return extensions + source + bytecode
[110] Fix | Delete
[111] Fix | Delete
[112] Fix | Delete
class NullImporter:
[113] Fix | Delete
[114] Fix | Delete
"""**DEPRECATED**
[115] Fix | Delete
[116] Fix | Delete
Null import object.
[117] Fix | Delete
[118] Fix | Delete
"""
[119] Fix | Delete
[120] Fix | Delete
def __init__(self, path):
[121] Fix | Delete
if path == '':
[122] Fix | Delete
raise ImportError('empty pathname', path='')
[123] Fix | Delete
elif os.path.isdir(path):
[124] Fix | Delete
raise ImportError('existing directory', path=path)
[125] Fix | Delete
[126] Fix | Delete
def find_module(self, fullname):
[127] Fix | Delete
"""Always returns None."""
[128] Fix | Delete
return None
[129] Fix | Delete
[130] Fix | Delete
[131] Fix | Delete
class _HackedGetData:
[132] Fix | Delete
[133] Fix | Delete
"""Compatibility support for 'file' arguments of various load_*()
[134] Fix | Delete
functions."""
[135] Fix | Delete
[136] Fix | Delete
def __init__(self, fullname, path, file=None):
[137] Fix | Delete
super().__init__(fullname, path)
[138] Fix | Delete
self.file = file
[139] Fix | Delete
[140] Fix | Delete
def get_data(self, path):
[141] Fix | Delete
"""Gross hack to contort loader to deal w/ load_*()'s bad API."""
[142] Fix | Delete
if self.file and path == self.path:
[143] Fix | Delete
if not self.file.closed:
[144] Fix | Delete
file = self.file
[145] Fix | Delete
else:
[146] Fix | Delete
self.file = file = open(self.path, 'r')
[147] Fix | Delete
[148] Fix | Delete
with file:
[149] Fix | Delete
# Technically should be returning bytes, but
[150] Fix | Delete
# SourceLoader.get_code() just passed what is returned to
[151] Fix | Delete
# compile() which can handle str. And converting to bytes would
[152] Fix | Delete
# require figuring out the encoding to decode to and
[153] Fix | Delete
# tokenize.detect_encoding() only accepts bytes.
[154] Fix | Delete
return file.read()
[155] Fix | Delete
else:
[156] Fix | Delete
return super().get_data(path)
[157] Fix | Delete
[158] Fix | Delete
[159] Fix | Delete
class _LoadSourceCompatibility(_HackedGetData, machinery.SourceFileLoader):
[160] Fix | Delete
[161] Fix | Delete
"""Compatibility support for implementing load_source()."""
[162] Fix | Delete
[163] Fix | Delete
[164] Fix | Delete
def load_source(name, pathname, file=None):
[165] Fix | Delete
loader = _LoadSourceCompatibility(name, pathname, file)
[166] Fix | Delete
spec = util.spec_from_file_location(name, pathname, loader=loader)
[167] Fix | Delete
if name in sys.modules:
[168] Fix | Delete
module = _exec(spec, sys.modules[name])
[169] Fix | Delete
else:
[170] Fix | Delete
module = _load(spec)
[171] Fix | Delete
# To allow reloading to potentially work, use a non-hacked loader which
[172] Fix | Delete
# won't rely on a now-closed file object.
[173] Fix | Delete
module.__loader__ = machinery.SourceFileLoader(name, pathname)
[174] Fix | Delete
module.__spec__.loader = module.__loader__
[175] Fix | Delete
return module
[176] Fix | Delete
[177] Fix | Delete
[178] Fix | Delete
class _LoadCompiledCompatibility(_HackedGetData, SourcelessFileLoader):
[179] Fix | Delete
[180] Fix | Delete
"""Compatibility support for implementing load_compiled()."""
[181] Fix | Delete
[182] Fix | Delete
[183] Fix | Delete
def load_compiled(name, pathname, file=None):
[184] Fix | Delete
"""**DEPRECATED**"""
[185] Fix | Delete
loader = _LoadCompiledCompatibility(name, pathname, file)
[186] Fix | Delete
spec = util.spec_from_file_location(name, pathname, loader=loader)
[187] Fix | Delete
if name in sys.modules:
[188] Fix | Delete
module = _exec(spec, sys.modules[name])
[189] Fix | Delete
else:
[190] Fix | Delete
module = _load(spec)
[191] Fix | Delete
# To allow reloading to potentially work, use a non-hacked loader which
[192] Fix | Delete
# won't rely on a now-closed file object.
[193] Fix | Delete
module.__loader__ = SourcelessFileLoader(name, pathname)
[194] Fix | Delete
module.__spec__.loader = module.__loader__
[195] Fix | Delete
return module
[196] Fix | Delete
[197] Fix | Delete
[198] Fix | Delete
def load_package(name, path):
[199] Fix | Delete
"""**DEPRECATED**"""
[200] Fix | Delete
if os.path.isdir(path):
[201] Fix | Delete
extensions = (machinery.SOURCE_SUFFIXES[:] +
[202] Fix | Delete
machinery.BYTECODE_SUFFIXES[:])
[203] Fix | Delete
for extension in extensions:
[204] Fix | Delete
init_path = os.path.join(path, '__init__' + extension)
[205] Fix | Delete
if os.path.exists(init_path):
[206] Fix | Delete
path = init_path
[207] Fix | Delete
break
[208] Fix | Delete
else:
[209] Fix | Delete
raise ValueError('{!r} is not a package'.format(path))
[210] Fix | Delete
spec = util.spec_from_file_location(name, path,
[211] Fix | Delete
submodule_search_locations=[])
[212] Fix | Delete
if name in sys.modules:
[213] Fix | Delete
return _exec(spec, sys.modules[name])
[214] Fix | Delete
else:
[215] Fix | Delete
return _load(spec)
[216] Fix | Delete
[217] Fix | Delete
[218] Fix | Delete
def load_module(name, file, filename, details):
[219] Fix | Delete
"""**DEPRECATED**
[220] Fix | Delete
[221] Fix | Delete
Load a module, given information returned by find_module().
[222] Fix | Delete
[223] Fix | Delete
The module name must include the full package name, if any.
[224] Fix | Delete
[225] Fix | Delete
"""
[226] Fix | Delete
suffix, mode, type_ = details
[227] Fix | Delete
if mode and (not mode.startswith(('r', 'U')) or '+' in mode):
[228] Fix | Delete
raise ValueError('invalid file open mode {!r}'.format(mode))
[229] Fix | Delete
elif file is None and type_ in {PY_SOURCE, PY_COMPILED}:
[230] Fix | Delete
msg = 'file object required for import (type code {})'.format(type_)
[231] Fix | Delete
raise ValueError(msg)
[232] Fix | Delete
elif type_ == PY_SOURCE:
[233] Fix | Delete
return load_source(name, filename, file)
[234] Fix | Delete
elif type_ == PY_COMPILED:
[235] Fix | Delete
return load_compiled(name, filename, file)
[236] Fix | Delete
elif type_ == C_EXTENSION and load_dynamic is not None:
[237] Fix | Delete
if file is None:
[238] Fix | Delete
with open(filename, 'rb') as opened_file:
[239] Fix | Delete
return load_dynamic(name, filename, opened_file)
[240] Fix | Delete
else:
[241] Fix | Delete
return load_dynamic(name, filename, file)
[242] Fix | Delete
elif type_ == PKG_DIRECTORY:
[243] Fix | Delete
return load_package(name, filename)
[244] Fix | Delete
elif type_ == C_BUILTIN:
[245] Fix | Delete
return init_builtin(name)
[246] Fix | Delete
elif type_ == PY_FROZEN:
[247] Fix | Delete
return init_frozen(name)
[248] Fix | Delete
else:
[249] Fix | Delete
msg = "Don't know how to import {} (type code {})".format(name, type_)
[250] Fix | Delete
raise ImportError(msg, name=name)
[251] Fix | Delete
[252] Fix | Delete
[253] Fix | Delete
def find_module(name, path=None):
[254] Fix | Delete
"""**DEPRECATED**
[255] Fix | Delete
[256] Fix | Delete
Search for a module.
[257] Fix | Delete
[258] Fix | Delete
If path is omitted or None, search for a built-in, frozen or special
[259] Fix | Delete
module and continue search in sys.path. The module name cannot
[260] Fix | Delete
contain '.'; to search for a submodule of a package, pass the
[261] Fix | Delete
submodule name and the package's __path__.
[262] Fix | Delete
[263] Fix | Delete
"""
[264] Fix | Delete
if not isinstance(name, str):
[265] Fix | Delete
raise TypeError("'name' must be a str, not {}".format(type(name)))
[266] Fix | Delete
elif not isinstance(path, (type(None), list)):
[267] Fix | Delete
# Backwards-compatibility
[268] Fix | Delete
raise RuntimeError("'path' must be None or a list, "
[269] Fix | Delete
"not {}".format(type(path)))
[270] Fix | Delete
[271] Fix | Delete
if path is None:
[272] Fix | Delete
if is_builtin(name):
[273] Fix | Delete
return None, None, ('', '', C_BUILTIN)
[274] Fix | Delete
elif is_frozen(name):
[275] Fix | Delete
return None, None, ('', '', PY_FROZEN)
[276] Fix | Delete
else:
[277] Fix | Delete
path = sys.path
[278] Fix | Delete
[279] Fix | Delete
for entry in path:
[280] Fix | Delete
package_directory = os.path.join(entry, name)
[281] Fix | Delete
for suffix in ['.py', machinery.BYTECODE_SUFFIXES[0]]:
[282] Fix | Delete
package_file_name = '__init__' + suffix
[283] Fix | Delete
file_path = os.path.join(package_directory, package_file_name)
[284] Fix | Delete
if os.path.isfile(file_path):
[285] Fix | Delete
return None, package_directory, ('', '', PKG_DIRECTORY)
[286] Fix | Delete
for suffix, mode, type_ in get_suffixes():
[287] Fix | Delete
file_name = name + suffix
[288] Fix | Delete
file_path = os.path.join(entry, file_name)
[289] Fix | Delete
if os.path.isfile(file_path):
[290] Fix | Delete
break
[291] Fix | Delete
else:
[292] Fix | Delete
continue
[293] Fix | Delete
break # Break out of outer loop when breaking out of inner loop.
[294] Fix | Delete
else:
[295] Fix | Delete
raise ImportError(_ERR_MSG.format(name), name=name)
[296] Fix | Delete
[297] Fix | Delete
encoding = None
[298] Fix | Delete
if 'b' not in mode:
[299] Fix | Delete
with open(file_path, 'rb') as file:
[300] Fix | Delete
encoding = tokenize.detect_encoding(file.readline)[0]
[301] Fix | Delete
file = open(file_path, mode, encoding=encoding)
[302] Fix | Delete
return file, file_path, (suffix, mode, type_)
[303] Fix | Delete
[304] Fix | Delete
[305] Fix | Delete
def reload(module):
[306] Fix | Delete
"""**DEPRECATED**
[307] Fix | Delete
[308] Fix | Delete
Reload the module and return it.
[309] Fix | Delete
[310] Fix | Delete
The module must have been successfully imported before.
[311] Fix | Delete
[312] Fix | Delete
"""
[313] Fix | Delete
return importlib.reload(module)
[314] Fix | Delete
[315] Fix | Delete
[316] Fix | Delete
def init_builtin(name):
[317] Fix | Delete
"""**DEPRECATED**
[318] Fix | Delete
[319] Fix | Delete
Load and return a built-in module by name, or None is such module doesn't
[320] Fix | Delete
exist
[321] Fix | Delete
"""
[322] Fix | Delete
try:
[323] Fix | Delete
return _builtin_from_name(name)
[324] Fix | Delete
except ImportError:
[325] Fix | Delete
return None
[326] Fix | Delete
[327] Fix | Delete
[328] Fix | Delete
if create_dynamic:
[329] Fix | Delete
def load_dynamic(name, path, file=None):
[330] Fix | Delete
"""**DEPRECATED**
[331] Fix | Delete
[332] Fix | Delete
Load an extension module.
[333] Fix | Delete
"""
[334] Fix | Delete
import importlib.machinery
[335] Fix | Delete
loader = importlib.machinery.ExtensionFileLoader(name, path)
[336] Fix | Delete
[337] Fix | Delete
# Issue #24748: Skip the sys.modules check in _load_module_shim;
[338] Fix | Delete
# always load new extension
[339] Fix | Delete
spec = importlib.machinery.ModuleSpec(
[340] Fix | Delete
name=name, loader=loader, origin=path)
[341] Fix | Delete
return _load(spec)
[342] Fix | Delete
[343] Fix | Delete
else:
[344] Fix | Delete
load_dynamic = None
[345] Fix | Delete
[346] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function