Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Unified Diff: pylib/gyp/xcodeproj_file.py

Issue 1454433002: Python 3 compatibility Base URL: https://chromium.googlesource.com/external/gyp.git@master
Patch Set: Rebase with master (4ec6c4e3a94bd04a6da2858163d40b2429b8aad1) Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pylib/gyp/xcodeproj_file.py
diff --git a/pylib/gyp/xcodeproj_file.py b/pylib/gyp/xcodeproj_file.py
index d08b7f777002f02e260ad9ffffa1816f042dba49..353997a8dbe7d93cee66496cf839777f0744ba31 100644
--- a/pylib/gyp/xcodeproj_file.py
+++ b/pylib/gyp/xcodeproj_file.py
@@ -154,6 +154,10 @@ except ImportError:
import sha
_new_sha1 = sha.new
+try:
+ basestring = basestring
+except NameError:
+ basestring = str
# See XCObject._EncodeString. This pattern is used to determine when a string
# can be printed unquoted. Strings that match this pattern may be printed
@@ -314,7 +318,7 @@ class XCObject(object):
"""
that = self.__class__(id=self.id, parent=self.parent)
- for key, value in self._properties.iteritems():
+ for key, value in self._properties.items():
is_strong = self._schema[key][2]
if isinstance(value, XCObject):
@@ -324,8 +328,7 @@ class XCObject(object):
that._properties[key] = new_value
else:
that._properties[key] = value
- elif isinstance(value, str) or isinstance(value, unicode) or \
- isinstance(value, int):
+ elif isinstance(value, basestring) or isinstance(value, int):
that._properties[key] = value
elif isinstance(value, list):
if is_strong:
@@ -449,10 +452,10 @@ class XCObject(object):
# is 160 bits. Instead of throwing out 64 bits of the digest, xor them
# into the portion that gets used.
assert hash.digest_size % 4 == 0
- digest_int_count = hash.digest_size / 4
+ digest_int_count = hash.digest_size // 4
digest_ints = struct.unpack('>' + 'I' * digest_int_count, hash.digest())
id_ints = [0, 0, 0]
- for index in xrange(0, digest_int_count):
+ for index in range(0, digest_int_count):
id_ints[index % 3] ^= digest_ints[index]
self.id = '%08X%08X%08X' % tuple(id_ints)
@@ -475,7 +478,7 @@ class XCObject(object):
"""Returns a list of all of this object's owned (strong) children."""
children = []
- for property, attributes in self._schema.iteritems():
+ for property, attributes in self._schema.items():
(is_list, property_type, is_strong) = attributes[0:3]
if is_strong and property in self._properties:
if not is_list:
@@ -603,7 +606,12 @@ class XCObject(object):
comment = value.Comment()
elif isinstance(value, str):
printable += self._EncodeString(value)
- elif isinstance(value, unicode):
+ # A python3 compatible way of saying isinstance(value, unicode).
+ # basestring is str in python3 so this is equivalent to the above isinstance.
+ # Thus if it failed above it will fail here.
+ # In python2 we test against str and unicode at this point. str has already
+ # failed in the above isinstance so we test against unicode.
+ elif isinstance(value, basestring):
printable += self._EncodeString(value.encode('utf-8'))
elif isinstance(value, int):
printable += str(value)
@@ -622,7 +630,7 @@ class XCObject(object):
printable += end_tabs + ')'
elif isinstance(value, dict):
printable = '{' + sep
- for item_key, item_value in sorted(value.iteritems()):
+ for item_key, item_value in sorted(value.items()):
printable += element_tabs + \
self._XCPrintableValue(tabs + 1, item_key, flatten_list) + ' = ' + \
self._XCPrintableValue(tabs + 1, item_value, flatten_list) + ';' + \
@@ -691,7 +699,7 @@ class XCObject(object):
printable_value[0] == '"' and printable_value[-1] == '"':
printable_value = printable_value[1:-1]
printable += printable_key + ' = ' + printable_value + ';' + after_kv
- except TypeError, e:
+ except TypeError as e:
gyp.common.ExceptionAppend(e,
'while printing key "%s"' % key)
raise
@@ -730,7 +738,7 @@ class XCObject(object):
self._XCKVPrint(file, 3, 'isa', self.__class__.__name__)
# The remaining elements of an object dictionary are sorted alphabetically.
- for property, value in sorted(self._properties.iteritems()):
+ for property, value in sorted(self._properties.items()):
self._XCKVPrint(file, 3, property, value)
# End the object.
@@ -752,7 +760,7 @@ class XCObject(object):
if properties is None:
return
- for property, value in properties.iteritems():
+ for property, value in properties.items():
# Make sure the property is in the schema.
if not property in self._schema:
raise KeyError(property + ' not in ' + self.__class__.__name__)
@@ -766,7 +774,7 @@ class XCObject(object):
' must be list, not ' + value.__class__.__name__)
for item in value:
if not isinstance(item, property_type) and \
- not (item.__class__ == unicode and property_type == str):
+ not (isinstance(item, basestring) and property_type == str):
# Accept unicode where str is specified. str is treated as
# UTF-8-encoded.
raise TypeError(
@@ -774,7 +782,7 @@ class XCObject(object):
' must be ' + property_type.__name__ + ', not ' + \
item.__class__.__name__)
elif not isinstance(value, property_type) and \
- not (value.__class__ == unicode and property_type == str):
+ not (isinstance(value, basestring) and property_type == str):
# Accept unicode where str is specified. str is treated as
# UTF-8-encoded.
raise TypeError(
@@ -788,8 +796,7 @@ class XCObject(object):
self._properties[property] = value.Copy()
else:
self._properties[property] = value
- elif isinstance(value, str) or isinstance(value, unicode) or \
- isinstance(value, int):
+ elif isinstance(value, basestring) or isinstance(value, int):
self._properties[property] = value
elif isinstance(value, list):
if is_strong:
@@ -865,7 +872,7 @@ class XCObject(object):
# TODO(mark): A stronger verification mechanism is needed. Some
# subclasses need to perform validation beyond what the schema can enforce.
- for property, attributes in self._schema.iteritems():
+ for property, attributes in self._schema.items():
(is_list, property_type, is_strong, is_required) = attributes[0:4]
if is_required and not property in self._properties:
raise KeyError(self.__class__.__name__ + ' requires ' + property)
@@ -875,7 +882,7 @@ class XCObject(object):
overwrite properties that have already been set."""
defaults = {}
- for property, attributes in self._schema.iteritems():
+ for property, attributes in self._schema.items():
(is_list, property_type, is_strong, is_required) = attributes[0:4]
if is_required and len(attributes) >= 5 and \
not property in self._properties:
@@ -1426,8 +1433,8 @@ class XCFileLikeElement(XCHierarchicalElement):
xche = self
while xche != None and isinstance(xche, XCHierarchicalElement):
xche_hashables = xche.Hashables()
- for index in xrange(0, len(xche_hashables)):
- hashables.insert(index, xche_hashables[index])
+ for index, xche_hashable in enumerate(xche_hashables):
+ hashables.insert(index, xche_hashable)
xche = xche.parent
return hashables
@@ -2401,8 +2408,7 @@ class PBXNativeTarget(XCTarget):
# The headers phase should come before the resources, sources, and
# frameworks phases, if any.
insert_at = len(self._properties['buildPhases'])
- for index in xrange(0, len(self._properties['buildPhases'])):
- phase = self._properties['buildPhases'][index]
+ for index, phase in enumerate(self._properties['buildPhases']):
if isinstance(phase, PBXResourcesBuildPhase) or \
isinstance(phase, PBXSourcesBuildPhase) or \
isinstance(phase, PBXFrameworksBuildPhase):
@@ -2422,8 +2428,7 @@ class PBXNativeTarget(XCTarget):
# The resources phase should come before the sources and frameworks
# phases, if any.
insert_at = len(self._properties['buildPhases'])
- for index in xrange(0, len(self._properties['buildPhases'])):
- phase = self._properties['buildPhases'][index]
+ for index, phase in enumerate(self._properties['buildPhases']):
if isinstance(phase, PBXSourcesBuildPhase) or \
isinstance(phase, PBXFrameworksBuildPhase):
insert_at = index
@@ -2844,7 +2849,7 @@ class PBXProject(XCContainerPortal):
# determine the sort order.
return cmp(x_index, y_index)
- for other_pbxproject, ref_dict in self._other_pbxprojects.iteritems():
+ for other_pbxproject, ref_dict in self._other_pbxprojects.items():
# Build up a list of products in the remote project file, ordered the
# same as the targets that produce them.
remote_products = []

Powered by Google App Engine
This is Rietveld 408576698