[Python-checkins] python/nondist/sandbox/pickletools pickletools.py,1.26,1.27

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
Sun, 26 Jan 2003 16:44:44 -0800


Update of /cvsroot/python/python/nondist/sandbox/pickletools
In directory sc8-pr-cvs1:/tmp/cvs-serv20938

Modified Files:
	pickletools.py 
Log Message:
Heh -- 5 stinking opcodes to go, and I finally hit oue that actually has
two arguments.  Added GLOBAL and hacked around that.


Index: pickletools.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/pickletools/pickletools.py,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -d -r1.26 -r1.27
*** pickletools.py	27 Jan 2003 00:19:50 -0000	1.26
--- pickletools.py	27 Jan 2003 00:44:40 -0000	1.27
***************
*** 286,289 ****
--- 286,314 ----
                          """)
  
+ def read_stringnl_noescape_pair(f):
+     """
+     >>> import StringIO
+     >>> read_stringnl_noescape_pair(StringIO.StringIO("Queue\\nEmpty\\njunk"))
+     'Queue.Empty'
+     """
+ 
+     return "%s %s" % (read_stringnl_noescape(f), read_stringnl_noescape(f))
+ 
+ stringnl_noescape_pair = ArgumentDescriptor(
+                              name='stringnl_noescape_pair',
+                              n=UP_TO_NEWLINE,
+                              reader=read_stringnl_noescape_pair,
+                              doc="""A pair of newline-terminated strings.
+ 
+                              These are str-style strings, without embedded
+                              escapes, or bracketing quotes.  They should
+                              consist solely of printable ASCII characters.
+                              The pair is returned as a single string, with
+                              a single '.' separating the two strings.
+                              """)
+ 
+ def read_stringnl_noescape_pair(f):
+     return read_stringnl_noescape(f), read_stringnl_noescape(f)
+ 
  def read_string4(f):
      """
***************
*** 1188,1191 ****
--- 1213,1233 ----
        """),
  
+     # Global names (class names).
+ 
+     I(name='GLOBAL',
+       code='c',
+       arg=stringnl_noescape_pair,
+       stack_before=[],
+       stack_after=[anyobject],
+       proto=0,
+       doc="""Push a global object on the stack.
+ 
+       Two newline-terminated strings follow the GLOBAL opcode.  The first is
+       taken as a module name, and the second as a class name.  The class
+       object module.class is pushed on the stack.  More accurately, the
+       object returned by self.find_class(module, class) is pushed on the
+       stack, so unpickling subclasses can override this form of lookup.
+       """),
+ 
      # Machine control.
  
***************
*** 1260,1274 ****
        """),
  
-     I(name='GLOBAL',
-       code='c',
-       arg=None,
-       stack_before=[],
-       stack_after=[],
-       proto=0,
-       doc="""XXX One-line description goes here.
- 
-       XXX Doc body goes here.
-       """),
- 
      I(name='INST',
        code='i',
--- 1302,1305 ----
***************
*** 1427,1431 ****
      """Produce a symbolic disassembly of a pickle.
  
!     'pickle' is file-like object, or string, containing a (at least one)
      pickle.  The pickle is disassembled from the current position, through
      the first STOP opcode encountered.
--- 1458,1462 ----
      """Produce a symbolic disassembly of a pickle.
  
!     'pickle' is a file-like object, or string, containing a (at least one)
      pickle.  The pickle is disassembled from the current position, through
      the first STOP opcode encountered.