[shared] xml_parser::XmlUnmarshaller: bugfix: in non-utf8 mode.

This commit is contained in:
Gaetan Delannay 2014-10-03 19:56:34 +02:00
parent 441dc0b423
commit 1455a74056
2 changed files with 11 additions and 6 deletions

View file

@ -183,7 +183,8 @@ class Ref(Field):
# This PX displays, in a cell header from a ref table, icons for sorting the
# ref field according to the field that corresponds to this column.
pxSortIcons = Px('''
<x if="changeOrder and ztool.isSortable(refField.name,tiedClassName,'ref')"
<x if="changeOrder and (len(objects) &gt; 1) and \
ztool.isSortable(refField.name, tiedClassName, 'ref')"
var2="ajaxBaseCall=navBaseCall.replace('**v**', '%s,%s,{%s:%s,%s:%s}'% \
(q(startNumber), q('sort'), q('sortKey'), q(refField.name), \
q('reverse'), q('**v**')))">

View file

@ -323,13 +323,18 @@ class XmlUnmarshaller(XmlParser):
self.conversionFunctions = conversionFunctions
self.utf8 = utf8
def encode(self, value):
'''Depending on self.utf8 we may need to encode p_value.'''
if self.utf8: return value
return value.encode('utf-8')
def convertAttrs(self, attrs):
'''Converts XML attrs to a dict.'''
res = {}
for k, v in attrs.items():
if ':' in k: # An attr prefixed with a namespace. Remove this.
k = k.split(':')[-1]
res[str(k)] = v
res[str(k)] = self.encode(v)
return res
def startDocument(self):
@ -366,9 +371,9 @@ class XmlUnmarshaller(XmlParser):
elif elemType == 'file':
newObject = UnmarshalledFile()
if attrs.has_key('name'):
newObject.name = attrs['name']
newObject.name = self.encode(attrs['name'])
if attrs.has_key('mimeType'):
newObject.mimeType = attrs['mimeType']
newObject.mimeType = self.encode(attrs['mimeType'])
else: newObject = Object(**self.convertAttrs(attrs))
# Store the value on the last container, or on the root object.
self.storeValue(elem, newObject)
@ -430,8 +435,7 @@ class XmlUnmarshaller(XmlParser):
setattr(currentContainer, name, attrValue)
def characters(self, content):
if not self.utf8:
content = content.encode('utf-8')
content = self.encode(content)
e = XmlParser.characters(self, content)
if e.currentBasicType:
e.currentContent += content