blob: 11299e97e627d0c7d09cead1d45dc6c58433dc3b [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);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030056 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka5bbd2312014-12-16 19:39:08 +020057 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030058 }
Serhiy Storchaka5bbd2312014-12-16 19:39:08 +020059 return_value = PyLong_FromSsize_t(_return_value);
60
61exit:
62 return return_value;
63}
64
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +020065PyDoc_STRVAR(_pickle_Pickler___init____doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -080066"Pickler(file, protocol=None, fix_imports=True)\n"
67"--\n"
68"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +020069"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 and 4. The default\n"
73"protocol is 3; a backward-incompatible protocol designed for Python 3.\n"
74"\n"
75"Specifying a negative protocol version selects the highest protocol\n"
76"version supported. The higher the protocol used, the more recent the\n"
77"version of Python needed to read the pickle produced.\n"
78"\n"
79"The *file* argument must have a write() method that accepts a single\n"
80"bytes argument. It can thus be a file object opened for binary\n"
Martin Panter7462b6492015-11-02 03:37:02 +000081"writing, an io.BytesIO instance, or any other custom object that meets\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +020082"this interface.\n"
83"\n"
84"If *fix_imports* is True and protocol is less than 3, pickle will try\n"
85"to map the new Python 3 names to the old module names used in Python\n"
86"2, so that the pickle data stream is readable with Python 2.");
87
88static int
Larry Hastings89964c42015-04-14 18:07:59 -040089_pickle_Pickler___init___impl(PicklerObject *self, PyObject *file,
90 PyObject *protocol, int fix_imports);
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +020091
92static int
93_pickle_Pickler___init__(PyObject *self, PyObject *args, PyObject *kwargs)
94{
95 int return_value = -1;
96 static char *_keywords[] = {"file", "protocol", "fix_imports", NULL};
97 PyObject *file;
98 PyObject *protocol = NULL;
99 int fix_imports = 1;
100
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300101 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|Op:Pickler", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300102 &file, &protocol, &fix_imports)) {
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200103 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300104 }
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200105 return_value = _pickle_Pickler___init___impl((PicklerObject *)self, file, protocol, fix_imports);
106
107exit:
108 return return_value;
109}
110
111PyDoc_STRVAR(_pickle_PicklerMemoProxy_clear__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800112"clear($self, /)\n"
113"--\n"
114"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200115"Remove all items from memo.");
116
117#define _PICKLE_PICKLERMEMOPROXY_CLEAR_METHODDEF \
118 {"clear", (PyCFunction)_pickle_PicklerMemoProxy_clear, METH_NOARGS, _pickle_PicklerMemoProxy_clear__doc__},
119
120static PyObject *
121_pickle_PicklerMemoProxy_clear_impl(PicklerMemoProxyObject *self);
122
123static PyObject *
124_pickle_PicklerMemoProxy_clear(PicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
125{
126 return _pickle_PicklerMemoProxy_clear_impl(self);
127}
128
129PyDoc_STRVAR(_pickle_PicklerMemoProxy_copy__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800130"copy($self, /)\n"
131"--\n"
132"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200133"Copy the memo to a new object.");
134
135#define _PICKLE_PICKLERMEMOPROXY_COPY_METHODDEF \
136 {"copy", (PyCFunction)_pickle_PicklerMemoProxy_copy, METH_NOARGS, _pickle_PicklerMemoProxy_copy__doc__},
137
138static PyObject *
139_pickle_PicklerMemoProxy_copy_impl(PicklerMemoProxyObject *self);
140
141static PyObject *
142_pickle_PicklerMemoProxy_copy(PicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
143{
144 return _pickle_PicklerMemoProxy_copy_impl(self);
145}
146
147PyDoc_STRVAR(_pickle_PicklerMemoProxy___reduce____doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800148"__reduce__($self, /)\n"
149"--\n"
150"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200151"Implement pickle support.");
152
153#define _PICKLE_PICKLERMEMOPROXY___REDUCE___METHODDEF \
154 {"__reduce__", (PyCFunction)_pickle_PicklerMemoProxy___reduce__, METH_NOARGS, _pickle_PicklerMemoProxy___reduce____doc__},
155
156static PyObject *
157_pickle_PicklerMemoProxy___reduce___impl(PicklerMemoProxyObject *self);
158
159static PyObject *
160_pickle_PicklerMemoProxy___reduce__(PicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
161{
162 return _pickle_PicklerMemoProxy___reduce___impl(self);
163}
164
165PyDoc_STRVAR(_pickle_Unpickler_load__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800166"load($self, /)\n"
167"--\n"
168"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200169"Load a pickle.\n"
170"\n"
171"Read a pickled object representation from the open file object given\n"
172"in the constructor, and return the reconstituted object hierarchy\n"
173"specified therein.");
174
175#define _PICKLE_UNPICKLER_LOAD_METHODDEF \
176 {"load", (PyCFunction)_pickle_Unpickler_load, METH_NOARGS, _pickle_Unpickler_load__doc__},
177
178static PyObject *
179_pickle_Unpickler_load_impl(UnpicklerObject *self);
180
181static PyObject *
182_pickle_Unpickler_load(UnpicklerObject *self, PyObject *Py_UNUSED(ignored))
183{
184 return _pickle_Unpickler_load_impl(self);
185}
186
187PyDoc_STRVAR(_pickle_Unpickler_find_class__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800188"find_class($self, module_name, global_name, /)\n"
189"--\n"
190"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200191"Return an object from a specified module.\n"
192"\n"
193"If necessary, the module will be imported. Subclasses may override\n"
194"this method (e.g. to restrict unpickling of arbitrary classes and\n"
195"functions).\n"
196"\n"
197"This method is called whenever a class or a function object is\n"
198"needed. Both arguments passed are str objects.");
199
200#define _PICKLE_UNPICKLER_FIND_CLASS_METHODDEF \
201 {"find_class", (PyCFunction)_pickle_Unpickler_find_class, METH_VARARGS, _pickle_Unpickler_find_class__doc__},
202
203static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400204_pickle_Unpickler_find_class_impl(UnpicklerObject *self,
205 PyObject *module_name,
206 PyObject *global_name);
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200207
208static PyObject *
209_pickle_Unpickler_find_class(UnpicklerObject *self, PyObject *args)
210{
211 PyObject *return_value = NULL;
212 PyObject *module_name;
213 PyObject *global_name;
214
215 if (!PyArg_UnpackTuple(args, "find_class",
216 2, 2,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300217 &module_name, &global_name)) {
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200218 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300219 }
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200220 return_value = _pickle_Unpickler_find_class_impl(self, module_name, global_name);
221
222exit:
223 return return_value;
224}
225
Serhiy Storchaka5bbd2312014-12-16 19:39:08 +0200226PyDoc_STRVAR(_pickle_Unpickler___sizeof____doc__,
227"__sizeof__($self, /)\n"
228"--\n"
229"\n"
230"Returns size in memory, in bytes.");
231
232#define _PICKLE_UNPICKLER___SIZEOF___METHODDEF \
233 {"__sizeof__", (PyCFunction)_pickle_Unpickler___sizeof__, METH_NOARGS, _pickle_Unpickler___sizeof____doc__},
234
235static Py_ssize_t
236_pickle_Unpickler___sizeof___impl(UnpicklerObject *self);
237
238static PyObject *
239_pickle_Unpickler___sizeof__(UnpicklerObject *self, PyObject *Py_UNUSED(ignored))
240{
241 PyObject *return_value = NULL;
242 Py_ssize_t _return_value;
243
244 _return_value = _pickle_Unpickler___sizeof___impl(self);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300245 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka5bbd2312014-12-16 19:39:08 +0200246 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300247 }
Serhiy Storchaka5bbd2312014-12-16 19:39:08 +0200248 return_value = PyLong_FromSsize_t(_return_value);
249
250exit:
251 return return_value;
252}
253
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200254PyDoc_STRVAR(_pickle_Unpickler___init____doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800255"Unpickler(file, *, fix_imports=True, encoding=\'ASCII\', errors=\'strict\')\n"
256"--\n"
257"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200258"This takes a binary file for reading a pickle data stream.\n"
259"\n"
260"The protocol version of the pickle is detected automatically, so no\n"
261"protocol argument is needed. Bytes past the pickled object\'s\n"
262"representation are ignored.\n"
263"\n"
264"The argument *file* must have two methods, a read() method that takes\n"
265"an integer argument, and a readline() method that requires no\n"
266"arguments. Both methods should return bytes. Thus *file* can be a\n"
Martin Panter7462b6492015-11-02 03:37:02 +0000267"binary file object opened for reading, an io.BytesIO object, or any\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200268"other custom object that meets this interface.\n"
269"\n"
270"Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n"
Martin Panter46f50722016-05-26 05:35:26 +0000271"which are used to control compatibility support for pickle stream\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200272"generated by Python 2. If *fix_imports* is True, pickle will try to\n"
273"map the old Python 2 names to the new names used in Python 3. The\n"
274"*encoding* and *errors* tell pickle how to decode 8-bit string\n"
275"instances pickled by Python 2; these default to \'ASCII\' and \'strict\',\n"
276"respectively. The *encoding* can be \'bytes\' to read these 8-bit\n"
277"string instances as bytes objects.");
278
279static int
Larry Hastings89964c42015-04-14 18:07:59 -0400280_pickle_Unpickler___init___impl(UnpicklerObject *self, PyObject *file,
281 int fix_imports, const char *encoding,
282 const char *errors);
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200283
284static int
285_pickle_Unpickler___init__(PyObject *self, PyObject *args, PyObject *kwargs)
286{
287 int return_value = -1;
288 static char *_keywords[] = {"file", "fix_imports", "encoding", "errors", NULL};
289 PyObject *file;
290 int fix_imports = 1;
291 const char *encoding = "ASCII";
292 const char *errors = "strict";
293
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300294 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|$pss:Unpickler", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300295 &file, &fix_imports, &encoding, &errors)) {
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200296 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300297 }
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200298 return_value = _pickle_Unpickler___init___impl((UnpicklerObject *)self, file, fix_imports, encoding, errors);
299
300exit:
301 return return_value;
302}
303
304PyDoc_STRVAR(_pickle_UnpicklerMemoProxy_clear__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800305"clear($self, /)\n"
306"--\n"
307"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200308"Remove all items from memo.");
309
310#define _PICKLE_UNPICKLERMEMOPROXY_CLEAR_METHODDEF \
311 {"clear", (PyCFunction)_pickle_UnpicklerMemoProxy_clear, METH_NOARGS, _pickle_UnpicklerMemoProxy_clear__doc__},
312
313static PyObject *
314_pickle_UnpicklerMemoProxy_clear_impl(UnpicklerMemoProxyObject *self);
315
316static PyObject *
317_pickle_UnpicklerMemoProxy_clear(UnpicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
318{
319 return _pickle_UnpicklerMemoProxy_clear_impl(self);
320}
321
322PyDoc_STRVAR(_pickle_UnpicklerMemoProxy_copy__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800323"copy($self, /)\n"
324"--\n"
325"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200326"Copy the memo to a new object.");
327
328#define _PICKLE_UNPICKLERMEMOPROXY_COPY_METHODDEF \
329 {"copy", (PyCFunction)_pickle_UnpicklerMemoProxy_copy, METH_NOARGS, _pickle_UnpicklerMemoProxy_copy__doc__},
330
331static PyObject *
332_pickle_UnpicklerMemoProxy_copy_impl(UnpicklerMemoProxyObject *self);
333
334static PyObject *
335_pickle_UnpicklerMemoProxy_copy(UnpicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
336{
337 return _pickle_UnpicklerMemoProxy_copy_impl(self);
338}
339
340PyDoc_STRVAR(_pickle_UnpicklerMemoProxy___reduce____doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800341"__reduce__($self, /)\n"
342"--\n"
343"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200344"Implement pickling support.");
345
346#define _PICKLE_UNPICKLERMEMOPROXY___REDUCE___METHODDEF \
347 {"__reduce__", (PyCFunction)_pickle_UnpicklerMemoProxy___reduce__, METH_NOARGS, _pickle_UnpicklerMemoProxy___reduce____doc__},
348
349static PyObject *
350_pickle_UnpicklerMemoProxy___reduce___impl(UnpicklerMemoProxyObject *self);
351
352static PyObject *
353_pickle_UnpicklerMemoProxy___reduce__(UnpicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
354{
355 return _pickle_UnpicklerMemoProxy___reduce___impl(self);
356}
357
358PyDoc_STRVAR(_pickle_dump__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800359"dump($module, /, obj, file, protocol=None, *, fix_imports=True)\n"
360"--\n"
361"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200362"Write a pickled representation of obj to the open file object file.\n"
363"\n"
364"This is equivalent to ``Pickler(file, protocol).dump(obj)``, but may\n"
365"be more efficient.\n"
366"\n"
367"The optional *protocol* argument tells the pickler to use the given\n"
368"protocol supported protocols are 0, 1, 2, 3 and 4. The default\n"
369"protocol is 3; a backward-incompatible protocol designed for Python 3.\n"
370"\n"
371"Specifying a negative protocol version selects the highest protocol\n"
372"version supported. The higher the protocol used, the more recent the\n"
373"version of Python needed to read the pickle produced.\n"
374"\n"
375"The *file* argument must have a write() method that accepts a single\n"
376"bytes argument. It can thus be a file object opened for binary\n"
Martin Panter7462b6492015-11-02 03:37:02 +0000377"writing, an io.BytesIO instance, or any other custom object that meets\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200378"this interface.\n"
379"\n"
380"If *fix_imports* is True and protocol is less than 3, pickle will try\n"
381"to map the new Python 3 names to the old module names used in Python\n"
382"2, so that the pickle data stream is readable with Python 2.");
383
384#define _PICKLE_DUMP_METHODDEF \
385 {"dump", (PyCFunction)_pickle_dump, METH_VARARGS|METH_KEYWORDS, _pickle_dump__doc__},
386
387static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400388_pickle_dump_impl(PyModuleDef *module, PyObject *obj, PyObject *file,
389 PyObject *protocol, int fix_imports);
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200390
391static PyObject *
392_pickle_dump(PyModuleDef *module, PyObject *args, PyObject *kwargs)
393{
394 PyObject *return_value = NULL;
395 static char *_keywords[] = {"obj", "file", "protocol", "fix_imports", NULL};
396 PyObject *obj;
397 PyObject *file;
398 PyObject *protocol = NULL;
399 int fix_imports = 1;
400
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300401 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|O$p:dump", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300402 &obj, &file, &protocol, &fix_imports)) {
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200403 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300404 }
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200405 return_value = _pickle_dump_impl(module, obj, file, protocol, fix_imports);
406
407exit:
408 return return_value;
409}
410
411PyDoc_STRVAR(_pickle_dumps__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800412"dumps($module, /, obj, protocol=None, *, fix_imports=True)\n"
413"--\n"
414"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200415"Return the pickled representation of the object as a bytes object.\n"
416"\n"
417"The optional *protocol* argument tells the pickler to use the given\n"
418"protocol; supported protocols are 0, 1, 2, 3 and 4. The default\n"
419"protocol is 3; a backward-incompatible protocol designed for Python 3.\n"
420"\n"
421"Specifying a negative protocol version selects the highest protocol\n"
422"version supported. The higher the protocol used, the more recent the\n"
423"version of Python needed to read the pickle produced.\n"
424"\n"
425"If *fix_imports* is True and *protocol* is less than 3, pickle will\n"
426"try to map the new Python 3 names to the old module names used in\n"
427"Python 2, so that the pickle data stream is readable with Python 2.");
428
429#define _PICKLE_DUMPS_METHODDEF \
430 {"dumps", (PyCFunction)_pickle_dumps, METH_VARARGS|METH_KEYWORDS, _pickle_dumps__doc__},
431
432static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400433_pickle_dumps_impl(PyModuleDef *module, PyObject *obj, PyObject *protocol,
434 int fix_imports);
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200435
436static PyObject *
437_pickle_dumps(PyModuleDef *module, PyObject *args, PyObject *kwargs)
438{
439 PyObject *return_value = NULL;
440 static char *_keywords[] = {"obj", "protocol", "fix_imports", NULL};
441 PyObject *obj;
442 PyObject *protocol = NULL;
443 int fix_imports = 1;
444
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300445 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O$p:dumps", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300446 &obj, &protocol, &fix_imports)) {
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200447 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300448 }
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200449 return_value = _pickle_dumps_impl(module, obj, protocol, fix_imports);
450
451exit:
452 return return_value;
453}
454
455PyDoc_STRVAR(_pickle_load__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800456"load($module, /, file, *, fix_imports=True, encoding=\'ASCII\',\n"
457" errors=\'strict\')\n"
458"--\n"
459"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200460"Read and return an object from the pickle data stored in a file.\n"
461"\n"
462"This is equivalent to ``Unpickler(file).load()``, but may be more\n"
463"efficient.\n"
464"\n"
465"The protocol version of the pickle is detected automatically, so no\n"
466"protocol argument is needed. Bytes past the pickled object\'s\n"
467"representation are ignored.\n"
468"\n"
469"The argument *file* must have two methods, a read() method that takes\n"
470"an integer argument, and a readline() method that requires no\n"
471"arguments. Both methods should return bytes. Thus *file* can be a\n"
Martin Panter7462b6492015-11-02 03:37:02 +0000472"binary file object opened for reading, an io.BytesIO object, or any\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200473"other custom object that meets this interface.\n"
474"\n"
475"Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n"
Martin Panter46f50722016-05-26 05:35:26 +0000476"which are used to control compatibility support for pickle stream\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200477"generated by Python 2. If *fix_imports* is True, pickle will try to\n"
478"map the old Python 2 names to the new names used in Python 3. The\n"
479"*encoding* and *errors* tell pickle how to decode 8-bit string\n"
480"instances pickled by Python 2; these default to \'ASCII\' and \'strict\',\n"
481"respectively. The *encoding* can be \'bytes\' to read these 8-bit\n"
482"string instances as bytes objects.");
483
484#define _PICKLE_LOAD_METHODDEF \
485 {"load", (PyCFunction)_pickle_load, METH_VARARGS|METH_KEYWORDS, _pickle_load__doc__},
486
487static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400488_pickle_load_impl(PyModuleDef *module, PyObject *file, int fix_imports,
489 const char *encoding, const char *errors);
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200490
491static PyObject *
492_pickle_load(PyModuleDef *module, PyObject *args, PyObject *kwargs)
493{
494 PyObject *return_value = NULL;
495 static char *_keywords[] = {"file", "fix_imports", "encoding", "errors", NULL};
496 PyObject *file;
497 int fix_imports = 1;
498 const char *encoding = "ASCII";
499 const char *errors = "strict";
500
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300501 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|$pss:load", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300502 &file, &fix_imports, &encoding, &errors)) {
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200503 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300504 }
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200505 return_value = _pickle_load_impl(module, file, fix_imports, encoding, errors);
506
507exit:
508 return return_value;
509}
510
511PyDoc_STRVAR(_pickle_loads__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800512"loads($module, /, data, *, fix_imports=True, encoding=\'ASCII\',\n"
513" errors=\'strict\')\n"
514"--\n"
515"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200516"Read and return an object from the given pickle data.\n"
517"\n"
518"The protocol version of the pickle is detected automatically, so no\n"
519"protocol argument is needed. Bytes past the pickled object\'s\n"
520"representation are ignored.\n"
521"\n"
522"Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n"
Martin Panter46f50722016-05-26 05:35:26 +0000523"which are used to control compatibility support for pickle stream\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200524"generated by Python 2. If *fix_imports* is True, pickle will try to\n"
525"map the old Python 2 names to the new names used in Python 3. The\n"
526"*encoding* and *errors* tell pickle how to decode 8-bit string\n"
527"instances pickled by Python 2; these default to \'ASCII\' and \'strict\',\n"
528"respectively. The *encoding* can be \'bytes\' to read these 8-bit\n"
529"string instances as bytes objects.");
530
531#define _PICKLE_LOADS_METHODDEF \
532 {"loads", (PyCFunction)_pickle_loads, METH_VARARGS|METH_KEYWORDS, _pickle_loads__doc__},
533
534static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400535_pickle_loads_impl(PyModuleDef *module, PyObject *data, int fix_imports,
536 const char *encoding, const char *errors);
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200537
538static PyObject *
539_pickle_loads(PyModuleDef *module, PyObject *args, PyObject *kwargs)
540{
541 PyObject *return_value = NULL;
542 static char *_keywords[] = {"data", "fix_imports", "encoding", "errors", NULL};
543 PyObject *data;
544 int fix_imports = 1;
545 const char *encoding = "ASCII";
546 const char *errors = "strict";
547
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300548 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|$pss:loads", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300549 &data, &fix_imports, &encoding, &errors)) {
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200550 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300551 }
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200552 return_value = _pickle_loads_impl(module, data, fix_imports, encoding, errors);
553
554exit:
555 return return_value;
556}
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300557/*[clinic end generated code: output=5e972f339d197760 input=a9049054013a1b77]*/