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