Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/__init__.py +104 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/__init__.pyi +389 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/_cmp.py +160 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/_cmp.pyi +13 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/_compat.py +94 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/_config.py +31 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/_funcs.py +468 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/_make.py +3055 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/_next_gen.py +623 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/_typing_compat.pyi +15 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/_version_info.py +86 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/_version_info.pyi +9 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/converters.py +162 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/converters.pyi +19 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/exceptions.py +95 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/exceptions.pyi +17 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/filters.py +72 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/filters.pyi +6 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/py.typed +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/setters.py +79 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/setters.pyi +20 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/validators.py +710 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/validators.pyi +86 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/__init__.py +115 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/chardistribution.py +261 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/codingstatemachine.py +90 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/cp949prober.py +49 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/escsm.py +261 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/eucjpprober.py +102 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/euckrfreq.py +196 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/euckrprober.py +47 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/euctwfreq.py +388 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/euctwprober.py +47 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/gb2312prober.py +47 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/hebrewprober.py +316 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/jisfreq.py +325 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/johabprober.py +47 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/jpcntx.py +238 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/langbulgarianmodel.py +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/langgreekmodel.py +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/macromanprober.py +162 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/mbcharsetprober.py +95 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/mbcsgroupprober.py +57 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/py.typed +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/resultdict.py +16 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/sbcharsetprober.py +162 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/sbcsgroupprober.py +88 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/sjisprober.py +105 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/universaldetector.py +362 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/utf1632prober.py +225 -0
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/__init__.py
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-License-Identifier: MIT
|
| 2 |
+
|
| 3 |
+
"""
|
| 4 |
+
Classes Without Boilerplate
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
from functools import partial
|
| 8 |
+
from typing import Callable, Literal, Protocol
|
| 9 |
+
|
| 10 |
+
from . import converters, exceptions, filters, setters, validators
|
| 11 |
+
from ._cmp import cmp_using
|
| 12 |
+
from ._config import get_run_validators, set_run_validators
|
| 13 |
+
from ._funcs import asdict, assoc, astuple, has, resolve_types
|
| 14 |
+
from ._make import (
|
| 15 |
+
NOTHING,
|
| 16 |
+
Attribute,
|
| 17 |
+
Converter,
|
| 18 |
+
Factory,
|
| 19 |
+
_Nothing,
|
| 20 |
+
attrib,
|
| 21 |
+
attrs,
|
| 22 |
+
evolve,
|
| 23 |
+
fields,
|
| 24 |
+
fields_dict,
|
| 25 |
+
make_class,
|
| 26 |
+
validate,
|
| 27 |
+
)
|
| 28 |
+
from ._next_gen import define, field, frozen, mutable
|
| 29 |
+
from ._version_info import VersionInfo
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
s = attributes = attrs
|
| 33 |
+
ib = attr = attrib
|
| 34 |
+
dataclass = partial(attrs, auto_attribs=True) # happy Easter ;)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
class AttrsInstance(Protocol):
|
| 38 |
+
pass
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
NothingType = Literal[_Nothing.NOTHING]
|
| 42 |
+
|
| 43 |
+
__all__ = [
|
| 44 |
+
"NOTHING",
|
| 45 |
+
"Attribute",
|
| 46 |
+
"AttrsInstance",
|
| 47 |
+
"Converter",
|
| 48 |
+
"Factory",
|
| 49 |
+
"NothingType",
|
| 50 |
+
"asdict",
|
| 51 |
+
"assoc",
|
| 52 |
+
"astuple",
|
| 53 |
+
"attr",
|
| 54 |
+
"attrib",
|
| 55 |
+
"attributes",
|
| 56 |
+
"attrs",
|
| 57 |
+
"cmp_using",
|
| 58 |
+
"converters",
|
| 59 |
+
"define",
|
| 60 |
+
"evolve",
|
| 61 |
+
"exceptions",
|
| 62 |
+
"field",
|
| 63 |
+
"fields",
|
| 64 |
+
"fields_dict",
|
| 65 |
+
"filters",
|
| 66 |
+
"frozen",
|
| 67 |
+
"get_run_validators",
|
| 68 |
+
"has",
|
| 69 |
+
"ib",
|
| 70 |
+
"make_class",
|
| 71 |
+
"mutable",
|
| 72 |
+
"resolve_types",
|
| 73 |
+
"s",
|
| 74 |
+
"set_run_validators",
|
| 75 |
+
"setters",
|
| 76 |
+
"validate",
|
| 77 |
+
"validators",
|
| 78 |
+
]
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def _make_getattr(mod_name: str) -> Callable:
|
| 82 |
+
"""
|
| 83 |
+
Create a metadata proxy for packaging information that uses *mod_name* in
|
| 84 |
+
its warnings and errors.
|
| 85 |
+
"""
|
| 86 |
+
|
| 87 |
+
def __getattr__(name: str) -> str:
|
| 88 |
+
if name not in ("__version__", "__version_info__"):
|
| 89 |
+
msg = f"module {mod_name} has no attribute {name}"
|
| 90 |
+
raise AttributeError(msg)
|
| 91 |
+
|
| 92 |
+
from importlib.metadata import metadata
|
| 93 |
+
|
| 94 |
+
meta = metadata("attrs")
|
| 95 |
+
|
| 96 |
+
if name == "__version_info__":
|
| 97 |
+
return VersionInfo._from_version_string(meta["version"])
|
| 98 |
+
|
| 99 |
+
return meta["version"]
|
| 100 |
+
|
| 101 |
+
return __getattr__
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
__getattr__ = _make_getattr(__name__)
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/__init__.pyi
ADDED
|
@@ -0,0 +1,389 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import enum
|
| 2 |
+
import sys
|
| 3 |
+
|
| 4 |
+
from typing import (
|
| 5 |
+
Any,
|
| 6 |
+
Callable,
|
| 7 |
+
Generic,
|
| 8 |
+
Literal,
|
| 9 |
+
Mapping,
|
| 10 |
+
Protocol,
|
| 11 |
+
Sequence,
|
| 12 |
+
TypeVar,
|
| 13 |
+
overload,
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
# `import X as X` is required to make these public
|
| 17 |
+
from . import converters as converters
|
| 18 |
+
from . import exceptions as exceptions
|
| 19 |
+
from . import filters as filters
|
| 20 |
+
from . import setters as setters
|
| 21 |
+
from . import validators as validators
|
| 22 |
+
from ._cmp import cmp_using as cmp_using
|
| 23 |
+
from ._typing_compat import AttrsInstance_
|
| 24 |
+
from ._version_info import VersionInfo
|
| 25 |
+
from attrs import (
|
| 26 |
+
define as define,
|
| 27 |
+
field as field,
|
| 28 |
+
mutable as mutable,
|
| 29 |
+
frozen as frozen,
|
| 30 |
+
_EqOrderType,
|
| 31 |
+
_ValidatorType,
|
| 32 |
+
_ConverterType,
|
| 33 |
+
_ReprArgType,
|
| 34 |
+
_OnSetAttrType,
|
| 35 |
+
_OnSetAttrArgType,
|
| 36 |
+
_FieldTransformer,
|
| 37 |
+
_ValidatorArgType,
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
if sys.version_info >= (3, 10):
|
| 41 |
+
from typing import TypeGuard, TypeAlias
|
| 42 |
+
else:
|
| 43 |
+
from typing_extensions import TypeGuard, TypeAlias
|
| 44 |
+
|
| 45 |
+
if sys.version_info >= (3, 11):
|
| 46 |
+
from typing import dataclass_transform
|
| 47 |
+
else:
|
| 48 |
+
from typing_extensions import dataclass_transform
|
| 49 |
+
|
| 50 |
+
__version__: str
|
| 51 |
+
__version_info__: VersionInfo
|
| 52 |
+
__title__: str
|
| 53 |
+
__description__: str
|
| 54 |
+
__url__: str
|
| 55 |
+
__uri__: str
|
| 56 |
+
__author__: str
|
| 57 |
+
__email__: str
|
| 58 |
+
__license__: str
|
| 59 |
+
__copyright__: str
|
| 60 |
+
|
| 61 |
+
_T = TypeVar("_T")
|
| 62 |
+
_C = TypeVar("_C", bound=type)
|
| 63 |
+
|
| 64 |
+
_FilterType = Callable[["Attribute[_T]", _T], bool]
|
| 65 |
+
|
| 66 |
+
# We subclass this here to keep the protocol's qualified name clean.
|
| 67 |
+
class AttrsInstance(AttrsInstance_, Protocol):
|
| 68 |
+
pass
|
| 69 |
+
|
| 70 |
+
_A = TypeVar("_A", bound=type[AttrsInstance])
|
| 71 |
+
|
| 72 |
+
class _Nothing(enum.Enum):
|
| 73 |
+
NOTHING = enum.auto()
|
| 74 |
+
|
| 75 |
+
NOTHING = _Nothing.NOTHING
|
| 76 |
+
NothingType: TypeAlias = Literal[_Nothing.NOTHING]
|
| 77 |
+
|
| 78 |
+
# NOTE: Factory lies about its return type to make this possible:
|
| 79 |
+
# `x: List[int] # = Factory(list)`
|
| 80 |
+
# Work around mypy issue #4554 in the common case by using an overload.
|
| 81 |
+
|
| 82 |
+
@overload
|
| 83 |
+
def Factory(factory: Callable[[], _T]) -> _T: ...
|
| 84 |
+
@overload
|
| 85 |
+
def Factory(
|
| 86 |
+
factory: Callable[[Any], _T],
|
| 87 |
+
takes_self: Literal[True],
|
| 88 |
+
) -> _T: ...
|
| 89 |
+
@overload
|
| 90 |
+
def Factory(
|
| 91 |
+
factory: Callable[[], _T],
|
| 92 |
+
takes_self: Literal[False],
|
| 93 |
+
) -> _T: ...
|
| 94 |
+
|
| 95 |
+
In = TypeVar("In")
|
| 96 |
+
Out = TypeVar("Out")
|
| 97 |
+
|
| 98 |
+
class Converter(Generic[In, Out]):
|
| 99 |
+
@overload
|
| 100 |
+
def __init__(self, converter: Callable[[In], Out]) -> None: ...
|
| 101 |
+
@overload
|
| 102 |
+
def __init__(
|
| 103 |
+
self,
|
| 104 |
+
converter: Callable[[In, AttrsInstance, Attribute], Out],
|
| 105 |
+
*,
|
| 106 |
+
takes_self: Literal[True],
|
| 107 |
+
takes_field: Literal[True],
|
| 108 |
+
) -> None: ...
|
| 109 |
+
@overload
|
| 110 |
+
def __init__(
|
| 111 |
+
self,
|
| 112 |
+
converter: Callable[[In, Attribute], Out],
|
| 113 |
+
*,
|
| 114 |
+
takes_field: Literal[True],
|
| 115 |
+
) -> None: ...
|
| 116 |
+
@overload
|
| 117 |
+
def __init__(
|
| 118 |
+
self,
|
| 119 |
+
converter: Callable[[In, AttrsInstance], Out],
|
| 120 |
+
*,
|
| 121 |
+
takes_self: Literal[True],
|
| 122 |
+
) -> None: ...
|
| 123 |
+
|
| 124 |
+
class Attribute(Generic[_T]):
|
| 125 |
+
name: str
|
| 126 |
+
default: _T | None
|
| 127 |
+
validator: _ValidatorType[_T] | None
|
| 128 |
+
repr: _ReprArgType
|
| 129 |
+
cmp: _EqOrderType
|
| 130 |
+
eq: _EqOrderType
|
| 131 |
+
order: _EqOrderType
|
| 132 |
+
hash: bool | None
|
| 133 |
+
init: bool
|
| 134 |
+
converter: Converter | None
|
| 135 |
+
metadata: dict[Any, Any]
|
| 136 |
+
type: type[_T] | None
|
| 137 |
+
kw_only: bool
|
| 138 |
+
on_setattr: _OnSetAttrType
|
| 139 |
+
alias: str | None
|
| 140 |
+
|
| 141 |
+
def evolve(self, **changes: Any) -> "Attribute[Any]": ...
|
| 142 |
+
|
| 143 |
+
# NOTE: We had several choices for the annotation to use for type arg:
|
| 144 |
+
# 1) Type[_T]
|
| 145 |
+
# - Pros: Handles simple cases correctly
|
| 146 |
+
# - Cons: Might produce less informative errors in the case of conflicting
|
| 147 |
+
# TypeVars e.g. `attr.ib(default='bad', type=int)`
|
| 148 |
+
# 2) Callable[..., _T]
|
| 149 |
+
# - Pros: Better error messages than #1 for conflicting TypeVars
|
| 150 |
+
# - Cons: Terrible error messages for validator checks.
|
| 151 |
+
# e.g. attr.ib(type=int, validator=validate_str)
|
| 152 |
+
# -> error: Cannot infer function type argument
|
| 153 |
+
# 3) type (and do all of the work in the mypy plugin)
|
| 154 |
+
# - Pros: Simple here, and we could customize the plugin with our own errors.
|
| 155 |
+
# - Cons: Would need to write mypy plugin code to handle all the cases.
|
| 156 |
+
# We chose option #1.
|
| 157 |
+
|
| 158 |
+
# `attr` lies about its return type to make the following possible:
|
| 159 |
+
# attr() -> Any
|
| 160 |
+
# attr(8) -> int
|
| 161 |
+
# attr(validator=<some callable>) -> Whatever the callable expects.
|
| 162 |
+
# This makes this type of assignments possible:
|
| 163 |
+
# x: int = attr(8)
|
| 164 |
+
#
|
| 165 |
+
# This form catches explicit None or no default but with no other arguments
|
| 166 |
+
# returns Any.
|
| 167 |
+
@overload
|
| 168 |
+
def attrib(
|
| 169 |
+
default: None = ...,
|
| 170 |
+
validator: None = ...,
|
| 171 |
+
repr: _ReprArgType = ...,
|
| 172 |
+
cmp: _EqOrderType | None = ...,
|
| 173 |
+
hash: bool | None = ...,
|
| 174 |
+
init: bool = ...,
|
| 175 |
+
metadata: Mapping[Any, Any] | None = ...,
|
| 176 |
+
type: None = ...,
|
| 177 |
+
converter: None = ...,
|
| 178 |
+
factory: None = ...,
|
| 179 |
+
kw_only: bool = ...,
|
| 180 |
+
eq: _EqOrderType | None = ...,
|
| 181 |
+
order: _EqOrderType | None = ...,
|
| 182 |
+
on_setattr: _OnSetAttrArgType | None = ...,
|
| 183 |
+
alias: str | None = ...,
|
| 184 |
+
) -> Any: ...
|
| 185 |
+
|
| 186 |
+
# This form catches an explicit None or no default and infers the type from the
|
| 187 |
+
# other arguments.
|
| 188 |
+
@overload
|
| 189 |
+
def attrib(
|
| 190 |
+
default: None = ...,
|
| 191 |
+
validator: _ValidatorArgType[_T] | None = ...,
|
| 192 |
+
repr: _ReprArgType = ...,
|
| 193 |
+
cmp: _EqOrderType | None = ...,
|
| 194 |
+
hash: bool | None = ...,
|
| 195 |
+
init: bool = ...,
|
| 196 |
+
metadata: Mapping[Any, Any] | None = ...,
|
| 197 |
+
type: type[_T] | None = ...,
|
| 198 |
+
converter: _ConverterType
|
| 199 |
+
| list[_ConverterType]
|
| 200 |
+
| tuple[_ConverterType]
|
| 201 |
+
| None = ...,
|
| 202 |
+
factory: Callable[[], _T] | None = ...,
|
| 203 |
+
kw_only: bool = ...,
|
| 204 |
+
eq: _EqOrderType | None = ...,
|
| 205 |
+
order: _EqOrderType | None = ...,
|
| 206 |
+
on_setattr: _OnSetAttrArgType | None = ...,
|
| 207 |
+
alias: str | None = ...,
|
| 208 |
+
) -> _T: ...
|
| 209 |
+
|
| 210 |
+
# This form catches an explicit default argument.
|
| 211 |
+
@overload
|
| 212 |
+
def attrib(
|
| 213 |
+
default: _T,
|
| 214 |
+
validator: _ValidatorArgType[_T] | None = ...,
|
| 215 |
+
repr: _ReprArgType = ...,
|
| 216 |
+
cmp: _EqOrderType | None = ...,
|
| 217 |
+
hash: bool | None = ...,
|
| 218 |
+
init: bool = ...,
|
| 219 |
+
metadata: Mapping[Any, Any] | None = ...,
|
| 220 |
+
type: type[_T] | None = ...,
|
| 221 |
+
converter: _ConverterType
|
| 222 |
+
| list[_ConverterType]
|
| 223 |
+
| tuple[_ConverterType]
|
| 224 |
+
| None = ...,
|
| 225 |
+
factory: Callable[[], _T] | None = ...,
|
| 226 |
+
kw_only: bool = ...,
|
| 227 |
+
eq: _EqOrderType | None = ...,
|
| 228 |
+
order: _EqOrderType | None = ...,
|
| 229 |
+
on_setattr: _OnSetAttrArgType | None = ...,
|
| 230 |
+
alias: str | None = ...,
|
| 231 |
+
) -> _T: ...
|
| 232 |
+
|
| 233 |
+
# This form covers type=non-Type: e.g. forward references (str), Any
|
| 234 |
+
@overload
|
| 235 |
+
def attrib(
|
| 236 |
+
default: _T | None = ...,
|
| 237 |
+
validator: _ValidatorArgType[_T] | None = ...,
|
| 238 |
+
repr: _ReprArgType = ...,
|
| 239 |
+
cmp: _EqOrderType | None = ...,
|
| 240 |
+
hash: bool | None = ...,
|
| 241 |
+
init: bool = ...,
|
| 242 |
+
metadata: Mapping[Any, Any] | None = ...,
|
| 243 |
+
type: object = ...,
|
| 244 |
+
converter: _ConverterType
|
| 245 |
+
| list[_ConverterType]
|
| 246 |
+
| tuple[_ConverterType]
|
| 247 |
+
| None = ...,
|
| 248 |
+
factory: Callable[[], _T] | None = ...,
|
| 249 |
+
kw_only: bool = ...,
|
| 250 |
+
eq: _EqOrderType | None = ...,
|
| 251 |
+
order: _EqOrderType | None = ...,
|
| 252 |
+
on_setattr: _OnSetAttrArgType | None = ...,
|
| 253 |
+
alias: str | None = ...,
|
| 254 |
+
) -> Any: ...
|
| 255 |
+
@overload
|
| 256 |
+
@dataclass_transform(order_default=True, field_specifiers=(attrib, field))
|
| 257 |
+
def attrs(
|
| 258 |
+
maybe_cls: _C,
|
| 259 |
+
these: dict[str, Any] | None = ...,
|
| 260 |
+
repr_ns: str | None = ...,
|
| 261 |
+
repr: bool = ...,
|
| 262 |
+
cmp: _EqOrderType | None = ...,
|
| 263 |
+
hash: bool | None = ...,
|
| 264 |
+
init: bool = ...,
|
| 265 |
+
slots: bool = ...,
|
| 266 |
+
frozen: bool = ...,
|
| 267 |
+
weakref_slot: bool = ...,
|
| 268 |
+
str: bool = ...,
|
| 269 |
+
auto_attribs: bool = ...,
|
| 270 |
+
kw_only: bool = ...,
|
| 271 |
+
cache_hash: bool = ...,
|
| 272 |
+
auto_exc: bool = ...,
|
| 273 |
+
eq: _EqOrderType | None = ...,
|
| 274 |
+
order: _EqOrderType | None = ...,
|
| 275 |
+
auto_detect: bool = ...,
|
| 276 |
+
collect_by_mro: bool = ...,
|
| 277 |
+
getstate_setstate: bool | None = ...,
|
| 278 |
+
on_setattr: _OnSetAttrArgType | None = ...,
|
| 279 |
+
field_transformer: _FieldTransformer | None = ...,
|
| 280 |
+
match_args: bool = ...,
|
| 281 |
+
unsafe_hash: bool | None = ...,
|
| 282 |
+
) -> _C: ...
|
| 283 |
+
@overload
|
| 284 |
+
@dataclass_transform(order_default=True, field_specifiers=(attrib, field))
|
| 285 |
+
def attrs(
|
| 286 |
+
maybe_cls: None = ...,
|
| 287 |
+
these: dict[str, Any] | None = ...,
|
| 288 |
+
repr_ns: str | None = ...,
|
| 289 |
+
repr: bool = ...,
|
| 290 |
+
cmp: _EqOrderType | None = ...,
|
| 291 |
+
hash: bool | None = ...,
|
| 292 |
+
init: bool = ...,
|
| 293 |
+
slots: bool = ...,
|
| 294 |
+
frozen: bool = ...,
|
| 295 |
+
weakref_slot: bool = ...,
|
| 296 |
+
str: bool = ...,
|
| 297 |
+
auto_attribs: bool = ...,
|
| 298 |
+
kw_only: bool = ...,
|
| 299 |
+
cache_hash: bool = ...,
|
| 300 |
+
auto_exc: bool = ...,
|
| 301 |
+
eq: _EqOrderType | None = ...,
|
| 302 |
+
order: _EqOrderType | None = ...,
|
| 303 |
+
auto_detect: bool = ...,
|
| 304 |
+
collect_by_mro: bool = ...,
|
| 305 |
+
getstate_setstate: bool | None = ...,
|
| 306 |
+
on_setattr: _OnSetAttrArgType | None = ...,
|
| 307 |
+
field_transformer: _FieldTransformer | None = ...,
|
| 308 |
+
match_args: bool = ...,
|
| 309 |
+
unsafe_hash: bool | None = ...,
|
| 310 |
+
) -> Callable[[_C], _C]: ...
|
| 311 |
+
def fields(cls: type[AttrsInstance]) -> Any: ...
|
| 312 |
+
def fields_dict(cls: type[AttrsInstance]) -> dict[str, Attribute[Any]]: ...
|
| 313 |
+
def validate(inst: AttrsInstance) -> None: ...
|
| 314 |
+
def resolve_types(
|
| 315 |
+
cls: _A,
|
| 316 |
+
globalns: dict[str, Any] | None = ...,
|
| 317 |
+
localns: dict[str, Any] | None = ...,
|
| 318 |
+
attribs: list[Attribute[Any]] | None = ...,
|
| 319 |
+
include_extras: bool = ...,
|
| 320 |
+
) -> _A: ...
|
| 321 |
+
|
| 322 |
+
# TODO: add support for returning a proper attrs class from the mypy plugin
|
| 323 |
+
# we use Any instead of _CountingAttr so that e.g. `make_class('Foo',
|
| 324 |
+
# [attr.ib()])` is valid
|
| 325 |
+
def make_class(
|
| 326 |
+
name: str,
|
| 327 |
+
attrs: list[str] | tuple[str, ...] | dict[str, Any],
|
| 328 |
+
bases: tuple[type, ...] = ...,
|
| 329 |
+
class_body: dict[str, Any] | None = ...,
|
| 330 |
+
repr_ns: str | None = ...,
|
| 331 |
+
repr: bool = ...,
|
| 332 |
+
cmp: _EqOrderType | None = ...,
|
| 333 |
+
hash: bool | None = ...,
|
| 334 |
+
init: bool = ...,
|
| 335 |
+
slots: bool = ...,
|
| 336 |
+
frozen: bool = ...,
|
| 337 |
+
weakref_slot: bool = ...,
|
| 338 |
+
str: bool = ...,
|
| 339 |
+
auto_attribs: bool = ...,
|
| 340 |
+
kw_only: bool = ...,
|
| 341 |
+
cache_hash: bool = ...,
|
| 342 |
+
auto_exc: bool = ...,
|
| 343 |
+
eq: _EqOrderType | None = ...,
|
| 344 |
+
order: _EqOrderType | None = ...,
|
| 345 |
+
collect_by_mro: bool = ...,
|
| 346 |
+
on_setattr: _OnSetAttrArgType | None = ...,
|
| 347 |
+
field_transformer: _FieldTransformer | None = ...,
|
| 348 |
+
) -> type: ...
|
| 349 |
+
|
| 350 |
+
# _funcs --
|
| 351 |
+
|
| 352 |
+
# TODO: add support for returning TypedDict from the mypy plugin
|
| 353 |
+
# FIXME: asdict/astuple do not honor their factory args. Waiting on one of
|
| 354 |
+
# these:
|
| 355 |
+
# https://github.com/python/mypy/issues/4236
|
| 356 |
+
# https://github.com/python/typing/issues/253
|
| 357 |
+
# XXX: remember to fix attrs.asdict/astuple too!
|
| 358 |
+
def asdict(
|
| 359 |
+
inst: AttrsInstance,
|
| 360 |
+
recurse: bool = ...,
|
| 361 |
+
filter: _FilterType[Any] | None = ...,
|
| 362 |
+
dict_factory: type[Mapping[Any, Any]] = ...,
|
| 363 |
+
retain_collection_types: bool = ...,
|
| 364 |
+
value_serializer: Callable[[type, Attribute[Any], Any], Any] | None = ...,
|
| 365 |
+
tuple_keys: bool | None = ...,
|
| 366 |
+
) -> dict[str, Any]: ...
|
| 367 |
+
|
| 368 |
+
# TODO: add support for returning NamedTuple from the mypy plugin
|
| 369 |
+
def astuple(
|
| 370 |
+
inst: AttrsInstance,
|
| 371 |
+
recurse: bool = ...,
|
| 372 |
+
filter: _FilterType[Any] | None = ...,
|
| 373 |
+
tuple_factory: type[Sequence[Any]] = ...,
|
| 374 |
+
retain_collection_types: bool = ...,
|
| 375 |
+
) -> tuple[Any, ...]: ...
|
| 376 |
+
def has(cls: type) -> TypeGuard[type[AttrsInstance]]: ...
|
| 377 |
+
def assoc(inst: _T, **changes: Any) -> _T: ...
|
| 378 |
+
def evolve(inst: _T, **changes: Any) -> _T: ...
|
| 379 |
+
|
| 380 |
+
# _config --
|
| 381 |
+
|
| 382 |
+
def set_run_validators(run: bool) -> None: ...
|
| 383 |
+
def get_run_validators() -> bool: ...
|
| 384 |
+
|
| 385 |
+
# aliases --
|
| 386 |
+
|
| 387 |
+
s = attributes = attrs
|
| 388 |
+
ib = attr = attrib
|
| 389 |
+
dataclass = attrs # Technically, partial(attrs, auto_att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
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-License-Identifier: MIT
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
import functools
|
| 5 |
+
import types
|
| 6 |
+
|
| 7 |
+
from ._make import _make_ne
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
_operation_names = {"eq": "==", "lt": "<", "le": "<=", "gt": ">", "ge": ">="}
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def cmp_using(
|
| 14 |
+
eq=None,
|
| 15 |
+
lt=None,
|
| 16 |
+
le=None,
|
| 17 |
+
gt=None,
|
| 18 |
+
ge=None,
|
| 19 |
+
require_same_type=True,
|
| 20 |
+
class_name="Comparable",
|
| 21 |
+
):
|
| 22 |
+
"""
|
| 23 |
+
Create a class that can be passed into `attrs.field`'s ``eq``, ``order``,
|
| 24 |
+
and ``cmp`` arguments to customize field comparison.
|
| 25 |
+
|
| 26 |
+
The resulting class will have a full set of ordering methods if at least
|
| 27 |
+
one of ``{lt, le, gt, ge}`` and ``eq`` are provided.
|
| 28 |
+
|
| 29 |
+
Args:
|
| 30 |
+
eq (typing.Callable | None):
|
| 31 |
+
Callable used to evaluate equality of two objects.
|
| 32 |
+
|
| 33 |
+
lt (typing.Callable | None):
|
| 34 |
+
Callable used to evaluate whether one object is less than another
|
| 35 |
+
object.
|
| 36 |
+
|
| 37 |
+
le (typing.Callable | None):
|
| 38 |
+
Callable used to evaluate whether one object is less than or equal
|
| 39 |
+
to another object.
|
| 40 |
+
|
| 41 |
+
gt (typing.Callable | None):
|
| 42 |
+
Callable used to evaluate whether one object is greater than
|
| 43 |
+
another object.
|
| 44 |
+
|
| 45 |
+
ge (typing.Callable | None):
|
| 46 |
+
Callable used to evaluate whether one object is greater than or
|
| 47 |
+
equal to another object.
|
| 48 |
+
|
| 49 |
+
require_same_type (bool):
|
| 50 |
+
When `True`, equality and ordering methods will return
|
| 51 |
+
`NotImplemented` if objects are not of the same type.
|
| 52 |
+
|
| 53 |
+
class_name (str | None): Name of class. Defaults to "Comparable".
|
| 54 |
+
|
| 55 |
+
See `comparison` for more details.
|
| 56 |
+
|
| 57 |
+
.. versionadded:: 21.1.0
|
| 58 |
+
"""
|
| 59 |
+
|
| 60 |
+
body = {
|
| 61 |
+
"__slots__": ["value"],
|
| 62 |
+
"__init__": _make_init(),
|
| 63 |
+
"_requirements": [],
|
| 64 |
+
"_is_comparable_to": _is_comparable_to,
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
# Add operations.
|
| 68 |
+
num_order_functions = 0
|
| 69 |
+
has_eq_function = False
|
| 70 |
+
|
| 71 |
+
if eq is not None:
|
| 72 |
+
has_eq_function = True
|
| 73 |
+
body["__eq__"] = _make_operator("eq", eq)
|
| 74 |
+
body["__ne__"] = _make_ne()
|
| 75 |
+
|
| 76 |
+
if lt is not None:
|
| 77 |
+
num_order_functions += 1
|
| 78 |
+
body["__lt__"] = _make_operator("lt", lt)
|
| 79 |
+
|
| 80 |
+
if le is not None:
|
| 81 |
+
num_order_functions += 1
|
| 82 |
+
body["__le__"] = _make_operator("le", le)
|
| 83 |
+
|
| 84 |
+
if gt is not None:
|
| 85 |
+
num_order_functions += 1
|
| 86 |
+
body["__gt__"] = _make_operator("gt", gt)
|
| 87 |
+
|
| 88 |
+
if ge is not None:
|
| 89 |
+
num_order_functions += 1
|
| 90 |
+
body["__ge__"] = _make_operator("ge", ge)
|
| 91 |
+
|
| 92 |
+
type_ = types.new_class(
|
| 93 |
+
class_name, (object,), {}, lambda ns: ns.update(body)
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
# Add same type requirement.
|
| 97 |
+
if require_same_type:
|
| 98 |
+
type_._requirements.append(_check_same_type)
|
| 99 |
+
|
| 100 |
+
# Add total ordering if at least one operation was defined.
|
| 101 |
+
if 0 < num_order_functions < 4:
|
| 102 |
+
if not has_eq_function:
|
| 103 |
+
# functools.total_ordering requires __eq__ to be defined,
|
| 104 |
+
# so raise early error here to keep a nice stack.
|
| 105 |
+
msg = "eq must be define is order to complete ordering from lt, le, gt, ge."
|
| 106 |
+
raise ValueError(msg)
|
| 107 |
+
type_ = functools.total_ordering(type_)
|
| 108 |
+
|
| 109 |
+
return type_
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
def _make_init():
|
| 113 |
+
"""
|
| 114 |
+
Create __init__ method.
|
| 115 |
+
"""
|
| 116 |
+
|
| 117 |
+
def __init__(self, value):
|
| 118 |
+
"""
|
| 119 |
+
Initialize object with *value*.
|
| 120 |
+
"""
|
| 121 |
+
self.value = value
|
| 122 |
+
|
| 123 |
+
return __init__
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
def _make_operator(name, func):
|
| 127 |
+
"""
|
| 128 |
+
Create operator method.
|
| 129 |
+
"""
|
| 130 |
+
|
| 131 |
+
def method(self, other):
|
| 132 |
+
if not self._is_comparable_to(other):
|
| 133 |
+
return NotImplemented
|
| 134 |
+
|
| 135 |
+
result = func(self.value, other.value)
|
| 136 |
+
if result is NotImplemented:
|
| 137 |
+
return NotImplemented
|
| 138 |
+
|
| 139 |
+
return result
|
| 140 |
+
|
| 141 |
+
method.__name__ = f"__{name}__"
|
| 142 |
+
method.__doc__ = (
|
| 143 |
+
f"Return a {_operation_names[name]} b. Computed by attrs."
|
| 144 |
+
)
|
| 145 |
+
|
| 146 |
+
return method
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
def _is_comparable_to(self, other):
|
| 150 |
+
"""
|
| 151 |
+
Check whether `other` is comparable to `self`.
|
| 152 |
+
"""
|
| 153 |
+
return all(func(self, other) for func in self._requirements)
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
def _check_same_type(self, other):
|
| 157 |
+
"""
|
| 158 |
+
Return True if *self* and *other* are of the same type, False otherwise.
|
| 159 |
+
"""
|
| 160 |
+
return other.value.__class__ is self.value.__class__
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/_cmp.pyi
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any, Callable
|
| 2 |
+
|
| 3 |
+
_CompareWithType = Callable[[Any, Any], bool]
|
| 4 |
+
|
| 5 |
+
def cmp_using(
|
| 6 |
+
eq: _CompareWithType | None = ...,
|
| 7 |
+
lt: _CompareWithType | None = ...,
|
| 8 |
+
le: _CompareWithType | None = ...,
|
| 9 |
+
gt: _CompareWithType | None = ...,
|
| 10 |
+
ge: _CompareWithType | None = ...,
|
| 11 |
+
require_same_type: bool = ...,
|
| 12 |
+
class_name: str = ...,
|
| 13 |
+
) -> type: ...
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/_compat.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-License-Identifier: MIT
|
| 2 |
+
|
| 3 |
+
import inspect
|
| 4 |
+
import platform
|
| 5 |
+
import sys
|
| 6 |
+
import threading
|
| 7 |
+
|
| 8 |
+
from collections.abc import Mapping, Sequence # noqa: F401
|
| 9 |
+
from typing import _GenericAlias
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
PYPY = platform.python_implementation() == "PyPy"
|
| 13 |
+
PY_3_9_PLUS = sys.version_info[:2] >= (3, 9)
|
| 14 |
+
PY_3_10_PLUS = sys.version_info[:2] >= (3, 10)
|
| 15 |
+
PY_3_11_PLUS = sys.version_info[:2] >= (3, 11)
|
| 16 |
+
PY_3_12_PLUS = sys.version_info[:2] >= (3, 12)
|
| 17 |
+
PY_3_13_PLUS = sys.version_info[:2] >= (3, 13)
|
| 18 |
+
PY_3_14_PLUS = sys.version_info[:2] >= (3, 14)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
if PY_3_14_PLUS: # pragma: no cover
|
| 22 |
+
import annotationlib
|
| 23 |
+
|
| 24 |
+
_get_annotations = annotationlib.get_annotations
|
| 25 |
+
|
| 26 |
+
else:
|
| 27 |
+
|
| 28 |
+
def _get_annotations(cls):
|
| 29 |
+
"""
|
| 30 |
+
Get annotations for *cls*.
|
| 31 |
+
"""
|
| 32 |
+
return cls.__dict__.get("__annotations__", {})
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
class _AnnotationExtractor:
|
| 36 |
+
"""
|
| 37 |
+
Extract type annotations from a callable, returning None whenever there
|
| 38 |
+
is none.
|
| 39 |
+
"""
|
| 40 |
+
|
| 41 |
+
__slots__ = ["sig"]
|
| 42 |
+
|
| 43 |
+
def __init__(self, callable):
|
| 44 |
+
try:
|
| 45 |
+
self.sig = inspect.signature(callable)
|
| 46 |
+
except (ValueError, TypeError): # inspect failed
|
| 47 |
+
self.sig = None
|
| 48 |
+
|
| 49 |
+
def get_first_param_type(self):
|
| 50 |
+
"""
|
| 51 |
+
Return the type annotation of the first argument if it's not empty.
|
| 52 |
+
"""
|
| 53 |
+
if not self.sig:
|
| 54 |
+
return None
|
| 55 |
+
|
| 56 |
+
params = list(self.sig.parameters.values())
|
| 57 |
+
if params and params[0].annotation is not inspect.Parameter.empty:
|
| 58 |
+
return params[0].annotation
|
| 59 |
+
|
| 60 |
+
return None
|
| 61 |
+
|
| 62 |
+
def get_return_type(self):
|
| 63 |
+
"""
|
| 64 |
+
Return the return type if it's not empty.
|
| 65 |
+
"""
|
| 66 |
+
if (
|
| 67 |
+
self.sig
|
| 68 |
+
and self.sig.return_annotation is not inspect.Signature.empty
|
| 69 |
+
):
|
| 70 |
+
return self.sig.return_annotation
|
| 71 |
+
|
| 72 |
+
return None
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
# Thread-local global to track attrs instances which are already being repr'd.
|
| 76 |
+
# This is needed because there is no other (thread-safe) way to pass info
|
| 77 |
+
# about the instances that are already being repr'd through the call stack
|
| 78 |
+
# in order to ensure we don't perform infinite recursion.
|
| 79 |
+
#
|
| 80 |
+
# For instance, if an instance contains a dict which contains that instance,
|
| 81 |
+
# we need to know that we're already repr'ing the outside instance from within
|
| 82 |
+
# the dict's repr() call.
|
| 83 |
+
#
|
| 84 |
+
# This lives here rather than in _make.py so that the functions in _make.py
|
| 85 |
+
# don't have a direct reference to the thread-local in their globals dict.
|
| 86 |
+
# If they have such a reference, it breaks cloudpickle.
|
| 87 |
+
repr_context = threading.local()
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def get_generic_base(cl):
|
| 91 |
+
"""If this is a generic class (A[str]), return the generic base for it."""
|
| 92 |
+
if cl.__class__ is _GenericAlias:
|
| 93 |
+
return cl.__origin__
|
| 94 |
+
return None
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/_config.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-License-Identifier: MIT
|
| 2 |
+
|
| 3 |
+
__all__ = ["get_run_validators", "set_run_validators"]
|
| 4 |
+
|
| 5 |
+
_run_validators = True
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def set_run_validators(run):
|
| 9 |
+
"""
|
| 10 |
+
Set whether or not validators are run. By default, they are run.
|
| 11 |
+
|
| 12 |
+
.. deprecated:: 21.3.0 It will not be removed, but it also will not be
|
| 13 |
+
moved to new ``attrs`` namespace. Use `attrs.validators.set_disabled()`
|
| 14 |
+
instead.
|
| 15 |
+
"""
|
| 16 |
+
if not isinstance(run, bool):
|
| 17 |
+
msg = "'run' must be bool."
|
| 18 |
+
raise TypeError(msg)
|
| 19 |
+
global _run_validators
|
| 20 |
+
_run_validators = run
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def get_run_validators():
|
| 24 |
+
"""
|
| 25 |
+
Return whether or not validators are run.
|
| 26 |
+
|
| 27 |
+
.. deprecated:: 21.3.0 It will not be removed, but it also will not be
|
| 28 |
+
moved to new ``attrs`` namespace. Use `attrs.validators.get_disabled()`
|
| 29 |
+
instead.
|
| 30 |
+
"""
|
| 31 |
+
return _run_validators
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/_funcs.py
ADDED
|
@@ -0,0 +1,468 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-License-Identifier: MIT
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
import copy
|
| 5 |
+
|
| 6 |
+
from ._compat import PY_3_9_PLUS, get_generic_base
|
| 7 |
+
from ._make import _OBJ_SETATTR, NOTHING, fields
|
| 8 |
+
from .exceptions import AttrsAttributeNotFoundError
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def asdict(
|
| 12 |
+
inst,
|
| 13 |
+
recurse=True,
|
| 14 |
+
filter=None,
|
| 15 |
+
dict_factory=dict,
|
| 16 |
+
retain_collection_types=False,
|
| 17 |
+
value_serializer=None,
|
| 18 |
+
):
|
| 19 |
+
"""
|
| 20 |
+
Return the *attrs* attribute values of *inst* as a dict.
|
| 21 |
+
|
| 22 |
+
Optionally recurse into other *attrs*-decorated classes.
|
| 23 |
+
|
| 24 |
+
Args:
|
| 25 |
+
inst: Instance of an *attrs*-decorated class.
|
| 26 |
+
|
| 27 |
+
recurse (bool): Recurse into classes that are also *attrs*-decorated.
|
| 28 |
+
|
| 29 |
+
filter (~typing.Callable):
|
| 30 |
+
A callable whose return code determines whether an attribute or
|
| 31 |
+
element is included (`True`) or dropped (`False`). Is called with
|
| 32 |
+
the `attrs.Attribute` as the first argument and the value as the
|
| 33 |
+
second argument.
|
| 34 |
+
|
| 35 |
+
dict_factory (~typing.Callable):
|
| 36 |
+
A callable to produce dictionaries from. For example, to produce
|
| 37 |
+
ordered dictionaries instead of normal Python dictionaries, pass in
|
| 38 |
+
``collections.OrderedDict``.
|
| 39 |
+
|
| 40 |
+
retain_collection_types (bool):
|
| 41 |
+
Do not convert to `list` when encountering an attribute whose type
|
| 42 |
+
is `tuple` or `set`. Only meaningful if *recurse* is `True`.
|
| 43 |
+
|
| 44 |
+
value_serializer (typing.Callable | None):
|
| 45 |
+
A hook that is called for every attribute or dict key/value. It
|
| 46 |
+
receives the current instance, field and value and must return the
|
| 47 |
+
(updated) value. The hook is run *after* the optional *filter* has
|
| 48 |
+
been applied.
|
| 49 |
+
|
| 50 |
+
Returns:
|
| 51 |
+
Return type of *dict_factory*.
|
| 52 |
+
|
| 53 |
+
Raises:
|
| 54 |
+
attrs.exceptions.NotAnAttrsClassError:
|
| 55 |
+
If *cls* is not an *attrs* class.
|
| 56 |
+
|
| 57 |
+
.. versionadded:: 16.0.0 *dict_factory*
|
| 58 |
+
.. versionadded:: 16.1.0 *retain_collection_types*
|
| 59 |
+
.. versionadded:: 20.3.0 *value_serializer*
|
| 60 |
+
.. versionadded:: 21.3.0
|
| 61 |
+
If a dict has a collection for a key, it is serialized as a tuple.
|
| 62 |
+
"""
|
| 63 |
+
attrs = fields(inst.__class__)
|
| 64 |
+
rv = dict_factory()
|
| 65 |
+
for a in attrs:
|
| 66 |
+
v = getattr(inst, a.name)
|
| 67 |
+
if filter is not None and not filter(a, v):
|
| 68 |
+
continue
|
| 69 |
+
|
| 70 |
+
if value_serializer is not None:
|
| 71 |
+
v = value_serializer(inst, a, v)
|
| 72 |
+
|
| 73 |
+
if recurse is True:
|
| 74 |
+
if has(v.__class__):
|
| 75 |
+
rv[a.name] = asdict(
|
| 76 |
+
v,
|
| 77 |
+
recurse=True,
|
| 78 |
+
filter=filter,
|
| 79 |
+
dict_factory=dict_factory,
|
| 80 |
+
retain_collection_types=retain_collection_types,
|
| 81 |
+
value_serializer=value_serializer,
|
| 82 |
+
)
|
| 83 |
+
elif isinstance(v, (tuple, list, set, frozenset)):
|
| 84 |
+
cf = v.__class__ if retain_collection_types is True else list
|
| 85 |
+
items = [
|
| 86 |
+
_asdict_anything(
|
| 87 |
+
i,
|
| 88 |
+
is_key=False,
|
| 89 |
+
filter=filter,
|
| 90 |
+
dict_factory=dict_factory,
|
| 91 |
+
retain_collection_types=retain_collection_types,
|
| 92 |
+
value_serializer=value_serializer,
|
| 93 |
+
)
|
| 94 |
+
for i in v
|
| 95 |
+
]
|
| 96 |
+
try:
|
| 97 |
+
rv[a.name] = cf(items)
|
| 98 |
+
except TypeError:
|
| 99 |
+
if not issubclass(cf, tuple):
|
| 100 |
+
raise
|
| 101 |
+
# Workaround for TypeError: cf.__new__() missing 1 required
|
| 102 |
+
# positional argument (which appears, for a namedturle)
|
| 103 |
+
rv[a.name] = cf(*items)
|
| 104 |
+
elif isinstance(v, dict):
|
| 105 |
+
df = dict_factory
|
| 106 |
+
rv[a.name] = df(
|
| 107 |
+
(
|
| 108 |
+
_asdict_anything(
|
| 109 |
+
kk,
|
| 110 |
+
is_key=True,
|
| 111 |
+
filter=filter,
|
| 112 |
+
dict_factory=df,
|
| 113 |
+
retain_collection_types=retain_collection_types,
|
| 114 |
+
value_serializer=value_serializer,
|
| 115 |
+
),
|
| 116 |
+
_asdict_anything(
|
| 117 |
+
vv,
|
| 118 |
+
is_key=False,
|
| 119 |
+
filter=filter,
|
| 120 |
+
dict_factory=df,
|
| 121 |
+
retain_collection_types=retain_collection_types,
|
| 122 |
+
value_serializer=value_serializer,
|
| 123 |
+
),
|
| 124 |
+
)
|
| 125 |
+
for kk, vv in v.items()
|
| 126 |
+
)
|
| 127 |
+
else:
|
| 128 |
+
rv[a.name] = v
|
| 129 |
+
else:
|
| 130 |
+
rv[a.name] = v
|
| 131 |
+
return rv
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def _asdict_anything(
|
| 135 |
+
val,
|
| 136 |
+
is_key,
|
| 137 |
+
filter,
|
| 138 |
+
dict_factory,
|
| 139 |
+
retain_collection_types,
|
| 140 |
+
value_serializer,
|
| 141 |
+
):
|
| 142 |
+
"""
|
| 143 |
+
``asdict`` only works on attrs instances, this works on anything.
|
| 144 |
+
"""
|
| 145 |
+
if getattr(val.__class__, "__attrs_attrs__", None) is not None:
|
| 146 |
+
# Attrs class.
|
| 147 |
+
rv = asdict(
|
| 148 |
+
val,
|
| 149 |
+
recurse=True,
|
| 150 |
+
filter=filter,
|
| 151 |
+
dict_factory=dict_factory,
|
| 152 |
+
retain_collection_types=retain_collection_types,
|
| 153 |
+
value_serializer=value_serializer,
|
| 154 |
+
)
|
| 155 |
+
elif isinstance(val, (tuple, list, set, frozenset)):
|
| 156 |
+
if retain_collection_types is True:
|
| 157 |
+
cf = val.__class__
|
| 158 |
+
elif is_key:
|
| 159 |
+
cf = tuple
|
| 160 |
+
else:
|
| 161 |
+
cf = list
|
| 162 |
+
|
| 163 |
+
rv = cf(
|
| 164 |
+
[
|
| 165 |
+
_asdict_anything(
|
| 166 |
+
i,
|
| 167 |
+
is_key=False,
|
| 168 |
+
filter=filter,
|
| 169 |
+
dict_factory=dict_factory,
|
| 170 |
+
retain_collection_types=retain_collection_types,
|
| 171 |
+
value_serializer=value_serializer,
|
| 172 |
+
)
|
| 173 |
+
for i in val
|
| 174 |
+
]
|
| 175 |
+
)
|
| 176 |
+
elif isinstance(val, dict):
|
| 177 |
+
df = dict_factory
|
| 178 |
+
rv = df(
|
| 179 |
+
(
|
| 180 |
+
_asdict_anything(
|
| 181 |
+
kk,
|
| 182 |
+
is_key=True,
|
| 183 |
+
filter=filter,
|
| 184 |
+
dict_factory=df,
|
| 185 |
+
retain_collection_types=retain_collection_types,
|
| 186 |
+
value_serializer=value_serializer,
|
| 187 |
+
),
|
| 188 |
+
_asdict_anything(
|
| 189 |
+
vv,
|
| 190 |
+
is_key=False,
|
| 191 |
+
filter=filter,
|
| 192 |
+
dict_factory=df,
|
| 193 |
+
retain_collection_types=retain_collection_types,
|
| 194 |
+
value_serializer=value_serializer,
|
| 195 |
+
),
|
| 196 |
+
)
|
| 197 |
+
for kk, vv in val.items()
|
| 198 |
+
)
|
| 199 |
+
else:
|
| 200 |
+
rv = val
|
| 201 |
+
if value_serializer is not None:
|
| 202 |
+
rv = value_serializer(None, None, rv)
|
| 203 |
+
|
| 204 |
+
return rv
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
def astuple(
|
| 208 |
+
inst,
|
| 209 |
+
recurse=True,
|
| 210 |
+
filter=None,
|
| 211 |
+
tuple_factory=tuple,
|
| 212 |
+
retain_collection_types=False,
|
| 213 |
+
):
|
| 214 |
+
"""
|
| 215 |
+
Return the *attrs* attribute values of *inst* as a tuple.
|
| 216 |
+
|
| 217 |
+
Optionally recurse into other *attrs*-decorated classes.
|
| 218 |
+
|
| 219 |
+
Args:
|
| 220 |
+
inst: Instance of an *attrs*-decorated class.
|
| 221 |
+
|
| 222 |
+
recurse (bool):
|
| 223 |
+
Recurse into classes that are also *attrs*-decorated.
|
| 224 |
+
|
| 225 |
+
filter (~typing.Callable):
|
| 226 |
+
A callable whose return code determines whether an attribute or
|
| 227 |
+
element is included (`True`) or dropped (`False`). Is called with
|
| 228 |
+
the `attrs.Attribute` as the first argument and the value as the
|
| 229 |
+
second argument.
|
| 230 |
+
|
| 231 |
+
tuple_factory (~typing.Callable):
|
| 232 |
+
A callable to produce tuples from. For example, to produce lists
|
| 233 |
+
instead of tuples.
|
| 234 |
+
|
| 235 |
+
retain_collection_types (bool):
|
| 236 |
+
Do not convert to `list` or `dict` when encountering an attribute
|
| 237 |
+
which type is `tuple`, `dict` or `set`. Only meaningful if
|
| 238 |
+
*recurse* is `True`.
|
| 239 |
+
|
| 240 |
+
Returns:
|
| 241 |
+
Return type of *tuple_factory*
|
| 242 |
+
|
| 243 |
+
Raises:
|
| 244 |
+
attrs.exceptions.NotAnAttrsClassError:
|
| 245 |
+
If *cls* is not an *attrs* class.
|
| 246 |
+
|
| 247 |
+
.. versionadded:: 16.2.0
|
| 248 |
+
"""
|
| 249 |
+
attrs = fields(inst.__class__)
|
| 250 |
+
rv = []
|
| 251 |
+
retain = retain_collection_types # Very long. :/
|
| 252 |
+
for a in attrs:
|
| 253 |
+
v = getattr(inst, a.name)
|
| 254 |
+
if filter is not None and not filter(a, v):
|
| 255 |
+
continue
|
| 256 |
+
if recurse is True:
|
| 257 |
+
if has(v.__class__):
|
| 258 |
+
rv.append(
|
| 259 |
+
astuple(
|
| 260 |
+
v,
|
| 261 |
+
recurse=True,
|
| 262 |
+
filter=filter,
|
| 263 |
+
tuple_factory=tuple_factory,
|
| 264 |
+
retain_collection_types=retain,
|
| 265 |
+
)
|
| 266 |
+
)
|
| 267 |
+
elif isinstance(v, (tuple, list, set, frozenset)):
|
| 268 |
+
cf = v.__class__ if retain is True else list
|
| 269 |
+
items = [
|
| 270 |
+
(
|
| 271 |
+
astuple(
|
| 272 |
+
j,
|
| 273 |
+
recurse=True,
|
| 274 |
+
filter=filter,
|
| 275 |
+
tuple_factory=tuple_factory,
|
| 276 |
+
retain_collection_types=retain,
|
| 277 |
+
)
|
| 278 |
+
if has(j.__class__)
|
| 279 |
+
else j
|
| 280 |
+
)
|
| 281 |
+
for j in v
|
| 282 |
+
]
|
| 283 |
+
try:
|
| 284 |
+
rv.append(cf(items))
|
| 285 |
+
except TypeError:
|
| 286 |
+
if not issubclass(cf, tuple):
|
| 287 |
+
raise
|
| 288 |
+
# Workaround for TypeError: cf.__new__() missing 1 required
|
| 289 |
+
# positional argument (which appears, for a namedturle)
|
| 290 |
+
rv.append(cf(*items))
|
| 291 |
+
elif isinstance(v, dict):
|
| 292 |
+
df = v.__class__ if retain is True else dict
|
| 293 |
+
rv.append(
|
| 294 |
+
df(
|
| 295 |
+
(
|
| 296 |
+
(
|
| 297 |
+
astuple(
|
| 298 |
+
kk,
|
| 299 |
+
tuple_factory=tuple_factory,
|
| 300 |
+
retain_collection_types=retain,
|
| 301 |
+
)
|
| 302 |
+
if has(kk.__class__)
|
| 303 |
+
else kk
|
| 304 |
+
),
|
| 305 |
+
(
|
| 306 |
+
astuple(
|
| 307 |
+
vv,
|
| 308 |
+
tuple_factory=tuple_factory,
|
| 309 |
+
retain_collection_types=retain,
|
| 310 |
+
)
|
| 311 |
+
if has(vv.__class__)
|
| 312 |
+
else vv
|
| 313 |
+
),
|
| 314 |
+
)
|
| 315 |
+
for kk, vv in v.items()
|
| 316 |
+
)
|
| 317 |
+
)
|
| 318 |
+
else:
|
| 319 |
+
rv.append(v)
|
| 320 |
+
else:
|
| 321 |
+
rv.append(v)
|
| 322 |
+
|
| 323 |
+
return rv if tuple_factory is list else tuple_factory(rv)
|
| 324 |
+
|
| 325 |
+
|
| 326 |
+
def has(cls):
|
| 327 |
+
"""
|
| 328 |
+
Check whether *cls* is a class with *attrs* attributes.
|
| 329 |
+
|
| 330 |
+
Args:
|
| 331 |
+
cls (type): Class to introspect.
|
| 332 |
+
|
| 333 |
+
Raises:
|
| 334 |
+
TypeError: If *cls* is not a class.
|
| 335 |
+
|
| 336 |
+
Returns:
|
| 337 |
+
bool:
|
| 338 |
+
"""
|
| 339 |
+
attrs = getattr(cls, "__attrs_attrs__", None)
|
| 340 |
+
if attrs is not None:
|
| 341 |
+
return True
|
| 342 |
+
|
| 343 |
+
# No attrs, maybe it's a specialized generic (A[str])?
|
| 344 |
+
generic_base = get_generic_base(cls)
|
| 345 |
+
if generic_base is not None:
|
| 346 |
+
generic_attrs = getattr(generic_base, "__attrs_attrs__", None)
|
| 347 |
+
if generic_attrs is not None:
|
| 348 |
+
# Stick it on here for speed next time.
|
| 349 |
+
cls.__attrs_attrs__ = generic_attrs
|
| 350 |
+
return generic_attrs is not None
|
| 351 |
+
return False
|
| 352 |
+
|
| 353 |
+
|
| 354 |
+
def assoc(inst, **changes):
|
| 355 |
+
"""
|
| 356 |
+
Copy *inst* and apply *changes*.
|
| 357 |
+
|
| 358 |
+
This is different from `evolve` that applies the changes to the arguments
|
| 359 |
+
that create the new instance.
|
| 360 |
+
|
| 361 |
+
`evolve`'s behavior is preferable, but there are `edge cases`_ where it
|
| 362 |
+
doesn't work. Therefore `assoc` is deprecated, but will not be removed.
|
| 363 |
+
|
| 364 |
+
.. _`edge cases`: https://github.com/python-attrs/attrs/issues/251
|
| 365 |
+
|
| 366 |
+
Args:
|
| 367 |
+
inst: Instance of a class with *attrs* attributes.
|
| 368 |
+
|
| 369 |
+
changes: Keyword changes in the new copy.
|
| 370 |
+
|
| 371 |
+
Returns:
|
| 372 |
+
A copy of inst with *changes* incorporated.
|
| 373 |
+
|
| 374 |
+
Raises:
|
| 375 |
+
attrs.exceptions.AttrsAttributeNotFoundError:
|
| 376 |
+
If *attr_name* couldn't be found on *cls*.
|
| 377 |
+
|
| 378 |
+
attrs.exceptions.NotAnAttrsClassError:
|
| 379 |
+
If *cls* is not an *attrs* class.
|
| 380 |
+
|
| 381 |
+
.. deprecated:: 17.1.0
|
| 382 |
+
Use `attrs.evolve` instead if you can. This function will not be
|
| 383 |
+
removed du to the slightly different approach compared to
|
| 384 |
+
`attrs.evolve`, though.
|
| 385 |
+
"""
|
| 386 |
+
new = copy.copy(inst)
|
| 387 |
+
attrs = fields(inst.__class__)
|
| 388 |
+
for k, v in changes.items():
|
| 389 |
+
a = getattr(attrs, k, NOTHING)
|
| 390 |
+
if a is NOTHING:
|
| 391 |
+
msg = f"{k} is not an attrs attribute on {new.__class__}."
|
| 392 |
+
raise AttrsAttributeNotFoundError(msg)
|
| 393 |
+
_OBJ_SETATTR(new, k, v)
|
| 394 |
+
return new
|
| 395 |
+
|
| 396 |
+
|
| 397 |
+
def resolve_types(
|
| 398 |
+
cls, globalns=None, localns=None, attribs=None, include_extras=True
|
| 399 |
+
):
|
| 400 |
+
"""
|
| 401 |
+
Resolve any strings and forward annotations in type annotations.
|
| 402 |
+
|
| 403 |
+
This is only required if you need concrete types in :class:`Attribute`'s
|
| 404 |
+
*type* field. In other words, you don't need to resolve your types if you
|
| 405 |
+
only use them for static type checking.
|
| 406 |
+
|
| 407 |
+
With no arguments, names will be looked up in the module in which the class
|
| 408 |
+
was created. If this is not what you want, for example, if the name only
|
| 409 |
+
exists inside a method, you may pass *globalns* or *localns* to specify
|
| 410 |
+
other dictionaries in which to look up these names. See the docs of
|
| 411 |
+
`typing.get_type_hints` for more details.
|
| 412 |
+
|
| 413 |
+
Args:
|
| 414 |
+
cls (type): Class to resolve.
|
| 415 |
+
|
| 416 |
+
globalns (dict | None): Dictionary containing global variables.
|
| 417 |
+
|
| 418 |
+
localns (dict | None): Dictionary containing local variables.
|
| 419 |
+
|
| 420 |
+
attribs (list | None):
|
| 421 |
+
List of attribs for the given class. This is necessary when calling
|
| 422 |
+
from inside a ``field_transformer`` since *cls* is not an *attrs*
|
| 423 |
+
class yet.
|
| 424 |
+
|
| 425 |
+
include_extras (bool):
|
| 426 |
+
Resolve more accurately, if possible. Pass ``include_extras`` to
|
| 427 |
+
``typing.get_hints``, if supported by the typing module. On
|
| 428 |
+
supported Python versions (3.9+), this resolves the types more
|
| 429 |
+
accurately.
|
| 430 |
+
|
| 431 |
+
Raises:
|
| 432 |
+
TypeError: If *cls* is not a class.
|
| 433 |
+
|
| 434 |
+
attrs.exceptions.NotAnAttrsClassError:
|
| 435 |
+
If *cls* is not an *attrs* class and you didn't pass any attribs.
|
| 436 |
+
|
| 437 |
+
NameError: If types cannot be resolved because of missing variables.
|
| 438 |
+
|
| 439 |
+
Returns:
|
| 440 |
+
*cls* so you can use this function also as a class decorator. Please
|
| 441 |
+
note that you have to apply it **after** `attrs.define`. That means the
|
| 442 |
+
decorator has to come in the line **before** `attrs.define`.
|
| 443 |
+
|
| 444 |
+
.. versionadded:: 20.1.0
|
| 445 |
+
.. versionadded:: 21.1.0 *attribs*
|
| 446 |
+
.. versionadded:: 23.1.0 *include_extras*
|
| 447 |
+
"""
|
| 448 |
+
# Since calling get_type_hints is expensive we cache whether we've
|
| 449 |
+
# done it already.
|
| 450 |
+
if getattr(cls, "__attrs_types_resolved__", None) != cls:
|
| 451 |
+
import typing
|
| 452 |
+
|
| 453 |
+
kwargs = {"globalns": globalns, "localns": localns}
|
| 454 |
+
|
| 455 |
+
if PY_3_9_PLUS:
|
| 456 |
+
kwargs["include_extras"] = include_extras
|
| 457 |
+
|
| 458 |
+
hints = typing.get_type_hints(cls, **kwargs)
|
| 459 |
+
for field in fields(cls) if attribs is None else attribs:
|
| 460 |
+
if field.name in hints:
|
| 461 |
+
# Since fields have been frozen we must work around it.
|
| 462 |
+
_OBJ_SETATTR(field, "type", hints[field.name])
|
| 463 |
+
# We store the class we resolved so that subclasses know they haven't
|
| 464 |
+
# been resolved.
|
| 465 |
+
cls.__attrs_types_resolved__ = cls
|
| 466 |
+
|
| 467 |
+
# Return the class so you can use it as a decorator too.
|
| 468 |
+
return cls
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/_make.py
ADDED
|
@@ -0,0 +1,3055 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-License-Identifier: MIT
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import abc
|
| 6 |
+
import contextlib
|
| 7 |
+
import copy
|
| 8 |
+
import enum
|
| 9 |
+
import functools
|
| 10 |
+
import inspect
|
| 11 |
+
import itertools
|
| 12 |
+
import linecache
|
| 13 |
+
import sys
|
| 14 |
+
import types
|
| 15 |
+
import typing
|
| 16 |
+
|
| 17 |
+
from operator import itemgetter
|
| 18 |
+
|
| 19 |
+
# We need to import _compat itself in addition to the _compat members to avoid
|
| 20 |
+
# having the thread-local in the globals here.
|
| 21 |
+
from . import _compat, _config, setters
|
| 22 |
+
from ._compat import (
|
| 23 |
+
PY_3_10_PLUS,
|
| 24 |
+
PY_3_11_PLUS,
|
| 25 |
+
PY_3_13_PLUS,
|
| 26 |
+
_AnnotationExtractor,
|
| 27 |
+
_get_annotations,
|
| 28 |
+
get_generic_base,
|
| 29 |
+
)
|
| 30 |
+
from .exceptions import (
|
| 31 |
+
DefaultAlreadySetError,
|
| 32 |
+
FrozenInstanceError,
|
| 33 |
+
NotAnAttrsClassError,
|
| 34 |
+
UnannotatedAttributeError,
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
# This is used at least twice, so cache it here.
|
| 39 |
+
_OBJ_SETATTR = object.__setattr__
|
| 40 |
+
_INIT_FACTORY_PAT = "__attr_factory_%s"
|
| 41 |
+
_CLASSVAR_PREFIXES = (
|
| 42 |
+
"typing.ClassVar",
|
| 43 |
+
"t.ClassVar",
|
| 44 |
+
"ClassVar",
|
| 45 |
+
"typing_extensions.ClassVar",
|
| 46 |
+
)
|
| 47 |
+
# we don't use a double-underscore prefix because that triggers
|
| 48 |
+
# name mangling when trying to create a slot for the field
|
| 49 |
+
# (when slots=True)
|
| 50 |
+
_HASH_CACHE_FIELD = "_attrs_cached_hash"
|
| 51 |
+
|
| 52 |
+
_EMPTY_METADATA_SINGLETON = types.MappingProxyType({})
|
| 53 |
+
|
| 54 |
+
# Unique object for unequivocal getattr() defaults.
|
| 55 |
+
_SENTINEL = object()
|
| 56 |
+
|
| 57 |
+
_DEFAULT_ON_SETATTR = setters.pipe(setters.convert, setters.validate)
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
class _Nothing(enum.Enum):
|
| 61 |
+
"""
|
| 62 |
+
Sentinel to indicate the lack of a value when `None` is ambiguous.
|
| 63 |
+
|
| 64 |
+
If extending attrs, you can use ``typing.Literal[NOTHING]`` to show
|
| 65 |
+
that a value may be ``NOTHING``.
|
| 66 |
+
|
| 67 |
+
.. versionchanged:: 21.1.0 ``bool(NOTHING)`` is now False.
|
| 68 |
+
.. versionchanged:: 22.2.0 ``NOTHING`` is now an ``enum.Enum`` variant.
|
| 69 |
+
"""
|
| 70 |
+
|
| 71 |
+
NOTHING = enum.auto()
|
| 72 |
+
|
| 73 |
+
def __repr__(self):
|
| 74 |
+
return "NOTHING"
|
| 75 |
+
|
| 76 |
+
def __bool__(self):
|
| 77 |
+
return False
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
NOTHING = _Nothing.NOTHING
|
| 81 |
+
"""
|
| 82 |
+
Sentinel to indicate the lack of a value when `None` is ambiguous.
|
| 83 |
+
|
| 84 |
+
When using in 3rd party code, use `attrs.NothingType` for type annotations.
|
| 85 |
+
"""
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
class _CacheHashWrapper(int):
|
| 89 |
+
"""
|
| 90 |
+
An integer subclass that pickles / copies as None
|
| 91 |
+
|
| 92 |
+
This is used for non-slots classes with ``cache_hash=True``, to avoid
|
| 93 |
+
serializing a potentially (even likely) invalid hash value. Since `None`
|
| 94 |
+
is the default value for uncalculated hashes, whenever this is copied,
|
| 95 |
+
the copy's value for the hash should automatically reset.
|
| 96 |
+
|
| 97 |
+
See GH #613 for more details.
|
| 98 |
+
"""
|
| 99 |
+
|
| 100 |
+
def __reduce__(self, _none_constructor=type(None), _args=()): # noqa: B008
|
| 101 |
+
return _none_constructor, _args
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def attrib(
|
| 105 |
+
default=NOTHING,
|
| 106 |
+
validator=None,
|
| 107 |
+
repr=True,
|
| 108 |
+
cmp=None,
|
| 109 |
+
hash=None,
|
| 110 |
+
init=True,
|
| 111 |
+
metadata=None,
|
| 112 |
+
type=None,
|
| 113 |
+
converter=None,
|
| 114 |
+
factory=None,
|
| 115 |
+
kw_only=False,
|
| 116 |
+
eq=None,
|
| 117 |
+
order=None,
|
| 118 |
+
on_setattr=None,
|
| 119 |
+
alias=None,
|
| 120 |
+
):
|
| 121 |
+
"""
|
| 122 |
+
Create a new field / attribute on a class.
|
| 123 |
+
|
| 124 |
+
Identical to `attrs.field`, except it's not keyword-only.
|
| 125 |
+
|
| 126 |
+
Consider using `attrs.field` in new code (``attr.ib`` will *never* go away,
|
| 127 |
+
though).
|
| 128 |
+
|
| 129 |
+
.. warning::
|
| 130 |
+
|
| 131 |
+
Does **nothing** unless the class is also decorated with
|
| 132 |
+
`attr.s` (or similar)!
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
.. versionadded:: 15.2.0 *convert*
|
| 136 |
+
.. versionadded:: 16.3.0 *metadata*
|
| 137 |
+
.. versionchanged:: 17.1.0 *validator* can be a ``list`` now.
|
| 138 |
+
.. versionchanged:: 17.1.0
|
| 139 |
+
*hash* is `None` and therefore mirrors *eq* by default.
|
| 140 |
+
.. versionadded:: 17.3.0 *type*
|
| 141 |
+
.. deprecated:: 17.4.0 *convert*
|
| 142 |
+
.. versionadded:: 17.4.0
|
| 143 |
+
*converter* as a replacement for the deprecated *convert* to achieve
|
| 144 |
+
consistency with other noun-based arguments.
|
| 145 |
+
.. versionadded:: 18.1.0
|
| 146 |
+
``factory=f`` is syntactic sugar for ``default=attr.Factory(f)``.
|
| 147 |
+
.. versionadded:: 18.2.0 *kw_only*
|
| 148 |
+
.. versionchanged:: 19.2.0 *convert* keyword argument removed.
|
| 149 |
+
.. versionchanged:: 19.2.0 *repr* also accepts a custom callable.
|
| 150 |
+
.. deprecated:: 19.2.0 *cmp* Removal on or after 2021-06-01.
|
| 151 |
+
.. versionadded:: 19.2.0 *eq* and *order*
|
| 152 |
+
.. versionadded:: 20.1.0 *on_setattr*
|
| 153 |
+
.. versionchanged:: 20.3.0 *kw_only* backported to Python 2
|
| 154 |
+
.. versionchanged:: 21.1.0
|
| 155 |
+
*eq*, *order*, and *cmp* also accept a custom callable
|
| 156 |
+
.. versionchanged:: 21.1.0 *cmp* undeprecated
|
| 157 |
+
.. versionadded:: 22.2.0 *alias*
|
| 158 |
+
"""
|
| 159 |
+
eq, eq_key, order, order_key = _determine_attrib_eq_order(
|
| 160 |
+
cmp, eq, order, True
|
| 161 |
+
)
|
| 162 |
+
|
| 163 |
+
if hash is not None and hash is not True and hash is not False:
|
| 164 |
+
msg = "Invalid value for hash. Must be True, False, or None."
|
| 165 |
+
raise TypeError(msg)
|
| 166 |
+
|
| 167 |
+
if factory is not None:
|
| 168 |
+
if default is not NOTHING:
|
| 169 |
+
msg = (
|
| 170 |
+
"The `default` and `factory` arguments are mutually exclusive."
|
| 171 |
+
)
|
| 172 |
+
raise ValueError(msg)
|
| 173 |
+
if not callable(factory):
|
| 174 |
+
msg = "The `factory` argument must be a callable."
|
| 175 |
+
raise ValueError(msg)
|
| 176 |
+
default = Factory(factory)
|
| 177 |
+
|
| 178 |
+
if metadata is None:
|
| 179 |
+
metadata = {}
|
| 180 |
+
|
| 181 |
+
# Apply syntactic sugar by auto-wrapping.
|
| 182 |
+
if isinstance(on_setattr, (list, tuple)):
|
| 183 |
+
on_setattr = setters.pipe(*on_setattr)
|
| 184 |
+
|
| 185 |
+
if validator and isinstance(validator, (list, tuple)):
|
| 186 |
+
validator = and_(*validator)
|
| 187 |
+
|
| 188 |
+
if converter and isinstance(converter, (list, tuple)):
|
| 189 |
+
converter = pipe(*converter)
|
| 190 |
+
|
| 191 |
+
return _CountingAttr(
|
| 192 |
+
default=default,
|
| 193 |
+
validator=validator,
|
| 194 |
+
repr=repr,
|
| 195 |
+
cmp=None,
|
| 196 |
+
hash=hash,
|
| 197 |
+
init=init,
|
| 198 |
+
converter=converter,
|
| 199 |
+
metadata=metadata,
|
| 200 |
+
type=type,
|
| 201 |
+
kw_only=kw_only,
|
| 202 |
+
eq=eq,
|
| 203 |
+
eq_key=eq_key,
|
| 204 |
+
order=order,
|
| 205 |
+
order_key=order_key,
|
| 206 |
+
on_setattr=on_setattr,
|
| 207 |
+
alias=alias,
|
| 208 |
+
)
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
def _compile_and_eval(script, globs, locs=None, filename=""):
|
| 212 |
+
"""
|
| 213 |
+
Evaluate the script with the given global (globs) and local (locs)
|
| 214 |
+
variables.
|
| 215 |
+
"""
|
| 216 |
+
bytecode = compile(script, filename, "exec")
|
| 217 |
+
eval(bytecode, globs, locs)
|
| 218 |
+
|
| 219 |
+
|
| 220 |
+
def _make_method(name, script, filename, globs, locals=None):
|
| 221 |
+
"""
|
| 222 |
+
Create the method with the script given and return the method object.
|
| 223 |
+
"""
|
| 224 |
+
locs = {} if locals is None else locals
|
| 225 |
+
|
| 226 |
+
# In order of debuggers like PDB being able to step through the code,
|
| 227 |
+
# we add a fake linecache entry.
|
| 228 |
+
count = 1
|
| 229 |
+
base_filename = filename
|
| 230 |
+
while True:
|
| 231 |
+
linecache_tuple = (
|
| 232 |
+
len(script),
|
| 233 |
+
None,
|
| 234 |
+
script.splitlines(True),
|
| 235 |
+
filename,
|
| 236 |
+
)
|
| 237 |
+
old_val = linecache.cache.setdefault(filename, linecache_tuple)
|
| 238 |
+
if old_val == linecache_tuple:
|
| 239 |
+
break
|
| 240 |
+
|
| 241 |
+
filename = f"{base_filename[:-1]}-{count}>"
|
| 242 |
+
count += 1
|
| 243 |
+
|
| 244 |
+
_compile_and_eval(script, globs, locs, filename)
|
| 245 |
+
|
| 246 |
+
return locs[name]
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
def _make_attr_tuple_class(cls_name, attr_names):
|
| 250 |
+
"""
|
| 251 |
+
Create a tuple subclass to hold `Attribute`s for an `attrs` class.
|
| 252 |
+
|
| 253 |
+
The subclass is a bare tuple with properties for names.
|
| 254 |
+
|
| 255 |
+
class MyClassAttributes(tuple):
|
| 256 |
+
__slots__ = ()
|
| 257 |
+
x = property(itemgetter(0))
|
| 258 |
+
"""
|
| 259 |
+
attr_class_name = f"{cls_name}Attributes"
|
| 260 |
+
attr_class_template = [
|
| 261 |
+
f"class {attr_class_name}(tuple):",
|
| 262 |
+
" __slots__ = ()",
|
| 263 |
+
]
|
| 264 |
+
if attr_names:
|
| 265 |
+
for i, attr_name in enumerate(attr_names):
|
| 266 |
+
attr_class_template.append(
|
| 267 |
+
f" {attr_name} = _attrs_property(_attrs_itemgetter({i}))"
|
| 268 |
+
)
|
| 269 |
+
else:
|
| 270 |
+
attr_class_template.append(" pass")
|
| 271 |
+
globs = {"_attrs_itemgetter": itemgetter, "_attrs_property": property}
|
| 272 |
+
_compile_and_eval("\n".join(attr_class_template), globs)
|
| 273 |
+
return globs[attr_class_name]
|
| 274 |
+
|
| 275 |
+
|
| 276 |
+
# Tuple class for extracted attributes from a class definition.
|
| 277 |
+
# `base_attrs` is a subset of `attrs`.
|
| 278 |
+
_Attributes = _make_attr_tuple_class(
|
| 279 |
+
"_Attributes",
|
| 280 |
+
[
|
| 281 |
+
# all attributes to build dunder methods for
|
| 282 |
+
"attrs",
|
| 283 |
+
# attributes that have been inherited
|
| 284 |
+
"base_attrs",
|
| 285 |
+
# map inherited attributes to their originating classes
|
| 286 |
+
"base_attrs_map",
|
| 287 |
+
],
|
| 288 |
+
)
|
| 289 |
+
|
| 290 |
+
|
| 291 |
+
def _is_class_var(annot):
|
| 292 |
+
"""
|
| 293 |
+
Check whether *annot* is a typing.ClassVar.
|
| 294 |
+
|
| 295 |
+
The string comparison hack is used to avoid evaluating all string
|
| 296 |
+
annotations which would put attrs-based classes at a performance
|
| 297 |
+
disadvantage compared to plain old classes.
|
| 298 |
+
"""
|
| 299 |
+
annot = str(annot)
|
| 300 |
+
|
| 301 |
+
# Annotation can be quoted.
|
| 302 |
+
if annot.startswith(("'", '"')) and annot.endswith(("'", '"')):
|
| 303 |
+
annot = annot[1:-1]
|
| 304 |
+
|
| 305 |
+
return annot.startswith(_CLASSVAR_PREFIXES)
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
def _has_own_attribute(cls, attrib_name):
|
| 309 |
+
"""
|
| 310 |
+
Check whether *cls* defines *attrib_name* (and doesn't just inherit it).
|
| 311 |
+
"""
|
| 312 |
+
return attrib_name in cls.__dict__
|
| 313 |
+
|
| 314 |
+
|
| 315 |
+
def _collect_base_attrs(cls, taken_attr_names):
|
| 316 |
+
"""
|
| 317 |
+
Collect attr.ibs from base classes of *cls*, except *taken_attr_names*.
|
| 318 |
+
"""
|
| 319 |
+
base_attrs = []
|
| 320 |
+
base_attr_map = {} # A dictionary of base attrs to their classes.
|
| 321 |
+
|
| 322 |
+
# Traverse the MRO and collect attributes.
|
| 323 |
+
for base_cls in reversed(cls.__mro__[1:-1]):
|
| 324 |
+
for a in getattr(base_cls, "__attrs_attrs__", []):
|
| 325 |
+
if a.inherited or a.name in taken_attr_names:
|
| 326 |
+
continue
|
| 327 |
+
|
| 328 |
+
a = a.evolve(inherited=True) # noqa: PLW2901
|
| 329 |
+
base_attrs.append(a)
|
| 330 |
+
base_attr_map[a.name] = base_cls
|
| 331 |
+
|
| 332 |
+
# For each name, only keep the freshest definition i.e. the furthest at the
|
| 333 |
+
# back. base_attr_map is fine because it gets overwritten with every new
|
| 334 |
+
# instance.
|
| 335 |
+
filtered = []
|
| 336 |
+
seen = set()
|
| 337 |
+
for a in reversed(base_attrs):
|
| 338 |
+
if a.name in seen:
|
| 339 |
+
continue
|
| 340 |
+
filtered.insert(0, a)
|
| 341 |
+
seen.add(a.name)
|
| 342 |
+
|
| 343 |
+
return filtered, base_attr_map
|
| 344 |
+
|
| 345 |
+
|
| 346 |
+
def _collect_base_attrs_broken(cls, taken_attr_names):
|
| 347 |
+
"""
|
| 348 |
+
Collect attr.ibs from base classes of *cls*, except *taken_attr_names*.
|
| 349 |
+
|
| 350 |
+
N.B. *taken_attr_names* will be mutated.
|
| 351 |
+
|
| 352 |
+
Adhere to the old incorrect behavior.
|
| 353 |
+
|
| 354 |
+
Notably it collects from the front and considers inherited attributes which
|
| 355 |
+
leads to the buggy behavior reported in #428.
|
| 356 |
+
"""
|
| 357 |
+
base_attrs = []
|
| 358 |
+
base_attr_map = {} # A dictionary of base attrs to their classes.
|
| 359 |
+
|
| 360 |
+
# Traverse the MRO and collect attributes.
|
| 361 |
+
for base_cls in cls.__mro__[1:-1]:
|
| 362 |
+
for a in getattr(base_cls, "__attrs_attrs__", []):
|
| 363 |
+
if a.name in taken_attr_names:
|
| 364 |
+
continue
|
| 365 |
+
|
| 366 |
+
a = a.evolve(inherited=True) # noqa: PLW2901
|
| 367 |
+
taken_attr_names.add(a.name)
|
| 368 |
+
base_attrs.append(a)
|
| 369 |
+
base_attr_map[a.name] = base_cls
|
| 370 |
+
|
| 371 |
+
return base_attrs, base_attr_map
|
| 372 |
+
|
| 373 |
+
|
| 374 |
+
def _transform_attrs(
|
| 375 |
+
cls, these, auto_attribs, kw_only, collect_by_mro, field_transformer
|
| 376 |
+
):
|
| 377 |
+
"""
|
| 378 |
+
Transform all `_CountingAttr`s on a class into `Attribute`s.
|
| 379 |
+
|
| 380 |
+
If *these* is passed, use that and don't look for them on the class.
|
| 381 |
+
|
| 382 |
+
If *collect_by_mro* is True, collect them in the correct MRO order,
|
| 383 |
+
otherwise use the old -- incorrect -- order. See #428.
|
| 384 |
+
|
| 385 |
+
Return an `_Attributes`.
|
| 386 |
+
"""
|
| 387 |
+
cd = cls.__dict__
|
| 388 |
+
anns = _get_annotations(cls)
|
| 389 |
+
|
| 390 |
+
if these is not None:
|
| 391 |
+
ca_list = list(these.items())
|
| 392 |
+
elif auto_attribs is True:
|
| 393 |
+
ca_names = {
|
| 394 |
+
name
|
| 395 |
+
for name, attr in cd.items()
|
| 396 |
+
if isinstance(attr, _CountingAttr)
|
| 397 |
+
}
|
| 398 |
+
ca_list = []
|
| 399 |
+
annot_names = set()
|
| 400 |
+
for attr_name, type in anns.items():
|
| 401 |
+
if _is_class_var(type):
|
| 402 |
+
continue
|
| 403 |
+
annot_names.add(attr_name)
|
| 404 |
+
a = cd.get(attr_name, NOTHING)
|
| 405 |
+
|
| 406 |
+
if not isinstance(a, _CountingAttr):
|
| 407 |
+
a = attrib() if a is NOTHING else attrib(default=a)
|
| 408 |
+
ca_list.append((attr_name, a))
|
| 409 |
+
|
| 410 |
+
unannotated = ca_names - annot_names
|
| 411 |
+
if len(unannotated) > 0:
|
| 412 |
+
raise UnannotatedAttributeError(
|
| 413 |
+
"The following `attr.ib`s lack a type annotation: "
|
| 414 |
+
+ ", ".join(
|
| 415 |
+
sorted(unannotated, key=lambda n: cd.get(n).counter)
|
| 416 |
+
)
|
| 417 |
+
+ "."
|
| 418 |
+
)
|
| 419 |
+
else:
|
| 420 |
+
ca_list = sorted(
|
| 421 |
+
(
|
| 422 |
+
(name, attr)
|
| 423 |
+
for name, attr in cd.items()
|
| 424 |
+
if isinstance(attr, _CountingAttr)
|
| 425 |
+
),
|
| 426 |
+
key=lambda e: e[1].counter,
|
| 427 |
+
)
|
| 428 |
+
|
| 429 |
+
own_attrs = [
|
| 430 |
+
Attribute.from_counting_attr(
|
| 431 |
+
name=attr_name, ca=ca, type=anns.get(attr_name)
|
| 432 |
+
)
|
| 433 |
+
for attr_name, ca in ca_list
|
| 434 |
+
]
|
| 435 |
+
|
| 436 |
+
if collect_by_mro:
|
| 437 |
+
base_attrs, base_attr_map = _collect_base_attrs(
|
| 438 |
+
cls, {a.name for a in own_attrs}
|
| 439 |
+
)
|
| 440 |
+
else:
|
| 441 |
+
base_attrs, base_attr_map = _collect_base_attrs_broken(
|
| 442 |
+
cls, {a.name for a in own_attrs}
|
| 443 |
+
)
|
| 444 |
+
|
| 445 |
+
if kw_only:
|
| 446 |
+
own_attrs = [a.evolve(kw_only=True) for a in own_attrs]
|
| 447 |
+
base_attrs = [a.evolve(kw_only=True) for a in base_attrs]
|
| 448 |
+
|
| 449 |
+
attrs = base_attrs + own_attrs
|
| 450 |
+
|
| 451 |
+
# Mandatory vs non-mandatory attr order only matters when they are part of
|
| 452 |
+
# the __init__ signature and when they aren't kw_only (which are moved to
|
| 453 |
+
# the end and can be mandatory or non-mandatory in any order, as they will
|
| 454 |
+
# be specified as keyword args anyway). Check the order of those attrs:
|
| 455 |
+
had_default = False
|
| 456 |
+
for a in (a for a in attrs if a.init is not False and a.kw_only is False):
|
| 457 |
+
if had_default is True and a.default is NOTHING:
|
| 458 |
+
msg = f"No mandatory attributes allowed after an attribute with a default value or factory. Attribute in question: {a!r}"
|
| 459 |
+
raise ValueError(msg)
|
| 460 |
+
|
| 461 |
+
if had_default is False and a.default is not NOTHING:
|
| 462 |
+
had_default = True
|
| 463 |
+
|
| 464 |
+
if field_transformer is not None:
|
| 465 |
+
attrs = field_transformer(cls, attrs)
|
| 466 |
+
|
| 467 |
+
# Resolve default field alias after executing field_transformer.
|
| 468 |
+
# This allows field_transformer to differentiate between explicit vs
|
| 469 |
+
# default aliases and supply their own defaults.
|
| 470 |
+
attrs = [
|
| 471 |
+
a.evolve(alias=_default_init_alias_for(a.name)) if not a.alias else a
|
| 472 |
+
for a in attrs
|
| 473 |
+
]
|
| 474 |
+
|
| 475 |
+
# Create AttrsClass *after* applying the field_transformer since it may
|
| 476 |
+
# add or remove attributes!
|
| 477 |
+
attr_names = [a.name for a in attrs]
|
| 478 |
+
AttrsClass = _make_attr_tuple_class(cls.__name__, attr_names)
|
| 479 |
+
|
| 480 |
+
return _Attributes((AttrsClass(attrs), base_attrs, base_attr_map))
|
| 481 |
+
|
| 482 |
+
|
| 483 |
+
def _make_cached_property_getattr(cached_properties, original_getattr, cls):
|
| 484 |
+
lines = [
|
| 485 |
+
# Wrapped to get `__class__` into closure cell for super()
|
| 486 |
+
# (It will be replaced with the newly constructed class after construction).
|
| 487 |
+
"def wrapper(_cls):",
|
| 488 |
+
" __class__ = _cls",
|
| 489 |
+
" def __getattr__(self, item, cached_properties=cached_properties, original_getattr=original_getattr, _cached_setattr_get=_cached_setattr_get):",
|
| 490 |
+
" func = cached_properties.get(item)",
|
| 491 |
+
" if func is not None:",
|
| 492 |
+
" result = func(self)",
|
| 493 |
+
" _setter = _cached_setattr_get(self)",
|
| 494 |
+
" _setter(item, result)",
|
| 495 |
+
" return result",
|
| 496 |
+
]
|
| 497 |
+
if original_getattr is not None:
|
| 498 |
+
lines.append(
|
| 499 |
+
" return original_getattr(self, item)",
|
| 500 |
+
)
|
| 501 |
+
else:
|
| 502 |
+
lines.extend(
|
| 503 |
+
[
|
| 504 |
+
" try:",
|
| 505 |
+
" return super().__getattribute__(item)",
|
| 506 |
+
" except AttributeError:",
|
| 507 |
+
" if not hasattr(super(), '__getattr__'):",
|
| 508 |
+
" raise",
|
| 509 |
+
" return super().__getattr__(item)",
|
| 510 |
+
" original_error = f\"'{self.__class__.__name__}' object has no attribute '{item}'\"",
|
| 511 |
+
" raise AttributeError(original_error)",
|
| 512 |
+
]
|
| 513 |
+
)
|
| 514 |
+
|
| 515 |
+
lines.extend(
|
| 516 |
+
[
|
| 517 |
+
" return __getattr__",
|
| 518 |
+
"__getattr__ = wrapper(_cls)",
|
| 519 |
+
]
|
| 520 |
+
)
|
| 521 |
+
|
| 522 |
+
unique_filename = _generate_unique_filename(cls, "getattr")
|
| 523 |
+
|
| 524 |
+
glob = {
|
| 525 |
+
"cached_properties": cached_properties,
|
| 526 |
+
"_cached_setattr_get": _OBJ_SETATTR.__get__,
|
| 527 |
+
"original_getattr": original_getattr,
|
| 528 |
+
}
|
| 529 |
+
|
| 530 |
+
return _make_method(
|
| 531 |
+
"__getattr__",
|
| 532 |
+
"\n".join(lines),
|
| 533 |
+
unique_filename,
|
| 534 |
+
glob,
|
| 535 |
+
locals={
|
| 536 |
+
"_cls": cls,
|
| 537 |
+
},
|
| 538 |
+
)
|
| 539 |
+
|
| 540 |
+
|
| 541 |
+
def _frozen_setattrs(self, name, value):
|
| 542 |
+
"""
|
| 543 |
+
Attached to frozen classes as __setattr__.
|
| 544 |
+
"""
|
| 545 |
+
if isinstance(self, BaseException) and name in (
|
| 546 |
+
"__cause__",
|
| 547 |
+
"__context__",
|
| 548 |
+
"__traceback__",
|
| 549 |
+
"__suppress_context__",
|
| 550 |
+
"__notes__",
|
| 551 |
+
):
|
| 552 |
+
BaseException.__setattr__(self, name, value)
|
| 553 |
+
return
|
| 554 |
+
|
| 555 |
+
raise FrozenInstanceError
|
| 556 |
+
|
| 557 |
+
|
| 558 |
+
def _frozen_delattrs(self, name):
|
| 559 |
+
"""
|
| 560 |
+
Attached to frozen classes as __delattr__.
|
| 561 |
+
"""
|
| 562 |
+
if isinstance(self, BaseException) and name in ("__notes__",):
|
| 563 |
+
BaseException.__delattr__(self, name)
|
| 564 |
+
return
|
| 565 |
+
|
| 566 |
+
raise FrozenInstanceError
|
| 567 |
+
|
| 568 |
+
|
| 569 |
+
def evolve(*args, **changes):
|
| 570 |
+
"""
|
| 571 |
+
Create a new instance, based on the first positional argument with
|
| 572 |
+
*changes* applied.
|
| 573 |
+
|
| 574 |
+
.. tip::
|
| 575 |
+
|
| 576 |
+
On Python 3.13 and later, you can also use `copy.replace` instead.
|
| 577 |
+
|
| 578 |
+
Args:
|
| 579 |
+
|
| 580 |
+
inst:
|
| 581 |
+
Instance of a class with *attrs* attributes. *inst* must be passed
|
| 582 |
+
as a positional argument.
|
| 583 |
+
|
| 584 |
+
changes:
|
| 585 |
+
Keyword changes in the new copy.
|
| 586 |
+
|
| 587 |
+
Returns:
|
| 588 |
+
A copy of inst with *changes* incorporated.
|
| 589 |
+
|
| 590 |
+
Raises:
|
| 591 |
+
TypeError:
|
| 592 |
+
If *attr_name* couldn't be found in the class ``__init__``.
|
| 593 |
+
|
| 594 |
+
attrs.exceptions.NotAnAttrsClassError:
|
| 595 |
+
If *cls* is not an *attrs* class.
|
| 596 |
+
|
| 597 |
+
.. versionadded:: 17.1.0
|
| 598 |
+
.. deprecated:: 23.1.0
|
| 599 |
+
It is now deprecated to pass the instance using the keyword argument
|
| 600 |
+
*inst*. It will raise a warning until at least April 2024, after which
|
| 601 |
+
it will become an error. Always pass the instance as a positional
|
| 602 |
+
argument.
|
| 603 |
+
.. versionchanged:: 24.1.0
|
| 604 |
+
*inst* can't be passed as a keyword argument anymore.
|
| 605 |
+
"""
|
| 606 |
+
try:
|
| 607 |
+
(inst,) = args
|
| 608 |
+
except ValueError:
|
| 609 |
+
msg = (
|
| 610 |
+
f"evolve() takes 1 positional argument, but {len(args)} were given"
|
| 611 |
+
)
|
| 612 |
+
raise TypeError(msg) from None
|
| 613 |
+
|
| 614 |
+
cls = inst.__class__
|
| 615 |
+
attrs = fields(cls)
|
| 616 |
+
for a in attrs:
|
| 617 |
+
if not a.init:
|
| 618 |
+
continue
|
| 619 |
+
attr_name = a.name # To deal with private attributes.
|
| 620 |
+
init_name = a.alias
|
| 621 |
+
if init_name not in changes:
|
| 622 |
+
changes[init_name] = getattr(inst, attr_name)
|
| 623 |
+
|
| 624 |
+
return cls(**changes)
|
| 625 |
+
|
| 626 |
+
|
| 627 |
+
class _ClassBuilder:
|
| 628 |
+
"""
|
| 629 |
+
Iteratively build *one* class.
|
| 630 |
+
"""
|
| 631 |
+
|
| 632 |
+
__slots__ = (
|
| 633 |
+
"_attr_names",
|
| 634 |
+
"_attrs",
|
| 635 |
+
"_base_attr_map",
|
| 636 |
+
"_base_names",
|
| 637 |
+
"_cache_hash",
|
| 638 |
+
"_cls",
|
| 639 |
+
"_cls_dict",
|
| 640 |
+
"_delete_attribs",
|
| 641 |
+
"_frozen",
|
| 642 |
+
"_has_custom_setattr",
|
| 643 |
+
"_has_post_init",
|
| 644 |
+
"_has_pre_init",
|
| 645 |
+
"_is_exc",
|
| 646 |
+
"_on_setattr",
|
| 647 |
+
"_pre_init_has_args",
|
| 648 |
+
"_slots",
|
| 649 |
+
"_weakref_slot",
|
| 650 |
+
"_wrote_own_setattr",
|
| 651 |
+
)
|
| 652 |
+
|
| 653 |
+
def __init__(
|
| 654 |
+
self,
|
| 655 |
+
cls,
|
| 656 |
+
these,
|
| 657 |
+
slots,
|
| 658 |
+
frozen,
|
| 659 |
+
weakref_slot,
|
| 660 |
+
getstate_setstate,
|
| 661 |
+
auto_attribs,
|
| 662 |
+
kw_only,
|
| 663 |
+
cache_hash,
|
| 664 |
+
is_exc,
|
| 665 |
+
collect_by_mro,
|
| 666 |
+
on_setattr,
|
| 667 |
+
has_custom_setattr,
|
| 668 |
+
field_transformer,
|
| 669 |
+
):
|
| 670 |
+
attrs, base_attrs, base_map = _transform_attrs(
|
| 671 |
+
cls,
|
| 672 |
+
these,
|
| 673 |
+
auto_attribs,
|
| 674 |
+
kw_only,
|
| 675 |
+
collect_by_mro,
|
| 676 |
+
field_transformer,
|
| 677 |
+
)
|
| 678 |
+
|
| 679 |
+
self._cls = cls
|
| 680 |
+
self._cls_dict = dict(cls.__dict__) if slots else {}
|
| 681 |
+
self._attrs = attrs
|
| 682 |
+
self._base_names = {a.name for a in base_attrs}
|
| 683 |
+
self._base_attr_map = base_map
|
| 684 |
+
self._attr_names = tuple(a.name for a in attrs)
|
| 685 |
+
self._slots = slots
|
| 686 |
+
self._frozen = frozen
|
| 687 |
+
self._weakref_slot = weakref_slot
|
| 688 |
+
self._cache_hash = cache_hash
|
| 689 |
+
self._has_pre_init = bool(getattr(cls, "__attrs_pre_init__", False))
|
| 690 |
+
self._pre_init_has_args = False
|
| 691 |
+
if self._has_pre_init:
|
| 692 |
+
# Check if the pre init method has more arguments than just `self`
|
| 693 |
+
# We want to pass arguments if pre init expects arguments
|
| 694 |
+
pre_init_func = cls.__attrs_pre_init__
|
| 695 |
+
pre_init_signature = inspect.signature(pre_init_func)
|
| 696 |
+
self._pre_init_has_args = len(pre_init_signature.parameters) > 1
|
| 697 |
+
self._has_post_init = bool(getattr(cls, "__attrs_post_init__", False))
|
| 698 |
+
self._delete_attribs = not bool(these)
|
| 699 |
+
self._is_exc = is_exc
|
| 700 |
+
self._on_setattr = on_setattr
|
| 701 |
+
|
| 702 |
+
self._has_custom_setattr = has_custom_setattr
|
| 703 |
+
self._wrote_own_setattr = False
|
| 704 |
+
|
| 705 |
+
self._cls_dict["__attrs_attrs__"] = self._attrs
|
| 706 |
+
|
| 707 |
+
if frozen:
|
| 708 |
+
self._cls_dict["__setattr__"] = _frozen_setattrs
|
| 709 |
+
self._cls_dict["__delattr__"] = _frozen_delattrs
|
| 710 |
+
|
| 711 |
+
self._wrote_own_setattr = True
|
| 712 |
+
elif on_setattr in (
|
| 713 |
+
_DEFAULT_ON_SETATTR,
|
| 714 |
+
setters.validate,
|
| 715 |
+
setters.convert,
|
| 716 |
+
):
|
| 717 |
+
has_validator = has_converter = False
|
| 718 |
+
for a in attrs:
|
| 719 |
+
if a.validator is not None:
|
| 720 |
+
has_validator = True
|
| 721 |
+
if a.converter is not None:
|
| 722 |
+
has_converter = True
|
| 723 |
+
|
| 724 |
+
if has_validator and has_converter:
|
| 725 |
+
break
|
| 726 |
+
if (
|
| 727 |
+
(
|
| 728 |
+
on_setattr == _DEFAULT_ON_SETATTR
|
| 729 |
+
and not (has_validator or has_converter)
|
| 730 |
+
)
|
| 731 |
+
or (on_setattr == setters.validate and not has_validator)
|
| 732 |
+
or (on_setattr == setters.convert and not has_converter)
|
| 733 |
+
):
|
| 734 |
+
# If class-level on_setattr is set to convert + validate, but
|
| 735 |
+
# there's no field to convert or validate, pretend like there's
|
| 736 |
+
# no on_setattr.
|
| 737 |
+
self._on_setattr = None
|
| 738 |
+
|
| 739 |
+
if getstate_setstate:
|
| 740 |
+
(
|
| 741 |
+
self._cls_dict["__getstate__"],
|
| 742 |
+
self._cls_dict["__setstate__"],
|
| 743 |
+
) = self._make_getstate_setstate()
|
| 744 |
+
|
| 745 |
+
def __repr__(self):
|
| 746 |
+
return f"<_ClassBuilder(cls={self._cls.__name__})>"
|
| 747 |
+
|
| 748 |
+
def build_class(self):
|
| 749 |
+
"""
|
| 750 |
+
Finalize class based on the accumulated configuration.
|
| 751 |
+
|
| 752 |
+
Builder cannot be used after calling this method.
|
| 753 |
+
"""
|
| 754 |
+
if self._slots is True:
|
| 755 |
+
cls = self._create_slots_class()
|
| 756 |
+
else:
|
| 757 |
+
cls = self._patch_original_class()
|
| 758 |
+
if PY_3_10_PLUS:
|
| 759 |
+
cls = abc.update_abstractmethods(cls)
|
| 760 |
+
|
| 761 |
+
# The method gets only called if it's not inherited from a base class.
|
| 762 |
+
# _has_own_attribute does NOT work properly for classmethods.
|
| 763 |
+
if (
|
| 764 |
+
getattr(cls, "__attrs_init_subclass__", None)
|
| 765 |
+
and "__attrs_init_subclass__" not in cls.__dict__
|
| 766 |
+
):
|
| 767 |
+
cls.__attrs_init_subclass__()
|
| 768 |
+
|
| 769 |
+
return cls
|
| 770 |
+
|
| 771 |
+
def _patch_original_class(self):
|
| 772 |
+
"""
|
| 773 |
+
Apply accumulated methods and return the class.
|
| 774 |
+
"""
|
| 775 |
+
cls = self._cls
|
| 776 |
+
base_names = self._base_names
|
| 777 |
+
|
| 778 |
+
# Clean class of attribute definitions (`attr.ib()`s).
|
| 779 |
+
if self._delete_attribs:
|
| 780 |
+
for name in self._attr_names:
|
| 781 |
+
if (
|
| 782 |
+
name not in base_names
|
| 783 |
+
and getattr(cls, name, _SENTINEL) is not _SENTINEL
|
| 784 |
+
):
|
| 785 |
+
# An AttributeError can happen if a base class defines a
|
| 786 |
+
# class variable and we want to set an attribute with the
|
| 787 |
+
# same name by using only a type annotation.
|
| 788 |
+
with contextlib.suppress(AttributeError):
|
| 789 |
+
delattr(cls, name)
|
| 790 |
+
|
| 791 |
+
# Attach our dunder methods.
|
| 792 |
+
for name, value in self._cls_dict.items():
|
| 793 |
+
setattr(cls, name, value)
|
| 794 |
+
|
| 795 |
+
# If we've inherited an attrs __setattr__ and don't write our own,
|
| 796 |
+
# reset it to object's.
|
| 797 |
+
if not self._wrote_own_setattr and getattr(
|
| 798 |
+
cls, "__attrs_own_setattr__", False
|
| 799 |
+
):
|
| 800 |
+
cls.__attrs_own_setattr__ = False
|
| 801 |
+
|
| 802 |
+
if not self._has_custom_setattr:
|
| 803 |
+
cls.__setattr__ = _OBJ_SETATTR
|
| 804 |
+
|
| 805 |
+
return cls
|
| 806 |
+
|
| 807 |
+
def _create_slots_class(self):
|
| 808 |
+
"""
|
| 809 |
+
Build and return a new class with a `__slots__` attribute.
|
| 810 |
+
"""
|
| 811 |
+
cd = {
|
| 812 |
+
k: v
|
| 813 |
+
for k, v in self._cls_dict.items()
|
| 814 |
+
if k not in (*tuple(self._attr_names), "__dict__", "__weakref__")
|
| 815 |
+
}
|
| 816 |
+
|
| 817 |
+
# If our class doesn't have its own implementation of __setattr__
|
| 818 |
+
# (either from the user or by us), check the bases, if one of them has
|
| 819 |
+
# an attrs-made __setattr__, that needs to be reset. We don't walk the
|
| 820 |
+
# MRO because we only care about our immediate base classes.
|
| 821 |
+
# XXX: This can be confused by subclassing a slotted attrs class with
|
| 822 |
+
# XXX: a non-attrs class and subclass the resulting class with an attrs
|
| 823 |
+
# XXX: class. See `test_slotted_confused` for details. For now that's
|
| 824 |
+
# XXX: OK with us.
|
| 825 |
+
if not self._wrote_own_setattr:
|
| 826 |
+
cd["__attrs_own_setattr__"] = False
|
| 827 |
+
|
| 828 |
+
if not self._has_custom_setattr:
|
| 829 |
+
for base_cls in self._cls.__bases__:
|
| 830 |
+
if base_cls.__dict__.get("__attrs_own_setattr__", False):
|
| 831 |
+
cd["__setattr__"] = _OBJ_SETATTR
|
| 832 |
+
break
|
| 833 |
+
|
| 834 |
+
# Traverse the MRO to collect existing slots
|
| 835 |
+
# and check for an existing __weakref__.
|
| 836 |
+
existing_slots = {}
|
| 837 |
+
weakref_inherited = False
|
| 838 |
+
for base_cls in self._cls.__mro__[1:-1]:
|
| 839 |
+
if base_cls.__dict__.get("__weakref__", None) is not None:
|
| 840 |
+
weakref_inherited = True
|
| 841 |
+
existing_slots.update(
|
| 842 |
+
{
|
| 843 |
+
name: getattr(base_cls, name)
|
| 844 |
+
for name in getattr(base_cls, "__slots__", [])
|
| 845 |
+
}
|
| 846 |
+
)
|
| 847 |
+
|
| 848 |
+
base_names = set(self._base_names)
|
| 849 |
+
|
| 850 |
+
names = self._attr_names
|
| 851 |
+
if (
|
| 852 |
+
self._weakref_slot
|
| 853 |
+
and "__weakref__" not in getattr(self._cls, "__slots__", ())
|
| 854 |
+
and "__weakref__" not in names
|
| 855 |
+
and not weakref_inherited
|
| 856 |
+
):
|
| 857 |
+
names += ("__weakref__",)
|
| 858 |
+
|
| 859 |
+
cached_properties = {
|
| 860 |
+
name: cached_property.func
|
| 861 |
+
for name, cached_property in cd.items()
|
| 862 |
+
if isinstance(cached_property, functools.cached_property)
|
| 863 |
+
}
|
| 864 |
+
|
| 865 |
+
# Collect methods with a `__class__` reference that are shadowed in the new class.
|
| 866 |
+
# To know to update them.
|
| 867 |
+
additional_closure_functions_to_update = []
|
| 868 |
+
if cached_properties:
|
| 869 |
+
class_annotations = _get_annotations(self._cls)
|
| 870 |
+
for name, func in cached_properties.items():
|
| 871 |
+
# Add cached properties to names for slotting.
|
| 872 |
+
names += (name,)
|
| 873 |
+
# Clear out function from class to avoid clashing.
|
| 874 |
+
del cd[name]
|
| 875 |
+
additional_closure_functions_to_update.append(func)
|
| 876 |
+
annotation = inspect.signature(func).return_annotation
|
| 877 |
+
if annotation is not inspect.Parameter.empty:
|
| 878 |
+
class_annotations[name] = annotation
|
| 879 |
+
|
| 880 |
+
original_getattr = cd.get("__getattr__")
|
| 881 |
+
if original_getattr is not None:
|
| 882 |
+
additional_closure_functions_to_update.append(original_getattr)
|
| 883 |
+
|
| 884 |
+
cd["__getattr__"] = _make_cached_property_getattr(
|
| 885 |
+
cached_properties, original_getattr, self._cls
|
| 886 |
+
)
|
| 887 |
+
|
| 888 |
+
# We only add the names of attributes that aren't inherited.
|
| 889 |
+
# Setting __slots__ to inherited attributes wastes memory.
|
| 890 |
+
slot_names = [name for name in names if name not in base_names]
|
| 891 |
+
|
| 892 |
+
# There are slots for attributes from current class
|
| 893 |
+
# that are defined in parent classes.
|
| 894 |
+
# As their descriptors may be overridden by a child class,
|
| 895 |
+
# we collect them here and update the class dict
|
| 896 |
+
reused_slots = {
|
| 897 |
+
slot: slot_descriptor
|
| 898 |
+
for slot, slot_descriptor in existing_slots.items()
|
| 899 |
+
if slot in slot_names
|
| 900 |
+
}
|
| 901 |
+
slot_names = [name for name in slot_names if name not in reused_slots]
|
| 902 |
+
cd.update(reused_slots)
|
| 903 |
+
if self._cache_hash:
|
| 904 |
+
slot_names.append(_HASH_CACHE_FIELD)
|
| 905 |
+
|
| 906 |
+
cd["__slots__"] = tuple(slot_names)
|
| 907 |
+
|
| 908 |
+
cd["__qualname__"] = self._cls.__qualname__
|
| 909 |
+
|
| 910 |
+
# Create new class based on old class and our methods.
|
| 911 |
+
cls = type(self._cls)(self._cls.__name__, self._cls.__bases__, cd)
|
| 912 |
+
|
| 913 |
+
# The following is a fix for
|
| 914 |
+
# <https://github.com/python-attrs/attrs/issues/102>.
|
| 915 |
+
# If a method mentions `__class__` or uses the no-arg super(), the
|
| 916 |
+
# compiler will bake a reference to the class in the method itself
|
| 917 |
+
# as `method.__closure__`. Since we replace the class with a
|
| 918 |
+
# clone, we rewrite these references so it keeps working.
|
| 919 |
+
for item in itertools.chain(
|
| 920 |
+
cls.__dict__.values(), additional_closure_functions_to_update
|
| 921 |
+
):
|
| 922 |
+
if isinstance(item, (classmethod, staticmethod)):
|
| 923 |
+
# Class- and staticmethods hide their functions inside.
|
| 924 |
+
# These might need to be rewritten as well.
|
| 925 |
+
closure_cells = getattr(item.__func__, "__closure__", None)
|
| 926 |
+
elif isinstance(item, property):
|
| 927 |
+
# Workaround for property `super()` shortcut (PY3-only).
|
| 928 |
+
# There is no universal way for other descriptors.
|
| 929 |
+
closure_cells = getattr(item.fget, "__closure__", None)
|
| 930 |
+
else:
|
| 931 |
+
closure_cells = getattr(item, "__closure__", None)
|
| 932 |
+
|
| 933 |
+
if not closure_cells: # Catch None or the empty list.
|
| 934 |
+
continue
|
| 935 |
+
for cell in closure_cells:
|
| 936 |
+
try:
|
| 937 |
+
match = cell.cell_contents is self._cls
|
| 938 |
+
except ValueError: # noqa: PERF203
|
| 939 |
+
# ValueError: Cell is empty
|
| 940 |
+
pass
|
| 941 |
+
else:
|
| 942 |
+
if match:
|
| 943 |
+
cell.cell_contents = cls
|
| 944 |
+
return cls
|
| 945 |
+
|
| 946 |
+
def add_repr(self, ns):
|
| 947 |
+
self._cls_dict["__repr__"] = self._add_method_dunders(
|
| 948 |
+
_make_repr(self._attrs, ns, self._cls)
|
| 949 |
+
)
|
| 950 |
+
return self
|
| 951 |
+
|
| 952 |
+
def add_str(self):
|
| 953 |
+
repr = self._cls_dict.get("__repr__")
|
| 954 |
+
if repr is None:
|
| 955 |
+
msg = "__str__ can only be generated if a __repr__ exists."
|
| 956 |
+
raise ValueError(msg)
|
| 957 |
+
|
| 958 |
+
def __str__(self):
|
| 959 |
+
return self.__repr__()
|
| 960 |
+
|
| 961 |
+
self._cls_dict["__str__"] = self._add_method_dunders(__str__)
|
| 962 |
+
return self
|
| 963 |
+
|
| 964 |
+
def _make_getstate_setstate(self):
|
| 965 |
+
"""
|
| 966 |
+
Create custom __setstate__ and __getstate__ methods.
|
| 967 |
+
"""
|
| 968 |
+
# __weakref__ is not writable.
|
| 969 |
+
state_attr_names = tuple(
|
| 970 |
+
an for an in self._attr_names if an != "__weakref__"
|
| 971 |
+
)
|
| 972 |
+
|
| 973 |
+
def slots_getstate(self):
|
| 974 |
+
"""
|
| 975 |
+
Automatically created by attrs.
|
| 976 |
+
"""
|
| 977 |
+
return {name: getattr(self, name) for name in state_attr_names}
|
| 978 |
+
|
| 979 |
+
hash_caching_enabled = self._cache_hash
|
| 980 |
+
|
| 981 |
+
def slots_setstate(self, state):
|
| 982 |
+
"""
|
| 983 |
+
Automatically created by attrs.
|
| 984 |
+
"""
|
| 985 |
+
__bound_setattr = _OBJ_SETATTR.__get__(self)
|
| 986 |
+
if isinstance(state, tuple):
|
| 987 |
+
# Backward compatibility with attrs instances pickled with
|
| 988 |
+
# attrs versions before v22.2.0 which stored tuples.
|
| 989 |
+
for name, value in zip(state_attr_names, state):
|
| 990 |
+
__bound_setattr(name, value)
|
| 991 |
+
else:
|
| 992 |
+
for name in state_attr_names:
|
| 993 |
+
if name in state:
|
| 994 |
+
__bound_setattr(name, state[name])
|
| 995 |
+
|
| 996 |
+
# The hash code cache is not included when the object is
|
| 997 |
+
# serialized, but it still needs to be initialized to None to
|
| 998 |
+
# indicate that the first call to __hash__ should be a cache
|
| 999 |
+
# miss.
|
| 1000 |
+
if hash_caching_enabled:
|
| 1001 |
+
__bound_setattr(_HASH_CACHE_FIELD, None)
|
| 1002 |
+
|
| 1003 |
+
return slots_getstate, slots_setstate
|
| 1004 |
+
|
| 1005 |
+
def make_unhashable(self):
|
| 1006 |
+
self._cls_dict["__hash__"] = None
|
| 1007 |
+
return self
|
| 1008 |
+
|
| 1009 |
+
def add_hash(self):
|
| 1010 |
+
self._cls_dict["__hash__"] = self._add_method_dunders(
|
| 1011 |
+
_make_hash(
|
| 1012 |
+
self._cls,
|
| 1013 |
+
self._attrs,
|
| 1014 |
+
frozen=self._frozen,
|
| 1015 |
+
cache_hash=self._cache_hash,
|
| 1016 |
+
)
|
| 1017 |
+
)
|
| 1018 |
+
|
| 1019 |
+
return self
|
| 1020 |
+
|
| 1021 |
+
def add_init(self):
|
| 1022 |
+
self._cls_dict["__init__"] = self._add_method_dunders(
|
| 1023 |
+
_make_init(
|
| 1024 |
+
self._cls,
|
| 1025 |
+
self._attrs,
|
| 1026 |
+
self._has_pre_init,
|
| 1027 |
+
self._pre_init_has_args,
|
| 1028 |
+
self._has_post_init,
|
| 1029 |
+
self._frozen,
|
| 1030 |
+
self._slots,
|
| 1031 |
+
self._cache_hash,
|
| 1032 |
+
self._base_attr_map,
|
| 1033 |
+
self._is_exc,
|
| 1034 |
+
self._on_setattr,
|
| 1035 |
+
attrs_init=False,
|
| 1036 |
+
)
|
| 1037 |
+
)
|
| 1038 |
+
|
| 1039 |
+
return self
|
| 1040 |
+
|
| 1041 |
+
def add_replace(self):
|
| 1042 |
+
self._cls_dict["__replace__"] = self._add_method_dunders(
|
| 1043 |
+
lambda self, **changes: evolve(self, **changes)
|
| 1044 |
+
)
|
| 1045 |
+
return self
|
| 1046 |
+
|
| 1047 |
+
def add_match_args(self):
|
| 1048 |
+
self._cls_dict["__match_args__"] = tuple(
|
| 1049 |
+
field.name
|
| 1050 |
+
for field in self._attrs
|
| 1051 |
+
if field.init and not field.kw_only
|
| 1052 |
+
)
|
| 1053 |
+
|
| 1054 |
+
def add_attrs_init(self):
|
| 1055 |
+
self._cls_dict["__attrs_init__"] = self._add_method_dunders(
|
| 1056 |
+
_make_init(
|
| 1057 |
+
self._cls,
|
| 1058 |
+
self._attrs,
|
| 1059 |
+
self._has_pre_init,
|
| 1060 |
+
self._pre_init_has_args,
|
| 1061 |
+
self._has_post_init,
|
| 1062 |
+
self._frozen,
|
| 1063 |
+
self._slots,
|
| 1064 |
+
self._cache_hash,
|
| 1065 |
+
self._base_attr_map,
|
| 1066 |
+
self._is_exc,
|
| 1067 |
+
self._on_setattr,
|
| 1068 |
+
attrs_init=True,
|
| 1069 |
+
)
|
| 1070 |
+
)
|
| 1071 |
+
|
| 1072 |
+
return self
|
| 1073 |
+
|
| 1074 |
+
def add_eq(self):
|
| 1075 |
+
cd = self._cls_dict
|
| 1076 |
+
|
| 1077 |
+
cd["__eq__"] = self._add_method_dunders(
|
| 1078 |
+
_make_eq(self._cls, self._attrs)
|
| 1079 |
+
)
|
| 1080 |
+
cd["__ne__"] = self._add_method_dunders(_make_ne())
|
| 1081 |
+
|
| 1082 |
+
return self
|
| 1083 |
+
|
| 1084 |
+
def add_order(self):
|
| 1085 |
+
cd = self._cls_dict
|
| 1086 |
+
|
| 1087 |
+
cd["__lt__"], cd["__le__"], cd["__gt__"], cd["__ge__"] = (
|
| 1088 |
+
self._add_method_dunders(meth)
|
| 1089 |
+
for meth in _make_order(self._cls, self._attrs)
|
| 1090 |
+
)
|
| 1091 |
+
|
| 1092 |
+
return self
|
| 1093 |
+
|
| 1094 |
+
def add_setattr(self):
|
| 1095 |
+
if self._frozen:
|
| 1096 |
+
return self
|
| 1097 |
+
|
| 1098 |
+
sa_attrs = {}
|
| 1099 |
+
for a in self._attrs:
|
| 1100 |
+
on_setattr = a.on_setattr or self._on_setattr
|
| 1101 |
+
if on_setattr and on_setattr is not setters.NO_OP:
|
| 1102 |
+
sa_attrs[a.name] = a, on_setattr
|
| 1103 |
+
|
| 1104 |
+
if not sa_attrs:
|
| 1105 |
+
return self
|
| 1106 |
+
|
| 1107 |
+
if self._has_custom_setattr:
|
| 1108 |
+
# We need to write a __setattr__ but there already is one!
|
| 1109 |
+
msg = "Can't combine custom __setattr__ with on_setattr hooks."
|
| 1110 |
+
raise ValueError(msg)
|
| 1111 |
+
|
| 1112 |
+
# docstring comes from _add_method_dunders
|
| 1113 |
+
def __setattr__(self, name, val):
|
| 1114 |
+
try:
|
| 1115 |
+
a, hook = sa_attrs[name]
|
| 1116 |
+
except KeyError:
|
| 1117 |
+
nval = val
|
| 1118 |
+
else:
|
| 1119 |
+
nval = hook(self, a, val)
|
| 1120 |
+
|
| 1121 |
+
_OBJ_SETATTR(self, name, nval)
|
| 1122 |
+
|
| 1123 |
+
self._cls_dict["__attrs_own_setattr__"] = True
|
| 1124 |
+
self._cls_dict["__setattr__"] = self._add_method_dunders(__setattr__)
|
| 1125 |
+
self._wrote_own_setattr = True
|
| 1126 |
+
|
| 1127 |
+
return self
|
| 1128 |
+
|
| 1129 |
+
def _add_method_dunders(self, method):
|
| 1130 |
+
"""
|
| 1131 |
+
Add __module__ and __qualname__ to a *method* if possible.
|
| 1132 |
+
"""
|
| 1133 |
+
with contextlib.suppress(AttributeError):
|
| 1134 |
+
method.__module__ = self._cls.__module__
|
| 1135 |
+
|
| 1136 |
+
with contextlib.suppress(AttributeError):
|
| 1137 |
+
method.__qualname__ = f"{self._cls.__qualname__}.{method.__name__}"
|
| 1138 |
+
|
| 1139 |
+
with contextlib.suppress(AttributeError):
|
| 1140 |
+
method.__doc__ = (
|
| 1141 |
+
"Method generated by attrs for class "
|
| 1142 |
+
f"{self._cls.__qualname__}."
|
| 1143 |
+
)
|
| 1144 |
+
|
| 1145 |
+
return method
|
| 1146 |
+
|
| 1147 |
+
|
| 1148 |
+
def _determine_attrs_eq_order(cmp, eq, order, default_eq):
|
| 1149 |
+
"""
|
| 1150 |
+
Validate the combination of *cmp*, *eq*, and *order*. Derive the effective
|
| 1151 |
+
values of eq and order. If *eq* is None, set it to *default_eq*.
|
| 1152 |
+
"""
|
| 1153 |
+
if cmp is not None and any((eq is not None, order is not None)):
|
| 1154 |
+
msg = "Don't mix `cmp` with `eq' and `order`."
|
| 1155 |
+
raise ValueError(msg)
|
| 1156 |
+
|
| 1157 |
+
# cmp takes precedence due to bw-compatibility.
|
| 1158 |
+
if cmp is not None:
|
| 1159 |
+
return cmp, cmp
|
| 1160 |
+
|
| 1161 |
+
# If left None, equality is set to the specified default and ordering
|
| 1162 |
+
# mirrors equality.
|
| 1163 |
+
if eq is None:
|
| 1164 |
+
eq = default_eq
|
| 1165 |
+
|
| 1166 |
+
if order is None:
|
| 1167 |
+
order = eq
|
| 1168 |
+
|
| 1169 |
+
if eq is False and order is True:
|
| 1170 |
+
msg = "`order` can only be True if `eq` is True too."
|
| 1171 |
+
raise ValueError(msg)
|
| 1172 |
+
|
| 1173 |
+
return eq, order
|
| 1174 |
+
|
| 1175 |
+
|
| 1176 |
+
def _determine_attrib_eq_order(cmp, eq, order, default_eq):
|
| 1177 |
+
"""
|
| 1178 |
+
Validate the combination of *cmp*, *eq*, and *order*. Derive the effective
|
| 1179 |
+
values of eq and order. If *eq* is None, set it to *default_eq*.
|
| 1180 |
+
"""
|
| 1181 |
+
if cmp is not None and any((eq is not None, order is not None)):
|
| 1182 |
+
msg = "Don't mix `cmp` with `eq' and `order`."
|
| 1183 |
+
raise ValueError(msg)
|
| 1184 |
+
|
| 1185 |
+
def decide_callable_or_boolean(value):
|
| 1186 |
+
"""
|
| 1187 |
+
Decide whether a key function is used.
|
| 1188 |
+
"""
|
| 1189 |
+
if callable(value):
|
| 1190 |
+
value, key = True, value
|
| 1191 |
+
else:
|
| 1192 |
+
key = None
|
| 1193 |
+
return value, key
|
| 1194 |
+
|
| 1195 |
+
# cmp takes precedence due to bw-compatibility.
|
| 1196 |
+
if cmp is not None:
|
| 1197 |
+
cmp, cmp_key = decide_callable_or_boolean(cmp)
|
| 1198 |
+
return cmp, cmp_key, cmp, cmp_key
|
| 1199 |
+
|
| 1200 |
+
# If left None, equality is set to the specified default and ordering
|
| 1201 |
+
# mirrors equality.
|
| 1202 |
+
if eq is None:
|
| 1203 |
+
eq, eq_key = default_eq, None
|
| 1204 |
+
else:
|
| 1205 |
+
eq, eq_key = decide_callable_or_boolean(eq)
|
| 1206 |
+
|
| 1207 |
+
if order is None:
|
| 1208 |
+
order, order_key = eq, eq_key
|
| 1209 |
+
else:
|
| 1210 |
+
order, order_key = decide_callable_or_boolean(order)
|
| 1211 |
+
|
| 1212 |
+
if eq is False and order is True:
|
| 1213 |
+
msg = "`order` can only be True if `eq` is True too."
|
| 1214 |
+
raise ValueError(msg)
|
| 1215 |
+
|
| 1216 |
+
return eq, eq_key, order, order_key
|
| 1217 |
+
|
| 1218 |
+
|
| 1219 |
+
def _determine_whether_to_implement(
|
| 1220 |
+
cls, flag, auto_detect, dunders, default=True
|
| 1221 |
+
):
|
| 1222 |
+
"""
|
| 1223 |
+
Check whether we should implement a set of methods for *cls*.
|
| 1224 |
+
|
| 1225 |
+
*flag* is the argument passed into @attr.s like 'init', *auto_detect* the
|
| 1226 |
+
same as passed into @attr.s and *dunders* is a tuple of attribute names
|
| 1227 |
+
whose presence signal that the user has implemented it themselves.
|
| 1228 |
+
|
| 1229 |
+
Return *default* if no reason for either for or against is found.
|
| 1230 |
+
"""
|
| 1231 |
+
if flag is True or flag is False:
|
| 1232 |
+
return flag
|
| 1233 |
+
|
| 1234 |
+
if flag is None and auto_detect is False:
|
| 1235 |
+
return default
|
| 1236 |
+
|
| 1237 |
+
# Logically, flag is None and auto_detect is True here.
|
| 1238 |
+
for dunder in dunders:
|
| 1239 |
+
if _has_own_attribute(cls, dunder):
|
| 1240 |
+
return False
|
| 1241 |
+
|
| 1242 |
+
return default
|
| 1243 |
+
|
| 1244 |
+
|
| 1245 |
+
def attrs(
|
| 1246 |
+
maybe_cls=None,
|
| 1247 |
+
these=None,
|
| 1248 |
+
repr_ns=None,
|
| 1249 |
+
repr=None,
|
| 1250 |
+
cmp=None,
|
| 1251 |
+
hash=None,
|
| 1252 |
+
init=None,
|
| 1253 |
+
slots=False,
|
| 1254 |
+
frozen=False,
|
| 1255 |
+
weakref_slot=True,
|
| 1256 |
+
str=False,
|
| 1257 |
+
auto_attribs=False,
|
| 1258 |
+
kw_only=False,
|
| 1259 |
+
cache_hash=False,
|
| 1260 |
+
auto_exc=False,
|
| 1261 |
+
eq=None,
|
| 1262 |
+
order=None,
|
| 1263 |
+
auto_detect=False,
|
| 1264 |
+
collect_by_mro=False,
|
| 1265 |
+
getstate_setstate=None,
|
| 1266 |
+
on_setattr=None,
|
| 1267 |
+
field_transformer=None,
|
| 1268 |
+
match_args=True,
|
| 1269 |
+
unsafe_hash=None,
|
| 1270 |
+
):
|
| 1271 |
+
r"""
|
| 1272 |
+
A class decorator that adds :term:`dunder methods` according to the
|
| 1273 |
+
specified attributes using `attr.ib` or the *these* argument.
|
| 1274 |
+
|
| 1275 |
+
Consider using `attrs.define` / `attrs.frozen` in new code (``attr.s`` will
|
| 1276 |
+
*never* go away, though).
|
| 1277 |
+
|
| 1278 |
+
Args:
|
| 1279 |
+
repr_ns (str):
|
| 1280 |
+
When using nested classes, there was no way in Python 2 to
|
| 1281 |
+
automatically detect that. This argument allows to set a custom
|
| 1282 |
+
name for a more meaningful ``repr`` output. This argument is
|
| 1283 |
+
pointless in Python 3 and is therefore deprecated.
|
| 1284 |
+
|
| 1285 |
+
.. caution::
|
| 1286 |
+
Refer to `attrs.define` for the rest of the parameters, but note that they
|
| 1287 |
+
can have different defaults.
|
| 1288 |
+
|
| 1289 |
+
Notably, leaving *on_setattr* as `None` will **not** add any hooks.
|
| 1290 |
+
|
| 1291 |
+
.. versionadded:: 16.0.0 *slots*
|
| 1292 |
+
.. versionadded:: 16.1.0 *frozen*
|
| 1293 |
+
.. versionadded:: 16.3.0 *str*
|
| 1294 |
+
.. versionadded:: 16.3.0 Support for ``__attrs_post_init__``.
|
| 1295 |
+
.. versionchanged:: 17.1.0
|
| 1296 |
+
*hash* supports `None` as value which is also the default now.
|
| 1297 |
+
.. versionadded:: 17.3.0 *auto_attribs*
|
| 1298 |
+
.. versionchanged:: 18.1.0
|
| 1299 |
+
If *these* is passed, no attributes are deleted from the class body.
|
| 1300 |
+
.. versionchanged:: 18.1.0 If *these* is ordered, the order is retained.
|
| 1301 |
+
.. versionadded:: 18.2.0 *weakref_slot*
|
| 1302 |
+
.. deprecated:: 18.2.0
|
| 1303 |
+
``__lt__``, ``__le__``, ``__gt__``, and ``__ge__`` now raise a
|
| 1304 |
+
`DeprecationWarning` if the classes compared are subclasses of
|
| 1305 |
+
each other. ``__eq`` and ``__ne__`` never tried to compared subclasses
|
| 1306 |
+
to each other.
|
| 1307 |
+
.. versionchanged:: 19.2.0
|
| 1308 |
+
``__lt__``, ``__le__``, ``__gt__``, and ``__ge__`` now do not consider
|
| 1309 |
+
subclasses comparable anymore.
|
| 1310 |
+
.. versionadded:: 18.2.0 *kw_only*
|
| 1311 |
+
.. versionadded:: 18.2.0 *cache_hash*
|
| 1312 |
+
.. versionadded:: 19.1.0 *auto_exc*
|
| 1313 |
+
.. deprecated:: 19.2.0 *cmp* Removal on or after 2021-06-01.
|
| 1314 |
+
.. versionadded:: 19.2.0 *eq* and *order*
|
| 1315 |
+
.. versionadded:: 20.1.0 *auto_detect*
|
| 1316 |
+
.. versionadded:: 20.1.0 *collect_by_mro*
|
| 1317 |
+
.. versionadded:: 20.1.0 *getstate_setstate*
|
| 1318 |
+
.. versionadded:: 20.1.0 *on_setattr*
|
| 1319 |
+
.. versionadded:: 20.3.0 *field_transformer*
|
| 1320 |
+
.. versionchanged:: 21.1.0
|
| 1321 |
+
``init=False`` injects ``__attrs_init__``
|
| 1322 |
+
.. versionchanged:: 21.1.0 Support for ``__attrs_pre_init__``
|
| 1323 |
+
.. versionchanged:: 21.1.0 *cmp* undeprecated
|
| 1324 |
+
.. versionadded:: 21.3.0 *match_args*
|
| 1325 |
+
.. versionadded:: 22.2.0
|
| 1326 |
+
*unsafe_hash* as an alias for *hash* (for :pep:`681` compliance).
|
| 1327 |
+
.. deprecated:: 24.1.0 *repr_ns*
|
| 1328 |
+
.. versionchanged:: 24.1.0
|
| 1329 |
+
Instances are not compared as tuples of attributes anymore, but using a
|
| 1330 |
+
big ``and`` condition. This is faster and has more correct behavior for
|
| 1331 |
+
uncomparable values like `math.nan`.
|
| 1332 |
+
.. versionadded:: 24.1.0
|
| 1333 |
+
If a class has an *inherited* classmethod called
|
| 1334 |
+
``__attrs_init_subclass__``, it is executed after the class is created.
|
| 1335 |
+
.. deprecated:: 24.1.0 *hash* is deprecated in favor of *unsafe_hash*.
|
| 1336 |
+
"""
|
| 1337 |
+
if repr_ns is not None:
|
| 1338 |
+
import warnings
|
| 1339 |
+
|
| 1340 |
+
warnings.warn(
|
| 1341 |
+
DeprecationWarning(
|
| 1342 |
+
"The `repr_ns` argument is deprecated and will be removed in or after August 2025."
|
| 1343 |
+
),
|
| 1344 |
+
stacklevel=2,
|
| 1345 |
+
)
|
| 1346 |
+
|
| 1347 |
+
eq_, order_ = _determine_attrs_eq_order(cmp, eq, order, None)
|
| 1348 |
+
|
| 1349 |
+
# unsafe_hash takes precedence due to PEP 681.
|
| 1350 |
+
if unsafe_hash is not None:
|
| 1351 |
+
hash = unsafe_hash
|
| 1352 |
+
|
| 1353 |
+
if isinstance(on_setattr, (list, tuple)):
|
| 1354 |
+
on_setattr = setters.pipe(*on_setattr)
|
| 1355 |
+
|
| 1356 |
+
def wrap(cls):
|
| 1357 |
+
is_frozen = frozen or _has_frozen_base_class(cls)
|
| 1358 |
+
is_exc = auto_exc is True and issubclass(cls, BaseException)
|
| 1359 |
+
has_own_setattr = auto_detect and _has_own_attribute(
|
| 1360 |
+
cls, "__setattr__"
|
| 1361 |
+
)
|
| 1362 |
+
|
| 1363 |
+
if has_own_setattr and is_frozen:
|
| 1364 |
+
msg = "Can't freeze a class with a custom __setattr__."
|
| 1365 |
+
raise ValueError(msg)
|
| 1366 |
+
|
| 1367 |
+
builder = _ClassBuilder(
|
| 1368 |
+
cls,
|
| 1369 |
+
these,
|
| 1370 |
+
slots,
|
| 1371 |
+
is_frozen,
|
| 1372 |
+
weakref_slot,
|
| 1373 |
+
_determine_whether_to_implement(
|
| 1374 |
+
cls,
|
| 1375 |
+
getstate_setstate,
|
| 1376 |
+
auto_detect,
|
| 1377 |
+
("__getstate__", "__setstate__"),
|
| 1378 |
+
default=slots,
|
| 1379 |
+
),
|
| 1380 |
+
auto_attribs,
|
| 1381 |
+
kw_only,
|
| 1382 |
+
cache_hash,
|
| 1383 |
+
is_exc,
|
| 1384 |
+
collect_by_mro,
|
| 1385 |
+
on_setattr,
|
| 1386 |
+
has_own_setattr,
|
| 1387 |
+
field_transformer,
|
| 1388 |
+
)
|
| 1389 |
+
if _determine_whether_to_implement(
|
| 1390 |
+
cls, repr, auto_detect, ("__repr__",)
|
| 1391 |
+
):
|
| 1392 |
+
builder.add_repr(repr_ns)
|
| 1393 |
+
if str is True:
|
| 1394 |
+
builder.add_str()
|
| 1395 |
+
|
| 1396 |
+
eq = _determine_whether_to_implement(
|
| 1397 |
+
cls, eq_, auto_detect, ("__eq__", "__ne__")
|
| 1398 |
+
)
|
| 1399 |
+
if not is_exc and eq is True:
|
| 1400 |
+
builder.add_eq()
|
| 1401 |
+
if not is_exc and _determine_whether_to_implement(
|
| 1402 |
+
cls, order_, auto_detect, ("__lt__", "__le__", "__gt__", "__ge__")
|
| 1403 |
+
):
|
| 1404 |
+
builder.add_order()
|
| 1405 |
+
|
| 1406 |
+
builder.add_setattr()
|
| 1407 |
+
|
| 1408 |
+
nonlocal hash
|
| 1409 |
+
if (
|
| 1410 |
+
hash is None
|
| 1411 |
+
and auto_detect is True
|
| 1412 |
+
and _has_own_attribute(cls, "__hash__")
|
| 1413 |
+
):
|
| 1414 |
+
hash = False
|
| 1415 |
+
|
| 1416 |
+
if hash is not True and hash is not False and hash is not None:
|
| 1417 |
+
# Can't use `hash in` because 1 == True for example.
|
| 1418 |
+
msg = "Invalid value for hash. Must be True, False, or None."
|
| 1419 |
+
raise TypeError(msg)
|
| 1420 |
+
|
| 1421 |
+
if hash is False or (hash is None and eq is False) or is_exc:
|
| 1422 |
+
# Don't do anything. Should fall back to __object__'s __hash__
|
| 1423 |
+
# which is by id.
|
| 1424 |
+
if cache_hash:
|
| 1425 |
+
msg = "Invalid value for cache_hash. To use hash caching, hashing must be either explicitly or implicitly enabled."
|
| 1426 |
+
raise TypeError(msg)
|
| 1427 |
+
elif hash is True or (
|
| 1428 |
+
hash is None and eq is True and is_frozen is True
|
| 1429 |
+
):
|
| 1430 |
+
# Build a __hash__ if told so, or if it's safe.
|
| 1431 |
+
builder.add_hash()
|
| 1432 |
+
else:
|
| 1433 |
+
# Raise TypeError on attempts to hash.
|
| 1434 |
+
if cache_hash:
|
| 1435 |
+
msg = "Invalid value for cache_hash. To use hash caching, hashing must be either explicitly or implicitly enabled."
|
| 1436 |
+
raise TypeError(msg)
|
| 1437 |
+
builder.make_unhashable()
|
| 1438 |
+
|
| 1439 |
+
if _determine_whether_to_implement(
|
| 1440 |
+
cls, init, auto_detect, ("__init__",)
|
| 1441 |
+
):
|
| 1442 |
+
builder.add_init()
|
| 1443 |
+
else:
|
| 1444 |
+
builder.add_attrs_init()
|
| 1445 |
+
if cache_hash:
|
| 1446 |
+
msg = "Invalid value for cache_hash. To use hash caching, init must be True."
|
| 1447 |
+
raise TypeError(msg)
|
| 1448 |
+
|
| 1449 |
+
if PY_3_13_PLUS and not _has_own_attribute(cls, "__replace__"):
|
| 1450 |
+
builder.add_replace()
|
| 1451 |
+
|
| 1452 |
+
if (
|
| 1453 |
+
PY_3_10_PLUS
|
| 1454 |
+
and match_args
|
| 1455 |
+
and not _has_own_attribute(cls, "__match_args__")
|
| 1456 |
+
):
|
| 1457 |
+
builder.add_match_args()
|
| 1458 |
+
|
| 1459 |
+
return builder.build_class()
|
| 1460 |
+
|
| 1461 |
+
# maybe_cls's type depends on the usage of the decorator. It's a class
|
| 1462 |
+
# if it's used as `@attrs` but `None` if used as `@attrs()`.
|
| 1463 |
+
if maybe_cls is None:
|
| 1464 |
+
return wrap
|
| 1465 |
+
|
| 1466 |
+
return wrap(maybe_cls)
|
| 1467 |
+
|
| 1468 |
+
|
| 1469 |
+
_attrs = attrs
|
| 1470 |
+
"""
|
| 1471 |
+
Internal alias so we can use it in functions that take an argument called
|
| 1472 |
+
*attrs*.
|
| 1473 |
+
"""
|
| 1474 |
+
|
| 1475 |
+
|
| 1476 |
+
def _has_frozen_base_class(cls):
|
| 1477 |
+
"""
|
| 1478 |
+
Check whether *cls* has a frozen ancestor by looking at its
|
| 1479 |
+
__setattr__.
|
| 1480 |
+
"""
|
| 1481 |
+
return cls.__setattr__ is _frozen_setattrs
|
| 1482 |
+
|
| 1483 |
+
|
| 1484 |
+
def _generate_unique_filename(cls, func_name):
|
| 1485 |
+
"""
|
| 1486 |
+
Create a "filename" suitable for a function being generated.
|
| 1487 |
+
"""
|
| 1488 |
+
return (
|
| 1489 |
+
f"<attrs generated {func_name} {cls.__module__}."
|
| 1490 |
+
f"{getattr(cls, '__qualname__', cls.__name__)}>"
|
| 1491 |
+
)
|
| 1492 |
+
|
| 1493 |
+
|
| 1494 |
+
def _make_hash(cls, attrs, frozen, cache_hash):
|
| 1495 |
+
attrs = tuple(
|
| 1496 |
+
a for a in attrs if a.hash is True or (a.hash is None and a.eq is True)
|
| 1497 |
+
)
|
| 1498 |
+
|
| 1499 |
+
tab = " "
|
| 1500 |
+
|
| 1501 |
+
unique_filename = _generate_unique_filename(cls, "hash")
|
| 1502 |
+
type_hash = hash(unique_filename)
|
| 1503 |
+
# If eq is custom generated, we need to include the functions in globs
|
| 1504 |
+
globs = {}
|
| 1505 |
+
|
| 1506 |
+
hash_def = "def __hash__(self"
|
| 1507 |
+
hash_func = "hash(("
|
| 1508 |
+
closing_braces = "))"
|
| 1509 |
+
if not cache_hash:
|
| 1510 |
+
hash_def += "):"
|
| 1511 |
+
else:
|
| 1512 |
+
hash_def += ", *"
|
| 1513 |
+
|
| 1514 |
+
hash_def += ", _cache_wrapper=__import__('attr._make')._make._CacheHashWrapper):"
|
| 1515 |
+
hash_func = "_cache_wrapper(" + hash_func
|
| 1516 |
+
closing_braces += ")"
|
| 1517 |
+
|
| 1518 |
+
method_lines = [hash_def]
|
| 1519 |
+
|
| 1520 |
+
def append_hash_computation_lines(prefix, indent):
|
| 1521 |
+
"""
|
| 1522 |
+
Generate the code for actually computing the hash code.
|
| 1523 |
+
Below this will either be returned directly or used to compute
|
| 1524 |
+
a value which is then cached, depending on the value of cache_hash
|
| 1525 |
+
"""
|
| 1526 |
+
|
| 1527 |
+
method_lines.extend(
|
| 1528 |
+
[
|
| 1529 |
+
indent + prefix + hash_func,
|
| 1530 |
+
indent + f" {type_hash},",
|
| 1531 |
+
]
|
| 1532 |
+
)
|
| 1533 |
+
|
| 1534 |
+
for a in attrs:
|
| 1535 |
+
if a.eq_key:
|
| 1536 |
+
cmp_name = f"_{a.name}_key"
|
| 1537 |
+
globs[cmp_name] = a.eq_key
|
| 1538 |
+
method_lines.append(
|
| 1539 |
+
indent + f" {cmp_name}(self.{a.name}),"
|
| 1540 |
+
)
|
| 1541 |
+
else:
|
| 1542 |
+
method_lines.append(indent + f" self.{a.name},")
|
| 1543 |
+
|
| 1544 |
+
method_lines.append(indent + " " + closing_braces)
|
| 1545 |
+
|
| 1546 |
+
if cache_hash:
|
| 1547 |
+
method_lines.append(tab + f"if self.{_HASH_CACHE_FIELD} is None:")
|
| 1548 |
+
if frozen:
|
| 1549 |
+
append_hash_computation_lines(
|
| 1550 |
+
f"object.__setattr__(self, '{_HASH_CACHE_FIELD}', ", tab * 2
|
| 1551 |
+
)
|
| 1552 |
+
method_lines.append(tab * 2 + ")") # close __setattr__
|
| 1553 |
+
else:
|
| 1554 |
+
append_hash_computation_lines(
|
| 1555 |
+
f"self.{_HASH_CACHE_FIELD} = ", tab * 2
|
| 1556 |
+
)
|
| 1557 |
+
method_lines.append(tab + f"return self.{_HASH_CACHE_FIELD}")
|
| 1558 |
+
else:
|
| 1559 |
+
append_hash_computation_lines("return ", tab)
|
| 1560 |
+
|
| 1561 |
+
script = "\n".join(method_lines)
|
| 1562 |
+
return _make_method("__hash__", script, unique_filename, globs)
|
| 1563 |
+
|
| 1564 |
+
|
| 1565 |
+
def _add_hash(cls, attrs):
|
| 1566 |
+
"""
|
| 1567 |
+
Add a hash method to *cls*.
|
| 1568 |
+
"""
|
| 1569 |
+
cls.__hash__ = _make_hash(cls, attrs, frozen=False, cache_hash=False)
|
| 1570 |
+
return cls
|
| 1571 |
+
|
| 1572 |
+
|
| 1573 |
+
def _make_ne():
|
| 1574 |
+
"""
|
| 1575 |
+
Create __ne__ method.
|
| 1576 |
+
"""
|
| 1577 |
+
|
| 1578 |
+
def __ne__(self, other):
|
| 1579 |
+
"""
|
| 1580 |
+
Check equality and either forward a NotImplemented or
|
| 1581 |
+
return the result negated.
|
| 1582 |
+
"""
|
| 1583 |
+
result = self.__eq__(other)
|
| 1584 |
+
if result is NotImplemented:
|
| 1585 |
+
return NotImplemented
|
| 1586 |
+
|
| 1587 |
+
return not result
|
| 1588 |
+
|
| 1589 |
+
return __ne__
|
| 1590 |
+
|
| 1591 |
+
|
| 1592 |
+
def _make_eq(cls, attrs):
|
| 1593 |
+
"""
|
| 1594 |
+
Create __eq__ method for *cls* with *attrs*.
|
| 1595 |
+
"""
|
| 1596 |
+
attrs = [a for a in attrs if a.eq]
|
| 1597 |
+
|
| 1598 |
+
unique_filename = _generate_unique_filename(cls, "eq")
|
| 1599 |
+
lines = [
|
| 1600 |
+
"def __eq__(self, other):",
|
| 1601 |
+
" if other.__class__ is not self.__class__:",
|
| 1602 |
+
" return NotImplemented",
|
| 1603 |
+
]
|
| 1604 |
+
|
| 1605 |
+
globs = {}
|
| 1606 |
+
if attrs:
|
| 1607 |
+
lines.append(" return (")
|
| 1608 |
+
for a in attrs:
|
| 1609 |
+
if a.eq_key:
|
| 1610 |
+
cmp_name = f"_{a.name}_key"
|
| 1611 |
+
# Add the key function to the global namespace
|
| 1612 |
+
# of the evaluated function.
|
| 1613 |
+
globs[cmp_name] = a.eq_key
|
| 1614 |
+
lines.append(
|
| 1615 |
+
f" {cmp_name}(self.{a.name}) == {cmp_name}(other.{a.name})"
|
| 1616 |
+
)
|
| 1617 |
+
else:
|
| 1618 |
+
lines.append(f" self.{a.name} == other.{a.name}")
|
| 1619 |
+
if a is not attrs[-1]:
|
| 1620 |
+
lines[-1] = f"{lines[-1]} and"
|
| 1621 |
+
lines.append(" )")
|
| 1622 |
+
else:
|
| 1623 |
+
lines.append(" return True")
|
| 1624 |
+
|
| 1625 |
+
script = "\n".join(lines)
|
| 1626 |
+
|
| 1627 |
+
return _make_method("__eq__", script, unique_filename, globs)
|
| 1628 |
+
|
| 1629 |
+
|
| 1630 |
+
def _make_order(cls, attrs):
|
| 1631 |
+
"""
|
| 1632 |
+
Create ordering methods for *cls* with *attrs*.
|
| 1633 |
+
"""
|
| 1634 |
+
attrs = [a for a in attrs if a.order]
|
| 1635 |
+
|
| 1636 |
+
def attrs_to_tuple(obj):
|
| 1637 |
+
"""
|
| 1638 |
+
Save us some typing.
|
| 1639 |
+
"""
|
| 1640 |
+
return tuple(
|
| 1641 |
+
key(value) if key else value
|
| 1642 |
+
for value, key in (
|
| 1643 |
+
(getattr(obj, a.name), a.order_key) for a in attrs
|
| 1644 |
+
)
|
| 1645 |
+
)
|
| 1646 |
+
|
| 1647 |
+
def __lt__(self, other):
|
| 1648 |
+
"""
|
| 1649 |
+
Automatically created by attrs.
|
| 1650 |
+
"""
|
| 1651 |
+
if other.__class__ is self.__class__:
|
| 1652 |
+
return attrs_to_tuple(self) < attrs_to_tuple(other)
|
| 1653 |
+
|
| 1654 |
+
return NotImplemented
|
| 1655 |
+
|
| 1656 |
+
def __le__(self, other):
|
| 1657 |
+
"""
|
| 1658 |
+
Automatically created by attrs.
|
| 1659 |
+
"""
|
| 1660 |
+
if other.__class__ is self.__class__:
|
| 1661 |
+
return attrs_to_tuple(self) <= attrs_to_tuple(other)
|
| 1662 |
+
|
| 1663 |
+
return NotImplemented
|
| 1664 |
+
|
| 1665 |
+
def __gt__(self, other):
|
| 1666 |
+
"""
|
| 1667 |
+
Automatically created by attrs.
|
| 1668 |
+
"""
|
| 1669 |
+
if other.__class__ is self.__class__:
|
| 1670 |
+
return attrs_to_tuple(self) > attrs_to_tuple(other)
|
| 1671 |
+
|
| 1672 |
+
return NotImplemented
|
| 1673 |
+
|
| 1674 |
+
def __ge__(self, other):
|
| 1675 |
+
"""
|
| 1676 |
+
Automatically created by attrs.
|
| 1677 |
+
"""
|
| 1678 |
+
if other.__class__ is self.__class__:
|
| 1679 |
+
return attrs_to_tuple(self) >= attrs_to_tuple(other)
|
| 1680 |
+
|
| 1681 |
+
return NotImplemented
|
| 1682 |
+
|
| 1683 |
+
return __lt__, __le__, __gt__, __ge__
|
| 1684 |
+
|
| 1685 |
+
|
| 1686 |
+
def _add_eq(cls, attrs=None):
|
| 1687 |
+
"""
|
| 1688 |
+
Add equality methods to *cls* with *attrs*.
|
| 1689 |
+
"""
|
| 1690 |
+
if attrs is None:
|
| 1691 |
+
attrs = cls.__attrs_attrs__
|
| 1692 |
+
|
| 1693 |
+
cls.__eq__ = _make_eq(cls, attrs)
|
| 1694 |
+
cls.__ne__ = _make_ne()
|
| 1695 |
+
|
| 1696 |
+
return cls
|
| 1697 |
+
|
| 1698 |
+
|
| 1699 |
+
def _make_repr(attrs, ns, cls):
|
| 1700 |
+
unique_filename = _generate_unique_filename(cls, "repr")
|
| 1701 |
+
# Figure out which attributes to include, and which function to use to
|
| 1702 |
+
# format them. The a.repr value can be either bool or a custom
|
| 1703 |
+
# callable.
|
| 1704 |
+
attr_names_with_reprs = tuple(
|
| 1705 |
+
(a.name, (repr if a.repr is True else a.repr), a.init)
|
| 1706 |
+
for a in attrs
|
| 1707 |
+
if a.repr is not False
|
| 1708 |
+
)
|
| 1709 |
+
globs = {
|
| 1710 |
+
name + "_repr": r for name, r, _ in attr_names_with_reprs if r != repr
|
| 1711 |
+
}
|
| 1712 |
+
globs["_compat"] = _compat
|
| 1713 |
+
globs["AttributeError"] = AttributeError
|
| 1714 |
+
globs["NOTHING"] = NOTHING
|
| 1715 |
+
attribute_fragments = []
|
| 1716 |
+
for name, r, i in attr_names_with_reprs:
|
| 1717 |
+
accessor = (
|
| 1718 |
+
"self." + name if i else 'getattr(self, "' + name + '", NOTHING)'
|
| 1719 |
+
)
|
| 1720 |
+
fragment = (
|
| 1721 |
+
"%s={%s!r}" % (name, accessor)
|
| 1722 |
+
if r == repr
|
| 1723 |
+
else "%s={%s_repr(%s)}" % (name, name, accessor)
|
| 1724 |
+
)
|
| 1725 |
+
attribute_fragments.append(fragment)
|
| 1726 |
+
repr_fragment = ", ".join(attribute_fragments)
|
| 1727 |
+
|
| 1728 |
+
if ns is None:
|
| 1729 |
+
cls_name_fragment = '{self.__class__.__qualname__.rsplit(">.", 1)[-1]}'
|
| 1730 |
+
else:
|
| 1731 |
+
cls_name_fragment = ns + ".{self.__class__.__name__}"
|
| 1732 |
+
|
| 1733 |
+
lines = [
|
| 1734 |
+
"def __repr__(self):",
|
| 1735 |
+
" try:",
|
| 1736 |
+
" already_repring = _compat.repr_context.already_repring",
|
| 1737 |
+
" except AttributeError:",
|
| 1738 |
+
" already_repring = {id(self),}",
|
| 1739 |
+
" _compat.repr_context.already_repring = already_repring",
|
| 1740 |
+
" else:",
|
| 1741 |
+
" if id(self) in already_repring:",
|
| 1742 |
+
" return '...'",
|
| 1743 |
+
" else:",
|
| 1744 |
+
" already_repring.add(id(self))",
|
| 1745 |
+
" try:",
|
| 1746 |
+
f" return f'{cls_name_fragment}({repr_fragment})'",
|
| 1747 |
+
" finally:",
|
| 1748 |
+
" already_repring.remove(id(self))",
|
| 1749 |
+
]
|
| 1750 |
+
|
| 1751 |
+
return _make_method(
|
| 1752 |
+
"__repr__", "\n".join(lines), unique_filename, globs=globs
|
| 1753 |
+
)
|
| 1754 |
+
|
| 1755 |
+
|
| 1756 |
+
def _add_repr(cls, ns=None, attrs=None):
|
| 1757 |
+
"""
|
| 1758 |
+
Add a repr method to *cls*.
|
| 1759 |
+
"""
|
| 1760 |
+
if attrs is None:
|
| 1761 |
+
attrs = cls.__attrs_attrs__
|
| 1762 |
+
|
| 1763 |
+
cls.__repr__ = _make_repr(attrs, ns, cls)
|
| 1764 |
+
return cls
|
| 1765 |
+
|
| 1766 |
+
|
| 1767 |
+
def fields(cls):
|
| 1768 |
+
"""
|
| 1769 |
+
Return the tuple of *attrs* attributes for a class.
|
| 1770 |
+
|
| 1771 |
+
The tuple also allows accessing the fields by their names (see below for
|
| 1772 |
+
examples).
|
| 1773 |
+
|
| 1774 |
+
Args:
|
| 1775 |
+
cls (type): Class to introspect.
|
| 1776 |
+
|
| 1777 |
+
Raises:
|
| 1778 |
+
TypeError: If *cls* is not a class.
|
| 1779 |
+
|
| 1780 |
+
attrs.exceptions.NotAnAttrsClassError:
|
| 1781 |
+
If *cls* is not an *attrs* class.
|
| 1782 |
+
|
| 1783 |
+
Returns:
|
| 1784 |
+
tuple (with name accessors) of `attrs.Attribute`
|
| 1785 |
+
|
| 1786 |
+
.. versionchanged:: 16.2.0 Returned tuple allows accessing the fields
|
| 1787 |
+
by name.
|
| 1788 |
+
.. versionchanged:: 23.1.0 Add support for generic classes.
|
| 1789 |
+
"""
|
| 1790 |
+
generic_base = get_generic_base(cls)
|
| 1791 |
+
|
| 1792 |
+
if generic_base is None and not isinstance(cls, type):
|
| 1793 |
+
msg = "Passed object must be a class."
|
| 1794 |
+
raise TypeError(msg)
|
| 1795 |
+
|
| 1796 |
+
attrs = getattr(cls, "__attrs_attrs__", None)
|
| 1797 |
+
|
| 1798 |
+
if attrs is None:
|
| 1799 |
+
if generic_base is not None:
|
| 1800 |
+
attrs = getattr(generic_base, "__attrs_attrs__", None)
|
| 1801 |
+
if attrs is not None:
|
| 1802 |
+
# Even though this is global state, stick it on here to speed
|
| 1803 |
+
# it up. We rely on `cls` being cached for this to be
|
| 1804 |
+
# efficient.
|
| 1805 |
+
cls.__attrs_attrs__ = attrs
|
| 1806 |
+
return attrs
|
| 1807 |
+
msg = f"{cls!r} is not an attrs-decorated class."
|
| 1808 |
+
raise NotAnAttrsClassError(msg)
|
| 1809 |
+
|
| 1810 |
+
return attrs
|
| 1811 |
+
|
| 1812 |
+
|
| 1813 |
+
def fields_dict(cls):
|
| 1814 |
+
"""
|
| 1815 |
+
Return an ordered dictionary of *attrs* attributes for a class, whose keys
|
| 1816 |
+
are the attribute names.
|
| 1817 |
+
|
| 1818 |
+
Args:
|
| 1819 |
+
cls (type): Class to introspect.
|
| 1820 |
+
|
| 1821 |
+
Raises:
|
| 1822 |
+
TypeError: If *cls* is not a class.
|
| 1823 |
+
|
| 1824 |
+
attrs.exceptions.NotAnAttrsClassError:
|
| 1825 |
+
If *cls* is not an *attrs* class.
|
| 1826 |
+
|
| 1827 |
+
Returns:
|
| 1828 |
+
dict[str, attrs.Attribute]: Dict of attribute name to definition
|
| 1829 |
+
|
| 1830 |
+
.. versionadded:: 18.1.0
|
| 1831 |
+
"""
|
| 1832 |
+
if not isinstance(cls, type):
|
| 1833 |
+
msg = "Passed object must be a class."
|
| 1834 |
+
raise TypeError(msg)
|
| 1835 |
+
attrs = getattr(cls, "__attrs_attrs__", None)
|
| 1836 |
+
if attrs is None:
|
| 1837 |
+
msg = f"{cls!r} is not an attrs-decorated class."
|
| 1838 |
+
raise NotAnAttrsClassError(msg)
|
| 1839 |
+
return {a.name: a for a in attrs}
|
| 1840 |
+
|
| 1841 |
+
|
| 1842 |
+
def validate(inst):
|
| 1843 |
+
"""
|
| 1844 |
+
Validate all attributes on *inst* that have a validator.
|
| 1845 |
+
|
| 1846 |
+
Leaves all exceptions through.
|
| 1847 |
+
|
| 1848 |
+
Args:
|
| 1849 |
+
inst: Instance of a class with *attrs* attributes.
|
| 1850 |
+
"""
|
| 1851 |
+
if _config._run_validators is False:
|
| 1852 |
+
return
|
| 1853 |
+
|
| 1854 |
+
for a in fields(inst.__class__):
|
| 1855 |
+
v = a.validator
|
| 1856 |
+
if v is not None:
|
| 1857 |
+
v(inst, a, getattr(inst, a.name))
|
| 1858 |
+
|
| 1859 |
+
|
| 1860 |
+
def _is_slot_attr(a_name, base_attr_map):
|
| 1861 |
+
"""
|
| 1862 |
+
Check if the attribute name comes from a slot class.
|
| 1863 |
+
"""
|
| 1864 |
+
cls = base_attr_map.get(a_name)
|
| 1865 |
+
return cls and "__slots__" in cls.__dict__
|
| 1866 |
+
|
| 1867 |
+
|
| 1868 |
+
def _make_init(
|
| 1869 |
+
cls,
|
| 1870 |
+
attrs,
|
| 1871 |
+
pre_init,
|
| 1872 |
+
pre_init_has_args,
|
| 1873 |
+
post_init,
|
| 1874 |
+
frozen,
|
| 1875 |
+
slots,
|
| 1876 |
+
cache_hash,
|
| 1877 |
+
base_attr_map,
|
| 1878 |
+
is_exc,
|
| 1879 |
+
cls_on_setattr,
|
| 1880 |
+
attrs_init,
|
| 1881 |
+
):
|
| 1882 |
+
has_cls_on_setattr = (
|
| 1883 |
+
cls_on_setattr is not None and cls_on_setattr is not setters.NO_OP
|
| 1884 |
+
)
|
| 1885 |
+
|
| 1886 |
+
if frozen and has_cls_on_setattr:
|
| 1887 |
+
msg = "Frozen classes can't use on_setattr."
|
| 1888 |
+
raise ValueError(msg)
|
| 1889 |
+
|
| 1890 |
+
needs_cached_setattr = cache_hash or frozen
|
| 1891 |
+
filtered_attrs = []
|
| 1892 |
+
attr_dict = {}
|
| 1893 |
+
for a in attrs:
|
| 1894 |
+
if not a.init and a.default is NOTHING:
|
| 1895 |
+
continue
|
| 1896 |
+
|
| 1897 |
+
filtered_attrs.append(a)
|
| 1898 |
+
attr_dict[a.name] = a
|
| 1899 |
+
|
| 1900 |
+
if a.on_setattr is not None:
|
| 1901 |
+
if frozen is True:
|
| 1902 |
+
msg = "Frozen classes can't use on_setattr."
|
| 1903 |
+
raise ValueError(msg)
|
| 1904 |
+
|
| 1905 |
+
needs_cached_setattr = True
|
| 1906 |
+
elif has_cls_on_setattr and a.on_setattr is not setters.NO_OP:
|
| 1907 |
+
needs_cached_setattr = True
|
| 1908 |
+
|
| 1909 |
+
unique_filename = _generate_unique_filename(cls, "init")
|
| 1910 |
+
|
| 1911 |
+
script, globs, annotations = _attrs_to_init_script(
|
| 1912 |
+
filtered_attrs,
|
| 1913 |
+
frozen,
|
| 1914 |
+
slots,
|
| 1915 |
+
pre_init,
|
| 1916 |
+
pre_init_has_args,
|
| 1917 |
+
post_init,
|
| 1918 |
+
cache_hash,
|
| 1919 |
+
base_attr_map,
|
| 1920 |
+
is_exc,
|
| 1921 |
+
needs_cached_setattr,
|
| 1922 |
+
has_cls_on_setattr,
|
| 1923 |
+
"__attrs_init__" if attrs_init else "__init__",
|
| 1924 |
+
)
|
| 1925 |
+
if cls.__module__ in sys.modules:
|
| 1926 |
+
# This makes typing.get_type_hints(CLS.__init__) resolve string types.
|
| 1927 |
+
globs.update(sys.modules[cls.__module__].__dict__)
|
| 1928 |
+
|
| 1929 |
+
globs.update({"NOTHING": NOTHING, "attr_dict": attr_dict})
|
| 1930 |
+
|
| 1931 |
+
if needs_cached_setattr:
|
| 1932 |
+
# Save the lookup overhead in __init__ if we need to circumvent
|
| 1933 |
+
# setattr hooks.
|
| 1934 |
+
globs["_cached_setattr_get"] = _OBJ_SETATTR.__get__
|
| 1935 |
+
|
| 1936 |
+
init = _make_method(
|
| 1937 |
+
"__attrs_init__" if attrs_init else "__init__",
|
| 1938 |
+
script,
|
| 1939 |
+
unique_filename,
|
| 1940 |
+
globs,
|
| 1941 |
+
)
|
| 1942 |
+
init.__annotations__ = annotations
|
| 1943 |
+
|
| 1944 |
+
return init
|
| 1945 |
+
|
| 1946 |
+
|
| 1947 |
+
def _setattr(attr_name: str, value_var: str, has_on_setattr: bool) -> str:
|
| 1948 |
+
"""
|
| 1949 |
+
Use the cached object.setattr to set *attr_name* to *value_var*.
|
| 1950 |
+
"""
|
| 1951 |
+
return f"_setattr('{attr_name}', {value_var})"
|
| 1952 |
+
|
| 1953 |
+
|
| 1954 |
+
def _setattr_with_converter(
|
| 1955 |
+
attr_name: str, value_var: str, has_on_setattr: bool, converter: Converter
|
| 1956 |
+
) -> str:
|
| 1957 |
+
"""
|
| 1958 |
+
Use the cached object.setattr to set *attr_name* to *value_var*, but run
|
| 1959 |
+
its converter first.
|
| 1960 |
+
"""
|
| 1961 |
+
return f"_setattr('{attr_name}', {converter._fmt_converter_call(attr_name, value_var)})"
|
| 1962 |
+
|
| 1963 |
+
|
| 1964 |
+
def _assign(attr_name: str, value: str, has_on_setattr: bool) -> str:
|
| 1965 |
+
"""
|
| 1966 |
+
Unless *attr_name* has an on_setattr hook, use normal assignment. Otherwise
|
| 1967 |
+
relegate to _setattr.
|
| 1968 |
+
"""
|
| 1969 |
+
if has_on_setattr:
|
| 1970 |
+
return _setattr(attr_name, value, True)
|
| 1971 |
+
|
| 1972 |
+
return f"self.{attr_name} = {value}"
|
| 1973 |
+
|
| 1974 |
+
|
| 1975 |
+
def _assign_with_converter(
|
| 1976 |
+
attr_name: str, value_var: str, has_on_setattr: bool, converter: Converter
|
| 1977 |
+
) -> str:
|
| 1978 |
+
"""
|
| 1979 |
+
Unless *attr_name* has an on_setattr hook, use normal assignment after
|
| 1980 |
+
conversion. Otherwise relegate to _setattr_with_converter.
|
| 1981 |
+
"""
|
| 1982 |
+
if has_on_setattr:
|
| 1983 |
+
return _setattr_with_converter(attr_name, value_var, True, converter)
|
| 1984 |
+
|
| 1985 |
+
return f"self.{attr_name} = {converter._fmt_converter_call(attr_name, value_var)}"
|
| 1986 |
+
|
| 1987 |
+
|
| 1988 |
+
def _determine_setters(
|
| 1989 |
+
frozen: bool, slots: bool, base_attr_map: dict[str, type]
|
| 1990 |
+
):
|
| 1991 |
+
"""
|
| 1992 |
+
Determine the correct setter functions based on whether a class is frozen
|
| 1993 |
+
and/or slotted.
|
| 1994 |
+
"""
|
| 1995 |
+
if frozen is True:
|
| 1996 |
+
if slots is True:
|
| 1997 |
+
return (), _setattr, _setattr_with_converter
|
| 1998 |
+
|
| 1999 |
+
# Dict frozen classes assign directly to __dict__.
|
| 2000 |
+
# But only if the attribute doesn't come from an ancestor slot
|
| 2001 |
+
# class.
|
| 2002 |
+
# Note _inst_dict will be used again below if cache_hash is True
|
| 2003 |
+
|
| 2004 |
+
def fmt_setter(
|
| 2005 |
+
attr_name: str, value_var: str, has_on_setattr: bool
|
| 2006 |
+
) -> str:
|
| 2007 |
+
if _is_slot_attr(attr_name, base_attr_map):
|
| 2008 |
+
return _setattr(attr_name, value_var, has_on_setattr)
|
| 2009 |
+
|
| 2010 |
+
return f"_inst_dict['{attr_name}'] = {value_var}"
|
| 2011 |
+
|
| 2012 |
+
def fmt_setter_with_converter(
|
| 2013 |
+
attr_name: str,
|
| 2014 |
+
value_var: str,
|
| 2015 |
+
has_on_setattr: bool,
|
| 2016 |
+
converter: Converter,
|
| 2017 |
+
) -> str:
|
| 2018 |
+
if has_on_setattr or _is_slot_attr(attr_name, base_attr_map):
|
| 2019 |
+
return _setattr_with_converter(
|
| 2020 |
+
attr_name, value_var, has_on_setattr, converter
|
| 2021 |
+
)
|
| 2022 |
+
|
| 2023 |
+
return f"_inst_dict['{attr_name}'] = {converter._fmt_converter_call(attr_name, value_var)}"
|
| 2024 |
+
|
| 2025 |
+
return (
|
| 2026 |
+
("_inst_dict = self.__dict__",),
|
| 2027 |
+
fmt_setter,
|
| 2028 |
+
fmt_setter_with_converter,
|
| 2029 |
+
)
|
| 2030 |
+
|
| 2031 |
+
# Not frozen -- we can just assign directly.
|
| 2032 |
+
return (), _assign, _assign_with_converter
|
| 2033 |
+
|
| 2034 |
+
|
| 2035 |
+
def _attrs_to_init_script(
|
| 2036 |
+
attrs: list[Attribute],
|
| 2037 |
+
is_frozen: bool,
|
| 2038 |
+
is_slotted: bool,
|
| 2039 |
+
call_pre_init: bool,
|
| 2040 |
+
pre_init_has_args: bool,
|
| 2041 |
+
call_post_init: bool,
|
| 2042 |
+
does_cache_hash: bool,
|
| 2043 |
+
base_attr_map: dict[str, type],
|
| 2044 |
+
is_exc: bool,
|
| 2045 |
+
needs_cached_setattr: bool,
|
| 2046 |
+
has_cls_on_setattr: bool,
|
| 2047 |
+
method_name: str,
|
| 2048 |
+
) -> tuple[str, dict, dict]:
|
| 2049 |
+
"""
|
| 2050 |
+
Return a script of an initializer for *attrs*, a dict of globals, and
|
| 2051 |
+
annotations for the initializer.
|
| 2052 |
+
|
| 2053 |
+
The globals are required by the generated script.
|
| 2054 |
+
"""
|
| 2055 |
+
lines = ["self.__attrs_pre_init__()"] if call_pre_init else []
|
| 2056 |
+
|
| 2057 |
+
if needs_cached_setattr:
|
| 2058 |
+
lines.append(
|
| 2059 |
+
# Circumvent the __setattr__ descriptor to save one lookup per
|
| 2060 |
+
# assignment. Note _setattr will be used again below if
|
| 2061 |
+
# does_cache_hash is True.
|
| 2062 |
+
"_setattr = _cached_setattr_get(self)"
|
| 2063 |
+
)
|
| 2064 |
+
|
| 2065 |
+
extra_lines, fmt_setter, fmt_setter_with_converter = _determine_setters(
|
| 2066 |
+
is_frozen, is_slotted, base_attr_map
|
| 2067 |
+
)
|
| 2068 |
+
lines.extend(extra_lines)
|
| 2069 |
+
|
| 2070 |
+
args = []
|
| 2071 |
+
kw_only_args = []
|
| 2072 |
+
attrs_to_validate = []
|
| 2073 |
+
|
| 2074 |
+
# This is a dictionary of names to validator and converter callables.
|
| 2075 |
+
# Injecting this into __init__ globals lets us avoid lookups.
|
| 2076 |
+
names_for_globals = {}
|
| 2077 |
+
annotations = {"return": None}
|
| 2078 |
+
|
| 2079 |
+
for a in attrs:
|
| 2080 |
+
if a.validator:
|
| 2081 |
+
attrs_to_validate.append(a)
|
| 2082 |
+
|
| 2083 |
+
attr_name = a.name
|
| 2084 |
+
has_on_setattr = a.on_setattr is not None or (
|
| 2085 |
+
a.on_setattr is not setters.NO_OP and has_cls_on_setattr
|
| 2086 |
+
)
|
| 2087 |
+
# a.alias is set to maybe-mangled attr_name in _ClassBuilder if not
|
| 2088 |
+
# explicitly provided
|
| 2089 |
+
arg_name = a.alias
|
| 2090 |
+
|
| 2091 |
+
has_factory = isinstance(a.default, Factory)
|
| 2092 |
+
maybe_self = "self" if has_factory and a.default.takes_self else ""
|
| 2093 |
+
|
| 2094 |
+
if a.converter is not None and not isinstance(a.converter, Converter):
|
| 2095 |
+
converter = Converter(a.converter)
|
| 2096 |
+
else:
|
| 2097 |
+
converter = a.converter
|
| 2098 |
+
|
| 2099 |
+
if a.init is False:
|
| 2100 |
+
if has_factory:
|
| 2101 |
+
init_factory_name = _INIT_FACTORY_PAT % (a.name,)
|
| 2102 |
+
if converter is not None:
|
| 2103 |
+
lines.append(
|
| 2104 |
+
fmt_setter_with_converter(
|
| 2105 |
+
attr_name,
|
| 2106 |
+
init_factory_name + f"({maybe_self})",
|
| 2107 |
+
has_on_setattr,
|
| 2108 |
+
converter,
|
| 2109 |
+
)
|
| 2110 |
+
)
|
| 2111 |
+
names_for_globals[converter._get_global_name(a.name)] = (
|
| 2112 |
+
converter.converter
|
| 2113 |
+
)
|
| 2114 |
+
else:
|
| 2115 |
+
lines.append(
|
| 2116 |
+
fmt_setter(
|
| 2117 |
+
attr_name,
|
| 2118 |
+
init_factory_name + f"({maybe_self})",
|
| 2119 |
+
has_on_setattr,
|
| 2120 |
+
)
|
| 2121 |
+
)
|
| 2122 |
+
names_for_globals[init_factory_name] = a.default.factory
|
| 2123 |
+
elif converter is not None:
|
| 2124 |
+
lines.append(
|
| 2125 |
+
fmt_setter_with_converter(
|
| 2126 |
+
attr_name,
|
| 2127 |
+
f"attr_dict['{attr_name}'].default",
|
| 2128 |
+
has_on_setattr,
|
| 2129 |
+
converter,
|
| 2130 |
+
)
|
| 2131 |
+
)
|
| 2132 |
+
names_for_globals[converter._get_global_name(a.name)] = (
|
| 2133 |
+
converter.converter
|
| 2134 |
+
)
|
| 2135 |
+
else:
|
| 2136 |
+
lines.append(
|
| 2137 |
+
fmt_setter(
|
| 2138 |
+
attr_name,
|
| 2139 |
+
f"attr_dict['{attr_name}'].default",
|
| 2140 |
+
has_on_setattr,
|
| 2141 |
+
)
|
| 2142 |
+
)
|
| 2143 |
+
elif a.default is not NOTHING and not has_factory:
|
| 2144 |
+
arg = f"{arg_name}=attr_dict['{attr_name}'].default"
|
| 2145 |
+
if a.kw_only:
|
| 2146 |
+
kw_only_args.append(arg)
|
| 2147 |
+
else:
|
| 2148 |
+
args.append(arg)
|
| 2149 |
+
|
| 2150 |
+
if converter is not None:
|
| 2151 |
+
lines.append(
|
| 2152 |
+
fmt_setter_with_converter(
|
| 2153 |
+
attr_name, arg_name, has_on_setattr, converter
|
| 2154 |
+
)
|
| 2155 |
+
)
|
| 2156 |
+
names_for_globals[converter._get_global_name(a.name)] = (
|
| 2157 |
+
converter.converter
|
| 2158 |
+
)
|
| 2159 |
+
else:
|
| 2160 |
+
lines.append(fmt_setter(attr_name, arg_name, has_on_setattr))
|
| 2161 |
+
|
| 2162 |
+
elif has_factory:
|
| 2163 |
+
arg = f"{arg_name}=NOTHING"
|
| 2164 |
+
if a.kw_only:
|
| 2165 |
+
kw_only_args.append(arg)
|
| 2166 |
+
else:
|
| 2167 |
+
args.append(arg)
|
| 2168 |
+
lines.append(f"if {arg_name} is not NOTHING:")
|
| 2169 |
+
|
| 2170 |
+
init_factory_name = _INIT_FACTORY_PAT % (a.name,)
|
| 2171 |
+
if converter is not None:
|
| 2172 |
+
lines.append(
|
| 2173 |
+
" "
|
| 2174 |
+
+ fmt_setter_with_converter(
|
| 2175 |
+
attr_name, arg_name, has_on_setattr, converter
|
| 2176 |
+
)
|
| 2177 |
+
)
|
| 2178 |
+
lines.append("else:")
|
| 2179 |
+
lines.append(
|
| 2180 |
+
" "
|
| 2181 |
+
+ fmt_setter_with_converter(
|
| 2182 |
+
attr_name,
|
| 2183 |
+
init_factory_name + "(" + maybe_self + ")",
|
| 2184 |
+
has_on_setattr,
|
| 2185 |
+
converter,
|
| 2186 |
+
)
|
| 2187 |
+
)
|
| 2188 |
+
names_for_globals[converter._get_global_name(a.name)] = (
|
| 2189 |
+
converter.converter
|
| 2190 |
+
)
|
| 2191 |
+
else:
|
| 2192 |
+
lines.append(
|
| 2193 |
+
" " + fmt_setter(attr_name, arg_name, has_on_setattr)
|
| 2194 |
+
)
|
| 2195 |
+
lines.append("else:")
|
| 2196 |
+
lines.append(
|
| 2197 |
+
" "
|
| 2198 |
+
+ fmt_setter(
|
| 2199 |
+
attr_name,
|
| 2200 |
+
init_factory_name + "(" + maybe_self + ")",
|
| 2201 |
+
has_on_setattr,
|
| 2202 |
+
)
|
| 2203 |
+
)
|
| 2204 |
+
names_for_globals[init_factory_name] = a.default.factory
|
| 2205 |
+
else:
|
| 2206 |
+
if a.kw_only:
|
| 2207 |
+
kw_only_args.append(arg_name)
|
| 2208 |
+
else:
|
| 2209 |
+
args.append(arg_name)
|
| 2210 |
+
|
| 2211 |
+
if converter is not None:
|
| 2212 |
+
lines.append(
|
| 2213 |
+
fmt_setter_with_converter(
|
| 2214 |
+
attr_name, arg_name, has_on_setattr, converter
|
| 2215 |
+
)
|
| 2216 |
+
)
|
| 2217 |
+
names_for_globals[converter._get_global_name(a.name)] = (
|
| 2218 |
+
converter.converter
|
| 2219 |
+
)
|
| 2220 |
+
else:
|
| 2221 |
+
lines.append(fmt_setter(attr_name, arg_name, has_on_setattr))
|
| 2222 |
+
|
| 2223 |
+
if a.init is True:
|
| 2224 |
+
if a.type is not None and converter is None:
|
| 2225 |
+
annotations[arg_name] = a.type
|
| 2226 |
+
elif converter is not None and converter._first_param_type:
|
| 2227 |
+
# Use the type from the converter if present.
|
| 2228 |
+
annotations[arg_name] = converter._first_param_type
|
| 2229 |
+
|
| 2230 |
+
if attrs_to_validate: # we can skip this if there are no validators.
|
| 2231 |
+
names_for_globals["_config"] = _config
|
| 2232 |
+
lines.append("if _config._run_validators is True:")
|
| 2233 |
+
for a in attrs_to_validate:
|
| 2234 |
+
val_name = "__attr_validator_" + a.name
|
| 2235 |
+
attr_name = "__attr_" + a.name
|
| 2236 |
+
lines.append(f" {val_name}(self, {attr_name}, self.{a.name})")
|
| 2237 |
+
names_for_globals[val_name] = a.validator
|
| 2238 |
+
names_for_globals[attr_name] = a
|
| 2239 |
+
|
| 2240 |
+
if call_post_init:
|
| 2241 |
+
lines.append("self.__attrs_post_init__()")
|
| 2242 |
+
|
| 2243 |
+
# Because this is set only after __attrs_post_init__ is called, a crash
|
| 2244 |
+
# will result if post-init tries to access the hash code. This seemed
|
| 2245 |
+
# preferable to setting this beforehand, in which case alteration to field
|
| 2246 |
+
# values during post-init combined with post-init accessing the hash code
|
| 2247 |
+
# would result in silent bugs.
|
| 2248 |
+
if does_cache_hash:
|
| 2249 |
+
if is_frozen:
|
| 2250 |
+
if is_slotted:
|
| 2251 |
+
init_hash_cache = f"_setattr('{_HASH_CACHE_FIELD}', None)"
|
| 2252 |
+
else:
|
| 2253 |
+
init_hash_cache = f"_inst_dict['{_HASH_CACHE_FIELD}'] = None"
|
| 2254 |
+
else:
|
| 2255 |
+
init_hash_cache = f"self.{_HASH_CACHE_FIELD} = None"
|
| 2256 |
+
lines.append(init_hash_cache)
|
| 2257 |
+
|
| 2258 |
+
# For exceptions we rely on BaseException.__init__ for proper
|
| 2259 |
+
# initialization.
|
| 2260 |
+
if is_exc:
|
| 2261 |
+
vals = ",".join(f"self.{a.name}" for a in attrs if a.init)
|
| 2262 |
+
|
| 2263 |
+
lines.append(f"BaseException.__init__(self, {vals})")
|
| 2264 |
+
|
| 2265 |
+
args = ", ".join(args)
|
| 2266 |
+
pre_init_args = args
|
| 2267 |
+
if kw_only_args:
|
| 2268 |
+
# leading comma & kw_only args
|
| 2269 |
+
args += f"{', ' if args else ''}*, {', '.join(kw_only_args)}"
|
| 2270 |
+
pre_init_kw_only_args = ", ".join(
|
| 2271 |
+
[
|
| 2272 |
+
f"{kw_arg_name}={kw_arg_name}"
|
| 2273 |
+
# We need to remove the defaults from the kw_only_args.
|
| 2274 |
+
for kw_arg_name in (kwa.split("=")[0] for kwa in kw_only_args)
|
| 2275 |
+
]
|
| 2276 |
+
)
|
| 2277 |
+
pre_init_args += ", " if pre_init_args else ""
|
| 2278 |
+
pre_init_args += pre_init_kw_only_args
|
| 2279 |
+
|
| 2280 |
+
if call_pre_init and pre_init_has_args:
|
| 2281 |
+
# If pre init method has arguments, pass same arguments as `__init__`.
|
| 2282 |
+
lines[0] = f"self.__attrs_pre_init__({pre_init_args})"
|
| 2283 |
+
|
| 2284 |
+
# Python <3.12 doesn't allow backslashes in f-strings.
|
| 2285 |
+
NL = "\n "
|
| 2286 |
+
return (
|
| 2287 |
+
f"""def {method_name}(self, {args}):
|
| 2288 |
+
{NL.join(lines) if lines else "pass"}
|
| 2289 |
+
""",
|
| 2290 |
+
names_for_globals,
|
| 2291 |
+
annotations,
|
| 2292 |
+
)
|
| 2293 |
+
|
| 2294 |
+
|
| 2295 |
+
def _default_init_alias_for(name: str) -> str:
|
| 2296 |
+
"""
|
| 2297 |
+
The default __init__ parameter name for a field.
|
| 2298 |
+
|
| 2299 |
+
This performs private-name adjustment via leading-unscore stripping,
|
| 2300 |
+
and is the default value of Attribute.alias if not provided.
|
| 2301 |
+
"""
|
| 2302 |
+
|
| 2303 |
+
return name.lstrip("_")
|
| 2304 |
+
|
| 2305 |
+
|
| 2306 |
+
class Attribute:
|
| 2307 |
+
"""
|
| 2308 |
+
*Read-only* representation of an attribute.
|
| 2309 |
+
|
| 2310 |
+
.. warning::
|
| 2311 |
+
|
| 2312 |
+
You should never instantiate this class yourself.
|
| 2313 |
+
|
| 2314 |
+
The class has *all* arguments of `attr.ib` (except for ``factory`` which is
|
| 2315 |
+
only syntactic sugar for ``default=Factory(...)`` plus the following:
|
| 2316 |
+
|
| 2317 |
+
- ``name`` (`str`): The name of the attribute.
|
| 2318 |
+
- ``alias`` (`str`): The __init__ parameter name of the attribute, after
|
| 2319 |
+
any explicit overrides and default private-attribute-name handling.
|
| 2320 |
+
- ``inherited`` (`bool`): Whether or not that attribute has been inherited
|
| 2321 |
+
from a base class.
|
| 2322 |
+
- ``eq_key`` and ``order_key`` (`typing.Callable` or `None`): The
|
| 2323 |
+
callables that are used for comparing and ordering objects by this
|
| 2324 |
+
attribute, respectively. These are set by passing a callable to
|
| 2325 |
+
`attr.ib`'s ``eq``, ``order``, or ``cmp`` arguments. See also
|
| 2326 |
+
:ref:`comparison customization <custom-comparison>`.
|
| 2327 |
+
|
| 2328 |
+
Instances of this class are frequently used for introspection purposes
|
| 2329 |
+
like:
|
| 2330 |
+
|
| 2331 |
+
- `fields` returns a tuple of them.
|
| 2332 |
+
- Validators get them passed as the first argument.
|
| 2333 |
+
- The :ref:`field transformer <transform-fields>` hook receives a list of
|
| 2334 |
+
them.
|
| 2335 |
+
- The ``alias`` property exposes the __init__ parameter name of the field,
|
| 2336 |
+
with any overrides and default private-attribute handling applied.
|
| 2337 |
+
|
| 2338 |
+
|
| 2339 |
+
.. versionadded:: 20.1.0 *inherited*
|
| 2340 |
+
.. versionadded:: 20.1.0 *on_setattr*
|
| 2341 |
+
.. versionchanged:: 20.2.0 *inherited* is not taken into account for
|
| 2342 |
+
equality checks and hashing anymore.
|
| 2343 |
+
.. versionadded:: 21.1.0 *eq_key* and *order_key*
|
| 2344 |
+
.. versionadded:: 22.2.0 *alias*
|
| 2345 |
+
|
| 2346 |
+
For the full version history of the fields, see `attr.ib`.
|
| 2347 |
+
"""
|
| 2348 |
+
|
| 2349 |
+
# These slots must NOT be reordered because we use them later for
|
| 2350 |
+
# instantiation.
|
| 2351 |
+
__slots__ = ( # noqa: RUF023
|
| 2352 |
+
"name",
|
| 2353 |
+
"default",
|
| 2354 |
+
"validator",
|
| 2355 |
+
"repr",
|
| 2356 |
+
"eq",
|
| 2357 |
+
"eq_key",
|
| 2358 |
+
"order",
|
| 2359 |
+
"order_key",
|
| 2360 |
+
"hash",
|
| 2361 |
+
"init",
|
| 2362 |
+
"metadata",
|
| 2363 |
+
"type",
|
| 2364 |
+
"converter",
|
| 2365 |
+
"kw_only",
|
| 2366 |
+
"inherited",
|
| 2367 |
+
"on_setattr",
|
| 2368 |
+
"alias",
|
| 2369 |
+
)
|
| 2370 |
+
|
| 2371 |
+
def __init__(
|
| 2372 |
+
self,
|
| 2373 |
+
name,
|
| 2374 |
+
default,
|
| 2375 |
+
validator,
|
| 2376 |
+
repr,
|
| 2377 |
+
cmp, # XXX: unused, remove along with other cmp code.
|
| 2378 |
+
hash,
|
| 2379 |
+
init,
|
| 2380 |
+
inherited,
|
| 2381 |
+
metadata=None,
|
| 2382 |
+
type=None,
|
| 2383 |
+
converter=None,
|
| 2384 |
+
kw_only=False,
|
| 2385 |
+
eq=None,
|
| 2386 |
+
eq_key=None,
|
| 2387 |
+
order=None,
|
| 2388 |
+
order_key=None,
|
| 2389 |
+
on_setattr=None,
|
| 2390 |
+
alias=None,
|
| 2391 |
+
):
|
| 2392 |
+
eq, eq_key, order, order_key = _determine_attrib_eq_order(
|
| 2393 |
+
cmp, eq_key or eq, order_key or order, True
|
| 2394 |
+
)
|
| 2395 |
+
|
| 2396 |
+
# Cache this descriptor here to speed things up later.
|
| 2397 |
+
bound_setattr = _OBJ_SETATTR.__get__(self)
|
| 2398 |
+
|
| 2399 |
+
# Despite the big red warning, people *do* instantiate `Attribute`
|
| 2400 |
+
# themselves.
|
| 2401 |
+
bound_setattr("name", name)
|
| 2402 |
+
bound_setattr("default", default)
|
| 2403 |
+
bound_setattr("validator", validator)
|
| 2404 |
+
bound_setattr("repr", repr)
|
| 2405 |
+
bound_setattr("eq", eq)
|
| 2406 |
+
bound_setattr("eq_key", eq_key)
|
| 2407 |
+
bound_setattr("order", order)
|
| 2408 |
+
bound_setattr("order_key", order_key)
|
| 2409 |
+
bound_setattr("hash", hash)
|
| 2410 |
+
bound_setattr("init", init)
|
| 2411 |
+
bound_setattr("converter", converter)
|
| 2412 |
+
bound_setattr(
|
| 2413 |
+
"metadata",
|
| 2414 |
+
(
|
| 2415 |
+
types.MappingProxyType(dict(metadata)) # Shallow copy
|
| 2416 |
+
if metadata
|
| 2417 |
+
else _EMPTY_METADATA_SINGLETON
|
| 2418 |
+
),
|
| 2419 |
+
)
|
| 2420 |
+
bound_setattr("type", type)
|
| 2421 |
+
bound_setattr("kw_only", kw_only)
|
| 2422 |
+
bound_setattr("inherited", inherited)
|
| 2423 |
+
bound_setattr("on_setattr", on_setattr)
|
| 2424 |
+
bound_setattr("alias", alias)
|
| 2425 |
+
|
| 2426 |
+
def __setattr__(self, name, value):
|
| 2427 |
+
raise FrozenInstanceError
|
| 2428 |
+
|
| 2429 |
+
@classmethod
|
| 2430 |
+
def from_counting_attr(cls, name, ca, type=None):
|
| 2431 |
+
# type holds the annotated value. deal with conflicts:
|
| 2432 |
+
if type is None:
|
| 2433 |
+
type = ca.type
|
| 2434 |
+
elif ca.type is not None:
|
| 2435 |
+
msg = "Type annotation and type argument cannot both be present"
|
| 2436 |
+
raise ValueError(msg)
|
| 2437 |
+
inst_dict = {
|
| 2438 |
+
k: getattr(ca, k)
|
| 2439 |
+
for k in Attribute.__slots__
|
| 2440 |
+
if k
|
| 2441 |
+
not in (
|
| 2442 |
+
"name",
|
| 2443 |
+
"validator",
|
| 2444 |
+
"default",
|
| 2445 |
+
"type",
|
| 2446 |
+
"inherited",
|
| 2447 |
+
) # exclude methods and deprecated alias
|
| 2448 |
+
}
|
| 2449 |
+
return cls(
|
| 2450 |
+
name=name,
|
| 2451 |
+
validator=ca._validator,
|
| 2452 |
+
default=ca._default,
|
| 2453 |
+
type=type,
|
| 2454 |
+
cmp=None,
|
| 2455 |
+
inherited=False,
|
| 2456 |
+
**inst_dict,
|
| 2457 |
+
)
|
| 2458 |
+
|
| 2459 |
+
# Don't use attrs.evolve since fields(Attribute) doesn't work
|
| 2460 |
+
def evolve(self, **changes):
|
| 2461 |
+
"""
|
| 2462 |
+
Copy *self* and apply *changes*.
|
| 2463 |
+
|
| 2464 |
+
This works similarly to `attrs.evolve` but that function does not work
|
| 2465 |
+
with :class:`attrs.Attribute`.
|
| 2466 |
+
|
| 2467 |
+
It is mainly meant to be used for `transform-fields`.
|
| 2468 |
+
|
| 2469 |
+
.. versionadded:: 20.3.0
|
| 2470 |
+
"""
|
| 2471 |
+
new = copy.copy(self)
|
| 2472 |
+
|
| 2473 |
+
new._setattrs(changes.items())
|
| 2474 |
+
|
| 2475 |
+
return new
|
| 2476 |
+
|
| 2477 |
+
# Don't use _add_pickle since fields(Attribute) doesn't work
|
| 2478 |
+
def __getstate__(self):
|
| 2479 |
+
"""
|
| 2480 |
+
Play nice with pickle.
|
| 2481 |
+
"""
|
| 2482 |
+
return tuple(
|
| 2483 |
+
getattr(self, name) if name != "metadata" else dict(self.metadata)
|
| 2484 |
+
for name in self.__slots__
|
| 2485 |
+
)
|
| 2486 |
+
|
| 2487 |
+
def __setstate__(self, state):
|
| 2488 |
+
"""
|
| 2489 |
+
Play nice with pickle.
|
| 2490 |
+
"""
|
| 2491 |
+
self._setattrs(zip(self.__slots__, state))
|
| 2492 |
+
|
| 2493 |
+
def _setattrs(self, name_values_pairs):
|
| 2494 |
+
bound_setattr = _OBJ_SETATTR.__get__(self)
|
| 2495 |
+
for name, value in name_values_pairs:
|
| 2496 |
+
if name != "metadata":
|
| 2497 |
+
bound_setattr(name, value)
|
| 2498 |
+
else:
|
| 2499 |
+
bound_setattr(
|
| 2500 |
+
name,
|
| 2501 |
+
(
|
| 2502 |
+
types.MappingProxyType(dict(value))
|
| 2503 |
+
if value
|
| 2504 |
+
else _EMPTY_METADATA_SINGLETON
|
| 2505 |
+
),
|
| 2506 |
+
)
|
| 2507 |
+
|
| 2508 |
+
|
| 2509 |
+
_a = [
|
| 2510 |
+
Attribute(
|
| 2511 |
+
name=name,
|
| 2512 |
+
default=NOTHING,
|
| 2513 |
+
validator=None,
|
| 2514 |
+
repr=True,
|
| 2515 |
+
cmp=None,
|
| 2516 |
+
eq=True,
|
| 2517 |
+
order=False,
|
| 2518 |
+
hash=(name != "metadata"),
|
| 2519 |
+
init=True,
|
| 2520 |
+
inherited=False,
|
| 2521 |
+
alias=_default_init_alias_for(name),
|
| 2522 |
+
)
|
| 2523 |
+
for name in Attribute.__slots__
|
| 2524 |
+
]
|
| 2525 |
+
|
| 2526 |
+
Attribute = _add_hash(
|
| 2527 |
+
_add_eq(
|
| 2528 |
+
_add_repr(Attribute, attrs=_a),
|
| 2529 |
+
attrs=[a for a in _a if a.name != "inherited"],
|
| 2530 |
+
),
|
| 2531 |
+
attrs=[a for a in _a if a.hash and a.name != "inherited"],
|
| 2532 |
+
)
|
| 2533 |
+
|
| 2534 |
+
|
| 2535 |
+
class _CountingAttr:
|
| 2536 |
+
"""
|
| 2537 |
+
Intermediate representation of attributes that uses a counter to preserve
|
| 2538 |
+
the order in which the attributes have been defined.
|
| 2539 |
+
|
| 2540 |
+
*Internal* data structure of the attrs library. Running into is most
|
| 2541 |
+
likely the result of a bug like a forgotten `@attr.s` decorator.
|
| 2542 |
+
"""
|
| 2543 |
+
|
| 2544 |
+
__slots__ = (
|
| 2545 |
+
"_default",
|
| 2546 |
+
"_validator",
|
| 2547 |
+
"alias",
|
| 2548 |
+
"converter",
|
| 2549 |
+
"counter",
|
| 2550 |
+
"eq",
|
| 2551 |
+
"eq_key",
|
| 2552 |
+
"hash",
|
| 2553 |
+
"init",
|
| 2554 |
+
"kw_only",
|
| 2555 |
+
"metadata",
|
| 2556 |
+
"on_setattr",
|
| 2557 |
+
"order",
|
| 2558 |
+
"order_key",
|
| 2559 |
+
"repr",
|
| 2560 |
+
"type",
|
| 2561 |
+
)
|
| 2562 |
+
__attrs_attrs__ = (
|
| 2563 |
+
*tuple(
|
| 2564 |
+
Attribute(
|
| 2565 |
+
name=name,
|
| 2566 |
+
alias=_default_init_alias_for(name),
|
| 2567 |
+
default=NOTHING,
|
| 2568 |
+
validator=None,
|
| 2569 |
+
repr=True,
|
| 2570 |
+
cmp=None,
|
| 2571 |
+
hash=True,
|
| 2572 |
+
init=True,
|
| 2573 |
+
kw_only=False,
|
| 2574 |
+
eq=True,
|
| 2575 |
+
eq_key=None,
|
| 2576 |
+
order=False,
|
| 2577 |
+
order_key=None,
|
| 2578 |
+
inherited=False,
|
| 2579 |
+
on_setattr=None,
|
| 2580 |
+
)
|
| 2581 |
+
for name in (
|
| 2582 |
+
"counter",
|
| 2583 |
+
"_default",
|
| 2584 |
+
"repr",
|
| 2585 |
+
"eq",
|
| 2586 |
+
"order",
|
| 2587 |
+
"hash",
|
| 2588 |
+
"init",
|
| 2589 |
+
"on_setattr",
|
| 2590 |
+
"alias",
|
| 2591 |
+
)
|
| 2592 |
+
),
|
| 2593 |
+
Attribute(
|
| 2594 |
+
name="metadata",
|
| 2595 |
+
alias="metadata",
|
| 2596 |
+
default=None,
|
| 2597 |
+
validator=None,
|
| 2598 |
+
repr=True,
|
| 2599 |
+
cmp=None,
|
| 2600 |
+
hash=False,
|
| 2601 |
+
init=True,
|
| 2602 |
+
kw_only=False,
|
| 2603 |
+
eq=True,
|
| 2604 |
+
eq_key=None,
|
| 2605 |
+
order=False,
|
| 2606 |
+
order_key=None,
|
| 2607 |
+
inherited=False,
|
| 2608 |
+
on_setattr=None,
|
| 2609 |
+
),
|
| 2610 |
+
)
|
| 2611 |
+
cls_counter = 0
|
| 2612 |
+
|
| 2613 |
+
def __init__(
|
| 2614 |
+
self,
|
| 2615 |
+
default,
|
| 2616 |
+
validator,
|
| 2617 |
+
repr,
|
| 2618 |
+
cmp,
|
| 2619 |
+
hash,
|
| 2620 |
+
init,
|
| 2621 |
+
converter,
|
| 2622 |
+
metadata,
|
| 2623 |
+
type,
|
| 2624 |
+
kw_only,
|
| 2625 |
+
eq,
|
| 2626 |
+
eq_key,
|
| 2627 |
+
order,
|
| 2628 |
+
order_key,
|
| 2629 |
+
on_setattr,
|
| 2630 |
+
alias,
|
| 2631 |
+
):
|
| 2632 |
+
_CountingAttr.cls_counter += 1
|
| 2633 |
+
self.counter = _CountingAttr.cls_counter
|
| 2634 |
+
self._default = default
|
| 2635 |
+
self._validator = validator
|
| 2636 |
+
self.converter = converter
|
| 2637 |
+
self.repr = repr
|
| 2638 |
+
self.eq = eq
|
| 2639 |
+
self.eq_key = eq_key
|
| 2640 |
+
self.order = order
|
| 2641 |
+
self.order_key = order_key
|
| 2642 |
+
self.hash = hash
|
| 2643 |
+
self.init = init
|
| 2644 |
+
self.metadata = metadata
|
| 2645 |
+
self.type = type
|
| 2646 |
+
self.kw_only = kw_only
|
| 2647 |
+
self.on_setattr = on_setattr
|
| 2648 |
+
self.alias = alias
|
| 2649 |
+
|
| 2650 |
+
def validator(self, meth):
|
| 2651 |
+
"""
|
| 2652 |
+
Decorator that adds *meth* to the list of validators.
|
| 2653 |
+
|
| 2654 |
+
Returns *meth* unchanged.
|
| 2655 |
+
|
| 2656 |
+
.. versionadded:: 17.1.0
|
| 2657 |
+
"""
|
| 2658 |
+
if self._validator is None:
|
| 2659 |
+
self._validator = meth
|
| 2660 |
+
else:
|
| 2661 |
+
self._validator = and_(self._validator, meth)
|
| 2662 |
+
return meth
|
| 2663 |
+
|
| 2664 |
+
def default(self, meth):
|
| 2665 |
+
"""
|
| 2666 |
+
Decorator that allows to set the default for an attribute.
|
| 2667 |
+
|
| 2668 |
+
Returns *meth* unchanged.
|
| 2669 |
+
|
| 2670 |
+
Raises:
|
| 2671 |
+
DefaultAlreadySetError: If default has been set before.
|
| 2672 |
+
|
| 2673 |
+
.. versionadded:: 17.1.0
|
| 2674 |
+
"""
|
| 2675 |
+
if self._default is not NOTHING:
|
| 2676 |
+
raise DefaultAlreadySetError
|
| 2677 |
+
|
| 2678 |
+
self._default = Factory(meth, takes_self=True)
|
| 2679 |
+
|
| 2680 |
+
return meth
|
| 2681 |
+
|
| 2682 |
+
|
| 2683 |
+
_CountingAttr = _add_eq(_add_repr(_CountingAttr))
|
| 2684 |
+
|
| 2685 |
+
|
| 2686 |
+
class Factory:
|
| 2687 |
+
"""
|
| 2688 |
+
Stores a factory callable.
|
| 2689 |
+
|
| 2690 |
+
If passed as the default value to `attrs.field`, the factory is used to
|
| 2691 |
+
generate a new value.
|
| 2692 |
+
|
| 2693 |
+
Args:
|
| 2694 |
+
factory (typing.Callable):
|
| 2695 |
+
A callable that takes either none or exactly one mandatory
|
| 2696 |
+
positional argument depending on *takes_self*.
|
| 2697 |
+
|
| 2698 |
+
takes_self (bool):
|
| 2699 |
+
Pass the partially initialized instance that is being initialized
|
| 2700 |
+
as a positional argument.
|
| 2701 |
+
|
| 2702 |
+
.. versionadded:: 17.1.0 *takes_self*
|
| 2703 |
+
"""
|
| 2704 |
+
|
| 2705 |
+
__slots__ = ("factory", "takes_self")
|
| 2706 |
+
|
| 2707 |
+
def __init__(self, factory, takes_self=False):
|
| 2708 |
+
self.factory = factory
|
| 2709 |
+
self.takes_self = takes_self
|
| 2710 |
+
|
| 2711 |
+
def __getstate__(self):
|
| 2712 |
+
"""
|
| 2713 |
+
Play nice with pickle.
|
| 2714 |
+
"""
|
| 2715 |
+
return tuple(getattr(self, name) for name in self.__slots__)
|
| 2716 |
+
|
| 2717 |
+
def __setstate__(self, state):
|
| 2718 |
+
"""
|
| 2719 |
+
Play nice with pickle.
|
| 2720 |
+
"""
|
| 2721 |
+
for name, value in zip(self.__slots__, state):
|
| 2722 |
+
setattr(self, name, value)
|
| 2723 |
+
|
| 2724 |
+
|
| 2725 |
+
_f = [
|
| 2726 |
+
Attribute(
|
| 2727 |
+
name=name,
|
| 2728 |
+
default=NOTHING,
|
| 2729 |
+
validator=None,
|
| 2730 |
+
repr=True,
|
| 2731 |
+
cmp=None,
|
| 2732 |
+
eq=True,
|
| 2733 |
+
order=False,
|
| 2734 |
+
hash=True,
|
| 2735 |
+
init=True,
|
| 2736 |
+
inherited=False,
|
| 2737 |
+
)
|
| 2738 |
+
for name in Factory.__slots__
|
| 2739 |
+
]
|
| 2740 |
+
|
| 2741 |
+
Factory = _add_hash(_add_eq(_add_repr(Factory, attrs=_f), attrs=_f), attrs=_f)
|
| 2742 |
+
|
| 2743 |
+
|
| 2744 |
+
class Converter:
|
| 2745 |
+
"""
|
| 2746 |
+
Stores a converter callable.
|
| 2747 |
+
|
| 2748 |
+
Allows for the wrapped converter to take additional arguments. The
|
| 2749 |
+
arguments are passed in the order they are documented.
|
| 2750 |
+
|
| 2751 |
+
Args:
|
| 2752 |
+
converter (Callable): A callable that converts the passed value.
|
| 2753 |
+
|
| 2754 |
+
takes_self (bool):
|
| 2755 |
+
Pass the partially initialized instance that is being initialized
|
| 2756 |
+
as a positional argument. (default: `False`)
|
| 2757 |
+
|
| 2758 |
+
takes_field (bool):
|
| 2759 |
+
Pass the field definition (an :class:`Attribute`) into the
|
| 2760 |
+
converter as a positional argument. (default: `False`)
|
| 2761 |
+
|
| 2762 |
+
.. versionadded:: 24.1.0
|
| 2763 |
+
"""
|
| 2764 |
+
|
| 2765 |
+
__slots__ = (
|
| 2766 |
+
"__call__",
|
| 2767 |
+
"_first_param_type",
|
| 2768 |
+
"_global_name",
|
| 2769 |
+
"converter",
|
| 2770 |
+
"takes_field",
|
| 2771 |
+
"takes_self",
|
| 2772 |
+
)
|
| 2773 |
+
|
| 2774 |
+
def __init__(self, converter, *, takes_self=False, takes_field=False):
|
| 2775 |
+
self.converter = converter
|
| 2776 |
+
self.takes_self = takes_self
|
| 2777 |
+
self.takes_field = takes_field
|
| 2778 |
+
|
| 2779 |
+
ex = _AnnotationExtractor(converter)
|
| 2780 |
+
self._first_param_type = ex.get_first_param_type()
|
| 2781 |
+
|
| 2782 |
+
if not (self.takes_self or self.takes_field):
|
| 2783 |
+
self.__call__ = lambda value, _, __: self.converter(value)
|
| 2784 |
+
elif self.takes_self and not self.takes_field:
|
| 2785 |
+
self.__call__ = lambda value, instance, __: self.converter(
|
| 2786 |
+
value, instance
|
| 2787 |
+
)
|
| 2788 |
+
elif not self.takes_self and self.takes_field:
|
| 2789 |
+
self.__call__ = lambda value, __, field: self.converter(
|
| 2790 |
+
value, field
|
| 2791 |
+
)
|
| 2792 |
+
else:
|
| 2793 |
+
self.__call__ = lambda value, instance, field: self.converter(
|
| 2794 |
+
value, instance, field
|
| 2795 |
+
)
|
| 2796 |
+
|
| 2797 |
+
rt = ex.get_return_type()
|
| 2798 |
+
if rt is not None:
|
| 2799 |
+
self.__call__.__annotations__["return"] = rt
|
| 2800 |
+
|
| 2801 |
+
@staticmethod
|
| 2802 |
+
def _get_global_name(attr_name: str) -> str:
|
| 2803 |
+
"""
|
| 2804 |
+
Return the name that a converter for an attribute name *attr_name*
|
| 2805 |
+
would have.
|
| 2806 |
+
"""
|
| 2807 |
+
return f"__attr_converter_{attr_name}"
|
| 2808 |
+
|
| 2809 |
+
def _fmt_converter_call(self, attr_name: str, value_var: str) -> str:
|
| 2810 |
+
"""
|
| 2811 |
+
Return a string that calls the converter for an attribute name
|
| 2812 |
+
*attr_name* and the value in variable named *value_var* according to
|
| 2813 |
+
`self.takes_self` and `self.takes_field`.
|
| 2814 |
+
"""
|
| 2815 |
+
if not (self.takes_self or self.takes_field):
|
| 2816 |
+
return f"{self._get_global_name(attr_name)}({value_var})"
|
| 2817 |
+
|
| 2818 |
+
if self.takes_self and self.takes_field:
|
| 2819 |
+
return f"{self._get_global_name(attr_name)}({value_var}, self, attr_dict['{attr_name}'])"
|
| 2820 |
+
|
| 2821 |
+
if self.takes_self:
|
| 2822 |
+
return f"{self._get_global_name(attr_name)}({value_var}, self)"
|
| 2823 |
+
|
| 2824 |
+
return f"{self._get_global_name(attr_name)}({value_var}, attr_dict['{attr_name}'])"
|
| 2825 |
+
|
| 2826 |
+
def __getstate__(self):
|
| 2827 |
+
"""
|
| 2828 |
+
Return a dict containing only converter and takes_self -- the rest gets
|
| 2829 |
+
computed when loading.
|
| 2830 |
+
"""
|
| 2831 |
+
return {
|
| 2832 |
+
"converter": self.converter,
|
| 2833 |
+
"takes_self": self.takes_self,
|
| 2834 |
+
"takes_field": self.takes_field,
|
| 2835 |
+
}
|
| 2836 |
+
|
| 2837 |
+
def __setstate__(self, state):
|
| 2838 |
+
"""
|
| 2839 |
+
Load instance from state.
|
| 2840 |
+
"""
|
| 2841 |
+
self.__init__(**state)
|
| 2842 |
+
|
| 2843 |
+
|
| 2844 |
+
_f = [
|
| 2845 |
+
Attribute(
|
| 2846 |
+
name=name,
|
| 2847 |
+
default=NOTHING,
|
| 2848 |
+
validator=None,
|
| 2849 |
+
repr=True,
|
| 2850 |
+
cmp=None,
|
| 2851 |
+
eq=True,
|
| 2852 |
+
order=False,
|
| 2853 |
+
hash=True,
|
| 2854 |
+
init=True,
|
| 2855 |
+
inherited=False,
|
| 2856 |
+
)
|
| 2857 |
+
for name in ("converter", "takes_self", "takes_field")
|
| 2858 |
+
]
|
| 2859 |
+
|
| 2860 |
+
Converter = _add_hash(
|
| 2861 |
+
_add_eq(_add_repr(Converter, attrs=_f), attrs=_f), attrs=_f
|
| 2862 |
+
)
|
| 2863 |
+
|
| 2864 |
+
|
| 2865 |
+
def make_class(
|
| 2866 |
+
name, attrs, bases=(object,), class_body=None, **attributes_arguments
|
| 2867 |
+
):
|
| 2868 |
+
r"""
|
| 2869 |
+
A quick way to create a new class called *name* with *attrs*.
|
| 2870 |
+
|
| 2871 |
+
.. note::
|
| 2872 |
+
|
| 2873 |
+
``make_class()`` is a thin wrapper around `attr.s`, not `attrs.define`
|
| 2874 |
+
which means that it doesn't come with some of the improved defaults.
|
| 2875 |
+
|
| 2876 |
+
For example, if you want the same ``on_setattr`` behavior as in
|
| 2877 |
+
`attrs.define`, you have to pass the hooks yourself: ``make_class(...,
|
| 2878 |
+
on_setattr=setters.pipe(setters.convert, setters.validate)``
|
| 2879 |
+
|
| 2880 |
+
Args:
|
| 2881 |
+
name (str): The name for the new class.
|
| 2882 |
+
|
| 2883 |
+
attrs (list | dict):
|
| 2884 |
+
A list of names or a dictionary of mappings of names to `attr.ib`\
|
| 2885 |
+
s / `attrs.field`\ s.
|
| 2886 |
+
|
| 2887 |
+
The order is deduced from the order of the names or attributes
|
| 2888 |
+
inside *attrs*. Otherwise the order of the definition of the
|
| 2889 |
+
attributes is used.
|
| 2890 |
+
|
| 2891 |
+
bases (tuple[type, ...]): Classes that the new class will subclass.
|
| 2892 |
+
|
| 2893 |
+
class_body (dict):
|
| 2894 |
+
An optional dictionary of class attributes for the new class.
|
| 2895 |
+
|
| 2896 |
+
attributes_arguments: Passed unmodified to `attr.s`.
|
| 2897 |
+
|
| 2898 |
+
Returns:
|
| 2899 |
+
type: A new class with *attrs*.
|
| 2900 |
+
|
| 2901 |
+
.. versionadded:: 17.1.0 *bases*
|
| 2902 |
+
.. versionchanged:: 18.1.0 If *attrs* is ordered, the order is retained.
|
| 2903 |
+
.. versionchanged:: 23.2.0 *class_body*
|
| 2904 |
+
"""
|
| 2905 |
+
if isinstance(attrs, dict):
|
| 2906 |
+
cls_dict = attrs
|
| 2907 |
+
elif isinstance(attrs, (list, tuple)):
|
| 2908 |
+
cls_dict = {a: attrib() for a in attrs}
|
| 2909 |
+
else:
|
| 2910 |
+
msg = "attrs argument must be a dict or a list."
|
| 2911 |
+
raise TypeError(msg)
|
| 2912 |
+
|
| 2913 |
+
pre_init = cls_dict.pop("__attrs_pre_init__", None)
|
| 2914 |
+
post_init = cls_dict.pop("__attrs_post_init__", None)
|
| 2915 |
+
user_init = cls_dict.pop("__init__", None)
|
| 2916 |
+
|
| 2917 |
+
body = {}
|
| 2918 |
+
if class_body is not None:
|
| 2919 |
+
body.update(class_body)
|
| 2920 |
+
if pre_init is not None:
|
| 2921 |
+
body["__attrs_pre_init__"] = pre_init
|
| 2922 |
+
if post_init is not None:
|
| 2923 |
+
body["__attrs_post_init__"] = post_init
|
| 2924 |
+
if user_init is not None:
|
| 2925 |
+
body["__init__"] = user_init
|
| 2926 |
+
|
| 2927 |
+
type_ = types.new_class(name, bases, {}, lambda ns: ns.update(body))
|
| 2928 |
+
|
| 2929 |
+
# For pickling to work, the __module__ variable needs to be set to the
|
| 2930 |
+
# frame where the class is created. Bypass this step in environments where
|
| 2931 |
+
# sys._getframe is not defined (Jython for example) or sys._getframe is not
|
| 2932 |
+
# defined for arguments greater than 0 (IronPython).
|
| 2933 |
+
with contextlib.suppress(AttributeError, ValueError):
|
| 2934 |
+
type_.__module__ = sys._getframe(1).f_globals.get(
|
| 2935 |
+
"__name__", "__main__"
|
| 2936 |
+
)
|
| 2937 |
+
|
| 2938 |
+
# We do it here for proper warnings with meaningful stacklevel.
|
| 2939 |
+
cmp = attributes_arguments.pop("cmp", None)
|
| 2940 |
+
(
|
| 2941 |
+
attributes_arguments["eq"],
|
| 2942 |
+
attributes_arguments["order"],
|
| 2943 |
+
) = _determine_attrs_eq_order(
|
| 2944 |
+
cmp,
|
| 2945 |
+
attributes_arguments.get("eq"),
|
| 2946 |
+
attributes_arguments.get("order"),
|
| 2947 |
+
True,
|
| 2948 |
+
)
|
| 2949 |
+
|
| 2950 |
+
cls = _attrs(these=cls_dict, **attributes_arguments)(type_)
|
| 2951 |
+
# Only add type annotations now or "_attrs()" will complain:
|
| 2952 |
+
cls.__annotations__ = {
|
| 2953 |
+
k: v.type for k, v in cls_dict.items() if v.type is not None
|
| 2954 |
+
}
|
| 2955 |
+
return cls
|
| 2956 |
+
|
| 2957 |
+
|
| 2958 |
+
# These are required by within this module so we define them here and merely
|
| 2959 |
+
# import into .validators / .converters.
|
| 2960 |
+
|
| 2961 |
+
|
| 2962 |
+
@attrs(slots=True, unsafe_hash=True)
|
| 2963 |
+
class _AndValidator:
|
| 2964 |
+
"""
|
| 2965 |
+
Compose many validators to a single one.
|
| 2966 |
+
"""
|
| 2967 |
+
|
| 2968 |
+
_validators = attrib()
|
| 2969 |
+
|
| 2970 |
+
def __call__(self, inst, attr, value):
|
| 2971 |
+
for v in self._validators:
|
| 2972 |
+
v(inst, attr, value)
|
| 2973 |
+
|
| 2974 |
+
|
| 2975 |
+
def and_(*validators):
|
| 2976 |
+
"""
|
| 2977 |
+
A validator that composes multiple validators into one.
|
| 2978 |
+
|
| 2979 |
+
When called on a value, it runs all wrapped validators.
|
| 2980 |
+
|
| 2981 |
+
Args:
|
| 2982 |
+
validators (~collections.abc.Iterable[typing.Callable]):
|
| 2983 |
+
Arbitrary number of validators.
|
| 2984 |
+
|
| 2985 |
+
.. versionadded:: 17.1.0
|
| 2986 |
+
"""
|
| 2987 |
+
vals = []
|
| 2988 |
+
for validator in validators:
|
| 2989 |
+
vals.extend(
|
| 2990 |
+
validator._validators
|
| 2991 |
+
if isinstance(validator, _AndValidator)
|
| 2992 |
+
else [validator]
|
| 2993 |
+
)
|
| 2994 |
+
|
| 2995 |
+
return _AndValidator(tuple(vals))
|
| 2996 |
+
|
| 2997 |
+
|
| 2998 |
+
def pipe(*converters):
|
| 2999 |
+
"""
|
| 3000 |
+
A converter that composes multiple converters into one.
|
| 3001 |
+
|
| 3002 |
+
When called on a value, it runs all wrapped converters, returning the
|
| 3003 |
+
*last* value.
|
| 3004 |
+
|
| 3005 |
+
Type annotations will be inferred from the wrapped converters', if they
|
| 3006 |
+
have any.
|
| 3007 |
+
|
| 3008 |
+
converters (~collections.abc.Iterable[typing.Callable]):
|
| 3009 |
+
Arbitrary number of converters.
|
| 3010 |
+
|
| 3011 |
+
.. versionadded:: 20.1.0
|
| 3012 |
+
"""
|
| 3013 |
+
|
| 3014 |
+
return_instance = any(isinstance(c, Converter) for c in converters)
|
| 3015 |
+
|
| 3016 |
+
if return_instance:
|
| 3017 |
+
|
| 3018 |
+
def pipe_converter(val, inst, field):
|
| 3019 |
+
for c in converters:
|
| 3020 |
+
val = (
|
| 3021 |
+
c(val, inst, field) if isinstance(c, Converter) else c(val)
|
| 3022 |
+
)
|
| 3023 |
+
|
| 3024 |
+
return val
|
| 3025 |
+
|
| 3026 |
+
else:
|
| 3027 |
+
|
| 3028 |
+
def pipe_converter(val):
|
| 3029 |
+
for c in converters:
|
| 3030 |
+
val = c(val)
|
| 3031 |
+
|
| 3032 |
+
return val
|
| 3033 |
+
|
| 3034 |
+
if not converters:
|
| 3035 |
+
# If the converter list is empty, pipe_converter is the identity.
|
| 3036 |
+
A = typing.TypeVar("A")
|
| 3037 |
+
pipe_converter.__annotations__.update({"val": A, "return": A})
|
| 3038 |
+
else:
|
| 3039 |
+
# Get parameter type from first converter.
|
| 3040 |
+
t = _AnnotationExtractor(converters[0]).get_first_param_type()
|
| 3041 |
+
if t:
|
| 3042 |
+
pipe_converter.__annotations__["val"] = t
|
| 3043 |
+
|
| 3044 |
+
last = converters[-1]
|
| 3045 |
+
if not PY_3_11_PLUS and isinstance(last, Converter):
|
| 3046 |
+
last = last.__call__
|
| 3047 |
+
|
| 3048 |
+
# Get return type from last converter.
|
| 3049 |
+
rt = _AnnotationExtractor(last).get_return_type()
|
| 3050 |
+
if rt:
|
| 3051 |
+
pipe_converter.__annotations__["return"] = rt
|
| 3052 |
+
|
| 3053 |
+
if return_instance:
|
| 3054 |
+
return Converter(pipe_converter, takes_self=True, takes_field=True)
|
| 3055 |
+
return pipe_converter
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/_next_gen.py
ADDED
|
@@ -0,0 +1,623 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-License-Identifier: MIT
|
| 2 |
+
|
| 3 |
+
"""
|
| 4 |
+
These are keyword-only APIs that call `attr.s` and `attr.ib` with different
|
| 5 |
+
default values.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
from functools import partial
|
| 9 |
+
|
| 10 |
+
from . import setters
|
| 11 |
+
from ._funcs import asdict as _asdict
|
| 12 |
+
from ._funcs import astuple as _astuple
|
| 13 |
+
from ._make import (
|
| 14 |
+
_DEFAULT_ON_SETATTR,
|
| 15 |
+
NOTHING,
|
| 16 |
+
_frozen_setattrs,
|
| 17 |
+
attrib,
|
| 18 |
+
attrs,
|
| 19 |
+
)
|
| 20 |
+
from .exceptions import UnannotatedAttributeError
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def define(
|
| 24 |
+
maybe_cls=None,
|
| 25 |
+
*,
|
| 26 |
+
these=None,
|
| 27 |
+
repr=None,
|
| 28 |
+
unsafe_hash=None,
|
| 29 |
+
hash=None,
|
| 30 |
+
init=None,
|
| 31 |
+
slots=True,
|
| 32 |
+
frozen=False,
|
| 33 |
+
weakref_slot=True,
|
| 34 |
+
str=False,
|
| 35 |
+
auto_attribs=None,
|
| 36 |
+
kw_only=False,
|
| 37 |
+
cache_hash=False,
|
| 38 |
+
auto_exc=True,
|
| 39 |
+
eq=None,
|
| 40 |
+
order=False,
|
| 41 |
+
auto_detect=True,
|
| 42 |
+
getstate_setstate=None,
|
| 43 |
+
on_setattr=None,
|
| 44 |
+
field_transformer=None,
|
| 45 |
+
match_args=True,
|
| 46 |
+
):
|
| 47 |
+
r"""
|
| 48 |
+
A class decorator that adds :term:`dunder methods` according to
|
| 49 |
+
:term:`fields <field>` specified using :doc:`type annotations <types>`,
|
| 50 |
+
`field()` calls, or the *these* argument.
|
| 51 |
+
|
| 52 |
+
Since *attrs* patches or replaces an existing class, you cannot use
|
| 53 |
+
`object.__init_subclass__` with *attrs* classes, because it runs too early.
|
| 54 |
+
As a replacement, you can define ``__attrs_init_subclass__`` on your class.
|
| 55 |
+
It will be called by *attrs* classes that subclass it after they're
|
| 56 |
+
created. See also :ref:`init-subclass`.
|
| 57 |
+
|
| 58 |
+
Args:
|
| 59 |
+
slots (bool):
|
| 60 |
+
Create a :term:`slotted class <slotted classes>` that's more
|
| 61 |
+
memory-efficient. Slotted classes are generally superior to the
|
| 62 |
+
default dict classes, but have some gotchas you should know about,
|
| 63 |
+
so we encourage you to read the :term:`glossary entry <slotted
|
| 64 |
+
classes>`.
|
| 65 |
+
|
| 66 |
+
auto_detect (bool):
|
| 67 |
+
Instead of setting the *init*, *repr*, *eq*, and *hash* arguments
|
| 68 |
+
explicitly, assume they are set to True **unless any** of the
|
| 69 |
+
involved methods for one of the arguments is implemented in the
|
| 70 |
+
*current* class (meaning, it is *not* inherited from some base
|
| 71 |
+
class).
|
| 72 |
+
|
| 73 |
+
So, for example by implementing ``__eq__`` on a class yourself,
|
| 74 |
+
*attrs* will deduce ``eq=False`` and will create *neither*
|
| 75 |
+
``__eq__`` *nor* ``__ne__`` (but Python classes come with a
|
| 76 |
+
sensible ``__ne__`` by default, so it *should* be enough to only
|
| 77 |
+
implement ``__eq__`` in most cases).
|
| 78 |
+
|
| 79 |
+
Passing True or False` to *init*, *repr*, *eq*, or *hash*
|
| 80 |
+
overrides whatever *auto_detect* would determine.
|
| 81 |
+
|
| 82 |
+
auto_exc (bool):
|
| 83 |
+
If the class subclasses `BaseException` (which implicitly includes
|
| 84 |
+
any subclass of any exception), the following happens to behave
|
| 85 |
+
like a well-behaved Python exception class:
|
| 86 |
+
|
| 87 |
+
- the values for *eq*, *order*, and *hash* are ignored and the
|
| 88 |
+
instances compare and hash by the instance's ids [#]_ ,
|
| 89 |
+
- all attributes that are either passed into ``__init__`` or have a
|
| 90 |
+
default value are additionally available as a tuple in the
|
| 91 |
+
``args`` attribute,
|
| 92 |
+
- the value of *str* is ignored leaving ``__str__`` to base
|
| 93 |
+
classes.
|
| 94 |
+
|
| 95 |
+
.. [#]
|
| 96 |
+
Note that *attrs* will *not* remove existing implementations of
|
| 97 |
+
``__hash__`` or the equality methods. It just won't add own
|
| 98 |
+
ones.
|
| 99 |
+
|
| 100 |
+
on_setattr (~typing.Callable | list[~typing.Callable] | None | ~typing.Literal[attrs.setters.NO_OP]):
|
| 101 |
+
A callable that is run whenever the user attempts to set an
|
| 102 |
+
attribute (either by assignment like ``i.x = 42`` or by using
|
| 103 |
+
`setattr` like ``setattr(i, "x", 42)``). It receives the same
|
| 104 |
+
arguments as validators: the instance, the attribute that is being
|
| 105 |
+
modified, and the new value.
|
| 106 |
+
|
| 107 |
+
If no exception is raised, the attribute is set to the return value
|
| 108 |
+
of the callable.
|
| 109 |
+
|
| 110 |
+
If a list of callables is passed, they're automatically wrapped in
|
| 111 |
+
an `attrs.setters.pipe`.
|
| 112 |
+
|
| 113 |
+
If left None, the default behavior is to run converters and
|
| 114 |
+
validators whenever an attribute is set.
|
| 115 |
+
|
| 116 |
+
init (bool):
|
| 117 |
+
Create a ``__init__`` method that initializes the *attrs*
|
| 118 |
+
attributes. Leading underscores are stripped for the argument name,
|
| 119 |
+
unless an alias is set on the attribute.
|
| 120 |
+
|
| 121 |
+
.. seealso::
|
| 122 |
+
`init` shows advanced ways to customize the generated
|
| 123 |
+
``__init__`` method, including executing code before and after.
|
| 124 |
+
|
| 125 |
+
repr(bool):
|
| 126 |
+
Create a ``__repr__`` method with a human readable representation
|
| 127 |
+
of *attrs* attributes.
|
| 128 |
+
|
| 129 |
+
str (bool):
|
| 130 |
+
Create a ``__str__`` method that is identical to ``__repr__``. This
|
| 131 |
+
is usually not necessary except for `Exception`\ s.
|
| 132 |
+
|
| 133 |
+
eq (bool | None):
|
| 134 |
+
If True or None (default), add ``__eq__`` and ``__ne__`` methods
|
| 135 |
+
that check two instances for equality.
|
| 136 |
+
|
| 137 |
+
.. seealso::
|
| 138 |
+
`comparison` describes how to customize the comparison behavior
|
| 139 |
+
going as far comparing NumPy arrays.
|
| 140 |
+
|
| 141 |
+
order (bool | None):
|
| 142 |
+
If True, add ``__lt__``, ``__le__``, ``__gt__``, and ``__ge__``
|
| 143 |
+
methods that behave like *eq* above and allow instances to be
|
| 144 |
+
ordered.
|
| 145 |
+
|
| 146 |
+
They compare the instances as if they were tuples of their *attrs*
|
| 147 |
+
attributes if and only if the types of both classes are
|
| 148 |
+
*identical*.
|
| 149 |
+
|
| 150 |
+
If `None` mirror value of *eq*.
|
| 151 |
+
|
| 152 |
+
.. seealso:: `comparison`
|
| 153 |
+
|
| 154 |
+
unsafe_hash (bool | None):
|
| 155 |
+
If None (default), the ``__hash__`` method is generated according
|
| 156 |
+
how *eq* and *frozen* are set.
|
| 157 |
+
|
| 158 |
+
1. If *both* are True, *attrs* will generate a ``__hash__`` for
|
| 159 |
+
you.
|
| 160 |
+
2. If *eq* is True and *frozen* is False, ``__hash__`` will be set
|
| 161 |
+
to None, marking it unhashable (which it is).
|
| 162 |
+
3. If *eq* is False, ``__hash__`` will be left untouched meaning
|
| 163 |
+
the ``__hash__`` method of the base class will be used. If the
|
| 164 |
+
base class is `object`, this means it will fall back to id-based
|
| 165 |
+
hashing.
|
| 166 |
+
|
| 167 |
+
Although not recommended, you can decide for yourself and force
|
| 168 |
+
*attrs* to create one (for example, if the class is immutable even
|
| 169 |
+
though you didn't freeze it programmatically) by passing True or
|
| 170 |
+
not. Both of these cases are rather special and should be used
|
| 171 |
+
carefully.
|
| 172 |
+
|
| 173 |
+
.. seealso::
|
| 174 |
+
|
| 175 |
+
- Our documentation on `hashing`,
|
| 176 |
+
- Python's documentation on `object.__hash__`,
|
| 177 |
+
- and the `GitHub issue that led to the default \ behavior
|
| 178 |
+
<https://github.com/python-attrs/attrs/issues/136>`_ for more
|
| 179 |
+
details.
|
| 180 |
+
|
| 181 |
+
hash (bool | None):
|
| 182 |
+
Deprecated alias for *unsafe_hash*. *unsafe_hash* takes precedence.
|
| 183 |
+
|
| 184 |
+
cache_hash (bool):
|
| 185 |
+
Ensure that the object's hash code is computed only once and stored
|
| 186 |
+
on the object. If this is set to True, hashing must be either
|
| 187 |
+
explicitly or implicitly enabled for this class. If the hash code
|
| 188 |
+
is cached, avoid any reassignments of fields involved in hash code
|
| 189 |
+
computation or mutations of the objects those fields point to after
|
| 190 |
+
object creation. If such changes occur, the behavior of the
|
| 191 |
+
object's hash code is undefined.
|
| 192 |
+
|
| 193 |
+
frozen (bool):
|
| 194 |
+
Make instances immutable after initialization. If someone attempts
|
| 195 |
+
to modify a frozen instance, `attrs.exceptions.FrozenInstanceError`
|
| 196 |
+
is raised.
|
| 197 |
+
|
| 198 |
+
.. note::
|
| 199 |
+
|
| 200 |
+
1. This is achieved by installing a custom ``__setattr__``
|
| 201 |
+
method on your class, so you can't implement your own.
|
| 202 |
+
|
| 203 |
+
2. True immutability is impossible in Python.
|
| 204 |
+
|
| 205 |
+
3. This *does* have a minor a runtime performance `impact
|
| 206 |
+
<how-frozen>` when initializing new instances. In other
|
| 207 |
+
words: ``__init__`` is slightly slower with ``frozen=True``.
|
| 208 |
+
|
| 209 |
+
4. If a class is frozen, you cannot modify ``self`` in
|
| 210 |
+
``__attrs_post_init__`` or a self-written ``__init__``. You
|
| 211 |
+
can circumvent that limitation by using
|
| 212 |
+
``object.__setattr__(self, "attribute_name", value)``.
|
| 213 |
+
|
| 214 |
+
5. Subclasses of a frozen class are frozen too.
|
| 215 |
+
|
| 216 |
+
kw_only (bool):
|
| 217 |
+
Make all attributes keyword-only in the generated ``__init__`` (if
|
| 218 |
+
*init* is False, this parameter is ignored).
|
| 219 |
+
|
| 220 |
+
weakref_slot (bool):
|
| 221 |
+
Make instances weak-referenceable. This has no effect unless
|
| 222 |
+
*slots* is True.
|
| 223 |
+
|
| 224 |
+
field_transformer (~typing.Callable | None):
|
| 225 |
+
A function that is called with the original class object and all
|
| 226 |
+
fields right before *attrs* finalizes the class. You can use this,
|
| 227 |
+
for example, to automatically add converters or validators to
|
| 228 |
+
fields based on their types.
|
| 229 |
+
|
| 230 |
+
.. seealso:: `transform-fields`
|
| 231 |
+
|
| 232 |
+
match_args (bool):
|
| 233 |
+
If True (default), set ``__match_args__`` on the class to support
|
| 234 |
+
:pep:`634` (*Structural Pattern Matching*). It is a tuple of all
|
| 235 |
+
non-keyword-only ``__init__`` parameter names on Python 3.10 and
|
| 236 |
+
later. Ignored on older Python versions.
|
| 237 |
+
|
| 238 |
+
collect_by_mro (bool):
|
| 239 |
+
If True, *attrs* collects attributes from base classes correctly
|
| 240 |
+
according to the `method resolution order
|
| 241 |
+
<https://docs.python.org/3/howto/mro.html>`_. If False, *attrs*
|
| 242 |
+
will mimic the (wrong) behavior of `dataclasses` and :pep:`681`.
|
| 243 |
+
|
| 244 |
+
See also `issue #428
|
| 245 |
+
<https://github.com/python-attrs/attrs/issues/428>`_.
|
| 246 |
+
|
| 247 |
+
getstate_setstate (bool | None):
|
| 248 |
+
.. note::
|
| 249 |
+
|
| 250 |
+
This is usually only interesting for slotted classes and you
|
| 251 |
+
should probably just set *auto_detect* to True.
|
| 252 |
+
|
| 253 |
+
If True, ``__getstate__`` and ``__setstate__`` are generated and
|
| 254 |
+
attached to the class. This is necessary for slotted classes to be
|
| 255 |
+
pickleable. If left None, it's True by default for slotted classes
|
| 256 |
+
and False for dict classes.
|
| 257 |
+
|
| 258 |
+
If *auto_detect* is True, and *getstate_setstate* is left None, and
|
| 259 |
+
**either** ``__getstate__`` or ``__setstate__`` is detected
|
| 260 |
+
directly on the class (meaning: not inherited), it is set to False
|
| 261 |
+
(this is usually what you want).
|
| 262 |
+
|
| 263 |
+
auto_attribs (bool | None):
|
| 264 |
+
If True, look at type annotations to determine which attributes to
|
| 265 |
+
use, like `dataclasses`. If False, it will only look for explicit
|
| 266 |
+
:func:`field` class attributes, like classic *attrs*.
|
| 267 |
+
|
| 268 |
+
If left None, it will guess:
|
| 269 |
+
|
| 270 |
+
1. If any attributes are annotated and no unannotated
|
| 271 |
+
`attrs.field`\ s are found, it assumes *auto_attribs=True*.
|
| 272 |
+
2. Otherwise it assumes *auto_attribs=False* and tries to collect
|
| 273 |
+
`attrs.field`\ s.
|
| 274 |
+
|
| 275 |
+
If *attrs* decides to look at type annotations, **all** fields
|
| 276 |
+
**must** be annotated. If *attrs* encounters a field that is set to
|
| 277 |
+
a :func:`field` / `attr.ib` but lacks a type annotation, an
|
| 278 |
+
`attrs.exceptions.UnannotatedAttributeError` is raised. Use
|
| 279 |
+
``field_name: typing.Any = field(...)`` if you don't want to set a
|
| 280 |
+
type.
|
| 281 |
+
|
| 282 |
+
.. warning::
|
| 283 |
+
|
| 284 |
+
For features that use the attribute name to create decorators
|
| 285 |
+
(for example, :ref:`validators <validators>`), you still *must*
|
| 286 |
+
assign :func:`field` / `attr.ib` to them. Otherwise Python will
|
| 287 |
+
either not find the name or try to use the default value to
|
| 288 |
+
call, for example, ``validator`` on it.
|
| 289 |
+
|
| 290 |
+
Attributes annotated as `typing.ClassVar`, and attributes that are
|
| 291 |
+
neither annotated nor set to an `field()` are **ignored**.
|
| 292 |
+
|
| 293 |
+
these (dict[str, object]):
|
| 294 |
+
A dictionary of name to the (private) return value of `field()`
|
| 295 |
+
mappings. This is useful to avoid the definition of your attributes
|
| 296 |
+
within the class body because you can't (for example, if you want
|
| 297 |
+
to add ``__repr__`` methods to Django models) or don't want to.
|
| 298 |
+
|
| 299 |
+
If *these* is not `None`, *attrs* will *not* search the class body
|
| 300 |
+
for attributes and will *not* remove any attributes from it.
|
| 301 |
+
|
| 302 |
+
The order is deduced from the order of the attributes inside
|
| 303 |
+
*these*.
|
| 304 |
+
|
| 305 |
+
Arguably, this is a rather obscure feature.
|
| 306 |
+
|
| 307 |
+
.. versionadded:: 20.1.0
|
| 308 |
+
.. versionchanged:: 21.3.0 Converters are also run ``on_setattr``.
|
| 309 |
+
.. versionadded:: 22.2.0
|
| 310 |
+
*unsafe_hash* as an alias for *hash* (for :pep:`681` compliance).
|
| 311 |
+
.. versionchanged:: 24.1.0
|
| 312 |
+
Instances are not compared as tuples of attributes anymore, but using a
|
| 313 |
+
big ``and`` condition. This is faster and has more correct behavior for
|
| 314 |
+
uncomparable values like `math.nan`.
|
| 315 |
+
.. versionadded:: 24.1.0
|
| 316 |
+
If a class has an *inherited* classmethod called
|
| 317 |
+
``__attrs_init_subclass__``, it is executed after the class is created.
|
| 318 |
+
.. deprecated:: 24.1.0 *hash* is deprecated in favor of *unsafe_hash*.
|
| 319 |
+
.. versionadded:: 24.3.0
|
| 320 |
+
Unless already present, a ``__replace__`` method is automatically
|
| 321 |
+
created for `copy.replace` (Python 3.13+ only).
|
| 322 |
+
|
| 323 |
+
.. note::
|
| 324 |
+
|
| 325 |
+
The main differences to the classic `attr.s` are:
|
| 326 |
+
|
| 327 |
+
- Automatically detect whether or not *auto_attribs* should be `True`
|
| 328 |
+
(c.f. *auto_attribs* parameter).
|
| 329 |
+
- Converters and validators run when attributes are set by default --
|
| 330 |
+
if *frozen* is `False`.
|
| 331 |
+
- *slots=True*
|
| 332 |
+
|
| 333 |
+
Usually, this has only upsides and few visible effects in everyday
|
| 334 |
+
programming. But it *can* lead to some surprising behaviors, so
|
| 335 |
+
please make sure to read :term:`slotted classes`.
|
| 336 |
+
|
| 337 |
+
- *auto_exc=True*
|
| 338 |
+
- *auto_detect=True*
|
| 339 |
+
- *order=False*
|
| 340 |
+
- Some options that were only relevant on Python 2 or were kept around
|
| 341 |
+
for backwards-compatibility have been removed.
|
| 342 |
+
|
| 343 |
+
"""
|
| 344 |
+
|
| 345 |
+
def do_it(cls, auto_attribs):
|
| 346 |
+
return attrs(
|
| 347 |
+
maybe_cls=cls,
|
| 348 |
+
these=these,
|
| 349 |
+
repr=repr,
|
| 350 |
+
hash=hash,
|
| 351 |
+
unsafe_hash=unsafe_hash,
|
| 352 |
+
init=init,
|
| 353 |
+
slots=slots,
|
| 354 |
+
frozen=frozen,
|
| 355 |
+
weakref_slot=weakref_slot,
|
| 356 |
+
str=str,
|
| 357 |
+
auto_attribs=auto_attribs,
|
| 358 |
+
kw_only=kw_only,
|
| 359 |
+
cache_hash=cache_hash,
|
| 360 |
+
auto_exc=auto_exc,
|
| 361 |
+
eq=eq,
|
| 362 |
+
order=order,
|
| 363 |
+
auto_detect=auto_detect,
|
| 364 |
+
collect_by_mro=True,
|
| 365 |
+
getstate_setstate=getstate_setstate,
|
| 366 |
+
on_setattr=on_setattr,
|
| 367 |
+
field_transformer=field_transformer,
|
| 368 |
+
match_args=match_args,
|
| 369 |
+
)
|
| 370 |
+
|
| 371 |
+
def wrap(cls):
|
| 372 |
+
"""
|
| 373 |
+
Making this a wrapper ensures this code runs during class creation.
|
| 374 |
+
|
| 375 |
+
We also ensure that frozen-ness of classes is inherited.
|
| 376 |
+
"""
|
| 377 |
+
nonlocal frozen, on_setattr
|
| 378 |
+
|
| 379 |
+
had_on_setattr = on_setattr not in (None, setters.NO_OP)
|
| 380 |
+
|
| 381 |
+
# By default, mutable classes convert & validate on setattr.
|
| 382 |
+
if frozen is False and on_setattr is None:
|
| 383 |
+
on_setattr = _DEFAULT_ON_SETATTR
|
| 384 |
+
|
| 385 |
+
# However, if we subclass a frozen class, we inherit the immutability
|
| 386 |
+
# and disable on_setattr.
|
| 387 |
+
for base_cls in cls.__bases__:
|
| 388 |
+
if base_cls.__setattr__ is _frozen_setattrs:
|
| 389 |
+
if had_on_setattr:
|
| 390 |
+
msg = "Frozen classes can't use on_setattr (frozen-ness was inherited)."
|
| 391 |
+
raise ValueError(msg)
|
| 392 |
+
|
| 393 |
+
on_setattr = setters.NO_OP
|
| 394 |
+
break
|
| 395 |
+
|
| 396 |
+
if auto_attribs is not None:
|
| 397 |
+
return do_it(cls, auto_attribs)
|
| 398 |
+
|
| 399 |
+
try:
|
| 400 |
+
return do_it(cls, True)
|
| 401 |
+
except UnannotatedAttributeError:
|
| 402 |
+
return do_it(cls, False)
|
| 403 |
+
|
| 404 |
+
# maybe_cls's type depends on the usage of the decorator. It's a class
|
| 405 |
+
# if it's used as `@attrs` but `None` if used as `@attrs()`.
|
| 406 |
+
if maybe_cls is None:
|
| 407 |
+
return wrap
|
| 408 |
+
|
| 409 |
+
return wrap(maybe_cls)
|
| 410 |
+
|
| 411 |
+
|
| 412 |
+
mutable = define
|
| 413 |
+
frozen = partial(define, frozen=True, on_setattr=None)
|
| 414 |
+
|
| 415 |
+
|
| 416 |
+
def field(
|
| 417 |
+
*,
|
| 418 |
+
default=NOTHING,
|
| 419 |
+
validator=None,
|
| 420 |
+
repr=True,
|
| 421 |
+
hash=None,
|
| 422 |
+
init=True,
|
| 423 |
+
metadata=None,
|
| 424 |
+
type=None,
|
| 425 |
+
converter=None,
|
| 426 |
+
factory=None,
|
| 427 |
+
kw_only=False,
|
| 428 |
+
eq=None,
|
| 429 |
+
order=None,
|
| 430 |
+
on_setattr=None,
|
| 431 |
+
alias=None,
|
| 432 |
+
):
|
| 433 |
+
"""
|
| 434 |
+
Create a new :term:`field` / :term:`attribute` on a class.
|
| 435 |
+
|
| 436 |
+
.. warning::
|
| 437 |
+
|
| 438 |
+
Does **nothing** unless the class is also decorated with
|
| 439 |
+
`attrs.define` (or similar)!
|
| 440 |
+
|
| 441 |
+
Args:
|
| 442 |
+
default:
|
| 443 |
+
A value that is used if an *attrs*-generated ``__init__`` is used
|
| 444 |
+
and no value is passed while instantiating or the attribute is
|
| 445 |
+
excluded using ``init=False``.
|
| 446 |
+
|
| 447 |
+
If the value is an instance of `attrs.Factory`, its callable will
|
| 448 |
+
be used to construct a new value (useful for mutable data types
|
| 449 |
+
like lists or dicts).
|
| 450 |
+
|
| 451 |
+
If a default is not set (or set manually to `attrs.NOTHING`), a
|
| 452 |
+
value *must* be supplied when instantiating; otherwise a
|
| 453 |
+
`TypeError` will be raised.
|
| 454 |
+
|
| 455 |
+
.. seealso:: `defaults`
|
| 456 |
+
|
| 457 |
+
factory (~typing.Callable):
|
| 458 |
+
Syntactic sugar for ``default=attr.Factory(factory)``.
|
| 459 |
+
|
| 460 |
+
validator (~typing.Callable | list[~typing.Callable]):
|
| 461 |
+
Callable that is called by *attrs*-generated ``__init__`` methods
|
| 462 |
+
after the instance has been initialized. They receive the
|
| 463 |
+
initialized instance, the :func:`~attrs.Attribute`, and the passed
|
| 464 |
+
value.
|
| 465 |
+
|
| 466 |
+
The return value is *not* inspected so the validator has to throw
|
| 467 |
+
an exception itself.
|
| 468 |
+
|
| 469 |
+
If a `list` is passed, its items are treated as validators and must
|
| 470 |
+
all pass.
|
| 471 |
+
|
| 472 |
+
Validators can be globally disabled and re-enabled using
|
| 473 |
+
`attrs.validators.get_disabled` / `attrs.validators.set_disabled`.
|
| 474 |
+
|
| 475 |
+
The validator can also be set using decorator notation as shown
|
| 476 |
+
below.
|
| 477 |
+
|
| 478 |
+
.. seealso:: :ref:`validators`
|
| 479 |
+
|
| 480 |
+
repr (bool | ~typing.Callable):
|
| 481 |
+
Include this attribute in the generated ``__repr__`` method. If
|
| 482 |
+
True, include the attribute; if False, omit it. By default, the
|
| 483 |
+
built-in ``repr()`` function is used. To override how the attribute
|
| 484 |
+
value is formatted, pass a ``callable`` that takes a single value
|
| 485 |
+
and returns a string. Note that the resulting string is used as-is,
|
| 486 |
+
which means it will be used directly *instead* of calling
|
| 487 |
+
``repr()`` (the default).
|
| 488 |
+
|
| 489 |
+
eq (bool | ~typing.Callable):
|
| 490 |
+
If True (default), include this attribute in the generated
|
| 491 |
+
``__eq__`` and ``__ne__`` methods that check two instances for
|
| 492 |
+
equality. To override how the attribute value is compared, pass a
|
| 493 |
+
callable that takes a single value and returns the value to be
|
| 494 |
+
compared.
|
| 495 |
+
|
| 496 |
+
.. seealso:: `comparison`
|
| 497 |
+
|
| 498 |
+
order (bool | ~typing.Callable):
|
| 499 |
+
If True (default), include this attributes in the generated
|
| 500 |
+
``__lt__``, ``__le__``, ``__gt__`` and ``__ge__`` methods. To
|
| 501 |
+
override how the attribute value is ordered, pass a callable that
|
| 502 |
+
takes a single value and returns the value to be ordered.
|
| 503 |
+
|
| 504 |
+
.. seealso:: `comparison`
|
| 505 |
+
|
| 506 |
+
hash (bool | None):
|
| 507 |
+
Include this attribute in the generated ``__hash__`` method. If
|
| 508 |
+
None (default), mirror *eq*'s value. This is the correct behavior
|
| 509 |
+
according the Python spec. Setting this value to anything else
|
| 510 |
+
than None is *discouraged*.
|
| 511 |
+
|
| 512 |
+
.. seealso:: `hashing`
|
| 513 |
+
|
| 514 |
+
init (bool):
|
| 515 |
+
Include this attribute in the generated ``__init__`` method.
|
| 516 |
+
|
| 517 |
+
It is possible to set this to False and set a default value. In
|
| 518 |
+
that case this attributed is unconditionally initialized with the
|
| 519 |
+
specified default value or factory.
|
| 520 |
+
|
| 521 |
+
.. seealso:: `init`
|
| 522 |
+
|
| 523 |
+
converter (typing.Callable | Converter):
|
| 524 |
+
A callable that is called by *attrs*-generated ``__init__`` methods
|
| 525 |
+
to convert attribute's value to the desired format.
|
| 526 |
+
|
| 527 |
+
If a vanilla callable is passed, it is given the passed-in value as
|
| 528 |
+
the only positional argument. It is possible to receive additional
|
| 529 |
+
arguments by wrapping the callable in a `Converter`.
|
| 530 |
+
|
| 531 |
+
Either way, the returned value will be used as the new value of the
|
| 532 |
+
attribute. The value is converted before being passed to the
|
| 533 |
+
validator, if any.
|
| 534 |
+
|
| 535 |
+
.. seealso:: :ref:`converters`
|
| 536 |
+
|
| 537 |
+
metadata (dict | None):
|
| 538 |
+
An arbitrary mapping, to be used by third-party code.
|
| 539 |
+
|
| 540 |
+
.. seealso:: `extending-metadata`.
|
| 541 |
+
|
| 542 |
+
type (type):
|
| 543 |
+
The type of the attribute. Nowadays, the preferred method to
|
| 544 |
+
specify the type is using a variable annotation (see :pep:`526`).
|
| 545 |
+
This argument is provided for backwards-compatibility and for usage
|
| 546 |
+
with `make_class`. Regardless of the approach used, the type will
|
| 547 |
+
be stored on ``Attribute.type``.
|
| 548 |
+
|
| 549 |
+
Please note that *attrs* doesn't do anything with this metadata by
|
| 550 |
+
itself. You can use it as part of your own code or for `static type
|
| 551 |
+
checking <types>`.
|
| 552 |
+
|
| 553 |
+
kw_only (bool):
|
| 554 |
+
Make this attribute keyword-only in the generated ``__init__`` (if
|
| 555 |
+
``init`` is False, this parameter is ignored).
|
| 556 |
+
|
| 557 |
+
on_setattr (~typing.Callable | list[~typing.Callable] | None | ~typing.Literal[attrs.setters.NO_OP]):
|
| 558 |
+
Allows to overwrite the *on_setattr* setting from `attr.s`. If left
|
| 559 |
+
None, the *on_setattr* value from `attr.s` is used. Set to
|
| 560 |
+
`attrs.setters.NO_OP` to run **no** `setattr` hooks for this
|
| 561 |
+
attribute -- regardless of the setting in `define()`.
|
| 562 |
+
|
| 563 |
+
alias (str | None):
|
| 564 |
+
Override this attribute's parameter name in the generated
|
| 565 |
+
``__init__`` method. If left None, default to ``name`` stripped
|
| 566 |
+
of leading underscores. See `private-attributes`.
|
| 567 |
+
|
| 568 |
+
.. versionadded:: 20.1.0
|
| 569 |
+
.. versionchanged:: 21.1.0
|
| 570 |
+
*eq*, *order*, and *cmp* also accept a custom callable
|
| 571 |
+
.. versionadded:: 22.2.0 *alias*
|
| 572 |
+
.. versionadded:: 23.1.0
|
| 573 |
+
The *type* parameter has been re-added; mostly for `attrs.make_class`.
|
| 574 |
+
Please note that type checkers ignore this metadata.
|
| 575 |
+
|
| 576 |
+
.. seealso::
|
| 577 |
+
|
| 578 |
+
`attr.ib`
|
| 579 |
+
"""
|
| 580 |
+
return attrib(
|
| 581 |
+
default=default,
|
| 582 |
+
validator=validator,
|
| 583 |
+
repr=repr,
|
| 584 |
+
hash=hash,
|
| 585 |
+
init=init,
|
| 586 |
+
metadata=metadata,
|
| 587 |
+
type=type,
|
| 588 |
+
converter=converter,
|
| 589 |
+
factory=factory,
|
| 590 |
+
kw_only=kw_only,
|
| 591 |
+
eq=eq,
|
| 592 |
+
order=order,
|
| 593 |
+
on_setattr=on_setattr,
|
| 594 |
+
alias=alias,
|
| 595 |
+
)
|
| 596 |
+
|
| 597 |
+
|
| 598 |
+
def asdict(inst, *, recurse=True, filter=None, value_serializer=None):
|
| 599 |
+
"""
|
| 600 |
+
Same as `attr.asdict`, except that collections types are always retained
|
| 601 |
+
and dict is always used as *dict_factory*.
|
| 602 |
+
|
| 603 |
+
.. versionadded:: 21.3.0
|
| 604 |
+
"""
|
| 605 |
+
return _asdict(
|
| 606 |
+
inst=inst,
|
| 607 |
+
recurse=recurse,
|
| 608 |
+
filter=filter,
|
| 609 |
+
value_serializer=value_serializer,
|
| 610 |
+
retain_collection_types=True,
|
| 611 |
+
)
|
| 612 |
+
|
| 613 |
+
|
| 614 |
+
def astuple(inst, *, recurse=True, filter=None):
|
| 615 |
+
"""
|
| 616 |
+
Same as `attr.astuple`, except that collections types are always retained
|
| 617 |
+
and `tuple` is always used as the *tuple_factory*.
|
| 618 |
+
|
| 619 |
+
.. versionadded:: 21.3.0
|
| 620 |
+
"""
|
| 621 |
+
return _astuple(
|
| 622 |
+
inst=inst, recurse=recurse, filter=filter, retain_collection_types=True
|
| 623 |
+
)
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/_typing_compat.pyi
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any, ClassVar, Protocol
|
| 2 |
+
|
| 3 |
+
# MYPY is a special constant in mypy which works the same way as `TYPE_CHECKING`.
|
| 4 |
+
MYPY = False
|
| 5 |
+
|
| 6 |
+
if MYPY:
|
| 7 |
+
# A protocol to be able to statically accept an attrs class.
|
| 8 |
+
class AttrsInstance_(Protocol):
|
| 9 |
+
__attrs_attrs__: ClassVar[Any]
|
| 10 |
+
|
| 11 |
+
else:
|
| 12 |
+
# For type checkers without plug-in support use an empty protocol that
|
| 13 |
+
# will (hopefully) be combined into a union.
|
| 14 |
+
class AttrsInstance_(Protocol):
|
| 15 |
+
pass
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/_version_info.py
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-License-Identifier: MIT
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
from functools import total_ordering
|
| 5 |
+
|
| 6 |
+
from ._funcs import astuple
|
| 7 |
+
from ._make import attrib, attrs
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
@total_ordering
|
| 11 |
+
@attrs(eq=False, order=False, slots=True, frozen=True)
|
| 12 |
+
class VersionInfo:
|
| 13 |
+
"""
|
| 14 |
+
A version object that can be compared to tuple of length 1--4:
|
| 15 |
+
|
| 16 |
+
>>> attr.VersionInfo(19, 1, 0, "final") <= (19, 2)
|
| 17 |
+
True
|
| 18 |
+
>>> attr.VersionInfo(19, 1, 0, "final") < (19, 1, 1)
|
| 19 |
+
True
|
| 20 |
+
>>> vi = attr.VersionInfo(19, 2, 0, "final")
|
| 21 |
+
>>> vi < (19, 1, 1)
|
| 22 |
+
False
|
| 23 |
+
>>> vi < (19,)
|
| 24 |
+
False
|
| 25 |
+
>>> vi == (19, 2,)
|
| 26 |
+
True
|
| 27 |
+
>>> vi == (19, 2, 1)
|
| 28 |
+
False
|
| 29 |
+
|
| 30 |
+
.. versionadded:: 19.2
|
| 31 |
+
"""
|
| 32 |
+
|
| 33 |
+
year = attrib(type=int)
|
| 34 |
+
minor = attrib(type=int)
|
| 35 |
+
micro = attrib(type=int)
|
| 36 |
+
releaselevel = attrib(type=str)
|
| 37 |
+
|
| 38 |
+
@classmethod
|
| 39 |
+
def _from_version_string(cls, s):
|
| 40 |
+
"""
|
| 41 |
+
Parse *s* and return a _VersionInfo.
|
| 42 |
+
"""
|
| 43 |
+
v = s.split(".")
|
| 44 |
+
if len(v) == 3:
|
| 45 |
+
v.append("final")
|
| 46 |
+
|
| 47 |
+
return cls(
|
| 48 |
+
year=int(v[0]), minor=int(v[1]), micro=int(v[2]), releaselevel=v[3]
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
def _ensure_tuple(self, other):
|
| 52 |
+
"""
|
| 53 |
+
Ensure *other* is a tuple of a valid length.
|
| 54 |
+
|
| 55 |
+
Returns a possibly transformed *other* and ourselves as a tuple of
|
| 56 |
+
the same length as *other*.
|
| 57 |
+
"""
|
| 58 |
+
|
| 59 |
+
if self.__class__ is other.__class__:
|
| 60 |
+
other = astuple(other)
|
| 61 |
+
|
| 62 |
+
if not isinstance(other, tuple):
|
| 63 |
+
raise NotImplementedError
|
| 64 |
+
|
| 65 |
+
if not (1 <= len(other) <= 4):
|
| 66 |
+
raise NotImplementedError
|
| 67 |
+
|
| 68 |
+
return astuple(self)[: len(other)], other
|
| 69 |
+
|
| 70 |
+
def __eq__(self, other):
|
| 71 |
+
try:
|
| 72 |
+
us, them = self._ensure_tuple(other)
|
| 73 |
+
except NotImplementedError:
|
| 74 |
+
return NotImplemented
|
| 75 |
+
|
| 76 |
+
return us == them
|
| 77 |
+
|
| 78 |
+
def __lt__(self, other):
|
| 79 |
+
try:
|
| 80 |
+
us, them = self._ensure_tuple(other)
|
| 81 |
+
except NotImplementedError:
|
| 82 |
+
return NotImplemented
|
| 83 |
+
|
| 84 |
+
# Since alphabetically "dev0" < "final" < "post1" < "post2", we don't
|
| 85 |
+
# have to do anything special with releaselevel for now.
|
| 86 |
+
return us < them
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/_version_info.pyi
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class VersionInfo:
|
| 2 |
+
@property
|
| 3 |
+
def year(self) -> int: ...
|
| 4 |
+
@property
|
| 5 |
+
def minor(self) -> int: ...
|
| 6 |
+
@property
|
| 7 |
+
def micro(self) -> int: ...
|
| 8 |
+
@property
|
| 9 |
+
def releaselevel(self) -> str: ...
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/converters.py
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-License-Identifier: MIT
|
| 2 |
+
|
| 3 |
+
"""
|
| 4 |
+
Commonly useful converters.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import typing
|
| 8 |
+
|
| 9 |
+
from ._compat import _AnnotationExtractor
|
| 10 |
+
from ._make import NOTHING, Converter, Factory, pipe
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
__all__ = [
|
| 14 |
+
"default_if_none",
|
| 15 |
+
"optional",
|
| 16 |
+
"pipe",
|
| 17 |
+
"to_bool",
|
| 18 |
+
]
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def optional(converter):
|
| 22 |
+
"""
|
| 23 |
+
A converter that allows an attribute to be optional. An optional attribute
|
| 24 |
+
is one which can be set to `None`.
|
| 25 |
+
|
| 26 |
+
Type annotations will be inferred from the wrapped converter's, if it has
|
| 27 |
+
any.
|
| 28 |
+
|
| 29 |
+
Args:
|
| 30 |
+
converter (typing.Callable):
|
| 31 |
+
the converter that is used for non-`None` values.
|
| 32 |
+
|
| 33 |
+
.. versionadded:: 17.1.0
|
| 34 |
+
"""
|
| 35 |
+
|
| 36 |
+
if isinstance(converter, Converter):
|
| 37 |
+
|
| 38 |
+
def optional_converter(val, inst, field):
|
| 39 |
+
if val is None:
|
| 40 |
+
return None
|
| 41 |
+
return converter(val, inst, field)
|
| 42 |
+
|
| 43 |
+
else:
|
| 44 |
+
|
| 45 |
+
def optional_converter(val):
|
| 46 |
+
if val is None:
|
| 47 |
+
return None
|
| 48 |
+
return converter(val)
|
| 49 |
+
|
| 50 |
+
xtr = _AnnotationExtractor(converter)
|
| 51 |
+
|
| 52 |
+
t = xtr.get_first_param_type()
|
| 53 |
+
if t:
|
| 54 |
+
optional_converter.__annotations__["val"] = typing.Optional[t]
|
| 55 |
+
|
| 56 |
+
rt = xtr.get_return_type()
|
| 57 |
+
if rt:
|
| 58 |
+
optional_converter.__annotations__["return"] = typing.Optional[rt]
|
| 59 |
+
|
| 60 |
+
if isinstance(converter, Converter):
|
| 61 |
+
return Converter(optional_converter, takes_self=True, takes_field=True)
|
| 62 |
+
|
| 63 |
+
return optional_converter
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def default_if_none(default=NOTHING, factory=None):
|
| 67 |
+
"""
|
| 68 |
+
A converter that allows to replace `None` values by *default* or the result
|
| 69 |
+
of *factory*.
|
| 70 |
+
|
| 71 |
+
Args:
|
| 72 |
+
default:
|
| 73 |
+
Value to be used if `None` is passed. Passing an instance of
|
| 74 |
+
`attrs.Factory` is supported, however the ``takes_self`` option is
|
| 75 |
+
*not*.
|
| 76 |
+
|
| 77 |
+
factory (typing.Callable):
|
| 78 |
+
A callable that takes no parameters whose result is used if `None`
|
| 79 |
+
is passed.
|
| 80 |
+
|
| 81 |
+
Raises:
|
| 82 |
+
TypeError: If **neither** *default* or *factory* is passed.
|
| 83 |
+
|
| 84 |
+
TypeError: If **both** *default* and *factory* are passed.
|
| 85 |
+
|
| 86 |
+
ValueError:
|
| 87 |
+
If an instance of `attrs.Factory` is passed with
|
| 88 |
+
``takes_self=True``.
|
| 89 |
+
|
| 90 |
+
.. versionadded:: 18.2.0
|
| 91 |
+
"""
|
| 92 |
+
if default is NOTHING and factory is None:
|
| 93 |
+
msg = "Must pass either `default` or `factory`."
|
| 94 |
+
raise TypeError(msg)
|
| 95 |
+
|
| 96 |
+
if default is not NOTHING and factory is not None:
|
| 97 |
+
msg = "Must pass either `default` or `factory` but not both."
|
| 98 |
+
raise TypeError(msg)
|
| 99 |
+
|
| 100 |
+
if factory is not None:
|
| 101 |
+
default = Factory(factory)
|
| 102 |
+
|
| 103 |
+
if isinstance(default, Factory):
|
| 104 |
+
if default.takes_self:
|
| 105 |
+
msg = "`takes_self` is not supported by default_if_none."
|
| 106 |
+
raise ValueError(msg)
|
| 107 |
+
|
| 108 |
+
def default_if_none_converter(val):
|
| 109 |
+
if val is not None:
|
| 110 |
+
return val
|
| 111 |
+
|
| 112 |
+
return default.factory()
|
| 113 |
+
|
| 114 |
+
else:
|
| 115 |
+
|
| 116 |
+
def default_if_none_converter(val):
|
| 117 |
+
if val is not None:
|
| 118 |
+
return val
|
| 119 |
+
|
| 120 |
+
return default
|
| 121 |
+
|
| 122 |
+
return default_if_none_converter
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
def to_bool(val):
|
| 126 |
+
"""
|
| 127 |
+
Convert "boolean" strings (for example, from environment variables) to real
|
| 128 |
+
booleans.
|
| 129 |
+
|
| 130 |
+
Values mapping to `True`:
|
| 131 |
+
|
| 132 |
+
- ``True``
|
| 133 |
+
- ``"true"`` / ``"t"``
|
| 134 |
+
- ``"yes"`` / ``"y"``
|
| 135 |
+
- ``"on"``
|
| 136 |
+
- ``"1"``
|
| 137 |
+
- ``1``
|
| 138 |
+
|
| 139 |
+
Values mapping to `False`:
|
| 140 |
+
|
| 141 |
+
- ``False``
|
| 142 |
+
- ``"false"`` / ``"f"``
|
| 143 |
+
- ``"no"`` / ``"n"``
|
| 144 |
+
- ``"off"``
|
| 145 |
+
- ``"0"``
|
| 146 |
+
- ``0``
|
| 147 |
+
|
| 148 |
+
Raises:
|
| 149 |
+
ValueError: For any other value.
|
| 150 |
+
|
| 151 |
+
.. versionadded:: 21.3.0
|
| 152 |
+
"""
|
| 153 |
+
if isinstance(val, str):
|
| 154 |
+
val = val.lower()
|
| 155 |
+
|
| 156 |
+
if val in (True, "true", "t", "yes", "y", "on", "1", 1):
|
| 157 |
+
return True
|
| 158 |
+
if val in (False, "false", "f", "no", "n", "off", "0", 0):
|
| 159 |
+
return False
|
| 160 |
+
|
| 161 |
+
msg = f"Cannot convert value to bool: {val!r}"
|
| 162 |
+
raise ValueError(msg)
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/converters.pyi
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Callable, Any, overload
|
| 2 |
+
|
| 3 |
+
from attrs import _ConverterType, _CallableConverterType
|
| 4 |
+
|
| 5 |
+
@overload
|
| 6 |
+
def pipe(*validators: _CallableConverterType) -> _CallableConverterType: ...
|
| 7 |
+
@overload
|
| 8 |
+
def pipe(*validators: _ConverterType) -> _ConverterType: ...
|
| 9 |
+
@overload
|
| 10 |
+
def optional(converter: _CallableConverterType) -> _CallableConverterType: ...
|
| 11 |
+
@overload
|
| 12 |
+
def optional(converter: _ConverterType) -> _ConverterType: ...
|
| 13 |
+
@overload
|
| 14 |
+
def default_if_none(default: Any) -> _CallableConverterType: ...
|
| 15 |
+
@overload
|
| 16 |
+
def default_if_none(
|
| 17 |
+
*, factory: Callable[[], Any]
|
| 18 |
+
) -> _CallableConverterType: ...
|
| 19 |
+
def to_bool(val: str | int | bool) -> bool: ...
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/exceptions.py
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-License-Identifier: MIT
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from typing import ClassVar
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class FrozenError(AttributeError):
|
| 9 |
+
"""
|
| 10 |
+
A frozen/immutable instance or attribute have been attempted to be
|
| 11 |
+
modified.
|
| 12 |
+
|
| 13 |
+
It mirrors the behavior of ``namedtuples`` by using the same error message
|
| 14 |
+
and subclassing `AttributeError`.
|
| 15 |
+
|
| 16 |
+
.. versionadded:: 20.1.0
|
| 17 |
+
"""
|
| 18 |
+
|
| 19 |
+
msg = "can't set attribute"
|
| 20 |
+
args: ClassVar[tuple[str]] = [msg]
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
class FrozenInstanceError(FrozenError):
|
| 24 |
+
"""
|
| 25 |
+
A frozen instance has been attempted to be modified.
|
| 26 |
+
|
| 27 |
+
.. versionadded:: 16.1.0
|
| 28 |
+
"""
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class FrozenAttributeError(FrozenError):
|
| 32 |
+
"""
|
| 33 |
+
A frozen attribute has been attempted to be modified.
|
| 34 |
+
|
| 35 |
+
.. versionadded:: 20.1.0
|
| 36 |
+
"""
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
class AttrsAttributeNotFoundError(ValueError):
|
| 40 |
+
"""
|
| 41 |
+
An *attrs* function couldn't find an attribute that the user asked for.
|
| 42 |
+
|
| 43 |
+
.. versionadded:: 16.2.0
|
| 44 |
+
"""
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
class NotAnAttrsClassError(ValueError):
|
| 48 |
+
"""
|
| 49 |
+
A non-*attrs* class has been passed into an *attrs* function.
|
| 50 |
+
|
| 51 |
+
.. versionadded:: 16.2.0
|
| 52 |
+
"""
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
class DefaultAlreadySetError(RuntimeError):
|
| 56 |
+
"""
|
| 57 |
+
A default has been set when defining the field and is attempted to be reset
|
| 58 |
+
using the decorator.
|
| 59 |
+
|
| 60 |
+
.. versionadded:: 17.1.0
|
| 61 |
+
"""
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
class UnannotatedAttributeError(RuntimeError):
|
| 65 |
+
"""
|
| 66 |
+
A class with ``auto_attribs=True`` has a field without a type annotation.
|
| 67 |
+
|
| 68 |
+
.. versionadded:: 17.3.0
|
| 69 |
+
"""
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
class PythonTooOldError(RuntimeError):
|
| 73 |
+
"""
|
| 74 |
+
It was attempted to use an *attrs* feature that requires a newer Python
|
| 75 |
+
version.
|
| 76 |
+
|
| 77 |
+
.. versionadded:: 18.2.0
|
| 78 |
+
"""
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
class NotCallableError(TypeError):
|
| 82 |
+
"""
|
| 83 |
+
A field requiring a callable has been set with a value that is not
|
| 84 |
+
callable.
|
| 85 |
+
|
| 86 |
+
.. versionadded:: 19.2.0
|
| 87 |
+
"""
|
| 88 |
+
|
| 89 |
+
def __init__(self, msg, value):
|
| 90 |
+
super(TypeError, self).__init__(msg, value)
|
| 91 |
+
self.msg = msg
|
| 92 |
+
self.value = value
|
| 93 |
+
|
| 94 |
+
def __str__(self):
|
| 95 |
+
return str(self.msg)
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/exceptions.pyi
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any
|
| 2 |
+
|
| 3 |
+
class FrozenError(AttributeError):
|
| 4 |
+
msg: str = ...
|
| 5 |
+
|
| 6 |
+
class FrozenInstanceError(FrozenError): ...
|
| 7 |
+
class FrozenAttributeError(FrozenError): ...
|
| 8 |
+
class AttrsAttributeNotFoundError(ValueError): ...
|
| 9 |
+
class NotAnAttrsClassError(ValueError): ...
|
| 10 |
+
class DefaultAlreadySetError(RuntimeError): ...
|
| 11 |
+
class UnannotatedAttributeError(RuntimeError): ...
|
| 12 |
+
class PythonTooOldError(RuntimeError): ...
|
| 13 |
+
|
| 14 |
+
class NotCallableError(TypeError):
|
| 15 |
+
msg: str = ...
|
| 16 |
+
value: Any = ...
|
| 17 |
+
def __init__(self, msg: str, value: Any) -> None: ...
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/filters.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-License-Identifier: MIT
|
| 2 |
+
|
| 3 |
+
"""
|
| 4 |
+
Commonly useful filters for `attrs.asdict` and `attrs.astuple`.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
from ._make import Attribute
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def _split_what(what):
|
| 11 |
+
"""
|
| 12 |
+
Returns a tuple of `frozenset`s of classes and attributes.
|
| 13 |
+
"""
|
| 14 |
+
return (
|
| 15 |
+
frozenset(cls for cls in what if isinstance(cls, type)),
|
| 16 |
+
frozenset(cls for cls in what if isinstance(cls, str)),
|
| 17 |
+
frozenset(cls for cls in what if isinstance(cls, Attribute)),
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def include(*what):
|
| 22 |
+
"""
|
| 23 |
+
Create a filter that only allows *what*.
|
| 24 |
+
|
| 25 |
+
Args:
|
| 26 |
+
what (list[type, str, attrs.Attribute]):
|
| 27 |
+
What to include. Can be a type, a name, or an attribute.
|
| 28 |
+
|
| 29 |
+
Returns:
|
| 30 |
+
Callable:
|
| 31 |
+
A callable that can be passed to `attrs.asdict`'s and
|
| 32 |
+
`attrs.astuple`'s *filter* argument.
|
| 33 |
+
|
| 34 |
+
.. versionchanged:: 23.1.0 Accept strings with field names.
|
| 35 |
+
"""
|
| 36 |
+
cls, names, attrs = _split_what(what)
|
| 37 |
+
|
| 38 |
+
def include_(attribute, value):
|
| 39 |
+
return (
|
| 40 |
+
value.__class__ in cls
|
| 41 |
+
or attribute.name in names
|
| 42 |
+
or attribute in attrs
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
return include_
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def exclude(*what):
|
| 49 |
+
"""
|
| 50 |
+
Create a filter that does **not** allow *what*.
|
| 51 |
+
|
| 52 |
+
Args:
|
| 53 |
+
what (list[type, str, attrs.Attribute]):
|
| 54 |
+
What to exclude. Can be a type, a name, or an attribute.
|
| 55 |
+
|
| 56 |
+
Returns:
|
| 57 |
+
Callable:
|
| 58 |
+
A callable that can be passed to `attrs.asdict`'s and
|
| 59 |
+
`attrs.astuple`'s *filter* argument.
|
| 60 |
+
|
| 61 |
+
.. versionchanged:: 23.3.0 Accept field name string as input argument
|
| 62 |
+
"""
|
| 63 |
+
cls, names, attrs = _split_what(what)
|
| 64 |
+
|
| 65 |
+
def exclude_(attribute, value):
|
| 66 |
+
return not (
|
| 67 |
+
value.__class__ in cls
|
| 68 |
+
or attribute.name in names
|
| 69 |
+
or attribute in attrs
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
+
return exclude_
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/filters.pyi
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any
|
| 2 |
+
|
| 3 |
+
from . import Attribute, _FilterType
|
| 4 |
+
|
| 5 |
+
def include(*what: type | str | Attribute[Any]) -> _FilterType[Any]: ...
|
| 6 |
+
def exclude(*what: type | str | Attribute[Any]) -> _FilterType[Any]: ...
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/py.typed
ADDED
|
File without changes
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/setters.py
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-License-Identifier: MIT
|
| 2 |
+
|
| 3 |
+
"""
|
| 4 |
+
Commonly used hooks for on_setattr.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
from . import _config
|
| 8 |
+
from .exceptions import FrozenAttributeError
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def pipe(*setters):
|
| 12 |
+
"""
|
| 13 |
+
Run all *setters* and return the return value of the last one.
|
| 14 |
+
|
| 15 |
+
.. versionadded:: 20.1.0
|
| 16 |
+
"""
|
| 17 |
+
|
| 18 |
+
def wrapped_pipe(instance, attrib, new_value):
|
| 19 |
+
rv = new_value
|
| 20 |
+
|
| 21 |
+
for setter in setters:
|
| 22 |
+
rv = setter(instance, attrib, rv)
|
| 23 |
+
|
| 24 |
+
return rv
|
| 25 |
+
|
| 26 |
+
return wrapped_pipe
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def frozen(_, __, ___):
|
| 30 |
+
"""
|
| 31 |
+
Prevent an attribute to be modified.
|
| 32 |
+
|
| 33 |
+
.. versionadded:: 20.1.0
|
| 34 |
+
"""
|
| 35 |
+
raise FrozenAttributeError
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def validate(instance, attrib, new_value):
|
| 39 |
+
"""
|
| 40 |
+
Run *attrib*'s validator on *new_value* if it has one.
|
| 41 |
+
|
| 42 |
+
.. versionadded:: 20.1.0
|
| 43 |
+
"""
|
| 44 |
+
if _config._run_validators is False:
|
| 45 |
+
return new_value
|
| 46 |
+
|
| 47 |
+
v = attrib.validator
|
| 48 |
+
if not v:
|
| 49 |
+
return new_value
|
| 50 |
+
|
| 51 |
+
v(instance, attrib, new_value)
|
| 52 |
+
|
| 53 |
+
return new_value
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def convert(instance, attrib, new_value):
|
| 57 |
+
"""
|
| 58 |
+
Run *attrib*'s converter -- if it has one -- on *new_value* and return the
|
| 59 |
+
result.
|
| 60 |
+
|
| 61 |
+
.. versionadded:: 20.1.0
|
| 62 |
+
"""
|
| 63 |
+
c = attrib.converter
|
| 64 |
+
if c:
|
| 65 |
+
# This can be removed once we drop 3.8 and use attrs.Converter instead.
|
| 66 |
+
from ._make import Converter
|
| 67 |
+
|
| 68 |
+
if not isinstance(c, Converter):
|
| 69 |
+
return c(new_value)
|
| 70 |
+
|
| 71 |
+
return c(new_value, instance, attrib)
|
| 72 |
+
|
| 73 |
+
return new_value
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
# Sentinel for disabling class-wide *on_setattr* hooks for certain attributes.
|
| 77 |
+
# Sphinx's autodata stopped working, so the docstring is inlined in the API
|
| 78 |
+
# docs.
|
| 79 |
+
NO_OP = object()
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/setters.pyi
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any, NewType, NoReturn, TypeVar
|
| 2 |
+
|
| 3 |
+
from . import Attribute
|
| 4 |
+
from attrs import _OnSetAttrType
|
| 5 |
+
|
| 6 |
+
_T = TypeVar("_T")
|
| 7 |
+
|
| 8 |
+
def frozen(
|
| 9 |
+
instance: Any, attribute: Attribute[Any], new_value: Any
|
| 10 |
+
) -> NoReturn: ...
|
| 11 |
+
def pipe(*setters: _OnSetAttrType) -> _OnSetAttrType: ...
|
| 12 |
+
def validate(instance: Any, attribute: Attribute[_T], new_value: _T) -> _T: ...
|
| 13 |
+
|
| 14 |
+
# convert is allowed to return Any, because they can be chained using pipe.
|
| 15 |
+
def convert(
|
| 16 |
+
instance: Any, attribute: Attribute[Any], new_value: Any
|
| 17 |
+
) -> Any: ...
|
| 18 |
+
|
| 19 |
+
_NoOpType = NewType("_NoOpType", object)
|
| 20 |
+
NO_OP: _NoOpType
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/validators.py
ADDED
|
@@ -0,0 +1,710 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-License-Identifier: MIT
|
| 2 |
+
|
| 3 |
+
"""
|
| 4 |
+
Commonly useful validators.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import operator
|
| 8 |
+
import re
|
| 9 |
+
|
| 10 |
+
from contextlib import contextmanager
|
| 11 |
+
from re import Pattern
|
| 12 |
+
|
| 13 |
+
from ._config import get_run_validators, set_run_validators
|
| 14 |
+
from ._make import _AndValidator, and_, attrib, attrs
|
| 15 |
+
from .converters import default_if_none
|
| 16 |
+
from .exceptions import NotCallableError
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
__all__ = [
|
| 20 |
+
"and_",
|
| 21 |
+
"deep_iterable",
|
| 22 |
+
"deep_mapping",
|
| 23 |
+
"disabled",
|
| 24 |
+
"ge",
|
| 25 |
+
"get_disabled",
|
| 26 |
+
"gt",
|
| 27 |
+
"in_",
|
| 28 |
+
"instance_of",
|
| 29 |
+
"is_callable",
|
| 30 |
+
"le",
|
| 31 |
+
"lt",
|
| 32 |
+
"matches_re",
|
| 33 |
+
"max_len",
|
| 34 |
+
"min_len",
|
| 35 |
+
"not_",
|
| 36 |
+
"optional",
|
| 37 |
+
"or_",
|
| 38 |
+
"set_disabled",
|
| 39 |
+
]
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def set_disabled(disabled):
|
| 43 |
+
"""
|
| 44 |
+
Globally disable or enable running validators.
|
| 45 |
+
|
| 46 |
+
By default, they are run.
|
| 47 |
+
|
| 48 |
+
Args:
|
| 49 |
+
disabled (bool): If `True`, disable running all validators.
|
| 50 |
+
|
| 51 |
+
.. warning::
|
| 52 |
+
|
| 53 |
+
This function is not thread-safe!
|
| 54 |
+
|
| 55 |
+
.. versionadded:: 21.3.0
|
| 56 |
+
"""
|
| 57 |
+
set_run_validators(not disabled)
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def get_disabled():
|
| 61 |
+
"""
|
| 62 |
+
Return a bool indicating whether validators are currently disabled or not.
|
| 63 |
+
|
| 64 |
+
Returns:
|
| 65 |
+
bool:`True` if validators are currently disabled.
|
| 66 |
+
|
| 67 |
+
.. versionadded:: 21.3.0
|
| 68 |
+
"""
|
| 69 |
+
return not get_run_validators()
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
@contextmanager
|
| 73 |
+
def disabled():
|
| 74 |
+
"""
|
| 75 |
+
Context manager that disables running validators within its context.
|
| 76 |
+
|
| 77 |
+
.. warning::
|
| 78 |
+
|
| 79 |
+
This context manager is not thread-safe!
|
| 80 |
+
|
| 81 |
+
.. versionadded:: 21.3.0
|
| 82 |
+
"""
|
| 83 |
+
set_run_validators(False)
|
| 84 |
+
try:
|
| 85 |
+
yield
|
| 86 |
+
finally:
|
| 87 |
+
set_run_validators(True)
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
@attrs(repr=False, slots=True, unsafe_hash=True)
|
| 91 |
+
class _InstanceOfValidator:
|
| 92 |
+
type = attrib()
|
| 93 |
+
|
| 94 |
+
def __call__(self, inst, attr, value):
|
| 95 |
+
"""
|
| 96 |
+
We use a callable class to be able to change the ``__repr__``.
|
| 97 |
+
"""
|
| 98 |
+
if not isinstance(value, self.type):
|
| 99 |
+
msg = f"'{attr.name}' must be {self.type!r} (got {value!r} that is a {value.__class__!r})."
|
| 100 |
+
raise TypeError(
|
| 101 |
+
msg,
|
| 102 |
+
attr,
|
| 103 |
+
self.type,
|
| 104 |
+
value,
|
| 105 |
+
)
|
| 106 |
+
|
| 107 |
+
def __repr__(self):
|
| 108 |
+
return f"<instance_of validator for type {self.type!r}>"
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
def instance_of(type):
|
| 112 |
+
"""
|
| 113 |
+
A validator that raises a `TypeError` if the initializer is called with a
|
| 114 |
+
wrong type for this particular attribute (checks are performed using
|
| 115 |
+
`isinstance` therefore it's also valid to pass a tuple of types).
|
| 116 |
+
|
| 117 |
+
Args:
|
| 118 |
+
type (type | tuple[type]): The type to check for.
|
| 119 |
+
|
| 120 |
+
Raises:
|
| 121 |
+
TypeError:
|
| 122 |
+
With a human readable error message, the attribute (of type
|
| 123 |
+
`attrs.Attribute`), the expected type, and the value it got.
|
| 124 |
+
"""
|
| 125 |
+
return _InstanceOfValidator(type)
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
@attrs(repr=False, frozen=True, slots=True)
|
| 129 |
+
class _MatchesReValidator:
|
| 130 |
+
pattern = attrib()
|
| 131 |
+
match_func = attrib()
|
| 132 |
+
|
| 133 |
+
def __call__(self, inst, attr, value):
|
| 134 |
+
"""
|
| 135 |
+
We use a callable class to be able to change the ``__repr__``.
|
| 136 |
+
"""
|
| 137 |
+
if not self.match_func(value):
|
| 138 |
+
msg = f"'{attr.name}' must match regex {self.pattern.pattern!r} ({value!r} doesn't)"
|
| 139 |
+
raise ValueError(
|
| 140 |
+
msg,
|
| 141 |
+
attr,
|
| 142 |
+
self.pattern,
|
| 143 |
+
value,
|
| 144 |
+
)
|
| 145 |
+
|
| 146 |
+
def __repr__(self):
|
| 147 |
+
return f"<matches_re validator for pattern {self.pattern!r}>"
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
def matches_re(regex, flags=0, func=None):
|
| 151 |
+
r"""
|
| 152 |
+
A validator that raises `ValueError` if the initializer is called with a
|
| 153 |
+
string that doesn't match *regex*.
|
| 154 |
+
|
| 155 |
+
Args:
|
| 156 |
+
regex (str, re.Pattern):
|
| 157 |
+
A regex string or precompiled pattern to match against
|
| 158 |
+
|
| 159 |
+
flags (int):
|
| 160 |
+
Flags that will be passed to the underlying re function (default 0)
|
| 161 |
+
|
| 162 |
+
func (typing.Callable):
|
| 163 |
+
Which underlying `re` function to call. Valid options are
|
| 164 |
+
`re.fullmatch`, `re.search`, and `re.match`; the default `None`
|
| 165 |
+
means `re.fullmatch`. For performance reasons, the pattern is
|
| 166 |
+
always precompiled using `re.compile`.
|
| 167 |
+
|
| 168 |
+
.. versionadded:: 19.2.0
|
| 169 |
+
.. versionchanged:: 21.3.0 *regex* can be a pre-compiled pattern.
|
| 170 |
+
"""
|
| 171 |
+
valid_funcs = (re.fullmatch, None, re.search, re.match)
|
| 172 |
+
if func not in valid_funcs:
|
| 173 |
+
msg = "'func' must be one of {}.".format(
|
| 174 |
+
", ".join(
|
| 175 |
+
sorted((e and e.__name__) or "None" for e in set(valid_funcs))
|
| 176 |
+
)
|
| 177 |
+
)
|
| 178 |
+
raise ValueError(msg)
|
| 179 |
+
|
| 180 |
+
if isinstance(regex, Pattern):
|
| 181 |
+
if flags:
|
| 182 |
+
msg = "'flags' can only be used with a string pattern; pass flags to re.compile() instead"
|
| 183 |
+
raise TypeError(msg)
|
| 184 |
+
pattern = regex
|
| 185 |
+
else:
|
| 186 |
+
pattern = re.compile(regex, flags)
|
| 187 |
+
|
| 188 |
+
if func is re.match:
|
| 189 |
+
match_func = pattern.match
|
| 190 |
+
elif func is re.search:
|
| 191 |
+
match_func = pattern.search
|
| 192 |
+
else:
|
| 193 |
+
match_func = pattern.fullmatch
|
| 194 |
+
|
| 195 |
+
return _MatchesReValidator(pattern, match_func)
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
@attrs(repr=False, slots=True, unsafe_hash=True)
|
| 199 |
+
class _OptionalValidator:
|
| 200 |
+
validator = attrib()
|
| 201 |
+
|
| 202 |
+
def __call__(self, inst, attr, value):
|
| 203 |
+
if value is None:
|
| 204 |
+
return
|
| 205 |
+
|
| 206 |
+
self.validator(inst, attr, value)
|
| 207 |
+
|
| 208 |
+
def __repr__(self):
|
| 209 |
+
return f"<optional validator for {self.validator!r} or None>"
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
def optional(validator):
|
| 213 |
+
"""
|
| 214 |
+
A validator that makes an attribute optional. An optional attribute is one
|
| 215 |
+
which can be set to `None` in addition to satisfying the requirements of
|
| 216 |
+
the sub-validator.
|
| 217 |
+
|
| 218 |
+
Args:
|
| 219 |
+
validator
|
| 220 |
+
(typing.Callable | tuple[typing.Callable] | list[typing.Callable]):
|
| 221 |
+
A validator (or validators) that is used for non-`None` values.
|
| 222 |
+
|
| 223 |
+
.. versionadded:: 15.1.0
|
| 224 |
+
.. versionchanged:: 17.1.0 *validator* can be a list of validators.
|
| 225 |
+
.. versionchanged:: 23.1.0 *validator* can also be a tuple of validators.
|
| 226 |
+
"""
|
| 227 |
+
if isinstance(validator, (list, tuple)):
|
| 228 |
+
return _OptionalValidator(_AndValidator(validator))
|
| 229 |
+
|
| 230 |
+
return _OptionalValidator(validator)
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
@attrs(repr=False, slots=True, unsafe_hash=True)
|
| 234 |
+
class _InValidator:
|
| 235 |
+
options = attrib()
|
| 236 |
+
_original_options = attrib(hash=False)
|
| 237 |
+
|
| 238 |
+
def __call__(self, inst, attr, value):
|
| 239 |
+
try:
|
| 240 |
+
in_options = value in self.options
|
| 241 |
+
except TypeError: # e.g. `1 in "abc"`
|
| 242 |
+
in_options = False
|
| 243 |
+
|
| 244 |
+
if not in_options:
|
| 245 |
+
msg = f"'{attr.name}' must be in {self._original_options!r} (got {value!r})"
|
| 246 |
+
raise ValueError(
|
| 247 |
+
msg,
|
| 248 |
+
attr,
|
| 249 |
+
self._original_options,
|
| 250 |
+
value,
|
| 251 |
+
)
|
| 252 |
+
|
| 253 |
+
def __repr__(self):
|
| 254 |
+
return f"<in_ validator with options {self._original_options!r}>"
|
| 255 |
+
|
| 256 |
+
|
| 257 |
+
def in_(options):
|
| 258 |
+
"""
|
| 259 |
+
A validator that raises a `ValueError` if the initializer is called with a
|
| 260 |
+
value that does not belong in the *options* provided.
|
| 261 |
+
|
| 262 |
+
The check is performed using ``value in options``, so *options* has to
|
| 263 |
+
support that operation.
|
| 264 |
+
|
| 265 |
+
To keep the validator hashable, dicts, lists, and sets are transparently
|
| 266 |
+
transformed into a `tuple`.
|
| 267 |
+
|
| 268 |
+
Args:
|
| 269 |
+
options: Allowed options.
|
| 270 |
+
|
| 271 |
+
Raises:
|
| 272 |
+
ValueError:
|
| 273 |
+
With a human readable error message, the attribute (of type
|
| 274 |
+
`attrs.Attribute`), the expected options, and the value it got.
|
| 275 |
+
|
| 276 |
+
.. versionadded:: 17.1.0
|
| 277 |
+
.. versionchanged:: 22.1.0
|
| 278 |
+
The ValueError was incomplete until now and only contained the human
|
| 279 |
+
readable error message. Now it contains all the information that has
|
| 280 |
+
been promised since 17.1.0.
|
| 281 |
+
.. versionchanged:: 24.1.0
|
| 282 |
+
*options* that are a list, dict, or a set are now transformed into a
|
| 283 |
+
tuple to keep the validator hashable.
|
| 284 |
+
"""
|
| 285 |
+
repr_options = options
|
| 286 |
+
if isinstance(options, (list, dict, set)):
|
| 287 |
+
options = tuple(options)
|
| 288 |
+
|
| 289 |
+
return _InValidator(options, repr_options)
|
| 290 |
+
|
| 291 |
+
|
| 292 |
+
@attrs(repr=False, slots=False, unsafe_hash=True)
|
| 293 |
+
class _IsCallableValidator:
|
| 294 |
+
def __call__(self, inst, attr, value):
|
| 295 |
+
"""
|
| 296 |
+
We use a callable class to be able to change the ``__repr__``.
|
| 297 |
+
"""
|
| 298 |
+
if not callable(value):
|
| 299 |
+
message = (
|
| 300 |
+
"'{name}' must be callable "
|
| 301 |
+
"(got {value!r} that is a {actual!r})."
|
| 302 |
+
)
|
| 303 |
+
raise NotCallableError(
|
| 304 |
+
msg=message.format(
|
| 305 |
+
name=attr.name, value=value, actual=value.__class__
|
| 306 |
+
),
|
| 307 |
+
value=value,
|
| 308 |
+
)
|
| 309 |
+
|
| 310 |
+
def __repr__(self):
|
| 311 |
+
return "<is_callable validator>"
|
| 312 |
+
|
| 313 |
+
|
| 314 |
+
def is_callable():
|
| 315 |
+
"""
|
| 316 |
+
A validator that raises a `attrs.exceptions.NotCallableError` if the
|
| 317 |
+
initializer is called with a value for this particular attribute that is
|
| 318 |
+
not callable.
|
| 319 |
+
|
| 320 |
+
.. versionadded:: 19.1.0
|
| 321 |
+
|
| 322 |
+
Raises:
|
| 323 |
+
attrs.exceptions.NotCallableError:
|
| 324 |
+
With a human readable error message containing the attribute
|
| 325 |
+
(`attrs.Attribute`) name, and the value it got.
|
| 326 |
+
"""
|
| 327 |
+
return _IsCallableValidator()
|
| 328 |
+
|
| 329 |
+
|
| 330 |
+
@attrs(repr=False, slots=True, unsafe_hash=True)
|
| 331 |
+
class _DeepIterable:
|
| 332 |
+
member_validator = attrib(validator=is_callable())
|
| 333 |
+
iterable_validator = attrib(
|
| 334 |
+
default=None, validator=optional(is_callable())
|
| 335 |
+
)
|
| 336 |
+
|
| 337 |
+
def __call__(self, inst, attr, value):
|
| 338 |
+
"""
|
| 339 |
+
We use a callable class to be able to change the ``__repr__``.
|
| 340 |
+
"""
|
| 341 |
+
if self.iterable_validator is not None:
|
| 342 |
+
self.iterable_validator(inst, attr, value)
|
| 343 |
+
|
| 344 |
+
for member in value:
|
| 345 |
+
self.member_validator(inst, attr, member)
|
| 346 |
+
|
| 347 |
+
def __repr__(self):
|
| 348 |
+
iterable_identifier = (
|
| 349 |
+
""
|
| 350 |
+
if self.iterable_validator is None
|
| 351 |
+
else f" {self.iterable_validator!r}"
|
| 352 |
+
)
|
| 353 |
+
return (
|
| 354 |
+
f"<deep_iterable validator for{iterable_identifier}"
|
| 355 |
+
f" iterables of {self.member_validator!r}>"
|
| 356 |
+
)
|
| 357 |
+
|
| 358 |
+
|
| 359 |
+
def deep_iterable(member_validator, iterable_validator=None):
|
| 360 |
+
"""
|
| 361 |
+
A validator that performs deep validation of an iterable.
|
| 362 |
+
|
| 363 |
+
Args:
|
| 364 |
+
member_validator: Validator to apply to iterable members.
|
| 365 |
+
|
| 366 |
+
iterable_validator:
|
| 367 |
+
Validator to apply to iterable itself (optional).
|
| 368 |
+
|
| 369 |
+
Raises
|
| 370 |
+
TypeError: if any sub-validators fail
|
| 371 |
+
|
| 372 |
+
.. versionadded:: 19.1.0
|
| 373 |
+
"""
|
| 374 |
+
if isinstance(member_validator, (list, tuple)):
|
| 375 |
+
member_validator = and_(*member_validator)
|
| 376 |
+
return _DeepIterable(member_validator, iterable_validator)
|
| 377 |
+
|
| 378 |
+
|
| 379 |
+
@attrs(repr=False, slots=True, unsafe_hash=True)
|
| 380 |
+
class _DeepMapping:
|
| 381 |
+
key_validator = attrib(validator=is_callable())
|
| 382 |
+
value_validator = attrib(validator=is_callable())
|
| 383 |
+
mapping_validator = attrib(default=None, validator=optional(is_callable()))
|
| 384 |
+
|
| 385 |
+
def __call__(self, inst, attr, value):
|
| 386 |
+
"""
|
| 387 |
+
We use a callable class to be able to change the ``__repr__``.
|
| 388 |
+
"""
|
| 389 |
+
if self.mapping_validator is not None:
|
| 390 |
+
self.mapping_validator(inst, attr, value)
|
| 391 |
+
|
| 392 |
+
for key in value:
|
| 393 |
+
self.key_validator(inst, attr, key)
|
| 394 |
+
self.value_validator(inst, attr, value[key])
|
| 395 |
+
|
| 396 |
+
def __repr__(self):
|
| 397 |
+
return f"<deep_mapping validator for objects mapping {self.key_validator!r} to {self.value_validator!r}>"
|
| 398 |
+
|
| 399 |
+
|
| 400 |
+
def deep_mapping(key_validator, value_validator, mapping_validator=None):
|
| 401 |
+
"""
|
| 402 |
+
A validator that performs deep validation of a dictionary.
|
| 403 |
+
|
| 404 |
+
Args:
|
| 405 |
+
key_validator: Validator to apply to dictionary keys.
|
| 406 |
+
|
| 407 |
+
value_validator: Validator to apply to dictionary values.
|
| 408 |
+
|
| 409 |
+
mapping_validator:
|
| 410 |
+
Validator to apply to top-level mapping attribute (optional).
|
| 411 |
+
|
| 412 |
+
.. versionadded:: 19.1.0
|
| 413 |
+
|
| 414 |
+
Raises:
|
| 415 |
+
TypeError: if any sub-validators fail
|
| 416 |
+
"""
|
| 417 |
+
return _DeepMapping(key_validator, value_validator, mapping_validator)
|
| 418 |
+
|
| 419 |
+
|
| 420 |
+
@attrs(repr=False, frozen=True, slots=True)
|
| 421 |
+
class _NumberValidator:
|
| 422 |
+
bound = attrib()
|
| 423 |
+
compare_op = attrib()
|
| 424 |
+
compare_func = attrib()
|
| 425 |
+
|
| 426 |
+
def __call__(self, inst, attr, value):
|
| 427 |
+
"""
|
| 428 |
+
We use a callable class to be able to change the ``__repr__``.
|
| 429 |
+
"""
|
| 430 |
+
if not self.compare_func(value, self.bound):
|
| 431 |
+
msg = f"'{attr.name}' must be {self.compare_op} {self.bound}: {value}"
|
| 432 |
+
raise ValueError(msg)
|
| 433 |
+
|
| 434 |
+
def __repr__(self):
|
| 435 |
+
return f"<Validator for x {self.compare_op} {self.bound}>"
|
| 436 |
+
|
| 437 |
+
|
| 438 |
+
def lt(val):
|
| 439 |
+
"""
|
| 440 |
+
A validator that raises `ValueError` if the initializer is called with a
|
| 441 |
+
number larger or equal to *val*.
|
| 442 |
+
|
| 443 |
+
The validator uses `operator.lt` to compare the values.
|
| 444 |
+
|
| 445 |
+
Args:
|
| 446 |
+
val: Exclusive upper bound for values.
|
| 447 |
+
|
| 448 |
+
.. versionadded:: 21.3.0
|
| 449 |
+
"""
|
| 450 |
+
return _NumberValidator(val, "<", operator.lt)
|
| 451 |
+
|
| 452 |
+
|
| 453 |
+
def le(val):
|
| 454 |
+
"""
|
| 455 |
+
A validator that raises `ValueError` if the initializer is called with a
|
| 456 |
+
number greater than *val*.
|
| 457 |
+
|
| 458 |
+
The validator uses `operator.le` to compare the values.
|
| 459 |
+
|
| 460 |
+
Args:
|
| 461 |
+
val: Inclusive upper bound for values.
|
| 462 |
+
|
| 463 |
+
.. versionadded:: 21.3.0
|
| 464 |
+
"""
|
| 465 |
+
return _NumberValidator(val, "<=", operator.le)
|
| 466 |
+
|
| 467 |
+
|
| 468 |
+
def ge(val):
|
| 469 |
+
"""
|
| 470 |
+
A validator that raises `ValueError` if the initializer is called with a
|
| 471 |
+
number smaller than *val*.
|
| 472 |
+
|
| 473 |
+
The validator uses `operator.ge` to compare the values.
|
| 474 |
+
|
| 475 |
+
Args:
|
| 476 |
+
val: Inclusive lower bound for values
|
| 477 |
+
|
| 478 |
+
.. versionadded:: 21.3.0
|
| 479 |
+
"""
|
| 480 |
+
return _NumberValidator(val, ">=", operator.ge)
|
| 481 |
+
|
| 482 |
+
|
| 483 |
+
def gt(val):
|
| 484 |
+
"""
|
| 485 |
+
A validator that raises `ValueError` if the initializer is called with a
|
| 486 |
+
number smaller or equal to *val*.
|
| 487 |
+
|
| 488 |
+
The validator uses `operator.ge` to compare the values.
|
| 489 |
+
|
| 490 |
+
Args:
|
| 491 |
+
val: Exclusive lower bound for values
|
| 492 |
+
|
| 493 |
+
.. versionadded:: 21.3.0
|
| 494 |
+
"""
|
| 495 |
+
return _NumberValidator(val, ">", operator.gt)
|
| 496 |
+
|
| 497 |
+
|
| 498 |
+
@attrs(repr=False, frozen=True, slots=True)
|
| 499 |
+
class _MaxLengthValidator:
|
| 500 |
+
max_length = attrib()
|
| 501 |
+
|
| 502 |
+
def __call__(self, inst, attr, value):
|
| 503 |
+
"""
|
| 504 |
+
We use a callable class to be able to change the ``__repr__``.
|
| 505 |
+
"""
|
| 506 |
+
if len(value) > self.max_length:
|
| 507 |
+
msg = f"Length of '{attr.name}' must be <= {self.max_length}: {len(value)}"
|
| 508 |
+
raise ValueError(msg)
|
| 509 |
+
|
| 510 |
+
def __repr__(self):
|
| 511 |
+
return f"<max_len validator for {self.max_length}>"
|
| 512 |
+
|
| 513 |
+
|
| 514 |
+
def max_len(length):
|
| 515 |
+
"""
|
| 516 |
+
A validator that raises `ValueError` if the initializer is called
|
| 517 |
+
with a string or iterable that is longer than *length*.
|
| 518 |
+
|
| 519 |
+
Args:
|
| 520 |
+
length (int): Maximum length of the string or iterable
|
| 521 |
+
|
| 522 |
+
.. versionadded:: 21.3.0
|
| 523 |
+
"""
|
| 524 |
+
return _MaxLengthValidator(length)
|
| 525 |
+
|
| 526 |
+
|
| 527 |
+
@attrs(repr=False, frozen=True, slots=True)
|
| 528 |
+
class _MinLengthValidator:
|
| 529 |
+
min_length = attrib()
|
| 530 |
+
|
| 531 |
+
def __call__(self, inst, attr, value):
|
| 532 |
+
"""
|
| 533 |
+
We use a callable class to be able to change the ``__repr__``.
|
| 534 |
+
"""
|
| 535 |
+
if len(value) < self.min_length:
|
| 536 |
+
msg = f"Length of '{attr.name}' must be >= {self.min_length}: {len(value)}"
|
| 537 |
+
raise ValueError(msg)
|
| 538 |
+
|
| 539 |
+
def __repr__(self):
|
| 540 |
+
return f"<min_len validator for {self.min_length}>"
|
| 541 |
+
|
| 542 |
+
|
| 543 |
+
def min_len(length):
|
| 544 |
+
"""
|
| 545 |
+
A validator that raises `ValueError` if the initializer is called
|
| 546 |
+
with a string or iterable that is shorter than *length*.
|
| 547 |
+
|
| 548 |
+
Args:
|
| 549 |
+
length (int): Minimum length of the string or iterable
|
| 550 |
+
|
| 551 |
+
.. versionadded:: 22.1.0
|
| 552 |
+
"""
|
| 553 |
+
return _MinLengthValidator(length)
|
| 554 |
+
|
| 555 |
+
|
| 556 |
+
@attrs(repr=False, slots=True, unsafe_hash=True)
|
| 557 |
+
class _SubclassOfValidator:
|
| 558 |
+
type = attrib()
|
| 559 |
+
|
| 560 |
+
def __call__(self, inst, attr, value):
|
| 561 |
+
"""
|
| 562 |
+
We use a callable class to be able to change the ``__repr__``.
|
| 563 |
+
"""
|
| 564 |
+
if not issubclass(value, self.type):
|
| 565 |
+
msg = f"'{attr.name}' must be a subclass of {self.type!r} (got {value!r})."
|
| 566 |
+
raise TypeError(
|
| 567 |
+
msg,
|
| 568 |
+
attr,
|
| 569 |
+
self.type,
|
| 570 |
+
value,
|
| 571 |
+
)
|
| 572 |
+
|
| 573 |
+
def __repr__(self):
|
| 574 |
+
return f"<subclass_of validator for type {self.type!r}>"
|
| 575 |
+
|
| 576 |
+
|
| 577 |
+
def _subclass_of(type):
|
| 578 |
+
"""
|
| 579 |
+
A validator that raises a `TypeError` if the initializer is called with a
|
| 580 |
+
wrong type for this particular attribute (checks are performed using
|
| 581 |
+
`issubclass` therefore it's also valid to pass a tuple of types).
|
| 582 |
+
|
| 583 |
+
Args:
|
| 584 |
+
type (type | tuple[type, ...]): The type(s) to check for.
|
| 585 |
+
|
| 586 |
+
Raises:
|
| 587 |
+
TypeError:
|
| 588 |
+
With a human readable error message, the attribute (of type
|
| 589 |
+
`attrs.Attribute`), the expected type, and the value it got.
|
| 590 |
+
"""
|
| 591 |
+
return _SubclassOfValidator(type)
|
| 592 |
+
|
| 593 |
+
|
| 594 |
+
@attrs(repr=False, slots=True, unsafe_hash=True)
|
| 595 |
+
class _NotValidator:
|
| 596 |
+
validator = attrib()
|
| 597 |
+
msg = attrib(
|
| 598 |
+
converter=default_if_none(
|
| 599 |
+
"not_ validator child '{validator!r}' "
|
| 600 |
+
"did not raise a captured error"
|
| 601 |
+
)
|
| 602 |
+
)
|
| 603 |
+
exc_types = attrib(
|
| 604 |
+
validator=deep_iterable(
|
| 605 |
+
member_validator=_subclass_of(Exception),
|
| 606 |
+
iterable_validator=instance_of(tuple),
|
| 607 |
+
),
|
| 608 |
+
)
|
| 609 |
+
|
| 610 |
+
def __call__(self, inst, attr, value):
|
| 611 |
+
try:
|
| 612 |
+
self.validator(inst, attr, value)
|
| 613 |
+
except self.exc_types:
|
| 614 |
+
pass # suppress error to invert validity
|
| 615 |
+
else:
|
| 616 |
+
raise ValueError(
|
| 617 |
+
self.msg.format(
|
| 618 |
+
validator=self.validator,
|
| 619 |
+
exc_types=self.exc_types,
|
| 620 |
+
),
|
| 621 |
+
attr,
|
| 622 |
+
self.validator,
|
| 623 |
+
value,
|
| 624 |
+
self.exc_types,
|
| 625 |
+
)
|
| 626 |
+
|
| 627 |
+
def __repr__(self):
|
| 628 |
+
return f"<not_ validator wrapping {self.validator!r}, capturing {self.exc_types!r}>"
|
| 629 |
+
|
| 630 |
+
|
| 631 |
+
def not_(validator, *, msg=None, exc_types=(ValueError, TypeError)):
|
| 632 |
+
"""
|
| 633 |
+
A validator that wraps and logically 'inverts' the validator passed to it.
|
| 634 |
+
It will raise a `ValueError` if the provided validator *doesn't* raise a
|
| 635 |
+
`ValueError` or `TypeError` (by default), and will suppress the exception
|
| 636 |
+
if the provided validator *does*.
|
| 637 |
+
|
| 638 |
+
Intended to be used with existing validators to compose logic without
|
| 639 |
+
needing to create inverted variants, for example, ``not_(in_(...))``.
|
| 640 |
+
|
| 641 |
+
Args:
|
| 642 |
+
validator: A validator to be logically inverted.
|
| 643 |
+
|
| 644 |
+
msg (str):
|
| 645 |
+
Message to raise if validator fails. Formatted with keys
|
| 646 |
+
``exc_types`` and ``validator``.
|
| 647 |
+
|
| 648 |
+
exc_types (tuple[type, ...]):
|
| 649 |
+
Exception type(s) to capture. Other types raised by child
|
| 650 |
+
validators will not be intercepted and pass through.
|
| 651 |
+
|
| 652 |
+
Raises:
|
| 653 |
+
ValueError:
|
| 654 |
+
With a human readable error message, the attribute (of type
|
| 655 |
+
`attrs.Attribute`), the validator that failed to raise an
|
| 656 |
+
exception, the value it got, and the expected exception types.
|
| 657 |
+
|
| 658 |
+
.. versionadded:: 22.2.0
|
| 659 |
+
"""
|
| 660 |
+
try:
|
| 661 |
+
exc_types = tuple(exc_types)
|
| 662 |
+
except TypeError:
|
| 663 |
+
exc_types = (exc_types,)
|
| 664 |
+
return _NotValidator(validator, msg, exc_types)
|
| 665 |
+
|
| 666 |
+
|
| 667 |
+
@attrs(repr=False, slots=True, unsafe_hash=True)
|
| 668 |
+
class _OrValidator:
|
| 669 |
+
validators = attrib()
|
| 670 |
+
|
| 671 |
+
def __call__(self, inst, attr, value):
|
| 672 |
+
for v in self.validators:
|
| 673 |
+
try:
|
| 674 |
+
v(inst, attr, value)
|
| 675 |
+
except Exception: # noqa: BLE001, PERF203, S112
|
| 676 |
+
continue
|
| 677 |
+
else:
|
| 678 |
+
return
|
| 679 |
+
|
| 680 |
+
msg = f"None of {self.validators!r} satisfied for value {value!r}"
|
| 681 |
+
raise ValueError(msg)
|
| 682 |
+
|
| 683 |
+
def __repr__(self):
|
| 684 |
+
return f"<or validator wrapping {self.validators!r}>"
|
| 685 |
+
|
| 686 |
+
|
| 687 |
+
def or_(*validators):
|
| 688 |
+
"""
|
| 689 |
+
A validator that composes multiple validators into one.
|
| 690 |
+
|
| 691 |
+
When called on a value, it runs all wrapped validators until one of them is
|
| 692 |
+
satisfied.
|
| 693 |
+
|
| 694 |
+
Args:
|
| 695 |
+
validators (~collections.abc.Iterable[typing.Callable]):
|
| 696 |
+
Arbitrary number of validators.
|
| 697 |
+
|
| 698 |
+
Raises:
|
| 699 |
+
ValueError:
|
| 700 |
+
If no validator is satisfied. Raised with a human-readable error
|
| 701 |
+
message listing all the wrapped validators and the value that
|
| 702 |
+
failed all of them.
|
| 703 |
+
|
| 704 |
+
.. versionadded:: 24.1.0
|
| 705 |
+
"""
|
| 706 |
+
vals = []
|
| 707 |
+
for v in validators:
|
| 708 |
+
vals.extend(v.validators if isinstance(v, _OrValidator) else [v])
|
| 709 |
+
|
| 710 |
+
return _OrValidator(tuple(vals))
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/attr/validators.pyi
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from types import UnionType
|
| 2 |
+
from typing import (
|
| 3 |
+
Any,
|
| 4 |
+
AnyStr,
|
| 5 |
+
Callable,
|
| 6 |
+
Container,
|
| 7 |
+
ContextManager,
|
| 8 |
+
Iterable,
|
| 9 |
+
Mapping,
|
| 10 |
+
Match,
|
| 11 |
+
Pattern,
|
| 12 |
+
TypeVar,
|
| 13 |
+
overload,
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
from attrs import _ValidatorType
|
| 17 |
+
from attrs import _ValidatorArgType
|
| 18 |
+
|
| 19 |
+
_T = TypeVar("_T")
|
| 20 |
+
_T1 = TypeVar("_T1")
|
| 21 |
+
_T2 = TypeVar("_T2")
|
| 22 |
+
_T3 = TypeVar("_T3")
|
| 23 |
+
_I = TypeVar("_I", bound=Iterable)
|
| 24 |
+
_K = TypeVar("_K")
|
| 25 |
+
_V = TypeVar("_V")
|
| 26 |
+
_M = TypeVar("_M", bound=Mapping)
|
| 27 |
+
|
| 28 |
+
def set_disabled(run: bool) -> None: ...
|
| 29 |
+
def get_disabled() -> bool: ...
|
| 30 |
+
def disabled() -> ContextManager[None]: ...
|
| 31 |
+
|
| 32 |
+
# To be more precise on instance_of use some overloads.
|
| 33 |
+
# If there are more than 3 items in the tuple then we fall back to Any
|
| 34 |
+
@overload
|
| 35 |
+
def instance_of(type: type[_T]) -> _ValidatorType[_T]: ...
|
| 36 |
+
@overload
|
| 37 |
+
def instance_of(type: tuple[type[_T]]) -> _ValidatorType[_T]: ...
|
| 38 |
+
@overload
|
| 39 |
+
def instance_of(
|
| 40 |
+
type: tuple[type[_T1], type[_T2]],
|
| 41 |
+
) -> _ValidatorType[_T1 | _T2]: ...
|
| 42 |
+
@overload
|
| 43 |
+
def instance_of(
|
| 44 |
+
type: tuple[type[_T1], type[_T2], type[_T3]],
|
| 45 |
+
) -> _ValidatorType[_T1 | _T2 | _T3]: ...
|
| 46 |
+
@overload
|
| 47 |
+
def instance_of(type: tuple[type, ...]) -> _ValidatorType[Any]: ...
|
| 48 |
+
@overload
|
| 49 |
+
def instance_of(type: UnionType) -> _ValidatorType[Any]: ...
|
| 50 |
+
def optional(
|
| 51 |
+
validator: (
|
| 52 |
+
_ValidatorType[_T]
|
| 53 |
+
| list[_ValidatorType[_T]]
|
| 54 |
+
| tuple[_ValidatorType[_T]]
|
| 55 |
+
),
|
| 56 |
+
) -> _ValidatorType[_T | None]: ...
|
| 57 |
+
def in_(options: Container[_T]) -> _ValidatorType[_T]: ...
|
| 58 |
+
def and_(*validators: _ValidatorType[_T]) -> _ValidatorType[_T]: ...
|
| 59 |
+
def matches_re(
|
| 60 |
+
regex: Pattern[AnyStr] | AnyStr,
|
| 61 |
+
flags: int = ...,
|
| 62 |
+
func: Callable[[AnyStr, AnyStr, int], Match[AnyStr] | None] | None = ...,
|
| 63 |
+
) -> _ValidatorType[AnyStr]: ...
|
| 64 |
+
def deep_iterable(
|
| 65 |
+
member_validator: _ValidatorArgType[_T],
|
| 66 |
+
iterable_validator: _ValidatorType[_I] | None = ...,
|
| 67 |
+
) -> _ValidatorType[_I]: ...
|
| 68 |
+
def deep_mapping(
|
| 69 |
+
key_validator: _ValidatorType[_K],
|
| 70 |
+
value_validator: _ValidatorType[_V],
|
| 71 |
+
mapping_validator: _ValidatorType[_M] | None = ...,
|
| 72 |
+
) -> _ValidatorType[_M]: ...
|
| 73 |
+
def is_callable() -> _ValidatorType[_T]: ...
|
| 74 |
+
def lt(val: _T) -> _ValidatorType[_T]: ...
|
| 75 |
+
def le(val: _T) -> _ValidatorType[_T]: ...
|
| 76 |
+
def ge(val: _T) -> _ValidatorType[_T]: ...
|
| 77 |
+
def gt(val: _T) -> _ValidatorType[_T]: ...
|
| 78 |
+
def max_len(length: int) -> _ValidatorType[_T]: ...
|
| 79 |
+
def min_len(length: int) -> _ValidatorType[_T]: ...
|
| 80 |
+
def not_(
|
| 81 |
+
validator: _ValidatorType[_T],
|
| 82 |
+
*,
|
| 83 |
+
msg: str | None = None,
|
| 84 |
+
exc_types: type[Exception] | Iterable[type[Exception]] = ...,
|
| 85 |
+
) -> _ValidatorType[_T]: ...
|
| 86 |
+
def or_(*validators: _ValidatorType[_T]) -> _ValidatorType[_T]: ...
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/__init__.py
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
######################## BEGIN LICENSE BLOCK ########################
|
| 2 |
+
# This library is free software; you can redistribute it and/or
|
| 3 |
+
# modify it under the terms of the GNU Lesser General Public
|
| 4 |
+
# License as published by the Free Software Foundation; either
|
| 5 |
+
# version 2.1 of the License, or (at your option) any later version.
|
| 6 |
+
#
|
| 7 |
+
# This library is distributed in the hope that it will be useful,
|
| 8 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 9 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 10 |
+
# Lesser General Public License for more details.
|
| 11 |
+
#
|
| 12 |
+
# You should have received a copy of the GNU Lesser General Public
|
| 13 |
+
# License along with this library; if not, write to the Free Software
|
| 14 |
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
| 15 |
+
# 02110-1301 USA
|
| 16 |
+
######################### END LICENSE BLOCK #########################
|
| 17 |
+
|
| 18 |
+
from typing import List, Union
|
| 19 |
+
|
| 20 |
+
from .charsetgroupprober import CharSetGroupProber
|
| 21 |
+
from .charsetprober import CharSetProber
|
| 22 |
+
from .enums import InputState
|
| 23 |
+
from .resultdict import ResultDict
|
| 24 |
+
from .universaldetector import UniversalDetector
|
| 25 |
+
from .version import VERSION, __version__
|
| 26 |
+
|
| 27 |
+
__all__ = ["UniversalDetector", "detect", "detect_all", "__version__", "VERSION"]
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def detect(
|
| 31 |
+
byte_str: Union[bytes, bytearray], should_rename_legacy: bool = False
|
| 32 |
+
) -> ResultDict:
|
| 33 |
+
"""
|
| 34 |
+
Detect the encoding of the given byte string.
|
| 35 |
+
|
| 36 |
+
:param byte_str: The byte sequence to examine.
|
| 37 |
+
:type byte_str: ``bytes`` or ``bytearray``
|
| 38 |
+
:param should_rename_legacy: Should we rename legacy encodings
|
| 39 |
+
to their more modern equivalents?
|
| 40 |
+
:type should_rename_legacy: ``bool``
|
| 41 |
+
"""
|
| 42 |
+
if not isinstance(byte_str, bytearray):
|
| 43 |
+
if not isinstance(byte_str, bytes):
|
| 44 |
+
raise TypeError(
|
| 45 |
+
f"Expected object of type bytes or bytearray, got: {type(byte_str)}"
|
| 46 |
+
)
|
| 47 |
+
byte_str = bytearray(byte_str)
|
| 48 |
+
detector = UniversalDetector(should_rename_legacy=should_rename_legacy)
|
| 49 |
+
detector.feed(byte_str)
|
| 50 |
+
return detector.close()
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def detect_all(
|
| 54 |
+
byte_str: Union[bytes, bytearray],
|
| 55 |
+
ignore_threshold: bool = False,
|
| 56 |
+
should_rename_legacy: bool = False,
|
| 57 |
+
) -> List[ResultDict]:
|
| 58 |
+
"""
|
| 59 |
+
Detect all the possible encodings of the given byte string.
|
| 60 |
+
|
| 61 |
+
:param byte_str: The byte sequence to examine.
|
| 62 |
+
:type byte_str: ``bytes`` or ``bytearray``
|
| 63 |
+
:param ignore_threshold: Include encodings that are below
|
| 64 |
+
``UniversalDetector.MINIMUM_THRESHOLD``
|
| 65 |
+
in results.
|
| 66 |
+
:type ignore_threshold: ``bool``
|
| 67 |
+
:param should_rename_legacy: Should we rename legacy encodings
|
| 68 |
+
to their more modern equivalents?
|
| 69 |
+
:type should_rename_legacy: ``bool``
|
| 70 |
+
"""
|
| 71 |
+
if not isinstance(byte_str, bytearray):
|
| 72 |
+
if not isinstance(byte_str, bytes):
|
| 73 |
+
raise TypeError(
|
| 74 |
+
f"Expected object of type bytes or bytearray, got: {type(byte_str)}"
|
| 75 |
+
)
|
| 76 |
+
byte_str = bytearray(byte_str)
|
| 77 |
+
|
| 78 |
+
detector = UniversalDetector(should_rename_legacy=should_rename_legacy)
|
| 79 |
+
detector.feed(byte_str)
|
| 80 |
+
detector.close()
|
| 81 |
+
|
| 82 |
+
if detector.input_state == InputState.HIGH_BYTE:
|
| 83 |
+
results: List[ResultDict] = []
|
| 84 |
+
probers: List[CharSetProber] = []
|
| 85 |
+
for prober in detector.charset_probers:
|
| 86 |
+
if isinstance(prober, CharSetGroupProber):
|
| 87 |
+
probers.extend(p for p in prober.probers)
|
| 88 |
+
else:
|
| 89 |
+
probers.append(prober)
|
| 90 |
+
for prober in probers:
|
| 91 |
+
if ignore_threshold or prober.get_confidence() > detector.MINIMUM_THRESHOLD:
|
| 92 |
+
charset_name = prober.charset_name or ""
|
| 93 |
+
lower_charset_name = charset_name.lower()
|
| 94 |
+
# Use Windows encoding name instead of ISO-8859 if we saw any
|
| 95 |
+
# extra Windows-specific bytes
|
| 96 |
+
if lower_charset_name.startswith("iso-8859") and detector.has_win_bytes:
|
| 97 |
+
charset_name = detector.ISO_WIN_MAP.get(
|
| 98 |
+
lower_charset_name, charset_name
|
| 99 |
+
)
|
| 100 |
+
# Rename legacy encodings with superset encodings if asked
|
| 101 |
+
if should_rename_legacy:
|
| 102 |
+
charset_name = detector.LEGACY_MAP.get(
|
| 103 |
+
charset_name.lower(), charset_name
|
| 104 |
+
)
|
| 105 |
+
results.append(
|
| 106 |
+
{
|
| 107 |
+
"encoding": charset_name,
|
| 108 |
+
"confidence": prober.get_confidence(),
|
| 109 |
+
"language": prober.language,
|
| 110 |
+
}
|
| 111 |
+
)
|
| 112 |
+
if len(results) > 0:
|
| 113 |
+
return sorted(results, key=lambda result: -result["confidence"])
|
| 114 |
+
|
| 115 |
+
return [detector.result]
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/chardistribution.py
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
######################## BEGIN LICENSE BLOCK ########################
|
| 2 |
+
# The Original Code is Mozilla Communicator client code.
|
| 3 |
+
#
|
| 4 |
+
# The Initial Developer of the Original Code is
|
| 5 |
+
# Netscape Communications Corporation.
|
| 6 |
+
# Portions created by the Initial Developer are Copyright (C) 1998
|
| 7 |
+
# the Initial Developer. All Rights Reserved.
|
| 8 |
+
#
|
| 9 |
+
# Contributor(s):
|
| 10 |
+
# Mark Pilgrim - port to Python
|
| 11 |
+
#
|
| 12 |
+
# This library is free software; you can redistribute it and/or
|
| 13 |
+
# modify it under the terms of the GNU Lesser General Public
|
| 14 |
+
# License as published by the Free Software Foundation; either
|
| 15 |
+
# version 2.1 of the License, or (at your option) any later version.
|
| 16 |
+
#
|
| 17 |
+
# This library is distributed in the hope that it will be useful,
|
| 18 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 19 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 20 |
+
# Lesser General Public License for more details.
|
| 21 |
+
#
|
| 22 |
+
# You should have received a copy of the GNU Lesser General Public
|
| 23 |
+
# License along with this library; if not, write to the Free Software
|
| 24 |
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
| 25 |
+
# 02110-1301 USA
|
| 26 |
+
######################### END LICENSE BLOCK #########################
|
| 27 |
+
|
| 28 |
+
from typing import Tuple, Union
|
| 29 |
+
|
| 30 |
+
from .big5freq import (
|
| 31 |
+
BIG5_CHAR_TO_FREQ_ORDER,
|
| 32 |
+
BIG5_TABLE_SIZE,
|
| 33 |
+
BIG5_TYPICAL_DISTRIBUTION_RATIO,
|
| 34 |
+
)
|
| 35 |
+
from .euckrfreq import (
|
| 36 |
+
EUCKR_CHAR_TO_FREQ_ORDER,
|
| 37 |
+
EUCKR_TABLE_SIZE,
|
| 38 |
+
EUCKR_TYPICAL_DISTRIBUTION_RATIO,
|
| 39 |
+
)
|
| 40 |
+
from .euctwfreq import (
|
| 41 |
+
EUCTW_CHAR_TO_FREQ_ORDER,
|
| 42 |
+
EUCTW_TABLE_SIZE,
|
| 43 |
+
EUCTW_TYPICAL_DISTRIBUTION_RATIO,
|
| 44 |
+
)
|
| 45 |
+
from .gb2312freq import (
|
| 46 |
+
GB2312_CHAR_TO_FREQ_ORDER,
|
| 47 |
+
GB2312_TABLE_SIZE,
|
| 48 |
+
GB2312_TYPICAL_DISTRIBUTION_RATIO,
|
| 49 |
+
)
|
| 50 |
+
from .jisfreq import (
|
| 51 |
+
JIS_CHAR_TO_FREQ_ORDER,
|
| 52 |
+
JIS_TABLE_SIZE,
|
| 53 |
+
JIS_TYPICAL_DISTRIBUTION_RATIO,
|
| 54 |
+
)
|
| 55 |
+
from .johabfreq import JOHAB_TO_EUCKR_ORDER_TABLE
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
class CharDistributionAnalysis:
|
| 59 |
+
ENOUGH_DATA_THRESHOLD = 1024
|
| 60 |
+
SURE_YES = 0.99
|
| 61 |
+
SURE_NO = 0.01
|
| 62 |
+
MINIMUM_DATA_THRESHOLD = 3
|
| 63 |
+
|
| 64 |
+
def __init__(self) -> None:
|
| 65 |
+
# Mapping table to get frequency order from char order (get from
|
| 66 |
+
# GetOrder())
|
| 67 |
+
self._char_to_freq_order: Tuple[int, ...] = tuple()
|
| 68 |
+
self._table_size = 0 # Size of above table
|
| 69 |
+
# This is a constant value which varies from language to language,
|
| 70 |
+
# used in calculating confidence. See
|
| 71 |
+
# http://www.mozilla.org/projects/intl/UniversalCharsetDetection.html
|
| 72 |
+
# for further detail.
|
| 73 |
+
self.typical_distribution_ratio = 0.0
|
| 74 |
+
self._done = False
|
| 75 |
+
self._total_chars = 0
|
| 76 |
+
self._freq_chars = 0
|
| 77 |
+
self.reset()
|
| 78 |
+
|
| 79 |
+
def reset(self) -> None:
|
| 80 |
+
"""reset analyser, clear any state"""
|
| 81 |
+
# If this flag is set to True, detection is done and conclusion has
|
| 82 |
+
# been made
|
| 83 |
+
self._done = False
|
| 84 |
+
self._total_chars = 0 # Total characters encountered
|
| 85 |
+
# The number of characters whose frequency order is less than 512
|
| 86 |
+
self._freq_chars = 0
|
| 87 |
+
|
| 88 |
+
def feed(self, char: Union[bytes, bytearray], char_len: int) -> None:
|
| 89 |
+
"""feed a character with known length"""
|
| 90 |
+
if char_len == 2:
|
| 91 |
+
# we only care about 2-bytes character in our distribution analysis
|
| 92 |
+
order = self.get_order(char)
|
| 93 |
+
else:
|
| 94 |
+
order = -1
|
| 95 |
+
if order >= 0:
|
| 96 |
+
self._total_chars += 1
|
| 97 |
+
# order is valid
|
| 98 |
+
if order < self._table_size:
|
| 99 |
+
if 512 > self._char_to_freq_order[order]:
|
| 100 |
+
self._freq_chars += 1
|
| 101 |
+
|
| 102 |
+
def get_confidence(self) -> float:
|
| 103 |
+
"""return confidence based on existing data"""
|
| 104 |
+
# if we didn't receive any character in our consideration range,
|
| 105 |
+
# return negative answer
|
| 106 |
+
if self._total_chars <= 0 or self._freq_chars <= self.MINIMUM_DATA_THRESHOLD:
|
| 107 |
+
return self.SURE_NO
|
| 108 |
+
|
| 109 |
+
if self._total_chars != self._freq_chars:
|
| 110 |
+
r = self._freq_chars / (
|
| 111 |
+
(self._total_chars - self._freq_chars) * self.typical_distribution_ratio
|
| 112 |
+
)
|
| 113 |
+
if r < self.SURE_YES:
|
| 114 |
+
return r
|
| 115 |
+
|
| 116 |
+
# normalize confidence (we don't want to be 100% sure)
|
| 117 |
+
return self.SURE_YES
|
| 118 |
+
|
| 119 |
+
def got_enough_data(self) -> bool:
|
| 120 |
+
# It is not necessary to receive all data to draw conclusion.
|
| 121 |
+
# For charset detection, certain amount of data is enough
|
| 122 |
+
return self._total_chars > self.ENOUGH_DATA_THRESHOLD
|
| 123 |
+
|
| 124 |
+
def get_order(self, _: Union[bytes, bytearray]) -> int:
|
| 125 |
+
# We do not handle characters based on the original encoding string,
|
| 126 |
+
# but convert this encoding string to a number, here called order.
|
| 127 |
+
# This allows multiple encodings of a language to share one frequency
|
| 128 |
+
# table.
|
| 129 |
+
return -1
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
class EUCTWDistributionAnalysis(CharDistributionAnalysis):
|
| 133 |
+
def __init__(self) -> None:
|
| 134 |
+
super().__init__()
|
| 135 |
+
self._char_to_freq_order = EUCTW_CHAR_TO_FREQ_ORDER
|
| 136 |
+
self._table_size = EUCTW_TABLE_SIZE
|
| 137 |
+
self.typical_distribution_ratio = EUCTW_TYPICAL_DISTRIBUTION_RATIO
|
| 138 |
+
|
| 139 |
+
def get_order(self, byte_str: Union[bytes, bytearray]) -> int:
|
| 140 |
+
# for euc-TW encoding, we are interested
|
| 141 |
+
# first byte range: 0xc4 -- 0xfe
|
| 142 |
+
# second byte range: 0xa1 -- 0xfe
|
| 143 |
+
# no validation needed here. State machine has done that
|
| 144 |
+
first_char = byte_str[0]
|
| 145 |
+
if first_char >= 0xC4:
|
| 146 |
+
return 94 * (first_char - 0xC4) + byte_str[1] - 0xA1
|
| 147 |
+
return -1
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
class EUCKRDistributionAnalysis(CharDistributionAnalysis):
|
| 151 |
+
def __init__(self) -> None:
|
| 152 |
+
super().__init__()
|
| 153 |
+
self._char_to_freq_order = EUCKR_CHAR_TO_FREQ_ORDER
|
| 154 |
+
self._table_size = EUCKR_TABLE_SIZE
|
| 155 |
+
self.typical_distribution_ratio = EUCKR_TYPICAL_DISTRIBUTION_RATIO
|
| 156 |
+
|
| 157 |
+
def get_order(self, byte_str: Union[bytes, bytearray]) -> int:
|
| 158 |
+
# for euc-KR encoding, we are interested
|
| 159 |
+
# first byte range: 0xb0 -- 0xfe
|
| 160 |
+
# second byte range: 0xa1 -- 0xfe
|
| 161 |
+
# no validation needed here. State machine has done that
|
| 162 |
+
first_char = byte_str[0]
|
| 163 |
+
if first_char >= 0xB0:
|
| 164 |
+
return 94 * (first_char - 0xB0) + byte_str[1] - 0xA1
|
| 165 |
+
return -1
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
class JOHABDistributionAnalysis(CharDistributionAnalysis):
|
| 169 |
+
def __init__(self) -> None:
|
| 170 |
+
super().__init__()
|
| 171 |
+
self._char_to_freq_order = EUCKR_CHAR_TO_FREQ_ORDER
|
| 172 |
+
self._table_size = EUCKR_TABLE_SIZE
|
| 173 |
+
self.typical_distribution_ratio = EUCKR_TYPICAL_DISTRIBUTION_RATIO
|
| 174 |
+
|
| 175 |
+
def get_order(self, byte_str: Union[bytes, bytearray]) -> int:
|
| 176 |
+
first_char = byte_str[0]
|
| 177 |
+
if 0x88 <= first_char < 0xD4:
|
| 178 |
+
code = first_char * 256 + byte_str[1]
|
| 179 |
+
return JOHAB_TO_EUCKR_ORDER_TABLE.get(code, -1)
|
| 180 |
+
return -1
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
class GB2312DistributionAnalysis(CharDistributionAnalysis):
|
| 184 |
+
def __init__(self) -> None:
|
| 185 |
+
super().__init__()
|
| 186 |
+
self._char_to_freq_order = GB2312_CHAR_TO_FREQ_ORDER
|
| 187 |
+
self._table_size = GB2312_TABLE_SIZE
|
| 188 |
+
self.typical_distribution_ratio = GB2312_TYPICAL_DISTRIBUTION_RATIO
|
| 189 |
+
|
| 190 |
+
def get_order(self, byte_str: Union[bytes, bytearray]) -> int:
|
| 191 |
+
# for GB2312 encoding, we are interested
|
| 192 |
+
# first byte range: 0xb0 -- 0xfe
|
| 193 |
+
# second byte range: 0xa1 -- 0xfe
|
| 194 |
+
# no validation needed here. State machine has done that
|
| 195 |
+
first_char, second_char = byte_str[0], byte_str[1]
|
| 196 |
+
if (first_char >= 0xB0) and (second_char >= 0xA1):
|
| 197 |
+
return 94 * (first_char - 0xB0) + second_char - 0xA1
|
| 198 |
+
return -1
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
class Big5DistributionAnalysis(CharDistributionAnalysis):
|
| 202 |
+
def __init__(self) -> None:
|
| 203 |
+
super().__init__()
|
| 204 |
+
self._char_to_freq_order = BIG5_CHAR_TO_FREQ_ORDER
|
| 205 |
+
self._table_size = BIG5_TABLE_SIZE
|
| 206 |
+
self.typical_distribution_ratio = BIG5_TYPICAL_DISTRIBUTION_RATIO
|
| 207 |
+
|
| 208 |
+
def get_order(self, byte_str: Union[bytes, bytearray]) -> int:
|
| 209 |
+
# for big5 encoding, we are interested
|
| 210 |
+
# first byte range: 0xa4 -- 0xfe
|
| 211 |
+
# second byte range: 0x40 -- 0x7e , 0xa1 -- 0xfe
|
| 212 |
+
# no validation needed here. State machine has done that
|
| 213 |
+
first_char, second_char = byte_str[0], byte_str[1]
|
| 214 |
+
if first_char >= 0xA4:
|
| 215 |
+
if second_char >= 0xA1:
|
| 216 |
+
return 157 * (first_char - 0xA4) + second_char - 0xA1 + 63
|
| 217 |
+
return 157 * (first_char - 0xA4) + second_char - 0x40
|
| 218 |
+
return -1
|
| 219 |
+
|
| 220 |
+
|
| 221 |
+
class SJISDistributionAnalysis(CharDistributionAnalysis):
|
| 222 |
+
def __init__(self) -> None:
|
| 223 |
+
super().__init__()
|
| 224 |
+
self._char_to_freq_order = JIS_CHAR_TO_FREQ_ORDER
|
| 225 |
+
self._table_size = JIS_TABLE_SIZE
|
| 226 |
+
self.typical_distribution_ratio = JIS_TYPICAL_DISTRIBUTION_RATIO
|
| 227 |
+
|
| 228 |
+
def get_order(self, byte_str: Union[bytes, bytearray]) -> int:
|
| 229 |
+
# for sjis encoding, we are interested
|
| 230 |
+
# first byte range: 0x81 -- 0x9f , 0xe0 -- 0xfe
|
| 231 |
+
# second byte range: 0x40 -- 0x7e, 0x81 -- oxfe
|
| 232 |
+
# no validation needed here. State machine has done that
|
| 233 |
+
first_char, second_char = byte_str[0], byte_str[1]
|
| 234 |
+
if 0x81 <= first_char <= 0x9F:
|
| 235 |
+
order = 188 * (first_char - 0x81)
|
| 236 |
+
elif 0xE0 <= first_char <= 0xEF:
|
| 237 |
+
order = 188 * (first_char - 0xE0 + 31)
|
| 238 |
+
else:
|
| 239 |
+
return -1
|
| 240 |
+
order = order + second_char - 0x40
|
| 241 |
+
if second_char > 0x7F:
|
| 242 |
+
order = -1
|
| 243 |
+
return order
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
class EUCJPDistributionAnalysis(CharDistributionAnalysis):
|
| 247 |
+
def __init__(self) -> None:
|
| 248 |
+
super().__init__()
|
| 249 |
+
self._char_to_freq_order = JIS_CHAR_TO_FREQ_ORDER
|
| 250 |
+
self._table_size = JIS_TABLE_SIZE
|
| 251 |
+
self.typical_distribution_ratio = JIS_TYPICAL_DISTRIBUTION_RATIO
|
| 252 |
+
|
| 253 |
+
def get_order(self, byte_str: Union[bytes, bytearray]) -> int:
|
| 254 |
+
# for euc-JP encoding, we are interested
|
| 255 |
+
# first byte range: 0xa0 -- 0xfe
|
| 256 |
+
# second byte range: 0xa1 -- 0xfe
|
| 257 |
+
# no validation needed here. State machine has done that
|
| 258 |
+
char = byte_str[0]
|
| 259 |
+
if char >= 0xA0:
|
| 260 |
+
return 94 * (char - 0xA1) + byte_str[1] - 0xA1
|
| 261 |
+
return -1
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/codingstatemachine.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
######################## BEGIN LICENSE BLOCK ########################
|
| 2 |
+
# The Original Code is mozilla.org code.
|
| 3 |
+
#
|
| 4 |
+
# The Initial Developer of the Original Code is
|
| 5 |
+
# Netscape Communications Corporation.
|
| 6 |
+
# Portions created by the Initial Developer are Copyright (C) 1998
|
| 7 |
+
# the Initial Developer. All Rights Reserved.
|
| 8 |
+
#
|
| 9 |
+
# Contributor(s):
|
| 10 |
+
# Mark Pilgrim - port to Python
|
| 11 |
+
#
|
| 12 |
+
# This library is free software; you can redistribute it and/or
|
| 13 |
+
# modify it under the terms of the GNU Lesser General Public
|
| 14 |
+
# License as published by the Free Software Foundation; either
|
| 15 |
+
# version 2.1 of the License, or (at your option) any later version.
|
| 16 |
+
#
|
| 17 |
+
# This library is distributed in the hope that it will be useful,
|
| 18 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 19 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 20 |
+
# Lesser General Public License for more details.
|
| 21 |
+
#
|
| 22 |
+
# You should have received a copy of the GNU Lesser General Public
|
| 23 |
+
# License along with this library; if not, write to the Free Software
|
| 24 |
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
| 25 |
+
# 02110-1301 USA
|
| 26 |
+
######################### END LICENSE BLOCK #########################
|
| 27 |
+
|
| 28 |
+
import logging
|
| 29 |
+
|
| 30 |
+
from .codingstatemachinedict import CodingStateMachineDict
|
| 31 |
+
from .enums import MachineState
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class CodingStateMachine:
|
| 35 |
+
"""
|
| 36 |
+
A state machine to verify a byte sequence for a particular encoding. For
|
| 37 |
+
each byte the detector receives, it will feed that byte to every active
|
| 38 |
+
state machine available, one byte at a time. The state machine changes its
|
| 39 |
+
state based on its previous state and the byte it receives. There are 3
|
| 40 |
+
states in a state machine that are of interest to an auto-detector:
|
| 41 |
+
|
| 42 |
+
START state: This is the state to start with, or a legal byte sequence
|
| 43 |
+
(i.e. a valid code point) for character has been identified.
|
| 44 |
+
|
| 45 |
+
ME state: This indicates that the state machine identified a byte sequence
|
| 46 |
+
that is specific to the charset it is designed for and that
|
| 47 |
+
there is no other possible encoding which can contain this byte
|
| 48 |
+
sequence. This will to lead to an immediate positive answer for
|
| 49 |
+
the detector.
|
| 50 |
+
|
| 51 |
+
ERROR state: This indicates the state machine identified an illegal byte
|
| 52 |
+
sequence for that encoding. This will lead to an immediate
|
| 53 |
+
negative answer for this encoding. Detector will exclude this
|
| 54 |
+
encoding from consideration from here on.
|
| 55 |
+
"""
|
| 56 |
+
|
| 57 |
+
def __init__(self, sm: CodingStateMachineDict) -> None:
|
| 58 |
+
self._model = sm
|
| 59 |
+
self._curr_byte_pos = 0
|
| 60 |
+
self._curr_char_len = 0
|
| 61 |
+
self._curr_state = MachineState.START
|
| 62 |
+
self.active = True
|
| 63 |
+
self.logger = logging.getLogger(__name__)
|
| 64 |
+
self.reset()
|
| 65 |
+
|
| 66 |
+
def reset(self) -> None:
|
| 67 |
+
self._curr_state = MachineState.START
|
| 68 |
+
|
| 69 |
+
def next_state(self, c: int) -> int:
|
| 70 |
+
# for each byte we get its class
|
| 71 |
+
# if it is first byte, we also get byte length
|
| 72 |
+
byte_class = self._model["class_table"][c]
|
| 73 |
+
if self._curr_state == MachineState.START:
|
| 74 |
+
self._curr_byte_pos = 0
|
| 75 |
+
self._curr_char_len = self._model["char_len_table"][byte_class]
|
| 76 |
+
# from byte's class and state_table, we get its next state
|
| 77 |
+
curr_state = self._curr_state * self._model["class_factor"] + byte_class
|
| 78 |
+
self._curr_state = self._model["state_table"][curr_state]
|
| 79 |
+
self._curr_byte_pos += 1
|
| 80 |
+
return self._curr_state
|
| 81 |
+
|
| 82 |
+
def get_current_charlen(self) -> int:
|
| 83 |
+
return self._curr_char_len
|
| 84 |
+
|
| 85 |
+
def get_coding_state_machine(self) -> str:
|
| 86 |
+
return self._model["name"]
|
| 87 |
+
|
| 88 |
+
@property
|
| 89 |
+
def language(self) -> str:
|
| 90 |
+
return self._model["language"]
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/cp949prober.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
######################## BEGIN LICENSE BLOCK ########################
|
| 2 |
+
# The Original Code is mozilla.org code.
|
| 3 |
+
#
|
| 4 |
+
# The Initial Developer of the Original Code is
|
| 5 |
+
# Netscape Communications Corporation.
|
| 6 |
+
# Portions created by the Initial Developer are Copyright (C) 1998
|
| 7 |
+
# the Initial Developer. All Rights Reserved.
|
| 8 |
+
#
|
| 9 |
+
# Contributor(s):
|
| 10 |
+
# Mark Pilgrim - port to Python
|
| 11 |
+
#
|
| 12 |
+
# This library is free software; you can redistribute it and/or
|
| 13 |
+
# modify it under the terms of the GNU Lesser General Public
|
| 14 |
+
# License as published by the Free Software Foundation; either
|
| 15 |
+
# version 2.1 of the License, or (at your option) any later version.
|
| 16 |
+
#
|
| 17 |
+
# This library is distributed in the hope that it will be useful,
|
| 18 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 19 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 20 |
+
# Lesser General Public License for more details.
|
| 21 |
+
#
|
| 22 |
+
# You should have received a copy of the GNU Lesser General Public
|
| 23 |
+
# License along with this library; if not, write to the Free Software
|
| 24 |
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
| 25 |
+
# 02110-1301 USA
|
| 26 |
+
######################### END LICENSE BLOCK #########################
|
| 27 |
+
|
| 28 |
+
from .chardistribution import EUCKRDistributionAnalysis
|
| 29 |
+
from .codingstatemachine import CodingStateMachine
|
| 30 |
+
from .mbcharsetprober import MultiByteCharSetProber
|
| 31 |
+
from .mbcssm import CP949_SM_MODEL
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class CP949Prober(MultiByteCharSetProber):
|
| 35 |
+
def __init__(self) -> None:
|
| 36 |
+
super().__init__()
|
| 37 |
+
self.coding_sm = CodingStateMachine(CP949_SM_MODEL)
|
| 38 |
+
# NOTE: CP949 is a superset of EUC-KR, so the distribution should be
|
| 39 |
+
# not different.
|
| 40 |
+
self.distribution_analyzer = EUCKRDistributionAnalysis()
|
| 41 |
+
self.reset()
|
| 42 |
+
|
| 43 |
+
@property
|
| 44 |
+
def charset_name(self) -> str:
|
| 45 |
+
return "CP949"
|
| 46 |
+
|
| 47 |
+
@property
|
| 48 |
+
def language(self) -> str:
|
| 49 |
+
return "Korean"
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/escsm.py
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
######################## BEGIN LICENSE BLOCK ########################
|
| 2 |
+
# The Original Code is mozilla.org code.
|
| 3 |
+
#
|
| 4 |
+
# The Initial Developer of the Original Code is
|
| 5 |
+
# Netscape Communications Corporation.
|
| 6 |
+
# Portions created by the Initial Developer are Copyright (C) 1998
|
| 7 |
+
# the Initial Developer. All Rights Reserved.
|
| 8 |
+
#
|
| 9 |
+
# Contributor(s):
|
| 10 |
+
# Mark Pilgrim - port to Python
|
| 11 |
+
#
|
| 12 |
+
# This library is free software; you can redistribute it and/or
|
| 13 |
+
# modify it under the terms of the GNU Lesser General Public
|
| 14 |
+
# License as published by the Free Software Foundation; either
|
| 15 |
+
# version 2.1 of the License, or (at your option) any later version.
|
| 16 |
+
#
|
| 17 |
+
# This library is distributed in the hope that it will be useful,
|
| 18 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 19 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 20 |
+
# Lesser General Public License for more details.
|
| 21 |
+
#
|
| 22 |
+
# You should have received a copy of the GNU Lesser General Public
|
| 23 |
+
# License along with this library; if not, write to the Free Software
|
| 24 |
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
| 25 |
+
# 02110-1301 USA
|
| 26 |
+
######################### END LICENSE BLOCK #########################
|
| 27 |
+
|
| 28 |
+
from .codingstatemachinedict import CodingStateMachineDict
|
| 29 |
+
from .enums import MachineState
|
| 30 |
+
|
| 31 |
+
# fmt: off
|
| 32 |
+
HZ_CLS = (
|
| 33 |
+
1, 0, 0, 0, 0, 0, 0, 0, # 00 - 07
|
| 34 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 08 - 0f
|
| 35 |
+
0, 0, 0, 0, 0, 0, 0, 0, #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1, 1, 1, # d8 - df
|
| 61 |
+
1, 1, 1, 1, 1, 1, 1, 1, # e0 - e7
|
| 62 |
+
1, 1, 1, 1, 1, 1, 1, 1, # e8 - ef
|
| 63 |
+
1, 1, 1, 1, 1, 1, 1, 1, # f0 - f7
|
| 64 |
+
1, 1, 1, 1, 1, 1, 1, 1, # f8 - ff
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
HZ_ST = (
|
| 68 |
+
MachineState.START, MachineState.ERROR, 3, MachineState.START, MachineState.START, MachineState.START, MachineState.ERROR, MachineState.ERROR, # 00-07
|
| 69 |
+
MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ITS_ME, MachineState.ITS_ME, MachineState.ITS_ME, MachineState.ITS_ME, # 08-0f
|
| 70 |
+
MachineState.ITS_ME, MachineState.ITS_ME, MachineState.ERROR, MachineState.ERROR, MachineState.START, MachineState.START, 4, MachineState.ERROR, # 10-17
|
| 71 |
+
5, MachineState.ERROR, 6, MachineState.ERROR, 5, 5, 4, MachineState.ERROR, # 18-1f
|
| 72 |
+
4, MachineState.ERROR, 4, 4, 4, MachineState.ERROR, 4, MachineState.ERROR, # 20-27
|
| 73 |
+
4, MachineState.ITS_ME, MachineState.START, MachineState.START, MachineState.START, MachineState.START, MachineState.START, MachineState.START, # 28-2f
|
| 74 |
+
)
|
| 75 |
+
# fmt: on
|
| 76 |
+
|
| 77 |
+
HZ_CHAR_LEN_TABLE = (0, 0, 0, 0, 0, 0)
|
| 78 |
+
|
| 79 |
+
HZ_SM_MODEL: CodingStateMachineDict = {
|
| 80 |
+
"class_table": HZ_CLS,
|
| 81 |
+
"class_factor": 6,
|
| 82 |
+
"state_table": HZ_ST,
|
| 83 |
+
"char_len_table": HZ_CHAR_LEN_TABLE,
|
| 84 |
+
"name": "HZ-GB-2312",
|
| 85 |
+
"language": "Chinese",
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
# fmt: off
|
| 89 |
+
ISO2022CN_CLS = (
|
| 90 |
+
2, 0, 0, 0, 0, 0, 0, 0, # 00 - 07
|
| 91 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 08 - 0f
|
| 92 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 10 - 17
|
| 93 |
+
0, 0, 0, 1, 0, 0, 0, 0, # 18 - 1f
|
| 94 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 20 - 27
|
| 95 |
+
0, 3, 0, 0, 0, 0, 0, 0, # 28 - 2f
|
| 96 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 30 - 37
|
| 97 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 38 - 3f
|
| 98 |
+
0, 0, 0, 4, 0, 0, 0, 0, # 40 - 47
|
| 99 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 48 - 4f
|
| 100 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 50 - 57
|
| 101 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 58 - 5f
|
| 102 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 60 - 67
|
| 103 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 68 - 6f
|
| 104 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 70 - 77
|
| 105 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 78 - 7f
|
| 106 |
+
2, 2, 2, 2, 2, 2, 2, 2, # 80 - 87
|
| 107 |
+
2, 2, 2, 2, 2, 2, 2, 2, # 88 - 8f
|
| 108 |
+
2, 2, 2, 2, 2, 2, 2, 2, # 90 - 97
|
| 109 |
+
2, 2, 2, 2, 2, 2, 2, 2, # 98 - 9f
|
| 110 |
+
2, 2, 2, 2, 2, 2, 2, 2, # a0 - a7
|
| 111 |
+
2, 2, 2, 2, 2, 2, 2, 2, # a8 - af
|
| 112 |
+
2, 2, 2, 2, 2, 2, 2, 2, # b0 - b7
|
| 113 |
+
2, 2, 2, 2, 2, 2, 2, 2, # b8 - bf
|
| 114 |
+
2, 2, 2, 2, 2, 2, 2, 2, # c0 - c7
|
| 115 |
+
2, 2, 2, 2, 2, 2, 2, 2, # c8 - cf
|
| 116 |
+
2, 2, 2, 2, 2, 2, 2, 2, # d0 - d7
|
| 117 |
+
2, 2, 2, 2, 2, 2, 2, 2, # d8 - df
|
| 118 |
+
2, 2, 2, 2, 2, 2, 2, 2, # e0 - e7
|
| 119 |
+
2, 2, 2, 2, 2, 2, 2, 2, # e8 - ef
|
| 120 |
+
2, 2, 2, 2, 2, 2, 2, 2, # f0 - f7
|
| 121 |
+
2, 2, 2, 2, 2, 2, 2, 2, # f8 - ff
|
| 122 |
+
)
|
| 123 |
+
|
| 124 |
+
ISO2022CN_ST = (
|
| 125 |
+
MachineState.START, 3, MachineState.ERROR, MachineState.START, MachineState.START, MachineState.START, MachineState.START, MachineState.START, # 00-07
|
| 126 |
+
MachineState.START, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, # 08-0f
|
| 127 |
+
MachineState.ERROR, MachineState.ERROR, MachineState.ITS_ME, MachineState.ITS_ME, MachineState.ITS_ME, MachineState.ITS_ME, MachineState.ITS_ME, MachineState.ITS_ME, # 10-17
|
| 128 |
+
MachineState.ITS_ME, MachineState.ITS_ME, MachineState.ITS_ME, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, 4, MachineState.ERROR, # 18-1f
|
| 129 |
+
MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ITS_ME, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, # 20-27
|
| 130 |
+
5, 6, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, # 28-2f
|
| 131 |
+
MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ITS_ME, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, # 30-37
|
| 132 |
+
MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ITS_ME, MachineState.ERROR, MachineState.START, # 38-3f
|
| 133 |
+
)
|
| 134 |
+
# fmt: on
|
| 135 |
+
|
| 136 |
+
ISO2022CN_CHAR_LEN_TABLE = (0, 0, 0, 0, 0, 0, 0, 0, 0)
|
| 137 |
+
|
| 138 |
+
ISO2022CN_SM_MODEL: CodingStateMachineDict = {
|
| 139 |
+
"class_table": ISO2022CN_CLS,
|
| 140 |
+
"class_factor": 9,
|
| 141 |
+
"state_table": ISO2022CN_ST,
|
| 142 |
+
"char_len_table": ISO2022CN_CHAR_LEN_TABLE,
|
| 143 |
+
"name": "ISO-2022-CN",
|
| 144 |
+
"language": "Chinese",
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
# fmt: off
|
| 148 |
+
ISO2022JP_CLS = (
|
| 149 |
+
2, 0, 0, 0, 0, 0, 0, 0, # 00 - 07
|
| 150 |
+
0, 0, 0, 0, 0, 0, 2, 2, # 08 - 0f
|
| 151 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 10 - 17
|
| 152 |
+
0, 0, 0, 1, 0, 0, 0, 0, # 18 - 1f
|
| 153 |
+
0, 0, 0, 0, 7, 0, 0, 0, # 20 - 27
|
| 154 |
+
3, 0, 0, 0, 0, 0, 0, 0, # 28 - 2f
|
| 155 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 30 - 37
|
| 156 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 38 - 3f
|
| 157 |
+
6, 0, 4, 0, 8, 0, 0, 0, # 40 - 47
|
| 158 |
+
0, 9, 5, 0, 0, 0, 0, 0, # 48 - 4f
|
| 159 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 50 - 57
|
| 160 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 58 - 5f
|
| 161 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 60 - 67
|
| 162 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 68 - 6f
|
| 163 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 70 - 77
|
| 164 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 78 - 7f
|
| 165 |
+
2, 2, 2, 2, 2, 2, 2, 2, # 80 - 87
|
| 166 |
+
2, 2, 2, 2, 2, 2, 2, 2, # 88 - 8f
|
| 167 |
+
2, 2, 2, 2, 2, 2, 2, 2, # 90 - 97
|
| 168 |
+
2, 2, 2, 2, 2, 2, 2, 2, # 98 - 9f
|
| 169 |
+
2, 2, 2, 2, 2, 2, 2, 2, # a0 - a7
|
| 170 |
+
2, 2, 2, 2, 2, 2, 2, 2, # a8 - af
|
| 171 |
+
2, 2, 2, 2, 2, 2, 2, 2, # b0 - b7
|
| 172 |
+
2, 2, 2, 2, 2, 2, 2, 2, # b8 - bf
|
| 173 |
+
2, 2, 2, 2, 2, 2, 2, 2, # c0 - c7
|
| 174 |
+
2, 2, 2, 2, 2, 2, 2, 2, # c8 - cf
|
| 175 |
+
2, 2, 2, 2, 2, 2, 2, 2, # d0 - d7
|
| 176 |
+
2, 2, 2, 2, 2, 2, 2, 2, # d8 - df
|
| 177 |
+
2, 2, 2, 2, 2, 2, 2, 2, # e0 - e7
|
| 178 |
+
2, 2, 2, 2, 2, 2, 2, 2, # e8 - ef
|
| 179 |
+
2, 2, 2, 2, 2, 2, 2, 2, # f0 - f7
|
| 180 |
+
2, 2, 2, 2, 2, 2, 2, 2, # f8 - ff
|
| 181 |
+
)
|
| 182 |
+
|
| 183 |
+
ISO2022JP_ST = (
|
| 184 |
+
MachineState.START, 3, MachineState.ERROR, MachineState.START, MachineState.START, MachineState.START, MachineState.START, MachineState.START, # 00-07
|
| 185 |
+
MachineState.START, MachineState.START, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, # 08-0f
|
| 186 |
+
MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ITS_ME, MachineState.ITS_ME, MachineState.ITS_ME, MachineState.ITS_ME, # 10-17
|
| 187 |
+
MachineState.ITS_ME, MachineState.ITS_ME, MachineState.ITS_ME, MachineState.ITS_ME, MachineState.ITS_ME, MachineState.ITS_ME, MachineState.ERROR, MachineState.ERROR, # 18-1f
|
| 188 |
+
MachineState.ERROR, 5, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, 4, MachineState.ERROR, MachineState.ERROR, # 20-27
|
| 189 |
+
MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, 6, MachineState.ITS_ME, MachineState.ERROR, MachineState.ITS_ME, MachineState.ERROR, # 28-2f
|
| 190 |
+
MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ITS_ME, MachineState.ITS_ME, # 30-37
|
| 191 |
+
MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ITS_ME, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, # 38-3f
|
| 192 |
+
MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ITS_ME, MachineState.ERROR, MachineState.START, MachineState.START, # 40-47
|
| 193 |
+
)
|
| 194 |
+
# fmt: on
|
| 195 |
+
|
| 196 |
+
ISO2022JP_CHAR_LEN_TABLE = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
|
| 197 |
+
|
| 198 |
+
ISO2022JP_SM_MODEL: CodingStateMachineDict = {
|
| 199 |
+
"class_table": ISO2022JP_CLS,
|
| 200 |
+
"class_factor": 10,
|
| 201 |
+
"state_table": ISO2022JP_ST,
|
| 202 |
+
"char_len_table": ISO2022JP_CHAR_LEN_TABLE,
|
| 203 |
+
"name": "ISO-2022-JP",
|
| 204 |
+
"language": "Japanese",
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
# fmt: off
|
| 208 |
+
ISO2022KR_CLS = (
|
| 209 |
+
2, 0, 0, 0, 0, 0, 0, 0, # 00 - 07
|
| 210 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 08 - 0f
|
| 211 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 10 - 17
|
| 212 |
+
0, 0, 0, 1, 0, 0, 0, 0, # 18 - 1f
|
| 213 |
+
0, 0, 0, 0, 3, 0, 0, 0, # 20 - 27
|
| 214 |
+
0, 4, 0, 0, 0, 0, 0, 0, # 28 - 2f
|
| 215 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 30 - 37
|
| 216 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 38 - 3f
|
| 217 |
+
0, 0, 0, 5, 0, 0, 0, 0, # 40 - 47
|
| 218 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 48 - 4f
|
| 219 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 50 - 57
|
| 220 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 58 - 5f
|
| 221 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 60 - 67
|
| 222 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 68 - 6f
|
| 223 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 70 - 77
|
| 224 |
+
0, 0, 0, 0, 0, 0, 0, 0, # 78 - 7f
|
| 225 |
+
2, 2, 2, 2, 2, 2, 2, 2, # 80 - 87
|
| 226 |
+
2, 2, 2, 2, 2, 2, 2, 2, # 88 - 8f
|
| 227 |
+
2, 2, 2, 2, 2, 2, 2, 2, # 90 - 97
|
| 228 |
+
2, 2, 2, 2, 2, 2, 2, 2, # 98 - 9f
|
| 229 |
+
2, 2, 2, 2, 2, 2, 2, 2, # a0 - a7
|
| 230 |
+
2, 2, 2, 2, 2, 2, 2, 2, # a8 - af
|
| 231 |
+
2, 2, 2, 2, 2, 2, 2, 2, # b0 - b7
|
| 232 |
+
2, 2, 2, 2, 2, 2, 2, 2, # b8 - bf
|
| 233 |
+
2, 2, 2, 2, 2, 2, 2, 2, # c0 - c7
|
| 234 |
+
2, 2, 2, 2, 2, 2, 2, 2, # c8 - cf
|
| 235 |
+
2, 2, 2, 2, 2, 2, 2, 2, # d0 - d7
|
| 236 |
+
2, 2, 2, 2, 2, 2, 2, 2, # d8 - df
|
| 237 |
+
2, 2, 2, 2, 2, 2, 2, 2, # e0 - e7
|
| 238 |
+
2, 2, 2, 2, 2, 2, 2, 2, # e8 - ef
|
| 239 |
+
2, 2, 2, 2, 2, 2, 2, 2, # f0 - f7
|
| 240 |
+
2, 2, 2, 2, 2, 2, 2, 2, # f8 - ff
|
| 241 |
+
)
|
| 242 |
+
|
| 243 |
+
ISO2022KR_ST = (
|
| 244 |
+
MachineState.START, 3, MachineState.ERROR, MachineState.START, MachineState.START, MachineState.START, MachineState.ERROR, MachineState.ERROR, # 00-07
|
| 245 |
+
MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ITS_ME, MachineState.ITS_ME, MachineState.ITS_ME, MachineState.ITS_ME, # 08-0f
|
| 246 |
+
MachineState.ITS_ME, MachineState.ITS_ME, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, 4, MachineState.ERROR, MachineState.ERROR, # 10-17
|
| 247 |
+
MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, 5, MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, # 18-1f
|
| 248 |
+
MachineState.ERROR, MachineState.ERROR, MachineState.ERROR, MachineState.ITS_ME, MachineState.START, MachineState.START, MachineState.START, MachineState.START, # 20-27
|
| 249 |
+
)
|
| 250 |
+
# fmt: on
|
| 251 |
+
|
| 252 |
+
ISO2022KR_CHAR_LEN_TABLE = (0, 0, 0, 0, 0, 0)
|
| 253 |
+
|
| 254 |
+
ISO2022KR_SM_MODEL: CodingStateMachineDict = {
|
| 255 |
+
"class_table": ISO2022KR_CLS,
|
| 256 |
+
"class_factor": 6,
|
| 257 |
+
"state_table": ISO2022KR_ST,
|
| 258 |
+
"char_len_table": ISO2022KR_CHAR_LEN_TABLE,
|
| 259 |
+
"name": "ISO-2022-KR",
|
| 260 |
+
"language": "Korean",
|
| 261 |
+
}
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/eucjpprober.py
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
######################## BEGIN LICENSE BLOCK ########################
|
| 2 |
+
# The Original Code is mozilla.org code.
|
| 3 |
+
#
|
| 4 |
+
# The Initial Developer of the Original Code is
|
| 5 |
+
# Netscape Communications Corporation.
|
| 6 |
+
# Portions created by the Initial Developer are Copyright (C) 1998
|
| 7 |
+
# the Initial Developer. All Rights Reserved.
|
| 8 |
+
#
|
| 9 |
+
# Contributor(s):
|
| 10 |
+
# Mark Pilgrim - port to Python
|
| 11 |
+
#
|
| 12 |
+
# This library is free software; you can redistribute it and/or
|
| 13 |
+
# modify it under the terms of the GNU Lesser General Public
|
| 14 |
+
# License as published by the Free Software Foundation; either
|
| 15 |
+
# version 2.1 of the License, or (at your option) any later version.
|
| 16 |
+
#
|
| 17 |
+
# This library is distributed in the hope that it will be useful,
|
| 18 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 19 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 20 |
+
# Lesser General Public License for more details.
|
| 21 |
+
#
|
| 22 |
+
# You should have received a copy of the GNU Lesser General Public
|
| 23 |
+
# License along with this library; if not, write to the Free Software
|
| 24 |
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
| 25 |
+
# 02110-1301 USA
|
| 26 |
+
######################### END LICENSE BLOCK #########################
|
| 27 |
+
|
| 28 |
+
from typing import Union
|
| 29 |
+
|
| 30 |
+
from .chardistribution import EUCJPDistributionAnalysis
|
| 31 |
+
from .codingstatemachine import CodingStateMachine
|
| 32 |
+
from .enums import MachineState, ProbingState
|
| 33 |
+
from .jpcntx import EUCJPContextAnalysis
|
| 34 |
+
from .mbcharsetprober import MultiByteCharSetProber
|
| 35 |
+
from .mbcssm import EUCJP_SM_MODEL
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
class EUCJPProber(MultiByteCharSetProber):
|
| 39 |
+
def __init__(self) -> None:
|
| 40 |
+
super().__init__()
|
| 41 |
+
self.coding_sm = CodingStateMachine(EUCJP_SM_MODEL)
|
| 42 |
+
self.distribution_analyzer = EUCJPDistributionAnalysis()
|
| 43 |
+
self.context_analyzer = EUCJPContextAnalysis()
|
| 44 |
+
self.reset()
|
| 45 |
+
|
| 46 |
+
def reset(self) -> None:
|
| 47 |
+
super().reset()
|
| 48 |
+
self.context_analyzer.reset()
|
| 49 |
+
|
| 50 |
+
@property
|
| 51 |
+
def charset_name(self) -> str:
|
| 52 |
+
return "EUC-JP"
|
| 53 |
+
|
| 54 |
+
@property
|
| 55 |
+
def language(self) -> str:
|
| 56 |
+
return "Japanese"
|
| 57 |
+
|
| 58 |
+
def feed(self, byte_str: Union[bytes, bytearray]) -> ProbingState:
|
| 59 |
+
assert self.coding_sm is not None
|
| 60 |
+
assert self.distribution_analyzer is not None
|
| 61 |
+
|
| 62 |
+
for i, byte in enumerate(byte_str):
|
| 63 |
+
# PY3K: byte_str is a byte array, so byte is an int, not a byte
|
| 64 |
+
coding_state = self.coding_sm.next_state(byte)
|
| 65 |
+
if coding_state == MachineState.ERROR:
|
| 66 |
+
self.logger.debug(
|
| 67 |
+
"%s %s prober hit error at byte %s",
|
| 68 |
+
self.charset_name,
|
| 69 |
+
self.language,
|
| 70 |
+
i,
|
| 71 |
+
)
|
| 72 |
+
self._state = ProbingState.NOT_ME
|
| 73 |
+
break
|
| 74 |
+
if coding_state == MachineState.ITS_ME:
|
| 75 |
+
self._state = ProbingState.FOUND_IT
|
| 76 |
+
break
|
| 77 |
+
if coding_state == MachineState.START:
|
| 78 |
+
char_len = self.coding_sm.get_current_charlen()
|
| 79 |
+
if i == 0:
|
| 80 |
+
self._last_char[1] = byte
|
| 81 |
+
self.context_analyzer.feed(self._last_char, char_len)
|
| 82 |
+
self.distribution_analyzer.feed(self._last_char, char_len)
|
| 83 |
+
else:
|
| 84 |
+
self.context_analyzer.feed(byte_str[i - 1 : i + 1], char_len)
|
| 85 |
+
self.distribution_analyzer.feed(byte_str[i - 1 : i + 1], char_len)
|
| 86 |
+
|
| 87 |
+
self._last_char[0] = byte_str[-1]
|
| 88 |
+
|
| 89 |
+
if self.state == ProbingState.DETECTING:
|
| 90 |
+
if self.context_analyzer.got_enough_data() and (
|
| 91 |
+
self.get_confidence() > self.SHORTCUT_THRESHOLD
|
| 92 |
+
):
|
| 93 |
+
self._state = ProbingState.FOUND_IT
|
| 94 |
+
|
| 95 |
+
return self.state
|
| 96 |
+
|
| 97 |
+
def get_confidence(self) -> float:
|
| 98 |
+
assert self.distribution_analyzer is not None
|
| 99 |
+
|
| 100 |
+
context_conf = self.context_analyzer.get_confidence()
|
| 101 |
+
distrib_con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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
######################## BEGIN LICENSE BLOCK ########################
|
| 2 |
+
# The Original Code is Mozilla Communicator client code.
|
| 3 |
+
#
|
| 4 |
+
# The Initial Developer of the Original Code is
|
| 5 |
+
# Netscape Communications Corporation.
|
| 6 |
+
# Portions created by the Initial Developer are Copyright (C) 1998
|
| 7 |
+
# the Initial Developer. All Rights Reserved.
|
| 8 |
+
#
|
| 9 |
+
# Contributor(s):
|
| 10 |
+
# Mark Pilgrim - port to Python
|
| 11 |
+
#
|
| 12 |
+
# This library is free software; you can redistribute it and/or
|
| 13 |
+
# modify it under the terms of the GNU Lesser General Public
|
| 14 |
+
# License as published by the Free Software Foundation; either
|
| 15 |
+
# version 2.1 of the License, or (at your option) any later version.
|
| 16 |
+
#
|
| 17 |
+
# This library is distributed in the hope that it will be useful,
|
| 18 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 19 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 20 |
+
# Lesser General Public License for more details.
|
| 21 |
+
#
|
| 22 |
+
# You should have received a copy of the GNU Lesser General Public
|
| 23 |
+
# License along with this library; if not, write to the Free Software
|
| 24 |
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
| 25 |
+
# 02110-1301 USA
|
| 26 |
+
######################### END LICENSE BLOCK #########################
|
| 27 |
+
|
| 28 |
+
# Sampling from about 20M text materials include literature and computer technology
|
| 29 |
+
|
| 30 |
+
# 128 --> 0.79
|
| 31 |
+
# 256 --> 0.92
|
| 32 |
+
# 512 --> 0.986
|
| 33 |
+
# 1024 --> 0.99944
|
| 34 |
+
# 2048 --> 0.99999
|
| 35 |
+
#
|
| 36 |
+
# Idea Distribution Ratio = 0.98653 / (1-0.98653) = 73.24
|
| 37 |
+
# Random Distribution Ration = 512 / (2350-512) = 0.279.
|
| 38 |
+
#
|
| 39 |
+
# Typical Distribution Ratio
|
| 40 |
+
|
| 41 |
+
EUCKR_TYPICAL_DISTRIBUTION_RATIO = 6.0
|
| 42 |
+
|
| 43 |
+
EUCKR_TABLE_SIZE = 2352
|
| 44 |
+
|
| 45 |
+
# Char to FreqOrder table ,
|
| 46 |
+
# fmt: off
|
| 47 |
+
EUCKR_CHAR_TO_FREQ_ORDER = (
|
| 48 |
+
13, 130, 120,1396, 481,1719,1720, 328, 609, 212,1721, 707, 400, 299,1722, 87,
|
| 49 |
+
1397,1723, 104, 536,1117,1203,1724,1267, 685,1268, 508,1725,1726,1727,1728,1398,
|
| 50 |
+
1399,1729,1730,1731, 141, 621, 326,1057, 368,1732, 267, 488, 20,1733,1269,1734,
|
| 51 |
+
945,1400,1735, 47, 904,1270,1736,1737, 773, 248,1738, 409, 313, 786, 429,1739,
|
| 52 |
+
116, 987, 813,1401, 683, 75,1204, 145,1740,1741,1742,1743, 16, 847, 667, 622,
|
| 53 |
+
708,1744,1745,1746, 966, 787, 304, 129,1747, 60, 820, 123, 676,1748,1749,1750,
|
| 54 |
+
1751, 617,1752, 626,1753,1754,1755,1756, 653,1757,1758,1759,1760,1761,1762, 856,
|
| 55 |
+
344,1763,1764,1765,1766, 89, 401, 418, 806, 905, 848,1767,1768,1769, 946,1205,
|
| 56 |
+
709,1770,1118,1771, 241,1772,1773,1774,1271,1775, 569,1776, 999,1777,1778,1779,
|
| 57 |
+
1780, 337, 751,1058, 28, 628, 254,1781, 177, 906, 270, 349, 891,1079,1782, 19,
|
| 58 |
+
1783, 379,1784, 315,1785, 629, 754,1402, 559,1786, 636, 203,1206,1787, 710, 567,
|
| 59 |
+
1788, 935, 814,1789,1790,1207, 766, 528,1791,1792,1208,1793,1794,1795,1796,1797,
|
| 60 |
+
1403,1798,1799, 533,1059,1404,1405,1156,1406, 936, 884,1080,1800, 351,1801,1802,
|
| 61 |
+
1803,1804,1805, 801,1806,1807,1808,1119,1809,1157, 714, 474,1407,1810, 298, 899,
|
| 62 |
+
885,1811,1120, 802,1158,1812, 892,1813,1814,1408, 659,1815,1816,1121,1817,1818,
|
| 63 |
+
1819,1820,1821,1822, 319,1823, 594, 545,1824, 815, 937,1209,1825,1826, 573,1409,
|
| 64 |
+
1022,1827,1210,1828,1829,1830,1831,1832,1833, 556, 722, 807,1122,1060,1834, 697,
|
| 65 |
+
1835, 900, 557, 715,1836,1410, 540,1411, 752,1159, 294, 597,1211, 976, 803, 770,
|
| 66 |
+
1412,1837,1838, 39, 794,1413, 358,1839, 371, 925,1840, 453, 661, 788, 531, 723,
|
| 67 |
+
544,1023,1081, 869, 91,1841, 392, 430, 790, 602,1414, 677,1082, 457,1415,1416,
|
| 68 |
+
1842,1843, 475, 327,1024,1417, 795, 121,1844, 733, 403,1418,1845,1846,1847, 300,
|
| 69 |
+
119, 711,1212, 627,1848,1272, 207,1849,1850, 796,1213, 382,1851, 519,1852,1083,
|
| 70 |
+
893,1853,1854,1855, 367, 809, 487, 671,1856, 663,1857,1858, 956, 471, 306, 857,
|
| 71 |
+
1859,1860,1160,1084,1861,1862,1863,1864,1865,1061,1866,1867,1868,1869,1870,1871,
|
| 72 |
+
282, 96, 574,1872, 502,1085,1873,1214,1874, 907,1875,1876, 827, 977,1419,1420,
|
| 73 |
+
1421, 268,1877,1422,1878,1879,1880, 308,1881, 2, 537,1882,1883,1215,1884,1885,
|
| 74 |
+
127, 791,1886,1273,1423,1887, 34, 336, 404, 643,1888, 571, 654, 894, 840,1889,
|
| 75 |
+
0, 886,1274, 122, 575, 260, 908, 938,1890,1275, 410, 316,1891,1892, 100,1893,
|
| 76 |
+
1894,1123, 48,1161,1124,1025,1895, 633, 901,1276,1896,1897, 115, 816,1898, 317,
|
| 77 |
+
1899, 694,1900, 909, 734,1424, 572, 866,1425, 691, 85, 524,1010, 543, 394, 841,
|
| 78 |
+
1901,1902,1903,1026,1904,1905,1906,1907,1908,1909, 30, 451, 651, 988, 310,1910,
|
| 79 |
+
1911,1426, 810,1216, 93,1912,1913,1277,1217,1914, 858, 759, 45, 58, 181, 610,
|
| 80 |
+
269,1915,1916, 131,1062, 551, 443,1000, 821,1427, 957, 895,1086,1917,1918, 375,
|
| 81 |
+
1919, 359,1920, 687,1921, 822,1922, 293,1923,1924, 40, 662, 118, 692, 29, 939,
|
| 82 |
+
887, 640, 482, 174,1925, 69,1162, 728,1428, 910,1926,1278,1218,1279, 386, 870,
|
| 83 |
+
217, 854,1163, 823,1927,1928,1929,1930, 834,1931, 78,1932, 859,1933,1063,1934,
|
| 84 |
+
1935,1936,1937, 438,1164, 208, 595,1938,1939,1940,1941,1219,1125,1942, 280, 888,
|
| 85 |
+
1429,1430,1220,1431,1943,1944,1945,1946,1947,1280, 150, 510,1432,1948,1949,1950,
|
| 86 |
+
1951,1952,1953,1954,1011,1087,1955,1433,1043,1956, 881,1957, 614, 958,1064,1065,
|
| 87 |
+
1221,1958, 638,1001, 860, 967, 896,1434, 989, 492, 553,1281,1165,1959,1282,1002,
|
| 88 |
+
1283,1222,1960,1961,1962,1963, 36, 383, 228, 753, 247, 454,1964, 876, 678,1965,
|
| 89 |
+
1966,1284, 126, 464, 490, 835, 136, 672, 529, 940,1088,1435, 473,1967,1968, 467,
|
| 90 |
+
50, 390, 227, 587, 279, 378, 598, 792, 968, 240, 151, 160, 849, 882,1126,1285,
|
| 91 |
+
639,1044, 133, 140, 288, 360, 811, 563,1027, 561, 142, 523,1969,1970,1971, 7,
|
| 92 |
+
103, 296, 439, 407, 506, 634, 990,1972,1973,1974,1975, 645,1976,1977,1978,1979,
|
| 93 |
+
1980,1981, 236,1982,1436,1983,1984,1089, 192, 828, 618, 518,1166, 333,1127,1985,
|
| 94 |
+
818,1223,1986,1987,1988,1989,1990,1991,1992,1993, 342,1128,1286, 746, 842,1994,
|
| 95 |
+
1995, 560, 223,1287, 98, 8, 189, 650, 978,1288,1996,1437,1997, 17, 345, 250,
|
| 96 |
+
423, 277, 234, 512, 226, 97, 289, 42, 167,1998, 201,1999,2000, 843, 836, 824,
|
| 97 |
+
532, 338, 783,1090, 182, 576, 436,1438,1439, 527, 500,2001, 947, 889,2002,2003,
|
| 98 |
+
2004,2005, 262, 600, 314, 447,2006, 547,2007, 693, 738,1129,2008, 71,1440, 745,
|
| 99 |
+
619, 688,2009, 829,2010,2011, 147,2012, 33, 948,2013,2014, 74, 224,2015, 61,
|
| 100 |
+
191, 918, 399, 637,2016,1028,1130, 257, 902,2017,2018,2019,2020,2021,2022,2023,
|
| 101 |
+
2024,2025,2026, 837,2027,2028,2029,2030, 179, 874, 591, 52, 724, 246,2031,2032,
|
| 102 |
+
2033,2034,1167, 969,2035,1289, 630, 605, 911,1091,1168,2036,2037,2038,1441, 912,
|
| 103 |
+
2039, 623,2040,2041, 253,1169,1290,2042,1442, 146, 620, 611, 577, 433,2043,1224,
|
| 104 |
+
719,1170, 959, 440, 437, 534, 84, 388, 480,1131, 159, 220, 198, 679,2044,1012,
|
| 105 |
+
819,1066,1443, 113,1225, 194, 318,1003,1029,2045,2046,2047,2048,1067,2049,2050,
|
| 106 |
+
2051,2052,2053, 59, 913, 112,2054, 632,2055, 455, 144, 739,1291,2056, 273, 681,
|
| 107 |
+
499,2057, 448,2058,2059, 760,2060,2061, 970, 384, 169, 245,1132,2062,2063, 414,
|
| 108 |
+
1444,2064,2065, 41, 235,2066, 157, 252, 877, 568, 919, 789, 580,2067, 725,2068,
|
| 109 |
+
2069,1292,2070,2071,1445,2072,1446,2073,2074, 55, 588, 66,1447, 271,1092,2075,
|
| 110 |
+
1226,2076, 960,1013, 372,2077,2078,2079,2080,2081,1293,2082,2083,2084,2085, 850,
|
| 111 |
+
2086,2087,2088,2089,2090, 186,2091,1068, 180,2092,2093,2094, 109,1227, 522, 606,
|
| 112 |
+
2095, 867,1448,1093, 991,1171, 926, 353,1133,2096, 581,2097,2098,2099,1294,1449,
|
| 113 |
+
1450,2100, 596,1172,1014,1228,2101,1451,1295,1173,1229,2102,2103,1296,1134,1452,
|
| 114 |
+
949,1135,2104,2105,1094,1453,1454,1455,2106,1095,2107,2108,2109,2110,2111,2112,
|
| 115 |
+
2113,2114,2115,2116,2117, 804,2118,2119,1230,1231, 805,1456, 405,1136,2120,2121,
|
| 116 |
+
2122,2123,2124, 720, 701,1297, 992,1457, 927,1004,2125,2126,2127,2128,2129,2130,
|
| 117 |
+
22, 417,2131, 303,2132, 385,2133, 971, 520, 513,2134,1174, 73,1096, 231, 274,
|
| 118 |
+
962,1458, 673,2135,1459,2136, 152,1137,2137,2138,2139,2140,1005,1138,1460,1139,
|
| 119 |
+
2141,2142,2143,2144, 11, 374, 844,2145, 154,1232, 46,1461,2146, 838, 830, 721,
|
| 120 |
+
1233, 106,2147, 90, 428, 462, 578, 566,1175, 352,2148,2149, 538,1234, 124,1298,
|
| 121 |
+
2150,1462, 761, 565,2151, 686,2152, 649,2153, 72, 173,2154, 460, 415,2155,1463,
|
| 122 |
+
2156,1235, 305,2157,2158,2159,2160,2161,2162, 579,2163,2164,2165,2166,2167, 747,
|
| 123 |
+
2168,2169,2170,2171,1464, 669,2172,2173,2174,2175,2176,1465,2177, 23, 530, 285,
|
| 124 |
+
2178, 335, 729,2179, 397,2180,2181,2182,1030,2183,2184, 698,2185,2186, 325,2187,
|
| 125 |
+
2188, 369,2189, 799,1097,1015, 348,2190,1069, 680,2191, 851,1466,2192,2193, 10,
|
| 126 |
+
2194, 613, 424,2195, 979, 108, 449, 589, 27, 172, 81,1031, 80, 774, 281, 350,
|
| 127 |
+
1032, 525, 301, 582,1176,2196, 674,1045,2197,2198,1467, 730, 762,2199,2200,2201,
|
| 128 |
+
2202,1468,2203, 993,2204,2205, 266,1070, 963,1140,2206,2207,2208, 664,1098, 972,
|
| 129 |
+
2209,2210,2211,1177,1469,1470, 871,2212,2213,2214,2215,2216,1471,2217,2218,2219,
|
| 130 |
+
2220,2221,2222,2223,2224,2225,2226,2227,1472,1236,2228,2229,2230,2231,2232,2233,
|
| 131 |
+
2234,2235,1299,2236,2237, 200,2238, 477, 373,2239,2240, 731, 825, 777,2241,2242,
|
| 132 |
+
2243, 521, 486, 548,2244,2245,2246,1473,1300, 53, 549, 137, 875, 76, 158,2247,
|
| 133 |
+
1301,1474, 469, 396,1016, 278, 712,2248, 321, 442, 503, 767, 744, 941,1237,1178,
|
| 134 |
+
1475,2249, 82, 178,1141,1179, 973,2250,1302,2251, 297,2252,2253, 570,2254,2255,
|
| 135 |
+
2256, 18, 450, 206,2257, 290, 292,1142,2258, 511, 162, 99, 346, 164, 735,2259,
|
| 136 |
+
1476,1477, 4, 554, 343, 798,1099,2260,1100,2261, 43, 171,1303, 139, 215,2262,
|
| 137 |
+
2263, 717, 775,2264,1033, 322, 216,2265, 831,2266, 149,2267,1304,2268,2269, 702,
|
| 138 |
+
1238, 135, 845, 347, 309,2270, 484,2271, 878, 655, 238,1006,1478,2272, 67,2273,
|
| 139 |
+
295,2274,2275, 461,2276, 478, 942, 412,2277,1034,2278,2279,2280, 265,2281, 541,
|
| 140 |
+
2282,2283,2284,2285,2286, 70, 852,1071,2287,2288,2289,2290, 21, 56, 509, 117,
|
| 141 |
+
432,2291,2292, 331, 980, 552,1101, 148, 284, 105, 393,1180,1239, 755,2293, 187,
|
| 142 |
+
2294,1046,1479,2295, 340,2296, 63,1047, 230,2297,2298,1305, 763,1306, 101, 800,
|
| 143 |
+
808, 494,2299,2300,2301, 903,2302, 37,1072, 14, 5,2303, 79, 675,2304, 312,
|
| 144 |
+
2305,2306,2307,2308,2309,1480, 6,1307,2310,2311,2312, 1, 470, 35, 24, 229,
|
| 145 |
+
2313, 695, 210, 86, 778, 15, 784, 592, 779, 32, 77, 855, 964,2314, 259,2315,
|
| 146 |
+
501, 380,2316,2317, 83, 981, 153, 689,1308,1481,1482,1483,2318,2319, 716,1484,
|
| 147 |
+
2320,2321,2322,2323,2324,2325,1485,2326,2327, 128, 57, 68, 261,1048, 211, 170,
|
| 148 |
+
1240, 31,2328, 51, 435, 742,2329,2330,2331, 635,2332, 264, 456,2333,2334,2335,
|
| 149 |
+
425,2336,1486, 143, 507, 263, 943,2337, 363, 920,1487, 256,1488,1102, 243, 601,
|
| 150 |
+
1489,2338,2339,2340,2341,2342,2343,2344, 861,2345,2346,2347,2348,2349,2350, 395,
|
| 151 |
+
2351,1490,1491, 62, 535, 166, 225,2352,2353, 668, 419,1241, 138, 604, 928,2354,
|
| 152 |
+
1181,2355,1492,1493,2356,2357,2358,1143,2359, 696,2360, 387, 307,1309, 682, 476,
|
| 153 |
+
2361,2362, 332, 12, 222, 156,2363, 232,2364, 641, 276, 656, 517,1494,1495,1035,
|
| 154 |
+
416, 736,1496,2365,1017, 586,2366,2367,2368,1497,2369, 242,2370,2371,2372,1498,
|
| 155 |
+
2373, 965, 713,2374,2375,2376,2377, 740, 982,1499, 944,1500,1007,2378,2379,1310,
|
| 156 |
+
1501,2380,2381,2382, 785, 329,2383,2384,1502,2385,2386,2387, 932,2388,1503,2389,
|
| 157 |
+
2390,2391,2392,1242,2393,2394,2395,2396,2397, 994, 950,2398,2399,2400,2401,1504,
|
| 158 |
+
1311,2402,2403,2404,2405,1049, 749,2406,2407, 853, 718,1144,1312,2408,1182,1505,
|
| 159 |
+
2409,2410, 255, 516, 479, 564, 550, 214,1506,1507,1313, 413, 239, 444, 339,1145,
|
| 160 |
+
1036,1508,1509,1314,1037,1510,1315,2411,1511,2412,2413,2414, 176, 703, 497, 624,
|
| 161 |
+
593, 921, 302,2415, 341, 165,1103,1512,2416,1513,2417,2418,2419, 376,2420, 700,
|
| 162 |
+
2421,2422,2423, 258, 768,1316,2424,1183,2425, 995, 608,2426,2427,2428,2429, 221,
|
| 163 |
+
2430,2431,2432,2433,2434,2435,2436,2437, 195, 323, 726, 188, 897, 983,1317, 377,
|
| 164 |
+
644,1050, 879,2438, 452,2439,2440,2441,2442,2443,2444, 914,2445,2446,2447,2448,
|
| 165 |
+
915, 489,2449,1514,1184,2450,2451, 515, 64, 427, 495,2452, 583,2453, 483, 485,
|
| 166 |
+
1038, 562, 213,1515, 748, 666,2454,2455,2456,2457, 334,2458, 780, 996,1008, 705,
|
| 167 |
+
1243,2459,2460,2461,2462,2463, 114,2464, 493,1146, 366, 163,1516, 961,1104,2465,
|
| 168 |
+
291,2466,1318,1105,2467,1517, 365,2468, 355, 951,1244,2469,1319,2470, 631,2471,
|
| 169 |
+
2472, 218,1320, 364, 320, 756,1518,1519,1321,1520,1322,2473,2474,2475,2476, 997,
|
| 170 |
+
2477,2478,2479,2480, 665,1185,2481, 916,1521,2482,2483,2484, 584, 684,2485,2486,
|
| 171 |
+
797,2487,1051,1186,2488,2489,2490,1522,2491,2492, 370,2493,1039,1187, 65,2494,
|
| 172 |
+
434, 205, 463,1188,2495, 125, 812, 391, 402, 826, 699, 286, 398, 155, 781, 771,
|
| 173 |
+
585,2496, 590, 505,1073,2497, 599, 244, 219, 917,1018, 952, 646,1523,2498,1323,
|
| 174 |
+
2499,2500, 49, 984, 354, 741,2501, 625,2502,1324,2503,1019, 190, 357, 757, 491,
|
| 175 |
+
95, 782, 868,2504,2505,2506,2507,2508,2509, 134,1524,1074, 422,1525, 898,2510,
|
| 176 |
+
161,2511,2512,2513,2514, 769,2515,1526,2516,2517, 411,1325,2518, 472,1527,2519,
|
| 177 |
+
2520,2521,2522,2523,2524, 985,2525,2526,2527,2528,2529,2530, 764,2531,1245,2532,
|
| 178 |
+
2533, 25, 204, 311,2534, 496,2535,1052,2536,2537,2538,2539,2540,2541,2542, 199,
|
| 179 |
+
704, 504, 468, 758, 657,1528, 196, 44, 839,1246, 272, 750,2543, 765, 862,2544,
|
| 180 |
+
2545,1326,2546, 132, 615, 933,2547, 732,2548,2549,2550,1189,1529,2551, 283,1247,
|
| 181 |
+
1053, 607, 929,2552,2553,2554, 930, 183, 872, 616,1040,1147,2555,1148,1020, 441,
|
| 182 |
+
249,1075,2556,2557,2558, 466, 743,2559,2560,2561, 92, 514, 426, 420, 526,2562,
|
| 183 |
+
2563,2564,2565,2566,2567,2568, 185,2569,2570,2571,2572, 776,1530, 658,2573, 362,
|
| 184 |
+
2574, 361, 922,1076, 793,2575,2576,2577,2578,2579,2580,1531, 251,2581,2582,2583,
|
| 185 |
+
2584,1532, 54, 612, 237,1327,2585,2586, 275, 408, 647, 111,2587,1533,1106, 465,
|
| 186 |
+
3, 458, 9, 38,2588, 107, 110, 890, 209, 26, 737, 498,2589,1534,2590, 431,
|
| 187 |
+
202, 88,1535, 356, 287,1107, 660,1149,2591, 381,1536, 986,1150, 445,1248,1151,
|
| 188 |
+
974,2592,2593, 846,2594, 446, 953, 184,1249,1250, 727,2595, 923, 193, 883,2596,
|
| 189 |
+
2597,2598, 102, 324, 539, 817,2599, 421,1041,2600, 832,2601, 94, 175, 197, 406,
|
| 190 |
+
2602, 459,2603,2604,2605,2606,2607, 330, 555,2608,2609,2610, 706,1108, 389,2611,
|
| 191 |
+
2612,2613,2614, 233,2615, 833, 558, 931, 954,1251,2616,2617,1537, 546,2618,2619,
|
| 192 |
+
1009,2620,2621,2622,1538, 690,1328,2623, 955,2624,1539,2625,2626, 772,2627,2628,
|
| 193 |
+
2629,2630,2631, 924, 648, 863, 603,2632,2633, 934,1540, 864, 865,2634, 642,1042,
|
| 194 |
+
670,1190,2635,2636,2637,2638, 168,2639, 652, 873, 542,1054,1541,2640,2641,2642, # 512, 256
|
| 195 |
+
)
|
| 196 |
+
# fmt: on
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/euckrprober.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
######################## BEGIN LICENSE BLOCK ########################
|
| 2 |
+
# The Original Code is mozilla.org code.
|
| 3 |
+
#
|
| 4 |
+
# The Initial Developer of the Original Code is
|
| 5 |
+
# Netscape Communications Corporation.
|
| 6 |
+
# Portions created by the Initial Developer are Copyright (C) 1998
|
| 7 |
+
# the Initial Developer. All Rights Reserved.
|
| 8 |
+
#
|
| 9 |
+
# Contributor(s):
|
| 10 |
+
# Mark Pilgrim - port to Python
|
| 11 |
+
#
|
| 12 |
+
# This library is free software; you can redistribute it and/or
|
| 13 |
+
# modify it under the terms of the GNU Lesser General Public
|
| 14 |
+
# License as published by the Free Software Foundation; either
|
| 15 |
+
# version 2.1 of the License, or (at your option) any later version.
|
| 16 |
+
#
|
| 17 |
+
# This library is distributed in the hope that it will be useful,
|
| 18 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 19 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 20 |
+
# Lesser General Public License for more details.
|
| 21 |
+
#
|
| 22 |
+
# You should have received a copy of the GNU Lesser General Public
|
| 23 |
+
# License along with this library; if not, write to the Free Software
|
| 24 |
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
| 25 |
+
# 02110-1301 USA
|
| 26 |
+
######################### END LICENSE BLOCK #########################
|
| 27 |
+
|
| 28 |
+
from .chardistribution import EUCKRDistributionAnalysis
|
| 29 |
+
from .codingstatemachine import CodingStateMachine
|
| 30 |
+
from .mbcharsetprober import MultiByteCharSetProber
|
| 31 |
+
from .mbcssm import EUCKR_SM_MODEL
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class EUCKRProber(MultiByteCharSetProber):
|
| 35 |
+
def __init__(self) -> None:
|
| 36 |
+
super().__init__()
|
| 37 |
+
self.coding_sm = CodingStateMachine(EUCKR_SM_MODEL)
|
| 38 |
+
self.distribution_analyzer = EUCKRDistributionAnalysis()
|
| 39 |
+
self.reset()
|
| 40 |
+
|
| 41 |
+
@property
|
| 42 |
+
def charset_name(self) -> str:
|
| 43 |
+
return "EUC-KR"
|
| 44 |
+
|
| 45 |
+
@property
|
| 46 |
+
def language(self) -> str:
|
| 47 |
+
return "Korean"
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/euctwfreq.py
ADDED
|
@@ -0,0 +1,388 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
######################## BEGIN LICENSE BLOCK ########################
|
| 2 |
+
# The Original Code is Mozilla Communicator client code.
|
| 3 |
+
#
|
| 4 |
+
# The Initial Developer of the Original Code is
|
| 5 |
+
# Netscape Communications Corporation.
|
| 6 |
+
# Portions created by the Initial Developer are Copyright (C) 1998
|
| 7 |
+
# the Initial Developer. All Rights Reserved.
|
| 8 |
+
#
|
| 9 |
+
# Contributor(s):
|
| 10 |
+
# Mark Pilgrim - port to Python
|
| 11 |
+
#
|
| 12 |
+
# This library is free software; you can redistribute it and/or
|
| 13 |
+
# modify it under the terms of the GNU Lesser General Public
|
| 14 |
+
# License as published by the Free Software Foundation; either
|
| 15 |
+
# version 2.1 of the License, or (at your option) any later version.
|
| 16 |
+
#
|
| 17 |
+
# This library is distributed in the hope that it will be useful,
|
| 18 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 19 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 20 |
+
# Lesser General Public License for more details.
|
| 21 |
+
#
|
| 22 |
+
# You should have received a copy of the GNU Lesser General Public
|
| 23 |
+
# License along with this library; if not, write to the Free Software
|
| 24 |
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
| 25 |
+
# 02110-1301 USA
|
| 26 |
+
######################### END LICENSE BLOCK #########################
|
| 27 |
+
|
| 28 |
+
# EUCTW frequency table
|
| 29 |
+
# Converted from big5 work
|
| 30 |
+
# by Taiwan's Mandarin Promotion Council
|
| 31 |
+
# <http:#www.edu.tw:81/mandr/>
|
| 32 |
+
|
| 33 |
+
# 128 --> 0.42261
|
| 34 |
+
# 256 --> 0.57851
|
| 35 |
+
# 512 --> 0.74851
|
| 36 |
+
# 1024 --> 0.89384
|
| 37 |
+
# 2048 --> 0.97583
|
| 38 |
+
#
|
| 39 |
+
# Idea Distribution Ratio = 0.74851/(1-0.74851) =2.98
|
| 40 |
+
# Random Distribution Ration = 512/(5401-512)=0.105
|
| 41 |
+
#
|
| 42 |
+
# Typical Distribution Ratio about 25% of Ideal one, still much higher than RDR
|
| 43 |
+
|
| 44 |
+
EUCTW_TYPICAL_DISTRIBUTION_RATIO = 0.75
|
| 45 |
+
|
| 46 |
+
# Char to FreqOrder table
|
| 47 |
+
EUCTW_TABLE_SIZE = 5376
|
| 48 |
+
|
| 49 |
+
# fmt: off
|
| 50 |
+
EUCTW_CHAR_TO_FREQ_ORDER = (
|
| 51 |
+
1, 1800, 1506, 255, 1431, 198, 9, 82, 6, 7310, 177, 202, 3615, 1256, 2808, 110, # 2742
|
| 52 |
+
3735, 33, 3241, 261, 76, 44, 2113, 16, 2931, 2184, 1176, 659, 3868, 26, 3404, 2643, # 2758
|
| 53 |
+
1198, 3869, 3313, 4060, 410, 2211, 302, 590, 361, 1963, 8, 204, 58, 4296, 7311, 1931, # 2774
|
| 54 |
+
63, 7312, 7313, 317, 1614, 75, 222, 159, 4061, 2412, 1480, 7314, 3500, 3068, 224, 2809, # 2790
|
| 55 |
+
3616, 3, 10, 3870, 1471, 29, 2774, 1135, 2852, 1939, 873, 130, 3242, 1123, 312, 7315, # 2806
|
| 56 |
+
4297, 2051, 507, 252, 682, 7316, 142, 1914, 124, 206, 2932, 34, 3501, 3173, 64, 604, # 2822
|
| 57 |
+
7317, 2494, 1976, 1977, 155, 1990, 645, 641, 1606, 7318, 3405, 337, 72, 406, 7319, 80, # 2838
|
| 58 |
+
630, 238, 3174, 1509, 263, 939, 1092, 2644, 756, 1440, 1094, 3406, 449, 69, 2969, 591, # 2854
|
| 59 |
+
179, 2095, 471, 115, 2034, 1843, 60, 50, 2970, 134, 806, 1868, 734, 2035, 3407, 180, # 2870
|
| 60 |
+
995, 1607, 156, 537, 2893, 688, 7320, 319, 1305, 779, 2144, 514, 2374, 298, 4298, 359, # 2886
|
| 61 |
+
2495, 90, 2707, 1338, 663, 11, 906, 1099, 2545, 20, 2436, 182, 532, 1716, 7321, 732, # 2902
|
| 62 |
+
1376, 4062, 1311, 1420, 3175, 25, 2312, 1056, 113, 399, 382, 1949, 242, 3408, 2467, 529, # 2918
|
| 63 |
+
3243, 475, 1447, 3617, 7322, 117, 21, 656, 810, 1297, 2295, 2329, 3502, 7323, 126, 4063, # 2934
|
| 64 |
+
706, 456, 150, 613, 4299, 71, 1118, 2036, 4064, 145, 3069, 85, 835, 486, 2114, 1246, # 2950
|
| 65 |
+
1426, 428, 727, 1285, 1015, 800, 106, 623, 303, 1281, 7324, 2127, 2354, 347, 3736, 221, # 2966
|
| 66 |
+
3503, 3110, 7325, 1955, 1153, 4065, 83, 296, 1199, 3070, 192, 624, 93, 7326, 822, 1897, # 2982
|
| 67 |
+
2810, 3111, 795, 2064, 991, 1554, 1542, 1592, 27, 43, 2853, 859, 139, 1456, 860, 4300, # 2998
|
| 68 |
+
437, 712, 3871, 164, 2392, 3112, 695, 211, 3017, 2096, 195, 3872, 1608, 3504, 3505, 3618, # 3014
|
| 69 |
+
3873, 234, 811, 2971, 2097, 3874, 2229, 1441, 3506, 1615, 2375, 668, 2076, 1638, 305, 228, # 3030
|
| 70 |
+
1664, 4301, 467, 415, 7327, 262, 2098, 1593, 239, 108, 300, 200, 1033, 512, 1247, 2077, # 3046
|
| 71 |
+
7328, 7329, 2173, 3176, 3619, 2673, 593, 845, 1062, 3244, 88, 1723, 2037, 3875, 1950, 212, # 3062
|
| 72 |
+
266, 152, 149, 468, 1898, 4066, 4302, 77, 187, 7330, 3018, 37, 5, 2972, 7331, 3876, # 3078
|
| 73 |
+
7332, 7333, 39, 2517, 4303, 2894, 3177, 2078, 55, 148, 74, 4304, 545, 483, 1474, 1029, # 3094
|
| 74 |
+
1665, 217, 1869, 1531, 3113, 1104, 2645, 4067, 24, 172, 3507, 900, 3877, 3508, 3509, 4305, # 3110
|
| 75 |
+
32, 1408, 2811, 1312, 329, 487, 2355, 2247, 2708, 784, 2674, 4, 3019, 3314, 1427, 1788, # 3126
|
| 76 |
+
188, 109, 499, 7334, 3620, 1717, 1789, 888, 1217, 3020, 4306, 7335, 3510, 7336, 3315, 1520, # 3142
|
| 77 |
+
3621, 3878, 196, 1034, 775, 7337, 7338, 929, 1815, 249, 439, 38, 7339, 1063, 7340, 794, # 3158
|
| 78 |
+
3879, 1435, 2296, 46, 178, 3245, 2065, 7341, 2376, 7342, 214, 1709, 4307, 804, 35, 707, # 3174
|
| 79 |
+
324, 3622, 1601, 2546, 140, 459, 4068, 7343, 7344, 1365, 839, 272, 978, 2257, 2572, 3409, # 3190
|
| 80 |
+
2128, 1363, 3623, 1423, 697, 100, 3071, 48, 70, 1231, 495, 3114, 2193, 7345, 1294, 7346, # 3206
|
| 81 |
+
2079, 462, 586, 1042, 3246, 853, 256, 988, 185, 2377, 3410, 1698, 434, 1084, 7347, 3411, # 3222
|
| 82 |
+
314, 2615, 2775, 4308, 2330, 2331, 569, 2280, 637, 1816, 2518, 757, 1162, 1878, 1616, 3412, # 3238
|
| 83 |
+
287, 1577, 2115, 768, 4309, 1671, 2854, 3511, 2519, 1321, 3737, 909, 2413, 7348, 4069, 933, # 3254
|
| 84 |
+
3738, 7349, 2052, 2356, 1222, 4310, 765, 2414, 1322, 786, 4311, 7350, 1919, 1462, 1677, 2895, # 3270
|
| 85 |
+
1699, 7351, 4312, 1424, 2437, 3115, 3624, 2590, 3316, 1774, 1940, 3413, 3880, 4070, 309, 1369, # 3286
|
| 86 |
+
1130, 2812, 364, 2230, 1653, 1299, 3881, 3512, 3882, 3883, 2646, 525, 1085, 3021, 902, 2000, # 3302
|
| 87 |
+
1475, 964, 4313, 421, 1844, 1415, 1057, 2281, 940, 1364, 3116, 376, 4314, 4315, 1381, 7, # 3318
|
| 88 |
+
2520, 983, 2378, 336, 1710, 2675, 1845, 321, 3414, 559, 1131, 3022, 2742, 1808, 1132, 1313, # 3334
|
| 89 |
+
265, 1481, 1857, 7352, 352, 1203, 2813, 3247, 167, 1089, 420, 2814, 776, 792, 1724, 3513, # 3350
|
| 90 |
+
4071, 2438, 3248, 7353, 4072, 7354, 446, 229, 333, 2743, 901, 3739, 1200, 1557, 4316, 2647, # 3366
|
| 91 |
+
1920, 395, 2744, 2676, 3740, 4073, 1835, 125, 916, 3178, 2616, 4317, 7355, 7356, 3741, 7357, # 3382
|
| 92 |
+
7358, 7359, 4318, 3117, 3625, 1133, 2547, 1757, 3415, 1510, 2313, 1409, 3514, 7360, 2145, 438, # 3398
|
| 93 |
+
2591, 2896, 2379, 3317, 1068, 958, 3023, 461, 311, 2855, 2677, 4074, 1915, 3179, 4075, 1978, # 3414
|
| 94 |
+
383, 750, 2745, 2617, 4076, 274, 539, 385, 1278, 1442, 7361, 1154, 1964, 384, 561, 210, # 3430
|
| 95 |
+
98, 1295, 2548, 3515, 7362, 1711, 2415, 1482, 3416, 3884, 2897, 1257, 129, 7363, 3742, 642, # 3446
|
| 96 |
+
523, 2776, 2777, 2648, 7364, 141, 2231, 1333, 68, 176, 441, 876, 907, 4077, 603, 2592, # 3462
|
| 97 |
+
710, 171, 3417, 404, 549, 18, 3118, 2393, 1410, 3626, 1666, 7365, 3516, 4319, 2898, 4320, # 3478
|
| 98 |
+
7366, 2973, 368, 7367, 146, 366, 99, 871, 3627, 1543, 748, 807, 1586, 1185, 22, 2258, # 3494
|
| 99 |
+
379, 3743, 3180, 7368, 3181, 505, 1941, 2618, 1991, 1382, 2314, 7369, 380, 2357, 218, 702, # 3510
|
| 100 |
+
1817, 1248, 3418, 3024, 3517, 3318, 3249, 7370, 2974, 3628, 930, 3250, 3744, 7371, 59, 7372, # 3526
|
| 101 |
+
585, 601, 4078, 497, 3419, 1112, 1314, 4321, 1801, 7373, 1223, 1472, 2174, 7374, 749, 1836, # 3542
|
| 102 |
+
690, 1899, 3745, 1772, 3885, 1476, 429, 1043, 1790, 2232, 2116, 917, 4079, 447, 1086, 1629, # 3558
|
| 103 |
+
7375, 556, 7376, 7377, 2020, 1654, 844, 1090, 105, 550, 966, 1758, 2815, 1008, 1782, 686, # 3574
|
| 104 |
+
1095, 7378, 2282, 793, 1602, 7379, 3518, 2593, 4322, 4080, 2933, 2297, 4323, 3746, 980, 2496, # 3590
|
| 105 |
+
544, 353, 527, 4324, 908, 2678, 2899, 7380, 381, 2619, 1942, 1348, 7381, 1341, 1252, 560, # 3606
|
| 106 |
+
3072, 7382, 3420, 2856, 7383, 2053, 973, 886, 2080, 143, 4325, 7384, 7385, 157, 3886, 496, # 3622
|
| 107 |
+
4081, 57, 840, 540, 2038, 4326, 4327, 3421, 2117, 1445, 970, 2259, 1748, 1965, 2081, 4082, # 3638
|
| 108 |
+
3119, 1234, 1775, 3251, 2816, 3629, 773, 1206, 2129, 1066, 2039, 1326, 3887, 1738, 1725, 4083, # 3654
|
| 109 |
+
279, 3120, 51, 1544, 2594, 423, 1578, 2130, 2066, 173, 4328, 1879, 7386, 7387, 1583, 264, # 3670
|
| 110 |
+
610, 3630, 4329, 2439, 280, 154, 7388, 7389, 7390, 1739, 338, 1282, 3073, 693, 2857, 1411, # 3686
|
| 111 |
+
1074, 3747, 2440, 7391, 4330, 7392, 7393, 1240, 952, 2394, 7394, 2900, 1538, 2679, 685, 1483, # 3702
|
| 112 |
+
4084, 2468, 1436, 953, 4085, 2054, 4331, 671, 2395, 79, 4086, 2441, 3252, 608, 567, 2680, # 3718
|
| 113 |
+
3422, 4087, 4088, 1691, 393, 1261, 1791, 2396, 7395, 4332, 7396, 7397, 7398, 7399, 1383, 1672, # 3734
|
| 114 |
+
3748, 3182, 1464, 522, 1119, 661, 1150, 216, 675, 4333, 3888, 1432, 3519, 609, 4334, 2681, # 3750
|
| 115 |
+
2397, 7400, 7401, 7402, 4089, 3025, 0, 7403, 2469, 315, 231, 2442, 301, 3319, 4335, 2380, # 3766
|
| 116 |
+
7404, 233, 4090, 3631, 1818, 4336, 4337, 7405, 96, 1776, 1315, 2082, 7406, 257, 7407, 1809, # 3782
|
| 117 |
+
3632, 2709, 1139, 1819, 4091, 2021, 1124, 2163, 2778, 1777, 2649, 7408, 3074, 363, 1655, 3183, # 3798
|
| 118 |
+
7409, 2975, 7410, 7411, 7412, 3889, 1567, 3890, 718, 103, 3184, 849, 1443, 341, 3320, 2934, # 3814
|
| 119 |
+
1484, 7413, 1712, 127, 67, 339, 4092, 2398, 679, 1412, 821, 7414, 7415, 834, 738, 351, # 3830
|
| 120 |
+
2976, 2146, 846, 235, 1497, 1880, 418, 1992, 3749, 2710, 186, 1100, 2147, 2746, 3520, 1545, # 3846
|
| 121 |
+
1355, 2935, 2858, 1377, 583, 3891, 4093, 2573, 2977, 7416, 1298, 3633, 1078, 2549, 3634, 2358, # 3862
|
| 122 |
+
78, 3750, 3751, 267, 1289, 2099, 2001, 1594, 4094, 348, 369, 1274, 2194, 2175, 1837, 4338, # 3878
|
| 123 |
+
1820, 2817, 3635, 2747, 2283, 2002, 4339, 2936, 2748, 144, 3321, 882, 4340, 3892, 2749, 3423, # 3894
|
| 124 |
+
4341, 2901, 7417, 4095, 1726, 320, 7418, 3893, 3026, 788, 2978, 7419, 2818, 1773, 1327, 2859, # 3910
|
| 125 |
+
3894, 2819, 7420, 1306, 4342, 2003, 1700, 3752, 3521, 2359, 2650, 787, 2022, 506, 824, 3636, # 3926
|
| 126 |
+
534, 323, 4343, 1044, 3322, 2023, 1900, 946, 3424, 7421, 1778, 1500, 1678, 7422, 1881, 4344, # 3942
|
| 127 |
+
165, 243, 4345, 3637, 2521, 123, 683, 4096, 764, 4346, 36, 3895, 1792, 589, 2902, 816, # 3958
|
| 128 |
+
626, 1667, 3027, 2233, 1639, 1555, 1622, 3753, 3896, 7423, 3897, 2860, 1370, 1228, 1932, 891, # 3974
|
| 129 |
+
2083, 2903, 304, 4097, 7424, 292, 2979, 2711, 3522, 691, 2100, 4098, 1115, 4347, 118, 662, # 3990
|
| 130 |
+
7425, 611, 1156, 854, 2381, 1316, 2861, 2, 386, 515, 2904, 7426, 7427, 3253, 868, 2234, # 4006
|
| 131 |
+
1486, 855, 2651, 785, 2212, 3028, 7428, 1040, 3185, 3523, 7429, 3121, 448, 7430, 1525, 7431, # 4022
|
| 132 |
+
2164, 4348, 7432, 3754, 7433, 4099, 2820, 3524, 3122, 503, 818, 3898, 3123, 1568, 814, 676, # 4038
|
| 133 |
+
1444, 306, 1749, 7434, 3755, 1416, 1030, 197, 1428, 805, 2821, 1501, 4349, 7435, 7436, 7437, # 4054
|
| 134 |
+
1993, 7438, 4350, 7439, 7440, 2195, 13, 2779, 3638, 2980, 3124, 1229, 1916, 7441, 3756, 2131, # 4070
|
| 135 |
+
7442, 4100, 4351, 2399, 3525, 7443, 2213, 1511, 1727, 1120, 7444, 7445, 646, 3757, 2443, 307, # 4086
|
| 136 |
+
7446, 7447, 1595, 3186, 7448, 7449, 7450, 3639, 1113, 1356, 3899, 1465, 2522, 2523, 7451, 519, # 4102
|
| 137 |
+
7452, 128, 2132, 92, 2284, 1979, 7453, 3900, 1512, 342, 3125, 2196, 7454, 2780, 2214, 1980, # 4118
|
| 138 |
+
3323, 7455, 290, 1656, 1317, 789, 827, 2360, 7456, 3758, 4352, 562, 581, 3901, 7457, 401, # 4134
|
| 139 |
+
4353, 2248, 94, 4354, 1399, 2781, 7458, 1463, 2024, 4355, 3187, 1943, 7459, 828, 1105, 4101, # 4150
|
| 140 |
+
1262, 1394, 7460, 4102, 605, 4356, 7461, 1783, 2862, 7462, 2822, 819, 2101, 578, 2197, 2937, # 4166
|
| 141 |
+
7463, 1502, 436, 3254, 4103, 3255, 2823, 3902, 2905, 3425, 3426, 7464, 2712, 2315, 7465, 7466, # 4182
|
| 142 |
+
2332, 2067, 23, 4357, 193, 826, 3759, 2102, 699, 1630, 4104, 3075, 390, 1793, 1064, 3526, # 4198
|
| 143 |
+
7467, 1579, 3076, 3077, 1400, 7468, 4105, 1838, 1640, 2863, 7469, 4358, 4359, 137, 4106, 598, # 4214
|
| 144 |
+
3078, 1966, 780, 104, 974, 2938, 7470, 278, 899, 253, 402, 572, 504, 493, 1339, 7471, # 4230
|
| 145 |
+
3903, 1275, 4360, 2574, 2550, 7472, 3640, 3029, 3079, 2249, 565, 1334, 2713, 863, 41, 7473, # 4246
|
| 146 |
+
7474, 4361, 7475, 1657, 2333, 19, 463, 2750, 4107, 606, 7476, 2981, 3256, 1087, 2084, 1323, # 4262
|
| 147 |
+
2652, 2982, 7477, 1631, 1623, 1750, 4108, 2682, 7478, 2864, 791, 2714, 2653, 2334, 232, 2416, # 4278
|
| 148 |
+
7479, 2983, 1498, 7480, 2654, 2620, 755, 1366, 3641, 3257, 3126, 2025, 1609, 119, 1917, 3427, # 4294
|
| 149 |
+
862, 1026, 4109, 7481, 3904, 3760, 4362, 3905, 4363, 2260, 1951, 2470, 7482, 1125, 817, 4110, # 4310
|
| 150 |
+
4111, 3906, 1513, 1766, 2040, 1487, 4112, 3030, 3258, 2824, 3761, 3127, 7483, 7484, 1507, 7485, # 4326
|
| 151 |
+
2683, 733, 40, 1632, 1106, 2865, 345, 4113, 841, 2524, 230, 4364, 2984, 1846, 3259, 3428, # 4342
|
| 152 |
+
7486, 1263, 986, 3429, 7487, 735, 879, 254, 1137, 857, 622, 1300, 1180, 1388, 1562, 3907, # 4358
|
| 153 |
+
3908, 2939, 967, 2751, 2655, 1349, 592, 2133, 1692, 3324, 2985, 1994, 4114, 1679, 3909, 1901, # 4374
|
| 154 |
+
2185, 7488, 739, 3642, 2715, 1296, 1290, 7489, 4115, 2198, 2199, 1921, 1563, 2595, 2551, 1870, # 4390
|
| 155 |
+
2752, 2986, 7490, 435, 7491, 343, 1108, 596, 17, 1751, 4365, 2235, 3430, 3643, 7492, 4366, # 4406
|
| 156 |
+
294, 3527, 2940, 1693, 477, 979, 281, 2041, 3528, 643, 2042, 3644, 2621, 2782, 2261, 1031, # 4422
|
| 157 |
+
2335, 2134, 2298, 3529, 4367, 367, 1249, 2552, 7493, 3530, 7494, 4368, 1283, 3325, 2004, 240, # 4438
|
| 158 |
+
1762, 3326, 4369, 4370, 836, 1069, 3128, 474, 7495, 2148, 2525, 268, 3531, 7496, 3188, 1521, # 4454
|
| 159 |
+
1284, 7497, 1658, 1546, 4116, 7498, 3532, 3533, 7499, 4117, 3327, 2684, 1685, 4118, 961, 1673, # 4470
|
| 160 |
+
2622, 190, 2005, 2200, 3762, 4371, 4372, 7500, 570, 2497, 3645, 1490, 7501, 4373, 2623, 3260, # 4486
|
| 161 |
+
1956, 4374, 584, 1514, 396, 1045, 1944, 7502, 4375, 1967, 2444, 7503, 7504, 4376, 3910, 619, # 4502
|
| 162 |
+
7505, 3129, 3261, 215, 2006, 2783, 2553, 3189, 4377, 3190, 4378, 763, 4119, 3763, 4379, 7506, # 4518
|
| 163 |
+
7507, 1957, 1767, 2941, 3328, 3646, 1174, 452, 1477, 4380, 3329, 3130, 7508, 2825, 1253, 2382, # 4534
|
| 164 |
+
2186, 1091, 2285, 4120, 492, 7509, 638, 1169, 1824, 2135, 1752, 3911, 648, 926, 1021, 1324, # 4550
|
| 165 |
+
4381, 520, 4382, 997, 847, 1007, 892, 4383, 3764, 2262, 1871, 3647, 7510, 2400, 1784, 4384, # 4566
|
| 166 |
+
1952, 2942, 3080, 3191, 1728, 4121, 2043, 3648, 4385, 2007, 1701, 3131, 1551, 30, 2263, 4122, # 4582
|
| 167 |
+
7511, 2026, 4386, 3534, 7512, 501, 7513, 4123, 594, 3431, 2165, 1821, 3535, 3432, 3536, 3192, # 4598
|
| 168 |
+
829, 2826, 4124, 7514, 1680, 3132, 1225, 4125, 7515, 3262, 4387, 4126, 3133, 2336, 7516, 4388, # 4614
|
| 169 |
+
4127, 7517, 3912, 3913, 7518, 1847, 2383, 2596, 3330, 7519, 4389, 374, 3914, 652, 4128, 4129, # 4630
|
| 170 |
+
375, 1140, 798, 7520, 7521, 7522, 2361, 4390, 2264, 546, 1659, 138, 3031, 2445, 4391, 7523, # 4646
|
| 171 |
+
2250, 612, 1848, 910, 796, 3765, 1740, 1371, 825, 3766, 3767, 7524, 2906, 2554, 7525, 692, # 4662
|
| 172 |
+
444, 3032, 2624, 801, 4392, 4130, 7526, 1491, 244, 1053, 3033, 4131, 4132, 340, 7527, 3915, # 4678
|
| 173 |
+
1041, 2987, 293, 1168, 87, 1357, 7528, 1539, 959, 7529, 2236, 721, 694, 4133, 3768, 219, # 4694
|
| 174 |
+
1478, 644, 1417, 3331, 2656, 1413, 1401, 1335, 1389, 3916, 7530, 7531, 2988, 2362, 3134, 1825, # 4710
|
| 175 |
+
730, 1515, 184, 2827, 66, 4393, 7532, 1660, 2943, 246, 3332, 378, 1457, 226, 3433, 975, # 4726
|
| 176 |
+
3917, 2944, 1264, 3537, 674, 696, 7533, 163, 7534, 1141, 2417, 2166, 713, 3538, 3333, 4394, # 4742
|
| 177 |
+
3918, 7535, 7536, 1186, 15, 7537, 1079, 1070, 7538, 1522, 3193, 3539, 276, 1050, 2716, 758, # 4758
|
| 178 |
+
1126, 653, 2945, 3263, 7539, 2337, 889, 3540, 3919, 3081, 2989, 903, 1250, 4395, 3920, 3434, # 4774
|
| 179 |
+
3541, 1342, 1681, 1718, 766, 3264, 286, 89, 2946, 3649, 7540, 1713, 7541, 2597, 3334, 2990, # 4790
|
| 180 |
+
7542, 2947, 2215, 3194, 2866, 7543, 4396, 2498, 2526, 181, 387, 1075, 3921, 731, 2187, 3335, # 4806
|
| 181 |
+
7544, 3265, 310, 313, 3435, 2299, 770, 4134, 54, 3034, 189, 4397, 3082, 3769, 3922, 7545, # 4822
|
| 182 |
+
1230, 1617, 1849, 355, 3542, 4135, 4398, 3336, 111, 4136, 3650, 1350, 3135, 3436, 3035, 4137, # 4838
|
| 183 |
+
2149, 3266, 3543, 7546, 2784, 3923, 3924, 2991, 722, 2008, 7547, 1071, 247, 1207, 2338, 2471, # 4854
|
| 184 |
+
1378, 4399, 2009, 864, 1437, 1214, 4400, 373, 3770, 1142, 2216, 667, 4401, 442, 2753, 2555, # 4870
|
| 185 |
+
3771, 3925, 1968, 4138, 3267, 1839, 837, 170, 1107, 934, 1336, 1882, 7548, 7549, 2118, 4139, # 4886
|
| 186 |
+
2828, 743, 1569, 7550, 4402, 4140, 582, 2384, 1418, 3437, 7551, 1802, 7552, 357, 1395, 1729, # 4902
|
| 187 |
+
3651, 3268, 2418, 1564, 2237, 7553, 3083, 3772, 1633, 4403, 1114, 2085, 4141, 1532, 7554, 482, # 4918
|
| 188 |
+
2446, 4404, 7555, 7556, 1492, 833, 1466, 7557, 2717, 3544, 1641, 2829, 7558, 1526, 1272, 3652, # 4934
|
| 189 |
+
4142, 1686, 1794, 416, 2556, 1902, 1953, 1803, 7559, 3773, 2785, 3774, 1159, 2316, 7560, 2867, # 4950
|
| 190 |
+
4405, 1610, 1584, 3036, 2419, 2754, 443, 3269, 1163, 3136, 7561, 7562, 3926, 7563, 4143, 2499, # 4966
|
| 191 |
+
3037, 4406, 3927, 3137, 2103, 1647, 3545, 2010, 1872, 4144, 7564, 4145, 431, 3438, 7565, 250, # 4982
|
| 192 |
+
97, 81, 4146, 7566, 1648, 1850, 1558, 160, 848, 7567, 866, 740, 1694, 7568, 2201, 2830, # 4998
|
| 193 |
+
3195, 4147, 4407, 3653, 1687, 950, 2472, 426, 469, 3196, 3654, 3655, 3928, 7569, 7570, 1188, # 5014
|
| 194 |
+
424, 1995, 861, 3546, 4148, 3775, 2202, 2685, 168, 1235, 3547, 4149, 7571, 2086, 1674, 4408, # 5030
|
| 195 |
+
3337, 3270, 220, 2557, 1009, 7572, 3776, 670, 2992, 332, 1208, 717, 7573, 7574, 3548, 2447, # 5046
|
| 196 |
+
3929, 3338, 7575, 513, 7576, 1209, 2868, 3339, 3138, 4409, 1080, 7577, 7578, 7579, 7580, 2527, # 5062
|
| 197 |
+
3656, 3549, 815, 1587, 3930, 3931, 7581, 3550, 3439, 3777, 1254, 4410, 1328, 3038, 1390, 3932, # 5078
|
| 198 |
+
1741, 3933, 3778, 3934, 7582, 236, 3779, 2448, 3271, 7583, 7584, 3657, 3780, 1273, 3781, 4411, # 5094
|
| 199 |
+
7585, 308, 7586, 4412, 245, 4413, 1851, 2473, 1307, 2575, 430, 715, 2136, 2449, 7587, 270, # 5110
|
| 200 |
+
199, 2869, 3935, 7588, 3551, 2718, 1753, 761, 1754, 725, 1661, 1840, 4414, 3440, 3658, 7589, # 5126
|
| 201 |
+
7590, 587, 14, 3272, 227, 2598, 326, 480, 2265, 943, 2755, 3552, 291, 650, 1883, 7591, # 5142
|
| 202 |
+
1702, 1226, 102, 1547, 62, 3441, 904, 4415, 3442, 1164, 4150, 7592, 7593, 1224, 1548, 2756, # 5158
|
| 203 |
+
391, 498, 1493, 7594, 1386, 1419, 7595, 2055, 1177, 4416, 813, 880, 1081, 2363, 566, 1145, # 5174
|
| 204 |
+
4417, 2286, 1001, 1035, 2558, 2599, 2238, 394, 1286, 7596, 7597, 2068, 7598, 86, 1494, 1730, # 5190
|
| 205 |
+
3936, 491, 1588, 745, 897, 2948, 843, 3340, 3937, 2757, 2870, 3273, 1768, 998, 2217, 2069, # 5206
|
| 206 |
+
397, 1826, 1195, 1969, 3659, 2993, 3341, 284, 7599, 3782, 2500, 2137, 2119, 1903, 7600, 3938, # 5222
|
| 207 |
+
2150, 3939, 4151, 1036, 3443, 1904, 114, 2559, 4152, 209, 1527, 7601, 7602, 2949, 2831, 2625, # 5238
|
| 208 |
+
2385, 2719, 3139, 812, 2560, 7603, 3274, 7604, 1559, 737, 1884, 3660, 1210, 885, 28, 2686, # 5254
|
| 209 |
+
3553, 3783, 7605, 4153, 1004, 1779, 4418, 7606, 346, 1981, 2218, 2687, 4419, 3784, 1742, 797, # 5270
|
| 210 |
+
1642, 3940, 1933, 1072, 1384, 2151, 896, 3941, 3275, 3661, 3197, 2871, 3554, 7607, 2561, 1958, # 5286
|
| 211 |
+
4420, 2450, 1785, 7608, 7609, 7610, 3942, 4154, 1005, 1308, 3662, 4155, 2720, 4421, 4422, 1528, # 5302
|
| 212 |
+
2600, 161, 1178, 4156, 1982, 987, 4423, 1101, 4157, 631, 3943, 1157, 3198, 2420, 1343, 1241, # 5318
|
| 213 |
+
1016, 2239, 2562, 372, 877, 2339, 2501, 1160, 555, 1934, 911, 3944, 7611, 466, 1170, 169, # 5334
|
| 214 |
+
1051, 2907, 2688, 3663, 2474, 2994, 1182, 2011, 2563, 1251, 2626, 7612, 992, 2340, 3444, 1540, # 5350
|
| 215 |
+
2721, 1201, 2070, 2401, 1996, 2475, 7613, 4424, 528, 1922, 2188, 1503, 1873, 1570, 2364, 3342, # 5366
|
| 216 |
+
3276, 7614, 557, 1073, 7615, 1827, 3445, 2087, 2266, 3140, 3039, 3084, 767, 3085, 2786, 4425, # 5382
|
| 217 |
+
1006, 4158, 4426, 2341, 1267, 2176, 3664, 3199, 778, 3945, 3200, 2722, 1597, 2657, 7616, 4427, # 5398
|
| 218 |
+
7617, 3446, 7618, 7619, 7620, 3277, 2689, 1433, 3278, 131, 95, 1504, 3946, 723, 4159, 3141, # 5414
|
| 219 |
+
1841, 3555, 2758, 2189, 3947, 2027, 2104, 3665, 7621, 2995, 3948, 1218, 7622, 3343, 3201, 3949, # 5430
|
| 220 |
+
4160, 2576, 248, 1634, 3785, 912, 7623, 2832, 3666, 3040, 3786, 654, 53, 7624, 2996, 7625, # 5446
|
| 221 |
+
1688, 4428, 777, 3447, 1032, 3950, 1425, 7626, 191, 820, 2120, 2833, 971, 4429, 931, 3202, # 5462
|
| 222 |
+
135, 664, 783, 3787, 1997, 772, 2908, 1935, 3951, 3788, 4430, 2909, 3203, 282, 2723, 640, # 5478
|
| 223 |
+
1372, 3448, 1127, 922, 325, 3344, 7627, 7628, 711, 2044, 7629, 7630, 3952, 2219, 2787, 1936, # 5494
|
| 224 |
+
3953, 3345, 2220, 2251, 3789, 2300, 7631, 4431, 3790, 1258, 3279, 3954, 3204, 2138, 2950, 3955, # 5510
|
| 225 |
+
3956, 7632, 2221, 258, 3205, 4432, 101, 1227, 7633, 3280, 1755, 7634, 1391, 3281, 7635, 2910, # 5526
|
| 226 |
+
2056, 893, 7636, 7637, 7638, 1402, 4161, 2342, 7639, 7640, 3206, 3556, 7641, 7642, 878, 1325, # 5542
|
| 227 |
+
1780, 2788, 4433, 259, 1385, 2577, 744, 1183, 2267, 4434, 7643, 3957, 2502, 7644, 684, 1024, # 5558
|
| 228 |
+
4162, 7645, 472, 3557, 3449, 1165, 3282, 3958, 3959, 322, 2152, 881, 455, 1695, 1152, 1340, # 5574
|
| 229 |
+
660, 554, 2153, 4435, 1058, 4436, 4163, 830, 1065, 3346, 3960, 4437, 1923, 7646, 1703, 1918, # 5590
|
| 230 |
+
7647, 932, 2268, 122, 7648, 4438, 947, 677, 7649, 3791, 2627, 297, 1905, 1924, 2269, 4439, # 5606
|
| 231 |
+
2317, 3283, 7650, 7651, 4164, 7652, 4165, 84, 4166, 112, 989, 7653, 547, 1059, 3961, 701, # 5622
|
| 232 |
+
3558, 1019, 7654, 4167, 7655, 3450, 942, 639, 457, 2301, 2451, 993, 2951, 407, 851, 494, # 5638
|
| 233 |
+
4440, 3347, 927, 7656, 1237, 7657, 2421, 3348, 573, 4168, 680, 921, 2911, 1279, 1874, 285, # 5654
|
| 234 |
+
790, 1448, 1983, 719, 2167, 7658, 7659, 4441, 3962, 3963, 1649, 7660, 1541, 563, 7661, 1077, # 5670
|
| 235 |
+
7662, 3349, 3041, 3451, 511, 2997, 3964, 3965, 3667, 3966, 1268, 2564, 3350, 3207, 4442, 4443, # 5686
|
| 236 |
+
7663, 535, 1048, 1276, 1189, 2912, 2028, 3142, 1438, 1373, 2834, 2952, 1134, 2012, 7664, 4169, # 5702
|
| 237 |
+
1238, 2578, 3086, 1259, 7665, 700, 7666, 2953, 3143, 3668, 4170, 7667, 4171, 1146, 1875, 1906, # 5718
|
| 238 |
+
4444, 2601, 3967, 781, 2422, 132, 1589, 203, 147, 273, 2789, 2402, 898, 1786, 2154, 3968, # 5734
|
| 239 |
+
3969, 7668, 3792, 2790, 7669, 7670, 4445, 4446, 7671, 3208, 7672, 1635, 3793, 965, 7673, 1804, # 5750
|
| 240 |
+
2690, 1516, 3559, 1121, 1082, 1329, 3284, 3970, 1449, 3794, 65, 1128, 2835, 2913, 2759, 1590, # 5766
|
| 241 |
+
3795, 7674, 7675, 12, 2658, 45, 976, 2579, 3144, 4447, 517, 2528, 1013, 1037, 3209, 7676, # 5782
|
| 242 |
+
3796, 2836, 7677, 3797, 7678, 3452, 7679, 2602, 614, 1998, 2318, 3798, 3087, 2724, 2628, 7680, # 5798
|
| 243 |
+
2580, 4172, 599, 1269, 7681, 1810, 3669, 7682, 2691, 3088, 759, 1060, 489, 1805, 3351, 3285, # 5814
|
| 244 |
+
1358, 7683, 7684, 2386, 1387, 1215, 2629, 2252, 490, 7685, 7686, 4173, 1759, 2387, 2343, 7687, # 5830
|
| 245 |
+
4448, 3799, 1907, 3971, 2630, 1806, 3210, 4449, 3453, 3286, 2760, 2344, 874, 7688, 7689, 3454, # 5846
|
| 246 |
+
3670, 1858, 91, 2914, 3671, 3042, 3800, 4450, 7690, 3145, 3972, 2659, 7691, 3455, 1202, 1403, # 5862
|
| 247 |
+
3801, 2954, 2529, 1517, 2503, 4451, 3456, 2504, 7692, 4452, 7693, 2692, 1885, 1495, 1731, 3973, # 5878
|
| 248 |
+
2365, 4453, 7694, 2029, 7695, 7696, 3974, 2693, 1216, 237, 2581, 4174, 2319, 3975, 3802, 4454, # 5894
|
| 249 |
+
4455, 2694, 3560, 3457, 445, 4456, 7697, 7698, 7699, 7700, 2761, 61, 3976, 3672, 1822, 3977, # 5910
|
| 250 |
+
7701, 687, 2045, 935, 925, 405, 2660, 703, 1096, 1859, 2725, 4457, 3978, 1876, 1367, 2695, # 5926
|
| 251 |
+
3352, 918, 2105, 1781, 2476, 334, 3287, 1611, 1093, 4458, 564, 3146, 3458, 3673, 3353, 945, # 5942
|
| 252 |
+
2631, 2057, 4459, 7702, 1925, 872, 4175, 7703, 3459, 2696, 3089, 349, 4176, 3674, 3979, 4460, # 5958
|
| 253 |
+
3803, 4177, 3675, 2155, 3980, 4461, 4462, 4178, 4463, 2403, 2046, 782, 3981, 400, 251, 4179, # 5974
|
| 254 |
+
1624, 7704, 7705, 277, 3676, 299, 1265, 476, 1191, 3804, 2121, 4180, 4181, 1109, 205, 7706, # 5990
|
| 255 |
+
2582, 1000, 2156, 3561, 1860, 7707, 7708, 7709, 4464, 7710, 4465, 2565, 107, 2477, 2157, 3982, # 6006
|
| 256 |
+
3460, 3147, 7711, 1533, 541, 1301, 158, 753, 4182, 2872, 3562, 7712, 1696, 370, 1088, 4183, # 6022
|
| 257 |
+
4466, 3563, 579, 327, 440, 162, 2240, 269, 1937, 1374, 3461, 968, 3043, 56, 1396, 3090, # 6038
|
| 258 |
+
2106, 3288, 3354, 7713, 1926, 2158, 4467, 2998, 7714, 3564, 7715, 7716, 3677, 4468, 2478, 7717, # 6054
|
| 259 |
+
2791, 7718, 1650, 4469, 7719, 2603, 7720, 7721, 3983, 2661, 3355, 1149, 3356, 3984, 3805, 3985, # 6070
|
| 260 |
+
7722, 1076, 49, 7723, 951, 3211, 3289, 3290, 450, 2837, 920, 7724, 1811, 2792, 2366, 4184, # 6086
|
| 261 |
+
1908, 1138, 2367, 3806, 3462, 7725, 3212, 4470, 1909, 1147, 1518, 2423, 4471, 3807, 7726, 4472, # 6102
|
| 262 |
+
2388, 2604, 260, 1795, 3213, 7727, 7728, 3808, 3291, 708, 7729, 3565, 1704, 7730, 3566, 1351, # 6118
|
| 263 |
+
1618, 3357, 2999, 1886, 944, 4185, 3358, 4186, 3044, 3359, 4187, 7731, 3678, 422, 413, 1714, # 6134
|
| 264 |
+
3292, 500, 2058, 2345, 4188, 2479, 7732, 1344, 1910, 954, 7733, 1668, 7734, 7735, 3986, 2404, # 6150
|
| 265 |
+
4189, 3567, 3809, 4190, 7736, 2302, 1318, 2505, 3091, 133, 3092, 2873, 4473, 629, 31, 2838, # 6166
|
| 266 |
+
2697, 3810, 4474, 850, 949, 4475, 3987, 2955, 1732, 2088, 4191, 1496, 1852, 7737, 3988, 620, # 6182
|
| 267 |
+
3214, 981, 1242, 3679, 3360, 1619, 3680, 1643, 3293, 2139, 2452, 1970, 1719, 3463, 2168, 7738, # 6198
|
| 268 |
+
3215, 7739, 7740, 3361, 1828, 7741, 1277, 4476, 1565, 2047, 7742, 1636, 3568, 3093, 7743, 869, # 6214
|
| 269 |
+
2839, 655, 3811, 3812, 3094, 3989, 3000, 3813, 1310, 3569, 4477, 7744, 7745, 7746, 1733, 558, # 6230
|
| 270 |
+
4478, 3681, 335, 1549, 3045, 1756, 4192, 3682, 1945, 3464, 1829, 1291, 1192, 470, 2726, 2107, # 6246
|
| 271 |
+
2793, 913, 1054, 3990, 7747, 1027, 7748, 3046, 3991, 4479, 982, 2662, 3362, 3148, 3465, 3216, # 6262
|
| 272 |
+
3217, 1946, 2794, 7749, 571, 4480, 7750, 1830, 7751, 3570, 2583, 1523, 2424, 7752, 2089, 984, # 6278
|
| 273 |
+
4481, 3683, 1959, 7753, 3684, 852, 923, 2795, 3466, 3685, 969, 1519, 999, 2048, 2320, 1705, # 6294
|
| 274 |
+
7754, 3095, 615, 1662, 151, 597, 3992, 2405, 2321, 1049, 275, 4482, 3686, 4193, 568, 3687, # 6310
|
| 275 |
+
3571, 2480, 4194, 3688, 7755, 2425, 2270, 409, 3218, 7756, 1566, 2874, 3467, 1002, 769, 2840, # 6326
|
| 276 |
+
194, 2090, 3149, 3689, 2222, 3294, 4195, 628, 1505, 7757, 7758, 1763, 2177, 3001, 3993, 521, # 6342
|
| 277 |
+
1161, 2584, 1787, 2203, 2406, 4483, 3994, 1625, 4196, 4197, 412, 42, 3096, 464, 7759, 2632, # 6358
|
| 278 |
+
4484, 3363, 1760, 1571, 2875, 3468, 2530, 1219, 2204, 3814, 2633, 2140, 2368, 4485, 4486, 3295, # 6374
|
| 279 |
+
1651, 3364, 3572, 7760, 7761, 3573, 2481, 3469, 7762, 3690, 7763, 7764, 2271, 2091, 460, 7765, # 6390
|
| 280 |
+
4487, 7766, 3002, 962, 588, 3574, 289, 3219, 2634, 1116, 52, 7767, 3047, 1796, 7768, 7769, # 6406
|
| 281 |
+
7770, 1467, 7771, 1598, 1143, 3691, 4198, 1984, 1734, 1067, 4488, 1280, 3365, 465, 4489, 1572, # 6422
|
| 282 |
+
510, 7772, 1927, 2241, 1812, 1644, 3575, 7773, 4490, 3692, 7774, 7775, 2663, 1573, 1534, 7776, # 6438
|
| 283 |
+
7777, 4199, 536, 1807, 1761, 3470, 3815, 3150, 2635, 7778, 7779, 7780, 4491, 3471, 2915, 1911, # 6454
|
| 284 |
+
2796, 7781, 3296, 1122, 377, 3220, 7782, 360, 7783, 7784, 4200, 1529, 551, 7785, 2059, 3693, # 6470
|
| 285 |
+
1769, 2426, 7786, 2916, 4201, 3297, 3097, 2322, 2108, 2030, 4492, 1404, 136, 1468, 1479, 672, # 6486
|
| 286 |
+
1171, 3221, 2303, 271, 3151, 7787, 2762, 7788, 2049, 678, 2727, 865, 1947, 4493, 7789, 2013, # 6502
|
| 287 |
+
3995, 2956, 7790, 2728, 2223, 1397, 3048, 3694, 4494, 4495, 1735, 2917, 3366, 3576, 7791, 3816, # 6518
|
| 288 |
+
509, 2841, 2453, 2876, 3817, 7792, 7793, 3152, 3153, 4496, 4202, 2531, 4497, 2304, 1166, 1010, # 6534
|
| 289 |
+
552, 681, 1887, 7794, 7795, 2957, 2958, 3996, 1287, 1596, 1861, 3154, 358, 453, 736, 175, # 6550
|
| 290 |
+
478, 1117, 905, 1167, 1097, 7796, 1853, 1530, 7797, 1706, 7798, 2178, 3472, 2287, 3695, 3473, # 6566
|
| 291 |
+
3577, 4203, 2092, 4204, 7799, 3367, 1193, 2482, 4205, 1458, 2190, 2205, 1862, 1888, 1421, 3298, # 6582
|
| 292 |
+
2918, 3049, 2179, 3474, 595, 2122, 7800, 3997, 7801, 7802, 4206, 1707, 2636, 223, 3696, 1359, # 6598
|
| 293 |
+
751, 3098, 183, 3475, 7803, 2797, 3003, 419, 2369, 633, 704, 3818, 2389, 241, 7804, 7805, # 6614
|
| 294 |
+
7806, 838, 3004, 3697, 2272, 2763, 2454, 3819, 1938, 2050, 3998, 1309, 3099, 2242, 1181, 7807, # 6630
|
| 295 |
+
1136, 2206, 3820, 2370, 1446, 4207, 2305, 4498, 7808, 7809, 4208, 1055, 2605, 484, 3698, 7810, # 6646
|
| 296 |
+
3999, 625, 4209, 2273, 3368, 1499, 4210, 4000, 7811, 4001, 4211, 3222, 2274, 2275, 3476, 7812, # 6662
|
| 297 |
+
7813, 2764, 808, 2606, 3699, 3369, 4002, 4212, 3100, 2532, 526, 3370, 3821, 4213, 955, 7814, # 6678
|
| 298 |
+
1620, 4214, 2637, 2427, 7815, 1429, 3700, 1669, 1831, 994, 928, 7816, 3578, 1260, 7817, 7818, # 6694
|
| 299 |
+
7819, 1948, 2288, 741, 2919, 1626, 4215, 2729, 2455, 867, 1184, 362, 3371, 1392, 7820, 7821, # 6710
|
| 300 |
+
4003, 4216, 1770, 1736, 3223, 2920, 4499, 4500, 1928, 2698, 1459, 1158, 7822, 3050, 3372, 2877, # 6726
|
| 301 |
+
1292, 1929, 2506, 2842, 3701, 1985, 1187, 2071, 2014, 2607, 4217, 7823, 2566, 2507, 2169, 3702, # 6742
|
| 302 |
+
2483, 3299, 7824, 3703, 4501, 7825, 7826, 666, 1003, 3005, 1022, 3579, 4218, 7827, 4502, 1813, # 6758
|
| 303 |
+
2253, 574, 3822, 1603, 295, 1535, 705, 3823, 4219, 283, 858, 417, 7828, 7829, 3224, 4503, # 6774
|
| 304 |
+
4504, 3051, 1220, 1889, 1046, 2276, 2456, 4004, 1393, 1599, 689, 2567, 388, 4220, 7830, 2484, # 6790
|
| 305 |
+
802, 7831, 2798, 3824, 2060, 1405, 2254, 7832, 4505, 3825, 2109, 1052, 1345, 3225, 1585, 7833, # 6806
|
| 306 |
+
809, 7834, 7835, 7836, 575, 2730, 3477, 956, 1552, 1469, 1144, 2323, 7837, 2324, 1560, 2457, # 6822
|
| 307 |
+
3580, 3226, 4005, 616, 2207, 3155, 2180, 2289, 7838, 1832, 7839, 3478, 4506, 7840, 1319, 3704, # 6838
|
| 308 |
+
3705, 1211, 3581, 1023, 3227, 1293, 2799, 7841, 7842, 7843, 3826, 607, 2306, 3827, 762, 2878, # 6854
|
| 309 |
+
1439, 4221, 1360, 7844, 1485, 3052, 7845, 4507, 1038, 4222, 1450, 2061, 2638, 4223, 1379, 4508, # 6870
|
| 310 |
+
2585, 7846, 7847, 4224, 1352, 1414, 2325, 2921, 1172, 7848, 7849, 3828, 3829, 7850, 1797, 1451, # 6886
|
| 311 |
+
7851, 7852, 7853, 7854, 2922, 4006, 4007, 2485, 2346, 411, 4008, 4009, 3582, 3300, 3101, 4509, # 6902
|
| 312 |
+
1561, 2664, 1452, 4010, 1375, 7855, 7856, 47, 2959, 316, 7857, 1406, 1591, 2923, 3156, 7858, # 6918
|
| 313 |
+
1025, 2141, 3102, 3157, 354, 2731, 884, 2224, 4225, 2407, 508, 3706, 726, 3583, 996, 2428, # 6934
|
| 314 |
+
3584, 729, 7859, 392, 2191, 1453, 4011, 4510, 3707, 7860, 7861, 2458, 3585, 2608, 1675, 2800, # 6950
|
| 315 |
+
919, 2347, 2960, 2348, 1270, 4511, 4012, 73, 7862, 7863, 647, 7864, 3228, 2843, 2255, 1550, # 6966
|
| 316 |
+
1346, 3006, 7865, 1332, 883, 3479, 7866, 7867, 7868, 7869, 3301, 2765, 7870, 1212, 831, 1347, # 6982
|
| 317 |
+
4226, 4512, 2326, 3830, 1863, 3053, 720, 3831, 4513, 4514, 3832, 7871, 4227, 7872, 7873, 4515, # 6998
|
| 318 |
+
7874, 7875, 1798, 4516, 3708, 2609, 4517, 3586, 1645, 2371, 7876, 7877, 2924, 669, 2208, 2665, # 7014
|
| 319 |
+
2429, 7878, 2879, 7879, 7880, 1028, 3229, 7881, 4228, 2408, 7882, 2256, 1353, 7883, 7884, 4518, # 7030
|
| 320 |
+
3158, 518, 7885, 4013, 7886, 4229, 1960, 7887, 2142, 4230, 7888, 7889, 3007, 2349, 2350, 3833, # 7046
|
| 321 |
+
516, 1833, 1454, 4014, 2699, 4231, 4519, 2225, 2610, 1971, 1129, 3587, 7890, 2766, 7891, 2961, # 7062
|
| 322 |
+
1422, 577, 1470, 3008, 1524, 3373, 7892, 7893, 432, 4232, 3054, 3480, 7894, 2586, 1455, 2508, # 7078
|
| 323 |
+
2226, 1972, 1175, 7895, 1020, 2732, 4015, 3481, 4520, 7896, 2733, 7897, 1743, 1361, 3055, 3482, # 7094
|
| 324 |
+
2639, 4016, 4233, 4521, 2290, 895, 924, 4234, 2170, 331, 2243, 3056, 166, 1627, 3057, 1098, # 7110
|
| 325 |
+
7898, 1232, 2880, 2227, 3374, 4522, 657, 403, 1196, 2372, 542, 3709, 3375, 1600, 4235, 3483, # 7126
|
| 326 |
+
7899, 4523, 2767, 3230, 576, 530, 1362, 7900, 4524, 2533, 2666, 3710, 4017, 7901, 842, 3834, # 7142
|
| 327 |
+
7902, 2801, 2031, 1014, 4018, 213, 2700, 3376, 665, 621, 4236, 7903, 3711, 2925, 2430, 7904, # 7158
|
| 328 |
+
2431, 3302, 3588, 3377, 7905, 4237, 2534, 4238, 4525, 3589, 1682, 4239, 3484, 1380, 7906, 724, # 7174
|
| 329 |
+
2277, 600, 1670, 7907, 1337, 1233, 4526, 3103, 2244, 7908, 1621, 4527, 7909, 651, 4240, 7910, # 7190
|
| 330 |
+
1612, 4241, 2611, 7911, 2844, 7912, 2734, 2307, 3058, 7913, 716, 2459, 3059, 174, 1255, 2701, # 7206
|
| 331 |
+
4019, 3590, 548, 1320, 1398, 728, 4020, 1574, 7914, 1890, 1197, 3060, 4021, 7915, 3061, 3062, # 7222
|
| 332 |
+
3712, 3591, 3713, 747, 7916, 635, 4242, 4528, 7917, 7918, 7919, 4243, 7920, 7921, 4529, 7922, # 7238
|
| 333 |
+
3378, 4530, 2432, 451, 7923, 3714, 2535, 2072, 4244, 2735, 4245, 4022, 7924, 1764, 4531, 7925, # 7254
|
| 334 |
+
4246, 350, 7926, 2278, 2390, 2486, 7927, 4247, 4023, 2245, 1434, 4024, 488, 4532, 458, 4248, # 7270
|
| 335 |
+
4025, 3715, 771, 1330, 2391, 3835, 2568, 3159, 2159, 2409, 1553, 2667, 3160, 4249, 7928, 2487, # 7286
|
| 336 |
+
2881, 2612, 1720, 2702, 4250, 3379, 4533, 7929, 2536, 4251, 7930, 3231, 4252, 2768, 7931, 2015, # 7302
|
| 337 |
+
2736, 7932, 1155, 1017, 3716, 3836, 7933, 3303, 2308, 201, 1864, 4253, 1430, 7934, 4026, 7935, # 7318
|
| 338 |
+
7936, 7937, 7938, 7939, 4254, 1604, 7940, 414, 1865, 371, 2587, 4534, 4535, 3485, 2016, 3104, # 7334
|
| 339 |
+
4536, 1708, 960, 4255, 887, 389, 2171, 1536, 1663, 1721, 7941, 2228, 4027, 2351, 2926, 1580, # 7350
|
| 340 |
+
7942, 7943, 7944, 1744, 7945, 2537, 4537, 4538, 7946, 4539, 7947, 2073, 7948, 7949, 3592, 3380, # 7366
|
| 341 |
+
2882, 4256, 7950, 4257, 2640, 3381, 2802, 673, 2703, 2460, 709, 3486, 4028, 3593, 4258, 7951, # 7382
|
| 342 |
+
1148, 502, 634, 7952, 7953, 1204, 4540, 3594, 1575, 4541, 2613, 3717, 7954, 3718, 3105, 948, # 7398
|
| 343 |
+
3232, 121, 1745, 3837, 1110, 7955, 4259, 3063, 2509, 3009, 4029, 3719, 1151, 1771, 3838, 1488, # 7414
|
| 344 |
+
4030, 1986, 7956, 2433, 3487, 7957, 7958, 2093, 7959, 4260, 3839, 1213, 1407, 2803, 531, 2737, # 7430
|
| 345 |
+
2538, 3233, 1011, 1537, 7960, 2769, 4261, 3106, 1061, 7961, 3720, 3721, 1866, 2883, 7962, 2017, # 7446
|
| 346 |
+
120, 4262, 4263, 2062, 3595, 3234, 2309, 3840, 2668, 3382, 1954, 4542, 7963, 7964, 3488, 1047, # 7462
|
| 347 |
+
2704, 1266, 7965, 1368, 4543, 2845, 649, 3383, 3841, 2539, 2738, 1102, 2846, 2669, 7966, 7967, # 7478
|
| 348 |
+
1999, 7968, 1111, 3596, 2962, 7969, 2488, 3842, 3597, 2804, 1854, 3384, 3722, 7970, 7971, 3385, # 7494
|
| 349 |
+
2410, 2884, 3304, 3235, 3598, 7972, 2569, 7973, 3599, 2805, 4031, 1460, 856, 7974, 3600, 7975, # 7510
|
| 350 |
+
2885, 2963, 7976, 2886, 3843, 7977, 4264, 632, 2510, 875, 3844, 1697, 3845, 2291, 7978, 7979, # 7526
|
| 351 |
+
4544, 3010, 1239, 580, 4545, 4265, 7980, 914, 936, 2074, 1190, 4032, 1039, 2123, 7981, 7982, # 7542
|
| 352 |
+
7983, 3386, 1473, 7984, 1354, 4266, 3846, 7985, 2172, 3064, 4033, 915, 3305, 4267, 4268, 3306, # 7558
|
| 353 |
+
1605, 1834, 7986, 2739, 398, 3601, 4269, 3847, 4034, 328, 1912, 2847, 4035, 3848, 1331, 4270, # 7574
|
| 354 |
+
3011, 937, 4271, 7987, 3602, 4036, 4037, 3387, 2160, 4546, 3388, 524, 742, 538, 3065, 1012, # 7590
|
| 355 |
+
7988, 7989, 3849, 2461, 7990, 658, 1103, 225, 3850, 7991, 7992, 4547, 7993, 4548, 7994, 3236, # 7606
|
| 356 |
+
1243, 7995, 4038, 963, 2246, 4549, 7996, 2705, 3603, 3161, 7997, 7998, 2588, 2327, 7999, 4550, # 7622
|
| 357 |
+
8000, 8001, 8002, 3489, 3307, 957, 3389, 2540, 2032, 1930, 2927, 2462, 870, 2018, 3604, 1746, # 7638
|
| 358 |
+
2770, 2771, 2434, 2463, 8003, 3851, 8004, 3723, 3107, 3724, 3490, 3390, 3725, 8005, 1179, 3066, # 7654
|
| 359 |
+
8006, 3162, 2373, 4272, 3726, 2541, 3163, 3108, 2740, 4039, 8007, 3391, 1556, 2542, 2292, 977, # 7670
|
| 360 |
+
2887, 2033, 4040, 1205, 3392, 8008, 1765, 3393, 3164, 2124, 1271, 1689, 714, 4551, 3491, 8009, # 7686
|
| 361 |
+
2328, 3852, 533, 4273, 3605, 2181, 617, 8010, 2464, 3308, 3492, 2310, 8011, 8012, 3165, 8013, # 7702
|
| 362 |
+
8014, 3853, 1987, 618, 427, 2641, 3493, 3394, 8015, 8016, 1244, 1690, 8017, 2806, 4274, 4552, # 7718
|
| 363 |
+
8018, 3494, 8019, 8020, 2279, 1576, 473, 3606, 4275, 3395, 972, 8021, 3607, 8022, 3067, 8023, # 7734
|
| 364 |
+
8024, 4553, 4554, 8025, 3727, 4041, 4042, 8026, 153, 4555, 356, 8027, 1891, 2888, 4276, 2143, # 7750
|
| 365 |
+
408, 803, 2352, 8028, 3854, 8029, 4277, 1646, 2570, 2511, 4556, 4557, 3855, 8030, 3856, 4278, # 7766
|
| 366 |
+
8031, 2411, 3396, 752, 8032, 8033, 1961, 2964, 8034, 746, 3012, 2465, 8035, 4279, 3728, 698, # 7782
|
| 367 |
+
4558, 1892, 4280, 3608, 2543, 4559, 3609, 3857, 8036, 3166, 3397, 8037, 1823, 1302, 4043, 2706, # 7798
|
| 368 |
+
3858, 1973, 4281, 8038, 4282, 3167, 823, 1303, 1288, 1236, 2848, 3495, 4044, 3398, 774, 3859, # 7814
|
| 369 |
+
8039, 1581, 4560, 1304, 2849, 3860, 4561, 8040, 2435, 2161, 1083, 3237, 4283, 4045, 4284, 344, # 7830
|
| 370 |
+
1173, 288, 2311, 454, 1683, 8041, 8042, 1461, 4562, 4046, 2589, 8043, 8044, 4563, 985, 894, # 7846
|
| 371 |
+
8045, 3399, 3168, 8046, 1913, 2928, 3729, 1988, 8047, 2110, 1974, 8048, 4047, 8049, 2571, 1194, # 7862
|
| 372 |
+
425, 8050, 4564, 3169, 1245, 3730, 4285, 8051, 8052, 2850, 8053, 636, 4565, 1855, 3861, 760, # 7878
|
| 373 |
+
1799, 8054, 4286, 2209, 1508, 4566, 4048, 1893, 1684, 2293, 8055, 8056, 8057, 4287, 4288, 2210, # 7894
|
| 374 |
+
479, 8058, 8059, 832, 8060, 4049, 2489, 8061, 2965, 2490, 3731, 990, 3109, 627, 1814, 2642, # 7910
|
| 375 |
+
4289, 1582, 4290, 2125, 2111, 3496, 4567, 8062, 799, 4291, 3170, 8063, 4568, 2112, 1737, 3013, # 7926
|
| 376 |
+
1018, 543, 754, 4292, 3309, 1676, 4569, 4570, 4050, 8064, 1489, 8065, 3497, 8066, 2614, 2889, # 7942
|
| 377 |
+
4051, 8067, 8068, 2966, 8069, 8070, 8071, 8072, 3171, 4571, 4572, 2182, 1722, 8073, 3238, 3239, # 7958
|
| 378 |
+
1842, 3610, 1715, 481, 365, 1975, 1856, 8074, 8075, 1962, 2491, 4573, 8076, 2126, 3611, 3240, # 7974
|
| 379 |
+
433, 1894, 2063, 2075, 8077, 602, 2741, 8078, 8079, 8080, 8081, 8082, 3014, 1628, 3400, 8083, # 7990
|
| 380 |
+
3172, 4574, 4052, 2890, 4575, 2512, 8084, 2544, 2772, 8085, 8086, 8087, 3310, 4576, 2891, 8088, # 8006
|
| 381 |
+
4577, 8089, 2851, 4578, 4579, 1221, 2967, 4053, 2513, 8090, 8091, 8092, 1867, 1989, 8093, 8094, # 8022
|
| 382 |
+
8095, 1895, 8096, 8097, 4580, 1896, 4054, 318, 8098, 2094, 4055, 4293, 8099, 8100, 485, 8101, # 8038
|
| 383 |
+
938, 3862, 553, 2670, 116, 8102, 3863, 3612, 8103, 3498, 2671, 2773, 3401, 3311, 2807, 8104, # 8054
|
| 384 |
+
3613, 2929, 4056, 1747, 2930, 2968, 8105, 8106, 207, 8107, 8108, 2672, 4581, 2514, 8109, 3015, # 8070
|
| 385 |
+
890, 3614, 3864, 8110, 1877, 3732, 3402, 8111, 2183, 2353, 3403, 1652, 8112, 8113, 8114, 941, # 8086
|
| 386 |
+
2294, 208, 3499, 4057, 2019, 330, 4294, 3865, 2892, 2492, 3733, 4295, 8115, 8116, 8117, 8118, # 8102
|
| 387 |
+
)
|
| 388 |
+
# fmt: on
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/euctwprober.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
######################## BEGIN LICENSE BLOCK ########################
|
| 2 |
+
# The Original Code is mozilla.org code.
|
| 3 |
+
#
|
| 4 |
+
# The Initial Developer of the Original Code is
|
| 5 |
+
# Netscape Communications Corporation.
|
| 6 |
+
# Portions created by the Initial Developer are Copyright (C) 1998
|
| 7 |
+
# the Initial Developer. All Rights Reserved.
|
| 8 |
+
#
|
| 9 |
+
# Contributor(s):
|
| 10 |
+
# Mark Pilgrim - port to Python
|
| 11 |
+
#
|
| 12 |
+
# This library is free software; you can redistribute it and/or
|
| 13 |
+
# modify it under the terms of the GNU Lesser General Public
|
| 14 |
+
# License as published by the Free Software Foundation; either
|
| 15 |
+
# version 2.1 of the License, or (at your option) any later version.
|
| 16 |
+
#
|
| 17 |
+
# This library is distributed in the hope that it will be useful,
|
| 18 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 19 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 20 |
+
# Lesser General Public License for more details.
|
| 21 |
+
#
|
| 22 |
+
# You should have received a copy of the GNU Lesser General Public
|
| 23 |
+
# License along with this library; if not, write to the Free Software
|
| 24 |
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
| 25 |
+
# 02110-1301 USA
|
| 26 |
+
######################### END LICENSE BLOCK #########################
|
| 27 |
+
|
| 28 |
+
from .chardistribution import EUCTWDistributionAnalysis
|
| 29 |
+
from .codingstatemachine import CodingStateMachine
|
| 30 |
+
from .mbcharsetprober import MultiByteCharSetProber
|
| 31 |
+
from .mbcssm import EUCTW_SM_MODEL
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class EUCTWProber(MultiByteCharSetProber):
|
| 35 |
+
def __init__(self) -> None:
|
| 36 |
+
super().__init__()
|
| 37 |
+
self.coding_sm = CodingStateMachine(EUCTW_SM_MODEL)
|
| 38 |
+
self.distribution_analyzer = EUCTWDistributionAnalysis()
|
| 39 |
+
self.reset()
|
| 40 |
+
|
| 41 |
+
@property
|
| 42 |
+
def charset_name(self) -> str:
|
| 43 |
+
return "EUC-TW"
|
| 44 |
+
|
| 45 |
+
@property
|
| 46 |
+
def language(self) -> str:
|
| 47 |
+
return "Taiwan"
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/gb2312prober.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
######################## BEGIN LICENSE BLOCK ########################
|
| 2 |
+
# The Original Code is mozilla.org code.
|
| 3 |
+
#
|
| 4 |
+
# The Initial Developer of the Original Code is
|
| 5 |
+
# Netscape Communications Corporation.
|
| 6 |
+
# Portions created by the Initial Developer are Copyright (C) 1998
|
| 7 |
+
# the Initial Developer. All Rights Reserved.
|
| 8 |
+
#
|
| 9 |
+
# Contributor(s):
|
| 10 |
+
# Mark Pilgrim - port to Python
|
| 11 |
+
#
|
| 12 |
+
# This library is free software; you can redistribute it and/or
|
| 13 |
+
# modify it under the terms of the GNU Lesser General Public
|
| 14 |
+
# License as published by the Free Software Foundation; either
|
| 15 |
+
# version 2.1 of the License, or (at your option) any later version.
|
| 16 |
+
#
|
| 17 |
+
# This library is distributed in the hope that it will be useful,
|
| 18 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 19 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 20 |
+
# Lesser General Public License for more details.
|
| 21 |
+
#
|
| 22 |
+
# You should have received a copy of the GNU Lesser General Public
|
| 23 |
+
# License along with this library; if not, write to the Free Software
|
| 24 |
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
| 25 |
+
# 02110-1301 USA
|
| 26 |
+
######################### END LICENSE BLOCK #########################
|
| 27 |
+
|
| 28 |
+
from .chardistribution import GB2312DistributionAnalysis
|
| 29 |
+
from .codingstatemachine import CodingStateMachine
|
| 30 |
+
from .mbcharsetprober import MultiByteCharSetProber
|
| 31 |
+
from .mbcssm import GB2312_SM_MODEL
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class GB2312Prober(MultiByteCharSetProber):
|
| 35 |
+
def __init__(self) -> None:
|
| 36 |
+
super().__init__()
|
| 37 |
+
self.coding_sm = CodingStateMachine(GB2312_SM_MODEL)
|
| 38 |
+
self.distribution_analyzer = GB2312DistributionAnalysis()
|
| 39 |
+
self.reset()
|
| 40 |
+
|
| 41 |
+
@property
|
| 42 |
+
def charset_name(self) -> str:
|
| 43 |
+
return "GB2312"
|
| 44 |
+
|
| 45 |
+
@property
|
| 46 |
+
def language(self) -> str:
|
| 47 |
+
return "Chinese"
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/hebrewprober.py
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
######################## BEGIN LICENSE BLOCK ########################
|
| 2 |
+
# The Original Code is Mozilla Universal charset detector code.
|
| 3 |
+
#
|
| 4 |
+
# The Initial Developer of the Original Code is
|
| 5 |
+
# Shy Shalom
|
| 6 |
+
# Portions created by the Initial Developer are Copyright (C) 2005
|
| 7 |
+
# the Initial Developer. All Rights Reserved.
|
| 8 |
+
#
|
| 9 |
+
# Contributor(s):
|
| 10 |
+
# Mark Pilgrim - port to Python
|
| 11 |
+
#
|
| 12 |
+
# This library is free software; you can redistribute it and/or
|
| 13 |
+
# modify it under the terms of the GNU Lesser General Public
|
| 14 |
+
# License as published by the Free Software Foundation; either
|
| 15 |
+
# version 2.1 of the License, or (at your option) any later version.
|
| 16 |
+
#
|
| 17 |
+
# This library is distributed in the hope that it will be useful,
|
| 18 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 19 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 20 |
+
# Lesser General Public License for more details.
|
| 21 |
+
#
|
| 22 |
+
# You should have received a copy of the GNU Lesser General Public
|
| 23 |
+
# License along with this library; if not, write to the Free Software
|
| 24 |
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
| 25 |
+
# 02110-1301 USA
|
| 26 |
+
######################### END LICENSE BLOCK #########################
|
| 27 |
+
|
| 28 |
+
from typing import Optional, Union
|
| 29 |
+
|
| 30 |
+
from .charsetprober import CharSetProber
|
| 31 |
+
from .enums import ProbingState
|
| 32 |
+
from .sbcharsetprober import SingleByteCharSetProber
|
| 33 |
+
|
| 34 |
+
# This prober doesn't actually recognize a language or a charset.
|
| 35 |
+
# It is a helper prober for the use of the Hebrew model probers
|
| 36 |
+
|
| 37 |
+
### General ideas of the Hebrew charset recognition ###
|
| 38 |
+
#
|
| 39 |
+
# Four main charsets exist in Hebrew:
|
| 40 |
+
# "ISO-8859-8" - Visual Hebrew
|
| 41 |
+
# "windows-1255" - Logical Hebrew
|
| 42 |
+
# "ISO-8859-8-I" - Logical Hebrew
|
| 43 |
+
# "x-mac-hebrew" - ?? Logical Hebrew ??
|
| 44 |
+
#
|
| 45 |
+
# Both "ISO" charsets use a completely identical set of code points, whereas
|
| 46 |
+
# "windows-1255" and "x-mac-hebrew" are two different proper supersets of
|
| 47 |
+
# these code points. windows-1255 defines additional characters in the range
|
| 48 |
+
# 0x80-0x9F as some misc punctuation marks as well as some Hebrew-specific
|
| 49 |
+
# diacritics and additional 'Yiddish' ligature letters in the range 0xc0-0xd6.
|
| 50 |
+
# x-mac-hebrew defines similar additional code points but with a different
|
| 51 |
+
# mapping.
|
| 52 |
+
#
|
| 53 |
+
# As far as an average Hebrew text with no diacritics is concerned, all four
|
| 54 |
+
# charsets are identical with respect to code points. Meaning that for the
|
| 55 |
+
# main Hebrew alphabet, all four map the same values to all 27 Hebrew letters
|
| 56 |
+
# (including final letters).
|
| 57 |
+
#
|
| 58 |
+
# The dominant difference between these charsets is their directionality.
|
| 59 |
+
# "Visual" directionality means that the text is ordered as if the renderer is
|
| 60 |
+
# not aware of a BIDI rendering algorithm. The renderer sees the text and
|
| 61 |
+
# draws it from left to right. The text itself when ordered naturally is read
|
| 62 |
+
# backwards. A buffer of Visual Hebrew generally looks like so:
|
| 63 |
+
# "[last word of first line spelled backwards] [whole line ordered backwards
|
| 64 |
+
# and spelled backwards] [first word of first line spelled backwards]
|
| 65 |
+
# [end of line] [last word of second line] ... etc' "
|
| 66 |
+
# adding punctuation marks, numbers and English text to visual text is
|
| 67 |
+
# naturally also "visual" and from left to right.
|
| 68 |
+
#
|
| 69 |
+
# "Logical" directionality means the text is ordered "naturally" according to
|
| 70 |
+
# the order it is read. It is the responsibility of the renderer to display
|
| 71 |
+
# the text from right to left. A BIDI algorithm is used to place general
|
| 72 |
+
# punctuation marks, numbers and English text in the text.
|
| 73 |
+
#
|
| 74 |
+
# Texts in x-mac-hebrew are almost impossible to find on the Internet. From
|
| 75 |
+
# what little evidence I could find, it seems that its general directionality
|
| 76 |
+
# is Logical.
|
| 77 |
+
#
|
| 78 |
+
# To sum up all of the above, the Hebrew probing mechanism knows about two
|
| 79 |
+
# charsets:
|
| 80 |
+
# Visual Hebrew - "ISO-8859-8" - backwards text - Words and sentences are
|
| 81 |
+
# backwards while line order is natural. For charset recognition purposes
|
| 82 |
+
# the line order is unimportant (In fact, for this implementation, even
|
| 83 |
+
# word order is unimportant).
|
| 84 |
+
# Logical Hebrew - "windows-1255" - normal, naturally ordered text.
|
| 85 |
+
#
|
| 86 |
+
# "ISO-8859-8-I" is a subset of windows-1255 and doesn't need to be
|
| 87 |
+
# specifically identified.
|
| 88 |
+
# "x-mac-hebrew" is also identified as windows-1255. A text in x-mac-hebrew
|
| 89 |
+
# that contain special punctuation marks or diacritics is displayed with
|
| 90 |
+
# some unconverted characters showing as question marks. This problem might
|
| 91 |
+
# be corrected using another model prober for x-mac-hebrew. Due to the fact
|
| 92 |
+
# that x-mac-hebrew texts are so rare, writing another model prober isn't
|
| 93 |
+
# worth the effort and performance hit.
|
| 94 |
+
#
|
| 95 |
+
#### The Prober ####
|
| 96 |
+
#
|
| 97 |
+
# The prober is divided between two SBCharSetProbers and a HebrewProber,
|
| 98 |
+
# all of which are managed, created, fed data, inquired and deleted by the
|
| 99 |
+
# SBCSGroupProber. The two SBCharSetProbers identify that the text is in
|
| 100 |
+
# fact some kind of Hebrew, Logical or Visual. The final decision about which
|
| 101 |
+
# one is it is made by the HebrewProber by combining final-letter scores
|
| 102 |
+
# with the scores of the two SBCharSetProbers to produce a final answer.
|
| 103 |
+
#
|
| 104 |
+
# The SBCSGroupProber is responsible for stripping the original text of HTML
|
| 105 |
+
# tags, English characters, numbers, low-ASCII punctuation characters, spaces
|
| 106 |
+
# and new lines. It reduces any sequence of such characters to a single space.
|
| 107 |
+
# The buffer fed to each prober in the SBCS group prober is pure text in
|
| 108 |
+
# high-ASCII.
|
| 109 |
+
# The two SBCharSetProbers (model probers) share the same language model:
|
| 110 |
+
# Win1255Model.
|
| 111 |
+
# The first SBCharSetProber uses the model normally as any other
|
| 112 |
+
# SBCharSetProber does, to recognize windows-1255, upon which this model was
|
| 113 |
+
# built. The second SBCharSetProber is told to make the pair-of-letter
|
| 114 |
+
# lookup in the language model backwards. This in practice exactly simulates
|
| 115 |
+
# a visual Hebrew model using the windows-1255 logical Hebrew model.
|
| 116 |
+
#
|
| 117 |
+
# The HebrewProber is not using any language model. All it does is look for
|
| 118 |
+
# final-letter evidence suggesting the text is either logical Hebrew or visual
|
| 119 |
+
# Hebrew. Disjointed from the model probers, the results of the HebrewProber
|
| 120 |
+
# alone are meaningless. HebrewProber always returns 0.00 as confidence
|
| 121 |
+
# since it never identifies a charset by itself. Instead, the pointer to the
|
| 122 |
+
# HebrewProber is passed to the model probers as a helper "Name Prober".
|
| 123 |
+
# When the Group prober receives a positive identification from any prober,
|
| 124 |
+
# it asks for the name of the charset identified. If the prober queried is a
|
| 125 |
+
# Hebrew model prober, the model prober forwards the call to the
|
| 126 |
+
# HebrewProber to make the final decision. In the HebrewProber, the
|
| 127 |
+
# decision is made according to the final-letters scores maintained and Both
|
| 128 |
+
# model probers scores. The answer is returned in the form of the name of the
|
| 129 |
+
# charset identified, either "windows-1255" or "ISO-8859-8".
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
class HebrewProber(CharSetProber):
|
| 133 |
+
SPACE = 0x20
|
| 134 |
+
# windows-1255 / ISO-8859-8 code points of interest
|
| 135 |
+
FINAL_KAF = 0xEA
|
| 136 |
+
NORMAL_KAF = 0xEB
|
| 137 |
+
FINAL_MEM = 0xED
|
| 138 |
+
NORMAL_MEM = 0xEE
|
| 139 |
+
FINAL_NUN = 0xEF
|
| 140 |
+
NORMAL_NUN = 0xF0
|
| 141 |
+
FINAL_PE = 0xF3
|
| 142 |
+
NORMAL_PE = 0xF4
|
| 143 |
+
FINAL_TSADI = 0xF5
|
| 144 |
+
NORMAL_TSADI = 0xF6
|
| 145 |
+
|
| 146 |
+
# Minimum Visual vs Logical final letter score difference.
|
| 147 |
+
# If the difference is below this, don't rely solely on the final letter score
|
| 148 |
+
# distance.
|
| 149 |
+
MIN_FINAL_CHAR_DISTANCE = 5
|
| 150 |
+
|
| 151 |
+
# Minimum Visual vs Logical model score difference.
|
| 152 |
+
# If the difference is below this, don't rely at all on the model score
|
| 153 |
+
# distance.
|
| 154 |
+
MIN_MODEL_DISTANCE = 0.01
|
| 155 |
+
|
| 156 |
+
VISUAL_HEBREW_NAME = "ISO-8859-8"
|
| 157 |
+
LOGICAL_HEBREW_NAME = "windows-1255"
|
| 158 |
+
|
| 159 |
+
def __init__(self) -> None:
|
| 160 |
+
super().__init__()
|
| 161 |
+
self._final_char_logical_score = 0
|
| 162 |
+
self._final_char_visual_score = 0
|
| 163 |
+
self._prev = self.SPACE
|
| 164 |
+
self._before_prev = self.SPACE
|
| 165 |
+
self._logical_prober: Optional[SingleByteCharSetProber] = None
|
| 166 |
+
self._visual_prober: Optional[SingleByteCharSetProber] = None
|
| 167 |
+
self.reset()
|
| 168 |
+
|
| 169 |
+
def reset(self) -> None:
|
| 170 |
+
self._final_char_logical_score = 0
|
| 171 |
+
self._final_char_visual_score = 0
|
| 172 |
+
# The two last characters seen in the previous buffer,
|
| 173 |
+
# mPrev and mBeforePrev are initialized to space in order to simulate
|
| 174 |
+
# a word delimiter at the beginning of the data
|
| 175 |
+
self._prev = self.SPACE
|
| 176 |
+
self._before_prev = self.SPACE
|
| 177 |
+
# These probers are owned by the group prober.
|
| 178 |
+
|
| 179 |
+
def set_model_probers(
|
| 180 |
+
self,
|
| 181 |
+
logical_prober: SingleByteCharSetProber,
|
| 182 |
+
visual_prober: SingleByteCharSetProber,
|
| 183 |
+
) -> None:
|
| 184 |
+
self._logical_prober = logical_prober
|
| 185 |
+
self._visual_prober = visual_prober
|
| 186 |
+
|
| 187 |
+
def is_final(self, c: int) -> bool:
|
| 188 |
+
return c in [
|
| 189 |
+
self.FINAL_KAF,
|
| 190 |
+
self.FINAL_MEM,
|
| 191 |
+
self.FINAL_NUN,
|
| 192 |
+
self.FINAL_PE,
|
| 193 |
+
self.FINAL_TSADI,
|
| 194 |
+
]
|
| 195 |
+
|
| 196 |
+
def is_non_final(self, c: int) -> bool:
|
| 197 |
+
# The normal Tsadi is not a good Non-Final letter due to words like
|
| 198 |
+
# 'lechotet' (to chat) containing an apostrophe after the tsadi. This
|
| 199 |
+
# apostrophe is converted to a space in FilterWithoutEnglishLetters
|
| 200 |
+
# causing the Non-Final tsadi to appear at an end of a word even
|
| 201 |
+
# though this is not the case in the original text.
|
| 202 |
+
# The letters Pe and Kaf rarely display a related behavior of not being
|
| 203 |
+
# a good Non-Final letter. Words like 'Pop', 'Winamp' and 'Mubarak'
|
| 204 |
+
# for example legally end with a Non-Final Pe or Kaf. However, the
|
| 205 |
+
# benefit of these letters as Non-Final letters outweighs the damage
|
| 206 |
+
# since these words are quite rare.
|
| 207 |
+
return c in [self.NORMAL_KAF, self.NORMAL_MEM, self.NORMAL_NUN, self.NORMAL_PE]
|
| 208 |
+
|
| 209 |
+
def feed(self, byte_str: Union[bytes, bytearray]) -> ProbingState:
|
| 210 |
+
# Final letter analysis for logical-visual decision.
|
| 211 |
+
# Look for evidence that the received buffer is either logical Hebrew
|
| 212 |
+
# or visual Hebrew.
|
| 213 |
+
# The following cases are checked:
|
| 214 |
+
# 1) A word longer than 1 letter, ending with a final letter. This is
|
| 215 |
+
# an indication that the text is laid out "naturally" since the
|
| 216 |
+
# final letter really appears at the end. +1 for logical score.
|
| 217 |
+
# 2) A word longer than 1 letter, ending with a Non-Final letter. In
|
| 218 |
+
# normal Hebrew, words ending with Kaf, Mem, Nun, Pe or Tsadi,
|
| 219 |
+
# should not end with the Non-Final form of that letter. Exceptions
|
| 220 |
+
# to this rule are mentioned above in isNonFinal(). This is an
|
| 221 |
+
# indication that the text is laid out backwards. +1 for visual
|
| 222 |
+
# score
|
| 223 |
+
# 3) A word longer than 1 letter, starting with a final letter. Final
|
| 224 |
+
# letters should not appear at the beginning of a word. This is an
|
| 225 |
+
# indication that the text is laid out backwards. +1 for visual
|
| 226 |
+
# score.
|
| 227 |
+
#
|
| 228 |
+
# The visual score and logical score are accumulated throughout the
|
| 229 |
+
# text and are finally checked against each other in GetCharSetName().
|
| 230 |
+
# No checking for final letters in the middle of words is done since
|
| 231 |
+
# that case is not an indication for either Logical or Visual text.
|
| 232 |
+
#
|
| 233 |
+
# We automatically filter out all 7-bit characters (replace them with
|
| 234 |
+
# spaces) so the word boundary detection works properly. [MAP]
|
| 235 |
+
|
| 236 |
+
if self.state == ProbingState.NOT_ME:
|
| 237 |
+
# Both model probers say it's not them. No reason to continue.
|
| 238 |
+
return ProbingState.NOT_ME
|
| 239 |
+
|
| 240 |
+
byte_str = self.filter_high_byte_only(byte_str)
|
| 241 |
+
|
| 242 |
+
for cur in byte_str:
|
| 243 |
+
if cur == self.SPACE:
|
| 244 |
+
# We stand on a space - a word just ended
|
| 245 |
+
if self._before_prev != self.SPACE:
|
| 246 |
+
# next-to-last char was not a space so self._prev is not a
|
| 247 |
+
# 1 letter word
|
| 248 |
+
if self.is_final(self._prev):
|
| 249 |
+
# case (1) [-2:not space][-1:final letter][cur:space]
|
| 250 |
+
self._final_char_logical_score += 1
|
| 251 |
+
elif self.is_non_final(self._prev):
|
| 252 |
+
# case (2) [-2:not space][-1:Non-Final letter][
|
| 253 |
+
# cur:space]
|
| 254 |
+
self._final_char_visual_score += 1
|
| 255 |
+
else:
|
| 256 |
+
# Not standing on a space
|
| 257 |
+
if (
|
| 258 |
+
(self._before_prev == self.SPACE)
|
| 259 |
+
and (self.is_final(self._prev))
|
| 260 |
+
and (cur != self.SPACE)
|
| 261 |
+
):
|
| 262 |
+
# case (3) [-2:space][-1:final letter][cur:not space]
|
| 263 |
+
self._final_char_visual_score += 1
|
| 264 |
+
self._before_prev = self._prev
|
| 265 |
+
self._prev = cur
|
| 266 |
+
|
| 267 |
+
# Forever detecting, till the end or until both model probers return
|
| 268 |
+
# ProbingState.NOT_ME (handled above)
|
| 269 |
+
return ProbingState.DETECTING
|
| 270 |
+
|
| 271 |
+
@property
|
| 272 |
+
def charset_name(self) -> str:
|
| 273 |
+
assert self._logical_prober is not None
|
| 274 |
+
assert self._visual_prober is not None
|
| 275 |
+
|
| 276 |
+
# Make the decision: is it Logical or Visual?
|
| 277 |
+
# If the final letter score distance is dominant enough, rely on it.
|
| 278 |
+
finalsub = self._final_char_logical_score - self._final_char_visual_score
|
| 279 |
+
if finalsub >= self.MIN_FINAL_CHAR_DISTANCE:
|
| 280 |
+
return self.LOGICAL_HEBREW_NAME
|
| 281 |
+
if finalsub <= -self.MIN_FINAL_CHAR_DISTANCE:
|
| 282 |
+
return self.VISUAL_HEBREW_NAME
|
| 283 |
+
|
| 284 |
+
# It's not dominant enough, try to rely on the model scores instead.
|
| 285 |
+
modelsub = (
|
| 286 |
+
self._logical_prober.get_confidence() - self._visual_prober.get_confidence()
|
| 287 |
+
)
|
| 288 |
+
if modelsub > self.MIN_MODEL_DISTANCE:
|
| 289 |
+
return self.LOGICAL_HEBREW_NAME
|
| 290 |
+
if modelsub < -self.MIN_MODEL_DISTANCE:
|
| 291 |
+
return self.VISUAL_HEBREW_NAME
|
| 292 |
+
|
| 293 |
+
# Still no good, back to final letter distance, maybe it'll save the
|
| 294 |
+
# day.
|
| 295 |
+
if finalsub < 0.0:
|
| 296 |
+
return self.VISUAL_HEBREW_NAME
|
| 297 |
+
|
| 298 |
+
# (finalsub > 0 - Logical) or (don't know what to do) default to
|
| 299 |
+
# Logical.
|
| 300 |
+
return self.LOGICAL_HEBREW_NAME
|
| 301 |
+
|
| 302 |
+
@property
|
| 303 |
+
def language(self) -> str:
|
| 304 |
+
return "Hebrew"
|
| 305 |
+
|
| 306 |
+
@property
|
| 307 |
+
def state(self) -> ProbingState:
|
| 308 |
+
assert self._logical_prober is not None
|
| 309 |
+
assert self._visual_prober is not None
|
| 310 |
+
|
| 311 |
+
# Remain active as long as any of the model probers are active.
|
| 312 |
+
if (self._logical_prober.state == ProbingState.NOT_ME) and (
|
| 313 |
+
self._visual_prober.state == ProbingState.NOT_ME
|
| 314 |
+
):
|
| 315 |
+
return ProbingState.NOT_ME
|
| 316 |
+
return ProbingState.DETECTING
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/jisfreq.py
ADDED
|
@@ -0,0 +1,325 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
######################## BEGIN LICENSE BLOCK ########################
|
| 2 |
+
# The Original Code is Mozilla Communicator client code.
|
| 3 |
+
#
|
| 4 |
+
# The Initial Developer of the Original Code is
|
| 5 |
+
# Netscape Communications Corporation.
|
| 6 |
+
# Portions created by the Initial Developer are Copyright (C) 1998
|
| 7 |
+
# the Initial Developer. All Rights Reserved.
|
| 8 |
+
#
|
| 9 |
+
# Contributor(s):
|
| 10 |
+
# Mark Pilgrim - port to Python
|
| 11 |
+
#
|
| 12 |
+
# This library is free software; you can redistribute it and/or
|
| 13 |
+
# modify it under the terms of the GNU Lesser General Public
|
| 14 |
+
# License as published by the Free Software Foundation; either
|
| 15 |
+
# version 2.1 of the License, or (at your option) any later version.
|
| 16 |
+
#
|
| 17 |
+
# This library is distributed in the hope that it will be useful,
|
| 18 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 19 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 20 |
+
# Lesser General Public License for more details.
|
| 21 |
+
#
|
| 22 |
+
# You should have received a copy of the GNU Lesser General Public
|
| 23 |
+
# License along with this library; if not, write to the Free Software
|
| 24 |
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
| 25 |
+
# 02110-1301 USA
|
| 26 |
+
######################### END LICENSE BLOCK #########################
|
| 27 |
+
|
| 28 |
+
# Sampling from about 20M text materials include literature and computer technology
|
| 29 |
+
#
|
| 30 |
+
# Japanese frequency table, applied to both S-JIS and EUC-JP
|
| 31 |
+
# They are sorted in order.
|
| 32 |
+
|
| 33 |
+
# 128 --> 0.77094
|
| 34 |
+
# 256 --> 0.85710
|
| 35 |
+
# 512 --> 0.92635
|
| 36 |
+
# 1024 --> 0.97130
|
| 37 |
+
# 2048 --> 0.99431
|
| 38 |
+
#
|
| 39 |
+
# Ideal Distribution Ratio = 0.92635 / (1-0.92635) = 12.58
|
| 40 |
+
# Random Distribution Ration = 512 / (2965+62+83+86-512) = 0.191
|
| 41 |
+
#
|
| 42 |
+
# Typical Distribution Ratio, 25% of IDR
|
| 43 |
+
|
| 44 |
+
JIS_TYPICAL_DISTRIBUTION_RATIO = 3.0
|
| 45 |
+
|
| 46 |
+
# Char to FreqOrder table ,
|
| 47 |
+
JIS_TABLE_SIZE = 4368
|
| 48 |
+
|
| 49 |
+
# fmt: off
|
| 50 |
+
JIS_CHAR_TO_FREQ_ORDER = (
|
| 51 |
+
40, 1, 6, 182, 152, 180, 295,2127, 285, 381,3295,4304,3068,4606,3165,3510, # 16
|
| 52 |
+
3511,1822,2785,4607,1193,2226,5070,4608, 171,2996,1247, 18, 179,5071, 856,1661, # 32
|
| 53 |
+
1262,5072, 619, 127,3431,3512,3230,1899,1700, 232, 228,1294,1298, 284, 283,2041, # 48
|
| 54 |
+
2042,1061,1062, 48, 49, 44, 45, 433, 434,1040,1041, 996, 787,2997,1255,4305, # 64
|
| 55 |
+
2108,4609,1684,1648,5073,5074,5075,5076,5077,5078,3687,5079,4610,5080,3927,3928, # 80
|
| 56 |
+
5081,3296,3432, 290,2285,1471,2187,5082,2580,2825,1303,2140,1739,1445,2691,3375, # 96
|
| 57 |
+
1691,3297,4306,4307,4611, 452,3376,1182,2713,3688,3069,4308,5083,5084,5085,5086, # 112
|
| 58 |
+
5087,5088,5089,5090,5091,5092,5093,5094,5095,5096,5097,5098,5099,5100,5101,5102, # 128
|
| 59 |
+
5103,5104,5105,5106,5107,5108,5109,5110,5111,5112,4097,5113,5114,5115,5116,5117, # 144
|
| 60 |
+
5118,5119,5120,5121,5122,5123,5124,5125,5126,5127,5128,5129,5130,5131,5132,5133, # 160
|
| 61 |
+
5134,5135,5136,5137,5138,5139,5140,5141,5142,5143,5144,5145,5146,5147,5148,5149, # 176
|
| 62 |
+
5150,5151,5152,4612,5153,5154,5155,5156,5157,5158,5159,5160,5161,5162,5163,5164, # 192
|
| 63 |
+
5165,5166,5167,5168,5169,5170,5171,5172,5173,5174,5175,1472, 598, 618, 820,1205, # 208
|
| 64 |
+
1309,1412,1858,1307,1692,5176,5177,5178,5179,5180,5181,5182,1142,1452,1234,1172, # 224
|
| 65 |
+
1875,2043,2149,1793,1382,2973, 925,2404,1067,1241, 960,1377,2935,1491, 919,1217, # 240
|
| 66 |
+
1865,2030,1406,1499,2749,4098,5183,5184,5185,5186,5187,5188,2561,4099,3117,1804, # 256
|
| 67 |
+
2049,3689,4309,3513,1663,5189,3166,3118,3298,1587,1561,3433,5190,3119,1625,2998, # 272
|
| 68 |
+
3299,4613,1766,3690,2786,4614,5191,5192,5193,5194,2161, 26,3377, 2,3929, 20, # 288
|
| 69 |
+
3691, 47,4100, 50, 17, 16, 35, 268, 27, 243, 42, 155, 24, 154, 29, 184, # 304
|
| 70 |
+
4, 91, 14, 92, 53, 396, 33, 289, 9, 37, 64, 620, 21, 39, 321, 5, # 320
|
| 71 |
+
12, 11, 52, 13, 3, 208, 138, 0, 7, 60, 526, 141, 151,1069, 181, 275, # 336
|
| 72 |
+
1591, 83, 132,1475, 126, 331, 829, 15, 69, 160, 59, 22, 157, 55,1079, 312, # 352
|
| 73 |
+
109, 38, 23, 25, 10, 19, 79,5195, 61, 382,1124, 8, 30,5196,5197,5198, # 368
|
| 74 |
+
5199,5200,5201,5202,5203,5204,5205,5206, 89, 62, 74, 34,2416, 112, 139, 196, # 384
|
| 75 |
+
271, 149, 84, 607, 131, 765, 46, 88, 153, 683, 76, 874, 101, 258, 57, 80, # 400
|
| 76 |
+
32, 364, 121,1508, 169,1547, 68, 235, 145,2999, 41, 360,3027, 70, 63, 31, # 416
|
| 77 |
+
43, 259, 262,1383, 99, 533, 194, 66, 93, 846, 217, 192, 56, 106, 58, 565, # 432
|
| 78 |
+
280, 272, 311, 256, 146, 82, 308, 71, 100, 128, 214, 655, 110, 261, 104,1140, # 448
|
| 79 |
+
54, 51, 36, 87, 67,3070, 185,2618,2936,2020, 28,1066,2390,2059,5207,5208, # 464
|
| 80 |
+
5209,5210,5211,5212,5213,5214,5215,5216,4615,5217,5218,5219,5220,5221,5222,5223, # 480
|
| 81 |
+
5224,5225,5226,5227,5228,5229,5230,5231,5232,5233,5234,5235,5236,3514,5237,5238, # 496
|
| 82 |
+
5239,5240,5241,5242,5243,5244,2297,2031,4616,4310,3692,5245,3071,5246,3598,5247, # 512
|
| 83 |
+
4617,3231,3515,5248,4101,4311,4618,3808,4312,4102,5249,4103,4104,3599,5250,5251, # 528
|
| 84 |
+
5252,5253,5254,5255,5256,5257,5258,5259,5260,5261,5262,5263,5264,5265,5266,5267, # 544
|
| 85 |
+
5268,5269,5270,5271,5272,5273,5274,5275,5276,5277,5278,5279,5280,5281,5282,5283, # 560
|
| 86 |
+
5284,5285,5286,5287,5288,5289,5290,5291,5292,5293,5294,5295,5296,5297,5298,5299, # 576
|
| 87 |
+
5300,5301,5302,5303,5304,5305,5306,5307,5308,5309,5310,5311,5312,5313,5314,5315, # 592
|
| 88 |
+
5316,5317,5318,5319,5320,5321,5322,5323,5324,5325,5326,5327,5328,5329,5330,5331, # 608
|
| 89 |
+
5332,5333,5334,5335,5336,5337,5338,5339,5340,5341,5342,5343,5344,5345,5346,5347, # 624
|
| 90 |
+
5348,5349,5350,5351,5352,5353,5354,5355,5356,5357,5358,5359,5360,5361,5362,5363, # 640
|
| 91 |
+
5364,5365,5366,5367,5368,5369,5370,5371,5372,5373,5374,5375,5376,5377,5378,5379, # 656
|
| 92 |
+
5380,5381, 363, 642,2787,2878,2788,2789,2316,3232,2317,3434,2011, 165,1942,3930, # 672
|
| 93 |
+
3931,3932,3933,5382,4619,5383,4620,5384,5385,5386,5387,5388,5389,5390,5391,5392, # 688
|
| 94 |
+
5393,5394,5395,5396,5397,5398,5399,5400,5401,5402,5403,5404,5405,5406,5407,5408, # 704
|
| 95 |
+
5409,5410,5411,5412,5413,5414,5415,5416,5417,5418,5419,5420,5421,5422,5423,5424, # 720
|
| 96 |
+
5425,5426,5427,5428,5429,5430,5431,5432,5433,5434,5435,5436,5437,5438,5439,5440, # 736
|
| 97 |
+
5441,5442,5443,5444,5445,5446,5447,5448,5449,5450,5451,5452,5453,5454,5455,5456, # 752
|
| 98 |
+
5457,5458,5459,5460,5461,5462,5463,5464,5465,5466,5467,5468,5469,5470,5471,5472, # 768
|
| 99 |
+
5473,5474,5475,5476,5477,5478,5479,5480,5481,5482,5483,5484,5485,5486,5487,5488, # 784
|
| 100 |
+
5489,5490,5491,5492,5493,5494,5495,5496,5497,5498,5499,5500,5501,5502,5503,5504, # 800
|
| 101 |
+
5505,5506,5507,5508,5509,5510,5511,5512,5513,5514,5515,5516,5517,5518,5519,5520, # 816
|
| 102 |
+
5521,5522,5523,5524,5525,5526,5527,5528,5529,5530,5531,5532,5533,5534,5535,5536, # 832
|
| 103 |
+
5537,5538,5539,5540,5541,5542,5543,5544,5545,5546,5547,5548,5549,5550,5551,5552, # 848
|
| 104 |
+
5553,5554,5555,5556,5557,5558,5559,5560,5561,5562,5563,5564,5565,5566,5567,5568, # 864
|
| 105 |
+
5569,5570,5571,5572,5573,5574,5575,5576,5577,5578,5579,5580,5581,5582,5583,5584, # 880
|
| 106 |
+
5585,5586,5587,5588,5589,5590,5591,5592,5593,5594,5595,5596,5597,5598,5599,5600, # 896
|
| 107 |
+
5601,5602,5603,5604,5605,5606,5607,5608,5609,5610,5611,5612,5613,5614,5615,5616, # 912
|
| 108 |
+
5617,5618,5619,5620,5621,5622,5623,5624,5625,5626,5627,5628,5629,5630,5631,5632, # 928
|
| 109 |
+
5633,5634,5635,5636,5637,5638,5639,5640,5641,5642,5643,5644,5645,5646,5647,5648, # 944
|
| 110 |
+
5649,5650,5651,5652,5653,5654,5655,5656,5657,5658,5659,5660,5661,5662,5663,5664, # 960
|
| 111 |
+
5665,5666,5667,5668,5669,5670,5671,5672,5673,5674,5675,5676,5677,5678,5679,5680, # 976
|
| 112 |
+
5681,5682,5683,5684,5685,5686,5687,5688,5689,5690,5691,5692,5693,5694,5695,5696, # 992
|
| 113 |
+
5697,5698,5699,5700,5701,5702,5703,5704,5705,5706,5707,5708,5709,5710,5711,5712, # 1008
|
| 114 |
+
5713,5714,5715,5716,5717,5718,5719,5720,5721,5722,5723,5724,5725,5726,5727,5728, # 1024
|
| 115 |
+
5729,5730,5731,5732,5733,5734,5735,5736,5737,5738,5739,5740,5741,5742,5743,5744, # 1040
|
| 116 |
+
5745,5746,5747,5748,5749,5750,5751,5752,5753,5754,5755,5756,5757,5758,5759,5760, # 1056
|
| 117 |
+
5761,5762,5763,5764,5765,5766,5767,5768,5769,5770,5771,5772,5773,5774,5775,5776, # 1072
|
| 118 |
+
5777,5778,5779,5780,5781,5782,5783,5784,5785,5786,5787,5788,5789,5790,5791,5792, # 1088
|
| 119 |
+
5793,5794,5795,5796,5797,5798,5799,5800,5801,5802,5803,5804,5805,5806,5807,5808, # 1104
|
| 120 |
+
5809,5810,5811,5812,5813,5814,5815,5816,5817,5818,5819,5820,5821,5822,5823,5824, # 1120
|
| 121 |
+
5825,5826,5827,5828,5829,5830,5831,5832,5833,5834,5835,5836,5837,5838,5839,5840, # 1136
|
| 122 |
+
5841,5842,5843,5844,5845,5846,5847,5848,5849,5850,5851,5852,5853,5854,5855,5856, # 1152
|
| 123 |
+
5857,5858,5859,5860,5861,5862,5863,5864,5865,5866,5867,5868,5869,5870,5871,5872, # 1168
|
| 124 |
+
5873,5874,5875,5876,5877,5878,5879,5880,5881,5882,5883,5884,5885,5886,5887,5888, # 1184
|
| 125 |
+
5889,5890,5891,5892,5893,5894,5895,5896,5897,5898,5899,5900,5901,5902,5903,5904, # 1200
|
| 126 |
+
5905,5906,5907,5908,5909,5910,5911,5912,5913,5914,5915,5916,5917,5918,5919,5920, # 1216
|
| 127 |
+
5921,5922,5923,5924,5925,5926,5927,5928,5929,5930,5931,5932,5933,5934,5935,5936, # 1232
|
| 128 |
+
5937,5938,5939,5940,5941,5942,5943,5944,5945,5946,5947,5948,5949,5950,5951,5952, # 1248
|
| 129 |
+
5953,5954,5955,5956,5957,5958,5959,5960,5961,5962,5963,5964,5965,5966,5967,5968, # 1264
|
| 130 |
+
5969,5970,5971,5972,5973,5974,5975,5976,5977,5978,5979,5980,5981,5982,5983,5984, # 1280
|
| 131 |
+
5985,5986,5987,5988,5989,5990,5991,5992,5993,5994,5995,5996,5997,5998,5999,6000, # 1296
|
| 132 |
+
6001,6002,6003,6004,6005,6006,6007,6008,6009,6010,6011,6012,6013,6014,6015,6016, # 1312
|
| 133 |
+
6017,6018,6019,6020,6021,6022,6023,6024,6025,6026,6027,6028,6029,6030,6031,6032, # 1328
|
| 134 |
+
6033,6034,6035,6036,6037,6038,6039,6040,6041,6042,6043,6044,6045,6046,6047,6048, # 1344
|
| 135 |
+
6049,6050,6051,6052,6053,6054,6055,6056,6057,6058,6059,6060,6061,6062,6063,6064, # 1360
|
| 136 |
+
6065,6066,6067,6068,6069,6070,6071,6072,6073,6074,6075,6076,6077,6078,6079,6080, # 1376
|
| 137 |
+
6081,6082,6083,6084,6085,6086,6087,6088,6089,6090,6091,6092,6093,6094,6095,6096, # 1392
|
| 138 |
+
6097,6098,6099,6100,6101,6102,6103,6104,6105,6106,6107,6108,6109,6110,6111,6112, # 1408
|
| 139 |
+
6113,6114,2044,2060,4621, 997,1235, 473,1186,4622, 920,3378,6115,6116, 379,1108, # 1424
|
| 140 |
+
4313,2657,2735,3934,6117,3809, 636,3233, 573,1026,3693,3435,2974,3300,2298,4105, # 1440
|
| 141 |
+
854,2937,2463, 393,2581,2417, 539, 752,1280,2750,2480, 140,1161, 440, 708,1569, # 1456
|
| 142 |
+
665,2497,1746,1291,1523,3000, 164,1603, 847,1331, 537,1997, 486, 508,1693,2418, # 1472
|
| 143 |
+
1970,2227, 878,1220, 299,1030, 969, 652,2751, 624,1137,3301,2619, 65,3302,2045, # 1488
|
| 144 |
+
1761,1859,3120,1930,3694,3516, 663,1767, 852, 835,3695, 269, 767,2826,2339,1305, # 1504
|
| 145 |
+
896,1150, 770,1616,6118, 506,1502,2075,1012,2519, 775,2520,2975,2340,2938,4314, # 1520
|
| 146 |
+
3028,2086,1224,1943,2286,6119,3072,4315,2240,1273,1987,3935,1557, 175, 597, 985, # 1536
|
| 147 |
+
3517,2419,2521,1416,3029, 585, 938,1931,1007,1052,1932,1685,6120,3379,4316,4623, # 1552
|
| 148 |
+
804, 599,3121,1333,2128,2539,1159,1554,2032,3810, 687,2033,2904, 952, 675,1467, # 1568
|
| 149 |
+
3436,6121,2241,1096,1786,2440,1543,1924, 980,1813,2228, 781,2692,1879, 728,1918, # 1584
|
| 150 |
+
3696,4624, 548,1950,4625,1809,1088,1356,3303,2522,1944, 502, 972, 373, 513,2827, # 1600
|
| 151 |
+
586,2377,2391,1003,1976,1631,6122,2464,1084, 648,1776,4626,2141, 324, 962,2012, # 1616
|
| 152 |
+
2177,2076,1384, 742,2178,1448,1173,1810, 222, 102, 301, 445, 125,2420, 662,2498, # 1632
|
| 153 |
+
277, 200,1476,1165,1068, 224,2562,1378,1446, 450,1880, 659, 791, 582,4627,2939, # 1648
|
| 154 |
+
3936,1516,1274, 555,2099,3697,1020,1389,1526,3380,1762,1723,1787,2229, 412,2114, # 1664
|
| 155 |
+
1900,2392,3518, 512,2597, 427,1925,2341,3122,1653,1686,2465,2499, 697, 330, 273, # 1680
|
| 156 |
+
380,2162, 951, 832, 780, 991,1301,3073, 965,2270,3519, 668,2523,2636,1286, 535, # 1696
|
| 157 |
+
1407, 518, 671, 957,2658,2378, 267, 611,2197,3030,6123, 248,2299, 967,1799,2356, # 1712
|
| 158 |
+
850,1418,3437,1876,1256,1480,2828,1718,6124,6125,1755,1664,2405,6126,4628,2879, # 1728
|
| 159 |
+
2829, 499,2179, 676,4629, 557,2329,2214,2090, 325,3234, 464, 811,3001, 992,2342, # 1744
|
| 160 |
+
2481,1232,1469, 303,2242, 466,1070,2163, 603,1777,2091,4630,2752,4631,2714, 322, # 1760
|
| 161 |
+
2659,1964,1768, 481,2188,1463,2330,2857,3600,2092,3031,2421,4632,2318,2070,1849, # 1776
|
| 162 |
+
2598,4633,1302,2254,1668,1701,2422,3811,2905,3032,3123,2046,4106,1763,1694,4634, # 1792
|
| 163 |
+
1604, 943,1724,1454, 917, 868,2215,1169,2940, 552,1145,1800,1228,1823,1955, 316, # 1808
|
| 164 |
+
1080,2510, 361,1807,2830,4107,2660,3381,1346,1423,1134,4108,6127, 541,1263,1229, # 1824
|
| 165 |
+
1148,2540, 545, 465,1833,2880,3438,1901,3074,2482, 816,3937, 713,1788,2500, 122, # 1840
|
| 166 |
+
1575, 195,1451,2501,1111,6128, 859, 374,1225,2243,2483,4317, 390,1033,3439,3075, # 1856
|
| 167 |
+
2524,1687, 266, 793,1440,2599, 946, 779, 802, 507, 897,1081, 528,2189,1292, 711, # 1872
|
| 168 |
+
1866,1725,1167,1640, 753, 398,2661,1053, 246, 348,4318, 137,1024,3440,1600,2077, # 1888
|
| 169 |
+
2129, 825,4319, 698, 238, 521, 187,2300,1157,2423,1641,1605,1464,1610,1097,2541, # 1904
|
| 170 |
+
1260,1436, 759,2255,1814,2150, 705,3235, 409,2563,3304, 561,3033,2005,2564, 726, # 1920
|
| 171 |
+
1956,2343,3698,4109, 949,3812,3813,3520,1669, 653,1379,2525, 881,2198, 632,2256, # 1936
|
| 172 |
+
1027, 778,1074, 733,1957, 514,1481,2466, 554,2180, 702,3938,1606,1017,1398,6129, # 1952
|
| 173 |
+
1380,3521, 921, 993,1313, 594, 449,1489,1617,1166, 768,1426,1360, 495,1794,3601, # 1968
|
| 174 |
+
1177,3602,1170,4320,2344, 476, 425,3167,4635,3168,1424, 401,2662,1171,3382,1998, # 1984
|
| 175 |
+
1089,4110, 477,3169, 474,6130,1909, 596,2831,1842, 494, 693,1051,1028,1207,3076, # 2000
|
| 176 |
+
606,2115, 727,2790,1473,1115, 743,3522, 630, 805,1532,4321,2021, 366,1057, 838, # 2016
|
| 177 |
+
684,1114,2142,4322,2050,1492,1892,1808,2271,3814,2424,1971,1447,1373,3305,1090, # 2032
|
| 178 |
+
1536,3939,3523,3306,1455,2199, 336, 369,2331,1035, 584,2393, 902, 718,2600,6131, # 2048
|
| 179 |
+
2753, 463,2151,1149,1611,2467, 715,1308,3124,1268, 343,1413,3236,1517,1347,2663, # 2064
|
| 180 |
+
2093,3940,2022,1131,1553,2100,2941,1427,3441,2942,1323,2484,6132,1980, 872,2368, # 2080
|
| 181 |
+
2441,2943, 320,2369,2116,1082, 679,1933,3941,2791,3815, 625,1143,2023, 422,2200, # 2096
|
| 182 |
+
3816,6133, 730,1695, 356,2257,1626,2301,2858,2637,1627,1778, 937, 883,2906,2693, # 2112
|
| 183 |
+
3002,1769,1086, 400,1063,1325,3307,2792,4111,3077, 456,2345,1046, 747,6134,1524, # 2128
|
| 184 |
+
884,1094,3383,1474,2164,1059, 974,1688,2181,2258,1047, 345,1665,1187, 358, 875, # 2144
|
| 185 |
+
3170, 305, 660,3524,2190,1334,1135,3171,1540,1649,2542,1527, 927, 968,2793, 885, # 2160
|
| 186 |
+
1972,1850, 482, 500,2638,1218,1109,1085,2543,1654,2034, 876, 78,2287,1482,1277, # 2176
|
| 187 |
+
861,1675,1083,1779, 724,2754, 454, 397,1132,1612,2332, 893, 672,1237, 257,2259, # 2192
|
| 188 |
+
2370, 135,3384, 337,2244, 547, 352, 340, 709,2485,1400, 788,1138,2511, 540, 772, # 2208
|
| 189 |
+
1682,2260,2272,2544,2013,1843,1902,4636,1999,1562,2288,4637,2201,1403,1533, 407, # 2224
|
| 190 |
+
576,3308,1254,2071, 978,3385, 170, 136,1201,3125,2664,3172,2394, 213, 912, 873, # 2240
|
| 191 |
+
3603,1713,2202, 699,3604,3699, 813,3442, 493, 531,1054, 468,2907,1483, 304, 281, # 2256
|
| 192 |
+
4112,1726,1252,2094, 339,2319,2130,2639, 756,1563,2944, 748, 571,2976,1588,2425, # 2272
|
| 193 |
+
2715,1851,1460,2426,1528,1392,1973,3237, 288,3309, 685,3386, 296, 892,2716,2216, # 2288
|
| 194 |
+
1570,2245, 722,1747,2217, 905,3238,1103,6135,1893,1441,1965, 251,1805,2371,3700, # 2304
|
| 195 |
+
2601,1919,1078, 75,2182,1509,1592,1270,2640,4638,2152,6136,3310,3817, 524, 706, # 2320
|
| 196 |
+
1075, 292,3818,1756,2602, 317, 98,3173,3605,3525,1844,2218,3819,2502, 814, 567, # 2336
|
| 197 |
+
385,2908,1534,6137, 534,1642,3239, 797,6138,1670,1529, 953,4323, 188,1071, 538, # 2352
|
| 198 |
+
178, 729,3240,2109,1226,1374,2000,2357,2977, 731,2468,1116,2014,2051,6139,1261, # 2368
|
| 199 |
+
1593, 803,2859,2736,3443, 556, 682, 823,1541,6140,1369,2289,1706,2794, 845, 462, # 2384
|
| 200 |
+
2603,2665,1361, 387, 162,2358,1740, 739,1770,1720,1304,1401,3241,1049, 627,1571, # 2400
|
| 201 |
+
2427,3526,1877,3942,1852,1500, 431,1910,1503, 677, 297,2795, 286,1433,1038,1198, # 2416
|
| 202 |
+
2290,1133,1596,4113,4639,2469,1510,1484,3943,6141,2442, 108, 712,4640,2372, 866, # 2432
|
| 203 |
+
3701,2755,3242,1348, 834,1945,1408,3527,2395,3243,1811, 824, 994,1179,2110,1548, # 2448
|
| 204 |
+
1453, 790,3003, 690,4324,4325,2832,2909,3820,1860,3821, 225,1748, 310, 346,1780, # 2464
|
| 205 |
+
2470, 821,1993,2717,2796, 828, 877,3528,2860,2471,1702,2165,2910,2486,1789, 453, # 2480
|
| 206 |
+
359,2291,1676, 73,1164,1461,1127,3311, 421, 604, 314,1037, 589, 116,2487, 737, # 2496
|
| 207 |
+
837,1180, 111, 244, 735,6142,2261,1861,1362, 986, 523, 418, 581,2666,3822, 103, # 2512
|
| 208 |
+
855, 503,1414,1867,2488,1091, 657,1597, 979, 605,1316,4641,1021,2443,2078,2001, # 2528
|
| 209 |
+
1209, 96, 587,2166,1032, 260,1072,2153, 173, 94, 226,3244, 819,2006,4642,4114, # 2544
|
| 210 |
+
2203, 231,1744, 782, 97,2667, 786,3387, 887, 391, 442,2219,4326,1425,6143,2694, # 2560
|
| 211 |
+
633,1544,1202, 483,2015, 592,2052,1958,2472,1655, 419, 129,4327,3444,3312,1714, # 2576
|
| 212 |
+
1257,3078,4328,1518,1098, 865,1310,1019,1885,1512,1734, 469,2444, 148, 773, 436, # 2592
|
| 213 |
+
1815,1868,1128,1055,4329,1245,2756,3445,2154,1934,1039,4643, 579,1238, 932,2320, # 2608
|
| 214 |
+
353, 205, 801, 115,2428, 944,2321,1881, 399,2565,1211, 678, 766,3944, 335,2101, # 2624
|
| 215 |
+
1459,1781,1402,3945,2737,2131,1010, 844, 981,1326,1013, 550,1816,1545,2620,1335, # 2640
|
| 216 |
+
1008, 371,2881, 936,1419,1613,3529,1456,1395,2273,1834,2604,1317,2738,2503, 416, # 2656
|
| 217 |
+
1643,4330, 806,1126, 229, 591,3946,1314,1981,1576,1837,1666, 347,1790, 977,3313, # 2672
|
| 218 |
+
764,2861,1853, 688,2429,1920,1462, 77, 595, 415,2002,3034, 798,1192,4115,6144, # 2688
|
| 219 |
+
2978,4331,3035,2695,2582,2072,2566, 430,2430,1727, 842,1396,3947,3702, 613, 377, # 2704
|
| 220 |
+
278, 236,1417,3388,3314,3174, 757,1869, 107,3530,6145,1194, 623,2262, 207,1253, # 2720
|
| 221 |
+
2167,3446,3948, 492,1117,1935, 536,1838,2757,1246,4332, 696,2095,2406,1393,1572, # 2736
|
| 222 |
+
3175,1782, 583, 190, 253,1390,2230, 830,3126,3389, 934,3245,1703,1749,2979,1870, # 2752
|
| 223 |
+
2545,1656,2204, 869,2346,4116,3176,1817, 496,1764,4644, 942,1504, 404,1903,1122, # 2768
|
| 224 |
+
1580,3606,2945,1022, 515, 372,1735, 955,2431,3036,6146,2797,1110,2302,2798, 617, # 2784
|
| 225 |
+
6147, 441, 762,1771,3447,3607,3608,1904, 840,3037, 86, 939,1385, 572,1370,2445, # 2800
|
| 226 |
+
1336, 114,3703, 898, 294, 203,3315, 703,1583,2274, 429, 961,4333,1854,1951,3390, # 2816
|
| 227 |
+
2373,3704,4334,1318,1381, 966,1911,2322,1006,1155, 309, 989, 458,2718,1795,1372, # 2832
|
| 228 |
+
1203, 252,1689,1363,3177, 517,1936, 168,1490, 562, 193,3823,1042,4117,1835, 551, # 2848
|
| 229 |
+
470,4645, 395, 489,3448,1871,1465,2583,2641, 417,1493, 279,1295, 511,1236,1119, # 2864
|
| 230 |
+
72,1231,1982,1812,3004, 871,1564, 984,3449,1667,2696,2096,4646,2347,2833,1673, # 2880
|
| 231 |
+
3609, 695,3246,2668, 807,1183,4647, 890, 388,2333,1801,1457,2911,1765,1477,1031, # 2896
|
| 232 |
+
3316,3317,1278,3391,2799,2292,2526, 163,3450,4335,2669,1404,1802,6148,2323,2407, # 2912
|
| 233 |
+
1584,1728,1494,1824,1269, 298, 909,3318,1034,1632, 375, 776,1683,2061, 291, 210, # 2928
|
| 234 |
+
1123, 809,1249,1002,2642,3038, 206,1011,2132, 144, 975, 882,1565, 342, 667, 754, # 2944
|
| 235 |
+
1442,2143,1299,2303,2062, 447, 626,2205,1221,2739,2912,1144,1214,2206,2584, 760, # 2960
|
| 236 |
+
1715, 614, 950,1281,2670,2621, 810, 577,1287,2546,4648, 242,2168, 250,2643, 691, # 2976
|
| 237 |
+
123,2644, 647, 313,1029, 689,1357,2946,1650, 216, 771,1339,1306, 808,2063, 549, # 2992
|
| 238 |
+
913,1371,2913,2914,6149,1466,1092,1174,1196,1311,2605,2396,1783,1796,3079, 406, # 3008
|
| 239 |
+
2671,2117,3949,4649, 487,1825,2220,6150,2915, 448,2348,1073,6151,2397,1707, 130, # 3024
|
| 240 |
+
900,1598, 329, 176,1959,2527,1620,6152,2275,4336,3319,1983,2191,3705,3610,2155, # 3040
|
| 241 |
+
3706,1912,1513,1614,6153,1988, 646, 392,2304,1589,3320,3039,1826,1239,1352,1340, # 3056
|
| 242 |
+
2916, 505,2567,1709,1437,2408,2547, 906,6154,2672, 384,1458,1594,1100,1329, 710, # 3072
|
| 243 |
+
423,3531,2064,2231,2622,1989,2673,1087,1882, 333, 841,3005,1296,2882,2379, 580, # 3088
|
| 244 |
+
1937,1827,1293,2585, 601, 574, 249,1772,4118,2079,1120, 645, 901,1176,1690, 795, # 3104
|
| 245 |
+
2207, 478,1434, 516,1190,1530, 761,2080, 930,1264, 355, 435,1552, 644,1791, 987, # 3120
|
| 246 |
+
220,1364,1163,1121,1538, 306,2169,1327,1222, 546,2645, 218, 241, 610,1704,3321, # 3136
|
| 247 |
+
1984,1839,1966,2528, 451,6155,2586,3707,2568, 907,3178, 254,2947, 186,1845,4650, # 3152
|
| 248 |
+
745, 432,1757, 428,1633, 888,2246,2221,2489,3611,2118,1258,1265, 956,3127,1784, # 3168
|
| 249 |
+
4337,2490, 319, 510, 119, 457,3612, 274,2035,2007,4651,1409,3128, 970,2758, 590, # 3184
|
| 250 |
+
2800, 661,2247,4652,2008,3950,1420,1549,3080,3322,3951,1651,1375,2111, 485,2491, # 3200
|
| 251 |
+
1429,1156,6156,2548,2183,1495, 831,1840,2529,2446, 501,1657, 307,1894,3247,1341, # 3216
|
| 252 |
+
666, 899,2156,1539,2549,1559, 886, 349,2208,3081,2305,1736,3824,2170,2759,1014, # 3232
|
| 253 |
+
1913,1386, 542,1397,2948, 490, 368, 716, 362, 159, 282,2569,1129,1658,1288,1750, # 3248
|
| 254 |
+
2674, 276, 649,2016, 751,1496, 658,1818,1284,1862,2209,2087,2512,3451, 622,2834, # 3264
|
| 255 |
+
376, 117,1060,2053,1208,1721,1101,1443, 247,1250,3179,1792,3952,2760,2398,3953, # 3280
|
| 256 |
+
6157,2144,3708, 446,2432,1151,2570,3452,2447,2761,2835,1210,2448,3082, 424,2222, # 3296
|
| 257 |
+
1251,2449,2119,2836, 504,1581,4338, 602, 817, 857,3825,2349,2306, 357,3826,1470, # 3312
|
| 258 |
+
1883,2883, 255, 958, 929,2917,3248, 302,4653,1050,1271,1751,2307,1952,1430,2697, # 3328
|
| 259 |
+
2719,2359, 354,3180, 777, 158,2036,4339,1659,4340,4654,2308,2949,2248,1146,2232, # 3344
|
| 260 |
+
3532,2720,1696,2623,3827,6158,3129,1550,2698,1485,1297,1428, 637, 931,2721,2145, # 3360
|
| 261 |
+
914,2550,2587, 81,2450, 612, 827,2646,1242,4655,1118,2884, 472,1855,3181,3533, # 3376
|
| 262 |
+
3534, 569,1353,2699,1244,1758,2588,4119,2009,2762,2171,3709,1312,1531,6159,1152, # 3392
|
| 263 |
+
1938, 134,1830, 471,3710,2276,1112,1535,3323,3453,3535, 982,1337,2950, 488, 826, # 3408
|
| 264 |
+
674,1058,1628,4120,2017, 522,2399, 211, 568,1367,3454, 350, 293,1872,1139,3249, # 3424
|
| 265 |
+
1399,1946,3006,1300,2360,3324, 588, 736,6160,2606, 744, 669,3536,3828,6161,1358, # 3440
|
| 266 |
+
199, 723, 848, 933, 851,1939,1505,1514,1338,1618,1831,4656,1634,3613, 443,2740, # 3456
|
| 267 |
+
3829, 717,1947, 491,1914,6162,2551,1542,4121,1025,6163,1099,1223, 198,3040,2722, # 3472
|
| 268 |
+
370, 410,1905,2589, 998,1248,3182,2380, 519,1449,4122,1710, 947, 928,1153,4341, # 3488
|
| 269 |
+
2277, 344,2624,1511, 615, 105, 161,1212,1076,1960,3130,2054,1926,1175,1906,2473, # 3504
|
| 270 |
+
414,1873,2801,6164,2309, 315,1319,3325, 318,2018,2146,2157, 963, 631, 223,4342, # 3520
|
| 271 |
+
4343,2675, 479,3711,1197,2625,3712,2676,2361,6165,4344,4123,6166,2451,3183,1886, # 3536
|
| 272 |
+
2184,1674,1330,1711,1635,1506, 799, 219,3250,3083,3954,1677,3713,3326,2081,3614, # 3552
|
| 273 |
+
1652,2073,4657,1147,3041,1752, 643,1961, 147,1974,3955,6167,1716,2037, 918,3007, # 3568
|
| 274 |
+
1994, 120,1537, 118, 609,3184,4345, 740,3455,1219, 332,1615,3830,6168,1621,2980, # 3584
|
| 275 |
+
1582, 783, 212, 553,2350,3714,1349,2433,2082,4124, 889,6169,2310,1275,1410, 973, # 3600
|
| 276 |
+
166,1320,3456,1797,1215,3185,2885,1846,2590,2763,4658, 629, 822,3008, 763, 940, # 3616
|
| 277 |
+
1990,2862, 439,2409,1566,1240,1622, 926,1282,1907,2764, 654,2210,1607, 327,1130, # 3632
|
| 278 |
+
3956,1678,1623,6170,2434,2192, 686, 608,3831,3715, 903,3957,3042,6171,2741,1522, # 3648
|
| 279 |
+
1915,1105,1555,2552,1359, 323,3251,4346,3457, 738,1354,2553,2311,2334,1828,2003, # 3664
|
| 280 |
+
3832,1753,2351,1227,6172,1887,4125,1478,6173,2410,1874,1712,1847, 520,1204,2607, # 3680
|
| 281 |
+
264,4659, 836,2677,2102, 600,4660,3833,2278,3084,6174,4347,3615,1342, 640, 532, # 3696
|
| 282 |
+
543,2608,1888,2400,2591,1009,4348,1497, 341,1737,3616,2723,1394, 529,3252,1321, # 3712
|
| 283 |
+
983,4661,1515,2120, 971,2592, 924, 287,1662,3186,4349,2700,4350,1519, 908,1948, # 3728
|
| 284 |
+
2452, 156, 796,1629,1486,2223,2055, 694,4126,1259,1036,3392,1213,2249,2742,1889, # 3744
|
| 285 |
+
1230,3958,1015, 910, 408, 559,3617,4662, 746, 725, 935,4663,3959,3009,1289, 563, # 3760
|
| 286 |
+
867,4664,3960,1567,2981,2038,2626, 988,2263,2381,4351, 143,2374, 704,1895,6175, # 3776
|
| 287 |
+
1188,3716,2088, 673,3085,2362,4352, 484,1608,1921,2765,2918, 215, 904,3618,3537, # 3792
|
| 288 |
+
894, 509, 976,3043,2701,3961,4353,2837,2982, 498,6176,6177,1102,3538,1332,3393, # 3808
|
| 289 |
+
1487,1636,1637, 233, 245,3962, 383, 650, 995,3044, 460,1520,1206,2352, 749,3327, # 3824
|
| 290 |
+
530, 700, 389,1438,1560,1773,3963,2264, 719,2951,2724,3834, 870,1832,1644,1000, # 3840
|
| 291 |
+
839,2474,3717, 197,1630,3394, 365,2886,3964,1285,2133, 734, 922, 818,1106, 732, # 3856
|
| 292 |
+
480,2083,1774,3458, 923,2279,1350, 221,3086, 85,2233,2234,3835,1585,3010,2147, # 3872
|
| 293 |
+
1387,1705,2382,1619,2475, 133, 239,2802,1991,1016,2084,2383, 411,2838,1113, 651, # 3888
|
| 294 |
+
1985,1160,3328, 990,1863,3087,1048,1276,2647, 265,2627,1599,3253,2056, 150, 638, # 3904
|
| 295 |
+
2019, 656, 853, 326,1479, 680,1439,4354,1001,1759, 413,3459,3395,2492,1431, 459, # 3920
|
| 296 |
+
4355,1125,3329,2265,1953,1450,2065,2863, 849, 351,2678,3131,3254,3255,1104,1577, # 3936
|
| 297 |
+
227,1351,1645,2453,2193,1421,2887, 812,2121, 634, 95,2435, 201,2312,4665,1646, # 3952
|
| 298 |
+
1671,2743,1601,2554,2702,2648,2280,1315,1366,2089,3132,1573,3718,3965,1729,1189, # 3968
|
| 299 |
+
328,2679,1077,1940,1136, 558,1283, 964,1195, 621,2074,1199,1743,3460,3619,1896, # 3984
|
| 300 |
+
1916,1890,3836,2952,1154,2112,1064, 862, 378,3011,2066,2113,2803,1568,2839,6178, # 4000
|
| 301 |
+
3088,2919,1941,1660,2004,1992,2194, 142, 707,1590,1708,1624,1922,1023,1836,1233, # 4016
|
| 302 |
+
1004,2313, 789, 741,3620,6179,1609,2411,1200,4127,3719,3720,4666,2057,3721, 593, # 4032
|
| 303 |
+
2840, 367,2920,1878,6180,3461,1521, 628,1168, 692,2211,2649, 300, 720,2067,2571, # 4048
|
| 304 |
+
2953,3396, 959,2504,3966,3539,3462,1977, 701,6181, 954,1043, 800, 681, 183,3722, # 4064
|
| 305 |
+
1803,1730,3540,4128,2103, 815,2314, 174, 467, 230,2454,1093,2134, 755,3541,3397, # 4080
|
| 306 |
+
1141,1162,6182,1738,2039, 270,3256,2513,1005,1647,2185,3837, 858,1679,1897,1719, # 4096
|
| 307 |
+
2954,2324,1806, 402, 670, 167,4129,1498,2158,2104, 750,6183, 915, 189,1680,1551, # 4112
|
| 308 |
+
455,4356,1501,2455, 405,1095,2955, 338,1586,1266,1819, 570, 641,1324, 237,1556, # 4128
|
| 309 |
+
2650,1388,3723,6184,1368,2384,1343,1978,3089,2436, 879,3724, 792,1191, 758,3012, # 4144
|
| 310 |
+
1411,2135,1322,4357, 240,4667,1848,3725,1574,6185, 420,3045,1546,1391, 714,4358, # 4160
|
| 311 |
+
1967, 941,1864, 863, 664, 426, 560,1731,2680,1785,2864,1949,2363, 403,3330,1415, # 4176
|
| 312 |
+
1279,2136,1697,2335, 204, 721,2097,3838, 90,6186,2085,2505, 191,3967, 124,2148, # 4192
|
| 313 |
+
1376,1798,1178,1107,1898,1405, 860,4359,1243,1272,2375,2983,1558,2456,1638, 113, # 4208
|
| 314 |
+
3621, 578,1923,2609, 880, 386,4130, 784,2186,2266,1422,2956,2172,1722, 497, 263, # 4224
|
| 315 |
+
2514,1267,2412,2610, 177,2703,3542, 774,1927,1344, 616,1432,1595,1018, 172,4360, # 4240
|
| 316 |
+
2325, 911,4361, 438,1468,3622, 794,3968,2024,2173,1681,1829,2957, 945, 895,3090, # 4256
|
| 317 |
+
575,2212,2476, 475,2401,2681, 785,2744,1745,2293,2555,1975,3133,2865, 394,4668, # 4272
|
| 318 |
+
3839, 635,4131, 639, 202,1507,2195,2766,1345,1435,2572,3726,1908,1184,1181,2457, # 4288
|
| 319 |
+
3727,3134,4362, 843,2611, 437, 916,4669, 234, 769,1884,3046,3047,3623, 833,6187, # 4304
|
| 320 |
+
1639,2250,2402,1355,1185,2010,2047, 999, 525,1732,1290,1488,2612, 948,1578,3728, # 4320
|
| 321 |
+
2413,2477,1216,2725,2159, 334,3840,1328,3624,2921,1525,4132, 564,1056, 891,4363, # 4336
|
| 322 |
+
1444,1698,2385,2251,3729,1365,2281,2235,1717,6188, 864,3841,2515, 444, 527,2767, # 4352
|
| 323 |
+
2922,3625, 544, 461,6189, 566, 209,2437,3398,2098,1065,2068,3331,3626,3257,2137, # 4368 #last 512
|
| 324 |
+
)
|
| 325 |
+
# fmt: on
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/johabprober.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
######################## BEGIN LICENSE BLOCK ########################
|
| 2 |
+
# The Original Code is mozilla.org code.
|
| 3 |
+
#
|
| 4 |
+
# The Initial Developer of the Original Code is
|
| 5 |
+
# Netscape Communications Corporation.
|
| 6 |
+
# Portions created by the Initial Developer are Copyright (C) 1998
|
| 7 |
+
# the Initial Developer. All Rights Reserved.
|
| 8 |
+
#
|
| 9 |
+
# Contributor(s):
|
| 10 |
+
# Mark Pilgrim - port to Python
|
| 11 |
+
#
|
| 12 |
+
# This library is free software; you can redistribute it and/or
|
| 13 |
+
# modify it under the terms of the GNU Lesser General Public
|
| 14 |
+
# License as published by the Free Software Foundation; either
|
| 15 |
+
# version 2.1 of the License, or (at your option) any later version.
|
| 16 |
+
#
|
| 17 |
+
# This library is distributed in the hope that it will be useful,
|
| 18 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 19 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 20 |
+
# Lesser General Public License for more details.
|
| 21 |
+
#
|
| 22 |
+
# You should have received a copy of the GNU Lesser General Public
|
| 23 |
+
# License along with this library; if not, write to the Free Software
|
| 24 |
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
| 25 |
+
# 02110-1301 USA
|
| 26 |
+
######################### END LICENSE BLOCK #########################
|
| 27 |
+
|
| 28 |
+
from .chardistribution import JOHABDistributionAnalysis
|
| 29 |
+
from .codingstatemachine import CodingStateMachine
|
| 30 |
+
from .mbcharsetprober import MultiByteCharSetProber
|
| 31 |
+
from .mbcssm import JOHAB_SM_MODEL
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class JOHABProber(MultiByteCharSetProber):
|
| 35 |
+
def __init__(self) -> None:
|
| 36 |
+
super().__init__()
|
| 37 |
+
self.coding_sm = CodingStateMachine(JOHAB_SM_MODEL)
|
| 38 |
+
self.distribution_analyzer = JOHABDistributionAnalysis()
|
| 39 |
+
self.reset()
|
| 40 |
+
|
| 41 |
+
@property
|
| 42 |
+
def charset_name(self) -> str:
|
| 43 |
+
return "Johab"
|
| 44 |
+
|
| 45 |
+
@property
|
| 46 |
+
def language(self) -> str:
|
| 47 |
+
return "Korean"
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/jpcntx.py
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
######################## BEGIN LICENSE BLOCK ########################
|
| 2 |
+
# The Original Code is Mozilla Communicator client code.
|
| 3 |
+
#
|
| 4 |
+
# The Initial Developer of the Original Code is
|
| 5 |
+
# Netscape Communications Corporation.
|
| 6 |
+
# Portions created by the Initial Developer are Copyright (C) 1998
|
| 7 |
+
# the Initial Developer. All Rights Reserved.
|
| 8 |
+
#
|
| 9 |
+
# Contributor(s):
|
| 10 |
+
# Mark Pilgrim - port to Python
|
| 11 |
+
#
|
| 12 |
+
# This library is free software; you can redistribute it and/or
|
| 13 |
+
# modify it under the terms of the GNU Lesser General Public
|
| 14 |
+
# License as published by the Free Software Foundation; either
|
| 15 |
+
# version 2.1 of the License, or (at your option) any later version.
|
| 16 |
+
#
|
| 17 |
+
# This library is distributed in the hope that it will be useful,
|
| 18 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 19 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 20 |
+
# Lesser General Public License for more details.
|
| 21 |
+
#
|
| 22 |
+
# You should have received a copy of the GNU Lesser General Public
|
| 23 |
+
# License along with this library; if not, write to the Free Software
|
| 24 |
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
| 25 |
+
# 02110-1301 USA
|
| 26 |
+
######################### END LICENSE BLOCK #########################
|
| 27 |
+
|
| 28 |
+
from typing import List, Tuple, Union
|
| 29 |
+
|
| 30 |
+
# This is hiragana 2-char sequence table, the number in each cell represents its frequency category
|
| 31 |
+
# fmt: off
|
| 32 |
+
jp2_char_context = (
|
| 33 |
+
(0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1),
|
| 34 |
+
(2, 4, 0, 4, 0, 3, 0, 4, 0, 3, 4, 4, 4, 2, 4, 3, 3, 4, 3, 2, 3, 3, 4, 2, 3, 3, 3, 2, 4, 1, 4, 3, 3, 1, 5, 4, 3, 4, 3, 4, 3, 5, 3, 0, 3, 5, 4, 2, 0, 3, 1, 0, 3, 3, 0, 3, 3, 0, 1, 1, 0, 4, 3, 0, 3, 3, 0, 4, 0, 2, 0, 3, 5, 5, 5, 5, 4, 0, 4, 1, 0, 3, 4),
|
| 35 |
+
(0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2),
|
| 36 |
+
(0, 4, 0, 5, 0, 5, 0, 4, 0, 4, 5, 4, 4, 3, 5, 3, 5, 1, 5, 3, 4, 3, 4, 4, 3, 4, 3, 3, 4, 3, 5, 4, 4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, 3, 3, 3, 4, 3, 4, 3, 3, 3, 4, 4, 4, 3, 3, 3, 3, 4, 3, 5, 3, 3, 1, 3, 2, 4, 5, 5, 5, 5, 4, 3, 4, 5, 5, 3, 2, 2, 3, 3, 3, 3, 2, 3, 3, 1, 2, 3, 2, 4, 3, 3, 3, 4, 0, 4, 0, 2, 0, 4, 3, 2, 2, 1, 2, 0, 3, 0, 0, 4, 1),
|
| 116 |
+
)
|
| 117 |
+
# fmt: on
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
class JapaneseContextAnalysis:
|
| 121 |
+
NUM_OF_CATEGORY = 6
|
| 122 |
+
DONT_KNOW = -1
|
| 123 |
+
ENOUGH_REL_THRESHOLD = 100
|
| 124 |
+
MAX_REL_THRESHOLD = 1000
|
| 125 |
+
MINIMUM_DATA_THRESHOLD = 4
|
| 126 |
+
|
| 127 |
+
def __init__(self) -> None:
|
| 128 |
+
self._total_rel = 0
|
| 129 |
+
self._rel_sample: List[int] = []
|
| 130 |
+
self._need_to_skip_char_num = 0
|
| 131 |
+
self._last_char_order = -1
|
| 132 |
+
self._done = False
|
| 133 |
+
self.reset()
|
| 134 |
+
|
| 135 |
+
def reset(self) -> None:
|
| 136 |
+
self._total_rel = 0 # total sequence received
|
| 137 |
+
# category counters, each integer counts sequence in its category
|
| 138 |
+
self._rel_sample = [0] * self.NUM_OF_CATEGORY
|
| 139 |
+
# if last byte in current buffer is not the last byte of a character,
|
| 140 |
+
# we need to know how many bytes to skip in next buffer
|
| 141 |
+
self._need_to_skip_char_num = 0
|
| 142 |
+
self._last_char_order = -1 # The order of previous char
|
| 143 |
+
# If this flag is set to True, detection is done and conclusion has
|
| 144 |
+
# been made
|
| 145 |
+
self._done = False
|
| 146 |
+
|
| 147 |
+
def feed(self, byte_str: Union[bytes, bytearray], num_bytes: int) -> None:
|
| 148 |
+
if self._done:
|
| 149 |
+
return
|
| 150 |
+
|
| 151 |
+
# The buffer we got is byte oriented, and a character may span in more than one
|
| 152 |
+
# buffers. In case the last one or two byte in last buffer is not
|
| 153 |
+
# complete, we record how many byte needed to complete that character
|
| 154 |
+
# and skip these bytes here. We can choose to record those bytes as
|
| 155 |
+
# well and analyse the character once it is complete, but since a
|
| 156 |
+
# character will not make much difference, by simply skipping
|
| 157 |
+
# this character will simply our logic and improve performance.
|
| 158 |
+
i = self._need_to_skip_char_num
|
| 159 |
+
while i < num_bytes:
|
| 160 |
+
order, char_len = self.get_order(byte_str[i : i + 2])
|
| 161 |
+
i += char_len
|
| 162 |
+
if i > num_bytes:
|
| 163 |
+
self._need_to_skip_char_num = i - num_bytes
|
| 164 |
+
self._last_char_order = -1
|
| 165 |
+
else:
|
| 166 |
+
if (order != -1) and (self._last_char_order != -1):
|
| 167 |
+
self._total_rel += 1
|
| 168 |
+
if self._total_rel > self.MAX_REL_THRESHOLD:
|
| 169 |
+
self._done = True
|
| 170 |
+
break
|
| 171 |
+
self._rel_sample[
|
| 172 |
+
jp2_char_context[self._last_char_order][order]
|
| 173 |
+
] += 1
|
| 174 |
+
self._last_char_order = order
|
| 175 |
+
|
| 176 |
+
def got_enough_data(self) -> bool:
|
| 177 |
+
return self._total_rel > self.ENOUGH_REL_THRESHOLD
|
| 178 |
+
|
| 179 |
+
def get_confidence(self) -> float:
|
| 180 |
+
# This is just one way to calculate confidence. It works well for me.
|
| 181 |
+
if self._total_rel > self.MINIMUM_DATA_THRESHOLD:
|
| 182 |
+
return (self._total_rel - self._rel_sample[0]) / self._total_rel
|
| 183 |
+
return self.DONT_KNOW
|
| 184 |
+
|
| 185 |
+
def get_order(self, _: Union[bytes, bytearray]) -> Tuple[int, int]:
|
| 186 |
+
return -1, 1
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
class SJISContextAnalysis(JapaneseContextAnalysis):
|
| 190 |
+
def __init__(self) -> None:
|
| 191 |
+
super().__init__()
|
| 192 |
+
self._charset_name = "SHIFT_JIS"
|
| 193 |
+
|
| 194 |
+
@property
|
| 195 |
+
def charset_name(self) -> str:
|
| 196 |
+
return self._charset_name
|
| 197 |
+
|
| 198 |
+
def get_order(self, byte_str: Union[bytes, bytearray]) -> Tuple[int, int]:
|
| 199 |
+
if not byte_str:
|
| 200 |
+
return -1, 1
|
| 201 |
+
# find out current char's byte length
|
| 202 |
+
first_char = byte_str[0]
|
| 203 |
+
if (0x81 <= first_char <= 0x9F) or (0xE0 <= first_char <= 0xFC):
|
| 204 |
+
char_len = 2
|
| 205 |
+
if (first_char == 0x87) or (0xFA <= first_char <= 0xFC):
|
| 206 |
+
self._charset_name = "CP932"
|
| 207 |
+
else:
|
| 208 |
+
char_len = 1
|
| 209 |
+
|
| 210 |
+
# return its order if it is hiragana
|
| 211 |
+
if len(byte_str) > 1:
|
| 212 |
+
second_char = byte_str[1]
|
| 213 |
+
if (first_char == 202) and (0x9F <= second_char <= 0xF1):
|
| 214 |
+
return second_char - 0x9F, char_len
|
| 215 |
+
|
| 216 |
+
return -1, char_len
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
class EUCJPContextAnalysis(JapaneseContextAnalysis):
|
| 220 |
+
def get_order(self, byte_str: Union[bytes, bytearray]) -> Tuple[int, int]:
|
| 221 |
+
if not byte_str:
|
| 222 |
+
return -1, 1
|
| 223 |
+
# find out current char's byte length
|
| 224 |
+
first_char = byte_str[0]
|
| 225 |
+
if (first_char == 0x8E) or (0xA1 <= first_char <= 0xFE):
|
| 226 |
+
char_len = 2
|
| 227 |
+
elif first_char == 0x8F:
|
| 228 |
+
char_len = 3
|
| 229 |
+
else:
|
| 230 |
+
char_len = 1
|
| 231 |
+
|
| 232 |
+
# return its order if it is hiragana
|
| 233 |
+
if len(byte_str) > 1:
|
| 234 |
+
second_char = byte_str[1]
|
| 235 |
+
if (first_char == 0xA4) and (0xA1 <= second_char <= 0xF3):
|
| 236 |
+
return second_char - 0xA1, char_len
|
| 237 |
+
|
| 238 |
+
return -1, char_len
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/langbulgarianmodel.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/langgreekmodel.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/macromanprober.py
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
######################## BEGIN LICENSE BLOCK ########################
|
| 2 |
+
# This code was modified from latin1prober.py by Rob Speer <rob@lumino.so>.
|
| 3 |
+
# The Original Code is Mozilla Universal charset detector code.
|
| 4 |
+
#
|
| 5 |
+
# The Initial Developer of the Original Code is
|
| 6 |
+
# Netscape Communications Corporation.
|
| 7 |
+
# Portions created by the Initial Developer are Copyright (C) 2001
|
| 8 |
+
# the Initial Developer. All Rights Reserved.
|
| 9 |
+
#
|
| 10 |
+
# Contributor(s):
|
| 11 |
+
# Rob Speer - adapt to MacRoman encoding
|
| 12 |
+
# Mark Pilgrim - port to Python
|
| 13 |
+
# Shy Shalom - original C code
|
| 14 |
+
#
|
| 15 |
+
# This library is free software; you can redistribute it and/or
|
| 16 |
+
# modify it under the terms of the GNU Lesser General Public
|
| 17 |
+
# License as published by the Free Software Foundation; either
|
| 18 |
+
# version 2.1 of the License, or (at your option) any later version.
|
| 19 |
+
#
|
| 20 |
+
# This library is distributed in the hope that it will be useful,
|
| 21 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 22 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 23 |
+
# Lesser General Public License for more details.
|
| 24 |
+
#
|
| 25 |
+
# You should have received a copy of the GNU Lesser General Public
|
| 26 |
+
# License along with this library; if not, write to the Free Software
|
| 27 |
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
| 28 |
+
# 02110-1301 USA
|
| 29 |
+
######################### END LICENSE BLOCK #########################
|
| 30 |
+
|
| 31 |
+
from typing import List, Union
|
| 32 |
+
|
| 33 |
+
from .charsetprober import CharSetProber
|
| 34 |
+
from .enums import ProbingState
|
| 35 |
+
|
| 36 |
+
FREQ_CAT_NUM = 4
|
| 37 |
+
|
| 38 |
+
UDF = 0 # undefined
|
| 39 |
+
OTH = 1 # other
|
| 40 |
+
ASC = 2 # ascii capital letter
|
| 41 |
+
ASS = 3 # ascii small letter
|
| 42 |
+
ACV = 4 # accent capital vowel
|
| 43 |
+
ACO = 5 # accent capital other
|
| 44 |
+
ASV = 6 # accent small vowel
|
| 45 |
+
ASO = 7 # accent small other
|
| 46 |
+
ODD = 8 # character that is unlikely to appear
|
| 47 |
+
CLASS_NUM = 9 # total classes
|
| 48 |
+
|
| 49 |
+
# The change from Latin1 is that we explicitly look for extended characters
|
| 50 |
+
# that are infrequently-occurring symbols, and consider them to always be
|
| 51 |
+
# improbable. This should let MacRoman get out of the way of more likely
|
| 52 |
+
# encodings in most situations.
|
| 53 |
+
|
| 54 |
+
# fmt: off
|
| 55 |
+
MacRoman_CharToClass = (
|
| 56 |
+
OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 00 - 07
|
| 57 |
+
OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 08 - 0F
|
| 58 |
+
OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 10 - 17
|
| 59 |
+
OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 18 - 1F
|
| 60 |
+
OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 20 - 27
|
| 61 |
+
OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 28 - 2F
|
| 62 |
+
OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 30 - 37
|
| 63 |
+
OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 38 - 3F
|
| 64 |
+
OTH, ASC, ASC, ASC, ASC, ASC, ASC, ASC, # 40 - 47
|
| 65 |
+
ASC, ASC, ASC, ASC, ASC, ASC, ASC, ASC, # 48 - 4F
|
| 66 |
+
ASC, ASC, ASC, ASC, ASC, ASC, ASC, ASC, # 50 - 57
|
| 67 |
+
ASC, ASC, ASC, OTH, OTH, OTH, OTH, OTH, # 58 - 5F
|
| 68 |
+
OTH, ASS, ASS, ASS, ASS, ASS, ASS, ASS, # 60 - 67
|
| 69 |
+
ASS, ASS, ASS, ASS, ASS, ASS, ASS, ASS, # 68 - 6F
|
| 70 |
+
ASS, ASS, ASS, ASS, ASS, ASS, ASS, ASS, # 70 - 77
|
| 71 |
+
ASS, ASS, ASS, OTH, OTH, OTH, OTH, OTH, # 78 - 7F
|
| 72 |
+
ACV, ACV, ACO, ACV, ACO, ACV, ACV, ASV, # 80 - 87
|
| 73 |
+
ASV, ASV, ASV, ASV, ASV, ASO, ASV, ASV, # 88 - 8F
|
| 74 |
+
ASV, ASV, ASV, ASV, ASV, ASV, ASO, ASV, # 90 - 97
|
| 75 |
+
ASV, ASV, ASV, ASV, ASV, ASV, ASV, ASV, # 98 - 9F
|
| 76 |
+
OTH, OTH, OTH, OTH, OTH, OTH, OTH, ASO, # A0 - A7
|
| 77 |
+
OTH, OTH, ODD, ODD, OTH, OTH, ACV, ACV, # A8 - AF
|
| 78 |
+
OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # B0 - B7
|
| 79 |
+
OTH, OTH, OTH, OTH, OTH, OTH, ASV, ASV, # B8 - BF
|
| 80 |
+
OTH, OTH, ODD, OTH, ODD, OTH, OTH, OTH, # C0 - C7
|
| 81 |
+
OTH, OTH, OTH, ACV, ACV, ACV, ACV, ASV, # C8 - CF
|
| 82 |
+
OTH, OTH, OTH, OTH, OTH, OTH, OTH, ODD, # D0 - D7
|
| 83 |
+
ASV, ACV, ODD, OTH, OTH, OTH, OTH, OTH, # D8 - DF
|
| 84 |
+
OTH, OTH, OTH, OTH, OTH, ACV, ACV, ACV, # E0 - E7
|
| 85 |
+
ACV, ACV, ACV, ACV, ACV, ACV, ACV, ACV, # E8 - EF
|
| 86 |
+
ODD, ACV, ACV, ACV, ACV, ASV, ODD, ODD, # F0 - F7
|
| 87 |
+
ODD, ODD, ODD, ODD, ODD, ODD, ODD, ODD, # F8 - FF
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
# 0 : illegal
|
| 91 |
+
# 1 : very unlikely
|
| 92 |
+
# 2 : normal
|
| 93 |
+
# 3 : very likely
|
| 94 |
+
MacRomanClassModel = (
|
| 95 |
+
# UDF OTH ASC ASS ACV ACO ASV ASO ODD
|
| 96 |
+
0, 0, 0, 0, 0, 0, 0, 0, 0, # UDF
|
| 97 |
+
0, 3, 3, 3, 3, 3, 3, 3, 1, # OTH
|
| 98 |
+
0, 3, 3, 3, 3, 3, 3, 3, 1, # ASC
|
| 99 |
+
0, 3, 3, 3, 1, 1, 3, 3, 1, # ASS
|
| 100 |
+
0, 3, 3, 3, 1, 2, 1, 2, 1, # ACV
|
| 101 |
+
0, 3, 3, 3, 3, 3, 3, 3, 1, # ACO
|
| 102 |
+
0, 3, 1, 3, 1, 1, 1, 3, 1, # ASV
|
| 103 |
+
0, 3, 1, 3, 1, 1, 3, 3, 1, # ASO
|
| 104 |
+
0, 1, 1, 1, 1, 1, 1, 1, 1, # ODD
|
| 105 |
+
)
|
| 106 |
+
# fmt: on
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
class MacRomanProber(CharSetProber):
|
| 110 |
+
def __init__(self) -> None:
|
| 111 |
+
super().__init__()
|
| 112 |
+
self._last_char_class = OTH
|
| 113 |
+
self._freq_counter: List[int] = []
|
| 114 |
+
self.reset()
|
| 115 |
+
|
| 116 |
+
def reset(self) -> None:
|
| 117 |
+
self._last_char_class = OTH
|
| 118 |
+
self._freq_counter = [0] * FREQ_CAT_NUM
|
| 119 |
+
|
| 120 |
+
# express the prior that MacRoman is a somewhat rare encoding;
|
| 121 |
+
# this can be done by starting out in a slightly improbable state
|
| 122 |
+
# that must be overcome
|
| 123 |
+
self._freq_counter[2] = 10
|
| 124 |
+
|
| 125 |
+
super().reset()
|
| 126 |
+
|
| 127 |
+
@property
|
| 128 |
+
def charset_name(self) -> str:
|
| 129 |
+
return "MacRoman"
|
| 130 |
+
|
| 131 |
+
@property
|
| 132 |
+
def language(self) -> str:
|
| 133 |
+
return ""
|
| 134 |
+
|
| 135 |
+
def feed(self, byte_str: Union[bytes, bytearray]) -> ProbingState:
|
| 136 |
+
byte_str = self.remove_xml_tags(byte_str)
|
| 137 |
+
for c in byte_str:
|
| 138 |
+
char_class = MacRoman_CharToClass[c]
|
| 139 |
+
freq = MacRomanClassModel[(self._last_char_class * CLASS_NUM) + char_class]
|
| 140 |
+
if freq == 0:
|
| 141 |
+
self._state = ProbingState.NOT_ME
|
| 142 |
+
break
|
| 143 |
+
self._freq_counter[freq] += 1
|
| 144 |
+
self._last_char_class = char_class
|
| 145 |
+
|
| 146 |
+
return self.state
|
| 147 |
+
|
| 148 |
+
def get_confidence(self) -> float:
|
| 149 |
+
if self.state == ProbingState.NOT_ME:
|
| 150 |
+
return 0.01
|
| 151 |
+
|
| 152 |
+
total = sum(self._freq_counter)
|
| 153 |
+
confidence = (
|
| 154 |
+
0.0
|
| 155 |
+
if total < 0.01
|
| 156 |
+
else (self._freq_counter[3] - self._freq_counter[1] * 20.0) / total
|
| 157 |
+
)
|
| 158 |
+
confidence = max(confidence, 0.0)
|
| 159 |
+
# lower the confidence of MacRoman so that other more accurate
|
| 160 |
+
# detector can take priority.
|
| 161 |
+
confidence *= 0.73
|
| 162 |
+
return confidence
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/mbcharsetprober.py
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
######################## BEGIN LICENSE BLOCK ########################
|
| 2 |
+
# The Original Code is Mozilla Universal charset detector code.
|
| 3 |
+
#
|
| 4 |
+
# The Initial Developer of the Original Code is
|
| 5 |
+
# Netscape Communications Corporation.
|
| 6 |
+
# Portions created by the Initial Developer are Copyright (C) 2001
|
| 7 |
+
# the Initial Developer. All Rights Reserved.
|
| 8 |
+
#
|
| 9 |
+
# Contributor(s):
|
| 10 |
+
# Mark Pilgrim - port to Python
|
| 11 |
+
# Shy Shalom - original C code
|
| 12 |
+
# Proofpoint, Inc.
|
| 13 |
+
#
|
| 14 |
+
# This library is free software; you can redistribute it and/or
|
| 15 |
+
# modify it under the terms of the GNU Lesser General Public
|
| 16 |
+
# License as published by the Free Software Foundation; either
|
| 17 |
+
# version 2.1 of the License, or (at your option) any later version.
|
| 18 |
+
#
|
| 19 |
+
# This library is distributed in the hope that it will be useful,
|
| 20 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 21 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 22 |
+
# Lesser General Public License for more details.
|
| 23 |
+
#
|
| 24 |
+
# You should have received a copy of the GNU Lesser General Public
|
| 25 |
+
# License along with this library; if not, write to the Free Software
|
| 26 |
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
| 27 |
+
# 02110-1301 USA
|
| 28 |
+
######################### END LICENSE BLOCK #########################
|
| 29 |
+
|
| 30 |
+
from typing import Optional, Union
|
| 31 |
+
|
| 32 |
+
from .chardistribution import CharDistributionAnalysis
|
| 33 |
+
from .charsetprober import CharSetProber
|
| 34 |
+
from .codingstatemachine import CodingStateMachine
|
| 35 |
+
from .enums import LanguageFilter, MachineState, ProbingState
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
class MultiByteCharSetProber(CharSetProber):
|
| 39 |
+
"""
|
| 40 |
+
MultiByteCharSetProber
|
| 41 |
+
"""
|
| 42 |
+
|
| 43 |
+
def __init__(self, lang_filter: LanguageFilter = LanguageFilter.NONE) -> None:
|
| 44 |
+
super().__init__(lang_filter=lang_filter)
|
| 45 |
+
self.distribution_analyzer: Optional[CharDistributionAnalysis] = None
|
| 46 |
+
self.coding_sm: Optional[CodingStateMachine] = None
|
| 47 |
+
self._last_char = bytearray(b"\0\0")
|
| 48 |
+
|
| 49 |
+
def reset(self) -> None:
|
| 50 |
+
super().reset()
|
| 51 |
+
if self.coding_sm:
|
| 52 |
+
self.coding_sm.reset()
|
| 53 |
+
if self.distribution_analyzer:
|
| 54 |
+
self.distribution_analyzer.reset()
|
| 55 |
+
self._last_char = bytearray(b"\0\0")
|
| 56 |
+
|
| 57 |
+
def feed(self, byte_str: Union[bytes, bytearray]) -> ProbingState:
|
| 58 |
+
assert self.coding_sm is not None
|
| 59 |
+
assert self.distribution_analyzer is not None
|
| 60 |
+
|
| 61 |
+
for i, byte in enumerate(byte_str):
|
| 62 |
+
coding_state = self.coding_sm.next_state(byte)
|
| 63 |
+
if coding_state == MachineState.ERROR:
|
| 64 |
+
self.logger.debug(
|
| 65 |
+
"%s %s prober hit error at byte %s",
|
| 66 |
+
self.charset_name,
|
| 67 |
+
self.language,
|
| 68 |
+
i,
|
| 69 |
+
)
|
| 70 |
+
self._state = ProbingState.NOT_ME
|
| 71 |
+
break
|
| 72 |
+
if coding_state == MachineState.ITS_ME:
|
| 73 |
+
self._state = ProbingState.FOUND_IT
|
| 74 |
+
break
|
| 75 |
+
if coding_state == MachineState.START:
|
| 76 |
+
char_len = self.coding_sm.get_current_charlen()
|
| 77 |
+
if i == 0:
|
| 78 |
+
self._last_char[1] = byte
|
| 79 |
+
self.distribution_analyzer.feed(self._last_char, char_len)
|
| 80 |
+
else:
|
| 81 |
+
self.distribution_analyzer.feed(byte_str[i - 1 : i + 1], char_len)
|
| 82 |
+
|
| 83 |
+
self._last_char[0] = byte_str[-1]
|
| 84 |
+
|
| 85 |
+
if self.state == ProbingState.DETECTING:
|
| 86 |
+
if self.distribution_analyzer.got_enough_data() and (
|
| 87 |
+
self.get_confidence() > self.SHORTCUT_THRESHOLD
|
| 88 |
+
):
|
| 89 |
+
self._state = ProbingState.FOUND_IT
|
| 90 |
+
|
| 91 |
+
return self.state
|
| 92 |
+
|
| 93 |
+
def get_confidence(self) -> float:
|
| 94 |
+
assert self.distribution_analyzer is not None
|
| 95 |
+
return self.distribution_analyzer.get_confidence()
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/mbcsgroupprober.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
######################## BEGIN LICENSE BLOCK ########################
|
| 2 |
+
# The Original Code is Mozilla Universal charset detector code.
|
| 3 |
+
#
|
| 4 |
+
# The Initial Developer of the Original Code is
|
| 5 |
+
# Netscape Communications Corporation.
|
| 6 |
+
# Portions created by the Initial Developer are Copyright (C) 2001
|
| 7 |
+
# the Initial Developer. All Rights Reserved.
|
| 8 |
+
#
|
| 9 |
+
# Contributor(s):
|
| 10 |
+
# Mark Pilgrim - port to Python
|
| 11 |
+
# Shy Shalom - original C code
|
| 12 |
+
# Proofpoint, Inc.
|
| 13 |
+
#
|
| 14 |
+
# This library is free software; you can redistribute it and/or
|
| 15 |
+
# modify it under the terms of the GNU Lesser General Public
|
| 16 |
+
# License as published by the Free Software Foundation; either
|
| 17 |
+
# version 2.1 of the License, or (at your option) any later version.
|
| 18 |
+
#
|
| 19 |
+
# This library is distributed in the hope that it will be useful,
|
| 20 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 21 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 22 |
+
# Lesser General Public License for more details.
|
| 23 |
+
#
|
| 24 |
+
# You should have received a copy of the GNU Lesser General Public
|
| 25 |
+
# License along with this library; if not, write to the Free Software
|
| 26 |
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
| 27 |
+
# 02110-1301 USA
|
| 28 |
+
######################### END LICENSE BLOCK #########################
|
| 29 |
+
|
| 30 |
+
from .big5prober import Big5Prober
|
| 31 |
+
from .charsetgroupprober import CharSetGroupProber
|
| 32 |
+
from .cp949prober import CP949Prober
|
| 33 |
+
from .enums import LanguageFilter
|
| 34 |
+
from .eucjpprober import EUCJPProber
|
| 35 |
+
from .euckrprober import EUCKRProber
|
| 36 |
+
from .euctwprober import EUCTWProber
|
| 37 |
+
from .gb2312prober import GB2312Prober
|
| 38 |
+
from .johabprober import JOHABProber
|
| 39 |
+
from .sjisprober import SJISProber
|
| 40 |
+
from .utf8prober import UTF8Prober
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
class MBCSGroupProber(CharSetGroupProber):
|
| 44 |
+
def __init__(self, lang_filter: LanguageFilter = LanguageFilter.NONE) -> None:
|
| 45 |
+
super().__init__(lang_filter=lang_filter)
|
| 46 |
+
self.probers = [
|
| 47 |
+
UTF8Prober(),
|
| 48 |
+
SJISProber(),
|
| 49 |
+
EUCJPProber(),
|
| 50 |
+
GB2312Prober(),
|
| 51 |
+
EUCKRProber(),
|
| 52 |
+
CP949Prober(),
|
| 53 |
+
Big5Prober(),
|
| 54 |
+
EUCTWProber(),
|
| 55 |
+
JOHABProber(),
|
| 56 |
+
]
|
| 57 |
+
self.reset()
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/py.typed
ADDED
|
File without changes
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/resultdict.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import TYPE_CHECKING, Optional
|
| 2 |
+
|
| 3 |
+
if TYPE_CHECKING:
|
| 4 |
+
# TypedDict was introduced in Python 3.8.
|
| 5 |
+
#
|
| 6 |
+
# TODO: Remove the else block and TYPE_CHECKING check when dropping support
|
| 7 |
+
# for Python 3.7.
|
| 8 |
+
from typing import TypedDict
|
| 9 |
+
|
| 10 |
+
class ResultDict(TypedDict):
|
| 11 |
+
encoding: Optional[str]
|
| 12 |
+
confidence: float
|
| 13 |
+
language: Optional[str]
|
| 14 |
+
|
| 15 |
+
else:
|
| 16 |
+
ResultDict = dict
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/sbcharsetprober.py
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
######################## BEGIN LICENSE BLOCK ########################
|
| 2 |
+
# The Original Code is Mozilla Universal charset detector code.
|
| 3 |
+
#
|
| 4 |
+
# The Initial Developer of the Original Code is
|
| 5 |
+
# Netscape Communications Corporation.
|
| 6 |
+
# Portions created by the Initial Developer are Copyright (C) 2001
|
| 7 |
+
# the Initial Developer. All Rights Reserved.
|
| 8 |
+
#
|
| 9 |
+
# Contributor(s):
|
| 10 |
+
# Mark Pilgrim - port to Python
|
| 11 |
+
# Shy Shalom - original C code
|
| 12 |
+
#
|
| 13 |
+
# This library is free software; you can redistribute it and/or
|
| 14 |
+
# modify it under the terms of the GNU Lesser General Public
|
| 15 |
+
# License as published by the Free Software Foundation; either
|
| 16 |
+
# version 2.1 of the License, or (at your option) any later version.
|
| 17 |
+
#
|
| 18 |
+
# This library is distributed in the hope that it will be useful,
|
| 19 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 20 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 21 |
+
# Lesser General Public License for more details.
|
| 22 |
+
#
|
| 23 |
+
# You should have received a copy of the GNU Lesser General Public
|
| 24 |
+
# License along with this library; if not, write to the Free Software
|
| 25 |
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
| 26 |
+
# 02110-1301 USA
|
| 27 |
+
######################### END LICENSE BLOCK #########################
|
| 28 |
+
|
| 29 |
+
from typing import Dict, List, NamedTuple, Optional, Union
|
| 30 |
+
|
| 31 |
+
from .charsetprober import CharSetProber
|
| 32 |
+
from .enums import CharacterCategory, ProbingState, SequenceLikelihood
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
class SingleByteCharSetModel(NamedTuple):
|
| 36 |
+
charset_name: str
|
| 37 |
+
language: str
|
| 38 |
+
char_to_order_map: Dict[int, int]
|
| 39 |
+
language_model: Dict[int, Dict[int, int]]
|
| 40 |
+
typical_positive_ratio: float
|
| 41 |
+
keep_ascii_letters: bool
|
| 42 |
+
alphabet: str
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
class SingleByteCharSetProber(CharSetProber):
|
| 46 |
+
SAMPLE_SIZE = 64
|
| 47 |
+
SB_ENOUGH_REL_THRESHOLD = 1024 # 0.25 * SAMPLE_SIZE^2
|
| 48 |
+
POSITIVE_SHORTCUT_THRESHOLD = 0.95
|
| 49 |
+
NEGATIVE_SHORTCUT_THRESHOLD = 0.05
|
| 50 |
+
|
| 51 |
+
def __init__(
|
| 52 |
+
self,
|
| 53 |
+
model: SingleByteCharSetModel,
|
| 54 |
+
is_reversed: bool = False,
|
| 55 |
+
name_prober: Optional[CharSetProber] = None,
|
| 56 |
+
) -> None:
|
| 57 |
+
super().__init__()
|
| 58 |
+
self._model = model
|
| 59 |
+
# TRUE if we need to reverse every pair in the model lookup
|
| 60 |
+
self._reversed = is_reversed
|
| 61 |
+
# Optional auxiliary prober for name decision
|
| 62 |
+
self._name_prober = name_prober
|
| 63 |
+
self._last_order = 255
|
| 64 |
+
self._seq_counters: List[int] = []
|
| 65 |
+
self._total_seqs = 0
|
| 66 |
+
self._total_char = 0
|
| 67 |
+
self._control_char = 0
|
| 68 |
+
self._freq_char = 0
|
| 69 |
+
self.reset()
|
| 70 |
+
|
| 71 |
+
def reset(self) -> None:
|
| 72 |
+
super().reset()
|
| 73 |
+
# char order of last character
|
| 74 |
+
self._last_order = 255
|
| 75 |
+
self._seq_counters = [0] * SequenceLikelihood.get_num_categories()
|
| 76 |
+
self._total_seqs = 0
|
| 77 |
+
self._total_char = 0
|
| 78 |
+
self._control_char = 0
|
| 79 |
+
# characters that fall in our sampling range
|
| 80 |
+
self._freq_char = 0
|
| 81 |
+
|
| 82 |
+
@property
|
| 83 |
+
def charset_name(self) -> Optional[str]:
|
| 84 |
+
if self._name_prober:
|
| 85 |
+
return self._name_prober.charset_name
|
| 86 |
+
return self._model.charset_name
|
| 87 |
+
|
| 88 |
+
@property
|
| 89 |
+
def language(self) -> Optional[str]:
|
| 90 |
+
if self._name_prober:
|
| 91 |
+
return self._name_prober.language
|
| 92 |
+
return self._model.language
|
| 93 |
+
|
| 94 |
+
def feed(self, byte_str: Union[bytes, bytearray]) -> ProbingState:
|
| 95 |
+
# TODO: Make filter_international_words keep things in self.alphabet
|
| 96 |
+
if not self._model.keep_ascii_letters:
|
| 97 |
+
byte_str = self.filter_international_words(byte_str)
|
| 98 |
+
else:
|
| 99 |
+
byte_str = self.remove_xml_tags(byte_str)
|
| 100 |
+
if not byte_str:
|
| 101 |
+
return self.state
|
| 102 |
+
char_to_order_map = self._model.char_to_order_map
|
| 103 |
+
language_model = self._model.language_model
|
| 104 |
+
for char in byte_str:
|
| 105 |
+
order = char_to_order_map.get(char, CharacterCategory.UNDEFINED)
|
| 106 |
+
# XXX: This was SYMBOL_CAT_ORDER before, with a value of 250, but
|
| 107 |
+
# CharacterCategory.SYMBOL is actually 253, so we use CONTROL
|
| 108 |
+
# to make it closer to the original intent. The only difference
|
| 109 |
+
# is whether or not we count digits and control characters for
|
| 110 |
+
# _total_char purposes.
|
| 111 |
+
if order < CharacterCategory.CONTROL:
|
| 112 |
+
self._total_char += 1
|
| 113 |
+
if order < self.SAMPLE_SIZE:
|
| 114 |
+
self._freq_char += 1
|
| 115 |
+
if self._last_order < self.SAMPLE_SIZE:
|
| 116 |
+
self._total_seqs += 1
|
| 117 |
+
if not self._reversed:
|
| 118 |
+
lm_cat = language_model[self._last_order][order]
|
| 119 |
+
else:
|
| 120 |
+
lm_cat = language_model[order][self._last_order]
|
| 121 |
+
self._seq_counters[lm_cat] += 1
|
| 122 |
+
self._last_order = order
|
| 123 |
+
|
| 124 |
+
charset_name = self._model.charset_name
|
| 125 |
+
if self.state == ProbingState.DETECTING:
|
| 126 |
+
if self._total_seqs > self.SB_ENOUGH_REL_THRESHOLD:
|
| 127 |
+
confidence = self.get_confidence()
|
| 128 |
+
if confidence > self.POSITIVE_SHORTCUT_THRESHOLD:
|
| 129 |
+
self.logger.debug(
|
| 130 |
+
"%s confidence = %s, we have a winner", charset_name, confidence
|
| 131 |
+
)
|
| 132 |
+
self._state = ProbingState.FOUND_IT
|
| 133 |
+
elif confidence < self.NEGATIVE_SHORTCUT_THRESHOLD:
|
| 134 |
+
self.logger.debug(
|
| 135 |
+
"%s confidence = %s, below negative shortcut threshold %s",
|
| 136 |
+
charset_name,
|
| 137 |
+
confidence,
|
| 138 |
+
self.NEGATIVE_SHORTCUT_THRESHOLD,
|
| 139 |
+
)
|
| 140 |
+
self._state = ProbingState.NOT_ME
|
| 141 |
+
|
| 142 |
+
return self.state
|
| 143 |
+
|
| 144 |
+
def get_confidence(self) -> float:
|
| 145 |
+
r = 0.01
|
| 146 |
+
if self._total_seqs > 0:
|
| 147 |
+
r = (
|
| 148 |
+
(
|
| 149 |
+
self._seq_counters[SequenceLikelihood.POSITIVE]
|
| 150 |
+
+ 0.25 * self._seq_counters[SequenceLikelihood.LIKELY]
|
| 151 |
+
)
|
| 152 |
+
/ self._total_seqs
|
| 153 |
+
/ self._model.typical_positive_ratio
|
| 154 |
+
)
|
| 155 |
+
# The more control characters (proportionnaly to the size
|
| 156 |
+
# of the text), the less confident we become in the current
|
| 157 |
+
# charset.
|
| 158 |
+
r = r * (self._total_char - self._control_char) / self._total_char
|
| 159 |
+
r = r * self._freq_char / self._total_char
|
| 160 |
+
if r >= 1.0:
|
| 161 |
+
r = 0.99
|
| 162 |
+
return r
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/sbcsgroupprober.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
######################## BEGIN LICENSE BLOCK ########################
|
| 2 |
+
# The Original Code is Mozilla Universal charset detector code.
|
| 3 |
+
#
|
| 4 |
+
# The Initial Developer of the Original Code is
|
| 5 |
+
# Netscape Communications Corporation.
|
| 6 |
+
# Portions created by the Initial Developer are Copyright (C) 2001
|
| 7 |
+
# the Initial Developer. All Rights Reserved.
|
| 8 |
+
#
|
| 9 |
+
# Contributor(s):
|
| 10 |
+
# Mark Pilgrim - port to Python
|
| 11 |
+
# Shy Shalom - original C code
|
| 12 |
+
#
|
| 13 |
+
# This library is free software; you can redistribute it and/or
|
| 14 |
+
# modify it under the terms of the GNU Lesser General Public
|
| 15 |
+
# License as published by the Free Software Foundation; either
|
| 16 |
+
# version 2.1 of the License, or (at your option) any later version.
|
| 17 |
+
#
|
| 18 |
+
# This library is distributed in the hope that it will be useful,
|
| 19 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 20 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 21 |
+
# Lesser General Public License for more details.
|
| 22 |
+
#
|
| 23 |
+
# You should have received a copy of the GNU Lesser General Public
|
| 24 |
+
# License along with this library; if not, write to the Free Software
|
| 25 |
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
| 26 |
+
# 02110-1301 USA
|
| 27 |
+
######################### END LICENSE BLOCK #########################
|
| 28 |
+
|
| 29 |
+
from .charsetgroupprober import CharSetGroupProber
|
| 30 |
+
from .hebrewprober import HebrewProber
|
| 31 |
+
from .langbulgarianmodel import ISO_8859_5_BULGARIAN_MODEL, WINDOWS_1251_BULGARIAN_MODEL
|
| 32 |
+
from .langgreekmodel import ISO_8859_7_GREEK_MODEL, WINDOWS_1253_GREEK_MODEL
|
| 33 |
+
from .langhebrewmodel import WINDOWS_1255_HEBREW_MODEL
|
| 34 |
+
|
| 35 |
+
# from .langhungarianmodel import (ISO_8859_2_HUNGARIAN_MODEL,
|
| 36 |
+
# WINDOWS_1250_HUNGARIAN_MODEL)
|
| 37 |
+
from .langrussianmodel import (
|
| 38 |
+
IBM855_RUSSIAN_MODEL,
|
| 39 |
+
IBM866_RUSSIAN_MODEL,
|
| 40 |
+
ISO_8859_5_RUSSIAN_MODEL,
|
| 41 |
+
KOI8_R_RUSSIAN_MODEL,
|
| 42 |
+
MACCYRILLIC_RUSSIAN_MODEL,
|
| 43 |
+
WINDOWS_1251_RUSSIAN_MODEL,
|
| 44 |
+
)
|
| 45 |
+
from .langthaimodel import TIS_620_THAI_MODEL
|
| 46 |
+
from .langturkishmodel import ISO_8859_9_TURKISH_MODEL
|
| 47 |
+
from .sbcharsetprober import SingleByteCharSetProber
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
class SBCSGroupProber(CharSetGroupProber):
|
| 51 |
+
def __init__(self) -> None:
|
| 52 |
+
super().__init__()
|
| 53 |
+
hebrew_prober = HebrewProber()
|
| 54 |
+
logical_hebrew_prober = SingleByteCharSetProber(
|
| 55 |
+
WINDOWS_1255_HEBREW_MODEL, is_reversed=False, name_prober=hebrew_prober
|
| 56 |
+
)
|
| 57 |
+
# TODO: See if using ISO-8859-8 Hebrew model works better here, since
|
| 58 |
+
# it's actually the visual one
|
| 59 |
+
visual_hebrew_prober = SingleByteCharSetProber(
|
| 60 |
+
WINDOWS_1255_HEBREW_MODEL, is_reversed=True, name_prober=hebrew_prober
|
| 61 |
+
)
|
| 62 |
+
hebrew_prober.set_model_probers(logical_hebrew_prober, visual_hebrew_prober)
|
| 63 |
+
# TODO: ORDER MATTERS HERE. I changed the order vs what was in master
|
| 64 |
+
# and several tests failed that did not before. Some thought
|
| 65 |
+
# should be put into the ordering, and we should consider making
|
| 66 |
+
# order not matter here, because that is very counter-intuitive.
|
| 67 |
+
self.probers = [
|
| 68 |
+
SingleByteCharSetProber(WINDOWS_1251_RUSSIAN_MODEL),
|
| 69 |
+
SingleByteCharSetProber(KOI8_R_RUSSIAN_MODEL),
|
| 70 |
+
SingleByteCharSetProber(ISO_8859_5_RUSSIAN_MODEL),
|
| 71 |
+
SingleByteCharSetProber(MACCYRILLIC_RUSSIAN_MODEL),
|
| 72 |
+
SingleByteCharSetProber(IBM866_RUSSIAN_MODEL),
|
| 73 |
+
SingleByteCharSetProber(IBM855_RUSSIAN_MODEL),
|
| 74 |
+
SingleByteCharSetProber(ISO_8859_7_GREEK_MODEL),
|
| 75 |
+
SingleByteCharSetProber(WINDOWS_1253_GREEK_MODEL),
|
| 76 |
+
SingleByteCharSetProber(ISO_8859_5_BULGARIAN_MODEL),
|
| 77 |
+
SingleByteCharSetProber(WINDOWS_1251_BULGARIAN_MODEL),
|
| 78 |
+
# TODO: Restore Hungarian encodings (iso-8859-2 and windows-1250)
|
| 79 |
+
# after we retrain model.
|
| 80 |
+
# SingleByteCharSetProber(ISO_8859_2_HUNGARIAN_MODEL),
|
| 81 |
+
# SingleByteCharSetProber(WINDOWS_1250_HUNGARIAN_MODEL),
|
| 82 |
+
SingleByteCharSetProber(TIS_620_THAI_MODEL),
|
| 83 |
+
SingleByteCharSetProber(ISO_8859_9_TURKISH_MODEL),
|
| 84 |
+
hebrew_prober,
|
| 85 |
+
logical_hebrew_prober,
|
| 86 |
+
visual_hebrew_prober,
|
| 87 |
+
]
|
| 88 |
+
self.reset()
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/sjisprober.py
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
######################## BEGIN LICENSE BLOCK ########################
|
| 2 |
+
# The Original Code is mozilla.org code.
|
| 3 |
+
#
|
| 4 |
+
# The Initial Developer of the Original Code is
|
| 5 |
+
# Netscape Communications Corporation.
|
| 6 |
+
# Portions created by the Initial Developer are Copyright (C) 1998
|
| 7 |
+
# the Initial Developer. All Rights Reserved.
|
| 8 |
+
#
|
| 9 |
+
# Contributor(s):
|
| 10 |
+
# Mark Pilgrim - port to Python
|
| 11 |
+
#
|
| 12 |
+
# This library is free software; you can redistribute it and/or
|
| 13 |
+
# modify it under the terms of the GNU Lesser General Public
|
| 14 |
+
# License as published by the Free Software Foundation; either
|
| 15 |
+
# version 2.1 of the License, or (at your option) any later version.
|
| 16 |
+
#
|
| 17 |
+
# This library is distributed in the hope that it will be useful,
|
| 18 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 19 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 20 |
+
# Lesser General Public License for more details.
|
| 21 |
+
#
|
| 22 |
+
# You should have received a copy of the GNU Lesser General Public
|
| 23 |
+
# License along with this library; if not, write to the Free Software
|
| 24 |
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
| 25 |
+
# 02110-1301 USA
|
| 26 |
+
######################### END LICENSE BLOCK #########################
|
| 27 |
+
|
| 28 |
+
from typing import Union
|
| 29 |
+
|
| 30 |
+
from .chardistribution import SJISDistributionAnalysis
|
| 31 |
+
from .codingstatemachine import CodingStateMachine
|
| 32 |
+
from .enums import MachineState, ProbingState
|
| 33 |
+
from .jpcntx import SJISContextAnalysis
|
| 34 |
+
from .mbcharsetprober import MultiByteCharSetProber
|
| 35 |
+
from .mbcssm import SJIS_SM_MODEL
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
class SJISProber(MultiByteCharSetProber):
|
| 39 |
+
def __init__(self) -> None:
|
| 40 |
+
super().__init__()
|
| 41 |
+
self.coding_sm = CodingStateMachine(SJIS_SM_MODEL)
|
| 42 |
+
self.distribution_analyzer = SJISDistributionAnalysis()
|
| 43 |
+
self.context_analyzer = SJISContextAnalysis()
|
| 44 |
+
self.reset()
|
| 45 |
+
|
| 46 |
+
def reset(self) -> None:
|
| 47 |
+
super().reset()
|
| 48 |
+
self.context_analyzer.reset()
|
| 49 |
+
|
| 50 |
+
@property
|
| 51 |
+
def charset_name(self) -> str:
|
| 52 |
+
return self.context_analyzer.charset_name
|
| 53 |
+
|
| 54 |
+
@property
|
| 55 |
+
def language(self) -> str:
|
| 56 |
+
return "Japanese"
|
| 57 |
+
|
| 58 |
+
def feed(self, byte_str: Union[bytes, bytearray]) -> ProbingState:
|
| 59 |
+
assert self.coding_sm is not None
|
| 60 |
+
assert self.distribution_analyzer is not None
|
| 61 |
+
|
| 62 |
+
for i, byte in enumerate(byte_str):
|
| 63 |
+
coding_state = self.coding_sm.next_state(byte)
|
| 64 |
+
if coding_state == MachineState.ERROR:
|
| 65 |
+
self.logger.debug(
|
| 66 |
+
"%s %s prober hit error at byte %s",
|
| 67 |
+
self.charset_name,
|
| 68 |
+
self.language,
|
| 69 |
+
i,
|
| 70 |
+
)
|
| 71 |
+
self._state = ProbingState.NOT_ME
|
| 72 |
+
break
|
| 73 |
+
if coding_state == MachineState.ITS_ME:
|
| 74 |
+
self._state = ProbingState.FOUND_IT
|
| 75 |
+
break
|
| 76 |
+
if coding_state == MachineState.START:
|
| 77 |
+
char_len = self.coding_sm.get_current_charlen()
|
| 78 |
+
if i == 0:
|
| 79 |
+
self._last_char[1] = byte
|
| 80 |
+
self.context_analyzer.feed(
|
| 81 |
+
self._last_char[2 - char_len :], char_len
|
| 82 |
+
)
|
| 83 |
+
self.distribution_analyzer.feed(self._last_char, char_len)
|
| 84 |
+
else:
|
| 85 |
+
self.context_analyzer.feed(
|
| 86 |
+
byte_str[i + 1 - char_len : i + 3 - char_len], char_len
|
| 87 |
+
)
|
| 88 |
+
self.distribution_analyzer.feed(byte_str[i - 1 : i + 1], char_len)
|
| 89 |
+
|
| 90 |
+
self._last_char[0] = byte_str[-1]
|
| 91 |
+
|
| 92 |
+
if self.state == ProbingState.DETECTING:
|
| 93 |
+
if self.context_analyzer.got_enough_data() and (
|
| 94 |
+
self.get_confidence() > self.SHORTCUT_THRESHOLD
|
| 95 |
+
):
|
| 96 |
+
self._state = ProbingState.FOUND_IT
|
| 97 |
+
|
| 98 |
+
return self.state
|
| 99 |
+
|
| 100 |
+
def get_confidence(self) -> float:
|
| 101 |
+
assert self.distribution_analyzer is not None
|
| 102 |
+
|
| 103 |
+
context_conf = self.context_analyzer.get_confidence()
|
| 104 |
+
distrib_conf = self.distribution_analyzer.get_confidence()
|
| 105 |
+
return max(context_conf, distrib_conf)
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/universaldetector.py
ADDED
|
@@ -0,0 +1,362 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
######################## BEGIN LICENSE BLOCK ########################
|
| 2 |
+
# The Original Code is Mozilla Universal charset detector code.
|
| 3 |
+
#
|
| 4 |
+
# The Initial Developer of the Original Code is
|
| 5 |
+
# Netscape Communications Corporation.
|
| 6 |
+
# Portions created by the Initial Developer are Copyright (C) 2001
|
| 7 |
+
# the Initial Developer. All Rights Reserved.
|
| 8 |
+
#
|
| 9 |
+
# Contributor(s):
|
| 10 |
+
# Mark Pilgrim - port to Python
|
| 11 |
+
# Shy Shalom - original C code
|
| 12 |
+
#
|
| 13 |
+
# This library is free software; you can redistribute it and/or
|
| 14 |
+
# modify it under the terms of the GNU Lesser General Public
|
| 15 |
+
# License as published by the Free Software Foundation; either
|
| 16 |
+
# version 2.1 of the License, or (at your option) any later version.
|
| 17 |
+
#
|
| 18 |
+
# This library is distributed in the hope that it will be useful,
|
| 19 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 20 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 21 |
+
# Lesser General Public License for more details.
|
| 22 |
+
#
|
| 23 |
+
# You should have received a copy of the GNU Lesser General Public
|
| 24 |
+
# License along with this library; if not, write to the Free Software
|
| 25 |
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
| 26 |
+
# 02110-1301 USA
|
| 27 |
+
######################### END LICENSE BLOCK #########################
|
| 28 |
+
"""
|
| 29 |
+
Module containing the UniversalDetector detector class, which is the primary
|
| 30 |
+
class a user of ``chardet`` should use.
|
| 31 |
+
|
| 32 |
+
:author: Mark Pilgrim (initial port to Python)
|
| 33 |
+
:author: Shy Shalom (original C code)
|
| 34 |
+
:author: Dan Blanchard (major refactoring for 3.0)
|
| 35 |
+
:author: Ian Cordasco
|
| 36 |
+
"""
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
import codecs
|
| 40 |
+
import logging
|
| 41 |
+
import re
|
| 42 |
+
from typing import List, Optional, Union
|
| 43 |
+
|
| 44 |
+
from .charsetgroupprober import CharSetGroupProber
|
| 45 |
+
from .charsetprober import CharSetProber
|
| 46 |
+
from .enums import InputState, LanguageFilter, ProbingState
|
| 47 |
+
from .escprober import EscCharSetProber
|
| 48 |
+
from .latin1prober import Latin1Prober
|
| 49 |
+
from .macromanprober import MacRomanProber
|
| 50 |
+
from .mbcsgroupprober import MBCSGroupProber
|
| 51 |
+
from .resultdict import ResultDict
|
| 52 |
+
from .sbcsgroupprober import SBCSGroupProber
|
| 53 |
+
from .utf1632prober import UTF1632Prober
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
class UniversalDetector:
|
| 57 |
+
"""
|
| 58 |
+
The ``UniversalDetector`` class underlies the ``chardet.detect`` function
|
| 59 |
+
and coordinates all of the different charset probers.
|
| 60 |
+
|
| 61 |
+
To get a ``dict`` containing an encoding and its confidence, you can simply
|
| 62 |
+
run:
|
| 63 |
+
|
| 64 |
+
.. code::
|
| 65 |
+
|
| 66 |
+
u = UniversalDetector()
|
| 67 |
+
u.feed(some_bytes)
|
| 68 |
+
u.close()
|
| 69 |
+
detected = u.result
|
| 70 |
+
|
| 71 |
+
"""
|
| 72 |
+
|
| 73 |
+
MINIMUM_THRESHOLD = 0.20
|
| 74 |
+
HIGH_BYTE_DETECTOR = re.compile(b"[\x80-\xFF]")
|
| 75 |
+
ESC_DETECTOR = re.compile(b"(\033|~{)")
|
| 76 |
+
WIN_BYTE_DETECTOR = re.compile(b"[\x80-\x9F]")
|
| 77 |
+
ISO_WIN_MAP = {
|
| 78 |
+
"iso-8859-1": "Windows-1252",
|
| 79 |
+
"iso-8859-2": "Windows-1250",
|
| 80 |
+
"iso-8859-5": "Windows-1251",
|
| 81 |
+
"iso-8859-6": "Windows-1256",
|
| 82 |
+
"iso-8859-7": "Windows-1253",
|
| 83 |
+
"iso-8859-8": "Windows-1255",
|
| 84 |
+
"iso-8859-9": "Windows-1254",
|
| 85 |
+
"iso-8859-13": "Windows-1257",
|
| 86 |
+
}
|
| 87 |
+
# Based on https://encoding.spec.whatwg.org/#names-and-labels
|
| 88 |
+
# but altered to match Python names for encodings and remove mappings
|
| 89 |
+
# that break tests.
|
| 90 |
+
LEGACY_MAP = {
|
| 91 |
+
"ascii": "Windows-1252",
|
| 92 |
+
"iso-8859-1": "Windows-1252",
|
| 93 |
+
"tis-620": "ISO-8859-11",
|
| 94 |
+
"iso-8859-9": "Windows-1254",
|
| 95 |
+
"gb2312": "GB18030",
|
| 96 |
+
"euc-kr": "CP949",
|
| 97 |
+
"utf-16le": "UTF-16",
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
def __init__(
|
| 101 |
+
self,
|
| 102 |
+
lang_filter: LanguageFilter = LanguageFilter.ALL,
|
| 103 |
+
should_rename_legacy: bool = False,
|
| 104 |
+
) -> None:
|
| 105 |
+
self._esc_charset_prober: Optional[EscCharSetProber] = None
|
| 106 |
+
self._utf1632_prober: Optional[UTF1632Prober] = None
|
| 107 |
+
self._charset_probers: List[CharSetProber] = []
|
| 108 |
+
self.result: ResultDict = {
|
| 109 |
+
"encoding": None,
|
| 110 |
+
"confidence": 0.0,
|
| 111 |
+
"language": None,
|
| 112 |
+
}
|
| 113 |
+
self.done = False
|
| 114 |
+
self._got_data = False
|
| 115 |
+
self._input_state = InputState.PURE_ASCII
|
| 116 |
+
self._last_char = b""
|
| 117 |
+
self.lang_filter = lang_filter
|
| 118 |
+
self.logger = logging.getLogger(__name__)
|
| 119 |
+
self._has_win_bytes = False
|
| 120 |
+
self.should_rename_legacy = should_rename_legacy
|
| 121 |
+
self.reset()
|
| 122 |
+
|
| 123 |
+
@property
|
| 124 |
+
def input_state(self) -> int:
|
| 125 |
+
return self._input_state
|
| 126 |
+
|
| 127 |
+
@property
|
| 128 |
+
def has_win_bytes(self) -> bool:
|
| 129 |
+
return self._has_win_bytes
|
| 130 |
+
|
| 131 |
+
@property
|
| 132 |
+
def charset_probers(self) -> List[CharSetProber]:
|
| 133 |
+
return self._charset_probers
|
| 134 |
+
|
| 135 |
+
def reset(self) -> None:
|
| 136 |
+
"""
|
| 137 |
+
Reset the UniversalDetector and all of its probers back to their
|
| 138 |
+
initial states. This is called by ``__init__``, so you only need to
|
| 139 |
+
call this directly in between analyses of different documents.
|
| 140 |
+
"""
|
| 141 |
+
self.result = {"encoding": None, "confidence": 0.0, "language": None}
|
| 142 |
+
self.done = False
|
| 143 |
+
self._got_data = False
|
| 144 |
+
self._has_win_bytes = False
|
| 145 |
+
self._input_state = InputState.PURE_ASCII
|
| 146 |
+
self._last_char = b""
|
| 147 |
+
if self._esc_charset_prober:
|
| 148 |
+
self._esc_charset_prober.reset()
|
| 149 |
+
if self._utf1632_prober:
|
| 150 |
+
self._utf1632_prober.reset()
|
| 151 |
+
for prober in self._charset_probers:
|
| 152 |
+
prober.reset()
|
| 153 |
+
|
| 154 |
+
def feed(self, byte_str: Union[bytes, bytearray]) -> None:
|
| 155 |
+
"""
|
| 156 |
+
Takes a chunk of a document and feeds it through all of the relevant
|
| 157 |
+
charset probers.
|
| 158 |
+
|
| 159 |
+
After calling ``feed``, you can check the value of the ``done``
|
| 160 |
+
attribute to see if you need to continue feeding the
|
| 161 |
+
``UniversalDetector`` more data, or if it has made a prediction
|
| 162 |
+
(in the ``result`` attribute).
|
| 163 |
+
|
| 164 |
+
.. note::
|
| 165 |
+
You should always call ``close`` when you're done feeding in your
|
| 166 |
+
document if ``done`` is not already ``True``.
|
| 167 |
+
"""
|
| 168 |
+
if self.done:
|
| 169 |
+
return
|
| 170 |
+
|
| 171 |
+
if not byte_str:
|
| 172 |
+
return
|
| 173 |
+
|
| 174 |
+
if not isinstance(byte_str, bytearray):
|
| 175 |
+
byte_str = bytearray(byte_str)
|
| 176 |
+
|
| 177 |
+
# First check for known BOMs, since these are guaranteed to be correct
|
| 178 |
+
if not self._got_data:
|
| 179 |
+
# If the data starts with BOM, we know it is UTF
|
| 180 |
+
if byte_str.startswith(codecs.BOM_UTF8):
|
| 181 |
+
# EF BB BF UTF-8 with BOM
|
| 182 |
+
self.result = {
|
| 183 |
+
"encoding": "UTF-8-SIG",
|
| 184 |
+
"confidence": 1.0,
|
| 185 |
+
"language": "",
|
| 186 |
+
}
|
| 187 |
+
elif byte_str.startswith((codecs.BOM_UTF32_LE, codecs.BOM_UTF32_BE)):
|
| 188 |
+
# FF FE 00 00 UTF-32, little-endian BOM
|
| 189 |
+
# 00 00 FE FF UTF-32, big-endian BOM
|
| 190 |
+
self.result = {"encoding": "UTF-32", "confidence": 1.0, "language": ""}
|
| 191 |
+
elif byte_str.startswith(b"\xFE\xFF\x00\x00"):
|
| 192 |
+
# FE FF 00 00 UCS-4, unusual octet order BOM (3412)
|
| 193 |
+
self.result = {
|
| 194 |
+
# TODO: This encoding is not supported by Python. Should remove?
|
| 195 |
+
"encoding": "X-ISO-10646-UCS-4-3412",
|
| 196 |
+
"confidence": 1.0,
|
| 197 |
+
"language": "",
|
| 198 |
+
}
|
| 199 |
+
elif byte_str.startswith(b"\x00\x00\xFF\xFE"):
|
| 200 |
+
# 00 00 FF FE UCS-4, unusual octet order BOM (2143)
|
| 201 |
+
self.result = {
|
| 202 |
+
# TODO: This encoding is not supported by Python. Should remove?
|
| 203 |
+
"encoding": "X-ISO-10646-UCS-4-2143",
|
| 204 |
+
"confidence": 1.0,
|
| 205 |
+
"language": "",
|
| 206 |
+
}
|
| 207 |
+
elif byte_str.startswith((codecs.BOM_LE, codecs.BOM_BE)):
|
| 208 |
+
# FF FE UTF-16, little endian BOM
|
| 209 |
+
# FE FF UTF-16, big endian BOM
|
| 210 |
+
self.result = {"encoding": "UTF-16", "confidence": 1.0, "language": ""}
|
| 211 |
+
|
| 212 |
+
self._got_data = True
|
| 213 |
+
if self.result["encoding"] is not None:
|
| 214 |
+
self.done = True
|
| 215 |
+
return
|
| 216 |
+
|
| 217 |
+
# If none of those matched and we've only see ASCII so far, check
|
| 218 |
+
# for high bytes and escape sequences
|
| 219 |
+
if self._input_state == InputState.PURE_ASCII:
|
| 220 |
+
if self.HIGH_BYTE_DETECTOR.search(byte_str):
|
| 221 |
+
self._input_state = InputState.HIGH_BYTE
|
| 222 |
+
elif (
|
| 223 |
+
self._input_state == InputState.PURE_ASCII
|
| 224 |
+
and self.ESC_DETECTOR.search(self._last_char + byte_str)
|
| 225 |
+
):
|
| 226 |
+
self._input_state = InputState.ESC_ASCII
|
| 227 |
+
|
| 228 |
+
self._last_char = byte_str[-1:]
|
| 229 |
+
|
| 230 |
+
# next we will look to see if it is appears to be either a UTF-16 or
|
| 231 |
+
# UTF-32 encoding
|
| 232 |
+
if not self._utf1632_prober:
|
| 233 |
+
self._utf1632_prober = UTF1632Prober()
|
| 234 |
+
|
| 235 |
+
if self._utf1632_prober.state == ProbingState.DETECTING:
|
| 236 |
+
if self._utf1632_prober.feed(byte_str) == ProbingState.FOUND_IT:
|
| 237 |
+
self.result = {
|
| 238 |
+
"encoding": self._utf1632_prober.charset_name,
|
| 239 |
+
"confidence": self._utf1632_prober.get_confidence(),
|
| 240 |
+
"language": "",
|
| 241 |
+
}
|
| 242 |
+
self.done = True
|
| 243 |
+
return
|
| 244 |
+
|
| 245 |
+
# If we've seen escape sequences, use the EscCharSetProber, which
|
| 246 |
+
# uses a simple state machine to check for known escape sequences in
|
| 247 |
+
# HZ and ISO-2022 encodings, since those are the only encodings that
|
| 248 |
+
# use such sequences.
|
| 249 |
+
if self._input_state == InputState.ESC_ASCII:
|
| 250 |
+
if not self._esc_charset_prober:
|
| 251 |
+
self._esc_charset_prober = EscCharSetProber(self.lang_filter)
|
| 252 |
+
if self._esc_charset_prober.feed(byte_str) == ProbingState.FOUND_IT:
|
| 253 |
+
self.result = {
|
| 254 |
+
"encoding": self._esc_charset_prober.charset_name,
|
| 255 |
+
"confidence": self._esc_charset_prober.get_confidence(),
|
| 256 |
+
"language": self._esc_charset_prober.language,
|
| 257 |
+
}
|
| 258 |
+
self.done = True
|
| 259 |
+
# If we've seen high bytes (i.e., those with values greater than 127),
|
| 260 |
+
# we need to do more complicated checks using all our multi-byte and
|
| 261 |
+
# single-byte probers that are left. The single-byte probers
|
| 262 |
+
# use character bigram distributions to determine the encoding, whereas
|
| 263 |
+
# the multi-byte probers use a combination of character unigram and
|
| 264 |
+
# bigram distributions.
|
| 265 |
+
elif self._input_state == InputState.HIGH_BYTE:
|
| 266 |
+
if not self._charset_probers:
|
| 267 |
+
self._charset_probers = [MBCSGroupProber(self.lang_filter)]
|
| 268 |
+
# If we're checking non-CJK encodings, use single-byte prober
|
| 269 |
+
if self.lang_filter & LanguageFilter.NON_CJK:
|
| 270 |
+
self._charset_probers.append(SBCSGroupProber())
|
| 271 |
+
self._charset_probers.append(Latin1Prober())
|
| 272 |
+
self._charset_probers.append(MacRomanProber())
|
| 273 |
+
for prober in self._charset_probers:
|
| 274 |
+
if prober.feed(byte_str) == ProbingState.FOUND_IT:
|
| 275 |
+
self.result = {
|
| 276 |
+
"encoding": prober.charset_name,
|
| 277 |
+
"confidence": prober.get_confidence(),
|
| 278 |
+
"language": prober.language,
|
| 279 |
+
}
|
| 280 |
+
self.done = True
|
| 281 |
+
break
|
| 282 |
+
if self.WIN_BYTE_DETECTOR.search(byte_str):
|
| 283 |
+
self._has_win_bytes = True
|
| 284 |
+
|
| 285 |
+
def close(self) -> ResultDict:
|
| 286 |
+
"""
|
| 287 |
+
Stop analyzing the current document and come up with a final
|
| 288 |
+
prediction.
|
| 289 |
+
|
| 290 |
+
:returns: The ``result`` attribute, a ``dict`` with the keys
|
| 291 |
+
`encoding`, `confidence`, and `language`.
|
| 292 |
+
"""
|
| 293 |
+
# Don't bother with checks if we're already done
|
| 294 |
+
if self.done:
|
| 295 |
+
return self.result
|
| 296 |
+
self.done = True
|
| 297 |
+
|
| 298 |
+
if not self._got_data:
|
| 299 |
+
self.logger.debug("no data received!")
|
| 300 |
+
|
| 301 |
+
# Default to ASCII if it is all we've seen so far
|
| 302 |
+
elif self._input_state == InputState.PURE_ASCII:
|
| 303 |
+
self.result = {"encoding": "ascii", "confidence": 1.0, "language": ""}
|
| 304 |
+
|
| 305 |
+
# If we have seen non-ASCII, return the best that met MINIMUM_THRESHOLD
|
| 306 |
+
elif self._input_state == InputState.HIGH_BYTE:
|
| 307 |
+
prober_confidence = None
|
| 308 |
+
max_prober_confidence = 0.0
|
| 309 |
+
max_prober = None
|
| 310 |
+
for prober in self._charset_probers:
|
| 311 |
+
if not prober:
|
| 312 |
+
continue
|
| 313 |
+
prober_confidence = prober.get_confidence()
|
| 314 |
+
if prober_confidence > max_prober_confidence:
|
| 315 |
+
max_prober_confidence = prober_confidence
|
| 316 |
+
max_prober = prober
|
| 317 |
+
if max_prober and (max_prober_confidence > self.MINIMUM_THRESHOLD):
|
| 318 |
+
charset_name = max_prober.charset_name
|
| 319 |
+
assert charset_name is not None
|
| 320 |
+
lower_charset_name = charset_name.lower()
|
| 321 |
+
confidence = max_prober.get_confidence()
|
| 322 |
+
# Use Windows encoding name instead of ISO-8859 if we saw any
|
| 323 |
+
# extra Windows-specific bytes
|
| 324 |
+
if lower_charset_name.startswith("iso-8859"):
|
| 325 |
+
if self._has_win_bytes:
|
| 326 |
+
charset_name = self.ISO_WIN_MAP.get(
|
| 327 |
+
lower_charset_name, charset_name
|
| 328 |
+
)
|
| 329 |
+
# Rename legacy encodings with superset encodings if asked
|
| 330 |
+
if self.should_rename_legacy:
|
| 331 |
+
charset_name = self.LEGACY_MAP.get(
|
| 332 |
+
(charset_name or "").lower(), charset_name
|
| 333 |
+
)
|
| 334 |
+
self.result = {
|
| 335 |
+
"encoding": charset_name,
|
| 336 |
+
"confidence": confidence,
|
| 337 |
+
"language": max_prober.language,
|
| 338 |
+
}
|
| 339 |
+
|
| 340 |
+
# Log all prober confidences if none met MINIMUM_THRESHOLD
|
| 341 |
+
if self.logger.getEffectiveLevel() <= logging.DEBUG:
|
| 342 |
+
if self.result["encoding"] is None:
|
| 343 |
+
self.logger.debug("no probers hit minimum threshold")
|
| 344 |
+
for group_prober in self._charset_probers:
|
| 345 |
+
if not group_prober:
|
| 346 |
+
continue
|
| 347 |
+
if isinstance(group_prober, CharSetGroupProber):
|
| 348 |
+
for prober in group_prober.probers:
|
| 349 |
+
self.logger.debug(
|
| 350 |
+
"%s %s confidence = %s",
|
| 351 |
+
prober.charset_name,
|
| 352 |
+
prober.language,
|
| 353 |
+
prober.get_confidence(),
|
| 354 |
+
)
|
| 355 |
+
else:
|
| 356 |
+
self.logger.debug(
|
| 357 |
+
"%s %s confidence = %s",
|
| 358 |
+
group_prober.charset_name,
|
| 359 |
+
group_prober.language,
|
| 360 |
+
group_prober.get_confidence(),
|
| 361 |
+
)
|
| 362 |
+
return self.result
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/chardet/utf1632prober.py
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
######################## BEGIN LICENSE BLOCK ########################
|
| 2 |
+
#
|
| 3 |
+
# Contributor(s):
|
| 4 |
+
# Jason Zavaglia
|
| 5 |
+
#
|
| 6 |
+
# This library is free software; you can redistribute it and/or
|
| 7 |
+
# modify it under the terms of the GNU Lesser General Public
|
| 8 |
+
# License as published by the Free Software Foundation; either
|
| 9 |
+
# version 2.1 of the License, or (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# This library is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 14 |
+
# Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public
|
| 17 |
+
# License along with this library; if not, write to the Free Software
|
| 18 |
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
| 19 |
+
# 02110-1301 USA
|
| 20 |
+
######################### END LICENSE BLOCK #########################
|
| 21 |
+
from typing import List, Union
|
| 22 |
+
|
| 23 |
+
from .charsetprober import CharSetProber
|
| 24 |
+
from .enums import ProbingState
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class UTF1632Prober(CharSetProber):
|
| 28 |
+
"""
|
| 29 |
+
This class simply looks for occurrences of zero bytes, and infers
|
| 30 |
+
whether the file is UTF16 or UTF32 (low-endian or big-endian)
|
| 31 |
+
For instance, files looking like ( \0 \0 \0 [nonzero] )+
|
| 32 |
+
have a good probability to be UTF32BE. Files looking like ( \0 [nonzero] )+
|
| 33 |
+
may be guessed to be UTF16BE, and inversely for little-endian varieties.
|
| 34 |
+
"""
|
| 35 |
+
|
| 36 |
+
# how many logical characters to scan before feeling confident of prediction
|
| 37 |
+
MIN_CHARS_FOR_DETECTION = 20
|
| 38 |
+
# a fixed constant ratio of expected zeros or non-zeros in modulo-position.
|
| 39 |
+
EXPECTED_RATIO = 0.94
|
| 40 |
+
|
| 41 |
+
def __init__(self) -> None:
|
| 42 |
+
super().__init__()
|
| 43 |
+
self.position = 0
|
| 44 |
+
self.zeros_at_mod = [0] * 4
|
| 45 |
+
self.nonzeros_at_mod = [0] * 4
|
| 46 |
+
self._state = ProbingState.DETECTING
|
| 47 |
+
self.quad = [0, 0, 0, 0]
|
| 48 |
+
self.invalid_utf16be = False
|
| 49 |
+
self.invalid_utf16le = False
|
| 50 |
+
self.invalid_utf32be = False
|
| 51 |
+
self.invalid_utf32le = False
|
| 52 |
+
self.first_half_surrogate_pair_detected_16be = False
|
| 53 |
+
self.first_half_surrogate_pair_detected_16le = False
|
| 54 |
+
self.reset()
|
| 55 |
+
|
| 56 |
+
def reset(self) -> None:
|
| 57 |
+
super().reset()
|
| 58 |
+
self.position = 0
|
| 59 |
+
self.zeros_at_mod = [0] * 4
|
| 60 |
+
self.nonzeros_at_mod = [0] * 4
|
| 61 |
+
self._state = ProbingState.DETECTING
|
| 62 |
+
self.invalid_utf16be = False
|
| 63 |
+
self.invalid_utf16le = False
|
| 64 |
+
self.invalid_utf32be = False
|
| 65 |
+
self.invalid_utf32le = False
|
| 66 |
+
self.first_half_surrogate_pair_detected_16be = False
|
| 67 |
+
self.first_half_surrogate_pair_detected_16le = False
|
| 68 |
+
self.quad = [0, 0, 0, 0]
|
| 69 |
+
|
| 70 |
+
@property
|
| 71 |
+
def charset_name(self) -> str:
|
| 72 |
+
if self.is_likely_utf32be():
|
| 73 |
+
return "utf-32be"
|
| 74 |
+
if self.is_likely_utf32le():
|
| 75 |
+
return "utf-32le"
|
| 76 |
+
if self.is_likely_utf16be():
|
| 77 |
+
return "utf-16be"
|
| 78 |
+
if self.is_likely_utf16le():
|
| 79 |
+
return "utf-16le"
|
| 80 |
+
# default to something valid
|
| 81 |
+
return "utf-16"
|
| 82 |
+
|
| 83 |
+
@property
|
| 84 |
+
def language(self) -> str:
|
| 85 |
+
return ""
|
| 86 |
+
|
| 87 |
+
def approx_32bit_chars(self) -> float:
|
| 88 |
+
return max(1.0, self.position / 4.0)
|
| 89 |
+
|
| 90 |
+
def approx_16bit_chars(self) -> float:
|
| 91 |
+
return max(1.0, self.position / 2.0)
|
| 92 |
+
|
| 93 |
+
def is_likely_utf32be(self) -> bool:
|
| 94 |
+
approx_chars = self.approx_32bit_chars()
|
| 95 |
+
return approx_chars >= self.MIN_CHARS_FOR_DETECTION and (
|
| 96 |
+
self.zeros_at_mod[0] / approx_chars > self.EXPECTED_RATIO
|
| 97 |
+
and self.zeros_at_mod[1] / approx_chars > self.EXPECTED_RATIO
|
| 98 |
+
and self.zeros_at_mod[2] / approx_chars > self.EXPECTED_RATIO
|
| 99 |
+
and self.nonzeros_at_mod[3] / approx_chars > self.EXPECTED_RATIO
|
| 100 |
+
and not self.invalid_utf32be
|
| 101 |
+
)
|
| 102 |
+
|
| 103 |
+
def is_likely_utf32le(self) -> bool:
|
| 104 |
+
approx_chars = self.approx_32bit_chars()
|
| 105 |
+
return approx_chars >= self.MIN_CHARS_FOR_DETECTION and (
|
| 106 |
+
self.nonzeros_at_mod[0] / approx_chars > self.EXPECTED_RATIO
|
| 107 |
+
and self.zeros_at_mod[1] / approx_chars > self.EXPECTED_RATIO
|
| 108 |
+
and self.zeros_at_mod[2] / approx_chars > self.EXPECTED_RATIO
|
| 109 |
+
and self.zeros_at_mod[3] / approx_chars > self.EXPECTED_RATIO
|
| 110 |
+
and not self.invalid_utf32le
|
| 111 |
+
)
|
| 112 |
+
|
| 113 |
+
def is_likely_utf16be(self) -> bool:
|
| 114 |
+
approx_chars = self.approx_16bit_chars()
|
| 115 |
+
return approx_chars >= self.MIN_CHARS_FOR_DETECTION and (
|
| 116 |
+
(self.nonzeros_at_mod[1] + self.nonzeros_at_mod[3]) / approx_chars
|
| 117 |
+
> self.EXPECTED_RATIO
|
| 118 |
+
and (self.zeros_at_mod[0] + self.zeros_at_mod[2]) / approx_chars
|
| 119 |
+
> self.EXPECTED_RATIO
|
| 120 |
+
and not self.invalid_utf16be
|
| 121 |
+
)
|
| 122 |
+
|
| 123 |
+
def is_likely_utf16le(self) -> bool:
|
| 124 |
+
approx_chars = self.approx_16bit_chars()
|
| 125 |
+
return approx_chars >= self.MIN_CHARS_FOR_DETECTION and (
|
| 126 |
+
(self.nonzeros_at_mod[0] + self.nonzeros_at_mod[2]) / approx_chars
|
| 127 |
+
> self.EXPECTED_RATIO
|
| 128 |
+
and (self.zeros_at_mod[1] + self.zeros_at_mod[3]) / approx_chars
|
| 129 |
+
> self.EXPECTED_RATIO
|
| 130 |
+
and not self.invalid_utf16le
|
| 131 |
+
)
|
| 132 |
+
|
| 133 |
+
def validate_utf32_characters(self, quad: List[int]) -> None:
|
| 134 |
+
"""
|
| 135 |
+
Validate if the quad of bytes is valid UTF-32.
|
| 136 |
+
|
| 137 |
+
UTF-32 is valid in the range 0x00000000 - 0x0010FFFF
|
| 138 |
+
excluding 0x0000D800 - 0x0000DFFF
|
| 139 |
+
|
| 140 |
+
https://en.wikipedia.org/wiki/UTF-32
|
| 141 |
+
"""
|
| 142 |
+
if (
|
| 143 |
+
quad[0] != 0
|
| 144 |
+
or quad[1] > 0x10
|
| 145 |
+
or (quad[0] == 0 and quad[1] == 0 and 0xD8 <= quad[2] <= 0xDF)
|
| 146 |
+
):
|
| 147 |
+
self.invalid_utf32be = True
|
| 148 |
+
if (
|
| 149 |
+
quad[3] != 0
|
| 150 |
+
or quad[2] > 0x10
|
| 151 |
+
or (quad[3] == 0 and quad[2] == 0 and 0xD8 <= quad[1] <= 0xDF)
|
| 152 |
+
):
|
| 153 |
+
self.invalid_utf32le = True
|
| 154 |
+
|
| 155 |
+
def validate_utf16_characters(self, pair: List[int]) -> None:
|
| 156 |
+
"""
|
| 157 |
+
Validate if the pair of bytes is valid UTF-16.
|
| 158 |
+
|
| 159 |
+
UTF-16 is valid in the range 0x0000 - 0xFFFF excluding 0xD800 - 0xFFFF
|
| 160 |
+
with an exception for surrogate pairs, which must be in the range
|
| 161 |
+
0xD800-0xDBFF followed by 0xDC00-0xDFFF
|
| 162 |
+
|
| 163 |
+
https://en.wikipedia.org/wiki/UTF-16
|
| 164 |
+
"""
|
| 165 |
+
if not self.first_half_surrogate_pair_detected_16be:
|
| 166 |
+
if 0xD8 <= pair[0] <= 0xDB:
|
| 167 |
+
self.first_half_surrogate_pair_detected_16be = True
|
| 168 |
+
elif 0xDC <= pair[0] <= 0xDF:
|
| 169 |
+
self.invalid_utf16be = True
|
| 170 |
+
else:
|
| 171 |
+
if 0xDC <= pair[0] <= 0xDF:
|
| 172 |
+
self.first_half_surrogate_pair_detected_16be = False
|
| 173 |
+
else:
|
| 174 |
+
self.invalid_utf16be = True
|
| 175 |
+
|
| 176 |
+
if not self.first_half_surrogate_pair_detected_16le:
|
| 177 |
+
if 0xD8 <= pair[1] <= 0xDB:
|
| 178 |
+
self.first_half_surrogate_pair_detected_16le = True
|
| 179 |
+
elif 0xDC <= pair[1] <= 0xDF:
|
| 180 |
+
self.invalid_utf16le = True
|
| 181 |
+
else:
|
| 182 |
+
if 0xDC <= pair[1] <= 0xDF:
|
| 183 |
+
self.first_half_surrogate_pair_detected_16le = False
|
| 184 |
+
else:
|
| 185 |
+
self.invalid_utf16le = True
|
| 186 |
+
|
| 187 |
+
def feed(self, byte_str: Union[bytes, bytearray]) -> ProbingState:
|
| 188 |
+
for c in byte_str:
|
| 189 |
+
mod4 = self.position % 4
|
| 190 |
+
self.quad[mod4] = c
|
| 191 |
+
if mod4 == 3:
|
| 192 |
+
self.validate_utf32_characters(self.quad)
|
| 193 |
+
self.validate_utf16_characters(self.quad[0:2])
|
| 194 |
+
self.validate_utf16_characters(self.quad[2:4])
|
| 195 |
+
if c == 0:
|
| 196 |
+
self.zeros_at_mod[mod4] += 1
|
| 197 |
+
else:
|
| 198 |
+
self.nonzeros_at_mod[mod4] += 1
|
| 199 |
+
self.position += 1
|
| 200 |
+
return self.state
|
| 201 |
+
|
| 202 |
+
@property
|
| 203 |
+
def state(self) -> ProbingState:
|
| 204 |
+
if self._state in {ProbingState.NOT_ME, ProbingState.FOUND_IT}:
|
| 205 |
+
# terminal, decided states
|
| 206 |
+
return self._state
|
| 207 |
+
if self.get_confidence() > 0.80:
|
| 208 |
+
self._state = ProbingState.FOUND_IT
|
| 209 |
+
elif self.position > 4 * 1024:
|
| 210 |
+
# if we get to 4kb into the file, and we can't conclude it's UTF,
|
| 211 |
+
# let's give up
|
| 212 |
+
self._state = ProbingState.NOT_ME
|
| 213 |
+
return self._state
|
| 214 |
+
|
| 215 |
+
def get_confidence(self) -> float:
|
| 216 |
+
return (
|
| 217 |
+
0.85
|
| 218 |
+
if (
|
| 219 |
+
self.is_likely_utf16le()
|
| 220 |
+
or self.is_likely_utf16be()
|
| 221 |
+
or self.is_likely_utf32le()
|
| 222 |
+
or self.is_likely_utf32be()
|
| 223 |
+
)
|
| 224 |
+
else 0.00
|
| 225 |
+
)
|