irmen / Pyro5

Pyro 5 - Python remote objects
https://pyro5.readthedocs.io
MIT License
305 stars 36 forks source link

datetime not deserialized #27

Closed zbynekdrlik closed 4 years ago

zbynekdrlik commented 4 years ago

I have use serpent serializer. Datetime is correctly serialized on server side, but on client side it is string with iso datetime format. Is it possible to have it automatically deserialized?

irmen commented 4 years ago

https://pyro5.readthedocs.io/en/latest/clientcode.html#customizing-serialization

May I request to please first read the documentation before asking questions here.

zbynekdrlik commented 4 years ago

Dear @irmen, sorry for reopening. In this example https://github.com/irmen/Pyro5/blob/02fadeecbf4854ba1131d8a3cbec8f65e764ad99/examples/timezones/client.py i see that datetime object is fully serialized/deserialized by pyro5(serpent). In my case datetime on client side is not deserialized and it is normal string. "2021-01-29T15:07:01+01:00".

I use this to register deserializer but it doesn't work.

from django.utils.dateparse import parse_datetime
Pyro5.api.register_dict_to_class('datetime', parse_datetime)

Where is my misleading? Thanks.

irmen commented 4 years ago

Ah. Actually, that example is broken in Pyro5 which I failed to notice until now (!) You can see it for yourself by inspecting the first few lines that the client prints when you run it:

******* serpent *******

FIRST: no timezone
Got from server: 2020-08-16T17:45:43.427997
2020-08-16T17:45:43.427997
  '2020-08-16T17:45:43.427997' (<class 'str'>)

SECOND: PyTz timezones
Got from server: 2020-08-16T17:45:43.428652+02:00

THIRD: DateUtil timezones
Got from server: 2020-08-16T17:45:43.429062+02:00

FOURTH: Pendulum timezones
Got from server: 2020-08-16T17:45:43.429462+02:00

see that it only prints the iso date time strings? instead of having a real datetime object.

I'll rework the example.

As to your second question, you can't register any function, it has to support the specific arguments that Pyro uses for it. Study the custom-serialization example.