1/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_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
19static PyObject *
20_pickle_Pickler_clear_memo_impl(PicklerObject *self);
21
22static PyObject *
23_pickle_Pickler_clear_memo(PicklerObject *self, PyObject *Py_UNUSED(ignored))
24{
25    return _pickle_Pickler_clear_memo_impl(self);
26}
27
28PyDoc_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
37PyDoc_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
46static Py_ssize_t
47_pickle_Pickler___sizeof___impl(PicklerObject *self);
48
49static PyObject *
50_pickle_Pickler___sizeof__(PicklerObject *self, PyObject *Py_UNUSED(ignored))
51{
52    PyObject *return_value = NULL;
53    Py_ssize_t _return_value;
54
55    _return_value = _pickle_Pickler___sizeof___impl(self);
56    if ((_return_value == -1) && PyErr_Occurred()) {
57        goto exit;
58    }
59    return_value = PyLong_FromSsize_t(_return_value);
60
61exit:
62    return return_value;
63}
64
65PyDoc_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
100static int
101_pickle_Pickler___init___impl(PicklerObject *self, PyObject *file,
102                              PyObject *protocol, int fix_imports,
103                              PyObject *buffer_callback);
104
105static int
106_pickle_Pickler___init__(PyObject *self, PyObject *args, PyObject *kwargs)
107{
108    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    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
114    Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
115    PyObject *file;
116    PyObject *protocol = Py_None;
117    int fix_imports = 1;
118    PyObject *buffer_callback = Py_None;
119
120    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 4, 0, argsbuf);
121    if (!fastargs) {
122        goto exit;
123    }
124    file = fastargs[0];
125    if (!noptargs) {
126        goto skip_optional_pos;
127    }
128    if (fastargs[1]) {
129        protocol = fastargs[1];
130        if (!--noptargs) {
131            goto skip_optional_pos;
132        }
133    }
134    if (fastargs[2]) {
135        fix_imports = PyObject_IsTrue(fastargs[2]);
136        if (fix_imports < 0) {
137            goto exit;
138        }
139        if (!--noptargs) {
140            goto skip_optional_pos;
141        }
142    }
143    buffer_callback = fastargs[3];
144skip_optional_pos:
145    return_value = _pickle_Pickler___init___impl((PicklerObject *)self, file, protocol, fix_imports, buffer_callback);
146
147exit:
148    return return_value;
149}
150
151PyDoc_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
160static PyObject *
161_pickle_PicklerMemoProxy_clear_impl(PicklerMemoProxyObject *self);
162
163static PyObject *
164_pickle_PicklerMemoProxy_clear(PicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
165{
166    return _pickle_PicklerMemoProxy_clear_impl(self);
167}
168
169PyDoc_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
178static PyObject *
179_pickle_PicklerMemoProxy_copy_impl(PicklerMemoProxyObject *self);
180
181static PyObject *
182_pickle_PicklerMemoProxy_copy(PicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
183{
184    return _pickle_PicklerMemoProxy_copy_impl(self);
185}
186
187PyDoc_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
196static PyObject *
197_pickle_PicklerMemoProxy___reduce___impl(PicklerMemoProxyObject *self);
198
199static PyObject *
200_pickle_PicklerMemoProxy___reduce__(PicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
201{
202    return _pickle_PicklerMemoProxy___reduce___impl(self);
203}
204
205PyDoc_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
218static PyObject *
219_pickle_Unpickler_load_impl(UnpicklerObject *self);
220
221static PyObject *
222_pickle_Unpickler_load(UnpicklerObject *self, PyObject *Py_UNUSED(ignored))
223{
224    return _pickle_Unpickler_load_impl(self);
225}
226
227PyDoc_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
243static PyObject *
244_pickle_Unpickler_find_class_impl(UnpicklerObject *self,
245                                  PyObject *module_name,
246                                  PyObject *global_name);
247
248static PyObject *
249_pickle_Unpickler_find_class(UnpicklerObject *self, PyObject *const *args, Py_ssize_t nargs)
250{
251    PyObject *return_value = NULL;
252    PyObject *module_name;
253    PyObject *global_name;
254
255    if (!_PyArg_CheckPositional("find_class", nargs, 2, 2)) {
256        goto exit;
257    }
258    module_name = args[0];
259    global_name = args[1];
260    return_value = _pickle_Unpickler_find_class_impl(self, module_name, global_name);
261
262exit:
263    return return_value;
264}
265
266PyDoc_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
275static Py_ssize_t
276_pickle_Unpickler___sizeof___impl(UnpicklerObject *self);
277
278static PyObject *
279_pickle_Unpickler___sizeof__(UnpicklerObject *self, PyObject *Py_UNUSED(ignored))
280{
281    PyObject *return_value = NULL;
282    Py_ssize_t _return_value;
283
284    _return_value = _pickle_Unpickler___sizeof___impl(self);
285    if ((_return_value == -1) && PyErr_Occurred()) {
286        goto exit;
287    }
288    return_value = PyLong_FromSsize_t(_return_value);
289
290exit:
291    return return_value;
292}
293
294PyDoc_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
320static int
321_pickle_Unpickler___init___impl(UnpicklerObject *self, PyObject *file,
322                                int fix_imports, const char *encoding,
323                                const char *errors, PyObject *buffers);
324
325static int
326_pickle_Unpickler___init__(PyObject *self, PyObject *args, PyObject *kwargs)
327{
328    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    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
334    Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
335    PyObject *file;
336    int fix_imports = 1;
337    const char *encoding = "ASCII";
338    const char *errors = "strict";
339    PyObject *buffers = NULL;
340
341    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 1, 0, argsbuf);
342    if (!fastargs) {
343        goto exit;
344    }
345    file = fastargs[0];
346    if (!noptargs) {
347        goto skip_optional_kwonly;
348    }
349    if (fastargs[1]) {
350        fix_imports = PyObject_IsTrue(fastargs[1]);
351        if (fix_imports < 0) {
352            goto exit;
353        }
354        if (!--noptargs) {
355            goto skip_optional_kwonly;
356        }
357    }
358    if (fastargs[2]) {
359        if (!PyUnicode_Check(fastargs[2])) {
360            _PyArg_BadArgument("Unpickler", "argument 'encoding'", "str", fastargs[2]);
361            goto exit;
362        }
363        Py_ssize_t encoding_length;
364        encoding = PyUnicode_AsUTF8AndSize(fastargs[2], &encoding_length);
365        if (encoding == NULL) {
366            goto exit;
367        }
368        if (strlen(encoding) != (size_t)encoding_length) {
369            PyErr_SetString(PyExc_ValueError, "embedded null character");
370            goto exit;
371        }
372        if (!--noptargs) {
373            goto skip_optional_kwonly;
374        }
375    }
376    if (fastargs[3]) {
377        if (!PyUnicode_Check(fastargs[3])) {
378            _PyArg_BadArgument("Unpickler", "argument 'errors'", "str", fastargs[3]);
379            goto exit;
380        }
381        Py_ssize_t errors_length;
382        errors = PyUnicode_AsUTF8AndSize(fastargs[3], &errors_length);
383        if (errors == NULL) {
384            goto exit;
385        }
386        if (strlen(errors) != (size_t)errors_length) {
387            PyErr_SetString(PyExc_ValueError, "embedded null character");
388            goto exit;
389        }
390        if (!--noptargs) {
391            goto skip_optional_kwonly;
392        }
393    }
394    buffers = fastargs[4];
395skip_optional_kwonly:
396    return_value = _pickle_Unpickler___init___impl((UnpicklerObject *)self, file, fix_imports, encoding, errors, buffers);
397
398exit:
399    return return_value;
400}
401
402PyDoc_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
411static PyObject *
412_pickle_UnpicklerMemoProxy_clear_impl(UnpicklerMemoProxyObject *self);
413
414static PyObject *
415_pickle_UnpicklerMemoProxy_clear(UnpicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
416{
417    return _pickle_UnpicklerMemoProxy_clear_impl(self);
418}
419
420PyDoc_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
429static PyObject *
430_pickle_UnpicklerMemoProxy_copy_impl(UnpicklerMemoProxyObject *self);
431
432static PyObject *
433_pickle_UnpicklerMemoProxy_copy(UnpicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
434{
435    return _pickle_UnpicklerMemoProxy_copy_impl(self);
436}
437
438PyDoc_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
447static PyObject *
448_pickle_UnpicklerMemoProxy___reduce___impl(UnpicklerMemoProxyObject *self);
449
450static PyObject *
451_pickle_UnpicklerMemoProxy___reduce__(UnpicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
452{
453    return _pickle_UnpicklerMemoProxy___reduce___impl(self);
454}
455
456PyDoc_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
491static PyObject *
492_pickle_dump_impl(PyObject *module, PyObject *obj, PyObject *file,
493                  PyObject *protocol, int fix_imports,
494                  PyObject *buffer_callback);
495
496static PyObject *
497_pickle_dump(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
498{
499    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    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
504    PyObject *obj;
505    PyObject *file;
506    PyObject *protocol = Py_None;
507    int fix_imports = 1;
508    PyObject *buffer_callback = Py_None;
509
510    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);
511    if (!args) {
512        goto exit;
513    }
514    obj = args[0];
515    file = args[1];
516    if (!noptargs) {
517        goto skip_optional_pos;
518    }
519    if (args[2]) {
520        protocol = args[2];
521        if (!--noptargs) {
522            goto skip_optional_pos;
523        }
524    }
525skip_optional_pos:
526    if (!noptargs) {
527        goto skip_optional_kwonly;
528    }
529    if (args[3]) {
530        fix_imports = PyObject_IsTrue(args[3]);
531        if (fix_imports < 0) {
532            goto exit;
533        }
534        if (!--noptargs) {
535            goto skip_optional_kwonly;
536        }
537    }
538    buffer_callback = args[4];
539skip_optional_kwonly:
540    return_value = _pickle_dump_impl(module, obj, file, protocol, fix_imports, buffer_callback);
541
542exit:
543    return return_value;
544}
545
546PyDoc_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
573static PyObject *
574_pickle_dumps_impl(PyObject *module, PyObject *obj, PyObject *protocol,
575                   int fix_imports, PyObject *buffer_callback);
576
577static PyObject *
578_pickle_dumps(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
579{
580    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    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
585    PyObject *obj;
586    PyObject *protocol = Py_None;
587    int fix_imports = 1;
588    PyObject *buffer_callback = Py_None;
589
590    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
591    if (!args) {
592        goto exit;
593    }
594    obj = args[0];
595    if (!noptargs) {
596        goto skip_optional_pos;
597    }
598    if (args[1]) {
599        protocol = args[1];
600        if (!--noptargs) {
601            goto skip_optional_pos;
602        }
603    }
604skip_optional_pos:
605    if (!noptargs) {
606        goto skip_optional_kwonly;
607    }
608    if (args[2]) {
609        fix_imports = PyObject_IsTrue(args[2]);
610        if (fix_imports < 0) {
611            goto exit;
612        }
613        if (!--noptargs) {
614            goto skip_optional_kwonly;
615        }
616    }
617    buffer_callback = args[3];
618skip_optional_kwonly:
619    return_value = _pickle_dumps_impl(module, obj, protocol, fix_imports, buffer_callback);
620
621exit:
622    return return_value;
623}
624
625PyDoc_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
657static PyObject *
658_pickle_load_impl(PyObject *module, PyObject *file, int fix_imports,
659                  const char *encoding, const char *errors,
660                  PyObject *buffers);
661
662static PyObject *
663_pickle_load(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
664{
665    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    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
670    PyObject *file;
671    int fix_imports = 1;
672    const char *encoding = "ASCII";
673    const char *errors = "strict";
674    PyObject *buffers = NULL;
675
676    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
677    if (!args) {
678        goto exit;
679    }
680    file = args[0];
681    if (!noptargs) {
682        goto skip_optional_kwonly;
683    }
684    if (args[1]) {
685        fix_imports = PyObject_IsTrue(args[1]);
686        if (fix_imports < 0) {
687            goto exit;
688        }
689        if (!--noptargs) {
690            goto skip_optional_kwonly;
691        }
692    }
693    if (args[2]) {
694        if (!PyUnicode_Check(args[2])) {
695            _PyArg_BadArgument("load", "argument 'encoding'", "str", args[2]);
696            goto exit;
697        }
698        Py_ssize_t encoding_length;
699        encoding = PyUnicode_AsUTF8AndSize(args[2], &encoding_length);
700        if (encoding == NULL) {
701            goto exit;
702        }
703        if (strlen(encoding) != (size_t)encoding_length) {
704            PyErr_SetString(PyExc_ValueError, "embedded null character");
705            goto exit;
706        }
707        if (!--noptargs) {
708            goto skip_optional_kwonly;
709        }
710    }
711    if (args[3]) {
712        if (!PyUnicode_Check(args[3])) {
713            _PyArg_BadArgument("load", "argument 'errors'", "str", args[3]);
714            goto exit;
715        }
716        Py_ssize_t errors_length;
717        errors = PyUnicode_AsUTF8AndSize(args[3], &errors_length);
718        if (errors == NULL) {
719            goto exit;
720        }
721        if (strlen(errors) != (size_t)errors_length) {
722            PyErr_SetString(PyExc_ValueError, "embedded null character");
723            goto exit;
724        }
725        if (!--noptargs) {
726            goto skip_optional_kwonly;
727        }
728    }
729    buffers = args[4];
730skip_optional_kwonly:
731    return_value = _pickle_load_impl(module, file, fix_imports, encoding, errors, buffers);
732
733exit:
734    return return_value;
735}
736
737PyDoc_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
760static PyObject *
761_pickle_loads_impl(PyObject *module, PyObject *data, int fix_imports,
762                   const char *encoding, const char *errors,
763                   PyObject *buffers);
764
765static PyObject *
766_pickle_loads(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
767{
768    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    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
773    PyObject *data;
774    int fix_imports = 1;
775    const char *encoding = "ASCII";
776    const char *errors = "strict";
777    PyObject *buffers = NULL;
778
779    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
780    if (!args) {
781        goto exit;
782    }
783    data = args[0];
784    if (!noptargs) {
785        goto skip_optional_kwonly;
786    }
787    if (args[1]) {
788        fix_imports = PyObject_IsTrue(args[1]);
789        if (fix_imports < 0) {
790            goto exit;
791        }
792        if (!--noptargs) {
793            goto skip_optional_kwonly;
794        }
795    }
796    if (args[2]) {
797        if (!PyUnicode_Check(args[2])) {
798            _PyArg_BadArgument("loads", "argument 'encoding'", "str", args[2]);
799            goto exit;
800        }
801        Py_ssize_t encoding_length;
802        encoding = PyUnicode_AsUTF8AndSize(args[2], &encoding_length);
803        if (encoding == NULL) {
804            goto exit;
805        }
806        if (strlen(encoding) != (size_t)encoding_length) {
807            PyErr_SetString(PyExc_ValueError, "embedded null character");
808            goto exit;
809        }
810        if (!--noptargs) {
811            goto skip_optional_kwonly;
812        }
813    }
814    if (args[3]) {
815        if (!PyUnicode_Check(args[3])) {
816            _PyArg_BadArgument("loads", "argument 'errors'", "str", args[3]);
817            goto exit;
818        }
819        Py_ssize_t errors_length;
820        errors = PyUnicode_AsUTF8AndSize(args[3], &errors_length);
821        if (errors == NULL) {
822            goto exit;
823        }
824        if (strlen(errors) != (size_t)errors_length) {
825            PyErr_SetString(PyExc_ValueError, "embedded null character");
826            goto exit;
827        }
828        if (!--noptargs) {
829            goto skip_optional_kwonly;
830        }
831    }
832    buffers = args[4];
833skip_optional_kwonly:
834    return_value = _pickle_loads_impl(module, data, fix_imports, encoding, errors, buffers);
835
836exit:
837    return return_value;
838}
839/*[clinic end generated code: output=1bb1ead3c828e108 input=a9049054013a1b77]*/
840