1
0
mirror of https://github.com/gryf/ebook-converter.git synced 2026-03-17 23:33:43 +01:00

Removed check for python version

This commit is contained in:
2020-04-21 21:06:48 +02:00
parent 3234e4de27
commit de4f8a444b
21 changed files with 54 additions and 246 deletions

View File

@@ -1,7 +1,7 @@
import copy, traceback
from ebook_converter import prints
from ebook_converter.constants import DEBUG, ispy3
from ebook_converter.constants import DEBUG
from ebook_converter.ebooks.metadata.book import (SC_COPYABLE_FIELDS,
SC_FIELDS_COPY_NOT_NULL, STANDARD_METADATA_FIELDS,
TOP_LEVEL_IDENTIFIERS, ALL_METADATA_FIELDS)
@@ -789,13 +789,7 @@ class Metadata(object):
ans[i] = '<tr><td><b>%s</b></td><td>%s</td></tr>'%x
return '<table>%s</table>'%'\n'.join(ans)
if ispy3:
__str__ = __unicode__representation__
else:
__unicode__ = __unicode__representation__
def __str__(self):
return self.__unicode__().encode('utf-8')
__str__ = __unicode__representation__
def __nonzero__(self):
return bool(self.title or self.author or self.comments or self.tags)

View File

@@ -16,7 +16,7 @@ import uuid
from lxml import etree
from ebook_converter.ebooks import escape_xpath_attr
from ebook_converter.constants import __appname__, __version__, filesystem_encoding, ispy3
from ebook_converter.constants import __appname__, __version__, filesystem_encoding
from ebook_converter.ebooks.metadata.toc import TOC
from ebook_converter.ebooks.metadata.utils import parse_opf, pretty_print_opf as _pretty_print
from ebook_converter.ebooks.metadata import string_to_authors, MetaInformation, check_isbn
@@ -212,13 +212,7 @@ class ManifestItem(Resource): # {{{
def __unicode__representation__(self):
return u'<item id="%s" href="%s" media-type="%s" />'%(self.id, self.href(), self.media_type)
if ispy3:
__str__ = __unicode__representation__
else:
__unicode__ = __unicode__representation__
def __str__(self):
return str(self).encode('utf-8')
__str__ = __unicode__representation__
def __repr__(self):
return str(self)

View File

@@ -5,7 +5,7 @@ import os, subprocess, shutil, re
from functools import partial
from ebook_converter import prints
from ebook_converter.constants import iswindows, ispy3
from ebook_converter.constants import iswindows
from ebook_converter.ptempfile import TemporaryDirectory
from ebook_converter.ebooks.metadata import (
MetaInformation, string_to_authors, check_isbn, check_doi)
@@ -101,8 +101,6 @@ def page_images(pdfpath, outputdir='.', first=1, last=1, image_format='jpeg', pr
def is_pdf_encrypted(path_to_pdf):
if not ispy3 and not isinstance(path_to_pdf, bytes):
path_to_pdf = path_to_pdf.encode('mbcs' if iswindows else 'utf-8')
pdfinfo = get_tools()[0]
raw = subprocess.check_output([pdfinfo, path_to_pdf])
q = re.search(br'^Encrypted:\s*(\S+)', raw, flags=re.MULTILINE)

View File

@@ -9,7 +9,7 @@ import urllib.parse
from lxml import etree, html
from ebook_converter import force_unicode
from ebook_converter.constants import filesystem_encoding, __version__, ispy3
from ebook_converter.constants import filesystem_encoding, __version__
from ebook_converter.utils.xml_parse import safe_xml_fromstring
from ebook_converter.ebooks.chardet import xml_to_unicode
from ebook_converter.ebooks.conversion.preprocess import CSSPreProcessor
@@ -753,15 +753,8 @@ class Metadata(object):
return 'Item(term=%r, value=%r, attrib=%r)' \
% (barename(self.term), self.value, self.attrib)
if ispy3:
def __str__(self):
return as_unicode(self.value)
else:
def __str__(self):
return str(self.value).encode('ascii', 'xmlcharrefreplace')
def __unicode__(self):
return as_unicode(self.value)
def __str__(self):
return as_unicode(self.value)
def to_opf1(self, dcmeta=None, xmeta=None, nsrmap={}):
attrib = {}
@@ -1096,15 +1089,8 @@ class Manifest(object):
def bytes_representation(self):
return serialize(self.data, self.media_type, pretty_print=self.oeb.pretty_print)
if ispy3:
def __str__(self):
return self.unicode_representation
else:
def __unicode__(self):
return self.unicode_representation
def __str__(self):
return self.bytes_representation
def __str__(self):
return self.unicode_representation
def __eq__(self, other):
return self is other
@@ -1615,15 +1601,8 @@ class TOC(object):
ans.extend(child.get_lines(lvl+1))
return ans
if ispy3:
def __str__(self):
return '\n'.join(self.get_lines())
else:
def __unicode__(self):
return '\n'.join(self.get_lines())
def __str__(self):
return b'\n'.join([x.encode('utf-8') for x in self.get_lines()])
def __str__(self):
return '\n'.join(self.get_lines())
def to_opf1(self, tour):
for node in self.nodes:

View File

@@ -7,7 +7,7 @@ import sys
from ebook_converter import CurrentDir, xml_replace_entities, prints
from ebook_converter.constants import (
filesystem_encoding, isbsd, islinux, isosx, ispy3, iswindows
filesystem_encoding, isbsd, islinux, isosx, iswindows
)
from ebook_converter.ebooks import ConversionError, DRMError
from ebook_converter.ebooks.chardet import xml_to_unicode
@@ -20,8 +20,6 @@ PDFTOHTML = 'pdftohtml'
def popen(cmd, **kw):
if not ispy3:
cmd = [x.encode(filesystem_encoding) if not isinstance(x, bytes) else x for x in cmd]
if iswindows:
kw['creationflags'] = 0x08
return subprocess.Popen(cmd, **kw)

View File

@@ -2,7 +2,6 @@ import codecs, zlib, numbers
from io import BytesIO
from datetime import datetime
from ebook_converter.constants import ispy3
from ebook_converter.utils.logging import default_log
from ebook_converter.polyglot.binary import as_hex_bytes
@@ -65,7 +64,7 @@ def serialize(o, stream):
# Must check bool before int as bools are subclasses of int
stream.write_raw(b'true' if o else b'false')
elif isinstance(o, numbers.Integral):
stream.write_raw(str(o).encode('ascii') if ispy3 else bytes(o))
stream.write_raw(str(o).encode('ascii'))
elif hasattr(o, 'pdf_serialize'):
o.pdf_serialize(stream)
elif o is None: