Patch #445762: Support --disable-unicode
- Do not compile unicodeobject, unicodectype, and unicodedata if Unicode is disabled
- check for Py_USING_UNICODE in all places that use Unicode functions
- disables unicode literals, and the builtin functions
- add the types.StringTypes list
- remove Unicode literals from most tests.
diff --git a/Objects/abstract.c b/Objects/abstract.c
index b646c36..f7ade6d 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -583,8 +583,10 @@
 {
 	if (PyString_Check(v))
 		return PyString_Format(v, w);
+#ifdef Py_USING_UNICODE
 	else if (PyUnicode_Check(v))
 		return PyUnicode_Format(v, w);
+#endif
 	return binary_op(v, w, NB_SLOT(nb_remainder), "%");
 }
 
@@ -707,8 +709,10 @@
 {
 	if (PyString_Check(v))
 		return PyString_Format(v, w);
+#ifdef Py_USING_UNICODE
 	else if (PyUnicode_Check(v))
 		return PyUnicode_Format(v, w);
+#endif
 	else
 		return binary_iop(v, w, NB_SLOT(nb_inplace_remainder),
 					NB_SLOT(nb_remainder), "%=");
@@ -821,10 +825,12 @@
 	if (PyString_Check(o))
 		return int_from_string(PyString_AS_STRING(o), 
 				       PyString_GET_SIZE(o));
+#ifdef Py_USING_UNICODE
 	if (PyUnicode_Check(o))
 		return PyInt_FromUnicode(PyUnicode_AS_UNICODE(o),
 					 PyUnicode_GET_SIZE(o),
 					 10);
+#endif
 	m = o->ob_type->tp_as_number;
 	if (m && m->nb_int)
 		return m->nb_int(o);
@@ -873,11 +879,13 @@
 		 */
 		return long_from_string(PyString_AS_STRING(o),
 					PyString_GET_SIZE(o));
+#ifdef Py_USING_UNICODE
 	if (PyUnicode_Check(o))
 		/* The above check is done in PyLong_FromUnicode(). */
 		return PyLong_FromUnicode(PyUnicode_AS_UNICODE(o),
 					  PyUnicode_GET_SIZE(o),
 					  10);
+#endif
 	m = o->ob_type->tp_as_number;
 	if (m && m->nb_long)
 		return m->nb_long(o);
diff --git a/Objects/complexobject.c b/Objects/complexobject.c
index 84eee11..cb081aa 100644
--- a/Objects/complexobject.c
+++ b/Objects/complexobject.c
@@ -611,14 +611,15 @@
 	int sw_error=0;
 	int sign;
 	char buffer[256]; /* For errors */
-	char s_buffer[256];
 	int len;
 
 	if (PyString_Check(v)) {
 		s = PyString_AS_STRING(v);
 		len = PyString_GET_SIZE(v);
 	}
+#ifdef Py_USING_UNICODE
 	else if (PyUnicode_Check(v)) {
+	    	char s_buffer[256];
 		if (PyUnicode_GET_SIZE(v) >= sizeof(s_buffer)) {
 			PyErr_SetString(PyExc_ValueError,
 				 "complex() literal too large to convert");
@@ -632,6 +633,7 @@
 		s = s_buffer;
 		len = (int)strlen(s);
 	}
+#endif
 	else if (PyObject_AsCharBuffer(v, &s, &len)) {
 		PyErr_SetString(PyExc_TypeError,
 				"complex() arg is not a string");
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 34b252b..044d1d3 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -109,7 +109,9 @@
 	const char *s, *last, *end;
 	double x;
 	char buffer[256]; /* for errors */
+#ifdef Py_USING_UNICODE
 	char s_buffer[256]; /* for objects convertible to a char buffer */
+#endif
 	int len;
 
 	if (pend)
@@ -118,6 +120,7 @@
 		s = PyString_AS_STRING(v);
 		len = PyString_GET_SIZE(v);
 	}
+#ifdef Py_USING_UNICODE
 	else if (PyUnicode_Check(v)) {
 		if (PyUnicode_GET_SIZE(v) >= sizeof(s_buffer)) {
 			PyErr_SetString(PyExc_ValueError,
@@ -132,6 +135,7 @@
 		s = s_buffer;
 		len = (int)strlen(s);
 	}
+#endif
 	else if (PyObject_AsCharBuffer(v, &s, &len)) {
 		PyErr_SetString(PyExc_TypeError,
 				"float() needs a string argument");
diff --git a/Objects/intobject.c b/Objects/intobject.c
index f69f81a..e7f618b 100644
--- a/Objects/intobject.c
+++ b/Objects/intobject.c
@@ -202,6 +202,7 @@
 	return PyInt_FromLong(x);
 }
 
+#ifdef Py_USING_UNICODE
 PyObject *
 PyInt_FromUnicode(Py_UNICODE *s, int length, int base)
 {
@@ -216,6 +217,7 @@
 		return NULL;
 	return PyInt_FromString(buffer, NULL, base);
 }
+#endif
 
 /* Methods */
 
@@ -765,10 +767,12 @@
 		return PyNumber_Int(x);
 	if (PyString_Check(x))
 		return PyInt_FromString(PyString_AS_STRING(x), NULL, base);
+#ifdef Py_USING_UNICODE
 	if (PyUnicode_Check(x))
 		return PyInt_FromUnicode(PyUnicode_AS_UNICODE(x),
 					 PyUnicode_GET_SIZE(x),
 					 base);
+#endif
 	PyErr_SetString(PyExc_TypeError,
 			"int() can't convert non-string with explicit base");
 	return NULL;
diff --git a/Objects/longobject.c b/Objects/longobject.c
index 9f7272c..01a7276 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -971,6 +971,7 @@
 	return NULL;
 }
 
+#ifdef Py_USING_UNICODE
 PyObject *
 PyLong_FromUnicode(Py_UNICODE *u, int length, int base)
 {
@@ -986,6 +987,7 @@
 
 	return PyLong_FromString(buffer, NULL, base);
 }
+#endif
 
 /* forward */
 static PyLongObject *x_divrem
@@ -2054,10 +2056,12 @@
 		return PyNumber_Long(x);
 	else if (PyString_Check(x))
 		return PyLong_FromString(PyString_AS_STRING(x), NULL, base);
+#ifdef Py_USING_UNICODE
 	else if (PyUnicode_Check(x))
 		return PyLong_FromUnicode(PyUnicode_AS_UNICODE(x),
 					  PyUnicode_GET_SIZE(x),
 					  base);
+#endif
 	else {
 		PyErr_SetString(PyExc_TypeError,
 			"long() can't convert non-string with explicit base");
diff --git a/Objects/object.c b/Objects/object.c
index fea9ee5..7e4a211 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -246,6 +246,7 @@
 		res = (*v->ob_type->tp_repr)(v);
 		if (res == NULL)
 			return NULL;
+#ifdef Py_USING_UNICODE
 		if (PyUnicode_Check(res)) {
 			PyObject* str;
 			str = PyUnicode_AsUnicodeEscapeString(res);
@@ -255,6 +256,7 @@
 			else
 				return NULL;
 		}
+#endif
 		if (!PyString_Check(res)) {
 			PyErr_Format(PyExc_TypeError,
 				     "__repr__ returned non-string (type %.200s)",
@@ -283,6 +285,7 @@
 	res = (*v->ob_type->tp_str)(v);
 	if (res == NULL)
 		return NULL;
+#ifdef Py_USING_UNICODE
 	if (PyUnicode_Check(res)) {
 		PyObject* str;
 		str = PyUnicode_AsEncodedString(res, NULL, NULL);
@@ -292,6 +295,7 @@
 		else
 		    	return NULL;
 	}
+#endif
 	if (!PyString_Check(res)) {
 		PyErr_Format(PyExc_TypeError,
 			     "__str__ returned non-string (type %.200s)",
@@ -302,6 +306,7 @@
 	return res;
 }
 
+#ifdef Py_USING_UNICODE
 PyObject *
 PyObject_Unicode(PyObject *v)
 {
@@ -350,6 +355,7 @@
 	}
 	return res;
 }
+#endif
 
 
 /* Macro to get the tp_richcompare field of a type if defined */
@@ -523,6 +529,7 @@
 		return (vv < ww) ? -1 : (vv > ww) ? 1 : 0;
 	}
 
+#ifdef Py_USING_UNICODE
 	/* Special case for Unicode */
 	if (PyUnicode_Check(v) || PyUnicode_Check(w)) {
 		c = PyUnicode_Compare(v, w);
@@ -537,6 +544,7 @@
 			return -2;
 		PyErr_Clear();
 	}
+#endif
 
 	/* None is smaller than anything */
 	if (v == Py_None)
@@ -1032,6 +1040,7 @@
 {
 	PyTypeObject *tp = v->ob_type;
 
+#ifdef Py_USING_UNICODE
 	/* The Unicode to string conversion is done here because the
 	   existing tp_getattro slots expect a string object as name
 	   and we wouldn't want to break those. */
@@ -1040,6 +1049,8 @@
 		if (name == NULL)
 			return NULL;
 	}
+#endif
+
 	if (!PyString_Check(name)) {
 		PyErr_SetString(PyExc_TypeError,
 				"attribute name must be string");
@@ -1073,6 +1084,7 @@
 	PyTypeObject *tp = v->ob_type;
 	int err;
 
+#ifdef Py_USING_UNICODE
 	/* The Unicode to string conversion is done here because the
 	   existing tp_setattro slots expect a string object as name
 	   and we wouldn't want to break those. */
@@ -1081,7 +1093,9 @@
 		if (name == NULL)
 			return -1;
 	}
-	else if (!PyString_Check(name)){
+	else 
+#endif
+	if (!PyString_Check(name)){
 		PyErr_SetString(PyExc_TypeError,
 				"attribute name must be string");
 		return -1;
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index e2682a0..a8e063e 100644
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -173,8 +173,14 @@
         goto onError;
     }
 
-    if (encoding == NULL)
+    if (encoding == NULL) {
+#ifdef Py_USING_UNICODE
 	encoding = PyUnicode_GetDefaultEncoding();
+#else
+	PyErr_SetString(PyExc_ValueError, "no encoding specified");
+	goto onError;
+#endif
+    }
 
     /* Decode via the codec registry */
     v = PyCodec_Decode(str, encoding, errors);
@@ -197,6 +203,7 @@
     if (v == NULL)
         goto onError;
 
+#ifdef Py_USING_UNICODE
     /* Convert Unicode to a string using the default encoding */
     if (PyUnicode_Check(v)) {
 	PyObject *temp = v;
@@ -205,6 +212,7 @@
 	if (v == NULL)
 	    goto onError;
     }
+#endif
     if (!PyString_Check(v)) {
         PyErr_Format(PyExc_TypeError,
                      "decoder did not return a string object (type=%.400s)",
@@ -245,8 +253,14 @@
         goto onError;
     }
 
-    if (encoding == NULL)
+    if (encoding == NULL) {
+#ifdef Py_USING_UNICODE
 	encoding = PyUnicode_GetDefaultEncoding();
+#else
+	PyErr_SetString(PyExc_ValueError, "no encoding specified");
+	goto onError;
+#endif
+    }
 
     /* Encode via the codec registry */
     v = PyCodec_Encode(str, encoding, errors);
@@ -269,6 +283,7 @@
     if (v == NULL)
         goto onError;
 
+#ifdef Py_USING_UNICODE
     /* Convert Unicode to a string using the default encoding */
     if (PyUnicode_Check(v)) {
 	PyObject *temp = v;
@@ -277,6 +292,7 @@
 	if (v == NULL)
 	    goto onError;
     }
+#endif
     if (!PyString_Check(v)) {
         PyErr_Format(PyExc_TypeError,
                      "encoder did not return a string object (type=%.400s)",
@@ -344,12 +360,15 @@
 	}
 
 	if (!PyString_Check(obj)) {
+#ifdef Py_USING_UNICODE
 		if (PyUnicode_Check(obj)) {
 			obj = _PyUnicode_AsDefaultEncodedString(obj, NULL);
 			if (obj == NULL)
 				return -1;
 		}
-		else {
+		else 
+#endif
+		{
 			PyErr_Format(PyExc_TypeError,
 				     "expected string or Unicode object, "
 				     "%.200s found", obj->ob_type->tp_name);
@@ -477,8 +496,10 @@
 	register unsigned int size;
 	register PyStringObject *op;
 	if (!PyString_Check(bb)) {
+#ifdef Py_USING_UNICODE
 		if (PyUnicode_Check(bb))
 		    return PyUnicode_Concat((PyObject *)a, bb);
+#endif
 		PyErr_Format(PyExc_TypeError,
 			     "cannot add type \"%.200s\" to string",
 			     bb->ob_type->tp_name);
@@ -586,8 +607,10 @@
 {
 	register char *s, *end;
 	register char c;
+#ifdef Py_USING_UNICODE
 	if (PyUnicode_Check(el))
 		return PyUnicode_Contains(a, el);
+#endif
 	if (!PyString_Check(el) || PyString_Size(el) != 1) {
 		PyErr_SetString(PyExc_TypeError,
 		    "'in <string>' requires character as left operand");
@@ -868,8 +891,10 @@
 		sub = PyString_AS_STRING(subobj);
 		n = PyString_GET_SIZE(subobj);
 	}
+#ifdef Py_USING_UNICODE
 	else if (PyUnicode_Check(subobj))
 		return PyUnicode_Split((PyObject *)self, subobj, maxsplit);
+#endif
 	else if (PyObject_AsCharBuffer(subobj, &sub, &n))
 		return NULL;
 	if (n == 0) {
@@ -969,6 +994,7 @@
 		const size_t old_sz = sz;
 		item = PySequence_Fast_GET_ITEM(seq, i);
 		if (!PyString_Check(item)){
+#ifdef Py_USING_UNICODE
 			if (PyUnicode_Check(item)) {
 				/* Defer to Unicode join.
 				 * CAUTION:  There's no gurantee that the
@@ -980,6 +1006,7 @@
 				Py_DECREF(seq);
 				return result;
 			}
+#endif
 			PyErr_Format(PyExc_TypeError,
 				     "sequence item %i: expected string,"
 				     " %.80s found",
@@ -1046,8 +1073,10 @@
 		sub = PyString_AS_STRING(subobj);
 		n = PyString_GET_SIZE(subobj);
 	}
+#ifdef Py_USING_UNICODE
 	else if (PyUnicode_Check(subobj))
 		return PyUnicode_Find((PyObject *)self, subobj, i, last, 1);
+#endif
 	else if (PyObject_AsCharBuffer(subobj, &sub, &n))
 		return -2;
 
@@ -1381,6 +1410,7 @@
 		sub = PyString_AS_STRING(subobj);
 		n = PyString_GET_SIZE(subobj);
 	}
+#ifdef Py_USING_UNICODE
 	else if (PyUnicode_Check(subobj)) {
 		int count;
 		count = PyUnicode_Count((PyObject *)self, subobj, i, last);
@@ -1389,6 +1419,7 @@
 		else
 		    	return PyInt_FromLong((long) count);
 	}
+#endif
 	else if (PyObject_AsCharBuffer(subobj, &sub, &n))
 		return NULL;
 
@@ -1481,6 +1512,7 @@
 		table1 = PyString_AS_STRING(tableobj);
 		tablen = PyString_GET_SIZE(tableobj);
 	}
+#ifdef Py_USING_UNICODE
 	else if (PyUnicode_Check(tableobj)) {
 		/* Unicode .translate() does not support the deletechars
 		   parameter; instead a mapping to None will cause characters
@@ -1492,6 +1524,7 @@
 		}
 		return PyUnicode_Translate((PyObject *)self, tableobj, NULL);
 	}
+#endif
 	else if (PyObject_AsCharBuffer(tableobj, &table1, &tablen))
 		return NULL;
 
@@ -1500,11 +1533,13 @@
 			del_table = PyString_AS_STRING(delobj);
 			dellen = PyString_GET_SIZE(delobj);
 		}
+#ifdef Py_USING_UNICODE
 		else if (PyUnicode_Check(delobj)) {
 			PyErr_SetString(PyExc_TypeError,
 			"deletions are implemented differently for unicode");
 			return NULL;
 		}
+#endif
 		else if (PyObject_AsCharBuffer(delobj, &del_table, &dellen))
 			return NULL;
 
@@ -1729,9 +1764,11 @@
 		sub = PyString_AS_STRING(subobj);
 		sub_len = PyString_GET_SIZE(subobj);
 	}
+#ifdef Py_USING_UNICODE
 	else if (PyUnicode_Check(subobj))
 		return PyUnicode_Replace((PyObject *)self,
 					 subobj, replobj, count);
+#endif
 	else if (PyObject_AsCharBuffer(subobj, &sub, &sub_len))
 		return NULL;
 
@@ -1739,9 +1776,11 @@
 		repl = PyString_AS_STRING(replobj);
 		repl_len = PyString_GET_SIZE(replobj);
 	}
+#ifdef Py_USING_UNICODE
 	else if (PyUnicode_Check(replobj))
 		return PyUnicode_Replace((PyObject *)self,
 					 subobj, replobj, count);
+#endif
 	else if (PyObject_AsCharBuffer(replobj, &repl, &repl_len))
 		return NULL;
 
@@ -1792,6 +1831,7 @@
 		prefix = PyString_AS_STRING(subobj);
 		plen = PyString_GET_SIZE(subobj);
 	}
+#ifdef Py_USING_UNICODE
 	else if (PyUnicode_Check(subobj)) {
 	    	int rc;
 		rc = PyUnicode_Tailmatch((PyObject *)self,
@@ -1801,6 +1841,7 @@
 		else
 			return PyInt_FromLong((long) rc);
 	}
+#endif
 	else if (PyObject_AsCharBuffer(subobj, &prefix, &plen))
 		return NULL;
 
@@ -1850,6 +1891,7 @@
 		suffix = PyString_AS_STRING(subobj);
 		slen = PyString_GET_SIZE(subobj);
 	}
+#ifdef Py_USING_UNICODE
 	else if (PyUnicode_Check(subobj)) {
 	    	int rc;
 		rc = PyUnicode_Tailmatch((PyObject *)self,
@@ -1859,6 +1901,7 @@
 		else
 			return PyInt_FromLong((long) rc);
 	}
+#endif
 	else if (PyObject_AsCharBuffer(subobj, &suffix, &slen))
 		return NULL;
 
@@ -2876,7 +2919,10 @@
 	char *fmt, *res;
 	int fmtcnt, rescnt, reslen, arglen, argidx;
 	int args_owned = 0;
-	PyObject *result, *orig_args, *v, *w;
+	PyObject *result, *orig_args;
+#ifdef Py_USING_UNICODE
+	PyObject *v, *w;
+#endif
 	PyObject *dict = NULL;
 	if (format == NULL || !PyString_Check(format) || args == NULL) {
 		PyErr_BadInternalCall();
@@ -2926,8 +2972,10 @@
 			int sign;
 			int len;
 			char formatbuf[FORMATBUFLEN]; /* For format{float,int,char}() */
+#ifdef Py_USING_UNICODE
 			char *fmt_start = fmt;
 		        int argidx_start = argidx;
+#endif
 
 			fmt++;
 			if (*fmt == '(') {
@@ -3078,11 +3126,13 @@
 				break;
 			case 's':
   			case 'r':
+#ifdef Py_USING_UNICODE
 				if (PyUnicode_Check(v)) {
 					fmt = fmt_start;
 					argidx = argidx_start;
 					goto unicode;
 				}
+#endif
 				if (c == 's')
 				temp = PyObject_Str(v);
 				else
@@ -3240,6 +3290,7 @@
 	_PyString_Resize(&result, reslen - rescnt);
 	return result;
 
+#ifdef Py_USING_UNICODE
  unicode:
 	if (args_owned) {
 		Py_DECREF(args);
@@ -3284,6 +3335,7 @@
 	Py_DECREF(v);
 	Py_DECREF(args);
 	return w;
+#endif /* Py_USING_UNICODE */
 
  error:
 	Py_DECREF(result);