blob: b698ce81bd34387c6f698e35f131c38c37b44b90 [file] [log] [blame]
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +02001/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_STRVAR(_pickle_Pickler_clear_memo__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -08006"clear_memo($self, /)\n"
7"--\n"
8"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +02009"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__,
Larry Hastings2623c8c2014-02-08 22:15:29 -080029"dump($self, obj, /)\n"
30"--\n"
31"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +020032"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
Serhiy Storchaka5bbd2312014-12-16 19:39:08 +020037PyDoc_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 return_value = PyLong_FromSsize_t(_return_value);
59
60exit:
61 return return_value;
62}
63
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +020064PyDoc_STRVAR(_pickle_Pickler___init____doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -080065"Pickler(file, protocol=None, fix_imports=True)\n"
66"--\n"
67"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +020068"This takes a binary file for writing a pickle data stream.\n"
69"\n"
70"The optional *protocol* argument tells the pickler to use the given\n"
71"protocol; supported protocols are 0, 1, 2, 3 and 4. The default\n"
72"protocol is 3; a backward-incompatible protocol designed for Python 3.\n"
73"\n"
74"Specifying a negative protocol version selects the highest protocol\n"
75"version supported. The higher the protocol used, the more recent the\n"
76"version of Python needed to read the pickle produced.\n"
77"\n"
78"The *file* argument must have a write() method that accepts a single\n"
79"bytes argument. It can thus be a file object opened for binary\n"
80"writing, a io.BytesIO instance, or any other custom object that meets\n"
81"this interface.\n"
82"\n"
83"If *fix_imports* is True and protocol is less than 3, pickle will try\n"
84"to map the new Python 3 names to the old module names used in Python\n"
85"2, so that the pickle data stream is readable with Python 2.");
86
87static int
Larry Hastings89964c42015-04-14 18:07:59 -040088_pickle_Pickler___init___impl(PicklerObject *self, PyObject *file,
89 PyObject *protocol, int fix_imports);
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +020090
91static int
92_pickle_Pickler___init__(PyObject *self, PyObject *args, PyObject *kwargs)
93{
94 int return_value = -1;
95 static char *_keywords[] = {"file", "protocol", "fix_imports", NULL};
96 PyObject *file;
97 PyObject *protocol = NULL;
98 int fix_imports = 1;
99
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300100 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|Op:Pickler", _keywords,
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200101 &file, &protocol, &fix_imports))
102 goto exit;
103 return_value = _pickle_Pickler___init___impl((PicklerObject *)self, file, protocol, fix_imports);
104
105exit:
106 return return_value;
107}
108
109PyDoc_STRVAR(_pickle_PicklerMemoProxy_clear__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800110"clear($self, /)\n"
111"--\n"
112"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200113"Remove all items from memo.");
114
115#define _PICKLE_PICKLERMEMOPROXY_CLEAR_METHODDEF \
116 {"clear", (PyCFunction)_pickle_PicklerMemoProxy_clear, METH_NOARGS, _pickle_PicklerMemoProxy_clear__doc__},
117
118static PyObject *
119_pickle_PicklerMemoProxy_clear_impl(PicklerMemoProxyObject *self);
120
121static PyObject *
122_pickle_PicklerMemoProxy_clear(PicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
123{
124 return _pickle_PicklerMemoProxy_clear_impl(self);
125}
126
127PyDoc_STRVAR(_pickle_PicklerMemoProxy_copy__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800128"copy($self, /)\n"
129"--\n"
130"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200131"Copy the memo to a new object.");
132
133#define _PICKLE_PICKLERMEMOPROXY_COPY_METHODDEF \
134 {"copy", (PyCFunction)_pickle_PicklerMemoProxy_copy, METH_NOARGS, _pickle_PicklerMemoProxy_copy__doc__},
135
136static PyObject *
137_pickle_PicklerMemoProxy_copy_impl(PicklerMemoProxyObject *self);
138
139static PyObject *
140_pickle_PicklerMemoProxy_copy(PicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
141{
142 return _pickle_PicklerMemoProxy_copy_impl(self);
143}
144
145PyDoc_STRVAR(_pickle_PicklerMemoProxy___reduce____doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800146"__reduce__($self, /)\n"
147"--\n"
148"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200149"Implement pickle support.");
150
151#define _PICKLE_PICKLERMEMOPROXY___REDUCE___METHODDEF \
152 {"__reduce__", (PyCFunction)_pickle_PicklerMemoProxy___reduce__, METH_NOARGS, _pickle_PicklerMemoProxy___reduce____doc__},
153
154static PyObject *
155_pickle_PicklerMemoProxy___reduce___impl(PicklerMemoProxyObject *self);
156
157static PyObject *
158_pickle_PicklerMemoProxy___reduce__(PicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
159{
160 return _pickle_PicklerMemoProxy___reduce___impl(self);
161}
162
163PyDoc_STRVAR(_pickle_Unpickler_load__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800164"load($self, /)\n"
165"--\n"
166"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200167"Load a pickle.\n"
168"\n"
169"Read a pickled object representation from the open file object given\n"
170"in the constructor, and return the reconstituted object hierarchy\n"
171"specified therein.");
172
173#define _PICKLE_UNPICKLER_LOAD_METHODDEF \
174 {"load", (PyCFunction)_pickle_Unpickler_load, METH_NOARGS, _pickle_Unpickler_load__doc__},
175
176static PyObject *
177_pickle_Unpickler_load_impl(UnpicklerObject *self);
178
179static PyObject *
180_pickle_Unpickler_load(UnpicklerObject *self, PyObject *Py_UNUSED(ignored))
181{
182 return _pickle_Unpickler_load_impl(self);
183}
184
185PyDoc_STRVAR(_pickle_Unpickler_find_class__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800186"find_class($self, module_name, global_name, /)\n"
187"--\n"
188"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200189"Return an object from a specified module.\n"
190"\n"
191"If necessary, the module will be imported. Subclasses may override\n"
192"this method (e.g. to restrict unpickling of arbitrary classes and\n"
193"functions).\n"
194"\n"
195"This method is called whenever a class or a function object is\n"
196"needed. Both arguments passed are str objects.");
197
198#define _PICKLE_UNPICKLER_FIND_CLASS_METHODDEF \
199 {"find_class", (PyCFunction)_pickle_Unpickler_find_class, METH_VARARGS, _pickle_Unpickler_find_class__doc__},
200
201static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400202_pickle_Unpickler_find_class_impl(UnpicklerObject *self,
203 PyObject *module_name,
204 PyObject *global_name);
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200205
206static PyObject *
207_pickle_Unpickler_find_class(UnpicklerObject *self, PyObject *args)
208{
209 PyObject *return_value = NULL;
210 PyObject *module_name;
211 PyObject *global_name;
212
213 if (!PyArg_UnpackTuple(args, "find_class",
214 2, 2,
215 &module_name, &global_name))
216 goto exit;
217 return_value = _pickle_Unpickler_find_class_impl(self, module_name, global_name);
218
219exit:
220 return return_value;
221}
222
Serhiy Storchaka5bbd2312014-12-16 19:39:08 +0200223PyDoc_STRVAR(_pickle_Unpickler___sizeof____doc__,
224"__sizeof__($self, /)\n"
225"--\n"
226"\n"
227"Returns size in memory, in bytes.");
228
229#define _PICKLE_UNPICKLER___SIZEOF___METHODDEF \
230 {"__sizeof__", (PyCFunction)_pickle_Unpickler___sizeof__, METH_NOARGS, _pickle_Unpickler___sizeof____doc__},
231
232static Py_ssize_t
233_pickle_Unpickler___sizeof___impl(UnpicklerObject *self);
234
235static PyObject *
236_pickle_Unpickler___sizeof__(UnpicklerObject *self, PyObject *Py_UNUSED(ignored))
237{
238 PyObject *return_value = NULL;
239 Py_ssize_t _return_value;
240
241 _return_value = _pickle_Unpickler___sizeof___impl(self);
242 if ((_return_value == -1) && PyErr_Occurred())
243 goto exit;
244 return_value = PyLong_FromSsize_t(_return_value);
245
246exit:
247 return return_value;
248}
249
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200250PyDoc_STRVAR(_pickle_Unpickler___init____doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800251"Unpickler(file, *, fix_imports=True, encoding=\'ASCII\', errors=\'strict\')\n"
252"--\n"
253"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200254"This takes a binary file for reading a pickle data stream.\n"
255"\n"
256"The protocol version of the pickle is detected automatically, so no\n"
257"protocol argument is needed. Bytes past the pickled object\'s\n"
258"representation are ignored.\n"
259"\n"
260"The argument *file* must have two methods, a read() method that takes\n"
261"an integer argument, and a readline() method that requires no\n"
262"arguments. Both methods should return bytes. Thus *file* can be a\n"
263"binary file object opened for reading, a io.BytesIO object, or any\n"
264"other custom object that meets this interface.\n"
265"\n"
266"Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n"
267"which are used to control compatiblity support for pickle stream\n"
268"generated by Python 2. If *fix_imports* is True, pickle will try to\n"
269"map the old Python 2 names to the new names used in Python 3. The\n"
270"*encoding* and *errors* tell pickle how to decode 8-bit string\n"
271"instances pickled by Python 2; these default to \'ASCII\' and \'strict\',\n"
272"respectively. The *encoding* can be \'bytes\' to read these 8-bit\n"
273"string instances as bytes objects.");
274
275static int
Larry Hastings89964c42015-04-14 18:07:59 -0400276_pickle_Unpickler___init___impl(UnpicklerObject *self, PyObject *file,
277 int fix_imports, const char *encoding,
278 const char *errors);
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200279
280static int
281_pickle_Unpickler___init__(PyObject *self, PyObject *args, PyObject *kwargs)
282{
283 int return_value = -1;
284 static char *_keywords[] = {"file", "fix_imports", "encoding", "errors", NULL};
285 PyObject *file;
286 int fix_imports = 1;
287 const char *encoding = "ASCII";
288 const char *errors = "strict";
289
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300290 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|$pss:Unpickler", _keywords,
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200291 &file, &fix_imports, &encoding, &errors))
292 goto exit;
293 return_value = _pickle_Unpickler___init___impl((UnpicklerObject *)self, file, fix_imports, encoding, errors);
294
295exit:
296 return return_value;
297}
298
299PyDoc_STRVAR(_pickle_UnpicklerMemoProxy_clear__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800300"clear($self, /)\n"
301"--\n"
302"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200303"Remove all items from memo.");
304
305#define _PICKLE_UNPICKLERMEMOPROXY_CLEAR_METHODDEF \
306 {"clear", (PyCFunction)_pickle_UnpicklerMemoProxy_clear, METH_NOARGS, _pickle_UnpicklerMemoProxy_clear__doc__},
307
308static PyObject *
309_pickle_UnpicklerMemoProxy_clear_impl(UnpicklerMemoProxyObject *self);
310
311static PyObject *
312_pickle_UnpicklerMemoProxy_clear(UnpicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
313{
314 return _pickle_UnpicklerMemoProxy_clear_impl(self);
315}
316
317PyDoc_STRVAR(_pickle_UnpicklerMemoProxy_copy__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800318"copy($self, /)\n"
319"--\n"
320"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200321"Copy the memo to a new object.");
322
323#define _PICKLE_UNPICKLERMEMOPROXY_COPY_METHODDEF \
324 {"copy", (PyCFunction)_pickle_UnpicklerMemoProxy_copy, METH_NOARGS, _pickle_UnpicklerMemoProxy_copy__doc__},
325
326static PyObject *
327_pickle_UnpicklerMemoProxy_copy_impl(UnpicklerMemoProxyObject *self);
328
329static PyObject *
330_pickle_UnpicklerMemoProxy_copy(UnpicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
331{
332 return _pickle_UnpicklerMemoProxy_copy_impl(self);
333}
334
335PyDoc_STRVAR(_pickle_UnpicklerMemoProxy___reduce____doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800336"__reduce__($self, /)\n"
337"--\n"
338"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200339"Implement pickling support.");
340
341#define _PICKLE_UNPICKLERMEMOPROXY___REDUCE___METHODDEF \
342 {"__reduce__", (PyCFunction)_pickle_UnpicklerMemoProxy___reduce__, METH_NOARGS, _pickle_UnpicklerMemoProxy___reduce____doc__},
343
344static PyObject *
345_pickle_UnpicklerMemoProxy___reduce___impl(UnpicklerMemoProxyObject *self);
346
347static PyObject *
348_pickle_UnpicklerMemoProxy___reduce__(UnpicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
349{
350 return _pickle_UnpicklerMemoProxy___reduce___impl(self);
351}
352
353PyDoc_STRVAR(_pickle_dump__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800354"dump($module, /, obj, file, protocol=None, *, fix_imports=True)\n"
355"--\n"
356"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200357"Write a pickled representation of obj to the open file object file.\n"
358"\n"
359"This is equivalent to ``Pickler(file, protocol).dump(obj)``, but may\n"
360"be more efficient.\n"
361"\n"
362"The optional *protocol* argument tells the pickler to use the given\n"
363"protocol supported protocols are 0, 1, 2, 3 and 4. The default\n"
364"protocol is 3; a backward-incompatible protocol designed for Python 3.\n"
365"\n"
366"Specifying a negative protocol version selects the highest protocol\n"
367"version supported. The higher the protocol used, the more recent the\n"
368"version of Python needed to read the pickle produced.\n"
369"\n"
370"The *file* argument must have a write() method that accepts a single\n"
371"bytes argument. It can thus be a file object opened for binary\n"
372"writing, a io.BytesIO instance, or any other custom object that meets\n"
373"this interface.\n"
374"\n"
375"If *fix_imports* is True and protocol is less than 3, pickle will try\n"
376"to map the new Python 3 names to the old module names used in Python\n"
377"2, so that the pickle data stream is readable with Python 2.");
378
379#define _PICKLE_DUMP_METHODDEF \
380 {"dump", (PyCFunction)_pickle_dump, METH_VARARGS|METH_KEYWORDS, _pickle_dump__doc__},
381
382static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400383_pickle_dump_impl(PyModuleDef *module, PyObject *obj, PyObject *file,
384 PyObject *protocol, int fix_imports);
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200385
386static PyObject *
387_pickle_dump(PyModuleDef *module, PyObject *args, PyObject *kwargs)
388{
389 PyObject *return_value = NULL;
390 static char *_keywords[] = {"obj", "file", "protocol", "fix_imports", NULL};
391 PyObject *obj;
392 PyObject *file;
393 PyObject *protocol = NULL;
394 int fix_imports = 1;
395
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300396 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|O$p:dump", _keywords,
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200397 &obj, &file, &protocol, &fix_imports))
398 goto exit;
399 return_value = _pickle_dump_impl(module, obj, file, protocol, fix_imports);
400
401exit:
402 return return_value;
403}
404
405PyDoc_STRVAR(_pickle_dumps__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800406"dumps($module, /, obj, protocol=None, *, fix_imports=True)\n"
407"--\n"
408"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200409"Return the pickled representation of the object as a bytes object.\n"
410"\n"
411"The optional *protocol* argument tells the pickler to use the given\n"
412"protocol; supported protocols are 0, 1, 2, 3 and 4. The default\n"
413"protocol is 3; a backward-incompatible protocol designed for Python 3.\n"
414"\n"
415"Specifying a negative protocol version selects the highest protocol\n"
416"version supported. The higher the protocol used, the more recent the\n"
417"version of Python needed to read the pickle produced.\n"
418"\n"
419"If *fix_imports* is True and *protocol* is less than 3, pickle will\n"
420"try to map the new Python 3 names to the old module names used in\n"
421"Python 2, so that the pickle data stream is readable with Python 2.");
422
423#define _PICKLE_DUMPS_METHODDEF \
424 {"dumps", (PyCFunction)_pickle_dumps, METH_VARARGS|METH_KEYWORDS, _pickle_dumps__doc__},
425
426static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400427_pickle_dumps_impl(PyModuleDef *module, PyObject *obj, PyObject *protocol,
428 int fix_imports);
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200429
430static PyObject *
431_pickle_dumps(PyModuleDef *module, PyObject *args, PyObject *kwargs)
432{
433 PyObject *return_value = NULL;
434 static char *_keywords[] = {"obj", "protocol", "fix_imports", NULL};
435 PyObject *obj;
436 PyObject *protocol = NULL;
437 int fix_imports = 1;
438
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300439 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O$p:dumps", _keywords,
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200440 &obj, &protocol, &fix_imports))
441 goto exit;
442 return_value = _pickle_dumps_impl(module, obj, protocol, fix_imports);
443
444exit:
445 return return_value;
446}
447
448PyDoc_STRVAR(_pickle_load__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800449"load($module, /, file, *, fix_imports=True, encoding=\'ASCII\',\n"
450" errors=\'strict\')\n"
451"--\n"
452"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200453"Read and return an object from the pickle data stored in a file.\n"
454"\n"
455"This is equivalent to ``Unpickler(file).load()``, but may be more\n"
456"efficient.\n"
457"\n"
458"The protocol version of the pickle is detected automatically, so no\n"
459"protocol argument is needed. Bytes past the pickled object\'s\n"
460"representation are ignored.\n"
461"\n"
462"The argument *file* must have two methods, a read() method that takes\n"
463"an integer argument, and a readline() method that requires no\n"
464"arguments. Both methods should return bytes. Thus *file* can be a\n"
465"binary file object opened for reading, a io.BytesIO object, or any\n"
466"other custom object that meets this interface.\n"
467"\n"
468"Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n"
469"which are used to control compatiblity support for pickle stream\n"
470"generated by Python 2. If *fix_imports* is True, pickle will try to\n"
471"map the old Python 2 names to the new names used in Python 3. The\n"
472"*encoding* and *errors* tell pickle how to decode 8-bit string\n"
473"instances pickled by Python 2; these default to \'ASCII\' and \'strict\',\n"
474"respectively. The *encoding* can be \'bytes\' to read these 8-bit\n"
475"string instances as bytes objects.");
476
477#define _PICKLE_LOAD_METHODDEF \
478 {"load", (PyCFunction)_pickle_load, METH_VARARGS|METH_KEYWORDS, _pickle_load__doc__},
479
480static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400481_pickle_load_impl(PyModuleDef *module, PyObject *file, int fix_imports,
482 const char *encoding, const char *errors);
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200483
484static PyObject *
485_pickle_load(PyModuleDef *module, PyObject *args, PyObject *kwargs)
486{
487 PyObject *return_value = NULL;
488 static char *_keywords[] = {"file", "fix_imports", "encoding", "errors", NULL};
489 PyObject *file;
490 int fix_imports = 1;
491 const char *encoding = "ASCII";
492 const char *errors = "strict";
493
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300494 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|$pss:load", _keywords,
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200495 &file, &fix_imports, &encoding, &errors))
496 goto exit;
497 return_value = _pickle_load_impl(module, file, fix_imports, encoding, errors);
498
499exit:
500 return return_value;
501}
502
503PyDoc_STRVAR(_pickle_loads__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800504"loads($module, /, data, *, fix_imports=True, encoding=\'ASCII\',\n"
505" errors=\'strict\')\n"
506"--\n"
507"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200508"Read and return an object from the given pickle data.\n"
509"\n"
510"The protocol version of the pickle is detected automatically, so no\n"
511"protocol argument is needed. Bytes past the pickled object\'s\n"
512"representation are ignored.\n"
513"\n"
514"Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n"
515"which are used to control compatiblity support for pickle stream\n"
516"generated by Python 2. If *fix_imports* is True, pickle will try to\n"
517"map the old Python 2 names to the new names used in Python 3. The\n"
518"*encoding* and *errors* tell pickle how to decode 8-bit string\n"
519"instances pickled by Python 2; these default to \'ASCII\' and \'strict\',\n"
520"respectively. The *encoding* can be \'bytes\' to read these 8-bit\n"
521"string instances as bytes objects.");
522
523#define _PICKLE_LOADS_METHODDEF \
524 {"loads", (PyCFunction)_pickle_loads, METH_VARARGS|METH_KEYWORDS, _pickle_loads__doc__},
525
526static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400527_pickle_loads_impl(PyModuleDef *module, PyObject *data, int fix_imports,
528 const char *encoding, const char *errors);
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200529
530static PyObject *
531_pickle_loads(PyModuleDef *module, PyObject *args, PyObject *kwargs)
532{
533 PyObject *return_value = NULL;
534 static char *_keywords[] = {"data", "fix_imports", "encoding", "errors", NULL};
535 PyObject *data;
536 int fix_imports = 1;
537 const char *encoding = "ASCII";
538 const char *errors = "strict";
539
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300540 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|$pss:loads", _keywords,
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200541 &data, &fix_imports, &encoding, &errors))
542 goto exit;
543 return_value = _pickle_loads_impl(module, data, fix_imports, encoding, errors);
544
545exit:
546 return return_value;
547}
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300548/*[clinic end generated code: output=06f3a5233298448e input=a9049054013a1b77]*/