Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 572dbf8

Browse files
committed
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.
1 parent d4617f2 commit 572dbf8

28 files changed

Lines changed: 68 additions & 81 deletions

Include/pydebug.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ PyAPI_DATA(int) Py_NoSiteFlag;
1414
PyAPI_DATA(int) Py_UseClassExceptionsFlag;
1515
PyAPI_DATA(int) Py_FrozenFlag;
1616
PyAPI_DATA(int) Py_TabcheckFlag;
17-
PyAPI_DATA(int) Py_UnicodeFlag;
1817
PyAPI_DATA(int) Py_IgnoreEnvironmentFlag;
1918
PyAPI_DATA(int) Py_DivisionWarningFlag;
2019

Lib/distutils/ccompiler.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class (via the 'executables' class attribute), but most will have:
168168
# set_executables ()
169169

170170
def set_executable(self, key, value):
171-
if type(value) is StringType:
171+
if isinstance(value, basestring):
172172
setattr(self, key, split_quoted(value))
173173
else:
174174
setattr(self, key, value)
@@ -193,8 +193,8 @@ def _check_macro_definitions (self, definitions):
193193
if not (type (defn) is TupleType and
194194
(len (defn) == 1 or
195195
(len (defn) == 2 and
196-
(type (defn[1]) is StringType or defn[1] is None))) and
197-
type (defn[0]) is StringType):
196+
(isinstance (defn[1], basestring) or defn[1] is None))) and
197+
isinstance (defn[0], basestring)):
198198
raise TypeError, \
199199
("invalid macro definition '%s': " % defn) + \
200200
"must be tuple (string,), (string, string), or " + \
@@ -344,7 +344,7 @@ def _setup_compile(self, outdir, macros, incdirs, sources, depends,
344344
"""
345345
if outdir is None:
346346
outdir = self.output_dir
347-
elif type(outdir) is not StringType:
347+
elif not isinstance(outdir, basestring):
348348
raise TypeError, "'output_dir' must be a string or None"
349349

350350
if macros is None:
@@ -442,7 +442,7 @@ def _fix_compile_args (self, output_dir, macros, include_dirs):
442442
"""
443443
if output_dir is None:
444444
output_dir = self.output_dir
445-
elif type (output_dir) is not StringType:
445+
elif not isinstance(output_dir, basestring):
446446
raise TypeError, "'output_dir' must be a string or None"
447447

448448
if macros is None:
@@ -527,7 +527,7 @@ def _fix_object_args (self, objects, output_dir):
527527

528528
if output_dir is None:
529529
output_dir = self.output_dir
530-
elif type (output_dir) is not StringType:
530+
elif not isinstance(output_dir, basestring):
531531
raise TypeError, "'output_dir' must be a string or None"
532532

533533
return (objects, output_dir)

Lib/distutils/cmd.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def _ensure_stringlike (self, option, what, default=None):
222222
if val is None:
223223
setattr(self, option, default)
224224
return default
225-
elif type(val) is not StringType:
225+
elif not isinstance(val, basestring):
226226
raise DistutilsOptionError, \
227227
"'%s' must be a %s (got `%s`)" % (option, what, val)
228228
return val
@@ -242,12 +242,11 @@ def ensure_string_list (self, option):
242242
val = getattr(self, option)
243243
if val is None:
244244
return
245-
elif type(val) is StringType:
245+
elif isinstance(val, basestring):
246246
setattr(self, option, re.split(r',\s*|\s+', val))
247247
else:
248248
if type(val) is ListType:
249-
types = map(type, val)
250-
ok = (types == [StringType] * len(val))
249+
ok = all(isinstance(v, basestring) for v in val)
251250
else:
252251
ok = 0
253252

@@ -421,7 +420,7 @@ def make_file (self, infiles, outfile, func, args,
421420

422421

423422
# Allow 'infiles' to be a single string
424-
if type(infiles) is StringType:
423+
if isinstance(infiles, basestring):
425424
infiles = (infiles,)
426425
elif type(infiles) not in (ListType, TupleType):
427426
raise TypeError, \

Lib/distutils/command/build_clib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def finalize_options (self):
9292

9393
if self.include_dirs is None:
9494
self.include_dirs = self.distribution.include_dirs or []
95-
if type(self.include_dirs) is StringType:
95+
if isinstance(self.include_dirs, basestring):
9696
self.include_dirs = self.include_dirs.split(os.pathsep)
9797

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

150-
if type(lib[0]) is not StringType:
150+
if isinstance(lib[0], basestring) StringType:
151151
raise DistutilsSetupError, \
152152
"first element of each tuple in 'libraries' " + \
153153
"must be a string (the library name)"

Lib/distutils/command/build_ext.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def finalize_options (self):
137137
plat_py_include = sysconfig.get_python_inc(plat_specific=1)
138138
if self.include_dirs is None:
139139
self.include_dirs = self.distribution.include_dirs or []
140-
if type(self.include_dirs) is StringType:
140+
if isinstance(self.include_dirs, basestring):
141141
self.include_dirs = self.include_dirs.split(os.pathsep)
142142

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

149-
if type(self.libraries) is StringType:
149+
if isinstance(self.libraries, basestring):
150150
self.libraries = [self.libraries]
151151

152152
# Life is easier if we're not forever checking for None, so
@@ -155,12 +155,12 @@ def finalize_options (self):
155155
self.libraries = []
156156
if self.library_dirs is None:
157157
self.library_dirs = []
158-
elif type(self.library_dirs) is StringType:
158+
elif isinstance(self.library_dirs, basestring):
159159
self.library_dirs = self.library_dirs.split(os.pathsep)
160160

161161
if self.rpath is None:
162162
self.rpath = []
163-
elif type(self.rpath) is StringType:
163+
elif isinstance(self.rpath, basestring):
164164
self.rpath = self.rpath.split(os.pathsep)
165165

166166
# for extensions under windows use different directories
@@ -321,7 +321,7 @@ def check_extensions_list (self, extensions):
321321
("each element of 'ext_modules' option must be an "
322322
"Extension instance or 2-tuple")
323323

324-
if not (type(ext_name) is StringType and
324+
if not (isinstance(ext_name, basestring) and
325325
extension_name_re.match(ext_name)):
326326
raise DistutilsSetupError, \
327327
("first element of each tuple in 'ext_modules' "

Lib/distutils/command/build_py.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ def get_outputs (self, include_bytecode=1):
361361

362362

363363
def build_module (self, module, module_file, package):
364-
if type(package) is StringType:
364+
if isinstance(package, basestring):
365365
package = package.split('.')
366366
elif type(package) not in (ListType, TupleType):
367367
raise TypeError, \

Lib/distutils/command/config.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,17 @@ def initialize_options (self):
7373
def finalize_options (self):
7474
if self.include_dirs is None:
7575
self.include_dirs = self.distribution.include_dirs or []
76-
elif type(self.include_dirs) is StringType:
76+
elif isinstance(self.include_dirs, basestring):
7777
self.include_dirs = self.include_dirs.split(os.pathsep)
7878

7979
if self.libraries is None:
8080
self.libraries = []
81-
elif type(self.libraries) is StringType:
81+
elif isinstance(self.libraries, basestring):
8282
self.libraries = [self.libraries]
8383

8484
if self.library_dirs is None:
8585
self.library_dirs = []
86-
elif type(self.library_dirs) is StringType:
86+
elif isinstance(self.library_dirs, basestring):
8787
self.library_dirs = self.library_dirs.split(os.pathsep)
8888

8989

@@ -212,7 +212,7 @@ def search_cpp (self, pattern, body=None,
212212
self._check_compiler()
213213
(src, out) = self._preprocess(body, headers, include_dirs, lang)
214214

215-
if type(pattern) is StringType:
215+
if isinstance(pattern, basestring):
216216
pattern = re.compile(pattern)
217217

218218
file = open(out)

Lib/distutils/command/install.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ def handle_extra_path (self):
463463
self.extra_path = self.distribution.extra_path
464464

465465
if self.extra_path is not None:
466-
if type(self.extra_path) is StringType:
466+
if isinstance(self.extra_path, basestring):
467467
self.extra_path = self.extra_path.split(',')
468468

469469
if len(self.extra_path) == 1:

Lib/distutils/command/install_data.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
__revision__ = "$Id$"
1111

1212
import os
13-
from types import StringType
1413
from distutils.core import Command
1514
from distutils.util import change_root, convert_path
1615

@@ -48,7 +47,7 @@ def finalize_options (self):
4847
def run (self):
4948
self.mkpath(self.install_dir)
5049
for f in self.data_files:
51-
if type(f) is StringType:
50+
if isinstance(f, basestring):
5251
# it's a simple file, so copy it
5352
f = convert_path(f)
5453
if self.warn_dir:

Lib/distutils/dir_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def mkpath (name, mode=0777, verbose=0, dry_run=0):
3131
global _path_created
3232

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

0 commit comments

Comments
 (0)