diff options
author | Patrick Totzke <patricktotzke@gmail.com> | 2017-08-20 09:50:26 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-20 09:50:26 +0100 |
commit | 762b7dc1a60dc322876c6b5fa8769037c483eba0 (patch) | |
tree | 464f9eae7f5c6bd7804559671ced1fbcf459cddd | |
parent | 568508ad55ee8d5b48d8465b2887e5749074b73d (diff) | |
parent | e36db1f99d0797f2b984e74fe2f14dafdecb7d39 (diff) |
Merge pull request #1129 from dcbaker/submit/py3k-small-fixes
py3k small fixes
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | alot/commands/__init__.py | 2 | ||||
-rw-r--r-- | alot/commands/envelope.py | 10 | ||||
-rw-r--r-- | alot/commands/globals.py | 2 | ||||
-rw-r--r-- | alot/commands/thread.py | 10 | ||||
-rw-r--r-- | alot/commands/utils.py | 2 | ||||
-rw-r--r-- | alot/crypto.py | 4 | ||||
-rw-r--r-- | alot/db/utils.py | 6 | ||||
-rw-r--r-- | alot/errors.py | 1 | ||||
-rw-r--r-- | alot/helper.py | 8 | ||||
-rw-r--r-- | alot/settings/manager.py | 2 | ||||
-rw-r--r-- | alot/settings/utils.py | 2 | ||||
-rw-r--r-- | alot/ui.py | 2 | ||||
-rw-r--r-- | alot/utils/configobj.py | 4 | ||||
-rw-r--r-- | alot/widgets/globals.py | 33 | ||||
-rw-r--r-- | alot/widgets/thread.py | 1 |
16 files changed, 53 insertions, 37 deletions
@@ -14,3 +14,4 @@ docs/build docs/source/configuration/*table.rst tags .eggs +__pycache__ 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/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 acbb4e28..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 @@ -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 @@ -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/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) diff --git a/alot/crypto.py b/alot/crypto.py index cd03d9e7..52eb8c58 100644 --- a/alot/crypto.py +++ b/alot/crypto.py @@ -196,7 +196,7 @@ def verify_detached(message, signature): except gpg.errors.BadSignatures as e: raise GPGProblem(str(e), code=GPGCode.BAD_SIGNATURE) except gpg.errors.GPGMEError as e: - raise GPGProblem(e.message, code=e.getcode()) + raise GPGProblem(str(e), code=e.getcode()) def decrypt_verify(encrypted): @@ -212,7 +212,7 @@ def decrypt_verify(encrypted): try: (plaintext, _, verify_result) = ctx.decrypt(encrypted, verify=True) except gpg.errors.GPGMEError as e: - raise GPGProblem(e.message, code=e.getcode()) + raise GPGProblem(str(e), code=e.getcode()) # what if the signature is bad? return verify_result.signatures, plaintext 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/errors.py b/alot/errors.py index c312e674..b9763192 100644 --- a/alot/errors.py +++ b/alot/errors.py @@ -19,6 +19,7 @@ class GPGCode(object): class GPGProblem(Exception): """GPG Error""" + def __init__(self, message, code): self.code = code super(GPGProblem, self).__init__(message) 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()) diff --git a/alot/settings/manager.py b/alot/settings/manager.py index 6f9273c2..6c9e80fe 100644 --- a/alot/settings/manager.py +++ b/alot/settings/manager.py @@ -123,7 +123,7 @@ class SettingsManager(object): except ConfigError as e: logging.warning( 'Theme file %s failed validation: %s', - themestring, str(e.message)) + themestring, e) else: break else: diff --git a/alot/settings/utils.py b/alot/settings/utils.py index 23278607..ea56b264 100644 --- a/alot/settings/utils.py +++ b/alot/settings/utils.py @@ -44,7 +44,7 @@ def read_config(configpath=None, specpath=None, checks=None): try: results = config.validate(validator, preserve_errors=True) except ConfigObjError as e: - raise ConfigError(e.message) + raise ConfigError(str(e)) if results is not True: error_msg = '' @@ -174,7 +174,7 @@ class UI(object): try: self.apply_commandline(cmdline) except CommandParseError as e: - self.notify(e.message, priority='error') + self.notify(str(e), priority='error') # move keys are always passed elif cmdline in ['move up', 'move down', 'move page up', 'move page down']: diff --git a/alot/utils/configobj.py b/alot/utils/configobj.py index 5e04409a..d7ce48a4 100644 --- a/alot/utils/configobj.py +++ b/alot/utils/configobj.py @@ -47,7 +47,7 @@ def attr_triple(value): normal = AttrSpec(acc['16fg'], acc['16bg'], 16) high = AttrSpec(acc['256fg'], acc['256bg'], 256) except AttrSpecError as e: - raise ValidateError(e.message) + raise ValidateError(str(e)) return mono, normal, high @@ -141,4 +141,4 @@ def gpg_key(value): try: return crypto.get_key(value) except GPGProblem as e: - raise ValidateError(e.message) + raise ValidateError(str(e)) diff --git a/alot/widgets/globals.py b/alot/widgets/globals.py index 6756149d..f602add0 100644 --- a/alot/widgets/globals.py +++ b/alot/widgets/globals.py @@ -7,7 +7,6 @@ This contains alot-specific :class:`urwid.Widget` used in more than one mode. """ from __future__ import absolute_import -import functools import re import operator import urwid @@ -272,7 +271,6 @@ class HeadersList(urwid.WidgetWrap): return headerlines -@functools.total_ordering class TagWidget(urwid.AttrMap): """ text widget that renders a tagstring. @@ -292,6 +290,7 @@ class TagWidget(urwid.AttrMap): self.translated = representation['translated'] self.hidden = self.translated == '' self.txt = urwid.Text(self.translated, wrap='clip') + self.__hash = hash('{}_{}'.format(self.translated, self.txt)) normal_att = representation['normal'] focus_att = representation['focussed'] self.attmaps = {'normal': normal_att, 'focus': focus_att} @@ -317,11 +316,8 @@ class TagWidget(urwid.AttrMap): def set_unfocussed(self): self.set_attr_map(self.attmaps['normal']) - def __lt__(self, other): - """Groups tags of 1 character first, then alphabetically. - - This groups tags unicode characters at the begnining. - """ + def __cmp(self, other, comparitor): + """Shared comparison method.""" if not isinstance(other, TagWidget): return NotImplemented @@ -329,8 +325,24 @@ class TagWidget(urwid.AttrMap): oth_len = len(other.translated) if (self_len == 1) is not (oth_len == 1): - return self_len < oth_len - return self.translated.lower() < other.translated.lower() + return comparitor(self_len, oth_len) + return comparitor(self.translated.lower(), other.translated.lower()) + + def __lt__(self, other): + """Groups tags of 1 character first, then alphabetically. + + This groups tags unicode characters at the begnining. + """ + return self.__cmp(other, operator.lt) + + def __gt__(self, other): + return self.__cmp(other, operator.gt) + + def __ge__(self, other): + return self.__cmp(other, operator.ge) + + def __le__(self, other): + return self.__cmp(other, operator.le) def __eq__(self, other): if not isinstance(other, TagWidget): @@ -343,3 +355,6 @@ class TagWidget(urwid.AttrMap): if not isinstance(other, TagWidget): return NotImplemented return self.translated.lower() != other.translated.lower() + + def __hash__(self): + return self.__hash diff --git a/alot/widgets/thread.py b/alot/widgets/thread.py index 31b89e9b..4c4e1c30 100644 --- a/alot/widgets/thread.py +++ b/alot/widgets/thread.py @@ -274,7 +274,6 @@ class MessageTree(CollapsibleTree): if headers is None: # collect all header/value pairs in the order they appear - headers = mail.keys() for key, value in mail.items(): dvalue = decode_header(value, normalize=normalize) lines.append((key, dvalue)) |