coinex-api 0.0.15__py3-none-any.whl → 0.0.17__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- coinex/__init__.py +7 -0
- coinex/ccxt/__init__.py +101 -0
- coinex/ccxt/abstract/coinex.py +237 -0
- coinex/ccxt/async_support/__init__.py +80 -0
- coinex/ccxt/async_support/base/__init__.py +1 -0
- coinex/ccxt/async_support/base/exchange.py +2100 -0
- coinex/ccxt/async_support/base/throttler.py +50 -0
- coinex/ccxt/async_support/base/ws/__init__.py +38 -0
- coinex/ccxt/async_support/base/ws/aiohttp_client.py +147 -0
- coinex/ccxt/async_support/base/ws/cache.py +213 -0
- coinex/ccxt/async_support/base/ws/client.py +214 -0
- coinex/ccxt/async_support/base/ws/fast_client.py +97 -0
- coinex/ccxt/async_support/base/ws/functions.py +59 -0
- coinex/ccxt/async_support/base/ws/future.py +69 -0
- coinex/ccxt/async_support/base/ws/order_book.py +78 -0
- coinex/ccxt/async_support/base/ws/order_book_side.py +174 -0
- coinex/ccxt/async_support/coinex.py +5833 -0
- coinex/ccxt/base/__init__.py +27 -0
- coinex/ccxt/base/decimal_to_precision.py +174 -0
- coinex/ccxt/base/errors.py +267 -0
- coinex/ccxt/base/exchange.py +6769 -0
- coinex/ccxt/base/precise.py +297 -0
- coinex/ccxt/base/types.py +577 -0
- coinex/ccxt/coinex.py +5832 -0
- coinex/ccxt/pro/__init__.py +21 -0
- coinex/ccxt/pro/coinex.py +1366 -0
- coinex/ccxt/static_dependencies/README.md +1 -0
- coinex/ccxt/static_dependencies/__init__.py +1 -0
- coinex/ccxt/static_dependencies/ecdsa/__init__.py +14 -0
- coinex/ccxt/static_dependencies/ecdsa/_version.py +520 -0
- coinex/ccxt/static_dependencies/ecdsa/curves.py +56 -0
- coinex/ccxt/static_dependencies/ecdsa/der.py +221 -0
- coinex/ccxt/static_dependencies/ecdsa/ecdsa.py +310 -0
- coinex/ccxt/static_dependencies/ecdsa/ellipticcurve.py +197 -0
- coinex/ccxt/static_dependencies/ecdsa/keys.py +332 -0
- coinex/ccxt/static_dependencies/ecdsa/numbertheory.py +531 -0
- coinex/ccxt/static_dependencies/ecdsa/rfc6979.py +100 -0
- coinex/ccxt/static_dependencies/ecdsa/util.py +266 -0
- coinex/ccxt/static_dependencies/ethereum/__init__.py +7 -0
- coinex/ccxt/static_dependencies/ethereum/abi/__init__.py +16 -0
- coinex/ccxt/static_dependencies/ethereum/abi/abi.py +19 -0
- coinex/ccxt/static_dependencies/ethereum/abi/base.py +152 -0
- coinex/ccxt/static_dependencies/ethereum/abi/codec.py +217 -0
- coinex/ccxt/static_dependencies/ethereum/abi/constants.py +3 -0
- coinex/ccxt/static_dependencies/ethereum/abi/decoding.py +565 -0
- coinex/ccxt/static_dependencies/ethereum/abi/encoding.py +720 -0
- coinex/ccxt/static_dependencies/ethereum/abi/exceptions.py +139 -0
- coinex/ccxt/static_dependencies/ethereum/abi/grammar.py +443 -0
- coinex/ccxt/static_dependencies/ethereum/abi/packed.py +13 -0
- coinex/ccxt/static_dependencies/ethereum/abi/py.typed +0 -0
- coinex/ccxt/static_dependencies/ethereum/abi/registry.py +643 -0
- coinex/ccxt/static_dependencies/ethereum/abi/tools/__init__.py +3 -0
- coinex/ccxt/static_dependencies/ethereum/abi/tools/_strategies.py +230 -0
- coinex/ccxt/static_dependencies/ethereum/abi/utils/__init__.py +0 -0
- coinex/ccxt/static_dependencies/ethereum/abi/utils/numeric.py +83 -0
- coinex/ccxt/static_dependencies/ethereum/abi/utils/padding.py +27 -0
- coinex/ccxt/static_dependencies/ethereum/abi/utils/string.py +19 -0
- coinex/ccxt/static_dependencies/ethereum/account/__init__.py +3 -0
- coinex/ccxt/static_dependencies/ethereum/account/encode_typed_data/__init__.py +4 -0
- coinex/ccxt/static_dependencies/ethereum/account/encode_typed_data/encoding_and_hashing.py +239 -0
- coinex/ccxt/static_dependencies/ethereum/account/encode_typed_data/helpers.py +40 -0
- coinex/ccxt/static_dependencies/ethereum/account/messages.py +263 -0
- coinex/ccxt/static_dependencies/ethereum/account/py.typed +0 -0
- coinex/ccxt/static_dependencies/ethereum/hexbytes/__init__.py +5 -0
- coinex/ccxt/static_dependencies/ethereum/hexbytes/_utils.py +54 -0
- coinex/ccxt/static_dependencies/ethereum/hexbytes/main.py +65 -0
- coinex/ccxt/static_dependencies/ethereum/hexbytes/py.typed +0 -0
- coinex/ccxt/static_dependencies/ethereum/typing/__init__.py +63 -0
- coinex/ccxt/static_dependencies/ethereum/typing/abi.py +6 -0
- coinex/ccxt/static_dependencies/ethereum/typing/bls.py +7 -0
- coinex/ccxt/static_dependencies/ethereum/typing/discovery.py +5 -0
- coinex/ccxt/static_dependencies/ethereum/typing/encoding.py +7 -0
- coinex/ccxt/static_dependencies/ethereum/typing/enums.py +17 -0
- coinex/ccxt/static_dependencies/ethereum/typing/ethpm.py +9 -0
- coinex/ccxt/static_dependencies/ethereum/typing/evm.py +20 -0
- coinex/ccxt/static_dependencies/ethereum/typing/networks.py +1122 -0
- coinex/ccxt/static_dependencies/ethereum/typing/py.typed +0 -0
- coinex/ccxt/static_dependencies/ethereum/utils/__init__.py +115 -0
- coinex/ccxt/static_dependencies/ethereum/utils/abi.py +72 -0
- coinex/ccxt/static_dependencies/ethereum/utils/address.py +171 -0
- coinex/ccxt/static_dependencies/ethereum/utils/applicators.py +151 -0
- coinex/ccxt/static_dependencies/ethereum/utils/conversions.py +190 -0
- coinex/ccxt/static_dependencies/ethereum/utils/currency.py +107 -0
- coinex/ccxt/static_dependencies/ethereum/utils/curried/__init__.py +269 -0
- coinex/ccxt/static_dependencies/ethereum/utils/debug.py +20 -0
- coinex/ccxt/static_dependencies/ethereum/utils/decorators.py +132 -0
- coinex/ccxt/static_dependencies/ethereum/utils/encoding.py +6 -0
- coinex/ccxt/static_dependencies/ethereum/utils/exceptions.py +4 -0
- coinex/ccxt/static_dependencies/ethereum/utils/functional.py +75 -0
- coinex/ccxt/static_dependencies/ethereum/utils/hexadecimal.py +74 -0
- coinex/ccxt/static_dependencies/ethereum/utils/humanize.py +188 -0
- coinex/ccxt/static_dependencies/ethereum/utils/logging.py +159 -0
- coinex/ccxt/static_dependencies/ethereum/utils/module_loading.py +31 -0
- coinex/ccxt/static_dependencies/ethereum/utils/numeric.py +43 -0
- coinex/ccxt/static_dependencies/ethereum/utils/py.typed +0 -0
- coinex/ccxt/static_dependencies/ethereum/utils/toolz.py +76 -0
- coinex/ccxt/static_dependencies/ethereum/utils/types.py +54 -0
- coinex/ccxt/static_dependencies/ethereum/utils/typing/__init__.py +18 -0
- coinex/ccxt/static_dependencies/ethereum/utils/typing/misc.py +14 -0
- coinex/ccxt/static_dependencies/ethereum/utils/units.py +31 -0
- coinex/ccxt/static_dependencies/keccak/__init__.py +3 -0
- coinex/ccxt/static_dependencies/keccak/keccak.py +197 -0
- coinex/ccxt/static_dependencies/lark/__init__.py +38 -0
- coinex/ccxt/static_dependencies/lark/__pyinstaller/__init__.py +6 -0
- coinex/ccxt/static_dependencies/lark/__pyinstaller/hook-lark.py +14 -0
- coinex/ccxt/static_dependencies/lark/ast_utils.py +59 -0
- coinex/ccxt/static_dependencies/lark/common.py +86 -0
- coinex/ccxt/static_dependencies/lark/exceptions.py +292 -0
- coinex/ccxt/static_dependencies/lark/grammar.py +130 -0
- coinex/ccxt/static_dependencies/lark/grammars/__init__.py +0 -0
- coinex/ccxt/static_dependencies/lark/grammars/common.lark +59 -0
- coinex/ccxt/static_dependencies/lark/grammars/lark.lark +62 -0
- coinex/ccxt/static_dependencies/lark/grammars/python.lark +302 -0
- coinex/ccxt/static_dependencies/lark/grammars/unicode.lark +7 -0
- coinex/ccxt/static_dependencies/lark/indenter.py +143 -0
- coinex/ccxt/static_dependencies/lark/lark.py +658 -0
- coinex/ccxt/static_dependencies/lark/lexer.py +678 -0
- coinex/ccxt/static_dependencies/lark/load_grammar.py +1428 -0
- coinex/ccxt/static_dependencies/lark/parse_tree_builder.py +391 -0
- coinex/ccxt/static_dependencies/lark/parser_frontends.py +257 -0
- coinex/ccxt/static_dependencies/lark/parsers/__init__.py +0 -0
- coinex/ccxt/static_dependencies/lark/parsers/cyk.py +340 -0
- coinex/ccxt/static_dependencies/lark/parsers/earley.py +314 -0
- coinex/ccxt/static_dependencies/lark/parsers/earley_common.py +42 -0
- coinex/ccxt/static_dependencies/lark/parsers/earley_forest.py +801 -0
- coinex/ccxt/static_dependencies/lark/parsers/grammar_analysis.py +203 -0
- coinex/ccxt/static_dependencies/lark/parsers/lalr_analysis.py +332 -0
- coinex/ccxt/static_dependencies/lark/parsers/lalr_interactive_parser.py +158 -0
- coinex/ccxt/static_dependencies/lark/parsers/lalr_parser.py +122 -0
- coinex/ccxt/static_dependencies/lark/parsers/lalr_parser_state.py +110 -0
- coinex/ccxt/static_dependencies/lark/parsers/xearley.py +165 -0
- coinex/ccxt/static_dependencies/lark/py.typed +0 -0
- coinex/ccxt/static_dependencies/lark/reconstruct.py +107 -0
- coinex/ccxt/static_dependencies/lark/tools/__init__.py +70 -0
- coinex/ccxt/static_dependencies/lark/tools/nearley.py +202 -0
- coinex/ccxt/static_dependencies/lark/tools/serialize.py +32 -0
- coinex/ccxt/static_dependencies/lark/tools/standalone.py +196 -0
- coinex/ccxt/static_dependencies/lark/tree.py +267 -0
- coinex/ccxt/static_dependencies/lark/tree_matcher.py +186 -0
- coinex/ccxt/static_dependencies/lark/tree_templates.py +180 -0
- coinex/ccxt/static_dependencies/lark/utils.py +343 -0
- coinex/ccxt/static_dependencies/lark/visitors.py +596 -0
- coinex/ccxt/static_dependencies/marshmallow/__init__.py +81 -0
- coinex/ccxt/static_dependencies/marshmallow/base.py +65 -0
- coinex/ccxt/static_dependencies/marshmallow/class_registry.py +94 -0
- coinex/ccxt/static_dependencies/marshmallow/decorators.py +231 -0
- coinex/ccxt/static_dependencies/marshmallow/error_store.py +60 -0
- coinex/ccxt/static_dependencies/marshmallow/exceptions.py +71 -0
- coinex/ccxt/static_dependencies/marshmallow/fields.py +2114 -0
- coinex/ccxt/static_dependencies/marshmallow/orderedset.py +89 -0
- coinex/ccxt/static_dependencies/marshmallow/py.typed +0 -0
- coinex/ccxt/static_dependencies/marshmallow/schema.py +1228 -0
- coinex/ccxt/static_dependencies/marshmallow/types.py +12 -0
- coinex/ccxt/static_dependencies/marshmallow/utils.py +378 -0
- coinex/ccxt/static_dependencies/marshmallow/validate.py +678 -0
- coinex/ccxt/static_dependencies/marshmallow/warnings.py +2 -0
- coinex/ccxt/static_dependencies/marshmallow_dataclass/__init__.py +1047 -0
- coinex/ccxt/static_dependencies/marshmallow_dataclass/collection_field.py +51 -0
- coinex/ccxt/static_dependencies/marshmallow_dataclass/lazy_class_attribute.py +45 -0
- coinex/ccxt/static_dependencies/marshmallow_dataclass/mypy.py +71 -0
- coinex/ccxt/static_dependencies/marshmallow_dataclass/py.typed +0 -0
- coinex/ccxt/static_dependencies/marshmallow_dataclass/typing.py +14 -0
- coinex/ccxt/static_dependencies/marshmallow_dataclass/union_field.py +82 -0
- coinex/ccxt/static_dependencies/marshmallow_oneofschema/__init__.py +1 -0
- coinex/ccxt/static_dependencies/marshmallow_oneofschema/one_of_schema.py +193 -0
- coinex/ccxt/static_dependencies/marshmallow_oneofschema/py.typed +0 -0
- coinex/ccxt/static_dependencies/msgpack/__init__.py +55 -0
- coinex/ccxt/static_dependencies/msgpack/_cmsgpack.pyx +11 -0
- coinex/ccxt/static_dependencies/msgpack/_packer.pyx +374 -0
- coinex/ccxt/static_dependencies/msgpack/_unpacker.pyx +547 -0
- coinex/ccxt/static_dependencies/msgpack/buff_converter.h +8 -0
- coinex/ccxt/static_dependencies/msgpack/exceptions.py +48 -0
- coinex/ccxt/static_dependencies/msgpack/ext.py +168 -0
- coinex/ccxt/static_dependencies/msgpack/fallback.py +951 -0
- coinex/ccxt/static_dependencies/msgpack/pack.h +89 -0
- coinex/ccxt/static_dependencies/msgpack/pack_template.h +820 -0
- coinex/ccxt/static_dependencies/msgpack/sysdep.h +194 -0
- coinex/ccxt/static_dependencies/msgpack/unpack.h +391 -0
- coinex/ccxt/static_dependencies/msgpack/unpack_define.h +95 -0
- coinex/ccxt/static_dependencies/msgpack/unpack_template.h +464 -0
- coinex/ccxt/static_dependencies/parsimonious/__init__.py +10 -0
- coinex/ccxt/static_dependencies/parsimonious/exceptions.py +105 -0
- coinex/ccxt/static_dependencies/parsimonious/expressions.py +479 -0
- coinex/ccxt/static_dependencies/parsimonious/grammar.py +487 -0
- coinex/ccxt/static_dependencies/parsimonious/nodes.py +325 -0
- coinex/ccxt/static_dependencies/parsimonious/utils.py +40 -0
- coinex/ccxt/static_dependencies/starknet/__init__.py +0 -0
- coinex/ccxt/static_dependencies/starknet/abi/v0/__init__.py +2 -0
- coinex/ccxt/static_dependencies/starknet/abi/v0/model.py +44 -0
- coinex/ccxt/static_dependencies/starknet/abi/v0/parser.py +216 -0
- coinex/ccxt/static_dependencies/starknet/abi/v0/schemas.py +72 -0
- coinex/ccxt/static_dependencies/starknet/abi/v0/shape.py +63 -0
- coinex/ccxt/static_dependencies/starknet/abi/v1/__init__.py +2 -0
- coinex/ccxt/static_dependencies/starknet/abi/v1/core_structures.json +14 -0
- coinex/ccxt/static_dependencies/starknet/abi/v1/model.py +39 -0
- coinex/ccxt/static_dependencies/starknet/abi/v1/parser.py +220 -0
- coinex/ccxt/static_dependencies/starknet/abi/v1/parser_transformer.py +179 -0
- coinex/ccxt/static_dependencies/starknet/abi/v1/schemas.py +66 -0
- coinex/ccxt/static_dependencies/starknet/abi/v1/shape.py +47 -0
- coinex/ccxt/static_dependencies/starknet/abi/v2/__init__.py +2 -0
- coinex/ccxt/static_dependencies/starknet/abi/v2/model.py +89 -0
- coinex/ccxt/static_dependencies/starknet/abi/v2/parser.py +293 -0
- coinex/ccxt/static_dependencies/starknet/abi/v2/parser_transformer.py +192 -0
- coinex/ccxt/static_dependencies/starknet/abi/v2/schemas.py +132 -0
- coinex/ccxt/static_dependencies/starknet/abi/v2/shape.py +107 -0
- coinex/ccxt/static_dependencies/starknet/cairo/__init__.py +0 -0
- coinex/ccxt/static_dependencies/starknet/cairo/data_types.py +123 -0
- coinex/ccxt/static_dependencies/starknet/cairo/deprecated_parse/__init__.py +0 -0
- coinex/ccxt/static_dependencies/starknet/cairo/deprecated_parse/cairo_types.py +77 -0
- coinex/ccxt/static_dependencies/starknet/cairo/deprecated_parse/parser.py +46 -0
- coinex/ccxt/static_dependencies/starknet/cairo/deprecated_parse/parser_transformer.py +138 -0
- coinex/ccxt/static_dependencies/starknet/cairo/felt.py +64 -0
- coinex/ccxt/static_dependencies/starknet/cairo/type_parser.py +121 -0
- coinex/ccxt/static_dependencies/starknet/cairo/v1/__init__.py +0 -0
- coinex/ccxt/static_dependencies/starknet/cairo/v1/type_parser.py +59 -0
- coinex/ccxt/static_dependencies/starknet/cairo/v2/__init__.py +0 -0
- coinex/ccxt/static_dependencies/starknet/cairo/v2/type_parser.py +77 -0
- coinex/ccxt/static_dependencies/starknet/ccxt_utils.py +7 -0
- coinex/ccxt/static_dependencies/starknet/common.py +15 -0
- coinex/ccxt/static_dependencies/starknet/constants.py +39 -0
- coinex/ccxt/static_dependencies/starknet/hash/__init__.py +0 -0
- coinex/ccxt/static_dependencies/starknet/hash/address.py +79 -0
- coinex/ccxt/static_dependencies/starknet/hash/compiled_class_hash_objects.py +111 -0
- coinex/ccxt/static_dependencies/starknet/hash/selector.py +16 -0
- coinex/ccxt/static_dependencies/starknet/hash/storage.py +12 -0
- coinex/ccxt/static_dependencies/starknet/hash/utils.py +78 -0
- coinex/ccxt/static_dependencies/starknet/models/__init__.py +0 -0
- coinex/ccxt/static_dependencies/starknet/models/typed_data.py +45 -0
- coinex/ccxt/static_dependencies/starknet/serialization/__init__.py +24 -0
- coinex/ccxt/static_dependencies/starknet/serialization/_calldata_reader.py +40 -0
- coinex/ccxt/static_dependencies/starknet/serialization/_context.py +142 -0
- coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/__init__.py +10 -0
- coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/_common.py +82 -0
- coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/array_serializer.py +43 -0
- coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/bool_serializer.py +37 -0
- coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/byte_array_serializer.py +66 -0
- coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/cairo_data_serializer.py +71 -0
- coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/enum_serializer.py +71 -0
- coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/felt_serializer.py +50 -0
- coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/named_tuple_serializer.py +58 -0
- coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/option_serializer.py +43 -0
- coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/output_serializer.py +40 -0
- coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/payload_serializer.py +72 -0
- coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/struct_serializer.py +36 -0
- coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/tuple_serializer.py +36 -0
- coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/uint256_serializer.py +76 -0
- coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/uint_serializer.py +100 -0
- coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/unit_serializer.py +32 -0
- coinex/ccxt/static_dependencies/starknet/serialization/errors.py +10 -0
- coinex/ccxt/static_dependencies/starknet/serialization/factory.py +229 -0
- coinex/ccxt/static_dependencies/starknet/serialization/function_serialization_adapter.py +110 -0
- coinex/ccxt/static_dependencies/starknet/serialization/tuple_dataclass.py +59 -0
- coinex/ccxt/static_dependencies/starknet/utils/__init__.py +0 -0
- coinex/ccxt/static_dependencies/starknet/utils/constructor_args_translator.py +86 -0
- coinex/ccxt/static_dependencies/starknet/utils/iterable.py +13 -0
- coinex/ccxt/static_dependencies/starknet/utils/schema.py +13 -0
- coinex/ccxt/static_dependencies/starknet/utils/typed_data.py +182 -0
- coinex/ccxt/static_dependencies/starkware/__init__.py +0 -0
- coinex/ccxt/static_dependencies/starkware/crypto/__init__.py +0 -0
- coinex/ccxt/static_dependencies/starkware/crypto/fast_pedersen_hash.py +50 -0
- coinex/ccxt/static_dependencies/starkware/crypto/math_utils.py +78 -0
- coinex/ccxt/static_dependencies/starkware/crypto/signature.py +2344 -0
- coinex/ccxt/static_dependencies/starkware/crypto/utils.py +63 -0
- coinex/ccxt/static_dependencies/sympy/__init__.py +0 -0
- coinex/ccxt/static_dependencies/sympy/core/__init__.py +0 -0
- coinex/ccxt/static_dependencies/sympy/core/intfunc.py +35 -0
- coinex/ccxt/static_dependencies/sympy/external/__init__.py +0 -0
- coinex/ccxt/static_dependencies/sympy/external/gmpy.py +345 -0
- coinex/ccxt/static_dependencies/sympy/external/importtools.py +187 -0
- coinex/ccxt/static_dependencies/sympy/external/ntheory.py +637 -0
- coinex/ccxt/static_dependencies/sympy/external/pythonmpq.py +341 -0
- coinex/ccxt/static_dependencies/toolz/__init__.py +26 -0
- coinex/ccxt/static_dependencies/toolz/_signatures.py +784 -0
- coinex/ccxt/static_dependencies/toolz/_version.py +520 -0
- coinex/ccxt/static_dependencies/toolz/compatibility.py +30 -0
- coinex/ccxt/static_dependencies/toolz/curried/__init__.py +101 -0
- coinex/ccxt/static_dependencies/toolz/curried/exceptions.py +22 -0
- coinex/ccxt/static_dependencies/toolz/curried/operator.py +22 -0
- coinex/ccxt/static_dependencies/toolz/dicttoolz.py +339 -0
- coinex/ccxt/static_dependencies/toolz/functoolz.py +1049 -0
- coinex/ccxt/static_dependencies/toolz/itertoolz.py +1057 -0
- coinex/ccxt/static_dependencies/toolz/recipes.py +46 -0
- coinex/ccxt/static_dependencies/toolz/utils.py +9 -0
- coinex/ccxt/static_dependencies/typing_inspect/__init__.py +0 -0
- coinex/ccxt/static_dependencies/typing_inspect/typing_inspect.py +851 -0
- coinex_api-0.0.17.dist-info/METADATA +425 -0
- coinex_api-0.0.17.dist-info/RECORD +288 -0
- coinex_api-0.0.15.dist-info/METADATA +0 -79
- coinex_api-0.0.15.dist-info/RECORD +0 -3
- {coinex_api-0.0.15.dist-info → coinex_api-0.0.17.dist-info}/WHEEL +0 -0
@@ -0,0 +1,197 @@
|
|
1
|
+
# code modified from https://github.com/zambonin/alice-and-bob
|
2
|
+
# thank you @zambonin for your contributions to the open source code that is used by ccxt!
|
3
|
+
|
4
|
+
"""keccakf1600.py
|
5
|
+
|
6
|
+
Keccak is a family of hash functions based on the sponge construction. It was
|
7
|
+
chosen by NIST to become the SHA-3 standard. This code implements the
|
8
|
+
Keccak-f[1600] permutation. Detailed information about this function can be
|
9
|
+
found on the official site [1]. Original implementation [2] by the Keccak Team.
|
10
|
+
|
11
|
+
Some caveats about the implementation:
|
12
|
+
* width `b` of permutation is fixed as 1600 (5 * 5 * 64), which means
|
13
|
+
the number of rounds is 24 (12 + 2ℓ, ℓ = log_2(b / 25))
|
14
|
+
* ρ step could have its offsets pre-computed as the array `r`.
|
15
|
+
* ι step could have its round constants pre-computed as the array `RC`.
|
16
|
+
|
17
|
+
[1] http://keccak.noekeon.org/
|
18
|
+
[2] https://git.io/vKfkb
|
19
|
+
"""
|
20
|
+
|
21
|
+
|
22
|
+
def keccak_f_1600(state):
|
23
|
+
"""The inner permutation for the Keccak sponge function.
|
24
|
+
|
25
|
+
The Keccak-f permutation is an iterated construction consisting of a
|
26
|
+
sequence of almost identical rounds. It operates on a state array with
|
27
|
+
each of the twenty-four rounds performing five steps, described below
|
28
|
+
with detail.
|
29
|
+
|
30
|
+
The loops above and below the core of the permutation are used to save and
|
31
|
+
restore the state array to a stream of bytes, used outside the permutation.
|
32
|
+
The original state array has three dimensions, whereas this characteristic
|
33
|
+
can be cleverly optimized to a 5x5 matrix with 64-bit words. As such, this
|
34
|
+
implementation makes use of this trick and stores an entire lane (a z-axis
|
35
|
+
set of bits within the state) as a single word.
|
36
|
+
|
37
|
+
The θ step diffuses the bits alongside the state array by calculating the
|
38
|
+
parity of nearby columns relative to a lane.
|
39
|
+
|
40
|
+
The ρ and π steps are merged; together, they move more bits around
|
41
|
+
according to two alike recurrence relations.
|
42
|
+
|
43
|
+
The χ step is similar to an S-box permutation; it makes the whole round
|
44
|
+
non-linear with a few logic operations on bits inside a line.
|
45
|
+
|
46
|
+
The ι step is a simple LFSR that breaks the symmetry of the rounds. It
|
47
|
+
generates constants by doing computations according to the round number
|
48
|
+
and its previous output, modulo polynomials over GF(2)[x].
|
49
|
+
|
50
|
+
Args:
|
51
|
+
state: square matrix of order 5 that holds the input bytes.
|
52
|
+
|
53
|
+
Returns:
|
54
|
+
state: bytes permuted by Keccak-f[1600].
|
55
|
+
"""
|
56
|
+
|
57
|
+
def load64(b):
|
58
|
+
"""
|
59
|
+
Saves each byte on its respective position within a 64-bit word.
|
60
|
+
|
61
|
+
Args:
|
62
|
+
b: partial list of bytes from input.
|
63
|
+
|
64
|
+
Returns:
|
65
|
+
Sum of list with numbers shifted.
|
66
|
+
"""
|
67
|
+
return sum((b[i] << (8 * i)) for i in range(8))
|
68
|
+
|
69
|
+
def store64(a):
|
70
|
+
"""
|
71
|
+
Transforms a 64-bit word into a list of bytes.
|
72
|
+
|
73
|
+
Args:
|
74
|
+
a: 64-bit word.
|
75
|
+
|
76
|
+
Returns:
|
77
|
+
List of bytes separated by position on the word.
|
78
|
+
"""
|
79
|
+
return list((a >> (8 * i)) % 256 for i in range(8))
|
80
|
+
|
81
|
+
def rotate(a, n):
|
82
|
+
"""
|
83
|
+
Denotes the bitwise cyclic shift operation, moving bit at position
|
84
|
+
`i` into position `i + n` (modulo the lane size).
|
85
|
+
|
86
|
+
Args:
|
87
|
+
a: lane with a 64-bit word, or elements from the state array.
|
88
|
+
n: offset for rotation.
|
89
|
+
|
90
|
+
Returns:
|
91
|
+
The rotated lane.
|
92
|
+
"""
|
93
|
+
return ((a >> (64 - (n % 64))) + (a << (n % 64))) % (1 << 64)
|
94
|
+
|
95
|
+
A = [[0 for _ in range(5)] for _ in range(5)]
|
96
|
+
for x in range(5):
|
97
|
+
for y in range(5):
|
98
|
+
i = 8 * (x + 5 * y)
|
99
|
+
A[x][y] = load64(state[i : i + 8])
|
100
|
+
|
101
|
+
R = 1
|
102
|
+
for _ in range(24):
|
103
|
+
C = [A[x][0] ^ A[x][1] ^ A[x][2] ^ A[x][3] ^ A[x][4] for x in range(5)]
|
104
|
+
D = [C[(x - 1) % 5] ^ rotate(C[(x + 1) % 5], 1) for x in range(5)]
|
105
|
+
A = [[A[x][y] ^ D[x] for y in range(5)] for x in range(5)]
|
106
|
+
|
107
|
+
x, y, current = 1, 0, A[1][0]
|
108
|
+
for t in range(24):
|
109
|
+
x, y = y, (2 * x + 3 * y) % 5
|
110
|
+
offset = ((t + 1) * (t + 2)) // 2
|
111
|
+
current, A[x][y] = A[x][y], rotate(current, offset)
|
112
|
+
|
113
|
+
for y in range(5):
|
114
|
+
T = [A[x][y] for x in range(5)]
|
115
|
+
for x in range(5):
|
116
|
+
A[x][y] = T[x] ^ ((~T[(x + 1) % 5]) & T[(x + 2) % 5])
|
117
|
+
|
118
|
+
for j in range(7):
|
119
|
+
R = ((R << 1) ^ ((R >> 7) * 0x71)) % 256
|
120
|
+
if R & 2:
|
121
|
+
A[0][0] ^= 1 << ((1 << j) - 1)
|
122
|
+
|
123
|
+
for x in range(5):
|
124
|
+
for y in range(5):
|
125
|
+
i = 8 * (x + 5 * y)
|
126
|
+
state[i : i + 8] = store64(A[x][y])
|
127
|
+
|
128
|
+
return state
|
129
|
+
|
130
|
+
|
131
|
+
def Keccak(r, c, _input, suffix, output_len):
|
132
|
+
"""
|
133
|
+
The general sponge function, consisting of the inner permutation and a
|
134
|
+
padding rule (`pad10*1`). It consists of three main parts.
|
135
|
+
* absorbing, where the input will be permuted repeatedly every time
|
136
|
+
it is divided into a block of size `r + c`.
|
137
|
+
* padding, where an oddly sized last block will be filled with bits
|
138
|
+
until it can be fed into the permutation.
|
139
|
+
* squeezing, where the output's blocks will be permuted more times
|
140
|
+
until they are concatenated to the desired size.
|
141
|
+
|
142
|
+
Args:
|
143
|
+
r: rate, or the number of input bits processed or output bits
|
144
|
+
generated per invocation of the underlying function
|
145
|
+
c: capacity, or the width of the underlying function minus
|
146
|
+
the rate
|
147
|
+
_input: list of bytes containing the desired object to be hashed
|
148
|
+
suffix: distinguishes the inputs arising from SHA-3/SHAKE functions
|
149
|
+
output_len: length of hash output.
|
150
|
+
|
151
|
+
Returns:
|
152
|
+
Hash of the input bytes.
|
153
|
+
"""
|
154
|
+
state = bytearray((r + c) // 8)
|
155
|
+
rate_bytes, block, offset = r // 8, 0, 0
|
156
|
+
|
157
|
+
while offset < len(_input):
|
158
|
+
block = min(len(_input) - offset, rate_bytes)
|
159
|
+
for i in range(block):
|
160
|
+
state[i] ^= _input[i + offset]
|
161
|
+
offset += block
|
162
|
+
if block == rate_bytes:
|
163
|
+
state = keccak_f_1600(state)
|
164
|
+
block = 0
|
165
|
+
|
166
|
+
state[block] ^= suffix
|
167
|
+
if (suffix & 0x80) and (block == (rate_bytes - 1)):
|
168
|
+
state = keccak_f_1600(state)
|
169
|
+
state[rate_bytes - 1] ^= 0x80
|
170
|
+
state = keccak_f_1600(state)
|
171
|
+
|
172
|
+
output = bytearray()
|
173
|
+
while output_len:
|
174
|
+
block = min(output_len, rate_bytes)
|
175
|
+
output += state[:block]
|
176
|
+
output_len -= block
|
177
|
+
if output_len:
|
178
|
+
state = keccak_f_1600(state)
|
179
|
+
|
180
|
+
return output
|
181
|
+
|
182
|
+
|
183
|
+
def SHA3(_input):
|
184
|
+
"""
|
185
|
+
FIPS 202 generalized instance of the SHA-3 hash function.
|
186
|
+
|
187
|
+
Args:
|
188
|
+
size: instance of desired SHA3 algorithm.
|
189
|
+
_input: list of bytes to compute a hash from.
|
190
|
+
|
191
|
+
Returns:
|
192
|
+
Instance of the Keccak permutation that calculates the hash.
|
193
|
+
"""
|
194
|
+
size = 256
|
195
|
+
# https://www.cybertest.com/blog/keccak-vs-sha3
|
196
|
+
padding = 0x01 # change this to 0x06 for NIST sha3
|
197
|
+
return Keccak(1600 - size * 2, size * 2, _input, padding, size // 8)
|
@@ -0,0 +1,38 @@
|
|
1
|
+
from .exceptions import (
|
2
|
+
GrammarError,
|
3
|
+
LarkError,
|
4
|
+
LexError,
|
5
|
+
ParseError,
|
6
|
+
UnexpectedCharacters,
|
7
|
+
UnexpectedEOF,
|
8
|
+
UnexpectedInput,
|
9
|
+
UnexpectedToken,
|
10
|
+
)
|
11
|
+
from .lark import Lark
|
12
|
+
from .lexer import Token
|
13
|
+
from .tree import ParseTree, Tree
|
14
|
+
from .utils import logger
|
15
|
+
from .visitors import Discard, Transformer, Transformer_NonRecursive, Visitor, v_args
|
16
|
+
|
17
|
+
__version__: str = "1.2.0"
|
18
|
+
|
19
|
+
__all__ = (
|
20
|
+
"GrammarError",
|
21
|
+
"LarkError",
|
22
|
+
"LexError",
|
23
|
+
"ParseError",
|
24
|
+
"UnexpectedCharacters",
|
25
|
+
"UnexpectedEOF",
|
26
|
+
"UnexpectedInput",
|
27
|
+
"UnexpectedToken",
|
28
|
+
"Lark",
|
29
|
+
"Token",
|
30
|
+
"ParseTree",
|
31
|
+
"Tree",
|
32
|
+
"logger",
|
33
|
+
"Discard",
|
34
|
+
"Transformer",
|
35
|
+
"Transformer_NonRecursive",
|
36
|
+
"Visitor",
|
37
|
+
"v_args",
|
38
|
+
)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#-----------------------------------------------------------------------------
|
2
|
+
# Copyright (c) 2017-2020, PyInstaller Development Team.
|
3
|
+
#
|
4
|
+
# Distributed under the terms of the GNU General Public License (version 2
|
5
|
+
# or later) with exception for distributing the bootloader.
|
6
|
+
#
|
7
|
+
# The full license is in the file COPYING.txt, distributed with this software.
|
8
|
+
#
|
9
|
+
# SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)
|
10
|
+
#-----------------------------------------------------------------------------
|
11
|
+
|
12
|
+
from PyInstaller.utils.hooks import collect_data_files
|
13
|
+
|
14
|
+
datas = collect_data_files('lark')
|
@@ -0,0 +1,59 @@
|
|
1
|
+
"""
|
2
|
+
Module of utilities for transforming a lark.Tree into a custom Abstract Syntax Tree (AST defined in classes)
|
3
|
+
"""
|
4
|
+
|
5
|
+
import inspect, re
|
6
|
+
import types
|
7
|
+
from typing import Optional, Callable
|
8
|
+
|
9
|
+
from lark import Transformer, v_args
|
10
|
+
|
11
|
+
class Ast:
|
12
|
+
"""Abstract class
|
13
|
+
|
14
|
+
Subclasses will be collected by `create_transformer()`
|
15
|
+
"""
|
16
|
+
pass
|
17
|
+
|
18
|
+
class AsList:
|
19
|
+
"""Abstract class
|
20
|
+
|
21
|
+
Subclasses will be instantiated with the parse results as a single list, instead of as arguments.
|
22
|
+
"""
|
23
|
+
|
24
|
+
class WithMeta:
|
25
|
+
"""Abstract class
|
26
|
+
|
27
|
+
Subclasses will be instantiated with the Meta instance of the tree. (see ``v_args`` for more detail)
|
28
|
+
"""
|
29
|
+
pass
|
30
|
+
|
31
|
+
def camel_to_snake(name):
|
32
|
+
return re.sub(r'(?<!^)(?=[A-Z])', '_', name).lower()
|
33
|
+
|
34
|
+
def create_transformer(ast_module: types.ModuleType,
|
35
|
+
transformer: Optional[Transformer]=None,
|
36
|
+
decorator_factory: Callable=v_args) -> Transformer:
|
37
|
+
"""Collects `Ast` subclasses from the given module, and creates a Lark transformer that builds the AST.
|
38
|
+
|
39
|
+
For each class, we create a corresponding rule in the transformer, with a matching name.
|
40
|
+
CamelCase names will be converted into snake_case. Example: "CodeBlock" -> "code_block".
|
41
|
+
|
42
|
+
Classes starting with an underscore (`_`) will be skipped.
|
43
|
+
|
44
|
+
Parameters:
|
45
|
+
ast_module: A Python module containing all the subclasses of ``ast_utils.Ast``
|
46
|
+
transformer (Optional[Transformer]): An initial transformer. Its attributes may be overwritten.
|
47
|
+
decorator_factory (Callable): An optional callable accepting two booleans, inline, and meta,
|
48
|
+
and returning a decorator for the methods of ``transformer``. (default: ``v_args``).
|
49
|
+
"""
|
50
|
+
t = transformer or Transformer()
|
51
|
+
|
52
|
+
for name, obj in inspect.getmembers(ast_module):
|
53
|
+
if not name.startswith('_') and inspect.isclass(obj):
|
54
|
+
if issubclass(obj, Ast):
|
55
|
+
wrapper = decorator_factory(inline=not issubclass(obj, AsList), meta=issubclass(obj, WithMeta))
|
56
|
+
obj = wrapper(obj).__get__(t)
|
57
|
+
setattr(t, camel_to_snake(name), obj)
|
58
|
+
|
59
|
+
return t
|
@@ -0,0 +1,86 @@
|
|
1
|
+
from copy import deepcopy
|
2
|
+
import sys
|
3
|
+
from types import ModuleType
|
4
|
+
from typing import Callable, Collection, Dict, Optional, TYPE_CHECKING, List
|
5
|
+
|
6
|
+
if TYPE_CHECKING:
|
7
|
+
from .lark import PostLex
|
8
|
+
from .lexer import Lexer
|
9
|
+
from .grammar import Rule
|
10
|
+
from typing import Union, Type
|
11
|
+
from typing import Literal
|
12
|
+
if sys.version_info >= (3, 10):
|
13
|
+
from typing import TypeAlias
|
14
|
+
else:
|
15
|
+
from typing_extensions import TypeAlias
|
16
|
+
|
17
|
+
from .utils import Serialize
|
18
|
+
from .lexer import TerminalDef, Token
|
19
|
+
|
20
|
+
###{standalone
|
21
|
+
|
22
|
+
_ParserArgType: 'TypeAlias' = 'Literal["earley", "lalr", "cyk", "auto"]'
|
23
|
+
_LexerArgType: 'TypeAlias' = 'Union[Literal["auto", "basic", "contextual", "dynamic", "dynamic_complete"], Type[Lexer]]'
|
24
|
+
_LexerCallback = Callable[[Token], Token]
|
25
|
+
ParserCallbacks = Dict[str, Callable]
|
26
|
+
|
27
|
+
class LexerConf(Serialize):
|
28
|
+
__serialize_fields__ = 'terminals', 'ignore', 'g_regex_flags', 'use_bytes', 'lexer_type'
|
29
|
+
__serialize_namespace__ = TerminalDef,
|
30
|
+
|
31
|
+
terminals: Collection[TerminalDef]
|
32
|
+
re_module: ModuleType
|
33
|
+
ignore: Collection[str]
|
34
|
+
postlex: 'Optional[PostLex]'
|
35
|
+
callbacks: Dict[str, _LexerCallback]
|
36
|
+
g_regex_flags: int
|
37
|
+
skip_validation: bool
|
38
|
+
use_bytes: bool
|
39
|
+
lexer_type: Optional[_LexerArgType]
|
40
|
+
strict: bool
|
41
|
+
|
42
|
+
def __init__(self, terminals: Collection[TerminalDef], re_module: ModuleType, ignore: Collection[str]=(), postlex: 'Optional[PostLex]'=None,
|
43
|
+
callbacks: Optional[Dict[str, _LexerCallback]]=None, g_regex_flags: int=0, skip_validation: bool=False, use_bytes: bool=False, strict: bool=False):
|
44
|
+
self.terminals = terminals
|
45
|
+
self.terminals_by_name = {t.name: t for t in self.terminals}
|
46
|
+
assert len(self.terminals) == len(self.terminals_by_name)
|
47
|
+
self.ignore = ignore
|
48
|
+
self.postlex = postlex
|
49
|
+
self.callbacks = callbacks or {}
|
50
|
+
self.g_regex_flags = g_regex_flags
|
51
|
+
self.re_module = re_module
|
52
|
+
self.skip_validation = skip_validation
|
53
|
+
self.use_bytes = use_bytes
|
54
|
+
self.strict = strict
|
55
|
+
self.lexer_type = None
|
56
|
+
|
57
|
+
def _deserialize(self):
|
58
|
+
self.terminals_by_name = {t.name: t for t in self.terminals}
|
59
|
+
|
60
|
+
def __deepcopy__(self, memo=None):
|
61
|
+
return type(self)(
|
62
|
+
deepcopy(self.terminals, memo),
|
63
|
+
self.re_module,
|
64
|
+
deepcopy(self.ignore, memo),
|
65
|
+
deepcopy(self.postlex, memo),
|
66
|
+
deepcopy(self.callbacks, memo),
|
67
|
+
deepcopy(self.g_regex_flags, memo),
|
68
|
+
deepcopy(self.skip_validation, memo),
|
69
|
+
deepcopy(self.use_bytes, memo),
|
70
|
+
)
|
71
|
+
|
72
|
+
class ParserConf(Serialize):
|
73
|
+
__serialize_fields__ = 'rules', 'start', 'parser_type'
|
74
|
+
|
75
|
+
rules: List['Rule']
|
76
|
+
callbacks: ParserCallbacks
|
77
|
+
start: List[str]
|
78
|
+
parser_type: _ParserArgType
|
79
|
+
|
80
|
+
def __init__(self, rules: List['Rule'], callbacks: ParserCallbacks, start: List[str]):
|
81
|
+
assert isinstance(start, list)
|
82
|
+
self.rules = rules
|
83
|
+
self.callbacks = callbacks
|
84
|
+
self.start = start
|
85
|
+
|
86
|
+
###}
|
@@ -0,0 +1,292 @@
|
|
1
|
+
from .utils import logger, NO_VALUE
|
2
|
+
from typing import Mapping, Iterable, Callable, Union, TypeVar, Tuple, Any, List, Set, Optional, Collection, TYPE_CHECKING
|
3
|
+
|
4
|
+
if TYPE_CHECKING:
|
5
|
+
from .lexer import Token
|
6
|
+
from .parsers.lalr_interactive_parser import InteractiveParser
|
7
|
+
from .tree import Tree
|
8
|
+
|
9
|
+
###{standalone
|
10
|
+
|
11
|
+
class LarkError(Exception):
|
12
|
+
pass
|
13
|
+
|
14
|
+
|
15
|
+
class ConfigurationError(LarkError, ValueError):
|
16
|
+
pass
|
17
|
+
|
18
|
+
|
19
|
+
def assert_config(value, options: Collection, msg='Got %r, expected one of %s'):
|
20
|
+
if value not in options:
|
21
|
+
raise ConfigurationError(msg % (value, options))
|
22
|
+
|
23
|
+
|
24
|
+
class GrammarError(LarkError):
|
25
|
+
pass
|
26
|
+
|
27
|
+
|
28
|
+
class ParseError(LarkError):
|
29
|
+
pass
|
30
|
+
|
31
|
+
|
32
|
+
class LexError(LarkError):
|
33
|
+
pass
|
34
|
+
|
35
|
+
T = TypeVar('T')
|
36
|
+
|
37
|
+
class UnexpectedInput(LarkError):
|
38
|
+
"""UnexpectedInput Error.
|
39
|
+
|
40
|
+
Used as a base class for the following exceptions:
|
41
|
+
|
42
|
+
- ``UnexpectedCharacters``: The lexer encountered an unexpected string
|
43
|
+
- ``UnexpectedToken``: The parser received an unexpected token
|
44
|
+
- ``UnexpectedEOF``: The parser expected a token, but the input ended
|
45
|
+
|
46
|
+
After catching one of these exceptions, you may call the following helper methods to create a nicer error message.
|
47
|
+
"""
|
48
|
+
line: int
|
49
|
+
column: int
|
50
|
+
pos_in_stream = None
|
51
|
+
state: Any
|
52
|
+
_terminals_by_name = None
|
53
|
+
interactive_parser: 'InteractiveParser'
|
54
|
+
|
55
|
+
def get_context(self, text: str, span: int=40) -> str:
|
56
|
+
"""Returns a pretty string pinpointing the error in the text,
|
57
|
+
with span amount of context characters around it.
|
58
|
+
|
59
|
+
Note:
|
60
|
+
The parser doesn't hold a copy of the text it has to parse,
|
61
|
+
so you have to provide it again
|
62
|
+
"""
|
63
|
+
assert self.pos_in_stream is not None, self
|
64
|
+
pos = self.pos_in_stream
|
65
|
+
start = max(pos - span, 0)
|
66
|
+
end = pos + span
|
67
|
+
if not isinstance(text, bytes):
|
68
|
+
before = text[start:pos].rsplit('\n', 1)[-1]
|
69
|
+
after = text[pos:end].split('\n', 1)[0]
|
70
|
+
return before + after + '\n' + ' ' * len(before.expandtabs()) + '^\n'
|
71
|
+
else:
|
72
|
+
before = text[start:pos].rsplit(b'\n', 1)[-1]
|
73
|
+
after = text[pos:end].split(b'\n', 1)[0]
|
74
|
+
return (before + after + b'\n' + b' ' * len(before.expandtabs()) + b'^\n').decode("ascii", "backslashreplace")
|
75
|
+
|
76
|
+
def match_examples(self, parse_fn: 'Callable[[str], Tree]',
|
77
|
+
examples: Union[Mapping[T, Iterable[str]], Iterable[Tuple[T, Iterable[str]]]],
|
78
|
+
token_type_match_fallback: bool=False,
|
79
|
+
use_accepts: bool=True
|
80
|
+
) -> Optional[T]:
|
81
|
+
"""Allows you to detect what's wrong in the input text by matching
|
82
|
+
against example errors.
|
83
|
+
|
84
|
+
Given a parser instance and a dictionary mapping some label with
|
85
|
+
some malformed syntax examples, it'll return the label for the
|
86
|
+
example that bests matches the current error. The function will
|
87
|
+
iterate the dictionary until it finds a matching error, and
|
88
|
+
return the corresponding value.
|
89
|
+
|
90
|
+
For an example usage, see `examples/error_reporting_lalr.py`
|
91
|
+
|
92
|
+
Parameters:
|
93
|
+
parse_fn: parse function (usually ``lark_instance.parse``)
|
94
|
+
examples: dictionary of ``{'example_string': value}``.
|
95
|
+
use_accepts: Recommended to keep this as ``use_accepts=True``.
|
96
|
+
"""
|
97
|
+
assert self.state is not None, "Not supported for this exception"
|
98
|
+
|
99
|
+
if isinstance(examples, Mapping):
|
100
|
+
examples = examples.items()
|
101
|
+
|
102
|
+
candidate = (None, False)
|
103
|
+
for i, (label, example) in enumerate(examples):
|
104
|
+
assert not isinstance(example, str), "Expecting a list"
|
105
|
+
|
106
|
+
for j, malformed in enumerate(example):
|
107
|
+
try:
|
108
|
+
parse_fn(malformed)
|
109
|
+
except UnexpectedInput as ut:
|
110
|
+
if ut.state == self.state:
|
111
|
+
if (
|
112
|
+
use_accepts
|
113
|
+
and isinstance(self, UnexpectedToken)
|
114
|
+
and isinstance(ut, UnexpectedToken)
|
115
|
+
and ut.accepts != self.accepts
|
116
|
+
):
|
117
|
+
logger.debug("Different accepts with same state[%d]: %s != %s at example [%s][%s]" %
|
118
|
+
(self.state, self.accepts, ut.accepts, i, j))
|
119
|
+
continue
|
120
|
+
if (
|
121
|
+
isinstance(self, (UnexpectedToken, UnexpectedEOF))
|
122
|
+
and isinstance(ut, (UnexpectedToken, UnexpectedEOF))
|
123
|
+
):
|
124
|
+
if ut.token == self.token: # Try exact match first
|
125
|
+
logger.debug("Exact Match at example [%s][%s]" % (i, j))
|
126
|
+
return label
|
127
|
+
|
128
|
+
if token_type_match_fallback:
|
129
|
+
# Fallback to token types match
|
130
|
+
if (ut.token.type == self.token.type) and not candidate[-1]:
|
131
|
+
logger.debug("Token Type Fallback at example [%s][%s]" % (i, j))
|
132
|
+
candidate = label, True
|
133
|
+
|
134
|
+
if candidate[0] is None:
|
135
|
+
logger.debug("Same State match at example [%s][%s]" % (i, j))
|
136
|
+
candidate = label, False
|
137
|
+
|
138
|
+
return candidate[0]
|
139
|
+
|
140
|
+
def _format_expected(self, expected):
|
141
|
+
if self._terminals_by_name:
|
142
|
+
d = self._terminals_by_name
|
143
|
+
expected = [d[t_name].user_repr() if t_name in d else t_name for t_name in expected]
|
144
|
+
return "Expected one of: \n\t* %s\n" % '\n\t* '.join(expected)
|
145
|
+
|
146
|
+
|
147
|
+
class UnexpectedEOF(ParseError, UnexpectedInput):
|
148
|
+
"""An exception that is raised by the parser, when the input ends while it still expects a token.
|
149
|
+
"""
|
150
|
+
expected: 'List[Token]'
|
151
|
+
|
152
|
+
def __init__(self, expected, state=None, terminals_by_name=None):
|
153
|
+
super(UnexpectedEOF, self).__init__()
|
154
|
+
|
155
|
+
self.expected = expected
|
156
|
+
self.state = state
|
157
|
+
from .lexer import Token
|
158
|
+
self.token = Token("<EOF>", "") # , line=-1, column=-1, pos_in_stream=-1)
|
159
|
+
self.pos_in_stream = -1
|
160
|
+
self.line = -1
|
161
|
+
self.column = -1
|
162
|
+
self._terminals_by_name = terminals_by_name
|
163
|
+
|
164
|
+
|
165
|
+
def __str__(self):
|
166
|
+
message = "Unexpected end-of-input. "
|
167
|
+
message += self._format_expected(self.expected)
|
168
|
+
return message
|
169
|
+
|
170
|
+
|
171
|
+
class UnexpectedCharacters(LexError, UnexpectedInput):
|
172
|
+
"""An exception that is raised by the lexer, when it cannot match the next
|
173
|
+
string of characters to any of its terminals.
|
174
|
+
"""
|
175
|
+
|
176
|
+
allowed: Set[str]
|
177
|
+
considered_tokens: Set[Any]
|
178
|
+
|
179
|
+
def __init__(self, seq, lex_pos, line, column, allowed=None, considered_tokens=None, state=None, token_history=None,
|
180
|
+
terminals_by_name=None, considered_rules=None):
|
181
|
+
super(UnexpectedCharacters, self).__init__()
|
182
|
+
|
183
|
+
# TODO considered_tokens and allowed can be figured out using state
|
184
|
+
self.line = line
|
185
|
+
self.column = column
|
186
|
+
self.pos_in_stream = lex_pos
|
187
|
+
self.state = state
|
188
|
+
self._terminals_by_name = terminals_by_name
|
189
|
+
|
190
|
+
self.allowed = allowed
|
191
|
+
self.considered_tokens = considered_tokens
|
192
|
+
self.considered_rules = considered_rules
|
193
|
+
self.token_history = token_history
|
194
|
+
|
195
|
+
if isinstance(seq, bytes):
|
196
|
+
self.char = seq[lex_pos:lex_pos + 1].decode("ascii", "backslashreplace")
|
197
|
+
else:
|
198
|
+
self.char = seq[lex_pos]
|
199
|
+
self._context = self.get_context(seq)
|
200
|
+
|
201
|
+
|
202
|
+
def __str__(self):
|
203
|
+
message = "No terminal matches '%s' in the current parser context, at line %d col %d" % (self.char, self.line, self.column)
|
204
|
+
message += '\n\n' + self._context
|
205
|
+
if self.allowed:
|
206
|
+
message += self._format_expected(self.allowed)
|
207
|
+
if self.token_history:
|
208
|
+
message += '\nPrevious tokens: %s\n' % ', '.join(repr(t) for t in self.token_history)
|
209
|
+
return message
|
210
|
+
|
211
|
+
|
212
|
+
class UnexpectedToken(ParseError, UnexpectedInput):
|
213
|
+
"""An exception that is raised by the parser, when the token it received
|
214
|
+
doesn't match any valid step forward.
|
215
|
+
|
216
|
+
Parameters:
|
217
|
+
token: The mismatched token
|
218
|
+
expected: The set of expected tokens
|
219
|
+
considered_rules: Which rules were considered, to deduce the expected tokens
|
220
|
+
state: A value representing the parser state. Do not rely on its value or type.
|
221
|
+
interactive_parser: An instance of ``InteractiveParser``, that is initialized to the point of failure,
|
222
|
+
and can be used for debugging and error handling.
|
223
|
+
|
224
|
+
Note: These parameters are available as attributes of the instance.
|
225
|
+
"""
|
226
|
+
|
227
|
+
expected: Set[str]
|
228
|
+
considered_rules: Set[str]
|
229
|
+
|
230
|
+
def __init__(self, token, expected, considered_rules=None, state=None, interactive_parser=None, terminals_by_name=None, token_history=None):
|
231
|
+
super(UnexpectedToken, self).__init__()
|
232
|
+
|
233
|
+
# TODO considered_rules and expected can be figured out using state
|
234
|
+
self.line = getattr(token, 'line', '?')
|
235
|
+
self.column = getattr(token, 'column', '?')
|
236
|
+
self.pos_in_stream = getattr(token, 'start_pos', None)
|
237
|
+
self.state = state
|
238
|
+
|
239
|
+
self.token = token
|
240
|
+
self.expected = expected # XXX deprecate? `accepts` is better
|
241
|
+
self._accepts = NO_VALUE
|
242
|
+
self.considered_rules = considered_rules
|
243
|
+
self.interactive_parser = interactive_parser
|
244
|
+
self._terminals_by_name = terminals_by_name
|
245
|
+
self.token_history = token_history
|
246
|
+
|
247
|
+
|
248
|
+
@property
|
249
|
+
def accepts(self) -> Set[str]:
|
250
|
+
if self._accepts is NO_VALUE:
|
251
|
+
self._accepts = self.interactive_parser and self.interactive_parser.accepts()
|
252
|
+
return self._accepts
|
253
|
+
|
254
|
+
def __str__(self):
|
255
|
+
message = ("Unexpected token %r at line %s, column %s.\n%s"
|
256
|
+
% (self.token, self.line, self.column, self._format_expected(self.accepts or self.expected)))
|
257
|
+
if self.token_history:
|
258
|
+
message += "Previous tokens: %r\n" % self.token_history
|
259
|
+
|
260
|
+
return message
|
261
|
+
|
262
|
+
|
263
|
+
|
264
|
+
class VisitError(LarkError):
|
265
|
+
"""VisitError is raised when visitors are interrupted by an exception
|
266
|
+
|
267
|
+
It provides the following attributes for inspection:
|
268
|
+
|
269
|
+
Parameters:
|
270
|
+
rule: the name of the visit rule that failed
|
271
|
+
obj: the tree-node or token that was being processed
|
272
|
+
orig_exc: the exception that cause it to fail
|
273
|
+
|
274
|
+
Note: These parameters are available as attributes
|
275
|
+
"""
|
276
|
+
|
277
|
+
obj: 'Union[Tree, Token]'
|
278
|
+
orig_exc: Exception
|
279
|
+
|
280
|
+
def __init__(self, rule, obj, orig_exc):
|
281
|
+
message = 'Error trying to process rule "%s":\n\n%s' % (rule, orig_exc)
|
282
|
+
super(VisitError, self).__init__(message)
|
283
|
+
|
284
|
+
self.rule = rule
|
285
|
+
self.obj = obj
|
286
|
+
self.orig_exc = orig_exc
|
287
|
+
|
288
|
+
|
289
|
+
class MissingVariableError(LarkError):
|
290
|
+
pass
|
291
|
+
|
292
|
+
###}
|