TACTIC Open Source
Why not use json for remote xmlprc api? - Printable Version

+- TACTIC Open Source (http://forum.southpawtech.com)
+-- Forum: TACTIC Open Source (http://forum.southpawtech.com/forumdisplay.php?fid=3)
+--- Forum: TACTIC Discussion (http://forum.southpawtech.com/forumdisplay.php?fid=4)
+--- Thread: Why not use json for remote xmlprc api? (/showthread.php?tid=19)



Why not use json for remote xmlprc api? - listy - 10-27-2019

It would be better to use JSON instead unicode>ast. And a little more secure.
Plus it will be compatible between python3>python2.
TACTIC 4.7 default query() returns HEX instead of unicode strings for some reason.

For example:
Original string "Всякие дескрипшены."

Result from python3 tactic47 '\xd0\x92\xd1\x81\xd1\x8f\xd0\xba\xd0\xb8\xd0\xb5 \xd0\xb4\xd0\xb5\xd1\x81\xd0\xba\xd1\x80\xd0\xb8\xd0\xbf\xd1\x88\xd0\xb5\xd0\xbd\xd1\x8b.'
Don't know what to do with this result with python2 client

Result from python2 tactic45 '\u0412\u0441\u044f\u043a\u0438\u0435 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0448\u0435\u043d\u044b.'
print u"\u0412\u0441\u044f\u043a\u0438\u0435 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0448\u0435\u043d\u044b.".encode('utf-8')

So the default python eval() do not decode string from python3 tactic47

http://lucumr.pocoo.org/2014/1/5/unicode-in-2-and-3/ - good readings about python3 unicode


So this should be decoded as string:
str('\xd0\x92\xd1\x81\xd1\x8f\xd0\xba\xd0\xb8\xd0\xb5 \xd0\xb4\xd0\xb5\xd1\x81\xd0\xba\xd1\x80\xd0\xb8\xd0\xbf\xd1\x88\xd0\xb5\xd0\xbd\xd1\x8b.').decode('utf-8')

And this should be decoded as unicode:
print unicode(u'\u0412\u0441\u044f\u043a\u0438\u0435 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0448\u0435\u043d\u044b.').encode('utf-8').decode('utf-8')

If i have one solid vatiant, it would be better not guessing which string i get in another query


RE: Why not use json for remote xmlprc api? - listy - 10-28-2019

I am not complaining here about Unicode and etc, I just want to know it this is a bug, or special case.
On my side to keep backwards compatibility i had to do checking all the strings and guiss how to decode it. It is potentially slower and looks like a duckt tape


RE: Why not use json for remote xmlprc api? - remkonoteboom - 10-28-2019

Python3 eliminated a lot of issues with unicode and strings in general, so that is welcome so I think you are seeing a bug in the Python3 implementation. However, this code was written a long time ago ... a time when json was pretty new and the python version was very slow (was implemented in python) and we used unicode because it was simply a lot faster.

This is no longer true. Json actually is now a lot faster than str() and eval() so I think all of this should all eventually be implemented in JSON. It would be rather simple to convert this however there may be backwards compatibility issues.


RE: Why not use json for remote xmlprc api? - remkonoteboom - 10-28-2019

Exactly how are you using XMLRPC to return those values. If you use the TacticServerStub, it marshals the data for you and currently seems to work in both Python3 and Python2. Here is some sample code:

from tactic_client_lib import TacticServerStub

server = TacticServerStub(setup=False)
server.set_server("http://localhost")
server.set_project("my_project")
server.set_ticket("-9bd9ff3c0012de53f46")

sobjects = server.query("sthpw/file")
print("len: ", len(sobjects))


RE: Why not use json for remote xmlprc api? - listy - 10-29-2019

(10-28-2019, 02:20 PM)remkonoteboom Wrote: Exactly how are you using XMLRPC to return those values.  If you use the TacticServerStub, it marshals the data for you and currently seems to work in both Python3 and Python2.  Here is some sample code:

from tactic_client_lib import TacticServerStub

server = TacticServerStub(setup=False)
server.set_server("http://localhost")
server.set_project("my_project")
server.set_ticket("-9bd9ff3c0012de53f46")

sobjects = server.query("sthpw/file")
print("len: ", len(sobjects))
What i am trying to tell is that 4.5 tactic with python2 returns unicode strings. But tactic 4.7 python3 returns stings (hex). That means backwards compatibility for unicode is broken