mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -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),
|
linespace=int(10*profile.line_space),
|
||||||
baselineskip=baselineskip,
|
baselineskip=baselineskip,
|
||||||
wordspace=10*options.wordspace)
|
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]
|
tsd['fontfacename'] = fonts['serif']['normal'][1]
|
||||||
|
|
||||||
book = _Book(textstyledefault=tsd,
|
book = _Book(textstyledefault=tsd,
|
||||||
@ -108,7 +108,6 @@ def Book(options, logger, font_delta=0, header=None,
|
|||||||
for family in ['serif', 'sans', 'mono']:
|
for family in ['serif', 'sans', 'mono']:
|
||||||
if not fonts[family]:
|
if not fonts[family]:
|
||||||
fonts[family] = {'normal' : (None, profile.default_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')
|
raise ConversionError('Could not find the normal version of the ' + family + ' font')
|
||||||
return book, fonts
|
return book, fonts
|
||||||
|
|
||||||
|
@ -166,16 +166,16 @@ class LrsParser(object):
|
|||||||
if label and \
|
if label and \
|
||||||
(label in self._style_labels or label in self.parsed_objects):
|
(label in self._style_labels or label in self.parsed_objects):
|
||||||
_obj = (self.parsed_objects[label] if
|
_obj = (self.parsed_objects[label] if
|
||||||
self.parsed_objects.has_key(label) else # noqa
|
label in self.parsed_objects else
|
||||||
self._style_labels[label])
|
self._style_labels[label])
|
||||||
settings[attrmap[a]] = _obj
|
settings[attrmap[a]] = _obj
|
||||||
for a in ('evenfooterid', 'oddfooterid', 'evenheaderid', 'oddheaderid'):
|
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)]
|
settings[a.replace('id', '')] = self.parsed_objects[tag.get(a)]
|
||||||
args = []
|
args = []
|
||||||
if tag.has_key('refstream'): # noqa
|
if 'refstream' in tag:
|
||||||
args.append(self.parsed_objects[tag.get('refstream')])
|
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')]
|
args += [tag.get('canvaswidth'), tag.get('canvasheight')]
|
||||||
self.parsed_objects[id] = map[tag.name][0](*args, **settings)
|
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'])
|
settings = self.attrs_to_dict(tag, map[tag.name][1]+['objid'])
|
||||||
if tag.name == 'pagestyle':
|
if tag.name == 'pagestyle':
|
||||||
for a in ('evenheaderid', 'oddheaderid', 'evenfooterid', 'oddfooterid'):
|
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[a.replace('id', '')] = self.parsed_objects[tag.get(a)]
|
||||||
settings.pop('autoindex', '')
|
settings.pop('autoindex', '')
|
||||||
self.parsed_objects[id] = map[tag.name][0](**settings)
|
self.parsed_objects[id] = map[tag.name][0](**settings)
|
||||||
@ -231,7 +231,7 @@ class LrsParser(object):
|
|||||||
tag = base.find(tagname.lower())
|
tag = base.find(tagname.lower())
|
||||||
if tag is None:
|
if tag is None:
|
||||||
return ('', '', '')
|
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
|
return tag
|
||||||
|
|
||||||
title = me(bookinfo, 'Title')
|
title = me(bookinfo, 'Title')
|
||||||
|
@ -183,9 +183,9 @@ class MarkdownMLizer(OEB2HTML):
|
|||||||
tags.append('\n')
|
tags.append('\n')
|
||||||
elif tag == 'a':
|
elif tag == 'a':
|
||||||
# Only write links with absolute (external) urls.
|
# 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 = ''
|
title = ''
|
||||||
if attribs.has_key('title'): # noqa
|
if 'title' in attribs:
|
||||||
title = ' "' + attribs['title'] + '"'
|
title = ' "' + attribs['title'] + '"'
|
||||||
remove_space = self.remove_space_after_newline
|
remove_space = self.remove_space_after_newline
|
||||||
title = self.remove_newlines(title)
|
title = self.remove_newlines(title)
|
||||||
@ -195,7 +195,7 @@ class MarkdownMLizer(OEB2HTML):
|
|||||||
elif tag == 'img':
|
elif tag == 'img':
|
||||||
if self.opts.keep_image_references:
|
if self.opts.keep_image_references:
|
||||||
txt = '!'
|
txt = '!'
|
||||||
if attribs.has_key('alt'): # noqa
|
if 'alt' in attribs:
|
||||||
remove_space = self.remove_space_after_newline
|
remove_space = self.remove_space_after_newline
|
||||||
txt += '[' + self.remove_newlines(attribs['alt']) + ']'
|
txt += '[' + self.remove_newlines(attribs['alt']) + ']'
|
||||||
self.remove_space_after_newline = remove_space
|
self.remove_space_after_newline = remove_space
|
||||||
|
@ -199,7 +199,7 @@ class TextileMLizer(OEB2HTML):
|
|||||||
|
|
||||||
def check_id_tag(self, attribs):
|
def check_id_tag(self, attribs):
|
||||||
txt = ''
|
txt = ''
|
||||||
if attribs.has_key('id'): # noqa
|
if 'id' in attribs:
|
||||||
txt = '(#'+attribs['id']+ ')'
|
txt = '(#'+attribs['id']+ ')'
|
||||||
self.our_ids.append('#'+attribs['id'])
|
self.our_ids.append('#'+attribs['id'])
|
||||||
self.id_no_text = u'\xa0'
|
self.id_no_text = u'\xa0'
|
||||||
@ -336,12 +336,12 @@ class TextileMLizer(OEB2HTML):
|
|||||||
tags.append('pre\n')
|
tags.append('pre\n')
|
||||||
elif tag == 'a':
|
elif tag == 'a':
|
||||||
if self.opts.keep_links:
|
if self.opts.keep_links:
|
||||||
if attribs.has_key('href'): # noqa
|
if 'href' in attribs:
|
||||||
text.append('"')
|
text.append('"')
|
||||||
tags.append('a')
|
tags.append('a')
|
||||||
tags.append('":' + attribs['href'])
|
tags.append('":' + attribs['href'])
|
||||||
self.our_links.append(attribs['href'])
|
self.our_links.append(attribs['href'])
|
||||||
if attribs.has_key('title'): # noqa
|
if 'title' in attribs:
|
||||||
tags.append('(' + attribs['title'] + ')')
|
tags.append('(' + attribs['title'] + ')')
|
||||||
self.in_a_link = True
|
self.in_a_link = True
|
||||||
else:
|
else:
|
||||||
@ -353,7 +353,7 @@ class TextileMLizer(OEB2HTML):
|
|||||||
txt += self.check_valign(style)
|
txt += self.check_valign(style)
|
||||||
txt += attribs['src']
|
txt += attribs['src']
|
||||||
text.append(txt)
|
text.append(txt)
|
||||||
if attribs.has_key('alt'): # noqa
|
if 'alt' in attribs:
|
||||||
txt = attribs['alt']
|
txt = attribs['alt']
|
||||||
if txt != '':
|
if txt != '':
|
||||||
text.append('(' + txt + ')')
|
text.append('(' + txt + ')')
|
||||||
@ -405,9 +405,9 @@ class TextileMLizer(OEB2HTML):
|
|||||||
txt = ''
|
txt = ''
|
||||||
txt += self.check_halign(style)
|
txt += self.check_halign(style)
|
||||||
txt += self.check_valign(style)
|
txt += self.check_valign(style)
|
||||||
if attribs.has_key('colspan'): # noqa
|
if 'colspan' in attribs:
|
||||||
txt += '\\' + attribs['colspan']
|
txt += '\\' + attribs['colspan']
|
||||||
if attribs.has_key('rowspan'): # noqa
|
if 'rowspan' in attribs:
|
||||||
txt += '/' + attribs['rowspan']
|
txt += '/' + attribs['rowspan']
|
||||||
txt += self.check_styles(style)
|
txt += self.check_styles(style)
|
||||||
if txt != '':
|
if txt != '':
|
||||||
@ -432,7 +432,7 @@ class TextileMLizer(OEB2HTML):
|
|||||||
text.append(txt)
|
text.append(txt)
|
||||||
tags.append('%')
|
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'):
|
if tag not in ('body', 'div', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'span', 'table'):
|
||||||
text.append(self.check_id_tag(attribs))
|
text.append(self.check_id_tag(attribs))
|
||||||
|
|
||||||
|
@ -138,8 +138,8 @@ def books_in_folder(folder, one_per_folder, # {{{
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
key = os.path.splitext(path)[0]
|
key = os.path.splitext(path)[0]
|
||||||
if not books.has_key(key): # noqa
|
if key not in books:
|
||||||
books[key] = set([])
|
books[key] = set()
|
||||||
books[key].add(path)
|
books[key].add(path)
|
||||||
|
|
||||||
return [FormatCollection(folder, x) for x in books.values() if x]
|
return [FormatCollection(folder, x) for x in books.values() if x]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user