summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/glob.py10
-rw-r--r--Lib/locale.py10
-rw-r--r--Lib/posixpath.py12
-rw-r--r--Lib/test/script_helper.py8
-rw-r--r--Lib/test/test_support.py2
-rw-r--r--Lib/textwrap.py12
-rw-r--r--Lib/unittest/case.py6
7 files changed, 51 insertions, 9 deletions
diff --git a/Lib/glob.py b/Lib/glob.py
index 04364be..d6ddaad 100644
--- a/Lib/glob.py
+++ b/Lib/glob.py
@@ -5,6 +5,14 @@ import os
import re
import fnmatch
+try:
+ _unicode = unicode
+except NameError:
+ # If Python is built without Unicode support, the unicode type
+ # will not exist. Fake one.
+ class _unicode(object):
+ pass
+
__all__ = ["glob", "iglob"]
def glob(pathname):
@@ -49,7 +57,7 @@ def iglob(pathname):
def glob1(dirname, pattern):
if not dirname:
dirname = os.curdir
- if isinstance(pattern, unicode) and not isinstance(dirname, unicode):
+ if isinstance(pattern, _unicode) and not isinstance(dirname, unicode):
dirname = unicode(dirname, sys.getfilesystemencoding() or
sys.getdefaultencoding())
try:
diff --git a/Lib/locale.py b/Lib/locale.py
index 0f60dcc..7ddfdb7 100644
--- a/Lib/locale.py
+++ b/Lib/locale.py
@@ -18,6 +18,14 @@ import re
import operator
import functools
+try:
+ _unicode = unicode
+except NameError:
+ # If Python is built without Unicode support, the unicode type
+ # will not exist. Fake one.
+ class _unicode(object):
+ pass
+
# Try importing the _locale module.
#
# If this fails, fall back on a basic 'C' locale emulation.
@@ -353,7 +361,7 @@ def normalize(localename):
"""
# Normalize the locale name and extract the encoding
- if isinstance(localename, unicode):
+ if isinstance(localename, _unicode):
localename = localename.encode('ascii')
fullname = localename.translate(_ascii_lower_map)
if ':' in fullname:
diff --git a/Lib/posixpath.py b/Lib/posixpath.py
index 163c00c..690c70d 100644
--- a/Lib/posixpath.py
+++ b/Lib/posixpath.py
@@ -17,6 +17,14 @@ import genericpath
import warnings
from genericpath import *
+try:
+ _unicode = unicode
+except NameError:
+ # If Python is built without Unicode support, the unicode type
+ # will not exist. Fake one.
+ class _unicode(object):
+ pass
+
__all__ = ["normcase","isabs","join","splitdrive","split","splitext",
"basename","dirname","commonprefix","getsize","getmtime",
"getatime","getctime","islink","exists","lexists","isdir","isfile",
@@ -312,7 +320,7 @@ def expandvars(path):
def normpath(path):
"""Normalize path, eliminating double slashes, etc."""
# Preserve unicode (if path is unicode)
- slash, dot = (u'/', u'.') if isinstance(path, unicode) else ('/', '.')
+ slash, dot = (u'/', u'.') if isinstance(path, _unicode) else ('/', '.')
if path == '':
return dot
initial_slashes = path.startswith('/')
@@ -341,7 +349,7 @@ def normpath(path):
def abspath(path):
"""Return an absolute path."""
if not isabs(path):
- if isinstance(path, unicode):
+ if isinstance(path, _unicode):
cwd = os.getcwdu()
else:
cwd = os.getcwd()
diff --git a/Lib/test/script_helper.py b/Lib/test/script_helper.py
index 337854a..7f7c70e 100644
--- a/Lib/test/script_helper.py
+++ b/Lib/test/script_helper.py
@@ -10,7 +10,13 @@ import subprocess
import py_compile
import contextlib
import shutil
-import zipfile
+try:
+ import zipfile
+except ImportError:
+ # If Python is build without Unicode support, importing _io will
+ # fail, which, in turn, means that zipfile cannot be imported
+ # Most of this module can then still be used.
+ pass
from test.test_support import strip_python_stderr
diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py
index b0a2048..ae6b44f 100644
--- a/Lib/test/test_support.py
+++ b/Lib/test/test_support.py
@@ -405,7 +405,7 @@ def temp_cwd(name='tempcwd', quiet=False):
the CWD, an error is raised. If it's True, only a warning is raised
and the original CWD is used.
"""
- if isinstance(name, unicode):
+ if have_unicode and isinstance(name, unicode):
try:
name = name.encode(sys.getfilesystemencoding() or 'ascii')
except UnicodeEncodeError:
diff --git a/Lib/textwrap.py b/Lib/textwrap.py
index 9582a1c..62ea0b4 100644
--- a/Lib/textwrap.py
+++ b/Lib/textwrap.py
@@ -9,6 +9,14 @@ __revision__ = "$Id$"
import string, re
+try:
+ _unicode = unicode
+except NameError:
+ # If Python is built without Unicode support, the unicode type
+ # will not exist. Fake one.
+ class _unicode(object):
+ pass
+
# Do the right thing with boolean values for all known Python versions
# (so this module can be copied to projects that don't depend on Python
# 2.3, e.g. Optik and Docutils) by uncommenting the block of code below.
@@ -147,7 +155,7 @@ class TextWrapper:
if self.replace_whitespace:
if isinstance(text, str):
text = text.translate(self.whitespace_trans)
- elif isinstance(text, unicode):
+ elif isinstance(text, _unicode):
text = text.translate(self.unicode_whitespace_trans)
return text
@@ -167,7 +175,7 @@ class TextWrapper:
'use', ' ', 'the', ' ', '-b', ' ', option!'
otherwise.
"""
- if isinstance(text, unicode):
+ if isinstance(text, _unicode):
if self.break_on_hyphens:
pat = self.wordsep_re_uni
else:
diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py
index f334b5b..b3c581a 100644
--- a/Lib/unittest/case.py
+++ b/Lib/unittest/case.py
@@ -202,7 +202,11 @@ class TestCase(object):
self.addTypeEqualityFunc(tuple, 'assertTupleEqual')
self.addTypeEqualityFunc(set, 'assertSetEqual')
self.addTypeEqualityFunc(frozenset, 'assertSetEqual')
- self.addTypeEqualityFunc(unicode, 'assertMultiLineEqual')
+ try:
+ self.addTypeEqualityFunc(unicode, 'assertMultiLineEqual')
+ except NameError:
+ # No unicode support in this build
+ pass
def addTypeEqualityFunc(self, typeobj, function):
"""Add a type specific assertEqual style function to compare a type.