Skip to content

Commit 4947146

Browse files
committed
switch to using codecs open
1 parent 482b0ac commit 4947146

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

htmlement.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
# Standard library imports
2929
from xml.etree import ElementTree as Etree
30+
from codecs import open as _open
3031
import warnings
3132
import sys
3233
import re
@@ -58,7 +59,7 @@
5859
name2codepoint["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

Comments
 (0)