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.
- {libvalkey-3.0.0/libvalkey.egg-info → libvalkey-4.0.0}/PKG-INFO +1 -1
- {libvalkey-3.0.0 → libvalkey-4.0.0}/libvalkey/libvalkey.pyi +1 -1
- libvalkey-4.0.0/libvalkey/version.py +1 -0
- {libvalkey-3.0.0 → libvalkey-4.0.0/libvalkey.egg-info}/PKG-INFO +1 -1
- {libvalkey-3.0.0 → libvalkey-4.0.0}/src/reader.c +54 -100
- {libvalkey-3.0.0 → libvalkey-4.0.0}/src/reader.h +1 -1
- {libvalkey-3.0.0 → libvalkey-4.0.0}/tests/test_reader.py +16 -23
- libvalkey-3.0.0/libvalkey/version.py +0 -1
- {libvalkey-3.0.0 → libvalkey-4.0.0}/LICENSE +0 -0
- {libvalkey-3.0.0 → libvalkey-4.0.0}/MANIFEST.in +0 -0
- {libvalkey-3.0.0 → libvalkey-4.0.0}/README.md +0 -0
- {libvalkey-3.0.0 → libvalkey-4.0.0}/libvalkey/__init__.py +0 -0
- {libvalkey-3.0.0 → libvalkey-4.0.0}/libvalkey/py.typed +0 -0
- {libvalkey-3.0.0 → libvalkey-4.0.0}/libvalkey.egg-info/SOURCES.txt +0 -0
- {libvalkey-3.0.0 → libvalkey-4.0.0}/libvalkey.egg-info/dependency_links.txt +0 -0
- {libvalkey-3.0.0 → libvalkey-4.0.0}/libvalkey.egg-info/top_level.txt +0 -0
- {libvalkey-3.0.0 → libvalkey-4.0.0}/setup.cfg +0 -0
- {libvalkey-3.0.0 → libvalkey-4.0.0}/setup.py +0 -0
- {libvalkey-3.0.0 → libvalkey-4.0.0}/src/libvalkey.c +0 -0
- {libvalkey-3.0.0 → libvalkey-4.0.0}/src/libvalkey.h +0 -0
- {libvalkey-3.0.0 → libvalkey-4.0.0}/src/pack.c +0 -0
- {libvalkey-3.0.0 → libvalkey-4.0.0}/src/pack.h +0 -0
- {libvalkey-3.0.0 → libvalkey-4.0.0}/tests/test_gc.py +0 -0
- {libvalkey-3.0.0 → libvalkey-4.0.0}/tests/test_pack.py +0 -0
- {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/adlist.c +0 -0
- {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/adlist.h +0 -0
- {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/alloc.c +0 -0
- {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/async.c +0 -0
- {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/async_private.h +0 -0
- {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/cmddef.h +0 -0
- {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/command.c +0 -0
- {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/command.h +0 -0
- {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/crc16.c +0 -0
- {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/dict.c +0 -0
- {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/fmacros.h +0 -0
- {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/net.c +0 -0
- {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/read.c +0 -0
- {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/sds.c +0 -0
- {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/sdsalloc.h +0 -0
- {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/sockcompat.c +0 -0
- {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/ssl.c +0 -0
- {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/valkey.c +0 -0
- {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/valkey_private.h +0 -0
- {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/valkeycluster.c +0 -0
- {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/valkeycluster_ssl.c +0 -0
- {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/vkutil.c +0 -0
- {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/vkutil.h +0 -0
- {libvalkey-3.0.0 → libvalkey-4.0.0}/vendor/libvalkey/src/win32.h +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "4.0.0"
|
|
@@ -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 *
|
|
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
|
-
{"
|
|
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
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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
|
|
113
|
+
return NULL;
|
|
130
114
|
}
|
|
131
|
-
|
|
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
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
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
|
-
|
|
241
|
-
|
|
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
|
-
"
|
|
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
|
|
322
|
+
int convertSetsToLists = 0;
|
|
369
323
|
|
|
370
324
|
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOzzOp", kwlist,
|
|
371
|
-
&protocolErrorClass, &replyErrorClass, &encoding, &errors, ¬EnoughData, &
|
|
325
|
+
&protocolErrorClass, &replyErrorClass, &encoding, &errors, ¬EnoughData, &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->
|
|
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->
|
|
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 *
|
|
506
|
+
static PyObject *Reader_convertSetsToLists(PyObject *obj, void *closure) {
|
|
553
507
|
libvalkey_ReaderObject *self = (libvalkey_ReaderObject*)obj;
|
|
554
|
-
PyObject *result = PyBool_FromLong(self->
|
|
508
|
+
PyObject *result = PyBool_FromLong(self->convertSetsToLists);
|
|
555
509
|
Py_INCREF(result);
|
|
556
510
|
return result;
|
|
557
511
|
}
|
|
@@ -3,7 +3,7 @@ import pytest
|
|
|
3
3
|
|
|
4
4
|
@pytest.fixture(params=[True, False])
|
|
5
5
|
def reader(request):
|
|
6
|
-
return libvalkey.Reader(
|
|
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.
|
|
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
|
-
|
|
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.
|
|
158
|
-
assert [b"tangerine",
|
|
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
|
-
|
|
167
|
-
|
|
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
|
-
|
|
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.
|
|
184
|
-
assert [
|
|
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
|
|
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
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|