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); |
| 56 | if ((_return_value == -1) && PyErr_Occurred()) |
| 57 | goto exit; |
| 58 | return_value = PyLong_FromSsize_t(_return_value); |
| 59 | |
| 60 | exit: |
| 61 | return return_value; |
| 62 | } |
| 63 | |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 64 | PyDoc_STRVAR(_pickle_Pickler___init____doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 65 | "Pickler(file, protocol=None, fix_imports=True)\n" |
| 66 | "--\n" |
| 67 | "\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 68 | "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 | |
| 87 | static int |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 88 | _pickle_Pickler___init___impl(PicklerObject *self, PyObject *file, |
| 89 | PyObject *protocol, int fix_imports); |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 90 | |
| 91 | static 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 Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 100 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|Op:Pickler", _keywords, |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 101 | &file, &protocol, &fix_imports)) |
| 102 | goto exit; |
| 103 | return_value = _pickle_Pickler___init___impl((PicklerObject *)self, file, protocol, fix_imports); |
| 104 | |
| 105 | exit: |
| 106 | return return_value; |
| 107 | } |
| 108 | |
| 109 | PyDoc_STRVAR(_pickle_PicklerMemoProxy_clear__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 110 | "clear($self, /)\n" |
| 111 | "--\n" |
| 112 | "\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 113 | "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 | |
| 118 | static PyObject * |
| 119 | _pickle_PicklerMemoProxy_clear_impl(PicklerMemoProxyObject *self); |
| 120 | |
| 121 | static PyObject * |
| 122 | _pickle_PicklerMemoProxy_clear(PicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored)) |
| 123 | { |
| 124 | return _pickle_PicklerMemoProxy_clear_impl(self); |
| 125 | } |
| 126 | |
| 127 | PyDoc_STRVAR(_pickle_PicklerMemoProxy_copy__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 128 | "copy($self, /)\n" |
| 129 | "--\n" |
| 130 | "\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 131 | "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 | |
| 136 | static PyObject * |
| 137 | _pickle_PicklerMemoProxy_copy_impl(PicklerMemoProxyObject *self); |
| 138 | |
| 139 | static PyObject * |
| 140 | _pickle_PicklerMemoProxy_copy(PicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored)) |
| 141 | { |
| 142 | return _pickle_PicklerMemoProxy_copy_impl(self); |
| 143 | } |
| 144 | |
| 145 | PyDoc_STRVAR(_pickle_PicklerMemoProxy___reduce____doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 146 | "__reduce__($self, /)\n" |
| 147 | "--\n" |
| 148 | "\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 149 | "Implement pickle support."); |
| 150 | |
| 151 | #define _PICKLE_PICKLERMEMOPROXY___REDUCE___METHODDEF \ |
| 152 | {"__reduce__", (PyCFunction)_pickle_PicklerMemoProxy___reduce__, METH_NOARGS, _pickle_PicklerMemoProxy___reduce____doc__}, |
| 153 | |
| 154 | static PyObject * |
| 155 | _pickle_PicklerMemoProxy___reduce___impl(PicklerMemoProxyObject *self); |
| 156 | |
| 157 | static PyObject * |
| 158 | _pickle_PicklerMemoProxy___reduce__(PicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored)) |
| 159 | { |
| 160 | return _pickle_PicklerMemoProxy___reduce___impl(self); |
| 161 | } |
| 162 | |
| 163 | PyDoc_STRVAR(_pickle_Unpickler_load__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 164 | "load($self, /)\n" |
| 165 | "--\n" |
| 166 | "\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 167 | "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 | |
| 176 | static PyObject * |
| 177 | _pickle_Unpickler_load_impl(UnpicklerObject *self); |
| 178 | |
| 179 | static PyObject * |
| 180 | _pickle_Unpickler_load(UnpicklerObject *self, PyObject *Py_UNUSED(ignored)) |
| 181 | { |
| 182 | return _pickle_Unpickler_load_impl(self); |
| 183 | } |
| 184 | |
| 185 | PyDoc_STRVAR(_pickle_Unpickler_find_class__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 186 | "find_class($self, module_name, global_name, /)\n" |
| 187 | "--\n" |
| 188 | "\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 189 | "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 | |
| 201 | static PyObject * |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 202 | _pickle_Unpickler_find_class_impl(UnpicklerObject *self, |
| 203 | PyObject *module_name, |
| 204 | PyObject *global_name); |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 205 | |
| 206 | static 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 | |
| 219 | exit: |
| 220 | return return_value; |
| 221 | } |
| 222 | |
Serhiy Storchaka | 5bbd231 | 2014-12-16 19:39:08 +0200 | [diff] [blame] | 223 | PyDoc_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 | |
| 232 | static Py_ssize_t |
| 233 | _pickle_Unpickler___sizeof___impl(UnpicklerObject *self); |
| 234 | |
| 235 | static 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 | |
| 246 | exit: |
| 247 | return return_value; |
| 248 | } |
| 249 | |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 250 | PyDoc_STRVAR(_pickle_Unpickler___init____doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 251 | "Unpickler(file, *, fix_imports=True, encoding=\'ASCII\', errors=\'strict\')\n" |
| 252 | "--\n" |
| 253 | "\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 254 | "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 | |
| 275 | static int |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 276 | _pickle_Unpickler___init___impl(UnpicklerObject *self, PyObject *file, |
| 277 | int fix_imports, const char *encoding, |
| 278 | const char *errors); |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 279 | |
| 280 | static 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 Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 290 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|$pss:Unpickler", _keywords, |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 291 | &file, &fix_imports, &encoding, &errors)) |
| 292 | goto exit; |
| 293 | return_value = _pickle_Unpickler___init___impl((UnpicklerObject *)self, file, fix_imports, encoding, errors); |
| 294 | |
| 295 | exit: |
| 296 | return return_value; |
| 297 | } |
| 298 | |
| 299 | PyDoc_STRVAR(_pickle_UnpicklerMemoProxy_clear__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 300 | "clear($self, /)\n" |
| 301 | "--\n" |
| 302 | "\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 303 | "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 | |
| 308 | static PyObject * |
| 309 | _pickle_UnpicklerMemoProxy_clear_impl(UnpicklerMemoProxyObject *self); |
| 310 | |
| 311 | static PyObject * |
| 312 | _pickle_UnpicklerMemoProxy_clear(UnpicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored)) |
| 313 | { |
| 314 | return _pickle_UnpicklerMemoProxy_clear_impl(self); |
| 315 | } |
| 316 | |
| 317 | PyDoc_STRVAR(_pickle_UnpicklerMemoProxy_copy__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 318 | "copy($self, /)\n" |
| 319 | "--\n" |
| 320 | "\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 321 | "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 | |
| 326 | static PyObject * |
| 327 | _pickle_UnpicklerMemoProxy_copy_impl(UnpicklerMemoProxyObject *self); |
| 328 | |
| 329 | static PyObject * |
| 330 | _pickle_UnpicklerMemoProxy_copy(UnpicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored)) |
| 331 | { |
| 332 | return _pickle_UnpicklerMemoProxy_copy_impl(self); |
| 333 | } |
| 334 | |
| 335 | PyDoc_STRVAR(_pickle_UnpicklerMemoProxy___reduce____doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 336 | "__reduce__($self, /)\n" |
| 337 | "--\n" |
| 338 | "\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 339 | "Implement pickling support."); |
| 340 | |
| 341 | #define _PICKLE_UNPICKLERMEMOPROXY___REDUCE___METHODDEF \ |
| 342 | {"__reduce__", (PyCFunction)_pickle_UnpicklerMemoProxy___reduce__, METH_NOARGS, _pickle_UnpicklerMemoProxy___reduce____doc__}, |
| 343 | |
| 344 | static PyObject * |
| 345 | _pickle_UnpicklerMemoProxy___reduce___impl(UnpicklerMemoProxyObject *self); |
| 346 | |
| 347 | static PyObject * |
| 348 | _pickle_UnpicklerMemoProxy___reduce__(UnpicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored)) |
| 349 | { |
| 350 | return _pickle_UnpicklerMemoProxy___reduce___impl(self); |
| 351 | } |
| 352 | |
| 353 | PyDoc_STRVAR(_pickle_dump__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 354 | "dump($module, /, obj, file, protocol=None, *, fix_imports=True)\n" |
| 355 | "--\n" |
| 356 | "\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 357 | "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 | |
| 382 | static PyObject * |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 383 | _pickle_dump_impl(PyModuleDef *module, PyObject *obj, PyObject *file, |
| 384 | PyObject *protocol, int fix_imports); |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 385 | |
| 386 | static 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 Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 396 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|O$p:dump", _keywords, |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 397 | &obj, &file, &protocol, &fix_imports)) |
| 398 | goto exit; |
| 399 | return_value = _pickle_dump_impl(module, obj, file, protocol, fix_imports); |
| 400 | |
| 401 | exit: |
| 402 | return return_value; |
| 403 | } |
| 404 | |
| 405 | PyDoc_STRVAR(_pickle_dumps__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 406 | "dumps($module, /, obj, protocol=None, *, fix_imports=True)\n" |
| 407 | "--\n" |
| 408 | "\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 409 | "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 | |
| 426 | static PyObject * |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 427 | _pickle_dumps_impl(PyModuleDef *module, PyObject *obj, PyObject *protocol, |
| 428 | int fix_imports); |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 429 | |
| 430 | static 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 Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 439 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O$p:dumps", _keywords, |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 440 | &obj, &protocol, &fix_imports)) |
| 441 | goto exit; |
| 442 | return_value = _pickle_dumps_impl(module, obj, protocol, fix_imports); |
| 443 | |
| 444 | exit: |
| 445 | return return_value; |
| 446 | } |
| 447 | |
| 448 | PyDoc_STRVAR(_pickle_load__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 449 | "load($module, /, file, *, fix_imports=True, encoding=\'ASCII\',\n" |
| 450 | " errors=\'strict\')\n" |
| 451 | "--\n" |
| 452 | "\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 453 | "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 | |
| 480 | static PyObject * |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 481 | _pickle_load_impl(PyModuleDef *module, PyObject *file, int fix_imports, |
| 482 | const char *encoding, const char *errors); |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 483 | |
| 484 | static 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 Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 494 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|$pss:load", _keywords, |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 495 | &file, &fix_imports, &encoding, &errors)) |
| 496 | goto exit; |
| 497 | return_value = _pickle_load_impl(module, file, fix_imports, encoding, errors); |
| 498 | |
| 499 | exit: |
| 500 | return return_value; |
| 501 | } |
| 502 | |
| 503 | PyDoc_STRVAR(_pickle_loads__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 504 | "loads($module, /, data, *, fix_imports=True, encoding=\'ASCII\',\n" |
| 505 | " errors=\'strict\')\n" |
| 506 | "--\n" |
| 507 | "\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 508 | "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 | |
| 526 | static PyObject * |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 527 | _pickle_loads_impl(PyModuleDef *module, PyObject *data, int fix_imports, |
| 528 | const char *encoding, const char *errors); |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 529 | |
| 530 | static 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 Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 540 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|$pss:loads", _keywords, |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 541 | &data, &fix_imports, &encoding, &errors)) |
| 542 | goto exit; |
| 543 | return_value = _pickle_loads_impl(module, data, fix_imports, encoding, errors); |
| 544 | |
| 545 | exit: |
| 546 | return return_value; |
| 547 | } |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 548 | /*[clinic end generated code: output=06f3a5233298448e input=a9049054013a1b77]*/ |