Skip to content

Commit

Permalink
Merge pull request #1 from nbensa/little_fixes_for_python3
Browse files Browse the repository at this point in the history
Python 3 doesn't have basestring nor long; use str and int instead
  • Loading branch information
ricardoduarte committed Mar 14, 2013
2 parents 68857e5 + 58ae72a commit d25f18d
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions unipath/abstractpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,20 @@ def _new_helper(class_, args):
if len(args) == 1 and isinstance(args[0], class_) and \
args[0].pathlib == pathlib:
return args[0]
legal_arg_types = (class_, basestring, list, int, long)
try:
legal_arg_types = (class_, basestring, list, int, long)
except NameError: # Python 3 doesn't have basestring nor long
legal_arg_types = (class_, str, list, int)
args = list(args)
for i, arg in enumerate(args):
if not isinstance(arg, legal_arg_types):
m = "arguments must be str, unicode, list, int, long, or %s"
raise TypeError(m % class_.__name__)
if isinstance(arg, (int, long)):
try:
int_types = (int, long)
except NameError: # We are in Python 3
int_types = int
if isinstance(arg, int_types):
args[i] = str(arg)
elif isinstance(arg, class_) and arg.pathlib != pathlib:
arg = getattr(arg, components)() # Now a list.
Expand Down

0 comments on commit d25f18d

Please sign in to comment.