Mercurial > cpython-lru_cache-weakref
diff Python/bltinmodule.c @ 41452:3c339de80010
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.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 13 Apr 2007 03:31:13 +0000 |
| parents | 19f7ff443718 |
| children | 0c5019afc55b |
line wrap: on
line diff
--- a/Python/bltinmodule.c Fri Apr 13 02:23:57 2007 +0000 +++ b/Python/bltinmodule.c Fri Apr 13 03:31:13 2007 +0000 @@ -1451,14 +1451,24 @@ 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);
