[Lxml-checkins] r49903 - in lxml/trunk: . src/lxml/html

ianb at codespeak.net ianb at codespeak.net
Tue Dec 18 22:04:53 CET 2007


Author: ianb
Date: Tue Dec 18 22:04:53 2007
New Revision: 49903

Modified:
   lxml/trunk/CHANGES.txt
   lxml/trunk/src/lxml/html/__init__.py
Log:
Added encoding argument to lxml.html.tostring

Modified: lxml/trunk/CHANGES.txt
==============================================================================
--- lxml/trunk/CHANGES.txt	(original)
+++ lxml/trunk/CHANGES.txt	Tue Dec 18 22:04:53 2007
@@ -30,6 +30,7 @@
 * Second argument to ``lxml.etree.Extension()`` helper is no longer
   required, third argument is now a keyword-only argument ``ns``.
 
+* ``lxml.html.tostring`` takes an ``encoding`` argument.
 
 2.0alpha5 (2007-11-24)
 ======================

Modified: lxml/trunk/src/lxml/html/__init__.py
==============================================================================
--- lxml/trunk/src/lxml/html/__init__.py	(original)
+++ lxml/trunk/src/lxml/html/__init__.py	Tue Dec 18 22:04:53 2007
@@ -1259,15 +1259,18 @@
 __replace_meta_content_type = re.compile(
     r'<meta http-equiv="Content-Type".*?>').sub
 
-def tostring(doc, pretty_print=False, include_meta_content_type=False):
+def tostring(doc, pretty_print=False, include_meta_content_type=False,
+             encoding=None):
     """
-    return HTML string representation of the document given 
+    return HTML string representation of the document given
  
-    note: this will create a meta http-equiv="Content" tag in the head
-    and may replace any that are present 
+    note: if include_meta_content_type is true this will create a meta
+    http-equiv="Content" tag in the head; regardless of the value of include_meta_content_type
+    any existing meta http-equiv="Content" tag will be removed
     """
     assert doc is not None
-    html = etree.tostring(doc, method="html", pretty_print=pretty_print)
+    html = etree.tostring(doc, method="html", pretty_print=pretty_print,
+                          encoding=encoding)
     if not include_meta_content_type:
         html = __replace_meta_content_type('', html)
     return html


More information about the lxml-checkins mailing list