cinap_lenrekadd hg and python4bb9e2215 years agoHistory
2147 lines · 58.3 KB · C
RawDownload
    return set_string(&((PyUnicodeErrorObject *)exc)->reason, reason);}  static intUnicodeError_init(PyUnicodeErrorObject *self, PyObject *args, PyObject *kwds,                  PyTypeObject *objecttype){    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!",        &PyString_Type, &self->encoding,        objecttype, &self->object,        &PyInt_Type, &self->start,        &PyInt_Type, &self->end,        &PyString_Type, &self->reason)) {        self->encoding = self->object = self->start = self->end =            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;} static intUnicodeError_clear(PyUnicodeErrorObject *self){    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);} static voidUnicodeError_dealloc(PyUnicodeErrorObject *self){    _PyObject_GC_UNTRACK(self);    UnicodeError_clear(self);    self->ob_type->tp_free((PyObject *)self);} static intUnicodeError_traverse(PyUnicodeErrorObject *self, visitproc visit, void *arg){    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);} static PyMemberDef UnicodeError_members[] = {    {"message", T_OBJECT, offsetof(PyUnicodeErrorObject, message), 0,        PyDoc_STR("exception message")},    {"encoding", T_OBJECT, offsetof(PyUnicodeErrorObject, encoding), 0,        PyDoc_STR("exception encoding")},    {"object", T_OBJECT, offsetof(PyUnicodeErrorObject, object), 0,        PyDoc_STR("exception object")},    {"start", T_OBJECT, offsetof(PyUnicodeErrorObject, start), 0,        PyDoc_STR("exception start")},    {"end", T_OBJECT, offsetof(PyUnicodeErrorObject, end), 0,        PyDoc_STR("exception end")},    {"reason", T_OBJECT, offsetof(PyUnicodeErrorObject, reason), 0,        PyDoc_STR("exception reason")},    {NULL}  /* Sentinel */};  /* *    UnicodeEncodeError extends UnicodeError */ static intUnicodeEncodeError_init(PyObject *self, PyObject *args, PyObject *kwds){    if (BaseException_init((PyBaseExceptionObject *)self, args, kwds) == -1)        return -1;    return UnicodeError_init((PyUnicodeErrorObject *)self, args,                             kwds, &PyUnicode_Type);} static PyObject *UnicodeEncodeError_str(PyObject *self){    Py_ssize_t start;    Py_ssize_t end;     if (PyUnicodeEncodeError_GetStart(self, &start))        return NULL;     if (PyUnicodeEncodeError_GetEnd(self, &end))        return NULL;     if (end==start+1) {        int badchar = (int)PyUnicode_AS_UNICODE(((PyUnicodeErrorObject *)self)->object)[start];        char badchar_str[20];        if (badchar <= 0xff)            PyOS_snprintf(badchar_str, sizeof(badchar_str), "x%02x", badchar);        else if (badchar <= 0xffff)            PyOS_snprintf(badchar_str, sizeof(badchar_str), "u%04x", badchar);        else            PyOS_snprintf(badchar_str, sizeof(badchar_str), "U%08x", badchar);        return PyString_FromFormat(            "'%.400s' codec can't encode character u'\\%s' in position %zd: %.400s",            PyString_AS_STRING(((PyUnicodeErrorObject *)self)->encoding),            badchar_str,            start,            PyString_AS_STRING(((PyUnicodeErrorObject *)self)->reason)        );    }    return PyString_FromFormat(        "'%.400s' codec can't encode characters in position %zd-%zd: %.400s",        PyString_AS_STRING(((PyUnicodeErrorObject *)self)->encoding),        start,        (end-1),        PyString_AS_STRING(((PyUnicodeErrorObject *)self)->reason)    );} static PyTypeObject _PyExc_UnicodeEncodeError = {    PyObject_HEAD_INIT(NULL)    0,    EXC_MODULE_NAME "UnicodeEncodeError",    sizeof(PyUnicodeErrorObject), 0,    (destructor)UnicodeError_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,    (reprfunc)UnicodeEncodeError_str, 0, 0, 0,    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,    PyDoc_STR("Unicode encoding error."), (traverseproc)UnicodeError_traverse,    (inquiry)UnicodeError_clear, 0, 0, 0, 0, 0, UnicodeError_members,    0, &_PyExc_UnicodeError, 0, 0, 0, offsetof(PyUnicodeErrorObject, dict),    (initproc)UnicodeEncodeError_init, 0, BaseException_new,};PyObject *PyExc_UnicodeEncodeError = (PyObject *)&_PyExc_UnicodeEncodeError; PyObject *PyUnicodeEncodeError_Create(    const char *encoding, const Py_UNICODE *object, Py_ssize_t length,    Py_ssize_t start, Py_ssize_t end, const char *reason){    return PyObject_CallFunction(PyExc_UnicodeEncodeError, "su#nns",                                 encoding, object, length, start, end, reason);}  /* *    UnicodeDecodeError extends UnicodeError */ static intUnicodeDecodeError_init(PyObject *self, PyObject *args, PyObject *kwds){    if (BaseException_init((PyBaseExceptionObject *)self, args, kwds) == -1)        return -1;    return UnicodeError_init((PyUnicodeErrorObject *)self, args,                             kwds, &PyString_Type);} static PyObject *UnicodeDecodeError_str(PyObject *self){    Py_ssize_t start = 0;    Py_ssize_t end = 0;     if (PyUnicodeDecodeError_GetStart(self, &start))    return NULL;     if (PyUnicodeDecodeError_GetEnd(self, &end))    return NULL;     if (end==start+1) {        /* FromFormat does not support %02x, so format that separately */        char byte[4];        PyOS_snprintf(byte, sizeof(byte), "%02x",                      ((int)PyString_AS_STRING(((PyUnicodeErrorObject *)self)->object)[start])&0xff);        return PyString_FromFormat(            "'%.400s' codec can't decode byte 0x%s in position %zd: %.400s",            PyString_AS_STRING(((PyUnicodeErrorObject *)self)->encoding),            byte,            start,            PyString_AS_STRING(((PyUnicodeErrorObject *)self)->reason)        );    }    return PyString_FromFormat(        "'%.400s' codec can't decode bytes in position %zd-%zd: %.400s",        PyString_AS_STRING(((PyUnicodeErrorObject *)self)->encoding),        start,        (end-1),        PyString_AS_STRING(((PyUnicodeErrorObject *)self)->reason)    );} static PyTypeObject _PyExc_UnicodeDecodeError = {    PyObject_HEAD_INIT(NULL)    0,    EXC_MODULE_NAME "UnicodeDecodeError",    sizeof(PyUnicodeErrorObject), 0,    (destructor)UnicodeError_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,    (reprfunc)UnicodeDecodeError_str, 0, 0, 0,    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,    PyDoc_STR("Unicode decoding error."), (traverseproc)UnicodeError_traverse,    (inquiry)UnicodeError_clear, 0, 0, 0, 0, 0, UnicodeError_members,    0, &_PyExc_UnicodeError, 0, 0, 0, offsetof(PyUnicodeErrorObject, dict),    (initproc)UnicodeDecodeError_init, 0, BaseException_new,};PyObject *PyExc_UnicodeDecodeError = (PyObject *)&_PyExc_UnicodeDecodeError; PyObject *PyUnicodeDecodeError_Create(    const char *encoding, const char *object, Py_ssize_t length,    Py_ssize_t start, Py_ssize_t end, const char *reason){    assert(length < INT_MAX);    assert(start < INT_MAX);    assert(end < INT_MAX);    return PyObject_CallFunction(PyExc_UnicodeDecodeError, "ss#nns",                                 encoding, object, length, start, end, reason);}  /* *    UnicodeTranslateError extends UnicodeError */ static intUnicodeTranslateError_init(PyUnicodeErrorObject *self, PyObject *args,                           PyObject *kwds){    if (BaseException_init((PyBaseExceptionObject *)self, args, kwds) == -1)        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!",        &PyUnicode_Type, &self->object,        &PyInt_Type, &self->start,        &PyInt_Type, &self->end,        &PyString_Type, &self->reason)) {        self->object = self->start = self->end = self->reason = NULL;        return -1;    }     Py_INCREF(self->object);    Py_INCREF(self->start);    Py_INCREF(self->end);    Py_INCREF(self->reason);     return 0;}  static PyObject *UnicodeTranslateError_str(PyObject *self){    Py_ssize_t start;    Py_ssize_t end;     if (PyUnicodeTranslateError_GetStart(self, &start))        return NULL;     if (PyUnicodeTranslateError_GetEnd(self, &end))        return NULL;     if (end==start+1) {        int badchar = (int)PyUnicode_AS_UNICODE(((PyUnicodeErrorObject *)self)->object)[start];        char badchar_str[20];        if (badchar <= 0xff)            PyOS_snprintf(badchar_str, sizeof(badchar_str), "x%02x", badchar);        else if (badchar <= 0xffff)            PyOS_snprintf(badchar_str, sizeof(badchar_str), "u%04x", badchar);        else            PyOS_snprintf(badchar_str, sizeof(badchar_str), "U%08x", badchar);        return PyString_FromFormat(            "can't translate character u'\\%s' in position %zd: %.400s",            badchar_str,            start,            PyString_AS_STRING(((PyUnicodeErrorObject *)self)->reason)        );    }    return PyString_FromFormat(        "can't translate characters in position %zd-%zd: %.400s",        start,        (end-1),        PyString_AS_STRING(((PyUnicodeErrorObject *)self)->reason)    );} static PyTypeObject _PyExc_UnicodeTranslateError = {    PyObject_HEAD_INIT(NULL)    0,    EXC_MODULE_NAME "UnicodeTranslateError",    sizeof(PyUnicodeErrorObject), 0,    (destructor)UnicodeError_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,    (reprfunc)UnicodeTranslateError_str, 0, 0, 0,    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,    PyDoc_STR("Unicode translation error."), (traverseproc)UnicodeError_traverse,    (inquiry)UnicodeError_clear, 0, 0, 0, 0, 0, UnicodeError_members,    0, &_PyExc_UnicodeError, 0, 0, 0, offsetof(PyUnicodeErrorObject, dict),    (initproc)UnicodeTranslateError_init, 0, BaseException_new,};PyObject *PyExc_UnicodeTranslateError = (PyObject *)&_PyExc_UnicodeTranslateError; PyObject *PyUnicodeTranslateError_Create(    const Py_UNICODE *object, Py_ssize_t length,    Py_ssize_t start, Py_ssize_t end, const char *reason){    return PyObject_CallFunction(PyExc_UnicodeTranslateError, "u#nns",                                 object, length, start, end, reason);}#endif  /* *    AssertionError extends StandardError */SimpleExtendsException(PyExc_StandardError, AssertionError,                       "Assertion failed.");  /* *    ArithmeticError extends StandardError */SimpleExtendsException(PyExc_StandardError, ArithmeticError,                       "Base class for arithmetic errors.");  /* *    FloatingPointError extends ArithmeticError */SimpleExtendsException(PyExc_ArithmeticError, FloatingPointError,                       "Floating point operation failed.");  /* *    OverflowError extends ArithmeticError */SimpleExtendsException(PyExc_ArithmeticError, OverflowError,                       "Result too large to be represented.");  /* *    ZeroDivisionError extends ArithmeticError */SimpleExtendsException(PyExc_ArithmeticError, ZeroDivisionError,          "Second argument to a division or modulo operation was zero.");  /* *    SystemError extends StandardError */SimpleExtendsException(PyExc_StandardError, SystemError,    "Internal error in the Python interpreter.\n"    "\n"    "Please report this to the Python maintainer, along with the traceback,\n"    "the Python version, and the hardware/OS platform and version.");  /* *    ReferenceError extends StandardError */SimpleExtendsException(PyExc_StandardError, ReferenceError,                       "Weak ref proxy used after referent went away.");  /* *    MemoryError extends StandardError */SimpleExtendsException(PyExc_StandardError, MemoryError, "Out of memory.");  /* Warning category docstrings */ /* *    Warning extends Exception */SimpleExtendsException(PyExc_Exception, Warning,                       "Base class for warning categories.");  /* *    UserWarning extends Warning */SimpleExtendsException(PyExc_Warning, UserWarning,                       "Base class for warnings generated by user code.");  /* *    DeprecationWarning extends Warning */SimpleExtendsException(PyExc_Warning, DeprecationWarning,                       "Base class for warnings about deprecated features.");  /* *    PendingDeprecationWarning extends Warning */SimpleExtendsException(PyExc_Warning, PendingDeprecationWarning,    "Base class for warnings about features which will be deprecated\n"    "in the future.");  /* *    SyntaxWarning extends Warning */SimpleExtendsException(PyExc_Warning, SyntaxWarning,                       "Base class for warnings about dubious syntax.");  /* *    RuntimeWarning extends Warning */SimpleExtendsException(PyExc_Warning, RuntimeWarning,                 "Base class for warnings about dubious runtime behavior.");  /* *    FutureWarning extends Warning */SimpleExtendsException(PyExc_Warning, FutureWarning,    "Base class for warnings about constructs that will change semantically\n"    "in the future.");  /* *    ImportWarning extends Warning */SimpleExtendsException(PyExc_Warning, ImportWarning,          "Base class for warnings about probable mistakes in module imports");  /* *    UnicodeWarning extends Warning */SimpleExtendsException(PyExc_Warning, UnicodeWarning,    "Base class for warnings about Unicode related problems, mostly\n"    "related to conversion problems.");  /* Pre-computed MemoryError instance.  Best to create this as early as * possible and not wait until a MemoryError is actually raised! */PyObject *PyExc_MemoryErrorInst=NULL; /* module global functions */static PyMethodDef functions[] = {    /* Sentinel */    {NULL, NULL}}; #define PRE_INIT(TYPE) if (PyType_Ready(&_PyExc_ ## TYPE) < 0) \    Py_FatalError("exceptions bootstrapping error."); #define POST_INIT(TYPE) Py_INCREF(PyExc_ ## TYPE); \    PyModule_AddObject(m, # TYPE, PyExc_ ## TYPE); \    if (PyDict_SetItemString(bdict, # TYPE, PyExc_ ## TYPE)) \        Py_FatalError("Module dictionary insertion problem."); #if defined _MSC_VER && _MSC_VER >= 1400 && defined(__STDC_SECURE_LIB__)/* crt variable checking in VisualStudio .NET 2005 */#include <crtdbg.h> static int	prevCrtReportMode;static _invalid_parameter_handler	prevCrtHandler; /* Invalid parameter handler.  Sets a ValueError exception */static voidInvalidParameterHandler(    const wchar_t * expression,    const wchar_t * function,    const wchar_t * file,    unsigned int line,    uintptr_t pReserved){    /* Do nothing, allow execution to continue.  Usually this     * means that the CRT will set errno to EINVAL     */}#endif  PyMODINIT_FUNC_PyExc_Init(void){    PyObject *m, *bltinmod, *bdict;

Lines 1501–2000 of 2147. Previous lines