@@ -93,7 +93,7 @@ def optional_warn_function(*args, **kwargs):
9393 # Preserve the original name to avoid masking all decorated functions as
9494 # 'deprecated_function'
9595 try :
96- optional_warn_function .func_name = f .func_name
96+ optional_warn_function .__name__ = f .__name__
9797 except TypeError :
9898 pass # In Python2.3 we can't set the func_name
9999 return optional_warn_function
@@ -121,7 +121,7 @@ def CreateClassFromXMLString(target_class, xml_string, string_encoding=None):
121121 match those of the target class.
122122 """
123123 encoding = string_encoding or XML_STRING_ENCODING
124- if encoding and isinstance (xml_string , unicode ):
124+ if encoding and isinstance (xml_string , str ):
125125 xml_string = xml_string .encode (encoding )
126126 tree = ElementTree .fromstring (xml_string )
127127 return _CreateClassFromElementTree (target_class , tree )
@@ -183,11 +183,11 @@ def _HarvestElementTree(self, tree):
183183 # Fill in the instance members from the contents of the XML tree.
184184 for child in tree :
185185 self ._ConvertElementTreeToMember (child )
186- for attribute , value in tree .attrib .iteritems ():
186+ for attribute , value in tree .attrib .items ():
187187 self ._ConvertElementAttributeToMember (attribute , value )
188188 # Encode the text string according to the desired encoding type. (UTF-8)
189189 if tree .text :
190- if MEMBER_STRING_ENCODING is unicode :
190+ if MEMBER_STRING_ENCODING is str :
191191 self .text = tree .text
192192 else :
193193 self .text = tree .text .encode (MEMBER_STRING_ENCODING )
@@ -199,7 +199,7 @@ def _ConvertElementTreeToMember(self, child_tree, current_class=None):
199199 def _ConvertElementAttributeToMember (self , attribute , value ):
200200 # Encode the attribute value's string with the desired type Default UTF-8
201201 if value :
202- if MEMBER_STRING_ENCODING is unicode :
202+ if MEMBER_STRING_ENCODING is str :
203203 self .extension_attributes [attribute ] = value
204204 else :
205205 self .extension_attributes [attribute ] = value .encode (
@@ -209,15 +209,15 @@ def _ConvertElementAttributeToMember(self, attribute, value):
209209 def _AddMembersToElementTree (self , tree ):
210210 for child in self .extension_elements :
211211 child ._BecomeChildElement (tree )
212- for attribute , value in self .extension_attributes .iteritems ():
212+ for attribute , value in self .extension_attributes .items ():
213213 if value :
214- if isinstance (value , unicode ) or MEMBER_STRING_ENCODING is unicode :
214+ if isinstance (value , str ) or MEMBER_STRING_ENCODING is str :
215215 tree .attrib [attribute ] = value
216216 else :
217217 # Decode the value from the desired encoding (default UTF-8).
218218 tree .attrib [attribute ] = value .decode (MEMBER_STRING_ENCODING )
219219 if self .text :
220- if isinstance (self .text , unicode ) or MEMBER_STRING_ENCODING is unicode :
220+ if isinstance (self .text , str ) or MEMBER_STRING_ENCODING is str :
221221 tree .text = self .text
222222 else :
223223 tree .text = self .text .decode (MEMBER_STRING_ENCODING )
@@ -278,7 +278,7 @@ def __init__(self, extension_elements=None, extension_attributes=None,
278278
279279 def _ConvertElementTreeToMember (self , child_tree ):
280280 # Find the element's tag in this class's list of child members
281- if self .__class__ ._children . has_key ( child_tree . tag ) :
281+ if child_tree . tag in self .__class__ ._children :
282282 member_name = self .__class__ ._children [child_tree .tag ][0 ]
283283 member_class = self .__class__ ._children [child_tree .tag ][1 ]
284284 # If the class member is supposed to contain a list, make sure the
@@ -297,13 +297,13 @@ def _ConvertElementTreeToMember(self, child_tree):
297297
298298 def _ConvertElementAttributeToMember (self , attribute , value ):
299299 # Find the attribute in this class's list of attributes.
300- if self .__class__ ._attributes . has_key ( attribute ) :
300+ if attribute in self .__class__ ._attributes :
301301 # Find the member of this class which corresponds to the XML attribute
302302 # (lookup in current_class._attributes) and set this member to the
303303 # desired value (using self.__dict__).
304304 if value :
305305 # Encode the string to capture non-ascii characters (default UTF-8)
306- if MEMBER_STRING_ENCODING is unicode :
306+ if MEMBER_STRING_ENCODING is str :
307307 setattr (self , self .__class__ ._attributes [attribute ], value )
308308 else :
309309 setattr (self , self .__class__ ._attributes [attribute ],
@@ -318,7 +318,7 @@ def _AddMembersToElementTree(self, tree):
318318 # This uses the class's _children dictionary to find the members which
319319 # should become XML child nodes.
320320 member_node_names = [values [0 ] for tag , values in
321- self .__class__ ._children .iteritems ()]
321+ self .__class__ ._children .items ()]
322322 for member_name in member_node_names :
323323 member = getattr (self , member_name )
324324 if member is None :
@@ -329,10 +329,10 @@ def _AddMembersToElementTree(self, tree):
329329 else :
330330 member ._BecomeChildElement (tree )
331331 # Convert the members of this class which are XML attributes.
332- for xml_attribute , member_name in self .__class__ ._attributes .iteritems ():
332+ for xml_attribute , member_name in self .__class__ ._attributes .items ():
333333 member = getattr (self , member_name )
334334 if member is not None :
335- if isinstance (member , unicode ) or MEMBER_STRING_ENCODING is unicode :
335+ if isinstance (member , str ) or MEMBER_STRING_ENCODING is str :
336336 tree .attrib [xml_attribute ] = member
337337 else :
338338 tree .attrib [xml_attribute ] = member .decode (MEMBER_STRING_ENCODING )
@@ -1374,7 +1374,7 @@ def _TransferToElementTree(self, element_tree):
13741374 else :
13751375 element_tree .tag = self .tag
13761376
1377- for key , value in self .attributes .iteritems ():
1377+ for key , value in self .attributes .items ():
13781378 element_tree .attrib [key ] = value
13791379
13801380 for child in self .children :
@@ -1451,7 +1451,7 @@ def _ExtensionElementFromElementTree(element_tree):
14511451 namespace = None
14521452 tag = element_tag
14531453 extension = ExtensionElement (namespace = namespace , tag = tag )
1454- for key , value in element_tree .attrib .iteritems ():
1454+ for key , value in element_tree .attrib .items ():
14551455 extension .attributes [key ] = value
14561456 for child in element_tree :
14571457 extension .children .append (_ExtensionElementFromElementTree (child ))
@@ -1475,7 +1475,7 @@ def deprecated_function(*args, **kwargs):
14751475 # Preserve the original name to avoid masking all decorated functions as
14761476 # 'deprecated_function'
14771477 try :
1478- deprecated_function .func_name = f .func_name
1478+ deprecated_function .__name__ = f .__name__
14791479 except TypeError :
14801480 # Setting the func_name is not allowed in Python2.3.
14811481 pass
0 commit comments