diff --git a/src/calibre/ebooks/lrf/meta.py b/src/calibre/ebooks/lrf/meta.py index 6a60e4c63d..555dd1d6d9 100644 --- a/src/calibre/ebooks/lrf/meta.py +++ b/src/calibre/ebooks/lrf/meta.py @@ -374,9 +374,9 @@ class LRFMetaFile(object): return res return restore_pos locals_ = func() - if locals_.has_key("fget"): # noqa + if 'fget' in locals_: locals_["fget"] = decorator(locals_["fget"]) - if locals_.has_key("fset"): # noqa + if 'fset' in locals_: locals_["fset"] = decorator(locals_["fset"]) return property(**locals_) diff --git a/src/calibre/ebooks/lrf/pylrs/pylrf.py b/src/calibre/ebooks/lrf/pylrs/pylrf.py index 3b21c25402..d0e58f7f59 100644 --- a/src/calibre/ebooks/lrf/pylrs/pylrf.py +++ b/src/calibre/ebooks/lrf/pylrs/pylrf.py @@ -9,7 +9,7 @@ import io import codecs import os -from pylrfopt import tagListOptimizer +from .pylrfopt import tagListOptimizer from polyglot.builtins import iteritems, string_or_bytes PYLRF_VERSION = "1.0" diff --git a/src/calibre/ebooks/lrf/pylrs/pylrs.py b/src/calibre/ebooks/lrf/pylrs/pylrs.py index d5aac7767c..f13e703a0b 100644 --- a/src/calibre/ebooks/lrf/pylrs/pylrs.py +++ b/src/calibre/ebooks/lrf/pylrs/pylrs.py @@ -42,7 +42,7 @@ from xml.sax.saxutils import escape from datetime import date from xml.etree.ElementTree import Element, SubElement, ElementTree -from pylrf import (LrfWriter, LrfObject, LrfTag, LrfToc, +from .pylrf import (LrfWriter, LrfObject, LrfTag, LrfToc, STREAM_COMPRESSED, LrfTagStream, LrfStreamBase, IMAGE_TYPE_ENCODING, BINDING_DIRECTION_ENCODING, LINE_TYPE_ENCODING, LrfFileStream, STREAM_FORCE_COMPRESSED) @@ -1153,7 +1153,7 @@ class TextStyle(LrsStyle): "rubyadjust", "rubyalign", "rubyoverhang", "empdotsposition", 'emplinetype', 'emplineposition'] - validSettings = baseDefaults.keys() + alsoAllow + validSettings = list(baseDefaults) + alsoAllow defaults = baseDefaults.copy() @@ -1214,7 +1214,7 @@ class PageStyle(LrsStyle): alsoAllow = ["header", "evenheader", "oddheader", "footer", "evenfooter", "oddfooter"] - validSettings = baseDefaults.keys() + alsoAllow + validSettings = list(baseDefaults) + alsoAllow defaults = baseDefaults.copy() @classmethod diff --git a/src/calibre/ebooks/metadata/kdl.py b/src/calibre/ebooks/metadata/kdl.py index 66460569cb..b95284193a 100644 --- a/src/calibre/ebooks/metadata/kdl.py +++ b/src/calibre/ebooks/metadata/kdl.py @@ -14,13 +14,13 @@ from calibre.ebooks.metadata.book.base import Metadata from calibre import browser from calibre.ebooks.BeautifulSoup import BeautifulSoup 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, range from polyglot.urllib import parse_qs, quote_plus URL = \ "http://ww2.kdl.org/libcat/WhatsNext.asp?AuthorLastName={0}&AuthorFirstName=&SeriesName=&BookTitle={1}&CategoryID=0&cmdSearch=Search&Search=1&grouping=" -_ignore_starts = u'\'"'+u''.join(codepoint_to_chr(x) for x in range(0x2018, 0x201e)+[0x2032, 0x2033]) +_ignore_starts = u'\'"'+u''.join(codepoint_to_chr(x) for x in list(range(0x2018, 0x201e))+[0x2032, 0x2033]) def get_series(title, authors, timeout=60): diff --git a/src/calibre/ebooks/mobi/writer8/skeleton.py b/src/calibre/ebooks/mobi/writer8/skeleton.py index 418c0858fc..7b6cf31a1a 100644 --- a/src/calibre/ebooks/mobi/writer8/skeleton.py +++ b/src/calibre/ebooks/mobi/writer8/skeleton.py @@ -34,9 +34,9 @@ aid_able_tags = {'a', 'abbr', 'address', 'article', 'aside', 'audio', 'b', 'span', 'strong', 'sub', 'summary', 'sup', 'textarea', 'time', 'ul', 'var', 'video'} -_self_closing_pat = re.compile(bytes( +_self_closing_pat = re.compile( r'<(?P%s)(?=[\s/])(?P[^>]*)/>'%('|'.join(aid_able_tags|{'script', - 'style', 'title', 'head'}))), + 'style', 'title', 'head'})).encode('ascii'), re.IGNORECASE) diff --git a/src/calibre/ebooks/pml/__init__.py b/src/calibre/ebooks/pml/__init__.py index 9435504b5e..c01caf569d 100644 --- a/src/calibre/ebooks/pml/__init__.py +++ b/src/calibre/ebooks/pml/__init__.py @@ -4,15 +4,22 @@ __license__ = 'GPL v3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' +from polyglot.builtins import range + + +def r(*a): + return list(range(*a)) + + # Uncommon Characters supported by PML. \\a tag codes -A_CHARS = range(160, 256) + range(130, 136) + range(138, 141) + \ - range(145, 152) + range(153, 157) + [159] +A_CHARS = r(160, 256) + r(130, 136) + r(138, 141) + \ + r(145, 152) + r(153, 157) + [159] # Extended Unicode characters supported by PML -Latin_ExtendedA = range(0x0100, 0x0104) + [0x0105, 0x0107, 0x010C, 0x010D, +Latin_ExtendedA = r(0x0100, 0x0104) + [0x0105, 0x0107, 0x010C, 0x010D, 0x0112, 0x0113, 0x0115, 0x0117, 0x0119, 0x011B, 0x011D, 0x011F, 0x012A, 0x012B, 0x012D, 0x012F, 0x0131, 0x0141, 0x0142, 0x0144, 0x0148] + \ - range(0x014B, 0x014E) + [0x014F, 0x0151, 0x0155] + range(0x0159, 0x015C) + \ + r(0x014B, 0x014E) + [0x014F, 0x0151, 0x0155] + r(0x0159, 0x015C) + \ [0x015F, 0x0163, 0x0169, 0x016B, 0x016D, 0x0177, 0x017A, 0x017D, 0x017E] Latin_ExtendedB = [0x01BF, 0x01CE, 0x01D0, 0x01D2, 0x01D4, 0x01E1, 0x01E3, 0x01E7, 0x01EB, 0x01F0, 0x0207, 0x021D, 0x0227, 0x022F, 0x0233] @@ -20,23 +27,23 @@ IPA_Extensions = [0x0251, 0x0251, 0x0254, 0x0259, 0x025C, 0x0265, 0x026A, 0x0272, 0x0283, 0x0289, 0x028A, 0x028C, 0x028F, 0x0292, 0x0294, 0x029C] Spacing_Modifier_Letters = [0x02BE, 0x02BF, 0x02C7, 0x02C8, 0x02CC, 0x02D0, 0x02D8, 0x02D9] -Greek_and_Coptic = range(0x0391, 0x03A2) + range(0x03A3, 0x03AA) + \ - range(0x03B1, 0x03CA) + [0x03D1, 0x03DD] -Hebrew = range(0x05D0, 0x05EB) +Greek_and_Coptic = r(0x0391, 0x03A2) + r(0x03A3, 0x03AA) + \ + r(0x03B1, 0x03CA) + [0x03D1, 0x03DD] +Hebrew = r(0x05D0, 0x05EB) Latin_Extended_Additional = [0x1E0B, 0x1E0D, 0x1E17, 0x1E22, 0x1E24, 0x1E25, 0x1E2B, 0x1E33, 0x1E37, 0x1E41, 0x1E43, 0x1E45, 0x1E47, 0x1E53] + \ - range(0x1E59, 0x1E5C) + [0x1E61, 0x1E63, 0x1E6B, 0x1E6D, 0x1E6F, 0x1E91, + r(0x1E59, 0x1E5C) + [0x1E61, 0x1E63, 0x1E6B, 0x1E6D, 0x1E6F, 0x1E91, 0x1E93, 0x1E96, 0x1EA1, 0x1ECD, 0x1EF9] General_Punctuation = [0x2011, 0x2038, 0x203D, 0x2042] Arrows = [0x2190, 0x2192] Mathematical_Operators = [0x2202, 0x221A, 0x221E, 0x2225, 0x222B, 0x2260, 0x2294, 0x2295, 0x22EE] Enclosed_Alphanumerics = [0x24CA] -Miscellaneous_Symbols = range(0x261C, 0x2641) + range(0x2642, 0x2648) + \ - range(0x2660, 0x2664) + range(0x266D, 0x2670) +Miscellaneous_Symbols = r(0x261C, 0x2641) + r(0x2642, 0x2648) + \ + r(0x2660, 0x2664) + r(0x266D, 0x2670) Dingbats = [0x2713, 0x2720] -Private_Use_Area = range(0xE000, 0xE01D) + range(0xE01E, 0xE029) + \ - range(0xE02A, 0xE052) +Private_Use_Area = r(0xE000, 0xE01D) + r(0xE01E, 0xE029) + \ + r(0xE02A, 0xE052) Alphabetic_Presentation_Forms = [0xFB02, 0xFB2A, 0xFB2B] # \\U tag codes. diff --git a/src/calibre/ebooks/readability/readability.py b/src/calibre/ebooks/readability/readability.py index 46ccbc8a14..7c20851b41 100644 --- a/src/calibre/ebooks/readability/readability.py +++ b/src/calibre/ebooks/readability/readability.py @@ -156,7 +156,7 @@ class Document: continue # try again else: return cleaned_article - except StandardError as e: + except Exception as e: self.log.exception('error getting summary: ') reraise(Unparseable, Unparseable(str(e)), sys.exc_info()[2]) diff --git a/src/calibre/ebooks/textile/__init__.py b/src/calibre/ebooks/textile/__init__.py index 74141ed884..1acbfc38fc 100644 --- a/src/calibre/ebooks/textile/__init__.py +++ b/src/calibre/ebooks/textile/__init__.py @@ -1,4 +1,4 @@ -from functions import textile, textile_restricted, Textile +from .functions import textile, textile_restricted, Textile if False: textile, textile_restricted, Textile diff --git a/src/calibre/gui2/catalog/catalog_epub_mobi.py b/src/calibre/gui2/catalog/catalog_epub_mobi.py index 20977b9cfd..08a99d5089 100644 --- a/src/calibre/gui2/catalog/catalog_epub_mobi.py +++ b/src/calibre/gui2/catalog/catalog_epub_mobi.py @@ -18,7 +18,7 @@ from calibre.utils.icu import sort_key from calibre.utils.localization import localize_user_manual_link from polyglot.builtins import unicode_type -from catalog_epub_mobi_ui import Ui_Form +from .catalog_epub_mobi_ui import Ui_Form from PyQt5.Qt import (Qt, QAbstractItemView, QCheckBox, QComboBox, QDoubleSpinBox, QIcon, QInputDialog, QLineEdit, QRadioButton, QSize, QSizePolicy, QTableWidget, QTableWidgetItem, QTextEdit, QToolButton, diff --git a/src/calibre/gui2/lrf_renderer/main.ui b/src/calibre/gui2/lrf_renderer/main.ui index f499e311ba..ad342ea394 100644 --- a/src/calibre/gui2/lrf_renderer/main.ui +++ b/src/calibre/gui2/lrf_renderer/main.ui @@ -204,7 +204,7 @@ BookView QGraphicsView -
bookview.h
+
calibre/gui2/lrf_renderer/bookview.h
diff --git a/src/calibre/gui2/store/config/chooser/chooser_widget.ui b/src/calibre/gui2/store/config/chooser/chooser_widget.ui index 8ff9fcc9df..f293ba89ee 100644 --- a/src/calibre/gui2/store/config/chooser/chooser_widget.ui +++ b/src/calibre/gui2/store/config/chooser/chooser_widget.ui @@ -127,7 +127,7 @@ ResultsView QTreeView -
results_view.h
+
calibre/gui2/store/config/chooser/results_view.h
HistoryLineEdit diff --git a/src/calibre/gui2/store/search/search.ui b/src/calibre/gui2/store/search/search.ui index 063853efd8..300bbd9d86 100644 --- a/src/calibre/gui2/store/search/search.ui +++ b/src/calibre/gui2/store/search/search.ui @@ -347,7 +347,7 @@ ResultsView QTreeView -
results_view.h
+
calibre/gui2/store/config/chooser/results_view.h
HistoryLineEdit2 diff --git a/src/calibre/gui2/store/stores/amazon_au_plugin.py b/src/calibre/gui2/store/stores/amazon_au_plugin.py index 54e980ac2b..885939172f 100644 --- a/src/calibre/gui2/store/stores/amazon_au_plugin.py +++ b/src/calibre/gui2/store/stores/amazon_au_plugin.py @@ -7,7 +7,10 @@ from __future__ import (unicode_literals, division, absolute_import, store_version = 5 # Needed for dynamic plugin loading from contextlib import closing -import urllib +try: + from urllib.parse import urlencode +except ImportError: + from urllib import urlencode from lxml import html @@ -44,7 +47,7 @@ def search_amazon(query, max_results=10, timeout=60, x = x.encode('utf-8') return x uquery = {asbytes(k):asbytes(v) for k, v in uquery.items()} - url = base_url + '?' + urllib.urlencode(uquery).decode('ascii') + url = base_url + '?' + urlencode(uquery).decode('ascii') br = browser(user_agent=get_user_agent()) counter = max_results diff --git a/src/calibre/gui2/store/stores/amazon_ca_plugin.py b/src/calibre/gui2/store/stores/amazon_ca_plugin.py index f05b0f986c..b0ee00e621 100644 --- a/src/calibre/gui2/store/stores/amazon_ca_plugin.py +++ b/src/calibre/gui2/store/stores/amazon_ca_plugin.py @@ -7,7 +7,10 @@ from __future__ import (unicode_literals, division, absolute_import, store_version = 7 # Needed for dynamic plugin loading from contextlib import closing -import urllib +try: + from urllib.parse import urlencode +except ImportError: + from urllib import urlencode from lxml import html @@ -44,7 +47,7 @@ def search_amazon(query, max_results=10, timeout=60, x = x.encode('utf-8') return x uquery = {asbytes(k):asbytes(v) for k, v in uquery.items()} - url = base_url + '?' + urllib.urlencode(uquery).decode('ascii') + url = base_url + '?' + urlencode(uquery).decode('ascii') br = browser(user_agent=get_user_agent()) counter = max_results diff --git a/src/calibre/gui2/store/stores/amazon_de_plugin.py b/src/calibre/gui2/store/stores/amazon_de_plugin.py index 6d6fca72d6..cfe98a78c9 100644 --- a/src/calibre/gui2/store/stores/amazon_de_plugin.py +++ b/src/calibre/gui2/store/stores/amazon_de_plugin.py @@ -7,7 +7,10 @@ from __future__ import (unicode_literals, division, absolute_import, store_version = 15 # Needed for dynamic plugin loading from contextlib import closing -import urllib +try: + from urllib.parse import urlencode +except ImportError: + from urllib import urlencode from lxml import html @@ -46,7 +49,7 @@ def search_amazon(query, max_results=10, timeout=60, x = x.encode('utf-8') return x uquery = {asbytes(k):asbytes(v) for k, v in uquery.items()} - url = base_url + '?' + urllib.urlencode(uquery).decode('ascii') + url = base_url + '?' + urlencode(uquery).decode('ascii') br = browser(user_agent=get_user_agent()) counter = max_results diff --git a/src/calibre/gui2/store/stores/amazon_es_plugin.py b/src/calibre/gui2/store/stores/amazon_es_plugin.py index 207625010c..e8726f7c9c 100644 --- a/src/calibre/gui2/store/stores/amazon_es_plugin.py +++ b/src/calibre/gui2/store/stores/amazon_es_plugin.py @@ -7,7 +7,10 @@ from __future__ import (unicode_literals, division, absolute_import, store_version = 15 # Needed for dynamic plugin loading from contextlib import closing -import urllib +try: + from urllib.parse import urlencode +except ImportError: + from urllib2 import urlencode from lxml import html @@ -46,7 +49,7 @@ def search_amazon(query, max_results=10, timeout=60, x = x.encode('utf-8') return x uquery = {asbytes(k):asbytes(v) for k, v in uquery.items()} - url = base_url + '?' + urllib.urlencode(uquery).decode('ascii') + url = base_url + '?' + urlencode(uquery).decode('ascii') br = browser(user_agent=get_user_agent()) counter = max_results diff --git a/src/calibre/gui2/store/stores/amazon_fr_plugin.py b/src/calibre/gui2/store/stores/amazon_fr_plugin.py index f4b3209619..ffed87b0c1 100644 --- a/src/calibre/gui2/store/stores/amazon_fr_plugin.py +++ b/src/calibre/gui2/store/stores/amazon_fr_plugin.py @@ -7,7 +7,10 @@ from __future__ import (unicode_literals, division, absolute_import, store_version = 15 # Needed for dynamic plugin loading from contextlib import closing -import urllib +try: + from urllib.parse import urlencode +except ImportError: + from urllib import urlencode from lxml import html @@ -46,7 +49,7 @@ def search_amazon(query, max_results=10, timeout=60, x = x.encode('utf-8') return x uquery = {asbytes(k):asbytes(v) for k, v in uquery.items()} - url = base_url + '?' + urllib.urlencode(uquery).decode('ascii') + url = base_url + '?' + urlencode(uquery).decode('ascii') br = browser(user_agent=get_user_agent()) counter = max_results diff --git a/src/calibre/gui2/store/stores/amazon_in_plugin.py b/src/calibre/gui2/store/stores/amazon_in_plugin.py index 1c4494e24e..5fe67d5ebc 100644 --- a/src/calibre/gui2/store/stores/amazon_in_plugin.py +++ b/src/calibre/gui2/store/stores/amazon_in_plugin.py @@ -7,7 +7,10 @@ from __future__ import (unicode_literals, division, absolute_import, store_version = 5 # Needed for dynamic plugin loading from contextlib import closing -import urllib +try: + from urllib.parse import urlencode +except ImportError: + from urllib import urlencode from lxml import html @@ -44,7 +47,7 @@ def search_amazon(query, max_results=10, timeout=60, x = x.encode('utf-8') return x uquery = {asbytes(k):asbytes(v) for k, v in uquery.items()} - url = base_url + '?' + urllib.urlencode(uquery).decode('ascii') + url = base_url + '?' + urlencode(uquery).decode('ascii') br = browser(user_agent=get_user_agent()) counter = max_results diff --git a/src/calibre/gui2/store/stores/amazon_it_plugin.py b/src/calibre/gui2/store/stores/amazon_it_plugin.py index 7dc3887bd1..b7040f50a2 100644 --- a/src/calibre/gui2/store/stores/amazon_it_plugin.py +++ b/src/calibre/gui2/store/stores/amazon_it_plugin.py @@ -7,7 +7,10 @@ from __future__ import (unicode_literals, division, absolute_import, store_version = 15 # Needed for dynamic plugin loading from contextlib import closing -import urllib +try: + from urllib.parse import urlencode +except ImportError: + from urllib import urlencode from lxml import html @@ -46,7 +49,7 @@ def search_amazon(query, max_results=10, timeout=60, x = x.encode('utf-8') return x uquery = {asbytes(k):asbytes(v) for k, v in uquery.items()} - url = base_url + '?' + urllib.urlencode(uquery).decode('ascii') + url = base_url + '?' + urlencode(uquery).decode('ascii') br = browser(user_agent=get_user_agent()) counter = max_results diff --git a/src/calibre/gui2/store/stores/amazon_plugin.py b/src/calibre/gui2/store/stores/amazon_plugin.py index e9543e3605..22a8b3a9c2 100644 --- a/src/calibre/gui2/store/stores/amazon_plugin.py +++ b/src/calibre/gui2/store/stores/amazon_plugin.py @@ -7,7 +7,10 @@ from __future__ import (unicode_literals, division, absolute_import, store_version = 16 # Needed for dynamic plugin loading from contextlib import closing -import urllib +try: + from urllib.parse import urlencode +except ImportError: + from urllib import urlencode from lxml import html, etree @@ -44,7 +47,7 @@ def search_amazon(query, max_results=10, timeout=60, x = x.encode('utf-8') return x uquery = {asbytes(k):asbytes(v) for k, v in uquery.items()} - url = base_url + '?' + urllib.urlencode(uquery).decode('ascii') + url = base_url + '?' + urlencode(uquery).decode('ascii') br = browser(user_agent=get_user_agent()) counter = max_results diff --git a/src/calibre/gui2/store/stores/amazon_uk_plugin.py b/src/calibre/gui2/store/stores/amazon_uk_plugin.py index 3dae69f495..3e4808c5f3 100644 --- a/src/calibre/gui2/store/stores/amazon_uk_plugin.py +++ b/src/calibre/gui2/store/stores/amazon_uk_plugin.py @@ -7,7 +7,10 @@ from __future__ import (unicode_literals, division, absolute_import, store_version = 15 # Needed for dynamic plugin loading from contextlib import closing -import urllib +try: + from urllib.parse import urlencode +except ImportError: + from urllib import urlencode from lxml import html @@ -44,7 +47,7 @@ def search_amazon(query, max_results=10, timeout=60, x = x.encode('utf-8') return x uquery = {asbytes(k):asbytes(v) for k, v in uquery.items()} - url = base_url + '?' + urllib.urlencode(uquery).decode('ascii') + url = base_url + '?' + urlencode(uquery).decode('ascii') br = browser(user_agent=get_user_agent()) counter = max_results diff --git a/src/calibre/gui2/store/stores/baen_webscription_plugin.py b/src/calibre/gui2/store/stores/baen_webscription_plugin.py index 7542737f56..6ff7b82857 100644 --- a/src/calibre/gui2/store/stores/baen_webscription_plugin.py +++ b/src/calibre/gui2/store/stores/baen_webscription_plugin.py @@ -7,8 +7,11 @@ __license__ = 'GPL 3' __copyright__ = '2011, John Schember ' __docformat__ = 'restructuredtext en' -from urllib import urlencode from contextlib import closing +try: + from urllib.parse import urlencode +except ImportError: + from urllib import urlencode from lxml import html diff --git a/src/calibre/gui2/store/stores/beam_ebooks_de_plugin.py b/src/calibre/gui2/store/stores/beam_ebooks_de_plugin.py index c84f67b3d5..ae6f9e810d 100644 --- a/src/calibre/gui2/store/stores/beam_ebooks_de_plugin.py +++ b/src/calibre/gui2/store/stores/beam_ebooks_de_plugin.py @@ -7,7 +7,10 @@ __license__ = 'GPL 3' __copyright__ = '2011, John Schember ' __docformat__ = 'restructuredtext en' -import urllib2 +try: + from urllib.parse import quote +except ImportError: + from urllib2 import quote from contextlib import closing from lxml import html @@ -41,7 +44,7 @@ class BeamEBooksDEStore(BasicStoreConfig, StorePlugin): d.exec_() def search(self, query, max_results=10, timeout=60): - url = 'https://www.beam-shop.de/search?saltFieldLimitation=all&sSearch=' + urllib2.quote(query) + url = 'https://www.beam-shop.de/search?saltFieldLimitation=all&sSearch=' + quote(query) br = browser() counter = max_results diff --git a/src/calibre/gui2/store/stores/bn_plugin.py b/src/calibre/gui2/store/stores/bn_plugin.py index 774c6e7fcb..30164199b9 100644 --- a/src/calibre/gui2/store/stores/bn_plugin.py +++ b/src/calibre/gui2/store/stores/bn_plugin.py @@ -8,8 +8,11 @@ __copyright__ = '2011, John Schember ' __docformat__ = 'restructuredtext en' import re -import urllib from contextlib import closing +try: + from urllib.parse import quote_plus +except ImportError: + from urllib import quote_plus from lxml import html @@ -37,7 +40,7 @@ class BNStore(BasicStoreConfig, StorePlugin): d.exec_() def search(self, query, max_results=10, timeout=60): - url = 'http://www.barnesandnoble.com/s/%s?keyword=%s&store=ebook&view=list' % (query.replace(' ', '-'), urllib.quote_plus(query)) + url = 'http://www.barnesandnoble.com/s/%s?keyword=%s&store=ebook&view=list' % (query.replace(' ', '-'), quote_plus(query)) br = browser() diff --git a/src/calibre/gui2/store/stores/bubok_portugal_plugin.py b/src/calibre/gui2/store/stores/bubok_portugal_plugin.py index c61d5a9cab..25971359dd 100644 --- a/src/calibre/gui2/store/stores/bubok_portugal_plugin.py +++ b/src/calibre/gui2/store/stores/bubok_portugal_plugin.py @@ -7,8 +7,11 @@ __license__ = 'GPL 3' __copyright__ = '2014, Rafael Vega ' __docformat__ = 'restructuredtext en' -import urllib from contextlib import closing +try: + from urllib.parse import quote_plus +except ImportError: + from urllib import quote_plus from lxml import html @@ -35,7 +38,7 @@ class BubokPortugalStore(BasicStoreConfig, StorePlugin): d.exec_() def search(self, query, max_results=10, timeout=60): - url = 'http://www.bubok.pt/resellers/calibre_search/' + urllib.quote_plus(query) + url = 'http://www.bubok.pt/resellers/calibre_search/' + quote_plus(query) br = browser() @@ -72,4 +75,3 @@ class BubokPortugalStore(BasicStoreConfig, StorePlugin): def get_details(self, search_result, timeout): return True - diff --git a/src/calibre/gui2/store/stores/bubok_publishing_plugin.py b/src/calibre/gui2/store/stores/bubok_publishing_plugin.py index e8d672e51f..6e7c88e30f 100644 --- a/src/calibre/gui2/store/stores/bubok_publishing_plugin.py +++ b/src/calibre/gui2/store/stores/bubok_publishing_plugin.py @@ -7,8 +7,11 @@ __license__ = 'GPL 3' __copyright__ = '2014, Rafael Vega ' __docformat__ = 'restructuredtext en' -import urllib from contextlib import closing +try: + from urllib.parse import quote_plus +except ImportError: + from urllib import quote_plus from lxml import html @@ -35,7 +38,7 @@ class BubokPublishingStore(BasicStoreConfig, StorePlugin): d.exec_() def search(self, query, max_results=10, timeout=60): - url = 'http://www.bubok.es/resellers/calibre_search/' + urllib.quote_plus(query) + url = 'http://www.bubok.es/resellers/calibre_search/' + quote_plus(query) br = browser() @@ -72,4 +75,3 @@ class BubokPublishingStore(BasicStoreConfig, StorePlugin): def get_details(self, search_result, timeout): return True - diff --git a/src/calibre/gui2/store/stores/chitanka_plugin.py b/src/calibre/gui2/store/stores/chitanka_plugin.py index 052c6fb751..9467735552 100644 --- a/src/calibre/gui2/store/stores/chitanka_plugin.py +++ b/src/calibre/gui2/store/stores/chitanka_plugin.py @@ -8,8 +8,12 @@ __copyright__ = '2011, Alex Stanev ' __docformat__ = 'restructuredtext en' import re -import urllib2 from contextlib import closing +try: + from urllib.parse import quote + from urllib.error import HTTPError +except ImportError: + from urllib import quote, HTTPError from lxml import html @@ -51,7 +55,7 @@ class ChitankaStore(BasicStoreConfig, StorePlugin): return base_url = 'http://chitanka.info' - url = base_url + '/search?q=' + urllib2.quote(query) + url = base_url + '/search?q=' + quote(query) counter = max_results # search for book title @@ -82,7 +86,7 @@ class ChitankaStore(BasicStoreConfig, StorePlugin): s.downloads['TXT'] = base_url + ''.join(data.xpath('.//a[@class="dl dl-txt"]/@href')).strip().replace('.zip', '') s.formats = 'FB2, EPUB, TXT, SFB' yield s - except urllib2.HTTPError as e: + except HTTPError as e: if e.code == 404: return else: diff --git a/src/calibre/gui2/store/stores/ebook_nl_plugin.py b/src/calibre/gui2/store/stores/ebook_nl_plugin.py index f5c5a50587..d9b94e2b03 100644 --- a/src/calibre/gui2/store/stores/ebook_nl_plugin.py +++ b/src/calibre/gui2/store/stores/ebook_nl_plugin.py @@ -7,8 +7,11 @@ __license__ = 'GPL 3' __copyright__ = '2011, John Schember ' __docformat__ = 'restructuredtext en' -import urllib2 from contextlib import closing +try: + from urllib.parse import quote +except ImportError: + from urllib import quote from lxml import html @@ -42,7 +45,7 @@ class EBookNLStore(BasicStoreConfig, StorePlugin): d.exec_() def search(self, query, max_results=10, timeout=60): - url = ('http://www.ebook.nl/store/advanced_search_result.php?keywords=' + urllib2.quote(query)) + url = ('http://www.ebook.nl/store/advanced_search_result.php?keywords=' + quote(query)) br = browser() counter = max_results diff --git a/src/calibre/gui2/store/stores/ebookpoint_plugin.py b/src/calibre/gui2/store/stores/ebookpoint_plugin.py index d2cf0e557e..47e50c61f6 100644 --- a/src/calibre/gui2/store/stores/ebookpoint_plugin.py +++ b/src/calibre/gui2/store/stores/ebookpoint_plugin.py @@ -8,9 +8,12 @@ __copyright__ = '2011-2016, Tomasz Długosz ' __docformat__ = 'restructuredtext en' import re -import urllib from base64 import b64encode from contextlib import closing +try: + from urllib.parse import quote_plus +except ImportError: + from urllib import quote_plus from lxml import html @@ -55,7 +58,7 @@ class EbookpointStore(BasicStoreConfig, StorePlugin): d.exec_() def search(self, query, max_results=25, timeout=60): - url = 'http://ebookpoint.pl/search?qa=&szukaj=' + urllib.quote_plus( + url = 'http://ebookpoint.pl/search?qa=&szukaj=' + quote_plus( query.decode('utf-8').encode('iso-8859-2')) + '&serwisyall=0&wprzyg=0&wsprzed=1&wyczerp=0&formaty=em-p' br = browser() diff --git a/src/calibre/gui2/store/stores/ebooks_com_plugin.py b/src/calibre/gui2/store/stores/ebooks_com_plugin.py index 170db0a5bd..542d5e6005 100644 --- a/src/calibre/gui2/store/stores/ebooks_com_plugin.py +++ b/src/calibre/gui2/store/stores/ebooks_com_plugin.py @@ -8,8 +8,11 @@ __copyright__ = '2011, John Schember ' __docformat__ = 'restructuredtext en' import re -import urllib from contextlib import closing +try: + from urllib.parse import quote_plus +except ImportError: + from urllib import quote_plus from lxml import html @@ -44,7 +47,7 @@ class EbookscomStore(BasicStoreConfig, StorePlugin): d.exec_() def search(self, query, max_results=10, timeout=60): - url = 'http://www.ebooks.com/SearchApp/SearchResults.net?term=' + urllib.quote_plus(query) + url = 'http://www.ebooks.com/SearchApp/SearchResults.net?term=' + quote_plus(query) br = browser() @@ -56,7 +59,7 @@ class EbookscomStore(BasicStoreConfig, StorePlugin): break id = ''.join(data.xpath('.//a[1]/@href')) - mo = re.search('\d+', id) + mo = re.search(r'\d+', id) if not mo: continue id = mo.group() diff --git a/src/calibre/gui2/store/stores/ebookshoppe_uk_plugin.py b/src/calibre/gui2/store/stores/ebookshoppe_uk_plugin.py index 9f34ccd677..bdef5fd85d 100644 --- a/src/calibre/gui2/store/stores/ebookshoppe_uk_plugin.py +++ b/src/calibre/gui2/store/stores/ebookshoppe_uk_plugin.py @@ -7,7 +7,10 @@ __license__ = 'GPL 3' __copyright__ = '2011, John Schember ' __docformat__ = 'restructuredtext en' -import urllib2 +try: + from urllib.parse import quote +except ImportError: + from urllib2 import quote from contextlib import closing from lxml import html @@ -42,7 +45,7 @@ class EBookShoppeUKStore(BasicStoreConfig, StorePlugin): d.exec_() def search(self, query, max_results=10, timeout=60): - url = 'http://www.ebookshoppe.com/search.php?search_query=' + urllib2.quote(query) + url = 'http://www.ebookshoppe.com/search.php?search_query=' + quote(query) br = browser() br.addheaders = [("Referer", "http://www.ebookshoppe.com/")] diff --git a/src/calibre/gui2/store/stores/eknigi_plugin.py b/src/calibre/gui2/store/stores/eknigi_plugin.py index f97dd41c5d..2be73deba1 100644 --- a/src/calibre/gui2/store/stores/eknigi_plugin.py +++ b/src/calibre/gui2/store/stores/eknigi_plugin.py @@ -9,8 +9,11 @@ __docformat__ = 'restructuredtext en' import re import random -import urllib2 from contextlib import closing +try: + from urllib.parse import quote +except ImportError: + from urllib import quote from lxml import html @@ -55,7 +58,7 @@ class eKnigiStore(BasicStoreConfig, StorePlugin): return base_url = 'http://e-knigi.net' - url = base_url + '/virtuemart?page=shop.browse&search_category=0&search_limiter=anywhere&keyword=' + urllib2.quote(query) + url = base_url + '/virtuemart?page=shop.browse&search_category=0&search_limiter=anywhere&keyword=' + quote(query) br = browser() diff --git a/src/calibre/gui2/store/stores/empik_plugin.py b/src/calibre/gui2/store/stores/empik_plugin.py index 6f2e6d0568..020cc8159e 100644 --- a/src/calibre/gui2/store/stores/empik_plugin.py +++ b/src/calibre/gui2/store/stores/empik_plugin.py @@ -8,9 +8,12 @@ __copyright__ = '2011-2017, Tomasz Długosz ' __docformat__ = 'restructuredtext en' import re -import urllib from base64 import b64encode from contextlib import closing +try: + from urllib.parse import quote +except ImportError: + from urllib import quote from lxml import html @@ -55,7 +58,7 @@ class EmpikStore(BasicStoreConfig, StorePlugin): d.exec_() def search(self, query, max_results=10, timeout=60): - url = 'http://www.empik.com/ebooki/ebooki,3501,s?resultsPP=' + str(max_results) + '&q=' + urllib.quote(query) + url = 'http://www.empik.com/ebooki/ebooki,3501,s?resultsPP=' + str(max_results) + '&q=' + quote(query) br = browser() diff --git a/src/calibre/gui2/store/stores/google_books_plugin.py b/src/calibre/gui2/store/stores/google_books_plugin.py index 239a0bdde1..e8ef2bb125 100644 --- a/src/calibre/gui2/store/stores/google_books_plugin.py +++ b/src/calibre/gui2/store/stores/google_books_plugin.py @@ -7,8 +7,11 @@ __license__ = 'GPL 3' __copyright__ = '2011, John Schember ' __docformat__ = 'restructuredtext en' -import urllib from contextlib import closing +try: + from urllib.parse import quote_plus +except ImportError: + from urllib import quote_plus from lxml import html from PyQt5.Qt import QUrl @@ -33,7 +36,7 @@ def parse_html(raw): def search_google(query, max_results=10, timeout=60, write_html_to=None): - url = 'https://www.google.com/search?tbm=bks&q=' + urllib.quote_plus(query) + url = 'https://www.google.com/search?tbm=bks&q=' + quote_plus(query) br = browser() diff --git a/src/calibre/gui2/store/stores/gutenberg_plugin.py b/src/calibre/gui2/store/stores/gutenberg_plugin.py index dc58626d01..5fe6d91c33 100644 --- a/src/calibre/gui2/store/stores/gutenberg_plugin.py +++ b/src/calibre/gui2/store/stores/gutenberg_plugin.py @@ -10,8 +10,11 @@ __docformat__ = 'restructuredtext en' import base64 import mimetypes import re -import urllib from contextlib import closing +try: + from urllib.parse import quote_plus +except ImportError: + from urllib import quote_plus from lxml import etree @@ -31,7 +34,7 @@ def fix_url(url): def search(query, max_results=10, timeout=60, write_raw_to=None): - url = 'http://m.gutenberg.org/ebooks/search.opds/?query=' + urllib.quote_plus(query) + url = 'http://m.gutenberg.org/ebooks/search.opds/?query=' + quote_plus(query) counter = max_results br = browser(user_agent='calibre/'+__version__) diff --git a/src/calibre/gui2/store/stores/kobo_plugin.py b/src/calibre/gui2/store/stores/kobo_plugin.py index 578803c081..0b6e09221b 100644 --- a/src/calibre/gui2/store/stores/kobo_plugin.py +++ b/src/calibre/gui2/store/stores/kobo_plugin.py @@ -7,8 +7,11 @@ __license__ = 'GPL 3' __copyright__ = '2011, John Schember ' __docformat__ = 'restructuredtext en' -import urllib from contextlib import closing +try: + from urllib.parse import quote_plus +except ImportError: + from urllib import quote_plus from lxml import html, etree @@ -23,7 +26,7 @@ from calibre.gui2.store.web_store_dialog import WebStoreDialog def search_kobo(query, max_results=10, timeout=60, write_html_to=None): from css_selectors import Select - url = 'https://www.kobobooks.com/search/search.html?q=' + urllib.quote_plus(query) + url = 'https://www.kobobooks.com/search/search.html?q=' + quote_plus(query) br = browser() @@ -89,7 +92,7 @@ class KoboStore(BasicStoreConfig, StorePlugin): murl = 'https://click.linksynergy.com/fs-bin/click?id=%s&subid=&offerid=280046.1&type=10&tmpid=9310&RD_PARM1=http%%3A%%2F%%2Fkobo.com' % pub_id if detail_item: - purl = 'https://click.linksynergy.com/link?id=%s&offerid=280046&type=2&murl=%s' % (pub_id, urllib.quote_plus(detail_item)) + purl = 'https://click.linksynergy.com/link?id=%s&offerid=280046&type=2&murl=%s' % (pub_id, quote_plus(detail_item)) url = purl else: purl = None diff --git a/src/calibre/gui2/store/stores/legimi_plugin.py b/src/calibre/gui2/store/stores/legimi_plugin.py index 3c8c80ac80..d7e20e9d65 100644 --- a/src/calibre/gui2/store/stores/legimi_plugin.py +++ b/src/calibre/gui2/store/stores/legimi_plugin.py @@ -8,9 +8,12 @@ __copyright__ = '2011-2017, Tomasz Długosz ' __docformat__ = 'restructuredtext en' import re -import urllib from base64 import b64encode from contextlib import closing +try: + from urllib.parse import quote_plus +except ImportError: + from urllib import quote_plus from lxml import html @@ -55,7 +58,7 @@ class LegimiStore(BasicStoreConfig, StorePlugin): d.exec_() def search(self, query, max_results=10, timeout=60): - url = 'https://www.legimi.pl/ebooki/?szukaj=' + urllib.quote_plus(query) + url = 'https://www.legimi.pl/ebooki/?szukaj=' + quote_plus(query) br = browser() diff --git a/src/calibre/gui2/store/stores/libri_de_plugin.py b/src/calibre/gui2/store/stores/libri_de_plugin.py index ffb3a02c98..8c250a83f2 100644 --- a/src/calibre/gui2/store/stores/libri_de_plugin.py +++ b/src/calibre/gui2/store/stores/libri_de_plugin.py @@ -7,8 +7,11 @@ __license__ = 'GPL 3' __copyright__ = '2011, John Schember ' __docformat__ = 'restructuredtext en' -import urllib2 from contextlib import closing +try: + from urllib.parse import quote +except ImportError: + from urllib import quote from lxml import html @@ -43,7 +46,7 @@ class LibreDEStore(BasicStoreConfig, StorePlugin): d.exec_() def search(self, query, max_results=10, timeout=60): - url = ('http://www.ebook.de/de/pathSearch?nav=52122&searchString=' + urllib2.quote(query)) + url = ('http://www.ebook.de/de/pathSearch?nav=52122&searchString=' + quote(query)) br = browser() counter = max_results diff --git a/src/calibre/gui2/store/stores/litres_plugin.py b/src/calibre/gui2/store/stores/litres_plugin.py index 13b342cb0a..3536577f5a 100644 --- a/src/calibre/gui2/store/stores/litres_plugin.py +++ b/src/calibre/gui2/store/stores/litres_plugin.py @@ -9,7 +9,10 @@ __docformat__ = 'restructuredtext en' import random import re -import urllib2 +try: + from urllib.parse import quote +except ImportError: + from urllib import quote from contextlib import closing from lxml import etree @@ -37,7 +40,7 @@ class LitResStore(BasicStoreConfig, StorePlugin): if detail_item: # http://www.litres.ru/pages/biblio_book/?art=157074 detail_url = self.shop_url + u'/pages/biblio_book/' + aff_id +\ - u'&art=' + urllib2.quote(detail_item) + u'&art=' + quote(detail_item) if external or self.config.get('open_external', False): open_url(QUrl(url_slash_cleaner(detail_url if detail_url else url))) @@ -50,7 +53,7 @@ class LitResStore(BasicStoreConfig, StorePlugin): def search(self, query, max_results=10, timeout=60): search_url = u'http://robot.litres.ru/pages/catalit_browser/?checkpoint=2000-01-02&'\ 'search=%s&limit=0,%s' - search_url = search_url % (urllib2.quote(query), max_results) + search_url = search_url % (quote(query), max_results) counter = max_results br = browser() diff --git a/src/calibre/gui2/store/stores/mills_boon_uk_plugin.py b/src/calibre/gui2/store/stores/mills_boon_uk_plugin.py index 0efc1a34ca..ec1798304a 100644 --- a/src/calibre/gui2/store/stores/mills_boon_uk_plugin.py +++ b/src/calibre/gui2/store/stores/mills_boon_uk_plugin.py @@ -7,8 +7,11 @@ __license__ = 'GPL 3' __copyright__ = '2011, John Schember ' __docformat__ = 'restructuredtext en' -import urllib2 from contextlib import closing +try: + from urllib.parse import quote +except ImportError: + from urllib import quote from lxml import html @@ -43,7 +46,7 @@ class MillsBoonUKStore(BasicStoreConfig, StorePlugin): def search(self, query, max_results=10, timeout=60): base_url = 'https://www.millsandboon.co.uk' - url = base_url + '/search.aspx??format=ebook&searchText=' + urllib2.quote(query) + url = base_url + '/search.aspx??format=ebook&searchText=' + quote(query) br = browser() counter = max_results diff --git a/src/calibre/gui2/store/stores/nexto_plugin.py b/src/calibre/gui2/store/stores/nexto_plugin.py index 52a89bfc91..49f9c08e85 100644 --- a/src/calibre/gui2/store/stores/nexto_plugin.py +++ b/src/calibre/gui2/store/stores/nexto_plugin.py @@ -8,8 +8,11 @@ __copyright__ = '2011-2016, Tomasz Długosz ' __docformat__ = 'restructuredtext en' import re -import urllib from contextlib import closing +try: + from urllib.parse import quote_plus +except ImportError: + from urllib import quote_plus from lxml import html @@ -46,7 +49,7 @@ class NextoStore(BasicStoreConfig, StorePlugin): d.exec_() def search(self, query, max_results=10, timeout=60): - url = 'http://www.nexto.pl/szukaj.xml?search-clause=' + urllib.quote_plus(query) + '&scid=1015' + url = 'http://www.nexto.pl/szukaj.xml?search-clause=' + quote_plus(query) + '&scid=1015' br = browser() offset=0 diff --git a/src/calibre/gui2/store/stores/open_books_plugin.py b/src/calibre/gui2/store/stores/open_books_plugin.py index e91fb423ad..69b30b4b41 100644 --- a/src/calibre/gui2/store/stores/open_books_plugin.py +++ b/src/calibre/gui2/store/stores/open_books_plugin.py @@ -7,8 +7,11 @@ __license__ = 'GPL 3' __copyright__ = '2011, John Schember ' __docformat__ = 'restructuredtext en' -import urllib from contextlib import closing +try: + from urllib.parse import quote_plus +except ImportError: + from urllib import quote_plus from lxml import html @@ -36,7 +39,7 @@ class OpenBooksStore(BasicStoreConfig, StorePlugin): d.exec_() def search(self, query, max_results=10, timeout=60): - url = 'https://drmfree.calibre-ebook.com/search/?q=' + urllib.quote_plus(query) + url = 'https://drmfree.calibre-ebook.com/search/?q=' + quote_plus(query) br = browser() diff --git a/src/calibre/gui2/store/stores/ozon_ru_plugin.py b/src/calibre/gui2/store/stores/ozon_ru_plugin.py index 9ad9acfa7d..158ccda849 100644 --- a/src/calibre/gui2/store/stores/ozon_ru_plugin.py +++ b/src/calibre/gui2/store/stores/ozon_ru_plugin.py @@ -7,8 +7,11 @@ __license__ = 'GPL 3' __copyright__ = '2011-2013, Roman Mukhin ' __docformat__ = 'restructuredtext en' -import urllib from contextlib import closing +try: + from urllib.parse import quote_plus +except ImportError: + from urllib import quote_plus from PyQt5.Qt import QUrl @@ -34,7 +37,7 @@ def parse_html(raw): def search(query, max_results=15, timeout=60): - url = 'http://www.ozon.ru/?context=search&text=%s&store=1,0&group=div_book' % urllib.quote_plus(query) + url = 'http://www.ozon.ru/?context=search&text=%s&store=1,0&group=div_book' % quote_plus(query) counter = max_results br = browser() diff --git a/src/calibre/gui2/store/stores/publio_plugin.py b/src/calibre/gui2/store/stores/publio_plugin.py index bf8913c529..2769975ff4 100644 --- a/src/calibre/gui2/store/stores/publio_plugin.py +++ b/src/calibre/gui2/store/stores/publio_plugin.py @@ -7,7 +7,10 @@ __license__ = 'GPL 3' __copyright__ = '2012-2017, Tomasz Długosz ' __docformat__ = 'restructuredtext en' -import urllib +try: + from urllib.parse import quote +except ImportError: + from urllib import quote from base64 import b64encode from contextlib import closing @@ -59,7 +62,7 @@ class PublioStore(BasicStoreConfig, StorePlugin): counter = max_results page = 1 while counter: - with closing(br.open('http://www.publio.pl/e-booki,strona' + str(page) + '.html?q=' + urllib.quote(query), timeout=timeout)) as f: # noqa + with closing(br.open('http://www.publio.pl/e-booki,strona' + str(page) + '.html?q=' + quote(query), timeout=timeout)) as f: # noqa doc = html.fromstring(f.read()) for data in doc.xpath('//div[@class="products-list"]//div[@class="product-tile"]'): if counter <= 0: diff --git a/src/calibre/gui2/store/stores/rw2010_plugin.py b/src/calibre/gui2/store/stores/rw2010_plugin.py index 1bc56884ea..e4a65d2a14 100644 --- a/src/calibre/gui2/store/stores/rw2010_plugin.py +++ b/src/calibre/gui2/store/stores/rw2010_plugin.py @@ -8,8 +8,11 @@ __copyright__ = '2011, Tomasz Długosz ' __docformat__ = 'restructuredtext en' import re -import urllib from contextlib import closing +try: + from urllib.parse import urlencode +except ImportError: + from urllib import urlencode from lxml import html @@ -46,7 +49,7 @@ class RW2010Store(BasicStoreConfig, StorePlugin): br = browser() counter = max_results - with closing(br.open(url, data=urllib.urlencode(values), timeout=timeout)) as f: + with closing(br.open(url, data=urlencode(values), timeout=timeout)) as f: doc = html.fromstring(f.read()) for data in doc.xpath('//div[@class="ProductDetail"]'): if counter <= 0: diff --git a/src/calibre/gui2/store/stores/smashwords_plugin.py b/src/calibre/gui2/store/stores/smashwords_plugin.py index 753af70569..329a43bc0b 100644 --- a/src/calibre/gui2/store/stores/smashwords_plugin.py +++ b/src/calibre/gui2/store/stores/smashwords_plugin.py @@ -9,8 +9,11 @@ __docformat__ = 'restructuredtext en' import random import re -import urllib2 from contextlib import closing +try: + from urllib.parse import quote +except ImportError: + from urllib import quote from lxml import html @@ -25,7 +28,7 @@ from calibre.gui2.store.web_store_dialog import WebStoreDialog def search(query, max_results=10, timeout=60): - url = 'https://www.smashwords.com/books/search?query=' + urllib2.quote(query) + url = 'https://www.smashwords.com/books/search?query=' + quote(query) br = browser() try: diff --git a/src/calibre/gui2/store/stores/swiatebookow_plugin.py b/src/calibre/gui2/store/stores/swiatebookow_plugin.py index f680eed78a..12d7f356e5 100644 --- a/src/calibre/gui2/store/stores/swiatebookow_plugin.py +++ b/src/calibre/gui2/store/stores/swiatebookow_plugin.py @@ -7,9 +7,12 @@ __license__ = 'GPL 3' __copyright__ = '2017, Tomasz Długosz ' __docformat__ = 'restructuredtext en' -import urllib from base64 import b64encode from contextlib import closing +try: + from urllib.parse import quote +except ImportError: + from urllib import quote from lxml import html @@ -60,7 +63,7 @@ class SwiatEbookowStore(BasicStoreConfig, StorePlugin): counter = max_results while counter: - with closing(br.open('https://www.swiatebookow.pl/ebooki/?q=' + urllib.quote(query) + '&page=' + str(page), timeout=timeout)) as f: + with closing(br.open('https://www.swiatebookow.pl/ebooki/?q=' + quote(query) + '&page=' + str(page), timeout=timeout)) as f: doc = html.fromstring(f.read().decode('utf-8')) for data in doc.xpath('//div[@class="category-item-container"]//div[@class="book-large"]'): if counter <= 0: diff --git a/src/calibre/gui2/store/stores/virtualo_plugin.py b/src/calibre/gui2/store/stores/virtualo_plugin.py index bdd484e722..9298933676 100644 --- a/src/calibre/gui2/store/stores/virtualo_plugin.py +++ b/src/calibre/gui2/store/stores/virtualo_plugin.py @@ -8,9 +8,12 @@ __copyright__ = '2011-2017, Tomasz Długosz ' __docformat__ = 'restructuredtext en' import re -import urllib from base64 import b64encode from contextlib import closing +try: + from urllib.parse import quote +except ImportError: + from urllib import quote from lxml import html @@ -55,7 +58,7 @@ class VirtualoStore(BasicStoreConfig, StorePlugin): d.exec_() def search(self, query, max_results=12, timeout=60): - url = 'http://virtualo.pl/?q=' + urllib.quote(query) + url = 'http://virtualo.pl/?q=' + quote(query) br = browser() no_drm_pattern = re.compile(r'Watermark|Brak') diff --git a/src/calibre/gui2/store/stores/weightless_books_plugin.py b/src/calibre/gui2/store/stores/weightless_books_plugin.py index 258a854f78..407dccc3fe 100644 --- a/src/calibre/gui2/store/stores/weightless_books_plugin.py +++ b/src/calibre/gui2/store/stores/weightless_books_plugin.py @@ -7,8 +7,11 @@ __license__ = 'GPL 3' __copyright__ = '2011, John Schember ' __docformat__ = 'restructuredtext en' -import urllib from contextlib import closing +try: + from urllib.parse import quote_plus +except ImportError: + from urllib2 import quote_plus from lxml import html @@ -36,7 +39,7 @@ class WeightlessBooksStore(BasicStoreConfig, StorePlugin): d.exec_() def search(self, query, max_results=10, timeout=60): - url = 'http://weightlessbooks.com/?s=' + urllib.quote_plus(query) + url = 'http://weightlessbooks.com/?s=' + quote_plus(query) br = browser() diff --git a/src/calibre/gui2/store/stores/whsmith_uk_plugin.py b/src/calibre/gui2/store/stores/whsmith_uk_plugin.py index 1fba7fdb62..030aaf3f40 100644 --- a/src/calibre/gui2/store/stores/whsmith_uk_plugin.py +++ b/src/calibre/gui2/store/stores/whsmith_uk_plugin.py @@ -7,8 +7,11 @@ __license__ = 'GPL 3' __copyright__ = '2011, John Schember ' __docformat__ = 'restructuredtext en' -import urllib2 from contextlib import closing +try: + from urllib.parse import quote +except ImportError: + from urllib import quote from lxml import html @@ -43,7 +46,7 @@ class WHSmithUKStore(BasicStoreConfig, StorePlugin): def search(self, query, max_results=10, timeout=60): url = ('http://www.whsmith.co.uk/search?keywordCategoryId=wc_dept_ebooks&results=60' - '&page=1&keywords=' + urllib2.quote(query)) + '&page=1&keywords=' + quote(query)) br = browser() diff --git a/src/calibre/gui2/store/stores/woblink_plugin.py b/src/calibre/gui2/store/stores/woblink_plugin.py index bdcd95a8d9..258a12a0cf 100644 --- a/src/calibre/gui2/store/stores/woblink_plugin.py +++ b/src/calibre/gui2/store/stores/woblink_plugin.py @@ -7,8 +7,11 @@ __license__ = 'GPL 3' __copyright__ = '2011-2017, Tomasz Długosz ' __docformat__ = 'restructuredtext en' -import urllib from base64 import b64encode +try: + from urllib.parse import urlencode, quote_plus +except ImportError: + from urllib import urlencode, quote_plus from lxml import html from mechanize import Request @@ -33,7 +36,7 @@ def as_base64(data): def search(query, max_results=10, timeout=60): - url = 'http://woblink.com/publication/ajax?mode=none&query=' + urllib.quote_plus(query.encode('utf-8')) + url = 'http://woblink.com/publication/ajax?mode=none&query=' + quote_plus(query.encode('utf-8')) if max_results > 10: if max_results > 20: url += '&limit=30' @@ -46,7 +49,7 @@ def search(query, max_results=10, timeout=60): 'X-Requested-With': 'XMLHttpRequest', 'Referrer':'http://woblink.com/ebooki-kategorie', 'Cache-Control':'max-age=0', - }, data=urllib.urlencode({ + }, data=urlencode({ 'nw_filtry_filtr_zakrescen_formularz[min]':'0', 'nw_filtry_filtr_zakrescen_formularz[max]':'350', })) diff --git a/src/calibre/gui2/store/stores/wolnelektury_plugin.py b/src/calibre/gui2/store/stores/wolnelektury_plugin.py index 702162e066..18358d61b6 100644 --- a/src/calibre/gui2/store/stores/wolnelektury_plugin.py +++ b/src/calibre/gui2/store/stores/wolnelektury_plugin.py @@ -7,8 +7,11 @@ __license__ = 'GPL 3' __copyright__ = '2012-2014, Tomasz Długosz ' __docformat__ = 'restructuredtext en' -import urllib from contextlib import closing +try: + from urllib.parse import quote_plus +except ImportError: + from urllib import quote_plus from lxml import html @@ -41,7 +44,7 @@ class WolneLekturyStore(BasicStoreConfig, StorePlugin): d.exec_() def search(self, query, max_results=10, timeout=60): - url = 'http://wolnelektury.pl/szukaj?q=' + urllib.quote_plus(query.encode('utf-8')) + url = 'http://wolnelektury.pl/szukaj?q=' + quote_plus(query.encode('utf-8')) br = browser() diff --git a/src/calibre/gui2/store/stores/xinxii_plugin.py b/src/calibre/gui2/store/stores/xinxii_plugin.py index b38e0841b3..4e69a4d295 100644 --- a/src/calibre/gui2/store/stores/xinxii_plugin.py +++ b/src/calibre/gui2/store/stores/xinxii_plugin.py @@ -7,8 +7,11 @@ __license__ = 'GPL 3' __copyright__ = '2011, John Schember ' __docformat__ = 'restructuredtext en' -import urllib from contextlib import closing +try: + from urllib.parse import quote_plus +except ImportError: + from urllib import quote_plus from lxml import etree @@ -39,7 +42,7 @@ class XinXiiStore(BasicStoreConfig, OpenSearchOPDSStore): function so this one is modified to remove parts that are used. ''' - url = 'http://www.xinxii.com/catalog-search/query/?keywords=' + urllib.quote_plus(query) + url = 'http://www.xinxii.com/catalog-search/query/?keywords=' + quote_plus(query) counter = max_results br = browser() diff --git a/src/odf/anim.py b/src/odf/anim.py index 27dca36ca8..4addbc2c77 100644 --- a/src/odf/anim.py +++ b/src/odf/anim.py @@ -18,8 +18,8 @@ # Contributor(s): # -from namespaces import ANIMNS -from element import Element +from .namespaces import ANIMNS +from .element import Element # Autogenerated @@ -58,4 +58,3 @@ def Set(**args): def Transitionfilter(**args): return Element(qname = (ANIMNS,'transitionFilter'), **args) - diff --git a/src/odf/attrconverters.py b/src/odf/attrconverters.py index 1ebc173961..d3a411d5cb 100644 --- a/src/odf/attrconverters.py +++ b/src/odf/attrconverters.py @@ -17,7 +17,7 @@ # # Contributor(s): # -from namespaces import * +from .namespaces import * import re, types pattern_color = re.compile(r'#[0-9a-fA-F]{6}') diff --git a/src/odf/chart.py b/src/odf/chart.py index cca83961ac..8c3d005ac3 100644 --- a/src/odf/chart.py +++ b/src/odf/chart.py @@ -18,8 +18,8 @@ # Contributor(s): # -from namespaces import CHARTNS -from element import Element +from .namespaces import CHARTNS +from .element import Element # Autogenerated def Axis(**args): @@ -84,4 +84,3 @@ def Title(**args): def Wall(**args): return Element(qname = (CHARTNS,'wall'), **args) - diff --git a/src/odf/config.py b/src/odf/config.py index f33f361396..966bedca8a 100644 --- a/src/odf/config.py +++ b/src/odf/config.py @@ -18,8 +18,8 @@ # Contributor(s): # -from namespaces import CONFIGNS -from element import Element +from .namespaces import CONFIGNS +from .element import Element # Autogenerated def ConfigItem(**args): @@ -36,4 +36,3 @@ def ConfigItemMapNamed(**args): def ConfigItemSet(**args): return Element(qname = (CONFIGNS, 'config-item-set'), **args) - diff --git a/src/odf/dc.py b/src/odf/dc.py index 7c967768bb..387e6dbfa8 100644 --- a/src/odf/dc.py +++ b/src/odf/dc.py @@ -18,8 +18,8 @@ # Contributor(s): # -from namespaces import DCNS -from element import Element +from .namespaces import DCNS +from .element import Element # Autogenerated def Creator(**args): diff --git a/src/odf/dr3d.py b/src/odf/dr3d.py index 324ae1cf4f..f6d7a28768 100644 --- a/src/odf/dr3d.py +++ b/src/odf/dr3d.py @@ -18,9 +18,9 @@ # Contributor(s): # -from namespaces import DR3DNS -from element import Element -from draw import StyleRefElement +from .namespaces import DR3DNS +from .element import Element +from .draw import StyleRefElement # Autogenerated def Cube(**args): @@ -40,4 +40,3 @@ def Scene(**args): def Sphere(**args): return StyleRefElement(qname = (DR3DNS,'sphere'), **args) - diff --git a/src/odf/draw.py b/src/odf/draw.py index 8e8c798ad6..af324bcccd 100644 --- a/src/odf/draw.py +++ b/src/odf/draw.py @@ -18,8 +18,8 @@ # Contributor(s): # -from namespaces import DRAWNS, STYLENS, PRESENTATIONNS -from element import Element +from .namespaces import DRAWNS, STYLENS, PRESENTATIONNS +from .element import Element def StyleRefElement(stylename=None, classnames=None, **args): qattrs = {} diff --git a/src/odf/element.py b/src/odf/element.py index b0a4b3d406..b3a2b4befd 100644 --- a/src/odf/element.py +++ b/src/odf/element.py @@ -24,9 +24,9 @@ # import xml.dom from xml.dom.minicompat import * -from namespaces import nsdict -import grammar -from attrconverters import AttrConverters +from .namespaces import nsdict +from . import grammar +from .attrconverters import AttrConverters # The following code is pasted form xml.sax.saxutils # Tt makes it possible to run the code without the xml sax package installed @@ -80,9 +80,9 @@ def _nsassign(namespace): return nsdict.setdefault(namespace,"ns" + str(len(nsdict))) # Exceptions -class IllegalChild(StandardError): +class IllegalChild(Exception): """ Complains if you add an element to a parent where it is not allowed """ -class IllegalText(StandardError): +class IllegalText(Exception): """ Complains if you add text or cdata to an element where it is not allowed """ class Node(xml.dom.Node): @@ -255,7 +255,7 @@ class Text(Childless, Node): if self.data: f.write(_escape(type(u'')(self.data).encode('utf-8'))) -class CDATASection(Childless, Text): +class CDATASection(Text, Childless): nodeType = Node.CDATA_SECTION_NODE def toXml(self,level,f): diff --git a/src/odf/elementtypes.py b/src/odf/elementtypes.py index 345e61556a..9450b08510 100644 --- a/src/odf/elementtypes.py +++ b/src/odf/elementtypes.py @@ -19,7 +19,7 @@ # Contributor(s): # -from namespaces import * +from .namespaces import * # Inline element don't cause a box # They are analogous to the HTML elements SPAN, B, I etc. diff --git a/src/odf/form.py b/src/odf/form.py index 7969b84018..8b5a35911c 100644 --- a/src/odf/form.py +++ b/src/odf/form.py @@ -18,8 +18,8 @@ # Contributor(s): # -from namespaces import FORMNS -from element import Element +from .namespaces import FORMNS +from .element import Element # Autogenerated diff --git a/src/odf/grammar.py b/src/odf/grammar.py index d5d8d5970e..69b55bbd27 100644 --- a/src/odf/grammar.py +++ b/src/odf/grammar.py @@ -23,7 +23,7 @@ Currently it contains the legal child elements of a given element. To be used for validation check in the API """ -from namespaces import * +from .namespaces import * # The following code is generated from the RelaxNG schema with this notice: diff --git a/src/odf/load.py b/src/odf/load.py index dbf6c65c77..2618d7877b 100644 --- a/src/odf/load.py +++ b/src/odf/load.py @@ -26,8 +26,8 @@ from __future__ import print_function from xml.sax import handler -from element import Element -from namespaces import OFFICENS +from .element import Element +from .namespaces import OFFICENS # # Parse the XML files diff --git a/src/odf/manifest.py b/src/odf/manifest.py index 82073987a9..0c11c1c3c6 100644 --- a/src/odf/manifest.py +++ b/src/odf/manifest.py @@ -20,8 +20,8 @@ # # -from namespaces import MANIFESTNS -from element import Element +from .namespaces import MANIFESTNS +from .element import Element # Autogenerated def Manifest(**args): @@ -38,4 +38,3 @@ def Algorithm(**args): def KeyDerivation(**args): return Element(qname = (MANIFESTNS,'key-derivation'), **args) - diff --git a/src/odf/math.py b/src/odf/math.py index 5dc38dfad3..498987d93d 100644 --- a/src/odf/math.py +++ b/src/odf/math.py @@ -18,8 +18,8 @@ # Contributor(s): # -from namespaces import MATHNS -from element import Element +from .namespaces import MATHNS +from .element import Element # ODF 1.0 section 12.5 # Mathematical content is represented by MathML 2.0 diff --git a/src/odf/meta.py b/src/odf/meta.py index dc0318117a..94d41b527e 100644 --- a/src/odf/meta.py +++ b/src/odf/meta.py @@ -18,8 +18,8 @@ # Contributor(s): # -from namespaces import METANS -from element import Element +from .namespaces import METANS +from .element import Element # Autogenerated def AutoReload(**args): diff --git a/src/odf/number.py b/src/odf/number.py index 12d81cba16..3587d1e7fb 100644 --- a/src/odf/number.py +++ b/src/odf/number.py @@ -18,9 +18,9 @@ # Contributor(s): # -from namespaces import NUMBERNS -from element import Element -from style import StyleElement +from .namespaces import NUMBERNS +from .element import Element +from .style import StyleElement # Autogenerated @@ -101,4 +101,3 @@ def WeekOfYear(**args): def Year(**args): return Element(qname = (NUMBERNS,'year'), **args) - diff --git a/src/odf/odf2moinmoin.py b/src/odf/odf2moinmoin.py index 167fcdacb5..aa52ec03d3 100644 --- a/src/odf/odf2moinmoin.py +++ b/src/odf/odf2moinmoin.py @@ -20,9 +20,9 @@ # Contributor(s): # -import sys, zipfile, xml.dom.minidom -from namespaces import nsdict -from elementtypes import * +import zipfile, xml.dom.minidom +from .namespaces import nsdict +from .elementtypes import * IGNORED_TAGS = [ 'draw:a' diff --git a/src/odf/odf2xhtml.py b/src/odf/odf2xhtml.py index b252bd256f..66a46a616e 100644 --- a/src/odf/odf2xhtml.py +++ b/src/odf/odf2xhtml.py @@ -25,9 +25,9 @@ from xml.sax import handler from xml.sax.saxutils import escape, quoteattr from xml.dom import Node -from opendocument import load +from .opendocument import load -from namespaces import ANIMNS, CHARTNS, CONFIGNS, DCNS, DR3DNS, DRAWNS, FONS, \ +from .namespaces import ANIMNS, CHARTNS, CONFIGNS, DCNS, DR3DNS, DRAWNS, FONS, \ FORMNS, MATHNS, METANS, NUMBERNS, OFFICENS, PRESENTATIONNS, SCRIPTNS, \ SMILNS, STYLENS, SVGNS, TABLENS, TEXTNS, XLINKNS diff --git a/src/odf/office.py b/src/odf/office.py index 085e251d09..eca47ad2a9 100644 --- a/src/odf/office.py +++ b/src/odf/office.py @@ -18,9 +18,9 @@ # Contributor(s): # -from namespaces import OFFICENS -from element import Element -from draw import StyleRefElement +from .namespaces import OFFICENS +from .element import Element +from .draw import StyleRefElement # Autogenerated def Annotation(**args): diff --git a/src/odf/opendocument.py b/src/odf/opendocument.py index 023f330e88..d3a67962e8 100644 --- a/src/odf/opendocument.py +++ b/src/odf/opendocument.py @@ -20,15 +20,13 @@ __doc__="""Use OpenDocument to generate your documents.""" -import zipfile, time, sys, mimetypes, copy -from cStringIO import StringIO -from namespaces import * -import manifest, meta -from office import * -import element -from attrconverters import make_NCName +import zipfile, time, sys, mimetypes +from .namespaces import * +from . import manifest, meta, element +from .office import * +from .attrconverters import make_NCName from xml.sax.xmlreader import InputSource -from odfmanifest import manifestlist +from .odfmanifest import manifestlist from polyglot.io import PolyglotBytesIO __version__= TOOLSVERSION @@ -177,7 +175,7 @@ class OpenDocument: """ Generates the content.xml file Always written as a bytestream in UTF-8 encoding """ - xml=StringIO() + xml=PolyglotBytesIO() xml.write(_XMLPROLOGUE) x = DocumentContent() x.write_open_tag(0, xml) @@ -202,7 +200,7 @@ class OpenDocument: """ Generates the manifest.xml file The self.manifest isn't avaible unless the document is being saved """ - xml=StringIO() + xml=PolyglotBytesIO() xml.write(_XMLPROLOGUE) self.manifest.toXml(0,xml) return xml.getvalue() diff --git a/src/odf/presentation.py b/src/odf/presentation.py index c1f2135abb..71c3d833d0 100644 --- a/src/odf/presentation.py +++ b/src/odf/presentation.py @@ -18,8 +18,8 @@ # Contributor(s): # -from namespaces import PRESENTATIONNS -from element import Element +from .namespaces import PRESENTATIONNS +from .element import Element # ODF 1.0 section 9.6 and 9.7 # Autogenerated diff --git a/src/odf/script.py b/src/odf/script.py index adbc73f657..210e4eb152 100644 --- a/src/odf/script.py +++ b/src/odf/script.py @@ -18,8 +18,8 @@ # Contributor(s): # -from namespaces import SCRIPTNS -from element import Element +from .namespaces import SCRIPTNS +from .element import Element # ODF 1.0 section 12.4.1 # The element binds an event to a macro. diff --git a/src/odf/style.py b/src/odf/style.py index f64d7c8217..76dc4a53be 100644 --- a/src/odf/style.py +++ b/src/odf/style.py @@ -18,8 +18,8 @@ # Contributor(s): # -from namespaces import STYLENS -from element import Element +from .namespaces import STYLENS +from .element import Element def StyleElement(**args): e = Element(**args) diff --git a/src/odf/svg.py b/src/odf/svg.py index 346c4904dd..d56df6c746 100644 --- a/src/odf/svg.py +++ b/src/odf/svg.py @@ -18,8 +18,8 @@ # Contributor(s): # -from namespaces import SVGNS -from element import Element +from .namespaces import SVGNS +from .element import Element from draw import DrawElement # Autogenerated diff --git a/src/odf/table.py b/src/odf/table.py index 4ba0c36e9b..5d27881edb 100644 --- a/src/odf/table.py +++ b/src/odf/table.py @@ -18,8 +18,8 @@ # Contributor(s): # -from namespaces import TABLENS -from element import Element +from .namespaces import TABLENS +from .element import Element # Autogenerated diff --git a/src/odf/text.py b/src/odf/text.py index b55a3a4a91..ba0487767c 100644 --- a/src/odf/text.py +++ b/src/odf/text.py @@ -18,9 +18,9 @@ # Contributor(s): # -from namespaces import TEXTNS -from element import Element -from style import StyleElement +from .namespaces import TEXTNS +from .element import Element +from .style import StyleElement # Autogenerated def A(**args): @@ -559,4 +559,3 @@ def VariableSet(**args): def WordCount(**args): return Element(qname = (TEXTNS,'word-count'), **args) - diff --git a/src/odf/xforms.py b/src/odf/xforms.py index f28b96e254..bbc05acda0 100644 --- a/src/odf/xforms.py +++ b/src/odf/xforms.py @@ -18,8 +18,8 @@ # Contributor(s): # -from namespaces import XFORMSNS -from element import Element +from .namespaces import XFORMSNS +from .element import Element # ODF 1.0 section 11.2 # XForms is designed to be embedded in another XML format.