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 |
| 88 | _pickle_Pickler___init___impl(PicklerObject *self, PyObject *file, PyObject *protocol, int fix_imports); |
| 89 | |
| 90 | static int |
| 91 | _pickle_Pickler___init__(PyObject *self, PyObject *args, PyObject *kwargs) |
| 92 | { |
| 93 | int return_value = -1; |
| 94 | static char *_keywords[] = {"file", "protocol", "fix_imports", NULL}; |
| 95 | PyObject *file; |
| 96 | PyObject *protocol = NULL; |
| 97 | int fix_imports = 1; |
| 98 | |
| 99 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 100 | "O|Op:Pickler", _keywords, |
| 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 * |
| 202 | _pickle_Unpickler_find_class_impl(UnpicklerObject *self, PyObject *module_name, PyObject *global_name); |
| 203 | |
| 204 | static PyObject * |
| 205 | _pickle_Unpickler_find_class(UnpicklerObject *self, PyObject *args) |
| 206 | { |
| 207 | PyObject *return_value = NULL; |
| 208 | PyObject *module_name; |
| 209 | PyObject *global_name; |
| 210 | |
| 211 | if (!PyArg_UnpackTuple(args, "find_class", |
| 212 | 2, 2, |
| 213 | &module_name, &global_name)) |
| 214 | goto exit; |
| 215 | return_value = _pickle_Unpickler_find_class_impl(self, module_name, global_name); |
| 216 | |
| 217 | exit: |
| 218 | return return_value; |
| 219 | } |
| 220 | |
Serhiy Storchaka | 5bbd231 | 2014-12-16 19:39:08 +0200 | [diff] [blame^] | 221 | PyDoc_STRVAR(_pickle_Unpickler___sizeof____doc__, |
| 222 | "__sizeof__($self, /)\n" |
| 223 | "--\n" |
| 224 | "\n" |
| 225 | "Returns size in memory, in bytes."); |
| 226 | |
| 227 | #define _PICKLE_UNPICKLER___SIZEOF___METHODDEF \ |
| 228 | {"__sizeof__", (PyCFunction)_pickle_Unpickler___sizeof__, METH_NOARGS, _pickle_Unpickler___sizeof____doc__}, |
| 229 | |
| 230 | static Py_ssize_t |
| 231 | _pickle_Unpickler___sizeof___impl(UnpicklerObject *self); |
| 232 | |
| 233 | static PyObject * |
| 234 | _pickle_Unpickler___sizeof__(UnpicklerObject *self, PyObject *Py_UNUSED(ignored)) |
| 235 | { |
| 236 | PyObject *return_value = NULL; |
| 237 | Py_ssize_t _return_value; |
| 238 | |
| 239 | _return_value = _pickle_Unpickler___sizeof___impl(self); |
| 240 | if ((_return_value == -1) && PyErr_Occurred()) |
| 241 | goto exit; |
| 242 | return_value = PyLong_FromSsize_t(_return_value); |
| 243 | |
| 244 | exit: |
| 245 | return return_value; |
| 246 | } |
| 247 | |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 248 | PyDoc_STRVAR(_pickle_Unpickler___init____doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 249 | "Unpickler(file, *, fix_imports=True, encoding=\'ASCII\', errors=\'strict\')\n" |
| 250 | "--\n" |
| 251 | "\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 252 | "This takes a binary file for reading a pickle data stream.\n" |
| 253 | "\n" |
| 254 | "The protocol version of the pickle is detected automatically, so no\n" |
| 255 | "protocol argument is needed. Bytes past the pickled object\'s\n" |
| 256 | "representation are ignored.\n" |
| 257 | "\n" |
| 258 | "The argument *file* must have two methods, a read() method that takes\n" |
| 259 | "an integer argument, and a readline() method that requires no\n" |
| 260 | "arguments. Both methods should return bytes. Thus *file* can be a\n" |
| 261 | "binary file object opened for reading, a io.BytesIO object, or any\n" |
| 262 | "other custom object that meets this interface.\n" |
| 263 | "\n" |
| 264 | "Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n" |
| 265 | "which are used to control compatiblity support for pickle stream\n" |
| 266 | "generated by Python 2. If *fix_imports* is True, pickle will try to\n" |
| 267 | "map the old Python 2 names to the new names used in Python 3. The\n" |
| 268 | "*encoding* and *errors* tell pickle how to decode 8-bit string\n" |
| 269 | "instances pickled by Python 2; these default to \'ASCII\' and \'strict\',\n" |
| 270 | "respectively. The *encoding* can be \'bytes\' to read these 8-bit\n" |
| 271 | "string instances as bytes objects."); |
| 272 | |
| 273 | static int |
| 274 | _pickle_Unpickler___init___impl(UnpicklerObject *self, PyObject *file, int fix_imports, const char *encoding, const char *errors); |
| 275 | |
| 276 | static int |
| 277 | _pickle_Unpickler___init__(PyObject *self, PyObject *args, PyObject *kwargs) |
| 278 | { |
| 279 | int return_value = -1; |
| 280 | static char *_keywords[] = {"file", "fix_imports", "encoding", "errors", NULL}; |
| 281 | PyObject *file; |
| 282 | int fix_imports = 1; |
| 283 | const char *encoding = "ASCII"; |
| 284 | const char *errors = "strict"; |
| 285 | |
| 286 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 287 | "O|$pss:Unpickler", _keywords, |
| 288 | &file, &fix_imports, &encoding, &errors)) |
| 289 | goto exit; |
| 290 | return_value = _pickle_Unpickler___init___impl((UnpicklerObject *)self, file, fix_imports, encoding, errors); |
| 291 | |
| 292 | exit: |
| 293 | return return_value; |
| 294 | } |
| 295 | |
| 296 | PyDoc_STRVAR(_pickle_UnpicklerMemoProxy_clear__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 297 | "clear($self, /)\n" |
| 298 | "--\n" |
| 299 | "\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 300 | "Remove all items from memo."); |
| 301 | |
| 302 | #define _PICKLE_UNPICKLERMEMOPROXY_CLEAR_METHODDEF \ |
| 303 | {"clear", (PyCFunction)_pickle_UnpicklerMemoProxy_clear, METH_NOARGS, _pickle_UnpicklerMemoProxy_clear__doc__}, |
| 304 | |
| 305 | static PyObject * |
| 306 | _pickle_UnpicklerMemoProxy_clear_impl(UnpicklerMemoProxyObject *self); |
| 307 | |
| 308 | static PyObject * |
| 309 | _pickle_UnpicklerMemoProxy_clear(UnpicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored)) |
| 310 | { |
| 311 | return _pickle_UnpicklerMemoProxy_clear_impl(self); |
| 312 | } |
| 313 | |
| 314 | PyDoc_STRVAR(_pickle_UnpicklerMemoProxy_copy__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 315 | "copy($self, /)\n" |
| 316 | "--\n" |
| 317 | "\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 318 | "Copy the memo to a new object."); |
| 319 | |
| 320 | #define _PICKLE_UNPICKLERMEMOPROXY_COPY_METHODDEF \ |
| 321 | {"copy", (PyCFunction)_pickle_UnpicklerMemoProxy_copy, METH_NOARGS, _pickle_UnpicklerMemoProxy_copy__doc__}, |
| 322 | |
| 323 | static PyObject * |
| 324 | _pickle_UnpicklerMemoProxy_copy_impl(UnpicklerMemoProxyObject *self); |
| 325 | |
| 326 | static PyObject * |
| 327 | _pickle_UnpicklerMemoProxy_copy(UnpicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored)) |
| 328 | { |
| 329 | return _pickle_UnpicklerMemoProxy_copy_impl(self); |
| 330 | } |
| 331 | |
| 332 | PyDoc_STRVAR(_pickle_UnpicklerMemoProxy___reduce____doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 333 | "__reduce__($self, /)\n" |
| 334 | "--\n" |
| 335 | "\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 336 | "Implement pickling support."); |
| 337 | |
| 338 | #define _PICKLE_UNPICKLERMEMOPROXY___REDUCE___METHODDEF \ |
| 339 | {"__reduce__", (PyCFunction)_pickle_UnpicklerMemoProxy___reduce__, METH_NOARGS, _pickle_UnpicklerMemoProxy___reduce____doc__}, |
| 340 | |
| 341 | static PyObject * |
| 342 | _pickle_UnpicklerMemoProxy___reduce___impl(UnpicklerMemoProxyObject *self); |
| 343 | |
| 344 | static PyObject * |
| 345 | _pickle_UnpicklerMemoProxy___reduce__(UnpicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored)) |
| 346 | { |
| 347 | return _pickle_UnpicklerMemoProxy___reduce___impl(self); |
| 348 | } |
| 349 | |
| 350 | PyDoc_STRVAR(_pickle_dump__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 351 | "dump($module, /, obj, file, protocol=None, *, fix_imports=True)\n" |
| 352 | "--\n" |
| 353 | "\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 354 | "Write a pickled representation of obj to the open file object file.\n" |
| 355 | "\n" |
| 356 | "This is equivalent to ``Pickler(file, protocol).dump(obj)``, but may\n" |
| 357 | "be more efficient.\n" |
| 358 | "\n" |
| 359 | "The optional *protocol* argument tells the pickler to use the given\n" |
| 360 | "protocol supported protocols are 0, 1, 2, 3 and 4. The default\n" |
| 361 | "protocol is 3; a backward-incompatible protocol designed for Python 3.\n" |
| 362 | "\n" |
| 363 | "Specifying a negative protocol version selects the highest protocol\n" |
| 364 | "version supported. The higher the protocol used, the more recent the\n" |
| 365 | "version of Python needed to read the pickle produced.\n" |
| 366 | "\n" |
| 367 | "The *file* argument must have a write() method that accepts a single\n" |
| 368 | "bytes argument. It can thus be a file object opened for binary\n" |
| 369 | "writing, a io.BytesIO instance, or any other custom object that meets\n" |
| 370 | "this interface.\n" |
| 371 | "\n" |
| 372 | "If *fix_imports* is True and protocol is less than 3, pickle will try\n" |
| 373 | "to map the new Python 3 names to the old module names used in Python\n" |
| 374 | "2, so that the pickle data stream is readable with Python 2."); |
| 375 | |
| 376 | #define _PICKLE_DUMP_METHODDEF \ |
| 377 | {"dump", (PyCFunction)_pickle_dump, METH_VARARGS|METH_KEYWORDS, _pickle_dump__doc__}, |
| 378 | |
| 379 | static PyObject * |
| 380 | _pickle_dump_impl(PyModuleDef *module, PyObject *obj, PyObject *file, PyObject *protocol, int fix_imports); |
| 381 | |
| 382 | static PyObject * |
| 383 | _pickle_dump(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 384 | { |
| 385 | PyObject *return_value = NULL; |
| 386 | static char *_keywords[] = {"obj", "file", "protocol", "fix_imports", NULL}; |
| 387 | PyObject *obj; |
| 388 | PyObject *file; |
| 389 | PyObject *protocol = NULL; |
| 390 | int fix_imports = 1; |
| 391 | |
| 392 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 393 | "OO|O$p:dump", _keywords, |
| 394 | &obj, &file, &protocol, &fix_imports)) |
| 395 | goto exit; |
| 396 | return_value = _pickle_dump_impl(module, obj, file, protocol, fix_imports); |
| 397 | |
| 398 | exit: |
| 399 | return return_value; |
| 400 | } |
| 401 | |
| 402 | PyDoc_STRVAR(_pickle_dumps__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 403 | "dumps($module, /, obj, protocol=None, *, fix_imports=True)\n" |
| 404 | "--\n" |
| 405 | "\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 406 | "Return the pickled representation of the object as a bytes object.\n" |
| 407 | "\n" |
| 408 | "The optional *protocol* argument tells the pickler to use the given\n" |
| 409 | "protocol; supported protocols are 0, 1, 2, 3 and 4. The default\n" |
| 410 | "protocol is 3; a backward-incompatible protocol designed for Python 3.\n" |
| 411 | "\n" |
| 412 | "Specifying a negative protocol version selects the highest protocol\n" |
| 413 | "version supported. The higher the protocol used, the more recent the\n" |
| 414 | "version of Python needed to read the pickle produced.\n" |
| 415 | "\n" |
| 416 | "If *fix_imports* is True and *protocol* is less than 3, pickle will\n" |
| 417 | "try to map the new Python 3 names to the old module names used in\n" |
| 418 | "Python 2, so that the pickle data stream is readable with Python 2."); |
| 419 | |
| 420 | #define _PICKLE_DUMPS_METHODDEF \ |
| 421 | {"dumps", (PyCFunction)_pickle_dumps, METH_VARARGS|METH_KEYWORDS, _pickle_dumps__doc__}, |
| 422 | |
| 423 | static PyObject * |
| 424 | _pickle_dumps_impl(PyModuleDef *module, PyObject *obj, PyObject *protocol, int fix_imports); |
| 425 | |
| 426 | static PyObject * |
| 427 | _pickle_dumps(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 428 | { |
| 429 | PyObject *return_value = NULL; |
| 430 | static char *_keywords[] = {"obj", "protocol", "fix_imports", NULL}; |
| 431 | PyObject *obj; |
| 432 | PyObject *protocol = NULL; |
| 433 | int fix_imports = 1; |
| 434 | |
| 435 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 436 | "O|O$p:dumps", _keywords, |
| 437 | &obj, &protocol, &fix_imports)) |
| 438 | goto exit; |
| 439 | return_value = _pickle_dumps_impl(module, obj, protocol, fix_imports); |
| 440 | |
| 441 | exit: |
| 442 | return return_value; |
| 443 | } |
| 444 | |
| 445 | PyDoc_STRVAR(_pickle_load__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 446 | "load($module, /, file, *, fix_imports=True, encoding=\'ASCII\',\n" |
| 447 | " errors=\'strict\')\n" |
| 448 | "--\n" |
| 449 | "\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 450 | "Read and return an object from the pickle data stored in a file.\n" |
| 451 | "\n" |
| 452 | "This is equivalent to ``Unpickler(file).load()``, but may be more\n" |
| 453 | "efficient.\n" |
| 454 | "\n" |
| 455 | "The protocol version of the pickle is detected automatically, so no\n" |
| 456 | "protocol argument is needed. Bytes past the pickled object\'s\n" |
| 457 | "representation are ignored.\n" |
| 458 | "\n" |
| 459 | "The argument *file* must have two methods, a read() method that takes\n" |
| 460 | "an integer argument, and a readline() method that requires no\n" |
| 461 | "arguments. Both methods should return bytes. Thus *file* can be a\n" |
| 462 | "binary file object opened for reading, a io.BytesIO object, or any\n" |
| 463 | "other custom object that meets this interface.\n" |
| 464 | "\n" |
| 465 | "Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n" |
| 466 | "which are used to control compatiblity support for pickle stream\n" |
| 467 | "generated by Python 2. If *fix_imports* is True, pickle will try to\n" |
| 468 | "map the old Python 2 names to the new names used in Python 3. The\n" |
| 469 | "*encoding* and *errors* tell pickle how to decode 8-bit string\n" |
| 470 | "instances pickled by Python 2; these default to \'ASCII\' and \'strict\',\n" |
| 471 | "respectively. The *encoding* can be \'bytes\' to read these 8-bit\n" |
| 472 | "string instances as bytes objects."); |
| 473 | |
| 474 | #define _PICKLE_LOAD_METHODDEF \ |
| 475 | {"load", (PyCFunction)_pickle_load, METH_VARARGS|METH_KEYWORDS, _pickle_load__doc__}, |
| 476 | |
| 477 | static PyObject * |
| 478 | _pickle_load_impl(PyModuleDef *module, PyObject *file, int fix_imports, const char *encoding, const char *errors); |
| 479 | |
| 480 | static PyObject * |
| 481 | _pickle_load(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 482 | { |
| 483 | PyObject *return_value = NULL; |
| 484 | static char *_keywords[] = {"file", "fix_imports", "encoding", "errors", NULL}; |
| 485 | PyObject *file; |
| 486 | int fix_imports = 1; |
| 487 | const char *encoding = "ASCII"; |
| 488 | const char *errors = "strict"; |
| 489 | |
| 490 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 491 | "O|$pss:load", _keywords, |
| 492 | &file, &fix_imports, &encoding, &errors)) |
| 493 | goto exit; |
| 494 | return_value = _pickle_load_impl(module, file, fix_imports, encoding, errors); |
| 495 | |
| 496 | exit: |
| 497 | return return_value; |
| 498 | } |
| 499 | |
| 500 | PyDoc_STRVAR(_pickle_loads__doc__, |
Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 501 | "loads($module, /, data, *, fix_imports=True, encoding=\'ASCII\',\n" |
| 502 | " errors=\'strict\')\n" |
| 503 | "--\n" |
| 504 | "\n" |
Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 505 | "Read and return an object from the given pickle data.\n" |
| 506 | "\n" |
| 507 | "The protocol version of the pickle is detected automatically, so no\n" |
| 508 | "protocol argument is needed. Bytes past the pickled object\'s\n" |
| 509 | "representation are ignored.\n" |
| 510 | "\n" |
| 511 | "Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n" |
| 512 | "which are used to control compatiblity support for pickle stream\n" |
| 513 | "generated by Python 2. If *fix_imports* is True, pickle will try to\n" |
| 514 | "map the old Python 2 names to the new names used in Python 3. The\n" |
| 515 | "*encoding* and *errors* tell pickle how to decode 8-bit string\n" |
| 516 | "instances pickled by Python 2; these default to \'ASCII\' and \'strict\',\n" |
| 517 | "respectively. The *encoding* can be \'bytes\' to read these 8-bit\n" |
| 518 | "string instances as bytes objects."); |
| 519 | |
| 520 | #define _PICKLE_LOADS_METHODDEF \ |
| 521 | {"loads", (PyCFunction)_pickle_loads, METH_VARARGS|METH_KEYWORDS, _pickle_loads__doc__}, |
| 522 | |
| 523 | static PyObject * |
| 524 | _pickle_loads_impl(PyModuleDef *module, PyObject *data, int fix_imports, const char *encoding, const char *errors); |
| 525 | |
| 526 | static PyObject * |
| 527 | _pickle_loads(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 528 | { |
| 529 | PyObject *return_value = NULL; |
| 530 | static char *_keywords[] = {"data", "fix_imports", "encoding", "errors", NULL}; |
| 531 | PyObject *data; |
| 532 | int fix_imports = 1; |
| 533 | const char *encoding = "ASCII"; |
| 534 | const char *errors = "strict"; |
| 535 | |
| 536 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
| 537 | "O|$pss:loads", _keywords, |
| 538 | &data, &fix_imports, &encoding, &errors)) |
| 539 | goto exit; |
| 540 | return_value = _pickle_loads_impl(module, data, fix_imports, encoding, errors); |
| 541 | |
| 542 | exit: |
| 543 | return return_value; |
| 544 | } |
Serhiy Storchaka | 5bbd231 | 2014-12-16 19:39:08 +0200 | [diff] [blame^] | 545 | /*[clinic end generated code: output=3aba79576e240c62 input=a9049054013a1b77]*/ |