2727
2828# Standard library imports
2929from xml .etree import ElementTree as Etree
30+ from codecs import open as _open
3031import warnings
3132import sys
3233import re
5859name2codepoint ["apos" ] = 0x0027
5960
6061
61- def fromstring (text , tag = "" , attrs = None , encoding = "" ):
62+ def fromstring (text , tag = "" , attrs = None , encoding = None ):
6263 """
6364 Parse's "HTML" document from a string into an element tree.
6465
@@ -84,7 +85,7 @@ def fromstring(text, tag="", attrs=None, encoding=""):
8485 return parser .close ()
8586
8687
87- def fromstringlist (sequence , tag = "" , attrs = None , encoding = "" ):
88+ def fromstringlist (sequence , tag = "" , attrs = None , encoding = None ):
8889 """
8990 Parses an "HTML document" from a sequence of "HTML sections" into an element tree.
9091
@@ -111,7 +112,7 @@ def fromstringlist(sequence, tag="", attrs=None, encoding=""):
111112 return parser .close ()
112113
113114
114- def parse (source , tag = "" , attrs = None , encoding = "" ):
115+ def parse (source , tag = "" , attrs = None , encoding = None ):
115116 """
116117 Load an external "HTML document" into an element tree.
117118
@@ -134,7 +135,7 @@ def parse(source, tag="", attrs=None, encoding=""):
134135 """
135136 # Assume that source is a file pointer if no read methods is found
136137 if not hasattr (source , "read" ):
137- source = open (source , "rb" )
138+ source = _open (source , "rb" , encoding = encoding )
138139 close_source = True
139140 else :
140141 close_source = False
@@ -186,7 +187,7 @@ class HTMLement(object):
186187 .. _Xpath: https://docs.python.org/3.6/library/xml.etree.elementtree.html#xpath-support
187188 __ XPath_
188189 """
189- def __init__ (self , tag = "" , attrs = None , encoding = "" ):
190+ def __init__ (self , tag = "" , attrs = None , encoding = None ):
190191 self ._parser = ParseHTML (tag , attrs )
191192 self .encoding = encoding
192193 self ._finished = False
0 commit comments