Florian Fuchs has proposed merging lp:~flo-fuchs/mailman.client/settings into 
lp:mailman.client.

Requested reviews:
  Barry Warsaw (barry)

For more details, see:
https://code.launchpad.net/~flo-fuchs/mailman.client/settings/+merge/56088

Hi, 

I have added methods to delete mailing lists as well as a _Settings class to 
read and write list settings. Please feel free to make any changes you want 
(...and, of course, tell me if you feel this should be done completely 
differently...  ;-)

Cheers
Florian

-- 
https://code.launchpad.net/~flo-fuchs/mailman.client/settings/+merge/56088
Your team Mailman Coders is subscribed to branch lp:mailman.client.
=== modified file 'mailman/client/_client.py'
--- mailman/client/_client.py	2010-12-26 21:11:54 +0000
+++ mailman/client/_client.py	2011-04-03 20:58:26 +0000
@@ -189,6 +189,10 @@
             'lists/{0}'.format(fqdn_listname))
         return _List(self._connection, content['self_link'])
 
+    def delete_list(self, fqdn_listname):
+        response, content = self._connection.call(
+            'lists/{0}'.format(fqdn_listname), None, 'DELETE')
+
 
 
 class _Domain:
@@ -282,6 +286,11 @@
                 for entry in sorted(content['entries'],
                                     key=itemgetter('address'))]
 
+    @property
+    def settings(self):
+        return _Settings(self._connection,
+            'lists/{0}/config'.format(self.fqdn_listname))
+
     def get_member(self, address):
         """Get a membership.
 
@@ -318,6 +327,10 @@
             'lists/{0}/member/{1}'.format(self.fqdn_listname, address),
             method='DELETE')
 
+    def delete(self):
+        response, content = self._connection.call(
+            'lists/{0}'.format(self.fqdn_listname), None, 'DELETE')
+
 
 
 class _Member:
@@ -353,3 +366,50 @@
         self._connection.call(
             'lists/{0}/member/{1}'.format(self.fqdn_listname, self.address),
             method='DELETE')
+
+
+READ_ONLY_ATTRS = ('bounces_address', 'created_at', 'digest_last_sent_at',
+                   'fqdn_listname', 'http_etag', 'host_name', 'join_address',
+                   'last_post_at', 'leave_address', 'list_id', 'list_name',
+                   'next_digest_number', 'no_reply_address', 'owner_address',
+                   'post_id', 'posting_address', 'request_address', 'scheme',
+                   'volume', 'web_host',)
+
+
+class _Settings():
+    def __init__(self, connection, url):
+        self._connection = connection
+        self._url = url
+        self._info = None
+        self._get_info()
+
+    def __repr__(self):
+        return repr(self._info)
+
+    def _get_info(self):
+        if self._info is None:
+            response, content = self._connection.call(self._url)
+            self._info = content
+
+    def __iter__(self):
+        for key in self._info.keys():
+            yield key
+
+    def __getitem__(self, key):
+        return self._info[key]
+
+    def __setitem__(self, key, value):
+        self._info[key] = value
+
+    def __len__(self):
+        return len(self._info)
+
+    def save(self):
+        data = {}
+        for attribute, value in self._info.items():
+            if attribute not in READ_ONLY_ATTRS:
+                data[attribute] = value
+        response, content = self._connection.call(self._url, data, 'PATCH')
+
+
+

=== modified file 'mailman/client/docs/using.txt'
--- mailman/client/docs/using.txt	2010-12-26 21:11:54 +0000
+++ mailman/client/docs/using.txt	2011-04-03 20:58:26 +0000
@@ -119,6 +119,20 @@
     <List "[email protected]">
     <List "[email protected]">
 
+You can use a list instance to delete the list.
+
+    >>> test_three = client.get_list('[email protected]')
+    >>> test_three.delete()
+
+You can also delete a list using the client instance's delete_list method.
+
+    >>> client.delete_list('[email protected]')
+
+    >>> for mlist in client.lists:
+    ...     print mlist
+    <List "[email protected]">
+    <List "[email protected]">
+
 
 Membership
 ==========
@@ -188,3 +202,42 @@
     ...     print member
     <Member "[email protected]" on "[email protected]">
     <Member "[email protected]" on "[email protected]">
+
+
+List Settings
+=============
+
+We can get all list settings via a lists settings attribute. A proxy object for the settings is returned which behaves much like a dictionary.
+
+    >>> settings = test_one.settings
+    >>> len(settings)
+    48
+
+    >>> for attr in sorted(settings):
+    ...     print attr + ': ' + str(settings[attr])
+    acceptable_aliases: []
+    ...
+    welcome_msg:
+
+    >>> settings['real_name']
+    u'Test-one'
+
+We can access all valid list settings as attributes.
+
+    >>> settings['fqdn_listname']
+    u'[email protected]'
+    >>> settings['description']
+    u''
+
+    >>> settings['description'] = u'A very meaningful description.'
+    >>> settings['real_name'] = u'Test Numero Uno'
+
+    >>> settings.save()
+
+    >>> settings_new = test_one.settings
+    >>> settings_new['description']
+    u'A very meaningful description.'
+    >>> settings_new['real_name']
+    u'Test Numero Uno'
+
+

_______________________________________________
Mailman-coders mailing list
[email protected]
http://mail.python.org/mailman/listinfo/mailman-coders

Reply via email to