diff --git a/src/calibre/db/lazy.py b/src/calibre/db/lazy.py
index 79c552d8db..ffa71f8612 100644
--- a/src/calibre/db/lazy.py
+++ b/src/calibre/db/lazy.py
@@ -106,6 +106,7 @@ class FormatsList(MutableBase, MutableSequence):
# }}}
+
# Lazy metadata getters {{{
ga = object.__getattribute__
sa = object.__setattr__
@@ -223,6 +224,7 @@ def has_cover_getter(dbref, book_id, cache):
cache['has_cover'] = ret = _('Yes') if db.field_for('cover', book_id, default_value=False) else ''
return ret
+
fmt_custom = lambda x:list(x) if isinstance(x, tuple) else x
@@ -276,6 +278,7 @@ def user_categories_getter(proxy_metadata):
ret = cache['user_categories'] = db.user_categories_for_books((book_id,), {book_id:proxy_metadata})[book_id]
return ret
+
getters = {
'title':simple_getter('title', _('Unknown')),
'title_sort':simple_getter('sort', _('Unknown')),
diff --git a/src/calibre/devices/udisks.py b/src/calibre/devices/udisks.py
index 7240444f2a..1d90d0f779 100644
--- a/src/calibre/devices/udisks.py
+++ b/src/calibre/devices/udisks.py
@@ -10,6 +10,7 @@ import os, re
from polyglot.builtins import unicode_type
+
def node_mountpoint(node):
def de_mangle(raw):
diff --git a/src/calibre/devices/utils.py b/src/calibre/devices/utils.py
index 506527c668..2240874393 100644
--- a/src/calibre/devices/utils.py
+++ b/src/calibre/devices/utils.py
@@ -59,11 +59,11 @@ def build_template_regexp(template):
try:
template = template.rpartition('/')[2]
- return re.compile(re.sub('{([^}]*)}', f, template) + '([_\d]*$)')
+ return re.compile(re.sub('{([^}]*)}', f, template) + r'([_\d]*$)')
except:
prints(u'Failed to parse template: %r'%template)
template = u'{title} - {authors}'
- return re.compile(re.sub('{([^}]*)}', f, template) + '([_\d]*$)')
+ return re.compile(re.sub('{([^}]*)}', f, template) + r'([_\d]*$)')
def create_upload_path(mdata, fname, template, sanitize,
diff --git a/src/calibre/ebooks/chardet.py b/src/calibre/ebooks/chardet.py
index 2d0dd7efe2..6d08cb61fd 100644
--- a/src/calibre/ebooks/chardet.py
+++ b/src/calibre/ebooks/chardet.py
@@ -61,6 +61,7 @@ def substitute_entites(raw):
from calibre import xml_entity_to_unicode
return ENTITY_PATTERN.sub(xml_entity_to_unicode, raw)
+
_CHARSET_ALIASES = {"macintosh" : "mac-roman",
"x-sjis" : "shift-jis"}
diff --git a/src/calibre/ebooks/conversion/plugins/epub_input.py b/src/calibre/ebooks/conversion/plugins/epub_input.py
index a0216ac9f3..a94e02150e 100644
--- a/src/calibre/ebooks/conversion/plugins/epub_input.py
+++ b/src/calibre/ebooks/conversion/plugins/epub_input.py
@@ -368,7 +368,9 @@ class EPUBInput(InputFormatPlugin):
def add_from_li(li, parent):
href = text = None
for x in li.iterchildren(XHTML('a'), XHTML('span')):
- text = etree.tostring(x, method='text', encoding=unicode_type, with_tail=False).strip() or ' '.join(x.xpath('descendant-or-self::*/@title')).strip()
+ text = etree.tostring(
+ x, method='text', encoding=unicode_type, with_tail=False).strip() or ' '.join(
+ x.xpath('descendant-or-self::*/@title')).strip()
href = x.get('href')
if href:
if href.startswith('#'):
diff --git a/src/calibre/ebooks/conversion/utils.py b/src/calibre/ebooks/conversion/utils.py
index cdae26aed9..e7f3b99dbb 100644
--- a/src/calibre/ebooks/conversion/utils.py
+++ b/src/calibre/ebooks/conversion/utils.py
@@ -309,9 +309,11 @@ class HeuristicProcessor(object):
if float(self.chapters_with_title) / float(hits) > .5:
title_req = True
strict_title = False
- self.log.debug(unicode_type(type_name)+" had "+unicode_type(hits)+" hits - "+unicode_type(self.chapters_no_title)+" chapters with no title, "+
- unicode_type(self.chapters_with_title)+" chapters with titles, "+
- unicode_type(float(self.chapters_with_title) / float(hits))+" percent. ")
+ self.log.debug(
+ unicode_type(type_name)+" had "+unicode_type(hits)+
+ " hits - "+unicode_type(self.chapters_no_title)+" chapters with no title, "+
+ unicode_type(self.chapters_with_title)+" chapters with titles, "+
+ unicode_type(float(self.chapters_with_title) / float(hits))+" percent. ")
if type_name == 'common':
analysis_result.append([chapter_type, n_lookahead_req, strict_title, ignorecase, title_req, log_message, type_name])
elif self.min_chapters <= hits < max_chapters or self.min_chapters < 3 > hits:
diff --git a/src/calibre/ebooks/docx/container.py b/src/calibre/ebooks/docx/container.py
index 8ba8b2ff83..06913667fc 100644
--- a/src/calibre/ebooks/docx/container.py
+++ b/src/calibre/ebooks/docx/container.py
@@ -264,6 +264,7 @@ class DOCX(object):
except EnvironmentError:
pass
+
if __name__ == '__main__':
d = DOCX(sys.argv[-1], extract=False)
- print (d.metadata)
+ print(d.metadata)
diff --git a/src/calibre/ebooks/docx/tables.py b/src/calibre/ebooks/docx/tables.py
index b2cb4b2346..056869aa6a 100644
--- a/src/calibre/ebooks/docx/tables.py
+++ b/src/calibre/ebooks/docx/tables.py
@@ -95,6 +95,7 @@ def read_indent(parent, dest, XPath, get):
ans = _read_width(cs, get)
setattr(dest, 'indent', ans)
+
border_edges = ('left', 'top', 'right', 'bottom', 'insideH', 'insideV')
diff --git a/src/calibre/ebooks/htmlz/oeb2html.py b/src/calibre/ebooks/htmlz/oeb2html.py
index 5797d31ae4..7a77f4c64e 100644
--- a/src/calibre/ebooks/htmlz/oeb2html.py
+++ b/src/calibre/ebooks/htmlz/oeb2html.py
@@ -272,7 +272,7 @@ class OEB2HTMLInlineCSSizer(OEB2HTML):
# as a page break and remove all other page break types that might be set.
style_a = 'page-break-before: always; %s' % re.sub('page-break-[^:]+:[^;]+;?', '', style_a)
# Remove unnecessary spaces.
- style_a = re.sub('\s{2,}', ' ', style_a).strip()
+ style_a = re.sub(r'\s{2,}', ' ', style_a).strip()
tags.append(tag)
# Remove attributes we won't want.
diff --git a/src/calibre/ebooks/lrf/lrfparser.py b/src/calibre/ebooks/lrf/lrfparser.py
index 1760de269a..4915bba235 100644
--- a/src/calibre/ebooks/lrf/lrfparser.py
+++ b/src/calibre/ebooks/lrf/lrfparser.py
@@ -168,5 +168,6 @@ def main(args=sys.argv, logger=None):
logger.info(_('LRS written to ')+opts.out)
return 0
+
if __name__ == '__main__':
sys.exit(main())
diff --git a/src/calibre/ebooks/metadata/mobi.py b/src/calibre/ebooks/metadata/mobi.py
index 26dcbe4793..3c64bf07c4 100644
--- a/src/calibre/ebooks/metadata/mobi.py
+++ b/src/calibre/ebooks/metadata/mobi.py
@@ -335,8 +335,8 @@ class MetadataUpdater(object):
self.original_exth_records.pop(rec[0])
if self.type != "BOOKMOBI":
- raise MobiError("Setting metadata only supported for MOBI files of type 'BOOK'.\n"
- "\tThis is a %r file of type %r" % (self.type[0:4], self.type[4:8]))
+ raise MobiError("Setting metadata only supported for MOBI files of type 'BOOK'.\n"
+ "\tThis is a %r file of type %r" % (self.type[0:4], self.type[4:8]))
recs = []
added_501 = False
diff --git a/src/calibre/ebooks/metadata/rtf.py b/src/calibre/ebooks/metadata/rtf.py
index 31b36ac850..084f0d8ae9 100644
--- a/src/calibre/ebooks/metadata/rtf.py
+++ b/src/calibre/ebooks/metadata/rtf.py
@@ -19,7 +19,7 @@ publisher_pat = re.compile(r'\{\\info.*?\{\\manager(.*?)(? 0:
html += '