Re: Pyro 4.20 serpent serializer issues
"Vernon D. Cole" <[email protected]>
| Newsgroups | gmane.comp.python.pyro |
|---|---|
| Message-ID | <CAH-ZgAfXdaB1987e0M=HLeWhf7S78mG_r2MBdJSzxoC1KUGudw@mail.gmail.com> |
List Readers: You can switch serializers by setting the environment variable Linux: export PYRO_SERIALIZER=pickle Windows: set PYRO_SERIALIZER=pickle Irmen: The documentation page at http://pythonhosted.org/Pyro4/api/config.htmlrefers back to itself. I think that you intended for it to refer to: http://pythonhosted.org/Pyro4/config.html#overview-of-config-items which is where I (finally) found the answer I needed. May I suggest putting information on _how_ to change serializers earlier in the documentation? It took me an age to find out how to switch back to pickle. (My code already has a work-around for a pickle idiosyncrasy, and I suspect that I will have to vastly expand that to handle decimal and datetime instances (if I even can) to support serpent. I am doing SQL database I/O, and do not know in advance what type of data my user might throw at me. -- Vernon On Tue, Jun 11, 2013 at 8:25 PM, Irmen de Jong <[email protected]> wrote: > On 11-6-2013 15:01, Éric Piel wrote: > > On 09/06/13 01:38, Irmen de Jong wrote: > > : > >> Decimals are encoded as a literal string (because otherwise you will > lose precision). > >> The receiver however needs to 'know' this and will have to convert the > string back to a > >> decimal.Decimal. Similarly, datetime.datetime are encoded as a ISO > formatted date+time > >> string, and the receiver will have to convert it back explicitly (if > desired). > > : > >> The key issue here is that when not using pickle, you probably will > have to redesign > >> your remote method contracts if they depend a lot on custom types on > both ends. If you > >> stick to Python literals mainly, the pain will be a lot less or even > non-existent... > > > > Hi Irmen, > > Just to be sure I understand correctly, does this mean that in Pyro 4.20 > > (with the default serializer), a method returning a decimal.Decimal will > > return a string when called remotely via Pyro? > > Yep, that's right. > The string form makes sure no precision is lost. You can convert it back > to a Decimal if > you need (but yeah, that will have to be an explicit step in your code). > > The new serializer (serpent), and the json one even more so, trade > expressive power for > security (and human readability, if that matters). You gain some, you > loose some. > > You can check it out by enabling LOGWIRE and then looking in the log to > see what Pyro > puts on the wire. Or if you're interested in serpent specifically, you can > check it out > directly by playing with serpent.dumps(). > > If you don't like the way serpent serializes certain types, you can > register your own > custom hooks (Pyro already does this, for a few types). Example: > > >>> import serpent > >>> def serialize_decimal(obj, serializer, stream, indent): > ... serializer._serialize("decimal.Decimal('%s')" % obj, stream, indent) > ... > >>> serpent.register_class(decimal.Decimal, serialize_decimal) > >>> print serpent.dumps(decimal.Decimal("1234.56789")) > # serpent utf-8 python3.2 > "decimal.Decimal('1234.56789')" > >>> > > Ofcourse, this specific example can no longer be deserialized by serpent > itself: the > serialized data is no longer a python literal expression. > > For security reasons (again), Pyro only converts a limited set of well > known types back > into actual objects of that type. It is not possible (yet?) to extend that > mechanism. > (This doesn't apply to pickle) > > If you find that you loose to much expressive power by using serpent or > one of the other > serializers, you can always switch back to pickle. But you'll then have to > deal with its > security problems. > > Cheers > Irmen > > > > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by Windows: > > Build for Windows Store. > > http://p.sf.net/sfu/windows-dev2dev > _______________________________________________ > Pyro-core mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/pyro-core > ------------------------------------------------------------------------------ This SF.net email is sponsored by Windows: Build for Windows Store. http://p.sf.net/sfu/windows-dev2dev _______________________________________________ Pyro-core mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/pyro-core