@@ -93,7 +93,7 @@ def optional_warn_function(*args, **kwargs):
93
93
# Preserve the original name to avoid masking all decorated functions as
94
94
# 'deprecated_function'
95
95
try :
96
- optional_warn_function .func_name = f .func_name
96
+ optional_warn_function .__name__ = f .__name__
97
97
except TypeError :
98
98
pass # In Python2.3 we can't set the func_name
99
99
return optional_warn_function
@@ -121,7 +121,7 @@ def CreateClassFromXMLString(target_class, xml_string, string_encoding=None):
121
121
match those of the target class.
122
122
"""
123
123
encoding = string_encoding or XML_STRING_ENCODING
124
- if encoding and isinstance (xml_string , unicode ):
124
+ if encoding and isinstance (xml_string , str ):
125
125
xml_string = xml_string .encode (encoding )
126
126
tree = ElementTree .fromstring (xml_string )
127
127
return _CreateClassFromElementTree (target_class , tree )
@@ -183,11 +183,11 @@ def _HarvestElementTree(self, tree):
183
183
# Fill in the instance members from the contents of the XML tree.
184
184
for child in tree :
185
185
self ._ConvertElementTreeToMember (child )
186
- for attribute , value in tree .attrib .iteritems ():
186
+ for attribute , value in tree .attrib .items ():
187
187
self ._ConvertElementAttributeToMember (attribute , value )
188
188
# Encode the text string according to the desired encoding type. (UTF-8)
189
189
if tree .text :
190
- if MEMBER_STRING_ENCODING is unicode :
190
+ if MEMBER_STRING_ENCODING is str :
191
191
self .text = tree .text
192
192
else :
193
193
self .text = tree .text .encode (MEMBER_STRING_ENCODING )
@@ -199,7 +199,7 @@ def _ConvertElementTreeToMember(self, child_tree, current_class=None):
199
199
def _ConvertElementAttributeToMember (self , attribute , value ):
200
200
# Encode the attribute value's string with the desired type Default UTF-8
201
201
if value :
202
- if MEMBER_STRING_ENCODING is unicode :
202
+ if MEMBER_STRING_ENCODING is str :
203
203
self .extension_attributes [attribute ] = value
204
204
else :
205
205
self .extension_attributes [attribute ] = value .encode (
@@ -209,15 +209,15 @@ def _ConvertElementAttributeToMember(self, attribute, value):
209
209
def _AddMembersToElementTree (self , tree ):
210
210
for child in self .extension_elements :
211
211
child ._BecomeChildElement (tree )
212
- for attribute , value in self .extension_attributes .iteritems ():
212
+ for attribute , value in self .extension_attributes .items ():
213
213
if value :
214
- if isinstance (value , unicode ) or MEMBER_STRING_ENCODING is unicode :
214
+ if isinstance (value , str ) or MEMBER_STRING_ENCODING is str :
215
215
tree .attrib [attribute ] = value
216
216
else :
217
217
# Decode the value from the desired encoding (default UTF-8).
218
218
tree .attrib [attribute ] = value .decode (MEMBER_STRING_ENCODING )
219
219
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 :
221
221
tree .text = self .text
222
222
else :
223
223
tree .text = self .text .decode (MEMBER_STRING_ENCODING )
@@ -278,7 +278,7 @@ def __init__(self, extension_elements=None, extension_attributes=None,
278
278
279
279
def _ConvertElementTreeToMember (self , child_tree ):
280
280
# 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 :
282
282
member_name = self .__class__ ._children [child_tree .tag ][0 ]
283
283
member_class = self .__class__ ._children [child_tree .tag ][1 ]
284
284
# If the class member is supposed to contain a list, make sure the
@@ -297,13 +297,13 @@ def _ConvertElementTreeToMember(self, child_tree):
297
297
298
298
def _ConvertElementAttributeToMember (self , attribute , value ):
299
299
# 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 :
301
301
# Find the member of this class which corresponds to the XML attribute
302
302
# (lookup in current_class._attributes) and set this member to the
303
303
# desired value (using self.__dict__).
304
304
if value :
305
305
# 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 :
307
307
setattr (self , self .__class__ ._attributes [attribute ], value )
308
308
else :
309
309
setattr (self , self .__class__ ._attributes [attribute ],
@@ -318,7 +318,7 @@ def _AddMembersToElementTree(self, tree):
318
318
# This uses the class's _children dictionary to find the members which
319
319
# should become XML child nodes.
320
320
member_node_names = [values [0 ] for tag , values in
321
- self .__class__ ._children .iteritems ()]
321
+ self .__class__ ._children .items ()]
322
322
for member_name in member_node_names :
323
323
member = getattr (self , member_name )
324
324
if member is None :
@@ -329,10 +329,10 @@ def _AddMembersToElementTree(self, tree):
329
329
else :
330
330
member ._BecomeChildElement (tree )
331
331
# 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 ():
333
333
member = getattr (self , member_name )
334
334
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 :
336
336
tree .attrib [xml_attribute ] = member
337
337
else :
338
338
tree .attrib [xml_attribute ] = member .decode (MEMBER_STRING_ENCODING )
@@ -1374,7 +1374,7 @@ def _TransferToElementTree(self, element_tree):
1374
1374
else :
1375
1375
element_tree .tag = self .tag
1376
1376
1377
- for key , value in self .attributes .iteritems ():
1377
+ for key , value in self .attributes .items ():
1378
1378
element_tree .attrib [key ] = value
1379
1379
1380
1380
for child in self .children :
@@ -1451,7 +1451,7 @@ def _ExtensionElementFromElementTree(element_tree):
1451
1451
namespace = None
1452
1452
tag = element_tag
1453
1453
extension = ExtensionElement (namespace = namespace , tag = tag )
1454
- for key , value in element_tree .attrib .iteritems ():
1454
+ for key , value in element_tree .attrib .items ():
1455
1455
extension .attributes [key ] = value
1456
1456
for child in element_tree :
1457
1457
extension .children .append (_ExtensionElementFromElementTree (child ))
@@ -1475,7 +1475,7 @@ def deprecated_function(*args, **kwargs):
1475
1475
# Preserve the original name to avoid masking all decorated functions as
1476
1476
# 'deprecated_function'
1477
1477
try :
1478
- deprecated_function .func_name = f .func_name
1478
+ deprecated_function .__name__ = f .__name__
1479
1479
except TypeError :
1480
1480
# Setting the func_name is not allowed in Python2.3.
1481
1481
pass
0 commit comments