------------------------------------------------------------
revno: 10
committer: Barry Warsaw <[email protected]>
branch nick: trunk
timestamp: Sun 2010-12-26 14:07:13 -0500
message:
Members and subscriptions.
modified:
mailman/client/_client.py
mailman/client/docs/using.txt
--
lp:mailman.client
https://code.launchpad.net/~mailman-coders/mailman.client/trunk
Your team Mailman Coders is subscribed to branch lp:mailman.client.
To unsubscribe from this branch go to
https://code.launchpad.net/~mailman-coders/mailman.client/trunk/+edit-subscription
=== modified file 'mailman/client/_client.py'
--- mailman/client/_client.py 2010-12-25 14:06:50 +0000
+++ mailman/client/_client.py 2010-12-26 19:07:13 +0000
@@ -38,6 +38,16 @@
+def _member_key(member_dict):
+ """Return the keys for sorting a member.
+
+ :param member_dict: The JSON dictionary for a member.
+ :return: 2-tuple of (fqdn_listname, address)
+ """
+ return (member_dict['fqdn_listname'], member_dict['address'])
+
+
+
class _Connection:
"""A connection to the REST client."""
@@ -148,6 +158,15 @@
for entry in sorted(content['entries'],
key=itemgetter('url_host'))]
+ @property
+ def members(self):
+ response, content = self._connection.call('members')
+ if 'entries' not in content:
+ return []
+ return [_Member(self._connection, entry['self_link'])
+ for entry in sorted(content['entries'],
+ key=_member_key)]
+
def create_domain(self, email_host, base_url=None,
description=None, contact_address=None):
data = dict(email_host=email_host)
@@ -252,3 +271,46 @@
def real_name(self):
self._get_info()
return self._info['real_name']
+
+ def subscribe(self, address, real_name=None):
+ """Subscribe an email address to a mailing list.
+
+ :param address: Email address to subscribe to the list.
+ :type address: str
+ :param real_name: The real name of the new member.
+ :type real_name: str
+ """
+ data = dict(
+ fqdn_listname=self.fqdn_listname,
+ address=address,
+ real_name=real_name,
+ )
+ response, content = self._connection.call('members', data)
+ return _Member(self._connection, response['location'])
+
+
+
+class _Member:
+ def __init__(self, connection, url):
+ self._connection = connection
+ self._url = url
+ self._info = None
+
+ def __repr__(self):
+ return '<Member "{0}" on "{1}">'.format(
+ self.address, self.fqdn_listname)
+
+ def _get_info(self):
+ if self._info is None:
+ response, content = self._connection.call(self._url)
+ self._info = content
+
+ @property
+ def fqdn_listname(self):
+ self._get_info()
+ return self._info['fqdn_listname']
+
+ @property
+ def address(self):
+ self._get_info()
+ return self._info['address']
=== modified file 'mailman/client/docs/using.txt'
--- mailman/client/docs/using.txt 2010-12-25 14:06:50 +0000
+++ mailman/client/docs/using.txt 2010-12-26 19:07:13 +0000
@@ -111,10 +111,49 @@
<List "[email protected]">
>>> example.create_list('test-three')
<List "[email protected]">
-
+
>>> for mlist in client.lists:
... print mlist
<List "[email protected]">
<List "[email protected]">
<List "[email protected]">
<List "[email protected]">
+
+
+Membership
+==========
+
+Email addresses can subscribe to existing mailing lists, becoming members of
+that list. The address is a unique id for a specific user in the system, and
+a member is a user that is subscribed to a mailing list. Email addresses need
+not be pre-registered, though the auto-registered user will be unique for each
+email address.
+
+The system starts out with no members.
+
+ >>> client.members
+ []
+
+New members can be easily added; users are automatically registered.
+::
+
+ >>> test_two = client.get_list('[email protected]')
+
+ >>> test_one.subscribe('[email protected]', 'Anna')
+ <Member "[email protected]" on "[email protected]">
+ >>> test_one.subscribe('[email protected]', 'Bill')
+ <Member "[email protected]" on "[email protected]">
+ >>> test_two.subscribe('[email protected]')
+ <Member "[email protected]" on "[email protected]">
+ >>> test_two.subscribe('[email protected]', 'Cris')
+ <Member "[email protected]" on "[email protected]">
+
+We can retrieve all known memberships. These are sorted first by mailing list
+name, then by email address.
+
+ >>> for member in client.members:
+ ... print member
+ <Member "[email protected]" on "[email protected]">
+ <Member "[email protected]" on "[email protected]">
+ <Member "[email protected]" on "[email protected]">
+ <Member "[email protected]" on "[email protected]">
_______________________________________________
Mailman-coders mailing list
[email protected]
http://mail.python.org/mailman/listinfo/mailman-coders