Back to index

python3.2  3.2.2
Classes | Defines | Typedefs | Enumerations | Functions | Variables
pyexpat.c File Reference
#include "Python.h"
#include <ctype.h>
#include "frameobject.h"
#include "expat.h"
#include "pyexpat.h"

Go to the source code of this file.

Classes

struct  xmlparseobject
struct  HandlerInfo

Defines

#define XML_COMBINED_VERSION   (10000*XML_MAJOR_VERSION+100*XML_MINOR_VERSION+XML_MICRO_VERSION)
#define FIX_TRACE
#define CHARACTER_DATA_BUFFER_SIZE   8192
#define RC_HANDLER(RC, NAME, PARAMS, INIT, PARAM_FORMAT, CONVERSION, RETURN, GETUSERDATA)
#define VOID_HANDLER(NAME, PARAMS, PARAM_FORMAT)
#define INT_HANDLER(NAME, PARAMS, PARAM_FORMAT)
#define BUF_SIZE   2048
#define APPEND(list, str)
#define MODULE_NAME   "pyexpat"
#define MODULE_INITFUNC   PyInit_pyexpat
#define PyMODINIT_FUNC   void
#define MYCONST(name)
#define MYCONST(c)   PyModule_AddIntConstant(m, #c, c)
#define MYCONST(c)   PyModule_AddIntConstant(model_module, #c, c)

Typedefs

typedef void(* xmlhandlersetter )(XML_Parser self, void *meth)
typedef voidxmlhandler

Enumerations

enum  HandlerTypes {
  StartElement, EndElement, ProcessingInstruction, CharacterData,
  UnparsedEntityDecl, NotationDecl, StartNamespaceDecl, EndNamespaceDecl,
  Comment, StartCdataSection, EndCdataSection, Default,
  DefaultHandlerExpand, NotStandalone, ExternalEntityRef, StartDoctypeDecl,
  EndDoctypeDecl, EntityDecl, XmlDecl, ElementDecl,
  AttlistDecl, _DummyDecl
}

Functions

static int set_error_attr (PyObject *err, char *name, int value)
static PyObjectset_error (xmlparseobject *self, enum XML_Error code)
static int have_handler (xmlparseobject *self, int type)
static PyObjectget_handler_name (struct HandlerInfo *hinfo)
static PyObjectconv_string_to_unicode (const XML_Char *str)
static PyObjectconv_string_len_to_unicode (const XML_Char *str, int len)
static void clear_handlers (xmlparseobject *self, int initial)
static int error_external_entity_ref_handler (XML_Parser parser, const XML_Char *context, const XML_Char *base, const XML_Char *systemId, const XML_Char *publicId)
static void noop_character_data_handler (void *userData, const XML_Char *data, int len)
static void flag_error (xmlparseobject *self)
static PyCodeObjectgetcode (enum HandlerTypes slot, char *func_name, int lineno)
static int trace_frame (PyThreadState *tstate, PyFrameObject *f, int code, PyObject *val)
static int trace_frame_exc (PyThreadState *tstate, PyFrameObject *f)
static PyObjectcall_with_frame (PyCodeObject *c, PyObject *func, PyObject *args, xmlparseobject *self)
static PyObjectstring_intern (xmlparseobject *self, const char *str)
static int call_character_handler (xmlparseobject *self, const XML_Char *buffer, int len)
static int flush_character_buffer (xmlparseobject *self)
static void my_CharacterDataHandler (void *userData, const XML_Char *data, int len)
static void my_StartElementHandler (void *userData, const XML_Char *name, const XML_Char *atts[])
 VOID_HANDLER (EndElement,(void *userData, const XML_Char *name),("(N)", string_intern(self, name)))
static void my_ElementDeclHandler (void *userData, const XML_Char *name, XML_Content *model)
 VOID_HANDLER (AttlistDecl,(void *userData, const XML_Char *elname, const XML_Char *attname, const XML_Char *att_type, const XML_Char *dflt, int isrequired),("(NNO&O&i)", string_intern(self, elname), string_intern(self, attname), conv_string_to_unicode, att_type, conv_string_to_unicode, dflt, isrequired))
 PyDoc_STRVAR (xmlparse_Parse__doc__,"Parse(data[, isfinal])\n\ Parse XML data. `isfinal' should be true at end of input.")
static PyObjectxmlparse_Parse (xmlparseobject *self, PyObject *args)
static int readinst (char *buf, int buf_size, PyObject *meth)
 PyDoc_STRVAR (xmlparse_ParseFile__doc__,"ParseFile(file)\n\ Parse XML data from file-like object.")
static PyObjectxmlparse_ParseFile (xmlparseobject *self, PyObject *f)
 PyDoc_STRVAR (xmlparse_SetBase__doc__,"SetBase(base_url)\n\ Set the base URL for the parser.")
static PyObjectxmlparse_SetBase (xmlparseobject *self, PyObject *args)
 PyDoc_STRVAR (xmlparse_GetBase__doc__,"GetBase() -> url\n\ Return base URL string for the parser.")
static PyObjectxmlparse_GetBase (xmlparseobject *self, PyObject *unused)
 PyDoc_STRVAR (xmlparse_GetInputContext__doc__,"GetInputContext() -> string\n\ Return the untranslated text of the input that caused the current event.\n\ If the event was generated by a large amount of text (such as a start tag\n\ for an element with many attributes), not all of the text may be available.")
static PyObjectxmlparse_GetInputContext (xmlparseobject *self, PyObject *unused)
 PyDoc_STRVAR (xmlparse_ExternalEntityParserCreate__doc__,"ExternalEntityParserCreate(context[, encoding])\n\ Create a parser for parsing an external entity based on the\n\ information passed to the ExternalEntityRefHandler.")
static PyObjectxmlparse_ExternalEntityParserCreate (xmlparseobject *self, PyObject *args)
 PyDoc_STRVAR (xmlparse_SetParamEntityParsing__doc__,"SetParamEntityParsing(flag) -> success\n\ Controls parsing of parameter entities (including the external DTD\n\ subset). Possible flag values are XML_PARAM_ENTITY_PARSING_NEVER,\n\ XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE and\n\ XML_PARAM_ENTITY_PARSING_ALWAYS. Returns true if setting the flag\n\ was successful.")
static PyObjectxmlparse_SetParamEntityParsing (xmlparseobject *p, PyObject *args)
static PyObjectxmlparse_dir (PyObject *self, PyObject *noargs)
static void init_template_buffer (void)
static int PyUnknownEncodingHandler (void *encodingHandlerData, const XML_Char *name, XML_Encoding *info)
static PyObjectnewxmlparseobject (char *encoding, char *namespace_separator, PyObject *intern)
static void xmlparse_dealloc (xmlparseobject *self)
static int handlername2int (PyObject *name)
static PyObjectget_pybool (int istrue)
static PyObjectxmlparse_getattro (xmlparseobject *self, PyObject *nameobj)
static int sethandler (xmlparseobject *self, PyObject *name, PyObject *v)
static int xmlparse_setattro (xmlparseobject *self, PyObject *name, PyObject *v)
static int xmlparse_traverse (xmlparseobject *op, visitproc visit, void *arg)
static int xmlparse_clear (xmlparseobject *op)
 PyDoc_STRVAR (Xmlparsetype__doc__,"XML parser")
 PyDoc_STRVAR (pyexpat_ParserCreate__doc__,"ParserCreate([encoding[, namespace_separator]]) -> parser\n\ Return a new XML parser object.")
static PyObjectpyexpat_ParserCreate (PyObject *notused, PyObject *args, PyObject *kw)
 PyDoc_STRVAR (pyexpat_ErrorString__doc__,"ErrorString(errno) -> string\n\ Returns string error for given number.")
static PyObjectpyexpat_ErrorString (PyObject *self, PyObject *args)
 PyDoc_STRVAR (pyexpat_module_documentation,"Python wrapper for Expat parser.")
PyMODINIT_FUNC MODULE_INITFUNC (void)

Variables

static PyObjectErrorObject
static PyTypeObject Xmlparsetype
static struct HandlerInfo [64]
static struct PyMethodDef []
static char template_buffer [257]
static struct PyModuleDef

Class Documentation

struct xmlparseobject

Definition at line 47 of file pyexpat.c.

Collaboration diagram for xmlparseobject:
Class Members
XML_Char * buffer
int buffer_size
int buffer_used
PyObject ** handlers
int in_callback
PyObject * intern
PyObject_HEAD XML_Parser itself
int ns_prefixes
int ordered_attributes
int specified_attributes
struct HandlerInfo

Definition at line 70 of file pyexpat.c.

Collaboration diagram for HandlerInfo:
Class Members
xmlhandler handler
const char * name
PyObject * nameobj
xmlhandlersetter setter
PyCodeObject * tb_code

Define Documentation

#define APPEND (   list,
  str 
)
Value:
do {                                            \
                PyObject *o = PyUnicode_FromString(str);        \
                if (o != NULL)                          \
                        PyList_Append(list, o);         \
                Py_XDECREF(o);                          \
        } while (0)
#define BUF_SIZE   2048

Definition at line 795 of file pyexpat.c.

#define CHARACTER_DATA_BUFFER_SIZE   8192

Definition at line 63 of file pyexpat.c.

#define FIX_TRACE

Definition at line 11 of file pyexpat.c.

#define INT_HANDLER (   NAME,
  PARAMS,
  PARAM_FORMAT 
)
Value:
RC_HANDLER(int, NAME, PARAMS, int rc=0;, PARAM_FORMAT, \
                        rc = PyLong_AsLong(rv);, rc, \
        (xmlparseobject *)userData)

Definition at line 541 of file pyexpat.c.

#define MODULE_INITFUNC   PyInit_pyexpat

Definition at line 1631 of file pyexpat.c.

#define MODULE_NAME   "pyexpat"

Definition at line 1627 of file pyexpat.c.

#define MYCONST (   name)
Value:
if (PyModule_AddStringConstant(errors_module, #name,               \
                                   (char *)XML_ErrorString(name)) < 0) \
        return NULL;                                                   \
    tmpnum = PyLong_FromLong(name);                                    \
    if (tmpnum == NULL) return NULL;                                   \
    res = PyDict_SetItemString(codes_dict,                             \
                               XML_ErrorString(name), tmpnum);         \
    if (res < 0) return NULL;                                          \
    tmpstr = PyUnicode_FromString(XML_ErrorString(name));              \
    if (tmpstr == NULL) return NULL;                                   \
    res = PyDict_SetItem(rev_codes_dict, tmpnum, tmpstr);              \
    Py_DECREF(tmpstr);                                                 \
    Py_DECREF(tmpnum);                                                 \
    if (res < 0) return NULL;                                          \
#define MYCONST (   c)    PyModule_AddIntConstant(m, #c, c)
#define MYCONST (   c)    PyModule_AddIntConstant(model_module, #c, c)
#define PyMODINIT_FUNC   void

Definition at line 1638 of file pyexpat.c.

#define RC_HANDLER (   RC,
  NAME,
  PARAMS,
  INIT,
  PARAM_FORMAT,
  CONVERSION,
  RETURN,
  GETUSERDATA 
)
Value:
static RC \
my_##NAME##Handler PARAMS {\
    xmlparseobject *self = GETUSERDATA ; \
    PyObject *args = NULL; \
    PyObject *rv = NULL; \
    INIT \
\
    if (have_handler(self, NAME)) { \
        if (flush_character_buffer(self) < 0) \
            return RETURN; \
        args = Py_BuildValue PARAM_FORMAT ;\
        if (!args) { flag_error(self); return RETURN;} \
        self->in_callback = 1; \
        rv = call_with_frame(getcode(NAME,#NAME,__LINE__), \
                             self->handlers[NAME], args, self); \
        self->in_callback = 0; \
        Py_DECREF(args); \
        if (rv == NULL) { \
            flag_error(self); \
            return RETURN; \
        } \
        CONVERSION \
        Py_DECREF(rv); \
    } \
    return RETURN; \
}

Definition at line 508 of file pyexpat.c.

#define VOID_HANDLER (   NAME,
  PARAMS,
  PARAM_FORMAT 
)
Value:
RC_HANDLER(void, NAME, PARAMS, ;, PARAM_FORMAT, ;, ;,\
        (xmlparseobject *)userData)

Definition at line 537 of file pyexpat.c.

Definition at line 9 of file pyexpat.c.


Typedef Documentation

typedef void* xmlhandler

Definition at line 68 of file pyexpat.c.

Definition at line 67 of file pyexpat.c.


Enumeration Type Documentation

Enumerator:
StartElement 
EndElement 
ProcessingInstruction 
CharacterData 
UnparsedEntityDecl 
NotationDecl 
StartNamespaceDecl 
EndNamespaceDecl 
Comment 
StartCdataSection 
EndCdataSection 
Default 
DefaultHandlerExpand 
NotStandalone 
ExternalEntityRef 
StartDoctypeDecl 
EndDoctypeDecl 
EntityDecl 
XmlDecl 
ElementDecl 
AttlistDecl 
_DummyDecl 

Definition at line 13 of file pyexpat.c.


Function Documentation

static int call_character_handler ( xmlparseobject self,
const XML_Char buffer,
int  len 
) [static]

Definition at line 349 of file pyexpat.c.

{
    PyObject *args;
    PyObject *temp;

    if (!have_handler(self, CharacterData))
        return -1;

    args = PyTuple_New(1);
    if (args == NULL)
        return -1;
    temp = (conv_string_len_to_unicode(buffer, len));
    if (temp == NULL) {
        Py_DECREF(args);
        flag_error(self);
        XML_SetCharacterDataHandler(self->itself,
                                    noop_character_data_handler);
        return -1;
    }
    PyTuple_SET_ITEM(args, 0, temp);
    /* temp is now a borrowed reference; consider it unused. */
    self->in_callback = 1;
    temp = call_with_frame(getcode(CharacterData, "CharacterData", __LINE__),
                           self->handlers[CharacterData], args, self);
    /* temp is an owned reference again, or NULL */
    self->in_callback = 0;
    Py_DECREF(args);
    if (temp == NULL) {
        flag_error(self);
        XML_SetCharacterDataHandler(self->itself,
                                    noop_character_data_handler);
        return -1;
    }
    Py_DECREF(temp);
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* call_with_frame ( PyCodeObject c,
PyObject func,
PyObject args,
xmlparseobject self 
) [static]

Definition at line 280 of file pyexpat.c.

{
    PyThreadState *tstate = PyThreadState_GET();
    PyFrameObject *f;
    PyObject *res;

    if (c == NULL)
        return NULL;

    f = PyFrame_New(tstate, c, PyEval_GetGlobals(), NULL);
    if (f == NULL)
        return NULL;
    tstate->frame = f;
#ifdef FIX_TRACE
    if (trace_frame(tstate, f, PyTrace_CALL, Py_None) < 0) {
        return NULL;
    }
#endif
    res = PyEval_CallObject(func, args);
    if (res == NULL) {
        if (tstate->curexc_traceback == NULL)
            PyTraceBack_Here(f);
        XML_StopParser(self->itself, XML_FALSE);
#ifdef FIX_TRACE
        if (trace_frame_exc(tstate, f) < 0) {
            return NULL;
        }
    }
    else {
        if (trace_frame(tstate, f, PyTrace_RETURN, res) < 0) {
            Py_XDECREF(res);
            res = NULL;
        }
    }
#else
    }
#endif
    tstate->frame = f->f_back;
    Py_DECREF(f);
    return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void clear_handlers ( xmlparseobject self,
int  initial 
) [static]

Definition at line 1906 of file pyexpat.c.

{
    int i = 0;
    PyObject *temp;

    for (; handler_info[i].name != NULL; i++) {
        if (initial)
            self->handlers[i] = NULL;
        else {
            temp = self->handlers[i];
            self->handlers[i] = NULL;
            Py_XDECREF(temp);
            handler_info[i].setter(self->itself, NULL);
        }
    }
}

Here is the caller graph for this function:

static PyObject* conv_string_len_to_unicode ( const XML_Char str,
int  len 
) [static]

Definition at line 160 of file pyexpat.c.

{
    /* XXX currently this code assumes that XML_Char is 8-bit,
       and hence in UTF-8.  */
    /* UTF-8 from Expat, Unicode desired */
    if (str == NULL) {
        Py_INCREF(Py_None);
        return Py_None;
    }
    return PyUnicode_DecodeUTF8((const char *)str, len, "strict");
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* conv_string_to_unicode ( const XML_Char str) [static]

Definition at line 147 of file pyexpat.c.

{
    /* XXX currently this code assumes that XML_Char is 8-bit,
       and hence in UTF-8.  */
    /* UTF-8 from Expat, Unicode desired */
    if (str == NULL) {
        Py_INCREF(Py_None);
        return Py_None;
    }
    return PyUnicode_DecodeUTF8(str, strlen(str), "strict");
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int error_external_entity_ref_handler ( XML_Parser  parser,
const XML_Char context,
const XML_Char base,
const XML_Char systemId,
const XML_Char publicId 
) [static]

Definition at line 180 of file pyexpat.c.

{
    return 0;
}

Here is the caller graph for this function:

static void flag_error ( xmlparseobject self) [static]

Definition at line 202 of file pyexpat.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static int flush_character_buffer ( xmlparseobject self) [static]

Definition at line 387 of file pyexpat.c.

{
    int rc;
    if (self->buffer == NULL || self->buffer_used == 0)
        return 0;
    rc = call_character_handler(self, self->buffer, self->buffer_used);
    self->buffer_used = 0;
    return rc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* get_handler_name ( struct HandlerInfo hinfo) [static]

Definition at line 131 of file pyexpat.c.

{
    PyObject *name = hinfo->nameobj;
    if (name == NULL) {
        name = PyUnicode_FromString(hinfo->name);
        hinfo->nameobj = name;
    }
    Py_XINCREF(name);
    return name;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* get_pybool ( int  istrue) [static]

Definition at line 1221 of file pyexpat.c.

{
    PyObject *result = istrue ? Py_True : Py_False;
    Py_INCREF(result);
    return result;
}

Here is the caller graph for this function:

static PyCodeObject* getcode ( enum HandlerTypes  slot,
char *  func_name,
int  lineno 
) [static]

Definition at line 210 of file pyexpat.c.

{
    if (handler_info[slot].tb_code == NULL) {
        handler_info[slot].tb_code =
            PyCode_NewEmpty(__FILE__, func_name, lineno);
    }
    return handler_info[slot].tb_code;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int handlername2int ( PyObject name) [static]

Definition at line 1208 of file pyexpat.c.

{
    int i;
    for (i = 0; handler_info[i].name != NULL; i++) {
        if (PyUnicode_CompareWithASCIIString(
                name, handler_info[i].name) == 0) {
            return i;
        }
    }
    return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int have_handler ( xmlparseobject self,
int  type 
) [static]

Definition at line 124 of file pyexpat.c.

{
    PyObject *handler = self->handlers[type];
    return handler != NULL;
}

Here is the caller graph for this function:

static void init_template_buffer ( void  ) [static]

Definition at line 1087 of file pyexpat.c.

{
    int i;
    for (i = 0; i < 256; i++) {
        template_buffer[i] = i;
    }
    template_buffer[256] = 0;
}

Here is the caller graph for this function:

Definition at line 1657 of file pyexpat.c.

{
    PyObject *m, *d;
    PyObject *errmod_name = PyUnicode_FromString(MODULE_NAME ".errors");
    PyObject *errors_module;
    PyObject *modelmod_name;
    PyObject *model_module;
    PyObject *version;
    PyObject *sys_modules;
    PyObject *tmpnum, *tmpstr;
    PyObject *codes_dict;
    PyObject *rev_codes_dict;
    int res;
    static struct PyExpat_CAPI capi;
    PyObject *capi_object;

    if (errmod_name == NULL)
        return NULL;
    modelmod_name = PyUnicode_FromString(MODULE_NAME ".model");
    if (modelmod_name == NULL)
        return NULL;

    if (PyType_Ready(&Xmlparsetype) < 0)
        return NULL;

    /* Create the module and add the functions */
    m = PyModule_Create(&pyexpatmodule);
    if (m == NULL)
        return NULL;

    /* Add some symbolic constants to the module */
    if (ErrorObject == NULL) {
        ErrorObject = PyErr_NewException("xml.parsers.expat.ExpatError",
                                         NULL, NULL);
        if (ErrorObject == NULL)
            return NULL;
    }
    Py_INCREF(ErrorObject);
    PyModule_AddObject(m, "error", ErrorObject);
    Py_INCREF(ErrorObject);
    PyModule_AddObject(m, "ExpatError", ErrorObject);
    Py_INCREF(&Xmlparsetype);
    PyModule_AddObject(m, "XMLParserType", (PyObject *) &Xmlparsetype);

    version = PyUnicode_FromString(PY_VERSION);
    if (!version)
        return NULL;
    PyModule_AddObject(m, "__version__", version);
    PyModule_AddStringConstant(m, "EXPAT_VERSION",
                               (char *) XML_ExpatVersion());
    {
        XML_Expat_Version info = XML_ExpatVersionInfo();
        PyModule_AddObject(m, "version_info",
                           Py_BuildValue("(iii)", info.major,
                                         info.minor, info.micro));
    }
    init_template_buffer();
    /* XXX When Expat supports some way of figuring out how it was
       compiled, this should check and set native_encoding
       appropriately.
    */
    PyModule_AddStringConstant(m, "native_encoding", "UTF-8");

    sys_modules = PySys_GetObject("modules");
    d = PyModule_GetDict(m);
    errors_module = PyDict_GetItem(d, errmod_name);
    if (errors_module == NULL) {
        errors_module = PyModule_New(MODULE_NAME ".errors");
        if (errors_module != NULL) {
            PyDict_SetItem(sys_modules, errmod_name, errors_module);
            /* gives away the reference to errors_module */
            PyModule_AddObject(m, "errors", errors_module);
        }
    }
    Py_DECREF(errmod_name);
    model_module = PyDict_GetItem(d, modelmod_name);
    if (model_module == NULL) {
        model_module = PyModule_New(MODULE_NAME ".model");
        if (model_module != NULL) {
            PyDict_SetItem(sys_modules, modelmod_name, model_module);
            /* gives away the reference to model_module */
            PyModule_AddObject(m, "model", model_module);
        }
    }
    Py_DECREF(modelmod_name);
    if (errors_module == NULL || model_module == NULL)
        /* Don't core dump later! */
        return NULL;

#if XML_COMBINED_VERSION > 19505
    {
        const XML_Feature *features = XML_GetFeatureList();
        PyObject *list = PyList_New(0);
        if (list == NULL)
            /* just ignore it */
            PyErr_Clear();
        else {
            int i = 0;
            for (; features[i].feature != XML_FEATURE_END; ++i) {
                int ok;
                PyObject *item = Py_BuildValue("si", features[i].name,
                                               features[i].value);
                if (item == NULL) {
                    Py_DECREF(list);
                    list = NULL;
                    break;
                }
                ok = PyList_Append(list, item);
                Py_DECREF(item);
                if (ok < 0) {
                    PyErr_Clear();
                    break;
                }
            }
            if (list != NULL)
                PyModule_AddObject(m, "features", list);
        }
    }
#endif

    codes_dict = PyDict_New();
    rev_codes_dict = PyDict_New();
    if (codes_dict == NULL || rev_codes_dict == NULL) {
        Py_XDECREF(codes_dict);
        Py_XDECREF(rev_codes_dict);
        return NULL;
    }

#define MYCONST(name) \
    if (PyModule_AddStringConstant(errors_module, #name,               \
                                   (char *)XML_ErrorString(name)) < 0) \
        return NULL;                                                   \
    tmpnum = PyLong_FromLong(name);                                    \
    if (tmpnum == NULL) return NULL;                                   \
    res = PyDict_SetItemString(codes_dict,                             \
                               XML_ErrorString(name), tmpnum);         \
    if (res < 0) return NULL;                                          \
    tmpstr = PyUnicode_FromString(XML_ErrorString(name));              \
    if (tmpstr == NULL) return NULL;                                   \
    res = PyDict_SetItem(rev_codes_dict, tmpnum, tmpstr);              \
    Py_DECREF(tmpstr);                                                 \
    Py_DECREF(tmpnum);                                                 \
    if (res < 0) return NULL;                                          \

    MYCONST(XML_ERROR_NO_MEMORY);
    MYCONST(XML_ERROR_SYNTAX);
    MYCONST(XML_ERROR_NO_ELEMENTS);
    MYCONST(XML_ERROR_INVALID_TOKEN);
    MYCONST(XML_ERROR_UNCLOSED_TOKEN);
    MYCONST(XML_ERROR_PARTIAL_CHAR);
    MYCONST(XML_ERROR_TAG_MISMATCH);
    MYCONST(XML_ERROR_DUPLICATE_ATTRIBUTE);
    MYCONST(XML_ERROR_JUNK_AFTER_DOC_ELEMENT);
    MYCONST(XML_ERROR_PARAM_ENTITY_REF);
    MYCONST(XML_ERROR_UNDEFINED_ENTITY);
    MYCONST(XML_ERROR_RECURSIVE_ENTITY_REF);
    MYCONST(XML_ERROR_ASYNC_ENTITY);
    MYCONST(XML_ERROR_BAD_CHAR_REF);
    MYCONST(XML_ERROR_BINARY_ENTITY_REF);
    MYCONST(XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF);
    MYCONST(XML_ERROR_MISPLACED_XML_PI);
    MYCONST(XML_ERROR_UNKNOWN_ENCODING);
    MYCONST(XML_ERROR_INCORRECT_ENCODING);
    MYCONST(XML_ERROR_UNCLOSED_CDATA_SECTION);
    MYCONST(XML_ERROR_EXTERNAL_ENTITY_HANDLING);
    MYCONST(XML_ERROR_NOT_STANDALONE);
    MYCONST(XML_ERROR_UNEXPECTED_STATE);
    MYCONST(XML_ERROR_ENTITY_DECLARED_IN_PE);
    MYCONST(XML_ERROR_FEATURE_REQUIRES_XML_DTD);
    MYCONST(XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING);
    /* Added in Expat 1.95.7. */
    MYCONST(XML_ERROR_UNBOUND_PREFIX);
    /* Added in Expat 1.95.8. */
    MYCONST(XML_ERROR_UNDECLARING_PREFIX);
    MYCONST(XML_ERROR_INCOMPLETE_PE);
    MYCONST(XML_ERROR_XML_DECL);
    MYCONST(XML_ERROR_TEXT_DECL);
    MYCONST(XML_ERROR_PUBLICID);
    MYCONST(XML_ERROR_SUSPENDED);
    MYCONST(XML_ERROR_NOT_SUSPENDED);
    MYCONST(XML_ERROR_ABORTED);
    MYCONST(XML_ERROR_FINISHED);
    MYCONST(XML_ERROR_SUSPEND_PE);

    if (PyModule_AddStringConstant(errors_module, "__doc__",
                                   "Constants used to describe "
                                   "error conditions.") < 0)
        return NULL;

    if (PyModule_AddObject(errors_module, "codes", codes_dict) < 0)
        return NULL;
    if (PyModule_AddObject(errors_module, "messages", rev_codes_dict) < 0)
        return NULL;

#undef MYCONST

#define MYCONST(c) PyModule_AddIntConstant(m, #c, c)
    MYCONST(XML_PARAM_ENTITY_PARSING_NEVER);
    MYCONST(XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE);
    MYCONST(XML_PARAM_ENTITY_PARSING_ALWAYS);
#undef MYCONST

#define MYCONST(c) PyModule_AddIntConstant(model_module, #c, c)
    PyModule_AddStringConstant(model_module, "__doc__",
                     "Constants used to interpret content model information.");

    MYCONST(XML_CTYPE_EMPTY);
    MYCONST(XML_CTYPE_ANY);
    MYCONST(XML_CTYPE_MIXED);
    MYCONST(XML_CTYPE_NAME);
    MYCONST(XML_CTYPE_CHOICE);
    MYCONST(XML_CTYPE_SEQ);

    MYCONST(XML_CQUANT_NONE);
    MYCONST(XML_CQUANT_OPT);
    MYCONST(XML_CQUANT_REP);
    MYCONST(XML_CQUANT_PLUS);
#undef MYCONST

    /* initialize pyexpat dispatch table */
    capi.size = sizeof(capi);
    capi.magic = PyExpat_CAPI_MAGIC;
    capi.MAJOR_VERSION = XML_MAJOR_VERSION;
    capi.MINOR_VERSION = XML_MINOR_VERSION;
    capi.MICRO_VERSION = XML_MICRO_VERSION;
    capi.ErrorString = XML_ErrorString;
    capi.GetErrorCode = XML_GetErrorCode;
    capi.GetErrorColumnNumber = XML_GetErrorColumnNumber;
    capi.GetErrorLineNumber = XML_GetErrorLineNumber;
    capi.Parse = XML_Parse;
    capi.ParserCreate_MM = XML_ParserCreate_MM;
    capi.ParserFree = XML_ParserFree;
    capi.SetCharacterDataHandler = XML_SetCharacterDataHandler;
    capi.SetCommentHandler = XML_SetCommentHandler;
    capi.SetDefaultHandlerExpand = XML_SetDefaultHandlerExpand;
    capi.SetElementHandler = XML_SetElementHandler;
    capi.SetNamespaceDeclHandler = XML_SetNamespaceDeclHandler;
    capi.SetProcessingInstructionHandler = XML_SetProcessingInstructionHandler;
    capi.SetUnknownEncodingHandler = XML_SetUnknownEncodingHandler;
    capi.SetUserData = XML_SetUserData;

    /* export using capsule */
    capi_object = PyCapsule_New(&capi, PyExpat_CAPSULE_NAME, NULL);
    if (capi_object)
        PyModule_AddObject(m, "expat_CAPI", capi_object);
    return m;
}

Here is the call graph for this function:

static void my_CharacterDataHandler ( void userData,
const XML_Char data,
int  len 
) [static]

Definition at line 398 of file pyexpat.c.

{
    xmlparseobject *self = (xmlparseobject *) userData;
    if (self->buffer == NULL)
        call_character_handler(self, data, len);
    else {
        if ((self->buffer_used + len) > self->buffer_size) {
            if (flush_character_buffer(self) < 0)
                return;
            /* handler might have changed; drop the rest on the floor
             * if there isn't a handler anymore
             */
            if (!have_handler(self, CharacterData))
                return;
        }
        if (len > self->buffer_size) {
            call_character_handler(self, data, len);
            self->buffer_used = 0;
        }
        else {
            memcpy(self->buffer + self->buffer_used,
                   data, len * sizeof(XML_Char));
            self->buffer_used += len;
        }
    }
}

Here is the call graph for this function:

static void my_ElementDeclHandler ( void userData,
const XML_Char name,
XML_Content *  model 
) [static]

Definition at line 621 of file pyexpat.c.

{
    xmlparseobject *self = (xmlparseobject *)userData;
    PyObject *args = NULL;

    if (have_handler(self, ElementDecl)) {
        PyObject *rv = NULL;
        PyObject *modelobj, *nameobj;

        if (flush_character_buffer(self) < 0)
            goto finally;
        modelobj = conv_content_model(model, (conv_string_to_unicode));
        if (modelobj == NULL) {
            flag_error(self);
            goto finally;
        }
        nameobj = string_intern(self, name);
        if (nameobj == NULL) {
            Py_DECREF(modelobj);
            flag_error(self);
            goto finally;
        }
        args = Py_BuildValue("NN", nameobj, modelobj);
        if (args == NULL) {
            Py_DECREF(modelobj);
            flag_error(self);
            goto finally;
        }
        self->in_callback = 1;
        rv = call_with_frame(getcode(ElementDecl, "ElementDecl", __LINE__),
                             self->handlers[ElementDecl], args, self);
        self->in_callback = 0;
        if (rv == NULL) {
            flag_error(self);
            goto finally;
        }
        Py_DECREF(rv);
    }
 finally:
    Py_XDECREF(args);
    XML_FreeContentModel(self->itself, model);
    return;
}

Here is the call graph for this function:

static void my_StartElementHandler ( void userData,
const XML_Char name,
const XML_Char atts[] 
) [static]

Definition at line 426 of file pyexpat.c.

{
    xmlparseobject *self = (xmlparseobject *)userData;

    if (have_handler(self, StartElement)) {
        PyObject *container, *rv, *args;
        int i, max;

        if (flush_character_buffer(self) < 0)
            return;
        /* Set max to the number of slots filled in atts[]; max/2 is
         * the number of attributes we need to process.
         */
        if (self->specified_attributes) {
            max = XML_GetSpecifiedAttributeCount(self->itself);
        }
        else {
            max = 0;
            while (atts[max] != NULL)
                max += 2;
        }
        /* Build the container. */
        if (self->ordered_attributes)
            container = PyList_New(max);
        else
            container = PyDict_New();
        if (container == NULL) {
            flag_error(self);
            return;
        }
        for (i = 0; i < max; i += 2) {
            PyObject *n = string_intern(self, (XML_Char *) atts[i]);
            PyObject *v;
            if (n == NULL) {
                flag_error(self);
                Py_DECREF(container);
                return;
            }
            v = conv_string_to_unicode((XML_Char *) atts[i+1]);
            if (v == NULL) {
                flag_error(self);
                Py_DECREF(container);
                Py_DECREF(n);
                return;
            }
            if (self->ordered_attributes) {
                PyList_SET_ITEM(container, i, n);
                PyList_SET_ITEM(container, i+1, v);
            }
            else if (PyDict_SetItem(container, n, v)) {
                flag_error(self);
                Py_DECREF(n);
                Py_DECREF(v);
                return;
            }
            else {
                Py_DECREF(n);
                Py_DECREF(v);
            }
        }
        args = string_intern(self, name);
        if (args != NULL)
            args = Py_BuildValue("(NN)", args, container);
        if (args == NULL) {
            Py_DECREF(container);
            return;
        }
        /* Container is now a borrowed reference; ignore it. */
        self->in_callback = 1;
        rv = call_with_frame(getcode(StartElement, "StartElement", __LINE__),
                             self->handlers[StartElement], args, self);
        self->in_callback = 0;
        Py_DECREF(args);
        if (rv == NULL) {
            flag_error(self);
            return;
        }
        Py_DECREF(rv);
    }
}

Here is the call graph for this function:

static PyObject* newxmlparseobject ( char *  encoding,
char *  namespace_separator,
PyObject intern 
) [static]

Definition at line 1130 of file pyexpat.c.

{
    int i;
    xmlparseobject *self;

    self = PyObject_GC_New(xmlparseobject, &Xmlparsetype);
    if (self == NULL)
        return NULL;

    self->buffer = NULL;
    self->buffer_size = CHARACTER_DATA_BUFFER_SIZE;
    self->buffer_used = 0;
    self->ordered_attributes = 0;
    self->specified_attributes = 0;
    self->in_callback = 0;
    self->ns_prefixes = 0;
    self->handlers = NULL;
    if (namespace_separator != NULL) {
        self->itself = XML_ParserCreateNS(encoding, *namespace_separator);
    }
    else {
        self->itself = XML_ParserCreate(encoding);
    }
    self->intern = intern;
    Py_XINCREF(self->intern);
    PyObject_GC_Track(self);
    if (self->itself == NULL) {
        PyErr_SetString(PyExc_RuntimeError,
                        "XML_ParserCreate failed");
        Py_DECREF(self);
        return NULL;
    }
    XML_SetUserData(self->itself, (void *)self);
    XML_SetUnknownEncodingHandler(self->itself,
                  (XML_UnknownEncodingHandler) PyUnknownEncodingHandler, NULL);

    for (i = 0; handler_info[i].name != NULL; i++)
        /* do nothing */;

    self->handlers = malloc(sizeof(PyObject *) * i);
    if (!self->handlers) {
        Py_DECREF(self);
        return PyErr_NoMemory();
    }
    clear_handlers(self, 1);

    return (PyObject*)self;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void noop_character_data_handler ( void userData,
const XML_Char data,
int  len 
) [static]

Definition at line 196 of file pyexpat.c.

{
    /* Do nothing. */
}

Here is the caller graph for this function:

PyDoc_STRVAR ( xmlparse_Parse__doc__  ,
"Parse(data[, isfinal])\n\Parse XML data. `isfinal' should be true at end of input."   
)
PyDoc_STRVAR ( xmlparse_ParseFile__doc__  ,
"ParseFile(file)\n\Parse XML data from file-like object."   
)
PyDoc_STRVAR ( xmlparse_SetBase__doc__  ,
"SetBase(base_url)\n\Set the base URL for the parser."   
)
PyDoc_STRVAR ( xmlparse_GetBase__doc__  ,
"GetBase() -> url\n\Return base URL string for the parser."   
)
PyDoc_STRVAR ( xmlparse_GetInputContext__doc__  ,
GetInputContext) -> string\n\Return the untranslated text of the input that caused the current event.\n\If the event was generated by a large amount of text (such as a start tag\n\for an element with many attributes,
not all of the text may be available."   
)
PyDoc_STRVAR ( xmlparse_ExternalEntityParserCreate__doc__  ,
"ExternalEntityParserCreate(context[, encoding])\n\Create a parser for parsing an external entity based on the\n\information passed to the ExternalEntityRefHandler."   
)
PyDoc_STRVAR ( xmlparse_SetParamEntityParsing__doc__  ,
"SetParamEntityParsing(flag) -> success\n\Controls parsing of parameter entities (including the external DTD\n\subset). Possible flag values are  XML_PARAM_ENTITY_PARSING_NEVER,
\n\XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE and\n\XML_PARAM_ENTITY_PARSING_ALWAYS.Returns true if setting the flag\n\was successful."   
)
PyDoc_STRVAR ( Xmlparsetype__doc__  ,
"XML parser"   
)
PyDoc_STRVAR ( pyexpat_ParserCreate__doc__  ,
"ParserCreate([encoding[, namespace_separator]]) -> parser\n\Return a new XML parser object."   
)
PyDoc_STRVAR ( pyexpat_ErrorString__doc__  ,
"ErrorString(errno) -> string\n\Returns string error for given number."   
)
PyDoc_STRVAR ( pyexpat_module_documentation  ,
"Python wrapper for Expat parser."   
)
static PyObject* pyexpat_ErrorString ( PyObject self,
PyObject args 
) [static]

Definition at line 1599 of file pyexpat.c.

{
    long code = 0;

    if (!PyArg_ParseTuple(args, "l:ErrorString", &code))
        return NULL;
    return Py_BuildValue("z", XML_ErrorString((int)code));
}

Here is the call graph for this function:

static PyObject* pyexpat_ParserCreate ( PyObject notused,
PyObject args,
PyObject kw 
) [static]

Definition at line 1552 of file pyexpat.c.

{
    char *encoding = NULL;
    char *namespace_separator = NULL;
    PyObject *intern = NULL;
    PyObject *result;
    int intern_decref = 0;
    static char *kwlist[] = {"encoding", "namespace_separator",
                                   "intern", NULL};

    if (!PyArg_ParseTupleAndKeywords(args, kw, "|zzO:ParserCreate", kwlist,
                                     &encoding, &namespace_separator, &intern))
        return NULL;
    if (namespace_separator != NULL
        && strlen(namespace_separator) > 1) {
        PyErr_SetString(PyExc_ValueError,
                        "namespace_separator must be at most one"
                        " character, omitted, or None");
        return NULL;
    }
    /* Explicitly passing None means no interning is desired.
       Not passing anything means that a new dictionary is used. */
    if (intern == Py_None)
        intern = NULL;
    else if (intern == NULL) {
        intern = PyDict_New();
        if (!intern)
            return NULL;
        intern_decref = 1;
    }
    else if (!PyDict_Check(intern)) {
        PyErr_SetString(PyExc_TypeError, "intern must be a dictionary");
        return NULL;
    }

    result = newxmlparseobject(encoding, namespace_separator, intern);
    if (intern_decref) {
        Py_DECREF(intern);
    }
    return result;
}

Here is the call graph for this function:

static int PyUnknownEncodingHandler ( void encodingHandlerData,
const XML_Char name,
XML_Encoding info 
) [static]

Definition at line 1097 of file pyexpat.c.

{
    PyUnicodeObject *_u_string = NULL;
    int result = 0;
    int i;

    /* Yes, supports only 8bit encodings */
    _u_string = (PyUnicodeObject *)
        PyUnicode_Decode(template_buffer, 256, name, "replace");

    if (_u_string == NULL)
        return result;

    for (i = 0; i < 256; i++) {
        /* Stupid to access directly, but fast */
        Py_UNICODE c = _u_string->str[i];
        if (c == Py_UNICODE_REPLACEMENT_CHARACTER)
            info->map[i] = -1;
        else
            info->map[i] = c;
    }
    info->data = NULL;
    info->convert = NULL;
    info->release = NULL;
    result = 1;
    Py_DECREF(_u_string);
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int readinst ( char *  buf,
int  buf_size,
PyObject meth 
) [static]

Definition at line 798 of file pyexpat.c.

{
    PyObject *str;
    Py_ssize_t len;
    char *ptr;

    str = PyObject_CallFunction(meth, "n", buf_size);
    if (str == NULL)
        goto error;

    if (PyBytes_Check(str))
        ptr = PyBytes_AS_STRING(str);
    else if (PyByteArray_Check(str))
        ptr = PyByteArray_AS_STRING(str);
    else {
        PyErr_Format(PyExc_TypeError,
                     "read() did not return a bytes object (type=%.400s)",
                     Py_TYPE(str)->tp_name);
        goto error;
    }
    len = Py_SIZE(str);
    if (len > buf_size) {
        PyErr_Format(PyExc_ValueError,
                     "read() returned too much data: "
                     "%i bytes requested, %zd returned",
                     buf_size, len);
        goto error;
    }
    memcpy(buf, ptr, len);
    Py_DECREF(str);
    /* len <= buf_size <= INT_MAX */
    return (int)len;

error:
    Py_XDECREF(str);
    return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* set_error ( xmlparseobject self,
enum XML_Error  code 
) [static]

Definition at line 100 of file pyexpat.c.

{
    PyObject *err;
    char buffer[256];
    XML_Parser parser = self->itself;
    int lineno = XML_GetErrorLineNumber(parser);
    int column = XML_GetErrorColumnNumber(parser);

    /* There is no risk of overflowing this buffer, since
       even for 64-bit integers, there is sufficient space. */
    sprintf(buffer, "%.200s: line %i, column %i",
            XML_ErrorString(code), lineno, column);
    err = PyObject_CallFunction(ErrorObject, "s", buffer);
    if (  err != NULL
          && set_error_attr(err, "code", code)
          && set_error_attr(err, "offset", column)
          && set_error_attr(err, "lineno", lineno)) {
        PyErr_SetObject(ErrorObject, err);
    }
    Py_XDECREF(err);
    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int set_error_attr ( PyObject err,
char *  name,
int  value 
) [static]

Definition at line 84 of file pyexpat.c.

{
    PyObject *v = PyLong_FromLong(value);

    if (v == NULL || PyObject_SetAttrString(err, name, v) == -1) {
        Py_XDECREF(v);
        return 0;
    }
    Py_DECREF(v);
    return 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int sethandler ( xmlparseobject self,
PyObject name,
PyObject v 
) [static]

Definition at line 1348 of file pyexpat.c.

{
    int handlernum = handlername2int(name);
    if (handlernum >= 0) {
        xmlhandler c_handler = NULL;
        PyObject *temp = self->handlers[handlernum];

        if (v == Py_None) {
            /* If this is the character data handler, and a character
               data handler is already active, we need to be more
               careful.  What we can safely do is replace the existing
               character data handler callback function with a no-op
               function that will refuse to call Python.  The downside
               is that this doesn't completely remove the character
               data handler from the C layer if there's any callback
               active, so Expat does a little more work than it
               otherwise would, but that's really an odd case.  A more
               elaborate system of handlers and state could remove the
               C handler more effectively. */
            if (handlernum == CharacterData && self->in_callback)
                c_handler = noop_character_data_handler;
            v = NULL;
        }
        else if (v != NULL) {
            Py_INCREF(v);
            c_handler = handler_info[handlernum].handler;
        }
        self->handlers[handlernum] = v;
        Py_XDECREF(temp);
        handler_info[handlernum].setter(self->itself, c_handler);
        return 1;
    }
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* string_intern ( xmlparseobject self,
const char *  str 
) [static]

Definition at line 324 of file pyexpat.c.

{
    PyObject *result = conv_string_to_unicode(str);
    PyObject *value;
    /* result can be NULL if the unicode conversion failed. */
    if (!result)
        return result;
    if (!self->intern)
        return result;
    value = PyDict_GetItem(self->intern, result);
    if (!value) {
        if (PyDict_SetItem(self->intern, result, result) == 0)
            return result;
        else
            return NULL;
    }
    Py_INCREF(value);
    Py_DECREF(result);
    return value;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int trace_frame ( PyThreadState tstate,
PyFrameObject f,
int  code,
PyObject val 
) [static]

Definition at line 221 of file pyexpat.c.

{
    int result = 0;
    if (!tstate->use_tracing || tstate->tracing)
        return 0;
    if (tstate->c_profilefunc != NULL) {
        tstate->tracing++;
        result = tstate->c_profilefunc(tstate->c_profileobj,
                                       f, code , val);
        tstate->use_tracing = ((tstate->c_tracefunc != NULL)
                               || (tstate->c_profilefunc != NULL));
        tstate->tracing--;
        if (result)
            return result;
    }
    if (tstate->c_tracefunc != NULL) {
        tstate->tracing++;
        result = tstate->c_tracefunc(tstate->c_traceobj,
                                     f, code , val);
        tstate->use_tracing = ((tstate->c_tracefunc != NULL)
                               || (tstate->c_profilefunc != NULL));
        tstate->tracing--;
    }
    return result;
}

Here is the caller graph for this function:

static int trace_frame_exc ( PyThreadState tstate,
PyFrameObject f 
) [static]

Definition at line 248 of file pyexpat.c.

{
    PyObject *type, *value, *traceback, *arg;
    int err;

    if (tstate->c_tracefunc == NULL)
        return 0;

    PyErr_Fetch(&type, &value, &traceback);
    if (value == NULL) {
        value = Py_None;
        Py_INCREF(value);
    }
    arg = PyTuple_Pack(3, type, value, traceback);
    if (arg == NULL) {
        PyErr_Restore(type, value, traceback);
        return 0;
    }
    err = trace_frame(tstate, f, PyTrace_EXCEPTION, arg);
    Py_DECREF(arg);
    if (err == 0)
        PyErr_Restore(type, value, traceback);
    else {
        Py_XDECREF(type);
        Py_XDECREF(value);
        Py_XDECREF(traceback);
    }
    return err;
}

Here is the call graph for this function:

Here is the caller graph for this function:

VOID_HANDLER ( EndElement  ,
(void *userData, const XML_Char *name ,
("(N)", string_intern(self, name))   
)

Definition at line 546 of file pyexpat.c.

{
    PyObject *result = NULL;
    PyObject *children = PyTuple_New(model->numchildren);
    int i;

    if (children != NULL) {
        assert(model->numchildren < INT_MAX);
        for (i = 0; i < (int)model->numchildren; ++i) {
            PyObject *child = conv_content_model(&model->children[i],
                                                 conv_string);
            if (child == NULL) {
                Py_XDECREF(children);
                return NULL;
            }
            PyTuple_SET_ITEM(children, i, child);
        }
        result = Py_BuildValue("(iiO&N)",
                               model->type, model->quant,
                               conv_string,model->name, children);
    }
    return result;
}

Here is the call graph for this function:

Definition at line 667 of file pyexpat.c.

{
    if (PyErr_Occurred()) {
        return NULL;
    }
    if (rv == 0) {
        return set_error(self, XML_GetErrorCode(self->itself));
    }
    if (flush_character_buffer(self) < 0) {
        return NULL;
    }
    return PyLong_FromLong(rv);
}

Here is the call graph for this function:

static int xmlparse_clear ( xmlparseobject op) [static]

Definition at line 1503 of file pyexpat.c.

{
    clear_handlers(op, 0);
    Py_CLEAR(op->intern);
    return 0;
}

Here is the call graph for this function:

static void xmlparse_dealloc ( xmlparseobject self) [static]

Definition at line 1181 of file pyexpat.c.

{
    int i;
    PyObject_GC_UnTrack(self);
    if (self->itself != NULL)
        XML_ParserFree(self->itself);
    self->itself = NULL;

    if (self->handlers != NULL) {
        PyObject *temp;
        for (i = 0; handler_info[i].name != NULL; i++) {
            temp = self->handlers[i];
            self->handlers[i] = NULL;
            Py_XDECREF(temp);
        }
        free(self->handlers);
        self->handlers = NULL;
    }
    if (self->buffer != NULL) {
        free(self->buffer);
        self->buffer = NULL;
    }
    Py_XDECREF(self->intern);
    PyObject_GC_Del(self);
}

Here is the call graph for this function:

static PyObject * xmlparse_dir ( PyObject self,
PyObject noargs 
) [static]

Definition at line 1302 of file pyexpat.c.

{
#define APPEND(list, str)                               \
        do {                                            \
                PyObject *o = PyUnicode_FromString(str);        \
                if (o != NULL)                          \
                        PyList_Append(list, o);         \
                Py_XDECREF(o);                          \
        } while (0)

    int i;
    PyObject *rc = PyList_New(0);
    if (!rc)
        return NULL;
    for (i = 0; handler_info[i].name != NULL; i++) {
        PyObject *o = get_handler_name(&handler_info[i]);
        if (o != NULL)
            PyList_Append(rc, o);
        Py_XDECREF(o);
    }
    APPEND(rc, "ErrorCode");
    APPEND(rc, "ErrorLineNumber");
    APPEND(rc, "ErrorColumnNumber");
    APPEND(rc, "ErrorByteIndex");
    APPEND(rc, "CurrentLineNumber");
    APPEND(rc, "CurrentColumnNumber");
    APPEND(rc, "CurrentByteIndex");
    APPEND(rc, "buffer_size");
    APPEND(rc, "buffer_text");
    APPEND(rc, "buffer_used");
    APPEND(rc, "namespace_prefixes");
    APPEND(rc, "ordered_attributes");
    APPEND(rc, "specified_attributes");
    APPEND(rc, "intern");

#undef APPEND

    if (PyErr_Occurred()) {
        Py_DECREF(rc);
        rc = NULL;
    }

    return rc;
}

Here is the call graph for this function:

static PyObject* xmlparse_ExternalEntityParserCreate ( xmlparseobject self,
PyObject args 
) [static]

Definition at line 937 of file pyexpat.c.

{
    char *context;
    char *encoding = NULL;
    xmlparseobject *new_parser;
    int i;

    if (!PyArg_ParseTuple(args, "z|s:ExternalEntityParserCreate",
                          &context, &encoding)) {
        return NULL;
    }

    new_parser = PyObject_GC_New(xmlparseobject, &Xmlparsetype);
    if (new_parser == NULL)
        return NULL;
    new_parser->buffer_size = self->buffer_size;
    new_parser->buffer_used = 0;
    new_parser->buffer = NULL;
    new_parser->ordered_attributes = self->ordered_attributes;
    new_parser->specified_attributes = self->specified_attributes;
    new_parser->in_callback = 0;
    new_parser->ns_prefixes = self->ns_prefixes;
    new_parser->itself = XML_ExternalEntityParserCreate(self->itself, context,
                                                        encoding);
    new_parser->handlers = 0;
    new_parser->intern = self->intern;
    Py_XINCREF(new_parser->intern);
    PyObject_GC_Track(new_parser);

    if (self->buffer != NULL) {
        new_parser->buffer = malloc(new_parser->buffer_size);
        if (new_parser->buffer == NULL) {
            Py_DECREF(new_parser);
            return PyErr_NoMemory();
        }
    }
    if (!new_parser->itself) {
        Py_DECREF(new_parser);
        return PyErr_NoMemory();
    }

    XML_SetUserData(new_parser->itself, (void *)new_parser);

    /* allocate and clear handlers first */
    for (i = 0; handler_info[i].name != NULL; i++)
        /* do nothing */;

    new_parser->handlers = malloc(sizeof(PyObject *) * i);
    if (!new_parser->handlers) {
        Py_DECREF(new_parser);
        return PyErr_NoMemory();
    }
    clear_handlers(new_parser, 1);

    /* then copy handlers from self */
    for (i = 0; handler_info[i].name != NULL; i++) {
        PyObject *handler = self->handlers[i];
        if (handler != NULL) {
            Py_INCREF(handler);
            new_parser->handlers[i] = handler;
            handler_info[i].setter(new_parser->itself,
                                   handler_info[i].handler);
        }
    }
    return (PyObject *)new_parser;
}

Here is the call graph for this function:

static PyObject* xmlparse_getattro ( xmlparseobject self,
PyObject nameobj 
) [static]

Definition at line 1229 of file pyexpat.c.

{
    Py_UNICODE *name;
    int handlernum = -1;

    if (!PyUnicode_Check(nameobj))
        goto generic;

    handlernum = handlername2int(nameobj);

    if (handlernum != -1) {
        PyObject *result = self->handlers[handlernum];
        if (result == NULL)
            result = Py_None;
        Py_INCREF(result);
        return result;
    }

    name = PyUnicode_AS_UNICODE(nameobj);
    if (name[0] == 'E') {
        if (PyUnicode_CompareWithASCIIString(nameobj, "ErrorCode") == 0)
            return PyLong_FromLong((long)
                                  XML_GetErrorCode(self->itself));
        if (PyUnicode_CompareWithASCIIString(nameobj, "ErrorLineNumber") == 0)
            return PyLong_FromLong((long)
                                  XML_GetErrorLineNumber(self->itself));
        if (PyUnicode_CompareWithASCIIString(nameobj, "ErrorColumnNumber") == 0)
            return PyLong_FromLong((long)
                                  XML_GetErrorColumnNumber(self->itself));
        if (PyUnicode_CompareWithASCIIString(nameobj, "ErrorByteIndex") == 0)
            return PyLong_FromLong((long)
                                  XML_GetErrorByteIndex(self->itself));
    }
    if (name[0] == 'C') {
        if (PyUnicode_CompareWithASCIIString(nameobj, "CurrentLineNumber") == 0)
            return PyLong_FromLong((long)
                                  XML_GetCurrentLineNumber(self->itself));
        if (PyUnicode_CompareWithASCIIString(nameobj, "CurrentColumnNumber") == 0)
            return PyLong_FromLong((long)
                                  XML_GetCurrentColumnNumber(self->itself));
        if (PyUnicode_CompareWithASCIIString(nameobj, "CurrentByteIndex") == 0)
            return PyLong_FromLong((long)
                                  XML_GetCurrentByteIndex(self->itself));
    }
    if (name[0] == 'b') {
        if (PyUnicode_CompareWithASCIIString(nameobj, "buffer_size") == 0)
            return PyLong_FromLong((long) self->buffer_size);
        if (PyUnicode_CompareWithASCIIString(nameobj, "buffer_text") == 0)
            return get_pybool(self->buffer != NULL);
        if (PyUnicode_CompareWithASCIIString(nameobj, "buffer_used") == 0)
            return PyLong_FromLong((long) self->buffer_used);
    }
    if (PyUnicode_CompareWithASCIIString(nameobj, "namespace_prefixes") == 0)
        return get_pybool(self->ns_prefixes);
    if (PyUnicode_CompareWithASCIIString(nameobj, "ordered_attributes") == 0)
        return get_pybool(self->ordered_attributes);
    if (PyUnicode_CompareWithASCIIString(nameobj, "specified_attributes") == 0)
        return get_pybool((long) self->specified_attributes);
    if (PyUnicode_CompareWithASCIIString(nameobj, "intern") == 0) {
        if (self->intern == NULL) {
            Py_INCREF(Py_None);
            return Py_None;
        }
        else {
            Py_INCREF(self->intern);
            return self->intern;
        }
    }
  generic:
    return PyObject_GenericGetAttr((PyObject*)self, nameobj);
}

Here is the call graph for this function:

static PyObject* xmlparse_GetBase ( xmlparseobject self,
PyObject unused 
) [static]

Definition at line 902 of file pyexpat.c.

{
    return Py_BuildValue("z", XML_GetBase(self->itself));
}

Here is the call graph for this function:

static PyObject* xmlparse_GetInputContext ( xmlparseobject self,
PyObject unused 
) [static]

Definition at line 914 of file pyexpat.c.

{
    if (self->in_callback) {
        int offset, size;
        const char *buffer
            = XML_GetInputContext(self->itself, &offset, &size);

        if (buffer != NULL)
            return PyBytes_FromStringAndSize(buffer + offset,
                                              size - offset);
        else
            Py_RETURN_NONE;
    }
    else
        Py_RETURN_NONE;
}

Here is the call graph for this function:

static PyObject* xmlparse_Parse ( xmlparseobject self,
PyObject args 
) [static]

Definition at line 781 of file pyexpat.c.

{
    char *s;
    int slen;
    int isFinal = 0;

    if (!PyArg_ParseTuple(args, "s#|i:Parse", &s, &slen, &isFinal))
        return NULL;

    return get_parse_result(self, XML_Parse(self->itself, s, slen, isFinal));
}

Here is the call graph for this function:

static PyObject* xmlparse_ParseFile ( xmlparseobject self,
PyObject f 
) [static]

Definition at line 841 of file pyexpat.c.

{
    int rv = 1;
    PyObject *readmethod = NULL;


    readmethod = PyObject_GetAttrString(f, "read");
    if (readmethod == NULL) {
        PyErr_SetString(PyExc_TypeError,
                        "argument must have 'read' attribute");
        return NULL;
    }
    for (;;) {
        int bytes_read;
        void *buf = XML_GetBuffer(self->itself, BUF_SIZE);
        if (buf == NULL) {
            Py_XDECREF(readmethod);
            return PyErr_NoMemory();
        }

        bytes_read = readinst(buf, BUF_SIZE, readmethod);
        if (bytes_read < 0) {
            Py_DECREF(readmethod);
            return NULL;
        }
        rv = XML_ParseBuffer(self->itself, bytes_read, bytes_read == 0);
        if (PyErr_Occurred()) {
            Py_XDECREF(readmethod);
            return NULL;
        }

        if (!rv || bytes_read == 0)
            break;
    }
    Py_XDECREF(readmethod);
    return get_parse_result(self, rv);
}

Here is the call graph for this function:

static int xmlparse_setattro ( xmlparseobject self,
PyObject name,
PyObject v 
) [static]

Definition at line 1384 of file pyexpat.c.

{
    /* Set attribute 'name' to value 'v'. v==NULL means delete */
    if (v == NULL) {
        PyErr_SetString(PyExc_RuntimeError, "Cannot delete attribute");
        return -1;
    }
    assert(PyUnicode_Check(name));
    if (PyUnicode_CompareWithASCIIString(name, "buffer_text") == 0) {
        if (PyObject_IsTrue(v)) {
            if (self->buffer == NULL) {
                self->buffer = malloc(self->buffer_size);
                if (self->buffer == NULL) {
                    PyErr_NoMemory();
                    return -1;
                }
                self->buffer_used = 0;
            }
        }
        else if (self->buffer != NULL) {
            if (flush_character_buffer(self) < 0)
                return -1;
            free(self->buffer);
            self->buffer = NULL;
        }
        return 0;
    }
    if (PyUnicode_CompareWithASCIIString(name, "namespace_prefixes") == 0) {
        if (PyObject_IsTrue(v))
            self->ns_prefixes = 1;
        else
            self->ns_prefixes = 0;
        XML_SetReturnNSTriplet(self->itself, self->ns_prefixes);
        return 0;
    }
    if (PyUnicode_CompareWithASCIIString(name, "ordered_attributes") == 0) {
        if (PyObject_IsTrue(v))
            self->ordered_attributes = 1;
        else
            self->ordered_attributes = 0;
        return 0;
    }
    if (PyUnicode_CompareWithASCIIString(name, "specified_attributes") == 0) {
        if (PyObject_IsTrue(v))
            self->specified_attributes = 1;
        else
            self->specified_attributes = 0;
        return 0;
    }

    if (PyUnicode_CompareWithASCIIString(name, "buffer_size") == 0) {
      long new_buffer_size;
      if (!PyLong_Check(v)) {
        PyErr_SetString(PyExc_TypeError, "buffer_size must be an integer");
        return -1;
      }

      new_buffer_size=PyLong_AS_LONG(v);
      /* trivial case -- no change */
      if (new_buffer_size == self->buffer_size) {
        return 0;
      }

      if (new_buffer_size <= 0) {
        PyErr_SetString(PyExc_ValueError, "buffer_size must be greater than zero");
        return -1;
      }

      /* check maximum */
      if (new_buffer_size > INT_MAX) {
        char errmsg[100];
        sprintf(errmsg, "buffer_size must not be greater than %i", INT_MAX);
        PyErr_SetString(PyExc_ValueError, errmsg);
        return -1;
      }

      if (self->buffer != NULL) {
        /* there is already a buffer */
        if (self->buffer_used != 0) {
          flush_character_buffer(self);
        }
        /* free existing buffer */
        free(self->buffer);
      }
      self->buffer = malloc(new_buffer_size);
      if (self->buffer == NULL) {
        PyErr_NoMemory();
        return -1;
      }
      self->buffer_size = new_buffer_size;
      return 0;
    }

    if (PyUnicode_CompareWithASCIIString(name, "CharacterDataHandler") == 0) {
        /* If we're changing the character data handler, flush all
         * cached data with the old handler.  Not sure there's a
         * "right" thing to do, though, but this probably won't
         * happen.
         */
        if (flush_character_buffer(self) < 0)
            return -1;
    }
    if (sethandler(self, name, v)) {
        return 0;
    }
    PyErr_SetObject(PyExc_AttributeError, name);
    return -1;
}

Here is the call graph for this function:

static PyObject* xmlparse_SetBase ( xmlparseobject self,
PyObject args 
) [static]

Definition at line 884 of file pyexpat.c.

{
    char *base;

    if (!PyArg_ParseTuple(args, "s:SetBase", &base))
        return NULL;
    if (!XML_SetBase(self->itself, base)) {
        return PyErr_NoMemory();
    }
    Py_INCREF(Py_None);
    return Py_None;
}

Here is the call graph for this function:

static PyObject* xmlparse_SetParamEntityParsing ( xmlparseobject p,
PyObject args 
) [static]

Definition at line 1013 of file pyexpat.c.

{
    int flag;
    if (!PyArg_ParseTuple(args, "i", &flag))
        return NULL;
    flag = XML_SetParamEntityParsing(p->itself, flag);
    return PyLong_FromLong(flag);
}

Here is the call graph for this function:

static int xmlparse_traverse ( xmlparseobject op,
visitproc  visit,
void arg 
) [static]

Definition at line 1494 of file pyexpat.c.

{
    int i;
    for (i = 0; handler_info[i].name != NULL; i++)
        Py_VISIT(op->handlers[i]);
    return 0;
}

Variable Documentation

PyObject* ErrorObject [static]

Definition at line 41 of file pyexpat.c.

static struct HandlerInfo [static]

Definition at line 78 of file pyexpat.c.

struct PyMethodDef[] [static]
Initial value:
 {
    {"Parse",     (PyCFunction)xmlparse_Parse,
                  METH_VARARGS, xmlparse_Parse__doc__},
    {"ParseFile", (PyCFunction)xmlparse_ParseFile,
                  METH_O,       xmlparse_ParseFile__doc__},
    {"SetBase",   (PyCFunction)xmlparse_SetBase,
                  METH_VARARGS, xmlparse_SetBase__doc__},
    {"GetBase",   (PyCFunction)xmlparse_GetBase,
                  METH_NOARGS, xmlparse_GetBase__doc__},
    {"ExternalEntityParserCreate", (PyCFunction)xmlparse_ExternalEntityParserCreate,
                  METH_VARARGS, xmlparse_ExternalEntityParserCreate__doc__},
    {"SetParamEntityParsing", (PyCFunction)xmlparse_SetParamEntityParsing,
                  METH_VARARGS, xmlparse_SetParamEntityParsing__doc__},
    {"GetInputContext", (PyCFunction)xmlparse_GetInputContext,
                  METH_NOARGS, xmlparse_GetInputContext__doc__},




    {"__dir__", xmlparse_dir, METH_NOARGS},
    {NULL,        NULL}         
}

Definition at line 1053 of file pyexpat.c.

struct PyModuleDef [static]
Initial value:
 {
        PyModuleDef_HEAD_INIT,
        MODULE_NAME,
        pyexpat_module_documentation,
        -1,
        pyexpat_methods,
        NULL,
        NULL,
        NULL,
        NULL
}

Definition at line 1644 of file pyexpat.c.

char template_buffer[257] [static]

Definition at line 1084 of file pyexpat.c.

static PyTypeObject Xmlparsetype [static]

Definition at line 65 of file pyexpat.c.