diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2011-09-28 05:41:54 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2011-09-28 05:41:54 (GMT) |
commit | d63a3b8beb4a0841cb59fb3515347ccaab34b733 (patch) | |
tree | 3b4e3cc63151c5a5a910c3550a190aefaea96ad4 /Objects/exceptions.c | |
parent | 48d49497c50e79d14e9df9527d766ca3a0a38be5 (diff) | |
download | cpython-d63a3b8beb4a0841cb59fb3515347ccaab34b733.zip cpython-d63a3b8beb4a0841cb59fb3515347ccaab34b733.tar.gz cpython-d63a3b8beb4a0841cb59fb3515347ccaab34b733.tar.bz2 |
Implement PEP 393.
Diffstat (limited to 'Objects/exceptions.c')
-rw-r--r-- | Objects/exceptions.c | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/Objects/exceptions.c b/Objects/exceptions.c index fb7864f..703e72e 100644 --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -962,21 +962,18 @@ SyntaxError_traverse(PySyntaxErrorObject *self, visitproc visit, void *arg) static PyObject* my_basename(PyObject *name) { - Py_UNICODE *unicode; Py_ssize_t i, size, offset; - - unicode = PyUnicode_AS_UNICODE(name); - size = PyUnicode_GET_SIZE(name); + int kind = PyUnicode_KIND(name); + void *data = PyUnicode_DATA(name); + size = PyUnicode_GET_LENGTH(name); offset = 0; for(i=0; i < size; i++) { - if (unicode[i] == SEP) + if (PyUnicode_READ(kind, data, i) == SEP) offset = i + 1; } - if (offset != 0) { - return PyUnicode_FromUnicode( - PyUnicode_AS_UNICODE(name) + offset, - size - offset); - } else { + if (offset != 0) + return PyUnicode_Substring(name, offset, size); + else { Py_INCREF(name); return name; } @@ -1712,6 +1709,7 @@ static PyTypeObject _PyExc_UnicodeTranslateError = { }; PyObject *PyExc_UnicodeTranslateError = (PyObject *)&_PyExc_UnicodeTranslateError; +/* Deprecated. */ PyObject * PyUnicodeTranslateError_Create( const Py_UNICODE *object, Py_ssize_t length, @@ -1721,6 +1719,14 @@ PyUnicodeTranslateError_Create( object, length, start, end, reason); } +PyObject * +_PyUnicodeTranslateError_Create( + PyObject *object, + Py_ssize_t start, Py_ssize_t end, const char *reason) +{ + return PyObject_CallFunction(PyExc_UnicodeTranslateError, "Ons", + object, start, end, reason); +} /* * AssertionError extends Exception |