mirror of
https://github.com/wassname/FanFicFare.git
synced 2026-09-11 11:52:07 +08:00
Correct 'hasattr' call for bs3 back compat.
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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 < < and &
|
||||
return removeEntities(text).replace('<', '<').replace('>', '>').replace('&', '&')
|
||||
|
||||
def removeEntities(text):
|
||||
|
||||
def removeEntities(text):
|
||||
if text is None:
|
||||
return ""
|
||||
return u""
|
||||
|
||||
if not isinstance(text,basestring):
|
||||
return unicode(text)
|
||||
|
||||
Reference in New Issue
Block a user