diff options
-rw-r--r-- | alot/account.py | 8 | ||||
-rw-r--r-- | alot/commands/globals.py | 21 | ||||
-rw-r--r-- | alot/commands/thread.py | 13 | ||||
-rw-r--r-- | alot/crypto.py | 5 | ||||
-rw-r--r-- | alot/db/envelope.py | 14 | ||||
-rw-r--r-- | alot/db/utils.py | 3 | ||||
-rw-r--r-- | alot/ui.py | 11 | ||||
-rw-r--r-- | tests/commands/global_test.py | 20 | ||||
-rw-r--r-- | tests/commands/utils_tests.py | 6 | ||||
-rw-r--r-- | tests/completion_test.py | 6 | ||||
-rw-r--r-- | tests/crypto_test.py | 24 | ||||
-rw-r--r-- | tests/db/utils_test.py | 24 |
12 files changed, 99 insertions, 56 deletions
diff --git a/alot/account.py b/alot/account.py index 461d2bbf..fe304ac6 100644 --- a/alot/account.py +++ b/alot/account.py @@ -213,9 +213,11 @@ class Account(object): replied_tags = replied_tags or [] passed_tags = passed_tags or [] - self.address = Address.from_string(address, case_sensitive=case_sensitive_username) - self.aliases = [Address.from_string(a, case_sensitive=case_sensitive_username) - for a in (aliases or [])] + self.address = Address.from_string( + address, case_sensitive=case_sensitive_username) + self.aliases = [ + Address.from_string(a, case_sensitive=case_sensitive_username) + for a in (aliases or [])] self.alias_regexp = alias_regexp self.realname = realname self.encrypt_to_self = encrypt_to_self diff --git a/alot/commands/globals.py b/alot/commands/globals.py index d335e8cf..4e272b8e 100644 --- a/alot/commands/globals.py +++ b/alot/commands/globals.py @@ -271,9 +271,10 @@ class ExternalCommand(Command): def thread_code(*_): try: - proc = subprocess.Popen(self.cmdlist, shell=self.shell, - stdin=subprocess.PIPE if stdin else None, - stderr=subprocess.PIPE) + proc = subprocess.Popen( + self.cmdlist, shell=self.shell, + stdin=subprocess.PIPE if stdin else None, + stderr=subprocess.PIPE) except OSError as e: return str(e) @@ -623,8 +624,8 @@ class HelpCommand(Command): globalmaps, modemaps = settings.get_keybindings(ui.mode) # build table - maxkeylength = len(max(list(modemaps.keys()) + list(globalmaps.keys()), - key=len)) + maxkeylength = len( + max(list(modemaps.keys()) + list(globalmaps.keys()), key=len)) keycolumnwidth = maxkeylength + 2 linewidgets = [] @@ -689,10 +690,12 @@ class HelpCommand(Command): class ComposeCommand(Command): """compose a new email""" - def __init__(self, envelope=None, headers=None, template=None, sender=u'', - tags=None, subject=u'', to=None, cc=None, bcc=None, attach=None, - omit_signature=False, spawn=None, rest=None, encrypt=False, - **kwargs): + def __init__( + self, + envelope=None, headers=None, template=None, sender=u'', + tags=None, subject=u'', to=None, cc=None, bcc=None, attach=None, + omit_signature=False, spawn=None, rest=None, encrypt=False, + **kwargs): """ :param envelope: use existing envelope :type envelope: :class:`~alot.db.envelope.Envelope` diff --git a/alot/commands/thread.py b/alot/commands/thread.py index a6380ac9..6a631e62 100644 --- a/alot/commands/thread.py +++ b/alot/commands/thread.py @@ -72,13 +72,16 @@ def determine_sender(mail, action='reply'): # pick the most important account that has an address in candidates # and use that accounts realname and the address found here for account in my_accounts: - acc_addresses = [re.escape(str(a)) for a in account.get_addresses()] + acc_addresses = [ + re.escape(str(a)) for a in account.get_addresses()] if account.alias_regexp is not None: acc_addresses.append(account.alias_regexp) for alias in acc_addresses: regex = re.compile( u'^' + str(alias) + u'$', - flags=re.IGNORECASE if not account.address.case_sensitive else 0) + flags=( + re.IGNORECASE if not account.address.case_sensitive + else 0)) for seen_name, seen_address in candidate_addresses: if regex.match(seen_address): logging.debug("match!: '%s' '%s'", seen_address, alias) @@ -241,7 +244,11 @@ class ReplyCommand(Command): # Reply-To is standart reply target RFC 2822:, RFC 1036: 2.2.1 # X-BeenThere is needed by sourceforge ML also winehq # X-Mailing-List is also standart and is used by git-send-mail - to = mail['Reply-To'] or mail['X-BeenThere'] or mail['X-Mailing-List'] + to = ( + mail['Reply-To'] + or mail['X-BeenThere'] + or mail['X-Mailing-List'] + ) # Some mail server (gmail) will not resend you own mail, so you # have to deal with the one in sent if to is None: diff --git a/alot/crypto.py b/alot/crypto.py index 247dbd19..e7e0bd36 100644 --- a/alot/crypto.py +++ b/alot/crypto.py @@ -112,8 +112,9 @@ def get_key(keyid, validate=False, encrypt=False, sign=False, else: raise e # pragma: nocover if signed_only and not check_uid_validity(key, keyid): - raise GPGProblem('Cannot find a trusworthy key for "{}".'.format(keyid), - code=GPGCode.NOT_FOUND) + raise GPGProblem( + 'Cannot find a trusworthy key for "{}".'.format(keyid), + code=GPGCode.NOT_FOUND) return key diff --git a/alot/db/envelope.py b/alot/db/envelope.py index b742ba81..89a99ffa 100644 --- a/alot/db/envelope.py +++ b/alot/db/envelope.py @@ -223,9 +223,10 @@ class Envelope(object): # wrap signature in MIMEcontainter stype = 'pgp-signature; name="signature.asc"' - signature_mime = MIMEApplication(_data=signature_str.decode('ascii'), - _subtype=stype, - _encoder=encode_7or8bit) + signature_mime = MIMEApplication( + _data=signature_str.decode('ascii'), + _subtype=stype, + _encoder=encode_7or8bit) signature_mime['Content-Description'] = 'signature' signature_mime.set_charset('us-ascii') @@ -255,9 +256,10 @@ class Envelope(object): _encoder=encode_7or8bit) encryption_mime.set_charset('us-ascii') - encrypted_mime = MIMEApplication(_data=encrypted_str.decode('ascii'), - _subtype='octet-stream', - _encoder=encode_7or8bit) + encrypted_mime = MIMEApplication( + _data=encrypted_str.decode('ascii'), + _subtype='octet-stream', + _encoder=encode_7or8bit) encrypted_mime.set_charset('us-ascii') outer_msg.attach(encryption_mime) outer_msg.attach(encrypted_mime) diff --git a/alot/db/utils.py b/alot/db/utils.py index ba32b832..3ed88c74 100644 --- a/alot/db/utils.py +++ b/alot/db/utils.py @@ -364,7 +364,8 @@ def extract_body(mail, types=None, field_key='copiousoutput'): elif cte == 'base64': raw_payload = base64.b64decode(payload) else: - raise Exception('Unknown Content-Transfer-Encoding {}'.format(cte)) + raise Exception( + 'Unknown Content-Transfer-Encoding {}'.format(cte)) # message.get_payload(decode=True) also handles a number of unicode # encodindigs. maybe those are useful? payload = raw_payload.decode(enc) @@ -103,11 +103,12 @@ class UI(object): self._recipients_hist_file, size=size) # set up main loop - self.mainloop = urwid.MainLoop(self.root_widget, - handle_mouse=settings.get('handle_mouse'), - event_loop=urwid.TwistedEventLoop(), - unhandled_input=self._unhandled_input, - input_filter=self._input_filter) + self.mainloop = urwid.MainLoop( + self.root_widget, + handle_mouse=settings.get('handle_mouse'), + event_loop=urwid.TwistedEventLoop(), + unhandled_input=self._unhandled_input, + input_filter=self._input_filter) # Create a defered that calls the loop_hook loop_hook = settings.get_hook('loop_hook') diff --git a/tests/commands/global_test.py b/tests/commands/global_test.py index 102d75c2..59943e5e 100644 --- a/tests/commands/global_test.py +++ b/tests/commands/global_test.py @@ -50,7 +50,8 @@ class TestComposeCommand(unittest.TestCase): return envelope @staticmethod - def _make_account_mock(sign_by_default=True, gpg_key=mock.sentinel.gpg_key): + def _make_account_mock( + sign_by_default=True, gpg_key=mock.sentinel.gpg_key): account = mock.Mock() account.sign_by_default = sign_by_default account.gpg_key = gpg_key @@ -153,8 +154,9 @@ class TestComposeCommand(unittest.TestCase): cmd = g_commands.ComposeCommand(template=f.name) # Crutch to exit the giant `apply` method early. - with mock.patch('alot.commands.globals.settings.get_account_by_address', - mock.Mock(side_effect=Stop)): + with mock.patch( + 'alot.commands.globals.settings.get_account_by_address', + mock.Mock(side_effect=Stop)): try: yield cmd.apply(mock.Mock()) except Stop: @@ -189,7 +191,8 @@ class TestExternalCommand(unittest.TestCase): def test_no_spawn_stdin_attached(self): ui = utilities.make_ui() - cmd = g_commands.ExternalCommand(u"test -t 0", stdin=u'0', refocus=False) + cmd = g_commands.ExternalCommand( + u"test -t 0", stdin=u'0', refocus=False) cmd.apply(ui) ui.notify.assert_called_once_with('', priority='error') @@ -199,7 +202,8 @@ class TestExternalCommand(unittest.TestCase): cmd.apply(ui) ui.notify.assert_called_once_with('', priority='error') - @mock.patch('alot.commands.globals.settings.get', mock.Mock(return_value='')) + @mock.patch( + 'alot.commands.globals.settings.get', mock.Mock(return_value='')) @mock.patch.dict(os.environ, {'DISPLAY': ':0'}) def test_spawn_no_stdin_success(self): ui = utilities.make_ui() @@ -207,7 +211,8 @@ class TestExternalCommand(unittest.TestCase): cmd.apply(ui) ui.notify.assert_not_called() - @mock.patch('alot.commands.globals.settings.get', mock.Mock(return_value='')) + @mock.patch( + 'alot.commands.globals.settings.get', mock.Mock(return_value='')) @mock.patch.dict(os.environ, {'DISPLAY': ':0'}) def test_spawn_stdin_success(self): ui = utilities.make_ui() @@ -217,7 +222,8 @@ class TestExternalCommand(unittest.TestCase): cmd.apply(ui) ui.notify.assert_not_called() - @mock.patch('alot.commands.globals.settings.get', mock.Mock(return_value='')) + @mock.patch( + 'alot.commands.globals.settings.get', mock.Mock(return_value='')) @mock.patch.dict(os.environ, {'DISPLAY': ':0'}) def test_spawn_failure(self): ui = utilities.make_ui() diff --git a/tests/commands/utils_tests.py b/tests/commands/utils_tests.py index 487d0d3b..c17473dc 100644 --- a/tests/commands/utils_tests.py +++ b/tests/commands/utils_tests.py @@ -57,7 +57,8 @@ def setUpModule(): with gpg.core.Context(armor=True) as ctx: # Add the public and private keys. They have no password - search_dir = os.path.join(os.path.dirname(__file__), '../static/gpg-keys') + search_dir = os.path.join( + os.path.dirname(__file__), '../static/gpg-keys') for each in os.listdir(search_dir): if os.path.splitext(each)[1] == '.gpg': with open(os.path.join(search_dir, each)) as f: @@ -106,7 +107,8 @@ class TestGetKeys(unittest.TestCase): @inlineCallbacks def test_get_keys_ambiguous(self): """Test gettings keys when when the key is ambiguous.""" - key = crypto.get_key(FPR, validate=True, encrypt=True, signed_only=False) + key = crypto.get_key( + FPR, validate=True, encrypt=True, signed_only=False) ui = utilities.make_ui() # Creat a ui.choice object that can satisfy twisted, but can also be diff --git a/tests/completion_test.py b/tests/completion_test.py index 5b335779..15a80a89 100644 --- a/tests/completion_test.py +++ b/tests/completion_test.py @@ -57,7 +57,8 @@ class AbooksCompleterTest(unittest.TestCase): self.assertTupleEqual(actual[0], expected[0]) def test_empty_real_name_returns_plain_email_address(self): - actual = self.__class__.example_abook_completer.complete("real-name", 9) + actual = self.__class__.example_abook_completer.complete( + "real-name", 9) expected = [("no-real-name@example.com", 24)] self._assert_only_one_list_entry(actual, expected) @@ -79,7 +80,8 @@ class AbooksCompleterTest(unittest.TestCase): def test_real_name_double_quotes(self): actual = self.__class__.example_abook_completer.complete("dquote", 6) expected = [("", 0)] - expected = [(r""""double \"quote\" person" <dquote@example.com>""", 46)] + expected = [ + (r""""double \"quote\" person" <dquote@example.com>""", 46)] self._assert_only_one_list_entry(actual, expected) def test_real_name_with_quotes_and_comma(self): diff --git a/tests/crypto_test.py b/tests/crypto_test.py index 25cce8ba..c3db1055 100644 --- a/tests/crypto_test.py +++ b/tests/crypto_test.py @@ -59,7 +59,8 @@ def tearDownModule(): lookfor = 'gpg-agent --homedir {}'.format(os.environ['GNUPGHOME']) out = subprocess.check_output( - ['ps', 'xo', 'pid,cmd'], stderr=DEVNULL).decode(urwid.util.detected_encoding) + ['ps', 'xo', 'pid,cmd'], + stderr=DEVNULL).decode(urwid.util.detected_encoding) for each in out.strip().split('\n'): pid, cmd = each.strip().split(' ', 1) if cmd.startswith(lookfor): @@ -113,7 +114,8 @@ class TestDetachedSignatureFor(unittest.TestCase): def test_valid_signature_generated(self): to_sign = b"this is some text.\nit is more than nothing.\n" with gpg.core.Context() as ctx: - _, detached = crypto.detached_signature_for(to_sign, [ctx.get_key(FPR)]) + _, detached = crypto.detached_signature_for( + to_sign, [ctx.get_key(FPR)]) with tempfile.NamedTemporaryFile(delete=False) as f: f.write(detached) @@ -135,7 +137,8 @@ class TestVerifyDetached(unittest.TestCase): def test_verify_signature_good(self): to_sign = b"this is some text.\nIt's something\n." with gpg.core.Context() as ctx: - _, detached = crypto.detached_signature_for(to_sign, [ctx.get_key(FPR)]) + _, detached = crypto.detached_signature_for( + to_sign, [ctx.get_key(FPR)]) try: crypto.verify_detached(to_sign, detached) @@ -146,7 +149,8 @@ class TestVerifyDetached(unittest.TestCase): to_sign = b"this is some text.\nIt's something\n." similar = b"this is some text.\r\n.It's something\r\n." with gpg.core.Context() as ctx: - _, detached = crypto.detached_signature_for(to_sign, [ctx.get_key(FPR)]) + _, detached = crypto.detached_signature_for( + to_sign, [ctx.get_key(FPR)]) with self.assertRaises(GPGProblem): crypto.verify_detached(similar, detached) @@ -180,7 +184,8 @@ class TestValidateKey(unittest.TestCase): def test_encrypt(self): with self.assertRaises(GPGProblem) as caught: - crypto.validate_key(utilities.make_key(can_encrypt=False), encrypt=True) + crypto.validate_key( + utilities.make_key(can_encrypt=False), encrypt=True) self.assertEqual(caught.exception.code, GPGCode.KEY_CANNOT_ENCRYPT) @@ -286,7 +291,8 @@ class TestGetKey(unittest.TestCase): # once. with gpg.core.Context() as ctx: expected = ctx.get_key(FPR).uids[0].uid - actual = crypto.get_key(FPR, validate=True, encrypt=True, sign=True).uids[0].uid + actual = crypto.get_key( + FPR, validate=True, encrypt=True, sign=True).uids[0].uid self.assertEqual(expected, actual) def test_missing_key(self): @@ -306,7 +312,8 @@ class TestGetKey(unittest.TestCase): except GPGProblem as e: raise AssertionError(e) - @mock.patch('alot.crypto.check_uid_validity', mock.Mock(return_value=False)) + @mock.patch( + 'alot.crypto.check_uid_validity', mock.Mock(return_value=False)) def test_signed_only_false(self): with self.assertRaises(GPGProblem) as e: crypto.get_key(FPR, signed_only=True) @@ -370,7 +377,8 @@ class TestEncrypt(unittest.TestCase): enc_file = f.name self.addCleanup(os.unlink, enc_file) - dec = subprocess.check_output(['gpg', '--decrypt', enc_file], stderr=DEVNULL) + dec = subprocess.check_output( + ['gpg', '--decrypt', enc_file], stderr=DEVNULL) self.assertEqual(to_encrypt, dec) diff --git a/tests/db/utils_test.py b/tests/db/utils_test.py index 9013f5ce..25c3641d 100644 --- a/tests/db/utils_test.py +++ b/tests/db/utils_test.py @@ -385,7 +385,8 @@ class TestAddSignatureHeaders(unittest.TestCase): self.assertIn((utils.X_SIGNATURE_VALID_HEADER, u'True'), mail.headers) self.assertIn( - (utils.X_SIGNATURE_MESSAGE_HEADER, u'Untrusted: mocked'), mail.headers) + (utils.X_SIGNATURE_MESSAGE_HEADER, u'Untrusted: mocked'), + mail.headers) def test_unicode_as_bytes(self): mail = self.FakeMail() @@ -395,7 +396,8 @@ class TestAddSignatureHeaders(unittest.TestCase): self.assertIn((utils.X_SIGNATURE_VALID_HEADER, u'True'), mail.headers) self.assertIn( - (utils.X_SIGNATURE_MESSAGE_HEADER, u'Valid: AndreĆ”'), mail.headers) + (utils.X_SIGNATURE_MESSAGE_HEADER, u'Valid: AndreĆ”'), + mail.headers) def test_error_message_unicode(self): mail = self.check(mock.Mock(), mock.Mock(), u'error message') @@ -433,7 +435,8 @@ class TestMessageFromFile(TestCaseClassCleanup): with open(os.path.join(search_dir, each)) as f: ctx.op_import(f) - cls.keys = [ctx.get_key("DD19862809A7573A74058FF255937AFBB156245D")] + cls.keys = [ + ctx.get_key("DD19862809A7573A74058FF255937AFBB156245D")] def test_erase_alot_header_signature_valid(self): """Alot uses special headers for passing certain kinds of information, @@ -490,7 +493,8 @@ class TestMessageFromFile(TestCaseClassCleanup): m = self._make_signed() m = utils.message_from_file(io.StringIO(m.as_string())) # Don't test for valid/invalid since that might change - self.assertIn('ambig <ambig@example.com>', m[utils.X_SIGNATURE_MESSAGE_HEADER]) + self.assertIn( + 'ambig <ambig@example.com>', m[utils.X_SIGNATURE_MESSAGE_HEADER]) def test_signed_wrong_mimetype_second_payload(self): m = self._make_signed() @@ -601,7 +605,8 @@ class TestMessageFromFile(TestCaseClassCleanup): m = self._make_encrypted(True) m = utils.message_from_file(io.StringIO(m.as_string())) self.assertIn(utils.X_SIGNATURE_MESSAGE_HEADER, m) - self.assertIn('ambig <ambig@example.com>', m[utils.X_SIGNATURE_MESSAGE_HEADER]) + self.assertIn( + 'ambig <ambig@example.com>', m[utils.X_SIGNATURE_MESSAGE_HEADER]) # TODO: tests for the RFC 2440 style combined signed/encrypted blob @@ -728,7 +733,8 @@ class TestExtractBody(unittest.TestCase): @mock.patch('alot.db.utils.settings.mailcap_find_match', mock.Mock(return_value=(None, {'view': 'cat'}))) def test_prefer_html(self): - expected = '<!DOCTYPE html><html><body>This is an html email</body></html>' + expected = ( + '<!DOCTYPE html><html><body>This is an html email</body></html>') mail = self._make_mixed_plain_html() actual = utils.extract_body(mail) @@ -755,7 +761,8 @@ class TestExtractBody(unittest.TestCase): '<!DOCTYPE html><html><body>This is an html email</body></html>', 'html')) actual = utils.extract_body(mail) - expected = '<!DOCTYPE html><html><body>This is an html email</body></html>' + expected = ( + '<!DOCTYPE html><html><body>This is an html email</body></html>') self.assertEqual(actual, expected) @@ -768,7 +775,8 @@ class TestExtractBody(unittest.TestCase): '<!DOCTYPE html><html><body>This is an html email</body></html>', 'html')) actual = utils.extract_body(mail) - expected = '<!DOCTYPE html><html><body>This is an html email</body></html>' + expected = ( + '<!DOCTYPE html><html><body>This is an html email</body></html>') self.assertEqual(actual, expected) |