gyp: fix the remaining Python 3 issues

PR-URL: https://github.com/nodejs/node-gyp/pull/1793
Reviewed-By: Rod Vagg <rod@vagg.org>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
cclauss 2019-06-21 17:45:44 +02:00 committed by Rod Vagg
parent 395f843de0
commit a991f633d6
No known key found for this signature in database
GPG key ID: C273792F7D83545D
6 changed files with 35 additions and 21 deletions

View file

@ -10,6 +10,11 @@ import random
import gyp.common
try:
cmp
except NameError:
def cmp(x, y):
return (x > y) - (x < y)
# Initialize random number generator
random.seed()

View file

@ -28,8 +28,12 @@ _deepcopy_dispatch = d = {}
def _deepcopy_atomic(x):
return x
for x in (type(None), int, long, float,
bool, str, unicode, type):
try:
types = bool, float, int, str, type, type(None), long, unicode
except NameError: # Python 3
types = bool, float, int, str, type, type(None)
for x in types:
d[x] = _deepcopy_atomic
def _deepcopy_list(x):

View file

@ -138,21 +138,18 @@ a project file is output.
"""
import gyp.common
import hashlib
import posixpath
import re
import struct
import sys
# hashlib is supplied as of Python 2.5 as the replacement interface for sha
# and other secure hashes. In 2.6, sha is deprecated. Import hashlib if
# available, avoiding a deprecation warning under 2.6. Import sha otherwise,
# preserving 2.4 compatibility.
try:
import hashlib
_new_sha1 = hashlib.sha1
except ImportError:
import sha
_new_sha1 = sha.new
basestring, cmp, unicode
except NameError: # Python 3
basestring = unicode = str
def cmp(x, y):
return (x > y) - (x < y)
# See XCObject._EncodeString. This pattern is used to determine when a string
@ -324,8 +321,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, int)):
that._properties[key] = value
elif isinstance(value, list):
if is_strong:
@ -422,7 +418,7 @@ class XCObject(object):
hash.update(data)
if seed_hash is None:
seed_hash = _new_sha1()
seed_hash = hashlib.sha1()
hash = seed_hash.copy()
@ -788,8 +784,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, int)):
self._properties[property] = value
elif isinstance(value, list):
if is_strong:

View file

@ -22,6 +22,12 @@ from xml.dom.minidom import Node
__author__ = 'nsylvain (Nicolas Sylvain)'
try:
cmp
except NameError:
def cmp(x, y):
return (x > y) - (x < y)
REPLACEMENTS = dict()
ARGUMENTS = None