[Assorted-commits] SF.net SVN: assorted: [190] python-afx/trunk/src/afx/pubsub.py
Brought to you by:
yangzhang
|
From: <yan...@us...> - 2007-12-22 10:07:32
|
Revision: 190
http://assorted.svn.sourceforge.net/assorted/?rev=190&view=rev
Author: yangzhang
Date: 2007-12-22 02:07:32 -0800 (Sat, 22 Dec 2007)
Log Message:
-----------
added safe_pickle, write_pickle
Modified Paths:
--------------
python-afx/trunk/src/afx/pubsub.py
Modified: python-afx/trunk/src/afx/pubsub.py
===================================================================
--- python-afx/trunk/src/afx/pubsub.py 2007-12-06 19:19:25 UTC (rev 189)
+++ python-afx/trunk/src/afx/pubsub.py 2007-12-22 10:07:32 UTC (rev 190)
@@ -7,8 +7,8 @@
from contextlib import closing
from cStringIO import StringIO
from itertools import chain
-from struct import unpack
-from cPickle import load
+from struct import pack, unpack
+from cPickle import dumps, load
from commons.seqs import streamlen
import af
@@ -261,6 +261,14 @@
# yield any( tag( task, index ) for index, task in enumerate( tasks ) )
@af.task
+def write_pickle( socket, obj ):
+ yield socket.write( safe_pickle( obj ) )
+
+def safe_pickle( obj ):
+ msg = dumps(obj)
+ return pack('i4',len(msg)) + msg
+
+@af.task
def read_pickle( socket, init = '' ):
with closing( StringIO() ) as stream:
failed = False
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|