From b9c781b5e005253bae56c803b34997b5efde01d9 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 30 Apr 2019 17:24:05 +0530 Subject: [PATCH] py3: Port some remaining uses of has_key() --- src/calibre/ebooks/lrf/__init__.py | 5 ++--- src/calibre/ebooks/lrf/lrs/convert_from.py | 12 ++++++------ src/calibre/ebooks/txt/markdownml.py | 6 +++--- src/calibre/ebooks/txt/textileml.py | 14 +++++++------- src/calibre/library/add_to_library.py | 4 ++-- 5 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/calibre/ebooks/lrf/__init__.py b/src/calibre/ebooks/lrf/__init__.py index 8ada0d1bd4..6c696b16ed 100644 --- a/src/calibre/ebooks/lrf/__init__.py +++ b/src/calibre/ebooks/lrf/__init__.py @@ -91,7 +91,7 @@ def Book(options, logger, font_delta=0, header=None, linespace=int(10*profile.line_space), baselineskip=baselineskip, wordspace=10*options.wordspace) - if fonts['serif'] and fonts['serif'].has_key('normal'): # noqa + if fonts['serif'] and 'normal' in fonts['serif']: tsd['fontfacename'] = fonts['serif']['normal'][1] book = _Book(textstyledefault=tsd, @@ -108,7 +108,6 @@ def Book(options, logger, font_delta=0, header=None, for family in ['serif', 'sans', 'mono']: if not fonts[family]: fonts[family] = {'normal' : (None, profile.default_fonts[family])} - elif not fonts[family].has_key('normal'): # noqa + elif 'normal' not in fonts[family]: raise ConversionError('Could not find the normal version of the ' + family + ' font') return book, fonts - diff --git a/src/calibre/ebooks/lrf/lrs/convert_from.py b/src/calibre/ebooks/lrf/lrs/convert_from.py index c412ac4814..f5ac2da0bf 100644 --- a/src/calibre/ebooks/lrf/lrs/convert_from.py +++ b/src/calibre/ebooks/lrf/lrs/convert_from.py @@ -166,16 +166,16 @@ class LrsParser(object): if label and \ (label in self._style_labels or label in self.parsed_objects): _obj = (self.parsed_objects[label] if - self.parsed_objects.has_key(label) else # noqa + label in self.parsed_objects else self._style_labels[label]) settings[attrmap[a]] = _obj for a in ('evenfooterid', 'oddfooterid', 'evenheaderid', 'oddheaderid'): - if tag.has_key(a): # noqa + if a in tag: settings[a.replace('id', '')] = self.parsed_objects[tag.get(a)] args = [] - if tag.has_key('refstream'): # noqa + if 'refstream' in tag: args.append(self.parsed_objects[tag.get('refstream')]) - if tag.has_key('canvaswidth'): # noqa + if 'canvaswidth' in tag: args += [tag.get('canvaswidth'), tag.get('canvasheight')] self.parsed_objects[id] = map[tag.name][0](*args, **settings) @@ -193,7 +193,7 @@ class LrsParser(object): settings = self.attrs_to_dict(tag, map[tag.name][1]+['objid']) if tag.name == 'pagestyle': for a in ('evenheaderid', 'oddheaderid', 'evenfooterid', 'oddfooterid'): - if tag.has_key(a): # noqa + if a in tag: settings[a.replace('id', '')] = self.parsed_objects[tag.get(a)] settings.pop('autoindex', '') self.parsed_objects[id] = map[tag.name][0](**settings) @@ -231,7 +231,7 @@ class LrsParser(object): tag = base.find(tagname.lower()) if tag is None: return ('', '', '') - tag = (self.tag_to_string(tag), tag.get('reading') if tag.has_key('reading') else '') # noqa + tag = (self.tag_to_string(tag), tag.get('reading') if 'reading' in tag else '') # noqa return tag title = me(bookinfo, 'Title') diff --git a/src/calibre/ebooks/txt/markdownml.py b/src/calibre/ebooks/txt/markdownml.py index 70346df569..c133854918 100644 --- a/src/calibre/ebooks/txt/markdownml.py +++ b/src/calibre/ebooks/txt/markdownml.py @@ -183,9 +183,9 @@ class MarkdownMLizer(OEB2HTML): tags.append('\n') elif tag == 'a': # Only write links with absolute (external) urls. - if self.opts.keep_links and attribs.has_key('href') and '://' in attribs['href']: # noqa + if self.opts.keep_links and 'href' in attribs and '://' in attribs['href']: title = '' - if attribs.has_key('title'): # noqa + if 'title' in attribs: title = ' "' + attribs['title'] + '"' remove_space = self.remove_space_after_newline title = self.remove_newlines(title) @@ -195,7 +195,7 @@ class MarkdownMLizer(OEB2HTML): elif tag == 'img': if self.opts.keep_image_references: txt = '!' - if attribs.has_key('alt'): # noqa + if 'alt' in attribs: remove_space = self.remove_space_after_newline txt += '[' + self.remove_newlines(attribs['alt']) + ']' self.remove_space_after_newline = remove_space diff --git a/src/calibre/ebooks/txt/textileml.py b/src/calibre/ebooks/txt/textileml.py index b4f12e2e74..eb381dea1e 100644 --- a/src/calibre/ebooks/txt/textileml.py +++ b/src/calibre/ebooks/txt/textileml.py @@ -199,7 +199,7 @@ class TextileMLizer(OEB2HTML): def check_id_tag(self, attribs): txt = '' - if attribs.has_key('id'): # noqa + if 'id' in attribs: txt = '(#'+attribs['id']+ ')' self.our_ids.append('#'+attribs['id']) self.id_no_text = u'\xa0' @@ -336,12 +336,12 @@ class TextileMLizer(OEB2HTML): tags.append('pre\n') elif tag == 'a': if self.opts.keep_links: - if attribs.has_key('href'): # noqa + if 'href' in attribs: text.append('"') tags.append('a') tags.append('":' + attribs['href']) self.our_links.append(attribs['href']) - if attribs.has_key('title'): # noqa + if 'title' in attribs: tags.append('(' + attribs['title'] + ')') self.in_a_link = True else: @@ -353,7 +353,7 @@ class TextileMLizer(OEB2HTML): txt += self.check_valign(style) txt += attribs['src'] text.append(txt) - if attribs.has_key('alt'): # noqa + if 'alt' in attribs: txt = attribs['alt'] if txt != '': text.append('(' + txt + ')') @@ -405,9 +405,9 @@ class TextileMLizer(OEB2HTML): txt = '' txt += self.check_halign(style) txt += self.check_valign(style) - if attribs.has_key('colspan'): # noqa + if 'colspan' in attribs: txt += '\\' + attribs['colspan'] - if attribs.has_key('rowspan'): # noqa + if 'rowspan' in attribs: txt += '/' + attribs['rowspan'] txt += self.check_styles(style) if txt != '': @@ -432,7 +432,7 @@ class TextileMLizer(OEB2HTML): text.append(txt) tags.append('%') - if self.opts.keep_links and attribs.has_key('id'): # noqa + if self.opts.keep_links and 'id' in attribs: if tag not in ('body', 'div', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'span', 'table'): text.append(self.check_id_tag(attribs)) diff --git a/src/calibre/library/add_to_library.py b/src/calibre/library/add_to_library.py index cb117e5f40..b51f418261 100644 --- a/src/calibre/library/add_to_library.py +++ b/src/calibre/library/add_to_library.py @@ -138,8 +138,8 @@ def books_in_folder(folder, one_per_folder, # {{{ continue key = os.path.splitext(path)[0] - if not books.has_key(key): # noqa - books[key] = set([]) + if key not in books: + books[key] = set() books[key].add(path) return [FormatCollection(folder, x) for x in books.values() if x]