diff options
author | Guido van Rossum <guido@python.org> | 2007-04-13 03:31:13 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-04-13 03:31:13 (GMT) |
commit | 98f9746740e95bd0307a4a1a1f1adf69cc585e61 (patch) | |
tree | 66ce1f83cb22b87e627a4c2520055507a25c8cc8 /Python/bltinmodule.c | |
parent | 84d79ddce2176ae54825da32e096d6332a8d5138 (diff) | |
download | cpython-98f9746740e95bd0307a4a1a1f1adf69cc585e61.zip cpython-98f9746740e95bd0307a4a1a1f1adf69cc585e61.tar.gz cpython-98f9746740e95bd0307a4a1a1f1adf69cc585e61.tar.bz2 |
Support marshal.dump(x, f) where f is not a real file.
Support ord(b) where b is a 1-byte string.
In zipfile.py, work around bytes being ints instead of chars, sometimes.
Diffstat (limited to 'Python/bltinmodule.c')
-rw-r--r-- | Python/bltinmodule.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 4aa9c62..20746fa 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -1451,14 +1451,24 @@ builtin_ord(PyObject *self, PyObject* obj) return PyInt_FromLong(ord); } #ifdef Py_USING_UNICODE - } else if (PyUnicode_Check(obj)) { + } + else if (PyUnicode_Check(obj)) { size = PyUnicode_GET_SIZE(obj); if (size == 1) { ord = (long)*PyUnicode_AS_UNICODE(obj); return PyInt_FromLong(ord); } #endif - } else { + } + else if (PyBytes_Check(obj)) { + /* XXX Hopefully this is temporary */ + size = PyBytes_GET_SIZE(obj); + if (size == 1) { + ord = (long)*PyBytes_AS_STRING(obj); + return PyInt_FromLong(ord); + } + } + else { PyErr_Format(PyExc_TypeError, "ord() expected string of length 1, but " \ "%.200s found", obj->ob_type->tp_name); |