Marshaling unicode WDDX

I

isthar

Hi !
i am trying to serialise object which contains some unicode objects
but looks like there is no way to do it.

File
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/
_xmlplus/marshal/generic.py", line 92, in _marshal
return getattr(self, meth)(value, dict)
AttributeError: WDDXMarshaller instance has no attribute 'm_unicode'

WDDX is perfect for me for exchange between python and php application.
but maybe there is a better way to do it.


Any clue?

Thanks in advance.
 
T

Tim Arnold

isthar said:
Hi !
i am trying to serialise object which contains some unicode objects
but looks like there is no way to do it.

hi, I'm sure you'll get better answers for the unicode part of your problem
(I'd start with a look at the codecs module), but I wanted you to know that
I'm using the wddx connection between Python and PHP with no problem. Here's
the python code that writes a fairly complex data structure to the wddx
file:

def writeDocReport(self):
from xml.marshal import wddx
fileName = '%s/%s.doc.wddx' % (os.path.join(adsWeb,'jobs','wddx'),
self.name)
tmpFile = open(fileName,'wb')
tmpFile.write(wddx.dumps(self.getDocData()))
tmpFile.close()

and the PHP:

function getInputData($){
$file = "wddx/$prodName.wddx";

if (!is_file($file)) {
exit("<h1>Report is not available for $prodName</h1>");
}

$output = wddx_deserialize(file_get_contents($file));
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

isthar said:
WDDX is perfect for me for exchange between python and php application.
but maybe there is a better way to do it.

It appears that Unicode objects where forgotten in the WDDX
implementation. I suggest to define the following classes:

class UWDDXMarshaller(xml.marshal.wddx.WDDXMarshaller):
def m_unicode(self, data, dict):
return self.m_string(data.encode("utf-8"), dict)

class UWDDXUnmarshaller(xml.marshal.wddx.WDDXUnmarshaller):
def um_end_string(self, name):
ds = self.data_stack
ds[-1] = u"".join(ds[-1])
self.accumulating_chars = 0

The m_unicode part should get integrated into PyXML;
the um_end_string should probably return ASCII strings
if possible, else Unicode strings.

Regards,
Martin
 
I

isthar

Ok. but how I suppose to use them. I am currently using marshaller
indirectly via wddx.dump().

Anyway, thanks :)
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

isthar said:
Ok. but how I suppose to use them. I am currently using marshaller
indirectly via wddx.dump().

Do UWDDXMarshaller().dump()

Regards,
Martin
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top