------------------------------------------------------------
revno: 44
committer: Florian Fuchs <[email protected]>
branch nick: mailman.client
timestamp: Thu 2013-03-21 17:38:47 -0700
message:
  * added preferences (RO)
  * test on port 9001
modified:
  src/mailmanclient/_client.py
  src/mailmanclient/docs/using.txt
  src/mailmanclient/tests/test_docs.py


--
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 'src/mailmanclient/_client.py'
--- src/mailmanclient/_client.py	2013-03-21 22:11:33 +0000
+++ src/mailmanclient/_client.py	2013-03-22 00:38:47 +0000
@@ -154,7 +154,7 @@
 
     @property
     def preferences(self):
-        return self._connection.call('system/preferences')[1]
+        return _Preferences(self._connection, 'system/preferences')
 
     @property
     def lists(self):
@@ -760,19 +760,37 @@
         self._info = None
 
 
+PREFERENCE_FIELDS = (
+    'acknowledge_posts',
+    'delivery_mode',
+    'delivery_status',
+    'hide_address',
+    'preferred_language',
+    'receive_list_copy',
+    'receive_own_postings', )
+
+
 class _Preferences:
-    def __init__(self, connection, path):
+    def __init__(self, connection, url):
         self._connection = connection
-        self._path = path
+        self._url = url
         self._preferences = None
         self.delivery_mode = None
         self._get_preferences()
 
+    def __repr__(self):
+        return repr(self._preferences)
+
     def _get_preferences(self):
         if self._preferences is None:
-            response, content = self._connection.call(self._path)
+            response, content = self._connection.call(self._url)
             self._preferences = content
+            for key in PREFERENCE_FIELDS:
+                self._preferences[key] = content.get(key)
 
+    def __setitem__(self, key, value):
+        self._preferences[key] = value
+        
     def __getitem__(self, key):
         return self._preferences[key]
 
@@ -780,6 +798,25 @@
         for key in self._preferences.keys():
             yield self._preferences[key]
 
+    def __len__(self):
+        return len(self._preferences)
+
+    def get(self, key, default=None):
+        try:
+            return self._preferences[key]
+        except KeyError:
+            return default
+
+    def keys(self):
+        return self._preferences.keys()
+
+    def save(self):
+        data = {}
+        for key in self._preferences:
+            if self._preferences[key] is not None:
+                data[key] = self._preferences[key]
+        response, content = self._connection.call(self._url, data, 'PUT')
+
 
 LIST_READ_ONLY_ATTRS = ('bounces_address', 'created_at', 'digest_last_sent_at',
                         'fqdn_listname', 'http_etag', 'mail_host',
@@ -824,6 +861,9 @@
         except KeyError:
             return default
 
+    def keys(self):
+        return self._info.keys()
+
     def save(self):
         data = {}
         for attribute, value in self._info.items():

=== modified file 'src/mailmanclient/docs/using.txt'
--- src/mailmanclient/docs/using.txt	2013-03-21 21:17:54 +0000
+++ src/mailmanclient/docs/using.txt	2013-03-22 00:38:47 +0000
@@ -15,7 +15,7 @@
 providing it the base URL, user name and password (for Basic Auth).
 
     >>> from mailmanclient import Client
-    >>> client = Client('http://localhost:8001/3.0', 'restadmin', 'restpass')
+    >>> client = Client('http://localhost:9001/3.0', 'restadmin', 'restpass')
 
 We can retrieve basic information about the server.
 
@@ -23,7 +23,7 @@
     http_etag: "..."
     mailman_version: GNU Mailman 3.0... (...)
     python_version: ...
-    self_link: http://localhost:8001/3.0/system
+    self_link: http://localhost:9001/3.0/system
 
 To start with, there are no known mailing lists.
 
@@ -218,8 +218,24 @@
     <Member "[email protected]" on "test-two.example.com">
     >>> print cris_test_two.role
     member
-    >>> print cris_test_two.self_link
-    http://localhost:8001/3.0/members/...
+
+A membership has preferences.
+
+    >>> prefs = cris_test_two.preferences
+    >>> print prefs['delivery_mode']
+    regular
+    >>> print prefs['acknowledge_posts']
+    None
+    >>> print prefs['delivery_status']
+    None
+    >>> print prefs['hide_address']
+    None
+    >>> print prefs['preferred_language']
+    None
+    >>> print prefs['receive_list_copy']
+    None
+    >>> print prefs['receive_own_postings']
+    None
 
 The membership object's ``user`` attribute will return a User object:
 
@@ -454,6 +470,8 @@
     >>> print global_prefs['receive_own_postings']
     True
 
+Preferences can be set, but you have to call ``save`` to make your changes permanent.
+
 
 Owners and Moderators
 =====================

=== modified file 'src/mailmanclient/tests/test_docs.py'
--- src/mailmanclient/tests/test_docs.py	2013-03-15 23:02:04 +0000
+++ src/mailmanclient/tests/test_docs.py	2013-03-22 00:38:47 +0000
@@ -91,6 +91,8 @@
 [paths.tmpdir]
 var_dir: {vardir}
 log_dir: /tmp/mmclient/logs
+[webservice]
+port: 9001
 [runner.archive]
 start: no
 [runner.bounces]

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

Reply via email to