diff -r 4b101df1e9f7 Lib/site.py --- a/Lib/site.py Wed Apr 25 19:55:30 2012 +0200 +++ b/Lib/site.py Fri Apr 27 08:52:20 2012 +0200 @@ -560,7 +560,31 @@ if hasattr(sys, "setdefaultencoding"): del sys.setdefaultencoding -main() +try: + unicode +except NameError: + # If Python is built with no unicode support, we need to patch a + # few modules where unicode is used only in isinstance clauses. + class unicode(object): + def __new__(cls, *args, **kw): + # Make sure that you cannot instantiate instances + raise TypeError("No unicode support") + # We do not want to pollute the __builtin__ names space, so we + # inject this unicode class directly into the modules that need it + def _patch_modules(*modnames): + for n in modnames: + try: + __import__(n) + m = sys.modules[n] + except ImportError: + pass + else: + setattr(m, 'unicode', unicode) + _patch_modules('posixpath', 'glob') + main() + _patch_modules('locale', 'textwrap', 'unittest.case') +else: + main() def _script(): help = """\ diff -r 4b101df1e9f7 Lib/test/script_helper.py --- a/Lib/test/script_helper.py Wed Apr 25 19:55:30 2012 +0200 +++ b/Lib/test/script_helper.py Fri Apr 27 08:52:20 2012 +0200 @@ -10,7 +10,10 @@ import py_compile import contextlib import shutil -import zipfile +try: + import zipfile +except: + pass from test.test_support import strip_python_stderr diff -r 4b101df1e9f7 Lib/test/test_support.py --- a/Lib/test/test_support.py Wed Apr 25 19:55:30 2012 +0200 +++ b/Lib/test/test_support.py Fri Apr 27 08:52:20 2012 +0200 @@ -405,7 +405,7 @@ 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 -r 4b101df1e9f7 Misc/ACKS --- a/Misc/ACKS Wed Apr 25 19:55:30 2012 +0200 +++ b/Misc/ACKS Fri Apr 27 08:52:20 2012 +0200 @@ -833,6 +833,7 @@ Geoff Talvola William Tanksley Christian Tanzer +Stefano Taschini Steven Taschuk Monty Taylor Amy Taylor diff -r 4b101df1e9f7 Objects/object.c --- a/Objects/object.c Wed Apr 25 19:55:30 2012 +0200 +++ b/Objects/object.c Fri Apr 27 08:52:20 2012 +0200 @@ -2111,8 +2111,10 @@ 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"); diff -r 4b101df1e9f7 Python/bltinmodule.c --- a/Python/bltinmodule.c Wed Apr 25 19:55:30 2012 +0200 +++ b/Python/bltinmodule.c Fri Apr 27 08:52:20 2012 +0200 @@ -1578,6 +1578,7 @@ 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 @@ Py_CLEAR(unicode_space); return NULL; } +#endif } if (!PyArg_ParseTupleAndKeywords(dummy_args, kwds, "|OOO:print", kwlist, &sep, &end, &file)) diff -r 4b101df1e9f7 Python/peephole.c --- a/Python/peephole.c Wed Apr 25 19:55:30 2012 +0200 +++ b/Python/peephole.c Fri Apr 27 08:52:20 2012 +0200 @@ -135,6 +135,7 @@ 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 @@ return 0; } } +#endif break; case BINARY_LSHIFT: newconst = PyNumber_Lshift(v, w); diff -r 4b101df1e9f7 configure --- a/configure Wed Apr 25 19:55:30 2012 +0200 +++ b/configure Fri Apr 27 08:52:20 2012 +0200 @@ -12522,6 +12522,7 @@ $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 diff -r 4b101df1e9f7 configure.ac --- a/configure.ac Wed Apr 25 19:55:30 2012 +0200 +++ b/configure.ac Fri Apr 27 08:52:20 2012 +0200 @@ -3776,6 +3776,7 @@ 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