summaryrefslogtreecommitdiffstats
path: root/Objects/exceptions.c
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2011-09-28 05:41:54 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2011-09-28 05:41:54 (GMT)
commitd63a3b8beb4a0841cb59fb3515347ccaab34b733 (patch)
tree3b4e3cc63151c5a5a910c3550a190aefaea96ad4 /Objects/exceptions.c
parent48d49497c50e79d14e9df9527d766ca3a0a38be5 (diff)
downloadcpython-d63a3b8beb4a0841cb59fb3515347ccaab34b733.zip
cpython-d63a3b8beb4a0841cb59fb3515347ccaab34b733.tar.gz
cpython-d63a3b8beb4a0841cb59fb3515347ccaab34b733.tar.bz2
Implement PEP 393.
Diffstat (limited to 'Objects/exceptions.c')
-rw-r--r--Objects/exceptions.c26
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