Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/imh-pyth.../lib/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
# The contract of get_data() requires us to return bytes. Reopen the
[144] Fix | Delete
# file in binary mode if needed.
[145] Fix | Delete
if not self.file.closed:
[146] Fix | Delete
file = self.file
[147] Fix | Delete
if 'b' not in file.mode:
[148] Fix | Delete
file.close()
[149] Fix | Delete
if self.file.closed:
[150] Fix | Delete
self.file = file = open(self.path, 'rb')
[151] Fix | Delete
[152] Fix | Delete
with file:
[153] Fix | Delete
return file.read()
[154] Fix | Delete
else:
[155] Fix | Delete
return super().get_data(path)
[156] Fix | Delete
[157] Fix | Delete
[158] Fix | Delete
class _LoadSourceCompatibility(_HackedGetData, machinery.SourceFileLoader):
[159] Fix | Delete
[160] Fix | Delete
"""Compatibility support for implementing load_source()."""
[161] Fix | Delete
[162] Fix | Delete
[163] Fix | Delete
def load_source(name, pathname, file=None):
[164] Fix | Delete
loader = _LoadSourceCompatibility(name, pathname, file)
[165] Fix | Delete
spec = util.spec_from_file_location(name, pathname, loader=loader)
[166] Fix | Delete
if name in sys.modules:
[167] Fix | Delete
module = _exec(spec, sys.modules[name])
[168] Fix | Delete
else:
[169] Fix | Delete
module = _load(spec)
[170] Fix | Delete
# To allow reloading to potentially work, use a non-hacked loader which
[171] Fix | Delete
# won't rely on a now-closed file object.
[172] Fix | Delete
module.__loader__ = machinery.SourceFileLoader(name, pathname)
[173] Fix | Delete
module.__spec__.loader = module.__loader__
[174] Fix | Delete
return module
[175] Fix | Delete
[176] Fix | Delete
[177] Fix | Delete
class _LoadCompiledCompatibility(_HackedGetData, SourcelessFileLoader):
[178] Fix | Delete
[179] Fix | Delete
"""Compatibility support for implementing load_compiled()."""
[180] Fix | Delete
[181] Fix | Delete
[182] Fix | Delete
def load_compiled(name, pathname, file=None):
[183] Fix | Delete
"""**DEPRECATED**"""
[184] Fix | Delete
loader = _LoadCompiledCompatibility(name, pathname, file)
[185] Fix | Delete
spec = util.spec_from_file_location(name, pathname, loader=loader)
[186] Fix | Delete
if name in sys.modules:
[187] Fix | Delete
module = _exec(spec, sys.modules[name])
[188] Fix | Delete
else:
[189] Fix | Delete
module = _load(spec)
[190] Fix | Delete
# To allow reloading to potentially work, use a non-hacked loader which
[191] Fix | Delete
# won't rely on a now-closed file object.
[192] Fix | Delete
module.__loader__ = SourcelessFileLoader(name, pathname)
[193] Fix | Delete
module.__spec__.loader = module.__loader__
[194] Fix | Delete
return module
[195] Fix | Delete
[196] Fix | Delete
[197] Fix | Delete
def load_package(name, path):
[198] Fix | Delete
"""**DEPRECATED**"""
[199] Fix | Delete
if os.path.isdir(path):
[200] Fix | Delete
extensions = (machinery.SOURCE_SUFFIXES[:] +
[201] Fix | Delete
machinery.BYTECODE_SUFFIXES[:])
[202] Fix | Delete
for extension in extensions:
[203] Fix | Delete
init_path = os.path.join(path, '__init__' + extension)
[204] Fix | Delete
if os.path.exists(init_path):
[205] Fix | Delete
path = init_path
[206] Fix | Delete
break
[207] Fix | Delete
else:
[208] Fix | Delete
raise ValueError('{!r} is not a package'.format(path))
[209] Fix | Delete
spec = util.spec_from_file_location(name, path,
[210] Fix | Delete
submodule_search_locations=[])
[211] Fix | Delete
if name in sys.modules:
[212] Fix | Delete
return _exec(spec, sys.modules[name])
[213] Fix | Delete
else:
[214] Fix | Delete
return _load(spec)
[215] Fix | Delete
[216] Fix | Delete
[217] Fix | Delete
def load_module(name, file, filename, details):
[218] Fix | Delete
"""**DEPRECATED**
[219] Fix | Delete
[220] Fix | Delete
Load a module, given information returned by find_module().
[221] Fix | Delete
[222] Fix | Delete
The module name must include the full package name, if any.
[223] Fix | Delete
[224] Fix | Delete
"""
[225] Fix | Delete
suffix, mode, type_ = details
[226] Fix | Delete
if mode and (not mode.startswith(('r', 'U')) or '+' in mode):
[227] Fix | Delete
raise ValueError('invalid file open mode {!r}'.format(mode))
[228] Fix | Delete
elif file is None and type_ in {PY_SOURCE, PY_COMPILED}:
[229] Fix | Delete
msg = 'file object required for import (type code {})'.format(type_)
[230] Fix | Delete
raise ValueError(msg)
[231] Fix | Delete
elif type_ == PY_SOURCE:
[232] Fix | Delete
return load_source(name, filename, file)
[233] Fix | Delete
elif type_ == PY_COMPILED:
[234] Fix | Delete
return load_compiled(name, filename, file)
[235] Fix | Delete
elif type_ == C_EXTENSION and load_dynamic is not None:
[236] Fix | Delete
if file is None:
[237] Fix | Delete
with open(filename, 'rb') as opened_file:
[238] Fix | Delete
return load_dynamic(name, filename, opened_file)
[239] Fix | Delete
else:
[240] Fix | Delete
return load_dynamic(name, filename, file)
[241] Fix | Delete
elif type_ == PKG_DIRECTORY:
[242] Fix | Delete
return load_package(name, filename)
[243] Fix | Delete
elif type_ == C_BUILTIN:
[244] Fix | Delete
return init_builtin(name)
[245] Fix | Delete
elif type_ == PY_FROZEN:
[246] Fix | Delete
return init_frozen(name)
[247] Fix | Delete
else:
[248] Fix | Delete
msg = "Don't know how to import {} (type code {})".format(name, type_)
[249] Fix | Delete
raise ImportError(msg, name=name)
[250] Fix | Delete
[251] Fix | Delete
[252] Fix | Delete
def find_module(name, path=None):
[253] Fix | Delete
"""**DEPRECATED**
[254] Fix | Delete
[255] Fix | Delete
Search for a module.
[256] Fix | Delete
[257] Fix | Delete
If path is omitted or None, search for a built-in, frozen or special
[258] Fix | Delete
module and continue search in sys.path. The module name cannot
[259] Fix | Delete
contain '.'; to search for a submodule of a package, pass the
[260] Fix | Delete
submodule name and the package's __path__.
[261] Fix | Delete
[262] Fix | Delete
"""
[263] Fix | Delete
if not isinstance(name, str):
[264] Fix | Delete
raise TypeError("'name' must be a str, not {}".format(type(name)))
[265] Fix | Delete
elif not isinstance(path, (type(None), list)):
[266] Fix | Delete
# Backwards-compatibility
[267] Fix | Delete
raise RuntimeError("'path' must be None or a list, "
[268] Fix | Delete
"not {}".format(type(path)))
[269] Fix | Delete
[270] Fix | Delete
if path is None:
[271] Fix | Delete
if is_builtin(name):
[272] Fix | Delete
return None, None, ('', '', C_BUILTIN)
[273] Fix | Delete
elif is_frozen(name):
[274] Fix | Delete
return None, None, ('', '', PY_FROZEN)
[275] Fix | Delete
else:
[276] Fix | Delete
path = sys.path
[277] Fix | Delete
[278] Fix | Delete
for entry in path:
[279] Fix | Delete
package_directory = os.path.join(entry, name)
[280] Fix | Delete
for suffix in ['.py', machinery.BYTECODE_SUFFIXES[0]]:
[281] Fix | Delete
package_file_name = '__init__' + suffix
[282] Fix | Delete
file_path = os.path.join(package_directory, package_file_name)
[283] Fix | Delete
if os.path.isfile(file_path):
[284] Fix | Delete
return None, package_directory, ('', '', PKG_DIRECTORY)
[285] Fix | Delete
for suffix, mode, type_ in get_suffixes():
[286] Fix | Delete
file_name = name + suffix
[287] Fix | Delete
file_path = os.path.join(entry, file_name)
[288] Fix | Delete
if os.path.isfile(file_path):
[289] Fix | Delete
break
[290] Fix | Delete
else:
[291] Fix | Delete
continue
[292] Fix | Delete
break # Break out of outer loop when breaking out of inner loop.
[293] Fix | Delete
else:
[294] Fix | Delete
raise ImportError(_ERR_MSG.format(name), name=name)
[295] Fix | Delete
[296] Fix | Delete
encoding = None
[297] Fix | Delete
if 'b' not in mode:
[298] Fix | Delete
with open(file_path, 'rb') as file:
[299] Fix | Delete
encoding = tokenize.detect_encoding(file.readline)[0]
[300] Fix | Delete
file = open(file_path, mode, encoding=encoding)
[301] Fix | Delete
return file, file_path, (suffix, mode, type_)
[302] Fix | Delete
[303] Fix | Delete
[304] Fix | Delete
def reload(module):
[305] Fix | Delete
"""**DEPRECATED**
[306] Fix | Delete
[307] Fix | Delete
Reload the module and return it.
[308] Fix | Delete
[309] Fix | Delete
The module must have been successfully imported before.
[310] Fix | Delete
[311] Fix | Delete
"""
[312] Fix | Delete
return importlib.reload(module)
[313] Fix | Delete
[314] Fix | Delete
[315] Fix | Delete
def init_builtin(name):
[316] Fix | Delete
"""**DEPRECATED**
[317] Fix | Delete
[318] Fix | Delete
Load and return a built-in module by name, or None is such module doesn't
[319] Fix | Delete
exist
[320] Fix | Delete
"""
[321] Fix | Delete
try:
[322] Fix | Delete
return _builtin_from_name(name)
[323] Fix | Delete
except ImportError:
[324] Fix | Delete
return None
[325] Fix | Delete
[326] Fix | Delete
[327] Fix | Delete
if create_dynamic:
[328] Fix | Delete
def load_dynamic(name, path, file=None):
[329] Fix | Delete
"""**DEPRECATED**
[330] Fix | Delete
[331] Fix | Delete
Load an extension module.
[332] Fix | Delete
"""
[333] Fix | Delete
import importlib.machinery
[334] Fix | Delete
loader = importlib.machinery.ExtensionFileLoader(name, path)
[335] Fix | Delete
[336] Fix | Delete
# Issue #24748: Skip the sys.modules check in _load_module_shim;
[337] Fix | Delete
# always load new extension
[338] Fix | Delete
spec = importlib.machinery.ModuleSpec(
[339] Fix | Delete
name=name, loader=loader, origin=path)
[340] Fix | Delete
return _load(spec)
[341] Fix | Delete
[342] Fix | Delete
else:
[343] Fix | Delete
load_dynamic = None
[344] Fix | Delete
[345] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function