Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 1 | /*[clinic input] |
| 2 | preserve |
| 3 | [clinic start generated code]*/ |
| 4 | |
| 5 | PyDoc_STRVAR(_pickle_Pickler_clear_memo__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 6 | "clear_memo($self, /)\n" |
| 7 | "--\n" |
| 8 | "\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 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 | _pickle_Pickler_clear_memo(PicklerObject *self, PyObject *Py_UNUSED(ignored)) |
| 24 | { |
| 25 | return _pickle_Pickler_clear_memo_impl(self); |
| 26 | } |
| 27 | |
| 28 | PyDoc_STRVAR(_pickle_Pickler_dump__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 29 | "dump($self, obj, /)\n" |
| 30 | "--\n" |
| 31 | "\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 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 | |
Serhiy Storchaka | 5bbd231 | 2014-12-16 19:39:08 +0200 | [diff] [blame] | 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 | _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 Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 56 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 5bbd231 | 2014-12-16 19:39:08 +0200 | [diff] [blame] | 57 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 58 | } |
Serhiy Storchaka | 5bbd231 | 2014-12-16 19:39:08 +0200 | [diff] [blame] | 59 | return_value = PyLong_FromSsize_t(_return_value); |
| 60 | |
| 61 | exit: |
| 62 | return return_value; |
| 63 | } |
| 64 | |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 65 | PyDoc_STRVAR(_pickle_Pickler___init____doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 66 | "Pickler(file, protocol=None, fix_imports=True)\n" |
| 67 | "--\n" |
| 68 | "\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 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 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 Panter | 7462b649 | 2015-11-02 03:37:02 +0000 | [diff] [blame] | 81 | "writing, an io.BytesIO instance, or any other custom object that meets\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 82 | "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 | |
| 88 | static int |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 89 | _pickle_Pickler___init___impl(PicklerObject *self, PyObject *file, |
| 90 | PyObject *protocol, int fix_imports); |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 91 | |
| 92 | static int |
| 93 | _pickle_Pickler___init__(PyObject *self, PyObject *args, PyObject *kwargs) |
| 94 | { |
| 95 | int return_value = -1; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 96 | static const char * const _keywords[] = {"file", "protocol", "fix_imports", NULL}; |
| 97 | static _PyArg_Parser _parser = {"O|Op:Pickler", _keywords, 0}; |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 98 | PyObject *file; |
| 99 | PyObject *protocol = NULL; |
| 100 | int fix_imports = 1; |
| 101 | |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 102 | if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 103 | &file, &protocol, &fix_imports)) { |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 104 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 105 | } |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 106 | return_value = _pickle_Pickler___init___impl((PicklerObject *)self, file, protocol, fix_imports); |
| 107 | |
| 108 | exit: |
| 109 | return return_value; |
| 110 | } |
| 111 | |
| 112 | PyDoc_STRVAR(_pickle_PicklerMemoProxy_clear__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 113 | "clear($self, /)\n" |
| 114 | "--\n" |
| 115 | "\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 116 | "Remove all items from memo."); |
| 117 | |
| 118 | #define _PICKLE_PICKLERMEMOPROXY_CLEAR_METHODDEF \ |
| 119 | {"clear", (PyCFunction)_pickle_PicklerMemoProxy_clear, METH_NOARGS, _pickle_PicklerMemoProxy_clear__doc__}, |
| 120 | |
| 121 | static PyObject * |
| 122 | _pickle_PicklerMemoProxy_clear_impl(PicklerMemoProxyObject *self); |
| 123 | |
| 124 | static PyObject * |
| 125 | _pickle_PicklerMemoProxy_clear(PicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored)) |
| 126 | { |
| 127 | return _pickle_PicklerMemoProxy_clear_impl(self); |
| 128 | } |
| 129 | |
| 130 | PyDoc_STRVAR(_pickle_PicklerMemoProxy_copy__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 131 | "copy($self, /)\n" |
| 132 | "--\n" |
| 133 | "\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 134 | "Copy the memo to a new object."); |
| 135 | |
| 136 | #define _PICKLE_PICKLERMEMOPROXY_COPY_METHODDEF \ |
| 137 | {"copy", (PyCFunction)_pickle_PicklerMemoProxy_copy, METH_NOARGS, _pickle_PicklerMemoProxy_copy__doc__}, |
| 138 | |
| 139 | static PyObject * |
| 140 | _pickle_PicklerMemoProxy_copy_impl(PicklerMemoProxyObject *self); |
| 141 | |
| 142 | static PyObject * |
| 143 | _pickle_PicklerMemoProxy_copy(PicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored)) |
| 144 | { |
| 145 | return _pickle_PicklerMemoProxy_copy_impl(self); |
| 146 | } |
| 147 | |
| 148 | PyDoc_STRVAR(_pickle_PicklerMemoProxy___reduce____doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 149 | "__reduce__($self, /)\n" |
| 150 | "--\n" |
| 151 | "\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 152 | "Implement pickle support."); |
| 153 | |
| 154 | #define _PICKLE_PICKLERMEMOPROXY___REDUCE___METHODDEF \ |
| 155 | {"__reduce__", (PyCFunction)_pickle_PicklerMemoProxy___reduce__, METH_NOARGS, _pickle_PicklerMemoProxy___reduce____doc__}, |
| 156 | |
| 157 | static PyObject * |
| 158 | _pickle_PicklerMemoProxy___reduce___impl(PicklerMemoProxyObject *self); |
| 159 | |
| 160 | static PyObject * |
| 161 | _pickle_PicklerMemoProxy___reduce__(PicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored)) |
| 162 | { |
| 163 | return _pickle_PicklerMemoProxy___reduce___impl(self); |
| 164 | } |
| 165 | |
| 166 | PyDoc_STRVAR(_pickle_Unpickler_load__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 167 | "load($self, /)\n" |
| 168 | "--\n" |
| 169 | "\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 170 | "Load a pickle.\n" |
| 171 | "\n" |
| 172 | "Read a pickled object representation from the open file object given\n" |
| 173 | "in the constructor, and return the reconstituted object hierarchy\n" |
| 174 | "specified therein."); |
| 175 | |
| 176 | #define _PICKLE_UNPICKLER_LOAD_METHODDEF \ |
| 177 | {"load", (PyCFunction)_pickle_Unpickler_load, METH_NOARGS, _pickle_Unpickler_load__doc__}, |
| 178 | |
| 179 | static PyObject * |
| 180 | _pickle_Unpickler_load_impl(UnpicklerObject *self); |
| 181 | |
| 182 | static PyObject * |
| 183 | _pickle_Unpickler_load(UnpicklerObject *self, PyObject *Py_UNUSED(ignored)) |
| 184 | { |
| 185 | return _pickle_Unpickler_load_impl(self); |
| 186 | } |
| 187 | |
| 188 | PyDoc_STRVAR(_pickle_Unpickler_find_class__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 189 | "find_class($self, module_name, global_name, /)\n" |
| 190 | "--\n" |
| 191 | "\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 192 | "Return an object from a specified module.\n" |
| 193 | "\n" |
| 194 | "If necessary, the module will be imported. Subclasses may override\n" |
| 195 | "this method (e.g. to restrict unpickling of arbitrary classes and\n" |
| 196 | "functions).\n" |
| 197 | "\n" |
| 198 | "This method is called whenever a class or a function object is\n" |
| 199 | "needed. Both arguments passed are str objects."); |
| 200 | |
| 201 | #define _PICKLE_UNPICKLER_FIND_CLASS_METHODDEF \ |
| 202 | {"find_class", (PyCFunction)_pickle_Unpickler_find_class, METH_VARARGS, _pickle_Unpickler_find_class__doc__}, |
| 203 | |
| 204 | static PyObject * |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 205 | _pickle_Unpickler_find_class_impl(UnpicklerObject *self, |
| 206 | PyObject *module_name, |
| 207 | PyObject *global_name); |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 208 | |
| 209 | static PyObject * |
| 210 | _pickle_Unpickler_find_class(UnpicklerObject *self, PyObject *args) |
| 211 | { |
| 212 | PyObject *return_value = NULL; |
| 213 | PyObject *module_name; |
| 214 | PyObject *global_name; |
| 215 | |
| 216 | if (!PyArg_UnpackTuple(args, "find_class", |
| 217 | 2, 2, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 218 | &module_name, &global_name)) { |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 219 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 220 | } |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 221 | return_value = _pickle_Unpickler_find_class_impl(self, module_name, global_name); |
| 222 | |
| 223 | exit: |
| 224 | return return_value; |
| 225 | } |
| 226 | |
Serhiy Storchaka | 5bbd231 | 2014-12-16 19:39:08 +0200 | [diff] [blame] | 227 | PyDoc_STRVAR(_pickle_Unpickler___sizeof____doc__, |
| 228 | "__sizeof__($self, /)\n" |
| 229 | "--\n" |
| 230 | "\n" |
| 231 | "Returns size in memory, in bytes."); |
| 232 | |
| 233 | #define _PICKLE_UNPICKLER___SIZEOF___METHODDEF \ |
| 234 | {"__sizeof__", (PyCFunction)_pickle_Unpickler___sizeof__, METH_NOARGS, _pickle_Unpickler___sizeof____doc__}, |
| 235 | |
| 236 | static Py_ssize_t |
| 237 | _pickle_Unpickler___sizeof___impl(UnpicklerObject *self); |
| 238 | |
| 239 | static PyObject * |
| 240 | _pickle_Unpickler___sizeof__(UnpicklerObject *self, PyObject *Py_UNUSED(ignored)) |
| 241 | { |
| 242 | PyObject *return_value = NULL; |
| 243 | Py_ssize_t _return_value; |
| 244 | |
| 245 | _return_value = _pickle_Unpickler___sizeof___impl(self); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 246 | if ((_return_value == -1) && PyErr_Occurred()) { |
Serhiy Storchaka | 5bbd231 | 2014-12-16 19:39:08 +0200 | [diff] [blame] | 247 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 248 | } |
Serhiy Storchaka | 5bbd231 | 2014-12-16 19:39:08 +0200 | [diff] [blame] | 249 | return_value = PyLong_FromSsize_t(_return_value); |
| 250 | |
| 251 | exit: |
| 252 | return return_value; |
| 253 | } |
| 254 | |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 255 | PyDoc_STRVAR(_pickle_Unpickler___init____doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 256 | "Unpickler(file, *, fix_imports=True, encoding=\'ASCII\', errors=\'strict\')\n" |
| 257 | "--\n" |
| 258 | "\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 259 | "This takes a binary file for reading a pickle data stream.\n" |
| 260 | "\n" |
| 261 | "The protocol version of the pickle is detected automatically, so no\n" |
| 262 | "protocol argument is needed. Bytes past the pickled object\'s\n" |
| 263 | "representation are ignored.\n" |
| 264 | "\n" |
| 265 | "The argument *file* must have two methods, a read() method that takes\n" |
| 266 | "an integer argument, and a readline() method that requires no\n" |
| 267 | "arguments. Both methods should return bytes. Thus *file* can be a\n" |
Martin Panter | 7462b649 | 2015-11-02 03:37:02 +0000 | [diff] [blame] | 268 | "binary file object opened for reading, an io.BytesIO object, or any\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 269 | "other custom object that meets this interface.\n" |
| 270 | "\n" |
| 271 | "Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n" |
Martin Panter | 46f5072 | 2016-05-26 05:35:26 +0000 | [diff] [blame] | 272 | "which are used to control compatibility support for pickle stream\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 273 | "generated by Python 2. If *fix_imports* is True, pickle will try to\n" |
| 274 | "map the old Python 2 names to the new names used in Python 3. The\n" |
| 275 | "*encoding* and *errors* tell pickle how to decode 8-bit string\n" |
| 276 | "instances pickled by Python 2; these default to \'ASCII\' and \'strict\',\n" |
| 277 | "respectively. The *encoding* can be \'bytes\' to read these 8-bit\n" |
| 278 | "string instances as bytes objects."); |
| 279 | |
| 280 | static int |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 281 | _pickle_Unpickler___init___impl(UnpicklerObject *self, PyObject *file, |
| 282 | int fix_imports, const char *encoding, |
| 283 | const char *errors); |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 284 | |
| 285 | static int |
| 286 | _pickle_Unpickler___init__(PyObject *self, PyObject *args, PyObject *kwargs) |
| 287 | { |
| 288 | int return_value = -1; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 289 | static const char * const _keywords[] = {"file", "fix_imports", "encoding", "errors", NULL}; |
| 290 | static _PyArg_Parser _parser = {"O|$pss:Unpickler", _keywords, 0}; |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 291 | PyObject *file; |
| 292 | int fix_imports = 1; |
| 293 | const char *encoding = "ASCII"; |
| 294 | const char *errors = "strict"; |
| 295 | |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 296 | if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 297 | &file, &fix_imports, &encoding, &errors)) { |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 298 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 299 | } |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 300 | return_value = _pickle_Unpickler___init___impl((UnpicklerObject *)self, file, fix_imports, encoding, errors); |
| 301 | |
| 302 | exit: |
| 303 | return return_value; |
| 304 | } |
| 305 | |
| 306 | PyDoc_STRVAR(_pickle_UnpicklerMemoProxy_clear__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 307 | "clear($self, /)\n" |
| 308 | "--\n" |
| 309 | "\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 310 | "Remove all items from memo."); |
| 311 | |
| 312 | #define _PICKLE_UNPICKLERMEMOPROXY_CLEAR_METHODDEF \ |
| 313 | {"clear", (PyCFunction)_pickle_UnpicklerMemoProxy_clear, METH_NOARGS, _pickle_UnpicklerMemoProxy_clear__doc__}, |
| 314 | |
| 315 | static PyObject * |
| 316 | _pickle_UnpicklerMemoProxy_clear_impl(UnpicklerMemoProxyObject *self); |
| 317 | |
| 318 | static PyObject * |
| 319 | _pickle_UnpicklerMemoProxy_clear(UnpicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored)) |
| 320 | { |
| 321 | return _pickle_UnpicklerMemoProxy_clear_impl(self); |
| 322 | } |
| 323 | |
| 324 | PyDoc_STRVAR(_pickle_UnpicklerMemoProxy_copy__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 325 | "copy($self, /)\n" |
| 326 | "--\n" |
| 327 | "\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 328 | "Copy the memo to a new object."); |
| 329 | |
| 330 | #define _PICKLE_UNPICKLERMEMOPROXY_COPY_METHODDEF \ |
| 331 | {"copy", (PyCFunction)_pickle_UnpicklerMemoProxy_copy, METH_NOARGS, _pickle_UnpicklerMemoProxy_copy__doc__}, |
| 332 | |
| 333 | static PyObject * |
| 334 | _pickle_UnpicklerMemoProxy_copy_impl(UnpicklerMemoProxyObject *self); |
| 335 | |
| 336 | static PyObject * |
| 337 | _pickle_UnpicklerMemoProxy_copy(UnpicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored)) |
| 338 | { |
| 339 | return _pickle_UnpicklerMemoProxy_copy_impl(self); |
| 340 | } |
| 341 | |
| 342 | PyDoc_STRVAR(_pickle_UnpicklerMemoProxy___reduce____doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 343 | "__reduce__($self, /)\n" |
| 344 | "--\n" |
| 345 | "\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 346 | "Implement pickling support."); |
| 347 | |
| 348 | #define _PICKLE_UNPICKLERMEMOPROXY___REDUCE___METHODDEF \ |
| 349 | {"__reduce__", (PyCFunction)_pickle_UnpicklerMemoProxy___reduce__, METH_NOARGS, _pickle_UnpicklerMemoProxy___reduce____doc__}, |
| 350 | |
| 351 | static PyObject * |
| 352 | _pickle_UnpicklerMemoProxy___reduce___impl(UnpicklerMemoProxyObject *self); |
| 353 | |
| 354 | static PyObject * |
| 355 | _pickle_UnpicklerMemoProxy___reduce__(UnpicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored)) |
| 356 | { |
| 357 | return _pickle_UnpicklerMemoProxy___reduce___impl(self); |
| 358 | } |
| 359 | |
| 360 | PyDoc_STRVAR(_pickle_dump__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 361 | "dump($module, /, obj, file, protocol=None, *, fix_imports=True)\n" |
| 362 | "--\n" |
| 363 | "\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 364 | "Write a pickled representation of obj to the open file object file.\n" |
| 365 | "\n" |
| 366 | "This is equivalent to ``Pickler(file, protocol).dump(obj)``, but may\n" |
| 367 | "be more efficient.\n" |
| 368 | "\n" |
| 369 | "The optional *protocol* argument tells the pickler to use the given\n" |
| 370 | "protocol supported protocols are 0, 1, 2, 3 and 4. The default\n" |
| 371 | "protocol is 3; a backward-incompatible protocol designed for Python 3.\n" |
| 372 | "\n" |
| 373 | "Specifying a negative protocol version selects the highest protocol\n" |
| 374 | "version supported. The higher the protocol used, the more recent the\n" |
| 375 | "version of Python needed to read the pickle produced.\n" |
| 376 | "\n" |
| 377 | "The *file* argument must have a write() method that accepts a single\n" |
| 378 | "bytes argument. It can thus be a file object opened for binary\n" |
Martin Panter | 7462b649 | 2015-11-02 03:37:02 +0000 | [diff] [blame] | 379 | "writing, an io.BytesIO instance, or any other custom object that meets\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 380 | "this interface.\n" |
| 381 | "\n" |
| 382 | "If *fix_imports* is True and protocol is less than 3, pickle will try\n" |
| 383 | "to map the new Python 3 names to the old module names used in Python\n" |
| 384 | "2, so that the pickle data stream is readable with Python 2."); |
| 385 | |
| 386 | #define _PICKLE_DUMP_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 387 | {"dump", (PyCFunction)_pickle_dump, METH_FASTCALL, _pickle_dump__doc__}, |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 388 | |
| 389 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 390 | _pickle_dump_impl(PyObject *module, PyObject *obj, PyObject *file, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 391 | PyObject *protocol, int fix_imports); |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 392 | |
| 393 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 394 | _pickle_dump(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 395 | { |
| 396 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 397 | static const char * const _keywords[] = {"obj", "file", "protocol", "fix_imports", NULL}; |
| 398 | static _PyArg_Parser _parser = {"OO|O$p:dump", _keywords, 0}; |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 399 | PyObject *obj; |
| 400 | PyObject *file; |
| 401 | PyObject *protocol = NULL; |
| 402 | int fix_imports = 1; |
| 403 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 404 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 405 | &obj, &file, &protocol, &fix_imports)) { |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 406 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 407 | } |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 408 | return_value = _pickle_dump_impl(module, obj, file, protocol, fix_imports); |
| 409 | |
| 410 | exit: |
| 411 | return return_value; |
| 412 | } |
| 413 | |
| 414 | PyDoc_STRVAR(_pickle_dumps__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 415 | "dumps($module, /, obj, protocol=None, *, fix_imports=True)\n" |
| 416 | "--\n" |
| 417 | "\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 418 | "Return the pickled representation of the object as a bytes object.\n" |
| 419 | "\n" |
| 420 | "The optional *protocol* argument tells the pickler to use the given\n" |
| 421 | "protocol; supported protocols are 0, 1, 2, 3 and 4. The default\n" |
| 422 | "protocol is 3; a backward-incompatible protocol designed for Python 3.\n" |
| 423 | "\n" |
| 424 | "Specifying a negative protocol version selects the highest protocol\n" |
| 425 | "version supported. The higher the protocol used, the more recent the\n" |
| 426 | "version of Python needed to read the pickle produced.\n" |
| 427 | "\n" |
| 428 | "If *fix_imports* is True and *protocol* is less than 3, pickle will\n" |
| 429 | "try to map the new Python 3 names to the old module names used in\n" |
| 430 | "Python 2, so that the pickle data stream is readable with Python 2."); |
| 431 | |
| 432 | #define _PICKLE_DUMPS_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 433 | {"dumps", (PyCFunction)_pickle_dumps, METH_FASTCALL, _pickle_dumps__doc__}, |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 434 | |
| 435 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 436 | _pickle_dumps_impl(PyObject *module, PyObject *obj, PyObject *protocol, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 437 | int fix_imports); |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 438 | |
| 439 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 440 | _pickle_dumps(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 441 | { |
| 442 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 443 | static const char * const _keywords[] = {"obj", "protocol", "fix_imports", NULL}; |
| 444 | static _PyArg_Parser _parser = {"O|O$p:dumps", _keywords, 0}; |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 445 | PyObject *obj; |
| 446 | PyObject *protocol = NULL; |
| 447 | int fix_imports = 1; |
| 448 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 449 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 450 | &obj, &protocol, &fix_imports)) { |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 451 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 452 | } |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 453 | return_value = _pickle_dumps_impl(module, obj, protocol, fix_imports); |
| 454 | |
| 455 | exit: |
| 456 | return return_value; |
| 457 | } |
| 458 | |
| 459 | PyDoc_STRVAR(_pickle_load__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 460 | "load($module, /, file, *, fix_imports=True, encoding=\'ASCII\',\n" |
| 461 | " errors=\'strict\')\n" |
| 462 | "--\n" |
| 463 | "\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 464 | "Read and return an object from the pickle data stored in a file.\n" |
| 465 | "\n" |
| 466 | "This is equivalent to ``Unpickler(file).load()``, but may be more\n" |
| 467 | "efficient.\n" |
| 468 | "\n" |
| 469 | "The protocol version of the pickle is detected automatically, so no\n" |
| 470 | "protocol argument is needed. Bytes past the pickled object\'s\n" |
| 471 | "representation are ignored.\n" |
| 472 | "\n" |
| 473 | "The argument *file* must have two methods, a read() method that takes\n" |
| 474 | "an integer argument, and a readline() method that requires no\n" |
| 475 | "arguments. Both methods should return bytes. Thus *file* can be a\n" |
Martin Panter | 7462b649 | 2015-11-02 03:37:02 +0000 | [diff] [blame] | 476 | "binary file object opened for reading, an io.BytesIO object, or any\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 477 | "other custom object that meets this interface.\n" |
| 478 | "\n" |
| 479 | "Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n" |
Martin Panter | 46f5072 | 2016-05-26 05:35:26 +0000 | [diff] [blame] | 480 | "which are used to control compatibility support for pickle stream\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 481 | "generated by Python 2. If *fix_imports* is True, pickle will try to\n" |
| 482 | "map the old Python 2 names to the new names used in Python 3. The\n" |
| 483 | "*encoding* and *errors* tell pickle how to decode 8-bit string\n" |
| 484 | "instances pickled by Python 2; these default to \'ASCII\' and \'strict\',\n" |
| 485 | "respectively. The *encoding* can be \'bytes\' to read these 8-bit\n" |
| 486 | "string instances as bytes objects."); |
| 487 | |
| 488 | #define _PICKLE_LOAD_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 489 | {"load", (PyCFunction)_pickle_load, METH_FASTCALL, _pickle_load__doc__}, |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 490 | |
| 491 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 492 | _pickle_load_impl(PyObject *module, PyObject *file, int fix_imports, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 493 | const char *encoding, const char *errors); |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 494 | |
| 495 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 496 | _pickle_load(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 497 | { |
| 498 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 499 | static const char * const _keywords[] = {"file", "fix_imports", "encoding", "errors", NULL}; |
| 500 | static _PyArg_Parser _parser = {"O|$pss:load", _keywords, 0}; |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 501 | PyObject *file; |
| 502 | int fix_imports = 1; |
| 503 | const char *encoding = "ASCII"; |
| 504 | const char *errors = "strict"; |
| 505 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 506 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 507 | &file, &fix_imports, &encoding, &errors)) { |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 508 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 509 | } |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 510 | return_value = _pickle_load_impl(module, file, fix_imports, encoding, errors); |
| 511 | |
| 512 | exit: |
| 513 | return return_value; |
| 514 | } |
| 515 | |
| 516 | PyDoc_STRVAR(_pickle_loads__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 517 | "loads($module, /, data, *, fix_imports=True, encoding=\'ASCII\',\n" |
| 518 | " errors=\'strict\')\n" |
| 519 | "--\n" |
| 520 | "\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 521 | "Read and return an object from the given pickle data.\n" |
| 522 | "\n" |
| 523 | "The protocol version of the pickle is detected automatically, so no\n" |
| 524 | "protocol argument is needed. Bytes past the pickled object\'s\n" |
| 525 | "representation are ignored.\n" |
| 526 | "\n" |
| 527 | "Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n" |
Martin Panter | 46f5072 | 2016-05-26 05:35:26 +0000 | [diff] [blame] | 528 | "which are used to control compatibility support for pickle stream\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 529 | "generated by Python 2. If *fix_imports* is True, pickle will try to\n" |
| 530 | "map the old Python 2 names to the new names used in Python 3. The\n" |
| 531 | "*encoding* and *errors* tell pickle how to decode 8-bit string\n" |
| 532 | "instances pickled by Python 2; these default to \'ASCII\' and \'strict\',\n" |
| 533 | "respectively. The *encoding* can be \'bytes\' to read these 8-bit\n" |
| 534 | "string instances as bytes objects."); |
| 535 | |
| 536 | #define _PICKLE_LOADS_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 537 | {"loads", (PyCFunction)_pickle_loads, METH_FASTCALL, _pickle_loads__doc__}, |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 538 | |
| 539 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 540 | _pickle_loads_impl(PyObject *module, PyObject *data, int fix_imports, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 541 | const char *encoding, const char *errors); |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 542 | |
| 543 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 544 | _pickle_loads(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 545 | { |
| 546 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 547 | static const char * const _keywords[] = {"data", "fix_imports", "encoding", "errors", NULL}; |
| 548 | static _PyArg_Parser _parser = {"O|$pss:loads", _keywords, 0}; |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 549 | PyObject *data; |
| 550 | int fix_imports = 1; |
| 551 | const char *encoding = "ASCII"; |
| 552 | const char *errors = "strict"; |
| 553 | |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 554 | if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 555 | &data, &fix_imports, &encoding, &errors)) { |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 556 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 557 | } |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 558 | return_value = _pickle_loads_impl(module, data, fix_imports, encoding, errors); |
| 559 | |
| 560 | exit: |
| 561 | return return_value; |
| 562 | } |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 563 | /*[clinic end generated code: output=82be137b3c09cb9f input=a9049054013a1b77]*/ |