Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- llava/lib/python3.10/_bootsubprocess.py +97 -0
- llava/lib/python3.10/_sysconfigdata__linux_x86_64-linux-gnu.py +986 -0
- llava/lib/python3.10/fractions.py +748 -0
- llava/lib/python3.10/getpass.py +185 -0
- llava/lib/python3.10/imaplib.py +1649 -0
- llava/lib/python3.10/locale.py +1761 -0
- llava/lib/python3.10/modulefinder.py +685 -0
- llava/lib/python3.10/os.py +1123 -0
- llava/lib/python3.10/pathlib.py +1461 -0
- llava/lib/python3.10/shelve.py +243 -0
- llava/lib/python3.10/tarfile.py +0 -0
- parrot/lib/python3.10/site-packages/torch/include/ATen/ops/_cast_Double_native.h +21 -0
- parrot/lib/python3.10/site-packages/torch/include/ATen/ops/_cdist_backward_ops.h +39 -0
- parrot/lib/python3.10/site-packages/torch/include/ATen/ops/_conv_depthwise2d_cuda_dispatch.h +28 -0
- parrot/lib/python3.10/site-packages/torch/include/ATen/ops/_debug_has_internal_overlap_native.h +21 -0
- parrot/lib/python3.10/site-packages/torch/include/ATen/ops/_foreach_norm.h +39 -0
- parrot/lib/python3.10/site-packages/torch/include/ATen/ops/_foreach_round_compositeexplicitautograd_dispatch.h +26 -0
- parrot/lib/python3.10/site-packages/torch/include/ATen/ops/_histogramdd_bin_edges_ops.h +39 -0
- parrot/lib/python3.10/site-packages/torch/include/ATen/ops/_histogramdd_from_bin_tensors_cpu_dispatch.h +23 -0
- parrot/lib/python3.10/site-packages/torch/include/ATen/ops/_mps_convolution_transpose.h +91 -0
- parrot/lib/python3.10/site-packages/torch/include/ATen/ops/_sample_dirichlet_ops.h +39 -0
- parrot/lib/python3.10/site-packages/torch/include/ATen/ops/_segment_reduce_backward_ops.h +39 -0
- parrot/lib/python3.10/site-packages/torch/include/ATen/ops/_sobol_engine_ff.h +30 -0
- parrot/lib/python3.10/site-packages/torch/include/ATen/ops/_sparse_log_softmax_backward_data_native.h +23 -0
- parrot/lib/python3.10/site-packages/torch/include/ATen/ops/_upsample_bicubic2d_aa_backward_native.h +26 -0
- parrot/lib/python3.10/site-packages/torch/include/ATen/ops/_weight_int4pack_mm.h +30 -0
- parrot/lib/python3.10/site-packages/torch/include/ATen/ops/_weight_norm_interface_backward_native.h +23 -0
- parrot/lib/python3.10/site-packages/torch/include/ATen/ops/amax_cuda_dispatch.h +25 -0
- parrot/lib/python3.10/site-packages/torch/include/ATen/ops/atleast_1d.h +35 -0
- parrot/lib/python3.10/site-packages/torch/include/ATen/ops/batch_norm_backward_elemt_native.h +22 -0
- parrot/lib/python3.10/site-packages/torch/include/ATen/ops/bitwise_right_shift.h +67 -0
- parrot/lib/python3.10/site-packages/torch/include/ATen/ops/chalf_native.h +21 -0
- parrot/lib/python3.10/site-packages/torch/include/ATen/ops/col2im_cpu_dispatch.h +28 -0
- parrot/lib/python3.10/site-packages/torch/include/ATen/ops/cumsum_ops.h +83 -0
- parrot/lib/python3.10/site-packages/torch/include/ATen/ops/det.h +30 -0
- parrot/lib/python3.10/site-packages/torch/include/ATen/ops/embedding_ops.h +39 -0
- parrot/lib/python3.10/site-packages/torch/include/ATen/ops/gcd_meta.h +27 -0
- parrot/lib/python3.10/site-packages/torch/include/ATen/ops/hamming_window_native.h +28 -0
- parrot/lib/python3.10/site-packages/torch/include/ATen/ops/hardsigmoid_backward_ops.h +39 -0
- parrot/lib/python3.10/site-packages/torch/include/ATen/ops/heaviside_meta_dispatch.h +26 -0
- parrot/lib/python3.10/site-packages/torch/include/ATen/ops/index_fill_cuda_dispatch.h +24 -0
- parrot/lib/python3.10/site-packages/torch/include/ATen/ops/isreal_ops.h +28 -0
- parrot/lib/python3.10/site-packages/torch/include/ATen/ops/item_compositeimplicitautograd_dispatch.h +23 -0
- parrot/lib/python3.10/site-packages/torch/include/ATen/ops/l1_loss.h +30 -0
- parrot/lib/python3.10/site-packages/torch/include/ATen/ops/linalg_diagonal_ops.h +28 -0
- parrot/lib/python3.10/site-packages/torch/include/ATen/ops/linalg_inv_ex_cuda_dispatch.h +25 -0
- parrot/lib/python3.10/site-packages/torch/include/ATen/ops/log_sigmoid_forward_cuda_dispatch.h +25 -0
- parrot/lib/python3.10/site-packages/torch/include/ATen/ops/logical_or_cuda_dispatch.h +24 -0
- parrot/lib/python3.10/site-packages/torch/include/ATen/ops/mH_compositeimplicitautograd_dispatch.h +23 -0
- parrot/lib/python3.10/site-packages/torch/include/ATen/ops/masked_scatter_backward_ops.h +28 -0
llava/lib/python3.10/_bootsubprocess.py
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Basic subprocess implementation for POSIX which only uses os functions. Only
|
| 3 |
+
implement features required by setup.py to build C extension modules when
|
| 4 |
+
subprocess is unavailable. setup.py is not used on Windows.
|
| 5 |
+
"""
|
| 6 |
+
import os
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
# distutils.spawn used by distutils.command.build_ext
|
| 10 |
+
# calls subprocess.Popen().wait()
|
| 11 |
+
class Popen:
|
| 12 |
+
def __init__(self, cmd, env=None):
|
| 13 |
+
self._cmd = cmd
|
| 14 |
+
self._env = env
|
| 15 |
+
self.returncode = None
|
| 16 |
+
|
| 17 |
+
def wait(self):
|
| 18 |
+
pid = os.fork()
|
| 19 |
+
if pid == 0:
|
| 20 |
+
# Child process
|
| 21 |
+
try:
|
| 22 |
+
if self._env is not None:
|
| 23 |
+
os.execve(self._cmd[0], self._cmd, self._env)
|
| 24 |
+
else:
|
| 25 |
+
os.execv(self._cmd[0], self._cmd)
|
| 26 |
+
finally:
|
| 27 |
+
os._exit(1)
|
| 28 |
+
else:
|
| 29 |
+
# Parent process
|
| 30 |
+
_, status = os.waitpid(pid, 0)
|
| 31 |
+
self.returncode = os.waitstatus_to_exitcode(status)
|
| 32 |
+
|
| 33 |
+
return self.returncode
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def _check_cmd(cmd):
|
| 37 |
+
# Use regex [a-zA-Z0-9./-]+: reject empty string, space, etc.
|
| 38 |
+
safe_chars = []
|
| 39 |
+
for first, last in (("a", "z"), ("A", "Z"), ("0", "9")):
|
| 40 |
+
for ch in range(ord(first), ord(last) + 1):
|
| 41 |
+
safe_chars.append(chr(ch))
|
| 42 |
+
safe_chars.append("./-")
|
| 43 |
+
safe_chars = ''.join(safe_chars)
|
| 44 |
+
|
| 45 |
+
if isinstance(cmd, (tuple, list)):
|
| 46 |
+
check_strs = cmd
|
| 47 |
+
elif isinstance(cmd, str):
|
| 48 |
+
check_strs = [cmd]
|
| 49 |
+
else:
|
| 50 |
+
return False
|
| 51 |
+
|
| 52 |
+
for arg in check_strs:
|
| 53 |
+
if not isinstance(arg, str):
|
| 54 |
+
return False
|
| 55 |
+
if not arg:
|
| 56 |
+
# reject empty string
|
| 57 |
+
return False
|
| 58 |
+
for ch in arg:
|
| 59 |
+
if ch not in safe_chars:
|
| 60 |
+
return False
|
| 61 |
+
|
| 62 |
+
return True
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
# _aix_support used by distutil.util calls subprocess.check_output()
|
| 66 |
+
def check_output(cmd, **kwargs):
|
| 67 |
+
if kwargs:
|
| 68 |
+
raise NotImplementedError(repr(kwargs))
|
| 69 |
+
|
| 70 |
+
if not _check_cmd(cmd):
|
| 71 |
+
raise ValueError(f"unsupported command: {cmd!r}")
|
| 72 |
+
|
| 73 |
+
tmp_filename = "check_output.tmp"
|
| 74 |
+
if not isinstance(cmd, str):
|
| 75 |
+
cmd = " ".join(cmd)
|
| 76 |
+
cmd = f"{cmd} >{tmp_filename}"
|
| 77 |
+
|
| 78 |
+
try:
|
| 79 |
+
# system() spawns a shell
|
| 80 |
+
status = os.system(cmd)
|
| 81 |
+
exitcode = os.waitstatus_to_exitcode(status)
|
| 82 |
+
if exitcode:
|
| 83 |
+
raise ValueError(f"Command {cmd!r} returned non-zero "
|
| 84 |
+
f"exit status {exitcode!r}")
|
| 85 |
+
|
| 86 |
+
try:
|
| 87 |
+
with open(tmp_filename, "rb") as fp:
|
| 88 |
+
stdout = fp.read()
|
| 89 |
+
except FileNotFoundError:
|
| 90 |
+
stdout = b''
|
| 91 |
+
finally:
|
| 92 |
+
try:
|
| 93 |
+
os.unlink(tmp_filename)
|
| 94 |
+
except OSError:
|
| 95 |
+
pass
|
| 96 |
+
|
| 97 |
+
return stdout
|
llava/lib/python3.10/_sysconfigdata__linux_x86_64-linux-gnu.py
ADDED
|
@@ -0,0 +1,986 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# system configuration generated and used by the sysconfig module
|
| 2 |
+
build_time_vars = {'ABIFLAGS': '',
|
| 3 |
+
'AC_APPLE_UNIVERSAL_BUILD': 0,
|
| 4 |
+
'AIX_BUILDDATE': 0,
|
| 5 |
+
'AIX_GENUINE_CPLUSPLUS': 0,
|
| 6 |
+
'ALIGNOF_LONG': 8,
|
| 7 |
+
'ALIGNOF_SIZE_T': 8,
|
| 8 |
+
'ALT_SOABI': 0,
|
| 9 |
+
'ANDROID_API_LEVEL': 0,
|
| 10 |
+
'AR': 'ar',
|
| 11 |
+
'ARFLAGS': 'rcs',
|
| 12 |
+
'BASECFLAGS': '-Wno-unused-result -Wsign-compare',
|
| 13 |
+
'BASECPPFLAGS': '-IObjects -IInclude -IPython',
|
| 14 |
+
'BASEMODLIBS': '',
|
| 15 |
+
'BINDIR': '/root/envs/llava/bin',
|
| 16 |
+
'BINLIBDEST': '/root/envs/llava/lib/python3.10',
|
| 17 |
+
'BLDLIBRARY': 'libpython3.10.a',
|
| 18 |
+
'BLDSHARED': 'gcc -pthread -B /root/envs/llava/compiler_compat -shared '
|
| 19 |
+
''
|
| 20 |
+
''
|
| 21 |
+
'-Wl,-rpath,/root/envs/llava/lib '
|
| 22 |
+
'-Wl,-rpath-link,/root/envs/llava/lib '
|
| 23 |
+
'-L/root/envs/llava/lib '
|
| 24 |
+
''
|
| 25 |
+
''
|
| 26 |
+
'-Wl,-rpath,/root/envs/llava/lib '
|
| 27 |
+
'-Wl,-rpath-link,/root/envs/llava/lib '
|
| 28 |
+
'-L/root/envs/llava/lib',
|
| 29 |
+
'BUILDEXE': '',
|
| 30 |
+
'BUILDPYTHON': 'python',
|
| 31 |
+
'BUILD_GNU_TYPE': 'x86_64-conda_cos6-linux-gnu',
|
| 32 |
+
'BYTESTR_DEPS': '\\',
|
| 33 |
+
'CC': 'gcc -pthread -B /root/envs/llava/compiler_compat',
|
| 34 |
+
'CCSHARED': '-fPIC',
|
| 35 |
+
'CFLAGS': '-Wno-unused-result -Wsign-compare -DNDEBUG -fwrapv -O2 -Wall '
|
| 36 |
+
'-fPIC '
|
| 37 |
+
'-O2 '
|
| 38 |
+
'-isystem '
|
| 39 |
+
'/root/envs/llava/include '
|
| 40 |
+
''
|
| 41 |
+
''
|
| 42 |
+
''
|
| 43 |
+
'-fPIC '
|
| 44 |
+
'-O2 '
|
| 45 |
+
'-isystem '
|
| 46 |
+
'/root/envs/llava/include '
|
| 47 |
+
''
|
| 48 |
+
''
|
| 49 |
+
'',
|
| 50 |
+
'CFLAGSFORSHARED': '',
|
| 51 |
+
'CFLAGS_ALIASING': '',
|
| 52 |
+
'CONFIGFILES': 'configure configure.ac acconfig.h pyconfig.h.in '
|
| 53 |
+
'Makefile.pre.in',
|
| 54 |
+
'CONFIGURE_CFLAGS': '-fPIC '
|
| 55 |
+
'-O2 '
|
| 56 |
+
'-isystem '
|
| 57 |
+
'/root/envs/llava/include '
|
| 58 |
+
''
|
| 59 |
+
''
|
| 60 |
+
''
|
| 61 |
+
'',
|
| 62 |
+
'CONFIGURE_CFLAGS_NODIST': '-fno-semantic-interposition '
|
| 63 |
+
''
|
| 64 |
+
'-g -std=c99 -Wextra '
|
| 65 |
+
'-Wno-unused-result -Wno-unused-parameter '
|
| 66 |
+
'-Wno-missing-field-initializers '
|
| 67 |
+
'-Werror=implicit-function-declaration '
|
| 68 |
+
'-fvisibility=hidden',
|
| 69 |
+
'CONFIGURE_CPPFLAGS': '-DNDEBUG -D_FORTIFY_SOURCE=2 -O2 -isystem '
|
| 70 |
+
'/root/envs/llava/include '
|
| 71 |
+
'-I/root/envs/llava/include',
|
| 72 |
+
'CONFIGURE_LDFLAGS': ''
|
| 73 |
+
''
|
| 74 |
+
'-Wl,-rpath,/root/envs/llava/lib '
|
| 75 |
+
'-Wl,-rpath-link,/root/envs/llava/lib '
|
| 76 |
+
'-L/root/envs/llava/lib',
|
| 77 |
+
'CONFIGURE_LDFLAGS_NODIST': '-fno-semantic-interposition '
|
| 78 |
+
''
|
| 79 |
+
'-g',
|
| 80 |
+
'CONFIG_ARGS': "'--prefix=/root/envs/llava'"
|
| 81 |
+
"'--build=x86_64-conda_cos6-linux-gnu'"
|
| 82 |
+
"'--host=x86_64-conda_cos6-linux-gnu''--enable-ipv6'"
|
| 83 |
+
"'--with-ensurepip=no'"
|
| 84 |
+
"'--with-tzpath=/root/envs/llava/share/zoneinfo:/root/envs/llava/share/tzinfo'"
|
| 85 |
+
"'--with-computed-gotos''--with-system-ffi'"
|
| 86 |
+
"'--enable-loadable-sqlite-extensions'"
|
| 87 |
+
"'--with-tcltk-includes=-I/root/envs/llava/include'"
|
| 88 |
+
"'--with-tcltk-libs=-L/root/envs/llava/lib "
|
| 89 |
+
"-ltcl8.6 -ltk8.6''--with-platlibdir=lib''--with-lto'"
|
| 90 |
+
"'--enable-optimizations'"
|
| 91 |
+
"'-oldincludedir=/croot/python-split_1733933809325/_build_env/x86_64-conda_cos6-linux-gnu/sysroot/usr/include'"
|
| 92 |
+
"'--disable-shared''PROFILE_TASK=-m test --pgo'"
|
| 93 |
+
"'build_alias=x86_64-conda_cos6-linux-gnu'"
|
| 94 |
+
"'host_alias=x86_64-conda_cos6-linux-gnu''MACHDEP=linux'"
|
| 95 |
+
"'CC=gcc''CFLAGS= "
|
| 96 |
+
'-fPIC '
|
| 97 |
+
'-O2 '
|
| 98 |
+
'-isystem '
|
| 99 |
+
'/root/envs/llava/include '
|
| 100 |
+
''
|
| 101 |
+
''
|
| 102 |
+
''
|
| 103 |
+
"''LDFLAGS= "
|
| 104 |
+
''
|
| 105 |
+
''
|
| 106 |
+
'-Wl,-rpath,/root/envs/llava/lib '
|
| 107 |
+
'-Wl,-rpath-link,/root/envs/llava/lib '
|
| 108 |
+
"-L/root/envs/llava/lib'"
|
| 109 |
+
"'CPPFLAGS=-DNDEBUG -D_FORTIFY_SOURCE=2 -O2 -isystem "
|
| 110 |
+
'/root/envs/llava/include '
|
| 111 |
+
"-I/root/envs/llava/include'"
|
| 112 |
+
"'CPP=/croot/python-split_1733933809325/_build_env/bin/cpp'"
|
| 113 |
+
"'PKG_CONFIG_PATH=/root/envs/llava/lib/pkgconfig'",
|
| 114 |
+
'CONFINCLUDEDIR': '/root/envs/llava/include',
|
| 115 |
+
'CONFINCLUDEPY': '/root/envs/llava/include/python3.10',
|
| 116 |
+
'COREPYTHONPATH': '',
|
| 117 |
+
'COVERAGE_INFO': '/croot/python-split_1733933809325/work/build-static/coverage.info',
|
| 118 |
+
'COVERAGE_REPORT': '/croot/python-split_1733933809325/work/build-static/lcov-report',
|
| 119 |
+
'COVERAGE_REPORT_OPTIONS': '--no-branch-coverage --title "CPython lcov '
|
| 120 |
+
'report"',
|
| 121 |
+
'CPPFLAGS': '-IObjects -IInclude -IPython -I. '
|
| 122 |
+
'-I/croot/python-split_1733933809325/work/Include -DNDEBUG '
|
| 123 |
+
'-D_FORTIFY_SOURCE=2 -O2 -isystem '
|
| 124 |
+
'/root/envs/llava/include '
|
| 125 |
+
'-I/root/envs/llava/include '
|
| 126 |
+
'-DNDEBUG -D_FORTIFY_SOURCE=2 -O2 -isystem '
|
| 127 |
+
'/root/envs/llava/include '
|
| 128 |
+
'-I/root/envs/llava/include',
|
| 129 |
+
'CXX': 'g++ -pthread -B /root/envs/llava/compiler_compat',
|
| 130 |
+
'DESTDIRS': '/root/envs/llava '
|
| 131 |
+
'/root/envs/llava/lib '
|
| 132 |
+
'/root/envs/llava/lib/python3.10 '
|
| 133 |
+
'/root/envs/llava/lib/python3.10/lib-dynload',
|
| 134 |
+
'DESTLIB': '/root/envs/llava/lib/python3.10',
|
| 135 |
+
'DESTPATH': '',
|
| 136 |
+
'DESTSHARED': '/root/envs/llava/lib/python3.10/lib-dynload',
|
| 137 |
+
'DFLAGS': '',
|
| 138 |
+
'DIRMODE': 755,
|
| 139 |
+
'DIST': 'README.rst ChangeLog configure configure.ac acconfig.h pyconfig.h.in '
|
| 140 |
+
'Makefile.pre.in Include Lib Misc Ext-dummy',
|
| 141 |
+
'DISTDIRS': 'Include Lib Misc Ext-dummy',
|
| 142 |
+
'DISTFILES': 'README.rst ChangeLog configure configure.ac acconfig.h '
|
| 143 |
+
'pyconfig.h.in Makefile.pre.in',
|
| 144 |
+
'DLINCLDIR': '.',
|
| 145 |
+
'DLLLIBRARY': '',
|
| 146 |
+
'DOUBLE_IS_ARM_MIXED_ENDIAN_IEEE754': 0,
|
| 147 |
+
'DOUBLE_IS_BIG_ENDIAN_IEEE754': 0,
|
| 148 |
+
'DOUBLE_IS_LITTLE_ENDIAN_IEEE754': 1,
|
| 149 |
+
'DTRACE': '',
|
| 150 |
+
'DTRACE_DEPS': '\\',
|
| 151 |
+
'DTRACE_HEADERS': '',
|
| 152 |
+
'DTRACE_OBJS': '',
|
| 153 |
+
'DYNLOADFILE': 'dynload_shlib.o',
|
| 154 |
+
'ENABLE_IPV6': 1,
|
| 155 |
+
'ENSUREPIP': 'no',
|
| 156 |
+
'EXE': '',
|
| 157 |
+
'EXEMODE': 755,
|
| 158 |
+
'EXPERIMENTAL_ISOLATED_SUBINTERPRETERS': 0,
|
| 159 |
+
'EXPORTSFROM': '',
|
| 160 |
+
'EXPORTSYMS': '',
|
| 161 |
+
'EXTRATESTOPTS': '',
|
| 162 |
+
'EXT_SUFFIX': '.cpython-310-x86_64-linux-gnu.so',
|
| 163 |
+
'FILEMODE': 644,
|
| 164 |
+
'FLOAT_WORDS_BIGENDIAN': 0,
|
| 165 |
+
'FLOCK_NEEDS_LIBBSD': 0,
|
| 166 |
+
'GETPGRP_HAVE_ARG': 0,
|
| 167 |
+
'GITBRANCH': '',
|
| 168 |
+
'GITTAG': '',
|
| 169 |
+
'GITVERSION': '',
|
| 170 |
+
'GNULD': 'no',
|
| 171 |
+
'HAVE_ACCEPT4': 1,
|
| 172 |
+
'HAVE_ACOSH': 1,
|
| 173 |
+
'HAVE_ADDRINFO': 1,
|
| 174 |
+
'HAVE_ALARM': 1,
|
| 175 |
+
'HAVE_ALIGNED_REQUIRED': 0,
|
| 176 |
+
'HAVE_ALLOCA_H': 1,
|
| 177 |
+
'HAVE_ALTZONE': 0,
|
| 178 |
+
'HAVE_ASINH': 1,
|
| 179 |
+
'HAVE_ASM_TYPES_H': 1,
|
| 180 |
+
'HAVE_ATANH': 1,
|
| 181 |
+
'HAVE_BIND_TEXTDOMAIN_CODESET': 1,
|
| 182 |
+
'HAVE_BLUETOOTH_BLUETOOTH_H': 0,
|
| 183 |
+
'HAVE_BLUETOOTH_H': 0,
|
| 184 |
+
'HAVE_BROKEN_MBSTOWCS': 0,
|
| 185 |
+
'HAVE_BROKEN_NICE': 0,
|
| 186 |
+
'HAVE_BROKEN_PIPE_BUF': 0,
|
| 187 |
+
'HAVE_BROKEN_POLL': 0,
|
| 188 |
+
'HAVE_BROKEN_POSIX_SEMAPHORES': 0,
|
| 189 |
+
'HAVE_BROKEN_PTHREAD_SIGMASK': 0,
|
| 190 |
+
'HAVE_BROKEN_SEM_GETVALUE': 0,
|
| 191 |
+
'HAVE_BROKEN_UNSETENV': 0,
|
| 192 |
+
'HAVE_BUILTIN_ATOMIC': 1,
|
| 193 |
+
'HAVE_CHFLAGS': 0,
|
| 194 |
+
'HAVE_CHOWN': 1,
|
| 195 |
+
'HAVE_CHROOT': 1,
|
| 196 |
+
'HAVE_CLOCK': 1,
|
| 197 |
+
'HAVE_CLOCK_GETRES': 1,
|
| 198 |
+
'HAVE_CLOCK_GETTIME': 1,
|
| 199 |
+
'HAVE_CLOCK_SETTIME': 1,
|
| 200 |
+
'HAVE_CLOSE_RANGE': 0,
|
| 201 |
+
'HAVE_COMPUTED_GOTOS': 1,
|
| 202 |
+
'HAVE_CONFSTR': 1,
|
| 203 |
+
'HAVE_CONIO_H': 0,
|
| 204 |
+
'HAVE_COPYSIGN': 1,
|
| 205 |
+
'HAVE_COPY_FILE_RANGE': 0,
|
| 206 |
+
'HAVE_CRYPT_H': 1,
|
| 207 |
+
'HAVE_CRYPT_R': 1,
|
| 208 |
+
'HAVE_CTERMID': 1,
|
| 209 |
+
'HAVE_CTERMID_R': 0,
|
| 210 |
+
'HAVE_CURSES_FILTER': 1,
|
| 211 |
+
'HAVE_CURSES_H': 1,
|
| 212 |
+
'HAVE_CURSES_HAS_KEY': 1,
|
| 213 |
+
'HAVE_CURSES_IMMEDOK': 1,
|
| 214 |
+
'HAVE_CURSES_IS_PAD': 1,
|
| 215 |
+
'HAVE_CURSES_IS_TERM_RESIZED': 1,
|
| 216 |
+
'HAVE_CURSES_RESIZETERM': 1,
|
| 217 |
+
'HAVE_CURSES_RESIZE_TERM': 1,
|
| 218 |
+
'HAVE_CURSES_SYNCOK': 1,
|
| 219 |
+
'HAVE_CURSES_TYPEAHEAD': 1,
|
| 220 |
+
'HAVE_CURSES_USE_ENV': 1,
|
| 221 |
+
'HAVE_CURSES_WCHGAT': 1,
|
| 222 |
+
'HAVE_DECL_ISFINITE': 1,
|
| 223 |
+
'HAVE_DECL_ISINF': 1,
|
| 224 |
+
'HAVE_DECL_ISNAN': 1,
|
| 225 |
+
'HAVE_DECL_RTLD_DEEPBIND': 1,
|
| 226 |
+
'HAVE_DECL_RTLD_GLOBAL': 1,
|
| 227 |
+
'HAVE_DECL_RTLD_LAZY': 1,
|
| 228 |
+
'HAVE_DECL_RTLD_LOCAL': 1,
|
| 229 |
+
'HAVE_DECL_RTLD_MEMBER': 0,
|
| 230 |
+
'HAVE_DECL_RTLD_NODELETE': 1,
|
| 231 |
+
'HAVE_DECL_RTLD_NOLOAD': 1,
|
| 232 |
+
'HAVE_DECL_RTLD_NOW': 1,
|
| 233 |
+
'HAVE_DECL_TZNAME': 0,
|
| 234 |
+
'HAVE_DEVICE_MACROS': 1,
|
| 235 |
+
'HAVE_DEV_PTC': 0,
|
| 236 |
+
'HAVE_DEV_PTMX': 1,
|
| 237 |
+
'HAVE_DIRECT_H': 0,
|
| 238 |
+
'HAVE_DIRENT_D_TYPE': 1,
|
| 239 |
+
'HAVE_DIRENT_H': 1,
|
| 240 |
+
'HAVE_DIRFD': 1,
|
| 241 |
+
'HAVE_DLFCN_H': 1,
|
| 242 |
+
'HAVE_DLOPEN': 1,
|
| 243 |
+
'HAVE_DUP2': 1,
|
| 244 |
+
'HAVE_DUP3': 1,
|
| 245 |
+
'HAVE_DYLD_SHARED_CACHE_CONTAINS_PATH': 0,
|
| 246 |
+
'HAVE_DYNAMIC_LOADING': 1,
|
| 247 |
+
'HAVE_ENDIAN_H': 1,
|
| 248 |
+
'HAVE_EPOLL': 1,
|
| 249 |
+
'HAVE_EPOLL_CREATE1': 1,
|
| 250 |
+
'HAVE_ERF': 1,
|
| 251 |
+
'HAVE_ERFC': 1,
|
| 252 |
+
'HAVE_ERRNO_H': 1,
|
| 253 |
+
'HAVE_EVENTFD': 1,
|
| 254 |
+
'HAVE_EXECV': 1,
|
| 255 |
+
'HAVE_EXPLICIT_BZERO': 0,
|
| 256 |
+
'HAVE_EXPLICIT_MEMSET': 0,
|
| 257 |
+
'HAVE_EXPM1': 1,
|
| 258 |
+
'HAVE_FACCESSAT': 1,
|
| 259 |
+
'HAVE_FCHDIR': 1,
|
| 260 |
+
'HAVE_FCHMOD': 1,
|
| 261 |
+
'HAVE_FCHMODAT': 1,
|
| 262 |
+
'HAVE_FCHOWN': 1,
|
| 263 |
+
'HAVE_FCHOWNAT': 1,
|
| 264 |
+
'HAVE_FCNTL_H': 1,
|
| 265 |
+
'HAVE_FDATASYNC': 1,
|
| 266 |
+
'HAVE_FDOPENDIR': 1,
|
| 267 |
+
'HAVE_FDWALK': 0,
|
| 268 |
+
'HAVE_FEXECVE': 1,
|
| 269 |
+
'HAVE_FINITE': 1,
|
| 270 |
+
'HAVE_FLOCK': 1,
|
| 271 |
+
'HAVE_FORK': 1,
|
| 272 |
+
'HAVE_FORKPTY': 1,
|
| 273 |
+
'HAVE_FPATHCONF': 1,
|
| 274 |
+
'HAVE_FSEEK64': 0,
|
| 275 |
+
'HAVE_FSEEKO': 1,
|
| 276 |
+
'HAVE_FSTATAT': 1,
|
| 277 |
+
'HAVE_FSTATVFS': 1,
|
| 278 |
+
'HAVE_FSYNC': 1,
|
| 279 |
+
'HAVE_FTELL64': 0,
|
| 280 |
+
'HAVE_FTELLO': 1,
|
| 281 |
+
'HAVE_FTIME': 1,
|
| 282 |
+
'HAVE_FTRUNCATE': 1,
|
| 283 |
+
'HAVE_FUTIMENS': 1,
|
| 284 |
+
'HAVE_FUTIMES': 1,
|
| 285 |
+
'HAVE_FUTIMESAT': 1,
|
| 286 |
+
'HAVE_GAI_STRERROR': 1,
|
| 287 |
+
'HAVE_GAMMA': 1,
|
| 288 |
+
'HAVE_GCC_ASM_FOR_MC68881': 0,
|
| 289 |
+
'HAVE_GCC_ASM_FOR_X64': 1,
|
| 290 |
+
'HAVE_GCC_ASM_FOR_X87': 1,
|
| 291 |
+
'HAVE_GCC_UINT128_T': 1,
|
| 292 |
+
'HAVE_GETADDRINFO': 1,
|
| 293 |
+
'HAVE_GETC_UNLOCKED': 1,
|
| 294 |
+
'HAVE_GETENTROPY': 0,
|
| 295 |
+
'HAVE_GETGRGID_R': 1,
|
| 296 |
+
'HAVE_GETGRNAM_R': 1,
|
| 297 |
+
'HAVE_GETGROUPLIST': 1,
|
| 298 |
+
'HAVE_GETGROUPS': 1,
|
| 299 |
+
'HAVE_GETHOSTBYNAME': 0,
|
| 300 |
+
'HAVE_GETHOSTBYNAME_R': 1,
|
| 301 |
+
'HAVE_GETHOSTBYNAME_R_3_ARG': 0,
|
| 302 |
+
'HAVE_GETHOSTBYNAME_R_5_ARG': 0,
|
| 303 |
+
'HAVE_GETHOSTBYNAME_R_6_ARG': 1,
|
| 304 |
+
'HAVE_GETITIMER': 1,
|
| 305 |
+
'HAVE_GETLOADAVG': 1,
|
| 306 |
+
'HAVE_GETLOGIN': 1,
|
| 307 |
+
'HAVE_GETNAMEINFO': 1,
|
| 308 |
+
'HAVE_GETPAGESIZE': 1,
|
| 309 |
+
'HAVE_GETPEERNAME': 1,
|
| 310 |
+
'HAVE_GETPGID': 1,
|
| 311 |
+
'HAVE_GETPGRP': 1,
|
| 312 |
+
'HAVE_GETPID': 1,
|
| 313 |
+
'HAVE_GETPRIORITY': 1,
|
| 314 |
+
'HAVE_GETPWENT': 1,
|
| 315 |
+
'HAVE_GETPWNAM_R': 1,
|
| 316 |
+
'HAVE_GETPWUID_R': 1,
|
| 317 |
+
'HAVE_GETRANDOM': 0,
|
| 318 |
+
'HAVE_GETRANDOM_SYSCALL': 1,
|
| 319 |
+
'HAVE_GETRESGID': 1,
|
| 320 |
+
'HAVE_GETRESUID': 1,
|
| 321 |
+
'HAVE_GETSID': 1,
|
| 322 |
+
'HAVE_GETSPENT': 1,
|
| 323 |
+
'HAVE_GETSPNAM': 1,
|
| 324 |
+
'HAVE_GETWD': 1,
|
| 325 |
+
'HAVE_GLIBC_MEMMOVE_BUG': 0,
|
| 326 |
+
'HAVE_GRP_H': 1,
|
| 327 |
+
'HAVE_HSTRERROR': 1,
|
| 328 |
+
'HAVE_HTOLE64': 1,
|
| 329 |
+
'HAVE_HYPOT': 1,
|
| 330 |
+
'HAVE_IEEEFP_H': 0,
|
| 331 |
+
'HAVE_IF_NAMEINDEX': 1,
|
| 332 |
+
'HAVE_INET_ATON': 1,
|
| 333 |
+
'HAVE_INET_PTON': 1,
|
| 334 |
+
'HAVE_INITGROUPS': 1,
|
| 335 |
+
'HAVE_INTTYPES_H': 1,
|
| 336 |
+
'HAVE_IO_H': 0,
|
| 337 |
+
'HAVE_IPA_PURE_CONST_BUG': 0,
|
| 338 |
+
'HAVE_KILL': 1,
|
| 339 |
+
'HAVE_KILLPG': 1,
|
| 340 |
+
'HAVE_KQUEUE': 0,
|
| 341 |
+
'HAVE_LANGINFO_H': 1,
|
| 342 |
+
'HAVE_LARGEFILE_SUPPORT': 0,
|
| 343 |
+
'HAVE_LCHFLAGS': 0,
|
| 344 |
+
'HAVE_LCHMOD': 0,
|
| 345 |
+
'HAVE_LCHOWN': 1,
|
| 346 |
+
'HAVE_LGAMMA': 1,
|
| 347 |
+
'HAVE_LIBDL': 1,
|
| 348 |
+
'HAVE_LIBDLD': 0,
|
| 349 |
+
'HAVE_LIBIEEE': 0,
|
| 350 |
+
'HAVE_LIBINTL_H': 1,
|
| 351 |
+
'HAVE_LIBREADLINE': 1,
|
| 352 |
+
'HAVE_LIBRESOLV': 0,
|
| 353 |
+
'HAVE_LIBSENDFILE': 0,
|
| 354 |
+
'HAVE_LIBUTIL_H': 0,
|
| 355 |
+
'HAVE_LIBUUID': 1,
|
| 356 |
+
'HAVE_LINK': 1,
|
| 357 |
+
'HAVE_LINKAT': 1,
|
| 358 |
+
'HAVE_LINUX_AUXVEC_H': 1,
|
| 359 |
+
'HAVE_LINUX_CAN_BCM_H': 1,
|
| 360 |
+
'HAVE_LINUX_CAN_H': 1,
|
| 361 |
+
'HAVE_LINUX_CAN_J1939_H': 0,
|
| 362 |
+
'HAVE_LINUX_CAN_RAW_FD_FRAMES': 1,
|
| 363 |
+
'HAVE_LINUX_CAN_RAW_H': 1,
|
| 364 |
+
'HAVE_LINUX_CAN_RAW_JOIN_FILTERS': 1,
|
| 365 |
+
'HAVE_LINUX_MEMFD_H': 1,
|
| 366 |
+
'HAVE_LINUX_NETLINK_H': 1,
|
| 367 |
+
'HAVE_LINUX_QRTR_H': 0,
|
| 368 |
+
'HAVE_LINUX_RANDOM_H': 1,
|
| 369 |
+
'HAVE_LINUX_TIPC_H': 1,
|
| 370 |
+
'HAVE_LINUX_VM_SOCKETS_H': 1,
|
| 371 |
+
'HAVE_LINUX_WAIT_H': 1,
|
| 372 |
+
'HAVE_LOCKF': 1,
|
| 373 |
+
'HAVE_LOG1P': 1,
|
| 374 |
+
'HAVE_LOG2': 1,
|
| 375 |
+
'HAVE_LONG_DOUBLE': 1,
|
| 376 |
+
'HAVE_LSTAT': 1,
|
| 377 |
+
'HAVE_LUTIMES': 1,
|
| 378 |
+
'HAVE_MADVISE': 1,
|
| 379 |
+
'HAVE_MAKEDEV': 1,
|
| 380 |
+
'HAVE_MBRTOWC': 1,
|
| 381 |
+
'HAVE_MEMFD_CREATE': 0,
|
| 382 |
+
'HAVE_MEMORY_H': 1,
|
| 383 |
+
'HAVE_MEMRCHR': 1,
|
| 384 |
+
'HAVE_MKDIRAT': 1,
|
| 385 |
+
'HAVE_MKFIFO': 1,
|
| 386 |
+
'HAVE_MKFIFOAT': 1,
|
| 387 |
+
'HAVE_MKNOD': 1,
|
| 388 |
+
'HAVE_MKNODAT': 1,
|
| 389 |
+
'HAVE_MKTIME': 1,
|
| 390 |
+
'HAVE_MMAP': 1,
|
| 391 |
+
'HAVE_MREMAP': 1,
|
| 392 |
+
'HAVE_NCURSES_H': 1,
|
| 393 |
+
'HAVE_NDIR_H': 0,
|
| 394 |
+
'HAVE_NETPACKET_PACKET_H': 1,
|
| 395 |
+
'HAVE_NET_IF_H': 1,
|
| 396 |
+
'HAVE_NICE': 1,
|
| 397 |
+
'HAVE_NON_UNICODE_WCHAR_T_REPRESENTATION': 0,
|
| 398 |
+
'HAVE_OPENAT': 1,
|
| 399 |
+
'HAVE_OPENPTY': 1,
|
| 400 |
+
'HAVE_PATHCONF': 1,
|
| 401 |
+
'HAVE_PAUSE': 1,
|
| 402 |
+
'HAVE_PIPE2': 1,
|
| 403 |
+
'HAVE_PLOCK': 0,
|
| 404 |
+
'HAVE_POLL': 1,
|
| 405 |
+
'HAVE_POLL_H': 1,
|
| 406 |
+
'HAVE_POSIX_FADVISE': 1,
|
| 407 |
+
'HAVE_POSIX_FALLOCATE': 1,
|
| 408 |
+
'HAVE_POSIX_SPAWN': 1,
|
| 409 |
+
'HAVE_POSIX_SPAWNP': 1,
|
| 410 |
+
'HAVE_PREAD': 1,
|
| 411 |
+
'HAVE_PREADV': 1,
|
| 412 |
+
'HAVE_PREADV2': 0,
|
| 413 |
+
'HAVE_PRLIMIT': 1,
|
| 414 |
+
'HAVE_PROCESS_H': 0,
|
| 415 |
+
'HAVE_PROTOTYPES': 1,
|
| 416 |
+
'HAVE_PTHREAD_CONDATTR_SETCLOCK': 1,
|
| 417 |
+
'HAVE_PTHREAD_DESTRUCTOR': 0,
|
| 418 |
+
'HAVE_PTHREAD_GETCPUCLOCKID': 1,
|
| 419 |
+
'HAVE_PTHREAD_H': 1,
|
| 420 |
+
'HAVE_PTHREAD_INIT': 0,
|
| 421 |
+
'HAVE_PTHREAD_KILL': 1,
|
| 422 |
+
'HAVE_PTHREAD_SIGMASK': 1,
|
| 423 |
+
'HAVE_PTY_H': 1,
|
| 424 |
+
'HAVE_PWRITE': 1,
|
| 425 |
+
'HAVE_PWRITEV': 1,
|
| 426 |
+
'HAVE_PWRITEV2': 0,
|
| 427 |
+
'HAVE_READLINK': 1,
|
| 428 |
+
'HAVE_READLINKAT': 1,
|
| 429 |
+
'HAVE_READV': 1,
|
| 430 |
+
'HAVE_REALPATH': 1,
|
| 431 |
+
'HAVE_RENAMEAT': 1,
|
| 432 |
+
'HAVE_RL_APPEND_HISTORY': 1,
|
| 433 |
+
'HAVE_RL_CATCH_SIGNAL': 1,
|
| 434 |
+
'HAVE_RL_COMPLETION_APPEND_CHARACTER': 1,
|
| 435 |
+
'HAVE_RL_COMPLETION_DISPLAY_MATCHES_HOOK': 1,
|
| 436 |
+
'HAVE_RL_COMPLETION_MATCHES': 1,
|
| 437 |
+
'HAVE_RL_COMPLETION_SUPPRESS_APPEND': 1,
|
| 438 |
+
'HAVE_RL_PRE_INPUT_HOOK': 1,
|
| 439 |
+
'HAVE_RL_RESIZE_TERMINAL': 1,
|
| 440 |
+
'HAVE_ROUND': 1,
|
| 441 |
+
'HAVE_RTPSPAWN': 0,
|
| 442 |
+
'HAVE_SCHED_GET_PRIORITY_MAX': 1,
|
| 443 |
+
'HAVE_SCHED_H': 1,
|
| 444 |
+
'HAVE_SCHED_RR_GET_INTERVAL': 1,
|
| 445 |
+
'HAVE_SCHED_SETAFFINITY': 1,
|
| 446 |
+
'HAVE_SCHED_SETPARAM': 1,
|
| 447 |
+
'HAVE_SCHED_SETSCHEDULER': 1,
|
| 448 |
+
'HAVE_SEM_CLOCKWAIT': 0,
|
| 449 |
+
'HAVE_SEM_GETVALUE': 1,
|
| 450 |
+
'HAVE_SEM_OPEN': 1,
|
| 451 |
+
'HAVE_SEM_TIMEDWAIT': 1,
|
| 452 |
+
'HAVE_SEM_UNLINK': 1,
|
| 453 |
+
'HAVE_SENDFILE': 1,
|
| 454 |
+
'HAVE_SETEGID': 1,
|
| 455 |
+
'HAVE_SETEUID': 1,
|
| 456 |
+
'HAVE_SETGID': 1,
|
| 457 |
+
'HAVE_SETGROUPS': 1,
|
| 458 |
+
'HAVE_SETHOSTNAME': 1,
|
| 459 |
+
'HAVE_SETITIMER': 1,
|
| 460 |
+
'HAVE_SETLOCALE': 1,
|
| 461 |
+
'HAVE_SETPGID': 1,
|
| 462 |
+
'HAVE_SETPGRP': 1,
|
| 463 |
+
'HAVE_SETPRIORITY': 1,
|
| 464 |
+
'HAVE_SETREGID': 1,
|
| 465 |
+
'HAVE_SETRESGID': 1,
|
| 466 |
+
'HAVE_SETRESUID': 1,
|
| 467 |
+
'HAVE_SETREUID': 1,
|
| 468 |
+
'HAVE_SETSID': 1,
|
| 469 |
+
'HAVE_SETUID': 1,
|
| 470 |
+
'HAVE_SETVBUF': 1,
|
| 471 |
+
'HAVE_SHADOW_H': 1,
|
| 472 |
+
'HAVE_SHM_OPEN': 1,
|
| 473 |
+
'HAVE_SHM_UNLINK': 1,
|
| 474 |
+
'HAVE_SIGACTION': 1,
|
| 475 |
+
'HAVE_SIGALTSTACK': 1,
|
| 476 |
+
'HAVE_SIGFILLSET': 1,
|
| 477 |
+
'HAVE_SIGINFO_T_SI_BAND': 1,
|
| 478 |
+
'HAVE_SIGINTERRUPT': 1,
|
| 479 |
+
'HAVE_SIGNAL_H': 1,
|
| 480 |
+
'HAVE_SIGPENDING': 1,
|
| 481 |
+
'HAVE_SIGRELSE': 1,
|
| 482 |
+
'HAVE_SIGTIMEDWAIT': 1,
|
| 483 |
+
'HAVE_SIGWAIT': 1,
|
| 484 |
+
'HAVE_SIGWAITINFO': 1,
|
| 485 |
+
'HAVE_SNPRINTF': 1,
|
| 486 |
+
'HAVE_SOCKADDR_ALG': 1,
|
| 487 |
+
'HAVE_SOCKADDR_SA_LEN': 0,
|
| 488 |
+
'HAVE_SOCKADDR_STORAGE': 1,
|
| 489 |
+
'HAVE_SOCKETPAIR': 1,
|
| 490 |
+
'HAVE_SPAWN_H': 1,
|
| 491 |
+
'HAVE_SPLICE': 1,
|
| 492 |
+
'HAVE_SSIZE_T': 1,
|
| 493 |
+
'HAVE_STATVFS': 1,
|
| 494 |
+
'HAVE_STAT_TV_NSEC': 1,
|
| 495 |
+
'HAVE_STAT_TV_NSEC2': 0,
|
| 496 |
+
'HAVE_STDARG_PROTOTYPES': 1,
|
| 497 |
+
'HAVE_STDINT_H': 1,
|
| 498 |
+
'HAVE_STDLIB_H': 1,
|
| 499 |
+
'HAVE_STD_ATOMIC': 1,
|
| 500 |
+
'HAVE_STRFTIME': 1,
|
| 501 |
+
'HAVE_STRINGS_H': 1,
|
| 502 |
+
'HAVE_STRING_H': 1,
|
| 503 |
+
'HAVE_STRLCPY': 0,
|
| 504 |
+
'HAVE_STROPTS_H': 0,
|
| 505 |
+
'HAVE_STRSIGNAL': 1,
|
| 506 |
+
'HAVE_STRUCT_PASSWD_PW_GECOS': 1,
|
| 507 |
+
'HAVE_STRUCT_PASSWD_PW_PASSWD': 1,
|
| 508 |
+
'HAVE_STRUCT_STAT_ST_BIRTHTIME': 0,
|
| 509 |
+
'HAVE_STRUCT_STAT_ST_BLKSIZE': 1,
|
| 510 |
+
'HAVE_STRUCT_STAT_ST_BLOCKS': 1,
|
| 511 |
+
'HAVE_STRUCT_STAT_ST_FLAGS': 0,
|
| 512 |
+
'HAVE_STRUCT_STAT_ST_GEN': 0,
|
| 513 |
+
'HAVE_STRUCT_STAT_ST_RDEV': 1,
|
| 514 |
+
'HAVE_STRUCT_TM_TM_ZONE': 1,
|
| 515 |
+
'HAVE_SYMLINK': 1,
|
| 516 |
+
'HAVE_SYMLINKAT': 1,
|
| 517 |
+
'HAVE_SYNC': 1,
|
| 518 |
+
'HAVE_SYSCONF': 1,
|
| 519 |
+
'HAVE_SYSEXITS_H': 1,
|
| 520 |
+
'HAVE_SYS_AUDIOIO_H': 0,
|
| 521 |
+
'HAVE_SYS_AUXV_H': 1,
|
| 522 |
+
'HAVE_SYS_BSDTTY_H': 0,
|
| 523 |
+
'HAVE_SYS_DEVPOLL_H': 0,
|
| 524 |
+
'HAVE_SYS_DIR_H': 0,
|
| 525 |
+
'HAVE_SYS_ENDIAN_H': 0,
|
| 526 |
+
'HAVE_SYS_EPOLL_H': 1,
|
| 527 |
+
'HAVE_SYS_EVENTFD_H': 1,
|
| 528 |
+
'HAVE_SYS_EVENT_H': 0,
|
| 529 |
+
'HAVE_SYS_FILE_H': 1,
|
| 530 |
+
'HAVE_SYS_IOCTL_H': 1,
|
| 531 |
+
'HAVE_SYS_KERN_CONTROL_H': 0,
|
| 532 |
+
'HAVE_SYS_LOADAVG_H': 0,
|
| 533 |
+
'HAVE_SYS_LOCK_H': 0,
|
| 534 |
+
'HAVE_SYS_MEMFD_H': 0,
|
| 535 |
+
'HAVE_SYS_MKDEV_H': 0,
|
| 536 |
+
'HAVE_SYS_MMAN_H': 1,
|
| 537 |
+
'HAVE_SYS_MODEM_H': 0,
|
| 538 |
+
'HAVE_SYS_NDIR_H': 0,
|
| 539 |
+
'HAVE_SYS_PARAM_H': 1,
|
| 540 |
+
'HAVE_SYS_POLL_H': 1,
|
| 541 |
+
'HAVE_SYS_RANDOM_H': 0,
|
| 542 |
+
'HAVE_SYS_RESOURCE_H': 1,
|
| 543 |
+
'HAVE_SYS_SELECT_H': 1,
|
| 544 |
+
'HAVE_SYS_SENDFILE_H': 1,
|
| 545 |
+
'HAVE_SYS_SOCKET_H': 1,
|
| 546 |
+
'HAVE_SYS_STATVFS_H': 1,
|
| 547 |
+
'HAVE_SYS_STAT_H': 1,
|
| 548 |
+
'HAVE_SYS_SYSCALL_H': 1,
|
| 549 |
+
'HAVE_SYS_SYSMACROS_H': 1,
|
| 550 |
+
'HAVE_SYS_SYS_DOMAIN_H': 0,
|
| 551 |
+
'HAVE_SYS_TERMIO_H': 0,
|
| 552 |
+
'HAVE_SYS_TIMES_H': 1,
|
| 553 |
+
'HAVE_SYS_TIME_H': 1,
|
| 554 |
+
'HAVE_SYS_TYPES_H': 1,
|
| 555 |
+
'HAVE_SYS_UIO_H': 1,
|
| 556 |
+
'HAVE_SYS_UN_H': 1,
|
| 557 |
+
'HAVE_SYS_UTSNAME_H': 1,
|
| 558 |
+
'HAVE_SYS_WAIT_H': 1,
|
| 559 |
+
'HAVE_SYS_XATTR_H': 1,
|
| 560 |
+
'HAVE_TCGETPGRP': 1,
|
| 561 |
+
'HAVE_TCSETPGRP': 1,
|
| 562 |
+
'HAVE_TEMPNAM': 1,
|
| 563 |
+
'HAVE_TERMIOS_H': 1,
|
| 564 |
+
'HAVE_TERM_H': 1,
|
| 565 |
+
'HAVE_TGAMMA': 1,
|
| 566 |
+
'HAVE_TIMEGM': 1,
|
| 567 |
+
'HAVE_TIMES': 1,
|
| 568 |
+
'HAVE_TMPFILE': 1,
|
| 569 |
+
'HAVE_TMPNAM': 1,
|
| 570 |
+
'HAVE_TMPNAM_R': 1,
|
| 571 |
+
'HAVE_TM_ZONE': 1,
|
| 572 |
+
'HAVE_TRUNCATE': 1,
|
| 573 |
+
'HAVE_TZNAME': 0,
|
| 574 |
+
'HAVE_UCS4_TCL': 0,
|
| 575 |
+
'HAVE_UNAME': 1,
|
| 576 |
+
'HAVE_UNISTD_H': 1,
|
| 577 |
+
'HAVE_UNLINKAT': 1,
|
| 578 |
+
'HAVE_USABLE_WCHAR_T': 0,
|
| 579 |
+
'HAVE_UTIL_H': 0,
|
| 580 |
+
'HAVE_UTIMENSAT': 1,
|
| 581 |
+
'HAVE_UTIMES': 1,
|
| 582 |
+
'HAVE_UTIME_H': 1,
|
| 583 |
+
'HAVE_UUID_CREATE': 0,
|
| 584 |
+
'HAVE_UUID_ENC_BE': 0,
|
| 585 |
+
'HAVE_UUID_GENERATE_TIME_SAFE': 1,
|
| 586 |
+
'HAVE_UUID_H': 1,
|
| 587 |
+
'HAVE_UUID_UUID_H': 1,
|
| 588 |
+
'HAVE_VFORK': 1,
|
| 589 |
+
'HAVE_WAIT3': 1,
|
| 590 |
+
'HAVE_WAIT4': 1,
|
| 591 |
+
'HAVE_WAITID': 1,
|
| 592 |
+
'HAVE_WAITPID': 1,
|
| 593 |
+
'HAVE_WCHAR_H': 1,
|
| 594 |
+
'HAVE_WCSCOLL': 1,
|
| 595 |
+
'HAVE_WCSFTIME': 1,
|
| 596 |
+
'HAVE_WCSXFRM': 1,
|
| 597 |
+
'HAVE_WMEMCMP': 1,
|
| 598 |
+
'HAVE_WORKING_TZSET': 1,
|
| 599 |
+
'HAVE_WRITEV': 1,
|
| 600 |
+
'HAVE_ZLIB_COPY': 1,
|
| 601 |
+
'HAVE__GETPTY': 0,
|
| 602 |
+
'HOST_GNU_TYPE': 'x86_64-conda_cos6-linux-gnu',
|
| 603 |
+
'INCLDIRSTOMAKE': '/root/envs/llava/include '
|
| 604 |
+
'/root/envs/llava/include '
|
| 605 |
+
'/root/envs/llava/include/python3.10 '
|
| 606 |
+
'/root/envs/llava/include/python3.10',
|
| 607 |
+
'INCLUDEDIR': '/root/envs/llava/include',
|
| 608 |
+
'INCLUDEPY': '/root/envs/llava/include/python3.10',
|
| 609 |
+
'INSTALL': '/usr/bin/install -c',
|
| 610 |
+
'INSTALL_DATA': '/usr/bin/install -c -m 644',
|
| 611 |
+
'INSTALL_PROGRAM': '/usr/bin/install -c',
|
| 612 |
+
'INSTALL_SCRIPT': '/usr/bin/install -c',
|
| 613 |
+
'INSTALL_SHARED': '/usr/bin/install -c -m 755',
|
| 614 |
+
'INSTSONAME': 'libpython3.10.a',
|
| 615 |
+
'IO_H': 'Modules/_io/_iomodule.h',
|
| 616 |
+
'IO_OBJS': '\\',
|
| 617 |
+
'LDCXXSHARED': 'g++ -pthread -B /root/envs/llava/compiler_compat -shared',
|
| 618 |
+
'LDFLAGS': ''
|
| 619 |
+
''
|
| 620 |
+
'-Wl,-rpath,/root/envs/llava/lib '
|
| 621 |
+
'-Wl,-rpath-link,/root/envs/llava/lib '
|
| 622 |
+
'-L/root/envs/llava/lib '
|
| 623 |
+
''
|
| 624 |
+
''
|
| 625 |
+
'-Wl,-rpath,/root/envs/llava/lib '
|
| 626 |
+
'-Wl,-rpath-link,/root/envs/llava/lib '
|
| 627 |
+
'-L/root/envs/llava/lib',
|
| 628 |
+
'LDLIBRARY': 'libpython3.10.a',
|
| 629 |
+
'LDLIBRARYDIR': '',
|
| 630 |
+
'LDSHARED': 'gcc -pthread -B /root/envs/llava/compiler_compat -shared '
|
| 631 |
+
''
|
| 632 |
+
''
|
| 633 |
+
'-Wl,-rpath,/root/envs/llava/lib '
|
| 634 |
+
'-Wl,-rpath-link,/root/envs/llava/lib '
|
| 635 |
+
'-L/root/envs/llava/lib '
|
| 636 |
+
''
|
| 637 |
+
''
|
| 638 |
+
'-Wl,-rpath,/root/envs/llava/lib '
|
| 639 |
+
'-Wl,-rpath-link,/root/envs/llava/lib '
|
| 640 |
+
'-L/root/envs/llava/lib',
|
| 641 |
+
'LDVERSION': '3.10',
|
| 642 |
+
'LIBC': '',
|
| 643 |
+
'LIBDEST': '/root/envs/llava/lib/python3.10',
|
| 644 |
+
'LIBDIR': '/root/envs/llava/lib',
|
| 645 |
+
'LIBFFI_INCLUDEDIR': '/root/envs/llava/include',
|
| 646 |
+
'LIBM': '-lm',
|
| 647 |
+
'LIBOBJDIR': 'Python/',
|
| 648 |
+
'LIBOBJS': '',
|
| 649 |
+
'LIBPC': '/root/envs/llava/lib/pkgconfig',
|
| 650 |
+
'LIBPL': '/root/envs/llava/lib/python3.10/config-3.10-x86_64-linux-gnu',
|
| 651 |
+
'LIBPYTHON': '',
|
| 652 |
+
'LIBRARY': 'libpython3.10.a',
|
| 653 |
+
'LIBRARY_DEPS': 'libpython3.10.a',
|
| 654 |
+
'LIBRARY_OBJS': '\\',
|
| 655 |
+
'LIBRARY_OBJS_OMIT_FROZEN': '\\',
|
| 656 |
+
'LIBS': '-lcrypt -lpthread -ldl -lutil -lm',
|
| 657 |
+
'LIBSUBDIRS': 'asyncio \\',
|
| 658 |
+
'LINKCC': 'gcc -pthread -B /root/envs/llava/compiler_compat',
|
| 659 |
+
'LINKFORSHARED': '-Xlinker -export-dynamic',
|
| 660 |
+
'LIPO_32BIT_FLAGS': '',
|
| 661 |
+
'LIPO_INTEL64_FLAGS': '',
|
| 662 |
+
'LLVM_PROF_ERR': 'no',
|
| 663 |
+
'LLVM_PROF_FILE': '',
|
| 664 |
+
'LLVM_PROF_MERGER': 'true',
|
| 665 |
+
'LN': 'ln',
|
| 666 |
+
'LOCALMODLIBS': '',
|
| 667 |
+
'MACHDEP': 'linux',
|
| 668 |
+
'MACHDEP_OBJS': '',
|
| 669 |
+
'MACHDESTLIB': '/root/envs/llava/lib/python3.10',
|
| 670 |
+
'MACOSX_DEPLOYMENT_TARGET': '',
|
| 671 |
+
'MAINCC': 'gcc -pthread -B /root/envs/llava/compiler_compat',
|
| 672 |
+
'MAJOR_IN_MKDEV': 0,
|
| 673 |
+
'MAJOR_IN_SYSMACROS': 0,
|
| 674 |
+
'MAKESETUP': '/croot/python-split_1733933809325/work/Modules/makesetup',
|
| 675 |
+
'MANDIR': '/root/envs/llava/share/man',
|
| 676 |
+
'MKDIR_P': '/usr/bin/mkdir -p',
|
| 677 |
+
'MODBUILT_NAMES': 'posix errno pwd _sre _codecs _weakref _functools '
|
| 678 |
+
'_operator _collections _abc itertools atexit _signal '
|
| 679 |
+
'_stat time _thread _locale _io faulthandler '
|
| 680 |
+
'_tracemalloc _symtable xxsubtype',
|
| 681 |
+
'MODDISABLED_NAMES': '',
|
| 682 |
+
'MODLIBS': '',
|
| 683 |
+
'MODOBJS': 'Modules/posixmodule.o Modules/errnomodule.o '
|
| 684 |
+
'Modules/pwdmodule.o Modules/_sre.o Modules/_codecsmodule.o '
|
| 685 |
+
'Modules/_weakref.o Modules/_functoolsmodule.o '
|
| 686 |
+
'Modules/_operator.o Modules/_collectionsmodule.o '
|
| 687 |
+
'Modules/_abc.o Modules/itertoolsmodule.o '
|
| 688 |
+
'Modules/atexitmodule.o Modules/signalmodule.o Modules/_stat.o '
|
| 689 |
+
'Modules/timemodule.o Modules/_threadmodule.o '
|
| 690 |
+
'Modules/_localemodule.o Modules/_iomodule.o Modules/iobase.o '
|
| 691 |
+
'Modules/fileio.o Modules/bytesio.o Modules/bufferedio.o '
|
| 692 |
+
'Modules/textio.o Modules/stringio.o Modules/faulthandler.o '
|
| 693 |
+
'Modules/_tracemalloc.o Modules/symtablemodule.o '
|
| 694 |
+
'Modules/xxsubtype.o',
|
| 695 |
+
'MODULE_OBJS': '\\',
|
| 696 |
+
'MULTIARCH': 'x86_64-linux-gnu',
|
| 697 |
+
'MULTIARCH_CPPFLAGS': '-DMULTIARCH=\\"x86_64-linux-gnu\\"',
|
| 698 |
+
'MVWDELCH_IS_EXPRESSION': 1,
|
| 699 |
+
'NO_AS_NEEDED': '-Wl,--no-as-needed',
|
| 700 |
+
'OBJECT_OBJS': '\\',
|
| 701 |
+
'OPENSSL_INCLUDES': '-I/root/envs/llava/include',
|
| 702 |
+
'OPENSSL_LDFLAGS': '-L/root/envs/llava/lib',
|
| 703 |
+
'OPENSSL_LIBS': '-lssl -lcrypto',
|
| 704 |
+
'OPENSSL_RPATH': '',
|
| 705 |
+
'OPT': '-DNDEBUG -fwrapv -O2 -Wall',
|
| 706 |
+
'OTHER_LIBTOOL_OPT': '',
|
| 707 |
+
'PACKAGE_BUGREPORT': 0,
|
| 708 |
+
'PACKAGE_NAME': 0,
|
| 709 |
+
'PACKAGE_STRING': 0,
|
| 710 |
+
'PACKAGE_TARNAME': 0,
|
| 711 |
+
'PACKAGE_URL': 0,
|
| 712 |
+
'PACKAGE_VERSION': 0,
|
| 713 |
+
'PARSER_HEADERS': '\\',
|
| 714 |
+
'PARSER_OBJS': '\\ \\ Parser/myreadline.o Parser/tokenizer.o',
|
| 715 |
+
'PEGEN_HEADERS': '\\',
|
| 716 |
+
'PEGEN_OBJS': '\\',
|
| 717 |
+
'PGO_PROF_GEN_FLAG': '-fprofile-generate',
|
| 718 |
+
'PGO_PROF_USE_FLAG': '',
|
| 719 |
+
'PLATLIBDIR': 'lib',
|
| 720 |
+
'POBJS': '\\',
|
| 721 |
+
'POSIX_SEMAPHORES_NOT_ENABLED': 0,
|
| 722 |
+
'PROFILE_TASK': '-m test --pgo',
|
| 723 |
+
'PTHREAD_KEY_T_IS_COMPATIBLE_WITH_INT': 1,
|
| 724 |
+
'PTHREAD_SYSTEM_SCHED_SUPPORTED': 1,
|
| 725 |
+
'PURIFY': '',
|
| 726 |
+
'PY3LIBRARY': '',
|
| 727 |
+
'PYLONG_BITS_IN_DIGIT': 0,
|
| 728 |
+
'PYTHON': 'python',
|
| 729 |
+
'PYTHONFRAMEWORK': '',
|
| 730 |
+
'PYTHONFRAMEWORKDIR': 'no-framework',
|
| 731 |
+
'PYTHONFRAMEWORKINSTALLDIR': '',
|
| 732 |
+
'PYTHONFRAMEWORKPREFIX': '',
|
| 733 |
+
'PYTHONPATH': '',
|
| 734 |
+
'PYTHON_FOR_BUILD': './python -E',
|
| 735 |
+
'PYTHON_FOR_REGEN': '',
|
| 736 |
+
'PYTHON_HEADERS': '\\',
|
| 737 |
+
'PYTHON_OBJS': '\\',
|
| 738 |
+
'PY_BUILD_ENVIRON': '',
|
| 739 |
+
'PY_BUILTIN_HASHLIB_HASHES': '"md5,sha1,sha256,sha512,sha3,blake2"',
|
| 740 |
+
'PY_BUILTIN_MODULE_CFLAGS': '-Wno-unused-result -Wsign-compare -DNDEBUG '
|
| 741 |
+
'-fwrapv -O2 -Wall '
|
| 742 |
+
'-fPIC '
|
| 743 |
+
'-O2 -isystem '
|
| 744 |
+
'/root/envs/llava/include '
|
| 745 |
+
''
|
| 746 |
+
''
|
| 747 |
+
''
|
| 748 |
+
''
|
| 749 |
+
'-fPIC '
|
| 750 |
+
'-O2 '
|
| 751 |
+
'-isystem '
|
| 752 |
+
'/root/envs/llava/include '
|
| 753 |
+
''
|
| 754 |
+
''
|
| 755 |
+
''
|
| 756 |
+
''
|
| 757 |
+
'-fno-semantic-interposition '
|
| 758 |
+
''
|
| 759 |
+
'-g -std=c99 -Wextra '
|
| 760 |
+
'-Wno-unused-result -Wno-unused-parameter '
|
| 761 |
+
'-Wno-missing-field-initializers '
|
| 762 |
+
'-Werror=implicit-function-declaration '
|
| 763 |
+
'-fvisibility=hidden '
|
| 764 |
+
''
|
| 765 |
+
'-I/croot/python-split_1733933809325/work/Include/internal '
|
| 766 |
+
'-IObjects -IInclude -IPython -I. '
|
| 767 |
+
'-I/croot/python-split_1733933809325/work/Include '
|
| 768 |
+
'-DNDEBUG -D_FORTIFY_SOURCE=2 -O2 -isystem '
|
| 769 |
+
'/root/envs/llava/include '
|
| 770 |
+
'-I/root/envs/llava/include '
|
| 771 |
+
'-DNDEBUG -D_FORTIFY_SOURCE=2 -O2 -isystem '
|
| 772 |
+
'/root/envs/llava/include '
|
| 773 |
+
'-I/root/envs/llava/include '
|
| 774 |
+
'-DPy_BUILD_CORE_BUILTIN',
|
| 775 |
+
'PY_CFLAGS': '-Wno-unused-result -Wsign-compare -DNDEBUG -fwrapv -O2 -Wall '
|
| 776 |
+
'-fPIC '
|
| 777 |
+
'-O2 '
|
| 778 |
+
'-isystem '
|
| 779 |
+
'/root/envs/llava/include '
|
| 780 |
+
''
|
| 781 |
+
''
|
| 782 |
+
''
|
| 783 |
+
'-fPIC '
|
| 784 |
+
'-O2 '
|
| 785 |
+
'-isystem '
|
| 786 |
+
'/root/envs/llava/include '
|
| 787 |
+
''
|
| 788 |
+
''
|
| 789 |
+
''
|
| 790 |
+
'',
|
| 791 |
+
'PY_CFLAGS_NODIST': '-fno-semantic-interposition '
|
| 792 |
+
'-g -std=c99 '
|
| 793 |
+
'-Wextra -Wno-unused-result -Wno-unused-parameter '
|
| 794 |
+
'-Wno-missing-field-initializers '
|
| 795 |
+
'-Werror=implicit-function-declaration '
|
| 796 |
+
'-fvisibility=hidden '
|
| 797 |
+
'-I/croot/python-split_1733933809325/work/Include/internal',
|
| 798 |
+
'PY_COERCE_C_LOCALE': 1,
|
| 799 |
+
'PY_CORE_CFLAGS': '-Wno-unused-result -Wsign-compare -DNDEBUG -fwrapv -O2 '
|
| 800 |
+
'-Wall -fPIC '
|
| 801 |
+
'-O2 '
|
| 802 |
+
'-isystem '
|
| 803 |
+
'/root/envs/llava/include '
|
| 804 |
+
''
|
| 805 |
+
''
|
| 806 |
+
''
|
| 807 |
+
'-fPIC '
|
| 808 |
+
'-O2 '
|
| 809 |
+
'-isystem '
|
| 810 |
+
'/root/envs/llava/include '
|
| 811 |
+
''
|
| 812 |
+
''
|
| 813 |
+
''
|
| 814 |
+
'-fno-semantic-interposition '
|
| 815 |
+
''
|
| 816 |
+
'-g -std=c99 -Wextra -Wno-unused-result '
|
| 817 |
+
'-Wno-unused-parameter -Wno-missing-field-initializers '
|
| 818 |
+
'-Werror=implicit-function-declaration -fvisibility=hidden '
|
| 819 |
+
''
|
| 820 |
+
'-I/croot/python-split_1733933809325/work/Include/internal '
|
| 821 |
+
'-IObjects -IInclude -IPython -I. '
|
| 822 |
+
'-I/croot/python-split_1733933809325/work/Include -DNDEBUG '
|
| 823 |
+
'-D_FORTIFY_SOURCE=2 -O2 -isystem '
|
| 824 |
+
'/root/envs/llava/include '
|
| 825 |
+
'-I/root/envs/llava/include '
|
| 826 |
+
'-DNDEBUG -D_FORTIFY_SOURCE=2 -O2 -isystem '
|
| 827 |
+
'/root/envs/llava/include '
|
| 828 |
+
'-I/root/envs/llava/include '
|
| 829 |
+
'-DPy_BUILD_CORE',
|
| 830 |
+
'PY_CORE_LDFLAGS': ''
|
| 831 |
+
''
|
| 832 |
+
'-Wl,-rpath,/root/envs/llava/lib '
|
| 833 |
+
'-Wl,-rpath-link,/root/envs/llava/lib '
|
| 834 |
+
'-L/root/envs/llava/lib '
|
| 835 |
+
''
|
| 836 |
+
''
|
| 837 |
+
'-Wl,-rpath,/root/envs/llava/lib '
|
| 838 |
+
'-Wl,-rpath-link,/root/envs/llava/lib '
|
| 839 |
+
'-L/root/envs/llava/lib '
|
| 840 |
+
'-fno-semantic-interposition '
|
| 841 |
+
'-g',
|
| 842 |
+
'PY_CPPFLAGS': '-IObjects -IInclude -IPython -I. '
|
| 843 |
+
'-I/croot/python-split_1733933809325/work/Include -DNDEBUG '
|
| 844 |
+
'-D_FORTIFY_SOURCE=2 -O2 -isystem '
|
| 845 |
+
'/root/envs/llava/include '
|
| 846 |
+
'-I/root/envs/llava/include '
|
| 847 |
+
'-DNDEBUG -D_FORTIFY_SOURCE=2 -O2 -isystem '
|
| 848 |
+
'/root/envs/llava/include '
|
| 849 |
+
'-I/root/envs/llava/include',
|
| 850 |
+
'PY_ENABLE_SHARED': 0,
|
| 851 |
+
'PY_FORMAT_SIZE_T': '"z"',
|
| 852 |
+
'PY_LDFLAGS': ''
|
| 853 |
+
''
|
| 854 |
+
'-Wl,-rpath,/root/envs/llava/lib '
|
| 855 |
+
'-Wl,-rpath-link,/root/envs/llava/lib '
|
| 856 |
+
'-L/root/envs/llava/lib '
|
| 857 |
+
''
|
| 858 |
+
''
|
| 859 |
+
'-Wl,-rpath,/root/envs/llava/lib '
|
| 860 |
+
'-Wl,-rpath-link,/root/envs/llava/lib '
|
| 861 |
+
'-L/root/envs/llava/lib',
|
| 862 |
+
'PY_LDFLAGS_NODIST': '-fno-semantic-interposition '
|
| 863 |
+
'-g',
|
| 864 |
+
'PY_SSL_DEFAULT_CIPHERS': 1,
|
| 865 |
+
'PY_SSL_DEFAULT_CIPHER_STRING': 0,
|
| 866 |
+
'PY_STDMODULE_CFLAGS': '-Wno-unused-result -Wsign-compare -DNDEBUG -fwrapv '
|
| 867 |
+
'-O2 -Wall '
|
| 868 |
+
'-fPIC '
|
| 869 |
+
'-O2 -isystem '
|
| 870 |
+
'/root/envs/llava/include '
|
| 871 |
+
''
|
| 872 |
+
''
|
| 873 |
+
''
|
| 874 |
+
''
|
| 875 |
+
'-fPIC '
|
| 876 |
+
'-O2 '
|
| 877 |
+
'-isystem '
|
| 878 |
+
'/root/envs/llava/include '
|
| 879 |
+
''
|
| 880 |
+
''
|
| 881 |
+
''
|
| 882 |
+
''
|
| 883 |
+
'-fno-semantic-interposition '
|
| 884 |
+
'-g -std=c99 '
|
| 885 |
+
'-Wextra -Wno-unused-result -Wno-unused-parameter '
|
| 886 |
+
'-Wno-missing-field-initializers '
|
| 887 |
+
'-Werror=implicit-function-declaration '
|
| 888 |
+
'-fvisibility=hidden '
|
| 889 |
+
''
|
| 890 |
+
'-I/croot/python-split_1733933809325/work/Include/internal '
|
| 891 |
+
'-IObjects -IInclude -IPython -I. '
|
| 892 |
+
'-I/croot/python-split_1733933809325/work/Include '
|
| 893 |
+
'-DNDEBUG -D_FORTIFY_SOURCE=2 -O2 -isystem '
|
| 894 |
+
'/root/envs/llava/include '
|
| 895 |
+
'-I/root/envs/llava/include '
|
| 896 |
+
'-DNDEBUG -D_FORTIFY_SOURCE=2 -O2 -isystem '
|
| 897 |
+
'/root/envs/llava/include '
|
| 898 |
+
'-I/root/envs/llava/include',
|
| 899 |
+
'Py_DEBUG': 0,
|
| 900 |
+
'Py_ENABLE_SHARED': 0,
|
| 901 |
+
'Py_HASH_ALGORITHM': 0,
|
| 902 |
+
'Py_TRACE_REFS': 0,
|
| 903 |
+
'QUICKTESTOPTS': '-x test_subprocess test_io test_lib2to3 \\',
|
| 904 |
+
'READELF': 'readelf',
|
| 905 |
+
'RESSRCDIR': 'Mac/Resources/framework',
|
| 906 |
+
'RETSIGTYPE': 'void',
|
| 907 |
+
'RUNSHARED': '',
|
| 908 |
+
'SCRIPTDIR': '/root/envs/llava/lib',
|
| 909 |
+
'SETPGRP_HAVE_ARG': 0,
|
| 910 |
+
'SHELL': '/bin/sh',
|
| 911 |
+
'SHLIBS': '-lcrypt -lpthread -ldl -lutil -lm',
|
| 912 |
+
'SHLIB_SUFFIX': '.so',
|
| 913 |
+
'SHM_NEEDS_LIBRT': 1,
|
| 914 |
+
'SIGNED_RIGHT_SHIFT_ZERO_FILLS': 0,
|
| 915 |
+
'SITEPATH': '',
|
| 916 |
+
'SIZEOF_DOUBLE': 8,
|
| 917 |
+
'SIZEOF_FLOAT': 4,
|
| 918 |
+
'SIZEOF_FPOS_T': 16,
|
| 919 |
+
'SIZEOF_INT': 4,
|
| 920 |
+
'SIZEOF_LONG': 8,
|
| 921 |
+
'SIZEOF_LONG_DOUBLE': 16,
|
| 922 |
+
'SIZEOF_LONG_LONG': 8,
|
| 923 |
+
'SIZEOF_OFF_T': 8,
|
| 924 |
+
'SIZEOF_PID_T': 4,
|
| 925 |
+
'SIZEOF_PTHREAD_KEY_T': 4,
|
| 926 |
+
'SIZEOF_PTHREAD_T': 8,
|
| 927 |
+
'SIZEOF_SHORT': 2,
|
| 928 |
+
'SIZEOF_SIZE_T': 8,
|
| 929 |
+
'SIZEOF_TIME_T': 8,
|
| 930 |
+
'SIZEOF_UINTPTR_T': 8,
|
| 931 |
+
'SIZEOF_VOID_P': 8,
|
| 932 |
+
'SIZEOF_WCHAR_T': 4,
|
| 933 |
+
'SIZEOF__BOOL': 1,
|
| 934 |
+
'SOABI': 'cpython-310-x86_64-linux-gnu',
|
| 935 |
+
'SRCDIRS': 'Parser Objects Python Modules Modules/_io Programs',
|
| 936 |
+
'SRC_GDB_HOOKS': '/croot/python-split_1733933809325/work/Tools/gdb/libpython.py',
|
| 937 |
+
'STATIC_LIBPYTHON': 1,
|
| 938 |
+
'STDC_HEADERS': 1,
|
| 939 |
+
'STRICT_SYSV_CURSES': "/* Don't use ncurses extensions */",
|
| 940 |
+
'STRIPFLAG': '-s',
|
| 941 |
+
'SUBDIRS': '',
|
| 942 |
+
'SUBDIRSTOO': 'Include Lib Misc',
|
| 943 |
+
'SYSLIBS': '-lm',
|
| 944 |
+
'SYS_SELECT_WITH_SYS_TIME': 1,
|
| 945 |
+
'TCLTK_INCLUDES': '-I/root/envs/llava/include',
|
| 946 |
+
'TCLTK_LIBS': '-L/root/envs/llava/lib '
|
| 947 |
+
'-ltcl8.6 -ltk8.6',
|
| 948 |
+
'TESTOPTS': '',
|
| 949 |
+
'TESTPATH': '',
|
| 950 |
+
'TESTPYTHON': './python',
|
| 951 |
+
'TESTPYTHONOPTS': '',
|
| 952 |
+
'TESTRUNNER': './python '
|
| 953 |
+
'/croot/python-split_1733933809325/work/Tools/scripts/run_tests.py',
|
| 954 |
+
'TESTSUBDIRS': 'ctypes/test \\',
|
| 955 |
+
'TESTTIMEOUT': 1200,
|
| 956 |
+
'TEST_MODULES': 'yes',
|
| 957 |
+
'THREAD_STACK_SIZE': 0,
|
| 958 |
+
'TIMEMODULE_LIB': 0,
|
| 959 |
+
'TIME_WITH_SYS_TIME': 1,
|
| 960 |
+
'TM_IN_SYS_TIME': 0,
|
| 961 |
+
'TZPATH': '/root/envs/llava/share/zoneinfo:/root/envs/llava/share/tzinfo',
|
| 962 |
+
'UNICODE_DEPS': '\\',
|
| 963 |
+
'UNIVERSALSDK': '',
|
| 964 |
+
'UPDATE_FILE': '/croot/python-split_1733933809325/work/Tools/scripts/update_file.py',
|
| 965 |
+
'USE_COMPUTED_GOTOS': 1,
|
| 966 |
+
'VERSION': '3.10',
|
| 967 |
+
'VPATH': '/croot/python-split_1733933809325/work',
|
| 968 |
+
'WHEEL_PKG_DIR': '',
|
| 969 |
+
'WINDOW_HAS_FLAGS': 1,
|
| 970 |
+
'WITH_DECIMAL_CONTEXTVAR': 1,
|
| 971 |
+
'WITH_DOC_STRINGS': 1,
|
| 972 |
+
'WITH_DTRACE': 0,
|
| 973 |
+
'WITH_DYLD': 0,
|
| 974 |
+
'WITH_EDITLINE': 0,
|
| 975 |
+
'WITH_LIBINTL': 0,
|
| 976 |
+
'WITH_NEXT_FRAMEWORK': 0,
|
| 977 |
+
'WITH_PYMALLOC': 1,
|
| 978 |
+
'WITH_VALGRIND': 0,
|
| 979 |
+
'X87_DOUBLE_ROUNDING': 0,
|
| 980 |
+
'XMLLIBSUBDIRS': 'xml xml/dom xml/etree xml/parsers xml/sax',
|
| 981 |
+
'abs_builddir': '/croot/python-split_1733933809325/work/build-static',
|
| 982 |
+
'abs_srcdir': '/croot/python-split_1733933809325/work',
|
| 983 |
+
'datarootdir': '/root/envs/llava/share',
|
| 984 |
+
'exec_prefix': '/root/envs/llava',
|
| 985 |
+
'prefix': '/root/envs/llava',
|
| 986 |
+
'srcdir': '/croot/python-split_1733933809325/work'}
|
llava/lib/python3.10/fractions.py
ADDED
|
@@ -0,0 +1,748 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Originally contributed by Sjoerd Mullender.
|
| 2 |
+
# Significantly modified by Jeffrey Yasskin <jyasskin at gmail.com>.
|
| 3 |
+
|
| 4 |
+
"""Fraction, infinite-precision, real numbers."""
|
| 5 |
+
|
| 6 |
+
from decimal import Decimal
|
| 7 |
+
import math
|
| 8 |
+
import numbers
|
| 9 |
+
import operator
|
| 10 |
+
import re
|
| 11 |
+
import sys
|
| 12 |
+
|
| 13 |
+
__all__ = ['Fraction']
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
# Constants related to the hash implementation; hash(x) is based
|
| 17 |
+
# on the reduction of x modulo the prime _PyHASH_MODULUS.
|
| 18 |
+
_PyHASH_MODULUS = sys.hash_info.modulus
|
| 19 |
+
# Value to be used for rationals that reduce to infinity modulo
|
| 20 |
+
# _PyHASH_MODULUS.
|
| 21 |
+
_PyHASH_INF = sys.hash_info.inf
|
| 22 |
+
|
| 23 |
+
_RATIONAL_FORMAT = re.compile(r"""
|
| 24 |
+
\A\s* # optional whitespace at the start, then
|
| 25 |
+
(?P<sign>[-+]?) # an optional sign, then
|
| 26 |
+
(?=\d|\.\d) # lookahead for digit or .digit
|
| 27 |
+
(?P<num>\d*) # numerator (possibly empty)
|
| 28 |
+
(?: # followed by
|
| 29 |
+
(?:/(?P<denom>\d+))? # an optional denominator
|
| 30 |
+
| # or
|
| 31 |
+
(?:\.(?P<decimal>\d*))? # an optional fractional part
|
| 32 |
+
(?:E(?P<exp>[-+]?\d+))? # and optional exponent
|
| 33 |
+
)
|
| 34 |
+
\s*\Z # and optional whitespace to finish
|
| 35 |
+
""", re.VERBOSE | re.IGNORECASE)
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
class Fraction(numbers.Rational):
|
| 39 |
+
"""This class implements rational numbers.
|
| 40 |
+
|
| 41 |
+
In the two-argument form of the constructor, Fraction(8, 6) will
|
| 42 |
+
produce a rational number equivalent to 4/3. Both arguments must
|
| 43 |
+
be Rational. The numerator defaults to 0 and the denominator
|
| 44 |
+
defaults to 1 so that Fraction(3) == 3 and Fraction() == 0.
|
| 45 |
+
|
| 46 |
+
Fractions can also be constructed from:
|
| 47 |
+
|
| 48 |
+
- numeric strings similar to those accepted by the
|
| 49 |
+
float constructor (for example, '-2.3' or '1e10')
|
| 50 |
+
|
| 51 |
+
- strings of the form '123/456'
|
| 52 |
+
|
| 53 |
+
- float and Decimal instances
|
| 54 |
+
|
| 55 |
+
- other Rational instances (including integers)
|
| 56 |
+
|
| 57 |
+
"""
|
| 58 |
+
|
| 59 |
+
__slots__ = ('_numerator', '_denominator')
|
| 60 |
+
|
| 61 |
+
# We're immutable, so use __new__ not __init__
|
| 62 |
+
def __new__(cls, numerator=0, denominator=None, *, _normalize=True):
|
| 63 |
+
"""Constructs a Rational.
|
| 64 |
+
|
| 65 |
+
Takes a string like '3/2' or '1.5', another Rational instance, a
|
| 66 |
+
numerator/denominator pair, or a float.
|
| 67 |
+
|
| 68 |
+
Examples
|
| 69 |
+
--------
|
| 70 |
+
|
| 71 |
+
>>> Fraction(10, -8)
|
| 72 |
+
Fraction(-5, 4)
|
| 73 |
+
>>> Fraction(Fraction(1, 7), 5)
|
| 74 |
+
Fraction(1, 35)
|
| 75 |
+
>>> Fraction(Fraction(1, 7), Fraction(2, 3))
|
| 76 |
+
Fraction(3, 14)
|
| 77 |
+
>>> Fraction('314')
|
| 78 |
+
Fraction(314, 1)
|
| 79 |
+
>>> Fraction('-35/4')
|
| 80 |
+
Fraction(-35, 4)
|
| 81 |
+
>>> Fraction('3.1415') # conversion from numeric string
|
| 82 |
+
Fraction(6283, 2000)
|
| 83 |
+
>>> Fraction('-47e-2') # string may include a decimal exponent
|
| 84 |
+
Fraction(-47, 100)
|
| 85 |
+
>>> Fraction(1.47) # direct construction from float (exact conversion)
|
| 86 |
+
Fraction(6620291452234629, 4503599627370496)
|
| 87 |
+
>>> Fraction(2.25)
|
| 88 |
+
Fraction(9, 4)
|
| 89 |
+
>>> Fraction(Decimal('1.47'))
|
| 90 |
+
Fraction(147, 100)
|
| 91 |
+
|
| 92 |
+
"""
|
| 93 |
+
self = super(Fraction, cls).__new__(cls)
|
| 94 |
+
|
| 95 |
+
if denominator is None:
|
| 96 |
+
if type(numerator) is int:
|
| 97 |
+
self._numerator = numerator
|
| 98 |
+
self._denominator = 1
|
| 99 |
+
return self
|
| 100 |
+
|
| 101 |
+
elif isinstance(numerator, numbers.Rational):
|
| 102 |
+
self._numerator = numerator.numerator
|
| 103 |
+
self._denominator = numerator.denominator
|
| 104 |
+
return self
|
| 105 |
+
|
| 106 |
+
elif isinstance(numerator, (float, Decimal)):
|
| 107 |
+
# Exact conversion
|
| 108 |
+
self._numerator, self._denominator = numerator.as_integer_ratio()
|
| 109 |
+
return self
|
| 110 |
+
|
| 111 |
+
elif isinstance(numerator, str):
|
| 112 |
+
# Handle construction from strings.
|
| 113 |
+
m = _RATIONAL_FORMAT.match(numerator)
|
| 114 |
+
if m is None:
|
| 115 |
+
raise ValueError('Invalid literal for Fraction: %r' %
|
| 116 |
+
numerator)
|
| 117 |
+
numerator = int(m.group('num') or '0')
|
| 118 |
+
denom = m.group('denom')
|
| 119 |
+
if denom:
|
| 120 |
+
denominator = int(denom)
|
| 121 |
+
else:
|
| 122 |
+
denominator = 1
|
| 123 |
+
decimal = m.group('decimal')
|
| 124 |
+
if decimal:
|
| 125 |
+
scale = 10**len(decimal)
|
| 126 |
+
numerator = numerator * scale + int(decimal)
|
| 127 |
+
denominator *= scale
|
| 128 |
+
exp = m.group('exp')
|
| 129 |
+
if exp:
|
| 130 |
+
exp = int(exp)
|
| 131 |
+
if exp >= 0:
|
| 132 |
+
numerator *= 10**exp
|
| 133 |
+
else:
|
| 134 |
+
denominator *= 10**-exp
|
| 135 |
+
if m.group('sign') == '-':
|
| 136 |
+
numerator = -numerator
|
| 137 |
+
|
| 138 |
+
else:
|
| 139 |
+
raise TypeError("argument should be a string "
|
| 140 |
+
"or a Rational instance")
|
| 141 |
+
|
| 142 |
+
elif type(numerator) is int is type(denominator):
|
| 143 |
+
pass # *very* normal case
|
| 144 |
+
|
| 145 |
+
elif (isinstance(numerator, numbers.Rational) and
|
| 146 |
+
isinstance(denominator, numbers.Rational)):
|
| 147 |
+
numerator, denominator = (
|
| 148 |
+
numerator.numerator * denominator.denominator,
|
| 149 |
+
denominator.numerator * numerator.denominator
|
| 150 |
+
)
|
| 151 |
+
else:
|
| 152 |
+
raise TypeError("both arguments should be "
|
| 153 |
+
"Rational instances")
|
| 154 |
+
|
| 155 |
+
if denominator == 0:
|
| 156 |
+
raise ZeroDivisionError('Fraction(%s, 0)' % numerator)
|
| 157 |
+
if _normalize:
|
| 158 |
+
g = math.gcd(numerator, denominator)
|
| 159 |
+
if denominator < 0:
|
| 160 |
+
g = -g
|
| 161 |
+
numerator //= g
|
| 162 |
+
denominator //= g
|
| 163 |
+
self._numerator = numerator
|
| 164 |
+
self._denominator = denominator
|
| 165 |
+
return self
|
| 166 |
+
|
| 167 |
+
@classmethod
|
| 168 |
+
def from_float(cls, f):
|
| 169 |
+
"""Converts a finite float to a rational number, exactly.
|
| 170 |
+
|
| 171 |
+
Beware that Fraction.from_float(0.3) != Fraction(3, 10).
|
| 172 |
+
|
| 173 |
+
"""
|
| 174 |
+
if isinstance(f, numbers.Integral):
|
| 175 |
+
return cls(f)
|
| 176 |
+
elif not isinstance(f, float):
|
| 177 |
+
raise TypeError("%s.from_float() only takes floats, not %r (%s)" %
|
| 178 |
+
(cls.__name__, f, type(f).__name__))
|
| 179 |
+
return cls(*f.as_integer_ratio())
|
| 180 |
+
|
| 181 |
+
@classmethod
|
| 182 |
+
def from_decimal(cls, dec):
|
| 183 |
+
"""Converts a finite Decimal instance to a rational number, exactly."""
|
| 184 |
+
from decimal import Decimal
|
| 185 |
+
if isinstance(dec, numbers.Integral):
|
| 186 |
+
dec = Decimal(int(dec))
|
| 187 |
+
elif not isinstance(dec, Decimal):
|
| 188 |
+
raise TypeError(
|
| 189 |
+
"%s.from_decimal() only takes Decimals, not %r (%s)" %
|
| 190 |
+
(cls.__name__, dec, type(dec).__name__))
|
| 191 |
+
return cls(*dec.as_integer_ratio())
|
| 192 |
+
|
| 193 |
+
def as_integer_ratio(self):
|
| 194 |
+
"""Return the integer ratio as a tuple.
|
| 195 |
+
|
| 196 |
+
Return a tuple of two integers, whose ratio is equal to the
|
| 197 |
+
Fraction and with a positive denominator.
|
| 198 |
+
"""
|
| 199 |
+
return (self._numerator, self._denominator)
|
| 200 |
+
|
| 201 |
+
def limit_denominator(self, max_denominator=1000000):
|
| 202 |
+
"""Closest Fraction to self with denominator at most max_denominator.
|
| 203 |
+
|
| 204 |
+
>>> Fraction('3.141592653589793').limit_denominator(10)
|
| 205 |
+
Fraction(22, 7)
|
| 206 |
+
>>> Fraction('3.141592653589793').limit_denominator(100)
|
| 207 |
+
Fraction(311, 99)
|
| 208 |
+
>>> Fraction(4321, 8765).limit_denominator(10000)
|
| 209 |
+
Fraction(4321, 8765)
|
| 210 |
+
|
| 211 |
+
"""
|
| 212 |
+
# Algorithm notes: For any real number x, define a *best upper
|
| 213 |
+
# approximation* to x to be a rational number p/q such that:
|
| 214 |
+
#
|
| 215 |
+
# (1) p/q >= x, and
|
| 216 |
+
# (2) if p/q > r/s >= x then s > q, for any rational r/s.
|
| 217 |
+
#
|
| 218 |
+
# Define *best lower approximation* similarly. Then it can be
|
| 219 |
+
# proved that a rational number is a best upper or lower
|
| 220 |
+
# approximation to x if, and only if, it is a convergent or
|
| 221 |
+
# semiconvergent of the (unique shortest) continued fraction
|
| 222 |
+
# associated to x.
|
| 223 |
+
#
|
| 224 |
+
# To find a best rational approximation with denominator <= M,
|
| 225 |
+
# we find the best upper and lower approximations with
|
| 226 |
+
# denominator <= M and take whichever of these is closer to x.
|
| 227 |
+
# In the event of a tie, the bound with smaller denominator is
|
| 228 |
+
# chosen. If both denominators are equal (which can happen
|
| 229 |
+
# only when max_denominator == 1 and self is midway between
|
| 230 |
+
# two integers) the lower bound---i.e., the floor of self, is
|
| 231 |
+
# taken.
|
| 232 |
+
|
| 233 |
+
if max_denominator < 1:
|
| 234 |
+
raise ValueError("max_denominator should be at least 1")
|
| 235 |
+
if self._denominator <= max_denominator:
|
| 236 |
+
return Fraction(self)
|
| 237 |
+
|
| 238 |
+
p0, q0, p1, q1 = 0, 1, 1, 0
|
| 239 |
+
n, d = self._numerator, self._denominator
|
| 240 |
+
while True:
|
| 241 |
+
a = n//d
|
| 242 |
+
q2 = q0+a*q1
|
| 243 |
+
if q2 > max_denominator:
|
| 244 |
+
break
|
| 245 |
+
p0, q0, p1, q1 = p1, q1, p0+a*p1, q2
|
| 246 |
+
n, d = d, n-a*d
|
| 247 |
+
|
| 248 |
+
k = (max_denominator-q0)//q1
|
| 249 |
+
bound1 = Fraction(p0+k*p1, q0+k*q1)
|
| 250 |
+
bound2 = Fraction(p1, q1)
|
| 251 |
+
if abs(bound2 - self) <= abs(bound1-self):
|
| 252 |
+
return bound2
|
| 253 |
+
else:
|
| 254 |
+
return bound1
|
| 255 |
+
|
| 256 |
+
@property
|
| 257 |
+
def numerator(a):
|
| 258 |
+
return a._numerator
|
| 259 |
+
|
| 260 |
+
@property
|
| 261 |
+
def denominator(a):
|
| 262 |
+
return a._denominator
|
| 263 |
+
|
| 264 |
+
def __repr__(self):
|
| 265 |
+
"""repr(self)"""
|
| 266 |
+
return '%s(%s, %s)' % (self.__class__.__name__,
|
| 267 |
+
self._numerator, self._denominator)
|
| 268 |
+
|
| 269 |
+
def __str__(self):
|
| 270 |
+
"""str(self)"""
|
| 271 |
+
if self._denominator == 1:
|
| 272 |
+
return str(self._numerator)
|
| 273 |
+
else:
|
| 274 |
+
return '%s/%s' % (self._numerator, self._denominator)
|
| 275 |
+
|
| 276 |
+
def _operator_fallbacks(monomorphic_operator, fallback_operator):
|
| 277 |
+
"""Generates forward and reverse operators given a purely-rational
|
| 278 |
+
operator and a function from the operator module.
|
| 279 |
+
|
| 280 |
+
Use this like:
|
| 281 |
+
__op__, __rop__ = _operator_fallbacks(just_rational_op, operator.op)
|
| 282 |
+
|
| 283 |
+
In general, we want to implement the arithmetic operations so
|
| 284 |
+
that mixed-mode operations either call an implementation whose
|
| 285 |
+
author knew about the types of both arguments, or convert both
|
| 286 |
+
to the nearest built in type and do the operation there. In
|
| 287 |
+
Fraction, that means that we define __add__ and __radd__ as:
|
| 288 |
+
|
| 289 |
+
def __add__(self, other):
|
| 290 |
+
# Both types have numerators/denominator attributes,
|
| 291 |
+
# so do the operation directly
|
| 292 |
+
if isinstance(other, (int, Fraction)):
|
| 293 |
+
return Fraction(self.numerator * other.denominator +
|
| 294 |
+
other.numerator * self.denominator,
|
| 295 |
+
self.denominator * other.denominator)
|
| 296 |
+
# float and complex don't have those operations, but we
|
| 297 |
+
# know about those types, so special case them.
|
| 298 |
+
elif isinstance(other, float):
|
| 299 |
+
return float(self) + other
|
| 300 |
+
elif isinstance(other, complex):
|
| 301 |
+
return complex(self) + other
|
| 302 |
+
# Let the other type take over.
|
| 303 |
+
return NotImplemented
|
| 304 |
+
|
| 305 |
+
def __radd__(self, other):
|
| 306 |
+
# radd handles more types than add because there's
|
| 307 |
+
# nothing left to fall back to.
|
| 308 |
+
if isinstance(other, numbers.Rational):
|
| 309 |
+
return Fraction(self.numerator * other.denominator +
|
| 310 |
+
other.numerator * self.denominator,
|
| 311 |
+
self.denominator * other.denominator)
|
| 312 |
+
elif isinstance(other, Real):
|
| 313 |
+
return float(other) + float(self)
|
| 314 |
+
elif isinstance(other, Complex):
|
| 315 |
+
return complex(other) + complex(self)
|
| 316 |
+
return NotImplemented
|
| 317 |
+
|
| 318 |
+
|
| 319 |
+
There are 5 different cases for a mixed-type addition on
|
| 320 |
+
Fraction. I'll refer to all of the above code that doesn't
|
| 321 |
+
refer to Fraction, float, or complex as "boilerplate". 'r'
|
| 322 |
+
will be an instance of Fraction, which is a subtype of
|
| 323 |
+
Rational (r : Fraction <: Rational), and b : B <:
|
| 324 |
+
Complex. The first three involve 'r + b':
|
| 325 |
+
|
| 326 |
+
1. If B <: Fraction, int, float, or complex, we handle
|
| 327 |
+
that specially, and all is well.
|
| 328 |
+
2. If Fraction falls back to the boilerplate code, and it
|
| 329 |
+
were to return a value from __add__, we'd miss the
|
| 330 |
+
possibility that B defines a more intelligent __radd__,
|
| 331 |
+
so the boilerplate should return NotImplemented from
|
| 332 |
+
__add__. In particular, we don't handle Rational
|
| 333 |
+
here, even though we could get an exact answer, in case
|
| 334 |
+
the other type wants to do something special.
|
| 335 |
+
3. If B <: Fraction, Python tries B.__radd__ before
|
| 336 |
+
Fraction.__add__. This is ok, because it was
|
| 337 |
+
implemented with knowledge of Fraction, so it can
|
| 338 |
+
handle those instances before delegating to Real or
|
| 339 |
+
Complex.
|
| 340 |
+
|
| 341 |
+
The next two situations describe 'b + r'. We assume that b
|
| 342 |
+
didn't know about Fraction in its implementation, and that it
|
| 343 |
+
uses similar boilerplate code:
|
| 344 |
+
|
| 345 |
+
4. If B <: Rational, then __radd_ converts both to the
|
| 346 |
+
builtin rational type (hey look, that's us) and
|
| 347 |
+
proceeds.
|
| 348 |
+
5. Otherwise, __radd__ tries to find the nearest common
|
| 349 |
+
base ABC, and fall back to its builtin type. Since this
|
| 350 |
+
class doesn't subclass a concrete type, there's no
|
| 351 |
+
implementation to fall back to, so we need to try as
|
| 352 |
+
hard as possible to return an actual value, or the user
|
| 353 |
+
will get a TypeError.
|
| 354 |
+
|
| 355 |
+
"""
|
| 356 |
+
def forward(a, b):
|
| 357 |
+
if isinstance(b, (int, Fraction)):
|
| 358 |
+
return monomorphic_operator(a, b)
|
| 359 |
+
elif isinstance(b, float):
|
| 360 |
+
return fallback_operator(float(a), b)
|
| 361 |
+
elif isinstance(b, complex):
|
| 362 |
+
return fallback_operator(complex(a), b)
|
| 363 |
+
else:
|
| 364 |
+
return NotImplemented
|
| 365 |
+
forward.__name__ = '__' + fallback_operator.__name__ + '__'
|
| 366 |
+
forward.__doc__ = monomorphic_operator.__doc__
|
| 367 |
+
|
| 368 |
+
def reverse(b, a):
|
| 369 |
+
if isinstance(a, numbers.Rational):
|
| 370 |
+
# Includes ints.
|
| 371 |
+
return monomorphic_operator(a, b)
|
| 372 |
+
elif isinstance(a, numbers.Real):
|
| 373 |
+
return fallback_operator(float(a), float(b))
|
| 374 |
+
elif isinstance(a, numbers.Complex):
|
| 375 |
+
return fallback_operator(complex(a), complex(b))
|
| 376 |
+
else:
|
| 377 |
+
return NotImplemented
|
| 378 |
+
reverse.__name__ = '__r' + fallback_operator.__name__ + '__'
|
| 379 |
+
reverse.__doc__ = monomorphic_operator.__doc__
|
| 380 |
+
|
| 381 |
+
return forward, reverse
|
| 382 |
+
|
| 383 |
+
# Rational arithmetic algorithms: Knuth, TAOCP, Volume 2, 4.5.1.
|
| 384 |
+
#
|
| 385 |
+
# Assume input fractions a and b are normalized.
|
| 386 |
+
#
|
| 387 |
+
# 1) Consider addition/subtraction.
|
| 388 |
+
#
|
| 389 |
+
# Let g = gcd(da, db). Then
|
| 390 |
+
#
|
| 391 |
+
# na nb na*db ± nb*da
|
| 392 |
+
# a ± b == -- ± -- == ------------- ==
|
| 393 |
+
# da db da*db
|
| 394 |
+
#
|
| 395 |
+
# na*(db//g) ± nb*(da//g) t
|
| 396 |
+
# == ----------------------- == -
|
| 397 |
+
# (da*db)//g d
|
| 398 |
+
#
|
| 399 |
+
# Now, if g > 1, we're working with smaller integers.
|
| 400 |
+
#
|
| 401 |
+
# Note, that t, (da//g) and (db//g) are pairwise coprime.
|
| 402 |
+
#
|
| 403 |
+
# Indeed, (da//g) and (db//g) share no common factors (they were
|
| 404 |
+
# removed) and da is coprime with na (since input fractions are
|
| 405 |
+
# normalized), hence (da//g) and na are coprime. By symmetry,
|
| 406 |
+
# (db//g) and nb are coprime too. Then,
|
| 407 |
+
#
|
| 408 |
+
# gcd(t, da//g) == gcd(na*(db//g), da//g) == 1
|
| 409 |
+
# gcd(t, db//g) == gcd(nb*(da//g), db//g) == 1
|
| 410 |
+
#
|
| 411 |
+
# Above allows us optimize reduction of the result to lowest
|
| 412 |
+
# terms. Indeed,
|
| 413 |
+
#
|
| 414 |
+
# g2 = gcd(t, d) == gcd(t, (da//g)*(db//g)*g) == gcd(t, g)
|
| 415 |
+
#
|
| 416 |
+
# t//g2 t//g2
|
| 417 |
+
# a ± b == ----------------------- == ----------------
|
| 418 |
+
# (da//g)*(db//g)*(g//g2) (da//g)*(db//g2)
|
| 419 |
+
#
|
| 420 |
+
# is a normalized fraction. This is useful because the unnormalized
|
| 421 |
+
# denominator d could be much larger than g.
|
| 422 |
+
#
|
| 423 |
+
# We should special-case g == 1 (and g2 == 1), since 60.8% of
|
| 424 |
+
# randomly-chosen integers are coprime:
|
| 425 |
+
# https://en.wikipedia.org/wiki/Coprime_integers#Probability_of_coprimality
|
| 426 |
+
# Note, that g2 == 1 always for fractions, obtained from floats: here
|
| 427 |
+
# g is a power of 2 and the unnormalized numerator t is an odd integer.
|
| 428 |
+
#
|
| 429 |
+
# 2) Consider multiplication
|
| 430 |
+
#
|
| 431 |
+
# Let g1 = gcd(na, db) and g2 = gcd(nb, da), then
|
| 432 |
+
#
|
| 433 |
+
# na*nb na*nb (na//g1)*(nb//g2)
|
| 434 |
+
# a*b == ----- == ----- == -----------------
|
| 435 |
+
# da*db db*da (db//g1)*(da//g2)
|
| 436 |
+
#
|
| 437 |
+
# Note, that after divisions we're multiplying smaller integers.
|
| 438 |
+
#
|
| 439 |
+
# Also, the resulting fraction is normalized, because each of
|
| 440 |
+
# two factors in the numerator is coprime to each of the two factors
|
| 441 |
+
# in the denominator.
|
| 442 |
+
#
|
| 443 |
+
# Indeed, pick (na//g1). It's coprime with (da//g2), because input
|
| 444 |
+
# fractions are normalized. It's also coprime with (db//g1), because
|
| 445 |
+
# common factors are removed by g1 == gcd(na, db).
|
| 446 |
+
#
|
| 447 |
+
# As for addition/subtraction, we should special-case g1 == 1
|
| 448 |
+
# and g2 == 1 for same reason. That happens also for multiplying
|
| 449 |
+
# rationals, obtained from floats.
|
| 450 |
+
|
| 451 |
+
def _add(a, b):
|
| 452 |
+
"""a + b"""
|
| 453 |
+
na, da = a.numerator, a.denominator
|
| 454 |
+
nb, db = b.numerator, b.denominator
|
| 455 |
+
g = math.gcd(da, db)
|
| 456 |
+
if g == 1:
|
| 457 |
+
return Fraction(na * db + da * nb, da * db, _normalize=False)
|
| 458 |
+
s = da // g
|
| 459 |
+
t = na * (db // g) + nb * s
|
| 460 |
+
g2 = math.gcd(t, g)
|
| 461 |
+
if g2 == 1:
|
| 462 |
+
return Fraction(t, s * db, _normalize=False)
|
| 463 |
+
return Fraction(t // g2, s * (db // g2), _normalize=False)
|
| 464 |
+
|
| 465 |
+
__add__, __radd__ = _operator_fallbacks(_add, operator.add)
|
| 466 |
+
|
| 467 |
+
def _sub(a, b):
|
| 468 |
+
"""a - b"""
|
| 469 |
+
na, da = a.numerator, a.denominator
|
| 470 |
+
nb, db = b.numerator, b.denominator
|
| 471 |
+
g = math.gcd(da, db)
|
| 472 |
+
if g == 1:
|
| 473 |
+
return Fraction(na * db - da * nb, da * db, _normalize=False)
|
| 474 |
+
s = da // g
|
| 475 |
+
t = na * (db // g) - nb * s
|
| 476 |
+
g2 = math.gcd(t, g)
|
| 477 |
+
if g2 == 1:
|
| 478 |
+
return Fraction(t, s * db, _normalize=False)
|
| 479 |
+
return Fraction(t // g2, s * (db // g2), _normalize=False)
|
| 480 |
+
|
| 481 |
+
__sub__, __rsub__ = _operator_fallbacks(_sub, operator.sub)
|
| 482 |
+
|
| 483 |
+
def _mul(a, b):
|
| 484 |
+
"""a * b"""
|
| 485 |
+
na, da = a.numerator, a.denominator
|
| 486 |
+
nb, db = b.numerator, b.denominator
|
| 487 |
+
g1 = math.gcd(na, db)
|
| 488 |
+
if g1 > 1:
|
| 489 |
+
na //= g1
|
| 490 |
+
db //= g1
|
| 491 |
+
g2 = math.gcd(nb, da)
|
| 492 |
+
if g2 > 1:
|
| 493 |
+
nb //= g2
|
| 494 |
+
da //= g2
|
| 495 |
+
return Fraction(na * nb, db * da, _normalize=False)
|
| 496 |
+
|
| 497 |
+
__mul__, __rmul__ = _operator_fallbacks(_mul, operator.mul)
|
| 498 |
+
|
| 499 |
+
def _div(a, b):
|
| 500 |
+
"""a / b"""
|
| 501 |
+
# Same as _mul(), with inversed b.
|
| 502 |
+
na, da = a.numerator, a.denominator
|
| 503 |
+
nb, db = b.numerator, b.denominator
|
| 504 |
+
g1 = math.gcd(na, nb)
|
| 505 |
+
if g1 > 1:
|
| 506 |
+
na //= g1
|
| 507 |
+
nb //= g1
|
| 508 |
+
g2 = math.gcd(db, da)
|
| 509 |
+
if g2 > 1:
|
| 510 |
+
da //= g2
|
| 511 |
+
db //= g2
|
| 512 |
+
n, d = na * db, nb * da
|
| 513 |
+
if d < 0:
|
| 514 |
+
n, d = -n, -d
|
| 515 |
+
return Fraction(n, d, _normalize=False)
|
| 516 |
+
|
| 517 |
+
__truediv__, __rtruediv__ = _operator_fallbacks(_div, operator.truediv)
|
| 518 |
+
|
| 519 |
+
def _floordiv(a, b):
|
| 520 |
+
"""a // b"""
|
| 521 |
+
return (a.numerator * b.denominator) // (a.denominator * b.numerator)
|
| 522 |
+
|
| 523 |
+
__floordiv__, __rfloordiv__ = _operator_fallbacks(_floordiv, operator.floordiv)
|
| 524 |
+
|
| 525 |
+
def _divmod(a, b):
|
| 526 |
+
"""(a // b, a % b)"""
|
| 527 |
+
da, db = a.denominator, b.denominator
|
| 528 |
+
div, n_mod = divmod(a.numerator * db, da * b.numerator)
|
| 529 |
+
return div, Fraction(n_mod, da * db)
|
| 530 |
+
|
| 531 |
+
__divmod__, __rdivmod__ = _operator_fallbacks(_divmod, divmod)
|
| 532 |
+
|
| 533 |
+
def _mod(a, b):
|
| 534 |
+
"""a % b"""
|
| 535 |
+
da, db = a.denominator, b.denominator
|
| 536 |
+
return Fraction((a.numerator * db) % (b.numerator * da), da * db)
|
| 537 |
+
|
| 538 |
+
__mod__, __rmod__ = _operator_fallbacks(_mod, operator.mod)
|
| 539 |
+
|
| 540 |
+
def __pow__(a, b):
|
| 541 |
+
"""a ** b
|
| 542 |
+
|
| 543 |
+
If b is not an integer, the result will be a float or complex
|
| 544 |
+
since roots are generally irrational. If b is an integer, the
|
| 545 |
+
result will be rational.
|
| 546 |
+
|
| 547 |
+
"""
|
| 548 |
+
if isinstance(b, numbers.Rational):
|
| 549 |
+
if b.denominator == 1:
|
| 550 |
+
power = b.numerator
|
| 551 |
+
if power >= 0:
|
| 552 |
+
return Fraction(a._numerator ** power,
|
| 553 |
+
a._denominator ** power,
|
| 554 |
+
_normalize=False)
|
| 555 |
+
elif a._numerator >= 0:
|
| 556 |
+
return Fraction(a._denominator ** -power,
|
| 557 |
+
a._numerator ** -power,
|
| 558 |
+
_normalize=False)
|
| 559 |
+
else:
|
| 560 |
+
return Fraction((-a._denominator) ** -power,
|
| 561 |
+
(-a._numerator) ** -power,
|
| 562 |
+
_normalize=False)
|
| 563 |
+
else:
|
| 564 |
+
# A fractional power will generally produce an
|
| 565 |
+
# irrational number.
|
| 566 |
+
return float(a) ** float(b)
|
| 567 |
+
else:
|
| 568 |
+
return float(a) ** b
|
| 569 |
+
|
| 570 |
+
def __rpow__(b, a):
|
| 571 |
+
"""a ** b"""
|
| 572 |
+
if b._denominator == 1 and b._numerator >= 0:
|
| 573 |
+
# If a is an int, keep it that way if possible.
|
| 574 |
+
return a ** b._numerator
|
| 575 |
+
|
| 576 |
+
if isinstance(a, numbers.Rational):
|
| 577 |
+
return Fraction(a.numerator, a.denominator) ** b
|
| 578 |
+
|
| 579 |
+
if b._denominator == 1:
|
| 580 |
+
return a ** b._numerator
|
| 581 |
+
|
| 582 |
+
return a ** float(b)
|
| 583 |
+
|
| 584 |
+
def __pos__(a):
|
| 585 |
+
"""+a: Coerces a subclass instance to Fraction"""
|
| 586 |
+
return Fraction(a._numerator, a._denominator, _normalize=False)
|
| 587 |
+
|
| 588 |
+
def __neg__(a):
|
| 589 |
+
"""-a"""
|
| 590 |
+
return Fraction(-a._numerator, a._denominator, _normalize=False)
|
| 591 |
+
|
| 592 |
+
def __abs__(a):
|
| 593 |
+
"""abs(a)"""
|
| 594 |
+
return Fraction(abs(a._numerator), a._denominator, _normalize=False)
|
| 595 |
+
|
| 596 |
+
def __trunc__(a):
|
| 597 |
+
"""trunc(a)"""
|
| 598 |
+
if a._numerator < 0:
|
| 599 |
+
return -(-a._numerator // a._denominator)
|
| 600 |
+
else:
|
| 601 |
+
return a._numerator // a._denominator
|
| 602 |
+
|
| 603 |
+
def __floor__(a):
|
| 604 |
+
"""math.floor(a)"""
|
| 605 |
+
return a.numerator // a.denominator
|
| 606 |
+
|
| 607 |
+
def __ceil__(a):
|
| 608 |
+
"""math.ceil(a)"""
|
| 609 |
+
# The negations cleverly convince floordiv to return the ceiling.
|
| 610 |
+
return -(-a.numerator // a.denominator)
|
| 611 |
+
|
| 612 |
+
def __round__(self, ndigits=None):
|
| 613 |
+
"""round(self, ndigits)
|
| 614 |
+
|
| 615 |
+
Rounds half toward even.
|
| 616 |
+
"""
|
| 617 |
+
if ndigits is None:
|
| 618 |
+
floor, remainder = divmod(self.numerator, self.denominator)
|
| 619 |
+
if remainder * 2 < self.denominator:
|
| 620 |
+
return floor
|
| 621 |
+
elif remainder * 2 > self.denominator:
|
| 622 |
+
return floor + 1
|
| 623 |
+
# Deal with the half case:
|
| 624 |
+
elif floor % 2 == 0:
|
| 625 |
+
return floor
|
| 626 |
+
else:
|
| 627 |
+
return floor + 1
|
| 628 |
+
shift = 10**abs(ndigits)
|
| 629 |
+
# See _operator_fallbacks.forward to check that the results of
|
| 630 |
+
# these operations will always be Fraction and therefore have
|
| 631 |
+
# round().
|
| 632 |
+
if ndigits > 0:
|
| 633 |
+
return Fraction(round(self * shift), shift)
|
| 634 |
+
else:
|
| 635 |
+
return Fraction(round(self / shift) * shift)
|
| 636 |
+
|
| 637 |
+
def __hash__(self):
|
| 638 |
+
"""hash(self)"""
|
| 639 |
+
|
| 640 |
+
# To make sure that the hash of a Fraction agrees with the hash
|
| 641 |
+
# of a numerically equal integer, float or Decimal instance, we
|
| 642 |
+
# follow the rules for numeric hashes outlined in the
|
| 643 |
+
# documentation. (See library docs, 'Built-in Types').
|
| 644 |
+
|
| 645 |
+
try:
|
| 646 |
+
dinv = pow(self._denominator, -1, _PyHASH_MODULUS)
|
| 647 |
+
except ValueError:
|
| 648 |
+
# ValueError means there is no modular inverse.
|
| 649 |
+
hash_ = _PyHASH_INF
|
| 650 |
+
else:
|
| 651 |
+
# The general algorithm now specifies that the absolute value of
|
| 652 |
+
# the hash is
|
| 653 |
+
# (|N| * dinv) % P
|
| 654 |
+
# where N is self._numerator and P is _PyHASH_MODULUS. That's
|
| 655 |
+
# optimized here in two ways: first, for a non-negative int i,
|
| 656 |
+
# hash(i) == i % P, but the int hash implementation doesn't need
|
| 657 |
+
# to divide, and is faster than doing % P explicitly. So we do
|
| 658 |
+
# hash(|N| * dinv)
|
| 659 |
+
# instead. Second, N is unbounded, so its product with dinv may
|
| 660 |
+
# be arbitrarily expensive to compute. The final answer is the
|
| 661 |
+
# same if we use the bounded |N| % P instead, which can again
|
| 662 |
+
# be done with an int hash() call. If 0 <= i < P, hash(i) == i,
|
| 663 |
+
# so this nested hash() call wastes a bit of time making a
|
| 664 |
+
# redundant copy when |N| < P, but can save an arbitrarily large
|
| 665 |
+
# amount of computation for large |N|.
|
| 666 |
+
hash_ = hash(hash(abs(self._numerator)) * dinv)
|
| 667 |
+
result = hash_ if self._numerator >= 0 else -hash_
|
| 668 |
+
return -2 if result == -1 else result
|
| 669 |
+
|
| 670 |
+
def __eq__(a, b):
|
| 671 |
+
"""a == b"""
|
| 672 |
+
if type(b) is int:
|
| 673 |
+
return a._numerator == b and a._denominator == 1
|
| 674 |
+
if isinstance(b, numbers.Rational):
|
| 675 |
+
return (a._numerator == b.numerator and
|
| 676 |
+
a._denominator == b.denominator)
|
| 677 |
+
if isinstance(b, numbers.Complex) and b.imag == 0:
|
| 678 |
+
b = b.real
|
| 679 |
+
if isinstance(b, float):
|
| 680 |
+
if math.isnan(b) or math.isinf(b):
|
| 681 |
+
# comparisons with an infinity or nan should behave in
|
| 682 |
+
# the same way for any finite a, so treat a as zero.
|
| 683 |
+
return 0.0 == b
|
| 684 |
+
else:
|
| 685 |
+
return a == a.from_float(b)
|
| 686 |
+
else:
|
| 687 |
+
# Since a doesn't know how to compare with b, let's give b
|
| 688 |
+
# a chance to compare itself with a.
|
| 689 |
+
return NotImplemented
|
| 690 |
+
|
| 691 |
+
def _richcmp(self, other, op):
|
| 692 |
+
"""Helper for comparison operators, for internal use only.
|
| 693 |
+
|
| 694 |
+
Implement comparison between a Rational instance `self`, and
|
| 695 |
+
either another Rational instance or a float `other`. If
|
| 696 |
+
`other` is not a Rational instance or a float, return
|
| 697 |
+
NotImplemented. `op` should be one of the six standard
|
| 698 |
+
comparison operators.
|
| 699 |
+
|
| 700 |
+
"""
|
| 701 |
+
# convert other to a Rational instance where reasonable.
|
| 702 |
+
if isinstance(other, numbers.Rational):
|
| 703 |
+
return op(self._numerator * other.denominator,
|
| 704 |
+
self._denominator * other.numerator)
|
| 705 |
+
if isinstance(other, float):
|
| 706 |
+
if math.isnan(other) or math.isinf(other):
|
| 707 |
+
return op(0.0, other)
|
| 708 |
+
else:
|
| 709 |
+
return op(self, self.from_float(other))
|
| 710 |
+
else:
|
| 711 |
+
return NotImplemented
|
| 712 |
+
|
| 713 |
+
def __lt__(a, b):
|
| 714 |
+
"""a < b"""
|
| 715 |
+
return a._richcmp(b, operator.lt)
|
| 716 |
+
|
| 717 |
+
def __gt__(a, b):
|
| 718 |
+
"""a > b"""
|
| 719 |
+
return a._richcmp(b, operator.gt)
|
| 720 |
+
|
| 721 |
+
def __le__(a, b):
|
| 722 |
+
"""a <= b"""
|
| 723 |
+
return a._richcmp(b, operator.le)
|
| 724 |
+
|
| 725 |
+
def __ge__(a, b):
|
| 726 |
+
"""a >= b"""
|
| 727 |
+
return a._richcmp(b, operator.ge)
|
| 728 |
+
|
| 729 |
+
def __bool__(a):
|
| 730 |
+
"""a != 0"""
|
| 731 |
+
# bpo-39274: Use bool() because (a._numerator != 0) can return an
|
| 732 |
+
# object which is not a bool.
|
| 733 |
+
return bool(a._numerator)
|
| 734 |
+
|
| 735 |
+
# support for pickling, copy, and deepcopy
|
| 736 |
+
|
| 737 |
+
def __reduce__(self):
|
| 738 |
+
return (self.__class__, (str(self),))
|
| 739 |
+
|
| 740 |
+
def __copy__(self):
|
| 741 |
+
if type(self) == Fraction:
|
| 742 |
+
return self # I'm immutable; therefore I am my own clone
|
| 743 |
+
return self.__class__(self._numerator, self._denominator)
|
| 744 |
+
|
| 745 |
+
def __deepcopy__(self, memo):
|
| 746 |
+
if type(self) == Fraction:
|
| 747 |
+
return self # My components are also immutable
|
| 748 |
+
return self.__class__(self._numerator, self._denominator)
|
llava/lib/python3.10/getpass.py
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Utilities to get a password and/or the current user name.
|
| 2 |
+
|
| 3 |
+
getpass(prompt[, stream]) - Prompt for a password, with echo turned off.
|
| 4 |
+
getuser() - Get the user name from the environment or password database.
|
| 5 |
+
|
| 6 |
+
GetPassWarning - This UserWarning is issued when getpass() cannot prevent
|
| 7 |
+
echoing of the password contents while reading.
|
| 8 |
+
|
| 9 |
+
On Windows, the msvcrt module will be used.
|
| 10 |
+
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
# Authors: Piers Lauder (original)
|
| 14 |
+
# Guido van Rossum (Windows support and cleanup)
|
| 15 |
+
# Gregory P. Smith (tty support & GetPassWarning)
|
| 16 |
+
|
| 17 |
+
import contextlib
|
| 18 |
+
import io
|
| 19 |
+
import os
|
| 20 |
+
import sys
|
| 21 |
+
import warnings
|
| 22 |
+
|
| 23 |
+
__all__ = ["getpass","getuser","GetPassWarning"]
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
class GetPassWarning(UserWarning): pass
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def unix_getpass(prompt='Password: ', stream=None):
|
| 30 |
+
"""Prompt for a password, with echo turned off.
|
| 31 |
+
|
| 32 |
+
Args:
|
| 33 |
+
prompt: Written on stream to ask for the input. Default: 'Password: '
|
| 34 |
+
stream: A writable file object to display the prompt. Defaults to
|
| 35 |
+
the tty. If no tty is available defaults to sys.stderr.
|
| 36 |
+
Returns:
|
| 37 |
+
The seKr3t input.
|
| 38 |
+
Raises:
|
| 39 |
+
EOFError: If our input tty or stdin was closed.
|
| 40 |
+
GetPassWarning: When we were unable to turn echo off on the input.
|
| 41 |
+
|
| 42 |
+
Always restores terminal settings before returning.
|
| 43 |
+
"""
|
| 44 |
+
passwd = None
|
| 45 |
+
with contextlib.ExitStack() as stack:
|
| 46 |
+
try:
|
| 47 |
+
# Always try reading and writing directly on the tty first.
|
| 48 |
+
fd = os.open('/dev/tty', os.O_RDWR|os.O_NOCTTY)
|
| 49 |
+
tty = io.FileIO(fd, 'w+')
|
| 50 |
+
stack.enter_context(tty)
|
| 51 |
+
input = io.TextIOWrapper(tty)
|
| 52 |
+
stack.enter_context(input)
|
| 53 |
+
if not stream:
|
| 54 |
+
stream = input
|
| 55 |
+
except OSError:
|
| 56 |
+
# If that fails, see if stdin can be controlled.
|
| 57 |
+
stack.close()
|
| 58 |
+
try:
|
| 59 |
+
fd = sys.stdin.fileno()
|
| 60 |
+
except (AttributeError, ValueError):
|
| 61 |
+
fd = None
|
| 62 |
+
passwd = fallback_getpass(prompt, stream)
|
| 63 |
+
input = sys.stdin
|
| 64 |
+
if not stream:
|
| 65 |
+
stream = sys.stderr
|
| 66 |
+
|
| 67 |
+
if fd is not None:
|
| 68 |
+
try:
|
| 69 |
+
old = termios.tcgetattr(fd) # a copy to save
|
| 70 |
+
new = old[:]
|
| 71 |
+
new[3] &= ~termios.ECHO # 3 == 'lflags'
|
| 72 |
+
tcsetattr_flags = termios.TCSAFLUSH
|
| 73 |
+
if hasattr(termios, 'TCSASOFT'):
|
| 74 |
+
tcsetattr_flags |= termios.TCSASOFT
|
| 75 |
+
try:
|
| 76 |
+
termios.tcsetattr(fd, tcsetattr_flags, new)
|
| 77 |
+
passwd = _raw_input(prompt, stream, input=input)
|
| 78 |
+
finally:
|
| 79 |
+
termios.tcsetattr(fd, tcsetattr_flags, old)
|
| 80 |
+
stream.flush() # issue7208
|
| 81 |
+
except termios.error:
|
| 82 |
+
if passwd is not None:
|
| 83 |
+
# _raw_input succeeded. The final tcsetattr failed. Reraise
|
| 84 |
+
# instead of leaving the terminal in an unknown state.
|
| 85 |
+
raise
|
| 86 |
+
# We can't control the tty or stdin. Give up and use normal IO.
|
| 87 |
+
# fallback_getpass() raises an appropriate warning.
|
| 88 |
+
if stream is not input:
|
| 89 |
+
# clean up unused file objects before blocking
|
| 90 |
+
stack.close()
|
| 91 |
+
passwd = fallback_getpass(prompt, stream)
|
| 92 |
+
|
| 93 |
+
stream.write('\n')
|
| 94 |
+
return passwd
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
def win_getpass(prompt='Password: ', stream=None):
|
| 98 |
+
"""Prompt for password with echo off, using Windows getwch()."""
|
| 99 |
+
if sys.stdin is not sys.__stdin__:
|
| 100 |
+
return fallback_getpass(prompt, stream)
|
| 101 |
+
|
| 102 |
+
for c in prompt:
|
| 103 |
+
msvcrt.putwch(c)
|
| 104 |
+
pw = ""
|
| 105 |
+
while 1:
|
| 106 |
+
c = msvcrt.getwch()
|
| 107 |
+
if c == '\r' or c == '\n':
|
| 108 |
+
break
|
| 109 |
+
if c == '\003':
|
| 110 |
+
raise KeyboardInterrupt
|
| 111 |
+
if c == '\b':
|
| 112 |
+
pw = pw[:-1]
|
| 113 |
+
else:
|
| 114 |
+
pw = pw + c
|
| 115 |
+
msvcrt.putwch('\r')
|
| 116 |
+
msvcrt.putwch('\n')
|
| 117 |
+
return pw
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
def fallback_getpass(prompt='Password: ', stream=None):
|
| 121 |
+
warnings.warn("Can not control echo on the terminal.", GetPassWarning,
|
| 122 |
+
stacklevel=2)
|
| 123 |
+
if not stream:
|
| 124 |
+
stream = sys.stderr
|
| 125 |
+
print("Warning: Password input may be echoed.", file=stream)
|
| 126 |
+
return _raw_input(prompt, stream)
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
def _raw_input(prompt="", stream=None, input=None):
|
| 130 |
+
# This doesn't save the string in the GNU readline history.
|
| 131 |
+
if not stream:
|
| 132 |
+
stream = sys.stderr
|
| 133 |
+
if not input:
|
| 134 |
+
input = sys.stdin
|
| 135 |
+
prompt = str(prompt)
|
| 136 |
+
if prompt:
|
| 137 |
+
try:
|
| 138 |
+
stream.write(prompt)
|
| 139 |
+
except UnicodeEncodeError:
|
| 140 |
+
# Use replace error handler to get as much as possible printed.
|
| 141 |
+
prompt = prompt.encode(stream.encoding, 'replace')
|
| 142 |
+
prompt = prompt.decode(stream.encoding)
|
| 143 |
+
stream.write(prompt)
|
| 144 |
+
stream.flush()
|
| 145 |
+
# NOTE: The Python C API calls flockfile() (and unlock) during readline.
|
| 146 |
+
line = input.readline()
|
| 147 |
+
if not line:
|
| 148 |
+
raise EOFError
|
| 149 |
+
if line[-1] == '\n':
|
| 150 |
+
line = line[:-1]
|
| 151 |
+
return line
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
def getuser():
|
| 155 |
+
"""Get the username from the environment or password database.
|
| 156 |
+
|
| 157 |
+
First try various environment variables, then the password
|
| 158 |
+
database. This works on Windows as long as USERNAME is set.
|
| 159 |
+
|
| 160 |
+
"""
|
| 161 |
+
|
| 162 |
+
for name in ('LOGNAME', 'USER', 'LNAME', 'USERNAME'):
|
| 163 |
+
user = os.environ.get(name)
|
| 164 |
+
if user:
|
| 165 |
+
return user
|
| 166 |
+
|
| 167 |
+
# If this fails, the exception will "explain" why
|
| 168 |
+
import pwd
|
| 169 |
+
return pwd.getpwuid(os.getuid())[0]
|
| 170 |
+
|
| 171 |
+
# Bind the name getpass to the appropriate function
|
| 172 |
+
try:
|
| 173 |
+
import termios
|
| 174 |
+
# it's possible there is an incompatible termios from the
|
| 175 |
+
# McMillan Installer, make sure we have a UNIX-compatible termios
|
| 176 |
+
termios.tcgetattr, termios.tcsetattr
|
| 177 |
+
except (ImportError, AttributeError):
|
| 178 |
+
try:
|
| 179 |
+
import msvcrt
|
| 180 |
+
except ImportError:
|
| 181 |
+
getpass = fallback_getpass
|
| 182 |
+
else:
|
| 183 |
+
getpass = win_getpass
|
| 184 |
+
else:
|
| 185 |
+
getpass = unix_getpass
|
llava/lib/python3.10/imaplib.py
ADDED
|
@@ -0,0 +1,1649 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""IMAP4 client.
|
| 2 |
+
|
| 3 |
+
Based on RFC 2060.
|
| 4 |
+
|
| 5 |
+
Public class: IMAP4
|
| 6 |
+
Public variable: Debug
|
| 7 |
+
Public functions: Internaldate2tuple
|
| 8 |
+
Int2AP
|
| 9 |
+
ParseFlags
|
| 10 |
+
Time2Internaldate
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
# Author: Piers Lauder <piers@cs.su.oz.au> December 1997.
|
| 14 |
+
#
|
| 15 |
+
# Authentication code contributed by Donn Cave <donn@u.washington.edu> June 1998.
|
| 16 |
+
# String method conversion by ESR, February 2001.
|
| 17 |
+
# GET/SETACL contributed by Anthony Baxter <anthony@interlink.com.au> April 2001.
|
| 18 |
+
# IMAP4_SSL contributed by Tino Lange <Tino.Lange@isg.de> March 2002.
|
| 19 |
+
# GET/SETQUOTA contributed by Andreas Zeidler <az@kreativkombinat.de> June 2002.
|
| 20 |
+
# PROXYAUTH contributed by Rick Holbert <holbert.13@osu.edu> November 2002.
|
| 21 |
+
# GET/SETANNOTATION contributed by Tomas Lindroos <skitta@abo.fi> June 2005.
|
| 22 |
+
|
| 23 |
+
__version__ = "2.58"
|
| 24 |
+
|
| 25 |
+
import binascii, errno, random, re, socket, subprocess, sys, time, calendar
|
| 26 |
+
from datetime import datetime, timezone, timedelta
|
| 27 |
+
from io import DEFAULT_BUFFER_SIZE
|
| 28 |
+
|
| 29 |
+
try:
|
| 30 |
+
import ssl
|
| 31 |
+
HAVE_SSL = True
|
| 32 |
+
except ImportError:
|
| 33 |
+
HAVE_SSL = False
|
| 34 |
+
|
| 35 |
+
__all__ = ["IMAP4", "IMAP4_stream", "Internaldate2tuple",
|
| 36 |
+
"Int2AP", "ParseFlags", "Time2Internaldate"]
|
| 37 |
+
|
| 38 |
+
# Globals
|
| 39 |
+
|
| 40 |
+
CRLF = b'\r\n'
|
| 41 |
+
Debug = 0
|
| 42 |
+
IMAP4_PORT = 143
|
| 43 |
+
IMAP4_SSL_PORT = 993
|
| 44 |
+
AllowedVersions = ('IMAP4REV1', 'IMAP4') # Most recent first
|
| 45 |
+
|
| 46 |
+
# Maximal line length when calling readline(). This is to prevent
|
| 47 |
+
# reading arbitrary length lines. RFC 3501 and 2060 (IMAP 4rev1)
|
| 48 |
+
# don't specify a line length. RFC 2683 suggests limiting client
|
| 49 |
+
# command lines to 1000 octets and that servers should be prepared
|
| 50 |
+
# to accept command lines up to 8000 octets, so we used to use 10K here.
|
| 51 |
+
# In the modern world (eg: gmail) the response to, for example, a
|
| 52 |
+
# search command can be quite large, so we now use 1M.
|
| 53 |
+
_MAXLINE = 1000000
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
# Commands
|
| 57 |
+
|
| 58 |
+
Commands = {
|
| 59 |
+
# name valid states
|
| 60 |
+
'APPEND': ('AUTH', 'SELECTED'),
|
| 61 |
+
'AUTHENTICATE': ('NONAUTH',),
|
| 62 |
+
'CAPABILITY': ('NONAUTH', 'AUTH', 'SELECTED', 'LOGOUT'),
|
| 63 |
+
'CHECK': ('SELECTED',),
|
| 64 |
+
'CLOSE': ('SELECTED',),
|
| 65 |
+
'COPY': ('SELECTED',),
|
| 66 |
+
'CREATE': ('AUTH', 'SELECTED'),
|
| 67 |
+
'DELETE': ('AUTH', 'SELECTED'),
|
| 68 |
+
'DELETEACL': ('AUTH', 'SELECTED'),
|
| 69 |
+
'ENABLE': ('AUTH', ),
|
| 70 |
+
'EXAMINE': ('AUTH', 'SELECTED'),
|
| 71 |
+
'EXPUNGE': ('SELECTED',),
|
| 72 |
+
'FETCH': ('SELECTED',),
|
| 73 |
+
'GETACL': ('AUTH', 'SELECTED'),
|
| 74 |
+
'GETANNOTATION':('AUTH', 'SELECTED'),
|
| 75 |
+
'GETQUOTA': ('AUTH', 'SELECTED'),
|
| 76 |
+
'GETQUOTAROOT': ('AUTH', 'SELECTED'),
|
| 77 |
+
'MYRIGHTS': ('AUTH', 'SELECTED'),
|
| 78 |
+
'LIST': ('AUTH', 'SELECTED'),
|
| 79 |
+
'LOGIN': ('NONAUTH',),
|
| 80 |
+
'LOGOUT': ('NONAUTH', 'AUTH', 'SELECTED', 'LOGOUT'),
|
| 81 |
+
'LSUB': ('AUTH', 'SELECTED'),
|
| 82 |
+
'MOVE': ('SELECTED',),
|
| 83 |
+
'NAMESPACE': ('AUTH', 'SELECTED'),
|
| 84 |
+
'NOOP': ('NONAUTH', 'AUTH', 'SELECTED', 'LOGOUT'),
|
| 85 |
+
'PARTIAL': ('SELECTED',), # NB: obsolete
|
| 86 |
+
'PROXYAUTH': ('AUTH',),
|
| 87 |
+
'RENAME': ('AUTH', 'SELECTED'),
|
| 88 |
+
'SEARCH': ('SELECTED',),
|
| 89 |
+
'SELECT': ('AUTH', 'SELECTED'),
|
| 90 |
+
'SETACL': ('AUTH', 'SELECTED'),
|
| 91 |
+
'SETANNOTATION':('AUTH', 'SELECTED'),
|
| 92 |
+
'SETQUOTA': ('AUTH', 'SELECTED'),
|
| 93 |
+
'SORT': ('SELECTED',),
|
| 94 |
+
'STARTTLS': ('NONAUTH',),
|
| 95 |
+
'STATUS': ('AUTH', 'SELECTED'),
|
| 96 |
+
'STORE': ('SELECTED',),
|
| 97 |
+
'SUBSCRIBE': ('AUTH', 'SELECTED'),
|
| 98 |
+
'THREAD': ('SELECTED',),
|
| 99 |
+
'UID': ('SELECTED',),
|
| 100 |
+
'UNSUBSCRIBE': ('AUTH', 'SELECTED'),
|
| 101 |
+
'UNSELECT': ('SELECTED',),
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
# Patterns to match server responses
|
| 105 |
+
|
| 106 |
+
Continuation = re.compile(br'\+( (?P<data>.*))?')
|
| 107 |
+
Flags = re.compile(br'.*FLAGS \((?P<flags>[^\)]*)\)')
|
| 108 |
+
InternalDate = re.compile(br'.*INTERNALDATE "'
|
| 109 |
+
br'(?P<day>[ 0123][0-9])-(?P<mon>[A-Z][a-z][a-z])-(?P<year>[0-9][0-9][0-9][0-9])'
|
| 110 |
+
br' (?P<hour>[0-9][0-9]):(?P<min>[0-9][0-9]):(?P<sec>[0-9][0-9])'
|
| 111 |
+
br' (?P<zonen>[-+])(?P<zoneh>[0-9][0-9])(?P<zonem>[0-9][0-9])'
|
| 112 |
+
br'"')
|
| 113 |
+
# Literal is no longer used; kept for backward compatibility.
|
| 114 |
+
Literal = re.compile(br'.*{(?P<size>\d+)}$', re.ASCII)
|
| 115 |
+
MapCRLF = re.compile(br'\r\n|\r|\n')
|
| 116 |
+
# We no longer exclude the ']' character from the data portion of the response
|
| 117 |
+
# code, even though it violates the RFC. Popular IMAP servers such as Gmail
|
| 118 |
+
# allow flags with ']', and there are programs (including imaplib!) that can
|
| 119 |
+
# produce them. The problem with this is if the 'text' portion of the response
|
| 120 |
+
# includes a ']' we'll parse the response wrong (which is the point of the RFC
|
| 121 |
+
# restriction). However, that seems less likely to be a problem in practice
|
| 122 |
+
# than being unable to correctly parse flags that include ']' chars, which
|
| 123 |
+
# was reported as a real-world problem in issue #21815.
|
| 124 |
+
Response_code = re.compile(br'\[(?P<type>[A-Z-]+)( (?P<data>.*))?\]')
|
| 125 |
+
Untagged_response = re.compile(br'\* (?P<type>[A-Z-]+)( (?P<data>.*))?')
|
| 126 |
+
# Untagged_status is no longer used; kept for backward compatibility
|
| 127 |
+
Untagged_status = re.compile(
|
| 128 |
+
br'\* (?P<data>\d+) (?P<type>[A-Z-]+)( (?P<data2>.*))?', re.ASCII)
|
| 129 |
+
# We compile these in _mode_xxx.
|
| 130 |
+
_Literal = br'.*{(?P<size>\d+)}$'
|
| 131 |
+
_Untagged_status = br'\* (?P<data>\d+) (?P<type>[A-Z-]+)( (?P<data2>.*))?'
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
class IMAP4:
|
| 136 |
+
|
| 137 |
+
r"""IMAP4 client class.
|
| 138 |
+
|
| 139 |
+
Instantiate with: IMAP4([host[, port[, timeout=None]]])
|
| 140 |
+
|
| 141 |
+
host - host's name (default: localhost);
|
| 142 |
+
port - port number (default: standard IMAP4 port).
|
| 143 |
+
timeout - socket timeout (default: None)
|
| 144 |
+
If timeout is not given or is None,
|
| 145 |
+
the global default socket timeout is used
|
| 146 |
+
|
| 147 |
+
All IMAP4rev1 commands are supported by methods of the same
|
| 148 |
+
name (in lower-case).
|
| 149 |
+
|
| 150 |
+
All arguments to commands are converted to strings, except for
|
| 151 |
+
AUTHENTICATE, and the last argument to APPEND which is passed as
|
| 152 |
+
an IMAP4 literal. If necessary (the string contains any
|
| 153 |
+
non-printing characters or white-space and isn't enclosed with
|
| 154 |
+
either parentheses or double quotes) each string is quoted.
|
| 155 |
+
However, the 'password' argument to the LOGIN command is always
|
| 156 |
+
quoted. If you want to avoid having an argument string quoted
|
| 157 |
+
(eg: the 'flags' argument to STORE) then enclose the string in
|
| 158 |
+
parentheses (eg: "(\Deleted)").
|
| 159 |
+
|
| 160 |
+
Each command returns a tuple: (type, [data, ...]) where 'type'
|
| 161 |
+
is usually 'OK' or 'NO', and 'data' is either the text from the
|
| 162 |
+
tagged response, or untagged results from command. Each 'data'
|
| 163 |
+
is either a string, or a tuple. If a tuple, then the first part
|
| 164 |
+
is the header of the response, and the second part contains
|
| 165 |
+
the data (ie: 'literal' value).
|
| 166 |
+
|
| 167 |
+
Errors raise the exception class <instance>.error("<reason>").
|
| 168 |
+
IMAP4 server errors raise <instance>.abort("<reason>"),
|
| 169 |
+
which is a sub-class of 'error'. Mailbox status changes
|
| 170 |
+
from READ-WRITE to READ-ONLY raise the exception class
|
| 171 |
+
<instance>.readonly("<reason>"), which is a sub-class of 'abort'.
|
| 172 |
+
|
| 173 |
+
"error" exceptions imply a program error.
|
| 174 |
+
"abort" exceptions imply the connection should be reset, and
|
| 175 |
+
the command re-tried.
|
| 176 |
+
"readonly" exceptions imply the command should be re-tried.
|
| 177 |
+
|
| 178 |
+
Note: to use this module, you must read the RFCs pertaining to the
|
| 179 |
+
IMAP4 protocol, as the semantics of the arguments to each IMAP4
|
| 180 |
+
command are left to the invoker, not to mention the results. Also,
|
| 181 |
+
most IMAP servers implement a sub-set of the commands available here.
|
| 182 |
+
"""
|
| 183 |
+
|
| 184 |
+
class error(Exception): pass # Logical errors - debug required
|
| 185 |
+
class abort(error): pass # Service errors - close and retry
|
| 186 |
+
class readonly(abort): pass # Mailbox status changed to READ-ONLY
|
| 187 |
+
|
| 188 |
+
def __init__(self, host='', port=IMAP4_PORT, timeout=None):
|
| 189 |
+
self.debug = Debug
|
| 190 |
+
self.state = 'LOGOUT'
|
| 191 |
+
self.literal = None # A literal argument to a command
|
| 192 |
+
self.tagged_commands = {} # Tagged commands awaiting response
|
| 193 |
+
self.untagged_responses = {} # {typ: [data, ...], ...}
|
| 194 |
+
self.continuation_response = '' # Last continuation response
|
| 195 |
+
self.is_readonly = False # READ-ONLY desired state
|
| 196 |
+
self.tagnum = 0
|
| 197 |
+
self._tls_established = False
|
| 198 |
+
self._mode_ascii()
|
| 199 |
+
|
| 200 |
+
# Open socket to server.
|
| 201 |
+
|
| 202 |
+
self.open(host, port, timeout)
|
| 203 |
+
|
| 204 |
+
try:
|
| 205 |
+
self._connect()
|
| 206 |
+
except Exception:
|
| 207 |
+
try:
|
| 208 |
+
self.shutdown()
|
| 209 |
+
except OSError:
|
| 210 |
+
pass
|
| 211 |
+
raise
|
| 212 |
+
|
| 213 |
+
def _mode_ascii(self):
|
| 214 |
+
self.utf8_enabled = False
|
| 215 |
+
self._encoding = 'ascii'
|
| 216 |
+
self.Literal = re.compile(_Literal, re.ASCII)
|
| 217 |
+
self.Untagged_status = re.compile(_Untagged_status, re.ASCII)
|
| 218 |
+
|
| 219 |
+
|
| 220 |
+
def _mode_utf8(self):
|
| 221 |
+
self.utf8_enabled = True
|
| 222 |
+
self._encoding = 'utf-8'
|
| 223 |
+
self.Literal = re.compile(_Literal)
|
| 224 |
+
self.Untagged_status = re.compile(_Untagged_status)
|
| 225 |
+
|
| 226 |
+
|
| 227 |
+
def _connect(self):
|
| 228 |
+
# Create unique tag for this session,
|
| 229 |
+
# and compile tagged response matcher.
|
| 230 |
+
|
| 231 |
+
self.tagpre = Int2AP(random.randint(4096, 65535))
|
| 232 |
+
self.tagre = re.compile(br'(?P<tag>'
|
| 233 |
+
+ self.tagpre
|
| 234 |
+
+ br'\d+) (?P<type>[A-Z]+) (?P<data>.*)', re.ASCII)
|
| 235 |
+
|
| 236 |
+
# Get server welcome message,
|
| 237 |
+
# request and store CAPABILITY response.
|
| 238 |
+
|
| 239 |
+
if __debug__:
|
| 240 |
+
self._cmd_log_len = 10
|
| 241 |
+
self._cmd_log_idx = 0
|
| 242 |
+
self._cmd_log = {} # Last `_cmd_log_len' interactions
|
| 243 |
+
if self.debug >= 1:
|
| 244 |
+
self._mesg('imaplib version %s' % __version__)
|
| 245 |
+
self._mesg('new IMAP4 connection, tag=%s' % self.tagpre)
|
| 246 |
+
|
| 247 |
+
self.welcome = self._get_response()
|
| 248 |
+
if 'PREAUTH' in self.untagged_responses:
|
| 249 |
+
self.state = 'AUTH'
|
| 250 |
+
elif 'OK' in self.untagged_responses:
|
| 251 |
+
self.state = 'NONAUTH'
|
| 252 |
+
else:
|
| 253 |
+
raise self.error(self.welcome)
|
| 254 |
+
|
| 255 |
+
self._get_capabilities()
|
| 256 |
+
if __debug__:
|
| 257 |
+
if self.debug >= 3:
|
| 258 |
+
self._mesg('CAPABILITIES: %r' % (self.capabilities,))
|
| 259 |
+
|
| 260 |
+
for version in AllowedVersions:
|
| 261 |
+
if not version in self.capabilities:
|
| 262 |
+
continue
|
| 263 |
+
self.PROTOCOL_VERSION = version
|
| 264 |
+
return
|
| 265 |
+
|
| 266 |
+
raise self.error('server not IMAP4 compliant')
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
def __getattr__(self, attr):
|
| 270 |
+
# Allow UPPERCASE variants of IMAP4 command methods.
|
| 271 |
+
if attr in Commands:
|
| 272 |
+
return getattr(self, attr.lower())
|
| 273 |
+
raise AttributeError("Unknown IMAP4 command: '%s'" % attr)
|
| 274 |
+
|
| 275 |
+
def __enter__(self):
|
| 276 |
+
return self
|
| 277 |
+
|
| 278 |
+
def __exit__(self, *args):
|
| 279 |
+
if self.state == "LOGOUT":
|
| 280 |
+
return
|
| 281 |
+
|
| 282 |
+
try:
|
| 283 |
+
self.logout()
|
| 284 |
+
except OSError:
|
| 285 |
+
pass
|
| 286 |
+
|
| 287 |
+
|
| 288 |
+
# Overridable methods
|
| 289 |
+
|
| 290 |
+
|
| 291 |
+
def _create_socket(self, timeout):
|
| 292 |
+
# Default value of IMAP4.host is '', but socket.getaddrinfo()
|
| 293 |
+
# (which is used by socket.create_connection()) expects None
|
| 294 |
+
# as a default value for host.
|
| 295 |
+
if timeout is not None and not timeout:
|
| 296 |
+
raise ValueError('Non-blocking socket (timeout=0) is not supported')
|
| 297 |
+
host = None if not self.host else self.host
|
| 298 |
+
sys.audit("imaplib.open", self, self.host, self.port)
|
| 299 |
+
address = (host, self.port)
|
| 300 |
+
if timeout is not None:
|
| 301 |
+
return socket.create_connection(address, timeout)
|
| 302 |
+
return socket.create_connection(address)
|
| 303 |
+
|
| 304 |
+
def open(self, host='', port=IMAP4_PORT, timeout=None):
|
| 305 |
+
"""Setup connection to remote server on "host:port"
|
| 306 |
+
(default: localhost:standard IMAP4 port).
|
| 307 |
+
This connection will be used by the routines:
|
| 308 |
+
read, readline, send, shutdown.
|
| 309 |
+
"""
|
| 310 |
+
self.host = host
|
| 311 |
+
self.port = port
|
| 312 |
+
self.sock = self._create_socket(timeout)
|
| 313 |
+
self.file = self.sock.makefile('rb')
|
| 314 |
+
|
| 315 |
+
|
| 316 |
+
def read(self, size):
|
| 317 |
+
"""Read 'size' bytes from remote."""
|
| 318 |
+
return self.file.read(size)
|
| 319 |
+
|
| 320 |
+
|
| 321 |
+
def readline(self):
|
| 322 |
+
"""Read line from remote."""
|
| 323 |
+
line = self.file.readline(_MAXLINE + 1)
|
| 324 |
+
if len(line) > _MAXLINE:
|
| 325 |
+
raise self.error("got more than %d bytes" % _MAXLINE)
|
| 326 |
+
return line
|
| 327 |
+
|
| 328 |
+
|
| 329 |
+
def send(self, data):
|
| 330 |
+
"""Send data to remote."""
|
| 331 |
+
sys.audit("imaplib.send", self, data)
|
| 332 |
+
self.sock.sendall(data)
|
| 333 |
+
|
| 334 |
+
|
| 335 |
+
def shutdown(self):
|
| 336 |
+
"""Close I/O established in "open"."""
|
| 337 |
+
self.file.close()
|
| 338 |
+
try:
|
| 339 |
+
self.sock.shutdown(socket.SHUT_RDWR)
|
| 340 |
+
except OSError as exc:
|
| 341 |
+
# The server might already have closed the connection.
|
| 342 |
+
# On Windows, this may result in WSAEINVAL (error 10022):
|
| 343 |
+
# An invalid operation was attempted.
|
| 344 |
+
if (exc.errno != errno.ENOTCONN
|
| 345 |
+
and getattr(exc, 'winerror', 0) != 10022):
|
| 346 |
+
raise
|
| 347 |
+
finally:
|
| 348 |
+
self.sock.close()
|
| 349 |
+
|
| 350 |
+
|
| 351 |
+
def socket(self):
|
| 352 |
+
"""Return socket instance used to connect to IMAP4 server.
|
| 353 |
+
|
| 354 |
+
socket = <instance>.socket()
|
| 355 |
+
"""
|
| 356 |
+
return self.sock
|
| 357 |
+
|
| 358 |
+
|
| 359 |
+
|
| 360 |
+
# Utility methods
|
| 361 |
+
|
| 362 |
+
|
| 363 |
+
def recent(self):
|
| 364 |
+
"""Return most recent 'RECENT' responses if any exist,
|
| 365 |
+
else prompt server for an update using the 'NOOP' command.
|
| 366 |
+
|
| 367 |
+
(typ, [data]) = <instance>.recent()
|
| 368 |
+
|
| 369 |
+
'data' is None if no new messages,
|
| 370 |
+
else list of RECENT responses, most recent last.
|
| 371 |
+
"""
|
| 372 |
+
name = 'RECENT'
|
| 373 |
+
typ, dat = self._untagged_response('OK', [None], name)
|
| 374 |
+
if dat[-1]:
|
| 375 |
+
return typ, dat
|
| 376 |
+
typ, dat = self.noop() # Prod server for response
|
| 377 |
+
return self._untagged_response(typ, dat, name)
|
| 378 |
+
|
| 379 |
+
|
| 380 |
+
def response(self, code):
|
| 381 |
+
"""Return data for response 'code' if received, or None.
|
| 382 |
+
|
| 383 |
+
Old value for response 'code' is cleared.
|
| 384 |
+
|
| 385 |
+
(code, [data]) = <instance>.response(code)
|
| 386 |
+
"""
|
| 387 |
+
return self._untagged_response(code, [None], code.upper())
|
| 388 |
+
|
| 389 |
+
|
| 390 |
+
|
| 391 |
+
# IMAP4 commands
|
| 392 |
+
|
| 393 |
+
|
| 394 |
+
def append(self, mailbox, flags, date_time, message):
|
| 395 |
+
"""Append message to named mailbox.
|
| 396 |
+
|
| 397 |
+
(typ, [data]) = <instance>.append(mailbox, flags, date_time, message)
|
| 398 |
+
|
| 399 |
+
All args except `message' can be None.
|
| 400 |
+
"""
|
| 401 |
+
name = 'APPEND'
|
| 402 |
+
if not mailbox:
|
| 403 |
+
mailbox = 'INBOX'
|
| 404 |
+
if flags:
|
| 405 |
+
if (flags[0],flags[-1]) != ('(',')'):
|
| 406 |
+
flags = '(%s)' % flags
|
| 407 |
+
else:
|
| 408 |
+
flags = None
|
| 409 |
+
if date_time:
|
| 410 |
+
date_time = Time2Internaldate(date_time)
|
| 411 |
+
else:
|
| 412 |
+
date_time = None
|
| 413 |
+
literal = MapCRLF.sub(CRLF, message)
|
| 414 |
+
if self.utf8_enabled:
|
| 415 |
+
literal = b'UTF8 (' + literal + b')'
|
| 416 |
+
self.literal = literal
|
| 417 |
+
return self._simple_command(name, mailbox, flags, date_time)
|
| 418 |
+
|
| 419 |
+
|
| 420 |
+
def authenticate(self, mechanism, authobject):
|
| 421 |
+
"""Authenticate command - requires response processing.
|
| 422 |
+
|
| 423 |
+
'mechanism' specifies which authentication mechanism is to
|
| 424 |
+
be used - it must appear in <instance>.capabilities in the
|
| 425 |
+
form AUTH=<mechanism>.
|
| 426 |
+
|
| 427 |
+
'authobject' must be a callable object:
|
| 428 |
+
|
| 429 |
+
data = authobject(response)
|
| 430 |
+
|
| 431 |
+
It will be called to process server continuation responses; the
|
| 432 |
+
response argument it is passed will be a bytes. It should return bytes
|
| 433 |
+
data that will be base64 encoded and sent to the server. It should
|
| 434 |
+
return None if the client abort response '*' should be sent instead.
|
| 435 |
+
"""
|
| 436 |
+
mech = mechanism.upper()
|
| 437 |
+
# XXX: shouldn't this code be removed, not commented out?
|
| 438 |
+
#cap = 'AUTH=%s' % mech
|
| 439 |
+
#if not cap in self.capabilities: # Let the server decide!
|
| 440 |
+
# raise self.error("Server doesn't allow %s authentication." % mech)
|
| 441 |
+
self.literal = _Authenticator(authobject).process
|
| 442 |
+
typ, dat = self._simple_command('AUTHENTICATE', mech)
|
| 443 |
+
if typ != 'OK':
|
| 444 |
+
raise self.error(dat[-1].decode('utf-8', 'replace'))
|
| 445 |
+
self.state = 'AUTH'
|
| 446 |
+
return typ, dat
|
| 447 |
+
|
| 448 |
+
|
| 449 |
+
def capability(self):
|
| 450 |
+
"""(typ, [data]) = <instance>.capability()
|
| 451 |
+
Fetch capabilities list from server."""
|
| 452 |
+
|
| 453 |
+
name = 'CAPABILITY'
|
| 454 |
+
typ, dat = self._simple_command(name)
|
| 455 |
+
return self._untagged_response(typ, dat, name)
|
| 456 |
+
|
| 457 |
+
|
| 458 |
+
def check(self):
|
| 459 |
+
"""Checkpoint mailbox on server.
|
| 460 |
+
|
| 461 |
+
(typ, [data]) = <instance>.check()
|
| 462 |
+
"""
|
| 463 |
+
return self._simple_command('CHECK')
|
| 464 |
+
|
| 465 |
+
|
| 466 |
+
def close(self):
|
| 467 |
+
"""Close currently selected mailbox.
|
| 468 |
+
|
| 469 |
+
Deleted messages are removed from writable mailbox.
|
| 470 |
+
This is the recommended command before 'LOGOUT'.
|
| 471 |
+
|
| 472 |
+
(typ, [data]) = <instance>.close()
|
| 473 |
+
"""
|
| 474 |
+
try:
|
| 475 |
+
typ, dat = self._simple_command('CLOSE')
|
| 476 |
+
finally:
|
| 477 |
+
self.state = 'AUTH'
|
| 478 |
+
return typ, dat
|
| 479 |
+
|
| 480 |
+
|
| 481 |
+
def copy(self, message_set, new_mailbox):
|
| 482 |
+
"""Copy 'message_set' messages onto end of 'new_mailbox'.
|
| 483 |
+
|
| 484 |
+
(typ, [data]) = <instance>.copy(message_set, new_mailbox)
|
| 485 |
+
"""
|
| 486 |
+
return self._simple_command('COPY', message_set, new_mailbox)
|
| 487 |
+
|
| 488 |
+
|
| 489 |
+
def create(self, mailbox):
|
| 490 |
+
"""Create new mailbox.
|
| 491 |
+
|
| 492 |
+
(typ, [data]) = <instance>.create(mailbox)
|
| 493 |
+
"""
|
| 494 |
+
return self._simple_command('CREATE', mailbox)
|
| 495 |
+
|
| 496 |
+
|
| 497 |
+
def delete(self, mailbox):
|
| 498 |
+
"""Delete old mailbox.
|
| 499 |
+
|
| 500 |
+
(typ, [data]) = <instance>.delete(mailbox)
|
| 501 |
+
"""
|
| 502 |
+
return self._simple_command('DELETE', mailbox)
|
| 503 |
+
|
| 504 |
+
def deleteacl(self, mailbox, who):
|
| 505 |
+
"""Delete the ACLs (remove any rights) set for who on mailbox.
|
| 506 |
+
|
| 507 |
+
(typ, [data]) = <instance>.deleteacl(mailbox, who)
|
| 508 |
+
"""
|
| 509 |
+
return self._simple_command('DELETEACL', mailbox, who)
|
| 510 |
+
|
| 511 |
+
def enable(self, capability):
|
| 512 |
+
"""Send an RFC5161 enable string to the server.
|
| 513 |
+
|
| 514 |
+
(typ, [data]) = <instance>.enable(capability)
|
| 515 |
+
"""
|
| 516 |
+
if 'ENABLE' not in self.capabilities:
|
| 517 |
+
raise IMAP4.error("Server does not support ENABLE")
|
| 518 |
+
typ, data = self._simple_command('ENABLE', capability)
|
| 519 |
+
if typ == 'OK' and 'UTF8=ACCEPT' in capability.upper():
|
| 520 |
+
self._mode_utf8()
|
| 521 |
+
return typ, data
|
| 522 |
+
|
| 523 |
+
def expunge(self):
|
| 524 |
+
"""Permanently remove deleted items from selected mailbox.
|
| 525 |
+
|
| 526 |
+
Generates 'EXPUNGE' response for each deleted message.
|
| 527 |
+
|
| 528 |
+
(typ, [data]) = <instance>.expunge()
|
| 529 |
+
|
| 530 |
+
'data' is list of 'EXPUNGE'd message numbers in order received.
|
| 531 |
+
"""
|
| 532 |
+
name = 'EXPUNGE'
|
| 533 |
+
typ, dat = self._simple_command(name)
|
| 534 |
+
return self._untagged_response(typ, dat, name)
|
| 535 |
+
|
| 536 |
+
|
| 537 |
+
def fetch(self, message_set, message_parts):
|
| 538 |
+
"""Fetch (parts of) messages.
|
| 539 |
+
|
| 540 |
+
(typ, [data, ...]) = <instance>.fetch(message_set, message_parts)
|
| 541 |
+
|
| 542 |
+
'message_parts' should be a string of selected parts
|
| 543 |
+
enclosed in parentheses, eg: "(UID BODY[TEXT])".
|
| 544 |
+
|
| 545 |
+
'data' are tuples of message part envelope and data.
|
| 546 |
+
"""
|
| 547 |
+
name = 'FETCH'
|
| 548 |
+
typ, dat = self._simple_command(name, message_set, message_parts)
|
| 549 |
+
return self._untagged_response(typ, dat, name)
|
| 550 |
+
|
| 551 |
+
|
| 552 |
+
def getacl(self, mailbox):
|
| 553 |
+
"""Get the ACLs for a mailbox.
|
| 554 |
+
|
| 555 |
+
(typ, [data]) = <instance>.getacl(mailbox)
|
| 556 |
+
"""
|
| 557 |
+
typ, dat = self._simple_command('GETACL', mailbox)
|
| 558 |
+
return self._untagged_response(typ, dat, 'ACL')
|
| 559 |
+
|
| 560 |
+
|
| 561 |
+
def getannotation(self, mailbox, entry, attribute):
|
| 562 |
+
"""(typ, [data]) = <instance>.getannotation(mailbox, entry, attribute)
|
| 563 |
+
Retrieve ANNOTATIONs."""
|
| 564 |
+
|
| 565 |
+
typ, dat = self._simple_command('GETANNOTATION', mailbox, entry, attribute)
|
| 566 |
+
return self._untagged_response(typ, dat, 'ANNOTATION')
|
| 567 |
+
|
| 568 |
+
|
| 569 |
+
def getquota(self, root):
|
| 570 |
+
"""Get the quota root's resource usage and limits.
|
| 571 |
+
|
| 572 |
+
Part of the IMAP4 QUOTA extension defined in rfc2087.
|
| 573 |
+
|
| 574 |
+
(typ, [data]) = <instance>.getquota(root)
|
| 575 |
+
"""
|
| 576 |
+
typ, dat = self._simple_command('GETQUOTA', root)
|
| 577 |
+
return self._untagged_response(typ, dat, 'QUOTA')
|
| 578 |
+
|
| 579 |
+
|
| 580 |
+
def getquotaroot(self, mailbox):
|
| 581 |
+
"""Get the list of quota roots for the named mailbox.
|
| 582 |
+
|
| 583 |
+
(typ, [[QUOTAROOT responses...], [QUOTA responses]]) = <instance>.getquotaroot(mailbox)
|
| 584 |
+
"""
|
| 585 |
+
typ, dat = self._simple_command('GETQUOTAROOT', mailbox)
|
| 586 |
+
typ, quota = self._untagged_response(typ, dat, 'QUOTA')
|
| 587 |
+
typ, quotaroot = self._untagged_response(typ, dat, 'QUOTAROOT')
|
| 588 |
+
return typ, [quotaroot, quota]
|
| 589 |
+
|
| 590 |
+
|
| 591 |
+
def list(self, directory='""', pattern='*'):
|
| 592 |
+
"""List mailbox names in directory matching pattern.
|
| 593 |
+
|
| 594 |
+
(typ, [data]) = <instance>.list(directory='""', pattern='*')
|
| 595 |
+
|
| 596 |
+
'data' is list of LIST responses.
|
| 597 |
+
"""
|
| 598 |
+
name = 'LIST'
|
| 599 |
+
typ, dat = self._simple_command(name, directory, pattern)
|
| 600 |
+
return self._untagged_response(typ, dat, name)
|
| 601 |
+
|
| 602 |
+
|
| 603 |
+
def login(self, user, password):
|
| 604 |
+
"""Identify client using plaintext password.
|
| 605 |
+
|
| 606 |
+
(typ, [data]) = <instance>.login(user, password)
|
| 607 |
+
|
| 608 |
+
NB: 'password' will be quoted.
|
| 609 |
+
"""
|
| 610 |
+
typ, dat = self._simple_command('LOGIN', user, self._quote(password))
|
| 611 |
+
if typ != 'OK':
|
| 612 |
+
raise self.error(dat[-1])
|
| 613 |
+
self.state = 'AUTH'
|
| 614 |
+
return typ, dat
|
| 615 |
+
|
| 616 |
+
|
| 617 |
+
def login_cram_md5(self, user, password):
|
| 618 |
+
""" Force use of CRAM-MD5 authentication.
|
| 619 |
+
|
| 620 |
+
(typ, [data]) = <instance>.login_cram_md5(user, password)
|
| 621 |
+
"""
|
| 622 |
+
self.user, self.password = user, password
|
| 623 |
+
return self.authenticate('CRAM-MD5', self._CRAM_MD5_AUTH)
|
| 624 |
+
|
| 625 |
+
|
| 626 |
+
def _CRAM_MD5_AUTH(self, challenge):
|
| 627 |
+
""" Authobject to use with CRAM-MD5 authentication. """
|
| 628 |
+
import hmac
|
| 629 |
+
pwd = (self.password.encode('utf-8') if isinstance(self.password, str)
|
| 630 |
+
else self.password)
|
| 631 |
+
return self.user + " " + hmac.HMAC(pwd, challenge, 'md5').hexdigest()
|
| 632 |
+
|
| 633 |
+
|
| 634 |
+
def logout(self):
|
| 635 |
+
"""Shutdown connection to server.
|
| 636 |
+
|
| 637 |
+
(typ, [data]) = <instance>.logout()
|
| 638 |
+
|
| 639 |
+
Returns server 'BYE' response.
|
| 640 |
+
"""
|
| 641 |
+
self.state = 'LOGOUT'
|
| 642 |
+
typ, dat = self._simple_command('LOGOUT')
|
| 643 |
+
self.shutdown()
|
| 644 |
+
return typ, dat
|
| 645 |
+
|
| 646 |
+
|
| 647 |
+
def lsub(self, directory='""', pattern='*'):
|
| 648 |
+
"""List 'subscribed' mailbox names in directory matching pattern.
|
| 649 |
+
|
| 650 |
+
(typ, [data, ...]) = <instance>.lsub(directory='""', pattern='*')
|
| 651 |
+
|
| 652 |
+
'data' are tuples of message part envelope and data.
|
| 653 |
+
"""
|
| 654 |
+
name = 'LSUB'
|
| 655 |
+
typ, dat = self._simple_command(name, directory, pattern)
|
| 656 |
+
return self._untagged_response(typ, dat, name)
|
| 657 |
+
|
| 658 |
+
def myrights(self, mailbox):
|
| 659 |
+
"""Show my ACLs for a mailbox (i.e. the rights that I have on mailbox).
|
| 660 |
+
|
| 661 |
+
(typ, [data]) = <instance>.myrights(mailbox)
|
| 662 |
+
"""
|
| 663 |
+
typ,dat = self._simple_command('MYRIGHTS', mailbox)
|
| 664 |
+
return self._untagged_response(typ, dat, 'MYRIGHTS')
|
| 665 |
+
|
| 666 |
+
def namespace(self):
|
| 667 |
+
""" Returns IMAP namespaces ala rfc2342
|
| 668 |
+
|
| 669 |
+
(typ, [data, ...]) = <instance>.namespace()
|
| 670 |
+
"""
|
| 671 |
+
name = 'NAMESPACE'
|
| 672 |
+
typ, dat = self._simple_command(name)
|
| 673 |
+
return self._untagged_response(typ, dat, name)
|
| 674 |
+
|
| 675 |
+
|
| 676 |
+
def noop(self):
|
| 677 |
+
"""Send NOOP command.
|
| 678 |
+
|
| 679 |
+
(typ, [data]) = <instance>.noop()
|
| 680 |
+
"""
|
| 681 |
+
if __debug__:
|
| 682 |
+
if self.debug >= 3:
|
| 683 |
+
self._dump_ur(self.untagged_responses)
|
| 684 |
+
return self._simple_command('NOOP')
|
| 685 |
+
|
| 686 |
+
|
| 687 |
+
def partial(self, message_num, message_part, start, length):
|
| 688 |
+
"""Fetch truncated part of a message.
|
| 689 |
+
|
| 690 |
+
(typ, [data, ...]) = <instance>.partial(message_num, message_part, start, length)
|
| 691 |
+
|
| 692 |
+
'data' is tuple of message part envelope and data.
|
| 693 |
+
"""
|
| 694 |
+
name = 'PARTIAL'
|
| 695 |
+
typ, dat = self._simple_command(name, message_num, message_part, start, length)
|
| 696 |
+
return self._untagged_response(typ, dat, 'FETCH')
|
| 697 |
+
|
| 698 |
+
|
| 699 |
+
def proxyauth(self, user):
|
| 700 |
+
"""Assume authentication as "user".
|
| 701 |
+
|
| 702 |
+
Allows an authorised administrator to proxy into any user's
|
| 703 |
+
mailbox.
|
| 704 |
+
|
| 705 |
+
(typ, [data]) = <instance>.proxyauth(user)
|
| 706 |
+
"""
|
| 707 |
+
|
| 708 |
+
name = 'PROXYAUTH'
|
| 709 |
+
return self._simple_command('PROXYAUTH', user)
|
| 710 |
+
|
| 711 |
+
|
| 712 |
+
def rename(self, oldmailbox, newmailbox):
|
| 713 |
+
"""Rename old mailbox name to new.
|
| 714 |
+
|
| 715 |
+
(typ, [data]) = <instance>.rename(oldmailbox, newmailbox)
|
| 716 |
+
"""
|
| 717 |
+
return self._simple_command('RENAME', oldmailbox, newmailbox)
|
| 718 |
+
|
| 719 |
+
|
| 720 |
+
def search(self, charset, *criteria):
|
| 721 |
+
"""Search mailbox for matching messages.
|
| 722 |
+
|
| 723 |
+
(typ, [data]) = <instance>.search(charset, criterion, ...)
|
| 724 |
+
|
| 725 |
+
'data' is space separated list of matching message numbers.
|
| 726 |
+
If UTF8 is enabled, charset MUST be None.
|
| 727 |
+
"""
|
| 728 |
+
name = 'SEARCH'
|
| 729 |
+
if charset:
|
| 730 |
+
if self.utf8_enabled:
|
| 731 |
+
raise IMAP4.error("Non-None charset not valid in UTF8 mode")
|
| 732 |
+
typ, dat = self._simple_command(name, 'CHARSET', charset, *criteria)
|
| 733 |
+
else:
|
| 734 |
+
typ, dat = self._simple_command(name, *criteria)
|
| 735 |
+
return self._untagged_response(typ, dat, name)
|
| 736 |
+
|
| 737 |
+
|
| 738 |
+
def select(self, mailbox='INBOX', readonly=False):
|
| 739 |
+
"""Select a mailbox.
|
| 740 |
+
|
| 741 |
+
Flush all untagged responses.
|
| 742 |
+
|
| 743 |
+
(typ, [data]) = <instance>.select(mailbox='INBOX', readonly=False)
|
| 744 |
+
|
| 745 |
+
'data' is count of messages in mailbox ('EXISTS' response).
|
| 746 |
+
|
| 747 |
+
Mandated responses are ('FLAGS', 'EXISTS', 'RECENT', 'UIDVALIDITY'), so
|
| 748 |
+
other responses should be obtained via <instance>.response('FLAGS') etc.
|
| 749 |
+
"""
|
| 750 |
+
self.untagged_responses = {} # Flush old responses.
|
| 751 |
+
self.is_readonly = readonly
|
| 752 |
+
if readonly:
|
| 753 |
+
name = 'EXAMINE'
|
| 754 |
+
else:
|
| 755 |
+
name = 'SELECT'
|
| 756 |
+
typ, dat = self._simple_command(name, mailbox)
|
| 757 |
+
if typ != 'OK':
|
| 758 |
+
self.state = 'AUTH' # Might have been 'SELECTED'
|
| 759 |
+
return typ, dat
|
| 760 |
+
self.state = 'SELECTED'
|
| 761 |
+
if 'READ-ONLY' in self.untagged_responses \
|
| 762 |
+
and not readonly:
|
| 763 |
+
if __debug__:
|
| 764 |
+
if self.debug >= 1:
|
| 765 |
+
self._dump_ur(self.untagged_responses)
|
| 766 |
+
raise self.readonly('%s is not writable' % mailbox)
|
| 767 |
+
return typ, self.untagged_responses.get('EXISTS', [None])
|
| 768 |
+
|
| 769 |
+
|
| 770 |
+
def setacl(self, mailbox, who, what):
|
| 771 |
+
"""Set a mailbox acl.
|
| 772 |
+
|
| 773 |
+
(typ, [data]) = <instance>.setacl(mailbox, who, what)
|
| 774 |
+
"""
|
| 775 |
+
return self._simple_command('SETACL', mailbox, who, what)
|
| 776 |
+
|
| 777 |
+
|
| 778 |
+
def setannotation(self, *args):
|
| 779 |
+
"""(typ, [data]) = <instance>.setannotation(mailbox[, entry, attribute]+)
|
| 780 |
+
Set ANNOTATIONs."""
|
| 781 |
+
|
| 782 |
+
typ, dat = self._simple_command('SETANNOTATION', *args)
|
| 783 |
+
return self._untagged_response(typ, dat, 'ANNOTATION')
|
| 784 |
+
|
| 785 |
+
|
| 786 |
+
def setquota(self, root, limits):
|
| 787 |
+
"""Set the quota root's resource limits.
|
| 788 |
+
|
| 789 |
+
(typ, [data]) = <instance>.setquota(root, limits)
|
| 790 |
+
"""
|
| 791 |
+
typ, dat = self._simple_command('SETQUOTA', root, limits)
|
| 792 |
+
return self._untagged_response(typ, dat, 'QUOTA')
|
| 793 |
+
|
| 794 |
+
|
| 795 |
+
def sort(self, sort_criteria, charset, *search_criteria):
|
| 796 |
+
"""IMAP4rev1 extension SORT command.
|
| 797 |
+
|
| 798 |
+
(typ, [data]) = <instance>.sort(sort_criteria, charset, search_criteria, ...)
|
| 799 |
+
"""
|
| 800 |
+
name = 'SORT'
|
| 801 |
+
#if not name in self.capabilities: # Let the server decide!
|
| 802 |
+
# raise self.error('unimplemented extension command: %s' % name)
|
| 803 |
+
if (sort_criteria[0],sort_criteria[-1]) != ('(',')'):
|
| 804 |
+
sort_criteria = '(%s)' % sort_criteria
|
| 805 |
+
typ, dat = self._simple_command(name, sort_criteria, charset, *search_criteria)
|
| 806 |
+
return self._untagged_response(typ, dat, name)
|
| 807 |
+
|
| 808 |
+
|
| 809 |
+
def starttls(self, ssl_context=None):
|
| 810 |
+
name = 'STARTTLS'
|
| 811 |
+
if not HAVE_SSL:
|
| 812 |
+
raise self.error('SSL support missing')
|
| 813 |
+
if self._tls_established:
|
| 814 |
+
raise self.abort('TLS session already established')
|
| 815 |
+
if name not in self.capabilities:
|
| 816 |
+
raise self.abort('TLS not supported by server')
|
| 817 |
+
# Generate a default SSL context if none was passed.
|
| 818 |
+
if ssl_context is None:
|
| 819 |
+
ssl_context = ssl._create_stdlib_context()
|
| 820 |
+
typ, dat = self._simple_command(name)
|
| 821 |
+
if typ == 'OK':
|
| 822 |
+
self.sock = ssl_context.wrap_socket(self.sock,
|
| 823 |
+
server_hostname=self.host)
|
| 824 |
+
self.file = self.sock.makefile('rb')
|
| 825 |
+
self._tls_established = True
|
| 826 |
+
self._get_capabilities()
|
| 827 |
+
else:
|
| 828 |
+
raise self.error("Couldn't establish TLS session")
|
| 829 |
+
return self._untagged_response(typ, dat, name)
|
| 830 |
+
|
| 831 |
+
|
| 832 |
+
def status(self, mailbox, names):
|
| 833 |
+
"""Request named status conditions for mailbox.
|
| 834 |
+
|
| 835 |
+
(typ, [data]) = <instance>.status(mailbox, names)
|
| 836 |
+
"""
|
| 837 |
+
name = 'STATUS'
|
| 838 |
+
#if self.PROTOCOL_VERSION == 'IMAP4': # Let the server decide!
|
| 839 |
+
# raise self.error('%s unimplemented in IMAP4 (obtain IMAP4rev1 server, or re-code)' % name)
|
| 840 |
+
typ, dat = self._simple_command(name, mailbox, names)
|
| 841 |
+
return self._untagged_response(typ, dat, name)
|
| 842 |
+
|
| 843 |
+
|
| 844 |
+
def store(self, message_set, command, flags):
|
| 845 |
+
"""Alters flag dispositions for messages in mailbox.
|
| 846 |
+
|
| 847 |
+
(typ, [data]) = <instance>.store(message_set, command, flags)
|
| 848 |
+
"""
|
| 849 |
+
if (flags[0],flags[-1]) != ('(',')'):
|
| 850 |
+
flags = '(%s)' % flags # Avoid quoting the flags
|
| 851 |
+
typ, dat = self._simple_command('STORE', message_set, command, flags)
|
| 852 |
+
return self._untagged_response(typ, dat, 'FETCH')
|
| 853 |
+
|
| 854 |
+
|
| 855 |
+
def subscribe(self, mailbox):
|
| 856 |
+
"""Subscribe to new mailbox.
|
| 857 |
+
|
| 858 |
+
(typ, [data]) = <instance>.subscribe(mailbox)
|
| 859 |
+
"""
|
| 860 |
+
return self._simple_command('SUBSCRIBE', mailbox)
|
| 861 |
+
|
| 862 |
+
|
| 863 |
+
def thread(self, threading_algorithm, charset, *search_criteria):
|
| 864 |
+
"""IMAPrev1 extension THREAD command.
|
| 865 |
+
|
| 866 |
+
(type, [data]) = <instance>.thread(threading_algorithm, charset, search_criteria, ...)
|
| 867 |
+
"""
|
| 868 |
+
name = 'THREAD'
|
| 869 |
+
typ, dat = self._simple_command(name, threading_algorithm, charset, *search_criteria)
|
| 870 |
+
return self._untagged_response(typ, dat, name)
|
| 871 |
+
|
| 872 |
+
|
| 873 |
+
def uid(self, command, *args):
|
| 874 |
+
"""Execute "command arg ..." with messages identified by UID,
|
| 875 |
+
rather than message number.
|
| 876 |
+
|
| 877 |
+
(typ, [data]) = <instance>.uid(command, arg1, arg2, ...)
|
| 878 |
+
|
| 879 |
+
Returns response appropriate to 'command'.
|
| 880 |
+
"""
|
| 881 |
+
command = command.upper()
|
| 882 |
+
if not command in Commands:
|
| 883 |
+
raise self.error("Unknown IMAP4 UID command: %s" % command)
|
| 884 |
+
if self.state not in Commands[command]:
|
| 885 |
+
raise self.error("command %s illegal in state %s, "
|
| 886 |
+
"only allowed in states %s" %
|
| 887 |
+
(command, self.state,
|
| 888 |
+
', '.join(Commands[command])))
|
| 889 |
+
name = 'UID'
|
| 890 |
+
typ, dat = self._simple_command(name, command, *args)
|
| 891 |
+
if command in ('SEARCH', 'SORT', 'THREAD'):
|
| 892 |
+
name = command
|
| 893 |
+
else:
|
| 894 |
+
name = 'FETCH'
|
| 895 |
+
return self._untagged_response(typ, dat, name)
|
| 896 |
+
|
| 897 |
+
|
| 898 |
+
def unsubscribe(self, mailbox):
|
| 899 |
+
"""Unsubscribe from old mailbox.
|
| 900 |
+
|
| 901 |
+
(typ, [data]) = <instance>.unsubscribe(mailbox)
|
| 902 |
+
"""
|
| 903 |
+
return self._simple_command('UNSUBSCRIBE', mailbox)
|
| 904 |
+
|
| 905 |
+
|
| 906 |
+
def unselect(self):
|
| 907 |
+
"""Free server's resources associated with the selected mailbox
|
| 908 |
+
and returns the server to the authenticated state.
|
| 909 |
+
This command performs the same actions as CLOSE, except
|
| 910 |
+
that no messages are permanently removed from the currently
|
| 911 |
+
selected mailbox.
|
| 912 |
+
|
| 913 |
+
(typ, [data]) = <instance>.unselect()
|
| 914 |
+
"""
|
| 915 |
+
try:
|
| 916 |
+
typ, data = self._simple_command('UNSELECT')
|
| 917 |
+
finally:
|
| 918 |
+
self.state = 'AUTH'
|
| 919 |
+
return typ, data
|
| 920 |
+
|
| 921 |
+
|
| 922 |
+
def xatom(self, name, *args):
|
| 923 |
+
"""Allow simple extension commands
|
| 924 |
+
notified by server in CAPABILITY response.
|
| 925 |
+
|
| 926 |
+
Assumes command is legal in current state.
|
| 927 |
+
|
| 928 |
+
(typ, [data]) = <instance>.xatom(name, arg, ...)
|
| 929 |
+
|
| 930 |
+
Returns response appropriate to extension command `name'.
|
| 931 |
+
"""
|
| 932 |
+
name = name.upper()
|
| 933 |
+
#if not name in self.capabilities: # Let the server decide!
|
| 934 |
+
# raise self.error('unknown extension command: %s' % name)
|
| 935 |
+
if not name in Commands:
|
| 936 |
+
Commands[name] = (self.state,)
|
| 937 |
+
return self._simple_command(name, *args)
|
| 938 |
+
|
| 939 |
+
|
| 940 |
+
|
| 941 |
+
# Private methods
|
| 942 |
+
|
| 943 |
+
|
| 944 |
+
def _append_untagged(self, typ, dat):
|
| 945 |
+
if dat is None:
|
| 946 |
+
dat = b''
|
| 947 |
+
ur = self.untagged_responses
|
| 948 |
+
if __debug__:
|
| 949 |
+
if self.debug >= 5:
|
| 950 |
+
self._mesg('untagged_responses[%s] %s += ["%r"]' %
|
| 951 |
+
(typ, len(ur.get(typ,'')), dat))
|
| 952 |
+
if typ in ur:
|
| 953 |
+
ur[typ].append(dat)
|
| 954 |
+
else:
|
| 955 |
+
ur[typ] = [dat]
|
| 956 |
+
|
| 957 |
+
|
| 958 |
+
def _check_bye(self):
|
| 959 |
+
bye = self.untagged_responses.get('BYE')
|
| 960 |
+
if bye:
|
| 961 |
+
raise self.abort(bye[-1].decode(self._encoding, 'replace'))
|
| 962 |
+
|
| 963 |
+
|
| 964 |
+
def _command(self, name, *args):
|
| 965 |
+
|
| 966 |
+
if self.state not in Commands[name]:
|
| 967 |
+
self.literal = None
|
| 968 |
+
raise self.error("command %s illegal in state %s, "
|
| 969 |
+
"only allowed in states %s" %
|
| 970 |
+
(name, self.state,
|
| 971 |
+
', '.join(Commands[name])))
|
| 972 |
+
|
| 973 |
+
for typ in ('OK', 'NO', 'BAD'):
|
| 974 |
+
if typ in self.untagged_responses:
|
| 975 |
+
del self.untagged_responses[typ]
|
| 976 |
+
|
| 977 |
+
if 'READ-ONLY' in self.untagged_responses \
|
| 978 |
+
and not self.is_readonly:
|
| 979 |
+
raise self.readonly('mailbox status changed to READ-ONLY')
|
| 980 |
+
|
| 981 |
+
tag = self._new_tag()
|
| 982 |
+
name = bytes(name, self._encoding)
|
| 983 |
+
data = tag + b' ' + name
|
| 984 |
+
for arg in args:
|
| 985 |
+
if arg is None: continue
|
| 986 |
+
if isinstance(arg, str):
|
| 987 |
+
arg = bytes(arg, self._encoding)
|
| 988 |
+
data = data + b' ' + arg
|
| 989 |
+
|
| 990 |
+
literal = self.literal
|
| 991 |
+
if literal is not None:
|
| 992 |
+
self.literal = None
|
| 993 |
+
if type(literal) is type(self._command):
|
| 994 |
+
literator = literal
|
| 995 |
+
else:
|
| 996 |
+
literator = None
|
| 997 |
+
data = data + bytes(' {%s}' % len(literal), self._encoding)
|
| 998 |
+
|
| 999 |
+
if __debug__:
|
| 1000 |
+
if self.debug >= 4:
|
| 1001 |
+
self._mesg('> %r' % data)
|
| 1002 |
+
else:
|
| 1003 |
+
self._log('> %r' % data)
|
| 1004 |
+
|
| 1005 |
+
try:
|
| 1006 |
+
self.send(data + CRLF)
|
| 1007 |
+
except OSError as val:
|
| 1008 |
+
raise self.abort('socket error: %s' % val)
|
| 1009 |
+
|
| 1010 |
+
if literal is None:
|
| 1011 |
+
return tag
|
| 1012 |
+
|
| 1013 |
+
while 1:
|
| 1014 |
+
# Wait for continuation response
|
| 1015 |
+
|
| 1016 |
+
while self._get_response():
|
| 1017 |
+
if self.tagged_commands[tag]: # BAD/NO?
|
| 1018 |
+
return tag
|
| 1019 |
+
|
| 1020 |
+
# Send literal
|
| 1021 |
+
|
| 1022 |
+
if literator:
|
| 1023 |
+
literal = literator(self.continuation_response)
|
| 1024 |
+
|
| 1025 |
+
if __debug__:
|
| 1026 |
+
if self.debug >= 4:
|
| 1027 |
+
self._mesg('write literal size %s' % len(literal))
|
| 1028 |
+
|
| 1029 |
+
try:
|
| 1030 |
+
self.send(literal)
|
| 1031 |
+
self.send(CRLF)
|
| 1032 |
+
except OSError as val:
|
| 1033 |
+
raise self.abort('socket error: %s' % val)
|
| 1034 |
+
|
| 1035 |
+
if not literator:
|
| 1036 |
+
break
|
| 1037 |
+
|
| 1038 |
+
return tag
|
| 1039 |
+
|
| 1040 |
+
|
| 1041 |
+
def _command_complete(self, name, tag):
|
| 1042 |
+
logout = (name == 'LOGOUT')
|
| 1043 |
+
# BYE is expected after LOGOUT
|
| 1044 |
+
if not logout:
|
| 1045 |
+
self._check_bye()
|
| 1046 |
+
try:
|
| 1047 |
+
typ, data = self._get_tagged_response(tag, expect_bye=logout)
|
| 1048 |
+
except self.abort as val:
|
| 1049 |
+
raise self.abort('command: %s => %s' % (name, val))
|
| 1050 |
+
except self.error as val:
|
| 1051 |
+
raise self.error('command: %s => %s' % (name, val))
|
| 1052 |
+
if not logout:
|
| 1053 |
+
self._check_bye()
|
| 1054 |
+
if typ == 'BAD':
|
| 1055 |
+
raise self.error('%s command error: %s %s' % (name, typ, data))
|
| 1056 |
+
return typ, data
|
| 1057 |
+
|
| 1058 |
+
|
| 1059 |
+
def _get_capabilities(self):
|
| 1060 |
+
typ, dat = self.capability()
|
| 1061 |
+
if dat == [None]:
|
| 1062 |
+
raise self.error('no CAPABILITY response from server')
|
| 1063 |
+
dat = str(dat[-1], self._encoding)
|
| 1064 |
+
dat = dat.upper()
|
| 1065 |
+
self.capabilities = tuple(dat.split())
|
| 1066 |
+
|
| 1067 |
+
|
| 1068 |
+
def _get_response(self):
|
| 1069 |
+
|
| 1070 |
+
# Read response and store.
|
| 1071 |
+
#
|
| 1072 |
+
# Returns None for continuation responses,
|
| 1073 |
+
# otherwise first response line received.
|
| 1074 |
+
|
| 1075 |
+
resp = self._get_line()
|
| 1076 |
+
|
| 1077 |
+
# Command completion response?
|
| 1078 |
+
|
| 1079 |
+
if self._match(self.tagre, resp):
|
| 1080 |
+
tag = self.mo.group('tag')
|
| 1081 |
+
if not tag in self.tagged_commands:
|
| 1082 |
+
raise self.abort('unexpected tagged response: %r' % resp)
|
| 1083 |
+
|
| 1084 |
+
typ = self.mo.group('type')
|
| 1085 |
+
typ = str(typ, self._encoding)
|
| 1086 |
+
dat = self.mo.group('data')
|
| 1087 |
+
self.tagged_commands[tag] = (typ, [dat])
|
| 1088 |
+
else:
|
| 1089 |
+
dat2 = None
|
| 1090 |
+
|
| 1091 |
+
# '*' (untagged) responses?
|
| 1092 |
+
|
| 1093 |
+
if not self._match(Untagged_response, resp):
|
| 1094 |
+
if self._match(self.Untagged_status, resp):
|
| 1095 |
+
dat2 = self.mo.group('data2')
|
| 1096 |
+
|
| 1097 |
+
if self.mo is None:
|
| 1098 |
+
# Only other possibility is '+' (continuation) response...
|
| 1099 |
+
|
| 1100 |
+
if self._match(Continuation, resp):
|
| 1101 |
+
self.continuation_response = self.mo.group('data')
|
| 1102 |
+
return None # NB: indicates continuation
|
| 1103 |
+
|
| 1104 |
+
raise self.abort("unexpected response: %r" % resp)
|
| 1105 |
+
|
| 1106 |
+
typ = self.mo.group('type')
|
| 1107 |
+
typ = str(typ, self._encoding)
|
| 1108 |
+
dat = self.mo.group('data')
|
| 1109 |
+
if dat is None: dat = b'' # Null untagged response
|
| 1110 |
+
if dat2: dat = dat + b' ' + dat2
|
| 1111 |
+
|
| 1112 |
+
# Is there a literal to come?
|
| 1113 |
+
|
| 1114 |
+
while self._match(self.Literal, dat):
|
| 1115 |
+
|
| 1116 |
+
# Read literal direct from connection.
|
| 1117 |
+
|
| 1118 |
+
size = int(self.mo.group('size'))
|
| 1119 |
+
if __debug__:
|
| 1120 |
+
if self.debug >= 4:
|
| 1121 |
+
self._mesg('read literal size %s' % size)
|
| 1122 |
+
data = self.read(size)
|
| 1123 |
+
|
| 1124 |
+
# Store response with literal as tuple
|
| 1125 |
+
|
| 1126 |
+
self._append_untagged(typ, (dat, data))
|
| 1127 |
+
|
| 1128 |
+
# Read trailer - possibly containing another literal
|
| 1129 |
+
|
| 1130 |
+
dat = self._get_line()
|
| 1131 |
+
|
| 1132 |
+
self._append_untagged(typ, dat)
|
| 1133 |
+
|
| 1134 |
+
# Bracketed response information?
|
| 1135 |
+
|
| 1136 |
+
if typ in ('OK', 'NO', 'BAD') and self._match(Response_code, dat):
|
| 1137 |
+
typ = self.mo.group('type')
|
| 1138 |
+
typ = str(typ, self._encoding)
|
| 1139 |
+
self._append_untagged(typ, self.mo.group('data'))
|
| 1140 |
+
|
| 1141 |
+
if __debug__:
|
| 1142 |
+
if self.debug >= 1 and typ in ('NO', 'BAD', 'BYE'):
|
| 1143 |
+
self._mesg('%s response: %r' % (typ, dat))
|
| 1144 |
+
|
| 1145 |
+
return resp
|
| 1146 |
+
|
| 1147 |
+
|
| 1148 |
+
def _get_tagged_response(self, tag, expect_bye=False):
|
| 1149 |
+
|
| 1150 |
+
while 1:
|
| 1151 |
+
result = self.tagged_commands[tag]
|
| 1152 |
+
if result is not None:
|
| 1153 |
+
del self.tagged_commands[tag]
|
| 1154 |
+
return result
|
| 1155 |
+
|
| 1156 |
+
if expect_bye:
|
| 1157 |
+
typ = 'BYE'
|
| 1158 |
+
bye = self.untagged_responses.pop(typ, None)
|
| 1159 |
+
if bye is not None:
|
| 1160 |
+
# Server replies to the "LOGOUT" command with "BYE"
|
| 1161 |
+
return (typ, bye)
|
| 1162 |
+
|
| 1163 |
+
# If we've seen a BYE at this point, the socket will be
|
| 1164 |
+
# closed, so report the BYE now.
|
| 1165 |
+
self._check_bye()
|
| 1166 |
+
|
| 1167 |
+
# Some have reported "unexpected response" exceptions.
|
| 1168 |
+
# Note that ignoring them here causes loops.
|
| 1169 |
+
# Instead, send me details of the unexpected response and
|
| 1170 |
+
# I'll update the code in `_get_response()'.
|
| 1171 |
+
|
| 1172 |
+
try:
|
| 1173 |
+
self._get_response()
|
| 1174 |
+
except self.abort as val:
|
| 1175 |
+
if __debug__:
|
| 1176 |
+
if self.debug >= 1:
|
| 1177 |
+
self.print_log()
|
| 1178 |
+
raise
|
| 1179 |
+
|
| 1180 |
+
|
| 1181 |
+
def _get_line(self):
|
| 1182 |
+
|
| 1183 |
+
line = self.readline()
|
| 1184 |
+
if not line:
|
| 1185 |
+
raise self.abort('socket error: EOF')
|
| 1186 |
+
|
| 1187 |
+
# Protocol mandates all lines terminated by CRLF
|
| 1188 |
+
if not line.endswith(b'\r\n'):
|
| 1189 |
+
raise self.abort('socket error: unterminated line: %r' % line)
|
| 1190 |
+
|
| 1191 |
+
line = line[:-2]
|
| 1192 |
+
if __debug__:
|
| 1193 |
+
if self.debug >= 4:
|
| 1194 |
+
self._mesg('< %r' % line)
|
| 1195 |
+
else:
|
| 1196 |
+
self._log('< %r' % line)
|
| 1197 |
+
return line
|
| 1198 |
+
|
| 1199 |
+
|
| 1200 |
+
def _match(self, cre, s):
|
| 1201 |
+
|
| 1202 |
+
# Run compiled regular expression match method on 's'.
|
| 1203 |
+
# Save result, return success.
|
| 1204 |
+
|
| 1205 |
+
self.mo = cre.match(s)
|
| 1206 |
+
if __debug__:
|
| 1207 |
+
if self.mo is not None and self.debug >= 5:
|
| 1208 |
+
self._mesg("\tmatched %r => %r" % (cre.pattern, self.mo.groups()))
|
| 1209 |
+
return self.mo is not None
|
| 1210 |
+
|
| 1211 |
+
|
| 1212 |
+
def _new_tag(self):
|
| 1213 |
+
|
| 1214 |
+
tag = self.tagpre + bytes(str(self.tagnum), self._encoding)
|
| 1215 |
+
self.tagnum = self.tagnum + 1
|
| 1216 |
+
self.tagged_commands[tag] = None
|
| 1217 |
+
return tag
|
| 1218 |
+
|
| 1219 |
+
|
| 1220 |
+
def _quote(self, arg):
|
| 1221 |
+
|
| 1222 |
+
arg = arg.replace('\\', '\\\\')
|
| 1223 |
+
arg = arg.replace('"', '\\"')
|
| 1224 |
+
|
| 1225 |
+
return '"' + arg + '"'
|
| 1226 |
+
|
| 1227 |
+
|
| 1228 |
+
def _simple_command(self, name, *args):
|
| 1229 |
+
|
| 1230 |
+
return self._command_complete(name, self._command(name, *args))
|
| 1231 |
+
|
| 1232 |
+
|
| 1233 |
+
def _untagged_response(self, typ, dat, name):
|
| 1234 |
+
if typ == 'NO':
|
| 1235 |
+
return typ, dat
|
| 1236 |
+
if not name in self.untagged_responses:
|
| 1237 |
+
return typ, [None]
|
| 1238 |
+
data = self.untagged_responses.pop(name)
|
| 1239 |
+
if __debug__:
|
| 1240 |
+
if self.debug >= 5:
|
| 1241 |
+
self._mesg('untagged_responses[%s] => %s' % (name, data))
|
| 1242 |
+
return typ, data
|
| 1243 |
+
|
| 1244 |
+
|
| 1245 |
+
if __debug__:
|
| 1246 |
+
|
| 1247 |
+
def _mesg(self, s, secs=None):
|
| 1248 |
+
if secs is None:
|
| 1249 |
+
secs = time.time()
|
| 1250 |
+
tm = time.strftime('%M:%S', time.localtime(secs))
|
| 1251 |
+
sys.stderr.write(' %s.%02d %s\n' % (tm, (secs*100)%100, s))
|
| 1252 |
+
sys.stderr.flush()
|
| 1253 |
+
|
| 1254 |
+
def _dump_ur(self, untagged_resp_dict):
|
| 1255 |
+
if not untagged_resp_dict:
|
| 1256 |
+
return
|
| 1257 |
+
items = (f'{key}: {value!r}'
|
| 1258 |
+
for key, value in untagged_resp_dict.items())
|
| 1259 |
+
self._mesg('untagged responses dump:' + '\n\t\t'.join(items))
|
| 1260 |
+
|
| 1261 |
+
def _log(self, line):
|
| 1262 |
+
# Keep log of last `_cmd_log_len' interactions for debugging.
|
| 1263 |
+
self._cmd_log[self._cmd_log_idx] = (line, time.time())
|
| 1264 |
+
self._cmd_log_idx += 1
|
| 1265 |
+
if self._cmd_log_idx >= self._cmd_log_len:
|
| 1266 |
+
self._cmd_log_idx = 0
|
| 1267 |
+
|
| 1268 |
+
def print_log(self):
|
| 1269 |
+
self._mesg('last %d IMAP4 interactions:' % len(self._cmd_log))
|
| 1270 |
+
i, n = self._cmd_log_idx, self._cmd_log_len
|
| 1271 |
+
while n:
|
| 1272 |
+
try:
|
| 1273 |
+
self._mesg(*self._cmd_log[i])
|
| 1274 |
+
except:
|
| 1275 |
+
pass
|
| 1276 |
+
i += 1
|
| 1277 |
+
if i >= self._cmd_log_len:
|
| 1278 |
+
i = 0
|
| 1279 |
+
n -= 1
|
| 1280 |
+
|
| 1281 |
+
|
| 1282 |
+
if HAVE_SSL:
|
| 1283 |
+
|
| 1284 |
+
class IMAP4_SSL(IMAP4):
|
| 1285 |
+
|
| 1286 |
+
"""IMAP4 client class over SSL connection
|
| 1287 |
+
|
| 1288 |
+
Instantiate with: IMAP4_SSL([host[, port[, keyfile[, certfile[, ssl_context[, timeout=None]]]]]])
|
| 1289 |
+
|
| 1290 |
+
host - host's name (default: localhost);
|
| 1291 |
+
port - port number (default: standard IMAP4 SSL port);
|
| 1292 |
+
keyfile - PEM formatted file that contains your private key (default: None);
|
| 1293 |
+
certfile - PEM formatted certificate chain file (default: None);
|
| 1294 |
+
ssl_context - a SSLContext object that contains your certificate chain
|
| 1295 |
+
and private key (default: None)
|
| 1296 |
+
Note: if ssl_context is provided, then parameters keyfile or
|
| 1297 |
+
certfile should not be set otherwise ValueError is raised.
|
| 1298 |
+
timeout - socket timeout (default: None) If timeout is not given or is None,
|
| 1299 |
+
the global default socket timeout is used
|
| 1300 |
+
|
| 1301 |
+
for more documentation see the docstring of the parent class IMAP4.
|
| 1302 |
+
"""
|
| 1303 |
+
|
| 1304 |
+
|
| 1305 |
+
def __init__(self, host='', port=IMAP4_SSL_PORT, keyfile=None,
|
| 1306 |
+
certfile=None, ssl_context=None, timeout=None):
|
| 1307 |
+
if ssl_context is not None and keyfile is not None:
|
| 1308 |
+
raise ValueError("ssl_context and keyfile arguments are mutually "
|
| 1309 |
+
"exclusive")
|
| 1310 |
+
if ssl_context is not None and certfile is not None:
|
| 1311 |
+
raise ValueError("ssl_context and certfile arguments are mutually "
|
| 1312 |
+
"exclusive")
|
| 1313 |
+
if keyfile is not None or certfile is not None:
|
| 1314 |
+
import warnings
|
| 1315 |
+
warnings.warn("keyfile and certfile are deprecated, use a "
|
| 1316 |
+
"custom ssl_context instead", DeprecationWarning, 2)
|
| 1317 |
+
self.keyfile = keyfile
|
| 1318 |
+
self.certfile = certfile
|
| 1319 |
+
if ssl_context is None:
|
| 1320 |
+
ssl_context = ssl._create_stdlib_context(certfile=certfile,
|
| 1321 |
+
keyfile=keyfile)
|
| 1322 |
+
self.ssl_context = ssl_context
|
| 1323 |
+
IMAP4.__init__(self, host, port, timeout)
|
| 1324 |
+
|
| 1325 |
+
def _create_socket(self, timeout):
|
| 1326 |
+
sock = IMAP4._create_socket(self, timeout)
|
| 1327 |
+
return self.ssl_context.wrap_socket(sock,
|
| 1328 |
+
server_hostname=self.host)
|
| 1329 |
+
|
| 1330 |
+
def open(self, host='', port=IMAP4_SSL_PORT, timeout=None):
|
| 1331 |
+
"""Setup connection to remote server on "host:port".
|
| 1332 |
+
(default: localhost:standard IMAP4 SSL port).
|
| 1333 |
+
This connection will be used by the routines:
|
| 1334 |
+
read, readline, send, shutdown.
|
| 1335 |
+
"""
|
| 1336 |
+
IMAP4.open(self, host, port, timeout)
|
| 1337 |
+
|
| 1338 |
+
__all__.append("IMAP4_SSL")
|
| 1339 |
+
|
| 1340 |
+
|
| 1341 |
+
class IMAP4_stream(IMAP4):
|
| 1342 |
+
|
| 1343 |
+
"""IMAP4 client class over a stream
|
| 1344 |
+
|
| 1345 |
+
Instantiate with: IMAP4_stream(command)
|
| 1346 |
+
|
| 1347 |
+
"command" - a string that can be passed to subprocess.Popen()
|
| 1348 |
+
|
| 1349 |
+
for more documentation see the docstring of the parent class IMAP4.
|
| 1350 |
+
"""
|
| 1351 |
+
|
| 1352 |
+
|
| 1353 |
+
def __init__(self, command):
|
| 1354 |
+
self.command = command
|
| 1355 |
+
IMAP4.__init__(self)
|
| 1356 |
+
|
| 1357 |
+
|
| 1358 |
+
def open(self, host=None, port=None, timeout=None):
|
| 1359 |
+
"""Setup a stream connection.
|
| 1360 |
+
This connection will be used by the routines:
|
| 1361 |
+
read, readline, send, shutdown.
|
| 1362 |
+
"""
|
| 1363 |
+
self.host = None # For compatibility with parent class
|
| 1364 |
+
self.port = None
|
| 1365 |
+
self.sock = None
|
| 1366 |
+
self.file = None
|
| 1367 |
+
self.process = subprocess.Popen(self.command,
|
| 1368 |
+
bufsize=DEFAULT_BUFFER_SIZE,
|
| 1369 |
+
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
|
| 1370 |
+
shell=True, close_fds=True)
|
| 1371 |
+
self.writefile = self.process.stdin
|
| 1372 |
+
self.readfile = self.process.stdout
|
| 1373 |
+
|
| 1374 |
+
def read(self, size):
|
| 1375 |
+
"""Read 'size' bytes from remote."""
|
| 1376 |
+
return self.readfile.read(size)
|
| 1377 |
+
|
| 1378 |
+
|
| 1379 |
+
def readline(self):
|
| 1380 |
+
"""Read line from remote."""
|
| 1381 |
+
return self.readfile.readline()
|
| 1382 |
+
|
| 1383 |
+
|
| 1384 |
+
def send(self, data):
|
| 1385 |
+
"""Send data to remote."""
|
| 1386 |
+
self.writefile.write(data)
|
| 1387 |
+
self.writefile.flush()
|
| 1388 |
+
|
| 1389 |
+
|
| 1390 |
+
def shutdown(self):
|
| 1391 |
+
"""Close I/O established in "open"."""
|
| 1392 |
+
self.readfile.close()
|
| 1393 |
+
self.writefile.close()
|
| 1394 |
+
self.process.wait()
|
| 1395 |
+
|
| 1396 |
+
|
| 1397 |
+
|
| 1398 |
+
class _Authenticator:
|
| 1399 |
+
|
| 1400 |
+
"""Private class to provide en/decoding
|
| 1401 |
+
for base64-based authentication conversation.
|
| 1402 |
+
"""
|
| 1403 |
+
|
| 1404 |
+
def __init__(self, mechinst):
|
| 1405 |
+
self.mech = mechinst # Callable object to provide/process data
|
| 1406 |
+
|
| 1407 |
+
def process(self, data):
|
| 1408 |
+
ret = self.mech(self.decode(data))
|
| 1409 |
+
if ret is None:
|
| 1410 |
+
return b'*' # Abort conversation
|
| 1411 |
+
return self.encode(ret)
|
| 1412 |
+
|
| 1413 |
+
def encode(self, inp):
|
| 1414 |
+
#
|
| 1415 |
+
# Invoke binascii.b2a_base64 iteratively with
|
| 1416 |
+
# short even length buffers, strip the trailing
|
| 1417 |
+
# line feed from the result and append. "Even"
|
| 1418 |
+
# means a number that factors to both 6 and 8,
|
| 1419 |
+
# so when it gets to the end of the 8-bit input
|
| 1420 |
+
# there's no partial 6-bit output.
|
| 1421 |
+
#
|
| 1422 |
+
oup = b''
|
| 1423 |
+
if isinstance(inp, str):
|
| 1424 |
+
inp = inp.encode('utf-8')
|
| 1425 |
+
while inp:
|
| 1426 |
+
if len(inp) > 48:
|
| 1427 |
+
t = inp[:48]
|
| 1428 |
+
inp = inp[48:]
|
| 1429 |
+
else:
|
| 1430 |
+
t = inp
|
| 1431 |
+
inp = b''
|
| 1432 |
+
e = binascii.b2a_base64(t)
|
| 1433 |
+
if e:
|
| 1434 |
+
oup = oup + e[:-1]
|
| 1435 |
+
return oup
|
| 1436 |
+
|
| 1437 |
+
def decode(self, inp):
|
| 1438 |
+
if not inp:
|
| 1439 |
+
return b''
|
| 1440 |
+
return binascii.a2b_base64(inp)
|
| 1441 |
+
|
| 1442 |
+
Months = ' Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec'.split(' ')
|
| 1443 |
+
Mon2num = {s.encode():n+1 for n, s in enumerate(Months[1:])}
|
| 1444 |
+
|
| 1445 |
+
def Internaldate2tuple(resp):
|
| 1446 |
+
"""Parse an IMAP4 INTERNALDATE string.
|
| 1447 |
+
|
| 1448 |
+
Return corresponding local time. The return value is a
|
| 1449 |
+
time.struct_time tuple or None if the string has wrong format.
|
| 1450 |
+
"""
|
| 1451 |
+
|
| 1452 |
+
mo = InternalDate.match(resp)
|
| 1453 |
+
if not mo:
|
| 1454 |
+
return None
|
| 1455 |
+
|
| 1456 |
+
mon = Mon2num[mo.group('mon')]
|
| 1457 |
+
zonen = mo.group('zonen')
|
| 1458 |
+
|
| 1459 |
+
day = int(mo.group('day'))
|
| 1460 |
+
year = int(mo.group('year'))
|
| 1461 |
+
hour = int(mo.group('hour'))
|
| 1462 |
+
min = int(mo.group('min'))
|
| 1463 |
+
sec = int(mo.group('sec'))
|
| 1464 |
+
zoneh = int(mo.group('zoneh'))
|
| 1465 |
+
zonem = int(mo.group('zonem'))
|
| 1466 |
+
|
| 1467 |
+
# INTERNALDATE timezone must be subtracted to get UT
|
| 1468 |
+
|
| 1469 |
+
zone = (zoneh*60 + zonem)*60
|
| 1470 |
+
if zonen == b'-':
|
| 1471 |
+
zone = -zone
|
| 1472 |
+
|
| 1473 |
+
tt = (year, mon, day, hour, min, sec, -1, -1, -1)
|
| 1474 |
+
utc = calendar.timegm(tt) - zone
|
| 1475 |
+
|
| 1476 |
+
return time.localtime(utc)
|
| 1477 |
+
|
| 1478 |
+
|
| 1479 |
+
|
| 1480 |
+
def Int2AP(num):
|
| 1481 |
+
|
| 1482 |
+
"""Convert integer to A-P string representation."""
|
| 1483 |
+
|
| 1484 |
+
val = b''; AP = b'ABCDEFGHIJKLMNOP'
|
| 1485 |
+
num = int(abs(num))
|
| 1486 |
+
while num:
|
| 1487 |
+
num, mod = divmod(num, 16)
|
| 1488 |
+
val = AP[mod:mod+1] + val
|
| 1489 |
+
return val
|
| 1490 |
+
|
| 1491 |
+
|
| 1492 |
+
|
| 1493 |
+
def ParseFlags(resp):
|
| 1494 |
+
|
| 1495 |
+
"""Convert IMAP4 flags response to python tuple."""
|
| 1496 |
+
|
| 1497 |
+
mo = Flags.match(resp)
|
| 1498 |
+
if not mo:
|
| 1499 |
+
return ()
|
| 1500 |
+
|
| 1501 |
+
return tuple(mo.group('flags').split())
|
| 1502 |
+
|
| 1503 |
+
|
| 1504 |
+
def Time2Internaldate(date_time):
|
| 1505 |
+
|
| 1506 |
+
"""Convert date_time to IMAP4 INTERNALDATE representation.
|
| 1507 |
+
|
| 1508 |
+
Return string in form: '"DD-Mmm-YYYY HH:MM:SS +HHMM"'. The
|
| 1509 |
+
date_time argument can be a number (int or float) representing
|
| 1510 |
+
seconds since epoch (as returned by time.time()), a 9-tuple
|
| 1511 |
+
representing local time, an instance of time.struct_time (as
|
| 1512 |
+
returned by time.localtime()), an aware datetime instance or a
|
| 1513 |
+
double-quoted string. In the last case, it is assumed to already
|
| 1514 |
+
be in the correct format.
|
| 1515 |
+
"""
|
| 1516 |
+
if isinstance(date_time, (int, float)):
|
| 1517 |
+
dt = datetime.fromtimestamp(date_time,
|
| 1518 |
+
timezone.utc).astimezone()
|
| 1519 |
+
elif isinstance(date_time, tuple):
|
| 1520 |
+
try:
|
| 1521 |
+
gmtoff = date_time.tm_gmtoff
|
| 1522 |
+
except AttributeError:
|
| 1523 |
+
if time.daylight:
|
| 1524 |
+
dst = date_time[8]
|
| 1525 |
+
if dst == -1:
|
| 1526 |
+
dst = time.localtime(time.mktime(date_time))[8]
|
| 1527 |
+
gmtoff = -(time.timezone, time.altzone)[dst]
|
| 1528 |
+
else:
|
| 1529 |
+
gmtoff = -time.timezone
|
| 1530 |
+
delta = timedelta(seconds=gmtoff)
|
| 1531 |
+
dt = datetime(*date_time[:6], tzinfo=timezone(delta))
|
| 1532 |
+
elif isinstance(date_time, datetime):
|
| 1533 |
+
if date_time.tzinfo is None:
|
| 1534 |
+
raise ValueError("date_time must be aware")
|
| 1535 |
+
dt = date_time
|
| 1536 |
+
elif isinstance(date_time, str) and (date_time[0],date_time[-1]) == ('"','"'):
|
| 1537 |
+
return date_time # Assume in correct format
|
| 1538 |
+
else:
|
| 1539 |
+
raise ValueError("date_time not of a known type")
|
| 1540 |
+
fmt = '"%d-{}-%Y %H:%M:%S %z"'.format(Months[dt.month])
|
| 1541 |
+
return dt.strftime(fmt)
|
| 1542 |
+
|
| 1543 |
+
|
| 1544 |
+
|
| 1545 |
+
if __name__ == '__main__':
|
| 1546 |
+
|
| 1547 |
+
# To test: invoke either as 'python imaplib.py [IMAP4_server_hostname]'
|
| 1548 |
+
# or 'python imaplib.py -s "rsh IMAP4_server_hostname exec /etc/rimapd"'
|
| 1549 |
+
# to test the IMAP4_stream class
|
| 1550 |
+
|
| 1551 |
+
import getopt, getpass
|
| 1552 |
+
|
| 1553 |
+
try:
|
| 1554 |
+
optlist, args = getopt.getopt(sys.argv[1:], 'd:s:')
|
| 1555 |
+
except getopt.error as val:
|
| 1556 |
+
optlist, args = (), ()
|
| 1557 |
+
|
| 1558 |
+
stream_command = None
|
| 1559 |
+
for opt,val in optlist:
|
| 1560 |
+
if opt == '-d':
|
| 1561 |
+
Debug = int(val)
|
| 1562 |
+
elif opt == '-s':
|
| 1563 |
+
stream_command = val
|
| 1564 |
+
if not args: args = (stream_command,)
|
| 1565 |
+
|
| 1566 |
+
if not args: args = ('',)
|
| 1567 |
+
|
| 1568 |
+
host = args[0]
|
| 1569 |
+
|
| 1570 |
+
USER = getpass.getuser()
|
| 1571 |
+
PASSWD = getpass.getpass("IMAP password for %s on %s: " % (USER, host or "localhost"))
|
| 1572 |
+
|
| 1573 |
+
test_mesg = 'From: %(user)s@localhost%(lf)sSubject: IMAP4 test%(lf)s%(lf)sdata...%(lf)s' % {'user':USER, 'lf':'\n'}
|
| 1574 |
+
test_seq1 = (
|
| 1575 |
+
('login', (USER, PASSWD)),
|
| 1576 |
+
('create', ('/tmp/xxx 1',)),
|
| 1577 |
+
('rename', ('/tmp/xxx 1', '/tmp/yyy')),
|
| 1578 |
+
('CREATE', ('/tmp/yyz 2',)),
|
| 1579 |
+
('append', ('/tmp/yyz 2', None, None, test_mesg)),
|
| 1580 |
+
('list', ('/tmp', 'yy*')),
|
| 1581 |
+
('select', ('/tmp/yyz 2',)),
|
| 1582 |
+
('search', (None, 'SUBJECT', 'test')),
|
| 1583 |
+
('fetch', ('1', '(FLAGS INTERNALDATE RFC822)')),
|
| 1584 |
+
('store', ('1', 'FLAGS', r'(\Deleted)')),
|
| 1585 |
+
('namespace', ()),
|
| 1586 |
+
('expunge', ()),
|
| 1587 |
+
('recent', ()),
|
| 1588 |
+
('close', ()),
|
| 1589 |
+
)
|
| 1590 |
+
|
| 1591 |
+
test_seq2 = (
|
| 1592 |
+
('select', ()),
|
| 1593 |
+
('response',('UIDVALIDITY',)),
|
| 1594 |
+
('uid', ('SEARCH', 'ALL')),
|
| 1595 |
+
('response', ('EXISTS',)),
|
| 1596 |
+
('append', (None, None, None, test_mesg)),
|
| 1597 |
+
('recent', ()),
|
| 1598 |
+
('logout', ()),
|
| 1599 |
+
)
|
| 1600 |
+
|
| 1601 |
+
def run(cmd, args):
|
| 1602 |
+
M._mesg('%s %s' % (cmd, args))
|
| 1603 |
+
typ, dat = getattr(M, cmd)(*args)
|
| 1604 |
+
M._mesg('%s => %s %s' % (cmd, typ, dat))
|
| 1605 |
+
if typ == 'NO': raise dat[0]
|
| 1606 |
+
return dat
|
| 1607 |
+
|
| 1608 |
+
try:
|
| 1609 |
+
if stream_command:
|
| 1610 |
+
M = IMAP4_stream(stream_command)
|
| 1611 |
+
else:
|
| 1612 |
+
M = IMAP4(host)
|
| 1613 |
+
if M.state == 'AUTH':
|
| 1614 |
+
test_seq1 = test_seq1[1:] # Login not needed
|
| 1615 |
+
M._mesg('PROTOCOL_VERSION = %s' % M.PROTOCOL_VERSION)
|
| 1616 |
+
M._mesg('CAPABILITIES = %r' % (M.capabilities,))
|
| 1617 |
+
|
| 1618 |
+
for cmd,args in test_seq1:
|
| 1619 |
+
run(cmd, args)
|
| 1620 |
+
|
| 1621 |
+
for ml in run('list', ('/tmp/', 'yy%')):
|
| 1622 |
+
mo = re.match(r'.*"([^"]+)"$', ml)
|
| 1623 |
+
if mo: path = mo.group(1)
|
| 1624 |
+
else: path = ml.split()[-1]
|
| 1625 |
+
run('delete', (path,))
|
| 1626 |
+
|
| 1627 |
+
for cmd,args in test_seq2:
|
| 1628 |
+
dat = run(cmd, args)
|
| 1629 |
+
|
| 1630 |
+
if (cmd,args) != ('uid', ('SEARCH', 'ALL')):
|
| 1631 |
+
continue
|
| 1632 |
+
|
| 1633 |
+
uid = dat[-1].split()
|
| 1634 |
+
if not uid: continue
|
| 1635 |
+
run('uid', ('FETCH', '%s' % uid[-1],
|
| 1636 |
+
'(FLAGS INTERNALDATE RFC822.SIZE RFC822.HEADER RFC822.TEXT)'))
|
| 1637 |
+
|
| 1638 |
+
print('\nAll tests OK.')
|
| 1639 |
+
|
| 1640 |
+
except:
|
| 1641 |
+
print('\nTests failed.')
|
| 1642 |
+
|
| 1643 |
+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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Locale support module.
|
| 2 |
+
|
| 3 |
+
The module provides low-level access to the C lib's locale APIs and adds high
|
| 4 |
+
level number formatting APIs as well as a locale aliasing engine to complement
|
| 5 |
+
these.
|
| 6 |
+
|
| 7 |
+
The aliasing engine includes support for many commonly used locale names and
|
| 8 |
+
maps them to values suitable for passing to the C lib's setlocale() function. It
|
| 9 |
+
also includes default encodings for all supported locale names.
|
| 10 |
+
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
import sys
|
| 14 |
+
import encodings
|
| 15 |
+
import encodings.aliases
|
| 16 |
+
import re
|
| 17 |
+
import _collections_abc
|
| 18 |
+
from builtins import str as _builtin_str
|
| 19 |
+
import functools
|
| 20 |
+
|
| 21 |
+
# Try importing the _locale module.
|
| 22 |
+
#
|
| 23 |
+
# If this fails, fall back on a basic 'C' locale emulation.
|
| 24 |
+
|
| 25 |
+
# Yuck: LC_MESSAGES is non-standard: can't tell whether it exists before
|
| 26 |
+
# trying the import. So __all__ is also fiddled at the end of the file.
|
| 27 |
+
__all__ = ["getlocale", "getdefaultlocale", "getpreferredencoding", "Error",
|
| 28 |
+
"setlocale", "resetlocale", "localeconv", "strcoll", "strxfrm",
|
| 29 |
+
"str", "atof", "atoi", "format", "format_string", "currency",
|
| 30 |
+
"normalize", "LC_CTYPE", "LC_COLLATE", "LC_TIME", "LC_MONETARY",
|
| 31 |
+
"LC_NUMERIC", "LC_ALL", "CHAR_MAX"]
|
| 32 |
+
|
| 33 |
+
def _strcoll(a,b):
|
| 34 |
+
""" strcoll(string,string) -> int.
|
| 35 |
+
Compares two strings according to the locale.
|
| 36 |
+
"""
|
| 37 |
+
return (a > b) - (a < b)
|
| 38 |
+
|
| 39 |
+
def _strxfrm(s):
|
| 40 |
+
""" strxfrm(string) -> string.
|
| 41 |
+
Returns a string that behaves for cmp locale-aware.
|
| 42 |
+
"""
|
| 43 |
+
return s
|
| 44 |
+
|
| 45 |
+
try:
|
| 46 |
+
|
| 47 |
+
from _locale import *
|
| 48 |
+
|
| 49 |
+
except ImportError:
|
| 50 |
+
|
| 51 |
+
# Locale emulation
|
| 52 |
+
|
| 53 |
+
CHAR_MAX = 127
|
| 54 |
+
LC_ALL = 6
|
| 55 |
+
LC_COLLATE = 3
|
| 56 |
+
LC_CTYPE = 0
|
| 57 |
+
LC_MESSAGES = 5
|
| 58 |
+
LC_MONETARY = 4
|
| 59 |
+
LC_NUMERIC = 1
|
| 60 |
+
LC_TIME = 2
|
| 61 |
+
Error = ValueError
|
| 62 |
+
|
| 63 |
+
def localeconv():
|
| 64 |
+
""" localeconv() -> dict.
|
| 65 |
+
Returns numeric and monetary locale-specific parameters.
|
| 66 |
+
"""
|
| 67 |
+
# 'C' locale default values
|
| 68 |
+
return {'grouping': [127],
|
| 69 |
+
'currency_symbol': '',
|
| 70 |
+
'n_sign_posn': 127,
|
| 71 |
+
'p_cs_precedes': 127,
|
| 72 |
+
'n_cs_precedes': 127,
|
| 73 |
+
'mon_grouping': [],
|
| 74 |
+
'n_sep_by_space': 127,
|
| 75 |
+
'decimal_point': '.',
|
| 76 |
+
'negative_sign': '',
|
| 77 |
+
'positive_sign': '',
|
| 78 |
+
'p_sep_by_space': 127,
|
| 79 |
+
'int_curr_symbol': '',
|
| 80 |
+
'p_sign_posn': 127,
|
| 81 |
+
'thousands_sep': '',
|
| 82 |
+
'mon_thousands_sep': '',
|
| 83 |
+
'frac_digits': 127,
|
| 84 |
+
'mon_decimal_point': '',
|
| 85 |
+
'int_frac_digits': 127}
|
| 86 |
+
|
| 87 |
+
def setlocale(category, value=None):
|
| 88 |
+
""" setlocale(integer,string=None) -> string.
|
| 89 |
+
Activates/queries locale processing.
|
| 90 |
+
"""
|
| 91 |
+
if value not in (None, '', 'C'):
|
| 92 |
+
raise Error('_locale emulation only supports "C" locale')
|
| 93 |
+
return 'C'
|
| 94 |
+
|
| 95 |
+
# These may or may not exist in _locale, so be sure to set them.
|
| 96 |
+
if 'strxfrm' not in globals():
|
| 97 |
+
strxfrm = _strxfrm
|
| 98 |
+
if 'strcoll' not in globals():
|
| 99 |
+
strcoll = _strcoll
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
_localeconv = localeconv
|
| 103 |
+
|
| 104 |
+
# With this dict, you can override some items of localeconv's return value.
|
| 105 |
+
# This is useful for testing purposes.
|
| 106 |
+
_override_localeconv = {}
|
| 107 |
+
|
| 108 |
+
@functools.wraps(_localeconv)
|
| 109 |
+
def localeconv():
|
| 110 |
+
d = _localeconv()
|
| 111 |
+
if _override_localeconv:
|
| 112 |
+
d.update(_override_localeconv)
|
| 113 |
+
return d
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
### Number formatting APIs
|
| 117 |
+
|
| 118 |
+
# Author: Martin von Loewis
|
| 119 |
+
# improved by Georg Brandl
|
| 120 |
+
|
| 121 |
+
# Iterate over grouping intervals
|
| 122 |
+
def _grouping_intervals(grouping):
|
| 123 |
+
last_interval = None
|
| 124 |
+
for interval in grouping:
|
| 125 |
+
# if grouping is -1, we are done
|
| 126 |
+
if interval == CHAR_MAX:
|
| 127 |
+
return
|
| 128 |
+
# 0: re-use last group ad infinitum
|
| 129 |
+
if interval == 0:
|
| 130 |
+
if last_interval is None:
|
| 131 |
+
raise ValueError("invalid grouping")
|
| 132 |
+
while True:
|
| 133 |
+
yield last_interval
|
| 134 |
+
yield interval
|
| 135 |
+
last_interval = interval
|
| 136 |
+
|
| 137 |
+
#perform the grouping from right to left
|
| 138 |
+
def _group(s, monetary=False):
|
| 139 |
+
conv = localeconv()
|
| 140 |
+
thousands_sep = conv[monetary and 'mon_thousands_sep' or 'thousands_sep']
|
| 141 |
+
grouping = conv[monetary and 'mon_grouping' or 'grouping']
|
| 142 |
+
if not grouping:
|
| 143 |
+
return (s, 0)
|
| 144 |
+
if s[-1] == ' ':
|
| 145 |
+
stripped = s.rstrip()
|
| 146 |
+
right_spaces = s[len(stripped):]
|
| 147 |
+
s = stripped
|
| 148 |
+
else:
|
| 149 |
+
right_spaces = ''
|
| 150 |
+
left_spaces = ''
|
| 151 |
+
groups = []
|
| 152 |
+
for interval in _grouping_intervals(grouping):
|
| 153 |
+
if not s or s[-1] not in "0123456789":
|
| 154 |
+
# only non-digit characters remain (sign, spaces)
|
| 155 |
+
left_spaces = s
|
| 156 |
+
s = ''
|
| 157 |
+
break
|
| 158 |
+
groups.append(s[-interval:])
|
| 159 |
+
s = s[:-interval]
|
| 160 |
+
if s:
|
| 161 |
+
groups.append(s)
|
| 162 |
+
groups.reverse()
|
| 163 |
+
return (
|
| 164 |
+
left_spaces + thousands_sep.join(groups) + right_spaces,
|
| 165 |
+
len(thousands_sep) * (len(groups) - 1)
|
| 166 |
+
)
|
| 167 |
+
|
| 168 |
+
# Strip a given amount of excess padding from the given string
|
| 169 |
+
def _strip_padding(s, amount):
|
| 170 |
+
lpos = 0
|
| 171 |
+
while amount and s[lpos] == ' ':
|
| 172 |
+
lpos += 1
|
| 173 |
+
amount -= 1
|
| 174 |
+
rpos = len(s) - 1
|
| 175 |
+
while amount and s[rpos] == ' ':
|
| 176 |
+
rpos -= 1
|
| 177 |
+
amount -= 1
|
| 178 |
+
return s[lpos:rpos+1]
|
| 179 |
+
|
| 180 |
+
_percent_re = re.compile(r'%(?:\((?P<key>.*?)\))?'
|
| 181 |
+
r'(?P<modifiers>[-#0-9 +*.hlL]*?)[eEfFgGdiouxXcrs%]')
|
| 182 |
+
|
| 183 |
+
def _format(percent, value, grouping=False, monetary=False, *additional):
|
| 184 |
+
if additional:
|
| 185 |
+
formatted = percent % ((value,) + additional)
|
| 186 |
+
else:
|
| 187 |
+
formatted = percent % value
|
| 188 |
+
if percent[-1] in 'eEfFgGdiu':
|
| 189 |
+
formatted = _localize(formatted, grouping, monetary)
|
| 190 |
+
return formatted
|
| 191 |
+
|
| 192 |
+
# Transform formatted as locale number according to the locale settings
|
| 193 |
+
def _localize(formatted, grouping=False, monetary=False):
|
| 194 |
+
# floats and decimal ints need special action!
|
| 195 |
+
if '.' in formatted:
|
| 196 |
+
seps = 0
|
| 197 |
+
parts = formatted.split('.')
|
| 198 |
+
if grouping:
|
| 199 |
+
parts[0], seps = _group(parts[0], monetary=monetary)
|
| 200 |
+
decimal_point = localeconv()[monetary and 'mon_decimal_point'
|
| 201 |
+
or 'decimal_point']
|
| 202 |
+
formatted = decimal_point.join(parts)
|
| 203 |
+
if seps:
|
| 204 |
+
formatted = _strip_padding(formatted, seps)
|
| 205 |
+
else:
|
| 206 |
+
seps = 0
|
| 207 |
+
if grouping:
|
| 208 |
+
formatted, seps = _group(formatted, monetary=monetary)
|
| 209 |
+
if seps:
|
| 210 |
+
formatted = _strip_padding(formatted, seps)
|
| 211 |
+
return formatted
|
| 212 |
+
|
| 213 |
+
def format_string(f, val, grouping=False, monetary=False):
|
| 214 |
+
"""Formats a string in the same way that the % formatting would use,
|
| 215 |
+
but takes the current locale into account.
|
| 216 |
+
|
| 217 |
+
Grouping is applied if the third parameter is true.
|
| 218 |
+
Conversion uses monetary thousands separator and grouping strings if
|
| 219 |
+
forth parameter monetary is true."""
|
| 220 |
+
percents = list(_percent_re.finditer(f))
|
| 221 |
+
new_f = _percent_re.sub('%s', f)
|
| 222 |
+
|
| 223 |
+
if isinstance(val, _collections_abc.Mapping):
|
| 224 |
+
new_val = []
|
| 225 |
+
for perc in percents:
|
| 226 |
+
if perc.group()[-1]=='%':
|
| 227 |
+
new_val.append('%')
|
| 228 |
+
else:
|
| 229 |
+
new_val.append(_format(perc.group(), val, grouping, monetary))
|
| 230 |
+
else:
|
| 231 |
+
if not isinstance(val, tuple):
|
| 232 |
+
val = (val,)
|
| 233 |
+
new_val = []
|
| 234 |
+
i = 0
|
| 235 |
+
for perc in percents:
|
| 236 |
+
if perc.group()[-1]=='%':
|
| 237 |
+
new_val.append('%')
|
| 238 |
+
else:
|
| 239 |
+
starcount = perc.group('modifiers').count('*')
|
| 240 |
+
new_val.append(_format(perc.group(),
|
| 241 |
+
val[i],
|
| 242 |
+
grouping,
|
| 243 |
+
monetary,
|
| 244 |
+
*val[i+1:i+1+starcount]))
|
| 245 |
+
i += (1 + starcount)
|
| 246 |
+
val = tuple(new_val)
|
| 247 |
+
|
| 248 |
+
return new_f % val
|
| 249 |
+
|
| 250 |
+
def format(percent, value, grouping=False, monetary=False, *additional):
|
| 251 |
+
"""Deprecated, use format_string instead."""
|
| 252 |
+
import warnings
|
| 253 |
+
warnings.warn(
|
| 254 |
+
"This method will be removed in a future version of Python. "
|
| 255 |
+
"Use 'locale.format_string()' instead.",
|
| 256 |
+
DeprecationWarning, stacklevel=2
|
| 257 |
+
)
|
| 258 |
+
|
| 259 |
+
match = _percent_re.match(percent)
|
| 260 |
+
if not match or len(match.group())!= len(percent):
|
| 261 |
+
raise ValueError(("format() must be given exactly one %%char "
|
| 262 |
+
"format specifier, %s not valid") % repr(percent))
|
| 263 |
+
return _format(percent, value, grouping, monetary, *additional)
|
| 264 |
+
|
| 265 |
+
def currency(val, symbol=True, grouping=False, international=False):
|
| 266 |
+
"""Formats val according to the currency settings
|
| 267 |
+
in the current locale."""
|
| 268 |
+
conv = localeconv()
|
| 269 |
+
|
| 270 |
+
# check for illegal values
|
| 271 |
+
digits = conv[international and 'int_frac_digits' or 'frac_digits']
|
| 272 |
+
if digits == 127:
|
| 273 |
+
raise ValueError("Currency formatting is not possible using "
|
| 274 |
+
"the 'C' locale.")
|
| 275 |
+
|
| 276 |
+
s = _localize(f'{abs(val):.{digits}f}', grouping, monetary=True)
|
| 277 |
+
# '<' and '>' are markers if the sign must be inserted between symbol and value
|
| 278 |
+
s = '<' + s + '>'
|
| 279 |
+
|
| 280 |
+
if symbol:
|
| 281 |
+
smb = conv[international and 'int_curr_symbol' or 'currency_symbol']
|
| 282 |
+
precedes = conv[val<0 and 'n_cs_precedes' or 'p_cs_precedes']
|
| 283 |
+
separated = conv[val<0 and 'n_sep_by_space' or 'p_sep_by_space']
|
| 284 |
+
|
| 285 |
+
if precedes:
|
| 286 |
+
s = smb + (separated and ' ' or '') + s
|
| 287 |
+
else:
|
| 288 |
+
if international and smb[-1] == ' ':
|
| 289 |
+
smb = smb[:-1]
|
| 290 |
+
s = s + (separated and ' ' or '') + smb
|
| 291 |
+
|
| 292 |
+
sign_pos = conv[val<0 and 'n_sign_posn' or 'p_sign_posn']
|
| 293 |
+
sign = conv[val<0 and 'negative_sign' or 'positive_sign']
|
| 294 |
+
|
| 295 |
+
if sign_pos == 0:
|
| 296 |
+
s = '(' + s + ')'
|
| 297 |
+
elif sign_pos == 1:
|
| 298 |
+
s = sign + s
|
| 299 |
+
elif sign_pos == 2:
|
| 300 |
+
s = s + sign
|
| 301 |
+
elif sign_pos == 3:
|
| 302 |
+
s = s.replace('<', sign)
|
| 303 |
+
elif sign_pos == 4:
|
| 304 |
+
s = s.replace('>', sign)
|
| 305 |
+
else:
|
| 306 |
+
# the default if nothing specified;
|
| 307 |
+
# this should be the most fitting sign position
|
| 308 |
+
s = sign + s
|
| 309 |
+
|
| 310 |
+
return s.replace('<', '').replace('>', '')
|
| 311 |
+
|
| 312 |
+
def str(val):
|
| 313 |
+
"""Convert float to string, taking the locale into account."""
|
| 314 |
+
return _format("%.12g", val)
|
| 315 |
+
|
| 316 |
+
def delocalize(string):
|
| 317 |
+
"Parses a string as a normalized number according to the locale settings."
|
| 318 |
+
|
| 319 |
+
conv = localeconv()
|
| 320 |
+
|
| 321 |
+
#First, get rid of the grouping
|
| 322 |
+
ts = conv['thousands_sep']
|
| 323 |
+
if ts:
|
| 324 |
+
string = string.replace(ts, '')
|
| 325 |
+
|
| 326 |
+
#next, replace the decimal point with a dot
|
| 327 |
+
dd = conv['decimal_point']
|
| 328 |
+
if dd:
|
| 329 |
+
string = string.replace(dd, '.')
|
| 330 |
+
return string
|
| 331 |
+
|
| 332 |
+
def localize(string, grouping=False, monetary=False):
|
| 333 |
+
"""Parses a string as locale number according to the locale settings."""
|
| 334 |
+
return _localize(string, grouping, monetary)
|
| 335 |
+
|
| 336 |
+
def atof(string, func=float):
|
| 337 |
+
"Parses a string as a float according to the locale settings."
|
| 338 |
+
return func(delocalize(string))
|
| 339 |
+
|
| 340 |
+
def atoi(string):
|
| 341 |
+
"Converts a string to an integer according to the locale settings."
|
| 342 |
+
return int(delocalize(string))
|
| 343 |
+
|
| 344 |
+
def _test():
|
| 345 |
+
setlocale(LC_ALL, "")
|
| 346 |
+
#do grouping
|
| 347 |
+
s1 = format_string("%d", 123456789,1)
|
| 348 |
+
print(s1, "is", atoi(s1))
|
| 349 |
+
#standard formatting
|
| 350 |
+
s1 = str(3.14)
|
| 351 |
+
print(s1, "is", atof(s1))
|
| 352 |
+
|
| 353 |
+
### Locale name aliasing engine
|
| 354 |
+
|
| 355 |
+
# Author: Marc-Andre Lemburg, mal@lemburg.com
|
| 356 |
+
# Various tweaks by Fredrik Lundh <fredrik@pythonware.com>
|
| 357 |
+
|
| 358 |
+
# store away the low-level version of setlocale (it's
|
| 359 |
+
# overridden below)
|
| 360 |
+
_setlocale = setlocale
|
| 361 |
+
|
| 362 |
+
def _replace_encoding(code, encoding):
|
| 363 |
+
if '.' in code:
|
| 364 |
+
langname = code[:code.index('.')]
|
| 365 |
+
else:
|
| 366 |
+
langname = code
|
| 367 |
+
# Convert the encoding to a C lib compatible encoding string
|
| 368 |
+
norm_encoding = encodings.normalize_encoding(encoding)
|
| 369 |
+
#print('norm encoding: %r' % norm_encoding)
|
| 370 |
+
norm_encoding = encodings.aliases.aliases.get(norm_encoding.lower(),
|
| 371 |
+
norm_encoding)
|
| 372 |
+
#print('aliased encoding: %r' % norm_encoding)
|
| 373 |
+
encoding = norm_encoding
|
| 374 |
+
norm_encoding = norm_encoding.lower()
|
| 375 |
+
if norm_encoding in locale_encoding_alias:
|
| 376 |
+
encoding = locale_encoding_alias[norm_encoding]
|
| 377 |
+
else:
|
| 378 |
+
norm_encoding = norm_encoding.replace('_', '')
|
| 379 |
+
norm_encoding = norm_encoding.replace('-', '')
|
| 380 |
+
if norm_encoding in locale_encoding_alias:
|
| 381 |
+
encoding = locale_encoding_alias[norm_encoding]
|
| 382 |
+
#print('found encoding %r' % encoding)
|
| 383 |
+
return langname + '.' + encoding
|
| 384 |
+
|
| 385 |
+
def _append_modifier(code, modifier):
|
| 386 |
+
if modifier == 'euro':
|
| 387 |
+
if '.' not in code:
|
| 388 |
+
return code + '.ISO8859-15'
|
| 389 |
+
_, _, encoding = code.partition('.')
|
| 390 |
+
if encoding in ('ISO8859-15', 'UTF-8'):
|
| 391 |
+
return code
|
| 392 |
+
if encoding == 'ISO8859-1':
|
| 393 |
+
return _replace_encoding(code, 'ISO8859-15')
|
| 394 |
+
return code + '@' + modifier
|
| 395 |
+
|
| 396 |
+
def normalize(localename):
|
| 397 |
+
|
| 398 |
+
""" Returns a normalized locale code for the given locale
|
| 399 |
+
name.
|
| 400 |
+
|
| 401 |
+
The returned locale code is formatted for use with
|
| 402 |
+
setlocale().
|
| 403 |
+
|
| 404 |
+
If normalization fails, the original name is returned
|
| 405 |
+
unchanged.
|
| 406 |
+
|
| 407 |
+
If the given encoding is not known, the function defaults to
|
| 408 |
+
the default encoding for the locale code just like setlocale()
|
| 409 |
+
does.
|
| 410 |
+
|
| 411 |
+
"""
|
| 412 |
+
# Normalize the locale name and extract the encoding and modifier
|
| 413 |
+
code = localename.lower()
|
| 414 |
+
if ':' in code:
|
| 415 |
+
# ':' is sometimes used as encoding delimiter.
|
| 416 |
+
code = code.replace(':', '.')
|
| 417 |
+
if '@' in code:
|
| 418 |
+
code, modifier = code.split('@', 1)
|
| 419 |
+
else:
|
| 420 |
+
modifier = ''
|
| 421 |
+
if '.' in code:
|
| 422 |
+
langname, encoding = code.split('.')[:2]
|
| 423 |
+
else:
|
| 424 |
+
langname = code
|
| 425 |
+
encoding = ''
|
| 426 |
+
|
| 427 |
+
# First lookup: fullname (possibly with encoding and modifier)
|
| 428 |
+
lang_enc = langname
|
| 429 |
+
if encoding:
|
| 430 |
+
norm_encoding = encoding.replace('-', '')
|
| 431 |
+
norm_encoding = norm_encoding.replace('_', '')
|
| 432 |
+
lang_enc += '.' + norm_encoding
|
| 433 |
+
lookup_name = lang_enc
|
| 434 |
+
if modifier:
|
| 435 |
+
lookup_name += '@' + modifier
|
| 436 |
+
code = locale_alias.get(lookup_name, None)
|
| 437 |
+
if code is not None:
|
| 438 |
+
return code
|
| 439 |
+
#print('first lookup failed')
|
| 440 |
+
|
| 441 |
+
if modifier:
|
| 442 |
+
# Second try: fullname without modifier (possibly with encoding)
|
| 443 |
+
code = locale_alias.get(lang_enc, None)
|
| 444 |
+
if code is not None:
|
| 445 |
+
#print('lookup without modifier succeeded')
|
| 446 |
+
if '@' not in code:
|
| 447 |
+
return _append_modifier(code, modifier)
|
| 448 |
+
if code.split('@', 1)[1].lower() == modifier:
|
| 449 |
+
return code
|
| 450 |
+
#print('second lookup failed')
|
| 451 |
+
|
| 452 |
+
if encoding:
|
| 453 |
+
# Third try: langname (without encoding, possibly with modifier)
|
| 454 |
+
lookup_name = langname
|
| 455 |
+
if modifier:
|
| 456 |
+
lookup_name += '@' + modifier
|
| 457 |
+
code = locale_alias.get(lookup_name, None)
|
| 458 |
+
if code is not None:
|
| 459 |
+
#print('lookup without encoding succeeded')
|
| 460 |
+
if '@' not in code:
|
| 461 |
+
return _replace_encoding(code, encoding)
|
| 462 |
+
code, modifier = code.split('@', 1)
|
| 463 |
+
return _replace_encoding(code, encoding) + '@' + modifier
|
| 464 |
+
|
| 465 |
+
if modifier:
|
| 466 |
+
# Fourth try: langname (without encoding and modifier)
|
| 467 |
+
code = locale_alias.get(langname, None)
|
| 468 |
+
if code is not None:
|
| 469 |
+
#print('lookup without modifier and encoding succeeded')
|
| 470 |
+
if '@' not in code:
|
| 471 |
+
code = _replace_encoding(code, encoding)
|
| 472 |
+
return _append_modifier(code, modifier)
|
| 473 |
+
code, defmod = code.split('@', 1)
|
| 474 |
+
if defmod.lower() == modifier:
|
| 475 |
+
return _replace_encoding(code, encoding) + '@' + defmod
|
| 476 |
+
|
| 477 |
+
return localename
|
| 478 |
+
|
| 479 |
+
def _parse_localename(localename):
|
| 480 |
+
|
| 481 |
+
""" Parses the locale code for localename and returns the
|
| 482 |
+
result as tuple (language code, encoding).
|
| 483 |
+
|
| 484 |
+
The localename is normalized and passed through the locale
|
| 485 |
+
alias engine. A ValueError is raised in case the locale name
|
| 486 |
+
cannot be parsed.
|
| 487 |
+
|
| 488 |
+
The language code corresponds to RFC 1766. code and encoding
|
| 489 |
+
can be None in case the values cannot be determined or are
|
| 490 |
+
unknown to this implementation.
|
| 491 |
+
|
| 492 |
+
"""
|
| 493 |
+
code = normalize(localename)
|
| 494 |
+
if '@' in code:
|
| 495 |
+
# Deal with locale modifiers
|
| 496 |
+
code, modifier = code.split('@', 1)
|
| 497 |
+
if modifier == 'euro' and '.' not in code:
|
| 498 |
+
# Assume Latin-9 for @euro locales. This is bogus,
|
| 499 |
+
# since some systems may use other encodings for these
|
| 500 |
+
# locales. Also, we ignore other modifiers.
|
| 501 |
+
return code, 'iso-8859-15'
|
| 502 |
+
|
| 503 |
+
if '.' in code:
|
| 504 |
+
return tuple(code.split('.')[:2])
|
| 505 |
+
elif code == 'C':
|
| 506 |
+
return None, None
|
| 507 |
+
elif code == 'UTF-8':
|
| 508 |
+
# On macOS "LC_CTYPE=UTF-8" is a valid locale setting
|
| 509 |
+
# for getting UTF-8 handling for text.
|
| 510 |
+
return None, 'UTF-8'
|
| 511 |
+
raise ValueError('unknown locale: %s' % localename)
|
| 512 |
+
|
| 513 |
+
def _build_localename(localetuple):
|
| 514 |
+
|
| 515 |
+
""" Builds a locale code from the given tuple (language code,
|
| 516 |
+
encoding).
|
| 517 |
+
|
| 518 |
+
No aliasing or normalizing takes place.
|
| 519 |
+
|
| 520 |
+
"""
|
| 521 |
+
try:
|
| 522 |
+
language, encoding = localetuple
|
| 523 |
+
|
| 524 |
+
if language is None:
|
| 525 |
+
language = 'C'
|
| 526 |
+
if encoding is None:
|
| 527 |
+
return language
|
| 528 |
+
else:
|
| 529 |
+
return language + '.' + encoding
|
| 530 |
+
except (TypeError, ValueError):
|
| 531 |
+
raise TypeError('Locale must be None, a string, or an iterable of '
|
| 532 |
+
'two strings -- language code, encoding.') from None
|
| 533 |
+
|
| 534 |
+
def getdefaultlocale(envvars=('LC_ALL', 'LC_CTYPE', 'LANG', 'LANGUAGE')):
|
| 535 |
+
|
| 536 |
+
""" Tries to determine the default locale settings and returns
|
| 537 |
+
them as tuple (language code, encoding).
|
| 538 |
+
|
| 539 |
+
According to POSIX, a program which has not called
|
| 540 |
+
setlocale(LC_ALL, "") runs using the portable 'C' locale.
|
| 541 |
+
Calling setlocale(LC_ALL, "") lets it use the default locale as
|
| 542 |
+
defined by the LANG variable. Since we don't want to interfere
|
| 543 |
+
with the current locale setting we thus emulate the behavior
|
| 544 |
+
in the way described above.
|
| 545 |
+
|
| 546 |
+
To maintain compatibility with other platforms, not only the
|
| 547 |
+
LANG variable is tested, but a list of variables given as
|
| 548 |
+
envvars parameter. The first found to be defined will be
|
| 549 |
+
used. envvars defaults to the search path used in GNU gettext;
|
| 550 |
+
it must always contain the variable name 'LANG'.
|
| 551 |
+
|
| 552 |
+
Except for the code 'C', the language code corresponds to RFC
|
| 553 |
+
1766. code and encoding can be None in case the values cannot
|
| 554 |
+
be determined.
|
| 555 |
+
|
| 556 |
+
"""
|
| 557 |
+
|
| 558 |
+
try:
|
| 559 |
+
# check if it's supported by the _locale module
|
| 560 |
+
import _locale
|
| 561 |
+
code, encoding = _locale._getdefaultlocale()
|
| 562 |
+
except (ImportError, AttributeError):
|
| 563 |
+
pass
|
| 564 |
+
else:
|
| 565 |
+
# make sure the code/encoding values are valid
|
| 566 |
+
if sys.platform == "win32" and code and code[:2] == "0x":
|
| 567 |
+
# map windows language identifier to language name
|
| 568 |
+
code = windows_locale.get(int(code, 0))
|
| 569 |
+
# ...add other platform-specific processing here, if
|
| 570 |
+
# necessary...
|
| 571 |
+
return code, encoding
|
| 572 |
+
|
| 573 |
+
# fall back on POSIX behaviour
|
| 574 |
+
import os
|
| 575 |
+
lookup = os.environ.get
|
| 576 |
+
for variable in envvars:
|
| 577 |
+
localename = lookup(variable,None)
|
| 578 |
+
if localename:
|
| 579 |
+
if variable == 'LANGUAGE':
|
| 580 |
+
localename = localename.split(':')[0]
|
| 581 |
+
break
|
| 582 |
+
else:
|
| 583 |
+
localename = 'C'
|
| 584 |
+
return _parse_localename(localename)
|
| 585 |
+
|
| 586 |
+
|
| 587 |
+
def getlocale(category=LC_CTYPE):
|
| 588 |
+
|
| 589 |
+
""" Returns the current setting for the given locale category as
|
| 590 |
+
tuple (language code, encoding).
|
| 591 |
+
|
| 592 |
+
category may be one of the LC_* value except LC_ALL. It
|
| 593 |
+
defaults to LC_CTYPE.
|
| 594 |
+
|
| 595 |
+
Except for the code 'C', the language code corresponds to RFC
|
| 596 |
+
1766. code and encoding can be None in case the values cannot
|
| 597 |
+
be determined.
|
| 598 |
+
|
| 599 |
+
"""
|
| 600 |
+
localename = _setlocale(category)
|
| 601 |
+
if category == LC_ALL and ';' in localename:
|
| 602 |
+
raise TypeError('category LC_ALL is not supported')
|
| 603 |
+
return _parse_localename(localename)
|
| 604 |
+
|
| 605 |
+
def setlocale(category, locale=None):
|
| 606 |
+
|
| 607 |
+
""" Set the locale for the given category. The locale can be
|
| 608 |
+
a string, an iterable of two strings (language code and encoding),
|
| 609 |
+
or None.
|
| 610 |
+
|
| 611 |
+
Iterables are converted to strings using the locale aliasing
|
| 612 |
+
engine. Locale strings are passed directly to the C lib.
|
| 613 |
+
|
| 614 |
+
category may be given as one of the LC_* values.
|
| 615 |
+
|
| 616 |
+
"""
|
| 617 |
+
if locale and not isinstance(locale, _builtin_str):
|
| 618 |
+
# convert to string
|
| 619 |
+
locale = normalize(_build_localename(locale))
|
| 620 |
+
return _setlocale(category, locale)
|
| 621 |
+
|
| 622 |
+
def resetlocale(category=LC_ALL):
|
| 623 |
+
|
| 624 |
+
""" Sets the locale for category to the default setting.
|
| 625 |
+
|
| 626 |
+
The default setting is determined by calling
|
| 627 |
+
getdefaultlocale(). category defaults to LC_ALL.
|
| 628 |
+
|
| 629 |
+
"""
|
| 630 |
+
_setlocale(category, _build_localename(getdefaultlocale()))
|
| 631 |
+
|
| 632 |
+
|
| 633 |
+
try:
|
| 634 |
+
from _locale import _get_locale_encoding
|
| 635 |
+
except ImportError:
|
| 636 |
+
def _get_locale_encoding():
|
| 637 |
+
if hasattr(sys, 'getandroidapilevel'):
|
| 638 |
+
# On Android langinfo.h and CODESET are missing, and UTF-8 is
|
| 639 |
+
# always used in mbstowcs() and wcstombs().
|
| 640 |
+
return 'UTF-8'
|
| 641 |
+
if sys.flags.utf8_mode:
|
| 642 |
+
return 'UTF-8'
|
| 643 |
+
encoding = getdefaultlocale()[1]
|
| 644 |
+
if encoding is None:
|
| 645 |
+
# LANG not set, default conservatively to ASCII
|
| 646 |
+
encoding = 'ascii'
|
| 647 |
+
return encoding
|
| 648 |
+
|
| 649 |
+
try:
|
| 650 |
+
CODESET
|
| 651 |
+
except NameError:
|
| 652 |
+
def getpreferredencoding(do_setlocale=True):
|
| 653 |
+
"""Return the charset that the user is likely using."""
|
| 654 |
+
return _get_locale_encoding()
|
| 655 |
+
else:
|
| 656 |
+
# On Unix, if CODESET is available, use that.
|
| 657 |
+
def getpreferredencoding(do_setlocale=True):
|
| 658 |
+
"""Return the charset that the user is likely using,
|
| 659 |
+
according to the system configuration."""
|
| 660 |
+
if sys.flags.utf8_mode:
|
| 661 |
+
return 'UTF-8'
|
| 662 |
+
|
| 663 |
+
if not do_setlocale:
|
| 664 |
+
return _get_locale_encoding()
|
| 665 |
+
|
| 666 |
+
old_loc = setlocale(LC_CTYPE)
|
| 667 |
+
try:
|
| 668 |
+
try:
|
| 669 |
+
setlocale(LC_CTYPE, "")
|
| 670 |
+
except Error:
|
| 671 |
+
pass
|
| 672 |
+
return _get_locale_encoding()
|
| 673 |
+
finally:
|
| 674 |
+
setlocale(LC_CTYPE, old_loc)
|
| 675 |
+
|
| 676 |
+
|
| 677 |
+
### Database
|
| 678 |
+
#
|
| 679 |
+
# The following data was extracted from the locale.alias file which
|
| 680 |
+
# comes with X11 and then hand edited removing the explicit encoding
|
| 681 |
+
# definitions and adding some more aliases. The file is usually
|
| 682 |
+
# available as /usr/lib/X11/locale/locale.alias.
|
| 683 |
+
#
|
| 684 |
+
|
| 685 |
+
#
|
| 686 |
+
# The local_encoding_alias table maps lowercase encoding alias names
|
| 687 |
+
# to C locale encoding names (case-sensitive). Note that normalize()
|
| 688 |
+
# first looks up the encoding in the encodings.aliases dictionary and
|
| 689 |
+
# then applies this mapping to find the correct C lib name for the
|
| 690 |
+
# encoding.
|
| 691 |
+
#
|
| 692 |
+
locale_encoding_alias = {
|
| 693 |
+
|
| 694 |
+
# Mappings for non-standard encoding names used in locale names
|
| 695 |
+
'437': 'C',
|
| 696 |
+
'c': 'C',
|
| 697 |
+
'en': 'ISO8859-1',
|
| 698 |
+
'jis': 'JIS7',
|
| 699 |
+
'jis7': 'JIS7',
|
| 700 |
+
'ajec': 'eucJP',
|
| 701 |
+
'koi8c': 'KOI8-C',
|
| 702 |
+
'microsoftcp1251': 'CP1251',
|
| 703 |
+
'microsoftcp1255': 'CP1255',
|
| 704 |
+
'microsoftcp1256': 'CP1256',
|
| 705 |
+
'88591': 'ISO8859-1',
|
| 706 |
+
'88592': 'ISO8859-2',
|
| 707 |
+
'88595': 'ISO8859-5',
|
| 708 |
+
'885915': 'ISO8859-15',
|
| 709 |
+
|
| 710 |
+
# Mappings from Python codec names to C lib encoding names
|
| 711 |
+
'ascii': 'ISO8859-1',
|
| 712 |
+
'latin_1': 'ISO8859-1',
|
| 713 |
+
'iso8859_1': 'ISO8859-1',
|
| 714 |
+
'iso8859_10': 'ISO8859-10',
|
| 715 |
+
'iso8859_11': 'ISO8859-11',
|
| 716 |
+
'iso8859_13': 'ISO8859-13',
|
| 717 |
+
'iso8859_14': 'ISO8859-14',
|
| 718 |
+
'iso8859_15': 'ISO8859-15',
|
| 719 |
+
'iso8859_16': 'ISO8859-16',
|
| 720 |
+
'iso8859_2': 'ISO8859-2',
|
| 721 |
+
'iso8859_3': 'ISO8859-3',
|
| 722 |
+
'iso8859_4': 'ISO8859-4',
|
| 723 |
+
'iso8859_5': 'ISO8859-5',
|
| 724 |
+
'iso8859_6': 'ISO8859-6',
|
| 725 |
+
'iso8859_7': 'ISO8859-7',
|
| 726 |
+
'iso8859_8': 'ISO8859-8',
|
| 727 |
+
'iso8859_9': 'ISO8859-9',
|
| 728 |
+
'iso2022_jp': 'JIS7',
|
| 729 |
+
'shift_jis': 'SJIS',
|
| 730 |
+
'tactis': 'TACTIS',
|
| 731 |
+
'euc_jp': 'eucJP',
|
| 732 |
+
'euc_kr': 'eucKR',
|
| 733 |
+
'utf_8': 'UTF-8',
|
| 734 |
+
'koi8_r': 'KOI8-R',
|
| 735 |
+
'koi8_t': 'KOI8-T',
|
| 736 |
+
'koi8_u': 'KOI8-U',
|
| 737 |
+
'kz1048': 'RK1048',
|
| 738 |
+
'cp1251': 'CP1251',
|
| 739 |
+
'cp1255': 'CP1255',
|
| 740 |
+
'cp1256': 'CP1256',
|
| 741 |
+
|
| 742 |
+
# XXX This list is still incomplete. If you know more
|
| 743 |
+
# mappings, please file a bug report. Thanks.
|
| 744 |
+
}
|
| 745 |
+
|
| 746 |
+
for k, v in sorted(locale_encoding_alias.items()):
|
| 747 |
+
k = k.replace('_', '')
|
| 748 |
+
locale_encoding_alias.setdefault(k, v)
|
| 749 |
+
|
| 750 |
+
#
|
| 751 |
+
# The locale_alias table maps lowercase alias names to C locale names
|
| 752 |
+
# (case-sensitive). Encodings are always separated from the locale
|
| 753 |
+
# name using a dot ('.'); they should only be given in case the
|
| 754 |
+
# language name is needed to interpret the given encoding alias
|
| 755 |
+
# correctly (CJK codes often have this need).
|
| 756 |
+
#
|
| 757 |
+
# Note that the normalize() function which uses this tables
|
| 758 |
+
# removes '_' and '-' characters from the encoding part of the
|
| 759 |
+
# locale name before doing the lookup. This saves a lot of
|
| 760 |
+
# space in the table.
|
| 761 |
+
#
|
| 762 |
+
# MAL 2004-12-10:
|
| 763 |
+
# Updated alias mapping to most recent locale.alias file
|
| 764 |
+
# from X.org distribution using makelocalealias.py.
|
| 765 |
+
#
|
| 766 |
+
# These are the differences compared to the old mapping (Python 2.4
|
| 767 |
+
# and older):
|
| 768 |
+
#
|
| 769 |
+
# updated 'bg' -> 'bg_BG.ISO8859-5' to 'bg_BG.CP1251'
|
| 770 |
+
# updated 'bg_bg' -> 'bg_BG.ISO8859-5' to 'bg_BG.CP1251'
|
| 771 |
+
# updated 'bulgarian' -> 'bg_BG.ISO8859-5' to 'bg_BG.CP1251'
|
| 772 |
+
# updated 'cz' -> 'cz_CZ.ISO8859-2' to 'cs_CZ.ISO8859-2'
|
| 773 |
+
# updated 'cz_cz' -> 'cz_CZ.ISO8859-2' to 'cs_CZ.ISO8859-2'
|
| 774 |
+
# updated 'czech' -> 'cs_CS.ISO8859-2' to 'cs_CZ.ISO8859-2'
|
| 775 |
+
# updated 'dutch' -> 'nl_BE.ISO8859-1' to 'nl_NL.ISO8859-1'
|
| 776 |
+
# updated 'et' -> 'et_EE.ISO8859-4' to 'et_EE.ISO8859-15'
|
| 777 |
+
# updated 'et_ee' -> 'et_EE.ISO8859-4' to 'et_EE.ISO8859-15'
|
| 778 |
+
# updated 'fi' -> 'fi_FI.ISO8859-1' to 'fi_FI.ISO8859-15'
|
| 779 |
+
# updated 'fi_fi' -> 'fi_FI.ISO8859-1' to 'fi_FI.ISO8859-15'
|
| 780 |
+
# updated 'iw' -> 'iw_IL.ISO8859-8' to 'he_IL.ISO8859-8'
|
| 781 |
+
# updated 'iw_il' -> 'iw_IL.ISO8859-8' to 'he_IL.ISO8859-8'
|
| 782 |
+
# updated 'japanese' -> 'ja_JP.SJIS' to 'ja_JP.eucJP'
|
| 783 |
+
# updated 'lt' -> 'lt_LT.ISO8859-4' to 'lt_LT.ISO8859-13'
|
| 784 |
+
# updated 'lv' -> 'lv_LV.ISO8859-4' to 'lv_LV.ISO8859-13'
|
| 785 |
+
# updated 'sl' -> 'sl_CS.ISO8859-2' to 'sl_SI.ISO8859-2'
|
| 786 |
+
# updated 'slovene' -> 'sl_CS.ISO8859-2' to 'sl_SI.ISO8859-2'
|
| 787 |
+
# updated 'th_th' -> 'th_TH.TACTIS' to 'th_TH.ISO8859-11'
|
| 788 |
+
# updated 'zh_cn' -> 'zh_CN.eucCN' to 'zh_CN.gb2312'
|
| 789 |
+
# updated 'zh_cn.big5' -> 'zh_TW.eucTW' to 'zh_TW.big5'
|
| 790 |
+
# updated 'zh_tw' -> 'zh_TW.eucTW' to 'zh_TW.big5'
|
| 791 |
+
#
|
| 792 |
+
# MAL 2008-05-30:
|
| 793 |
+
# Updated alias mapping to most recent locale.alias file
|
| 794 |
+
# from X.org distribution using makelocalealias.py.
|
| 795 |
+
#
|
| 796 |
+
# These are the differences compared to the old mapping (Python 2.5
|
| 797 |
+
# and older):
|
| 798 |
+
#
|
| 799 |
+
# updated 'cs_cs.iso88592' -> 'cs_CZ.ISO8859-2' to 'cs_CS.ISO8859-2'
|
| 800 |
+
# updated 'serbocroatian' -> 'sh_YU.ISO8859-2' to 'sr_CS.ISO8859-2'
|
| 801 |
+
# updated 'sh' -> 'sh_YU.ISO8859-2' to 'sr_CS.ISO8859-2'
|
| 802 |
+
# updated 'sh_hr.iso88592' -> 'sh_HR.ISO8859-2' to 'hr_HR.ISO8859-2'
|
| 803 |
+
# updated 'sh_sp' -> 'sh_YU.ISO8859-2' to 'sr_CS.ISO8859-2'
|
| 804 |
+
# updated 'sh_yu' -> 'sh_YU.ISO8859-2' to 'sr_CS.ISO8859-2'
|
| 805 |
+
# updated 'sp' -> 'sp_YU.ISO8859-5' to 'sr_CS.ISO8859-5'
|
| 806 |
+
# updated 'sp_yu' -> 'sp_YU.ISO8859-5' to 'sr_CS.ISO8859-5'
|
| 807 |
+
# updated 'sr' -> 'sr_YU.ISO8859-5' to 'sr_CS.ISO8859-5'
|
| 808 |
+
# updated 'sr@cyrillic' -> 'sr_YU.ISO8859-5' to 'sr_CS.ISO8859-5'
|
| 809 |
+
# updated 'sr_sp' -> 'sr_SP.ISO8859-2' to 'sr_CS.ISO8859-2'
|
| 810 |
+
# updated 'sr_yu' -> 'sr_YU.ISO8859-5' to 'sr_CS.ISO8859-5'
|
| 811 |
+
# updated 'sr_yu.cp1251@cyrillic' -> 'sr_YU.CP1251' to 'sr_CS.CP1251'
|
| 812 |
+
# updated 'sr_yu.iso88592' -> 'sr_YU.ISO8859-2' to 'sr_CS.ISO8859-2'
|
| 813 |
+
# updated 'sr_yu.iso88595' -> 'sr_YU.ISO8859-5' to 'sr_CS.ISO8859-5'
|
| 814 |
+
# updated 'sr_yu.iso88595@cyrillic' -> 'sr_YU.ISO8859-5' to 'sr_CS.ISO8859-5'
|
| 815 |
+
# updated 'sr_yu.microsoftcp1251@cyrillic' -> 'sr_YU.CP1251' to 'sr_CS.CP1251'
|
| 816 |
+
# updated 'sr_yu.utf8@cyrillic' -> 'sr_YU.UTF-8' to 'sr_CS.UTF-8'
|
| 817 |
+
# updated 'sr_yu@cyrillic' -> 'sr_YU.ISO8859-5' to 'sr_CS.ISO8859-5'
|
| 818 |
+
#
|
| 819 |
+
# AP 2010-04-12:
|
| 820 |
+
# Updated alias mapping to most recent locale.alias file
|
| 821 |
+
# from X.org distribution using makelocalealias.py.
|
| 822 |
+
#
|
| 823 |
+
# These are the differences compared to the old mapping (Python 2.6.5
|
| 824 |
+
# and older):
|
| 825 |
+
#
|
| 826 |
+
# updated 'ru' -> 'ru_RU.ISO8859-5' to 'ru_RU.UTF-8'
|
| 827 |
+
# updated 'ru_ru' -> 'ru_RU.ISO8859-5' to 'ru_RU.UTF-8'
|
| 828 |
+
# updated 'serbocroatian' -> 'sr_CS.ISO8859-2' to 'sr_RS.UTF-8@latin'
|
| 829 |
+
# updated 'sh' -> 'sr_CS.ISO8859-2' to 'sr_RS.UTF-8@latin'
|
| 830 |
+
# updated 'sh_yu' -> 'sr_CS.ISO8859-2' to 'sr_RS.UTF-8@latin'
|
| 831 |
+
# updated 'sr' -> 'sr_CS.ISO8859-5' to 'sr_RS.UTF-8'
|
| 832 |
+
# updated 'sr@cyrillic' -> 'sr_CS.ISO8859-5' to 'sr_RS.UTF-8'
|
| 833 |
+
# updated 'sr@latn' -> 'sr_CS.ISO8859-2' to 'sr_RS.UTF-8@latin'
|
| 834 |
+
# updated 'sr_cs.utf8@latn' -> 'sr_CS.UTF-8' to 'sr_RS.UTF-8@latin'
|
| 835 |
+
# updated 'sr_cs@latn' -> 'sr_CS.ISO8859-2' to 'sr_RS.UTF-8@latin'
|
| 836 |
+
# updated 'sr_yu' -> 'sr_CS.ISO8859-5' to 'sr_RS.UTF-8@latin'
|
| 837 |
+
# updated 'sr_yu.utf8@cyrillic' -> 'sr_CS.UTF-8' to 'sr_RS.UTF-8'
|
| 838 |
+
# updated 'sr_yu@cyrillic' -> 'sr_CS.ISO8859-5' to 'sr_RS.UTF-8'
|
| 839 |
+
#
|
| 840 |
+
# SS 2013-12-20:
|
| 841 |
+
# Updated alias mapping to most recent locale.alias file
|
| 842 |
+
# from X.org distribution using makelocalealias.py.
|
| 843 |
+
#
|
| 844 |
+
# These are the differences compared to the old mapping (Python 3.3.3
|
| 845 |
+
# and older):
|
| 846 |
+
#
|
| 847 |
+
# updated 'a3' -> 'a3_AZ.KOI8-C' to 'az_AZ.KOI8-C'
|
| 848 |
+
# updated 'a3_az' -> 'a3_AZ.KOI8-C' to 'az_AZ.KOI8-C'
|
| 849 |
+
# updated 'a3_az.koi8c' -> 'a3_AZ.KOI8-C' to 'az_AZ.KOI8-C'
|
| 850 |
+
# updated 'cs_cs.iso88592' -> 'cs_CS.ISO8859-2' to 'cs_CZ.ISO8859-2'
|
| 851 |
+
# updated 'hebrew' -> 'iw_IL.ISO8859-8' to 'he_IL.ISO8859-8'
|
| 852 |
+
# updated 'hebrew.iso88598' -> 'iw_IL.ISO8859-8' to 'he_IL.ISO8859-8'
|
| 853 |
+
# updated 'sd' -> 'sd_IN@devanagari.UTF-8' to 'sd_IN.UTF-8'
|
| 854 |
+
# updated 'sr@latn' -> 'sr_RS.UTF-8@latin' to 'sr_CS.UTF-8@latin'
|
| 855 |
+
# updated 'sr_cs' -> 'sr_RS.UTF-8' to 'sr_CS.UTF-8'
|
| 856 |
+
# updated 'sr_cs.utf8@latn' -> 'sr_RS.UTF-8@latin' to 'sr_CS.UTF-8@latin'
|
| 857 |
+
# updated 'sr_cs@latn' -> 'sr_RS.UTF-8@latin' to 'sr_CS.UTF-8@latin'
|
| 858 |
+
#
|
| 859 |
+
# SS 2014-10-01:
|
| 860 |
+
# Updated alias mapping with glibc 2.19 supported locales.
|
| 861 |
+
#
|
| 862 |
+
# SS 2018-05-05:
|
| 863 |
+
# Updated alias mapping with glibc 2.27 supported locales.
|
| 864 |
+
#
|
| 865 |
+
# These are the differences compared to the old mapping (Python 3.6.5
|
| 866 |
+
# and older):
|
| 867 |
+
#
|
| 868 |
+
# updated 'ca_es@valencia' -> 'ca_ES.ISO8859-15@valencia' to 'ca_ES.UTF-8@valencia'
|
| 869 |
+
# updated 'kk_kz' -> 'kk_KZ.RK1048' to 'kk_KZ.ptcp154'
|
| 870 |
+
# updated 'russian' -> 'ru_RU.ISO8859-5' to 'ru_RU.KOI8-R'
|
| 871 |
+
|
| 872 |
+
locale_alias = {
|
| 873 |
+
'a3': 'az_AZ.KOI8-C',
|
| 874 |
+
'a3_az': 'az_AZ.KOI8-C',
|
| 875 |
+
'a3_az.koic': 'az_AZ.KOI8-C',
|
| 876 |
+
'aa_dj': 'aa_DJ.ISO8859-1',
|
| 877 |
+
'aa_er': 'aa_ER.UTF-8',
|
| 878 |
+
'aa_et': 'aa_ET.UTF-8',
|
| 879 |
+
'af': 'af_ZA.ISO8859-1',
|
| 880 |
+
'af_za': 'af_ZA.ISO8859-1',
|
| 881 |
+
'agr_pe': 'agr_PE.UTF-8',
|
| 882 |
+
'ak_gh': 'ak_GH.UTF-8',
|
| 883 |
+
'am': 'am_ET.UTF-8',
|
| 884 |
+
'am_et': 'am_ET.UTF-8',
|
| 885 |
+
'american': 'en_US.ISO8859-1',
|
| 886 |
+
'an_es': 'an_ES.ISO8859-15',
|
| 887 |
+
'anp_in': 'anp_IN.UTF-8',
|
| 888 |
+
'ar': 'ar_AA.ISO8859-6',
|
| 889 |
+
'ar_aa': 'ar_AA.ISO8859-6',
|
| 890 |
+
'ar_ae': 'ar_AE.ISO8859-6',
|
| 891 |
+
'ar_bh': 'ar_BH.ISO8859-6',
|
| 892 |
+
'ar_dz': 'ar_DZ.ISO8859-6',
|
| 893 |
+
'ar_eg': 'ar_EG.ISO8859-6',
|
| 894 |
+
'ar_in': 'ar_IN.UTF-8',
|
| 895 |
+
'ar_iq': 'ar_IQ.ISO8859-6',
|
| 896 |
+
'ar_jo': 'ar_JO.ISO8859-6',
|
| 897 |
+
'ar_kw': 'ar_KW.ISO8859-6',
|
| 898 |
+
'ar_lb': 'ar_LB.ISO8859-6',
|
| 899 |
+
'ar_ly': 'ar_LY.ISO8859-6',
|
| 900 |
+
'ar_ma': 'ar_MA.ISO8859-6',
|
| 901 |
+
'ar_om': 'ar_OM.ISO8859-6',
|
| 902 |
+
'ar_qa': 'ar_QA.ISO8859-6',
|
| 903 |
+
'ar_sa': 'ar_SA.ISO8859-6',
|
| 904 |
+
'ar_sd': 'ar_SD.ISO8859-6',
|
| 905 |
+
'ar_ss': 'ar_SS.UTF-8',
|
| 906 |
+
'ar_sy': 'ar_SY.ISO8859-6',
|
| 907 |
+
'ar_tn': 'ar_TN.ISO8859-6',
|
| 908 |
+
'ar_ye': 'ar_YE.ISO8859-6',
|
| 909 |
+
'arabic': 'ar_AA.ISO8859-6',
|
| 910 |
+
'as': 'as_IN.UTF-8',
|
| 911 |
+
'as_in': 'as_IN.UTF-8',
|
| 912 |
+
'ast_es': 'ast_ES.ISO8859-15',
|
| 913 |
+
'ayc_pe': 'ayc_PE.UTF-8',
|
| 914 |
+
'az': 'az_AZ.ISO8859-9E',
|
| 915 |
+
'az_az': 'az_AZ.ISO8859-9E',
|
| 916 |
+
'az_az.iso88599e': 'az_AZ.ISO8859-9E',
|
| 917 |
+
'az_ir': 'az_IR.UTF-8',
|
| 918 |
+
'be': 'be_BY.CP1251',
|
| 919 |
+
'be@latin': 'be_BY.UTF-8@latin',
|
| 920 |
+
'be_bg.utf8': 'bg_BG.UTF-8',
|
| 921 |
+
'be_by': 'be_BY.CP1251',
|
| 922 |
+
'be_by@latin': 'be_BY.UTF-8@latin',
|
| 923 |
+
'bem_zm': 'bem_ZM.UTF-8',
|
| 924 |
+
'ber_dz': 'ber_DZ.UTF-8',
|
| 925 |
+
'ber_ma': 'ber_MA.UTF-8',
|
| 926 |
+
'bg': 'bg_BG.CP1251',
|
| 927 |
+
'bg_bg': 'bg_BG.CP1251',
|
| 928 |
+
'bhb_in.utf8': 'bhb_IN.UTF-8',
|
| 929 |
+
'bho_in': 'bho_IN.UTF-8',
|
| 930 |
+
'bho_np': 'bho_NP.UTF-8',
|
| 931 |
+
'bi_vu': 'bi_VU.UTF-8',
|
| 932 |
+
'bn_bd': 'bn_BD.UTF-8',
|
| 933 |
+
'bn_in': 'bn_IN.UTF-8',
|
| 934 |
+
'bo_cn': 'bo_CN.UTF-8',
|
| 935 |
+
'bo_in': 'bo_IN.UTF-8',
|
| 936 |
+
'bokmal': 'nb_NO.ISO8859-1',
|
| 937 |
+
'bokm\xe5l': 'nb_NO.ISO8859-1',
|
| 938 |
+
'br': 'br_FR.ISO8859-1',
|
| 939 |
+
'br_fr': 'br_FR.ISO8859-1',
|
| 940 |
+
'brx_in': 'brx_IN.UTF-8',
|
| 941 |
+
'bs': 'bs_BA.ISO8859-2',
|
| 942 |
+
'bs_ba': 'bs_BA.ISO8859-2',
|
| 943 |
+
'bulgarian': 'bg_BG.CP1251',
|
| 944 |
+
'byn_er': 'byn_ER.UTF-8',
|
| 945 |
+
'c': 'C',
|
| 946 |
+
'c-french': 'fr_CA.ISO8859-1',
|
| 947 |
+
'c.ascii': 'C',
|
| 948 |
+
'c.en': 'C',
|
| 949 |
+
'c.iso88591': 'en_US.ISO8859-1',
|
| 950 |
+
'c.utf8': 'en_US.UTF-8',
|
| 951 |
+
'c_c': 'C',
|
| 952 |
+
'c_c.c': 'C',
|
| 953 |
+
'ca': 'ca_ES.ISO8859-1',
|
| 954 |
+
'ca_ad': 'ca_AD.ISO8859-1',
|
| 955 |
+
'ca_es': 'ca_ES.ISO8859-1',
|
| 956 |
+
'ca_es@valencia': 'ca_ES.UTF-8@valencia',
|
| 957 |
+
'ca_fr': 'ca_FR.ISO8859-1',
|
| 958 |
+
'ca_it': 'ca_IT.ISO8859-1',
|
| 959 |
+
'catalan': 'ca_ES.ISO8859-1',
|
| 960 |
+
'ce_ru': 'ce_RU.UTF-8',
|
| 961 |
+
'cextend': 'en_US.ISO8859-1',
|
| 962 |
+
'chinese-s': 'zh_CN.eucCN',
|
| 963 |
+
'chinese-t': 'zh_TW.eucTW',
|
| 964 |
+
'chr_us': 'chr_US.UTF-8',
|
| 965 |
+
'ckb_iq': 'ckb_IQ.UTF-8',
|
| 966 |
+
'cmn_tw': 'cmn_TW.UTF-8',
|
| 967 |
+
'crh_ua': 'crh_UA.UTF-8',
|
| 968 |
+
'croatian': 'hr_HR.ISO8859-2',
|
| 969 |
+
'cs': 'cs_CZ.ISO8859-2',
|
| 970 |
+
'cs_cs': 'cs_CZ.ISO8859-2',
|
| 971 |
+
'cs_cz': 'cs_CZ.ISO8859-2',
|
| 972 |
+
'csb_pl': 'csb_PL.UTF-8',
|
| 973 |
+
'cv_ru': 'cv_RU.UTF-8',
|
| 974 |
+
'cy': 'cy_GB.ISO8859-1',
|
| 975 |
+
'cy_gb': 'cy_GB.ISO8859-1',
|
| 976 |
+
'cz': 'cs_CZ.ISO8859-2',
|
| 977 |
+
'cz_cz': 'cs_CZ.ISO8859-2',
|
| 978 |
+
'czech': 'cs_CZ.ISO8859-2',
|
| 979 |
+
'da': 'da_DK.ISO8859-1',
|
| 980 |
+
'da_dk': 'da_DK.ISO8859-1',
|
| 981 |
+
'danish': 'da_DK.ISO8859-1',
|
| 982 |
+
'dansk': 'da_DK.ISO8859-1',
|
| 983 |
+
'de': 'de_DE.ISO8859-1',
|
| 984 |
+
'de_at': 'de_AT.ISO8859-1',
|
| 985 |
+
'de_be': 'de_BE.ISO8859-1',
|
| 986 |
+
'de_ch': 'de_CH.ISO8859-1',
|
| 987 |
+
'de_de': 'de_DE.ISO8859-1',
|
| 988 |
+
'de_it': 'de_IT.ISO8859-1',
|
| 989 |
+
'de_li.utf8': 'de_LI.UTF-8',
|
| 990 |
+
'de_lu': 'de_LU.ISO8859-1',
|
| 991 |
+
'deutsch': 'de_DE.ISO8859-1',
|
| 992 |
+
'doi_in': 'doi_IN.UTF-8',
|
| 993 |
+
'dutch': 'nl_NL.ISO8859-1',
|
| 994 |
+
'dutch.iso88591': 'nl_BE.ISO8859-1',
|
| 995 |
+
'dv_mv': 'dv_MV.UTF-8',
|
| 996 |
+
'dz_bt': 'dz_BT.UTF-8',
|
| 997 |
+
'ee': 'ee_EE.ISO8859-4',
|
| 998 |
+
'ee_ee': 'ee_EE.ISO8859-4',
|
| 999 |
+
'eesti': 'et_EE.ISO8859-1',
|
| 1000 |
+
'el': 'el_GR.ISO8859-7',
|
| 1001 |
+
'el_cy': 'el_CY.ISO8859-7',
|
| 1002 |
+
'el_gr': 'el_GR.ISO8859-7',
|
| 1003 |
+
'el_gr@euro': 'el_GR.ISO8859-15',
|
| 1004 |
+
'en': 'en_US.ISO8859-1',
|
| 1005 |
+
'en_ag': 'en_AG.UTF-8',
|
| 1006 |
+
'en_au': 'en_AU.ISO8859-1',
|
| 1007 |
+
'en_be': 'en_BE.ISO8859-1',
|
| 1008 |
+
'en_bw': 'en_BW.ISO8859-1',
|
| 1009 |
+
'en_ca': 'en_CA.ISO8859-1',
|
| 1010 |
+
'en_dk': 'en_DK.ISO8859-1',
|
| 1011 |
+
'en_dl.utf8': 'en_DL.UTF-8',
|
| 1012 |
+
'en_gb': 'en_GB.ISO8859-1',
|
| 1013 |
+
'en_hk': 'en_HK.ISO8859-1',
|
| 1014 |
+
'en_ie': 'en_IE.ISO8859-1',
|
| 1015 |
+
'en_il': 'en_IL.UTF-8',
|
| 1016 |
+
'en_in': 'en_IN.ISO8859-1',
|
| 1017 |
+
'en_ng': 'en_NG.UTF-8',
|
| 1018 |
+
'en_nz': 'en_NZ.ISO8859-1',
|
| 1019 |
+
'en_ph': 'en_PH.ISO8859-1',
|
| 1020 |
+
'en_sc.utf8': 'en_SC.UTF-8',
|
| 1021 |
+
'en_sg': 'en_SG.ISO8859-1',
|
| 1022 |
+
'en_uk': 'en_GB.ISO8859-1',
|
| 1023 |
+
'en_us': 'en_US.ISO8859-1',
|
| 1024 |
+
'en_us@euro@euro': 'en_US.ISO8859-15',
|
| 1025 |
+
'en_za': 'en_ZA.ISO8859-1',
|
| 1026 |
+
'en_zm': 'en_ZM.UTF-8',
|
| 1027 |
+
'en_zw': 'en_ZW.ISO8859-1',
|
| 1028 |
+
'en_zw.utf8': 'en_ZS.UTF-8',
|
| 1029 |
+
'eng_gb': 'en_GB.ISO8859-1',
|
| 1030 |
+
'english': 'en_EN.ISO8859-1',
|
| 1031 |
+
'english.iso88591': 'en_US.ISO8859-1',
|
| 1032 |
+
'english_uk': 'en_GB.ISO8859-1',
|
| 1033 |
+
'english_united-states': 'en_US.ISO8859-1',
|
| 1034 |
+
'english_united-states.437': 'C',
|
| 1035 |
+
'english_us': 'en_US.ISO8859-1',
|
| 1036 |
+
'eo': 'eo_XX.ISO8859-3',
|
| 1037 |
+
'eo.utf8': 'eo.UTF-8',
|
| 1038 |
+
'eo_eo': 'eo_EO.ISO8859-3',
|
| 1039 |
+
'eo_us.utf8': 'eo_US.UTF-8',
|
| 1040 |
+
'eo_xx': 'eo_XX.ISO8859-3',
|
| 1041 |
+
'es': 'es_ES.ISO8859-1',
|
| 1042 |
+
'es_ar': 'es_AR.ISO8859-1',
|
| 1043 |
+
'es_bo': 'es_BO.ISO8859-1',
|
| 1044 |
+
'es_cl': 'es_CL.ISO8859-1',
|
| 1045 |
+
'es_co': 'es_CO.ISO8859-1',
|
| 1046 |
+
'es_cr': 'es_CR.ISO8859-1',
|
| 1047 |
+
'es_cu': 'es_CU.UTF-8',
|
| 1048 |
+
'es_do': 'es_DO.ISO8859-1',
|
| 1049 |
+
'es_ec': 'es_EC.ISO8859-1',
|
| 1050 |
+
'es_es': 'es_ES.ISO8859-1',
|
| 1051 |
+
'es_gt': 'es_GT.ISO8859-1',
|
| 1052 |
+
'es_hn': 'es_HN.ISO8859-1',
|
| 1053 |
+
'es_mx': 'es_MX.ISO8859-1',
|
| 1054 |
+
'es_ni': 'es_NI.ISO8859-1',
|
| 1055 |
+
'es_pa': 'es_PA.ISO8859-1',
|
| 1056 |
+
'es_pe': 'es_PE.ISO8859-1',
|
| 1057 |
+
'es_pr': 'es_PR.ISO8859-1',
|
| 1058 |
+
'es_py': 'es_PY.ISO8859-1',
|
| 1059 |
+
'es_sv': 'es_SV.ISO8859-1',
|
| 1060 |
+
'es_us': 'es_US.ISO8859-1',
|
| 1061 |
+
'es_uy': 'es_UY.ISO8859-1',
|
| 1062 |
+
'es_ve': 'es_VE.ISO8859-1',
|
| 1063 |
+
'estonian': 'et_EE.ISO8859-1',
|
| 1064 |
+
'et': 'et_EE.ISO8859-15',
|
| 1065 |
+
'et_ee': 'et_EE.ISO8859-15',
|
| 1066 |
+
'eu': 'eu_ES.ISO8859-1',
|
| 1067 |
+
'eu_es': 'eu_ES.ISO8859-1',
|
| 1068 |
+
'eu_fr': 'eu_FR.ISO8859-1',
|
| 1069 |
+
'fa': 'fa_IR.UTF-8',
|
| 1070 |
+
'fa_ir': 'fa_IR.UTF-8',
|
| 1071 |
+
'fa_ir.isiri3342': 'fa_IR.ISIRI-3342',
|
| 1072 |
+
'ff_sn': 'ff_SN.UTF-8',
|
| 1073 |
+
'fi': 'fi_FI.ISO8859-15',
|
| 1074 |
+
'fi_fi': 'fi_FI.ISO8859-15',
|
| 1075 |
+
'fil_ph': 'fil_PH.UTF-8',
|
| 1076 |
+
'finnish': 'fi_FI.ISO8859-1',
|
| 1077 |
+
'fo': 'fo_FO.ISO8859-1',
|
| 1078 |
+
'fo_fo': 'fo_FO.ISO8859-1',
|
| 1079 |
+
'fr': 'fr_FR.ISO8859-1',
|
| 1080 |
+
'fr_be': 'fr_BE.ISO8859-1',
|
| 1081 |
+
'fr_ca': 'fr_CA.ISO8859-1',
|
| 1082 |
+
'fr_ch': 'fr_CH.ISO8859-1',
|
| 1083 |
+
'fr_fr': 'fr_FR.ISO8859-1',
|
| 1084 |
+
'fr_lu': 'fr_LU.ISO8859-1',
|
| 1085 |
+
'fran\xe7ais': 'fr_FR.ISO8859-1',
|
| 1086 |
+
'fre_fr': 'fr_FR.ISO8859-1',
|
| 1087 |
+
'french': 'fr_FR.ISO8859-1',
|
| 1088 |
+
'french.iso88591': 'fr_CH.ISO8859-1',
|
| 1089 |
+
'french_france': 'fr_FR.ISO8859-1',
|
| 1090 |
+
'fur_it': 'fur_IT.UTF-8',
|
| 1091 |
+
'fy_de': 'fy_DE.UTF-8',
|
| 1092 |
+
'fy_nl': 'fy_NL.UTF-8',
|
| 1093 |
+
'ga': 'ga_IE.ISO8859-1',
|
| 1094 |
+
'ga_ie': 'ga_IE.ISO8859-1',
|
| 1095 |
+
'galego': 'gl_ES.ISO8859-1',
|
| 1096 |
+
'galician': 'gl_ES.ISO8859-1',
|
| 1097 |
+
'gd': 'gd_GB.ISO8859-1',
|
| 1098 |
+
'gd_gb': 'gd_GB.ISO8859-1',
|
| 1099 |
+
'ger_de': 'de_DE.ISO8859-1',
|
| 1100 |
+
'german': 'de_DE.ISO8859-1',
|
| 1101 |
+
'german.iso88591': 'de_CH.ISO8859-1',
|
| 1102 |
+
'german_germany': 'de_DE.ISO8859-1',
|
| 1103 |
+
'gez_er': 'gez_ER.UTF-8',
|
| 1104 |
+
'gez_et': 'gez_ET.UTF-8',
|
| 1105 |
+
'gl': 'gl_ES.ISO8859-1',
|
| 1106 |
+
'gl_es': 'gl_ES.ISO8859-1',
|
| 1107 |
+
'greek': 'el_GR.ISO8859-7',
|
| 1108 |
+
'gu_in': 'gu_IN.UTF-8',
|
| 1109 |
+
'gv': 'gv_GB.ISO8859-1',
|
| 1110 |
+
'gv_gb': 'gv_GB.ISO8859-1',
|
| 1111 |
+
'ha_ng': 'ha_NG.UTF-8',
|
| 1112 |
+
'hak_tw': 'hak_TW.UTF-8',
|
| 1113 |
+
'he': 'he_IL.ISO8859-8',
|
| 1114 |
+
'he_il': 'he_IL.ISO8859-8',
|
| 1115 |
+
'hebrew': 'he_IL.ISO8859-8',
|
| 1116 |
+
'hi': 'hi_IN.ISCII-DEV',
|
| 1117 |
+
'hi_in': 'hi_IN.ISCII-DEV',
|
| 1118 |
+
'hi_in.isciidev': 'hi_IN.ISCII-DEV',
|
| 1119 |
+
'hif_fj': 'hif_FJ.UTF-8',
|
| 1120 |
+
'hne': 'hne_IN.UTF-8',
|
| 1121 |
+
'hne_in': 'hne_IN.UTF-8',
|
| 1122 |
+
'hr': 'hr_HR.ISO8859-2',
|
| 1123 |
+
'hr_hr': 'hr_HR.ISO8859-2',
|
| 1124 |
+
'hrvatski': 'hr_HR.ISO8859-2',
|
| 1125 |
+
'hsb_de': 'hsb_DE.ISO8859-2',
|
| 1126 |
+
'ht_ht': 'ht_HT.UTF-8',
|
| 1127 |
+
'hu': 'hu_HU.ISO8859-2',
|
| 1128 |
+
'hu_hu': 'hu_HU.ISO8859-2',
|
| 1129 |
+
'hungarian': 'hu_HU.ISO8859-2',
|
| 1130 |
+
'hy_am': 'hy_AM.UTF-8',
|
| 1131 |
+
'hy_am.armscii8': 'hy_AM.ARMSCII_8',
|
| 1132 |
+
'ia': 'ia.UTF-8',
|
| 1133 |
+
'ia_fr': 'ia_FR.UTF-8',
|
| 1134 |
+
'icelandic': 'is_IS.ISO8859-1',
|
| 1135 |
+
'id': 'id_ID.ISO8859-1',
|
| 1136 |
+
'id_id': 'id_ID.ISO8859-1',
|
| 1137 |
+
'ig_ng': 'ig_NG.UTF-8',
|
| 1138 |
+
'ik_ca': 'ik_CA.UTF-8',
|
| 1139 |
+
'in': 'id_ID.ISO8859-1',
|
| 1140 |
+
'in_id': 'id_ID.ISO8859-1',
|
| 1141 |
+
'is': 'is_IS.ISO8859-1',
|
| 1142 |
+
'is_is': 'is_IS.ISO8859-1',
|
| 1143 |
+
'iso-8859-1': 'en_US.ISO8859-1',
|
| 1144 |
+
'iso-8859-15': 'en_US.ISO8859-15',
|
| 1145 |
+
'iso8859-1': 'en_US.ISO8859-1',
|
| 1146 |
+
'iso8859-15': 'en_US.ISO8859-15',
|
| 1147 |
+
'iso_8859_1': 'en_US.ISO8859-1',
|
| 1148 |
+
'iso_8859_15': 'en_US.ISO8859-15',
|
| 1149 |
+
'it': 'it_IT.ISO8859-1',
|
| 1150 |
+
'it_ch': 'it_CH.ISO8859-1',
|
| 1151 |
+
'it_it': 'it_IT.ISO8859-1',
|
| 1152 |
+
'italian': 'it_IT.ISO8859-1',
|
| 1153 |
+
'iu': 'iu_CA.NUNACOM-8',
|
| 1154 |
+
'iu_ca': 'iu_CA.NUNACOM-8',
|
| 1155 |
+
'iu_ca.nunacom8': 'iu_CA.NUNACOM-8',
|
| 1156 |
+
'iw': 'he_IL.ISO8859-8',
|
| 1157 |
+
'iw_il': 'he_IL.ISO8859-8',
|
| 1158 |
+
'iw_il.utf8': 'iw_IL.UTF-8',
|
| 1159 |
+
'ja': 'ja_JP.eucJP',
|
| 1160 |
+
'ja_jp': 'ja_JP.eucJP',
|
| 1161 |
+
'ja_jp.euc': 'ja_JP.eucJP',
|
| 1162 |
+
'ja_jp.mscode': 'ja_JP.SJIS',
|
| 1163 |
+
'ja_jp.pck': 'ja_JP.SJIS',
|
| 1164 |
+
'japan': 'ja_JP.eucJP',
|
| 1165 |
+
'japanese': 'ja_JP.eucJP',
|
| 1166 |
+
'japanese-euc': 'ja_JP.eucJP',
|
| 1167 |
+
'japanese.euc': 'ja_JP.eucJP',
|
| 1168 |
+
'jp_jp': 'ja_JP.eucJP',
|
| 1169 |
+
'ka': 'ka_GE.GEORGIAN-ACADEMY',
|
| 1170 |
+
'ka_ge': 'ka_GE.GEORGIAN-ACADEMY',
|
| 1171 |
+
'ka_ge.georgianacademy': 'ka_GE.GEORGIAN-ACADEMY',
|
| 1172 |
+
'ka_ge.georgianps': 'ka_GE.GEORGIAN-PS',
|
| 1173 |
+
'ka_ge.georgianrs': 'ka_GE.GEORGIAN-ACADEMY',
|
| 1174 |
+
'kab_dz': 'kab_DZ.UTF-8',
|
| 1175 |
+
'kk_kz': 'kk_KZ.ptcp154',
|
| 1176 |
+
'kl': 'kl_GL.ISO8859-1',
|
| 1177 |
+
'kl_gl': 'kl_GL.ISO8859-1',
|
| 1178 |
+
'km_kh': 'km_KH.UTF-8',
|
| 1179 |
+
'kn': 'kn_IN.UTF-8',
|
| 1180 |
+
'kn_in': 'kn_IN.UTF-8',
|
| 1181 |
+
'ko': 'ko_KR.eucKR',
|
| 1182 |
+
'ko_kr': 'ko_KR.eucKR',
|
| 1183 |
+
'ko_kr.euc': 'ko_KR.eucKR',
|
| 1184 |
+
'kok_in': 'kok_IN.UTF-8',
|
| 1185 |
+
'korean': 'ko_KR.eucKR',
|
| 1186 |
+
'korean.euc': 'ko_KR.eucKR',
|
| 1187 |
+
'ks': 'ks_IN.UTF-8',
|
| 1188 |
+
'ks_in': 'ks_IN.UTF-8',
|
| 1189 |
+
'ks_in@devanagari.utf8': 'ks_IN.UTF-8@devanagari',
|
| 1190 |
+
'ku_tr': 'ku_TR.ISO8859-9',
|
| 1191 |
+
'kw': 'kw_GB.ISO8859-1',
|
| 1192 |
+
'kw_gb': 'kw_GB.ISO8859-1',
|
| 1193 |
+
'ky': 'ky_KG.UTF-8',
|
| 1194 |
+
'ky_kg': 'ky_KG.UTF-8',
|
| 1195 |
+
'lb_lu': 'lb_LU.UTF-8',
|
| 1196 |
+
'lg_ug': 'lg_UG.ISO8859-10',
|
| 1197 |
+
'li_be': 'li_BE.UTF-8',
|
| 1198 |
+
'li_nl': 'li_NL.UTF-8',
|
| 1199 |
+
'lij_it': 'lij_IT.UTF-8',
|
| 1200 |
+
'lithuanian': 'lt_LT.ISO8859-13',
|
| 1201 |
+
'ln_cd': 'ln_CD.UTF-8',
|
| 1202 |
+
'lo': 'lo_LA.MULELAO-1',
|
| 1203 |
+
'lo_la': 'lo_LA.MULELAO-1',
|
| 1204 |
+
'lo_la.cp1133': 'lo_LA.IBM-CP1133',
|
| 1205 |
+
'lo_la.ibmcp1133': 'lo_LA.IBM-CP1133',
|
| 1206 |
+
'lo_la.mulelao1': 'lo_LA.MULELAO-1',
|
| 1207 |
+
'lt': 'lt_LT.ISO8859-13',
|
| 1208 |
+
'lt_lt': 'lt_LT.ISO8859-13',
|
| 1209 |
+
'lv': 'lv_LV.ISO8859-13',
|
| 1210 |
+
'lv_lv': 'lv_LV.ISO8859-13',
|
| 1211 |
+
'lzh_tw': 'lzh_TW.UTF-8',
|
| 1212 |
+
'mag_in': 'mag_IN.UTF-8',
|
| 1213 |
+
'mai': 'mai_IN.UTF-8',
|
| 1214 |
+
'mai_in': 'mai_IN.UTF-8',
|
| 1215 |
+
'mai_np': 'mai_NP.UTF-8',
|
| 1216 |
+
'mfe_mu': 'mfe_MU.UTF-8',
|
| 1217 |
+
'mg_mg': 'mg_MG.ISO8859-15',
|
| 1218 |
+
'mhr_ru': 'mhr_RU.UTF-8',
|
| 1219 |
+
'mi': 'mi_NZ.ISO8859-1',
|
| 1220 |
+
'mi_nz': 'mi_NZ.ISO8859-1',
|
| 1221 |
+
'miq_ni': 'miq_NI.UTF-8',
|
| 1222 |
+
'mjw_in': 'mjw_IN.UTF-8',
|
| 1223 |
+
'mk': 'mk_MK.ISO8859-5',
|
| 1224 |
+
'mk_mk': 'mk_MK.ISO8859-5',
|
| 1225 |
+
'ml': 'ml_IN.UTF-8',
|
| 1226 |
+
'ml_in': 'ml_IN.UTF-8',
|
| 1227 |
+
'mn_mn': 'mn_MN.UTF-8',
|
| 1228 |
+
'mni_in': 'mni_IN.UTF-8',
|
| 1229 |
+
'mr': 'mr_IN.UTF-8',
|
| 1230 |
+
'mr_in': 'mr_IN.UTF-8',
|
| 1231 |
+
'ms': 'ms_MY.ISO8859-1',
|
| 1232 |
+
'ms_my': 'ms_MY.ISO8859-1',
|
| 1233 |
+
'mt': 'mt_MT.ISO8859-3',
|
| 1234 |
+
'mt_mt': 'mt_MT.ISO8859-3',
|
| 1235 |
+
'my_mm': 'my_MM.UTF-8',
|
| 1236 |
+
'nan_tw': 'nan_TW.UTF-8',
|
| 1237 |
+
'nb': 'nb_NO.ISO8859-1',
|
| 1238 |
+
'nb_no': 'nb_NO.ISO8859-1',
|
| 1239 |
+
'nds_de': 'nds_DE.UTF-8',
|
| 1240 |
+
'nds_nl': 'nds_NL.UTF-8',
|
| 1241 |
+
'ne_np': 'ne_NP.UTF-8',
|
| 1242 |
+
'nhn_mx': 'nhn_MX.UTF-8',
|
| 1243 |
+
'niu_nu': 'niu_NU.UTF-8',
|
| 1244 |
+
'niu_nz': 'niu_NZ.UTF-8',
|
| 1245 |
+
'nl': 'nl_NL.ISO8859-1',
|
| 1246 |
+
'nl_aw': 'nl_AW.UTF-8',
|
| 1247 |
+
'nl_be': 'nl_BE.ISO8859-1',
|
| 1248 |
+
'nl_nl': 'nl_NL.ISO8859-1',
|
| 1249 |
+
'nn': 'nn_NO.ISO8859-1',
|
| 1250 |
+
'nn_no': 'nn_NO.ISO8859-1',
|
| 1251 |
+
'no': 'no_NO.ISO8859-1',
|
| 1252 |
+
'no@nynorsk': 'ny_NO.ISO8859-1',
|
| 1253 |
+
'no_no': 'no_NO.ISO8859-1',
|
| 1254 |
+
'no_no.iso88591@bokmal': 'no_NO.ISO8859-1',
|
| 1255 |
+
'no_no.iso88591@nynorsk': 'no_NO.ISO8859-1',
|
| 1256 |
+
'norwegian': 'no_NO.ISO8859-1',
|
| 1257 |
+
'nr': 'nr_ZA.ISO8859-1',
|
| 1258 |
+
'nr_za': 'nr_ZA.ISO8859-1',
|
| 1259 |
+
'nso': 'nso_ZA.ISO8859-15',
|
| 1260 |
+
'nso_za': 'nso_ZA.ISO8859-15',
|
| 1261 |
+
'ny': 'ny_NO.ISO8859-1',
|
| 1262 |
+
'ny_no': 'ny_NO.ISO8859-1',
|
| 1263 |
+
'nynorsk': 'nn_NO.ISO8859-1',
|
| 1264 |
+
'oc': 'oc_FR.ISO8859-1',
|
| 1265 |
+
'oc_fr': 'oc_FR.ISO8859-1',
|
| 1266 |
+
'om_et': 'om_ET.UTF-8',
|
| 1267 |
+
'om_ke': 'om_KE.ISO8859-1',
|
| 1268 |
+
'or': 'or_IN.UTF-8',
|
| 1269 |
+
'or_in': 'or_IN.UTF-8',
|
| 1270 |
+
'os_ru': 'os_RU.UTF-8',
|
| 1271 |
+
'pa': 'pa_IN.UTF-8',
|
| 1272 |
+
'pa_in': 'pa_IN.UTF-8',
|
| 1273 |
+
'pa_pk': 'pa_PK.UTF-8',
|
| 1274 |
+
'pap_an': 'pap_AN.UTF-8',
|
| 1275 |
+
'pap_aw': 'pap_AW.UTF-8',
|
| 1276 |
+
'pap_cw': 'pap_CW.UTF-8',
|
| 1277 |
+
'pd': 'pd_US.ISO8859-1',
|
| 1278 |
+
'pd_de': 'pd_DE.ISO8859-1',
|
| 1279 |
+
'pd_us': 'pd_US.ISO8859-1',
|
| 1280 |
+
'ph': 'ph_PH.ISO8859-1',
|
| 1281 |
+
'ph_ph': 'ph_PH.ISO8859-1',
|
| 1282 |
+
'pl': 'pl_PL.ISO8859-2',
|
| 1283 |
+
'pl_pl': 'pl_PL.ISO8859-2',
|
| 1284 |
+
'polish': 'pl_PL.ISO8859-2',
|
| 1285 |
+
'portuguese': 'pt_PT.ISO8859-1',
|
| 1286 |
+
'portuguese_brazil': 'pt_BR.ISO8859-1',
|
| 1287 |
+
'posix': 'C',
|
| 1288 |
+
'posix-utf2': 'C',
|
| 1289 |
+
'pp': 'pp_AN.ISO8859-1',
|
| 1290 |
+
'pp_an': 'pp_AN.ISO8859-1',
|
| 1291 |
+
'ps_af': 'ps_AF.UTF-8',
|
| 1292 |
+
'pt': 'pt_PT.ISO8859-1',
|
| 1293 |
+
'pt_br': 'pt_BR.ISO8859-1',
|
| 1294 |
+
'pt_pt': 'pt_PT.ISO8859-1',
|
| 1295 |
+
'quz_pe': 'quz_PE.UTF-8',
|
| 1296 |
+
'raj_in': 'raj_IN.UTF-8',
|
| 1297 |
+
'ro': 'ro_RO.ISO8859-2',
|
| 1298 |
+
'ro_ro': 'ro_RO.ISO8859-2',
|
| 1299 |
+
'romanian': 'ro_RO.ISO8859-2',
|
| 1300 |
+
'ru': 'ru_RU.UTF-8',
|
| 1301 |
+
'ru_ru': 'ru_RU.UTF-8',
|
| 1302 |
+
'ru_ua': 'ru_UA.KOI8-U',
|
| 1303 |
+
'rumanian': 'ro_RO.ISO8859-2',
|
| 1304 |
+
'russian': 'ru_RU.KOI8-R',
|
| 1305 |
+
'rw': 'rw_RW.ISO8859-1',
|
| 1306 |
+
'rw_rw': 'rw_RW.ISO8859-1',
|
| 1307 |
+
'sa_in': 'sa_IN.UTF-8',
|
| 1308 |
+
'sat_in': 'sat_IN.UTF-8',
|
| 1309 |
+
'sc_it': 'sc_IT.UTF-8',
|
| 1310 |
+
'sd': 'sd_IN.UTF-8',
|
| 1311 |
+
'sd_in': 'sd_IN.UTF-8',
|
| 1312 |
+
'sd_in@devanagari.utf8': 'sd_IN.UTF-8@devanagari',
|
| 1313 |
+
'sd_pk': 'sd_PK.UTF-8',
|
| 1314 |
+
'se_no': 'se_NO.UTF-8',
|
| 1315 |
+
'serbocroatian': 'sr_RS.UTF-8@latin',
|
| 1316 |
+
'sgs_lt': 'sgs_LT.UTF-8',
|
| 1317 |
+
'sh': 'sr_RS.UTF-8@latin',
|
| 1318 |
+
'sh_ba.iso88592@bosnia': 'sr_CS.ISO8859-2',
|
| 1319 |
+
'sh_hr': 'sh_HR.ISO8859-2',
|
| 1320 |
+
'sh_hr.iso88592': 'hr_HR.ISO8859-2',
|
| 1321 |
+
'sh_sp': 'sr_CS.ISO8859-2',
|
| 1322 |
+
'sh_yu': 'sr_RS.UTF-8@latin',
|
| 1323 |
+
'shn_mm': 'shn_MM.UTF-8',
|
| 1324 |
+
'shs_ca': 'shs_CA.UTF-8',
|
| 1325 |
+
'si': 'si_LK.UTF-8',
|
| 1326 |
+
'si_lk': 'si_LK.UTF-8',
|
| 1327 |
+
'sid_et': 'sid_ET.UTF-8',
|
| 1328 |
+
'sinhala': 'si_LK.UTF-8',
|
| 1329 |
+
'sk': 'sk_SK.ISO8859-2',
|
| 1330 |
+
'sk_sk': 'sk_SK.ISO8859-2',
|
| 1331 |
+
'sl': 'sl_SI.ISO8859-2',
|
| 1332 |
+
'sl_cs': 'sl_CS.ISO8859-2',
|
| 1333 |
+
'sl_si': 'sl_SI.ISO8859-2',
|
| 1334 |
+
'slovak': 'sk_SK.ISO8859-2',
|
| 1335 |
+
'slovene': 'sl_SI.ISO8859-2',
|
| 1336 |
+
'slovenian': 'sl_SI.ISO8859-2',
|
| 1337 |
+
'sm_ws': 'sm_WS.UTF-8',
|
| 1338 |
+
'so_dj': 'so_DJ.ISO8859-1',
|
| 1339 |
+
'so_et': 'so_ET.UTF-8',
|
| 1340 |
+
'so_ke': 'so_KE.ISO8859-1',
|
| 1341 |
+
'so_so': 'so_SO.ISO8859-1',
|
| 1342 |
+
'sp': 'sr_CS.ISO8859-5',
|
| 1343 |
+
'sp_yu': 'sr_CS.ISO8859-5',
|
| 1344 |
+
'spanish': 'es_ES.ISO8859-1',
|
| 1345 |
+
'spanish_spain': 'es_ES.ISO8859-1',
|
| 1346 |
+
'sq': 'sq_AL.ISO8859-2',
|
| 1347 |
+
'sq_al': 'sq_AL.ISO8859-2',
|
| 1348 |
+
'sq_mk': 'sq_MK.UTF-8',
|
| 1349 |
+
'sr': 'sr_RS.UTF-8',
|
| 1350 |
+
'sr@cyrillic': 'sr_RS.UTF-8',
|
| 1351 |
+
'sr@latn': 'sr_CS.UTF-8@latin',
|
| 1352 |
+
'sr_cs': 'sr_CS.UTF-8',
|
| 1353 |
+
'sr_cs.iso88592@latn': 'sr_CS.ISO8859-2',
|
| 1354 |
+
'sr_cs@latn': 'sr_CS.UTF-8@latin',
|
| 1355 |
+
'sr_me': 'sr_ME.UTF-8',
|
| 1356 |
+
'sr_rs': 'sr_RS.UTF-8',
|
| 1357 |
+
'sr_rs@latn': 'sr_RS.UTF-8@latin',
|
| 1358 |
+
'sr_sp': 'sr_CS.ISO8859-2',
|
| 1359 |
+
'sr_yu': 'sr_RS.UTF-8@latin',
|
| 1360 |
+
'sr_yu.cp1251@cyrillic': 'sr_CS.CP1251',
|
| 1361 |
+
'sr_yu.iso88592': 'sr_CS.ISO8859-2',
|
| 1362 |
+
'sr_yu.iso88595': 'sr_CS.ISO8859-5',
|
| 1363 |
+
'sr_yu.iso88595@cyrillic': 'sr_CS.ISO8859-5',
|
| 1364 |
+
'sr_yu.microsoftcp1251@cyrillic': 'sr_CS.CP1251',
|
| 1365 |
+
'sr_yu.utf8': 'sr_RS.UTF-8',
|
| 1366 |
+
'sr_yu.utf8@cyrillic': 'sr_RS.UTF-8',
|
| 1367 |
+
'sr_yu@cyrillic': 'sr_RS.UTF-8',
|
| 1368 |
+
'ss': 'ss_ZA.ISO8859-1',
|
| 1369 |
+
'ss_za': 'ss_ZA.ISO8859-1',
|
| 1370 |
+
'st': 'st_ZA.ISO8859-1',
|
| 1371 |
+
'st_za': 'st_ZA.ISO8859-1',
|
| 1372 |
+
'sv': 'sv_SE.ISO8859-1',
|
| 1373 |
+
'sv_fi': 'sv_FI.ISO8859-1',
|
| 1374 |
+
'sv_se': 'sv_SE.ISO8859-1',
|
| 1375 |
+
'sw_ke': 'sw_KE.UTF-8',
|
| 1376 |
+
'sw_tz': 'sw_TZ.UTF-8',
|
| 1377 |
+
'swedish': 'sv_SE.ISO8859-1',
|
| 1378 |
+
'szl_pl': 'szl_PL.UTF-8',
|
| 1379 |
+
'ta': 'ta_IN.TSCII-0',
|
| 1380 |
+
'ta_in': 'ta_IN.TSCII-0',
|
| 1381 |
+
'ta_in.tscii': 'ta_IN.TSCII-0',
|
| 1382 |
+
'ta_in.tscii0': 'ta_IN.TSCII-0',
|
| 1383 |
+
'ta_lk': 'ta_LK.UTF-8',
|
| 1384 |
+
'tcy_in.utf8': 'tcy_IN.UTF-8',
|
| 1385 |
+
'te': 'te_IN.UTF-8',
|
| 1386 |
+
'te_in': 'te_IN.UTF-8',
|
| 1387 |
+
'tg': 'tg_TJ.KOI8-C',
|
| 1388 |
+
'tg_tj': 'tg_TJ.KOI8-C',
|
| 1389 |
+
'th': 'th_TH.ISO8859-11',
|
| 1390 |
+
'th_th': 'th_TH.ISO8859-11',
|
| 1391 |
+
'th_th.tactis': 'th_TH.TIS620',
|
| 1392 |
+
'th_th.tis620': 'th_TH.TIS620',
|
| 1393 |
+
'thai': 'th_TH.ISO8859-11',
|
| 1394 |
+
'the_np': 'the_NP.UTF-8',
|
| 1395 |
+
'ti_er': 'ti_ER.UTF-8',
|
| 1396 |
+
'ti_et': 'ti_ET.UTF-8',
|
| 1397 |
+
'tig_er': 'tig_ER.UTF-8',
|
| 1398 |
+
'tk_tm': 'tk_TM.UTF-8',
|
| 1399 |
+
'tl': 'tl_PH.ISO8859-1',
|
| 1400 |
+
'tl_ph': 'tl_PH.ISO8859-1',
|
| 1401 |
+
'tn': 'tn_ZA.ISO8859-15',
|
| 1402 |
+
'tn_za': 'tn_ZA.ISO8859-15',
|
| 1403 |
+
'to_to': 'to_TO.UTF-8',
|
| 1404 |
+
'tpi_pg': 'tpi_PG.UTF-8',
|
| 1405 |
+
'tr': 'tr_TR.ISO8859-9',
|
| 1406 |
+
'tr_cy': 'tr_CY.ISO8859-9',
|
| 1407 |
+
'tr_tr': 'tr_TR.ISO8859-9',
|
| 1408 |
+
'ts': 'ts_ZA.ISO8859-1',
|
| 1409 |
+
'ts_za': 'ts_ZA.ISO8859-1',
|
| 1410 |
+
'tt': 'tt_RU.TATAR-CYR',
|
| 1411 |
+
'tt_ru': 'tt_RU.TATAR-CYR',
|
| 1412 |
+
'tt_ru.tatarcyr': 'tt_RU.TATAR-CYR',
|
| 1413 |
+
'tt_ru@iqtelif': 'tt_RU.UTF-8@iqtelif',
|
| 1414 |
+
'turkish': 'tr_TR.ISO8859-9',
|
| 1415 |
+
'ug_cn': 'ug_CN.UTF-8',
|
| 1416 |
+
'uk': 'uk_UA.KOI8-U',
|
| 1417 |
+
'uk_ua': 'uk_UA.KOI8-U',
|
| 1418 |
+
'univ': 'en_US.utf',
|
| 1419 |
+
'universal': 'en_US.utf',
|
| 1420 |
+
'universal.utf8@ucs4': 'en_US.UTF-8',
|
| 1421 |
+
'unm_us': 'unm_US.UTF-8',
|
| 1422 |
+
'ur': 'ur_PK.CP1256',
|
| 1423 |
+
'ur_in': 'ur_IN.UTF-8',
|
| 1424 |
+
'ur_pk': 'ur_PK.CP1256',
|
| 1425 |
+
'uz': 'uz_UZ.UTF-8',
|
| 1426 |
+
'uz_uz': 'uz_UZ.UTF-8',
|
| 1427 |
+
'uz_uz@cyrillic': 'uz_UZ.UTF-8',
|
| 1428 |
+
've': 've_ZA.UTF-8',
|
| 1429 |
+
've_za': 've_ZA.UTF-8',
|
| 1430 |
+
'vi': 'vi_VN.TCVN',
|
| 1431 |
+
'vi_vn': 'vi_VN.TCVN',
|
| 1432 |
+
'vi_vn.tcvn': 'vi_VN.TCVN',
|
| 1433 |
+
'vi_vn.tcvn5712': 'vi_VN.TCVN',
|
| 1434 |
+
'vi_vn.viscii': 'vi_VN.VISCII',
|
| 1435 |
+
'vi_vn.viscii111': 'vi_VN.VISCII',
|
| 1436 |
+
'wa': 'wa_BE.ISO8859-1',
|
| 1437 |
+
'wa_be': 'wa_BE.ISO8859-1',
|
| 1438 |
+
'wae_ch': 'wae_CH.UTF-8',
|
| 1439 |
+
'wal_et': 'wal_ET.UTF-8',
|
| 1440 |
+
'wo_sn': 'wo_SN.UTF-8',
|
| 1441 |
+
'xh': 'xh_ZA.ISO8859-1',
|
| 1442 |
+
'xh_za': 'xh_ZA.ISO8859-1',
|
| 1443 |
+
'yi': 'yi_US.CP1255',
|
| 1444 |
+
'yi_us': 'yi_US.CP1255',
|
| 1445 |
+
'yo_ng': 'yo_NG.UTF-8',
|
| 1446 |
+
'yue_hk': 'yue_HK.UTF-8',
|
| 1447 |
+
'yuw_pg': 'yuw_PG.UTF-8',
|
| 1448 |
+
'zh': 'zh_CN.eucCN',
|
| 1449 |
+
'zh_cn': 'zh_CN.gb2312',
|
| 1450 |
+
'zh_cn.big5': 'zh_TW.big5',
|
| 1451 |
+
'zh_cn.euc': 'zh_CN.eucCN',
|
| 1452 |
+
'zh_hk': 'zh_HK.big5hkscs',
|
| 1453 |
+
'zh_hk.big5hk': 'zh_HK.big5hkscs',
|
| 1454 |
+
'zh_sg': 'zh_SG.GB2312',
|
| 1455 |
+
'zh_sg.gbk': 'zh_SG.GBK',
|
| 1456 |
+
'zh_tw': 'zh_TW.big5',
|
| 1457 |
+
'zh_tw.euc': 'zh_TW.eucTW',
|
| 1458 |
+
'zh_tw.euctw': 'zh_TW.eucTW',
|
| 1459 |
+
'zu': 'zu_ZA.ISO8859-1',
|
| 1460 |
+
'zu_za': 'zu_ZA.ISO8859-1',
|
| 1461 |
+
}
|
| 1462 |
+
|
| 1463 |
+
#
|
| 1464 |
+
# This maps Windows language identifiers to locale strings.
|
| 1465 |
+
#
|
| 1466 |
+
# This list has been updated from
|
| 1467 |
+
# http://msdn.microsoft.com/library/default.asp?url=/library/en-us/intl/nls_238z.asp
|
| 1468 |
+
# to include every locale up to Windows Vista.
|
| 1469 |
+
#
|
| 1470 |
+
# NOTE: this mapping is incomplete. If your language is missing, please
|
| 1471 |
+
# submit a bug report to the Python bug tracker at http://bugs.python.org/
|
| 1472 |
+
# Make sure you include the missing language identifier and the suggested
|
| 1473 |
+
# locale code.
|
| 1474 |
+
#
|
| 1475 |
+
|
| 1476 |
+
windows_locale = {
|
| 1477 |
+
0x0436: "af_ZA", # Afrikaans
|
| 1478 |
+
0x041c: "sq_AL", # Albanian
|
| 1479 |
+
0x0484: "gsw_FR",# Alsatian - France
|
| 1480 |
+
0x045e: "am_ET", # Amharic - Ethiopia
|
| 1481 |
+
0x0401: "ar_SA", # Arabic - Saudi Arabia
|
| 1482 |
+
0x0801: "ar_IQ", # Arabic - Iraq
|
| 1483 |
+
0x0c01: "ar_EG", # Arabic - Egypt
|
| 1484 |
+
0x1001: "ar_LY", # Arabic - Libya
|
| 1485 |
+
0x1401: "ar_DZ", # Arabic - Algeria
|
| 1486 |
+
0x1801: "ar_MA", # Arabic - Morocco
|
| 1487 |
+
0x1c01: "ar_TN", # Arabic - Tunisia
|
| 1488 |
+
0x2001: "ar_OM", # Arabic - Oman
|
| 1489 |
+
0x2401: "ar_YE", # Arabic - Yemen
|
| 1490 |
+
0x2801: "ar_SY", # Arabic - Syria
|
| 1491 |
+
0x2c01: "ar_JO", # Arabic - Jordan
|
| 1492 |
+
0x3001: "ar_LB", # Arabic - Lebanon
|
| 1493 |
+
0x3401: "ar_KW", # Arabic - Kuwait
|
| 1494 |
+
0x3801: "ar_AE", # Arabic - United Arab Emirates
|
| 1495 |
+
0x3c01: "ar_BH", # Arabic - Bahrain
|
| 1496 |
+
0x4001: "ar_QA", # Arabic - Qatar
|
| 1497 |
+
0x042b: "hy_AM", # Armenian
|
| 1498 |
+
0x044d: "as_IN", # Assamese - India
|
| 1499 |
+
0x042c: "az_AZ", # Azeri - Latin
|
| 1500 |
+
0x082c: "az_AZ", # Azeri - Cyrillic
|
| 1501 |
+
0x046d: "ba_RU", # Bashkir
|
| 1502 |
+
0x042d: "eu_ES", # Basque - Russia
|
| 1503 |
+
0x0423: "be_BY", # Belarusian
|
| 1504 |
+
0x0445: "bn_IN", # Begali
|
| 1505 |
+
0x201a: "bs_BA", # Bosnian - Cyrillic
|
| 1506 |
+
0x141a: "bs_BA", # Bosnian - Latin
|
| 1507 |
+
0x047e: "br_FR", # Breton - France
|
| 1508 |
+
0x0402: "bg_BG", # Bulgarian
|
| 1509 |
+
# 0x0455: "my_MM", # Burmese - Not supported
|
| 1510 |
+
0x0403: "ca_ES", # Catalan
|
| 1511 |
+
0x0004: "zh_CHS",# Chinese - Simplified
|
| 1512 |
+
0x0404: "zh_TW", # Chinese - Taiwan
|
| 1513 |
+
0x0804: "zh_CN", # Chinese - PRC
|
| 1514 |
+
0x0c04: "zh_HK", # Chinese - Hong Kong S.A.R.
|
| 1515 |
+
0x1004: "zh_SG", # Chinese - Singapore
|
| 1516 |
+
0x1404: "zh_MO", # Chinese - Macao S.A.R.
|
| 1517 |
+
0x7c04: "zh_CHT",# Chinese - Traditional
|
| 1518 |
+
0x0483: "co_FR", # Corsican - France
|
| 1519 |
+
0x041a: "hr_HR", # Croatian
|
| 1520 |
+
0x101a: "hr_BA", # Croatian - Bosnia
|
| 1521 |
+
0x0405: "cs_CZ", # Czech
|
| 1522 |
+
0x0406: "da_DK", # Danish
|
| 1523 |
+
0x048c: "gbz_AF",# Dari - Afghanistan
|
| 1524 |
+
0x0465: "div_MV",# Divehi - Maldives
|
| 1525 |
+
0x0413: "nl_NL", # Dutch - The Netherlands
|
| 1526 |
+
0x0813: "nl_BE", # Dutch - Belgium
|
| 1527 |
+
0x0409: "en_US", # English - United States
|
| 1528 |
+
0x0809: "en_GB", # English - United Kingdom
|
| 1529 |
+
0x0c09: "en_AU", # English - Australia
|
| 1530 |
+
0x1009: "en_CA", # English - Canada
|
| 1531 |
+
0x1409: "en_NZ", # English - New Zealand
|
| 1532 |
+
0x1809: "en_IE", # English - Ireland
|
| 1533 |
+
0x1c09: "en_ZA", # English - South Africa
|
| 1534 |
+
0x2009: "en_JA", # English - Jamaica
|
| 1535 |
+
0x2409: "en_CB", # English - Caribbean
|
| 1536 |
+
0x2809: "en_BZ", # English - Belize
|
| 1537 |
+
0x2c09: "en_TT", # English - Trinidad
|
| 1538 |
+
0x3009: "en_ZW", # English - Zimbabwe
|
| 1539 |
+
0x3409: "en_PH", # English - Philippines
|
| 1540 |
+
0x4009: "en_IN", # English - India
|
| 1541 |
+
0x4409: "en_MY", # English - Malaysia
|
| 1542 |
+
0x4809: "en_IN", # English - Singapore
|
| 1543 |
+
0x0425: "et_EE", # Estonian
|
| 1544 |
+
0x0438: "fo_FO", # Faroese
|
| 1545 |
+
0x0464: "fil_PH",# Filipino
|
| 1546 |
+
0x040b: "fi_FI", # Finnish
|
| 1547 |
+
0x040c: "fr_FR", # French - France
|
| 1548 |
+
0x080c: "fr_BE", # French - Belgium
|
| 1549 |
+
0x0c0c: "fr_CA", # French - Canada
|
| 1550 |
+
0x100c: "fr_CH", # French - Switzerland
|
| 1551 |
+
0x140c: "fr_LU", # French - Luxembourg
|
| 1552 |
+
0x180c: "fr_MC", # French - Monaco
|
| 1553 |
+
0x0462: "fy_NL", # Frisian - Netherlands
|
| 1554 |
+
0x0456: "gl_ES", # Galician
|
| 1555 |
+
0x0437: "ka_GE", # Georgian
|
| 1556 |
+
0x0407: "de_DE", # German - Germany
|
| 1557 |
+
0x0807: "de_CH", # German - Switzerland
|
| 1558 |
+
0x0c07: "de_AT", # German - Austria
|
| 1559 |
+
0x1007: "de_LU", # German - Luxembourg
|
| 1560 |
+
0x1407: "de_LI", # German - Liechtenstein
|
| 1561 |
+
0x0408: "el_GR", # Greek
|
| 1562 |
+
0x046f: "kl_GL", # Greenlandic - Greenland
|
| 1563 |
+
0x0447: "gu_IN", # Gujarati
|
| 1564 |
+
0x0468: "ha_NG", # Hausa - Latin
|
| 1565 |
+
0x040d: "he_IL", # Hebrew
|
| 1566 |
+
0x0439: "hi_IN", # Hindi
|
| 1567 |
+
0x040e: "hu_HU", # Hungarian
|
| 1568 |
+
0x040f: "is_IS", # Icelandic
|
| 1569 |
+
0x0421: "id_ID", # Indonesian
|
| 1570 |
+
0x045d: "iu_CA", # Inuktitut - Syllabics
|
| 1571 |
+
0x085d: "iu_CA", # Inuktitut - Latin
|
| 1572 |
+
0x083c: "ga_IE", # Irish - Ireland
|
| 1573 |
+
0x0410: "it_IT", # Italian - Italy
|
| 1574 |
+
0x0810: "it_CH", # Italian - Switzerland
|
| 1575 |
+
0x0411: "ja_JP", # Japanese
|
| 1576 |
+
0x044b: "kn_IN", # Kannada - India
|
| 1577 |
+
0x043f: "kk_KZ", # Kazakh
|
| 1578 |
+
0x0453: "kh_KH", # Khmer - Cambodia
|
| 1579 |
+
0x0486: "qut_GT",# K'iche - Guatemala
|
| 1580 |
+
0x0487: "rw_RW", # Kinyarwanda - Rwanda
|
| 1581 |
+
0x0457: "kok_IN",# Konkani
|
| 1582 |
+
0x0412: "ko_KR", # Korean
|
| 1583 |
+
0x0440: "ky_KG", # Kyrgyz
|
| 1584 |
+
0x0454: "lo_LA", # Lao - Lao PDR
|
| 1585 |
+
0x0426: "lv_LV", # Latvian
|
| 1586 |
+
0x0427: "lt_LT", # Lithuanian
|
| 1587 |
+
0x082e: "dsb_DE",# Lower Sorbian - Germany
|
| 1588 |
+
0x046e: "lb_LU", # Luxembourgish
|
| 1589 |
+
0x042f: "mk_MK", # FYROM Macedonian
|
| 1590 |
+
0x043e: "ms_MY", # Malay - Malaysia
|
| 1591 |
+
0x083e: "ms_BN", # Malay - Brunei Darussalam
|
| 1592 |
+
0x044c: "ml_IN", # Malayalam - India
|
| 1593 |
+
0x043a: "mt_MT", # Maltese
|
| 1594 |
+
0x0481: "mi_NZ", # Maori
|
| 1595 |
+
0x047a: "arn_CL",# Mapudungun
|
| 1596 |
+
0x044e: "mr_IN", # Marathi
|
| 1597 |
+
0x047c: "moh_CA",# Mohawk - Canada
|
| 1598 |
+
0x0450: "mn_MN", # Mongolian - Cyrillic
|
| 1599 |
+
0x0850: "mn_CN", # Mongolian - PRC
|
| 1600 |
+
0x0461: "ne_NP", # Nepali
|
| 1601 |
+
0x0414: "nb_NO", # Norwegian - Bokmal
|
| 1602 |
+
0x0814: "nn_NO", # Norwegian - Nynorsk
|
| 1603 |
+
0x0482: "oc_FR", # Occitan - France
|
| 1604 |
+
0x0448: "or_IN", # Oriya - India
|
| 1605 |
+
0x0463: "ps_AF", # Pashto - Afghanistan
|
| 1606 |
+
0x0429: "fa_IR", # Persian
|
| 1607 |
+
0x0415: "pl_PL", # Polish
|
| 1608 |
+
0x0416: "pt_BR", # Portuguese - Brazil
|
| 1609 |
+
0x0816: "pt_PT", # Portuguese - Portugal
|
| 1610 |
+
0x0446: "pa_IN", # Punjabi
|
| 1611 |
+
0x046b: "quz_BO",# Quechua (Bolivia)
|
| 1612 |
+
0x086b: "quz_EC",# Quechua (Ecuador)
|
| 1613 |
+
0x0c6b: "quz_PE",# Quechua (Peru)
|
| 1614 |
+
0x0418: "ro_RO", # Romanian - Romania
|
| 1615 |
+
0x0417: "rm_CH", # Romansh
|
| 1616 |
+
0x0419: "ru_RU", # Russian
|
| 1617 |
+
0x243b: "smn_FI",# Sami Finland
|
| 1618 |
+
0x103b: "smj_NO",# Sami Norway
|
| 1619 |
+
0x143b: "smj_SE",# Sami Sweden
|
| 1620 |
+
0x043b: "se_NO", # Sami Northern Norway
|
| 1621 |
+
0x083b: "se_SE", # Sami Northern Sweden
|
| 1622 |
+
0x0c3b: "se_FI", # Sami Northern Finland
|
| 1623 |
+
0x203b: "sms_FI",# Sami Skolt
|
| 1624 |
+
0x183b: "sma_NO",# Sami Southern Norway
|
| 1625 |
+
0x1c3b: "sma_SE",# Sami Southern Sweden
|
| 1626 |
+
0x044f: "sa_IN", # Sanskrit
|
| 1627 |
+
0x0c1a: "sr_SP", # Serbian - Cyrillic
|
| 1628 |
+
0x1c1a: "sr_BA", # Serbian - Bosnia Cyrillic
|
| 1629 |
+
0x081a: "sr_SP", # Serbian - Latin
|
| 1630 |
+
0x181a: "sr_BA", # Serbian - Bosnia Latin
|
| 1631 |
+
0x045b: "si_LK", # Sinhala - Sri Lanka
|
| 1632 |
+
0x046c: "ns_ZA", # Northern Sotho
|
| 1633 |
+
0x0432: "tn_ZA", # Setswana - Southern Africa
|
| 1634 |
+
0x041b: "sk_SK", # Slovak
|
| 1635 |
+
0x0424: "sl_SI", # Slovenian
|
| 1636 |
+
0x040a: "es_ES", # Spanish - Spain
|
| 1637 |
+
0x080a: "es_MX", # Spanish - Mexico
|
| 1638 |
+
0x0c0a: "es_ES", # Spanish - Spain (Modern)
|
| 1639 |
+
0x100a: "es_GT", # Spanish - Guatemala
|
| 1640 |
+
0x140a: "es_CR", # Spanish - Costa Rica
|
| 1641 |
+
0x180a: "es_PA", # Spanish - Panama
|
| 1642 |
+
0x1c0a: "es_DO", # Spanish - Dominican Republic
|
| 1643 |
+
0x200a: "es_VE", # Spanish - Venezuela
|
| 1644 |
+
0x240a: "es_CO", # Spanish - Colombia
|
| 1645 |
+
0x280a: "es_PE", # Spanish - Peru
|
| 1646 |
+
0x2c0a: "es_AR", # Spanish - Argentina
|
| 1647 |
+
0x300a: "es_EC", # Spanish - Ecuador
|
| 1648 |
+
0x340a: "es_CL", # Spanish - Chile
|
| 1649 |
+
0x380a: "es_UR", # Spanish - Uruguay
|
| 1650 |
+
0x3c0a: "es_PY", # Spanish - Paraguay
|
| 1651 |
+
0x400a: "es_BO", # Spanish - Bolivia
|
| 1652 |
+
0x440a: "es_SV", # Spanish - El Salvador
|
| 1653 |
+
0x480a: "es_HN", # Spanish - Honduras
|
| 1654 |
+
0x4c0a: "es_NI", # Spanish - Nicaragua
|
| 1655 |
+
0x500a: "es_PR", # Spanish - Puerto Rico
|
| 1656 |
+
0x540a: "es_US", # Spanish - United States
|
| 1657 |
+
# 0x0430: "", # Sutu - Not supported
|
| 1658 |
+
0x0441: "sw_KE", # Swahili
|
| 1659 |
+
0x041d: "sv_SE", # Swedish - Sweden
|
| 1660 |
+
0x081d: "sv_FI", # Swedish - Finland
|
| 1661 |
+
0x045a: "syr_SY",# Syriac
|
| 1662 |
+
0x0428: "tg_TJ", # Tajik - Cyrillic
|
| 1663 |
+
0x085f: "tmz_DZ",# Tamazight - Latin
|
| 1664 |
+
0x0449: "ta_IN", # Tamil
|
| 1665 |
+
0x0444: "tt_RU", # Tatar
|
| 1666 |
+
0x044a: "te_IN", # Telugu
|
| 1667 |
+
0x041e: "th_TH", # Thai
|
| 1668 |
+
0x0851: "bo_BT", # Tibetan - Bhutan
|
| 1669 |
+
0x0451: "bo_CN", # Tibetan - PRC
|
| 1670 |
+
0x041f: "tr_TR", # Turkish
|
| 1671 |
+
0x0442: "tk_TM", # Turkmen - Cyrillic
|
| 1672 |
+
0x0480: "ug_CN", # Uighur - Arabic
|
| 1673 |
+
0x0422: "uk_UA", # Ukrainian
|
| 1674 |
+
0x042e: "wen_DE",# Upper Sorbian - Germany
|
| 1675 |
+
0x0420: "ur_PK", # Urdu
|
| 1676 |
+
0x0820: "ur_IN", # Urdu - India
|
| 1677 |
+
0x0443: "uz_UZ", # Uzbek - Latin
|
| 1678 |
+
0x0843: "uz_UZ", # Uzbek - Cyrillic
|
| 1679 |
+
0x042a: "vi_VN", # Vietnamese
|
| 1680 |
+
0x0452: "cy_GB", # Welsh
|
| 1681 |
+
0x0488: "wo_SN", # Wolof - Senegal
|
| 1682 |
+
0x0434: "xh_ZA", # Xhosa - South Africa
|
| 1683 |
+
0x0485: "sah_RU",# Yakut - Cyrillic
|
| 1684 |
+
0x0478: "ii_CN", # Yi - PRC
|
| 1685 |
+
0x046a: "yo_NG", # Yoruba - Nigeria
|
| 1686 |
+
0x0435: "zu_ZA", # Zulu
|
| 1687 |
+
}
|
| 1688 |
+
|
| 1689 |
+
def _print_locale():
|
| 1690 |
+
|
| 1691 |
+
""" Test function.
|
| 1692 |
+
"""
|
| 1693 |
+
categories = {}
|
| 1694 |
+
def _init_categories(categories=categories):
|
| 1695 |
+
for k,v in globals().items():
|
| 1696 |
+
if k[:3] == 'LC_':
|
| 1697 |
+
categories[k] = v
|
| 1698 |
+
_init_categories()
|
| 1699 |
+
del categories['LC_ALL']
|
| 1700 |
+
|
| 1701 |
+
print('Locale defaults as determined by getdefaultlocale():')
|
| 1702 |
+
print('-'*72)
|
| 1703 |
+
lang, enc = getdefaultlocale()
|
| 1704 |
+
print('Language: ', lang or '(undefined)')
|
| 1705 |
+
print('Encoding: ', enc or '(undefined)')
|
| 1706 |
+
print()
|
| 1707 |
+
|
| 1708 |
+
print('Locale settings on startup:')
|
| 1709 |
+
print('-'*72)
|
| 1710 |
+
for name,category in categories.items():
|
| 1711 |
+
print(name, '...')
|
| 1712 |
+
lang, enc = getlocale(category)
|
| 1713 |
+
print(' Language: ', lang or '(undefined)')
|
| 1714 |
+
print(' Encoding: ', enc or '(undefined)')
|
| 1715 |
+
print()
|
| 1716 |
+
|
| 1717 |
+
print()
|
| 1718 |
+
print('Locale settings after calling resetlocale():')
|
| 1719 |
+
print('-'*72)
|
| 1720 |
+
resetlocale()
|
| 1721 |
+
for name,category in categories.items():
|
| 1722 |
+
print(name, '...')
|
| 1723 |
+
lang, enc = getlocale(category)
|
| 1724 |
+
print(' Language: ', lang or '(undefined)')
|
| 1725 |
+
print(' Encoding: ', enc or '(undefined)')
|
| 1726 |
+
print()
|
| 1727 |
+
|
| 1728 |
+
try:
|
| 1729 |
+
setlocale(LC_ALL, "")
|
| 1730 |
+
except:
|
| 1731 |
+
print('NOTE:')
|
| 1732 |
+
print('setlocale(LC_ALL, "") does not support the default locale')
|
| 1733 |
+
print('given in the OS environment variables.')
|
| 1734 |
+
else:
|
| 1735 |
+
print()
|
| 1736 |
+
print('Locale settings after calling setlocale(LC_ALL, ""):')
|
| 1737 |
+
print('-'*72)
|
| 1738 |
+
for name,category in categories.items():
|
| 1739 |
+
print(name, '...')
|
| 1740 |
+
lang, enc = getlocale(category)
|
| 1741 |
+
print(' Language: ', lang or '(undefined)')
|
| 1742 |
+
print(' Encoding: ', enc or '(undefined)')
|
| 1743 |
+
print()
|
| 1744 |
+
|
| 1745 |
+
###
|
| 1746 |
+
|
| 1747 |
+
try:
|
| 1748 |
+
LC_MESSAGES
|
| 1749 |
+
except NameError:
|
| 1750 |
+
pass
|
| 1751 |
+
else:
|
| 1752 |
+
__all__.append("LC_MESSAGES")
|
| 1753 |
+
|
| 1754 |
+
if __name__=='__main__':
|
| 1755 |
+
print('Locale aliasing:')
|
| 1756 |
+
print()
|
| 1757 |
+
_print_locale()
|
| 1758 |
+
print()
|
| 1759 |
+
print('Number formatting:')
|
| 1760 |
+
print()
|
| 1761 |
+
_test()
|
llava/lib/python3.10/modulefinder.py
ADDED
|
@@ -0,0 +1,685 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Find modules used by a script, using introspection."""
|
| 2 |
+
|
| 3 |
+
import dis
|
| 4 |
+
import importlib._bootstrap_external
|
| 5 |
+
import importlib.machinery
|
| 6 |
+
import marshal
|
| 7 |
+
import os
|
| 8 |
+
import io
|
| 9 |
+
import sys
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
LOAD_CONST = dis.opmap['LOAD_CONST']
|
| 13 |
+
IMPORT_NAME = dis.opmap['IMPORT_NAME']
|
| 14 |
+
STORE_NAME = dis.opmap['STORE_NAME']
|
| 15 |
+
STORE_GLOBAL = dis.opmap['STORE_GLOBAL']
|
| 16 |
+
STORE_OPS = STORE_NAME, STORE_GLOBAL
|
| 17 |
+
EXTENDED_ARG = dis.EXTENDED_ARG
|
| 18 |
+
|
| 19 |
+
# Old imp constants:
|
| 20 |
+
|
| 21 |
+
_SEARCH_ERROR = 0
|
| 22 |
+
_PY_SOURCE = 1
|
| 23 |
+
_PY_COMPILED = 2
|
| 24 |
+
_C_EXTENSION = 3
|
| 25 |
+
_PKG_DIRECTORY = 5
|
| 26 |
+
_C_BUILTIN = 6
|
| 27 |
+
_PY_FROZEN = 7
|
| 28 |
+
|
| 29 |
+
# Modulefinder does a good job at simulating Python's, but it can not
|
| 30 |
+
# handle __path__ modifications packages make at runtime. Therefore there
|
| 31 |
+
# is a mechanism whereby you can register extra paths in this map for a
|
| 32 |
+
# package, and it will be honored.
|
| 33 |
+
|
| 34 |
+
# Note this is a mapping is lists of paths.
|
| 35 |
+
packagePathMap = {}
|
| 36 |
+
|
| 37 |
+
# A Public interface
|
| 38 |
+
def AddPackagePath(packagename, path):
|
| 39 |
+
packagePathMap.setdefault(packagename, []).append(path)
|
| 40 |
+
|
| 41 |
+
replacePackageMap = {}
|
| 42 |
+
|
| 43 |
+
# This ReplacePackage mechanism allows modulefinder to work around
|
| 44 |
+
# situations in which a package injects itself under the name
|
| 45 |
+
# of another package into sys.modules at runtime by calling
|
| 46 |
+
# ReplacePackage("real_package_name", "faked_package_name")
|
| 47 |
+
# before running ModuleFinder.
|
| 48 |
+
|
| 49 |
+
def ReplacePackage(oldname, newname):
|
| 50 |
+
replacePackageMap[oldname] = newname
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def _find_module(name, path=None):
|
| 54 |
+
"""An importlib reimplementation of imp.find_module (for our purposes)."""
|
| 55 |
+
|
| 56 |
+
# It's necessary to clear the caches for our Finder first, in case any
|
| 57 |
+
# modules are being added/deleted/modified at runtime. In particular,
|
| 58 |
+
# test_modulefinder.py changes file tree contents in a cache-breaking way:
|
| 59 |
+
|
| 60 |
+
importlib.machinery.PathFinder.invalidate_caches()
|
| 61 |
+
|
| 62 |
+
spec = importlib.machinery.PathFinder.find_spec(name, path)
|
| 63 |
+
|
| 64 |
+
if spec is None:
|
| 65 |
+
raise ImportError("No module named {name!r}".format(name=name), name=name)
|
| 66 |
+
|
| 67 |
+
# Some special cases:
|
| 68 |
+
|
| 69 |
+
if spec.loader is importlib.machinery.BuiltinImporter:
|
| 70 |
+
return None, None, ("", "", _C_BUILTIN)
|
| 71 |
+
|
| 72 |
+
if spec.loader is importlib.machinery.FrozenImporter:
|
| 73 |
+
return None, None, ("", "", _PY_FROZEN)
|
| 74 |
+
|
| 75 |
+
file_path = spec.origin
|
| 76 |
+
|
| 77 |
+
if spec.loader.is_package(name):
|
| 78 |
+
return None, os.path.dirname(file_path), ("", "", _PKG_DIRECTORY)
|
| 79 |
+
|
| 80 |
+
if isinstance(spec.loader, importlib.machinery.SourceFileLoader):
|
| 81 |
+
kind = _PY_SOURCE
|
| 82 |
+
|
| 83 |
+
elif isinstance(spec.loader, importlib.machinery.ExtensionFileLoader):
|
| 84 |
+
kind = _C_EXTENSION
|
| 85 |
+
|
| 86 |
+
elif isinstance(spec.loader, importlib.machinery.SourcelessFileLoader):
|
| 87 |
+
kind = _PY_COMPILED
|
| 88 |
+
|
| 89 |
+
else: # Should never happen.
|
| 90 |
+
return None, None, ("", "", _SEARCH_ERROR)
|
| 91 |
+
|
| 92 |
+
file = io.open_code(file_path)
|
| 93 |
+
suffix = os.path.splitext(file_path)[-1]
|
| 94 |
+
|
| 95 |
+
return file, file_path, (suffix, "rb", kind)
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
class Module:
|
| 99 |
+
|
| 100 |
+
def __init__(self, name, file=None, path=None):
|
| 101 |
+
self.__name__ = name
|
| 102 |
+
self.__file__ = file
|
| 103 |
+
self.__path__ = path
|
| 104 |
+
self.__code__ = None
|
| 105 |
+
# The set of global names that are assigned to in the module.
|
| 106 |
+
# This includes those names imported through starimports of
|
| 107 |
+
# Python modules.
|
| 108 |
+
self.globalnames = {}
|
| 109 |
+
# The set of starimports this module did that could not be
|
| 110 |
+
# resolved, ie. a starimport from a non-Python module.
|
| 111 |
+
self.starimports = {}
|
| 112 |
+
|
| 113 |
+
def __repr__(self):
|
| 114 |
+
s = "Module(%r" % (self.__name__,)
|
| 115 |
+
if self.__file__ is not None:
|
| 116 |
+
s = s + ", %r" % (self.__file__,)
|
| 117 |
+
if self.__path__ is not None:
|
| 118 |
+
s = s + ", %r" % (self.__path__,)
|
| 119 |
+
s = s + ")"
|
| 120 |
+
return s
|
| 121 |
+
|
| 122 |
+
class ModuleFinder:
|
| 123 |
+
|
| 124 |
+
def __init__(self, path=None, debug=0, excludes=None, replace_paths=None):
|
| 125 |
+
if path is None:
|
| 126 |
+
path = sys.path
|
| 127 |
+
self.path = path
|
| 128 |
+
self.modules = {}
|
| 129 |
+
self.badmodules = {}
|
| 130 |
+
self.debug = debug
|
| 131 |
+
self.indent = 0
|
| 132 |
+
self.excludes = excludes if excludes is not None else []
|
| 133 |
+
self.replace_paths = replace_paths if replace_paths is not None else []
|
| 134 |
+
self.processed_paths = [] # Used in debugging only
|
| 135 |
+
|
| 136 |
+
def msg(self, level, str, *args):
|
| 137 |
+
if level <= self.debug:
|
| 138 |
+
for i in range(self.indent):
|
| 139 |
+
print(" ", end=' ')
|
| 140 |
+
print(str, end=' ')
|
| 141 |
+
for arg in args:
|
| 142 |
+
print(repr(arg), end=' ')
|
| 143 |
+
print()
|
| 144 |
+
|
| 145 |
+
def msgin(self, *args):
|
| 146 |
+
level = args[0]
|
| 147 |
+
if level <= self.debug:
|
| 148 |
+
self.indent = self.indent + 1
|
| 149 |
+
self.msg(*args)
|
| 150 |
+
|
| 151 |
+
def msgout(self, *args):
|
| 152 |
+
level = args[0]
|
| 153 |
+
if level <= self.debug:
|
| 154 |
+
self.indent = self.indent - 1
|
| 155 |
+
self.msg(*args)
|
| 156 |
+
|
| 157 |
+
def run_script(self, pathname):
|
| 158 |
+
self.msg(2, "run_script", pathname)
|
| 159 |
+
with io.open_code(pathname) as fp:
|
| 160 |
+
stuff = ("", "rb", _PY_SOURCE)
|
| 161 |
+
self.load_module('__main__', fp, pathname, stuff)
|
| 162 |
+
|
| 163 |
+
def load_file(self, pathname):
|
| 164 |
+
dir, name = os.path.split(pathname)
|
| 165 |
+
name, ext = os.path.splitext(name)
|
| 166 |
+
with io.open_code(pathname) as fp:
|
| 167 |
+
stuff = (ext, "rb", _PY_SOURCE)
|
| 168 |
+
self.load_module(name, fp, pathname, stuff)
|
| 169 |
+
|
| 170 |
+
def import_hook(self, name, caller=None, fromlist=None, level=-1):
|
| 171 |
+
self.msg(3, "import_hook", name, caller, fromlist, level)
|
| 172 |
+
parent = self.determine_parent(caller, level=level)
|
| 173 |
+
q, tail = self.find_head_package(parent, name)
|
| 174 |
+
m = self.load_tail(q, tail)
|
| 175 |
+
if not fromlist:
|
| 176 |
+
return q
|
| 177 |
+
if m.__path__:
|
| 178 |
+
self.ensure_fromlist(m, fromlist)
|
| 179 |
+
return None
|
| 180 |
+
|
| 181 |
+
def determine_parent(self, caller, level=-1):
|
| 182 |
+
self.msgin(4, "determine_parent", caller, level)
|
| 183 |
+
if not caller or level == 0:
|
| 184 |
+
self.msgout(4, "determine_parent -> None")
|
| 185 |
+
return None
|
| 186 |
+
pname = caller.__name__
|
| 187 |
+
if level >= 1: # relative import
|
| 188 |
+
if caller.__path__:
|
| 189 |
+
level -= 1
|
| 190 |
+
if level == 0:
|
| 191 |
+
parent = self.modules[pname]
|
| 192 |
+
assert parent is caller
|
| 193 |
+
self.msgout(4, "determine_parent ->", parent)
|
| 194 |
+
return parent
|
| 195 |
+
if pname.count(".") < level:
|
| 196 |
+
raise ImportError("relative importpath too deep")
|
| 197 |
+
pname = ".".join(pname.split(".")[:-level])
|
| 198 |
+
parent = self.modules[pname]
|
| 199 |
+
self.msgout(4, "determine_parent ->", parent)
|
| 200 |
+
return parent
|
| 201 |
+
if caller.__path__:
|
| 202 |
+
parent = self.modules[pname]
|
| 203 |
+
assert caller is parent
|
| 204 |
+
self.msgout(4, "determine_parent ->", parent)
|
| 205 |
+
return parent
|
| 206 |
+
if '.' in pname:
|
| 207 |
+
i = pname.rfind('.')
|
| 208 |
+
pname = pname[:i]
|
| 209 |
+
parent = self.modules[pname]
|
| 210 |
+
assert parent.__name__ == pname
|
| 211 |
+
self.msgout(4, "determine_parent ->", parent)
|
| 212 |
+
return parent
|
| 213 |
+
self.msgout(4, "determine_parent -> None")
|
| 214 |
+
return None
|
| 215 |
+
|
| 216 |
+
def find_head_package(self, parent, name):
|
| 217 |
+
self.msgin(4, "find_head_package", parent, name)
|
| 218 |
+
if '.' in name:
|
| 219 |
+
i = name.find('.')
|
| 220 |
+
head = name[:i]
|
| 221 |
+
tail = name[i+1:]
|
| 222 |
+
else:
|
| 223 |
+
head = name
|
| 224 |
+
tail = ""
|
| 225 |
+
if parent:
|
| 226 |
+
qname = "%s.%s" % (parent.__name__, head)
|
| 227 |
+
else:
|
| 228 |
+
qname = head
|
| 229 |
+
q = self.import_module(head, qname, parent)
|
| 230 |
+
if q:
|
| 231 |
+
self.msgout(4, "find_head_package ->", (q, tail))
|
| 232 |
+
return q, tail
|
| 233 |
+
if parent:
|
| 234 |
+
qname = head
|
| 235 |
+
parent = None
|
| 236 |
+
q = self.import_module(head, qname, parent)
|
| 237 |
+
if q:
|
| 238 |
+
self.msgout(4, "find_head_package ->", (q, tail))
|
| 239 |
+
return q, tail
|
| 240 |
+
self.msgout(4, "raise ImportError: No module named", qname)
|
| 241 |
+
raise ImportError("No module named " + qname)
|
| 242 |
+
|
| 243 |
+
def load_tail(self, q, tail):
|
| 244 |
+
self.msgin(4, "load_tail", q, tail)
|
| 245 |
+
m = q
|
| 246 |
+
while tail:
|
| 247 |
+
i = tail.find('.')
|
| 248 |
+
if i < 0: i = len(tail)
|
| 249 |
+
head, tail = tail[:i], tail[i+1:]
|
| 250 |
+
mname = "%s.%s" % (m.__name__, head)
|
| 251 |
+
m = self.import_module(head, mname, m)
|
| 252 |
+
if not m:
|
| 253 |
+
self.msgout(4, "raise ImportError: No module named", mname)
|
| 254 |
+
raise ImportError("No module named " + mname)
|
| 255 |
+
self.msgout(4, "load_tail ->", m)
|
| 256 |
+
return m
|
| 257 |
+
|
| 258 |
+
def ensure_fromlist(self, m, fromlist, recursive=0):
|
| 259 |
+
self.msg(4, "ensure_fromlist", m, fromlist, recursive)
|
| 260 |
+
for sub in fromlist:
|
| 261 |
+
if sub == "*":
|
| 262 |
+
if not recursive:
|
| 263 |
+
all = self.find_all_submodules(m)
|
| 264 |
+
if all:
|
| 265 |
+
self.ensure_fromlist(m, all, 1)
|
| 266 |
+
elif not hasattr(m, sub):
|
| 267 |
+
subname = "%s.%s" % (m.__name__, sub)
|
| 268 |
+
submod = self.import_module(sub, subname, m)
|
| 269 |
+
if not submod:
|
| 270 |
+
raise ImportError("No module named " + subname)
|
| 271 |
+
|
| 272 |
+
def find_all_submodules(self, m):
|
| 273 |
+
if not m.__path__:
|
| 274 |
+
return
|
| 275 |
+
modules = {}
|
| 276 |
+
# 'suffixes' used to be a list hardcoded to [".py", ".pyc"].
|
| 277 |
+
# But we must also collect Python extension modules - although
|
| 278 |
+
# we cannot separate normal dlls from Python extensions.
|
| 279 |
+
suffixes = []
|
| 280 |
+
suffixes += importlib.machinery.EXTENSION_SUFFIXES[:]
|
| 281 |
+
suffixes += importlib.machinery.SOURCE_SUFFIXES[:]
|
| 282 |
+
suffixes += importlib.machinery.BYTECODE_SUFFIXES[:]
|
| 283 |
+
for dir in m.__path__:
|
| 284 |
+
try:
|
| 285 |
+
names = os.listdir(dir)
|
| 286 |
+
except OSError:
|
| 287 |
+
self.msg(2, "can't list directory", dir)
|
| 288 |
+
continue
|
| 289 |
+
for name in names:
|
| 290 |
+
mod = None
|
| 291 |
+
for suff in suffixes:
|
| 292 |
+
n = len(suff)
|
| 293 |
+
if name[-n:] == suff:
|
| 294 |
+
mod = name[:-n]
|
| 295 |
+
break
|
| 296 |
+
if mod and mod != "__init__":
|
| 297 |
+
modules[mod] = mod
|
| 298 |
+
return modules.keys()
|
| 299 |
+
|
| 300 |
+
def import_module(self, partname, fqname, parent):
|
| 301 |
+
self.msgin(3, "import_module", partname, fqname, parent)
|
| 302 |
+
try:
|
| 303 |
+
m = self.modules[fqname]
|
| 304 |
+
except KeyError:
|
| 305 |
+
pass
|
| 306 |
+
else:
|
| 307 |
+
self.msgout(3, "import_module ->", m)
|
| 308 |
+
return m
|
| 309 |
+
if fqname in self.badmodules:
|
| 310 |
+
self.msgout(3, "import_module -> None")
|
| 311 |
+
return None
|
| 312 |
+
if parent and parent.__path__ is None:
|
| 313 |
+
self.msgout(3, "import_module -> None")
|
| 314 |
+
return None
|
| 315 |
+
try:
|
| 316 |
+
fp, pathname, stuff = self.find_module(partname,
|
| 317 |
+
parent and parent.__path__, parent)
|
| 318 |
+
except ImportError:
|
| 319 |
+
self.msgout(3, "import_module ->", None)
|
| 320 |
+
return None
|
| 321 |
+
|
| 322 |
+
try:
|
| 323 |
+
m = self.load_module(fqname, fp, pathname, stuff)
|
| 324 |
+
finally:
|
| 325 |
+
if fp:
|
| 326 |
+
fp.close()
|
| 327 |
+
if parent:
|
| 328 |
+
setattr(parent, partname, m)
|
| 329 |
+
self.msgout(3, "import_module ->", m)
|
| 330 |
+
return m
|
| 331 |
+
|
| 332 |
+
def load_module(self, fqname, fp, pathname, file_info):
|
| 333 |
+
suffix, mode, type = file_info
|
| 334 |
+
self.msgin(2, "load_module", fqname, fp and "fp", pathname)
|
| 335 |
+
if type == _PKG_DIRECTORY:
|
| 336 |
+
m = self.load_package(fqname, pathname)
|
| 337 |
+
self.msgout(2, "load_module ->", m)
|
| 338 |
+
return m
|
| 339 |
+
if type == _PY_SOURCE:
|
| 340 |
+
co = compile(fp.read(), pathname, 'exec')
|
| 341 |
+
elif type == _PY_COMPILED:
|
| 342 |
+
try:
|
| 343 |
+
data = fp.read()
|
| 344 |
+
importlib._bootstrap_external._classify_pyc(data, fqname, {})
|
| 345 |
+
except ImportError as exc:
|
| 346 |
+
self.msgout(2, "raise ImportError: " + str(exc), pathname)
|
| 347 |
+
raise
|
| 348 |
+
co = marshal.loads(memoryview(data)[16:])
|
| 349 |
+
else:
|
| 350 |
+
co = None
|
| 351 |
+
m = self.add_module(fqname)
|
| 352 |
+
m.__file__ = pathname
|
| 353 |
+
if co:
|
| 354 |
+
if self.replace_paths:
|
| 355 |
+
co = self.replace_paths_in_code(co)
|
| 356 |
+
m.__code__ = co
|
| 357 |
+
self.scan_code(co, m)
|
| 358 |
+
self.msgout(2, "load_module ->", m)
|
| 359 |
+
return m
|
| 360 |
+
|
| 361 |
+
def _add_badmodule(self, name, caller):
|
| 362 |
+
if name not in self.badmodules:
|
| 363 |
+
self.badmodules[name] = {}
|
| 364 |
+
if caller:
|
| 365 |
+
self.badmodules[name][caller.__name__] = 1
|
| 366 |
+
else:
|
| 367 |
+
self.badmodules[name]["-"] = 1
|
| 368 |
+
|
| 369 |
+
def _safe_import_hook(self, name, caller, fromlist, level=-1):
|
| 370 |
+
# wrapper for self.import_hook() that won't raise ImportError
|
| 371 |
+
if name in self.badmodules:
|
| 372 |
+
self._add_badmodule(name, caller)
|
| 373 |
+
return
|
| 374 |
+
try:
|
| 375 |
+
self.import_hook(name, caller, level=level)
|
| 376 |
+
except ImportError as msg:
|
| 377 |
+
self.msg(2, "ImportError:", str(msg))
|
| 378 |
+
self._add_badmodule(name, caller)
|
| 379 |
+
except SyntaxError as msg:
|
| 380 |
+
self.msg(2, "SyntaxError:", str(msg))
|
| 381 |
+
self._add_badmodule(name, caller)
|
| 382 |
+
else:
|
| 383 |
+
if fromlist:
|
| 384 |
+
for sub in fromlist:
|
| 385 |
+
fullname = name + "." + sub
|
| 386 |
+
if fullname in self.badmodules:
|
| 387 |
+
self._add_badmodule(fullname, caller)
|
| 388 |
+
continue
|
| 389 |
+
try:
|
| 390 |
+
self.import_hook(name, caller, [sub], level=level)
|
| 391 |
+
except ImportError as msg:
|
| 392 |
+
self.msg(2, "ImportError:", str(msg))
|
| 393 |
+
self._add_badmodule(fullname, caller)
|
| 394 |
+
|
| 395 |
+
def scan_opcodes(self, co):
|
| 396 |
+
# Scan the code, and yield 'interesting' opcode combinations
|
| 397 |
+
code = co.co_code
|
| 398 |
+
names = co.co_names
|
| 399 |
+
consts = co.co_consts
|
| 400 |
+
opargs = [(op, arg) for _, op, arg in dis._unpack_opargs(code)
|
| 401 |
+
if op != EXTENDED_ARG]
|
| 402 |
+
for i, (op, oparg) in enumerate(opargs):
|
| 403 |
+
if op in STORE_OPS:
|
| 404 |
+
yield "store", (names[oparg],)
|
| 405 |
+
continue
|
| 406 |
+
if (op == IMPORT_NAME and i >= 2
|
| 407 |
+
and opargs[i-1][0] == opargs[i-2][0] == LOAD_CONST):
|
| 408 |
+
level = consts[opargs[i-2][1]]
|
| 409 |
+
fromlist = consts[opargs[i-1][1]]
|
| 410 |
+
if level == 0: # absolute import
|
| 411 |
+
yield "absolute_import", (fromlist, names[oparg])
|
| 412 |
+
else: # relative import
|
| 413 |
+
yield "relative_import", (level, fromlist, names[oparg])
|
| 414 |
+
continue
|
| 415 |
+
|
| 416 |
+
def scan_code(self, co, m):
|
| 417 |
+
code = co.co_code
|
| 418 |
+
scanner = self.scan_opcodes
|
| 419 |
+
for what, args in scanner(co):
|
| 420 |
+
if what == "store":
|
| 421 |
+
name, = args
|
| 422 |
+
m.globalnames[name] = 1
|
| 423 |
+
elif what == "absolute_import":
|
| 424 |
+
fromlist, name = args
|
| 425 |
+
have_star = 0
|
| 426 |
+
if fromlist is not None:
|
| 427 |
+
if "*" in fromlist:
|
| 428 |
+
have_star = 1
|
| 429 |
+
fromlist = [f for f in fromlist if f != "*"]
|
| 430 |
+
self._safe_import_hook(name, m, fromlist, level=0)
|
| 431 |
+
if have_star:
|
| 432 |
+
# We've encountered an "import *". If it is a Python module,
|
| 433 |
+
# the code has already been parsed and we can suck out the
|
| 434 |
+
# global names.
|
| 435 |
+
mm = None
|
| 436 |
+
if m.__path__:
|
| 437 |
+
# At this point we don't know whether 'name' is a
|
| 438 |
+
# submodule of 'm' or a global module. Let's just try
|
| 439 |
+
# the full name first.
|
| 440 |
+
mm = self.modules.get(m.__name__ + "." + name)
|
| 441 |
+
if mm is None:
|
| 442 |
+
mm = self.modules.get(name)
|
| 443 |
+
if mm is not None:
|
| 444 |
+
m.globalnames.update(mm.globalnames)
|
| 445 |
+
m.starimports.update(mm.starimports)
|
| 446 |
+
if mm.__code__ is None:
|
| 447 |
+
m.starimports[name] = 1
|
| 448 |
+
else:
|
| 449 |
+
m.starimports[name] = 1
|
| 450 |
+
elif what == "relative_import":
|
| 451 |
+
level, fromlist, name = args
|
| 452 |
+
if name:
|
| 453 |
+
self._safe_import_hook(name, m, fromlist, level=level)
|
| 454 |
+
else:
|
| 455 |
+
parent = self.determine_parent(m, level=level)
|
| 456 |
+
self._safe_import_hook(parent.__name__, None, fromlist, level=0)
|
| 457 |
+
else:
|
| 458 |
+
# We don't expect anything else from the generator.
|
| 459 |
+
raise RuntimeError(what)
|
| 460 |
+
|
| 461 |
+
for c in co.co_consts:
|
| 462 |
+
if isinstance(c, type(co)):
|
| 463 |
+
self.scan_code(c, m)
|
| 464 |
+
|
| 465 |
+
def load_package(self, fqname, pathname):
|
| 466 |
+
self.msgin(2, "load_package", fqname, pathname)
|
| 467 |
+
newname = replacePackageMap.get(fqname)
|
| 468 |
+
if newname:
|
| 469 |
+
fqname = newname
|
| 470 |
+
m = self.add_module(fqname)
|
| 471 |
+
m.__file__ = pathname
|
| 472 |
+
m.__path__ = [pathname]
|
| 473 |
+
|
| 474 |
+
# As per comment at top of file, simulate runtime __path__ additions.
|
| 475 |
+
m.__path__ = m.__path__ + packagePathMap.get(fqname, [])
|
| 476 |
+
|
| 477 |
+
fp, buf, stuff = self.find_module("__init__", m.__path__)
|
| 478 |
+
try:
|
| 479 |
+
self.load_module(fqname, fp, buf, stuff)
|
| 480 |
+
self.msgout(2, "load_package ->", m)
|
| 481 |
+
return m
|
| 482 |
+
finally:
|
| 483 |
+
if fp:
|
| 484 |
+
fp.close()
|
| 485 |
+
|
| 486 |
+
def add_module(self, fqname):
|
| 487 |
+
if fqname in self.modules:
|
| 488 |
+
return self.modules[fqname]
|
| 489 |
+
self.modules[fqname] = m = Module(fqname)
|
| 490 |
+
return m
|
| 491 |
+
|
| 492 |
+
def find_module(self, name, path, parent=None):
|
| 493 |
+
if parent is not None:
|
| 494 |
+
# assert path is not None
|
| 495 |
+
fullname = parent.__name__+'.'+name
|
| 496 |
+
else:
|
| 497 |
+
fullname = name
|
| 498 |
+
if fullname in self.excludes:
|
| 499 |
+
self.msgout(3, "find_module -> Excluded", fullname)
|
| 500 |
+
raise ImportError(name)
|
| 501 |
+
|
| 502 |
+
if path is None:
|
| 503 |
+
if name in sys.builtin_module_names:
|
| 504 |
+
return (None, None, ("", "", _C_BUILTIN))
|
| 505 |
+
|
| 506 |
+
path = self.path
|
| 507 |
+
|
| 508 |
+
return _find_module(name, path)
|
| 509 |
+
|
| 510 |
+
def report(self):
|
| 511 |
+
"""Print a report to stdout, listing the found modules with their
|
| 512 |
+
paths, as well as modules that are missing, or seem to be missing.
|
| 513 |
+
"""
|
| 514 |
+
print()
|
| 515 |
+
print(" %-25s %s" % ("Name", "File"))
|
| 516 |
+
print(" %-25s %s" % ("----", "----"))
|
| 517 |
+
# Print modules found
|
| 518 |
+
keys = sorted(self.modules.keys())
|
| 519 |
+
for key in keys:
|
| 520 |
+
m = self.modules[key]
|
| 521 |
+
if m.__path__:
|
| 522 |
+
print("P", end=' ')
|
| 523 |
+
else:
|
| 524 |
+
print("m", end=' ')
|
| 525 |
+
print("%-25s" % key, m.__file__ or "")
|
| 526 |
+
|
| 527 |
+
# Print missing modules
|
| 528 |
+
missing, maybe = self.any_missing_maybe()
|
| 529 |
+
if missing:
|
| 530 |
+
print()
|
| 531 |
+
print("Missing modules:")
|
| 532 |
+
for name in missing:
|
| 533 |
+
mods = sorted(self.badmodules[name].keys())
|
| 534 |
+
print("?", name, "imported from", ', '.join(mods))
|
| 535 |
+
# Print modules that may be missing, but then again, maybe not...
|
| 536 |
+
if maybe:
|
| 537 |
+
print()
|
| 538 |
+
print("Submodules that appear to be missing, but could also be", end=' ')
|
| 539 |
+
print("global names in the parent package:")
|
| 540 |
+
for name in maybe:
|
| 541 |
+
mods = sorted(self.badmodules[name].keys())
|
| 542 |
+
print("?", name, "imported from", ', '.join(mods))
|
| 543 |
+
|
| 544 |
+
def any_missing(self):
|
| 545 |
+
"""Return a list of modules that appear to be missing. Use
|
| 546 |
+
any_missing_maybe() if you want to know which modules are
|
| 547 |
+
certain to be missing, and which *may* be missing.
|
| 548 |
+
"""
|
| 549 |
+
missing, maybe = self.any_missing_maybe()
|
| 550 |
+
return missing + maybe
|
| 551 |
+
|
| 552 |
+
def any_missing_maybe(self):
|
| 553 |
+
"""Return two lists, one with modules that are certainly missing
|
| 554 |
+
and one with modules that *may* be missing. The latter names could
|
| 555 |
+
either be submodules *or* just global names in the package.
|
| 556 |
+
|
| 557 |
+
The reason it can't always be determined is that it's impossible to
|
| 558 |
+
tell which names are imported when "from module import *" is done
|
| 559 |
+
with an extension module, short of actually importing it.
|
| 560 |
+
"""
|
| 561 |
+
missing = []
|
| 562 |
+
maybe = []
|
| 563 |
+
for name in self.badmodules:
|
| 564 |
+
if name in self.excludes:
|
| 565 |
+
continue
|
| 566 |
+
i = name.rfind(".")
|
| 567 |
+
if i < 0:
|
| 568 |
+
missing.append(name)
|
| 569 |
+
continue
|
| 570 |
+
subname = name[i+1:]
|
| 571 |
+
pkgname = name[:i]
|
| 572 |
+
pkg = self.modules.get(pkgname)
|
| 573 |
+
if pkg is not None:
|
| 574 |
+
if pkgname in self.badmodules[name]:
|
| 575 |
+
# The package tried to import this module itself and
|
| 576 |
+
# failed. It's definitely missing.
|
| 577 |
+
missing.append(name)
|
| 578 |
+
elif subname in pkg.globalnames:
|
| 579 |
+
# It's a global in the package: definitely not missing.
|
| 580 |
+
pass
|
| 581 |
+
elif pkg.starimports:
|
| 582 |
+
# It could be missing, but the package did an "import *"
|
| 583 |
+
# from a non-Python module, so we simply can't be sure.
|
| 584 |
+
maybe.append(name)
|
| 585 |
+
else:
|
| 586 |
+
# It's not a global in the package, the package didn't
|
| 587 |
+
# do funny star imports, it's very likely to be missing.
|
| 588 |
+
# The symbol could be inserted into the package from the
|
| 589 |
+
# outside, but since that's not good style we simply list
|
| 590 |
+
# it missing.
|
| 591 |
+
missing.append(name)
|
| 592 |
+
else:
|
| 593 |
+
missing.append(name)
|
| 594 |
+
missing.sort()
|
| 595 |
+
maybe.sort()
|
| 596 |
+
return missing, maybe
|
| 597 |
+
|
| 598 |
+
def replace_paths_in_code(self, co):
|
| 599 |
+
new_filename = original_filename = os.path.normpath(co.co_filename)
|
| 600 |
+
for f, r in self.replace_paths:
|
| 601 |
+
if original_filename.startswith(f):
|
| 602 |
+
new_filename = r + original_filename[len(f):]
|
| 603 |
+
break
|
| 604 |
+
|
| 605 |
+
if self.debug and original_filename not in self.processed_paths:
|
| 606 |
+
if new_filename != original_filename:
|
| 607 |
+
self.msgout(2, "co_filename %r changed to %r" \
|
| 608 |
+
% (original_filename,new_filename,))
|
| 609 |
+
else:
|
| 610 |
+
self.msgout(2, "co_filename %r remains unchanged" \
|
| 611 |
+
% (original_filename,))
|
| 612 |
+
self.processed_paths.append(original_filename)
|
| 613 |
+
|
| 614 |
+
consts = list(co.co_consts)
|
| 615 |
+
for i in range(len(consts)):
|
| 616 |
+
if isinstance(consts[i], type(co)):
|
| 617 |
+
consts[i] = self.replace_paths_in_code(consts[i])
|
| 618 |
+
|
| 619 |
+
return co.replace(co_consts=tuple(consts), co_filename=new_filename)
|
| 620 |
+
|
| 621 |
+
|
| 622 |
+
def test():
|
| 623 |
+
# Parse command line
|
| 624 |
+
import getopt
|
| 625 |
+
try:
|
| 626 |
+
opts, args = getopt.getopt(sys.argv[1:], "dmp:qx:")
|
| 627 |
+
except getopt.error as msg:
|
| 628 |
+
print(msg)
|
| 629 |
+
return
|
| 630 |
+
|
| 631 |
+
# Process options
|
| 632 |
+
debug = 1
|
| 633 |
+
domods = 0
|
| 634 |
+
addpath = []
|
| 635 |
+
exclude = []
|
| 636 |
+
for o, a in opts:
|
| 637 |
+
if o == '-d':
|
| 638 |
+
debug = debug + 1
|
| 639 |
+
if o == '-m':
|
| 640 |
+
domods = 1
|
| 641 |
+
if o == '-p':
|
| 642 |
+
addpath = addpath + a.split(os.pathsep)
|
| 643 |
+
if o == '-q':
|
| 644 |
+
debug = 0
|
| 645 |
+
if o == '-x':
|
| 646 |
+
exclude.append(a)
|
| 647 |
+
|
| 648 |
+
# Provide default arguments
|
| 649 |
+
if not args:
|
| 650 |
+
script = "hello.py"
|
| 651 |
+
else:
|
| 652 |
+
script = args[0]
|
| 653 |
+
|
| 654 |
+
# Set the path based on sys.path and the script directory
|
| 655 |
+
path = sys.path[:]
|
| 656 |
+
path[0] = os.path.dirname(script)
|
| 657 |
+
path = addpath + path
|
| 658 |
+
if debug > 1:
|
| 659 |
+
print("path:")
|
| 660 |
+
for item in path:
|
| 661 |
+
print(" ", repr(item))
|
| 662 |
+
|
| 663 |
+
# Create the module finder and turn its crank
|
| 664 |
+
mf = ModuleFinder(path, debug, exclude)
|
| 665 |
+
for arg in args[1:]:
|
| 666 |
+
if arg == '-m':
|
| 667 |
+
domods = 1
|
| 668 |
+
continue
|
| 669 |
+
if domods:
|
| 670 |
+
if arg[-2:] == '.*':
|
| 671 |
+
mf.import_hook(arg[:-2], None, ["*"])
|
| 672 |
+
else:
|
| 673 |
+
mf.import_hook(arg)
|
| 674 |
+
else:
|
| 675 |
+
mf.load_file(arg)
|
| 676 |
+
mf.run_script(script)
|
| 677 |
+
mf.report()
|
| 678 |
+
return mf # for -i debugging
|
| 679 |
+
|
| 680 |
+
|
| 681 |
+
if __name__ == '__main__':
|
| 682 |
+
try:
|
| 683 |
+
mf = test()
|
| 684 |
+
except KeyboardInterrupt:
|
| 685 |
+
print("\n[interrupted]")
|
llava/lib/python3.10/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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
r"""OS routines for NT or Posix depending on what system we're on.
|
| 2 |
+
|
| 3 |
+
This exports:
|
| 4 |
+
- all functions from posix or nt, e.g. unlink, stat, etc.
|
| 5 |
+
- os.path is either posixpath or ntpath
|
| 6 |
+
- os.name is either 'posix' or 'nt'
|
| 7 |
+
- os.curdir is a string representing the current directory (always '.')
|
| 8 |
+
- os.pardir is a string representing the parent directory (always '..')
|
| 9 |
+
- os.sep is the (or a most common) pathname separator ('/' or '\\')
|
| 10 |
+
- os.extsep is the extension separator (always '.')
|
| 11 |
+
- os.altsep is the alternate pathname separator (None or '/')
|
| 12 |
+
- os.pathsep is the component separator used in $PATH etc
|
| 13 |
+
- os.linesep is the line separator in text files ('\r' or '\n' or '\r\n')
|
| 14 |
+
- os.defpath is the default search path for executables
|
| 15 |
+
- os.devnull is the file path of the null device ('/dev/null', etc.)
|
| 16 |
+
|
| 17 |
+
Programs that import and use 'os' stand a better chance of being
|
| 18 |
+
portable between different platforms. Of course, they must then
|
| 19 |
+
only use functions that are defined by all platforms (e.g., unlink
|
| 20 |
+
and opendir), and leave all pathname manipulation to os.path
|
| 21 |
+
(e.g., split and join).
|
| 22 |
+
"""
|
| 23 |
+
|
| 24 |
+
#'
|
| 25 |
+
import abc
|
| 26 |
+
import sys
|
| 27 |
+
import stat as st
|
| 28 |
+
|
| 29 |
+
from _collections_abc import _check_methods
|
| 30 |
+
|
| 31 |
+
GenericAlias = type(list[int])
|
| 32 |
+
|
| 33 |
+
_names = sys.builtin_module_names
|
| 34 |
+
|
| 35 |
+
# Note: more names are added to __all__ later.
|
| 36 |
+
__all__ = ["altsep", "curdir", "pardir", "sep", "pathsep", "linesep",
|
| 37 |
+
"defpath", "name", "path", "devnull", "SEEK_SET", "SEEK_CUR",
|
| 38 |
+
"SEEK_END", "fsencode", "fsdecode", "get_exec_path", "fdopen",
|
| 39 |
+
"extsep"]
|
| 40 |
+
|
| 41 |
+
def _exists(name):
|
| 42 |
+
return name in globals()
|
| 43 |
+
|
| 44 |
+
def _get_exports_list(module):
|
| 45 |
+
try:
|
| 46 |
+
return list(module.__all__)
|
| 47 |
+
except AttributeError:
|
| 48 |
+
return [n for n in dir(module) if n[0] != '_']
|
| 49 |
+
|
| 50 |
+
# Any new dependencies of the os module and/or changes in path separator
|
| 51 |
+
# requires updating importlib as well.
|
| 52 |
+
if 'posix' in _names:
|
| 53 |
+
name = 'posix'
|
| 54 |
+
linesep = '\n'
|
| 55 |
+
from posix import *
|
| 56 |
+
try:
|
| 57 |
+
from posix import _exit
|
| 58 |
+
__all__.append('_exit')
|
| 59 |
+
except ImportError:
|
| 60 |
+
pass
|
| 61 |
+
import posixpath as path
|
| 62 |
+
|
| 63 |
+
try:
|
| 64 |
+
from posix import _have_functions
|
| 65 |
+
except ImportError:
|
| 66 |
+
pass
|
| 67 |
+
|
| 68 |
+
import posix
|
| 69 |
+
__all__.extend(_get_exports_list(posix))
|
| 70 |
+
del posix
|
| 71 |
+
|
| 72 |
+
elif 'nt' in _names:
|
| 73 |
+
name = 'nt'
|
| 74 |
+
linesep = '\r\n'
|
| 75 |
+
from nt import *
|
| 76 |
+
try:
|
| 77 |
+
from nt import _exit
|
| 78 |
+
__all__.append('_exit')
|
| 79 |
+
except ImportError:
|
| 80 |
+
pass
|
| 81 |
+
import ntpath as path
|
| 82 |
+
|
| 83 |
+
import nt
|
| 84 |
+
__all__.extend(_get_exports_list(nt))
|
| 85 |
+
del nt
|
| 86 |
+
|
| 87 |
+
try:
|
| 88 |
+
from nt import _have_functions
|
| 89 |
+
except ImportError:
|
| 90 |
+
pass
|
| 91 |
+
|
| 92 |
+
else:
|
| 93 |
+
raise ImportError('no os specific module found')
|
| 94 |
+
|
| 95 |
+
sys.modules['os.path'] = path
|
| 96 |
+
from os.path import (curdir, pardir, sep, pathsep, defpath, extsep, altsep,
|
| 97 |
+
devnull)
|
| 98 |
+
|
| 99 |
+
del _names
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
if _exists("_have_functions"):
|
| 103 |
+
_globals = globals()
|
| 104 |
+
def _add(str, fn):
|
| 105 |
+
if (fn in _globals) and (str in _have_functions):
|
| 106 |
+
_set.add(_globals[fn])
|
| 107 |
+
|
| 108 |
+
_set = set()
|
| 109 |
+
_add("HAVE_FACCESSAT", "access")
|
| 110 |
+
_add("HAVE_FCHMODAT", "chmod")
|
| 111 |
+
_add("HAVE_FCHOWNAT", "chown")
|
| 112 |
+
_add("HAVE_FSTATAT", "stat")
|
| 113 |
+
_add("HAVE_FUTIMESAT", "utime")
|
| 114 |
+
_add("HAVE_LINKAT", "link")
|
| 115 |
+
_add("HAVE_MKDIRAT", "mkdir")
|
| 116 |
+
_add("HAVE_MKFIFOAT", "mkfifo")
|
| 117 |
+
_add("HAVE_MKNODAT", "mknod")
|
| 118 |
+
_add("HAVE_OPENAT", "open")
|
| 119 |
+
_add("HAVE_READLINKAT", "readlink")
|
| 120 |
+
_add("HAVE_RENAMEAT", "rename")
|
| 121 |
+
_add("HAVE_SYMLINKAT", "symlink")
|
| 122 |
+
_add("HAVE_UNLINKAT", "unlink")
|
| 123 |
+
_add("HAVE_UNLINKAT", "rmdir")
|
| 124 |
+
_add("HAVE_UTIMENSAT", "utime")
|
| 125 |
+
supports_dir_fd = _set
|
| 126 |
+
|
| 127 |
+
_set = set()
|
| 128 |
+
_add("HAVE_FACCESSAT", "access")
|
| 129 |
+
supports_effective_ids = _set
|
| 130 |
+
|
| 131 |
+
_set = set()
|
| 132 |
+
_add("HAVE_FCHDIR", "chdir")
|
| 133 |
+
_add("HAVE_FCHMOD", "chmod")
|
| 134 |
+
_add("HAVE_FCHOWN", "chown")
|
| 135 |
+
_add("HAVE_FDOPENDIR", "listdir")
|
| 136 |
+
_add("HAVE_FDOPENDIR", "scandir")
|
| 137 |
+
_add("HAVE_FEXECVE", "execve")
|
| 138 |
+
_set.add(stat) # fstat always works
|
| 139 |
+
_add("HAVE_FTRUNCATE", "truncate")
|
| 140 |
+
_add("HAVE_FUTIMENS", "utime")
|
| 141 |
+
_add("HAVE_FUTIMES", "utime")
|
| 142 |
+
_add("HAVE_FPATHCONF", "pathconf")
|
| 143 |
+
if _exists("statvfs") and _exists("fstatvfs"): # mac os x10.3
|
| 144 |
+
_add("HAVE_FSTATVFS", "statvfs")
|
| 145 |
+
supports_fd = _set
|
| 146 |
+
|
| 147 |
+
_set = set()
|
| 148 |
+
_add("HAVE_FACCESSAT", "access")
|
| 149 |
+
# Some platforms don't support lchmod(). Often the function exists
|
| 150 |
+
# anyway, as a stub that always returns ENOSUP or perhaps EOPNOTSUPP.
|
| 151 |
+
# (No, I don't know why that's a good design.) ./configure will detect
|
| 152 |
+
# this and reject it--so HAVE_LCHMOD still won't be defined on such
|
| 153 |
+
# platforms. This is Very Helpful.
|
| 154 |
+
#
|
| 155 |
+
# However, sometimes platforms without a working lchmod() *do* have
|
| 156 |
+
# fchmodat(). (Examples: Linux kernel 3.2 with glibc 2.15,
|
| 157 |
+
# OpenIndiana 3.x.) And fchmodat() has a flag that theoretically makes
|
| 158 |
+
# it behave like lchmod(). So in theory it would be a suitable
|
| 159 |
+
# replacement for lchmod(). But when lchmod() doesn't work, fchmodat()'s
|
| 160 |
+
# flag doesn't work *either*. Sadly ./configure isn't sophisticated
|
| 161 |
+
# enough to detect this condition--it only determines whether or not
|
| 162 |
+
# fchmodat() minimally works.
|
| 163 |
+
#
|
| 164 |
+
# Therefore we simply ignore fchmodat() when deciding whether or not
|
| 165 |
+
# os.chmod supports follow_symlinks. Just checking lchmod() is
|
| 166 |
+
# sufficient. After all--if you have a working fchmodat(), your
|
| 167 |
+
# lchmod() almost certainly works too.
|
| 168 |
+
#
|
| 169 |
+
# _add("HAVE_FCHMODAT", "chmod")
|
| 170 |
+
_add("HAVE_FCHOWNAT", "chown")
|
| 171 |
+
_add("HAVE_FSTATAT", "stat")
|
| 172 |
+
_add("HAVE_LCHFLAGS", "chflags")
|
| 173 |
+
_add("HAVE_LCHMOD", "chmod")
|
| 174 |
+
if _exists("lchown"): # mac os x10.3
|
| 175 |
+
_add("HAVE_LCHOWN", "chown")
|
| 176 |
+
_add("HAVE_LINKAT", "link")
|
| 177 |
+
_add("HAVE_LUTIMES", "utime")
|
| 178 |
+
_add("HAVE_LSTAT", "stat")
|
| 179 |
+
_add("HAVE_FSTATAT", "stat")
|
| 180 |
+
_add("HAVE_UTIMENSAT", "utime")
|
| 181 |
+
_add("MS_WINDOWS", "stat")
|
| 182 |
+
supports_follow_symlinks = _set
|
| 183 |
+
|
| 184 |
+
del _set
|
| 185 |
+
del _have_functions
|
| 186 |
+
del _globals
|
| 187 |
+
del _add
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
# Python uses fixed values for the SEEK_ constants; they are mapped
|
| 191 |
+
# to native constants if necessary in posixmodule.c
|
| 192 |
+
# Other possible SEEK values are directly imported from posixmodule.c
|
| 193 |
+
SEEK_SET = 0
|
| 194 |
+
SEEK_CUR = 1
|
| 195 |
+
SEEK_END = 2
|
| 196 |
+
|
| 197 |
+
# Super directory utilities.
|
| 198 |
+
# (Inspired by Eric Raymond; the doc strings are mostly his)
|
| 199 |
+
|
| 200 |
+
def makedirs(name, mode=0o777, exist_ok=False):
|
| 201 |
+
"""makedirs(name [, mode=0o777][, exist_ok=False])
|
| 202 |
+
|
| 203 |
+
Super-mkdir; create a leaf directory and all intermediate ones. Works like
|
| 204 |
+
mkdir, except that any intermediate path segment (not just the rightmost)
|
| 205 |
+
will be created if it does not exist. If the target directory already
|
| 206 |
+
exists, raise an OSError if exist_ok is False. Otherwise no exception is
|
| 207 |
+
raised. This is recursive.
|
| 208 |
+
|
| 209 |
+
"""
|
| 210 |
+
head, tail = path.split(name)
|
| 211 |
+
if not tail:
|
| 212 |
+
head, tail = path.split(head)
|
| 213 |
+
if head and tail and not path.exists(head):
|
| 214 |
+
try:
|
| 215 |
+
makedirs(head, exist_ok=exist_ok)
|
| 216 |
+
except FileExistsError:
|
| 217 |
+
# Defeats race condition when another thread created the path
|
| 218 |
+
pass
|
| 219 |
+
cdir = curdir
|
| 220 |
+
if isinstance(tail, bytes):
|
| 221 |
+
cdir = bytes(curdir, 'ASCII')
|
| 222 |
+
if tail == cdir: # xxx/newdir/. exists if xxx/newdir exists
|
| 223 |
+
return
|
| 224 |
+
try:
|
| 225 |
+
mkdir(name, mode)
|
| 226 |
+
except OSError:
|
| 227 |
+
# Cannot rely on checking for EEXIST, since the operating system
|
| 228 |
+
# could give priority to other errors like EACCES or EROFS
|
| 229 |
+
if not exist_ok or not path.isdir(name):
|
| 230 |
+
raise
|
| 231 |
+
|
| 232 |
+
def removedirs(name):
|
| 233 |
+
"""removedirs(name)
|
| 234 |
+
|
| 235 |
+
Super-rmdir; remove a leaf directory and all empty intermediate
|
| 236 |
+
ones. Works like rmdir except that, if the leaf directory is
|
| 237 |
+
successfully removed, directories corresponding to rightmost path
|
| 238 |
+
segments will be pruned away until either the whole path is
|
| 239 |
+
consumed or an error occurs. Errors during this latter phase are
|
| 240 |
+
ignored -- they generally mean that a directory was not empty.
|
| 241 |
+
|
| 242 |
+
"""
|
| 243 |
+
rmdir(name)
|
| 244 |
+
head, tail = path.split(name)
|
| 245 |
+
if not tail:
|
| 246 |
+
head, tail = path.split(head)
|
| 247 |
+
while head and tail:
|
| 248 |
+
try:
|
| 249 |
+
rmdir(head)
|
| 250 |
+
except OSError:
|
| 251 |
+
break
|
| 252 |
+
head, tail = path.split(head)
|
| 253 |
+
|
| 254 |
+
def renames(old, new):
|
| 255 |
+
"""renames(old, new)
|
| 256 |
+
|
| 257 |
+
Super-rename; create directories as necessary and delete any left
|
| 258 |
+
empty. Works like rename, except creation of any intermediate
|
| 259 |
+
directories needed to make the new pathname good is attempted
|
| 260 |
+
first. After the rename, directories corresponding to rightmost
|
| 261 |
+
path segments of the old name will be pruned until either the
|
| 262 |
+
whole path is consumed or a nonempty directory is found.
|
| 263 |
+
|
| 264 |
+
Note: this function can fail with the new directory structure made
|
| 265 |
+
if you lack permissions needed to unlink the leaf directory or
|
| 266 |
+
file.
|
| 267 |
+
|
| 268 |
+
"""
|
| 269 |
+
head, tail = path.split(new)
|
| 270 |
+
if head and tail and not path.exists(head):
|
| 271 |
+
makedirs(head)
|
| 272 |
+
rename(old, new)
|
| 273 |
+
head, tail = path.split(old)
|
| 274 |
+
if head and tail:
|
| 275 |
+
try:
|
| 276 |
+
removedirs(head)
|
| 277 |
+
except OSError:
|
| 278 |
+
pass
|
| 279 |
+
|
| 280 |
+
__all__.extend(["makedirs", "removedirs", "renames"])
|
| 281 |
+
|
| 282 |
+
def walk(top, topdown=True, onerror=None, followlinks=False):
|
| 283 |
+
"""Directory tree generator.
|
| 284 |
+
|
| 285 |
+
For each directory in the directory tree rooted at top (including top
|
| 286 |
+
itself, but excluding '.' and '..'), yields a 3-tuple
|
| 287 |
+
|
| 288 |
+
dirpath, dirnames, filenames
|
| 289 |
+
|
| 290 |
+
dirpath is a string, the path to the directory. dirnames is a list of
|
| 291 |
+
the names of the subdirectories in dirpath (including symlinks to directories,
|
| 292 |
+
and excluding '.' and '..').
|
| 293 |
+
filenames is a list of the names of the non-directory files in dirpath.
|
| 294 |
+
Note that the names in the lists are just names, with no path components.
|
| 295 |
+
To get a full path (which begins with top) to a file or directory in
|
| 296 |
+
dirpath, do os.path.join(dirpath, name).
|
| 297 |
+
|
| 298 |
+
If optional arg 'topdown' is true or not specified, the triple for a
|
| 299 |
+
directory is generated before the triples for any of its subdirectories
|
| 300 |
+
(directories are generated top down). If topdown is false, the triple
|
| 301 |
+
for a directory is generated after the triples for all of its
|
| 302 |
+
subdirectories (directories are generated bottom up).
|
| 303 |
+
|
| 304 |
+
When topdown is true, the caller can modify the dirnames list in-place
|
| 305 |
+
(e.g., via del or slice assignment), and walk will only recurse into the
|
| 306 |
+
subdirectories whose names remain in dirnames; this can be used to prune the
|
| 307 |
+
search, or to impose a specific order of visiting. Modifying dirnames when
|
| 308 |
+
topdown is false has no effect on the behavior of os.walk(), since the
|
| 309 |
+
directories in dirnames have already been generated by the time dirnames
|
| 310 |
+
itself is generated. No matter the value of topdown, the list of
|
| 311 |
+
subdirectories is retrieved before the tuples for the directory and its
|
| 312 |
+
subdirectories are generated.
|
| 313 |
+
|
| 314 |
+
By default errors from the os.scandir() call are ignored. If
|
| 315 |
+
optional arg 'onerror' is specified, it should be a function; it
|
| 316 |
+
will be called with one argument, an OSError instance. It can
|
| 317 |
+
report the error to continue with the walk, or raise the exception
|
| 318 |
+
to abort the walk. Note that the filename is available as the
|
| 319 |
+
filename attribute of the exception object.
|
| 320 |
+
|
| 321 |
+
By default, os.walk does not follow symbolic links to subdirectories on
|
| 322 |
+
systems that support them. In order to get this functionality, set the
|
| 323 |
+
optional argument 'followlinks' to true.
|
| 324 |
+
|
| 325 |
+
Caution: if you pass a relative pathname for top, don't change the
|
| 326 |
+
current working directory between resumptions of walk. walk never
|
| 327 |
+
changes the current directory, and assumes that the client doesn't
|
| 328 |
+
either.
|
| 329 |
+
|
| 330 |
+
Example:
|
| 331 |
+
|
| 332 |
+
import os
|
| 333 |
+
from os.path import join, getsize
|
| 334 |
+
for root, dirs, files in os.walk('python/Lib/email'):
|
| 335 |
+
print(root, "consumes", end="")
|
| 336 |
+
print(sum(getsize(join(root, name)) for name in files), end="")
|
| 337 |
+
print("bytes in", len(files), "non-directory files")
|
| 338 |
+
if 'CVS' in dirs:
|
| 339 |
+
dirs.remove('CVS') # don't visit CVS directories
|
| 340 |
+
|
| 341 |
+
"""
|
| 342 |
+
sys.audit("os.walk", top, topdown, onerror, followlinks)
|
| 343 |
+
return _walk(fspath(top), topdown, onerror, followlinks)
|
| 344 |
+
|
| 345 |
+
def _walk(top, topdown, onerror, followlinks):
|
| 346 |
+
dirs = []
|
| 347 |
+
nondirs = []
|
| 348 |
+
walk_dirs = []
|
| 349 |
+
|
| 350 |
+
# We may not have read permission for top, in which case we can't
|
| 351 |
+
# get a list of the files the directory contains. os.walk
|
| 352 |
+
# always suppressed the exception then, rather than blow up for a
|
| 353 |
+
# minor reason when (say) a thousand readable directories are still
|
| 354 |
+
# left to visit. That logic is copied here.
|
| 355 |
+
try:
|
| 356 |
+
# Note that scandir is global in this module due
|
| 357 |
+
# to earlier import-*.
|
| 358 |
+
scandir_it = scandir(top)
|
| 359 |
+
except OSError as error:
|
| 360 |
+
if onerror is not None:
|
| 361 |
+
onerror(error)
|
| 362 |
+
return
|
| 363 |
+
|
| 364 |
+
with scandir_it:
|
| 365 |
+
while True:
|
| 366 |
+
try:
|
| 367 |
+
try:
|
| 368 |
+
entry = next(scandir_it)
|
| 369 |
+
except StopIteration:
|
| 370 |
+
break
|
| 371 |
+
except OSError as error:
|
| 372 |
+
if onerror is not None:
|
| 373 |
+
onerror(error)
|
| 374 |
+
return
|
| 375 |
+
|
| 376 |
+
try:
|
| 377 |
+
is_dir = entry.is_dir()
|
| 378 |
+
except OSError:
|
| 379 |
+
# If is_dir() raises an OSError, consider that the entry is not
|
| 380 |
+
# a directory, same behaviour than os.path.isdir().
|
| 381 |
+
is_dir = False
|
| 382 |
+
|
| 383 |
+
if is_dir:
|
| 384 |
+
dirs.append(entry.name)
|
| 385 |
+
else:
|
| 386 |
+
nondirs.append(entry.name)
|
| 387 |
+
|
| 388 |
+
if not topdown and is_dir:
|
| 389 |
+
# Bottom-up: recurse into sub-directory, but exclude symlinks to
|
| 390 |
+
# directories if followlinks is False
|
| 391 |
+
if followlinks:
|
| 392 |
+
walk_into = True
|
| 393 |
+
else:
|
| 394 |
+
try:
|
| 395 |
+
is_symlink = entry.is_symlink()
|
| 396 |
+
except OSError:
|
| 397 |
+
# If is_symlink() raises an OSError, consider that the
|
| 398 |
+
# entry is not a symbolic link, same behaviour than
|
| 399 |
+
# os.path.islink().
|
| 400 |
+
is_symlink = False
|
| 401 |
+
walk_into = not is_symlink
|
| 402 |
+
|
| 403 |
+
if walk_into:
|
| 404 |
+
walk_dirs.append(entry.path)
|
| 405 |
+
|
| 406 |
+
# Yield before recursion if going top down
|
| 407 |
+
if topdown:
|
| 408 |
+
yield top, dirs, nondirs
|
| 409 |
+
|
| 410 |
+
# Recurse into sub-directories
|
| 411 |
+
islink, join = path.islink, path.join
|
| 412 |
+
for dirname in dirs:
|
| 413 |
+
new_path = join(top, dirname)
|
| 414 |
+
# Issue #23605: os.path.islink() is used instead of caching
|
| 415 |
+
# entry.is_symlink() result during the loop on os.scandir() because
|
| 416 |
+
# the caller can replace the directory entry during the "yield"
|
| 417 |
+
# above.
|
| 418 |
+
if followlinks or not islink(new_path):
|
| 419 |
+
yield from _walk(new_path, topdown, onerror, followlinks)
|
| 420 |
+
else:
|
| 421 |
+
# Recurse into sub-directories
|
| 422 |
+
for new_path in walk_dirs:
|
| 423 |
+
yield from _walk(new_path, topdown, onerror, followlinks)
|
| 424 |
+
# Yield after recursion if going bottom up
|
| 425 |
+
yield top, dirs, nondirs
|
| 426 |
+
|
| 427 |
+
__all__.append("walk")
|
| 428 |
+
|
| 429 |
+
if {open, stat} <= supports_dir_fd and {scandir, stat} <= supports_fd:
|
| 430 |
+
|
| 431 |
+
def fwalk(top=".", topdown=True, onerror=None, *, follow_symlinks=False, dir_fd=None):
|
| 432 |
+
"""Directory tree generator.
|
| 433 |
+
|
| 434 |
+
This behaves exactly like walk(), except that it yields a 4-tuple
|
| 435 |
+
|
| 436 |
+
dirpath, dirnames, filenames, dirfd
|
| 437 |
+
|
| 438 |
+
`dirpath`, `dirnames` and `filenames` are identical to walk() output,
|
| 439 |
+
and `dirfd` is a file descriptor referring to the directory `dirpath`.
|
| 440 |
+
|
| 441 |
+
The advantage of fwalk() over walk() is that it's safe against symlink
|
| 442 |
+
races (when follow_symlinks is False).
|
| 443 |
+
|
| 444 |
+
If dir_fd is not None, it should be a file descriptor open to a directory,
|
| 445 |
+
and top should be relative; top will then be relative to that directory.
|
| 446 |
+
(dir_fd is always supported for fwalk.)
|
| 447 |
+
|
| 448 |
+
Caution:
|
| 449 |
+
Since fwalk() yields file descriptors, those are only valid until the
|
| 450 |
+
next iteration step, so you should dup() them if you want to keep them
|
| 451 |
+
for a longer period.
|
| 452 |
+
|
| 453 |
+
Example:
|
| 454 |
+
|
| 455 |
+
import os
|
| 456 |
+
for root, dirs, files, rootfd in os.fwalk('python/Lib/email'):
|
| 457 |
+
print(root, "consumes", end="")
|
| 458 |
+
print(sum(os.stat(name, dir_fd=rootfd).st_size for name in files),
|
| 459 |
+
end="")
|
| 460 |
+
print("bytes in", len(files), "non-directory files")
|
| 461 |
+
if 'CVS' in dirs:
|
| 462 |
+
dirs.remove('CVS') # don't visit CVS directories
|
| 463 |
+
"""
|
| 464 |
+
sys.audit("os.fwalk", top, topdown, onerror, follow_symlinks, dir_fd)
|
| 465 |
+
if not isinstance(top, int) or not hasattr(top, '__index__'):
|
| 466 |
+
top = fspath(top)
|
| 467 |
+
# Note: To guard against symlink races, we use the standard
|
| 468 |
+
# lstat()/open()/fstat() trick.
|
| 469 |
+
if not follow_symlinks:
|
| 470 |
+
orig_st = stat(top, follow_symlinks=False, dir_fd=dir_fd)
|
| 471 |
+
topfd = open(top, O_RDONLY, dir_fd=dir_fd)
|
| 472 |
+
try:
|
| 473 |
+
if (follow_symlinks or (st.S_ISDIR(orig_st.st_mode) and
|
| 474 |
+
path.samestat(orig_st, stat(topfd)))):
|
| 475 |
+
yield from _fwalk(topfd, top, isinstance(top, bytes),
|
| 476 |
+
topdown, onerror, follow_symlinks)
|
| 477 |
+
finally:
|
| 478 |
+
close(topfd)
|
| 479 |
+
|
| 480 |
+
def _fwalk(topfd, toppath, isbytes, topdown, onerror, follow_symlinks):
|
| 481 |
+
# Note: This uses O(depth of the directory tree) file descriptors: if
|
| 482 |
+
# necessary, it can be adapted to only require O(1) FDs, see issue
|
| 483 |
+
# #13734.
|
| 484 |
+
|
| 485 |
+
scandir_it = scandir(topfd)
|
| 486 |
+
dirs = []
|
| 487 |
+
nondirs = []
|
| 488 |
+
entries = None if topdown or follow_symlinks else []
|
| 489 |
+
for entry in scandir_it:
|
| 490 |
+
name = entry.name
|
| 491 |
+
if isbytes:
|
| 492 |
+
name = fsencode(name)
|
| 493 |
+
try:
|
| 494 |
+
if entry.is_dir():
|
| 495 |
+
dirs.append(name)
|
| 496 |
+
if entries is not None:
|
| 497 |
+
entries.append(entry)
|
| 498 |
+
else:
|
| 499 |
+
nondirs.append(name)
|
| 500 |
+
except OSError:
|
| 501 |
+
try:
|
| 502 |
+
# Add dangling symlinks, ignore disappeared files
|
| 503 |
+
if entry.is_symlink():
|
| 504 |
+
nondirs.append(name)
|
| 505 |
+
except OSError:
|
| 506 |
+
pass
|
| 507 |
+
|
| 508 |
+
if topdown:
|
| 509 |
+
yield toppath, dirs, nondirs, topfd
|
| 510 |
+
|
| 511 |
+
for name in dirs if entries is None else zip(dirs, entries):
|
| 512 |
+
try:
|
| 513 |
+
if not follow_symlinks:
|
| 514 |
+
if topdown:
|
| 515 |
+
orig_st = stat(name, dir_fd=topfd, follow_symlinks=False)
|
| 516 |
+
else:
|
| 517 |
+
assert entries is not None
|
| 518 |
+
name, entry = name
|
| 519 |
+
orig_st = entry.stat(follow_symlinks=False)
|
| 520 |
+
dirfd = open(name, O_RDONLY, dir_fd=topfd)
|
| 521 |
+
except OSError as err:
|
| 522 |
+
if onerror is not None:
|
| 523 |
+
onerror(err)
|
| 524 |
+
continue
|
| 525 |
+
try:
|
| 526 |
+
if follow_symlinks or path.samestat(orig_st, stat(dirfd)):
|
| 527 |
+
dirpath = path.join(toppath, name)
|
| 528 |
+
yield from _fwalk(dirfd, dirpath, isbytes,
|
| 529 |
+
topdown, onerror, follow_symlinks)
|
| 530 |
+
finally:
|
| 531 |
+
close(dirfd)
|
| 532 |
+
|
| 533 |
+
if not topdown:
|
| 534 |
+
yield toppath, dirs, nondirs, topfd
|
| 535 |
+
|
| 536 |
+
__all__.append("fwalk")
|
| 537 |
+
|
| 538 |
+
def execl(file, *args):
|
| 539 |
+
"""execl(file, *args)
|
| 540 |
+
|
| 541 |
+
Execute the executable file with argument list args, replacing the
|
| 542 |
+
current process. """
|
| 543 |
+
execv(file, args)
|
| 544 |
+
|
| 545 |
+
def execle(file, *args):
|
| 546 |
+
"""execle(file, *args, env)
|
| 547 |
+
|
| 548 |
+
Execute the executable file with argument list args and
|
| 549 |
+
environment env, replacing the current process. """
|
| 550 |
+
env = args[-1]
|
| 551 |
+
execve(file, args[:-1], env)
|
| 552 |
+
|
| 553 |
+
def execlp(file, *args):
|
| 554 |
+
"""execlp(file, *args)
|
| 555 |
+
|
| 556 |
+
Execute the executable file (which is searched for along $PATH)
|
| 557 |
+
with argument list args, replacing the current process. """
|
| 558 |
+
execvp(file, args)
|
| 559 |
+
|
| 560 |
+
def execlpe(file, *args):
|
| 561 |
+
"""execlpe(file, *args, env)
|
| 562 |
+
|
| 563 |
+
Execute the executable file (which is searched for along $PATH)
|
| 564 |
+
with argument list args and environment env, replacing the current
|
| 565 |
+
process. """
|
| 566 |
+
env = args[-1]
|
| 567 |
+
execvpe(file, args[:-1], env)
|
| 568 |
+
|
| 569 |
+
def execvp(file, args):
|
| 570 |
+
"""execvp(file, args)
|
| 571 |
+
|
| 572 |
+
Execute the executable file (which is searched for along $PATH)
|
| 573 |
+
with argument list args, replacing the current process.
|
| 574 |
+
args may be a list or tuple of strings. """
|
| 575 |
+
_execvpe(file, args)
|
| 576 |
+
|
| 577 |
+
def execvpe(file, args, env):
|
| 578 |
+
"""execvpe(file, args, env)
|
| 579 |
+
|
| 580 |
+
Execute the executable file (which is searched for along $PATH)
|
| 581 |
+
with argument list args and environment env, replacing the
|
| 582 |
+
current process.
|
| 583 |
+
args may be a list or tuple of strings. """
|
| 584 |
+
_execvpe(file, args, env)
|
| 585 |
+
|
| 586 |
+
__all__.extend(["execl","execle","execlp","execlpe","execvp","execvpe"])
|
| 587 |
+
|
| 588 |
+
def _execvpe(file, args, env=None):
|
| 589 |
+
if env is not None:
|
| 590 |
+
exec_func = execve
|
| 591 |
+
argrest = (args, env)
|
| 592 |
+
else:
|
| 593 |
+
exec_func = execv
|
| 594 |
+
argrest = (args,)
|
| 595 |
+
env = environ
|
| 596 |
+
|
| 597 |
+
if path.dirname(file):
|
| 598 |
+
exec_func(file, *argrest)
|
| 599 |
+
return
|
| 600 |
+
saved_exc = None
|
| 601 |
+
path_list = get_exec_path(env)
|
| 602 |
+
if name != 'nt':
|
| 603 |
+
file = fsencode(file)
|
| 604 |
+
path_list = map(fsencode, path_list)
|
| 605 |
+
for dir in path_list:
|
| 606 |
+
fullname = path.join(dir, file)
|
| 607 |
+
try:
|
| 608 |
+
exec_func(fullname, *argrest)
|
| 609 |
+
except (FileNotFoundError, NotADirectoryError) as e:
|
| 610 |
+
last_exc = e
|
| 611 |
+
except OSError as e:
|
| 612 |
+
last_exc = e
|
| 613 |
+
if saved_exc is None:
|
| 614 |
+
saved_exc = e
|
| 615 |
+
if saved_exc is not None:
|
| 616 |
+
raise saved_exc
|
| 617 |
+
raise last_exc
|
| 618 |
+
|
| 619 |
+
|
| 620 |
+
def get_exec_path(env=None):
|
| 621 |
+
"""Returns the sequence of directories that will be searched for the
|
| 622 |
+
named executable (similar to a shell) when launching a process.
|
| 623 |
+
|
| 624 |
+
*env* must be an environment variable dict or None. If *env* is None,
|
| 625 |
+
os.environ will be used.
|
| 626 |
+
"""
|
| 627 |
+
# Use a local import instead of a global import to limit the number of
|
| 628 |
+
# modules loaded at startup: the os module is always loaded at startup by
|
| 629 |
+
# Python. It may also avoid a bootstrap issue.
|
| 630 |
+
import warnings
|
| 631 |
+
|
| 632 |
+
if env is None:
|
| 633 |
+
env = environ
|
| 634 |
+
|
| 635 |
+
# {b'PATH': ...}.get('PATH') and {'PATH': ...}.get(b'PATH') emit a
|
| 636 |
+
# BytesWarning when using python -b or python -bb: ignore the warning
|
| 637 |
+
with warnings.catch_warnings():
|
| 638 |
+
warnings.simplefilter("ignore", BytesWarning)
|
| 639 |
+
|
| 640 |
+
try:
|
| 641 |
+
path_list = env.get('PATH')
|
| 642 |
+
except TypeError:
|
| 643 |
+
path_list = None
|
| 644 |
+
|
| 645 |
+
if supports_bytes_environ:
|
| 646 |
+
try:
|
| 647 |
+
path_listb = env[b'PATH']
|
| 648 |
+
except (KeyError, TypeError):
|
| 649 |
+
pass
|
| 650 |
+
else:
|
| 651 |
+
if path_list is not None:
|
| 652 |
+
raise ValueError(
|
| 653 |
+
"env cannot contain 'PATH' and b'PATH' keys")
|
| 654 |
+
path_list = path_listb
|
| 655 |
+
|
| 656 |
+
if path_list is not None and isinstance(path_list, bytes):
|
| 657 |
+
path_list = fsdecode(path_list)
|
| 658 |
+
|
| 659 |
+
if path_list is None:
|
| 660 |
+
path_list = defpath
|
| 661 |
+
return path_list.split(pathsep)
|
| 662 |
+
|
| 663 |
+
|
| 664 |
+
# Change environ to automatically call putenv() and unsetenv()
|
| 665 |
+
from _collections_abc import MutableMapping, Mapping
|
| 666 |
+
|
| 667 |
+
class _Environ(MutableMapping):
|
| 668 |
+
def __init__(self, data, encodekey, decodekey, encodevalue, decodevalue):
|
| 669 |
+
self.encodekey = encodekey
|
| 670 |
+
self.decodekey = decodekey
|
| 671 |
+
self.encodevalue = encodevalue
|
| 672 |
+
self.decodevalue = decodevalue
|
| 673 |
+
self._data = data
|
| 674 |
+
|
| 675 |
+
def __getitem__(self, key):
|
| 676 |
+
try:
|
| 677 |
+
value = self._data[self.encodekey(key)]
|
| 678 |
+
except KeyError:
|
| 679 |
+
# raise KeyError with the original key value
|
| 680 |
+
raise KeyError(key) from None
|
| 681 |
+
return self.decodevalue(value)
|
| 682 |
+
|
| 683 |
+
def __setitem__(self, key, value):
|
| 684 |
+
key = self.encodekey(key)
|
| 685 |
+
value = self.encodevalue(value)
|
| 686 |
+
putenv(key, value)
|
| 687 |
+
self._data[key] = value
|
| 688 |
+
|
| 689 |
+
def __delitem__(self, key):
|
| 690 |
+
encodedkey = self.encodekey(key)
|
| 691 |
+
unsetenv(encodedkey)
|
| 692 |
+
try:
|
| 693 |
+
del self._data[encodedkey]
|
| 694 |
+
except KeyError:
|
| 695 |
+
# raise KeyError with the original key value
|
| 696 |
+
raise KeyError(key) from None
|
| 697 |
+
|
| 698 |
+
def __iter__(self):
|
| 699 |
+
# list() from dict object is an atomic operation
|
| 700 |
+
keys = list(self._data)
|
| 701 |
+
for key in keys:
|
| 702 |
+
yield self.decodekey(key)
|
| 703 |
+
|
| 704 |
+
def __len__(self):
|
| 705 |
+
return len(self._data)
|
| 706 |
+
|
| 707 |
+
def __repr__(self):
|
| 708 |
+
return 'environ({{{}}})'.format(', '.join(
|
| 709 |
+
('{!r}: {!r}'.format(self.decodekey(key), self.decodevalue(value))
|
| 710 |
+
for key, value in self._data.items())))
|
| 711 |
+
|
| 712 |
+
def copy(self):
|
| 713 |
+
return dict(self)
|
| 714 |
+
|
| 715 |
+
def setdefault(self, key, value):
|
| 716 |
+
if key not in self:
|
| 717 |
+
self[key] = value
|
| 718 |
+
return self[key]
|
| 719 |
+
|
| 720 |
+
def __ior__(self, other):
|
| 721 |
+
self.update(other)
|
| 722 |
+
return self
|
| 723 |
+
|
| 724 |
+
def __or__(self, other):
|
| 725 |
+
if not isinstance(other, Mapping):
|
| 726 |
+
return NotImplemented
|
| 727 |
+
new = dict(self)
|
| 728 |
+
new.update(other)
|
| 729 |
+
return new
|
| 730 |
+
|
| 731 |
+
def __ror__(self, other):
|
| 732 |
+
if not isinstance(other, Mapping):
|
| 733 |
+
return NotImplemented
|
| 734 |
+
new = dict(other)
|
| 735 |
+
new.update(self)
|
| 736 |
+
return new
|
| 737 |
+
|
| 738 |
+
def _createenviron():
|
| 739 |
+
if name == 'nt':
|
| 740 |
+
# Where Env Var Names Must Be UPPERCASE
|
| 741 |
+
def check_str(value):
|
| 742 |
+
if not isinstance(value, str):
|
| 743 |
+
raise TypeError("str expected, not %s" % type(value).__name__)
|
| 744 |
+
return value
|
| 745 |
+
encode = check_str
|
| 746 |
+
decode = str
|
| 747 |
+
def encodekey(key):
|
| 748 |
+
return encode(key).upper()
|
| 749 |
+
data = {}
|
| 750 |
+
for key, value in environ.items():
|
| 751 |
+
data[encodekey(key)] = value
|
| 752 |
+
else:
|
| 753 |
+
# Where Env Var Names Can Be Mixed Case
|
| 754 |
+
encoding = sys.getfilesystemencoding()
|
| 755 |
+
def encode(value):
|
| 756 |
+
if not isinstance(value, str):
|
| 757 |
+
raise TypeError("str expected, not %s" % type(value).__name__)
|
| 758 |
+
return value.encode(encoding, 'surrogateescape')
|
| 759 |
+
def decode(value):
|
| 760 |
+
return value.decode(encoding, 'surrogateescape')
|
| 761 |
+
encodekey = encode
|
| 762 |
+
data = environ
|
| 763 |
+
return _Environ(data,
|
| 764 |
+
encodekey, decode,
|
| 765 |
+
encode, decode)
|
| 766 |
+
|
| 767 |
+
# unicode environ
|
| 768 |
+
environ = _createenviron()
|
| 769 |
+
del _createenviron
|
| 770 |
+
|
| 771 |
+
|
| 772 |
+
def getenv(key, default=None):
|
| 773 |
+
"""Get an environment variable, return None if it doesn't exist.
|
| 774 |
+
The optional second argument can specify an alternate default.
|
| 775 |
+
key, default and the result are str."""
|
| 776 |
+
return environ.get(key, default)
|
| 777 |
+
|
| 778 |
+
supports_bytes_environ = (name != 'nt')
|
| 779 |
+
__all__.extend(("getenv", "supports_bytes_environ"))
|
| 780 |
+
|
| 781 |
+
if supports_bytes_environ:
|
| 782 |
+
def _check_bytes(value):
|
| 783 |
+
if not isinstance(value, bytes):
|
| 784 |
+
raise TypeError("bytes expected, not %s" % type(value).__name__)
|
| 785 |
+
return value
|
| 786 |
+
|
| 787 |
+
# bytes environ
|
| 788 |
+
environb = _Environ(environ._data,
|
| 789 |
+
_check_bytes, bytes,
|
| 790 |
+
_check_bytes, bytes)
|
| 791 |
+
del _check_bytes
|
| 792 |
+
|
| 793 |
+
def getenvb(key, default=None):
|
| 794 |
+
"""Get an environment variable, return None if it doesn't exist.
|
| 795 |
+
The optional second argument can specify an alternate default.
|
| 796 |
+
key, default and the result are bytes."""
|
| 797 |
+
return environb.get(key, default)
|
| 798 |
+
|
| 799 |
+
__all__.extend(("environb", "getenvb"))
|
| 800 |
+
|
| 801 |
+
def _fscodec():
|
| 802 |
+
encoding = sys.getfilesystemencoding()
|
| 803 |
+
errors = sys.getfilesystemencodeerrors()
|
| 804 |
+
|
| 805 |
+
def fsencode(filename):
|
| 806 |
+
"""Encode filename (an os.PathLike, bytes, or str) to the filesystem
|
| 807 |
+
encoding with 'surrogateescape' error handler, return bytes unchanged.
|
| 808 |
+
On Windows, use 'strict' error handler if the file system encoding is
|
| 809 |
+
'mbcs' (which is the default encoding).
|
| 810 |
+
"""
|
| 811 |
+
filename = fspath(filename) # Does type-checking of `filename`.
|
| 812 |
+
if isinstance(filename, str):
|
| 813 |
+
return filename.encode(encoding, errors)
|
| 814 |
+
else:
|
| 815 |
+
return filename
|
| 816 |
+
|
| 817 |
+
def fsdecode(filename):
|
| 818 |
+
"""Decode filename (an os.PathLike, bytes, or str) from the filesystem
|
| 819 |
+
encoding with 'surrogateescape' error handler, return str unchanged. On
|
| 820 |
+
Windows, use 'strict' error handler if the file system encoding is
|
| 821 |
+
'mbcs' (which is the default encoding).
|
| 822 |
+
"""
|
| 823 |
+
filename = fspath(filename) # Does type-checking of `filename`.
|
| 824 |
+
if isinstance(filename, bytes):
|
| 825 |
+
return filename.decode(encoding, errors)
|
| 826 |
+
else:
|
| 827 |
+
return filename
|
| 828 |
+
|
| 829 |
+
return fsencode, fsdecode
|
| 830 |
+
|
| 831 |
+
fsencode, fsdecode = _fscodec()
|
| 832 |
+
del _fscodec
|
| 833 |
+
|
| 834 |
+
# Supply spawn*() (probably only for Unix)
|
| 835 |
+
if _exists("fork") and not _exists("spawnv") and _exists("execv"):
|
| 836 |
+
|
| 837 |
+
P_WAIT = 0
|
| 838 |
+
P_NOWAIT = P_NOWAITO = 1
|
| 839 |
+
|
| 840 |
+
__all__.extend(["P_WAIT", "P_NOWAIT", "P_NOWAITO"])
|
| 841 |
+
|
| 842 |
+
# XXX Should we support P_DETACH? I suppose it could fork()**2
|
| 843 |
+
# and close the std I/O streams. Also, P_OVERLAY is the same
|
| 844 |
+
# as execv*()?
|
| 845 |
+
|
| 846 |
+
def _spawnvef(mode, file, args, env, func):
|
| 847 |
+
# Internal helper; func is the exec*() function to use
|
| 848 |
+
if not isinstance(args, (tuple, list)):
|
| 849 |
+
raise TypeError('argv must be a tuple or a list')
|
| 850 |
+
if not args or not args[0]:
|
| 851 |
+
raise ValueError('argv first element cannot be empty')
|
| 852 |
+
pid = fork()
|
| 853 |
+
if not pid:
|
| 854 |
+
# Child
|
| 855 |
+
try:
|
| 856 |
+
if env is None:
|
| 857 |
+
func(file, args)
|
| 858 |
+
else:
|
| 859 |
+
func(file, args, env)
|
| 860 |
+
except:
|
| 861 |
+
_exit(127)
|
| 862 |
+
else:
|
| 863 |
+
# Parent
|
| 864 |
+
if mode == P_NOWAIT:
|
| 865 |
+
return pid # Caller is responsible for waiting!
|
| 866 |
+
while 1:
|
| 867 |
+
wpid, sts = waitpid(pid, 0)
|
| 868 |
+
if WIFSTOPPED(sts):
|
| 869 |
+
continue
|
| 870 |
+
|
| 871 |
+
return waitstatus_to_exitcode(sts)
|
| 872 |
+
|
| 873 |
+
def spawnv(mode, file, args):
|
| 874 |
+
"""spawnv(mode, file, args) -> integer
|
| 875 |
+
|
| 876 |
+
Execute file with arguments from args in a subprocess.
|
| 877 |
+
If mode == P_NOWAIT return the pid of the process.
|
| 878 |
+
If mode == P_WAIT return the process's exit code if it exits normally;
|
| 879 |
+
otherwise return -SIG, where SIG is the signal that killed it. """
|
| 880 |
+
return _spawnvef(mode, file, args, None, execv)
|
| 881 |
+
|
| 882 |
+
def spawnve(mode, file, args, env):
|
| 883 |
+
"""spawnve(mode, file, args, env) -> integer
|
| 884 |
+
|
| 885 |
+
Execute file with arguments from args in a subprocess with the
|
| 886 |
+
specified environment.
|
| 887 |
+
If mode == P_NOWAIT return the pid of the process.
|
| 888 |
+
If mode == P_WAIT return the process's exit code if it exits normally;
|
| 889 |
+
otherwise return -SIG, where SIG is the signal that killed it. """
|
| 890 |
+
return _spawnvef(mode, file, args, env, execve)
|
| 891 |
+
|
| 892 |
+
# Note: spawnvp[e] isn't currently supported on Windows
|
| 893 |
+
|
| 894 |
+
def spawnvp(mode, file, args):
|
| 895 |
+
"""spawnvp(mode, file, args) -> integer
|
| 896 |
+
|
| 897 |
+
Execute file (which is looked for along $PATH) with arguments from
|
| 898 |
+
args in a subprocess.
|
| 899 |
+
If mode == P_NOWAIT return the pid of the process.
|
| 900 |
+
If mode == P_WAIT return the process's exit code if it exits normally;
|
| 901 |
+
otherwise return -SIG, where SIG is the signal that killed it. """
|
| 902 |
+
return _spawnvef(mode, file, args, None, execvp)
|
| 903 |
+
|
| 904 |
+
def spawnvpe(mode, file, args, env):
|
| 905 |
+
"""spawnvpe(mode, file, args, env) -> integer
|
| 906 |
+
|
| 907 |
+
Execute file (which is looked for along $PATH) with arguments from
|
| 908 |
+
args in a subprocess with the supplied environment.
|
| 909 |
+
If mode == P_NOWAIT return the pid of the process.
|
| 910 |
+
If mode == P_WAIT return the process's exit code if it exits normally;
|
| 911 |
+
otherwise return -SIG, where SIG is the signal that killed it. """
|
| 912 |
+
return _spawnvef(mode, file, args, env, execvpe)
|
| 913 |
+
|
| 914 |
+
|
| 915 |
+
__all__.extend(["spawnv", "spawnve", "spawnvp", "spawnvpe"])
|
| 916 |
+
|
| 917 |
+
|
| 918 |
+
if _exists("spawnv"):
|
| 919 |
+
# These aren't supplied by the basic Windows code
|
| 920 |
+
# but can be easily implemented in Python
|
| 921 |
+
|
| 922 |
+
def spawnl(mode, file, *args):
|
| 923 |
+
"""spawnl(mode, file, *args) -> integer
|
| 924 |
+
|
| 925 |
+
Execute file with arguments from args in a subprocess.
|
| 926 |
+
If mode == P_NOWAIT return the pid of the process.
|
| 927 |
+
If mode == P_WAIT return the process's exit code if it exits normally;
|
| 928 |
+
otherwise return -SIG, where SIG is the signal that killed it. """
|
| 929 |
+
return spawnv(mode, file, args)
|
| 930 |
+
|
| 931 |
+
def spawnle(mode, file, *args):
|
| 932 |
+
"""spawnle(mode, file, *args, env) -> integer
|
| 933 |
+
|
| 934 |
+
Execute file with arguments from args in a subprocess with the
|
| 935 |
+
supplied environment.
|
| 936 |
+
If mode == P_NOWAIT return the pid of the process.
|
| 937 |
+
If mode == P_WAIT return the process's exit code if it exits normally;
|
| 938 |
+
otherwise return -SIG, where SIG is the signal that killed it. """
|
| 939 |
+
env = args[-1]
|
| 940 |
+
return spawnve(mode, file, args[:-1], env)
|
| 941 |
+
|
| 942 |
+
|
| 943 |
+
__all__.extend(["spawnl", "spawnle"])
|
| 944 |
+
|
| 945 |
+
|
| 946 |
+
if _exists("spawnvp"):
|
| 947 |
+
# At the moment, Windows doesn't implement spawnvp[e],
|
| 948 |
+
# so it won't have spawnlp[e] either.
|
| 949 |
+
def spawnlp(mode, file, *args):
|
| 950 |
+
"""spawnlp(mode, file, *args) -> integer
|
| 951 |
+
|
| 952 |
+
Execute file (which is looked for along $PATH) with arguments from
|
| 953 |
+
args in a subprocess with the supplied environment.
|
| 954 |
+
If mode == P_NOWAIT return the pid of the process.
|
| 955 |
+
If mode == P_WAIT return the process's exit code if it exits normally;
|
| 956 |
+
otherwise return -SIG, where SIG is the signal that killed it. """
|
| 957 |
+
return spawnvp(mode, file, args)
|
| 958 |
+
|
| 959 |
+
def spawnlpe(mode, file, *args):
|
| 960 |
+
"""spawnlpe(mode, file, *args, env) -> integer
|
| 961 |
+
|
| 962 |
+
Execute file (which is looked for along $PATH) with arguments from
|
| 963 |
+
args in a subprocess with the supplied environment.
|
| 964 |
+
If mode == P_NOWAIT return the pid of the process.
|
| 965 |
+
If mode == P_WAIT return the process's exit code if it exits normally;
|
| 966 |
+
otherwise return -SIG, where SIG is the signal that killed it. """
|
| 967 |
+
env = args[-1]
|
| 968 |
+
return spawnvpe(mode, file, args[:-1], env)
|
| 969 |
+
|
| 970 |
+
|
| 971 |
+
__all__.extend(["spawnlp", "spawnlpe"])
|
| 972 |
+
|
| 973 |
+
# VxWorks has no user space shell provided. As a result, running
|
| 974 |
+
# command in a shell can't be supported.
|
| 975 |
+
if sys.platform != 'vxworks':
|
| 976 |
+
# Supply os.popen()
|
| 977 |
+
def popen(cmd, mode="r", buffering=-1):
|
| 978 |
+
if not isinstance(cmd, str):
|
| 979 |
+
raise TypeError("invalid cmd type (%s, expected string)" % type(cmd))
|
| 980 |
+
if mode not in ("r", "w"):
|
| 981 |
+
raise ValueError("invalid mode %r" % mode)
|
| 982 |
+
if buffering == 0 or buffering is None:
|
| 983 |
+
raise ValueError("popen() does not support unbuffered streams")
|
| 984 |
+
import subprocess, io
|
| 985 |
+
if mode == "r":
|
| 986 |
+
proc = subprocess.Popen(cmd,
|
| 987 |
+
shell=True, text=True,
|
| 988 |
+
stdout=subprocess.PIPE,
|
| 989 |
+
bufsize=buffering)
|
| 990 |
+
return _wrap_close(proc.stdout, proc)
|
| 991 |
+
else:
|
| 992 |
+
proc = subprocess.Popen(cmd,
|
| 993 |
+
shell=True, text=True,
|
| 994 |
+
stdin=subprocess.PIPE,
|
| 995 |
+
bufsize=buffering)
|
| 996 |
+
return _wrap_close(proc.stdin, proc)
|
| 997 |
+
|
| 998 |
+
# Helper for popen() -- a proxy for a file whose close waits for the process
|
| 999 |
+
class _wrap_close:
|
| 1000 |
+
def __init__(self, stream, proc):
|
| 1001 |
+
self._stream = stream
|
| 1002 |
+
self._proc = proc
|
| 1003 |
+
def close(self):
|
| 1004 |
+
self._stream.close()
|
| 1005 |
+
returncode = self._proc.wait()
|
| 1006 |
+
if returncode == 0:
|
| 1007 |
+
return None
|
| 1008 |
+
if name == 'nt':
|
| 1009 |
+
return returncode
|
| 1010 |
+
else:
|
| 1011 |
+
return returncode << 8 # Shift left to match old behavior
|
| 1012 |
+
def __enter__(self):
|
| 1013 |
+
return self
|
| 1014 |
+
def __exit__(self, *args):
|
| 1015 |
+
self.close()
|
| 1016 |
+
def __getattr__(self, name):
|
| 1017 |
+
return getattr(self._stream, name)
|
| 1018 |
+
def __iter__(self):
|
| 1019 |
+
return iter(self._stream)
|
| 1020 |
+
|
| 1021 |
+
__all__.append("popen")
|
| 1022 |
+
|
| 1023 |
+
# Supply os.fdopen()
|
| 1024 |
+
def fdopen(fd, mode="r", buffering=-1, encoding=None, *args, **kwargs):
|
| 1025 |
+
if not isinstance(fd, int):
|
| 1026 |
+
raise TypeError("invalid fd type (%s, expected integer)" % type(fd))
|
| 1027 |
+
import io
|
| 1028 |
+
if "b" not in mode:
|
| 1029 |
+
encoding = io.text_encoding(encoding)
|
| 1030 |
+
return io.open(fd, mode, buffering, encoding, *args, **kwargs)
|
| 1031 |
+
|
| 1032 |
+
|
| 1033 |
+
# For testing purposes, make sure the function is available when the C
|
| 1034 |
+
# implementation exists.
|
| 1035 |
+
def _fspath(path):
|
| 1036 |
+
"""Return the path representation of a path-like object.
|
| 1037 |
+
|
| 1038 |
+
If str or bytes is passed in, it is returned unchanged. Otherwise the
|
| 1039 |
+
os.PathLike interface is used to get the path representation. If the
|
| 1040 |
+
path representation is not str or bytes, TypeError is raised. If the
|
| 1041 |
+
provided path is not str, bytes, or os.PathLike, TypeError is raised.
|
| 1042 |
+
"""
|
| 1043 |
+
if isinstance(path, (str, bytes)):
|
| 1044 |
+
return path
|
| 1045 |
+
|
| 1046 |
+
# Work from the object's type to match method resolution of other magic
|
| 1047 |
+
# methods.
|
| 1048 |
+
path_type = type(path)
|
| 1049 |
+
try:
|
| 1050 |
+
path_repr = path_type.__fspath__(path)
|
| 1051 |
+
except AttributeError:
|
| 1052 |
+
if hasattr(path_type, '__fspath__'):
|
| 1053 |
+
raise
|
| 1054 |
+
else:
|
| 1055 |
+
raise TypeError("expected str, bytes or os.PathLike object, "
|
| 1056 |
+
"not " + path_type.__name__)
|
| 1057 |
+
if isinstance(path_repr, (str, bytes)):
|
| 1058 |
+
return path_repr
|
| 1059 |
+
else:
|
| 1060 |
+
raise TypeError("expected {}.__fspath__() to return str or bytes, "
|
| 1061 |
+
"not {}".format(path_type.__name__,
|
| 1062 |
+
type(path_repr).__name__))
|
| 1063 |
+
|
| 1064 |
+
# If there is no C implementation, make the pure Python version the
|
| 1065 |
+
# implementation as transparently as possible.
|
| 1066 |
+
if not _exists('fspath'):
|
| 1067 |
+
fspath = _fspath
|
| 1068 |
+
fspath.__name__ = "fspath"
|
| 1069 |
+
|
| 1070 |
+
|
| 1071 |
+
class PathLike(abc.ABC):
|
| 1072 |
+
|
| 1073 |
+
"""Abstract base class for implementing the file system path protocol."""
|
| 1074 |
+
|
| 1075 |
+
@abc.abstractmethod
|
| 1076 |
+
def __fspath__(self):
|
| 1077 |
+
"""Return the file system path representation of the object."""
|
| 1078 |
+
raise NotImplementedError
|
| 1079 |
+
|
| 1080 |
+
@classmethod
|
| 1081 |
+
def __subclasshook__(cls, subclass):
|
| 1082 |
+
if cls is PathLike:
|
| 1083 |
+
return _check_methods(subclass, '__fspath__')
|
| 1084 |
+
return NotImplemented
|
| 1085 |
+
|
| 1086 |
+
__class_getitem__ = classmethod(GenericAlias)
|
| 1087 |
+
|
| 1088 |
+
|
| 1089 |
+
if name == 'nt':
|
| 1090 |
+
class _AddedDllDirectory:
|
| 1091 |
+
def __init__(self, path, cookie, remove_dll_directory):
|
| 1092 |
+
self.path = path
|
| 1093 |
+
self._cookie = cookie
|
| 1094 |
+
self._remove_dll_directory = remove_dll_directory
|
| 1095 |
+
def close(self):
|
| 1096 |
+
self._remove_dll_directory(self._cookie)
|
| 1097 |
+
self.path = None
|
| 1098 |
+
def __enter__(self):
|
| 1099 |
+
return self
|
| 1100 |
+
def __exit__(self, *args):
|
| 1101 |
+
self.close()
|
| 1102 |
+
def __repr__(self):
|
| 1103 |
+
if self.path:
|
| 1104 |
+
return "<AddedDllDirectory({!r})>".format(self.path)
|
| 1105 |
+
return "<AddedDllDirectory()>"
|
| 1106 |
+
|
| 1107 |
+
def add_dll_directory(path):
|
| 1108 |
+
"""Add a path to the DLL search path.
|
| 1109 |
+
|
| 1110 |
+
This search path is used when resolving dependencies for imported
|
| 1111 |
+
extension modules (the module itself is resolved through sys.path),
|
| 1112 |
+
and also by ctypes.
|
| 1113 |
+
|
| 1114 |
+
Remove the directory by calling close() on the returned object or
|
| 1115 |
+
using it in a with statement.
|
| 1116 |
+
"""
|
| 1117 |
+
import nt
|
| 1118 |
+
cookie = nt._add_dll_directory(path)
|
| 1119 |
+
return _AddedDllDirectory(
|
| 1120 |
+
path,
|
| 1121 |
+
cookie,
|
| 1122 |
+
nt._remove_dll_directory
|
| 1123 |
+
)
|
llava/lib/python3.10/pathlib.py
ADDED
|
@@ -0,0 +1,1461 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import fnmatch
|
| 2 |
+
import functools
|
| 3 |
+
import io
|
| 4 |
+
import ntpath
|
| 5 |
+
import os
|
| 6 |
+
import posixpath
|
| 7 |
+
import re
|
| 8 |
+
import sys
|
| 9 |
+
import warnings
|
| 10 |
+
from _collections_abc import Sequence
|
| 11 |
+
from errno import EINVAL, ENOENT, ENOTDIR, EBADF, ELOOP
|
| 12 |
+
from operator import attrgetter
|
| 13 |
+
from stat import S_ISDIR, S_ISLNK, S_ISREG, S_ISSOCK, S_ISBLK, S_ISCHR, S_ISFIFO
|
| 14 |
+
from urllib.parse import quote_from_bytes as urlquote_from_bytes
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
__all__ = [
|
| 18 |
+
"PurePath", "PurePosixPath", "PureWindowsPath",
|
| 19 |
+
"Path", "PosixPath", "WindowsPath",
|
| 20 |
+
]
|
| 21 |
+
|
| 22 |
+
#
|
| 23 |
+
# Internals
|
| 24 |
+
#
|
| 25 |
+
|
| 26 |
+
_WINERROR_NOT_READY = 21 # drive exists but is not accessible
|
| 27 |
+
_WINERROR_INVALID_NAME = 123 # fix for bpo-35306
|
| 28 |
+
_WINERROR_CANT_RESOLVE_FILENAME = 1921 # broken symlink pointing to itself
|
| 29 |
+
|
| 30 |
+
# EBADF - guard against macOS `stat` throwing EBADF
|
| 31 |
+
_IGNORED_ERROS = (ENOENT, ENOTDIR, EBADF, ELOOP)
|
| 32 |
+
|
| 33 |
+
_IGNORED_WINERRORS = (
|
| 34 |
+
_WINERROR_NOT_READY,
|
| 35 |
+
_WINERROR_INVALID_NAME,
|
| 36 |
+
_WINERROR_CANT_RESOLVE_FILENAME)
|
| 37 |
+
|
| 38 |
+
def _ignore_error(exception):
|
| 39 |
+
return (getattr(exception, 'errno', None) in _IGNORED_ERROS or
|
| 40 |
+
getattr(exception, 'winerror', None) in _IGNORED_WINERRORS)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def _is_wildcard_pattern(pat):
|
| 44 |
+
# Whether this pattern needs actual matching using fnmatch, or can
|
| 45 |
+
# be looked up directly as a file.
|
| 46 |
+
return "*" in pat or "?" in pat or "[" in pat
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
class _Flavour(object):
|
| 50 |
+
"""A flavour implements a particular (platform-specific) set of path
|
| 51 |
+
semantics."""
|
| 52 |
+
|
| 53 |
+
def __init__(self):
|
| 54 |
+
self.join = self.sep.join
|
| 55 |
+
|
| 56 |
+
def parse_parts(self, parts):
|
| 57 |
+
parsed = []
|
| 58 |
+
sep = self.sep
|
| 59 |
+
altsep = self.altsep
|
| 60 |
+
drv = root = ''
|
| 61 |
+
it = reversed(parts)
|
| 62 |
+
for part in it:
|
| 63 |
+
if not part:
|
| 64 |
+
continue
|
| 65 |
+
if altsep:
|
| 66 |
+
part = part.replace(altsep, sep)
|
| 67 |
+
drv, root, rel = self.splitroot(part)
|
| 68 |
+
if sep in rel:
|
| 69 |
+
for x in reversed(rel.split(sep)):
|
| 70 |
+
if x and x != '.':
|
| 71 |
+
parsed.append(sys.intern(x))
|
| 72 |
+
else:
|
| 73 |
+
if rel and rel != '.':
|
| 74 |
+
parsed.append(sys.intern(rel))
|
| 75 |
+
if drv or root:
|
| 76 |
+
if not drv:
|
| 77 |
+
# If no drive is present, try to find one in the previous
|
| 78 |
+
# parts. This makes the result of parsing e.g.
|
| 79 |
+
# ("C:", "/", "a") reasonably intuitive.
|
| 80 |
+
for part in it:
|
| 81 |
+
if not part:
|
| 82 |
+
continue
|
| 83 |
+
if altsep:
|
| 84 |
+
part = part.replace(altsep, sep)
|
| 85 |
+
drv = self.splitroot(part)[0]
|
| 86 |
+
if drv:
|
| 87 |
+
break
|
| 88 |
+
break
|
| 89 |
+
if drv or root:
|
| 90 |
+
parsed.append(drv + root)
|
| 91 |
+
parsed.reverse()
|
| 92 |
+
return drv, root, parsed
|
| 93 |
+
|
| 94 |
+
def join_parsed_parts(self, drv, root, parts, drv2, root2, parts2):
|
| 95 |
+
"""
|
| 96 |
+
Join the two paths represented by the respective
|
| 97 |
+
(drive, root, parts) tuples. Return a new (drive, root, parts) tuple.
|
| 98 |
+
"""
|
| 99 |
+
if root2:
|
| 100 |
+
if not drv2 and drv:
|
| 101 |
+
return drv, root2, [drv + root2] + parts2[1:]
|
| 102 |
+
elif drv2:
|
| 103 |
+
if drv2 == drv or self.casefold(drv2) == self.casefold(drv):
|
| 104 |
+
# Same drive => second path is relative to the first
|
| 105 |
+
return drv, root, parts + parts2[1:]
|
| 106 |
+
else:
|
| 107 |
+
# Second path is non-anchored (common case)
|
| 108 |
+
return drv, root, parts + parts2
|
| 109 |
+
return drv2, root2, parts2
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
class _WindowsFlavour(_Flavour):
|
| 113 |
+
# Reference for Windows paths can be found at
|
| 114 |
+
# http://msdn.microsoft.com/en-us/library/aa365247%28v=vs.85%29.aspx
|
| 115 |
+
|
| 116 |
+
sep = '\\'
|
| 117 |
+
altsep = '/'
|
| 118 |
+
has_drv = True
|
| 119 |
+
pathmod = ntpath
|
| 120 |
+
|
| 121 |
+
is_supported = (os.name == 'nt')
|
| 122 |
+
|
| 123 |
+
drive_letters = set('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
|
| 124 |
+
ext_namespace_prefix = '\\\\?\\'
|
| 125 |
+
|
| 126 |
+
reserved_names = (
|
| 127 |
+
{'CON', 'PRN', 'AUX', 'NUL', 'CONIN$', 'CONOUT$'} |
|
| 128 |
+
{'COM%s' % c for c in '123456789\xb9\xb2\xb3'} |
|
| 129 |
+
{'LPT%s' % c for c in '123456789\xb9\xb2\xb3'}
|
| 130 |
+
)
|
| 131 |
+
|
| 132 |
+
# Interesting findings about extended paths:
|
| 133 |
+
# * '\\?\c:\a' is an extended path, which bypasses normal Windows API
|
| 134 |
+
# path processing. Thus relative paths are not resolved and slash is not
|
| 135 |
+
# translated to backslash. It has the native NT path limit of 32767
|
| 136 |
+
# characters, but a bit less after resolving device symbolic links,
|
| 137 |
+
# such as '\??\C:' => '\Device\HarddiskVolume2'.
|
| 138 |
+
# * '\\?\c:/a' looks for a device named 'C:/a' because slash is a
|
| 139 |
+
# regular name character in the object namespace.
|
| 140 |
+
# * '\\?\c:\foo/bar' is invalid because '/' is illegal in NT filesystems.
|
| 141 |
+
# The only path separator at the filesystem level is backslash.
|
| 142 |
+
# * '//?/c:\a' and '//?/c:/a' are effectively equivalent to '\\.\c:\a' and
|
| 143 |
+
# thus limited to MAX_PATH.
|
| 144 |
+
# * Prior to Windows 8, ANSI API bytes paths are limited to MAX_PATH,
|
| 145 |
+
# even with the '\\?\' prefix.
|
| 146 |
+
|
| 147 |
+
def splitroot(self, part, sep=sep):
|
| 148 |
+
first = part[0:1]
|
| 149 |
+
second = part[1:2]
|
| 150 |
+
if (second == sep and first == sep):
|
| 151 |
+
# XXX extended paths should also disable the collapsing of "."
|
| 152 |
+
# components (according to MSDN docs).
|
| 153 |
+
prefix, part = self._split_extended_path(part)
|
| 154 |
+
first = part[0:1]
|
| 155 |
+
second = part[1:2]
|
| 156 |
+
else:
|
| 157 |
+
prefix = ''
|
| 158 |
+
third = part[2:3]
|
| 159 |
+
if (second == sep and first == sep and third != sep):
|
| 160 |
+
# is a UNC path:
|
| 161 |
+
# vvvvvvvvvvvvvvvvvvvvv root
|
| 162 |
+
# \\machine\mountpoint\directory\etc\...
|
| 163 |
+
# directory ^^^^^^^^^^^^^^
|
| 164 |
+
index = part.find(sep, 2)
|
| 165 |
+
if index != -1:
|
| 166 |
+
index2 = part.find(sep, index + 1)
|
| 167 |
+
# a UNC path can't have two slashes in a row
|
| 168 |
+
# (after the initial two)
|
| 169 |
+
if index2 != index + 1:
|
| 170 |
+
if index2 == -1:
|
| 171 |
+
index2 = len(part)
|
| 172 |
+
if prefix:
|
| 173 |
+
return prefix + part[1:index2], sep, part[index2+1:]
|
| 174 |
+
else:
|
| 175 |
+
return part[:index2], sep, part[index2+1:]
|
| 176 |
+
drv = root = ''
|
| 177 |
+
if second == ':' and first in self.drive_letters:
|
| 178 |
+
drv = part[:2]
|
| 179 |
+
part = part[2:]
|
| 180 |
+
first = third
|
| 181 |
+
if first == sep:
|
| 182 |
+
root = first
|
| 183 |
+
part = part.lstrip(sep)
|
| 184 |
+
return prefix + drv, root, part
|
| 185 |
+
|
| 186 |
+
def casefold(self, s):
|
| 187 |
+
return s.lower()
|
| 188 |
+
|
| 189 |
+
def casefold_parts(self, parts):
|
| 190 |
+
return [p.lower() for p in parts]
|
| 191 |
+
|
| 192 |
+
def compile_pattern(self, pattern):
|
| 193 |
+
return re.compile(fnmatch.translate(pattern), re.IGNORECASE).fullmatch
|
| 194 |
+
|
| 195 |
+
def _split_extended_path(self, s, ext_prefix=ext_namespace_prefix):
|
| 196 |
+
prefix = ''
|
| 197 |
+
if s.startswith(ext_prefix):
|
| 198 |
+
prefix = s[:4]
|
| 199 |
+
s = s[4:]
|
| 200 |
+
if s.startswith('UNC\\'):
|
| 201 |
+
prefix += s[:3]
|
| 202 |
+
s = '\\' + s[3:]
|
| 203 |
+
return prefix, s
|
| 204 |
+
|
| 205 |
+
def is_reserved(self, parts):
|
| 206 |
+
# NOTE: the rules for reserved names seem somewhat complicated
|
| 207 |
+
# (e.g. r"..\NUL" is reserved but not r"foo\NUL" if "foo" does not
|
| 208 |
+
# exist). We err on the side of caution and return True for paths
|
| 209 |
+
# which are not considered reserved by Windows.
|
| 210 |
+
if not parts:
|
| 211 |
+
return False
|
| 212 |
+
if parts[0].startswith('\\\\'):
|
| 213 |
+
# UNC paths are never reserved
|
| 214 |
+
return False
|
| 215 |
+
name = parts[-1].partition('.')[0].partition(':')[0].rstrip(' ')
|
| 216 |
+
return name.upper() in self.reserved_names
|
| 217 |
+
|
| 218 |
+
def make_uri(self, path):
|
| 219 |
+
# Under Windows, file URIs use the UTF-8 encoding.
|
| 220 |
+
drive = path.drive
|
| 221 |
+
if len(drive) == 2 and drive[1] == ':':
|
| 222 |
+
# It's a path on a local drive => 'file:///c:/a/b'
|
| 223 |
+
rest = path.as_posix()[2:].lstrip('/')
|
| 224 |
+
return 'file:///%s/%s' % (
|
| 225 |
+
drive, urlquote_from_bytes(rest.encode('utf-8')))
|
| 226 |
+
else:
|
| 227 |
+
# It's a path on a network drive => 'file://host/share/a/b'
|
| 228 |
+
return 'file:' + urlquote_from_bytes(path.as_posix().encode('utf-8'))
|
| 229 |
+
|
| 230 |
+
|
| 231 |
+
class _PosixFlavour(_Flavour):
|
| 232 |
+
sep = '/'
|
| 233 |
+
altsep = ''
|
| 234 |
+
has_drv = False
|
| 235 |
+
pathmod = posixpath
|
| 236 |
+
|
| 237 |
+
is_supported = (os.name != 'nt')
|
| 238 |
+
|
| 239 |
+
def splitroot(self, part, sep=sep):
|
| 240 |
+
if part and part[0] == sep:
|
| 241 |
+
stripped_part = part.lstrip(sep)
|
| 242 |
+
# According to POSIX path resolution:
|
| 243 |
+
# http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap04.html#tag_04_11
|
| 244 |
+
# "A pathname that begins with two successive slashes may be
|
| 245 |
+
# interpreted in an implementation-defined manner, although more
|
| 246 |
+
# than two leading slashes shall be treated as a single slash".
|
| 247 |
+
if len(part) - len(stripped_part) == 2:
|
| 248 |
+
return '', sep * 2, stripped_part
|
| 249 |
+
else:
|
| 250 |
+
return '', sep, stripped_part
|
| 251 |
+
else:
|
| 252 |
+
return '', '', part
|
| 253 |
+
|
| 254 |
+
def casefold(self, s):
|
| 255 |
+
return s
|
| 256 |
+
|
| 257 |
+
def casefold_parts(self, parts):
|
| 258 |
+
return parts
|
| 259 |
+
|
| 260 |
+
def compile_pattern(self, pattern):
|
| 261 |
+
return re.compile(fnmatch.translate(pattern)).fullmatch
|
| 262 |
+
|
| 263 |
+
def is_reserved(self, parts):
|
| 264 |
+
return False
|
| 265 |
+
|
| 266 |
+
def make_uri(self, path):
|
| 267 |
+
# We represent the path using the local filesystem encoding,
|
| 268 |
+
# for portability to other applications.
|
| 269 |
+
bpath = bytes(path)
|
| 270 |
+
return 'file://' + urlquote_from_bytes(bpath)
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
_windows_flavour = _WindowsFlavour()
|
| 274 |
+
_posix_flavour = _PosixFlavour()
|
| 275 |
+
|
| 276 |
+
|
| 277 |
+
class _Accessor:
|
| 278 |
+
"""An accessor implements a particular (system-specific or not) way of
|
| 279 |
+
accessing paths on the filesystem."""
|
| 280 |
+
|
| 281 |
+
|
| 282 |
+
class _NormalAccessor(_Accessor):
|
| 283 |
+
|
| 284 |
+
stat = os.stat
|
| 285 |
+
|
| 286 |
+
open = io.open
|
| 287 |
+
|
| 288 |
+
listdir = os.listdir
|
| 289 |
+
|
| 290 |
+
scandir = os.scandir
|
| 291 |
+
|
| 292 |
+
chmod = os.chmod
|
| 293 |
+
|
| 294 |
+
mkdir = os.mkdir
|
| 295 |
+
|
| 296 |
+
unlink = os.unlink
|
| 297 |
+
|
| 298 |
+
if hasattr(os, "link"):
|
| 299 |
+
link = os.link
|
| 300 |
+
else:
|
| 301 |
+
def link(self, src, dst):
|
| 302 |
+
raise NotImplementedError("os.link() not available on this system")
|
| 303 |
+
|
| 304 |
+
rmdir = os.rmdir
|
| 305 |
+
|
| 306 |
+
rename = os.rename
|
| 307 |
+
|
| 308 |
+
replace = os.replace
|
| 309 |
+
|
| 310 |
+
if hasattr(os, "symlink"):
|
| 311 |
+
symlink = os.symlink
|
| 312 |
+
else:
|
| 313 |
+
def symlink(self, src, dst, target_is_directory=False):
|
| 314 |
+
raise NotImplementedError("os.symlink() not available on this system")
|
| 315 |
+
|
| 316 |
+
def touch(self, path, mode=0o666, exist_ok=True):
|
| 317 |
+
if exist_ok:
|
| 318 |
+
# First try to bump modification time
|
| 319 |
+
# Implementation note: GNU touch uses the UTIME_NOW option of
|
| 320 |
+
# the utimensat() / futimens() functions.
|
| 321 |
+
try:
|
| 322 |
+
os.utime(path, None)
|
| 323 |
+
except OSError:
|
| 324 |
+
# Avoid exception chaining
|
| 325 |
+
pass
|
| 326 |
+
else:
|
| 327 |
+
return
|
| 328 |
+
flags = os.O_CREAT | os.O_WRONLY
|
| 329 |
+
if not exist_ok:
|
| 330 |
+
flags |= os.O_EXCL
|
| 331 |
+
fd = os.open(path, flags, mode)
|
| 332 |
+
os.close(fd)
|
| 333 |
+
|
| 334 |
+
if hasattr(os, "readlink"):
|
| 335 |
+
readlink = os.readlink
|
| 336 |
+
else:
|
| 337 |
+
def readlink(self, path):
|
| 338 |
+
raise NotImplementedError("os.readlink() not available on this system")
|
| 339 |
+
|
| 340 |
+
def owner(self, path):
|
| 341 |
+
try:
|
| 342 |
+
import pwd
|
| 343 |
+
return pwd.getpwuid(self.stat(path).st_uid).pw_name
|
| 344 |
+
except ImportError:
|
| 345 |
+
raise NotImplementedError("Path.owner() is unsupported on this system")
|
| 346 |
+
|
| 347 |
+
def group(self, path):
|
| 348 |
+
try:
|
| 349 |
+
import grp
|
| 350 |
+
return grp.getgrgid(self.stat(path).st_gid).gr_name
|
| 351 |
+
except ImportError:
|
| 352 |
+
raise NotImplementedError("Path.group() is unsupported on this system")
|
| 353 |
+
|
| 354 |
+
getcwd = os.getcwd
|
| 355 |
+
|
| 356 |
+
expanduser = staticmethod(os.path.expanduser)
|
| 357 |
+
|
| 358 |
+
realpath = staticmethod(os.path.realpath)
|
| 359 |
+
|
| 360 |
+
|
| 361 |
+
_normal_accessor = _NormalAccessor()
|
| 362 |
+
|
| 363 |
+
|
| 364 |
+
#
|
| 365 |
+
# Globbing helpers
|
| 366 |
+
#
|
| 367 |
+
|
| 368 |
+
def _make_selector(pattern_parts, flavour):
|
| 369 |
+
pat = pattern_parts[0]
|
| 370 |
+
child_parts = pattern_parts[1:]
|
| 371 |
+
if pat == '**':
|
| 372 |
+
cls = _RecursiveWildcardSelector
|
| 373 |
+
elif '**' in pat:
|
| 374 |
+
raise ValueError("Invalid pattern: '**' can only be an entire path component")
|
| 375 |
+
elif _is_wildcard_pattern(pat):
|
| 376 |
+
cls = _WildcardSelector
|
| 377 |
+
else:
|
| 378 |
+
cls = _PreciseSelector
|
| 379 |
+
return cls(pat, child_parts, flavour)
|
| 380 |
+
|
| 381 |
+
if hasattr(functools, "lru_cache"):
|
| 382 |
+
_make_selector = functools.lru_cache()(_make_selector)
|
| 383 |
+
|
| 384 |
+
|
| 385 |
+
class _Selector:
|
| 386 |
+
"""A selector matches a specific glob pattern part against the children
|
| 387 |
+
of a given path."""
|
| 388 |
+
|
| 389 |
+
def __init__(self, child_parts, flavour):
|
| 390 |
+
self.child_parts = child_parts
|
| 391 |
+
if child_parts:
|
| 392 |
+
self.successor = _make_selector(child_parts, flavour)
|
| 393 |
+
self.dironly = True
|
| 394 |
+
else:
|
| 395 |
+
self.successor = _TerminatingSelector()
|
| 396 |
+
self.dironly = False
|
| 397 |
+
|
| 398 |
+
def select_from(self, parent_path):
|
| 399 |
+
"""Iterate over all child paths of `parent_path` matched by this
|
| 400 |
+
selector. This can contain parent_path itself."""
|
| 401 |
+
path_cls = type(parent_path)
|
| 402 |
+
is_dir = path_cls.is_dir
|
| 403 |
+
exists = path_cls.exists
|
| 404 |
+
scandir = parent_path._accessor.scandir
|
| 405 |
+
if not is_dir(parent_path):
|
| 406 |
+
return iter([])
|
| 407 |
+
return self._select_from(parent_path, is_dir, exists, scandir)
|
| 408 |
+
|
| 409 |
+
|
| 410 |
+
class _TerminatingSelector:
|
| 411 |
+
|
| 412 |
+
def _select_from(self, parent_path, is_dir, exists, scandir):
|
| 413 |
+
yield parent_path
|
| 414 |
+
|
| 415 |
+
|
| 416 |
+
class _PreciseSelector(_Selector):
|
| 417 |
+
|
| 418 |
+
def __init__(self, name, child_parts, flavour):
|
| 419 |
+
self.name = name
|
| 420 |
+
_Selector.__init__(self, child_parts, flavour)
|
| 421 |
+
|
| 422 |
+
def _select_from(self, parent_path, is_dir, exists, scandir):
|
| 423 |
+
try:
|
| 424 |
+
path = parent_path._make_child_relpath(self.name)
|
| 425 |
+
if (is_dir if self.dironly else exists)(path):
|
| 426 |
+
for p in self.successor._select_from(path, is_dir, exists, scandir):
|
| 427 |
+
yield p
|
| 428 |
+
except PermissionError:
|
| 429 |
+
return
|
| 430 |
+
|
| 431 |
+
|
| 432 |
+
class _WildcardSelector(_Selector):
|
| 433 |
+
|
| 434 |
+
def __init__(self, pat, child_parts, flavour):
|
| 435 |
+
self.match = flavour.compile_pattern(pat)
|
| 436 |
+
_Selector.__init__(self, child_parts, flavour)
|
| 437 |
+
|
| 438 |
+
def _select_from(self, parent_path, is_dir, exists, scandir):
|
| 439 |
+
try:
|
| 440 |
+
with scandir(parent_path) as scandir_it:
|
| 441 |
+
entries = list(scandir_it)
|
| 442 |
+
for entry in entries:
|
| 443 |
+
if self.dironly:
|
| 444 |
+
try:
|
| 445 |
+
# "entry.is_dir()" can raise PermissionError
|
| 446 |
+
# in some cases (see bpo-38894), which is not
|
| 447 |
+
# among the errors ignored by _ignore_error()
|
| 448 |
+
if not entry.is_dir():
|
| 449 |
+
continue
|
| 450 |
+
except OSError as e:
|
| 451 |
+
if not _ignore_error(e):
|
| 452 |
+
raise
|
| 453 |
+
continue
|
| 454 |
+
name = entry.name
|
| 455 |
+
if self.match(name):
|
| 456 |
+
path = parent_path._make_child_relpath(name)
|
| 457 |
+
for p in self.successor._select_from(path, is_dir, exists, scandir):
|
| 458 |
+
yield p
|
| 459 |
+
except PermissionError:
|
| 460 |
+
return
|
| 461 |
+
|
| 462 |
+
|
| 463 |
+
class _RecursiveWildcardSelector(_Selector):
|
| 464 |
+
|
| 465 |
+
def __init__(self, pat, child_parts, flavour):
|
| 466 |
+
_Selector.__init__(self, child_parts, flavour)
|
| 467 |
+
|
| 468 |
+
def _iterate_directories(self, parent_path, is_dir, scandir):
|
| 469 |
+
yield parent_path
|
| 470 |
+
try:
|
| 471 |
+
with scandir(parent_path) as scandir_it:
|
| 472 |
+
entries = list(scandir_it)
|
| 473 |
+
for entry in entries:
|
| 474 |
+
entry_is_dir = False
|
| 475 |
+
try:
|
| 476 |
+
entry_is_dir = entry.is_dir()
|
| 477 |
+
except OSError as e:
|
| 478 |
+
if not _ignore_error(e):
|
| 479 |
+
raise
|
| 480 |
+
if entry_is_dir and not entry.is_symlink():
|
| 481 |
+
path = parent_path._make_child_relpath(entry.name)
|
| 482 |
+
for p in self._iterate_directories(path, is_dir, scandir):
|
| 483 |
+
yield p
|
| 484 |
+
except PermissionError:
|
| 485 |
+
return
|
| 486 |
+
|
| 487 |
+
def _select_from(self, parent_path, is_dir, exists, scandir):
|
| 488 |
+
try:
|
| 489 |
+
yielded = set()
|
| 490 |
+
try:
|
| 491 |
+
successor_select = self.successor._select_from
|
| 492 |
+
for starting_point in self._iterate_directories(parent_path, is_dir, scandir):
|
| 493 |
+
for p in successor_select(starting_point, is_dir, exists, scandir):
|
| 494 |
+
if p not in yielded:
|
| 495 |
+
yield p
|
| 496 |
+
yielded.add(p)
|
| 497 |
+
finally:
|
| 498 |
+
yielded.clear()
|
| 499 |
+
except PermissionError:
|
| 500 |
+
return
|
| 501 |
+
|
| 502 |
+
|
| 503 |
+
#
|
| 504 |
+
# Public API
|
| 505 |
+
#
|
| 506 |
+
|
| 507 |
+
class _PathParents(Sequence):
|
| 508 |
+
"""This object provides sequence-like access to the logical ancestors
|
| 509 |
+
of a path. Don't try to construct it yourself."""
|
| 510 |
+
__slots__ = ('_pathcls', '_drv', '_root', '_parts')
|
| 511 |
+
|
| 512 |
+
def __init__(self, path):
|
| 513 |
+
# We don't store the instance to avoid reference cycles
|
| 514 |
+
self._pathcls = type(path)
|
| 515 |
+
self._drv = path._drv
|
| 516 |
+
self._root = path._root
|
| 517 |
+
self._parts = path._parts
|
| 518 |
+
|
| 519 |
+
def __len__(self):
|
| 520 |
+
if self._drv or self._root:
|
| 521 |
+
return len(self._parts) - 1
|
| 522 |
+
else:
|
| 523 |
+
return len(self._parts)
|
| 524 |
+
|
| 525 |
+
def __getitem__(self, idx):
|
| 526 |
+
if isinstance(idx, slice):
|
| 527 |
+
return tuple(self[i] for i in range(*idx.indices(len(self))))
|
| 528 |
+
|
| 529 |
+
if idx >= len(self) or idx < -len(self):
|
| 530 |
+
raise IndexError(idx)
|
| 531 |
+
if idx < 0:
|
| 532 |
+
idx += len(self)
|
| 533 |
+
return self._pathcls._from_parsed_parts(self._drv, self._root,
|
| 534 |
+
self._parts[:-idx - 1])
|
| 535 |
+
|
| 536 |
+
def __repr__(self):
|
| 537 |
+
return "<{}.parents>".format(self._pathcls.__name__)
|
| 538 |
+
|
| 539 |
+
|
| 540 |
+
class PurePath(object):
|
| 541 |
+
"""Base class for manipulating paths without I/O.
|
| 542 |
+
|
| 543 |
+
PurePath represents a filesystem path and offers operations which
|
| 544 |
+
don't imply any actual filesystem I/O. Depending on your system,
|
| 545 |
+
instantiating a PurePath will return either a PurePosixPath or a
|
| 546 |
+
PureWindowsPath object. You can also instantiate either of these classes
|
| 547 |
+
directly, regardless of your system.
|
| 548 |
+
"""
|
| 549 |
+
__slots__ = (
|
| 550 |
+
'_drv', '_root', '_parts',
|
| 551 |
+
'_str', '_hash', '_pparts', '_cached_cparts',
|
| 552 |
+
)
|
| 553 |
+
|
| 554 |
+
def __new__(cls, *args):
|
| 555 |
+
"""Construct a PurePath from one or several strings and or existing
|
| 556 |
+
PurePath objects. The strings and path objects are combined so as
|
| 557 |
+
to yield a canonicalized path, which is incorporated into the
|
| 558 |
+
new PurePath object.
|
| 559 |
+
"""
|
| 560 |
+
if cls is PurePath:
|
| 561 |
+
cls = PureWindowsPath if os.name == 'nt' else PurePosixPath
|
| 562 |
+
return cls._from_parts(args)
|
| 563 |
+
|
| 564 |
+
def __reduce__(self):
|
| 565 |
+
# Using the parts tuple helps share interned path parts
|
| 566 |
+
# when pickling related paths.
|
| 567 |
+
return (self.__class__, tuple(self._parts))
|
| 568 |
+
|
| 569 |
+
@classmethod
|
| 570 |
+
def _parse_args(cls, args):
|
| 571 |
+
# This is useful when you don't want to create an instance, just
|
| 572 |
+
# canonicalize some constructor arguments.
|
| 573 |
+
parts = []
|
| 574 |
+
for a in args:
|
| 575 |
+
if isinstance(a, PurePath):
|
| 576 |
+
parts += a._parts
|
| 577 |
+
else:
|
| 578 |
+
a = os.fspath(a)
|
| 579 |
+
if isinstance(a, str):
|
| 580 |
+
# Force-cast str subclasses to str (issue #21127)
|
| 581 |
+
parts.append(str(a))
|
| 582 |
+
else:
|
| 583 |
+
raise TypeError(
|
| 584 |
+
"argument should be a str object or an os.PathLike "
|
| 585 |
+
"object returning str, not %r"
|
| 586 |
+
% type(a))
|
| 587 |
+
return cls._flavour.parse_parts(parts)
|
| 588 |
+
|
| 589 |
+
@classmethod
|
| 590 |
+
def _from_parts(cls, args):
|
| 591 |
+
# We need to call _parse_args on the instance, so as to get the
|
| 592 |
+
# right flavour.
|
| 593 |
+
self = object.__new__(cls)
|
| 594 |
+
drv, root, parts = self._parse_args(args)
|
| 595 |
+
self._drv = drv
|
| 596 |
+
self._root = root
|
| 597 |
+
self._parts = parts
|
| 598 |
+
return self
|
| 599 |
+
|
| 600 |
+
@classmethod
|
| 601 |
+
def _from_parsed_parts(cls, drv, root, parts):
|
| 602 |
+
self = object.__new__(cls)
|
| 603 |
+
self._drv = drv
|
| 604 |
+
self._root = root
|
| 605 |
+
self._parts = parts
|
| 606 |
+
return self
|
| 607 |
+
|
| 608 |
+
@classmethod
|
| 609 |
+
def _format_parsed_parts(cls, drv, root, parts):
|
| 610 |
+
if drv or root:
|
| 611 |
+
return drv + root + cls._flavour.join(parts[1:])
|
| 612 |
+
else:
|
| 613 |
+
return cls._flavour.join(parts)
|
| 614 |
+
|
| 615 |
+
def _make_child(self, args):
|
| 616 |
+
drv, root, parts = self._parse_args(args)
|
| 617 |
+
drv, root, parts = self._flavour.join_parsed_parts(
|
| 618 |
+
self._drv, self._root, self._parts, drv, root, parts)
|
| 619 |
+
return self._from_parsed_parts(drv, root, parts)
|
| 620 |
+
|
| 621 |
+
def __str__(self):
|
| 622 |
+
"""Return the string representation of the path, suitable for
|
| 623 |
+
passing to system calls."""
|
| 624 |
+
try:
|
| 625 |
+
return self._str
|
| 626 |
+
except AttributeError:
|
| 627 |
+
self._str = self._format_parsed_parts(self._drv, self._root,
|
| 628 |
+
self._parts) or '.'
|
| 629 |
+
return self._str
|
| 630 |
+
|
| 631 |
+
def __fspath__(self):
|
| 632 |
+
return str(self)
|
| 633 |
+
|
| 634 |
+
def as_posix(self):
|
| 635 |
+
"""Return the string representation of the path with forward (/)
|
| 636 |
+
slashes."""
|
| 637 |
+
f = self._flavour
|
| 638 |
+
return str(self).replace(f.sep, '/')
|
| 639 |
+
|
| 640 |
+
def __bytes__(self):
|
| 641 |
+
"""Return the bytes representation of the path. This is only
|
| 642 |
+
recommended to use under Unix."""
|
| 643 |
+
return os.fsencode(self)
|
| 644 |
+
|
| 645 |
+
def __repr__(self):
|
| 646 |
+
return "{}({!r})".format(self.__class__.__name__, self.as_posix())
|
| 647 |
+
|
| 648 |
+
def as_uri(self):
|
| 649 |
+
"""Return the path as a 'file' URI."""
|
| 650 |
+
if not self.is_absolute():
|
| 651 |
+
raise ValueError("relative path can't be expressed as a file URI")
|
| 652 |
+
return self._flavour.make_uri(self)
|
| 653 |
+
|
| 654 |
+
@property
|
| 655 |
+
def _cparts(self):
|
| 656 |
+
# Cached casefolded parts, for hashing and comparison
|
| 657 |
+
try:
|
| 658 |
+
return self._cached_cparts
|
| 659 |
+
except AttributeError:
|
| 660 |
+
self._cached_cparts = self._flavour.casefold_parts(self._parts)
|
| 661 |
+
return self._cached_cparts
|
| 662 |
+
|
| 663 |
+
def __eq__(self, other):
|
| 664 |
+
if not isinstance(other, PurePath):
|
| 665 |
+
return NotImplemented
|
| 666 |
+
return self._cparts == other._cparts and self._flavour is other._flavour
|
| 667 |
+
|
| 668 |
+
def __hash__(self):
|
| 669 |
+
try:
|
| 670 |
+
return self._hash
|
| 671 |
+
except AttributeError:
|
| 672 |
+
self._hash = hash(tuple(self._cparts))
|
| 673 |
+
return self._hash
|
| 674 |
+
|
| 675 |
+
def __lt__(self, other):
|
| 676 |
+
if not isinstance(other, PurePath) or self._flavour is not other._flavour:
|
| 677 |
+
return NotImplemented
|
| 678 |
+
return self._cparts < other._cparts
|
| 679 |
+
|
| 680 |
+
def __le__(self, other):
|
| 681 |
+
if not isinstance(other, PurePath) or self._flavour is not other._flavour:
|
| 682 |
+
return NotImplemented
|
| 683 |
+
return self._cparts <= other._cparts
|
| 684 |
+
|
| 685 |
+
def __gt__(self, other):
|
| 686 |
+
if not isinstance(other, PurePath) or self._flavour is not other._flavour:
|
| 687 |
+
return NotImplemented
|
| 688 |
+
return self._cparts > other._cparts
|
| 689 |
+
|
| 690 |
+
def __ge__(self, other):
|
| 691 |
+
if not isinstance(other, PurePath) or self._flavour is not other._flavour:
|
| 692 |
+
return NotImplemented
|
| 693 |
+
return self._cparts >= other._cparts
|
| 694 |
+
|
| 695 |
+
def __class_getitem__(cls, type):
|
| 696 |
+
return cls
|
| 697 |
+
|
| 698 |
+
drive = property(attrgetter('_drv'),
|
| 699 |
+
doc="""The drive prefix (letter or UNC path), if any.""")
|
| 700 |
+
|
| 701 |
+
root = property(attrgetter('_root'),
|
| 702 |
+
doc="""The root of the path, if any.""")
|
| 703 |
+
|
| 704 |
+
@property
|
| 705 |
+
def anchor(self):
|
| 706 |
+
"""The concatenation of the drive and root, or ''."""
|
| 707 |
+
anchor = self._drv + self._root
|
| 708 |
+
return anchor
|
| 709 |
+
|
| 710 |
+
@property
|
| 711 |
+
def name(self):
|
| 712 |
+
"""The final path component, if any."""
|
| 713 |
+
parts = self._parts
|
| 714 |
+
if len(parts) == (1 if (self._drv or self._root) else 0):
|
| 715 |
+
return ''
|
| 716 |
+
return parts[-1]
|
| 717 |
+
|
| 718 |
+
@property
|
| 719 |
+
def suffix(self):
|
| 720 |
+
"""
|
| 721 |
+
The final component's last suffix, if any.
|
| 722 |
+
|
| 723 |
+
This includes the leading period. For example: '.txt'
|
| 724 |
+
"""
|
| 725 |
+
name = self.name
|
| 726 |
+
i = name.rfind('.')
|
| 727 |
+
if 0 < i < len(name) - 1:
|
| 728 |
+
return name[i:]
|
| 729 |
+
else:
|
| 730 |
+
return ''
|
| 731 |
+
|
| 732 |
+
@property
|
| 733 |
+
def suffixes(self):
|
| 734 |
+
"""
|
| 735 |
+
A list of the final component's suffixes, if any.
|
| 736 |
+
|
| 737 |
+
These include the leading periods. For example: ['.tar', '.gz']
|
| 738 |
+
"""
|
| 739 |
+
name = self.name
|
| 740 |
+
if name.endswith('.'):
|
| 741 |
+
return []
|
| 742 |
+
name = name.lstrip('.')
|
| 743 |
+
return ['.' + suffix for suffix in name.split('.')[1:]]
|
| 744 |
+
|
| 745 |
+
@property
|
| 746 |
+
def stem(self):
|
| 747 |
+
"""The final path component, minus its last suffix."""
|
| 748 |
+
name = self.name
|
| 749 |
+
i = name.rfind('.')
|
| 750 |
+
if 0 < i < len(name) - 1:
|
| 751 |
+
return name[:i]
|
| 752 |
+
else:
|
| 753 |
+
return name
|
| 754 |
+
|
| 755 |
+
def with_name(self, name):
|
| 756 |
+
"""Return a new path with the file name changed."""
|
| 757 |
+
if not self.name:
|
| 758 |
+
raise ValueError("%r has an empty name" % (self,))
|
| 759 |
+
drv, root, parts = self._flavour.parse_parts((name,))
|
| 760 |
+
if (not name or name[-1] in [self._flavour.sep, self._flavour.altsep]
|
| 761 |
+
or drv or root or len(parts) != 1):
|
| 762 |
+
raise ValueError("Invalid name %r" % (name))
|
| 763 |
+
return self._from_parsed_parts(self._drv, self._root,
|
| 764 |
+
self._parts[:-1] + [name])
|
| 765 |
+
|
| 766 |
+
def with_stem(self, stem):
|
| 767 |
+
"""Return a new path with the stem changed."""
|
| 768 |
+
return self.with_name(stem + self.suffix)
|
| 769 |
+
|
| 770 |
+
def with_suffix(self, suffix):
|
| 771 |
+
"""Return a new path with the file suffix changed. If the path
|
| 772 |
+
has no suffix, add given suffix. If the given suffix is an empty
|
| 773 |
+
string, remove the suffix from the path.
|
| 774 |
+
"""
|
| 775 |
+
f = self._flavour
|
| 776 |
+
if f.sep in suffix or f.altsep and f.altsep in suffix:
|
| 777 |
+
raise ValueError("Invalid suffix %r" % (suffix,))
|
| 778 |
+
if suffix and not suffix.startswith('.') or suffix == '.':
|
| 779 |
+
raise ValueError("Invalid suffix %r" % (suffix))
|
| 780 |
+
name = self.name
|
| 781 |
+
if not name:
|
| 782 |
+
raise ValueError("%r has an empty name" % (self,))
|
| 783 |
+
old_suffix = self.suffix
|
| 784 |
+
if not old_suffix:
|
| 785 |
+
name = name + suffix
|
| 786 |
+
else:
|
| 787 |
+
name = name[:-len(old_suffix)] + suffix
|
| 788 |
+
return self._from_parsed_parts(self._drv, self._root,
|
| 789 |
+
self._parts[:-1] + [name])
|
| 790 |
+
|
| 791 |
+
def relative_to(self, *other):
|
| 792 |
+
"""Return the relative path to another path identified by the passed
|
| 793 |
+
arguments. If the operation is not possible (because this is not
|
| 794 |
+
a subpath of the other path), raise ValueError.
|
| 795 |
+
"""
|
| 796 |
+
# For the purpose of this method, drive and root are considered
|
| 797 |
+
# separate parts, i.e.:
|
| 798 |
+
# Path('c:/').relative_to('c:') gives Path('/')
|
| 799 |
+
# Path('c:/').relative_to('/') raise ValueError
|
| 800 |
+
if not other:
|
| 801 |
+
raise TypeError("need at least one argument")
|
| 802 |
+
parts = self._parts
|
| 803 |
+
drv = self._drv
|
| 804 |
+
root = self._root
|
| 805 |
+
if root:
|
| 806 |
+
abs_parts = [drv, root] + parts[1:]
|
| 807 |
+
else:
|
| 808 |
+
abs_parts = parts
|
| 809 |
+
to_drv, to_root, to_parts = self._parse_args(other)
|
| 810 |
+
if to_root:
|
| 811 |
+
to_abs_parts = [to_drv, to_root] + to_parts[1:]
|
| 812 |
+
else:
|
| 813 |
+
to_abs_parts = to_parts
|
| 814 |
+
n = len(to_abs_parts)
|
| 815 |
+
cf = self._flavour.casefold_parts
|
| 816 |
+
if (root or drv) if n == 0 else cf(abs_parts[:n]) != cf(to_abs_parts):
|
| 817 |
+
formatted = self._format_parsed_parts(to_drv, to_root, to_parts)
|
| 818 |
+
raise ValueError("{!r} is not in the subpath of {!r}"
|
| 819 |
+
" OR one path is relative and the other is absolute."
|
| 820 |
+
.format(str(self), str(formatted)))
|
| 821 |
+
return self._from_parsed_parts('', root if n == 1 else '',
|
| 822 |
+
abs_parts[n:])
|
| 823 |
+
|
| 824 |
+
def is_relative_to(self, *other):
|
| 825 |
+
"""Return True if the path is relative to another path or False.
|
| 826 |
+
"""
|
| 827 |
+
try:
|
| 828 |
+
self.relative_to(*other)
|
| 829 |
+
return True
|
| 830 |
+
except ValueError:
|
| 831 |
+
return False
|
| 832 |
+
|
| 833 |
+
@property
|
| 834 |
+
def parts(self):
|
| 835 |
+
"""An object providing sequence-like access to the
|
| 836 |
+
components in the filesystem path."""
|
| 837 |
+
# We cache the tuple to avoid building a new one each time .parts
|
| 838 |
+
# is accessed. XXX is this necessary?
|
| 839 |
+
try:
|
| 840 |
+
return self._pparts
|
| 841 |
+
except AttributeError:
|
| 842 |
+
self._pparts = tuple(self._parts)
|
| 843 |
+
return self._pparts
|
| 844 |
+
|
| 845 |
+
def joinpath(self, *args):
|
| 846 |
+
"""Combine this path with one or several arguments, and return a
|
| 847 |
+
new path representing either a subpath (if all arguments are relative
|
| 848 |
+
paths) or a totally different path (if one of the arguments is
|
| 849 |
+
anchored).
|
| 850 |
+
"""
|
| 851 |
+
return self._make_child(args)
|
| 852 |
+
|
| 853 |
+
def __truediv__(self, key):
|
| 854 |
+
try:
|
| 855 |
+
return self._make_child((key,))
|
| 856 |
+
except TypeError:
|
| 857 |
+
return NotImplemented
|
| 858 |
+
|
| 859 |
+
def __rtruediv__(self, key):
|
| 860 |
+
try:
|
| 861 |
+
return self._from_parts([key] + self._parts)
|
| 862 |
+
except TypeError:
|
| 863 |
+
return NotImplemented
|
| 864 |
+
|
| 865 |
+
@property
|
| 866 |
+
def parent(self):
|
| 867 |
+
"""The logical parent of the path."""
|
| 868 |
+
drv = self._drv
|
| 869 |
+
root = self._root
|
| 870 |
+
parts = self._parts
|
| 871 |
+
if len(parts) == 1 and (drv or root):
|
| 872 |
+
return self
|
| 873 |
+
return self._from_parsed_parts(drv, root, parts[:-1])
|
| 874 |
+
|
| 875 |
+
@property
|
| 876 |
+
def parents(self):
|
| 877 |
+
"""A sequence of this path's logical parents."""
|
| 878 |
+
return _PathParents(self)
|
| 879 |
+
|
| 880 |
+
def is_absolute(self):
|
| 881 |
+
"""True if the path is absolute (has both a root and, if applicable,
|
| 882 |
+
a drive)."""
|
| 883 |
+
if not self._root:
|
| 884 |
+
return False
|
| 885 |
+
return not self._flavour.has_drv or bool(self._drv)
|
| 886 |
+
|
| 887 |
+
def is_reserved(self):
|
| 888 |
+
"""Return True if the path contains one of the special names reserved
|
| 889 |
+
by the system, if any."""
|
| 890 |
+
return self._flavour.is_reserved(self._parts)
|
| 891 |
+
|
| 892 |
+
def match(self, path_pattern):
|
| 893 |
+
"""
|
| 894 |
+
Return True if this path matches the given pattern.
|
| 895 |
+
"""
|
| 896 |
+
cf = self._flavour.casefold
|
| 897 |
+
path_pattern = cf(path_pattern)
|
| 898 |
+
drv, root, pat_parts = self._flavour.parse_parts((path_pattern,))
|
| 899 |
+
if not pat_parts:
|
| 900 |
+
raise ValueError("empty pattern")
|
| 901 |
+
if drv and drv != cf(self._drv):
|
| 902 |
+
return False
|
| 903 |
+
if root and root != cf(self._root):
|
| 904 |
+
return False
|
| 905 |
+
parts = self._cparts
|
| 906 |
+
if drv or root:
|
| 907 |
+
if len(pat_parts) != len(parts):
|
| 908 |
+
return False
|
| 909 |
+
pat_parts = pat_parts[1:]
|
| 910 |
+
elif len(pat_parts) > len(parts):
|
| 911 |
+
return False
|
| 912 |
+
for part, pat in zip(reversed(parts), reversed(pat_parts)):
|
| 913 |
+
if not fnmatch.fnmatchcase(part, pat):
|
| 914 |
+
return False
|
| 915 |
+
return True
|
| 916 |
+
|
| 917 |
+
# Can't subclass os.PathLike from PurePath and keep the constructor
|
| 918 |
+
# optimizations in PurePath._parse_args().
|
| 919 |
+
os.PathLike.register(PurePath)
|
| 920 |
+
|
| 921 |
+
|
| 922 |
+
class PurePosixPath(PurePath):
|
| 923 |
+
"""PurePath subclass for non-Windows systems.
|
| 924 |
+
|
| 925 |
+
On a POSIX system, instantiating a PurePath should return this object.
|
| 926 |
+
However, you can also instantiate it directly on any system.
|
| 927 |
+
"""
|
| 928 |
+
_flavour = _posix_flavour
|
| 929 |
+
__slots__ = ()
|
| 930 |
+
|
| 931 |
+
|
| 932 |
+
class PureWindowsPath(PurePath):
|
| 933 |
+
"""PurePath subclass for Windows systems.
|
| 934 |
+
|
| 935 |
+
On a Windows system, instantiating a PurePath should return this object.
|
| 936 |
+
However, you can also instantiate it directly on any system.
|
| 937 |
+
"""
|
| 938 |
+
_flavour = _windows_flavour
|
| 939 |
+
__slots__ = ()
|
| 940 |
+
|
| 941 |
+
|
| 942 |
+
# Filesystem-accessing classes
|
| 943 |
+
|
| 944 |
+
|
| 945 |
+
class Path(PurePath):
|
| 946 |
+
"""PurePath subclass that can make system calls.
|
| 947 |
+
|
| 948 |
+
Path represents a filesystem path but unlike PurePath, also offers
|
| 949 |
+
methods to do system calls on path objects. Depending on your system,
|
| 950 |
+
instantiating a Path will return either a PosixPath or a WindowsPath
|
| 951 |
+
object. You can also instantiate a PosixPath or WindowsPath directly,
|
| 952 |
+
but cannot instantiate a WindowsPath on a POSIX system or vice versa.
|
| 953 |
+
"""
|
| 954 |
+
_accessor = _normal_accessor
|
| 955 |
+
__slots__ = ()
|
| 956 |
+
|
| 957 |
+
def __new__(cls, *args, **kwargs):
|
| 958 |
+
if cls is Path:
|
| 959 |
+
cls = WindowsPath if os.name == 'nt' else PosixPath
|
| 960 |
+
self = cls._from_parts(args)
|
| 961 |
+
if not self._flavour.is_supported:
|
| 962 |
+
raise NotImplementedError("cannot instantiate %r on your system"
|
| 963 |
+
% (cls.__name__,))
|
| 964 |
+
return self
|
| 965 |
+
|
| 966 |
+
def _make_child_relpath(self, part):
|
| 967 |
+
# This is an optimization used for dir walking. `part` must be
|
| 968 |
+
# a single part relative to this path.
|
| 969 |
+
parts = self._parts + [part]
|
| 970 |
+
return self._from_parsed_parts(self._drv, self._root, parts)
|
| 971 |
+
|
| 972 |
+
def __enter__(self):
|
| 973 |
+
return self
|
| 974 |
+
|
| 975 |
+
def __exit__(self, t, v, tb):
|
| 976 |
+
# https://bugs.python.org/issue39682
|
| 977 |
+
# In previous versions of pathlib, this method marked this path as
|
| 978 |
+
# closed; subsequent attempts to perform I/O would raise an IOError.
|
| 979 |
+
# This functionality was never documented, and had the effect of
|
| 980 |
+
# making Path objects mutable, contrary to PEP 428. In Python 3.9 the
|
| 981 |
+
# _closed attribute was removed, and this method made a no-op.
|
| 982 |
+
# This method and __enter__()/__exit__() should be deprecated and
|
| 983 |
+
# removed in the future.
|
| 984 |
+
pass
|
| 985 |
+
|
| 986 |
+
# Public API
|
| 987 |
+
|
| 988 |
+
@classmethod
|
| 989 |
+
def cwd(cls):
|
| 990 |
+
"""Return a new path pointing to the current working directory
|
| 991 |
+
(as returned by os.getcwd()).
|
| 992 |
+
"""
|
| 993 |
+
return cls(cls._accessor.getcwd())
|
| 994 |
+
|
| 995 |
+
@classmethod
|
| 996 |
+
def home(cls):
|
| 997 |
+
"""Return a new path pointing to the user's home directory (as
|
| 998 |
+
returned by os.path.expanduser('~')).
|
| 999 |
+
"""
|
| 1000 |
+
return cls("~").expanduser()
|
| 1001 |
+
|
| 1002 |
+
def samefile(self, other_path):
|
| 1003 |
+
"""Return whether other_path is the same or not as this file
|
| 1004 |
+
(as returned by os.path.samefile()).
|
| 1005 |
+
"""
|
| 1006 |
+
st = self.stat()
|
| 1007 |
+
try:
|
| 1008 |
+
other_st = other_path.stat()
|
| 1009 |
+
except AttributeError:
|
| 1010 |
+
other_st = self._accessor.stat(other_path)
|
| 1011 |
+
return os.path.samestat(st, other_st)
|
| 1012 |
+
|
| 1013 |
+
def iterdir(self):
|
| 1014 |
+
"""Iterate over the files in this directory. Does not yield any
|
| 1015 |
+
result for the special paths '.' and '..'.
|
| 1016 |
+
"""
|
| 1017 |
+
for name in self._accessor.listdir(self):
|
| 1018 |
+
if name in {'.', '..'}:
|
| 1019 |
+
# Yielding a path object for these makes little sense
|
| 1020 |
+
continue
|
| 1021 |
+
yield self._make_child_relpath(name)
|
| 1022 |
+
|
| 1023 |
+
def glob(self, pattern):
|
| 1024 |
+
"""Iterate over this subtree and yield all existing files (of any
|
| 1025 |
+
kind, including directories) matching the given relative pattern.
|
| 1026 |
+
"""
|
| 1027 |
+
sys.audit("pathlib.Path.glob", self, pattern)
|
| 1028 |
+
if not pattern:
|
| 1029 |
+
raise ValueError("Unacceptable pattern: {!r}".format(pattern))
|
| 1030 |
+
drv, root, pattern_parts = self._flavour.parse_parts((pattern,))
|
| 1031 |
+
if drv or root:
|
| 1032 |
+
raise NotImplementedError("Non-relative patterns are unsupported")
|
| 1033 |
+
selector = _make_selector(tuple(pattern_parts), self._flavour)
|
| 1034 |
+
for p in selector.select_from(self):
|
| 1035 |
+
yield p
|
| 1036 |
+
|
| 1037 |
+
def rglob(self, pattern):
|
| 1038 |
+
"""Recursively yield all existing files (of any kind, including
|
| 1039 |
+
directories) matching the given relative pattern, anywhere in
|
| 1040 |
+
this subtree.
|
| 1041 |
+
"""
|
| 1042 |
+
sys.audit("pathlib.Path.rglob", self, pattern)
|
| 1043 |
+
drv, root, pattern_parts = self._flavour.parse_parts((pattern,))
|
| 1044 |
+
if drv or root:
|
| 1045 |
+
raise NotImplementedError("Non-relative patterns are unsupported")
|
| 1046 |
+
selector = _make_selector(("**",) + tuple(pattern_parts), self._flavour)
|
| 1047 |
+
for p in selector.select_from(self):
|
| 1048 |
+
yield p
|
| 1049 |
+
|
| 1050 |
+
def absolute(self):
|
| 1051 |
+
"""Return an absolute version of this path. This function works
|
| 1052 |
+
even if the path doesn't point to anything.
|
| 1053 |
+
|
| 1054 |
+
No normalization is done, i.e. all '.' and '..' will be kept along.
|
| 1055 |
+
Use resolve() to get the canonical path to a file.
|
| 1056 |
+
"""
|
| 1057 |
+
# XXX untested yet!
|
| 1058 |
+
if self.is_absolute():
|
| 1059 |
+
return self
|
| 1060 |
+
# FIXME this must defer to the specific flavour (and, under Windows,
|
| 1061 |
+
# use nt._getfullpathname())
|
| 1062 |
+
return self._from_parts([self._accessor.getcwd()] + self._parts)
|
| 1063 |
+
|
| 1064 |
+
def resolve(self, strict=False):
|
| 1065 |
+
"""
|
| 1066 |
+
Make the path absolute, resolving all symlinks on the way and also
|
| 1067 |
+
normalizing it (for example turning slashes into backslashes under
|
| 1068 |
+
Windows).
|
| 1069 |
+
"""
|
| 1070 |
+
|
| 1071 |
+
def check_eloop(e):
|
| 1072 |
+
winerror = getattr(e, 'winerror', 0)
|
| 1073 |
+
if e.errno == ELOOP or winerror == _WINERROR_CANT_RESOLVE_FILENAME:
|
| 1074 |
+
raise RuntimeError("Symlink loop from %r" % e.filename)
|
| 1075 |
+
|
| 1076 |
+
try:
|
| 1077 |
+
s = self._accessor.realpath(self, strict=strict)
|
| 1078 |
+
except OSError as e:
|
| 1079 |
+
check_eloop(e)
|
| 1080 |
+
raise
|
| 1081 |
+
p = self._from_parts((s,))
|
| 1082 |
+
|
| 1083 |
+
# In non-strict mode, realpath() doesn't raise on symlink loops.
|
| 1084 |
+
# Ensure we get an exception by calling stat()
|
| 1085 |
+
if not strict:
|
| 1086 |
+
try:
|
| 1087 |
+
p.stat()
|
| 1088 |
+
except OSError as e:
|
| 1089 |
+
check_eloop(e)
|
| 1090 |
+
return p
|
| 1091 |
+
|
| 1092 |
+
def stat(self, *, follow_symlinks=True):
|
| 1093 |
+
"""
|
| 1094 |
+
Return the result of the stat() system call on this path, like
|
| 1095 |
+
os.stat() does.
|
| 1096 |
+
"""
|
| 1097 |
+
return self._accessor.stat(self, follow_symlinks=follow_symlinks)
|
| 1098 |
+
|
| 1099 |
+
def owner(self):
|
| 1100 |
+
"""
|
| 1101 |
+
Return the login name of the file owner.
|
| 1102 |
+
"""
|
| 1103 |
+
return self._accessor.owner(self)
|
| 1104 |
+
|
| 1105 |
+
def group(self):
|
| 1106 |
+
"""
|
| 1107 |
+
Return the group name of the file gid.
|
| 1108 |
+
"""
|
| 1109 |
+
return self._accessor.group(self)
|
| 1110 |
+
|
| 1111 |
+
def open(self, mode='r', buffering=-1, encoding=None,
|
| 1112 |
+
errors=None, newline=None):
|
| 1113 |
+
"""
|
| 1114 |
+
Open the file pointed by this path and return a file object, as
|
| 1115 |
+
the built-in open() function does.
|
| 1116 |
+
"""
|
| 1117 |
+
if "b" not in mode:
|
| 1118 |
+
encoding = io.text_encoding(encoding)
|
| 1119 |
+
return self._accessor.open(self, mode, buffering, encoding, errors,
|
| 1120 |
+
newline)
|
| 1121 |
+
|
| 1122 |
+
def read_bytes(self):
|
| 1123 |
+
"""
|
| 1124 |
+
Open the file in bytes mode, read it, and close the file.
|
| 1125 |
+
"""
|
| 1126 |
+
with self.open(mode='rb') as f:
|
| 1127 |
+
return f.read()
|
| 1128 |
+
|
| 1129 |
+
def read_text(self, encoding=None, errors=None):
|
| 1130 |
+
"""
|
| 1131 |
+
Open the file in text mode, read it, and close the file.
|
| 1132 |
+
"""
|
| 1133 |
+
encoding = io.text_encoding(encoding)
|
| 1134 |
+
with self.open(mode='r', encoding=encoding, errors=errors) as f:
|
| 1135 |
+
return f.read()
|
| 1136 |
+
|
| 1137 |
+
def write_bytes(self, data):
|
| 1138 |
+
"""
|
| 1139 |
+
Open the file in bytes mode, write to it, and close the file.
|
| 1140 |
+
"""
|
| 1141 |
+
# type-check for the buffer interface before truncating the file
|
| 1142 |
+
view = memoryview(data)
|
| 1143 |
+
with self.open(mode='wb') as f:
|
| 1144 |
+
return f.write(view)
|
| 1145 |
+
|
| 1146 |
+
def write_text(self, data, encoding=None, errors=None, newline=None):
|
| 1147 |
+
"""
|
| 1148 |
+
Open the file in text mode, write to it, and close the file.
|
| 1149 |
+
"""
|
| 1150 |
+
if not isinstance(data, str):
|
| 1151 |
+
raise TypeError('data must be str, not %s' %
|
| 1152 |
+
data.__class__.__name__)
|
| 1153 |
+
encoding = io.text_encoding(encoding)
|
| 1154 |
+
with self.open(mode='w', encoding=encoding, errors=errors, newline=newline) as f:
|
| 1155 |
+
return f.write(data)
|
| 1156 |
+
|
| 1157 |
+
def readlink(self):
|
| 1158 |
+
"""
|
| 1159 |
+
Return the path to which the symbolic link points.
|
| 1160 |
+
"""
|
| 1161 |
+
path = self._accessor.readlink(self)
|
| 1162 |
+
return self._from_parts((path,))
|
| 1163 |
+
|
| 1164 |
+
def touch(self, mode=0o666, exist_ok=True):
|
| 1165 |
+
"""
|
| 1166 |
+
Create this file with the given access mode, if it doesn't exist.
|
| 1167 |
+
"""
|
| 1168 |
+
self._accessor.touch(self, mode, exist_ok)
|
| 1169 |
+
|
| 1170 |
+
def mkdir(self, mode=0o777, parents=False, exist_ok=False):
|
| 1171 |
+
"""
|
| 1172 |
+
Create a new directory at this given path.
|
| 1173 |
+
"""
|
| 1174 |
+
try:
|
| 1175 |
+
self._accessor.mkdir(self, mode)
|
| 1176 |
+
except FileNotFoundError:
|
| 1177 |
+
if not parents or self.parent == self:
|
| 1178 |
+
raise
|
| 1179 |
+
self.parent.mkdir(parents=True, exist_ok=True)
|
| 1180 |
+
self.mkdir(mode, parents=False, exist_ok=exist_ok)
|
| 1181 |
+
except OSError:
|
| 1182 |
+
# Cannot rely on checking for EEXIST, since the operating system
|
| 1183 |
+
# could give priority to other errors like EACCES or EROFS
|
| 1184 |
+
if not exist_ok or not self.is_dir():
|
| 1185 |
+
raise
|
| 1186 |
+
|
| 1187 |
+
def chmod(self, mode, *, follow_symlinks=True):
|
| 1188 |
+
"""
|
| 1189 |
+
Change the permissions of the path, like os.chmod().
|
| 1190 |
+
"""
|
| 1191 |
+
self._accessor.chmod(self, mode, follow_symlinks=follow_symlinks)
|
| 1192 |
+
|
| 1193 |
+
def lchmod(self, mode):
|
| 1194 |
+
"""
|
| 1195 |
+
Like chmod(), except if the path points to a symlink, the symlink's
|
| 1196 |
+
permissions are changed, rather than its target's.
|
| 1197 |
+
"""
|
| 1198 |
+
self.chmod(mode, follow_symlinks=False)
|
| 1199 |
+
|
| 1200 |
+
def unlink(self, missing_ok=False):
|
| 1201 |
+
"""
|
| 1202 |
+
Remove this file or link.
|
| 1203 |
+
If the path is a directory, use rmdir() instead.
|
| 1204 |
+
"""
|
| 1205 |
+
try:
|
| 1206 |
+
self._accessor.unlink(self)
|
| 1207 |
+
except FileNotFoundError:
|
| 1208 |
+
if not missing_ok:
|
| 1209 |
+
raise
|
| 1210 |
+
|
| 1211 |
+
def rmdir(self):
|
| 1212 |
+
"""
|
| 1213 |
+
Remove this directory. The directory must be empty.
|
| 1214 |
+
"""
|
| 1215 |
+
self._accessor.rmdir(self)
|
| 1216 |
+
|
| 1217 |
+
def lstat(self):
|
| 1218 |
+
"""
|
| 1219 |
+
Like stat(), except if the path points to a symlink, the symlink's
|
| 1220 |
+
status information is returned, rather than its target's.
|
| 1221 |
+
"""
|
| 1222 |
+
return self.stat(follow_symlinks=False)
|
| 1223 |
+
|
| 1224 |
+
def rename(self, target):
|
| 1225 |
+
"""
|
| 1226 |
+
Rename this path to the target path.
|
| 1227 |
+
|
| 1228 |
+
The target path may be absolute or relative. Relative paths are
|
| 1229 |
+
interpreted relative to the current working directory, *not* the
|
| 1230 |
+
directory of the Path object.
|
| 1231 |
+
|
| 1232 |
+
Returns the new Path instance pointing to the target path.
|
| 1233 |
+
"""
|
| 1234 |
+
self._accessor.rename(self, target)
|
| 1235 |
+
return self.__class__(target)
|
| 1236 |
+
|
| 1237 |
+
def replace(self, target):
|
| 1238 |
+
"""
|
| 1239 |
+
Rename this path to the target path, overwriting if that path exists.
|
| 1240 |
+
|
| 1241 |
+
The target path may be absolute or relative. Relative paths are
|
| 1242 |
+
interpreted relative to the current working directory, *not* the
|
| 1243 |
+
directory of the Path object.
|
| 1244 |
+
|
| 1245 |
+
Returns the new Path instance pointing to the target path.
|
| 1246 |
+
"""
|
| 1247 |
+
self._accessor.replace(self, target)
|
| 1248 |
+
return self.__class__(target)
|
| 1249 |
+
|
| 1250 |
+
def symlink_to(self, target, target_is_directory=False):
|
| 1251 |
+
"""
|
| 1252 |
+
Make this path a symlink pointing to the target path.
|
| 1253 |
+
Note the order of arguments (link, target) is the reverse of os.symlink.
|
| 1254 |
+
"""
|
| 1255 |
+
self._accessor.symlink(target, self, target_is_directory)
|
| 1256 |
+
|
| 1257 |
+
def hardlink_to(self, target):
|
| 1258 |
+
"""
|
| 1259 |
+
Make this path a hard link pointing to the same file as *target*.
|
| 1260 |
+
|
| 1261 |
+
Note the order of arguments (self, target) is the reverse of os.link's.
|
| 1262 |
+
"""
|
| 1263 |
+
self._accessor.link(target, self)
|
| 1264 |
+
|
| 1265 |
+
def link_to(self, target):
|
| 1266 |
+
"""
|
| 1267 |
+
Make the target path a hard link pointing to this path.
|
| 1268 |
+
|
| 1269 |
+
Note this function does not make this path a hard link to *target*,
|
| 1270 |
+
despite the implication of the function and argument names. The order
|
| 1271 |
+
of arguments (target, link) is the reverse of Path.symlink_to, but
|
| 1272 |
+
matches that of os.link.
|
| 1273 |
+
|
| 1274 |
+
Deprecated since Python 3.10 and scheduled for removal in Python 3.12.
|
| 1275 |
+
Use `hardlink_to()` instead.
|
| 1276 |
+
"""
|
| 1277 |
+
warnings.warn("pathlib.Path.link_to() is deprecated and is scheduled "
|
| 1278 |
+
"for removal in Python 3.12. "
|
| 1279 |
+
"Use pathlib.Path.hardlink_to() instead.",
|
| 1280 |
+
DeprecationWarning, stacklevel=2)
|
| 1281 |
+
self._accessor.link(self, target)
|
| 1282 |
+
|
| 1283 |
+
# Convenience functions for querying the stat results
|
| 1284 |
+
|
| 1285 |
+
def exists(self):
|
| 1286 |
+
"""
|
| 1287 |
+
Whether this path exists.
|
| 1288 |
+
"""
|
| 1289 |
+
try:
|
| 1290 |
+
self.stat()
|
| 1291 |
+
except OSError as e:
|
| 1292 |
+
if not _ignore_error(e):
|
| 1293 |
+
raise
|
| 1294 |
+
return False
|
| 1295 |
+
except ValueError:
|
| 1296 |
+
# Non-encodable path
|
| 1297 |
+
return False
|
| 1298 |
+
return True
|
| 1299 |
+
|
| 1300 |
+
def is_dir(self):
|
| 1301 |
+
"""
|
| 1302 |
+
Whether this path is a directory.
|
| 1303 |
+
"""
|
| 1304 |
+
try:
|
| 1305 |
+
return S_ISDIR(self.stat().st_mode)
|
| 1306 |
+
except OSError as e:
|
| 1307 |
+
if not _ignore_error(e):
|
| 1308 |
+
raise
|
| 1309 |
+
# Path doesn't exist or is a broken symlink
|
| 1310 |
+
# (see http://web.archive.org/web/20200623061726/https://bitbucket.org/pitrou/pathlib/issues/12/ )
|
| 1311 |
+
return False
|
| 1312 |
+
except ValueError:
|
| 1313 |
+
# Non-encodable path
|
| 1314 |
+
return False
|
| 1315 |
+
|
| 1316 |
+
def is_file(self):
|
| 1317 |
+
"""
|
| 1318 |
+
Whether this path is a regular file (also True for symlinks pointing
|
| 1319 |
+
to regular files).
|
| 1320 |
+
"""
|
| 1321 |
+
try:
|
| 1322 |
+
return S_ISREG(self.stat().st_mode)
|
| 1323 |
+
except OSError as e:
|
| 1324 |
+
if not _ignore_error(e):
|
| 1325 |
+
raise
|
| 1326 |
+
# Path doesn't exist or is a broken symlink
|
| 1327 |
+
# (see http://web.archive.org/web/20200623061726/https://bitbucket.org/pitrou/pathlib/issues/12/ )
|
| 1328 |
+
return False
|
| 1329 |
+
except ValueError:
|
| 1330 |
+
# Non-encodable path
|
| 1331 |
+
return False
|
| 1332 |
+
|
| 1333 |
+
def is_mount(self):
|
| 1334 |
+
"""
|
| 1335 |
+
Check if this path is a POSIX mount point
|
| 1336 |
+
"""
|
| 1337 |
+
# Need to exist and be a dir
|
| 1338 |
+
if not self.exists() or not self.is_dir():
|
| 1339 |
+
return False
|
| 1340 |
+
|
| 1341 |
+
try:
|
| 1342 |
+
parent_dev = self.parent.stat().st_dev
|
| 1343 |
+
except OSError:
|
| 1344 |
+
return False
|
| 1345 |
+
|
| 1346 |
+
dev = self.stat().st_dev
|
| 1347 |
+
if dev != parent_dev:
|
| 1348 |
+
return True
|
| 1349 |
+
ino = self.stat().st_ino
|
| 1350 |
+
parent_ino = self.parent.stat().st_ino
|
| 1351 |
+
return ino == parent_ino
|
| 1352 |
+
|
| 1353 |
+
def is_symlink(self):
|
| 1354 |
+
"""
|
| 1355 |
+
Whether this path is a symbolic link.
|
| 1356 |
+
"""
|
| 1357 |
+
try:
|
| 1358 |
+
return S_ISLNK(self.lstat().st_mode)
|
| 1359 |
+
except OSError as e:
|
| 1360 |
+
if not _ignore_error(e):
|
| 1361 |
+
raise
|
| 1362 |
+
# Path doesn't exist
|
| 1363 |
+
return False
|
| 1364 |
+
except ValueError:
|
| 1365 |
+
# Non-encodable path
|
| 1366 |
+
return False
|
| 1367 |
+
|
| 1368 |
+
def is_block_device(self):
|
| 1369 |
+
"""
|
| 1370 |
+
Whether this path is a block device.
|
| 1371 |
+
"""
|
| 1372 |
+
try:
|
| 1373 |
+
return S_ISBLK(self.stat().st_mode)
|
| 1374 |
+
except OSError as e:
|
| 1375 |
+
if not _ignore_error(e):
|
| 1376 |
+
raise
|
| 1377 |
+
# Path doesn't exist or is a broken symlink
|
| 1378 |
+
# (see http://web.archive.org/web/20200623061726/https://bitbucket.org/pitrou/pathlib/issues/12/ )
|
| 1379 |
+
return False
|
| 1380 |
+
except ValueError:
|
| 1381 |
+
# Non-encodable path
|
| 1382 |
+
return False
|
| 1383 |
+
|
| 1384 |
+
def is_char_device(self):
|
| 1385 |
+
"""
|
| 1386 |
+
Whether this path is a character device.
|
| 1387 |
+
"""
|
| 1388 |
+
try:
|
| 1389 |
+
return S_ISCHR(self.stat().st_mode)
|
| 1390 |
+
except OSError as e:
|
| 1391 |
+
if not _ignore_error(e):
|
| 1392 |
+
raise
|
| 1393 |
+
# Path doesn't exist or is a broken symlink
|
| 1394 |
+
# (see http://web.archive.org/web/20200623061726/https://bitbucket.org/pitrou/pathlib/issues/12/ )
|
| 1395 |
+
return False
|
| 1396 |
+
except ValueError:
|
| 1397 |
+
# Non-encodable path
|
| 1398 |
+
return False
|
| 1399 |
+
|
| 1400 |
+
def is_fifo(self):
|
| 1401 |
+
"""
|
| 1402 |
+
Whether this path is a FIFO.
|
| 1403 |
+
"""
|
| 1404 |
+
try:
|
| 1405 |
+
return S_ISFIFO(self.stat().st_mode)
|
| 1406 |
+
except OSError as e:
|
| 1407 |
+
if not _ignore_error(e):
|
| 1408 |
+
raise
|
| 1409 |
+
# Path doesn't exist or is a broken symlink
|
| 1410 |
+
# (see http://web.archive.org/web/20200623061726/https://bitbucket.org/pitrou/pathlib/issues/12/ )
|
| 1411 |
+
return False
|
| 1412 |
+
except ValueError:
|
| 1413 |
+
# Non-encodable path
|
| 1414 |
+
return False
|
| 1415 |
+
|
| 1416 |
+
def is_socket(self):
|
| 1417 |
+
"""
|
| 1418 |
+
Whether this path is a socket.
|
| 1419 |
+
"""
|
| 1420 |
+
try:
|
| 1421 |
+
return S_ISSOCK(self.stat().st_mode)
|
| 1422 |
+
except OSError as e:
|
| 1423 |
+
if not _ignore_error(e):
|
| 1424 |
+
raise
|
| 1425 |
+
# Path doesn't exist or is a broken symlink
|
| 1426 |
+
# (see http://web.archive.org/web/20200623061726/https://bitbucket.org/pitrou/pathlib/issues/12/ )
|
| 1427 |
+
return False
|
| 1428 |
+
except ValueError:
|
| 1429 |
+
# Non-encodable path
|
| 1430 |
+
return False
|
| 1431 |
+
|
| 1432 |
+
def expanduser(self):
|
| 1433 |
+
""" Return a new path with expanded ~ and ~user constructs
|
| 1434 |
+
(as returned by os.path.expanduser)
|
| 1435 |
+
"""
|
| 1436 |
+
if (not (self._drv or self._root) and
|
| 1437 |
+
self._parts and self._parts[0][:1] == '~'):
|
| 1438 |
+
homedir = self._accessor.expanduser(self._parts[0])
|
| 1439 |
+
if homedir[:1] == "~":
|
| 1440 |
+
raise RuntimeError("Could not determine home directory.")
|
| 1441 |
+
return self._from_parts([homedir] + self._parts[1:])
|
| 1442 |
+
|
| 1443 |
+
return self
|
| 1444 |
+
|
| 1445 |
+
|
| 1446 |
+
class PosixPath(Path, PurePosixPath):
|
| 1447 |
+
"""Path subclass for non-Windows systems.
|
| 1448 |
+
|
| 1449 |
+
On a POSIX system, instantiating a Path should return this object.
|
| 1450 |
+
"""
|
| 1451 |
+
__slots__ = ()
|
| 1452 |
+
|
| 1453 |
+
class WindowsPath(Path, PureWindowsPath):
|
| 1454 |
+
"""Path subclass for Windows systems.
|
| 1455 |
+
|
| 1456 |
+
On a Windows system, instantiating a Path should return this object.
|
| 1457 |
+
"""
|
| 1458 |
+
__slots__ = ()
|
| 1459 |
+
|
| 1460 |
+
def is_mount(self):
|
| 1461 |
+
raise NotImplementedError("Path.is_mount() is unsupported on this system")
|
llava/lib/python3.10/shelve.py
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Manage shelves of pickled objects.
|
| 2 |
+
|
| 3 |
+
A "shelf" is a persistent, dictionary-like object. The difference
|
| 4 |
+
with dbm databases is that the values (not the keys!) in a shelf can
|
| 5 |
+
be essentially arbitrary Python objects -- anything that the "pickle"
|
| 6 |
+
module can handle. This includes most class instances, recursive data
|
| 7 |
+
types, and objects containing lots of shared sub-objects. The keys
|
| 8 |
+
are ordinary strings.
|
| 9 |
+
|
| 10 |
+
To summarize the interface (key is a string, data is an arbitrary
|
| 11 |
+
object):
|
| 12 |
+
|
| 13 |
+
import shelve
|
| 14 |
+
d = shelve.open(filename) # open, with (g)dbm filename -- no suffix
|
| 15 |
+
|
| 16 |
+
d[key] = data # store data at key (overwrites old data if
|
| 17 |
+
# using an existing key)
|
| 18 |
+
data = d[key] # retrieve a COPY of the data at key (raise
|
| 19 |
+
# KeyError if no such key) -- NOTE that this
|
| 20 |
+
# access returns a *copy* of the entry!
|
| 21 |
+
del d[key] # delete data stored at key (raises KeyError
|
| 22 |
+
# if no such key)
|
| 23 |
+
flag = key in d # true if the key exists
|
| 24 |
+
list = d.keys() # a list of all existing keys (slow!)
|
| 25 |
+
|
| 26 |
+
d.close() # close it
|
| 27 |
+
|
| 28 |
+
Dependent on the implementation, closing a persistent dictionary may
|
| 29 |
+
or may not be necessary to flush changes to disk.
|
| 30 |
+
|
| 31 |
+
Normally, d[key] returns a COPY of the entry. This needs care when
|
| 32 |
+
mutable entries are mutated: for example, if d[key] is a list,
|
| 33 |
+
d[key].append(anitem)
|
| 34 |
+
does NOT modify the entry d[key] itself, as stored in the persistent
|
| 35 |
+
mapping -- it only modifies the copy, which is then immediately
|
| 36 |
+
discarded, so that the append has NO effect whatsoever. To append an
|
| 37 |
+
item to d[key] in a way that will affect the persistent mapping, use:
|
| 38 |
+
data = d[key]
|
| 39 |
+
data.append(anitem)
|
| 40 |
+
d[key] = data
|
| 41 |
+
|
| 42 |
+
To avoid the problem with mutable entries, you may pass the keyword
|
| 43 |
+
argument writeback=True in the call to shelve.open. When you use:
|
| 44 |
+
d = shelve.open(filename, writeback=True)
|
| 45 |
+
then d keeps a cache of all entries you access, and writes them all back
|
| 46 |
+
to the persistent mapping when you call d.close(). This ensures that
|
| 47 |
+
such usage as d[key].append(anitem) works as intended.
|
| 48 |
+
|
| 49 |
+
However, using keyword argument writeback=True may consume vast amount
|
| 50 |
+
of memory for the cache, and it may make d.close() very slow, if you
|
| 51 |
+
access many of d's entries after opening it in this way: d has no way to
|
| 52 |
+
check which of the entries you access are mutable and/or which ones you
|
| 53 |
+
actually mutate, so it must cache, and write back at close, all of the
|
| 54 |
+
entries that you access. You can call d.sync() to write back all the
|
| 55 |
+
entries in the cache, and empty the cache (d.sync() also synchronizes
|
| 56 |
+
the persistent dictionary on disk, if feasible).
|
| 57 |
+
"""
|
| 58 |
+
|
| 59 |
+
from pickle import DEFAULT_PROTOCOL, Pickler, Unpickler
|
| 60 |
+
from io import BytesIO
|
| 61 |
+
|
| 62 |
+
import collections.abc
|
| 63 |
+
|
| 64 |
+
__all__ = ["Shelf", "BsdDbShelf", "DbfilenameShelf", "open"]
|
| 65 |
+
|
| 66 |
+
class _ClosedDict(collections.abc.MutableMapping):
|
| 67 |
+
'Marker for a closed dict. Access attempts raise a ValueError.'
|
| 68 |
+
|
| 69 |
+
def closed(self, *args):
|
| 70 |
+
raise ValueError('invalid operation on closed shelf')
|
| 71 |
+
__iter__ = __len__ = __getitem__ = __setitem__ = __delitem__ = keys = closed
|
| 72 |
+
|
| 73 |
+
def __repr__(self):
|
| 74 |
+
return '<Closed Dictionary>'
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
class Shelf(collections.abc.MutableMapping):
|
| 78 |
+
"""Base class for shelf implementations.
|
| 79 |
+
|
| 80 |
+
This is initialized with a dictionary-like object.
|
| 81 |
+
See the module's __doc__ string for an overview of the interface.
|
| 82 |
+
"""
|
| 83 |
+
|
| 84 |
+
def __init__(self, dict, protocol=None, writeback=False,
|
| 85 |
+
keyencoding="utf-8"):
|
| 86 |
+
self.dict = dict
|
| 87 |
+
if protocol is None:
|
| 88 |
+
protocol = DEFAULT_PROTOCOL
|
| 89 |
+
self._protocol = protocol
|
| 90 |
+
self.writeback = writeback
|
| 91 |
+
self.cache = {}
|
| 92 |
+
self.keyencoding = keyencoding
|
| 93 |
+
|
| 94 |
+
def __iter__(self):
|
| 95 |
+
for k in self.dict.keys():
|
| 96 |
+
yield k.decode(self.keyencoding)
|
| 97 |
+
|
| 98 |
+
def __len__(self):
|
| 99 |
+
return len(self.dict)
|
| 100 |
+
|
| 101 |
+
def __contains__(self, key):
|
| 102 |
+
return key.encode(self.keyencoding) in self.dict
|
| 103 |
+
|
| 104 |
+
def get(self, key, default=None):
|
| 105 |
+
if key.encode(self.keyencoding) in self.dict:
|
| 106 |
+
return self[key]
|
| 107 |
+
return default
|
| 108 |
+
|
| 109 |
+
def __getitem__(self, key):
|
| 110 |
+
try:
|
| 111 |
+
value = self.cache[key]
|
| 112 |
+
except KeyError:
|
| 113 |
+
f = BytesIO(self.dict[key.encode(self.keyencoding)])
|
| 114 |
+
value = Unpickler(f).load()
|
| 115 |
+
if self.writeback:
|
| 116 |
+
self.cache[key] = value
|
| 117 |
+
return value
|
| 118 |
+
|
| 119 |
+
def __setitem__(self, key, value):
|
| 120 |
+
if self.writeback:
|
| 121 |
+
self.cache[key] = value
|
| 122 |
+
f = BytesIO()
|
| 123 |
+
p = Pickler(f, self._protocol)
|
| 124 |
+
p.dump(value)
|
| 125 |
+
self.dict[key.encode(self.keyencoding)] = f.getvalue()
|
| 126 |
+
|
| 127 |
+
def __delitem__(self, key):
|
| 128 |
+
del self.dict[key.encode(self.keyencoding)]
|
| 129 |
+
try:
|
| 130 |
+
del self.cache[key]
|
| 131 |
+
except KeyError:
|
| 132 |
+
pass
|
| 133 |
+
|
| 134 |
+
def __enter__(self):
|
| 135 |
+
return self
|
| 136 |
+
|
| 137 |
+
def __exit__(self, type, value, traceback):
|
| 138 |
+
self.close()
|
| 139 |
+
|
| 140 |
+
def close(self):
|
| 141 |
+
if self.dict is None:
|
| 142 |
+
return
|
| 143 |
+
try:
|
| 144 |
+
self.sync()
|
| 145 |
+
try:
|
| 146 |
+
self.dict.close()
|
| 147 |
+
except AttributeError:
|
| 148 |
+
pass
|
| 149 |
+
finally:
|
| 150 |
+
# Catch errors that may happen when close is called from __del__
|
| 151 |
+
# because CPython is in interpreter shutdown.
|
| 152 |
+
try:
|
| 153 |
+
self.dict = _ClosedDict()
|
| 154 |
+
except:
|
| 155 |
+
self.dict = None
|
| 156 |
+
|
| 157 |
+
def __del__(self):
|
| 158 |
+
if not hasattr(self, 'writeback'):
|
| 159 |
+
# __init__ didn't succeed, so don't bother closing
|
| 160 |
+
# see http://bugs.python.org/issue1339007 for details
|
| 161 |
+
return
|
| 162 |
+
self.close()
|
| 163 |
+
|
| 164 |
+
def sync(self):
|
| 165 |
+
if self.writeback and self.cache:
|
| 166 |
+
self.writeback = False
|
| 167 |
+
for key, entry in self.cache.items():
|
| 168 |
+
self[key] = entry
|
| 169 |
+
self.writeback = True
|
| 170 |
+
self.cache = {}
|
| 171 |
+
if hasattr(self.dict, 'sync'):
|
| 172 |
+
self.dict.sync()
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
class BsdDbShelf(Shelf):
|
| 176 |
+
"""Shelf implementation using the "BSD" db interface.
|
| 177 |
+
|
| 178 |
+
This adds methods first(), next(), previous(), last() and
|
| 179 |
+
set_location() that have no counterpart in [g]dbm databases.
|
| 180 |
+
|
| 181 |
+
The actual database must be opened using one of the "bsddb"
|
| 182 |
+
modules "open" routines (i.e. bsddb.hashopen, bsddb.btopen or
|
| 183 |
+
bsddb.rnopen) and passed to the constructor.
|
| 184 |
+
|
| 185 |
+
See the module's __doc__ string for an overview of the interface.
|
| 186 |
+
"""
|
| 187 |
+
|
| 188 |
+
def __init__(self, dict, protocol=None, writeback=False,
|
| 189 |
+
keyencoding="utf-8"):
|
| 190 |
+
Shelf.__init__(self, dict, protocol, writeback, keyencoding)
|
| 191 |
+
|
| 192 |
+
def set_location(self, key):
|
| 193 |
+
(key, value) = self.dict.set_location(key)
|
| 194 |
+
f = BytesIO(value)
|
| 195 |
+
return (key.decode(self.keyencoding), Unpickler(f).load())
|
| 196 |
+
|
| 197 |
+
def next(self):
|
| 198 |
+
(key, value) = next(self.dict)
|
| 199 |
+
f = BytesIO(value)
|
| 200 |
+
return (key.decode(self.keyencoding), Unpickler(f).load())
|
| 201 |
+
|
| 202 |
+
def previous(self):
|
| 203 |
+
(key, value) = self.dict.previous()
|
| 204 |
+
f = BytesIO(value)
|
| 205 |
+
return (key.decode(self.keyencoding), Unpickler(f).load())
|
| 206 |
+
|
| 207 |
+
def first(self):
|
| 208 |
+
(key, value) = self.dict.first()
|
| 209 |
+
f = BytesIO(value)
|
| 210 |
+
return (key.decode(self.keyencoding), Unpickler(f).load())
|
| 211 |
+
|
| 212 |
+
def last(self):
|
| 213 |
+
(key, value) = self.dict.last()
|
| 214 |
+
f = BytesIO(value)
|
| 215 |
+
return (key.decode(self.keyencoding), Unpickler(f).load())
|
| 216 |
+
|
| 217 |
+
|
| 218 |
+
class DbfilenameShelf(Shelf):
|
| 219 |
+
"""Shelf implementation using the "dbm" generic dbm interface.
|
| 220 |
+
|
| 221 |
+
This is initialized with the filename for the dbm database.
|
| 222 |
+
See the module's __doc__ string for an overview of the interface.
|
| 223 |
+
"""
|
| 224 |
+
|
| 225 |
+
def __init__(self, filename, flag='c', protocol=None, writeback=False):
|
| 226 |
+
import dbm
|
| 227 |
+
Shelf.__init__(self, dbm.open(filename, flag), protocol, writeback)
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
def open(filename, flag='c', protocol=None, writeback=False):
|
| 231 |
+
"""Open a persistent dictionary for reading and writing.
|
| 232 |
+
|
| 233 |
+
The filename parameter is the base filename for the underlying
|
| 234 |
+
database. As a side-effect, an extension may be added to the
|
| 235 |
+
filename and more than one file may be created. The optional flag
|
| 236 |
+
parameter has the same interpretation as the flag parameter of
|
| 237 |
+
dbm.open(). The optional protocol parameter specifies the
|
| 238 |
+
version of the pickle protocol.
|
| 239 |
+
|
| 240 |
+
See the module's __doc__ string for an overview of the interface.
|
| 241 |
+
"""
|
| 242 |
+
|
| 243 |
+
return DbfilenameShelf(filename, flag, protocol, writeback)
|
llava/lib/python3.10/tarfile.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
parrot/lib/python3.10/site-packages/torch/include/ATen/ops/_cast_Double_native.h
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from NativeFunction.h
|
| 4 |
+
|
| 5 |
+
#include <c10/core/Scalar.h>
|
| 6 |
+
#include <c10/core/Storage.h>
|
| 7 |
+
#include <c10/core/TensorOptions.h>
|
| 8 |
+
#include <c10/util/Deprecated.h>
|
| 9 |
+
#include <c10/util/Optional.h>
|
| 10 |
+
#include <c10/core/QScheme.h>
|
| 11 |
+
#include <ATen/core/Reduction.h>
|
| 12 |
+
#include <ATen/core/Tensor.h>
|
| 13 |
+
#include <tuple>
|
| 14 |
+
#include <vector>
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
namespace at {
|
| 18 |
+
namespace native {
|
| 19 |
+
TORCH_API at::Tensor _cast_Double(const at::Tensor & self, bool non_blocking=false);
|
| 20 |
+
} // namespace native
|
| 21 |
+
} // namespace at
|
parrot/lib/python3.10/site-packages/torch/include/ATen/ops/_cdist_backward_ops.h
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from Operator.h
|
| 4 |
+
|
| 5 |
+
#include <tuple>
|
| 6 |
+
#include <vector>
|
| 7 |
+
|
| 8 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 9 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 10 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 11 |
+
#include <ATen/core/ATen_fwd.h>
|
| 12 |
+
|
| 13 |
+
namespace at {
|
| 14 |
+
namespace _ops {
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
struct TORCH_API _cdist_backward {
|
| 18 |
+
using schema = at::Tensor (const at::Tensor &, const at::Tensor &, const at::Tensor &, double, const at::Tensor &);
|
| 19 |
+
using ptr_schema = schema*;
|
| 20 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 21 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::_cdist_backward")
|
| 22 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "")
|
| 23 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "_cdist_backward(Tensor grad, Tensor x1, Tensor x2, float p, Tensor cdist) -> Tensor")
|
| 24 |
+
static at::Tensor call(const at::Tensor & grad, const at::Tensor & x1, const at::Tensor & x2, double p, const at::Tensor & cdist);
|
| 25 |
+
static at::Tensor redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & grad, const at::Tensor & x1, const at::Tensor & x2, double p, const at::Tensor & cdist);
|
| 26 |
+
};
|
| 27 |
+
|
| 28 |
+
struct TORCH_API _cdist_backward_out {
|
| 29 |
+
using schema = at::Tensor & (const at::Tensor &, const at::Tensor &, const at::Tensor &, double, const at::Tensor &, at::Tensor &);
|
| 30 |
+
using ptr_schema = schema*;
|
| 31 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 32 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::_cdist_backward")
|
| 33 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "out")
|
| 34 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "_cdist_backward.out(Tensor grad, Tensor x1, Tensor x2, float p, Tensor cdist, *, Tensor(a!) out) -> Tensor(a!)")
|
| 35 |
+
static at::Tensor & call(const at::Tensor & grad, const at::Tensor & x1, const at::Tensor & x2, double p, const at::Tensor & cdist, at::Tensor & out);
|
| 36 |
+
static at::Tensor & redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & grad, const at::Tensor & x1, const at::Tensor & x2, double p, const at::Tensor & cdist, at::Tensor & out);
|
| 37 |
+
};
|
| 38 |
+
|
| 39 |
+
}} // namespace at::_ops
|
parrot/lib/python3.10/site-packages/torch/include/ATen/ops/_conv_depthwise2d_cuda_dispatch.h
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// @generated by torchgen/gen.py from DispatchKeyFunction.h
|
| 3 |
+
|
| 4 |
+
// NB: The implementing C++ file is RegisterDispatchKey.cpp
|
| 5 |
+
|
| 6 |
+
// The only #includes we need are for custom classes that have defaults in the C++ API
|
| 7 |
+
#include <c10/core/MemoryFormat.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <ATen/core/Reduction.h>
|
| 10 |
+
|
| 11 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 12 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 13 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 14 |
+
#include <ATen/core/ATen_fwd.h>
|
| 15 |
+
|
| 16 |
+
namespace at {
|
| 17 |
+
|
| 18 |
+
namespace cuda {
|
| 19 |
+
|
| 20 |
+
TORCH_API at::Tensor _conv_depthwise2d(const at::Tensor & self, const at::Tensor & weight, at::IntArrayRef kernel_size, const ::std::optional<at::Tensor> & bias, at::IntArrayRef stride, at::IntArrayRef padding, at::IntArrayRef dilation);
|
| 21 |
+
TORCH_API at::Tensor _conv_depthwise2d_symint(const at::Tensor & self, const at::Tensor & weight, c10::SymIntArrayRef kernel_size, const ::std::optional<at::Tensor> & bias, c10::SymIntArrayRef stride, c10::SymIntArrayRef padding, c10::SymIntArrayRef dilation);
|
| 22 |
+
TORCH_API const at::Tensor & _conv_depthwise2d_out(const at::Tensor & out, const at::Tensor & self, const at::Tensor & weight, at::IntArrayRef kernel_size, const ::std::optional<at::Tensor> & bias, at::IntArrayRef stride, at::IntArrayRef padding, at::IntArrayRef dilation);
|
| 23 |
+
TORCH_API const at::Tensor & _conv_depthwise2d_outf(const at::Tensor & self, const at::Tensor & weight, at::IntArrayRef kernel_size, const ::std::optional<at::Tensor> & bias, at::IntArrayRef stride, at::IntArrayRef padding, at::IntArrayRef dilation, const at::Tensor & out);
|
| 24 |
+
TORCH_API const at::Tensor & _conv_depthwise2d_symint_out(const at::Tensor & out, const at::Tensor & self, const at::Tensor & weight, c10::SymIntArrayRef kernel_size, const ::std::optional<at::Tensor> & bias, c10::SymIntArrayRef stride, c10::SymIntArrayRef padding, c10::SymIntArrayRef dilation);
|
| 25 |
+
TORCH_API const at::Tensor & _conv_depthwise2d_symint_outf(const at::Tensor & self, const at::Tensor & weight, c10::SymIntArrayRef kernel_size, const ::std::optional<at::Tensor> & bias, c10::SymIntArrayRef stride, c10::SymIntArrayRef padding, c10::SymIntArrayRef dilation, const at::Tensor & out);
|
| 26 |
+
|
| 27 |
+
} // namespace cuda
|
| 28 |
+
} // namespace at
|
parrot/lib/python3.10/site-packages/torch/include/ATen/ops/_debug_has_internal_overlap_native.h
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from NativeFunction.h
|
| 4 |
+
|
| 5 |
+
#include <c10/core/Scalar.h>
|
| 6 |
+
#include <c10/core/Storage.h>
|
| 7 |
+
#include <c10/core/TensorOptions.h>
|
| 8 |
+
#include <c10/util/Deprecated.h>
|
| 9 |
+
#include <c10/util/Optional.h>
|
| 10 |
+
#include <c10/core/QScheme.h>
|
| 11 |
+
#include <ATen/core/Reduction.h>
|
| 12 |
+
#include <ATen/core/Tensor.h>
|
| 13 |
+
#include <tuple>
|
| 14 |
+
#include <vector>
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
namespace at {
|
| 18 |
+
namespace native {
|
| 19 |
+
TORCH_API int64_t _debug_has_internal_overlap(const at::Tensor & self);
|
| 20 |
+
} // namespace native
|
| 21 |
+
} // namespace at
|
parrot/lib/python3.10/site-packages/torch/include/ATen/ops/_foreach_norm.h
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from Function.h
|
| 4 |
+
|
| 5 |
+
#include <ATen/Context.h>
|
| 6 |
+
#include <ATen/DeviceGuard.h>
|
| 7 |
+
#include <ATen/TensorUtils.h>
|
| 8 |
+
#include <ATen/TracerMode.h>
|
| 9 |
+
#include <ATen/core/Generator.h>
|
| 10 |
+
#include <ATen/core/Reduction.h>
|
| 11 |
+
#include <ATen/core/Tensor.h>
|
| 12 |
+
#include <c10/core/Scalar.h>
|
| 13 |
+
#include <c10/core/Storage.h>
|
| 14 |
+
#include <c10/core/TensorOptions.h>
|
| 15 |
+
#include <c10/util/Deprecated.h>
|
| 16 |
+
#include <c10/util/Optional.h>
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
#include <ATen/ops/_foreach_norm_ops.h>
|
| 21 |
+
|
| 22 |
+
namespace at {
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
// aten::_foreach_norm.Scalar(Tensor[] self, Scalar ord=2, ScalarType? dtype=None) -> Tensor[]
|
| 26 |
+
inline ::std::vector<at::Tensor> _foreach_norm(at::TensorList self, const at::Scalar & ord=2, ::std::optional<at::ScalarType> dtype=::std::nullopt) {
|
| 27 |
+
return at::_ops::_foreach_norm_Scalar::call(self, ord, dtype);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
// aten::_foreach_norm.Scalar_out(Tensor[] self, Scalar ord=2, ScalarType? dtype=None, *, Tensor(a!)[] out) -> ()
|
| 31 |
+
inline void _foreach_norm_out(at::TensorList out, at::TensorList self, const at::Scalar & ord=2, ::std::optional<at::ScalarType> dtype=::std::nullopt) {
|
| 32 |
+
return at::_ops::_foreach_norm_Scalar_out::call(self, ord, dtype, out);
|
| 33 |
+
}
|
| 34 |
+
// aten::_foreach_norm.Scalar_out(Tensor[] self, Scalar ord=2, ScalarType? dtype=None, *, Tensor(a!)[] out) -> ()
|
| 35 |
+
inline void _foreach_norm_outf(at::TensorList self, const at::Scalar & ord, ::std::optional<at::ScalarType> dtype, at::TensorList out) {
|
| 36 |
+
return at::_ops::_foreach_norm_Scalar_out::call(self, ord, dtype, out);
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
}
|
parrot/lib/python3.10/site-packages/torch/include/ATen/ops/_foreach_round_compositeexplicitautograd_dispatch.h
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// @generated by torchgen/gen.py from DispatchKeyFunction.h
|
| 3 |
+
|
| 4 |
+
// NB: The implementing C++ file is RegisterDispatchKey.cpp
|
| 5 |
+
|
| 6 |
+
// The only #includes we need are for custom classes that have defaults in the C++ API
|
| 7 |
+
#include <c10/core/MemoryFormat.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <ATen/core/Reduction.h>
|
| 10 |
+
|
| 11 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 12 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 13 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 14 |
+
#include <ATen/core/ATen_fwd.h>
|
| 15 |
+
|
| 16 |
+
namespace at {
|
| 17 |
+
|
| 18 |
+
namespace compositeexplicitautograd {
|
| 19 |
+
|
| 20 |
+
TORCH_API ::std::vector<at::Tensor> _foreach_round(at::TensorList self);
|
| 21 |
+
TORCH_API void _foreach_round_out(at::TensorList out, at::TensorList self);
|
| 22 |
+
TORCH_API void _foreach_round_outf(at::TensorList self, at::TensorList out);
|
| 23 |
+
TORCH_API void _foreach_round_(at::TensorList self);
|
| 24 |
+
|
| 25 |
+
} // namespace compositeexplicitautograd
|
| 26 |
+
} // namespace at
|
parrot/lib/python3.10/site-packages/torch/include/ATen/ops/_histogramdd_bin_edges_ops.h
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from Operator.h
|
| 4 |
+
|
| 5 |
+
#include <tuple>
|
| 6 |
+
#include <vector>
|
| 7 |
+
|
| 8 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 9 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 10 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 11 |
+
#include <ATen/core/ATen_fwd.h>
|
| 12 |
+
|
| 13 |
+
namespace at {
|
| 14 |
+
namespace _ops {
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
struct TORCH_API _histogramdd_bin_edges {
|
| 18 |
+
using schema = ::std::vector<at::Tensor> (const at::Tensor &, at::IntArrayRef, ::std::optional<at::ArrayRef<double>>, const ::std::optional<at::Tensor> &, bool);
|
| 19 |
+
using ptr_schema = schema*;
|
| 20 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 21 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::_histogramdd_bin_edges")
|
| 22 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "")
|
| 23 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "_histogramdd_bin_edges(Tensor self, int[] bins, *, float[]? range=None, Tensor? weight=None, bool density=False) -> Tensor[]")
|
| 24 |
+
static ::std::vector<at::Tensor> call(const at::Tensor & self, at::IntArrayRef bins, ::std::optional<at::ArrayRef<double>> range, const ::std::optional<at::Tensor> & weight, bool density);
|
| 25 |
+
static ::std::vector<at::Tensor> redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & self, at::IntArrayRef bins, ::std::optional<at::ArrayRef<double>> range, const ::std::optional<at::Tensor> & weight, bool density);
|
| 26 |
+
};
|
| 27 |
+
|
| 28 |
+
struct TORCH_API _histogramdd_bin_edges_out {
|
| 29 |
+
using schema = void (const at::Tensor &, at::IntArrayRef, ::std::optional<at::ArrayRef<double>>, const ::std::optional<at::Tensor> &, bool, at::TensorList);
|
| 30 |
+
using ptr_schema = schema*;
|
| 31 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 32 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::_histogramdd_bin_edges")
|
| 33 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "out")
|
| 34 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "_histogramdd_bin_edges.out(Tensor self, int[] bins, *, float[]? range=None, Tensor? weight=None, bool density=False, Tensor(a!)[] out) -> ()")
|
| 35 |
+
static void call(const at::Tensor & self, at::IntArrayRef bins, ::std::optional<at::ArrayRef<double>> range, const ::std::optional<at::Tensor> & weight, bool density, at::TensorList out);
|
| 36 |
+
static void redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & self, at::IntArrayRef bins, ::std::optional<at::ArrayRef<double>> range, const ::std::optional<at::Tensor> & weight, bool density, at::TensorList out);
|
| 37 |
+
};
|
| 38 |
+
|
| 39 |
+
}} // namespace at::_ops
|
parrot/lib/python3.10/site-packages/torch/include/ATen/ops/_histogramdd_from_bin_tensors_cpu_dispatch.h
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// @generated by torchgen/gen.py from DispatchKeyFunction.h
|
| 3 |
+
|
| 4 |
+
// NB: The implementing C++ file is RegisterDispatchKey.cpp
|
| 5 |
+
|
| 6 |
+
// The only #includes we need are for custom classes that have defaults in the C++ API
|
| 7 |
+
#include <c10/core/MemoryFormat.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <ATen/core/Reduction.h>
|
| 10 |
+
|
| 11 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 12 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 13 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 14 |
+
#include <ATen/core/ATen_fwd.h>
|
| 15 |
+
|
| 16 |
+
namespace at {
|
| 17 |
+
|
| 18 |
+
namespace cpu {
|
| 19 |
+
|
| 20 |
+
TORCH_API at::Tensor _histogramdd_from_bin_tensors(const at::Tensor & self, at::TensorList bins, const ::std::optional<at::Tensor> & weight={}, bool density=false);
|
| 21 |
+
|
| 22 |
+
} // namespace cpu
|
| 23 |
+
} // namespace at
|
parrot/lib/python3.10/site-packages/torch/include/ATen/ops/_mps_convolution_transpose.h
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from Function.h
|
| 4 |
+
|
| 5 |
+
#include <ATen/Context.h>
|
| 6 |
+
#include <ATen/DeviceGuard.h>
|
| 7 |
+
#include <ATen/TensorUtils.h>
|
| 8 |
+
#include <ATen/TracerMode.h>
|
| 9 |
+
#include <ATen/core/Generator.h>
|
| 10 |
+
#include <ATen/core/Reduction.h>
|
| 11 |
+
#include <ATen/core/Tensor.h>
|
| 12 |
+
#include <c10/core/Scalar.h>
|
| 13 |
+
#include <c10/core/Storage.h>
|
| 14 |
+
#include <c10/core/TensorOptions.h>
|
| 15 |
+
#include <c10/util/Deprecated.h>
|
| 16 |
+
#include <c10/util/Optional.h>
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
#include <ATen/ops/_mps_convolution_transpose_ops.h>
|
| 21 |
+
|
| 22 |
+
namespace at {
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
// aten::_mps_convolution_transpose(Tensor self, Tensor weight, SymInt[] padding, SymInt[] output_padding, SymInt[] stride, SymInt[] dilation, SymInt groups) -> Tensor
|
| 26 |
+
inline at::Tensor _mps_convolution_transpose(const at::Tensor & self, const at::Tensor & weight, at::IntArrayRef padding, at::IntArrayRef output_padding, at::IntArrayRef stride, at::IntArrayRef dilation, int64_t groups) {
|
| 27 |
+
return at::_ops::_mps_convolution_transpose::call(self, weight, c10::fromIntArrayRefSlow(padding), c10::fromIntArrayRefSlow(output_padding), c10::fromIntArrayRefSlow(stride), c10::fromIntArrayRefSlow(dilation), groups);
|
| 28 |
+
}
|
| 29 |
+
namespace symint {
|
| 30 |
+
template <typename T, typename = std::enable_if_t<std::is_same<T, int64_t>::value>>
|
| 31 |
+
at::Tensor _mps_convolution_transpose(const at::Tensor & self, const at::Tensor & weight, at::IntArrayRef padding, at::IntArrayRef output_padding, at::IntArrayRef stride, at::IntArrayRef dilation, int64_t groups) {
|
| 32 |
+
return at::_ops::_mps_convolution_transpose::call(self, weight, c10::fromIntArrayRefSlow(padding), c10::fromIntArrayRefSlow(output_padding), c10::fromIntArrayRefSlow(stride), c10::fromIntArrayRefSlow(dilation), groups);
|
| 33 |
+
}
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
// aten::_mps_convolution_transpose(Tensor self, Tensor weight, SymInt[] padding, SymInt[] output_padding, SymInt[] stride, SymInt[] dilation, SymInt groups) -> Tensor
|
| 37 |
+
inline at::Tensor _mps_convolution_transpose_symint(const at::Tensor & self, const at::Tensor & weight, c10::SymIntArrayRef padding, c10::SymIntArrayRef output_padding, c10::SymIntArrayRef stride, c10::SymIntArrayRef dilation, c10::SymInt groups) {
|
| 38 |
+
return at::_ops::_mps_convolution_transpose::call(self, weight, padding, output_padding, stride, dilation, groups);
|
| 39 |
+
}
|
| 40 |
+
namespace symint {
|
| 41 |
+
template <typename T, typename = std::enable_if_t<std::is_same<T, c10::SymInt>::value>>
|
| 42 |
+
at::Tensor _mps_convolution_transpose(const at::Tensor & self, const at::Tensor & weight, c10::SymIntArrayRef padding, c10::SymIntArrayRef output_padding, c10::SymIntArrayRef stride, c10::SymIntArrayRef dilation, c10::SymInt groups) {
|
| 43 |
+
return at::_ops::_mps_convolution_transpose::call(self, weight, padding, output_padding, stride, dilation, groups);
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
// aten::_mps_convolution_transpose.out(Tensor self, Tensor weight, SymInt[] padding, SymInt[] output_padding, SymInt[] stride, SymInt[] dilation, SymInt groups, *, Tensor(a!) out) -> Tensor(a!)
|
| 48 |
+
inline at::Tensor & _mps_convolution_transpose_out(at::Tensor & out, const at::Tensor & self, const at::Tensor & weight, at::IntArrayRef padding, at::IntArrayRef output_padding, at::IntArrayRef stride, at::IntArrayRef dilation, int64_t groups) {
|
| 49 |
+
return at::_ops::_mps_convolution_transpose_out::call(self, weight, c10::fromIntArrayRefSlow(padding), c10::fromIntArrayRefSlow(output_padding), c10::fromIntArrayRefSlow(stride), c10::fromIntArrayRefSlow(dilation), groups, out);
|
| 50 |
+
}
|
| 51 |
+
namespace symint {
|
| 52 |
+
template <typename T, typename = std::enable_if_t<std::is_same<T, int64_t>::value>>
|
| 53 |
+
at::Tensor & _mps_convolution_transpose_out(at::Tensor & out, const at::Tensor & self, const at::Tensor & weight, at::IntArrayRef padding, at::IntArrayRef output_padding, at::IntArrayRef stride, at::IntArrayRef dilation, int64_t groups) {
|
| 54 |
+
return at::_ops::_mps_convolution_transpose_out::call(self, weight, c10::fromIntArrayRefSlow(padding), c10::fromIntArrayRefSlow(output_padding), c10::fromIntArrayRefSlow(stride), c10::fromIntArrayRefSlow(dilation), groups, out);
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
// aten::_mps_convolution_transpose.out(Tensor self, Tensor weight, SymInt[] padding, SymInt[] output_padding, SymInt[] stride, SymInt[] dilation, SymInt groups, *, Tensor(a!) out) -> Tensor(a!)
|
| 59 |
+
inline at::Tensor & _mps_convolution_transpose_outf(const at::Tensor & self, const at::Tensor & weight, at::IntArrayRef padding, at::IntArrayRef output_padding, at::IntArrayRef stride, at::IntArrayRef dilation, int64_t groups, at::Tensor & out) {
|
| 60 |
+
return at::_ops::_mps_convolution_transpose_out::call(self, weight, c10::fromIntArrayRefSlow(padding), c10::fromIntArrayRefSlow(output_padding), c10::fromIntArrayRefSlow(stride), c10::fromIntArrayRefSlow(dilation), groups, out);
|
| 61 |
+
}
|
| 62 |
+
namespace symint {
|
| 63 |
+
template <typename T, typename = std::enable_if_t<std::is_same<T, int64_t>::value>>
|
| 64 |
+
at::Tensor & _mps_convolution_transpose_outf(const at::Tensor & self, const at::Tensor & weight, at::IntArrayRef padding, at::IntArrayRef output_padding, at::IntArrayRef stride, at::IntArrayRef dilation, int64_t groups, at::Tensor & out) {
|
| 65 |
+
return at::_ops::_mps_convolution_transpose_out::call(self, weight, c10::fromIntArrayRefSlow(padding), c10::fromIntArrayRefSlow(output_padding), c10::fromIntArrayRefSlow(stride), c10::fromIntArrayRefSlow(dilation), groups, out);
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
// aten::_mps_convolution_transpose.out(Tensor self, Tensor weight, SymInt[] padding, SymInt[] output_padding, SymInt[] stride, SymInt[] dilation, SymInt groups, *, Tensor(a!) out) -> Tensor(a!)
|
| 70 |
+
inline at::Tensor & _mps_convolution_transpose_symint_out(at::Tensor & out, const at::Tensor & self, const at::Tensor & weight, c10::SymIntArrayRef padding, c10::SymIntArrayRef output_padding, c10::SymIntArrayRef stride, c10::SymIntArrayRef dilation, c10::SymInt groups) {
|
| 71 |
+
return at::_ops::_mps_convolution_transpose_out::call(self, weight, padding, output_padding, stride, dilation, groups, out);
|
| 72 |
+
}
|
| 73 |
+
namespace symint {
|
| 74 |
+
template <typename T, typename = std::enable_if_t<std::is_same<T, c10::SymInt>::value>>
|
| 75 |
+
at::Tensor & _mps_convolution_transpose_out(at::Tensor & out, const at::Tensor & self, const at::Tensor & weight, c10::SymIntArrayRef padding, c10::SymIntArrayRef output_padding, c10::SymIntArrayRef stride, c10::SymIntArrayRef dilation, c10::SymInt groups) {
|
| 76 |
+
return at::_ops::_mps_convolution_transpose_out::call(self, weight, padding, output_padding, stride, dilation, groups, out);
|
| 77 |
+
}
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
// aten::_mps_convolution_transpose.out(Tensor self, Tensor weight, SymInt[] padding, SymInt[] output_padding, SymInt[] stride, SymInt[] dilation, SymInt groups, *, Tensor(a!) out) -> Tensor(a!)
|
| 81 |
+
inline at::Tensor & _mps_convolution_transpose_symint_outf(const at::Tensor & self, const at::Tensor & weight, c10::SymIntArrayRef padding, c10::SymIntArrayRef output_padding, c10::SymIntArrayRef stride, c10::SymIntArrayRef dilation, c10::SymInt groups, at::Tensor & out) {
|
| 82 |
+
return at::_ops::_mps_convolution_transpose_out::call(self, weight, padding, output_padding, stride, dilation, groups, out);
|
| 83 |
+
}
|
| 84 |
+
namespace symint {
|
| 85 |
+
template <typename T, typename = std::enable_if_t<std::is_same<T, c10::SymInt>::value>>
|
| 86 |
+
at::Tensor & _mps_convolution_transpose_outf(const at::Tensor & self, const at::Tensor & weight, c10::SymIntArrayRef padding, c10::SymIntArrayRef output_padding, c10::SymIntArrayRef stride, c10::SymIntArrayRef dilation, c10::SymInt groups, at::Tensor & out) {
|
| 87 |
+
return at::_ops::_mps_convolution_transpose_out::call(self, weight, padding, output_padding, stride, dilation, groups, out);
|
| 88 |
+
}
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
}
|
parrot/lib/python3.10/site-packages/torch/include/ATen/ops/_sample_dirichlet_ops.h
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from Operator.h
|
| 4 |
+
|
| 5 |
+
#include <tuple>
|
| 6 |
+
#include <vector>
|
| 7 |
+
|
| 8 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 9 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 10 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 11 |
+
#include <ATen/core/ATen_fwd.h>
|
| 12 |
+
|
| 13 |
+
namespace at {
|
| 14 |
+
namespace _ops {
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
struct TORCH_API _sample_dirichlet {
|
| 18 |
+
using schema = at::Tensor (const at::Tensor &, ::std::optional<at::Generator>);
|
| 19 |
+
using ptr_schema = schema*;
|
| 20 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 21 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::_sample_dirichlet")
|
| 22 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "")
|
| 23 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "_sample_dirichlet(Tensor self, Generator? generator=None) -> Tensor")
|
| 24 |
+
static at::Tensor call(const at::Tensor & self, ::std::optional<at::Generator> generator);
|
| 25 |
+
static at::Tensor redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & self, ::std::optional<at::Generator> generator);
|
| 26 |
+
};
|
| 27 |
+
|
| 28 |
+
struct TORCH_API _sample_dirichlet_out {
|
| 29 |
+
using schema = at::Tensor & (const at::Tensor &, ::std::optional<at::Generator>, at::Tensor &);
|
| 30 |
+
using ptr_schema = schema*;
|
| 31 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 32 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::_sample_dirichlet")
|
| 33 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "out")
|
| 34 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "_sample_dirichlet.out(Tensor self, Generator? generator=None, *, Tensor(a!) out) -> Tensor(a!)")
|
| 35 |
+
static at::Tensor & call(const at::Tensor & self, ::std::optional<at::Generator> generator, at::Tensor & out);
|
| 36 |
+
static at::Tensor & redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & self, ::std::optional<at::Generator> generator, at::Tensor & out);
|
| 37 |
+
};
|
| 38 |
+
|
| 39 |
+
}} // namespace at::_ops
|
parrot/lib/python3.10/site-packages/torch/include/ATen/ops/_segment_reduce_backward_ops.h
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from Operator.h
|
| 4 |
+
|
| 5 |
+
#include <tuple>
|
| 6 |
+
#include <vector>
|
| 7 |
+
|
| 8 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 9 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 10 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 11 |
+
#include <ATen/core/ATen_fwd.h>
|
| 12 |
+
|
| 13 |
+
namespace at {
|
| 14 |
+
namespace _ops {
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
struct TORCH_API _segment_reduce_backward {
|
| 18 |
+
using schema = at::Tensor (const at::Tensor &, const at::Tensor &, const at::Tensor &, c10::string_view, const ::std::optional<at::Tensor> &, const ::std::optional<at::Tensor> &, int64_t, const ::std::optional<at::Scalar> &);
|
| 19 |
+
using ptr_schema = schema*;
|
| 20 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 21 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::_segment_reduce_backward")
|
| 22 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "")
|
| 23 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "_segment_reduce_backward(Tensor grad, Tensor output, Tensor data, str reduce, *, Tensor? lengths=None, Tensor? offsets=None, int axis=0, Scalar? initial=None) -> Tensor")
|
| 24 |
+
static at::Tensor call(const at::Tensor & grad, const at::Tensor & output, const at::Tensor & data, c10::string_view reduce, const ::std::optional<at::Tensor> & lengths, const ::std::optional<at::Tensor> & offsets, int64_t axis, const ::std::optional<at::Scalar> & initial);
|
| 25 |
+
static at::Tensor redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & grad, const at::Tensor & output, const at::Tensor & data, c10::string_view reduce, const ::std::optional<at::Tensor> & lengths, const ::std::optional<at::Tensor> & offsets, int64_t axis, const ::std::optional<at::Scalar> & initial);
|
| 26 |
+
};
|
| 27 |
+
|
| 28 |
+
struct TORCH_API _segment_reduce_backward_out {
|
| 29 |
+
using schema = at::Tensor & (const at::Tensor &, const at::Tensor &, const at::Tensor &, c10::string_view, const ::std::optional<at::Tensor> &, const ::std::optional<at::Tensor> &, int64_t, const ::std::optional<at::Scalar> &, at::Tensor &);
|
| 30 |
+
using ptr_schema = schema*;
|
| 31 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 32 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::_segment_reduce_backward")
|
| 33 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "out")
|
| 34 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "_segment_reduce_backward.out(Tensor grad, Tensor output, Tensor data, str reduce, *, Tensor? lengths=None, Tensor? offsets=None, int axis=0, Scalar? initial=None, Tensor(a!) out) -> Tensor(a!)")
|
| 35 |
+
static at::Tensor & call(const at::Tensor & grad, const at::Tensor & output, const at::Tensor & data, c10::string_view reduce, const ::std::optional<at::Tensor> & lengths, const ::std::optional<at::Tensor> & offsets, int64_t axis, const ::std::optional<at::Scalar> & initial, at::Tensor & out);
|
| 36 |
+
static at::Tensor & redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & grad, const at::Tensor & output, const at::Tensor & data, c10::string_view reduce, const ::std::optional<at::Tensor> & lengths, const ::std::optional<at::Tensor> & offsets, int64_t axis, const ::std::optional<at::Scalar> & initial, at::Tensor & out);
|
| 37 |
+
};
|
| 38 |
+
|
| 39 |
+
}} // namespace at::_ops
|
parrot/lib/python3.10/site-packages/torch/include/ATen/ops/_sobol_engine_ff.h
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from Function.h
|
| 4 |
+
|
| 5 |
+
#include <ATen/Context.h>
|
| 6 |
+
#include <ATen/DeviceGuard.h>
|
| 7 |
+
#include <ATen/TensorUtils.h>
|
| 8 |
+
#include <ATen/TracerMode.h>
|
| 9 |
+
#include <ATen/core/Generator.h>
|
| 10 |
+
#include <ATen/core/Reduction.h>
|
| 11 |
+
#include <ATen/core/Tensor.h>
|
| 12 |
+
#include <c10/core/Scalar.h>
|
| 13 |
+
#include <c10/core/Storage.h>
|
| 14 |
+
#include <c10/core/TensorOptions.h>
|
| 15 |
+
#include <c10/util/Deprecated.h>
|
| 16 |
+
#include <c10/util/Optional.h>
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
#include <ATen/ops/_sobol_engine_ff_ops.h>
|
| 21 |
+
|
| 22 |
+
namespace at {
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
// aten::_sobol_engine_ff_(Tensor(a!) self, int n, Tensor sobolstate, int dimension, int num_generated) -> Tensor(a!)
|
| 26 |
+
inline at::Tensor & _sobol_engine_ff_(at::Tensor & self, int64_t n, const at::Tensor & sobolstate, int64_t dimension, int64_t num_generated) {
|
| 27 |
+
return at::_ops::_sobol_engine_ff_::call(self, n, sobolstate, dimension, num_generated);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
}
|
parrot/lib/python3.10/site-packages/torch/include/ATen/ops/_sparse_log_softmax_backward_data_native.h
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from NativeFunction.h
|
| 4 |
+
|
| 5 |
+
#include <c10/core/Scalar.h>
|
| 6 |
+
#include <c10/core/Storage.h>
|
| 7 |
+
#include <c10/core/TensorOptions.h>
|
| 8 |
+
#include <c10/util/Deprecated.h>
|
| 9 |
+
#include <c10/util/Optional.h>
|
| 10 |
+
#include <c10/core/QScheme.h>
|
| 11 |
+
#include <ATen/core/Reduction.h>
|
| 12 |
+
#include <ATen/core/Tensor.h>
|
| 13 |
+
#include <tuple>
|
| 14 |
+
#include <vector>
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
namespace at {
|
| 18 |
+
namespace native {
|
| 19 |
+
TORCH_API at::Tensor & _sparse_log_softmax_backward_data_out(const at::Tensor & grad_output, const at::Tensor & output, int64_t dim, const at::Tensor & self, at::Tensor & out);
|
| 20 |
+
TORCH_API at::Tensor log_softmax_backward_sparse_cpu(const at::Tensor & grad_output, const at::Tensor & output, int64_t dim, const at::Tensor & self);
|
| 21 |
+
TORCH_API at::Tensor log_softmax_backward_sparse_cuda(const at::Tensor & grad_output, const at::Tensor & output, int64_t dim, const at::Tensor & self);
|
| 22 |
+
} // namespace native
|
| 23 |
+
} // namespace at
|
parrot/lib/python3.10/site-packages/torch/include/ATen/ops/_upsample_bicubic2d_aa_backward_native.h
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from NativeFunction.h
|
| 4 |
+
|
| 5 |
+
#include <c10/core/Scalar.h>
|
| 6 |
+
#include <c10/core/Storage.h>
|
| 7 |
+
#include <c10/core/TensorOptions.h>
|
| 8 |
+
#include <c10/util/Deprecated.h>
|
| 9 |
+
#include <c10/util/Optional.h>
|
| 10 |
+
#include <c10/core/QScheme.h>
|
| 11 |
+
#include <ATen/core/Reduction.h>
|
| 12 |
+
#include <ATen/core/Tensor.h>
|
| 13 |
+
#include <tuple>
|
| 14 |
+
#include <vector>
|
| 15 |
+
#include <ATen/ops/_upsample_bicubic2d_aa_backward_meta.h>
|
| 16 |
+
|
| 17 |
+
namespace at {
|
| 18 |
+
namespace native {
|
| 19 |
+
struct TORCH_API structured__upsample_bicubic2d_aa_backward_out_cpu : public at::meta::structured__upsample_bicubic2d_aa_backward {
|
| 20 |
+
void impl(const at::Tensor & grad_output, at::ArrayRef<int64_t> output_size, at::ArrayRef<int64_t> input_size, bool align_corners, ::std::optional<double> scales_h, ::std::optional<double> scales_w, const at::Tensor & grad_input);
|
| 21 |
+
};
|
| 22 |
+
struct TORCH_API structured__upsample_bicubic2d_aa_backward_out_cuda : public at::meta::structured__upsample_bicubic2d_aa_backward {
|
| 23 |
+
void impl(const at::Tensor & grad_output, at::ArrayRef<int64_t> output_size, at::ArrayRef<int64_t> input_size, bool align_corners, ::std::optional<double> scales_h, ::std::optional<double> scales_w, const at::Tensor & grad_input);
|
| 24 |
+
};
|
| 25 |
+
} // namespace native
|
| 26 |
+
} // namespace at
|
parrot/lib/python3.10/site-packages/torch/include/ATen/ops/_weight_int4pack_mm.h
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from Function.h
|
| 4 |
+
|
| 5 |
+
#include <ATen/Context.h>
|
| 6 |
+
#include <ATen/DeviceGuard.h>
|
| 7 |
+
#include <ATen/TensorUtils.h>
|
| 8 |
+
#include <ATen/TracerMode.h>
|
| 9 |
+
#include <ATen/core/Generator.h>
|
| 10 |
+
#include <ATen/core/Reduction.h>
|
| 11 |
+
#include <ATen/core/Tensor.h>
|
| 12 |
+
#include <c10/core/Scalar.h>
|
| 13 |
+
#include <c10/core/Storage.h>
|
| 14 |
+
#include <c10/core/TensorOptions.h>
|
| 15 |
+
#include <c10/util/Deprecated.h>
|
| 16 |
+
#include <c10/util/Optional.h>
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
#include <ATen/ops/_weight_int4pack_mm_ops.h>
|
| 21 |
+
|
| 22 |
+
namespace at {
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
// aten::_weight_int4pack_mm(Tensor self, Tensor mat2, int qGroupSize, Tensor qScaleAndZeros) -> Tensor
|
| 26 |
+
inline at::Tensor _weight_int4pack_mm(const at::Tensor & self, const at::Tensor & mat2, int64_t qGroupSize, const at::Tensor & qScaleAndZeros) {
|
| 27 |
+
return at::_ops::_weight_int4pack_mm::call(self, mat2, qGroupSize, qScaleAndZeros);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
}
|
parrot/lib/python3.10/site-packages/torch/include/ATen/ops/_weight_norm_interface_backward_native.h
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from NativeFunction.h
|
| 4 |
+
|
| 5 |
+
#include <c10/core/Scalar.h>
|
| 6 |
+
#include <c10/core/Storage.h>
|
| 7 |
+
#include <c10/core/TensorOptions.h>
|
| 8 |
+
#include <c10/util/Deprecated.h>
|
| 9 |
+
#include <c10/util/Optional.h>
|
| 10 |
+
#include <c10/core/QScheme.h>
|
| 11 |
+
#include <ATen/core/Reduction.h>
|
| 12 |
+
#include <ATen/core/Tensor.h>
|
| 13 |
+
#include <tuple>
|
| 14 |
+
#include <vector>
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
namespace at {
|
| 18 |
+
namespace native {
|
| 19 |
+
TORCH_API ::std::tuple<at::Tensor &,at::Tensor &> _weight_norm_interface_backward_out(const at::Tensor & grad_w, const at::Tensor & saved_v, const at::Tensor & saved_g, const at::Tensor & saved_norms, int64_t dim, at::Tensor & out0, at::Tensor & out1);
|
| 20 |
+
TORCH_API ::std::tuple<at::Tensor,at::Tensor> weight_norm_backward_cpu(const at::Tensor & grad_w, const at::Tensor & saved_v, const at::Tensor & saved_g, const at::Tensor & saved_norms, int64_t dim);
|
| 21 |
+
TORCH_API ::std::tuple<at::Tensor,at::Tensor> weight_norm_backward_cuda(const at::Tensor & grad_w, const at::Tensor & saved_v, const at::Tensor & saved_g, const at::Tensor & saved_norms, int64_t dim);
|
| 22 |
+
} // namespace native
|
| 23 |
+
} // namespace at
|
parrot/lib/python3.10/site-packages/torch/include/ATen/ops/amax_cuda_dispatch.h
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// @generated by torchgen/gen.py from DispatchKeyFunction.h
|
| 3 |
+
|
| 4 |
+
// NB: The implementing C++ file is RegisterDispatchKey.cpp
|
| 5 |
+
|
| 6 |
+
// The only #includes we need are for custom classes that have defaults in the C++ API
|
| 7 |
+
#include <c10/core/MemoryFormat.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <ATen/core/Reduction.h>
|
| 10 |
+
|
| 11 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 12 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 13 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 14 |
+
#include <ATen/core/ATen_fwd.h>
|
| 15 |
+
|
| 16 |
+
namespace at {
|
| 17 |
+
|
| 18 |
+
namespace cuda {
|
| 19 |
+
|
| 20 |
+
TORCH_API at::Tensor amax(const at::Tensor & self, at::IntArrayRef dim={}, bool keepdim=false);
|
| 21 |
+
TORCH_API at::Tensor & amax_out(at::Tensor & out, const at::Tensor & self, at::IntArrayRef dim={}, bool keepdim=false);
|
| 22 |
+
TORCH_API at::Tensor & amax_outf(const at::Tensor & self, at::IntArrayRef dim, bool keepdim, at::Tensor & out);
|
| 23 |
+
|
| 24 |
+
} // namespace cuda
|
| 25 |
+
} // namespace at
|
parrot/lib/python3.10/site-packages/torch/include/ATen/ops/atleast_1d.h
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from Function.h
|
| 4 |
+
|
| 5 |
+
#include <ATen/Context.h>
|
| 6 |
+
#include <ATen/DeviceGuard.h>
|
| 7 |
+
#include <ATen/TensorUtils.h>
|
| 8 |
+
#include <ATen/TracerMode.h>
|
| 9 |
+
#include <ATen/core/Generator.h>
|
| 10 |
+
#include <ATen/core/Reduction.h>
|
| 11 |
+
#include <ATen/core/Tensor.h>
|
| 12 |
+
#include <c10/core/Scalar.h>
|
| 13 |
+
#include <c10/core/Storage.h>
|
| 14 |
+
#include <c10/core/TensorOptions.h>
|
| 15 |
+
#include <c10/util/Deprecated.h>
|
| 16 |
+
#include <c10/util/Optional.h>
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
#include <ATen/ops/atleast_1d_ops.h>
|
| 21 |
+
|
| 22 |
+
namespace at {
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
// aten::atleast_1d(Tensor self) -> Tensor
|
| 26 |
+
inline at::Tensor atleast_1d(const at::Tensor & self) {
|
| 27 |
+
return at::_ops::atleast_1d::call(self);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
// aten::atleast_1d.Sequence(Tensor[] tensors) -> Tensor[]
|
| 31 |
+
inline ::std::vector<at::Tensor> atleast_1d(at::TensorList tensors) {
|
| 32 |
+
return at::_ops::atleast_1d_Sequence::call(tensors);
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
}
|
parrot/lib/python3.10/site-packages/torch/include/ATen/ops/batch_norm_backward_elemt_native.h
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from NativeFunction.h
|
| 4 |
+
|
| 5 |
+
#include <c10/core/Scalar.h>
|
| 6 |
+
#include <c10/core/Storage.h>
|
| 7 |
+
#include <c10/core/TensorOptions.h>
|
| 8 |
+
#include <c10/util/Deprecated.h>
|
| 9 |
+
#include <c10/util/Optional.h>
|
| 10 |
+
#include <c10/core/QScheme.h>
|
| 11 |
+
#include <ATen/core/Reduction.h>
|
| 12 |
+
#include <ATen/core/Tensor.h>
|
| 13 |
+
#include <tuple>
|
| 14 |
+
#include <vector>
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
namespace at {
|
| 18 |
+
namespace native {
|
| 19 |
+
TORCH_API at::Tensor & batch_norm_backward_elemt_out(const at::Tensor & grad_out, const at::Tensor & input, const at::Tensor & mean, const at::Tensor & invstd, const ::std::optional<at::Tensor> & weight, const at::Tensor & sum_dy, const at::Tensor & sum_dy_xmu, const at::Tensor & count, at::Tensor & out);
|
| 20 |
+
TORCH_API at::Tensor batch_norm_backward_elemt_cuda(const at::Tensor & grad_out, const at::Tensor & input, const at::Tensor & mean, const at::Tensor & invstd, const ::std::optional<at::Tensor> & weight, const at::Tensor & sum_dy, const at::Tensor & sum_dy_xmu, const at::Tensor & count);
|
| 21 |
+
} // namespace native
|
| 22 |
+
} // namespace at
|
parrot/lib/python3.10/site-packages/torch/include/ATen/ops/bitwise_right_shift.h
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from Function.h
|
| 4 |
+
|
| 5 |
+
#include <ATen/Context.h>
|
| 6 |
+
#include <ATen/DeviceGuard.h>
|
| 7 |
+
#include <ATen/TensorUtils.h>
|
| 8 |
+
#include <ATen/TracerMode.h>
|
| 9 |
+
#include <ATen/core/Generator.h>
|
| 10 |
+
#include <ATen/core/Reduction.h>
|
| 11 |
+
#include <ATen/core/Tensor.h>
|
| 12 |
+
#include <c10/core/Scalar.h>
|
| 13 |
+
#include <c10/core/Storage.h>
|
| 14 |
+
#include <c10/core/TensorOptions.h>
|
| 15 |
+
#include <c10/util/Deprecated.h>
|
| 16 |
+
#include <c10/util/Optional.h>
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
#include <ATen/ops/bitwise_right_shift_ops.h>
|
| 21 |
+
|
| 22 |
+
namespace at {
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
// aten::bitwise_right_shift.Tensor(Tensor self, Tensor other) -> Tensor
|
| 26 |
+
inline at::Tensor bitwise_right_shift(const at::Tensor & self, const at::Tensor & other) {
|
| 27 |
+
return at::_ops::bitwise_right_shift_Tensor::call(self, other);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
// aten::bitwise_right_shift.Tensor_out(Tensor self, Tensor other, *, Tensor(a!) out) -> Tensor(a!)
|
| 31 |
+
inline at::Tensor & bitwise_right_shift_out(at::Tensor & out, const at::Tensor & self, const at::Tensor & other) {
|
| 32 |
+
return at::_ops::bitwise_right_shift_Tensor_out::call(self, other, out);
|
| 33 |
+
}
|
| 34 |
+
// aten::bitwise_right_shift.Tensor_out(Tensor self, Tensor other, *, Tensor(a!) out) -> Tensor(a!)
|
| 35 |
+
inline at::Tensor & bitwise_right_shift_outf(const at::Tensor & self, const at::Tensor & other, at::Tensor & out) {
|
| 36 |
+
return at::_ops::bitwise_right_shift_Tensor_out::call(self, other, out);
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
// aten::bitwise_right_shift.Tensor_Scalar(Tensor self, Scalar other) -> Tensor
|
| 40 |
+
inline at::Tensor bitwise_right_shift(const at::Tensor & self, const at::Scalar & other) {
|
| 41 |
+
return at::_ops::bitwise_right_shift_Tensor_Scalar::call(self, other);
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
// aten::bitwise_right_shift.Tensor_Scalar_out(Tensor self, Scalar other, *, Tensor(a!) out) -> Tensor(a!)
|
| 45 |
+
inline at::Tensor & bitwise_right_shift_out(at::Tensor & out, const at::Tensor & self, const at::Scalar & other) {
|
| 46 |
+
return at::_ops::bitwise_right_shift_Tensor_Scalar_out::call(self, other, out);
|
| 47 |
+
}
|
| 48 |
+
// aten::bitwise_right_shift.Tensor_Scalar_out(Tensor self, Scalar other, *, Tensor(a!) out) -> Tensor(a!)
|
| 49 |
+
inline at::Tensor & bitwise_right_shift_outf(const at::Tensor & self, const at::Scalar & other, at::Tensor & out) {
|
| 50 |
+
return at::_ops::bitwise_right_shift_Tensor_Scalar_out::call(self, other, out);
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
// aten::bitwise_right_shift.Scalar_Tensor(Scalar self, Tensor other) -> Tensor
|
| 54 |
+
inline at::Tensor bitwise_right_shift(const at::Scalar & self, const at::Tensor & other) {
|
| 55 |
+
return at::_ops::bitwise_right_shift_Scalar_Tensor::call(self, other);
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
// aten::bitwise_right_shift.Scalar_Tensor_out(Scalar self, Tensor other, *, Tensor(a!) out) -> Tensor(a!)
|
| 59 |
+
inline at::Tensor & bitwise_right_shift_out(at::Tensor & out, const at::Scalar & self, const at::Tensor & other) {
|
| 60 |
+
return at::_ops::bitwise_right_shift_Scalar_Tensor_out::call(self, other, out);
|
| 61 |
+
}
|
| 62 |
+
// aten::bitwise_right_shift.Scalar_Tensor_out(Scalar self, Tensor other, *, Tensor(a!) out) -> Tensor(a!)
|
| 63 |
+
inline at::Tensor & bitwise_right_shift_outf(const at::Scalar & self, const at::Tensor & other, at::Tensor & out) {
|
| 64 |
+
return at::_ops::bitwise_right_shift_Scalar_Tensor_out::call(self, other, out);
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
}
|
parrot/lib/python3.10/site-packages/torch/include/ATen/ops/chalf_native.h
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from NativeFunction.h
|
| 4 |
+
|
| 5 |
+
#include <c10/core/Scalar.h>
|
| 6 |
+
#include <c10/core/Storage.h>
|
| 7 |
+
#include <c10/core/TensorOptions.h>
|
| 8 |
+
#include <c10/util/Deprecated.h>
|
| 9 |
+
#include <c10/util/Optional.h>
|
| 10 |
+
#include <c10/core/QScheme.h>
|
| 11 |
+
#include <ATen/core/Reduction.h>
|
| 12 |
+
#include <ATen/core/Tensor.h>
|
| 13 |
+
#include <tuple>
|
| 14 |
+
#include <vector>
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
namespace at {
|
| 18 |
+
namespace native {
|
| 19 |
+
TORCH_API at::Tensor chalf(const at::Tensor & self, ::std::optional<at::MemoryFormat> memory_format=::std::nullopt);
|
| 20 |
+
} // namespace native
|
| 21 |
+
} // namespace at
|
parrot/lib/python3.10/site-packages/torch/include/ATen/ops/col2im_cpu_dispatch.h
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// @generated by torchgen/gen.py from DispatchKeyFunction.h
|
| 3 |
+
|
| 4 |
+
// NB: The implementing C++ file is RegisterDispatchKey.cpp
|
| 5 |
+
|
| 6 |
+
// The only #includes we need are for custom classes that have defaults in the C++ API
|
| 7 |
+
#include <c10/core/MemoryFormat.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <ATen/core/Reduction.h>
|
| 10 |
+
|
| 11 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 12 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 13 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 14 |
+
#include <ATen/core/ATen_fwd.h>
|
| 15 |
+
|
| 16 |
+
namespace at {
|
| 17 |
+
|
| 18 |
+
namespace cpu {
|
| 19 |
+
|
| 20 |
+
TORCH_API at::Tensor col2im(const at::Tensor & self, at::IntArrayRef output_size, at::IntArrayRef kernel_size, at::IntArrayRef dilation, at::IntArrayRef padding, at::IntArrayRef stride);
|
| 21 |
+
TORCH_API at::Tensor col2im_symint(const at::Tensor & self, c10::SymIntArrayRef output_size, at::IntArrayRef kernel_size, at::IntArrayRef dilation, at::IntArrayRef padding, at::IntArrayRef stride);
|
| 22 |
+
TORCH_API at::Tensor & col2im_out(at::Tensor & out, const at::Tensor & self, at::IntArrayRef output_size, at::IntArrayRef kernel_size, at::IntArrayRef dilation, at::IntArrayRef padding, at::IntArrayRef stride);
|
| 23 |
+
TORCH_API at::Tensor & col2im_outf(const at::Tensor & self, at::IntArrayRef output_size, at::IntArrayRef kernel_size, at::IntArrayRef dilation, at::IntArrayRef padding, at::IntArrayRef stride, at::Tensor & out);
|
| 24 |
+
TORCH_API at::Tensor & col2im_symint_out(at::Tensor & out, const at::Tensor & self, c10::SymIntArrayRef output_size, at::IntArrayRef kernel_size, at::IntArrayRef dilation, at::IntArrayRef padding, at::IntArrayRef stride);
|
| 25 |
+
TORCH_API at::Tensor & col2im_symint_outf(const at::Tensor & self, c10::SymIntArrayRef output_size, at::IntArrayRef kernel_size, at::IntArrayRef dilation, at::IntArrayRef padding, at::IntArrayRef stride, at::Tensor & out);
|
| 26 |
+
|
| 27 |
+
} // namespace cpu
|
| 28 |
+
} // namespace at
|
parrot/lib/python3.10/site-packages/torch/include/ATen/ops/cumsum_ops.h
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from Operator.h
|
| 4 |
+
|
| 5 |
+
#include <tuple>
|
| 6 |
+
#include <vector>
|
| 7 |
+
|
| 8 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 9 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 10 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 11 |
+
#include <ATen/core/ATen_fwd.h>
|
| 12 |
+
|
| 13 |
+
namespace at {
|
| 14 |
+
namespace _ops {
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
struct TORCH_API cumsum {
|
| 18 |
+
using schema = at::Tensor (const at::Tensor &, int64_t, ::std::optional<at::ScalarType>);
|
| 19 |
+
using ptr_schema = schema*;
|
| 20 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 21 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::cumsum")
|
| 22 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "")
|
| 23 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "cumsum(Tensor self, int dim, *, ScalarType? dtype=None) -> Tensor")
|
| 24 |
+
static at::Tensor call(const at::Tensor & self, int64_t dim, ::std::optional<at::ScalarType> dtype);
|
| 25 |
+
static at::Tensor redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & self, int64_t dim, ::std::optional<at::ScalarType> dtype);
|
| 26 |
+
};
|
| 27 |
+
|
| 28 |
+
struct TORCH_API cumsum_ {
|
| 29 |
+
using schema = at::Tensor & (at::Tensor &, int64_t, ::std::optional<at::ScalarType>);
|
| 30 |
+
using ptr_schema = schema*;
|
| 31 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 32 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::cumsum_")
|
| 33 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "")
|
| 34 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "cumsum_(Tensor(a!) self, int dim, *, ScalarType? dtype=None) -> Tensor(a!)")
|
| 35 |
+
static at::Tensor & call(at::Tensor & self, int64_t dim, ::std::optional<at::ScalarType> dtype);
|
| 36 |
+
static at::Tensor & redispatch(c10::DispatchKeySet dispatchKeySet, at::Tensor & self, int64_t dim, ::std::optional<at::ScalarType> dtype);
|
| 37 |
+
};
|
| 38 |
+
|
| 39 |
+
struct TORCH_API cumsum_out {
|
| 40 |
+
using schema = at::Tensor & (const at::Tensor &, int64_t, ::std::optional<at::ScalarType>, at::Tensor &);
|
| 41 |
+
using ptr_schema = schema*;
|
| 42 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 43 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::cumsum")
|
| 44 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "out")
|
| 45 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "cumsum.out(Tensor self, int dim, *, ScalarType? dtype=None, Tensor(a!) out) -> Tensor(a!)")
|
| 46 |
+
static at::Tensor & call(const at::Tensor & self, int64_t dim, ::std::optional<at::ScalarType> dtype, at::Tensor & out);
|
| 47 |
+
static at::Tensor & redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & self, int64_t dim, ::std::optional<at::ScalarType> dtype, at::Tensor & out);
|
| 48 |
+
};
|
| 49 |
+
|
| 50 |
+
struct TORCH_API cumsum_dimname {
|
| 51 |
+
using schema = at::Tensor (const at::Tensor &, at::Dimname, ::std::optional<at::ScalarType>);
|
| 52 |
+
using ptr_schema = schema*;
|
| 53 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 54 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::cumsum")
|
| 55 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "dimname")
|
| 56 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "cumsum.dimname(Tensor self, Dimname dim, *, ScalarType? dtype=None) -> Tensor")
|
| 57 |
+
static at::Tensor call(const at::Tensor & self, at::Dimname dim, ::std::optional<at::ScalarType> dtype);
|
| 58 |
+
static at::Tensor redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & self, at::Dimname dim, ::std::optional<at::ScalarType> dtype);
|
| 59 |
+
};
|
| 60 |
+
|
| 61 |
+
struct TORCH_API cumsum__dimname {
|
| 62 |
+
using schema = at::Tensor & (at::Tensor &, at::Dimname, ::std::optional<at::ScalarType>);
|
| 63 |
+
using ptr_schema = schema*;
|
| 64 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 65 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::cumsum_")
|
| 66 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "dimname")
|
| 67 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "cumsum_.dimname(Tensor(a!) self, Dimname dim, *, ScalarType? dtype=None) -> Tensor(a!)")
|
| 68 |
+
static at::Tensor & call(at::Tensor & self, at::Dimname dim, ::std::optional<at::ScalarType> dtype);
|
| 69 |
+
static at::Tensor & redispatch(c10::DispatchKeySet dispatchKeySet, at::Tensor & self, at::Dimname dim, ::std::optional<at::ScalarType> dtype);
|
| 70 |
+
};
|
| 71 |
+
|
| 72 |
+
struct TORCH_API cumsum_dimname_out {
|
| 73 |
+
using schema = at::Tensor & (const at::Tensor &, at::Dimname, ::std::optional<at::ScalarType>, at::Tensor &);
|
| 74 |
+
using ptr_schema = schema*;
|
| 75 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 76 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::cumsum")
|
| 77 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "dimname_out")
|
| 78 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "cumsum.dimname_out(Tensor self, Dimname dim, *, ScalarType? dtype=None, Tensor(a!) out) -> Tensor(a!)")
|
| 79 |
+
static at::Tensor & call(const at::Tensor & self, at::Dimname dim, ::std::optional<at::ScalarType> dtype, at::Tensor & out);
|
| 80 |
+
static at::Tensor & redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & self, at::Dimname dim, ::std::optional<at::ScalarType> dtype, at::Tensor & out);
|
| 81 |
+
};
|
| 82 |
+
|
| 83 |
+
}} // namespace at::_ops
|
parrot/lib/python3.10/site-packages/torch/include/ATen/ops/det.h
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from Function.h
|
| 4 |
+
|
| 5 |
+
#include <ATen/Context.h>
|
| 6 |
+
#include <ATen/DeviceGuard.h>
|
| 7 |
+
#include <ATen/TensorUtils.h>
|
| 8 |
+
#include <ATen/TracerMode.h>
|
| 9 |
+
#include <ATen/core/Generator.h>
|
| 10 |
+
#include <ATen/core/Reduction.h>
|
| 11 |
+
#include <ATen/core/Tensor.h>
|
| 12 |
+
#include <c10/core/Scalar.h>
|
| 13 |
+
#include <c10/core/Storage.h>
|
| 14 |
+
#include <c10/core/TensorOptions.h>
|
| 15 |
+
#include <c10/util/Deprecated.h>
|
| 16 |
+
#include <c10/util/Optional.h>
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
#include <ATen/ops/det_ops.h>
|
| 21 |
+
|
| 22 |
+
namespace at {
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
// aten::det(Tensor self) -> Tensor
|
| 26 |
+
inline at::Tensor det(const at::Tensor & self) {
|
| 27 |
+
return at::_ops::det::call(self);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
}
|
parrot/lib/python3.10/site-packages/torch/include/ATen/ops/embedding_ops.h
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from Operator.h
|
| 4 |
+
|
| 5 |
+
#include <tuple>
|
| 6 |
+
#include <vector>
|
| 7 |
+
|
| 8 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 9 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 10 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 11 |
+
#include <ATen/core/ATen_fwd.h>
|
| 12 |
+
|
| 13 |
+
namespace at {
|
| 14 |
+
namespace _ops {
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
struct TORCH_API embedding {
|
| 18 |
+
using schema = at::Tensor (const at::Tensor &, const at::Tensor &, c10::SymInt, bool, bool);
|
| 19 |
+
using ptr_schema = schema*;
|
| 20 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 21 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::embedding")
|
| 22 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "")
|
| 23 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "embedding(Tensor weight, Tensor indices, SymInt padding_idx=-1, bool scale_grad_by_freq=False, bool sparse=False) -> Tensor")
|
| 24 |
+
static at::Tensor call(const at::Tensor & weight, const at::Tensor & indices, c10::SymInt padding_idx, bool scale_grad_by_freq, bool sparse);
|
| 25 |
+
static at::Tensor redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & weight, const at::Tensor & indices, c10::SymInt padding_idx, bool scale_grad_by_freq, bool sparse);
|
| 26 |
+
};
|
| 27 |
+
|
| 28 |
+
struct TORCH_API embedding_out {
|
| 29 |
+
using schema = at::Tensor & (const at::Tensor &, const at::Tensor &, c10::SymInt, bool, bool, at::Tensor &);
|
| 30 |
+
using ptr_schema = schema*;
|
| 31 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 32 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::embedding")
|
| 33 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "out")
|
| 34 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "embedding.out(Tensor weight, Tensor indices, SymInt padding_idx=-1, bool scale_grad_by_freq=False, bool sparse=False, *, Tensor(a!) out) -> Tensor(a!)")
|
| 35 |
+
static at::Tensor & call(const at::Tensor & weight, const at::Tensor & indices, c10::SymInt padding_idx, bool scale_grad_by_freq, bool sparse, at::Tensor & out);
|
| 36 |
+
static at::Tensor & redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & weight, const at::Tensor & indices, c10::SymInt padding_idx, bool scale_grad_by_freq, bool sparse, at::Tensor & out);
|
| 37 |
+
};
|
| 38 |
+
|
| 39 |
+
}} // namespace at::_ops
|
parrot/lib/python3.10/site-packages/torch/include/ATen/ops/gcd_meta.h
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from NativeMetaFunction.h
|
| 4 |
+
|
| 5 |
+
#include <c10/core/Scalar.h>
|
| 6 |
+
#include <c10/core/Storage.h>
|
| 7 |
+
#include <c10/core/TensorOptions.h>
|
| 8 |
+
#include <c10/util/Deprecated.h>
|
| 9 |
+
#include <c10/util/Optional.h>
|
| 10 |
+
#include <c10/core/QScheme.h>
|
| 11 |
+
#include <ATen/core/Reduction.h>
|
| 12 |
+
#include <ATen/TensorIterator.h>
|
| 13 |
+
#include <ATen/TensorMeta.h>
|
| 14 |
+
#include <tuple>
|
| 15 |
+
#include <vector>
|
| 16 |
+
|
| 17 |
+
namespace at {
|
| 18 |
+
namespace meta {
|
| 19 |
+
|
| 20 |
+
struct TORCH_API structured_gcd : public TensorIteratorBase {
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
void meta(const at::Tensor & self, const at::Tensor & other);
|
| 24 |
+
};
|
| 25 |
+
|
| 26 |
+
} // namespace native
|
| 27 |
+
} // namespace at
|
parrot/lib/python3.10/site-packages/torch/include/ATen/ops/hamming_window_native.h
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from NativeFunction.h
|
| 4 |
+
|
| 5 |
+
#include <c10/core/Scalar.h>
|
| 6 |
+
#include <c10/core/Storage.h>
|
| 7 |
+
#include <c10/core/TensorOptions.h>
|
| 8 |
+
#include <c10/util/Deprecated.h>
|
| 9 |
+
#include <c10/util/Optional.h>
|
| 10 |
+
#include <c10/core/QScheme.h>
|
| 11 |
+
#include <ATen/core/Reduction.h>
|
| 12 |
+
#include <ATen/core/Tensor.h>
|
| 13 |
+
#include <tuple>
|
| 14 |
+
#include <vector>
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
namespace at {
|
| 18 |
+
namespace native {
|
| 19 |
+
TORCH_API at::Tensor hamming_window(int64_t window_length, ::std::optional<at::ScalarType> dtype={}, ::std::optional<at::Layout> layout={}, ::std::optional<at::Device> device={}, ::std::optional<bool> pin_memory={});
|
| 20 |
+
TORCH_API at::Tensor & hamming_window_out(int64_t window_length, at::Tensor & out);
|
| 21 |
+
TORCH_API at::Tensor hamming_window(int64_t window_length, bool periodic, ::std::optional<at::ScalarType> dtype={}, ::std::optional<at::Layout> layout={}, ::std::optional<at::Device> device={}, ::std::optional<bool> pin_memory={});
|
| 22 |
+
TORCH_API at::Tensor & hamming_window_periodic_out(int64_t window_length, bool periodic, at::Tensor & out);
|
| 23 |
+
TORCH_API at::Tensor hamming_window(int64_t window_length, bool periodic, double alpha, ::std::optional<at::ScalarType> dtype={}, ::std::optional<at::Layout> layout={}, ::std::optional<at::Device> device={}, ::std::optional<bool> pin_memory={});
|
| 24 |
+
TORCH_API at::Tensor & hamming_window_periodic_alpha_out(int64_t window_length, bool periodic, double alpha, at::Tensor & out);
|
| 25 |
+
TORCH_API at::Tensor hamming_window(int64_t window_length, bool periodic, double alpha, double beta, ::std::optional<at::ScalarType> dtype={}, ::std::optional<at::Layout> layout={}, ::std::optional<at::Device> device={}, ::std::optional<bool> pin_memory={});
|
| 26 |
+
TORCH_API at::Tensor & hamming_window_periodic_alpha_beta_out(int64_t window_length, bool periodic, double alpha, double beta, at::Tensor & out);
|
| 27 |
+
} // namespace native
|
| 28 |
+
} // namespace at
|
parrot/lib/python3.10/site-packages/torch/include/ATen/ops/hardsigmoid_backward_ops.h
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from Operator.h
|
| 4 |
+
|
| 5 |
+
#include <tuple>
|
| 6 |
+
#include <vector>
|
| 7 |
+
|
| 8 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 9 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 10 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 11 |
+
#include <ATen/core/ATen_fwd.h>
|
| 12 |
+
|
| 13 |
+
namespace at {
|
| 14 |
+
namespace _ops {
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
struct TORCH_API hardsigmoid_backward_grad_input {
|
| 18 |
+
using schema = at::Tensor & (const at::Tensor &, const at::Tensor &, at::Tensor &);
|
| 19 |
+
using ptr_schema = schema*;
|
| 20 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 21 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::hardsigmoid_backward")
|
| 22 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "grad_input")
|
| 23 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "hardsigmoid_backward.grad_input(Tensor grad_output, Tensor self, *, Tensor(a!) grad_input) -> Tensor(a!)")
|
| 24 |
+
static at::Tensor & call(const at::Tensor & grad_output, const at::Tensor & self, at::Tensor & grad_input);
|
| 25 |
+
static at::Tensor & redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & grad_output, const at::Tensor & self, at::Tensor & grad_input);
|
| 26 |
+
};
|
| 27 |
+
|
| 28 |
+
struct TORCH_API hardsigmoid_backward {
|
| 29 |
+
using schema = at::Tensor (const at::Tensor &, const at::Tensor &);
|
| 30 |
+
using ptr_schema = schema*;
|
| 31 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 32 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::hardsigmoid_backward")
|
| 33 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "")
|
| 34 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "hardsigmoid_backward(Tensor grad_output, Tensor self) -> Tensor")
|
| 35 |
+
static at::Tensor call(const at::Tensor & grad_output, const at::Tensor & self);
|
| 36 |
+
static at::Tensor redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & grad_output, const at::Tensor & self);
|
| 37 |
+
};
|
| 38 |
+
|
| 39 |
+
}} // namespace at::_ops
|
parrot/lib/python3.10/site-packages/torch/include/ATen/ops/heaviside_meta_dispatch.h
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// @generated by torchgen/gen.py from DispatchKeyFunction.h
|
| 3 |
+
|
| 4 |
+
// NB: The implementing C++ file is RegisterDispatchKey.cpp
|
| 5 |
+
|
| 6 |
+
// The only #includes we need are for custom classes that have defaults in the C++ API
|
| 7 |
+
#include <c10/core/MemoryFormat.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <ATen/core/Reduction.h>
|
| 10 |
+
|
| 11 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 12 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 13 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 14 |
+
#include <ATen/core/ATen_fwd.h>
|
| 15 |
+
|
| 16 |
+
namespace at {
|
| 17 |
+
|
| 18 |
+
namespace meta {
|
| 19 |
+
|
| 20 |
+
TORCH_API at::Tensor heaviside(const at::Tensor & self, const at::Tensor & values);
|
| 21 |
+
TORCH_API at::Tensor & heaviside_out(at::Tensor & out, const at::Tensor & self, const at::Tensor & values);
|
| 22 |
+
TORCH_API at::Tensor & heaviside_outf(const at::Tensor & self, const at::Tensor & values, at::Tensor & out);
|
| 23 |
+
TORCH_API at::Tensor & heaviside_(at::Tensor & self, const at::Tensor & values);
|
| 24 |
+
|
| 25 |
+
} // namespace meta
|
| 26 |
+
} // namespace at
|
parrot/lib/python3.10/site-packages/torch/include/ATen/ops/index_fill_cuda_dispatch.h
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// @generated by torchgen/gen.py from DispatchKeyFunction.h
|
| 3 |
+
|
| 4 |
+
// NB: The implementing C++ file is RegisterDispatchKey.cpp
|
| 5 |
+
|
| 6 |
+
// The only #includes we need are for custom classes that have defaults in the C++ API
|
| 7 |
+
#include <c10/core/MemoryFormat.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <ATen/core/Reduction.h>
|
| 10 |
+
|
| 11 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 12 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 13 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 14 |
+
#include <ATen/core/ATen_fwd.h>
|
| 15 |
+
|
| 16 |
+
namespace at {
|
| 17 |
+
|
| 18 |
+
namespace cuda {
|
| 19 |
+
|
| 20 |
+
TORCH_API at::Tensor & index_fill_(at::Tensor & self, int64_t dim, const at::Tensor & index, const at::Scalar & value);
|
| 21 |
+
TORCH_API at::Tensor & index_fill_(at::Tensor & self, int64_t dim, const at::Tensor & index, const at::Tensor & value);
|
| 22 |
+
|
| 23 |
+
} // namespace cuda
|
| 24 |
+
} // namespace at
|
parrot/lib/python3.10/site-packages/torch/include/ATen/ops/isreal_ops.h
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from Operator.h
|
| 4 |
+
|
| 5 |
+
#include <tuple>
|
| 6 |
+
#include <vector>
|
| 7 |
+
|
| 8 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 9 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 10 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 11 |
+
#include <ATen/core/ATen_fwd.h>
|
| 12 |
+
|
| 13 |
+
namespace at {
|
| 14 |
+
namespace _ops {
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
struct TORCH_API isreal {
|
| 18 |
+
using schema = at::Tensor (const at::Tensor &);
|
| 19 |
+
using ptr_schema = schema*;
|
| 20 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 21 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::isreal")
|
| 22 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "")
|
| 23 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "isreal(Tensor self) -> Tensor")
|
| 24 |
+
static at::Tensor call(const at::Tensor & self);
|
| 25 |
+
static at::Tensor redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & self);
|
| 26 |
+
};
|
| 27 |
+
|
| 28 |
+
}} // namespace at::_ops
|
parrot/lib/python3.10/site-packages/torch/include/ATen/ops/item_compositeimplicitautograd_dispatch.h
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// @generated by torchgen/gen.py from DispatchKeyFunction.h
|
| 3 |
+
|
| 4 |
+
// NB: The implementing C++ file is RegisterDispatchKey.cpp
|
| 5 |
+
|
| 6 |
+
// The only #includes we need are for custom classes that have defaults in the C++ API
|
| 7 |
+
#include <c10/core/MemoryFormat.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <ATen/core/Reduction.h>
|
| 10 |
+
|
| 11 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 12 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 13 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 14 |
+
#include <ATen/core/ATen_fwd.h>
|
| 15 |
+
|
| 16 |
+
namespace at {
|
| 17 |
+
|
| 18 |
+
namespace compositeimplicitautograd {
|
| 19 |
+
|
| 20 |
+
TORCH_API at::Scalar item(const at::Tensor & self);
|
| 21 |
+
|
| 22 |
+
} // namespace compositeimplicitautograd
|
| 23 |
+
} // namespace at
|
parrot/lib/python3.10/site-packages/torch/include/ATen/ops/l1_loss.h
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from Function.h
|
| 4 |
+
|
| 5 |
+
#include <ATen/Context.h>
|
| 6 |
+
#include <ATen/DeviceGuard.h>
|
| 7 |
+
#include <ATen/TensorUtils.h>
|
| 8 |
+
#include <ATen/TracerMode.h>
|
| 9 |
+
#include <ATen/core/Generator.h>
|
| 10 |
+
#include <ATen/core/Reduction.h>
|
| 11 |
+
#include <ATen/core/Tensor.h>
|
| 12 |
+
#include <c10/core/Scalar.h>
|
| 13 |
+
#include <c10/core/Storage.h>
|
| 14 |
+
#include <c10/core/TensorOptions.h>
|
| 15 |
+
#include <c10/util/Deprecated.h>
|
| 16 |
+
#include <c10/util/Optional.h>
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
#include <ATen/ops/l1_loss_ops.h>
|
| 21 |
+
|
| 22 |
+
namespace at {
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
// aten::l1_loss(Tensor self, Tensor target, int reduction=Mean) -> Tensor
|
| 26 |
+
inline at::Tensor l1_loss(const at::Tensor & self, const at::Tensor & target, int64_t reduction=at::Reduction::Mean) {
|
| 27 |
+
return at::_ops::l1_loss::call(self, target, reduction);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
}
|
parrot/lib/python3.10/site-packages/torch/include/ATen/ops/linalg_diagonal_ops.h
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from Operator.h
|
| 4 |
+
|
| 5 |
+
#include <tuple>
|
| 6 |
+
#include <vector>
|
| 7 |
+
|
| 8 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 9 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 10 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 11 |
+
#include <ATen/core/ATen_fwd.h>
|
| 12 |
+
|
| 13 |
+
namespace at {
|
| 14 |
+
namespace _ops {
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
struct TORCH_API linalg_diagonal {
|
| 18 |
+
using schema = at::Tensor (const at::Tensor &, int64_t, int64_t, int64_t);
|
| 19 |
+
using ptr_schema = schema*;
|
| 20 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 21 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::linalg_diagonal")
|
| 22 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "")
|
| 23 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "linalg_diagonal(Tensor(a) A, *, int offset=0, int dim1=-2, int dim2=-1) -> Tensor(a)")
|
| 24 |
+
static at::Tensor call(const at::Tensor & A, int64_t offset, int64_t dim1, int64_t dim2);
|
| 25 |
+
static at::Tensor redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & A, int64_t offset, int64_t dim1, int64_t dim2);
|
| 26 |
+
};
|
| 27 |
+
|
| 28 |
+
}} // namespace at::_ops
|
parrot/lib/python3.10/site-packages/torch/include/ATen/ops/linalg_inv_ex_cuda_dispatch.h
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// @generated by torchgen/gen.py from DispatchKeyFunction.h
|
| 3 |
+
|
| 4 |
+
// NB: The implementing C++ file is RegisterDispatchKey.cpp
|
| 5 |
+
|
| 6 |
+
// The only #includes we need are for custom classes that have defaults in the C++ API
|
| 7 |
+
#include <c10/core/MemoryFormat.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <ATen/core/Reduction.h>
|
| 10 |
+
|
| 11 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 12 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 13 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 14 |
+
#include <ATen/core/ATen_fwd.h>
|
| 15 |
+
|
| 16 |
+
namespace at {
|
| 17 |
+
|
| 18 |
+
namespace cuda {
|
| 19 |
+
|
| 20 |
+
TORCH_API ::std::tuple<at::Tensor,at::Tensor> linalg_inv_ex(const at::Tensor & A, bool check_errors=false);
|
| 21 |
+
TORCH_API ::std::tuple<at::Tensor &,at::Tensor &> linalg_inv_ex_out(at::Tensor & inverse, at::Tensor & info, const at::Tensor & A, bool check_errors=false);
|
| 22 |
+
TORCH_API ::std::tuple<at::Tensor &,at::Tensor &> linalg_inv_ex_outf(const at::Tensor & A, bool check_errors, at::Tensor & inverse, at::Tensor & info);
|
| 23 |
+
|
| 24 |
+
} // namespace cuda
|
| 25 |
+
} // namespace at
|
parrot/lib/python3.10/site-packages/torch/include/ATen/ops/log_sigmoid_forward_cuda_dispatch.h
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// @generated by torchgen/gen.py from DispatchKeyFunction.h
|
| 3 |
+
|
| 4 |
+
// NB: The implementing C++ file is RegisterDispatchKey.cpp
|
| 5 |
+
|
| 6 |
+
// The only #includes we need are for custom classes that have defaults in the C++ API
|
| 7 |
+
#include <c10/core/MemoryFormat.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <ATen/core/Reduction.h>
|
| 10 |
+
|
| 11 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 12 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 13 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 14 |
+
#include <ATen/core/ATen_fwd.h>
|
| 15 |
+
|
| 16 |
+
namespace at {
|
| 17 |
+
|
| 18 |
+
namespace cuda {
|
| 19 |
+
|
| 20 |
+
TORCH_API ::std::tuple<at::Tensor,at::Tensor> log_sigmoid_forward(const at::Tensor & self);
|
| 21 |
+
TORCH_API ::std::tuple<at::Tensor &,at::Tensor &> log_sigmoid_forward_out(at::Tensor & output, at::Tensor & buffer, const at::Tensor & self);
|
| 22 |
+
TORCH_API ::std::tuple<at::Tensor &,at::Tensor &> log_sigmoid_forward_outf(const at::Tensor & self, at::Tensor & output, at::Tensor & buffer);
|
| 23 |
+
|
| 24 |
+
} // namespace cuda
|
| 25 |
+
} // namespace at
|
parrot/lib/python3.10/site-packages/torch/include/ATen/ops/logical_or_cuda_dispatch.h
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// @generated by torchgen/gen.py from DispatchKeyFunction.h
|
| 3 |
+
|
| 4 |
+
// NB: The implementing C++ file is RegisterDispatchKey.cpp
|
| 5 |
+
|
| 6 |
+
// The only #includes we need are for custom classes that have defaults in the C++ API
|
| 7 |
+
#include <c10/core/MemoryFormat.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <ATen/core/Reduction.h>
|
| 10 |
+
|
| 11 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 12 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 13 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 14 |
+
#include <ATen/core/ATen_fwd.h>
|
| 15 |
+
|
| 16 |
+
namespace at {
|
| 17 |
+
|
| 18 |
+
namespace cuda {
|
| 19 |
+
|
| 20 |
+
TORCH_API at::Tensor & logical_or_out(at::Tensor & out, const at::Tensor & self, const at::Tensor & other);
|
| 21 |
+
TORCH_API at::Tensor & logical_or_outf(const at::Tensor & self, const at::Tensor & other, at::Tensor & out);
|
| 22 |
+
|
| 23 |
+
} // namespace cuda
|
| 24 |
+
} // namespace at
|
parrot/lib/python3.10/site-packages/torch/include/ATen/ops/mH_compositeimplicitautograd_dispatch.h
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// @generated by torchgen/gen.py from DispatchKeyFunction.h
|
| 3 |
+
|
| 4 |
+
// NB: The implementing C++ file is RegisterDispatchKey.cpp
|
| 5 |
+
|
| 6 |
+
// The only #includes we need are for custom classes that have defaults in the C++ API
|
| 7 |
+
#include <c10/core/MemoryFormat.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <ATen/core/Reduction.h>
|
| 10 |
+
|
| 11 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 12 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 13 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 14 |
+
#include <ATen/core/ATen_fwd.h>
|
| 15 |
+
|
| 16 |
+
namespace at {
|
| 17 |
+
|
| 18 |
+
namespace compositeimplicitautograd {
|
| 19 |
+
|
| 20 |
+
TORCH_API at::Tensor mH(const at::Tensor & self);
|
| 21 |
+
|
| 22 |
+
} // namespace compositeimplicitautograd
|
| 23 |
+
} // namespace at
|
parrot/lib/python3.10/site-packages/torch/include/ATen/ops/masked_scatter_backward_ops.h
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from Operator.h
|
| 4 |
+
|
| 5 |
+
#include <tuple>
|
| 6 |
+
#include <vector>
|
| 7 |
+
|
| 8 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 9 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 10 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 11 |
+
#include <ATen/core/ATen_fwd.h>
|
| 12 |
+
|
| 13 |
+
namespace at {
|
| 14 |
+
namespace _ops {
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
struct TORCH_API masked_scatter_backward {
|
| 18 |
+
using schema = at::Tensor (const at::Tensor &, const at::Tensor &, c10::SymIntArrayRef);
|
| 19 |
+
using ptr_schema = schema*;
|
| 20 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 21 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::masked_scatter_backward")
|
| 22 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "")
|
| 23 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "masked_scatter_backward(Tensor grad_output, Tensor mask, SymInt[] sizes) -> Tensor")
|
| 24 |
+
static at::Tensor call(const at::Tensor & grad_output, const at::Tensor & mask, c10::SymIntArrayRef sizes);
|
| 25 |
+
static at::Tensor redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & grad_output, const at::Tensor & mask, c10::SymIntArrayRef sizes);
|
| 26 |
+
};
|
| 27 |
+
|
| 28 |
+
}} // namespace at::_ops
|