summaryrefslogtreecommitdiff
path: root/Lib/pickle.py
Commit message (Collapse)AuthorAgeFilesLines
* Revert previous checkin.Raymond Hettinger2005-02-071-15/+15
|
* Reduce the usage of the types module.Raymond Hettinger2005-02-071-15/+15
|
* Eliminate the deprecated option to return None instead of a tuple of ↵Raymond Hettinger2004-12-071-16/+2
| | | | arguments in __reduce__().
* Removed the deprecated bin parameter from the pickle module.Raymond Hettinger2004-12-051-11/+5
|
* Make 'bin' argument trigger DeprecationWarningAndrew M. Kuchling2004-08-071-1/+1
|
* Replace backticks with repr() or "%r"Walter Dörwald2004-02-121-11/+11
| | | | From SF patch #852334.
* Fix grammar in comment.Jeremy Hylton2003-06-291-1/+1
|
* Remove unused _better_reduce (which will disappear soon) andGuido van Rossum2003-02-181-1/+1
| | | | _reconstructor (whose import here is a mystery to me).
* Introducing __reduce_ex__, which is called with a protocol number argumentGuido van Rossum2003-02-181-15/+14
| | | | | if it exists in preference over __reduce__. Now Tim can go implement this in cPickle.c.
* cPickle.c, load_build(): Taught cPickle how to pick apartTim Peters2003-02-151-0/+4
| | | | | | | | | | | | | | | | | | the optional proto 2 slot state. pickle.py, load_build(): CAUTION: Noted that cPickle's load_build and pickle's load_build really don't do the same things with the state, and didn't before this patch either. cPickle never tries to do .update(), and has no backoff if instance.__dict__ can't be retrieved. There are no tests that can tell the difference, and part of what cPickle's load_build() did looked accidental to me, so I don't know what the true intent is here. pickletester.py, test_pickle.py: Got rid of the hack for exempting cPickle from running some of the proto 2 tests. dictobject.c, PyDict_Next(): documented intended use.
* Added a HIGHEST_PROTOCOL module attribute to pickle and cPickle.Tim Peters2003-02-131-3/+7
|
* Implemented batching for dicts in cPickle. This is after two failedTim Peters2003-02-111-1/+2
| | | | | attempts to merge the C list-batch and dict-batch code -- they worked, but it was a godawful mess to read.
* Implemented list batching in cPickle.Tim Peters2003-02-111-0/+1
|
* Rename 'proto' keyword arg to 'protocol' . Greg Ward's suggestion.Guido van Rossum2003-02-091-17/+17
|
* Move _better_reduce from copy.py to copy_reg.py, and also use it inGuido van Rossum2003-02-061-122/+4
| | | | pickle.py, where it makes save_newobj() unnecessary. Tests pass.
* Remove a debug print statement.Guido van Rossum2003-02-061-1/+0
|
* No need for a continuation line.Jeremy Hylton2003-02-061-2/+1
|
* Replace hasattr() + getattr() with single getattr() and default value.Jeremy Hylton2003-02-061-2/+1
|
* Rename the extension registry variables to have leading underscores --Guido van Rossum2003-02-041-5/+5
| | | | | | | | | this clarifies that they are part of an internal API (albeit shared between pickle.py, copy_reg.py and cPickle.c). I'd like to do the same for copy_reg.dispatch_table, but worry that it might be used by existing code. This risk doesn't exist for the extension registry.
* _slotnames(): this is a fairly expensive calculation. Cache theGuido van Rossum2003-02-031-6/+23
| | | | | | | outcome as __slotnames__ on the class. (Like __slots__, it's not safe to ask for this as an attribute -- you must look for it in the specific class's __dict__. But it must be set using attribute notation, because __dict__ is a read-only proxy.)
* _slotnames(): exclude __dict__ and __weakref__; these aren't realGuido van Rossum2003-02-031-1/+2
| | | | slots even though they can be listed in __slots__.
* Support keyword argument 'bin', with a pending deprecation warning.Guido van Rossum2003-02-031-5/+13
|
* cPickle support for TUPLE[123]. Incidentally plugged several undetectedTim Peters2003-02-021-7/+9
| | | | overflow holes in Pdata_grow().
* long(string, base) now takes time linear in len(string) when base is aTim Peters2003-02-021-4/+1
| | | | | power of 2. Enabled the tail end of test_long() in pickletester.py because it no longer takes forever when run from test_pickle.py.
* cPickle.c: Full support for the new LONG1 and LONG4. Added comments.Tim Peters2003-02-021-7/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Assorted code cleanups; e.g., sizeof(char) is 1 by definition, so there's no need to do things like multiply by sizeof(char) in hairy malloc arguments. Fixed an undetected-overflow bug in readline_file(). longobject.c: Fixed a really stupid bug in the new _PyLong_NumBits. pickle.py: Fixed stupid bug in save_long(): When proto is 2, it wrote LONG1 or LONG4, but forgot to return then -- it went on to append the proto 1 LONG opcode too. Fixed equally stupid cancelling bugs in load_long1() and load_long4(): they *returned* the unpickled long instead of pushing it on the stack. The return values were ignored. Tests passed before only because save_long() pickled the long twice. Fixed bugs in encode_long(). Noted that decode_long() is quadratic-time despite our hopes, because long(string, 16) is still quadratic-time in len(string). It's hex() that's linear-time. I don't know a way to make decode_long() linear-time in Python, short of maybe transforming the 256's-complement bytes into marshal's funky internal format, and letting marshal decode that. It would be more valuable to make long(string, 16) linear time. pickletester.py: Added a global "protocols" vector so tests can try all the protocols in a sane way. Changed test_ints() and test_unicode() to do so. Added a new test_long(), but the tail end of it is disabled because it "takes forever" under pickle.py (but runs very quickly under cPickle: cPickle proto 2 for longs is linear-time).
* The C pickle now knows how to deal with a proto= argument. AssortedTim Peters2003-02-011-11/+9
| | | | code cleanups, and purged more references to text-vs-binary modes.
* Change the default protocol back to 0.Guido van Rossum2003-01-311-8/+12
| | | | | Add a feature suggested by Tim: a negative protocol value means to use the largest protocol value supported.
* Another extension to reduce(). It can return a 4- or 5-tuple now.Guido van Rossum2003-01-311-67/+92
| | | | | | | | | | | | | | The 4th item can be None or an iterator yielding list items, which are used to append() or extend() the object. The 5th item can be None or an iterator yielding a dict's (key, value) pairs, which are stuffed into the object using __setitem__. Also (as a separate, though related, feature) add "batching" for list and dict items. If you pickled a dict or list with a million items in the past, it would push a million items onto the stack. It now pushes only 1000 items at a time on the stack, using repeated APPENDS or SETITEMS opcodes. (For lists, I hope that using many short extend() calls doesn't exhibit quadratic behavior.)
* Provide __module__ attributes for functions defined in C and Python.Jeremy Hylton2003-01-311-3/+6
| | | | | | | | | | | | | | __module__ is the string name of the module the function was defined in, just like __module__ of classes. In some cases, particularly for C functions, the __module__ may be None. Change PyCFunction_New() from a function to a macro, but keep an unused copy of the function around so that we don't change the binary API. Change pickle's save_global() to use whichmodule() if __module__ is None, but add the __module__ logic to whichmodule() since it might be used outside of pickle.
* Pass the object to save_reduce(), so the memoize() call can go intoGuido van Rossum2003-01-311-3/+8
| | | | | save_reduce(), before the state is pickled. This makes it possible for an object to be referenced from its own (mutable) state.
* Add a magical feature to save_reduce so that __reduce__ can causeGuido van Rossum2003-01-311-4/+40
| | | | NEWOBJ to be generated.
* It's Official: for LONG1/LONG4, a "byte count" of 0 is taken as aTim Peters2003-01-311-6/+17
| | | | | shortcut meaning 0L. This allows LONG1 to encode 0L in two bytes total.
* Fix typoNeal Norwitz2003-01-311-1/+1
|
* Linear-time implementations of {encode,decode}_long.Tim Peters2003-01-311-19/+50
|
* load_inst(), load_obj(): Put the bulk of these into a common newTim Peters2003-01-301-26/+18
| | | | _instantiate() method.
* There was a subtle big in save_newobj(): it used self.save_global(t)Guido van Rossum2003-01-301-1/+2
| | | | | | | | | | | | | | | on the type instead of self.save(t). This defeated the purpose of NEWOBJ, because it didn't generate a BINGET opcode when t was already memoized; but moreover, it would generate multiple BINPUT opcodes for the same type! pickletools.dis() doesn't like this. How I found this? I was playing with picklesize.py in the datetime sandbox, and noticed that protocol 2 pickles for multiple objects were in fact larger than protocol 1 pickles! That was suspicious, so I decided to disassemble one of the pickles. This really needs a unit test, but I'm exhausted. I'll be late for work as it is. :-(
* Slight code rearrangement to avoid testing getstate twice.Guido van Rossum2003-01-301-22/+23
|
* In save_newobj(), if an object's __getnewargs__ and __getstate__ areGuido van Rossum2003-01-301-0/+23
| | | | | | | | | the same function, don't save the state or write a BUILD opcode. This is so that a type (e.g. datetime :-) can support protocol 2 using __getnewargs__ while also supporting protocol 0 and 1 using __getstate__. (Without this, the state would be pickled twice with protocol 2, unless __getstate__ is defined to return None, which breaks protocol 0 and 1.)
* Use %c rather than chr() to turn some ints into chars.Guido van Rossum2003-01-291-2/+2
|
* Implement appropriate __getnewargs__ for all immutable subclassable builtinGuido van Rossum2003-01-291-8/+4
| | | | | | | | types. The special handling for these can now be removed from save_newobj(). Add some testing for this. Also add support for setting the 'fast' flag on the Python Pickler class, which suppresses use of the memo.
* Declare Protocol 2 as implemented.Guido van Rossum2003-01-291-1/+1
|
* Support for extension codes. (By accident I checked in the tests first.)Guido van Rossum2003-01-291-8/+63
|
* pickle: Comment repair.Tim Peters2003-01-291-4/+9
| | | | pickletools: Import decode_long from pickle instead of duplicating it.
* Add a comment about how some built-in types should grow aGuido van Rossum2003-01-281-1/+3
| | | | __getnewargs__ method.
* Get rid of __safe_for_unpickling__ and safe_constructors.Guido van Rossum2003-01-281-28/+12
| | | | Also tidied up a few lines, got rid of apply(), added a comment.
* Instead of bad hacks trying to worm around the inheritedGuido van Rossum2003-01-281-37/+79
| | | | | | | | | | | | | object.__reduce__, do a getattr() on the class so we can explicitly test for it. The reduce()-calling code becomes a bit more regular as a result. Also add support slots: if an object has slots, the default state is (dict, slots) where dict is the __dict__ or None, and slots is a dict mapping slot names to slot values. We do a best-effort approach to find slot names, assuming the __slots__ fields of classes aren't modified after class definition time to misrepresent the actual list of slots defined by a class.
* The default __reduce__ on the base object type obscured anyGuido van Rossum2003-01-281-7/+39
| | | | | | possibility of calling save_reduce(). Add a special hack for this. The tests for this are much simpler now (no __getstate__ or __getnewargs__ needed).
* Move the NEWOBJ-generating code to a separate function, and invoke itGuido van Rossum2003-01-281-24/+28
| | | | after checking for __reduce__.
* Some experimental support for generating NEWOBJ with proto=2, andGuido van Rossum2003-01-281-2/+31
| | | | fixed a bug in load_newobj().
* save_empty_tuple(): Comment on why we can't get rid of this.Tim Peters2003-01-281-0/+3
|