From 32b82d58032833256ed8c912b6e86d77dfdef380 Mon Sep 17 00:00:00 2001 From: flan Date: Sat, 4 Nov 2017 02:15:40 +0100 Subject: [PATCH] Fix up some changes made by 2to3 --- anki-bundled | 2 +- ankisyncctl.py | 3 --- ankisyncd/sync_app.py | 18 ++++++------------ ankisyncd/thread.py | 6 ++---- tests/collection_test_base.py | 4 ++-- tests/helpers/monkey_patches.py | 5 +---- tests/helpers/server_utils.py | 2 +- 7 files changed, 13 insertions(+), 27 deletions(-) diff --git a/anki-bundled b/anki-bundled index 499b022..7b1747d 160000 --- a/anki-bundled +++ b/anki-bundled @@ -1 +1 @@ -Subproject commit 499b02281b4ab2bea3c4167128f02cc3d9cf973b +Subproject commit 7b1747d6504c9091a34793cebaa559b9fb6968df diff --git a/ankisyncctl.py b/ankisyncctl.py index 59a7775..b6dadaa 100755 --- a/ankisyncctl.py +++ b/ankisyncctl.py @@ -1,7 +1,4 @@ #!/usr/bin/env python - - - import os import sys import getpass diff --git a/ankisyncd/sync_app.py b/ankisyncd/sync_app.py index 855aa4d..d54abd0 100644 --- a/ankisyncd/sync_app.py +++ b/ankisyncd/sync_app.py @@ -15,7 +15,7 @@ # along with this program. If not, see . -from configparser import SafeConfigParser +from configparser import ConfigParser from webob.dec import wsgify from webob.exc import * @@ -30,6 +30,7 @@ import string import unicodedata import zipfile from sqlite3 import dbapi2 as sqlite +from io import StringIO import ankisyncd @@ -41,10 +42,6 @@ from anki.consts import SYNC_ZIP_SIZE, SYNC_ZIP_COUNT from ankisyncd.users import SimpleUserManager, SqliteUserManager -try: - from io import StringIO -except ImportError: - from io import StringIO def old_client(cv): if not cv: @@ -53,7 +50,7 @@ def old_client(cv): note = {"alpha": 0, "beta": 0} client, version, platform = cv.split(',') - for name in list(note.keys()): + for name in note.keys(): if name in version: vs = version.split(name) version = vs[0] @@ -209,9 +206,6 @@ class SyncMediaHandler(anki.sync.MediaSyncer): MediaManager.addFilesFromZip(). """ - if not isinstance(filename, str): - filename = str(filename, "utf8") - # Normalize name for platform. if anki.utils.isMac: # global filename = unicodedata.normalize("NFD", filename) @@ -540,7 +534,7 @@ class SyncApp(object): result = self._execute_handler_method_in_thread(url, data, session) # If it's a complex data type, we convert it to JSON - if type(result) not in (str, str): + if type(result) not in (str, bytes): result = json.dumps(result) if url == 'finish': @@ -583,7 +577,7 @@ class SyncApp(object): result = self._execute_handler_method_in_thread(url, data, session) # If it's a complex data type, we convert it to JSON - if type(result) not in (str, str): + if type(result) not in (str, bytes): result = json.dumps(result) return result @@ -692,7 +686,7 @@ def main(): from ankisyncd.thread import shutdown logging.basicConfig(level=logging.INFO) - config = SafeConfigParser() + config = ConfigParser() config.read("ankisyncd.conf") ankiserver = SyncApp(config) diff --git a/ankisyncd/thread.py b/ankisyncd/thread.py index edba54f..9d2dcfd 100644 --- a/ankisyncd/thread.py +++ b/ankisyncd/thread.py @@ -1,5 +1,3 @@ - - from ankisyncd.collection import CollectionWrapper, CollectionManager from threading import Thread @@ -61,7 +59,7 @@ class ThreadingCollectionWrapper(object): while self._running: func, args, kw, return_queue = self._queue.get(True) - if hasattr(func, 'func_name'): + if hasattr(func, '__name__'): func_name = func.__name__ else: func_name = func.__class__.__name__ @@ -153,7 +151,7 @@ class ThreadingCollectionManager(CollectionManager): small memory footprint!) """ while True: cur = time.time() - for path, thread in list(self.collections.items()): + for path, thread in self.collections.items(): if thread.running and thread.wrapper.opened() and thread.qempty() and cur - thread.last_timestamp >= self.monitor_inactivity: logging.info('Monitor is closing collection on inactive CollectionThread[%s]', thread.path) thread.close() diff --git a/tests/collection_test_base.py b/tests/collection_test_base.py index f5655f2..03d05b0 100644 --- a/tests/collection_test_base.py +++ b/tests/collection_test_base.py @@ -2,7 +2,7 @@ import unittest import tempfile import os -from mock import MagicMock +from unittest.mock import MagicMock import shutil import anki @@ -31,7 +31,7 @@ class CollectionTestBase(unittest.TestCase): model = self.collection.models.byName(data['model']) note = Note(self.collection, model) - for name, value in list(data['fields'].items()): + for name, value in data['fields'].items(): note[name] = value if 'tags' in data: diff --git a/tests/helpers/monkey_patches.py b/tests/helpers/monkey_patches.py index 5e8b76c..906bce0 100644 --- a/tests/helpers/monkey_patches.py +++ b/tests/helpers/monkey_patches.py @@ -69,11 +69,8 @@ def monkeypatch_db(): def patched___init__(self, path, text=None, timeout=0): # Code taken from Anki's DB.__init__() - encpath = path - if isinstance(encpath, str): - encpath = path.encode("utf-8") # Allow more than one thread to use this connection. - self._db = sqlite.connect(encpath, + self._db = sqlite.connect(path, timeout=timeout, check_same_thread=False) if text: diff --git a/tests/helpers/server_utils.py b/tests/helpers/server_utils.py index 63da2cb..7943126 100644 --- a/tests/helpers/server_utils.py +++ b/tests/helpers/server_utils.py @@ -22,7 +22,7 @@ def create_server_paths(): } def create_sync_app(server_paths, config_path): - config = configparser.SafeConfigParser() + config = configparser.ConfigParser() config.read(config_path) # Use custom files and dirs in settings.