Skip to content

Commit

Permalink
Pass the encoding parameter to the parse method in all cases
Browse files Browse the repository at this point in the history
Pass the encoding parameter to the parse method even when using Python 3,
since there are some cases when you need to specify it. Use None as the
default encoding value, respecting html5lib's encoding detection logic.
  • Loading branch information
jesuslosada committed Aug 24, 2015
1 parent 3adb698 commit ae65cd6
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions microdata.py
Expand Up @@ -11,19 +11,14 @@
import simplejson as json


def get_items(location, encoding='UTF-8'):
def get_items(location, encoding=None):
"""
Pass in a string or file-like object and get a list of Items present in the
HTML document.
"""
dom_builder = html5lib.treebuilders.getTreeBuilder("dom")
parser = html5lib.HTMLParser(tree=dom_builder)

if (sys.version_info.major == 3):
tree = parser.parse(location)
else:
tree = parser.parse(location, encoding=encoding)

tree = parser.parse(location, encoding=encoding)
return _find_items(tree)


Expand Down

0 comments on commit ae65cd6

Please sign in to comment.