From f328f4d8eb8acd93cb634f3372bc2abda5b93385 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 12 Jun 2017 22:37:09 +0530 Subject: [PATCH] pep8 --- src/calibre/db/cli/cmd_add.py | 1 + src/calibre/db/fields.py | 2 +- src/calibre/devices/kobo/driver.py | 6 +++--- src/calibre/utils/formatter.py | 4 ++-- src/calibre/utils/formatter_functions.py | 3 +++ 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/calibre/db/cli/cmd_add.py b/src/calibre/db/cli/cmd_add.py index 2e00cfb8a0..e5edcaf403 100644 --- a/src/calibre/db/cli/cmd_add.py +++ b/src/calibre/db/cli/cmd_add.py @@ -20,6 +20,7 @@ from calibre.utils.localization import canonicalize_lang readonly = False version = 0 # change this if you change signature of implementation() + def to_stream(data): ans = BytesIO(data[1]) ans.name = data[0] diff --git a/src/calibre/db/fields.py b/src/calibre/db/fields.py index e00307187b..036a04f771 100644 --- a/src/calibre/db/fields.py +++ b/src/calibre/db/fields.py @@ -25,6 +25,7 @@ from calibre.utils.localization import calibre_langcode_to_name def bool_sort_key(bools_are_tristate): return (lambda x:{True: 1, False: 2, None: 3}.get(x, 3)) if bools_are_tristate else lambda x:{True: 1, False: 2, None: 2}.get(x, 2) + IDENTITY = lambda x: x @@ -756,4 +757,3 @@ def create_field(name, table, bools_are_tristate, get_template_functions): elif table.metadata['datatype'] == 'series': cls = SeriesField return cls(name, table, bools_are_tristate, get_template_functions) - diff --git a/src/calibre/devices/kobo/driver.py b/src/calibre/devices/kobo/driver.py index 9bd21b1665..867079701a 100644 --- a/src/calibre/devices/kobo/driver.py +++ b/src/calibre/devices/kobo/driver.py @@ -1451,15 +1451,15 @@ class KOBOTOUCH(KOBO): def open_linux(self): super(KOBOTOUCH, self).open_linux() - + self.swap_drives_if_needed() def open_osx(self): # Just dump some info to the logs. super(KOBOTOUCH, self).open_osx() - # Wrap some debugging output in a try/except so that it unlikely to break things completely. - try: + # Wrap some debugging output in a try/except so that it unlikely to break things completely. + try: if DEBUG: from calibre.constants import plugins usbobserver, usbobserver_err = plugins['usbobserver'] diff --git a/src/calibre/utils/formatter.py b/src/calibre/utils/formatter.py index 9e9e3130a5..2a47fc5823 100644 --- a/src/calibre/utils/formatter.py +++ b/src/calibre/utils/formatter.py @@ -12,8 +12,7 @@ import re, string, traceback from calibre import prints from calibre.constants import DEBUG -from calibre.utils.formatter_functions import formatter_functions, compile_user_function -from calibre.utils.config import tweaks +from calibre.utils.formatter_functions import formatter_functions class _Parser(object): @@ -174,6 +173,7 @@ class _Parser(object): else: self.error(_('expression is not function or constant')) + class TemplateFormatter(string.Formatter): ''' Provides a format function that substitutes '' for any missing value diff --git a/src/calibre/utils/formatter_functions.py b/src/calibre/utils/formatter_functions.py index bd3d20ae6e..c5feaf0688 100644 --- a/src/calibre/utils/formatter_functions.py +++ b/src/calibre/utils/formatter_functions.py @@ -1635,6 +1635,7 @@ class UserFunction(FormatterUserFunction): cls = locals_['UserFunction'](name, doc, arg_count, eval_func) return cls + def compile_user_template_functions(funcs): compiled_funcs = {} for func in funcs: @@ -1653,6 +1654,7 @@ def compile_user_template_functions(funcs): traceback.print_exc() return compiled_funcs + def load_user_template_functions(library_uuid, funcs, precompiled_user_functions=None): unload_user_template_functions(library_uuid) if precompiled_user_functions: @@ -1661,5 +1663,6 @@ def load_user_template_functions(library_uuid, funcs, precompiled_user_functions compiled_funcs = compile_user_template_functions(funcs) formatter_functions().register_functions(library_uuid, compiled_funcs.values()) + def unload_user_template_functions(library_uuid): formatter_functions().unregister_functions(library_uuid)