Commit 26c3adb4 authored by Barry Warsaw's avatar Barry Warsaw

* Use the ``enum34`` package instead of ``flufl.enum``.

parents c175a703 0120c079
......@@ -93,8 +93,8 @@ case second `m'. Any other spelling is incorrect.""",
'console_scripts' : list(scripts),
},
install_requires = [
'enum34',
'flufl.bounce',
'flufl.enum',
'flufl.i18n',
'flufl.lock',
'httplib2',
......
......@@ -246,7 +246,7 @@ def handle_subscription(mlist, id, action, comment=None):
lang=getUtility(ILanguageManager)[data['language']])
elif action is Action.accept:
key, data = requestdb.get_request(id)
delivery_mode = DeliveryMode(data['delivery_mode'])
delivery_mode = DeliveryMode[data['delivery_mode']]
address = data['address']
display_name = data['display_name']
language = getUtility(ILanguageManager)[data['language']]
......
......@@ -54,7 +54,7 @@ def _membership_sort_key(member):
The members are sorted first by unique list id, then by subscribed email
address, then by role.
"""
return (member.list_id, member.address.email, int(member.role))
return (member.list_id, member.address.email, member.role.value)
......
......@@ -34,7 +34,7 @@ import socket
import logging
from datetime import timedelta
from flufl.enum import Enum
from enum import Enum
from flufl.lock import Lock, NotLockedError, TimeOutError
from lazr.config import as_boolean
......
......@@ -130,7 +130,7 @@ class Members:
DeliveryMode.mime_digests,
DeliveryMode.summary_digests]
elif args.digest is not None:
digest_types = [DeliveryMode(args.digest + '_digests')]
digest_types = [DeliveryMode[args.digest + '_digests']]
else:
# Don't filter on digest type.
pass
......@@ -140,7 +140,7 @@ class Members:
elif args.nomail == 'byadmin':
status_types = [DeliveryStatus.by_moderator]
elif args.nomail.startswith('by'):
status_types = [DeliveryStatus('by_' + args.nomail[2:])]
status_types = [DeliveryStatus['by_' + args.nomail[2:]]]
elif args.nomail == 'enabled':
status_types = [DeliveryStatus.enabled]
elif args.nomail == 'unknown':
......
......@@ -64,4 +64,4 @@ class Status:
message = _('GNU Mailman is in an unexpected state '
'($hostname != $fqdn_name)')
print(message)
return int(status)
return status.value
......@@ -67,11 +67,11 @@ def upgrade(database, store, version, module_path):
def archive_policy(archive, archive_private):
"""Convert archive and archive_private to archive_policy."""
if archive == 0:
return int(ArchivePolicy.never)
return ArchivePolicy.never.value
elif archive_private == 1:
return int(ArchivePolicy.private)
return ArchivePolicy.private.value
else:
return int(ArchivePolicy.public)
return ArchivePolicy.public.value
......
......@@ -32,7 +32,7 @@ from storm.variables import Variable
class _EnumVariable(Variable):
"""Storm variable for supporting flufl.enum.Enum types.
"""Storm variable for supporting enum types.
To use this, make the database column a INTEGER.
"""
......@@ -46,18 +46,18 @@ class _EnumVariable(Variable):
return None
if not from_db:
return value
return self._enum[value]
return self._enum(value)
def parse_get(self, value, to_db):
if value is None:
return None
if not to_db:
return value
return int(value)
return value.value
class Enum(SimpleProperty):
"""Custom Enum type for Storm supporting flufl.enum.Enums."""
"""Custom type for Storm supporting enums."""
variable_class = _EnumVariable
......
......@@ -17,6 +17,7 @@ Development
* Mailman 3 no longer uses ``zc.buildout`` and tests are now run by the
``nose2`` test runner. See ``src/mailman/docs/START.rst`` for details on
how to build Mailman and run the test suite.
* Use the ``enum34`` package instead of ``flufl.enum``.
REST
----
......
......@@ -24,7 +24,7 @@ __all__ = [
]
from flufl.enum import Enum
from enum import Enum
......
......@@ -27,7 +27,7 @@ __all__ = [
]
from flufl.enum import Enum
from enum import Enum
from zope.interface import Interface, Attribute
......
......@@ -30,7 +30,7 @@ __all__ = [
from datetime import timedelta
from flufl.enum import Enum
from enum import Enum
from zope.interface import Interface, Attribute
ALWAYS_REPLY = timedelta()
......
......@@ -28,7 +28,7 @@ __all__ = [
]
from flufl.enum import Enum
from enum import Enum
from zope.interface import Attribute, Interface
......
......@@ -35,7 +35,7 @@ __all__ = [
]
from flufl.enum import Enum
from enum import Enum
from zope.interface import Interface, Attribute
......
......@@ -28,7 +28,7 @@ __all__ = [
]
from flufl.enum import Enum
from enum import Enum
from zope.interface import Interface, Attribute
......
......@@ -25,7 +25,7 @@ __all__ = [
]
from flufl.enum import Enum
from enum import Enum
from zope.interface import Interface, Attribute
......
......@@ -29,7 +29,7 @@ __all__ = [
]
from flufl.enum import Enum
from enum import Enum
from zope.interface import Interface, Attribute
from mailman.interfaces.member import MemberRole
......
......@@ -36,7 +36,7 @@ __all__ = [
]
from flufl.enum import Enum
from enum import Enum
from zope.interface import Interface, Attribute
from mailman.core.errors import MailmanError
......
......@@ -27,7 +27,7 @@ __all__ = [
]
from flufl.enum import Enum
from enum import Enum
from zope.interface import Interface, Attribute
......
......@@ -25,7 +25,7 @@ __all__ = [
]
from flufl.enum import Enum
from enum import Enum
......
......@@ -30,7 +30,7 @@ __all__ = [
]
from flufl.enum import Enum
from enum import Enum
from zope.interface import Interface, Attribute
......
......@@ -90,7 +90,7 @@ You can also use the response set to get the date of the last response sent.
>>> response.address
<Address: [email protected] [not verified] at ...>
>>> response.response_type
<EnumValue: Response.hold [int=1]>
<Response.hold: 1>
>>> response.date_sent
datetime.date(2005, 8, 1)
......
......@@ -217,7 +217,7 @@ There is also a roster containing all the subscribers of a mailing list,
regardless of their role.
>>> def sortkey(member):
... return (member.address.email, int(member.role))
... return (member.address.email, member.role.value)
>>> for member in sorted(mlist.subscribers.members, key=sortkey):
... print member.address.email, member.role
[email protected] MemberRole.member
......
......@@ -332,8 +332,7 @@ membership role.
>>> len(members)
4
>>> def sortkey(member):
... return (member.address.email, member.mailing_list,
... int(member.role))
... return member.address.email, member.mailing_list, member.role.value
>>> for member in sorted(members, key=sortkey):
... print member.address.email, member.mailing_list.list_id, \
... member.role
......
......@@ -178,7 +178,7 @@ class UserAddresses(_AddressBase):
def membership_key(member):
# Sort first by mailing list, then by address, then by role.
return member.list_id, member.address.email, int(member.role)
return member.list_id, member.address.email, member.role.value
class AddressMemberships(MemberCollection):
......
......@@ -36,7 +36,7 @@ import hashlib
from cStringIO import StringIO
from datetime import datetime, timedelta
from flufl.enum import Enum
from enum import Enum
from lazr.config import as_boolean
from restish import http
from restish.http import Response
......@@ -79,7 +79,7 @@ class ExtendedEncoder(json.JSONEncoder):
seconds = obj.seconds + obj.microseconds / 1000000.0
return '{0}d{1}s'.format(obj.days, seconds)
return '{0}d'.format(obj.days)
elif hasattr(obj, 'enum') and issubclass(obj.enum, Enum):
elif isinstance(obj, Enum):
# It's up to the decoding validator to associate this name with
# the right Enum class.
return obj.name
......
......@@ -57,7 +57,7 @@ def member_matcher(request, segments):
return None
try:
role = MemberRole[segments[0]]
except ValueError:
except KeyError:
# Not a valid role.
return None
# No more segments.
......@@ -76,7 +76,7 @@ def roster_matcher(request, segments):
return None
try:
return (), dict(role=MemberRole[segments[1]]), ()
except ValueError:
except KeyError:
# Not a valid role.
return None
......
......@@ -60,7 +60,7 @@ class _ModerationBase:
resource.update(data)
# Check for a matching request type, and insert the type name into the
# resource.
request_type = RequestType(resource.pop('_request_type'))
request_type = RequestType[resource.pop('_request_type')]
if request_type not in expected_request_types:
return None
resource['type'] = request_type.name
......@@ -205,7 +205,7 @@ class MembershipChangeRequest(resource.Resource, _ModerationBase):
return http.not_found()
key, data = results
try:
request_type = RequestType(data['_request_type'])
request_type = RequestType[data['_request_type']]
except ValueError:
return http.bad_request()
if request_type is RequestType.subscription:
......
......@@ -48,9 +48,13 @@ class enum_validator:
self._enum_class = enum_class
def __call__(self, enum_value):
# This will raise a ValueError if the enum value is unknown. Let that
# percolate up.
return self._enum_class[enum_value]
# This will raise a KeyError if the enum value is unknown. The
# Validator API requires turning this into a ValueError.
try:
return self._enum_class[enum_value]
except KeyError as exception:
# Retain the error message.
raise ValueError(exception.message)
def subscriber_validator(subscriber):
......
......@@ -124,7 +124,7 @@ cperson is neither a member, nor a nonmember of the mailing list.
::
>>> def memberkey(member):
... return member.mailing_list, member.address.email, int(member.role)
... return member.mailing_list, member.address.email, member.role.value
>>> dump_list(mlist.members.members, key=memberkey)
<Member: Anne Person <[email protected]>
......
......@@ -28,6 +28,7 @@ __all__ = [
import sys
import datetime
from mailman.interfaces.action import FilterAction
from mailman.interfaces.autorespond import ResponseAction
from mailman.interfaces.digests import DigestFrequency
from mailman.interfaces.mailinglist import Personalization, ReplyToMunging
......@@ -47,6 +48,7 @@ TYPES = dict(
bounce_info_stale_after=seconds_to_delta,
bounce_you_are_disabled_warnings_interval=seconds_to_delta,
digest_volume_frequency=DigestFrequency,
filter_action=FilterAction,
newsgroup_moderation=NewsgroupModeration,
personalize=Personalization,
reply_goes_to_list=ReplyToMunging,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment