[shared] xml_parser::XmlUnmarshaller: bugfix: in non-utf8 mode.
This commit is contained in:
parent
441dc0b423
commit
1455a74056
|
@ -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) > 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**')))">
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue