Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1 | /*********************************************************** |
| 2 | Copyright 2000 by Stichting Mathematisch Centrum, Amsterdam, |
| 3 | The Netherlands. |
| 4 | |
| 5 | All Rights Reserved |
| 6 | |
Guido van Rossum | fd71b9e | 2000-06-30 23:50:40 +0000 | [diff] [blame] | 7 | Copyright (c) 2000, BeOpen.com. |
| 8 | Copyright (c) 1995-2000, Corporation for National Research Initiatives. |
| 9 | Copyright (c) 1990-1995, Stichting Mathematisch Centrum. |
| 10 | All rights reserved. |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 11 | |
Guido van Rossum | fd71b9e | 2000-06-30 23:50:40 +0000 | [diff] [blame] | 12 | See the file "Misc/COPYRIGHT" for information on usage and |
| 13 | redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 14 | |
| 15 | ******************************************************************/ |
| 16 | |
| 17 | #include "Python.h" |
| 18 | #include "xmlparse.h" |
| 19 | |
| 20 | /* |
| 21 | ** The version number should match the one in _checkversion |
| 22 | */ |
| 23 | #define VERSION "1.9" |
| 24 | |
| 25 | enum HandlerTypes{ |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 26 | StartElement, |
| 27 | EndElement, |
| 28 | ProcessingInstruction, |
| 29 | CharacterData, |
| 30 | UnparsedEntityDecl, |
| 31 | NotationDecl, |
| 32 | StartNamespaceDecl, |
| 33 | EndNamespaceDecl, |
| 34 | Comment, |
| 35 | StartCdataSection, |
| 36 | EndCdataSection, |
| 37 | Default, |
| 38 | DefaultHandlerExpand, |
| 39 | NotStandalone, |
| 40 | ExternalEntityRef |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | static PyObject *ErrorObject; |
| 44 | |
| 45 | /* ----------------------------------------------------- */ |
| 46 | |
| 47 | /* Declarations for objects of type xmlparser */ |
| 48 | |
| 49 | typedef struct { |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 50 | PyObject_HEAD |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 51 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 52 | XML_Parser itself; |
| 53 | int returns_unicode; /* True if Unicode strings are returned; |
| 54 | if false, UTF-8 strings are returned */ |
| 55 | PyObject **handlers; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 56 | } xmlparseobject; |
| 57 | |
| 58 | staticforward PyTypeObject Xmlparsetype; |
| 59 | |
| 60 | typedef void (*xmlhandlersetter)( XML_Parser *self, void *meth ); |
| 61 | typedef void* xmlhandler; |
| 62 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 63 | struct HandlerInfo { |
| 64 | const char *name; |
| 65 | xmlhandlersetter setter; |
| 66 | xmlhandler handler; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 67 | }; |
| 68 | |
Andrew M. Kuchling | 637f664 | 2000-07-04 14:53:43 +0000 | [diff] [blame] | 69 | staticforward struct HandlerInfo handler_info[64]; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 70 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 71 | /* Convert an array of attributes and their values into a Python dict */ |
| 72 | |
| 73 | static PyObject *conv_atts_using_string( XML_Char **atts){ |
| 74 | PyObject *attrs_obj=NULL; |
| 75 | XML_Char **attrs_p, **attrs_k; |
| 76 | int attrs_len; |
| 77 | PyObject *rv; |
| 78 | |
| 79 | if( (attrs_obj = PyDict_New()) == NULL ) |
| 80 | goto finally; |
| 81 | for(attrs_len=0, attrs_p = atts; |
| 82 | *attrs_p; |
| 83 | attrs_p++, attrs_len++) { |
| 84 | if (attrs_len%2) { |
| 85 | rv=PyString_FromString(*attrs_p); |
| 86 | if (! rv) { |
| 87 | Py_DECREF(attrs_obj); |
| 88 | attrs_obj=NULL; |
| 89 | goto finally; |
| 90 | } |
| 91 | if (PyDict_SetItemString( |
| 92 | attrs_obj, |
| 93 | (char*)*attrs_k, rv) < 0){ |
| 94 | Py_DECREF(attrs_obj); |
| 95 | attrs_obj=NULL; |
| 96 | goto finally; |
| 97 | } |
| 98 | Py_DECREF(rv); |
| 99 | } |
| 100 | else attrs_k=attrs_p; |
| 101 | } |
| 102 | finally: |
| 103 | return attrs_obj; |
| 104 | } |
| 105 | |
| 106 | #if !(PY_MAJOR_VERSION == 1 && PY_MINOR_VERSION < 6) |
| 107 | static PyObject *conv_atts_using_unicode( XML_Char **atts){ |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 108 | PyObject *attrs_obj=NULL; |
| 109 | XML_Char **attrs_p, **attrs_k; |
| 110 | int attrs_len; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 111 | |
| 112 | if( (attrs_obj = PyDict_New()) == NULL ) |
| 113 | goto finally; |
| 114 | for(attrs_len=0, attrs_p = atts; |
| 115 | *attrs_p; |
| 116 | attrs_p++, attrs_len++) { |
| 117 | if (attrs_len%2) { |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 118 | PyObject *attr_str, *value_str; |
| 119 | const char *p = (const char *) (*attrs_k); |
| 120 | attr_str=PyUnicode_DecodeUTF8(p, strlen(p), "strict"); |
| 121 | if (! attr_str) { |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 122 | Py_DECREF(attrs_obj); |
| 123 | attrs_obj=NULL; |
| 124 | goto finally; |
| 125 | } |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 126 | p = (const char *) *attrs_p; |
| 127 | value_str=PyUnicode_DecodeUTF8(p, strlen(p), "strict"); |
| 128 | if (! value_str) { |
| 129 | Py_DECREF(attrs_obj); |
| 130 | Py_DECREF(attr_str); |
| 131 | attrs_obj=NULL; |
| 132 | goto finally; |
| 133 | } |
| 134 | if (PyDict_SetItem(attrs_obj, attr_str, value_str) < 0) { |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 135 | Py_DECREF(attrs_obj); |
| 136 | attrs_obj=NULL; |
| 137 | goto finally; |
| 138 | } |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 139 | Py_DECREF(attr_str); |
| 140 | Py_DECREF(value_str); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 141 | } |
| 142 | else attrs_k=attrs_p; |
| 143 | } |
| 144 | finally: |
| 145 | return attrs_obj; |
| 146 | } |
| 147 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 148 | /* Convert a string of XML_Chars into a Unicode string. |
| 149 | Returns None if str is a null pointer. */ |
| 150 | |
| 151 | static PyObject *conv_string_to_unicode( XML_Char *str ) { |
| 152 | /* XXX currently this code assumes that XML_Char is 8-bit, |
| 153 | and hence in UTF-8. */ |
| 154 | /* UTF-8 from Expat, Unicode desired */ |
| 155 | if (str == NULL) {Py_INCREF(Py_None); return Py_None;} |
| 156 | return PyUnicode_DecodeUTF8( (const char *)str, |
| 157 | strlen( (const char *)str ), |
| 158 | "strict" ); |
| 159 | } |
| 160 | |
| 161 | static PyObject *conv_string_len_to_unicode( const XML_Char *str, int len ) { |
| 162 | /* XXX currently this code assumes that XML_Char is 8-bit, |
| 163 | and hence in UTF-8. */ |
| 164 | /* UTF-8 from Expat, Unicode desired */ |
| 165 | if (str == NULL) {Py_INCREF(Py_None); return Py_None;} |
| 166 | return PyUnicode_DecodeUTF8( (const char *)str, |
| 167 | len, |
| 168 | "strict" ); |
| 169 | } |
| 170 | #endif |
| 171 | |
| 172 | /* Convert a string of XML_Chars into an 8-bit Python string. |
| 173 | Returns None if str is a null pointer. */ |
| 174 | |
| 175 | static PyObject *conv_string_to_utf8( XML_Char *str ) { |
| 176 | /* XXX currently this code assumes that XML_Char is 8-bit, |
| 177 | and hence in UTF-8. */ |
| 178 | /* UTF-8 from Expat, UTF-8 desired */ |
| 179 | if (str == NULL) {Py_INCREF(Py_None); return Py_None;} |
| 180 | return PyString_FromString( (const char *)str ); |
| 181 | } |
| 182 | |
| 183 | static PyObject *conv_string_len_to_utf8( const XML_Char *str, |
| 184 | int len ) |
| 185 | { |
| 186 | /* XXX currently this code assumes that XML_Char is 8-bit, |
| 187 | and hence in UTF-8. */ |
| 188 | /* UTF-8 from Expat, UTF-8 desired */ |
| 189 | if (str == NULL) {Py_INCREF(Py_None); return Py_None;} |
| 190 | return PyString_FromStringAndSize( (const char *)str, len ); |
| 191 | } |
| 192 | |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 193 | /* Callback routines */ |
| 194 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 195 | static void clear_handlers( xmlparseobject *self ); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 196 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 197 | static void flag_error( xmlparseobject *self ){ |
| 198 | clear_handlers(self); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | #define RC_HANDLER( RC, NAME, PARAMS, INIT, PARAM_FORMAT, CONVERSION, \ |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 202 | RETURN, GETUSERDATA) \ |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 203 | \ |
| 204 | static RC my_##NAME##Handler PARAMS {\ |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 205 | xmlparseobject *self = GETUSERDATA ; \ |
| 206 | PyObject *args=NULL; \ |
| 207 | PyObject *rv=NULL; \ |
| 208 | INIT \ |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 209 | \ |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 210 | if (self->handlers[NAME] \ |
| 211 | && self->handlers[NAME] != Py_None) { \ |
| 212 | args = Py_BuildValue PARAM_FORMAT ;\ |
| 213 | if (!args) return RETURN; \ |
| 214 | rv = PyEval_CallObject(self->handlers[NAME], args); \ |
| 215 | Py_DECREF(args); \ |
| 216 | if (rv == NULL) { \ |
| 217 | flag_error( self ); \ |
| 218 | return RETURN; \ |
| 219 | } \ |
| 220 | CONVERSION \ |
| 221 | Py_DECREF(rv); \ |
| 222 | } \ |
| 223 | return RETURN; \ |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 224 | } |
| 225 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 226 | #if PY_MAJOR_VERSION == 1 && PY_MINOR_VERSION < 6 |
| 227 | #define STRING_CONV_FUNC conv_string_to_utf8 |
| 228 | #else |
| 229 | /* Python 1.6 and later versions */ |
| 230 | #define STRING_CONV_FUNC (self->returns_unicode \ |
| 231 | ? conv_string_to_unicode : conv_string_to_utf8) |
| 232 | #endif |
Guido van Rossum | 5961f5a | 2000-03-31 16:18:11 +0000 | [diff] [blame] | 233 | |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 234 | #define VOID_HANDLER( NAME, PARAMS, PARAM_FORMAT ) \ |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 235 | RC_HANDLER( void, NAME, PARAMS, ;, PARAM_FORMAT, ;, ;,\ |
| 236 | (xmlparseobject *)userData ) |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 237 | |
| 238 | #define INT_HANDLER( NAME, PARAMS, PARAM_FORMAT )\ |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 239 | RC_HANDLER( int, NAME, PARAMS, int rc=0;, PARAM_FORMAT, \ |
| 240 | rc = PyInt_AsLong( rv );, rc, \ |
| 241 | (xmlparseobject *)userData ) |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 242 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 243 | #if PY_MAJOR_VERSION == 1 && PY_MINOR_VERSION < 6 |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 244 | VOID_HANDLER( StartElement, |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 245 | (void *userData, const XML_Char *name, const XML_Char **atts ), |
| 246 | ("(O&O&)", STRING_CONV_FUNC, name, |
| 247 | conv_atts_using_string, atts ) ) |
| 248 | #else |
| 249 | /* Python 1.6 and later */ |
| 250 | VOID_HANDLER( StartElement, |
| 251 | (void *userData, const XML_Char *name, const XML_Char **atts ), |
| 252 | ("(O&O&)", STRING_CONV_FUNC, name, |
| 253 | (self->returns_unicode |
| 254 | ? conv_atts_using_unicode |
| 255 | : conv_atts_using_string), atts ) ) |
| 256 | #endif |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 257 | |
| 258 | VOID_HANDLER( EndElement, |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 259 | (void *userData, const XML_Char *name ), |
| 260 | ("(O&)", STRING_CONV_FUNC, name) ) |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 261 | |
| 262 | VOID_HANDLER( ProcessingInstruction, |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 263 | (void *userData, |
| 264 | const XML_Char *target, |
| 265 | const XML_Char *data), |
| 266 | ("(O&O&)",STRING_CONV_FUNC,target, STRING_CONV_FUNC,data )) |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 267 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 268 | #if PY_MAJOR_VERSION == 1 && PY_MINOR_VERSION < 6 |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 269 | VOID_HANDLER( CharacterData, |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 270 | (void *userData, const XML_Char *data, int len), |
| 271 | ("(O)", conv_string_len_to_utf8(data,len) ) ) |
| 272 | #else |
| 273 | VOID_HANDLER( CharacterData, |
| 274 | (void *userData, const XML_Char *data, int len), |
| 275 | ("(O)", (self->returns_unicode |
| 276 | ? conv_string_len_to_unicode(data,len) |
| 277 | : conv_string_len_to_utf8(data,len) ) ) ) |
| 278 | #endif |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 279 | |
| 280 | VOID_HANDLER( UnparsedEntityDecl, |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 281 | (void *userData, |
| 282 | const XML_Char *entityName, |
| 283 | const XML_Char *base, |
| 284 | const XML_Char *systemId, |
| 285 | const XML_Char *publicId, |
| 286 | const XML_Char *notationName), |
| 287 | ("(O&O&O&O&O&)", |
| 288 | STRING_CONV_FUNC,entityName, STRING_CONV_FUNC,base, |
| 289 | STRING_CONV_FUNC,systemId, STRING_CONV_FUNC,publicId, |
| 290 | STRING_CONV_FUNC,notationName)) |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 291 | |
| 292 | VOID_HANDLER( NotationDecl, |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 293 | (void *userData, |
| 294 | const XML_Char *notationName, |
| 295 | const XML_Char *base, |
| 296 | const XML_Char *systemId, |
| 297 | const XML_Char *publicId), |
| 298 | ("(O&O&O&O&)", |
| 299 | STRING_CONV_FUNC,notationName, STRING_CONV_FUNC,base, |
| 300 | STRING_CONV_FUNC,systemId, STRING_CONV_FUNC,publicId)) |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 301 | |
| 302 | VOID_HANDLER( StartNamespaceDecl, |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 303 | (void *userData, |
| 304 | const XML_Char *prefix, |
| 305 | const XML_Char *uri), |
| 306 | ("(O&O&)", STRING_CONV_FUNC,prefix, STRING_CONV_FUNC,uri )) |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 307 | |
| 308 | VOID_HANDLER( EndNamespaceDecl, |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 309 | (void *userData, |
| 310 | const XML_Char *prefix), |
| 311 | ("(O&)", STRING_CONV_FUNC,prefix )) |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 312 | |
| 313 | VOID_HANDLER( Comment, |
| 314 | (void *userData, const XML_Char *prefix), |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 315 | ("(O&)", STRING_CONV_FUNC,prefix)) |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 316 | |
| 317 | VOID_HANDLER( StartCdataSection, |
| 318 | (void *userData), |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 319 | ("()" )) |
| 320 | |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 321 | VOID_HANDLER( EndCdataSection, |
| 322 | (void *userData), |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 323 | ("()" )) |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 324 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 325 | #if PY_MAJOR_VERSION == 1 && PY_MINOR_VERSION < 6 |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 326 | VOID_HANDLER( Default, |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 327 | (void *userData, const XML_Char *s, int len), |
| 328 | ("(O)", conv_string_len_to_utf8(s,len) ) ) |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 329 | |
| 330 | VOID_HANDLER( DefaultHandlerExpand, |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 331 | (void *userData, const XML_Char *s, int len), |
| 332 | ("(O)", conv_string_len_to_utf8(s,len) ) ) |
| 333 | #else |
| 334 | VOID_HANDLER( Default, |
| 335 | (void *userData, const XML_Char *s, int len), |
| 336 | ("(O)", (self->returns_unicode |
| 337 | ? conv_string_len_to_unicode(s,len) |
| 338 | : conv_string_len_to_utf8(s,len) ) ) ) |
| 339 | |
| 340 | VOID_HANDLER( DefaultHandlerExpand, |
| 341 | (void *userData, const XML_Char *s, int len), |
| 342 | ("(O)", (self->returns_unicode |
| 343 | ? conv_string_len_to_unicode(s,len) |
| 344 | : conv_string_len_to_utf8(s,len) ) ) ) |
| 345 | #endif |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 346 | |
| 347 | INT_HANDLER( NotStandalone, |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 348 | (void *userData), |
| 349 | ("()")) |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 350 | |
| 351 | RC_HANDLER( int, ExternalEntityRef, |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 352 | (XML_Parser parser, |
| 353 | const XML_Char *context, |
| 354 | const XML_Char *base, |
| 355 | const XML_Char *systemId, |
| 356 | const XML_Char *publicId), |
| 357 | int rc=0;, |
| 358 | ("(O&O&O&O&)", |
| 359 | STRING_CONV_FUNC,context, STRING_CONV_FUNC,base, |
| 360 | STRING_CONV_FUNC,systemId, STRING_CONV_FUNC,publicId ), |
| 361 | rc = PyInt_AsLong( rv );, rc, |
| 362 | XML_GetUserData( parser ) ) |
| 363 | |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 364 | |
| 365 | |
| 366 | /* File reading copied from cPickle */ |
| 367 | |
| 368 | #define UNLESS(E) if (!(E)) |
| 369 | |
| 370 | /* |
| 371 | static int |
| 372 | read_other(xmlparseobject *self, char **s, int n) { |
| 373 | PyObject *bytes=NULL, *str=NULL, *arg=NULL; |
| 374 | int res = -1; |
| 375 | |
| 376 | UNLESS(bytes = PyInt_FromLong(n)) { |
| 377 | if (!PyErr_Occurred()) |
| 378 | PyErr_SetNone(PyExc_EOFError); |
| 379 | |
| 380 | goto finally; |
| 381 | } |
| 382 | |
| 383 | UNLESS(arg) |
| 384 | UNLESS(arg = PyTuple_New(1)) |
| 385 | goto finally; |
| 386 | |
| 387 | Py_INCREF(bytes); |
| 388 | if (PyTuple_SetItem(arg, 0, bytes) < 0) |
| 389 | goto finally; |
| 390 | |
| 391 | UNLESS(str = PyObject_CallObject(self->read, arg)) |
| 392 | goto finally; |
| 393 | |
| 394 | *s = PyString_AsString(str); |
| 395 | |
| 396 | res = n; |
| 397 | |
| 398 | finally: |
| 399 | Py_XDECREF(arg); |
| 400 | Py_XDECREF(bytes); |
| 401 | |
| 402 | return res; |
| 403 | } |
| 404 | |
| 405 | */ |
| 406 | |
| 407 | |
| 408 | |
| 409 | |
| 410 | |
| 411 | /* ---------------------------------------------------------------- */ |
| 412 | |
| 413 | static char xmlparse_Parse__doc__[] = |
| 414 | "(data [,isfinal]) - Parse XML data" |
| 415 | ; |
| 416 | |
| 417 | static PyObject * |
| 418 | xmlparse_Parse( xmlparseobject *self, PyObject *args ) |
| 419 | { |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 420 | char *s; |
| 421 | int slen; |
| 422 | int isFinal = 0; |
| 423 | int rv; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 424 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 425 | if (!PyArg_ParseTuple(args, "s#|i", &s, &slen, &isFinal)) |
| 426 | return NULL; |
| 427 | rv = XML_Parse(self->itself, s, slen, isFinal); |
| 428 | if( PyErr_Occurred() ){ |
| 429 | return NULL; |
| 430 | } |
| 431 | else if (rv == 0) { |
Guido van Rossum | 5db862d | 2000-04-10 12:46:51 +0000 | [diff] [blame] | 432 | PyErr_Format(ErrorObject, "%.200s: line %i, column %i", |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 433 | XML_ErrorString( XML_GetErrorCode(self->itself) ), |
| 434 | XML_GetErrorLineNumber(self->itself), |
| 435 | XML_GetErrorColumnNumber(self->itself) ); |
| 436 | return NULL; |
| 437 | } |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 438 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 439 | return Py_BuildValue("i", rv); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | #define BUF_SIZE 2048 |
| 443 | |
| 444 | int readinst(char *buf, int buf_size, PyObject *meth){ |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 445 | PyObject *arg=NULL; |
| 446 | PyObject *bytes=NULL; |
| 447 | PyObject *str=NULL; |
| 448 | int len; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 449 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 450 | UNLESS(bytes = PyInt_FromLong(buf_size)) { |
| 451 | if (!PyErr_Occurred()) |
| 452 | PyErr_SetNone(PyExc_EOFError); |
| 453 | goto finally; |
| 454 | } |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 455 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 456 | UNLESS(arg) |
| 457 | UNLESS(arg = PyTuple_New(1)) |
| 458 | goto finally; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 459 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 460 | Py_INCREF(bytes); |
| 461 | if (PyTuple_SetItem(arg, 0, bytes) < 0) |
| 462 | goto finally; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 463 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 464 | UNLESS(str = PyObject_CallObject(meth, arg)) |
| 465 | goto finally; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 466 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 467 | UNLESS(PyString_Check( str )) |
| 468 | goto finally; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 469 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 470 | len=PyString_GET_SIZE( str ); |
| 471 | strncpy( buf, PyString_AsString(str), len ); |
| 472 | Py_XDECREF( str ); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 473 | finally: |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 474 | return len; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | static char xmlparse_ParseFile__doc__[] = |
| 478 | "(file) - Parse XML data" |
| 479 | ; |
| 480 | |
| 481 | static PyObject * |
| 482 | xmlparse_ParseFile( xmlparseobject *self, PyObject *args ) |
| 483 | { |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 484 | int rv=1; |
| 485 | PyObject *f; |
| 486 | FILE *fp; |
| 487 | PyObject *readmethod=NULL; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 488 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 489 | if (!PyArg_ParseTuple(args, "O", &f)) |
| 490 | return NULL; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 491 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 492 | if (PyFile_Check(f)) { |
| 493 | fp = PyFile_AsFile(f); |
| 494 | }else{ |
| 495 | fp = NULL; |
| 496 | UNLESS(readmethod = PyObject_GetAttrString(f, "read")) { |
| 497 | PyErr_Clear(); |
| 498 | PyErr_SetString( PyExc_TypeError, |
| 499 | "argument must have 'read' attribute" ); |
| 500 | return 0; |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | for (;;) { |
| 505 | int bytes_read; |
| 506 | void *buf = XML_GetBuffer(self->itself, BUF_SIZE); |
| 507 | if (buf == NULL) { |
| 508 | PyErr_SetString(PyExc_MemoryError, "out of memory"); |
| 509 | return NULL; |
| 510 | } |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 511 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 512 | if( fp ){ |
| 513 | bytes_read=fread( buf, sizeof( char ), BUF_SIZE, fp); |
| 514 | }else{ |
| 515 | bytes_read=readinst( buf, BUF_SIZE, readmethod ); |
| 516 | } |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 517 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 518 | if (bytes_read < 0) { |
| 519 | PyErr_SetFromErrno(PyExc_IOError); |
| 520 | return NULL; |
| 521 | } |
| 522 | rv=XML_ParseBuffer(self->itself, bytes_read, bytes_read == 0); |
| 523 | if( PyErr_Occurred() ){ |
| 524 | return NULL; |
| 525 | } |
| 526 | if (!rv || bytes_read == 0) |
| 527 | break; |
| 528 | } |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 529 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 530 | return Py_BuildValue("i", rv); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | static char xmlparse_SetBase__doc__[] = |
| 534 | "(base_url) - Base URL string" |
| 535 | ; |
| 536 | |
| 537 | static PyObject * |
| 538 | xmlparse_SetBase( xmlparseobject *self, PyObject *args ){ |
| 539 | char *base; |
| 540 | |
| 541 | if (!PyArg_ParseTuple(args, "s", &base)) |
| 542 | return NULL; |
| 543 | if( !XML_SetBase( self->itself, base ) ){ |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 544 | PyErr_SetNone(PyExc_MemoryError); |
| 545 | return NULL; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | Py_INCREF(Py_None); |
| 549 | return Py_None; |
| 550 | } |
| 551 | |
| 552 | static char xmlparse_GetBase__doc__[] = |
| 553 | "() - returns base URL string " |
| 554 | ; |
| 555 | |
| 556 | static PyObject * |
| 557 | xmlparse_GetBase( xmlparseobject *self, PyObject *args ){ |
| 558 | const XML_Char *base; |
| 559 | PyObject *rc; |
| 560 | |
| 561 | if( PyTuple_Size( args )!=0 ){ |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 562 | PyArg_ParseTuple(args, "()" ); /* get good error reporting */ |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 563 | return NULL; |
| 564 | } |
| 565 | base=XML_GetBase( self->itself ); |
| 566 | if( base ){ |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 567 | rc=Py_BuildValue("s", base); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 568 | }else{ |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 569 | Py_INCREF(Py_None); |
| 570 | rc=Py_None; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 571 | } |
| 572 | return rc; |
| 573 | |
| 574 | } |
| 575 | |
| 576 | static struct PyMethodDef xmlparse_methods[] = { |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 577 | {"Parse", (PyCFunction)xmlparse_Parse, |
| 578 | METH_VARARGS, xmlparse_Parse__doc__}, |
| 579 | {"ParseFile", (PyCFunction)xmlparse_ParseFile, |
| 580 | METH_VARARGS, xmlparse_ParseFile__doc__}, |
| 581 | {"SetBase", (PyCFunction)xmlparse_SetBase, |
| 582 | METH_VARARGS, xmlparse_SetBase__doc__}, |
| 583 | {"GetBase", (PyCFunction)xmlparse_GetBase, |
| 584 | METH_VARARGS, xmlparse_GetBase__doc__}, |
| 585 | {NULL, NULL} /* sentinel */ |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 586 | }; |
| 587 | |
| 588 | /* ---------- */ |
| 589 | |
| 590 | |
| 591 | static xmlparseobject * |
| 592 | newxmlparseobject( char *encoding, char *namespace_separator){ |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 593 | int i; |
| 594 | xmlparseobject *self; |
| 595 | |
| 596 | #if PY_MAJOR_VERSION == 1 && PY_MINOR_VERSION < 6 |
| 597 | self = PyObject_NEW(xmlparseobject, &Xmlparsetype); |
| 598 | if (self == NULL) |
| 599 | return NULL; |
| 600 | |
| 601 | self->returns_unicode = 0; |
| 602 | #else |
| 603 | /* Code for versions 1.6 and later */ |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 604 | self = PyObject_New(xmlparseobject, &Xmlparsetype); |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 605 | if (self == NULL) |
| 606 | return NULL; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 607 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 608 | self->returns_unicode = 1; |
| 609 | #endif |
| 610 | if (namespace_separator) { |
| 611 | self->itself = XML_ParserCreateNS(encoding, |
| 612 | *namespace_separator); |
| 613 | }else{ |
| 614 | self->itself = XML_ParserCreate(encoding); |
| 615 | } |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 616 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 617 | if( self->itself==NULL ){ |
| 618 | PyErr_SetString(PyExc_RuntimeError, |
| 619 | "XML_ParserCreate failed"); |
| 620 | Py_DECREF(self); |
| 621 | return NULL; |
| 622 | } |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 623 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 624 | XML_SetUserData(self->itself, (void *)self); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 625 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 626 | for( i=0; handler_info[i].name!=NULL;i++); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 627 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 628 | self->handlers=malloc( sizeof( PyObject *)*i ); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 629 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 630 | clear_handlers( self ); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 631 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 632 | return self; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | |
| 636 | static void |
| 637 | xmlparse_dealloc( xmlparseobject *self ) |
| 638 | { |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 639 | int i; |
| 640 | if (self->itself) |
| 641 | XML_ParserFree(self->itself); |
| 642 | self->itself = NULL; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 643 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 644 | for( i=0; handler_info[i].name!=NULL; i++ ){ |
| 645 | Py_XDECREF( self->handlers[i] ); |
| 646 | } |
| 647 | #if PY_MAJOR_VERSION == 1 && PY_MINOR_VERSION < 6 |
| 648 | /* Code for versions before 1.6 */ |
| 649 | free(self); |
| 650 | #else |
| 651 | /* Code for versions 1.6 and later */ |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 652 | PyObject_Del(self); |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 653 | #endif |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | static int handlername2int( const char *name ){ |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 657 | int i; |
| 658 | for( i=0;handler_info[i].name!=NULL;i++){ |
| 659 | if( strcmp( name, handler_info[i].name )==0 ){ |
| 660 | return i; |
| 661 | } |
| 662 | } |
| 663 | return -1; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | static PyObject * |
| 667 | xmlparse_getattr(xmlparseobject *self, char *name) |
| 668 | { |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 669 | int handlernum; |
| 670 | if (strcmp(name, "ErrorCode") == 0) |
| 671 | return Py_BuildValue("l", |
| 672 | (long)XML_GetErrorCode(self->itself)); |
| 673 | if (strcmp(name, "ErrorLineNumber") == 0) |
| 674 | return Py_BuildValue("l", |
| 675 | (long)XML_GetErrorLineNumber(self->itself)); |
| 676 | if (strcmp(name, "ErrorColumnNumber") == 0) |
| 677 | return Py_BuildValue("l", |
| 678 | (long)XML_GetErrorColumnNumber(self->itself)); |
| 679 | if (strcmp(name, "ErrorByteIndex") == 0) |
| 680 | return Py_BuildValue("l", |
| 681 | XML_GetErrorByteIndex(self->itself)); |
| 682 | if (strcmp(name, "returns_unicode") == 0) |
| 683 | return Py_BuildValue("i", self->returns_unicode); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 684 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 685 | handlernum=handlername2int( name ); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 686 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 687 | if( handlernum!=-1 && self->handlers[handlernum]!=NULL){ |
| 688 | Py_INCREF( self->handlers[handlernum] ); |
| 689 | return self->handlers[handlernum]; |
| 690 | } |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 691 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 692 | if (strcmp(name, "__members__") == 0){ |
| 693 | int i; |
| 694 | PyObject *rc=PyList_New(0); |
| 695 | for(i=0; handler_info[i].name!=NULL;i++ ){ |
| 696 | PyList_Append( rc, |
| 697 | PyString_FromString( handler_info[i].name ) ); |
| 698 | } |
| 699 | PyList_Append( rc, PyString_FromString( "ErrorCode" )); |
| 700 | PyList_Append( rc, PyString_FromString( "ErrorLineNumber" )); |
| 701 | PyList_Append( rc, PyString_FromString( "ErrorColumnNumber")); |
| 702 | PyList_Append( rc, PyString_FromString( "ErrorByteIndex" )); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 703 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 704 | return rc; |
| 705 | } |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 706 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 707 | return Py_FindMethod(xmlparse_methods, (PyObject *)self, name); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | static int sethandler( xmlparseobject *self, const char *name, PyObject* v ){ |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 711 | int handlernum = handlername2int( name ); |
| 712 | if( handlernum!=-1 ){ |
| 713 | Py_INCREF( v ); |
| 714 | Py_XDECREF( self->handlers[handlernum] ); |
| 715 | self->handlers[handlernum]=v; |
| 716 | handler_info[handlernum].setter( self->itself, |
| 717 | handler_info[handlernum].handler ); |
| 718 | return 1; |
| 719 | } |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 720 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 721 | return 0; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | static int |
| 725 | xmlparse_setattr( xmlparseobject *self, char *name, PyObject *v) |
| 726 | { |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 727 | /* Set attribute 'name' to value 'v'. v==NULL means delete */ |
| 728 | if (v==NULL) { |
| 729 | PyErr_SetString(PyExc_RuntimeError, "Cannot delete attribute"); |
| 730 | return -1; |
| 731 | } |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 732 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 733 | if (strcmp(name, "returns_unicode") == 0) { |
| 734 | PyObject *intobj = PyNumber_Int(v); |
| 735 | if (intobj == NULL) return -1; |
| 736 | if (PyInt_AsLong(intobj)) { |
| 737 | #if PY_MAJOR_VERSION == 1 && PY_MINOR_VERSION < 6 |
| 738 | PyErr_SetString(PyExc_ValueError, |
| 739 | "Cannot return Unicode strings in Python 1.5"); |
| 740 | return -1; |
| 741 | #else |
| 742 | self->returns_unicode = 1; |
| 743 | #endif |
| 744 | } |
| 745 | else self->returns_unicode = 0; |
| 746 | Py_DECREF(intobj); |
| 747 | return 0; |
| 748 | } |
| 749 | if( sethandler( self, name, v ) ){ |
| 750 | return 0; |
| 751 | } |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 752 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 753 | PyErr_SetString( PyExc_AttributeError, name ); |
| 754 | return -1; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | static char Xmlparsetype__doc__[] = |
| 758 | "XML parser" |
| 759 | ; |
| 760 | |
| 761 | static PyTypeObject Xmlparsetype = { |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 762 | PyObject_HEAD_INIT(NULL) |
| 763 | 0, /*ob_size*/ |
| 764 | "xmlparser", /*tp_name*/ |
| 765 | sizeof(xmlparseobject), /*tp_basicsize*/ |
| 766 | 0, /*tp_itemsize*/ |
| 767 | /* methods */ |
| 768 | (destructor)xmlparse_dealloc, /*tp_dealloc*/ |
| 769 | (printfunc)0, /*tp_print*/ |
| 770 | (getattrfunc)xmlparse_getattr, /*tp_getattr*/ |
| 771 | (setattrfunc)xmlparse_setattr, /*tp_setattr*/ |
| 772 | (cmpfunc)0, /*tp_compare*/ |
| 773 | (reprfunc)0, /*tp_repr*/ |
| 774 | 0, /*tp_as_number*/ |
| 775 | 0, /*tp_as_sequence*/ |
| 776 | 0, /*tp_as_mapping*/ |
| 777 | (hashfunc)0, /*tp_hash*/ |
| 778 | (ternaryfunc)0, /*tp_call*/ |
| 779 | (reprfunc)0, /*tp_str*/ |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 780 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 781 | /* Space for future expansion */ |
| 782 | 0L,0L,0L,0L, |
| 783 | Xmlparsetype__doc__ /* Documentation string */ |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 784 | }; |
| 785 | |
| 786 | /* End of code for xmlparser objects */ |
| 787 | /* -------------------------------------------------------- */ |
| 788 | |
| 789 | |
| 790 | static char pyexpat_ParserCreate__doc__[] = |
| 791 | "([encoding, namespace_separator]) - Return a new XML parser object" |
| 792 | ; |
| 793 | |
| 794 | static PyObject * |
| 795 | pyexpat_ParserCreate(PyObject *notused, PyObject *args, PyObject *kw) { |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 796 | char *encoding = NULL, *namespace_separator=NULL; |
| 797 | static char *kwlist[] = {"encoding", "namespace_separator", NULL}; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 798 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 799 | if (!PyArg_ParseTupleAndKeywords(args, kw, "|zz", kwlist, |
| 800 | &encoding, &namespace_separator)) |
| 801 | return NULL; |
| 802 | return (PyObject *)newxmlparseobject(encoding, namespace_separator); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | static char pyexpat_ErrorString__doc__[] = |
| 806 | "(errno) Returns string error for given number" |
| 807 | ; |
| 808 | |
| 809 | static PyObject * |
| 810 | pyexpat_ErrorString(self, args) |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 811 | PyObject *self; /* Not used */ |
| 812 | PyObject *args; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 813 | { |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 814 | long code; |
| 815 | |
| 816 | if (!PyArg_ParseTuple(args, "l", &code)) |
| 817 | return NULL; |
| 818 | return Py_BuildValue("z", XML_ErrorString((int)code)); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | /* List of methods defined in the module */ |
| 822 | |
| 823 | static struct PyMethodDef pyexpat_methods[] = { |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 824 | {"ParserCreate", (PyCFunction)pyexpat_ParserCreate, |
| 825 | METH_VARARGS|METH_KEYWORDS, pyexpat_ParserCreate__doc__}, |
| 826 | {"ErrorString", (PyCFunction)pyexpat_ErrorString, |
| 827 | METH_VARARGS, pyexpat_ErrorString__doc__}, |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 828 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 829 | {NULL, (PyCFunction)NULL, 0, NULL} /* sentinel */ |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 830 | }; |
| 831 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 832 | /* Module docstring */ |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 833 | |
| 834 | static char pyexpat_module_documentation[] = |
| 835 | "Python wrapper for Expat parser." |
| 836 | ; |
| 837 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 838 | /* Initialization function for the module */ |
| 839 | |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 840 | void |
| 841 | initpyexpat(){ |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 842 | PyObject *m, *d; |
Fred Drake | 7bd9f41 | 2000-07-04 23:51:31 +0000 | [diff] [blame] | 843 | char *rev = "$Revision$"; |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 844 | PyObject *errors_module, *errors_dict; |
Fred Drake | 7bd9f41 | 2000-07-04 23:51:31 +0000 | [diff] [blame] | 845 | PyObject *sys_modules; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 846 | |
Fred Drake | 7bd9f41 | 2000-07-04 23:51:31 +0000 | [diff] [blame] | 847 | Xmlparsetype.ob_type = &PyType_Type; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 848 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 849 | /* Create the module and add the functions */ |
| 850 | m = Py_InitModule4("pyexpat", pyexpat_methods, |
Fred Drake | 7bd9f41 | 2000-07-04 23:51:31 +0000 | [diff] [blame] | 851 | pyexpat_module_documentation, |
| 852 | (PyObject*)NULL, PYTHON_API_VERSION); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 853 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 854 | /* Add some symbolic constants to the module */ |
| 855 | d = PyModule_GetDict(m); |
| 856 | ErrorObject = PyString_FromString("pyexpat.error"); |
| 857 | PyDict_SetItemString(d, "error", ErrorObject); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 858 | |
Fred Drake | 7bd9f41 | 2000-07-04 23:51:31 +0000 | [diff] [blame] | 859 | PyDict_SetItemString(d, "__version__", |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 860 | PyString_FromStringAndSize(rev+11, |
| 861 | strlen(rev+11)-2)); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 862 | |
Fred Drake | 7bd9f41 | 2000-07-04 23:51:31 +0000 | [diff] [blame] | 863 | sys_modules = PySys_GetObject("modules"); |
| 864 | errors_module = PyModule_New("pyexpat.errors"); |
| 865 | PyDict_SetItemString(d, "errors", errors_module); |
| 866 | PyDict_SetItemString(sys_modules, "pyexpat.errors", errors_module); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 867 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 868 | /* XXX When Expat supports some way of figuring out how it was |
| 869 | compiled, this should check and set native_encoding |
| 870 | appropriately. |
| 871 | */ |
| 872 | PyDict_SetItemString(d, "native_encoding", |
Fred Drake | 7bd9f41 | 2000-07-04 23:51:31 +0000 | [diff] [blame] | 873 | PyString_FromString("UTF-8")); |
| 874 | errors_dict = PyModule_GetDict(errors_module); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 875 | |
| 876 | #define MYCONST(name) \ |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 877 | PyDict_SetItemString(errors_dict, #name, \ |
Fred Drake | 7bd9f41 | 2000-07-04 23:51:31 +0000 | [diff] [blame] | 878 | PyString_FromString(XML_ErrorString(name))) |
| 879 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 880 | MYCONST(XML_ERROR_NO_MEMORY); |
| 881 | MYCONST(XML_ERROR_SYNTAX); |
| 882 | MYCONST(XML_ERROR_NO_ELEMENTS); |
| 883 | MYCONST(XML_ERROR_INVALID_TOKEN); |
| 884 | MYCONST(XML_ERROR_UNCLOSED_TOKEN); |
| 885 | MYCONST(XML_ERROR_PARTIAL_CHAR); |
| 886 | MYCONST(XML_ERROR_TAG_MISMATCH); |
| 887 | MYCONST(XML_ERROR_DUPLICATE_ATTRIBUTE); |
| 888 | MYCONST(XML_ERROR_JUNK_AFTER_DOC_ELEMENT); |
| 889 | MYCONST(XML_ERROR_PARAM_ENTITY_REF); |
| 890 | MYCONST(XML_ERROR_UNDEFINED_ENTITY); |
| 891 | MYCONST(XML_ERROR_RECURSIVE_ENTITY_REF); |
| 892 | MYCONST(XML_ERROR_ASYNC_ENTITY); |
| 893 | MYCONST(XML_ERROR_BAD_CHAR_REF); |
| 894 | MYCONST(XML_ERROR_BINARY_ENTITY_REF); |
| 895 | MYCONST(XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF); |
| 896 | MYCONST(XML_ERROR_MISPLACED_XML_PI); |
| 897 | MYCONST(XML_ERROR_UNKNOWN_ENCODING); |
| 898 | MYCONST(XML_ERROR_INCORRECT_ENCODING); |
Fred Drake | 7bd9f41 | 2000-07-04 23:51:31 +0000 | [diff] [blame] | 899 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 900 | /* Check for errors */ |
| 901 | if (PyErr_Occurred()) |
| 902 | Py_FatalError("can't initialize module pyexpat"); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | void clear_handlers( xmlparseobject *self ){ |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 906 | int i=0; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 907 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 908 | for( i=0;handler_info[i].name!=NULL;i++ ){ |
| 909 | self->handlers[i]=NULL; |
| 910 | handler_info[i].setter( self->itself, NULL ); |
| 911 | } |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 912 | } |
| 913 | |
| 914 | typedef void (*pairsetter)( XML_Parser, void *handler1, void *handler2 ); |
| 915 | |
| 916 | void pyxml_UpdatePairedHandlers( xmlparseobject *self, |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 917 | int startHandler, |
| 918 | int endHandler, |
| 919 | pairsetter setter){ |
| 920 | void *start_handler=NULL; |
| 921 | void *end_handler=NULL; |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 922 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 923 | if( self->handlers[startHandler] && |
| 924 | self->handlers[endHandler]!=Py_None ){ |
| 925 | start_handler=handler_info[startHandler].handler; |
| 926 | } |
| 927 | if( self->handlers[EndElement] && |
| 928 | self->handlers[EndElement] !=Py_None ){ |
| 929 | end_handler=handler_info[endHandler].handler; |
| 930 | } |
| 931 | |
| 932 | setter(self->itself, |
| 933 | start_handler, |
| 934 | end_handler); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | void pyxml_SetStartElementHandler( XML_Parser *parser, |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 938 | void *junk){ |
| 939 | pyxml_UpdatePairedHandlers( |
| 940 | (xmlparseobject *)XML_GetUserData( parser ), |
| 941 | StartElement, EndElement, |
| 942 | (pairsetter)XML_SetElementHandler); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | void pyxml_SetEndElementHandler( XML_Parser *parser, |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 946 | void *junk){ |
| 947 | pyxml_UpdatePairedHandlers( |
| 948 | (xmlparseobject *)XML_GetUserData( parser ), |
| 949 | StartElement, EndElement, |
| 950 | (pairsetter)XML_SetElementHandler); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 951 | } |
| 952 | |
| 953 | void pyxml_SetStartNamespaceDeclHandler( XML_Parser *parser, |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 954 | void *junk){ |
| 955 | pyxml_UpdatePairedHandlers( |
| 956 | (xmlparseobject *)XML_GetUserData( parser ), |
| 957 | StartNamespaceDecl, EndNamespaceDecl, |
| 958 | (pairsetter)XML_SetNamespaceDeclHandler); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | void pyxml_SetEndNamespaceDeclHandler( XML_Parser *parser, |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 962 | void *junk){ |
| 963 | pyxml_UpdatePairedHandlers( |
| 964 | (xmlparseobject *)XML_GetUserData( parser ), |
| 965 | StartNamespaceDecl, EndNamespaceDecl, |
| 966 | (pairsetter)XML_SetNamespaceDeclHandler); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | void pyxml_SetStartCdataSection( XML_Parser *parser, |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 970 | void *junk){ |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 971 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 972 | pyxml_UpdatePairedHandlers( |
| 973 | (xmlparseobject *)XML_GetUserData( parser ), |
| 974 | StartCdataSection, EndCdataSection, |
| 975 | (pairsetter)XML_SetCdataSectionHandler); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | void pyxml_SetEndCdataSection( XML_Parser *parser, |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 979 | void *junk){ |
| 980 | pyxml_UpdatePairedHandlers( |
| 981 | (xmlparseobject *)XML_GetUserData( parser ), |
| 982 | StartCdataSection, EndCdataSection, |
| 983 | (pairsetter)XML_SetCdataSectionHandler); |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 984 | } |
| 985 | |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 986 | statichere struct HandlerInfo handler_info[]= |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 987 | {{"StartElementHandler", |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 988 | pyxml_SetStartElementHandler, |
Andrew M. Kuchling | 637f664 | 2000-07-04 14:53:43 +0000 | [diff] [blame] | 989 | (xmlhandler)my_StartElementHandler}, |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 990 | {"EndElementHandler", |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 991 | pyxml_SetEndElementHandler, |
Andrew M. Kuchling | 637f664 | 2000-07-04 14:53:43 +0000 | [diff] [blame] | 992 | (xmlhandler)my_EndElementHandler}, |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 993 | {"ProcessingInstructionHandler", |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 994 | (xmlhandlersetter)XML_SetProcessingInstructionHandler, |
Andrew M. Kuchling | 637f664 | 2000-07-04 14:53:43 +0000 | [diff] [blame] | 995 | (xmlhandler)my_ProcessingInstructionHandler}, |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 996 | {"CharacterDataHandler", |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 997 | (xmlhandlersetter)XML_SetCharacterDataHandler, |
Andrew M. Kuchling | 637f664 | 2000-07-04 14:53:43 +0000 | [diff] [blame] | 998 | (xmlhandler)my_CharacterDataHandler}, |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 999 | {"UnparsedEntityDeclHandler", |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 1000 | (xmlhandlersetter)XML_SetUnparsedEntityDeclHandler, |
Andrew M. Kuchling | 637f664 | 2000-07-04 14:53:43 +0000 | [diff] [blame] | 1001 | (xmlhandler)my_UnparsedEntityDeclHandler }, |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1002 | {"NotationDeclHandler", |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 1003 | (xmlhandlersetter)XML_SetNotationDeclHandler, |
Andrew M. Kuchling | 637f664 | 2000-07-04 14:53:43 +0000 | [diff] [blame] | 1004 | (xmlhandler)my_NotationDeclHandler }, |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1005 | {"StartNamespaceDeclHandler", |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 1006 | pyxml_SetStartNamespaceDeclHandler, |
Andrew M. Kuchling | 637f664 | 2000-07-04 14:53:43 +0000 | [diff] [blame] | 1007 | (xmlhandler)my_StartNamespaceDeclHandler }, |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1008 | {"EndNamespaceDeclHandler", |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 1009 | pyxml_SetEndNamespaceDeclHandler, |
Andrew M. Kuchling | 637f664 | 2000-07-04 14:53:43 +0000 | [diff] [blame] | 1010 | (xmlhandler)my_EndNamespaceDeclHandler }, |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1011 | {"CommentHandler", |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 1012 | (xmlhandlersetter)XML_SetCommentHandler, |
Andrew M. Kuchling | 637f664 | 2000-07-04 14:53:43 +0000 | [diff] [blame] | 1013 | (xmlhandler)my_CommentHandler}, |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1014 | {"StartCdataSectionHandler", |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 1015 | pyxml_SetStartCdataSection, |
Andrew M. Kuchling | 637f664 | 2000-07-04 14:53:43 +0000 | [diff] [blame] | 1016 | (xmlhandler)my_StartCdataSectionHandler}, |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1017 | {"EndCdataSectionHandler", |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 1018 | pyxml_SetEndCdataSection, |
Andrew M. Kuchling | 637f664 | 2000-07-04 14:53:43 +0000 | [diff] [blame] | 1019 | (xmlhandler)my_EndCdataSectionHandler}, |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1020 | {"DefaultHandler", |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 1021 | (xmlhandlersetter)XML_SetDefaultHandler, |
Andrew M. Kuchling | 637f664 | 2000-07-04 14:53:43 +0000 | [diff] [blame] | 1022 | (xmlhandler)my_DefaultHandler}, |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1023 | {"DefaultHandlerExpand", |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 1024 | (xmlhandlersetter)XML_SetDefaultHandlerExpand, |
Andrew M. Kuchling | 637f664 | 2000-07-04 14:53:43 +0000 | [diff] [blame] | 1025 | (xmlhandler)my_DefaultHandlerExpandHandler}, |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1026 | {"NotStandaloneHandler", |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 1027 | (xmlhandlersetter)XML_SetNotStandaloneHandler, |
Andrew M. Kuchling | 637f664 | 2000-07-04 14:53:43 +0000 | [diff] [blame] | 1028 | (xmlhandler)my_NotStandaloneHandler}, |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1029 | {"ExternalEntityRefHandler", |
Andrew M. Kuchling | beba056 | 2000-06-27 00:33:30 +0000 | [diff] [blame] | 1030 | (xmlhandlersetter)XML_SetExternalEntityRefHandler, |
Andrew M. Kuchling | 637f664 | 2000-07-04 14:53:43 +0000 | [diff] [blame] | 1031 | (xmlhandler)my_ExternalEntityRefHandler }, |
Andrew M. Kuchling | b7f1053 | 2000-03-31 15:43:31 +0000 | [diff] [blame] | 1032 | |
| 1033 | {NULL, NULL, NULL } /* sentinel */ |
| 1034 | }; |