From dee41bb04906d6976b4f7c05c222f7d95182b3ea Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Wed, 16 Aug 2017 11:37:31 -0700 Subject: Replace Exception.message with str(Exception) In python3 Exception doesn't have a message attribute, the only way to get the string output is to call str() on the Exception. This also works in python 2.7, so go ahead and make that change. --- alot/commands/__init__.py | 2 +- alot/commands/envelope.py | 10 +++++----- alot/commands/thread.py | 6 +++--- alot/commands/utils.py | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) (limited to 'alot/commands') diff --git a/alot/commands/__init__.py b/alot/commands/__init__.py index 351fc993..0638926a 100644 --- a/alot/commands/__init__.py +++ b/alot/commands/__init__.py @@ -167,7 +167,7 @@ def commandfactory(cmdline, mode='global'): try: args = split_commandstring(cmdline) except ValueError as e: - raise CommandParseError(e.message) + raise CommandParseError(str(e)) args = [string_decode(x, 'utf-8') for x in args] logging.debug('ARGS: %s', args) cmdname = args[0] diff --git a/alot/commands/envelope.py b/alot/commands/envelope.py index b9ff51d6..4d2963ee 100644 --- a/alot/commands/envelope.py +++ b/alot/commands/envelope.py @@ -146,8 +146,8 @@ class SaveCommand(Command): ui.apply_command(globals.FlushCommand()) ui.apply_command(commands.globals.BufferCloseCommand()) except DatabaseError as e: - logging.error(e.message) - ui.notify('could not index message:\n%s' % e.message, + logging.error(e) + ui.notify('could not index message:\n%s' % e, priority='error', block=True) else: @@ -217,7 +217,7 @@ class SendCommand(Command): self.mail = email_as_string(self.mail) except GPGProblem as e: ui.clear_notify([clearme]) - ui.notify(e.message, priority='error') + ui.notify(str(e), priority='error') return ui.clear_notify([clearme]) @@ -499,7 +499,7 @@ class SignCommand(Command): sign=True) except GPGProblem as e: envelope.sign = False - ui.notify(e.message, priority='error') + ui.notify(str(e), priority='error') return else: try: @@ -571,7 +571,7 @@ class EncryptCommand(Command): tmp_key = crypto.get_key(keyid) del envelope.encrypt_keys[tmp_key.fpr] except GPGProblem as e: - ui.notify(e.message, priority='error') + ui.notify(str(e), priority='error') if not envelope.encrypt_keys: envelope.encrypt = False ui.current_buffer.rebuild() diff --git a/alot/commands/thread.py b/alot/commands/thread.py index acbb4e28..d73ef622 100644 --- a/alot/commands/thread.py +++ b/alot/commands/thread.py @@ -186,7 +186,7 @@ class ReplyCommand(Command): try: from_header, _ = determine_sender(mail, 'reply') except AssertionError as e: - ui.notify(e.message, priority='error') + ui.notify(str(e), priority='error') return envelope.add('From', from_header) @@ -394,7 +394,7 @@ class ForwardCommand(Command): try: from_header, _ = determine_sender(mail, 'reply') except AssertionError as e: - ui.notify(e.message, priority='error') + ui.notify(str(e), priority='error') return envelope.add('From', from_header) @@ -441,7 +441,7 @@ class BounceMailCommand(Command): try: resent_from_header, account = determine_sender(mail, 'bounce') except AssertionError as e: - ui.notify(e.message, priority='error') + ui.notify(str(e), priority='error') return mail['Resent-From'] = resent_from_header diff --git a/alot/commands/utils.py b/alot/commands/utils.py index 0aa80656..1bf64cbb 100644 --- a/alot/commands/utils.py +++ b/alot/commands/utils.py @@ -86,7 +86,7 @@ def _get_keys(ui, encrypt_keyids, block_error=False, signed_only=False): encrypt_keyids.append(keyid) continue else: - ui.notify(e.message, priority='error', block=block_error) + ui.notify(str(e), priority='error', block=block_error) continue keys[key.fpr] = key returnValue(keys) -- cgit v1.2.3 From fa3dd1b04567c4ea03fa658c3838b569531c79f5 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Wed, 16 Aug 2017 11:50:25 -0700 Subject: Use io.BytesIO and io.StringIO In python3 StringIO and cStringIO are gone. In their place are io.BytesIO and io.StringIO. They are somewhat different in that they are not separated on implementation, but on the type they emulated. BytesIO works like the bytes class (str in python 2), while StringIO works like the str class (unicode in python2). --- alot/commands/globals.py | 2 +- alot/commands/thread.py | 4 ++-- alot/db/utils.py | 6 +++--- alot/helper.py | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) (limited to 'alot/commands') diff --git a/alot/commands/globals.py b/alot/commands/globals.py index 5f9faa3d..b71376a2 100644 --- a/alot/commands/globals.py +++ b/alot/commands/globals.py @@ -12,7 +12,7 @@ import glob import logging import os import subprocess -from StringIO import StringIO +from io import StringIO import urwid from twisted.internet.defer import inlineCallbacks diff --git a/alot/commands/thread.py b/alot/commands/thread.py index d73ef622..02017ae9 100644 --- a/alot/commands/thread.py +++ b/alot/commands/thread.py @@ -14,7 +14,7 @@ from email.utils import getaddresses, parseaddr, formataddr from email.message import Message from twisted.internet.defer import inlineCallbacks -from cStringIO import StringIO +from io import BytesIO from . import Command, registerCommand from .globals import ExternalCommand @@ -970,7 +970,7 @@ class OpenAttachmentCommand(Command): def afterwards(): os.unlink(tempfile_name) else: - handler_stdin = StringIO() + handler_stdin = BytesIO() self.attachment.write(handler_stdin) # create handler command list diff --git a/alot/db/utils.py b/alot/db/utils.py index c24ffef1..488e0ed7 100644 --- a/alot/db/utils.py +++ b/alot/db/utils.py @@ -15,7 +15,7 @@ import tempfile import re import logging import mailcap -from cStringIO import StringIO +from io import BytesIO from .. import crypto from .. import helper @@ -264,14 +264,14 @@ def message_from_file(handle): def message_from_string(s): '''Reads a mail from the given string. This is the equivalent of :func:`email.message_from_string` which does nothing but to wrap - the given string in a StringIO object and to call + the given string in a BytesIO object and to call :func:`email.message_from_file`. Please refer to the documentation of :func:`message_from_file` for details. ''' - return message_from_file(StringIO(s)) + return message_from_file(BytesIO(s)) def extract_headers(mail, headers=None): diff --git a/alot/helper.py b/alot/helper.py index effec6b3..ce307875 100644 --- a/alot/helper.py +++ b/alot/helper.py @@ -9,7 +9,7 @@ from __future__ import division from datetime import timedelta from datetime import datetime from collections import deque -from cStringIO import StringIO +from io import BytesIO import logging import mimetypes import os @@ -315,8 +315,8 @@ def call_cmd_async(cmdlist, stdin=None, env=None): class _EverythingGetter(ProcessProtocol): def __init__(self, deferred): self.deferred = deferred - self.outBuf = StringIO() - self.errBuf = StringIO() + self.outBuf = BytesIO() + self.errBuf = BytesIO() self.outReceived = self.outBuf.write self.errReceived = self.errBuf.write @@ -606,7 +606,7 @@ def email_as_string(mail): :param mail: email to convert to string :rtype: str """ - fp = StringIO() + fp = BytesIO() g = Generator(fp, mangle_from_=False, maxheaderlen=78) g.flatten(mail) as_string = RFC3156_canonicalize(fp.getvalue()) -- cgit v1.2.3