| 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; | 
|  | 96 | static char *_keywords[] = {"file", "protocol", "fix_imports", NULL}; | 
|  | 97 | PyObject *file; | 
|  | 98 | PyObject *protocol = NULL; | 
|  | 99 | int fix_imports = 1; | 
|  | 100 |  | 
| Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 101 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|Op:Pickler", _keywords, | 
| Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame^] | 102 | &file, &protocol, &fix_imports)) { | 
| Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 103 | goto exit; | 
| Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame^] | 104 | } | 
| Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 105 | return_value = _pickle_Pickler___init___impl((PicklerObject *)self, file, protocol, fix_imports); | 
|  | 106 |  | 
|  | 107 | exit: | 
|  | 108 | return return_value; | 
|  | 109 | } | 
|  | 110 |  | 
|  | 111 | PyDoc_STRVAR(_pickle_PicklerMemoProxy_clear__doc__, | 
| Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 112 | "clear($self, /)\n" | 
|  | 113 | "--\n" | 
|  | 114 | "\n" | 
| Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 115 | "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 |  | 
|  | 120 | static PyObject * | 
|  | 121 | _pickle_PicklerMemoProxy_clear_impl(PicklerMemoProxyObject *self); | 
|  | 122 |  | 
|  | 123 | static PyObject * | 
|  | 124 | _pickle_PicklerMemoProxy_clear(PicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored)) | 
|  | 125 | { | 
|  | 126 | return _pickle_PicklerMemoProxy_clear_impl(self); | 
|  | 127 | } | 
|  | 128 |  | 
|  | 129 | PyDoc_STRVAR(_pickle_PicklerMemoProxy_copy__doc__, | 
| Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 130 | "copy($self, /)\n" | 
|  | 131 | "--\n" | 
|  | 132 | "\n" | 
| Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 133 | "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 |  | 
|  | 138 | static PyObject * | 
|  | 139 | _pickle_PicklerMemoProxy_copy_impl(PicklerMemoProxyObject *self); | 
|  | 140 |  | 
|  | 141 | static PyObject * | 
|  | 142 | _pickle_PicklerMemoProxy_copy(PicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored)) | 
|  | 143 | { | 
|  | 144 | return _pickle_PicklerMemoProxy_copy_impl(self); | 
|  | 145 | } | 
|  | 146 |  | 
|  | 147 | PyDoc_STRVAR(_pickle_PicklerMemoProxy___reduce____doc__, | 
| Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 148 | "__reduce__($self, /)\n" | 
|  | 149 | "--\n" | 
|  | 150 | "\n" | 
| Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 151 | "Implement pickle support."); | 
|  | 152 |  | 
|  | 153 | #define _PICKLE_PICKLERMEMOPROXY___REDUCE___METHODDEF    \ | 
|  | 154 | {"__reduce__", (PyCFunction)_pickle_PicklerMemoProxy___reduce__, METH_NOARGS, _pickle_PicklerMemoProxy___reduce____doc__}, | 
|  | 155 |  | 
|  | 156 | static PyObject * | 
|  | 157 | _pickle_PicklerMemoProxy___reduce___impl(PicklerMemoProxyObject *self); | 
|  | 158 |  | 
|  | 159 | static PyObject * | 
|  | 160 | _pickle_PicklerMemoProxy___reduce__(PicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored)) | 
|  | 161 | { | 
|  | 162 | return _pickle_PicklerMemoProxy___reduce___impl(self); | 
|  | 163 | } | 
|  | 164 |  | 
|  | 165 | PyDoc_STRVAR(_pickle_Unpickler_load__doc__, | 
| Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 166 | "load($self, /)\n" | 
|  | 167 | "--\n" | 
|  | 168 | "\n" | 
| Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 169 | "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 |  | 
|  | 178 | static PyObject * | 
|  | 179 | _pickle_Unpickler_load_impl(UnpicklerObject *self); | 
|  | 180 |  | 
|  | 181 | static PyObject * | 
|  | 182 | _pickle_Unpickler_load(UnpicklerObject *self, PyObject *Py_UNUSED(ignored)) | 
|  | 183 | { | 
|  | 184 | return _pickle_Unpickler_load_impl(self); | 
|  | 185 | } | 
|  | 186 |  | 
|  | 187 | PyDoc_STRVAR(_pickle_Unpickler_find_class__doc__, | 
| Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 188 | "find_class($self, module_name, global_name, /)\n" | 
|  | 189 | "--\n" | 
|  | 190 | "\n" | 
| Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 191 | "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 |  | 
|  | 203 | static PyObject * | 
| Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 204 | _pickle_Unpickler_find_class_impl(UnpicklerObject *self, | 
|  | 205 | PyObject *module_name, | 
|  | 206 | PyObject *global_name); | 
| Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 207 |  | 
|  | 208 | static 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 Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame^] | 217 | &module_name, &global_name)) { | 
| Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 218 | goto exit; | 
| Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame^] | 219 | } | 
| Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 220 | return_value = _pickle_Unpickler_find_class_impl(self, module_name, global_name); | 
|  | 221 |  | 
|  | 222 | exit: | 
|  | 223 | return return_value; | 
|  | 224 | } | 
|  | 225 |  | 
| Serhiy Storchaka | 5bbd231 | 2014-12-16 19:39:08 +0200 | [diff] [blame] | 226 | PyDoc_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 |  | 
|  | 235 | static Py_ssize_t | 
|  | 236 | _pickle_Unpickler___sizeof___impl(UnpicklerObject *self); | 
|  | 237 |  | 
|  | 238 | static 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 Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame^] | 245 | if ((_return_value == -1) && PyErr_Occurred()) { | 
| Serhiy Storchaka | 5bbd231 | 2014-12-16 19:39:08 +0200 | [diff] [blame] | 246 | goto exit; | 
| Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame^] | 247 | } | 
| Serhiy Storchaka | 5bbd231 | 2014-12-16 19:39:08 +0200 | [diff] [blame] | 248 | return_value = PyLong_FromSsize_t(_return_value); | 
|  | 249 |  | 
|  | 250 | exit: | 
|  | 251 | return return_value; | 
|  | 252 | } | 
|  | 253 |  | 
| Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 254 | PyDoc_STRVAR(_pickle_Unpickler___init____doc__, | 
| Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 255 | "Unpickler(file, *, fix_imports=True, encoding=\'ASCII\', errors=\'strict\')\n" | 
|  | 256 | "--\n" | 
|  | 257 | "\n" | 
| Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 258 | "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 Panter | 7462b649 | 2015-11-02 03:37:02 +0000 | [diff] [blame] | 267 | "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] | 268 | "other custom object that meets this interface.\n" | 
|  | 269 | "\n" | 
|  | 270 | "Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n" | 
| Martin Panter | 46f5072 | 2016-05-26 05:35:26 +0000 | [diff] [blame] | 271 | "which are used to control compatibility support for pickle stream\n" | 
| Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 272 | "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 |  | 
|  | 279 | static int | 
| Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 280 | _pickle_Unpickler___init___impl(UnpicklerObject *self, PyObject *file, | 
|  | 281 | int fix_imports, const char *encoding, | 
|  | 282 | const char *errors); | 
| Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 283 |  | 
|  | 284 | static 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 Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 294 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|$pss:Unpickler", _keywords, | 
| Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame^] | 295 | &file, &fix_imports, &encoding, &errors)) { | 
| Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 296 | goto exit; | 
| Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame^] | 297 | } | 
| Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 298 | return_value = _pickle_Unpickler___init___impl((UnpicklerObject *)self, file, fix_imports, encoding, errors); | 
|  | 299 |  | 
|  | 300 | exit: | 
|  | 301 | return return_value; | 
|  | 302 | } | 
|  | 303 |  | 
|  | 304 | PyDoc_STRVAR(_pickle_UnpicklerMemoProxy_clear__doc__, | 
| Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 305 | "clear($self, /)\n" | 
|  | 306 | "--\n" | 
|  | 307 | "\n" | 
| Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 308 | "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 |  | 
|  | 313 | static PyObject * | 
|  | 314 | _pickle_UnpicklerMemoProxy_clear_impl(UnpicklerMemoProxyObject *self); | 
|  | 315 |  | 
|  | 316 | static PyObject * | 
|  | 317 | _pickle_UnpicklerMemoProxy_clear(UnpicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored)) | 
|  | 318 | { | 
|  | 319 | return _pickle_UnpicklerMemoProxy_clear_impl(self); | 
|  | 320 | } | 
|  | 321 |  | 
|  | 322 | PyDoc_STRVAR(_pickle_UnpicklerMemoProxy_copy__doc__, | 
| Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 323 | "copy($self, /)\n" | 
|  | 324 | "--\n" | 
|  | 325 | "\n" | 
| Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 326 | "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 |  | 
|  | 331 | static PyObject * | 
|  | 332 | _pickle_UnpicklerMemoProxy_copy_impl(UnpicklerMemoProxyObject *self); | 
|  | 333 |  | 
|  | 334 | static PyObject * | 
|  | 335 | _pickle_UnpicklerMemoProxy_copy(UnpicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored)) | 
|  | 336 | { | 
|  | 337 | return _pickle_UnpicklerMemoProxy_copy_impl(self); | 
|  | 338 | } | 
|  | 339 |  | 
|  | 340 | PyDoc_STRVAR(_pickle_UnpicklerMemoProxy___reduce____doc__, | 
| Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 341 | "__reduce__($self, /)\n" | 
|  | 342 | "--\n" | 
|  | 343 | "\n" | 
| Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 344 | "Implement pickling support."); | 
|  | 345 |  | 
|  | 346 | #define _PICKLE_UNPICKLERMEMOPROXY___REDUCE___METHODDEF    \ | 
|  | 347 | {"__reduce__", (PyCFunction)_pickle_UnpicklerMemoProxy___reduce__, METH_NOARGS, _pickle_UnpicklerMemoProxy___reduce____doc__}, | 
|  | 348 |  | 
|  | 349 | static PyObject * | 
|  | 350 | _pickle_UnpicklerMemoProxy___reduce___impl(UnpicklerMemoProxyObject *self); | 
|  | 351 |  | 
|  | 352 | static PyObject * | 
|  | 353 | _pickle_UnpicklerMemoProxy___reduce__(UnpicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored)) | 
|  | 354 | { | 
|  | 355 | return _pickle_UnpicklerMemoProxy___reduce___impl(self); | 
|  | 356 | } | 
|  | 357 |  | 
|  | 358 | PyDoc_STRVAR(_pickle_dump__doc__, | 
| Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 359 | "dump($module, /, obj, file, protocol=None, *, fix_imports=True)\n" | 
|  | 360 | "--\n" | 
|  | 361 | "\n" | 
| Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 362 | "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 Panter | 7462b649 | 2015-11-02 03:37:02 +0000 | [diff] [blame] | 377 | "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] | 378 | "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 |  | 
|  | 387 | static PyObject * | 
| Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 388 | _pickle_dump_impl(PyModuleDef *module, PyObject *obj, PyObject *file, | 
|  | 389 | PyObject *protocol, int fix_imports); | 
| Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 390 |  | 
|  | 391 | static 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 Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 401 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|O$p:dump", _keywords, | 
| Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame^] | 402 | &obj, &file, &protocol, &fix_imports)) { | 
| Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 403 | goto exit; | 
| Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame^] | 404 | } | 
| Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 405 | return_value = _pickle_dump_impl(module, obj, file, protocol, fix_imports); | 
|  | 406 |  | 
|  | 407 | exit: | 
|  | 408 | return return_value; | 
|  | 409 | } | 
|  | 410 |  | 
|  | 411 | PyDoc_STRVAR(_pickle_dumps__doc__, | 
| Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 412 | "dumps($module, /, obj, protocol=None, *, fix_imports=True)\n" | 
|  | 413 | "--\n" | 
|  | 414 | "\n" | 
| Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 415 | "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 |  | 
|  | 432 | static PyObject * | 
| Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 433 | _pickle_dumps_impl(PyModuleDef *module, PyObject *obj, PyObject *protocol, | 
|  | 434 | int fix_imports); | 
| Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 435 |  | 
|  | 436 | static 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 Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 445 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O$p:dumps", _keywords, | 
| Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame^] | 446 | &obj, &protocol, &fix_imports)) { | 
| Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 447 | goto exit; | 
| Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame^] | 448 | } | 
| Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 449 | return_value = _pickle_dumps_impl(module, obj, protocol, fix_imports); | 
|  | 450 |  | 
|  | 451 | exit: | 
|  | 452 | return return_value; | 
|  | 453 | } | 
|  | 454 |  | 
|  | 455 | PyDoc_STRVAR(_pickle_load__doc__, | 
| Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 456 | "load($module, /, file, *, fix_imports=True, encoding=\'ASCII\',\n" | 
|  | 457 | "     errors=\'strict\')\n" | 
|  | 458 | "--\n" | 
|  | 459 | "\n" | 
| Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 460 | "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 Panter | 7462b649 | 2015-11-02 03:37:02 +0000 | [diff] [blame] | 472 | "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] | 473 | "other custom object that meets this interface.\n" | 
|  | 474 | "\n" | 
|  | 475 | "Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n" | 
| Martin Panter | 46f5072 | 2016-05-26 05:35:26 +0000 | [diff] [blame] | 476 | "which are used to control compatibility support for pickle stream\n" | 
| Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 477 | "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 |  | 
|  | 487 | static PyObject * | 
| Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 488 | _pickle_load_impl(PyModuleDef *module, PyObject *file, int fix_imports, | 
|  | 489 | const char *encoding, const char *errors); | 
| Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 490 |  | 
|  | 491 | static 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 Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 501 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|$pss:load", _keywords, | 
| Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame^] | 502 | &file, &fix_imports, &encoding, &errors)) { | 
| Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 503 | goto exit; | 
| Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame^] | 504 | } | 
| Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 505 | return_value = _pickle_load_impl(module, file, fix_imports, encoding, errors); | 
|  | 506 |  | 
|  | 507 | exit: | 
|  | 508 | return return_value; | 
|  | 509 | } | 
|  | 510 |  | 
|  | 511 | PyDoc_STRVAR(_pickle_loads__doc__, | 
| Larry Hastings | 2623c8c | 2014-02-08 22:15:29 -0800 | [diff] [blame] | 512 | "loads($module, /, data, *, fix_imports=True, encoding=\'ASCII\',\n" | 
|  | 513 | "      errors=\'strict\')\n" | 
|  | 514 | "--\n" | 
|  | 515 | "\n" | 
| Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 516 | "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 Panter | 46f5072 | 2016-05-26 05:35:26 +0000 | [diff] [blame] | 523 | "which are used to control compatibility support for pickle stream\n" | 
| Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 524 | "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 |  | 
|  | 534 | static PyObject * | 
| Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 535 | _pickle_loads_impl(PyModuleDef *module, PyObject *data, int fix_imports, | 
|  | 536 | const char *encoding, const char *errors); | 
| Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 537 |  | 
|  | 538 | static 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 Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 548 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|$pss:loads", _keywords, | 
| Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame^] | 549 | &data, &fix_imports, &encoding, &errors)) { | 
| Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 550 | goto exit; | 
| Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame^] | 551 | } | 
| Serhiy Storchaka | 3c1f0f1 | 2014-01-27 10:34:22 +0200 | [diff] [blame] | 552 | return_value = _pickle_loads_impl(module, data, fix_imports, encoding, errors); | 
|  | 553 |  | 
|  | 554 | exit: | 
|  | 555 | return return_value; | 
|  | 556 | } | 
| Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame^] | 557 | /*[clinic end generated code: output=5e972f339d197760 input=a9049054013a1b77]*/ |