libvalkey 3.0.0__tar.gz → 4.0.0__tar.gz

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 (48) hide show
  1. {libvalkey-3.0.0/libvalkey.egg-info → libvalkey-4.0.0}/PKG-INFO +1 -1
  2. {libvalkey-3.0.0 → libvalkey-4.0.0}/libvalkey/libvalkey.pyi +1 -1
  3. libvalkey-4.0.0/libvalkey/version.py +1 -0
  4. {libvalkey-3.0.0 → libvalkey-4.0.0/libvalkey.egg-info}/PKG-INFO +1 -1
  5. {libvalkey-3.0.0 → libvalkey-4.0.0}/src/reader.c +54 -100
  6. {libvalkey-3.0.0 → libvalkey-4.0.0}/src/reader.h +1 -1
  7. {libvalkey-3.0.0 → libvalkey-4.0.0}/tests/test_reader.py +16 -23
  8. libvalkey-3.0.0/libvalkey/version.py +0 -1
  9. {libvalkey-3.0.0 → libvalkey-4.0.0}/LICENSE +0 -0
  10. {libvalkey-3.0.0 → libvalkey-4.0.0}/MANIFEST.in +0 -0
  11. {libvalkey-3.0.0 → libvalkey-4.0.0}/README.md +0 -0
  12. {libvalkey-3.0.0 → libvalkey-4.0.0}/libvalkey/__init__.py +0 -0
  13. {libvalkey-3.0.0 → libvalkey-4.0.0}/libvalkey/py.typed +0 -0
  14. {libvalkey-3.0.0 → libvalkey-4.0.0}/libvalkey.egg-info/SOURCES.txt +0 -0
  15. {libvalkey-3.0.0 → libvalkey-4.0.0}/libvalkey.egg-info/dependency_links.txt +0 -0
  16. {libvalkey-3.0.0 → libvalkey-4.0.0}/libvalkey.egg-info/top_level.txt +0 -0
  17. {libvalkey-3.0.0 → libvalkey-4.0.0}/setup.cfg +0 -0
  18. {libvalkey-3.0.0 → libvalkey-4.0.0}/setup.py +0 -0
  19. {libvalkey-3.0.0 → libvalkey-4.0.0}/src/libvalkey.c +0 -0
  20. {libvalkey-3.0.0 → libvalkey-4.0.0}/src/libvalkey.h +0 -0
  21. {libvalkey-3.0.0 → libvalkey-4.0.0}/src/pack.c +0 -0
  22. {libvalkey-3.0.0 → libvalkey-4.0.0}/src/pack.h +0 -0
  23. {libvalkey-3.0.0 → libvalkey-4.0.0}/tests/test_gc.py +0 -0
  24. {libvalkey-3.0.0 → libvalkey-4.0.0}/tests/test_pack.py +0 -0
  25. {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/adlist.c +0 -0
  26. {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/adlist.h +0 -0
  27. {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/alloc.c +0 -0
  28. {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/async.c +0 -0
  29. {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/async_private.h +0 -0
  30. {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/cmddef.h +0 -0
  31. {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/command.c +0 -0
  32. {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/command.h +0 -0
  33. {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/crc16.c +0 -0
  34. {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/dict.c +0 -0
  35. {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/fmacros.h +0 -0
  36. {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/net.c +0 -0
  37. {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/read.c +0 -0
  38. {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/sds.c +0 -0
  39. {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/sdsalloc.h +0 -0
  40. {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/sockcompat.c +0 -0
  41. {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/ssl.c +0 -0
  42. {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/valkey.c +0 -0
  43. {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/valkey_private.h +0 -0
  44. {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/valkeycluster.c +0 -0
  45. {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/valkeycluster_ssl.c +0 -0
  46. {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/vkutil.c +0 -0
  47. {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/vkutil.h +0 -0
  48. {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/win32.h +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: libvalkey
3
- Version: 3.0.0
3
+ Version: 4.0.0
4
4
  Summary: Python wrapper for libvalkey
5
5
  Home-page: https://github.com/valkey-io/libvalkey-py
6
6
  Author: libvalkey-py authors
@@ -21,7 +21,7 @@ class Reader:
21
21
  encoding: Optional[str] = ...,
22
22
  errors: Optional[str] = ...,
23
23
  notEnoughData: Any = ...,
24
- listOnly: bool = ...,
24
+ convertSetsToLists: bool = ...,
25
25
  ) -> None: ...
26
26
 
27
27
  def feed(
@@ -0,0 +1 @@
1
+ __version__ = "4.0.0"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: libvalkey
3
- Version: 3.0.0
3
+ Version: 4.0.0
4
4
  Summary: Python wrapper for libvalkey
5
5
  Home-page: https://github.com/valkey-io/libvalkey-py
6
6
  Author: libvalkey-py authors
@@ -14,7 +14,7 @@ static PyObject *Reader_getmaxbuf(libvalkey_ReaderObject *self);
14
14
  static PyObject *Reader_len(libvalkey_ReaderObject *self);
15
15
  static PyObject *Reader_has_data(libvalkey_ReaderObject *self);
16
16
  static PyObject *Reader_set_encoding(libvalkey_ReaderObject *self, PyObject *args, PyObject *kwds);
17
- static PyObject *Reader_listOnly(PyObject *self, void *closure);
17
+ static PyObject *Reader_convertSetsToLists(PyObject *self, void *closure);
18
18
 
19
19
  static PyMethodDef libvalkey_ReaderMethods[] = {
20
20
  {"feed", (PyCFunction)Reader_feed, METH_VARARGS, NULL },
@@ -28,7 +28,7 @@ static PyMethodDef libvalkey_ReaderMethods[] = {
28
28
  };
29
29
 
30
30
  static PyGetSetDef libvalkey_ReaderGetSet[] = {
31
- {"listOnly", (getter)Reader_listOnly, NULL, NULL, NULL},
31
+ {"convertSetsToLists", (getter)Reader_convertSetsToLists, NULL, NULL, NULL},
32
32
  {NULL} /* Sentinel */
33
33
  };
34
34
 
@@ -73,88 +73,46 @@ PyTypeObject libvalkey_ReaderType = {
73
73
  Reader_new, /*tp_new */
74
74
  };
75
75
 
76
- static int tryParentize_impl(const valkeyReadTask *task, PyObject *obj,
77
- PyObject *parent, libvalkey_ReaderObject *self) {
78
- switch (task->parent->type) {
79
- case VALKEY_REPLY_MAP:
80
- if (task->idx % 2 == 0) {
81
- /* Save the object as a key. */
82
- self->pendingObject = obj;
83
- } else {
84
- if (self->pendingObject == NULL) {
85
- Py_DECREF(obj);
86
- return -1;
87
- }
88
- if (PyDict_SetItem(parent, self->pendingObject, obj) < 0) {
89
- Py_DECREF(obj);
90
- Py_DECREF(self->pendingObject);
76
+ static void *tryParentize(const valkeyReadTask *task, PyObject *obj) {
77
+ libvalkey_ReaderObject *self = (libvalkey_ReaderObject*)task->privdata;
78
+ if (task && task->parent) {
79
+ PyObject *parent = (PyObject*)task->parent->obj;
80
+ switch (task->parent->type) {
81
+ case VALKEY_REPLY_MAP:
82
+ if (task->idx % 2 == 0) {
83
+ /* Save the object as a key. */
84
+ self->pendingObject = obj;
85
+ } else {
86
+ if (self->pendingObject == NULL) {
87
+ Py_DECREF(obj);
88
+ return NULL;
89
+ }
90
+ if (PyDict_SetItem(parent, self->pendingObject, obj) < 0) {
91
+ Py_DECREF(obj);
92
+ Py_DECREF(self->pendingObject);
93
+ self->pendingObject = NULL;
94
+ return NULL;
95
+ }
91
96
  self->pendingObject = NULL;
92
- return -1;
93
97
  }
94
- self->pendingObject = NULL;
95
- }
96
- break;
97
- case VALKEY_REPLY_SET:
98
- assert(PyAnySet_CheckExact(parent));
99
- if (PySet_Add(parent, obj) < 0) {
100
- Py_DECREF(obj);
101
- return -1;
102
- }
103
- break;
104
- default:
105
- assert(PyList_CheckExact(parent));
106
- if (PyList_SetItem(parent, task->idx, obj) < 0) {
107
- Py_DECREF(obj);
108
- return -1;
109
- }
110
- }
111
- return 0;
112
- }
113
-
114
- static int tryParentize_ListOnly(const valkeyReadTask *task, PyObject *obj,
115
- PyObject *parent, libvalkey_ReaderObject *self) {
116
- switch (task->parent->type) {
117
- case VALKEY_REPLY_MAP:
118
- if (task->idx % 2 == 0) {
119
- /* Set a temporary item to save the object as a key. */
120
- self->pendingObject = PyTuple_New(2);
121
- if (self->pendingObject == NULL) {
122
- Py_DECREF(obj);
123
- return -1;
98
+ break;
99
+ case VALKEY_REPLY_SET:
100
+ if (!self->convertSetsToLists) {
101
+ assert(PyAnySet_CheckExact(parent));
102
+ if (PySet_Add(parent, obj) < 0) {
103
+ Py_DECREF(obj);
104
+ return NULL;
105
+ }
106
+ break;
124
107
  }
125
- PyTuple_SET_ITEM(self->pendingObject, 0, obj);
126
- } else {
127
- if (self->pendingObject == NULL) {
108
+ /* fallthrough */
109
+ default:
110
+ assert(PyList_CheckExact(parent));
111
+ if (PyList_SetItem(parent, task->idx, obj) < 0) {
128
112
  Py_DECREF(obj);
129
- return -1;
113
+ return NULL;
130
114
  }
131
- PyTuple_SET_ITEM(self->pendingObject, 1, obj);
132
- int res = PyList_Append(parent, self->pendingObject);
133
- Py_DECREF(self->pendingObject);
134
- self->pendingObject = NULL;
135
- if (res < 0)
136
- return -1;
137
- }
138
- break;
139
- default:
140
- assert(PyList_CheckExact(parent));
141
- if (PyList_SetItem(parent, task->idx, obj) < 0) {
142
- Py_DECREF(obj);
143
- return -1;
144
- }
145
- }
146
- return 0;
147
- }
148
-
149
- static void *tryParentize(const valkeyReadTask *task, PyObject *obj) {
150
- libvalkey_ReaderObject *self = (libvalkey_ReaderObject*)task->privdata;
151
- if (task && task->parent) {
152
- PyObject *parent = (PyObject*)task->parent->obj;
153
- int res = self->listOnly
154
- ? tryParentize_ListOnly(task, obj, parent, self)
155
- : tryParentize_impl(task, obj, parent, self);
156
- if (res < 0)
157
- return NULL;
115
+ }
158
116
  }
159
117
  return obj;
160
118
  }
@@ -224,22 +182,18 @@ static void *createStringObject(const valkeyReadTask *task, char *str, size_t le
224
182
  static void *createArrayObject(const valkeyReadTask *task, size_t elements) {
225
183
  libvalkey_ReaderObject *self = (libvalkey_ReaderObject*)task->privdata;
226
184
  PyObject *obj;
227
- if (self->listOnly) {
228
- /* For map, don't preallocate listand use append later. */
229
- if (task->type == VALKEY_REPLY_MAP)
230
- elements = 0;
231
- obj = PyList_New(elements);
232
- } else {
233
- switch (task->type) {
234
- case VALKEY_REPLY_MAP:
235
- obj = PyDict_New();
236
- break;
237
- case VALKEY_REPLY_SET:
185
+ switch (task->type) {
186
+ case VALKEY_REPLY_MAP:
187
+ obj = PyDict_New();
188
+ break;
189
+ case VALKEY_REPLY_SET:
190
+ if (!self->convertSetsToLists) {
238
191
  obj = PySet_New(NULL);
239
192
  break;
240
- default:
241
- obj = PyList_New(elements);
242
- }
193
+ }
194
+ /* fallthrough */
195
+ default:
196
+ obj = PyList_New(elements);
243
197
  }
244
198
  return tryParentize(task, obj);
245
199
  }
@@ -357,7 +311,7 @@ static int Reader_init(libvalkey_ReaderObject *self, PyObject *args, PyObject *k
357
311
  "encoding",
358
312
  "errors",
359
313
  "notEnoughData",
360
- "listOnly",
314
+ "convertSetsToLists",
361
315
  NULL,
362
316
  };
363
317
  PyObject *protocolErrorClass = NULL;
@@ -365,10 +319,10 @@ static int Reader_init(libvalkey_ReaderObject *self, PyObject *args, PyObject *k
365
319
  PyObject *notEnoughData = NULL;
366
320
  char *encoding = NULL;
367
321
  char *errors = NULL;
368
- int listOnly = 0;
322
+ int convertSetsToLists = 0;
369
323
 
370
324
  if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOzzOp", kwlist,
371
- &protocolErrorClass, &replyErrorClass, &encoding, &errors, &notEnoughData, &listOnly))
325
+ &protocolErrorClass, &replyErrorClass, &encoding, &errors, &notEnoughData, &convertSetsToLists))
372
326
  return -1;
373
327
 
374
328
  if (protocolErrorClass)
@@ -386,7 +340,7 @@ static int Reader_init(libvalkey_ReaderObject *self, PyObject *args, PyObject *k
386
340
  Py_INCREF(self->notEnoughDataObject);
387
341
  }
388
342
 
389
- self->listOnly = listOnly;
343
+ self->convertSetsToLists = convertSetsToLists;
390
344
 
391
345
  return _Reader_set_encoding(self, encoding, errors);
392
346
  }
@@ -406,7 +360,7 @@ static PyObject *Reader_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
406
360
  self->protocolErrorClass = LIBVALKEY_STATE->VkErr_ProtocolError;
407
361
  self->replyErrorClass = LIBVALKEY_STATE->VkErr_ReplyError;
408
362
  self->pendingObject = NULL;
409
- self->listOnly = 0;
363
+ self->convertSetsToLists = 0;
410
364
  Py_INCREF(self->protocolErrorClass);
411
365
  Py_INCREF(self->replyErrorClass);
412
366
  Py_INCREF(self->notEnoughDataObject);
@@ -549,9 +503,9 @@ static PyObject *Reader_set_encoding(libvalkey_ReaderObject *self, PyObject *arg
549
503
 
550
504
  }
551
505
 
552
- static PyObject *Reader_listOnly(PyObject *obj, void *closure) {
506
+ static PyObject *Reader_convertSetsToLists(PyObject *obj, void *closure) {
553
507
  libvalkey_ReaderObject *self = (libvalkey_ReaderObject*)obj;
554
- PyObject *result = PyBool_FromLong(self->listOnly);
508
+ PyObject *result = PyBool_FromLong(self->convertSetsToLists);
555
509
  Py_INCREF(result);
556
510
  return result;
557
511
  }
@@ -13,7 +13,7 @@ typedef struct {
13
13
  PyObject *protocolErrorClass;
14
14
  PyObject *replyErrorClass;
15
15
  PyObject *notEnoughDataObject;
16
- int listOnly;
16
+ int convertSetsToLists;
17
17
 
18
18
  PyObject *pendingObject;
19
19
 
@@ -3,7 +3,7 @@ import pytest
3
3
 
4
4
  @pytest.fixture(params=[True, False])
5
5
  def reader(request):
6
- return libvalkey.Reader(listOnly=request.param)
6
+ return libvalkey.Reader(convertSetsToLists=request.param)
7
7
 
8
8
  # def reply():
9
9
  # return reader.gets()
@@ -138,55 +138,48 @@ def test_set(reader):
138
138
  reader.feed(b"~3\r\n+tangerine\r\n_\r\n,10.5\r\n")
139
139
  expected = (
140
140
  [b"tangerine", None, 10.5]
141
- if reader.listOnly
141
+ if reader.convertSetsToLists
142
142
  else {b"tangerine", None, 10.5}
143
143
  )
144
144
  assert expected == reader.gets()
145
145
 
146
146
  def test_dict(reader):
147
147
  reader.feed(b"%2\r\n+radius\r\n,4.5\r\n+diameter\r\n:9\r\n")
148
- expected = (
149
- [(b"radius", 4.5), (b"diameter", 9)]
150
- if reader.listOnly
151
- else {b"radius": 4.5, b"diameter": 9}
152
- )
153
- assert expected == reader.gets()
148
+ assert {b"radius": 4.5, b"diameter": 9} == reader.gets()
154
149
 
155
150
  def test_set_with_nested_dict(reader):
156
151
  reader.feed(b"~2\r\n+tangerine\r\n%1\r\n+a\r\n:1\r\n")
157
- if reader.listOnly:
158
- assert [b"tangerine", [(b"a", 1)]] == reader.gets()
152
+ if reader.convertSetsToLists:
153
+ assert [b"tangerine", {b"a": 1}] == reader.gets()
159
154
  else:
160
155
  with pytest.raises(TypeError):
161
156
  reader.gets()
162
157
 
163
158
  def test_dict_with_nested_set(reader):
164
159
  reader.feed(b"%1\r\n+a\r\n~2\r\n:1\r\n:2\r\n")
165
- expected = (
166
- [(b"a", [1, 2])]
167
- if reader.listOnly
168
- else {b"a": {1, 2}}
169
- )
160
+ expected: dict[bytes, set[int] | list[int]] = {b"a": {1, 2}}
161
+ if reader.convertSetsToLists:
162
+ expected[b"a"] = list(expected[b"a"])
170
163
  assert expected == reader.gets()
171
164
 
172
165
  def test_map_inside_list(reader):
173
166
  reader.feed(b"*1\r\n%1\r\n+a\r\n:1\r\n")
174
- expected = (
175
- [[(b"a", 1)]]
176
- if reader.listOnly
177
- else [{b"a": 1}]
178
- )
179
- assert expected == reader.gets()
167
+ assert [{b"a": 1}] == reader.gets()
180
168
 
181
169
  def test_map_inside_set(reader):
182
170
  reader.feed(b"~1\r\n%1\r\n+a\r\n:1\r\n")
183
- if reader.listOnly:
184
- assert [[(b"a", 1)]] == reader.gets()
171
+ if reader.convertSetsToLists:
172
+ assert [{b"a": 1}] == reader.gets()
185
173
  else:
186
174
  # Map inside set is not allowed in Python
187
175
  with pytest.raises(TypeError):
188
176
  reader.gets()
189
177
 
178
+ def test_set_as_map_key(reader):
179
+ reader.feed(b"%1\r\n~1\r\n:1\r\n:2\r\n")
180
+ with pytest.raises(TypeError):
181
+ reader.gets()
182
+
190
183
  def test_vector(reader):
191
184
  reader.feed(b">4\r\n+pubsub\r\n+message\r\n+channel\r\n+message\r\n")
192
185
  assert [b"pubsub", b"message", b"channel", b"message"] == reader.gets()
@@ -1 +0,0 @@
1
- __version__ = "3.0.0"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes