Walter Dörwald added the comment:
OK, I've changed the name of the codec to xml_auto_detect and added
support for EBCDIC.
Added file: http://bugs.python.org/file8717/diff2.txt
__________________________________
Tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue1399>
__________________________________
Index: Include/pyerrors.h
===================================================================
--- Include/pyerrors.h (Revision 55955)
+++ Include/pyerrors.h (Arbeitskopie)
@@ -30,8 +30,8 @@
PyObject *args;
PyObject *encoding;
PyObject *object;
- PyObject *start;
- PyObject *end;
+ Py_ssize_t start;
+ Py_ssize_t end;
PyObject *reason;
} PyUnicodeErrorObject;
Index: Objects/exceptions.c
===================================================================
--- Objects/exceptions.c (Revision 55955)
+++ Objects/exceptions.c (Arbeitskopie)
@@ -955,36 +955,6 @@
SimpleExtendsException(PyExc_ValueError, UnicodeError,
"Unicode related error.");
-static int
-get_int(PyObject *attr, Py_ssize_t *value, const char *name)
-{
- if (!attr) {
- PyErr_Format(PyExc_TypeError, "%.200s attribute not set", name);
- return -1;
- }
-
- if (PyLong_Check(attr)) {
- *value = PyLong_AsSsize_t(attr);
- if (*value == -1 && PyErr_Occurred())
- return -1;
- } else {
- PyErr_Format(PyExc_TypeError, "%.200s attribute must be int", name);
- return -1;
- }
- return 0;
-}
-
-static int
-set_ssize_t(PyObject **attr, Py_ssize_t value)
-{
- PyObject *obj = PyInt_FromSsize_t(value);
- if (!obj)
- return -1;
- Py_CLEAR(*attr);
- *attr = obj;
- return 0;
-}
-
static PyObject *
get_bytes(PyObject *attr, const char *name)
{
@@ -1062,40 +1032,35 @@
int
PyUnicodeEncodeError_GetStart(PyObject *exc, Py_ssize_t *start)
{
- if (!get_int(((PyUnicodeErrorObject *)exc)->start, start, "start")) {
- Py_ssize_t size;
- PyObject *obj = get_unicode(((PyUnicodeErrorObject *)exc)->object,
- "object");
- if (!obj) return -1;
- size = PyUnicode_GET_SIZE(obj);
- if (*start<0)
- *start = 0; /*XXX check for values <0*/
- if (*start>=size)
- *start = size-1;
- Py_DECREF(obj);
- return 0;
- }
- return -1;
+ PyObject *obj = get_unicode(((PyUnicodeErrorObject *)exc)->object,
+ "object");
+ Py_ssize_t size;
+ if (!obj)
+ return -1;
+ *start = ((PyUnicodeErrorObject *)exc)->start;
+ size = PyUnicode_GET_SIZE(obj);
+ if (*start<0)
+ *start = 0; /*XXX check for values <0*/
+ if (*start>=size)
+ *start = size-1;
+ return 0;
}
int
PyUnicodeDecodeError_GetStart(PyObject *exc, Py_ssize_t *start)
{
- if (!get_int(((PyUnicodeErrorObject *)exc)->start, start, "start")) {
- Py_ssize_t size;
- PyObject *obj = get_bytes(((PyUnicodeErrorObject *)exc)->object,
- "object");
- if (!obj) return -1;
- size = PyBytes_GET_SIZE(obj);
- if (*start<0)
- *start = 0;
- if (*start>=size)
- *start = size-1;
- Py_DECREF(obj);
- return 0;
- }
- return -1;
+ PyObject *obj = get_bytes(((PyUnicodeErrorObject *)exc)->object, "object");
+ Py_ssize_t size;
+ if (!obj)
+ return -1;
+ *start = ((PyUnicodeErrorObject *)exc)->start;
+ size = PyBytes_GET_SIZE(obj);
+ if (*start<0)
+ *start = 0;
+ if (*start>=size)
+ *start = size-1;
+ return 0;
}
@@ -1109,61 +1074,59 @@
int
PyUnicodeEncodeError_SetStart(PyObject *exc, Py_ssize_t start)
{
- return set_ssize_t(&((PyUnicodeErrorObject *)exc)->start, start);
+ ((PyUnicodeErrorObject *)exc)->start = start;
+ return 0;
}
int
PyUnicodeDecodeError_SetStart(PyObject *exc, Py_ssize_t start)
{
- return set_ssize_t(&((PyUnicodeErrorObject *)exc)->start, start);
+ ((PyUnicodeErrorObject *)exc)->start = start;
+ return 0;
}
int
PyUnicodeTranslateError_SetStart(PyObject *exc, Py_ssize_t start)
{
- return set_ssize_t(&((PyUnicodeErrorObject *)exc)->start, start);
+ ((PyUnicodeErrorObject *)exc)->start = start;
+ return 0;
}
int
PyUnicodeEncodeError_GetEnd(PyObject *exc, Py_ssize_t *end)
{
- if (!get_int(((PyUnicodeErrorObject *)exc)->end, end, "end")) {
- Py_ssize_t size;
- PyObject *obj = get_unicode(((PyUnicodeErrorObject *)exc)->object,
- "object");
- if (!obj) return -1;
- size = PyUnicode_GET_SIZE(obj);
- if (*end<1)
- *end = 1;
- if (*end>size)
- *end = size;
- Py_DECREF(obj);
- return 0;
- }
- return -1;
+ PyObject *obj = get_unicode(((PyUnicodeErrorObject *)exc)->object,
+ "object");
+ Py_ssize_t size;
+ if (!obj)
+ return -1;
+ *end = ((PyUnicodeErrorObject *)exc)->end;
+ size = PyUnicode_GET_SIZE(obj);
+ if (*end<1)
+ *end = 1;
+ if (*end>size)
+ *end = size;
+ return 0;
}
int
PyUnicodeDecodeError_GetEnd(PyObject *exc, Py_ssize_t *end)
{
- if (!get_int(((PyUnicodeErrorObject *)exc)->end, end, "end")) {
- Py_ssize_t size;
- PyObject *obj = get_bytes(((PyUnicodeErrorObject *)exc)->object,
- "object");
- if (!obj) return -1;
- size = PyBytes_GET_SIZE(obj);
- if (*end<1)
- *end = 1;
- if (*end>size)
- *end = size;
- Py_DECREF(obj);
- return 0;
- }
- return -1;
+ PyObject *obj = get_bytes(((PyUnicodeErrorObject *)exc)->object, "object");
+ Py_ssize_t size;
+ if (!obj)
+ return -1;
+ *end = ((PyUnicodeErrorObject *)exc)->end;
+ size = PyBytes_GET_SIZE(obj);
+ if (*end<1)
+ *end = 1;
+ if (*end>size)
+ *end = size;
+ return 0;
}
@@ -1177,21 +1140,24 @@
int
PyUnicodeEncodeError_SetEnd(PyObject *exc, Py_ssize_t end)
{
- return set_ssize_t(&((PyUnicodeErrorObject *)exc)->end, end);
+ ((PyUnicodeErrorObject *)exc)->end = end;
+ return 0;
}
int
PyUnicodeDecodeError_SetEnd(PyObject *exc, Py_ssize_t end)
{
- return set_ssize_t(&((PyUnicodeErrorObject *)exc)->end, end);
+ ((PyUnicodeErrorObject *)exc)->end = end;
+ return 0;
}
int
PyUnicodeTranslateError_SetEnd(PyObject *exc, Py_ssize_t end)
{
- return set_ssize_t(&((PyUnicodeErrorObject *)exc)->end, end);
+ ((PyUnicodeErrorObject *)exc)->end = end;
+ return 0;
}
PyObject *
@@ -1245,25 +1211,20 @@
{
Py_CLEAR(self->encoding);
Py_CLEAR(self->object);
- Py_CLEAR(self->start);
- Py_CLEAR(self->end);
Py_CLEAR(self->reason);
- if (!PyArg_ParseTuple(args, "O!O!O!O!O!",
+ if (!PyArg_ParseTuple(args, "O!O!nnO!",
&PyUnicode_Type, &self->encoding,
objecttype, &self->object,
- &PyLong_Type, &self->start,
- &PyLong_Type, &self->end,
+ &self->start,
+ &self->end,
&PyUnicode_Type, &self->reason)) {
- self->encoding = self->object = self->start = self->end =
- self->reason = NULL;
+ self->encoding = self->object = self->reason = NULL;
return -1;
}
Py_INCREF(self->encoding);
Py_INCREF(self->object);
- Py_INCREF(self->start);
- Py_INCREF(self->end);
Py_INCREF(self->reason);
return 0;
@@ -1274,8 +1235,6 @@
{
Py_CLEAR(self->encoding);
Py_CLEAR(self->object);
- Py_CLEAR(self->start);
- Py_CLEAR(self->end);
Py_CLEAR(self->reason);
return BaseException_clear((PyBaseExceptionObject *)self);
}
@@ -1293,8 +1252,6 @@
{
Py_VISIT(self->encoding);
Py_VISIT(self->object);
- Py_VISIT(self->start);
- Py_VISIT(self->end);
Py_VISIT(self->reason);
return BaseException_traverse((PyBaseExceptionObject *)self, visit, arg);
}
@@ -1304,9 +1261,9 @@
PyDoc_STR("exception encoding")},
{"object", T_OBJECT, offsetof(PyUnicodeErrorObject, object), 0,
PyDoc_STR("exception object")},
- {"start", T_OBJECT, offsetof(PyUnicodeErrorObject, start), 0,
+ {"start", T_PYSSIZET, offsetof(PyUnicodeErrorObject, start), 0,
PyDoc_STR("exception start")},
- {"end", T_OBJECT, offsetof(PyUnicodeErrorObject, end), 0,
+ {"end", T_PYSSIZET, offsetof(PyUnicodeErrorObject, end), 0,
PyDoc_STR("exception end")},
{"reason", T_OBJECT, offsetof(PyUnicodeErrorObject, reason), 0,
PyDoc_STR("exception reason")},
@@ -1474,22 +1431,18 @@
return -1;
Py_CLEAR(self->object);
- Py_CLEAR(self->start);
- Py_CLEAR(self->end);
Py_CLEAR(self->reason);
- if (!PyArg_ParseTuple(args, "O!O!O!O!",
+ if (!PyArg_ParseTuple(args, "O!nnO!",
&PyUnicode_Type, &self->object,
- &PyLong_Type, &self->start,
- &PyLong_Type, &self->end,
+ &self->start,
+ &self->end,
&PyUnicode_Type, &self->reason)) {
- self->object = self->start = self->end = self->reason = NULL;
+ self->object = self->reason = NULL;
return -1;
}
Py_INCREF(self->object);
- Py_INCREF(self->start);
- Py_INCREF(self->end);
Py_INCREF(self->reason);
return 0;
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com