From 34333a1c480dae51f43fbc4583b5ddfe33beeac5 Mon Sep 17 00:00:00 2001 From: Jim Miller Date: Tue, 26 Jan 2016 14:06:55 -0600 Subject: [PATCH] Change deprecated has_key() to has_attr() on BS objects. --- fanficfare/adapters/adapter_masseffect2in.py | 1 - fanficfare/adapters/adapter_twcslibrarynet.py | 4 ++-- fanficfare/adapters/base_adapter.py | 2 +- fanficfare/geturls.py | 2 +- fanficfare/html2text.py | 16 ++++++++-------- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/fanficfare/adapters/adapter_masseffect2in.py b/fanficfare/adapters/adapter_masseffect2in.py index 62609fe..10ada0b 100644 --- a/fanficfare/adapters/adapter_masseffect2in.py +++ b/fanficfare/adapters/adapter_masseffect2in.py @@ -554,7 +554,6 @@ class Chapter(object): def _parseRatingFromImage(self, element): """Given an image element, try to parse story rating from it.""" - # Although deprecated, `has_key()' is required here. if not element.has_attr('src'): return source = element['src'] diff --git a/fanficfare/adapters/adapter_twcslibrarynet.py b/fanficfare/adapters/adapter_twcslibrarynet.py index 2df3bf0..aef477c 100644 --- a/fanficfare/adapters/adapter_twcslibrarynet.py +++ b/fanficfare/adapters/adapter_twcslibrarynet.py @@ -256,9 +256,9 @@ class TheWritersCoffeeShopComSiteAdapter(BaseSiteAdapter): found=False for div in soup.findAll('div'): - if div.has_key('class') and div['class'] == 'notes': + if div.has_attr('class') and div['class'] == 'notes': chapter.append(div) - if div.has_key('id') and div['id'] == 'story': + if div.has_attr('id') and div['id'] == 'story': chapter.append(div) found=True diff --git a/fanficfare/adapters/base_adapter.py b/fanficfare/adapters/base_adapter.py index 0cf6746..c09af43 100644 --- a/fanficfare/adapters/base_adapter.py +++ b/fanficfare/adapters/base_adapter.py @@ -573,7 +573,7 @@ class BaseSiteAdapter(Configurable): acceptable_attributes.extend(('src','alt','longdesc')) for img in soup.findAll('img'): # some pre-existing epubs have img tags that had src stripped off. - if img.has_key('src'): + if img.has_attr('src'): (img['src'],img['longdesc'])=self.story.addImgUrl(url,img['src'],fetch, coverexclusion=self.getConfig('cover_exclusion_regexp')) diff --git a/fanficfare/geturls.py b/fanficfare/geturls.py index 8a4bf7f..9b63c39 100644 --- a/fanficfare/geturls.py +++ b/fanficfare/geturls.py @@ -92,7 +92,7 @@ def get_urls_from_html(data,url=None,configuration=None,normalize=False,restrict #logger.debug("restrict search:%s"%soup) for a in soup.findAll('a'): - if a.has_key('href'): + if a.has_attr('href'): #logger.debug("a['href']:%s"%a['href']) href = form_url(url,a['href']) #logger.debug("1 urlhref:%s"%href) diff --git a/fanficfare/html2text.py b/fanficfare/html2text.py index 1996527..20296a4 100644 --- a/fanficfare/html2text.py +++ b/fanficfare/html2text.py @@ -190,16 +190,16 @@ class _html2text(sgmllib.SGMLParser): If the set of attributes is not found, returns None """ - if not attrs.has_key('href'): return None + if not attrs.has_attr('href'): return None i = -1 for a in self.a: i += 1 match = 0 - if a.has_key('href') and a['href'] == attrs['href']: - if a.has_key('title') or attrs.has_key('title'): - if (a.has_key('title') and attrs.has_key('title') and + if a.has_attr('href') and a['href'] == attrs['href']: + if a.has_attr('title') or attrs.has_attr('title'): + if (a.has_attr('title') and attrs.has_attr('title') and a['title'] == attrs['title']): match = True else: @@ -249,7 +249,7 @@ class _html2text(sgmllib.SGMLParser): self.abbr_title = None self.abbr_data = '' - if attrs.has_key('title'): + if attrs.has_attr('title'): self.abbr_title = attrs['title'] else: if self.abbr_title != None: @@ -262,7 +262,7 @@ class _html2text(sgmllib.SGMLParser): attrsD = {} for (x, y) in attrs: attrsD[x] = y attrs = attrsD - if attrs.has_key('href') and not (SKIP_INTERNAL_LINKS and attrs['href'].startswith('#')): + if attrs.has_attr('href') and not (SKIP_INTERNAL_LINKS and attrs['href'].startswith('#')): self.astack.append(attrs) self.o("[") else: @@ -285,7 +285,7 @@ class _html2text(sgmllib.SGMLParser): attrsD = {} for (x, y) in attrs: attrsD[x] = y attrs = attrsD - if attrs.has_key('src'): + if attrs.has_attr('src'): attrs['href'] = attrs['src'] alt = attrs.get('alt', '') i = self.previousIndex(attrs) @@ -392,7 +392,7 @@ class _html2text(sgmllib.SGMLParser): for link in self.a: if self.outcount > link['outcount']: self.out(" ["+`link['count']`+"]: " + urlparse.urljoin(self.baseurl, link['href'])) - if link.has_key('title'): self.out(" ("+link['title']+")") + if link.has_attr('title'): self.out(" ("+link['title']+")") self.out("\n") else: newa.append(link)