Commit 3bf5ce40 authored by Guido van Rossum's avatar Guido van Rossum

Checkpoint. Manipulated things so that string literals are always

unicode, and a few other compensating changes, e.g. str <- unicode,
chr <- unichr, and repr() of a unicode string no longer starts
with 'u'.  Lots of unit tests are broken, but some basic things
work, in particular distutils works so the extensions can be built,
and test_builtin.py works.
parent 078fadd2
...@@ -168,7 +168,7 @@ class CCompiler: ...@@ -168,7 +168,7 @@ class CCompiler:
# set_executables () # set_executables ()
def set_executable(self, key, value): def set_executable(self, key, value):
if type(value) is StringType: if isinstance(value, basestring):
setattr(self, key, split_quoted(value)) setattr(self, key, split_quoted(value))
else: else:
setattr(self, key, value) setattr(self, key, value)
...@@ -193,8 +193,8 @@ class CCompiler: ...@@ -193,8 +193,8 @@ class CCompiler:
if not (type (defn) is TupleType and if not (type (defn) is TupleType and
(len (defn) == 1 or (len (defn) == 1 or
(len (defn) == 2 and (len (defn) == 2 and
(type (defn[1]) is StringType or defn[1] is None))) and (isinstance (defn[1], basestring) or defn[1] is None))) and
type (defn[0]) is StringType): isinstance (defn[0], basestring)):
raise TypeError, \ raise TypeError, \
("invalid macro definition '%s': " % defn) + \ ("invalid macro definition '%s': " % defn) + \
"must be tuple (string,), (string, string), or " + \ "must be tuple (string,), (string, string), or " + \
...@@ -344,7 +344,7 @@ class CCompiler: ...@@ -344,7 +344,7 @@ class CCompiler:
""" """
if outdir is None: if outdir is None:
outdir = self.output_dir outdir = self.output_dir
elif type(outdir) is not StringType: elif not isinstance(outdir, basestring):
raise TypeError, "'output_dir' must be a string or None" raise TypeError, "'output_dir' must be a string or None"
if macros is None: if macros is None:
...@@ -442,7 +442,7 @@ class CCompiler: ...@@ -442,7 +442,7 @@ class CCompiler:
""" """
if output_dir is None: if output_dir is None:
output_dir = self.output_dir output_dir = self.output_dir
elif type (output_dir) is not StringType: elif not isinstance(output_dir, basestring):
raise TypeError, "'output_dir' must be a string or None" raise TypeError, "'output_dir' must be a string or None"
if macros is None: if macros is None:
...@@ -527,7 +527,7 @@ class CCompiler: ...@@ -527,7 +527,7 @@ class CCompiler:
if output_dir is None: if output_dir is None:
output_dir = self.output_dir output_dir = self.output_dir
elif type (output_dir) is not StringType: elif not isinstance(output_dir, basestring):
raise TypeError, "'output_dir' must be a string or None" raise TypeError, "'output_dir' must be a string or None"
return (objects, output_dir) return (objects, output_dir)
......
...@@ -222,7 +222,7 @@ class Command: ...@@ -222,7 +222,7 @@ class Command:
if val is None: if val is None:
setattr(self, option, default) setattr(self, option, default)
return default return default
elif type(val) is not StringType: elif not isinstance(val, basestring):
raise DistutilsOptionError, \ raise DistutilsOptionError, \
"'%s' must be a %s (got `%s`)" % (option, what, val) "'%s' must be a %s (got `%s`)" % (option, what, val)
return val return val
...@@ -242,12 +242,11 @@ class Command: ...@@ -242,12 +242,11 @@ class Command:
val = getattr(self, option) val = getattr(self, option)
if val is None: if val is None:
return return
elif type(val) is StringType: elif isinstance(val, basestring):
setattr(self, option, re.split(r',\s*|\s+', val)) setattr(self, option, re.split(r',\s*|\s+', val))
else: else:
if type(val) is ListType: if type(val) is ListType:
types = map(type, val) ok = all(isinstance(v, basestring) for v in val)
ok = (types == [StringType] * len(val))
else: else:
ok = 0 ok = 0
...@@ -421,7 +420,7 @@ class Command: ...@@ -421,7 +420,7 @@ class Command:
# Allow 'infiles' to be a single string # Allow 'infiles' to be a single string
if type(infiles) is StringType: if isinstance(infiles, basestring):
infiles = (infiles,) infiles = (infiles,)
elif type(infiles) not in (ListType, TupleType): elif type(infiles) not in (ListType, TupleType):
raise TypeError, \ raise TypeError, \
......
...@@ -92,7 +92,7 @@ class build_clib (Command): ...@@ -92,7 +92,7 @@ class build_clib (Command):
if self.include_dirs is None: if self.include_dirs is None:
self.include_dirs = self.distribution.include_dirs or [] self.include_dirs = self.distribution.include_dirs or []
if type(self.include_dirs) is StringType: if isinstance(self.include_dirs, basestring):
self.include_dirs = self.include_dirs.split(os.pathsep) self.include_dirs = self.include_dirs.split(os.pathsep)
# XXX same as for build_ext -- what about 'self.define' and # XXX same as for build_ext -- what about 'self.define' and
...@@ -147,7 +147,7 @@ class build_clib (Command): ...@@ -147,7 +147,7 @@ class build_clib (Command):
raise DistutilsSetupError, \ raise DistutilsSetupError, \
"each element of 'libraries' must a 2-tuple" "each element of 'libraries' must a 2-tuple"
if type(lib[0]) is not StringType: if isinstance(lib[0], basestring) StringType:
raise DistutilsSetupError, \ raise DistutilsSetupError, \
"first element of each tuple in 'libraries' " + \ "first element of each tuple in 'libraries' " + \
"must be a string (the library name)" "must be a string (the library name)"
......
...@@ -137,7 +137,7 @@ class build_ext (Command): ...@@ -137,7 +137,7 @@ class build_ext (Command):
plat_py_include = sysconfig.get_python_inc(plat_specific=1) plat_py_include = sysconfig.get_python_inc(plat_specific=1)
if self.include_dirs is None: if self.include_dirs is None:
self.include_dirs = self.distribution.include_dirs or [] self.include_dirs = self.distribution.include_dirs or []
if type(self.include_dirs) is StringType: if isinstance(self.include_dirs, basestring):
self.include_dirs = self.include_dirs.split(os.pathsep) self.include_dirs = self.include_dirs.split(os.pathsep)
# Put the Python "system" include dir at the end, so that # Put the Python "system" include dir at the end, so that
...@@ -146,7 +146,7 @@ class build_ext (Command): ...@@ -146,7 +146,7 @@ class build_ext (Command):
if plat_py_include != py_include: if plat_py_include != py_include:
self.include_dirs.append(plat_py_include) self.include_dirs.append(plat_py_include)
if type(self.libraries) is StringType: if isinstance(self.libraries, basestring):
self.libraries = [self.libraries] self.libraries = [self.libraries]
# Life is easier if we're not forever checking for None, so # Life is easier if we're not forever checking for None, so
...@@ -155,12 +155,12 @@ class build_ext (Command): ...@@ -155,12 +155,12 @@ class build_ext (Command):
self.libraries = [] self.libraries = []
if self.library_dirs is None: if self.library_dirs is None:
self.library_dirs = [] self.library_dirs = []
elif type(self.library_dirs) is StringType: elif isinstance(self.library_dirs, basestring):
self.library_dirs = self.library_dirs.split(os.pathsep) self.library_dirs = self.library_dirs.split(os.pathsep)
if self.rpath is None: if self.rpath is None:
self.rpath = [] self.rpath = []
elif type(self.rpath) is StringType: elif isinstance(self.rpath, basestring):
self.rpath = self.rpath.split(os.pathsep) self.rpath = self.rpath.split(os.pathsep)
# for extensions under windows use different directories # for extensions under windows use different directories
...@@ -321,7 +321,7 @@ class build_ext (Command): ...@@ -321,7 +321,7 @@ class build_ext (Command):
("each element of 'ext_modules' option must be an " ("each element of 'ext_modules' option must be an "
"Extension instance or 2-tuple") "Extension instance or 2-tuple")
if not (type(ext_name) is StringType and if not (isinstance(ext_name, basestring) and
extension_name_re.match(ext_name)): extension_name_re.match(ext_name)):
raise DistutilsSetupError, \ raise DistutilsSetupError, \
("first element of each tuple in 'ext_modules' " ("first element of each tuple in 'ext_modules' "
......
...@@ -361,7 +361,7 @@ class build_py (Command): ...@@ -361,7 +361,7 @@ class build_py (Command):
def build_module (self, module, module_file, package): def build_module (self, module, module_file, package):
if type(package) is StringType: if isinstance(package, basestring):
package = package.split('.') package = package.split('.')
elif type(package) not in (ListType, TupleType): elif type(package) not in (ListType, TupleType):
raise TypeError, \ raise TypeError, \
......
...@@ -73,17 +73,17 @@ class config (Command): ...@@ -73,17 +73,17 @@ class config (Command):
def finalize_options (self): def finalize_options (self):
if self.include_dirs is None: if self.include_dirs is None:
self.include_dirs = self.distribution.include_dirs or [] self.include_dirs = self.distribution.include_dirs or []
elif type(self.include_dirs) is StringType: elif isinstance(self.include_dirs, basestring):
self.include_dirs = self.include_dirs.split(os.pathsep) self.include_dirs = self.include_dirs.split(os.pathsep)
if self.libraries is None: if self.libraries is None:
self.libraries = [] self.libraries = []
elif type(self.libraries) is StringType: elif isinstance(self.libraries, basestring):
self.libraries = [self.libraries] self.libraries = [self.libraries]
if self.library_dirs is None: if self.library_dirs is None:
self.library_dirs = [] self.library_dirs = []
elif type(self.library_dirs) is StringType: elif isinstance(self.library_dirs, basestring):
self.library_dirs = self.library_dirs.split(os.pathsep) self.library_dirs = self.library_dirs.split(os.pathsep)
...@@ -212,7 +212,7 @@ class config (Command): ...@@ -212,7 +212,7 @@ class config (Command):
self._check_compiler() self._check_compiler()
(src, out) = self._preprocess(body, headers, include_dirs, lang) (src, out) = self._preprocess(body, headers, include_dirs, lang)
if type(pattern) is StringType: if isinstance(pattern, basestring):
pattern = re.compile(pattern) pattern = re.compile(pattern)
file = open(out) file = open(out)
......
...@@ -463,7 +463,7 @@ class install (Command): ...@@ -463,7 +463,7 @@ class install (Command):
self.extra_path = self.distribution.extra_path self.extra_path = self.distribution.extra_path
if self.extra_path is not None: if self.extra_path is not None:
if type(self.extra_path) is StringType: if isinstance(self.extra_path, basestring):
self.extra_path = self.extra_path.split(',') self.extra_path = self.extra_path.split(',')
if len(self.extra_path) == 1: if len(self.extra_path) == 1:
......
...@@ -10,7 +10,6 @@ platform-independent data files.""" ...@@ -10,7 +10,6 @@ platform-independent data files."""
__revision__ = "$Id$" __revision__ = "$Id$"
import os import os
from types import StringType
from distutils.core import Command from distutils.core import Command
from distutils.util import change_root, convert_path from distutils.util import change_root, convert_path
...@@ -48,7 +47,7 @@ class install_data (Command): ...@@ -48,7 +47,7 @@ class install_data (Command):
def run (self): def run (self):
self.mkpath(self.install_dir) self.mkpath(self.install_dir)
for f in self.data_files: for f in self.data_files:
if type(f) is StringType: if isinstance(f, basestring):
# it's a simple file, so copy it # it's a simple file, so copy it
f = convert_path(f) f = convert_path(f)
if self.warn_dir: if self.warn_dir:
......
...@@ -31,7 +31,7 @@ def mkpath (name, mode=0777, verbose=0, dry_run=0): ...@@ -31,7 +31,7 @@ def mkpath (name, mode=0777, verbose=0, dry_run=0):
global _path_created global _path_created
# Detect a common bug -- name is None # Detect a common bug -- name is None
if not isinstance(name, StringTypes): if not isinstance(name, basestring):
raise DistutilsInternalError, \ raise DistutilsInternalError, \
"mkpath: 'name' must be a string (got %r)" % (name,) "mkpath: 'name' must be a string (got %r)" % (name,)
......
...@@ -598,13 +598,13 @@ Common commands: (see '--help-commands' for more) ...@@ -598,13 +598,13 @@ Common commands: (see '--help-commands' for more)
keywords = self.metadata.keywords keywords = self.metadata.keywords
if keywords is not None: if keywords is not None:
if type(keywords) is StringType: if isinstance(keywords, basestring):
keywordlist = keywords.split(',') keywordlist = keywords.split(',')
self.metadata.keywords = [x.strip() for x in keywordlist] self.metadata.keywords = [x.strip() for x in keywordlist]
platforms = self.metadata.platforms platforms = self.metadata.platforms
if platforms is not None: if platforms is not None:
if type(platforms) is StringType: if isinstance(platforms, basestring):
platformlist = platforms.split(',') platformlist = platforms.split(',')
self.metadata.platforms = [x.strip() for x in platformlist] self.metadata.platforms = [x.strip() for x in platformlist]
...@@ -906,7 +906,7 @@ Common commands: (see '--help-commands' for more) ...@@ -906,7 +906,7 @@ Common commands: (see '--help-commands' for more)
neg_opt = {} neg_opt = {}
try: try:
is_string = type(value) is StringType is_string = isinstance(value, basestring)
if option in neg_opt and is_string: if option in neg_opt and is_string:
setattr(command_obj, neg_opt[option], not strtobool(value)) setattr(command_obj, neg_opt[option], not strtobool(value))
elif option in bool_opts and is_string: elif option in bool_opts and is_string:
......
...@@ -103,9 +103,9 @@ class Extension: ...@@ -103,9 +103,9 @@ class Extension:
language=None, language=None,
**kw # To catch unknown keywords **kw # To catch unknown keywords
): ):
assert type(name) is StringType, "'name' must be a string" assert isinstance(name, basestring), "'name' must be a string"
assert (type(sources) is ListType and assert (type(sources) is ListType and
map(type, sources) == [StringType]*len(sources)), \ all(isinstance(v, basestring) for v in sources)), \
"'sources' must be a list of strings" "'sources' must be a list of strings"
self.name = name self.name = name
......
...@@ -166,13 +166,13 @@ class FancyGetopt: ...@@ -166,13 +166,13 @@ class FancyGetopt:
raise ValueError, "invalid option tuple: %r" % (option,) raise ValueError, "invalid option tuple: %r" % (option,)
# Type- and value-check the option names # Type- and value-check the option names
if type(long) is not StringType or len(long) < 2: if not isinstance(long, basestring) or len(long) < 2:
raise DistutilsGetoptError, \ raise DistutilsGetoptError, \
("invalid long option '%s': " ("invalid long option '%s': "
"must be a string of length >= 2") % long "must be a string of length >= 2") % long
if (not ((short is None) or if (not ((short is None) or
(type(short) is StringType and len(short) == 1))): (isinstance(short, basestring) and len(short) == 1))):
raise DistutilsGetoptError, \ raise DistutilsGetoptError, \
("invalid short option '%s': " ("invalid short option '%s': "
"must a single character or None") % short "must a single character or None") % short
......
...@@ -333,7 +333,7 @@ def translate_pattern (pattern, anchor=1, prefix=None, is_regex=0): ...@@ -333,7 +333,7 @@ def translate_pattern (pattern, anchor=1, prefix=None, is_regex=0):
or just returned as-is (assumes it's a regex object). or just returned as-is (assumes it's a regex object).
""" """
if is_regex: if is_regex:
if type(pattern) is StringType: if isinstance(pattern, basestring):
return re.compile(pattern) return re.compile(pattern)
else: else:
return pattern return pattern
......
...@@ -16,7 +16,7 @@ the "typical" Unix-style command-line C compiler: ...@@ -16,7 +16,7 @@ the "typical" Unix-style command-line C compiler:
__revision__ = "$Id$" __revision__ = "$Id$"
import os, sys import os, sys
from types import StringType, NoneType from types import NoneType
from copy import copy from copy import copy
from distutils import sysconfig from distutils import sysconfig
...@@ -212,7 +212,7 @@ class UnixCCompiler(CCompiler): ...@@ -212,7 +212,7 @@ class UnixCCompiler(CCompiler):
lib_opts = gen_lib_options(self, library_dirs, runtime_library_dirs, lib_opts = gen_lib_options(self, library_dirs, runtime_library_dirs,
libraries) libraries)
if type(output_dir) not in (StringType, NoneType): if not isinstance(output_dir, (basestring, NoneType)):
raise TypeError, "'output_dir' must be a string or None" raise TypeError, "'output_dir' must be a string or None"
if output_dir is not None: if output_dir is not None:
output_filename = os.path.join(output_dir, output_filename) output_filename = os.path.join(output_dir, output_filename)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment