1.1 --- a/libxml2dom/__init__.py Sat Mar 17 19:45:57 2007 +0000
1.2 +++ b/libxml2dom/__init__.py Sat Mar 17 19:46:52 2007 +0000
1.3 @@ -502,14 +502,15 @@
1.4 def createDocument(namespaceURI, localName, doctype):
1.5 return default_impl.createDocument(namespaceURI, localName, doctype)
1.6
1.7 -def parse(stream_or_string, html=0, impl=None):
1.8 +def parse(stream_or_string, html=0, htmlencoding=None, impl=None):
1.9
1.10 """
1.11 Parse the given 'stream_or_string', where the supplied object can either be
1.12 a stream (such as a file or stream object), or a string (containing the
1.13 filename of a document). If the optional 'html' parameter is set to a true
1.14 value, the content to be parsed will be treated as being HTML rather than
1.15 - XML.
1.16 + XML. If the optional 'htmlencoding' is specified, HTML parsing will be
1.17 + performed with the document encoding assumed to that specified.
1.18
1.19 A document object is returned by this function.
1.20 """
1.21 @@ -518,42 +519,48 @@
1.22
1.23 if hasattr(stream_or_string, "read"):
1.24 stream = stream_or_string
1.25 - return parseString(stream.read(), html, impl)
1.26 + return parseString(stream.read(), html, htmlencoding, impl)
1.27 else:
1.28 - return parseFile(stream_or_string, html, impl)
1.29 + return parseFile(stream_or_string, html, htmlencoding, impl)
1.30
1.31 -def parseFile(filename, html=0, impl=None):
1.32 +def parseFile(filename, html=0, htmlencoding=None, impl=None):
1.33
1.34 """
1.35 Parse the file having the given 'filename'. If the optional 'html' parameter
1.36 is set to a true value, the content to be parsed will be treated as being
1.37 - HTML rather than XML.
1.38 + HTML rather than XML. If the optional 'htmlencoding' is specified, HTML
1.39 + parsing will be performed with the document encoding assumed to be that
1.40 + specified.
1.41
1.42 A document object is returned by this function.
1.43 """
1.44
1.45 impl = impl or default_impl
1.46 - return impl.adoptDocument(Node_parseFile(filename, html))
1.47 + return impl.adoptDocument(Node_parseFile(filename, html, htmlencoding))
1.48
1.49 -def parseString(s, html=0, impl=None):
1.50 +def parseString(s, html=0, htmlencoding=None, impl=None):
1.51
1.52 """
1.53 Parse the content of the given string 's'. If the optional 'html' parameter
1.54 is set to a true value, the content to be parsed will be treated as being
1.55 - HTML rather than XML.
1.56 + HTML rather than XML. If the optional 'htmlencoding' is specified, HTML
1.57 + parsing will be performed with the document encoding assumed to be that
1.58 + specified.
1.59
1.60 A document object is returned by this function.
1.61 """
1.62
1.63 impl = impl or default_impl
1.64 - return impl.adoptDocument(Node_parseString(s, html))
1.65 + return impl.adoptDocument(Node_parseString(s, html, htmlencoding))
1.66
1.67 -def parseURI(uri, html=0, impl=None):
1.68 +def parseURI(uri, html=0, htmlencoding=None, impl=None):
1.69
1.70 """
1.71 Parse the content found at the given 'uri'. If the optional 'html' parameter
1.72 is set to a true value, the content to be parsed will be treated as being
1.73 - HTML rather than XML.
1.74 + HTML rather than XML. If the optional 'htmlencoding' is specified, HTML
1.75 + parsing will be performed with the document encoding assumed to be that
1.76 + specified.
1.77
1.78 XML documents are retrieved using libxml2's own network capabilities; HTML
1.79 documents are retrieved using the urllib module provided by Python. To
1.80 @@ -572,12 +579,12 @@
1.81 if html:
1.82 f = urllib.urlopen(uri)
1.83 try:
1.84 - return parse(f, html, impl)
1.85 + return parse(f, html, htmlencoding, impl)
1.86 finally:
1.87 f.close()
1.88 else:
1.89 impl = impl or default_impl
1.90 - return impl.adoptDocument(Node_parseURI(uri, html))
1.91 + return impl.adoptDocument(Node_parseURI(uri, html, htmlencoding))
1.92
1.93 def toString(node, encoding=None, prettyprint=0):
1.94
2.1 --- a/libxml2dom/macrolib/macrolib.py Sat Mar 17 19:45:57 2007 +0000
2.2 +++ b/libxml2dom/macrolib/macrolib.py Sat Mar 17 19:46:52 2007 +0000
2.3 @@ -501,14 +501,14 @@
2.4 libxml2mod.xmlCreateIntSubset(d, doctype.localName, doctype.publicId, doctype.systemId)
2.5 return d
2.6
2.7 -def parse(stream_or_string, html=0):
2.8 +def parse(stream_or_string, html=0, htmlencoding=None):
2.9 if hasattr(stream_or_string, "read"):
2.10 stream = stream_or_string
2.11 - return parseString(stream.read(), html)
2.12 + return parseString(stream.read(), html, htmlencoding)
2.13 else:
2.14 - return parseFile(stream_or_string, html)
2.15 + return parseFile(stream_or_string, html, htmlencoding)
2.16
2.17 -def parseFile(s, html=0):
2.18 +def parseFile(s, html=0, htmlencoding=None):
2.19 # NOTE: Switching off validation and remote DTD resolution.
2.20 if not html:
2.21 context = libxml2mod.xmlCreateFileParserCtxt(s)
2.22 @@ -518,9 +518,9 @@
2.23 libxml2mod.xmlParseDocument(context)
2.24 return libxml2mod.xmlParserGetDoc(context)
2.25 else:
2.26 - return libxml2mod.htmlReadFile(s, None, HTML_PARSE_NOERROR | HTML_PARSE_NOWARNING | HTML_PARSE_NONET)
2.27 + return libxml2mod.htmlReadFile(s, htmlencoding, HTML_PARSE_NOERROR | HTML_PARSE_NOWARNING | HTML_PARSE_NONET)
2.28
2.29 -def parseString(s, html=0):
2.30 +def parseString(s, html=0, htmlencoding=None):
2.31 # NOTE: Switching off validation and remote DTD resolution.
2.32 if not html:
2.33 context = libxml2mod.xmlCreateMemoryParserCtxt(s, len(s))
2.34 @@ -532,10 +532,10 @@
2.35 else:
2.36 # NOTE: URL given as None.
2.37 html_url = None
2.38 - return libxml2mod.htmlReadMemory(s, len(s), html_url, None,
2.39 + return libxml2mod.htmlReadMemory(s, len(s), html_url, htmlencoding,
2.40 HTML_PARSE_NOERROR | HTML_PARSE_NOWARNING | HTML_PARSE_NONET)
2.41
2.42 -def parseURI(uri, html=0):
2.43 +def parseURI(uri, html=0, htmlencoding=None):
2.44 # NOTE: Switching off validation and remote DTD resolution.
2.45 if not html:
2.46 context = libxml2mod.xmlCreateURLParserCtxt(uri, 0)
3.1 --- a/libxml2dom/svg.py Sat Mar 17 19:45:57 2007 +0000
3.2 +++ b/libxml2dom/svg.py Sat Mar 17 19:46:52 2007 +0000
3.3 @@ -98,17 +98,17 @@
3.4
3.5 # Convenience functions.
3.6
3.7 -def parse(stream_or_string, html=0):
3.8 - return libxml2dom.parse(stream_or_string, html, default_impl)
3.9 +def parse(stream_or_string, html=0, htmlencoding=None):
3.10 + return libxml2dom.parse(stream_or_string, html, htmlencoding, default_impl)
3.11
3.12 -def parseFile(filename, html=0):
3.13 - return libxml2dom.parseFile(filename, html, default_impl)
3.14 +def parseFile(filename, html=0, htmlencoding=None):
3.15 + return libxml2dom.parseFile(filename, html, htmlencoding, default_impl)
3.16
3.17 -def parseString(s, html=0):
3.18 - return libxml2dom.parseString(s, html, default_impl)
3.19 +def parseString(s, html=0, htmlencoding=None):
3.20 + return libxml2dom.parseString(s, html, htmlencoding, default_impl)
3.21
3.22 -def parseURI(uri, html=0):
3.23 - return libxml2dom.parseURI(uri, html, default_impl)
3.24 +def parseURI(uri, html=0, htmlencoding=None):
3.25 + return libxml2dom.parseURI(uri, html, htmlencoding, default_impl)
3.26
3.27 # Single instance of the implementation.
3.28