[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
|
# 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.
|
# ref field according to the field that corresponds to this column.
|
||||||
pxSortIcons = Px('''
|
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}'% \
|
var2="ajaxBaseCall=navBaseCall.replace('**v**', '%s,%s,{%s:%s,%s:%s}'% \
|
||||||
(q(startNumber), q('sort'), q('sortKey'), q(refField.name), \
|
(q(startNumber), q('sort'), q('sortKey'), q(refField.name), \
|
||||||
q('reverse'), q('**v**')))">
|
q('reverse'), q('**v**')))">
|
||||||
|
|
|
@ -323,13 +323,18 @@ class XmlUnmarshaller(XmlParser):
|
||||||
self.conversionFunctions = conversionFunctions
|
self.conversionFunctions = conversionFunctions
|
||||||
self.utf8 = utf8
|
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):
|
def convertAttrs(self, attrs):
|
||||||
'''Converts XML attrs to a dict.'''
|
'''Converts XML attrs to a dict.'''
|
||||||
res = {}
|
res = {}
|
||||||
for k, v in attrs.items():
|
for k, v in attrs.items():
|
||||||
if ':' in k: # An attr prefixed with a namespace. Remove this.
|
if ':' in k: # An attr prefixed with a namespace. Remove this.
|
||||||
k = k.split(':')[-1]
|
k = k.split(':')[-1]
|
||||||
res[str(k)] = v
|
res[str(k)] = self.encode(v)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def startDocument(self):
|
def startDocument(self):
|
||||||
|
@ -366,9 +371,9 @@ class XmlUnmarshaller(XmlParser):
|
||||||
elif elemType == 'file':
|
elif elemType == 'file':
|
||||||
newObject = UnmarshalledFile()
|
newObject = UnmarshalledFile()
|
||||||
if attrs.has_key('name'):
|
if attrs.has_key('name'):
|
||||||
newObject.name = attrs['name']
|
newObject.name = self.encode(attrs['name'])
|
||||||
if attrs.has_key('mimeType'):
|
if attrs.has_key('mimeType'):
|
||||||
newObject.mimeType = attrs['mimeType']
|
newObject.mimeType = self.encode(attrs['mimeType'])
|
||||||
else: newObject = Object(**self.convertAttrs(attrs))
|
else: newObject = Object(**self.convertAttrs(attrs))
|
||||||
# Store the value on the last container, or on the root object.
|
# Store the value on the last container, or on the root object.
|
||||||
self.storeValue(elem, newObject)
|
self.storeValue(elem, newObject)
|
||||||
|
@ -430,8 +435,7 @@ class XmlUnmarshaller(XmlParser):
|
||||||
setattr(currentContainer, name, attrValue)
|
setattr(currentContainer, name, attrValue)
|
||||||
|
|
||||||
def characters(self, content):
|
def characters(self, content):
|
||||||
if not self.utf8:
|
content = self.encode(content)
|
||||||
content = content.encode('utf-8')
|
|
||||||
e = XmlParser.characters(self, content)
|
e = XmlParser.characters(self, content)
|
||||||
if e.currentBasicType:
|
if e.currentBasicType:
|
||||||
e.currentContent += content
|
e.currentContent += content
|
||||||
|
|
Loading…
Reference in a new issue