Commit 90814a40 authored by Barry Warsaw's avatar Barry Warsaw

Fix the obvious errors identified by pyflakes. Skip false positives (mostly

due to _() interpolation) and a few other problems that did not have
immediately obvious fixes.
parent 3643347f
......@@ -18,7 +18,6 @@
from distribute_setup import use_setuptools
use_setuptools()
import os
import re
import sys
......
......@@ -32,12 +32,10 @@ __all__ = [
import os
import re
import cgi
import time
import errno
import base64
import random
import logging
import htmlentitydefs
# pylint: disable-msg=E0611,W0403
from email.errors import HeaderParseError
......@@ -50,7 +48,6 @@ import mailman.templates
from mailman import passwords
from mailman.config import config
from mailman.core import errors
from mailman.core.i18n import _
from mailman.interfaces.languages import ILanguageManager
from mailman.utilities.string import expand
......@@ -441,7 +438,7 @@ def uncanonstr(s, lang=None):
if isinstance(s, unicode):
return s.encode(charset)
else:
u = unicode(s, charset)
unicode(s, charset)
return s
except UnicodeError:
# Nope, it contains funny characters, so html-ref it
......
......@@ -31,7 +31,6 @@ from zope.component import getUtility
from mailman import Utils
from mailman.app.notifications import send_goodbye_message
from mailman.core import errors
from mailman.core.i18n import _
from mailman.email.message import OwnerNotification
from mailman.email.validate import validate
......
......@@ -31,7 +31,6 @@ from pkg_resources import resource_string
from zope.component import getUtility
from zope.interface import implements
from mailman.config import config
from mailman.core.i18n import _
from mailman.email.message import UserNotification
from mailman.email.validate import validate
......@@ -73,8 +72,8 @@ class Registrar:
# message and confirm through the web.
subject = 'confirm ' + token
confirm_address = mlist.confirm_address(token)
confirm_url = mlist.domain.confirm_url(token)
# For i18n interpolation.
confirm_url = mlist.domain.confirm_url(token)
email_address = address
domain_name = mlist.domain.email_host
contact_address = mlist.domain.contact_address
......
......@@ -30,8 +30,6 @@ __all__ = [
import logging
from mailman.core.i18n import _
log = logging.getLogger('mailman.vette')
......
......@@ -29,7 +29,6 @@ import os
import mailbox
import tempfile
from cStringIO import StringIO
from zope.interface import implements
from zope.interface.interface import adapter_hooks
......@@ -95,7 +94,7 @@ class Pipermail:
def list_url(mlist):
"""See `IArchiver`."""
if mlist.archive_private:
url = mlist.script_url('private') + '/index.html'
return mlist.script_url('private') + '/index.html'
else:
return expand(config.archiver.pipermail.base_url,
dict(listname=mlist.fqdn_listname,
......
......@@ -31,7 +31,6 @@ from base64 import b32encode
from urlparse import urljoin
from zope.interface import implements
from mailman.config import config
from mailman.interfaces.archiver import IArchiver
......
......@@ -58,7 +58,7 @@ def main():
try:
# Be sure the list is locked
mlist = MailList.MailList(listname)
except errors.MMListError, e:
except errors.MMListError:
parser.print_help()
print >> sys.stderr, _('No such list: $listname')
sys.exit(1)
......
......@@ -27,13 +27,12 @@ __all__ = [
import os
import sys
import time
import errno
import signal
import socket
import logging
from datetime import datetime, timedelta
from datetime import timedelta
from flufl.enum import Enum
from lazr.config import as_boolean
from locknix import lockfile
......@@ -119,7 +118,8 @@ def get_lock_data():
with open(config.LOCK_FILE) as fp:
filename = os.path.split(fp.read().strip())[1]
parts = filename.split('.')
timestamp = parts.pop()
# Ignore the timestamp.
parts.pop()
pid = parts.pop()
hostname = parts.pop()
filename = DOT.join(reversed(parts))
......
......@@ -148,7 +148,7 @@ def make_qrunner(name, slice, range, once=False):
class_path = name
try:
qrclass = find_name(class_path)
except ImportError as error:
except ImportError:
if os.environ.get('MAILMAN_UNDER_MASTER_CONTROL') is not None:
# Exit with SIGTERM exit code so the master watcher won't try to
# restart us.
......
......@@ -48,6 +48,8 @@ class ParseState(Enum):
class Caiwireless:
"""Parse mystery style generated by MTA at caiwireless.net."""
implements(IBounceDetector)
def process(self, msg):
if msg.get_content_type() != 'multipart/mixed':
return None
......
......@@ -46,6 +46,8 @@ class ParseState(Enum):
class Microsoft:
"""Microsoft's `SMTPSVC' nears I kin tell."""
implements(IBounceDetector)
def process(self, msg):
if msg.get_content_type() != 'multipart/mixed':
return None
......
......@@ -102,16 +102,16 @@ def autorespond_to_sender(mlist, sender, lang=None):
log.info('hold autoresponse limit hit: %s', sender)
response_set.response_sent(address, Response.hold)
# Send this notification message instead.
text = Utils.maketext(
text = maketext(
'nomoretoday.txt',
{'sender' : sender,
'listname': mlist.fqdn_listname,
'num' : count,
'num' : todays_count,
'owneremail': mlist.owner_address,
},
lang=lang)
with _.using(lang.code):
msg = Message.UserNotification(
msg = UserNotification(
sender, mlist.owner_address,
_('Last autoresponse notification for today'),
text, lang=lang)
......
......@@ -28,10 +28,8 @@ __all__ = [
import cPickle
from pprint import PrettyPrinter
from zope.component import getUtility
from zope.interface import implements
from mailman.config import config
from mailman.core.i18n import _
from mailman.interact import interact
from mailman.interfaces.command import ICLISubCommand
......
......@@ -26,7 +26,6 @@ __all__ = [
import re
import sys
from zope.component import getUtility
from zope.interface import implements
......
......@@ -32,7 +32,6 @@ from email.utils import formataddr, parseaddr
from zope.component import getUtility
from zope.interface import implements
from mailman.config import config
from mailman.core.i18n import _
from mailman.interfaces.command import ContinueProcessing, IEmailCommand
from mailman.interfaces.member import DeliveryMode
......
......@@ -27,8 +27,6 @@ __all__ = [
import os
import sys
import errno
import logging
from lazr.config import ConfigSchema, as_boolean
from pkg_resources import resource_stream
......@@ -37,7 +35,6 @@ from zope.component import getUtility
from zope.interface import Interface, implements
from mailman import version
from mailman.core import errors
from mailman.interfaces.languages import ILanguageManager
from mailman.styles.manager import StyleManager
from mailman.utilities.filesystem import makedirs
......
......@@ -35,7 +35,6 @@ __all__ = [
'BadPasswordSchemeError',
'CantDigestError',
'DiscardMessage',
'EmailAddressError',
'HandlerError',
'HoldMessage',
'LostHeldMessage',
......@@ -43,7 +42,6 @@ __all__ = [
'MailmanException',
'MemberError',
'MustDigestError',
'NotAMemberError',
'PasswordError',
'RejectMessage',
]
......
......@@ -24,7 +24,6 @@ __all__ = [
'_',
'ctime',
'initialize',
'set_language',
]
......
......@@ -37,7 +37,6 @@ __all__ = [
import os
import sys
from pkg_resources import resource_string
from zope.configuration import xmlconfig
......
......@@ -116,7 +116,7 @@ def initialize():
verifyObject(IHandler, handler)
assert handler.name not in config.handlers, (
'Duplicate handler "{0}" found in {1}'.format(
handler.name, handler_finder))
handler.name, handler_class))
config.handlers[handler.name] = handler
# Set up some pipelines.
for pipeline_class in (BuiltInPipeline, VirginPipeline):
......
......@@ -41,5 +41,5 @@ def initialize():
verifyObject(IRule, rule)
assert rule.name not in config.rules, (
'Duplicate rule "{0}" found in {1}'.format(
rule.name, rule_finder))
rule.name, rule_class))
config.rules[rule.name] = rule
......@@ -37,9 +37,6 @@ import mailman.version
from mailman.config import config
from mailman.interfaces.database import IDatabase, SchemaVersionMismatchError
from mailman.model.messagestore import MessageStore
from mailman.model.pending import Pendings
from mailman.model.requests import Requests
from mailman.model.version import Version
from mailman.utilities.string import expand
......
......@@ -26,8 +26,6 @@ __all__ = [
]
import sys
from storm.properties import SimpleProperty
from storm.variables import Variable
......
......@@ -33,14 +33,11 @@ __all__ = [
]
import re
import email
import email.message
import email.utils
from email.charset import Charset
from email.header import Header
from lazr.config import as_boolean
from mailman.config import config
......
......@@ -22,7 +22,7 @@ from __future__ import absolute_import, unicode_literals
__metaclass__ = type
__all__ = [
'IBounceDetector',
'Stop',
'NonFatal',
]
......
......@@ -26,7 +26,8 @@ __all__ = [
'SchemaVersionMismatchError',
]
from zope.interface import Interface, Attribute
from zope.interface import Interface
from mailman.interfaces.errors import MailmanError
from mailman.version import DATABASE_SCHEMA_VERSION
......
......@@ -30,7 +30,6 @@ __all__ = [
from zope.interface import Interface, Attribute
from mailman.core.errors import MailmanError
from mailman.core.i18n import _
......
......@@ -30,7 +30,6 @@ __all__ = [
from zope.interface import Interface, Attribute
from mailman.interfaces.errors import MailmanError
from mailman.interfaces.mailinglist import IMailingList
......
......@@ -21,7 +21,6 @@ from __future__ import absolute_import, unicode_literals
__metaclass__ = type
__all__ = [
'DigestFrequency',
'IAcceptableAlias',
'IAcceptableAliasSet',
'IMailingList',
......@@ -33,8 +32,6 @@ __all__ = [
from flufl.enum import Enum
from zope.interface import Interface, Attribute
from mailman.core.i18n import _
class Personalization(Enum):
......
......@@ -94,7 +94,7 @@ class MembershipIsBannedError(MembershipError):
"""The address is not allowed to subscribe to the mailing list."""
def __init__(self, mlist, address):
super(MembershipIsBanned, self).__init__()
super(MembershipIsBannedError, self).__init__()
self._mlist = mlist
self._address = address
......
......@@ -21,15 +21,12 @@ from __future__ import absolute_import, unicode_literals
__metaclass__ = type
__all__ = [
'SubscriptionService',
'ISubscriptionService',
]
from zope.interface import Interface
from mailman.core.i18n import _
from mailman.interfaces.member import IMember
class ISubscriptionService(Interface):
......
......@@ -35,7 +35,7 @@ from mailman.core.errors import MailmanError
class SomeRecipientsFailed(MailmanError):
"""Delivery to some or all recipients failed"""
def __init__(self, temporary_failures, permanent_failures):
HandlerError.__init__(self)
super(SomeRecipientsFailed, self).__init__()
self.temporary_failures = temporary_failures
self.permanent_failures = permanent_failures
......
......@@ -27,8 +27,6 @@ __all__ = [
from zope.interface import Interface, Attribute
from mailman.core.i18n import _
class ISystem(Interface):
......
......@@ -33,8 +33,7 @@ from mailman.config import config
from mailman.database.model import Model
from mailman.database.types import Enum
from mailman.interfaces.autorespond import (
IAutoResponseRecord, IAutoResponseSet, Response)
from mailman.interfaces.mailinglist import IMailingList
IAutoResponseRecord, IAutoResponseSet)
from mailman.utilities.datetime import today
......
......@@ -25,7 +25,7 @@ __all__ = [
]
from storm.locals import *
from storm.locals import Int, Unicode
from zope.interface import implements
from mailman.database import Model
......
......@@ -24,7 +24,7 @@ __all__ = [
'Member',
]
from storm.locals import *
from storm.locals import Bool, Int, Reference, Unicode
from zope.interface import implements
from mailman.config import config
......
......@@ -25,7 +25,7 @@ __all__ = [
'Message',
]
from storm.locals import *
from storm.locals import AutoReload, Int, RawStr, Unicode
from zope.interface import implements
from mailman.config import config
......
......@@ -25,7 +25,7 @@ __all__ = [
]
from storm.locals import Bool, Int, Reference, Unicode
from storm.locals import Int, Reference, Unicode
from zope.interface import implements
from mailman.database.model import Model
......
......@@ -25,14 +25,14 @@ __all__ = [
'Pendings',
]
import sys
import time
import random
import hashlib
import datetime
from lazr.config import as_timedelta
from storm.locals import *
from storm.locals import DateTime, Int, RawStr, ReferenceSet, Unicode
from zope.interface import implements
from zope.interface.verify import verifyObject
......
......@@ -25,11 +25,10 @@ __all__ = [
]
from storm.locals import *
from storm.locals import Bool, Int, Unicode
from zope.component import getUtility
from zope.interface import implements
from mailman.config import config
from mailman.database.model import Model
from mailman.database.types import Enum
from mailman.interfaces.languages import ILanguageManager
......
......@@ -26,7 +26,7 @@ __all__ = [
from datetime import timedelta
from storm.locals import *
from storm.locals import AutoReload, Int, RawStr, Reference, Unicode
from zope.component import getUtility
from zope.interface import implements
......
......@@ -37,7 +37,7 @@ __all__ = [
]
from storm.expr import And, LeftJoin, Or
from storm.expr import And, Or
from zope.interface import implements
from mailman.config import config
......@@ -45,7 +45,6 @@ from mailman.interfaces.member import DeliveryMode, MemberRole
from mailman.interfaces.roster import IRoster
from mailman.model.address import Address
from mailman.model.member import Member
from mailman.model.preferences import Preferences
......
......@@ -24,7 +24,7 @@ __all__ = [
'User',
]
from storm.locals import *
from storm.locals import Int, Reference, ReferenceSet, Unicode
from zope.interface import implements
from mailman.config import config
......
......@@ -24,7 +24,7 @@ __all__ = [
'Version',
]
from storm.locals import *
from storm.locals import Int, Unicode
from mailman.database.model import Model
......
......@@ -28,8 +28,6 @@ __all__ = [
import time
import logging
from lazr.config import as_boolean
from mailman.config import config
from mailman.interfaces.mailinglist import Personalization
from mailman.interfaces.mta import SomeRecipientsFailed
......@@ -150,9 +148,9 @@ def deliver(mlist, msg, msgdata):
template = config.logging.smtp.failure
if template.lower() != 'no':
substitutions.update(
recip = recip,
recip = recipient,
smtpcode = code,
smtpmsg = smtpmsg,
smtpmsg = smtp_message,
)
log.info('%s', expand(template, substitutions))
# Return the results
......
......@@ -26,10 +26,6 @@ __all__ = [
import os
import grp
import pwd
import time
import errno
import logging
import datetime
......@@ -37,9 +33,7 @@ from locknix.lockfile import Lock
from zope.component import getUtility
from zope.interface import implements
from mailman import Utils
from mailman.config import config
from mailman.core.i18n import _
from mailman.interfaces.listmanager import IListManager
from mailman.interfaces.mta import IMailTransportAgentAliases
......
......@@ -68,7 +68,8 @@ class VERPMixin:
# deliver it to this person, nor can we craft a valid verp
# header. I don't think there's much we can do except ignore
# this recipient.
log.info('Skipping VERP delivery to unqual recip: %s', recip)
log.info('Skipping VERP delivery to unqual recip: %s',
recipient)
return sender
return '{0}@{1}'.format(
expand(config.mta.verp_format, dict(
......
......@@ -238,7 +238,7 @@ def dispose(mlist, msg, msgdata, why):
mlist.ForwardMessage(
msg,
text=_("""\
The attached message matched the %(listname)s mailing list's content filtering
The attached message matched the $listname mailing list's content filtering
rules and was prevented from being forwarded on to the list membership. You
are receiving the only remaining copy of the discarded message.
......
......@@ -76,7 +76,7 @@ def process(mlist, msg, msgdata):
# Reject
text = mlist.member_moderation_notice
if text:
text = Utils.wrap(text)
text = wrap(text)
else:
# Use the default RejectMessage notice string
text = None
......@@ -144,12 +144,12 @@ def do_reject(mlist):
listowner = mlist.GetOwnerEmail()
if mlist.nonmember_rejection_notice:
raise errors.RejectMessage, \
Utils.wrap(_(mlist.nonmember_rejection_notice))
wrap(_(mlist.nonmember_rejection_notice))
else:
raise errors.RejectMessage, Utils.wrap(_("""\
raise errors.RejectMessage, wrap(_("""\
You are not allowed to post to this mailing list, and your message has been
automatically rejected. If you think that your messages are being rejected in
error, contact the mailing list owner at %(listowner)s."""))
error, contact the mailing list owner at ${listowner}."""))
......@@ -163,7 +163,7 @@ def do_discard(mlist, msg):
_('Auto-discard notification'),
lang=mlist.preferred_language)
nmsg.set_type('multipart/mixed')
text = MIMEText(Utils.wrap(_(
text = MIMEText(wrap(_(
'The attached message has been automatically discarded.')),
_charset=mlist.preferred_language.charset)
nmsg.attach(text)
......
......@@ -27,15 +27,12 @@ __all__ = [
import os
import re
import sys
import time
import errno
import hashlib
import logging
import binascii
from email.charset import Charset
from email.generator import Generator
from email.utils import make_msgid, parsedate
from lazr.config import as_boolean
from locknix.lockfile import Lock
......
......@@ -34,15 +34,12 @@ __all__ = [
import os
import sys
import time
import email
import errno
import pickle
import cPickle
import hashlib
import logging
import marshal
import traceback
from cStringIO import StringIO
......
......@@ -24,13 +24,11 @@ __all__ = [
import os
import sys
import time
import logging
from datetime import datetime
from email.Utils import parsedate_tz, mktime_tz, formatdate
from lazr.config import as_boolean, as_timedelta
from lazr.config import as_timedelta
from locknix.lockfile import Lock
from mailman.config import config
......
......@@ -26,7 +26,6 @@ import datetime
from email.Utils import parseaddr
from lazr.config import as_timedelta
from mailman.app.bounces import scan_message
from mailman.config import config
from mailman.core.i18n import _
from mailman.email.utils import split_email
......
......@@ -40,7 +40,7 @@ from zope.interface import implements
from mailman.config import config
from mailman.core.i18n import _
from mailman.email.message import Message, UserNotification
from mailman.email.message import UserNotification
from mailman.interfaces.command import ContinueProcessing, IEmailResults
from mailman.interfaces.languages import ILanguageManager
from mailman.queue import Runner
......
......@@ -130,7 +130,7 @@ class Digester:
# through in the digest messages.