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