Skip to content

Commit

Permalink
Run futurize --stage1
Browse files Browse the repository at this point in the history
  • Loading branch information
lukateras authored and BjarniRunar committed Jul 19, 2019
1 parent d334903 commit f66af75
Show file tree
Hide file tree
Showing 82 changed files with 361 additions and 291 deletions.
13 changes: 7 additions & 6 deletions mailpile/app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import getopt
import gettext
import locale
Expand Down Expand Up @@ -141,12 +142,12 @@ def Interact(session):
result = Action(session, opt, arg)
session.ui.block()
session.ui.display_result(result)
except UsageError, e:
except UsageError as e:
session.fatal_error(unicode(e))
except UrlRedirectException, e:
except UrlRedirectException as e:
session.fatal_error('Tried to redirect to: %s' % e.url)
except EOFError:
print
print()
finally:
session.ui.unblock(force=True)

Expand Down Expand Up @@ -181,7 +182,7 @@ def command(self):
splash = HelpSplash(session, 'help', []).run()
motd = MessageOfTheDay(session, 'motd', ['--noupdate']).run()
session.ui.display_result(splash)
print # FIXME: This is a hack!
print() # FIXME: This is a hack!
session.ui.display_result(motd)

Interact(session)
Expand Down Expand Up @@ -246,7 +247,7 @@ def Main(args):
'please log in!'))
HealthCheck(session, None, []).run()
config.prepare_workers(session)
except AccessError, e:
except AccessError as e:
session.ui.error('Access denied: %s\n' % e)
sys.exit(1)

Expand Down Expand Up @@ -282,7 +283,7 @@ def Main(args):
session.ui.display_result(Action(
session, args[0], ' '.join(args[1:]).decode('utf-8')))

except (getopt.GetoptError, UsageError), e:
except (getopt.GetoptError, UsageError) as e:
session.fatal_error(unicode(e))

if (not allopts) and (not a1) and (not a2):
Expand Down
5 changes: 3 additions & 2 deletions mailpile/config/base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import io
import json
import os
Expand Down Expand Up @@ -264,7 +265,7 @@ def as_config(self, config=None, _type=None, _xtype=None):
config.set(section, key, value, comment)
for key in keys:
if hasattr(self[key], 'as_config'):
if isinstance(self[key], (list,)):
if isinstance(self[key], list):
# If a list is marked public, we export all items
self[key].as_config(config=config)
else:
Expand Down Expand Up @@ -814,6 +815,6 @@ class PathDict(ConfigDict):
session.ui.block()

result = doctest.testmod(optionflags=doctest.ELLIPSIS)
print '%s' % (result, )
print('%s' % (result, ))
if result.failed:
sys.exit(1)
5 changes: 3 additions & 2 deletions mailpile/config/defaults.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
APPVER = "1.0.0rc5"
ABOUT = """\
Mailpile.py a tool Copyright 2013-2018, Mailpile ehf
Expand Down Expand Up @@ -260,7 +261,7 @@
import mailpile.config.defaults
from mailpile.config.base import ConfigDict

print '%s' % (ConfigDict(_name='mailpile',
print('%s' % (ConfigDict(_name='mailpile',
_comment='Base configuration',
_rules=mailpile.config.defaults.CONFIG_RULES
).as_config_bytes(), )
).as_config_bytes(), ))
15 changes: 8 additions & 7 deletions mailpile/config/manager.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import copy
import cPickle
import io
Expand Down Expand Up @@ -150,7 +151,7 @@ def create_and_lock_workdir(self, session):
if not os.path.exists(self.workdir):
if session:
session.ui.notify(_('Creating: %s') % self.workdir)
os.makedirs(self.workdir, mode=0700)
os.makedirs(self.workdir, mode=0o700)
mailpile.platforms.RestrictReadAccess(self.workdir)

# Once acquired, lock_workdir is only released by process termination.
Expand Down Expand Up @@ -1300,10 +1301,10 @@ def start_httpd(sspec=None):
except socket.error:
port_in_use = False
if port_in_use:
raise socket.error, errno.EADDRINUSE
raise socket.error(errno.EADDRINUSE)
config.http_worker = HttpWorker(config.background, sspec)
config.http_worker.start()
except socket.error, e:
except socket.error as e:
if e[0] == errno.EADDRINUSE:
session.ui.error(
_('Port %s:%s in use by another Mailpile or program'
Expand Down Expand Up @@ -1462,7 +1463,7 @@ def stop_workers(config):
for w in worker_list:
if w and w.isAlive():
if config.sys.debug and wait:
print 'Waiting for %s' % w
print('Waiting for %s' % w)
w.quit(join=wait)

# Flush the mailbox cache (queues save worker jobs)
Expand All @@ -1474,7 +1475,7 @@ def stop_workers(config):
save_worker = config.save_worker
config.save_worker = config.dumb_worker
if config.sys.debug:
print 'Waiting for %s' % save_worker
print('Waiting for %s' % save_worker)

from mailpile.postinglist import PLC_CACHE_FlushAndClean
PLC_CACHE_FlushAndClean(config.background, keep=0)
Expand All @@ -1483,7 +1484,7 @@ def stop_workers(config):

if config.sys.debug:
# Hooray!
print 'All stopped!'
print('All stopped!')

def _unlocked_notify_workers_config_changed(config):
worker_list = config._unlocked_get_all_workers()
Expand Down Expand Up @@ -1567,6 +1568,6 @@ def _unlocked_notify_workers_config_changed(config):
results = doctest.testmod(optionflags=doctest.ELLIPSIS,
extraglobs={'cfg': cfg,
'session': session})
print '%s' % (results, )
print('%s' % (results, ))
if results.failed:
sys.exit(1)
2 changes: 1 addition & 1 deletion mailpile/config/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
AppDirs = None


def _ensure_exists(path, mode=0700):
def _ensure_exists(path, mode=0o700):
if not os.path.exists(path):
head, tail = os.path.split(path)
_ensure_exists(head)
Expand Down
3 changes: 2 additions & 1 deletion mailpile/config/validators.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import os
import socket
import re
Expand Down Expand Up @@ -367,6 +368,6 @@ def IgnoreCheck(data):
import doctest
import sys
result = doctest.testmod(optionflags=doctest.ELLIPSIS)
print '%s' % (result, )
print('%s' % (result, ))
if result.failed:
sys.exit(1)
7 changes: 4 additions & 3 deletions mailpile/conn_brokers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
# Connection brokers facilitate & manage incoming and outgoing connections.
#
# The idea is that code actually tells us what it wants to do, so we can
Expand Down Expand Up @@ -716,7 +717,7 @@ def get_urls(self, listening_fd, need=None, reject=None):
def DisableUnbrokeredConnections():
"""Enforce the use of brokers EVERYWHERE!"""
def CreateConnWarning(*args, **kwargs):
print '*** socket.create_connection used without a broker ***'
print('*** socket.create_connection used without a broker ***')
traceback.print_stack()
raise IOError('FIXME: Please use within a broker context')
monkey_clean_scc = CreateConnWarning
Expand Down Expand Up @@ -999,7 +1000,7 @@ def SslWrapOnlyOnce(org_sslwrap, sock, *args, **kwargs):
kwargs['server_hostname'] = ctx.address[0]
sock = org_sslwrap(sock, *args, **kwargs)
ctx.encryption = _explain_encryption(sock)
except (socket.error, IOError, ssl.SSLError, ssl.CertificateError), e:
except (socket.error, IOError, ssl.SSLError, ssl.CertificateError) as e:
ctx.error = '%s' % e
raise
return sock
Expand Down Expand Up @@ -1046,6 +1047,6 @@ def SslContextWrapOnlyOnce(org_ctxwrap, self, sock, *args, **kwargs):
import sys
results = doctest.testmod(optionflags=doctest.ELLIPSIS,
extraglobs={})
print '%s' % (results, )
print('%s' % (results, ))
if results.failed:
sys.exit(1)
5 changes: 3 additions & 2 deletions mailpile/crypto/aes_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
# This is a compatibility wrapper for using whatever AES library is handy.
# By default we support Cryptography and pyCrypto, with a preference for
# Cryptography.
Expand Down Expand Up @@ -148,7 +149,7 @@ def aes_ctr_decrypt(key, iv, data):
r1 = results[0]
for result in results[1:]:
if r1[1] != result[1]:
print '%s != %s' % (r1, result)
print('%s != %s' % (r1, result))
okay = False
assert(okay)

Expand All @@ -162,4 +163,4 @@ def aes_ctr_decrypt(key, iv, data):
decrypted = aes_ctr_decrypt(legacy_key, legacy_nonce, legacy_ct)
assert(legacy_data == decrypted)

print "ok"
print("ok")
17 changes: 9 additions & 8 deletions mailpile/crypto/autocrypt_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
# Copyright (C) 2018 Jack Dodds
# This code is part of Mailpile and is hereby released under the
# Gnu Affero Public Licence v.3 - see ../../COPYING and ../../AGPLv3.txt.
Expand Down Expand Up @@ -300,9 +301,9 @@ def _pgp_header(type, body_length):
default_file = os.path.dirname(os.path.abspath(__file__))
default_file = os.path.abspath(default_file + '/../tests/data/pub.key')

print
print 'Default key file:', default_file
print
print()
print('Default key file:', default_file)
print()

key_file_path = raw_input('Enter key file path or <Enter> for default: ')
if key_file_path == '':
Expand All @@ -319,16 +320,16 @@ def _pgp_header(type, body_length):
with open(key_file_path, 'r') as keyfile:
keydata = bytearray( keyfile.read() )

print 'Key length:', len(keydata)
print('Key length:', len(keydata))

newkey, u, i = get_minimal_PGP_key(
keydata, user_id=user_id, subkey_id=subkey_id, binary_out=True)

print 'User ID:', u
print 'Subkey ID:', i
print 'Minimal key length:', len(newkey)
print('User ID:', u)
print('Subkey ID:', i)
print('Minimal key length:', len(newkey))
key_file_path += '.min.gpg'
print 'Minimal key output file:', key_file_path
print('Minimal key output file:', key_file_path)

with open(key_file_path, 'w') as keyfile:
keyfile.write(newkey)
Expand Down
19 changes: 10 additions & 9 deletions mailpile/crypto/gpgi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#coding:utf-8
from __future__ import print_function
import os
import string
import sys
Expand Down Expand Up @@ -389,7 +390,7 @@ def parse_revocation_key(self, line):
pass # FIXME

def parse_unknown(self, line):
print "Unknown line with code '%s'" % (line,)
print("Unknown line with code '%s'" % (line,))

def parse_none(line):
pass
Expand Down Expand Up @@ -490,7 +491,7 @@ def writeout(self, fd, output):
output.close()
except:
if not self.partial_write_ok:
print '%s: %s bytes left' % (self, total)
print('%s: %s bytes left' % (self, total))
traceback.print_exc()
finally:
self.state = 'done'
Expand Down Expand Up @@ -575,7 +576,7 @@ def _debug_all(self, msg):
if self.session:
self.session.debug(msg.rstrip())
else:
print '%s' % str(msg).rstrip()
print('%s' % str(msg).rstrip())

def _debug_none(self, msg):
pass
Expand Down Expand Up @@ -644,7 +645,7 @@ def common_args(self,
if which in binaries:
args.insert(1, "--%s=%s" % (setting, binaries[which]))
else:
print 'wtf: %s not in %s' % (which, binaries)
print('wtf: %s not in %s' % (which, binaries))

if (not self.use_agent) or will_send_passphrase:
if version < (1, 5):
Expand Down Expand Up @@ -780,7 +781,7 @@ def _reap_threads(self):
if thr.isAlive():
thr.join(timeout=15)
if thr.isAlive() and tries > 1:
print 'WARNING: Failed to reap thread %s' % thr
print('WARNING: Failed to reap thread %s' % thr)

def parse_status(self, line, *args):
self.debug('<<STATUS<< %s' % line)
Expand Down Expand Up @@ -1162,7 +1163,7 @@ def sniff(self, data, encoding = None):
found = set()
else:
# Could be PGP packet header. Check for sequence of legal headers.
while skip < len(segment) and body_len <> -1:
while skip < len(segment) and body_len != -1:
# Check this packet header.
prev_partial = partial
ptag, hdr_len, body_len, partial = (
Expand Down Expand Up @@ -1203,12 +1204,12 @@ def sniff(self, data, encoding = None):

dec_start += hdr_len + body_len
skip = dec_start
if is_base64 and body_len <> -1:
if is_base64 and body_len != -1:
enc_start, enc_end, skip = self.base64_segment(dec_start,
dec_start + 6, 0, line_len, line_end )
segment = base64.b64decode(data[enc_start:enc_end])

if is_base64 and body_len <> -1 and skip <> len(segment):
if is_base64 and body_len != -1 and skip != len(segment):
# End of last packet does not match end of data.
found = set()
return found
Expand Down Expand Up @@ -1693,7 +1694,7 @@ def expect_exact(self, proc, exp, timeout=None):
except TimedOut:
timebox[0] = 0
self.gnupg.debug('Timed out')
print 'Boo! %s not found in %s' % (exp, self.before)
print('Boo! %s not found in %s' % (exp, self.before))
raise

def run_script(self, proc, script):
Expand Down
1 change: 1 addition & 0 deletions mailpile/crypto/keyinfo.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import time
import traceback

Expand Down
5 changes: 3 additions & 2 deletions mailpile/crypto/mime.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
# These are methods to do with MIME and crypto, implementing PGP/MIME.

import re
Expand Down Expand Up @@ -237,7 +238,7 @@ def UnwrapMimeCrypto(part, protocols=None, psi=None, pei=None, charsets=None,

# Is there a Memory-Hole force-display part?
pl = part.get_payload()
if hdrs and isinstance(pl, (list, )):
if hdrs and isinstance(pl, list):
if (pl[0]['content-type'].startswith('text/rfc822-headers;')
and 'protected-headers' in pl[0]['content-type']):
# Parse these headers as well and override the top level,
Expand Down Expand Up @@ -800,6 +801,6 @@ def wrap(self, msg, prefer_inline=False):
# we don't have such tests. :-(

results = doctest.testmod(optionflags=doctest.ELLIPSIS)
print '%s' % (results, )
print('%s' % (results, ))
if results.failed:
sys.exit(1)
Loading

0 comments on commit f66af75

Please sign in to comment.