473,403 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

xmlrpclib and binary data as normal parameter strings

Trying something like::
import xmlrpclib
svr = xmlrpclib.Server("http://127.0.0.1:8000")
svr.test("\x1btest")

Failes on the server with::
xml.parsers.expat.ExpatError: not well-formed (invalid token)

(Smaller test-case: xmlrpclib.loads(xmlrpclib.dumps(('\x1btest',))))

Shouldn't this be allowed?

From http://www.xmlrpc.com/spec ::
Any characters are allowed in a string except < and &, which are
encoded as &lt; and &amp;. A string can be used to encode binary
data.

From http://www.w3.org/TR/2004/REC-xml11-.../#dt-character ::
Consequently, XML processors MUST accept any character in the range
specified for Char
...
Char ::= [#x1-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]

(I'm aware that xmlrpclib.Binary can be used as an ugly work-around.)

--
Rune Frøysa
Jul 19 '05 #1
3 2751
Rune Froysa wrote:
From http://www.w3.org/TR/2004/REC-xml11-.../#dt-character ::

Consequently, XML processors MUST accept any character in the range
specified for Char
...
Char ::= [#x1-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]


you're looking at the XML 1.1 specification. don't do that. nobody uses 1.1.

here's the 1.0 version:

http://www.w3.org/TR/REC-xml/#dt-character

Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]

</F>

Jul 19 '05 #2

"Rune Froysa" <ru*********@usit.uio.no> wrote in message news:sv*************@dresden.uio.no...
From http://www.xmlrpc.com/spec ::
Any characters are allowed in a string except < and &, which are
encoded as &lt; and &amp;. A string can be used to encode binary
data.
the XMLRPC specification is worded pretty loosely. Obviously characters
forbidden in XML will be problematic.
From http://www.w3.org/TR/2004/REC-xml11-.../#dt-character ::


That's XML 1.1; it's very rarely used in practice. Can XMLRPC use XML 1.1?
In principle, undefined, as far as I know. In practice, not in Python anyway.
Jul 19 '05 #3
"Richard Brodie" <R.******@rl.ac.uk> writes:
"Rune Froysa" <ru*********@usit.uio.no> wrote in message news:sv*************@dresden.uio.no...
From http://www.xmlrpc.com/spec ::
Any characters are allowed in a string except < and &, which are
encoded as &lt; and &amp;. A string can be used to encode binary
data.


the XMLRPC specification is worded pretty loosely. Obviously characters
forbidden in XML will be problematic.


IMHO that is not obvious. The API-user wants to call a function on a
remote server with an arbitrary argument. What the transport-layer
does to achieve this should be completly transparent to the user.

We already have code that takes care of "&<>". Ideally we should do
that for other data as well. Unfortunately the XML-spec doesn't allow
us to use character references "&%#x1b;".

With the patch below, setting BINARY_AS_STRING=True will cause all
strings to be transparently base64-encoded during transport.
Unfortunately it will do this for all incoming binary data, thus
breaking aplications that explicitly uses the Binary class for this
purpose.

IMHO the xmlrpc spec should be updated to allow something like this.

--- /local/lib/python2.3/xmlrpclib.py 2005-01-10 10:30:43.000000000 +0100
+++ xmlrpclib.py 2005-04-20 09:56:11.000000000 +0200
@@ -177,6 +177,8 @@

__version__ = "1.0.1"

+BINARY_AS_STRING = False
+
# xmlrpc integer limits
MAXINT = 2L**31-1
MININT = -2L**31
@@ -652,6 +654,11 @@
dispatch[FloatType] = dump_double

def dump_string(self, value, write, escape=escape):
+ if BINARY_AS_STRING:
+ self.write = write
+ Binary(value).encode(self)
+ del self.write
+ return
write("<value><string>")
write(escape(value))
write("</string></value>\n")
@@ -843,7 +850,10 @@
def end_base64(self, data):
value = Binary()
value.decode(data)
- self.append(value)
+ if BINARY_AS_STRING:
+ self.append(value.data)
+ else:
+ self.append(value)
self._value = 0
dispatch["base64"] = end_base64

--
Rune Frøysa
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: herc777 | last post by:
I want to manipulate binary files. this was just a test to concatinate 2 text files but it said file_put_contents was undefined. the second parameter is suppoed to be 'mixed data', no idea what...
0
by: Larry | last post by:
I've had a production system running for a long time that uses xmlrpclib with timeoutsocket, and with my recent upgrade to 2.3 it's no longer able to use xmlrpclib with the xmlrpc servers I...
0
by: Alan Little | last post by:
I'm trying to write a generic weblog update notifier using xmlrpclib, starting with technorati. What I want to do is something like this : XML config file that would look like this: <server...
4
by: nightflyer | last post by:
Hi all, [code snippet appended at the end.) my question: A class has a few string variables with not know length at design time. Now I declare lets say a 1000 of those classes and put them...
7
by: John Dann | last post by:
I'm trying to read some binary data from a file created by another program. I know the binary file format but can't change or control the format. The binary data is organised such that it should...
2
by: Bastian Voigt | last post by:
Hallo List! I just found this old posting on google. Now my question is how can I read an integer value from the PGresult using the binary format? Can someone plz gimme a code example? (please...
5
by: Jonathan Ballet | last post by:
Hello, I have developped a XMLRPC server, which runs under Gnu/Linux with python2.3. This server receives method calls from Windows client. The server got some parameters which are string,...
0
by: Arno Stienen | last post by:
Perhaps I should be a bit more specific. When using this code to connect to a remote XML-RPC server (C++, xmlrpc++0.7 library): import xmlrpclib server =...
5
by: gezerpunta | last post by:
Hi strlen does not return the correct value .I compared the filesize() and strlen byte size but they are not equal. I must find binary string length and it must be equal to filesize() thks.
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.