Skip to content

Commit

Permalink
Fix undefined names
Browse files Browse the repository at this point in the history
  • Loading branch information
cclauss authored and refack committed Oct 14, 2018
1 parent 2394a1e commit 897e8bb
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 15 deletions.
5 changes: 5 additions & 0 deletions gyp/pylib/gyp/MSVSNew.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
import md5
_new_md5 = md5.new

try:
cmp # Python 2
except NameError:
def cmp(x, y): # Python 3
return (x > y) - (x < y)

# Initialize random number generator
random.seed()
Expand Down
7 changes: 3 additions & 4 deletions gyp/pylib/gyp/MSVSVersion.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import re
import subprocess
import sys
import gyp
import glob


Expand Down Expand Up @@ -178,15 +177,15 @@ def _RegistryGetValueUsingWinReg(key, value):
"""
try:
# Python 2
from _winreg import OpenKey, QueryValueEx
from _winreg import HKEY_LOCAL_MACHINE, OpenKey, QueryValueEx
except ImportError:
# Python 3
from winreg import OpenKey, QueryValueEx
from winreg import HKEY_LOCAL_MACHINE, OpenKey, QueryValueEx

try:
root, subkey = key.split('\\', 1)
assert root == 'HKLM' # Only need HKLM for now.
with OpenKey(_winreg.HKEY_LOCAL_MACHINE, subkey) as hkey:
with OpenKey(HKEY_LOCAL_MACHINE, subkey) as hkey:
return QueryValueEx(hkey, value)[0]
except WindowsError:
return None
Expand Down
9 changes: 7 additions & 2 deletions gyp/pylib/gyp/simple_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@ def deepcopy(x):
def _deepcopy_atomic(x):
return x

for x in (type(None), int, long, float,
bool, str, unicode, type):
try:
type_list = (type(None), int, long, float,
bool, str, unicode, type)
except NameError:
type_list = (type(None), int, float,
bool, str, type)
for x in type_list:
d[x] = _deepcopy_atomic

def _deepcopy_list(x):
Expand Down
2 changes: 1 addition & 1 deletion gyp/pylib/gyp/xcode_emulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ def GetLdflags(self, configname, product_dir, gyp_to_build_path, arch=None):
if self._IsXCTest():
platform_root = self._XcodePlatformPath(configname)
if platform_root:
cflags.append('-F' + platform_root + '/Developer/Library/Frameworks/')
ldflags.append('-F' + platform_root + '/Developer/Library/Frameworks/')

is_extension = self._IsIosAppExtension() or self._IsIosWatchKitExtension()
if sdk_root and is_extension:
Expand Down
25 changes: 19 additions & 6 deletions gyp/pylib/gyp/xcodeproj_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,21 @@
import sha
_new_sha1 = sha.new

try:
basestring # Python 2
except NameError:
basestring = (str, ) # Python 3

try:
cmp # Python 2
except NameError:
def cmp(x, y): # Python 3
return (x > y) - (x < y)

try:
unicode # Python 2
except NameError:
unicode = str # Python 3

# See XCObject._EncodeString. This pattern is used to determine when a string
# can be printed unquoted. Strings that match this pattern may be printed
Expand Down Expand Up @@ -324,8 +339,7 @@ def Copy(self):
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:
Expand Down Expand Up @@ -766,15 +780,15 @@ def UpdateProperties(self, properties, do_copy=False):
' 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):
item.__class__ not in (str, unicode):
# Accept unicode where str is specified. str is treated as
# UTF-8-encoded.
raise TypeError(
'item of ' + property + ' of ' + self.__class__.__name__ + \
' must be ' + property_type.__name__ + ', not ' + \
item.__class__.__name__)
elif not isinstance(value, property_type) and \
not (value.__class__ == unicode and property_type == str):
value.__class__ not in (str, unicode):
# Accept unicode where str is specified. str is treated as
# UTF-8-encoded.
raise TypeError(
Expand All @@ -788,8 +802,7 @@ def UpdateProperties(self, properties, do_copy=False):
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:
Expand Down
6 changes: 6 additions & 0 deletions gyp/tools/pretty_vcproj.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
from xml.dom.minidom import parse
from xml.dom.minidom import Node

try:
cmp # Python 2
except NameError:
def cmp(x, y): # Python 3
return (x > y) - (x < y)

REPLACEMENTS = dict()
ARGUMENTS = None

Expand Down
10 changes: 8 additions & 2 deletions test/fixtures/test-charmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@
import sys
import locale

reload(sys)
try:
reload(sys)
except NameError:
pass

def main():
encoding = locale.getdefaultlocale()[1]
if not encoding:
return False

sys.setdefaultencoding(encoding)
try:
sys.setdefaultencoding(encoding)
except NameError:
pass
textmap = {
'cp936': u'\u4e2d\u6587',
'cp1252': u'Lat\u012Bna',
Expand Down

0 comments on commit 897e8bb

Please sign in to comment.