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
1ea8b07078
@ -320,7 +320,7 @@ def extract(path, dir):
|
|||||||
|
|
||||||
|
|
||||||
def get_proxies(debug=True):
|
def get_proxies(debug=True):
|
||||||
from urllib import getproxies
|
from polyglot.urllib import getproxies
|
||||||
proxies = getproxies()
|
proxies = getproxies()
|
||||||
for key, proxy in list(proxies.items()):
|
for key, proxy in list(proxies.items()):
|
||||||
if not proxy or '..' in proxy or key == 'auto':
|
if not proxy or '..' in proxy or key == 'auto':
|
||||||
@ -382,10 +382,10 @@ def get_proxy_info(proxy_scheme, proxy_string):
|
|||||||
is not available in the string. If an exception occurs parsing the string
|
is not available in the string. If an exception occurs parsing the string
|
||||||
this method returns None.
|
this method returns None.
|
||||||
'''
|
'''
|
||||||
import urlparse
|
from polyglot.urllib import urlparse
|
||||||
try:
|
try:
|
||||||
proxy_url = u'%s://%s'%(proxy_scheme, proxy_string)
|
proxy_url = u'%s://%s'%(proxy_scheme, proxy_string)
|
||||||
urlinfo = urlparse.urlparse(proxy_url)
|
urlinfo = urlparse(proxy_url)
|
||||||
ans = {
|
ans = {
|
||||||
u'scheme': urlinfo.scheme,
|
u'scheme': urlinfo.scheme,
|
||||||
u'hostname': urlinfo.hostname,
|
u'hostname': urlinfo.hostname,
|
||||||
|
@ -8,8 +8,6 @@ import httplib
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from urllib import urlencode
|
|
||||||
from urlparse import urlparse, urlunparse
|
|
||||||
|
|
||||||
from calibre import browser, prints
|
from calibre import browser, prints
|
||||||
from calibre.constants import __appname__, __version__, iswindows
|
from calibre.constants import __appname__, __version__, iswindows
|
||||||
@ -19,6 +17,7 @@ from calibre.utils.config import OptionParser, prefs
|
|||||||
from calibre.utils.localization import localize_user_manual_link
|
from calibre.utils.localization import localize_user_manual_link
|
||||||
from calibre.utils.lock import singleinstance
|
from calibre.utils.lock import singleinstance
|
||||||
from calibre.utils.serialize import MSGPACK_MIME
|
from calibre.utils.serialize import MSGPACK_MIME
|
||||||
|
from polyglot.urllib import urlencode, urlparse, urlunparse
|
||||||
|
|
||||||
COMMANDS = (
|
COMMANDS = (
|
||||||
'list', 'add', 'remove', 'add_format', 'remove_format', 'show_metadata',
|
'list', 'add', 'remove', 'add_format', 'remove_format', 'show_metadata',
|
||||||
|
@ -8,11 +8,11 @@ __copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
|
|
||||||
import os, tempfile, shutil, errno, time, atexit
|
import os, tempfile, shutil, errno, time, atexit
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from Queue import Queue
|
|
||||||
|
|
||||||
from calibre.ptempfile import remove_dir
|
from calibre.ptempfile import remove_dir
|
||||||
from calibre.utils.filenames import remove_dir_if_empty
|
from calibre.utils.filenames import remove_dir_if_empty
|
||||||
from calibre.utils.recycle_bin import delete_tree, delete_file
|
from calibre.utils.recycle_bin import delete_tree, delete_file
|
||||||
|
from polyglot.queue import Queue
|
||||||
|
|
||||||
|
|
||||||
class DeleteService(Thread):
|
class DeleteService(Thread):
|
||||||
@ -159,4 +159,3 @@ def has_jobs():
|
|||||||
if __ds is not None:
|
if __ds is not None:
|
||||||
return (not __ds.requests.empty()) or __ds.requests.unfinished_tasks
|
return (not __ds.requests.empty()) or __ds.requests.unfinished_tasks
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -11,7 +11,6 @@ import socket, select, json, os, traceback, time, sys, random
|
|||||||
import posixpath
|
import posixpath
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
import hashlib, threading
|
import hashlib, threading
|
||||||
import Queue
|
|
||||||
|
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from errno import EAGAIN, EINTR
|
from errno import EAGAIN, EINTR
|
||||||
@ -39,6 +38,7 @@ from calibre.utils.mdns import (publish as publish_zeroconf, unpublish as
|
|||||||
unpublish_zeroconf, get_all_ips)
|
unpublish_zeroconf, get_all_ips)
|
||||||
from calibre.utils.socket_inheritance import set_socket_inherit
|
from calibre.utils.socket_inheritance import set_socket_inherit
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import unicode_type
|
||||||
|
from polyglot import queue
|
||||||
|
|
||||||
|
|
||||||
def synchronous(tlockname):
|
def synchronous(tlockname):
|
||||||
@ -103,7 +103,7 @@ class ConnectionListener(Thread):
|
|||||||
{'otherDevice': d.get_gui_name()})
|
{'otherDevice': d.get_gui_name()})
|
||||||
self.driver._send_byte_string(device_socket, (b'%d' % len(s)) + s)
|
self.driver._send_byte_string(device_socket, (b'%d' % len(s)) + s)
|
||||||
sock.close()
|
sock.close()
|
||||||
except Queue.Empty:
|
except queue.Empty:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if getattr(self.driver, 'broadcast_socket', None) is not None:
|
if getattr(self.driver, 'broadcast_socket', None) is not None:
|
||||||
@ -148,7 +148,7 @@ class ConnectionListener(Thread):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
self.driver.connection_queue.put_nowait(device_socket)
|
self.driver.connection_queue.put_nowait(device_socket)
|
||||||
except Queue.Full:
|
except queue.Full:
|
||||||
self._close_socket(device_socket)
|
self._close_socket(device_socket)
|
||||||
device_socket = None
|
device_socket = None
|
||||||
self.driver._debug('driver is not answering')
|
self.driver._debug('driver is not answering')
|
||||||
@ -993,7 +993,7 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
|
|||||||
raise
|
raise
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
except Queue.Empty:
|
except queue.Empty:
|
||||||
self.is_connected = False
|
self.is_connected = False
|
||||||
return self if self.is_connected else None
|
return self if self.is_connected else None
|
||||||
return None
|
return None
|
||||||
@ -1969,7 +1969,7 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
|
|||||||
message = 'attaching port to broadcast socket failed. This is not fatal.'
|
message = 'attaching port to broadcast socket failed. This is not fatal.'
|
||||||
self._debug(message)
|
self._debug(message)
|
||||||
|
|
||||||
self.connection_queue = Queue.Queue(1)
|
self.connection_queue = queue.Queue(1)
|
||||||
self.connection_listener = ConnectionListener(self)
|
self.connection_listener = ConnectionListener(self)
|
||||||
self.connection_listener.start()
|
self.connection_listener.start()
|
||||||
return message
|
return message
|
||||||
|
@ -8,7 +8,6 @@ Based on ideas from comiclrf created by FangornUK.
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
import os, traceback, time
|
import os, traceback, time
|
||||||
from Queue import Empty
|
|
||||||
|
|
||||||
from calibre import extract, prints, walk
|
from calibre import extract, prints, walk
|
||||||
from calibre.constants import filesystem_encoding
|
from calibre.constants import filesystem_encoding
|
||||||
@ -17,6 +16,7 @@ from calibre.utils.icu import numeric_sort_key
|
|||||||
from calibre.utils.ipc.server import Server
|
from calibre.utils.ipc.server import Server
|
||||||
from calibre.utils.ipc.job import ParallelJob
|
from calibre.utils.ipc.job import ParallelJob
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import unicode_type
|
||||||
|
from polyglot.queue import Empty
|
||||||
|
|
||||||
# If the specified screen has either dimension larger than this value, no image
|
# If the specified screen has either dimension larger than this value, no image
|
||||||
# rescaling is done (we assume that it is a tablet output profile)
|
# rescaling is done (we assume that it is a tablet output profile)
|
||||||
|
@ -108,7 +108,7 @@ class CHMInput(InputFormatPlugin):
|
|||||||
|
|
||||||
def _create_html_root(self, hhcpath, log, encoding):
|
def _create_html_root(self, hhcpath, log, encoding):
|
||||||
from lxml import html
|
from lxml import html
|
||||||
from urllib import unquote as _unquote
|
from polyglot.urllib import unquote as _unquote
|
||||||
from calibre.ebooks.oeb.base import urlquote
|
from calibre.ebooks.oeb.base import urlquote
|
||||||
from calibre.ebooks.chardet import xml_to_unicode
|
from calibre.ebooks.chardet import xml_to_unicode
|
||||||
hhcdata = self._read_file(hhcpath)
|
hhcdata = self._read_file(hhcpath)
|
||||||
|
@ -247,7 +247,7 @@ class HTMLInput(InputFormatPlugin):
|
|||||||
return link, frag
|
return link, frag
|
||||||
|
|
||||||
def resource_adder(self, link_, base=None):
|
def resource_adder(self, link_, base=None):
|
||||||
from urllib import quote
|
from polyglot.urllib import quote
|
||||||
link, frag = self.link_to_local_path(link_, base=base)
|
link, frag = self.link_to_local_path(link_, base=base)
|
||||||
if link is None:
|
if link is None:
|
||||||
return link_
|
return link_
|
||||||
|
@ -47,7 +47,7 @@ class HTMLOutput(OutputFormatPlugin):
|
|||||||
Generate table of contents
|
Generate table of contents
|
||||||
'''
|
'''
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
from urllib import unquote
|
from polyglot.urllib import unquote
|
||||||
|
|
||||||
from calibre.ebooks.oeb.base import element
|
from calibre.ebooks.oeb.base import element
|
||||||
from calibre.utils.cleantext import clean_xml_chars
|
from calibre.utils.cleantext import clean_xml_chars
|
||||||
@ -86,7 +86,7 @@ class HTMLOutput(OutputFormatPlugin):
|
|||||||
from lxml import etree
|
from lxml import etree
|
||||||
from calibre.utils import zipfile
|
from calibre.utils import zipfile
|
||||||
from templite import Templite
|
from templite import Templite
|
||||||
from urllib import unquote
|
from polyglot.urllib import unquote
|
||||||
from calibre.ebooks.html.meta import EasyMeta
|
from calibre.ebooks.html.meta import EasyMeta
|
||||||
|
|
||||||
# read template files
|
# read template files
|
||||||
|
@ -21,7 +21,7 @@ class OEBOutput(OutputFormatPlugin):
|
|||||||
recommendations = {('pretty_print', True, OptionRecommendation.HIGH)}
|
recommendations = {('pretty_print', True, OptionRecommendation.HIGH)}
|
||||||
|
|
||||||
def convert(self, oeb_book, output_path, input_plugin, opts, log):
|
def convert(self, oeb_book, output_path, input_plugin, opts, log):
|
||||||
from urllib import unquote
|
from polyglot.urllib import unquote
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
|
|
||||||
self.log, self.opts = log, opts
|
self.log, self.opts = log, opts
|
||||||
|
@ -8,9 +8,9 @@ __copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
|
|
||||||
import posixpath, re
|
import posixpath, re
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
from urlparse import urlparse
|
|
||||||
|
|
||||||
from calibre.utils.filenames import ascii_text
|
from calibre.utils.filenames import ascii_text
|
||||||
|
from polyglot.urllib import urlparse
|
||||||
|
|
||||||
|
|
||||||
def start_text(tag, prefix_len=0, top_level=True):
|
def start_text(tag, prefix_len=0, top_level=True):
|
||||||
|
@ -13,13 +13,13 @@ Input plugin for HTML or OPF ebooks.
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
import os, re, sys, errno as gerrno
|
import os, re, sys, errno as gerrno
|
||||||
from urlparse import urlparse, urlunparse
|
|
||||||
|
|
||||||
from calibre.ebooks.oeb.base import urlunquote
|
from calibre.ebooks.oeb.base import urlunquote
|
||||||
from calibre.ebooks.chardet import detect_xml_encoding
|
from calibre.ebooks.chardet import detect_xml_encoding
|
||||||
from calibre.constants import iswindows
|
from calibre.constants import iswindows
|
||||||
from calibre import unicode_path, as_unicode, replace_entities
|
from calibre import unicode_path, as_unicode, replace_entities
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import unicode_type
|
||||||
|
from polyglot.urllib import urlparse, urlunparse
|
||||||
|
|
||||||
|
|
||||||
class Link(object):
|
class Link(object):
|
||||||
|
@ -15,7 +15,6 @@ import re
|
|||||||
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from lxml import html
|
from lxml import html
|
||||||
from urlparse import urldefrag
|
|
||||||
|
|
||||||
from calibre import prepare_string_for_xml
|
from calibre import prepare_string_for_xml
|
||||||
from calibre.ebooks.oeb.base import (
|
from calibre.ebooks.oeb.base import (
|
||||||
@ -23,6 +22,7 @@ from calibre.ebooks.oeb.base import (
|
|||||||
from calibre.ebooks.oeb.stylizer import Stylizer
|
from calibre.ebooks.oeb.stylizer import Stylizer
|
||||||
from calibre.utils.logging import default_log
|
from calibre.utils.logging import default_log
|
||||||
from polyglot.builtins import unicode_type, string_or_bytes
|
from polyglot.builtins import unicode_type, string_or_bytes
|
||||||
|
from polyglot.urllib import urldefrag
|
||||||
|
|
||||||
SELF_CLOSING_TAGS = {'area', 'base', 'basefont', 'br', 'hr', 'input', 'img', 'link', 'meta'}
|
SELF_CLOSING_TAGS = {'area', 'base', 'basefont', 'br', 'hr', 'input', 'img', 'link', 'meta'}
|
||||||
|
|
||||||
|
@ -9,8 +9,6 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net> ' \
|
|||||||
'and Marshall T. Vandegrift <llasram@gmail.com>'
|
'and Marshall T. Vandegrift <llasram@gmail.com>'
|
||||||
|
|
||||||
import io, struct, os, functools, re
|
import io, struct, os, functools, re
|
||||||
from urlparse import urldefrag
|
|
||||||
from urllib import unquote as urlunquote
|
|
||||||
|
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
|
|
||||||
@ -22,6 +20,7 @@ from calibre.ebooks.oeb.reader import OEBReader
|
|||||||
from calibre.ebooks import DRMError
|
from calibre.ebooks import DRMError
|
||||||
from calibre import plugins
|
from calibre import plugins
|
||||||
from polyglot.builtins import codepoint_to_chr, unicode_type, string_or_bytes, range
|
from polyglot.builtins import codepoint_to_chr, unicode_type, string_or_bytes, range
|
||||||
|
from polyglot.urllib import unquote as urlunquote, urldefrag
|
||||||
|
|
||||||
lzx, lxzerror = plugins['lzx']
|
lzx, lxzerror = plugins['lzx']
|
||||||
msdes, msdeserror = plugins['msdes']
|
msdes, msdeserror = plugins['msdes']
|
||||||
|
@ -17,8 +17,6 @@ import copy
|
|||||||
import uuid
|
import uuid
|
||||||
import functools
|
import functools
|
||||||
import numbers
|
import numbers
|
||||||
from urlparse import urldefrag
|
|
||||||
from urllib import unquote as urlunquote
|
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
from calibre.ebooks.lit.reader import DirectoryEntry
|
from calibre.ebooks.lit.reader import DirectoryEntry
|
||||||
import calibre.ebooks.lit.maps as maps
|
import calibre.ebooks.lit.maps as maps
|
||||||
@ -33,6 +31,7 @@ from calibre import plugins
|
|||||||
msdes, msdeserror = plugins['msdes']
|
msdes, msdeserror = plugins['msdes']
|
||||||
import calibre.ebooks.lit.mssha1 as mssha1
|
import calibre.ebooks.lit.mssha1 as mssha1
|
||||||
from polyglot.builtins import codepoint_to_chr, unicode_type, string_or_bytes, range
|
from polyglot.builtins import codepoint_to_chr, unicode_type, string_or_bytes, range
|
||||||
|
from polyglot.urllib import urldefrag, unquote
|
||||||
|
|
||||||
__all__ = ['LitWriter']
|
__all__ = ['LitWriter']
|
||||||
|
|
||||||
@ -521,7 +520,7 @@ class LitWriter(object):
|
|||||||
media_type = XHTML_MIME
|
media_type = XHTML_MIME
|
||||||
elif media_type in OEB_STYLES:
|
elif media_type in OEB_STYLES:
|
||||||
media_type = CSS_MIME
|
media_type = CSS_MIME
|
||||||
href = urlunquote(item.href)
|
href = unquote(item.href)
|
||||||
item.offset = offset \
|
item.offset = offset \
|
||||||
if state in ('linear', 'nonlinear') else 0
|
if state in ('linear', 'nonlinear') else 0
|
||||||
data.write(pack('<I', item.offset))
|
data.write(pack('<I', item.offset))
|
||||||
|
@ -9,8 +9,6 @@ and to Falstaff for pylrs.
|
|||||||
"""
|
"""
|
||||||
import os, re, sys, copy, glob, tempfile
|
import os, re, sys, copy, glob, tempfile
|
||||||
from collections import deque
|
from collections import deque
|
||||||
from urllib import unquote
|
|
||||||
from urlparse import urlparse
|
|
||||||
from math import ceil, floor
|
from math import ceil, floor
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
@ -37,6 +35,7 @@ from calibre.devices.interface import DevicePlugin as Device
|
|||||||
from calibre.ebooks.lrf.html.color_map import lrs_color
|
from calibre.ebooks.lrf.html.color_map import lrs_color
|
||||||
from calibre.ebooks.chardet import xml_to_unicode
|
from calibre.ebooks.chardet import xml_to_unicode
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import unicode_type
|
||||||
|
from polyglot.urllib import unquote, urlparse
|
||||||
|
|
||||||
|
|
||||||
def update_css(ncss, ocss):
|
def update_css(ncss, ocss):
|
||||||
|
@ -9,13 +9,11 @@ Provides abstraction for metadata reading.writing from a variety of ebook format
|
|||||||
"""
|
"""
|
||||||
import os, sys, re
|
import os, sys, re
|
||||||
|
|
||||||
from urlparse import urlparse
|
|
||||||
|
|
||||||
from calibre import relpath, guess_type, remove_bracketed_text, prints, force_unicode
|
from calibre import relpath, guess_type, remove_bracketed_text, prints, force_unicode
|
||||||
|
|
||||||
from calibre.utils.config_base import tweaks
|
from calibre.utils.config_base import tweaks
|
||||||
|
|
||||||
from polyglot.builtins import codepoint_to_chr, unicode_type
|
from polyglot.builtins import codepoint_to_chr, unicode_type
|
||||||
|
from polyglot.urllib import quote, unquote, urlparse
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
_author_pat = re.compile(tweaks['authors_split_regex'])
|
_author_pat = re.compile(tweaks['authors_split_regex'])
|
||||||
@ -205,7 +203,6 @@ class Resource(object):
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
def __init__(self, href_or_path, basedir=os.getcwdu(), is_path=True):
|
def __init__(self, href_or_path, basedir=os.getcwdu(), is_path=True):
|
||||||
from urllib import unquote
|
|
||||||
self._href = None
|
self._href = None
|
||||||
self._basedir = basedir
|
self._basedir = basedir
|
||||||
self.path = None
|
self.path = None
|
||||||
@ -243,7 +240,6 @@ class Resource(object):
|
|||||||
`basedir`: If None, the basedir of this resource is used (see :method:`set_basedir`).
|
`basedir`: If None, the basedir of this resource is used (see :method:`set_basedir`).
|
||||||
If this resource has no basedir, then the current working directory is used as the basedir.
|
If this resource has no basedir, then the current working directory is used as the basedir.
|
||||||
'''
|
'''
|
||||||
from urllib import quote
|
|
||||||
if basedir is None:
|
if basedir is None:
|
||||||
if self._basedir:
|
if self._basedir:
|
||||||
basedir = self._basedir
|
basedir = self._basedir
|
||||||
|
@ -6,7 +6,7 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import re, urllib, urlparse, socket
|
import re, socket
|
||||||
|
|
||||||
from mechanize import URLError
|
from mechanize import URLError
|
||||||
|
|
||||||
@ -15,6 +15,7 @@ from calibre import browser
|
|||||||
from calibre.ebooks.BeautifulSoup import BeautifulSoup
|
from calibre.ebooks.BeautifulSoup import BeautifulSoup
|
||||||
from calibre.ebooks.chardet import xml_to_unicode
|
from calibre.ebooks.chardet import xml_to_unicode
|
||||||
from polyglot.builtins import codepoint_to_chr, unicode_type
|
from polyglot.builtins import codepoint_to_chr, unicode_type
|
||||||
|
from polyglot.urllib import parse_qs, quote_plus
|
||||||
|
|
||||||
URL = \
|
URL = \
|
||||||
"http://ww2.kdl.org/libcat/WhatsNext.asp?AuthorLastName={0}&AuthorFirstName=&SeriesName=&BookTitle={1}&CategoryID=0&cmdSearch=Search&Search=1&grouping="
|
"http://ww2.kdl.org/libcat/WhatsNext.asp?AuthorLastName={0}&AuthorFirstName=&SeriesName=&BookTitle={1}&CategoryID=0&cmdSearch=Search&Search=1&grouping="
|
||||||
@ -32,7 +33,7 @@ def get_series(title, authors, timeout=60):
|
|||||||
if isinstance(title, unicode_type):
|
if isinstance(title, unicode_type):
|
||||||
title = title.encode('utf-8')
|
title = title.encode('utf-8')
|
||||||
|
|
||||||
title = urllib.quote_plus(title)
|
title = quote_plus(title)
|
||||||
|
|
||||||
author = authors[0].strip()
|
author = authors[0].strip()
|
||||||
if not author:
|
if not author:
|
||||||
@ -64,7 +65,7 @@ def get_series(title, authors, timeout=60):
|
|||||||
if a is None:
|
if a is None:
|
||||||
return mi
|
return mi
|
||||||
href = a['href'].partition('?')[-1]
|
href = a['href'].partition('?')[-1]
|
||||||
data = urlparse.parse_qs(href)
|
data = parse_qs(href)
|
||||||
series = data.get('SeriesName', [])
|
series = data.get('SeriesName', [])
|
||||||
if not series:
|
if not series:
|
||||||
return mi
|
return mi
|
||||||
|
@ -9,8 +9,6 @@ lxml based OPF parser.
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
import re, sys, unittest, functools, os, uuid, glob, io, json, copy
|
import re, sys, unittest, functools, os, uuid, glob, io, json, copy
|
||||||
from urllib import unquote
|
|
||||||
from urlparse import urlparse
|
|
||||||
|
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
|
|
||||||
@ -26,6 +24,7 @@ from calibre import prints, guess_type
|
|||||||
from calibre.utils.cleantext import clean_ascii_chars, clean_xml_chars
|
from calibre.utils.cleantext import clean_ascii_chars, clean_xml_chars
|
||||||
from calibre.utils.config import tweaks
|
from calibre.utils.config import tweaks
|
||||||
from polyglot.builtins import unicode_type, range
|
from polyglot.builtins import unicode_type, range
|
||||||
|
from polyglot.urllib import unquote, urlparse
|
||||||
|
|
||||||
pretty_print_opf = False
|
pretty_print_opf = False
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||||
|
|
||||||
from urllib import quote_plus
|
from polyglot.urllib import quote_plus
|
||||||
|
|
||||||
AUTHOR_SEARCHES = {
|
AUTHOR_SEARCHES = {
|
||||||
'goodreads':
|
'goodreads':
|
||||||
|
@ -21,6 +21,7 @@ from calibre.ebooks.metadata.sources.base import create_log
|
|||||||
from calibre.ebooks.metadata.sources.identify import identify
|
from calibre.ebooks.metadata.sources.identify import identify
|
||||||
from calibre.ebooks.metadata.sources.covers import download_cover
|
from calibre.ebooks.metadata.sources.covers import download_cover
|
||||||
from calibre.ebooks.metadata.sources.update import patch_plugins
|
from calibre.ebooks.metadata.sources.update import patch_plugins
|
||||||
|
from polyglot.builtins import unicode_type
|
||||||
|
|
||||||
|
|
||||||
def option_parser():
|
def option_parser():
|
||||||
@ -99,7 +100,7 @@ def main(args=sys.argv):
|
|||||||
log = buf.getvalue()
|
log = buf.getvalue()
|
||||||
|
|
||||||
result = (metadata_to_opf(result) if opts.opf else
|
result = (metadata_to_opf(result) if opts.opf else
|
||||||
type(u'')(result).encode('utf-8'))
|
unicode_type(result).encode('utf-8'))
|
||||||
|
|
||||||
if opts.verbose:
|
if opts.verbose:
|
||||||
print (log, file=sys.stderr)
|
print (log, file=sys.stderr)
|
||||||
|
@ -27,6 +27,7 @@ from calibre.utils.html2text import html2text
|
|||||||
from calibre.utils.icu import lower
|
from calibre.utils.icu import lower
|
||||||
from calibre.utils.date import UNDEFINED_DATE
|
from calibre.utils.date import UNDEFINED_DATE
|
||||||
from calibre.utils.formatter import EvalFormatter
|
from calibre.utils.formatter import EvalFormatter
|
||||||
|
from polyglot.builtins import unicode_type
|
||||||
|
|
||||||
# Download worker {{{
|
# Download worker {{{
|
||||||
|
|
||||||
@ -471,7 +472,7 @@ def identify(log, abort, # {{{
|
|||||||
for r in presults:
|
for r in presults:
|
||||||
log('\n\n---')
|
log('\n\n---')
|
||||||
try:
|
try:
|
||||||
log(type(u'')(r))
|
log(unicode_type(r))
|
||||||
except TypeError:
|
except TypeError:
|
||||||
log(repr(r))
|
log(repr(r))
|
||||||
if plog:
|
if plog:
|
||||||
|
@ -8,7 +8,6 @@ __copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
|
|||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import os, tempfile, time
|
import os, tempfile, time
|
||||||
from Queue import Queue, Empty
|
|
||||||
from threading import Event
|
from threading import Event
|
||||||
|
|
||||||
from calibre.customize.ui import all_metadata_plugins
|
from calibre.customize.ui import all_metadata_plugins
|
||||||
@ -16,6 +15,7 @@ from calibre import prints, sanitize_file_name2
|
|||||||
from calibre.ebooks.metadata import check_isbn
|
from calibre.ebooks.metadata import check_isbn
|
||||||
from calibre.ebooks.metadata.sources.base import create_log, get_cached_cover_urls
|
from calibre.ebooks.metadata.sources.base import create_log, get_cached_cover_urls
|
||||||
from calibre.ebooks.metadata.sources.prefs import msprefs
|
from calibre.ebooks.metadata.sources.prefs import msprefs
|
||||||
|
from polyglot.queue import Queue, Empty
|
||||||
|
|
||||||
|
|
||||||
def isbn_test(isbn):
|
def isbn_test(isbn):
|
||||||
|
@ -6,7 +6,6 @@ from __future__ import absolute_import, division, print_function, unicode_litera
|
|||||||
import os
|
import os
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from Queue import Empty, Queue
|
|
||||||
from threading import Event, Thread
|
from threading import Event, Thread
|
||||||
|
|
||||||
from calibre.customize.ui import metadata_plugins
|
from calibre.customize.ui import metadata_plugins
|
||||||
@ -18,6 +17,7 @@ from calibre.ebooks.metadata.sources.identify import identify, msprefs
|
|||||||
from calibre.ebooks.metadata.sources.update import patch_plugins
|
from calibre.ebooks.metadata.sources.update import patch_plugins
|
||||||
from calibre.utils.date import as_utc
|
from calibre.utils.date import as_utc
|
||||||
from calibre.utils.logging import GUILog
|
from calibre.utils.logging import GUILog
|
||||||
|
from polyglot.queue import Empty, Queue
|
||||||
|
|
||||||
|
|
||||||
def merge_result(oldmi, newmi, ensure_fields=None):
|
def merge_result(oldmi, newmi, ensure_fields=None):
|
||||||
|
@ -4,8 +4,6 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2010, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2010, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
|
|
||||||
import os, glob, re, functools
|
import os, glob, re, functools
|
||||||
from urlparse import urlparse
|
|
||||||
from urllib import unquote
|
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
|
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
@ -16,6 +14,7 @@ from calibre.ebooks.BeautifulSoup import BeautifulSoup
|
|||||||
from calibre.ebooks.chardet import xml_to_unicode
|
from calibre.ebooks.chardet import xml_to_unicode
|
||||||
from calibre.utils.cleantext import clean_xml_chars
|
from calibre.utils.cleantext import clean_xml_chars
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import unicode_type
|
||||||
|
from polyglot.urllib import unquote, urlparse
|
||||||
|
|
||||||
NCX_NS = "http://www.daisy.org/z3986/2005/ncx/"
|
NCX_NS = "http://www.daisy.org/z3986/2005/ncx/"
|
||||||
CALIBRE_NS = "http://calibre.kovidgoyal.net/2009/metadata"
|
CALIBRE_NS = "http://calibre.kovidgoyal.net/2009/metadata"
|
||||||
|
@ -10,7 +10,6 @@ __docformat__ = 'restructuredtext en'
|
|||||||
import struct, re, os
|
import struct, re, os
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from itertools import repeat, izip
|
from itertools import repeat, izip
|
||||||
from urlparse import urldefrag
|
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
@ -26,6 +25,7 @@ from calibre.ebooks.mobi.utils import read_font_record
|
|||||||
from calibre.ebooks.oeb.parse_utils import parse_html
|
from calibre.ebooks.oeb.parse_utils import parse_html
|
||||||
from calibre.ebooks.oeb.base import XPath, XHTML, xml2text
|
from calibre.ebooks.oeb.base import XPath, XHTML, xml2text
|
||||||
from polyglot.builtins import range
|
from polyglot.builtins import range
|
||||||
|
from polyglot.urllib import urldefrag
|
||||||
|
|
||||||
Part = namedtuple('Part',
|
Part = namedtuple('Part',
|
||||||
'num type filename start end aid')
|
'num type filename start end aid')
|
||||||
|
@ -11,7 +11,6 @@ import re
|
|||||||
import unicodedata
|
import unicodedata
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from urlparse import urldefrag
|
|
||||||
|
|
||||||
from calibre.ebooks.mobi.mobiml import MBP_NS
|
from calibre.ebooks.mobi.mobiml import MBP_NS
|
||||||
from calibre.ebooks.mobi.utils import is_guide_ref_start
|
from calibre.ebooks.mobi.utils import is_guide_ref_start
|
||||||
@ -19,6 +18,7 @@ from calibre.ebooks.oeb.base import (
|
|||||||
OEB_DOCS, XHTML, XHTML_NS, XML_NS, namespace, prefixname, urlnormalize
|
OEB_DOCS, XHTML, XHTML_NS, XML_NS, namespace, prefixname, urlnormalize
|
||||||
)
|
)
|
||||||
from polyglot.builtins import unicode_type, string_or_bytes
|
from polyglot.builtins import unicode_type, string_or_bytes
|
||||||
|
from polyglot.urllib import urldefrag
|
||||||
|
|
||||||
|
|
||||||
class Buf(BytesIO):
|
class Buf(BytesIO):
|
||||||
|
@ -9,8 +9,6 @@ __docformat__ = 'restructuredtext en'
|
|||||||
import os, re, logging
|
import os, re, logging
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from itertools import count
|
from itertools import count
|
||||||
from urlparse import urldefrag, urlparse, urlunparse, urljoin
|
|
||||||
from urllib import unquote
|
|
||||||
|
|
||||||
from lxml import etree, html
|
from lxml import etree, html
|
||||||
from calibre.constants import filesystem_encoding, __version__, ispy3
|
from calibre.constants import filesystem_encoding, __version__, ispy3
|
||||||
@ -23,6 +21,7 @@ from calibre.ebooks.oeb.parse_utils import (barename, XHTML_NS, RECOVER_PARSER,
|
|||||||
from calibre.utils.cleantext import clean_xml_chars
|
from calibre.utils.cleantext import clean_xml_chars
|
||||||
from calibre.utils.short_uuid import uuid4
|
from calibre.utils.short_uuid import uuid4
|
||||||
from polyglot.builtins import unicode_type, string_or_bytes, range
|
from polyglot.builtins import unicode_type, string_or_bytes, range
|
||||||
|
from polyglot.urllib import unquote, urldefrag, urljoin, urlparse, urlunparse
|
||||||
|
|
||||||
XML_NS = 'http://www.w3.org/XML/1998/namespace'
|
XML_NS = 'http://www.w3.org/XML/1998/namespace'
|
||||||
OEB_DOC_NS = 'http://openebook.org/namespaces/oeb-document/1.0/'
|
OEB_DOC_NS = 'http://openebook.org/namespaces/oeb-document/1.0/'
|
||||||
|
@ -8,9 +8,10 @@ __copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
|
|||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import os, shutil, tempfile
|
import os, shutil, tempfile
|
||||||
import SimpleHTTPServer
|
|
||||||
import SocketServer
|
import SocketServer
|
||||||
|
|
||||||
|
from polyglot.http_server import SimpleHTTPRequestHandler
|
||||||
|
|
||||||
|
|
||||||
def run_devel_server():
|
def run_devel_server():
|
||||||
base = os.path.dirname(os.path.abspath(__file__))
|
base = os.path.dirname(os.path.abspath(__file__))
|
||||||
@ -27,7 +28,7 @@ def run_devel_server():
|
|||||||
with lopen('cfi-test.pyj', 'rb') as f, lopen('cfi-test.js', 'wb') as js:
|
with lopen('cfi-test.pyj', 'rb') as f, lopen('cfi-test.js', 'wb') as js:
|
||||||
js.write(compile_pyj(f.read()).encode('utf-8'))
|
js.write(compile_pyj(f.read()).encode('utf-8'))
|
||||||
PORT = 8000
|
PORT = 8000
|
||||||
Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
|
Handler = SimpleHTTPRequestHandler
|
||||||
httpd = SocketServer.TCPServer(("", PORT), Handler)
|
httpd = SocketServer.TCPServer(("", PORT), Handler)
|
||||||
print('Serving CFI test at http://localhost:%d' % PORT)
|
print('Serving CFI test at http://localhost:%d' % PORT)
|
||||||
try:
|
try:
|
||||||
@ -37,4 +38,3 @@ def run_devel_server():
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
run_devel_server()
|
run_devel_server()
|
||||||
|
|
||||||
|
@ -8,10 +8,7 @@ __copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from urlparse import urlparse
|
|
||||||
from polyglot.builtins import map
|
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from Queue import Queue, Empty
|
|
||||||
|
|
||||||
from calibre import browser
|
from calibre import browser
|
||||||
from calibre.ebooks.oeb.base import OEB_DOCS, OEB_STYLES, urlunquote, XHTML_MIME
|
from calibre.ebooks.oeb.base import OEB_DOCS, OEB_STYLES, urlunquote, XHTML_MIME
|
||||||
@ -21,7 +18,9 @@ from calibre.ebooks.oeb.polish.replace import remove_links_to
|
|||||||
from calibre.ebooks.oeb.polish.cover import get_raster_cover_name
|
from calibre.ebooks.oeb.polish.cover import get_raster_cover_name
|
||||||
from calibre.ebooks.oeb.polish.utils import guess_type, actual_case_for_name, corrected_case_for_name
|
from calibre.ebooks.oeb.polish.utils import guess_type, actual_case_for_name, corrected_case_for_name
|
||||||
from calibre.ebooks.oeb.polish.check.base import BaseError, WARN, INFO
|
from calibre.ebooks.oeb.polish.check.base import BaseError, WARN, INFO
|
||||||
from polyglot.builtins import range
|
from polyglot.builtins import map, range
|
||||||
|
from polyglot.urllib import urlparse
|
||||||
|
from polyglot.queue import Queue, Empty
|
||||||
|
|
||||||
|
|
||||||
class BadLink(BaseError):
|
class BadLink(BaseError):
|
||||||
|
@ -17,7 +17,6 @@ from collections import defaultdict
|
|||||||
from polyglot.builtins import unicode_type, zip
|
from polyglot.builtins import unicode_type, zip
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from itertools import count
|
from itertools import count
|
||||||
from urlparse import urlparse
|
|
||||||
|
|
||||||
from css_parser import getUrls, replaceUrls
|
from css_parser import getUrls, replaceUrls
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
@ -55,6 +54,7 @@ from calibre.utils.filenames import hardlink_file, nlinks_file
|
|||||||
from calibre.utils.ipc.simple_worker import WorkerError, fork_job
|
from calibre.utils.ipc.simple_worker import WorkerError, fork_job
|
||||||
from calibre.utils.logging import default_log
|
from calibre.utils.logging import default_log
|
||||||
from calibre.utils.zipfile import ZipFile
|
from calibre.utils.zipfile import ZipFile
|
||||||
|
from polyglot.urllib import urlparse
|
||||||
|
|
||||||
exists, join, relpath = os.path.exists, os.path.join, os.path.relpath
|
exists, join, relpath = os.path.exists, os.path.join, os.path.relpath
|
||||||
|
|
||||||
|
@ -17,14 +17,13 @@ from functools import partial
|
|||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from multiprocessing.dummy import Pool
|
from multiprocessing.dummy import Pool
|
||||||
from tempfile import NamedTemporaryFile
|
from tempfile import NamedTemporaryFile
|
||||||
from urllib2 import urlopen
|
|
||||||
from urlparse import urlparse
|
|
||||||
|
|
||||||
from calibre import as_unicode, sanitize_file_name2
|
from calibre import as_unicode, sanitize_file_name2
|
||||||
from calibre.ebooks.oeb.base import OEB_DOCS, OEB_STYLES, barename, iterlinks
|
from calibre.ebooks.oeb.base import OEB_DOCS, OEB_STYLES, barename, iterlinks
|
||||||
from calibre.ebooks.oeb.polish.utils import guess_type
|
from calibre.ebooks.oeb.polish.utils import guess_type
|
||||||
from calibre.ptempfile import TemporaryDirectory
|
from calibre.ptempfile import TemporaryDirectory
|
||||||
from calibre.web import get_download_filename_from_response
|
from calibre.web import get_download_filename_from_response
|
||||||
|
from polyglot.urllib import urlopen, urlparse
|
||||||
|
|
||||||
|
|
||||||
def is_external(url):
|
def is_external(url):
|
||||||
|
@ -7,10 +7,10 @@ from __future__ import (unicode_literals, division, absolute_import,
|
|||||||
import os
|
import os
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from threading import Thread, Event
|
from threading import Thread, Event
|
||||||
from Queue import Queue, Empty
|
|
||||||
|
|
||||||
from calibre import detect_ncpus, human_readable, force_unicode, filesystem_encoding
|
from calibre import detect_ncpus, human_readable, force_unicode, filesystem_encoding
|
||||||
from polyglot.builtins import range
|
from polyglot.builtins import range
|
||||||
|
from polyglot.queue import Queue, Empty
|
||||||
|
|
||||||
|
|
||||||
class Worker(Thread):
|
class Worker(Thread):
|
||||||
|
@ -10,13 +10,13 @@ __docformat__ = 'restructuredtext en'
|
|||||||
import codecs, shutil, os, posixpath
|
import codecs, shutil, os, posixpath
|
||||||
from polyglot.builtins import map
|
from polyglot.builtins import map
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from urlparse import urlparse, urlunparse
|
|
||||||
from collections import Counter, defaultdict
|
from collections import Counter, defaultdict
|
||||||
|
|
||||||
from calibre import sanitize_file_name_unicode
|
from calibre import sanitize_file_name_unicode
|
||||||
from calibre.ebooks.chardet import strip_encoding_declarations
|
from calibre.ebooks.chardet import strip_encoding_declarations
|
||||||
from calibre.ebooks.oeb.polish.css import iter_declarations, remove_property_value
|
from calibre.ebooks.oeb.polish.css import iter_declarations, remove_property_value
|
||||||
from calibre.ebooks.oeb.polish.utils import extract
|
from calibre.ebooks.oeb.polish.utils import extract
|
||||||
|
from polyglot.urllib import urlparse, urlunparse
|
||||||
|
|
||||||
|
|
||||||
class LinkReplacer(object):
|
class LinkReplacer(object):
|
||||||
|
@ -8,12 +8,12 @@ __copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
|
|
||||||
import copy, os, re
|
import copy, os, re
|
||||||
from polyglot.builtins import map, string_or_bytes, range
|
from polyglot.builtins import map, string_or_bytes, range
|
||||||
from urlparse import urlparse
|
|
||||||
|
|
||||||
from calibre.ebooks.oeb.base import barename, XPNSMAP, XPath, OPF, XHTML, OEB_DOCS
|
from calibre.ebooks.oeb.base import barename, XPNSMAP, XPath, OPF, XHTML, OEB_DOCS
|
||||||
from calibre.ebooks.oeb.polish.errors import MalformedMarkup
|
from calibre.ebooks.oeb.polish.errors import MalformedMarkup
|
||||||
from calibre.ebooks.oeb.polish.toc import node_from_loc
|
from calibre.ebooks.oeb.polish.toc import node_from_loc
|
||||||
from calibre.ebooks.oeb.polish.replace import LinkRebaser
|
from calibre.ebooks.oeb.polish.replace import LinkRebaser
|
||||||
|
from polyglot.urllib import urlparse
|
||||||
|
|
||||||
|
|
||||||
class AbortError(ValueError):
|
class AbortError(ValueError):
|
||||||
|
@ -8,7 +8,6 @@ __copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import re
|
import re
|
||||||
from urlparse import urlparse
|
|
||||||
from collections import Counter, OrderedDict
|
from collections import Counter, OrderedDict
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from polyglot.builtins import map, unicode_type
|
from polyglot.builtins import map, unicode_type
|
||||||
@ -26,6 +25,7 @@ from calibre.ebooks.oeb.polish.opf import set_guide_item, get_book_language
|
|||||||
from calibre.ebooks.oeb.polish.pretty import pretty_html_tree
|
from calibre.ebooks.oeb.polish.pretty import pretty_html_tree
|
||||||
from calibre.translations.dynamic import translate
|
from calibre.translations.dynamic import translate
|
||||||
from calibre.utils.localization import get_lang, canonicalize_lang, lang_as_iso639_1
|
from calibre.utils.localization import get_lang, canonicalize_lang, lang_as_iso639_1
|
||||||
|
from polyglot.urllib import urlparse
|
||||||
|
|
||||||
ns = etree.FunctionNamespace('calibre_xpath_extensions')
|
ns = etree.FunctionNamespace('calibre_xpath_extensions')
|
||||||
ns.prefix = 'calibre'
|
ns.prefix = 'calibre'
|
||||||
|
@ -9,8 +9,6 @@ __copyright__ = '2008, Marshall T. Vandegrift <llasram@gmail.com>'
|
|||||||
|
|
||||||
import sys, os, uuid, copy, re, io
|
import sys, os, uuid, copy, re, io
|
||||||
from itertools import izip
|
from itertools import izip
|
||||||
from urlparse import urldefrag, urlparse
|
|
||||||
from urllib import unquote as urlunquote
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
@ -31,6 +29,7 @@ from calibre.ptempfile import TemporaryDirectory
|
|||||||
from calibre.constants import __appname__, __version__
|
from calibre.constants import __appname__, __version__
|
||||||
from calibre import guess_type, xml_replace_entities
|
from calibre import guess_type, xml_replace_entities
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import unicode_type
|
||||||
|
from polyglot.urllib import unquote, urldefrag, urlparse
|
||||||
|
|
||||||
__all__ = ['OEBReader']
|
__all__ = ['OEBReader']
|
||||||
|
|
||||||
@ -632,7 +631,7 @@ class OEBReader(object):
|
|||||||
with TemporaryDirectory('_html_cover') as tdir:
|
with TemporaryDirectory('_html_cover') as tdir:
|
||||||
writer = OEBWriter()
|
writer = OEBWriter()
|
||||||
writer(self.oeb, tdir)
|
writer(self.oeb, tdir)
|
||||||
path = os.path.join(tdir, urlunquote(hcover.href))
|
path = os.path.join(tdir, unquote(hcover.href))
|
||||||
data = render_html_svg_workaround(path, self.logger)
|
data = render_html_svg_workaround(path, self.logger)
|
||||||
if not data:
|
if not data:
|
||||||
data = ''
|
data = ''
|
||||||
|
@ -6,12 +6,12 @@ __copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
|||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import textwrap
|
import textwrap
|
||||||
from urllib import unquote
|
|
||||||
|
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
from calibre import guess_type
|
from calibre import guess_type
|
||||||
from calibre.utils.imghdr import identify
|
from calibre.utils.imghdr import identify
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import unicode_type
|
||||||
|
from polyglot.urllib import unquote
|
||||||
|
|
||||||
|
|
||||||
class CoverManager(object):
|
class CoverManager(object):
|
||||||
|
@ -6,11 +6,11 @@ __copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
|||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import posixpath
|
import posixpath
|
||||||
from urlparse import urldefrag, urlparse
|
|
||||||
|
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
|
|
||||||
from calibre.ebooks.oeb.base import rewrite_links, urlnormalize
|
from calibre.ebooks.oeb.base import rewrite_links, urlnormalize
|
||||||
|
from polyglot.urllib import urldefrag, urlparse
|
||||||
|
|
||||||
|
|
||||||
class RenameFiles(object): # {{{
|
class RenameFiles(object): # {{{
|
||||||
|
@ -7,7 +7,6 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2008, Marshall T. Vandegrift <llasram@gmail.com>'
|
__copyright__ = '2008, Marshall T. Vandegrift <llasram@gmail.com>'
|
||||||
|
|
||||||
import os, re
|
import os, re
|
||||||
from urlparse import urldefrag
|
|
||||||
|
|
||||||
from PyQt5.Qt import (
|
from PyQt5.Qt import (
|
||||||
Qt, QByteArray, QBuffer, QIODevice, QColor, QImage, QPainter, QSvgRenderer)
|
Qt, QByteArray, QBuffer, QIODevice, QColor, QImage, QPainter, QSvgRenderer)
|
||||||
@ -19,6 +18,7 @@ from calibre.ebooks.oeb.stylizer import Stylizer
|
|||||||
from calibre.ptempfile import PersistentTemporaryFile
|
from calibre.ptempfile import PersistentTemporaryFile
|
||||||
from calibre.utils.imghdr import what
|
from calibre.utils.imghdr import what
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import unicode_type
|
||||||
|
from polyglot.urllib import urldefrag
|
||||||
|
|
||||||
IMAGE_TAGS = {XHTML('img'), XHTML('object')}
|
IMAGE_TAGS = {XHTML('img'), XHTML('object')}
|
||||||
KEEP_ATTRS = {'class', 'style', 'width', 'height', 'align'}
|
KEEP_ATTRS = {'class', 'style', 'width', 'height', 'align'}
|
||||||
|
@ -9,12 +9,12 @@ __docformat__ = 'restructuredtext en'
|
|||||||
import re, uuid
|
import re, uuid
|
||||||
|
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
from urlparse import urlparse
|
|
||||||
from collections import OrderedDict, Counter
|
from collections import OrderedDict, Counter
|
||||||
|
|
||||||
from calibre.ebooks.oeb.base import XPNSMAP, TOC, XHTML, xml2text, barename
|
from calibre.ebooks.oeb.base import XPNSMAP, TOC, XHTML, xml2text, barename
|
||||||
from calibre.ebooks import ConversionError
|
from calibre.ebooks import ConversionError
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import unicode_type
|
||||||
|
from polyglot.urllib import urlparse
|
||||||
|
|
||||||
|
|
||||||
def XPath(x):
|
def XPath(x):
|
||||||
|
@ -6,10 +6,9 @@ from __future__ import with_statement
|
|||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2008, Marshall T. Vandegrift <llasram@gmail.com>'
|
__copyright__ = '2008, Marshall T. Vandegrift <llasram@gmail.com>'
|
||||||
|
|
||||||
from urlparse import urldefrag
|
|
||||||
|
|
||||||
from calibre.ebooks.oeb.base import CSS_MIME, OEB_DOCS
|
from calibre.ebooks.oeb.base import CSS_MIME, OEB_DOCS
|
||||||
from calibre.ebooks.oeb.base import urlnormalize, iterlinks
|
from calibre.ebooks.oeb.base import urlnormalize, iterlinks
|
||||||
|
from polyglot.urllib import urldefrag
|
||||||
|
|
||||||
|
|
||||||
class ManifestTrimmer(object):
|
class ManifestTrimmer(object):
|
||||||
|
@ -8,10 +8,9 @@ __copyright__ = '2012, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from urlparse import urlparse
|
|
||||||
from urllib2 import unquote
|
|
||||||
|
|
||||||
from calibre.ebooks.pdf.render.common import Array, Name, Dictionary, String, UTF16String, current_log
|
from calibre.ebooks.pdf.render.common import Array, Name, Dictionary, String, UTF16String, current_log
|
||||||
|
from polyglot.urllib import unquote, urlparse
|
||||||
|
|
||||||
|
|
||||||
class Destination(Array):
|
class Destination(Array):
|
||||||
|
@ -7,7 +7,6 @@ __docformat__ = 'restructuredtext en'
|
|||||||
import os
|
import os
|
||||||
import struct
|
import struct
|
||||||
import zlib
|
import zlib
|
||||||
from urllib import unquote as urlunquote
|
|
||||||
|
|
||||||
from calibre import CurrentDir
|
from calibre import CurrentDir
|
||||||
from calibre.ebooks.rb import HEADER
|
from calibre.ebooks.rb import HEADER
|
||||||
@ -15,6 +14,7 @@ from calibre.ebooks.rb import RocketBookError
|
|||||||
from calibre.ebooks.metadata.rb import get_metadata
|
from calibre.ebooks.metadata.rb import get_metadata
|
||||||
from calibre.ebooks.metadata.opf2 import OPFCreator
|
from calibre.ebooks.metadata.opf2 import OPFCreator
|
||||||
from polyglot.builtins import range
|
from polyglot.builtins import range
|
||||||
|
from polyglot.urllib import unquote
|
||||||
|
|
||||||
|
|
||||||
class RBToc(list):
|
class RBToc(list):
|
||||||
@ -64,7 +64,7 @@ class Reader(object):
|
|||||||
|
|
||||||
toc = RBToc()
|
toc = RBToc()
|
||||||
for i in range(pages):
|
for i in range(pages):
|
||||||
name = urlunquote(self.stream.read(32).strip('\x00'))
|
name = unquote(self.stream.read(32).strip('\x00'))
|
||||||
size, offset, flags = self.read_i32(), self.read_i32(), self.read_i32()
|
size, offset, flags = self.read_i32(), self.read_i32(), self.read_i32()
|
||||||
toc.append(RBToc.Item(name=name, size=size, offset=offset, flags=flags))
|
toc.append(RBToc.Item(name=name, size=size, offset=offset, flags=flags))
|
||||||
|
|
||||||
|
@ -62,9 +62,9 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||||||
|
|
||||||
import re
|
import re
|
||||||
import uuid
|
import uuid
|
||||||
from urlparse import urlparse
|
|
||||||
|
|
||||||
from calibre.utils.smartypants import smartyPants
|
from calibre.utils.smartypants import smartyPants
|
||||||
|
from polyglot.urllib import urlopen, urlparse
|
||||||
|
|
||||||
|
|
||||||
def _normalize_newlines(string):
|
def _normalize_newlines(string):
|
||||||
@ -95,14 +95,9 @@ def getimagesize(url):
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
try:
|
|
||||||
import urllib2
|
|
||||||
except ImportError:
|
|
||||||
return None
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
p = ImageFile.Parser()
|
p = ImageFile.Parser()
|
||||||
f = urllib2.urlopen(url)
|
f = urlopen(url)
|
||||||
while True:
|
while True:
|
||||||
s = f.read(1024)
|
s = f.read(1024)
|
||||||
if not s:
|
if not s:
|
||||||
|
@ -3,7 +3,6 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
""" The GUI """
|
""" The GUI """
|
||||||
import glob
|
import glob
|
||||||
import os
|
import os
|
||||||
import Queue
|
|
||||||
import signal
|
import signal
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
@ -36,6 +35,7 @@ from calibre.utils.date import UNDEFINED_DATE
|
|||||||
from calibre.utils.file_type_icons import EXT_MAP
|
from calibre.utils.file_type_icons import EXT_MAP
|
||||||
from calibre.utils.localization import get_lang
|
from calibre.utils.localization import get_lang
|
||||||
from polyglot.builtins import unicode_type, string_or_bytes, range
|
from polyglot.builtins import unicode_type, string_or_bytes, range
|
||||||
|
from polyglot import queue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
NO_URL_FORMATTING = QUrl.None_
|
NO_URL_FORMATTING = QUrl.None_
|
||||||
@ -502,7 +502,7 @@ class FunctionDispatcher(QObject):
|
|||||||
if not queued:
|
if not queued:
|
||||||
typ = Qt.AutoConnection if queued is None else Qt.DirectConnection
|
typ = Qt.AutoConnection if queued is None else Qt.DirectConnection
|
||||||
self.dispatch_signal.connect(self.dispatch, type=typ)
|
self.dispatch_signal.connect(self.dispatch, type=typ)
|
||||||
self.q = Queue.Queue()
|
self.q = queue.Queue()
|
||||||
self.lock = threading.Lock()
|
self.lock = threading.Lock()
|
||||||
|
|
||||||
def __call__(self, *args, **kwargs):
|
def __call__(self, *args, **kwargs):
|
||||||
|
@ -9,7 +9,6 @@ __copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
import shutil, os, weakref, traceback, tempfile, time
|
import shutil, os, weakref, traceback, tempfile, time
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from Queue import Empty
|
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from polyglot.builtins import map, unicode_type, string_or_bytes
|
from polyglot.builtins import map, unicode_type, string_or_bytes
|
||||||
|
|
||||||
@ -30,6 +29,7 @@ from calibre.ptempfile import PersistentTemporaryDirectory
|
|||||||
from calibre.utils import join_with_timeout
|
from calibre.utils import join_with_timeout
|
||||||
from calibre.utils.config import prefs
|
from calibre.utils.config import prefs
|
||||||
from calibre.utils.ipc.pool import Pool, Failure
|
from calibre.utils.ipc.pool import Pool, Failure
|
||||||
|
from polyglot.queue import Empty
|
||||||
|
|
||||||
|
|
||||||
def validate_source(source, parent=None): # {{{
|
def validate_source(source, parent=None): # {{{
|
||||||
|
@ -3,7 +3,7 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
|
|
||||||
# Imports {{{
|
# Imports {{{
|
||||||
import os, traceback, Queue, time, io, re, sys, weakref
|
import os, traceback, time, io, re, sys, weakref
|
||||||
from threading import Thread, Event
|
from threading import Thread, Event
|
||||||
|
|
||||||
from PyQt5.Qt import (
|
from PyQt5.Qt import (
|
||||||
@ -35,6 +35,7 @@ from calibre.utils.img import scale_image
|
|||||||
from calibre.library.save_to_disk import find_plugboard
|
from calibre.library.save_to_disk import find_plugboard
|
||||||
from calibre.ptempfile import PersistentTemporaryFile, force_unicode as filename_to_unicode
|
from calibre.ptempfile import PersistentTemporaryFile, force_unicode as filename_to_unicode
|
||||||
from polyglot.builtins import unicode_type, string_or_bytes
|
from polyglot.builtins import unicode_type, string_or_bytes
|
||||||
|
from polyglot import queue
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
|
||||||
@ -153,8 +154,8 @@ class DeviceManager(Thread): # {{{
|
|||||||
self.sleep_time = sleep_time
|
self.sleep_time = sleep_time
|
||||||
self.connected_slot = connected_slot
|
self.connected_slot = connected_slot
|
||||||
self.allow_connect_slot = allow_connect_slot
|
self.allow_connect_slot = allow_connect_slot
|
||||||
self.jobs = Queue.Queue(0)
|
self.jobs = queue.Queue(0)
|
||||||
self.job_steps = Queue.Queue(0)
|
self.job_steps = queue.Queue(0)
|
||||||
self.keep_going = True
|
self.keep_going = True
|
||||||
self.job_manager = job_manager
|
self.job_manager = job_manager
|
||||||
self.reported_errors = set([])
|
self.reported_errors = set([])
|
||||||
@ -163,7 +164,7 @@ class DeviceManager(Thread): # {{{
|
|||||||
self.connected_device = None
|
self.connected_device = None
|
||||||
self.connected_device_kind = None
|
self.connected_device_kind = None
|
||||||
self.ejected_devices = set([])
|
self.ejected_devices = set([])
|
||||||
self.mount_connection_requests = Queue.Queue(0)
|
self.mount_connection_requests = queue.Queue(0)
|
||||||
self.open_feedback_slot = open_feedback_slot
|
self.open_feedback_slot = open_feedback_slot
|
||||||
self.open_feedback_only_once_seen = set()
|
self.open_feedback_only_once_seen = set()
|
||||||
self.after_callback_feedback_slot = after_callback_feedback_slot
|
self.after_callback_feedback_slot = after_callback_feedback_slot
|
||||||
@ -241,7 +242,7 @@ class DeviceManager(Thread): # {{{
|
|||||||
try:
|
try:
|
||||||
job = self.jobs.get_nowait()
|
job = self.jobs.get_nowait()
|
||||||
job.abort(Exception(_('Device no longer connected.')))
|
job.abort(Exception(_('Device no longer connected.')))
|
||||||
except Queue.Empty:
|
except queue.Empty:
|
||||||
break
|
break
|
||||||
try:
|
try:
|
||||||
self.connected_device.post_yank_cleanup()
|
self.connected_device.post_yank_cleanup()
|
||||||
@ -358,13 +359,13 @@ class DeviceManager(Thread): # {{{
|
|||||||
if not self.job_steps.empty():
|
if not self.job_steps.empty():
|
||||||
try:
|
try:
|
||||||
return self.job_steps.get_nowait()
|
return self.job_steps.get_nowait()
|
||||||
except Queue.Empty:
|
except queue.Empty:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if not self.jobs.empty():
|
if not self.jobs.empty():
|
||||||
try:
|
try:
|
||||||
return self.jobs.get_nowait()
|
return self.jobs.get_nowait()
|
||||||
except Queue.Empty:
|
except queue.Empty:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def run_startup(self, dev):
|
def run_startup(self, dev):
|
||||||
@ -391,7 +392,7 @@ class DeviceManager(Thread): # {{{
|
|||||||
try:
|
try:
|
||||||
(kls,device_kind, folder_path) = \
|
(kls,device_kind, folder_path) = \
|
||||||
self.mount_connection_requests.get_nowait()
|
self.mount_connection_requests.get_nowait()
|
||||||
except Queue.Empty:
|
except queue.Empty:
|
||||||
break
|
break
|
||||||
if kls is not None:
|
if kls is not None:
|
||||||
try:
|
try:
|
||||||
|
@ -7,10 +7,8 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import posixpath, os, urllib, re
|
import posixpath, os, re
|
||||||
from urlparse import urlparse
|
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from Queue import Queue, Empty
|
|
||||||
|
|
||||||
from PyQt5.Qt import QPixmap, Qt, QDialog, QLabel, QVBoxLayout, \
|
from PyQt5.Qt import QPixmap, Qt, QDialog, QLabel, QVBoxLayout, \
|
||||||
QDialogButtonBox, QProgressBar, QTimer, QUrl, QImageReader
|
QDialogButtonBox, QProgressBar, QTimer, QUrl, QImageReader
|
||||||
@ -21,6 +19,8 @@ from calibre import browser, as_unicode, prints
|
|||||||
from calibre.gui2 import error_dialog
|
from calibre.gui2 import error_dialog
|
||||||
from calibre.utils.imghdr import what
|
from calibre.utils.imghdr import what
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import unicode_type
|
||||||
|
from polyglot.urllib import unquote, urlparse
|
||||||
|
from polyglot.queue import Queue, Empty
|
||||||
|
|
||||||
|
|
||||||
def image_extensions():
|
def image_extensions():
|
||||||
@ -162,7 +162,7 @@ def path_from_qurl(qurl):
|
|||||||
raw = bytes(qurl.toEncoded(
|
raw = bytes(qurl.toEncoded(
|
||||||
QUrl.PreferLocalFile | QUrl.RemoveScheme | QUrl.RemovePassword | QUrl.RemoveUserInfo |
|
QUrl.PreferLocalFile | QUrl.RemoveScheme | QUrl.RemovePassword | QUrl.RemoveUserInfo |
|
||||||
QUrl.RemovePort | QUrl.RemoveAuthority | QUrl.RemoveQuery | QUrl.RemoveFragment))
|
QUrl.RemovePort | QUrl.RemoveAuthority | QUrl.RemoveQuery | QUrl.RemoveFragment))
|
||||||
ans = urllib.unquote(raw).decode('utf-8', 'replace')
|
ans = unquote(raw).decode('utf-8', 'replace')
|
||||||
if iswindows and ans.startswith('/'):
|
if iswindows and ans.startswith('/'):
|
||||||
ans = ans[1:]
|
ans = ans[1:]
|
||||||
return ans
|
return ans
|
||||||
@ -232,7 +232,7 @@ def dnd_get_image(md, image_exts=None):
|
|||||||
paths = [path_from_qurl(u) for u in urls]
|
paths = [path_from_qurl(u) for u in urls]
|
||||||
# First look for a local file
|
# First look for a local file
|
||||||
images = [xi for xi in paths if
|
images = [xi for xi in paths if
|
||||||
posixpath.splitext(urllib.unquote(xi))[1][1:].lower() in
|
posixpath.splitext(unquote(xi))[1][1:].lower() in
|
||||||
image_exts]
|
image_exts]
|
||||||
images = [xi for xi in images if os.path.exists(xi)]
|
images = [xi for xi in images if os.path.exists(xi)]
|
||||||
p = QPixmap()
|
p = QPixmap()
|
||||||
@ -278,7 +278,7 @@ def dnd_get_files(md, exts, allow_all_extensions=False, filter_exts=()):
|
|||||||
if allow_all_extensions and ext and ext not in filter_exts:
|
if allow_all_extensions and ext and ext not in filter_exts:
|
||||||
return True
|
return True
|
||||||
return ext in exts and ext not in filter_exts
|
return ext in exts and ext not in filter_exts
|
||||||
local_files = [p for p in local_files if is_ok(urllib.unquote(p))]
|
local_files = [p for p in local_files if is_ok(unquote(p))]
|
||||||
local_files = [x for x in local_files if os.path.exists(x)]
|
local_files = [x for x in local_files if os.path.exists(x)]
|
||||||
if local_files:
|
if local_files:
|
||||||
return local_files, None
|
return local_files, None
|
||||||
|
@ -10,7 +10,6 @@ import os, errno, json, importlib, math, httplib, bz2, shutil, sys
|
|||||||
from itertools import count
|
from itertools import count
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from polyglot.builtins import map
|
from polyglot.builtins import map
|
||||||
from Queue import Queue, Empty
|
|
||||||
from threading import Thread, Event
|
from threading import Thread, Event
|
||||||
from multiprocessing.pool import ThreadPool
|
from multiprocessing.pool import ThreadPool
|
||||||
|
|
||||||
@ -39,6 +38,7 @@ from calibre.utils.img import image_from_data, Canvas, optimize_png, optimize_jp
|
|||||||
from calibre.utils.zipfile import ZipFile, ZIP_STORED
|
from calibre.utils.zipfile import ZipFile, ZIP_STORED
|
||||||
from calibre.utils.filenames import atomic_rename
|
from calibre.utils.filenames import atomic_rename
|
||||||
from lzma.xz import compress, decompress
|
from lzma.xz import compress, decompress
|
||||||
|
from polyglot.queue import Queue, Empty
|
||||||
|
|
||||||
IMAGE_EXTENSIONS = {'png', 'jpg', 'jpeg'}
|
IMAGE_EXTENSIONS = {'png', 'jpg', 'jpeg'}
|
||||||
THEME_COVER = 'icon-theme-cover.jpg'
|
THEME_COVER = 'icon-theme-cover.jpg'
|
||||||
|
@ -8,7 +8,6 @@ Job management.
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
import re, time
|
import re, time
|
||||||
from Queue import Empty, Queue
|
|
||||||
|
|
||||||
from PyQt5.Qt import (QAbstractTableModel, QModelIndex, Qt, QPainter,
|
from PyQt5.Qt import (QAbstractTableModel, QModelIndex, Qt, QPainter,
|
||||||
QTimer, pyqtSignal, QIcon, QDialog, QAbstractItemDelegate, QApplication,
|
QTimer, pyqtSignal, QIcon, QDialog, QAbstractItemDelegate, QApplication,
|
||||||
@ -31,6 +30,7 @@ from calibre.gui2.widgets2 import Dialog
|
|||||||
from calibre.utils.search_query_parser import SearchQueryParser, ParseException
|
from calibre.utils.search_query_parser import SearchQueryParser, ParseException
|
||||||
from calibre.utils.icu import lower
|
from calibre.utils.icu import lower
|
||||||
from polyglot.builtins import unicode_type, range
|
from polyglot.builtins import unicode_type, range
|
||||||
|
from polyglot.queue import Empty, Queue
|
||||||
|
|
||||||
|
|
||||||
class AdaptSQP(SearchQueryParser):
|
class AdaptSQP(SearchQueryParser):
|
||||||
|
@ -9,7 +9,6 @@ __copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
import itertools, operator, os, math
|
import itertools, operator, os, math
|
||||||
from types import MethodType
|
from types import MethodType
|
||||||
from threading import Event, Thread
|
from threading import Event, Thread
|
||||||
from Queue import LifoQueue
|
|
||||||
from functools import wraps, partial
|
from functools import wraps, partial
|
||||||
from textwrap import wrap
|
from textwrap import wrap
|
||||||
|
|
||||||
@ -31,6 +30,7 @@ from calibre.gui2.gestures import GestureManager
|
|||||||
from calibre.gui2.library.caches import CoverCache, ThumbnailCache
|
from calibre.gui2.library.caches import CoverCache, ThumbnailCache
|
||||||
from calibre.utils.config import prefs, tweaks
|
from calibre.utils.config import prefs, tweaks
|
||||||
from polyglot.builtins import unicode_type, range
|
from polyglot.builtins import unicode_type, range
|
||||||
|
from polyglot.queue import LifoQueue
|
||||||
|
|
||||||
CM_TO_INCH = 0.393701
|
CM_TO_INCH = 0.393701
|
||||||
CACHE_FORMAT = 'PPM'
|
CACHE_FORMAT = 'PPM'
|
||||||
|
@ -13,7 +13,6 @@ DEBUG_DIALOG = False
|
|||||||
import os, time
|
import os, time
|
||||||
from threading import Thread, Event
|
from threading import Thread, Event
|
||||||
from operator import attrgetter
|
from operator import attrgetter
|
||||||
from Queue import Queue, Empty
|
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
from PyQt5.Qt import (
|
from PyQt5.Qt import (
|
||||||
@ -41,6 +40,7 @@ from calibre.utils.config import tweaks
|
|||||||
from calibre.utils.ipc.simple_worker import fork_job, WorkerError
|
from calibre.utils.ipc.simple_worker import fork_job, WorkerError
|
||||||
from calibre.ptempfile import TemporaryDirectory
|
from calibre.ptempfile import TemporaryDirectory
|
||||||
from polyglot.builtins import unicode_type, range
|
from polyglot.builtins import unicode_type, range
|
||||||
|
from polyglot.queue import Queue, Empty
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,13 +5,13 @@
|
|||||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from urllib import unquote
|
|
||||||
|
|
||||||
from PyQt5.Qt import QFileDialog, QObject
|
from PyQt5.Qt import QFileDialog, QObject
|
||||||
|
|
||||||
from calibre.gui2.linux_file_dialogs import dialog_name, image_extensions
|
from calibre.gui2.linux_file_dialogs import dialog_name, image_extensions
|
||||||
from calibre.utils.filenames import expanduser
|
from calibre.utils.filenames import expanduser
|
||||||
from polyglot.builtins import unicode_type, string_or_bytes
|
from polyglot.builtins import unicode_type, string_or_bytes
|
||||||
|
from polyglot.urllib import unquote
|
||||||
|
|
||||||
|
|
||||||
def select_initial_dir(q):
|
def select_initial_dir(q):
|
||||||
|
@ -9,7 +9,6 @@ __copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
import traceback, errno, os, time, shutil
|
import traceback, errno, os, time, shutil
|
||||||
from collections import namedtuple, defaultdict
|
from collections import namedtuple, defaultdict
|
||||||
from tempfile import SpooledTemporaryFile
|
from tempfile import SpooledTemporaryFile
|
||||||
from Queue import Empty
|
|
||||||
|
|
||||||
from PyQt5.Qt import QObject, Qt, pyqtSignal
|
from PyQt5.Qt import QObject, Qt, pyqtSignal
|
||||||
|
|
||||||
@ -26,6 +25,7 @@ from calibre.utils.formatter_functions import load_user_template_functions
|
|||||||
from calibre.utils.ipc.pool import Pool, Failure
|
from calibre.utils.ipc.pool import Pool, Failure
|
||||||
from calibre.library.save_to_disk import sanitize_args, get_path_components, find_plugboard, plugboard_save_to_disk_value
|
from calibre.library.save_to_disk import sanitize_args, get_path_components, find_plugboard, plugboard_save_to_disk_value
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import unicode_type
|
||||||
|
from polyglot.queue import Empty
|
||||||
|
|
||||||
BookId = namedtuple('BookId', 'title authors')
|
BookId = namedtuple('BookId', 'title authors')
|
||||||
|
|
||||||
|
@ -11,12 +11,12 @@ import sys, time, io, re
|
|||||||
from zlib import decompressobj
|
from zlib import decompressobj
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from urllib import urlencode
|
|
||||||
|
|
||||||
from calibre import prints
|
from calibre import prints
|
||||||
from calibre.constants import numeric_version, DEBUG
|
from calibre.constants import numeric_version, DEBUG
|
||||||
from calibre.gui2.store import StorePlugin
|
from calibre.gui2.store import StorePlugin
|
||||||
from calibre.utils.config import JSONConfig
|
from calibre.utils.config import JSONConfig
|
||||||
|
from polyglot.urllib import urlencode
|
||||||
|
|
||||||
|
|
||||||
class VersionMismatch(ValueError):
|
class VersionMismatch(ValueError):
|
||||||
|
@ -9,12 +9,12 @@ __docformat__ = 'restructuredtext en'
|
|||||||
import traceback, base64
|
import traceback, base64
|
||||||
from contextlib import closing
|
from contextlib import closing
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from Queue import Queue
|
|
||||||
|
|
||||||
from calibre import browser
|
from calibre import browser
|
||||||
from calibre.constants import DEBUG
|
from calibre.constants import DEBUG
|
||||||
from calibre.utils.img import scale_image
|
from calibre.utils.img import scale_image
|
||||||
from polyglot.builtins import range
|
from polyglot.builtins import range
|
||||||
|
from polyglot.queue import Queue
|
||||||
|
|
||||||
|
|
||||||
class GenericDownloadThreadPool(object):
|
class GenericDownloadThreadPool(object):
|
||||||
|
@ -7,7 +7,6 @@ __copyright__ = '2011, John Schember <john@nachtimwald.com>'
|
|||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from urlparse import urlparse
|
|
||||||
|
|
||||||
from PyQt5.Qt import QNetworkCookieJar, QNetworkProxy
|
from PyQt5.Qt import QNetworkCookieJar, QNetworkProxy
|
||||||
from PyQt5.QtWebKitWidgets import QWebView, QWebPage
|
from PyQt5.QtWebKitWidgets import QWebView, QWebPage
|
||||||
@ -20,6 +19,7 @@ from calibre.ptempfile import PersistentTemporaryFile
|
|||||||
from calibre.utils.filenames import ascii_filename
|
from calibre.utils.filenames import ascii_filename
|
||||||
from calibre.web import get_download_filename
|
from calibre.web import get_download_filename
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import unicode_type
|
||||||
|
from polyglot.urllib import urlparse
|
||||||
|
|
||||||
|
|
||||||
class NPWebView(QWebView):
|
class NPWebView(QWebView):
|
||||||
|
@ -9,11 +9,11 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
import os, time, tempfile, json
|
import os, time, tempfile, json
|
||||||
from threading import Thread, RLock, Event
|
from threading import Thread, RLock, Event
|
||||||
from Queue import Queue
|
|
||||||
|
|
||||||
from calibre.utils.ipc.job import BaseJob
|
from calibre.utils.ipc.job import BaseJob
|
||||||
from calibre.utils.logging import GUILog
|
from calibre.utils.logging import GUILog
|
||||||
from calibre.ptempfile import base_dir
|
from calibre.ptempfile import base_dir
|
||||||
|
from polyglot.queue import Queue
|
||||||
|
|
||||||
|
|
||||||
class ThreadedJob(BaseJob):
|
class ThreadedJob(BaseJob):
|
||||||
@ -245,5 +245,3 @@ class ThreadedJobServer(Thread):
|
|||||||
queued_types.append(job.type)
|
queued_types.append(job.type)
|
||||||
ans.append(job)
|
ans.append(job)
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@ import shutil
|
|||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
from functools import partial, wraps
|
from functools import partial, wraps
|
||||||
from urlparse import urlparse
|
|
||||||
|
|
||||||
from PyQt5.Qt import (
|
from PyQt5.Qt import (
|
||||||
QApplication, QCheckBox, QDialog, QDialogButtonBox, QGridLayout, QIcon,
|
QApplication, QCheckBox, QDialog, QDialogButtonBox, QGridLayout, QIcon,
|
||||||
@ -71,6 +70,7 @@ from calibre.utils.icu import numeric_sort_key
|
|||||||
from calibre.utils.imghdr import identify
|
from calibre.utils.imghdr import identify
|
||||||
from calibre.utils.tdir_in_cache import tdir_in_cache
|
from calibre.utils.tdir_in_cache import tdir_in_cache
|
||||||
from polyglot.builtins import iteritems, string_or_bytes
|
from polyglot.builtins import iteritems, string_or_bytes
|
||||||
|
from polyglot.urllib import urlparse
|
||||||
|
|
||||||
_diff_dialogs = []
|
_diff_dialogs = []
|
||||||
last_used_transform_rules = []
|
last_used_transform_rules = []
|
||||||
|
@ -8,7 +8,6 @@ __copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
|
|
||||||
import os, sys
|
import os, sys
|
||||||
from threading import Thread, Event, RLock
|
from threading import Thread, Event, RLock
|
||||||
from Queue import Queue
|
|
||||||
from contextlib import closing
|
from contextlib import closing
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
@ -17,6 +16,7 @@ from calibre.gui2.tweak_book.completion.basic import Request
|
|||||||
from calibre.gui2.tweak_book.completion.utils import DataError
|
from calibre.gui2.tweak_book.completion.utils import DataError
|
||||||
from calibre.utils.ipc import eintr_retry_call
|
from calibre.utils.ipc import eintr_retry_call
|
||||||
from calibre.utils.serialize import msgpack_loads, msgpack_dumps
|
from calibre.utils.serialize import msgpack_loads, msgpack_dumps
|
||||||
|
from polyglot.queue import Queue
|
||||||
|
|
||||||
COMPLETION_REQUEST = 'completion request'
|
COMPLETION_REQUEST = 'completion request'
|
||||||
CLEAR_REQUEST = 'clear request'
|
CLEAR_REQUEST = 'clear request'
|
||||||
|
@ -11,9 +11,7 @@ from bisect import bisect_right
|
|||||||
from base64 import b64encode
|
from base64 import b64encode
|
||||||
from polyglot.builtins import map, unicode_type
|
from polyglot.builtins import map, unicode_type
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from Queue import Queue, Empty
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from urlparse import urlparse
|
|
||||||
|
|
||||||
from PyQt5.Qt import (
|
from PyQt5.Qt import (
|
||||||
QWidget, QVBoxLayout, QApplication, QSize, QNetworkAccessManager, QMenu, QIcon,
|
QWidget, QVBoxLayout, QApplication, QSize, QNetworkAccessManager, QMenu, QIcon,
|
||||||
@ -31,6 +29,8 @@ from calibre.gui2.viewer.documentview import apply_settings
|
|||||||
from calibre.gui2.viewer.config import config
|
from calibre.gui2.viewer.config import config
|
||||||
from calibre.gui2.widgets2 import HistoryLineEdit2
|
from calibre.gui2.widgets2 import HistoryLineEdit2
|
||||||
from calibre.utils.ipc.simple_worker import offload_worker
|
from calibre.utils.ipc.simple_worker import offload_worker
|
||||||
|
from polyglot.urllib import urlparse
|
||||||
|
from polyglot.queue import Queue, Empty
|
||||||
|
|
||||||
shutdown = object()
|
shutdown = object()
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@ __copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
|
|
||||||
import shutil, os, errno
|
import shutil, os, errno
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from Queue import LifoQueue, Empty
|
|
||||||
|
|
||||||
from PyQt5.Qt import (QObject, pyqtSignal, QLabel, QWidget, QHBoxLayout, Qt)
|
from PyQt5.Qt import (QObject, pyqtSignal, QLabel, QWidget, QHBoxLayout, Qt)
|
||||||
|
|
||||||
@ -18,6 +17,7 @@ from calibre.gui2.progress_indicator import ProgressIndicator
|
|||||||
from calibre.utils import join_with_timeout
|
from calibre.utils import join_with_timeout
|
||||||
from calibre.utils.filenames import atomic_rename, format_permissions
|
from calibre.utils.filenames import atomic_rename, format_permissions
|
||||||
from calibre.utils.ipc import RC
|
from calibre.utils.ipc import RC
|
||||||
|
from polyglot.queue import LifoQueue, Empty
|
||||||
|
|
||||||
|
|
||||||
def save_dir_container(container, path):
|
def save_dir_container(container, path):
|
||||||
|
@ -10,7 +10,6 @@ __docformat__ = 'restructuredtext en'
|
|||||||
'''The main GUI'''
|
'''The main GUI'''
|
||||||
|
|
||||||
import collections, os, sys, textwrap, time, gc, errno, re
|
import collections, os, sys, textwrap, time, gc, errno, re
|
||||||
from Queue import Queue, Empty
|
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
@ -54,6 +53,7 @@ from calibre.gui2.open_with import register_keyboard_shortcuts
|
|||||||
from calibre.library import current_library_name
|
from calibre.library import current_library_name
|
||||||
from calibre.srv.library_broker import GuiLibraryBroker
|
from calibre.srv.library_broker import GuiLibraryBroker
|
||||||
from polyglot.builtins import unicode_type, string_or_bytes
|
from polyglot.builtins import unicode_type, string_or_bytes
|
||||||
|
from polyglot.queue import Queue, Empty
|
||||||
|
|
||||||
|
|
||||||
class Listener(Thread): # {{{
|
class Listener(Thread): # {{{
|
||||||
|
@ -420,7 +420,7 @@ class EbookViewer(MainWindow):
|
|||||||
at_start=True)
|
at_start=True)
|
||||||
|
|
||||||
def lookup(self, word):
|
def lookup(self, word):
|
||||||
from urllib import quote
|
from polyglot.urllib import quote
|
||||||
word = word.replace(u'\u00ad', '')
|
word = word.replace(u'\u00ad', '')
|
||||||
word = quote(word.encode('utf-8'))
|
word = quote(word.encode('utf-8'))
|
||||||
lang = canonicalize_lang(self.view.current_language) or get_lang() or 'en'
|
lang = canonicalize_lang(self.view.current_language) or get_lang() or 'en'
|
||||||
|
@ -11,7 +11,6 @@ import sqlite3 as sqlite, traceback, time, uuid, sys, os
|
|||||||
import repr as reprlib
|
import repr as reprlib
|
||||||
from sqlite3 import IntegrityError, OperationalError
|
from sqlite3 import IntegrityError, OperationalError
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from Queue import Queue
|
|
||||||
from threading import RLock
|
from threading import RLock
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from functools import partial
|
from functools import partial
|
||||||
@ -23,6 +22,7 @@ from calibre.constants import iswindows, DEBUG, plugins
|
|||||||
from calibre.utils.icu import sort_key
|
from calibre.utils.icu import sort_key
|
||||||
from calibre import prints
|
from calibre import prints
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import unicode_type
|
||||||
|
from polyglot.queue import Queue
|
||||||
|
|
||||||
from dateutil.tz import tzoffset
|
from dateutil.tz import tzoffset
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@ __copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
|
|
||||||
import os, sys, subprocess, signal, time, errno, socket, ssl
|
import os, sys, subprocess, signal, time, errno, socket, ssl
|
||||||
from threading import Thread, Lock
|
from threading import Thread, Lock
|
||||||
from Queue import Queue, Empty
|
|
||||||
|
|
||||||
from calibre.constants import islinux, iswindows, isosx
|
from calibre.constants import islinux, iswindows, isosx
|
||||||
from calibre.srv.http_response import create_http_handler
|
from calibre.srv.http_response import create_http_handler
|
||||||
@ -18,6 +17,7 @@ from calibre.srv.standalone import create_option_parser
|
|||||||
from calibre.srv.utils import create_sock_pair
|
from calibre.srv.utils import create_sock_pair
|
||||||
from calibre.srv.web_socket import DummyHandler
|
from calibre.srv.web_socket import DummyHandler
|
||||||
from calibre.utils.monotonic import monotonic
|
from calibre.utils.monotonic import monotonic
|
||||||
|
from polyglot.queue import Queue, Empty
|
||||||
|
|
||||||
MAX_RETRIES = 10
|
MAX_RETRIES = 10
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@ from io import BytesIO
|
|||||||
from threading import Lock
|
from threading import Lock
|
||||||
from polyglot.builtins import map
|
from polyglot.builtins import map
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from urllib import quote
|
|
||||||
|
|
||||||
from calibre import fit_image, sanitize_file_name_unicode
|
from calibre import fit_image, sanitize_file_name_unicode
|
||||||
from calibre.constants import config_dir, iswindows
|
from calibre.constants import config_dir, iswindows
|
||||||
@ -30,6 +29,7 @@ from calibre.utils.date import timestampfromdt
|
|||||||
from calibre.utils.img import scale_image, image_from_data
|
from calibre.utils.img import scale_image, image_from_data
|
||||||
from calibre.utils.filenames import ascii_filename, atomic_rename
|
from calibre.utils.filenames import ascii_filename, atomic_rename
|
||||||
from calibre.utils.shared_file import share_open
|
from calibre.utils.shared_file import share_open
|
||||||
|
from polyglot.urllib import quote
|
||||||
|
|
||||||
plugboard_content_server_value = 'content_server'
|
plugboard_content_server_value = 'content_server'
|
||||||
plugboard_content_server_formats = ['epub', 'mobi', 'azw3']
|
plugboard_content_server_formats = ['epub', 'mobi', 'azw3']
|
||||||
|
@ -8,13 +8,13 @@ __copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
|
|
||||||
import re, httplib, repr as reprlib
|
import re, httplib, repr as reprlib
|
||||||
from io import BytesIO, DEFAULT_BUFFER_SIZE
|
from io import BytesIO, DEFAULT_BUFFER_SIZE
|
||||||
from urllib import unquote
|
|
||||||
|
|
||||||
from calibre import as_unicode, force_unicode
|
from calibre import as_unicode, force_unicode
|
||||||
from calibre.ptempfile import SpooledTemporaryFile
|
from calibre.ptempfile import SpooledTemporaryFile
|
||||||
from calibre.srv.errors import HTTPSimpleResponse
|
from calibre.srv.errors import HTTPSimpleResponse
|
||||||
from calibre.srv.loop import Connection, READ, WRITE
|
from calibre.srv.loop import Connection, READ, WRITE
|
||||||
from calibre.srv.utils import MultiDict, HTTP1, HTTP11, Accumulator
|
from calibre.srv.utils import MultiDict, HTTP1, HTTP11, Accumulator
|
||||||
|
from polyglot.urllib import unquote
|
||||||
|
|
||||||
protocol_map = {(1, 0):HTTP1, (1, 1):HTTP11}
|
protocol_map = {(1, 0):HTTP1, (1, 1):HTTP11}
|
||||||
quoted_slash = re.compile(br'%2[fF]')
|
quoted_slash = re.compile(br'%2[fF]')
|
||||||
|
@ -9,11 +9,11 @@ from itertools import count
|
|||||||
from collections import namedtuple, deque
|
from collections import namedtuple, deque
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from threading import RLock, Thread, Event
|
from threading import RLock, Thread, Event
|
||||||
from Queue import Queue, Empty
|
|
||||||
|
|
||||||
from calibre import detect_ncpus, force_unicode
|
from calibre import detect_ncpus, force_unicode
|
||||||
from calibre.utils.monotonic import monotonic
|
from calibre.utils.monotonic import monotonic
|
||||||
from calibre.utils.ipc.simple_worker import fork_job, WorkerError
|
from calibre.utils.ipc.simple_worker import fork_job, WorkerError
|
||||||
|
from polyglot.queue import Queue, Empty
|
||||||
|
|
||||||
StartEvent = namedtuple('StartEvent', 'job_id name module function args kwargs callback data')
|
StartEvent = namedtuple('StartEvent', 'job_id name module function args kwargs callback data')
|
||||||
DoneEvent = namedtuple('DoneEvent', 'job_id')
|
DoneEvent = namedtuple('DoneEvent', 'job_id')
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||||
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from urllib import urlencode
|
|
||||||
|
|
||||||
from lxml.html import tostring
|
from lxml.html import tostring
|
||||||
from lxml.html.builder import E as E_
|
from lxml.html.builder import E as E_
|
||||||
@ -21,6 +20,7 @@ from calibre.srv.utils import get_library_data, http_date
|
|||||||
from calibre.utils.cleantext import clean_xml_chars
|
from calibre.utils.cleantext import clean_xml_chars
|
||||||
from calibre.utils.date import dt_as_local, is_date_undefined, timestampfromdt
|
from calibre.utils.date import dt_as_local, is_date_undefined, timestampfromdt
|
||||||
from polyglot.builtins import string_or_bytes
|
from polyglot.builtins import string_or_bytes
|
||||||
|
from polyglot.urllib import urlencode
|
||||||
|
|
||||||
# /mobile {{{
|
# /mobile {{{
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@ __copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
|
|
||||||
import ssl, socket, select, os, traceback
|
import ssl, socket, select, os, traceback
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from Queue import Empty, Full
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from calibre import as_unicode
|
from calibre import as_unicode
|
||||||
@ -26,6 +25,7 @@ from calibre.utils.logging import ThreadSafeLog
|
|||||||
from calibre.utils.monotonic import monotonic
|
from calibre.utils.monotonic import monotonic
|
||||||
from calibre.utils.mdns import get_external_ip
|
from calibre.utils.mdns import get_external_ip
|
||||||
from polyglot.builtins import range
|
from polyglot.builtins import range
|
||||||
|
from polyglot.queue import Empty, Full
|
||||||
|
|
||||||
READ, WRITE, RDWR, WAIT = 'READ', 'WRITE', 'RDWR', 'WAIT'
|
READ, WRITE, RDWR, WAIT = 'READ', 'WRITE', 'RDWR', 'WAIT'
|
||||||
WAKEUP, JOB_DONE = bytes(bytearray(range(2)))
|
WAKEUP, JOB_DONE = bytes(bytearray(range(2)))
|
||||||
|
@ -10,7 +10,6 @@ from collections import namedtuple
|
|||||||
from datetime import datetime, time
|
from datetime import datetime, time
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from threading import Lock
|
from threading import Lock
|
||||||
from urllib import quote
|
|
||||||
|
|
||||||
from calibre.constants import config_dir
|
from calibre.constants import config_dir
|
||||||
from calibre.db.categories import Tag
|
from calibre.db.categories import Tag
|
||||||
@ -24,6 +23,7 @@ from calibre.utils.localization import calibre_langcode_to_name
|
|||||||
from calibre.library.comments import comments_to_html, markdown
|
from calibre.library.comments import comments_to_html, markdown
|
||||||
from calibre.library.field_metadata import category_icon_map
|
from calibre.library.field_metadata import category_icon_map
|
||||||
from polyglot.builtins import range
|
from polyglot.builtins import range
|
||||||
|
from polyglot.urllib import quote
|
||||||
|
|
||||||
IGNORED_FIELDS = frozenset('cover ondevice path marked au_map size'.split())
|
IGNORED_FIELDS = frozenset('cover ondevice path marked au_map size'.split())
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@ __docformat__ = 'restructuredtext en'
|
|||||||
import hashlib, binascii
|
import hashlib, binascii
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from collections import OrderedDict, namedtuple
|
from collections import OrderedDict, namedtuple
|
||||||
from urllib import urlencode
|
|
||||||
|
|
||||||
from lxml import etree, html
|
from lxml import etree, html
|
||||||
from lxml.builder import ElementMaker
|
from lxml.builder import ElementMaker
|
||||||
@ -28,6 +27,7 @@ from calibre.srv.errors import HTTPNotFound, HTTPInternalServerError
|
|||||||
from calibre.srv.routes import endpoint
|
from calibre.srv.routes import endpoint
|
||||||
from calibre.srv.utils import get_library_data, http_date, Offsets
|
from calibre.srv.utils import get_library_data, http_date, Offsets
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import unicode_type
|
||||||
|
from polyglot.urllib import urlencode
|
||||||
|
|
||||||
|
|
||||||
def hexlify(x):
|
def hexlify(x):
|
||||||
|
@ -7,11 +7,11 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from Queue import Queue, Full
|
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
from calibre.utils.monotonic import monotonic
|
from calibre.utils.monotonic import monotonic
|
||||||
from polyglot.builtins import range
|
from polyglot.builtins import range
|
||||||
|
from polyglot.queue import Queue, Full
|
||||||
|
|
||||||
|
|
||||||
class Worker(Thread):
|
class Worker(Thread):
|
||||||
|
@ -10,8 +10,6 @@ from collections import defaultdict, OrderedDict
|
|||||||
from itertools import count
|
from itertools import count
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from polyglot.builtins import map, unicode_type
|
from polyglot.builtins import map, unicode_type
|
||||||
from urlparse import urlparse
|
|
||||||
from urllib import quote
|
|
||||||
|
|
||||||
from css_parser import replaceUrls
|
from css_parser import replaceUrls
|
||||||
from css_parser.css import CSSRule
|
from css_parser.css import CSSRule
|
||||||
@ -30,6 +28,7 @@ from calibre.ebooks.oeb.polish.toc import get_toc, get_landmarks
|
|||||||
from calibre.ebooks.oeb.polish.utils import guess_type
|
from calibre.ebooks.oeb.polish.utils import guess_type
|
||||||
from calibre.utils.short_uuid import uuid4
|
from calibre.utils.short_uuid import uuid4
|
||||||
from calibre.utils.logging import default_log
|
from calibre.utils.logging import default_log
|
||||||
|
from polyglot.urllib import quote, urlparse
|
||||||
|
|
||||||
RENDER_VERSION = 1
|
RENDER_VERSION = 1
|
||||||
|
|
||||||
|
@ -7,7 +7,6 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
|
|
||||||
import httplib, sys, inspect, re, time, numbers, json as jsonlib, textwrap
|
import httplib, sys, inspect, re, time, numbers, json as jsonlib, textwrap
|
||||||
from urllib import quote as urlquote
|
|
||||||
from itertools import izip
|
from itertools import izip
|
||||||
from operator import attrgetter
|
from operator import attrgetter
|
||||||
|
|
||||||
@ -15,6 +14,7 @@ from calibre.srv.errors import HTTPSimpleResponse, HTTPNotFound, RouteError
|
|||||||
from calibre.srv.utils import http_date
|
from calibre.srv.utils import http_date
|
||||||
from calibre.utils.serialize import msgpack_dumps, json_dumps, MSGPACK_MIME
|
from calibre.utils.serialize import msgpack_dumps, json_dumps, MSGPACK_MIME
|
||||||
from polyglot.builtins import unicode_type, range
|
from polyglot.builtins import unicode_type, range
|
||||||
|
from polyglot.urllib import quote as urlquote
|
||||||
|
|
||||||
default_methods = frozenset(('HEAD', 'GET'))
|
default_methods = frozenset(('HEAD', 'GET'))
|
||||||
|
|
||||||
|
@ -9,11 +9,11 @@ __copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
import httplib, zlib, json, base64, os
|
import httplib, zlib, json, base64, os
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from urllib import urlencode, quote
|
|
||||||
from httplib import OK, NOT_FOUND, FORBIDDEN
|
from httplib import OK, NOT_FOUND, FORBIDDEN
|
||||||
|
|
||||||
from calibre.ebooks.metadata.meta import get_metadata
|
from calibre.ebooks.metadata.meta import get_metadata
|
||||||
from calibre.srv.tests.base import LibraryBaseTest
|
from calibre.srv.tests.base import LibraryBaseTest
|
||||||
|
from polyglot.urllib import urlencode, quote
|
||||||
|
|
||||||
|
|
||||||
def make_request(conn, url, headers={}, prefix='/ajax', username=None, password=None, method='GET', data=None):
|
def make_request(conn, url, headers={}, prefix='/ajax', username=None, password=None, method='GET', data=None):
|
||||||
|
@ -6,7 +6,7 @@ from __future__ import (unicode_literals, division, absolute_import,
|
|||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
|
|
||||||
import httplib, base64, urllib2, subprocess, os, cookielib, time
|
import httplib, base64, subprocess, os, cookielib, time
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
try:
|
try:
|
||||||
from distutils.spawn import find_executable
|
from distutils.spawn import find_executable
|
||||||
@ -17,6 +17,8 @@ from calibre.ptempfile import TemporaryDirectory
|
|||||||
from calibre.srv.errors import HTTPForbidden
|
from calibre.srv.errors import HTTPForbidden
|
||||||
from calibre.srv.tests.base import BaseTest, TestServer
|
from calibre.srv.tests.base import BaseTest, TestServer
|
||||||
from calibre.srv.routes import endpoint, Router
|
from calibre.srv.routes import endpoint, Router
|
||||||
|
from polyglot.urllib import (build_opener, HTTPBasicAuthHandler,
|
||||||
|
HTTPCookieProcessor, HTTPDigestAuthHandler, HTTPError)
|
||||||
|
|
||||||
REALM = 'calibre-test'
|
REALM = 'calibre-test'
|
||||||
|
|
||||||
@ -50,10 +52,10 @@ def router(prefer_basic_auth=False, ban_for=0, ban_after=5):
|
|||||||
|
|
||||||
|
|
||||||
def urlopen(server, path='/closed', un='testuser', pw='testpw', method='digest'):
|
def urlopen(server, path='/closed', un='testuser', pw='testpw', method='digest'):
|
||||||
auth_handler = urllib2.HTTPBasicAuthHandler() if method == 'basic' else urllib2.HTTPDigestAuthHandler()
|
auth_handler = HTTPBasicAuthHandler() if method == 'basic' else HTTPDigestAuthHandler()
|
||||||
url = 'http://localhost:%d%s' % (server.address[1], path)
|
url = 'http://localhost:%d%s' % (server.address[1], path)
|
||||||
auth_handler.add_password(realm=REALM, uri=url, user=un, passwd=pw)
|
auth_handler.add_password(realm=REALM, uri=url, user=un, passwd=pw)
|
||||||
return urllib2.build_opener(auth_handler).open(url)
|
return build_opener(auth_handler).open(url)
|
||||||
|
|
||||||
|
|
||||||
def digest(un, pw, nonce=None, uri=None, method='GET', nc=1, qop='auth', realm=REALM, cnonce=None, algorithm='MD5', body=b'', modify=lambda x:None):
|
def digest(un, pw, nonce=None, uri=None, method='GET', nc=1, qop='auth', realm=REALM, cnonce=None, algorithm='MD5', body=b'', modify=lambda x:None):
|
||||||
@ -276,26 +278,26 @@ class TestAuth(BaseTest):
|
|||||||
r = conn.getresponse()
|
r = conn.getresponse()
|
||||||
self.ae(r.status, httplib.UNAUTHORIZED)
|
self.ae(r.status, httplib.UNAUTHORIZED)
|
||||||
|
|
||||||
auth_handler = urllib2.HTTPDigestAuthHandler()
|
auth_handler = HTTPDigestAuthHandler()
|
||||||
url = 'http://localhost:%d%s' % (server.address[1], '/android')
|
url = 'http://localhost:%d%s' % (server.address[1], '/android')
|
||||||
auth_handler.add_password(realm=REALM, uri=url, user='testuser', passwd='testpw')
|
auth_handler.add_password(realm=REALM, uri=url, user='testuser', passwd='testpw')
|
||||||
cj = cookielib.CookieJar()
|
cj = cookielib.CookieJar()
|
||||||
cookie_handler = urllib2.HTTPCookieProcessor(cj)
|
cookie_handler = HTTPCookieProcessor(cj)
|
||||||
r = urllib2.build_opener(auth_handler, cookie_handler).open(url)
|
r = build_opener(auth_handler, cookie_handler).open(url)
|
||||||
self.ae(r.getcode(), httplib.OK)
|
self.ae(r.getcode(), httplib.OK)
|
||||||
cookies = tuple(cj)
|
cookies = tuple(cj)
|
||||||
self.ae(len(cookies), 1)
|
self.ae(len(cookies), 1)
|
||||||
cookie = cookies[0]
|
cookie = cookies[0]
|
||||||
self.assertIn(b':', cookie.value)
|
self.assertIn(b':', cookie.value)
|
||||||
self.ae(cookie.path, b'/android')
|
self.ae(cookie.path, b'/android')
|
||||||
r = urllib2.build_opener(cookie_handler).open(url)
|
r = build_opener(cookie_handler).open(url)
|
||||||
self.ae(r.getcode(), httplib.OK)
|
self.ae(r.getcode(), httplib.OK)
|
||||||
self.ae(r.read(), b'android')
|
self.ae(r.read(), b'android')
|
||||||
# Test that a replay attack against a different URL does not work
|
# Test that a replay attack against a different URL does not work
|
||||||
try:
|
try:
|
||||||
urllib2.build_opener(cookie_handler).open(url+'2')
|
build_opener(cookie_handler).open(url+'2')
|
||||||
assert ('Replay attack succeeded')
|
assert ('Replay attack succeeded')
|
||||||
except urllib2.HTTPError as e:
|
except HTTPError as e:
|
||||||
self.ae(e.code, httplib.UNAUTHORIZED)
|
self.ae(e.code, httplib.UNAUTHORIZED)
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
@ -9,12 +9,10 @@ __copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
import errno, socket, select, os, time
|
import errno, socket, select, os, time
|
||||||
from Cookie import SimpleCookie
|
from Cookie import SimpleCookie
|
||||||
from contextlib import closing
|
from contextlib import closing
|
||||||
from urlparse import parse_qs
|
|
||||||
import repr as reprlib
|
import repr as reprlib
|
||||||
from email.utils import formatdate
|
from email.utils import formatdate
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
from polyglot.builtins import map, unicode_type, range
|
from polyglot.builtins import map, unicode_type, range
|
||||||
from urllib import quote as urlquote
|
|
||||||
from binascii import hexlify, unhexlify
|
from binascii import hexlify, unhexlify
|
||||||
|
|
||||||
from calibre import prints
|
from calibre import prints
|
||||||
@ -25,6 +23,7 @@ from calibre.utils.localization import get_translator
|
|||||||
from calibre.utils.socket_inheritance import set_socket_inherit
|
from calibre.utils.socket_inheritance import set_socket_inherit
|
||||||
from calibre.utils.logging import ThreadSafeLog
|
from calibre.utils.logging import ThreadSafeLog
|
||||||
from calibre.utils.shared_file import share_open, raise_winerror
|
from calibre.utils.shared_file import share_open, raise_winerror
|
||||||
|
from polyglot.urllib import parse_qs, quote as urlquote
|
||||||
|
|
||||||
HTTP1 = 'HTTP/1.0'
|
HTTP1 = 'HTTP/1.0'
|
||||||
HTTP11 = 'HTTP/1.1'
|
HTTP11 = 'HTTP/1.1'
|
||||||
|
@ -9,7 +9,6 @@ import httplib, os, weakref, socket
|
|||||||
from base64 import standard_b64encode
|
from base64 import standard_b64encode
|
||||||
from collections import deque
|
from collections import deque
|
||||||
from hashlib import sha1
|
from hashlib import sha1
|
||||||
from Queue import Queue, Empty
|
|
||||||
from struct import unpack_from, pack, error as struct_error
|
from struct import unpack_from, pack, error as struct_error
|
||||||
from threading import Lock
|
from threading import Lock
|
||||||
|
|
||||||
@ -19,6 +18,7 @@ from calibre.srv.loop import ServerLoop, HandleInterrupt, WRITE, READ, RDWR, Con
|
|||||||
from calibre.srv.http_response import HTTPConnection, create_http_handler
|
from calibre.srv.http_response import HTTPConnection, create_http_handler
|
||||||
from calibre.srv.utils import DESIRED_SEND_BUFFER_SIZE
|
from calibre.srv.utils import DESIRED_SEND_BUFFER_SIZE
|
||||||
from calibre.utils.speedups import ReadOnlyFileBuffer
|
from calibre.utils.speedups import ReadOnlyFileBuffer
|
||||||
|
from polyglot.queue import Queue, Empty
|
||||||
speedup, err = plugins['speedup']
|
speedup, err = plugins['speedup']
|
||||||
if not speedup:
|
if not speedup:
|
||||||
raise RuntimeError('Failed to load speedup module with error: ' + err)
|
raise RuntimeError('Failed to load speedup module with error: ' + err)
|
||||||
|
@ -4,7 +4,9 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
'''
|
'''
|
||||||
Manage translation of user visible strings.
|
Manage translation of user visible strings.
|
||||||
'''
|
'''
|
||||||
import shutil, tarfile, re, os, subprocess, urllib2
|
import shutil, tarfile, re, os, subprocess
|
||||||
|
|
||||||
|
from polyglot.urllib import urlopen
|
||||||
|
|
||||||
language_codes = {
|
language_codes = {
|
||||||
'aa':'Afar','ab':'Abkhazian','af':'Afrikaans','am':'Amharic','ar':'Arabic','as':'Assamese','ay':'Aymara','az':'Azerbaijani',
|
'aa':'Afar','ab':'Abkhazian','af':'Afrikaans','am':'Amharic','ar':'Arabic','as':'Assamese','ay':'Aymara','az':'Azerbaijani',
|
||||||
@ -38,7 +40,7 @@ language_codes = {
|
|||||||
|
|
||||||
def import_from_launchpad(url):
|
def import_from_launchpad(url):
|
||||||
f = open('/tmp/launchpad_export.tar.gz', 'wb')
|
f = open('/tmp/launchpad_export.tar.gz', 'wb')
|
||||||
shutil.copyfileobj(urllib2.urlopen(url), f)
|
shutil.copyfileobj(urlopen(url), f)
|
||||||
f.close()
|
f.close()
|
||||||
tf = tarfile.open('/tmp/launchpad_export.tar.gz', 'r:gz')
|
tf = tarfile.open('/tmp/launchpad_export.tar.gz', 'r:gz')
|
||||||
next = tf.next()
|
next = tf.next()
|
||||||
|
@ -11,6 +11,7 @@ from contextlib import closing
|
|||||||
|
|
||||||
from calibre import get_proxies
|
from calibre import get_proxies
|
||||||
from calibre.constants import ispy3
|
from calibre.constants import ispy3
|
||||||
|
from polyglot.urllib import urlsplit
|
||||||
has_ssl_verify = hasattr(ssl, 'create_default_context') and hasattr(ssl, '_create_unverified_context')
|
has_ssl_verify = hasattr(ssl, 'create_default_context') and hasattr(ssl, '_create_unverified_context')
|
||||||
|
|
||||||
|
|
||||||
@ -25,11 +26,9 @@ class HTTPError(ValueError):
|
|||||||
|
|
||||||
|
|
||||||
if ispy3:
|
if ispy3:
|
||||||
from urllib.parse import urlparse
|
|
||||||
import http.client as httplib
|
import http.client as httplib
|
||||||
else:
|
else:
|
||||||
import httplib
|
import httplib
|
||||||
from urlparse import urlsplit as urlparse
|
|
||||||
|
|
||||||
if has_ssl_verify:
|
if has_ssl_verify:
|
||||||
class HTTPSConnection(httplib.HTTPSConnection):
|
class HTTPSConnection(httplib.HTTPSConnection):
|
||||||
@ -175,7 +174,7 @@ def get_https_resource_securely(
|
|||||||
cert_file = None
|
cert_file = None
|
||||||
if cacerts is not None:
|
if cacerts is not None:
|
||||||
cert_file = P(cacerts, allow_user_override=False)
|
cert_file = P(cacerts, allow_user_override=False)
|
||||||
p = urlparse(url)
|
p = urlsplit(url)
|
||||||
if p.scheme != 'https':
|
if p.scheme != 'https':
|
||||||
raise ValueError('URL %s scheme must be https, not %r' % (url, p.scheme))
|
raise ValueError('URL %s scheme must be https, not %r' % (url, p.scheme))
|
||||||
|
|
||||||
|
@ -9,10 +9,10 @@ __docformat__ = 'restructuredtext en'
|
|||||||
_count = 0
|
_count = 0
|
||||||
|
|
||||||
import time, io
|
import time, io
|
||||||
from Queue import Queue, Empty
|
|
||||||
|
|
||||||
from calibre import prints
|
from calibre import prints
|
||||||
from calibre.constants import DEBUG
|
from calibre.constants import DEBUG
|
||||||
|
from polyglot.queue import Queue, Empty
|
||||||
|
|
||||||
|
|
||||||
class BaseJob(object):
|
class BaseJob(object):
|
||||||
|
@ -9,7 +9,6 @@ __copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
import os, sys
|
import os, sys
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from Queue import Queue
|
|
||||||
|
|
||||||
from calibre import detect_ncpus, as_unicode, prints
|
from calibre import detect_ncpus, as_unicode, prints
|
||||||
from calibre.constants import iswindows, DEBUG
|
from calibre.constants import iswindows, DEBUG
|
||||||
@ -17,6 +16,7 @@ from calibre.ptempfile import PersistentTemporaryFile
|
|||||||
from calibre.utils import join_with_timeout
|
from calibre.utils import join_with_timeout
|
||||||
from calibre.utils.ipc import eintr_retry_call
|
from calibre.utils.ipc import eintr_retry_call
|
||||||
from calibre.utils.serialize import msgpack_dumps, msgpack_loads, pickle_dumps, pickle_loads
|
from calibre.utils.serialize import msgpack_dumps, msgpack_loads, pickle_dumps, pickle_loads
|
||||||
|
from polyglot.queue import Queue
|
||||||
|
|
||||||
Job = namedtuple('Job', 'id module func args kwargs')
|
Job = namedtuple('Job', 'id module func args kwargs')
|
||||||
Result = namedtuple('Result', 'value err traceback')
|
Result = namedtuple('Result', 'value err traceback')
|
||||||
|
@ -17,7 +17,6 @@ from binascii import hexlify
|
|||||||
from collections import deque
|
from collections import deque
|
||||||
from math import ceil
|
from math import ceil
|
||||||
from multiprocessing.connection import Listener, arbitrary_address
|
from multiprocessing.connection import Listener, arbitrary_address
|
||||||
from Queue import Empty, Queue
|
|
||||||
from threading import RLock, Thread
|
from threading import RLock, Thread
|
||||||
|
|
||||||
from calibre import detect_ncpus as cpu_count
|
from calibre import detect_ncpus as cpu_count
|
||||||
@ -28,6 +27,7 @@ from calibre.utils.ipc.launch import Worker
|
|||||||
from calibre.utils.ipc.worker import PARALLEL_FUNCS
|
from calibre.utils.ipc.worker import PARALLEL_FUNCS
|
||||||
from calibre.utils.serialize import msgpack_dumps, pickle_loads
|
from calibre.utils.serialize import msgpack_dumps, pickle_loads
|
||||||
from polyglot.builtins import string_or_bytes, environ_item
|
from polyglot.builtins import string_or_bytes, environ_item
|
||||||
|
from polyglot.queue import Empty, Queue
|
||||||
|
|
||||||
|
|
||||||
_counter = 0
|
_counter = 0
|
||||||
|
@ -10,7 +10,6 @@ __docformat__ = 'restructuredtext en'
|
|||||||
import os, sys, importlib
|
import os, sys, importlib
|
||||||
from multiprocessing.connection import Client
|
from multiprocessing.connection import Client
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from Queue import Queue
|
|
||||||
from contextlib import closing
|
from contextlib import closing
|
||||||
from binascii import unhexlify
|
from binascii import unhexlify
|
||||||
from zipimport import ZipImportError
|
from zipimport import ZipImportError
|
||||||
@ -19,6 +18,7 @@ from calibre import prints
|
|||||||
from calibre.constants import iswindows, isosx
|
from calibre.constants import iswindows, isosx
|
||||||
from calibre.utils.ipc import eintr_retry_call
|
from calibre.utils.ipc import eintr_retry_call
|
||||||
from calibre.utils.serialize import msgpack_loads, pickle_dumps
|
from calibre.utils.serialize import msgpack_loads, pickle_dumps
|
||||||
|
from polyglot.queue import Queue
|
||||||
|
|
||||||
PARALLEL_FUNCS = {
|
PARALLEL_FUNCS = {
|
||||||
'lrfviewer' :
|
'lrfviewer' :
|
||||||
|
@ -22,9 +22,9 @@ from __future__ import (unicode_literals, division, absolute_import,
|
|||||||
import os, stat
|
import os, stat
|
||||||
import os.path as op
|
import os.path as op
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from urllib import quote
|
|
||||||
|
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import unicode_type
|
||||||
|
from polyglot.urllib import quote
|
||||||
|
|
||||||
FILES_DIR = 'files'
|
FILES_DIR = 'files'
|
||||||
INFO_DIR = 'info'
|
INFO_DIR = 'info'
|
||||||
|
@ -9,7 +9,7 @@ __docformat__ = 'restructuredtext en'
|
|||||||
import os, locale, re, io
|
import os, locale, re, io
|
||||||
from gettext import GNUTranslations, NullTranslations
|
from gettext import GNUTranslations, NullTranslations
|
||||||
|
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import is_py3, unicode_type
|
||||||
|
|
||||||
_available_translations = None
|
_available_translations = None
|
||||||
|
|
||||||
@ -244,6 +244,9 @@ def set_translators():
|
|||||||
set_translators.lang = t.info().get('language')
|
set_translators.lang = t.info().get('language')
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
if is_py3:
|
||||||
|
t.install(names=('ngettext',))
|
||||||
|
else:
|
||||||
t.install(unicode=True, names=('ngettext',))
|
t.install(unicode=True, names=('ngettext',))
|
||||||
# Now that we have installed a translator, we have to retranslate the help
|
# Now that we have installed a translator, we have to retranslate the help
|
||||||
# for the global prefs object as it was instantiated in get_lang(), before
|
# for the global prefs object as it was instantiated in get_lang(), before
|
||||||
@ -500,7 +503,7 @@ def localize_user_manual_link(url):
|
|||||||
stats = user_manual_stats()
|
stats = user_manual_stats()
|
||||||
if stats.get(lc, 0) < 0.3:
|
if stats.get(lc, 0) < 0.3:
|
||||||
return url
|
return url
|
||||||
from urlparse import urlparse, urlunparse
|
from polyglot.urllib import urlparse, urlunparse
|
||||||
parts = urlparse(url)
|
parts = urlparse(url)
|
||||||
path = re.sub(r'/generated/[a-z]+/', '/generated/%s/' % lc, parts.path or '')
|
path = re.sub(r'/generated/[a-z]+/', '/generated/%s/' % lc, parts.path or '')
|
||||||
path = '/%s%s' % (lc, path)
|
path = '/%s%s' % (lc, path)
|
||||||
@ -525,7 +528,7 @@ def localize_website_link(url):
|
|||||||
langs = website_languages()
|
langs = website_languages()
|
||||||
if lc == 'en' or lc not in langs:
|
if lc == 'en' or lc not in langs:
|
||||||
return url
|
return url
|
||||||
from urlparse import urlparse, urlunparse
|
from polyglot.urllib import urlparse, urlunparse
|
||||||
parts = urlparse(url)
|
parts = urlparse(url)
|
||||||
path = '/{}{}'.format(lc, parts.path)
|
path = '/{}{}'.format(lc, parts.path)
|
||||||
parts = list(parts)
|
parts = list(parts)
|
||||||
|
@ -9,7 +9,6 @@ import atexit, os, sys
|
|||||||
from math import ceil
|
from math import ceil
|
||||||
from unicodedata import normalize
|
from unicodedata import normalize
|
||||||
from threading import Thread, Lock
|
from threading import Thread, Lock
|
||||||
from Queue import Queue
|
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from itertools import islice
|
from itertools import islice
|
||||||
@ -20,6 +19,7 @@ from polyglot.builtins import map, unicode_type, range
|
|||||||
from calibre import detect_ncpus as cpu_count, as_unicode
|
from calibre import detect_ncpus as cpu_count, as_unicode
|
||||||
from calibre.constants import plugins, filesystem_encoding
|
from calibre.constants import plugins, filesystem_encoding
|
||||||
from calibre.utils.icu import primary_sort_key, primary_find, primary_collator
|
from calibre.utils.icu import primary_sort_key, primary_find, primary_collator
|
||||||
|
from polyglot.queue import Queue
|
||||||
|
|
||||||
DEFAULT_LEVEL1 = '/'
|
DEFAULT_LEVEL1 = '/'
|
||||||
DEFAULT_LEVEL2 = '-_ 0123456789'
|
DEFAULT_LEVEL2 = '-_ 0123456789'
|
||||||
|
@ -20,9 +20,9 @@ application_locations = ('/Applications', '~/Applications', '~/Desktop')
|
|||||||
|
|
||||||
def generate_public_uti_map():
|
def generate_public_uti_map():
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
import urllib
|
from polyglot.urllib import urlopen
|
||||||
from html5_parser import parse
|
from html5_parser import parse
|
||||||
raw = urllib.urlopen(
|
raw = urlopen(
|
||||||
'https://developer.apple.com/library/ios/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html').read()
|
'https://developer.apple.com/library/ios/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html').read()
|
||||||
root = parse(raw)
|
root = parse(raw)
|
||||||
tables = root.xpath('//table')[0::2]
|
tables = root.xpath('//table')[0::2]
|
||||||
|
@ -6,8 +6,7 @@ __license__ = 'GPL 3'
|
|||||||
__copyright__ = '2006, Ed Summers <ehs@pobox.com>'
|
__copyright__ = '2006, Ed Summers <ehs@pobox.com>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
from urlparse import urlparse, urlunparse, parse_qs
|
from polyglot.urllib import parse_qs, urlencode, urlparse, urlunparse
|
||||||
from urllib import urlencode
|
|
||||||
|
|
||||||
|
|
||||||
class Query(object):
|
class Query(object):
|
||||||
@ -72,4 +71,3 @@ class Query(object):
|
|||||||
|
|
||||||
def has_macro(self, macro):
|
def has_macro(self, macro):
|
||||||
return macro in self.macro_map
|
return macro in self.macro_map
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from Queue import Empty, Queue
|
|
||||||
from threading import Thread, local
|
from threading import Thread, local
|
||||||
|
|
||||||
from calibre import force_unicode
|
from calibre import force_unicode
|
||||||
@ -24,6 +23,7 @@ from calibre.utils.terminal import ANSIStream
|
|||||||
from duktape import Context, JSError, to_python
|
from duktape import Context, JSError, to_python
|
||||||
from lzma.xz import compress, decompress
|
from lzma.xz import compress, decompress
|
||||||
from polyglot.builtins import range
|
from polyglot.builtins import range
|
||||||
|
from polyglot.queue import Empty, Queue
|
||||||
|
|
||||||
COMPILER_PATH = 'rapydscript/compiler.js.xz'
|
COMPILER_PATH = 'rapydscript/compiler.js.xz'
|
||||||
|
|
||||||
|
@ -18,9 +18,9 @@ if sys.version_info.major > 2:
|
|||||||
file=sys.stderr)
|
file=sys.stderr)
|
||||||
raise SystemExit(1)
|
raise SystemExit(1)
|
||||||
|
|
||||||
import time, BaseHTTPServer, os, sys, re, SocketServer
|
import time, os, sys, re, SocketServer
|
||||||
from threading import Lock, local
|
from threading import Lock, local
|
||||||
from SimpleHTTPServer import SimpleHTTPRequestHandler
|
from polyglot.http_server import BaseHTTPServer, SimpleHTTPRequestHandler
|
||||||
|
|
||||||
# Compiler {{{
|
# Compiler {{{
|
||||||
|
|
||||||
|
@ -1,90 +0,0 @@
|
|||||||
#!/usr/bin/env python2
|
|
||||||
from __future__ import print_function
|
|
||||||
__license__ = 'GPL v3'
|
|
||||||
__copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
|
|
||||||
__docformat__ = 'restructuredtext en'
|
|
||||||
|
|
||||||
'''
|
|
||||||
Create a file handle to a remote file over the sftp protocol.
|
|
||||||
'''
|
|
||||||
|
|
||||||
import sys, socket, getpass
|
|
||||||
from urlparse import urlparse
|
|
||||||
from binascii import hexlify
|
|
||||||
|
|
||||||
import paramiko
|
|
||||||
|
|
||||||
|
|
||||||
def agent_auth(transport, username):
|
|
||||||
"""
|
|
||||||
Attempt to authenticate to the given transport using any of the private
|
|
||||||
keys available from an SSH agent.
|
|
||||||
"""
|
|
||||||
|
|
||||||
agent = paramiko.Agent()
|
|
||||||
agent_keys = agent.get_keys()
|
|
||||||
if len(agent_keys) == 0:
|
|
||||||
return
|
|
||||||
|
|
||||||
for key in agent_keys:
|
|
||||||
print('Trying ssh-agent key %s' % hexlify(key.get_fingerprint()), end=' ')
|
|
||||||
try:
|
|
||||||
transport.auth_publickey(username, key)
|
|
||||||
print('... success!')
|
|
||||||
return True
|
|
||||||
except paramiko.SSHException:
|
|
||||||
print('... failed.')
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def portable_getpass(username, hostname, retry):
|
|
||||||
return getpass.getpass('%sPlease enter the password for %s on %s: '%(
|
|
||||||
'Incorrect password. ' if retry else '', username, hostname))
|
|
||||||
|
|
||||||
|
|
||||||
def password_auth(transport, username, hostname, getpw=portable_getpass):
|
|
||||||
for i in range(3):
|
|
||||||
pw = getpw(username, hostname, i>0)
|
|
||||||
transport.auth_password(username, pw)
|
|
||||||
if transport.is_authenticated():
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def connect_to_url(url, getpw=portable_getpass, mode='r+', bufsize=-1):
|
|
||||||
protocol, host, path = urlparse(url)[:3]
|
|
||||||
if protocol != 'sftp':
|
|
||||||
raise ValueError(_('URL must have the scheme sftp'))
|
|
||||||
try:
|
|
||||||
username, host = host.split('@')
|
|
||||||
except:
|
|
||||||
raise ValueError(_('host must be of the form user@hostname'))
|
|
||||||
port = 22
|
|
||||||
if ':' in host:
|
|
||||||
host, port = host.split(':')
|
|
||||||
port = int(port)
|
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
||||||
sock.connect((host, port))
|
|
||||||
t = paramiko.Transport(sock)
|
|
||||||
try:
|
|
||||||
t.start_client()
|
|
||||||
except:
|
|
||||||
raise Exception(_('Failed to negotiate SSH session: ') + str(t.get_exception()))
|
|
||||||
if not agent_auth(t, username):
|
|
||||||
if not password_auth(t, username, host, getpw):
|
|
||||||
raise ValueError(_('Failed to authenticate with server: %s')%url)
|
|
||||||
sftp = paramiko.SFTPClient.from_transport(t)
|
|
||||||
return sftp, sftp.open(path, mode=mode, bufsize=bufsize)
|
|
||||||
|
|
||||||
|
|
||||||
def main(args=sys.argv):
|
|
||||||
f = connect_to_url(args[1])[-1]
|
|
||||||
print(f.read())
|
|
||||||
f.seek(0, 2)
|
|
||||||
print(f.tell())
|
|
||||||
f.close()
|
|
||||||
return 0
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
sys.exit(main())
|
|
@ -48,7 +48,7 @@ __license__ = 'Python license'
|
|||||||
|
|
||||||
# standard library modules
|
# standard library modules
|
||||||
import threading
|
import threading
|
||||||
import Queue
|
from polyglot import queue
|
||||||
|
|
||||||
# exceptions
|
# exceptions
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ class WorkerThread(threading.Thread):
|
|||||||
def __init__(self, requestsQueue, resultsQueue, **kwds):
|
def __init__(self, requestsQueue, resultsQueue, **kwds):
|
||||||
"""Set up thread in daemonic mode and start it immediatedly.
|
"""Set up thread in daemonic mode and start it immediatedly.
|
||||||
|
|
||||||
requestsQueue and resultQueue are instances of Queue.Queue passed
|
requestsQueue and resultQueue are instances of queue.Queue passed
|
||||||
by the ThreadPool class when it creates a new worker thread.
|
by the ThreadPool class when it creates a new worker thread.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -174,8 +174,8 @@ class ThreadPool:
|
|||||||
more work requests in it (see putRequest method).
|
more work requests in it (see putRequest method).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.requestsQueue = Queue.Queue(q_size)
|
self.requestsQueue = queue.Queue(q_size)
|
||||||
self.resultsQueue = Queue.Queue()
|
self.resultsQueue = queue.Queue()
|
||||||
self.workers = []
|
self.workers = []
|
||||||
self.workRequests = {}
|
self.workRequests = {}
|
||||||
self.createWorkers(num_workers)
|
self.createWorkers(num_workers)
|
||||||
@ -223,7 +223,7 @@ class ThreadPool:
|
|||||||
(request.exception and request.exc_callback):
|
(request.exception and request.exc_callback):
|
||||||
request.callback(request, result)
|
request.callback(request, result)
|
||||||
del self.workRequests[request.requestID]
|
del self.workRequests[request.requestID]
|
||||||
except Queue.Empty:
|
except queue.Empty:
|
||||||
break
|
break
|
||||||
|
|
||||||
def wait(self, sleep=0):
|
def wait(self, sleep=0):
|
||||||
|
@ -7,12 +7,11 @@ class Recipe(object):
|
|||||||
|
|
||||||
|
|
||||||
def get_download_filename_from_response(response):
|
def get_download_filename_from_response(response):
|
||||||
from urlparse import urlparse
|
from polyglot.urllib import unquote, urlparse
|
||||||
from urllib2 import unquote as urllib2_unquote
|
|
||||||
filename = last_part_name = ''
|
filename = last_part_name = ''
|
||||||
try:
|
try:
|
||||||
purl = urlparse(response.geturl())
|
purl = urlparse(response.geturl())
|
||||||
last_part_name = urllib2_unquote(purl.path.split('/')[-1])
|
last_part_name = unquote(purl.path.split('/')[-1])
|
||||||
disposition = response.info().get('Content-disposition', '')
|
disposition = response.info().get('Content-disposition', '')
|
||||||
for p in disposition.split(';'):
|
for p in disposition.split(';'):
|
||||||
if 'filename' in p:
|
if 'filename' in p:
|
||||||
@ -25,7 +24,7 @@ def get_download_filename_from_response(response):
|
|||||||
filename = filename[1:]
|
filename = filename[1:]
|
||||||
if filename[-1] in ('\'', '"'):
|
if filename[-1] in ('\'', '"'):
|
||||||
filename = filename[:-1]
|
filename = filename[:-1]
|
||||||
filename = urllib2_unquote(filename)
|
filename = unquote(filename)
|
||||||
break
|
break
|
||||||
except Exception:
|
except Exception:
|
||||||
import traceback
|
import traceback
|
||||||
|
@ -7,7 +7,7 @@ Defines various abstract base classes that can be subclassed to create powerful
|
|||||||
__docformat__ = "restructuredtext en"
|
__docformat__ = "restructuredtext en"
|
||||||
|
|
||||||
|
|
||||||
import os, time, traceback, re, urlparse, sys, io
|
import os, time, traceback, re, sys, io
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from contextlib import nested, closing
|
from contextlib import nested, closing
|
||||||
@ -32,6 +32,7 @@ from calibre.utils.img import save_cover_data_to, add_borders_to_image, image_to
|
|||||||
from calibre.utils.localization import canonicalize_lang
|
from calibre.utils.localization import canonicalize_lang
|
||||||
from calibre.utils.logging import ThreadSafeWrapper
|
from calibre.utils.logging import ThreadSafeWrapper
|
||||||
from polyglot.builtins import unicode_type, string_or_bytes
|
from polyglot.builtins import unicode_type, string_or_bytes
|
||||||
|
from polyglot.urllib import urlparse, urlsplit
|
||||||
|
|
||||||
|
|
||||||
class LoginFailed(ValueError):
|
class LoginFailed(ValueError):
|
||||||
@ -652,7 +653,7 @@ class BasicNewsRecipe(Recipe):
|
|||||||
download an article.
|
download an article.
|
||||||
'''
|
'''
|
||||||
try:
|
try:
|
||||||
parts = urlparse.urlparse(url)
|
parts = urlparse(url)
|
||||||
except Exception:
|
except Exception:
|
||||||
self.log.error('Failed to parse url: %r, ignoring' % url)
|
self.log.error('Failed to parse url: %r, ignoring' % url)
|
||||||
return frozenset()
|
return frozenset()
|
||||||
@ -1092,7 +1093,7 @@ class BasicNewsRecipe(Recipe):
|
|||||||
if feed.image_url in self.image_map:
|
if feed.image_url in self.image_map:
|
||||||
feed.image_url = self.image_map[feed.image_url]
|
feed.image_url = self.image_map[feed.image_url]
|
||||||
else:
|
else:
|
||||||
bn = urlparse.urlsplit(feed.image_url).path
|
bn = urlsplit(feed.image_url).path
|
||||||
if bn:
|
if bn:
|
||||||
bn = bn.rpartition('/')[-1]
|
bn = bn.rpartition('/')[-1]
|
||||||
if bn:
|
if bn:
|
||||||
|
@ -7,8 +7,7 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
Fetch a webpage and its links recursively. The webpages are saved to disk in
|
Fetch a webpage and its links recursively. The webpages are saved to disk in
|
||||||
UTF-8 encoding with any charset declarations removed.
|
UTF-8 encoding with any charset declarations removed.
|
||||||
'''
|
'''
|
||||||
import sys, socket, os, urlparse, re, time, urllib2, threading, traceback
|
import sys, socket, os, re, time, threading, traceback
|
||||||
from urllib import url2pathname, quote
|
|
||||||
from httplib import responses
|
from httplib import responses
|
||||||
from base64 import b64decode
|
from base64 import b64decode
|
||||||
|
|
||||||
@ -25,6 +24,8 @@ from calibre.utils.img import image_from_data, image_to_data
|
|||||||
from calibre.utils.imghdr import what
|
from calibre.utils.imghdr import what
|
||||||
from calibre.web.fetch.utils import rescale_image
|
from calibre.web.fetch.utils import rescale_image
|
||||||
from polyglot.builtins import unicode_type
|
from polyglot.builtins import unicode_type
|
||||||
|
from polyglot.urllib import (quote, URLError, url2pathname, urljoin,
|
||||||
|
urlparse, urlsplit, urlunsplit)
|
||||||
|
|
||||||
|
|
||||||
class AbortArticle(Exception):
|
class AbortArticle(Exception):
|
||||||
@ -57,7 +58,7 @@ bad_url_counter = 0
|
|||||||
|
|
||||||
def basename(url):
|
def basename(url):
|
||||||
try:
|
try:
|
||||||
parts = urlparse.urlsplit(url)
|
parts = urlsplit(url)
|
||||||
path = url2pathname(parts.path)
|
path = url2pathname(parts.path)
|
||||||
res = os.path.basename(path)
|
res = os.path.basename(path)
|
||||||
except:
|
except:
|
||||||
@ -261,16 +262,16 @@ class RecursiveFetcher(object):
|
|||||||
# handles quoting automatically, but leaving it
|
# handles quoting automatically, but leaving it
|
||||||
# in case it breaks something
|
# in case it breaks something
|
||||||
if re.search(r'\s+', url) is not None:
|
if re.search(r'\s+', url) is not None:
|
||||||
purl = list(urlparse.urlparse(url))
|
purl = list(urlparse(url))
|
||||||
for i in range(2, 6):
|
for i in range(2, 6):
|
||||||
purl[i] = quote(purl[i])
|
purl[i] = quote(purl[i])
|
||||||
url = urlparse.urlunparse(purl)
|
url = urlunparse(purl)
|
||||||
open_func = getattr(self.browser, 'open_novisit', self.browser.open)
|
open_func = getattr(self.browser, 'open_novisit', self.browser.open)
|
||||||
try:
|
try:
|
||||||
with closing(open_func(url, timeout=self.timeout)) as f:
|
with closing(open_func(url, timeout=self.timeout)) as f:
|
||||||
data = response(f.read()+f.read())
|
data = response(f.read()+f.read())
|
||||||
data.newurl = f.geturl()
|
data.newurl = f.geturl()
|
||||||
except urllib2.URLError as err:
|
except URLError as err:
|
||||||
if hasattr(err, 'code') and err.code in responses:
|
if hasattr(err, 'code') and err.code in responses:
|
||||||
raise FetchError(responses[err.code])
|
raise FetchError(responses[err.code])
|
||||||
if getattr(err, 'reason', [0])[0] == 104 or \
|
if getattr(err, 'reason', [0])[0] == 104 or \
|
||||||
@ -325,8 +326,8 @@ class RecursiveFetcher(object):
|
|||||||
for c, tag in enumerate(soup.findAll(lambda tag: tag.name.lower()in ['link', 'style'] and tag.has_key('type') and tag['type'].lower() == 'text/css')): # noqa
|
for c, tag in enumerate(soup.findAll(lambda tag: tag.name.lower()in ['link', 'style'] and tag.has_key('type') and tag['type'].lower() == 'text/css')): # noqa
|
||||||
if tag.has_key('href'): # noqa
|
if tag.has_key('href'): # noqa
|
||||||
iurl = tag['href']
|
iurl = tag['href']
|
||||||
if not urlparse.urlsplit(iurl).scheme:
|
if not urlsplit(iurl).scheme:
|
||||||
iurl = urlparse.urljoin(baseurl, iurl, False)
|
iurl = urljoin(baseurl, iurl, False)
|
||||||
with self.stylemap_lock:
|
with self.stylemap_lock:
|
||||||
if self.stylemap.has_key(iurl): # noqa
|
if self.stylemap.has_key(iurl): # noqa
|
||||||
tag['href'] = self.stylemap[iurl]
|
tag['href'] = self.stylemap[iurl]
|
||||||
@ -348,8 +349,8 @@ class RecursiveFetcher(object):
|
|||||||
m = self.__class__.CSS_IMPORT_PATTERN.search(src)
|
m = self.__class__.CSS_IMPORT_PATTERN.search(src)
|
||||||
if m:
|
if m:
|
||||||
iurl = m.group(1)
|
iurl = m.group(1)
|
||||||
if not urlparse.urlsplit(iurl).scheme:
|
if not urlsplit(iurl).scheme:
|
||||||
iurl = urlparse.urljoin(baseurl, iurl, False)
|
iurl = urljoin(baseurl, iurl, False)
|
||||||
with self.stylemap_lock:
|
with self.stylemap_lock:
|
||||||
if self.stylemap.has_key(iurl): # noqa
|
if self.stylemap.has_key(iurl): # noqa
|
||||||
ns.replaceWith(src.replace(m.group(1), self.stylemap[iurl]))
|
ns.replaceWith(src.replace(m.group(1), self.stylemap[iurl]))
|
||||||
@ -386,8 +387,8 @@ class RecursiveFetcher(object):
|
|||||||
else:
|
else:
|
||||||
if callable(self.image_url_processor):
|
if callable(self.image_url_processor):
|
||||||
iurl = self.image_url_processor(baseurl, iurl)
|
iurl = self.image_url_processor(baseurl, iurl)
|
||||||
if not urlparse.urlsplit(iurl).scheme:
|
if not urlsplit(iurl).scheme:
|
||||||
iurl = urlparse.urljoin(baseurl, iurl, False)
|
iurl = urljoin(baseurl, iurl, False)
|
||||||
with self.imagemap_lock:
|
with self.imagemap_lock:
|
||||||
if self.imagemap.has_key(iurl): # noqa
|
if self.imagemap.has_key(iurl): # noqa
|
||||||
tag['src'] = self.imagemap[iurl]
|
tag['src'] = self.imagemap[iurl]
|
||||||
@ -443,11 +444,11 @@ class RecursiveFetcher(object):
|
|||||||
|
|
||||||
def absurl(self, baseurl, tag, key, filter=True):
|
def absurl(self, baseurl, tag, key, filter=True):
|
||||||
iurl = tag[key]
|
iurl = tag[key]
|
||||||
parts = urlparse.urlsplit(iurl)
|
parts = urlsplit(iurl)
|
||||||
if not parts.netloc and not parts.path and not parts.query:
|
if not parts.netloc and not parts.path and not parts.query:
|
||||||
return None
|
return None
|
||||||
if not parts.scheme:
|
if not parts.scheme:
|
||||||
iurl = urlparse.urljoin(baseurl, iurl, False)
|
iurl = urljoin(baseurl, iurl, False)
|
||||||
if not self.is_link_ok(iurl):
|
if not self.is_link_ok(iurl):
|
||||||
self.log.debug('Skipping invalid link:', iurl)
|
self.log.debug('Skipping invalid link:', iurl)
|
||||||
return None
|
return None
|
||||||
@ -457,12 +458,12 @@ class RecursiveFetcher(object):
|
|||||||
return iurl
|
return iurl
|
||||||
|
|
||||||
def normurl(self, url):
|
def normurl(self, url):
|
||||||
parts = list(urlparse.urlsplit(url))
|
parts = list(urlsplit(url))
|
||||||
parts[4] = ''
|
parts[4] = ''
|
||||||
return urlparse.urlunsplit(parts)
|
return urlunsplit(parts)
|
||||||
|
|
||||||
def localize_link(self, tag, key, path):
|
def localize_link(self, tag, key, path):
|
||||||
parts = urlparse.urlsplit(tag[key])
|
parts = urlsplit(tag[key])
|
||||||
suffix = ('#'+parts.fragment) if parts.fragment else ''
|
suffix = ('#'+parts.fragment) if parts.fragment else ''
|
||||||
tag[key] = path+suffix
|
tag[key] = path+suffix
|
||||||
|
|
||||||
@ -547,7 +548,7 @@ class RecursiveFetcher(object):
|
|||||||
|
|
||||||
if newbaseurl and not newbaseurl.startswith('/'):
|
if newbaseurl and not newbaseurl.startswith('/'):
|
||||||
for atag in soup.findAll('a', href=lambda x: x and x.startswith('/')):
|
for atag in soup.findAll('a', href=lambda x: x and x.startswith('/')):
|
||||||
atag['href'] = urlparse.urljoin(newbaseurl, atag['href'], True)
|
atag['href'] = urljoin(newbaseurl, atag['href'], True)
|
||||||
if callable(self.postprocess_html_ext):
|
if callable(self.postprocess_html_ext):
|
||||||
soup = self.postprocess_html_ext(soup,
|
soup = self.postprocess_html_ext(soup,
|
||||||
c==0 and recursion_level==0 and not getattr(self, 'called_first', False),
|
c==0 and recursion_level==0 and not getattr(self, 'called_first', False),
|
||||||
|
10
src/polyglot/queue.py
Normal file
10
src/polyglot/queue.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#!/usr/bin/env python2
|
||||||
|
# vim:fileencoding=utf-8
|
||||||
|
# License: GPL v3 Copyright: 2019, Eli Schwartz <eschwartz@archlinux.org>
|
||||||
|
|
||||||
|
from polyglot.builtins import is_py3
|
||||||
|
|
||||||
|
if is_py3:
|
||||||
|
from queue import * # noqa
|
||||||
|
else:
|
||||||
|
from Queue import * # noqa
|
@ -2,14 +2,22 @@
|
|||||||
# vim:fileencoding=utf-8
|
# vim:fileencoding=utf-8
|
||||||
# License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
|
||||||
from polyglot.builtins import is_py3
|
from polyglot.builtins import is_py3
|
||||||
|
|
||||||
if is_py3:
|
if is_py3:
|
||||||
from urllib.request import urlopen, Request # noqa
|
from urllib.request import (build_opener, getproxies, install_opener, # noqa
|
||||||
from urllib.parse import urlencode # noqa
|
HTTPBasicAuthHandler, HTTPCookieProcessor, HTTPDigestAuthHandler, # noqa
|
||||||
|
url2pathname, urlopen, Request) # noqa
|
||||||
|
from urllib.parse import (parse_qs, quote, unquote, quote_plus, urldefrag, # noqa
|
||||||
|
urlencode, urljoin, urlparse, urlunparse, urlsplit, urlunsplit) # noqa
|
||||||
|
from urllib.error import HTTPError, URLError # noqa
|
||||||
else:
|
else:
|
||||||
from urllib import urlencode # noqa
|
from urllib import (getproxies, quote, unquote, quote_plus, url2pathname, # noqa
|
||||||
from urllib2 import urlopen, Request # noqa
|
urlencode) # noqa
|
||||||
|
from urllib2 import (build_opener, install_opener, HTTPBasicAuthHandler, # noqa
|
||||||
|
HTTPCookieProcessor, HTTPDigestAuthHandler, HTTPError, URLError, # noqa
|
||||||
|
urlopen, Request) # noqa
|
||||||
|
from urlparse import (parse_qs, urldefrag, urljoin, urlparse, urlunparse, # noqa
|
||||||
|
urlsplit, urlunsplit) # noqa
|
||||||
|
Loading…
x
Reference in New Issue
Block a user