Re: Serpent serializer
Irmen de Jong <[email protected]> Thu, 06 Nov 2014 23:14:55 +0100
| Newsgroups | gmane.comp.python.pyro |
|---|---|
| Message-ID | <[email protected]> |
On 6-11-2014 22:30, Dick Kniep wrote:
> Hi List,
>
> I tried to pass an odt document as a field in Pyro using serpent. Now it seems that
> serpent encodes the zip which screws it up..... Any idea how I can solve this?
>
> Cheers, D. Kniep
Hello Dick!
What you see here is unfortunately a limitation of the serpent serializer. Its wire
protocol is text based so it has to encode any binary data. It uses base-64 to do that.
This means on the receiving side, instead of the raw bytes, you get a little dictionary
like this:
{'data': 'aXJtZW4gZGUgam9uZw==', 'encoding': 'base64'}
You must adapt your client code to handle this. To get your original binary data back
you simply base64-decode it, perhaps something like this:
import base64
document = proxy.getdocument()
if isinstance(document , dict):
# assume a serpent-style encoded response
assert document["encoding"]=="base64"
document = base64.b64decode(document["data"])
#...continue with document as if nothing happened...
There's not much else you can do about this, unless you switch to one of the less secure
serialization protocols that can deal with binary data directly (marshal and pickle).
Another way may be to add a custom class to hold your document and teach pyro/serpent
about how to serialize/deserialize that.
Also see http://pythonhosted.org/Pyro4/tipstricks.html#binary-data-transfer
(I suppose I could add a little note there about this specific serpent behavior...)
Regards
Irmen de Jong
------------------------------------------------------------------------------