Guido van Rossum 
								
							 
						 
						
							
							
							
							
								
							
							
								f7f4517fae 
								
							 
						 
						
							
							
								
								Pass the object to save_reduce(), so the memoize() call can go into  
							
							... 
							
							
							
							save_reduce(), before the state is pickled.  This makes it possible
for an object to be referenced from its own (mutable) state. 
							
						 
						
							2003-01-31 17:17:49 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Guido van Rossum 
								
							 
						 
						
							
							
							
							
								
							
							
								d053b4b416 
								
							 
						 
						
							
							
								
								Add a magical feature to save_reduce so that __reduce__ can cause  
							
							... 
							
							
							
							NEWOBJ to be generated. 
							
						 
						
							2003-01-31 16:51:45 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Tim Peters 
								
							 
						 
						
							
							
							
							
								
							
							
								4b23f2b44b 
								
							 
						 
						
							
							
								
								It's Official:  for LONG1/LONG4, a "byte count" of 0 is taken as a  
							
							... 
							
							
							
							shortcut meaning 0L.  This allows LONG1 to encode 0L in two bytes
total. 
							
						 
						
							2003-01-31 16:43:39 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Neal Norwitz 
								
							 
						 
						
							
							
							
							
								
							
							
								d17406830c 
								
							 
						 
						
							
							
								
								Fix typo  
							
							
							
						 
						
							2003-01-31 04:04:23 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Tim Peters 
								
							 
						 
						
							
							
							
							
								
							
							
								91149821d3 
								
							 
						 
						
							
							
								
								Linear-time implementations of {encode,decode}_long.  
							
							
							
						 
						
							2003-01-31 03:43:58 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Tim Peters 
								
							 
						 
						
							
							
							
							
								
							
							
								d01c1e91c4 
								
							 
						 
						
							
							
								
								load_inst(), load_obj():  Put the bulk of these into a common new  
							
							... 
							
							
							
							_instantiate() method. 
							
						 
						
							2003-01-30 15:41:46 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Guido van Rossum 
								
							 
						 
						
							
							
							
							
								
							
							
								9b40e804c7 
								
							 
						 
						
							
							
								
								There was a subtle big in save_newobj(): it used self.save_global(t)  
							
							... 
							
							
							
							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. :-( 
							
						 
						
							2003-01-30 06:37:41 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Guido van Rossum 
								
							 
						 
						
							
							
							
							
								
							
							
								4fba220f4a 
								
							 
						 
						
							
							
								
								Slight code rearrangement to avoid testing getstate twice.  
							
							
							
						 
						
							2003-01-30 05:41:19 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Guido van Rossum 
								
							 
						 
						
							
							
							
							
								
							
							
								45486176ea 
								
							 
						 
						
							
							
								
								In save_newobj(), if an object's __getnewargs__ and __getstate__ are  
							
							... 
							
							
							
							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.) 
							
						 
						
							2003-01-30 05:39:04 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Guido van Rossum 
								
							 
						 
						
							
							
							
							
								
							
							
								ba884f3d22 
								
							 
						 
						
							
							
								
								Use %c rather than chr() to turn some ints into chars.  
							
							
							
						 
						
							2003-01-29 20:14:23 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Guido van Rossum 
								
							 
						 
						
							
							
							
							
								
							
							
								5d9113d8be 
								
							 
						 
						
							
							
								
								Implement appropriate __getnewargs__ for all immutable subclassable builtin  
							
							... 
							
							
							
							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. 
							
						 
						
							2003-01-29 17:58:45 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Guido van Rossum 
								
							 
						 
						
							
							
							
							
								
							
							
								586c9e813c 
								
							 
						 
						
							
							
								
								Declare Protocol 2 as implemented.  
							
							
							
						 
						
							2003-01-29 06:16:12 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Guido van Rossum 
								
							 
						 
						
							
							
							
							
								
							
							
								255f3ee0a5 
								
							 
						 
						
							
							
								
								Support for extension codes.  (By accident I checked in the tests first.)  
							
							
							
						 
						
							2003-01-29 06:14:11 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Tim Peters 
								
							 
						 
						
							
							
							
							
								
							
							
								c0c12b5707 
								
							 
						 
						
							
							
								
								pickle:  Comment repair.  
							
							... 
							
							
							
							pickletools:  Import decode_long from pickle instead of duplicating it. 
							
						 
						
							2003-01-29 00:56:17 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Guido van Rossum 
								
							 
						 
						
							
							
							
							
								
							
							
								4e2491dbb1 
								
							 
						 
						
							
							
								
								Add a comment about how some built-in types should grow a  
							
							... 
							
							
							
							__getnewargs__ method. 
							
						 
						
							2003-01-28 22:31:25 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Guido van Rossum 
								
							 
						 
						
							
							
							
							
								
							
							
								b26a97aa50 
								
							 
						 
						
							
							
								
								Get rid of __safe_for_unpickling__ and safe_constructors.  
							
							... 
							
							
							
							Also tidied up a few lines, got rid of apply(), added a comment. 
							
						 
						
							2003-01-28 22:29:13 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Guido van Rossum 
								
							 
						 
						
							
							
							
							
								
							
							
								ac5b5d2e8b 
								
							 
						 
						
							
							
								
								Instead of bad hacks trying to worm around the inherited  
							
							... 
							
							
							
							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. 
							
						 
						
							2003-01-28 22:01:16 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Guido van Rossum 
								
							 
						 
						
							
							
							
							
								
							
							
								3d8c01b31c 
								
							 
						 
						
							
							
								
								The default __reduce__ on the base object type obscured any  
							
							... 
							
							
							
							possibility of calling save_reduce().  Add a special hack for this.
The tests for this are much simpler now (no __getstate__ or
__getnewargs__ needed). 
							
						 
						
							2003-01-28 19:48:18 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Guido van Rossum 
								
							 
						 
						
							
							
							
							
								
							
							
								54fb192508 
								
							 
						 
						
							
							
								
								Move the NEWOBJ-generating code to a separate function, and invoke it  
							
							... 
							
							
							
							after checking for __reduce__. 
							
						 
						
							2003-01-28 18:22:35 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Guido van Rossum 
								
							 
						 
						
							
							
							
							
								
							
							
								533dbcf250 
								
							 
						 
						
							
							
								
								Some experimental support for generating NEWOBJ with proto=2, and  
							
							... 
							
							
							
							fixed a bug in load_newobj(). 
							
						 
						
							2003-01-28 17:55:05 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Tim Peters 
								
							 
						 
						
							
							
							
							
								
							
							
								a6ae9a2128 
								
							 
						 
						
							
							
								
								save_empty_tuple():  Comment on why we can't get rid of this.  
							
							
							
						 
						
							2003-01-28 16:58:41 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Tim Peters 
								
							 
						 
						
							
							
							
							
								
							
							
								82ca59e002 
								
							 
						 
						
							
							
								
								save_dict():  Added a comment about the control flow NealN missed.  
							
							
							
						 
						
							2003-01-28 16:47:59 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Tim Peters 
								
							 
						 
						
							
							
							
							
								
							
							
								13a25fb8e6 
								
							 
						 
						
							
							
								
								_is_string_secure():  This method is no longer used; removed it.  (It  
							
							... 
							
							
							
							was used before string-escape codecs were added to the core.) 
							
						 
						
							2003-01-28 16:42:22 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Guido van Rossum 
								
							 
						 
						
							
							
							
							
								
							
							
								bc64e22ed6 
								
							 
						 
						
							
							
								
								Made save() fit on a page, while adding comments.  (I moved some type  
							
							... 
							
							
							
							checks to save_reduce(), which can also be called from a subclass.)
Also tweaked some more comments. 
							
						 
						
							2003-01-28 16:34:19 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Tim Peters 
								
							 
						 
						
							
							
							
							
								
							
							
								ad5a771fae 
								
							 
						 
						
							
							
								
								Got rid of the _quotes global.  Used only once, and is trivial.  
							
							
							
						 
						
							2003-01-28 16:23:33 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Guido van Rossum 
								
							 
						 
						
							
							
							
							
								
							
							
								1be3175992 
								
							 
						 
						
							
							
								
								Add a few comments.  Change the way the protocol is checked (it must  
							
							... 
							
							
							
							be one of 0, 1 or 2).
I should note that the previous checkin also added NEWOBJ support to
the unpickler -- but there's nothing yet that generates this. 
							
						 
						
							2003-01-28 15:19:53 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Guido van Rossum 
								
							 
						 
						
							
							
							
							
								
							
							
								3a41c61dd4 
								
							 
						 
						
							
							
								
								Rename all variables 'object' to 'obj' to avoid conflicts with the  
							
							... 
							
							
							
							type 'object'.  Also minor docstring tweakage, and rearranged a few
lines in save(). 
							
						 
						
							2003-01-28 15:10:22 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Guido van Rossum 
								
							 
						 
						
							
							
							
							
								
							
							
								cbe2dbddda 
								
							 
						 
						
							
							
								
								Don't memoize the empty tuple in protocol 0.  
							
							
							
						 
						
							2003-01-28 14:40:16 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Tim Peters 
								
							 
						 
						
							
							
							
							
								
							
							
								d97da80dd5 
								
							 
						 
						
							
							
								
								save_tuple():  So long as the charter is rewriting for clarity, the snaky  
							
							... 
							
							
							
							control flow had to be simplified. 
							
						 
						
							2003-01-28 05:48:29 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Tim Peters 
								
							 
						 
						
							
							
							
							
								
							
							
								ff57bff16e 
								
							 
						 
						
							
							
								
								save_tuple():  I believe the new code for TUPLE{1,2,3} in proto 2 was  
							
							... 
							
							
							
							incorrect for recursive tuples.  Tried to repair; seems to work OK, but
there are no checked-in tests for this yet. 
							
						 
						
							2003-01-28 05:34:53 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Guido van Rossum 
								
							 
						 
						
							
							
							
							
								
							
							
								7d97d31a1b 
								
							 
						 
						
							
							
								
								OK, this is really the last one tonight!  
							
							... 
							
							
							
							NEWFALSE and NEWTRUE. 
							
						 
						
							2003-01-28 04:25:27 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Guido van Rossum 
								
							 
						 
						
							
							
							
							
								
							
							
								44f0ea5f73 
								
							 
						 
						
							
							
								
								More protocol 2: TUPLE1, TUPLE2, TUPLE3.  
							
							... 
							
							
							
							Also moved the special case for empty tuples from save() to save_tuple(). 
							
						 
						
							2003-01-28 04:14:51 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Tim Peters 
								
							 
						 
						
							
							
							
							
								
							
							
								3b769835ca 
								
							 
						 
						
							
							
								
								save_inst():  Rewrote to have only one branch on self.bin.  Also got rid  
							
							... 
							
							
							
							of my recent XXX comment, taking a (what appears to be vanishingly small)
chance and calling self.memoize() instead. 
							
						 
						
							2003-01-28 03:51:36 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Guido van Rossum 
								
							 
						 
						
							
							
							
							
								
							
							
								d6c9e63af9 
								
							 
						 
						
							
							
								
								First baby steps towards implementing protocol 2: PROTO, LONG1 and LONG4.  
							
							
							
						 
						
							2003-01-28 03:49:52 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Tim Peters 
								
							 
						 
						
							
							
							
							
								
							
							
								d95c2df3a9 
								
							 
						 
						
							
							
								
								Fixed odd whitespace after "if", which I believe I introduced long ago.  
							
							
							
						 
						
							2003-01-28 03:41:54 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Tim Peters 
								
							 
						 
						
							
							
							
							
								
							
							
								8fda7bc48d 
								
							 
						 
						
							
							
								
								save_int():  Fixed two new off-by-1 glitches.  
							
							
							
						 
						
							2003-01-28 03:40:52 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Guido van Rossum 
								
							 
						 
						
							
							
							
							
								
							
							
								e0b904232f 
								
							 
						 
						
							
							
								
								Add a comment explaining that struct.pack() beats marshal.dumps(), but  
							
							... 
							
							
							
							marshal.loads() beats struct.unpack()!  Possibly because the latter
creates a one-tuple. :-( 
							
						 
						
							2003-01-28 03:17:21 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Guido van Rossum 
								
							 
						 
						
							
							
							
							
								
							
							
								5c938d00a1 
								
							 
						 
						
							
							
								
								Got rid of mdumps; I timed it, and struct.pack("<i", x) is more than  
							
							... 
							
							
							
							40% faster than marshal.dumps(x)[1:]!  (That's not counting the
module attribute lookups, which can be avoided in either case.) 
							
						 
						
							2003-01-28 03:03:08 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Tim Peters 
								
							 
						 
						
							
							
							
							
								
							
							
								f558da0f90 
								
							 
						 
						
							
							
								
								save_tuple():  Minor rewriting, and added a comment about the subtlety  
							
							... 
							
							
							
							created by recursive tuples. 
							
						 
						
							2003-01-28 02:09:55 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Tim Peters 
								
							 
						 
						
							
							
							
							
								
							
							
								209ad95b00 
								
							 
						 
						
							
							
								
								load_appends():  replaced .append() loop with an .extend().  
							
							
							
						 
						
							2003-01-28 01:44:45 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Tim Peters 
								
							 
						 
						
							
							
							
							
								
							
							
								c23d18a955 
								
							 
						 
						
							
							
								
								Comments.  
							
							
							
						 
						
							2003-01-28 01:41:51 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Tim Peters 
								
							 
						 
						
							
							
							
							
								
							
							
								064567e41a 
								
							 
						 
						
							
							
								
								save_dict():  Untangled most of the bin-vs-not-bin logic.  Also used  
							
							... 
							
							
							
							iteritems() instead of materializing a (possibly giant) list of the
items. 
							
						 
						
							2003-01-28 01:34:43 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Tim Peters 
								
							 
						 
						
							
							
							
							
								
							
							
								21c18f0bf5 
								
							 
						 
						
							
							
								
								save_list():  Rewrote, to untangle the proto 0 from the proto 1 cases.  
							
							... 
							
							
							
							The code is much easier to follow now, and I bet it's faster too. 
							
						 
						
							2003-01-28 01:15:46 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Tim Peters 
								
							 
						 
						
							
							
							
							
								
							
							
								22dc6f4f7a 
								
							 
						 
						
							
							
								
								save_list():  removed unused local "d".  
							
							
							
						 
						
							2003-01-28 01:07:48 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Tim Peters 
								
							 
						 
						
							
							
							
							
								
							
							
								58d7846e68 
								
							 
						 
						
							
							
								
								save_list():  removed unused local "memo".  
							
							
							
						 
						
							2003-01-28 01:07:10 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Tim Peters 
								
							 
						 
						
							
							
							
							
								
							
							
								bd1cdb9227 
								
							 
						 
						
							
							
								
								save_pers():  Switched the order of cases, to get rid of a "not", and to  
							
							... 
							
							
							
							make the bin-vs-not-bin order consistent with what other routines try to
do (they almost all handle the bin case first). 
							
						 
						
							2003-01-28 01:03:10 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Tim Peters 
								
							 
						 
						
							
							
							
							
								
							
							
								518df0dae4 
								
							 
						 
						
							
							
								
								Several routines appeared to inline the guts of memoize(), possibly for  
							
							... 
							
							
							
							some notion of low-level efficiency.  Undid that, but left one routine
alone:  save_inst() claims it has a reason for not using memoize().
I don't understand that comment, so added an XXX comment there. 
							
						 
						
							2003-01-28 01:00:38 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Tim Peters 
								
							 
						 
						
							
							
							
							
								
							
							
								b32a8317d7 
								
							 
						 
						
							
							
								
								save():  Fiddled the control flow to put the normal case where it  
							
							... 
							
							
							
							belongs.  This is a much smaller change than it may appear:  the bulk
of the function merely got unindented by one level. 
							
						 
						
							2003-01-28 00:48:09 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Tim Peters 
								
							 
						 
						
							
							
							
							
								
							
							
								c9d7c4a656 
								
							 
						 
						
							
							
								
								Added XXX about save()'s special-casing of tuples -- I don't get it.  
							
							
							
						 
						
							2003-01-28 00:43:26 +00:00 
							
								 
							
							
								 
							
						 
					 
				
					
						
							
								
								
									Tim Peters 
								
							 
						 
						
							
							
							
							
								
							
							
								22987e3cbd 
								
							 
						 
						
							
							
								
								save_bool():  simplified.  
							
							
							
						 
						
							2003-01-28 00:26:14 +00:00