mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Merge branch 'py3' of https://github.com/eli-schwartz/calibre
This commit is contained in:
commit
e3c889b10d
@ -223,13 +223,13 @@ class DOCX(object):
|
||||
|
||||
@property
|
||||
def containerrels(self):
|
||||
return textwrap.dedent(b'''\
|
||||
return textwrap.dedent('''\
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
|
||||
<Relationship Id="rId3" Type="{APPPROPS}" Target="docProps/app.xml"/>
|
||||
<Relationship Id="rId2" Type="{DOCPROPS}" Target="docProps/core.xml"/>
|
||||
<Relationship Id="rId1" Type="{DOCUMENT}" Target="word/document.xml"/>
|
||||
</Relationships>'''.format(**self.namespace.names))
|
||||
</Relationships>'''.format(**self.namespace.names)).encode('utf-8')
|
||||
|
||||
@property
|
||||
def websettings(self):
|
||||
|
@ -32,7 +32,7 @@ from calibre.srv.users import (
|
||||
UserManager, create_user_data, validate_password, validate_username
|
||||
)
|
||||
from calibre.utils.icu import primary_sort_key
|
||||
from polyglot.binary import unicode_type
|
||||
from polyglot.builtins import unicode_type, as_bytes
|
||||
|
||||
try:
|
||||
from PyQt5 import sip
|
||||
@ -967,7 +967,7 @@ class CustomList(QWidget): # {{{
|
||||
if path:
|
||||
raw = self.serialize(self.current_template)
|
||||
with lopen(path, 'wb') as f:
|
||||
f.write(raw)
|
||||
f.write(as_bytes(raw))
|
||||
|
||||
def thumbnail_state_changed(self):
|
||||
is_enabled = bool(self.thumbnail.isChecked())
|
||||
@ -1020,7 +1020,7 @@ class CustomList(QWidget): # {{{
|
||||
else:
|
||||
raw = self.serialize(template)
|
||||
with lopen(custom_list_template.path, 'wb') as f:
|
||||
f.write(raw)
|
||||
f.write(as_bytes(raw))
|
||||
return True
|
||||
|
||||
# }}}
|
||||
|
@ -2,21 +2,27 @@
|
||||
# vim:fileencoding=utf-8
|
||||
# License: GPLv3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
from __future__ import (unicode_literals, division, absolute_import,
|
||||
print_function)
|
||||
from hashlib import sha1
|
||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||
|
||||
import errno
|
||||
import json as jsonlib
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
import time
|
||||
from functools import partial
|
||||
from threading import RLock, Lock
|
||||
import errno, os, tempfile, shutil, time, json as jsonlib
|
||||
from hashlib import sha1
|
||||
from threading import Lock, RLock
|
||||
|
||||
from calibre.constants import cache_dir, iswindows
|
||||
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.render_book import RENDER_VERSION
|
||||
from calibre.srv.errors import HTTPNotFound, BookNotFound
|
||||
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 polyglot.builtins import as_unicode
|
||||
|
||||
cache_lock = RLock()
|
||||
queued_jobs = {}
|
||||
@ -50,7 +56,7 @@ def books_cache_dir():
|
||||
|
||||
def book_hash(library_uuid, book_id, fmt, size, mtime):
|
||||
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
|
||||
|
@ -31,7 +31,7 @@ from calibre.ebooks.oeb.polish.utils import extract, guess_type
|
||||
from calibre.utils.logging import default_log
|
||||
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.builtins import iteritems, map, unicode_type
|
||||
from polyglot.builtins import iteritems, map, is_py3, unicode_type
|
||||
from polyglot.urllib import quote, urlparse
|
||||
|
||||
RENDER_VERSION = 1
|
||||
@ -501,6 +501,9 @@ def html_as_dict(root):
|
||||
if child.tag.partition('}')[-1] not in ('head', 'body'):
|
||||
root.remove(child)
|
||||
root.text = root.tail = None
|
||||
if is_py3:
|
||||
nsmap = defaultdict(count().__next__)
|
||||
else:
|
||||
nsmap = defaultdict(count().next)
|
||||
nsmap[XHTML_NS]
|
||||
tags = [serialize_elem(root, nsmap)]
|
||||
|
@ -22,7 +22,7 @@ from calibre.utils.shared_file import share_open, raise_winerror
|
||||
from polyglot.builtins import iteritems, map, range
|
||||
from polyglot import reprlib
|
||||
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.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
|
||||
|
||||
|
||||
if iswindows:
|
||||
if iswindows and not is_py3:
|
||||
def fast_now_strftime(fmt):
|
||||
fmt = fmt.encode('mbcs')
|
||||
fmt = as_bytes(fmt, encoding='mbcs')
|
||||
return time.strftime(fmt).decode('mbcs', 'replace')
|
||||
else:
|
||||
def fast_now_strftime(fmt):
|
||||
return time.strftime(fmt).decode('utf-8', 'replace')
|
||||
return as_unicode(time.strftime(fmt), errors='replace')
|
||||
|
Loading…
x
Reference in New Issue
Block a user