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.
Files changed (290) hide show
  1. coinex/__init__.py +7 -0
  2. coinex/ccxt/__init__.py +101 -0
  3. coinex/ccxt/abstract/coinex.py +237 -0
  4. coinex/ccxt/async_support/__init__.py +80 -0
  5. coinex/ccxt/async_support/base/__init__.py +1 -0
  6. coinex/ccxt/async_support/base/exchange.py +2100 -0
  7. coinex/ccxt/async_support/base/throttler.py +50 -0
  8. coinex/ccxt/async_support/base/ws/__init__.py +38 -0
  9. coinex/ccxt/async_support/base/ws/aiohttp_client.py +147 -0
  10. coinex/ccxt/async_support/base/ws/cache.py +213 -0
  11. coinex/ccxt/async_support/base/ws/client.py +214 -0
  12. coinex/ccxt/async_support/base/ws/fast_client.py +97 -0
  13. coinex/ccxt/async_support/base/ws/functions.py +59 -0
  14. coinex/ccxt/async_support/base/ws/future.py +69 -0
  15. coinex/ccxt/async_support/base/ws/order_book.py +78 -0
  16. coinex/ccxt/async_support/base/ws/order_book_side.py +174 -0
  17. coinex/ccxt/async_support/coinex.py +5833 -0
  18. coinex/ccxt/base/__init__.py +27 -0
  19. coinex/ccxt/base/decimal_to_precision.py +174 -0
  20. coinex/ccxt/base/errors.py +267 -0
  21. coinex/ccxt/base/exchange.py +6769 -0
  22. coinex/ccxt/base/precise.py +297 -0
  23. coinex/ccxt/base/types.py +577 -0
  24. coinex/ccxt/coinex.py +5832 -0
  25. coinex/ccxt/pro/__init__.py +21 -0
  26. coinex/ccxt/pro/coinex.py +1366 -0
  27. coinex/ccxt/static_dependencies/README.md +1 -0
  28. coinex/ccxt/static_dependencies/__init__.py +1 -0
  29. coinex/ccxt/static_dependencies/ecdsa/__init__.py +14 -0
  30. coinex/ccxt/static_dependencies/ecdsa/_version.py +520 -0
  31. coinex/ccxt/static_dependencies/ecdsa/curves.py +56 -0
  32. coinex/ccxt/static_dependencies/ecdsa/der.py +221 -0
  33. coinex/ccxt/static_dependencies/ecdsa/ecdsa.py +310 -0
  34. coinex/ccxt/static_dependencies/ecdsa/ellipticcurve.py +197 -0
  35. coinex/ccxt/static_dependencies/ecdsa/keys.py +332 -0
  36. coinex/ccxt/static_dependencies/ecdsa/numbertheory.py +531 -0
  37. coinex/ccxt/static_dependencies/ecdsa/rfc6979.py +100 -0
  38. coinex/ccxt/static_dependencies/ecdsa/util.py +266 -0
  39. coinex/ccxt/static_dependencies/ethereum/__init__.py +7 -0
  40. coinex/ccxt/static_dependencies/ethereum/abi/__init__.py +16 -0
  41. coinex/ccxt/static_dependencies/ethereum/abi/abi.py +19 -0
  42. coinex/ccxt/static_dependencies/ethereum/abi/base.py +152 -0
  43. coinex/ccxt/static_dependencies/ethereum/abi/codec.py +217 -0
  44. coinex/ccxt/static_dependencies/ethereum/abi/constants.py +3 -0
  45. coinex/ccxt/static_dependencies/ethereum/abi/decoding.py +565 -0
  46. coinex/ccxt/static_dependencies/ethereum/abi/encoding.py +720 -0
  47. coinex/ccxt/static_dependencies/ethereum/abi/exceptions.py +139 -0
  48. coinex/ccxt/static_dependencies/ethereum/abi/grammar.py +443 -0
  49. coinex/ccxt/static_dependencies/ethereum/abi/packed.py +13 -0
  50. coinex/ccxt/static_dependencies/ethereum/abi/py.typed +0 -0
  51. coinex/ccxt/static_dependencies/ethereum/abi/registry.py +643 -0
  52. coinex/ccxt/static_dependencies/ethereum/abi/tools/__init__.py +3 -0
  53. coinex/ccxt/static_dependencies/ethereum/abi/tools/_strategies.py +230 -0
  54. coinex/ccxt/static_dependencies/ethereum/abi/utils/__init__.py +0 -0
  55. coinex/ccxt/static_dependencies/ethereum/abi/utils/numeric.py +83 -0
  56. coinex/ccxt/static_dependencies/ethereum/abi/utils/padding.py +27 -0
  57. coinex/ccxt/static_dependencies/ethereum/abi/utils/string.py +19 -0
  58. coinex/ccxt/static_dependencies/ethereum/account/__init__.py +3 -0
  59. coinex/ccxt/static_dependencies/ethereum/account/encode_typed_data/__init__.py +4 -0
  60. coinex/ccxt/static_dependencies/ethereum/account/encode_typed_data/encoding_and_hashing.py +239 -0
  61. coinex/ccxt/static_dependencies/ethereum/account/encode_typed_data/helpers.py +40 -0
  62. coinex/ccxt/static_dependencies/ethereum/account/messages.py +263 -0
  63. coinex/ccxt/static_dependencies/ethereum/account/py.typed +0 -0
  64. coinex/ccxt/static_dependencies/ethereum/hexbytes/__init__.py +5 -0
  65. coinex/ccxt/static_dependencies/ethereum/hexbytes/_utils.py +54 -0
  66. coinex/ccxt/static_dependencies/ethereum/hexbytes/main.py +65 -0
  67. coinex/ccxt/static_dependencies/ethereum/hexbytes/py.typed +0 -0
  68. coinex/ccxt/static_dependencies/ethereum/typing/__init__.py +63 -0
  69. coinex/ccxt/static_dependencies/ethereum/typing/abi.py +6 -0
  70. coinex/ccxt/static_dependencies/ethereum/typing/bls.py +7 -0
  71. coinex/ccxt/static_dependencies/ethereum/typing/discovery.py +5 -0
  72. coinex/ccxt/static_dependencies/ethereum/typing/encoding.py +7 -0
  73. coinex/ccxt/static_dependencies/ethereum/typing/enums.py +17 -0
  74. coinex/ccxt/static_dependencies/ethereum/typing/ethpm.py +9 -0
  75. coinex/ccxt/static_dependencies/ethereum/typing/evm.py +20 -0
  76. coinex/ccxt/static_dependencies/ethereum/typing/networks.py +1122 -0
  77. coinex/ccxt/static_dependencies/ethereum/typing/py.typed +0 -0
  78. coinex/ccxt/static_dependencies/ethereum/utils/__init__.py +115 -0
  79. coinex/ccxt/static_dependencies/ethereum/utils/abi.py +72 -0
  80. coinex/ccxt/static_dependencies/ethereum/utils/address.py +171 -0
  81. coinex/ccxt/static_dependencies/ethereum/utils/applicators.py +151 -0
  82. coinex/ccxt/static_dependencies/ethereum/utils/conversions.py +190 -0
  83. coinex/ccxt/static_dependencies/ethereum/utils/currency.py +107 -0
  84. coinex/ccxt/static_dependencies/ethereum/utils/curried/__init__.py +269 -0
  85. coinex/ccxt/static_dependencies/ethereum/utils/debug.py +20 -0
  86. coinex/ccxt/static_dependencies/ethereum/utils/decorators.py +132 -0
  87. coinex/ccxt/static_dependencies/ethereum/utils/encoding.py +6 -0
  88. coinex/ccxt/static_dependencies/ethereum/utils/exceptions.py +4 -0
  89. coinex/ccxt/static_dependencies/ethereum/utils/functional.py +75 -0
  90. coinex/ccxt/static_dependencies/ethereum/utils/hexadecimal.py +74 -0
  91. coinex/ccxt/static_dependencies/ethereum/utils/humanize.py +188 -0
  92. coinex/ccxt/static_dependencies/ethereum/utils/logging.py +159 -0
  93. coinex/ccxt/static_dependencies/ethereum/utils/module_loading.py +31 -0
  94. coinex/ccxt/static_dependencies/ethereum/utils/numeric.py +43 -0
  95. coinex/ccxt/static_dependencies/ethereum/utils/py.typed +0 -0
  96. coinex/ccxt/static_dependencies/ethereum/utils/toolz.py +76 -0
  97. coinex/ccxt/static_dependencies/ethereum/utils/types.py +54 -0
  98. coinex/ccxt/static_dependencies/ethereum/utils/typing/__init__.py +18 -0
  99. coinex/ccxt/static_dependencies/ethereum/utils/typing/misc.py +14 -0
  100. coinex/ccxt/static_dependencies/ethereum/utils/units.py +31 -0
  101. coinex/ccxt/static_dependencies/keccak/__init__.py +3 -0
  102. coinex/ccxt/static_dependencies/keccak/keccak.py +197 -0
  103. coinex/ccxt/static_dependencies/lark/__init__.py +38 -0
  104. coinex/ccxt/static_dependencies/lark/__pyinstaller/__init__.py +6 -0
  105. coinex/ccxt/static_dependencies/lark/__pyinstaller/hook-lark.py +14 -0
  106. coinex/ccxt/static_dependencies/lark/ast_utils.py +59 -0
  107. coinex/ccxt/static_dependencies/lark/common.py +86 -0
  108. coinex/ccxt/static_dependencies/lark/exceptions.py +292 -0
  109. coinex/ccxt/static_dependencies/lark/grammar.py +130 -0
  110. coinex/ccxt/static_dependencies/lark/grammars/__init__.py +0 -0
  111. coinex/ccxt/static_dependencies/lark/grammars/common.lark +59 -0
  112. coinex/ccxt/static_dependencies/lark/grammars/lark.lark +62 -0
  113. coinex/ccxt/static_dependencies/lark/grammars/python.lark +302 -0
  114. coinex/ccxt/static_dependencies/lark/grammars/unicode.lark +7 -0
  115. coinex/ccxt/static_dependencies/lark/indenter.py +143 -0
  116. coinex/ccxt/static_dependencies/lark/lark.py +658 -0
  117. coinex/ccxt/static_dependencies/lark/lexer.py +678 -0
  118. coinex/ccxt/static_dependencies/lark/load_grammar.py +1428 -0
  119. coinex/ccxt/static_dependencies/lark/parse_tree_builder.py +391 -0
  120. coinex/ccxt/static_dependencies/lark/parser_frontends.py +257 -0
  121. coinex/ccxt/static_dependencies/lark/parsers/__init__.py +0 -0
  122. coinex/ccxt/static_dependencies/lark/parsers/cyk.py +340 -0
  123. coinex/ccxt/static_dependencies/lark/parsers/earley.py +314 -0
  124. coinex/ccxt/static_dependencies/lark/parsers/earley_common.py +42 -0
  125. coinex/ccxt/static_dependencies/lark/parsers/earley_forest.py +801 -0
  126. coinex/ccxt/static_dependencies/lark/parsers/grammar_analysis.py +203 -0
  127. coinex/ccxt/static_dependencies/lark/parsers/lalr_analysis.py +332 -0
  128. coinex/ccxt/static_dependencies/lark/parsers/lalr_interactive_parser.py +158 -0
  129. coinex/ccxt/static_dependencies/lark/parsers/lalr_parser.py +122 -0
  130. coinex/ccxt/static_dependencies/lark/parsers/lalr_parser_state.py +110 -0
  131. coinex/ccxt/static_dependencies/lark/parsers/xearley.py +165 -0
  132. coinex/ccxt/static_dependencies/lark/py.typed +0 -0
  133. coinex/ccxt/static_dependencies/lark/reconstruct.py +107 -0
  134. coinex/ccxt/static_dependencies/lark/tools/__init__.py +70 -0
  135. coinex/ccxt/static_dependencies/lark/tools/nearley.py +202 -0
  136. coinex/ccxt/static_dependencies/lark/tools/serialize.py +32 -0
  137. coinex/ccxt/static_dependencies/lark/tools/standalone.py +196 -0
  138. coinex/ccxt/static_dependencies/lark/tree.py +267 -0
  139. coinex/ccxt/static_dependencies/lark/tree_matcher.py +186 -0
  140. coinex/ccxt/static_dependencies/lark/tree_templates.py +180 -0
  141. coinex/ccxt/static_dependencies/lark/utils.py +343 -0
  142. coinex/ccxt/static_dependencies/lark/visitors.py +596 -0
  143. coinex/ccxt/static_dependencies/marshmallow/__init__.py +81 -0
  144. coinex/ccxt/static_dependencies/marshmallow/base.py +65 -0
  145. coinex/ccxt/static_dependencies/marshmallow/class_registry.py +94 -0
  146. coinex/ccxt/static_dependencies/marshmallow/decorators.py +231 -0
  147. coinex/ccxt/static_dependencies/marshmallow/error_store.py +60 -0
  148. coinex/ccxt/static_dependencies/marshmallow/exceptions.py +71 -0
  149. coinex/ccxt/static_dependencies/marshmallow/fields.py +2114 -0
  150. coinex/ccxt/static_dependencies/marshmallow/orderedset.py +89 -0
  151. coinex/ccxt/static_dependencies/marshmallow/py.typed +0 -0
  152. coinex/ccxt/static_dependencies/marshmallow/schema.py +1228 -0
  153. coinex/ccxt/static_dependencies/marshmallow/types.py +12 -0
  154. coinex/ccxt/static_dependencies/marshmallow/utils.py +378 -0
  155. coinex/ccxt/static_dependencies/marshmallow/validate.py +678 -0
  156. coinex/ccxt/static_dependencies/marshmallow/warnings.py +2 -0
  157. coinex/ccxt/static_dependencies/marshmallow_dataclass/__init__.py +1047 -0
  158. coinex/ccxt/static_dependencies/marshmallow_dataclass/collection_field.py +51 -0
  159. coinex/ccxt/static_dependencies/marshmallow_dataclass/lazy_class_attribute.py +45 -0
  160. coinex/ccxt/static_dependencies/marshmallow_dataclass/mypy.py +71 -0
  161. coinex/ccxt/static_dependencies/marshmallow_dataclass/py.typed +0 -0
  162. coinex/ccxt/static_dependencies/marshmallow_dataclass/typing.py +14 -0
  163. coinex/ccxt/static_dependencies/marshmallow_dataclass/union_field.py +82 -0
  164. coinex/ccxt/static_dependencies/marshmallow_oneofschema/__init__.py +1 -0
  165. coinex/ccxt/static_dependencies/marshmallow_oneofschema/one_of_schema.py +193 -0
  166. coinex/ccxt/static_dependencies/marshmallow_oneofschema/py.typed +0 -0
  167. coinex/ccxt/static_dependencies/msgpack/__init__.py +55 -0
  168. coinex/ccxt/static_dependencies/msgpack/_cmsgpack.pyx +11 -0
  169. coinex/ccxt/static_dependencies/msgpack/_packer.pyx +374 -0
  170. coinex/ccxt/static_dependencies/msgpack/_unpacker.pyx +547 -0
  171. coinex/ccxt/static_dependencies/msgpack/buff_converter.h +8 -0
  172. coinex/ccxt/static_dependencies/msgpack/exceptions.py +48 -0
  173. coinex/ccxt/static_dependencies/msgpack/ext.py +168 -0
  174. coinex/ccxt/static_dependencies/msgpack/fallback.py +951 -0
  175. coinex/ccxt/static_dependencies/msgpack/pack.h +89 -0
  176. coinex/ccxt/static_dependencies/msgpack/pack_template.h +820 -0
  177. coinex/ccxt/static_dependencies/msgpack/sysdep.h +194 -0
  178. coinex/ccxt/static_dependencies/msgpack/unpack.h +391 -0
  179. coinex/ccxt/static_dependencies/msgpack/unpack_define.h +95 -0
  180. coinex/ccxt/static_dependencies/msgpack/unpack_template.h +464 -0
  181. coinex/ccxt/static_dependencies/parsimonious/__init__.py +10 -0
  182. coinex/ccxt/static_dependencies/parsimonious/exceptions.py +105 -0
  183. coinex/ccxt/static_dependencies/parsimonious/expressions.py +479 -0
  184. coinex/ccxt/static_dependencies/parsimonious/grammar.py +487 -0
  185. coinex/ccxt/static_dependencies/parsimonious/nodes.py +325 -0
  186. coinex/ccxt/static_dependencies/parsimonious/utils.py +40 -0
  187. coinex/ccxt/static_dependencies/starknet/__init__.py +0 -0
  188. coinex/ccxt/static_dependencies/starknet/abi/v0/__init__.py +2 -0
  189. coinex/ccxt/static_dependencies/starknet/abi/v0/model.py +44 -0
  190. coinex/ccxt/static_dependencies/starknet/abi/v0/parser.py +216 -0
  191. coinex/ccxt/static_dependencies/starknet/abi/v0/schemas.py +72 -0
  192. coinex/ccxt/static_dependencies/starknet/abi/v0/shape.py +63 -0
  193. coinex/ccxt/static_dependencies/starknet/abi/v1/__init__.py +2 -0
  194. coinex/ccxt/static_dependencies/starknet/abi/v1/core_structures.json +14 -0
  195. coinex/ccxt/static_dependencies/starknet/abi/v1/model.py +39 -0
  196. coinex/ccxt/static_dependencies/starknet/abi/v1/parser.py +220 -0
  197. coinex/ccxt/static_dependencies/starknet/abi/v1/parser_transformer.py +179 -0
  198. coinex/ccxt/static_dependencies/starknet/abi/v1/schemas.py +66 -0
  199. coinex/ccxt/static_dependencies/starknet/abi/v1/shape.py +47 -0
  200. coinex/ccxt/static_dependencies/starknet/abi/v2/__init__.py +2 -0
  201. coinex/ccxt/static_dependencies/starknet/abi/v2/model.py +89 -0
  202. coinex/ccxt/static_dependencies/starknet/abi/v2/parser.py +293 -0
  203. coinex/ccxt/static_dependencies/starknet/abi/v2/parser_transformer.py +192 -0
  204. coinex/ccxt/static_dependencies/starknet/abi/v2/schemas.py +132 -0
  205. coinex/ccxt/static_dependencies/starknet/abi/v2/shape.py +107 -0
  206. coinex/ccxt/static_dependencies/starknet/cairo/__init__.py +0 -0
  207. coinex/ccxt/static_dependencies/starknet/cairo/data_types.py +123 -0
  208. coinex/ccxt/static_dependencies/starknet/cairo/deprecated_parse/__init__.py +0 -0
  209. coinex/ccxt/static_dependencies/starknet/cairo/deprecated_parse/cairo_types.py +77 -0
  210. coinex/ccxt/static_dependencies/starknet/cairo/deprecated_parse/parser.py +46 -0
  211. coinex/ccxt/static_dependencies/starknet/cairo/deprecated_parse/parser_transformer.py +138 -0
  212. coinex/ccxt/static_dependencies/starknet/cairo/felt.py +64 -0
  213. coinex/ccxt/static_dependencies/starknet/cairo/type_parser.py +121 -0
  214. coinex/ccxt/static_dependencies/starknet/cairo/v1/__init__.py +0 -0
  215. coinex/ccxt/static_dependencies/starknet/cairo/v1/type_parser.py +59 -0
  216. coinex/ccxt/static_dependencies/starknet/cairo/v2/__init__.py +0 -0
  217. coinex/ccxt/static_dependencies/starknet/cairo/v2/type_parser.py +77 -0
  218. coinex/ccxt/static_dependencies/starknet/ccxt_utils.py +7 -0
  219. coinex/ccxt/static_dependencies/starknet/common.py +15 -0
  220. coinex/ccxt/static_dependencies/starknet/constants.py +39 -0
  221. coinex/ccxt/static_dependencies/starknet/hash/__init__.py +0 -0
  222. coinex/ccxt/static_dependencies/starknet/hash/address.py +79 -0
  223. coinex/ccxt/static_dependencies/starknet/hash/compiled_class_hash_objects.py +111 -0
  224. coinex/ccxt/static_dependencies/starknet/hash/selector.py +16 -0
  225. coinex/ccxt/static_dependencies/starknet/hash/storage.py +12 -0
  226. coinex/ccxt/static_dependencies/starknet/hash/utils.py +78 -0
  227. coinex/ccxt/static_dependencies/starknet/models/__init__.py +0 -0
  228. coinex/ccxt/static_dependencies/starknet/models/typed_data.py +45 -0
  229. coinex/ccxt/static_dependencies/starknet/serialization/__init__.py +24 -0
  230. coinex/ccxt/static_dependencies/starknet/serialization/_calldata_reader.py +40 -0
  231. coinex/ccxt/static_dependencies/starknet/serialization/_context.py +142 -0
  232. coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/__init__.py +10 -0
  233. coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/_common.py +82 -0
  234. coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/array_serializer.py +43 -0
  235. coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/bool_serializer.py +37 -0
  236. coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/byte_array_serializer.py +66 -0
  237. coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/cairo_data_serializer.py +71 -0
  238. coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/enum_serializer.py +71 -0
  239. coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/felt_serializer.py +50 -0
  240. coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/named_tuple_serializer.py +58 -0
  241. coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/option_serializer.py +43 -0
  242. coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/output_serializer.py +40 -0
  243. coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/payload_serializer.py +72 -0
  244. coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/struct_serializer.py +36 -0
  245. coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/tuple_serializer.py +36 -0
  246. coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/uint256_serializer.py +76 -0
  247. coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/uint_serializer.py +100 -0
  248. coinex/ccxt/static_dependencies/starknet/serialization/data_serializers/unit_serializer.py +32 -0
  249. coinex/ccxt/static_dependencies/starknet/serialization/errors.py +10 -0
  250. coinex/ccxt/static_dependencies/starknet/serialization/factory.py +229 -0
  251. coinex/ccxt/static_dependencies/starknet/serialization/function_serialization_adapter.py +110 -0
  252. coinex/ccxt/static_dependencies/starknet/serialization/tuple_dataclass.py +59 -0
  253. coinex/ccxt/static_dependencies/starknet/utils/__init__.py +0 -0
  254. coinex/ccxt/static_dependencies/starknet/utils/constructor_args_translator.py +86 -0
  255. coinex/ccxt/static_dependencies/starknet/utils/iterable.py +13 -0
  256. coinex/ccxt/static_dependencies/starknet/utils/schema.py +13 -0
  257. coinex/ccxt/static_dependencies/starknet/utils/typed_data.py +182 -0
  258. coinex/ccxt/static_dependencies/starkware/__init__.py +0 -0
  259. coinex/ccxt/static_dependencies/starkware/crypto/__init__.py +0 -0
  260. coinex/ccxt/static_dependencies/starkware/crypto/fast_pedersen_hash.py +50 -0
  261. coinex/ccxt/static_dependencies/starkware/crypto/math_utils.py +78 -0
  262. coinex/ccxt/static_dependencies/starkware/crypto/signature.py +2344 -0
  263. coinex/ccxt/static_dependencies/starkware/crypto/utils.py +63 -0
  264. coinex/ccxt/static_dependencies/sympy/__init__.py +0 -0
  265. coinex/ccxt/static_dependencies/sympy/core/__init__.py +0 -0
  266. coinex/ccxt/static_dependencies/sympy/core/intfunc.py +35 -0
  267. coinex/ccxt/static_dependencies/sympy/external/__init__.py +0 -0
  268. coinex/ccxt/static_dependencies/sympy/external/gmpy.py +345 -0
  269. coinex/ccxt/static_dependencies/sympy/external/importtools.py +187 -0
  270. coinex/ccxt/static_dependencies/sympy/external/ntheory.py +637 -0
  271. coinex/ccxt/static_dependencies/sympy/external/pythonmpq.py +341 -0
  272. coinex/ccxt/static_dependencies/toolz/__init__.py +26 -0
  273. coinex/ccxt/static_dependencies/toolz/_signatures.py +784 -0
  274. coinex/ccxt/static_dependencies/toolz/_version.py +520 -0
  275. coinex/ccxt/static_dependencies/toolz/compatibility.py +30 -0
  276. coinex/ccxt/static_dependencies/toolz/curried/__init__.py +101 -0
  277. coinex/ccxt/static_dependencies/toolz/curried/exceptions.py +22 -0
  278. coinex/ccxt/static_dependencies/toolz/curried/operator.py +22 -0
  279. coinex/ccxt/static_dependencies/toolz/dicttoolz.py +339 -0
  280. coinex/ccxt/static_dependencies/toolz/functoolz.py +1049 -0
  281. coinex/ccxt/static_dependencies/toolz/itertoolz.py +1057 -0
  282. coinex/ccxt/static_dependencies/toolz/recipes.py +46 -0
  283. coinex/ccxt/static_dependencies/toolz/utils.py +9 -0
  284. coinex/ccxt/static_dependencies/typing_inspect/__init__.py +0 -0
  285. coinex/ccxt/static_dependencies/typing_inspect/typing_inspect.py +851 -0
  286. coinex_api-0.0.17.dist-info/METADATA +425 -0
  287. coinex_api-0.0.17.dist-info/RECORD +288 -0
  288. coinex_api-0.0.15.dist-info/METADATA +0 -79
  289. coinex_api-0.0.15.dist-info/RECORD +0 -3
  290. {coinex_api-0.0.15.dist-info → coinex_api-0.0.17.dist-info}/WHEEL +0 -0
@@ -0,0 +1,951 @@
1
+ """Fallback pure Python implementation of msgpack"""
2
+ from datetime import datetime as _DateTime
3
+ import sys
4
+ import struct
5
+
6
+
7
+ if hasattr(sys, "pypy_version_info"):
8
+ # StringIO is slow on PyPy, StringIO is faster. However: PyPy's own
9
+ # StringBuilder is fastest.
10
+ from __pypy__ import newlist_hint
11
+
12
+ try:
13
+ from __pypy__.builders import BytesBuilder as StringBuilder
14
+ except ImportError:
15
+ from __pypy__.builders import StringBuilder
16
+ USING_STRINGBUILDER = True
17
+
18
+ class StringIO:
19
+ def __init__(self, s=b""):
20
+ if s:
21
+ self.builder = StringBuilder(len(s))
22
+ self.builder.append(s)
23
+ else:
24
+ self.builder = StringBuilder()
25
+
26
+ def write(self, s):
27
+ if isinstance(s, memoryview):
28
+ s = s.tobytes()
29
+ elif isinstance(s, bytearray):
30
+ s = bytes(s)
31
+ self.builder.append(s)
32
+
33
+ def getvalue(self):
34
+ return self.builder.build()
35
+
36
+ else:
37
+ USING_STRINGBUILDER = False
38
+ from io import BytesIO as StringIO
39
+
40
+ newlist_hint = lambda size: []
41
+
42
+
43
+ from .exceptions import BufferFull, OutOfData, ExtraData, FormatError, StackError
44
+
45
+ from .ext import ExtType, Timestamp
46
+
47
+
48
+ EX_SKIP = 0
49
+ EX_CONSTRUCT = 1
50
+ EX_READ_ARRAY_HEADER = 2
51
+ EX_READ_MAP_HEADER = 3
52
+
53
+ TYPE_IMMEDIATE = 0
54
+ TYPE_ARRAY = 1
55
+ TYPE_MAP = 2
56
+ TYPE_RAW = 3
57
+ TYPE_BIN = 4
58
+ TYPE_EXT = 5
59
+
60
+ DEFAULT_RECURSE_LIMIT = 511
61
+
62
+
63
+ def _check_type_strict(obj, t, type=type, tuple=tuple):
64
+ if type(t) is tuple:
65
+ return type(obj) in t
66
+ else:
67
+ return type(obj) is t
68
+
69
+
70
+ def _get_data_from_buffer(obj):
71
+ view = memoryview(obj)
72
+ if view.itemsize != 1:
73
+ raise ValueError("cannot unpack from multi-byte object")
74
+ return view
75
+
76
+
77
+ def unpackb(packed, **kwargs):
78
+ """
79
+ Unpack an object from `packed`.
80
+
81
+ Raises ``ExtraData`` when *packed* contains extra bytes.
82
+ Raises ``ValueError`` when *packed* is incomplete.
83
+ Raises ``FormatError`` when *packed* is not valid msgpack.
84
+ Raises ``StackError`` when *packed* contains too nested.
85
+ Other exceptions can be raised during unpacking.
86
+
87
+ See :class:`Unpacker` for options.
88
+ """
89
+ unpacker = Unpacker(None, max_buffer_size=len(packed), **kwargs)
90
+ unpacker.feed(packed)
91
+ try:
92
+ ret = unpacker._unpack()
93
+ except OutOfData:
94
+ raise ValueError("Unpack failed: incomplete input")
95
+ except RecursionError:
96
+ raise StackError
97
+ if unpacker._got_extradata():
98
+ raise ExtraData(ret, unpacker._get_extradata())
99
+ return ret
100
+
101
+
102
+ _NO_FORMAT_USED = ""
103
+ _MSGPACK_HEADERS = {
104
+ 0xC4: (1, _NO_FORMAT_USED, TYPE_BIN),
105
+ 0xC5: (2, ">H", TYPE_BIN),
106
+ 0xC6: (4, ">I", TYPE_BIN),
107
+ 0xC7: (2, "Bb", TYPE_EXT),
108
+ 0xC8: (3, ">Hb", TYPE_EXT),
109
+ 0xC9: (5, ">Ib", TYPE_EXT),
110
+ 0xCA: (4, ">f"),
111
+ 0xCB: (8, ">d"),
112
+ 0xCC: (1, _NO_FORMAT_USED),
113
+ 0xCD: (2, ">H"),
114
+ 0xCE: (4, ">I"),
115
+ 0xCF: (8, ">Q"),
116
+ 0xD0: (1, "b"),
117
+ 0xD1: (2, ">h"),
118
+ 0xD2: (4, ">i"),
119
+ 0xD3: (8, ">q"),
120
+ 0xD4: (1, "b1s", TYPE_EXT),
121
+ 0xD5: (2, "b2s", TYPE_EXT),
122
+ 0xD6: (4, "b4s", TYPE_EXT),
123
+ 0xD7: (8, "b8s", TYPE_EXT),
124
+ 0xD8: (16, "b16s", TYPE_EXT),
125
+ 0xD9: (1, _NO_FORMAT_USED, TYPE_RAW),
126
+ 0xDA: (2, ">H", TYPE_RAW),
127
+ 0xDB: (4, ">I", TYPE_RAW),
128
+ 0xDC: (2, ">H", TYPE_ARRAY),
129
+ 0xDD: (4, ">I", TYPE_ARRAY),
130
+ 0xDE: (2, ">H", TYPE_MAP),
131
+ 0xDF: (4, ">I", TYPE_MAP),
132
+ }
133
+
134
+
135
+ class Unpacker:
136
+ """Streaming unpacker.
137
+
138
+ Arguments:
139
+
140
+ :param file_like:
141
+ File-like object having `.read(n)` method.
142
+ If specified, unpacker reads serialized data from it and `.feed()` is not usable.
143
+
144
+ :param int read_size:
145
+ Used as `file_like.read(read_size)`. (default: `min(16*1024, max_buffer_size)`)
146
+
147
+ :param bool use_list:
148
+ If true, unpack msgpack array to Python list.
149
+ Otherwise, unpack to Python tuple. (default: True)
150
+
151
+ :param bool raw:
152
+ If true, unpack msgpack raw to Python bytes.
153
+ Otherwise, unpack to Python str by decoding with UTF-8 encoding (default).
154
+
155
+ :param int timestamp:
156
+ Control how timestamp type is unpacked:
157
+
158
+ 0 - Timestamp
159
+ 1 - float (Seconds from the EPOCH)
160
+ 2 - int (Nanoseconds from the EPOCH)
161
+ 3 - datetime.datetime (UTC).
162
+
163
+ :param bool strict_map_key:
164
+ If true (default), only str or bytes are accepted for map (dict) keys.
165
+
166
+ :param object_hook:
167
+ When specified, it should be callable.
168
+ Unpacker calls it with a dict argument after unpacking msgpack map.
169
+ (See also simplejson)
170
+
171
+ :param object_pairs_hook:
172
+ When specified, it should be callable.
173
+ Unpacker calls it with a list of key-value pairs after unpacking msgpack map.
174
+ (See also simplejson)
175
+
176
+ :param str unicode_errors:
177
+ The error handler for decoding unicode. (default: 'strict')
178
+ This option should be used only when you have msgpack data which
179
+ contains invalid UTF-8 string.
180
+
181
+ :param int max_buffer_size:
182
+ Limits size of data waiting unpacked. 0 means 2**32-1.
183
+ The default value is 100*1024*1024 (100MiB).
184
+ Raises `BufferFull` exception when it is insufficient.
185
+ You should set this parameter when unpacking data from untrusted source.
186
+
187
+ :param int max_str_len:
188
+ Deprecated, use *max_buffer_size* instead.
189
+ Limits max length of str. (default: max_buffer_size)
190
+
191
+ :param int max_bin_len:
192
+ Deprecated, use *max_buffer_size* instead.
193
+ Limits max length of bin. (default: max_buffer_size)
194
+
195
+ :param int max_array_len:
196
+ Limits max length of array.
197
+ (default: max_buffer_size)
198
+
199
+ :param int max_map_len:
200
+ Limits max length of map.
201
+ (default: max_buffer_size//2)
202
+
203
+ :param int max_ext_len:
204
+ Deprecated, use *max_buffer_size* instead.
205
+ Limits max size of ext type. (default: max_buffer_size)
206
+
207
+ Example of streaming deserialize from file-like object::
208
+
209
+ unpacker = Unpacker(file_like)
210
+ for o in unpacker:
211
+ process(o)
212
+
213
+ Example of streaming deserialize from socket::
214
+
215
+ unpacker = Unpacker()
216
+ while True:
217
+ buf = sock.recv(1024**2)
218
+ if not buf:
219
+ break
220
+ unpacker.feed(buf)
221
+ for o in unpacker:
222
+ process(o)
223
+
224
+ Raises ``ExtraData`` when *packed* contains extra bytes.
225
+ Raises ``OutOfData`` when *packed* is incomplete.
226
+ Raises ``FormatError`` when *packed* is not valid msgpack.
227
+ Raises ``StackError`` when *packed* contains too nested.
228
+ Other exceptions can be raised during unpacking.
229
+ """
230
+
231
+ def __init__(
232
+ self,
233
+ file_like=None,
234
+ read_size=0,
235
+ use_list=True,
236
+ raw=False,
237
+ timestamp=0,
238
+ strict_map_key=True,
239
+ object_hook=None,
240
+ object_pairs_hook=None,
241
+ list_hook=None,
242
+ unicode_errors=None,
243
+ max_buffer_size=100 * 1024 * 1024,
244
+ ext_hook=ExtType,
245
+ max_str_len=-1,
246
+ max_bin_len=-1,
247
+ max_array_len=-1,
248
+ max_map_len=-1,
249
+ max_ext_len=-1,
250
+ ):
251
+ if unicode_errors is None:
252
+ unicode_errors = "strict"
253
+
254
+ if file_like is None:
255
+ self._feeding = True
256
+ else:
257
+ if not callable(file_like.read):
258
+ raise TypeError("`file_like.read` must be callable")
259
+ self.file_like = file_like
260
+ self._feeding = False
261
+
262
+ #: array of bytes fed.
263
+ self._buffer = bytearray()
264
+ #: Which position we currently reads
265
+ self._buff_i = 0
266
+
267
+ # When Unpacker is used as an iterable, between the calls to next(),
268
+ # the buffer is not "consumed" completely, for efficiency sake.
269
+ # Instead, it is done sloppily. To make sure we raise BufferFull at
270
+ # the correct moments, we have to keep track of how sloppy we were.
271
+ # Furthermore, when the buffer is incomplete (that is: in the case
272
+ # we raise an OutOfData) we need to rollback the buffer to the correct
273
+ # state, which _buf_checkpoint records.
274
+ self._buf_checkpoint = 0
275
+
276
+ if not max_buffer_size:
277
+ max_buffer_size = 2**31 - 1
278
+ if max_str_len == -1:
279
+ max_str_len = max_buffer_size
280
+ if max_bin_len == -1:
281
+ max_bin_len = max_buffer_size
282
+ if max_array_len == -1:
283
+ max_array_len = max_buffer_size
284
+ if max_map_len == -1:
285
+ max_map_len = max_buffer_size // 2
286
+ if max_ext_len == -1:
287
+ max_ext_len = max_buffer_size
288
+
289
+ self._max_buffer_size = max_buffer_size
290
+ if read_size > self._max_buffer_size:
291
+ raise ValueError("read_size must be smaller than max_buffer_size")
292
+ self._read_size = read_size or min(self._max_buffer_size, 16 * 1024)
293
+ self._raw = bool(raw)
294
+ self._strict_map_key = bool(strict_map_key)
295
+ self._unicode_errors = unicode_errors
296
+ self._use_list = use_list
297
+ if not (0 <= timestamp <= 3):
298
+ raise ValueError("timestamp must be 0..3")
299
+ self._timestamp = timestamp
300
+ self._list_hook = list_hook
301
+ self._object_hook = object_hook
302
+ self._object_pairs_hook = object_pairs_hook
303
+ self._ext_hook = ext_hook
304
+ self._max_str_len = max_str_len
305
+ self._max_bin_len = max_bin_len
306
+ self._max_array_len = max_array_len
307
+ self._max_map_len = max_map_len
308
+ self._max_ext_len = max_ext_len
309
+ self._stream_offset = 0
310
+
311
+ if list_hook is not None and not callable(list_hook):
312
+ raise TypeError("`list_hook` is not callable")
313
+ if object_hook is not None and not callable(object_hook):
314
+ raise TypeError("`object_hook` is not callable")
315
+ if object_pairs_hook is not None and not callable(object_pairs_hook):
316
+ raise TypeError("`object_pairs_hook` is not callable")
317
+ if object_hook is not None and object_pairs_hook is not None:
318
+ raise TypeError("object_pairs_hook and object_hook are mutually exclusive")
319
+ if not callable(ext_hook):
320
+ raise TypeError("`ext_hook` is not callable")
321
+
322
+ def feed(self, next_bytes):
323
+ assert self._feeding
324
+ view = _get_data_from_buffer(next_bytes)
325
+ if len(self._buffer) - self._buff_i + len(view) > self._max_buffer_size:
326
+ raise BufferFull
327
+
328
+ # Strip buffer before checkpoint before reading file.
329
+ if self._buf_checkpoint > 0:
330
+ del self._buffer[: self._buf_checkpoint]
331
+ self._buff_i -= self._buf_checkpoint
332
+ self._buf_checkpoint = 0
333
+
334
+ # Use extend here: INPLACE_ADD += doesn't reliably typecast memoryview in jython
335
+ self._buffer.extend(view)
336
+
337
+ def _consume(self):
338
+ """Gets rid of the used parts of the buffer."""
339
+ self._stream_offset += self._buff_i - self._buf_checkpoint
340
+ self._buf_checkpoint = self._buff_i
341
+
342
+ def _got_extradata(self):
343
+ return self._buff_i < len(self._buffer)
344
+
345
+ def _get_extradata(self):
346
+ return self._buffer[self._buff_i :]
347
+
348
+ def read_bytes(self, n):
349
+ ret = self._read(n, raise_outofdata=False)
350
+ self._consume()
351
+ return ret
352
+
353
+ def _read(self, n, raise_outofdata=True):
354
+ # (int) -> bytearray
355
+ self._reserve(n, raise_outofdata=raise_outofdata)
356
+ i = self._buff_i
357
+ ret = self._buffer[i : i + n]
358
+ self._buff_i = i + len(ret)
359
+ return ret
360
+
361
+ def _reserve(self, n, raise_outofdata=True):
362
+ remain_bytes = len(self._buffer) - self._buff_i - n
363
+
364
+ # Fast path: buffer has n bytes already
365
+ if remain_bytes >= 0:
366
+ return
367
+
368
+ if self._feeding:
369
+ self._buff_i = self._buf_checkpoint
370
+ raise OutOfData
371
+
372
+ # Strip buffer before checkpoint before reading file.
373
+ if self._buf_checkpoint > 0:
374
+ del self._buffer[: self._buf_checkpoint]
375
+ self._buff_i -= self._buf_checkpoint
376
+ self._buf_checkpoint = 0
377
+
378
+ # Read from file
379
+ remain_bytes = -remain_bytes
380
+ if remain_bytes + len(self._buffer) > self._max_buffer_size:
381
+ raise BufferFull
382
+ while remain_bytes > 0:
383
+ to_read_bytes = max(self._read_size, remain_bytes)
384
+ read_data = self.file_like.read(to_read_bytes)
385
+ if not read_data:
386
+ break
387
+ assert isinstance(read_data, bytes)
388
+ self._buffer += read_data
389
+ remain_bytes -= len(read_data)
390
+
391
+ if len(self._buffer) < n + self._buff_i and raise_outofdata:
392
+ self._buff_i = 0 # rollback
393
+ raise OutOfData
394
+
395
+ def _read_header(self):
396
+ typ = TYPE_IMMEDIATE
397
+ n = 0
398
+ obj = None
399
+ self._reserve(1)
400
+ b = self._buffer[self._buff_i]
401
+ self._buff_i += 1
402
+ if b & 0b10000000 == 0:
403
+ obj = b
404
+ elif b & 0b11100000 == 0b11100000:
405
+ obj = -1 - (b ^ 0xFF)
406
+ elif b & 0b11100000 == 0b10100000:
407
+ n = b & 0b00011111
408
+ typ = TYPE_RAW
409
+ if n > self._max_str_len:
410
+ raise ValueError(f"{n} exceeds max_str_len({self._max_str_len})")
411
+ obj = self._read(n)
412
+ elif b & 0b11110000 == 0b10010000:
413
+ n = b & 0b00001111
414
+ typ = TYPE_ARRAY
415
+ if n > self._max_array_len:
416
+ raise ValueError(f"{n} exceeds max_array_len({self._max_array_len})")
417
+ elif b & 0b11110000 == 0b10000000:
418
+ n = b & 0b00001111
419
+ typ = TYPE_MAP
420
+ if n > self._max_map_len:
421
+ raise ValueError(f"{n} exceeds max_map_len({self._max_map_len})")
422
+ elif b == 0xC0:
423
+ obj = None
424
+ elif b == 0xC2:
425
+ obj = False
426
+ elif b == 0xC3:
427
+ obj = True
428
+ elif 0xC4 <= b <= 0xC6:
429
+ size, fmt, typ = _MSGPACK_HEADERS[b]
430
+ self._reserve(size)
431
+ if len(fmt) > 0:
432
+ n = struct.unpack_from(fmt, self._buffer, self._buff_i)[0]
433
+ else:
434
+ n = self._buffer[self._buff_i]
435
+ self._buff_i += size
436
+ if n > self._max_bin_len:
437
+ raise ValueError(f"{n} exceeds max_bin_len({self._max_bin_len})")
438
+ obj = self._read(n)
439
+ elif 0xC7 <= b <= 0xC9:
440
+ size, fmt, typ = _MSGPACK_HEADERS[b]
441
+ self._reserve(size)
442
+ L, n = struct.unpack_from(fmt, self._buffer, self._buff_i)
443
+ self._buff_i += size
444
+ if L > self._max_ext_len:
445
+ raise ValueError(f"{L} exceeds max_ext_len({self._max_ext_len})")
446
+ obj = self._read(L)
447
+ elif 0xCA <= b <= 0xD3:
448
+ size, fmt = _MSGPACK_HEADERS[b]
449
+ self._reserve(size)
450
+ if len(fmt) > 0:
451
+ obj = struct.unpack_from(fmt, self._buffer, self._buff_i)[0]
452
+ else:
453
+ obj = self._buffer[self._buff_i]
454
+ self._buff_i += size
455
+ elif 0xD4 <= b <= 0xD8:
456
+ size, fmt, typ = _MSGPACK_HEADERS[b]
457
+ if self._max_ext_len < size:
458
+ raise ValueError(f"{size} exceeds max_ext_len({self._max_ext_len})")
459
+ self._reserve(size + 1)
460
+ n, obj = struct.unpack_from(fmt, self._buffer, self._buff_i)
461
+ self._buff_i += size + 1
462
+ elif 0xD9 <= b <= 0xDB:
463
+ size, fmt, typ = _MSGPACK_HEADERS[b]
464
+ self._reserve(size)
465
+ if len(fmt) > 0:
466
+ (n,) = struct.unpack_from(fmt, self._buffer, self._buff_i)
467
+ else:
468
+ n = self._buffer[self._buff_i]
469
+ self._buff_i += size
470
+ if n > self._max_str_len:
471
+ raise ValueError(f"{n} exceeds max_str_len({self._max_str_len})")
472
+ obj = self._read(n)
473
+ elif 0xDC <= b <= 0xDD:
474
+ size, fmt, typ = _MSGPACK_HEADERS[b]
475
+ self._reserve(size)
476
+ (n,) = struct.unpack_from(fmt, self._buffer, self._buff_i)
477
+ self._buff_i += size
478
+ if n > self._max_array_len:
479
+ raise ValueError(f"{n} exceeds max_array_len({self._max_array_len})")
480
+ elif 0xDE <= b <= 0xDF:
481
+ size, fmt, typ = _MSGPACK_HEADERS[b]
482
+ self._reserve(size)
483
+ (n,) = struct.unpack_from(fmt, self._buffer, self._buff_i)
484
+ self._buff_i += size
485
+ if n > self._max_map_len:
486
+ raise ValueError(f"{n} exceeds max_map_len({self._max_map_len})")
487
+ else:
488
+ raise FormatError("Unknown header: 0x%x" % b)
489
+ return typ, n, obj
490
+
491
+ def _unpack(self, execute=EX_CONSTRUCT):
492
+ typ, n, obj = self._read_header()
493
+
494
+ if execute == EX_READ_ARRAY_HEADER:
495
+ if typ != TYPE_ARRAY:
496
+ raise ValueError("Expected array")
497
+ return n
498
+ if execute == EX_READ_MAP_HEADER:
499
+ if typ != TYPE_MAP:
500
+ raise ValueError("Expected map")
501
+ return n
502
+ # TODO should we eliminate the recursion?
503
+ if typ == TYPE_ARRAY:
504
+ if execute == EX_SKIP:
505
+ for i in range(n):
506
+ # TODO check whether we need to call `list_hook`
507
+ self._unpack(EX_SKIP)
508
+ return
509
+ ret = newlist_hint(n)
510
+ for i in range(n):
511
+ ret.append(self._unpack(EX_CONSTRUCT))
512
+ if self._list_hook is not None:
513
+ ret = self._list_hook(ret)
514
+ # TODO is the interaction between `list_hook` and `use_list` ok?
515
+ return ret if self._use_list else tuple(ret)
516
+ if typ == TYPE_MAP:
517
+ if execute == EX_SKIP:
518
+ for i in range(n):
519
+ # TODO check whether we need to call hooks
520
+ self._unpack(EX_SKIP)
521
+ self._unpack(EX_SKIP)
522
+ return
523
+ if self._object_pairs_hook is not None:
524
+ ret = self._object_pairs_hook(
525
+ (self._unpack(EX_CONSTRUCT), self._unpack(EX_CONSTRUCT)) for _ in range(n)
526
+ )
527
+ else:
528
+ ret = {}
529
+ for _ in range(n):
530
+ key = self._unpack(EX_CONSTRUCT)
531
+ if self._strict_map_key and type(key) not in (str, bytes):
532
+ raise ValueError("%s is not allowed for map key" % str(type(key)))
533
+ if isinstance(key, str):
534
+ key = sys.intern(key)
535
+ ret[key] = self._unpack(EX_CONSTRUCT)
536
+ if self._object_hook is not None:
537
+ ret = self._object_hook(ret)
538
+ return ret
539
+ if execute == EX_SKIP:
540
+ return
541
+ if typ == TYPE_RAW:
542
+ if self._raw:
543
+ obj = bytes(obj)
544
+ else:
545
+ obj = obj.decode("utf_8", self._unicode_errors)
546
+ return obj
547
+ if typ == TYPE_BIN:
548
+ return bytes(obj)
549
+ if typ == TYPE_EXT:
550
+ if n == -1: # timestamp
551
+ ts = Timestamp.from_bytes(bytes(obj))
552
+ if self._timestamp == 1:
553
+ return ts.to_unix()
554
+ elif self._timestamp == 2:
555
+ return ts.to_unix_nano()
556
+ elif self._timestamp == 3:
557
+ return ts.to_datetime()
558
+ else:
559
+ return ts
560
+ else:
561
+ return self._ext_hook(n, bytes(obj))
562
+ assert typ == TYPE_IMMEDIATE
563
+ return obj
564
+
565
+ def __iter__(self):
566
+ return self
567
+
568
+ def __next__(self):
569
+ try:
570
+ ret = self._unpack(EX_CONSTRUCT)
571
+ self._consume()
572
+ return ret
573
+ except OutOfData:
574
+ self._consume()
575
+ raise StopIteration
576
+ except RecursionError:
577
+ raise StackError
578
+
579
+ next = __next__
580
+
581
+ def skip(self):
582
+ self._unpack(EX_SKIP)
583
+ self._consume()
584
+
585
+ def unpack(self):
586
+ try:
587
+ ret = self._unpack(EX_CONSTRUCT)
588
+ except RecursionError:
589
+ raise StackError
590
+ self._consume()
591
+ return ret
592
+
593
+ def read_array_header(self):
594
+ ret = self._unpack(EX_READ_ARRAY_HEADER)
595
+ self._consume()
596
+ return ret
597
+
598
+ def read_map_header(self):
599
+ ret = self._unpack(EX_READ_MAP_HEADER)
600
+ self._consume()
601
+ return ret
602
+
603
+ def tell(self):
604
+ return self._stream_offset
605
+
606
+
607
+ class Packer:
608
+ """
609
+ MessagePack Packer
610
+
611
+ Usage::
612
+
613
+ packer = Packer()
614
+ astream.write(packer.pack(a))
615
+ astream.write(packer.pack(b))
616
+
617
+ Packer's constructor has some keyword arguments:
618
+
619
+ :param default:
620
+ When specified, it should be callable.
621
+ Convert user type to builtin type that Packer supports.
622
+ See also simplejson's document.
623
+
624
+ :param bool use_single_float:
625
+ Use single precision float type for float. (default: False)
626
+
627
+ :param bool autoreset:
628
+ Reset buffer after each pack and return its content as `bytes`. (default: True).
629
+ If set this to false, use `bytes()` to get content and `.reset()` to clear buffer.
630
+
631
+ :param bool use_bin_type:
632
+ Use bin type introduced in msgpack spec 2.0 for bytes.
633
+ It also enables str8 type for unicode. (default: True)
634
+
635
+ :param bool strict_types:
636
+ If set to true, types will be checked to be exact. Derived classes
637
+ from serializable types will not be serialized and will be
638
+ treated as unsupported type and forwarded to default.
639
+ Additionally tuples will not be serialized as lists.
640
+ This is useful when trying to implement accurate serialization
641
+ for python types.
642
+
643
+ :param bool datetime:
644
+ If set to true, datetime with tzinfo is packed into Timestamp type.
645
+ Note that the tzinfo is stripped in the timestamp.
646
+ You can get UTC datetime with `timestamp=3` option of the Unpacker.
647
+
648
+ :param str unicode_errors:
649
+ The error handler for encoding unicode. (default: 'strict')
650
+ DO NOT USE THIS!! This option is kept for very specific usage.
651
+
652
+ Example of streaming deserialize from file-like object::
653
+
654
+ unpacker = Unpacker(file_like)
655
+ for o in unpacker:
656
+ process(o)
657
+
658
+ Example of streaming deserialize from socket::
659
+
660
+ unpacker = Unpacker()
661
+ while True:
662
+ buf = sock.recv(1024**2)
663
+ if not buf:
664
+ break
665
+ unpacker.feed(buf)
666
+ for o in unpacker:
667
+ process(o)
668
+
669
+ Raises ``ExtraData`` when *packed* contains extra bytes.
670
+ Raises ``OutOfData`` when *packed* is incomplete.
671
+ Raises ``FormatError`` when *packed* is not valid msgpack.
672
+ Raises ``StackError`` when *packed* contains too nested.
673
+ Other exceptions can be raised during unpacking.
674
+ """
675
+
676
+ def __init__(
677
+ self,
678
+ default=None,
679
+ use_single_float=False,
680
+ autoreset=True,
681
+ use_bin_type=True,
682
+ strict_types=False,
683
+ datetime=False,
684
+ unicode_errors=None,
685
+ ):
686
+ self._strict_types = strict_types
687
+ self._use_float = use_single_float
688
+ self._autoreset = autoreset
689
+ self._use_bin_type = use_bin_type
690
+ self._buffer = StringIO()
691
+ self._datetime = bool(datetime)
692
+ self._unicode_errors = unicode_errors or "strict"
693
+ if default is not None:
694
+ if not callable(default):
695
+ raise TypeError("default must be callable")
696
+ self._default = default
697
+
698
+ def _pack(
699
+ self,
700
+ obj,
701
+ nest_limit=DEFAULT_RECURSE_LIMIT,
702
+ check=isinstance,
703
+ check_type_strict=_check_type_strict,
704
+ ):
705
+ default_used = False
706
+ if self._strict_types:
707
+ check = check_type_strict
708
+ list_types = list
709
+ else:
710
+ list_types = (list, tuple)
711
+ while True:
712
+ if nest_limit < 0:
713
+ raise ValueError("recursion limit exceeded")
714
+ if obj is None:
715
+ return self._buffer.write(b"\xc0")
716
+ if check(obj, bool):
717
+ if obj:
718
+ return self._buffer.write(b"\xc3")
719
+ return self._buffer.write(b"\xc2")
720
+ if check(obj, int):
721
+ if 0 <= obj < 0x80:
722
+ return self._buffer.write(struct.pack("B", obj))
723
+ if -0x20 <= obj < 0:
724
+ return self._buffer.write(struct.pack("b", obj))
725
+ if 0x80 <= obj <= 0xFF:
726
+ return self._buffer.write(struct.pack("BB", 0xCC, obj))
727
+ if -0x80 <= obj < 0:
728
+ return self._buffer.write(struct.pack(">Bb", 0xD0, obj))
729
+ if 0xFF < obj <= 0xFFFF:
730
+ return self._buffer.write(struct.pack(">BH", 0xCD, obj))
731
+ if -0x8000 <= obj < -0x80:
732
+ return self._buffer.write(struct.pack(">Bh", 0xD1, obj))
733
+ if 0xFFFF < obj <= 0xFFFFFFFF:
734
+ return self._buffer.write(struct.pack(">BI", 0xCE, obj))
735
+ if -0x80000000 <= obj < -0x8000:
736
+ return self._buffer.write(struct.pack(">Bi", 0xD2, obj))
737
+ if 0xFFFFFFFF < obj <= 0xFFFFFFFFFFFFFFFF:
738
+ return self._buffer.write(struct.pack(">BQ", 0xCF, obj))
739
+ if -0x8000000000000000 <= obj < -0x80000000:
740
+ return self._buffer.write(struct.pack(">Bq", 0xD3, obj))
741
+ if not default_used and self._default is not None:
742
+ obj = self._default(obj)
743
+ default_used = True
744
+ continue
745
+ raise OverflowError("Integer value out of range")
746
+ if check(obj, (bytes, bytearray)):
747
+ n = len(obj)
748
+ if n >= 2**32:
749
+ raise ValueError("%s is too large" % type(obj).__name__)
750
+ self._pack_bin_header(n)
751
+ return self._buffer.write(obj)
752
+ if check(obj, str):
753
+ obj = obj.encode("utf-8", self._unicode_errors)
754
+ n = len(obj)
755
+ if n >= 2**32:
756
+ raise ValueError("String is too large")
757
+ self._pack_raw_header(n)
758
+ return self._buffer.write(obj)
759
+ if check(obj, memoryview):
760
+ n = obj.nbytes
761
+ if n >= 2**32:
762
+ raise ValueError("Memoryview is too large")
763
+ self._pack_bin_header(n)
764
+ return self._buffer.write(obj)
765
+ if check(obj, float):
766
+ if self._use_float:
767
+ return self._buffer.write(struct.pack(">Bf", 0xCA, obj))
768
+ return self._buffer.write(struct.pack(">Bd", 0xCB, obj))
769
+ if check(obj, (ExtType, Timestamp)):
770
+ if check(obj, Timestamp):
771
+ code = -1
772
+ data = obj.to_bytes()
773
+ else:
774
+ code = obj.code
775
+ data = obj.data
776
+ assert isinstance(code, int)
777
+ assert isinstance(data, bytes)
778
+ L = len(data)
779
+ if L == 1:
780
+ self._buffer.write(b"\xd4")
781
+ elif L == 2:
782
+ self._buffer.write(b"\xd5")
783
+ elif L == 4:
784
+ self._buffer.write(b"\xd6")
785
+ elif L == 8:
786
+ self._buffer.write(b"\xd7")
787
+ elif L == 16:
788
+ self._buffer.write(b"\xd8")
789
+ elif L <= 0xFF:
790
+ self._buffer.write(struct.pack(">BB", 0xC7, L))
791
+ elif L <= 0xFFFF:
792
+ self._buffer.write(struct.pack(">BH", 0xC8, L))
793
+ else:
794
+ self._buffer.write(struct.pack(">BI", 0xC9, L))
795
+ self._buffer.write(struct.pack("b", code))
796
+ self._buffer.write(data)
797
+ return
798
+ if check(obj, list_types):
799
+ n = len(obj)
800
+ self._pack_array_header(n)
801
+ for i in range(n):
802
+ self._pack(obj[i], nest_limit - 1)
803
+ return
804
+ if check(obj, dict):
805
+ return self._pack_map_pairs(len(obj), obj.items(), nest_limit - 1)
806
+
807
+ if self._datetime and check(obj, _DateTime) and obj.tzinfo is not None:
808
+ obj = Timestamp.from_datetime(obj)
809
+ default_used = 1
810
+ continue
811
+
812
+ if not default_used and self._default is not None:
813
+ obj = self._default(obj)
814
+ default_used = 1
815
+ continue
816
+
817
+ if self._datetime and check(obj, _DateTime):
818
+ raise ValueError(f"Cannot serialize {obj!r} where tzinfo=None")
819
+
820
+ raise TypeError(f"Cannot serialize {obj!r}")
821
+
822
+ def pack(self, obj):
823
+ try:
824
+ self._pack(obj)
825
+ except:
826
+ self._buffer = StringIO() # force reset
827
+ raise
828
+ if self._autoreset:
829
+ ret = self._buffer.getvalue()
830
+ self._buffer = StringIO()
831
+ return ret
832
+
833
+ def pack_map_pairs(self, pairs):
834
+ self._pack_map_pairs(len(pairs), pairs)
835
+ if self._autoreset:
836
+ ret = self._buffer.getvalue()
837
+ self._buffer = StringIO()
838
+ return ret
839
+
840
+ def pack_array_header(self, n):
841
+ if n >= 2**32:
842
+ raise ValueError
843
+ self._pack_array_header(n)
844
+ if self._autoreset:
845
+ ret = self._buffer.getvalue()
846
+ self._buffer = StringIO()
847
+ return ret
848
+
849
+ def pack_map_header(self, n):
850
+ if n >= 2**32:
851
+ raise ValueError
852
+ self._pack_map_header(n)
853
+ if self._autoreset:
854
+ ret = self._buffer.getvalue()
855
+ self._buffer = StringIO()
856
+ return ret
857
+
858
+ def pack_ext_type(self, typecode, data):
859
+ if not isinstance(typecode, int):
860
+ raise TypeError("typecode must have int type.")
861
+ if not 0 <= typecode <= 127:
862
+ raise ValueError("typecode should be 0-127")
863
+ if not isinstance(data, bytes):
864
+ raise TypeError("data must have bytes type")
865
+ L = len(data)
866
+ if L > 0xFFFFFFFF:
867
+ raise ValueError("Too large data")
868
+ if L == 1:
869
+ self._buffer.write(b"\xd4")
870
+ elif L == 2:
871
+ self._buffer.write(b"\xd5")
872
+ elif L == 4:
873
+ self._buffer.write(b"\xd6")
874
+ elif L == 8:
875
+ self._buffer.write(b"\xd7")
876
+ elif L == 16:
877
+ self._buffer.write(b"\xd8")
878
+ elif L <= 0xFF:
879
+ self._buffer.write(b"\xc7" + struct.pack("B", L))
880
+ elif L <= 0xFFFF:
881
+ self._buffer.write(b"\xc8" + struct.pack(">H", L))
882
+ else:
883
+ self._buffer.write(b"\xc9" + struct.pack(">I", L))
884
+ self._buffer.write(struct.pack("B", typecode))
885
+ self._buffer.write(data)
886
+
887
+ def _pack_array_header(self, n):
888
+ if n <= 0x0F:
889
+ return self._buffer.write(struct.pack("B", 0x90 + n))
890
+ if n <= 0xFFFF:
891
+ return self._buffer.write(struct.pack(">BH", 0xDC, n))
892
+ if n <= 0xFFFFFFFF:
893
+ return self._buffer.write(struct.pack(">BI", 0xDD, n))
894
+ raise ValueError("Array is too large")
895
+
896
+ def _pack_map_header(self, n):
897
+ if n <= 0x0F:
898
+ return self._buffer.write(struct.pack("B", 0x80 + n))
899
+ if n <= 0xFFFF:
900
+ return self._buffer.write(struct.pack(">BH", 0xDE, n))
901
+ if n <= 0xFFFFFFFF:
902
+ return self._buffer.write(struct.pack(">BI", 0xDF, n))
903
+ raise ValueError("Dict is too large")
904
+
905
+ def _pack_map_pairs(self, n, pairs, nest_limit=DEFAULT_RECURSE_LIMIT):
906
+ self._pack_map_header(n)
907
+ for k, v in pairs:
908
+ self._pack(k, nest_limit - 1)
909
+ self._pack(v, nest_limit - 1)
910
+
911
+ def _pack_raw_header(self, n):
912
+ if n <= 0x1F:
913
+ self._buffer.write(struct.pack("B", 0xA0 + n))
914
+ elif self._use_bin_type and n <= 0xFF:
915
+ self._buffer.write(struct.pack(">BB", 0xD9, n))
916
+ elif n <= 0xFFFF:
917
+ self._buffer.write(struct.pack(">BH", 0xDA, n))
918
+ elif n <= 0xFFFFFFFF:
919
+ self._buffer.write(struct.pack(">BI", 0xDB, n))
920
+ else:
921
+ raise ValueError("Raw is too large")
922
+
923
+ def _pack_bin_header(self, n):
924
+ if not self._use_bin_type:
925
+ return self._pack_raw_header(n)
926
+ elif n <= 0xFF:
927
+ return self._buffer.write(struct.pack(">BB", 0xC4, n))
928
+ elif n <= 0xFFFF:
929
+ return self._buffer.write(struct.pack(">BH", 0xC5, n))
930
+ elif n <= 0xFFFFFFFF:
931
+ return self._buffer.write(struct.pack(">BI", 0xC6, n))
932
+ else:
933
+ raise ValueError("Bin is too large")
934
+
935
+ def bytes(self):
936
+ """Return internal buffer contents as bytes object"""
937
+ return self._buffer.getvalue()
938
+
939
+ def reset(self):
940
+ """Reset internal buffer.
941
+
942
+ This method is useful only when autoreset=False.
943
+ """
944
+ self._buffer = StringIO()
945
+
946
+ def getbuffer(self):
947
+ """Return view of internal buffer."""
948
+ if USING_STRINGBUILDER:
949
+ return memoryview(self.bytes())
950
+ else:
951
+ return self._buffer.getbuffer()