Skip to content

Commit

Permalink
Checkpoint. Manipulated things so that string literals are always
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gvanrossum committed Apr 27, 2007
1 parent d4617f2 commit 572dbf8
Show file tree
Hide file tree
Showing 28 changed files with 68 additions and 81 deletions.
1 change: 0 additions & 1 deletion Include/pydebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ PyAPI_DATA(int) Py_NoSiteFlag;
PyAPI_DATA(int) Py_UseClassExceptionsFlag;
PyAPI_DATA(int) Py_FrozenFlag;
PyAPI_DATA(int) Py_TabcheckFlag;
PyAPI_DATA(int) Py_UnicodeFlag;
PyAPI_DATA(int) Py_IgnoreEnvironmentFlag;
PyAPI_DATA(int) Py_DivisionWarningFlag;

Expand Down
12 changes: 6 additions & 6 deletions Lib/distutils/ccompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class (via the 'executables' class attribute), but most will have:
# set_executables ()

def set_executable(self, key, value):
if type(value) is StringType:
if isinstance(value, basestring):
setattr(self, key, split_quoted(value))
else:
setattr(self, key, value)
Expand All @@ -193,8 +193,8 @@ def _check_macro_definitions (self, definitions):
if not (type (defn) is TupleType and
(len (defn) == 1 or
(len (defn) == 2 and
(type (defn[1]) is StringType or defn[1] is None))) and
type (defn[0]) is StringType):
(isinstance (defn[1], basestring) or defn[1] is None))) and
isinstance (defn[0], basestring)):
raise TypeError, \
("invalid macro definition '%s': " % defn) + \
"must be tuple (string,), (string, string), or " + \
Expand Down Expand Up @@ -344,7 +344,7 @@ def _setup_compile(self, outdir, macros, incdirs, sources, depends,
"""
if outdir is None:
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"

if macros is None:
Expand Down Expand Up @@ -442,7 +442,7 @@ def _fix_compile_args (self, output_dir, macros, include_dirs):
"""
if output_dir is None:
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"

if macros is None:
Expand Down Expand Up @@ -527,7 +527,7 @@ def _fix_object_args (self, objects, output_dir):

if output_dir is None:
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"

return (objects, output_dir)
Expand Down
9 changes: 4 additions & 5 deletions Lib/distutils/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def _ensure_stringlike (self, option, what, default=None):
if val is None:
setattr(self, option, default)
return default
elif type(val) is not StringType:
elif not isinstance(val, basestring):
raise DistutilsOptionError, \
"'%s' must be a %s (got `%s`)" % (option, what, val)
return val
Expand All @@ -242,12 +242,11 @@ def ensure_string_list (self, option):
val = getattr(self, option)
if val is None:
return
elif type(val) is StringType:
elif isinstance(val, basestring):
setattr(self, option, re.split(r',\s*|\s+', val))
else:
if type(val) is ListType:
types = map(type, val)
ok = (types == [StringType] * len(val))
ok = all(isinstance(v, basestring) for v in val)
else:
ok = 0

Expand Down Expand Up @@ -421,7 +420,7 @@ def make_file (self, infiles, outfile, func, args,


# Allow 'infiles' to be a single string
if type(infiles) is StringType:
if isinstance(infiles, basestring):
infiles = (infiles,)
elif type(infiles) not in (ListType, TupleType):
raise TypeError, \
Expand Down
4 changes: 2 additions & 2 deletions Lib/distutils/command/build_clib.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def finalize_options (self):

if self.include_dirs is None:
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)

# XXX same as for build_ext -- what about 'self.define' and
Expand Down Expand Up @@ -147,7 +147,7 @@ def check_library_list (self, libraries):
raise DistutilsSetupError, \
"each element of 'libraries' must a 2-tuple"

if type(lib[0]) is not StringType:
if isinstance(lib[0], basestring) StringType:
raise DistutilsSetupError, \
"first element of each tuple in 'libraries' " + \
"must be a string (the library name)"
Expand Down
10 changes: 5 additions & 5 deletions Lib/distutils/command/build_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def finalize_options (self):
plat_py_include = sysconfig.get_python_inc(plat_specific=1)
if self.include_dirs is None:
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)

# Put the Python "system" include dir at the end, so that
Expand All @@ -146,7 +146,7 @@ def finalize_options (self):
if plat_py_include != py_include:
self.include_dirs.append(plat_py_include)

if type(self.libraries) is StringType:
if isinstance(self.libraries, basestring):
self.libraries = [self.libraries]

# Life is easier if we're not forever checking for None, so
Expand All @@ -155,12 +155,12 @@ def finalize_options (self):
self.libraries = []
if self.library_dirs is None:
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)

if self.rpath is None:
self.rpath = []
elif type(self.rpath) is StringType:
elif isinstance(self.rpath, basestring):
self.rpath = self.rpath.split(os.pathsep)

# for extensions under windows use different directories
Expand Down Expand Up @@ -321,7 +321,7 @@ def check_extensions_list (self, extensions):
("each element of 'ext_modules' option must be an "
"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)):
raise DistutilsSetupError, \
("first element of each tuple in 'ext_modules' "
Expand Down
2 changes: 1 addition & 1 deletion Lib/distutils/command/build_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def get_outputs (self, include_bytecode=1):


def build_module (self, module, module_file, package):
if type(package) is StringType:
if isinstance(package, basestring):
package = package.split('.')
elif type(package) not in (ListType, TupleType):
raise TypeError, \
Expand Down
8 changes: 4 additions & 4 deletions Lib/distutils/command/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,17 @@ def initialize_options (self):
def finalize_options (self):
if self.include_dirs is None:
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)

if self.libraries is None:
self.libraries = []
elif type(self.libraries) is StringType:
elif isinstance(self.libraries, basestring):
self.libraries = [self.libraries]

if self.library_dirs is None:
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)


Expand Down Expand Up @@ -212,7 +212,7 @@ def search_cpp (self, pattern, body=None,
self._check_compiler()
(src, out) = self._preprocess(body, headers, include_dirs, lang)

if type(pattern) is StringType:
if isinstance(pattern, basestring):
pattern = re.compile(pattern)

file = open(out)
Expand Down
2 changes: 1 addition & 1 deletion Lib/distutils/command/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ def handle_extra_path (self):
self.extra_path = self.distribution.extra_path

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(',')

if len(self.extra_path) == 1:
Expand Down
3 changes: 1 addition & 2 deletions Lib/distutils/command/install_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
__revision__ = "$Id$"

import os
from types import StringType
from distutils.core import Command
from distutils.util import change_root, convert_path

Expand Down Expand Up @@ -48,7 +47,7 @@ def finalize_options (self):
def run (self):
self.mkpath(self.install_dir)
for f in self.data_files:
if type(f) is StringType:
if isinstance(f, basestring):
# it's a simple file, so copy it
f = convert_path(f)
if self.warn_dir:
Expand Down
2 changes: 1 addition & 1 deletion Lib/distutils/dir_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def mkpath (name, mode=0777, verbose=0, dry_run=0):
global _path_created

# Detect a common bug -- name is None
if not isinstance(name, StringTypes):
if not isinstance(name, basestring):
raise DistutilsInternalError, \
"mkpath: 'name' must be a string (got %r)" % (name,)

Expand Down
6 changes: 3 additions & 3 deletions Lib/distutils/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,13 +598,13 @@ def finalize_options (self):

keywords = self.metadata.keywords
if keywords is not None:
if type(keywords) is StringType:
if isinstance(keywords, basestring):
keywordlist = keywords.split(',')
self.metadata.keywords = [x.strip() for x in keywordlist]

platforms = self.metadata.platforms
if platforms is not None:
if type(platforms) is StringType:
if isinstance(platforms, basestring):
platformlist = platforms.split(',')
self.metadata.platforms = [x.strip() for x in platformlist]

Expand Down Expand Up @@ -906,7 +906,7 @@ def _set_command_options (self, command_obj, option_dict=None):
neg_opt = {}

try:
is_string = type(value) is StringType
is_string = isinstance(value, basestring)
if option in neg_opt and is_string:
setattr(command_obj, neg_opt[option], not strtobool(value))
elif option in bool_opts and is_string:
Expand Down
4 changes: 2 additions & 2 deletions Lib/distutils/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ def __init__ (self, name, sources,
language=None,
**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
map(type, sources) == [StringType]*len(sources)), \
all(isinstance(v, basestring) for v in sources)), \
"'sources' must be a list of strings"

self.name = name
Expand Down
4 changes: 2 additions & 2 deletions Lib/distutils/fancy_getopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,13 @@ def _grok_option_table (self):
raise ValueError, "invalid option tuple: %r" % (option,)

# 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, \
("invalid long option '%s': "
"must be a string of length >= 2") % long

if (not ((short is None) or
(type(short) is StringType and len(short) == 1))):
(isinstance(short, basestring) and len(short) == 1))):
raise DistutilsGetoptError, \
("invalid short option '%s': "
"must a single character or None") % short
Expand Down
2 changes: 1 addition & 1 deletion Lib/distutils/filelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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).
"""
if is_regex:
if type(pattern) is StringType:
if isinstance(pattern, basestring):
return re.compile(pattern)
else:
return pattern
Expand Down
4 changes: 2 additions & 2 deletions Lib/distutils/unixccompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
__revision__ = "$Id$"

import os, sys
from types import StringType, NoneType
from types import NoneType
from copy import copy

from distutils import sysconfig
Expand Down Expand Up @@ -212,7 +212,7 @@ def link(self, target_desc, objects,

lib_opts = gen_lib_options(self, library_dirs, runtime_library_dirs,
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"
if output_dir is not None:
output_filename = os.path.join(output_dir, output_filename)
Expand Down
2 changes: 1 addition & 1 deletion Lib/locale.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ def setlocale(category, locale=None):
category may be given as one of the LC_* values.
"""
if locale and type(locale) is not type(""):
if locale and not isinstance(locale, basestring):
# convert to string
locale = normalize(_build_localename(locale))
return _setlocale(category, locale)
Expand Down
8 changes: 4 additions & 4 deletions Lib/os.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,8 +733,8 @@ def urandom(n):
_urandomfd = open("/dev/urandom", O_RDONLY)
except (OSError, IOError):
raise NotImplementedError("/dev/urandom (or equivalent) not found")
bytes = ""
while len(bytes) < n:
bytes += read(_urandomfd, n - len(bytes))
bs = b""
while len(bs) < n:
bs += read(_urandomfd, n - len(bs))
close(_urandomfd)
return bytes
return bs
12 changes: 1 addition & 11 deletions Lib/sre_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,18 +470,8 @@ def _compile_info(code, pattern, flags):
_compile_charset(charset, flags, code)
code[skip] = len(code) - skip

try:
unicode
except NameError:
STRING_TYPES = (type(""),)
else:
STRING_TYPES = (type(""), type(unicode("")))

def isstring(obj):
for tp in STRING_TYPES:
if isinstance(obj, tp):
return 1
return 0
return isinstance(obj, basestring)

def _code(p, flags):

Expand Down
Loading

0 comments on commit 572dbf8

Please sign in to comment.