What Data is Available With a Pickled Object Over a Socket?

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Fri Oct 19 04:33:08 CEST 2007


En Thu, 18 Oct 2007 19:21:15 -0300, milan_sanremo  
<hancock.robert at gmail.com> escribió:

> I've read the library entry for pickle a couple of times, and I'm
> still not
> sure what data is maintained when an item is pickled and sent over a
> socket.

For most "normal" objects, all their instance attributes are stored.

> pickledMailbag = cPickle.dump(mb, HIGHEST_PROTOCOL)

Please copy&paste actual code when posting, don't retype it...
The above line should read cPickle.dumps, I presume.

> while 1:
>     pickledData = conn.recv(1024)
>     if not pickledData break

Instead of reinventing the wheel again, I'd try to use the existing server  
classes in the standard library, like SimpleHTTPServer by example. Among  
other things, you are not accumulating pickledData.

> mb = cPickle.load(pickledData)
>
> At this point, does mb contain a dictionary with the two envelopes
> with
> their data?

Asuming you managed to get pickledData right, and you use cPickle.loads:  
yes, mb should contain the same things as the original.

-- 
Gabriel Genellina




More information about the Python-list mailing list