Branch data Line data Source code
1 : : /*[clinic input]
2 : : preserve
3 : : [clinic start generated code]*/
4 : :
5 : : PyDoc_STRVAR(_pickle_Pickler_clear_memo__doc__,
6 : : "clear_memo($self, /)\n"
7 : : "--\n"
8 : : "\n"
9 : : "Clears the pickler\'s \"memo\".\n"
10 : : "\n"
11 : : "The memo is the data structure that remembers which objects the\n"
12 : : "pickler has already seen, so that shared or recursive objects are\n"
13 : : "pickled by reference and not by value. This method is useful when\n"
14 : : "re-using picklers.");
15 : :
16 : : #define _PICKLE_PICKLER_CLEAR_MEMO_METHODDEF \
17 : : {"clear_memo", (PyCFunction)_pickle_Pickler_clear_memo, METH_NOARGS, _pickle_Pickler_clear_memo__doc__},
18 : :
19 : : static PyObject *
20 : : _pickle_Pickler_clear_memo_impl(PicklerObject *self);
21 : :
22 : : static PyObject *
23 : 6 : _pickle_Pickler_clear_memo(PicklerObject *self, PyObject *Py_UNUSED(ignored))
24 : : {
25 : 6 : return _pickle_Pickler_clear_memo_impl(self);
26 : : }
27 : :
28 : : PyDoc_STRVAR(_pickle_Pickler_dump__doc__,
29 : : "dump($self, obj, /)\n"
30 : : "--\n"
31 : : "\n"
32 : : "Write a pickled representation of the given object to the open file.");
33 : :
34 : : #define _PICKLE_PICKLER_DUMP_METHODDEF \
35 : : {"dump", (PyCFunction)_pickle_Pickler_dump, METH_O, _pickle_Pickler_dump__doc__},
36 : :
37 : : PyDoc_STRVAR(_pickle_Pickler___sizeof____doc__,
38 : : "__sizeof__($self, /)\n"
39 : : "--\n"
40 : : "\n"
41 : : "Returns size in memory, in bytes.");
42 : :
43 : : #define _PICKLE_PICKLER___SIZEOF___METHODDEF \
44 : : {"__sizeof__", (PyCFunction)_pickle_Pickler___sizeof__, METH_NOARGS, _pickle_Pickler___sizeof____doc__},
45 : :
46 : : static Py_ssize_t
47 : : _pickle_Pickler___sizeof___impl(PicklerObject *self);
48 : :
49 : : static PyObject *
50 : 2 : _pickle_Pickler___sizeof__(PicklerObject *self, PyObject *Py_UNUSED(ignored))
51 : : {
52 : 2 : PyObject *return_value = NULL;
53 : : Py_ssize_t _return_value;
54 : :
55 : 2 : _return_value = _pickle_Pickler___sizeof___impl(self);
56 [ - + - - ]: 2 : if ((_return_value == -1) && PyErr_Occurred()) {
57 : 0 : goto exit;
58 : : }
59 : 2 : return_value = PyLong_FromSsize_t(_return_value);
60 : :
61 : 2 : exit:
62 : 2 : return return_value;
63 : : }
64 : :
65 : : PyDoc_STRVAR(_pickle_Pickler___init____doc__,
66 : : "Pickler(file, protocol=None, fix_imports=True, buffer_callback=None)\n"
67 : : "--\n"
68 : : "\n"
69 : : "This takes a binary file for writing a pickle data stream.\n"
70 : : "\n"
71 : : "The optional *protocol* argument tells the pickler to use the given\n"
72 : : "protocol; supported protocols are 0, 1, 2, 3, 4 and 5. The default\n"
73 : : "protocol is 4. It was introduced in Python 3.4, and is incompatible\n"
74 : : "with previous versions.\n"
75 : : "\n"
76 : : "Specifying a negative protocol version selects the highest protocol\n"
77 : : "version supported. The higher the protocol used, the more recent the\n"
78 : : "version of Python needed to read the pickle produced.\n"
79 : : "\n"
80 : : "The *file* argument must have a write() method that accepts a single\n"
81 : : "bytes argument. It can thus be a file object opened for binary\n"
82 : : "writing, an io.BytesIO instance, or any other custom object that meets\n"
83 : : "this interface.\n"
84 : : "\n"
85 : : "If *fix_imports* is True and protocol is less than 3, pickle will try\n"
86 : : "to map the new Python 3 names to the old module names used in Python\n"
87 : : "2, so that the pickle data stream is readable with Python 2.\n"
88 : : "\n"
89 : : "If *buffer_callback* is None (the default), buffer views are\n"
90 : : "serialized into *file* as part of the pickle stream.\n"
91 : : "\n"
92 : : "If *buffer_callback* is not None, then it can be called any number\n"
93 : : "of times with a buffer view. If the callback returns a false value\n"
94 : : "(such as None), the given buffer is out-of-band; otherwise the\n"
95 : : "buffer is serialized in-band, i.e. inside the pickle stream.\n"
96 : : "\n"
97 : : "It is an error if *buffer_callback* is not None and *protocol*\n"
98 : : "is None or smaller than 5.");
99 : :
100 : : static int
101 : : _pickle_Pickler___init___impl(PicklerObject *self, PyObject *file,
102 : : PyObject *protocol, int fix_imports,
103 : : PyObject *buffer_callback);
104 : :
105 : : static int
106 : 41164 : _pickle_Pickler___init__(PyObject *self, PyObject *args, PyObject *kwargs)
107 : : {
108 : 41164 : int return_value = -1;
109 : : static const char * const _keywords[] = {"file", "protocol", "fix_imports", "buffer_callback", NULL};
110 : : static _PyArg_Parser _parser = {NULL, _keywords, "Pickler", 0};
111 : : PyObject *argsbuf[4];
112 : : PyObject * const *fastargs;
113 : 41164 : Py_ssize_t nargs = PyTuple_GET_SIZE(args);
114 [ + + ]: 41164 : Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
115 : : PyObject *file;
116 : 41164 : PyObject *protocol = Py_None;
117 : 41164 : int fix_imports = 1;
118 : 41164 : PyObject *buffer_callback = Py_None;
119 : :
120 [ + + + - : 41164 : fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 4, 0, argsbuf);
+ - + - ]
121 [ - + ]: 41164 : if (!fastargs) {
122 : 0 : goto exit;
123 : : }
124 : 41164 : file = fastargs[0];
125 [ + + ]: 41164 : if (!noptargs) {
126 : 14 : goto skip_optional_pos;
127 : : }
128 [ + - ]: 41150 : if (fastargs[1]) {
129 : 41150 : protocol = fastargs[1];
130 [ + + ]: 41150 : if (!--noptargs) {
131 : 41030 : goto skip_optional_pos;
132 : : }
133 : : }
134 [ - + ]: 120 : if (fastargs[2]) {
135 : 0 : fix_imports = PyObject_IsTrue(fastargs[2]);
136 [ # # ]: 0 : if (fix_imports < 0) {
137 : 0 : goto exit;
138 : : }
139 [ # # ]: 0 : if (!--noptargs) {
140 : 0 : goto skip_optional_pos;
141 : : }
142 : : }
143 : 120 : buffer_callback = fastargs[3];
144 : 41164 : skip_optional_pos:
145 : 41164 : return_value = _pickle_Pickler___init___impl((PicklerObject *)self, file, protocol, fix_imports, buffer_callback);
146 : :
147 : 41164 : exit:
148 : 41164 : return return_value;
149 : : }
150 : :
151 : : PyDoc_STRVAR(_pickle_PicklerMemoProxy_clear__doc__,
152 : : "clear($self, /)\n"
153 : : "--\n"
154 : : "\n"
155 : : "Remove all items from memo.");
156 : :
157 : : #define _PICKLE_PICKLERMEMOPROXY_CLEAR_METHODDEF \
158 : : {"clear", (PyCFunction)_pickle_PicklerMemoProxy_clear, METH_NOARGS, _pickle_PicklerMemoProxy_clear__doc__},
159 : :
160 : : static PyObject *
161 : : _pickle_PicklerMemoProxy_clear_impl(PicklerMemoProxyObject *self);
162 : :
163 : : static PyObject *
164 : 0 : _pickle_PicklerMemoProxy_clear(PicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
165 : : {
166 : 0 : return _pickle_PicklerMemoProxy_clear_impl(self);
167 : : }
168 : :
169 : : PyDoc_STRVAR(_pickle_PicklerMemoProxy_copy__doc__,
170 : : "copy($self, /)\n"
171 : : "--\n"
172 : : "\n"
173 : : "Copy the memo to a new object.");
174 : :
175 : : #define _PICKLE_PICKLERMEMOPROXY_COPY_METHODDEF \
176 : : {"copy", (PyCFunction)_pickle_PicklerMemoProxy_copy, METH_NOARGS, _pickle_PicklerMemoProxy_copy__doc__},
177 : :
178 : : static PyObject *
179 : : _pickle_PicklerMemoProxy_copy_impl(PicklerMemoProxyObject *self);
180 : :
181 : : static PyObject *
182 : 0 : _pickle_PicklerMemoProxy_copy(PicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
183 : : {
184 : 0 : return _pickle_PicklerMemoProxy_copy_impl(self);
185 : : }
186 : :
187 : : PyDoc_STRVAR(_pickle_PicklerMemoProxy___reduce____doc__,
188 : : "__reduce__($self, /)\n"
189 : : "--\n"
190 : : "\n"
191 : : "Implement pickle support.");
192 : :
193 : : #define _PICKLE_PICKLERMEMOPROXY___REDUCE___METHODDEF \
194 : : {"__reduce__", (PyCFunction)_pickle_PicklerMemoProxy___reduce__, METH_NOARGS, _pickle_PicklerMemoProxy___reduce____doc__},
195 : :
196 : : static PyObject *
197 : : _pickle_PicklerMemoProxy___reduce___impl(PicklerMemoProxyObject *self);
198 : :
199 : : static PyObject *
200 : 0 : _pickle_PicklerMemoProxy___reduce__(PicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
201 : : {
202 : 0 : return _pickle_PicklerMemoProxy___reduce___impl(self);
203 : : }
204 : :
205 : : PyDoc_STRVAR(_pickle_Unpickler_load__doc__,
206 : : "load($self, /)\n"
207 : : "--\n"
208 : : "\n"
209 : : "Load a pickle.\n"
210 : : "\n"
211 : : "Read a pickled object representation from the open file object given\n"
212 : : "in the constructor, and return the reconstituted object hierarchy\n"
213 : : "specified therein.");
214 : :
215 : : #define _PICKLE_UNPICKLER_LOAD_METHODDEF \
216 : : {"load", (PyCFunction)_pickle_Unpickler_load, METH_NOARGS, _pickle_Unpickler_load__doc__},
217 : :
218 : : static PyObject *
219 : : _pickle_Unpickler_load_impl(UnpicklerObject *self);
220 : :
221 : : static PyObject *
222 : 12250 : _pickle_Unpickler_load(UnpicklerObject *self, PyObject *Py_UNUSED(ignored))
223 : : {
224 : 12250 : return _pickle_Unpickler_load_impl(self);
225 : : }
226 : :
227 : : PyDoc_STRVAR(_pickle_Unpickler_find_class__doc__,
228 : : "find_class($self, module_name, global_name, /)\n"
229 : : "--\n"
230 : : "\n"
231 : : "Return an object from a specified module.\n"
232 : : "\n"
233 : : "If necessary, the module will be imported. Subclasses may override\n"
234 : : "this method (e.g. to restrict unpickling of arbitrary classes and\n"
235 : : "functions).\n"
236 : : "\n"
237 : : "This method is called whenever a class or a function object is\n"
238 : : "needed. Both arguments passed are str objects.");
239 : :
240 : : #define _PICKLE_UNPICKLER_FIND_CLASS_METHODDEF \
241 : : {"find_class", _PyCFunction_CAST(_pickle_Unpickler_find_class), METH_FASTCALL, _pickle_Unpickler_find_class__doc__},
242 : :
243 : : static PyObject *
244 : : _pickle_Unpickler_find_class_impl(UnpicklerObject *self,
245 : : PyObject *module_name,
246 : : PyObject *global_name);
247 : :
248 : : static PyObject *
249 : 140605 : _pickle_Unpickler_find_class(UnpicklerObject *self, PyObject *const *args, Py_ssize_t nargs)
250 : : {
251 : 140605 : PyObject *return_value = NULL;
252 : : PyObject *module_name;
253 : : PyObject *global_name;
254 : :
255 [ + - - + : 140605 : if (!_PyArg_CheckPositional("find_class", nargs, 2, 2)) {
- - ]
256 : 0 : goto exit;
257 : : }
258 : 140605 : module_name = args[0];
259 : 140605 : global_name = args[1];
260 : 140605 : return_value = _pickle_Unpickler_find_class_impl(self, module_name, global_name);
261 : :
262 : 140605 : exit:
263 : 140605 : return return_value;
264 : : }
265 : :
266 : : PyDoc_STRVAR(_pickle_Unpickler___sizeof____doc__,
267 : : "__sizeof__($self, /)\n"
268 : : "--\n"
269 : : "\n"
270 : : "Returns size in memory, in bytes.");
271 : :
272 : : #define _PICKLE_UNPICKLER___SIZEOF___METHODDEF \
273 : : {"__sizeof__", (PyCFunction)_pickle_Unpickler___sizeof__, METH_NOARGS, _pickle_Unpickler___sizeof____doc__},
274 : :
275 : : static Py_ssize_t
276 : : _pickle_Unpickler___sizeof___impl(UnpicklerObject *self);
277 : :
278 : : static PyObject *
279 : 15 : _pickle_Unpickler___sizeof__(UnpicklerObject *self, PyObject *Py_UNUSED(ignored))
280 : : {
281 : 15 : PyObject *return_value = NULL;
282 : : Py_ssize_t _return_value;
283 : :
284 : 15 : _return_value = _pickle_Unpickler___sizeof___impl(self);
285 [ - + - - ]: 15 : if ((_return_value == -1) && PyErr_Occurred()) {
286 : 0 : goto exit;
287 : : }
288 : 15 : return_value = PyLong_FromSsize_t(_return_value);
289 : :
290 : 15 : exit:
291 : 15 : return return_value;
292 : : }
293 : :
294 : : PyDoc_STRVAR(_pickle_Unpickler___init____doc__,
295 : : "Unpickler(file, *, fix_imports=True, encoding=\'ASCII\', errors=\'strict\',\n"
296 : : " buffers=())\n"
297 : : "--\n"
298 : : "\n"
299 : : "This takes a binary file for reading a pickle data stream.\n"
300 : : "\n"
301 : : "The protocol version of the pickle is detected automatically, so no\n"
302 : : "protocol argument is needed. Bytes past the pickled object\'s\n"
303 : : "representation are ignored.\n"
304 : : "\n"
305 : : "The argument *file* must have two methods, a read() method that takes\n"
306 : : "an integer argument, and a readline() method that requires no\n"
307 : : "arguments. Both methods should return bytes. Thus *file* can be a\n"
308 : : "binary file object opened for reading, an io.BytesIO object, or any\n"
309 : : "other custom object that meets this interface.\n"
310 : : "\n"
311 : : "Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n"
312 : : "which are used to control compatibility support for pickle stream\n"
313 : : "generated by Python 2. If *fix_imports* is True, pickle will try to\n"
314 : : "map the old Python 2 names to the new names used in Python 3. The\n"
315 : : "*encoding* and *errors* tell pickle how to decode 8-bit string\n"
316 : : "instances pickled by Python 2; these default to \'ASCII\' and \'strict\',\n"
317 : : "respectively. The *encoding* can be \'bytes\' to read these 8-bit\n"
318 : : "string instances as bytes objects.");
319 : :
320 : : static int
321 : : _pickle_Unpickler___init___impl(UnpicklerObject *self, PyObject *file,
322 : : int fix_imports, const char *encoding,
323 : : const char *errors, PyObject *buffers);
324 : :
325 : : static int
326 : 12170 : _pickle_Unpickler___init__(PyObject *self, PyObject *args, PyObject *kwargs)
327 : : {
328 : 12170 : int return_value = -1;
329 : : static const char * const _keywords[] = {"file", "fix_imports", "encoding", "errors", "buffers", NULL};
330 : : static _PyArg_Parser _parser = {NULL, _keywords, "Unpickler", 0};
331 : : PyObject *argsbuf[5];
332 : : PyObject * const *fastargs;
333 : 12170 : Py_ssize_t nargs = PyTuple_GET_SIZE(args);
334 [ + + ]: 12170 : Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
335 : : PyObject *file;
336 : 12170 : int fix_imports = 1;
337 : 12170 : const char *encoding = "ASCII";
338 : 12170 : const char *errors = "strict";
339 : 12170 : PyObject *buffers = NULL;
340 : :
341 [ + + + - : 12170 : fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 1, 0, argsbuf);
+ - + - ]
342 [ - + ]: 12170 : if (!fastargs) {
343 : 0 : goto exit;
344 : : }
345 : 12170 : file = fastargs[0];
346 [ + + ]: 12170 : if (!noptargs) {
347 : 12107 : goto skip_optional_kwonly;
348 : : }
349 [ - + ]: 63 : if (fastargs[1]) {
350 : 0 : fix_imports = PyObject_IsTrue(fastargs[1]);
351 [ # # ]: 0 : if (fix_imports < 0) {
352 : 0 : goto exit;
353 : : }
354 [ # # ]: 0 : if (!--noptargs) {
355 : 0 : goto skip_optional_kwonly;
356 : : }
357 : : }
358 [ + + ]: 63 : if (fastargs[2]) {
359 [ - + ]: 23 : if (!PyUnicode_Check(fastargs[2])) {
360 : 0 : _PyArg_BadArgument("Unpickler", "argument 'encoding'", "str", fastargs[2]);
361 : 0 : goto exit;
362 : : }
363 : : Py_ssize_t encoding_length;
364 : 23 : encoding = PyUnicode_AsUTF8AndSize(fastargs[2], &encoding_length);
365 [ - + ]: 23 : if (encoding == NULL) {
366 : 0 : goto exit;
367 : : }
368 [ - + ]: 23 : if (strlen(encoding) != (size_t)encoding_length) {
369 : 0 : PyErr_SetString(PyExc_ValueError, "embedded null character");
370 : 0 : goto exit;
371 : : }
372 [ + + ]: 23 : if (!--noptargs) {
373 : 8 : goto skip_optional_kwonly;
374 : : }
375 : : }
376 [ + + ]: 55 : if (fastargs[3]) {
377 [ - + ]: 15 : if (!PyUnicode_Check(fastargs[3])) {
378 : 0 : _PyArg_BadArgument("Unpickler", "argument 'errors'", "str", fastargs[3]);
379 : 0 : goto exit;
380 : : }
381 : : Py_ssize_t errors_length;
382 : 15 : errors = PyUnicode_AsUTF8AndSize(fastargs[3], &errors_length);
383 [ - + ]: 15 : if (errors == NULL) {
384 : 0 : goto exit;
385 : : }
386 [ - + ]: 15 : if (strlen(errors) != (size_t)errors_length) {
387 : 0 : PyErr_SetString(PyExc_ValueError, "embedded null character");
388 : 0 : goto exit;
389 : : }
390 [ + - ]: 15 : if (!--noptargs) {
391 : 15 : goto skip_optional_kwonly;
392 : : }
393 : : }
394 : 40 : buffers = fastargs[4];
395 : 12170 : skip_optional_kwonly:
396 : 12170 : return_value = _pickle_Unpickler___init___impl((UnpicklerObject *)self, file, fix_imports, encoding, errors, buffers);
397 : :
398 : 12170 : exit:
399 : 12170 : return return_value;
400 : : }
401 : :
402 : : PyDoc_STRVAR(_pickle_UnpicklerMemoProxy_clear__doc__,
403 : : "clear($self, /)\n"
404 : : "--\n"
405 : : "\n"
406 : : "Remove all items from memo.");
407 : :
408 : : #define _PICKLE_UNPICKLERMEMOPROXY_CLEAR_METHODDEF \
409 : : {"clear", (PyCFunction)_pickle_UnpicklerMemoProxy_clear, METH_NOARGS, _pickle_UnpicklerMemoProxy_clear__doc__},
410 : :
411 : : static PyObject *
412 : : _pickle_UnpicklerMemoProxy_clear_impl(UnpicklerMemoProxyObject *self);
413 : :
414 : : static PyObject *
415 : 1 : _pickle_UnpicklerMemoProxy_clear(UnpicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
416 : : {
417 : 1 : return _pickle_UnpicklerMemoProxy_clear_impl(self);
418 : : }
419 : :
420 : : PyDoc_STRVAR(_pickle_UnpicklerMemoProxy_copy__doc__,
421 : : "copy($self, /)\n"
422 : : "--\n"
423 : : "\n"
424 : : "Copy the memo to a new object.");
425 : :
426 : : #define _PICKLE_UNPICKLERMEMOPROXY_COPY_METHODDEF \
427 : : {"copy", (PyCFunction)_pickle_UnpicklerMemoProxy_copy, METH_NOARGS, _pickle_UnpicklerMemoProxy_copy__doc__},
428 : :
429 : : static PyObject *
430 : : _pickle_UnpicklerMemoProxy_copy_impl(UnpicklerMemoProxyObject *self);
431 : :
432 : : static PyObject *
433 : 0 : _pickle_UnpicklerMemoProxy_copy(UnpicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
434 : : {
435 : 0 : return _pickle_UnpicklerMemoProxy_copy_impl(self);
436 : : }
437 : :
438 : : PyDoc_STRVAR(_pickle_UnpicklerMemoProxy___reduce____doc__,
439 : : "__reduce__($self, /)\n"
440 : : "--\n"
441 : : "\n"
442 : : "Implement pickling support.");
443 : :
444 : : #define _PICKLE_UNPICKLERMEMOPROXY___REDUCE___METHODDEF \
445 : : {"__reduce__", (PyCFunction)_pickle_UnpicklerMemoProxy___reduce__, METH_NOARGS, _pickle_UnpicklerMemoProxy___reduce____doc__},
446 : :
447 : : static PyObject *
448 : : _pickle_UnpicklerMemoProxy___reduce___impl(UnpicklerMemoProxyObject *self);
449 : :
450 : : static PyObject *
451 : 0 : _pickle_UnpicklerMemoProxy___reduce__(UnpicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
452 : : {
453 : 0 : return _pickle_UnpicklerMemoProxy___reduce___impl(self);
454 : : }
455 : :
456 : : PyDoc_STRVAR(_pickle_dump__doc__,
457 : : "dump($module, /, obj, file, protocol=None, *, fix_imports=True,\n"
458 : : " buffer_callback=None)\n"
459 : : "--\n"
460 : : "\n"
461 : : "Write a pickled representation of obj to the open file object file.\n"
462 : : "\n"
463 : : "This is equivalent to ``Pickler(file, protocol).dump(obj)``, but may\n"
464 : : "be more efficient.\n"
465 : : "\n"
466 : : "The optional *protocol* argument tells the pickler to use the given\n"
467 : : "protocol; supported protocols are 0, 1, 2, 3, 4 and 5. The default\n"
468 : : "protocol is 4. It was introduced in Python 3.4, and is incompatible\n"
469 : : "with previous versions.\n"
470 : : "\n"
471 : : "Specifying a negative protocol version selects the highest protocol\n"
472 : : "version supported. The higher the protocol used, the more recent the\n"
473 : : "version of Python needed to read the pickle produced.\n"
474 : : "\n"
475 : : "The *file* argument must have a write() method that accepts a single\n"
476 : : "bytes argument. It can thus be a file object opened for binary\n"
477 : : "writing, an io.BytesIO instance, or any other custom object that meets\n"
478 : : "this interface.\n"
479 : : "\n"
480 : : "If *fix_imports* is True and protocol is less than 3, pickle will try\n"
481 : : "to map the new Python 3 names to the old module names used in Python\n"
482 : : "2, so that the pickle data stream is readable with Python 2.\n"
483 : : "\n"
484 : : "If *buffer_callback* is None (the default), buffer views are serialized\n"
485 : : "into *file* as part of the pickle stream. It is an error if\n"
486 : : "*buffer_callback* is not None and *protocol* is None or smaller than 5.");
487 : :
488 : : #define _PICKLE_DUMP_METHODDEF \
489 : : {"dump", _PyCFunction_CAST(_pickle_dump), METH_FASTCALL|METH_KEYWORDS, _pickle_dump__doc__},
490 : :
491 : : static PyObject *
492 : : _pickle_dump_impl(PyObject *module, PyObject *obj, PyObject *file,
493 : : PyObject *protocol, int fix_imports,
494 : : PyObject *buffer_callback);
495 : :
496 : : static PyObject *
497 : 31 : _pickle_dump(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
498 : : {
499 : 31 : PyObject *return_value = NULL;
500 : : static const char * const _keywords[] = {"obj", "file", "protocol", "fix_imports", "buffer_callback", NULL};
501 : : static _PyArg_Parser _parser = {NULL, _keywords, "dump", 0};
502 : : PyObject *argsbuf[5];
503 [ + + ]: 31 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
504 : : PyObject *obj;
505 : : PyObject *file;
506 : 31 : PyObject *protocol = Py_None;
507 : 31 : int fix_imports = 1;
508 : 31 : PyObject *buffer_callback = Py_None;
509 : :
510 [ + + + - : 31 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);
+ - - + ]
511 [ - + ]: 31 : if (!args) {
512 : 0 : goto exit;
513 : : }
514 : 31 : obj = args[0];
515 : 31 : file = args[1];
516 [ + + ]: 31 : if (!noptargs) {
517 : 12 : goto skip_optional_pos;
518 : : }
519 [ - + ]: 19 : if (args[2]) {
520 : 19 : protocol = args[2];
521 [ + + ]: 19 : if (!--noptargs) {
522 : 13 : goto skip_optional_pos;
523 : : }
524 : : }
525 : 6 : skip_optional_pos:
526 [ + + ]: 31 : if (!noptargs) {
527 : 25 : goto skip_optional_kwonly;
528 : : }
529 [ - + ]: 6 : if (args[3]) {
530 : 0 : fix_imports = PyObject_IsTrue(args[3]);
531 [ # # ]: 0 : if (fix_imports < 0) {
532 : 0 : goto exit;
533 : : }
534 [ # # ]: 0 : if (!--noptargs) {
535 : 0 : goto skip_optional_kwonly;
536 : : }
537 : : }
538 : 6 : buffer_callback = args[4];
539 : 31 : skip_optional_kwonly:
540 : 31 : return_value = _pickle_dump_impl(module, obj, file, protocol, fix_imports, buffer_callback);
541 : :
542 : 31 : exit:
543 : 31 : return return_value;
544 : : }
545 : :
546 : : PyDoc_STRVAR(_pickle_dumps__doc__,
547 : : "dumps($module, /, obj, protocol=None, *, fix_imports=True,\n"
548 : : " buffer_callback=None)\n"
549 : : "--\n"
550 : : "\n"
551 : : "Return the pickled representation of the object as a bytes object.\n"
552 : : "\n"
553 : : "The optional *protocol* argument tells the pickler to use the given\n"
554 : : "protocol; supported protocols are 0, 1, 2, 3, 4 and 5. The default\n"
555 : : "protocol is 4. It was introduced in Python 3.4, and is incompatible\n"
556 : : "with previous versions.\n"
557 : : "\n"
558 : : "Specifying a negative protocol version selects the highest protocol\n"
559 : : "version supported. The higher the protocol used, the more recent the\n"
560 : : "version of Python needed to read the pickle produced.\n"
561 : : "\n"
562 : : "If *fix_imports* is True and *protocol* is less than 3, pickle will\n"
563 : : "try to map the new Python 3 names to the old module names used in\n"
564 : : "Python 2, so that the pickle data stream is readable with Python 2.\n"
565 : : "\n"
566 : : "If *buffer_callback* is None (the default), buffer views are serialized\n"
567 : : "into *file* as part of the pickle stream. It is an error if\n"
568 : : "*buffer_callback* is not None and *protocol* is None or smaller than 5.");
569 : :
570 : : #define _PICKLE_DUMPS_METHODDEF \
571 : : {"dumps", _PyCFunction_CAST(_pickle_dumps), METH_FASTCALL|METH_KEYWORDS, _pickle_dumps__doc__},
572 : :
573 : : static PyObject *
574 : : _pickle_dumps_impl(PyObject *module, PyObject *obj, PyObject *protocol,
575 : : int fix_imports, PyObject *buffer_callback);
576 : :
577 : : static PyObject *
578 : 36834 : _pickle_dumps(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
579 : : {
580 : 36834 : PyObject *return_value = NULL;
581 : : static const char * const _keywords[] = {"obj", "protocol", "fix_imports", "buffer_callback", NULL};
582 : : static _PyArg_Parser _parser = {NULL, _keywords, "dumps", 0};
583 : : PyObject *argsbuf[4];
584 [ + + ]: 36834 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
585 : : PyObject *obj;
586 : 36834 : PyObject *protocol = Py_None;
587 : 36834 : int fix_imports = 1;
588 : 36834 : PyObject *buffer_callback = Py_None;
589 : :
590 [ + + + - : 36834 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
+ - - + ]
591 [ - + ]: 36834 : if (!args) {
592 : 0 : goto exit;
593 : : }
594 : 36834 : obj = args[0];
595 [ + + ]: 36834 : if (!noptargs) {
596 : 75 : goto skip_optional_pos;
597 : : }
598 [ - + ]: 36759 : if (args[1]) {
599 : 36759 : protocol = args[1];
600 [ + + ]: 36759 : if (!--noptargs) {
601 : 36633 : goto skip_optional_pos;
602 : : }
603 : : }
604 : 126 : skip_optional_pos:
605 [ + + ]: 36834 : if (!noptargs) {
606 : 36708 : goto skip_optional_kwonly;
607 : : }
608 [ - + ]: 126 : if (args[2]) {
609 : 0 : fix_imports = PyObject_IsTrue(args[2]);
610 [ # # ]: 0 : if (fix_imports < 0) {
611 : 0 : goto exit;
612 : : }
613 [ # # ]: 0 : if (!--noptargs) {
614 : 0 : goto skip_optional_kwonly;
615 : : }
616 : : }
617 : 126 : buffer_callback = args[3];
618 : 36834 : skip_optional_kwonly:
619 : 36834 : return_value = _pickle_dumps_impl(module, obj, protocol, fix_imports, buffer_callback);
620 : :
621 : 36834 : exit:
622 : 36834 : return return_value;
623 : : }
624 : :
625 : : PyDoc_STRVAR(_pickle_load__doc__,
626 : : "load($module, /, file, *, fix_imports=True, encoding=\'ASCII\',\n"
627 : : " errors=\'strict\', buffers=())\n"
628 : : "--\n"
629 : : "\n"
630 : : "Read and return an object from the pickle data stored in a file.\n"
631 : : "\n"
632 : : "This is equivalent to ``Unpickler(file).load()``, but may be more\n"
633 : : "efficient.\n"
634 : : "\n"
635 : : "The protocol version of the pickle is detected automatically, so no\n"
636 : : "protocol argument is needed. Bytes past the pickled object\'s\n"
637 : : "representation are ignored.\n"
638 : : "\n"
639 : : "The argument *file* must have two methods, a read() method that takes\n"
640 : : "an integer argument, and a readline() method that requires no\n"
641 : : "arguments. Both methods should return bytes. Thus *file* can be a\n"
642 : : "binary file object opened for reading, an io.BytesIO object, or any\n"
643 : : "other custom object that meets this interface.\n"
644 : : "\n"
645 : : "Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n"
646 : : "which are used to control compatibility support for pickle stream\n"
647 : : "generated by Python 2. If *fix_imports* is True, pickle will try to\n"
648 : : "map the old Python 2 names to the new names used in Python 3. The\n"
649 : : "*encoding* and *errors* tell pickle how to decode 8-bit string\n"
650 : : "instances pickled by Python 2; these default to \'ASCII\' and \'strict\',\n"
651 : : "respectively. The *encoding* can be \'bytes\' to read these 8-bit\n"
652 : : "string instances as bytes objects.");
653 : :
654 : : #define _PICKLE_LOAD_METHODDEF \
655 : : {"load", _PyCFunction_CAST(_pickle_load), METH_FASTCALL|METH_KEYWORDS, _pickle_load__doc__},
656 : :
657 : : static PyObject *
658 : : _pickle_load_impl(PyObject *module, PyObject *file, int fix_imports,
659 : : const char *encoding, const char *errors,
660 : : PyObject *buffers);
661 : :
662 : : static PyObject *
663 : 917 : _pickle_load(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
664 : : {
665 : 917 : PyObject *return_value = NULL;
666 : : static const char * const _keywords[] = {"file", "fix_imports", "encoding", "errors", "buffers", NULL};
667 : : static _PyArg_Parser _parser = {NULL, _keywords, "load", 0};
668 : : PyObject *argsbuf[5];
669 [ + + ]: 917 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
670 : : PyObject *file;
671 : 917 : int fix_imports = 1;
672 : 917 : const char *encoding = "ASCII";
673 : 917 : const char *errors = "strict";
674 : 917 : PyObject *buffers = NULL;
675 : :
676 [ + + + - : 917 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
+ - - + ]
677 [ - + ]: 917 : if (!args) {
678 : 0 : goto exit;
679 : : }
680 : 917 : file = args[0];
681 [ + + ]: 917 : if (!noptargs) {
682 : 916 : goto skip_optional_kwonly;
683 : : }
684 [ - + ]: 1 : if (args[1]) {
685 : 0 : fix_imports = PyObject_IsTrue(args[1]);
686 [ # # ]: 0 : if (fix_imports < 0) {
687 : 0 : goto exit;
688 : : }
689 [ # # ]: 0 : if (!--noptargs) {
690 : 0 : goto skip_optional_kwonly;
691 : : }
692 : : }
693 [ - + ]: 1 : if (args[2]) {
694 [ # # ]: 0 : if (!PyUnicode_Check(args[2])) {
695 : 0 : _PyArg_BadArgument("load", "argument 'encoding'", "str", args[2]);
696 : 0 : goto exit;
697 : : }
698 : : Py_ssize_t encoding_length;
699 : 0 : encoding = PyUnicode_AsUTF8AndSize(args[2], &encoding_length);
700 [ # # ]: 0 : if (encoding == NULL) {
701 : 0 : goto exit;
702 : : }
703 [ # # ]: 0 : if (strlen(encoding) != (size_t)encoding_length) {
704 : 0 : PyErr_SetString(PyExc_ValueError, "embedded null character");
705 : 0 : goto exit;
706 : : }
707 [ # # ]: 0 : if (!--noptargs) {
708 : 0 : goto skip_optional_kwonly;
709 : : }
710 : : }
711 [ - + ]: 1 : if (args[3]) {
712 [ # # ]: 0 : if (!PyUnicode_Check(args[3])) {
713 : 0 : _PyArg_BadArgument("load", "argument 'errors'", "str", args[3]);
714 : 0 : goto exit;
715 : : }
716 : : Py_ssize_t errors_length;
717 : 0 : errors = PyUnicode_AsUTF8AndSize(args[3], &errors_length);
718 [ # # ]: 0 : if (errors == NULL) {
719 : 0 : goto exit;
720 : : }
721 [ # # ]: 0 : if (strlen(errors) != (size_t)errors_length) {
722 : 0 : PyErr_SetString(PyExc_ValueError, "embedded null character");
723 : 0 : goto exit;
724 : : }
725 [ # # ]: 0 : if (!--noptargs) {
726 : 0 : goto skip_optional_kwonly;
727 : : }
728 : : }
729 : 1 : buffers = args[4];
730 : 917 : skip_optional_kwonly:
731 : 917 : return_value = _pickle_load_impl(module, file, fix_imports, encoding, errors, buffers);
732 : :
733 : 917 : exit:
734 : 917 : return return_value;
735 : : }
736 : :
737 : : PyDoc_STRVAR(_pickle_loads__doc__,
738 : : "loads($module, data, /, *, fix_imports=True, encoding=\'ASCII\',\n"
739 : : " errors=\'strict\', buffers=())\n"
740 : : "--\n"
741 : : "\n"
742 : : "Read and return an object from the given pickle data.\n"
743 : : "\n"
744 : : "The protocol version of the pickle is detected automatically, so no\n"
745 : : "protocol argument is needed. Bytes past the pickled object\'s\n"
746 : : "representation are ignored.\n"
747 : : "\n"
748 : : "Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n"
749 : : "which are used to control compatibility support for pickle stream\n"
750 : : "generated by Python 2. If *fix_imports* is True, pickle will try to\n"
751 : : "map the old Python 2 names to the new names used in Python 3. The\n"
752 : : "*encoding* and *errors* tell pickle how to decode 8-bit string\n"
753 : : "instances pickled by Python 2; these default to \'ASCII\' and \'strict\',\n"
754 : : "respectively. The *encoding* can be \'bytes\' to read these 8-bit\n"
755 : : "string instances as bytes objects.");
756 : :
757 : : #define _PICKLE_LOADS_METHODDEF \
758 : : {"loads", _PyCFunction_CAST(_pickle_loads), METH_FASTCALL|METH_KEYWORDS, _pickle_loads__doc__},
759 : :
760 : : static PyObject *
761 : : _pickle_loads_impl(PyObject *module, PyObject *data, int fix_imports,
762 : : const char *encoding, const char *errors,
763 : : PyObject *buffers);
764 : :
765 : : static PyObject *
766 : 72406 : _pickle_loads(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
767 : : {
768 : 72406 : PyObject *return_value = NULL;
769 : : static const char * const _keywords[] = {"", "fix_imports", "encoding", "errors", "buffers", NULL};
770 : : static _PyArg_Parser _parser = {NULL, _keywords, "loads", 0};
771 : : PyObject *argsbuf[5];
772 [ + + ]: 72406 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
773 : : PyObject *data;
774 : 72406 : int fix_imports = 1;
775 : 72406 : const char *encoding = "ASCII";
776 : 72406 : const char *errors = "strict";
777 : 72406 : PyObject *buffers = NULL;
778 : :
779 [ + + + - : 72406 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
+ - - + ]
780 [ - + ]: 72406 : if (!args) {
781 : 0 : goto exit;
782 : : }
783 : 72406 : data = args[0];
784 [ + + ]: 72406 : if (!noptargs) {
785 : 72315 : goto skip_optional_kwonly;
786 : : }
787 [ - + ]: 91 : if (args[1]) {
788 : 0 : fix_imports = PyObject_IsTrue(args[1]);
789 [ # # ]: 0 : if (fix_imports < 0) {
790 : 0 : goto exit;
791 : : }
792 [ # # ]: 0 : if (!--noptargs) {
793 : 0 : goto skip_optional_kwonly;
794 : : }
795 : : }
796 [ + + ]: 91 : if (args[2]) {
797 [ - + ]: 50 : if (!PyUnicode_Check(args[2])) {
798 : 0 : _PyArg_BadArgument("loads", "argument 'encoding'", "str", args[2]);
799 : 0 : goto exit;
800 : : }
801 : : Py_ssize_t encoding_length;
802 : 50 : encoding = PyUnicode_AsUTF8AndSize(args[2], &encoding_length);
803 [ - + ]: 50 : if (encoding == NULL) {
804 : 0 : goto exit;
805 : : }
806 [ - + ]: 50 : if (strlen(encoding) != (size_t)encoding_length) {
807 : 0 : PyErr_SetString(PyExc_ValueError, "embedded null character");
808 : 0 : goto exit;
809 : : }
810 [ + - ]: 50 : if (!--noptargs) {
811 : 50 : goto skip_optional_kwonly;
812 : : }
813 : : }
814 [ - + ]: 41 : if (args[3]) {
815 [ # # ]: 0 : if (!PyUnicode_Check(args[3])) {
816 : 0 : _PyArg_BadArgument("loads", "argument 'errors'", "str", args[3]);
817 : 0 : goto exit;
818 : : }
819 : : Py_ssize_t errors_length;
820 : 0 : errors = PyUnicode_AsUTF8AndSize(args[3], &errors_length);
821 [ # # ]: 0 : if (errors == NULL) {
822 : 0 : goto exit;
823 : : }
824 [ # # ]: 0 : if (strlen(errors) != (size_t)errors_length) {
825 : 0 : PyErr_SetString(PyExc_ValueError, "embedded null character");
826 : 0 : goto exit;
827 : : }
828 [ # # ]: 0 : if (!--noptargs) {
829 : 0 : goto skip_optional_kwonly;
830 : : }
831 : : }
832 : 41 : buffers = args[4];
833 : 72406 : skip_optional_kwonly:
834 : 72406 : return_value = _pickle_loads_impl(module, data, fix_imports, encoding, errors, buffers);
835 : :
836 : 72406 : exit:
837 : 72406 : return return_value;
838 : : }
839 : : /*[clinic end generated code: output=1bb1ead3c828e108 input=a9049054013a1b77]*/
|