Skip to content

Commit

Permalink
Fixed Python 3 compatibility.
Browse files Browse the repository at this point in the history
Fix taken from: oxplot/fysom#1
Replaces: alliedmodders#33
  • Loading branch information
WildCard65 committed Feb 11, 2016
1 parent debba8a commit 4995192
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
13 changes: 9 additions & 4 deletions ambuild2/frontend/v2_1/base/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ class ConfigureException(Exception):
def __init__(self, *args, **kwargs):
super(ConfigureException, self).__init__(*args, **kwargs)

try:
stringType = basestring
except NameError: #Python 3, basestring causes NameError
stringType = str

class BaseGenerator(object):
def __init__(self, sourcePath, buildPath, originalCwd, options, args):
super(BaseGenerator, self).__init__()
Expand Down Expand Up @@ -63,7 +68,7 @@ def popContext(self):
self.contextStack_.pop()

def importScript(self, context, path, vars={}):
if not isinstance(path, basestring):
if not isinstance(path, stringType):
for item in path:
self.importScriptImpl(context, item, vars)
return None
Expand All @@ -74,14 +79,14 @@ def evalScript(self, context, path, vars={}):
return obj.get('rvalue', None)

def runBuildScript(self, context, path, vars={}):
if not isinstance(path, basestring):
if not isinstance(path, stringType):
for item in path:
self.runBuildScriptImpl(context, item, vars)
return None
return self.runBuildScriptImpl(context, path, vars)

def importScriptImpl(self, parent, path, vars):
assert isinstance(path, basestring)
assert isinstance(path, stringType)

sourceFolder, _, scriptFile = self.computeScriptPaths(parent, path)

Expand All @@ -101,7 +106,7 @@ def importScriptImpl(self, parent, path, vars):
return obj

def runBuildScriptImpl(self, parent, path, vars):
assert isinstance(path, basestring)
assert isinstance(path, stringType)

if parent is not self.contextStack_[-1]:
raise Exception('Can only create child build contexts of the currently active context')
Expand Down
7 changes: 6 additions & 1 deletion ambuild2/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,13 @@ def con_err(*args):
def IsLambda(v):
return type(v) == LambdaType

try:
stringType = basestring
except NameError: #Python 3, basestring causes NameError
stringType = str

def IsString(v):
return isinstance(v, basestring)
return isinstance(v, stringType)

class Expando(object):
pass
Expand Down

0 comments on commit 4995192

Please sign in to comment.