mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-04-20 13:11:27 +02:00
Removed overwritten builtins from mosto of the files.
Just started the process of cleaning up the code base.
This commit is contained in:
@@ -5,7 +5,7 @@ __docformat__ = 'restructuredtext en'
|
||||
|
||||
import sys, os, re, time, random, warnings
|
||||
import pkg_resources
|
||||
from ebook_converter.polyglot.builtins import codepoint_to_chr, unicode_type, range, hasenv, native_string_type
|
||||
from ebook_converter.polyglot.builtins import codepoint_to_chr, unicode_type, hasenv, native_string_type
|
||||
from math import floor
|
||||
from functools import partial
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python2
|
||||
# vim:fileencoding=utf-8
|
||||
# License: GPLv3 Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
from ebook_converter.polyglot.builtins import map, unicode_type, environ_item, hasenv, getenv, as_unicode, native_string_type
|
||||
from ebook_converter.polyglot.builtins import unicode_type, environ_item, hasenv, getenv, as_unicode, native_string_type
|
||||
import sys, locale, codecs, os, importlib, collections
|
||||
|
||||
__appname__ = 'calibre'
|
||||
|
||||
@@ -15,7 +15,7 @@ import operator
|
||||
import string
|
||||
|
||||
from ebook_converter.css_selectors.errors import SelectorSyntaxError, ExpressionError
|
||||
from ebook_converter.polyglot.builtins import unicode_type, codepoint_to_chr, range
|
||||
from ebook_converter.polyglot.builtins import unicode_type, codepoint_to_chr
|
||||
|
||||
|
||||
utab = {c:c+32 for c in range(ord(u'A'), ord(u'Z')+1)}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from ebook_converter.customize import Plugin as _Plugin
|
||||
from ebook_converter.polyglot.builtins import zip
|
||||
|
||||
|
||||
__license__ = 'GPL 3'
|
||||
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
|
||||
@@ -11,7 +11,7 @@ from ebook_converter import as_unicode
|
||||
from ebook_converter.constants import ispy3
|
||||
from ebook_converter.customize import (Plugin, numeric_version, platform,
|
||||
InvalidPlugin, PluginNotFound)
|
||||
from ebook_converter.polyglot.builtins import (itervalues, map, string_or_bytes,
|
||||
from ebook_converter.polyglot.builtins import (itervalues, string_or_bytes,
|
||||
unicode_type, reload)
|
||||
|
||||
|
||||
|
||||
@@ -1,24 +1,20 @@
|
||||
# License: GPLv3 Copyright: 2019, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
import bs4
|
||||
from bs4 import ( # noqa
|
||||
CData, Comment, Declaration, NavigableString, ProcessingInstruction,
|
||||
SoupStrainer, Tag, __version__
|
||||
)
|
||||
from html5_parser import soup as html5_soup
|
||||
|
||||
from ebook_converter.polyglot.builtins import unicode_type
|
||||
from ebook_converter.ebooks import chardet
|
||||
from ebook_converter.utils import cleantext
|
||||
|
||||
|
||||
def parse_html(markup):
|
||||
from ebook_converter.ebooks.chardet import strip_encoding_declarations, xml_to_unicode, substitute_entites
|
||||
from ebook_converter.utils.cleantext import clean_xml_chars
|
||||
if isinstance(markup, unicode_type):
|
||||
markup = strip_encoding_declarations(markup)
|
||||
markup = substitute_entites(markup)
|
||||
if isinstance(markup, str):
|
||||
markup = chardet.strip_encoding_declarations(markup)
|
||||
markup = chardet.substitute_entites(markup)
|
||||
else:
|
||||
markup = xml_to_unicode(markup, strip_encoding_pats=True, resolve_entities=True)[0]
|
||||
markup = clean_xml_chars(markup)
|
||||
from html5_parser.soup import parse
|
||||
return parse(markup, return_root=False)
|
||||
markup = chardet.xml_to_unicode(markup, strip_encoding_pats=True,
|
||||
resolve_entities=True)[0]
|
||||
markup = cleantext.clean_xml_chars(markup)
|
||||
return html5_soup.parse(markup, return_root=False)
|
||||
|
||||
|
||||
def prettify(soup):
|
||||
@@ -28,9 +24,9 @@ def prettify(soup):
|
||||
return ans
|
||||
|
||||
|
||||
def BeautifulSoup(markup='', *a, **kw):
|
||||
def html5_parser(markup='', *a, **kw):
|
||||
return parse_html(markup)
|
||||
|
||||
|
||||
def BeautifulStoneSoup(markup='', *a, **kw):
|
||||
def beautiful_soup_parser(markup='', *a, **kw):
|
||||
return bs4.BeautifulSoup(markup, 'xml')
|
||||
|
||||
@@ -2,7 +2,6 @@ import io
|
||||
from struct import pack
|
||||
|
||||
from ebook_converter.ebooks.compression import cPalmdoc
|
||||
from ebook_converter.polyglot.builtins import range
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -6,7 +6,7 @@ import shutil, textwrap, codecs, os
|
||||
from ebook_converter.customize.conversion import InputFormatPlugin, OptionRecommendation
|
||||
from ebook_converter import CurrentDir
|
||||
from ebook_converter.ptempfile import PersistentTemporaryDirectory
|
||||
from ebook_converter.polyglot.builtins import getcwd, map
|
||||
from ebook_converter.polyglot.builtins import getcwd
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -4,7 +4,7 @@ from ebook_converter.customize.conversion import (OutputFormatPlugin,
|
||||
OptionRecommendation)
|
||||
from ebook_converter.ptempfile import TemporaryDirectory
|
||||
from ebook_converter import CurrentDir
|
||||
from ebook_converter.polyglot.builtins import unicode_type, filter, map, zip, range, as_bytes
|
||||
from ebook_converter.polyglot.builtins import unicode_type, as_bytes
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -7,7 +7,7 @@ from ebook_converter.customize.conversion import (InputFormatPlugin,
|
||||
from ebook_converter.utils.localization import get_lang
|
||||
from ebook_converter.utils.filenames import ascii_filename
|
||||
from ebook_converter.utils.imghdr import what
|
||||
from ebook_converter.polyglot.builtins import unicode_type, zip, getcwd, as_unicode
|
||||
from ebook_converter.polyglot.builtins import unicode_type, getcwd, as_unicode
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -2,7 +2,7 @@ import os, glob, re, textwrap
|
||||
import pkg_resources
|
||||
|
||||
from ebook_converter.customize.conversion import InputFormatPlugin, OptionRecommendation
|
||||
from ebook_converter.polyglot.builtins import iteritems, filter, getcwd, as_bytes
|
||||
from ebook_converter.polyglot.builtins import iteritems, getcwd, as_bytes
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
@@ -13,7 +13,7 @@ from ebook_converter.utils.zipfile import ZipFile
|
||||
from ebook_converter import (extract, walk, isbytestring, filesystem_encoding,
|
||||
get_types_map)
|
||||
from ebook_converter.constants import __version__
|
||||
from ebook_converter.polyglot.builtins import unicode_type, string_or_bytes, map
|
||||
from ebook_converter.polyglot.builtins import unicode_type, string_or_bytes
|
||||
|
||||
|
||||
__license__ = 'GPL 3'
|
||||
|
||||
@@ -2,7 +2,7 @@ import functools, re, json
|
||||
from math import ceil
|
||||
|
||||
from ebook_converter import entity_to_unicode, as_unicode
|
||||
from ebook_converter.polyglot.builtins import unicode_type, range
|
||||
from ebook_converter.polyglot.builtins import unicode_type
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -2,7 +2,7 @@ import re, random, unicodedata, numbers
|
||||
from collections import namedtuple
|
||||
from contextlib import contextmanager
|
||||
from math import ceil, sqrt, cos, sin, atan2
|
||||
from ebook_converter.polyglot.builtins import iteritems, itervalues, map, zip, string_or_bytes
|
||||
from ebook_converter.polyglot.builtins import iteritems, itervalues, string_or_bytes
|
||||
from itertools import chain
|
||||
|
||||
from PyQt5.Qt import (
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import os
|
||||
from ebook_converter.polyglot.builtins import itervalues, range
|
||||
from ebook_converter.polyglot.builtins import itervalues
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -6,7 +6,7 @@ from ebook_converter.utils.filenames import ascii_filename
|
||||
from ebook_converter.utils.fonts.scanner import font_scanner, NoFonts
|
||||
from ebook_converter.utils.fonts.utils import panose_to_css_generic_family, is_truetype_font
|
||||
from ebook_converter.utils.icu import ord_string
|
||||
from ebook_converter.polyglot.builtins import codepoint_to_chr, iteritems, range
|
||||
from ebook_converter.polyglot.builtins import codepoint_to_chr, iteritems
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -3,7 +3,7 @@ from operator import itemgetter
|
||||
from lxml import etree
|
||||
|
||||
from ebook_converter.utils.icu import partition_by_first_letter, sort_key
|
||||
from ebook_converter.polyglot.builtins import iteritems, filter
|
||||
from ebook_converter.polyglot.builtins import iteritems
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -2,7 +2,7 @@ from lxml.html.builder import TABLE, TR, TD
|
||||
|
||||
from ebook_converter.ebooks.docx.block_styles import inherit, read_shd as rs, read_border, binary_property, border_props, ParagraphStyle, border_to_css
|
||||
from ebook_converter.ebooks.docx.char_styles import RunStyle
|
||||
from ebook_converter.polyglot.builtins import filter, iteritems, itervalues, range, unicode_type
|
||||
from ebook_converter.polyglot.builtins import iteritems, itervalues, unicode_type
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -21,7 +21,7 @@ from ebook_converter.ebooks.docx.fields import Fields
|
||||
from ebook_converter.ebooks.docx.settings import Settings
|
||||
from ebook_converter.ebooks.metadata.opf2 import OPFCreator
|
||||
from ebook_converter.utils.localization import canonicalize_lang, lang_as_iso639_1
|
||||
from ebook_converter.polyglot.builtins import iteritems, itervalues, filter, getcwd, map, unicode_type
|
||||
from ebook_converter.polyglot.builtins import iteritems, itervalues, getcwd, unicode_type
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -5,7 +5,7 @@ from lxml.etree import tostring
|
||||
|
||||
from ebook_converter.ebooks.metadata.toc import TOC
|
||||
from ebook_converter.ebooks.oeb.polish.toc import elem_to_toc_text
|
||||
from ebook_converter.polyglot.builtins import iteritems, range
|
||||
from ebook_converter.polyglot.builtins import iteritems
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -11,7 +11,7 @@ from ebook_converter.ebooks.pdf.render.common import PAPER_SIZES
|
||||
from ebook_converter.utils.date import utcnow
|
||||
from ebook_converter.utils.localization import canonicalize_lang, lang_as_iso639_1
|
||||
from ebook_converter.utils.zipfile import ZipFile
|
||||
from ebook_converter.polyglot.builtins import iteritems, map, unicode_type, native_string_type
|
||||
from ebook_converter.polyglot.builtins import iteritems, unicode_type, native_string_type
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -3,7 +3,6 @@ from uuid import uuid4
|
||||
|
||||
from ebook_converter.ebooks.oeb.base import OEB_STYLES
|
||||
from ebook_converter.ebooks.oeb.transforms.subset import find_font_face_rules
|
||||
from ebook_converter.polyglot.builtins import range
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -2,7 +2,7 @@ import os
|
||||
import posixpath
|
||||
from collections import namedtuple
|
||||
from functools import partial
|
||||
from ebook_converter.polyglot.builtins import iteritems, itervalues, map, unicode_type
|
||||
from ebook_converter.polyglot.builtins import iteritems, itervalues, unicode_type
|
||||
|
||||
from lxml import etree
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ from lxml import etree
|
||||
from ebook_converter.ebooks import parse_css_length
|
||||
from ebook_converter.ebooks.docx.writer.utils import convert_color, int_or_zero
|
||||
from ebook_converter.utils.localization import lang_as_iso639_1
|
||||
from ebook_converter.polyglot.builtins import iteritems, filter, unicode_type
|
||||
from ebook_converter.polyglot.builtins import iteritems, unicode_type
|
||||
from ebook_converter.tinycss.css21 import CSS21Parser
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ from collections import namedtuple
|
||||
|
||||
from ebook_converter.ebooks.docx.writer.utils import convert_color
|
||||
from ebook_converter.ebooks.docx.writer.styles import read_css_block_borders as rcbb, border_edges
|
||||
from ebook_converter.polyglot.builtins import iteritems, range, unicode_type
|
||||
from ebook_converter.polyglot.builtins import iteritems, unicode_type
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -12,7 +12,7 @@ from ebook_converter.utils.localization import lang_as_iso639_1
|
||||
from ebook_converter.utils.xml_parse import safe_xml_fromstring
|
||||
from ebook_converter.utils.img import save_cover_data_to
|
||||
from ebook_converter.ebooks.oeb.base import urlnormalize
|
||||
from ebook_converter.polyglot.builtins import unicode_type, string_or_bytes, range, filter
|
||||
from ebook_converter.polyglot.builtins import unicode_type, string_or_bytes
|
||||
from ebook_converter.polyglot.binary import as_base64_unicode
|
||||
from ebook_converter.polyglot.urllib import urlparse
|
||||
|
||||
|
||||
@@ -17,15 +17,15 @@ from functools import partial
|
||||
from itertools import chain
|
||||
from math import ceil, floor
|
||||
|
||||
import bs4
|
||||
|
||||
from ebook_converter import (
|
||||
__appname__, entity_to_unicode, fit_image, force_unicode, preferred_encoding
|
||||
)
|
||||
from ebook_converter.constants import filesystem_encoding
|
||||
from ebook_converter.devices.interface import DevicePlugin as Device
|
||||
from ebook_converter.ebooks import ConversionError
|
||||
from ebook_converter.ebooks.BeautifulSoup import (
|
||||
BeautifulSoup, Comment, Declaration, NavigableString, ProcessingInstruction, Tag
|
||||
)
|
||||
from ebook_converter.ebooks.BeautifulSoup import html5_parser
|
||||
from ebook_converter.ebooks.chardet import xml_to_unicode
|
||||
from ebook_converter.ebooks.lrf import Book
|
||||
from ebook_converter.ebooks.lrf.html.color_map import lrs_color
|
||||
@@ -86,7 +86,7 @@ def tag_regex(tagname):
|
||||
class HTMLConverter(object):
|
||||
SELECTOR_PAT = re.compile(r"([A-Za-z0-9\-\_\:\.]+[A-Za-z0-9\-\_\:\.\s\,]*)\s*\{([^\}]*)\}")
|
||||
PAGE_BREAK_PAT = re.compile(r'page-break-(?:after|before)\s*:\s*(\w+)', re.IGNORECASE)
|
||||
IGNORED_TAGS = (Comment, Declaration, ProcessingInstruction)
|
||||
IGNORED_TAGS = (bs4.Comment, bs4.Declaration, bs4.ProcessingInstruction)
|
||||
|
||||
MARKUP_MASSAGE = [
|
||||
# Close <a /> tags
|
||||
@@ -337,7 +337,7 @@ class HTMLConverter(object):
|
||||
raw = xml_to_unicode(raw, replace_entities=True)[0]
|
||||
for pat, repl in nmassage:
|
||||
raw = pat.sub(repl, raw)
|
||||
soup = BeautifulSoup(raw)
|
||||
soup = html5_parser(raw)
|
||||
if not self.baen and self.is_baen(soup):
|
||||
self.baen = True
|
||||
self.log.info(_('\tBaen file detected. Re-parsing...'))
|
||||
@@ -585,9 +585,9 @@ class HTMLConverter(object):
|
||||
break
|
||||
if isinstance(c, HTMLConverter.IGNORED_TAGS):
|
||||
continue
|
||||
if isinstance(c, NavigableString):
|
||||
if isinstance(c, bs4.NavigableString):
|
||||
text += unicode_type(c)
|
||||
elif isinstance(c, Tag):
|
||||
elif isinstance(c, bs4.Tag):
|
||||
if c.name.lower() == 'img' and c.has_attr('alt'):
|
||||
alt_text += c['alt']
|
||||
continue
|
||||
@@ -720,9 +720,9 @@ class HTMLConverter(object):
|
||||
for c in copy.copy(ptag.contents):
|
||||
if isinstance(c, HTMLConverter.IGNORED_TAGS):
|
||||
continue
|
||||
elif isinstance(c, Tag):
|
||||
elif isinstance(c, bs4.Tag):
|
||||
self.parse_tag(c, pcss)
|
||||
elif isinstance(c, NavigableString):
|
||||
elif isinstance(c, bs4.NavigableString):
|
||||
self.add_text(c, pcss, ppcss)
|
||||
if not self.in_table:
|
||||
try:
|
||||
@@ -1551,11 +1551,11 @@ class HTMLConverter(object):
|
||||
|
||||
if tag.contents:
|
||||
c = tag.contents[0]
|
||||
if isinstance(c, NavigableString):
|
||||
if isinstance(c, bs4.NavigableString):
|
||||
c = unicode_type(c).replace('\r\n', '\n').replace('\r', '\n')
|
||||
if c.startswith('\n'):
|
||||
c = c[1:]
|
||||
tag.contents[0] = NavigableString(c)
|
||||
tag.contents[0] = bs4.NavigableString(c)
|
||||
tag.contents[0].setup(tag)
|
||||
self.process_children(tag, tag_css, tag_pseudo_css)
|
||||
self.end_current_block()
|
||||
@@ -1823,7 +1823,7 @@ def process_file(path, options, logger):
|
||||
for prop in ('author', 'author_sort', 'title', 'title_sort', 'publisher', 'freetext'):
|
||||
val = getattr(options, prop, None)
|
||||
if val and not isinstance(val, unicode_type):
|
||||
soup = BeautifulSoup(val)
|
||||
soup = html5_parser(val)
|
||||
setattr(options, prop, unicode_type(soup))
|
||||
|
||||
title = (options.title, options.title_sort)
|
||||
|
||||
@@ -4,7 +4,7 @@ from ebook_converter.ebooks.lrf.fonts import get_font
|
||||
from ebook_converter.ebooks.lrf.pylrs.pylrs import TextBlock, Text, CR, Span, \
|
||||
CharButton, Plot, Paragraph, \
|
||||
LrsTextTag
|
||||
from ebook_converter.polyglot.builtins import string_or_bytes, range, native_string_type
|
||||
from ebook_converter.polyglot.builtins import string_or_bytes, native_string_type
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -6,7 +6,7 @@ import os, sys, re
|
||||
|
||||
from ebook_converter import relpath, guess_type, prints, force_unicode
|
||||
from ebook_converter.utils.config_base import tweaks
|
||||
from ebook_converter.polyglot.builtins import codepoint_to_chr, unicode_type, range, map, zip, getcwd, iteritems, itervalues, as_unicode
|
||||
from ebook_converter.polyglot.builtins import codepoint_to_chr, unicode_type, getcwd, iteritems, itervalues, as_unicode
|
||||
from ebook_converter.polyglot.urllib import quote, unquote, urlparse
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ from contextlib import closing
|
||||
|
||||
from ebook_converter.customize import FileTypePlugin
|
||||
from ebook_converter.utils.localization import canonicalize_lang
|
||||
from ebook_converter.polyglot.builtins import filter, unicode_type
|
||||
from ebook_converter.polyglot.builtins import unicode_type
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -7,7 +7,7 @@ from ebook_converter.ebooks.metadata.book import (SC_COPYABLE_FIELDS,
|
||||
TOP_LEVEL_IDENTIFIERS, ALL_METADATA_FIELDS)
|
||||
from ebook_converter.library.field_metadata import FieldMetadata
|
||||
from ebook_converter.utils.icu import sort_key
|
||||
from ebook_converter.polyglot.builtins import iteritems, unicode_type, filter, map
|
||||
from ebook_converter.polyglot.builtins import iteritems, unicode_type
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -17,7 +17,7 @@ from ebook_converter import prints, guess_type
|
||||
from ebook_converter.utils.cleantext import clean_ascii_chars, clean_xml_chars
|
||||
from ebook_converter.utils.config import tweaks
|
||||
from ebook_converter.utils.xml_parse import safe_xml_fromstring
|
||||
from ebook_converter.polyglot.builtins import iteritems, unicode_type, getcwd, map
|
||||
from ebook_converter.polyglot.builtins import iteritems, unicode_type, getcwd
|
||||
from ebook_converter.polyglot.urllib import unquote, urlparse
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import json
|
||||
import re
|
||||
from collections import defaultdict, namedtuple
|
||||
from functools import wraps
|
||||
from ebook_converter.polyglot.builtins import iteritems, map, filter
|
||||
from ebook_converter.polyglot.builtins import iteritems
|
||||
|
||||
from lxml import etree
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import re
|
||||
|
||||
from ebook_converter import force_unicode
|
||||
from ebook_converter.ebooks.metadata import MetaInformation
|
||||
from ebook_converter.polyglot.builtins import codepoint_to_chr, string_or_bytes, unicode_type, int_to_byte, filter
|
||||
from ebook_converter.polyglot.builtins import codepoint_to_chr, string_or_bytes, unicode_type, int_to_byte
|
||||
|
||||
title_pat = re.compile(br'\{\\info.*?\{\\title(.*?)(?<!\\)\}', re.DOTALL)
|
||||
author_pat = re.compile(br'\{\\info.*?\{\\author(.*?)(?<!\\)\}', re.DOTALL)
|
||||
|
||||
@@ -7,7 +7,6 @@ from ebook_converter.spell import parse_lang_code
|
||||
from ebook_converter.utils.cleantext import clean_xml_chars
|
||||
from ebook_converter.utils.localization import lang_as_iso639_1
|
||||
from ebook_converter.utils.xml_parse import safe_xml_fromstring
|
||||
from ebook_converter.polyglot.builtins import filter, map
|
||||
|
||||
|
||||
OPFVersion = namedtuple('OPFVersion', 'major minor patch')
|
||||
|
||||
@@ -12,7 +12,7 @@ from ebook_converter.ebooks.metadata.book.base import Metadata
|
||||
from ebook_converter.ebooks.metadata.opf2 import dump_dict
|
||||
from ebook_converter.utils.date import parse_date, isoformat, now
|
||||
from ebook_converter.utils.localization import canonicalize_lang, lang_as_iso639_1
|
||||
from ebook_converter.polyglot.builtins import iteritems, string_or_bytes, filter
|
||||
from ebook_converter.polyglot.builtins import iteritems, string_or_bytes
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -5,7 +5,6 @@ darkninja and igorsk.
|
||||
import struct
|
||||
|
||||
from ebook_converter.ebooks.mobi import MobiError
|
||||
from ebook_converter.polyglot.builtins import map
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -3,7 +3,7 @@ from collections import OrderedDict, namedtuple
|
||||
|
||||
from ebook_converter.ebooks.mobi.utils import (decint, count_set_bits,
|
||||
decode_string)
|
||||
from ebook_converter.polyglot.builtins import iteritems, range, zip
|
||||
from ebook_converter.polyglot.builtins import iteritems
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import re, os
|
||||
|
||||
from ebook_converter.ebooks.chardet import strip_encoding_declarations
|
||||
from ebook_converter.polyglot.builtins import unicode_type, range
|
||||
from ebook_converter.polyglot.builtins import unicode_type
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -16,7 +16,7 @@ from ebook_converter.ebooks.metadata.toc import TOC
|
||||
from ebook_converter.ebooks.mobi.reader.headers import BookHeader
|
||||
from ebook_converter.utils.img import save_cover_data_to, gif_data_to_png_data, AnimatedGIF
|
||||
from ebook_converter.utils.imghdr import what
|
||||
from ebook_converter.polyglot.builtins import iteritems, unicode_type, range, map
|
||||
from ebook_converter.polyglot.builtins import iteritems, unicode_type
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -15,7 +15,7 @@ from ebook_converter.ebooks.metadata.toc import TOC
|
||||
from ebook_converter.ebooks.mobi.utils import read_font_record
|
||||
from ebook_converter.ebooks.oeb.parse_utils import parse_html
|
||||
from ebook_converter.ebooks.oeb.base import XPath, XHTML, xml2text
|
||||
from ebook_converter.polyglot.builtins import range, zip, unicode_type, getcwd, as_unicode
|
||||
from ebook_converter.polyglot.builtins import unicode_type, getcwd, as_unicode
|
||||
from ebook_converter.polyglot.urllib import urldefrag
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ from io import BytesIO
|
||||
from ebook_converter.utils.img import save_cover_data_to, scale_image, image_to_data, image_from_data, resize_image, png_data_to_gif_data
|
||||
from ebook_converter.utils.imghdr import what
|
||||
from ebook_converter.ebooks import normalize
|
||||
from ebook_converter.polyglot.builtins import unicode_type, range, as_bytes, map
|
||||
from ebook_converter.polyglot.builtins import unicode_type, as_bytes
|
||||
from ebook_converter.tinycss.color3 import parse_color_string
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ from collections import OrderedDict, defaultdict
|
||||
|
||||
from ebook_converter.ebooks.mobi.utils import (encint, encode_number_as_hex,
|
||||
encode_tbs, align_block, RECORD_SIZE, CNCX as CNCX_)
|
||||
from ebook_converter.polyglot.builtins import filter, iteritems, itervalues, map, range
|
||||
from ebook_converter.polyglot.builtins import iteritems, itervalues
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -10,7 +10,7 @@ from ebook_converter.ebooks.mobi.writer2 import (PALMDOC, UNCOMPRESSED)
|
||||
from ebook_converter.ebooks.mobi.utils import (encint, encode_trailing_data,
|
||||
align_block, detect_periodical, RECORD_SIZE, create_text_record)
|
||||
from ebook_converter.ebooks.mobi.writer2.indexer import Indexer
|
||||
from ebook_converter.polyglot.builtins import iteritems, unicode_type, range
|
||||
from ebook_converter.polyglot.builtins import iteritems, unicode_type
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -15,7 +15,7 @@ from odf.namespaces import TEXTNS as odTEXTNS
|
||||
from ebook_converter import CurrentDir, walk
|
||||
from ebook_converter.ebooks.oeb.base import _css_logger
|
||||
from ebook_converter.utils.xml_parse import safe_xml_fromstring
|
||||
from ebook_converter.polyglot.builtins import unicode_type, string_or_bytes, filter, getcwd, as_bytes
|
||||
from ebook_converter.polyglot.builtins import unicode_type, string_or_bytes, getcwd, as_bytes
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -16,7 +16,7 @@ from ebook_converter import (isbytestring, as_unicode, get_types_map)
|
||||
from ebook_converter.ebooks.oeb.parse_utils import barename, XHTML_NS, namespace, XHTML, parse_html, NotHTML
|
||||
from ebook_converter.utils.cleantext import clean_xml_chars
|
||||
from ebook_converter.utils.short_uuid import uuid4
|
||||
from ebook_converter.polyglot.builtins import iteritems, unicode_type, string_or_bytes, range, itervalues, filter, codepoint_to_chr
|
||||
from ebook_converter.polyglot.builtins import iteritems, unicode_type, string_or_bytes, itervalues, codepoint_to_chr
|
||||
from ebook_converter.polyglot.urllib import unquote as urlunquote, urldefrag, urljoin, urlparse, urlunparse
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ from css_parser.css import PropertyValue
|
||||
from css_parser import profile as cssprofiles, CSSParser
|
||||
from ebook_converter.tinycss.fonts3 import parse_font, serialize_font_family
|
||||
from ebook_converter.ebooks.oeb.base import css_text
|
||||
from ebook_converter.polyglot.builtins import iteritems, string_or_bytes, unicode_type, zip
|
||||
from ebook_converter.polyglot.builtins import iteritems, string_or_bytes, unicode_type
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -6,7 +6,7 @@ from ebook_converter import xml_replace_entities, force_unicode
|
||||
from ebook_converter.utils.xml_parse import safe_xml_fromstring
|
||||
from ebook_converter.constants import filesystem_encoding
|
||||
from ebook_converter.ebooks.chardet import xml_to_unicode, strip_encoding_declarations
|
||||
from ebook_converter.polyglot.builtins import iteritems, itervalues, unicode_type, string_or_bytes, map
|
||||
from ebook_converter.polyglot.builtins import iteritems, itervalues, unicode_type, string_or_bytes
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -48,7 +48,7 @@ from ebook_converter.utils.ipc.simple_worker import WorkerError, fork_job
|
||||
from ebook_converter.utils.logging import default_log
|
||||
from ebook_converter.utils.xml_parse import safe_xml_fromstring
|
||||
from ebook_converter.utils.zipfile import ZipFile
|
||||
from ebook_converter.polyglot.builtins import iteritems, map, unicode_type, zip
|
||||
from ebook_converter.polyglot.builtins import iteritems, unicode_type
|
||||
from ebook_converter.polyglot.urllib import urlparse
|
||||
|
||||
exists, join, relpath = os.path.exists, os.path.join, os.path.relpath
|
||||
|
||||
@@ -10,7 +10,7 @@ from ebook_converter.ebooks.oeb.normalize_css import normalize_filter_css, norma
|
||||
from ebook_converter.ebooks.oeb.polish.pretty import pretty_script_or_style, pretty_xml_tree, serialize
|
||||
from ebook_converter.utils.icu import numeric_sort_key
|
||||
from ebook_converter.css_selectors import Select, SelectorError
|
||||
from ebook_converter.polyglot.builtins import iteritems, itervalues, unicode_type, filter
|
||||
from ebook_converter.polyglot.builtins import iteritems, itervalues, unicode_type
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import textwrap
|
||||
from ebook_converter.polyglot.builtins import iteritems, map
|
||||
from ebook_converter.polyglot.builtins import iteritems
|
||||
|
||||
# from lxml.etree import Element
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import codecs, shutil, os, posixpath
|
||||
from ebook_converter.polyglot.builtins import iteritems, itervalues, map
|
||||
from ebook_converter.polyglot.builtins import iteritems, itervalues
|
||||
from functools import partial
|
||||
from collections import Counter, defaultdict
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import copy, os, re
|
||||
from ebook_converter.polyglot.builtins import map, string_or_bytes, range
|
||||
from ebook_converter.polyglot.builtins import string_or_bytes
|
||||
|
||||
from ebook_converter.ebooks.oeb.base import barename, XPNSMAP, XPath, OPF, XHTML, OEB_DOCS
|
||||
from ebook_converter.ebooks.oeb.polish.errors import MalformedMarkup
|
||||
|
||||
@@ -15,7 +15,7 @@ from ebook_converter.ebooks.oeb.polish.utils import guess_type, extract
|
||||
from ebook_converter.ebooks.oeb.polish.opf import set_guide_item, get_book_language
|
||||
from ebook_converter.ebooks.oeb.polish.pretty import pretty_html_tree
|
||||
from ebook_converter.utils.localization import get_lang, canonicalize_lang, lang_as_iso639_1
|
||||
from ebook_converter.polyglot.builtins import iteritems, map, unicode_type
|
||||
from ebook_converter.polyglot.builtins import iteritems, unicode_type
|
||||
from ebook_converter.polyglot.urllib import urlparse
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ import re, os
|
||||
from bisect import bisect
|
||||
|
||||
from ebook_converter import guess_type as _guess_type, replace_entities
|
||||
from ebook_converter.polyglot.builtins import filter
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -22,7 +22,7 @@ from ebook_converter.utils.localization import get_lang
|
||||
from ebook_converter.ptempfile import TemporaryDirectory
|
||||
from ebook_converter.constants import __appname__, __version__
|
||||
from ebook_converter import guess_type, xml_replace_entities
|
||||
from ebook_converter.polyglot.builtins import unicode_type, zip
|
||||
from ebook_converter.polyglot.builtins import unicode_type
|
||||
from ebook_converter.polyglot.urllib import unquote, urldefrag, urlparse
|
||||
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ from ebook_converter.ebooks import unit_convert
|
||||
from ebook_converter.ebooks.oeb.base import XHTML, XHTML_NS, CSS_MIME, OEB_STYLES, xpath, urlnormalize
|
||||
from ebook_converter.ebooks.oeb.normalize_css import DEFAULTS, normalizers
|
||||
from ebook_converter.css_selectors import Select, SelectorError, INAPPROPRIATE_PSEUDO_CLASSES
|
||||
from ebook_converter.polyglot.builtins import iteritems, unicode_type, filter
|
||||
from ebook_converter.polyglot.builtins import iteritems, unicode_type
|
||||
from ebook_converter.tinycss.media3 import CSSMedia3Parser
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ from ebook_converter.ebooks.oeb.base import (XHTML, XHTML_NS, CSS_MIME, OEB_STYL
|
||||
from ebook_converter.ebooks.oeb.stylizer import Stylizer
|
||||
from ebook_converter.utils.filenames import ascii_filename, ascii_text
|
||||
from ebook_converter.utils.icu import numeric_sort_key
|
||||
from ebook_converter.polyglot.builtins import iteritems, unicode_type, string_or_bytes, map
|
||||
from ebook_converter.polyglot.builtins import iteritems, unicode_type, string_or_bytes
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -10,7 +10,7 @@ from ebook_converter.library.comments import comments_to_html, markdown
|
||||
from ebook_converter.utils.date import is_date_undefined, as_local_time
|
||||
from ebook_converter.ebooks.chardet import strip_encoding_declarations
|
||||
from ebook_converter.ebooks.metadata import fmt_sidx, rating_to_stars
|
||||
from ebook_converter.polyglot.builtins import unicode_type, map
|
||||
from ebook_converter.polyglot.builtins import unicode_type
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -14,7 +14,7 @@ from ebook_converter.ebooks.epub import rules
|
||||
from ebook_converter.ebooks.oeb.base import (OEB_STYLES, XPNSMAP as NAMESPACES,
|
||||
urldefrag, rewrite_links, XHTML, urlnormalize)
|
||||
from ebook_converter.ebooks.oeb.polish.split import do_split
|
||||
from ebook_converter.polyglot.builtins import iteritems, range, map, unicode_type
|
||||
from ebook_converter.polyglot.builtins import iteritems, unicode_type
|
||||
from ebook_converter.polyglot.urllib import unquote
|
||||
from ebook_converter.css_selectors import Select, SelectorError
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ from collections import defaultdict
|
||||
|
||||
from ebook_converter.ebooks.oeb.base import urlnormalize, css_text
|
||||
from ebook_converter.utils.fonts.sfnt.subset import subset, NoGlyphs, UnsupportedFont
|
||||
from ebook_converter.polyglot.builtins import iteritems, itervalues, unicode_type, range
|
||||
from ebook_converter.polyglot.builtins import iteritems, itervalues, unicode_type
|
||||
from ebook_converter.tinycss.fonts3 import parse_font_family
|
||||
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ from ebook_converter.ebooks import DRMError
|
||||
from ebook_converter.ebooks.metadata.opf2 import OPFCreator
|
||||
from ebook_converter.ebooks.pdb.ereader import EreaderError
|
||||
from ebook_converter.ebooks.pdb.formatreader import FormatReader
|
||||
from ebook_converter.polyglot.builtins import unicode_type, range
|
||||
from ebook_converter.polyglot.builtins import unicode_type
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -9,7 +9,7 @@ from ebook_converter import CurrentDir
|
||||
from ebook_converter.ebooks.metadata.opf2 import OPFCreator
|
||||
from ebook_converter.ebooks.pdb.formatreader import FormatReader
|
||||
from ebook_converter.ebooks.pdb.ereader import EreaderError
|
||||
from ebook_converter.polyglot.builtins import unicode_type, range
|
||||
from ebook_converter.polyglot.builtins import unicode_type
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -8,7 +8,6 @@ from ebook_converter import prepare_string_for_xml
|
||||
from ebook_converter.ebooks.pdb.formatreader import FormatReader
|
||||
from ebook_converter.ebooks.metadata import MetaInformation
|
||||
from ebook_converter.ebooks.txt.processor import opf_writer, HTML_TEMPLATE
|
||||
from ebook_converter.polyglot.builtins import range, map
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -3,7 +3,6 @@ Read content from palmdoc pdb file.
|
||||
"""
|
||||
from ebook_converter.ebooks.pdb.formatreader import FormatReader
|
||||
from ebook_converter.ptempfile import PersistentTemporaryFile
|
||||
from ebook_converter.polyglot.builtins import range
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -9,7 +9,7 @@ from ebook_converter.ebooks.pdb.formatreader import FormatReader
|
||||
from ebook_converter.ebooks.compression.palmdoc import decompress_doc
|
||||
from ebook_converter.utils.imghdr import identify
|
||||
from ebook_converter.utils.img import save_cover_data_to, Canvas, image_from_data
|
||||
from ebook_converter.polyglot.builtins import codepoint_to_chr, range
|
||||
from ebook_converter.polyglot.builtins import codepoint_to_chr
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -15,7 +15,7 @@ import os, re
|
||||
from ebook_converter.ebooks.rtf2xml import copy
|
||||
from ebook_converter.utils.mreplace import MReplace
|
||||
from ebook_converter.ptempfile import better_mktemp
|
||||
from ebook_converter.polyglot.builtins import codepoint_to_chr, range, filter, map
|
||||
from ebook_converter.polyglot.builtins import codepoint_to_chr
|
||||
from . import open_for_read, open_for_write
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ from ebook_converter.ebooks.metadata.opf2 import OPFCreator
|
||||
|
||||
from ebook_converter.ebooks.conversion.preprocess import DocAnalysis
|
||||
from ebook_converter.utils.cleantext import clean_ascii_chars
|
||||
from ebook_converter.polyglot.builtins import iteritems, unicode_type, map, range, long_type
|
||||
from ebook_converter.polyglot.builtins import iteritems, unicode_type, long_type
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -3,8 +3,6 @@ Code to manage ebook library
|
||||
"""
|
||||
import os
|
||||
|
||||
from ebook_converter.polyglot.builtins import range
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
@@ -6,7 +6,7 @@ from ebook_converter.customize import CatalogPlugin
|
||||
from ebook_converter.library.catalogs import FIELDS, TEMPLATE_ALLOWED_FIELDS
|
||||
from ebook_converter.customize.conversion import DummyReporter
|
||||
from ebook_converter.ebooks.metadata import format_isbn
|
||||
from ebook_converter.polyglot.builtins import filter, string_or_bytes, unicode_type
|
||||
from ebook_converter.polyglot.builtins import string_or_bytes, unicode_type
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import re
|
||||
|
||||
import bs4
|
||||
|
||||
from ebook_converter import prepare_string_for_xml
|
||||
from ebook_converter.constants import preferred_encoding
|
||||
from ebook_converter.ebooks.BeautifulSoup import (
|
||||
BeautifulSoup, CData, Comment, Declaration, NavigableString,
|
||||
ProcessingInstruction
|
||||
)
|
||||
from ebook_converter.ebooks.BeautifulSoup import html5_parser
|
||||
from ebook_converter.utils.html2text import html2text
|
||||
from ebook_converter.polyglot.builtins import unicode_type
|
||||
|
||||
@@ -83,8 +82,8 @@ def comments_to_html(comments):
|
||||
# Convert two hyphens to emdash
|
||||
comments = comments.replace('--', '—')
|
||||
|
||||
soup = BeautifulSoup('<div>' + comments + '</div>').find('div')
|
||||
result = BeautifulSoup('<div>')
|
||||
soup = html5_parser('<div>' + comments + '</div>').find('div')
|
||||
result = html5_parser('<div>')
|
||||
container = result.find('div')
|
||||
rtc = 0
|
||||
open_pTag = False
|
||||
@@ -92,9 +91,10 @@ def comments_to_html(comments):
|
||||
all_tokens = list(soup.contents)
|
||||
inline_tags = ('br', 'b', 'i', 'em', 'strong', 'span', 'font', 'a', 'hr')
|
||||
for token in all_tokens:
|
||||
if isinstance(token, (CData, Comment, Declaration, ProcessingInstruction)):
|
||||
if isinstance(token, (bs4.CData, bs4.Comment, bs4.Declaration,
|
||||
bs4.ProcessingInstruction)):
|
||||
continue
|
||||
if isinstance(token, NavigableString):
|
||||
if isinstance(token, bs4.NavigableString):
|
||||
if not open_pTag:
|
||||
pTag = result.new_tag('p')
|
||||
open_pTag = True
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import importlib
|
||||
import os
|
||||
import sys
|
||||
|
||||
@@ -32,153 +33,67 @@ def as_unicode(x, encoding='utf-8', errors='strict'):
|
||||
return unicode_type(x)
|
||||
|
||||
|
||||
def only_unicode_recursive(x, encoding='utf-8', errors='strict'):
|
||||
# Convert any bytestrings in sets/lists/tuples/dicts to unicode
|
||||
def reraise(tp, value, tb=None):
|
||||
try:
|
||||
if value is None:
|
||||
value = tp()
|
||||
if value.__traceback__ is not tb:
|
||||
raise value.with_traceback(tb)
|
||||
raise value
|
||||
finally:
|
||||
value = None
|
||||
tb = None
|
||||
|
||||
|
||||
codepoint_to_chr = chr
|
||||
unicode_type = str
|
||||
string_or_bytes = str, bytes
|
||||
string_or_unicode = str
|
||||
long_type = int
|
||||
raw_input = input
|
||||
getcwd = os.getcwd
|
||||
getenv = os.getenv
|
||||
|
||||
|
||||
def error_message(exc):
|
||||
args = getattr(exc, 'args', None)
|
||||
if args and isinstance(args[0], unicode_type):
|
||||
return args[0]
|
||||
return unicode_type(exc)
|
||||
|
||||
|
||||
def iteritems(d):
|
||||
return iter(d.items())
|
||||
|
||||
|
||||
def itervalues(d):
|
||||
return iter(d.values())
|
||||
|
||||
|
||||
def environ_item(x):
|
||||
if isinstance(x, bytes):
|
||||
return x.decode(encoding, errors)
|
||||
if isinstance(x, unicode_type):
|
||||
return x
|
||||
if isinstance(x, (set, list, tuple, frozenset)):
|
||||
return type(x)(only_unicode_recursive(i, encoding, errors) for i in x)
|
||||
if isinstance(x, dict):
|
||||
return {only_unicode_recursive(k, encoding, errors): only_unicode_recursive(v, encoding, errors) for k, v in iteritems(x)}
|
||||
x = x.decode('utf-8')
|
||||
return x
|
||||
|
||||
|
||||
if is_py3:
|
||||
def reraise(tp, value, tb=None):
|
||||
try:
|
||||
if value is None:
|
||||
value = tp()
|
||||
if value.__traceback__ is not tb:
|
||||
raise value.with_traceback(tb)
|
||||
raise value
|
||||
finally:
|
||||
value = None
|
||||
tb = None
|
||||
def exec_path(path, ctx=None):
|
||||
ctx = ctx or {}
|
||||
with open(path, 'rb') as f:
|
||||
code = f.read()
|
||||
code = compile(code, f.name, 'exec')
|
||||
exec(code, ctx)
|
||||
|
||||
import builtins
|
||||
|
||||
zip = builtins.zip
|
||||
map = builtins.map
|
||||
filter = builtins.filter
|
||||
range = builtins.range
|
||||
def cmp(a, b):
|
||||
return (a > b) - (a < b)
|
||||
|
||||
codepoint_to_chr = chr
|
||||
unicode_type = str
|
||||
string_or_bytes = str, bytes
|
||||
string_or_unicode = str
|
||||
long_type = int
|
||||
raw_input = input
|
||||
getcwd = os.getcwd
|
||||
getenv = os.getenv
|
||||
|
||||
def error_message(exc):
|
||||
args = getattr(exc, 'args', None)
|
||||
if args and isinstance(args[0], unicode_type):
|
||||
return args[0]
|
||||
return unicode_type(exc)
|
||||
def int_to_byte(x):
|
||||
return bytes((x,))
|
||||
|
||||
def iteritems(d):
|
||||
return iter(d.items())
|
||||
|
||||
def itervalues(d):
|
||||
return iter(d.values())
|
||||
|
||||
def environ_item(x):
|
||||
if isinstance(x, bytes):
|
||||
x = x.decode('utf-8')
|
||||
return x
|
||||
|
||||
def exec_path(path, ctx=None):
|
||||
ctx = ctx or {}
|
||||
with open(path, 'rb') as f:
|
||||
code = f.read()
|
||||
code = compile(code, f.name, 'exec')
|
||||
exec(code, ctx)
|
||||
|
||||
def cmp(a, b):
|
||||
return (a > b) - (a < b)
|
||||
|
||||
def int_to_byte(x):
|
||||
return bytes((x,))
|
||||
|
||||
def reload(module):
|
||||
import importlib
|
||||
return importlib.reload(module)
|
||||
|
||||
else:
|
||||
exec("""def reraise(tp, value, tb=None):
|
||||
try:
|
||||
raise tp, value, tb
|
||||
finally:
|
||||
tb = None
|
||||
""")
|
||||
|
||||
from future_builtins import zip, map, filter # noqa
|
||||
range = xrange
|
||||
import __builtin__ as builtins
|
||||
|
||||
codepoint_to_chr = unichr
|
||||
unicode_type = unicode
|
||||
string_or_bytes = unicode, bytes
|
||||
string_or_unicode = str, unicode
|
||||
long_type = long
|
||||
exec_path = execfile
|
||||
raw_input = builtins.raw_input
|
||||
cmp = builtins.cmp
|
||||
int_to_byte = chr
|
||||
getcwd = os.getcwdu
|
||||
|
||||
def error_message(exc):
|
||||
ans = exc.message
|
||||
if isinstance(ans, bytes):
|
||||
ans = ans.decode('utf-8', 'replace')
|
||||
return ans
|
||||
|
||||
def iteritems(d):
|
||||
return d.iteritems()
|
||||
|
||||
def itervalues(d):
|
||||
return d.itervalues()
|
||||
|
||||
def environ_item(x):
|
||||
if isinstance(x, unicode_type):
|
||||
x = x.encode('utf-8')
|
||||
return x
|
||||
|
||||
if hasattr(sys, 'getwindowsversion'):
|
||||
def getenv(x, default=None):
|
||||
if isinstance(x, bytes):
|
||||
x = x.decode('mbcs', 'replace')
|
||||
|
||||
if getenv.buf is None:
|
||||
import ctypes
|
||||
import ctypes.wintypes as w
|
||||
getenv.cub = ctypes.create_unicode_buffer
|
||||
getenv.buf = getenv.cub(1024)
|
||||
getenv.gev = ctypes.windll.kernel32.GetEnvironmentVariableW
|
||||
getenv.gev.restype = w.DWORD
|
||||
getenv.gev.argtypes = [w.LPCWSTR, w.LPWSTR, w.DWORD]
|
||||
res = getenv.gev(x, getenv.buf, len(getenv.buf))
|
||||
if res == 0:
|
||||
return default
|
||||
if res > len(getenv.buf) - 4:
|
||||
getenv.buf = getenv.cub(res + 8)
|
||||
res = getenv.gev(x, getenv.buf, len(getenv.buf))
|
||||
if res == 0:
|
||||
return default
|
||||
return getenv.buf.value
|
||||
getenv.buf = None
|
||||
else:
|
||||
def getenv(x, default=None):
|
||||
ans = os.getenv(x, default)
|
||||
if isinstance(ans, bytes):
|
||||
ans = ans.decode('utf-8', 'replace')
|
||||
return ans
|
||||
|
||||
def reload(module):
|
||||
return builtins.reload(module)
|
||||
def reload(module):
|
||||
return importlib.reload(module)
|
||||
|
||||
|
||||
def print_to_binary_file(fileobj, encoding='utf-8'):
|
||||
|
||||
@@ -5,7 +5,7 @@ Provides platform independent temporary files that persist even after
|
||||
being closed.
|
||||
"""
|
||||
import tempfile, os, atexit
|
||||
from ebook_converter.polyglot.builtins import map, getenv
|
||||
from ebook_converter.polyglot.builtins import getenv
|
||||
|
||||
from ebook_converter.constants import (__version__, __appname__, filesystem_encoding,
|
||||
iswindows, get_windows_temp_path, isosx, ispy3)
|
||||
|
||||
@@ -6,10 +6,13 @@ __docformat__ = 'restructuredtext en'
|
||||
Perform various initialization tasks.
|
||||
'''
|
||||
|
||||
import locale, sys, os
|
||||
import builtins
|
||||
import locale
|
||||
import sys
|
||||
import os
|
||||
|
||||
# Default translation is NOOP
|
||||
from ebook_converter.polyglot.builtins import builtins, is_py3, unicode_type
|
||||
from ebook_converter.polyglot.builtins import is_py3
|
||||
builtins.__dict__['_'] = lambda s: s
|
||||
|
||||
# For strings which belong in the translation tables, but which shouldn't be
|
||||
@@ -75,7 +78,7 @@ if not _run_once:
|
||||
winutil, winutilerror = plugins['winutil']
|
||||
if not winutil:
|
||||
raise RuntimeError('Failed to load the winutil plugin: %s'%winutilerror)
|
||||
if len(sys.argv) > 1 and not isinstance(sys.argv[1], unicode_type):
|
||||
if len(sys.argv) > 1 and not isinstance(sys.argv[1], str):
|
||||
sys.argv[1:] = winutil.argv()[1-len(sys.argv):]
|
||||
|
||||
if not ispy3:
|
||||
@@ -110,7 +113,7 @@ if not _run_once:
|
||||
if isosx:
|
||||
enc = 'utf-8'
|
||||
for i in range(1, len(sys.argv)):
|
||||
if not isinstance(sys.argv[i], unicode_type):
|
||||
if not isinstance(sys.argv[i], str):
|
||||
sys.argv[i] = sys.argv[i].decode(enc, 'replace')
|
||||
|
||||
#
|
||||
@@ -239,7 +242,7 @@ if not _run_once:
|
||||
if name == 'Thread':
|
||||
name = self.name
|
||||
if name:
|
||||
if isinstance(name, unicode_type):
|
||||
if isinstance(name, str):
|
||||
name = name.encode('ascii', 'replace').decode('ascii')
|
||||
plugins['speedup'][0].set_thread_name(name[:15])
|
||||
except Exception:
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import re
|
||||
|
||||
from ebook_converter.polyglot.builtins import map
|
||||
from ebook_converter.tinycss.css21 import CSS21Parser, ParseError
|
||||
from ebook_converter.tinycss.tokenizer import tokenize_grouped
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import re
|
||||
|
||||
from ebook_converter.polyglot.builtins import codepoint_to_chr, map, range, filter
|
||||
from ebook_converter.polyglot.builtins import codepoint_to_chr
|
||||
from ebook_converter.polyglot.html_entities import name2codepoint
|
||||
from ebook_converter.constants import plugins, preferred_encoding
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import pkg_resources
|
||||
|
||||
from ebook_converter.utils.lock import ExclusiveFile
|
||||
from ebook_converter.constants import config_dir, CONFIG_DIR_MODE, ispy3, preferred_encoding, filesystem_encoding, iswindows
|
||||
from ebook_converter.polyglot.builtins import unicode_type, iteritems, map
|
||||
from ebook_converter.polyglot.builtins import unicode_type, iteritems
|
||||
|
||||
plugin_dir = os.path.join(config_dir, 'plugins')
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ from ebook_converter.constants import (
|
||||
filesystem_encoding, iswindows, plugins, preferred_encoding, isosx, ispy3
|
||||
)
|
||||
from ebook_converter.utils.localization import get_udc
|
||||
from ebook_converter.polyglot.builtins import iteritems, itervalues, unicode_type, range
|
||||
from ebook_converter.polyglot.builtins import iteritems, itervalues, unicode_type
|
||||
|
||||
|
||||
def ascii_text(orig):
|
||||
|
||||
@@ -3,7 +3,7 @@ from struct import calcsize, unpack, unpack_from
|
||||
from collections import namedtuple
|
||||
|
||||
from ebook_converter.utils.fonts.utils import get_font_names2, get_font_characteristics
|
||||
from ebook_converter.polyglot.builtins import range, unicode_type
|
||||
from ebook_converter.polyglot.builtins import unicode_type
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -6,7 +6,7 @@ from ebook_converter import walk, prints, as_unicode
|
||||
from ebook_converter.constants import (config_dir, iswindows, isosx, plugins, DEBUG,
|
||||
isworker, filesystem_encoding)
|
||||
from ebook_converter.utils.fonts.metadata import FontMetadata, UnsupportedFont
|
||||
from ebook_converter.polyglot.builtins import itervalues, unicode_type, filter
|
||||
from ebook_converter.polyglot.builtins import itervalues, unicode_type
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from struct import pack, unpack_from
|
||||
from ebook_converter.polyglot.builtins import range, unicode_type
|
||||
from ebook_converter.polyglot.builtins import unicode_type
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -6,7 +6,7 @@ from ebook_converter.utils.fonts.sfnt.errors import UnsupportedFont, NoGlyphs
|
||||
from ebook_converter.utils.fonts.sfnt.cff.dict_data import TopDict, PrivateDict
|
||||
from ebook_converter.utils.fonts.sfnt.cff.constants import (cff_standard_strings,
|
||||
STANDARD_CHARSETS)
|
||||
from ebook_converter.polyglot.builtins import iteritems, itervalues, range
|
||||
from ebook_converter.polyglot.builtins import iteritems, itervalues
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -4,7 +4,6 @@ from collections import OrderedDict
|
||||
from ebook_converter.utils.fonts.utils import read_bmp_prefix
|
||||
from ebook_converter.utils.fonts.sfnt import UnknownTable, max_power_of_two
|
||||
from ebook_converter.utils.fonts.sfnt.errors import UnsupportedFont
|
||||
from ebook_converter.polyglot.builtins import range
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -2,7 +2,7 @@ from struct import unpack_from, calcsize
|
||||
from collections import OrderedDict, namedtuple
|
||||
|
||||
from ebook_converter.utils.fonts.sfnt.errors import UnsupportedFont
|
||||
from ebook_converter.polyglot.builtins import range, iteritems
|
||||
from ebook_converter.polyglot.builtins import iteritems
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -3,7 +3,6 @@ from struct import unpack_from, pack, calcsize
|
||||
from ebook_converter.utils.fonts.sfnt import UnknownTable, DateTimeProperty, FixedProperty
|
||||
from ebook_converter.utils.fonts.sfnt.errors import UnsupportedFont
|
||||
from ebook_converter.utils.fonts.sfnt.loca import read_array
|
||||
from ebook_converter.polyglot.builtins import zip
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -3,7 +3,6 @@ from struct import unpack_from, calcsize, pack, error as struct_error
|
||||
from ebook_converter.utils.fonts.sfnt import (UnknownTable, FixedProperty,
|
||||
max_power_of_two)
|
||||
from ebook_converter.utils.fonts.sfnt.errors import UnsupportedFont
|
||||
from ebook_converter.polyglot.builtins import range
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -3,7 +3,7 @@ from operator import itemgetter
|
||||
from itertools import repeat
|
||||
|
||||
from ebook_converter.utils.fonts.sfnt import UnknownTable
|
||||
from ebook_converter.polyglot.builtins import iteritems, range
|
||||
from ebook_converter.polyglot.builtins import iteritems
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -2,7 +2,6 @@ from struct import unpack_from, pack
|
||||
|
||||
from ebook_converter.utils.fonts.sfnt import UnknownTable, FixedProperty
|
||||
from ebook_converter.utils.fonts.sfnt.errors import UnsupportedFont
|
||||
from ebook_converter.polyglot.builtins import zip
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -6,7 +6,7 @@ from functools import partial
|
||||
from ebook_converter.utils.icu import safe_chr, ord_string
|
||||
from ebook_converter.utils.fonts.sfnt.container import Sfnt
|
||||
from ebook_converter.utils.fonts.sfnt.errors import UnsupportedFont, NoGlyphs
|
||||
from ebook_converter.polyglot.builtins import unicode_type, range, iteritems, itervalues, map
|
||||
from ebook_converter.polyglot.builtins import unicode_type, iteritems, itervalues
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -2,7 +2,7 @@ import struct
|
||||
from io import BytesIO
|
||||
from collections import defaultdict
|
||||
|
||||
from ebook_converter.polyglot.builtins import iteritems, itervalues, unicode_type, range, as_bytes
|
||||
from ebook_converter.polyglot.builtins import iteritems, itervalues, unicode_type, as_bytes
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -5,7 +5,6 @@ import unicodedata
|
||||
# Setup code {{{
|
||||
from ebook_converter.constants import plugins
|
||||
from ebook_converter.polyglot.builtins import unicode_type, cmp
|
||||
from ebook_converter.polyglot.builtins import filter
|
||||
from ebook_converter.utils.config_base import tweaks
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ __docformat__ = 'restructuredtext en'
|
||||
import sys, os
|
||||
|
||||
from ebook_converter import config_dir
|
||||
from ebook_converter.polyglot.builtins import builtins
|
||||
|
||||
|
||||
user_dir = os.path.join(config_dir, 'resources')
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import os
|
||||
|
||||
from ebook_converter.polyglot.builtins import range, unicode_type
|
||||
from ebook_converter.polyglot.builtins import unicode_type
|
||||
|
||||
|
||||
class ReadOnlyFileBuffer(object):
|
||||
|
||||
@@ -7,7 +7,7 @@ except ValueError:
|
||||
iswindows = False
|
||||
|
||||
from ebook_converter.constants import ispy3
|
||||
from ebook_converter.polyglot.builtins import iteritems, range, zip, native_string_type
|
||||
from ebook_converter.polyglot.builtins import iteritems, native_string_type
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
@@ -10,7 +10,7 @@ from tempfile import SpooledTemporaryFile
|
||||
from ebook_converter import sanitize_file_name
|
||||
from ebook_converter.constants import filesystem_encoding
|
||||
from ebook_converter.ebooks.chardet import detect
|
||||
from ebook_converter.polyglot.builtins import unicode_type, string_or_bytes, getcwd, map, as_bytes
|
||||
from ebook_converter.polyglot.builtins import unicode_type, string_or_bytes, getcwd, as_bytes
|
||||
|
||||
try:
|
||||
import zlib # We may need its compression method
|
||||
|
||||
Reference in New Issue
Block a user