Fix up some changes made by 2to3

This commit is contained in:
flan 2017-11-04 02:15:40 +01:00
parent 0cc21101d7
commit 32b82d5803
7 changed files with 13 additions and 27 deletions

@ -1 +1 @@
Subproject commit 499b02281b4ab2bea3c4167128f02cc3d9cf973b Subproject commit 7b1747d6504c9091a34793cebaa559b9fb6968df

View File

@ -1,7 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python
import os import os
import sys import sys
import getpass import getpass

View File

@ -15,7 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from configparser import SafeConfigParser from configparser import ConfigParser
from webob.dec import wsgify from webob.dec import wsgify
from webob.exc import * from webob.exc import *
@ -30,6 +30,7 @@ import string
import unicodedata import unicodedata
import zipfile import zipfile
from sqlite3 import dbapi2 as sqlite from sqlite3 import dbapi2 as sqlite
from io import StringIO
import ankisyncd import ankisyncd
@ -41,10 +42,6 @@ from anki.consts import SYNC_ZIP_SIZE, SYNC_ZIP_COUNT
from ankisyncd.users import SimpleUserManager, SqliteUserManager from ankisyncd.users import SimpleUserManager, SqliteUserManager
try:
from io import StringIO
except ImportError:
from io import StringIO
def old_client(cv): def old_client(cv):
if not cv: if not cv:
@ -53,7 +50,7 @@ def old_client(cv):
note = {"alpha": 0, "beta": 0} note = {"alpha": 0, "beta": 0}
client, version, platform = cv.split(',') client, version, platform = cv.split(',')
for name in list(note.keys()): for name in note.keys():
if name in version: if name in version:
vs = version.split(name) vs = version.split(name)
version = vs[0] version = vs[0]
@ -209,9 +206,6 @@ class SyncMediaHandler(anki.sync.MediaSyncer):
MediaManager.addFilesFromZip(). MediaManager.addFilesFromZip().
""" """
if not isinstance(filename, str):
filename = str(filename, "utf8")
# Normalize name for platform. # Normalize name for platform.
if anki.utils.isMac: # global if anki.utils.isMac: # global
filename = unicodedata.normalize("NFD", filename) filename = unicodedata.normalize("NFD", filename)
@ -540,7 +534,7 @@ class SyncApp(object):
result = self._execute_handler_method_in_thread(url, data, session) result = self._execute_handler_method_in_thread(url, data, session)
# If it's a complex data type, we convert it to JSON # 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) result = json.dumps(result)
if url == 'finish': if url == 'finish':
@ -583,7 +577,7 @@ class SyncApp(object):
result = self._execute_handler_method_in_thread(url, data, session) result = self._execute_handler_method_in_thread(url, data, session)
# If it's a complex data type, we convert it to JSON # 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) result = json.dumps(result)
return result return result
@ -692,7 +686,7 @@ def main():
from ankisyncd.thread import shutdown from ankisyncd.thread import shutdown
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)
config = SafeConfigParser() config = ConfigParser()
config.read("ankisyncd.conf") config.read("ankisyncd.conf")
ankiserver = SyncApp(config) ankiserver = SyncApp(config)

View File

@ -1,5 +1,3 @@
from ankisyncd.collection import CollectionWrapper, CollectionManager from ankisyncd.collection import CollectionWrapper, CollectionManager
from threading import Thread from threading import Thread
@ -61,7 +59,7 @@ class ThreadingCollectionWrapper(object):
while self._running: while self._running:
func, args, kw, return_queue = self._queue.get(True) func, args, kw, return_queue = self._queue.get(True)
if hasattr(func, 'func_name'): if hasattr(func, '__name__'):
func_name = func.__name__ func_name = func.__name__
else: else:
func_name = func.__class__.__name__ func_name = func.__class__.__name__
@ -153,7 +151,7 @@ class ThreadingCollectionManager(CollectionManager):
small memory footprint!) """ small memory footprint!) """
while True: while True:
cur = time.time() 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: 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) logging.info('Monitor is closing collection on inactive CollectionThread[%s]', thread.path)
thread.close() thread.close()

View File

@ -2,7 +2,7 @@
import unittest import unittest
import tempfile import tempfile
import os import os
from mock import MagicMock from unittest.mock import MagicMock
import shutil import shutil
import anki import anki
@ -31,7 +31,7 @@ class CollectionTestBase(unittest.TestCase):
model = self.collection.models.byName(data['model']) model = self.collection.models.byName(data['model'])
note = Note(self.collection, model) note = Note(self.collection, model)
for name, value in list(data['fields'].items()): for name, value in data['fields'].items():
note[name] = value note[name] = value
if 'tags' in data: if 'tags' in data:

View File

@ -69,11 +69,8 @@ def monkeypatch_db():
def patched___init__(self, path, text=None, timeout=0): def patched___init__(self, path, text=None, timeout=0):
# Code taken from Anki's DB.__init__() # 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. # Allow more than one thread to use this connection.
self._db = sqlite.connect(encpath, self._db = sqlite.connect(path,
timeout=timeout, timeout=timeout,
check_same_thread=False) check_same_thread=False)
if text: if text:

View File

@ -22,7 +22,7 @@ def create_server_paths():
} }
def create_sync_app(server_paths, config_path): def create_sync_app(server_paths, config_path):
config = configparser.SafeConfigParser() config = configparser.ConfigParser()
config.read(config_path) config.read(config_path)
# Use custom files and dirs in settings. # Use custom files and dirs in settings.