annotate Modules/pyexpat.c @ 58925:eecf1bef052d 2.6

Merged revisions 78207 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line #7930: fix stripid ........
author Ezio Melotti <ezio.melotti@gmail.com>
date Tue, 16 Feb 2010 23:29:44 +0000
parents 52294af4b663
children e38335d4df91 a171048daf76
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
500ae952150b - back out Expat change; the final fix to Expat will be different
Fred Drake <fdrake@acm.org>
parents: 38489
diff changeset
248 noop_character_data_handler(void *userData, const XML_Char *data, int len)
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 PyObject *code = NULL;
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
265 PyObject *name = NULL;
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
266 PyObject *nulltuple = NULL;
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
267 PyObject *filename = NULL;
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
268
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
269 if (handler_info[slot].tb_code == NULL) {
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
270 code = PyString_FromString("");
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
271 if (code == NULL)
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
272 goto failed;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
273 name = PyString_FromString(func_name);
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
274 if (name == NULL)
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
275 goto failed;
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
276 nulltuple = PyTuple_New(0);
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
277 if (nulltuple == NULL)
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
278 goto failed;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
279 filename = PyString_FromString(__FILE__);
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
280 handler_info[slot].tb_code =
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
281 PyCode_New(0, /* argcount */
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
282 0, /* nlocals */
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
283 0, /* stacksize */
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
284 0, /* flags */
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
285 code, /* code */
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
286 nulltuple, /* consts */
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
287 nulltuple, /* names */
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
288 nulltuple, /* varnames */
16463
2ca8783ce8a3 Support older PYTHON_API_VERSIONs for backwards compatibility.
Martin v. Löwis <martin@v.loewis.de>
parents: 16267
diff changeset
289 #if PYTHON_API_VERSION >= 1010
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
290 nulltuple, /* freevars */
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
291 nulltuple, /* cellvars */
16463
2ca8783ce8a3 Support older PYTHON_API_VERSIONs for backwards compatibility.
Martin v. Löwis <martin@v.loewis.de>
parents: 16267
diff changeset
292 #endif
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
293 filename, /* filename */
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
294 name, /* name */
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
295 lineno, /* firstlineno */
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
296 code /* lnotab */
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
297 );
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
298 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
299 goto failed;
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
300 Py_DECREF(code);
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
301 Py_DECREF(nulltuple);
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
302 Py_DECREF(filename);
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
303 Py_DECREF(name);
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
304 }
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
305 return handler_info[slot].tb_code;
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
306 failed:
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
307 Py_XDECREF(code);
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
308 Py_XDECREF(name);
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
309 return NULL;
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
310 }
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
311
29605
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
312 #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
313 static int
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
314 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
315 {
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
316 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
317 if (!tstate->use_tracing || tstate->tracing)
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
318 return 0;
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
319 if (tstate->c_profilefunc != NULL) {
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
320 tstate->tracing++;
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
321 result = tstate->c_profilefunc(tstate->c_profileobj,
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
322 f, code , val);
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
323 tstate->use_tracing = ((tstate->c_tracefunc != NULL)
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
324 || (tstate->c_profilefunc != NULL));
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
325 tstate->tracing--;
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
326 if (result)
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
327 return result;
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
328 }
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
329 if (tstate->c_tracefunc != NULL) {
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
330 tstate->tracing++;
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
331 result = tstate->c_tracefunc(tstate->c_traceobj,
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
332 f, code , val);
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
333 tstate->use_tracing = ((tstate->c_tracefunc != NULL)
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
334 || (tstate->c_profilefunc != NULL));
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
335 tstate->tracing--;
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
336 }
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
337 return result;
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
338 }
29605
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
339
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
340 static int
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
341 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
342 {
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
343 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
344 int err;
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
345
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
346 if (tstate->c_tracefunc == NULL)
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
347 return 0;
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
348
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
349 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
350 if (value == NULL) {
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
351 value = Py_None;
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
352 Py_INCREF(value);
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
353 }
33752
ddc2d6e547c1 Synchronize with PyXML 1.79:
Martin v. Löwis <martin@v.loewis.de>
parents: 33279
diff changeset
354 #if PY_VERSION_HEX < 0x02040000
ddc2d6e547c1 Synchronize with PyXML 1.79:
Martin v. Löwis <martin@v.loewis.de>
parents: 33279
diff changeset
355 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
356 #else
30683
3b59fa5d25b1 Simplify and speedup uses of Py_BuildValue():
Raymond Hettinger <python@rcn.com>
parents: 29957
diff changeset
357 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
358 #endif
29605
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
359 if (arg == NULL) {
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
360 PyErr_Restore(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
361 return 0;
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
362 }
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
363 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
364 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
365 if (err == 0)
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
366 PyErr_Restore(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
367 else {
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
368 Py_XDECREF(type);
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
369 Py_XDECREF(value);
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
370 Py_XDECREF(traceback);
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
371 }
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
372 return err;
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
373 }
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
374 #endif
24533
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
375
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
376 static PyObject*
33113
28e877ff74cf make exception propogation more efficient; this avoids having Expat parse
Fred Drake <fdrake@acm.org>
parents: 32965
diff changeset
377 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
378 xmlparseobject *self)
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
379 {
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
380 PyThreadState *tstate = PyThreadState_GET();
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
381 PyFrameObject *f;
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
382 PyObject *res;
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
383
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
384 if (c == NULL)
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
385 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
386
29605
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
387 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
388 if (f == NULL)
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
389 return NULL;
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
390 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
391 #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
392 if (trace_frame(tstate, f, PyTrace_CALL, Py_None) < 0) {
24533
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
393 return NULL;
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
394 }
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
395 #endif
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
396 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
397 if (res == NULL) {
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
398 if (tstate->curexc_traceback == NULL)
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
399 PyTraceBack_Here(f);
33113
28e877ff74cf make exception propogation more efficient; this avoids having Expat parse
Fred Drake <fdrake@acm.org>
parents: 32965
diff changeset
400 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
401 #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
402 if (trace_frame_exc(tstate, f) < 0) {
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
403 return NULL;
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
404 }
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
405 }
24533
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
406 else {
29605
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
407 if (trace_frame(tstate, f, PyTrace_RETURN, res) < 0) {
24533
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
408 Py_XDECREF(res);
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
409 res = NULL;
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
410 }
1c26eb768293 Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 24328
diff changeset
411 }
29605
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
412 #else
e43126c470a7 Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27586
diff changeset
413 }
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
414 #endif
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
415 tstate->frame = f->f_back;
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
416 Py_DECREF(f);
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
417 return res;
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
418 }
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
419
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18854
diff changeset
420 #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
421 #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
422 #else
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
423 /* 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
424 #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
425 ? 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
426 #endif
12187
39b91cb80b41 Make it compile on Windows.
Guido van Rossum <guido@python.org>
parents: 12182
diff changeset
427
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
428 static PyObject*
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
429 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
430 {
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
431 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
432 PyObject *value;
35658
a83e8df13498 Patch #1309009, Fix segfault in pyexpat when the XML document is
Neal Norwitz <nnorwitz@gmail.com>
parents: 34687
diff changeset
433 /* 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
434 if (!result)
a83e8df13498 Patch #1309009, Fix segfault in pyexpat when the XML document is
Neal Norwitz <nnorwitz@gmail.com>
parents: 34687
diff changeset
435 return result;
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
436 if (!self->intern)
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
437 return result;
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
438 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
439 if (!value) {
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
440 if (PyDict_SetItem(self->intern, result, result) == 0)
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
441 return result;
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
442 else
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
443 return NULL;
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
444 }
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
445 Py_INCREF(value);
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
446 Py_DECREF(result);
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
447 return value;
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
448 }
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
449
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
450 /* 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
451 * 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
452 */
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
453 static int
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
454 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
455 {
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
456 PyObject *args;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
457 PyObject *temp;
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 args = PyTuple_New(1);
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
460 if (args == NULL)
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
461 return -1;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
462 #ifdef Py_USING_UNICODE
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
463 temp = (self->returns_unicode
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
464 ? conv_string_len_to_unicode(buffer, len)
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
465 : 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
466 #else
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
467 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
468 #endif
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
469 if (temp == NULL) {
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
470 Py_DECREF(args);
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
471 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
472 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
473 noop_character_data_handler);
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
474 return -1;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
475 }
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
476 PyTuple_SET_ITEM(args, 0, temp);
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
477 /* 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
478 self->in_callback = 1;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
479 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
480 self->handlers[CharacterData], args, self);
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
481 /* 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
482 self->in_callback = 0;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
483 Py_DECREF(args);
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
484 if (temp == NULL) {
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
485 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
486 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
487 noop_character_data_handler);
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
488 return -1;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
489 }
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
490 Py_DECREF(temp);
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
491 return 0;
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 static int
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
495 flush_character_buffer(xmlparseobject *self)
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
496 {
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
497 int rc;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
498 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
499 return 0;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
500 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
501 self->buffer_used = 0;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
502 return rc;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
503 }
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
504
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
505 static void
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
506 my_CharacterDataHandler(void *userData, const XML_Char *data, int len)
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
507 {
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
508 xmlparseobject *self = (xmlparseobject *) userData;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
509 if (self->buffer == NULL)
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
510 call_character_handler(self, data, len);
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
511 else {
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
512 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
513 if (flush_character_buffer(self) < 0)
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
514 return;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
515 /* 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
516 * 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
517 */
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
518 if (!have_handler(self, CharacterData))
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
519 return;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
520 }
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
521 if (len > self->buffer_size) {
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
522 call_character_handler(self, data, len);
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
523 self->buffer_used = 0;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
524 }
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
525 else {
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
526 memcpy(self->buffer + self->buffer_used,
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
527 data, len * sizeof(XML_Char));
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
528 self->buffer_used += len;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
529 }
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
530 }
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
531 }
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
532
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
533 static void
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
534 my_StartElementHandler(void *userData,
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
535 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
536 {
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
537 xmlparseobject *self = (xmlparseobject *)userData;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
538
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
539 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
540 PyObject *container, *rv, *args;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
541 int i, max;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
542
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
543 if (flush_character_buffer(self) < 0)
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
544 return;
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
545 /* 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
546 * 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
547 */
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
548 if (self->specified_attributes) {
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
549 max = XML_GetSpecifiedAttributeCount(self->itself);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
550 }
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
551 else {
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
552 max = 0;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
553 while (atts[max] != NULL)
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
554 max += 2;
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 /* Build the container. */
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
557 if (self->ordered_attributes)
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
558 container = PyList_New(max);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
559 else
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
560 container = PyDict_New();
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
561 if (container == NULL) {
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
562 flag_error(self);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
563 return;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
564 }
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
565 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
566 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
567 PyObject *v;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
568 if (n == NULL) {
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
569 flag_error(self);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
570 Py_DECREF(container);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
571 return;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
572 }
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
573 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
574 if (v == NULL) {
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
575 flag_error(self);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
576 Py_DECREF(container);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
577 Py_DECREF(n);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
578 return;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
579 }
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
580 if (self->ordered_attributes) {
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
581 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
582 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
583 }
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
584 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
585 flag_error(self);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
586 Py_DECREF(n);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
587 Py_DECREF(v);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
588 return;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
589 }
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
590 else {
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
591 Py_DECREF(n);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
592 Py_DECREF(v);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
593 }
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
594 }
35658
a83e8df13498 Patch #1309009, Fix segfault in pyexpat when the XML document is
Neal Norwitz <nnorwitz@gmail.com>
parents: 34687
diff changeset
595 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
596 if (args != NULL)
a83e8df13498 Patch #1309009, Fix segfault in pyexpat when the XML document is
Neal Norwitz <nnorwitz@gmail.com>
parents: 34687
diff changeset
597 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
598 if (args == NULL) {
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
599 Py_DECREF(container);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
600 return;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
601 }
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
602 /* 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
603 self->in_callback = 1;
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
604 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
605 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
606 self->in_callback = 0;
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
607 Py_DECREF(args);
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
608 if (rv == NULL) {
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
609 flag_error(self);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
610 return;
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
611 }
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
612 Py_DECREF(rv);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
613 }
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
614 }
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
615
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
616 #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
617 RETURN, GETUSERDATA) \
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
618 static RC \
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
619 my_##NAME##Handler PARAMS {\
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
620 xmlparseobject *self = GETUSERDATA ; \
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
621 PyObject *args = NULL; \
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
622 PyObject *rv = NULL; \
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
623 INIT \
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
624 \
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
625 if (have_handler(self, NAME)) { \
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
626 if (flush_character_buffer(self) < 0) \
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
627 return RETURN; \
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
628 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
629 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
630 self->in_callback = 1; \
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
631 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
632 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
633 self->in_callback = 0; \
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
634 Py_DECREF(args); \
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
635 if (rv == NULL) { \
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
636 flag_error(self); \
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
637 return RETURN; \
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
638 } \
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
639 CONVERSION \
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
640 Py_DECREF(rv); \
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
641 } \
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
642 return RETURN; \
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
643 }
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
644
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
645 #define VOID_HANDLER(NAME, PARAMS, PARAM_FORMAT) \
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
646 RC_HANDLER(void, NAME, PARAMS, ;, PARAM_FORMAT, ;, ;,\
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
647 (xmlparseobject *)userData)
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
648
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
649 #define INT_HANDLER(NAME, PARAMS, PARAM_FORMAT)\
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
650 RC_HANDLER(int, NAME, PARAMS, int rc=0;, PARAM_FORMAT, \
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
651 rc = PyInt_AsLong(rv);, rc, \
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
652 (xmlparseobject *)userData)
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
653
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
654 VOID_HANDLER(EndElement,
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
655 (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
656 ("(N)", string_intern(self, name)))
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
657
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
658 VOID_HANDLER(ProcessingInstruction,
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
659 (void *userData,
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
660 const XML_Char *target,
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
661 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
662 ("(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
663
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
664 VOID_HANDLER(UnparsedEntityDecl,
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
665 (void *userData,
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
666 const XML_Char *entityName,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
667 const XML_Char *base,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
668 const XML_Char *systemId,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
669 const XML_Char *publicId,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
670 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
671 ("(NNNNN)",
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
672 string_intern(self, entityName), string_intern(self, base),
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
673 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
674 string_intern(self, notationName)))
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
675
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18854
diff changeset
676 #ifndef Py_USING_UNICODE
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
677 VOID_HANDLER(EntityDecl,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
678 (void *userData,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
679 const XML_Char *entityName,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
680 int is_parameter_entity,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
681 const XML_Char *value,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
682 int value_length,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
683 const XML_Char *base,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
684 const XML_Char *systemId,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
685 const XML_Char *publicId,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
686 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
687 ("NiNNNNN",
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
688 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
689 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
690 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
691 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
692 string_intern(self, notationName)))
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
693 #else
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
694 VOID_HANDLER(EntityDecl,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
695 (void *userData,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
696 const XML_Char *entityName,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
697 int is_parameter_entity,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
698 const XML_Char *value,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
699 int value_length,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
700 const XML_Char *base,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
701 const XML_Char *systemId,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
702 const XML_Char *publicId,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
703 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
704 ("NiNNNNN",
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
705 string_intern(self, entityName), is_parameter_entity,
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
706 (self->returns_unicode
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
707 ? 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
708 : 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
709 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
710 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
711 string_intern(self, notationName)))
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
712 #endif
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
713
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
714 VOID_HANDLER(XmlDecl,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
715 (void *userData,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
716 const XML_Char *version,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
717 const XML_Char *encoding,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
718 int standalone),
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
719 ("(O&O&i)",
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
720 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
721 standalone))
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
722
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
723 static PyObject *
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
724 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
725 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
726 {
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
727 PyObject *result = NULL;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
728 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
729 int i;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
730
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
731 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
732 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
733 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
734 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
735 conv_string);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
736 if (child == NULL) {
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
737 Py_XDECREF(children);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
738 return NULL;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
739 }
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
740 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
741 }
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
742 result = Py_BuildValue("(iiO&N)",
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
743 model->type, model->quant,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
744 conv_string,model->name, children);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
745 }
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
746 return result;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
747 }
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
748
27586
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
749 static void
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
750 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
751 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
752 XML_Content *model)
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
753 {
27586
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
754 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
755 PyObject *args = NULL;
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
756
27586
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
757 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
758 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
759 PyObject *modelobj, *nameobj;
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
760
27586
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
761 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
762 goto finally;
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
763 #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
764 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
765 (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
766 ? 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
767 : conv_string_to_utf8));
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
768 #else
27586
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
769 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
770 #endif
27586
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
771 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
772 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
773 goto finally;
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
774 }
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
775 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
776 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
777 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
778 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
779 goto finally;
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
780 }
32923
f1bbf147810b Fix the reference count errors revealed by the test suite...
Michael W. Hudson <mwh@python.net>
parents: 30683
diff changeset
781 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
782 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
783 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
784 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
785 goto finally;
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
786 }
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
787 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
788 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
789 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
790 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
791 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
792 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
793 goto finally;
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
794 }
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
795 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
796 }
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
797 finally:
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
798 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
799 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
800 return;
98197ebe5ccb Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents: 27322
diff changeset
801 }
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
802
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
803 VOID_HANDLER(AttlistDecl,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
804 (void *userData,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
805 const XML_Char *elname,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
806 const XML_Char *attname,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
807 const XML_Char *att_type,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
808 const XML_Char *dflt,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
809 int isrequired),
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
810 ("(NNO&O&i)",
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
811 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
812 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
813 isrequired))
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
814
27322
88bf10313584 Conditionalize features not found in PyXML 1.95.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 27321
diff changeset
815 #if XML_COMBINED_VERSION >= 19504
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
816 VOID_HANDLER(SkippedEntity,
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
817 (void *userData,
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
818 const XML_Char *entityName,
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
819 int is_parameter_entity),
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
820 ("Ni",
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
821 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
822 #endif
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
823
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
824 VOID_HANDLER(NotationDecl,
13025
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
825 (void *userData,
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
826 const XML_Char *notationName,
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
827 const XML_Char *base,
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
828 const XML_Char *systemId,
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
829 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
830 ("(NNNN)",
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
831 string_intern(self, notationName), string_intern(self, base),
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
832 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
833
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
834 VOID_HANDLER(StartNamespaceDecl,
13025
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
835 (void *userData,
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
836 const XML_Char *prefix,
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
837 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
838 ("(NN)",
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
839 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
840
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
841 VOID_HANDLER(EndNamespaceDecl,
13025
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
842 (void *userData,
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
843 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
844 ("(N)", string_intern(self, prefix)))
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 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
847 (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
848 ("(O&)", STRING_CONV_FUNC,data))
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
849
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
850 VOID_HANDLER(StartCdataSection,
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
851 (void *userData),
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
852 ("()"))
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
853
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
854 VOID_HANDLER(EndCdataSection,
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
855 (void *userData),
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
856 ("()"))
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
857
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18854
diff changeset
858 #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
859 VOID_HANDLER(Default,
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
860 (void *userData, const XML_Char *s, int len),
14728
e2c03c30b06d Remove memory leaks of strings/Unicode objects passed into the character
Fred Drake <fdrake@acm.org>
parents: 14375
diff changeset
861 ("(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
862
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
863 VOID_HANDLER(DefaultHandlerExpand,
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
864 (void *userData, const XML_Char *s, int len),
14728
e2c03c30b06d Remove memory leaks of strings/Unicode objects passed into the character
Fred Drake <fdrake@acm.org>
parents: 14375
diff changeset
865 ("(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
866 #else
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
867 VOID_HANDLER(Default,
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
868 (void *userData, const XML_Char *s, int len),
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
869 ("(N)", (self->returns_unicode
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
870 ? conv_string_len_to_unicode(s,len)
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
871 : 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
872
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
873 VOID_HANDLER(DefaultHandlerExpand,
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
874 (void *userData, const XML_Char *s, int len),
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
875 ("(N)", (self->returns_unicode
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
876 ? conv_string_len_to_unicode(s,len)
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
877 : 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
878 #endif
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
879
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
880 INT_HANDLER(NotStandalone,
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
881 (void *userData),
13025
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
882 ("()"))
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
883
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
884 RC_HANDLER(int, ExternalEntityRef,
13025
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
885 (XML_Parser parser,
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
886 const XML_Char *context,
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
887 const XML_Char *base,
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
888 const XML_Char *systemId,
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
889 const XML_Char *publicId),
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
890 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
891 ("(O&NNN)",
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
892 STRING_CONV_FUNC,context, string_intern(self, base),
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
893 string_intern(self, systemId), string_intern(self, publicId)),
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
894 rc = PyInt_AsLong(rv);, rc,
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
895 XML_GetUserData(parser))
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
896
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
897 /* XXX UnknownEncodingHandler */
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
898
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
899 VOID_HANDLER(StartDoctypeDecl,
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
900 (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
901 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
902 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
903 ("(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
904 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
905 has_internal_subset))
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
906
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
907 VOID_HANDLER(EndDoctypeDecl, (void *userData), ("()"))
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
908
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
909 /* ---------------------------------------------------------------- */
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
910
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
911 static PyObject *
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
912 get_parse_result(xmlparseobject *self, int rv)
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
913 {
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
914 if (PyErr_Occurred()) {
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
915 return NULL;
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
916 }
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
917 if (rv == 0) {
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
918 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
919 }
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
920 if (flush_character_buffer(self) < 0) {
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
921 return NULL;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
922 }
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
923 return PyInt_FromLong(rv);
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
924 }
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
925
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22421
diff changeset
926 PyDoc_STRVAR(xmlparse_Parse__doc__,
13654
0bb49b3dbdf0 Mark Favas's fix for typos in docstrings.
Thomas Wouters <thomas@python.org>
parents: 13568
diff changeset
927 "Parse(data[, isfinal])\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22421
diff changeset
928 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
929
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
930 static PyObject *
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
931 xmlparse_Parse(xmlparseobject *self, PyObject *args)
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
932 {
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
933 char *s;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
934 int slen;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
935 int isFinal = 0;
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
936
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
937 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
938 return NULL;
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
939
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
940 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
941 }
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
942
14728
e2c03c30b06d Remove memory leaks of strings/Unicode objects passed into the character
Fred Drake <fdrake@acm.org>
parents: 14375
diff changeset
943 /* 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
944
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
945 #define BUF_SIZE 2048
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
946
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
947 static int
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
948 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
949 {
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
950 PyObject *arg = NULL;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
951 PyObject *bytes = NULL;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
952 PyObject *str = NULL;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
953 int len = -1;
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
954
14755
93207076d612 When PyInt_FromLong() returns NULL, you do not need to check
Fred Drake <fdrake@acm.org>
parents: 14749
diff changeset
955 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
956 goto finally;
14755
93207076d612 When PyInt_FromLong() returns NULL, you do not need to check
Fred Drake <fdrake@acm.org>
parents: 14749
diff changeset
957
29955
09c459851264 Fix memory leak reported & discussed on the Python XML-SIG mailing list.
Fred Drake <fdrake@acm.org>
parents: 29605
diff changeset
958 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
959 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
960 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
961 }
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
962
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
963 PyTuple_SET_ITEM(arg, 0, bytes);
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
964
33752
ddc2d6e547c1 Synchronize with PyXML 1.79:
Martin v. Löwis <martin@v.loewis.de>
parents: 33279
diff changeset
965 #if PY_VERSION_HEX < 0x02020000
ddc2d6e547c1 Synchronize with PyXML 1.79:
Martin v. Löwis <martin@v.loewis.de>
parents: 33279
diff changeset
966 str = PyObject_CallObject(meth, arg);
ddc2d6e547c1 Synchronize with PyXML 1.79:
Martin v. Löwis <martin@v.loewis.de>
parents: 33279
diff changeset
967 #else
ddc2d6e547c1 Synchronize with PyXML 1.79:
Martin v. Löwis <martin@v.loewis.de>
parents: 33279
diff changeset
968 str = PyObject_Call(meth, arg, NULL);
ddc2d6e547c1 Synchronize with PyXML 1.79:
Martin v. Löwis <martin@v.loewis.de>
parents: 33279
diff changeset
969 #endif
ddc2d6e547c1 Synchronize with PyXML 1.79:
Martin v. Löwis <martin@v.loewis.de>
parents: 33279
diff changeset
970 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
971 goto finally;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
972
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
973 /* 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
974 if (!PyString_Check(str)) {
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
975 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
976 "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
977 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
978 goto finally;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
979 }
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
980 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
981 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
982 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
983 "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
984 "%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
985 buf_size, len);
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
986 goto finally;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
987 }
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
988 memcpy(buf, PyString_AsString(str), len);
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
989 finally:
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
990 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
991 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
992 return len;
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
993 }
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
994
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22421
diff changeset
995 PyDoc_STRVAR(xmlparse_ParseFile__doc__,
13654
0bb49b3dbdf0 Mark Favas's fix for typos in docstrings.
Thomas Wouters <thomas@python.org>
parents: 13568
diff changeset
996 "ParseFile(file)\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22421
diff changeset
997 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
998
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
999 static PyObject *
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 37762
diff changeset
1000 xmlparse_ParseFile(xmlparseobject *self, PyObject *f)
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1001 {
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1002 int rv = 1;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1003 FILE *fp;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1004 PyObject *readmethod = NULL;
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1005
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1006 if (PyFile_Check(f)) {
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1007 fp = PyFile_AsFile(f);
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1008 }
36891
a9697de5e18b Fix logic error and DECREF reported by Coverity.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36675
diff changeset
1009 else {
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1010 fp = NULL;
14728
e2c03c30b06d Remove memory leaks of strings/Unicode objects passed into the character
Fred Drake <fdrake@acm.org>
parents: 14375
diff changeset
1011 readmethod = PyObject_GetAttrString(f, "read");
e2c03c30b06d Remove memory leaks of strings/Unicode objects passed into the character
Fred Drake <fdrake@acm.org>
parents: 14375
diff changeset
1012 if (readmethod == NULL) {
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1013 PyErr_Clear();
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1014 PyErr_SetString(PyExc_TypeError,
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1015 "argument must have 'read' attribute");
24328
d497f523b82e Return NULL instead of 0 from function with a pointer return value.
Fred Drake <fdrake@acm.org>
parents: 24315
diff changeset
1016 return NULL;
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1017 }
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1018 }
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1019 for (;;) {
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1020 int bytes_read;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1021 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
1022 if (buf == NULL) {
29957
cea7f8af8e0b Repair mis-application of Jeremy's patch. Thanks, Neal!
Fred Drake <fdrake@acm.org>
parents: 29955
diff changeset
1023 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
1024 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
1025 }
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1026
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1027 if (fp) {
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1028 bytes_read = fread(buf, sizeof(char), BUF_SIZE, fp);
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1029 if (bytes_read < 0) {
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1030 PyErr_SetFromErrno(PyExc_IOError);
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1031 return NULL;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1032 }
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1033 }
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1034 else {
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1035 bytes_read = readinst(buf, BUF_SIZE, readmethod);
29955
09c459851264 Fix memory leak reported & discussed on the Python XML-SIG mailing list.
Fred Drake <fdrake@acm.org>
parents: 29605
diff changeset
1036 if (bytes_read < 0) {
09c459851264 Fix memory leak reported & discussed on the Python XML-SIG mailing list.
Fred Drake <fdrake@acm.org>
parents: 29605
diff changeset
1037 Py_DECREF(readmethod);
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1038 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
1039 }
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1040 }
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1041 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
1042 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
1043 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
1044 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
1045 }
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1046
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1047 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
1048 break;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1049 }
29955
09c459851264 Fix memory leak reported & discussed on the Python XML-SIG mailing list.
Fred Drake <fdrake@acm.org>
parents: 29605
diff changeset
1050 Py_XDECREF(readmethod);
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1051 return get_parse_result(self, rv);
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1052 }
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1053
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22421
diff changeset
1054 PyDoc_STRVAR(xmlparse_SetBase__doc__,
13654
0bb49b3dbdf0 Mark Favas's fix for typos in docstrings.
Thomas Wouters <thomas@python.org>
parents: 13568
diff changeset
1055 "SetBase(base_url)\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22421
diff changeset
1056 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
1057
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1058 static PyObject *
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1059 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
1060 {
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1061 char *base;
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1062
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1063 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
1064 return NULL;
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1065 if (!XML_SetBase(self->itself, base)) {
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1066 return PyErr_NoMemory();
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1067 }
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1068 Py_INCREF(Py_None);
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1069 return Py_None;
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1070 }
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1071
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22421
diff changeset
1072 PyDoc_STRVAR(xmlparse_GetBase__doc__,
13654
0bb49b3dbdf0 Mark Favas's fix for typos in docstrings.
Thomas Wouters <thomas@python.org>
parents: 13568
diff changeset
1073 "GetBase() -> url\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22421
diff changeset
1074 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
1075
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1076 static PyObject *
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 37762
diff changeset
1077 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
1078 {
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1079 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
1080 }
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1081
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22421
diff changeset
1082 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
1083 "GetInputContext() -> string\n\
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
1084 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
1085 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
1086 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
1087
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
1088 static PyObject *
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 37762
diff changeset
1089 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
1090 {
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 37762
diff changeset
1091 if (self->in_callback) {
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 37762
diff changeset
1092 int offset, size;
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 37762
diff changeset
1093 const char *buffer
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 37762
diff changeset
1094 = 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
1095
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 37762
diff changeset
1096 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
1097 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
1098 size - offset);
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 37762
diff changeset
1099 else
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 37762
diff changeset
1100 Py_RETURN_NONE;
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
1101 }
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 37762
diff changeset
1102 else
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 37762
diff changeset
1103 Py_RETURN_NONE;
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
1104 }
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
1105
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22421
diff changeset
1106 PyDoc_STRVAR(xmlparse_ExternalEntityParserCreate__doc__,
15703
f6ee0d4672d6 Mark the "encoding" parameter to ExternalEntityParserCreate() as optional
Fred Drake <fdrake@acm.org>
parents: 15642
diff changeset
1107 "ExternalEntityParserCreate(context[, encoding])\n\
14824
a1033283a25d Repaired damaged string.
Tim Peters <tim.peters@gmail.com>
parents: 14823
diff changeset
1108 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
1109 information passed to the ExternalEntityRefHandler.");
14812
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1110
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1111 static PyObject *
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1112 xmlparse_ExternalEntityParserCreate(xmlparseobject *self, PyObject *args)
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1113 {
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1114 char *context;
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1115 char *encoding = NULL;
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1116 xmlparseobject *new_parser;
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1117 int i;
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1118
19978
a960e673077f Patch to bug #461753: Allow None in ExternalEntityParserCreate.
Martin v. Löwis <martin@v.loewis.de>
parents: 19343
diff changeset
1119 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
1120 &context, &encoding)) {
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1121 return NULL;
14812
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1122 }
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1123
20047
4c5cd3d1cf4b Reactivate participation of expat parsers in GC. Fixes bug #462710.
Martin v. Löwis <martin@v.loewis.de>
parents: 19979
diff changeset
1124 #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
1125 /* Python versions 2.0 and 2.1 */
14812
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1126 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
1127 #else
4c5cd3d1cf4b Reactivate participation of expat parsers in GC. Fixes bug #462710.
Martin v. Löwis <martin@v.loewis.de>
parents: 19979
diff changeset
1128 /* 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
1129 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
1130 #endif
14812
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1131
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1132 if (new_parser == NULL)
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1133 return NULL;
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1134 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
1135 new_parser->buffer_used = 0;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1136 if (self->buffer != NULL) {
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1137 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
1138 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
1139 #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
1140 /* 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
1141 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
1142 #else
183eba2d2214 Do not depend on pymemcompat.h (was only used for PyXML); Martin likes
Fred Drake <fdrake@acm.org>
parents: 24076
diff changeset
1143 /* 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
1144 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
1145 #endif
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1146 return PyErr_NoMemory();
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1147 }
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1148 }
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1149 else
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1150 new_parser->buffer = NULL;
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1151 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
1152 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
1153 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
1154 new_parser->in_callback = 0;
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1155 new_parser->ns_prefixes = self->ns_prefixes;
14812
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1156 new_parser->itself = XML_ExternalEntityParserCreate(self->itself, context,
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1157 encoding);
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1158 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
1159 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
1160 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
1161 #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
1162 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
1163 #else
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1164 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
1165 #endif
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1166
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1167 if (!new_parser->itself) {
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1168 Py_DECREF(new_parser);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1169 return PyErr_NoMemory();
14812
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1170 }
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1171
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1172 XML_SetUserData(new_parser->itself, (void *)new_parser);
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1173
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1174 /* allocate and clear handlers first */
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1175 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
1176 /* do nothing */;
14812
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1177
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1178 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
1179 if (!new_parser->handlers) {
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1180 Py_DECREF(new_parser);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1181 return PyErr_NoMemory();
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1182 }
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
1183 clear_handlers(new_parser, 1);
14812
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1184
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1185 /* then copy handlers from self */
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1186 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
1187 PyObject *handler = self->handlers[i];
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1188 if (handler != NULL) {
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1189 Py_INCREF(handler);
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1190 new_parser->handlers[i] = handler;
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1191 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
1192 handler_info[i].handler);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1193 }
14812
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1194 }
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1195 return (PyObject *)new_parser;
14812
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1196 }
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1197
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22421
diff changeset
1198 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
1199 "SetParamEntityParsing(flag) -> success\n\
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1200 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
1201 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
1202 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
1203 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
1204 was successful.");
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1205
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1206 static PyObject*
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
1207 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
1208 {
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1209 int flag;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1210 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
1211 return NULL;
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
1212 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
1213 return PyInt_FromLong(flag);
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1214 }
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1215
27322
88bf10313584 Conditionalize features not found in PyXML 1.95.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 27321
diff changeset
1216
88bf10313584 Conditionalize features not found in PyXML 1.95.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 27321
diff changeset
1217 #if XML_COMBINED_VERSION >= 19505
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1218 PyDoc_STRVAR(xmlparse_UseForeignDTD__doc__,
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1219 "UseForeignDTD([flag])\n\
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1220 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
1221 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
1222 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
1223 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
1224 '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
1225
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1226 static PyObject *
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1227 xmlparse_UseForeignDTD(xmlparseobject *self, PyObject *args)
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1228 {
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1229 PyObject *flagobj = NULL;
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1230 XML_Bool flag = XML_TRUE;
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1231 enum XML_Error rc;
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 37762
diff changeset
1232 if (!PyArg_UnpackTuple(args, "UseForeignDTD", 0, 1, &flagobj))
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1233 return NULL;
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1234 if (flagobj != NULL)
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1235 flag = PyObject_IsTrue(flagobj) ? XML_TRUE : XML_FALSE;
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1236 rc = XML_UseForeignDTD(self->itself, flag);
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1237 if (rc != XML_ERROR_NONE) {
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1238 return set_error(self, rc);
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1239 }
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1240 Py_INCREF(Py_None);
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1241 return Py_None;
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1242 }
27322
88bf10313584 Conditionalize features not found in PyXML 1.95.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 27321
diff changeset
1243 #endif
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1244
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1245 static struct PyMethodDef xmlparse_methods[] = {
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1246 {"Parse", (PyCFunction)xmlparse_Parse,
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
1247 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
1248 {"ParseFile", (PyCFunction)xmlparse_ParseFile,
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 37762
diff changeset
1249 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
1250 {"SetBase", (PyCFunction)xmlparse_SetBase,
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1251 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
1252 {"GetBase", (PyCFunction)xmlparse_GetBase,
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 37762
diff changeset
1253 METH_NOARGS, xmlparse_GetBase__doc__},
14812
d543daa15d71 Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents: 14788
diff changeset
1254 {"ExternalEntityParserCreate", (PyCFunction)xmlparse_ExternalEntityParserCreate,
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1255 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
1256 {"SetParamEntityParsing", (PyCFunction)xmlparse_SetParamEntityParsing,
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
1257 METH_VARARGS, xmlparse_SetParamEntityParsing__doc__},
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
1258 {"GetInputContext", (PyCFunction)xmlparse_GetInputContext,
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 37762
diff changeset
1259 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
1260 #if XML_COMBINED_VERSION >= 19505
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1261 {"UseForeignDTD", (PyCFunction)xmlparse_UseForeignDTD,
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1262 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
1263 #endif
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1264 {NULL, NULL} /* sentinel */
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1265 };
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1266
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1267 /* ---------- */
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1268
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1269
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18854
diff changeset
1270 #ifdef Py_USING_UNICODE
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1271
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1272 /* pyexpat international encoding support.
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1273 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
1274 */
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1275
16099
967abbecc404 Fix off-by-one error in array size.
Martin v. Löwis <martin@v.loewis.de>
parents: 16094
diff changeset
1276 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
1277 PyObject *template_string = NULL;
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1278
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1279 static void
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1280 init_template_buffer(void)
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1281 {
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1282 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
1283 for (i = 0; i < 256; i++) {
a46a13201eeb Wrap some long lines, use only C89 /* */ comments, and add spaces around
Fred Drake <fdrake@acm.org>
parents: 16644
diff changeset
1284 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
1285 }
16912
a46a13201eeb Wrap some long lines, use only C89 /* */ comments, and add spaces around
Fred Drake <fdrake@acm.org>
parents: 16644
diff changeset
1286 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
1287 }
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1288
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1289 static int
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1290 PyUnknownEncodingHandler(void *encodingHandlerData,
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1291 const XML_Char *name,
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1292 XML_Encoding *info)
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1293 {
16912
a46a13201eeb Wrap some long lines, use only C89 /* */ comments, and add spaces around
Fred Drake <fdrake@acm.org>
parents: 16644
diff changeset
1294 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
1295 int result = 0;
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1296 int i;
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1297
16912
a46a13201eeb Wrap some long lines, use only C89 /* */ comments, and add spaces around
Fred Drake <fdrake@acm.org>
parents: 16644
diff changeset
1298 /* 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
1299 _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
1300 PyUnicode_Decode(template_buffer, 256, name, "replace");
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1301
16912
a46a13201eeb Wrap some long lines, use only C89 /* */ comments, and add spaces around
Fred Drake <fdrake@acm.org>
parents: 16644
diff changeset
1302 if (_u_string == NULL)
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1303 return result;
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1304
16912
a46a13201eeb Wrap some long lines, use only C89 /* */ comments, and add spaces around
Fred Drake <fdrake@acm.org>
parents: 16644
diff changeset
1305 for (i = 0; i < 256; i++) {
a46a13201eeb Wrap some long lines, use only C89 /* */ comments, and add spaces around
Fred Drake <fdrake@acm.org>
parents: 16644
diff changeset
1306 /* Stupid to access directly, but fast */
a46a13201eeb Wrap some long lines, use only C89 /* */ comments, and add spaces around
Fred Drake <fdrake@acm.org>
parents: 16644
diff changeset
1307 Py_UNICODE c = _u_string->str[i];
a46a13201eeb Wrap some long lines, use only C89 /* */ comments, and add spaces around
Fred Drake <fdrake@acm.org>
parents: 16644
diff changeset
1308 if (c == Py_UNICODE_REPLACEMENT_CHARACTER)
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1309 info->map[i] = -1;
16912
a46a13201eeb Wrap some long lines, use only C89 /* */ comments, and add spaces around
Fred Drake <fdrake@acm.org>
parents: 16644
diff changeset
1310 else
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1311 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
1312 }
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1313 info->data = NULL;
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1314 info->convert = NULL;
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1315 info->release = NULL;
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1316 result = 1;
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1317 Py_DECREF(_u_string);
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1318 return result;
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1319 }
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1320
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1321 #endif
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1322
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1323 static PyObject *
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1324 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
1325 {
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1326 int i;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1327 xmlparseobject *self;
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1328
20047
4c5cd3d1cf4b Reactivate participation of expat parsers in GC. Fixes bug #462710.
Martin v. Löwis <martin@v.loewis.de>
parents: 19979
diff changeset
1329 #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
1330 /* 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
1331 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
1332 #else
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1333 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
1334 #endif
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1335 if (self == NULL)
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1336 return NULL;
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1337
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
1338 #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
1339 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
1340 #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
1341 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
1342 #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
1343
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1344 self->buffer = NULL;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1345 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
1346 self->buffer_used = 0;
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1347 self->ordered_attributes = 0;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1348 self->specified_attributes = 0;
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
1349 self->in_callback = 0;
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1350 self->ns_prefixes = 0;
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1351 self->handlers = NULL;
17623
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1352 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
1353 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
1354 }
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1355 else {
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1356 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
1357 }
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1358 self->intern = intern;
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1359 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
1360 #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
1361 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
1362 #else
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1363 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
1364 #endif
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1365 if (self->itself == NULL) {
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1366 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
1367 "XML_ParserCreate failed");
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1368 Py_DECREF(self);
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1369 return NULL;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1370 }
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1371 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
1372 #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
1373 XML_SetUnknownEncodingHandler(self->itself,
95ccd5bbdc86 Bring this back into sync with PyXML revision 1.58.
Fred Drake <fdrake@acm.org>
parents: 24064
diff changeset
1374 (XML_UnknownEncodingHandler) PyUnknownEncodingHandler, NULL);
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1375 #endif
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1376
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1377 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
1378 /* do nothing */;
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1379
24076
95ccd5bbdc86 Bring this back into sync with PyXML revision 1.58.
Fred Drake <fdrake@acm.org>
parents: 24064
diff changeset
1380 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
1381 if (!self->handlers) {
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1382 Py_DECREF(self);
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1383 return PyErr_NoMemory();
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1384 }
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
1385 clear_handlers(self, 1);
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1386
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1387 return (PyObject*)self;
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1388 }
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1389
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1390
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1391 static void
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1392 xmlparse_dealloc(xmlparseobject *self)
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1393 {
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1394 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
1395 #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
1396 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
1397 #else
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1398 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
1399 #endif
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1400 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
1401 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
1402 self->itself = NULL;
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1403
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1404 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
1405 PyObject *temp;
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1406 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
1407 temp = self->handlers[i];
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1408 self->handlers[i] = NULL;
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1409 Py_XDECREF(temp);
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1410 }
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1411 free(self->handlers);
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1412 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
1413 }
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1414 if (self->buffer != NULL) {
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1415 free(self->buffer);
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1416 self->buffer = NULL;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1417 }
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1418 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
1419 #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
1420 /* 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
1421 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
1422 #else
4c5cd3d1cf4b Reactivate participation of expat parsers in GC. Fixes bug #462710.
Martin v. Löwis <martin@v.loewis.de>
parents: 19979
diff changeset
1423 /* 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
1424 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
1425 #endif
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1426 }
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1427
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1428 static int
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1429 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
1430 {
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1431 int i;
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1432 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
1433 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
1434 return i;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1435 }
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1436 }
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1437 return -1;
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1438 }
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1439
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1440 static PyObject *
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1441 get_pybool(int istrue)
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1442 {
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1443 PyObject *result = istrue ? Py_True : Py_False;
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1444 Py_INCREF(result);
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1445 return result;
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1446 }
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1447
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1448 static PyObject *
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1449 xmlparse_getattr(xmlparseobject *self, char *name)
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1450 {
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1451 int handlernum = handlername2int(name);
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1452
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1453 if (handlernum != -1) {
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1454 PyObject *result = self->handlers[handlernum];
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1455 if (result == NULL)
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1456 result = Py_None;
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1457 Py_INCREF(result);
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1458 return result;
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1459 }
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1460 if (name[0] == 'E') {
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1461 if (strcmp(name, "ErrorCode") == 0)
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1462 return PyInt_FromLong((long)
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1463 XML_GetErrorCode(self->itself));
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1464 if (strcmp(name, "ErrorLineNumber") == 0)
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1465 return PyInt_FromLong((long)
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1466 XML_GetErrorLineNumber(self->itself));
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1467 if (strcmp(name, "ErrorColumnNumber") == 0)
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1468 return PyInt_FromLong((long)
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1469 XML_GetErrorColumnNumber(self->itself));
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1470 if (strcmp(name, "ErrorByteIndex") == 0)
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1471 return PyInt_FromLong((long)
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1472 XML_GetErrorByteIndex(self->itself));
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1473 }
33279
b25cb2045dac Patch #1014930. Expose current parse location to XMLParser.
Dave Cole <djc@object-craft.com.au>
parents: 33113
diff changeset
1474 if (name[0] == 'C') {
b25cb2045dac Patch #1014930. Expose current parse location to XMLParser.
Dave Cole <djc@object-craft.com.au>
parents: 33113
diff changeset
1475 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
1476 return PyInt_FromLong((long)
b25cb2045dac Patch #1014930. Expose current parse location to XMLParser.
Dave Cole <djc@object-craft.com.au>
parents: 33113
diff changeset
1477 XML_GetCurrentLineNumber(self->itself));
b25cb2045dac Patch #1014930. Expose current parse location to XMLParser.
Dave Cole <djc@object-craft.com.au>
parents: 33113
diff changeset
1478 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
1479 return PyInt_FromLong((long)
b25cb2045dac Patch #1014930. Expose current parse location to XMLParser.
Dave Cole <djc@object-craft.com.au>
parents: 33113
diff changeset
1480 XML_GetCurrentColumnNumber(self->itself));
b25cb2045dac Patch #1014930. Expose current parse location to XMLParser.
Dave Cole <djc@object-craft.com.au>
parents: 33113
diff changeset
1481 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
1482 return PyInt_FromLong((long)
b25cb2045dac Patch #1014930. Expose current parse location to XMLParser.
Dave Cole <djc@object-craft.com.au>
parents: 33113
diff changeset
1483 XML_GetCurrentByteIndex(self->itself));
b25cb2045dac Patch #1014930. Expose current parse location to XMLParser.
Dave Cole <djc@object-craft.com.au>
parents: 33113
diff changeset
1484 }
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1485 if (name[0] == 'b') {
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1486 if (strcmp(name, "buffer_size") == 0)
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1487 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
1488 if (strcmp(name, "buffer_text") == 0)
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1489 return get_pybool(self->buffer != NULL);
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1490 if (strcmp(name, "buffer_used") == 0)
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1491 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
1492 }
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1493 if (strcmp(name, "namespace_prefixes") == 0)
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1494 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
1495 if (strcmp(name, "ordered_attributes") == 0)
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1496 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
1497 if (strcmp(name, "returns_unicode") == 0)
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1498 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
1499 if (strcmp(name, "specified_attributes") == 0)
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1500 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
1501 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
1502 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
1503 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
1504 return Py_None;
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1505 }
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1506 else {
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1507 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
1508 return self->intern;
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1509 }
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1510 }
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1511
27301
5a975e82d70f SF # 669553, fix memory (ref) leaks
Neal Norwitz <nnorwitz@gmail.com>
parents: 26109
diff changeset
1512 #define APPEND(list, str) \
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1513 do { \
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
1514 PyObject *o = PyString_FromString(str); \
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1515 if (o != NULL) \
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1516 PyList_Append(list, o); \
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1517 Py_XDECREF(o); \
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1518 } while (0)
27301
5a975e82d70f SF # 669553, fix memory (ref) leaks
Neal Norwitz <nnorwitz@gmail.com>
parents: 26109
diff changeset
1519
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1520 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
1521 int i;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1522 PyObject *rc = PyList_New(0);
37067
1f4549865aad Fix some missing checks after PyTuple_New, PyList_New, PyDict_New
Georg Brandl <georg@python.org>
parents: 36891
diff changeset
1523 if (!rc)
1f4549865aad Fix some missing checks after PyTuple_New, PyList_New, PyDict_New
Georg Brandl <georg@python.org>
parents: 36891
diff changeset
1524 return NULL;
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1525 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
1526 PyObject *o = get_handler_name(&handler_info[i]);
5a975e82d70f SF # 669553, fix memory (ref) leaks
Neal Norwitz <nnorwitz@gmail.com>
parents: 26109
diff changeset
1527 if (o != NULL)
5a975e82d70f SF # 669553, fix memory (ref) leaks
Neal Norwitz <nnorwitz@gmail.com>
parents: 26109
diff changeset
1528 PyList_Append(rc, o);
5a975e82d70f SF # 669553, fix memory (ref) leaks
Neal Norwitz <nnorwitz@gmail.com>
parents: 26109
diff changeset
1529 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
1530 }
27301
5a975e82d70f SF # 669553, fix memory (ref) leaks
Neal Norwitz <nnorwitz@gmail.com>
parents: 26109
diff changeset
1531 APPEND(rc, "ErrorCode");
5a975e82d70f SF # 669553, fix memory (ref) leaks
Neal Norwitz <nnorwitz@gmail.com>
parents: 26109
diff changeset
1532 APPEND(rc, "ErrorLineNumber");
5a975e82d70f SF # 669553, fix memory (ref) leaks
Neal Norwitz <nnorwitz@gmail.com>
parents: 26109
diff changeset
1533 APPEND(rc, "ErrorColumnNumber");
5a975e82d70f SF # 669553, fix memory (ref) leaks
Neal Norwitz <nnorwitz@gmail.com>
parents: 26109
diff changeset
1534 APPEND(rc, "ErrorByteIndex");
33279
b25cb2045dac Patch #1014930. Expose current parse location to XMLParser.
Dave Cole <djc@object-craft.com.au>
parents: 33113
diff changeset
1535 APPEND(rc, "CurrentLineNumber");
b25cb2045dac Patch #1014930. Expose current parse location to XMLParser.
Dave Cole <djc@object-craft.com.au>
parents: 33113
diff changeset
1536 APPEND(rc, "CurrentColumnNumber");
b25cb2045dac Patch #1014930. Expose current parse location to XMLParser.
Dave Cole <djc@object-craft.com.au>
parents: 33113
diff changeset
1537 APPEND(rc, "CurrentByteIndex");
27301
5a975e82d70f SF # 669553, fix memory (ref) leaks
Neal Norwitz <nnorwitz@gmail.com>
parents: 26109
diff changeset
1538 APPEND(rc, "buffer_size");
5a975e82d70f SF # 669553, fix memory (ref) leaks
Neal Norwitz <nnorwitz@gmail.com>
parents: 26109
diff changeset
1539 APPEND(rc, "buffer_text");
5a975e82d70f SF # 669553, fix memory (ref) leaks
Neal Norwitz <nnorwitz@gmail.com>
parents: 26109
diff changeset
1540 APPEND(rc, "buffer_used");
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1541 APPEND(rc, "namespace_prefixes");
27301
5a975e82d70f SF # 669553, fix memory (ref) leaks
Neal Norwitz <nnorwitz@gmail.com>
parents: 26109
diff changeset
1542 APPEND(rc, "ordered_attributes");
5a975e82d70f SF # 669553, fix memory (ref) leaks
Neal Norwitz <nnorwitz@gmail.com>
parents: 26109
diff changeset
1543 APPEND(rc, "returns_unicode");
5a975e82d70f SF # 669553, fix memory (ref) leaks
Neal Norwitz <nnorwitz@gmail.com>
parents: 26109
diff changeset
1544 APPEND(rc, "specified_attributes");
5a975e82d70f SF # 669553, fix memory (ref) leaks
Neal Norwitz <nnorwitz@gmail.com>
parents: 26109
diff changeset
1545 APPEND(rc, "intern");
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1546
27301
5a975e82d70f SF # 669553, fix memory (ref) leaks
Neal Norwitz <nnorwitz@gmail.com>
parents: 26109
diff changeset
1547 #undef APPEND
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1548 return rc;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1549 }
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1550 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
1551 }
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1552
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1553 static int
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1554 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
1555 {
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1556 int handlernum = handlername2int(name);
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1557 if (handlernum >= 0) {
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1558 xmlhandler c_handler = NULL;
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1559 PyObject *temp = self->handlers[handlernum];
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1560
39009
500ae952150b - back out Expat change; the final fix to Expat will be different
Fred Drake <fdrake@acm.org>
parents: 38489
diff changeset
1561 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
1562 /* 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
1563 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
1564 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
1565 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
1566 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
1567 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
1568 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
1569 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
1570 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
1571 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
1572 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
1573 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
1574 c_handler = noop_character_data_handler;
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1575 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
1576 }
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1577 else if (v != NULL) {
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1578 Py_INCREF(v);
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1579 c_handler = handler_info[handlernum].handler;
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1580 }
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1581 self->handlers[handlernum] = v;
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1582 Py_XDECREF(temp);
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1583 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
1584 return 1;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1585 }
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1586 return 0;
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1587 }
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1588
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1589 static int
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1590 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
1591 {
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1592 /* 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
1593 if (v == NULL) {
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1594 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
1595 return -1;
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1596 }
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1597 if (strcmp(name, "buffer_text") == 0) {
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1598 if (PyObject_IsTrue(v)) {
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1599 if (self->buffer == NULL) {
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1600 self->buffer = malloc(self->buffer_size);
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1601 if (self->buffer == NULL) {
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1602 PyErr_NoMemory();
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1603 return -1;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1604 }
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1605 self->buffer_used = 0;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1606 }
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1607 }
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1608 else if (self->buffer != NULL) {
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1609 if (flush_character_buffer(self) < 0)
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1610 return -1;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1611 free(self->buffer);
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1612 self->buffer = NULL;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1613 }
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1614 return 0;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1615 }
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1616 if (strcmp(name, "namespace_prefixes") == 0) {
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1617 if (PyObject_IsTrue(v))
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1618 self->ns_prefixes = 1;
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1619 else
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1620 self->ns_prefixes = 0;
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1621 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
1622 return 0;
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1623 }
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1624 if (strcmp(name, "ordered_attributes") == 0) {
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1625 if (PyObject_IsTrue(v))
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1626 self->ordered_attributes = 1;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1627 else
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1628 self->ordered_attributes = 0;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1629 return 0;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1630 }
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1631 if (strcmp(name, "returns_unicode") == 0) {
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1632 if (PyObject_IsTrue(v)) {
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18854
diff changeset
1633 #ifndef Py_USING_UNICODE
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1634 PyErr_SetString(PyExc_ValueError,
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1635 "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
1636 return -1;
13025
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
1637 #else
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1638 self->returns_unicode = 1;
13025
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
1639 #endif
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1640 }
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1641 else
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1642 self->returns_unicode = 0;
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1643 return 0;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1644 }
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1645 if (strcmp(name, "specified_attributes") == 0) {
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1646 if (PyObject_IsTrue(v))
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1647 self->specified_attributes = 1;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1648 else
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1649 self->specified_attributes = 0;
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1650 return 0;
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
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
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1653 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
1654 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
1655 if (!PyInt_Check(v)) {
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1656 PyErr_SetString(PyExc_TypeError, "buffer_size must be an integer");
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1657 return -1;
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1658 }
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1659
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1660 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
1661 /* 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
1662 if (new_buffer_size == self->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
1663 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
1664 }
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1665
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1666 if (new_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
1667 PyErr_SetString(PyExc_ValueError, "buffer_size must be greater than zero");
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1668 return -1;
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1669 }
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1670
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1671 /* 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
1672 if (new_buffer_size > INT_MAX) {
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1673 char errmsg[100];
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1674 sprintf(errmsg, "buffer_size must not be greater than %i", INT_MAX);
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1675 PyErr_SetString(PyExc_ValueError, errmsg);
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1676 return -1;
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1677 }
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1678
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1679 if (self->buffer != NULL) {
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1680 /* there is already a buffer */
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1681 if (self->buffer_used != 0) {
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1682 flush_character_buffer(self);
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1683 }
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1684 /* free existing buffer */
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1685 free(self->buffer);
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1686 }
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1687 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
1688 if (self->buffer == NULL) {
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1689 PyErr_NoMemory();
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1690 return -1;
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1691 }
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1692 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
1693 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
1694 }
88d76b9206e6 Patch 1137: allow assigning to .buffer_size attribute of PyExpat.parser objects
Andrew M. Kuchling <amk@amk.ca>
parents: 44350
diff changeset
1695
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1696 if (strcmp(name, "CharacterDataHandler") == 0) {
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1697 /* 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
1698 * 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
1699 * "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
1700 * happen.
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1701 */
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1702 if (flush_character_buffer(self) < 0)
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1703 return -1;
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
1704 }
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1705 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
1706 return 0;
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1707 }
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1708 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
1709 return -1;
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1710 }
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1711
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1712 #ifdef WITH_CYCLE_GC
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1713 static int
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1714 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
1715 {
37762
a39cc84ff185 err is no longer used
Neal Norwitz <nnorwitz@gmail.com>
parents: 37756
diff changeset
1716 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
1717 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
1718 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
1719 return 0;
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1720 }
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1721
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1722 static int
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1723 xmlparse_clear(xmlparseobject *op)
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1724 {
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
1725 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
1726 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
1727 return 0;
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1728 }
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1729 #endif
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
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(Xmlparsetype__doc__, "XML parser");
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1732
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1733 static PyTypeObject Xmlparsetype = {
42333
6620a510e9a9 PEP 3123: Provide forward compatibility with Python 3.0, while keeping
Martin v. Löwis <martin@v.loewis.de>
parents: 39009
diff changeset
1734 PyVarObject_HEAD_INIT(NULL, 0)
21313
91dd223829c6 Patch supplied by Burton Radons for his own SF bug #487390: Modifying
Guido van Rossum <guido@python.org>
parents: 21073
diff changeset
1735 "pyexpat.xmlparser", /*tp_name*/
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1736 sizeof(xmlparseobject) + PyGC_HEAD_SIZE,/*tp_basicsize*/
13025
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
1737 0, /*tp_itemsize*/
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
1738 /* methods */
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
1739 (destructor)xmlparse_dealloc, /*tp_dealloc*/
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
1740 (printfunc)0, /*tp_print*/
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
1741 (getattrfunc)xmlparse_getattr, /*tp_getattr*/
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
1742 (setattrfunc)xmlparse_setattr, /*tp_setattr*/
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
1743 (cmpfunc)0, /*tp_compare*/
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
1744 (reprfunc)0, /*tp_repr*/
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
1745 0, /*tp_as_number*/
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
1746 0, /*tp_as_sequence*/
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
1747 0, /*tp_as_mapping*/
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
1748 (hashfunc)0, /*tp_hash*/
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
1749 (ternaryfunc)0, /*tp_call*/
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
1750 (reprfunc)0, /*tp_str*/
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1751 0, /* tp_getattro */
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1752 0, /* tp_setattro */
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1753 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
1754 #ifdef Py_TPFLAGS_HAVE_GC
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1755 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
1756 #else
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1757 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
1758 #endif
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1759 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
1760 #ifdef WITH_CYCLE_GC
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1761 (traverseproc)xmlparse_traverse, /* tp_traverse */
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1762 (inquiry)xmlparse_clear /* tp_clear */
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1763 #else
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1764 0, 0
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1765 #endif
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1766 };
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1767
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1768 /* End of code for xmlparser objects */
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1769 /* -------------------------------------------------------- */
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1770
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22421
diff changeset
1771 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
1772 "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
1773 Return a new XML parser object.");
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1774
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1775 static PyObject *
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1776 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
1777 {
17623
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1778 char *encoding = NULL;
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1779 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
1780 PyObject *intern = NULL;
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1781 PyObject *result;
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1782 int intern_decref = 0;
36675
dba6494735d0 Revert backwards-incompatible const changes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
1783 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
1784 "intern", NULL};
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1785
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1786 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
1787 &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
1788 return NULL;
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1789 if (namespace_separator != NULL
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1790 && strlen(namespace_separator) > 1) {
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1791 PyErr_SetString(PyExc_ValueError,
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1792 "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
1793 " character, omitted, or None");
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1794 return NULL;
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1795 }
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1796 /* 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
1797 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
1798 if (intern == Py_None)
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1799 intern = NULL;
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1800 else if (intern == NULL) {
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1801 intern = PyDict_New();
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1802 if (!intern)
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1803 return NULL;
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1804 intern_decref = 1;
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1805 }
24027
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1806 else if (!PyDict_Check(intern)) {
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1807 PyErr_SetString(PyExc_TypeError, "intern must be a dictionary");
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1808 return NULL;
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1809 }
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1810
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1811 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
1812 if (intern_decref) {
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1813 Py_DECREF(intern);
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1814 }
34b8cdbbd8fe Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents: 23832
diff changeset
1815 return result;
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1816 }
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1817
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22421
diff changeset
1818 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
1819 "ErrorString(errno) -> string\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22421
diff changeset
1820 Returns string error for given number.");
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1821
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1822 static PyObject *
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1823 pyexpat_ErrorString(PyObject *self, PyObject *args)
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1824 {
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1825 long code = 0;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1826
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1827 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
1828 return NULL;
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1829 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
1830 }
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1831
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1832 /* List of methods defined in the module */
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1833
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1834 static struct PyMethodDef pyexpat_methods[] = {
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1835 {"ParserCreate", (PyCFunction)pyexpat_ParserCreate,
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1836 METH_VARARGS|METH_KEYWORDS, pyexpat_ParserCreate__doc__},
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1837 {"ErrorString", (PyCFunction)pyexpat_ErrorString,
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1838 METH_VARARGS, pyexpat_ErrorString__doc__},
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1839
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1840 {NULL, (PyCFunction)NULL, 0, NULL} /* sentinel */
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1841 };
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1842
13025
58661a557dc6 Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents: 12576
diff changeset
1843 /* Module docstring */
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1844
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22421
diff changeset
1845 PyDoc_STRVAR(pyexpat_module_documentation,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 22421
diff changeset
1846 "Python wrapper for Expat parser.");
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1847
17219
3f912fb8c180 get_version_string(): New function -- returns a Python string object that
Fred Drake <fdrake@acm.org>
parents: 17034
diff changeset
1848 /* Return a Python string that represents the version number without the
3f912fb8c180 get_version_string(): New function -- returns a Python string object that
Fred Drake <fdrake@acm.org>
parents: 17034
diff changeset
1849 * extra cruft added by revision control, even if the right options were
3f912fb8c180 get_version_string(): New function -- returns a Python string object that
Fred Drake <fdrake@acm.org>
parents: 17034
diff changeset
1850 * given to the "cvs export" command to make it not include the extra
3f912fb8c180 get_version_string(): New function -- returns a Python string object that
Fred Drake <fdrake@acm.org>
parents: 17034
diff changeset
1851 * cruft.
3f912fb8c180 get_version_string(): New function -- returns a Python string object that
Fred Drake <fdrake@acm.org>
parents: 17034
diff changeset
1852 */
3f912fb8c180 get_version_string(): New function -- returns a Python string object that
Fred Drake <fdrake@acm.org>
parents: 17034
diff changeset
1853 static PyObject *
3f912fb8c180 get_version_string(): New function -- returns a Python string object that
Fred Drake <fdrake@acm.org>
parents: 17034
diff changeset
1854 get_version_string(void)
3f912fb8c180 get_version_string(): New function -- returns a Python string object that
Fred Drake <fdrake@acm.org>
parents: 17034
diff changeset
1855 {
3f912fb8c180 get_version_string(): New function -- returns a Python string object that
Fred Drake <fdrake@acm.org>
parents: 17034
diff changeset
1856 static char *rcsid = "$Revision$";
3f912fb8c180 get_version_string(): New function -- returns a Python string object that
Fred Drake <fdrake@acm.org>
parents: 17034
diff changeset
1857 char *rev = rcsid;
3f912fb8c180 get_version_string(): New function -- returns a Python string object that
Fred Drake <fdrake@acm.org>
parents: 17034
diff changeset
1858 int i = 0;
3f912fb8c180 get_version_string(): New function -- returns a Python string object that
Fred Drake <fdrake@acm.org>
parents: 17034
diff changeset
1859
36090
8cb686dd6e64 Fix SF bug #1072182, problems with signed characters.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36019
diff changeset
1860 while (!isdigit(Py_CHARMASK(*rev)))
17219
3f912fb8c180 get_version_string(): New function -- returns a Python string object that
Fred Drake <fdrake@acm.org>
parents: 17034
diff changeset
1861 ++rev;
3f912fb8c180 get_version_string(): New function -- returns a Python string object that
Fred Drake <fdrake@acm.org>
parents: 17034
diff changeset
1862 while (rev[i] != ' ' && rev[i] != '\0')
3f912fb8c180 get_version_string(): New function -- returns a Python string object that
Fred Drake <fdrake@acm.org>
parents: 17034
diff changeset
1863 ++i;
3f912fb8c180 get_version_string(): New function -- returns a Python string object that
Fred Drake <fdrake@acm.org>
parents: 17034
diff changeset
1864
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
1865 return PyString_FromStringAndSize(rev, i);
17219
3f912fb8c180 get_version_string(): New function -- returns a Python string object that
Fred Drake <fdrake@acm.org>
parents: 17034
diff changeset
1866 }
3f912fb8c180 get_version_string(): New function -- returns a Python string object that
Fred Drake <fdrake@acm.org>
parents: 17034
diff changeset
1867
17623
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1868 /* 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
1869
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1870 #ifndef MODULE_NAME
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1871 #define MODULE_NAME "pyexpat"
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1872 #endif
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1873
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1874 #ifndef MODULE_INITFUNC
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1875 #define MODULE_INITFUNC initpyexpat
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1876 #endif
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
1877
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1878 #ifndef PyMODINIT_FUNC
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1879 # ifdef MS_WINDOWS
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1880 # define PyMODINIT_FUNC __declspec(dllexport) void
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1881 # else
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1882 # define PyMODINIT_FUNC void
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1883 # endif
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1884 #endif
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1885
24315
a8df0c0be242 Land Patch [ 566100 ] Rationalize DL_IMPORT and DL_EXPORT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 24283
diff changeset
1886 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
1887
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1888 PyMODINIT_FUNC
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1889 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
1890 {
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1891 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
1892 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
1893 PyObject *errors_module;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1894 PyObject *modelmod_name;
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1895 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
1896 PyObject *sys_modules;
36018
c253e993df8a renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents: 36017
diff changeset
1897 static struct PyExpat_CAPI capi;
c253e993df8a renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents: 36017
diff changeset
1898 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
1899
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1900 if (errmod_name == NULL)
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1901 return;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
1902 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
1903 if (modelmod_name == NULL)
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1904 return;
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1905
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
1906 Py_TYPE(&Xmlparsetype) = &PyType_Type;
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1907
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1908 /* 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
1909 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
1910 pyexpat_module_documentation);
36324
1af7f719ed28 Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36090
diff changeset
1911 if (m == NULL)
1af7f719ed28 Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36090
diff changeset
1912 return;
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1913
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1914 /* 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
1915 if (ErrorObject == NULL) {
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
1916 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
1917 NULL, NULL);
16601
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
1918 if (ErrorObject == NULL)
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
1919 return;
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
1920 }
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
1921 Py_INCREF(ErrorObject);
14788
179e098238e8 Change the name of the exception from "pyexpat.error" to
Fred Drake <fdrake@acm.org>
parents: 14755
diff changeset
1922 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
1923 Py_INCREF(ErrorObject);
0b455a428967 xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents: 16476
diff changeset
1924 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
1925 Py_INCREF(&Xmlparsetype);
ab3438cf1f3e ParserCreate(): Added test that the namespace_separator value, if given,
Fred Drake <fdrake@acm.org>
parents: 14932
diff changeset
1926 PyModule_AddObject(m, "XMLParserType", (PyObject *) &Xmlparsetype);
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1927
17219
3f912fb8c180 get_version_string(): New function -- returns a Python string object that
Fred Drake <fdrake@acm.org>
parents: 17034
diff changeset
1928 PyModule_AddObject(m, "__version__", get_version_string());
15642
19c8a2d3807d When using the latest & greatest version of Expat (currently in the Expat
Fred Drake <fdrake@acm.org>
parents: 15600
diff changeset
1929 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
1930 (char *) XML_ExpatVersion());
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1931 {
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1932 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
1933 PyModule_AddObject(m, "version_info",
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1934 Py_BuildValue("(iii)", info.major,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1935 info.minor, info.micro));
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1936 }
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18854
diff changeset
1937 #ifdef Py_USING_UNICODE
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1938 init_template_buffer();
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
1939 #endif
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1940 /* 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
1941 compiled, this should check and set native_encoding
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
1942 appropriately.
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
1943 */
14788
179e098238e8 Change the name of the exception from "pyexpat.error" to
Fred Drake <fdrake@acm.org>
parents: 14755
diff changeset
1944 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
1945
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1946 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
1947 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
1948 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
1949 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
1950 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
1951 if (errors_module != NULL) {
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1952 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
1953 /* 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
1954 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
1955 }
91deadfdae36 Remove the Py_FatalError() from initpyexpat(); the Guido has decreed
Fred Drake <fdrake@acm.org>
parents: 13654
diff changeset
1956 }
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
1957 Py_DECREF(errmod_name);
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1958 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
1959 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
1960 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
1961 if (model_module != NULL) {
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1962 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
1963 /* 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
1964 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
1965 }
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1966 }
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1967 Py_DECREF(modelmod_name);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
1968 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
1969 /* 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
1970 return;
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1971
27322
88bf10313584 Conditionalize features not found in PyXML 1.95.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 27321
diff changeset
1972 #if XML_COMBINED_VERSION > 19505
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1973 {
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1974 const XML_Feature *features = XML_GetFeatureList();
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1975 PyObject *list = PyList_New(0);
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1976 if (list == NULL)
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1977 /* just ignore it */
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1978 PyErr_Clear();
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1979 else {
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1980 int i = 0;
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1981 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
1982 int ok;
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1983 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
1984 features[i].value);
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1985 if (item == NULL) {
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1986 Py_DECREF(list);
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1987 list = NULL;
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1988 break;
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1989 }
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1990 ok = PyList_Append(list, item);
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1991 Py_DECREF(item);
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1992 if (ok < 0) {
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1993 PyErr_Clear();
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1994 break;
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1995 }
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1996 }
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1997 if (list != NULL)
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1998 PyModule_AddObject(m, "features", list);
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
1999 }
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
2000 }
27322
88bf10313584 Conditionalize features not found in PyXML 1.95.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 27321
diff changeset
2001 #endif
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
2002
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
2003 #define MYCONST(name) \
14788
179e098238e8 Change the name of the exception from "pyexpat.error" to
Fred Drake <fdrake@acm.org>
parents: 14755
diff changeset
2004 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
2005 (char*)XML_ErrorString(name))
13344
c3029f276047 pyexpat.errors is a *strange* module!
Fred Drake <fdrake@acm.org>
parents: 13340
diff changeset
2006
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2007 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
2008 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
2009 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
2010 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
2011 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
2012 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
2013 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
2014 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
2015 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
2016 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
2017 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
2018 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
2019 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
2020 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
2021 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
2022 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
2023 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
2024 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
2025 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
2026 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
2027 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
2028 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
2029 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
2030 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
2031 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
2032 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
2033 /* 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
2034 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
2035 /* 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
2036 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
2037 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
2038 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
2039 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
2040 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
2041 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
2042 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
2043 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
2044 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
2045 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
2046
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2047 PyModule_AddStringConstant(errors_module, "__doc__",
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2048 "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
2049
14788
179e098238e8 Change the name of the exception from "pyexpat.error" to
Fred Drake <fdrake@acm.org>
parents: 14755
diff changeset
2050 #undef MYCONST
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
2051
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2052 #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
2053 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
2054 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
2055 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
2056 #undef MYCONST
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
2057
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2058 #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
2059 PyModule_AddStringConstant(model_module, "__doc__",
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2060 "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
2061
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2062 MYCONST(XML_CTYPE_EMPTY);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2063 MYCONST(XML_CTYPE_ANY);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2064 MYCONST(XML_CTYPE_MIXED);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2065 MYCONST(XML_CTYPE_NAME);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2066 MYCONST(XML_CTYPE_CHOICE);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2067 MYCONST(XML_CTYPE_SEQ);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2068
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2069 MYCONST(XML_CQUANT_NONE);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2070 MYCONST(XML_CQUANT_OPT);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2071 MYCONST(XML_CQUANT_REP);
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2072 MYCONST(XML_CQUANT_PLUS);
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
2073 #undef MYCONST
36017
ed347c436d58 added cobject-based expat dispatch mechanism to pyexpat
Fredrik Lundh <fredrik@pythonware.com>
parents: 35999
diff changeset
2074
ed347c436d58 added cobject-based expat dispatch mechanism to pyexpat
Fredrik Lundh <fredrik@pythonware.com>
parents: 35999
diff changeset
2075 /* initialize pyexpat dispatch table */
36018
c253e993df8a renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents: 36017
diff changeset
2076 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
2077 capi.magic = PyExpat_CAPI_MAGIC;
36018
c253e993df8a renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents: 36017
diff changeset
2078 capi.MAJOR_VERSION = XML_MAJOR_VERSION;
c253e993df8a renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents: 36017
diff changeset
2079 capi.MINOR_VERSION = XML_MINOR_VERSION;
c253e993df8a renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents: 36017
diff changeset
2080 capi.MICRO_VERSION = XML_MICRO_VERSION;
c253e993df8a renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents: 36017
diff changeset
2081 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
2082 capi.GetErrorCode = XML_GetErrorCode;
68817315b74c moved magic into structure (mainly to simplify the client code)
Fredrik Lundh <fredrik@pythonware.com>
parents: 36018
diff changeset
2083 capi.GetErrorColumnNumber = XML_GetErrorColumnNumber;
68817315b74c moved magic into structure (mainly to simplify the client code)
Fredrik Lundh <fredrik@pythonware.com>
parents: 36018
diff changeset
2084 capi.GetErrorLineNumber = XML_GetErrorLineNumber;
36018
c253e993df8a renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents: 36017
diff changeset
2085 capi.Parse = XML_Parse;
c253e993df8a renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents: 36017
diff changeset
2086 capi.ParserCreate_MM = XML_ParserCreate_MM;
c253e993df8a renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents: 36017
diff changeset
2087 capi.ParserFree = XML_ParserFree;
c253e993df8a renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents: 36017
diff changeset
2088 capi.SetCharacterDataHandler = XML_SetCharacterDataHandler;
c253e993df8a renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents: 36017
diff changeset
2089 capi.SetCommentHandler = XML_SetCommentHandler;
c253e993df8a renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents: 36017
diff changeset
2090 capi.SetDefaultHandlerExpand = XML_SetDefaultHandlerExpand;
c253e993df8a renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents: 36017
diff changeset
2091 capi.SetElementHandler = XML_SetElementHandler;
c253e993df8a renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents: 36017
diff changeset
2092 capi.SetNamespaceDeclHandler = XML_SetNamespaceDeclHandler;
c253e993df8a renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents: 36017
diff changeset
2093 capi.SetProcessingInstructionHandler = XML_SetProcessingInstructionHandler;
c253e993df8a renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents: 36017
diff changeset
2094 capi.SetUnknownEncodingHandler = XML_SetUnknownEncodingHandler;
c253e993df8a renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents: 36017
diff changeset
2095 capi.SetUserData = XML_SetUserData;
36017
ed347c436d58 added cobject-based expat dispatch mechanism to pyexpat
Fredrik Lundh <fredrik@pythonware.com>
parents: 35999
diff changeset
2096
ed347c436d58 added cobject-based expat dispatch mechanism to pyexpat
Fredrik Lundh <fredrik@pythonware.com>
parents: 35999
diff changeset
2097 /* export as cobject */
36019
68817315b74c moved magic into structure (mainly to simplify the client code)
Fredrik Lundh <fredrik@pythonware.com>
parents: 36018
diff changeset
2098 capi_object = PyCObject_FromVoidPtr(&capi, NULL);
36018
c253e993df8a renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents: 36017
diff changeset
2099 if (capi_object)
c253e993df8a renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents: 36017
diff changeset
2100 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
2101 }
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
2102
14186
e921228af435 initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents: 14169
diff changeset
2103 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
2104 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
2105 {
17623
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
2106 int i = 0;
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
2107 PyObject *temp;
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
2108
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
2109 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
2110 if (initial)
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
2111 self->handlers[i] = NULL;
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
2112 else {
17623
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
2113 temp = self->handlers[i];
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
2114 self->handlers[i] = NULL;
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
2115 Py_XDECREF(temp);
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
2116 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
2117 }
1686080a7c6c ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents: 17219
diff changeset
2118 }
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
2119 }
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
2120
24283
c0a67a1cab09 Removed more stray instances of statichere, but left _sre.c alone.
Tim Peters <tim.peters@gmail.com>
parents: 24280
diff changeset
2121 static struct HandlerInfo handler_info[] = {
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
2122 {"StartElementHandler",
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
2123 (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
2124 (xmlhandler)my_StartElementHandler},
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
2125 {"EndElementHandler",
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
2126 (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
2127 (xmlhandler)my_EndElementHandler},
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
2128 {"ProcessingInstructionHandler",
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2129 (xmlhandlersetter)XML_SetProcessingInstructionHandler,
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2130 (xmlhandler)my_ProcessingInstructionHandler},
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
2131 {"CharacterDataHandler",
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2132 (xmlhandlersetter)XML_SetCharacterDataHandler,
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2133 (xmlhandler)my_CharacterDataHandler},
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
2134 {"UnparsedEntityDeclHandler",
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2135 (xmlhandlersetter)XML_SetUnparsedEntityDeclHandler,
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
2136 (xmlhandler)my_UnparsedEntityDeclHandler},
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
2137 {"NotationDeclHandler",
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2138 (xmlhandlersetter)XML_SetNotationDeclHandler,
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
2139 (xmlhandler)my_NotationDeclHandler},
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
2140 {"StartNamespaceDeclHandler",
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
2141 (xmlhandlersetter)XML_SetStartNamespaceDeclHandler,
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
2142 (xmlhandler)my_StartNamespaceDeclHandler},
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
2143 {"EndNamespaceDeclHandler",
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
2144 (xmlhandlersetter)XML_SetEndNamespaceDeclHandler,
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
2145 (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
2146 {"CommentHandler",
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2147 (xmlhandlersetter)XML_SetCommentHandler,
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2148 (xmlhandler)my_CommentHandler},
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2149 {"StartCdataSectionHandler",
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
2150 (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
2151 (xmlhandler)my_StartCdataSectionHandler},
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2152 {"EndCdataSectionHandler",
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
2153 (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
2154 (xmlhandler)my_EndCdataSectionHandler},
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2155 {"DefaultHandler",
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2156 (xmlhandlersetter)XML_SetDefaultHandler,
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2157 (xmlhandler)my_DefaultHandler},
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2158 {"DefaultHandlerExpand",
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2159 (xmlhandlersetter)XML_SetDefaultHandlerExpand,
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2160 (xmlhandler)my_DefaultHandlerExpandHandler},
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2161 {"NotStandaloneHandler",
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2162 (xmlhandlersetter)XML_SetNotStandaloneHandler,
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2163 (xmlhandler)my_NotStandaloneHandler},
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2164 {"ExternalEntityRefHandler",
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2165 (xmlhandlersetter)XML_SetExternalEntityRefHandler,
24040
a78d41ee9474 Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents: 24037
diff changeset
2166 (xmlhandler)my_ExternalEntityRefHandler},
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
2167 {"StartDoctypeDeclHandler",
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
2168 (xmlhandlersetter)XML_SetStartDoctypeDeclHandler,
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
2169 (xmlhandler)my_StartDoctypeDeclHandler},
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
2170 {"EndDoctypeDeclHandler",
24037
2c2245aacef8 pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents: 24027
diff changeset
2171 (xmlhandlersetter)XML_SetEndDoctypeDeclHandler,
16076
eabd008b36ee Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents: 15703
diff changeset
2172 (xmlhandler)my_EndDoctypeDeclHandler},
16476
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2173 {"EntityDeclHandler",
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2174 (xmlhandlersetter)XML_SetEntityDeclHandler,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2175 (xmlhandler)my_EntityDeclHandler},
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2176 {"XmlDeclHandler",
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2177 (xmlhandlersetter)XML_SetXmlDeclHandler,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2178 (xmlhandler)my_XmlDeclHandler},
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2179 {"ElementDeclHandler",
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2180 (xmlhandlersetter)XML_SetElementDeclHandler,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2181 (xmlhandler)my_ElementDeclHandler},
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2182 {"AttlistDeclHandler",
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2183 (xmlhandlersetter)XML_SetAttlistDeclHandler,
f7b167c83318 set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents: 16463
diff changeset
2184 (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
2185 #if XML_COMBINED_VERSION >= 19504
27321
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
2186 {"SkippedEntityHandler",
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
2187 (xmlhandlersetter)XML_SetSkippedEntityHandler,
299ef2dabb52 Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents: 27301
diff changeset
2188 (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
2189 #endif
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
2190
13568
ac2bb7708320 Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents: 13559
diff changeset
2191 {NULL, NULL, NULL} /* sentinel */
12182
c888792de6a7 Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
2192 };