From ed26d34961c61c4cdb299b5d69d83c7eb67cba2f Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Mon, 4 Oct 2021 18:26:46 +0200 Subject: [PATCH] Code cleaning (remove python2) --- cps.py | 11 +++-------- cps/__init__.py | 12 +++--------- cps/about.py | 1 - cps/admin.py | 1 - cps/cache_buster.py | 1 - cps/cli.py | 14 -------------- cps/comic.py | 1 - cps/config_sql.py | 6 ------ cps/constants.py | 8 +------- cps/converter.py | 1 - cps/db.py | 3 --- cps/editbooks.py | 1 - cps/epub.py | 1 - cps/fb2.py | 1 - cps/gdrive.py | 6 +----- cps/gdriveutils.py | 1 - cps/helper.py | 8 +------- cps/isoLanguages.py | 2 -- cps/iso_language_names.py | 4 +--- cps/jinjia.py | 1 - cps/kobo.py | 5 +---- cps/logger.py | 1 - cps/oauth.py | 1 - cps/oauth_bb.py | 1 - cps/opds.py | 10 ++++------ cps/pagination.py | 1 - cps/redirect.py | 1 - cps/reverseproxy.py | 2 -- cps/search_metadata.py | 1 - cps/server.py | 1 - cps/services/SyncToken.py | 5 +---- cps/services/__init__.py | 2 -- cps/services/gmail.py | 19 +++++++++++++++++- cps/services/goodreads_support.py | 1 - cps/services/simpleldap.py | 1 - cps/services/worker.py | 18 ++++++++++++++++- cps/shelf.py | 2 -- cps/subproc_wrapper.py | 8 +------- cps/tasks/convert.py | 27 +++++++++++++++++--------- cps/tasks/mail.py | 32 ++++++++++++++++++------------- cps/tasks/upload.py | 18 ++++++++++++++++- cps/ub.py | 1 - cps/updater.py | 1 - cps/uploader.py | 1 - cps/web.py | 10 ++-------- 45 files changed, 108 insertions(+), 146 deletions(-) diff --git a/cps.py b/cps.py index 161b1655..ab9896ce 100755 --- a/cps.py +++ b/cps.py @@ -17,18 +17,13 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from __future__ import absolute_import, division, print_function, unicode_literals import sys import os # Insert local directories into path -if sys.version_info < (3, 0): - sys.path.append(os.path.dirname(os.path.abspath(__file__.decode('utf-8')))) - sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__.decode('utf-8'))), 'vendor')) -else: - sys.path.append(os.path.dirname(os.path.abspath(__file__))) - sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'vendor')) +sys.path.append(os.path.dirname(os.path.abspath(__file__))) +sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'vendor')) from cps import create_app @@ -49,7 +44,7 @@ try: from cps.kobo import kobo, get_kobo_activated from cps.kobo_auth import kobo_auth kobo_available = get_kobo_activated() -except (ImportError, AttributeError): # Catch also error for not installed flask-wtf (missing csrf decorator) +except (ImportError, AttributeError): # Catch also error for not installed flask-WTF (missing csrf decorator) kobo_available = False try: diff --git a/cps/__init__.py b/cps/__init__.py index f1143d9d..f38ce0d2 100644 --- a/cps/__init__.py +++ b/cps/__init__.py @@ -20,7 +20,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from __future__ import division, print_function, unicode_literals import sys import os import mimetypes @@ -118,16 +117,11 @@ def create_app(): print('*** "lxml" is needed for calibre-web to run. Please install it using pip: "pip install lxml" ***') sys.exit(6) if not wtf_present: - log.info('*** "flask-wtf" is needed for calibre-web to run. Please install it using pip: "pip install flask-wtf" ***') - print('*** "flask-wtf" is needed for calibre-web to run. Please install it using pip: "pip install flask-wtf" ***') - sys.exit(7) + log.info('*** "flask-WTF" is needed for calibre-web to run. Please install it using pip: "pip install flask-WTF" ***') + print('*** "flask-WTF" is needed for calibre-web to run. Please install it using pip: "pip install flask-WTF" ***') + # sys.exit(7) app.wsgi_app = ReverseProxied(app.wsgi_app) - # For python2 convert path to unicode - if sys.version_info < (3, 0): - app.static_folder = app.static_folder.decode('utf-8') - app.root_path = app.root_path.decode('utf-8') - app.instance_path = app.instance_path.decode('utf-8') if os.environ.get('FLASK_DEBUG'): cache_buster.init_cache_busting(app) diff --git a/cps/about.py b/cps/about.py index 31a16552..f3c8b95f 100644 --- a/cps/about.py +++ b/cps/about.py @@ -20,7 +20,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from __future__ import division, print_function, unicode_literals import sys import platform import sqlite3 diff --git a/cps/admin.py b/cps/admin.py index 2a65e53a..6d6c3ba2 100644 --- a/cps/admin.py +++ b/cps/admin.py @@ -20,7 +20,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from __future__ import division, print_function, unicode_literals import os import re import base64 diff --git a/cps/cache_buster.py b/cps/cache_buster.py index 8c521fe1..9619d605 100644 --- a/cps/cache_buster.py +++ b/cps/cache_buster.py @@ -19,7 +19,6 @@ # Inspired by https://github.com/ChrisTM/Flask-CacheBust # Uses query strings so CSS font files are found without having to resort to absolute URLs -from __future__ import division, print_function, unicode_literals import os import hashlib diff --git a/cps/cli.py b/cps/cli.py index 3bb08c1f..3685e8e2 100644 --- a/cps/cli.py +++ b/cps/cli.py @@ -16,7 +16,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from __future__ import division, print_function, unicode_literals import sys import os import argparse @@ -48,19 +47,6 @@ parser.add_argument('-s', metavar='user:pass', help='Sets specific username to n parser.add_argument('-f', action='store_true', help='Flag is depreciated and will be removed in next version') args = parser.parse_args() -if sys.version_info < (3, 0): - if args.p: - args.p = args.p.decode('utf-8') - if args.g: - args.g = args.g.decode('utf-8') - if args.k: - args.k = args.k.decode('utf-8') - if args.c: - args.c = args.c.decode('utf-8') - if args.s: - args.s = args.s.decode('utf-8') - - settingspath = args.p or os.path.join(_CONFIG_DIR, "app.db") gdpath = args.g or os.path.join(_CONFIG_DIR, "gdrive.db") diff --git a/cps/comic.py b/cps/comic.py index 462c11f0..b094c60f 100644 --- a/cps/comic.py +++ b/cps/comic.py @@ -16,7 +16,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from __future__ import division, print_function, unicode_literals import os from . import logger, isoLanguages diff --git a/cps/config_sql.py b/cps/config_sql.py index 88107f9b..232de145 100644 --- a/cps/config_sql.py +++ b/cps/config_sql.py @@ -16,8 +16,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . - -from __future__ import division, print_function, unicode_literals import os import sys import json @@ -361,10 +359,6 @@ def _migrate_table(session, orm_class): session.query(column).first() except OperationalError as err: log.debug("%s: %s", column_name, err.args[0]) - if column.default is not None: - if sys.version_info < (3, 0): - if isinstance(column.default.arg, unicode): - column.default.arg = column.default.arg.encode('utf-8') if column.default is None: column_default = "" else: diff --git a/cps/constants.py b/cps/constants.py index bfdee6da..367bc29d 100644 --- a/cps/constants.py +++ b/cps/constants.py @@ -16,7 +16,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from __future__ import division, print_function, unicode_literals import sys import os from collections import namedtuple @@ -31,12 +30,7 @@ HOME_CONFIG = os.path.isfile(os.path.join(os.path.dirname(os.path.abspath(__file UPDATER_AVAILABLE = True # Base dir is parent of current file, necessary if called from different folder -if sys.version_info < (3, 0): - BASE_DIR = os.path.abspath(os.path.join( - os.path.dirname(os.path.abspath(__file__)),os.pardir)).decode('utf-8') -else: - BASE_DIR = os.path.abspath(os.path.join( - os.path.dirname(os.path.abspath(__file__)),os.pardir)) +BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)),os.pardir)) STATIC_DIR = os.path.join(BASE_DIR, 'cps', 'static') TEMPLATES_DIR = os.path.join(BASE_DIR, 'cps', 'templates') TRANSLATIONS_DIR = os.path.join(BASE_DIR, 'cps', 'translations') diff --git a/cps/converter.py b/cps/converter.py index 6b0f22e4..fcbabbfc 100644 --- a/cps/converter.py +++ b/cps/converter.py @@ -16,7 +16,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from __future__ import division, print_function, unicode_literals import os import re from flask_babel import gettext as _ diff --git a/cps/db.py b/cps/db.py index cfb2ed7c..ab4f5bf5 100644 --- a/cps/db.py +++ b/cps/db.py @@ -17,7 +17,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from __future__ import division, print_function, unicode_literals import sys import os import re @@ -387,8 +386,6 @@ class Custom_Columns(Base): def get_display_dict(self): display_dict = ast.literal_eval(self.display) - if sys.version_info < (3, 0): - display_dict['enum_values'] = [x.decode('unicode_escape') for x in display_dict['enum_values']] return display_dict diff --git a/cps/editbooks.py b/cps/editbooks.py index ce06fbf4..063eba2a 100644 --- a/cps/editbooks.py +++ b/cps/editbooks.py @@ -20,7 +20,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from __future__ import division, print_function, unicode_literals import os from datetime import datetime import json diff --git a/cps/epub.py b/cps/epub.py index 998dbfa6..cbbdcbbd 100644 --- a/cps/epub.py +++ b/cps/epub.py @@ -16,7 +16,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from __future__ import division, print_function, unicode_literals import os import zipfile from lxml import etree diff --git a/cps/fb2.py b/cps/fb2.py index af4a29a7..21586736 100644 --- a/cps/fb2.py +++ b/cps/fb2.py @@ -16,7 +16,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from __future__ import division, print_function, unicode_literals from lxml import etree from .constants import BookMeta diff --git a/cps/gdrive.py b/cps/gdrive.py index c0764015..e2d8f166 100644 --- a/cps/gdrive.py +++ b/cps/gdrive.py @@ -20,7 +20,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from __future__ import division, print_function, unicode_literals import os import sys import hashlib @@ -137,10 +136,7 @@ def on_received_watch_confirmation(): response = gdriveutils.getChangeById(gdriveutils.Gdrive.Instance().drive, j['id']) log.debug('%r', response) if response: - if sys.version_info < (3, 0): - dbpath = os.path.join(config.config_calibre_dir, "metadata.db") - else: - dbpath = os.path.join(config.config_calibre_dir, "metadata.db").encode() + dbpath = os.path.join(config.config_calibre_dir, "metadata.db").encode() if not response['deleted'] and response['file']['title'] == 'metadata.db' \ and response['file']['md5Checksum'] != hashlib.md5(dbpath): # nosec tmp_dir = os.path.join(tempfile.gettempdir(), 'calibre_web') diff --git a/cps/gdriveutils.py b/cps/gdriveutils.py index c63b0393..d3277814 100644 --- a/cps/gdriveutils.py +++ b/cps/gdriveutils.py @@ -16,7 +16,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from __future__ import division, print_function, unicode_literals import os import json import shutil diff --git a/cps/helper.py b/cps/helper.py index f7b72a8d..df7019e6 100644 --- a/cps/helper.py +++ b/cps/helper.py @@ -17,7 +17,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from __future__ import division, print_function, unicode_literals import sys import os import io @@ -490,10 +489,7 @@ def reset_password(user_id): def generate_random_password(): s = "abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%&*()?" passlen = 8 - if sys.version_info < (3, 0): - return "".join(s[ord(c) % len(s)] for c in os.urandom(passlen)) - else: - return "".join(s[c % len(s)] for c in os.urandom(passlen)) + return "".join(s[c % len(s)] for c in os.urandom(passlen)) def uniq(inpt): @@ -707,8 +703,6 @@ def check_unrar(unrarLocation): return _('Unrar binary file not found') try: - if sys.version_info < (3, 0): - unrarLocation = unrarLocation.encode(sys.getfilesystemencoding()) unrarLocation = [unrarLocation] value = process_wait(unrarLocation, pattern='UNRAR (.*) freeware') if value: diff --git a/cps/isoLanguages.py b/cps/isoLanguages.py index 35d9f0a7..6c66a583 100644 --- a/cps/isoLanguages.py +++ b/cps/isoLanguages.py @@ -16,8 +16,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from __future__ import division, print_function, unicode_literals - from .iso_language_names import LANGUAGE_NAMES as _LANGUAGE_NAMES diff --git a/cps/iso_language_names.py b/cps/iso_language_names.py index d07158a0..9966ecd9 100644 --- a/cps/iso_language_names.py +++ b/cps/iso_language_names.py @@ -6,8 +6,6 @@ # pylint: disable=too-many-lines,bad-continuation -from __future__ import unicode_literals - # This file is autogenerated, do NOT add, change, or delete ANY string # If you need help or assistance for adding a new language, please contact the project team @@ -7855,4 +7853,4 @@ LANGUAGE_NAMES = { "zxx": "No linguistic content", "zza": "Zaza" } -} \ No newline at end of file +} diff --git a/cps/jinjia.py b/cps/jinjia.py index 554bc791..06e99141 100644 --- a/cps/jinjia.py +++ b/cps/jinjia.py @@ -22,7 +22,6 @@ # custom jinja filters -from __future__ import division, print_function, unicode_literals import datetime import mimetypes from uuid import uuid4 diff --git a/cps/kobo.py b/cps/kobo.py index ba9a8d1f..5ce2b640 100644 --- a/cps/kobo.py +++ b/cps/kobo.py @@ -492,10 +492,7 @@ def get_metadata(book): metadata.update(get_author(book)) if get_series(book): - if sys.version_info < (3, 0): - name = get_series(book).encode("utf-8") - else: - name = get_series(book) + name = get_series(book) metadata["Series"] = { "Name": get_series(book), "Number": get_seriesindex(book), # ToDo Check int() ? diff --git a/cps/logger.py b/cps/logger.py index e2747f53..5847188b 100644 --- a/cps/logger.py +++ b/cps/logger.py @@ -16,7 +16,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from __future__ import division, print_function, unicode_literals import os import sys import inspect diff --git a/cps/oauth.py b/cps/oauth.py index a8995180..f8e5c1fd 100644 --- a/cps/oauth.py +++ b/cps/oauth.py @@ -16,7 +16,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see -from __future__ import division, print_function, unicode_literals from flask import session try: diff --git a/cps/oauth_bb.py b/cps/oauth_bb.py index c8cc2e3e..d9efd41e 100644 --- a/cps/oauth_bb.py +++ b/cps/oauth_bb.py @@ -20,7 +20,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see -from __future__ import division, print_function, unicode_literals import json from functools import wraps diff --git a/cps/opds.py b/cps/opds.py index 2a615607..92c51d1b 100644 --- a/cps/opds.py +++ b/cps/opds.py @@ -20,7 +20,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from __future__ import division, print_function, unicode_literals import sys import datetime from functools import wraps @@ -537,11 +536,10 @@ def feed_search(term): def check_auth(username, password): - if sys.version_info.major == 3: - try: - username = username.encode('windows-1252') - except UnicodeEncodeError: - username = username.encode('utf-8') + try: + username = username.encode('windows-1252') + except UnicodeEncodeError: + username = username.encode('utf-8') user = ub.session.query(ub.User).filter(func.lower(ub.User.name) == username.decode('utf-8').lower()).first() if bool(user and check_password_hash(str(user.password), password)): diff --git a/cps/pagination.py b/cps/pagination.py index c29717c2..7a9bfb70 100644 --- a/cps/pagination.py +++ b/cps/pagination.py @@ -20,7 +20,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from __future__ import division, print_function, unicode_literals from math import ceil diff --git a/cps/redirect.py b/cps/redirect.py index 593afd0c..d491b353 100644 --- a/cps/redirect.py +++ b/cps/redirect.py @@ -27,7 +27,6 @@ # http://flask.pocoo.org/snippets/62/ -from __future__ import division, print_function, unicode_literals try: from urllib.parse import urlparse, urljoin except ImportError: diff --git a/cps/reverseproxy.py b/cps/reverseproxy.py index 3bcbd3b7..4acb8e45 100644 --- a/cps/reverseproxy.py +++ b/cps/reverseproxy.py @@ -36,8 +36,6 @@ # # Inspired by http://flask.pocoo.org/snippets/35/ -from __future__ import division, print_function, unicode_literals - class ReverseProxied(object): """Wrap the application in this middleware and configure the diff --git a/cps/search_metadata.py b/cps/search_metadata.py index 72e77cdd..e837fe21 100644 --- a/cps/search_metadata.py +++ b/cps/search_metadata.py @@ -16,7 +16,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from __future__ import division, print_function, unicode_literals import os import json import importlib diff --git a/cps/server.py b/cps/server.py index 9b79f77d..e261c50a 100644 --- a/cps/server.py +++ b/cps/server.py @@ -16,7 +16,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from __future__ import division, print_function, unicode_literals import sys import os import errno diff --git a/cps/services/SyncToken.py b/cps/services/SyncToken.py index 86165f71..692aaa24 100644 --- a/cps/services/SyncToken.py +++ b/cps/services/SyncToken.py @@ -35,10 +35,7 @@ log = logger.create() def b64encode_json(json_data): - if sys.version_info < (3, 0): - return b64encode(json.dumps(json_data)) - else: - return b64encode(json.dumps(json_data).encode()) + return b64encode(json.dumps(json_data).encode()) # Python3 has a timestamp() method we could be calling, however it's not avaiable in python2. diff --git a/cps/services/__init__.py b/cps/services/__init__.py index e6e5954c..32a9d485 100644 --- a/cps/services/__init__.py +++ b/cps/services/__init__.py @@ -16,8 +16,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from __future__ import division, print_function, unicode_literals - from .. import logger diff --git a/cps/services/gmail.py b/cps/services/gmail.py index baada1f8..ff36b308 100644 --- a/cps/services/gmail.py +++ b/cps/services/gmail.py @@ -1,4 +1,21 @@ -from __future__ import print_function +# -*- coding: utf-8 -*- + +# This file is part of the Calibre-Web (https://github.com/janeczku/calibre-web) +# Copyright (C) 2021 OzzieIsaacs +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + import os.path from google_auth_oauthlib.flow import InstalledAppFlow from google.auth.transport.requests import Request diff --git a/cps/services/goodreads_support.py b/cps/services/goodreads_support.py index 9312bc0f..74e6eba9 100644 --- a/cps/services/goodreads_support.py +++ b/cps/services/goodreads_support.py @@ -16,7 +16,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from __future__ import division, print_function, unicode_literals import time from functools import reduce diff --git a/cps/services/simpleldap.py b/cps/services/simpleldap.py index 4125bdab..1ca7e5bf 100644 --- a/cps/services/simpleldap.py +++ b/cps/services/simpleldap.py @@ -16,7 +16,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from __future__ import division, print_function, unicode_literals import base64 from flask_simpleldap import LDAP, LDAPException diff --git a/cps/services/worker.py b/cps/services/worker.py index 238c8dbf..5952c705 100644 --- a/cps/services/worker.py +++ b/cps/services/worker.py @@ -1,5 +1,21 @@ +# -*- coding: utf-8 -*- + +# This file is part of the Calibre-Web (https://github.com/janeczku/calibre-web) +# Copyright (C) 2020 pwr +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . -from __future__ import division, print_function, unicode_literals import threading import abc import uuid diff --git a/cps/shelf.py b/cps/shelf.py index d232e850..09fe8dd4 100644 --- a/cps/shelf.py +++ b/cps/shelf.py @@ -20,8 +20,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from __future__ import division, print_function, unicode_literals - import sys from datetime import datetime diff --git a/cps/subproc_wrapper.py b/cps/subproc_wrapper.py index 3cc4a070..187b2cb2 100644 --- a/cps/subproc_wrapper.py +++ b/cps/subproc_wrapper.py @@ -16,7 +16,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from __future__ import division, print_function, unicode_literals import sys import os import subprocess @@ -33,13 +32,8 @@ def process_open(command, quotes=(), env=None, sout=subprocess.PIPE, serr=subpro if key in quotes: command[key] = '"' + element + '"' exc_command = " ".join(command) - if sys.version_info < (3, 0): - exc_command = exc_command.encode(sys.getfilesystemencoding()) else: - if sys.version_info < (3, 0): - exc_command = [x.encode(sys.getfilesystemencoding()) for x in command] - else: - exc_command = [x for x in command] + exc_command = [x for x in command] return subprocess.Popen(exc_command, shell=False, stdout=sout, stderr=serr, universal_newlines=newlines, env=env) # nosec diff --git a/cps/tasks/convert.py b/cps/tasks/convert.py index 56cc7076..08fb1644 100644 --- a/cps/tasks/convert.py +++ b/cps/tasks/convert.py @@ -1,4 +1,21 @@ -from __future__ import division, print_function, unicode_literals +# -*- coding: utf-8 -*- + +# This file is part of the Calibre-Web (https://github.com/janeczku/calibre-web) +# Copyright (C) 2020 pwr +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + import sys import os import re @@ -161,8 +178,6 @@ class TaskConvert(CalibreTask): while True: nextline = p.stdout.readlines() nextline = [x.strip('\n') for x in nextline if x != '\n'] - if sys.version_info < (3, 0): - nextline = [x.decode('utf-8') for x in nextline] for line in nextline: log.debug(line) if p.poll() is not None: @@ -207,10 +222,6 @@ class TaskConvert(CalibreTask): while p.poll() is None: nextline = p.stdout.readline() - if os.name == 'nt' and sys.version_info < (3, 0): - nextline = nextline.decode('windows-1252') - elif os.name == 'posix' and sys.version_info < (3, 0): - nextline = nextline.decode('utf-8') log.debug(nextline.strip('\r\n')) # parse progress string from calibre-converter progress = re.search(r"(\d+)%\s.*", nextline) @@ -224,8 +235,6 @@ class TaskConvert(CalibreTask): calibre_traceback = p.stderr.readlines() error_message = "" for ele in calibre_traceback: - if sys.version_info < (3, 0): - ele = ele.decode('utf-8') log.debug(ele.strip('\n')) if not ele.startswith('Traceback') and not ele.startswith(' File'): error_message = _("Calibre failed with error: %(error)s", error=ele.strip('\n')) diff --git a/cps/tasks/mail.py b/cps/tasks/mail.py index 292114d5..2e95ee98 100644 --- a/cps/tasks/mail.py +++ b/cps/tasks/mail.py @@ -1,11 +1,27 @@ -from __future__ import division, print_function, unicode_literals +# -*- coding: utf-8 -*- + +# This file is part of the Calibre-Web (https://github.com/janeczku/calibre-web) +# Copyright (C) 2020 pwr +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + import sys import os import smtplib import threading import socket import mimetypes -import base64 try: from StringIO import StringIO @@ -162,17 +178,11 @@ class TaskEmail(CalibreTask): log.debug_or_exception(ex) self._handleError(u'Error sending e-mail: {}'.format(ex)) - def send_standard_email(self, msg): use_ssl = int(self.settings.get('mail_use_ssl', 0)) timeout = 600 # set timeout to 5mins - # redirect output to logfile on python2 on python3 debugoutput is caught with overwritten - # _print_debug function - if sys.version_info < (3, 0): - org_smtpstderr = smtplib.stderr - smtplib.stderr = logger.StderrLogger('worker.smtp') - + # on python3 debugoutput is caught with overwritten _print_debug function log.debug("Start sending e-mail") if use_ssl == 2: self.asyncSMTP = EmailSSL(self.settings["mail_server"], self.settings["mail_port"], @@ -198,9 +208,6 @@ class TaskEmail(CalibreTask): self._handleSuccess() log.debug("E-mail send successfully") - if sys.version_info < (3, 0): - smtplib.stderr = org_smtpstderr - def send_gmail_email(self, message): return gmail.send_messsage(self.settings.get('mail_gmail_token', None), message) @@ -218,7 +225,6 @@ class TaskEmail(CalibreTask): self.asyncSMTP = None self._progress = x - @classmethod def _get_attachment(cls, bookpath, filename): """Get file as MIMEBase message""" diff --git a/cps/tasks/upload.py b/cps/tasks/upload.py index d7ef34c2..6a341cdd 100644 --- a/cps/tasks/upload.py +++ b/cps/tasks/upload.py @@ -1,4 +1,20 @@ -from __future__ import division, print_function, unicode_literals +# -*- coding: utf-8 -*- + +# This file is part of the Calibre-Web (https://github.com/janeczku/calibre-web) +# Copyright (C) 2020 pwr +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . from datetime import datetime from cps.services.worker import CalibreTask, STAT_FINISH_SUCCESS diff --git a/cps/ub.py b/cps/ub.py index df1f0bc8..fe9d476a 100644 --- a/cps/ub.py +++ b/cps/ub.py @@ -17,7 +17,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from __future__ import division, print_function, unicode_literals import os import sys import datetime diff --git a/cps/updater.py b/cps/updater.py index 63ea23bf..9090263f 100644 --- a/cps/updater.py +++ b/cps/updater.py @@ -16,7 +16,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from __future__ import division, print_function, unicode_literals import sys import os import datetime diff --git a/cps/uploader.py b/cps/uploader.py index 0d59fd01..92a73381 100644 --- a/cps/uploader.py +++ b/cps/uploader.py @@ -16,7 +16,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from __future__ import division, print_function, unicode_literals import os import hashlib from tempfile import gettempdir diff --git a/cps/web.py b/cps/web.py index db0be841..fb01b6e5 100644 --- a/cps/web.py +++ b/cps/web.py @@ -20,7 +20,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from __future__ import division, print_function, unicode_literals import os from datetime import datetime import json @@ -30,7 +29,6 @@ import copy from babel.dates import format_date from babel import Locale as LC -from babel.core import UnknownLocaleError from flask import Blueprint, jsonify from flask import request, redirect, send_from_directory, make_response, flash, abort, url_for from flask import session as flask_session @@ -212,7 +210,7 @@ def toggle_archived(book_id): @web.route("/ajax/view", methods=["POST"]) @login_required_if_no_ano def update_view(): - to_save = request.get_json() + to_save = request.form.to_dict() # request.get_json() try: for element in to_save: for param in to_save[element]: @@ -261,10 +259,7 @@ def get_comic_book(book_id, book_format, page): log.error('unsupported comic format') return "", 204 - if sys.version_info.major >= 3: - b64 = codecs.encode(extract(page), 'base64').decode() - else: - b64 = extract(page).encode('base64') + b64 = codecs.encode(extract(page), 'base64').decode() ext = names[page].rpartition('.')[-1] if ext not in ('png', 'gif', 'jpg', 'jpeg', 'webp'): ext = 'png' @@ -274,7 +269,6 @@ def get_comic_book(book_id, book_format, page): return "", 204 ''' - # ################################### Typeahead ##################################################################