kafka-python 3.0.0__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 (373) hide show
  1. kafka/__init__.py +34 -0
  2. kafka/__main__.py +5 -0
  3. kafka/admin/__init__.py +29 -0
  4. kafka/admin/__main__.py +5 -0
  5. kafka/admin/_acls.py +355 -0
  6. kafka/admin/_cluster.py +359 -0
  7. kafka/admin/_configs.py +479 -0
  8. kafka/admin/_groups.py +754 -0
  9. kafka/admin/_partitions.py +595 -0
  10. kafka/admin/_topics.py +281 -0
  11. kafka/admin/_transactions.py +450 -0
  12. kafka/admin/_users.py +194 -0
  13. kafka/admin/client.py +373 -0
  14. kafka/benchmarks/__init__.py +0 -0
  15. kafka/benchmarks/consumer_performance.py +138 -0
  16. kafka/benchmarks/load_example.py +109 -0
  17. kafka/benchmarks/producer_encode_path.py +201 -0
  18. kafka/benchmarks/producer_performance.py +161 -0
  19. kafka/benchmarks/profile_protocol.py +138 -0
  20. kafka/benchmarks/protocol_old_vs_new.py +447 -0
  21. kafka/benchmarks/record_batch_compose.py +77 -0
  22. kafka/benchmarks/record_batch_read.py +82 -0
  23. kafka/benchmarks/varint_speed.py +426 -0
  24. kafka/cli/__init__.py +36 -0
  25. kafka/cli/admin/__init__.py +117 -0
  26. kafka/cli/admin/acls/__init__.py +9 -0
  27. kafka/cli/admin/acls/common.py +76 -0
  28. kafka/cli/admin/acls/create.py +19 -0
  29. kafka/cli/admin/acls/delete.py +23 -0
  30. kafka/cli/admin/acls/describe.py +16 -0
  31. kafka/cli/admin/cluster/__init__.py +14 -0
  32. kafka/cli/admin/cluster/describe.py +11 -0
  33. kafka/cli/admin/cluster/describe_quorum.py +11 -0
  34. kafka/cli/admin/cluster/features.py +52 -0
  35. kafka/cli/admin/cluster/log_dirs.py +43 -0
  36. kafka/cli/admin/cluster/versions.py +33 -0
  37. kafka/cli/admin/configs/__init__.py +10 -0
  38. kafka/cli/admin/configs/alter.py +43 -0
  39. kafka/cli/admin/configs/common.py +17 -0
  40. kafka/cli/admin/configs/describe.py +30 -0
  41. kafka/cli/admin/configs/list.py +16 -0
  42. kafka/cli/admin/configs/reset.py +20 -0
  43. kafka/cli/admin/groups/__init__.py +16 -0
  44. kafka/cli/admin/groups/alter_offsets.py +30 -0
  45. kafka/cli/admin/groups/delete.py +11 -0
  46. kafka/cli/admin/groups/delete_offsets.py +29 -0
  47. kafka/cli/admin/groups/describe.py +11 -0
  48. kafka/cli/admin/groups/list.py +28 -0
  49. kafka/cli/admin/groups/list_offsets.py +29 -0
  50. kafka/cli/admin/groups/remove_members.py +40 -0
  51. kafka/cli/admin/groups/reset_offsets.py +139 -0
  52. kafka/cli/admin/partitions/__init__.py +21 -0
  53. kafka/cli/admin/partitions/alter_reassignments.py +37 -0
  54. kafka/cli/admin/partitions/create.py +27 -0
  55. kafka/cli/admin/partitions/delete_records.py +31 -0
  56. kafka/cli/admin/partitions/describe.py +36 -0
  57. kafka/cli/admin/partitions/elect_leaders.py +53 -0
  58. kafka/cli/admin/partitions/list_offsets.py +88 -0
  59. kafka/cli/admin/partitions/list_reassignments.py +35 -0
  60. kafka/cli/admin/topics/__init__.py +10 -0
  61. kafka/cli/admin/topics/create.py +13 -0
  62. kafka/cli/admin/topics/delete.py +19 -0
  63. kafka/cli/admin/topics/describe.py +18 -0
  64. kafka/cli/admin/topics/list.py +11 -0
  65. kafka/cli/admin/transactions/__init__.py +17 -0
  66. kafka/cli/admin/transactions/abort.py +38 -0
  67. kafka/cli/admin/transactions/describe.py +24 -0
  68. kafka/cli/admin/transactions/describe_producers.py +29 -0
  69. kafka/cli/admin/transactions/find_hanging.py +26 -0
  70. kafka/cli/admin/transactions/list.py +37 -0
  71. kafka/cli/admin/users/__init__.py +8 -0
  72. kafka/cli/admin/users/alter_user_scram_credentials.py +34 -0
  73. kafka/cli/admin/users/describe_user_scram_credentials.py +15 -0
  74. kafka/cli/common.py +95 -0
  75. kafka/cli/consumer/__init__.py +63 -0
  76. kafka/cli/producer/__init__.py +57 -0
  77. kafka/cluster.py +824 -0
  78. kafka/codec.py +325 -0
  79. kafka/consumer/__init__.py +5 -0
  80. kafka/consumer/__main__.py +5 -0
  81. kafka/consumer/fetcher.py +2012 -0
  82. kafka/consumer/group.py +1347 -0
  83. kafka/consumer/subscription_state.py +897 -0
  84. kafka/coordinator/__init__.py +0 -0
  85. kafka/coordinator/assignors/__init__.py +0 -0
  86. kafka/coordinator/assignors/abstract.py +90 -0
  87. kafka/coordinator/assignors/cooperative_sticky.py +167 -0
  88. kafka/coordinator/assignors/range.py +81 -0
  89. kafka/coordinator/assignors/roundrobin.py +101 -0
  90. kafka/coordinator/assignors/sticky/StickyAssignorUserData.json +37 -0
  91. kafka/coordinator/assignors/sticky/__init__.py +0 -0
  92. kafka/coordinator/assignors/sticky/partition_movements.py +149 -0
  93. kafka/coordinator/assignors/sticky/sorted_set.py +63 -0
  94. kafka/coordinator/assignors/sticky/sticky_assignor.py +665 -0
  95. kafka/coordinator/assignors/sticky/user_data.py +8 -0
  96. kafka/coordinator/base.py +1215 -0
  97. kafka/coordinator/consumer.py +1224 -0
  98. kafka/coordinator/heartbeat.py +82 -0
  99. kafka/coordinator/subscription.py +34 -0
  100. kafka/errors.py +1004 -0
  101. kafka/future.py +166 -0
  102. kafka/metrics/__init__.py +13 -0
  103. kafka/metrics/compound_stat.py +33 -0
  104. kafka/metrics/dict_reporter.py +81 -0
  105. kafka/metrics/kafka_metric.py +36 -0
  106. kafka/metrics/measurable.py +27 -0
  107. kafka/metrics/measurable_stat.py +13 -0
  108. kafka/metrics/metric_config.py +33 -0
  109. kafka/metrics/metric_name.py +105 -0
  110. kafka/metrics/metrics.py +261 -0
  111. kafka/metrics/metrics_reporter.py +53 -0
  112. kafka/metrics/quota.py +41 -0
  113. kafka/metrics/stat.py +19 -0
  114. kafka/metrics/stats/__init__.py +15 -0
  115. kafka/metrics/stats/avg.py +24 -0
  116. kafka/metrics/stats/count.py +17 -0
  117. kafka/metrics/stats/histogram.py +99 -0
  118. kafka/metrics/stats/max_stat.py +17 -0
  119. kafka/metrics/stats/min_stat.py +19 -0
  120. kafka/metrics/stats/percentile.py +14 -0
  121. kafka/metrics/stats/percentiles.py +75 -0
  122. kafka/metrics/stats/rate.py +118 -0
  123. kafka/metrics/stats/sampled_stat.py +99 -0
  124. kafka/metrics/stats/sensor.py +136 -0
  125. kafka/metrics/stats/total.py +15 -0
  126. kafka/net/__init__.py +19 -0
  127. kafka/net/compat.py +165 -0
  128. kafka/net/connection.py +593 -0
  129. kafka/net/http_connect.py +144 -0
  130. kafka/net/inet.py +122 -0
  131. kafka/net/manager.py +451 -0
  132. kafka/net/metrics.py +149 -0
  133. kafka/net/sasl/__init__.py +32 -0
  134. kafka/net/sasl/abc.py +28 -0
  135. kafka/net/sasl/gssapi.py +95 -0
  136. kafka/net/sasl/msk.py +245 -0
  137. kafka/net/sasl/oauth.py +98 -0
  138. kafka/net/sasl/plain.py +42 -0
  139. kafka/net/sasl/scram.py +135 -0
  140. kafka/net/sasl/sspi.py +111 -0
  141. kafka/net/selector.py +644 -0
  142. kafka/net/socks5.py +262 -0
  143. kafka/net/transport.py +415 -0
  144. kafka/net/wakeup_notifier.py +72 -0
  145. kafka/partitioner/__init__.py +8 -0
  146. kafka/partitioner/abc.py +8 -0
  147. kafka/partitioner/default.py +89 -0
  148. kafka/partitioner/sticky.py +109 -0
  149. kafka/producer/__init__.py +5 -0
  150. kafka/producer/__main__.py +5 -0
  151. kafka/producer/future.py +101 -0
  152. kafka/producer/kafka.py +1123 -0
  153. kafka/producer/producer_batch.py +192 -0
  154. kafka/producer/record_accumulator.py +647 -0
  155. kafka/producer/sender.py +884 -0
  156. kafka/producer/transaction_manager.py +1326 -0
  157. kafka/protocol/__init__.py +0 -0
  158. kafka/protocol/admin/__init__.py +29 -0
  159. kafka/protocol/admin/acl.py +83 -0
  160. kafka/protocol/admin/acl.pyi +375 -0
  161. kafka/protocol/admin/client_quotas.py +14 -0
  162. kafka/protocol/admin/client_quotas.pyi +265 -0
  163. kafka/protocol/admin/cluster.py +31 -0
  164. kafka/protocol/admin/cluster.pyi +620 -0
  165. kafka/protocol/admin/configs.py +22 -0
  166. kafka/protocol/admin/configs.pyi +437 -0
  167. kafka/protocol/admin/groups.py +24 -0
  168. kafka/protocol/admin/groups.pyi +261 -0
  169. kafka/protocol/admin/topics.py +53 -0
  170. kafka/protocol/admin/topics.pyi +982 -0
  171. kafka/protocol/admin/transactions.py +18 -0
  172. kafka/protocol/admin/transactions.pyi +311 -0
  173. kafka/protocol/admin/users.py +14 -0
  174. kafka/protocol/admin/users.pyi +223 -0
  175. kafka/protocol/api_data.py +125 -0
  176. kafka/protocol/api_header.py +55 -0
  177. kafka/protocol/api_key.py +97 -0
  178. kafka/protocol/api_message.py +277 -0
  179. kafka/protocol/broker_version_data.py +246 -0
  180. kafka/protocol/consumer/__init__.py +13 -0
  181. kafka/protocol/consumer/fetch.py +16 -0
  182. kafka/protocol/consumer/fetch.pyi +298 -0
  183. kafka/protocol/consumer/group.py +38 -0
  184. kafka/protocol/consumer/group.pyi +824 -0
  185. kafka/protocol/consumer/metadata.py +30 -0
  186. kafka/protocol/consumer/metadata.pyi +89 -0
  187. kafka/protocol/consumer/offsets.py +75 -0
  188. kafka/protocol/consumer/offsets.pyi +288 -0
  189. kafka/protocol/data_container.py +166 -0
  190. kafka/protocol/frame.py +30 -0
  191. kafka/protocol/generate_stubs.py +468 -0
  192. kafka/protocol/metadata/__init__.py +10 -0
  193. kafka/protocol/metadata/api_versions.py +41 -0
  194. kafka/protocol/metadata/api_versions.pyi +128 -0
  195. kafka/protocol/metadata/find_coordinator.py +19 -0
  196. kafka/protocol/metadata/find_coordinator.pyi +105 -0
  197. kafka/protocol/metadata/metadata.py +34 -0
  198. kafka/protocol/metadata/metadata.pyi +160 -0
  199. kafka/protocol/old/__init__.py +0 -0
  200. kafka/protocol/old/abstract.py +17 -0
  201. kafka/protocol/old/add_offsets_to_txn.py +54 -0
  202. kafka/protocol/old/add_partitions_to_txn.py +71 -0
  203. kafka/protocol/old/admin.py +1086 -0
  204. kafka/protocol/old/api.py +205 -0
  205. kafka/protocol/old/api_versions.py +133 -0
  206. kafka/protocol/old/commit.py +355 -0
  207. kafka/protocol/old/consumer_protocol.py +36 -0
  208. kafka/protocol/old/end_txn.py +53 -0
  209. kafka/protocol/old/fetch.py +408 -0
  210. kafka/protocol/old/find_coordinator.py +72 -0
  211. kafka/protocol/old/group.py +451 -0
  212. kafka/protocol/old/init_producer_id.py +42 -0
  213. kafka/protocol/old/list_offsets.py +186 -0
  214. kafka/protocol/old/metadata.py +290 -0
  215. kafka/protocol/old/offset_for_leader_epoch.py +133 -0
  216. kafka/protocol/old/produce.py +247 -0
  217. kafka/protocol/old/sasl_authenticate.py +38 -0
  218. kafka/protocol/old/sasl_handshake.py +39 -0
  219. kafka/protocol/old/struct.py +87 -0
  220. kafka/protocol/old/txn_offset_commit.py +73 -0
  221. kafka/protocol/old/types.py +440 -0
  222. kafka/protocol/parser.py +191 -0
  223. kafka/protocol/producer/__init__.py +7 -0
  224. kafka/protocol/producer/produce.py +17 -0
  225. kafka/protocol/producer/produce.pyi +197 -0
  226. kafka/protocol/producer/transaction.py +30 -0
  227. kafka/protocol/producer/transaction.pyi +663 -0
  228. kafka/protocol/sasl.py +52 -0
  229. kafka/protocol/sasl.pyi +126 -0
  230. kafka/protocol/schemas/__init__.py +7 -0
  231. kafka/protocol/schemas/fields/__init__.py +7 -0
  232. kafka/protocol/schemas/fields/array.py +127 -0
  233. kafka/protocol/schemas/fields/base.py +156 -0
  234. kafka/protocol/schemas/fields/codecs/__init__.py +12 -0
  235. kafka/protocol/schemas/fields/codecs/encode_buffer.py +82 -0
  236. kafka/protocol/schemas/fields/codecs/tagged_fields.py +109 -0
  237. kafka/protocol/schemas/fields/codecs/types.py +505 -0
  238. kafka/protocol/schemas/fields/codegen.py +40 -0
  239. kafka/protocol/schemas/fields/simple.py +127 -0
  240. kafka/protocol/schemas/fields/struct.py +357 -0
  241. kafka/protocol/schemas/fields/struct_array.py +142 -0
  242. kafka/protocol/schemas/load_json.py +42 -0
  243. kafka/protocol/schemas/resources/AddOffsetsToTxnRequest.json +40 -0
  244. kafka/protocol/schemas/resources/AddOffsetsToTxnResponse.json +35 -0
  245. kafka/protocol/schemas/resources/AddPartitionsToTxnRequest.json +65 -0
  246. kafka/protocol/schemas/resources/AddPartitionsToTxnResponse.json +60 -0
  247. kafka/protocol/schemas/resources/AlterClientQuotasRequest.json +47 -0
  248. kafka/protocol/schemas/resources/AlterClientQuotasResponse.json +41 -0
  249. kafka/protocol/schemas/resources/AlterConfigsRequest.json +43 -0
  250. kafka/protocol/schemas/resources/AlterConfigsResponse.json +39 -0
  251. kafka/protocol/schemas/resources/AlterPartitionReassignmentsRequest.json +42 -0
  252. kafka/protocol/schemas/resources/AlterPartitionReassignmentsResponse.json +47 -0
  253. kafka/protocol/schemas/resources/AlterReplicaLogDirsRequest.json +41 -0
  254. kafka/protocol/schemas/resources/AlterReplicaLogDirsResponse.json +41 -0
  255. kafka/protocol/schemas/resources/AlterUserScramCredentialsRequest.json +45 -0
  256. kafka/protocol/schemas/resources/AlterUserScramCredentialsResponse.json +35 -0
  257. kafka/protocol/schemas/resources/ApiVersionsRequest.json +34 -0
  258. kafka/protocol/schemas/resources/ApiVersionsResponse.json +79 -0
  259. kafka/protocol/schemas/resources/ConsumerProtocolAssignment.json +42 -0
  260. kafka/protocol/schemas/resources/ConsumerProtocolSubscription.json +49 -0
  261. kafka/protocol/schemas/resources/CreateAclsRequest.json +46 -0
  262. kafka/protocol/schemas/resources/CreateAclsResponse.json +37 -0
  263. kafka/protocol/schemas/resources/CreatePartitionsRequest.json +47 -0
  264. kafka/protocol/schemas/resources/CreatePartitionsResponse.json +41 -0
  265. kafka/protocol/schemas/resources/CreateTopicsRequest.json +65 -0
  266. kafka/protocol/schemas/resources/CreateTopicsResponse.json +72 -0
  267. kafka/protocol/schemas/resources/DeleteAclsRequest.json +46 -0
  268. kafka/protocol/schemas/resources/DeleteAclsResponse.json +59 -0
  269. kafka/protocol/schemas/resources/DeleteGroupsRequest.json +30 -0
  270. kafka/protocol/schemas/resources/DeleteGroupsResponse.json +36 -0
  271. kafka/protocol/schemas/resources/DeleteRecordsRequest.json +42 -0
  272. kafka/protocol/schemas/resources/DeleteRecordsResponse.json +43 -0
  273. kafka/protocol/schemas/resources/DeleteTopicsRequest.json +43 -0
  274. kafka/protocol/schemas/resources/DeleteTopicsResponse.json +52 -0
  275. kafka/protocol/schemas/resources/DescribeAclsRequest.json +43 -0
  276. kafka/protocol/schemas/resources/DescribeAclsResponse.json +55 -0
  277. kafka/protocol/schemas/resources/DescribeClientQuotasRequest.json +37 -0
  278. kafka/protocol/schemas/resources/DescribeClientQuotasResponse.json +47 -0
  279. kafka/protocol/schemas/resources/DescribeClusterRequest.json +35 -0
  280. kafka/protocol/schemas/resources/DescribeClusterResponse.json +56 -0
  281. kafka/protocol/schemas/resources/DescribeConfigsRequest.json +42 -0
  282. kafka/protocol/schemas/resources/DescribeConfigsResponse.json +69 -0
  283. kafka/protocol/schemas/resources/DescribeGroupsRequest.json +38 -0
  284. kafka/protocol/schemas/resources/DescribeGroupsResponse.json +74 -0
  285. kafka/protocol/schemas/resources/DescribeLogDirsRequest.json +38 -0
  286. kafka/protocol/schemas/resources/DescribeLogDirsResponse.json +65 -0
  287. kafka/protocol/schemas/resources/DescribeProducersRequest.json +32 -0
  288. kafka/protocol/schemas/resources/DescribeProducersResponse.json +55 -0
  289. kafka/protocol/schemas/resources/DescribeQuorumRequest.json +39 -0
  290. kafka/protocol/schemas/resources/DescribeQuorumResponse.json +82 -0
  291. kafka/protocol/schemas/resources/DescribeTopicPartitionsRequest.json +40 -0
  292. kafka/protocol/schemas/resources/DescribeTopicPartitionsResponse.json +66 -0
  293. kafka/protocol/schemas/resources/DescribeTransactionsRequest.json +27 -0
  294. kafka/protocol/schemas/resources/DescribeTransactionsResponse.json +52 -0
  295. kafka/protocol/schemas/resources/DescribeUserScramCredentialsRequest.json +30 -0
  296. kafka/protocol/schemas/resources/DescribeUserScramCredentialsResponse.json +45 -0
  297. kafka/protocol/schemas/resources/ElectLeadersRequest.json +41 -0
  298. kafka/protocol/schemas/resources/ElectLeadersResponse.json +45 -0
  299. kafka/protocol/schemas/resources/EndTxnRequest.json +43 -0
  300. kafka/protocol/schemas/resources/EndTxnResponse.json +41 -0
  301. kafka/protocol/schemas/resources/FetchRequest.json +125 -0
  302. kafka/protocol/schemas/resources/FetchResponse.json +124 -0
  303. kafka/protocol/schemas/resources/FindCoordinatorRequest.json +43 -0
  304. kafka/protocol/schemas/resources/FindCoordinatorResponse.json +58 -0
  305. kafka/protocol/schemas/resources/HeartbeatRequest.json +39 -0
  306. kafka/protocol/schemas/resources/HeartbeatResponse.json +35 -0
  307. kafka/protocol/schemas/resources/IncrementalAlterConfigsRequest.json +44 -0
  308. kafka/protocol/schemas/resources/IncrementalAlterConfigsResponse.json +38 -0
  309. kafka/protocol/schemas/resources/InitProducerIdRequest.json +50 -0
  310. kafka/protocol/schemas/resources/InitProducerIdResponse.json +47 -0
  311. kafka/protocol/schemas/resources/JoinGroupRequest.json +63 -0
  312. kafka/protocol/schemas/resources/JoinGroupResponse.json +69 -0
  313. kafka/protocol/schemas/resources/LeaveGroupRequest.json +47 -0
  314. kafka/protocol/schemas/resources/LeaveGroupResponse.json +47 -0
  315. kafka/protocol/schemas/resources/ListConfigResourcesRequest.json +31 -0
  316. kafka/protocol/schemas/resources/ListConfigResourcesResponse.json +37 -0
  317. kafka/protocol/schemas/resources/ListGroupsRequest.json +36 -0
  318. kafka/protocol/schemas/resources/ListGroupsResponse.json +49 -0
  319. kafka/protocol/schemas/resources/ListOffsetsRequest.json +72 -0
  320. kafka/protocol/schemas/resources/ListOffsetsResponse.json +71 -0
  321. kafka/protocol/schemas/resources/ListPartitionReassignmentsRequest.json +34 -0
  322. kafka/protocol/schemas/resources/ListPartitionReassignmentsResponse.json +46 -0
  323. kafka/protocol/schemas/resources/ListTransactionsRequest.json +40 -0
  324. kafka/protocol/schemas/resources/ListTransactionsResponse.json +42 -0
  325. kafka/protocol/schemas/resources/MetadataRequest.json +56 -0
  326. kafka/protocol/schemas/resources/MetadataResponse.json +101 -0
  327. kafka/protocol/schemas/resources/OffsetCommitRequest.json +76 -0
  328. kafka/protocol/schemas/resources/OffsetCommitResponse.json +71 -0
  329. kafka/protocol/schemas/resources/OffsetDeleteRequest.json +39 -0
  330. kafka/protocol/schemas/resources/OffsetDeleteResponse.json +42 -0
  331. kafka/protocol/schemas/resources/OffsetFetchRequest.json +76 -0
  332. kafka/protocol/schemas/resources/OffsetFetchResponse.json +107 -0
  333. kafka/protocol/schemas/resources/OffsetForLeaderEpochRequest.json +52 -0
  334. kafka/protocol/schemas/resources/OffsetForLeaderEpochResponse.json +51 -0
  335. kafka/protocol/schemas/resources/ProduceRequest.json +73 -0
  336. kafka/protocol/schemas/resources/ProduceResponse.json +96 -0
  337. kafka/protocol/schemas/resources/RequestHeader.json +44 -0
  338. kafka/protocol/schemas/resources/ResponseHeader.json +26 -0
  339. kafka/protocol/schemas/resources/SaslAuthenticateRequest.json +29 -0
  340. kafka/protocol/schemas/resources/SaslAuthenticateResponse.json +34 -0
  341. kafka/protocol/schemas/resources/SaslHandshakeRequest.json +31 -0
  342. kafka/protocol/schemas/resources/SaslHandshakeResponse.json +32 -0
  343. kafka/protocol/schemas/resources/SyncGroupRequest.json +56 -0
  344. kafka/protocol/schemas/resources/SyncGroupResponse.json +46 -0
  345. kafka/protocol/schemas/resources/TxnOffsetCommitRequest.json +68 -0
  346. kafka/protocol/schemas/resources/TxnOffsetCommitResponse.json +47 -0
  347. kafka/protocol/schemas/resources/UpdateFeaturesRequest.json +43 -0
  348. kafka/protocol/schemas/resources/UpdateFeaturesResponse.json +39 -0
  349. kafka/protocol/schemas/resources/WriteTxnMarkersRequest.json +49 -0
  350. kafka/protocol/schemas/resources/WriteTxnMarkersResponse.json +45 -0
  351. kafka/protocol/schemas/resources/__init__.py +0 -0
  352. kafka/record/__init__.py +3 -0
  353. kafka/record/_crc32c.py +161 -0
  354. kafka/record/abc.py +144 -0
  355. kafka/record/default_records.py +782 -0
  356. kafka/record/legacy_records.py +587 -0
  357. kafka/record/memory_records.py +255 -0
  358. kafka/record/util.py +135 -0
  359. kafka/serializer/__init__.py +4 -0
  360. kafka/serializer/abstract.py +20 -0
  361. kafka/serializer/default.py +16 -0
  362. kafka/serializer/json.py +17 -0
  363. kafka/serializer/wrapper.py +21 -0
  364. kafka/structs.py +69 -0
  365. kafka/util.py +159 -0
  366. kafka/vendor/__init__.py +0 -0
  367. kafka/version.py +1 -0
  368. kafka_python-3.0.0.dist-info/METADATA +319 -0
  369. kafka_python-3.0.0.dist-info/RECORD +373 -0
  370. kafka_python-3.0.0.dist-info/WHEEL +5 -0
  371. kafka_python-3.0.0.dist-info/entry_points.txt +2 -0
  372. kafka_python-3.0.0.dist-info/licenses/LICENSE +202 -0
  373. kafka_python-3.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,18 @@
1
+ from ..api_message import ApiMessage
2
+
3
+
4
+ class ListTransactionsRequest(ApiMessage): pass
5
+ class ListTransactionsResponse(ApiMessage): pass
6
+
7
+ class DescribeTransactionsRequest(ApiMessage): pass
8
+ class DescribeTransactionsResponse(ApiMessage): pass
9
+
10
+ class DescribeProducersRequest(ApiMessage): pass
11
+ class DescribeProducersResponse(ApiMessage): pass
12
+
13
+
14
+ __all__ = [
15
+ 'ListTransactionsRequest', 'ListTransactionsResponse',
16
+ 'DescribeTransactionsRequest', 'DescribeTransactionsResponse',
17
+ 'DescribeProducersRequest', 'DescribeProducersResponse',
18
+ ]
@@ -0,0 +1,311 @@
1
+ # Generated by generate_stubs.py (Python 3.14)
2
+ import uuid
3
+ from typing import Any, Self
4
+
5
+ from kafka.protocol.api_message import ApiMessage
6
+ from kafka.protocol.data_container import DataContainer
7
+
8
+ __all__ = ['ListTransactionsRequest', 'ListTransactionsResponse', 'DescribeTransactionsRequest', 'DescribeTransactionsResponse', 'DescribeProducersRequest', 'DescribeProducersResponse']
9
+
10
+ class ListTransactionsRequest(ApiMessage):
11
+ state_filters: list[str]
12
+ producer_id_filters: list[int]
13
+ duration_filter: int
14
+ transactional_id_pattern: str | None
15
+ def __init__(
16
+ self,
17
+ *args: Any,
18
+ state_filters: list[str] = ...,
19
+ producer_id_filters: list[int] = ...,
20
+ duration_filter: int = ...,
21
+ transactional_id_pattern: str | None = ...,
22
+ version: int | None = None,
23
+ **kwargs: Any,
24
+ ) -> None: ...
25
+ @property
26
+ def version(self) -> int | None: ...
27
+ def to_dict(self, meta: bool = False, json: bool = True) -> dict: ...
28
+ name: str
29
+ type: str
30
+ API_KEY: int
31
+ API_VERSION: int
32
+ valid_versions: tuple[int, int]
33
+ min_version: int
34
+ max_version: int
35
+ @property
36
+ def header(self) -> Any: ...
37
+ @classmethod
38
+ def is_request(cls) -> bool: ...
39
+ def expect_response(self) -> bool: ...
40
+ def with_header(self, correlation_id: int = 0, client_id: str = "kafka-python") -> None: ...
41
+
42
+ class ListTransactionsResponse(ApiMessage):
43
+ class TransactionState(DataContainer):
44
+ transactional_id: str
45
+ producer_id: int
46
+ transaction_state: str
47
+ def __init__(
48
+ self,
49
+ *args: Any,
50
+ transactional_id: str = ...,
51
+ producer_id: int = ...,
52
+ transaction_state: str = ...,
53
+ version: int | None = None,
54
+ **kwargs: Any,
55
+ ) -> None: ...
56
+ @property
57
+ def version(self) -> int | None: ...
58
+ def to_dict(self, meta: bool = False, json: bool = True) -> dict: ...
59
+
60
+ throttle_time_ms: int
61
+ error_code: int
62
+ unknown_state_filters: list[str]
63
+ transaction_states: list[TransactionState]
64
+ def __init__(
65
+ self,
66
+ *args: Any,
67
+ throttle_time_ms: int = ...,
68
+ error_code: int = ...,
69
+ unknown_state_filters: list[str] = ...,
70
+ transaction_states: list[TransactionState] = ...,
71
+ version: int | None = None,
72
+ **kwargs: Any,
73
+ ) -> None: ...
74
+ @property
75
+ def version(self) -> int | None: ...
76
+ def to_dict(self, meta: bool = False, json: bool = True) -> dict: ...
77
+ name: str
78
+ type: str
79
+ API_KEY: int
80
+ API_VERSION: int
81
+ valid_versions: tuple[int, int]
82
+ min_version: int
83
+ max_version: int
84
+ @property
85
+ def header(self) -> Any: ...
86
+ @classmethod
87
+ def is_request(cls) -> bool: ...
88
+ def expect_response(self) -> bool: ...
89
+ def with_header(self, correlation_id: int = 0, client_id: str = "kafka-python") -> None: ...
90
+
91
+ class DescribeTransactionsRequest(ApiMessage):
92
+ transactional_ids: list[str]
93
+ def __init__(
94
+ self,
95
+ *args: Any,
96
+ transactional_ids: list[str] = ...,
97
+ version: int | None = None,
98
+ **kwargs: Any,
99
+ ) -> None: ...
100
+ @property
101
+ def version(self) -> int | None: ...
102
+ def to_dict(self, meta: bool = False, json: bool = True) -> dict: ...
103
+ name: str
104
+ type: str
105
+ API_KEY: int
106
+ API_VERSION: int
107
+ valid_versions: tuple[int, int]
108
+ min_version: int
109
+ max_version: int
110
+ @property
111
+ def header(self) -> Any: ...
112
+ @classmethod
113
+ def is_request(cls) -> bool: ...
114
+ def expect_response(self) -> bool: ...
115
+ def with_header(self, correlation_id: int = 0, client_id: str = "kafka-python") -> None: ...
116
+
117
+ class DescribeTransactionsResponse(ApiMessage):
118
+ class TransactionState(DataContainer):
119
+ class TopicData(DataContainer):
120
+ topic: str
121
+ partitions: list[int]
122
+ def __init__(
123
+ self,
124
+ *args: Any,
125
+ topic: str = ...,
126
+ partitions: list[int] = ...,
127
+ version: int | None = None,
128
+ **kwargs: Any,
129
+ ) -> None: ...
130
+ @property
131
+ def version(self) -> int | None: ...
132
+ def to_dict(self, meta: bool = False, json: bool = True) -> dict: ...
133
+
134
+ error_code: int
135
+ transactional_id: str
136
+ transaction_state: str
137
+ transaction_timeout_ms: int
138
+ transaction_start_time_ms: int
139
+ producer_id: int
140
+ producer_epoch: int
141
+ topics: list[TopicData]
142
+ def __init__(
143
+ self,
144
+ *args: Any,
145
+ error_code: int = ...,
146
+ transactional_id: str = ...,
147
+ transaction_state: str = ...,
148
+ transaction_timeout_ms: int = ...,
149
+ transaction_start_time_ms: int = ...,
150
+ producer_id: int = ...,
151
+ producer_epoch: int = ...,
152
+ topics: list[TopicData] = ...,
153
+ version: int | None = None,
154
+ **kwargs: Any,
155
+ ) -> None: ...
156
+ @property
157
+ def version(self) -> int | None: ...
158
+ def to_dict(self, meta: bool = False, json: bool = True) -> dict: ...
159
+
160
+ throttle_time_ms: int
161
+ transaction_states: list[TransactionState]
162
+ def __init__(
163
+ self,
164
+ *args: Any,
165
+ throttle_time_ms: int = ...,
166
+ transaction_states: list[TransactionState] = ...,
167
+ version: int | None = None,
168
+ **kwargs: Any,
169
+ ) -> None: ...
170
+ @property
171
+ def version(self) -> int | None: ...
172
+ def to_dict(self, meta: bool = False, json: bool = True) -> dict: ...
173
+ name: str
174
+ type: str
175
+ API_KEY: int
176
+ API_VERSION: int
177
+ valid_versions: tuple[int, int]
178
+ min_version: int
179
+ max_version: int
180
+ @property
181
+ def header(self) -> Any: ...
182
+ @classmethod
183
+ def is_request(cls) -> bool: ...
184
+ def expect_response(self) -> bool: ...
185
+ def with_header(self, correlation_id: int = 0, client_id: str = "kafka-python") -> None: ...
186
+
187
+ class DescribeProducersRequest(ApiMessage):
188
+ class TopicRequest(DataContainer):
189
+ name: str
190
+ partition_indexes: list[int]
191
+ def __init__(
192
+ self,
193
+ *args: Any,
194
+ name: str = ...,
195
+ partition_indexes: list[int] = ...,
196
+ version: int | None = None,
197
+ **kwargs: Any,
198
+ ) -> None: ...
199
+ @property
200
+ def version(self) -> int | None: ...
201
+ def to_dict(self, meta: bool = False, json: bool = True) -> dict: ...
202
+
203
+ topics: list[TopicRequest]
204
+ def __init__(
205
+ self,
206
+ *args: Any,
207
+ topics: list[TopicRequest] = ...,
208
+ version: int | None = None,
209
+ **kwargs: Any,
210
+ ) -> None: ...
211
+ @property
212
+ def version(self) -> int | None: ...
213
+ def to_dict(self, meta: bool = False, json: bool = True) -> dict: ...
214
+ name: str
215
+ type: str
216
+ API_KEY: int
217
+ API_VERSION: int
218
+ valid_versions: tuple[int, int]
219
+ min_version: int
220
+ max_version: int
221
+ @property
222
+ def header(self) -> Any: ...
223
+ @classmethod
224
+ def is_request(cls) -> bool: ...
225
+ def expect_response(self) -> bool: ...
226
+ def with_header(self, correlation_id: int = 0, client_id: str = "kafka-python") -> None: ...
227
+
228
+ class DescribeProducersResponse(ApiMessage):
229
+ class TopicResponse(DataContainer):
230
+ class PartitionResponse(DataContainer):
231
+ class ProducerState(DataContainer):
232
+ producer_id: int
233
+ producer_epoch: int
234
+ last_sequence: int
235
+ last_timestamp: int
236
+ coordinator_epoch: int
237
+ current_txn_start_offset: int
238
+ def __init__(
239
+ self,
240
+ *args: Any,
241
+ producer_id: int = ...,
242
+ producer_epoch: int = ...,
243
+ last_sequence: int = ...,
244
+ last_timestamp: int = ...,
245
+ coordinator_epoch: int = ...,
246
+ current_txn_start_offset: int = ...,
247
+ version: int | None = None,
248
+ **kwargs: Any,
249
+ ) -> None: ...
250
+ @property
251
+ def version(self) -> int | None: ...
252
+ def to_dict(self, meta: bool = False, json: bool = True) -> dict: ...
253
+
254
+ partition_index: int
255
+ error_code: int
256
+ error_message: str | None
257
+ active_producers: list[ProducerState]
258
+ def __init__(
259
+ self,
260
+ *args: Any,
261
+ partition_index: int = ...,
262
+ error_code: int = ...,
263
+ error_message: str | None = ...,
264
+ active_producers: list[ProducerState] = ...,
265
+ version: int | None = None,
266
+ **kwargs: Any,
267
+ ) -> None: ...
268
+ @property
269
+ def version(self) -> int | None: ...
270
+ def to_dict(self, meta: bool = False, json: bool = True) -> dict: ...
271
+
272
+ name: str
273
+ partitions: list[PartitionResponse]
274
+ def __init__(
275
+ self,
276
+ *args: Any,
277
+ name: str = ...,
278
+ partitions: list[PartitionResponse] = ...,
279
+ version: int | None = None,
280
+ **kwargs: Any,
281
+ ) -> None: ...
282
+ @property
283
+ def version(self) -> int | None: ...
284
+ def to_dict(self, meta: bool = False, json: bool = True) -> dict: ...
285
+
286
+ throttle_time_ms: int
287
+ topics: list[TopicResponse]
288
+ def __init__(
289
+ self,
290
+ *args: Any,
291
+ throttle_time_ms: int = ...,
292
+ topics: list[TopicResponse] = ...,
293
+ version: int | None = None,
294
+ **kwargs: Any,
295
+ ) -> None: ...
296
+ @property
297
+ def version(self) -> int | None: ...
298
+ def to_dict(self, meta: bool = False, json: bool = True) -> dict: ...
299
+ name: str
300
+ type: str
301
+ API_KEY: int
302
+ API_VERSION: int
303
+ valid_versions: tuple[int, int]
304
+ min_version: int
305
+ max_version: int
306
+ @property
307
+ def header(self) -> Any: ...
308
+ @classmethod
309
+ def is_request(cls) -> bool: ...
310
+ def expect_response(self) -> bool: ...
311
+ def with_header(self, correlation_id: int = 0, client_id: str = "kafka-python") -> None: ...
@@ -0,0 +1,14 @@
1
+ from ..api_message import ApiMessage
2
+
3
+
4
+ class AlterUserScramCredentialsRequest(ApiMessage): pass
5
+ class AlterUserScramCredentialsResponse(ApiMessage): pass
6
+
7
+ class DescribeUserScramCredentialsRequest(ApiMessage): pass
8
+ class DescribeUserScramCredentialsResponse(ApiMessage): pass
9
+
10
+
11
+ __all__ = [
12
+ 'AlterUserScramCredentialsRequest', 'AlterUserScramCredentialsResponse',
13
+ 'DescribeUserScramCredentialsRequest', 'DescribeUserScramCredentialsResponse',
14
+ ]
@@ -0,0 +1,223 @@
1
+ # Generated by generate_stubs.py (Python 3.14)
2
+ import uuid
3
+ from typing import Any, Self
4
+
5
+ from kafka.protocol.api_message import ApiMessage
6
+ from kafka.protocol.api_data import ApiData
7
+ from kafka.protocol.data_container import DataContainer
8
+
9
+ __all__ = ['AlterUserScramCredentialsRequest', 'AlterUserScramCredentialsResponse', 'DescribeUserScramCredentialsRequest', 'DescribeUserScramCredentialsResponse']
10
+
11
+ class AlterUserScramCredentialsRequest(ApiMessage):
12
+ class ScramCredentialDeletion(DataContainer):
13
+ name: str
14
+ mechanism: int
15
+ def __init__(
16
+ self,
17
+ *args: Any,
18
+ name: str = ...,
19
+ mechanism: int = ...,
20
+ version: int | None = None,
21
+ **kwargs: Any,
22
+ ) -> None: ...
23
+ @property
24
+ def version(self) -> int | None: ...
25
+ def to_dict(self, meta: bool = False, json: bool = True) -> dict: ...
26
+
27
+ class ScramCredentialUpsertion(DataContainer):
28
+ name: str
29
+ mechanism: int
30
+ iterations: int
31
+ salt: bytes | ApiData
32
+ salted_password: bytes | ApiData
33
+ def __init__(
34
+ self,
35
+ *args: Any,
36
+ name: str = ...,
37
+ mechanism: int = ...,
38
+ iterations: int = ...,
39
+ salt: bytes | ApiData = ...,
40
+ salted_password: bytes | ApiData = ...,
41
+ version: int | None = None,
42
+ **kwargs: Any,
43
+ ) -> None: ...
44
+ @property
45
+ def version(self) -> int | None: ...
46
+ def to_dict(self, meta: bool = False, json: bool = True) -> dict: ...
47
+
48
+ deletions: list[ScramCredentialDeletion]
49
+ upsertions: list[ScramCredentialUpsertion]
50
+ def __init__(
51
+ self,
52
+ *args: Any,
53
+ deletions: list[ScramCredentialDeletion] = ...,
54
+ upsertions: list[ScramCredentialUpsertion] = ...,
55
+ version: int | None = None,
56
+ **kwargs: Any,
57
+ ) -> None: ...
58
+ @property
59
+ def version(self) -> int | None: ...
60
+ def to_dict(self, meta: bool = False, json: bool = True) -> dict: ...
61
+ name: str
62
+ type: str
63
+ API_KEY: int
64
+ API_VERSION: int
65
+ valid_versions: tuple[int, int]
66
+ min_version: int
67
+ max_version: int
68
+ @property
69
+ def header(self) -> Any: ...
70
+ @classmethod
71
+ def is_request(cls) -> bool: ...
72
+ def expect_response(self) -> bool: ...
73
+ def with_header(self, correlation_id: int = 0, client_id: str = "kafka-python") -> None: ...
74
+
75
+ class AlterUserScramCredentialsResponse(ApiMessage):
76
+ class AlterUserScramCredentialsResult(DataContainer):
77
+ user: str
78
+ error_code: int
79
+ error_message: str | None
80
+ def __init__(
81
+ self,
82
+ *args: Any,
83
+ user: str = ...,
84
+ error_code: int = ...,
85
+ error_message: str | None = ...,
86
+ version: int | None = None,
87
+ **kwargs: Any,
88
+ ) -> None: ...
89
+ @property
90
+ def version(self) -> int | None: ...
91
+ def to_dict(self, meta: bool = False, json: bool = True) -> dict: ...
92
+
93
+ throttle_time_ms: int
94
+ results: list[AlterUserScramCredentialsResult]
95
+ def __init__(
96
+ self,
97
+ *args: Any,
98
+ throttle_time_ms: int = ...,
99
+ results: list[AlterUserScramCredentialsResult] = ...,
100
+ version: int | None = None,
101
+ **kwargs: Any,
102
+ ) -> None: ...
103
+ @property
104
+ def version(self) -> int | None: ...
105
+ def to_dict(self, meta: bool = False, json: bool = True) -> dict: ...
106
+ name: str
107
+ type: str
108
+ API_KEY: int
109
+ API_VERSION: int
110
+ valid_versions: tuple[int, int]
111
+ min_version: int
112
+ max_version: int
113
+ @property
114
+ def header(self) -> Any: ...
115
+ @classmethod
116
+ def is_request(cls) -> bool: ...
117
+ def expect_response(self) -> bool: ...
118
+ def with_header(self, correlation_id: int = 0, client_id: str = "kafka-python") -> None: ...
119
+
120
+ class DescribeUserScramCredentialsRequest(ApiMessage):
121
+ class UserName(DataContainer):
122
+ name: str
123
+ def __init__(
124
+ self,
125
+ *args: Any,
126
+ name: str = ...,
127
+ version: int | None = None,
128
+ **kwargs: Any,
129
+ ) -> None: ...
130
+ @property
131
+ def version(self) -> int | None: ...
132
+ def to_dict(self, meta: bool = False, json: bool = True) -> dict: ...
133
+
134
+ users: list[UserName] | None
135
+ def __init__(
136
+ self,
137
+ *args: Any,
138
+ users: list[UserName] | None = ...,
139
+ version: int | None = None,
140
+ **kwargs: Any,
141
+ ) -> None: ...
142
+ @property
143
+ def version(self) -> int | None: ...
144
+ def to_dict(self, meta: bool = False, json: bool = True) -> dict: ...
145
+ name: str
146
+ type: str
147
+ API_KEY: int
148
+ API_VERSION: int
149
+ valid_versions: tuple[int, int]
150
+ min_version: int
151
+ max_version: int
152
+ @property
153
+ def header(self) -> Any: ...
154
+ @classmethod
155
+ def is_request(cls) -> bool: ...
156
+ def expect_response(self) -> bool: ...
157
+ def with_header(self, correlation_id: int = 0, client_id: str = "kafka-python") -> None: ...
158
+
159
+ class DescribeUserScramCredentialsResponse(ApiMessage):
160
+ class DescribeUserScramCredentialsResult(DataContainer):
161
+ class CredentialInfo(DataContainer):
162
+ mechanism: int
163
+ iterations: int
164
+ def __init__(
165
+ self,
166
+ *args: Any,
167
+ mechanism: int = ...,
168
+ iterations: int = ...,
169
+ version: int | None = None,
170
+ **kwargs: Any,
171
+ ) -> None: ...
172
+ @property
173
+ def version(self) -> int | None: ...
174
+ def to_dict(self, meta: bool = False, json: bool = True) -> dict: ...
175
+
176
+ user: str
177
+ error_code: int
178
+ error_message: str | None
179
+ credential_infos: list[CredentialInfo]
180
+ def __init__(
181
+ self,
182
+ *args: Any,
183
+ user: str = ...,
184
+ error_code: int = ...,
185
+ error_message: str | None = ...,
186
+ credential_infos: list[CredentialInfo] = ...,
187
+ version: int | None = None,
188
+ **kwargs: Any,
189
+ ) -> None: ...
190
+ @property
191
+ def version(self) -> int | None: ...
192
+ def to_dict(self, meta: bool = False, json: bool = True) -> dict: ...
193
+
194
+ throttle_time_ms: int
195
+ error_code: int
196
+ error_message: str | None
197
+ results: list[DescribeUserScramCredentialsResult]
198
+ def __init__(
199
+ self,
200
+ *args: Any,
201
+ throttle_time_ms: int = ...,
202
+ error_code: int = ...,
203
+ error_message: str | None = ...,
204
+ results: list[DescribeUserScramCredentialsResult] = ...,
205
+ version: int | None = None,
206
+ **kwargs: Any,
207
+ ) -> None: ...
208
+ @property
209
+ def version(self) -> int | None: ...
210
+ def to_dict(self, meta: bool = False, json: bool = True) -> dict: ...
211
+ name: str
212
+ type: str
213
+ API_KEY: int
214
+ API_VERSION: int
215
+ valid_versions: tuple[int, int]
216
+ min_version: int
217
+ max_version: int
218
+ @property
219
+ def header(self) -> Any: ...
220
+ @classmethod
221
+ def is_request(cls) -> bool: ...
222
+ def expect_response(self) -> bool: ...
223
+ def with_header(self, correlation_id: int = 0, client_id: str = "kafka-python") -> None: ...
@@ -0,0 +1,125 @@
1
+ import io
2
+ import weakref
3
+
4
+ from kafka.util import classproperty
5
+
6
+ from .data_container import DataContainer, SlotsBuilder
7
+ from .schemas import BaseField, StructField, load_json
8
+ from .schemas.fields.codecs import Int16, Int32
9
+
10
+
11
+ class JsonSchemaData(SlotsBuilder):
12
+ def __new__(metacls, name, bases, attrs, **kw):
13
+ if kw.get('init', True):
14
+ json = load_json(name, package=kw.get('load_json'))
15
+ if 'json_patch' in attrs:
16
+ json = attrs['json_patch'].__func__(metacls, json)
17
+ attrs['_json'] = json
18
+ attrs['_struct'] = StructField(json)
19
+ if 'doc' in json:
20
+ attrs['__doc__'] = attrs.get('__doc__', '') + "\nNotes from json schema:\n" + json.get('doc')
21
+ attrs['__license__'] = json.get('license')
22
+ return super().__new__(metacls, name, bases, attrs, **kw)
23
+
24
+ def __init__(cls, name, bases, attrs, **kw):
25
+ super().__init__(name, bases, attrs, **kw)
26
+ if kw.get('init', True):
27
+ cls._struct.set_data_class(weakref.proxy(cls))
28
+
29
+
30
+ class ApiData(DataContainer, metaclass=JsonSchemaData, init=False):
31
+ def __init_subclass__(cls, **kw):
32
+ super().__init_subclass__(**kw)
33
+ if kw.get('init', True):
34
+ # pylint: disable=E1101
35
+ assert cls._json is not None
36
+ assert cls._json['type'] == 'data'
37
+ cls._flexible_versions = BaseField.parse_versions(cls._json['flexibleVersions'])
38
+ cls._valid_versions = BaseField.parse_versions(cls._json['validVersions'])
39
+
40
+ def __init__(self, *args, **kwargs):
41
+ if len(args) > 0 and isinstance(args[0], int) and 'version' not in kwargs:
42
+ kwargs['version'] = args[0]
43
+ args = tuple(args[1:])
44
+ super().__init__(*args, **kwargs)
45
+
46
+ @classproperty
47
+ def name(cls): # pylint: disable=E0213
48
+ return cls._json['name'] # pylint: disable=E1101
49
+
50
+ @classproperty
51
+ def type(cls): # pylint: disable=E0213
52
+ return cls._json['type'] # pylint: disable=E1101
53
+
54
+ @classproperty
55
+ def json(cls): # pylint: disable=E0213
56
+ return cls._json # pylint: disable=E1101
57
+
58
+ @classproperty
59
+ def valid_versions(cls): # pylint: disable=E0213
60
+ return cls._valid_versions
61
+
62
+ @classproperty
63
+ def min_version(cls): # pylint: disable=E0213
64
+ return 0
65
+
66
+ @classproperty
67
+ def max_version(cls): # pylint: disable=E0213
68
+ if cls._valid_versions is not None:
69
+ return cls._valid_versions[1] # pylint: disable=E1136
70
+ return None
71
+
72
+ @classmethod
73
+ def flexible_version_q(cls, version):
74
+ if cls._flexible_versions is not None:
75
+ if cls._flexible_versions[0] <= version <= cls._flexible_versions[1]: # pylint: disable=E1136
76
+ return True
77
+ return False
78
+
79
+ @classproperty
80
+ def header_class(cls): # pylint: disable=E0213
81
+ return Int16
82
+
83
+ def encode_header(self, flexible=False):
84
+ assert self._version is not None
85
+ return self.header_class.encode(self._version)
86
+
87
+ @classmethod
88
+ def parse_header(cls, data):
89
+ return cls.header_class.decode(data) # pylint: disable-msg=no-member
90
+
91
+ def encode(self, version=None, header=True, framed=False):
92
+ if version is not None:
93
+ self._version = version
94
+ elif self._version is None:
95
+ raise ValueError('Version required to encode data')
96
+ flexible = self.flexible_version_q(self._version)
97
+ encoded = self._struct.encode(self, version=self._version, compact=flexible, tagged=flexible)
98
+ if not header and not framed:
99
+ return encoded
100
+ bits = [encoded]
101
+ if header:
102
+ bits.insert(0, self.encode_header(flexible=flexible))
103
+ if framed:
104
+ bits.insert(0, Int32.encode(sum(map(len, bits))))
105
+ return b''.join(bits)
106
+
107
+ @classmethod
108
+ def decode(cls, data, version=None, header=True, framed=False):
109
+ if not header:
110
+ if version is None:
111
+ raise ValueError('Version required to decode data')
112
+ elif not 0 <= version <= cls.max_version:
113
+ raise ValueError('Invalid version %s (max version is %s).' % (version, cls.max_version))
114
+ if isinstance(data, bytes):
115
+ data = io.BytesIO(data)
116
+ if framed:
117
+ size = Int32.decode(data)
118
+ if header:
119
+ decoded_version = cls.parse_header(data)
120
+ if version is not None:
121
+ if version > decoded_version:
122
+ raise ValueError('Version mismatch: found v%d, expected v%d' % (decoded_version, version))
123
+ version = min(decoded_version, cls.max_version)
124
+ flexible = cls.flexible_version_q(version)
125
+ return cls._struct.decode(data, version=version, compact=flexible, tagged=flexible)