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
import os
import sys
import getpass

View File

@ -15,7 +15,7 @@
# 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.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)

View File

@ -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()

View File

@ -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:

View File

@ -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:

View File

@ -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.