coredis 5.1.0__py3-none-any.whl → 5.2.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.

Potentially problematic release.


This version of coredis might be problematic. Click here for more details.

coredis/__init__.py CHANGED
@@ -8,8 +8,7 @@ cluster & sentinel.
8
8
 
9
9
  from __future__ import annotations
10
10
 
11
- from typing import cast
12
-
11
+ from coredis._version import __version__
13
12
  from coredis.client import Redis, RedisCluster
14
13
  from coredis.config import Config
15
14
  from coredis.connection import (
@@ -26,8 +25,6 @@ from coredis.pool import (
26
25
  )
27
26
  from coredis.tokens import PureToken
28
27
 
29
- from . import _version
30
-
31
28
  __all__ = [
32
29
  "Config",
33
30
  "Redis",
@@ -41,6 +38,5 @@ __all__ = [
41
38
  "BlockingClusterConnectionPool",
42
39
  "ClusterConnectionPool",
43
40
  "PureToken",
41
+ "__version__",
44
42
  ]
45
-
46
- __version__ = cast(str, _version.get_versions()["version"]) # type: ignore
coredis/_enum.py ADDED
@@ -0,0 +1,42 @@
1
+ from __future__ import annotations
2
+
3
+ import enum
4
+
5
+ from coredis.typing import StringT
6
+
7
+
8
+ @enum.unique
9
+ class CaseAndEncodingInsensitiveEnum(bytes, enum.Enum):
10
+ __decoded: set[StringT]
11
+
12
+ @property
13
+ def variants(self) -> set[StringT]:
14
+ if not hasattr(self, "__decoded"):
15
+ decoded = str(self)
16
+ self.__decoded = {
17
+ self.value.lower(), # type: ignore
18
+ self.value, # type: ignore
19
+ decoded.lower(),
20
+ decoded.upper(),
21
+ }
22
+ return self.__decoded
23
+
24
+ def __eq__(self, other: object) -> bool:
25
+ """
26
+ Since redis tokens are case insensitive allow mixed case
27
+ Additionally allow strings to be passed in instead of
28
+ bytes.
29
+ """
30
+
31
+ if other:
32
+ if isinstance(other, self.__class__):
33
+ return bool(self.value == other.value)
34
+ else:
35
+ return other in self.variants
36
+ return False
37
+
38
+ def __str__(self) -> str:
39
+ return self.decode("latin-1")
40
+
41
+ def __hash__(self) -> int:
42
+ return hash(self.value)
coredis/_utils.py CHANGED
@@ -1,6 +1,5 @@
1
1
  from __future__ import annotations
2
2
 
3
- import enum
4
3
  from collections import UserDict
5
4
  from typing import Any
6
5
 
@@ -81,43 +80,6 @@ class EncodingInsensitiveDict(UserDict[Any, Any]):
81
80
  return d
82
81
 
83
82
 
84
- @enum.unique
85
- class CaseAndEncodingInsensitiveEnum(bytes, enum.Enum):
86
- __decoded: set[StringT]
87
-
88
- @property
89
- def variants(self) -> set[StringT]:
90
- if not hasattr(self, "__decoded"):
91
- decoded = str(self)
92
- self.__decoded = {
93
- self.value.lower(), # type: ignore
94
- self.value, # type: ignore
95
- decoded.lower(),
96
- decoded.upper(),
97
- }
98
- return self.__decoded
99
-
100
- def __eq__(self, other: object) -> bool:
101
- """
102
- Since redis tokens are case insensitive allow mixed case
103
- Additionally allow strings to be passed in instead of
104
- bytes.
105
- """
106
-
107
- if other:
108
- if isinstance(other, self.__class__):
109
- return bool(self.value == other.value)
110
- else:
111
- return other in self.variants
112
- return False
113
-
114
- def __str__(self) -> str:
115
- return self.decode("latin-1")
116
-
117
- def __hash__(self) -> int:
118
- return hash(self.value)
119
-
120
-
121
83
  def b(x: ResponseType, encoding: str | None = None) -> bytes:
122
84
  if isinstance(x, bytes):
123
85
  return x
@@ -191,290 +153,288 @@ def query_param_to_bool(value: Any | None) -> bool | None:
191
153
 
192
154
  # ++++++++++ cluster utils ++++++++++++++
193
155
 
194
- try:
195
- from coredis.speedups import crc16, hash_slot
196
- except ImportError:
197
- x_mode_m_crc16_lookup = [
198
- 0x0000,
199
- 0x1021,
200
- 0x2042,
201
- 0x3063,
202
- 0x4084,
203
- 0x50A5,
204
- 0x60C6,
205
- 0x70E7,
206
- 0x8108,
207
- 0x9129,
208
- 0xA14A,
209
- 0xB16B,
210
- 0xC18C,
211
- 0xD1AD,
212
- 0xE1CE,
213
- 0xF1EF,
214
- 0x1231,
215
- 0x0210,
216
- 0x3273,
217
- 0x2252,
218
- 0x52B5,
219
- 0x4294,
220
- 0x72F7,
221
- 0x62D6,
222
- 0x9339,
223
- 0x8318,
224
- 0xB37B,
225
- 0xA35A,
226
- 0xD3BD,
227
- 0xC39C,
228
- 0xF3FF,
229
- 0xE3DE,
230
- 0x2462,
231
- 0x3443,
232
- 0x0420,
233
- 0x1401,
234
- 0x64E6,
235
- 0x74C7,
236
- 0x44A4,
237
- 0x5485,
238
- 0xA56A,
239
- 0xB54B,
240
- 0x8528,
241
- 0x9509,
242
- 0xE5EE,
243
- 0xF5CF,
244
- 0xC5AC,
245
- 0xD58D,
246
- 0x3653,
247
- 0x2672,
248
- 0x1611,
249
- 0x0630,
250
- 0x76D7,
251
- 0x66F6,
252
- 0x5695,
253
- 0x46B4,
254
- 0xB75B,
255
- 0xA77A,
256
- 0x9719,
257
- 0x8738,
258
- 0xF7DF,
259
- 0xE7FE,
260
- 0xD79D,
261
- 0xC7BC,
262
- 0x48C4,
263
- 0x58E5,
264
- 0x6886,
265
- 0x78A7,
266
- 0x0840,
267
- 0x1861,
268
- 0x2802,
269
- 0x3823,
270
- 0xC9CC,
271
- 0xD9ED,
272
- 0xE98E,
273
- 0xF9AF,
274
- 0x8948,
275
- 0x9969,
276
- 0xA90A,
277
- 0xB92B,
278
- 0x5AF5,
279
- 0x4AD4,
280
- 0x7AB7,
281
- 0x6A96,
282
- 0x1A71,
283
- 0x0A50,
284
- 0x3A33,
285
- 0x2A12,
286
- 0xDBFD,
287
- 0xCBDC,
288
- 0xFBBF,
289
- 0xEB9E,
290
- 0x9B79,
291
- 0x8B58,
292
- 0xBB3B,
293
- 0xAB1A,
294
- 0x6CA6,
295
- 0x7C87,
296
- 0x4CE4,
297
- 0x5CC5,
298
- 0x2C22,
299
- 0x3C03,
300
- 0x0C60,
301
- 0x1C41,
302
- 0xEDAE,
303
- 0xFD8F,
304
- 0xCDEC,
305
- 0xDDCD,
306
- 0xAD2A,
307
- 0xBD0B,
308
- 0x8D68,
309
- 0x9D49,
310
- 0x7E97,
311
- 0x6EB6,
312
- 0x5ED5,
313
- 0x4EF4,
314
- 0x3E13,
315
- 0x2E32,
316
- 0x1E51,
317
- 0x0E70,
318
- 0xFF9F,
319
- 0xEFBE,
320
- 0xDFDD,
321
- 0xCFFC,
322
- 0xBF1B,
323
- 0xAF3A,
324
- 0x9F59,
325
- 0x8F78,
326
- 0x9188,
327
- 0x81A9,
328
- 0xB1CA,
329
- 0xA1EB,
330
- 0xD10C,
331
- 0xC12D,
332
- 0xF14E,
333
- 0xE16F,
334
- 0x1080,
335
- 0x00A1,
336
- 0x30C2,
337
- 0x20E3,
338
- 0x5004,
339
- 0x4025,
340
- 0x7046,
341
- 0x6067,
342
- 0x83B9,
343
- 0x9398,
344
- 0xA3FB,
345
- 0xB3DA,
346
- 0xC33D,
347
- 0xD31C,
348
- 0xE37F,
349
- 0xF35E,
350
- 0x02B1,
351
- 0x1290,
352
- 0x22F3,
353
- 0x32D2,
354
- 0x4235,
355
- 0x5214,
356
- 0x6277,
357
- 0x7256,
358
- 0xB5EA,
359
- 0xA5CB,
360
- 0x95A8,
361
- 0x8589,
362
- 0xF56E,
363
- 0xE54F,
364
- 0xD52C,
365
- 0xC50D,
366
- 0x34E2,
367
- 0x24C3,
368
- 0x14A0,
369
- 0x0481,
370
- 0x7466,
371
- 0x6447,
372
- 0x5424,
373
- 0x4405,
374
- 0xA7DB,
375
- 0xB7FA,
376
- 0x8799,
377
- 0x97B8,
378
- 0xE75F,
379
- 0xF77E,
380
- 0xC71D,
381
- 0xD73C,
382
- 0x26D3,
383
- 0x36F2,
384
- 0x0691,
385
- 0x16B0,
386
- 0x6657,
387
- 0x7676,
388
- 0x4615,
389
- 0x5634,
390
- 0xD94C,
391
- 0xC96D,
392
- 0xF90E,
393
- 0xE92F,
394
- 0x99C8,
395
- 0x89E9,
396
- 0xB98A,
397
- 0xA9AB,
398
- 0x5844,
399
- 0x4865,
400
- 0x7806,
401
- 0x6827,
402
- 0x18C0,
403
- 0x08E1,
404
- 0x3882,
405
- 0x28A3,
406
- 0xCB7D,
407
- 0xDB5C,
408
- 0xEB3F,
409
- 0xFB1E,
410
- 0x8BF9,
411
- 0x9BD8,
412
- 0xABBB,
413
- 0xBB9A,
414
- 0x4A75,
415
- 0x5A54,
416
- 0x6A37,
417
- 0x7A16,
418
- 0x0AF1,
419
- 0x1AD0,
420
- 0x2AB3,
421
- 0x3A92,
422
- 0xFD2E,
423
- 0xED0F,
424
- 0xDD6C,
425
- 0xCD4D,
426
- 0xBDAA,
427
- 0xAD8B,
428
- 0x9DE8,
429
- 0x8DC9,
430
- 0x7C26,
431
- 0x6C07,
432
- 0x5C64,
433
- 0x4C45,
434
- 0x3CA2,
435
- 0x2C83,
436
- 0x1CE0,
437
- 0x0CC1,
438
- 0xEF1F,
439
- 0xFF3E,
440
- 0xCF5D,
441
- 0xDF7C,
442
- 0xAF9B,
443
- 0xBFBA,
444
- 0x8FD9,
445
- 0x9FF8,
446
- 0x6E17,
447
- 0x7E36,
448
- 0x4E55,
449
- 0x5E74,
450
- 0x2E93,
451
- 0x3EB2,
452
- 0x0ED1,
453
- 0x1EF0,
454
- ]
455
-
456
- def crc16(data: bytes) -> int:
457
- crc = 0
458
-
459
- for byte in data:
460
- crc = ((crc << 8) & 0xFF00) ^ x_mode_m_crc16_lookup[((crc >> 8) & 0xFF) ^ byte]
461
-
462
- return crc & 0xFFFF
463
-
464
- def hash_slot(key: bytes) -> int:
465
- start = key.find(b"{")
466
-
467
- if start > -1:
468
- end = key.find(b"}", start + 1)
469
-
470
- if end > -1 and end != start + 1:
471
- key = key[start + 1 : end]
472
-
473
- return crc16(key) % 16384
156
+ x_mode_m_crc16_lookup = [
157
+ 0x0000,
158
+ 0x1021,
159
+ 0x2042,
160
+ 0x3063,
161
+ 0x4084,
162
+ 0x50A5,
163
+ 0x60C6,
164
+ 0x70E7,
165
+ 0x8108,
166
+ 0x9129,
167
+ 0xA14A,
168
+ 0xB16B,
169
+ 0xC18C,
170
+ 0xD1AD,
171
+ 0xE1CE,
172
+ 0xF1EF,
173
+ 0x1231,
174
+ 0x0210,
175
+ 0x3273,
176
+ 0x2252,
177
+ 0x52B5,
178
+ 0x4294,
179
+ 0x72F7,
180
+ 0x62D6,
181
+ 0x9339,
182
+ 0x8318,
183
+ 0xB37B,
184
+ 0xA35A,
185
+ 0xD3BD,
186
+ 0xC39C,
187
+ 0xF3FF,
188
+ 0xE3DE,
189
+ 0x2462,
190
+ 0x3443,
191
+ 0x0420,
192
+ 0x1401,
193
+ 0x64E6,
194
+ 0x74C7,
195
+ 0x44A4,
196
+ 0x5485,
197
+ 0xA56A,
198
+ 0xB54B,
199
+ 0x8528,
200
+ 0x9509,
201
+ 0xE5EE,
202
+ 0xF5CF,
203
+ 0xC5AC,
204
+ 0xD58D,
205
+ 0x3653,
206
+ 0x2672,
207
+ 0x1611,
208
+ 0x0630,
209
+ 0x76D7,
210
+ 0x66F6,
211
+ 0x5695,
212
+ 0x46B4,
213
+ 0xB75B,
214
+ 0xA77A,
215
+ 0x9719,
216
+ 0x8738,
217
+ 0xF7DF,
218
+ 0xE7FE,
219
+ 0xD79D,
220
+ 0xC7BC,
221
+ 0x48C4,
222
+ 0x58E5,
223
+ 0x6886,
224
+ 0x78A7,
225
+ 0x0840,
226
+ 0x1861,
227
+ 0x2802,
228
+ 0x3823,
229
+ 0xC9CC,
230
+ 0xD9ED,
231
+ 0xE98E,
232
+ 0xF9AF,
233
+ 0x8948,
234
+ 0x9969,
235
+ 0xA90A,
236
+ 0xB92B,
237
+ 0x5AF5,
238
+ 0x4AD4,
239
+ 0x7AB7,
240
+ 0x6A96,
241
+ 0x1A71,
242
+ 0x0A50,
243
+ 0x3A33,
244
+ 0x2A12,
245
+ 0xDBFD,
246
+ 0xCBDC,
247
+ 0xFBBF,
248
+ 0xEB9E,
249
+ 0x9B79,
250
+ 0x8B58,
251
+ 0xBB3B,
252
+ 0xAB1A,
253
+ 0x6CA6,
254
+ 0x7C87,
255
+ 0x4CE4,
256
+ 0x5CC5,
257
+ 0x2C22,
258
+ 0x3C03,
259
+ 0x0C60,
260
+ 0x1C41,
261
+ 0xEDAE,
262
+ 0xFD8F,
263
+ 0xCDEC,
264
+ 0xDDCD,
265
+ 0xAD2A,
266
+ 0xBD0B,
267
+ 0x8D68,
268
+ 0x9D49,
269
+ 0x7E97,
270
+ 0x6EB6,
271
+ 0x5ED5,
272
+ 0x4EF4,
273
+ 0x3E13,
274
+ 0x2E32,
275
+ 0x1E51,
276
+ 0x0E70,
277
+ 0xFF9F,
278
+ 0xEFBE,
279
+ 0xDFDD,
280
+ 0xCFFC,
281
+ 0xBF1B,
282
+ 0xAF3A,
283
+ 0x9F59,
284
+ 0x8F78,
285
+ 0x9188,
286
+ 0x81A9,
287
+ 0xB1CA,
288
+ 0xA1EB,
289
+ 0xD10C,
290
+ 0xC12D,
291
+ 0xF14E,
292
+ 0xE16F,
293
+ 0x1080,
294
+ 0x00A1,
295
+ 0x30C2,
296
+ 0x20E3,
297
+ 0x5004,
298
+ 0x4025,
299
+ 0x7046,
300
+ 0x6067,
301
+ 0x83B9,
302
+ 0x9398,
303
+ 0xA3FB,
304
+ 0xB3DA,
305
+ 0xC33D,
306
+ 0xD31C,
307
+ 0xE37F,
308
+ 0xF35E,
309
+ 0x02B1,
310
+ 0x1290,
311
+ 0x22F3,
312
+ 0x32D2,
313
+ 0x4235,
314
+ 0x5214,
315
+ 0x6277,
316
+ 0x7256,
317
+ 0xB5EA,
318
+ 0xA5CB,
319
+ 0x95A8,
320
+ 0x8589,
321
+ 0xF56E,
322
+ 0xE54F,
323
+ 0xD52C,
324
+ 0xC50D,
325
+ 0x34E2,
326
+ 0x24C3,
327
+ 0x14A0,
328
+ 0x0481,
329
+ 0x7466,
330
+ 0x6447,
331
+ 0x5424,
332
+ 0x4405,
333
+ 0xA7DB,
334
+ 0xB7FA,
335
+ 0x8799,
336
+ 0x97B8,
337
+ 0xE75F,
338
+ 0xF77E,
339
+ 0xC71D,
340
+ 0xD73C,
341
+ 0x26D3,
342
+ 0x36F2,
343
+ 0x0691,
344
+ 0x16B0,
345
+ 0x6657,
346
+ 0x7676,
347
+ 0x4615,
348
+ 0x5634,
349
+ 0xD94C,
350
+ 0xC96D,
351
+ 0xF90E,
352
+ 0xE92F,
353
+ 0x99C8,
354
+ 0x89E9,
355
+ 0xB98A,
356
+ 0xA9AB,
357
+ 0x5844,
358
+ 0x4865,
359
+ 0x7806,
360
+ 0x6827,
361
+ 0x18C0,
362
+ 0x08E1,
363
+ 0x3882,
364
+ 0x28A3,
365
+ 0xCB7D,
366
+ 0xDB5C,
367
+ 0xEB3F,
368
+ 0xFB1E,
369
+ 0x8BF9,
370
+ 0x9BD8,
371
+ 0xABBB,
372
+ 0xBB9A,
373
+ 0x4A75,
374
+ 0x5A54,
375
+ 0x6A37,
376
+ 0x7A16,
377
+ 0x0AF1,
378
+ 0x1AD0,
379
+ 0x2AB3,
380
+ 0x3A92,
381
+ 0xFD2E,
382
+ 0xED0F,
383
+ 0xDD6C,
384
+ 0xCD4D,
385
+ 0xBDAA,
386
+ 0xAD8B,
387
+ 0x9DE8,
388
+ 0x8DC9,
389
+ 0x7C26,
390
+ 0x6C07,
391
+ 0x5C64,
392
+ 0x4C45,
393
+ 0x3CA2,
394
+ 0x2C83,
395
+ 0x1CE0,
396
+ 0x0CC1,
397
+ 0xEF1F,
398
+ 0xFF3E,
399
+ 0xCF5D,
400
+ 0xDF7C,
401
+ 0xAF9B,
402
+ 0xBFBA,
403
+ 0x8FD9,
404
+ 0x9FF8,
405
+ 0x6E17,
406
+ 0x7E36,
407
+ 0x4E55,
408
+ 0x5E74,
409
+ 0x2E93,
410
+ 0x3EB2,
411
+ 0x0ED1,
412
+ 0x1EF0,
413
+ ]
414
+
415
+
416
+ def crc16(data: bytes) -> int:
417
+ crc = 0
418
+
419
+ for byte in data:
420
+ crc = ((crc << 8) & 0xFF00) ^ x_mode_m_crc16_lookup[((crc >> 8) & 0xFF) ^ byte]
421
+
422
+ return crc & 0xFFFF
423
+
424
+
425
+ def hash_slot(key: bytes) -> int:
426
+ start = key.find(b"{")
427
+
428
+ if start > -1:
429
+ end = key.find(b"}", start + 1)
430
+
431
+ if end > -1 and end != start + 1:
432
+ key = key[start + 1 : end]
433
+
434
+ return crc16(key) % 16384
474
435
 
475
436
 
476
437
  __all__ = [
477
438
  "hash_slot",
478
439
  "EncodingInsensitiveDict",
479
- "CaseAndEncodingInsensitiveEnum",
480
440
  ]