[shared] xml_parser::XmlUnmarshaller: bugfix: in non-utf8 mode.
This commit is contained in:
parent
441dc0b423
commit
1455a74056
2 changed files with 11 additions and 6 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue