mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
py3: Port some remaining uses of has_key()
This commit is contained in:
parent
a31151e864
commit
b9c781b5e0
@ -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
|
||||
|
||||
|
@ -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')
|
||||
|
@ -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
|
||||
|
@ -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))
|
||||
|
||||
|
@ -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]
|
||||
|
Loading…
x
Reference in New Issue
Block a user