cpython/Modules/pyexpat.c

#ifndef Py_BUILD_CORE_BUILTIN
#define Py_BUILD_CORE_MODULE
#endif

#include "Python.h"
#include "pycore_import.h"        // _PyImport_SetModule()
#include "pycore_pyhash.h"        // _Py_HashSecret
#include "pycore_traceback.h"     // _PyTraceback_Add()

#include <stdbool.h>
#include <stddef.h>               // offsetof()
#include "expat.h"
#include "pyexpat.h"

/* Do not emit Clinic output to a file as that wreaks havoc with conditionally
   included methods. */
/*[clinic input]
module pyexpat
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=b168d503a4490c15]*/

#define XML_COMBINED_VERSION

static XML_Memory_Handling_Suite ExpatMemoryHandler =;

enum HandlerTypes {};

pyexpat_state;

static inline pyexpat_state*
pyexpat_get_state(PyObject *module)
{}

/* ----------------------------------------------------- */

/* Declarations for objects of type xmlparser */

xmlparseobject;

#include "clinic/pyexpat.c.h"

#define CHARACTER_DATA_BUFFER_SIZE

xmlhandlersetter;
xmlhandler;

struct HandlerInfo {};

static struct HandlerInfo handler_info[64];

/* Set an integer attribute on the error object; return true on success,
 * false on an exception.
 */
static int
set_error_attr(PyObject *err, const char *name, int value)
{}

/* Build and set an Expat exception, including positioning
 * information.  Always returns NULL.
 */
static PyObject *
set_error(pyexpat_state *state, xmlparseobject *self, enum XML_Error code)
{}

static int
have_handler(xmlparseobject *self, int type)
{}

/* Convert a string of XML_Chars into a Unicode string.
   Returns None if str is a null pointer. */

static PyObject *
conv_string_to_unicode(const XML_Char *str)
{}

static PyObject *
conv_string_len_to_unicode(const XML_Char *str, int len)
{}

/* Callback routines */

static void clear_handlers(xmlparseobject *self, int initial);

/* This handler is used when an error has been detected, in the hope
   that actual parsing can be terminated early.  This will only help
   if an external entity reference is encountered. */
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)
{}

/* Dummy character data handler used when an error (exception) has
   been detected, and the actual parsing can be terminated early.
   This is needed since character data handler can't be safely removed
   from within the character data handler, but can be replaced.  It is
   used only from the character data handler trampoline, and must be
   used right after `flag_error()` is called. */
static void
noop_character_data_handler(void *userData, const XML_Char *data, int len)
{}

static void
flag_error(xmlparseobject *self)
{}

static PyObject*
call_with_frame(const char *funcname, int lineno, PyObject* func, PyObject* args,
                xmlparseobject *self)
{}

static PyObject*
string_intern(xmlparseobject *self, const char* str)
{}

/* Return 0 on success, -1 on exception.
 * flag_error() will be called before return if needed.
 */
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[])
{}

#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)

VOID_HANDLER()

VOID_HANDLER()

VOID_HANDLER()

VOID_HANDLER()

VOID_HANDLER()

static PyObject *
conv_content_model(XML_Content * const model,
                   PyObject *(*conv_string)(const XML_Char *))
{}

static void
my_ElementDeclHandler(void *userData,
                      const XML_Char *name,
                      XML_Content *model)
{}

VOID_HANDLER()

#if XML_COMBINED_VERSION >= 19504
VOID_HANDLER()
#endif

VOID_HANDLER()

VOID_HANDLER()

VOID_HANDLER()

VOID_HANDLER()

VOID_HANDLER()

VOID_HANDLER()

VOID_HANDLER()

VOID_HANDLER()
#define my_DefaultHandlerExpand

INT_HANDLER()

RC_HANDLER()

/* XXX UnknownEncodingHandler */

VOID_HANDLER()

VOID_HANDLER()

/* ---------------------------------------------------------------- */
/*[clinic input]
class pyexpat.xmlparser "xmlparseobject *" "&Xmlparsetype"
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=2393162385232e1c]*/


static PyObject *
get_parse_result(pyexpat_state *state, xmlparseobject *self, int rv)
{}

#define MAX_CHUNK_SIZE

/*[clinic input]
pyexpat.xmlparser.SetReparseDeferralEnabled

    enabled: bool
    /

Enable/Disable reparse deferral; enabled by default with Expat >=2.6.0.
[clinic start generated code]*/

static PyObject *
pyexpat_xmlparser_SetReparseDeferralEnabled_impl(xmlparseobject *self,
                                                 int enabled)
/*[clinic end generated code: output=5ec539e3b63c8c49 input=021eb9e0bafc32c5]*/
{}

/*[clinic input]
pyexpat.xmlparser.GetReparseDeferralEnabled

Retrieve reparse deferral enabled status; always returns false with Expat <2.6.0.
[clinic start generated code]*/

static PyObject *
pyexpat_xmlparser_GetReparseDeferralEnabled_impl(xmlparseobject *self)
/*[clinic end generated code: output=4e91312e88a595a8 input=54b5f11d32b20f3e]*/
{}

/*[clinic input]
pyexpat.xmlparser.Parse

    cls: defining_class
    data: object
    isfinal: bool = False
    /

Parse XML data.

'isfinal' should be true at end of input.
[clinic start generated code]*/

static PyObject *
pyexpat_xmlparser_Parse_impl(xmlparseobject *self, PyTypeObject *cls,
                             PyObject *data, int isfinal)
/*[clinic end generated code: output=8faffe07fe1f862a input=053e0f047e55c05a]*/
{}

/* File reading copied from cPickle */

#define BUF_SIZE

static int
readinst(char *buf, int buf_size, PyObject *meth)
{}

/*[clinic input]
pyexpat.xmlparser.ParseFile

    cls: defining_class
    file: object
    /

Parse XML data from file-like object.
[clinic start generated code]*/

static PyObject *
pyexpat_xmlparser_ParseFile_impl(xmlparseobject *self, PyTypeObject *cls,
                                 PyObject *file)
/*[clinic end generated code: output=34780a094c8ca3ae input=ba4bc9c541684793]*/
{}

/*[clinic input]
pyexpat.xmlparser.SetBase

    base: str
    /

Set the base URL for the parser.
[clinic start generated code]*/

static PyObject *
pyexpat_xmlparser_SetBase_impl(xmlparseobject *self, const char *base)
/*[clinic end generated code: output=c212ddceb607b539 input=c684e5de895ee1a8]*/
{}

/*[clinic input]
pyexpat.xmlparser.GetBase

Return base URL string for the parser.
[clinic start generated code]*/

static PyObject *
pyexpat_xmlparser_GetBase_impl(xmlparseobject *self)
/*[clinic end generated code: output=2886cb21f9a8739a input=918d71c38009620e]*/
{}

/*[clinic input]
pyexpat.xmlparser.GetInputContext

Return the untranslated text of the input that caused the current event.

If the event was generated by a large amount of text (such as a start tag
for an element with many attributes), not all of the text may be available.
[clinic start generated code]*/

static PyObject *
pyexpat_xmlparser_GetInputContext_impl(xmlparseobject *self)
/*[clinic end generated code: output=a88026d683fc22cc input=034df8712db68379]*/
{}

/*[clinic input]
pyexpat.xmlparser.ExternalEntityParserCreate

    cls: defining_class
    context: str(accept={str, NoneType})
    encoding: str = NULL
    /

Create a parser for parsing an external entity based on the information passed to the ExternalEntityRefHandler.
[clinic start generated code]*/

static PyObject *
pyexpat_xmlparser_ExternalEntityParserCreate_impl(xmlparseobject *self,
                                                  PyTypeObject *cls,
                                                  const char *context,
                                                  const char *encoding)
/*[clinic end generated code: output=01d4472b49cb3f92 input=ec70c6b9e6e9619a]*/
{}

/*[clinic input]
pyexpat.xmlparser.SetParamEntityParsing

    flag: int
    /

Controls parsing of parameter entities (including the external DTD subset).

Possible flag values are XML_PARAM_ENTITY_PARSING_NEVER,
XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE and
XML_PARAM_ENTITY_PARSING_ALWAYS. Returns true if setting the flag
was successful.
[clinic start generated code]*/

static PyObject *
pyexpat_xmlparser_SetParamEntityParsing_impl(xmlparseobject *self, int flag)
/*[clinic end generated code: output=18668ee8e760d64c input=8aea19b4b15e9af1]*/
{}


#if XML_COMBINED_VERSION >= 19505
/*[clinic input]
pyexpat.xmlparser.UseForeignDTD

    cls: defining_class
    flag: bool = True
    /

Allows the application to provide an artificial external subset if one is not specified as part of the document instance.

This readily allows the use of a 'default' document type controlled by the
application, while still getting the advantage of providing document type
information to the parser. 'flag' defaults to True if not provided.
[clinic start generated code]*/

static PyObject *
pyexpat_xmlparser_UseForeignDTD_impl(xmlparseobject *self, PyTypeObject *cls,
                                     int flag)
/*[clinic end generated code: output=d7d98252bd25a20f input=23440ecb0573fb29]*/
{}
#endif

static struct PyMethodDef xmlparse_methods[] =;

/* ---------- */



/* pyexpat international encoding support.
   Make it as simple as possible.
*/

static const unsigned char template_buffer[256] =;


static int
PyUnknownEncodingHandler(void *encodingHandlerData,
                         const XML_Char *name,
                         XML_Encoding *info)
{}


static PyObject *
newxmlparseobject(pyexpat_state *state, const char *encoding,
                  const char *namespace_separator, PyObject *intern)
{}

static int
xmlparse_traverse(xmlparseobject *op, visitproc visit, void *arg)
{}

static int
xmlparse_clear(xmlparseobject *op)
{}

static void
xmlparse_dealloc(xmlparseobject *self)
{}


static PyObject *
xmlparse_handler_getter(xmlparseobject *self, struct HandlerInfo *hi)
{}

static int
xmlparse_handler_setter(xmlparseobject *self, PyObject *v, struct HandlerInfo *hi)
{}

#define INT_GETTER
INT_GETTER
INT_GETTER
INT_GETTER
INT_GETTER
INT_GETTER
INT_GETTER
INT_GETTER

#undef INT_GETTER

static PyObject *
xmlparse_buffer_text_getter(xmlparseobject *self, void *closure)
{}

static int
xmlparse_buffer_text_setter(xmlparseobject *self, PyObject *v, void *closure)
{}

static PyObject *
xmlparse_buffer_size_getter(xmlparseobject *self, void *closure)
{}

static int
xmlparse_buffer_size_setter(xmlparseobject *self, PyObject *v, void *closure)
{}

static PyObject *
xmlparse_buffer_used_getter(xmlparseobject *self, void *closure)
{}

static PyObject *
xmlparse_namespace_prefixes_getter(xmlparseobject *self, void *closure)
{}

static int
xmlparse_namespace_prefixes_setter(xmlparseobject *self, PyObject *v, void *closure)
{}

static PyObject *
xmlparse_ordered_attributes_getter(xmlparseobject *self, void *closure)
{}

static int
xmlparse_ordered_attributes_setter(xmlparseobject *self, PyObject *v, void *closure)
{}

static PyObject *
xmlparse_specified_attributes_getter(xmlparseobject *self, void *closure)
{}

static int
xmlparse_specified_attributes_setter(xmlparseobject *self, PyObject *v, void *closure)
{}

static PyMemberDef xmlparse_members[] =;

#define XMLPARSE_GETTER_DEF
#define XMLPARSE_GETTER_SETTER_DEF

static PyGetSetDef xmlparse_getsetlist[] =;

#undef XMLPARSE_GETTER_DEF
#undef XMLPARSE_GETTER_SETTER_DEF

PyDoc_STRVAR(Xmlparsetype__doc__, "XML parser");

static PyType_Slot _xml_parse_type_spec_slots[] =;

static PyType_Spec _xml_parse_type_spec =;

/* End of code for xmlparser objects */
/* -------------------------------------------------------- */

/*[clinic input]
pyexpat.ParserCreate

    encoding: str(accept={str, NoneType}) = None
    namespace_separator: str(accept={str, NoneType}) = None
    intern: object = NULL

Return a new XML parser object.
[clinic start generated code]*/

static PyObject *
pyexpat_ParserCreate_impl(PyObject *module, const char *encoding,
                          const char *namespace_separator, PyObject *intern)
/*[clinic end generated code: output=295c0cf01ab1146c input=e8da8e8d7122cb5d]*/
{}

/*[clinic input]
pyexpat.ErrorString

    code: long
    /

Returns string error for given number.
[clinic start generated code]*/

static PyObject *
pyexpat_ErrorString_impl(PyObject *module, long code)
/*[clinic end generated code: output=2feae50d166f2174 input=cc67de010d9e62b3]*/
{}

/* List of methods defined in the module */

static struct PyMethodDef pyexpat_methods[] =;

/* Module docstring */

PyDoc_STRVAR(pyexpat_module_documentation,
"Python wrapper for Expat parser.");

/* Initialization function for the module */

#ifndef MODULE_NAME
#define MODULE_NAME
#endif

static int init_handler_descrs(pyexpat_state *state)
{}

static PyObject *
add_submodule(PyObject *mod, const char *fullname)
{}

struct ErrorInfo {};

static
struct ErrorInfo error_info_of[] =;

static int
add_error(PyObject *errors_module, PyObject *codes_dict,
          PyObject *rev_codes_dict, size_t error_index)
{}

static int
add_errors_module(PyObject *mod)
{}

static int
add_model_module(PyObject *mod)
{}

#if XML_COMBINED_VERSION > 19505
static int
add_features(PyObject *mod)
{}
#endif

static void
pyexpat_capsule_destructor(PyObject *capsule)
{}


static int
pyexpat_exec(PyObject *mod)
{}

static int
pyexpat_traverse(PyObject *module, visitproc visit, void *arg)
{}

static int
pyexpat_clear(PyObject *module)
{}

static void
pyexpat_free(void *module)
{}

static PyModuleDef_Slot pyexpat_slots[] =;

static struct PyModuleDef pyexpatmodule =;

PyMODINIT_FUNC
PyInit_pyexpat(void)
{}

static void
clear_handlers(xmlparseobject *self, int initial)
{}

static struct HandlerInfo handler_info[] =;