XMLRPCServer issues

L

looping

Hi,

I had some issues with XMLRPCServer and I try to validate my
workaround.

My first try was this (somewhat self explaining code):

from DocXMLRPCServer import DocXMLRPCServer
from cx_Oracle import connect

def get_task_list(user):
sql = """
select ISS.ISS_ISSUE_NUMBER
, ISS.ISS_DESCRIPTION
, ISS.C_PC_ISS_STATUS
, ISS.ISS_IN_WORK
, ISS.PC_ISSUES_ID
, DES.GCDTEXT1
from ...
where ...
"""
con = connect('DEVELOP/DEVELOP@DEV2003')
cur = con.cursor()
cur.execute(sql, USE_NAME = user.upper())
result = cur.fetchall()
cur.close()
con.close()
return result

server = DocXMLRPCServer(("localhost", 8000))
server.register_function(get_task_list)
server.serve_forever()


But I had 2 errors with this code:
-PC_ISSUES_ID column could be an integer of 12 digits but the XML
generator only allow 2L**31-1 long integer, so I had an
Overflowexception: long int exceeds XML-RPC.
-Text columns (like ISS_DESCRIPTION) could contains non ascii char.
(éàç) but the server doesn't allow to specify the encoding to use
for the XML, so parser error on non-ascii char. on the client side
(ExpatError: not well-formed (invalid token)).

My working code with workarounds for these issues is:

from DocXMLRPCServer import DocXMLRPCServer
from cx_Oracle import connect

#increase MAXINT constant to allow 12 digits integer for PC_ISSUES_ID
#(long int exceeds XML-RPC exception)
import xmlrpclib
xmlrpclib.MAXINT = 999999999999

def get_task_list(user):
sql = """
select ISS.ISS_ISSUE_NUMBER
, ISS.ISS_DESCRIPTION
, ISS.C_PC_ISS_STATUS
, ISS.ISS_IN_WORK
, ISS.PC_ISSUES_ID
, DES.GCDTEXT1
from ...
where ...
"""
con = connect('DEVELOP/DEVELOP@DEV2003')
cur = con.cursor()
cur.execute(sql, USE_NAME = user.upper())
result = cur.fetchall()
cur.close()
con.close()
#convert string column to unicode (XML generator does not use
# encoding so string must be UTF8 or unicode)
result = [list(row) for row in result]
for row in result:
for count, x in enumerate(row):
if isinstance(x, str):
row[count] = x.decode('cp1252')
return result

server = DocXMLRPCServer(("localhost", 8000))
server.register_function(get_task_list)
server.serve_forever()


But it seems to me not very clean, especially the MAXINT hack.
Has anyone a better solution ?
 
B

Brian Quinlan

1. Is there on option to get cx_Oracle to return string data as unicode
rather than strings objects? XML-RPC aside, dealing with unicode objects
might be better than dealing with encoded strings.

2. You might want to transmit integers as strings rather than use the
XML-RPC integer type (which is limited to numbers between -2147483648
and 2147483647).

Cheers,
Brian
 
L

looping

Brian said:
1. Is there on option to get cx_Oracle to return string data as unicode
rather than strings objects? XML-RPC aside, dealing with unicode objects
might be better than dealing with encoded strings.

I don't think cx_Oracle can return unicode string, so my code to
convert string is not so bad.
2. You might want to transmit integers as strings rather than use the
XML-RPC integer type (which is limited to numbers between -2147483648
and 2147483647).

Is it a limit of XML-RPC RFC or a limit (probably with a good reason)
of the python xmlrpclib ?

Thanks for your answer.
 
F

Fredrik Lundh

looping said:
Is it a limit of XML-RPC RFC or a limit (probably with a good reason)
of the python xmlrpclib ?

the specification defines an integer field as a "four-byte signed integer".

</F>
 
L

looping

Fredrik said:
the specification defines an integer field as a "four-byte signed integer".

</F>

OK, I will remove my MAXINT hack and convert value to string.

Thanks everybody for your fast answers, nice group with nice (and
brillant) people.
See you later for my next question.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,792
Messages
2,569,639
Members
45,353
Latest member
RogerDoger

Latest Threads

Top