Fred Drake | 4113b13 | 2001-03-24 19:58:26 +0000 | [diff] [blame] | 1 | #include <ctype.h> |
| 2 | |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 3 | #include "Python.h" |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 4 | #include "compile.h" |
| 5 | #include "frameobject.h" |
Fred Drake | a77254a | 2000-09-29 19:23:29 +0000 | [diff] [blame] | 6 | #ifdef HAVE_EXPAT_H |
| 7 | #include "expat.h" |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 8 | #ifdef XML_MAJOR_VERSION |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 9 | #define EXPAT_VERSION (0x10000 * XML_MAJOR_VERSION \ |
| 10 | + 0x100 * XML_MINOR_VERSION \ |
| 11 | + XML_MICRO_VERSION) |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 12 | #else |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 13 | /* Assume the oldest Expat that used expat.h and did not have version info */ |
| 14 | #define EXPAT_VERSION 0x015f00 |
| 15 | #endif |
| 16 | #else /* !defined(HAVE_EXPAT_H) */ |
| 17 | #include "xmlparse.h" |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 18 | /* Assume Expat 1.1 unless told otherwise */ |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 19 | #ifndef EXPAT_VERSION |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 20 | #define EXPAT_VERSION 0x010100 |
| 21 | #endif |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 22 | #endif /* !defined(HAVE_EXPAT_H) */ |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 23 | |
| 24 | #ifndef PyGC_HEAD_SIZE |
| 25 | #define PyGC_HEAD_SIZE 0 |
| 26 | #define PyObject_GC_Init(x) |
| 27 | #define PyObject_GC_Fini(m) |
| 28 | #define Py_TPFLAGS_GC 0 |
| 29 | #endif |
| 30 | |
Martin v. Löwis | 339d0f7 | 2001-08-17 18:39:25 +0000 | [diff] [blame] | 31 | #if (PY_MAJOR_VERSION == 1 && PY_MINOR_VERSION > 5) || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 2) |
| 32 | /* In Python 1.6, 2.0 and 2.1, disabling Unicode was not possible. */ |
| 33 | #define Py_USING_UNICODE |
| 34 | #endif |
| 35 | |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 36 | enum HandlerTypes { |
| 37 | StartElement, |
| 38 | EndElement, |
| 39 | ProcessingInstruction, |
| 40 | CharacterData, |
| 41 | UnparsedEntityDecl, |
| 42 | NotationDecl, |
| 43 | StartNamespaceDecl, |
| 44 | EndNamespaceDecl, |
| 45 | Comment, |
| 46 | StartCdataSection, |
| 47 | EndCdataSection, |
| 48 | Default, |
| 49 | DefaultHandlerExpand, |
| 50 | NotStandalone, |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 51 | ExternalEntityRef, |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 52 | #if EXPAT_VERSION >= 0x010200 |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 53 | StartDoctypeDecl, |
| 54 | EndDoctypeDecl, |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 55 | #endif |
| 56 | #if EXPAT_VERSION == 0x010200 |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 57 | ExternalParsedEntityDecl, |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 58 | InternalParsedEntityDecl, |
| 59 | #endif |
| 60 | #if EXPAT_VERSION >= 0x015f00 |
| 61 | EntityDecl, |
| 62 | XmlDecl, |
| 63 | ElementDecl, |
| 64 | AttlistDecl, |
| 65 | #endif |
| 66 | _DummyDecl |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | static PyObject *ErrorObject; |
| 70 | |
| 71 | /* ----------------------------------------------------- */ |
| 72 | |
| 73 | /* Declarations for objects of type xmlparser */ |
| 74 | |
| 75 | typedef struct { |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 76 | PyObject_HEAD |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 77 | |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 78 | XML_Parser itself; |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 79 | int returns_unicode; /* True if Unicode strings are returned; |
| 80 | if false, UTF-8 strings are returned */ |
| 81 | int ordered_attributes; /* Return attributes as a list. */ |
| 82 | int specified_attributes; /* Report only specified attributes. */ |
Fred Drake | bd6101c | 2001-02-14 18:29:45 +0000 | [diff] [blame] | 83 | int in_callback; /* Is a callback active? */ |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 84 | PyObject **handlers; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 85 | } xmlparseobject; |
| 86 | |
| 87 | staticforward PyTypeObject Xmlparsetype; |
| 88 | |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 89 | typedef void (*xmlhandlersetter)(XML_Parser *self, void *meth); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 90 | typedef void* xmlhandler; |
| 91 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 92 | struct HandlerInfo { |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 93 | const char *name; |
| 94 | xmlhandlersetter setter; |
| 95 | xmlhandler handler; |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 96 | PyCodeObject *tb_code; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 97 | }; |
| 98 | |
Andrew M. Kuchling | 637f664 | 2000-07-04 14:53:43 +0000 | [diff] [blame] | 99 | staticforward struct HandlerInfo handler_info[64]; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 100 | |
Fred Drake | bd6101c | 2001-02-14 18:29:45 +0000 | [diff] [blame] | 101 | /* Set an integer attribute on the error object; return true on success, |
| 102 | * false on an exception. |
| 103 | */ |
| 104 | static int |
| 105 | set_error_attr(PyObject *err, char *name, int value) |
| 106 | { |
| 107 | PyObject *v = PyInt_FromLong(value); |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 108 | |
Fred Drake | bd6101c | 2001-02-14 18:29:45 +0000 | [diff] [blame] | 109 | if (v != NULL && PyObject_SetAttrString(err, name, v) == -1) { |
| 110 | Py_DECREF(v); |
| 111 | return 0; |
| 112 | } |
| 113 | return 1; |
| 114 | } |
| 115 | |
| 116 | /* Build and set an Expat exception, including positioning |
| 117 | * information. Always returns NULL. |
| 118 | */ |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 119 | static PyObject * |
| 120 | set_error(xmlparseobject *self) |
| 121 | { |
| 122 | PyObject *err; |
| 123 | char buffer[256]; |
| 124 | XML_Parser parser = self->itself; |
Fred Drake | bd6101c | 2001-02-14 18:29:45 +0000 | [diff] [blame] | 125 | int lineno = XML_GetErrorLineNumber(parser); |
| 126 | int column = XML_GetErrorColumnNumber(parser); |
| 127 | enum XML_Error code = XML_GetErrorCode(parser); |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 128 | |
| 129 | sprintf(buffer, "%.200s: line %i, column %i", |
Fred Drake | bd6101c | 2001-02-14 18:29:45 +0000 | [diff] [blame] | 130 | XML_ErrorString(code), lineno, column); |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 131 | err = PyObject_CallFunction(ErrorObject, "s", buffer); |
Fred Drake | bd6101c | 2001-02-14 18:29:45 +0000 | [diff] [blame] | 132 | if ( err != NULL |
| 133 | && set_error_attr(err, "code", code) |
| 134 | && set_error_attr(err, "offset", column) |
| 135 | && set_error_attr(err, "lineno", lineno)) { |
| 136 | PyErr_SetObject(ErrorObject, err); |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 137 | } |
| 138 | return NULL; |
| 139 | } |
| 140 | |
| 141 | |
| 142 | #if EXPAT_VERSION == 0x010200 |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 143 | /* Convert an array of attributes and their values into a Python dict */ |
| 144 | |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 145 | static PyObject * |
| 146 | conv_atts_using_string(XML_Char **atts) |
Andrew M. Kuchling | a4e75d7 | 2000-07-12 00:53:41 +0000 | [diff] [blame] | 147 | { |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 148 | PyObject *attrs_obj = NULL; |
| 149 | XML_Char **attrs_p, **attrs_k = NULL; |
| 150 | int attrs_len; |
| 151 | PyObject *rv; |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 152 | |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 153 | if ((attrs_obj = PyDict_New()) == NULL) |
| 154 | goto finally; |
| 155 | for (attrs_len = 0, attrs_p = atts; |
| 156 | *attrs_p; |
| 157 | attrs_p++, attrs_len++) { |
| 158 | if (attrs_len % 2) { |
| 159 | rv = PyString_FromString(*attrs_p); |
| 160 | if (!rv) { |
| 161 | Py_DECREF(attrs_obj); |
| 162 | attrs_obj = NULL; |
| 163 | goto finally; |
| 164 | } |
| 165 | if (PyDict_SetItemString(attrs_obj, |
| 166 | (char*)*attrs_k, rv) < 0) { |
| 167 | Py_DECREF(attrs_obj); |
| 168 | attrs_obj = NULL; |
| 169 | goto finally; |
| 170 | } |
| 171 | Py_DECREF(rv); |
| 172 | } |
| 173 | else |
| 174 | attrs_k = attrs_p; |
| 175 | } |
| 176 | finally: |
| 177 | return attrs_obj; |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 178 | } |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 179 | #endif |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 180 | |
Martin v. Löwis | 339d0f7 | 2001-08-17 18:39:25 +0000 | [diff] [blame] | 181 | #ifdef Py_USING_UNICODE |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 182 | #if EXPAT_VERSION == 0x010200 |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 183 | static PyObject * |
| 184 | conv_atts_using_unicode(XML_Char **atts) |
| 185 | { |
Fred Drake | ca1f426 | 2000-09-21 20:10:23 +0000 | [diff] [blame] | 186 | PyObject *attrs_obj; |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 187 | XML_Char **attrs_p, **attrs_k = NULL; |
| 188 | int attrs_len; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 189 | |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 190 | if ((attrs_obj = PyDict_New()) == NULL) |
| 191 | goto finally; |
| 192 | for (attrs_len = 0, attrs_p = atts; |
| 193 | *attrs_p; |
| 194 | attrs_p++, attrs_len++) { |
| 195 | if (attrs_len % 2) { |
| 196 | PyObject *attr_str, *value_str; |
| 197 | const char *p = (const char *) (*attrs_k); |
| 198 | attr_str = PyUnicode_DecodeUTF8(p, strlen(p), "strict"); |
| 199 | if (!attr_str) { |
| 200 | Py_DECREF(attrs_obj); |
| 201 | attrs_obj = NULL; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 202 | goto finally; |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 203 | } |
| 204 | p = (const char *) *attrs_p; |
| 205 | value_str = PyUnicode_DecodeUTF8(p, strlen(p), "strict"); |
| 206 | if (!value_str) { |
| 207 | Py_DECREF(attrs_obj); |
| 208 | Py_DECREF(attr_str); |
| 209 | attrs_obj = NULL; |
| 210 | goto finally; |
| 211 | } |
| 212 | if (PyDict_SetItem(attrs_obj, attr_str, value_str) < 0) { |
| 213 | Py_DECREF(attrs_obj); |
Fred Drake | ca1f426 | 2000-09-21 20:10:23 +0000 | [diff] [blame] | 214 | Py_DECREF(attr_str); |
| 215 | Py_DECREF(value_str); |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 216 | attrs_obj = NULL; |
| 217 | goto finally; |
| 218 | } |
| 219 | Py_DECREF(attr_str); |
| 220 | Py_DECREF(value_str); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 221 | } |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 222 | else |
| 223 | attrs_k = attrs_p; |
| 224 | } |
| 225 | finally: |
| 226 | return attrs_obj; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 227 | } |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 228 | #endif |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 229 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 230 | /* Convert a string of XML_Chars into a Unicode string. |
| 231 | Returns None if str is a null pointer. */ |
| 232 | |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 233 | static PyObject * |
| 234 | conv_string_to_unicode(XML_Char *str) |
| 235 | { |
| 236 | /* XXX currently this code assumes that XML_Char is 8-bit, |
| 237 | and hence in UTF-8. */ |
| 238 | /* UTF-8 from Expat, Unicode desired */ |
| 239 | if (str == NULL) { |
| 240 | Py_INCREF(Py_None); |
| 241 | return Py_None; |
| 242 | } |
| 243 | return PyUnicode_DecodeUTF8((const char *)str, |
| 244 | strlen((const char *)str), |
| 245 | "strict"); |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 246 | } |
| 247 | |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 248 | static PyObject * |
| 249 | conv_string_len_to_unicode(const XML_Char *str, int len) |
| 250 | { |
| 251 | /* XXX currently this code assumes that XML_Char is 8-bit, |
| 252 | and hence in UTF-8. */ |
| 253 | /* UTF-8 from Expat, Unicode desired */ |
| 254 | if (str == NULL) { |
| 255 | Py_INCREF(Py_None); |
| 256 | return Py_None; |
| 257 | } |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 258 | return PyUnicode_DecodeUTF8((const char *)str, len, "strict"); |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 259 | } |
| 260 | #endif |
| 261 | |
| 262 | /* Convert a string of XML_Chars into an 8-bit Python string. |
| 263 | Returns None if str is a null pointer. */ |
| 264 | |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 265 | static PyObject * |
| 266 | conv_string_to_utf8(XML_Char *str) |
| 267 | { |
| 268 | /* XXX currently this code assumes that XML_Char is 8-bit, |
| 269 | and hence in UTF-8. */ |
| 270 | /* UTF-8 from Expat, UTF-8 desired */ |
| 271 | if (str == NULL) { |
| 272 | Py_INCREF(Py_None); |
| 273 | return Py_None; |
| 274 | } |
| 275 | return PyString_FromString((const char *)str); |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 276 | } |
| 277 | |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 278 | static PyObject * |
| 279 | conv_string_len_to_utf8(const XML_Char *str, int len) |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 280 | { |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 281 | /* XXX currently this code assumes that XML_Char is 8-bit, |
| 282 | and hence in UTF-8. */ |
| 283 | /* UTF-8 from Expat, UTF-8 desired */ |
| 284 | if (str == NULL) { |
| 285 | Py_INCREF(Py_None); |
| 286 | return Py_None; |
| 287 | } |
| 288 | return PyString_FromStringAndSize((const char *)str, len); |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 289 | } |
| 290 | |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 291 | /* Callback routines */ |
| 292 | |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 293 | static void clear_handlers(xmlparseobject *self, int decref); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 294 | |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 295 | static void |
| 296 | flag_error(xmlparseobject *self) |
| 297 | { |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 298 | clear_handlers(self, 1); |
| 299 | } |
| 300 | |
| 301 | static PyCodeObject* |
| 302 | getcode(enum HandlerTypes slot, char* func_name, int lineno) |
| 303 | { |
Fred Drake | bd6101c | 2001-02-14 18:29:45 +0000 | [diff] [blame] | 304 | PyObject *code = NULL; |
| 305 | PyObject *name = NULL; |
| 306 | PyObject *nulltuple = NULL; |
| 307 | PyObject *filename = NULL; |
| 308 | |
| 309 | if (handler_info[slot].tb_code == NULL) { |
| 310 | code = PyString_FromString(""); |
| 311 | if (code == NULL) |
| 312 | goto failed; |
| 313 | name = PyString_FromString(func_name); |
| 314 | if (name == NULL) |
| 315 | goto failed; |
| 316 | nulltuple = PyTuple_New(0); |
| 317 | if (nulltuple == NULL) |
| 318 | goto failed; |
| 319 | filename = PyString_FromString(__FILE__); |
| 320 | handler_info[slot].tb_code = |
| 321 | PyCode_New(0, /* argcount */ |
| 322 | 0, /* nlocals */ |
| 323 | 0, /* stacksize */ |
| 324 | 0, /* flags */ |
| 325 | code, /* code */ |
| 326 | nulltuple, /* consts */ |
| 327 | nulltuple, /* names */ |
| 328 | nulltuple, /* varnames */ |
Martin v. Löwis | 76192ee | 2001-02-06 09:34:40 +0000 | [diff] [blame] | 329 | #if PYTHON_API_VERSION >= 1010 |
Fred Drake | bd6101c | 2001-02-14 18:29:45 +0000 | [diff] [blame] | 330 | nulltuple, /* freevars */ |
| 331 | nulltuple, /* cellvars */ |
Martin v. Löwis | 76192ee | 2001-02-06 09:34:40 +0000 | [diff] [blame] | 332 | #endif |
Fred Drake | bd6101c | 2001-02-14 18:29:45 +0000 | [diff] [blame] | 333 | filename, /* filename */ |
| 334 | name, /* name */ |
| 335 | lineno, /* firstlineno */ |
| 336 | code /* lnotab */ |
| 337 | ); |
| 338 | if (handler_info[slot].tb_code == NULL) |
| 339 | goto failed; |
| 340 | Py_DECREF(code); |
| 341 | Py_DECREF(nulltuple); |
| 342 | Py_DECREF(filename); |
| 343 | Py_DECREF(name); |
| 344 | } |
| 345 | return handler_info[slot].tb_code; |
| 346 | failed: |
| 347 | Py_XDECREF(code); |
| 348 | Py_XDECREF(name); |
| 349 | return NULL; |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | static PyObject* |
| 353 | call_with_frame(PyCodeObject *c, PyObject* func, PyObject* args) |
| 354 | { |
Fred Drake | bd6101c | 2001-02-14 18:29:45 +0000 | [diff] [blame] | 355 | PyThreadState *tstate = PyThreadState_GET(); |
| 356 | PyFrameObject *f; |
| 357 | PyObject *res; |
| 358 | |
| 359 | if (c == NULL) |
| 360 | return NULL; |
| 361 | f = PyFrame_New( |
| 362 | tstate, /*back*/ |
| 363 | c, /*code*/ |
| 364 | tstate->frame->f_globals, /*globals*/ |
| 365 | NULL /*locals*/ |
Fred Drake | bd6101c | 2001-02-14 18:29:45 +0000 | [diff] [blame] | 366 | ); |
| 367 | if (f == NULL) |
| 368 | return NULL; |
| 369 | tstate->frame = f; |
| 370 | res = PyEval_CallObject(func, args); |
| 371 | if (res == NULL && tstate->curexc_traceback == NULL) |
| 372 | PyTraceBack_Here(f); |
| 373 | tstate->frame = f->f_back; |
| 374 | Py_DECREF(f); |
| 375 | return res; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 376 | } |
| 377 | |
Martin v. Löwis | 339d0f7 | 2001-08-17 18:39:25 +0000 | [diff] [blame] | 378 | #ifndef Py_USING_UNICODE |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 379 | #define STRING_CONV_FUNC conv_string_to_utf8 |
| 380 | #else |
| 381 | /* Python 1.6 and later versions */ |
| 382 | #define STRING_CONV_FUNC (self->returns_unicode \ |
| 383 | ? conv_string_to_unicode : conv_string_to_utf8) |
| 384 | #endif |
Guido van Rossum | 5961f5a | 2000-03-31 16:18:11 +0000 | [diff] [blame] | 385 | |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 386 | static void |
| 387 | my_StartElementHandler(void *userData, |
| 388 | const XML_Char *name, const XML_Char **atts) |
| 389 | { |
| 390 | xmlparseobject *self = (xmlparseobject *)userData; |
| 391 | |
| 392 | if (self->handlers[StartElement] |
| 393 | && self->handlers[StartElement] != Py_None) { |
| 394 | PyObject *container, *rv, *args; |
| 395 | int i, max; |
| 396 | |
| 397 | /* Set max to the number of slots filled in atts[]; max/2 is |
| 398 | * the number of attributes we need to process. |
| 399 | */ |
| 400 | if (self->specified_attributes) { |
| 401 | max = XML_GetSpecifiedAttributeCount(self->itself); |
| 402 | } |
| 403 | else { |
| 404 | max = 0; |
| 405 | while (atts[max] != NULL) |
| 406 | max += 2; |
| 407 | } |
| 408 | /* Build the container. */ |
| 409 | if (self->ordered_attributes) |
| 410 | container = PyList_New(max); |
| 411 | else |
| 412 | container = PyDict_New(); |
| 413 | if (container == NULL) { |
| 414 | flag_error(self); |
| 415 | return; |
| 416 | } |
| 417 | for (i = 0; i < max; i += 2) { |
| 418 | PyObject *n = STRING_CONV_FUNC((XML_Char *) atts[i]); |
| 419 | PyObject *v; |
| 420 | if (n == NULL) { |
| 421 | flag_error(self); |
| 422 | Py_DECREF(container); |
| 423 | return; |
| 424 | } |
| 425 | v = STRING_CONV_FUNC((XML_Char *) atts[i+1]); |
| 426 | if (v == NULL) { |
| 427 | flag_error(self); |
| 428 | Py_DECREF(container); |
| 429 | Py_DECREF(n); |
| 430 | return; |
| 431 | } |
| 432 | if (self->ordered_attributes) { |
| 433 | PyList_SET_ITEM(container, i, n); |
| 434 | PyList_SET_ITEM(container, i+1, v); |
| 435 | } |
| 436 | else if (PyDict_SetItem(container, n, v)) { |
| 437 | flag_error(self); |
| 438 | Py_DECREF(n); |
| 439 | Py_DECREF(v); |
| 440 | return; |
| 441 | } |
| 442 | else { |
| 443 | Py_DECREF(n); |
| 444 | Py_DECREF(v); |
| 445 | } |
| 446 | } |
| 447 | args = Py_BuildValue("(O&N)", STRING_CONV_FUNC,name, container); |
| 448 | if (args == NULL) { |
| 449 | Py_DECREF(container); |
| 450 | return; |
| 451 | } |
| 452 | /* Container is now a borrowed reference; ignore it. */ |
Fred Drake | bd6101c | 2001-02-14 18:29:45 +0000 | [diff] [blame] | 453 | self->in_callback = 1; |
| 454 | rv = call_with_frame(getcode(StartElement, "StartElement", __LINE__), |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 455 | self->handlers[StartElement], args); |
Fred Drake | bd6101c | 2001-02-14 18:29:45 +0000 | [diff] [blame] | 456 | self->in_callback = 0; |
| 457 | Py_DECREF(args); |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 458 | if (rv == NULL) { |
| 459 | flag_error(self); |
| 460 | return; |
Fred Drake | bd6101c | 2001-02-14 18:29:45 +0000 | [diff] [blame] | 461 | } |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 462 | Py_DECREF(rv); |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | #define RC_HANDLER(RC, NAME, PARAMS, INIT, PARAM_FORMAT, CONVERSION, \ |
| 467 | RETURN, GETUSERDATA) \ |
| 468 | static RC \ |
| 469 | my_##NAME##Handler PARAMS {\ |
| 470 | xmlparseobject *self = GETUSERDATA ; \ |
| 471 | PyObject *args = NULL; \ |
| 472 | PyObject *rv = NULL; \ |
| 473 | INIT \ |
| 474 | \ |
| 475 | if (self->handlers[NAME] \ |
| 476 | && self->handlers[NAME] != Py_None) { \ |
| 477 | args = Py_BuildValue PARAM_FORMAT ;\ |
| 478 | if (!args) \ |
| 479 | return RETURN; \ |
Fred Drake | bd6101c | 2001-02-14 18:29:45 +0000 | [diff] [blame] | 480 | self->in_callback = 1; \ |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 481 | rv = call_with_frame(getcode(NAME,#NAME,__LINE__), \ |
| 482 | self->handlers[NAME], args); \ |
Fred Drake | bd6101c | 2001-02-14 18:29:45 +0000 | [diff] [blame] | 483 | self->in_callback = 0; \ |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 484 | Py_DECREF(args); \ |
| 485 | if (rv == NULL) { \ |
| 486 | flag_error(self); \ |
| 487 | return RETURN; \ |
| 488 | } \ |
| 489 | CONVERSION \ |
| 490 | Py_DECREF(rv); \ |
| 491 | } \ |
| 492 | return RETURN; \ |
| 493 | } |
| 494 | |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 495 | #define VOID_HANDLER(NAME, PARAMS, PARAM_FORMAT) \ |
| 496 | RC_HANDLER(void, NAME, PARAMS, ;, PARAM_FORMAT, ;, ;,\ |
| 497 | (xmlparseobject *)userData) |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 498 | |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 499 | #define INT_HANDLER(NAME, PARAMS, PARAM_FORMAT)\ |
| 500 | RC_HANDLER(int, NAME, PARAMS, int rc=0;, PARAM_FORMAT, \ |
| 501 | rc = PyInt_AsLong(rv);, rc, \ |
| 502 | (xmlparseobject *)userData) |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 503 | |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 504 | VOID_HANDLER(EndElement, |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 505 | (void *userData, const XML_Char *name), |
| 506 | ("(O&)", STRING_CONV_FUNC, name)) |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 507 | |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 508 | VOID_HANDLER(ProcessingInstruction, |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 509 | (void *userData, |
| 510 | const XML_Char *target, |
| 511 | const XML_Char *data), |
| 512 | ("(O&O&)",STRING_CONV_FUNC,target, STRING_CONV_FUNC,data)) |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 513 | |
Martin v. Löwis | 339d0f7 | 2001-08-17 18:39:25 +0000 | [diff] [blame] | 514 | #ifndef Py_USING_UNICODE |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 515 | VOID_HANDLER(CharacterData, |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 516 | (void *userData, const XML_Char *data, int len), |
| 517 | ("(N)", conv_string_len_to_utf8(data,len))) |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 518 | #else |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 519 | VOID_HANDLER(CharacterData, |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 520 | (void *userData, const XML_Char *data, int len), |
| 521 | ("(N)", (self->returns_unicode |
| 522 | ? conv_string_len_to_unicode(data,len) |
| 523 | : conv_string_len_to_utf8(data,len)))) |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 524 | #endif |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 525 | |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 526 | VOID_HANDLER(UnparsedEntityDecl, |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 527 | (void *userData, |
| 528 | const XML_Char *entityName, |
| 529 | const XML_Char *base, |
| 530 | const XML_Char *systemId, |
| 531 | const XML_Char *publicId, |
| 532 | const XML_Char *notationName), |
| 533 | ("(O&O&O&O&O&)", |
| 534 | STRING_CONV_FUNC,entityName, STRING_CONV_FUNC,base, |
| 535 | STRING_CONV_FUNC,systemId, STRING_CONV_FUNC,publicId, |
| 536 | STRING_CONV_FUNC,notationName)) |
| 537 | |
| 538 | #if EXPAT_VERSION >= 0x015f00 |
Martin v. Löwis | 339d0f7 | 2001-08-17 18:39:25 +0000 | [diff] [blame] | 539 | #ifndef Py_USING_UNICODE |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 540 | VOID_HANDLER(EntityDecl, |
| 541 | (void *userData, |
| 542 | const XML_Char *entityName, |
| 543 | int is_parameter_entity, |
| 544 | const XML_Char *value, |
| 545 | int value_length, |
| 546 | const XML_Char *base, |
| 547 | const XML_Char *systemId, |
| 548 | const XML_Char *publicId, |
| 549 | const XML_Char *notationName), |
| 550 | ("O&iNO&O&O&O&", |
| 551 | STRING_CONV_FUNC,entityName, is_parameter_entity, |
| 552 | conv_string_len_to_utf8(value, value_length), |
| 553 | STRING_CONV_FUNC,base, STRING_CONV_FUNC,systemId, |
| 554 | STRING_CONV_FUNC,publicId, STRING_CONV_FUNC,notationName)) |
| 555 | #else |
| 556 | VOID_HANDLER(EntityDecl, |
| 557 | (void *userData, |
| 558 | const XML_Char *entityName, |
| 559 | int is_parameter_entity, |
| 560 | const XML_Char *value, |
| 561 | int value_length, |
| 562 | const XML_Char *base, |
| 563 | const XML_Char *systemId, |
| 564 | const XML_Char *publicId, |
| 565 | const XML_Char *notationName), |
| 566 | ("O&iNO&O&O&O&", |
| 567 | STRING_CONV_FUNC,entityName, is_parameter_entity, |
| 568 | (self->returns_unicode |
| 569 | ? conv_string_len_to_unicode(value, value_length) |
| 570 | : conv_string_len_to_utf8(value, value_length)), |
| 571 | STRING_CONV_FUNC,base, STRING_CONV_FUNC,systemId, |
| 572 | STRING_CONV_FUNC,publicId, STRING_CONV_FUNC,notationName)) |
| 573 | #endif |
| 574 | |
| 575 | VOID_HANDLER(XmlDecl, |
| 576 | (void *userData, |
| 577 | const XML_Char *version, |
| 578 | const XML_Char *encoding, |
| 579 | int standalone), |
| 580 | ("(O&O&i)", |
| 581 | STRING_CONV_FUNC,version, STRING_CONV_FUNC,encoding, |
| 582 | standalone)) |
| 583 | |
| 584 | static PyObject * |
| 585 | conv_content_model(XML_Content * const model, |
| 586 | PyObject *(*conv_string)(XML_Char *)) |
| 587 | { |
| 588 | PyObject *result = NULL; |
| 589 | PyObject *children = PyTuple_New(model->numchildren); |
| 590 | int i; |
| 591 | |
| 592 | if (children != NULL) { |
Tim Peters | 9544fc5 | 2001-07-28 09:36:36 +0000 | [diff] [blame] | 593 | assert(model->numchildren < INT_MAX); |
| 594 | for (i = 0; i < (int)model->numchildren; ++i) { |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 595 | PyObject *child = conv_content_model(&model->children[i], |
| 596 | conv_string); |
| 597 | if (child == NULL) { |
| 598 | Py_XDECREF(children); |
| 599 | return NULL; |
| 600 | } |
| 601 | PyTuple_SET_ITEM(children, i, child); |
| 602 | } |
| 603 | result = Py_BuildValue("(iiO&N)", |
| 604 | model->type, model->quant, |
| 605 | conv_string,model->name, children); |
| 606 | } |
| 607 | return result; |
| 608 | } |
| 609 | |
| 610 | static PyObject * |
| 611 | conv_content_model_utf8(XML_Content * const model) |
| 612 | { |
| 613 | return conv_content_model(model, conv_string_to_utf8); |
| 614 | } |
| 615 | |
Martin v. Löwis | 339d0f7 | 2001-08-17 18:39:25 +0000 | [diff] [blame] | 616 | #ifdef Py_USING_UNICODE |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 617 | static PyObject * |
| 618 | conv_content_model_unicode(XML_Content * const model) |
| 619 | { |
| 620 | return conv_content_model(model, conv_string_to_unicode); |
| 621 | } |
| 622 | |
| 623 | VOID_HANDLER(ElementDecl, |
| 624 | (void *userData, |
| 625 | const XML_Char *name, |
| 626 | XML_Content *model), |
| 627 | ("O&O&", |
| 628 | STRING_CONV_FUNC,name, |
| 629 | (self->returns_unicode ? conv_content_model_unicode |
| 630 | : conv_content_model_utf8),model)) |
| 631 | #else |
| 632 | VOID_HANDLER(ElementDecl, |
| 633 | (void *userData, |
| 634 | const XML_Char *name, |
| 635 | XML_Content *model), |
| 636 | ("O&O&", |
| 637 | STRING_CONV_FUNC,name, conv_content_model_utf8,model)) |
| 638 | #endif |
| 639 | |
| 640 | VOID_HANDLER(AttlistDecl, |
| 641 | (void *userData, |
| 642 | const XML_Char *elname, |
| 643 | const XML_Char *attname, |
| 644 | const XML_Char *att_type, |
| 645 | const XML_Char *dflt, |
| 646 | int isrequired), |
| 647 | ("(O&O&O&O&i)", |
| 648 | STRING_CONV_FUNC,elname, STRING_CONV_FUNC,attname, |
| 649 | STRING_CONV_FUNC,att_type, STRING_CONV_FUNC,dflt, |
| 650 | isrequired)) |
| 651 | #endif |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 652 | |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 653 | VOID_HANDLER(NotationDecl, |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 654 | (void *userData, |
| 655 | const XML_Char *notationName, |
| 656 | const XML_Char *base, |
| 657 | const XML_Char *systemId, |
| 658 | const XML_Char *publicId), |
| 659 | ("(O&O&O&O&)", |
| 660 | STRING_CONV_FUNC,notationName, STRING_CONV_FUNC,base, |
| 661 | STRING_CONV_FUNC,systemId, STRING_CONV_FUNC,publicId)) |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 662 | |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 663 | VOID_HANDLER(StartNamespaceDecl, |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 664 | (void *userData, |
| 665 | const XML_Char *prefix, |
| 666 | const XML_Char *uri), |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 667 | ("(O&O&)", STRING_CONV_FUNC,prefix, STRING_CONV_FUNC,uri)) |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 668 | |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 669 | VOID_HANDLER(EndNamespaceDecl, |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 670 | (void *userData, |
| 671 | const XML_Char *prefix), |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 672 | ("(O&)", STRING_CONV_FUNC,prefix)) |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 673 | |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 674 | VOID_HANDLER(Comment, |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 675 | (void *userData, const XML_Char *prefix), |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 676 | ("(O&)", STRING_CONV_FUNC,prefix)) |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 677 | |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 678 | VOID_HANDLER(StartCdataSection, |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 679 | (void *userData), |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 680 | ("()")) |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 681 | |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 682 | VOID_HANDLER(EndCdataSection, |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 683 | (void *userData), |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 684 | ("()")) |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 685 | |
Martin v. Löwis | 339d0f7 | 2001-08-17 18:39:25 +0000 | [diff] [blame] | 686 | #ifndef Py_USING_UNICODE |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 687 | VOID_HANDLER(Default, |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 688 | (void *userData, const XML_Char *s, int len), |
Fred Drake | ca1f426 | 2000-09-21 20:10:23 +0000 | [diff] [blame] | 689 | ("(N)", conv_string_len_to_utf8(s,len))) |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 690 | |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 691 | VOID_HANDLER(DefaultHandlerExpand, |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 692 | (void *userData, const XML_Char *s, int len), |
Fred Drake | ca1f426 | 2000-09-21 20:10:23 +0000 | [diff] [blame] | 693 | ("(N)", conv_string_len_to_utf8(s,len))) |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 694 | #else |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 695 | VOID_HANDLER(Default, |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 696 | (void *userData, const XML_Char *s, int len), |
Fred Drake | ca1f426 | 2000-09-21 20:10:23 +0000 | [diff] [blame] | 697 | ("(N)", (self->returns_unicode |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 698 | ? conv_string_len_to_unicode(s,len) |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 699 | : conv_string_len_to_utf8(s,len)))) |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 700 | |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 701 | VOID_HANDLER(DefaultHandlerExpand, |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 702 | (void *userData, const XML_Char *s, int len), |
Fred Drake | ca1f426 | 2000-09-21 20:10:23 +0000 | [diff] [blame] | 703 | ("(N)", (self->returns_unicode |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 704 | ? conv_string_len_to_unicode(s,len) |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 705 | : conv_string_len_to_utf8(s,len)))) |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 706 | #endif |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 707 | |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 708 | INT_HANDLER(NotStandalone, |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 709 | (void *userData), |
| 710 | ("()")) |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 711 | |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 712 | RC_HANDLER(int, ExternalEntityRef, |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 713 | (XML_Parser parser, |
| 714 | const XML_Char *context, |
| 715 | const XML_Char *base, |
| 716 | const XML_Char *systemId, |
| 717 | const XML_Char *publicId), |
| 718 | int rc=0;, |
| 719 | ("(O&O&O&O&)", |
| 720 | STRING_CONV_FUNC,context, STRING_CONV_FUNC,base, |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 721 | STRING_CONV_FUNC,systemId, STRING_CONV_FUNC,publicId), |
| 722 | rc = PyInt_AsLong(rv);, rc, |
| 723 | XML_GetUserData(parser)) |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 724 | |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 725 | /* XXX UnknownEncodingHandler */ |
| 726 | |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 727 | #if EXPAT_VERSION == 0x010200 |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 728 | VOID_HANDLER(StartDoctypeDecl, |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 729 | (void *userData, const XML_Char *doctypeName), |
| 730 | ("(O&OOi)", STRING_CONV_FUNC,doctypeName, |
| 731 | Py_None, Py_None, -1)) |
| 732 | #elif EXPAT_VERSION >= 0x015f00 |
| 733 | VOID_HANDLER(StartDoctypeDecl, |
| 734 | (void *userData, const XML_Char *doctypeName, |
| 735 | const XML_Char *sysid, const XML_Char *pubid, |
| 736 | int has_internal_subset), |
| 737 | ("(O&O&O&i)", STRING_CONV_FUNC,doctypeName, |
| 738 | STRING_CONV_FUNC,sysid, STRING_CONV_FUNC,pubid, |
| 739 | has_internal_subset)) |
| 740 | #endif |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 741 | |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 742 | #if EXPAT_VERSION >= 0x010200 |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 743 | VOID_HANDLER(EndDoctypeDecl, (void *userData), ("()")) |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 744 | #endif |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 745 | |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 746 | #if EXPAT_VERSION == 0x010200 |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 747 | VOID_HANDLER(ExternalParsedEntityDecl, |
| 748 | (void *userData, const XML_Char *entityName, |
| 749 | const XML_Char *base, const XML_Char *systemId, |
| 750 | const XML_Char *publicId), |
| 751 | ("(O&O&O&O&)", STRING_CONV_FUNC, entityName, |
| 752 | STRING_CONV_FUNC, base, STRING_CONV_FUNC, systemId, |
| 753 | STRING_CONV_FUNC, publicId)) |
| 754 | |
| 755 | VOID_HANDLER(InternalParsedEntityDecl, |
| 756 | (void *userData, const XML_Char *entityName, |
| 757 | const XML_Char *replacementText, int replacementTextLength), |
| 758 | ("(O&O&i)", STRING_CONV_FUNC, entityName, |
| 759 | STRING_CONV_FUNC, replacementText, replacementTextLength)) |
| 760 | |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 761 | #endif /* Expat version 1.2 & better */ |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 762 | |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 763 | /* ---------------------------------------------------------------- */ |
| 764 | |
| 765 | static char xmlparse_Parse__doc__[] = |
Thomas Wouters | 3531730 | 2000-07-22 16:34:15 +0000 | [diff] [blame] | 766 | "Parse(data[, isfinal])\n\ |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 767 | Parse XML data. `isfinal' should be true at end of input."; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 768 | |
| 769 | static PyObject * |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 770 | xmlparse_Parse(xmlparseobject *self, PyObject *args) |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 771 | { |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 772 | char *s; |
| 773 | int slen; |
| 774 | int isFinal = 0; |
| 775 | int rv; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 776 | |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 777 | if (!PyArg_ParseTuple(args, "s#|i:Parse", &s, &slen, &isFinal)) |
| 778 | return NULL; |
| 779 | rv = XML_Parse(self->itself, s, slen, isFinal); |
| 780 | if (PyErr_Occurred()) { |
| 781 | return NULL; |
| 782 | } |
| 783 | else if (rv == 0) { |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 784 | return set_error(self); |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 785 | } |
| 786 | return PyInt_FromLong(rv); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 787 | } |
| 788 | |
Fred Drake | ca1f426 | 2000-09-21 20:10:23 +0000 | [diff] [blame] | 789 | /* File reading copied from cPickle */ |
| 790 | |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 791 | #define BUF_SIZE 2048 |
| 792 | |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 793 | static int |
| 794 | readinst(char *buf, int buf_size, PyObject *meth) |
| 795 | { |
| 796 | PyObject *arg = NULL; |
| 797 | PyObject *bytes = NULL; |
| 798 | PyObject *str = NULL; |
| 799 | int len = -1; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 800 | |
Fred Drake | 676940b | 2000-09-22 15:21:31 +0000 | [diff] [blame] | 801 | if ((bytes = PyInt_FromLong(buf_size)) == NULL) |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 802 | goto finally; |
Fred Drake | 676940b | 2000-09-22 15:21:31 +0000 | [diff] [blame] | 803 | |
Fred Drake | ca1f426 | 2000-09-21 20:10:23 +0000 | [diff] [blame] | 804 | if ((arg = PyTuple_New(1)) == NULL) |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 805 | goto finally; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 806 | |
Tim Peters | 954eef7 | 2000-09-22 06:01:11 +0000 | [diff] [blame] | 807 | PyTuple_SET_ITEM(arg, 0, bytes); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 808 | |
Fred Drake | ca1f426 | 2000-09-21 20:10:23 +0000 | [diff] [blame] | 809 | if ((str = PyObject_CallObject(meth, arg)) == NULL) |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 810 | goto finally; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 811 | |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 812 | /* XXX what to do if it returns a Unicode string? */ |
Fred Drake | ca1f426 | 2000-09-21 20:10:23 +0000 | [diff] [blame] | 813 | if (!PyString_Check(str)) { |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 814 | PyErr_Format(PyExc_TypeError, |
| 815 | "read() did not return a string object (type=%.400s)", |
| 816 | str->ob_type->tp_name); |
| 817 | goto finally; |
| 818 | } |
| 819 | len = PyString_GET_SIZE(str); |
| 820 | if (len > buf_size) { |
| 821 | PyErr_Format(PyExc_ValueError, |
| 822 | "read() returned too much data: " |
| 823 | "%i bytes requested, %i returned", |
| 824 | buf_size, len); |
| 825 | Py_DECREF(str); |
| 826 | goto finally; |
| 827 | } |
| 828 | memcpy(buf, PyString_AsString(str), len); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 829 | finally: |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 830 | Py_XDECREF(arg); |
Fred Drake | ca1f426 | 2000-09-21 20:10:23 +0000 | [diff] [blame] | 831 | Py_XDECREF(str); |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 832 | return len; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | static char xmlparse_ParseFile__doc__[] = |
Thomas Wouters | 3531730 | 2000-07-22 16:34:15 +0000 | [diff] [blame] | 836 | "ParseFile(file)\n\ |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 837 | Parse XML data from file-like object."; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 838 | |
| 839 | static PyObject * |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 840 | xmlparse_ParseFile(xmlparseobject *self, PyObject *args) |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 841 | { |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 842 | int rv = 1; |
| 843 | PyObject *f; |
| 844 | FILE *fp; |
| 845 | PyObject *readmethod = NULL; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 846 | |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 847 | if (!PyArg_ParseTuple(args, "O:ParseFile", &f)) |
| 848 | return NULL; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 849 | |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 850 | if (PyFile_Check(f)) { |
| 851 | fp = PyFile_AsFile(f); |
| 852 | } |
| 853 | else{ |
| 854 | fp = NULL; |
Fred Drake | ca1f426 | 2000-09-21 20:10:23 +0000 | [diff] [blame] | 855 | readmethod = PyObject_GetAttrString(f, "read"); |
| 856 | if (readmethod == NULL) { |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 857 | PyErr_Clear(); |
| 858 | PyErr_SetString(PyExc_TypeError, |
| 859 | "argument must have 'read' attribute"); |
| 860 | return 0; |
| 861 | } |
| 862 | } |
| 863 | for (;;) { |
| 864 | int bytes_read; |
| 865 | void *buf = XML_GetBuffer(self->itself, BUF_SIZE); |
| 866 | if (buf == NULL) |
| 867 | return PyErr_NoMemory(); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 868 | |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 869 | if (fp) { |
| 870 | bytes_read = fread(buf, sizeof(char), BUF_SIZE, fp); |
| 871 | if (bytes_read < 0) { |
| 872 | PyErr_SetFromErrno(PyExc_IOError); |
| 873 | return NULL; |
| 874 | } |
| 875 | } |
| 876 | else { |
| 877 | bytes_read = readinst(buf, BUF_SIZE, readmethod); |
| 878 | if (bytes_read < 0) |
| 879 | return NULL; |
| 880 | } |
| 881 | rv = XML_ParseBuffer(self->itself, bytes_read, bytes_read == 0); |
| 882 | if (PyErr_Occurred()) |
| 883 | return NULL; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 884 | |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 885 | if (!rv || bytes_read == 0) |
| 886 | break; |
| 887 | } |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 888 | if (rv == 0) { |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 889 | return set_error(self); |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 890 | } |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 891 | return Py_BuildValue("i", rv); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 892 | } |
| 893 | |
| 894 | static char xmlparse_SetBase__doc__[] = |
Thomas Wouters | 3531730 | 2000-07-22 16:34:15 +0000 | [diff] [blame] | 895 | "SetBase(base_url)\n\ |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 896 | Set the base URL for the parser."; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 897 | |
| 898 | static PyObject * |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 899 | xmlparse_SetBase(xmlparseobject *self, PyObject *args) |
| 900 | { |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 901 | char *base; |
| 902 | |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 903 | if (!PyArg_ParseTuple(args, "s:SetBase", &base)) |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 904 | return NULL; |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 905 | if (!XML_SetBase(self->itself, base)) { |
| 906 | return PyErr_NoMemory(); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 907 | } |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 908 | Py_INCREF(Py_None); |
| 909 | return Py_None; |
| 910 | } |
| 911 | |
| 912 | static char xmlparse_GetBase__doc__[] = |
Thomas Wouters | 3531730 | 2000-07-22 16:34:15 +0000 | [diff] [blame] | 913 | "GetBase() -> url\n\ |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 914 | Return base URL string for the parser."; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 915 | |
| 916 | static PyObject * |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 917 | xmlparse_GetBase(xmlparseobject *self, PyObject *args) |
| 918 | { |
| 919 | if (!PyArg_ParseTuple(args, ":GetBase")) |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 920 | return NULL; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 921 | |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 922 | return Py_BuildValue("z", XML_GetBase(self->itself)); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 923 | } |
| 924 | |
Fred Drake | bd6101c | 2001-02-14 18:29:45 +0000 | [diff] [blame] | 925 | #if EXPAT_VERSION >= 0x015f00 |
| 926 | static char xmlparse_GetInputContext__doc__[] = |
| 927 | "GetInputContext() -> string\n\ |
| 928 | Return the untranslated text of the input that caused the current event.\n\ |
| 929 | If the event was generated by a large amount of text (such as a start tag\n\ |
| 930 | for an element with many attributes), not all of the text may be available."; |
| 931 | |
| 932 | static PyObject * |
| 933 | xmlparse_GetInputContext(xmlparseobject *self, PyObject *args) |
| 934 | { |
| 935 | PyObject *result = NULL; |
| 936 | |
| 937 | if (PyArg_ParseTuple(args, ":GetInputContext")) { |
| 938 | if (self->in_callback) { |
| 939 | int offset, size; |
| 940 | const char *buffer |
| 941 | = XML_GetInputContext(self->itself, &offset, &size); |
| 942 | |
| 943 | if (buffer != NULL) |
| 944 | result = PyString_FromStringAndSize(buffer + offset, size); |
| 945 | else { |
| 946 | result = Py_None; |
| 947 | Py_INCREF(result); |
| 948 | } |
| 949 | } |
| 950 | else { |
| 951 | result = Py_None; |
| 952 | Py_INCREF(result); |
| 953 | } |
| 954 | } |
| 955 | return result; |
| 956 | } |
| 957 | #endif |
| 958 | |
Lars Gustäbel | 4a30a07 | 2000-09-24 20:50:52 +0000 | [diff] [blame] | 959 | static char xmlparse_ExternalEntityParserCreate__doc__[] = |
Fred Drake | 2d4ac20 | 2001-01-03 15:36:25 +0000 | [diff] [blame] | 960 | "ExternalEntityParserCreate(context[, encoding])\n\ |
Tim Peters | 51dc968 | 2000-09-24 22:12:45 +0000 | [diff] [blame] | 961 | Create a parser for parsing an external entity based on the\n\ |
Lars Gustäbel | 4a30a07 | 2000-09-24 20:50:52 +0000 | [diff] [blame] | 962 | information passed to the ExternalEntityRefHandler."; |
| 963 | |
| 964 | static PyObject * |
| 965 | xmlparse_ExternalEntityParserCreate(xmlparseobject *self, PyObject *args) |
| 966 | { |
| 967 | char *context; |
| 968 | char *encoding = NULL; |
| 969 | xmlparseobject *new_parser; |
| 970 | int i; |
| 971 | |
Fred Drake | cde7913 | 2001-04-25 16:01:30 +0000 | [diff] [blame] | 972 | if (!PyArg_ParseTuple(args, "s|s:ExternalEntityParserCreate", |
| 973 | &context, &encoding)) { |
| 974 | return NULL; |
Lars Gustäbel | 4a30a07 | 2000-09-24 20:50:52 +0000 | [diff] [blame] | 975 | } |
| 976 | |
| 977 | #if PY_MAJOR_VERSION == 1 && PY_MINOR_VERSION < 6 |
| 978 | new_parser = PyObject_NEW(xmlparseobject, &Xmlparsetype); |
Lars Gustäbel | 4a30a07 | 2000-09-24 20:50:52 +0000 | [diff] [blame] | 979 | #else |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 980 | /* Python versions 1.6 and later */ |
Lars Gustäbel | 4a30a07 | 2000-09-24 20:50:52 +0000 | [diff] [blame] | 981 | new_parser = PyObject_New(xmlparseobject, &Xmlparsetype); |
Lars Gustäbel | 4a30a07 | 2000-09-24 20:50:52 +0000 | [diff] [blame] | 982 | #endif |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 983 | |
| 984 | if (new_parser == NULL) |
| 985 | return NULL; |
| 986 | new_parser->returns_unicode = self->returns_unicode; |
| 987 | new_parser->ordered_attributes = self->ordered_attributes; |
| 988 | new_parser->specified_attributes = self->specified_attributes; |
Fred Drake | bd6101c | 2001-02-14 18:29:45 +0000 | [diff] [blame] | 989 | new_parser->in_callback = 0; |
Lars Gustäbel | 4a30a07 | 2000-09-24 20:50:52 +0000 | [diff] [blame] | 990 | new_parser->itself = XML_ExternalEntityParserCreate(self->itself, context, |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 991 | encoding); |
| 992 | new_parser->handlers = 0; |
| 993 | PyObject_GC_Init(new_parser); |
| 994 | |
| 995 | if (!new_parser->itself) { |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 996 | Py_DECREF(new_parser); |
| 997 | return PyErr_NoMemory(); |
Lars Gustäbel | 4a30a07 | 2000-09-24 20:50:52 +0000 | [diff] [blame] | 998 | } |
| 999 | |
| 1000 | XML_SetUserData(new_parser->itself, (void *)new_parser); |
| 1001 | |
| 1002 | /* allocate and clear handlers first */ |
| 1003 | for(i = 0; handler_info[i].name != NULL; i++) |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 1004 | /* do nothing */; |
Lars Gustäbel | 4a30a07 | 2000-09-24 20:50:52 +0000 | [diff] [blame] | 1005 | |
| 1006 | new_parser->handlers = malloc(sizeof(PyObject *)*i); |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1007 | if (!new_parser->handlers) { |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 1008 | Py_DECREF(new_parser); |
| 1009 | return PyErr_NoMemory(); |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1010 | } |
| 1011 | clear_handlers(new_parser, 0); |
Lars Gustäbel | 4a30a07 | 2000-09-24 20:50:52 +0000 | [diff] [blame] | 1012 | |
| 1013 | /* then copy handlers from self */ |
| 1014 | for (i = 0; handler_info[i].name != NULL; i++) { |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 1015 | if (self->handlers[i]) { |
| 1016 | Py_INCREF(self->handlers[i]); |
| 1017 | new_parser->handlers[i] = self->handlers[i]; |
| 1018 | handler_info[i].setter(new_parser->itself, |
| 1019 | handler_info[i].handler); |
| 1020 | } |
Lars Gustäbel | 4a30a07 | 2000-09-24 20:50:52 +0000 | [diff] [blame] | 1021 | } |
Fred Drake | 28adf52 | 2000-09-24 22:07:59 +0000 | [diff] [blame] | 1022 | return (PyObject *)new_parser; |
Lars Gustäbel | 4a30a07 | 2000-09-24 20:50:52 +0000 | [diff] [blame] | 1023 | } |
| 1024 | |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1025 | #if EXPAT_VERSION >= 0x010200 |
Lars Gustäbel | 4a30a07 | 2000-09-24 20:50:52 +0000 | [diff] [blame] | 1026 | |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1027 | static char xmlparse_SetParamEntityParsing__doc__[] = |
| 1028 | "SetParamEntityParsing(flag) -> success\n\ |
| 1029 | Controls parsing of parameter entities (including the external DTD\n\ |
| 1030 | subset). Possible flag values are XML_PARAM_ENTITY_PARSING_NEVER,\n\ |
| 1031 | XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE and\n\ |
| 1032 | XML_PARAM_ENTITY_PARSING_ALWAYS. Returns true if setting the flag\n\ |
| 1033 | was successful."; |
| 1034 | |
| 1035 | static PyObject* |
Fred Drake | bd6101c | 2001-02-14 18:29:45 +0000 | [diff] [blame] | 1036 | xmlparse_SetParamEntityParsing(xmlparseobject *p, PyObject* args) |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1037 | { |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 1038 | int flag; |
| 1039 | if (!PyArg_ParseTuple(args, "i", &flag)) |
| 1040 | return NULL; |
Fred Drake | bd6101c | 2001-02-14 18:29:45 +0000 | [diff] [blame] | 1041 | flag = XML_SetParamEntityParsing(p->itself, flag); |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 1042 | return PyInt_FromLong(flag); |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1043 | } |
| 1044 | |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 1045 | #endif /* Expat version 1.2 or better */ |
Lars Gustäbel | 4a30a07 | 2000-09-24 20:50:52 +0000 | [diff] [blame] | 1046 | |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1047 | static struct PyMethodDef xmlparse_methods[] = { |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1048 | {"Parse", (PyCFunction)xmlparse_Parse, |
Fred Drake | bd6101c | 2001-02-14 18:29:45 +0000 | [diff] [blame] | 1049 | METH_VARARGS, xmlparse_Parse__doc__}, |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1050 | {"ParseFile", (PyCFunction)xmlparse_ParseFile, |
Fred Drake | bd6101c | 2001-02-14 18:29:45 +0000 | [diff] [blame] | 1051 | METH_VARARGS, xmlparse_ParseFile__doc__}, |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1052 | {"SetBase", (PyCFunction)xmlparse_SetBase, |
Fred Drake | bd6101c | 2001-02-14 18:29:45 +0000 | [diff] [blame] | 1053 | METH_VARARGS, xmlparse_SetBase__doc__}, |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1054 | {"GetBase", (PyCFunction)xmlparse_GetBase, |
Fred Drake | bd6101c | 2001-02-14 18:29:45 +0000 | [diff] [blame] | 1055 | METH_VARARGS, xmlparse_GetBase__doc__}, |
Lars Gustäbel | 4a30a07 | 2000-09-24 20:50:52 +0000 | [diff] [blame] | 1056 | {"ExternalEntityParserCreate", (PyCFunction)xmlparse_ExternalEntityParserCreate, |
| 1057 | METH_VARARGS, xmlparse_ExternalEntityParserCreate__doc__}, |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1058 | #if EXPAT_VERSION >= 0x010200 |
Fred Drake | bd6101c | 2001-02-14 18:29:45 +0000 | [diff] [blame] | 1059 | {"SetParamEntityParsing", (PyCFunction)xmlparse_SetParamEntityParsing, |
| 1060 | METH_VARARGS, xmlparse_SetParamEntityParsing__doc__}, |
| 1061 | #endif |
| 1062 | #if EXPAT_VERSION >= 0x015f00 |
| 1063 | {"GetInputContext", (PyCFunction)xmlparse_GetInputContext, |
| 1064 | METH_VARARGS, xmlparse_GetInputContext__doc__}, |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1065 | #endif |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 1066 | {NULL, NULL} /* sentinel */ |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1067 | }; |
| 1068 | |
| 1069 | /* ---------- */ |
| 1070 | |
| 1071 | |
Martin v. Löwis | 339d0f7 | 2001-08-17 18:39:25 +0000 | [diff] [blame] | 1072 | #ifdef Py_USING_UNICODE |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1073 | |
| 1074 | /* |
| 1075 | pyexpat international encoding support. |
| 1076 | Make it as simple as possible. |
| 1077 | */ |
| 1078 | |
Martin v. Löwis | 3af7cc0 | 2001-01-22 08:19:10 +0000 | [diff] [blame] | 1079 | static char template_buffer[257]; |
Fred Drake | bb66a20 | 2001-03-01 20:48:17 +0000 | [diff] [blame] | 1080 | PyObject *template_string = NULL; |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1081 | |
| 1082 | static void |
| 1083 | init_template_buffer(void) |
| 1084 | { |
| 1085 | int i; |
Fred Drake | bb66a20 | 2001-03-01 20:48:17 +0000 | [diff] [blame] | 1086 | for (i = 0; i < 256; i++) { |
| 1087 | template_buffer[i] = i; |
Tim Peters | 63cb99e | 2001-02-17 18:12:50 +0000 | [diff] [blame] | 1088 | } |
Fred Drake | bb66a20 | 2001-03-01 20:48:17 +0000 | [diff] [blame] | 1089 | template_buffer[256] = 0; |
Tim Peters | 63cb99e | 2001-02-17 18:12:50 +0000 | [diff] [blame] | 1090 | } |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1091 | |
| 1092 | int |
| 1093 | PyUnknownEncodingHandler(void *encodingHandlerData, |
| 1094 | const XML_Char *name, |
| 1095 | XML_Encoding * info) |
| 1096 | { |
Fred Drake | bb66a20 | 2001-03-01 20:48:17 +0000 | [diff] [blame] | 1097 | PyUnicodeObject *_u_string = NULL; |
| 1098 | int result = 0; |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1099 | int i; |
| 1100 | |
Fred Drake | bb66a20 | 2001-03-01 20:48:17 +0000 | [diff] [blame] | 1101 | /* Yes, supports only 8bit encodings */ |
| 1102 | _u_string = (PyUnicodeObject *) |
| 1103 | PyUnicode_Decode(template_buffer, 256, name, "replace"); |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1104 | |
Fred Drake | bb66a20 | 2001-03-01 20:48:17 +0000 | [diff] [blame] | 1105 | if (_u_string == NULL) |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1106 | return result; |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1107 | |
Fred Drake | bb66a20 | 2001-03-01 20:48:17 +0000 | [diff] [blame] | 1108 | for (i = 0; i < 256; i++) { |
| 1109 | /* Stupid to access directly, but fast */ |
| 1110 | Py_UNICODE c = _u_string->str[i]; |
| 1111 | if (c == Py_UNICODE_REPLACEMENT_CHARACTER) |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1112 | info->map[i] = -1; |
Fred Drake | bb66a20 | 2001-03-01 20:48:17 +0000 | [diff] [blame] | 1113 | else |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1114 | info->map[i] = c; |
Tim Peters | 63cb99e | 2001-02-17 18:12:50 +0000 | [diff] [blame] | 1115 | } |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1116 | |
| 1117 | info->data = NULL; |
| 1118 | info->convert = NULL; |
| 1119 | info->release = NULL; |
| 1120 | result=1; |
| 1121 | |
| 1122 | Py_DECREF(_u_string); |
| 1123 | return result; |
| 1124 | } |
| 1125 | |
| 1126 | #endif |
| 1127 | |
| 1128 | static PyObject * |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1129 | newxmlparseobject(char *encoding, char *namespace_separator) |
| 1130 | { |
| 1131 | int i; |
| 1132 | xmlparseobject *self; |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 1133 | |
| 1134 | #if PY_MAJOR_VERSION == 1 && PY_MINOR_VERSION < 6 |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1135 | self = PyObject_NEW(xmlparseobject, &Xmlparsetype); |
| 1136 | if (self == NULL) |
| 1137 | return NULL; |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 1138 | |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1139 | self->returns_unicode = 0; |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 1140 | #else |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1141 | /* Code for versions 1.6 and later */ |
| 1142 | self = PyObject_New(xmlparseobject, &Xmlparsetype); |
| 1143 | if (self == NULL) |
| 1144 | return NULL; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1145 | |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1146 | self->returns_unicode = 1; |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 1147 | #endif |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 1148 | self->ordered_attributes = 0; |
| 1149 | self->specified_attributes = 0; |
Fred Drake | bd6101c | 2001-02-14 18:29:45 +0000 | [diff] [blame] | 1150 | self->in_callback = 0; |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1151 | self->handlers = NULL; |
Fred Drake | cde7913 | 2001-04-25 16:01:30 +0000 | [diff] [blame] | 1152 | if (namespace_separator != NULL) { |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1153 | self->itself = XML_ParserCreateNS(encoding, *namespace_separator); |
| 1154 | } |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 1155 | else { |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1156 | self->itself = XML_ParserCreate(encoding); |
| 1157 | } |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1158 | PyObject_GC_Init(self); |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1159 | if (self->itself == NULL) { |
| 1160 | PyErr_SetString(PyExc_RuntimeError, |
| 1161 | "XML_ParserCreate failed"); |
| 1162 | Py_DECREF(self); |
| 1163 | return NULL; |
| 1164 | } |
| 1165 | XML_SetUserData(self->itself, (void *)self); |
Martin v. Löwis | 339d0f7 | 2001-08-17 18:39:25 +0000 | [diff] [blame] | 1166 | #ifdef Py_USING_UNICODE |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1167 | XML_SetUnknownEncodingHandler(self->itself, (XML_UnknownEncodingHandler) PyUnknownEncodingHandler, NULL); |
| 1168 | #endif |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1169 | |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1170 | for(i = 0; handler_info[i].name != NULL; i++) |
| 1171 | /* do nothing */; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1172 | |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1173 | self->handlers = malloc(sizeof(PyObject *)*i); |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1174 | if (!self->handlers){ |
| 1175 | Py_DECREF(self); |
| 1176 | return PyErr_NoMemory(); |
| 1177 | } |
| 1178 | clear_handlers(self, 0); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1179 | |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1180 | return (PyObject*)self; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1181 | } |
| 1182 | |
| 1183 | |
| 1184 | static void |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1185 | xmlparse_dealloc(xmlparseobject *self) |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1186 | { |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1187 | int i; |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1188 | PyObject_GC_Fini(self); |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 1189 | if (self->itself != NULL) |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1190 | XML_ParserFree(self->itself); |
| 1191 | self->itself = NULL; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1192 | |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 1193 | if (self->handlers != NULL) { |
Fred Drake | cde7913 | 2001-04-25 16:01:30 +0000 | [diff] [blame] | 1194 | PyObject *temp; |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 1195 | for (i = 0; handler_info[i].name != NULL; i++) { |
Fred Drake | cde7913 | 2001-04-25 16:01:30 +0000 | [diff] [blame] | 1196 | temp = self->handlers[i]; |
| 1197 | self->handlers[i] = NULL; |
| 1198 | Py_XDECREF(temp); |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 1199 | } |
| 1200 | free(self->handlers); |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1201 | } |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 1202 | #if PY_MAJOR_VERSION == 1 && PY_MINOR_VERSION < 6 |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1203 | /* Code for versions before 1.6 */ |
| 1204 | free(self); |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 1205 | #else |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1206 | /* Code for versions 1.6 and later */ |
| 1207 | PyObject_Del(self); |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 1208 | #endif |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1209 | } |
| 1210 | |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1211 | static int |
| 1212 | handlername2int(const char *name) |
| 1213 | { |
| 1214 | int i; |
| 1215 | for (i=0; handler_info[i].name != NULL; i++) { |
| 1216 | if (strcmp(name, handler_info[i].name) == 0) { |
| 1217 | return i; |
| 1218 | } |
| 1219 | } |
| 1220 | return -1; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1221 | } |
| 1222 | |
| 1223 | static PyObject * |
| 1224 | xmlparse_getattr(xmlparseobject *self, char *name) |
| 1225 | { |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1226 | int handlernum; |
| 1227 | if (strcmp(name, "ErrorCode") == 0) |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 1228 | return PyInt_FromLong((long) XML_GetErrorCode(self->itself)); |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1229 | if (strcmp(name, "ErrorLineNumber") == 0) |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 1230 | return PyInt_FromLong((long) XML_GetErrorLineNumber(self->itself)); |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1231 | if (strcmp(name, "ErrorColumnNumber") == 0) |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 1232 | return PyInt_FromLong((long) XML_GetErrorColumnNumber(self->itself)); |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1233 | if (strcmp(name, "ErrorByteIndex") == 0) |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 1234 | return PyInt_FromLong((long) XML_GetErrorByteIndex(self->itself)); |
| 1235 | if (strcmp(name, "ordered_attributes") == 0) |
| 1236 | return PyInt_FromLong((long) self->ordered_attributes); |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1237 | if (strcmp(name, "returns_unicode") == 0) |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 1238 | return PyInt_FromLong((long) self->returns_unicode); |
| 1239 | if (strcmp(name, "specified_attributes") == 0) |
| 1240 | return PyInt_FromLong((long) self->specified_attributes); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1241 | |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1242 | handlernum = handlername2int(name); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1243 | |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1244 | if (handlernum != -1 && self->handlers[handlernum] != NULL) { |
| 1245 | Py_INCREF(self->handlers[handlernum]); |
| 1246 | return self->handlers[handlernum]; |
| 1247 | } |
| 1248 | if (strcmp(name, "__members__") == 0) { |
| 1249 | int i; |
| 1250 | PyObject *rc = PyList_New(0); |
Fred Drake | e8f3ad5 | 2000-12-16 01:48:29 +0000 | [diff] [blame] | 1251 | for(i = 0; handler_info[i].name != NULL; i++) { |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 1252 | PyList_Append(rc, PyString_FromString(handler_info[i].name)); |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1253 | } |
| 1254 | PyList_Append(rc, PyString_FromString("ErrorCode")); |
| 1255 | PyList_Append(rc, PyString_FromString("ErrorLineNumber")); |
| 1256 | PyList_Append(rc, PyString_FromString("ErrorColumnNumber")); |
| 1257 | PyList_Append(rc, PyString_FromString("ErrorByteIndex")); |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 1258 | PyList_Append(rc, PyString_FromString("ordered_attributes")); |
Fred Drake | e8f3ad5 | 2000-12-16 01:48:29 +0000 | [diff] [blame] | 1259 | PyList_Append(rc, PyString_FromString("returns_unicode")); |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 1260 | PyList_Append(rc, PyString_FromString("specified_attributes")); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1261 | |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1262 | return rc; |
| 1263 | } |
| 1264 | return Py_FindMethod(xmlparse_methods, (PyObject *)self, name); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1265 | } |
| 1266 | |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 1267 | static int |
| 1268 | sethandler(xmlparseobject *self, const char *name, PyObject* v) |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1269 | { |
| 1270 | int handlernum = handlername2int(name); |
| 1271 | if (handlernum != -1) { |
| 1272 | Py_INCREF(v); |
| 1273 | Py_XDECREF(self->handlers[handlernum]); |
| 1274 | self->handlers[handlernum] = v; |
| 1275 | handler_info[handlernum].setter(self->itself, |
| 1276 | handler_info[handlernum].handler); |
| 1277 | return 1; |
| 1278 | } |
| 1279 | return 0; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | static int |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 1283 | xmlparse_setattr(xmlparseobject *self, char *name, PyObject *v) |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1284 | { |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 1285 | /* Set attribute 'name' to value 'v'. v==NULL means delete */ |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 1286 | if (v == NULL) { |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 1287 | PyErr_SetString(PyExc_RuntimeError, "Cannot delete attribute"); |
| 1288 | return -1; |
| 1289 | } |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 1290 | if (strcmp(name, "ordered_attributes") == 0) { |
| 1291 | if (PyObject_IsTrue(v)) |
| 1292 | self->ordered_attributes = 1; |
| 1293 | else |
| 1294 | self->ordered_attributes = 0; |
| 1295 | return 0; |
| 1296 | } |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 1297 | if (strcmp(name, "returns_unicode") == 0) { |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 1298 | if (PyObject_IsTrue(v)) { |
Martin v. Löwis | 339d0f7 | 2001-08-17 18:39:25 +0000 | [diff] [blame] | 1299 | #ifndef Py_USING_UNICODE |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 1300 | PyErr_SetString(PyExc_ValueError, |
| 1301 | "Cannot return Unicode strings in Python 1.5"); |
| 1302 | return -1; |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 1303 | #else |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 1304 | self->returns_unicode = 1; |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 1305 | #endif |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 1306 | } |
| 1307 | else |
| 1308 | self->returns_unicode = 0; |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 1309 | return 0; |
| 1310 | } |
| 1311 | if (strcmp(name, "specified_attributes") == 0) { |
| 1312 | if (PyObject_IsTrue(v)) |
| 1313 | self->specified_attributes = 1; |
| 1314 | else |
| 1315 | self->specified_attributes = 0; |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 1316 | return 0; |
| 1317 | } |
| 1318 | if (sethandler(self, name, v)) { |
| 1319 | return 0; |
| 1320 | } |
| 1321 | PyErr_SetString(PyExc_AttributeError, name); |
| 1322 | return -1; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1323 | } |
| 1324 | |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1325 | #ifdef WITH_CYCLE_GC |
| 1326 | static int |
| 1327 | xmlparse_traverse(xmlparseobject *op, visitproc visit, void *arg) |
| 1328 | { |
Fred Drake | cde7913 | 2001-04-25 16:01:30 +0000 | [diff] [blame] | 1329 | int i, err; |
| 1330 | for (i = 0; handler_info[i].name != NULL; i++) { |
| 1331 | if (!op->handlers[i]) |
| 1332 | continue; |
| 1333 | err = visit(op->handlers[i], arg); |
| 1334 | if (err) |
| 1335 | return err; |
| 1336 | } |
| 1337 | return 0; |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1338 | } |
| 1339 | |
| 1340 | static int |
| 1341 | xmlparse_clear(xmlparseobject *op) |
| 1342 | { |
Fred Drake | cde7913 | 2001-04-25 16:01:30 +0000 | [diff] [blame] | 1343 | clear_handlers(op, 1); |
| 1344 | return 0; |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1345 | } |
| 1346 | #endif |
| 1347 | |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1348 | static char Xmlparsetype__doc__[] = |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1349 | "XML parser"; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1350 | |
| 1351 | static PyTypeObject Xmlparsetype = { |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 1352 | PyObject_HEAD_INIT(NULL) |
| 1353 | 0, /*ob_size*/ |
| 1354 | "xmlparser", /*tp_name*/ |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1355 | sizeof(xmlparseobject) + PyGC_HEAD_SIZE,/*tp_basicsize*/ |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 1356 | 0, /*tp_itemsize*/ |
| 1357 | /* methods */ |
| 1358 | (destructor)xmlparse_dealloc, /*tp_dealloc*/ |
| 1359 | (printfunc)0, /*tp_print*/ |
| 1360 | (getattrfunc)xmlparse_getattr, /*tp_getattr*/ |
| 1361 | (setattrfunc)xmlparse_setattr, /*tp_setattr*/ |
| 1362 | (cmpfunc)0, /*tp_compare*/ |
| 1363 | (reprfunc)0, /*tp_repr*/ |
| 1364 | 0, /*tp_as_number*/ |
| 1365 | 0, /*tp_as_sequence*/ |
| 1366 | 0, /*tp_as_mapping*/ |
| 1367 | (hashfunc)0, /*tp_hash*/ |
| 1368 | (ternaryfunc)0, /*tp_call*/ |
| 1369 | (reprfunc)0, /*tp_str*/ |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1370 | 0, /* tp_getattro */ |
| 1371 | 0, /* tp_setattro */ |
| 1372 | 0, /* tp_as_buffer */ |
| 1373 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_GC, /*tp_flags*/ |
| 1374 | Xmlparsetype__doc__, /* Documentation string */ |
| 1375 | #ifdef WITH_CYCLE_GC |
| 1376 | (traverseproc)xmlparse_traverse, /* tp_traverse */ |
| 1377 | (inquiry)xmlparse_clear /* tp_clear */ |
| 1378 | #else |
| 1379 | 0, 0 |
| 1380 | #endif |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1381 | }; |
| 1382 | |
| 1383 | /* End of code for xmlparser objects */ |
| 1384 | /* -------------------------------------------------------- */ |
| 1385 | |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1386 | static char pyexpat_ParserCreate__doc__[] = |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1387 | "ParserCreate([encoding[, namespace_separator]]) -> parser\n\ |
| 1388 | Return a new XML parser object."; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1389 | |
| 1390 | static PyObject * |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1391 | pyexpat_ParserCreate(PyObject *notused, PyObject *args, PyObject *kw) |
| 1392 | { |
Fred Drake | cde7913 | 2001-04-25 16:01:30 +0000 | [diff] [blame] | 1393 | char *encoding = NULL; |
| 1394 | char *namespace_separator = NULL; |
| 1395 | static char *kwlist[] = {"encoding", "namespace_separator", NULL}; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1396 | |
Fred Drake | cde7913 | 2001-04-25 16:01:30 +0000 | [diff] [blame] | 1397 | if (!PyArg_ParseTupleAndKeywords(args, kw, "|zz:ParserCreate", kwlist, |
| 1398 | &encoding, &namespace_separator)) |
| 1399 | return NULL; |
| 1400 | if (namespace_separator != NULL |
| 1401 | && strlen(namespace_separator) > 1) { |
| 1402 | PyErr_SetString(PyExc_ValueError, |
| 1403 | "namespace_separator must be at most one" |
| 1404 | " character, omitted, or None"); |
| 1405 | return NULL; |
| 1406 | } |
| 1407 | return newxmlparseobject(encoding, namespace_separator); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1408 | } |
| 1409 | |
| 1410 | static char pyexpat_ErrorString__doc__[] = |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1411 | "ErrorString(errno) -> string\n\ |
| 1412 | Returns string error for given number."; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1413 | |
| 1414 | static PyObject * |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1415 | pyexpat_ErrorString(PyObject *self, PyObject *args) |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1416 | { |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1417 | long code = 0; |
| 1418 | |
| 1419 | if (!PyArg_ParseTuple(args, "l:ErrorString", &code)) |
| 1420 | return NULL; |
| 1421 | return Py_BuildValue("z", XML_ErrorString((int)code)); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1422 | } |
| 1423 | |
| 1424 | /* List of methods defined in the module */ |
| 1425 | |
| 1426 | static struct PyMethodDef pyexpat_methods[] = { |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1427 | {"ParserCreate", (PyCFunction)pyexpat_ParserCreate, |
| 1428 | METH_VARARGS|METH_KEYWORDS, pyexpat_ParserCreate__doc__}, |
| 1429 | {"ErrorString", (PyCFunction)pyexpat_ErrorString, |
| 1430 | METH_VARARGS, pyexpat_ErrorString__doc__}, |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1431 | |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1432 | {NULL, (PyCFunction)NULL, 0, NULL} /* sentinel */ |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1433 | }; |
| 1434 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 1435 | /* Module docstring */ |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1436 | |
| 1437 | static char pyexpat_module_documentation[] = |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1438 | "Python wrapper for Expat parser."; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1439 | |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1440 | #if PY_VERSION_HEX < 0x20000F0 |
Martin v. Löwis | c0718eb | 2000-09-29 19:05:48 +0000 | [diff] [blame] | 1441 | |
| 1442 | /* 1.5 compatibility: PyModule_AddObject */ |
| 1443 | static int |
| 1444 | PyModule_AddObject(PyObject *m, char *name, PyObject *o) |
| 1445 | { |
Fred Drake | cde7913 | 2001-04-25 16:01:30 +0000 | [diff] [blame] | 1446 | PyObject *dict; |
| 1447 | if (!PyModule_Check(m) || o == NULL) |
| 1448 | return -1; |
| 1449 | dict = PyModule_GetDict(m); |
| 1450 | if (dict == NULL) |
| 1451 | return -1; |
| 1452 | if (PyDict_SetItemString(dict, name, o)) |
| 1453 | return -1; |
| 1454 | Py_DECREF(o); |
| 1455 | return 0; |
Martin v. Löwis | c0718eb | 2000-09-29 19:05:48 +0000 | [diff] [blame] | 1456 | } |
| 1457 | |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1458 | int |
| 1459 | PyModule_AddIntConstant(PyObject *m, char *name, long value) |
| 1460 | { |
Fred Drake | cde7913 | 2001-04-25 16:01:30 +0000 | [diff] [blame] | 1461 | return PyModule_AddObject(m, name, PyInt_FromLong(value)); |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1462 | } |
| 1463 | |
Fred Drake | a77254a | 2000-09-29 19:23:29 +0000 | [diff] [blame] | 1464 | static int |
Martin v. Löwis | c0718eb | 2000-09-29 19:05:48 +0000 | [diff] [blame] | 1465 | PyModule_AddStringConstant(PyObject *m, char *name, char *value) |
| 1466 | { |
Fred Drake | cde7913 | 2001-04-25 16:01:30 +0000 | [diff] [blame] | 1467 | return PyModule_AddObject(m, name, PyString_FromString(value)); |
Martin v. Löwis | c0718eb | 2000-09-29 19:05:48 +0000 | [diff] [blame] | 1468 | } |
| 1469 | |
| 1470 | #endif |
| 1471 | |
Fred Drake | 4113b13 | 2001-03-24 19:58:26 +0000 | [diff] [blame] | 1472 | |
| 1473 | /* Return a Python string that represents the version number without the |
| 1474 | * extra cruft added by revision control, even if the right options were |
| 1475 | * given to the "cvs export" command to make it not include the extra |
| 1476 | * cruft. |
| 1477 | */ |
| 1478 | static PyObject * |
| 1479 | get_version_string(void) |
| 1480 | { |
| 1481 | static char *rcsid = "$Revision$"; |
| 1482 | char *rev = rcsid; |
| 1483 | int i = 0; |
| 1484 | |
| 1485 | while (!isdigit(*rev)) |
| 1486 | ++rev; |
| 1487 | while (rev[i] != ' ' && rev[i] != '\0') |
| 1488 | ++i; |
| 1489 | |
| 1490 | return PyString_FromStringAndSize(rev, i); |
| 1491 | } |
| 1492 | |
Fred Drake | cde7913 | 2001-04-25 16:01:30 +0000 | [diff] [blame] | 1493 | /* Initialization function for the module */ |
| 1494 | |
| 1495 | #ifndef MODULE_NAME |
| 1496 | #define MODULE_NAME "pyexpat" |
| 1497 | #endif |
| 1498 | |
| 1499 | #ifndef MODULE_INITFUNC |
| 1500 | #define MODULE_INITFUNC initpyexpat |
| 1501 | #endif |
| 1502 | |
| 1503 | void MODULE_INITFUNC(void); /* avoid compiler warnings */ |
| 1504 | |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 1505 | DL_EXPORT(void) |
Fred Drake | cde7913 | 2001-04-25 16:01:30 +0000 | [diff] [blame] | 1506 | MODULE_INITFUNC(void) |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1507 | { |
| 1508 | PyObject *m, *d; |
Fred Drake | cde7913 | 2001-04-25 16:01:30 +0000 | [diff] [blame] | 1509 | PyObject *errmod_name = PyString_FromString(MODULE_NAME ".errors"); |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 1510 | PyObject *errors_module; |
| 1511 | PyObject *modelmod_name; |
| 1512 | PyObject *model_module; |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1513 | PyObject *sys_modules; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1514 | |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 1515 | if (errmod_name == NULL) |
| 1516 | return; |
Fred Drake | cde7913 | 2001-04-25 16:01:30 +0000 | [diff] [blame] | 1517 | modelmod_name = PyString_FromString(MODULE_NAME ".model"); |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 1518 | if (modelmod_name == NULL) |
| 1519 | return; |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 1520 | |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1521 | Xmlparsetype.ob_type = &PyType_Type; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1522 | |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1523 | /* Create the module and add the functions */ |
Fred Drake | cde7913 | 2001-04-25 16:01:30 +0000 | [diff] [blame] | 1524 | m = Py_InitModule3(MODULE_NAME, pyexpat_methods, |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 1525 | pyexpat_module_documentation); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1526 | |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1527 | /* Add some symbolic constants to the module */ |
Fred Drake | bd6101c | 2001-02-14 18:29:45 +0000 | [diff] [blame] | 1528 | if (ErrorObject == NULL) { |
| 1529 | ErrorObject = PyErr_NewException("xml.parsers.expat.ExpatError", |
Fred Drake | 93adb69 | 2000-09-23 04:55:48 +0000 | [diff] [blame] | 1530 | NULL, NULL); |
Fred Drake | bd6101c | 2001-02-14 18:29:45 +0000 | [diff] [blame] | 1531 | if (ErrorObject == NULL) |
| 1532 | return; |
| 1533 | } |
| 1534 | Py_INCREF(ErrorObject); |
Fred Drake | 93adb69 | 2000-09-23 04:55:48 +0000 | [diff] [blame] | 1535 | PyModule_AddObject(m, "error", ErrorObject); |
Fred Drake | bd6101c | 2001-02-14 18:29:45 +0000 | [diff] [blame] | 1536 | Py_INCREF(ErrorObject); |
| 1537 | PyModule_AddObject(m, "ExpatError", ErrorObject); |
Fred Drake | 4ba298c | 2000-10-29 04:57:53 +0000 | [diff] [blame] | 1538 | Py_INCREF(&Xmlparsetype); |
| 1539 | PyModule_AddObject(m, "XMLParserType", (PyObject *) &Xmlparsetype); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1540 | |
Fred Drake | 4113b13 | 2001-03-24 19:58:26 +0000 | [diff] [blame] | 1541 | PyModule_AddObject(m, "__version__", get_version_string()); |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 1542 | #if EXPAT_VERSION >= 0x015f02 |
Fred Drake | 738293d | 2000-12-21 17:25:07 +0000 | [diff] [blame] | 1543 | PyModule_AddStringConstant(m, "EXPAT_VERSION", |
| 1544 | (char *) XML_ExpatVersion()); |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 1545 | { |
| 1546 | XML_Expat_Version info = XML_ExpatVersionInfo(); |
| 1547 | PyModule_AddObject(m, "version_info", |
| 1548 | Py_BuildValue("(iii)", info.major, |
| 1549 | info.minor, info.micro)); |
| 1550 | } |
Fred Drake | 738293d | 2000-12-21 17:25:07 +0000 | [diff] [blame] | 1551 | #endif |
Martin v. Löwis | 339d0f7 | 2001-08-17 18:39:25 +0000 | [diff] [blame] | 1552 | #ifdef Py_USING_UNICODE |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1553 | init_template_buffer(); |
| 1554 | #endif |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1555 | /* XXX When Expat supports some way of figuring out how it was |
| 1556 | compiled, this should check and set native_encoding |
| 1557 | appropriately. |
| 1558 | */ |
Fred Drake | 93adb69 | 2000-09-23 04:55:48 +0000 | [diff] [blame] | 1559 | PyModule_AddStringConstant(m, "native_encoding", "UTF-8"); |
Fred Drake | c23b523 | 2000-08-24 21:57:43 +0000 | [diff] [blame] | 1560 | |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 1561 | sys_modules = PySys_GetObject("modules"); |
Fred Drake | 93adb69 | 2000-09-23 04:55:48 +0000 | [diff] [blame] | 1562 | d = PyModule_GetDict(m); |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 1563 | errors_module = PyDict_GetItem(d, errmod_name); |
| 1564 | if (errors_module == NULL) { |
Fred Drake | cde7913 | 2001-04-25 16:01:30 +0000 | [diff] [blame] | 1565 | errors_module = PyModule_New(MODULE_NAME ".errors"); |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 1566 | if (errors_module != NULL) { |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 1567 | PyDict_SetItem(sys_modules, errmod_name, errors_module); |
Fred Drake | 93adb69 | 2000-09-23 04:55:48 +0000 | [diff] [blame] | 1568 | /* gives away the reference to errors_module */ |
| 1569 | PyModule_AddObject(m, "errors", errors_module); |
Fred Drake | c23b523 | 2000-08-24 21:57:43 +0000 | [diff] [blame] | 1570 | } |
| 1571 | } |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 1572 | Py_DECREF(errmod_name); |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 1573 | model_module = PyDict_GetItem(d, modelmod_name); |
| 1574 | if (model_module == NULL) { |
Fred Drake | cde7913 | 2001-04-25 16:01:30 +0000 | [diff] [blame] | 1575 | model_module = PyModule_New(MODULE_NAME ".model"); |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 1576 | if (model_module != NULL) { |
| 1577 | PyDict_SetItem(sys_modules, modelmod_name, model_module); |
| 1578 | /* gives away the reference to model_module */ |
| 1579 | PyModule_AddObject(m, "model", model_module); |
| 1580 | } |
| 1581 | } |
| 1582 | Py_DECREF(modelmod_name); |
| 1583 | if (errors_module == NULL || model_module == NULL) |
| 1584 | /* Don't core dump later! */ |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 1585 | return; |
| 1586 | |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1587 | #define MYCONST(name) \ |
Fred Drake | 93adb69 | 2000-09-23 04:55:48 +0000 | [diff] [blame] | 1588 | PyModule_AddStringConstant(errors_module, #name, \ |
| 1589 | (char*)XML_ErrorString(name)) |
Fred Drake | 7bd9f41 | 2000-07-04 23:51:31 +0000 | [diff] [blame] | 1590 | |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1591 | MYCONST(XML_ERROR_NO_MEMORY); |
| 1592 | MYCONST(XML_ERROR_SYNTAX); |
| 1593 | MYCONST(XML_ERROR_NO_ELEMENTS); |
| 1594 | MYCONST(XML_ERROR_INVALID_TOKEN); |
| 1595 | MYCONST(XML_ERROR_UNCLOSED_TOKEN); |
| 1596 | MYCONST(XML_ERROR_PARTIAL_CHAR); |
| 1597 | MYCONST(XML_ERROR_TAG_MISMATCH); |
| 1598 | MYCONST(XML_ERROR_DUPLICATE_ATTRIBUTE); |
| 1599 | MYCONST(XML_ERROR_JUNK_AFTER_DOC_ELEMENT); |
| 1600 | MYCONST(XML_ERROR_PARAM_ENTITY_REF); |
| 1601 | MYCONST(XML_ERROR_UNDEFINED_ENTITY); |
| 1602 | MYCONST(XML_ERROR_RECURSIVE_ENTITY_REF); |
| 1603 | MYCONST(XML_ERROR_ASYNC_ENTITY); |
| 1604 | MYCONST(XML_ERROR_BAD_CHAR_REF); |
| 1605 | MYCONST(XML_ERROR_BINARY_ENTITY_REF); |
| 1606 | MYCONST(XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF); |
| 1607 | MYCONST(XML_ERROR_MISPLACED_XML_PI); |
| 1608 | MYCONST(XML_ERROR_UNKNOWN_ENCODING); |
| 1609 | MYCONST(XML_ERROR_INCORRECT_ENCODING); |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1610 | MYCONST(XML_ERROR_UNCLOSED_CDATA_SECTION); |
| 1611 | MYCONST(XML_ERROR_EXTERNAL_ENTITY_HANDLING); |
| 1612 | MYCONST(XML_ERROR_NOT_STANDALONE); |
| 1613 | |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 1614 | PyModule_AddStringConstant(errors_module, "__doc__", |
| 1615 | "Constants used to describe error conditions."); |
| 1616 | |
Fred Drake | 93adb69 | 2000-09-23 04:55:48 +0000 | [diff] [blame] | 1617 | #undef MYCONST |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1618 | |
| 1619 | #if EXPAT_VERSION >= 0x010200 |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 1620 | #define MYCONST(c) PyModule_AddIntConstant(m, #c, c) |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1621 | MYCONST(XML_PARAM_ENTITY_PARSING_NEVER); |
| 1622 | MYCONST(XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE); |
| 1623 | MYCONST(XML_PARAM_ENTITY_PARSING_ALWAYS); |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 1624 | #undef MYCONST |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1625 | #endif |
| 1626 | |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 1627 | #if EXPAT_VERSION >= 0x015f00 |
| 1628 | #define MYCONST(c) PyModule_AddIntConstant(model_module, #c, c) |
| 1629 | PyModule_AddStringConstant(model_module, "__doc__", |
| 1630 | "Constants used to interpret content model information."); |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1631 | |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 1632 | MYCONST(XML_CTYPE_EMPTY); |
| 1633 | MYCONST(XML_CTYPE_ANY); |
| 1634 | MYCONST(XML_CTYPE_MIXED); |
| 1635 | MYCONST(XML_CTYPE_NAME); |
| 1636 | MYCONST(XML_CTYPE_CHOICE); |
| 1637 | MYCONST(XML_CTYPE_SEQ); |
| 1638 | |
| 1639 | MYCONST(XML_CQUANT_NONE); |
| 1640 | MYCONST(XML_CQUANT_OPT); |
| 1641 | MYCONST(XML_CQUANT_REP); |
| 1642 | MYCONST(XML_CQUANT_PLUS); |
| 1643 | #undef MYCONST |
| 1644 | #endif |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1645 | } |
| 1646 | |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 1647 | static void |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1648 | clear_handlers(xmlparseobject *self, int decref) |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1649 | { |
Fred Drake | cde7913 | 2001-04-25 16:01:30 +0000 | [diff] [blame] | 1650 | int i = 0; |
| 1651 | PyObject *temp; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1652 | |
Fred Drake | cde7913 | 2001-04-25 16:01:30 +0000 | [diff] [blame] | 1653 | for (; handler_info[i].name!=NULL; i++) { |
| 1654 | if (decref) { |
| 1655 | temp = self->handlers[i]; |
| 1656 | self->handlers[i] = NULL; |
| 1657 | Py_XDECREF(temp); |
| 1658 | } |
| 1659 | self->handlers[i]=NULL; |
| 1660 | handler_info[i].setter(self->itself, NULL); |
| 1661 | } |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1662 | } |
| 1663 | |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 1664 | typedef void (*pairsetter)(XML_Parser, void *handler1, void *handler2); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1665 | |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 1666 | static void |
| 1667 | pyxml_UpdatePairedHandlers(xmlparseobject *self, |
| 1668 | int startHandler, |
| 1669 | int endHandler, |
| 1670 | pairsetter setter) |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1671 | { |
Fred Drake | cde7913 | 2001-04-25 16:01:30 +0000 | [diff] [blame] | 1672 | void *start_handler = NULL; |
| 1673 | void *end_handler = NULL; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1674 | |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1675 | if (self->handlers[startHandler] |
Fred Drake | cde7913 | 2001-04-25 16:01:30 +0000 | [diff] [blame] | 1676 | && self->handlers[endHandler] != Py_None) { |
| 1677 | start_handler = handler_info[startHandler].handler; |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1678 | } |
| 1679 | if (self->handlers[EndElement] |
Fred Drake | cde7913 | 2001-04-25 16:01:30 +0000 | [diff] [blame] | 1680 | && self->handlers[EndElement] != Py_None) { |
| 1681 | end_handler = handler_info[endHandler].handler; |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1682 | } |
| 1683 | setter(self->itself, start_handler, end_handler); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1684 | } |
| 1685 | |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 1686 | static void |
| 1687 | pyxml_SetStartElementHandler(XML_Parser *parser, void *junk) |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1688 | { |
| 1689 | pyxml_UpdatePairedHandlers((xmlparseobject *)XML_GetUserData(parser), |
| 1690 | StartElement, EndElement, |
| 1691 | (pairsetter)XML_SetElementHandler); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1692 | } |
| 1693 | |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 1694 | static void |
| 1695 | pyxml_SetEndElementHandler(XML_Parser *parser, void *junk) |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1696 | { |
| 1697 | pyxml_UpdatePairedHandlers((xmlparseobject *)XML_GetUserData(parser), |
| 1698 | StartElement, EndElement, |
| 1699 | (pairsetter)XML_SetElementHandler); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1700 | } |
| 1701 | |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 1702 | static void |
| 1703 | pyxml_SetStartNamespaceDeclHandler(XML_Parser *parser, void *junk) |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1704 | { |
| 1705 | pyxml_UpdatePairedHandlers((xmlparseobject *)XML_GetUserData(parser), |
| 1706 | StartNamespaceDecl, EndNamespaceDecl, |
| 1707 | (pairsetter)XML_SetNamespaceDeclHandler); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1708 | } |
| 1709 | |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 1710 | static void |
| 1711 | pyxml_SetEndNamespaceDeclHandler(XML_Parser *parser, void *junk) |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1712 | { |
| 1713 | pyxml_UpdatePairedHandlers((xmlparseobject *)XML_GetUserData(parser), |
| 1714 | StartNamespaceDecl, EndNamespaceDecl, |
| 1715 | (pairsetter)XML_SetNamespaceDeclHandler); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1716 | } |
| 1717 | |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 1718 | static void |
| 1719 | pyxml_SetStartCdataSection(XML_Parser *parser, void *junk) |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1720 | { |
| 1721 | pyxml_UpdatePairedHandlers((xmlparseobject *)XML_GetUserData(parser), |
| 1722 | StartCdataSection, EndCdataSection, |
| 1723 | (pairsetter)XML_SetCdataSectionHandler); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1724 | } |
| 1725 | |
Fred Drake | 6f98762 | 2000-08-25 18:03:30 +0000 | [diff] [blame] | 1726 | static void |
| 1727 | pyxml_SetEndCdataSection(XML_Parser *parser, void *junk) |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1728 | { |
| 1729 | pyxml_UpdatePairedHandlers((xmlparseobject *)XML_GetUserData(parser), |
| 1730 | StartCdataSection, EndCdataSection, |
| 1731 | (pairsetter)XML_SetCdataSectionHandler); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1732 | } |
| 1733 | |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1734 | #if EXPAT_VERSION >= 0x010200 |
| 1735 | |
| 1736 | static void |
| 1737 | pyxml_SetStartDoctypeDeclHandler(XML_Parser *parser, void *junk) |
| 1738 | { |
| 1739 | pyxml_UpdatePairedHandlers((xmlparseobject *)XML_GetUserData(parser), |
| 1740 | StartDoctypeDecl, EndDoctypeDecl, |
| 1741 | (pairsetter)XML_SetDoctypeDeclHandler); |
| 1742 | } |
| 1743 | |
| 1744 | static void |
| 1745 | pyxml_SetEndDoctypeDeclHandler(XML_Parser *parser, void *junk) |
| 1746 | { |
| 1747 | pyxml_UpdatePairedHandlers((xmlparseobject *)XML_GetUserData(parser), |
| 1748 | StartDoctypeDecl, EndDoctypeDecl, |
| 1749 | (pairsetter)XML_SetDoctypeDeclHandler); |
| 1750 | } |
| 1751 | |
| 1752 | #endif |
| 1753 | |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1754 | statichere struct HandlerInfo handler_info[] = { |
| 1755 | {"StartElementHandler", |
| 1756 | pyxml_SetStartElementHandler, |
| 1757 | (xmlhandler)my_StartElementHandler}, |
| 1758 | {"EndElementHandler", |
| 1759 | pyxml_SetEndElementHandler, |
| 1760 | (xmlhandler)my_EndElementHandler}, |
| 1761 | {"ProcessingInstructionHandler", |
| 1762 | (xmlhandlersetter)XML_SetProcessingInstructionHandler, |
| 1763 | (xmlhandler)my_ProcessingInstructionHandler}, |
| 1764 | {"CharacterDataHandler", |
| 1765 | (xmlhandlersetter)XML_SetCharacterDataHandler, |
| 1766 | (xmlhandler)my_CharacterDataHandler}, |
| 1767 | {"UnparsedEntityDeclHandler", |
| 1768 | (xmlhandlersetter)XML_SetUnparsedEntityDeclHandler, |
| 1769 | (xmlhandler)my_UnparsedEntityDeclHandler }, |
| 1770 | {"NotationDeclHandler", |
| 1771 | (xmlhandlersetter)XML_SetNotationDeclHandler, |
| 1772 | (xmlhandler)my_NotationDeclHandler }, |
| 1773 | {"StartNamespaceDeclHandler", |
| 1774 | pyxml_SetStartNamespaceDeclHandler, |
| 1775 | (xmlhandler)my_StartNamespaceDeclHandler }, |
| 1776 | {"EndNamespaceDeclHandler", |
| 1777 | pyxml_SetEndNamespaceDeclHandler, |
| 1778 | (xmlhandler)my_EndNamespaceDeclHandler }, |
| 1779 | {"CommentHandler", |
| 1780 | (xmlhandlersetter)XML_SetCommentHandler, |
| 1781 | (xmlhandler)my_CommentHandler}, |
| 1782 | {"StartCdataSectionHandler", |
| 1783 | pyxml_SetStartCdataSection, |
| 1784 | (xmlhandler)my_StartCdataSectionHandler}, |
| 1785 | {"EndCdataSectionHandler", |
| 1786 | pyxml_SetEndCdataSection, |
| 1787 | (xmlhandler)my_EndCdataSectionHandler}, |
| 1788 | {"DefaultHandler", |
| 1789 | (xmlhandlersetter)XML_SetDefaultHandler, |
| 1790 | (xmlhandler)my_DefaultHandler}, |
| 1791 | {"DefaultHandlerExpand", |
| 1792 | (xmlhandlersetter)XML_SetDefaultHandlerExpand, |
| 1793 | (xmlhandler)my_DefaultHandlerExpandHandler}, |
| 1794 | {"NotStandaloneHandler", |
| 1795 | (xmlhandlersetter)XML_SetNotStandaloneHandler, |
| 1796 | (xmlhandler)my_NotStandaloneHandler}, |
| 1797 | {"ExternalEntityRefHandler", |
| 1798 | (xmlhandlersetter)XML_SetExternalEntityRefHandler, |
| 1799 | (xmlhandler)my_ExternalEntityRefHandler }, |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1800 | #if EXPAT_VERSION >= 0x010200 |
| 1801 | {"StartDoctypeDeclHandler", |
| 1802 | pyxml_SetStartDoctypeDeclHandler, |
| 1803 | (xmlhandler)my_StartDoctypeDeclHandler}, |
| 1804 | {"EndDoctypeDeclHandler", |
| 1805 | pyxml_SetEndDoctypeDeclHandler, |
| 1806 | (xmlhandler)my_EndDoctypeDeclHandler}, |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 1807 | #endif |
| 1808 | #if EXPAT_VERSION == 0x010200 |
Martin v. Löwis | 0078f6c | 2001-01-21 10:18:10 +0000 | [diff] [blame] | 1809 | {"ExternalParsedEntityDeclHandler", |
| 1810 | (xmlhandlersetter)XML_SetExternalParsedEntityDeclHandler, |
| 1811 | (xmlhandler)my_ExternalParsedEntityDeclHandler}, |
| 1812 | {"InternalParsedEntityDeclHandler", |
| 1813 | (xmlhandlersetter)XML_SetInternalParsedEntityDeclHandler, |
| 1814 | (xmlhandler)my_InternalParsedEntityDeclHandler}, |
Fred Drake | 85d835f | 2001-02-08 15:39:08 +0000 | [diff] [blame] | 1815 | #endif |
| 1816 | #if EXPAT_VERSION >= 0x015f00 |
| 1817 | {"EntityDeclHandler", |
| 1818 | (xmlhandlersetter)XML_SetEntityDeclHandler, |
| 1819 | (xmlhandler)my_EntityDeclHandler}, |
| 1820 | {"XmlDeclHandler", |
| 1821 | (xmlhandlersetter)XML_SetXmlDeclHandler, |
| 1822 | (xmlhandler)my_XmlDeclHandler}, |
| 1823 | {"ElementDeclHandler", |
| 1824 | (xmlhandlersetter)XML_SetElementDeclHandler, |
| 1825 | (xmlhandler)my_ElementDeclHandler}, |
| 1826 | {"AttlistDeclHandler", |
| 1827 | (xmlhandlersetter)XML_SetAttlistDeclHandler, |
| 1828 | (xmlhandler)my_AttlistDeclHandler}, |
| 1829 | #endif /* Expat version 1.95 or better */ |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1830 | |
Fred Drake | 0582df9 | 2000-07-12 04:49:00 +0000 | [diff] [blame] | 1831 | {NULL, NULL, NULL} /* sentinel */ |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1832 | }; |