crate 1.0.1__py3-none-any.whl → 2.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.
crate/client/__init__.py CHANGED
@@ -29,7 +29,7 @@ __all__ = [
29
29
 
30
30
  # version string read from setup.py using a regex. Take care not to break the
31
31
  # regex!
32
- __version__ = "1.0.1"
32
+ __version__ = "2.0.0"
33
33
 
34
34
  # codeql[py/unused-global-variable]
35
35
  apilevel = "2.0"
crate/client/http.py CHANGED
@@ -21,22 +21,22 @@
21
21
 
22
22
 
23
23
  import calendar
24
+ import datetime as dt
24
25
  import heapq
25
26
  import io
26
- import json
27
27
  import logging
28
28
  import os
29
29
  import re
30
30
  import socket
31
31
  import ssl
32
32
  import threading
33
+ import typing as t
33
34
  from base64 import b64encode
34
- from datetime import date, datetime, timezone
35
35
  from decimal import Decimal
36
36
  from time import time
37
37
  from urllib.parse import urlparse
38
- from uuid import UUID
39
38
 
39
+ import orjson
40
40
  import urllib3
41
41
  from urllib3 import connection_from_url
42
42
  from urllib3.connection import HTTPConnection
@@ -86,25 +86,53 @@ def super_len(o):
86
86
  return None
87
87
 
88
88
 
89
- class CrateJsonEncoder(json.JSONEncoder):
90
- epoch_aware = datetime(1970, 1, 1, tzinfo=timezone.utc)
91
- epoch_naive = datetime(1970, 1, 1)
92
-
93
- def default(self, o):
94
- if isinstance(o, (Decimal, UUID)):
95
- return str(o)
96
- if isinstance(o, datetime):
97
- if o.tzinfo is not None:
98
- delta = o - self.epoch_aware
99
- else:
100
- delta = o - self.epoch_naive
101
- return int(
102
- delta.microseconds / 1000.0
103
- + (delta.seconds + delta.days * 24 * 3600) * 1000.0
104
- )
105
- if isinstance(o, date):
106
- return calendar.timegm(o.timetuple()) * 1000
107
- return json.JSONEncoder.default(self, o)
89
+ epoch_aware = dt.datetime(1970, 1, 1, tzinfo=dt.timezone.utc)
90
+ epoch_naive = dt.datetime(1970, 1, 1)
91
+
92
+
93
+ def json_encoder(obj: t.Any) -> t.Union[int, str]:
94
+ """
95
+ Encoder function for orjson, with additional type support.
96
+
97
+ - Python's `Decimal` type will be serialized to `str`.
98
+ - Python's `dt.datetime` and `dt.date` types will be
99
+ serialized to `int` after converting to milliseconds
100
+ since epoch.
101
+
102
+ https://github.com/ijl/orjson#default
103
+ https://cratedb.com/docs/crate/reference/en/latest/general/ddl/data-types.html#type-timestamp
104
+ """
105
+ if isinstance(obj, Decimal):
106
+ return str(obj)
107
+ if isinstance(obj, dt.datetime):
108
+ if obj.tzinfo is not None:
109
+ delta = obj - epoch_aware
110
+ else:
111
+ delta = obj - epoch_naive
112
+ return int(
113
+ delta.microseconds / 1000.0
114
+ + (delta.seconds + delta.days * 24 * 3600) * 1000.0
115
+ )
116
+ if isinstance(obj, dt.date):
117
+ return calendar.timegm(obj.timetuple()) * 1000
118
+ raise TypeError
119
+
120
+
121
+ def json_dumps(obj: t.Any) -> bytes:
122
+ """
123
+ Serialize to JSON format, using `orjson`, with additional type support.
124
+
125
+ https://github.com/ijl/orjson
126
+ """
127
+ return orjson.dumps(
128
+ obj,
129
+ default=json_encoder,
130
+ option=(
131
+ orjson.OPT_PASSTHROUGH_DATETIME
132
+ | orjson.OPT_NON_STR_KEYS
133
+ | orjson.OPT_SERIALIZE_NUMPY
134
+ ),
135
+ )
108
136
 
109
137
 
110
138
  class Server:
@@ -180,7 +208,7 @@ class Server:
180
208
 
181
209
  def _json_from_response(response):
182
210
  try:
183
- return json.loads(response.data.decode("utf-8"))
211
+ return orjson.loads(response.data)
184
212
  except ValueError as ex:
185
213
  raise ProgrammingError(
186
214
  "Invalid server response of content-type '{}':\n{}".format(
@@ -223,7 +251,7 @@ def _raise_for_status_real(response):
223
251
  if response.status == 503:
224
252
  raise ConnectionError(message)
225
253
  if response.headers.get("content-type", "").startswith("application/json"):
226
- data = json.loads(response.data.decode("utf-8"))
254
+ data = orjson.loads(response.data)
227
255
  error = data.get("error", {})
228
256
  error_trace = data.get("error_trace", None)
229
257
  if "results" in data:
@@ -323,7 +351,7 @@ def _update_pool_kwargs_for_ssl_minimum_version(server, kwargs):
323
351
  kwargs["ssl_minimum_version"] = ssl.TLSVersion.MINIMUM_SUPPORTED
324
352
 
325
353
 
326
- def _create_sql_payload(stmt, args, bulk_args):
354
+ def _create_sql_payload(stmt, args, bulk_args) -> bytes:
327
355
  if not isinstance(stmt, str):
328
356
  raise ValueError("stmt is not a string")
329
357
  if args and bulk_args:
@@ -334,7 +362,7 @@ def _create_sql_payload(stmt, args, bulk_args):
334
362
  data["args"] = args
335
363
  if bulk_args:
336
364
  data["bulk_args"] = bulk_args
337
- return json.dumps(data, cls=CrateJsonEncoder)
365
+ return json_dumps(data)
338
366
 
339
367
 
340
368
  def _get_socket_opts(
@@ -670,7 +698,7 @@ class Client:
670
698
  # if this is the last server raise exception, otherwise try next
671
699
  if not self._active_servers:
672
700
  raise ConnectionError(
673
- ("No more Servers available, " "exception from last server: %s")
701
+ ("No more Servers available, exception from last server: %s")
674
702
  % message
675
703
  )
676
704
 
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: crate
3
- Version: 1.0.1
3
+ Version: 2.0.0
4
4
  Summary: CrateDB Python Client
5
5
  Home-page: https://github.com/crate/crate-python
6
6
  Author: Crate.io
@@ -29,6 +29,7 @@ Requires-Python: >=3.6
29
29
  Description-Content-Type: text/x-rst
30
30
  License-File: LICENSE
31
31
  License-File: NOTICE
32
+ Requires-Dist: orjson<4
32
33
  Requires-Dist: urllib3
33
34
  Requires-Dist: verlib2
34
35
  Provides-Extra: doc
@@ -38,15 +39,27 @@ Provides-Extra: test
38
39
  Requires-Dist: backports.zoneinfo<1; python_version < "3.9" and extra == "test"
39
40
  Requires-Dist: certifi; extra == "test"
40
41
  Requires-Dist: createcoverage<2,>=1; extra == "test"
41
- Requires-Dist: mypy<1.14; extra == "test"
42
- Requires-Dist: poethepoet<0.31; extra == "test"
43
- Requires-Dist: ruff<0.8; extra == "test"
42
+ Requires-Dist: mypy<1.15; extra == "test"
43
+ Requires-Dist: poethepoet<0.33; extra == "test"
44
+ Requires-Dist: ruff<0.10; extra == "test"
44
45
  Requires-Dist: stopit<2,>=1.1.2; extra == "test"
45
- Requires-Dist: tox<5,>=3; extra == "test"
46
46
  Requires-Dist: pytz; extra == "test"
47
47
  Requires-Dist: zc.customdoctests<2,>=1.0.1; extra == "test"
48
48
  Requires-Dist: zope.testing<6,>=4; extra == "test"
49
49
  Requires-Dist: zope.testrunner<7,>=5; extra == "test"
50
+ Dynamic: author
51
+ Dynamic: author-email
52
+ Dynamic: classifier
53
+ Dynamic: description
54
+ Dynamic: description-content-type
55
+ Dynamic: home-page
56
+ Dynamic: keywords
57
+ Dynamic: license
58
+ Dynamic: platform
59
+ Dynamic: provides-extra
60
+ Dynamic: requires-dist
61
+ Dynamic: requires-python
62
+ Dynamic: summary
50
63
 
51
64
  =====================
52
65
  CrateDB Python Client
@@ -1,17 +1,17 @@
1
- crate/client/__init__.py,sha256=hefR2KxiciqgwZ6dd5fR4wwPHuS3Kgup-gpc7jxFNlU,1344
1
+ crate/client/__init__.py,sha256=ljKM3KpoDmWYNx5JvErKhO6pXQ9fdtHrW9VCl-aZw14,1344
2
2
  crate/client/_pep440.py,sha256=iwY5wopxbgbwsT0ImANrwN3V_ZYQHhSr7lEdVT5dQRM,42
3
3
  crate/client/blob.py,sha256=aMo6ZNHGT3Zq_yR3gcpd3CKrJvfqUAhExhKtHUwC5Io,3460
4
4
  crate/client/connection.py,sha256=80v9_--YilDAaIQpejf3G_TWGz9iwUkixwHAL66sDm0,8098
5
5
  crate/client/converter.py,sha256=Qci0MNcpz1jAnjquG8Ld9LI84_iHVInrv4HMb8r5zzg,4313
6
6
  crate/client/cursor.py,sha256=Mlk-TVLzM4zSSr7GxcHK4Mjbt1KQeMfNFNrPBtGjk-c,10741
7
7
  crate/client/exceptions.py,sha256=wMyJmOB3RP5kuPeW9f0fEb-1AKZcGSTyIGvN0HqpqUw,2557
8
- crate/client/http.py,sha256=ddp_VSTcrMNStPjSG0CmdtRUO8dgaQZfNR_ltfs9DxI,22625
8
+ crate/client/http.py,sha256=wNTlFOwYv9R4dMWvaZ7b-U-uzUwLNJB7pknwiE_QGkE,23270
9
9
  crate/testing/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
10
  crate/testing/layer.py,sha256=jvHRWTRE4Zal211UO0HWPFcbprAcaGB3WyAUDR7BKFQ,13376
11
11
  crate/testing/util.py,sha256=BPEZ8DavXwyOTCmOQnP5QjQlapEw3harzKK4w2HOTA4,3264
12
- crate-1.0.1.dist-info/LICENSE,sha256=s_w3FXmAYQuatqsgvyYLnGyC_13KOqp3W1DUEXO9RpY,10175
13
- crate-1.0.1.dist-info/METADATA,sha256=nvUareNPApcQKA8AcNrTepTjFvDc72QbjzgHEUCo5Oc,5351
14
- crate-1.0.1.dist-info/NOTICE,sha256=jfWOHkoZKjNATGXMfgpMJdL38ki_ZZTgR6M9CUUJxrM,1159
15
- crate-1.0.1.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
16
- crate-1.0.1.dist-info/top_level.txt,sha256=2wP2HlpxdhgTLMl9ipi168xkm6FMq9_2bf0xGGxF_OI,6
17
- crate-1.0.1.dist-info/RECORD,,
12
+ crate-2.0.0.dist-info/LICENSE,sha256=s_w3FXmAYQuatqsgvyYLnGyC_13KOqp3W1DUEXO9RpY,10175
13
+ crate-2.0.0.dist-info/METADATA,sha256=Ho9tBUt4K4UuoYLn_-G8ZWn-gGbB4HFVS9kzvCc_BeQ,5608
14
+ crate-2.0.0.dist-info/NOTICE,sha256=jfWOHkoZKjNATGXMfgpMJdL38ki_ZZTgR6M9CUUJxrM,1159
15
+ crate-2.0.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
16
+ crate-2.0.0.dist-info/top_level.txt,sha256=2wP2HlpxdhgTLMl9ipi168xkm6FMq9_2bf0xGGxF_OI,6
17
+ crate-2.0.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.6.0)
2
+ Generator: setuptools (75.8.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
File without changes
File without changes