This commit is contained in:
Kovid Goyal 2019-05-12 11:08:35 +05:30
commit e3c889b10d
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
5 changed files with 28 additions and 19 deletions

View File

@ -223,13 +223,13 @@ class DOCX(object):
@property @property
def containerrels(self): def containerrels(self):
return textwrap.dedent(b'''\ return textwrap.dedent('''\
<?xml version='1.0' encoding='utf-8'?> <?xml version='1.0' encoding='utf-8'?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"> <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId3" Type="{APPPROPS}" Target="docProps/app.xml"/> <Relationship Id="rId3" Type="{APPPROPS}" Target="docProps/app.xml"/>
<Relationship Id="rId2" Type="{DOCPROPS}" Target="docProps/core.xml"/> <Relationship Id="rId2" Type="{DOCPROPS}" Target="docProps/core.xml"/>
<Relationship Id="rId1" Type="{DOCUMENT}" Target="word/document.xml"/> <Relationship Id="rId1" Type="{DOCUMENT}" Target="word/document.xml"/>
</Relationships>'''.format(**self.namespace.names)) </Relationships>'''.format(**self.namespace.names)).encode('utf-8')
@property @property
def websettings(self): def websettings(self):

View File

@ -32,7 +32,7 @@ from calibre.srv.users import (
UserManager, create_user_data, validate_password, validate_username UserManager, create_user_data, validate_password, validate_username
) )
from calibre.utils.icu import primary_sort_key from calibre.utils.icu import primary_sort_key
from polyglot.binary import unicode_type from polyglot.builtins import unicode_type, as_bytes
try: try:
from PyQt5 import sip from PyQt5 import sip
@ -967,7 +967,7 @@ class CustomList(QWidget): # {{{
if path: if path:
raw = self.serialize(self.current_template) raw = self.serialize(self.current_template)
with lopen(path, 'wb') as f: with lopen(path, 'wb') as f:
f.write(raw) f.write(as_bytes(raw))
def thumbnail_state_changed(self): def thumbnail_state_changed(self):
is_enabled = bool(self.thumbnail.isChecked()) is_enabled = bool(self.thumbnail.isChecked())
@ -1020,7 +1020,7 @@ class CustomList(QWidget): # {{{
else: else:
raw = self.serialize(template) raw = self.serialize(template)
with lopen(custom_list_template.path, 'wb') as f: with lopen(custom_list_template.path, 'wb') as f:
f.write(raw) f.write(as_bytes(raw))
return True return True
# }}} # }}}

View File

@ -2,21 +2,27 @@
# vim:fileencoding=utf-8 # vim:fileencoding=utf-8
# License: GPLv3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net> # License: GPLv3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
from __future__ import (unicode_literals, division, absolute_import, from __future__ import absolute_import, division, print_function, unicode_literals
print_function)
from hashlib import sha1 import errno
import json as jsonlib
import os
import shutil
import tempfile
import time
from functools import partial from functools import partial
from threading import RLock, Lock from hashlib import sha1
import errno, os, tempfile, shutil, time, json as jsonlib from threading import Lock, RLock
from calibre.constants import cache_dir, iswindows from calibre.constants import cache_dir, iswindows
from calibre.customize.ui import plugin_for_input_format from calibre.customize.ui import plugin_for_input_format
from calibre.srv.errors import BookNotFound, HTTPNotFound
from calibre.srv.metadata import book_as_json from calibre.srv.metadata import book_as_json
from calibre.srv.render_book import RENDER_VERSION from calibre.srv.render_book import RENDER_VERSION
from calibre.srv.errors import HTTPNotFound, BookNotFound
from calibre.srv.routes import endpoint, json from calibre.srv.routes import endpoint, json
from calibre.srv.utils import get_library_data, get_db from calibre.srv.utils import get_db, get_library_data
from calibre.utils.serialize import json_dumps from calibre.utils.serialize import json_dumps
from polyglot.builtins import as_unicode
cache_lock = RLock() cache_lock = RLock()
queued_jobs = {} queued_jobs = {}
@ -50,7 +56,7 @@ def books_cache_dir():
def book_hash(library_uuid, book_id, fmt, size, mtime): def book_hash(library_uuid, book_id, fmt, size, mtime):
raw = json_dumps((library_uuid, book_id, fmt.upper(), size, mtime, RENDER_VERSION)) raw = json_dumps((library_uuid, book_id, fmt.upper(), size, mtime, RENDER_VERSION))
return sha1(raw).hexdigest().decode('ascii') return as_unicode(sha1(raw).hexdigest())
staging_cleaned = False staging_cleaned = False

View File

@ -31,7 +31,7 @@ from calibre.ebooks.oeb.polish.utils import extract, guess_type
from calibre.utils.logging import default_log from calibre.utils.logging import default_log
from calibre.utils.short_uuid import uuid4 from calibre.utils.short_uuid import uuid4
from polyglot.binary import as_base64_unicode as encode_component, from_base64_unicode as decode_component from polyglot.binary import as_base64_unicode as encode_component, from_base64_unicode as decode_component
from polyglot.builtins import iteritems, map, unicode_type from polyglot.builtins import iteritems, map, is_py3, unicode_type
from polyglot.urllib import quote, urlparse from polyglot.urllib import quote, urlparse
RENDER_VERSION = 1 RENDER_VERSION = 1
@ -501,7 +501,10 @@ def html_as_dict(root):
if child.tag.partition('}')[-1] not in ('head', 'body'): if child.tag.partition('}')[-1] not in ('head', 'body'):
root.remove(child) root.remove(child)
root.text = root.tail = None root.text = root.tail = None
nsmap = defaultdict(count().next) if is_py3:
nsmap = defaultdict(count().__next__)
else:
nsmap = defaultdict(count().next)
nsmap[XHTML_NS] nsmap[XHTML_NS]
tags = [serialize_elem(root, nsmap)] tags = [serialize_elem(root, nsmap)]
tree = [0] tree = [0]

View File

@ -22,7 +22,7 @@ from calibre.utils.shared_file import share_open, raise_winerror
from polyglot.builtins import iteritems, map, range from polyglot.builtins import iteritems, map, range
from polyglot import reprlib from polyglot import reprlib
from polyglot.http_cookie import SimpleCookie from polyglot.http_cookie import SimpleCookie
from polyglot.builtins import unicode_type from polyglot.builtins import is_py3, unicode_type, as_bytes, as_unicode
from polyglot.urllib import parse_qs, quote as urlquote from polyglot.urllib import parse_qs, quote as urlquote
from polyglot.binary import as_hex_unicode as encode_name, from_hex_unicode as decode_name from polyglot.binary import as_hex_unicode as encode_name, from_hex_unicode as decode_name
@ -530,10 +530,10 @@ def get_use_roman():
return _use_roman return _use_roman
if iswindows: if iswindows and not is_py3:
def fast_now_strftime(fmt): def fast_now_strftime(fmt):
fmt = fmt.encode('mbcs') fmt = as_bytes(fmt, encoding='mbcs')
return time.strftime(fmt).decode('mbcs', 'replace') return time.strftime(fmt).decode('mbcs', 'replace')
else: else:
def fast_now_strftime(fmt): def fast_now_strftime(fmt):
return time.strftime(fmt).decode('utf-8', 'replace') return as_unicode(time.strftime(fmt), errors='replace')