fixing unicode mess

This commit is contained in:
Miroslav Stampar 2010-06-02 08:28:38 +00:00
parent 4d6d5c8447
commit 32a0ba9296

View File

@ -116,11 +116,10 @@ class XMLDump:
The text is escaped to an fit the xml text format.
'''
if data is None :
return self.__doc.createTextNode(unicode("","utf-8"))
return self.__doc.createTextNode('')
else :
string = self.__formatString(data)
escaped_data = saxutils.escape(unicode(string), ENTITIES)
return self.__doc.createTextNode(unicode(escaped_data, "utf-8"))
escaped_data = saxutils.escape(self.__formatString(data), ENTITIES)
return self.__doc.createTextNode(escaped_data)
def __createAttribute(self,attrName,attrValue):
'''
@ -129,18 +128,24 @@ class XMLDump:
'''
attr = self.__doc.createAttribute(attrName)
if attrValue is None :
attr.nodeValue = unicode("","utf-8")
attr.nodeValue = ''
else :
attr.nodeValue = attrValue if isinstance(attrValue, unicode) else unicode(attrValue,"utf-8")
attr.nodeValue = self.__getUnicode(attrValue)
return attr
def __formatString(self, string):
string = unicode(string)
string = self.__getUnicode(string)
string = string.replace("__NEWLINE__", "\n").replace("__TAB__", "\t")
string = string.replace("__START__", "").replace("__STOP__", "")
string = string.replace("__DEL__", ", ")
return string
def __getUnicode(self, value):
if isinstance(value, basestring):
return value if isinstance(value, unicode) else unicode(value, "utf-8")
else:
return unicode(value)
def string(self, header, data, sort=True):
'''
Adds string element to the xml.
@ -191,7 +196,7 @@ class XMLDump:
for e in element :
memberElemStr = self.__doc.createElement(MEMBER_ELEM)
memberElemStr.setAttributeNode(self.__createAttribute(TYPE_ATTR, "string"))
memberElemStr.appendChild(self.__createTextNode(unicode(e)))
memberElemStr.appendChild(self.__createTextNode(self.__getUnicode(e)))
memberElem.appendChild(memberElemStr)
listsElem = self.__getRootChild(LSTS_ELEM_NAME)
if not(listsElem):
@ -245,7 +250,7 @@ class XMLDump:
Adds information to the xml that indicates whether the user has DBA privileges
'''
isDBAElem = self.__doc.createElement(IS_DBA_ELEM_NAME)
isDBAElem.setAttributeNode(self.__createAttribute(VALUE_ATTR, unicode(isDBA)))
isDBAElem.setAttributeNode(self.__createAttribute(VALUE_ATTR, self.__getUnicode(isDBA)))
self.__addToRoot(isDBAElem)
def users(self,users):
@ -497,7 +502,7 @@ class XMLDump:
'''
if ((self.__outputFP is not None) and not(self.__outputFP.closed)):
statusElem = self.__doc.createElement(STATUS_ELEM_NAME)
statusElem.setAttributeNode(self.__createAttribute(SUCESS_ATTR,unicode(resultStatus)))
statusElem.setAttributeNode(self.__createAttribute(SUCESS_ATTR,self.__getUnicode(resultStatus)))
if not(resultStatus) :
errorElem = self.__doc.createElement(ERROR_ELEM_NAME)
@ -507,7 +512,7 @@ class XMLDump:
else :
errorElem.setAttributeNode(self.__createAttribute(TYPE_ATTR, UNHANDLED_PROBLEM_TYPE))
errorElem.appendChild(self.__createTextNode(unicode(resultMsg)))
errorElem.appendChild(self.__createTextNode(self.__getUnicode(resultMsg)))
statusElem.appendChild(errorElem)
self.__addToRoot(statusElem)