2to3 everything

This commit is contained in:
flan
2017-11-04 02:06:42 +01:00
parent c08fb74d91
commit 0cc21101d7
10 changed files with 61 additions and 60 deletions

View File

@@ -50,7 +50,7 @@ class CollectionWrapper(object):
dirname = os.path.dirname(self.path)
try:
os.makedirs(dirname)
except OSError, exc:
except OSError as exc:
if exc.errno == errno.EEXIST:
pass
else:
@@ -106,7 +106,7 @@ class CollectionManager(object):
def shutdown(self):
"""Close all CollectionWrappers managed by this object."""
for path, col in self.collections.items():
for path, col in list(self.collections.items()):
del self.collections[path]
col.close()

View File

@@ -14,7 +14,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from ConfigParser import SafeConfigParser
from configparser import SafeConfigParser
from webob.dec import wsgify
from webob.exc import *
@@ -41,9 +42,9 @@ from anki.consts import SYNC_ZIP_SIZE, SYNC_ZIP_COUNT
from ankisyncd.users import SimpleUserManager, SqliteUserManager
try:
from cStringIO import StringIO
from io import StringIO
except ImportError:
from StringIO import StringIO
from io import StringIO
def old_client(cv):
if not cv:
@@ -52,7 +53,7 @@ def old_client(cv):
note = {"alpha": 0, "beta": 0}
client, version, platform = cv.split(',')
for name in note.keys():
for name in list(note.keys()):
if name in version:
vs = version.split(name)
version = vs[0]
@@ -208,8 +209,8 @@ class SyncMediaHandler(anki.sync.MediaSyncer):
MediaManager.addFilesFromZip().
"""
if not isinstance(filename, unicode):
filename = unicode(filename, "utf8")
if not isinstance(filename, str):
filename = str(filename, "utf8")
# Normalize name for platform.
if anki.utils.isMac: # global
@@ -514,12 +515,12 @@ class SyncApp(object):
if url in SyncCollectionHandler.operations + SyncMediaHandler.operations:
# 'meta' passes the SYNC_VER but it isn't used in the handler
if url == 'meta':
if session.skey == None and req.POST.has_key('s'):
if session.skey == None and 's' in req.POST:
session.skey = req.POST['s']
if data.has_key('v'):
if 'v' in data:
session.version = data['v']
del data['v']
if data.has_key('cv'):
if 'cv' in data:
session.client_version = data['cv']
del data['cv']
@@ -539,7 +540,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, unicode):
if type(result) not in (str, str):
result = json.dumps(result)
if url == 'finish':
@@ -582,7 +583,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, unicode):
if type(result) not in (str, str):
result = json.dumps(result)
return result
@@ -607,7 +608,7 @@ class SyncApp(object):
col.save()
return res
run_func.func_name = method_name # More useful debugging messages.
run_func.__name__ = method_name # More useful debugging messages.
# Send the closure to the thread for execution.
thread = session.get_thread()

View File

@@ -1,9 +1,9 @@
from __future__ import absolute_import
from ankisyncd.collection import CollectionWrapper, CollectionManager
from threading import Thread
from Queue import Queue
from queue import Queue
import time, logging
@@ -62,7 +62,7 @@ class ThreadingCollectionWrapper(object):
func, args, kw, return_queue = self._queue.get(True)
if hasattr(func, 'func_name'):
func_name = func.func_name
func_name = func.__name__
else:
func_name = func.__class__.__name__
@@ -71,7 +71,7 @@ class ThreadingCollectionWrapper(object):
try:
ret = self.wrapper.execute(func, args, kw, return_queue)
except Exception, e:
except Exception as e:
logging.error('CollectionThread[%s]: Unable to %s(*%s, **%s): %s',
self.path, func_name, repr(args), repr(kw), e, exc_info=True)
# we return the Exception which will be raise'd on the other end
@@ -79,7 +79,7 @@ class ThreadingCollectionWrapper(object):
if return_queue is not None:
return_queue.put(ret)
except Exception, e:
except Exception as e:
logging.error('CollectionThread[%s]: Thread crashed! Exception: %s', self.path, e, exc_info=True)
finally:
self.wrapper.close()
@@ -153,7 +153,7 @@ class ThreadingCollectionManager(CollectionManager):
small memory footprint!) """
while True:
cur = time.time()
for path, thread in self.collections.items():
for path, thread in list(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()
@@ -163,7 +163,7 @@ class ThreadingCollectionManager(CollectionManager):
# TODO: stop the monitor thread!
# stop all the threads
for path, col in self.collections.items():
for path, col in list(self.collections.items()):
del self.collections[path]
col.stop()