diff options
author | Leonard Richardson <leonard.richardson@canonical.com> | 2011-05-21 12:04:42 -0400 |
---|---|---|
committer | Leonard Richardson <leonard.richardson@canonical.com> | 2011-05-21 12:04:42 -0400 |
commit | 60b789089df25026b48d0a63b054bfa1e347aac9 (patch) | |
tree | 1072af757f226864adeb0faea1154f8163d0d629 /bs4/element.py | |
parent | f2f5df1563c3861a1f28bcfc0532d2e54de50cab (diff) |
More Python 3 compatibility.
Diffstat (limited to 'bs4/element.py')
-rw-r--r-- | bs4/element.py | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/bs4/element.py b/bs4/element.py index a10e615..fb768d1 100644 --- a/bs4/element.py +++ b/bs4/element.py @@ -1,6 +1,5 @@ import collections import re -import types from bs4.dammit import EntitySubstitution DEFAULT_OUTPUT_ENCODING = "utf-8" @@ -753,7 +752,7 @@ class SoupStrainer(object): else: match = True markupAttrMap = None - for attr, matchAgainst in self.attrs.items(): + for attr, matchAgainst in list(self.attrs.items()): if not markupAttrMap: if hasattr(markupAttrs, 'get'): markupAttrMap = markupAttrs @@ -794,14 +793,14 @@ class SoupStrainer(object): if self._matches(markup, self.text): found = markup else: - raise Exception, "I don't know how to match against a %s" \ - % markup.__class__ + raise Exception( + "I don't know how to match against a %s" % markup.__class__) return found def _matches(self, markup, matchAgainst): #print "Matching %s against %s" % (markup, matchAgainst) result = False - if matchAgainst == True and type(matchAgainst) == types.BooleanType: + if matchAgainst == True and isinstance(matchAgainst, bool): result = markup != None elif isinstance(matchAgainst, collections.Callable): result = matchAgainst(markup) @@ -821,7 +820,7 @@ class SoupStrainer(object): or not isinstance(matchAgainst, basestring))): result = markup in matchAgainst elif hasattr(matchAgainst, 'items'): - result = markup.has_key(matchAgainst) + result = matchAgainst in markup elif matchAgainst and isinstance(markup, basestring): if isinstance(markup, unicode): matchAgainst = unicode(matchAgainst) |