1.1 --- a/libxml2dom/macrolib/macrolib.py Sun Apr 08 00:42:34 2007 +0000
1.2 +++ b/libxml2dom/macrolib/macrolib.py Sun Apr 08 00:43:00 2007 +0000
1.3 @@ -532,12 +532,10 @@
1.4 # NOTE: Switching off validation and remote DTD resolution.
1.5 if not html:
1.6 context = libxml2mod.xmlCreateFileParserCtxt(s)
1.7 - libxml2mod.xmlParserSetPedantic(context, 0)
1.8 - libxml2mod.xmlParserSetValidate(context, 0)
1.9 - libxml2mod.xmlCtxtUseOptions(context, XML_PARSE_NOERROR | XML_PARSE_NOWARNING | XML_PARSE_NONET)
1.10 - libxml2mod.xmlParseDocument(context)
1.11 - doc = libxml2mod.xmlParserGetDoc(context)
1.12 - if unfinished or libxml2mod.xmlParserGetWellFormed(context):
1.13 + Parser_configure(context)
1.14 + Parser_parse(context)
1.15 + doc = Parser_document(context)
1.16 + if unfinished or Parser_well_formed(context):
1.17 return doc
1.18 else:
1.19 raise LSException(LSException.PARSE_ERR)
1.20 @@ -548,12 +546,10 @@
1.21 # NOTE: Switching off validation and remote DTD resolution.
1.22 if not html:
1.23 context = libxml2mod.xmlCreateMemoryParserCtxt(s, len(s))
1.24 - libxml2mod.xmlParserSetPedantic(context, 0)
1.25 - libxml2mod.xmlParserSetValidate(context, 0)
1.26 - libxml2mod.xmlCtxtUseOptions(context, XML_PARSE_NOERROR | XML_PARSE_NOWARNING | XML_PARSE_NONET)
1.27 - libxml2mod.xmlParseDocument(context)
1.28 - doc = libxml2mod.xmlParserGetDoc(context)
1.29 - if unfinished or libxml2mod.xmlParserGetWellFormed(context):
1.30 + Parser_configure(context)
1.31 + Parser_parse(context)
1.32 + doc = Parser_document(context)
1.33 + if unfinished or Parser_well_formed(context):
1.34 return doc
1.35 else:
1.36 raise LSException(LSException.PARSE_ERR)
1.37 @@ -567,12 +563,10 @@
1.38 # NOTE: Switching off validation and remote DTD resolution.
1.39 if not html:
1.40 context = libxml2mod.xmlCreateURLParserCtxt(uri, 0)
1.41 - libxml2mod.xmlParserSetPedantic(context, 0)
1.42 - libxml2mod.xmlParserSetValidate(context, 0)
1.43 - libxml2mod.xmlCtxtUseOptions(context, XML_PARSE_NOERROR | XML_PARSE_NOWARNING | XML_PARSE_NONET)
1.44 - libxml2mod.xmlParseDocument(context)
1.45 - doc = libxml2mod.xmlParserGetDoc(context)
1.46 - if unfinished or libxml2mod.xmlParserGetWellFormed(context):
1.47 + Parser_configure(context)
1.48 + Parser_parse(context)
1.49 + doc = Parser_document(context)
1.50 + if unfinished or Parser_well_formed(context):
1.51 return doc
1.52 else:
1.53 raise LSException(LSException.PARSE_ERR)
1.54 @@ -588,7 +582,7 @@
1.55 def toFile(node, f, encoding=None, prettyprint=0):
1.56 libxml2mod.saveNodeTo(node, f, encoding, prettyprint)
1.57
1.58 -# libxml2mod constants.
1.59 +# libxml2mod constants and helper functions.
1.60
1.61 HTML_PARSE_NOERROR = 32
1.62 HTML_PARSE_NOWARNING = 64
1.63 @@ -597,4 +591,24 @@
1.64 XML_PARSE_NOWARNING = 64
1.65 XML_PARSE_NONET = 2048
1.66
1.67 +def Parser_push():
1.68 + return libxml2mod.xmlCreatePushParser(None, "", 0, None)
1.69 +
1.70 +def Parser_configure(context):
1.71 + libxml2mod.xmlParserSetPedantic(context, 0)
1.72 + libxml2mod.xmlParserSetValidate(context, 0)
1.73 + libxml2mod.xmlCtxtUseOptions(context, XML_PARSE_NOERROR | XML_PARSE_NOWARNING | XML_PARSE_NONET)
1.74 +
1.75 +def Parser_feed(context, s):
1.76 + libxml2mod.xmlParseChunk(context, s, len(s), 1)
1.77 +
1.78 +def Parser_well_formed(context):
1.79 + return libxml2mod.xmlParserGetWellFormed(context)
1.80 +
1.81 +def Parser_document(context):
1.82 + return libxml2mod.xmlParserGetDoc(context)
1.83 +
1.84 +def Parser_parse(context):
1.85 + libxml2mod.xmlParseDocument(context)
1.86 +
1.87 # vim: tabstop=4 expandtab shiftwidth=4