@@ -116,11 +116,10 @@ def __createTextNode(self,data):
116116 The text is escaped to an fit the xml text format.
117117 '''
118118 if data is None :
119- return self .__doc .createTextNode (unicode ( "" , "utf-8" ) )
119+ return self .__doc .createTextNode ('' )
120120 else :
121- string = self .__formatString (data )
122- escaped_data = saxutils .escape (unicode (string ), ENTITIES )
123- return self .__doc .createTextNode (unicode (escaped_data , "utf-8" ))
121+ escaped_data = saxutils .escape (self .__formatString (data ), ENTITIES )
122+ return self .__doc .createTextNode (escaped_data )
124123
125124 def __createAttribute (self ,attrName ,attrValue ):
126125 '''
@@ -129,18 +128,24 @@ def __createAttribute(self,attrName,attrValue):
129128 '''
130129 attr = self .__doc .createAttribute (attrName )
131130 if attrValue is None :
132- attr .nodeValue = unicode ( "" , "utf-8" )
131+ attr .nodeValue = ''
133132 else :
134- attr .nodeValue = attrValue if isinstance (attrValue , unicode ) else unicode ( attrValue , "utf-8" )
133+ attr .nodeValue = self . __getUnicode (attrValue )
135134 return attr
136135
137136 def __formatString (self , string ):
138- string = unicode (string )
137+ string = self . __getUnicode (string )
139138 string = string .replace ("__NEWLINE__" , "\n " ).replace ("__TAB__" , "\t " )
140139 string = string .replace ("__START__" , "" ).replace ("__STOP__" , "" )
141140 string = string .replace ("__DEL__" , ", " )
142141 return string
143142
143+ def __getUnicode (self , value ):
144+ if isinstance (value , basestring ):
145+ return value if isinstance (value , unicode ) else unicode (value , "utf-8" )
146+ else :
147+ return unicode (value )
148+
144149 def string (self , header , data , sort = True ):
145150 '''
146151 Adds string element to the xml.
@@ -191,7 +196,7 @@ def lister(self, header, elements, sort=True):
191196 for e in element :
192197 memberElemStr = self .__doc .createElement (MEMBER_ELEM )
193198 memberElemStr .setAttributeNode (self .__createAttribute (TYPE_ATTR , "string" ))
194- memberElemStr .appendChild (self .__createTextNode (unicode (e )))
199+ memberElemStr .appendChild (self .__createTextNode (self . __getUnicode (e )))
195200 memberElem .appendChild (memberElemStr )
196201 listsElem = self .__getRootChild (LSTS_ELEM_NAME )
197202 if not (listsElem ):
@@ -245,7 +250,7 @@ def dba(self,isDBA):
245250 Adds information to the xml that indicates whether the user has DBA privileges
246251 '''
247252 isDBAElem = self .__doc .createElement (IS_DBA_ELEM_NAME )
248- isDBAElem .setAttributeNode (self .__createAttribute (VALUE_ATTR , unicode (isDBA )))
253+ isDBAElem .setAttributeNode (self .__createAttribute (VALUE_ATTR , self . __getUnicode (isDBA )))
249254 self .__addToRoot (isDBAElem )
250255
251256 def users (self ,users ):
@@ -497,7 +502,7 @@ def finish(self, resultStatus, resultMsg=""):
497502 '''
498503 if ((self .__outputFP is not None ) and not (self .__outputFP .closed )):
499504 statusElem = self .__doc .createElement (STATUS_ELEM_NAME )
500- statusElem .setAttributeNode (self .__createAttribute (SUCESS_ATTR ,unicode (resultStatus )))
505+ statusElem .setAttributeNode (self .__createAttribute (SUCESS_ATTR ,self . __getUnicode (resultStatus )))
501506
502507 if not (resultStatus ) :
503508 errorElem = self .__doc .createElement (ERROR_ELEM_NAME )
@@ -507,7 +512,7 @@ def finish(self, resultStatus, resultMsg=""):
507512 else :
508513 errorElem .setAttributeNode (self .__createAttribute (TYPE_ATTR , UNHANDLED_PROBLEM_TYPE ))
509514
510- errorElem .appendChild (self .__createTextNode (unicode (resultMsg )))
515+ errorElem .appendChild (self .__createTextNode (self . __getUnicode (resultMsg )))
511516 statusElem .appendChild (errorElem )
512517
513518 self .__addToRoot (statusElem )
0 commit comments