Correct 'hasattr' call for bs3 back compat.

This commit is contained in:
Jim Miller 2014-12-05 22:33:43 -06:00
parent e414f522c6
commit 6aca8d2656
2 changed files with 4 additions and 4 deletions

View file

@ -114,6 +114,7 @@ class PageElement(object):
"""Contains the navigational information for some part of the page
(either a tag or a piece of text)"""
## Added for FFDL.
bs3=True
def setup(self, parent=None, previous=None):

View file

@ -56,7 +56,7 @@ def _replaceNotEntities(data):
return p.sub(r'&\1', data)
def stripHTML(soup):
if isinstance(soup,basestring) or soup.has_attr('bs3'):
if isinstance(soup,basestring) or hasattr(soup, 'bs3'):
return removeAllEntities(re.sub(r'<[^>]+>','',"%s" % soup)).strip()
else:
# bs4 already converts all the entities to UTF8 chars.
@ -72,10 +72,9 @@ def removeAllEntities(text):
# Remove &lt; &lt; and &amp;
return removeEntities(text).replace('&lt;', '<').replace('&gt;', '>').replace('&amp;', '&')
def removeEntities(text):
def removeEntities(text):
if text is None:
return ""
return u""
if not isinstance(text,basestring):
return unicode(text)