Mercurial > cpython-lru_cache-weakref
annotate Modules/pyexpat.c @ 78069:a8aa77458e12 3.2
Add c_size_t and c_ssize_t to the ctypes summary table.
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Thu, 12 Jul 2012 20:31:50 +0200 |
| parents | d238a3d3bf43 |
| children | 56dc7b09f390 3945d73ad525 |
| 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 |
|
29605
e43126c470a7
Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27586
diff
changeset
|
11 #define FIX_TRACE |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18854
diff
changeset
|
12 |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
13 enum HandlerTypes { |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
14 StartElement, |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
15 EndElement, |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
16 ProcessingInstruction, |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
17 CharacterData, |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
18 UnparsedEntityDecl, |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
19 NotationDecl, |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
20 StartNamespaceDecl, |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
21 EndNamespaceDecl, |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
22 Comment, |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
23 StartCdataSection, |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
24 EndCdataSection, |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
25 Default, |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
26 DefaultHandlerExpand, |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
27 NotStandalone, |
|
16076
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
28 ExternalEntityRef, |
|
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
29 StartDoctypeDecl, |
|
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
30 EndDoctypeDecl, |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
31 EntityDecl, |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
32 XmlDecl, |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
33 ElementDecl, |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
34 AttlistDecl, |
|
27322
88bf10313584
Conditionalize features not found in PyXML 1.95.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
27321
diff
changeset
|
35 #if XML_COMBINED_VERSION >= 19504 |
|
27321
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
36 SkippedEntity, |
|
27322
88bf10313584
Conditionalize features not found in PyXML 1.95.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
27321
diff
changeset
|
37 #endif |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
38 _DummyDecl |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
39 }; |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
40 |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
41 static PyObject *ErrorObject; |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
42 |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
43 /* ----------------------------------------------------- */ |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
44 |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
45 /* Declarations for objects of type xmlparser */ |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
46 |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
47 typedef struct { |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
48 PyObject_HEAD |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
49 |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
50 XML_Parser itself; |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
51 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
|
52 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
|
53 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
|
54 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
|
55 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
|
56 /* NULL if not enabled */ |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
57 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
|
58 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
|
59 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
|
60 PyObject **handlers; |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
61 } xmlparseobject; |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
62 |
|
24040
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
63 #define CHARACTER_DATA_BUFFER_SIZE 8192 |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
64 |
|
24280
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24079
diff
changeset
|
65 static PyTypeObject Xmlparsetype; |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
66 |
|
25395
9ca609f8bdf2
Be more careful with the type of the xmlhandlersetter; it takes an
Fred Drake <fdrake@acm.org>
parents:
25092
diff
changeset
|
67 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
|
68 typedef void* xmlhandler; |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
69 |
|
13025
58661a557dc6
Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents:
12576
diff
changeset
|
70 struct HandlerInfo { |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
71 const char *name; |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
72 xmlhandlersetter setter; |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
73 xmlhandler handler; |
|
16076
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
74 PyCodeObject *tb_code; |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
75 PyObject *nameobj; |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
76 }; |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
77 |
|
24280
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24079
diff
changeset
|
78 static struct HandlerInfo handler_info[64]; |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
79 |
|
16601
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
80 /* 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
|
81 * false on an exception. |
|
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
82 */ |
|
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
83 static int |
|
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
84 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
|
85 { |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
44046
diff
changeset
|
86 PyObject *v = PyLong_FromLong(value); |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
87 |
|
36891
a9697de5e18b
Fix logic error and DECREF reported by Coverity.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36675
diff
changeset
|
88 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
|
89 Py_XDECREF(v); |
|
16601
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
90 return 0; |
|
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
91 } |
|
32923
f1bbf147810b
Fix the reference count errors revealed by the test suite...
Michael W. Hudson <mwh@python.net>
parents:
30683
diff
changeset
|
92 Py_DECREF(v); |
|
16601
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
93 return 1; |
|
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
94 } |
|
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
95 |
|
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
96 /* 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
|
97 * information. Always returns NULL. |
|
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
98 */ |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
99 static PyObject * |
|
27321
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
100 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
|
101 { |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
102 PyObject *err; |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
103 char buffer[256]; |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
104 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
|
105 int lineno = XML_GetErrorLineNumber(parser); |
|
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
106 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
|
107 |
|
24063
e8789751a5cc
Undo usage of PyOS_snprintf (rev. 1.51 of PyXML).
Martin v. Löwis <martin@v.loewis.de>
parents:
24040
diff
changeset
|
108 /* 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
|
109 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
|
110 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
|
111 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
|
112 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
|
113 if ( err != NULL |
|
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
114 && 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
|
115 && 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
|
116 && 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
|
117 PyErr_SetObject(ErrorObject, err); |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
118 } |
|
36891
a9697de5e18b
Fix logic error and DECREF reported by Coverity.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36675
diff
changeset
|
119 Py_XDECREF(err); |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
120 return NULL; |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
121 } |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
122 |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
123 static int |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
124 have_handler(xmlparseobject *self, int type) |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
125 { |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
126 PyObject *handler = self->handlers[type]; |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
127 return handler != NULL; |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
128 } |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
129 |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
130 static PyObject * |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
131 get_handler_name(struct HandlerInfo *hinfo) |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
132 { |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
133 PyObject *name = hinfo->nameobj; |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
134 if (name == NULL) { |
| 42835 | 135 name = PyUnicode_FromString(hinfo->name); |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
136 hinfo->nameobj = name; |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
137 } |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
138 Py_XINCREF(name); |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
139 return name; |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
140 } |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
141 |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
142 |
|
13025
58661a557dc6
Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents:
12576
diff
changeset
|
143 /* 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
|
144 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
|
145 |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
146 static PyObject * |
|
24027
34b8cdbbd8fe
Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents:
23832
diff
changeset
|
147 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
|
148 { |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
149 /* 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
|
150 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
|
151 /* 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
|
152 if (str == NULL) { |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
153 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
|
154 return Py_None; |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
155 } |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
156 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
|
157 } |
|
58661a557dc6
Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents:
12576
diff
changeset
|
158 |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
159 static PyObject * |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
160 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
|
161 { |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
162 /* 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
|
163 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
|
164 /* 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
|
165 if (str == NULL) { |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
166 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
|
167 return Py_None; |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
168 } |
|
14186
e921228af435
initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents:
14169
diff
changeset
|
169 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
|
170 } |
|
58661a557dc6
Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents:
12576
diff
changeset
|
171 |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
172 /* Callback routines */ |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
173 |
|
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
|
174 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
|
175 |
|
27321
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
176 /* 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
|
177 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
|
178 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
|
179 static int |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
180 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
|
181 const XML_Char *context, |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
182 const XML_Char *base, |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
183 const XML_Char *systemId, |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
184 const XML_Char *publicId) |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
185 { |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
186 return 0; |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
187 } |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
188 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
189 /* Dummy character data handler used when an error (exception) has |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
190 been detected, and the actual parsing can be terminated early. |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
191 This is needed since character data handler can't be safely removed |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
192 from within the character data handler, but can be replaced. It is |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
193 used only from the character data handler trampoline, and must be |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
194 used right after `flag_error()` is called. */ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
195 static void |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
196 noop_character_data_handler(void *userData, const XML_Char *data, int len) |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
197 { |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
198 /* Do nothing. */ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
199 } |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
200 |
|
14186
e921228af435
initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents:
14169
diff
changeset
|
201 static void |
|
e921228af435
initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents:
14169
diff
changeset
|
202 flag_error(xmlparseobject *self) |
|
e921228af435
initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents:
14169
diff
changeset
|
203 { |
|
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
|
204 clear_handlers(self, 0); |
|
27321
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
205 XML_SetExternalEntityRefHandler(self->itself, |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
206 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
|
207 } |
|
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
208 |
|
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
209 static PyCodeObject* |
|
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
210 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
|
211 { |
|
16601
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
212 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
|
213 handler_info[slot].tb_code = |
|
55372
79718ee03986
Merged revisions 72487-72488,72879 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54812
diff
changeset
|
214 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
|
215 } |
|
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
216 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
|
217 } |
|
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
218 |
|
29605
e43126c470a7
Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27586
diff
changeset
|
219 #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
|
220 static int |
|
1c26eb768293
Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
24328
diff
changeset
|
221 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
|
222 { |
|
1c26eb768293
Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
24328
diff
changeset
|
223 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
|
224 if (!tstate->use_tracing || tstate->tracing) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
225 return 0; |
|
24533
1c26eb768293
Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
24328
diff
changeset
|
226 if (tstate->c_profilefunc != NULL) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
227 tstate->tracing++; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
228 result = tstate->c_profilefunc(tstate->c_profileobj, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
229 f, code , val); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
230 tstate->use_tracing = ((tstate->c_tracefunc != NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
231 || (tstate->c_profilefunc != NULL)); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
232 tstate->tracing--; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
233 if (result) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
234 return result; |
|
24533
1c26eb768293
Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
24328
diff
changeset
|
235 } |
|
1c26eb768293
Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
24328
diff
changeset
|
236 if (tstate->c_tracefunc != NULL) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
237 tstate->tracing++; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
238 result = tstate->c_tracefunc(tstate->c_traceobj, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
239 f, code , val); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
240 tstate->use_tracing = ((tstate->c_tracefunc != NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
241 || (tstate->c_profilefunc != NULL)); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
242 tstate->tracing--; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
243 } |
|
24533
1c26eb768293
Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
24328
diff
changeset
|
244 return result; |
|
1c26eb768293
Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
24328
diff
changeset
|
245 } |
|
29605
e43126c470a7
Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27586
diff
changeset
|
246 |
|
e43126c470a7
Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27586
diff
changeset
|
247 static int |
|
e43126c470a7
Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27586
diff
changeset
|
248 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
|
249 { |
|
e43126c470a7
Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27586
diff
changeset
|
250 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
|
251 int err; |
|
e43126c470a7
Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27586
diff
changeset
|
252 |
|
e43126c470a7
Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27586
diff
changeset
|
253 if (tstate->c_tracefunc == NULL) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
254 return 0; |
|
29605
e43126c470a7
Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27586
diff
changeset
|
255 |
|
e43126c470a7
Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27586
diff
changeset
|
256 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
|
257 if (value == NULL) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
258 value = Py_None; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
259 Py_INCREF(value); |
|
29605
e43126c470a7
Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27586
diff
changeset
|
260 } |
|
30683
3b59fa5d25b1
Simplify and speedup uses of Py_BuildValue():
Raymond Hettinger <python@rcn.com>
parents:
29957
diff
changeset
|
261 arg = PyTuple_Pack(3, type, value, traceback); |
|
29605
e43126c470a7
Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27586
diff
changeset
|
262 if (arg == NULL) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
263 PyErr_Restore(type, value, traceback); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
264 return 0; |
|
29605
e43126c470a7
Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27586
diff
changeset
|
265 } |
|
e43126c470a7
Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27586
diff
changeset
|
266 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
|
267 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
|
268 if (err == 0) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
269 PyErr_Restore(type, value, traceback); |
|
29605
e43126c470a7
Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27586
diff
changeset
|
270 else { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
271 Py_XDECREF(type); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
272 Py_XDECREF(value); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
273 Py_XDECREF(traceback); |
|
29605
e43126c470a7
Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27586
diff
changeset
|
274 } |
|
e43126c470a7
Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27586
diff
changeset
|
275 return err; |
|
e43126c470a7
Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27586
diff
changeset
|
276 } |
|
27321
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
277 #endif |
|
24533
1c26eb768293
Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
24328
diff
changeset
|
278 |
|
16076
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
279 static PyObject* |
|
33113
28e877ff74cf
make exception propogation more efficient; this avoids having Expat parse
Fred Drake <fdrake@acm.org>
parents:
32965
diff
changeset
|
280 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
|
281 xmlparseobject *self) |
|
16076
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
282 { |
|
16601
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
283 PyThreadState *tstate = PyThreadState_GET(); |
|
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
284 PyFrameObject *f; |
|
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
285 PyObject *res; |
|
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
286 |
|
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
287 if (c == NULL) |
|
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
288 return NULL; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
289 |
|
29605
e43126c470a7
Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27586
diff
changeset
|
290 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
|
291 if (f == NULL) |
|
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
292 return NULL; |
|
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
293 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
|
294 #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
|
295 if (trace_frame(tstate, f, PyTrace_CALL, Py_None) < 0) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
296 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
|
297 } |
|
27321
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
298 #endif |
|
16601
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
299 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
|
300 if (res == NULL) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
301 if (tstate->curexc_traceback == NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
302 PyTraceBack_Here(f); |
|
33113
28e877ff74cf
make exception propogation more efficient; this avoids having Expat parse
Fred Drake <fdrake@acm.org>
parents:
32965
diff
changeset
|
303 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
|
304 #ifdef FIX_TRACE |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
305 if (trace_frame_exc(tstate, f) < 0) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
306 return NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
307 } |
|
29605
e43126c470a7
Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27586
diff
changeset
|
308 } |
|
24533
1c26eb768293
Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
24328
diff
changeset
|
309 else { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
310 if (trace_frame(tstate, f, PyTrace_RETURN, res) < 0) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
311 Py_XDECREF(res); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
312 res = NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
313 } |
|
24533
1c26eb768293
Add trace_frame. Fixes #534864. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
24328
diff
changeset
|
314 } |
|
29605
e43126c470a7
Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27586
diff
changeset
|
315 #else |
|
e43126c470a7
Fix several bugs in handling of exceptions with trace function enabled.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
27586
diff
changeset
|
316 } |
|
27321
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
317 #endif |
|
16601
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
318 tstate->frame = f->f_back; |
|
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
319 Py_DECREF(f); |
|
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
320 return res; |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
321 } |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
322 |
|
24027
34b8cdbbd8fe
Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents:
23832
diff
changeset
|
323 static PyObject* |
|
34b8cdbbd8fe
Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents:
23832
diff
changeset
|
324 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
|
325 { |
|
42351
e50e33b7e0e0
SF patch# 1759016 by Joe Gregorio, who writes:
Guido van Rossum <guido@python.org>
parents:
42334
diff
changeset
|
326 PyObject *result = conv_string_to_unicode(str); |
|
24027
34b8cdbbd8fe
Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents:
23832
diff
changeset
|
327 PyObject *value; |
|
35658
a83e8df13498
Patch #1309009, Fix segfault in pyexpat when the XML document is
Neal Norwitz <nnorwitz@gmail.com>
parents:
34687
diff
changeset
|
328 /* 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
|
329 if (!result) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
330 return result; |
|
24027
34b8cdbbd8fe
Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents:
23832
diff
changeset
|
331 if (!self->intern) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
332 return result; |
|
24027
34b8cdbbd8fe
Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents:
23832
diff
changeset
|
333 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
|
334 if (!value) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
335 if (PyDict_SetItem(self->intern, result, result) == 0) |
|
24027
34b8cdbbd8fe
Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents:
23832
diff
changeset
|
336 return result; |
|
34b8cdbbd8fe
Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents:
23832
diff
changeset
|
337 else |
|
34b8cdbbd8fe
Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents:
23832
diff
changeset
|
338 return NULL; |
|
34b8cdbbd8fe
Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents:
23832
diff
changeset
|
339 } |
|
34b8cdbbd8fe
Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents:
23832
diff
changeset
|
340 Py_INCREF(value); |
|
34b8cdbbd8fe
Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents:
23832
diff
changeset
|
341 Py_DECREF(result); |
|
34b8cdbbd8fe
Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents:
23832
diff
changeset
|
342 return value; |
|
34b8cdbbd8fe
Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents:
23832
diff
changeset
|
343 } |
|
34b8cdbbd8fe
Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents:
23832
diff
changeset
|
344 |
|
24040
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
345 /* 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
|
346 * 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
|
347 */ |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
348 static int |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
349 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
|
350 { |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
351 PyObject *args; |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
352 PyObject *temp; |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
353 |
|
65621
c5aebffc9fac
Merged revisions 85536 via svnmerge from
Georg Brandl <georg@python.org>
parents:
61467
diff
changeset
|
354 if (!have_handler(self, CharacterData)) |
|
c5aebffc9fac
Merged revisions 85536 via svnmerge from
Georg Brandl <georg@python.org>
parents:
61467
diff
changeset
|
355 return -1; |
|
c5aebffc9fac
Merged revisions 85536 via svnmerge from
Georg Brandl <georg@python.org>
parents:
61467
diff
changeset
|
356 |
|
24040
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
357 args = PyTuple_New(1); |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
358 if (args == NULL) |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
359 return -1; |
|
42351
e50e33b7e0e0
SF patch# 1759016 by Joe Gregorio, who writes:
Guido van Rossum <guido@python.org>
parents:
42334
diff
changeset
|
360 temp = (conv_string_len_to_unicode(buffer, len)); |
|
24040
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
361 if (temp == NULL) { |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
362 Py_DECREF(args); |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
363 flag_error(self); |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
364 XML_SetCharacterDataHandler(self->itself, |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
365 noop_character_data_handler); |
|
24040
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
366 return -1; |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
367 } |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
368 PyTuple_SET_ITEM(args, 0, temp); |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
369 /* 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
|
370 self->in_callback = 1; |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
371 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
|
372 self->handlers[CharacterData], args, self); |
|
24040
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
373 /* 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
|
374 self->in_callback = 0; |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
375 Py_DECREF(args); |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
376 if (temp == NULL) { |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
377 flag_error(self); |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
378 XML_SetCharacterDataHandler(self->itself, |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
379 noop_character_data_handler); |
|
24040
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
380 return -1; |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
381 } |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
382 Py_DECREF(temp); |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
383 return 0; |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
384 } |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
385 |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
386 static int |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
387 flush_character_buffer(xmlparseobject *self) |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
388 { |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
389 int rc; |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
390 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
|
391 return 0; |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
392 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
|
393 self->buffer_used = 0; |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
394 return rc; |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
395 } |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
396 |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
397 static void |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
398 my_CharacterDataHandler(void *userData, const XML_Char *data, int len) |
|
24040
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
399 { |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
400 xmlparseobject *self = (xmlparseobject *) userData; |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
401 if (self->buffer == NULL) |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
402 call_character_handler(self, data, len); |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
403 else { |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
404 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
|
405 if (flush_character_buffer(self) < 0) |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
406 return; |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
407 /* 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
|
408 * 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
|
409 */ |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
410 if (!have_handler(self, CharacterData)) |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
411 return; |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
412 } |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
413 if (len > self->buffer_size) { |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
414 call_character_handler(self, data, len); |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
415 self->buffer_used = 0; |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
416 } |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
417 else { |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
418 memcpy(self->buffer + self->buffer_used, |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
419 data, len * sizeof(XML_Char)); |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
420 self->buffer_used += len; |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
421 } |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
422 } |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
423 } |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
424 |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
425 static void |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
426 my_StartElementHandler(void *userData, |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
427 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
|
428 { |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
429 xmlparseobject *self = (xmlparseobject *)userData; |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
430 |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
431 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
|
432 PyObject *container, *rv, *args; |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
433 int i, max; |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
434 |
|
24040
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
435 if (flush_character_buffer(self) < 0) |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
436 return; |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
437 /* 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
|
438 * 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
|
439 */ |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
440 if (self->specified_attributes) { |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
441 max = XML_GetSpecifiedAttributeCount(self->itself); |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
442 } |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
443 else { |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
444 max = 0; |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
445 while (atts[max] != NULL) |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
446 max += 2; |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
447 } |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
448 /* Build the container. */ |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
449 if (self->ordered_attributes) |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
450 container = PyList_New(max); |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
451 else |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
452 container = PyDict_New(); |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
453 if (container == NULL) { |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
454 flag_error(self); |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
455 return; |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
456 } |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
457 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
|
458 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
|
459 PyObject *v; |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
460 if (n == NULL) { |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
461 flag_error(self); |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
462 Py_DECREF(container); |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
463 return; |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
464 } |
|
42351
e50e33b7e0e0
SF patch# 1759016 by Joe Gregorio, who writes:
Guido van Rossum <guido@python.org>
parents:
42334
diff
changeset
|
465 v = conv_string_to_unicode((XML_Char *) atts[i+1]); |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
466 if (v == NULL) { |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
467 flag_error(self); |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
468 Py_DECREF(container); |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
469 Py_DECREF(n); |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
470 return; |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
471 } |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
472 if (self->ordered_attributes) { |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
473 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
|
474 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
|
475 } |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
476 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
|
477 flag_error(self); |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
478 Py_DECREF(n); |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
479 Py_DECREF(v); |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
480 return; |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
481 } |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
482 else { |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
483 Py_DECREF(n); |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
484 Py_DECREF(v); |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
485 } |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
486 } |
|
35658
a83e8df13498
Patch #1309009, Fix segfault in pyexpat when the XML document is
Neal Norwitz <nnorwitz@gmail.com>
parents:
34687
diff
changeset
|
487 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
|
488 if (args != NULL) |
|
a83e8df13498
Patch #1309009, Fix segfault in pyexpat when the XML document is
Neal Norwitz <nnorwitz@gmail.com>
parents:
34687
diff
changeset
|
489 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
|
490 if (args == NULL) { |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
491 Py_DECREF(container); |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
492 return; |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
493 } |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
494 /* 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
|
495 self->in_callback = 1; |
|
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
496 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
|
497 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
|
498 self->in_callback = 0; |
|
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
499 Py_DECREF(args); |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
500 if (rv == NULL) { |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
501 flag_error(self); |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
502 return; |
|
16601
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
503 } |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
504 Py_DECREF(rv); |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
505 } |
|
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 |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
508 #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
|
509 RETURN, GETUSERDATA) \ |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
510 static RC \ |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
511 my_##NAME##Handler PARAMS {\ |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
512 xmlparseobject *self = GETUSERDATA ; \ |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
513 PyObject *args = NULL; \ |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
514 PyObject *rv = NULL; \ |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
515 INIT \ |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
516 \ |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
517 if (have_handler(self, NAME)) { \ |
|
24040
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
518 if (flush_character_buffer(self) < 0) \ |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
519 return RETURN; \ |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
520 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
|
521 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
|
522 self->in_callback = 1; \ |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
523 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
|
524 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
|
525 self->in_callback = 0; \ |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
526 Py_DECREF(args); \ |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
527 if (rv == 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 return RETURN; \ |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
530 } \ |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
531 CONVERSION \ |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
532 Py_DECREF(rv); \ |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
533 } \ |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
534 return RETURN; \ |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
535 } |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
536 |
|
14186
e921228af435
initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents:
14169
diff
changeset
|
537 #define VOID_HANDLER(NAME, PARAMS, PARAM_FORMAT) \ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
538 RC_HANDLER(void, NAME, PARAMS, ;, PARAM_FORMAT, ;, ;,\ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
539 (xmlparseobject *)userData) |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
540 |
|
14186
e921228af435
initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents:
14169
diff
changeset
|
541 #define INT_HANDLER(NAME, PARAMS, PARAM_FORMAT)\ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
542 RC_HANDLER(int, NAME, PARAMS, int rc=0;, PARAM_FORMAT, \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
543 rc = PyLong_AsLong(rv);, rc, \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
544 (xmlparseobject *)userData) |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
545 |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
546 VOID_HANDLER(EndElement, |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
547 (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
|
548 ("(N)", string_intern(self, name))) |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
549 |
|
14186
e921228af435
initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents:
14169
diff
changeset
|
550 VOID_HANDLER(ProcessingInstruction, |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
551 (void *userData, |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
552 const XML_Char *target, |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
553 const XML_Char *data), |
|
42351
e50e33b7e0e0
SF patch# 1759016 by Joe Gregorio, who writes:
Guido van Rossum <guido@python.org>
parents:
42334
diff
changeset
|
554 ("(NO&)", string_intern(self, target), conv_string_to_unicode ,data)) |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
555 |
|
14186
e921228af435
initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents:
14169
diff
changeset
|
556 VOID_HANDLER(UnparsedEntityDecl, |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
557 (void *userData, |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
558 const XML_Char *entityName, |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
559 const XML_Char *base, |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
560 const XML_Char *systemId, |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
561 const XML_Char *publicId, |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
562 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
|
563 ("(NNNNN)", |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
564 string_intern(self, entityName), string_intern(self, base), |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
565 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
|
566 string_intern(self, notationName))) |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
567 |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
568 VOID_HANDLER(EntityDecl, |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
569 (void *userData, |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
570 const XML_Char *entityName, |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
571 int is_parameter_entity, |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
572 const XML_Char *value, |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
573 int value_length, |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
574 const XML_Char *base, |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
575 const XML_Char *systemId, |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
576 const XML_Char *publicId, |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
577 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
|
578 ("NiNNNNN", |
|
34b8cdbbd8fe
Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents:
23832
diff
changeset
|
579 string_intern(self, entityName), is_parameter_entity, |
|
42351
e50e33b7e0e0
SF patch# 1759016 by Joe Gregorio, who writes:
Guido van Rossum <guido@python.org>
parents:
42334
diff
changeset
|
580 (conv_string_len_to_unicode(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
|
581 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
|
582 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
|
583 string_intern(self, notationName))) |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
584 |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
585 VOID_HANDLER(XmlDecl, |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
586 (void *userData, |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
587 const XML_Char *version, |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
588 const XML_Char *encoding, |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
589 int standalone), |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
590 ("(O&O&i)", |
|
42351
e50e33b7e0e0
SF patch# 1759016 by Joe Gregorio, who writes:
Guido van Rossum <guido@python.org>
parents:
42334
diff
changeset
|
591 conv_string_to_unicode ,version, conv_string_to_unicode ,encoding, |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
592 standalone)) |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
593 |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
594 static PyObject * |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
595 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
|
596 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
|
597 { |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
598 PyObject *result = NULL; |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
599 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
|
600 int i; |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
601 |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
602 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
|
603 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
|
604 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
|
605 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
|
606 conv_string); |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
607 if (child == NULL) { |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
608 Py_XDECREF(children); |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
609 return NULL; |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
610 } |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
611 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
|
612 } |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
613 result = Py_BuildValue("(iiO&N)", |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
614 model->type, model->quant, |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
615 conv_string,model->name, children); |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
616 } |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
617 return result; |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
618 } |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
619 |
|
27586
98197ebe5ccb
Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents:
27322
diff
changeset
|
620 static void |
|
98197ebe5ccb
Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents:
27322
diff
changeset
|
621 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
|
622 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
|
623 XML_Content *model) |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
624 { |
|
27586
98197ebe5ccb
Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents:
27322
diff
changeset
|
625 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
|
626 PyObject *args = NULL; |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
627 |
|
27586
98197ebe5ccb
Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents:
27322
diff
changeset
|
628 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
|
629 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
|
630 PyObject *modelobj, *nameobj; |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
631 |
|
27586
98197ebe5ccb
Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents:
27322
diff
changeset
|
632 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
|
633 goto finally; |
|
42351
e50e33b7e0e0
SF patch# 1759016 by Joe Gregorio, who writes:
Guido van Rossum <guido@python.org>
parents:
42334
diff
changeset
|
634 modelobj = conv_content_model(model, (conv_string_to_unicode)); |
|
27586
98197ebe5ccb
Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents:
27322
diff
changeset
|
635 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
|
636 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
|
637 goto finally; |
|
98197ebe5ccb
Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents:
27322
diff
changeset
|
638 } |
|
98197ebe5ccb
Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents:
27322
diff
changeset
|
639 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
|
640 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
|
641 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
|
642 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
|
643 goto finally; |
|
98197ebe5ccb
Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents:
27322
diff
changeset
|
644 } |
|
32923
f1bbf147810b
Fix the reference count errors revealed by the test suite...
Michael W. Hudson <mwh@python.net>
parents:
30683
diff
changeset
|
645 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
|
646 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
|
647 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
|
648 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
|
649 goto finally; |
|
98197ebe5ccb
Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents:
27322
diff
changeset
|
650 } |
|
98197ebe5ccb
Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents:
27322
diff
changeset
|
651 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
|
652 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
|
653 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
|
654 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
|
655 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
|
656 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
|
657 goto finally; |
|
98197ebe5ccb
Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents:
27322
diff
changeset
|
658 } |
|
98197ebe5ccb
Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents:
27322
diff
changeset
|
659 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
|
660 } |
|
98197ebe5ccb
Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents:
27322
diff
changeset
|
661 finally: |
|
98197ebe5ccb
Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents:
27322
diff
changeset
|
662 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
|
663 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
|
664 return; |
|
98197ebe5ccb
Fix memory leak: free memory storing the content model passed to the
Fred Drake <fdrake@acm.org>
parents:
27322
diff
changeset
|
665 } |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
666 |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
667 VOID_HANDLER(AttlistDecl, |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
668 (void *userData, |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
669 const XML_Char *elname, |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
670 const XML_Char *attname, |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
671 const XML_Char *att_type, |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
672 const XML_Char *dflt, |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
673 int isrequired), |
|
24027
34b8cdbbd8fe
Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents:
23832
diff
changeset
|
674 ("(NNO&O&i)", |
|
34b8cdbbd8fe
Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents:
23832
diff
changeset
|
675 string_intern(self, elname), string_intern(self, attname), |
|
42351
e50e33b7e0e0
SF patch# 1759016 by Joe Gregorio, who writes:
Guido van Rossum <guido@python.org>
parents:
42334
diff
changeset
|
676 conv_string_to_unicode ,att_type, conv_string_to_unicode ,dflt, |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
677 isrequired)) |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
678 |
|
27322
88bf10313584
Conditionalize features not found in PyXML 1.95.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
27321
diff
changeset
|
679 #if XML_COMBINED_VERSION >= 19504 |
|
27321
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
680 VOID_HANDLER(SkippedEntity, |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
681 (void *userData, |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
682 const XML_Char *entityName, |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
683 int is_parameter_entity), |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
684 ("Ni", |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
685 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
|
686 #endif |
|
27321
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
687 |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
688 VOID_HANDLER(NotationDecl, |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
689 (void *userData, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
690 const XML_Char *notationName, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
691 const XML_Char *base, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
692 const XML_Char *systemId, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
693 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
|
694 ("(NNNN)", |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
695 string_intern(self, notationName), string_intern(self, base), |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
696 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
|
697 |
|
14186
e921228af435
initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents:
14169
diff
changeset
|
698 VOID_HANDLER(StartNamespaceDecl, |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
699 (void *userData, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
700 const XML_Char *prefix, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
701 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
|
702 ("(NN)", |
|
34b8cdbbd8fe
Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents:
23832
diff
changeset
|
703 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
|
704 |
|
14186
e921228af435
initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents:
14169
diff
changeset
|
705 VOID_HANDLER(EndNamespaceDecl, |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
706 (void *userData, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
707 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
|
708 ("(N)", string_intern(self, prefix))) |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
709 |
|
14186
e921228af435
initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents:
14169
diff
changeset
|
710 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
|
711 (void *userData, const XML_Char *data), |
|
42351
e50e33b7e0e0
SF patch# 1759016 by Joe Gregorio, who writes:
Guido van Rossum <guido@python.org>
parents:
42334
diff
changeset
|
712 ("(O&)", conv_string_to_unicode ,data)) |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
713 |
|
14186
e921228af435
initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents:
14169
diff
changeset
|
714 VOID_HANDLER(StartCdataSection, |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
715 (void *userData), |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
716 ("()")) |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
717 |
|
14186
e921228af435
initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents:
14169
diff
changeset
|
718 VOID_HANDLER(EndCdataSection, |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
719 (void *userData), |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
720 ("()")) |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
721 |
|
14186
e921228af435
initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents:
14169
diff
changeset
|
722 VOID_HANDLER(Default, |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
723 (void *userData, const XML_Char *s, int len), |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
724 ("(N)", (conv_string_len_to_unicode(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
|
725 |
|
14186
e921228af435
initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents:
14169
diff
changeset
|
726 VOID_HANDLER(DefaultHandlerExpand, |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
727 (void *userData, const XML_Char *s, int len), |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
728 ("(N)", (conv_string_len_to_unicode(s,len)))) |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
729 |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
730 INT_HANDLER(NotStandalone, |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
731 (void *userData), |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
732 ("()")) |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
733 |
|
14186
e921228af435
initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents:
14169
diff
changeset
|
734 RC_HANDLER(int, ExternalEntityRef, |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
735 (XML_Parser parser, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
736 const XML_Char *context, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
737 const XML_Char *base, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
738 const XML_Char *systemId, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
739 const XML_Char *publicId), |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
740 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
|
741 ("(O&NNN)", |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
742 conv_string_to_unicode ,context, string_intern(self, base), |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
743 string_intern(self, systemId), string_intern(self, publicId)), |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
744 rc = PyLong_AsLong(rv);, rc, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
745 XML_GetUserData(parser)) |
|
16076
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
746 |
|
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
747 /* XXX UnknownEncodingHandler */ |
|
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
748 |
|
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
749 VOID_HANDLER(StartDoctypeDecl, |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
750 (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
|
751 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
|
752 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
|
753 ("(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
|
754 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
|
755 has_internal_subset)) |
|
16076
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
756 |
|
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
757 VOID_HANDLER(EndDoctypeDecl, (void *userData), ("()")) |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
758 |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
759 /* ---------------------------------------------------------------- */ |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
760 |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
761 static PyObject * |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
762 get_parse_result(xmlparseobject *self, int rv) |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
763 { |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
764 if (PyErr_Occurred()) { |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
765 return NULL; |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
766 } |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
767 if (rv == 0) { |
|
27321
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
768 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
|
769 } |
|
24040
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
770 if (flush_character_buffer(self) < 0) { |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
771 return NULL; |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
772 } |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
44046
diff
changeset
|
773 return PyLong_FromLong(rv); |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
774 } |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
775 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22421
diff
changeset
|
776 PyDoc_STRVAR(xmlparse_Parse__doc__, |
|
13654
0bb49b3dbdf0
Mark Favas's fix for typos in docstrings.
Thomas Wouters <thomas@python.org>
parents:
13568
diff
changeset
|
777 "Parse(data[, isfinal])\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22421
diff
changeset
|
778 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
|
779 |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
780 static PyObject * |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
781 xmlparse_Parse(xmlparseobject *self, PyObject *args) |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
782 { |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
783 char *s; |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
784 int slen; |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
785 int isFinal = 0; |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
786 |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
787 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
|
788 return NULL; |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
789 |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
790 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
|
791 } |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
792 |
|
14728
e2c03c30b06d
Remove memory leaks of strings/Unicode objects passed into the character
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
793 /* 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
|
794 |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
795 #define BUF_SIZE 2048 |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
796 |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
797 static int |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
798 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
|
799 { |
|
67514
1450521b9d93
Issue #9566: Fix pyparse.xmlparser.ParseFile()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67361
diff
changeset
|
800 PyObject *str; |
|
1450521b9d93
Issue #9566: Fix pyparse.xmlparser.ParseFile()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67361
diff
changeset
|
801 Py_ssize_t len; |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
802 char *ptr; |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
803 |
|
67514
1450521b9d93
Issue #9566: Fix pyparse.xmlparser.ParseFile()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67361
diff
changeset
|
804 str = PyObject_CallFunction(meth, "n", buf_size); |
|
33752
ddc2d6e547c1
Synchronize with PyXML 1.79:
Martin v. Löwis <martin@v.loewis.de>
parents:
33279
diff
changeset
|
805 if (str == NULL) |
|
67514
1450521b9d93
Issue #9566: Fix pyparse.xmlparser.ParseFile()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67361
diff
changeset
|
806 goto error; |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
807 |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
47300
diff
changeset
|
808 if (PyBytes_Check(str)) |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
47300
diff
changeset
|
809 ptr = PyBytes_AS_STRING(str); |
|
47300
96b34263e448
Renamed PyBytes to PyByteArray
Christian Heimes <christian@cheimes.de>
parents:
44604
diff
changeset
|
810 else if (PyByteArray_Check(str)) |
|
96b34263e448
Renamed PyBytes to PyByteArray
Christian Heimes <christian@cheimes.de>
parents:
44604
diff
changeset
|
811 ptr = PyByteArray_AS_STRING(str); |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
812 else { |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
813 PyErr_Format(PyExc_TypeError, |
|
42351
e50e33b7e0e0
SF patch# 1759016 by Joe Gregorio, who writes:
Guido van Rossum <guido@python.org>
parents:
42334
diff
changeset
|
814 "read() did not return a bytes object (type=%.400s)", |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
815 Py_TYPE(str)->tp_name); |
|
67514
1450521b9d93
Issue #9566: Fix pyparse.xmlparser.ParseFile()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67361
diff
changeset
|
816 goto error; |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
817 } |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
818 len = Py_SIZE(str); |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
819 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
|
820 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
|
821 "read() returned too much data: " |
|
67361
c0fef8a144fa
Issue #9566: PyUnicode_FromFormatV() doesn't support %zi, use %zd instead
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67360
diff
changeset
|
822 "%i bytes requested, %zd returned", |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
823 buf_size, len); |
|
67514
1450521b9d93
Issue #9566: Fix pyparse.xmlparser.ParseFile()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67361
diff
changeset
|
824 goto error; |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
825 } |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
826 memcpy(buf, ptr, len); |
|
67514
1450521b9d93
Issue #9566: Fix pyparse.xmlparser.ParseFile()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67361
diff
changeset
|
827 Py_DECREF(str); |
|
1450521b9d93
Issue #9566: Fix pyparse.xmlparser.ParseFile()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67361
diff
changeset
|
828 /* len <= buf_size <= INT_MAX */ |
|
1450521b9d93
Issue #9566: Fix pyparse.xmlparser.ParseFile()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67361
diff
changeset
|
829 return (int)len; |
|
1450521b9d93
Issue #9566: Fix pyparse.xmlparser.ParseFile()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67361
diff
changeset
|
830 |
|
1450521b9d93
Issue #9566: Fix pyparse.xmlparser.ParseFile()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67361
diff
changeset
|
831 error: |
|
14728
e2c03c30b06d
Remove memory leaks of strings/Unicode objects passed into the character
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
832 Py_XDECREF(str); |
|
67514
1450521b9d93
Issue #9566: Fix pyparse.xmlparser.ParseFile()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67361
diff
changeset
|
833 return -1; |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
834 } |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
835 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22421
diff
changeset
|
836 PyDoc_STRVAR(xmlparse_ParseFile__doc__, |
|
13654
0bb49b3dbdf0
Mark Favas's fix for typos in docstrings.
Thomas Wouters <thomas@python.org>
parents:
13568
diff
changeset
|
837 "ParseFile(file)\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22421
diff
changeset
|
838 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
|
839 |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
840 static PyObject * |
|
38669
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
841 xmlparse_ParseFile(xmlparseobject *self, PyObject *f) |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
842 { |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
843 int rv = 1; |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
844 PyObject *readmethod = NULL; |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
845 |
|
63829
c52f5df50448
remove dead code #9292
Benjamin Peterson <benjamin@python.org>
parents:
61466
diff
changeset
|
846 |
|
c52f5df50448
remove dead code #9292
Benjamin Peterson <benjamin@python.org>
parents:
61466
diff
changeset
|
847 readmethod = PyObject_GetAttrString(f, "read"); |
|
c52f5df50448
remove dead code #9292
Benjamin Peterson <benjamin@python.org>
parents:
61466
diff
changeset
|
848 if (readmethod == NULL) { |
|
c52f5df50448
remove dead code #9292
Benjamin Peterson <benjamin@python.org>
parents:
61466
diff
changeset
|
849 PyErr_SetString(PyExc_TypeError, |
|
c52f5df50448
remove dead code #9292
Benjamin Peterson <benjamin@python.org>
parents:
61466
diff
changeset
|
850 "argument must have 'read' attribute"); |
|
c52f5df50448
remove dead code #9292
Benjamin Peterson <benjamin@python.org>
parents:
61466
diff
changeset
|
851 return NULL; |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
852 } |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
853 for (;;) { |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
854 int bytes_read; |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
855 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
|
856 if (buf == NULL) { |
|
29957
cea7f8af8e0b
Repair mis-application of Jeremy's patch. Thanks, Neal!
Fred Drake <fdrake@acm.org>
parents:
29955
diff
changeset
|
857 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
|
858 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
|
859 } |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
860 |
|
63829
c52f5df50448
remove dead code #9292
Benjamin Peterson <benjamin@python.org>
parents:
61466
diff
changeset
|
861 bytes_read = readinst(buf, BUF_SIZE, readmethod); |
|
c52f5df50448
remove dead code #9292
Benjamin Peterson <benjamin@python.org>
parents:
61466
diff
changeset
|
862 if (bytes_read < 0) { |
|
c52f5df50448
remove dead code #9292
Benjamin Peterson <benjamin@python.org>
parents:
61466
diff
changeset
|
863 Py_DECREF(readmethod); |
|
c52f5df50448
remove dead code #9292
Benjamin Peterson <benjamin@python.org>
parents:
61466
diff
changeset
|
864 return NULL; |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
865 } |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
866 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
|
867 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
|
868 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
|
869 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
|
870 } |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
871 |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
872 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
|
873 break; |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
874 } |
|
29955
09c459851264
Fix memory leak reported & discussed on the Python XML-SIG mailing list.
Fred Drake <fdrake@acm.org>
parents:
29605
diff
changeset
|
875 Py_XDECREF(readmethod); |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
876 return get_parse_result(self, rv); |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
877 } |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
878 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22421
diff
changeset
|
879 PyDoc_STRVAR(xmlparse_SetBase__doc__, |
|
13654
0bb49b3dbdf0
Mark Favas's fix for typos in docstrings.
Thomas Wouters <thomas@python.org>
parents:
13568
diff
changeset
|
880 "SetBase(base_url)\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22421
diff
changeset
|
881 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
|
882 |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
883 static PyObject * |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
884 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
|
885 { |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
886 char *base; |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
887 |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
888 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
|
889 return NULL; |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
890 if (!XML_SetBase(self->itself, base)) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
891 return PyErr_NoMemory(); |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
892 } |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
893 Py_INCREF(Py_None); |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
894 return Py_None; |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
895 } |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
896 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22421
diff
changeset
|
897 PyDoc_STRVAR(xmlparse_GetBase__doc__, |
|
13654
0bb49b3dbdf0
Mark Favas's fix for typos in docstrings.
Thomas Wouters <thomas@python.org>
parents:
13568
diff
changeset
|
898 "GetBase() -> url\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22421
diff
changeset
|
899 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
|
900 |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
901 static PyObject * |
|
38669
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
902 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
|
903 { |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
904 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
|
905 } |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
906 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22421
diff
changeset
|
907 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
|
908 "GetInputContext() -> string\n\ |
|
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
909 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
|
910 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
|
911 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
|
912 |
|
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
913 static PyObject * |
|
38669
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
914 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
|
915 { |
|
38669
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
916 if (self->in_callback) { |
|
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
917 int offset, size; |
|
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
918 const char *buffer |
|
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
919 = 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
|
920 |
|
38669
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
921 if (buffer != NULL) |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
47300
diff
changeset
|
922 return PyBytes_FromStringAndSize(buffer + offset, |
|
38669
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
923 size - offset); |
|
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
924 else |
|
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
925 Py_RETURN_NONE; |
|
16601
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
926 } |
|
38669
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
927 else |
|
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
928 Py_RETURN_NONE; |
|
16601
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
929 } |
|
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
930 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22421
diff
changeset
|
931 PyDoc_STRVAR(xmlparse_ExternalEntityParserCreate__doc__, |
|
15703
f6ee0d4672d6
Mark the "encoding" parameter to ExternalEntityParserCreate() as optional
Fred Drake <fdrake@acm.org>
parents:
15642
diff
changeset
|
932 "ExternalEntityParserCreate(context[, encoding])\n\ |
|
14824
a1033283a25d
Repaired damaged string.
Tim Peters <tim.peters@gmail.com>
parents:
14823
diff
changeset
|
933 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
|
934 information passed to the ExternalEntityRefHandler."); |
|
14812
d543daa15d71
Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents:
14788
diff
changeset
|
935 |
|
d543daa15d71
Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents:
14788
diff
changeset
|
936 static PyObject * |
|
d543daa15d71
Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents:
14788
diff
changeset
|
937 xmlparse_ExternalEntityParserCreate(xmlparseobject *self, PyObject *args) |
|
d543daa15d71
Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents:
14788
diff
changeset
|
938 { |
|
d543daa15d71
Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents:
14788
diff
changeset
|
939 char *context; |
|
d543daa15d71
Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents:
14788
diff
changeset
|
940 char *encoding = NULL; |
|
d543daa15d71
Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents:
14788
diff
changeset
|
941 xmlparseobject *new_parser; |
|
d543daa15d71
Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents:
14788
diff
changeset
|
942 int i; |
|
d543daa15d71
Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents:
14788
diff
changeset
|
943 |
|
19978
a960e673077f
Patch to bug #461753: Allow None in ExternalEntityParserCreate.
Martin v. Löwis <martin@v.loewis.de>
parents:
19343
diff
changeset
|
944 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
|
945 &context, &encoding)) { |
|
1686080a7c6c
ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents:
17219
diff
changeset
|
946 return NULL; |
|
14812
d543daa15d71
Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents:
14788
diff
changeset
|
947 } |
|
d543daa15d71
Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents:
14788
diff
changeset
|
948 |
|
20047
4c5cd3d1cf4b
Reactivate participation of expat parsers in GC. Fixes bug #462710.
Martin v. Löwis <martin@v.loewis.de>
parents:
19979
diff
changeset
|
949 new_parser = PyObject_GC_New(xmlparseobject, &Xmlparsetype); |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
950 if (new_parser == NULL) |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
951 return NULL; |
|
24040
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
952 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
|
953 new_parser->buffer_used = 0; |
|
64627
6accc2c65cb8
Issue #9402: pyexpat uses Py_DECREF() instead of PyObject_DEL()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
63829
diff
changeset
|
954 new_parser->buffer = NULL; |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
955 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
|
956 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
|
957 new_parser->in_callback = 0; |
|
27321
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
958 new_parser->ns_prefixes = self->ns_prefixes; |
|
14812
d543daa15d71
Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents:
14788
diff
changeset
|
959 new_parser->itself = XML_ExternalEntityParserCreate(self->itself, context, |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
960 encoding); |
|
16076
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
961 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
|
962 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
|
963 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
|
964 PyObject_GC_Track(new_parser); |
|
16076
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
965 |
|
64627
6accc2c65cb8
Issue #9402: pyexpat uses Py_DECREF() instead of PyObject_DEL()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
63829
diff
changeset
|
966 if (self->buffer != NULL) { |
|
6accc2c65cb8
Issue #9402: pyexpat uses Py_DECREF() instead of PyObject_DEL()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
63829
diff
changeset
|
967 new_parser->buffer = malloc(new_parser->buffer_size); |
|
6accc2c65cb8
Issue #9402: pyexpat uses Py_DECREF() instead of PyObject_DEL()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
63829
diff
changeset
|
968 if (new_parser->buffer == NULL) { |
|
6accc2c65cb8
Issue #9402: pyexpat uses Py_DECREF() instead of PyObject_DEL()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
63829
diff
changeset
|
969 Py_DECREF(new_parser); |
|
6accc2c65cb8
Issue #9402: pyexpat uses Py_DECREF() instead of PyObject_DEL()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
63829
diff
changeset
|
970 return PyErr_NoMemory(); |
|
6accc2c65cb8
Issue #9402: pyexpat uses Py_DECREF() instead of PyObject_DEL()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
63829
diff
changeset
|
971 } |
|
6accc2c65cb8
Issue #9402: pyexpat uses Py_DECREF() instead of PyObject_DEL()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
63829
diff
changeset
|
972 } |
|
16076
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
973 if (!new_parser->itself) { |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
974 Py_DECREF(new_parser); |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
975 return PyErr_NoMemory(); |
|
14812
d543daa15d71
Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents:
14788
diff
changeset
|
976 } |
|
d543daa15d71
Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents:
14788
diff
changeset
|
977 |
|
d543daa15d71
Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents:
14788
diff
changeset
|
978 XML_SetUserData(new_parser->itself, (void *)new_parser); |
|
d543daa15d71
Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents:
14788
diff
changeset
|
979 |
|
d543daa15d71
Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents:
14788
diff
changeset
|
980 /* allocate and clear handlers first */ |
|
24040
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
981 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
|
982 /* do nothing */; |
|
14812
d543daa15d71
Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents:
14788
diff
changeset
|
983 |
|
24040
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
984 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
|
985 if (!new_parser->handlers) { |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
986 Py_DECREF(new_parser); |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
987 return PyErr_NoMemory(); |
|
16076
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
988 } |
|
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
|
989 clear_handlers(new_parser, 1); |
|
14812
d543daa15d71
Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents:
14788
diff
changeset
|
990 |
|
d543daa15d71
Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents:
14788
diff
changeset
|
991 /* then copy handlers from self */ |
|
d543daa15d71
Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents:
14788
diff
changeset
|
992 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
|
993 PyObject *handler = self->handlers[i]; |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
994 if (handler != NULL) { |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
995 Py_INCREF(handler); |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
996 new_parser->handlers[i] = handler; |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
997 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
|
998 handler_info[i].handler); |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
999 } |
|
14812
d543daa15d71
Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents:
14788
diff
changeset
|
1000 } |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1001 return (PyObject *)new_parser; |
|
14812
d543daa15d71
Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents:
14788
diff
changeset
|
1002 } |
|
d543daa15d71
Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents:
14788
diff
changeset
|
1003 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22421
diff
changeset
|
1004 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
|
1005 "SetParamEntityParsing(flag) -> success\n\ |
|
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1006 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
|
1007 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
|
1008 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
|
1009 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
|
1010 was successful."); |
|
16076
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1011 |
|
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1012 static PyObject* |
|
16601
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
1013 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
|
1014 { |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1015 int flag; |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1016 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
|
1017 return NULL; |
|
16601
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
1018 flag = XML_SetParamEntityParsing(p->itself, flag); |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
44046
diff
changeset
|
1019 return PyLong_FromLong(flag); |
|
16076
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1020 } |
|
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1021 |
|
27322
88bf10313584
Conditionalize features not found in PyXML 1.95.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
27321
diff
changeset
|
1022 |
|
88bf10313584
Conditionalize features not found in PyXML 1.95.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
27321
diff
changeset
|
1023 #if XML_COMBINED_VERSION >= 19505 |
|
27321
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1024 PyDoc_STRVAR(xmlparse_UseForeignDTD__doc__, |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1025 "UseForeignDTD([flag])\n\ |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1026 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
|
1027 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
|
1028 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
|
1029 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
|
1030 '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
|
1031 |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1032 static PyObject * |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1033 xmlparse_UseForeignDTD(xmlparseobject *self, PyObject *args) |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1034 { |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1035 PyObject *flagobj = NULL; |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1036 XML_Bool flag = XML_TRUE; |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1037 enum XML_Error rc; |
|
38669
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
1038 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
|
1039 return NULL; |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1040 if (flagobj != NULL) |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1041 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
|
1042 rc = XML_UseForeignDTD(self->itself, flag); |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1043 if (rc != XML_ERROR_NONE) { |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1044 return set_error(self, rc); |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1045 } |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1046 Py_INCREF(Py_None); |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1047 return Py_None; |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1048 } |
|
27322
88bf10313584
Conditionalize features not found in PyXML 1.95.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
27321
diff
changeset
|
1049 #endif |
|
27321
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1050 |
|
48414
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
1051 static PyObject *xmlparse_dir(PyObject *self, PyObject* noargs); |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
1052 |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1053 static struct PyMethodDef xmlparse_methods[] = { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1054 {"Parse", (PyCFunction)xmlparse_Parse, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1055 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
|
1056 {"ParseFile", (PyCFunction)xmlparse_ParseFile, |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1057 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
|
1058 {"SetBase", (PyCFunction)xmlparse_SetBase, |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1059 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
|
1060 {"GetBase", (PyCFunction)xmlparse_GetBase, |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1061 METH_NOARGS, xmlparse_GetBase__doc__}, |
|
14812
d543daa15d71
Added ExternalEntityParserCreate method (patch 101635).
Lars Gustäbel <lars@gustaebel.de>
parents:
14788
diff
changeset
|
1062 {"ExternalEntityParserCreate", (PyCFunction)xmlparse_ExternalEntityParserCreate, |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1063 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
|
1064 {"SetParamEntityParsing", (PyCFunction)xmlparse_SetParamEntityParsing, |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1065 METH_VARARGS, xmlparse_SetParamEntityParsing__doc__}, |
|
16601
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
1066 {"GetInputContext", (PyCFunction)xmlparse_GetInputContext, |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1067 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
|
1068 #if XML_COMBINED_VERSION >= 19505 |
|
27321
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1069 {"UseForeignDTD", (PyCFunction)xmlparse_UseForeignDTD, |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1070 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
|
1071 #endif |
|
48414
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
1072 {"__dir__", xmlparse_dir, METH_NOARGS}, |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1073 {NULL, NULL} /* sentinel */ |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1074 }; |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1075 |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1076 /* ---------- */ |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1077 |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1078 |
|
16076
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1079 |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1080 /* pyexpat international encoding support. |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1081 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
|
1082 */ |
|
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1083 |
|
16099
967abbecc404
Fix off-by-one error in array size.
Martin v. Löwis <martin@v.loewis.de>
parents:
16094
diff
changeset
|
1084 static char template_buffer[257]; |
|
16076
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1085 |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1086 static void |
|
16076
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1087 init_template_buffer(void) |
|
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1088 { |
|
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1089 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
|
1090 for (i = 0; i < 256; i++) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1091 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
|
1092 } |
|
16912
a46a13201eeb
Wrap some long lines, use only C89 /* */ comments, and add spaces around
Fred Drake <fdrake@acm.org>
parents:
16644
diff
changeset
|
1093 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
|
1094 } |
|
16076
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1095 |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1096 static int |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1097 PyUnknownEncodingHandler(void *encodingHandlerData, |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1098 const XML_Char *name, |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1099 XML_Encoding *info) |
|
16076
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1100 { |
|
16912
a46a13201eeb
Wrap some long lines, use only C89 /* */ comments, and add spaces around
Fred Drake <fdrake@acm.org>
parents:
16644
diff
changeset
|
1101 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
|
1102 int result = 0; |
|
16076
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1103 int i; |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1104 |
|
16912
a46a13201eeb
Wrap some long lines, use only C89 /* */ comments, and add spaces around
Fred Drake <fdrake@acm.org>
parents:
16644
diff
changeset
|
1105 /* 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
|
1106 _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
|
1107 PyUnicode_Decode(template_buffer, 256, name, "replace"); |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1108 |
|
16912
a46a13201eeb
Wrap some long lines, use only C89 /* */ comments, and add spaces around
Fred Drake <fdrake@acm.org>
parents:
16644
diff
changeset
|
1109 if (_u_string == NULL) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1110 return result; |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1111 |
|
16912
a46a13201eeb
Wrap some long lines, use only C89 /* */ comments, and add spaces around
Fred Drake <fdrake@acm.org>
parents:
16644
diff
changeset
|
1112 for (i = 0; i < 256; i++) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1113 /* Stupid to access directly, but fast */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1114 Py_UNICODE c = _u_string->str[i]; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1115 if (c == Py_UNICODE_REPLACEMENT_CHARACTER) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1116 info->map[i] = -1; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1117 else |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1118 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
|
1119 } |
|
16076
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1120 info->data = NULL; |
|
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1121 info->convert = NULL; |
|
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1122 info->release = NULL; |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1123 result = 1; |
|
16076
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1124 Py_DECREF(_u_string); |
|
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1125 return result; |
|
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1126 } |
|
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1127 |
|
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1128 |
|
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1129 static PyObject * |
|
24027
34b8cdbbd8fe
Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents:
23832
diff
changeset
|
1130 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
|
1131 { |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1132 int i; |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1133 xmlparseobject *self; |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1134 |
|
20047
4c5cd3d1cf4b
Reactivate participation of expat parsers in GC. Fixes bug #462710.
Martin v. Löwis <martin@v.loewis.de>
parents:
19979
diff
changeset
|
1135 self = PyObject_GC_New(xmlparseobject, &Xmlparsetype); |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1136 if (self == NULL) |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1137 return NULL; |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1138 |
|
24040
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
1139 self->buffer = NULL; |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
1140 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
|
1141 self->buffer_used = 0; |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1142 self->ordered_attributes = 0; |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1143 self->specified_attributes = 0; |
|
16601
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
1144 self->in_callback = 0; |
|
27321
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1145 self->ns_prefixes = 0; |
|
16076
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1146 self->handlers = NULL; |
|
17623
1686080a7c6c
ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents:
17219
diff
changeset
|
1147 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
|
1148 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
|
1149 } |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1150 else { |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1151 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
|
1152 } |
|
75817
d54508a86a5d
Fixes Issue 14234: fix for the previous commit, keep compilation when
Gregory P. Smith <greg@krypto.org>
parents:
75816
diff
changeset
|
1153 #if ((XML_MAJOR_VERSION >= 2) && (XML_MINOR_VERSION >= 1)) || defined(XML_HAS_SET_HASH_SALT) |
|
d54508a86a5d
Fixes Issue 14234: fix for the previous commit, keep compilation when
Gregory P. Smith <greg@krypto.org>
parents:
75816
diff
changeset
|
1154 /* This feature was added upstream in libexpat 2.1.0. Our expat copy |
|
d54508a86a5d
Fixes Issue 14234: fix for the previous commit, keep compilation when
Gregory P. Smith <greg@krypto.org>
parents:
75816
diff
changeset
|
1155 * has a backport of this feature where we also define XML_HAS_SET_HASH_SALT |
|
d54508a86a5d
Fixes Issue 14234: fix for the previous commit, keep compilation when
Gregory P. Smith <greg@krypto.org>
parents:
75816
diff
changeset
|
1156 * to indicate that we can still use it. */ |
|
75816
cf7337a49a07
Transplant from main repo d6c197edd99b: Fixes Issue #14234: CVE-2012-0876: Randomize hashes of xml attributes
Georg Brandl <georg@python.org>
parents:
70572
diff
changeset
|
1157 XML_SetHashSalt(self->itself, |
|
cf7337a49a07
Transplant from main repo d6c197edd99b: Fixes Issue #14234: CVE-2012-0876: Randomize hashes of xml attributes
Georg Brandl <georg@python.org>
parents:
70572
diff
changeset
|
1158 (unsigned long)_Py_HashSecret.prefix); |
|
75817
d54508a86a5d
Fixes Issue 14234: fix for the previous commit, keep compilation when
Gregory P. Smith <greg@krypto.org>
parents:
75816
diff
changeset
|
1159 #endif |
|
24027
34b8cdbbd8fe
Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents:
23832
diff
changeset
|
1160 self->intern = intern; |
|
34b8cdbbd8fe
Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents:
23832
diff
changeset
|
1161 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
|
1162 PyObject_GC_Track(self); |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1163 if (self->itself == NULL) { |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1164 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
|
1165 "XML_ParserCreate failed"); |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1166 Py_DECREF(self); |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1167 return NULL; |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1168 } |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1169 XML_SetUserData(self->itself, (void *)self); |
|
24076
95ccd5bbdc86
Bring this back into sync with PyXML revision 1.58.
Fred Drake <fdrake@acm.org>
parents:
24064
diff
changeset
|
1170 XML_SetUnknownEncodingHandler(self->itself, |
|
95ccd5bbdc86
Bring this back into sync with PyXML revision 1.58.
Fred Drake <fdrake@acm.org>
parents:
24064
diff
changeset
|
1171 (XML_UnknownEncodingHandler) PyUnknownEncodingHandler, NULL); |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1172 |
|
24040
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
1173 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
|
1174 /* do nothing */; |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1175 |
|
24076
95ccd5bbdc86
Bring this back into sync with PyXML revision 1.58.
Fred Drake <fdrake@acm.org>
parents:
24064
diff
changeset
|
1176 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
|
1177 if (!self->handlers) { |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1178 Py_DECREF(self); |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1179 return PyErr_NoMemory(); |
|
16076
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1180 } |
|
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
|
1181 clear_handlers(self, 1); |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1182 |
|
16076
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1183 return (PyObject*)self; |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1184 } |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1185 |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1186 |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1187 static void |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1188 xmlparse_dealloc(xmlparseobject *self) |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1189 { |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1190 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
|
1191 PyObject_GC_UnTrack(self); |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1192 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
|
1193 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
|
1194 self->itself = NULL; |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1195 |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1196 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
|
1197 PyObject *temp; |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1198 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
|
1199 temp = self->handlers[i]; |
|
1686080a7c6c
ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents:
17219
diff
changeset
|
1200 self->handlers[i] = NULL; |
|
1686080a7c6c
ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents:
17219
diff
changeset
|
1201 Py_XDECREF(temp); |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1202 } |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1203 free(self->handlers); |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1204 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
|
1205 } |
|
24040
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
1206 if (self->buffer != NULL) { |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
1207 free(self->buffer); |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
1208 self->buffer = NULL; |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
1209 } |
|
24027
34b8cdbbd8fe
Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents:
23832
diff
changeset
|
1210 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
|
1211 PyObject_GC_Del(self); |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1212 } |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1213 |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1214 static int |
|
66799
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
65367
diff
changeset
|
1215 handlername2int(PyObject *name) |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1216 { |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1217 int i; |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1218 for (i = 0; handler_info[i].name != NULL; i++) { |
|
66799
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
65367
diff
changeset
|
1219 if (PyUnicode_CompareWithASCIIString( |
|
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
65367
diff
changeset
|
1220 name, handler_info[i].name) == 0) { |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1221 return i; |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1222 } |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1223 } |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1224 return -1; |
|
12182
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 static PyObject * |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1228 get_pybool(int istrue) |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1229 { |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1230 PyObject *result = istrue ? Py_True : Py_False; |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1231 Py_INCREF(result); |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1232 return result; |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1233 } |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1234 |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1235 static PyObject * |
|
48414
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
1236 xmlparse_getattro(xmlparseobject *self, PyObject *nameobj) |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1237 { |
|
66799
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
65367
diff
changeset
|
1238 Py_UNICODE *name; |
|
48414
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
1239 int handlernum = -1; |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
1240 |
|
66799
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
65367
diff
changeset
|
1241 if (!PyUnicode_Check(nameobj)) |
|
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
65367
diff
changeset
|
1242 goto generic; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1243 |
|
66799
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
65367
diff
changeset
|
1244 handlernum = handlername2int(nameobj); |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1245 |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1246 if (handlernum != -1) { |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1247 PyObject *result = self->handlers[handlernum]; |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1248 if (result == NULL) |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1249 result = Py_None; |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1250 Py_INCREF(result); |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1251 return result; |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1252 } |
|
66799
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
65367
diff
changeset
|
1253 |
|
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
65367
diff
changeset
|
1254 name = PyUnicode_AS_UNICODE(nameobj); |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1255 if (name[0] == 'E') { |
|
66799
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
65367
diff
changeset
|
1256 if (PyUnicode_CompareWithASCIIString(nameobj, "ErrorCode") == 0) |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
44046
diff
changeset
|
1257 return PyLong_FromLong((long) |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1258 XML_GetErrorCode(self->itself)); |
|
66799
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
65367
diff
changeset
|
1259 if (PyUnicode_CompareWithASCIIString(nameobj, "ErrorLineNumber") == 0) |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
44046
diff
changeset
|
1260 return PyLong_FromLong((long) |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1261 XML_GetErrorLineNumber(self->itself)); |
|
66799
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
65367
diff
changeset
|
1262 if (PyUnicode_CompareWithASCIIString(nameobj, "ErrorColumnNumber") == 0) |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
44046
diff
changeset
|
1263 return PyLong_FromLong((long) |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1264 XML_GetErrorColumnNumber(self->itself)); |
|
66799
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
65367
diff
changeset
|
1265 if (PyUnicode_CompareWithASCIIString(nameobj, "ErrorByteIndex") == 0) |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
44046
diff
changeset
|
1266 return PyLong_FromLong((long) |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1267 XML_GetErrorByteIndex(self->itself)); |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1268 } |
|
33279
b25cb2045dac
Patch #1014930. Expose current parse location to XMLParser.
Dave Cole <djc@object-craft.com.au>
parents:
33113
diff
changeset
|
1269 if (name[0] == 'C') { |
|
66799
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
65367
diff
changeset
|
1270 if (PyUnicode_CompareWithASCIIString(nameobj, "CurrentLineNumber") == 0) |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
44046
diff
changeset
|
1271 return PyLong_FromLong((long) |
|
33279
b25cb2045dac
Patch #1014930. Expose current parse location to XMLParser.
Dave Cole <djc@object-craft.com.au>
parents:
33113
diff
changeset
|
1272 XML_GetCurrentLineNumber(self->itself)); |
|
66799
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
65367
diff
changeset
|
1273 if (PyUnicode_CompareWithASCIIString(nameobj, "CurrentColumnNumber") == 0) |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
44046
diff
changeset
|
1274 return PyLong_FromLong((long) |
|
33279
b25cb2045dac
Patch #1014930. Expose current parse location to XMLParser.
Dave Cole <djc@object-craft.com.au>
parents:
33113
diff
changeset
|
1275 XML_GetCurrentColumnNumber(self->itself)); |
|
66799
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
65367
diff
changeset
|
1276 if (PyUnicode_CompareWithASCIIString(nameobj, "CurrentByteIndex") == 0) |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
44046
diff
changeset
|
1277 return PyLong_FromLong((long) |
|
33279
b25cb2045dac
Patch #1014930. Expose current parse location to XMLParser.
Dave Cole <djc@object-craft.com.au>
parents:
33113
diff
changeset
|
1278 XML_GetCurrentByteIndex(self->itself)); |
|
b25cb2045dac
Patch #1014930. Expose current parse location to XMLParser.
Dave Cole <djc@object-craft.com.au>
parents:
33113
diff
changeset
|
1279 } |
|
24040
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
1280 if (name[0] == 'b') { |
|
66799
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
65367
diff
changeset
|
1281 if (PyUnicode_CompareWithASCIIString(nameobj, "buffer_size") == 0) |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
44046
diff
changeset
|
1282 return PyLong_FromLong((long) self->buffer_size); |
|
66799
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
65367
diff
changeset
|
1283 if (PyUnicode_CompareWithASCIIString(nameobj, "buffer_text") == 0) |
|
24040
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
1284 return get_pybool(self->buffer != NULL); |
|
66799
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
65367
diff
changeset
|
1285 if (PyUnicode_CompareWithASCIIString(nameobj, "buffer_used") == 0) |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
44046
diff
changeset
|
1286 return PyLong_FromLong((long) self->buffer_used); |
|
24040
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
1287 } |
|
66799
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
65367
diff
changeset
|
1288 if (PyUnicode_CompareWithASCIIString(nameobj, "namespace_prefixes") == 0) |
|
27321
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1289 return get_pybool(self->ns_prefixes); |
|
66799
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
65367
diff
changeset
|
1290 if (PyUnicode_CompareWithASCIIString(nameobj, "ordered_attributes") == 0) |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1291 return get_pybool(self->ordered_attributes); |
|
66799
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
65367
diff
changeset
|
1292 if (PyUnicode_CompareWithASCIIString(nameobj, "specified_attributes") == 0) |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1293 return get_pybool((long) self->specified_attributes); |
|
66799
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
65367
diff
changeset
|
1294 if (PyUnicode_CompareWithASCIIString(nameobj, "intern") == 0) { |
|
24027
34b8cdbbd8fe
Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents:
23832
diff
changeset
|
1295 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
|
1296 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
|
1297 return Py_None; |
|
34b8cdbbd8fe
Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents:
23832
diff
changeset
|
1298 } |
|
34b8cdbbd8fe
Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents:
23832
diff
changeset
|
1299 else { |
|
34b8cdbbd8fe
Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents:
23832
diff
changeset
|
1300 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
|
1301 return self->intern; |
|
34b8cdbbd8fe
Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents:
23832
diff
changeset
|
1302 } |
|
34b8cdbbd8fe
Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents:
23832
diff
changeset
|
1303 } |
|
66799
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
65367
diff
changeset
|
1304 generic: |
|
48414
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
1305 return PyObject_GenericGetAttr((PyObject*)self, nameobj); |
|
42537
74a3c6826683
Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents:
42351
diff
changeset
|
1306 } |
|
74a3c6826683
Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents:
42351
diff
changeset
|
1307 |
|
74a3c6826683
Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents:
42351
diff
changeset
|
1308 static PyObject * |
|
74a3c6826683
Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents:
42351
diff
changeset
|
1309 xmlparse_dir(PyObject *self, PyObject* noargs) |
|
74a3c6826683
Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents:
42351
diff
changeset
|
1310 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1311 #define APPEND(list, str) \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1312 do { \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1313 PyObject *o = PyUnicode_FromString(str); \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1314 if (o != NULL) \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1315 PyList_Append(list, o); \ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1316 Py_XDECREF(o); \ |
|
27321
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1317 } while (0) |
|
27301
5a975e82d70f
SF # 669553, fix memory (ref) leaks
Neal Norwitz <nnorwitz@gmail.com>
parents:
26109
diff
changeset
|
1318 |
|
42537
74a3c6826683
Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents:
42351
diff
changeset
|
1319 int i; |
|
74a3c6826683
Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents:
42351
diff
changeset
|
1320 PyObject *rc = PyList_New(0); |
|
74a3c6826683
Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents:
42351
diff
changeset
|
1321 if (!rc) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1322 return NULL; |
|
42537
74a3c6826683
Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents:
42351
diff
changeset
|
1323 for (i = 0; handler_info[i].name != NULL; i++) { |
|
74a3c6826683
Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents:
42351
diff
changeset
|
1324 PyObject *o = get_handler_name(&handler_info[i]); |
|
74a3c6826683
Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents:
42351
diff
changeset
|
1325 if (o != NULL) |
|
74a3c6826683
Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents:
42351
diff
changeset
|
1326 PyList_Append(rc, o); |
|
74a3c6826683
Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents:
42351
diff
changeset
|
1327 Py_XDECREF(o); |
|
74a3c6826683
Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents:
42351
diff
changeset
|
1328 } |
|
74a3c6826683
Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents:
42351
diff
changeset
|
1329 APPEND(rc, "ErrorCode"); |
|
74a3c6826683
Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents:
42351
diff
changeset
|
1330 APPEND(rc, "ErrorLineNumber"); |
|
74a3c6826683
Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents:
42351
diff
changeset
|
1331 APPEND(rc, "ErrorColumnNumber"); |
|
74a3c6826683
Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents:
42351
diff
changeset
|
1332 APPEND(rc, "ErrorByteIndex"); |
|
74a3c6826683
Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents:
42351
diff
changeset
|
1333 APPEND(rc, "CurrentLineNumber"); |
|
74a3c6826683
Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents:
42351
diff
changeset
|
1334 APPEND(rc, "CurrentColumnNumber"); |
|
74a3c6826683
Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents:
42351
diff
changeset
|
1335 APPEND(rc, "CurrentByteIndex"); |
|
74a3c6826683
Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents:
42351
diff
changeset
|
1336 APPEND(rc, "buffer_size"); |
|
74a3c6826683
Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents:
42351
diff
changeset
|
1337 APPEND(rc, "buffer_text"); |
|
74a3c6826683
Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents:
42351
diff
changeset
|
1338 APPEND(rc, "buffer_used"); |
|
74a3c6826683
Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents:
42351
diff
changeset
|
1339 APPEND(rc, "namespace_prefixes"); |
|
74a3c6826683
Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents:
42351
diff
changeset
|
1340 APPEND(rc, "ordered_attributes"); |
|
74a3c6826683
Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents:
42351
diff
changeset
|
1341 APPEND(rc, "specified_attributes"); |
|
74a3c6826683
Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents:
42351
diff
changeset
|
1342 APPEND(rc, "intern"); |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1343 |
|
27301
5a975e82d70f
SF # 669553, fix memory (ref) leaks
Neal Norwitz <nnorwitz@gmail.com>
parents:
26109
diff
changeset
|
1344 #undef APPEND |
|
42537
74a3c6826683
Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents:
42351
diff
changeset
|
1345 |
|
74a3c6826683
Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents:
42351
diff
changeset
|
1346 if (PyErr_Occurred()) { |
|
74a3c6826683
Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents:
42351
diff
changeset
|
1347 Py_DECREF(rc); |
|
74a3c6826683
Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents:
42351
diff
changeset
|
1348 rc = NULL; |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1349 } |
|
42537
74a3c6826683
Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents:
42351
diff
changeset
|
1350 |
|
74a3c6826683
Remove support for __members__ and __methods__. There still might be
Neal Norwitz <nnorwitz@gmail.com>
parents:
42351
diff
changeset
|
1351 return rc; |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1352 } |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1353 |
|
14186
e921228af435
initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents:
14169
diff
changeset
|
1354 static int |
|
66799
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
65367
diff
changeset
|
1355 sethandler(xmlparseobject *self, PyObject *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
|
1356 { |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1357 int handlernum = handlername2int(name); |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1358 if (handlernum >= 0) { |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1359 xmlhandler c_handler = NULL; |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1360 PyObject *temp = self->handlers[handlernum]; |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1361 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1362 if (v == Py_None) { |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1363 /* If this is the character data handler, and a character |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1364 data handler is already active, we need to be more |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1365 careful. What we can safely do is replace the existing |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1366 character data handler callback function with a no-op |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1367 function that will refuse to call Python. The downside |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1368 is that this doesn't completely remove the character |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1369 data handler from the C layer if there's any callback |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1370 active, so Expat does a little more work than it |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1371 otherwise would, but that's really an odd case. A more |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1372 elaborate system of handlers and state could remove the |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1373 C handler more effectively. */ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1374 if (handlernum == CharacterData && self->in_callback) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1375 c_handler = noop_character_data_handler; |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1376 v = NULL; |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1377 } |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1378 else if (v != NULL) { |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1379 Py_INCREF(v); |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1380 c_handler = handler_info[handlernum].handler; |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1381 } |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1382 self->handlers[handlernum] = v; |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1383 Py_XDECREF(temp); |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1384 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
|
1385 return 1; |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1386 } |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1387 return 0; |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1388 } |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1389 |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1390 static int |
|
66799
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
65367
diff
changeset
|
1391 xmlparse_setattro(xmlparseobject *self, PyObject *name, PyObject *v) |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1392 { |
|
14186
e921228af435
initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents:
14169
diff
changeset
|
1393 /* 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
|
1394 if (v == NULL) { |
|
14186
e921228af435
initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents:
14169
diff
changeset
|
1395 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
|
1396 return -1; |
|
e921228af435
initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents:
14169
diff
changeset
|
1397 } |
|
66799
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
65367
diff
changeset
|
1398 assert(PyUnicode_Check(name)); |
|
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
65367
diff
changeset
|
1399 if (PyUnicode_CompareWithASCIIString(name, "buffer_text") == 0) { |
|
24040
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
1400 if (PyObject_IsTrue(v)) { |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
1401 if (self->buffer == NULL) { |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
1402 self->buffer = malloc(self->buffer_size); |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
1403 if (self->buffer == NULL) { |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
1404 PyErr_NoMemory(); |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
1405 return -1; |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
1406 } |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
1407 self->buffer_used = 0; |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
1408 } |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
1409 } |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
1410 else if (self->buffer != NULL) { |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
1411 if (flush_character_buffer(self) < 0) |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
1412 return -1; |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
1413 free(self->buffer); |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
1414 self->buffer = NULL; |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
1415 } |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
1416 return 0; |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
1417 } |
|
66799
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
65367
diff
changeset
|
1418 if (PyUnicode_CompareWithASCIIString(name, "namespace_prefixes") == 0) { |
|
27321
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1419 if (PyObject_IsTrue(v)) |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1420 self->ns_prefixes = 1; |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1421 else |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1422 self->ns_prefixes = 0; |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1423 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
|
1424 return 0; |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1425 } |
|
66799
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
65367
diff
changeset
|
1426 if (PyUnicode_CompareWithASCIIString(name, "ordered_attributes") == 0) { |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1427 if (PyObject_IsTrue(v)) |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1428 self->ordered_attributes = 1; |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1429 else |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1430 self->ordered_attributes = 0; |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1431 return 0; |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1432 } |
|
66799
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
65367
diff
changeset
|
1433 if (PyUnicode_CompareWithASCIIString(name, "specified_attributes") == 0) { |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1434 if (PyObject_IsTrue(v)) |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1435 self->specified_attributes = 1; |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1436 else |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1437 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
|
1438 return 0; |
|
e921228af435
initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents:
14169
diff
changeset
|
1439 } |
|
44604
94ab572ed6dd
Merged revisions 59843-59863 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
1440 |
|
66799
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
65367
diff
changeset
|
1441 if (PyUnicode_CompareWithASCIIString(name, "buffer_size") == 0) { |
|
44604
94ab572ed6dd
Merged revisions 59843-59863 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
1442 long new_buffer_size; |
|
94ab572ed6dd
Merged revisions 59843-59863 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
1443 if (!PyLong_Check(v)) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1444 PyErr_SetString(PyExc_TypeError, "buffer_size must be an integer"); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1445 return -1; |
|
44604
94ab572ed6dd
Merged revisions 59843-59863 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
1446 } |
|
94ab572ed6dd
Merged revisions 59843-59863 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
1447 |
|
94ab572ed6dd
Merged revisions 59843-59863 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
1448 new_buffer_size=PyLong_AS_LONG(v); |
|
94ab572ed6dd
Merged revisions 59843-59863 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
1449 /* trivial case -- no change */ |
|
94ab572ed6dd
Merged revisions 59843-59863 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
1450 if (new_buffer_size == self->buffer_size) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1451 return 0; |
|
44604
94ab572ed6dd
Merged revisions 59843-59863 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
1452 } |
|
94ab572ed6dd
Merged revisions 59843-59863 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
1453 |
|
94ab572ed6dd
Merged revisions 59843-59863 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
1454 if (new_buffer_size <= 0) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1455 PyErr_SetString(PyExc_ValueError, "buffer_size must be greater than zero"); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1456 return -1; |
|
44604
94ab572ed6dd
Merged revisions 59843-59863 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
1457 } |
|
94ab572ed6dd
Merged revisions 59843-59863 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
1458 |
|
94ab572ed6dd
Merged revisions 59843-59863 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
1459 /* check maximum */ |
|
94ab572ed6dd
Merged revisions 59843-59863 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
1460 if (new_buffer_size > INT_MAX) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1461 char errmsg[100]; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1462 sprintf(errmsg, "buffer_size must not be greater than %i", INT_MAX); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1463 PyErr_SetString(PyExc_ValueError, errmsg); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1464 return -1; |
|
44604
94ab572ed6dd
Merged revisions 59843-59863 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
1465 } |
|
94ab572ed6dd
Merged revisions 59843-59863 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
1466 |
|
94ab572ed6dd
Merged revisions 59843-59863 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
1467 if (self->buffer != NULL) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1468 /* there is already a buffer */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1469 if (self->buffer_used != 0) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1470 flush_character_buffer(self); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1471 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1472 /* free existing buffer */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1473 free(self->buffer); |
|
44604
94ab572ed6dd
Merged revisions 59843-59863 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
1474 } |
|
94ab572ed6dd
Merged revisions 59843-59863 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
1475 self->buffer = malloc(new_buffer_size); |
|
94ab572ed6dd
Merged revisions 59843-59863 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
1476 if (self->buffer == NULL) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1477 PyErr_NoMemory(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1478 return -1; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1479 } |
|
44604
94ab572ed6dd
Merged revisions 59843-59863 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
1480 self->buffer_size = new_buffer_size; |
|
94ab572ed6dd
Merged revisions 59843-59863 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
1481 return 0; |
|
94ab572ed6dd
Merged revisions 59843-59863 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
1482 } |
|
94ab572ed6dd
Merged revisions 59843-59863 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
1483 |
|
66799
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
65367
diff
changeset
|
1484 if (PyUnicode_CompareWithASCIIString(name, "CharacterDataHandler") == 0) { |
|
24040
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
1485 /* 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
|
1486 * 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
|
1487 * "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
|
1488 * happen. |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
1489 */ |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
1490 if (flush_character_buffer(self) < 0) |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
1491 return -1; |
|
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
1492 } |
|
14186
e921228af435
initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents:
14169
diff
changeset
|
1493 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
|
1494 return 0; |
|
e921228af435
initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents:
14169
diff
changeset
|
1495 } |
|
66799
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
65367
diff
changeset
|
1496 PyErr_SetObject(PyExc_AttributeError, name); |
|
14186
e921228af435
initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents:
14169
diff
changeset
|
1497 return -1; |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1498 } |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1499 |
|
16076
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1500 static int |
|
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1501 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
|
1502 { |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36891
diff
changeset
|
1503 int i; |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36891
diff
changeset
|
1504 for (i = 0; handler_info[i].name != NULL; i++) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36891
diff
changeset
|
1505 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
|
1506 return 0; |
|
16076
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1507 } |
|
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1508 |
|
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1509 static int |
|
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1510 xmlparse_clear(xmlparseobject *op) |
|
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1511 { |
|
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
|
1512 clear_handlers(op, 0); |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36891
diff
changeset
|
1513 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
|
1514 return 0; |
|
16076
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1515 } |
|
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1516 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22421
diff
changeset
|
1517 PyDoc_STRVAR(Xmlparsetype__doc__, "XML parser"); |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1518 |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1519 static PyTypeObject Xmlparsetype = { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1520 PyVarObject_HEAD_INIT(NULL, 0) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1521 "pyexpat.xmlparser", /*tp_name*/ |
|
67333
8b848d3c6ad0
Issue #10333: Remove ancient GC API, which has been deprecated since
Antoine Pitrou <solipsis@pitrou.net>
parents:
66799
diff
changeset
|
1522 sizeof(xmlparseobject), /*tp_basicsize*/ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1523 0, /*tp_itemsize*/ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1524 /* methods */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1525 (destructor)xmlparse_dealloc, /*tp_dealloc*/ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1526 (printfunc)0, /*tp_print*/ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1527 0, /*tp_getattr*/ |
|
66799
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
65367
diff
changeset
|
1528 0, /*tp_setattr*/ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1529 0, /*tp_reserved*/ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1530 (reprfunc)0, /*tp_repr*/ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1531 0, /*tp_as_number*/ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1532 0, /*tp_as_sequence*/ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1533 0, /*tp_as_mapping*/ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1534 (hashfunc)0, /*tp_hash*/ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1535 (ternaryfunc)0, /*tp_call*/ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1536 (reprfunc)0, /*tp_str*/ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1537 (getattrofunc)xmlparse_getattro, /* tp_getattro */ |
|
66799
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
65367
diff
changeset
|
1538 (setattrofunc)xmlparse_setattro, /* tp_setattro */ |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1539 0, /* tp_as_buffer */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1540 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1541 Xmlparsetype__doc__, /* tp_doc - Documentation string */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1542 (traverseproc)xmlparse_traverse, /* tp_traverse */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1543 (inquiry)xmlparse_clear, /* tp_clear */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1544 0, /* tp_richcompare */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1545 0, /* tp_weaklistoffset */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1546 0, /* tp_iter */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1547 0, /* tp_iternext */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1548 xmlparse_methods, /* tp_methods */ |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1549 }; |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1550 |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1551 /* End of code for xmlparser objects */ |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1552 /* -------------------------------------------------------- */ |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1553 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22421
diff
changeset
|
1554 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
|
1555 "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
|
1556 Return a new XML parser object."); |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1557 |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1558 static PyObject * |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1559 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
|
1560 { |
|
17623
1686080a7c6c
ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents:
17219
diff
changeset
|
1561 char *encoding = NULL; |
|
1686080a7c6c
ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents:
17219
diff
changeset
|
1562 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
|
1563 PyObject *intern = NULL; |
|
34b8cdbbd8fe
Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents:
23832
diff
changeset
|
1564 PyObject *result; |
|
34b8cdbbd8fe
Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents:
23832
diff
changeset
|
1565 int intern_decref = 0; |
|
36675
dba6494735d0
Revert backwards-incompatible const changes.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1566 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
|
1567 "intern", NULL}; |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1568 |
|
24027
34b8cdbbd8fe
Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents:
23832
diff
changeset
|
1569 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
|
1570 &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
|
1571 return NULL; |
|
1686080a7c6c
ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents:
17219
diff
changeset
|
1572 if (namespace_separator != NULL |
|
1686080a7c6c
ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents:
17219
diff
changeset
|
1573 && strlen(namespace_separator) > 1) { |
|
1686080a7c6c
ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents:
17219
diff
changeset
|
1574 PyErr_SetString(PyExc_ValueError, |
|
1686080a7c6c
ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents:
17219
diff
changeset
|
1575 "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
|
1576 " character, omitted, or None"); |
|
1686080a7c6c
ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents:
17219
diff
changeset
|
1577 return NULL; |
|
1686080a7c6c
ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents:
17219
diff
changeset
|
1578 } |
|
24027
34b8cdbbd8fe
Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents:
23832
diff
changeset
|
1579 /* 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
|
1580 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
|
1581 if (intern == Py_None) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1582 intern = NULL; |
|
24027
34b8cdbbd8fe
Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents:
23832
diff
changeset
|
1583 else if (intern == NULL) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1584 intern = PyDict_New(); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1585 if (!intern) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1586 return NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1587 intern_decref = 1; |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1588 } |
|
24027
34b8cdbbd8fe
Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents:
23832
diff
changeset
|
1589 else if (!PyDict_Check(intern)) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1590 PyErr_SetString(PyExc_TypeError, "intern must be a dictionary"); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1591 return NULL; |
|
24027
34b8cdbbd8fe
Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents:
23832
diff
changeset
|
1592 } |
|
34b8cdbbd8fe
Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents:
23832
diff
changeset
|
1593 |
|
34b8cdbbd8fe
Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents:
23832
diff
changeset
|
1594 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
|
1595 if (intern_decref) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1596 Py_DECREF(intern); |
|
24027
34b8cdbbd8fe
Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents:
23832
diff
changeset
|
1597 } |
|
34b8cdbbd8fe
Integrate the changes from PyXML's version of pyexpat.c revisions
Fred Drake <fdrake@acm.org>
parents:
23832
diff
changeset
|
1598 return result; |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1599 } |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1600 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22421
diff
changeset
|
1601 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
|
1602 "ErrorString(errno) -> string\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22421
diff
changeset
|
1603 Returns string error for given number."); |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1604 |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1605 static PyObject * |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1606 pyexpat_ErrorString(PyObject *self, PyObject *args) |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1607 { |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1608 long code = 0; |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1609 |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1610 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
|
1611 return NULL; |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1612 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
|
1613 } |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1614 |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1615 /* List of methods defined in the module */ |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1616 |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1617 static struct PyMethodDef pyexpat_methods[] = { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1618 {"ParserCreate", (PyCFunction)pyexpat_ParserCreate, |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1619 METH_VARARGS|METH_KEYWORDS, pyexpat_ParserCreate__doc__}, |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1620 {"ErrorString", (PyCFunction)pyexpat_ErrorString, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1621 METH_VARARGS, pyexpat_ErrorString__doc__}, |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1622 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1623 {NULL, (PyCFunction)NULL, 0, NULL} /* sentinel */ |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1624 }; |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1625 |
|
13025
58661a557dc6
Added support for passing Unicode strings to Expat handlers by default.
Andrew M. Kuchling <amk@amk.ca>
parents:
12576
diff
changeset
|
1626 /* Module docstring */ |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1627 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22421
diff
changeset
|
1628 PyDoc_STRVAR(pyexpat_module_documentation, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22421
diff
changeset
|
1629 "Python wrapper for Expat parser."); |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1630 |
|
17623
1686080a7c6c
ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents:
17219
diff
changeset
|
1631 /* 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
|
1632 |
|
1686080a7c6c
ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents:
17219
diff
changeset
|
1633 #ifndef MODULE_NAME |
|
1686080a7c6c
ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents:
17219
diff
changeset
|
1634 #define MODULE_NAME "pyexpat" |
|
1686080a7c6c
ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents:
17219
diff
changeset
|
1635 #endif |
|
1686080a7c6c
ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents:
17219
diff
changeset
|
1636 |
|
1686080a7c6c
ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents:
17219
diff
changeset
|
1637 #ifndef MODULE_INITFUNC |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
1638 #define MODULE_INITFUNC PyInit_pyexpat |
|
17623
1686080a7c6c
ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents:
17219
diff
changeset
|
1639 #endif |
|
1686080a7c6c
ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents:
17219
diff
changeset
|
1640 |
|
27321
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1641 #ifndef PyMODINIT_FUNC |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1642 # ifdef MS_WINDOWS |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1643 # define PyMODINIT_FUNC __declspec(dllexport) void |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1644 # else |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1645 # define PyMODINIT_FUNC void |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1646 # endif |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1647 #endif |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1648 |
|
24315
a8df0c0be242
Land Patch [ 566100 ] Rationalize DL_IMPORT and DL_EXPORT.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24283
diff
changeset
|
1649 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
|
1650 |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
1651 static struct PyModuleDef pyexpatmodule = { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1652 PyModuleDef_HEAD_INIT, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1653 MODULE_NAME, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1654 pyexpat_module_documentation, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1655 -1, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1656 pyexpat_methods, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1657 NULL, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1658 NULL, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1659 NULL, |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1660 NULL |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
1661 }; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
1662 |
|
27321
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1663 PyMODINIT_FUNC |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1664 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
|
1665 { |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1666 PyObject *m, *d; |
| 42835 | 1667 PyObject *errmod_name = PyUnicode_FromString(MODULE_NAME ".errors"); |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1668 PyObject *errors_module; |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1669 PyObject *modelmod_name; |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1670 PyObject *model_module; |
|
70562
9c23efa3f5c7
simply use the Python version for pyexpat.__version__ #12221
Benjamin Peterson <benjamin@python.org>
parents:
65621
diff
changeset
|
1671 PyObject *version; |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1672 PyObject *sys_modules; |
|
65357
320d0fa21658
#5355: Provide mappings from Expat error numbers to string descriptions and backwards, in order to actually make it possible to analyze error codes provided by ExpatError.
Georg Brandl <georg@python.org>
parents:
64641
diff
changeset
|
1673 PyObject *tmpnum, *tmpstr; |
|
320d0fa21658
#5355: Provide mappings from Expat error numbers to string descriptions and backwards, in order to actually make it possible to analyze error codes provided by ExpatError.
Georg Brandl <georg@python.org>
parents:
64641
diff
changeset
|
1674 PyObject *codes_dict; |
|
320d0fa21658
#5355: Provide mappings from Expat error numbers to string descriptions and backwards, in order to actually make it possible to analyze error codes provided by ExpatError.
Georg Brandl <georg@python.org>
parents:
64641
diff
changeset
|
1675 PyObject *rev_codes_dict; |
|
320d0fa21658
#5355: Provide mappings from Expat error numbers to string descriptions and backwards, in order to actually make it possible to analyze error codes provided by ExpatError.
Georg Brandl <georg@python.org>
parents:
64641
diff
changeset
|
1676 int res; |
|
36018
c253e993df8a
renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents:
36017
diff
changeset
|
1677 static struct PyExpat_CAPI capi; |
|
65357
320d0fa21658
#5355: Provide mappings from Expat error numbers to string descriptions and backwards, in order to actually make it possible to analyze error codes provided by ExpatError.
Georg Brandl <georg@python.org>
parents:
64641
diff
changeset
|
1678 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
|
1679 |
|
14186
e921228af435
initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents:
14169
diff
changeset
|
1680 if (errmod_name == NULL) |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
1681 return NULL; |
| 42835 | 1682 modelmod_name = PyUnicode_FromString(MODULE_NAME ".model"); |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1683 if (modelmod_name == NULL) |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
1684 return NULL; |
|
14186
e921228af435
initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents:
14169
diff
changeset
|
1685 |
|
48414
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
1686 if (PyType_Ready(&Xmlparsetype) < 0) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1687 return NULL; |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1688 |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1689 /* Create the module and add the functions */ |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
1690 m = PyModule_Create(&pyexpatmodule); |
|
36324
1af7f719ed28
Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36090
diff
changeset
|
1691 if (m == NULL) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1692 return NULL; |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1693 |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1694 /* 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
|
1695 if (ErrorObject == NULL) { |
|
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
1696 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
|
1697 NULL, NULL); |
|
16601
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
1698 if (ErrorObject == NULL) |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
1699 return NULL; |
|
16601
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
1700 } |
|
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
1701 Py_INCREF(ErrorObject); |
|
14788
179e098238e8
Change the name of the exception from "pyexpat.error" to
Fred Drake <fdrake@acm.org>
parents:
14755
diff
changeset
|
1702 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
|
1703 Py_INCREF(ErrorObject); |
|
0b455a428967
xmlparseobject: Remove the unused conv_attrs field, added an
Fred Drake <fdrake@acm.org>
parents:
16476
diff
changeset
|
1704 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
|
1705 Py_INCREF(&Xmlparsetype); |
|
ab3438cf1f3e
ParserCreate(): Added test that the namespace_separator value, if given,
Fred Drake <fdrake@acm.org>
parents:
14932
diff
changeset
|
1706 PyModule_AddObject(m, "XMLParserType", (PyObject *) &Xmlparsetype); |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1707 |
|
70562
9c23efa3f5c7
simply use the Python version for pyexpat.__version__ #12221
Benjamin Peterson <benjamin@python.org>
parents:
65621
diff
changeset
|
1708 version = PyUnicode_FromString(PY_VERSION); |
|
9c23efa3f5c7
simply use the Python version for pyexpat.__version__ #12221
Benjamin Peterson <benjamin@python.org>
parents:
65621
diff
changeset
|
1709 if (!version) |
|
70571
0639e630426c
return NULL on error
Benjamin Peterson <benjamin@python.org>
parents:
70562
diff
changeset
|
1710 return NULL; |
|
70562
9c23efa3f5c7
simply use the Python version for pyexpat.__version__ #12221
Benjamin Peterson <benjamin@python.org>
parents:
65621
diff
changeset
|
1711 PyModule_AddObject(m, "__version__", version); |
|
15642
19c8a2d3807d
When using the latest & greatest version of Expat (currently in the Expat
Fred Drake <fdrake@acm.org>
parents:
15600
diff
changeset
|
1712 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
|
1713 (char *) XML_ExpatVersion()); |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1714 { |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1715 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
|
1716 PyModule_AddObject(m, "version_info", |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1717 Py_BuildValue("(iii)", info.major, |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1718 info.minor, info.micro)); |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1719 } |
|
16076
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1720 init_template_buffer(); |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1721 /* 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
|
1722 compiled, this should check and set native_encoding |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1723 appropriately. |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1724 */ |
|
14788
179e098238e8
Change the name of the exception from "pyexpat.error" to
Fred Drake <fdrake@acm.org>
parents:
14755
diff
changeset
|
1725 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
|
1726 |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1727 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
|
1728 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
|
1729 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
|
1730 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
|
1731 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
|
1732 if (errors_module != NULL) { |
|
e921228af435
initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents:
14169
diff
changeset
|
1733 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
|
1734 /* 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
|
1735 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
|
1736 } |
|
91deadfdae36
Remove the Py_FatalError() from initpyexpat(); the Guido has decreed
Fred Drake <fdrake@acm.org>
parents:
13654
diff
changeset
|
1737 } |
|
14186
e921228af435
initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents:
14169
diff
changeset
|
1738 Py_DECREF(errmod_name); |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1739 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
|
1740 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
|
1741 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
|
1742 if (model_module != NULL) { |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1743 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
|
1744 /* 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
|
1745 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
|
1746 } |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1747 } |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1748 Py_DECREF(modelmod_name); |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1749 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
|
1750 /* Don't core dump later! */ |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
1751 return NULL; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1752 |
|
27322
88bf10313584
Conditionalize features not found in PyXML 1.95.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
27321
diff
changeset
|
1753 #if XML_COMBINED_VERSION > 19505 |
|
27321
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1754 { |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1755 const XML_Feature *features = XML_GetFeatureList(); |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1756 PyObject *list = PyList_New(0); |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1757 if (list == NULL) |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1758 /* just ignore it */ |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1759 PyErr_Clear(); |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1760 else { |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1761 int i = 0; |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1762 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
|
1763 int ok; |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1764 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
|
1765 features[i].value); |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1766 if (item == NULL) { |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1767 Py_DECREF(list); |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1768 list = NULL; |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1769 break; |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1770 } |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1771 ok = PyList_Append(list, item); |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1772 Py_DECREF(item); |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1773 if (ok < 0) { |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1774 PyErr_Clear(); |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1775 break; |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1776 } |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1777 } |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1778 if (list != NULL) |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1779 PyModule_AddObject(m, "features", list); |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1780 } |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1781 } |
|
27322
88bf10313584
Conditionalize features not found in PyXML 1.95.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
27321
diff
changeset
|
1782 #endif |
|
14186
e921228af435
initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents:
14169
diff
changeset
|
1783 |
|
65357
320d0fa21658
#5355: Provide mappings from Expat error numbers to string descriptions and backwards, in order to actually make it possible to analyze error codes provided by ExpatError.
Georg Brandl <georg@python.org>
parents:
64641
diff
changeset
|
1784 codes_dict = PyDict_New(); |
|
320d0fa21658
#5355: Provide mappings from Expat error numbers to string descriptions and backwards, in order to actually make it possible to analyze error codes provided by ExpatError.
Georg Brandl <georg@python.org>
parents:
64641
diff
changeset
|
1785 rev_codes_dict = PyDict_New(); |
|
320d0fa21658
#5355: Provide mappings from Expat error numbers to string descriptions and backwards, in order to actually make it possible to analyze error codes provided by ExpatError.
Georg Brandl <georg@python.org>
parents:
64641
diff
changeset
|
1786 if (codes_dict == NULL || rev_codes_dict == NULL) { |
|
320d0fa21658
#5355: Provide mappings from Expat error numbers to string descriptions and backwards, in order to actually make it possible to analyze error codes provided by ExpatError.
Georg Brandl <georg@python.org>
parents:
64641
diff
changeset
|
1787 Py_XDECREF(codes_dict); |
|
320d0fa21658
#5355: Provide mappings from Expat error numbers to string descriptions and backwards, in order to actually make it possible to analyze error codes provided by ExpatError.
Georg Brandl <georg@python.org>
parents:
64641
diff
changeset
|
1788 Py_XDECREF(rev_codes_dict); |
|
320d0fa21658
#5355: Provide mappings from Expat error numbers to string descriptions and backwards, in order to actually make it possible to analyze error codes provided by ExpatError.
Georg Brandl <georg@python.org>
parents:
64641
diff
changeset
|
1789 return NULL; |
|
320d0fa21658
#5355: Provide mappings from Expat error numbers to string descriptions and backwards, in order to actually make it possible to analyze error codes provided by ExpatError.
Georg Brandl <georg@python.org>
parents:
64641
diff
changeset
|
1790 } |
|
67347
3bf4d9f1660a
Issue #9566: use Py_ssize_t instead of int
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67333
diff
changeset
|
1791 |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1792 #define MYCONST(name) \ |
|
65357
320d0fa21658
#5355: Provide mappings from Expat error numbers to string descriptions and backwards, in order to actually make it possible to analyze error codes provided by ExpatError.
Georg Brandl <georg@python.org>
parents:
64641
diff
changeset
|
1793 if (PyModule_AddStringConstant(errors_module, #name, \ |
|
320d0fa21658
#5355: Provide mappings from Expat error numbers to string descriptions and backwards, in order to actually make it possible to analyze error codes provided by ExpatError.
Georg Brandl <georg@python.org>
parents:
64641
diff
changeset
|
1794 (char *)XML_ErrorString(name)) < 0) \ |
|
320d0fa21658
#5355: Provide mappings from Expat error numbers to string descriptions and backwards, in order to actually make it possible to analyze error codes provided by ExpatError.
Georg Brandl <georg@python.org>
parents:
64641
diff
changeset
|
1795 return NULL; \ |
|
320d0fa21658
#5355: Provide mappings from Expat error numbers to string descriptions and backwards, in order to actually make it possible to analyze error codes provided by ExpatError.
Georg Brandl <georg@python.org>
parents:
64641
diff
changeset
|
1796 tmpnum = PyLong_FromLong(name); \ |
|
320d0fa21658
#5355: Provide mappings from Expat error numbers to string descriptions and backwards, in order to actually make it possible to analyze error codes provided by ExpatError.
Georg Brandl <georg@python.org>
parents:
64641
diff
changeset
|
1797 if (tmpnum == NULL) return NULL; \ |
|
320d0fa21658
#5355: Provide mappings from Expat error numbers to string descriptions and backwards, in order to actually make it possible to analyze error codes provided by ExpatError.
Georg Brandl <georg@python.org>
parents:
64641
diff
changeset
|
1798 res = PyDict_SetItemString(codes_dict, \ |
|
320d0fa21658
#5355: Provide mappings from Expat error numbers to string descriptions and backwards, in order to actually make it possible to analyze error codes provided by ExpatError.
Georg Brandl <georg@python.org>
parents:
64641
diff
changeset
|
1799 XML_ErrorString(name), tmpnum); \ |
|
320d0fa21658
#5355: Provide mappings from Expat error numbers to string descriptions and backwards, in order to actually make it possible to analyze error codes provided by ExpatError.
Georg Brandl <georg@python.org>
parents:
64641
diff
changeset
|
1800 if (res < 0) return NULL; \ |
|
320d0fa21658
#5355: Provide mappings from Expat error numbers to string descriptions and backwards, in order to actually make it possible to analyze error codes provided by ExpatError.
Georg Brandl <georg@python.org>
parents:
64641
diff
changeset
|
1801 tmpstr = PyUnicode_FromString(XML_ErrorString(name)); \ |
|
320d0fa21658
#5355: Provide mappings from Expat error numbers to string descriptions and backwards, in order to actually make it possible to analyze error codes provided by ExpatError.
Georg Brandl <georg@python.org>
parents:
64641
diff
changeset
|
1802 if (tmpstr == NULL) return NULL; \ |
|
320d0fa21658
#5355: Provide mappings from Expat error numbers to string descriptions and backwards, in order to actually make it possible to analyze error codes provided by ExpatError.
Georg Brandl <georg@python.org>
parents:
64641
diff
changeset
|
1803 res = PyDict_SetItem(rev_codes_dict, tmpnum, tmpstr); \ |
|
320d0fa21658
#5355: Provide mappings from Expat error numbers to string descriptions and backwards, in order to actually make it possible to analyze error codes provided by ExpatError.
Georg Brandl <georg@python.org>
parents:
64641
diff
changeset
|
1804 Py_DECREF(tmpstr); \ |
|
320d0fa21658
#5355: Provide mappings from Expat error numbers to string descriptions and backwards, in order to actually make it possible to analyze error codes provided by ExpatError.
Georg Brandl <georg@python.org>
parents:
64641
diff
changeset
|
1805 Py_DECREF(tmpnum); \ |
|
320d0fa21658
#5355: Provide mappings from Expat error numbers to string descriptions and backwards, in order to actually make it possible to analyze error codes provided by ExpatError.
Georg Brandl <georg@python.org>
parents:
64641
diff
changeset
|
1806 if (res < 0) return NULL; \ |
|
13344
c3029f276047
pyexpat.errors is a *strange* module!
Fred Drake <fdrake@acm.org>
parents:
13340
diff
changeset
|
1807 |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1808 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
|
1809 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
|
1810 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
|
1811 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
|
1812 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
|
1813 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
|
1814 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
|
1815 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
|
1816 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
|
1817 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
|
1818 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
|
1819 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
|
1820 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
|
1821 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
|
1822 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
|
1823 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
|
1824 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
|
1825 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
|
1826 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
|
1827 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
|
1828 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
|
1829 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
|
1830 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
|
1831 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
|
1832 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
|
1833 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
|
1834 /* 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
|
1835 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
|
1836 /* 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
|
1837 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
|
1838 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
|
1839 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
|
1840 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
|
1841 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
|
1842 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
|
1843 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
|
1844 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
|
1845 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
|
1846 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
|
1847 |
|
65357
320d0fa21658
#5355: Provide mappings from Expat error numbers to string descriptions and backwards, in order to actually make it possible to analyze error codes provided by ExpatError.
Georg Brandl <georg@python.org>
parents:
64641
diff
changeset
|
1848 if (PyModule_AddStringConstant(errors_module, "__doc__", |
|
320d0fa21658
#5355: Provide mappings from Expat error numbers to string descriptions and backwards, in order to actually make it possible to analyze error codes provided by ExpatError.
Georg Brandl <georg@python.org>
parents:
64641
diff
changeset
|
1849 "Constants used to describe " |
|
320d0fa21658
#5355: Provide mappings from Expat error numbers to string descriptions and backwards, in order to actually make it possible to analyze error codes provided by ExpatError.
Georg Brandl <georg@python.org>
parents:
64641
diff
changeset
|
1850 "error conditions.") < 0) |
|
320d0fa21658
#5355: Provide mappings from Expat error numbers to string descriptions and backwards, in order to actually make it possible to analyze error codes provided by ExpatError.
Georg Brandl <georg@python.org>
parents:
64641
diff
changeset
|
1851 return NULL; |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1852 |
|
65357
320d0fa21658
#5355: Provide mappings from Expat error numbers to string descriptions and backwards, in order to actually make it possible to analyze error codes provided by ExpatError.
Georg Brandl <georg@python.org>
parents:
64641
diff
changeset
|
1853 if (PyModule_AddObject(errors_module, "codes", codes_dict) < 0) |
|
320d0fa21658
#5355: Provide mappings from Expat error numbers to string descriptions and backwards, in order to actually make it possible to analyze error codes provided by ExpatError.
Georg Brandl <georg@python.org>
parents:
64641
diff
changeset
|
1854 return NULL; |
|
320d0fa21658
#5355: Provide mappings from Expat error numbers to string descriptions and backwards, in order to actually make it possible to analyze error codes provided by ExpatError.
Georg Brandl <georg@python.org>
parents:
64641
diff
changeset
|
1855 if (PyModule_AddObject(errors_module, "messages", rev_codes_dict) < 0) |
|
320d0fa21658
#5355: Provide mappings from Expat error numbers to string descriptions and backwards, in order to actually make it possible to analyze error codes provided by ExpatError.
Georg Brandl <georg@python.org>
parents:
64641
diff
changeset
|
1856 return NULL; |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1857 |
|
14788
179e098238e8
Change the name of the exception from "pyexpat.error" to
Fred Drake <fdrake@acm.org>
parents:
14755
diff
changeset
|
1858 #undef MYCONST |
|
16076
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1859 |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1860 #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
|
1861 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
|
1862 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
|
1863 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
|
1864 #undef MYCONST |
|
16076
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1865 |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1866 #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
|
1867 PyModule_AddStringConstant(model_module, "__doc__", |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1868 "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
|
1869 |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1870 MYCONST(XML_CTYPE_EMPTY); |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1871 MYCONST(XML_CTYPE_ANY); |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1872 MYCONST(XML_CTYPE_MIXED); |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1873 MYCONST(XML_CTYPE_NAME); |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1874 MYCONST(XML_CTYPE_CHOICE); |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1875 MYCONST(XML_CTYPE_SEQ); |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1876 |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1877 MYCONST(XML_CQUANT_NONE); |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1878 MYCONST(XML_CQUANT_OPT); |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1879 MYCONST(XML_CQUANT_REP); |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1880 MYCONST(XML_CQUANT_PLUS); |
|
16076
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1881 #undef MYCONST |
|
36017
ed347c436d58
added cobject-based expat dispatch mechanism to pyexpat
Fredrik Lundh <fredrik@pythonware.com>
parents:
35999
diff
changeset
|
1882 |
|
ed347c436d58
added cobject-based expat dispatch mechanism to pyexpat
Fredrik Lundh <fredrik@pythonware.com>
parents:
35999
diff
changeset
|
1883 /* initialize pyexpat dispatch table */ |
|
36018
c253e993df8a
renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents:
36017
diff
changeset
|
1884 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
|
1885 capi.magic = PyExpat_CAPI_MAGIC; |
|
36018
c253e993df8a
renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents:
36017
diff
changeset
|
1886 capi.MAJOR_VERSION = XML_MAJOR_VERSION; |
|
c253e993df8a
renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents:
36017
diff
changeset
|
1887 capi.MINOR_VERSION = XML_MINOR_VERSION; |
|
c253e993df8a
renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents:
36017
diff
changeset
|
1888 capi.MICRO_VERSION = XML_MICRO_VERSION; |
|
c253e993df8a
renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents:
36017
diff
changeset
|
1889 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
|
1890 capi.GetErrorCode = XML_GetErrorCode; |
|
68817315b74c
moved magic into structure (mainly to simplify the client code)
Fredrik Lundh <fredrik@pythonware.com>
parents:
36018
diff
changeset
|
1891 capi.GetErrorColumnNumber = XML_GetErrorColumnNumber; |
|
68817315b74c
moved magic into structure (mainly to simplify the client code)
Fredrik Lundh <fredrik@pythonware.com>
parents:
36018
diff
changeset
|
1892 capi.GetErrorLineNumber = XML_GetErrorLineNumber; |
|
36018
c253e993df8a
renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents:
36017
diff
changeset
|
1893 capi.Parse = XML_Parse; |
|
c253e993df8a
renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents:
36017
diff
changeset
|
1894 capi.ParserCreate_MM = XML_ParserCreate_MM; |
|
c253e993df8a
renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents:
36017
diff
changeset
|
1895 capi.ParserFree = XML_ParserFree; |
|
c253e993df8a
renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents:
36017
diff
changeset
|
1896 capi.SetCharacterDataHandler = XML_SetCharacterDataHandler; |
|
c253e993df8a
renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents:
36017
diff
changeset
|
1897 capi.SetCommentHandler = XML_SetCommentHandler; |
|
c253e993df8a
renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents:
36017
diff
changeset
|
1898 capi.SetDefaultHandlerExpand = XML_SetDefaultHandlerExpand; |
|
c253e993df8a
renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents:
36017
diff
changeset
|
1899 capi.SetElementHandler = XML_SetElementHandler; |
|
c253e993df8a
renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents:
36017
diff
changeset
|
1900 capi.SetNamespaceDeclHandler = XML_SetNamespaceDeclHandler; |
|
c253e993df8a
renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents:
36017
diff
changeset
|
1901 capi.SetProcessingInstructionHandler = XML_SetProcessingInstructionHandler; |
|
c253e993df8a
renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents:
36017
diff
changeset
|
1902 capi.SetUnknownEncodingHandler = XML_SetUnknownEncodingHandler; |
|
c253e993df8a
renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents:
36017
diff
changeset
|
1903 capi.SetUserData = XML_SetUserData; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1904 |
|
53816
911df82bc25d
add a replacement API for PyCObject, PyCapsule #5630
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1905 /* export using capsule */ |
|
911df82bc25d
add a replacement API for PyCObject, PyCapsule #5630
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
1906 capi_object = PyCapsule_New(&capi, PyExpat_CAPSULE_NAME, NULL); |
|
36018
c253e993df8a
renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents:
36017
diff
changeset
|
1907 if (capi_object) |
|
c253e993df8a
renamed dispatch -> capi to match other CAPI implementations
Fredrik Lundh <fredrik@pythonware.com>
parents:
36017
diff
changeset
|
1908 PyModule_AddObject(m, "expat_CAPI", capi_object); |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
1909 return m; |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1910 } |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1911 |
|
14186
e921228af435
initpyexpat(): Code cleanup; makes it more robust and reduces warnings.
Fred Drake <fdrake@acm.org>
parents:
14169
diff
changeset
|
1912 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
|
1913 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
|
1914 { |
|
17623
1686080a7c6c
ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents:
17219
diff
changeset
|
1915 int i = 0; |
|
1686080a7c6c
ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents:
17219
diff
changeset
|
1916 PyObject *temp; |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1917 |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1918 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
|
1919 if (initial) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1920 self->handlers[i] = NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1921 else { |
|
17623
1686080a7c6c
ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents:
17219
diff
changeset
|
1922 temp = self->handlers[i]; |
|
1686080a7c6c
ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents:
17219
diff
changeset
|
1923 self->handlers[i] = NULL; |
|
1686080a7c6c
ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents:
17219
diff
changeset
|
1924 Py_XDECREF(temp); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
54812
diff
changeset
|
1925 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
|
1926 } |
|
1686080a7c6c
ParserCreate(): Allow an empty string for the namespace_separator argument;
Fred Drake <fdrake@acm.org>
parents:
17219
diff
changeset
|
1927 } |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1928 } |
|
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1929 |
|
24283
c0a67a1cab09
Removed more stray instances of statichere, but left _sre.c alone.
Tim Peters <tim.peters@gmail.com>
parents:
24280
diff
changeset
|
1930 static struct HandlerInfo handler_info[] = { |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1931 {"StartElementHandler", |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1932 (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
|
1933 (xmlhandler)my_StartElementHandler}, |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1934 {"EndElementHandler", |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1935 (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
|
1936 (xmlhandler)my_EndElementHandler}, |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1937 {"ProcessingInstructionHandler", |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1938 (xmlhandlersetter)XML_SetProcessingInstructionHandler, |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1939 (xmlhandler)my_ProcessingInstructionHandler}, |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1940 {"CharacterDataHandler", |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1941 (xmlhandlersetter)XML_SetCharacterDataHandler, |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1942 (xmlhandler)my_CharacterDataHandler}, |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1943 {"UnparsedEntityDeclHandler", |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1944 (xmlhandlersetter)XML_SetUnparsedEntityDeclHandler, |
|
24040
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
1945 (xmlhandler)my_UnparsedEntityDeclHandler}, |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1946 {"NotationDeclHandler", |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1947 (xmlhandlersetter)XML_SetNotationDeclHandler, |
|
24040
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
1948 (xmlhandler)my_NotationDeclHandler}, |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1949 {"StartNamespaceDeclHandler", |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1950 (xmlhandlersetter)XML_SetStartNamespaceDeclHandler, |
|
24040
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
1951 (xmlhandler)my_StartNamespaceDeclHandler}, |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1952 {"EndNamespaceDeclHandler", |
|
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1953 (xmlhandlersetter)XML_SetEndNamespaceDeclHandler, |
|
24040
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
1954 (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
|
1955 {"CommentHandler", |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1956 (xmlhandlersetter)XML_SetCommentHandler, |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1957 (xmlhandler)my_CommentHandler}, |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1958 {"StartCdataSectionHandler", |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1959 (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
|
1960 (xmlhandler)my_StartCdataSectionHandler}, |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1961 {"EndCdataSectionHandler", |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1962 (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
|
1963 (xmlhandler)my_EndCdataSectionHandler}, |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1964 {"DefaultHandler", |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1965 (xmlhandlersetter)XML_SetDefaultHandler, |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1966 (xmlhandler)my_DefaultHandler}, |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1967 {"DefaultHandlerExpand", |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1968 (xmlhandlersetter)XML_SetDefaultHandlerExpand, |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1969 (xmlhandler)my_DefaultHandlerExpandHandler}, |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1970 {"NotStandaloneHandler", |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1971 (xmlhandlersetter)XML_SetNotStandaloneHandler, |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1972 (xmlhandler)my_NotStandaloneHandler}, |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1973 {"ExternalEntityRefHandler", |
|
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
1974 (xmlhandlersetter)XML_SetExternalEntityRefHandler, |
|
24040
a78d41ee9474
Added character data buffering to pyexpat parser objects.
Fred Drake <fdrake@acm.org>
parents:
24037
diff
changeset
|
1975 (xmlhandler)my_ExternalEntityRefHandler}, |
|
16076
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1976 {"StartDoctypeDeclHandler", |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1977 (xmlhandlersetter)XML_SetStartDoctypeDeclHandler, |
|
16076
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1978 (xmlhandler)my_StartDoctypeDeclHandler}, |
|
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1979 {"EndDoctypeDeclHandler", |
|
24037
2c2245aacef8
pyexpat code cleanup and minor refactorings:
Fred Drake <fdrake@acm.org>
parents:
24027
diff
changeset
|
1980 (xmlhandlersetter)XML_SetEndDoctypeDeclHandler, |
|
16076
eabd008b36ee
Merge with 1.25 of PyXML:
Martin v. Löwis <martin@v.loewis.de>
parents:
15703
diff
changeset
|
1981 (xmlhandler)my_EndDoctypeDeclHandler}, |
|
16476
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1982 {"EntityDeclHandler", |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1983 (xmlhandlersetter)XML_SetEntityDeclHandler, |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1984 (xmlhandler)my_EntityDeclHandler}, |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1985 {"XmlDeclHandler", |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1986 (xmlhandlersetter)XML_SetXmlDeclHandler, |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1987 (xmlhandler)my_XmlDeclHandler}, |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1988 {"ElementDeclHandler", |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1989 (xmlhandlersetter)XML_SetElementDeclHandler, |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1990 (xmlhandler)my_ElementDeclHandler}, |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1991 {"AttlistDeclHandler", |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1992 (xmlhandlersetter)XML_SetAttlistDeclHandler, |
|
f7b167c83318
set_error(): Handle construction of pyexpat.error exceptions. They
Fred Drake <fdrake@acm.org>
parents:
16463
diff
changeset
|
1993 (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
|
1994 #if XML_COMBINED_VERSION >= 19504 |
|
27321
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1995 {"SkippedEntityHandler", |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1996 (xmlhandlersetter)XML_SetSkippedEntityHandler, |
|
299ef2dabb52
Merge with PyXML 1.71:
Martin v. Löwis <martin@v.loewis.de>
parents:
27301
diff
changeset
|
1997 (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
|
1998 #endif |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1999 |
|
13568
ac2bb7708320
Convert coding style to be internally consistent and similar to the
Fred Drake <fdrake@acm.org>
parents:
13559
diff
changeset
|
2000 {NULL, NULL, NULL} /* sentinel */ |
|
12182
c888792de6a7
Added Python interface to Expat XML parser.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
2001 }; |
