[Assorted-commits] SF.net SVN: assorted: [236] python-commons/trunk/src/commons/seqs.py
Brought to you by:
yangzhang
|
From: <yan...@us...> - 2008-01-18 06:55:04
|
Revision: 236
http://assorted.svn.sourceforge.net/assorted/?rev=236&view=rev
Author: yangzhang
Date: 2008-01-17 22:55:09 -0800 (Thu, 17 Jan 2008)
Log Message:
-----------
added read_pickles, touched up doc
Modified Paths:
--------------
python-commons/trunk/src/commons/seqs.py
Modified: python-commons/trunk/src/commons/seqs.py
===================================================================
--- python-commons/trunk/src/commons/seqs.py 2008-01-17 23:57:23 UTC (rev 235)
+++ python-commons/trunk/src/commons/seqs.py 2008-01-18 06:55:09 UTC (rev 236)
@@ -27,6 +27,11 @@
@param read: The reader function that reads from a stream. It should take
a single argument, the number of bytes to consume.
@type read: function
+
+ @return: A tuple whose first element is the deserialized object or None if
+ EOF was encountered, and whose second element is the remainder bytes until
+ the EOF that were not consumed by unpickling.
+ @rtype: (object, str)
"""
with closing( StringIO() ) as stream:
obj = None # return this if we hit eof (not enough bytes read)
@@ -49,6 +54,16 @@
return ( obj, stream.read() )
+def read_pickles( read ):
+ """
+ Reads all the consecutively pickled objects from the L{read} function.
+ """
+ while True:
+ pair = ( obj, rem ) = read_pickle( read )
+ if obj is None:
+ break
+ yield pair
+
def safe_pickle( obj ):
"""
Pickle L{obj} but prepends the serialized length in bytes.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|