Define the type data as required for the commit #29134

Change the XML conversion to handle it


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@29135 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 251cc6e2
...@@ -174,13 +174,19 @@ type_definition = { ...@@ -174,13 +174,19 @@ type_definition = {
'default' : None, 'default' : None,
'isList' : 0, 'isList' : 0,
}, },
# Object are properties of any type (ex. data) # Object are properties of any type
# and are considered as simple properties # and are considered as simple properties
'object' : { 'cast' : identity, 'object' : { 'cast' : identity,
'null' : ('', 'None', None,), 'null' : ('', 'None', None,),
'default' : None, 'default' : None,
'isList' : 0, 'isList' : 0,
}, },
# Used for converted documents (ex: data)
'data' : { 'cast' : identity,
'null' : ('', 'None', None,),
'default' : None,
'isList' : 0,
},
'tales' : { 'cast' : identity, 'tales' : { 'cast' : identity,
'null' : ('', 'None', None,), 'null' : ('', 'None', None,),
'default' : None, 'default' : None,
......
...@@ -36,7 +36,9 @@ from xml.sax.saxutils import escape, unescape ...@@ -36,7 +36,9 @@ from xml.sax.saxutils import escape, unescape
from lxml import etree from lxml import etree
from lxml.etree import Element, SubElement from lxml.etree import Element, SubElement
from xml.marshal.generic import dumps as marshaler from xml.marshal.generic import dumps as marshaler
from OFS.Image import Pdata
from zLOG import LOG from zLOG import LOG
from base64 import standard_b64encode
class OrderedPickler(Pickler): class OrderedPickler(Pickler):
...@@ -92,12 +94,40 @@ def Base_asXML(object, root=None): ...@@ -92,12 +94,40 @@ def Base_asXML(object, root=None):
# We may have very long lines, so we should split # We may have very long lines, so we should split
value = aq_base(value) value = aq_base(value)
value = dumps(value) value = dumps(value)
msg = MIMEBase('application', 'octet-stream') sub_object.text = standard_b64encode(value)
msg.set_payload(value) elif prop_type in ('data',):
Encoders.encode_base64(msg) # Create blocks to represent data
ascii_data = msg.get_payload() # <data><block>ZERD</block><block>OEJJM</block></data>
sub_object.text = ascii_data if isinstance(value, str):
sub_object.set('type_data','str')
size_block = 80
iterator_block = 0
data_encoded = standard_b64encode(value)
for index in xrange(0, len(data_encoded), 80):
content = data_encoded[index:index + size_block]
block = SubElement(sub_object, 'block_data', num=str(iterator_block))
block.text = content
iterator_block += 1
elif isinstance(value, Pdata):
# Create blocks if there is a stack of data
sub_object.set('type_data','Pdata')
size_block = 80
data = value
iterator_block = 0
while data is not None:
data_encoded = standard_b64encode(data.data)
for index in xrange(0, len(data_encoded), 80):
content = data_encoded[index:index + size_block]
block = SubElement(sub_object, 'block_data', num=str(iterator_block))
block.text = content
iterator_block += 1
data = data.next
else:
raise "XMLExportImport failed, the data is undefined"
elif prop_type in ('lines', 'tokens',): elif prop_type in ('lines', 'tokens',):
# Use CDATA node to not be taken into account by erp5diff
value = [word.decode('utf-8').encode('ascii','xmlcharrefreplace')\
for word in value]
sub_object.text = etree.CDATA(marshaler(value)) sub_object.text = etree.CDATA(marshaler(value))
elif prop_type in ('text', 'string',): elif prop_type in ('text', 'string',):
sub_object.text = unicode(escape(value), 'utf-8') sub_object.text = unicode(escape(value), 'utf-8')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment