import os
import os.path
import re
-import string
import sys
import types
# My ActivePython 2.0.1 doesn't set os.altsep! What gives?
_altsep = '/'
if _altsep:
- def rightmost_separator(path, sep, _altsep=_altsep):
- rfind = string.rfind
- return max(rfind(path, sep), rfind(path, _altsep))
+ def rightmost_separator(path, sep):
+ return max(path.rfind(sep), path.rfind(_altsep))
else:
- rightmost_separator = string.rfind
+ def rightmost_separator(path, sep):
+ return path.rfind(sep)
# First two from the Python Cookbook, just for completeness.
# (Yeah, yeah, YAGNI...)
def splitext(path):
"Same as os.path.splitext() but faster."
sep = rightmost_separator(path, os.sep)
- dot = string.rfind(path, '.')
+ dot = path.rfind('.')
# An ext is only real if it has at least one non-digit char
if dot > sep and not containsOnly(path[dot:], "0123456789."):
return path[:dot],path[dot:]
"""
drive, rest = os.path.splitdrive(path)
if drive:
- path = string.upper(drive) + rest
+ path = drive.upper() + rest
return path
class NodeList(UserList):
return len(self.data) != 0
def __str__(self):
- return string.join(map(str, self.data))
+ return ' '.join(map(str, self.data))
def __iter__(self):
return iter(self.data)
def __call__(self, *args, **kwargs):
- result = map(lambda x, args=args, kwargs=kwargs: apply(x,
- args,
- kwargs),
- self.data)
+ result = [x(*args, **kwargs) for x in self.data]
return self.__class__(result)
def __getattr__(self, name):
- result = map(lambda x, n=name: getattr(x, n), self.data)
+ result = [getattr(x, name) for x in self.data]
return self.__class__(result)
else:
retval = retval + " "
- if visited.has_key(rname):
+ if rname in visited:
return retval + "+-[" + rname + "]\n"
retval = retval + "+-" + rname + "\n"
def MMM(m):
return [" ","| "][m]
- margins = map(MMM, margin[:-1])
+ margins = list(map(MMM, margin[:-1]))
children = child_func(root)
- if prune and visited.has_key(rname) and children:
- print string.join(tags + margins + ['+-[', rname, ']'], '')
+ if prune and rname in visited and children:
+ print ''.join(tags + margins + ['+-[', rname, ']'])
return
- print string.join(tags + margins + ['+-', rname], '')
+ print ''.join(tags + margins + ['+-', rname])
visited[rname] = 1
def to_String_for_subst(s):
if is_Sequence( s ):
- return string.join( map(to_String_for_subst, s) )
+ return ' '.join( map(to_String_for_subst, s) )
return to_String( s )
return str(s)
def to_String_for_subst(s,
- isinstance=isinstance, join=string.join, str=str, to_String=to_String,
+ isinstance=isinstance, str=str, to_String=to_String,
BaseStringTypes=BaseStringTypes, SequenceTypes=SequenceTypes,
UserString=UserString):
l = []
for e in s:
l.append(to_String_for_subst(e))
- return join( s )
+ return ' '.join( s )
elif isinstance(s, UserString):
# s.data can only be either a unicode or a regular
# string. Please see the UserString initializer.
d[types.DictionaryType] = _semi_deepcopy_dict
def _semi_deepcopy_list(x):
- return map(semi_deepcopy, x)
+ return list(map(semi_deepcopy, x))
d[types.ListType] = _semi_deepcopy_list
def _semi_deepcopy_tuple(x):
except KeyError:
return None
if is_String(path):
- path = string.split(path, os.pathsep)
+ path = path.split(os.pathsep)
if pathext is None:
try:
pathext = os.environ['PATHEXT']
except KeyError:
pathext = '.COM;.EXE;.BAT;.CMD'
if is_String(pathext):
- pathext = string.split(pathext, os.pathsep)
+ pathext = pathext.split(os.pathsep)
for ext in pathext:
- if string.lower(ext) == string.lower(file[-len(ext):]):
+ if ext.lower() == file[-len(ext):].lower():
pathext = ['']
break
if not is_List(reject) and not is_Tuple(reject):
except KeyError:
return None
if is_String(path):
- path = string.split(path, os.pathsep)
+ path = path.split(os.pathsep)
if pathext is None:
pathext = ['.exe', '.cmd']
for ext in pathext:
- if string.lower(ext) == string.lower(file[-len(ext):]):
+ if ext.lower() == file[-len(ext):].lower():
pathext = ['']
break
if not is_List(reject) and not is_Tuple(reject):
except KeyError:
return None
if is_String(path):
- path = string.split(path, os.pathsep)
+ path = path.split(os.pathsep)
if not is_List(reject) and not is_Tuple(reject):
reject = [reject]
for d in path:
is_list = 1
paths = orig
if not is_List(orig) and not is_Tuple(orig):
- paths = string.split(paths, sep)
+ paths = paths.split(sep)
is_list = 0
if is_String(newpath):
- newpaths = string.split(newpath, sep)
+ newpaths = newpath.split(sep)
elif not is_List(newpath) and not is_Tuple(newpath):
newpaths = [ newpath ] # might be a Dir
else:
newpaths = newpath
if canonicalize:
- newpaths=map(canonicalize, newpaths)
+ newpaths=list(map(canonicalize, newpaths))
if not delete_existing:
# First uniquify the old paths, making sure to
if is_list:
return paths
else:
- return string.join(paths, sep)
+ return sep.join(paths)
def AppendPath(oldpath, newpath, sep = os.pathsep,
delete_existing=1, canonicalize=None):
is_list = 1
paths = orig
if not is_List(orig) and not is_Tuple(orig):
- paths = string.split(paths, sep)
+ paths = paths.split(sep)
is_list = 0
if is_String(newpath):
- newpaths = string.split(newpath, sep)
+ newpaths = newpath.split(sep)
elif not is_List(newpath) and not is_Tuple(newpath):
newpaths = [ newpath ] # might be a Dir
else:
newpaths = newpath
if canonicalize:
- newpaths=map(canonicalize, newpaths)
+ newpaths=list(map(canonicalize, newpaths))
if not delete_existing:
# add old paths to result, then
if is_list:
return paths
else:
- return string.join(paths, sep)
+ return sep.join(paths)
if sys.platform == 'cygwin':
def get_native_path(path):
"""Transforms an absolute path into a native path for the system. In
Cygwin, this converts from a Cygwin path to a Windows one."""
- return string.replace(os.popen('cygpath -w ' + path).read(), '\n', '')
+ return os.popen('cygpath -w ' + path).read().replace('\n', '')
else:
def get_native_path(path):
"""Transforms an absolute path into a native path for the system.
if is_List(arg) or is_Tuple(arg):
return arg
elif is_String(arg):
- return string.split(arg)
+ return arg.split()
else:
return [arg]
def __coerce__(self, other):
return (self, CLVar(other))
def __str__(self):
- return string.join(self.data)
+ return ' '.join(self.data)
# A dictionary that preserves the order in which items are added.
# Submitted by David Benjamin to ActiveState's Python Cookbook web site:
self.__setitem__(key, val)
def values(self):
- return map(self.get, self._keys)
+ return list(map(self.get, self._keys))
class Selector(OrderedDict):
"""A callable ordered dictionary that maps file suffixes to
for (k,v) in self.items():
if k is not None:
s_k = env.subst(k)
- if s_dict.has_key(s_k):
+ if s_k in s_dict:
# We only raise an error when variables point
# to the same suffix. If one suffix is literal
# and a variable suffix contains this literal,
result = []
for item in seq:
#if not item in seen:
- if not seen.has_key(item):
+ if item not in seen:
seen[item] = 1
result.append(item)
return result
else:
result.append(line)
break
- return string.join(result, '')
+ return ''.join(result)
def readlines(self):
result = []
UserList.reverse(self)
def sort(self, *args, **kwds):
self.__make_unique()
- #return UserList.sort(self, *args, **kwds)
- return apply(UserList.sort, (self,)+args, kwds)
+ return UserList.sort(self, *args, **kwds)
def extend(self, other):
UserList.extend(self, other)
self.unique = False
if len(signatures) == 1:
return signatures[0]
else:
- return MD5signature(string.join(signatures, ', '))
+ return MD5signature(', '.join(signatures))
""" Null objects always and reliably "do nothing." """
def __new__(cls, *args, **kwargs):
if not '_inst' in vars(cls):
- #cls._inst = type.__new__(cls, *args, **kwargs)
- cls._inst = apply(type.__new__, (cls,) + args, kwargs)
+ cls._inst = type.__new__(cls, *args, **kwargs)
return cls._inst
def __init__(self, *args, **kwargs):
pass