summaryrefslogtreecommitdiff
path: root/Objects/abstract.c
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-01-25 17:15:10 +0000
committerBenjamin Peterson <benjamin@python.org>2009-01-25 17:15:10 +0000
commit78821ddf8c8eeebf757d72c2989cc0accea155de (patch)
treec9ce0cdf40089bbc995de6138b237595b4cd51dd /Objects/abstract.c
parente52c31450dfbe649b559b3fa96630d348b838c19 (diff)
downloadcpython-git-78821ddf8c8eeebf757d72c2989cc0accea155de.tar.gz
fix building the core with --disable-unicode
I changed some bytearray methods to use strings instead of unicode like bytes_repr Also, bytearray.fromhex() can take strings as well as unicode
Diffstat (limited to 'Objects/abstract.c')
-rw-r--r--Objects/abstract.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c
index 80a1289138..503a611ef2 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -720,8 +720,10 @@ PyObject_Format(PyObject* obj, PyObject *format_spec)
static PyObject * str__format__ = NULL;
PyObject *empty = NULL;
PyObject *result = NULL;
+#ifdef Py_USING_UNICODE
int spec_is_unicode;
int result_is_unicode;
+#endif
/* Initialize cached value */
if (str__format__ == NULL) {
@@ -738,11 +740,15 @@ PyObject_Format(PyObject* obj, PyObject *format_spec)
}
/* Check the format_spec type, and make sure it's str or unicode */
+#if Py_USING_UNICODE
if (PyUnicode_Check(format_spec))
spec_is_unicode = 1;
else if (PyString_Check(format_spec))
spec_is_unicode = 0;
else {
+#else
+ if (!PyString_Check(format_spec)) {
+#endif
PyErr_Format(PyExc_TypeError,
"format expects arg 2 to be string "
"or unicode, not %.100s", Py_TYPE(format_spec)->tp_name);
@@ -773,9 +779,11 @@ PyObject_Format(PyObject* obj, PyObject *format_spec)
depending on the type of the format
specifier). For new-style classes, this
logic is done by object.__format__(). */
+#ifdef Py_USING_UNICODE
if (spec_is_unicode)
self_as_str = PyObject_Unicode(obj);
else
+#endif
self_as_str = PyObject_Str(obj);
if (self_as_str == NULL)
goto done;
@@ -818,11 +826,15 @@ PyObject_Format(PyObject* obj, PyObject *format_spec)
goto done;
/* Check the result type, and make sure it's str or unicode */
+#ifdef Py_USING_UNICODE
if (PyUnicode_Check(result))
result_is_unicode = 1;
else if (PyString_Check(result))
result_is_unicode = 0;
else {
+#else
+ if (!PyString_Check(result)) {
+#endif
PyErr_Format(PyExc_TypeError,
"%.100s.__format__ must return string or "
"unicode, not %.100s", Py_TYPE(obj)->tp_name,
@@ -834,12 +846,14 @@ PyObject_Format(PyObject* obj, PyObject *format_spec)
/* Convert to unicode, if needed. Required if spec is unicode
and result is str */
+#ifdef Py_USING_UNICODE
if (spec_is_unicode && !result_is_unicode) {
PyObject *tmp = PyObject_Unicode(result);
/* This logic works whether or not tmp is NULL */
Py_DECREF(result);
result = tmp;
}
+#endif
done:
Py_XDECREF(empty);