mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-30 23:00:21 -04:00
Remove use of custom globals
This commit is contained in:
parent
4e4928be1a
commit
fb262b7b57
@ -77,6 +77,7 @@ def to_unicode(raw, encoding='utf-8', errors='strict'):
|
||||
|
||||
def patheq(p1, p2):
|
||||
p = os.path
|
||||
|
||||
def d(x):
|
||||
return p.normcase(p.normpath(p.realpath(p.normpath(x))))
|
||||
if not p1 or not p2:
|
||||
|
@ -4,15 +4,18 @@
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
import errno, os, numbers
|
||||
from collections import namedtuple, OrderedDict
|
||||
from operator import attrgetter
|
||||
import errno
|
||||
import numbers
|
||||
import os
|
||||
from collections import OrderedDict, namedtuple
|
||||
from functools import partial
|
||||
from itertools import zip_longest
|
||||
from operator import attrgetter
|
||||
|
||||
from calibre.constants import config_dir
|
||||
from calibre.utils.localization import _
|
||||
from calibre.utils.lock import ExclusiveFile
|
||||
from polyglot.builtins import itervalues
|
||||
from itertools import zip_longest
|
||||
|
||||
Option = namedtuple('Option', 'name default longdoc shortdoc choices')
|
||||
|
||||
|
@ -7,7 +7,10 @@ __license__ = 'GPL v3'
|
||||
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
import re, string, traceback, numbers
|
||||
import numbers
|
||||
import re
|
||||
import string
|
||||
import traceback
|
||||
from collections import OrderedDict
|
||||
from functools import partial
|
||||
from math import modf
|
||||
@ -18,8 +21,10 @@ from calibre.constants import DEBUG
|
||||
from calibre.ebooks.metadata.book.base import field_metadata
|
||||
from calibre.utils.config import tweaks
|
||||
from calibre.utils.formatter_functions import (
|
||||
formatter_functions, get_database, function_object_type, StoredObjectType)
|
||||
StoredObjectType, formatter_functions, function_object_type, get_database,
|
||||
)
|
||||
from calibre.utils.icu import strcmp
|
||||
from calibre.utils.localization import _
|
||||
from polyglot.builtins import error_message
|
||||
|
||||
|
||||
|
@ -11,21 +11,24 @@ __license__ = 'GPL v3'
|
||||
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
import inspect, re, traceback, numbers
|
||||
import inspect
|
||||
import numbers
|
||||
import re
|
||||
import traceback
|
||||
from contextlib import suppress
|
||||
from datetime import datetime, timedelta
|
||||
from enum import Enum, auto
|
||||
from functools import partial
|
||||
from math import trunc, floor, ceil, modf
|
||||
from math import ceil, floor, modf, trunc
|
||||
|
||||
from calibre import human_readable, prints, prepare_string_for_xml
|
||||
from calibre import human_readable, prepare_string_for_xml, prints
|
||||
from calibre.constants import DEBUG
|
||||
from calibre.ebooks.metadata import title_sort
|
||||
from calibre.utils.config import tweaks
|
||||
from calibre.utils.date import UNDEFINED_DATE, format_date, now, parse_date
|
||||
from calibre.utils.icu import capitalize, sort_key, strcmp
|
||||
from calibre.utils.localization import _, calibre_langcode_to_name, canonicalize_lang
|
||||
from calibre.utils.titlecase import titlecase
|
||||
from calibre.utils.icu import capitalize, strcmp, sort_key
|
||||
from calibre.utils.date import parse_date, format_date, now, UNDEFINED_DATE
|
||||
from calibre.utils.localization import calibre_langcode_to_name, canonicalize_lang
|
||||
from polyglot.builtins import iteritems, itervalues
|
||||
|
||||
|
||||
|
@ -7,6 +7,7 @@ __docformat__ = 'restructuredtext en'
|
||||
|
||||
import os, locale, re, io
|
||||
from gettext import GNUTranslations, NullTranslations
|
||||
from calibre.utils.resources import get_path as P
|
||||
|
||||
from polyglot.builtins import iteritems
|
||||
|
||||
|
@ -21,6 +21,7 @@ import weakref, re
|
||||
|
||||
from calibre.constants import preferred_encoding
|
||||
from calibre.utils.icu import sort_key
|
||||
from calibre.utils.localization import _
|
||||
from calibre import prints
|
||||
from polyglot.binary import as_hex_unicode, from_hex_unicode
|
||||
from polyglot.builtins import codepoint_to_chr
|
||||
|
@ -11,6 +11,7 @@ This module implements a simple commandline SMTP client that supports:
|
||||
import sys, traceback, os, socket, encodings.idna as idna
|
||||
from calibre import isbytestring
|
||||
from calibre.constants import iswindows
|
||||
from calibre.utils.localization import _
|
||||
from polyglot.builtins import as_unicode, native_string_type
|
||||
|
||||
|
||||
|
@ -4,16 +4,19 @@
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
import os, sys, time, traceback
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import traceback
|
||||
from threading import Thread
|
||||
|
||||
|
||||
from calibre import guess_type, prints
|
||||
from calibre.constants import isportable, isfrozen, __version__, DEBUG
|
||||
from calibre.utils.winreg.lib import Key, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE
|
||||
from calibre.constants import DEBUG, __version__, isfrozen, isportable
|
||||
from calibre.utils.localization import _
|
||||
from calibre.utils.lock import singleinstance
|
||||
from polyglot.builtins import iteritems, itervalues
|
||||
from calibre.utils.winreg.lib import HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, Key
|
||||
from calibre_extensions import winutil
|
||||
from polyglot.builtins import iteritems, itervalues
|
||||
|
||||
# See https://msdn.microsoft.com/en-us/library/windows/desktop/cc144154(v=vs.85).aspx
|
||||
|
||||
@ -49,6 +52,7 @@ def default_programs():
|
||||
def extensions(basename):
|
||||
if basename == 'calibre.exe':
|
||||
from calibre.ebooks import BOOK_EXTENSIONS
|
||||
|
||||
# We remove rar and zip as they interfere with 7-zip associations
|
||||
# https://www.mobileread.com/forums/showthread.php?t=256459
|
||||
return set(BOOK_EXTENSIONS) - {'rar', 'zip'}
|
||||
@ -56,8 +60,8 @@ def extensions(basename):
|
||||
from calibre.customize.ui import all_input_formats
|
||||
return set(all_input_formats())
|
||||
if basename == 'ebook-edit.exe':
|
||||
from calibre.ebooks.oeb.polish.main import SUPPORTED
|
||||
from calibre.ebooks.oeb.polish.import_book import IMPORTABLE
|
||||
from calibre.ebooks.oeb.polish.main import SUPPORTED
|
||||
return SUPPORTED | IMPORTABLE
|
||||
|
||||
|
||||
|
@ -6,12 +6,16 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
'''
|
||||
Contains the logic for parsing feeds.
|
||||
'''
|
||||
import time, traceback, copy, re
|
||||
import copy
|
||||
import re
|
||||
import time
|
||||
import traceback
|
||||
from builtins import _
|
||||
|
||||
from calibre.utils.logging import default_log
|
||||
from calibre import entity_to_unicode, strftime, force_unicode
|
||||
from calibre.utils.date import dt_factory, utcnow, local_tz
|
||||
from calibre import entity_to_unicode, force_unicode, strftime
|
||||
from calibre.utils.cleantext import clean_ascii_chars, clean_xml_chars
|
||||
from calibre.utils.date import dt_factory, local_tz, utcnow
|
||||
from calibre.utils.logging import default_log
|
||||
from polyglot.builtins import string_or_bytes
|
||||
|
||||
|
||||
@ -341,6 +345,7 @@ def feed_from_xml(raw_xml, title=None, oldest_article=7,
|
||||
get_article_url=lambda item: item.get('link', None),
|
||||
log=default_log):
|
||||
from calibre.web.feeds.feedparser import parse
|
||||
|
||||
# Handle unclosed escaped entities. They trip up feedparser and HBR for one
|
||||
# generates them
|
||||
raw_xml = re.sub(br'(&#\d+)([^0-9;])', br'\1;\2', raw_xml)
|
||||
|
@ -18,7 +18,7 @@ from urllib.parse import urlparse, urlsplit
|
||||
|
||||
from calibre import (
|
||||
__appname__, as_unicode, browser, force_unicode, iswindows, preferred_encoding,
|
||||
random_user_agent, strftime
|
||||
random_user_agent, strftime,
|
||||
)
|
||||
from calibre.ebooks.BeautifulSoup import BeautifulSoup, CData, NavigableString, Tag
|
||||
from calibre.ebooks.metadata import MetaInformation
|
||||
@ -28,13 +28,13 @@ from calibre.ptempfile import PersistentTemporaryFile
|
||||
from calibre.utils.date import now as nowf
|
||||
from calibre.utils.icu import numeric_sort_key
|
||||
from calibre.utils.img import add_borders_to_image, image_to_data, save_cover_data_to
|
||||
from calibre.utils.localization import canonicalize_lang
|
||||
from calibre.utils.localization import _, canonicalize_lang
|
||||
from calibre.utils.logging import ThreadSafeWrapper
|
||||
from calibre.utils.threadpool import NoResultsPending, ThreadPool, WorkRequest
|
||||
from calibre.web import Recipe
|
||||
from calibre.web.feeds import Feed, feed_from_xml, feeds_from_index, templates
|
||||
from calibre.web.fetch.simple import (
|
||||
AbortArticle, RecursiveFetcher, option_parser as web2disk_option_parser
|
||||
AbortArticle, RecursiveFetcher, option_parser as web2disk_option_parser,
|
||||
)
|
||||
from calibre.web.fetch.utils import prepare_masthead_image
|
||||
from polyglot.builtins import string_or_bytes
|
||||
@ -717,9 +717,7 @@ class BasicNewsRecipe(Recipe):
|
||||
_raw = self.encoding(_raw)
|
||||
else:
|
||||
_raw = _raw.decode(self.encoding, 'replace')
|
||||
from calibre.ebooks.chardet import (
|
||||
strip_encoding_declarations, xml_to_unicode
|
||||
)
|
||||
from calibre.ebooks.chardet import strip_encoding_declarations, xml_to_unicode
|
||||
from calibre.utils.cleantext import clean_xml_chars
|
||||
if isinstance(_raw, str):
|
||||
_raw = strip_encoding_declarations(_raw)
|
||||
|
@ -5,19 +5,24 @@ __license__ = 'GPL v3'
|
||||
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
import os, calendar, zipfile
|
||||
from threading import RLock
|
||||
import calendar
|
||||
import os
|
||||
import zipfile
|
||||
from datetime import timedelta
|
||||
|
||||
from lxml import etree
|
||||
from lxml.builder import ElementMaker
|
||||
from threading import RLock
|
||||
|
||||
from calibre import force_unicode
|
||||
from calibre.utils.xml_parse import safe_xml_fromstring
|
||||
from calibre.constants import numeric_version
|
||||
from calibre.utils.date import (
|
||||
EPOCH, UNDEFINED_DATE, isoformat, local_tz, now as nowf, utcnow,
|
||||
)
|
||||
from calibre.utils.iso8601 import parse_iso8601
|
||||
from calibre.utils.date import now as nowf, utcnow, local_tz, isoformat, EPOCH, UNDEFINED_DATE
|
||||
from calibre.utils.resources import get_path as P
|
||||
from calibre.utils.localization import _
|
||||
from calibre.utils.recycle_bin import delete_file
|
||||
from calibre.utils.xml_parse import safe_xml_fromstring
|
||||
from polyglot.builtins import iteritems
|
||||
|
||||
NS = 'http://calibre-ebook.com/recipe_collection'
|
||||
@ -106,8 +111,7 @@ def get_builtin_recipe_collection():
|
||||
|
||||
|
||||
def get_custom_recipe_collection(*args):
|
||||
from calibre.web.feeds.recipes import compile_recipe, \
|
||||
custom_recipes
|
||||
from calibre.web.feeds.recipes import compile_recipe, custom_recipes
|
||||
bdir = os.path.dirname(custom_recipes.file_path)
|
||||
rmap = {}
|
||||
for id_, x in iteritems(custom_recipes):
|
||||
@ -132,8 +136,7 @@ def update_custom_recipe(id_, title, script):
|
||||
|
||||
|
||||
def update_custom_recipes(script_ids):
|
||||
from calibre.web.feeds.recipes import custom_recipes, \
|
||||
custom_recipe_filename
|
||||
from calibre.web.feeds.recipes import custom_recipe_filename, custom_recipes
|
||||
|
||||
bdir = os.path.dirname(custom_recipes.file_path)
|
||||
for id_, title, script in script_ids:
|
||||
@ -162,8 +165,7 @@ def add_custom_recipe(title, script):
|
||||
|
||||
|
||||
def add_custom_recipes(script_map):
|
||||
from calibre.web.feeds.recipes import custom_recipes, \
|
||||
custom_recipe_filename
|
||||
from calibre.web.feeds.recipes import custom_recipe_filename, custom_recipes
|
||||
id_ = 1000
|
||||
keys = tuple(map(int, custom_recipes))
|
||||
if keys:
|
||||
@ -217,9 +219,10 @@ def get_builtin_recipe_titles():
|
||||
|
||||
|
||||
def download_builtin_recipe(urn):
|
||||
import bz2
|
||||
|
||||
from calibre.utils.config_base import prefs
|
||||
from calibre.utils.https import get_https_resource_securely
|
||||
import bz2
|
||||
recipe_source = bz2.decompress(get_https_resource_securely(
|
||||
'https://code.calibre-ebook.com/recipe-compressed/'+urn, headers={'CALIBRE-INSTALL-UUID':prefs['installation_uuid']}))
|
||||
recipe_source = recipe_source.decode('utf-8')
|
||||
|
@ -5,19 +5,20 @@ import copy
|
||||
import zipfile
|
||||
from functools import total_ordering
|
||||
from qt.core import (
|
||||
QAbstractItemModel, QApplication, QFont, QIcon, QModelIndex, QPalette, QPixmap,
|
||||
Qt, pyqtSignal
|
||||
QAbstractItemModel, QApplication, QFont, QIcon, QModelIndex, QPalette, QPixmap, Qt,
|
||||
pyqtSignal,
|
||||
)
|
||||
|
||||
from calibre import force_unicode
|
||||
from calibre.utils.icu import primary_sort_key
|
||||
from calibre.utils.localization import get_language
|
||||
from calibre.utils.localization import _, get_language
|
||||
from calibre.utils.resources import get_path as P
|
||||
from calibre.utils.search_query_parser import ParseException, SearchQueryParser
|
||||
from calibre.web.feeds.recipes.collection import (
|
||||
SchedulerConfig, add_custom_recipe, add_custom_recipes, download_builtin_recipe,
|
||||
get_builtin_recipe, get_builtin_recipe_collection, get_custom_recipe,
|
||||
get_custom_recipe_collection, remove_custom_recipe, update_custom_recipe,
|
||||
update_custom_recipes
|
||||
update_custom_recipes,
|
||||
)
|
||||
from polyglot.builtins import iteritems
|
||||
|
||||
|
@ -13,6 +13,7 @@ from lxml.html.builder import HTML, HEAD, TITLE, STYLE, DIV, BODY, \
|
||||
TABLE, TD, TR
|
||||
|
||||
from calibre import strftime, isbytestring
|
||||
from calibre.utils.localization import _
|
||||
|
||||
|
||||
def attrs(*args, **kw):
|
||||
|
@ -26,6 +26,7 @@ from calibre.ebooks.chardet import xml_to_unicode
|
||||
from calibre.utils.config import OptionParser
|
||||
from calibre.utils.filenames import ascii_filename
|
||||
from calibre.utils.imghdr import what
|
||||
from calibre.utils.localization import _
|
||||
from calibre.utils.logging import Log
|
||||
from calibre.web.fetch.utils import rescale_image
|
||||
from polyglot.http_client import responses
|
||||
|
@ -913,6 +913,7 @@ dl.notes dd:last-of-type { page-break-after: avoid }
|
||||
if self.currentnote == 0:
|
||||
return
|
||||
# Changed by Kovid to improve endnote functionality
|
||||
from builtins import _
|
||||
self.opentag('h1', {'class':'notes-header'})
|
||||
self.writeout(_('Notes'))
|
||||
self.closetag('h1')
|
||||
|
Loading…
x
Reference in New Issue
Block a user