annotate Modules/pyexpat.c @ 79675:c0a2294de787 2.7

Issue #16199: Backport 2to3 typo fix from 3.2.
author Chris Jerdonek <chris.jerdonek@gmail.com>
date Thu, 11 Oct 2012 16:15:46 -0700
parents 3e0d632ce910
children b3efc140d8a6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19979
8dcfaf0e6559 Include ctype.h after Python.h.
Martin v. Löwis <martin@v.loewis.de>
parents: 19978
diff changeset
1 #include "Python.h"
17219
3f912fb8c180 get_version_string(): New function -- returns a Python string object that
Fred Drake <fdrake@acm.org>
parents: 17034
diff changeset
2 #include <ctype.h>
3f912fb8c180 get_version_string(): New function -- returns a Python string object that
Fred Drake <fdrake@acm.org>
parents: 17034
diff changeset
3
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
4 #include "frameobject.h"
14932
827e9d21a781 PyModule_AddStringConstant(): Make this static since it isn't used
Fred Drake <fdrake@acm.org>
parents: 14931
diff changeset
5 #include "expat.h"
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
6
36017
ed347c436d58 added cobject-based expat dispatch mechanism to pyexpat
Fredrik Lundh <fredrik@pythonware.com>
parents: 35999
diff changeset
7 #include "pyexpat.h"
ed347c436d58 added cobject-based expat dispatch mechanism to pyexpat
Fredrik Lundh <fredrik@pythonware.com>
parents: 35999
diff changeset
8
27322
88bf10313584 Conditionalize features not found in PyXML 1.95.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 27321
diff changeset
9 #define XML_COMBINED_VERSION (10000*XML_MAJOR_VERSION+100*XML_MINOR_VERSION+XML_MICRO_VERSION)
88bf10313584 Conditionalize features not found in PyXML 1.95.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 27321
diff changeset
10
24064
92834a248c15 Define PyDoc_STRVAR if it is not available (PyXML 1.54).
Martin v. Löwis <martin@v.loewis.de>
parents: 24063
diff changeset
11 #ifndef PyDoc_STRVAR
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
12
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
13 /*
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
14 * fdrake says:
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
15 * Don't change the PyDoc_STR macro definition to (str), because
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
16 * '''the parentheses cause compile failures
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
17 * ("non-constant static initializer" or something like that)
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
18 * on some platforms (Irix?)'''
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
19 */
25092
427efc35b5be Minor change for symmetry with PyXML: PyDoc_STR should not include
Fred Drake <fdrake@acm.org>
parents: 24867
diff changeset
20 #define PyDoc_STR(str) str
24076
95ccd5bbdc86 Bring this back into sync with PyXML revision 1.58.
Fred Drake <fdrake@acm.org>
parents: 24064
diff changeset
21 #define PyDoc_VAR(name) static char name[]
24064
92834a248c15 Define PyDoc_STRVAR if it is not available (PyXML 1.54).
Martin v. Löwis <martin@v.loewis.de>
parents: 24063
diff changeset
22 #define PyDoc_STRVAR(name,str) PyDoc_VAR(name) = PyDoc_STR(str)
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
23 #endif
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
24
24064
92834a248c15 Define PyDoc_STRVAR if it is not available (PyXML 1.54).
Martin v. Löwis <martin@v.loewis.de>
parents: 24063
diff changeset
25 #if (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 2)
92834a248c15 Define PyDoc_STRVAR if it is not available (PyXML 1.54).
Martin v. Löwis <martin@v.loewis.de>
parents: 24063
diff changeset
26 /* In Python 2.0 and 2.1, disabling Unicode was not possible. */
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18854
diff changeset
27 #define Py_USING_UNICODE
29605
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
28 #else
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
29 #define FIX_TRACE
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18854
diff changeset
30 #endif
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18854
diff changeset
31
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
32 enum HandlerTypes {
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
33 StartElement,
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
34 EndElement,
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
35 ProcessingInstruction,
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
36 CharacterData,
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
37 UnparsedEntityDecl,
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
38 NotationDecl,
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
39 StartNamespaceDecl,
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
40 EndNamespaceDecl,
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
41 Comment,
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
42 StartCdataSection,
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
43 EndCdataSection,
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
44 Default,
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
45 DefaultHandlerExpand,
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
46 NotStandalone,
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
47 ExternalEntityRef,
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
48 StartDoctypeDecl,
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
49 EndDoctypeDecl,
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
50 EntityDecl,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
51 XmlDecl,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
52 ElementDecl,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
53 AttlistDecl,
27322
88bf10313584 Conditionalize features not found in PyXML 1.95.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 27321
diff changeset
54 #if XML_COMBINED_VERSION >= 19504
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
55 SkippedEntity,
27322
88bf10313584 Conditionalize features not found in PyXML 1.95.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 27321
diff changeset
56 #endif
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
57 _DummyDecl
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
58 };
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
59
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
60 static PyObject *ErrorObject;
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
61
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
62 /* ----------------------------------------------------- */
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
63
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
64 /* Declarations for objects of type xmlparser */
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
65
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
66 typedef struct {
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
67 PyObject_HEAD
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
68
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
69 XML_Parser itself;
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
70 int returns_unicode; /* True if Unicode strings are returned;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
71 if false, UTF-8 strings are returned */
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
72 int ordered_attributes; /* Return attributes as a list. */
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
73 int specified_attributes; /* Report only specified attributes. */
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
74 int in_callback; /* Is a callback active? */
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
75 int ns_prefixes; /* Namespace-triplets mode? */
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
76 XML_Char *buffer; /* Buffer used when accumulating characters */
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
77 /* NULL if not enabled */
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
78 int buffer_size; /* Size of buffer, in XML_Char units */
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
79 int buffer_used; /* Buffer units in use */
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
80 PyObject *intern; /* Dictionary to intern strings */
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
81 PyObject **handlers;
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
82 } xmlparseobject;
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
83
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
84 #define CHARACTER_DATA_BUFFER_SIZE 8192
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
85
24280
1598a1e473e2 staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24079
diff changeset
86 static PyTypeObject Xmlparsetype;
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
87
25395
9ca609f8bdf2 Be more careful with the type of the xmlhandlersetter; it takes an
Fred Drake <fdrake@acm.org>
parents: 25092
diff changeset
88 typedef void (*xmlhandlersetter)(XML_Parser self, void *meth);
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
89 typedef void* xmlhandler;
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
90
13025
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
91 struct HandlerInfo {
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
92 const char *name;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
93 xmlhandlersetter setter;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
94 xmlhandler handler;
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
95 PyCodeObject *tb_code;
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
96 PyObject *nameobj;
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
97 };
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
98
24280
1598a1e473e2 staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24079
diff changeset
99 static struct HandlerInfo handler_info[64];
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
100
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
101 /* Set an integer attribute on the error object; return true on success,
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
102 * false on an exception.
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
103 */
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
104 static int
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
105 set_error_attr(PyObject *err, char *name, int value)
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
106 {
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
107 PyObject *v = PyInt_FromLong(value);
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
108
36891
a9697de5e18b Fix logic error and DECREF reported by Coverity.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36675
diff changeset
109 if (v == NULL || PyObject_SetAttrString(err, name, v) == -1) {
a9697de5e18b Fix logic error and DECREF reported by Coverity.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36675
diff changeset
110 Py_XDECREF(v);
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
111 return 0;
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
112 }
32923
f1bbf147810b Fix the reference count errors revealed by the test suite...
Michael W. Hudson <mwh@python.net>
parents: 30683
diff changeset
113 Py_DECREF(v);
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
114 return 1;
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
115 }
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
116
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
117 /* Build and set an Expat exception, including positioning
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
118 * information. Always returns NULL.
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
119 */
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
120 static PyObject *
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
121 set_error(xmlparseobject *self, enum XML_Error code)
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
122 {
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
123 PyObject *err;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
124 char buffer[256];
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
125 XML_Parser parser = self->itself;
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
126 int lineno = XML_GetErrorLineNumber(parser);
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
127 int column = XML_GetErrorColumnNumber(parser);
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
128
24063
e8789751a5cc Undo usage of PyOS_snprintf (rev. 1.51 of PyXML).
Martin v. Löwis <martin@v.loewis.de>
parents: 24040
diff changeset
129 /* There is no risk of overflowing this buffer, since
e8789751a5cc Undo usage of PyOS_snprintf (rev. 1.51 of PyXML).
Martin v. Löwis <martin@v.loewis.de>
parents: 24040
diff changeset
130 even for 64-bit integers, there is sufficient space. */
e8789751a5cc Undo usage of PyOS_snprintf (rev. 1.51 of PyXML).
Martin v. Löwis <martin@v.loewis.de>
parents: 24040
diff changeset
131 sprintf(buffer, "%.200s: line %i, column %i",
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
132 XML_ErrorString(code), lineno, column);
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
133 err = PyObject_CallFunction(ErrorObject, "s", buffer);
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
134 if ( err != NULL
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
135 && set_error_attr(err, "code", code)
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
136 && set_error_attr(err, "offset", column)
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
137 && set_error_attr(err, "lineno", lineno)) {
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
138 PyErr_SetObject(ErrorObject, err);
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
139 }
36891
a9697de5e18b Fix logic error and DECREF reported by Coverity.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36675
diff changeset
140 Py_XDECREF(err);
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
141 return NULL;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
142 }
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
143
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
144 static int
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
145 have_handler(xmlparseobject *self, int type)
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
146 {
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
147 PyObject *handler = self->handlers[type];
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
148 return handler != NULL;
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
149 }
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
150
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
151 static PyObject *
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
152 get_handler_name(struct HandlerInfo *hinfo)
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
153 {
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
154 PyObject *name = hinfo->nameobj;
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
155 if (name == NULL) {
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
156 name = PyString_FromString(hinfo->name);
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
157 hinfo->nameobj = name;
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
158 }
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
159 Py_XINCREF(name);
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
160 return name;
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
161 }
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
162
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
163
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18854
diff changeset
164 #ifdef Py_USING_UNICODE
13025
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
165 /* Convert a string of XML_Chars into a Unicode string.
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
166 Returns None if str is a null pointer. */
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
167
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
168 static PyObject *
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
169 conv_string_to_unicode(const XML_Char *str)
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
170 {
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
171 /* XXX currently this code assumes that XML_Char is 8-bit,
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
172 and hence in UTF-8. */
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
173 /* UTF-8 from Expat, Unicode desired */
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
174 if (str == NULL) {
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
175 Py_INCREF(Py_None);
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
176 return Py_None;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
177 }
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
178 return PyUnicode_DecodeUTF8(str, strlen(str), "strict");
13025
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
179 }
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
180
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
181 static PyObject *
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
182 conv_string_len_to_unicode(const XML_Char *str, int len)
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
183 {
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
184 /* XXX currently this code assumes that XML_Char is 8-bit,
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
185 and hence in UTF-8. */
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
186 /* UTF-8 from Expat, Unicode desired */
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
187 if (str == NULL) {
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
188 Py_INCREF(Py_None);
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
189 return Py_None;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
190 }
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
191 return PyUnicode_DecodeUTF8((const char *)str, len, "strict");
13025
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
192 }
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
193 #endif
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
194
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
195 /* Convert a string of XML_Chars into an 8-bit Python string.
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
196 Returns None if str is a null pointer. */
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
197
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
198 static PyObject *
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
199 conv_string_to_utf8(const XML_Char *str)
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
200 {
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
201 /* XXX currently this code assumes that XML_Char is 8-bit,
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
202 and hence in UTF-8. */
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
203 /* UTF-8 from Expat, UTF-8 desired */
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
204 if (str == NULL) {
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
205 Py_INCREF(Py_None);
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
206 return Py_None;
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
207 }
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
208 return PyString_FromString(str);
13025
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
209 }
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
210
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
211 static PyObject *
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
212 conv_string_len_to_utf8(const XML_Char *str, int len)
13025
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
213 {
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
214 /* XXX currently this code assumes that XML_Char is 8-bit,
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
215 and hence in UTF-8. */
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
216 /* UTF-8 from Expat, UTF-8 desired */
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
217 if (str == NULL) {
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
218 Py_INCREF(Py_None);
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
219 return Py_None;
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
220 }
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
221 return PyString_FromStringAndSize((const char *)str, len);
13025
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
222 }
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
223
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
224 /* Callback routines */
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
225
20588
aad762503d11 Change clear_handlers argument to indicate whether this is an initialization.
Martin v. Löwis <martin@v.loewis.de>
parents: 20047
diff changeset
226 static void clear_handlers(xmlparseobject *self, int initial);
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
227
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
228 /* This handler is used when an error has been detected, in the hope
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
229 that actual parsing can be terminated early. This will only help
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
230 if an external entity reference is encountered. */
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
231 static int
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
232 error_external_entity_ref_handler(XML_Parser parser,
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
233 const XML_Char *context,
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
234 const XML_Char *base,
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
235 const XML_Char *systemId,
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
236 const XML_Char *publicId)
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
237 {
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
238 return 0;
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
239 }
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
240
39009
500ae952150b - back out Expat change; the final fix to Expat will be different
Fred Drake <fdrake@acm.org>
parents: 38489
diff changeset
241 /* Dummy character data handler used when an error (exception) has
500ae952150b - back out Expat change; the final fix to Expat will be different
Fred Drake <fdrake@acm.org>
parents: 38489
diff changeset
242 been detected, and the actual parsing can be terminated early.
500ae952150b - back out Expat change; the final fix to Expat will be different
Fred Drake <fdrake@acm.org>
parents: 38489
diff changeset
243 This is needed since character data handler can't be safely removed
500ae952150b - back out Expat change; the final fix to Expat will be different
Fred Drake <fdrake@acm.org>
parents: 38489
diff changeset
244 from within the character data handler, but can be replaced. It is
500ae952150b - back out Expat change; the final fix to Expat will be different
Fred Drake <fdrake@acm.org>
parents: 38489
diff changeset
245 used only from the character data handler trampoline, and must be
500ae952150b - back out Expat change; the final fix to Expat will be different
Fred Drake <fdrake@acm.org>
parents: 38489
diff changeset
246 used right after `flag_error()` is called. */
500ae952150b - back out Expat change; the final fix to Expat will be different
Fred Drake <fdrake@acm.org>
parents: 38489
diff changeset
247 static void
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
248 noop_character_data_handler(void *userData, const XML_Char *data, int len)
39009
500ae952150b - back out Expat change; the final fix to Expat will be different
Fred Drake <fdrake@acm.org>
parents: 38489
diff changeset
249 {
500ae952150b - back out Expat change; the final fix to Expat will be different
Fred Drake <fdrake@acm.org>
parents: 38489
diff changeset
250 /* Do nothing. */
500ae952150b - back out Expat change; the final fix to Expat will be different
Fred Drake <fdrake@acm.org>
parents: 38489
diff changeset
251 }
500ae952150b - back out Expat change; the final fix to Expat will be different
Fred Drake <fdrake@acm.org>
parents: 38489
diff changeset
252
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
253 static void
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
254 flag_error(xmlparseobject *self)
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
255 {
20588
aad762503d11 Change clear_handlers argument to indicate whether this is an initialization.
Martin v. Löwis <martin@v.loewis.de>
parents: 20047
diff changeset
256 clear_handlers(self, 0);
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
257 XML_SetExternalEntityRefHandler(self->itself,
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
258 error_external_entity_ref_handler);
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
259 }
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
260
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
261 static PyCodeObject*
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
262 getcode(enum HandlerTypes slot, char* func_name, int lineno)
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
263 {
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
264 if (handler_info[slot].tb_code == NULL) {
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
265 handler_info[slot].tb_code =
53930
a171048daf76 PyCode_NewEmpty:
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 47527
diff changeset
266 PyCode_NewEmpty(__FILE__, func_name, lineno);
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
267 }
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
268 return handler_info[slot].tb_code;
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
269 }
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
270
29605
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
271 #ifdef FIX_TRACE
24533
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
272 static int
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
273 trace_frame(PyThreadState *tstate, PyFrameObject *f, int code, PyObject *val)
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
274 {
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
275 int result = 0;
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
276 if (!tstate->use_tracing || tstate->tracing)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
277 return 0;
24533
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
278 if (tstate->c_profilefunc != NULL) {
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
279 tstate->tracing++;
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
280 result = tstate->c_profilefunc(tstate->c_profileobj,
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
281 f, code , val);
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
282 tstate->use_tracing = ((tstate->c_tracefunc != NULL)
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
283 || (tstate->c_profilefunc != NULL));
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
284 tstate->tracing--;
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
285 if (result)
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
286 return result;
24533
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
287 }
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
288 if (tstate->c_tracefunc != NULL) {
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
289 tstate->tracing++;
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
290 result = tstate->c_tracefunc(tstate->c_traceobj,
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
291 f, code , val);
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
292 tstate->use_tracing = ((tstate->c_tracefunc != NULL)
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
293 || (tstate->c_profilefunc != NULL));
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
294 tstate->tracing--;
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
295 }
24533
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
296 return result;
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
297 }
29605
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
298
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
299 static int
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
300 trace_frame_exc(PyThreadState *tstate, PyFrameObject *f)
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
301 {
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
302 PyObject *type, *value, *traceback, *arg;
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
303 int err;
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
304
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
305 if (tstate->c_tracefunc == NULL)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
306 return 0;
29605
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
307
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
308 PyErr_Fetch(&type, &value, &traceback);
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
309 if (value == NULL) {
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
310 value = Py_None;
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
311 Py_INCREF(value);
29605
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
312 }
33752
ddc2d6e547c1 Synchronize with PyXML 1.79:
Martin v. Löwis <martin@v.loewis.de>
parents: 33279
diff changeset
313 #if PY_VERSION_HEX < 0x02040000
ddc2d6e547c1 Synchronize with PyXML 1.79:
Martin v. Löwis <martin@v.loewis.de>
parents: 33279
diff changeset
314 arg = Py_BuildValue("(OOO)", type, value, traceback);
ddc2d6e547c1 Synchronize with PyXML 1.79:
Martin v. Löwis <martin@v.loewis.de>
parents: 33279
diff changeset
315 #else
30683
3b59fa5d25b1 Simplify and speedup uses of Py_BuildValue():
Raymond Hettinger <python@rcn.com>
parents: 29957
diff changeset
316 arg = PyTuple_Pack(3, type, value, traceback);
33752
ddc2d6e547c1 Synchronize with PyXML 1.79:
Martin v. Löwis <martin@v.loewis.de>
parents: 33279
diff changeset
317 #endif
29605
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
318 if (arg == NULL) {
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
319 PyErr_Restore(type, value, traceback);
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
320 return 0;
29605
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
321 }
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
322 err = trace_frame(tstate, f, PyTrace_EXCEPTION, arg);
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
323 Py_DECREF(arg);
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
324 if (err == 0)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
325 PyErr_Restore(type, value, traceback);
29605
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
326 else {
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
327 Py_XDECREF(type);
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
328 Py_XDECREF(value);
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
329 Py_XDECREF(traceback);
29605
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
330 }
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
331 return err;
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
332 }
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
333 #endif
24533
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
334
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
335 static PyObject*
33113
28e877ff74cf make exception propogation more efficient; this avoids having Expat parse
Fred Drake <fdrake@acm.org>
parents: 32965
diff changeset
336 call_with_frame(PyCodeObject *c, PyObject* func, PyObject* args,
28e877ff74cf make exception propogation more efficient; this avoids having Expat parse
Fred Drake <fdrake@acm.org>
parents: 32965
diff changeset
337 xmlparseobject *self)
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
338 {
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
339 PyThreadState *tstate = PyThreadState_GET();
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
340 PyFrameObject *f;
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
341 PyObject *res;
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
342
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
343 if (c == NULL)
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
344 return NULL;
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
345
29605
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
346 f = PyFrame_New(tstate, c, PyEval_GetGlobals(), NULL);
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
347 if (f == NULL)
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
348 return NULL;
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
349 tstate->frame = f;
29605
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
350 #ifdef FIX_TRACE
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
351 if (trace_frame(tstate, f, PyTrace_CALL, Py_None) < 0) {
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
352 return NULL;
24533
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
353 }
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
354 #endif
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
355 res = PyEval_CallObject(func, args);
29605
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
356 if (res == NULL) {
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
357 if (tstate->curexc_traceback == NULL)
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
358 PyTraceBack_Here(f);
33113
28e877ff74cf make exception propogation more efficient; this avoids having Expat parse
Fred Drake <fdrake@acm.org>
parents: 32965
diff changeset
359 XML_StopParser(self->itself, XML_FALSE);
29605
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
360 #ifdef FIX_TRACE
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
361 if (trace_frame_exc(tstate, f) < 0) {
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
362 return NULL;
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
363 }
29605
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
364 }
24533
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
365 else {
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
366 if (trace_frame(tstate, f, PyTrace_RETURN, res) < 0) {
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
367 Py_XDECREF(res);
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
368 res = NULL;
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
369 }
24533
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
370 }
29605
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
371 #else
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
372 }
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
373 #endif
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
374 tstate->frame = f->f_back;
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
375 Py_DECREF(f);
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
376 return res;
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
377 }
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
378
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18854
diff changeset
379 #ifndef Py_USING_UNICODE
13025
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
380 #define STRING_CONV_FUNC conv_string_to_utf8
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
381 #else
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
382 /* Python 2.0 and later versions, when built with Unicode support */
13025
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
383 #define STRING_CONV_FUNC (self->returns_unicode \
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
384 ? conv_string_to_unicode : conv_string_to_utf8)
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
385 #endif
12187
39b91cb80b41 Make it compile on Windows.
Guido van Rossum <guido@python.org>
parents: 12182
diff changeset
386
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
387 static PyObject*
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
388 string_intern(xmlparseobject *self, const char* str)
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
389 {
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
390 PyObject *result = STRING_CONV_FUNC(str);
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
391 PyObject *value;
35658
a83e8df13498 Patch #1309009, Fix segfault in pyexpat when the XML document is
Neal Norwitz <nnorwitz@gmail.com>
parents: 34687
diff changeset
392 /* result can be NULL if the unicode conversion failed. */
a83e8df13498 Patch #1309009, Fix segfault in pyexpat when the XML document is
Neal Norwitz <nnorwitz@gmail.com>
parents: 34687
diff changeset
393 if (!result)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
394 return result;
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
395 if (!self->intern)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
396 return result;
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
397 value = PyDict_GetItem(self->intern, result);
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
398 if (!value) {
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
399 if (PyDict_SetItem(self->intern, result, result) == 0)
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
400 return result;
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
401 else
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
402 return NULL;
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
403 }
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
404 Py_INCREF(value);
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
405 Py_DECREF(result);
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
406 return value;
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
407 }
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
408
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
409 /* Return 0 on success, -1 on exception.
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
410 * flag_error() will be called before return if needed.
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
411 */
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
412 static int
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
413 call_character_handler(xmlparseobject *self, const XML_Char *buffer, int len)
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
414 {
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
415 PyObject *args;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
416 PyObject *temp;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
417
65619
5b536c90ca36 Merged revisions 85536 via svnmerge from
Georg Brandl <georg@python.org>
parents: 61463
diff changeset
418 if (!have_handler(self, CharacterData))
5b536c90ca36 Merged revisions 85536 via svnmerge from
Georg Brandl <georg@python.org>
parents: 61463
diff changeset
419 return -1;
5b536c90ca36 Merged revisions 85536 via svnmerge from
Georg Brandl <georg@python.org>
parents: 61463
diff changeset
420
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
421 args = PyTuple_New(1);
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
422 if (args == NULL)
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
423 return -1;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
424 #ifdef Py_USING_UNICODE
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
425 temp = (self->returns_unicode
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
426 ? conv_string_len_to_unicode(buffer, len)
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
427 : conv_string_len_to_utf8(buffer, len));
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
428 #else
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
429 temp = conv_string_len_to_utf8(buffer, len);
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
430 #endif
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
431 if (temp == NULL) {
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
432 Py_DECREF(args);
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
433 flag_error(self);
39009
500ae952150b - back out Expat change; the final fix to Expat will be different
Fred Drake <fdrake@acm.org>
parents: 38489
diff changeset
434 XML_SetCharacterDataHandler(self->itself,
500ae952150b - back out Expat change; the final fix to Expat will be different
Fred Drake <fdrake@acm.org>
parents: 38489
diff changeset
435 noop_character_data_handler);
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
436 return -1;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
437 }
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
438 PyTuple_SET_ITEM(args, 0, temp);
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
439 /* temp is now a borrowed reference; consider it unused. */
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
440 self->in_callback = 1;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
441 temp = call_with_frame(getcode(CharacterData, "CharacterData", __LINE__),
33113
28e877ff74cf make exception propogation more efficient; this avoids having Expat parse
Fred Drake <fdrake@acm.org>
parents: 32965
diff changeset
442 self->handlers[CharacterData], args, self);
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
443 /* temp is an owned reference again, or NULL */
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
444 self->in_callback = 0;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
445 Py_DECREF(args);
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
446 if (temp == NULL) {
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
447 flag_error(self);
39009
500ae952150b - back out Expat change; the final fix to Expat will be different
Fred Drake <fdrake@acm.org>
parents: 38489
diff changeset
448 XML_SetCharacterDataHandler(self->itself,
500ae952150b - back out Expat change; the final fix to Expat will be different
Fred Drake <fdrake@acm.org>
parents: 38489
diff changeset
449 noop_character_data_handler);
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
450 return -1;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
451 }
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
452 Py_DECREF(temp);
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
453 return 0;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
454 }
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
455
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
456 static int
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
457 flush_character_buffer(xmlparseobject *self)
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
458 {
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
459 int rc;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
460 if (self->buffer == NULL || self->buffer_used == 0)
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
461 return 0;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
462 rc = call_character_handler(self, self->buffer, self->buffer_used);
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
463 self->buffer_used = 0;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
464 return rc;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
465 }
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
466
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
467 static void
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
468 my_CharacterDataHandler(void *userData, const XML_Char *data, int len)
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
469 {
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
470 xmlparseobject *self = (xmlparseobject *) userData;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
471 if (self->buffer == NULL)
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
472 call_character_handler(self, data, len);
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
473 else {
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
474 if ((self->buffer_used + len) > self->buffer_size) {
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
475 if (flush_character_buffer(self) < 0)
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
476 return;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
477 /* handler might have changed; drop the rest on the floor
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
478 * if there isn't a handler anymore
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
479 */
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
480 if (!have_handler(self, CharacterData))
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
481 return;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
482 }
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
483 if (len > self->buffer_size) {
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
484 call_character_handler(self, data, len);
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
485 self->buffer_used = 0;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
486 }
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
487 else {
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
488 memcpy(self->buffer + self->buffer_used,
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
489 data, len * sizeof(XML_Char));
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
490 self->buffer_used += len;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
491 }
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
492 }
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
493 }
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
494
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
495 static void
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
496 my_StartElementHandler(void *userData,
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
497 const XML_Char *name, const XML_Char *atts[])
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
498 {
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
499 xmlparseobject *self = (xmlparseobject *)userData;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
500
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
501 if (have_handler(self, StartElement)) {
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
502 PyObject *container, *rv, *args;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
503 int i, max;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
504
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
505 if (flush_character_buffer(self) < 0)
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
506 return;
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
507 /* Set max to the number of slots filled in atts[]; max/2 is
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
508 * the number of attributes we need to process.
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
509 */
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
510 if (self->specified_attributes) {
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
511 max = XML_GetSpecifiedAttributeCount(self->itself);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
512 }
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
513 else {
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
514 max = 0;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
515 while (atts[max] != NULL)
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
516 max += 2;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
517 }
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
518 /* Build the container. */
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
519 if (self->ordered_attributes)
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
520 container = PyList_New(max);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
521 else
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
522 container = PyDict_New();
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
523 if (container == NULL) {
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
524 flag_error(self);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
525 return;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
526 }
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
527 for (i = 0; i < max; i += 2) {
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
528 PyObject *n = string_intern(self, (XML_Char *) atts[i]);
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
529 PyObject *v;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
530 if (n == NULL) {
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
531 flag_error(self);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
532 Py_DECREF(container);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
533 return;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
534 }
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
535 v = STRING_CONV_FUNC((XML_Char *) atts[i+1]);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
536 if (v == NULL) {
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
537 flag_error(self);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
538 Py_DECREF(container);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
539 Py_DECREF(n);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
540 return;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
541 }
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
542 if (self->ordered_attributes) {
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
543 PyList_SET_ITEM(container, i, n);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
544 PyList_SET_ITEM(container, i+1, v);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
545 }
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
546 else if (PyDict_SetItem(container, n, v)) {
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
547 flag_error(self);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
548 Py_DECREF(n);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
549 Py_DECREF(v);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
550 return;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
551 }
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
552 else {
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
553 Py_DECREF(n);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
554 Py_DECREF(v);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
555 }
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
556 }
35658
a83e8df13498 Patch #1309009, Fix segfault in pyexpat when the XML document is
Neal Norwitz <nnorwitz@gmail.com>
parents: 34687
diff changeset
557 args = string_intern(self, name);
a83e8df13498 Patch #1309009, Fix segfault in pyexpat when the XML document is
Neal Norwitz <nnorwitz@gmail.com>
parents: 34687
diff changeset
558 if (args != NULL)
a83e8df13498 Patch #1309009, Fix segfault in pyexpat when the XML document is
Neal Norwitz <nnorwitz@gmail.com>
parents: 34687
diff changeset
559 args = Py_BuildValue("(NN)", args, container);
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
560 if (args == NULL) {
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
561 Py_DECREF(container);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
562 return;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
563 }
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
564 /* Container is now a borrowed reference; ignore it. */
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
565 self->in_callback = 1;
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
566 rv = call_with_frame(getcode(StartElement, "StartElement", __LINE__),
33113
28e877ff74cf make exception propogation more efficient; this avoids having Expat parse
Fred Drake <fdrake@acm.org>
parents: 32965
diff changeset
567 self->handlers[StartElement], args, self);
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
568 self->in_callback = 0;
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
569 Py_DECREF(args);
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
570 if (rv == NULL) {
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
571 flag_error(self);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
572 return;
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
573 }
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
574 Py_DECREF(rv);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
575 }
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
576 }
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
577
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
578 #define RC_HANDLER(RC, NAME, PARAMS, INIT, PARAM_FORMAT, CONVERSION, \
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
579 RETURN, GETUSERDATA) \
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
580 static RC \
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
581 my_##NAME##Handler PARAMS {\
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
582 xmlparseobject *self = GETUSERDATA ; \
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
583 PyObject *args = NULL; \
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
584 PyObject *rv = NULL; \
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
585 INIT \
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
586 \
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
587 if (have_handler(self, NAME)) { \
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
588 if (flush_character_buffer(self) < 0) \
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
589 return RETURN; \
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
590 args = Py_BuildValue PARAM_FORMAT ;\
20950
c3b08319959c Merge 1.42 from PyXML: Flag errors resulting from argument conversion problems.
Martin v. Löwis <martin@v.loewis.de>
parents: 20588
diff changeset
591 if (!args) { flag_error(self); return RETURN;} \
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
592 self->in_callback = 1; \
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
593 rv = call_with_frame(getcode(NAME,#NAME,__LINE__), \
33113
28e877ff74cf make exception propogation more efficient; this avoids having Expat parse
Fred Drake <fdrake@acm.org>
parents: 32965
diff changeset
594 self->handlers[NAME], args, self); \
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
595 self->in_callback = 0; \
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
596 Py_DECREF(args); \
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
597 if (rv == NULL) { \
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
598 flag_error(self); \
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
599 return RETURN; \
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
600 } \
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
601 CONVERSION \
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
602 Py_DECREF(rv); \
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
603 } \
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
604 return RETURN; \
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
605 }
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
606
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
607 #define VOID_HANDLER(NAME, PARAMS, PARAM_FORMAT) \
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
608 RC_HANDLER(void, NAME, PARAMS, ;, PARAM_FORMAT, ;, ;,\
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
609 (xmlparseobject *)userData)
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
610
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
611 #define INT_HANDLER(NAME, PARAMS, PARAM_FORMAT)\
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
612 RC_HANDLER(int, NAME, PARAMS, int rc=0;, PARAM_FORMAT, \
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
613 rc = PyInt_AsLong(rv);, rc, \
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
614 (xmlparseobject *)userData)
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
615
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
616 VOID_HANDLER(EndElement,
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
617 (void *userData, const XML_Char *name),
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
618 ("(N)", string_intern(self, name)))
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
619
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
620 VOID_HANDLER(ProcessingInstruction,
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
621 (void *userData,
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
622 const XML_Char *target,
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
623 const XML_Char *data),
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
624 ("(NO&)", string_intern(self, target), STRING_CONV_FUNC,data))
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
625
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
626 VOID_HANDLER(UnparsedEntityDecl,
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
627 (void *userData,
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
628 const XML_Char *entityName,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
629 const XML_Char *base,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
630 const XML_Char *systemId,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
631 const XML_Char *publicId,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
632 const XML_Char *notationName),
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
633 ("(NNNNN)",
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
634 string_intern(self, entityName), string_intern(self, base),
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
635 string_intern(self, systemId), string_intern(self, publicId),
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
636 string_intern(self, notationName)))
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
637
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18854
diff changeset
638 #ifndef Py_USING_UNICODE
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
639 VOID_HANDLER(EntityDecl,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
640 (void *userData,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
641 const XML_Char *entityName,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
642 int is_parameter_entity,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
643 const XML_Char *value,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
644 int value_length,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
645 const XML_Char *base,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
646 const XML_Char *systemId,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
647 const XML_Char *publicId,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
648 const XML_Char *notationName),
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
649 ("NiNNNNN",
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
650 string_intern(self, entityName), is_parameter_entity,
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
651 conv_string_len_to_utf8(value, value_length),
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
652 string_intern(self, base), string_intern(self, systemId),
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
653 string_intern(self, publicId),
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
654 string_intern(self, notationName)))
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
655 #else
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
656 VOID_HANDLER(EntityDecl,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
657 (void *userData,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
658 const XML_Char *entityName,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
659 int is_parameter_entity,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
660 const XML_Char *value,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
661 int value_length,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
662 const XML_Char *base,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
663 const XML_Char *systemId,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
664 const XML_Char *publicId,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
665 const XML_Char *notationName),
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
666 ("NiNNNNN",
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
667 string_intern(self, entityName), is_parameter_entity,
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
668 (self->returns_unicode
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
669 ? conv_string_len_to_unicode(value, value_length)
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
670 : conv_string_len_to_utf8(value, value_length)),
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
671 string_intern(self, base), string_intern(self, systemId),
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
672 string_intern(self, publicId),
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
673 string_intern(self, notationName)))
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
674 #endif
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
675
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
676 VOID_HANDLER(XmlDecl,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
677 (void *userData,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
678 const XML_Char *version,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
679 const XML_Char *encoding,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
680 int standalone),
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
681 ("(O&O&i)",
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
682 STRING_CONV_FUNC,version, STRING_CONV_FUNC,encoding,
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
683 standalone))
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
684
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
685 static PyObject *
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
686 conv_content_model(XML_Content * const model,
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
687 PyObject *(*conv_string)(const XML_Char *))
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
688 {
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
689 PyObject *result = NULL;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
690 PyObject *children = PyTuple_New(model->numchildren);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
691 int i;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
692
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
693 if (children != NULL) {
18854
d64628cc8ffc Squash compiler wng about mixing signed and unsigned in comparison.
Tim Peters <tim.peters@gmail.com>
parents: 17623
diff changeset
694 assert(model->numchildren < INT_MAX);
d64628cc8ffc Squash compiler wng about mixing signed and unsigned in comparison.
Tim Peters <tim.peters@gmail.com>
parents: 17623
diff changeset
695 for (i = 0; i < (int)model->numchildren; ++i) {
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
696 PyObject *child = conv_content_model(&model->children[i],
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
697 conv_string);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
698 if (child == NULL) {
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
699 Py_XDECREF(children);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
700 return NULL;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
701 }
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
702 PyTuple_SET_ITEM(children, i, child);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
703 }
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
704 result = Py_BuildValue("(iiO&N)",
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
705 model->type, model->quant,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
706 conv_string,model->name, children);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
707 }
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
708 return result;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
709 }
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
710
27586
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
711 static void
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
712 my_ElementDeclHandler(void *userData,
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
713 const XML_Char *name,
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
714 XML_Content *model)
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
715 {
27586
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
716 xmlparseobject *self = (xmlparseobject *)userData;
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
717 PyObject *args = NULL;
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
718
27586
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
719 if (have_handler(self, ElementDecl)) {
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
720 PyObject *rv = NULL;
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
721 PyObject *modelobj, *nameobj;
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
722
27586
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
723 if (flush_character_buffer(self) < 0)
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
724 goto finally;
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
725 #ifdef Py_USING_UNICODE
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
726 modelobj = conv_content_model(model,
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
727 (self->returns_unicode
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
728 ? conv_string_to_unicode
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
729 : conv_string_to_utf8));
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
730 #else
27586
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
731 modelobj = conv_content_model(model, conv_string_to_utf8);
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
732 #endif
27586
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
733 if (modelobj == NULL) {
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
734 flag_error(self);
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
735 goto finally;
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
736 }
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
737 nameobj = string_intern(self, name);
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
738 if (nameobj == NULL) {
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
739 Py_DECREF(modelobj);
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
740 flag_error(self);
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
741 goto finally;
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
742 }
32923
f1bbf147810b Fix the reference count errors revealed by the test suite...
Michael W. Hudson <mwh@python.net>
parents: 30683
diff changeset
743 args = Py_BuildValue("NN", nameobj, modelobj);
27586
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
744 if (args == NULL) {
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
745 Py_DECREF(modelobj);
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
746 flag_error(self);
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
747 goto finally;
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
748 }
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
749 self->in_callback = 1;
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
750 rv = call_with_frame(getcode(ElementDecl, "ElementDecl", __LINE__),
33113
28e877ff74cf make exception propogation more efficient; this avoids having Expat parse
Fred Drake <fdrake@acm.org>
parents: 32965
diff changeset
751 self->handlers[ElementDecl], args, self);
27586
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
752 self->in_callback = 0;
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
753 if (rv == NULL) {
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
754 flag_error(self);
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
755 goto finally;
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
756 }
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
757 Py_DECREF(rv);
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
758 }
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
759 finally:
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
760 Py_XDECREF(args);
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
761 XML_FreeContentModel(self->itself, model);
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
762 return;
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
763 }
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
764
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
765 VOID_HANDLER(AttlistDecl,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
766 (void *userData,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
767 const XML_Char *elname,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
768 const XML_Char *attname,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
769 const XML_Char *att_type,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
770 const XML_Char *dflt,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
771 int isrequired),
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
772 ("(NNO&O&i)",
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
773 string_intern(self, elname), string_intern(self, attname),
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
774 STRING_CONV_FUNC,att_type, STRING_CONV_FUNC,dflt,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
775 isrequired))
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
776
27322
88bf10313584 Conditionalize features not found in PyXML 1.95.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 27321
diff changeset
777 #if XML_COMBINED_VERSION >= 19504
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
778 VOID_HANDLER(SkippedEntity,
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
779 (void *userData,
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
780 const XML_Char *entityName,
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
781 int is_parameter_entity),
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
782 ("Ni",
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
783 string_intern(self, entityName), is_parameter_entity))
27322
88bf10313584 Conditionalize features not found in PyXML 1.95.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 27321
diff changeset
784 #endif
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
785
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
786 VOID_HANDLER(NotationDecl,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
787 (void *userData,
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
788 const XML_Char *notationName,
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
789 const XML_Char *base,
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
790 const XML_Char *systemId,
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
791 const XML_Char *publicId),
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
792 ("(NNNN)",
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
793 string_intern(self, notationName), string_intern(self, base),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
794 string_intern(self, systemId), string_intern(self, publicId)))
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
795
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
796 VOID_HANDLER(StartNamespaceDecl,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
797 (void *userData,
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
798 const XML_Char *prefix,
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
799 const XML_Char *uri),
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
800 ("(NN)",
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
801 string_intern(self, prefix), string_intern(self, uri)))
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
802
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
803 VOID_HANDLER(EndNamespaceDecl,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
804 (void *userData,
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
805 const XML_Char *prefix),
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
806 ("(N)", string_intern(self, prefix)))
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
807
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
808 VOID_HANDLER(Comment,
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
809 (void *userData, const XML_Char *data),
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
810 ("(O&)", STRING_CONV_FUNC,data))
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
811
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
812 VOID_HANDLER(StartCdataSection,
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
813 (void *userData),
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
814 ("()"))
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
815
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
816 VOID_HANDLER(EndCdataSection,
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
817 (void *userData),
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
818 ("()"))
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
819
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18854
diff changeset
820 #ifndef Py_USING_UNICODE
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
821 VOID_HANDLER(Default,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
822 (void *userData, const XML_Char *s, int len),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
823 ("(N)", conv_string_len_to_utf8(s,len)))
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
824
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
825 VOID_HANDLER(DefaultHandlerExpand,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
826 (void *userData, const XML_Char *s, int len),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
827 ("(N)", conv_string_len_to_utf8(s,len)))
13025
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
828 #else
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
829 VOID_HANDLER(Default,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
830 (void *userData, const XML_Char *s, int len),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
831 ("(N)", (self->returns_unicode
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
832 ? conv_string_len_to_unicode(s,len)
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
833 : conv_string_len_to_utf8(s,len))))
13025
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
834
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
835 VOID_HANDLER(DefaultHandlerExpand,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
836 (void *userData, const XML_Char *s, int len),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
837 ("(N)", (self->returns_unicode
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
838 ? conv_string_len_to_unicode(s,len)
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
839 : conv_string_len_to_utf8(s,len))))
13025
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
840 #endif
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
841
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
842 INT_HANDLER(NotStandalone,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
843 (void *userData),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
844 ("()"))
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
845
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
846 RC_HANDLER(int, ExternalEntityRef,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
847 (XML_Parser parser,
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
848 const XML_Char *context,
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
849 const XML_Char *base,
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
850 const XML_Char *systemId,
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
851 const XML_Char *publicId),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
852 int rc=0;,
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
853 ("(O&NNN)",
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
854 STRING_CONV_FUNC,context, string_intern(self, base),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
855 string_intern(self, systemId), string_intern(self, publicId)),
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
856 rc = PyInt_AsLong(rv);, rc,
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
857 XML_GetUserData(parser))
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
858
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
859 /* XXX UnknownEncodingHandler */
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
860
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
861 VOID_HANDLER(StartDoctypeDecl,
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
862 (void *userData, const XML_Char *doctypeName,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
863 const XML_Char *sysid, const XML_Char *pubid,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
864 int has_internal_subset),
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
865 ("(NNNi)", string_intern(self, doctypeName),
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
866 string_intern(self, sysid), string_intern(self, pubid),
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
867 has_internal_subset))
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
868
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
869 VOID_HANDLER(EndDoctypeDecl, (void *userData), ("()"))
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
870
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
871 /* ---------------------------------------------------------------- */
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
872
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
873 static PyObject *
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
874 get_parse_result(xmlparseobject *self, int rv)
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
875 {
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
876 if (PyErr_Occurred()) {
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
877 return NULL;
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
878 }
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
879 if (rv == 0) {
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
880 return set_error(self, XML_GetErrorCode(self->itself));
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
881 }
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
882 if (flush_character_buffer(self) < 0) {
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
883 return NULL;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
884 }
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
885 return PyInt_FromLong(rv);
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
886 }
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
887
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22421
diff changeset
888 PyDoc_STRVAR(xmlparse_Parse__doc__,
13654
0bb49b3dbdf0 Mark Favas's fix for typos in docstrings.
Thomas Wouters <thomas@python.org>
parents: 13568
diff changeset
889 "Parse(data[, isfinal])\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22421
diff changeset
890 Parse XML data. `isfinal' should be true at end of input.");
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
891
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
892 static PyObject *
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
893 xmlparse_Parse(xmlparseobject *self, PyObject *args)
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
894 {
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
895 char *s;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
896 int slen;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
897 int isFinal = 0;
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
898
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
899 if (!PyArg_ParseTuple(args, "s#|i:Parse", &s, &slen, &isFinal))
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
900 return NULL;
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
901
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
902 return get_parse_result(self, XML_Parse(self->itself, s, slen, isFinal));
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
903 }
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
904
14728
e2c03c30b06d Remove memory leaks of strings/Unicode objects passed into the character
Fred Drake <fdrake@acm.org>
parents: 14375
diff changeset
905 /* File reading copied from cPickle */
e2c03c30b06d Remove memory leaks of strings/Unicode objects passed into the character
Fred Drake <fdrake@acm.org>
parents: 14375
diff changeset
906
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
907 #define BUF_SIZE 2048
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
908
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
909 static int
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
910 readinst(char *buf, int buf_size, PyObject *meth)
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
911 {
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
912 PyObject *arg = NULL;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
913 PyObject *bytes = NULL;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
914 PyObject *str = NULL;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
915 int len = -1;
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
916
14755
93207076d612 When PyInt_FromLong() returns NULL, you do not need to check
Fred Drake <fdrake@acm.org>
parents: 14749
diff changeset
917 if ((bytes = PyInt_FromLong(buf_size)) == NULL)
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
918 goto finally;
14755
93207076d612 When PyInt_FromLong() returns NULL, you do not need to check
Fred Drake <fdrake@acm.org>
parents: 14749
diff changeset
919
29955
09c459851264 Fix memory leak reported & discussed on the Python XML-SIG mailing list.
Fred Drake <fdrake@acm.org>
parents: 29605
diff changeset
920 if ((arg = PyTuple_New(1)) == NULL) {
09c459851264 Fix memory leak reported & discussed on the Python XML-SIG mailing list.
Fred Drake <fdrake@acm.org>
parents: 29605
diff changeset
921 Py_DECREF(bytes);
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
922 goto finally;
29955
09c459851264 Fix memory leak reported & discussed on the Python XML-SIG mailing list.
Fred Drake <fdrake@acm.org>
parents: 29605
diff changeset
923 }
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
924
14749
6f3fd7a2a7bc Fix for SF bug 115051: Dodgy use of PyTuple_SET_ITEM in pyexpat.c
Tim Peters <tim.peters@gmail.com>
parents: 14747
diff changeset
925 PyTuple_SET_ITEM(arg, 0, bytes);
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
926
33752
ddc2d6e547c1 Synchronize with PyXML 1.79:
Martin v. Löwis <martin@v.loewis.de>
parents: 33279
diff changeset
927 #if PY_VERSION_HEX < 0x02020000
ddc2d6e547c1 Synchronize with PyXML 1.79:
Martin v. Löwis <martin@v.loewis.de>
parents: 33279
diff changeset
928 str = PyObject_CallObject(meth, arg);
ddc2d6e547c1 Synchronize with PyXML 1.79:
Martin v. Löwis <martin@v.loewis.de>
parents: 33279
diff changeset
929 #else
ddc2d6e547c1 Synchronize with PyXML 1.79:
Martin v. Löwis <martin@v.loewis.de>
parents: 33279
diff changeset
930 str = PyObject_Call(meth, arg, NULL);
ddc2d6e547c1 Synchronize with PyXML 1.79:
Martin v. Löwis <martin@v.loewis.de>
parents: 33279
diff changeset
931 #endif
ddc2d6e547c1 Synchronize with PyXML 1.79:
Martin v. Löwis <martin@v.loewis.de>
parents: 33279
diff changeset
932 if (str == NULL)
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
933 goto finally;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
934
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
935 /* XXX what to do if it returns a Unicode string? */
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
936 if (!PyString_Check(str)) {
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
937 PyErr_Format(PyExc_TypeError,
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
938 "read() did not return a string object (type=%.400s)",
44350
26384b8180c7 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents: 42333
diff changeset
939 Py_TYPE(str)->tp_name);
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
940 goto finally;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
941 }
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
942 len = PyString_GET_SIZE(str);
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
943 if (len > buf_size) {
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
944 PyErr_Format(PyExc_ValueError,
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
945 "read() returned too much data: "
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
946 "%i bytes requested, %i returned",
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
947 buf_size, len);
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
948 goto finally;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
949 }
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
950 memcpy(buf, PyString_AsString(str), len);
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
951 finally:
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
952 Py_XDECREF(arg);
14728
e2c03c30b06d Remove memory leaks of strings/Unicode objects passed into the character
Fred Drake <fdrake@acm.org>
parents: 14375
diff changeset
953 Py_XDECREF(str);
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
954 return len;
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
955 }
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
956
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22421
diff changeset
957 PyDoc_STRVAR(xmlparse_ParseFile__doc__,
13654
0bb49b3dbdf0 Mark Favas's fix for typos in docstrings.
Thomas Wouters <thomas@python.org>
parents: 13568
diff changeset
958 "ParseFile(file)\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22421
diff changeset
959 Parse XML data from file-like object.");
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
960
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
961 static PyObject *
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 37762
diff changeset
962 xmlparse_ParseFile(xmlparseobject *self, PyObject *f)
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
963 {
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
964 int rv = 1;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
965 PyObject *readmethod = NULL;
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
966
69243
28705a7987c5 #4877: Fix a segfault in xml.parsers.expat while attempting to parse a closed file.
Ezio Melotti
parents: 68256
diff changeset
967 readmethod = PyObject_GetAttrString(f, "read");
28705a7987c5 #4877: Fix a segfault in xml.parsers.expat while attempting to parse a closed file.
Ezio Melotti
parents: 68256
diff changeset
968 if (readmethod == NULL) {
28705a7987c5 #4877: Fix a segfault in xml.parsers.expat while attempting to parse a closed file.
Ezio Melotti
parents: 68256
diff changeset
969 PyErr_SetString(PyExc_TypeError,
28705a7987c5 #4877: Fix a segfault in xml.parsers.expat while attempting to parse a closed file.
Ezio Melotti
parents: 68256
diff changeset
970 "argument must have 'read' attribute");
28705a7987c5 #4877: Fix a segfault in xml.parsers.expat while attempting to parse a closed file.
Ezio Melotti
parents: 68256
diff changeset
971 return NULL;
28705a7987c5 #4877: Fix a segfault in xml.parsers.expat while attempting to parse a closed file.
Ezio Melotti
parents: 68256
diff changeset
972
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
973 }
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
974 for (;;) {
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
975 int bytes_read;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
976 void *buf = XML_GetBuffer(self->itself, BUF_SIZE);
29955
09c459851264 Fix memory leak reported & discussed on the Python XML-SIG mailing list.
Fred Drake <fdrake@acm.org>
parents: 29605
diff changeset
977 if (buf == NULL) {
29957
cea7f8af8e0b Repair mis-application of Jeremy's patch. Thanks, Neal!
Fred Drake <fdrake@acm.org>
parents: 29955
diff changeset
978 Py_XDECREF(readmethod);
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
979 return PyErr_NoMemory();
29955
09c459851264 Fix memory leak reported & discussed on the Python XML-SIG mailing list.
Fred Drake <fdrake@acm.org>
parents: 29605
diff changeset
980 }
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
981
69243
28705a7987c5 #4877: Fix a segfault in xml.parsers.expat while attempting to parse a closed file.
Ezio Melotti
parents: 68256
diff changeset
982 bytes_read = readinst(buf, BUF_SIZE, readmethod);
28705a7987c5 #4877: Fix a segfault in xml.parsers.expat while attempting to parse a closed file.
Ezio Melotti
parents: 68256
diff changeset
983 if (bytes_read < 0) {
28705a7987c5 #4877: Fix a segfault in xml.parsers.expat while attempting to parse a closed file.
Ezio Melotti
parents: 68256
diff changeset
984 Py_XDECREF(readmethod);
28705a7987c5 #4877: Fix a segfault in xml.parsers.expat while attempting to parse a closed file.
Ezio Melotti
parents: 68256
diff changeset
985 return NULL;
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
986 }
69243
28705a7987c5 #4877: Fix a segfault in xml.parsers.expat while attempting to parse a closed file.
Ezio Melotti
parents: 68256
diff changeset
987
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
988 rv = XML_ParseBuffer(self->itself, bytes_read, bytes_read == 0);
29955
09c459851264 Fix memory leak reported & discussed on the Python XML-SIG mailing list.
Fred Drake <fdrake@acm.org>
parents: 29605
diff changeset
989 if (PyErr_Occurred()) {
09c459851264 Fix memory leak reported & discussed on the Python XML-SIG mailing list.
Fred Drake <fdrake@acm.org>
parents: 29605
diff changeset
990 Py_XDECREF(readmethod);
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
991 return NULL;
29955
09c459851264 Fix memory leak reported & discussed on the Python XML-SIG mailing list.
Fred Drake <fdrake@acm.org>
parents: 29605
diff changeset
992 }
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
993
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
994 if (!rv || bytes_read == 0)
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
995 break;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
996 }
29955
09c459851264 Fix memory leak reported & discussed on the Python XML-SIG mailing list.
Fred Drake <fdrake@acm.org>
parents: 29605
diff changeset
997 Py_XDECREF(readmethod);
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
998 return get_parse_result(self, rv);
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
999 }
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1000
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22421
diff changeset
1001 PyDoc_STRVAR(xmlparse_SetBase__doc__,
13654
0bb49b3dbdf0 Mark Favas's fix for typos in docstrings.
Thomas Wouters <thomas@python.org>
parents: 13568
diff changeset
1002 "SetBase(base_url)\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22421
diff changeset
1003 Set the base URL for the parser.");
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1004
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1005 static PyObject *
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1006 xmlparse_SetBase(xmlparseobject *self, PyObject *args)
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1007 {
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1008 char *base;
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1009
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1010 if (!PyArg_ParseTuple(args, "s:SetBase", &base))
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1011 return NULL;
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1012 if (!XML_SetBase(self->itself, base)) {
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1013 return PyErr_NoMemory();
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1014 }
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1015 Py_INCREF(Py_None);
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1016 return Py_None;
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1017 }
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1018
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22421
diff changeset
1019 PyDoc_STRVAR(xmlparse_GetBase__doc__,
13654
0bb49b3dbdf0 Mark Favas's fix for typos in docstrings.
Thomas Wouters <thomas@python.org>
parents: 13568
diff changeset
1020 "GetBase() -> url\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22421
diff changeset
1021 Return base URL string for the parser.");
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1022
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1023 static PyObject *
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 37762
diff changeset
1024 xmlparse_GetBase(xmlparseobject *self, PyObject *unused)
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1025 {
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1026 return Py_BuildValue("z", XML_GetBase(self->itself));
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1027 }
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1028
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22421
diff changeset
1029 PyDoc_STRVAR(xmlparse_GetInputContext__doc__,
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
1030 "GetInputContext() -> string\n\
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
1031 Return the untranslated text of the input that caused the current event.\n\
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
1032 If the event was generated by a large amount of text (such as a start tag\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22421
diff changeset
1033 for an element with many attributes), not all of the text may be available.");
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
1034
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
1035 static PyObject *
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 37762
diff changeset
1036 xmlparse_GetInputContext(xmlparseobject *self, PyObject *unused)
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
1037 {
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 37762
diff changeset
1038 if (self->in_callback) {
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 37762
diff changeset
1039 int offset, size;
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 37762
diff changeset
1040 const char *buffer
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 37762
diff changeset
1041 = XML_GetInputContext(self->itself, &offset, &size);
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
1042
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 37762
diff changeset
1043 if (buffer != NULL)
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
1044 return PyString_FromStringAndSize(buffer + offset,
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 37762
diff changeset
1045 size - offset);
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 37762
diff changeset
1046 else
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 37762
diff changeset
1047 Py_RETURN_NONE;
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
1048 }
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 37762
diff changeset
1049 else
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 37762
diff changeset
1050 Py_RETURN_NONE;
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
1051 }
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
1052
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22421
diff changeset
1053 PyDoc_STRVAR(xmlparse_ExternalEntityParserCreate__doc__,
15703
f6ee0d4672d6 Mark the "encoding" parameter to ExternalEntityParserCreate() as optional
Fred Drake <fdrake@acm.org>
parents: 15642
diff changeset
1054 "ExternalEntityParserCreate(context[, encoding])\n\
14824
a1033283a25d Repaired damaged string.
Tim Peters <tim.peters@gmail.com>
parents: 14823
diff changeset
1055 Create a parser for parsing an external entity based on the\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22421
diff changeset
1056 information passed to the ExternalEntityRefHandler.");
14812
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1057
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1058 static PyObject *
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1059 xmlparse_ExternalEntityParserCreate(xmlparseobject *self, PyObject *args)
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1060 {
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1061 char *context;
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1062 char *encoding = NULL;
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1063 xmlparseobject *new_parser;
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1064 int i;
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1065
19978
a960e673077f Patch to bug #461753: Allow None in ExternalEntityParserCreate.
Martin v. Löwis <martin@v.loewis.de>
parents: 19343
diff changeset
1066 if (!PyArg_ParseTuple(args, "z|s:ExternalEntityParserCreate",
17623
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1067 &context, &encoding)) {
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1068 return NULL;
14812
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1069 }
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1070
20047
4c5cd3d1cf4b Reactivate participation of expat parsers in GC. Fixes bug #462710.
Martin v. Löwis <martin@v.loewis.de>
parents: 19979
diff changeset
1071 #ifndef Py_TPFLAGS_HAVE_GC
24064
92834a248c15 Define PyDoc_STRVAR if it is not available (PyXML 1.54).
Martin v. Löwis <martin@v.loewis.de>
parents: 24063
diff changeset
1072 /* Python versions 2.0 and 2.1 */
14812
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1073 new_parser = PyObject_New(xmlparseobject, &Xmlparsetype);
20047
4c5cd3d1cf4b Reactivate participation of expat parsers in GC. Fixes bug #462710.
Martin v. Löwis <martin@v.loewis.de>
parents: 19979
diff changeset
1074 #else
4c5cd3d1cf4b Reactivate participation of expat parsers in GC. Fixes bug #462710.
Martin v. Löwis <martin@v.loewis.de>
parents: 19979
diff changeset
1075 /* Python versions 2.2 and later */
4c5cd3d1cf4b Reactivate participation of expat parsers in GC. Fixes bug #462710.
Martin v. Löwis <martin@v.loewis.de>
parents: 19979
diff changeset
1076 new_parser = PyObject_GC_New(xmlparseobject, &Xmlparsetype);
4c5cd3d1cf4b Reactivate participation of expat parsers in GC. Fixes bug #462710.
Martin v. Löwis <martin@v.loewis.de>
parents: 19979
diff changeset
1077 #endif
14812
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1078
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1079 if (new_parser == NULL)
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1080 return NULL;
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1081 new_parser->buffer_size = self->buffer_size;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1082 new_parser->buffer_used = 0;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1083 if (self->buffer != NULL) {
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1084 new_parser->buffer = malloc(new_parser->buffer_size);
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1085 if (new_parser->buffer == NULL) {
24079
183eba2d2214 Do not depend on pymemcompat.h (was only used for PyXML); Martin likes
Fred Drake <fdrake@acm.org>
parents: 24076
diff changeset
1086 #ifndef Py_TPFLAGS_HAVE_GC
183eba2d2214 Do not depend on pymemcompat.h (was only used for PyXML); Martin likes
Fred Drake <fdrake@acm.org>
parents: 24076
diff changeset
1087 /* Code for versions 2.0 and 2.1 */
183eba2d2214 Do not depend on pymemcompat.h (was only used for PyXML); Martin likes
Fred Drake <fdrake@acm.org>
parents: 24076
diff changeset
1088 PyObject_Del(new_parser);
183eba2d2214 Do not depend on pymemcompat.h (was only used for PyXML); Martin likes
Fred Drake <fdrake@acm.org>
parents: 24076
diff changeset
1089 #else
183eba2d2214 Do not depend on pymemcompat.h (was only used for PyXML); Martin likes
Fred Drake <fdrake@acm.org>
parents: 24076
diff changeset
1090 /* Code for versions 2.2 and later. */
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1091 PyObject_GC_Del(new_parser);
24079
183eba2d2214 Do not depend on pymemcompat.h (was only used for PyXML); Martin likes
Fred Drake <fdrake@acm.org>
parents: 24076
diff changeset
1092 #endif
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1093 return PyErr_NoMemory();
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1094 }
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1095 }
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1096 else
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1097 new_parser->buffer = NULL;
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1098 new_parser->returns_unicode = self->returns_unicode;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1099 new_parser->ordered_attributes = self->ordered_attributes;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1100 new_parser->specified_attributes = self->specified_attributes;
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
1101 new_parser->in_callback = 0;
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1102 new_parser->ns_prefixes = self->ns_prefixes;
14812
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1103 new_parser->itself = XML_ExternalEntityParserCreate(self->itself, context,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1104 encoding);
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1105 new_parser->handlers = 0;
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1106 new_parser->intern = self->intern;
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1107 Py_XINCREF(new_parser->intern);
20047
4c5cd3d1cf4b Reactivate participation of expat parsers in GC. Fixes bug #462710.
Martin v. Löwis <martin@v.loewis.de>
parents: 19979
diff changeset
1108 #ifdef Py_TPFLAGS_HAVE_GC
4c5cd3d1cf4b Reactivate participation of expat parsers in GC. Fixes bug #462710.
Martin v. Löwis <martin@v.loewis.de>
parents: 19979
diff changeset
1109 PyObject_GC_Track(new_parser);
4c5cd3d1cf4b Reactivate participation of expat parsers in GC. Fixes bug #462710.
Martin v. Löwis <martin@v.loewis.de>
parents: 19979
diff changeset
1110 #else
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1111 PyObject_GC_Init(new_parser);
20047
4c5cd3d1cf4b Reactivate participation of expat parsers in GC. Fixes bug #462710.
Martin v. Löwis <martin@v.loewis.de>
parents: 19979
diff changeset
1112 #endif
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1113
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1114 if (!new_parser->itself) {
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1115 Py_DECREF(new_parser);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1116 return PyErr_NoMemory();
14812
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1117 }
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1118
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1119 XML_SetUserData(new_parser->itself, (void *)new_parser);
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1120
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1121 /* allocate and clear handlers first */
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1122 for (i = 0; handler_info[i].name != NULL; i++)
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1123 /* do nothing */;
14812
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1124
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1125 new_parser->handlers = malloc(sizeof(PyObject *) * i);
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1126 if (!new_parser->handlers) {
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1127 Py_DECREF(new_parser);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1128 return PyErr_NoMemory();
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1129 }
20588
aad762503d11 Change clear_handlers argument to indicate whether this is an initialization.
Martin v. Löwis <martin@v.loewis.de>
parents: 20047
diff changeset
1130 clear_handlers(new_parser, 1);
14812
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1131
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1132 /* then copy handlers from self */
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1133 for (i = 0; handler_info[i].name != NULL; i++) {
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1134 PyObject *handler = self->handlers[i];
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1135 if (handler != NULL) {
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1136 Py_INCREF(handler);
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1137 new_parser->handlers[i] = handler;
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1138 handler_info[i].setter(new_parser->itself,
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1139 handler_info[i].handler);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1140 }
14812
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1141 }
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1142 return (PyObject *)new_parser;
14812
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1143 }
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1144
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22421
diff changeset
1145 PyDoc_STRVAR(xmlparse_SetParamEntityParsing__doc__,
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1146 "SetParamEntityParsing(flag) -> success\n\
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1147 Controls parsing of parameter entities (including the external DTD\n\
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1148 subset). Possible flag values are XML_PARAM_ENTITY_PARSING_NEVER,\n\
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1149 XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE and\n\
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1150 XML_PARAM_ENTITY_PARSING_ALWAYS. Returns true if setting the flag\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22421
diff changeset
1151 was successful.");
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1152
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1153 static PyObject*
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
1154 xmlparse_SetParamEntityParsing(xmlparseobject *p, PyObject* args)
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1155 {
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1156 int flag;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1157 if (!PyArg_ParseTuple(args, "i", &flag))
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1158 return NULL;
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
1159 flag = XML_SetParamEntityParsing(p->itself, flag);
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1160 return PyInt_FromLong(flag);
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1161 }
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1162
27322
88bf10313584 Conditionalize features not found in PyXML 1.95.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 27321
diff changeset
1163
88bf10313584 Conditionalize features not found in PyXML 1.95.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 27321
diff changeset
1164 #if XML_COMBINED_VERSION >= 19505
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1165 PyDoc_STRVAR(xmlparse_UseForeignDTD__doc__,
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1166 "UseForeignDTD([flag])\n\
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1167 Allows the application to provide an artificial external subset if one is\n\
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1168 not specified as part of the document instance. This readily allows the\n\
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1169 use of a 'default' document type controlled by the application, while still\n\
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1170 getting the advantage of providing document type information to the parser.\n\
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1171 'flag' defaults to True if not provided.");
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1172
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1173 static PyObject *
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1174 xmlparse_UseForeignDTD(xmlparseobject *self, PyObject *args)
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1175 {
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1176 PyObject *flagobj = NULL;
78603
ba1c48f8b571 Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents: 75681
diff changeset
1177 int flag = 1;
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1178 enum XML_Error rc;
79138
3e0d632ce910 Issue #16012: Fix a regression in pyexpat. The parser's UseForeignDTD()
Christian Heimes <christian@cheimes.de>
parents: 78603
diff changeset
1179 if (!PyArg_ParseTuple(args, "|O:UseForeignDTD", &flagobj))
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1180 return NULL;
78603
ba1c48f8b571 Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents: 75681
diff changeset
1181 if (flagobj != NULL) {
ba1c48f8b571 Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents: 75681
diff changeset
1182 flag = PyObject_IsTrue(flagobj);
ba1c48f8b571 Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents: 75681
diff changeset
1183 if (flag < 0)
ba1c48f8b571 Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents: 75681
diff changeset
1184 return NULL;
ba1c48f8b571 Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents: 75681
diff changeset
1185 }
ba1c48f8b571 Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents: 75681
diff changeset
1186 rc = XML_UseForeignDTD(self->itself, flag ? XML_TRUE : XML_FALSE);
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1187 if (rc != XML_ERROR_NONE) {
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1188 return set_error(self, rc);
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1189 }
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1190 Py_INCREF(Py_None);
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1191 return Py_None;
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1192 }
27322
88bf10313584 Conditionalize features not found in PyXML 1.95.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 27321
diff changeset
1193 #endif
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1194
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1195 static struct PyMethodDef xmlparse_methods[] = {
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1196 {"Parse", (PyCFunction)xmlparse_Parse,
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1197 METH_VARARGS, xmlparse_Parse__doc__},
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1198 {"ParseFile", (PyCFunction)xmlparse_ParseFile,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1199 METH_O, xmlparse_ParseFile__doc__},
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1200 {"SetBase", (PyCFunction)xmlparse_SetBase,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1201 METH_VARARGS, xmlparse_SetBase__doc__},
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1202 {"GetBase", (PyCFunction)xmlparse_GetBase,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1203 METH_NOARGS, xmlparse_GetBase__doc__},
14812
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1204 {"ExternalEntityParserCreate", (PyCFunction)xmlparse_ExternalEntityParserCreate,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1205 METH_VARARGS, xmlparse_ExternalEntityParserCreate__doc__},
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
1206 {"SetParamEntityParsing", (PyCFunction)xmlparse_SetParamEntityParsing,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1207 METH_VARARGS, xmlparse_SetParamEntityParsing__doc__},
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
1208 {"GetInputContext", (PyCFunction)xmlparse_GetInputContext,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1209 METH_NOARGS, xmlparse_GetInputContext__doc__},
27322
88bf10313584 Conditionalize features not found in PyXML 1.95.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 27321
diff changeset
1210 #if XML_COMBINED_VERSION >= 19505
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1211 {"UseForeignDTD", (PyCFunction)xmlparse_UseForeignDTD,
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1212 METH_VARARGS, xmlparse_UseForeignDTD__doc__},
27322
88bf10313584 Conditionalize features not found in PyXML 1.95.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 27321
diff changeset
1213 #endif
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1214 {NULL, NULL} /* sentinel */
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1215 };
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1216
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1217 /* ---------- */
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1218
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1219
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18854
diff changeset
1220 #ifdef Py_USING_UNICODE
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1221
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1222 /* pyexpat international encoding support.
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1223 Make it as simple as possible.
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1224 */
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1225
16099
967abbecc404 Fix off-by-one error in array size.
Martin v. Löwis <martin@v.loewis.de>
parents: 16094
diff changeset
1226 static char template_buffer[257];
16912
a46a13201eeb Wrap some long lines, use only C89 /* */ comments, and add spaces around
Fred Drake <fdrake@acm.org>
parents: 16644
diff changeset
1227 PyObject *template_string = NULL;
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1228
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1229 static void
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1230 init_template_buffer(void)
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1231 {
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1232 int i;
16912
a46a13201eeb Wrap some long lines, use only C89 /* */ comments, and add spaces around
Fred Drake <fdrake@acm.org>
parents: 16644
diff changeset
1233 for (i = 0; i < 256; i++) {
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1234 template_buffer[i] = i;
16644
7f127be07c50 Bug #132816: Compiler warning in PYEXPAT.C for extra ';'
Tim Peters <tim.peters@gmail.com>
parents: 16632
diff changeset
1235 }
16912
a46a13201eeb Wrap some long lines, use only C89 /* */ comments, and add spaces around
Fred Drake <fdrake@acm.org>
parents: 16644
diff changeset
1236 template_buffer[256] = 0;
16644
7f127be07c50 Bug #132816: Compiler warning in PYEXPAT.C for extra ';'
Tim Peters <tim.peters@gmail.com>
parents: 16632
diff changeset
1237 }
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1238
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1239 static int
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1240 PyUnknownEncodingHandler(void *encodingHandlerData,
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1241 const XML_Char *name,
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1242 XML_Encoding *info)
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1243 {
16912
a46a13201eeb Wrap some long lines, use only C89 /* */ comments, and add spaces around
Fred Drake <fdrake@acm.org>
parents: 16644
diff changeset
1244 PyUnicodeObject *_u_string = NULL;
a46a13201eeb Wrap some long lines, use only C89 /* */ comments, and add spaces around
Fred Drake <fdrake@acm.org>
parents: 16644
diff changeset
1245 int result = 0;
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1246 int i;
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1247
16912
a46a13201eeb Wrap some long lines, use only C89 /* */ comments, and add spaces around
Fred Drake <fdrake@acm.org>
parents: 16644
diff changeset
1248 /* Yes, supports only 8bit encodings */
a46a13201eeb Wrap some long lines, use only C89 /* */ comments, and add spaces around
Fred Drake <fdrake@acm.org>
parents: 16644
diff changeset
1249 _u_string = (PyUnicodeObject *)
a46a13201eeb Wrap some long lines, use only C89 /* */ comments, and add spaces around
Fred Drake <fdrake@acm.org>
parents: 16644
diff changeset
1250 PyUnicode_Decode(template_buffer, 256, name, "replace");
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1251
16912
a46a13201eeb Wrap some long lines, use only C89 /* */ comments, and add spaces around
Fred Drake <fdrake@acm.org>
parents: 16644
diff changeset
1252 if (_u_string == NULL)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1253 return result;
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1254
16912
a46a13201eeb Wrap some long lines, use only C89 /* */ comments, and add spaces around
Fred Drake <fdrake@acm.org>
parents: 16644
diff changeset
1255 for (i = 0; i < 256; i++) {
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1256 /* Stupid to access directly, but fast */
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1257 Py_UNICODE c = _u_string->str[i];
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1258 if (c == Py_UNICODE_REPLACEMENT_CHARACTER)
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1259 info->map[i] = -1;
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1260 else
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1261 info->map[i] = c;
16644
7f127be07c50 Bug #132816: Compiler warning in PYEXPAT.C for extra ';'
Tim Peters <tim.peters@gmail.com>
parents: 16632
diff changeset
1262 }
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1263 info->data = NULL;
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1264 info->convert = NULL;
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1265 info->release = NULL;
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1266 result = 1;
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1267 Py_DECREF(_u_string);
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1268 return result;
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1269 }
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1270
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1271 #endif
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1272
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1273 static PyObject *
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1274 newxmlparseobject(char *encoding, char *namespace_separator, PyObject *intern)
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1275 {
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1276 int i;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1277 xmlparseobject *self;
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1278
20047
4c5cd3d1cf4b Reactivate participation of expat parsers in GC. Fixes bug #462710.
Martin v. Löwis <martin@v.loewis.de>
parents: 19979
diff changeset
1279 #ifdef Py_TPFLAGS_HAVE_GC
4c5cd3d1cf4b Reactivate participation of expat parsers in GC. Fixes bug #462710.
Martin v. Löwis <martin@v.loewis.de>
parents: 19979
diff changeset
1280 /* Code for versions 2.2 and later */
4c5cd3d1cf4b Reactivate participation of expat parsers in GC. Fixes bug #462710.
Martin v. Löwis <martin@v.loewis.de>
parents: 19979
diff changeset
1281 self = PyObject_GC_New(xmlparseobject, &Xmlparsetype);
4c5cd3d1cf4b Reactivate participation of expat parsers in GC. Fixes bug #462710.
Martin v. Löwis <martin@v.loewis.de>
parents: 19979
diff changeset
1282 #else
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1283 self = PyObject_New(xmlparseobject, &Xmlparsetype);
20047
4c5cd3d1cf4b Reactivate participation of expat parsers in GC. Fixes bug #462710.
Martin v. Löwis <martin@v.loewis.de>
parents: 19979
diff changeset
1284 #endif
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1285 if (self == NULL)
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1286 return NULL;
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1287
24064
92834a248c15 Define PyDoc_STRVAR if it is not available (PyXML 1.54).
Martin v. Löwis <martin@v.loewis.de>
parents: 24063
diff changeset
1288 #ifdef Py_USING_UNICODE
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1289 self->returns_unicode = 1;
24064
92834a248c15 Define PyDoc_STRVAR if it is not available (PyXML 1.54).
Martin v. Löwis <martin@v.loewis.de>
parents: 24063
diff changeset
1290 #else
92834a248c15 Define PyDoc_STRVAR if it is not available (PyXML 1.54).
Martin v. Löwis <martin@v.loewis.de>
parents: 24063
diff changeset
1291 self->returns_unicode = 0;
13025
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
1292 #endif
24064
92834a248c15 Define PyDoc_STRVAR if it is not available (PyXML 1.54).
Martin v. Löwis <martin@v.loewis.de>
parents: 24063
diff changeset
1293
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1294 self->buffer = NULL;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1295 self->buffer_size = CHARACTER_DATA_BUFFER_SIZE;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1296 self->buffer_used = 0;
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1297 self->ordered_attributes = 0;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1298 self->specified_attributes = 0;
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
1299 self->in_callback = 0;
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1300 self->ns_prefixes = 0;
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1301 self->handlers = NULL;
17623
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1302 if (namespace_separator != NULL) {
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1303 self->itself = XML_ParserCreateNS(encoding, *namespace_separator);
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1304 }
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1305 else {
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1306 self->itself = XML_ParserCreate(encoding);
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1307 }
75680
cb72aa8a8008 Fixes Issue 14234: fix for the previous commit, keep compilation when
Gregory P. Smith <greg@krypto.org>
parents: 75667
diff changeset
1308 #if ((XML_MAJOR_VERSION >= 2) && (XML_MINOR_VERSION >= 1)) || defined(XML_HAS_SET_HASH_SALT)
cb72aa8a8008 Fixes Issue 14234: fix for the previous commit, keep compilation when
Gregory P. Smith <greg@krypto.org>
parents: 75667
diff changeset
1309 /* This feature was added upstream in libexpat 2.1.0. Our expat copy
cb72aa8a8008 Fixes Issue 14234: fix for the previous commit, keep compilation when
Gregory P. Smith <greg@krypto.org>
parents: 75667
diff changeset
1310 * has a backport of this feature where we also define XML_HAS_SET_HASH_SALT
cb72aa8a8008 Fixes Issue 14234: fix for the previous commit, keep compilation when
Gregory P. Smith <greg@krypto.org>
parents: 75667
diff changeset
1311 * to indicate that we can still use it. */
75673
9c8d066013ea - Issue #14234: CVE-2012-0876: Randomize hashes of xml attributes in the hash
Barry Warsaw <barry@python.org>
parents: 61465
diff changeset
1312 XML_SetHashSalt(self->itself,
9c8d066013ea - Issue #14234: CVE-2012-0876: Randomize hashes of xml attributes in the hash
Barry Warsaw <barry@python.org>
parents: 61465
diff changeset
1313 (unsigned long)_Py_HashSecret.prefix);
75680
cb72aa8a8008 Fixes Issue 14234: fix for the previous commit, keep compilation when
Gregory P. Smith <greg@krypto.org>
parents: 75667
diff changeset
1314 #endif
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1315 self->intern = intern;
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1316 Py_XINCREF(self->intern);
20047
4c5cd3d1cf4b Reactivate participation of expat parsers in GC. Fixes bug #462710.
Martin v. Löwis <martin@v.loewis.de>
parents: 19979
diff changeset
1317 #ifdef Py_TPFLAGS_HAVE_GC
4c5cd3d1cf4b Reactivate participation of expat parsers in GC. Fixes bug #462710.
Martin v. Löwis <martin@v.loewis.de>
parents: 19979
diff changeset
1318 PyObject_GC_Track(self);
4c5cd3d1cf4b Reactivate participation of expat parsers in GC. Fixes bug #462710.
Martin v. Löwis <martin@v.loewis.de>
parents: 19979
diff changeset
1319 #else
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1320 PyObject_GC_Init(self);
20047
4c5cd3d1cf4b Reactivate participation of expat parsers in GC. Fixes bug #462710.
Martin v. Löwis <martin@v.loewis.de>
parents: 19979
diff changeset
1321 #endif
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1322 if (self->itself == NULL) {
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1323 PyErr_SetString(PyExc_RuntimeError,
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1324 "XML_ParserCreate failed");
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1325 Py_DECREF(self);
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1326 return NULL;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1327 }
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1328 XML_SetUserData(self->itself, (void *)self);
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18854
diff changeset
1329 #ifdef Py_USING_UNICODE
24076
95ccd5bbdc86 Bring this back into sync with PyXML revision 1.58.
Fred Drake <fdrake@acm.org>
parents: 24064
diff changeset
1330 XML_SetUnknownEncodingHandler(self->itself,
95ccd5bbdc86 Bring this back into sync with PyXML revision 1.58.
Fred Drake <fdrake@acm.org>
parents: 24064
diff changeset
1331 (XML_UnknownEncodingHandler) PyUnknownEncodingHandler, NULL);
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1332 #endif
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1333
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1334 for (i = 0; handler_info[i].name != NULL; i++)
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1335 /* do nothing */;
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1336
24076
95ccd5bbdc86 Bring this back into sync with PyXML revision 1.58.
Fred Drake <fdrake@acm.org>
parents: 24064
diff changeset
1337 self->handlers = malloc(sizeof(PyObject *) * i);
95ccd5bbdc86 Bring this back into sync with PyXML revision 1.58.
Fred Drake <fdrake@acm.org>
parents: 24064
diff changeset
1338 if (!self->handlers) {
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1339 Py_DECREF(self);
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1340 return PyErr_NoMemory();
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1341 }
20588
aad762503d11 Change clear_handlers argument to indicate whether this is an initialization.
Martin v. Löwis <martin@v.loewis.de>
parents: 20047
diff changeset
1342 clear_handlers(self, 1);
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1343
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1344 return (PyObject*)self;
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1345 }
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1346
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1347
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1348 static void
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1349 xmlparse_dealloc(xmlparseobject *self)
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1350 {
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1351 int i;
20047
4c5cd3d1cf4b Reactivate participation of expat parsers in GC. Fixes bug #462710.
Martin v. Löwis <martin@v.loewis.de>
parents: 19979
diff changeset
1352 #ifdef Py_TPFLAGS_HAVE_GC
4c5cd3d1cf4b Reactivate participation of expat parsers in GC. Fixes bug #462710.
Martin v. Löwis <martin@v.loewis.de>
parents: 19979
diff changeset
1353 PyObject_GC_UnTrack(self);
4c5cd3d1cf4b Reactivate participation of expat parsers in GC. Fixes bug #462710.
Martin v. Löwis <martin@v.loewis.de>
parents: 19979
diff changeset
1354 #else
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1355 PyObject_GC_Fini(self);
20047
4c5cd3d1cf4b Reactivate participation of expat parsers in GC. Fixes bug #462710.
Martin v. Löwis <martin@v.loewis.de>
parents: 19979
diff changeset
1356 #endif
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1357 if (self->itself != NULL)
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1358 XML_ParserFree(self->itself);
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1359 self->itself = NULL;
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1360
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1361 if (self->handlers != NULL) {
17623
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1362 PyObject *temp;
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1363 for (i = 0; handler_info[i].name != NULL; i++) {
17623
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1364 temp = self->handlers[i];
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1365 self->handlers[i] = NULL;
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1366 Py_XDECREF(temp);
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1367 }
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1368 free(self->handlers);
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1369 self->handlers = NULL;
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1370 }
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1371 if (self->buffer != NULL) {
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1372 free(self->buffer);
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1373 self->buffer = NULL;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1374 }
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1375 Py_XDECREF(self->intern);
20047
4c5cd3d1cf4b Reactivate participation of expat parsers in GC. Fixes bug #462710.
Martin v. Löwis <martin@v.loewis.de>
parents: 19979
diff changeset
1376 #ifndef Py_TPFLAGS_HAVE_GC
24064
92834a248c15 Define PyDoc_STRVAR if it is not available (PyXML 1.54).
Martin v. Löwis <martin@v.loewis.de>
parents: 24063
diff changeset
1377 /* Code for versions 2.0 and 2.1 */
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1378 PyObject_Del(self);
20047
4c5cd3d1cf4b Reactivate participation of expat parsers in GC. Fixes bug #462710.
Martin v. Löwis <martin@v.loewis.de>
parents: 19979
diff changeset
1379 #else
4c5cd3d1cf4b Reactivate participation of expat parsers in GC. Fixes bug #462710.
Martin v. Löwis <martin@v.loewis.de>
parents: 19979
diff changeset
1380 /* Code for versions 2.2 and later. */
4c5cd3d1cf4b Reactivate participation of expat parsers in GC. Fixes bug #462710.
Martin v. Löwis <martin@v.loewis.de>
parents: 19979
diff changeset
1381 PyObject_GC_Del(self);
4c5cd3d1cf4b Reactivate participation of expat parsers in GC. Fixes bug #462710.
Martin v. Löwis <martin@v.loewis.de>
parents: 19979
diff changeset
1382 #endif
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1383 }
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1384
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1385 static int
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1386 handlername2int(const char *name)
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1387 {
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1388 int i;
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1389 for (i = 0; handler_info[i].name != NULL; i++) {
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1390 if (strcmp(name, handler_info[i].name) == 0) {
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1391 return i;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1392 }
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1393 }
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1394 return -1;
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1395 }
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1396
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1397 static PyObject *
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1398 get_pybool(int istrue)
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1399 {
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1400 PyObject *result = istrue ? Py_True : Py_False;
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1401 Py_INCREF(result);
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1402 return result;
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1403 }
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1404
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1405 static PyObject *
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1406 xmlparse_getattr(xmlparseobject *self, char *name)
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1407 {
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1408 int handlernum = handlername2int(name);
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1409
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1410 if (handlernum != -1) {
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1411 PyObject *result = self->handlers[handlernum];
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1412 if (result == NULL)
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1413 result = Py_None;
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1414 Py_INCREF(result);
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1415 return result;
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1416 }
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1417 if (name[0] == 'E') {
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1418 if (strcmp(name, "ErrorCode") == 0)
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1419 return PyInt_FromLong((long)
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1420 XML_GetErrorCode(self->itself));
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1421 if (strcmp(name, "ErrorLineNumber") == 0)
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1422 return PyInt_FromLong((long)
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1423 XML_GetErrorLineNumber(self->itself));
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1424 if (strcmp(name, "ErrorColumnNumber") == 0)
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1425 return PyInt_FromLong((long)
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1426 XML_GetErrorColumnNumber(self->itself));
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1427 if (strcmp(name, "ErrorByteIndex") == 0)
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1428 return PyInt_FromLong((long)
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1429 XML_GetErrorByteIndex(self->itself));
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1430 }
33279
b25cb2045dac Patch #1014930. Expose current parse location to XMLParser.
Dave Cole <djc@object-craft.com.au>
parents: 33113
diff changeset
1431 if (name[0] == 'C') {
b25cb2045dac Patch #1014930. Expose current parse location to XMLParser.
Dave Cole <djc@object-craft.com.au>
parents: 33113
diff changeset
1432 if (strcmp(name, "CurrentLineNumber") == 0)
b25cb2045dac Patch #1014930. Expose current parse location to XMLParser.
Dave Cole <djc@object-craft.com.au>
parents: 33113
diff changeset
1433 return PyInt_FromLong((long)
b25cb2045dac Patch #1014930. Expose current parse location to XMLParser.
Dave Cole <djc@object-craft.com.au>
parents: 33113
diff changeset
1434 XML_GetCurrentLineNumber(self->itself));
b25cb2045dac Patch #1014930. Expose current parse location to XMLParser.
Dave Cole <djc@object-craft.com.au>
parents: 33113
diff changeset
1435 if (strcmp(name, "CurrentColumnNumber") == 0)
b25cb2045dac Patch #1014930. Expose current parse location to XMLParser.
Dave Cole <djc@object-craft.com.au>
parents: 33113
diff changeset
1436 return PyInt_FromLong((long)
b25cb2045dac Patch #1014930. Expose current parse location to XMLParser.
Dave Cole <djc@object-craft.com.au>
parents: 33113
diff changeset
1437 XML_GetCurrentColumnNumber(self->itself));
b25cb2045dac Patch #1014930. Expose current parse location to XMLParser.
Dave Cole <djc@object-craft.com.au>
parents: 33113
diff changeset
1438 if (strcmp(name, "CurrentByteIndex") == 0)
b25cb2045dac Patch #1014930. Expose current parse location to XMLParser.
Dave Cole <djc@object-craft.com.au>
parents: 33113
diff changeset
1439 return PyInt_FromLong((long)
b25cb2045dac Patch #1014930. Expose current parse location to XMLParser.
Dave Cole <djc@object-craft.com.au>
parents: 33113
diff changeset
1440 XML_GetCurrentByteIndex(self->itself));
b25cb2045dac Patch #1014930. Expose current parse location to XMLParser.
Dave Cole <djc@object-craft.com.au>
parents: 33113
diff changeset
1441 }
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1442 if (name[0] == 'b') {
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1443 if (strcmp(name, "buffer_size") == 0)
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1444 return PyInt_FromLong((long) self->buffer_size);
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1445 if (strcmp(name, "buffer_text") == 0)
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1446 return get_pybool(self->buffer != NULL);
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1447 if (strcmp(name, "buffer_used") == 0)
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1448 return PyInt_FromLong((long) self->buffer_used);
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1449 }
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1450 if (strcmp(name, "namespace_prefixes") == 0)
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1451 return get_pybool(self->ns_prefixes);
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1452 if (strcmp(name, "ordered_attributes") == 0)
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1453 return get_pybool(self->ordered_attributes);
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1454 if (strcmp(name, "returns_unicode") == 0)
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1455 return get_pybool((long) self->returns_unicode);
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1456 if (strcmp(name, "specified_attributes") == 0)
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1457 return get_pybool((long) self->specified_attributes);
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1458 if (strcmp(name, "intern") == 0) {
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1459 if (self->intern == NULL) {
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1460 Py_INCREF(Py_None);
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1461 return Py_None;
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1462 }
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1463 else {
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1464 Py_INCREF(self->intern);
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1465 return self->intern;
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1466 }
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1467 }
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1468
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1469 #define APPEND(list, str) \
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1470 do { \
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1471 PyObject *o = PyString_FromString(str); \
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1472 if (o != NULL) \
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1473 PyList_Append(list, o); \
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1474 Py_XDECREF(o); \
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1475 } while (0)
27301
5a975e82d70f SF # 669553, fix memory (ref) leaks
Neal Norwitz <nnorwitz@gmail.com>
parents: 26109
diff changeset
1476
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1477 if (strcmp(name, "__members__") == 0) {
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1478 int i;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1479 PyObject *rc = PyList_New(0);
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1480 if (!rc)
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1481 return NULL;
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1482 for (i = 0; handler_info[i].name != NULL; i++) {
27301
5a975e82d70f SF # 669553, fix memory (ref) leaks
Neal Norwitz <nnorwitz@gmail.com>
parents: 26109
diff changeset
1483 PyObject *o = get_handler_name(&handler_info[i]);
5a975e82d70f SF # 669553, fix memory (ref) leaks
Neal Norwitz <nnorwitz@gmail.com>
parents: 26109
diff changeset
1484 if (o != NULL)
5a975e82d70f SF # 669553, fix memory (ref) leaks
Neal Norwitz <nnorwitz@gmail.com>
parents: 26109
diff changeset
1485 PyList_Append(rc, o);
5a975e82d70f SF # 669553, fix memory (ref) leaks
Neal Norwitz <nnorwitz@gmail.com>
parents: 26109
diff changeset
1486 Py_XDECREF(o);
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1487 }
27301
5a975e82d70f SF # 669553, fix memory (ref) leaks
Neal Norwitz <nnorwitz@gmail.com>
parents: 26109
diff changeset
1488 APPEND(rc, "ErrorCode");
5a975e82d70f SF # 669553, fix memory (ref) leaks
Neal Norwitz <nnorwitz@gmail.com>
parents: 26109
diff changeset
1489 APPEND(rc, "ErrorLineNumber");
5a975e82d70f SF # 669553, fix memory (ref) leaks
Neal Norwitz <nnorwitz@gmail.com>
parents: 26109
diff changeset
1490 APPEND(rc, "ErrorColumnNumber");
5a975e82d70f SF # 669553, fix memory (ref) leaks
Neal Norwitz <nnorwitz@gmail.com>
parents: 26109
diff changeset
1491 APPEND(rc, "ErrorByteIndex");
33279
b25cb2045dac Patch #1014930. Expose current parse location to XMLParser.
Dave Cole <djc@object-craft.com.au>
parents: 33113
diff changeset
1492 APPEND(rc, "CurrentLineNumber");
b25cb2045dac Patch #1014930. Expose current parse location to XMLParser.
Dave Cole <djc@object-craft.com.au>
parents: 33113
diff changeset
1493 APPEND(rc, "CurrentColumnNumber");
b25cb2045dac Patch #1014930. Expose current parse location to XMLParser.
Dave Cole <djc@object-craft.com.au>
parents: 33113
diff changeset
1494 APPEND(rc, "CurrentByteIndex");
27301
5a975e82d70f SF # 669553, fix memory (ref) leaks
Neal Norwitz <nnorwitz@gmail.com>
parents: 26109
diff changeset
1495 APPEND(rc, "buffer_size");
5a975e82d70f SF # 669553, fix memory (ref) leaks
Neal Norwitz <nnorwitz@gmail.com>
parents: 26109
diff changeset
1496 APPEND(rc, "buffer_text");
5a975e82d70f SF # 669553, fix memory (ref) leaks
Neal Norwitz <nnorwitz@gmail.com>
parents: 26109
diff changeset
1497 APPEND(rc, "buffer_used");
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1498 APPEND(rc, "namespace_prefixes");
27301
5a975e82d70f SF # 669553, fix memory (ref) leaks
Neal Norwitz <nnorwitz@gmail.com>
parents: 26109
diff changeset
1499 APPEND(rc, "ordered_attributes");
5a975e82d70f SF # 669553, fix memory (ref) leaks
Neal Norwitz <nnorwitz@gmail.com>
parents: 26109
diff changeset
1500 APPEND(rc, "returns_unicode");
5a975e82d70f SF # 669553, fix memory (ref) leaks
Neal Norwitz <nnorwitz@gmail.com>
parents: 26109
diff changeset
1501 APPEND(rc, "specified_attributes");
5a975e82d70f SF # 669553, fix memory (ref) leaks
Neal Norwitz <nnorwitz@gmail.com>
parents: 26109
diff changeset
1502 APPEND(rc, "intern");
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1503
27301
5a975e82d70f SF # 669553, fix memory (ref) leaks
Neal Norwitz <nnorwitz@gmail.com>
parents: 26109
diff changeset
1504 #undef APPEND
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1505 return rc;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1506 }
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1507 return Py_FindMethod(xmlparse_methods, (PyObject *)self, name);
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1508 }
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1509
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1510 static int
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1511 sethandler(xmlparseobject *self, const char *name, PyObject* v)
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1512 {
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1513 int handlernum = handlername2int(name);
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1514 if (handlernum >= 0) {
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1515 xmlhandler c_handler = NULL;
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1516 PyObject *temp = self->handlers[handlernum];
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1517
39009
500ae952150b - back out Expat change; the final fix to Expat will be different
Fred Drake <fdrake@acm.org>
parents: 38489
diff changeset
1518 if (v == Py_None) {
500ae952150b - back out Expat change; the final fix to Expat will be different
Fred Drake <fdrake@acm.org>
parents: 38489
diff changeset
1519 /* If this is the character data handler, and a character
500ae952150b - back out Expat change; the final fix to Expat will be different
Fred Drake <fdrake@acm.org>
parents: 38489
diff changeset
1520 data handler is already active, we need to be more
500ae952150b - back out Expat change; the final fix to Expat will be different
Fred Drake <fdrake@acm.org>
parents: 38489
diff changeset
1521 careful. What we can safely do is replace the existing
500ae952150b - back out Expat change; the final fix to Expat will be different
Fred Drake <fdrake@acm.org>
parents: 38489
diff changeset
1522 character data handler callback function with a no-op
500ae952150b - back out Expat change; the final fix to Expat will be different
Fred Drake <fdrake@acm.org>
parents: 38489
diff changeset
1523 function that will refuse to call Python. The downside
500ae952150b - back out Expat change; the final fix to Expat will be different
Fred Drake <fdrake@acm.org>
parents: 38489
diff changeset
1524 is that this doesn't completely remove the character
500ae952150b - back out Expat change; the final fix to Expat will be different
Fred Drake <fdrake@acm.org>
parents: 38489
diff changeset
1525 data handler from the C layer if there's any callback
500ae952150b - back out Expat change; the final fix to Expat will be different
Fred Drake <fdrake@acm.org>
parents: 38489
diff changeset
1526 active, so Expat does a little more work than it
500ae952150b - back out Expat change; the final fix to Expat will be different
Fred Drake <fdrake@acm.org>
parents: 38489
diff changeset
1527 otherwise would, but that's really an odd case. A more
500ae952150b - back out Expat change; the final fix to Expat will be different
Fred Drake <fdrake@acm.org>
parents: 38489
diff changeset
1528 elaborate system of handlers and state could remove the
500ae952150b - back out Expat change; the final fix to Expat will be different
Fred Drake <fdrake@acm.org>
parents: 38489
diff changeset
1529 C handler more effectively. */
500ae952150b - back out Expat change; the final fix to Expat will be different
Fred Drake <fdrake@acm.org>
parents: 38489
diff changeset
1530 if (handlernum == CharacterData && self->in_callback)
500ae952150b - back out Expat change; the final fix to Expat will be different
Fred Drake <fdrake@acm.org>
parents: 38489
diff changeset
1531 c_handler = noop_character_data_handler;
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1532 v = NULL;
39009
500ae952150b - back out Expat change; the final fix to Expat will be different
Fred Drake <fdrake@acm.org>
parents: 38489
diff changeset
1533 }
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1534 else if (v != NULL) {
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1535 Py_INCREF(v);
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1536 c_handler = handler_info[handlernum].handler;
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1537 }
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1538 self->handlers[handlernum] = v;
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1539 Py_XDECREF(temp);
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1540 handler_info[handlernum].setter(self->itself, c_handler);
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1541 return 1;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1542 }
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1543 return 0;
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1544 }
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1545
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1546 static int
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1547 xmlparse_setattr(xmlparseobject *self, char *name, PyObject *v)
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1548 {
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1549 /* Set attribute 'name' to value 'v'. v==NULL means delete */
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1550 if (v == NULL) {
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1551 PyErr_SetString(PyExc_RuntimeError, "Cannot delete attribute");
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1552 return -1;
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1553 }
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1554 if (strcmp(name, "buffer_text") == 0) {
78603
ba1c48f8b571 Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents: 75681
diff changeset
1555 int b = PyObject_IsTrue(v);
ba1c48f8b571 Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents: 75681
diff changeset
1556 if (b < 0)
ba1c48f8b571 Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents: 75681
diff changeset
1557 return -1;
ba1c48f8b571 Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents: 75681
diff changeset
1558 if (b) {
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1559 if (self->buffer == NULL) {
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1560 self->buffer = malloc(self->buffer_size);
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1561 if (self->buffer == NULL) {
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1562 PyErr_NoMemory();
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1563 return -1;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1564 }
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1565 self->buffer_used = 0;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1566 }
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1567 }
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1568 else if (self->buffer != NULL) {
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1569 if (flush_character_buffer(self) < 0)
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1570 return -1;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1571 free(self->buffer);
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1572 self->buffer = NULL;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1573 }
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1574 return 0;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1575 }
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1576 if (strcmp(name, "namespace_prefixes") == 0) {
78603
ba1c48f8b571 Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents: 75681
diff changeset
1577 int b = PyObject_IsTrue(v);
ba1c48f8b571 Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents: 75681
diff changeset
1578 if (b < 0)
ba1c48f8b571 Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents: 75681
diff changeset
1579 return -1;
ba1c48f8b571 Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents: 75681
diff changeset
1580 self->ns_prefixes = b;
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1581 XML_SetReturnNSTriplet(self->itself, self->ns_prefixes);
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1582 return 0;
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1583 }
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1584 if (strcmp(name, "ordered_attributes") == 0) {
78603
ba1c48f8b571 Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents: 75681
diff changeset
1585 int b = PyObject_IsTrue(v);
ba1c48f8b571 Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents: 75681
diff changeset
1586 if (b < 0)
ba1c48f8b571 Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents: 75681
diff changeset
1587 return -1;
ba1c48f8b571 Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents: 75681
diff changeset
1588 self->ordered_attributes = b;
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1589 return 0;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1590 }
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1591 if (strcmp(name, "returns_unicode") == 0) {
78603
ba1c48f8b571 Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents: 75681
diff changeset
1592 int b = PyObject_IsTrue(v);
ba1c48f8b571 Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents: 75681
diff changeset
1593 if (b < 0)
ba1c48f8b571 Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents: 75681
diff changeset
1594 return -1;
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18854
diff changeset
1595 #ifndef Py_USING_UNICODE
78603
ba1c48f8b571 Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents: 75681
diff changeset
1596 if (b) {
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1597 PyErr_SetString(PyExc_ValueError,
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1598 "Unicode support not available");
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1599 return -1;
78603
ba1c48f8b571 Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents: 75681
diff changeset
1600 }
13025
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
1601 #endif
78603
ba1c48f8b571 Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents: 75681
diff changeset
1602 self->returns_unicode = b;
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1603 return 0;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1604 }
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1605 if (strcmp(name, "specified_attributes") == 0) {
78603
ba1c48f8b571 Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents: 75681
diff changeset
1606 int b = PyObject_IsTrue(v);
ba1c48f8b571 Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents: 75681
diff changeset
1607 if (b < 0)
ba1c48f8b571 Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents: 75681
diff changeset
1608 return -1;
ba1c48f8b571 Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents: 75681
diff changeset
1609 self->specified_attributes = b;
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1610 return 0;
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1611 }
44594
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1612
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1613 if (strcmp(name, "buffer_size") == 0) {
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1614 long new_buffer_size;
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1615 if (!PyInt_Check(v)) {
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1616 PyErr_SetString(PyExc_TypeError, "buffer_size must be an integer");
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1617 return -1;
44594
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1618 }
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1619
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1620 new_buffer_size=PyInt_AS_LONG(v);
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1621 /* trivial case -- no change */
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1622 if (new_buffer_size == self->buffer_size) {
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1623 return 0;
44594
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1624 }
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1625
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1626 if (new_buffer_size <= 0) {
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1627 PyErr_SetString(PyExc_ValueError, "buffer_size must be greater than zero");
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1628 return -1;
44594
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1629 }
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1630
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1631 /* check maximum */
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1632 if (new_buffer_size > INT_MAX) {
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1633 char errmsg[100];
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1634 sprintf(errmsg, "buffer_size must not be greater than %i", INT_MAX);
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1635 PyErr_SetString(PyExc_ValueError, errmsg);
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1636 return -1;
44594
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1637 }
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1638
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1639 if (self->buffer != NULL) {
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1640 /* there is already a buffer */
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1641 if (self->buffer_used != 0) {
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1642 flush_character_buffer(self);
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1643 }
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1644 /* free existing buffer */
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1645 free(self->buffer);
44594
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1646 }
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1647 self->buffer = malloc(new_buffer_size);
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1648 if (self->buffer == NULL) {
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1649 PyErr_NoMemory();
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1650 return -1;
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1651 }
44594
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1652 self->buffer_size = new_buffer_size;
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1653 return 0;
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1654 }
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1655
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1656 if (strcmp(name, "CharacterDataHandler") == 0) {
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1657 /* If we're changing the character data handler, flush all
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1658 * cached data with the old handler. Not sure there's a
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1659 * "right" thing to do, though, but this probably won't
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1660 * happen.
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1661 */
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1662 if (flush_character_buffer(self) < 0)
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1663 return -1;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1664 }
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1665 if (sethandler(self, name, v)) {
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1666 return 0;
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1667 }
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1668 PyErr_SetString(PyExc_AttributeError, name);
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1669 return -1;
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1670 }
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1671
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1672 #ifdef WITH_CYCLE_GC
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1673 static int
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1674 xmlparse_traverse(xmlparseobject *op, visitproc visit, void *arg)
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1675 {
37762
a39cc84ff185 err is no longer used
Neal Norwitz <nnorwitz@gmail.com>
parents: 37756
diff changeset
1676 int i;
37756
7b2e436a4a21 Use Py_VISIT in all tp_traverse methods, instead of traversing manually or
Thomas Wouters <thomas@python.org>
parents: 37748
diff changeset
1677 for (i = 0; handler_info[i].name != NULL; i++)
7b2e436a4a21 Use Py_VISIT in all tp_traverse methods, instead of traversing manually or
Thomas Wouters <thomas@python.org>
parents: 37748
diff changeset
1678 Py_VISIT(op->handlers[i]);
17623
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1679 return 0;
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1680 }
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1681
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1682 static int
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1683 xmlparse_clear(xmlparseobject *op)
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1684 {
20588
aad762503d11 Change clear_handlers argument to indicate whether this is an initialization.
Martin v. Löwis <martin@v.loewis.de>
parents: 20047
diff changeset
1685 clear_handlers(op, 0);
37748
d1547426ab61 Use Py_CLEAR instead of in-place DECREF/XDECREF or custom macros, for
Thomas Wouters <thomas@python.org>
parents: 37067
diff changeset
1686 Py_CLEAR(op->intern);
17623
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1687 return 0;
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1688 }
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1689 #endif
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1690
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22421
diff changeset
1691 PyDoc_STRVAR(Xmlparsetype__doc__, "XML parser");
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1692
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1693 static PyTypeObject Xmlparsetype = {
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1694 PyVarObject_HEAD_INIT(NULL, 0)
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1695 "pyexpat.xmlparser", /*tp_name*/
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1696 sizeof(xmlparseobject) + PyGC_HEAD_SIZE,/*tp_basicsize*/
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1697 0, /*tp_itemsize*/
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1698 /* methods */
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1699 (destructor)xmlparse_dealloc, /*tp_dealloc*/
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1700 (printfunc)0, /*tp_print*/
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1701 (getattrfunc)xmlparse_getattr, /*tp_getattr*/
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1702 (setattrfunc)xmlparse_setattr, /*tp_setattr*/
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1703 (cmpfunc)0, /*tp_compare*/
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1704 (reprfunc)0, /*tp_repr*/
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1705 0, /*tp_as_number*/
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1706 0, /*tp_as_sequence*/
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1707 0, /*tp_as_mapping*/
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1708 (hashfunc)0, /*tp_hash*/
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1709 (ternaryfunc)0, /*tp_call*/
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1710 (reprfunc)0, /*tp_str*/
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1711 0, /* tp_getattro */
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1712 0, /* tp_setattro */
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1713 0, /* tp_as_buffer */
20047
4c5cd3d1cf4b Reactivate participation of expat parsers in GC. Fixes bug #462710.
Martin v. Löwis <martin@v.loewis.de>
parents: 19979
diff changeset
1714 #ifdef Py_TPFLAGS_HAVE_GC
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1715 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
20047
4c5cd3d1cf4b Reactivate participation of expat parsers in GC. Fixes bug #462710.
Martin v. Löwis <martin@v.loewis.de>
parents: 19979
diff changeset
1716 #else
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1717 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_GC, /*tp_flags*/
20047
4c5cd3d1cf4b Reactivate participation of expat parsers in GC. Fixes bug #462710.
Martin v. Löwis <martin@v.loewis.de>
parents: 19979
diff changeset
1718 #endif
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1719 Xmlparsetype__doc__, /* tp_doc - Documentation string */
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1720 #ifdef WITH_CYCLE_GC
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1721 (traverseproc)xmlparse_traverse, /* tp_traverse */
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1722 (inquiry)xmlparse_clear /* tp_clear */
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1723 #else
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1724 0, 0
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1725 #endif
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1726 };
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1727
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1728 /* End of code for xmlparser objects */
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1729 /* -------------------------------------------------------- */
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1730
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22421
diff changeset
1731 PyDoc_STRVAR(pyexpat_ParserCreate__doc__,
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1732 "ParserCreate([encoding[, namespace_separator]]) -> parser\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22421
diff changeset
1733 Return a new XML parser object.");
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1734
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1735 static PyObject *
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1736 pyexpat_ParserCreate(PyObject *notused, PyObject *args, PyObject *kw)
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1737 {
17623
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1738 char *encoding = NULL;
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1739 char *namespace_separator = NULL;
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1740 PyObject *intern = NULL;
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1741 PyObject *result;
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1742 int intern_decref = 0;
36675
dba6494735d0 Revert backwards-incompatible const changes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
1743 static char *kwlist[] = {"encoding", "namespace_separator",
35999
9541369b0dca Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35766
diff changeset
1744 "intern", NULL};
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1745
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1746 if (!PyArg_ParseTupleAndKeywords(args, kw, "|zzO:ParserCreate", kwlist,
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1747 &encoding, &namespace_separator, &intern))
17623
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1748 return NULL;
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1749 if (namespace_separator != NULL
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1750 && strlen(namespace_separator) > 1) {
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1751 PyErr_SetString(PyExc_ValueError,
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1752 "namespace_separator must be at most one"
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1753 " character, omitted, or None");
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1754 return NULL;
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1755 }
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1756 /* Explicitly passing None means no interning is desired.
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1757 Not passing anything means that a new dictionary is used. */
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1758 if (intern == Py_None)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1759 intern = NULL;
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1760 else if (intern == NULL) {
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1761 intern = PyDict_New();
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1762 if (!intern)
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1763 return NULL;
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1764 intern_decref = 1;
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1765 }
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1766 else if (!PyDict_Check(intern)) {
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1767 PyErr_SetString(PyExc_TypeError, "intern must be a dictionary");
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1768 return NULL;
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1769 }
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1770
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1771 result = newxmlparseobject(encoding, namespace_separator, intern);
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1772 if (intern_decref) {
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1773 Py_DECREF(intern);
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1774 }
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1775 return result;
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1776 }
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1777
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22421
diff changeset
1778 PyDoc_STRVAR(pyexpat_ErrorString__doc__,
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1779 "ErrorString(errno) -> string\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22421
diff changeset
1780 Returns string error for given number.");
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1781
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1782 static PyObject *
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1783 pyexpat_ErrorString(PyObject *self, PyObject *args)
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1784 {
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1785 long code = 0;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1786
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1787 if (!PyArg_ParseTuple(args, "l:ErrorString", &code))
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1788 return NULL;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1789 return Py_BuildValue("z", XML_ErrorString((int)code));
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1790 }
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1791
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1792 /* List of methods defined in the module */
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1793
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1794 static struct PyMethodDef pyexpat_methods[] = {
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1795 {"ParserCreate", (PyCFunction)pyexpat_ParserCreate,
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1796 METH_VARARGS|METH_KEYWORDS, pyexpat_ParserCreate__doc__},
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1797 {"ErrorString", (PyCFunction)pyexpat_ErrorString,
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1798 METH_VARARGS, pyexpat_ErrorString__doc__},
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1799
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1800 {NULL, (PyCFunction)NULL, 0, NULL} /* sentinel */
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1801 };
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1802
13025
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
1803 /* Module docstring */
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1804
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22421
diff changeset
1805 PyDoc_STRVAR(pyexpat_module_documentation,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22421
diff changeset
1806 "Python wrapper for Expat parser.");
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1807
17623
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1808 /* Initialization function for the module */
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1809
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1810 #ifndef MODULE_NAME
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1811 #define MODULE_NAME "pyexpat"
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1812 #endif
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1813
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1814 #ifndef MODULE_INITFUNC
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1815 #define MODULE_INITFUNC initpyexpat
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1816 #endif
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1817
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1818 #ifndef PyMODINIT_FUNC
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1819 # ifdef MS_WINDOWS
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1820 # define PyMODINIT_FUNC __declspec(dllexport) void
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1821 # else
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1822 # define PyMODINIT_FUNC void
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1823 # endif
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1824 #endif
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1825
24315
a8df0c0be242 Land Patch [ 566100 ] Rationalize DL_IMPORT and DL_EXPORT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 24283
diff changeset
1826 PyMODINIT_FUNC MODULE_INITFUNC(void); /* avoid compiler warnings */
17623
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1827
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1828 PyMODINIT_FUNC
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1829 MODULE_INITFUNC(void)
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1830 {
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1831 PyObject *m, *d;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
1832 PyObject *errmod_name = PyString_FromString(MODULE_NAME ".errors");
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1833 PyObject *errors_module;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1834 PyObject *modelmod_name;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1835 PyObject *model_module;
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1836 PyObject *sys_modules;
70560
9c1116e582e3 simply use the Python version for pyexpat.__version__ #12221
Benjamin Peterson <benjamin@python.org>
parents: 69244
diff changeset
1837 PyObject *version;
36018
c253e993df8a renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents: 36017
diff changeset
1838 static struct PyExpat_CAPI capi;
c253e993df8a renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents: 36017
diff changeset
1839 PyObject* capi_object;
13025
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
1840
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1841 if (errmod_name == NULL)
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1842 return;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
1843 modelmod_name = PyString_FromString(MODULE_NAME ".model");
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1844 if (modelmod_name == NULL)
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1845 return;
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1846
44350
26384b8180c7 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents: 42333
diff changeset
1847 Py_TYPE(&Xmlparsetype) = &PyType_Type;
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1848
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1849 /* Create the module and add the functions */
17623
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1850 m = Py_InitModule3(MODULE_NAME, pyexpat_methods,
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1851 pyexpat_module_documentation);
36324
1af7f719ed28 Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36090
diff changeset
1852 if (m == NULL)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1853 return;
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1854
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1855 /* Add some symbolic constants to the module */
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
1856 if (ErrorObject == NULL) {
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
1857 ErrorObject = PyErr_NewException("xml.parsers.expat.ExpatError",
14788
179e098238e8 Change the name of the exception from "pyexpat.error" to
Fred Drake <fdrake@acm.org>
parents: 14755
diff changeset
1858 NULL, NULL);
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
1859 if (ErrorObject == NULL)
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
1860 return;
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
1861 }
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
1862 Py_INCREF(ErrorObject);
14788
179e098238e8 Change the name of the exception from "pyexpat.error" to
Fred Drake <fdrake@acm.org>
parents: 14755
diff changeset
1863 PyModule_AddObject(m, "error", ErrorObject);
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
1864 Py_INCREF(ErrorObject);
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
1865 PyModule_AddObject(m, "ExpatError", ErrorObject);
15358
ab3438cf1f3e ParserCreate(): Added test that the namespace_separator value, if given,
Fred Drake <fdrake@acm.org>
parents: 14932
diff changeset
1866 Py_INCREF(&Xmlparsetype);
ab3438cf1f3e ParserCreate(): Added test that the namespace_separator value, if given,
Fred Drake <fdrake@acm.org>
parents: 14932
diff changeset
1867 PyModule_AddObject(m, "XMLParserType", (PyObject *) &Xmlparsetype);
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1868
70560
9c1116e582e3 simply use the Python version for pyexpat.__version__ #12221
Benjamin Peterson <benjamin@python.org>
parents: 69244
diff changeset
1869 version = PyString_FromString(PY_VERSION);
9c1116e582e3 simply use the Python version for pyexpat.__version__ #12221
Benjamin Peterson <benjamin@python.org>
parents: 69244
diff changeset
1870 if (!version)
9c1116e582e3 simply use the Python version for pyexpat.__version__ #12221
Benjamin Peterson <benjamin@python.org>
parents: 69244
diff changeset
1871 return;
9c1116e582e3 simply use the Python version for pyexpat.__version__ #12221
Benjamin Peterson <benjamin@python.org>
parents: 69244
diff changeset
1872 PyModule_AddObject(m, "__version__", version);
15642
19c8a2d3807d When using the latest & greatest version of Expat (currently in the Expat
Fred Drake <fdrake@acm.org>
parents: 15600
diff changeset
1873 PyModule_AddStringConstant(m, "EXPAT_VERSION",
19c8a2d3807d When using the latest & greatest version of Expat (currently in the Expat
Fred Drake <fdrake@acm.org>
parents: 15600
diff changeset
1874 (char *) XML_ExpatVersion());
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1875 {
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1876 XML_Expat_Version info = XML_ExpatVersionInfo();
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1877 PyModule_AddObject(m, "version_info",
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1878 Py_BuildValue("(iii)", info.major,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1879 info.minor, info.micro));
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1880 }
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18854
diff changeset
1881 #ifdef Py_USING_UNICODE
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1882 init_template_buffer();
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1883 #endif
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1884 /* XXX When Expat supports some way of figuring out how it was
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1885 compiled, this should check and set native_encoding
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1886 appropriately.
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1887 */
14788
179e098238e8 Change the name of the exception from "pyexpat.error" to
Fred Drake <fdrake@acm.org>
parents: 14755
diff changeset
1888 PyModule_AddStringConstant(m, "native_encoding", "UTF-8");
14168
91deadfdae36 Remove the Py_FatalError() from initpyexpat(); the Guido has decreed
Fred Drake <fdrake@acm.org>
parents: 13654
diff changeset
1889
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1890 sys_modules = PySys_GetObject("modules");
14788
179e098238e8 Change the name of the exception from "pyexpat.error" to
Fred Drake <fdrake@acm.org>
parents: 14755
diff changeset
1891 d = PyModule_GetDict(m);
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1892 errors_module = PyDict_GetItem(d, errmod_name);
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1893 if (errors_module == NULL) {
17623
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1894 errors_module = PyModule_New(MODULE_NAME ".errors");
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1895 if (errors_module != NULL) {
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1896 PyDict_SetItem(sys_modules, errmod_name, errors_module);
14788
179e098238e8 Change the name of the exception from "pyexpat.error" to
Fred Drake <fdrake@acm.org>
parents: 14755
diff changeset
1897 /* gives away the reference to errors_module */
179e098238e8 Change the name of the exception from "pyexpat.error" to
Fred Drake <fdrake@acm.org>
parents: 14755
diff changeset
1898 PyModule_AddObject(m, "errors", errors_module);
14168
91deadfdae36 Remove the Py_FatalError() from initpyexpat(); the Guido has decreed
Fred Drake <fdrake@acm.org>
parents: 13654
diff changeset
1899 }
91deadfdae36 Remove the Py_FatalError() from initpyexpat(); the Guido has decreed
Fred Drake <fdrake@acm.org>
parents: 13654
diff changeset
1900 }
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1901 Py_DECREF(errmod_name);
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1902 model_module = PyDict_GetItem(d, modelmod_name);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1903 if (model_module == NULL) {
17623
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1904 model_module = PyModule_New(MODULE_NAME ".model");
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1905 if (model_module != NULL) {
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1906 PyDict_SetItem(sys_modules, modelmod_name, model_module);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1907 /* gives away the reference to model_module */
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1908 PyModule_AddObject(m, "model", model_module);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1909 }
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1910 }
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1911 Py_DECREF(modelmod_name);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1912 if (errors_module == NULL || model_module == NULL)
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1913 /* Don't core dump later! */
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1914 return;
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
1915
27322
88bf10313584 Conditionalize features not found in PyXML 1.95.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 27321
diff changeset
1916 #if XML_COMBINED_VERSION > 19505
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1917 {
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1918 const XML_Feature *features = XML_GetFeatureList();
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1919 PyObject *list = PyList_New(0);
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1920 if (list == NULL)
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1921 /* just ignore it */
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1922 PyErr_Clear();
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1923 else {
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1924 int i = 0;
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1925 for (; features[i].feature != XML_FEATURE_END; ++i) {
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1926 int ok;
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1927 PyObject *item = Py_BuildValue("si", features[i].name,
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1928 features[i].value);
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1929 if (item == NULL) {
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1930 Py_DECREF(list);
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1931 list = NULL;
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1932 break;
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1933 }
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1934 ok = PyList_Append(list, item);
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1935 Py_DECREF(item);
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1936 if (ok < 0) {
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1937 PyErr_Clear();
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1938 break;
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1939 }
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1940 }
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1941 if (list != NULL)
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1942 PyModule_AddObject(m, "features", list);
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1943 }
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1944 }
27322
88bf10313584 Conditionalize features not found in PyXML 1.95.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 27321
diff changeset
1945 #endif
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1946
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1947 #define MYCONST(name) \
14788
179e098238e8 Change the name of the exception from "pyexpat.error" to
Fred Drake <fdrake@acm.org>
parents: 14755
diff changeset
1948 PyModule_AddStringConstant(errors_module, #name, \
179e098238e8 Change the name of the exception from "pyexpat.error" to
Fred Drake <fdrake@acm.org>
parents: 14755
diff changeset
1949 (char*)XML_ErrorString(name))
13344
c3029f276047 pyexpat.errors is a *strange* module!
Fred Drake <fdrake@acm.org>
parents: 13340
diff changeset
1950
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1951 MYCONST(XML_ERROR_NO_MEMORY);
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1952 MYCONST(XML_ERROR_SYNTAX);
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1953 MYCONST(XML_ERROR_NO_ELEMENTS);
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1954 MYCONST(XML_ERROR_INVALID_TOKEN);
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1955 MYCONST(XML_ERROR_UNCLOSED_TOKEN);
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1956 MYCONST(XML_ERROR_PARTIAL_CHAR);
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1957 MYCONST(XML_ERROR_TAG_MISMATCH);
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1958 MYCONST(XML_ERROR_DUPLICATE_ATTRIBUTE);
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1959 MYCONST(XML_ERROR_JUNK_AFTER_DOC_ELEMENT);
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1960 MYCONST(XML_ERROR_PARAM_ENTITY_REF);
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1961 MYCONST(XML_ERROR_UNDEFINED_ENTITY);
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1962 MYCONST(XML_ERROR_RECURSIVE_ENTITY_REF);
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1963 MYCONST(XML_ERROR_ASYNC_ENTITY);
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1964 MYCONST(XML_ERROR_BAD_CHAR_REF);
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1965 MYCONST(XML_ERROR_BINARY_ENTITY_REF);
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1966 MYCONST(XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF);
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1967 MYCONST(XML_ERROR_MISPLACED_XML_PI);
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1968 MYCONST(XML_ERROR_UNKNOWN_ENCODING);
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1969 MYCONST(XML_ERROR_INCORRECT_ENCODING);
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1970 MYCONST(XML_ERROR_UNCLOSED_CDATA_SECTION);
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1971 MYCONST(XML_ERROR_EXTERNAL_ENTITY_HANDLING);
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1972 MYCONST(XML_ERROR_NOT_STANDALONE);
32965
ea338baab859 add constants for many error values added over the past couple of
Fred Drake <fdrake@acm.org>
parents: 32923
diff changeset
1973 MYCONST(XML_ERROR_UNEXPECTED_STATE);
ea338baab859 add constants for many error values added over the past couple of
Fred Drake <fdrake@acm.org>
parents: 32923
diff changeset
1974 MYCONST(XML_ERROR_ENTITY_DECLARED_IN_PE);
ea338baab859 add constants for many error values added over the past couple of
Fred Drake <fdrake@acm.org>
parents: 32923
diff changeset
1975 MYCONST(XML_ERROR_FEATURE_REQUIRES_XML_DTD);
ea338baab859 add constants for many error values added over the past couple of
Fred Drake <fdrake@acm.org>
parents: 32923
diff changeset
1976 MYCONST(XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING);
ea338baab859 add constants for many error values added over the past couple of
Fred Drake <fdrake@acm.org>
parents: 32923
diff changeset
1977 /* Added in Expat 1.95.7. */
ea338baab859 add constants for many error values added over the past couple of
Fred Drake <fdrake@acm.org>
parents: 32923
diff changeset
1978 MYCONST(XML_ERROR_UNBOUND_PREFIX);
ea338baab859 add constants for many error values added over the past couple of
Fred Drake <fdrake@acm.org>
parents: 32923
diff changeset
1979 /* Added in Expat 1.95.8. */
ea338baab859 add constants for many error values added over the past couple of
Fred Drake <fdrake@acm.org>
parents: 32923
diff changeset
1980 MYCONST(XML_ERROR_UNDECLARING_PREFIX);
ea338baab859 add constants for many error values added over the past couple of
Fred Drake <fdrake@acm.org>
parents: 32923
diff changeset
1981 MYCONST(XML_ERROR_INCOMPLETE_PE);
ea338baab859 add constants for many error values added over the past couple of
Fred Drake <fdrake@acm.org>
parents: 32923
diff changeset
1982 MYCONST(XML_ERROR_XML_DECL);
ea338baab859 add constants for many error values added over the past couple of
Fred Drake <fdrake@acm.org>
parents: 32923
diff changeset
1983 MYCONST(XML_ERROR_TEXT_DECL);
ea338baab859 add constants for many error values added over the past couple of
Fred Drake <fdrake@acm.org>
parents: 32923
diff changeset
1984 MYCONST(XML_ERROR_PUBLICID);
ea338baab859 add constants for many error values added over the past couple of
Fred Drake <fdrake@acm.org>
parents: 32923
diff changeset
1985 MYCONST(XML_ERROR_SUSPENDED);
ea338baab859 add constants for many error values added over the past couple of
Fred Drake <fdrake@acm.org>
parents: 32923
diff changeset
1986 MYCONST(XML_ERROR_NOT_SUSPENDED);
ea338baab859 add constants for many error values added over the past couple of
Fred Drake <fdrake@acm.org>
parents: 32923
diff changeset
1987 MYCONST(XML_ERROR_ABORTED);
ea338baab859 add constants for many error values added over the past couple of
Fred Drake <fdrake@acm.org>
parents: 32923
diff changeset
1988 MYCONST(XML_ERROR_FINISHED);
ea338baab859 add constants for many error values added over the past couple of
Fred Drake <fdrake@acm.org>
parents: 32923
diff changeset
1989 MYCONST(XML_ERROR_SUSPEND_PE);
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1990
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1991 PyModule_AddStringConstant(errors_module, "__doc__",
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1992 "Constants used to describe error conditions.");
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1993
14788
179e098238e8 Change the name of the exception from "pyexpat.error" to
Fred Drake <fdrake@acm.org>
parents: 14755
diff changeset
1994 #undef MYCONST
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1995
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1996 #define MYCONST(c) PyModule_AddIntConstant(m, #c, c)
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1997 MYCONST(XML_PARAM_ENTITY_PARSING_NEVER);
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1998 MYCONST(XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE);
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1999 MYCONST(XML_PARAM_ENTITY_PARSING_ALWAYS);
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2000 #undef MYCONST
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
2001
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2002 #define MYCONST(c) PyModule_AddIntConstant(model_module, #c, c)
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2003 PyModule_AddStringConstant(model_module, "__doc__",
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2004 "Constants used to interpret content model information.");
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2005
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2006 MYCONST(XML_CTYPE_EMPTY);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2007 MYCONST(XML_CTYPE_ANY);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2008 MYCONST(XML_CTYPE_MIXED);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2009 MYCONST(XML_CTYPE_NAME);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2010 MYCONST(XML_CTYPE_CHOICE);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2011 MYCONST(XML_CTYPE_SEQ);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2012
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2013 MYCONST(XML_CQUANT_NONE);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2014 MYCONST(XML_CQUANT_OPT);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2015 MYCONST(XML_CQUANT_REP);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2016 MYCONST(XML_CQUANT_PLUS);
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
2017 #undef MYCONST
36017
ed347c436d58 added cobject-based expat dispatch mechanism to pyexpat
Fredrik Lundh <fredrik@pythonware.com>
parents: 35999
diff changeset
2018
ed347c436d58 added cobject-based expat dispatch mechanism to pyexpat
Fredrik Lundh <fredrik@pythonware.com>
parents: 35999
diff changeset
2019 /* initialize pyexpat dispatch table */
36018
c253e993df8a renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents: 36017
diff changeset
2020 capi.size = sizeof(capi);
36019
68817315b74c moved magic into structure (mainly to simplify the client code)
Fredrik Lundh <fredrik@pythonware.com>
parents: 36018
diff changeset
2021 capi.magic = PyExpat_CAPI_MAGIC;
36018
c253e993df8a renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents: 36017
diff changeset
2022 capi.MAJOR_VERSION = XML_MAJOR_VERSION;
c253e993df8a renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents: 36017
diff changeset
2023 capi.MINOR_VERSION = XML_MINOR_VERSION;
c253e993df8a renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents: 36017
diff changeset
2024 capi.MICRO_VERSION = XML_MICRO_VERSION;
c253e993df8a renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents: 36017
diff changeset
2025 capi.ErrorString = XML_ErrorString;
36019
68817315b74c moved magic into structure (mainly to simplify the client code)
Fredrik Lundh <fredrik@pythonware.com>
parents: 36018
diff changeset
2026 capi.GetErrorCode = XML_GetErrorCode;
68817315b74c moved magic into structure (mainly to simplify the client code)
Fredrik Lundh <fredrik@pythonware.com>
parents: 36018
diff changeset
2027 capi.GetErrorColumnNumber = XML_GetErrorColumnNumber;
68817315b74c moved magic into structure (mainly to simplify the client code)
Fredrik Lundh <fredrik@pythonware.com>
parents: 36018
diff changeset
2028 capi.GetErrorLineNumber = XML_GetErrorLineNumber;
36018
c253e993df8a renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents: 36017
diff changeset
2029 capi.Parse = XML_Parse;
c253e993df8a renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents: 36017
diff changeset
2030 capi.ParserCreate_MM = XML_ParserCreate_MM;
c253e993df8a renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents: 36017
diff changeset
2031 capi.ParserFree = XML_ParserFree;
c253e993df8a renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents: 36017
diff changeset
2032 capi.SetCharacterDataHandler = XML_SetCharacterDataHandler;
c253e993df8a renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents: 36017
diff changeset
2033 capi.SetCommentHandler = XML_SetCommentHandler;
c253e993df8a renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents: 36017
diff changeset
2034 capi.SetDefaultHandlerExpand = XML_SetDefaultHandlerExpand;
c253e993df8a renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents: 36017
diff changeset
2035 capi.SetElementHandler = XML_SetElementHandler;
c253e993df8a renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents: 36017
diff changeset
2036 capi.SetNamespaceDeclHandler = XML_SetNamespaceDeclHandler;
c253e993df8a renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents: 36017
diff changeset
2037 capi.SetProcessingInstructionHandler = XML_SetProcessingInstructionHandler;
c253e993df8a renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents: 36017
diff changeset
2038 capi.SetUnknownEncodingHandler = XML_SetUnknownEncodingHandler;
c253e993df8a renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents: 36017
diff changeset
2039 capi.SetUserData = XML_SetUserData;
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
2040
59998
d11fbc796499 Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents: 53930
diff changeset
2041 /* export using capsule */
d11fbc796499 Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents: 53930
diff changeset
2042 capi_object = PyCapsule_New(&capi, PyExpat_CAPSULE_NAME, NULL);
36018
c253e993df8a renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents: 36017
diff changeset
2043 if (capi_object)
c253e993df8a renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents: 36017
diff changeset
2044 PyModule_AddObject(m, "expat_CAPI", capi_object);
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
2045 }
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
2046
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
2047 static void
20588
aad762503d11 Change clear_handlers argument to indicate whether this is an initialization.
Martin v. Löwis <martin@v.loewis.de>
parents: 20047
diff changeset
2048 clear_handlers(xmlparseobject *self, int initial)
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2049 {
17623
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
2050 int i = 0;
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
2051 PyObject *temp;
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
2052
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
2053 for (; handler_info[i].name != NULL; i++) {
20588
aad762503d11 Change clear_handlers argument to indicate whether this is an initialization.
Martin v. Löwis <martin@v.loewis.de>
parents: 20047
diff changeset
2054 if (initial)
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
2055 self->handlers[i] = NULL;
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
2056 else {
17623
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
2057 temp = self->handlers[i];
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
2058 self->handlers[i] = NULL;
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
2059 Py_XDECREF(temp);
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 47527
diff changeset
2060 handler_info[i].setter(self->itself, NULL);
17623
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
2061 }
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
2062 }
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
2063 }
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
2064
24283
c0a67a1cab09 Removed more stray instances of statichere, but left _sre.c alone.
Tim Peters <tim.peters@gmail.com>
parents: 24280
diff changeset
2065 static struct HandlerInfo handler_info[] = {
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
2066 {"StartElementHandler",
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
2067 (xmlhandlersetter)XML_SetStartElementHandler,
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2068 (xmlhandler)my_StartElementHandler},
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
2069 {"EndElementHandler",
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
2070 (xmlhandlersetter)XML_SetEndElementHandler,
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2071 (xmlhandler)my_EndElementHandler},
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
2072 {"ProcessingInstructionHandler",
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2073 (xmlhandlersetter)XML_SetProcessingInstructionHandler,
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2074 (xmlhandler)my_ProcessingInstructionHandler},
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
2075 {"CharacterDataHandler",
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2076 (xmlhandlersetter)XML_SetCharacterDataHandler,
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2077 (xmlhandler)my_CharacterDataHandler},
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
2078 {"UnparsedEntityDeclHandler",
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2079 (xmlhandlersetter)XML_SetUnparsedEntityDeclHandler,
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
2080 (xmlhandler)my_UnparsedEntityDeclHandler},
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
2081 {"NotationDeclHandler",
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2082 (xmlhandlersetter)XML_SetNotationDeclHandler,
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
2083 (xmlhandler)my_NotationDeclHandler},
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
2084 {"StartNamespaceDeclHandler",
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
2085 (xmlhandlersetter)XML_SetStartNamespaceDeclHandler,
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
2086 (xmlhandler)my_StartNamespaceDeclHandler},
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
2087 {"EndNamespaceDeclHandler",
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
2088 (xmlhandlersetter)XML_SetEndNamespaceDeclHandler,
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
2089 (xmlhandler)my_EndNamespaceDeclHandler},
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2090 {"CommentHandler",
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2091 (xmlhandlersetter)XML_SetCommentHandler,
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2092 (xmlhandler)my_CommentHandler},
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2093 {"StartCdataSectionHandler",
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
2094 (xmlhandlersetter)XML_SetStartCdataSectionHandler,
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2095 (xmlhandler)my_StartCdataSectionHandler},
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2096 {"EndCdataSectionHandler",
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
2097 (xmlhandlersetter)XML_SetEndCdataSectionHandler,
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2098 (xmlhandler)my_EndCdataSectionHandler},
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2099 {"DefaultHandler",
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2100 (xmlhandlersetter)XML_SetDefaultHandler,
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2101 (xmlhandler)my_DefaultHandler},
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2102 {"DefaultHandlerExpand",
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2103 (xmlhandlersetter)XML_SetDefaultHandlerExpand,
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2104 (xmlhandler)my_DefaultHandlerExpandHandler},
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2105 {"NotStandaloneHandler",
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2106 (xmlhandlersetter)XML_SetNotStandaloneHandler,
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2107 (xmlhandler)my_NotStandaloneHandler},
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2108 {"ExternalEntityRefHandler",
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2109 (xmlhandlersetter)XML_SetExternalEntityRefHandler,
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
2110 (xmlhandler)my_ExternalEntityRefHandler},
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
2111 {"StartDoctypeDeclHandler",
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
2112 (xmlhandlersetter)XML_SetStartDoctypeDeclHandler,
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
2113 (xmlhandler)my_StartDoctypeDeclHandler},
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
2114 {"EndDoctypeDeclHandler",
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
2115 (xmlhandlersetter)XML_SetEndDoctypeDeclHandler,
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
2116 (xmlhandler)my_EndDoctypeDeclHandler},
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2117 {"EntityDeclHandler",
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2118 (xmlhandlersetter)XML_SetEntityDeclHandler,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2119 (xmlhandler)my_EntityDeclHandler},
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2120 {"XmlDeclHandler",
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2121 (xmlhandlersetter)XML_SetXmlDeclHandler,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2122 (xmlhandler)my_XmlDeclHandler},
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2123 {"ElementDeclHandler",
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2124 (xmlhandlersetter)XML_SetElementDeclHandler,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2125 (xmlhandler)my_ElementDeclHandler},
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2126 {"AttlistDeclHandler",
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2127 (xmlhandlersetter)XML_SetAttlistDeclHandler,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2128 (xmlhandler)my_AttlistDeclHandler},
27322
88bf10313584 Conditionalize features not found in PyXML 1.95.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 27321
diff changeset
2129 #if XML_COMBINED_VERSION >= 19504
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
2130 {"SkippedEntityHandler",
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
2131 (xmlhandlersetter)XML_SetSkippedEntityHandler,
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
2132 (xmlhandler)my_SkippedEntityHandler},
27322
88bf10313584 Conditionalize features not found in PyXML 1.95.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 27321
diff changeset
2133 #endif
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
2134
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2135 {NULL, NULL, NULL} /* sentinel */
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
2136 };