2to3 main
This commit is contained in:
parent
d5564828ea
commit
6ec6111896
@ -20,7 +20,7 @@ from sys import exc_info
|
||||
import six
|
||||
|
||||
try:
|
||||
from ConfigParser import SafeConfigParser, Error
|
||||
from configparser import SafeConfigParser, Error
|
||||
except ImportError: # Python3.
|
||||
from configparser import SafeConfigParser, Error
|
||||
from offlineimap.localeval import LocalEval
|
||||
|
@ -65,8 +65,8 @@ if bytes != str:
|
||||
import queue
|
||||
string_types = str
|
||||
else:
|
||||
import Queue as queue
|
||||
string_types = basestring
|
||||
import queue as queue
|
||||
string_types = str
|
||||
|
||||
select_module = select
|
||||
|
||||
@ -1871,7 +1871,7 @@ class IMAP4(object):
|
||||
select.POLLHUP: 'Hang up',
|
||||
select.POLLNVAL: 'Invalid request: descriptor not open',
|
||||
}
|
||||
return ' '.join([PollErrors[s] for s in PollErrors.keys() if (s & state)])
|
||||
return ' '.join([PollErrors[s] for s in list(PollErrors.keys()) if (s & state)])
|
||||
|
||||
if bytes != str:
|
||||
line_part = b''
|
||||
@ -2698,9 +2698,9 @@ if __name__ == '__main__':
|
||||
print('Tests failed.')
|
||||
|
||||
if not debug:
|
||||
print('''
|
||||
print(('''
|
||||
If you would like to see debugging output,
|
||||
try: %s -d5
|
||||
''' % sys.argv[0])
|
||||
''' % sys.argv[0]))
|
||||
|
||||
raise
|
||||
|
@ -286,7 +286,7 @@ class BaseFolder(object):
|
||||
def ismessagelistempty(self):
|
||||
"""Is the list of messages empty."""
|
||||
|
||||
if len(self.messagelist.keys()) < 1:
|
||||
if len(list(self.messagelist.keys())) < 1:
|
||||
return True
|
||||
return False
|
||||
|
||||
@ -1059,14 +1059,14 @@ class BaseFolder(object):
|
||||
delflaglist[flag] = []
|
||||
delflaglist[flag].append(uid)
|
||||
|
||||
for flag, uids in addflaglist.items():
|
||||
for flag, uids in list(addflaglist.items()):
|
||||
self.ui.addingflags(uids, flag, dstfolder)
|
||||
if self.repository.account.dryrun:
|
||||
continue # Don't actually add in a dryrun.
|
||||
dstfolder.addmessagesflags(uids, set(flag))
|
||||
statusfolder.addmessagesflags(uids, set(flag))
|
||||
|
||||
for flag, uids in delflaglist.items():
|
||||
for flag, uids in list(delflaglist.items()):
|
||||
self.ui.deletingflags(uids, flag, dstfolder)
|
||||
if self.repository.account.dryrun:
|
||||
continue # Don't actually remove in a dryrun.
|
||||
|
@ -57,11 +57,11 @@ class GmailMaildirFolder(MaildirFolder):
|
||||
sorted(statusfolder.getmessageuidlist()):
|
||||
return True
|
||||
# Check for flag changes, it's quick on a Maildir.
|
||||
for (uid, message) in self.getmessagelist().items():
|
||||
for (uid, message) in list(self.getmessagelist().items()):
|
||||
if message['flags'] != statusfolder.getmessageflags(uid):
|
||||
return True
|
||||
# check for newer mtimes. it is also fast
|
||||
for (uid, message) in self.getmessagelist().items():
|
||||
for (uid, message) in list(self.getmessagelist().items()):
|
||||
if message['mtime'] > statusfolder.getmessagemtime(uid):
|
||||
return True
|
||||
return False # Nope, nothing changed.
|
||||
@ -302,7 +302,7 @@ class GmailMaildirFolder(MaildirFolder):
|
||||
dellabellist[lb] = []
|
||||
dellabellist[lb].append(uid)
|
||||
|
||||
for lb, uids in addlabellist.items():
|
||||
for lb, uids in list(addlabellist.items()):
|
||||
# Bail out on CTRL-C or SIGTERM.
|
||||
if offlineimap.accounts.Account.abort_NOW_signal.is_set():
|
||||
break
|
||||
@ -313,7 +313,7 @@ class GmailMaildirFolder(MaildirFolder):
|
||||
dstfolder.addmessageslabels(uids, set([lb]))
|
||||
statusfolder.addmessageslabels(uids, set([lb]))
|
||||
|
||||
for lb, uids in dellabellist.items():
|
||||
for lb, uids in list(dellabellist.items()):
|
||||
# Bail out on CTRL-C or SIGTERM.
|
||||
if offlineimap.accounts.Account.abort_NOW_signal.is_set():
|
||||
break
|
||||
|
@ -177,7 +177,7 @@ class LocalStatusFolder(BaseFolder):
|
||||
with self.savelock:
|
||||
cachefd = open(self.filename + ".tmp", "wt")
|
||||
cachefd.write((self.magicline % self.cur_version) + "\n")
|
||||
for msg in self.messagelist.values():
|
||||
for msg in list(self.messagelist.values()):
|
||||
flags = ''.join(sorted(msg['flags']))
|
||||
labels = ', '.join(sorted(msg['labels']))
|
||||
cachefd.write("%s|%s|%d|%s\n" % (msg['uid'], flags, msg['mtime'], labels))
|
||||
@ -237,7 +237,7 @@ class LocalStatusFolder(BaseFolder):
|
||||
def savemessageslabelsbulk(self, labels):
|
||||
"""Saves labels from a dictionary in a single database operation."""
|
||||
|
||||
for uid, lb in labels.items():
|
||||
for uid, lb in list(labels.items()):
|
||||
self.messagelist[uid]['labels'] = lb
|
||||
self.save()
|
||||
|
||||
@ -257,7 +257,7 @@ class LocalStatusFolder(BaseFolder):
|
||||
def savemessagesmtimebulk(self, mtimes):
|
||||
"""Saves mtimes from the mtimes dictionary in a single database operation."""
|
||||
|
||||
for uid, mt in mtimes.items():
|
||||
for uid, mt in list(mtimes.items()):
|
||||
self.messagelist[uid]['mtime'] = mt
|
||||
self.save()
|
||||
|
||||
|
@ -284,7 +284,7 @@ class LocalStatusSQLiteFolder(BaseFolder):
|
||||
|
||||
with self._databaseFileLock.getLock():
|
||||
data = []
|
||||
for uid, msg in self.messagelist.items():
|
||||
for uid, msg in list(self.messagelist.items()):
|
||||
mtime = msg['mtime']
|
||||
flags = ''.join(sorted(msg['flags']))
|
||||
labels = ', '.join(sorted(msg['labels']))
|
||||
@ -391,9 +391,9 @@ class LocalStatusSQLiteFolder(BaseFolder):
|
||||
Saves labels from a dictionary in a single database operation.
|
||||
|
||||
"""
|
||||
data = [(', '.join(sorted(l)), uid) for uid, l in labels.items()]
|
||||
data = [(', '.join(sorted(l)), uid) for uid, l in list(labels.items())]
|
||||
self.__sql_write('UPDATE status SET labels=? WHERE id=?', data, executemany=True)
|
||||
for uid, l in labels.items():
|
||||
for uid, l in list(labels.items()):
|
||||
self.messagelist[uid]['labels'] = l
|
||||
|
||||
|
||||
@ -424,9 +424,9 @@ class LocalStatusSQLiteFolder(BaseFolder):
|
||||
def savemessagesmtimebulk(self, mtimes):
|
||||
"""Saves mtimes from the mtimes dictionary in a single database operation."""
|
||||
|
||||
data = [(mt, uid) for uid, mt in mtimes.items()]
|
||||
data = [(mt, uid) for uid, mt in list(mtimes.items())]
|
||||
self.__sql_write('UPDATE status SET mtime=? WHERE id=?', data, executemany=True)
|
||||
for uid, mt in mtimes.items():
|
||||
for uid, mt in list(mtimes.items()):
|
||||
self.messagelist[uid]['mtime'] = mt
|
||||
|
||||
|
||||
|
@ -227,7 +227,7 @@ class MaildirFolder(BaseFolder):
|
||||
positive_uids = [uid for uid in retval if uid > 0]
|
||||
if positive_uids:
|
||||
min_uid = min(positive_uids)
|
||||
for uid in date_excludees.keys():
|
||||
for uid in list(date_excludees.keys()):
|
||||
if uid > min_uid:
|
||||
# This message was originally excluded because of
|
||||
# its date. It is re-included now because we want all
|
||||
@ -245,7 +245,7 @@ class MaildirFolder(BaseFolder):
|
||||
sorted(statusfolder.getmessageuidlist()):
|
||||
return True
|
||||
# Also check for flag changes, it's quick on a Maildir.
|
||||
for (uid, message) in self.getmessagelist().items():
|
||||
for (uid, message) in list(self.getmessagelist().items()):
|
||||
if message['flags'] != statusfolder.getmessageflags(uid):
|
||||
return True
|
||||
return False # Nope, nothing changed.
|
||||
@ -523,7 +523,7 @@ class MaildirFolder(BaseFolder):
|
||||
"""
|
||||
oldfmd5 = md5(self.name).hexdigest()
|
||||
msglist = self._scanfolder()
|
||||
for mkey, mvalue in msglist.items():
|
||||
for mkey, mvalue in list(msglist.items()):
|
||||
filename = os.path.join(self.getfullname(), mvalue['filename'])
|
||||
match = re.search("FMD5=([a-fA-F0-9]+)", filename)
|
||||
if match is None:
|
||||
|
@ -110,7 +110,7 @@ class MappedIMAPFolder(IMAPFolder):
|
||||
except NameError:
|
||||
pass # Windows...
|
||||
with open(mapfilenametmp, 'wt') as mapfilefd:
|
||||
for (key, value) in self.diskl2r.items():
|
||||
for (key, value) in list(self.diskl2r.items()):
|
||||
mapfilefd.write("%d:%d\n"% (key, value))
|
||||
if self.dofsync():
|
||||
fsync(mapfilefd)
|
||||
@ -139,7 +139,7 @@ class MappedIMAPFolder(IMAPFolder):
|
||||
with self.maplock:
|
||||
# OK. Now we've got a nice list. First, delete things from the
|
||||
# summary that have been deleted from the folder.
|
||||
for luid in self.diskl2r.keys():
|
||||
for luid in list(self.diskl2r.keys()):
|
||||
if not luid in reallist:
|
||||
ruid = self.diskl2r[luid]
|
||||
#XXX: the following KeyError are sightly unexpected. This
|
||||
@ -166,7 +166,7 @@ class MappedIMAPFolder(IMAPFolder):
|
||||
self.r2l = self.diskr2l.copy()
|
||||
self.l2r = self.diskl2r.copy()
|
||||
|
||||
for luid in reallist.keys():
|
||||
for luid in list(reallist.keys()):
|
||||
if not luid in self.l2r:
|
||||
ruid = nextneg
|
||||
nextneg -= 1
|
||||
@ -192,7 +192,7 @@ class MappedIMAPFolder(IMAPFolder):
|
||||
|
||||
# This implementation overrides the one in BaseFolder, as it is
|
||||
# much more efficient for the mapped case.
|
||||
return self.r2l.keys()
|
||||
return list(self.r2l.keys())
|
||||
|
||||
# Interface from BaseFolder
|
||||
def getmessagecount(self):
|
||||
|
@ -220,7 +220,7 @@ class WrappedIMAP4_SSL(UsefulIMAPMixIn, IMAP4_SSL):
|
||||
"does not match configured fingerprint(s) %s. "
|
||||
"Please verify and set 'cert_fingerprint' accordingly "
|
||||
"if not set yet."%
|
||||
(zip([hash.__name__ for hash in hashes], server_fingerprints), host, self._fingerprint),
|
||||
(list(zip([hash.__name__ for hash in hashes], server_fingerprints)), host, self._fingerprint),
|
||||
OfflineImapError.ERROR.REPO)
|
||||
|
||||
|
||||
|
@ -19,7 +19,7 @@ import datetime
|
||||
import hmac
|
||||
import socket
|
||||
import json
|
||||
import urllib
|
||||
import urllib.request, urllib.parse, urllib.error
|
||||
import time
|
||||
import errno
|
||||
import socket
|
||||
@ -247,8 +247,8 @@ class IMAPServer(object):
|
||||
original_socket = socket.socket
|
||||
socket.socket = self.authproxied_socket
|
||||
try:
|
||||
response = urllib.urlopen(
|
||||
self.oauth2_request_url, urllib.urlencode(params)).read()
|
||||
response = urllib.request.urlopen(
|
||||
self.oauth2_request_url, urllib.parse.urlencode(params)).read()
|
||||
except Exception as e:
|
||||
try:
|
||||
msg = "%s (configuration is: %s)"% (e, str(params))
|
||||
@ -260,11 +260,11 @@ class IMAPServer(object):
|
||||
|
||||
resp = json.loads(response)
|
||||
self.ui.debug('imap', 'xoauth2handler: response "%s"'% resp)
|
||||
if u'error' in resp:
|
||||
if 'error' in resp:
|
||||
raise OfflineImapError("xoauth2handler got: %s"% resp,
|
||||
OfflineImapError.ERROR.REPO)
|
||||
self.oauth2_access_token = resp['access_token']
|
||||
if u'expires_in' in resp:
|
||||
if 'expires_in' in resp:
|
||||
self.oauth2_access_token_expires_at = now + datetime.timedelta(
|
||||
seconds=resp['expires_in']/2
|
||||
)
|
||||
@ -444,7 +444,7 @@ class IMAPServer(object):
|
||||
continue
|
||||
|
||||
tried_to_authn = True
|
||||
self.ui.debug('imap', u'Attempting '
|
||||
self.ui.debug('imap', 'Attempting '
|
||||
'%s authentication'% m)
|
||||
try:
|
||||
if func(imapobj):
|
||||
@ -461,7 +461,7 @@ class IMAPServer(object):
|
||||
if not tried_to_authn:
|
||||
methods = ", ".join([x[5:] for x in
|
||||
[x for x in imapobj.capabilities if x[0:5] == "AUTH="]])
|
||||
raise OfflineImapError(u"Repository %s: no supported "
|
||||
raise OfflineImapError("Repository %s: no supported "
|
||||
"authentication mechanisms found; configured %s, "
|
||||
"server advertises %s"% (self.repos,
|
||||
", ".join(self.authmechs), methods),
|
||||
|
@ -416,7 +416,7 @@ def encoder(s):
|
||||
# decoding
|
||||
def modified_unbase64(s):
|
||||
b = binascii.a2b_base64(s.replace(',', '/') + '===')
|
||||
return unicode(b, 'utf-16be')
|
||||
return str(b, 'utf-16be')
|
||||
|
||||
def decoder(s):
|
||||
r = []
|
||||
|
@ -191,9 +191,9 @@ class OfflineImap(object):
|
||||
glob.set_options(options)
|
||||
|
||||
if options.version:
|
||||
print("offlineimap v%s, %s"% (
|
||||
print(("offlineimap v%s, %s"% (
|
||||
offlineimap.__version__, self.get_env_info())
|
||||
)
|
||||
))
|
||||
sys.exit(0)
|
||||
|
||||
# Read in configuration file.
|
||||
@ -255,7 +255,7 @@ class OfflineImap(object):
|
||||
ui_type = ui_type.split('.')[-1]
|
||||
# TODO, make use of chosen ui for logging
|
||||
logging.warning('Using old interface name, consider using one '
|
||||
'of %s'% ', '.join(UI_LIST.keys()))
|
||||
'of %s'% ', '.join(list(UI_LIST.keys())))
|
||||
if options.diagnostics:
|
||||
ui_type = 'ttyui' # Enforce this UI for --info.
|
||||
|
||||
@ -269,7 +269,7 @@ class OfflineImap(object):
|
||||
self.ui = UI_LIST[ui_type.lower()](config)
|
||||
except KeyError:
|
||||
logging.error("UI '%s' does not exist, choose one of: %s"%
|
||||
(ui_type, ', '.join(UI_LIST.keys())))
|
||||
(ui_type, ', '.join(list(UI_LIST.keys()))))
|
||||
sys.exit(1)
|
||||
setglobalui(self.ui)
|
||||
|
||||
@ -363,10 +363,10 @@ class OfflineImap(object):
|
||||
d = collections.defaultdict(lambda: 0)
|
||||
for v in l:
|
||||
d[tuple(v)] += 1
|
||||
return list((k, v) for k, v in d.items())
|
||||
return list((k, v) for k, v in list(d.items()))
|
||||
|
||||
stack_displays = []
|
||||
for threadId, stack in sys._current_frames().items():
|
||||
for threadId, stack in list(sys._current_frames().items()):
|
||||
stack_display = []
|
||||
for filename, lineno, name, line in traceback.extract_stack(stack):
|
||||
stack_display.append(' File: "%s", line %d, in %s'
|
||||
@ -387,7 +387,7 @@ class OfflineImap(object):
|
||||
self.ui.debug('thread', msg % (times, '\n'.join(stack[- (context * 2):])))
|
||||
|
||||
self.ui.debug('thread', "Dumped a total of %d Threads." %
|
||||
len(sys._current_frames().keys()))
|
||||
len(list(sys._current_frames().keys())))
|
||||
|
||||
def _get_activeaccounts(self, options):
|
||||
activeaccounts = []
|
||||
|
@ -23,7 +23,7 @@ from threading import Lock
|
||||
from os import listdir, makedirs, path, unlink
|
||||
from sys import exc_info
|
||||
try:
|
||||
from ConfigParser import NoSectionError
|
||||
from configparser import NoSectionError
|
||||
except ImportError: # Py3.
|
||||
from configparser import NoSectionError
|
||||
|
||||
|
@ -197,7 +197,7 @@ class BaseRepository(CustomConfig.ConfigHelperMixin):
|
||||
local_hash[folder.getname()] = folder
|
||||
|
||||
# Create new folders from remote to local.
|
||||
for remote_name, remote_folder in remote_hash.items():
|
||||
for remote_name, remote_folder in list(remote_hash.items()):
|
||||
# Don't create on local_repo, if it is readonly.
|
||||
if not local_repo.should_create_folders():
|
||||
break
|
||||
@ -205,7 +205,7 @@ class BaseRepository(CustomConfig.ConfigHelperMixin):
|
||||
# Apply remote nametrans and fix serparator.
|
||||
local_name = remote_folder.getvisiblename().replace(
|
||||
remote_repo.getsep(), local_repo.getsep())
|
||||
if remote_folder.sync_this and not local_name in local_hash.keys():
|
||||
if remote_folder.sync_this and not local_name in list(local_hash.keys()):
|
||||
try:
|
||||
local_repo.makefolder(local_name)
|
||||
# Need to refresh list.
|
||||
@ -219,7 +219,7 @@ class BaseRepository(CustomConfig.ConfigHelperMixin):
|
||||
local_repo.getsep(), status_repo.getsep()))
|
||||
|
||||
# Create new folders from local to remote.
|
||||
for local_name, local_folder in local_hash.items():
|
||||
for local_name, local_folder in list(local_hash.items()):
|
||||
if not remote_repo.should_create_folders():
|
||||
# Don't create missing folder on readonly repo.
|
||||
break
|
||||
@ -227,7 +227,7 @@ class BaseRepository(CustomConfig.ConfigHelperMixin):
|
||||
# Apply reverse nametrans and fix serparator.
|
||||
remote_name = local_folder.getvisiblename().replace(
|
||||
local_repo.getsep(), remote_repo.getsep())
|
||||
if local_folder.sync_this and not remote_name in remote_hash.keys():
|
||||
if local_folder.sync_this and not remote_name in list(remote_hash.keys()):
|
||||
# Would the remote filter out the new folder name? In this case
|
||||
# don't create it.
|
||||
if not remote_repo.should_sync_folder(remote_name):
|
||||
|
@ -57,13 +57,13 @@ class LocalStatusRepository(BaseRepository):
|
||||
return self.LocalStatusFolderClass(foldername, self) # Instanciate.
|
||||
|
||||
def setup_backend(self, backend):
|
||||
if backend in self.backends.keys():
|
||||
if backend in list(self.backends.keys()):
|
||||
self._backend = backend
|
||||
self.root = self.backends[backend]['root']
|
||||
self.LocalStatusFolderClass = self.backends[backend]['class']
|
||||
|
||||
def import_other_backend(self, folder):
|
||||
for bk, dic in self.backends.items():
|
||||
for bk, dic in list(self.backends.items()):
|
||||
# Skip folder's own type.
|
||||
if dic['class'] == type(folder):
|
||||
continue
|
||||
|
@ -20,7 +20,7 @@ from sys import exc_info
|
||||
try:
|
||||
from configparser import NoSectionError
|
||||
except ImportError: #python2
|
||||
from ConfigParser import NoSectionError
|
||||
from configparser import NoSectionError
|
||||
|
||||
from offlineimap.repository.IMAP import IMAPRepository, MappedIMAPRepository
|
||||
from offlineimap.repository.Gmail import GmailRepository
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
from threading import Lock, Thread, BoundedSemaphore, currentThread
|
||||
try:
|
||||
from Queue import Queue, Empty
|
||||
from queue import Queue, Empty
|
||||
except ImportError: # python3
|
||||
from queue import Queue, Empty
|
||||
import traceback
|
||||
|
@ -14,7 +14,7 @@
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
try:
|
||||
from urllib import urlencode
|
||||
from urllib.parse import urlencode
|
||||
except ImportError: # python3
|
||||
from urllib.parse import urlencode
|
||||
import sys
|
||||
|
@ -23,7 +23,7 @@ import sys
|
||||
import traceback
|
||||
import threading
|
||||
try:
|
||||
from Queue import Queue
|
||||
from queue import Queue
|
||||
except ImportError: # python3
|
||||
from queue import Queue
|
||||
from collections import deque
|
||||
|
@ -13,7 +13,7 @@ def dump(out):
|
||||
for th in threading.enumerate():
|
||||
id2name[th.ident] = th.name
|
||||
n = 0
|
||||
for i, stack in sys._current_frames().items():
|
||||
for i, stack in list(sys._current_frames().items()):
|
||||
out.write ("\n# Thread #%d (id=%d), %s\n" % \
|
||||
(n, i, id2name[i]))
|
||||
n = n + 1
|
||||
|
Loading…
Reference in New Issue
Block a user