Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- parrot/lib/python3.10/encodings/__pycache__/cp852.cpython-310.pyc +0 -0
- parrot/lib/python3.10/idlelib/Icons/folder.gif +3 -0
- parrot/lib/python3.10/idlelib/Icons/idle_16.png +3 -0
- parrot/lib/python3.10/idlelib/Icons/idle_48.png +3 -0
- parrot/lib/python3.10/importlib/__pycache__/__init__.cpython-310.pyc +0 -0
- parrot/lib/python3.10/importlib/__pycache__/_adapters.cpython-310.pyc +0 -0
- parrot/lib/python3.10/importlib/__pycache__/_bootstrap_external.cpython-310.pyc +0 -0
- parrot/lib/python3.10/importlib/__pycache__/_common.cpython-310.pyc +0 -0
- parrot/lib/python3.10/importlib/__pycache__/util.cpython-310.pyc +0 -0
- parrot/lib/python3.10/importlib/_abc.py +54 -0
- parrot/lib/python3.10/importlib/metadata/__init__.py +1057 -0
- parrot/lib/python3.10/importlib/metadata/__pycache__/__init__.cpython-310.pyc +0 -0
- parrot/lib/python3.10/importlib/metadata/__pycache__/_adapters.cpython-310.pyc +0 -0
- parrot/lib/python3.10/importlib/metadata/__pycache__/_functools.cpython-310.pyc +0 -0
- parrot/lib/python3.10/importlib/metadata/__pycache__/_itertools.cpython-310.pyc +0 -0
- parrot/lib/python3.10/importlib/metadata/__pycache__/_text.cpython-310.pyc +0 -0
- parrot/lib/python3.10/importlib/metadata/_adapters.py +68 -0
- parrot/lib/python3.10/importlib/metadata/_collections.py +30 -0
- parrot/lib/python3.10/importlib/metadata/_functools.py +104 -0
- parrot/lib/python3.10/importlib/metadata/_itertools.py +19 -0
- parrot/lib/python3.10/importlib/metadata/_meta.py +47 -0
- parrot/lib/python3.10/importlib/metadata/_text.py +99 -0
- parrot/lib/python3.10/site-packages/README.txt +2 -0
- parrot/lib/python3.10/site-packages/click-8.1.7.dist-info/INSTALLER +1 -0
- parrot/lib/python3.10/site-packages/click-8.1.7.dist-info/LICENSE.rst +28 -0
- parrot/lib/python3.10/site-packages/click-8.1.7.dist-info/METADATA +103 -0
- parrot/lib/python3.10/site-packages/click-8.1.7.dist-info/RECORD +40 -0
- parrot/lib/python3.10/site-packages/click-8.1.7.dist-info/REQUESTED +0 -0
- parrot/lib/python3.10/site-packages/click-8.1.7.dist-info/WHEEL +5 -0
- parrot/lib/python3.10/site-packages/click-8.1.7.dist-info/top_level.txt +1 -0
- parrot/lib/python3.10/site-packages/decorator.py +454 -0
- parrot/lib/python3.10/site-packages/filelock-3.16.1.dist-info/INSTALLER +1 -0
- parrot/lib/python3.10/site-packages/filelock-3.16.1.dist-info/METADATA +59 -0
- parrot/lib/python3.10/site-packages/filelock-3.16.1.dist-info/REQUESTED +0 -0
- parrot/lib/python3.10/site-packages/frozenlist-1.4.1.dist-info/INSTALLER +1 -0
- parrot/lib/python3.10/site-packages/frozenlist-1.4.1.dist-info/LICENSE +201 -0
- parrot/lib/python3.10/site-packages/frozenlist-1.4.1.dist-info/METADATA +420 -0
- parrot/lib/python3.10/site-packages/frozenlist-1.4.1.dist-info/RECORD +13 -0
- parrot/lib/python3.10/site-packages/frozenlist-1.4.1.dist-info/REQUESTED +0 -0
- parrot/lib/python3.10/site-packages/frozenlist-1.4.1.dist-info/WHEEL +8 -0
- parrot/lib/python3.10/site-packages/frozenlist-1.4.1.dist-info/top_level.txt +1 -0
- parrot/lib/python3.10/site-packages/hjson/__init__.py +642 -0
- parrot/lib/python3.10/site-packages/hjson/compat.py +46 -0
- parrot/lib/python3.10/site-packages/hjson/decoder.py +569 -0
- parrot/lib/python3.10/site-packages/hjson/encoderH.py +552 -0
- parrot/lib/python3.10/site-packages/hjson/ordered_dict.py +119 -0
- parrot/lib/python3.10/site-packages/hjson/scanner.py +56 -0
- parrot/lib/python3.10/site-packages/hjson/tests/test_decode.py +139 -0
- parrot/lib/python3.10/site-packages/hjson/tool.py +79 -0
- parrot/lib/python3.10/site-packages/isympy.py +342 -0
parrot/lib/python3.10/encodings/__pycache__/cp852.cpython-310.pyc
ADDED
|
Binary file (9.23 kB). View file
|
|
|
parrot/lib/python3.10/idlelib/Icons/folder.gif
ADDED
|
|
Git LFS Details
|
parrot/lib/python3.10/idlelib/Icons/idle_16.png
ADDED
|
|
Git LFS Details
|
parrot/lib/python3.10/idlelib/Icons/idle_48.png
ADDED
|
|
Git LFS Details
|
parrot/lib/python3.10/importlib/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (4.06 kB). View file
|
|
|
parrot/lib/python3.10/importlib/__pycache__/_adapters.cpython-310.pyc
ADDED
|
Binary file (3.96 kB). View file
|
|
|
parrot/lib/python3.10/importlib/__pycache__/_bootstrap_external.cpython-310.pyc
ADDED
|
Binary file (44.6 kB). View file
|
|
|
parrot/lib/python3.10/importlib/__pycache__/_common.cpython-310.pyc
ADDED
|
Binary file (2.96 kB). View file
|
|
|
parrot/lib/python3.10/importlib/__pycache__/util.cpython-310.pyc
ADDED
|
Binary file (9.58 kB). View file
|
|
|
parrot/lib/python3.10/importlib/_abc.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Subset of importlib.abc used to reduce importlib.util imports."""
|
| 2 |
+
from . import _bootstrap
|
| 3 |
+
import abc
|
| 4 |
+
import warnings
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class Loader(metaclass=abc.ABCMeta):
|
| 8 |
+
|
| 9 |
+
"""Abstract base class for import loaders."""
|
| 10 |
+
|
| 11 |
+
def create_module(self, spec):
|
| 12 |
+
"""Return a module to initialize and into which to load.
|
| 13 |
+
|
| 14 |
+
This method should raise ImportError if anything prevents it
|
| 15 |
+
from creating a new module. It may return None to indicate
|
| 16 |
+
that the spec should create the new module.
|
| 17 |
+
"""
|
| 18 |
+
# By default, defer to default semantics for the new module.
|
| 19 |
+
return None
|
| 20 |
+
|
| 21 |
+
# We don't define exec_module() here since that would break
|
| 22 |
+
# hasattr checks we do to support backward compatibility.
|
| 23 |
+
|
| 24 |
+
def load_module(self, fullname):
|
| 25 |
+
"""Return the loaded module.
|
| 26 |
+
|
| 27 |
+
The module must be added to sys.modules and have import-related
|
| 28 |
+
attributes set properly. The fullname is a str.
|
| 29 |
+
|
| 30 |
+
ImportError is raised on failure.
|
| 31 |
+
|
| 32 |
+
This method is deprecated in favor of loader.exec_module(). If
|
| 33 |
+
exec_module() exists then it is used to provide a backwards-compatible
|
| 34 |
+
functionality for this method.
|
| 35 |
+
|
| 36 |
+
"""
|
| 37 |
+
if not hasattr(self, 'exec_module'):
|
| 38 |
+
raise ImportError
|
| 39 |
+
# Warning implemented in _load_module_shim().
|
| 40 |
+
return _bootstrap._load_module_shim(self, fullname)
|
| 41 |
+
|
| 42 |
+
def module_repr(self, module):
|
| 43 |
+
"""Return a module's repr.
|
| 44 |
+
|
| 45 |
+
Used by the module type when the method does not raise
|
| 46 |
+
NotImplementedError.
|
| 47 |
+
|
| 48 |
+
This method is deprecated.
|
| 49 |
+
|
| 50 |
+
"""
|
| 51 |
+
warnings.warn("importlib.abc.Loader.module_repr() is deprecated and "
|
| 52 |
+
"slated for removal in Python 3.12", DeprecationWarning)
|
| 53 |
+
# The exception will cause ModuleType.__repr__ to ignore this method.
|
| 54 |
+
raise NotImplementedError
|
parrot/lib/python3.10/importlib/metadata/__init__.py
ADDED
|
@@ -0,0 +1,1057 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import re
|
| 3 |
+
import abc
|
| 4 |
+
import csv
|
| 5 |
+
import sys
|
| 6 |
+
import email
|
| 7 |
+
import pathlib
|
| 8 |
+
import zipfile
|
| 9 |
+
import operator
|
| 10 |
+
import textwrap
|
| 11 |
+
import warnings
|
| 12 |
+
import functools
|
| 13 |
+
import itertools
|
| 14 |
+
import posixpath
|
| 15 |
+
import collections
|
| 16 |
+
|
| 17 |
+
from . import _adapters, _meta
|
| 18 |
+
from ._meta import PackageMetadata
|
| 19 |
+
from ._collections import FreezableDefaultDict, Pair
|
| 20 |
+
from ._functools import method_cache, pass_none
|
| 21 |
+
from ._itertools import unique_everseen
|
| 22 |
+
from ._meta import PackageMetadata, SimplePath
|
| 23 |
+
|
| 24 |
+
from contextlib import suppress
|
| 25 |
+
from importlib import import_module
|
| 26 |
+
from importlib.abc import MetaPathFinder
|
| 27 |
+
from itertools import starmap
|
| 28 |
+
from typing import List, Mapping, Optional, Union
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
__all__ = [
|
| 32 |
+
'Distribution',
|
| 33 |
+
'DistributionFinder',
|
| 34 |
+
'PackageMetadata',
|
| 35 |
+
'PackageNotFoundError',
|
| 36 |
+
'distribution',
|
| 37 |
+
'distributions',
|
| 38 |
+
'entry_points',
|
| 39 |
+
'files',
|
| 40 |
+
'metadata',
|
| 41 |
+
'packages_distributions',
|
| 42 |
+
'requires',
|
| 43 |
+
'version',
|
| 44 |
+
]
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
class PackageNotFoundError(ModuleNotFoundError):
|
| 48 |
+
"""The package was not found."""
|
| 49 |
+
|
| 50 |
+
def __str__(self):
|
| 51 |
+
return f"No package metadata was found for {self.name}"
|
| 52 |
+
|
| 53 |
+
@property
|
| 54 |
+
def name(self):
|
| 55 |
+
(name,) = self.args
|
| 56 |
+
return name
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
class Sectioned:
|
| 60 |
+
"""
|
| 61 |
+
A simple entry point config parser for performance
|
| 62 |
+
|
| 63 |
+
>>> for item in Sectioned.read(Sectioned._sample):
|
| 64 |
+
... print(item)
|
| 65 |
+
Pair(name='sec1', value='# comments ignored')
|
| 66 |
+
Pair(name='sec1', value='a = 1')
|
| 67 |
+
Pair(name='sec1', value='b = 2')
|
| 68 |
+
Pair(name='sec2', value='a = 2')
|
| 69 |
+
|
| 70 |
+
>>> res = Sectioned.section_pairs(Sectioned._sample)
|
| 71 |
+
>>> item = next(res)
|
| 72 |
+
>>> item.name
|
| 73 |
+
'sec1'
|
| 74 |
+
>>> item.value
|
| 75 |
+
Pair(name='a', value='1')
|
| 76 |
+
>>> item = next(res)
|
| 77 |
+
>>> item.value
|
| 78 |
+
Pair(name='b', value='2')
|
| 79 |
+
>>> item = next(res)
|
| 80 |
+
>>> item.name
|
| 81 |
+
'sec2'
|
| 82 |
+
>>> item.value
|
| 83 |
+
Pair(name='a', value='2')
|
| 84 |
+
>>> list(res)
|
| 85 |
+
[]
|
| 86 |
+
"""
|
| 87 |
+
|
| 88 |
+
_sample = textwrap.dedent(
|
| 89 |
+
"""
|
| 90 |
+
[sec1]
|
| 91 |
+
# comments ignored
|
| 92 |
+
a = 1
|
| 93 |
+
b = 2
|
| 94 |
+
|
| 95 |
+
[sec2]
|
| 96 |
+
a = 2
|
| 97 |
+
"""
|
| 98 |
+
).lstrip()
|
| 99 |
+
|
| 100 |
+
@classmethod
|
| 101 |
+
def section_pairs(cls, text):
|
| 102 |
+
return (
|
| 103 |
+
section._replace(value=Pair.parse(section.value))
|
| 104 |
+
for section in cls.read(text, filter_=cls.valid)
|
| 105 |
+
if section.name is not None
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
@staticmethod
|
| 109 |
+
def read(text, filter_=None):
|
| 110 |
+
lines = filter(filter_, map(str.strip, text.splitlines()))
|
| 111 |
+
name = None
|
| 112 |
+
for value in lines:
|
| 113 |
+
section_match = value.startswith('[') and value.endswith(']')
|
| 114 |
+
if section_match:
|
| 115 |
+
name = value.strip('[]')
|
| 116 |
+
continue
|
| 117 |
+
yield Pair(name, value)
|
| 118 |
+
|
| 119 |
+
@staticmethod
|
| 120 |
+
def valid(line):
|
| 121 |
+
return line and not line.startswith('#')
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
class EntryPoint(
|
| 125 |
+
collections.namedtuple('EntryPointBase', 'name value group')):
|
| 126 |
+
"""An entry point as defined by Python packaging conventions.
|
| 127 |
+
|
| 128 |
+
See `the packaging docs on entry points
|
| 129 |
+
<https://packaging.python.org/specifications/entry-points/>`_
|
| 130 |
+
for more information.
|
| 131 |
+
|
| 132 |
+
>>> ep = EntryPoint(
|
| 133 |
+
... name=None, group=None, value='package.module:attr [extra1, extra2]')
|
| 134 |
+
>>> ep.module
|
| 135 |
+
'package.module'
|
| 136 |
+
>>> ep.attr
|
| 137 |
+
'attr'
|
| 138 |
+
>>> ep.extras
|
| 139 |
+
['extra1', 'extra2']
|
| 140 |
+
"""
|
| 141 |
+
|
| 142 |
+
pattern = re.compile(
|
| 143 |
+
r'(?P<module>[\w.]+)\s*'
|
| 144 |
+
r'(:\s*(?P<attr>[\w.]+)\s*)?'
|
| 145 |
+
r'((?P<extras>\[.*\])\s*)?$'
|
| 146 |
+
)
|
| 147 |
+
"""
|
| 148 |
+
A regular expression describing the syntax for an entry point,
|
| 149 |
+
which might look like:
|
| 150 |
+
|
| 151 |
+
- module
|
| 152 |
+
- package.module
|
| 153 |
+
- package.module:attribute
|
| 154 |
+
- package.module:object.attribute
|
| 155 |
+
- package.module:attr [extra1, extra2]
|
| 156 |
+
|
| 157 |
+
Other combinations are possible as well.
|
| 158 |
+
|
| 159 |
+
The expression is lenient about whitespace around the ':',
|
| 160 |
+
following the attr, and following any extras.
|
| 161 |
+
"""
|
| 162 |
+
|
| 163 |
+
dist: Optional['Distribution'] = None
|
| 164 |
+
|
| 165 |
+
def load(self):
|
| 166 |
+
"""Load the entry point from its definition. If only a module
|
| 167 |
+
is indicated by the value, return that module. Otherwise,
|
| 168 |
+
return the named object.
|
| 169 |
+
"""
|
| 170 |
+
match = self.pattern.match(self.value)
|
| 171 |
+
module = import_module(match.group('module'))
|
| 172 |
+
attrs = filter(None, (match.group('attr') or '').split('.'))
|
| 173 |
+
return functools.reduce(getattr, attrs, module)
|
| 174 |
+
|
| 175 |
+
@property
|
| 176 |
+
def module(self):
|
| 177 |
+
match = self.pattern.match(self.value)
|
| 178 |
+
return match.group('module')
|
| 179 |
+
|
| 180 |
+
@property
|
| 181 |
+
def attr(self):
|
| 182 |
+
match = self.pattern.match(self.value)
|
| 183 |
+
return match.group('attr')
|
| 184 |
+
|
| 185 |
+
@property
|
| 186 |
+
def extras(self):
|
| 187 |
+
match = self.pattern.match(self.value)
|
| 188 |
+
return re.findall(r'\w+', match.group('extras') or '')
|
| 189 |
+
|
| 190 |
+
def _for(self, dist):
|
| 191 |
+
self.dist = dist
|
| 192 |
+
return self
|
| 193 |
+
|
| 194 |
+
def __iter__(self):
|
| 195 |
+
"""
|
| 196 |
+
Supply iter so one may construct dicts of EntryPoints by name.
|
| 197 |
+
"""
|
| 198 |
+
msg = (
|
| 199 |
+
"Construction of dict of EntryPoints is deprecated in "
|
| 200 |
+
"favor of EntryPoints."
|
| 201 |
+
)
|
| 202 |
+
warnings.warn(msg, DeprecationWarning)
|
| 203 |
+
return iter((self.name, self))
|
| 204 |
+
|
| 205 |
+
def __reduce__(self):
|
| 206 |
+
return (
|
| 207 |
+
self.__class__,
|
| 208 |
+
(self.name, self.value, self.group),
|
| 209 |
+
)
|
| 210 |
+
|
| 211 |
+
def matches(self, **params):
|
| 212 |
+
"""
|
| 213 |
+
EntryPoint matches the given parameters.
|
| 214 |
+
|
| 215 |
+
>>> ep = EntryPoint(group='foo', name='bar', value='bing:bong [extra1, extra2]')
|
| 216 |
+
>>> ep.matches(group='foo')
|
| 217 |
+
True
|
| 218 |
+
>>> ep.matches(name='bar', value='bing:bong [extra1, extra2]')
|
| 219 |
+
True
|
| 220 |
+
>>> ep.matches(group='foo', name='other')
|
| 221 |
+
False
|
| 222 |
+
>>> ep.matches()
|
| 223 |
+
True
|
| 224 |
+
>>> ep.matches(extras=['extra1', 'extra2'])
|
| 225 |
+
True
|
| 226 |
+
>>> ep.matches(module='bing')
|
| 227 |
+
True
|
| 228 |
+
>>> ep.matches(attr='bong')
|
| 229 |
+
True
|
| 230 |
+
"""
|
| 231 |
+
attrs = (getattr(self, param) for param in params)
|
| 232 |
+
return all(map(operator.eq, params.values(), attrs))
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
class DeprecatedList(list):
|
| 236 |
+
"""
|
| 237 |
+
Allow an otherwise immutable object to implement mutability
|
| 238 |
+
for compatibility.
|
| 239 |
+
|
| 240 |
+
>>> recwarn = getfixture('recwarn')
|
| 241 |
+
>>> dl = DeprecatedList(range(3))
|
| 242 |
+
>>> dl[0] = 1
|
| 243 |
+
>>> dl.append(3)
|
| 244 |
+
>>> del dl[3]
|
| 245 |
+
>>> dl.reverse()
|
| 246 |
+
>>> dl.sort()
|
| 247 |
+
>>> dl.extend([4])
|
| 248 |
+
>>> dl.pop(-1)
|
| 249 |
+
4
|
| 250 |
+
>>> dl.remove(1)
|
| 251 |
+
>>> dl += [5]
|
| 252 |
+
>>> dl + [6]
|
| 253 |
+
[1, 2, 5, 6]
|
| 254 |
+
>>> dl + (6,)
|
| 255 |
+
[1, 2, 5, 6]
|
| 256 |
+
>>> dl.insert(0, 0)
|
| 257 |
+
>>> dl
|
| 258 |
+
[0, 1, 2, 5]
|
| 259 |
+
>>> dl == [0, 1, 2, 5]
|
| 260 |
+
True
|
| 261 |
+
>>> dl == (0, 1, 2, 5)
|
| 262 |
+
True
|
| 263 |
+
>>> len(recwarn)
|
| 264 |
+
1
|
| 265 |
+
"""
|
| 266 |
+
|
| 267 |
+
__slots__ = ()
|
| 268 |
+
|
| 269 |
+
_warn = functools.partial(
|
| 270 |
+
warnings.warn,
|
| 271 |
+
"EntryPoints list interface is deprecated. Cast to list if needed.",
|
| 272 |
+
DeprecationWarning,
|
| 273 |
+
stacklevel=2,
|
| 274 |
+
)
|
| 275 |
+
|
| 276 |
+
def __setitem__(self, *args, **kwargs):
|
| 277 |
+
self._warn()
|
| 278 |
+
return super().__setitem__(*args, **kwargs)
|
| 279 |
+
|
| 280 |
+
def __delitem__(self, *args, **kwargs):
|
| 281 |
+
self._warn()
|
| 282 |
+
return super().__delitem__(*args, **kwargs)
|
| 283 |
+
|
| 284 |
+
def append(self, *args, **kwargs):
|
| 285 |
+
self._warn()
|
| 286 |
+
return super().append(*args, **kwargs)
|
| 287 |
+
|
| 288 |
+
def reverse(self, *args, **kwargs):
|
| 289 |
+
self._warn()
|
| 290 |
+
return super().reverse(*args, **kwargs)
|
| 291 |
+
|
| 292 |
+
def extend(self, *args, **kwargs):
|
| 293 |
+
self._warn()
|
| 294 |
+
return super().extend(*args, **kwargs)
|
| 295 |
+
|
| 296 |
+
def pop(self, *args, **kwargs):
|
| 297 |
+
self._warn()
|
| 298 |
+
return super().pop(*args, **kwargs)
|
| 299 |
+
|
| 300 |
+
def remove(self, *args, **kwargs):
|
| 301 |
+
self._warn()
|
| 302 |
+
return super().remove(*args, **kwargs)
|
| 303 |
+
|
| 304 |
+
def __iadd__(self, *args, **kwargs):
|
| 305 |
+
self._warn()
|
| 306 |
+
return super().__iadd__(*args, **kwargs)
|
| 307 |
+
|
| 308 |
+
def __add__(self, other):
|
| 309 |
+
if not isinstance(other, tuple):
|
| 310 |
+
self._warn()
|
| 311 |
+
other = tuple(other)
|
| 312 |
+
return self.__class__(tuple(self) + other)
|
| 313 |
+
|
| 314 |
+
def insert(self, *args, **kwargs):
|
| 315 |
+
self._warn()
|
| 316 |
+
return super().insert(*args, **kwargs)
|
| 317 |
+
|
| 318 |
+
def sort(self, *args, **kwargs):
|
| 319 |
+
self._warn()
|
| 320 |
+
return super().sort(*args, **kwargs)
|
| 321 |
+
|
| 322 |
+
def __eq__(self, other):
|
| 323 |
+
if not isinstance(other, tuple):
|
| 324 |
+
self._warn()
|
| 325 |
+
other = tuple(other)
|
| 326 |
+
|
| 327 |
+
return tuple(self).__eq__(other)
|
| 328 |
+
|
| 329 |
+
|
| 330 |
+
class EntryPoints(DeprecatedList):
|
| 331 |
+
"""
|
| 332 |
+
An immutable collection of selectable EntryPoint objects.
|
| 333 |
+
"""
|
| 334 |
+
|
| 335 |
+
__slots__ = ()
|
| 336 |
+
|
| 337 |
+
def __getitem__(self, name): # -> EntryPoint:
|
| 338 |
+
"""
|
| 339 |
+
Get the EntryPoint in self matching name.
|
| 340 |
+
"""
|
| 341 |
+
if isinstance(name, int):
|
| 342 |
+
warnings.warn(
|
| 343 |
+
"Accessing entry points by index is deprecated. "
|
| 344 |
+
"Cast to tuple if needed.",
|
| 345 |
+
DeprecationWarning,
|
| 346 |
+
stacklevel=2,
|
| 347 |
+
)
|
| 348 |
+
return super().__getitem__(name)
|
| 349 |
+
try:
|
| 350 |
+
return next(iter(self.select(name=name)))
|
| 351 |
+
except StopIteration:
|
| 352 |
+
raise KeyError(name)
|
| 353 |
+
|
| 354 |
+
def select(self, **params):
|
| 355 |
+
"""
|
| 356 |
+
Select entry points from self that match the
|
| 357 |
+
given parameters (typically group and/or name).
|
| 358 |
+
"""
|
| 359 |
+
return EntryPoints(ep for ep in self if ep.matches(**params))
|
| 360 |
+
|
| 361 |
+
@property
|
| 362 |
+
def names(self):
|
| 363 |
+
"""
|
| 364 |
+
Return the set of all names of all entry points.
|
| 365 |
+
"""
|
| 366 |
+
return set(ep.name for ep in self)
|
| 367 |
+
|
| 368 |
+
@property
|
| 369 |
+
def groups(self):
|
| 370 |
+
"""
|
| 371 |
+
Return the set of all groups of all entry points.
|
| 372 |
+
|
| 373 |
+
For coverage while SelectableGroups is present.
|
| 374 |
+
>>> EntryPoints().groups
|
| 375 |
+
set()
|
| 376 |
+
"""
|
| 377 |
+
return set(ep.group for ep in self)
|
| 378 |
+
|
| 379 |
+
@classmethod
|
| 380 |
+
def _from_text_for(cls, text, dist):
|
| 381 |
+
return cls(ep._for(dist) for ep in cls._from_text(text))
|
| 382 |
+
|
| 383 |
+
@classmethod
|
| 384 |
+
def _from_text(cls, text):
|
| 385 |
+
return itertools.starmap(EntryPoint, cls._parse_groups(text or ''))
|
| 386 |
+
|
| 387 |
+
@staticmethod
|
| 388 |
+
def _parse_groups(text):
|
| 389 |
+
return (
|
| 390 |
+
(item.value.name, item.value.value, item.name)
|
| 391 |
+
for item in Sectioned.section_pairs(text)
|
| 392 |
+
)
|
| 393 |
+
|
| 394 |
+
|
| 395 |
+
class Deprecated:
|
| 396 |
+
"""
|
| 397 |
+
Compatibility add-in for mapping to indicate that
|
| 398 |
+
mapping behavior is deprecated.
|
| 399 |
+
|
| 400 |
+
>>> recwarn = getfixture('recwarn')
|
| 401 |
+
>>> class DeprecatedDict(Deprecated, dict): pass
|
| 402 |
+
>>> dd = DeprecatedDict(foo='bar')
|
| 403 |
+
>>> dd.get('baz', None)
|
| 404 |
+
>>> dd['foo']
|
| 405 |
+
'bar'
|
| 406 |
+
>>> list(dd)
|
| 407 |
+
['foo']
|
| 408 |
+
>>> list(dd.keys())
|
| 409 |
+
['foo']
|
| 410 |
+
>>> 'foo' in dd
|
| 411 |
+
True
|
| 412 |
+
>>> list(dd.values())
|
| 413 |
+
['bar']
|
| 414 |
+
>>> len(recwarn)
|
| 415 |
+
1
|
| 416 |
+
"""
|
| 417 |
+
|
| 418 |
+
_warn = functools.partial(
|
| 419 |
+
warnings.warn,
|
| 420 |
+
"SelectableGroups dict interface is deprecated. Use select.",
|
| 421 |
+
DeprecationWarning,
|
| 422 |
+
stacklevel=2,
|
| 423 |
+
)
|
| 424 |
+
|
| 425 |
+
def __getitem__(self, name):
|
| 426 |
+
self._warn()
|
| 427 |
+
return super().__getitem__(name)
|
| 428 |
+
|
| 429 |
+
def get(self, name, default=None):
|
| 430 |
+
self._warn()
|
| 431 |
+
return super().get(name, default)
|
| 432 |
+
|
| 433 |
+
def __iter__(self):
|
| 434 |
+
self._warn()
|
| 435 |
+
return super().__iter__()
|
| 436 |
+
|
| 437 |
+
def __contains__(self, *args):
|
| 438 |
+
self._warn()
|
| 439 |
+
return super().__contains__(*args)
|
| 440 |
+
|
| 441 |
+
def keys(self):
|
| 442 |
+
self._warn()
|
| 443 |
+
return super().keys()
|
| 444 |
+
|
| 445 |
+
def values(self):
|
| 446 |
+
self._warn()
|
| 447 |
+
return super().values()
|
| 448 |
+
|
| 449 |
+
|
| 450 |
+
class SelectableGroups(Deprecated, dict):
|
| 451 |
+
"""
|
| 452 |
+
A backward- and forward-compatible result from
|
| 453 |
+
entry_points that fully implements the dict interface.
|
| 454 |
+
"""
|
| 455 |
+
|
| 456 |
+
@classmethod
|
| 457 |
+
def load(cls, eps):
|
| 458 |
+
by_group = operator.attrgetter('group')
|
| 459 |
+
ordered = sorted(eps, key=by_group)
|
| 460 |
+
grouped = itertools.groupby(ordered, by_group)
|
| 461 |
+
return cls((group, EntryPoints(eps)) for group, eps in grouped)
|
| 462 |
+
|
| 463 |
+
@property
|
| 464 |
+
def _all(self):
|
| 465 |
+
"""
|
| 466 |
+
Reconstruct a list of all entrypoints from the groups.
|
| 467 |
+
"""
|
| 468 |
+
groups = super(Deprecated, self).values()
|
| 469 |
+
return EntryPoints(itertools.chain.from_iterable(groups))
|
| 470 |
+
|
| 471 |
+
@property
|
| 472 |
+
def groups(self):
|
| 473 |
+
return self._all.groups
|
| 474 |
+
|
| 475 |
+
@property
|
| 476 |
+
def names(self):
|
| 477 |
+
"""
|
| 478 |
+
for coverage:
|
| 479 |
+
>>> SelectableGroups().names
|
| 480 |
+
set()
|
| 481 |
+
"""
|
| 482 |
+
return self._all.names
|
| 483 |
+
|
| 484 |
+
def select(self, **params):
|
| 485 |
+
if not params:
|
| 486 |
+
return self
|
| 487 |
+
return self._all.select(**params)
|
| 488 |
+
|
| 489 |
+
|
| 490 |
+
class PackagePath(pathlib.PurePosixPath):
|
| 491 |
+
"""A reference to a path in a package"""
|
| 492 |
+
|
| 493 |
+
def read_text(self, encoding='utf-8'):
|
| 494 |
+
with self.locate().open(encoding=encoding) as stream:
|
| 495 |
+
return stream.read()
|
| 496 |
+
|
| 497 |
+
def read_binary(self):
|
| 498 |
+
with self.locate().open('rb') as stream:
|
| 499 |
+
return stream.read()
|
| 500 |
+
|
| 501 |
+
def locate(self):
|
| 502 |
+
"""Return a path-like object for this path"""
|
| 503 |
+
return self.dist.locate_file(self)
|
| 504 |
+
|
| 505 |
+
|
| 506 |
+
class FileHash:
|
| 507 |
+
def __init__(self, spec):
|
| 508 |
+
self.mode, _, self.value = spec.partition('=')
|
| 509 |
+
|
| 510 |
+
def __repr__(self):
|
| 511 |
+
return f'<FileHash mode: {self.mode} value: {self.value}>'
|
| 512 |
+
|
| 513 |
+
|
| 514 |
+
class Distribution:
|
| 515 |
+
"""A Python distribution package."""
|
| 516 |
+
|
| 517 |
+
@abc.abstractmethod
|
| 518 |
+
def read_text(self, filename):
|
| 519 |
+
"""Attempt to load metadata file given by the name.
|
| 520 |
+
|
| 521 |
+
:param filename: The name of the file in the distribution info.
|
| 522 |
+
:return: The text if found, otherwise None.
|
| 523 |
+
"""
|
| 524 |
+
|
| 525 |
+
@abc.abstractmethod
|
| 526 |
+
def locate_file(self, path):
|
| 527 |
+
"""
|
| 528 |
+
Given a path to a file in this distribution, return a path
|
| 529 |
+
to it.
|
| 530 |
+
"""
|
| 531 |
+
|
| 532 |
+
@classmethod
|
| 533 |
+
def from_name(cls, name):
|
| 534 |
+
"""Return the Distribution for the given package name.
|
| 535 |
+
|
| 536 |
+
:param name: The name of the distribution package to search for.
|
| 537 |
+
:return: The Distribution instance (or subclass thereof) for the named
|
| 538 |
+
package, if found.
|
| 539 |
+
:raises PackageNotFoundError: When the named package's distribution
|
| 540 |
+
metadata cannot be found.
|
| 541 |
+
"""
|
| 542 |
+
for resolver in cls._discover_resolvers():
|
| 543 |
+
dists = resolver(DistributionFinder.Context(name=name))
|
| 544 |
+
dist = next(iter(dists), None)
|
| 545 |
+
if dist is not None:
|
| 546 |
+
return dist
|
| 547 |
+
else:
|
| 548 |
+
raise PackageNotFoundError(name)
|
| 549 |
+
|
| 550 |
+
@classmethod
|
| 551 |
+
def discover(cls, **kwargs):
|
| 552 |
+
"""Return an iterable of Distribution objects for all packages.
|
| 553 |
+
|
| 554 |
+
Pass a ``context`` or pass keyword arguments for constructing
|
| 555 |
+
a context.
|
| 556 |
+
|
| 557 |
+
:context: A ``DistributionFinder.Context`` object.
|
| 558 |
+
:return: Iterable of Distribution objects for all packages.
|
| 559 |
+
"""
|
| 560 |
+
context = kwargs.pop('context', None)
|
| 561 |
+
if context and kwargs:
|
| 562 |
+
raise ValueError("cannot accept context and kwargs")
|
| 563 |
+
context = context or DistributionFinder.Context(**kwargs)
|
| 564 |
+
return itertools.chain.from_iterable(
|
| 565 |
+
resolver(context) for resolver in cls._discover_resolvers()
|
| 566 |
+
)
|
| 567 |
+
|
| 568 |
+
@staticmethod
|
| 569 |
+
def at(path):
|
| 570 |
+
"""Return a Distribution for the indicated metadata path
|
| 571 |
+
|
| 572 |
+
:param path: a string or path-like object
|
| 573 |
+
:return: a concrete Distribution instance for the path
|
| 574 |
+
"""
|
| 575 |
+
return PathDistribution(pathlib.Path(path))
|
| 576 |
+
|
| 577 |
+
@staticmethod
|
| 578 |
+
def _discover_resolvers():
|
| 579 |
+
"""Search the meta_path for resolvers."""
|
| 580 |
+
declared = (
|
| 581 |
+
getattr(finder, 'find_distributions', None) for finder in sys.meta_path
|
| 582 |
+
)
|
| 583 |
+
return filter(None, declared)
|
| 584 |
+
|
| 585 |
+
@classmethod
|
| 586 |
+
def _local(cls, root='.'):
|
| 587 |
+
from pep517 import build, meta
|
| 588 |
+
|
| 589 |
+
system = build.compat_system(root)
|
| 590 |
+
builder = functools.partial(
|
| 591 |
+
meta.build,
|
| 592 |
+
source_dir=root,
|
| 593 |
+
system=system,
|
| 594 |
+
)
|
| 595 |
+
return PathDistribution(zipfile.Path(meta.build_as_zip(builder)))
|
| 596 |
+
|
| 597 |
+
@property
|
| 598 |
+
def metadata(self) -> _meta.PackageMetadata:
|
| 599 |
+
"""Return the parsed metadata for this Distribution.
|
| 600 |
+
|
| 601 |
+
The returned object will have keys that name the various bits of
|
| 602 |
+
metadata. See PEP 566 for details.
|
| 603 |
+
"""
|
| 604 |
+
text = (
|
| 605 |
+
self.read_text('METADATA')
|
| 606 |
+
or self.read_text('PKG-INFO')
|
| 607 |
+
# This last clause is here to support old egg-info files. Its
|
| 608 |
+
# effect is to just end up using the PathDistribution's self._path
|
| 609 |
+
# (which points to the egg-info file) attribute unchanged.
|
| 610 |
+
or self.read_text('')
|
| 611 |
+
)
|
| 612 |
+
return _adapters.Message(email.message_from_string(text))
|
| 613 |
+
|
| 614 |
+
@property
|
| 615 |
+
def name(self):
|
| 616 |
+
"""Return the 'Name' metadata for the distribution package."""
|
| 617 |
+
return self.metadata['Name']
|
| 618 |
+
|
| 619 |
+
@property
|
| 620 |
+
def _normalized_name(self):
|
| 621 |
+
"""Return a normalized version of the name."""
|
| 622 |
+
return Prepared.normalize(self.name)
|
| 623 |
+
|
| 624 |
+
@property
|
| 625 |
+
def version(self):
|
| 626 |
+
"""Return the 'Version' metadata for the distribution package."""
|
| 627 |
+
return self.metadata['Version']
|
| 628 |
+
|
| 629 |
+
@property
|
| 630 |
+
def entry_points(self):
|
| 631 |
+
return EntryPoints._from_text_for(self.read_text('entry_points.txt'), self)
|
| 632 |
+
|
| 633 |
+
@property
|
| 634 |
+
def files(self):
|
| 635 |
+
"""Files in this distribution.
|
| 636 |
+
|
| 637 |
+
:return: List of PackagePath for this distribution or None
|
| 638 |
+
|
| 639 |
+
Result is `None` if the metadata file that enumerates files
|
| 640 |
+
(i.e. RECORD for dist-info or SOURCES.txt for egg-info) is
|
| 641 |
+
missing.
|
| 642 |
+
Result may be empty if the metadata exists but is empty.
|
| 643 |
+
"""
|
| 644 |
+
file_lines = self._read_files_distinfo() or self._read_files_egginfo()
|
| 645 |
+
|
| 646 |
+
def make_file(name, hash=None, size_str=None):
|
| 647 |
+
result = PackagePath(name)
|
| 648 |
+
result.hash = FileHash(hash) if hash else None
|
| 649 |
+
result.size = int(size_str) if size_str else None
|
| 650 |
+
result.dist = self
|
| 651 |
+
return result
|
| 652 |
+
|
| 653 |
+
return file_lines and list(starmap(make_file, csv.reader(file_lines)))
|
| 654 |
+
|
| 655 |
+
def _read_files_distinfo(self):
|
| 656 |
+
"""
|
| 657 |
+
Read the lines of RECORD
|
| 658 |
+
"""
|
| 659 |
+
text = self.read_text('RECORD')
|
| 660 |
+
return text and text.splitlines()
|
| 661 |
+
|
| 662 |
+
def _read_files_egginfo(self):
|
| 663 |
+
"""
|
| 664 |
+
SOURCES.txt might contain literal commas, so wrap each line
|
| 665 |
+
in quotes.
|
| 666 |
+
"""
|
| 667 |
+
text = self.read_text('SOURCES.txt')
|
| 668 |
+
return text and map('"{}"'.format, text.splitlines())
|
| 669 |
+
|
| 670 |
+
@property
|
| 671 |
+
def requires(self):
|
| 672 |
+
"""Generated requirements specified for this Distribution"""
|
| 673 |
+
reqs = self._read_dist_info_reqs() or self._read_egg_info_reqs()
|
| 674 |
+
return reqs and list(reqs)
|
| 675 |
+
|
| 676 |
+
def _read_dist_info_reqs(self):
|
| 677 |
+
return self.metadata.get_all('Requires-Dist')
|
| 678 |
+
|
| 679 |
+
def _read_egg_info_reqs(self):
|
| 680 |
+
source = self.read_text('requires.txt')
|
| 681 |
+
return None if source is None else self._deps_from_requires_text(source)
|
| 682 |
+
|
| 683 |
+
@classmethod
|
| 684 |
+
def _deps_from_requires_text(cls, source):
|
| 685 |
+
return cls._convert_egg_info_reqs_to_simple_reqs(Sectioned.read(source))
|
| 686 |
+
|
| 687 |
+
@staticmethod
|
| 688 |
+
def _convert_egg_info_reqs_to_simple_reqs(sections):
|
| 689 |
+
"""
|
| 690 |
+
Historically, setuptools would solicit and store 'extra'
|
| 691 |
+
requirements, including those with environment markers,
|
| 692 |
+
in separate sections. More modern tools expect each
|
| 693 |
+
dependency to be defined separately, with any relevant
|
| 694 |
+
extras and environment markers attached directly to that
|
| 695 |
+
requirement. This method converts the former to the
|
| 696 |
+
latter. See _test_deps_from_requires_text for an example.
|
| 697 |
+
"""
|
| 698 |
+
|
| 699 |
+
def make_condition(name):
|
| 700 |
+
return name and f'extra == "{name}"'
|
| 701 |
+
|
| 702 |
+
def quoted_marker(section):
|
| 703 |
+
section = section or ''
|
| 704 |
+
extra, sep, markers = section.partition(':')
|
| 705 |
+
if extra and markers:
|
| 706 |
+
markers = f'({markers})'
|
| 707 |
+
conditions = list(filter(None, [markers, make_condition(extra)]))
|
| 708 |
+
return '; ' + ' and '.join(conditions) if conditions else ''
|
| 709 |
+
|
| 710 |
+
def url_req_space(req):
|
| 711 |
+
"""
|
| 712 |
+
PEP 508 requires a space between the url_spec and the quoted_marker.
|
| 713 |
+
Ref python/importlib_metadata#357.
|
| 714 |
+
"""
|
| 715 |
+
# '@' is uniquely indicative of a url_req.
|
| 716 |
+
return ' ' * ('@' in req)
|
| 717 |
+
|
| 718 |
+
for section in sections:
|
| 719 |
+
space = url_req_space(section.value)
|
| 720 |
+
yield section.value + space + quoted_marker(section.name)
|
| 721 |
+
|
| 722 |
+
|
| 723 |
+
class DistributionFinder(MetaPathFinder):
|
| 724 |
+
"""
|
| 725 |
+
A MetaPathFinder capable of discovering installed distributions.
|
| 726 |
+
"""
|
| 727 |
+
|
| 728 |
+
class Context:
|
| 729 |
+
"""
|
| 730 |
+
Keyword arguments presented by the caller to
|
| 731 |
+
``distributions()`` or ``Distribution.discover()``
|
| 732 |
+
to narrow the scope of a search for distributions
|
| 733 |
+
in all DistributionFinders.
|
| 734 |
+
|
| 735 |
+
Each DistributionFinder may expect any parameters
|
| 736 |
+
and should attempt to honor the canonical
|
| 737 |
+
parameters defined below when appropriate.
|
| 738 |
+
"""
|
| 739 |
+
|
| 740 |
+
name = None
|
| 741 |
+
"""
|
| 742 |
+
Specific name for which a distribution finder should match.
|
| 743 |
+
A name of ``None`` matches all distributions.
|
| 744 |
+
"""
|
| 745 |
+
|
| 746 |
+
def __init__(self, **kwargs):
|
| 747 |
+
vars(self).update(kwargs)
|
| 748 |
+
|
| 749 |
+
@property
|
| 750 |
+
def path(self):
|
| 751 |
+
"""
|
| 752 |
+
The sequence of directory path that a distribution finder
|
| 753 |
+
should search.
|
| 754 |
+
|
| 755 |
+
Typically refers to Python installed package paths such as
|
| 756 |
+
"site-packages" directories and defaults to ``sys.path``.
|
| 757 |
+
"""
|
| 758 |
+
return vars(self).get('path', sys.path)
|
| 759 |
+
|
| 760 |
+
@abc.abstractmethod
|
| 761 |
+
def find_distributions(self, context=Context()):
|
| 762 |
+
"""
|
| 763 |
+
Find distributions.
|
| 764 |
+
|
| 765 |
+
Return an iterable of all Distribution instances capable of
|
| 766 |
+
loading the metadata for packages matching the ``context``,
|
| 767 |
+
a DistributionFinder.Context instance.
|
| 768 |
+
"""
|
| 769 |
+
|
| 770 |
+
|
| 771 |
+
class FastPath:
|
| 772 |
+
"""
|
| 773 |
+
Micro-optimized class for searching a path for
|
| 774 |
+
children.
|
| 775 |
+
"""
|
| 776 |
+
|
| 777 |
+
@functools.lru_cache() # type: ignore
|
| 778 |
+
def __new__(cls, root):
|
| 779 |
+
return super().__new__(cls)
|
| 780 |
+
|
| 781 |
+
def __init__(self, root):
|
| 782 |
+
self.root = root
|
| 783 |
+
|
| 784 |
+
def joinpath(self, child):
|
| 785 |
+
return pathlib.Path(self.root, child)
|
| 786 |
+
|
| 787 |
+
def children(self):
|
| 788 |
+
with suppress(Exception):
|
| 789 |
+
return os.listdir(self.root or '.')
|
| 790 |
+
with suppress(Exception):
|
| 791 |
+
return self.zip_children()
|
| 792 |
+
return []
|
| 793 |
+
|
| 794 |
+
def zip_children(self):
|
| 795 |
+
zip_path = zipfile.Path(self.root)
|
| 796 |
+
names = zip_path.root.namelist()
|
| 797 |
+
self.joinpath = zip_path.joinpath
|
| 798 |
+
|
| 799 |
+
return dict.fromkeys(child.split(posixpath.sep, 1)[0] for child in names)
|
| 800 |
+
|
| 801 |
+
def search(self, name):
|
| 802 |
+
return self.lookup(self.mtime).search(name)
|
| 803 |
+
|
| 804 |
+
@property
|
| 805 |
+
def mtime(self):
|
| 806 |
+
with suppress(OSError):
|
| 807 |
+
return os.stat(self.root).st_mtime
|
| 808 |
+
self.lookup.cache_clear()
|
| 809 |
+
|
| 810 |
+
@method_cache
|
| 811 |
+
def lookup(self, mtime):
|
| 812 |
+
return Lookup(self)
|
| 813 |
+
|
| 814 |
+
|
| 815 |
+
class Lookup:
|
| 816 |
+
def __init__(self, path: FastPath):
|
| 817 |
+
base = os.path.basename(path.root).lower()
|
| 818 |
+
base_is_egg = base.endswith(".egg")
|
| 819 |
+
self.infos = FreezableDefaultDict(list)
|
| 820 |
+
self.eggs = FreezableDefaultDict(list)
|
| 821 |
+
|
| 822 |
+
for child in path.children():
|
| 823 |
+
low = child.lower()
|
| 824 |
+
if low.endswith((".dist-info", ".egg-info")):
|
| 825 |
+
# rpartition is faster than splitext and suitable for this purpose.
|
| 826 |
+
name = low.rpartition(".")[0].partition("-")[0]
|
| 827 |
+
normalized = Prepared.normalize(name)
|
| 828 |
+
self.infos[normalized].append(path.joinpath(child))
|
| 829 |
+
elif base_is_egg and low == "egg-info":
|
| 830 |
+
name = base.rpartition(".")[0].partition("-")[0]
|
| 831 |
+
legacy_normalized = Prepared.legacy_normalize(name)
|
| 832 |
+
self.eggs[legacy_normalized].append(path.joinpath(child))
|
| 833 |
+
|
| 834 |
+
self.infos.freeze()
|
| 835 |
+
self.eggs.freeze()
|
| 836 |
+
|
| 837 |
+
def search(self, prepared):
|
| 838 |
+
infos = (
|
| 839 |
+
self.infos[prepared.normalized]
|
| 840 |
+
if prepared
|
| 841 |
+
else itertools.chain.from_iterable(self.infos.values())
|
| 842 |
+
)
|
| 843 |
+
eggs = (
|
| 844 |
+
self.eggs[prepared.legacy_normalized]
|
| 845 |
+
if prepared
|
| 846 |
+
else itertools.chain.from_iterable(self.eggs.values())
|
| 847 |
+
)
|
| 848 |
+
return itertools.chain(infos, eggs)
|
| 849 |
+
|
| 850 |
+
|
| 851 |
+
class Prepared:
|
| 852 |
+
"""
|
| 853 |
+
A prepared search for metadata on a possibly-named package.
|
| 854 |
+
"""
|
| 855 |
+
|
| 856 |
+
normalized = None
|
| 857 |
+
legacy_normalized = None
|
| 858 |
+
|
| 859 |
+
def __init__(self, name):
|
| 860 |
+
self.name = name
|
| 861 |
+
if name is None:
|
| 862 |
+
return
|
| 863 |
+
self.normalized = self.normalize(name)
|
| 864 |
+
self.legacy_normalized = self.legacy_normalize(name)
|
| 865 |
+
|
| 866 |
+
@staticmethod
|
| 867 |
+
def normalize(name):
|
| 868 |
+
"""
|
| 869 |
+
PEP 503 normalization plus dashes as underscores.
|
| 870 |
+
"""
|
| 871 |
+
return re.sub(r"[-_.]+", "-", name).lower().replace('-', '_')
|
| 872 |
+
|
| 873 |
+
@staticmethod
|
| 874 |
+
def legacy_normalize(name):
|
| 875 |
+
"""
|
| 876 |
+
Normalize the package name as found in the convention in
|
| 877 |
+
older packaging tools versions and specs.
|
| 878 |
+
"""
|
| 879 |
+
return name.lower().replace('-', '_')
|
| 880 |
+
|
| 881 |
+
def __bool__(self):
|
| 882 |
+
return bool(self.name)
|
| 883 |
+
|
| 884 |
+
|
| 885 |
+
class MetadataPathFinder(DistributionFinder):
|
| 886 |
+
@classmethod
|
| 887 |
+
def find_distributions(cls, context=DistributionFinder.Context()):
|
| 888 |
+
"""
|
| 889 |
+
Find distributions.
|
| 890 |
+
|
| 891 |
+
Return an iterable of all Distribution instances capable of
|
| 892 |
+
loading the metadata for packages matching ``context.name``
|
| 893 |
+
(or all names if ``None`` indicated) along the paths in the list
|
| 894 |
+
of directories ``context.path``.
|
| 895 |
+
"""
|
| 896 |
+
found = cls._search_paths(context.name, context.path)
|
| 897 |
+
return map(PathDistribution, found)
|
| 898 |
+
|
| 899 |
+
@classmethod
|
| 900 |
+
def _search_paths(cls, name, paths):
|
| 901 |
+
"""Find metadata directories in paths heuristically."""
|
| 902 |
+
prepared = Prepared(name)
|
| 903 |
+
return itertools.chain.from_iterable(
|
| 904 |
+
path.search(prepared) for path in map(FastPath, paths)
|
| 905 |
+
)
|
| 906 |
+
|
| 907 |
+
def invalidate_caches(cls):
|
| 908 |
+
FastPath.__new__.cache_clear()
|
| 909 |
+
|
| 910 |
+
|
| 911 |
+
class PathDistribution(Distribution):
|
| 912 |
+
def __init__(self, path: SimplePath):
|
| 913 |
+
"""Construct a distribution.
|
| 914 |
+
|
| 915 |
+
:param path: SimplePath indicating the metadata directory.
|
| 916 |
+
"""
|
| 917 |
+
self._path = path
|
| 918 |
+
|
| 919 |
+
def read_text(self, filename):
|
| 920 |
+
with suppress(
|
| 921 |
+
FileNotFoundError,
|
| 922 |
+
IsADirectoryError,
|
| 923 |
+
KeyError,
|
| 924 |
+
NotADirectoryError,
|
| 925 |
+
PermissionError,
|
| 926 |
+
):
|
| 927 |
+
return self._path.joinpath(filename).read_text(encoding='utf-8')
|
| 928 |
+
|
| 929 |
+
read_text.__doc__ = Distribution.read_text.__doc__
|
| 930 |
+
|
| 931 |
+
def locate_file(self, path):
|
| 932 |
+
return self._path.parent / path
|
| 933 |
+
|
| 934 |
+
@property
|
| 935 |
+
def _normalized_name(self):
|
| 936 |
+
"""
|
| 937 |
+
Performance optimization: where possible, resolve the
|
| 938 |
+
normalized name from the file system path.
|
| 939 |
+
"""
|
| 940 |
+
stem = os.path.basename(str(self._path))
|
| 941 |
+
return (
|
| 942 |
+
pass_none(Prepared.normalize)(self._name_from_stem(stem))
|
| 943 |
+
or super()._normalized_name
|
| 944 |
+
)
|
| 945 |
+
|
| 946 |
+
@staticmethod
|
| 947 |
+
def _name_from_stem(stem):
|
| 948 |
+
"""
|
| 949 |
+
>>> PathDistribution._name_from_stem('foo-3.0.egg-info')
|
| 950 |
+
'foo'
|
| 951 |
+
>>> PathDistribution._name_from_stem('CherryPy-3.0.dist-info')
|
| 952 |
+
'CherryPy'
|
| 953 |
+
>>> PathDistribution._name_from_stem('face.egg-info')
|
| 954 |
+
'face'
|
| 955 |
+
"""
|
| 956 |
+
filename, ext = os.path.splitext(stem)
|
| 957 |
+
if ext not in ('.dist-info', '.egg-info'):
|
| 958 |
+
return
|
| 959 |
+
name, sep, rest = filename.partition('-')
|
| 960 |
+
return name
|
| 961 |
+
|
| 962 |
+
|
| 963 |
+
def distribution(distribution_name):
|
| 964 |
+
"""Get the ``Distribution`` instance for the named package.
|
| 965 |
+
|
| 966 |
+
:param distribution_name: The name of the distribution package as a string.
|
| 967 |
+
:return: A ``Distribution`` instance (or subclass thereof).
|
| 968 |
+
"""
|
| 969 |
+
return Distribution.from_name(distribution_name)
|
| 970 |
+
|
| 971 |
+
|
| 972 |
+
def distributions(**kwargs):
|
| 973 |
+
"""Get all ``Distribution`` instances in the current environment.
|
| 974 |
+
|
| 975 |
+
:return: An iterable of ``Distribution`` instances.
|
| 976 |
+
"""
|
| 977 |
+
return Distribution.discover(**kwargs)
|
| 978 |
+
|
| 979 |
+
|
| 980 |
+
def metadata(distribution_name) -> _meta.PackageMetadata:
|
| 981 |
+
"""Get the metadata for the named package.
|
| 982 |
+
|
| 983 |
+
:param distribution_name: The name of the distribution package to query.
|
| 984 |
+
:return: A PackageMetadata containing the parsed metadata.
|
| 985 |
+
"""
|
| 986 |
+
return Distribution.from_name(distribution_name).metadata
|
| 987 |
+
|
| 988 |
+
|
| 989 |
+
def version(distribution_name):
|
| 990 |
+
"""Get the version string for the named package.
|
| 991 |
+
|
| 992 |
+
:param distribution_name: The name of the distribution package to query.
|
| 993 |
+
:return: The version string for the package as defined in the package's
|
| 994 |
+
"Version" metadata key.
|
| 995 |
+
"""
|
| 996 |
+
return distribution(distribution_name).version
|
| 997 |
+
|
| 998 |
+
|
| 999 |
+
def entry_points(**params) -> Union[EntryPoints, SelectableGroups]:
|
| 1000 |
+
"""Return EntryPoint objects for all installed packages.
|
| 1001 |
+
|
| 1002 |
+
Pass selection parameters (group or name) to filter the
|
| 1003 |
+
result to entry points matching those properties (see
|
| 1004 |
+
EntryPoints.select()).
|
| 1005 |
+
|
| 1006 |
+
For compatibility, returns ``SelectableGroups`` object unless
|
| 1007 |
+
selection parameters are supplied. In the future, this function
|
| 1008 |
+
will return ``EntryPoints`` instead of ``SelectableGroups``
|
| 1009 |
+
even when no selection parameters are supplied.
|
| 1010 |
+
|
| 1011 |
+
For maximum future compatibility, pass selection parameters
|
| 1012 |
+
or invoke ``.select`` with parameters on the result.
|
| 1013 |
+
|
| 1014 |
+
:return: EntryPoints or SelectableGroups for all installed packages.
|
| 1015 |
+
"""
|
| 1016 |
+
norm_name = operator.attrgetter('_normalized_name')
|
| 1017 |
+
unique = functools.partial(unique_everseen, key=norm_name)
|
| 1018 |
+
eps = itertools.chain.from_iterable(
|
| 1019 |
+
dist.entry_points for dist in unique(distributions())
|
| 1020 |
+
)
|
| 1021 |
+
return SelectableGroups.load(eps).select(**params)
|
| 1022 |
+
|
| 1023 |
+
|
| 1024 |
+
def files(distribution_name):
|
| 1025 |
+
"""Return a list of files for the named package.
|
| 1026 |
+
|
| 1027 |
+
:param distribution_name: The name of the distribution package to query.
|
| 1028 |
+
:return: List of files composing the distribution.
|
| 1029 |
+
"""
|
| 1030 |
+
return distribution(distribution_name).files
|
| 1031 |
+
|
| 1032 |
+
|
| 1033 |
+
def requires(distribution_name):
|
| 1034 |
+
"""
|
| 1035 |
+
Return a list of requirements for the named package.
|
| 1036 |
+
|
| 1037 |
+
:return: An iterator of requirements, suitable for
|
| 1038 |
+
packaging.requirement.Requirement.
|
| 1039 |
+
"""
|
| 1040 |
+
return distribution(distribution_name).requires
|
| 1041 |
+
|
| 1042 |
+
|
| 1043 |
+
def packages_distributions() -> Mapping[str, List[str]]:
|
| 1044 |
+
"""
|
| 1045 |
+
Return a mapping of top-level packages to their
|
| 1046 |
+
distributions.
|
| 1047 |
+
|
| 1048 |
+
>>> import collections.abc
|
| 1049 |
+
>>> pkgs = packages_distributions()
|
| 1050 |
+
>>> all(isinstance(dist, collections.abc.Sequence) for dist in pkgs.values())
|
| 1051 |
+
True
|
| 1052 |
+
"""
|
| 1053 |
+
pkg_to_dist = collections.defaultdict(list)
|
| 1054 |
+
for dist in distributions():
|
| 1055 |
+
for pkg in (dist.read_text('top_level.txt') or '').split():
|
| 1056 |
+
pkg_to_dist[pkg].append(dist.metadata['Name'])
|
| 1057 |
+
return dict(pkg_to_dist)
|
parrot/lib/python3.10/importlib/metadata/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (37.1 kB). View file
|
|
|
parrot/lib/python3.10/importlib/metadata/__pycache__/_adapters.cpython-310.pyc
ADDED
|
Binary file (2.6 kB). View file
|
|
|
parrot/lib/python3.10/importlib/metadata/__pycache__/_functools.cpython-310.pyc
ADDED
|
Binary file (3.36 kB). View file
|
|
|
parrot/lib/python3.10/importlib/metadata/__pycache__/_itertools.cpython-310.pyc
ADDED
|
Binary file (825 Bytes). View file
|
|
|
parrot/lib/python3.10/importlib/metadata/__pycache__/_text.cpython-310.pyc
ADDED
|
Binary file (3.31 kB). View file
|
|
|
parrot/lib/python3.10/importlib/metadata/_adapters.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re
|
| 2 |
+
import textwrap
|
| 3 |
+
import email.message
|
| 4 |
+
|
| 5 |
+
from ._text import FoldedCase
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class Message(email.message.Message):
|
| 9 |
+
multiple_use_keys = set(
|
| 10 |
+
map(
|
| 11 |
+
FoldedCase,
|
| 12 |
+
[
|
| 13 |
+
'Classifier',
|
| 14 |
+
'Obsoletes-Dist',
|
| 15 |
+
'Platform',
|
| 16 |
+
'Project-URL',
|
| 17 |
+
'Provides-Dist',
|
| 18 |
+
'Provides-Extra',
|
| 19 |
+
'Requires-Dist',
|
| 20 |
+
'Requires-External',
|
| 21 |
+
'Supported-Platform',
|
| 22 |
+
'Dynamic',
|
| 23 |
+
],
|
| 24 |
+
)
|
| 25 |
+
)
|
| 26 |
+
"""
|
| 27 |
+
Keys that may be indicated multiple times per PEP 566.
|
| 28 |
+
"""
|
| 29 |
+
|
| 30 |
+
def __new__(cls, orig: email.message.Message):
|
| 31 |
+
res = super().__new__(cls)
|
| 32 |
+
vars(res).update(vars(orig))
|
| 33 |
+
return res
|
| 34 |
+
|
| 35 |
+
def __init__(self, *args, **kwargs):
|
| 36 |
+
self._headers = self._repair_headers()
|
| 37 |
+
|
| 38 |
+
# suppress spurious error from mypy
|
| 39 |
+
def __iter__(self):
|
| 40 |
+
return super().__iter__()
|
| 41 |
+
|
| 42 |
+
def _repair_headers(self):
|
| 43 |
+
def redent(value):
|
| 44 |
+
"Correct for RFC822 indentation"
|
| 45 |
+
if not value or '\n' not in value:
|
| 46 |
+
return value
|
| 47 |
+
return textwrap.dedent(' ' * 8 + value)
|
| 48 |
+
|
| 49 |
+
headers = [(key, redent(value)) for key, value in vars(self)['_headers']]
|
| 50 |
+
if self._payload:
|
| 51 |
+
headers.append(('Description', self.get_payload()))
|
| 52 |
+
return headers
|
| 53 |
+
|
| 54 |
+
@property
|
| 55 |
+
def json(self):
|
| 56 |
+
"""
|
| 57 |
+
Convert PackageMetadata to a JSON-compatible format
|
| 58 |
+
per PEP 0566.
|
| 59 |
+
"""
|
| 60 |
+
|
| 61 |
+
def transform(key):
|
| 62 |
+
value = self.get_all(key) if key in self.multiple_use_keys else self[key]
|
| 63 |
+
if key == 'Keywords':
|
| 64 |
+
value = re.split(r'\s+', value)
|
| 65 |
+
tk = key.lower().replace('-', '_')
|
| 66 |
+
return tk, value
|
| 67 |
+
|
| 68 |
+
return dict(map(transform, map(FoldedCase, self)))
|
parrot/lib/python3.10/importlib/metadata/_collections.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import collections
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
# from jaraco.collections 3.3
|
| 5 |
+
class FreezableDefaultDict(collections.defaultdict):
|
| 6 |
+
"""
|
| 7 |
+
Often it is desirable to prevent the mutation of
|
| 8 |
+
a default dict after its initial construction, such
|
| 9 |
+
as to prevent mutation during iteration.
|
| 10 |
+
|
| 11 |
+
>>> dd = FreezableDefaultDict(list)
|
| 12 |
+
>>> dd[0].append('1')
|
| 13 |
+
>>> dd.freeze()
|
| 14 |
+
>>> dd[1]
|
| 15 |
+
[]
|
| 16 |
+
>>> len(dd)
|
| 17 |
+
1
|
| 18 |
+
"""
|
| 19 |
+
|
| 20 |
+
def __missing__(self, key):
|
| 21 |
+
return getattr(self, '_frozen', super().__missing__)(key)
|
| 22 |
+
|
| 23 |
+
def freeze(self):
|
| 24 |
+
self._frozen = lambda key: self.default_factory()
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class Pair(collections.namedtuple('Pair', 'name value')):
|
| 28 |
+
@classmethod
|
| 29 |
+
def parse(cls, text):
|
| 30 |
+
return cls(*map(str.strip, text.split("=", 1)))
|
parrot/lib/python3.10/importlib/metadata/_functools.py
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import types
|
| 2 |
+
import functools
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
# from jaraco.functools 3.3
|
| 6 |
+
def method_cache(method, cache_wrapper=None):
|
| 7 |
+
"""
|
| 8 |
+
Wrap lru_cache to support storing the cache data in the object instances.
|
| 9 |
+
|
| 10 |
+
Abstracts the common paradigm where the method explicitly saves an
|
| 11 |
+
underscore-prefixed protected property on first call and returns that
|
| 12 |
+
subsequently.
|
| 13 |
+
|
| 14 |
+
>>> class MyClass:
|
| 15 |
+
... calls = 0
|
| 16 |
+
...
|
| 17 |
+
... @method_cache
|
| 18 |
+
... def method(self, value):
|
| 19 |
+
... self.calls += 1
|
| 20 |
+
... return value
|
| 21 |
+
|
| 22 |
+
>>> a = MyClass()
|
| 23 |
+
>>> a.method(3)
|
| 24 |
+
3
|
| 25 |
+
>>> for x in range(75):
|
| 26 |
+
... res = a.method(x)
|
| 27 |
+
>>> a.calls
|
| 28 |
+
75
|
| 29 |
+
|
| 30 |
+
Note that the apparent behavior will be exactly like that of lru_cache
|
| 31 |
+
except that the cache is stored on each instance, so values in one
|
| 32 |
+
instance will not flush values from another, and when an instance is
|
| 33 |
+
deleted, so are the cached values for that instance.
|
| 34 |
+
|
| 35 |
+
>>> b = MyClass()
|
| 36 |
+
>>> for x in range(35):
|
| 37 |
+
... res = b.method(x)
|
| 38 |
+
>>> b.calls
|
| 39 |
+
35
|
| 40 |
+
>>> a.method(0)
|
| 41 |
+
0
|
| 42 |
+
>>> a.calls
|
| 43 |
+
75
|
| 44 |
+
|
| 45 |
+
Note that if method had been decorated with ``functools.lru_cache()``,
|
| 46 |
+
a.calls would have been 76 (due to the cached value of 0 having been
|
| 47 |
+
flushed by the 'b' instance).
|
| 48 |
+
|
| 49 |
+
Clear the cache with ``.cache_clear()``
|
| 50 |
+
|
| 51 |
+
>>> a.method.cache_clear()
|
| 52 |
+
|
| 53 |
+
Same for a method that hasn't yet been called.
|
| 54 |
+
|
| 55 |
+
>>> c = MyClass()
|
| 56 |
+
>>> c.method.cache_clear()
|
| 57 |
+
|
| 58 |
+
Another cache wrapper may be supplied:
|
| 59 |
+
|
| 60 |
+
>>> cache = functools.lru_cache(maxsize=2)
|
| 61 |
+
>>> MyClass.method2 = method_cache(lambda self: 3, cache_wrapper=cache)
|
| 62 |
+
>>> a = MyClass()
|
| 63 |
+
>>> a.method2()
|
| 64 |
+
3
|
| 65 |
+
|
| 66 |
+
Caution - do not subsequently wrap the method with another decorator, such
|
| 67 |
+
as ``@property``, which changes the semantics of the function.
|
| 68 |
+
|
| 69 |
+
See also
|
| 70 |
+
http://code.activestate.com/recipes/577452-a-memoize-decorator-for-instance-methods/
|
| 71 |
+
for another implementation and additional justification.
|
| 72 |
+
"""
|
| 73 |
+
cache_wrapper = cache_wrapper or functools.lru_cache()
|
| 74 |
+
|
| 75 |
+
def wrapper(self, *args, **kwargs):
|
| 76 |
+
# it's the first call, replace the method with a cached, bound method
|
| 77 |
+
bound_method = types.MethodType(method, self)
|
| 78 |
+
cached_method = cache_wrapper(bound_method)
|
| 79 |
+
setattr(self, method.__name__, cached_method)
|
| 80 |
+
return cached_method(*args, **kwargs)
|
| 81 |
+
|
| 82 |
+
# Support cache clear even before cache has been created.
|
| 83 |
+
wrapper.cache_clear = lambda: None
|
| 84 |
+
|
| 85 |
+
return wrapper
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
# From jaraco.functools 3.3
|
| 89 |
+
def pass_none(func):
|
| 90 |
+
"""
|
| 91 |
+
Wrap func so it's not called if its first param is None
|
| 92 |
+
|
| 93 |
+
>>> print_text = pass_none(print)
|
| 94 |
+
>>> print_text('text')
|
| 95 |
+
text
|
| 96 |
+
>>> print_text(None)
|
| 97 |
+
"""
|
| 98 |
+
|
| 99 |
+
@functools.wraps(func)
|
| 100 |
+
def wrapper(param, *args, **kwargs):
|
| 101 |
+
if param is not None:
|
| 102 |
+
return func(param, *args, **kwargs)
|
| 103 |
+
|
| 104 |
+
return wrapper
|
parrot/lib/python3.10/importlib/metadata/_itertools.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from itertools import filterfalse
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def unique_everseen(iterable, key=None):
|
| 5 |
+
"List unique elements, preserving order. Remember all elements ever seen."
|
| 6 |
+
# unique_everseen('AAAABBBCCDAABBB') --> A B C D
|
| 7 |
+
# unique_everseen('ABBCcAD', str.lower) --> A B C D
|
| 8 |
+
seen = set()
|
| 9 |
+
seen_add = seen.add
|
| 10 |
+
if key is None:
|
| 11 |
+
for element in filterfalse(seen.__contains__, iterable):
|
| 12 |
+
seen_add(element)
|
| 13 |
+
yield element
|
| 14 |
+
else:
|
| 15 |
+
for element in iterable:
|
| 16 |
+
k = key(element)
|
| 17 |
+
if k not in seen:
|
| 18 |
+
seen_add(k)
|
| 19 |
+
yield element
|
parrot/lib/python3.10/importlib/metadata/_meta.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any, Dict, Iterator, List, Protocol, TypeVar, Union
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
_T = TypeVar("_T")
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class PackageMetadata(Protocol):
|
| 8 |
+
def __len__(self) -> int:
|
| 9 |
+
... # pragma: no cover
|
| 10 |
+
|
| 11 |
+
def __contains__(self, item: str) -> bool:
|
| 12 |
+
... # pragma: no cover
|
| 13 |
+
|
| 14 |
+
def __getitem__(self, key: str) -> str:
|
| 15 |
+
... # pragma: no cover
|
| 16 |
+
|
| 17 |
+
def __iter__(self) -> Iterator[str]:
|
| 18 |
+
... # pragma: no cover
|
| 19 |
+
|
| 20 |
+
def get_all(self, name: str, failobj: _T = ...) -> Union[List[Any], _T]:
|
| 21 |
+
"""
|
| 22 |
+
Return all values associated with a possibly multi-valued key.
|
| 23 |
+
"""
|
| 24 |
+
|
| 25 |
+
@property
|
| 26 |
+
def json(self) -> Dict[str, Union[str, List[str]]]:
|
| 27 |
+
"""
|
| 28 |
+
A JSON-compatible form of the metadata.
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
class SimplePath(Protocol):
|
| 33 |
+
"""
|
| 34 |
+
A minimal subset of pathlib.Path required by PathDistribution.
|
| 35 |
+
"""
|
| 36 |
+
|
| 37 |
+
def joinpath(self) -> 'SimplePath':
|
| 38 |
+
... # pragma: no cover
|
| 39 |
+
|
| 40 |
+
def __div__(self) -> 'SimplePath':
|
| 41 |
+
... # pragma: no cover
|
| 42 |
+
|
| 43 |
+
def parent(self) -> 'SimplePath':
|
| 44 |
+
... # pragma: no cover
|
| 45 |
+
|
| 46 |
+
def read_text(self) -> str:
|
| 47 |
+
... # pragma: no cover
|
parrot/lib/python3.10/importlib/metadata/_text.py
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re
|
| 2 |
+
|
| 3 |
+
from ._functools import method_cache
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
# from jaraco.text 3.5
|
| 7 |
+
class FoldedCase(str):
|
| 8 |
+
"""
|
| 9 |
+
A case insensitive string class; behaves just like str
|
| 10 |
+
except compares equal when the only variation is case.
|
| 11 |
+
|
| 12 |
+
>>> s = FoldedCase('hello world')
|
| 13 |
+
|
| 14 |
+
>>> s == 'Hello World'
|
| 15 |
+
True
|
| 16 |
+
|
| 17 |
+
>>> 'Hello World' == s
|
| 18 |
+
True
|
| 19 |
+
|
| 20 |
+
>>> s != 'Hello World'
|
| 21 |
+
False
|
| 22 |
+
|
| 23 |
+
>>> s.index('O')
|
| 24 |
+
4
|
| 25 |
+
|
| 26 |
+
>>> s.split('O')
|
| 27 |
+
['hell', ' w', 'rld']
|
| 28 |
+
|
| 29 |
+
>>> sorted(map(FoldedCase, ['GAMMA', 'alpha', 'Beta']))
|
| 30 |
+
['alpha', 'Beta', 'GAMMA']
|
| 31 |
+
|
| 32 |
+
Sequence membership is straightforward.
|
| 33 |
+
|
| 34 |
+
>>> "Hello World" in [s]
|
| 35 |
+
True
|
| 36 |
+
>>> s in ["Hello World"]
|
| 37 |
+
True
|
| 38 |
+
|
| 39 |
+
You may test for set inclusion, but candidate and elements
|
| 40 |
+
must both be folded.
|
| 41 |
+
|
| 42 |
+
>>> FoldedCase("Hello World") in {s}
|
| 43 |
+
True
|
| 44 |
+
>>> s in {FoldedCase("Hello World")}
|
| 45 |
+
True
|
| 46 |
+
|
| 47 |
+
String inclusion works as long as the FoldedCase object
|
| 48 |
+
is on the right.
|
| 49 |
+
|
| 50 |
+
>>> "hello" in FoldedCase("Hello World")
|
| 51 |
+
True
|
| 52 |
+
|
| 53 |
+
But not if the FoldedCase object is on the left:
|
| 54 |
+
|
| 55 |
+
>>> FoldedCase('hello') in 'Hello World'
|
| 56 |
+
False
|
| 57 |
+
|
| 58 |
+
In that case, use in_:
|
| 59 |
+
|
| 60 |
+
>>> FoldedCase('hello').in_('Hello World')
|
| 61 |
+
True
|
| 62 |
+
|
| 63 |
+
>>> FoldedCase('hello') > FoldedCase('Hello')
|
| 64 |
+
False
|
| 65 |
+
"""
|
| 66 |
+
|
| 67 |
+
def __lt__(self, other):
|
| 68 |
+
return self.lower() < other.lower()
|
| 69 |
+
|
| 70 |
+
def __gt__(self, other):
|
| 71 |
+
return self.lower() > other.lower()
|
| 72 |
+
|
| 73 |
+
def __eq__(self, other):
|
| 74 |
+
return self.lower() == other.lower()
|
| 75 |
+
|
| 76 |
+
def __ne__(self, other):
|
| 77 |
+
return self.lower() != other.lower()
|
| 78 |
+
|
| 79 |
+
def __hash__(self):
|
| 80 |
+
return hash(self.lower())
|
| 81 |
+
|
| 82 |
+
def __contains__(self, other):
|
| 83 |
+
return super(FoldedCase, self).lower().__contains__(other.lower())
|
| 84 |
+
|
| 85 |
+
def in_(self, other):
|
| 86 |
+
"Does self appear in other?"
|
| 87 |
+
return self in FoldedCase(other)
|
| 88 |
+
|
| 89 |
+
# cache lower since it's likely to be called frequently.
|
| 90 |
+
@method_cache
|
| 91 |
+
def lower(self):
|
| 92 |
+
return super(FoldedCase, self).lower()
|
| 93 |
+
|
| 94 |
+
def index(self, sub):
|
| 95 |
+
return self.lower().index(sub.lower())
|
| 96 |
+
|
| 97 |
+
def split(self, splitter=' ', maxsplit=0):
|
| 98 |
+
pattern = re.compile(re.escape(splitter), re.I)
|
| 99 |
+
return pattern.split(self, maxsplit)
|
parrot/lib/python3.10/site-packages/README.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
This directory exists so that 3rd party packages can be installed
|
| 2 |
+
here. Read the source for site.py for more details.
|
parrot/lib/python3.10/site-packages/click-8.1.7.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pip
|
parrot/lib/python3.10/site-packages/click-8.1.7.dist-info/LICENSE.rst
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright 2014 Pallets
|
| 2 |
+
|
| 3 |
+
Redistribution and use in source and binary forms, with or without
|
| 4 |
+
modification, are permitted provided that the following conditions are
|
| 5 |
+
met:
|
| 6 |
+
|
| 7 |
+
1. Redistributions of source code must retain the above copyright
|
| 8 |
+
notice, this list of conditions and the following disclaimer.
|
| 9 |
+
|
| 10 |
+
2. Redistributions in binary form must reproduce the above copyright
|
| 11 |
+
notice, this list of conditions and the following disclaimer in the
|
| 12 |
+
documentation and/or other materials provided with the distribution.
|
| 13 |
+
|
| 14 |
+
3. Neither the name of the copyright holder nor the names of its
|
| 15 |
+
contributors may be used to endorse or promote products derived from
|
| 16 |
+
this software without specific prior written permission.
|
| 17 |
+
|
| 18 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 19 |
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 20 |
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
| 21 |
+
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| 22 |
+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 23 |
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
| 24 |
+
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
| 25 |
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
| 26 |
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
| 27 |
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
| 28 |
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
parrot/lib/python3.10/site-packages/click-8.1.7.dist-info/METADATA
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.1
|
| 2 |
+
Name: click
|
| 3 |
+
Version: 8.1.7
|
| 4 |
+
Summary: Composable command line interface toolkit
|
| 5 |
+
Home-page: https://palletsprojects.com/p/click/
|
| 6 |
+
Maintainer: Pallets
|
| 7 |
+
Maintainer-email: contact@palletsprojects.com
|
| 8 |
+
License: BSD-3-Clause
|
| 9 |
+
Project-URL: Donate, https://palletsprojects.com/donate
|
| 10 |
+
Project-URL: Documentation, https://click.palletsprojects.com/
|
| 11 |
+
Project-URL: Changes, https://click.palletsprojects.com/changes/
|
| 12 |
+
Project-URL: Source Code, https://github.com/pallets/click/
|
| 13 |
+
Project-URL: Issue Tracker, https://github.com/pallets/click/issues/
|
| 14 |
+
Project-URL: Chat, https://discord.gg/pallets
|
| 15 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 16 |
+
Classifier: Intended Audience :: Developers
|
| 17 |
+
Classifier: License :: OSI Approved :: BSD License
|
| 18 |
+
Classifier: Operating System :: OS Independent
|
| 19 |
+
Classifier: Programming Language :: Python
|
| 20 |
+
Requires-Python: >=3.7
|
| 21 |
+
Description-Content-Type: text/x-rst
|
| 22 |
+
License-File: LICENSE.rst
|
| 23 |
+
Requires-Dist: colorama ; platform_system == "Windows"
|
| 24 |
+
Requires-Dist: importlib-metadata ; python_version < "3.8"
|
| 25 |
+
|
| 26 |
+
\$ click\_
|
| 27 |
+
==========
|
| 28 |
+
|
| 29 |
+
Click is a Python package for creating beautiful command line interfaces
|
| 30 |
+
in a composable way with as little code as necessary. It's the "Command
|
| 31 |
+
Line Interface Creation Kit". It's highly configurable but comes with
|
| 32 |
+
sensible defaults out of the box.
|
| 33 |
+
|
| 34 |
+
It aims to make the process of writing command line tools quick and fun
|
| 35 |
+
while also preventing any frustration caused by the inability to
|
| 36 |
+
implement an intended CLI API.
|
| 37 |
+
|
| 38 |
+
Click in three points:
|
| 39 |
+
|
| 40 |
+
- Arbitrary nesting of commands
|
| 41 |
+
- Automatic help page generation
|
| 42 |
+
- Supports lazy loading of subcommands at runtime
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
Installing
|
| 46 |
+
----------
|
| 47 |
+
|
| 48 |
+
Install and update using `pip`_:
|
| 49 |
+
|
| 50 |
+
.. code-block:: text
|
| 51 |
+
|
| 52 |
+
$ pip install -U click
|
| 53 |
+
|
| 54 |
+
.. _pip: https://pip.pypa.io/en/stable/getting-started/
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
A Simple Example
|
| 58 |
+
----------------
|
| 59 |
+
|
| 60 |
+
.. code-block:: python
|
| 61 |
+
|
| 62 |
+
import click
|
| 63 |
+
|
| 64 |
+
@click.command()
|
| 65 |
+
@click.option("--count", default=1, help="Number of greetings.")
|
| 66 |
+
@click.option("--name", prompt="Your name", help="The person to greet.")
|
| 67 |
+
def hello(count, name):
|
| 68 |
+
"""Simple program that greets NAME for a total of COUNT times."""
|
| 69 |
+
for _ in range(count):
|
| 70 |
+
click.echo(f"Hello, {name}!")
|
| 71 |
+
|
| 72 |
+
if __name__ == '__main__':
|
| 73 |
+
hello()
|
| 74 |
+
|
| 75 |
+
.. code-block:: text
|
| 76 |
+
|
| 77 |
+
$ python hello.py --count=3
|
| 78 |
+
Your name: Click
|
| 79 |
+
Hello, Click!
|
| 80 |
+
Hello, Click!
|
| 81 |
+
Hello, Click!
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
Donate
|
| 85 |
+
------
|
| 86 |
+
|
| 87 |
+
The Pallets organization develops and supports Click and other popular
|
| 88 |
+
packages. In order to grow the community of contributors and users, and
|
| 89 |
+
allow the maintainers to devote more time to the projects, `please
|
| 90 |
+
donate today`_.
|
| 91 |
+
|
| 92 |
+
.. _please donate today: https://palletsprojects.com/donate
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
Links
|
| 96 |
+
-----
|
| 97 |
+
|
| 98 |
+
- Documentation: https://click.palletsprojects.com/
|
| 99 |
+
- Changes: https://click.palletsprojects.com/changes/
|
| 100 |
+
- PyPI Releases: https://pypi.org/project/click/
|
| 101 |
+
- Source Code: https://github.com/pallets/click
|
| 102 |
+
- Issue Tracker: https://github.com/pallets/click/issues
|
| 103 |
+
- Chat: https://discord.gg/pallets
|
parrot/lib/python3.10/site-packages/click-8.1.7.dist-info/RECORD
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
click-8.1.7.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
| 2 |
+
click-8.1.7.dist-info/LICENSE.rst,sha256=morRBqOU6FO_4h9C9OctWSgZoigF2ZG18ydQKSkrZY0,1475
|
| 3 |
+
click-8.1.7.dist-info/METADATA,sha256=qIMevCxGA9yEmJOM_4WHuUJCwWpsIEVbCPOhs45YPN4,3014
|
| 4 |
+
click-8.1.7.dist-info/RECORD,,
|
| 5 |
+
click-8.1.7.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 6 |
+
click-8.1.7.dist-info/WHEEL,sha256=5sUXSg9e4bi7lTLOHcm6QEYwO5TIF1TNbTSVFVjcJcc,92
|
| 7 |
+
click-8.1.7.dist-info/top_level.txt,sha256=J1ZQogalYS4pphY_lPECoNMfw0HzTSrZglC4Yfwo4xA,6
|
| 8 |
+
click/__init__.py,sha256=YDDbjm406dTOA0V8bTtdGnhN7zj5j-_dFRewZF_pLvw,3138
|
| 9 |
+
click/__pycache__/__init__.cpython-310.pyc,,
|
| 10 |
+
click/__pycache__/_compat.cpython-310.pyc,,
|
| 11 |
+
click/__pycache__/_termui_impl.cpython-310.pyc,,
|
| 12 |
+
click/__pycache__/_textwrap.cpython-310.pyc,,
|
| 13 |
+
click/__pycache__/_winconsole.cpython-310.pyc,,
|
| 14 |
+
click/__pycache__/core.cpython-310.pyc,,
|
| 15 |
+
click/__pycache__/decorators.cpython-310.pyc,,
|
| 16 |
+
click/__pycache__/exceptions.cpython-310.pyc,,
|
| 17 |
+
click/__pycache__/formatting.cpython-310.pyc,,
|
| 18 |
+
click/__pycache__/globals.cpython-310.pyc,,
|
| 19 |
+
click/__pycache__/parser.cpython-310.pyc,,
|
| 20 |
+
click/__pycache__/shell_completion.cpython-310.pyc,,
|
| 21 |
+
click/__pycache__/termui.cpython-310.pyc,,
|
| 22 |
+
click/__pycache__/testing.cpython-310.pyc,,
|
| 23 |
+
click/__pycache__/types.cpython-310.pyc,,
|
| 24 |
+
click/__pycache__/utils.cpython-310.pyc,,
|
| 25 |
+
click/_compat.py,sha256=5318agQpbt4kroKsbqDOYpTSWzL_YCZVUQiTT04yXmc,18744
|
| 26 |
+
click/_termui_impl.py,sha256=3dFYv4445Nw-rFvZOTBMBPYwB1bxnmNk9Du6Dm_oBSU,24069
|
| 27 |
+
click/_textwrap.py,sha256=10fQ64OcBUMuK7mFvh8363_uoOxPlRItZBmKzRJDgoY,1353
|
| 28 |
+
click/_winconsole.py,sha256=5ju3jQkcZD0W27WEMGqmEP4y_crUVzPCqsX_FYb7BO0,7860
|
| 29 |
+
click/core.py,sha256=j6oEWtGgGna8JarD6WxhXmNnxLnfRjwXglbBc-8jr7U,114086
|
| 30 |
+
click/decorators.py,sha256=-ZlbGYgV-oI8jr_oH4RpuL1PFS-5QmeuEAsLDAYgxtw,18719
|
| 31 |
+
click/exceptions.py,sha256=fyROO-47HWFDjt2qupo7A3J32VlpM-ovJnfowu92K3s,9273
|
| 32 |
+
click/formatting.py,sha256=Frf0-5W33-loyY_i9qrwXR8-STnW3m5gvyxLVUdyxyk,9706
|
| 33 |
+
click/globals.py,sha256=TP-qM88STzc7f127h35TD_v920FgfOD2EwzqA0oE8XU,1961
|
| 34 |
+
click/parser.py,sha256=LKyYQE9ZLj5KgIDXkrcTHQRXIggfoivX14_UVIn56YA,19067
|
| 35 |
+
click/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 36 |
+
click/shell_completion.py,sha256=Ty3VM_ts0sQhj6u7eFTiLwHPoTgcXTGEAUg2OpLqYKw,18460
|
| 37 |
+
click/termui.py,sha256=H7Q8FpmPelhJ2ovOhfCRhjMtCpNyjFXryAMLZODqsdc,28324
|
| 38 |
+
click/testing.py,sha256=1Qd4kS5bucn1hsNIRryd0WtTMuCpkA93grkWxT8POsU,16084
|
| 39 |
+
click/types.py,sha256=TZvz3hKvBztf-Hpa2enOmP4eznSPLzijjig5b_0XMxE,36391
|
| 40 |
+
click/utils.py,sha256=1476UduUNY6UePGU4m18uzVHLt1sKM2PP3yWsQhbItM,20298
|
parrot/lib/python3.10/site-packages/click-8.1.7.dist-info/REQUESTED
ADDED
|
File without changes
|
parrot/lib/python3.10/site-packages/click-8.1.7.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: bdist_wheel (0.41.1)
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: py3-none-any
|
| 5 |
+
|
parrot/lib/python3.10/site-packages/click-8.1.7.dist-info/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
click
|
parrot/lib/python3.10/site-packages/decorator.py
ADDED
|
@@ -0,0 +1,454 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ######################### LICENSE ############################ #
|
| 2 |
+
|
| 3 |
+
# Copyright (c) 2005-2018, Michele Simionato
|
| 4 |
+
# All rights reserved.
|
| 5 |
+
|
| 6 |
+
# Redistribution and use in source and binary forms, with or without
|
| 7 |
+
# modification, are permitted provided that the following conditions are
|
| 8 |
+
# met:
|
| 9 |
+
|
| 10 |
+
# Redistributions of source code must retain the above copyright
|
| 11 |
+
# notice, this list of conditions and the following disclaimer.
|
| 12 |
+
# Redistributions in bytecode form must reproduce the above copyright
|
| 13 |
+
# notice, this list of conditions and the following disclaimer in
|
| 14 |
+
# the documentation and/or other materials provided with the
|
| 15 |
+
# distribution.
|
| 16 |
+
|
| 17 |
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 18 |
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 19 |
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| 20 |
+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| 21 |
+
# HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
| 22 |
+
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
| 23 |
+
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
| 24 |
+
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 25 |
+
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
| 26 |
+
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
| 27 |
+
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
| 28 |
+
# DAMAGE.
|
| 29 |
+
|
| 30 |
+
"""
|
| 31 |
+
Decorator module, see http://pypi.python.org/pypi/decorator
|
| 32 |
+
for the documentation.
|
| 33 |
+
"""
|
| 34 |
+
from __future__ import print_function
|
| 35 |
+
|
| 36 |
+
import re
|
| 37 |
+
import sys
|
| 38 |
+
import inspect
|
| 39 |
+
import operator
|
| 40 |
+
import itertools
|
| 41 |
+
import collections
|
| 42 |
+
|
| 43 |
+
__version__ = '4.4.2'
|
| 44 |
+
|
| 45 |
+
if sys.version_info >= (3,):
|
| 46 |
+
from inspect import getfullargspec
|
| 47 |
+
|
| 48 |
+
def get_init(cls):
|
| 49 |
+
return cls.__init__
|
| 50 |
+
else:
|
| 51 |
+
FullArgSpec = collections.namedtuple(
|
| 52 |
+
'FullArgSpec', 'args varargs varkw defaults '
|
| 53 |
+
'kwonlyargs kwonlydefaults annotations')
|
| 54 |
+
|
| 55 |
+
def getfullargspec(f):
|
| 56 |
+
"A quick and dirty replacement for getfullargspec for Python 2.X"
|
| 57 |
+
return FullArgSpec._make(inspect.getargspec(f) + ([], None, {}))
|
| 58 |
+
|
| 59 |
+
def get_init(cls):
|
| 60 |
+
return cls.__init__.__func__
|
| 61 |
+
|
| 62 |
+
try:
|
| 63 |
+
iscoroutinefunction = inspect.iscoroutinefunction
|
| 64 |
+
except AttributeError:
|
| 65 |
+
# let's assume there are no coroutine functions in old Python
|
| 66 |
+
def iscoroutinefunction(f):
|
| 67 |
+
return False
|
| 68 |
+
try:
|
| 69 |
+
from inspect import isgeneratorfunction
|
| 70 |
+
except ImportError:
|
| 71 |
+
# assume no generator function in old Python versions
|
| 72 |
+
def isgeneratorfunction(caller):
|
| 73 |
+
return False
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
DEF = re.compile(r'\s*def\s*([_\w][_\w\d]*)\s*\(')
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
# basic functionality
|
| 80 |
+
class FunctionMaker(object):
|
| 81 |
+
"""
|
| 82 |
+
An object with the ability to create functions with a given signature.
|
| 83 |
+
It has attributes name, doc, module, signature, defaults, dict and
|
| 84 |
+
methods update and make.
|
| 85 |
+
"""
|
| 86 |
+
|
| 87 |
+
# Atomic get-and-increment provided by the GIL
|
| 88 |
+
_compile_count = itertools.count()
|
| 89 |
+
|
| 90 |
+
# make pylint happy
|
| 91 |
+
args = varargs = varkw = defaults = kwonlyargs = kwonlydefaults = ()
|
| 92 |
+
|
| 93 |
+
def __init__(self, func=None, name=None, signature=None,
|
| 94 |
+
defaults=None, doc=None, module=None, funcdict=None):
|
| 95 |
+
self.shortsignature = signature
|
| 96 |
+
if func:
|
| 97 |
+
# func can be a class or a callable, but not an instance method
|
| 98 |
+
self.name = func.__name__
|
| 99 |
+
if self.name == '<lambda>': # small hack for lambda functions
|
| 100 |
+
self.name = '_lambda_'
|
| 101 |
+
self.doc = func.__doc__
|
| 102 |
+
self.module = func.__module__
|
| 103 |
+
if inspect.isfunction(func):
|
| 104 |
+
argspec = getfullargspec(func)
|
| 105 |
+
self.annotations = getattr(func, '__annotations__', {})
|
| 106 |
+
for a in ('args', 'varargs', 'varkw', 'defaults', 'kwonlyargs',
|
| 107 |
+
'kwonlydefaults'):
|
| 108 |
+
setattr(self, a, getattr(argspec, a))
|
| 109 |
+
for i, arg in enumerate(self.args):
|
| 110 |
+
setattr(self, 'arg%d' % i, arg)
|
| 111 |
+
allargs = list(self.args)
|
| 112 |
+
allshortargs = list(self.args)
|
| 113 |
+
if self.varargs:
|
| 114 |
+
allargs.append('*' + self.varargs)
|
| 115 |
+
allshortargs.append('*' + self.varargs)
|
| 116 |
+
elif self.kwonlyargs:
|
| 117 |
+
allargs.append('*') # single star syntax
|
| 118 |
+
for a in self.kwonlyargs:
|
| 119 |
+
allargs.append('%s=None' % a)
|
| 120 |
+
allshortargs.append('%s=%s' % (a, a))
|
| 121 |
+
if self.varkw:
|
| 122 |
+
allargs.append('**' + self.varkw)
|
| 123 |
+
allshortargs.append('**' + self.varkw)
|
| 124 |
+
self.signature = ', '.join(allargs)
|
| 125 |
+
self.shortsignature = ', '.join(allshortargs)
|
| 126 |
+
self.dict = func.__dict__.copy()
|
| 127 |
+
# func=None happens when decorating a caller
|
| 128 |
+
if name:
|
| 129 |
+
self.name = name
|
| 130 |
+
if signature is not None:
|
| 131 |
+
self.signature = signature
|
| 132 |
+
if defaults:
|
| 133 |
+
self.defaults = defaults
|
| 134 |
+
if doc:
|
| 135 |
+
self.doc = doc
|
| 136 |
+
if module:
|
| 137 |
+
self.module = module
|
| 138 |
+
if funcdict:
|
| 139 |
+
self.dict = funcdict
|
| 140 |
+
# check existence required attributes
|
| 141 |
+
assert hasattr(self, 'name')
|
| 142 |
+
if not hasattr(self, 'signature'):
|
| 143 |
+
raise TypeError('You are decorating a non function: %s' % func)
|
| 144 |
+
|
| 145 |
+
def update(self, func, **kw):
|
| 146 |
+
"Update the signature of func with the data in self"
|
| 147 |
+
func.__name__ = self.name
|
| 148 |
+
func.__doc__ = getattr(self, 'doc', None)
|
| 149 |
+
func.__dict__ = getattr(self, 'dict', {})
|
| 150 |
+
func.__defaults__ = self.defaults
|
| 151 |
+
func.__kwdefaults__ = self.kwonlydefaults or None
|
| 152 |
+
func.__annotations__ = getattr(self, 'annotations', None)
|
| 153 |
+
try:
|
| 154 |
+
frame = sys._getframe(3)
|
| 155 |
+
except AttributeError: # for IronPython and similar implementations
|
| 156 |
+
callermodule = '?'
|
| 157 |
+
else:
|
| 158 |
+
callermodule = frame.f_globals.get('__name__', '?')
|
| 159 |
+
func.__module__ = getattr(self, 'module', callermodule)
|
| 160 |
+
func.__dict__.update(kw)
|
| 161 |
+
|
| 162 |
+
def make(self, src_templ, evaldict=None, addsource=False, **attrs):
|
| 163 |
+
"Make a new function from a given template and update the signature"
|
| 164 |
+
src = src_templ % vars(self) # expand name and signature
|
| 165 |
+
evaldict = evaldict or {}
|
| 166 |
+
mo = DEF.search(src)
|
| 167 |
+
if mo is None:
|
| 168 |
+
raise SyntaxError('not a valid function template\n%s' % src)
|
| 169 |
+
name = mo.group(1) # extract the function name
|
| 170 |
+
names = set([name] + [arg.strip(' *') for arg in
|
| 171 |
+
self.shortsignature.split(',')])
|
| 172 |
+
for n in names:
|
| 173 |
+
if n in ('_func_', '_call_'):
|
| 174 |
+
raise NameError('%s is overridden in\n%s' % (n, src))
|
| 175 |
+
|
| 176 |
+
if not src.endswith('\n'): # add a newline for old Pythons
|
| 177 |
+
src += '\n'
|
| 178 |
+
|
| 179 |
+
# Ensure each generated function has a unique filename for profilers
|
| 180 |
+
# (such as cProfile) that depend on the tuple of (<filename>,
|
| 181 |
+
# <definition line>, <function name>) being unique.
|
| 182 |
+
filename = '<decorator-gen-%d>' % next(self._compile_count)
|
| 183 |
+
try:
|
| 184 |
+
code = compile(src, filename, 'single')
|
| 185 |
+
exec(code, evaldict)
|
| 186 |
+
except Exception:
|
| 187 |
+
print('Error in generated code:', file=sys.stderr)
|
| 188 |
+
print(src, file=sys.stderr)
|
| 189 |
+
raise
|
| 190 |
+
func = evaldict[name]
|
| 191 |
+
if addsource:
|
| 192 |
+
attrs['__source__'] = src
|
| 193 |
+
self.update(func, **attrs)
|
| 194 |
+
return func
|
| 195 |
+
|
| 196 |
+
@classmethod
|
| 197 |
+
def create(cls, obj, body, evaldict, defaults=None,
|
| 198 |
+
doc=None, module=None, addsource=True, **attrs):
|
| 199 |
+
"""
|
| 200 |
+
Create a function from the strings name, signature and body.
|
| 201 |
+
evaldict is the evaluation dictionary. If addsource is true an
|
| 202 |
+
attribute __source__ is added to the result. The attributes attrs
|
| 203 |
+
are added, if any.
|
| 204 |
+
"""
|
| 205 |
+
if isinstance(obj, str): # "name(signature)"
|
| 206 |
+
name, rest = obj.strip().split('(', 1)
|
| 207 |
+
signature = rest[:-1] # strip a right parens
|
| 208 |
+
func = None
|
| 209 |
+
else: # a function
|
| 210 |
+
name = None
|
| 211 |
+
signature = None
|
| 212 |
+
func = obj
|
| 213 |
+
self = cls(func, name, signature, defaults, doc, module)
|
| 214 |
+
ibody = '\n'.join(' ' + line for line in body.splitlines())
|
| 215 |
+
caller = evaldict.get('_call_') # when called from `decorate`
|
| 216 |
+
if caller and iscoroutinefunction(caller):
|
| 217 |
+
body = ('async def %(name)s(%(signature)s):\n' + ibody).replace(
|
| 218 |
+
'return', 'return await')
|
| 219 |
+
else:
|
| 220 |
+
body = 'def %(name)s(%(signature)s):\n' + ibody
|
| 221 |
+
return self.make(body, evaldict, addsource, **attrs)
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
def decorate(func, caller, extras=()):
|
| 225 |
+
"""
|
| 226 |
+
decorate(func, caller) decorates a function using a caller.
|
| 227 |
+
If the caller is a generator function, the resulting function
|
| 228 |
+
will be a generator function.
|
| 229 |
+
"""
|
| 230 |
+
evaldict = dict(_call_=caller, _func_=func)
|
| 231 |
+
es = ''
|
| 232 |
+
for i, extra in enumerate(extras):
|
| 233 |
+
ex = '_e%d_' % i
|
| 234 |
+
evaldict[ex] = extra
|
| 235 |
+
es += ex + ', '
|
| 236 |
+
|
| 237 |
+
if '3.5' <= sys.version < '3.6':
|
| 238 |
+
# with Python 3.5 isgeneratorfunction returns True for all coroutines
|
| 239 |
+
# however we know that it is NOT possible to have a generator
|
| 240 |
+
# coroutine in python 3.5: PEP525 was not there yet
|
| 241 |
+
generatorcaller = isgeneratorfunction(
|
| 242 |
+
caller) and not iscoroutinefunction(caller)
|
| 243 |
+
else:
|
| 244 |
+
generatorcaller = isgeneratorfunction(caller)
|
| 245 |
+
if generatorcaller:
|
| 246 |
+
fun = FunctionMaker.create(
|
| 247 |
+
func, "for res in _call_(_func_, %s%%(shortsignature)s):\n"
|
| 248 |
+
" yield res" % es, evaldict, __wrapped__=func)
|
| 249 |
+
else:
|
| 250 |
+
fun = FunctionMaker.create(
|
| 251 |
+
func, "return _call_(_func_, %s%%(shortsignature)s)" % es,
|
| 252 |
+
evaldict, __wrapped__=func)
|
| 253 |
+
if hasattr(func, '__qualname__'):
|
| 254 |
+
fun.__qualname__ = func.__qualname__
|
| 255 |
+
return fun
|
| 256 |
+
|
| 257 |
+
|
| 258 |
+
def decorator(caller, _func=None):
|
| 259 |
+
"""decorator(caller) converts a caller function into a decorator"""
|
| 260 |
+
if _func is not None: # return a decorated function
|
| 261 |
+
# this is obsolete behavior; you should use decorate instead
|
| 262 |
+
return decorate(_func, caller)
|
| 263 |
+
# else return a decorator function
|
| 264 |
+
defaultargs, defaults = '', ()
|
| 265 |
+
if inspect.isclass(caller):
|
| 266 |
+
name = caller.__name__.lower()
|
| 267 |
+
doc = 'decorator(%s) converts functions/generators into ' \
|
| 268 |
+
'factories of %s objects' % (caller.__name__, caller.__name__)
|
| 269 |
+
elif inspect.isfunction(caller):
|
| 270 |
+
if caller.__name__ == '<lambda>':
|
| 271 |
+
name = '_lambda_'
|
| 272 |
+
else:
|
| 273 |
+
name = caller.__name__
|
| 274 |
+
doc = caller.__doc__
|
| 275 |
+
nargs = caller.__code__.co_argcount
|
| 276 |
+
ndefs = len(caller.__defaults__ or ())
|
| 277 |
+
defaultargs = ', '.join(caller.__code__.co_varnames[nargs-ndefs:nargs])
|
| 278 |
+
if defaultargs:
|
| 279 |
+
defaultargs += ','
|
| 280 |
+
defaults = caller.__defaults__
|
| 281 |
+
else: # assume caller is an object with a __call__ method
|
| 282 |
+
name = caller.__class__.__name__.lower()
|
| 283 |
+
doc = caller.__call__.__doc__
|
| 284 |
+
evaldict = dict(_call=caller, _decorate_=decorate)
|
| 285 |
+
dec = FunctionMaker.create(
|
| 286 |
+
'%s(func, %s)' % (name, defaultargs),
|
| 287 |
+
'if func is None: return lambda func: _decorate_(func, _call, (%s))\n'
|
| 288 |
+
'return _decorate_(func, _call, (%s))' % (defaultargs, defaultargs),
|
| 289 |
+
evaldict, doc=doc, module=caller.__module__, __wrapped__=caller)
|
| 290 |
+
if defaults:
|
| 291 |
+
dec.__defaults__ = (None,) + defaults
|
| 292 |
+
return dec
|
| 293 |
+
|
| 294 |
+
|
| 295 |
+
# ####################### contextmanager ####################### #
|
| 296 |
+
|
| 297 |
+
try: # Python >= 3.2
|
| 298 |
+
from contextlib import _GeneratorContextManager
|
| 299 |
+
except ImportError: # Python >= 2.5
|
| 300 |
+
from contextlib import GeneratorContextManager as _GeneratorContextManager
|
| 301 |
+
|
| 302 |
+
|
| 303 |
+
class ContextManager(_GeneratorContextManager):
|
| 304 |
+
def __call__(self, func):
|
| 305 |
+
"""Context manager decorator"""
|
| 306 |
+
return FunctionMaker.create(
|
| 307 |
+
func, "with _self_: return _func_(%(shortsignature)s)",
|
| 308 |
+
dict(_self_=self, _func_=func), __wrapped__=func)
|
| 309 |
+
|
| 310 |
+
|
| 311 |
+
init = getfullargspec(_GeneratorContextManager.__init__)
|
| 312 |
+
n_args = len(init.args)
|
| 313 |
+
if n_args == 2 and not init.varargs: # (self, genobj) Python 2.7
|
| 314 |
+
def __init__(self, g, *a, **k):
|
| 315 |
+
return _GeneratorContextManager.__init__(self, g(*a, **k))
|
| 316 |
+
ContextManager.__init__ = __init__
|
| 317 |
+
elif n_args == 2 and init.varargs: # (self, gen, *a, **k) Python 3.4
|
| 318 |
+
pass
|
| 319 |
+
elif n_args == 4: # (self, gen, args, kwds) Python 3.5
|
| 320 |
+
def __init__(self, g, *a, **k):
|
| 321 |
+
return _GeneratorContextManager.__init__(self, g, a, k)
|
| 322 |
+
ContextManager.__init__ = __init__
|
| 323 |
+
|
| 324 |
+
_contextmanager = decorator(ContextManager)
|
| 325 |
+
|
| 326 |
+
|
| 327 |
+
def contextmanager(func):
|
| 328 |
+
# Enable Pylint config: contextmanager-decorators=decorator.contextmanager
|
| 329 |
+
return _contextmanager(func)
|
| 330 |
+
|
| 331 |
+
|
| 332 |
+
# ############################ dispatch_on ############################ #
|
| 333 |
+
|
| 334 |
+
def append(a, vancestors):
|
| 335 |
+
"""
|
| 336 |
+
Append ``a`` to the list of the virtual ancestors, unless it is already
|
| 337 |
+
included.
|
| 338 |
+
"""
|
| 339 |
+
add = True
|
| 340 |
+
for j, va in enumerate(vancestors):
|
| 341 |
+
if issubclass(va, a):
|
| 342 |
+
add = False
|
| 343 |
+
break
|
| 344 |
+
if issubclass(a, va):
|
| 345 |
+
vancestors[j] = a
|
| 346 |
+
add = False
|
| 347 |
+
if add:
|
| 348 |
+
vancestors.append(a)
|
| 349 |
+
|
| 350 |
+
|
| 351 |
+
# inspired from simplegeneric by P.J. Eby and functools.singledispatch
|
| 352 |
+
def dispatch_on(*dispatch_args):
|
| 353 |
+
"""
|
| 354 |
+
Factory of decorators turning a function into a generic function
|
| 355 |
+
dispatching on the given arguments.
|
| 356 |
+
"""
|
| 357 |
+
assert dispatch_args, 'No dispatch args passed'
|
| 358 |
+
dispatch_str = '(%s,)' % ', '.join(dispatch_args)
|
| 359 |
+
|
| 360 |
+
def check(arguments, wrong=operator.ne, msg=''):
|
| 361 |
+
"""Make sure one passes the expected number of arguments"""
|
| 362 |
+
if wrong(len(arguments), len(dispatch_args)):
|
| 363 |
+
raise TypeError('Expected %d arguments, got %d%s' %
|
| 364 |
+
(len(dispatch_args), len(arguments), msg))
|
| 365 |
+
|
| 366 |
+
def gen_func_dec(func):
|
| 367 |
+
"""Decorator turning a function into a generic function"""
|
| 368 |
+
|
| 369 |
+
# first check the dispatch arguments
|
| 370 |
+
argset = set(getfullargspec(func).args)
|
| 371 |
+
if not set(dispatch_args) <= argset:
|
| 372 |
+
raise NameError('Unknown dispatch arguments %s' % dispatch_str)
|
| 373 |
+
|
| 374 |
+
typemap = {}
|
| 375 |
+
|
| 376 |
+
def vancestors(*types):
|
| 377 |
+
"""
|
| 378 |
+
Get a list of sets of virtual ancestors for the given types
|
| 379 |
+
"""
|
| 380 |
+
check(types)
|
| 381 |
+
ras = [[] for _ in range(len(dispatch_args))]
|
| 382 |
+
for types_ in typemap:
|
| 383 |
+
for t, type_, ra in zip(types, types_, ras):
|
| 384 |
+
if issubclass(t, type_) and type_ not in t.mro():
|
| 385 |
+
append(type_, ra)
|
| 386 |
+
return [set(ra) for ra in ras]
|
| 387 |
+
|
| 388 |
+
def ancestors(*types):
|
| 389 |
+
"""
|
| 390 |
+
Get a list of virtual MROs, one for each type
|
| 391 |
+
"""
|
| 392 |
+
check(types)
|
| 393 |
+
lists = []
|
| 394 |
+
for t, vas in zip(types, vancestors(*types)):
|
| 395 |
+
n_vas = len(vas)
|
| 396 |
+
if n_vas > 1:
|
| 397 |
+
raise RuntimeError(
|
| 398 |
+
'Ambiguous dispatch for %s: %s' % (t, vas))
|
| 399 |
+
elif n_vas == 1:
|
| 400 |
+
va, = vas
|
| 401 |
+
mro = type('t', (t, va), {}).mro()[1:]
|
| 402 |
+
else:
|
| 403 |
+
mro = t.mro()
|
| 404 |
+
lists.append(mro[:-1]) # discard t and object
|
| 405 |
+
return lists
|
| 406 |
+
|
| 407 |
+
def register(*types):
|
| 408 |
+
"""
|
| 409 |
+
Decorator to register an implementation for the given types
|
| 410 |
+
"""
|
| 411 |
+
check(types)
|
| 412 |
+
|
| 413 |
+
def dec(f):
|
| 414 |
+
check(getfullargspec(f).args, operator.lt, ' in ' + f.__name__)
|
| 415 |
+
typemap[types] = f
|
| 416 |
+
return f
|
| 417 |
+
return dec
|
| 418 |
+
|
| 419 |
+
def dispatch_info(*types):
|
| 420 |
+
"""
|
| 421 |
+
An utility to introspect the dispatch algorithm
|
| 422 |
+
"""
|
| 423 |
+
check(types)
|
| 424 |
+
lst = []
|
| 425 |
+
for anc in itertools.product(*ancestors(*types)):
|
| 426 |
+
lst.append(tuple(a.__name__ for a in anc))
|
| 427 |
+
return lst
|
| 428 |
+
|
| 429 |
+
def _dispatch(dispatch_args, *args, **kw):
|
| 430 |
+
types = tuple(type(arg) for arg in dispatch_args)
|
| 431 |
+
try: # fast path
|
| 432 |
+
f = typemap[types]
|
| 433 |
+
except KeyError:
|
| 434 |
+
pass
|
| 435 |
+
else:
|
| 436 |
+
return f(*args, **kw)
|
| 437 |
+
combinations = itertools.product(*ancestors(*types))
|
| 438 |
+
next(combinations) # the first one has been already tried
|
| 439 |
+
for types_ in combinations:
|
| 440 |
+
f = typemap.get(types_)
|
| 441 |
+
if f is not None:
|
| 442 |
+
return f(*args, **kw)
|
| 443 |
+
|
| 444 |
+
# else call the default implementation
|
| 445 |
+
return func(*args, **kw)
|
| 446 |
+
|
| 447 |
+
return FunctionMaker.create(
|
| 448 |
+
func, 'return _f_(%s, %%(shortsignature)s)' % dispatch_str,
|
| 449 |
+
dict(_f_=_dispatch), register=register, default=func,
|
| 450 |
+
typemap=typemap, vancestors=vancestors, ancestors=ancestors,
|
| 451 |
+
dispatch_info=dispatch_info, __wrapped__=func)
|
| 452 |
+
|
| 453 |
+
gen_func_dec.__name__ = 'dispatch_on' + dispatch_str
|
| 454 |
+
return gen_func_dec
|
parrot/lib/python3.10/site-packages/filelock-3.16.1.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pip
|
parrot/lib/python3.10/site-packages/filelock-3.16.1.dist-info/METADATA
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.3
|
| 2 |
+
Name: filelock
|
| 3 |
+
Version: 3.16.1
|
| 4 |
+
Summary: A platform independent file lock.
|
| 5 |
+
Project-URL: Documentation, https://py-filelock.readthedocs.io
|
| 6 |
+
Project-URL: Homepage, https://github.com/tox-dev/py-filelock
|
| 7 |
+
Project-URL: Source, https://github.com/tox-dev/py-filelock
|
| 8 |
+
Project-URL: Tracker, https://github.com/tox-dev/py-filelock/issues
|
| 9 |
+
Maintainer-email: Bernát Gábor <gaborjbernat@gmail.com>
|
| 10 |
+
License-Expression: Unlicense
|
| 11 |
+
License-File: LICENSE
|
| 12 |
+
Keywords: application,cache,directory,log,user
|
| 13 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 14 |
+
Classifier: Intended Audience :: Developers
|
| 15 |
+
Classifier: License :: OSI Approved :: The Unlicense (Unlicense)
|
| 16 |
+
Classifier: Operating System :: OS Independent
|
| 17 |
+
Classifier: Programming Language :: Python
|
| 18 |
+
Classifier: Programming Language :: Python :: 3 :: Only
|
| 19 |
+
Classifier: Programming Language :: Python :: 3.8
|
| 20 |
+
Classifier: Programming Language :: Python :: 3.9
|
| 21 |
+
Classifier: Programming Language :: Python :: 3.10
|
| 22 |
+
Classifier: Programming Language :: Python :: 3.11
|
| 23 |
+
Classifier: Programming Language :: Python :: 3.12
|
| 24 |
+
Classifier: Programming Language :: Python :: 3.13
|
| 25 |
+
Classifier: Topic :: Internet
|
| 26 |
+
Classifier: Topic :: Software Development :: Libraries
|
| 27 |
+
Classifier: Topic :: System
|
| 28 |
+
Requires-Python: >=3.8
|
| 29 |
+
Provides-Extra: docs
|
| 30 |
+
Requires-Dist: furo>=2024.8.6; extra == 'docs'
|
| 31 |
+
Requires-Dist: sphinx-autodoc-typehints>=2.4.1; extra == 'docs'
|
| 32 |
+
Requires-Dist: sphinx>=8.0.2; extra == 'docs'
|
| 33 |
+
Provides-Extra: testing
|
| 34 |
+
Requires-Dist: covdefaults>=2.3; extra == 'testing'
|
| 35 |
+
Requires-Dist: coverage>=7.6.1; extra == 'testing'
|
| 36 |
+
Requires-Dist: diff-cover>=9.2; extra == 'testing'
|
| 37 |
+
Requires-Dist: pytest-asyncio>=0.24; extra == 'testing'
|
| 38 |
+
Requires-Dist: pytest-cov>=5; extra == 'testing'
|
| 39 |
+
Requires-Dist: pytest-mock>=3.14; extra == 'testing'
|
| 40 |
+
Requires-Dist: pytest-timeout>=2.3.1; extra == 'testing'
|
| 41 |
+
Requires-Dist: pytest>=8.3.3; extra == 'testing'
|
| 42 |
+
Requires-Dist: virtualenv>=20.26.4; extra == 'testing'
|
| 43 |
+
Provides-Extra: typing
|
| 44 |
+
Requires-Dist: typing-extensions>=4.12.2; (python_version < '3.11') and extra == 'typing'
|
| 45 |
+
Description-Content-Type: text/markdown
|
| 46 |
+
|
| 47 |
+
# filelock
|
| 48 |
+
|
| 49 |
+
[](https://pypi.org/project/filelock/)
|
| 50 |
+
[](https://pypi.org/project/filelock/)
|
| 52 |
+
[](https://py-filelock.readthedocs.io/en/latest/?badge=latest)
|
| 54 |
+
[](https://github.com/psf/black)
|
| 56 |
+
[](https://pepy.tech/project/filelock)
|
| 57 |
+
[](https://github.com/tox-dev/py-filelock/actions/workflows/check.yml)
|
| 58 |
+
|
| 59 |
+
For more information checkout the [official documentation](https://py-filelock.readthedocs.io/en/latest/index.html).
|
parrot/lib/python3.10/site-packages/filelock-3.16.1.dist-info/REQUESTED
ADDED
|
File without changes
|
parrot/lib/python3.10/site-packages/frozenlist-1.4.1.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pip
|
parrot/lib/python3.10/site-packages/frozenlist-1.4.1.dist-info/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Apache License
|
| 2 |
+
Version 2.0, January 2004
|
| 3 |
+
http://www.apache.org/licenses/
|
| 4 |
+
|
| 5 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 6 |
+
|
| 7 |
+
1. Definitions.
|
| 8 |
+
|
| 9 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 10 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 11 |
+
|
| 12 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 13 |
+
the copyright owner that is granting the License.
|
| 14 |
+
|
| 15 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 16 |
+
other entities that control, are controlled by, or are under common
|
| 17 |
+
control with that entity. For the purposes of this definition,
|
| 18 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 19 |
+
direction or management of such entity, whether by contract or
|
| 20 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 21 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 22 |
+
|
| 23 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 24 |
+
exercising permissions granted by this License.
|
| 25 |
+
|
| 26 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 27 |
+
including but not limited to software source code, documentation
|
| 28 |
+
source, and configuration files.
|
| 29 |
+
|
| 30 |
+
"Object" form shall mean any form resulting from mechanical
|
| 31 |
+
transformation or translation of a Source form, including but
|
| 32 |
+
not limited to compiled object code, generated documentation,
|
| 33 |
+
and conversions to other media types.
|
| 34 |
+
|
| 35 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 36 |
+
Object form, made available under the License, as indicated by a
|
| 37 |
+
copyright notice that is included in or attached to the work
|
| 38 |
+
(an example is provided in the Appendix below).
|
| 39 |
+
|
| 40 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 41 |
+
form, that is based on (or derived from) the Work and for which the
|
| 42 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 43 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 44 |
+
of this License, Derivative Works shall not include works that remain
|
| 45 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 46 |
+
the Work and Derivative Works thereof.
|
| 47 |
+
|
| 48 |
+
"Contribution" shall mean any work of authorship, including
|
| 49 |
+
the original version of the Work and any modifications or additions
|
| 50 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 51 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 52 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 53 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 54 |
+
means any form of electronic, verbal, or written communication sent
|
| 55 |
+
to the Licensor or its representatives, including but not limited to
|
| 56 |
+
communication on electronic mailing lists, source code control systems,
|
| 57 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 58 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 59 |
+
excluding communication that is conspicuously marked or otherwise
|
| 60 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 61 |
+
|
| 62 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 63 |
+
on behalf of whom a Contribution has been received by Licensor and
|
| 64 |
+
subsequently incorporated within the Work.
|
| 65 |
+
|
| 66 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 67 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 68 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 69 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 70 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 71 |
+
Work and such Derivative Works in Source or Object form.
|
| 72 |
+
|
| 73 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 74 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 75 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 76 |
+
(except as stated in this section) patent license to make, have made,
|
| 77 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 78 |
+
where such license applies only to those patent claims licensable
|
| 79 |
+
by such Contributor that are necessarily infringed by their
|
| 80 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 81 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 82 |
+
institute patent litigation against any entity (including a
|
| 83 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 84 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 85 |
+
or contributory patent infringement, then any patent licenses
|
| 86 |
+
granted to You under this License for that Work shall terminate
|
| 87 |
+
as of the date such litigation is filed.
|
| 88 |
+
|
| 89 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 90 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 91 |
+
modifications, and in Source or Object form, provided that You
|
| 92 |
+
meet the following conditions:
|
| 93 |
+
|
| 94 |
+
(a) You must give any other recipients of the Work or
|
| 95 |
+
Derivative Works a copy of this License; and
|
| 96 |
+
|
| 97 |
+
(b) You must cause any modified files to carry prominent notices
|
| 98 |
+
stating that You changed the files; and
|
| 99 |
+
|
| 100 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 101 |
+
that You distribute, all copyright, patent, trademark, and
|
| 102 |
+
attribution notices from the Source form of the Work,
|
| 103 |
+
excluding those notices that do not pertain to any part of
|
| 104 |
+
the Derivative Works; and
|
| 105 |
+
|
| 106 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 107 |
+
distribution, then any Derivative Works that You distribute must
|
| 108 |
+
include a readable copy of the attribution notices contained
|
| 109 |
+
within such NOTICE file, excluding those notices that do not
|
| 110 |
+
pertain to any part of the Derivative Works, in at least one
|
| 111 |
+
of the following places: within a NOTICE text file distributed
|
| 112 |
+
as part of the Derivative Works; within the Source form or
|
| 113 |
+
documentation, if provided along with the Derivative Works; or,
|
| 114 |
+
within a display generated by the Derivative Works, if and
|
| 115 |
+
wherever such third-party notices normally appear. The contents
|
| 116 |
+
of the NOTICE file are for informational purposes only and
|
| 117 |
+
do not modify the License. You may add Your own attribution
|
| 118 |
+
notices within Derivative Works that You distribute, alongside
|
| 119 |
+
or as an addendum to the NOTICE text from the Work, provided
|
| 120 |
+
that such additional attribution notices cannot be construed
|
| 121 |
+
as modifying the License.
|
| 122 |
+
|
| 123 |
+
You may add Your own copyright statement to Your modifications and
|
| 124 |
+
may provide additional or different license terms and conditions
|
| 125 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 126 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 127 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 128 |
+
the conditions stated in this License.
|
| 129 |
+
|
| 130 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 131 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 132 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 133 |
+
this License, without any additional terms or conditions.
|
| 134 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 135 |
+
the terms of any separate license agreement you may have executed
|
| 136 |
+
with Licensor regarding such Contributions.
|
| 137 |
+
|
| 138 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 139 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 140 |
+
except as required for reasonable and customary use in describing the
|
| 141 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 142 |
+
|
| 143 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 144 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 145 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 146 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 147 |
+
implied, including, without limitation, any warranties or conditions
|
| 148 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 149 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 150 |
+
appropriateness of using or redistributing the Work and assume any
|
| 151 |
+
risks associated with Your exercise of permissions under this License.
|
| 152 |
+
|
| 153 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 154 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 155 |
+
unless required by applicable law (such as deliberate and grossly
|
| 156 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 157 |
+
liable to You for damages, including any direct, indirect, special,
|
| 158 |
+
incidental, or consequential damages of any character arising as a
|
| 159 |
+
result of this License or out of the use or inability to use the
|
| 160 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 161 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 162 |
+
other commercial damages or losses), even if such Contributor
|
| 163 |
+
has been advised of the possibility of such damages.
|
| 164 |
+
|
| 165 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 166 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
| 167 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 168 |
+
or other liability obligations and/or rights consistent with this
|
| 169 |
+
License. However, in accepting such obligations, You may act only
|
| 170 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 171 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 172 |
+
defend, and hold each Contributor harmless for any liability
|
| 173 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 174 |
+
of your accepting any such warranty or additional liability.
|
| 175 |
+
|
| 176 |
+
END OF TERMS AND CONDITIONS
|
| 177 |
+
|
| 178 |
+
APPENDIX: How to apply the Apache License to your work.
|
| 179 |
+
|
| 180 |
+
To apply the Apache License to your work, attach the following
|
| 181 |
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
| 182 |
+
replaced with your own identifying information. (Don't include
|
| 183 |
+
the brackets!) The text should be enclosed in the appropriate
|
| 184 |
+
comment syntax for the file format. We also recommend that a
|
| 185 |
+
file or class name and description of purpose be included on the
|
| 186 |
+
same "printed page" as the copyright notice for easier
|
| 187 |
+
identification within third-party archives.
|
| 188 |
+
|
| 189 |
+
Copyright 2013-2019 Nikolay Kim and Andrew Svetlov
|
| 190 |
+
|
| 191 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 192 |
+
you may not use this file except in compliance with the License.
|
| 193 |
+
You may obtain a copy of the License at
|
| 194 |
+
|
| 195 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 196 |
+
|
| 197 |
+
Unless required by applicable law or agreed to in writing, software
|
| 198 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 199 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 200 |
+
See the License for the specific language governing permissions and
|
| 201 |
+
limitations under the License.
|
parrot/lib/python3.10/site-packages/frozenlist-1.4.1.dist-info/METADATA
ADDED
|
@@ -0,0 +1,420 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.1
|
| 2 |
+
Name: frozenlist
|
| 3 |
+
Version: 1.4.1
|
| 4 |
+
Summary: A list-like structure which implements collections.abc.MutableSequence
|
| 5 |
+
Home-page: https://github.com/aio-libs/frozenlist
|
| 6 |
+
Maintainer: aiohttp team <team@aiohttp.org>
|
| 7 |
+
Maintainer-email: team@aiohttp.org
|
| 8 |
+
License: Apache 2
|
| 9 |
+
Project-URL: Chat: Matrix, https://matrix.to/#/#aio-libs:matrix.org
|
| 10 |
+
Project-URL: Chat: Matrix Space, https://matrix.to/#/#aio-libs-space:matrix.org
|
| 11 |
+
Project-URL: CI: Github Actions, https://github.com/aio-libs/frozenlist/actions
|
| 12 |
+
Project-URL: Code of Conduct, https://github.com/aio-libs/.github/blob/master/CODE_OF_CONDUCT.md
|
| 13 |
+
Project-URL: Coverage: codecov, https://codecov.io/github/aio-libs/frozenlist
|
| 14 |
+
Project-URL: Docs: Changelog, https://github.com/aio-libs/frozenlist/blob/master/CHANGES.rst#changelog
|
| 15 |
+
Project-URL: Docs: RTD, https://frozenlist.aio-libs.org
|
| 16 |
+
Project-URL: GitHub: issues, https://github.com/aio-libs/frozenlist/issues
|
| 17 |
+
Project-URL: GitHub: repo, https://github.com/aio-libs/frozenlist
|
| 18 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 19 |
+
Classifier: Intended Audience :: Developers
|
| 20 |
+
Classifier: License :: OSI Approved :: Apache Software License
|
| 21 |
+
Classifier: Operating System :: POSIX
|
| 22 |
+
Classifier: Operating System :: MacOS :: MacOS X
|
| 23 |
+
Classifier: Operating System :: Microsoft :: Windows
|
| 24 |
+
Classifier: Programming Language :: Cython
|
| 25 |
+
Classifier: Programming Language :: Python
|
| 26 |
+
Classifier: Programming Language :: Python :: 3
|
| 27 |
+
Classifier: Programming Language :: Python :: 3.8
|
| 28 |
+
Classifier: Programming Language :: Python :: 3.9
|
| 29 |
+
Classifier: Programming Language :: Python :: 3.10
|
| 30 |
+
Classifier: Programming Language :: Python :: 3.11
|
| 31 |
+
Classifier: Programming Language :: Python :: 3.12
|
| 32 |
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
| 33 |
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
| 34 |
+
Requires-Python: >=3.8
|
| 35 |
+
Description-Content-Type: text/x-rst
|
| 36 |
+
License-File: LICENSE
|
| 37 |
+
|
| 38 |
+
frozenlist
|
| 39 |
+
==========
|
| 40 |
+
|
| 41 |
+
.. image:: https://github.com/aio-libs/frozenlist/workflows/CI/badge.svg
|
| 42 |
+
:target: https://github.com/aio-libs/frozenlist/actions
|
| 43 |
+
:alt: GitHub status for master branch
|
| 44 |
+
|
| 45 |
+
.. image:: https://codecov.io/gh/aio-libs/frozenlist/branch/master/graph/badge.svg
|
| 46 |
+
:target: https://codecov.io/gh/aio-libs/frozenlist
|
| 47 |
+
:alt: codecov.io status for master branch
|
| 48 |
+
|
| 49 |
+
.. image:: https://img.shields.io/pypi/v/frozenlist.svg?logo=Python&logoColor=white
|
| 50 |
+
:target: https://pypi.org/project/frozenlist
|
| 51 |
+
:alt: frozenlist @ PyPI
|
| 52 |
+
|
| 53 |
+
.. image:: https://readthedocs.org/projects/frozenlist/badge/?version=latest
|
| 54 |
+
:target: https://frozenlist.aio-libs.org
|
| 55 |
+
:alt: Read The Docs build status badge
|
| 56 |
+
|
| 57 |
+
.. image:: https://img.shields.io/matrix/aio-libs:matrix.org?label=Discuss%20on%20Matrix%20at%20%23aio-libs%3Amatrix.org&logo=matrix&server_fqdn=matrix.org&style=flat
|
| 58 |
+
:target: https://matrix.to/#/%23aio-libs:matrix.org
|
| 59 |
+
:alt: Matrix Room — #aio-libs:matrix.org
|
| 60 |
+
|
| 61 |
+
.. image:: https://img.shields.io/matrix/aio-libs-space:matrix.org?label=Discuss%20on%20Matrix%20at%20%23aio-libs-space%3Amatrix.org&logo=matrix&server_fqdn=matrix.org&style=flat
|
| 62 |
+
:target: https://matrix.to/#/%23aio-libs-space:matrix.org
|
| 63 |
+
:alt: Matrix Space — #aio-libs-space:matrix.org
|
| 64 |
+
|
| 65 |
+
Introduction
|
| 66 |
+
------------
|
| 67 |
+
|
| 68 |
+
``frozenlist.FrozenList`` is a list-like structure which implements
|
| 69 |
+
``collections.abc.MutableSequence``. The list is *mutable* until ``FrozenList.freeze``
|
| 70 |
+
is called, after which list modifications raise ``RuntimeError``:
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
>>> from frozenlist import FrozenList
|
| 74 |
+
>>> fl = FrozenList([17, 42])
|
| 75 |
+
>>> fl.append('spam')
|
| 76 |
+
>>> fl.append('Vikings')
|
| 77 |
+
>>> fl
|
| 78 |
+
<FrozenList(frozen=False, [17, 42, 'spam', 'Vikings'])>
|
| 79 |
+
>>> fl.freeze()
|
| 80 |
+
>>> fl
|
| 81 |
+
<FrozenList(frozen=True, [17, 42, 'spam', 'Vikings'])>
|
| 82 |
+
>>> fl.frozen
|
| 83 |
+
True
|
| 84 |
+
>>> fl.append("Monty")
|
| 85 |
+
Traceback (most recent call last):
|
| 86 |
+
File "<stdin>", line 1, in <module>
|
| 87 |
+
File "frozenlist/_frozenlist.pyx", line 97, in frozenlist._frozenlist.FrozenList.append
|
| 88 |
+
self._check_frozen()
|
| 89 |
+
File "frozenlist/_frozenlist.pyx", line 19, in frozenlist._frozenlist.FrozenList._check_frozen
|
| 90 |
+
raise RuntimeError("Cannot modify frozen list.")
|
| 91 |
+
RuntimeError: Cannot modify frozen list.
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
FrozenList is also hashable, but only when frozen. Otherwise it also throws a RuntimeError:
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
>>> fl = FrozenList([17, 42, 'spam'])
|
| 98 |
+
>>> hash(fl)
|
| 99 |
+
Traceback (most recent call last):
|
| 100 |
+
File "<stdin>", line 1, in <module>
|
| 101 |
+
File "frozenlist/_frozenlist.pyx", line 111, in frozenlist._frozenlist.FrozenList.__hash__
|
| 102 |
+
raise RuntimeError("Cannot hash unfrozen list.")
|
| 103 |
+
RuntimeError: Cannot hash unfrozen list.
|
| 104 |
+
>>> fl.freeze()
|
| 105 |
+
>>> hash(fl)
|
| 106 |
+
3713081631934410656
|
| 107 |
+
>>> dictionary = {fl: 'Vikings'} # frozen fl can be a dict key
|
| 108 |
+
>>> dictionary
|
| 109 |
+
{<FrozenList(frozen=True, [1, 2])>: 'Vikings'}
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
Installation
|
| 113 |
+
------------
|
| 114 |
+
|
| 115 |
+
::
|
| 116 |
+
|
| 117 |
+
$ pip install frozenlist
|
| 118 |
+
|
| 119 |
+
The library requires Python 3.8 or newer.
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
Documentation
|
| 123 |
+
-------------
|
| 124 |
+
|
| 125 |
+
https://frozenlist.aio-libs.org
|
| 126 |
+
|
| 127 |
+
Communication channels
|
| 128 |
+
----------------------
|
| 129 |
+
|
| 130 |
+
We have a *Matrix Space* `#aio-libs-space:matrix.org
|
| 131 |
+
<https://matrix.to/#/%23aio-libs-space:matrix.org>`_ which is
|
| 132 |
+
also accessible via Gitter.
|
| 133 |
+
|
| 134 |
+
Requirements
|
| 135 |
+
------------
|
| 136 |
+
|
| 137 |
+
- Python >= 3.8
|
| 138 |
+
|
| 139 |
+
License
|
| 140 |
+
-------
|
| 141 |
+
|
| 142 |
+
``frozenlist`` is offered under the Apache 2 license.
|
| 143 |
+
|
| 144 |
+
Source code
|
| 145 |
+
-----------
|
| 146 |
+
|
| 147 |
+
The project is hosted on GitHub_
|
| 148 |
+
|
| 149 |
+
Please file an issue in the `bug tracker
|
| 150 |
+
<https://github.com/aio-libs/frozenlist/issues>`_ if you have found a bug
|
| 151 |
+
or have some suggestions to improve the library.
|
| 152 |
+
|
| 153 |
+
.. _GitHub: https://github.com/aio-libs/frozenlist
|
| 154 |
+
|
| 155 |
+
=========
|
| 156 |
+
Changelog
|
| 157 |
+
=========
|
| 158 |
+
|
| 159 |
+
..
|
| 160 |
+
You should *NOT* be adding new change log entries to this file, this
|
| 161 |
+
file is managed by towncrier. You *may* edit previous change logs to
|
| 162 |
+
fix problems like typo corrections or such.
|
| 163 |
+
To add a new change log entry, please see
|
| 164 |
+
https://pip.pypa.io/en/latest/development/contributing/#news-entries
|
| 165 |
+
we named the news folder "changes".
|
| 166 |
+
|
| 167 |
+
WARNING: Don't drop the next directive!
|
| 168 |
+
|
| 169 |
+
.. towncrier release notes start
|
| 170 |
+
|
| 171 |
+
1.4.1 (2023-12-15)
|
| 172 |
+
==================
|
| 173 |
+
|
| 174 |
+
Packaging updates and notes for downstreams
|
| 175 |
+
-------------------------------------------
|
| 176 |
+
|
| 177 |
+
- Declared Python 3.12 and PyPy 3.8-3.10 supported officially
|
| 178 |
+
in the distribution package metadata.
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
*Related issues and pull requests on GitHub:*
|
| 182 |
+
`#553 <https://github.com/aio-libs/yarl/issues/553>`__.
|
| 183 |
+
|
| 184 |
+
- Replaced the packaging is replaced from an old-fashioned ``setup.py`` to an
|
| 185 |
+
in-tree `PEP 517 <https://peps.python.org/pep-517>`__ build backend -- by `@webknjaz <https://github.com/sponsors/webknjaz>`__.
|
| 186 |
+
|
| 187 |
+
Whenever the end-users or downstream packagers need to build ``frozenlist``
|
| 188 |
+
from source (a Git checkout or an sdist), they may pass a ``config_settings``
|
| 189 |
+
flag ``pure-python``. If this flag is not set, a C-extension will be built
|
| 190 |
+
and included into the distribution.
|
| 191 |
+
|
| 192 |
+
Here is how this can be done with ``pip``:
|
| 193 |
+
|
| 194 |
+
.. code-block:: console
|
| 195 |
+
|
| 196 |
+
$ python3 -m pip install . --config-settings=pure-python=
|
| 197 |
+
|
| 198 |
+
This will also work with ``-e | --editable``.
|
| 199 |
+
|
| 200 |
+
The same can be achieved via ``pypa/build``:
|
| 201 |
+
|
| 202 |
+
.. code-block:: console
|
| 203 |
+
|
| 204 |
+
$ python3 -m build --config-setting=pure-python=
|
| 205 |
+
|
| 206 |
+
Adding ``-w | --wheel`` can force ``pypa/build`` produce a wheel from source
|
| 207 |
+
directly, as opposed to building an ``sdist`` and then building from it.
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
*Related issues and pull requests on GitHub:*
|
| 211 |
+
`#560 <https://github.com/aio-libs/yarl/issues/560>`__.
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
Contributor-facing changes
|
| 215 |
+
--------------------------
|
| 216 |
+
|
| 217 |
+
- It is now possible to request line tracing in Cython builds using the
|
| 218 |
+
``with-cython-tracing`` `PEP 517 <https://peps.python.org/pep-517>`__ config setting
|
| 219 |
+
-- `@webknjaz <https://github.com/sponsors/webknjaz>`__.
|
| 220 |
+
|
| 221 |
+
This can be used in CI and development environment to measure coverage
|
| 222 |
+
on Cython modules, but is not normally useful to the end-users or
|
| 223 |
+
downstream packagers.
|
| 224 |
+
|
| 225 |
+
Here's a usage example:
|
| 226 |
+
|
| 227 |
+
.. code-block:: console
|
| 228 |
+
|
| 229 |
+
$ python3 -Im pip install . --config-settings=with-cython-tracing=true
|
| 230 |
+
|
| 231 |
+
For editable installs, this setting is on by default. Otherwise, it's
|
| 232 |
+
off unless requested explicitly.
|
| 233 |
+
|
| 234 |
+
The following produces C-files required for the Cython coverage
|
| 235 |
+
plugin to map the measurements back to the PYX-files:
|
| 236 |
+
|
| 237 |
+
.. code-block:: console
|
| 238 |
+
|
| 239 |
+
$ python -Im pip install -e .
|
| 240 |
+
|
| 241 |
+
Alternatively, the ``FROZENLIST_CYTHON_TRACING=1`` environment variable
|
| 242 |
+
can be set to do the same as the `PEP 517 <https://peps.python.org/pep-517>`__ config setting.
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
*Related issues and pull requests on GitHub:*
|
| 246 |
+
`#560 <https://github.com/aio-libs/yarl/issues/560>`__.
|
| 247 |
+
|
| 248 |
+
- Coverage collection has been implemented for the Cython modules
|
| 249 |
+
-- by `@webknjaz <https://github.com/sponsors/webknjaz>`__.
|
| 250 |
+
|
| 251 |
+
It will also be reported to Codecov from any non-release CI jobs.
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
*Related issues and pull requests on GitHub:*
|
| 255 |
+
`#561 <https://github.com/aio-libs/yarl/issues/561>`__.
|
| 256 |
+
|
| 257 |
+
- A step-by-step ``Release Guide`` guide has
|
| 258 |
+
been added, describing how to release *frozenlist* -- by `@webknjaz <https://github.com/sponsors/webknjaz>`__.
|
| 259 |
+
|
| 260 |
+
This is primarily targeting the maintainers.
|
| 261 |
+
|
| 262 |
+
|
| 263 |
+
*Related issues and pull requests on GitHub:*
|
| 264 |
+
`#563 <https://github.com/aio-libs/yarl/issues/563>`__.
|
| 265 |
+
|
| 266 |
+
- Detailed ``Contributing Guidelines`` on
|
| 267 |
+
authoring the changelog fragments have been published in the
|
| 268 |
+
documentation -- by `@webknjaz <https://github.com/sponsors/webknjaz>`__.
|
| 269 |
+
|
| 270 |
+
|
| 271 |
+
*Related issues and pull requests on GitHub:*
|
| 272 |
+
`#564 <https://github.com/aio-libs/yarl/issues/564>`__.
|
| 273 |
+
|
| 274 |
+
|
| 275 |
+
----
|
| 276 |
+
|
| 277 |
+
|
| 278 |
+
1.4.0 (2023-07-12)
|
| 279 |
+
==================
|
| 280 |
+
|
| 281 |
+
The published source distribution package became buildable
|
| 282 |
+
under Python 3.12.
|
| 283 |
+
|
| 284 |
+
|
| 285 |
+
----
|
| 286 |
+
|
| 287 |
+
|
| 288 |
+
Bugfixes
|
| 289 |
+
--------
|
| 290 |
+
|
| 291 |
+
- Removed an unused ``typing.Tuple`` import
|
| 292 |
+
`#411 <https://github.com/aio-libs/frozenlist/issues/411>`_
|
| 293 |
+
|
| 294 |
+
|
| 295 |
+
Deprecations and Removals
|
| 296 |
+
-------------------------
|
| 297 |
+
|
| 298 |
+
- Dropped Python 3.7 support.
|
| 299 |
+
`#413 <https://github.com/aio-libs/frozenlist/issues/413>`_
|
| 300 |
+
|
| 301 |
+
|
| 302 |
+
Misc
|
| 303 |
+
----
|
| 304 |
+
|
| 305 |
+
- `#410 <https://github.com/aio-libs/frozenlist/issues/410>`_, `#433 <https://github.com/aio-libs/frozenlist/issues/433>`_
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
----
|
| 309 |
+
|
| 310 |
+
|
| 311 |
+
1.3.3 (2022-11-08)
|
| 312 |
+
==================
|
| 313 |
+
|
| 314 |
+
- Fixed CI runs when creating a new release, where new towncrier versions
|
| 315 |
+
fail when the current version section is already present.
|
| 316 |
+
|
| 317 |
+
|
| 318 |
+
----
|
| 319 |
+
|
| 320 |
+
|
| 321 |
+
1.3.2 (2022-11-08)
|
| 322 |
+
==================
|
| 323 |
+
|
| 324 |
+
Misc
|
| 325 |
+
----
|
| 326 |
+
|
| 327 |
+
- Updated the CI runs to better check for test results and to avoid deprecated syntax. `#327 <https://github.com/aio-libs/frozenlist/issues/327>`_
|
| 328 |
+
|
| 329 |
+
|
| 330 |
+
----
|
| 331 |
+
|
| 332 |
+
|
| 333 |
+
1.3.1 (2022-08-02)
|
| 334 |
+
==================
|
| 335 |
+
|
| 336 |
+
The published source distribution package became buildable
|
| 337 |
+
under Python 3.11.
|
| 338 |
+
|
| 339 |
+
|
| 340 |
+
----
|
| 341 |
+
|
| 342 |
+
|
| 343 |
+
1.3.0 (2022-01-18)
|
| 344 |
+
==================
|
| 345 |
+
|
| 346 |
+
Bugfixes
|
| 347 |
+
--------
|
| 348 |
+
|
| 349 |
+
- Do not install C sources with binary distributions.
|
| 350 |
+
`#250 <https://github.com/aio-libs/frozenlist/issues/250>`_
|
| 351 |
+
|
| 352 |
+
|
| 353 |
+
Deprecations and Removals
|
| 354 |
+
-------------------------
|
| 355 |
+
|
| 356 |
+
- Dropped Python 3.6 support
|
| 357 |
+
`#274 <https://github.com/aio-libs/frozenlist/issues/274>`_
|
| 358 |
+
|
| 359 |
+
|
| 360 |
+
----
|
| 361 |
+
|
| 362 |
+
|
| 363 |
+
1.2.0 (2021-10-16)
|
| 364 |
+
==================
|
| 365 |
+
|
| 366 |
+
Features
|
| 367 |
+
--------
|
| 368 |
+
|
| 369 |
+
- ``FrozenList`` now supports being used as a generic type as per PEP 585, e.g. ``frozen_int_list: FrozenList[int]`` (requires Python 3.9 or newer).
|
| 370 |
+
`#172 <https://github.com/aio-libs/frozenlist/issues/172>`_
|
| 371 |
+
- Added support for Python 3.10.
|
| 372 |
+
`#227 <https://github.com/aio-libs/frozenlist/issues/227>`_
|
| 373 |
+
- Started shipping platform-specific wheels with the ``musl`` tag targeting typical Alpine Linux runtimes.
|
| 374 |
+
`#227 <https://github.com/aio-libs/frozenlist/issues/227>`_
|
| 375 |
+
- Started shipping platform-specific arm64 wheels for Apple Silicon.
|
| 376 |
+
`#227 <https://github.com/aio-libs/frozenlist/issues/227>`_
|
| 377 |
+
|
| 378 |
+
|
| 379 |
+
----
|
| 380 |
+
|
| 381 |
+
|
| 382 |
+
1.1.1 (2020-11-14)
|
| 383 |
+
==================
|
| 384 |
+
|
| 385 |
+
Bugfixes
|
| 386 |
+
--------
|
| 387 |
+
|
| 388 |
+
- Provide x86 Windows wheels.
|
| 389 |
+
`#169 <https://github.com/aio-libs/frozenlist/issues/169>`_
|
| 390 |
+
|
| 391 |
+
|
| 392 |
+
----
|
| 393 |
+
|
| 394 |
+
|
| 395 |
+
1.1.0 (2020-10-13)
|
| 396 |
+
==================
|
| 397 |
+
|
| 398 |
+
Features
|
| 399 |
+
--------
|
| 400 |
+
|
| 401 |
+
- Add support for hashing of a frozen list.
|
| 402 |
+
`#136 <https://github.com/aio-libs/frozenlist/issues/136>`_
|
| 403 |
+
|
| 404 |
+
- Support Python 3.8 and 3.9.
|
| 405 |
+
|
| 406 |
+
- Provide wheels for ``aarch64``, ``i686``, ``ppc64le``, ``s390x`` architectures on
|
| 407 |
+
Linux as well as ``x86_64``.
|
| 408 |
+
|
| 409 |
+
|
| 410 |
+
----
|
| 411 |
+
|
| 412 |
+
|
| 413 |
+
1.0.0 (2019-11-09)
|
| 414 |
+
==================
|
| 415 |
+
|
| 416 |
+
Deprecations and Removals
|
| 417 |
+
-------------------------
|
| 418 |
+
|
| 419 |
+
- Dropped support for Python 3.5; only 3.6, 3.7 and 3.8 are supported going forward.
|
| 420 |
+
`#24 <https://github.com/aio-libs/frozenlist/issues/24>`_
|
parrot/lib/python3.10/site-packages/frozenlist-1.4.1.dist-info/RECORD
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
frozenlist-1.4.1.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
| 2 |
+
frozenlist-1.4.1.dist-info/LICENSE,sha256=b9UkPpLdf5jsacesN3co50kFcJ_1J6W_mNbQJjwE9bY,11332
|
| 3 |
+
frozenlist-1.4.1.dist-info/METADATA,sha256=i-BTxwxpJrHm-I8DMpFRvXVXJiqXwUcsPiUR47NY6eg,12136
|
| 4 |
+
frozenlist-1.4.1.dist-info/RECORD,,
|
| 5 |
+
frozenlist-1.4.1.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 6 |
+
frozenlist-1.4.1.dist-info/WHEEL,sha256=vV-3gZY0A60KvZ7BiFVUnyR1ohNO_OSjBIJIoRfk_rE,225
|
| 7 |
+
frozenlist-1.4.1.dist-info/top_level.txt,sha256=jivtxsPXA3nK3WBWW2LW5Mtu_GHt8UZA13NeCs2cKuA,11
|
| 8 |
+
frozenlist/__init__.py,sha256=hrSQhfujMaz1BWlHfwuVFrPD02-pCK7jG4e9FaCZCmM,2316
|
| 9 |
+
frozenlist/__init__.pyi,sha256=vMEoES1xGegPtVXoCi9XydEeHsyuIq-KdeXwP5PdsaA,1470
|
| 10 |
+
frozenlist/__pycache__/__init__.cpython-310.pyc,,
|
| 11 |
+
frozenlist/_frozenlist.cpython-310-x86_64-linux-gnu.so,sha256=NlvcEP-slIw1H6qbBejxVzEOxKG33BnttUAdSoP1wA4,766040
|
| 12 |
+
frozenlist/_frozenlist.pyx,sha256=9V4Z1En6TZwgFD26d-sjxyhUzUm338H1Qiz4-i5ukv0,2983
|
| 13 |
+
frozenlist/py.typed,sha256=sow9soTwP9T_gEAQSVh7Gb8855h04Nwmhs2We-JRgZM,7
|
parrot/lib/python3.10/site-packages/frozenlist-1.4.1.dist-info/REQUESTED
ADDED
|
File without changes
|
parrot/lib/python3.10/site-packages/frozenlist-1.4.1.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: bdist_wheel (0.42.0)
|
| 3 |
+
Root-Is-Purelib: false
|
| 4 |
+
Tag: cp310-cp310-manylinux_2_5_x86_64
|
| 5 |
+
Tag: cp310-cp310-manylinux1_x86_64
|
| 6 |
+
Tag: cp310-cp310-manylinux_2_17_x86_64
|
| 7 |
+
Tag: cp310-cp310-manylinux2014_x86_64
|
| 8 |
+
|
parrot/lib/python3.10/site-packages/frozenlist-1.4.1.dist-info/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
frozenlist
|
parrot/lib/python3.10/site-packages/hjson/__init__.py
ADDED
|
@@ -0,0 +1,642 @@
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
r"""Hjson, the Human JSON. A configuration file format that caters to
|
| 2 |
+
humans and helps reduce the errors they make.
|
| 3 |
+
|
| 4 |
+
For details and syntax see <https://hjson.github.io>.
|
| 5 |
+
|
| 6 |
+
Decoding Hjson::
|
| 7 |
+
|
| 8 |
+
>>> import hjson
|
| 9 |
+
>>> text = "{\n foo: a\n bar: 1\n}"
|
| 10 |
+
>>> hjson.loads(text)
|
| 11 |
+
OrderedDict([('foo', 'a'), ('bar', 1)])
|
| 12 |
+
|
| 13 |
+
Encoding Python object hierarchies::
|
| 14 |
+
|
| 15 |
+
>>> import hjson
|
| 16 |
+
>>> # hjson.dumps({'foo': 'text', 'bar': (1, 2)})
|
| 17 |
+
>>> hjson.dumps(OrderedDict([('foo', 'text'), ('bar', (1, 2))]))
|
| 18 |
+
'{\n foo: text\n bar:\n [\n 1\n 2\n ]\n}'
|
| 19 |
+
|
| 20 |
+
Encoding as JSON::
|
| 21 |
+
|
| 22 |
+
Note that this is probably not as performant as the simplejson version.
|
| 23 |
+
|
| 24 |
+
>>> import hjson
|
| 25 |
+
>>> hjson.dumpsJSON(['foo', {'bar': ('baz', None, 1.0, 2)}])
|
| 26 |
+
'["foo", {"bar": ["baz", null, 1.0, 2]}]'
|
| 27 |
+
|
| 28 |
+
Using hjson.tool from the shell to validate and pretty-print::
|
| 29 |
+
|
| 30 |
+
$ echo '{"json":"obj"}' | python -m hjson.tool
|
| 31 |
+
{
|
| 32 |
+
json: obj
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
Other formats are -c for compact or -j for formatted JSON.
|
| 36 |
+
|
| 37 |
+
"""
|
| 38 |
+
from __future__ import absolute_import
|
| 39 |
+
__version__ = '3.1.0'
|
| 40 |
+
__all__ = [
|
| 41 |
+
'dump', 'dumps', 'load', 'loads',
|
| 42 |
+
'dumpJSON', 'dumpsJSON',
|
| 43 |
+
'HjsonDecoder', 'HjsonDecodeError', 'HjsonEncoder', 'JSONEncoder',
|
| 44 |
+
'OrderedDict', 'simple_first',
|
| 45 |
+
]
|
| 46 |
+
|
| 47 |
+
# based on simplejson by
|
| 48 |
+
# __author__ = 'Bob Ippolito <bob@redivi.com>'
|
| 49 |
+
__author__ = 'Christian Zangl <coralllama@gmail.com>'
|
| 50 |
+
|
| 51 |
+
from decimal import Decimal
|
| 52 |
+
|
| 53 |
+
from .scanner import HjsonDecodeError
|
| 54 |
+
from .decoder import HjsonDecoder
|
| 55 |
+
from .encoderH import HjsonEncoder
|
| 56 |
+
from .encoder import JSONEncoder
|
| 57 |
+
def _import_OrderedDict():
|
| 58 |
+
import collections
|
| 59 |
+
try:
|
| 60 |
+
return collections.OrderedDict
|
| 61 |
+
except AttributeError:
|
| 62 |
+
from . import ordered_dict
|
| 63 |
+
return ordered_dict.OrderedDict
|
| 64 |
+
OrderedDict = _import_OrderedDict()
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
_default_decoder = HjsonDecoder(encoding=None, object_hook=None,
|
| 68 |
+
object_pairs_hook=OrderedDict)
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def load(fp, encoding=None, cls=None, object_hook=None, parse_float=None,
|
| 72 |
+
parse_int=None, object_pairs_hook=OrderedDict,
|
| 73 |
+
use_decimal=False, namedtuple_as_object=True, tuple_as_array=True,
|
| 74 |
+
**kw):
|
| 75 |
+
"""Deserialize ``fp`` (a ``.read()``-supporting file-like object containing
|
| 76 |
+
a JSON document) to a Python object.
|
| 77 |
+
|
| 78 |
+
*encoding* determines the encoding used to interpret any
|
| 79 |
+
:class:`str` objects decoded by this instance (``'utf-8'`` by
|
| 80 |
+
default). It has no effect when decoding :class:`unicode` objects.
|
| 81 |
+
|
| 82 |
+
Note that currently only encodings that are a superset of ASCII work,
|
| 83 |
+
strings of other encodings should be passed in as :class:`unicode`.
|
| 84 |
+
|
| 85 |
+
*object_hook*, if specified, will be called with the result of every
|
| 86 |
+
JSON object decoded and its return value will be used in place of the
|
| 87 |
+
given :class:`dict`. This can be used to provide custom
|
| 88 |
+
deserializations (e.g. to support JSON-RPC class hinting).
|
| 89 |
+
|
| 90 |
+
*object_pairs_hook* is an optional function that will be called with
|
| 91 |
+
the result of any object literal decode with an ordered list of pairs.
|
| 92 |
+
The return value of *object_pairs_hook* will be used instead of the
|
| 93 |
+
:class:`dict`. This feature can be used to implement custom decoders
|
| 94 |
+
that rely on the order that the key and value pairs are decoded (for
|
| 95 |
+
example, :func:`collections.OrderedDict` will remember the order of
|
| 96 |
+
insertion). If *object_hook* is also defined, the *object_pairs_hook*
|
| 97 |
+
takes priority.
|
| 98 |
+
|
| 99 |
+
*parse_float*, if specified, will be called with the string of every
|
| 100 |
+
JSON float to be decoded. By default, this is equivalent to
|
| 101 |
+
``float(num_str)``. This can be used to use another datatype or parser
|
| 102 |
+
for JSON floats (e.g. :class:`decimal.Decimal`).
|
| 103 |
+
|
| 104 |
+
*parse_int*, if specified, will be called with the string of every
|
| 105 |
+
JSON int to be decoded. By default, this is equivalent to
|
| 106 |
+
``int(num_str)``. This can be used to use another datatype or parser
|
| 107 |
+
for JSON integers (e.g. :class:`float`).
|
| 108 |
+
|
| 109 |
+
If *use_decimal* is true (default: ``False``) then it implies
|
| 110 |
+
parse_float=decimal.Decimal for parity with ``dump``.
|
| 111 |
+
|
| 112 |
+
To use a custom ``HjsonDecoder`` subclass, specify it with the ``cls``
|
| 113 |
+
kwarg. NOTE: You should use *object_hook* or *object_pairs_hook* instead
|
| 114 |
+
of subclassing whenever possible.
|
| 115 |
+
|
| 116 |
+
"""
|
| 117 |
+
return loads(fp.read(),
|
| 118 |
+
encoding=encoding, cls=cls, object_hook=object_hook,
|
| 119 |
+
parse_float=parse_float, parse_int=parse_int,
|
| 120 |
+
object_pairs_hook=object_pairs_hook,
|
| 121 |
+
use_decimal=use_decimal, **kw)
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
def loads(s, encoding=None, cls=None, object_hook=None, parse_float=None,
|
| 125 |
+
parse_int=None, object_pairs_hook=None,
|
| 126 |
+
use_decimal=False, **kw):
|
| 127 |
+
"""Deserialize ``s`` (a ``str`` or ``unicode`` instance containing a JSON
|
| 128 |
+
document) to a Python object.
|
| 129 |
+
|
| 130 |
+
*encoding* determines the encoding used to interpret any
|
| 131 |
+
:class:`str` objects decoded by this instance (``'utf-8'`` by
|
| 132 |
+
default). It has no effect when decoding :class:`unicode` objects.
|
| 133 |
+
|
| 134 |
+
Note that currently only encodings that are a superset of ASCII work,
|
| 135 |
+
strings of other encodings should be passed in as :class:`unicode`.
|
| 136 |
+
|
| 137 |
+
*object_hook*, if specified, will be called with the result of every
|
| 138 |
+
JSON object decoded and its return value will be used in place of the
|
| 139 |
+
given :class:`dict`. This can be used to provide custom
|
| 140 |
+
deserializations (e.g. to support JSON-RPC class hinting).
|
| 141 |
+
|
| 142 |
+
*object_pairs_hook* is an optional function that will be called with
|
| 143 |
+
the result of any object literal decode with an ordered list of pairs.
|
| 144 |
+
The return value of *object_pairs_hook* will be used instead of the
|
| 145 |
+
:class:`dict`. This feature can be used to implement custom decoders
|
| 146 |
+
that rely on the order that the key and value pairs are decoded (for
|
| 147 |
+
example, :func:`collections.OrderedDict` will remember the order of
|
| 148 |
+
insertion). If *object_hook* is also defined, the *object_pairs_hook*
|
| 149 |
+
takes priority.
|
| 150 |
+
|
| 151 |
+
*parse_float*, if specified, will be called with the string of every
|
| 152 |
+
JSON float to be decoded. By default, this is equivalent to
|
| 153 |
+
``float(num_str)``. This can be used to use another datatype or parser
|
| 154 |
+
for JSON floats (e.g. :class:`decimal.Decimal`).
|
| 155 |
+
|
| 156 |
+
*parse_int*, if specified, will be called with the string of every
|
| 157 |
+
JSON int to be decoded. By default, this is equivalent to
|
| 158 |
+
``int(num_str)``. This can be used to use another datatype or parser
|
| 159 |
+
for JSON integers (e.g. :class:`float`).
|
| 160 |
+
|
| 161 |
+
If *use_decimal* is true (default: ``False``) then it implies
|
| 162 |
+
parse_float=decimal.Decimal for parity with ``dump``.
|
| 163 |
+
|
| 164 |
+
To use a custom ``HjsonDecoder`` subclass, specify it with the ``cls``
|
| 165 |
+
kwarg. NOTE: You should use *object_hook* or *object_pairs_hook* instead
|
| 166 |
+
of subclassing whenever possible.
|
| 167 |
+
|
| 168 |
+
"""
|
| 169 |
+
if (cls is None and encoding is None and object_hook is None and
|
| 170 |
+
parse_int is None and parse_float is None and
|
| 171 |
+
object_pairs_hook is None
|
| 172 |
+
and not use_decimal and not kw):
|
| 173 |
+
return _default_decoder.decode(s)
|
| 174 |
+
if cls is None:
|
| 175 |
+
cls = HjsonDecoder
|
| 176 |
+
if object_hook is not None:
|
| 177 |
+
kw['object_hook'] = object_hook
|
| 178 |
+
if object_pairs_hook is not None:
|
| 179 |
+
kw['object_pairs_hook'] = object_pairs_hook
|
| 180 |
+
if parse_float is not None:
|
| 181 |
+
kw['parse_float'] = parse_float
|
| 182 |
+
if parse_int is not None:
|
| 183 |
+
kw['parse_int'] = parse_int
|
| 184 |
+
if use_decimal:
|
| 185 |
+
if parse_float is not None:
|
| 186 |
+
raise TypeError("use_decimal=True implies parse_float=Decimal")
|
| 187 |
+
kw['parse_float'] = Decimal
|
| 188 |
+
return cls(encoding=encoding, **kw).decode(s)
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
_default_hjson_encoder = HjsonEncoder(
|
| 192 |
+
skipkeys=False,
|
| 193 |
+
ensure_ascii=True,
|
| 194 |
+
check_circular=True,
|
| 195 |
+
indent=None,
|
| 196 |
+
encoding='utf-8',
|
| 197 |
+
default=None,
|
| 198 |
+
use_decimal=True,
|
| 199 |
+
namedtuple_as_object=True,
|
| 200 |
+
tuple_as_array=True,
|
| 201 |
+
bigint_as_string=False,
|
| 202 |
+
item_sort_key=None,
|
| 203 |
+
for_json=False,
|
| 204 |
+
int_as_string_bitcount=None,
|
| 205 |
+
)
|
| 206 |
+
|
| 207 |
+
def dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True,
|
| 208 |
+
cls=None, indent=None,
|
| 209 |
+
encoding='utf-8', default=None, use_decimal=True,
|
| 210 |
+
namedtuple_as_object=True, tuple_as_array=True,
|
| 211 |
+
bigint_as_string=False, sort_keys=False, item_sort_key=None,
|
| 212 |
+
for_json=False, int_as_string_bitcount=None, **kw):
|
| 213 |
+
"""Serialize ``obj`` as a JSON formatted stream to ``fp`` (a
|
| 214 |
+
``.write()``-supporting file-like object).
|
| 215 |
+
|
| 216 |
+
If *skipkeys* is true then ``dict`` keys that are not basic types
|
| 217 |
+
(``str``, ``unicode``, ``int``, ``long``, ``float``, ``bool``, ``None``)
|
| 218 |
+
will be skipped instead of raising a ``TypeError``.
|
| 219 |
+
|
| 220 |
+
If *ensure_ascii* is false, then the some chunks written to ``fp``
|
| 221 |
+
may be ``unicode`` instances, subject to normal Python ``str`` to
|
| 222 |
+
``unicode`` coercion rules. Unless ``fp.write()`` explicitly
|
| 223 |
+
understands ``unicode`` (as in ``codecs.getwriter()``) this is likely
|
| 224 |
+
to cause an error.
|
| 225 |
+
|
| 226 |
+
If *check_circular* is false, then the circular reference check
|
| 227 |
+
for container types will be skipped and a circular reference will
|
| 228 |
+
result in an ``OverflowError`` (or worse).
|
| 229 |
+
|
| 230 |
+
*indent* defines the amount of whitespace that the JSON array elements
|
| 231 |
+
and object members will be indented for each level of nesting.
|
| 232 |
+
The default is two spaces.
|
| 233 |
+
|
| 234 |
+
*encoding* is the character encoding for str instances, default is UTF-8.
|
| 235 |
+
|
| 236 |
+
*default(obj)* is a function that should return a serializable version
|
| 237 |
+
of obj or raise ``TypeError``. The default simply raises ``TypeError``.
|
| 238 |
+
|
| 239 |
+
If *use_decimal* is true (default: ``True``) then decimal.Decimal
|
| 240 |
+
will be natively serialized to JSON with full precision.
|
| 241 |
+
|
| 242 |
+
If *namedtuple_as_object* is true (default: ``True``),
|
| 243 |
+
:class:`tuple` subclasses with ``_asdict()`` methods will be encoded
|
| 244 |
+
as JSON objects.
|
| 245 |
+
|
| 246 |
+
If *tuple_as_array* is true (default: ``True``),
|
| 247 |
+
:class:`tuple` (and subclasses) will be encoded as JSON arrays.
|
| 248 |
+
|
| 249 |
+
If *bigint_as_string* is true (default: ``False``), ints 2**53 and higher
|
| 250 |
+
or lower than -2**53 will be encoded as strings. This is to avoid the
|
| 251 |
+
rounding that happens in Javascript otherwise. Note that this is still a
|
| 252 |
+
lossy operation that will not round-trip correctly and should be used
|
| 253 |
+
sparingly.
|
| 254 |
+
|
| 255 |
+
If *int_as_string_bitcount* is a positive number (n), then int of size
|
| 256 |
+
greater than or equal to 2**n or lower than or equal to -2**n will be
|
| 257 |
+
encoded as strings.
|
| 258 |
+
|
| 259 |
+
If specified, *item_sort_key* is a callable used to sort the items in
|
| 260 |
+
each dictionary. This is useful if you want to sort items other than
|
| 261 |
+
in alphabetical order by key. This option takes precedence over
|
| 262 |
+
*sort_keys*.
|
| 263 |
+
|
| 264 |
+
If *sort_keys* is true (default: ``False``), the output of dictionaries
|
| 265 |
+
will be sorted by item.
|
| 266 |
+
|
| 267 |
+
If *for_json* is true (default: ``False``), objects with a ``for_json()``
|
| 268 |
+
method will use the return value of that method for encoding as JSON
|
| 269 |
+
instead of the object.
|
| 270 |
+
|
| 271 |
+
To use a custom ``HjsonEncoder`` subclass (e.g. one that overrides the
|
| 272 |
+
``.default()`` method to serialize additional types), specify it with
|
| 273 |
+
the ``cls`` kwarg. NOTE: You should use *default* or *for_json* instead
|
| 274 |
+
of subclassing whenever possible.
|
| 275 |
+
|
| 276 |
+
"""
|
| 277 |
+
# cached encoder
|
| 278 |
+
if (not skipkeys and ensure_ascii and
|
| 279 |
+
check_circular and
|
| 280 |
+
cls is None and indent is None and
|
| 281 |
+
encoding == 'utf-8' and default is None and use_decimal
|
| 282 |
+
and namedtuple_as_object and tuple_as_array
|
| 283 |
+
and not bigint_as_string and not sort_keys
|
| 284 |
+
and not item_sort_key and not for_json
|
| 285 |
+
and int_as_string_bitcount is None
|
| 286 |
+
and not kw
|
| 287 |
+
):
|
| 288 |
+
iterable = _default_hjson_encoder.iterencode(obj)
|
| 289 |
+
else:
|
| 290 |
+
if cls is None:
|
| 291 |
+
cls = HjsonEncoder
|
| 292 |
+
iterable = cls(skipkeys=skipkeys, ensure_ascii=ensure_ascii,
|
| 293 |
+
check_circular=check_circular, indent=indent,
|
| 294 |
+
encoding=encoding,
|
| 295 |
+
default=default, use_decimal=use_decimal,
|
| 296 |
+
namedtuple_as_object=namedtuple_as_object,
|
| 297 |
+
tuple_as_array=tuple_as_array,
|
| 298 |
+
bigint_as_string=bigint_as_string,
|
| 299 |
+
sort_keys=sort_keys,
|
| 300 |
+
item_sort_key=item_sort_key,
|
| 301 |
+
for_json=for_json,
|
| 302 |
+
int_as_string_bitcount=int_as_string_bitcount,
|
| 303 |
+
**kw).iterencode(obj)
|
| 304 |
+
# could accelerate with writelines in some versions of Python, at
|
| 305 |
+
# a debuggability cost
|
| 306 |
+
for chunk in iterable:
|
| 307 |
+
fp.write(chunk)
|
| 308 |
+
|
| 309 |
+
|
| 310 |
+
def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True,
|
| 311 |
+
cls=None, indent=None,
|
| 312 |
+
encoding='utf-8', default=None, use_decimal=True,
|
| 313 |
+
namedtuple_as_object=True, tuple_as_array=True,
|
| 314 |
+
bigint_as_string=False, sort_keys=False, item_sort_key=None,
|
| 315 |
+
for_json=False, int_as_string_bitcount=None, **kw):
|
| 316 |
+
"""Serialize ``obj`` to a JSON formatted ``str``.
|
| 317 |
+
|
| 318 |
+
If ``skipkeys`` is false then ``dict`` keys that are not basic types
|
| 319 |
+
(``str``, ``unicode``, ``int``, ``long``, ``float``, ``bool``, ``None``)
|
| 320 |
+
will be skipped instead of raising a ``TypeError``.
|
| 321 |
+
|
| 322 |
+
If ``ensure_ascii`` is false, then the return value will be a
|
| 323 |
+
``unicode`` instance subject to normal Python ``str`` to ``unicode``
|
| 324 |
+
coercion rules instead of being escaped to an ASCII ``str``.
|
| 325 |
+
|
| 326 |
+
If ``check_circular`` is false, then the circular reference check
|
| 327 |
+
for container types will be skipped and a circular reference will
|
| 328 |
+
result in an ``OverflowError`` (or worse).
|
| 329 |
+
|
| 330 |
+
*indent* defines the amount of whitespace that the JSON array elements
|
| 331 |
+
and object members will be indented for each level of nesting.
|
| 332 |
+
The default is two spaces.
|
| 333 |
+
|
| 334 |
+
``encoding`` is the character encoding for str instances, default is UTF-8.
|
| 335 |
+
|
| 336 |
+
``default(obj)`` is a function that should return a serializable version
|
| 337 |
+
of obj or raise TypeError. The default simply raises TypeError.
|
| 338 |
+
|
| 339 |
+
If *use_decimal* is true (default: ``True``) then decimal.Decimal
|
| 340 |
+
will be natively serialized to JSON with full precision.
|
| 341 |
+
|
| 342 |
+
If *namedtuple_as_object* is true (default: ``True``),
|
| 343 |
+
:class:`tuple` subclasses with ``_asdict()`` methods will be encoded
|
| 344 |
+
as JSON objects.
|
| 345 |
+
|
| 346 |
+
If *tuple_as_array* is true (default: ``True``),
|
| 347 |
+
:class:`tuple` (and subclasses) will be encoded as JSON arrays.
|
| 348 |
+
|
| 349 |
+
If *bigint_as_string* is true (not the default), ints 2**53 and higher
|
| 350 |
+
or lower than -2**53 will be encoded as strings. This is to avoid the
|
| 351 |
+
rounding that happens in Javascript otherwise.
|
| 352 |
+
|
| 353 |
+
If *int_as_string_bitcount* is a positive number (n), then int of size
|
| 354 |
+
greater than or equal to 2**n or lower than or equal to -2**n will be
|
| 355 |
+
encoded as strings.
|
| 356 |
+
|
| 357 |
+
If specified, *item_sort_key* is a callable used to sort the items in
|
| 358 |
+
each dictionary. This is useful if you want to sort items other than
|
| 359 |
+
in alphabetical order by key. This option takes precendence over
|
| 360 |
+
*sort_keys*.
|
| 361 |
+
|
| 362 |
+
If *sort_keys* is true (default: ``False``), the output of dictionaries
|
| 363 |
+
will be sorted by item.
|
| 364 |
+
|
| 365 |
+
If *for_json* is true (default: ``False``), objects with a ``for_json()``
|
| 366 |
+
method will use the return value of that method for encoding as JSON
|
| 367 |
+
instead of the object.
|
| 368 |
+
|
| 369 |
+
To use a custom ``HjsonEncoder`` subclass (e.g. one that overrides the
|
| 370 |
+
``.default()`` method to serialize additional types), specify it with
|
| 371 |
+
the ``cls`` kwarg. NOTE: You should use *default* instead of subclassing
|
| 372 |
+
whenever possible.
|
| 373 |
+
|
| 374 |
+
"""
|
| 375 |
+
# cached encoder
|
| 376 |
+
if (
|
| 377 |
+
not skipkeys and ensure_ascii and
|
| 378 |
+
check_circular and
|
| 379 |
+
cls is None and indent is None and
|
| 380 |
+
encoding == 'utf-8' and default is None and use_decimal
|
| 381 |
+
and namedtuple_as_object and tuple_as_array
|
| 382 |
+
and not bigint_as_string and not sort_keys
|
| 383 |
+
and not item_sort_key and not for_json
|
| 384 |
+
and int_as_string_bitcount is None
|
| 385 |
+
and not kw
|
| 386 |
+
):
|
| 387 |
+
return _default_hjson_encoder.encode(obj)
|
| 388 |
+
if cls is None:
|
| 389 |
+
cls = HjsonEncoder
|
| 390 |
+
return cls(
|
| 391 |
+
skipkeys=skipkeys, ensure_ascii=ensure_ascii,
|
| 392 |
+
check_circular=check_circular, indent=indent,
|
| 393 |
+
encoding=encoding, default=default,
|
| 394 |
+
use_decimal=use_decimal,
|
| 395 |
+
namedtuple_as_object=namedtuple_as_object,
|
| 396 |
+
tuple_as_array=tuple_as_array,
|
| 397 |
+
bigint_as_string=bigint_as_string,
|
| 398 |
+
sort_keys=sort_keys,
|
| 399 |
+
item_sort_key=item_sort_key,
|
| 400 |
+
for_json=for_json,
|
| 401 |
+
int_as_string_bitcount=int_as_string_bitcount,
|
| 402 |
+
**kw).encode(obj)
|
| 403 |
+
|
| 404 |
+
|
| 405 |
+
|
| 406 |
+
_default_json_encoder = JSONEncoder(
|
| 407 |
+
skipkeys=False,
|
| 408 |
+
ensure_ascii=True,
|
| 409 |
+
check_circular=True,
|
| 410 |
+
indent=None,
|
| 411 |
+
separators=None,
|
| 412 |
+
encoding='utf-8',
|
| 413 |
+
default=None,
|
| 414 |
+
use_decimal=True,
|
| 415 |
+
namedtuple_as_object=True,
|
| 416 |
+
tuple_as_array=True,
|
| 417 |
+
bigint_as_string=False,
|
| 418 |
+
item_sort_key=None,
|
| 419 |
+
for_json=False,
|
| 420 |
+
int_as_string_bitcount=None,
|
| 421 |
+
)
|
| 422 |
+
|
| 423 |
+
def dumpJSON(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True,
|
| 424 |
+
cls=None, indent=None, separators=None,
|
| 425 |
+
encoding='utf-8', default=None, use_decimal=True,
|
| 426 |
+
namedtuple_as_object=True, tuple_as_array=True,
|
| 427 |
+
bigint_as_string=False, sort_keys=False, item_sort_key=None,
|
| 428 |
+
for_json=False, int_as_string_bitcount=None, **kw):
|
| 429 |
+
"""Serialize ``obj`` as a JSON formatted stream to ``fp`` (a
|
| 430 |
+
``.write()``-supporting file-like object).
|
| 431 |
+
|
| 432 |
+
If *skipkeys* is true then ``dict`` keys that are not basic types
|
| 433 |
+
(``str``, ``unicode``, ``int``, ``long``, ``float``, ``bool``, ``None``)
|
| 434 |
+
will be skipped instead of raising a ``TypeError``.
|
| 435 |
+
|
| 436 |
+
If *ensure_ascii* is false, then the some chunks written to ``fp``
|
| 437 |
+
may be ``unicode`` instances, subject to normal Python ``str`` to
|
| 438 |
+
``unicode`` coercion rules. Unless ``fp.write()`` explicitly
|
| 439 |
+
understands ``unicode`` (as in ``codecs.getwriter()``) this is likely
|
| 440 |
+
to cause an error.
|
| 441 |
+
|
| 442 |
+
If *check_circular* is false, then the circular reference check
|
| 443 |
+
for container types will be skipped and a circular reference will
|
| 444 |
+
result in an ``OverflowError`` (or worse).
|
| 445 |
+
|
| 446 |
+
If *indent* is a string, then JSON array elements and object members
|
| 447 |
+
will be pretty-printed with a newline followed by that string repeated
|
| 448 |
+
for each level of nesting. ``None`` (the default) selects the most compact
|
| 449 |
+
representation without any newlines. An integer is also accepted
|
| 450 |
+
and is converted to a string with that many spaces.
|
| 451 |
+
|
| 452 |
+
If specified, *separators* should be an
|
| 453 |
+
``(item_separator, key_separator)`` tuple. The default is ``(', ', ': ')``
|
| 454 |
+
if *indent* is ``None`` and ``(',', ': ')`` otherwise. To get the most
|
| 455 |
+
compact JSON representation, you should specify ``(',', ':')`` to eliminate
|
| 456 |
+
whitespace.
|
| 457 |
+
|
| 458 |
+
*encoding* is the character encoding for str instances, default is UTF-8.
|
| 459 |
+
|
| 460 |
+
*default(obj)* is a function that should return a serializable version
|
| 461 |
+
of obj or raise ``TypeError``. The default simply raises ``TypeError``.
|
| 462 |
+
|
| 463 |
+
If *use_decimal* is true (default: ``True``) then decimal.Decimal
|
| 464 |
+
will be natively serialized to JSON with full precision.
|
| 465 |
+
|
| 466 |
+
If *namedtuple_as_object* is true (default: ``True``),
|
| 467 |
+
:class:`tuple` subclasses with ``_asdict()`` methods will be encoded
|
| 468 |
+
as JSON objects.
|
| 469 |
+
|
| 470 |
+
If *tuple_as_array* is true (default: ``True``),
|
| 471 |
+
:class:`tuple` (and subclasses) will be encoded as JSON arrays.
|
| 472 |
+
|
| 473 |
+
If *bigint_as_string* is true (default: ``False``), ints 2**53 and higher
|
| 474 |
+
or lower than -2**53 will be encoded as strings. This is to avoid the
|
| 475 |
+
rounding that happens in Javascript otherwise. Note that this is still a
|
| 476 |
+
lossy operation that will not round-trip correctly and should be used
|
| 477 |
+
sparingly.
|
| 478 |
+
|
| 479 |
+
If *int_as_string_bitcount* is a positive number (n), then int of size
|
| 480 |
+
greater than or equal to 2**n or lower than or equal to -2**n will be
|
| 481 |
+
encoded as strings.
|
| 482 |
+
|
| 483 |
+
If specified, *item_sort_key* is a callable used to sort the items in
|
| 484 |
+
each dictionary. This is useful if you want to sort items other than
|
| 485 |
+
in alphabetical order by key. This option takes precedence over
|
| 486 |
+
*sort_keys*.
|
| 487 |
+
|
| 488 |
+
If *sort_keys* is true (default: ``False``), the output of dictionaries
|
| 489 |
+
will be sorted by item.
|
| 490 |
+
|
| 491 |
+
If *for_json* is true (default: ``False``), objects with a ``for_json()``
|
| 492 |
+
method will use the return value of that method for encoding as JSON
|
| 493 |
+
instead of the object.
|
| 494 |
+
|
| 495 |
+
To use a custom ``JSONEncoder`` subclass (e.g. one that overrides the
|
| 496 |
+
``.default()`` method to serialize additional types), specify it with
|
| 497 |
+
the ``cls`` kwarg. NOTE: You should use *default* or *for_json* instead
|
| 498 |
+
of subclassing whenever possible.
|
| 499 |
+
|
| 500 |
+
"""
|
| 501 |
+
# cached encoder
|
| 502 |
+
if (not skipkeys and ensure_ascii and
|
| 503 |
+
check_circular and
|
| 504 |
+
cls is None and indent is None and separators is None and
|
| 505 |
+
encoding == 'utf-8' and default is None and use_decimal
|
| 506 |
+
and namedtuple_as_object and tuple_as_array
|
| 507 |
+
and not bigint_as_string and not sort_keys
|
| 508 |
+
and not item_sort_key and not for_json
|
| 509 |
+
and int_as_string_bitcount is None
|
| 510 |
+
and not kw
|
| 511 |
+
):
|
| 512 |
+
iterable = _default_json_encoder.iterencode(obj)
|
| 513 |
+
else:
|
| 514 |
+
if cls is None:
|
| 515 |
+
cls = JSONEncoder
|
| 516 |
+
iterable = cls(skipkeys=skipkeys, ensure_ascii=ensure_ascii,
|
| 517 |
+
check_circular=check_circular, indent=indent,
|
| 518 |
+
separators=separators, encoding=encoding,
|
| 519 |
+
default=default, use_decimal=use_decimal,
|
| 520 |
+
namedtuple_as_object=namedtuple_as_object,
|
| 521 |
+
tuple_as_array=tuple_as_array,
|
| 522 |
+
bigint_as_string=bigint_as_string,
|
| 523 |
+
sort_keys=sort_keys,
|
| 524 |
+
item_sort_key=item_sort_key,
|
| 525 |
+
for_json=for_json,
|
| 526 |
+
int_as_string_bitcount=int_as_string_bitcount,
|
| 527 |
+
**kw).iterencode(obj)
|
| 528 |
+
# could accelerate with writelines in some versions of Python, at
|
| 529 |
+
# a debuggability cost
|
| 530 |
+
for chunk in iterable:
|
| 531 |
+
fp.write(chunk)
|
| 532 |
+
|
| 533 |
+
|
| 534 |
+
def dumpsJSON(obj, skipkeys=False, ensure_ascii=True, check_circular=True,
|
| 535 |
+
cls=None, indent=None, separators=None,
|
| 536 |
+
encoding='utf-8', default=None, use_decimal=True,
|
| 537 |
+
namedtuple_as_object=True, tuple_as_array=True,
|
| 538 |
+
bigint_as_string=False, sort_keys=False, item_sort_key=None,
|
| 539 |
+
for_json=False, int_as_string_bitcount=None, **kw):
|
| 540 |
+
"""Serialize ``obj`` to a JSON formatted ``str``.
|
| 541 |
+
|
| 542 |
+
If ``skipkeys`` is false then ``dict`` keys that are not basic types
|
| 543 |
+
(``str``, ``unicode``, ``int``, ``long``, ``float``, ``bool``, ``None``)
|
| 544 |
+
will be skipped instead of raising a ``TypeError``.
|
| 545 |
+
|
| 546 |
+
If ``ensure_ascii`` is false, then the return value will be a
|
| 547 |
+
``unicode`` instance subject to normal Python ``str`` to ``unicode``
|
| 548 |
+
coercion rules instead of being escaped to an ASCII ``str``.
|
| 549 |
+
|
| 550 |
+
If ``check_circular`` is false, then the circular reference check
|
| 551 |
+
for container types will be skipped and a circular reference will
|
| 552 |
+
result in an ``OverflowError`` (or worse).
|
| 553 |
+
|
| 554 |
+
If ``indent`` is a string, then JSON array elements and object members
|
| 555 |
+
will be pretty-printed with a newline followed by that string repeated
|
| 556 |
+
for each level of nesting. ``None`` (the default) selects the most compact
|
| 557 |
+
representation without any newlines. An integer is also accepted
|
| 558 |
+
and is converted to a string with that many spaces.
|
| 559 |
+
|
| 560 |
+
If specified, ``separators`` should be an
|
| 561 |
+
``(item_separator, key_separator)`` tuple. The default is ``(', ', ': ')``
|
| 562 |
+
if *indent* is ``None`` and ``(',', ': ')`` otherwise. To get the most
|
| 563 |
+
compact JSON representation, you should specify ``(',', ':')`` to eliminate
|
| 564 |
+
whitespace.
|
| 565 |
+
|
| 566 |
+
``encoding`` is the character encoding for str instances, default is UTF-8.
|
| 567 |
+
|
| 568 |
+
``default(obj)`` is a function that should return a serializable version
|
| 569 |
+
of obj or raise TypeError. The default simply raises TypeError.
|
| 570 |
+
|
| 571 |
+
If *use_decimal* is true (default: ``True``) then decimal.Decimal
|
| 572 |
+
will be natively serialized to JSON with full precision.
|
| 573 |
+
|
| 574 |
+
If *namedtuple_as_object* is true (default: ``True``),
|
| 575 |
+
:class:`tuple` subclasses with ``_asdict()`` methods will be encoded
|
| 576 |
+
as JSON objects.
|
| 577 |
+
|
| 578 |
+
If *tuple_as_array* is true (default: ``True``),
|
| 579 |
+
:class:`tuple` (and subclasses) will be encoded as JSON arrays.
|
| 580 |
+
|
| 581 |
+
If *bigint_as_string* is true (not the default), ints 2**53 and higher
|
| 582 |
+
or lower than -2**53 will be encoded as strings. This is to avoid the
|
| 583 |
+
rounding that happens in Javascript otherwise.
|
| 584 |
+
|
| 585 |
+
If *int_as_string_bitcount* is a positive number (n), then int of size
|
| 586 |
+
greater than or equal to 2**n or lower than or equal to -2**n will be
|
| 587 |
+
encoded as strings.
|
| 588 |
+
|
| 589 |
+
If specified, *item_sort_key* is a callable used to sort the items in
|
| 590 |
+
each dictionary. This is useful if you want to sort items other than
|
| 591 |
+
in alphabetical order by key. This option takes precendence over
|
| 592 |
+
*sort_keys*.
|
| 593 |
+
|
| 594 |
+
If *sort_keys* is true (default: ``False``), the output of dictionaries
|
| 595 |
+
will be sorted by item.
|
| 596 |
+
|
| 597 |
+
If *for_json* is true (default: ``False``), objects with a ``for_json()``
|
| 598 |
+
method will use the return value of that method for encoding as JSON
|
| 599 |
+
instead of the object.
|
| 600 |
+
|
| 601 |
+
To use a custom ``JSONEncoder`` subclass (e.g. one that overrides the
|
| 602 |
+
``.default()`` method to serialize additional types), specify it with
|
| 603 |
+
the ``cls`` kwarg. NOTE: You should use *default* instead of subclassing
|
| 604 |
+
whenever possible.
|
| 605 |
+
|
| 606 |
+
"""
|
| 607 |
+
# cached encoder
|
| 608 |
+
if (
|
| 609 |
+
not skipkeys and ensure_ascii and
|
| 610 |
+
check_circular and
|
| 611 |
+
cls is None and indent is None and separators is None and
|
| 612 |
+
encoding == 'utf-8' and default is None and use_decimal
|
| 613 |
+
and namedtuple_as_object and tuple_as_array
|
| 614 |
+
and not bigint_as_string and not sort_keys
|
| 615 |
+
and not item_sort_key and not for_json
|
| 616 |
+
and int_as_string_bitcount is None
|
| 617 |
+
and not kw
|
| 618 |
+
):
|
| 619 |
+
return _default_json_encoder.encode(obj)
|
| 620 |
+
if cls is None:
|
| 621 |
+
cls = JSONEncoder
|
| 622 |
+
return cls(
|
| 623 |
+
skipkeys=skipkeys, ensure_ascii=ensure_ascii,
|
| 624 |
+
check_circular=check_circular, indent=indent,
|
| 625 |
+
separators=separators, encoding=encoding, default=default,
|
| 626 |
+
use_decimal=use_decimal,
|
| 627 |
+
namedtuple_as_object=namedtuple_as_object,
|
| 628 |
+
tuple_as_array=tuple_as_array,
|
| 629 |
+
bigint_as_string=bigint_as_string,
|
| 630 |
+
sort_keys=sort_keys,
|
| 631 |
+
item_sort_key=item_sort_key,
|
| 632 |
+
for_json=for_json,
|
| 633 |
+
int_as_string_bitcount=int_as_string_bitcount,
|
| 634 |
+
**kw).encode(obj)
|
| 635 |
+
|
| 636 |
+
|
| 637 |
+
|
| 638 |
+
def simple_first(kv):
|
| 639 |
+
"""Helper function to pass to item_sort_key to sort simple
|
| 640 |
+
elements to the top, then container elements.
|
| 641 |
+
"""
|
| 642 |
+
return (isinstance(kv[1], (list, dict, tuple)), kv[0])
|
parrot/lib/python3.10/site-packages/hjson/compat.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Python 3 compatibility shims
|
| 2 |
+
"""
|
| 3 |
+
import sys
|
| 4 |
+
if sys.version_info[0] < 3:
|
| 5 |
+
PY3 = False
|
| 6 |
+
def b(s):
|
| 7 |
+
return s
|
| 8 |
+
def u(s):
|
| 9 |
+
return unicode(s, 'unicode_escape')
|
| 10 |
+
import cStringIO as StringIO
|
| 11 |
+
StringIO = BytesIO = StringIO.StringIO
|
| 12 |
+
text_type = unicode
|
| 13 |
+
binary_type = str
|
| 14 |
+
string_types = (basestring,)
|
| 15 |
+
integer_types = (int, long)
|
| 16 |
+
unichr = unichr
|
| 17 |
+
reload_module = reload
|
| 18 |
+
def fromhex(s):
|
| 19 |
+
return s.decode('hex')
|
| 20 |
+
|
| 21 |
+
else:
|
| 22 |
+
PY3 = True
|
| 23 |
+
if sys.version_info[:2] >= (3, 4):
|
| 24 |
+
from importlib import reload as reload_module
|
| 25 |
+
else:
|
| 26 |
+
from imp import reload as reload_module
|
| 27 |
+
import codecs
|
| 28 |
+
def b(s):
|
| 29 |
+
return codecs.latin_1_encode(s)[0]
|
| 30 |
+
def u(s):
|
| 31 |
+
return s
|
| 32 |
+
import io
|
| 33 |
+
StringIO = io.StringIO
|
| 34 |
+
BytesIO = io.BytesIO
|
| 35 |
+
text_type = str
|
| 36 |
+
binary_type = bytes
|
| 37 |
+
string_types = (str,)
|
| 38 |
+
integer_types = (int,)
|
| 39 |
+
|
| 40 |
+
def unichr(s):
|
| 41 |
+
return u(chr(s))
|
| 42 |
+
|
| 43 |
+
def fromhex(s):
|
| 44 |
+
return bytes.fromhex(s)
|
| 45 |
+
|
| 46 |
+
long_type = integer_types[-1]
|
parrot/lib/python3.10/site-packages/hjson/decoder.py
ADDED
|
@@ -0,0 +1,569 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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+
from .compat import fromhex, b, u, text_type, binary_type, PY3, unichr
|
| 8 |
+
from .scanner import HjsonDecodeError
|
| 9 |
+
|
| 10 |
+
# NOTE (3.1.0): HjsonDecodeError may still be imported from this module for
|
| 11 |
+
# compatibility, but it was never in the __all__
|
| 12 |
+
__all__ = ['HjsonDecoder']
|
| 13 |
+
|
| 14 |
+
FLAGS = re.VERBOSE | re.MULTILINE | re.DOTALL
|
| 15 |
+
|
| 16 |
+
def _floatconstants():
|
| 17 |
+
_BYTES = fromhex('7FF80000000000007FF0000000000000')
|
| 18 |
+
# The struct module in Python 2.4 would get frexp() out of range here
|
| 19 |
+
# when an endian is specified in the format string. Fixed in Python 2.5+
|
| 20 |
+
if sys.byteorder != 'big':
|
| 21 |
+
_BYTES = _BYTES[:8][::-1] + _BYTES[8:][::-1]
|
| 22 |
+
nan, inf = struct.unpack('dd', _BYTES)
|
| 23 |
+
return nan, inf, -inf
|
| 24 |
+
|
| 25 |
+
NaN, PosInf, NegInf = _floatconstants()
|
| 26 |
+
|
| 27 |
+
WHITESPACE = ' \t\n\r'
|
| 28 |
+
PUNCTUATOR = '{}[],:'
|
| 29 |
+
|
| 30 |
+
NUMBER_RE = re.compile(r'[\t ]*(-?(?:0|[1-9]\d*))(\.\d+)?([eE][-+]?\d+)?[\t ]*')
|
| 31 |
+
STRINGCHUNK = re.compile(r'(.*?)([\'"\\\x00-\x1f])', FLAGS)
|
| 32 |
+
BACKSLASH = {
|
| 33 |
+
'"': u('"'), '\'': u('\''), '\\': u('\u005c'), '/': u('/'),
|
| 34 |
+
'b': u('\b'), 'f': u('\f'), 'n': u('\n'), 'r': u('\r'), 't': u('\t'),
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
DEFAULT_ENCODING = "utf-8"
|
| 38 |
+
|
| 39 |
+
def getNext(s, end):
|
| 40 |
+
while 1:
|
| 41 |
+
# Use a slice to prevent IndexError from being raised
|
| 42 |
+
ch = s[end:end + 1]
|
| 43 |
+
# Skip whitespace.
|
| 44 |
+
while ch in WHITESPACE:
|
| 45 |
+
if ch == '': return ch, end
|
| 46 |
+
end += 1
|
| 47 |
+
ch = s[end:end + 1]
|
| 48 |
+
|
| 49 |
+
# Hjson allows comments
|
| 50 |
+
ch2 = s[end + 1:end + 2]
|
| 51 |
+
if ch == '#' or ch == '/' and ch2 == '/':
|
| 52 |
+
end = getEol(s, end)
|
| 53 |
+
elif ch == '/' and ch2 == '*':
|
| 54 |
+
end += 2
|
| 55 |
+
ch = s[end]
|
| 56 |
+
while ch != '' and not (ch == '*' and s[end + 1] == '/'):
|
| 57 |
+
end += 1
|
| 58 |
+
ch = s[end]
|
| 59 |
+
if ch != '':
|
| 60 |
+
end += 2
|
| 61 |
+
else:
|
| 62 |
+
break
|
| 63 |
+
|
| 64 |
+
return ch, end
|
| 65 |
+
|
| 66 |
+
def getEol(s, end):
|
| 67 |
+
# skip until eol
|
| 68 |
+
|
| 69 |
+
while 1:
|
| 70 |
+
ch = s[end:end + 1]
|
| 71 |
+
if ch == '\r' or ch == '\n' or ch == '':
|
| 72 |
+
return end
|
| 73 |
+
end += 1
|
| 74 |
+
|
| 75 |
+
def skipIndent(s, end, n):
|
| 76 |
+
ch = s[end:end + 1]
|
| 77 |
+
while ch != '' and ch in " \t\r" and (n > 0 or n < 0):
|
| 78 |
+
end += 1
|
| 79 |
+
n -= 1
|
| 80 |
+
ch = s[end:end + 1]
|
| 81 |
+
return end
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def scanstring(s, end, encoding=None, strict=True,
|
| 85 |
+
_b=BACKSLASH, _m=STRINGCHUNK.match, _join=u('').join,
|
| 86 |
+
_PY3=PY3, _maxunicode=sys.maxunicode):
|
| 87 |
+
"""Scan the string s for a JSON string. End is the index of the
|
| 88 |
+
character in s after the quote that started the JSON string.
|
| 89 |
+
Unescapes all valid JSON string escape sequences and raises ValueError
|
| 90 |
+
on attempt to decode an invalid string. If strict is False then literal
|
| 91 |
+
control characters are allowed in the string.
|
| 92 |
+
|
| 93 |
+
Returns a tuple of the decoded string and the index of the character in s
|
| 94 |
+
after the end quote."""
|
| 95 |
+
if encoding is None:
|
| 96 |
+
encoding = DEFAULT_ENCODING
|
| 97 |
+
chunks = []
|
| 98 |
+
_append = chunks.append
|
| 99 |
+
begin = end - 1
|
| 100 |
+
# callers make sure that string starts with " or '
|
| 101 |
+
exitCh = s[begin]
|
| 102 |
+
while 1:
|
| 103 |
+
chunk = _m(s, end)
|
| 104 |
+
if chunk is None:
|
| 105 |
+
raise HjsonDecodeError(
|
| 106 |
+
"Unterminated string starting at", s, begin)
|
| 107 |
+
end = chunk.end()
|
| 108 |
+
content, terminator = chunk.groups()
|
| 109 |
+
# Content is contains zero or more unescaped string characters
|
| 110 |
+
if content:
|
| 111 |
+
if not _PY3 and not isinstance(content, text_type):
|
| 112 |
+
content = text_type(content, encoding)
|
| 113 |
+
_append(content)
|
| 114 |
+
# Terminator is the end of string, a literal control character,
|
| 115 |
+
# or a backslash denoting that an escape sequence follows
|
| 116 |
+
if terminator == exitCh:
|
| 117 |
+
break
|
| 118 |
+
elif terminator == '"' or terminator == '\'':
|
| 119 |
+
_append(terminator)
|
| 120 |
+
continue
|
| 121 |
+
elif terminator != '\\':
|
| 122 |
+
if strict:
|
| 123 |
+
msg = "Invalid control character %r at"
|
| 124 |
+
raise HjsonDecodeError(msg, s, end)
|
| 125 |
+
else:
|
| 126 |
+
_append(terminator)
|
| 127 |
+
continue
|
| 128 |
+
try:
|
| 129 |
+
esc = s[end]
|
| 130 |
+
except IndexError:
|
| 131 |
+
raise HjsonDecodeError(
|
| 132 |
+
"Unterminated string starting at", s, begin)
|
| 133 |
+
# If not a unicode escape sequence, must be in the lookup table
|
| 134 |
+
if esc != 'u':
|
| 135 |
+
try:
|
| 136 |
+
char = _b[esc]
|
| 137 |
+
except KeyError:
|
| 138 |
+
msg = "Invalid \\X escape sequence %r"
|
| 139 |
+
raise HjsonDecodeError(msg, s, end)
|
| 140 |
+
end += 1
|
| 141 |
+
else:
|
| 142 |
+
# Unicode escape sequence
|
| 143 |
+
msg = "Invalid \\uXXXX escape sequence"
|
| 144 |
+
esc = s[end + 1:end + 5]
|
| 145 |
+
escX = esc[1:2]
|
| 146 |
+
if len(esc) != 4 or escX == 'x' or escX == 'X':
|
| 147 |
+
raise HjsonDecodeError(msg, s, end - 1)
|
| 148 |
+
try:
|
| 149 |
+
uni = int(esc, 16)
|
| 150 |
+
except ValueError:
|
| 151 |
+
raise HjsonDecodeError(msg, s, end - 1)
|
| 152 |
+
end += 5
|
| 153 |
+
# Check for surrogate pair on UCS-4 systems
|
| 154 |
+
# Note that this will join high/low surrogate pairs
|
| 155 |
+
# but will also pass unpaired surrogates through
|
| 156 |
+
if (_maxunicode > 65535 and
|
| 157 |
+
uni & 0xfc00 == 0xd800 and
|
| 158 |
+
s[end:end + 2] == '\\u'):
|
| 159 |
+
esc2 = s[end + 2:end + 6]
|
| 160 |
+
escX = esc2[1:2]
|
| 161 |
+
if len(esc2) == 4 and not (escX == 'x' or escX == 'X'):
|
| 162 |
+
try:
|
| 163 |
+
uni2 = int(esc2, 16)
|
| 164 |
+
except ValueError:
|
| 165 |
+
raise HjsonDecodeError(msg, s, end)
|
| 166 |
+
if uni2 & 0xfc00 == 0xdc00:
|
| 167 |
+
uni = 0x10000 + (((uni - 0xd800) << 10) |
|
| 168 |
+
(uni2 - 0xdc00))
|
| 169 |
+
end += 6
|
| 170 |
+
char = unichr(uni)
|
| 171 |
+
# Append the unescaped character
|
| 172 |
+
_append(char)
|
| 173 |
+
return _join(chunks), end
|
| 174 |
+
|
| 175 |
+
def mlscanstring(s, end):
|
| 176 |
+
"""Scan a multiline string"""
|
| 177 |
+
|
| 178 |
+
string = ""
|
| 179 |
+
triple = 0
|
| 180 |
+
|
| 181 |
+
# we are at ''' - get indent
|
| 182 |
+
indent = 0
|
| 183 |
+
while 1:
|
| 184 |
+
ch = s[end-indent-1]
|
| 185 |
+
if ch == '\n': break
|
| 186 |
+
indent += 1
|
| 187 |
+
|
| 188 |
+
# skip white/to (newline)
|
| 189 |
+
end = skipIndent(s, end + 3, -1)
|
| 190 |
+
|
| 191 |
+
ch = s[end]
|
| 192 |
+
if ch == '\n': end = skipIndent(s, end + 1, indent)
|
| 193 |
+
|
| 194 |
+
# When parsing multiline string values, we must look for ' characters
|
| 195 |
+
while 1:
|
| 196 |
+
ch = s[end:end + 1]
|
| 197 |
+
if ch == '':
|
| 198 |
+
raise HjsonDecodeError("Bad multiline string", s, end);
|
| 199 |
+
elif ch == '\'':
|
| 200 |
+
triple += 1
|
| 201 |
+
end += 1
|
| 202 |
+
if triple == 3:
|
| 203 |
+
if string and string[-1] == '\n':
|
| 204 |
+
string = string[:-1] # remove last EOL
|
| 205 |
+
return string, end
|
| 206 |
+
else:
|
| 207 |
+
continue
|
| 208 |
+
else:
|
| 209 |
+
while triple > 0:
|
| 210 |
+
string += '\''
|
| 211 |
+
triple -= 1
|
| 212 |
+
|
| 213 |
+
if ch == '\n':
|
| 214 |
+
string += ch
|
| 215 |
+
end = skipIndent(s, end + 1, indent)
|
| 216 |
+
else:
|
| 217 |
+
if ch != '\r':
|
| 218 |
+
string += ch
|
| 219 |
+
end += 1
|
| 220 |
+
|
| 221 |
+
def scantfnns(context, s, end):
|
| 222 |
+
"""Scan s until eol. return string, True, False or None"""
|
| 223 |
+
|
| 224 |
+
chf, begin = getNext(s, end)
|
| 225 |
+
end = begin
|
| 226 |
+
|
| 227 |
+
if chf in PUNCTUATOR:
|
| 228 |
+
raise HjsonDecodeError("Found a punctuator character when expecting a quoteless string (check your syntax)", s, end);
|
| 229 |
+
|
| 230 |
+
while 1:
|
| 231 |
+
ch = s[end:end + 1]
|
| 232 |
+
|
| 233 |
+
isEol = ch == '\r' or ch == '\n' or ch == ''
|
| 234 |
+
if isEol or ch == ',' or \
|
| 235 |
+
ch == '}' or ch == ']' or \
|
| 236 |
+
ch == '#' or \
|
| 237 |
+
ch == '/' and (s[end + 1:end + 2] == '/' or s[end + 1:end + 2] == '*'):
|
| 238 |
+
|
| 239 |
+
m = None
|
| 240 |
+
mend = end
|
| 241 |
+
if next: mend -= 1
|
| 242 |
+
|
| 243 |
+
if chf == 'n' and s[begin:end].strip() == 'null':
|
| 244 |
+
return None, end
|
| 245 |
+
elif chf == 't' and s[begin:end].strip() == 'true':
|
| 246 |
+
return True, end
|
| 247 |
+
elif chf == 'f' and s[begin:end].strip() == 'false':
|
| 248 |
+
return False, end
|
| 249 |
+
elif chf == '-' or chf >= '0' and chf <= '9':
|
| 250 |
+
m = NUMBER_RE.match(s, begin)
|
| 251 |
+
|
| 252 |
+
if m is not None and m.end() == end:
|
| 253 |
+
integer, frac, exp = m.groups()
|
| 254 |
+
if frac or exp:
|
| 255 |
+
res = context.parse_float(integer + (frac or '') + (exp or ''))
|
| 256 |
+
if int(res) == res and abs(res)<1e10: res = int(res)
|
| 257 |
+
else:
|
| 258 |
+
res = context.parse_int(integer)
|
| 259 |
+
return res, end
|
| 260 |
+
|
| 261 |
+
if isEol:
|
| 262 |
+
return s[begin:end].strip(), end
|
| 263 |
+
|
| 264 |
+
end += 1
|
| 265 |
+
|
| 266 |
+
def scanKeyName(s, end, encoding=None, strict=True):
|
| 267 |
+
"""Scan the string s for a JSON/Hjson key. see scanstring"""
|
| 268 |
+
|
| 269 |
+
ch, end = getNext(s, end)
|
| 270 |
+
|
| 271 |
+
if ch == '"' or ch == '\'':
|
| 272 |
+
return scanstring(s, end + 1, encoding, strict)
|
| 273 |
+
|
| 274 |
+
begin = end
|
| 275 |
+
space = -1
|
| 276 |
+
while 1:
|
| 277 |
+
ch = s[end:end + 1]
|
| 278 |
+
|
| 279 |
+
if ch == '':
|
| 280 |
+
raise HjsonDecodeError("Bad key name (eof)", s, end);
|
| 281 |
+
elif ch == ':':
|
| 282 |
+
if begin == end:
|
| 283 |
+
raise HjsonDecodeError("Found ':' but no key name (for an empty key name use quotes)", s, begin)
|
| 284 |
+
elif space >= 0:
|
| 285 |
+
if space != end - 1: raise HjsonDecodeError("Found whitespace in your key name (use quotes to include)", s, space)
|
| 286 |
+
return s[begin:end].rstrip(), end
|
| 287 |
+
else:
|
| 288 |
+
return s[begin:end], end
|
| 289 |
+
elif ch in WHITESPACE:
|
| 290 |
+
if space < 0 or space == end - 1: space = end
|
| 291 |
+
elif ch == '{' or ch == '}' or ch == '[' or ch == ']' or ch == ',':
|
| 292 |
+
raise HjsonDecodeError("Found '" + ch + "' where a key name was expected (check your syntax or use quotes if the key name includes {}[],: or whitespace)", s, begin)
|
| 293 |
+
end += 1
|
| 294 |
+
|
| 295 |
+
def make_scanner(context):
|
| 296 |
+
parse_object = context.parse_object
|
| 297 |
+
parse_array = context.parse_array
|
| 298 |
+
parse_string = context.parse_string
|
| 299 |
+
parse_mlstring = context.parse_mlstring
|
| 300 |
+
parse_tfnns = context.parse_tfnns
|
| 301 |
+
encoding = context.encoding
|
| 302 |
+
strict = context.strict
|
| 303 |
+
object_hook = context.object_hook
|
| 304 |
+
object_pairs_hook = context.object_pairs_hook
|
| 305 |
+
memo = context.memo
|
| 306 |
+
|
| 307 |
+
def _scan_once(string, idx):
|
| 308 |
+
try:
|
| 309 |
+
ch = string[idx]
|
| 310 |
+
except IndexError:
|
| 311 |
+
raise HjsonDecodeError('Expecting value', string, idx)
|
| 312 |
+
|
| 313 |
+
if ch == '"' or ch == '\'':
|
| 314 |
+
if string[idx:idx + 3] == '\'\'\'':
|
| 315 |
+
return parse_mlstring(string, idx)
|
| 316 |
+
else:
|
| 317 |
+
return parse_string(string, idx + 1, encoding, strict)
|
| 318 |
+
elif ch == '{':
|
| 319 |
+
return parse_object((string, idx + 1), encoding, strict,
|
| 320 |
+
_scan_once, object_hook, object_pairs_hook, memo)
|
| 321 |
+
elif ch == '[':
|
| 322 |
+
return parse_array((string, idx + 1), _scan_once)
|
| 323 |
+
|
| 324 |
+
return parse_tfnns(context, string, idx)
|
| 325 |
+
|
| 326 |
+
def scan_once(string, idx):
|
| 327 |
+
if idx < 0: raise HjsonDecodeError('Expecting value', string, idx)
|
| 328 |
+
try:
|
| 329 |
+
return _scan_once(string, idx)
|
| 330 |
+
finally:
|
| 331 |
+
memo.clear()
|
| 332 |
+
|
| 333 |
+
def scan_object_once(string, idx):
|
| 334 |
+
if idx < 0: raise HjsonDecodeError('Expecting value', string, idx)
|
| 335 |
+
try:
|
| 336 |
+
return parse_object((string, idx), encoding, strict,
|
| 337 |
+
_scan_once, object_hook, object_pairs_hook, memo, True)
|
| 338 |
+
finally:
|
| 339 |
+
memo.clear()
|
| 340 |
+
|
| 341 |
+
return scan_once, scan_object_once
|
| 342 |
+
|
| 343 |
+
|
| 344 |
+
def JSONObject(state, encoding, strict, scan_once, object_hook,
|
| 345 |
+
object_pairs_hook, memo=None, objectWithoutBraces=False):
|
| 346 |
+
(s, end) = state
|
| 347 |
+
# Backwards compatibility
|
| 348 |
+
if memo is None:
|
| 349 |
+
memo = {}
|
| 350 |
+
memo_get = memo.setdefault
|
| 351 |
+
pairs = []
|
| 352 |
+
|
| 353 |
+
ch, end = getNext(s, end)
|
| 354 |
+
|
| 355 |
+
# Trivial empty object
|
| 356 |
+
if not objectWithoutBraces and ch == '}':
|
| 357 |
+
if object_pairs_hook is not None:
|
| 358 |
+
result = object_pairs_hook(pairs)
|
| 359 |
+
return result, end + 1
|
| 360 |
+
pairs = {}
|
| 361 |
+
if object_hook is not None:
|
| 362 |
+
pairs = object_hook(pairs)
|
| 363 |
+
return pairs, end + 1
|
| 364 |
+
|
| 365 |
+
while True:
|
| 366 |
+
key, end = scanKeyName(s, end, encoding, strict)
|
| 367 |
+
key = memo_get(key, key)
|
| 368 |
+
|
| 369 |
+
ch, end = getNext(s, end)
|
| 370 |
+
if ch != ':':
|
| 371 |
+
raise HjsonDecodeError("Expecting ':' delimiter", s, end)
|
| 372 |
+
|
| 373 |
+
ch, end = getNext(s, end + 1)
|
| 374 |
+
|
| 375 |
+
value, end = scan_once(s, end)
|
| 376 |
+
pairs.append((key, value))
|
| 377 |
+
|
| 378 |
+
ch, end = getNext(s, end)
|
| 379 |
+
|
| 380 |
+
if ch == ',':
|
| 381 |
+
ch, end = getNext(s, end + 1)
|
| 382 |
+
|
| 383 |
+
if objectWithoutBraces:
|
| 384 |
+
if ch == '': break;
|
| 385 |
+
else:
|
| 386 |
+
if ch == '}':
|
| 387 |
+
end += 1
|
| 388 |
+
break
|
| 389 |
+
|
| 390 |
+
ch, end = getNext(s, end)
|
| 391 |
+
|
| 392 |
+
if object_pairs_hook is not None:
|
| 393 |
+
result = object_pairs_hook(pairs)
|
| 394 |
+
return result, end
|
| 395 |
+
pairs = dict(pairs)
|
| 396 |
+
if object_hook is not None:
|
| 397 |
+
pairs = object_hook(pairs)
|
| 398 |
+
return pairs, end
|
| 399 |
+
|
| 400 |
+
def JSONArray(state, scan_once):
|
| 401 |
+
(s, end) = state
|
| 402 |
+
values = []
|
| 403 |
+
|
| 404 |
+
ch, end = getNext(s, end)
|
| 405 |
+
|
| 406 |
+
# Look-ahead for trivial empty array
|
| 407 |
+
if ch == ']':
|
| 408 |
+
return values, end + 1
|
| 409 |
+
elif ch == '':
|
| 410 |
+
raise HjsonDecodeError("End of input while parsing an array (did you forget a closing ']'?)", s, end)
|
| 411 |
+
_append = values.append
|
| 412 |
+
while True:
|
| 413 |
+
value, end = scan_once(s, end)
|
| 414 |
+
_append(value)
|
| 415 |
+
|
| 416 |
+
ch, end = getNext(s, end)
|
| 417 |
+
if ch == ',':
|
| 418 |
+
ch, end = getNext(s, end + 1)
|
| 419 |
+
|
| 420 |
+
if ch == ']':
|
| 421 |
+
end += 1
|
| 422 |
+
break
|
| 423 |
+
|
| 424 |
+
ch, end = getNext(s, end)
|
| 425 |
+
|
| 426 |
+
return values, end
|
| 427 |
+
|
| 428 |
+
|
| 429 |
+
class HjsonDecoder(object):
|
| 430 |
+
"""Hjson decoder
|
| 431 |
+
|
| 432 |
+
Performs the following translations in decoding by default:
|
| 433 |
+
|
| 434 |
+
+---------------+-------------------+
|
| 435 |
+
| JSON | Python |
|
| 436 |
+
+===============+===================+
|
| 437 |
+
| object | dict |
|
| 438 |
+
+---------------+-------------------+
|
| 439 |
+
| array | list |
|
| 440 |
+
+---------------+-------------------+
|
| 441 |
+
| string | str, unicode |
|
| 442 |
+
+---------------+-------------------+
|
| 443 |
+
| number (int) | int, long |
|
| 444 |
+
+---------------+-------------------+
|
| 445 |
+
| number (real) | float |
|
| 446 |
+
+---------------+-------------------+
|
| 447 |
+
| true | True |
|
| 448 |
+
+---------------+-------------------+
|
| 449 |
+
| false | False |
|
| 450 |
+
+---------------+-------------------+
|
| 451 |
+
| null | None |
|
| 452 |
+
+---------------+-------------------+
|
| 453 |
+
|
| 454 |
+
"""
|
| 455 |
+
|
| 456 |
+
def __init__(self, encoding=None, object_hook=None, parse_float=None,
|
| 457 |
+
parse_int=None, strict=True,
|
| 458 |
+
object_pairs_hook=None):
|
| 459 |
+
"""
|
| 460 |
+
*encoding* determines the encoding used to interpret any
|
| 461 |
+
:class:`str` objects decoded by this instance (``'utf-8'`` by
|
| 462 |
+
default). It has no effect when decoding :class:`unicode` objects.
|
| 463 |
+
|
| 464 |
+
Note that currently only encodings that are a superset of ASCII work,
|
| 465 |
+
strings of other encodings should be passed in as :class:`unicode`.
|
| 466 |
+
|
| 467 |
+
*object_hook*, if specified, will be called with the result of every
|
| 468 |
+
JSON object decoded and its return value will be used in place of the
|
| 469 |
+
given :class:`dict`. This can be used to provide custom
|
| 470 |
+
deserializations (e.g. to support JSON-RPC class hinting).
|
| 471 |
+
|
| 472 |
+
*object_pairs_hook* is an optional function that will be called with
|
| 473 |
+
the result of any object literal decode with an ordered list of pairs.
|
| 474 |
+
The return value of *object_pairs_hook* will be used instead of the
|
| 475 |
+
:class:`dict`. This feature can be used to implement custom decoders
|
| 476 |
+
that rely on the order that the key and value pairs are decoded (for
|
| 477 |
+
example, :func:`collections.OrderedDict` will remember the order of
|
| 478 |
+
insertion). If *object_hook* is also defined, the *object_pairs_hook*
|
| 479 |
+
takes priority.
|
| 480 |
+
|
| 481 |
+
*parse_float*, if specified, will be called with the string of every
|
| 482 |
+
JSON float to be decoded. By default, this is equivalent to
|
| 483 |
+
``float(num_str)``. This can be used to use another datatype or parser
|
| 484 |
+
for JSON floats (e.g. :class:`decimal.Decimal`).
|
| 485 |
+
|
| 486 |
+
*parse_int*, if specified, will be called with the string of every
|
| 487 |
+
JSON int to be decoded. By default, this is equivalent to
|
| 488 |
+
``int(num_str)``. This can be used to use another datatype or parser
|
| 489 |
+
for JSON integers (e.g. :class:`float`).
|
| 490 |
+
|
| 491 |
+
*strict* controls the parser's behavior when it encounters an
|
| 492 |
+
invalid control character in a string. The default setting of
|
| 493 |
+
``True`` means that unescaped control characters are parse errors, if
|
| 494 |
+
``False`` then control characters will be allowed in strings.
|
| 495 |
+
|
| 496 |
+
"""
|
| 497 |
+
if encoding is None:
|
| 498 |
+
encoding = DEFAULT_ENCODING
|
| 499 |
+
self.encoding = encoding
|
| 500 |
+
self.object_hook = object_hook
|
| 501 |
+
self.object_pairs_hook = object_pairs_hook
|
| 502 |
+
self.parse_float = parse_float or float
|
| 503 |
+
self.parse_int = parse_int or int
|
| 504 |
+
self.strict = strict
|
| 505 |
+
self.parse_object = JSONObject
|
| 506 |
+
self.parse_array = JSONArray
|
| 507 |
+
self.parse_string = scanstring
|
| 508 |
+
self.parse_mlstring = mlscanstring
|
| 509 |
+
self.parse_tfnns = scantfnns
|
| 510 |
+
self.memo = {}
|
| 511 |
+
(self.scan_once, self.scan_object_once) = make_scanner(self)
|
| 512 |
+
|
| 513 |
+
def decode(self, s, _PY3=PY3):
|
| 514 |
+
"""Return the Python representation of ``s`` (a ``str`` or ``unicode``
|
| 515 |
+
instance containing a JSON document)
|
| 516 |
+
|
| 517 |
+
"""
|
| 518 |
+
if _PY3 and isinstance(s, binary_type):
|
| 519 |
+
s = s.decode(self.encoding)
|
| 520 |
+
obj, end = self.raw_decode(s)
|
| 521 |
+
ch, end = getNext(s, end)
|
| 522 |
+
if end != len(s):
|
| 523 |
+
raise HjsonDecodeError("Extra data", s, end, len(s))
|
| 524 |
+
return obj
|
| 525 |
+
|
| 526 |
+
def raw_decode(self, s, idx=0, _PY3=PY3):
|
| 527 |
+
"""Decode a JSON document from ``s`` (a ``str`` or ``unicode``
|
| 528 |
+
beginning with a JSON document) and return a 2-tuple of the Python
|
| 529 |
+
representation and the index in ``s`` where the document ended.
|
| 530 |
+
Optionally, ``idx`` can be used to specify an offset in ``s`` where
|
| 531 |
+
the JSON document begins.
|
| 532 |
+
|
| 533 |
+
This can be used to decode a JSON document from a string that may
|
| 534 |
+
have extraneous data at the end.
|
| 535 |
+
|
| 536 |
+
"""
|
| 537 |
+
if idx < 0:
|
| 538 |
+
# Ensure that raw_decode bails on negative indexes, the regex
|
| 539 |
+
# would otherwise mask this behavior. #98
|
| 540 |
+
raise HjsonDecodeError('Expecting value', s, idx)
|
| 541 |
+
if _PY3 and not isinstance(s, text_type):
|
| 542 |
+
raise TypeError("Input string must be text")
|
| 543 |
+
# strip UTF-8 bom
|
| 544 |
+
if len(s) > idx:
|
| 545 |
+
ord0 = ord(s[idx])
|
| 546 |
+
if ord0 == 0xfeff:
|
| 547 |
+
idx += 1
|
| 548 |
+
elif ord0 == 0xef and s[idx:idx + 3] == '\xef\xbb\xbf':
|
| 549 |
+
idx += 3
|
| 550 |
+
|
| 551 |
+
start_index = idx
|
| 552 |
+
ch, idx = getNext(s, idx)
|
| 553 |
+
|
| 554 |
+
# If blank or comment only file, return dict
|
| 555 |
+
if start_index == 0 and ch == '':
|
| 556 |
+
return {}, 0
|
| 557 |
+
|
| 558 |
+
if ch == '{' or ch == '[':
|
| 559 |
+
return self.scan_once(s, idx)
|
| 560 |
+
else:
|
| 561 |
+
# assume we have a root object without braces
|
| 562 |
+
try:
|
| 563 |
+
return self.scan_object_once(s, idx)
|
| 564 |
+
except HjsonDecodeError as e:
|
| 565 |
+
# test if we are dealing with a single JSON value instead (true/false/null/num/"")
|
| 566 |
+
try:
|
| 567 |
+
return self.scan_once(s, idx)
|
| 568 |
+
except:
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Implementation of HjsonEncoder
|
| 2 |
+
"""
|
| 3 |
+
from __future__ import absolute_import
|
| 4 |
+
import re
|
| 5 |
+
from operator import itemgetter
|
| 6 |
+
from decimal import Decimal
|
| 7 |
+
from .compat import u, unichr, binary_type, string_types, integer_types, PY3
|
| 8 |
+
from .decoder import PosInf
|
| 9 |
+
|
| 10 |
+
# This is required because u() will mangle the string and ur'' isn't valid
|
| 11 |
+
# python3 syntax
|
| 12 |
+
ESCAPE = re.compile(u'[\\x00-\\x1f\\\\"\\b\\f\\n\\r\\t\u2028\u2029\uffff]')
|
| 13 |
+
ESCAPE_ASCII = re.compile(r'([\\"]|[^\ -~])')
|
| 14 |
+
HAS_UTF8 = re.compile(r'[\x80-\xff]')
|
| 15 |
+
ESCAPE_DCT = {
|
| 16 |
+
'\\': '\\\\',
|
| 17 |
+
'"': '\\"',
|
| 18 |
+
'\b': '\\b',
|
| 19 |
+
'\f': '\\f',
|
| 20 |
+
'\n': '\\n',
|
| 21 |
+
'\r': '\\r',
|
| 22 |
+
'\t': '\\t',
|
| 23 |
+
}
|
| 24 |
+
for i in range(0x20):
|
| 25 |
+
#ESCAPE_DCT.setdefault(chr(i), '\\u{0:04x}'.format(i))
|
| 26 |
+
ESCAPE_DCT.setdefault(chr(i), '\\u%04x' % (i,))
|
| 27 |
+
for i in [0x2028, 0x2029, 0xffff]:
|
| 28 |
+
ESCAPE_DCT.setdefault(unichr(i), '\\u%04x' % (i,))
|
| 29 |
+
|
| 30 |
+
COMMONRANGE=u'\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff'
|
| 31 |
+
|
| 32 |
+
# NEEDSESCAPE tests if the string can be written without escapes
|
| 33 |
+
NEEDSESCAPE = re.compile(u'[\\\"\x00-\x1f'+COMMONRANGE+']')
|
| 34 |
+
# NEEDSQUOTES tests if the string can be written as a quoteless string (like needsEscape but without \\ and \")
|
| 35 |
+
NEEDSQUOTES = re.compile(u'^\\s|^"|^\'|^#|^\\/\\*|^\\/\\/|^\\{|^\\}|^\\[|^\\]|^:|^,|\\s$|[\x00-\x1f'+COMMONRANGE+u']')
|
| 36 |
+
# NEEDSESCAPEML tests if the string can be written as a multiline string (like needsEscape but without \n, \r, \\, \", \t)
|
| 37 |
+
NEEDSESCAPEML = re.compile(u'\'\'\'|^[\\s]+$|[\x00-\x08\x0b\x0c\x0e-\x1f'+COMMONRANGE+u']')
|
| 38 |
+
|
| 39 |
+
WHITESPACE = ' \t\n\r'
|
| 40 |
+
STARTSWITHNUMBER = re.compile(r'^[\t ]*(-?(?:0|[1-9]\d*))(\.\d+)?([eE][-+]?\d+)?\s*((,|\]|\}|#|\/\/|\/\*).*)?$');
|
| 41 |
+
STARTSWITHKEYWORD = re.compile(r'^(true|false|null)\s*((,|\]|\}|#|\/\/|\/\*).*)?$');
|
| 42 |
+
NEEDSESCAPENAME = re.compile(r'[,\{\[\}\]\s:#"\']|\/\/|\/\*|'+"'''")
|
| 43 |
+
|
| 44 |
+
FLOAT_REPR = repr
|
| 45 |
+
|
| 46 |
+
def encode_basestring(s, _PY3=PY3, _q=u('"')):
|
| 47 |
+
"""Return a JSON representation of a Python string
|
| 48 |
+
|
| 49 |
+
"""
|
| 50 |
+
if _PY3:
|
| 51 |
+
if isinstance(s, binary_type):
|
| 52 |
+
s = s.decode('utf-8')
|
| 53 |
+
else:
|
| 54 |
+
if isinstance(s, str) and HAS_UTF8.search(s) is not None:
|
| 55 |
+
s = s.decode('utf-8')
|
| 56 |
+
def replace(match):
|
| 57 |
+
return ESCAPE_DCT[match.group(0)]
|
| 58 |
+
return _q + ESCAPE.sub(replace, s) + _q
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def encode_basestring_ascii(s, _PY3=PY3):
|
| 62 |
+
"""Return an ASCII-only JSON representation of a Python string
|
| 63 |
+
|
| 64 |
+
"""
|
| 65 |
+
if _PY3:
|
| 66 |
+
if isinstance(s, binary_type):
|
| 67 |
+
s = s.decode('utf-8')
|
| 68 |
+
else:
|
| 69 |
+
if isinstance(s, str) and HAS_UTF8.search(s) is not None:
|
| 70 |
+
s = s.decode('utf-8')
|
| 71 |
+
def replace(match):
|
| 72 |
+
s = match.group(0)
|
| 73 |
+
try:
|
| 74 |
+
return ESCAPE_DCT[s]
|
| 75 |
+
except KeyError:
|
| 76 |
+
n = ord(s)
|
| 77 |
+
if n < 0x10000:
|
| 78 |
+
#return '\\u{0:04x}'.format(n)
|
| 79 |
+
return '\\u%04x' % (n,)
|
| 80 |
+
else:
|
| 81 |
+
# surrogate pair
|
| 82 |
+
n -= 0x10000
|
| 83 |
+
s1 = 0xd800 | ((n >> 10) & 0x3ff)
|
| 84 |
+
s2 = 0xdc00 | (n & 0x3ff)
|
| 85 |
+
#return '\\u{0:04x}\\u{1:04x}'.format(s1, s2)
|
| 86 |
+
return '\\u%04x\\u%04x' % (s1, s2)
|
| 87 |
+
return '"' + str(ESCAPE_ASCII.sub(replace, s)) + '"'
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
class HjsonEncoder(object):
|
| 91 |
+
"""Extensible JSON <http://json.org> encoder for Python data structures.
|
| 92 |
+
|
| 93 |
+
Supports the following objects and types by default:
|
| 94 |
+
|
| 95 |
+
+-------------------+---------------+
|
| 96 |
+
| Python | JSON |
|
| 97 |
+
+===================+===============+
|
| 98 |
+
| dict, namedtuple | object |
|
| 99 |
+
+-------------------+---------------+
|
| 100 |
+
| list, tuple | array |
|
| 101 |
+
+-------------------+---------------+
|
| 102 |
+
| str, unicode | string |
|
| 103 |
+
+-------------------+---------------+
|
| 104 |
+
| int, long, float | number |
|
| 105 |
+
+-------------------+---------------+
|
| 106 |
+
| True | true |
|
| 107 |
+
+-------------------+---------------+
|
| 108 |
+
| False | false |
|
| 109 |
+
+-------------------+---------------+
|
| 110 |
+
| None | null |
|
| 111 |
+
+-------------------+---------------+
|
| 112 |
+
|
| 113 |
+
To extend this to recognize other objects, subclass and implement a
|
| 114 |
+
``.default()`` method with another method that returns a serializable
|
| 115 |
+
object for ``o`` if possible, otherwise it should call the superclass
|
| 116 |
+
implementation (to raise ``TypeError``).
|
| 117 |
+
|
| 118 |
+
"""
|
| 119 |
+
|
| 120 |
+
def __init__(self, skipkeys=False, ensure_ascii=True,
|
| 121 |
+
check_circular=True, sort_keys=False,
|
| 122 |
+
indent=' ', encoding='utf-8', default=None,
|
| 123 |
+
use_decimal=True, namedtuple_as_object=True,
|
| 124 |
+
tuple_as_array=True, bigint_as_string=False,
|
| 125 |
+
item_sort_key=None, for_json=False,
|
| 126 |
+
int_as_string_bitcount=None):
|
| 127 |
+
"""Constructor for HjsonEncoder, with sensible defaults.
|
| 128 |
+
|
| 129 |
+
If skipkeys is false, then it is a TypeError to attempt
|
| 130 |
+
encoding of keys that are not str, int, long, float or None. If
|
| 131 |
+
skipkeys is True, such items are simply skipped.
|
| 132 |
+
|
| 133 |
+
If ensure_ascii is true, the output is guaranteed to be str
|
| 134 |
+
objects with all incoming unicode characters escaped. If
|
| 135 |
+
ensure_ascii is false, the output will be unicode object.
|
| 136 |
+
|
| 137 |
+
If check_circular is true, then lists, dicts, and custom encoded
|
| 138 |
+
objects will be checked for circular references during encoding to
|
| 139 |
+
prevent an infinite recursion (which would cause an OverflowError).
|
| 140 |
+
Otherwise, no such check takes place.
|
| 141 |
+
|
| 142 |
+
If sort_keys is true, then the output of dictionaries will be
|
| 143 |
+
sorted by key; this is useful for regression tests to ensure
|
| 144 |
+
that JSON serializations can be compared on a day-to-day basis.
|
| 145 |
+
|
| 146 |
+
If indent is a string, then JSON array elements and object members
|
| 147 |
+
will be pretty-printed with a newline followed by that string repeated
|
| 148 |
+
for each level of nesting.
|
| 149 |
+
|
| 150 |
+
If specified, default is a function that gets called for objects
|
| 151 |
+
that can't otherwise be serialized. It should return a JSON encodable
|
| 152 |
+
version of the object or raise a ``TypeError``.
|
| 153 |
+
|
| 154 |
+
If encoding is not None, then all input strings will be
|
| 155 |
+
transformed into unicode using that encoding prior to JSON-encoding.
|
| 156 |
+
The default is UTF-8.
|
| 157 |
+
|
| 158 |
+
If use_decimal is true (not the default), ``decimal.Decimal`` will
|
| 159 |
+
be supported directly by the encoder. For the inverse, decode JSON
|
| 160 |
+
with ``parse_float=decimal.Decimal``.
|
| 161 |
+
|
| 162 |
+
If namedtuple_as_object is true (the default), objects with
|
| 163 |
+
``_asdict()`` methods will be encoded as JSON objects.
|
| 164 |
+
|
| 165 |
+
If tuple_as_array is true (the default), tuple (and subclasses) will
|
| 166 |
+
be encoded as JSON arrays.
|
| 167 |
+
|
| 168 |
+
If bigint_as_string is true (not the default), ints 2**53 and higher
|
| 169 |
+
or lower than -2**53 will be encoded as strings. This is to avoid the
|
| 170 |
+
rounding that happens in Javascript otherwise.
|
| 171 |
+
|
| 172 |
+
If int_as_string_bitcount is a positive number (n), then int of size
|
| 173 |
+
greater than or equal to 2**n or lower than or equal to -2**n will be
|
| 174 |
+
encoded as strings.
|
| 175 |
+
|
| 176 |
+
If specified, item_sort_key is a callable used to sort the items in
|
| 177 |
+
each dictionary. This is useful if you want to sort items other than
|
| 178 |
+
in alphabetical order by key.
|
| 179 |
+
|
| 180 |
+
If for_json is true (not the default), objects with a ``for_json()``
|
| 181 |
+
method will use the return value of that method for encoding as JSON
|
| 182 |
+
instead of the object.
|
| 183 |
+
|
| 184 |
+
"""
|
| 185 |
+
|
| 186 |
+
self.skipkeys = skipkeys
|
| 187 |
+
self.ensure_ascii = ensure_ascii
|
| 188 |
+
self.check_circular = check_circular
|
| 189 |
+
self.sort_keys = sort_keys
|
| 190 |
+
self.use_decimal = use_decimal
|
| 191 |
+
self.namedtuple_as_object = namedtuple_as_object
|
| 192 |
+
self.tuple_as_array = tuple_as_array
|
| 193 |
+
self.bigint_as_string = bigint_as_string
|
| 194 |
+
self.item_sort_key = item_sort_key
|
| 195 |
+
self.for_json = for_json
|
| 196 |
+
self.int_as_string_bitcount = int_as_string_bitcount
|
| 197 |
+
if indent is not None and not isinstance(indent, string_types):
|
| 198 |
+
indent = indent * ' '
|
| 199 |
+
elif indent is None:
|
| 200 |
+
indent = ' '
|
| 201 |
+
self.indent = indent
|
| 202 |
+
if default is not None:
|
| 203 |
+
self.default = default
|
| 204 |
+
self.encoding = encoding
|
| 205 |
+
|
| 206 |
+
def default(self, o):
|
| 207 |
+
"""Implement this method in a subclass such that it returns
|
| 208 |
+
a serializable object for ``o``, or calls the base implementation
|
| 209 |
+
(to raise a ``TypeError``).
|
| 210 |
+
|
| 211 |
+
For example, to support arbitrary iterators, you could
|
| 212 |
+
implement default like this::
|
| 213 |
+
|
| 214 |
+
def default(self, o):
|
| 215 |
+
try:
|
| 216 |
+
iterable = iter(o)
|
| 217 |
+
except TypeError:
|
| 218 |
+
pass
|
| 219 |
+
else:
|
| 220 |
+
return list(iterable)
|
| 221 |
+
return HjsonEncoder.default(self, o)
|
| 222 |
+
|
| 223 |
+
"""
|
| 224 |
+
raise TypeError(repr(o) + " is not JSON serializable")
|
| 225 |
+
|
| 226 |
+
def encode(self, o):
|
| 227 |
+
"""Return a JSON string representation of a Python data structure.
|
| 228 |
+
|
| 229 |
+
>>> from hjson import HjsonEncoder
|
| 230 |
+
>>> HjsonEncoder().encode({"foo": ["bar", "baz"]})
|
| 231 |
+
'{"foo": ["bar", "baz"]}'
|
| 232 |
+
|
| 233 |
+
"""
|
| 234 |
+
# This is for extremely simple cases and benchmarks.
|
| 235 |
+
if isinstance(o, binary_type):
|
| 236 |
+
_encoding = self.encoding
|
| 237 |
+
if (_encoding is not None and not (_encoding == 'utf-8')):
|
| 238 |
+
o = o.decode(_encoding)
|
| 239 |
+
|
| 240 |
+
# This doesn't pass the iterator directly to ''.join() because the
|
| 241 |
+
# exceptions aren't as detailed. The list call should be roughly
|
| 242 |
+
# equivalent to the PySequence_Fast that ''.join() would do.
|
| 243 |
+
chunks = self.iterencode(o, _one_shot=True)
|
| 244 |
+
if not isinstance(chunks, (list, tuple)):
|
| 245 |
+
chunks = list(chunks)
|
| 246 |
+
if self.ensure_ascii:
|
| 247 |
+
return ''.join(chunks)
|
| 248 |
+
else:
|
| 249 |
+
return u''.join(chunks)
|
| 250 |
+
|
| 251 |
+
def iterencode(self, o, _one_shot=False):
|
| 252 |
+
"""Encode the given object and yield each string
|
| 253 |
+
representation as available.
|
| 254 |
+
|
| 255 |
+
For example::
|
| 256 |
+
|
| 257 |
+
for chunk in HjsonEncoder().iterencode(bigobject):
|
| 258 |
+
mysocket.write(chunk)
|
| 259 |
+
|
| 260 |
+
"""
|
| 261 |
+
if self.check_circular:
|
| 262 |
+
markers = {}
|
| 263 |
+
else:
|
| 264 |
+
markers = None
|
| 265 |
+
if self.ensure_ascii:
|
| 266 |
+
_encoder = encode_basestring_ascii
|
| 267 |
+
else:
|
| 268 |
+
_encoder = encode_basestring
|
| 269 |
+
if self.encoding != 'utf-8':
|
| 270 |
+
def _encoder(o, _orig_encoder=_encoder, _encoding=self.encoding):
|
| 271 |
+
if isinstance(o, binary_type):
|
| 272 |
+
o = o.decode(_encoding)
|
| 273 |
+
return _orig_encoder(o)
|
| 274 |
+
|
| 275 |
+
def floatstr(o, _repr=FLOAT_REPR, _inf=PosInf, _neginf=-PosInf):
|
| 276 |
+
# Check for specials. Note that this type of test is processor
|
| 277 |
+
# and/or platform-specific, so do tests which don't depend on
|
| 278 |
+
# the internals.
|
| 279 |
+
|
| 280 |
+
if o != o or o == _inf or o == _neginf:
|
| 281 |
+
return 'null'
|
| 282 |
+
else:
|
| 283 |
+
return _repr(o)
|
| 284 |
+
|
| 285 |
+
key_memo = {}
|
| 286 |
+
int_as_string_bitcount = (
|
| 287 |
+
53 if self.bigint_as_string else self.int_as_string_bitcount)
|
| 288 |
+
_iterencode = _make_iterencode(
|
| 289 |
+
markers, self.default, _encoder, self.indent, floatstr,
|
| 290 |
+
self.sort_keys, self.skipkeys, _one_shot, self.use_decimal,
|
| 291 |
+
self.namedtuple_as_object, self.tuple_as_array,
|
| 292 |
+
int_as_string_bitcount,
|
| 293 |
+
self.item_sort_key, self.encoding, self.for_json,
|
| 294 |
+
Decimal=Decimal)
|
| 295 |
+
try:
|
| 296 |
+
return _iterencode(o, 0, True)
|
| 297 |
+
finally:
|
| 298 |
+
key_memo.clear()
|
| 299 |
+
|
| 300 |
+
|
| 301 |
+
def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
|
| 302 |
+
_sort_keys, _skipkeys, _one_shot,
|
| 303 |
+
_use_decimal, _namedtuple_as_object, _tuple_as_array,
|
| 304 |
+
_int_as_string_bitcount, _item_sort_key,
|
| 305 |
+
_encoding,_for_json,
|
| 306 |
+
## HACK: hand-optimized bytecode; turn globals into locals
|
| 307 |
+
_PY3=PY3,
|
| 308 |
+
ValueError=ValueError,
|
| 309 |
+
string_types=string_types,
|
| 310 |
+
Decimal=Decimal,
|
| 311 |
+
dict=dict,
|
| 312 |
+
float=float,
|
| 313 |
+
id=id,
|
| 314 |
+
integer_types=integer_types,
|
| 315 |
+
isinstance=isinstance,
|
| 316 |
+
list=list,
|
| 317 |
+
str=str,
|
| 318 |
+
tuple=tuple,
|
| 319 |
+
):
|
| 320 |
+
if _item_sort_key and not callable(_item_sort_key):
|
| 321 |
+
raise TypeError("item_sort_key must be None or callable")
|
| 322 |
+
elif _sort_keys and not _item_sort_key:
|
| 323 |
+
_item_sort_key = itemgetter(0)
|
| 324 |
+
|
| 325 |
+
if (_int_as_string_bitcount is not None and
|
| 326 |
+
(_int_as_string_bitcount <= 0 or
|
| 327 |
+
not isinstance(_int_as_string_bitcount, integer_types))):
|
| 328 |
+
raise TypeError("int_as_string_bitcount must be a positive integer")
|
| 329 |
+
|
| 330 |
+
def _encode_int(value):
|
| 331 |
+
return str(value)
|
| 332 |
+
|
| 333 |
+
def _stringify_key(key):
|
| 334 |
+
if isinstance(key, string_types): # pragma: no cover
|
| 335 |
+
pass
|
| 336 |
+
elif isinstance(key, binary_type):
|
| 337 |
+
key = key.decode(_encoding)
|
| 338 |
+
elif isinstance(key, float):
|
| 339 |
+
key = _floatstr(key)
|
| 340 |
+
elif key is True:
|
| 341 |
+
key = 'true'
|
| 342 |
+
elif key is False:
|
| 343 |
+
key = 'false'
|
| 344 |
+
elif key is None:
|
| 345 |
+
key = 'null'
|
| 346 |
+
elif isinstance(key, integer_types):
|
| 347 |
+
key = str(key)
|
| 348 |
+
elif _use_decimal and isinstance(key, Decimal):
|
| 349 |
+
key = str(key)
|
| 350 |
+
elif _skipkeys:
|
| 351 |
+
key = None
|
| 352 |
+
else:
|
| 353 |
+
raise TypeError("key " + repr(key) + " is not a string")
|
| 354 |
+
return key
|
| 355 |
+
|
| 356 |
+
def _encoder_key(name):
|
| 357 |
+
if not name: return '""'
|
| 358 |
+
|
| 359 |
+
# Check if we can insert this name without quotes
|
| 360 |
+
if NEEDSESCAPENAME.search(name):
|
| 361 |
+
return _encoder(name)
|
| 362 |
+
else:
|
| 363 |
+
# return without quotes
|
| 364 |
+
return name
|
| 365 |
+
|
| 366 |
+
def _encoder_str(str, _current_indent_level):
|
| 367 |
+
if not str: return '""'
|
| 368 |
+
|
| 369 |
+
# Check if we can insert this string without quotes
|
| 370 |
+
# see hjson syntax (must not parse as true, false, null or number)
|
| 371 |
+
|
| 372 |
+
first = str[0]
|
| 373 |
+
isNumber = False
|
| 374 |
+
if first == '-' or first >= '0' and first <= '9':
|
| 375 |
+
isNumber = STARTSWITHNUMBER.match(str) is not None
|
| 376 |
+
|
| 377 |
+
if (NEEDSQUOTES.search(str) or
|
| 378 |
+
isNumber or
|
| 379 |
+
STARTSWITHKEYWORD.match(str) is not None):
|
| 380 |
+
|
| 381 |
+
# If the string contains no control characters, no quote characters, and no
|
| 382 |
+
# backslash characters, then we can safely slap some quotes around it.
|
| 383 |
+
# Otherwise we first check if the string can be expressed in multiline
|
| 384 |
+
# format or we must replace the offending characters with safe escape
|
| 385 |
+
# sequences.
|
| 386 |
+
|
| 387 |
+
if not NEEDSESCAPE.search(str):
|
| 388 |
+
return '"' + str + '"'
|
| 389 |
+
elif not NEEDSESCAPEML.search(str):
|
| 390 |
+
return _encoder_str_ml(str, _current_indent_level + 1)
|
| 391 |
+
else:
|
| 392 |
+
return _encoder(str)
|
| 393 |
+
else:
|
| 394 |
+
# return without quotes
|
| 395 |
+
return str
|
| 396 |
+
|
| 397 |
+
def _encoder_str_ml(str, _current_indent_level):
|
| 398 |
+
|
| 399 |
+
a = str.replace('\r', '').split('\n')
|
| 400 |
+
# gap += indent;
|
| 401 |
+
|
| 402 |
+
if len(a) == 1:
|
| 403 |
+
# The string contains only a single line. We still use the multiline
|
| 404 |
+
# format as it avoids escaping the \ character (e.g. when used in a
|
| 405 |
+
# regex).
|
| 406 |
+
return "'''" + a[0] + "'''"
|
| 407 |
+
else:
|
| 408 |
+
gap = _indent * _current_indent_level
|
| 409 |
+
res = '\n' + gap + "'''"
|
| 410 |
+
for line in a:
|
| 411 |
+
res += '\n'
|
| 412 |
+
if line: res += gap + line
|
| 413 |
+
return res + '\n' + gap + "'''"
|
| 414 |
+
|
| 415 |
+
def _iterencode_dict(dct, _current_indent_level, _isRoot=False):
|
| 416 |
+
if not dct:
|
| 417 |
+
yield '{}'
|
| 418 |
+
return
|
| 419 |
+
if markers is not None:
|
| 420 |
+
markerid = id(dct)
|
| 421 |
+
if markerid in markers:
|
| 422 |
+
raise ValueError("Circular reference detected")
|
| 423 |
+
markers[markerid] = dct
|
| 424 |
+
|
| 425 |
+
if not _isRoot:
|
| 426 |
+
yield '\n' + (_indent * _current_indent_level)
|
| 427 |
+
|
| 428 |
+
_current_indent_level += 1
|
| 429 |
+
newline_indent = '\n' + (_indent * _current_indent_level)
|
| 430 |
+
|
| 431 |
+
yield '{'
|
| 432 |
+
|
| 433 |
+
if _PY3:
|
| 434 |
+
iteritems = dct.items()
|
| 435 |
+
else:
|
| 436 |
+
iteritems = dct.iteritems()
|
| 437 |
+
if _item_sort_key:
|
| 438 |
+
items = []
|
| 439 |
+
for k, v in dct.items():
|
| 440 |
+
if not isinstance(k, string_types):
|
| 441 |
+
k = _stringify_key(k)
|
| 442 |
+
if k is None:
|
| 443 |
+
continue
|
| 444 |
+
items.append((k, v))
|
| 445 |
+
items.sort(key=_item_sort_key)
|
| 446 |
+
else:
|
| 447 |
+
items = iteritems
|
| 448 |
+
for key, value in items:
|
| 449 |
+
if not (_item_sort_key or isinstance(key, string_types)):
|
| 450 |
+
key = _stringify_key(key)
|
| 451 |
+
if key is None:
|
| 452 |
+
# _skipkeys must be True
|
| 453 |
+
continue
|
| 454 |
+
|
| 455 |
+
yield newline_indent
|
| 456 |
+
yield _encoder_key(key)
|
| 457 |
+
|
| 458 |
+
first = True
|
| 459 |
+
for chunk in _iterencode(value, _current_indent_level):
|
| 460 |
+
if first:
|
| 461 |
+
first = False
|
| 462 |
+
if chunk[0 : 1] == '\n': yield ':'
|
| 463 |
+
else: yield ': '
|
| 464 |
+
yield chunk
|
| 465 |
+
|
| 466 |
+
if newline_indent is not None:
|
| 467 |
+
_current_indent_level -= 1
|
| 468 |
+
yield '\n' + (_indent * _current_indent_level)
|
| 469 |
+
yield '}'
|
| 470 |
+
if markers is not None:
|
| 471 |
+
del markers[markerid]
|
| 472 |
+
|
| 473 |
+
|
| 474 |
+
def _iterencode_list(lst, _current_indent_level, _isRoot=False):
|
| 475 |
+
if not lst:
|
| 476 |
+
yield '[]'
|
| 477 |
+
return
|
| 478 |
+
if markers is not None:
|
| 479 |
+
markerid = id(lst)
|
| 480 |
+
if markerid in markers:
|
| 481 |
+
raise ValueError("Circular reference detected")
|
| 482 |
+
markers[markerid] = lst
|
| 483 |
+
|
| 484 |
+
if not _isRoot:
|
| 485 |
+
yield '\n' + (_indent * _current_indent_level)
|
| 486 |
+
|
| 487 |
+
_current_indent_level += 1
|
| 488 |
+
newline_indent = '\n' + (_indent * _current_indent_level)
|
| 489 |
+
yield '['
|
| 490 |
+
|
| 491 |
+
for value in lst:
|
| 492 |
+
yield newline_indent
|
| 493 |
+
|
| 494 |
+
for chunk in _iterencode(value, _current_indent_level, True):
|
| 495 |
+
yield chunk
|
| 496 |
+
|
| 497 |
+
if newline_indent is not None:
|
| 498 |
+
_current_indent_level -= 1
|
| 499 |
+
yield '\n' + (_indent * _current_indent_level)
|
| 500 |
+
yield ']'
|
| 501 |
+
if markers is not None:
|
| 502 |
+
del markers[markerid]
|
| 503 |
+
|
| 504 |
+
|
| 505 |
+
def _iterencode(o, _current_indent_level, _isRoot=False):
|
| 506 |
+
if (isinstance(o, string_types) or
|
| 507 |
+
(_PY3 and isinstance(o, binary_type))):
|
| 508 |
+
yield _encoder_str(o, _current_indent_level)
|
| 509 |
+
elif o is None:
|
| 510 |
+
yield 'null'
|
| 511 |
+
elif o is True:
|
| 512 |
+
yield 'true'
|
| 513 |
+
elif o is False:
|
| 514 |
+
yield 'false'
|
| 515 |
+
elif isinstance(o, integer_types):
|
| 516 |
+
yield _encode_int(o)
|
| 517 |
+
elif isinstance(o, float):
|
| 518 |
+
yield _floatstr(o)
|
| 519 |
+
else:
|
| 520 |
+
for_json = _for_json and getattr(o, 'for_json', None)
|
| 521 |
+
if for_json and callable(for_json):
|
| 522 |
+
for chunk in _iterencode(for_json(), _current_indent_level, _isRoot):
|
| 523 |
+
yield chunk
|
| 524 |
+
elif isinstance(o, list):
|
| 525 |
+
for chunk in _iterencode_list(o, _current_indent_level, _isRoot):
|
| 526 |
+
yield chunk
|
| 527 |
+
else:
|
| 528 |
+
_asdict = _namedtuple_as_object and getattr(o, '_asdict', None)
|
| 529 |
+
if _asdict and callable(_asdict):
|
| 530 |
+
for chunk in _iterencode_dict(_asdict(), _current_indent_level, _isRoot):
|
| 531 |
+
yield chunk
|
| 532 |
+
elif (_tuple_as_array and isinstance(o, tuple)):
|
| 533 |
+
for chunk in _iterencode_list(o, _current_indent_level, _isRoot):
|
| 534 |
+
yield chunk
|
| 535 |
+
elif isinstance(o, dict):
|
| 536 |
+
for chunk in _iterencode_dict(o, _current_indent_level, _isRoot):
|
| 537 |
+
yield chunk
|
| 538 |
+
elif _use_decimal and isinstance(o, Decimal):
|
| 539 |
+
yield str(o)
|
| 540 |
+
else:
|
| 541 |
+
if markers is not None:
|
| 542 |
+
markerid = id(o)
|
| 543 |
+
if markerid in markers:
|
| 544 |
+
raise ValueError("Circular reference detected")
|
| 545 |
+
markers[markerid] = o
|
| 546 |
+
o = _default(o)
|
| 547 |
+
for chunk in _iterencode(o, _current_indent_level, _isRoot):
|
| 548 |
+
yield chunk
|
| 549 |
+
if markers is not None:
|
| 550 |
+
del markers[markerid]
|
| 551 |
+
|
| 552 |
+
return _iterencode
|
parrot/lib/python3.10/site-packages/hjson/ordered_dict.py
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Drop-in replacement for collections.OrderedDict by Raymond Hettinger
|
| 2 |
+
|
| 3 |
+
http://code.activestate.com/recipes/576693/
|
| 4 |
+
|
| 5 |
+
"""
|
| 6 |
+
from UserDict import DictMixin
|
| 7 |
+
|
| 8 |
+
# Modified from original to support Python 2.4, see
|
| 9 |
+
# http://code.google.com/p/simplejson/issues/detail?id=53
|
| 10 |
+
try:
|
| 11 |
+
all
|
| 12 |
+
except NameError:
|
| 13 |
+
def all(seq):
|
| 14 |
+
for elem in seq:
|
| 15 |
+
if not elem:
|
| 16 |
+
return False
|
| 17 |
+
return True
|
| 18 |
+
|
| 19 |
+
class OrderedDict(dict, DictMixin):
|
| 20 |
+
|
| 21 |
+
def __init__(self, *args, **kwds):
|
| 22 |
+
if len(args) > 1:
|
| 23 |
+
raise TypeError('expected at most 1 arguments, got %d' % len(args))
|
| 24 |
+
try:
|
| 25 |
+
self.__end
|
| 26 |
+
except AttributeError:
|
| 27 |
+
self.clear()
|
| 28 |
+
self.update(*args, **kwds)
|
| 29 |
+
|
| 30 |
+
def clear(self):
|
| 31 |
+
self.__end = end = []
|
| 32 |
+
end += [None, end, end] # sentinel node for doubly linked list
|
| 33 |
+
self.__map = {} # key --> [key, prev, next]
|
| 34 |
+
dict.clear(self)
|
| 35 |
+
|
| 36 |
+
def __setitem__(self, key, value):
|
| 37 |
+
if key not in self:
|
| 38 |
+
end = self.__end
|
| 39 |
+
curr = end[1]
|
| 40 |
+
curr[2] = end[1] = self.__map[key] = [key, curr, end]
|
| 41 |
+
dict.__setitem__(self, key, value)
|
| 42 |
+
|
| 43 |
+
def __delitem__(self, key):
|
| 44 |
+
dict.__delitem__(self, key)
|
| 45 |
+
key, prev, next = self.__map.pop(key)
|
| 46 |
+
prev[2] = next
|
| 47 |
+
next[1] = prev
|
| 48 |
+
|
| 49 |
+
def __iter__(self):
|
| 50 |
+
end = self.__end
|
| 51 |
+
curr = end[2]
|
| 52 |
+
while curr is not end:
|
| 53 |
+
yield curr[0]
|
| 54 |
+
curr = curr[2]
|
| 55 |
+
|
| 56 |
+
def __reversed__(self):
|
| 57 |
+
end = self.__end
|
| 58 |
+
curr = end[1]
|
| 59 |
+
while curr is not end:
|
| 60 |
+
yield curr[0]
|
| 61 |
+
curr = curr[1]
|
| 62 |
+
|
| 63 |
+
def popitem(self, last=True):
|
| 64 |
+
if not self:
|
| 65 |
+
raise KeyError('dictionary is empty')
|
| 66 |
+
# Modified from original to support Python 2.4, see
|
| 67 |
+
# http://code.google.com/p/simplejson/issues/detail?id=53
|
| 68 |
+
if last:
|
| 69 |
+
key = reversed(self).next()
|
| 70 |
+
else:
|
| 71 |
+
key = iter(self).next()
|
| 72 |
+
value = self.pop(key)
|
| 73 |
+
return key, value
|
| 74 |
+
|
| 75 |
+
def __reduce__(self):
|
| 76 |
+
items = [[k, self[k]] for k in self]
|
| 77 |
+
tmp = self.__map, self.__end
|
| 78 |
+
del self.__map, self.__end
|
| 79 |
+
inst_dict = vars(self).copy()
|
| 80 |
+
self.__map, self.__end = tmp
|
| 81 |
+
if inst_dict:
|
| 82 |
+
return (self.__class__, (items,), inst_dict)
|
| 83 |
+
return self.__class__, (items,)
|
| 84 |
+
|
| 85 |
+
def keys(self):
|
| 86 |
+
return list(self)
|
| 87 |
+
|
| 88 |
+
setdefault = DictMixin.setdefault
|
| 89 |
+
update = DictMixin.update
|
| 90 |
+
pop = DictMixin.pop
|
| 91 |
+
values = DictMixin.values
|
| 92 |
+
items = DictMixin.items
|
| 93 |
+
iterkeys = DictMixin.iterkeys
|
| 94 |
+
itervalues = DictMixin.itervalues
|
| 95 |
+
iteritems = DictMixin.iteritems
|
| 96 |
+
|
| 97 |
+
def __repr__(self):
|
| 98 |
+
if not self:
|
| 99 |
+
return '%s()' % (self.__class__.__name__,)
|
| 100 |
+
return '%s(%r)' % (self.__class__.__name__, self.items())
|
| 101 |
+
|
| 102 |
+
def copy(self):
|
| 103 |
+
return self.__class__(self)
|
| 104 |
+
|
| 105 |
+
@classmethod
|
| 106 |
+
def fromkeys(cls, iterable, value=None):
|
| 107 |
+
d = cls()
|
| 108 |
+
for key in iterable:
|
| 109 |
+
d[key] = value
|
| 110 |
+
return d
|
| 111 |
+
|
| 112 |
+
def __eq__(self, other):
|
| 113 |
+
if isinstance(other, OrderedDict):
|
| 114 |
+
return len(self)==len(other) and \
|
| 115 |
+
all(p==q for p, q in zip(self.items(), other.items()))
|
| 116 |
+
return dict.__eq__(self, other)
|
| 117 |
+
|
| 118 |
+
def __ne__(self, other):
|
| 119 |
+
return not self == other
|
parrot/lib/python3.10/site-packages/hjson/scanner.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""JSON token scanner
|
| 2 |
+
"""
|
| 3 |
+
import re
|
| 4 |
+
|
| 5 |
+
__all__ = ['HjsonDecodeError']
|
| 6 |
+
|
| 7 |
+
class HjsonDecodeError(ValueError):
|
| 8 |
+
"""Subclass of ValueError with the following additional properties:
|
| 9 |
+
|
| 10 |
+
msg: The unformatted error message
|
| 11 |
+
doc: The JSON document being parsed
|
| 12 |
+
pos: The start index of doc where parsing failed
|
| 13 |
+
end: The end index of doc where parsing failed (may be None)
|
| 14 |
+
lineno: The line corresponding to pos
|
| 15 |
+
colno: The column corresponding to pos
|
| 16 |
+
endlineno: The line corresponding to end (may be None)
|
| 17 |
+
endcolno: The column corresponding to end (may be None)
|
| 18 |
+
|
| 19 |
+
"""
|
| 20 |
+
# Note that this exception is used from _speedups
|
| 21 |
+
def __init__(self, msg, doc, pos, end=None):
|
| 22 |
+
ValueError.__init__(self, errmsg(msg, doc, pos, end=end))
|
| 23 |
+
self.msg = msg
|
| 24 |
+
self.doc = doc
|
| 25 |
+
self.pos = pos
|
| 26 |
+
self.end = end
|
| 27 |
+
self.lineno, self.colno = linecol(doc, pos)
|
| 28 |
+
if end is not None:
|
| 29 |
+
self.endlineno, self.endcolno = linecol(doc, end)
|
| 30 |
+
else:
|
| 31 |
+
self.endlineno, self.endcolno = None, None
|
| 32 |
+
|
| 33 |
+
def __reduce__(self):
|
| 34 |
+
return self.__class__, (self.msg, self.doc, self.pos, self.end)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def linecol(doc, pos):
|
| 38 |
+
lineno = doc.count('\n', 0, pos) + 1
|
| 39 |
+
if lineno == 1:
|
| 40 |
+
colno = pos + 1
|
| 41 |
+
else:
|
| 42 |
+
colno = pos - doc.rindex('\n', 0, pos)
|
| 43 |
+
return lineno, colno
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def errmsg(msg, doc, pos, end=None):
|
| 47 |
+
lineno, colno = linecol(doc, pos)
|
| 48 |
+
msg = msg.replace('%r', repr(doc[pos:pos + 1]))
|
| 49 |
+
if end is None:
|
| 50 |
+
fmt = '%s: line %d column %d (char %d)'
|
| 51 |
+
return fmt % (msg, lineno, colno, pos)
|
| 52 |
+
endlineno, endcolno = linecol(doc, end)
|
| 53 |
+
fmt = '%s: line %d column %d - line %d column %d (char %d - %d)'
|
| 54 |
+
return fmt % (msg, lineno, colno, endlineno, endcolno, pos, end)
|
| 55 |
+
|
| 56 |
+
|
parrot/lib/python3.10/site-packages/hjson/tests/test_decode.py
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import absolute_import
|
| 2 |
+
|
| 3 |
+
import decimal
|
| 4 |
+
from unittest import TestCase
|
| 5 |
+
|
| 6 |
+
import hjson as json
|
| 7 |
+
from hjson import OrderedDict
|
| 8 |
+
from hjson.compat import StringIO
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class TestDecode(TestCase):
|
| 12 |
+
if not hasattr(TestCase, "assertIs"):
|
| 13 |
+
|
| 14 |
+
def assertIs(self, a, b):
|
| 15 |
+
self.assertTrue(a is b, "%r is %r" % (a, b))
|
| 16 |
+
|
| 17 |
+
def test_decimal(self):
|
| 18 |
+
rval = json.loads("1.1", parse_float=decimal.Decimal)
|
| 19 |
+
self.assertTrue(isinstance(rval, decimal.Decimal))
|
| 20 |
+
self.assertEqual(rval, decimal.Decimal("1.1"))
|
| 21 |
+
|
| 22 |
+
def test_float(self):
|
| 23 |
+
rval = json.loads("1", parse_int=float)
|
| 24 |
+
self.assertTrue(isinstance(rval, float))
|
| 25 |
+
self.assertEqual(rval, 1.0)
|
| 26 |
+
|
| 27 |
+
def test_decoder_optimizations(self):
|
| 28 |
+
# Several optimizations were made that skip over calls to
|
| 29 |
+
# the whitespace regex, so this test is designed to try and
|
| 30 |
+
# exercise the uncommon cases. The array cases are already covered.
|
| 31 |
+
rval = json.loads('{ "key" : "value" , "k":"v" }')
|
| 32 |
+
self.assertEqual(rval, {"key": "value", "k": "v"})
|
| 33 |
+
|
| 34 |
+
def test_empty_objects(self):
|
| 35 |
+
s = "{}"
|
| 36 |
+
self.assertEqual(json.loads(s), eval(s))
|
| 37 |
+
s = "[]"
|
| 38 |
+
self.assertEqual(json.loads(s), eval(s))
|
| 39 |
+
s = '""'
|
| 40 |
+
self.assertEqual(json.loads(s), eval(s))
|
| 41 |
+
|
| 42 |
+
def test_object_pairs_hook(self):
|
| 43 |
+
s = '{"xkd":1, "kcw":2, "art":3, "hxm":4, "qrt":5, "pad":6, "hoy":7}'
|
| 44 |
+
p = [
|
| 45 |
+
("xkd", 1),
|
| 46 |
+
("kcw", 2),
|
| 47 |
+
("art", 3),
|
| 48 |
+
("hxm", 4),
|
| 49 |
+
("qrt", 5),
|
| 50 |
+
("pad", 6),
|
| 51 |
+
("hoy", 7),
|
| 52 |
+
]
|
| 53 |
+
self.assertEqual(json.loads(s), eval(s))
|
| 54 |
+
self.assertEqual(json.loads(s, object_pairs_hook=lambda x: x), p)
|
| 55 |
+
self.assertEqual(json.load(StringIO(s), object_pairs_hook=lambda x: x), p)
|
| 56 |
+
od = json.loads(s, object_pairs_hook=OrderedDict)
|
| 57 |
+
self.assertEqual(od, OrderedDict(p))
|
| 58 |
+
self.assertEqual(type(od), OrderedDict)
|
| 59 |
+
# the object_pairs_hook takes priority over the object_hook
|
| 60 |
+
self.assertEqual(
|
| 61 |
+
json.loads(s, object_pairs_hook=OrderedDict, object_hook=lambda x: None),
|
| 62 |
+
OrderedDict(p),
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
+
def check_keys_reuse(self, source, loads):
|
| 66 |
+
rval = loads(source)
|
| 67 |
+
(a, b), (c, d) = sorted(rval[0]), sorted(rval[1])
|
| 68 |
+
self.assertIs(a, c)
|
| 69 |
+
self.assertIs(b, d)
|
| 70 |
+
|
| 71 |
+
def test_keys_reuse_str(self):
|
| 72 |
+
s = u'[{"a_key": 1, "b_\xe9": 2}, {"a_key": 3, "b_\xe9": 4}]'.encode("utf8")
|
| 73 |
+
self.check_keys_reuse(s, json.loads)
|
| 74 |
+
|
| 75 |
+
def test_keys_reuse_unicode(self):
|
| 76 |
+
s = u'[{"a_key": 1, "b_\xe9": 2}, {"a_key": 3, "b_\xe9": 4}]'
|
| 77 |
+
self.check_keys_reuse(s, json.loads)
|
| 78 |
+
|
| 79 |
+
def test_empty_strings(self):
|
| 80 |
+
self.assertEqual(json.loads('""'), "")
|
| 81 |
+
self.assertEqual(json.loads(u'""'), u"")
|
| 82 |
+
self.assertEqual(json.loads('[""]'), [""])
|
| 83 |
+
self.assertEqual(json.loads(u'[""]'), [u""])
|
| 84 |
+
|
| 85 |
+
def test_multiline_string(self):
|
| 86 |
+
s1 = """
|
| 87 |
+
|
| 88 |
+
hello: '''
|
| 89 |
+
|
| 90 |
+
'''
|
| 91 |
+
|
| 92 |
+
"""
|
| 93 |
+
s2 = """
|
| 94 |
+
|
| 95 |
+
hello: '''
|
| 96 |
+
'''
|
| 97 |
+
|
| 98 |
+
"""
|
| 99 |
+
s3 = """
|
| 100 |
+
|
| 101 |
+
hello: ''''''
|
| 102 |
+
|
| 103 |
+
"""
|
| 104 |
+
s4 = """
|
| 105 |
+
|
| 106 |
+
hello: ''
|
| 107 |
+
|
| 108 |
+
"""
|
| 109 |
+
s5 = """
|
| 110 |
+
|
| 111 |
+
hello: ""
|
| 112 |
+
|
| 113 |
+
"""
|
| 114 |
+
self.assertEqual(json.loads(s1), {"hello": ""})
|
| 115 |
+
self.assertEqual(json.loads(s2), {"hello": ""})
|
| 116 |
+
self.assertEqual(json.loads(s3), {"hello": ""})
|
| 117 |
+
self.assertEqual(json.loads(s4), {"hello": ""})
|
| 118 |
+
self.assertEqual(json.loads(s5), {"hello": ""})
|
| 119 |
+
|
| 120 |
+
def test_raw_decode(self):
|
| 121 |
+
cls = json.decoder.HjsonDecoder
|
| 122 |
+
self.assertEqual(({"a": {}}, 9), cls().raw_decode('{"a": {}}'))
|
| 123 |
+
# http://code.google.com/p/simplejson/issues/detail?id=85
|
| 124 |
+
self.assertEqual(
|
| 125 |
+
({"a": {}}, 9), cls(object_pairs_hook=dict).raw_decode('{"a": {}}')
|
| 126 |
+
)
|
| 127 |
+
# https://github.com/simplejson/simplejson/pull/38
|
| 128 |
+
self.assertEqual(({"a": {}}, 11), cls().raw_decode(' \n{"a": {}}'))
|
| 129 |
+
|
| 130 |
+
def test_bounds_checking(self):
|
| 131 |
+
# https://github.com/simplejson/simplejson/issues/98
|
| 132 |
+
j = json.decoder.HjsonDecoder()
|
| 133 |
+
for i in [4, 5, 6, -1, -2, -3, -4, -5, -6]:
|
| 134 |
+
self.assertRaises(ValueError, j.scan_once, "1234", i)
|
| 135 |
+
self.assertRaises(ValueError, j.raw_decode, "1234", i)
|
| 136 |
+
x, y = sorted(["128931233", "472389423"], key=id)
|
| 137 |
+
diff = id(x) - id(y)
|
| 138 |
+
self.assertRaises(ValueError, j.scan_once, y, diff)
|
| 139 |
+
self.assertRaises(ValueError, j.raw_decode, y, i)
|
parrot/lib/python3.10/site-packages/hjson/tool.py
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
r"""Command-line tool to validate and pretty-print JSON
|
| 2 |
+
|
| 3 |
+
Usage::
|
| 4 |
+
|
| 5 |
+
$ echo '{"json":"obj"}' | hjson
|
| 6 |
+
{
|
| 7 |
+
"json": "obj"
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
"""
|
| 11 |
+
from __future__ import with_statement
|
| 12 |
+
import sys
|
| 13 |
+
import hjson
|
| 14 |
+
|
| 15 |
+
HELP="""Hjson, a user interface for JSON
|
| 16 |
+
|
| 17 |
+
Usage:
|
| 18 |
+
hjson [options]
|
| 19 |
+
hjson [options] <input>
|
| 20 |
+
hjson (-h | --help)
|
| 21 |
+
hjson (-V | --version)
|
| 22 |
+
|
| 23 |
+
Options:
|
| 24 |
+
-h --help Show this screen.
|
| 25 |
+
-j Output as formatted JSON.
|
| 26 |
+
-c Output as JSON.
|
| 27 |
+
-V --version Show version.
|
| 28 |
+
""";
|
| 29 |
+
|
| 30 |
+
def showerr(msg):
|
| 31 |
+
sys.stderr.write(msg)
|
| 32 |
+
sys.stderr.write("\n")
|
| 33 |
+
|
| 34 |
+
def main():
|
| 35 |
+
format = 'hjson'
|
| 36 |
+
args = []
|
| 37 |
+
for arg in sys.argv[1:]:
|
| 38 |
+
if arg == '-h' or arg == '--help':
|
| 39 |
+
showerr(HELP)
|
| 40 |
+
return
|
| 41 |
+
elif arg == '-j': format = 'json'
|
| 42 |
+
elif arg == '-c': format = 'compact'
|
| 43 |
+
elif arg == '-V' or arg == '--version':
|
| 44 |
+
showerr('Hjson ' + hjson.__version__)
|
| 45 |
+
return
|
| 46 |
+
|
| 47 |
+
elif arg[0] == '-':
|
| 48 |
+
showerr(HELP)
|
| 49 |
+
raise SystemExit('unknown option ' + arg)
|
| 50 |
+
else:
|
| 51 |
+
args.append(arg)
|
| 52 |
+
|
| 53 |
+
outfile = sys.stdout
|
| 54 |
+
if len(args) == 0:
|
| 55 |
+
infile = sys.stdin
|
| 56 |
+
elif len(args) == 1:
|
| 57 |
+
infile = open(args[0], 'r')
|
| 58 |
+
else:
|
| 59 |
+
showerr(HELP)
|
| 60 |
+
raise SystemExit('unknown options')
|
| 61 |
+
|
| 62 |
+
with infile:
|
| 63 |
+
try:
|
| 64 |
+
obj = hjson.load(infile, use_decimal=True)
|
| 65 |
+
except ValueError:
|
| 66 |
+
raise SystemExit(sys.exc_info()[1])
|
| 67 |
+
|
| 68 |
+
with outfile:
|
| 69 |
+
if format == 'json':
|
| 70 |
+
hjson.dumpJSON(obj, outfile, ensure_ascii=False, use_decimal=True, indent=' ')
|
| 71 |
+
elif format == 'compact':
|
| 72 |
+
hjson.dumpJSON(obj, outfile, ensure_ascii=False, use_decimal=True, separators=(',', ':'))
|
| 73 |
+
else:
|
| 74 |
+
hjson.dump(obj, outfile, ensure_ascii=False, use_decimal=True)
|
| 75 |
+
|
| 76 |
+
outfile.write('\n')
|
| 77 |
+
|
| 78 |
+
if __name__ == '__main__':
|
| 79 |
+
main()
|
parrot/lib/python3.10/site-packages/isympy.py
ADDED
|
@@ -0,0 +1,342 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Python shell for SymPy.
|
| 3 |
+
|
| 4 |
+
This is just a normal Python shell (IPython shell if you have the
|
| 5 |
+
IPython package installed), that executes the following commands for
|
| 6 |
+
the user:
|
| 7 |
+
|
| 8 |
+
>>> from __future__ import division
|
| 9 |
+
>>> from sympy import *
|
| 10 |
+
>>> x, y, z, t = symbols('x y z t')
|
| 11 |
+
>>> k, m, n = symbols('k m n', integer=True)
|
| 12 |
+
>>> f, g, h = symbols('f g h', cls=Function)
|
| 13 |
+
>>> init_printing()
|
| 14 |
+
|
| 15 |
+
So starting 'isympy' is equivalent to starting Python (or IPython) and
|
| 16 |
+
executing the above commands by hand. It is intended for easy and quick
|
| 17 |
+
experimentation with SymPy. isympy is a good way to use SymPy as an
|
| 18 |
+
interactive calculator. If you have IPython and Matplotlib installed, then
|
| 19 |
+
interactive plotting is enabled by default.
|
| 20 |
+
|
| 21 |
+
COMMAND LINE OPTIONS
|
| 22 |
+
--------------------
|
| 23 |
+
|
| 24 |
+
-c CONSOLE, --console=CONSOLE
|
| 25 |
+
|
| 26 |
+
Use the specified shell (Python or IPython) shell as the console
|
| 27 |
+
backend instead of the default one (IPython if present, Python
|
| 28 |
+
otherwise), e.g.:
|
| 29 |
+
|
| 30 |
+
$isympy -c python
|
| 31 |
+
|
| 32 |
+
CONSOLE must be one of 'ipython' or 'python'
|
| 33 |
+
|
| 34 |
+
-p PRETTY, --pretty PRETTY
|
| 35 |
+
|
| 36 |
+
Setup pretty-printing in SymPy. When pretty-printing is enabled,
|
| 37 |
+
expressions can be printed with Unicode or ASCII. The default is
|
| 38 |
+
to use pretty-printing (with Unicode if the terminal supports it).
|
| 39 |
+
When this option is 'no', expressions will not be pretty-printed
|
| 40 |
+
and ASCII will be used:
|
| 41 |
+
|
| 42 |
+
$isympy -p no
|
| 43 |
+
|
| 44 |
+
PRETTY must be one of 'unicode', 'ascii', or 'no'
|
| 45 |
+
|
| 46 |
+
-t TYPES, --types=TYPES
|
| 47 |
+
|
| 48 |
+
Setup the ground types for the polys. By default, gmpy ground types
|
| 49 |
+
are used if gmpy2 or gmpy is installed, otherwise it falls back to python
|
| 50 |
+
ground types, which are a little bit slower. You can manually
|
| 51 |
+
choose python ground types even if gmpy is installed (e.g., for
|
| 52 |
+
testing purposes):
|
| 53 |
+
|
| 54 |
+
$isympy -t python
|
| 55 |
+
|
| 56 |
+
TYPES must be one of 'gmpy', 'gmpy1' or 'python'
|
| 57 |
+
|
| 58 |
+
Note that the ground type gmpy1 is primarily intended for testing; it
|
| 59 |
+
forces the use of gmpy version 1 even if gmpy2 is available.
|
| 60 |
+
|
| 61 |
+
This is the same as setting the environment variable
|
| 62 |
+
SYMPY_GROUND_TYPES to the given ground type (e.g.,
|
| 63 |
+
SYMPY_GROUND_TYPES='gmpy')
|
| 64 |
+
|
| 65 |
+
The ground types can be determined interactively from the variable
|
| 66 |
+
sympy.polys.domains.GROUND_TYPES.
|
| 67 |
+
|
| 68 |
+
-o ORDER, --order ORDER
|
| 69 |
+
|
| 70 |
+
Setup the ordering of terms for printing. The default is lex, which
|
| 71 |
+
orders terms lexicographically (e.g., x**2 + x + 1). You can choose
|
| 72 |
+
other orderings, such as rev-lex, which will use reverse
|
| 73 |
+
lexicographic ordering (e.g., 1 + x + x**2):
|
| 74 |
+
|
| 75 |
+
$isympy -o rev-lex
|
| 76 |
+
|
| 77 |
+
ORDER must be one of 'lex', 'rev-lex', 'grlex', 'rev-grlex',
|
| 78 |
+
'grevlex', 'rev-grevlex', 'old', or 'none'.
|
| 79 |
+
|
| 80 |
+
Note that for very large expressions, ORDER='none' may speed up
|
| 81 |
+
printing considerably but the terms will have no canonical order.
|
| 82 |
+
|
| 83 |
+
-q, --quiet
|
| 84 |
+
|
| 85 |
+
Print only Python's and SymPy's versions to stdout at startup.
|
| 86 |
+
|
| 87 |
+
-d, --doctest
|
| 88 |
+
|
| 89 |
+
Use the same format that should be used for doctests. This is
|
| 90 |
+
equivalent to -c python -p no.
|
| 91 |
+
|
| 92 |
+
-C, --no-cache
|
| 93 |
+
|
| 94 |
+
Disable the caching mechanism. Disabling the cache may slow certain
|
| 95 |
+
operations down considerably. This is useful for testing the cache,
|
| 96 |
+
or for benchmarking, as the cache can result in deceptive timings.
|
| 97 |
+
|
| 98 |
+
This is equivalent to setting the environment variable
|
| 99 |
+
SYMPY_USE_CACHE to 'no'.
|
| 100 |
+
|
| 101 |
+
-a, --auto-symbols (requires at least IPython 0.11)
|
| 102 |
+
|
| 103 |
+
Automatically create missing symbols. Normally, typing a name of a
|
| 104 |
+
Symbol that has not been instantiated first would raise NameError,
|
| 105 |
+
but with this option enabled, any undefined name will be
|
| 106 |
+
automatically created as a Symbol.
|
| 107 |
+
|
| 108 |
+
Note that this is intended only for interactive, calculator style
|
| 109 |
+
usage. In a script that uses SymPy, Symbols should be instantiated
|
| 110 |
+
at the top, so that it's clear what they are.
|
| 111 |
+
|
| 112 |
+
This will not override any names that are already defined, which
|
| 113 |
+
includes the single character letters represented by the mnemonic
|
| 114 |
+
QCOSINE (see the "Gotchas and Pitfalls" document in the
|
| 115 |
+
documentation). You can delete existing names by executing "del
|
| 116 |
+
name". If a name is defined, typing "'name' in dir()" will return True.
|
| 117 |
+
|
| 118 |
+
The Symbols that are created using this have default assumptions.
|
| 119 |
+
If you want to place assumptions on symbols, you should create them
|
| 120 |
+
using symbols() or var().
|
| 121 |
+
|
| 122 |
+
Finally, this only works in the top level namespace. So, for
|
| 123 |
+
example, if you define a function in isympy with an undefined
|
| 124 |
+
Symbol, it will not work.
|
| 125 |
+
|
| 126 |
+
See also the -i and -I options.
|
| 127 |
+
|
| 128 |
+
-i, --int-to-Integer (requires at least IPython 0.11)
|
| 129 |
+
|
| 130 |
+
Automatically wrap int literals with Integer. This makes it so that
|
| 131 |
+
things like 1/2 will come out as Rational(1, 2), rather than 0.5. This
|
| 132 |
+
works by preprocessing the source and wrapping all int literals with
|
| 133 |
+
Integer. Note that this will not change the behavior of int literals
|
| 134 |
+
assigned to variables, and it also won't change the behavior of functions
|
| 135 |
+
that return int literals.
|
| 136 |
+
|
| 137 |
+
If you want an int, you can wrap the literal in int(), e.g. int(3)/int(2)
|
| 138 |
+
gives 1.5 (with division imported from __future__).
|
| 139 |
+
|
| 140 |
+
-I, --interactive (requires at least IPython 0.11)
|
| 141 |
+
|
| 142 |
+
This is equivalent to --auto-symbols --int-to-Integer. Future options
|
| 143 |
+
designed for ease of interactive use may be added to this.
|
| 144 |
+
|
| 145 |
+
-D, --debug
|
| 146 |
+
|
| 147 |
+
Enable debugging output. This is the same as setting the
|
| 148 |
+
environment variable SYMPY_DEBUG to 'True'. The debug status is set
|
| 149 |
+
in the variable SYMPY_DEBUG within isympy.
|
| 150 |
+
|
| 151 |
+
-- IPython options
|
| 152 |
+
|
| 153 |
+
Additionally you can pass command line options directly to the IPython
|
| 154 |
+
interpreter (the standard Python shell is not supported). However you
|
| 155 |
+
need to add the '--' separator between two types of options, e.g the
|
| 156 |
+
startup banner option and the colors option. You need to enter the
|
| 157 |
+
options as required by the version of IPython that you are using, too:
|
| 158 |
+
|
| 159 |
+
in IPython 0.11,
|
| 160 |
+
|
| 161 |
+
$isympy -q -- --colors=NoColor
|
| 162 |
+
|
| 163 |
+
or older versions of IPython,
|
| 164 |
+
|
| 165 |
+
$isympy -q -- -colors NoColor
|
| 166 |
+
|
| 167 |
+
See also isympy --help.
|
| 168 |
+
"""
|
| 169 |
+
|
| 170 |
+
import os
|
| 171 |
+
import sys
|
| 172 |
+
|
| 173 |
+
# DO NOT IMPORT SYMPY HERE! Or the setting of the sympy environment variables
|
| 174 |
+
# by the command line will break.
|
| 175 |
+
|
| 176 |
+
def main() -> None:
|
| 177 |
+
from argparse import ArgumentParser, RawDescriptionHelpFormatter
|
| 178 |
+
|
| 179 |
+
VERSION = None
|
| 180 |
+
if '--version' in sys.argv:
|
| 181 |
+
# We cannot import sympy before this is run, because flags like -C and
|
| 182 |
+
# -t set environment variables that must be set before SymPy is
|
| 183 |
+
# imported. The only thing we need to import it for is to get the
|
| 184 |
+
# version, which only matters with the --version flag.
|
| 185 |
+
import sympy
|
| 186 |
+
VERSION = sympy.__version__
|
| 187 |
+
|
| 188 |
+
usage = 'isympy [options] -- [ipython options]'
|
| 189 |
+
parser = ArgumentParser(
|
| 190 |
+
usage=usage,
|
| 191 |
+
description=__doc__,
|
| 192 |
+
formatter_class=RawDescriptionHelpFormatter,
|
| 193 |
+
)
|
| 194 |
+
|
| 195 |
+
parser.add_argument('--version', action='version', version=VERSION)
|
| 196 |
+
|
| 197 |
+
parser.add_argument(
|
| 198 |
+
'-c', '--console',
|
| 199 |
+
dest='console',
|
| 200 |
+
action='store',
|
| 201 |
+
default=None,
|
| 202 |
+
choices=['ipython', 'python'],
|
| 203 |
+
metavar='CONSOLE',
|
| 204 |
+
help='select type of interactive session: ipython | python; defaults '
|
| 205 |
+
'to ipython if IPython is installed, otherwise python')
|
| 206 |
+
|
| 207 |
+
parser.add_argument(
|
| 208 |
+
'-p', '--pretty',
|
| 209 |
+
dest='pretty',
|
| 210 |
+
action='store',
|
| 211 |
+
default=None,
|
| 212 |
+
metavar='PRETTY',
|
| 213 |
+
choices=['unicode', 'ascii', 'no'],
|
| 214 |
+
help='setup pretty printing: unicode | ascii | no; defaults to '
|
| 215 |
+
'unicode printing if the terminal supports it, otherwise ascii')
|
| 216 |
+
|
| 217 |
+
parser.add_argument(
|
| 218 |
+
'-t', '--types',
|
| 219 |
+
dest='types',
|
| 220 |
+
action='store',
|
| 221 |
+
default=None,
|
| 222 |
+
metavar='TYPES',
|
| 223 |
+
choices=['gmpy', 'gmpy1', 'python'],
|
| 224 |
+
help='setup ground types: gmpy | gmpy1 | python; defaults to gmpy if gmpy2 '
|
| 225 |
+
'or gmpy is installed, otherwise python')
|
| 226 |
+
|
| 227 |
+
parser.add_argument(
|
| 228 |
+
'-o', '--order',
|
| 229 |
+
dest='order',
|
| 230 |
+
action='store',
|
| 231 |
+
default=None,
|
| 232 |
+
metavar='ORDER',
|
| 233 |
+
choices=['lex', 'grlex', 'grevlex', 'rev-lex', 'rev-grlex', 'rev-grevlex', 'old', 'none'],
|
| 234 |
+
help='setup ordering of terms: [rev-]lex | [rev-]grlex | [rev-]grevlex | old | none; defaults to lex')
|
| 235 |
+
|
| 236 |
+
parser.add_argument(
|
| 237 |
+
'-q', '--quiet',
|
| 238 |
+
dest='quiet',
|
| 239 |
+
action='store_true',
|
| 240 |
+
default=False,
|
| 241 |
+
help='print only version information at startup')
|
| 242 |
+
|
| 243 |
+
parser.add_argument(
|
| 244 |
+
'-d', '--doctest',
|
| 245 |
+
dest='doctest',
|
| 246 |
+
action='store_true',
|
| 247 |
+
default=False,
|
| 248 |
+
help='use the doctest format for output (you can just copy and paste it)')
|
| 249 |
+
|
| 250 |
+
parser.add_argument(
|
| 251 |
+
'-C', '--no-cache',
|
| 252 |
+
dest='cache',
|
| 253 |
+
action='store_false',
|
| 254 |
+
default=True,
|
| 255 |
+
help='disable caching mechanism')
|
| 256 |
+
|
| 257 |
+
parser.add_argument(
|
| 258 |
+
'-a', '--auto-symbols',
|
| 259 |
+
dest='auto_symbols',
|
| 260 |
+
action='store_true',
|
| 261 |
+
default=False,
|
| 262 |
+
help='automatically construct missing symbols')
|
| 263 |
+
|
| 264 |
+
parser.add_argument(
|
| 265 |
+
'-i', '--int-to-Integer',
|
| 266 |
+
dest='auto_int_to_Integer',
|
| 267 |
+
action='store_true',
|
| 268 |
+
default=False,
|
| 269 |
+
help="automatically wrap int literals with Integer")
|
| 270 |
+
|
| 271 |
+
parser.add_argument(
|
| 272 |
+
'-I', '--interactive',
|
| 273 |
+
dest='interactive',
|
| 274 |
+
action='store_true',
|
| 275 |
+
default=False,
|
| 276 |
+
help="equivalent to -a -i")
|
| 277 |
+
|
| 278 |
+
parser.add_argument(
|
| 279 |
+
'-D', '--debug',
|
| 280 |
+
dest='debug',
|
| 281 |
+
action='store_true',
|
| 282 |
+
default=False,
|
| 283 |
+
help='enable debugging output')
|
| 284 |
+
|
| 285 |
+
(options, ipy_args) = parser.parse_known_args()
|
| 286 |
+
if '--' in ipy_args:
|
| 287 |
+
ipy_args.remove('--')
|
| 288 |
+
|
| 289 |
+
if not options.cache:
|
| 290 |
+
os.environ['SYMPY_USE_CACHE'] = 'no'
|
| 291 |
+
|
| 292 |
+
if options.types:
|
| 293 |
+
os.environ['SYMPY_GROUND_TYPES'] = options.types
|
| 294 |
+
|
| 295 |
+
if options.debug:
|
| 296 |
+
os.environ['SYMPY_DEBUG'] = str(options.debug)
|
| 297 |
+
|
| 298 |
+
if options.doctest:
|
| 299 |
+
options.pretty = 'no'
|
| 300 |
+
options.console = 'python'
|
| 301 |
+
|
| 302 |
+
session = options.console
|
| 303 |
+
|
| 304 |
+
if session is not None:
|
| 305 |
+
ipython = session == 'ipython'
|
| 306 |
+
else:
|
| 307 |
+
try:
|
| 308 |
+
import IPython
|
| 309 |
+
ipython = True
|
| 310 |
+
except ImportError:
|
| 311 |
+
if not options.quiet:
|
| 312 |
+
from sympy.interactive.session import no_ipython
|
| 313 |
+
print(no_ipython)
|
| 314 |
+
ipython = False
|
| 315 |
+
|
| 316 |
+
args = {
|
| 317 |
+
'pretty_print': True,
|
| 318 |
+
'use_unicode': None,
|
| 319 |
+
'use_latex': None,
|
| 320 |
+
'order': None,
|
| 321 |
+
'argv': ipy_args,
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
if options.pretty == 'unicode':
|
| 325 |
+
args['use_unicode'] = True
|
| 326 |
+
elif options.pretty == 'ascii':
|
| 327 |
+
args['use_unicode'] = False
|
| 328 |
+
elif options.pretty == 'no':
|
| 329 |
+
args['pretty_print'] = False
|
| 330 |
+
|
| 331 |
+
if options.order is not None:
|
| 332 |
+
args['order'] = options.order
|
| 333 |
+
|
| 334 |
+
args['quiet'] = options.quiet
|
| 335 |
+
args['auto_symbols'] = options.auto_symbols or options.interactive
|
| 336 |
+
args['auto_int_to_Integer'] = options.auto_int_to_Integer or options.interactive
|
| 337 |
+
|
| 338 |
+
from sympy.interactive import init_session
|
| 339 |
+
init_session(ipython, **args)
|
| 340 |
+
|
| 341 |
+
if __name__ == "__main__":
|
| 342 |
+
main()
|