]> granicus.if.org Git - python/commitdiff
Issue #8767: Restore building with --disable-unicode.
authorMartin v. Löwis <martin@v.loewis.de>
Sun, 20 May 2012 08:42:17 +0000 (10:42 +0200)
committerMartin v. Löwis <martin@v.loewis.de>
Sun, 20 May 2012 08:42:17 +0000 (10:42 +0200)
Original patch by Stefano Taschini.

14 files changed:
Lib/glob.py
Lib/locale.py
Lib/posixpath.py
Lib/test/script_helper.py
Lib/test/test_support.py
Lib/textwrap.py
Lib/unittest/case.py
Misc/ACKS
Misc/NEWS
Objects/object.c
Python/bltinmodule.c
Python/peephole.c
configure
configure.ac

index 04364be7dfb7898def3c7464bef57e59d2d023dd..d6ddaadc90de33d4c855ff132e5009cdf96fca3c 100644 (file)
@@ -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:
index 0f60dcc654e1fe8e67d4ea7e37c23478ae9235b5..7ddfdb782c0d0945413ddbfebe2fd34975a896ec 100644 (file)
@@ -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:
index 163c00c445ca1233165ef124c2b2cf7ee701a73d..690c70da374b660517d656ad45ae17f15da3a4bb 100644 (file)
@@ -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()
index 337854af55898fe86808adc35b71980b2a3ae327..7f7c70ea06751e81365e722c74dd132ecd4e76bc 100644 (file)
@@ -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
 
index b0a2048c8daeceeb7ca7b6b42f9749cd88523c21..ae6b44f79526b66e3e35d3871813357865d11108 100644 (file)
@@ -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:
index 9582a1c02f5c39e85bf1b8addf3f947ea7b0dde7..62ea0b48e6c18955c08a43805067c072387fee61 100644 (file)
@@ -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:
index f334b5b71d1d6960526843bf494607222c298e13..b3c581a6eaaa01d5104ae77600cc518a726d8498 100644 (file)
@@ -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.
index 2844dfac98557ecb26ccff6f39b45825edc35833..9908bb1e3fff613f24d1e025df0efbabb973beb2 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -839,6 +839,7 @@ Arfrever Frehtes Taifersar Arahesis
 Geoff Talvola
 William Tanksley
 Christian Tanzer
+Stefano Taschini
 Steven Taschuk
 Monty Taylor
 Amy Taylor
index 34c5e47d85e238c4e27ec6a7c898c934cc64b297..d9faea53bad8682124f5f10920c4d112121bedf8 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -191,6 +191,9 @@ Tests
 Build
 -----
 
+- Issue #8767: Restore building with --disable-unicode.
+  Patch by Stefano Taschini.
+
 - Build against bzip2 1.0.6 and openssl 0.9.8x on Windows.
 
 - Issue #14557: Fix extensions build on HP-UX. Patch by Adi Roiban.
index 93030863d554a2aafd33b93ece48cc5dcffd3aa9..f1902a7e03964004c39ec4274732355db576d91f 100644 (file)
@@ -2111,8 +2111,10 @@ _Py_ReadyTypes(void)
     if (PyType_Ready(&PySet_Type) < 0)
         Py_FatalError("Can't initialize set type");
 
+#ifdef Py_USING_UNICODE
     if (PyType_Ready(&PyUnicode_Type) < 0)
         Py_FatalError("Can't initialize unicode type");
+#endif
 
     if (PyType_Ready(&PySlice_Type) < 0)
         Py_FatalError("Can't initialize slice type");
index c25588a45e2261668db2bfb5891ae8cbde6d42de..373f8706245c8133b64752089a07936a02ee026d 100644 (file)
@@ -1578,6 +1578,7 @@ builtin_print(PyObject *self, PyObject *args, PyObject *kwds)
             Py_CLEAR(str_newline);
             return NULL;
         }
+#ifdef Py_USING_UNICODE
         unicode_newline = PyUnicode_FromString("\n");
         if (unicode_newline == NULL) {
             Py_CLEAR(str_newline);
@@ -1591,6 +1592,7 @@ builtin_print(PyObject *self, PyObject *args, PyObject *kwds)
             Py_CLEAR(unicode_space);
             return NULL;
         }
+#endif
     }
     if (!PyArg_ParseTupleAndKeywords(dummy_args, kwds, "|OOO:print",
                                      kwlist, &sep, &end, &file))
index 433fe27d0e93ecb55090d03548cf31cc9fda58ac..7521b9ce218308907fedd50c9743d7c5f64b17a6 100644 (file)
@@ -135,6 +135,7 @@ fold_binops_on_constants(unsigned char *codestr, PyObject *consts)
                will return a surrogate.  In both the cases skip the
                optimization in order to produce compatible pycs.
              */
+#ifdef Py_USING_UNICODE
             if (newconst != NULL &&
                 PyUnicode_Check(v) && PyUnicode_Check(newconst)) {
                 Py_UNICODE ch = PyUnicode_AS_UNICODE(newconst)[0];
@@ -147,6 +148,7 @@ fold_binops_on_constants(unsigned char *codestr, PyObject *consts)
                     return 0;
                 }
             }
+#endif
             break;
         case BINARY_LSHIFT:
             newconst = PyNumber_Lshift(v, w);
index 25c4acf8bb55feeab2ac04bae357091904b4e1dc..9d58c1732b2a127e29d7dd2dda1ea6d4ea53a689 100755 (executable)
--- a/configure
+++ b/configure
@@ -12522,6 +12522,7 @@ ucs4) unicode_size="4"
       $as_echo "#define Py_UNICODE_SIZE 4" >>confdefs.h
 
       ;;
+no)   ;;      # To allow --disable-unicode
 *) as_fn_error $? "invalid value for --enable-unicode. Use either ucs2 or ucs4 (lowercase)." "$LINENO" 5 ;;
 esac
 
index 3f5b3b948fff431a97ec3a48f7e0d3aaf35ffabb..9a1eb5dfd59baaf6449a86072eb3d6e344fb36e3 100644 (file)
@@ -3776,6 +3776,7 @@ ucs2) unicode_size="2"
 ucs4) unicode_size="4"
       AC_DEFINE(Py_UNICODE_SIZE,4)
       ;;
+no)   ;;      # To allow --disable-unicode
 *) AC_MSG_ERROR([invalid value for --enable-unicode. Use either ucs2 or ucs4 (lowercase).]) ;;
 esac