8 commits - pykolab/auth pykolab/cli pykolab/conf pykolab/imap pykolab/translit.py pykolab/xml tests/unit

Jeroen van Meeuwen vanmeeuwen at kolabsys.com
Mon Jun 9 16:50:19 CEST 2014


 pykolab/auth/ldap/__init__.py               |   32 ++++++++++++++++-------
 pykolab/cli/cmd_remove_user_subscription.py |    6 ++--
 pykolab/conf/__init__.py                    |   24 ++++++++++++++---
 pykolab/imap/__init__.py                    |   37 ++++++++++++++-------------
 pykolab/translit.py                         |   23 +++++++++++-----
 pykolab/xml/attendee.py                     |    1 
 tests/unit/test-002-attendee.py             |    4 +-
 tests/unit/test-003-event.py                |    4 +-
 tests/unit/test-014-conf-and-raw.py         |   38 ++++++++++++++++++++++++++++
 9 files changed, 124 insertions(+), 45 deletions(-)

New commits:
commit 4b1f0279d79478555d9d568a58199759296a7b2e
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Mon Jun 9 16:49:36 2014 +0200

    Tests setting and getting items with '%' in it (#3099)

diff --git a/tests/unit/test-014-conf-and-raw.py b/tests/unit/test-014-conf-and-raw.py
new file mode 100644
index 0000000..677cb2f
--- /dev/null
+++ b/tests/unit/test-014-conf-and-raw.py
@@ -0,0 +1,38 @@
+# -*- coding: utf-8 -*-
+
+import os
+import pykolab
+import tempfile
+import unittest
+
+conf = pykolab.getConf()
+conf.finalize_conf(fatal=False)
+
+class TestConfRaw(unittest.TestCase):
+    config_file = None
+
+    @classmethod
+    def setup_class(self, *args, **kw):
+        (fp, self.config_file) = tempfile.mkstemp()
+        os.write(fp, '[kolab]\n')
+        os.close(fp)
+        conf.read_config(self.config_file)
+
+    @classmethod
+    def teardown_class(self, *args, **kw):
+        os.remove(self.config_file)
+
+    def test_001_set(self):
+        password = '$%something'
+        conf.command_set('kolab', 'test_password', password)
+        
+    def test_002_get(self):
+        password = conf.get('kolab', 'test_password')
+        self.assertEqual('$%something', password)
+
+    def test_003_get_raw(self):
+        password = conf.get_raw('kolab', 'test_password')
+        self.assertNotEqual('$%something', password)
+
+if __name__ == '__main__':
+    unittest.main()


commit 4825f5d6ae9b9c4266d4b694d6fda1c71a7f04a1
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Mon Jun 9 16:48:47 2014 +0200

    Add commentary with the RFC references (since "OPTIONAL" and "REQUIRED" were changed to "OPT-PARTICIPANT" and "REQ-PARTICIPANT")

diff --git a/pykolab/xml/attendee.py b/pykolab/xml/attendee.py
index 877f810..b496899 100644
--- a/pykolab/xml/attendee.py
+++ b/pykolab/xml/attendee.py
@@ -22,6 +22,7 @@ class Attendee(kolabformat.Attendee):
             #"IN-PROCESS": ,
         }
 
+    # See RFC 2445, 5445
     role_map = {
             "CHAIR": kolabformat.Chair,
             "REQ-PARTICIPANT": kolabformat.Required,


commit b5247cc255d0e5fa1afe9760dca8c026c3539586
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Mon Jun 9 16:23:05 2014 +0200

    "OPTIONAL" is supposed to be "OPT-PARTICIPANT"

diff --git a/tests/unit/test-003-event.py b/tests/unit/test-003-event.py
index 429e5bc..61ea8ec 100644
--- a/tests/unit/test-003-event.py
+++ b/tests/unit/test-003-event.py
@@ -44,7 +44,7 @@ class TestEventXML(unittest.TestCase):
         self.assertEqual(len(self.event.get_attendees()), 1)
 
     def test_005_attendee_add_name_and_props(self):
-        self.event.add_attendee("jane at doe.org", "Doe, Jane", role="OPTIONAL", cutype="RESOURCE")
+        self.event.add_attendee("jane at doe.org", "Doe, Jane", role="OPT-PARTICIPANT", cutype="RESOURCE")
         self.assertIsInstance(self.event.get_attendees(), list)
         self.assertEqual(len(self.event.get_attendees()), 2)
 
@@ -129,7 +129,7 @@ UID:7a35527d-f783-4b58-b404-b1389bd2fc57
 ATTENDEE;CN="Doe, Jane";CUTYPE=INDIVIDUAL;PARTSTAT=ACCEPTED
  ;ROLE=REQ-PARTICIPANT;RSVP=FALSE:MAILTO:jane at doe.org
 ATTENDEE;CUTYPE=RESOURCE;PARTSTAT=NEEDS-ACTION
- ;ROLE=OPTIONAL;RSVP=FALSE:MAILTO:max at imum.com
+ ;ROLE=OPT-PARTICIPANT;RSVP=FALSE:MAILTO:max at imum.com
 SEQUENCE:2
 END:VEVENT
 END:VCALENDAR


commit d7c32d8ce509a16d635569949b1058f832cc0051
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Mon Jun 9 16:22:23 2014 +0200

    Assure when a configuration file is read, it is also configured as the configuration file in use

diff --git a/pykolab/conf/__init__.py b/pykolab/conf/__init__.py
index 675944a..c5e5b09 100644
--- a/pykolab/conf/__init__.py
+++ b/pykolab/conf/__init__.py
@@ -377,6 +377,11 @@ class Conf(object):
         self.cfg_parser = SafeConfigParser()
         self.cfg_parser.read(value)
 
+        if hasattr(self, 'cli_keywords') and hasattr(self.cli_keywords, 'config_file'):
+            self.cli_keywords.config_file = value
+        self.defaults.config_file = value
+        self.config_file = value
+
     def command_get(self, *args, **kw):
         """
             Get a configuration option.
@@ -413,10 +418,21 @@ class Conf(object):
         if not self.cfg_parser.has_section(args[0]):
             log.error(_("No section '%s' exists.") % (args[0]))
 
-        self.cfg_parser.set(args[0], args[1], args[2])
-        fp = open(self.cli_keywords.config_file, "w+")
-        self.cfg_parser.write(fp)
-        fp.close()
+        if '%' in args[2]:
+            value = args[2].replace('%', '%%')
+        else:
+            value = args[2]
+
+        self.cfg_parser.set(args[0], args[1], value)
+
+        if hasattr(self, 'cli_keywords') and hasattr(self.cli_keywords, 'config_file'):
+            fp = open(self.cli_keywords.config_file, "w+")
+            self.cfg_parser.write(fp)
+            fp.close()
+        else:
+            fp = open(self.config_file, "w+")
+            self.cfg_parser.write(fp)
+            fp.close()
 
     def create_logger(self):
         """


commit bf56250be719dae16808914e681b8f08980546c3
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Mon Jun 9 16:21:54 2014 +0200

    Only non-unicode strings need be decoded

diff --git a/pykolab/translit.py b/pykolab/translit.py
index 855e249..fd27d8f 100644
--- a/pykolab/translit.py
+++ b/pykolab/translit.py
@@ -102,13 +102,22 @@ def transliterate(_input, lang, _output_expected=None):
 
     _output = ''
 
-    for char in _input.decode('utf-8'):
-        if translit_map[_translit_name].has_key(char):
-            _output += translit_map[_translit_name][char]
-        elif char in [repr(x) for x in translit_map[_translit_name].keys()]:
-            _output += translit_map[_translit_name][[char in [raw(x) for x in translit_map[_translit_name].keys()]][0]]
-        else:
-            _output += char
+    if not isinstance(_input, unicode):
+        for char in _input.decode('utf-8'):
+            if translit_map[_translit_name].has_key(char):
+                _output += translit_map[_translit_name][char]
+            elif char in [repr(x) for x in translit_map[_translit_name].keys()]:
+                _output += translit_map[_translit_name][[char in [raw(x) for x in translit_map[_translit_name].keys()]][0]]
+            else:
+                _output += char
+    else:
+        for char in _input:
+            if translit_map[_translit_name].has_key(char):
+                _output += translit_map[_translit_name][char]
+            elif char in [repr(x) for x in translit_map[_translit_name].keys()]:
+                _output += translit_map[_translit_name][[char in [raw(x) for x in translit_map[_translit_name].keys()]][0]]
+            else:
+                _output += char
 
     return _output
 


commit fd2ca3c222295bc7b52db6f5edd9a2d911046e81
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Mon Jun 9 16:09:03 2014 +0200

    Fix unit test for attendee

diff --git a/tests/unit/test-002-attendee.py b/tests/unit/test-002-attendee.py
index cbfa9cc..9da93c7 100644
--- a/tests/unit/test-002-attendee.py
+++ b/tests/unit/test-002-attendee.py
@@ -79,13 +79,13 @@ class TestEventXML(unittest.TestCase):
     def test_016_role_map_forward_lookup(self):
         self.assertEqual(self.attendee.role_map["REQ-PARTICIPANT"], 0)
         self.assertEqual(self.attendee.role_map["CHAIR"], 1)
-        self.assertEqual(self.attendee.role_map["OPTIONAL"], 2)
+        self.assertEqual(self.attendee.role_map["OPT-PARTICIPANT"], 2)
         self.assertEqual(self.attendee.role_map["NON-PARTICIPANT"], 3)
 
     def test_017_role_map_reverse_lookup(self):
         self.assertEqual([k for k,v in self.attendee.role_map.iteritems() if v == 0][0], "REQ-PARTICIPANT")
         self.assertEqual([k for k,v in self.attendee.role_map.iteritems() if v == 1][0], "CHAIR")
-        self.assertEqual([k for k,v in self.attendee.role_map.iteritems() if v == 2][0], "OPTIONAL")
+        self.assertEqual([k for k,v in self.attendee.role_map.iteritems() if v == 2][0], "OPT-PARTICIPANT")
         self.assertEqual([k for k,v in self.attendee.role_map.iteritems() if v == 3][0], "NON-PARTICIPANT")
 
     def test_015_cutype_map_length(self):


commit bddd2e8bd8d7dbdbb7b5d1c0eab337e74d0ef019
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Tue May 27 14:15:06 2014 +0200

    Make sure a mailbox is only renamed if it actually exists.

diff --git a/pykolab/auth/ldap/__init__.py b/pykolab/auth/ldap/__init__.py
index 8379c0c..aa9736b 100644
--- a/pykolab/auth/ldap/__init__.py
+++ b/pykolab/auth/ldap/__init__.py
@@ -1346,7 +1346,7 @@ class LDAP(pykolab.base.Base):
                 )
 
         else:
-            folder = "user%s%s" % (self.imap.separator,entry[result_attribute].lower())
+            folder = "user%s%s" % (self.imap.get_separator(),entry[result_attribute].lower())
 
         server = self.imap.user_mailbox_server(folder)
 
@@ -1685,19 +1685,31 @@ class LDAP(pykolab.base.Base):
 
         if entry_changes.has_key(result_attribute):
             if not entry_changes[result_attribute] == old_canon_attr:
-                self.imap.user_mailbox_rename(
-                        old_canon_attr,
-                        entry_changes[result_attribute]
-                    )
+                if old_canon_attr == None:
+                    self.imap.user_mailbox_create(
+                            entry_changes[result_attribute]
+                        )
+
+                else:
+                    self.imap.user_mailbox_rename(
+                            old_canon_attr,
+                            entry_changes[result_attribute]
+                        )
 
                 entry[result_attribute] = entry_changes[result_attribute]
                 cache.get_entry(self.domain, entry)
         elif entry.has_key(result_attribute):
             if not entry[result_attribute] == old_canon_attr:
-                self.imap.user_mailbox_rename(
-                        old_canon_attr,
-                        entry[result_attribute]
-                    )
+                if old_canon_attr == None:
+                    self.imap.user_mailbox_create(
+                            entry[result_attribute]
+                        )
+
+                else:
+                    self.imap.user_mailbox_rename(
+                            old_canon_attr,
+                            entry[result_attribute]
+                        )
 
                 cache.get_entry(self.domain, entry)
 
@@ -1873,7 +1885,7 @@ class LDAP(pykolab.base.Base):
                 server = self.imap.user_mailbox_server(folder)
             else:
                 folder = "user%s%s" % (
-                        self.imap.separator,
+                        self.imap.get_separator(),
                         entry[result_attribute]
                     )
 
diff --git a/pykolab/imap/__init__.py b/pykolab/imap/__init__.py
index c9df6d3..fcf374c 100644
--- a/pykolab/imap/__init__.py
+++ b/pykolab/imap/__init__.py
@@ -384,10 +384,10 @@ class IMAP(object):
             Create a shared folder.
         """
 
-        folder_name = "shared%s%s" % (self.imap.separator, folder_path)
+        folder_name = "shared%s%s" % (self.get_separator(), folder_path)
 
         # Correct folder_path being supplied with "shared/shared/" for example
-        if folder_name.startswith("shared%s" % (self.imap.separator) * 2):
+        if folder_name.startswith("shared%s" % (self.get_separator()) * 2):
             folder_name = folder_name[7:]
 
         log.info(_("Creating new shared folder %s") %(folder_name))
@@ -397,19 +397,19 @@ class IMAP(object):
         """
             Check if a shared mailbox exists.
         """
-        folder_name = 'shared%s%s' % (self.imap.separator, folder_path)
+        folder_name = 'shared%s%s' % (self.get_separator(), folder_path)
 
         # Correct folder_path being supplied with "shared/shared/" for example
-        if folder_name.startswith("shared%s" % (self.imap.separator) * 2):
+        if folder_name.startswith("shared%s" % (self.get_separator()) * 2):
             folder_name = folder_name[7:]
 
         return self.has_folder(folder_name)
 
     def shared_folder_set_type(self, folder_path, folder_type):
-        folder_name = 'shared%s%s' % (self.imap.separator, folder_path)
+        folder_name = 'shared%s%s' % (self.get_separator(), folder_path)
 
         # Correct folder_path being supplied with "shared/shared/" for example
-        if folder_name.startswith("shared%s" % (self.imap.separator) * 2):
+        if folder_name.startswith("shared%s" % (self.get_separator()) * 2):
             folder_name = folder_name[7:]
 
         self.set_metadata(folder_name, '/shared/vendor/kolab/folder-type', folder_type)
@@ -419,10 +419,10 @@ class IMAP(object):
             Create a shared folder.
         """
 
-        folder_name = "shared%s%s" % (self.imap.separator, mailbox_base_name)
+        folder_name = "shared%s%s" % (self.get_separator(), mailbox_base_name)
 
         # Correct folder_path being supplied with "shared/shared/" for example
-        if folder_name.startswith("shared%s" % (self.imap.separator) * 2):
+        if folder_name.startswith("shared%s" % (self.get_separator()) * 2):
             folder_name = folder_name[7:]
 
         log.info(_("Creating new shared folder %s") %(mailbox_base_name))
@@ -432,10 +432,10 @@ class IMAP(object):
         """
             Check if a shared mailbox exists.
         """
-        folder_name = "shared%s%s" % (self.imap.separator, mailbox_base_name)
+        folder_name = "shared%s%s" % (self.get_separator(), mailbox_base_name)
 
         # Correct folder_path being supplied with "shared/shared/" for example
-        if folder_name.startswith("shared%s" % (self.imap.separator) * 2):
+        if folder_name.startswith("shared%s" % (self.get_separator()) * 2):
             folder_name = folder_name[7:]
 
         return self.has_folder(folder_name)
@@ -453,7 +453,7 @@ class IMAP(object):
             log.warning(_("Downcasing mailbox name %r") % (mailbox_base_name))
             mailbox_base_name = mailbox_base_name.lower()
 
-        folder_name = "user%s%s" % (self.imap.separator, mailbox_base_name)
+        folder_name = "user%s%s" % (self.get_separator(), mailbox_base_name)
         log.info(_("Creating new mailbox for user %s") %(mailbox_base_name))
 
         self.create_folder(folder_name, server)
@@ -637,9 +637,9 @@ class IMAP(object):
                 folder_name = additional_folder
 
             folder_name = "user%s%s%s%s%s" % (
-                    self.imap.separator,
+                    self.get_separator(),
                     localpart,
-                    self.imap.separator,
+                    self.get_separator(),
                     folder_name,
                     domain_suffix
                 )
@@ -663,7 +663,7 @@ class IMAP(object):
         """
         self.connect()
 
-        folder = "user%s%s" %(self.imap.separator,mailbox_base_name)
+        folder = "user%s%s" %(self.get_separator(),mailbox_base_name)
         self.delete_mailfolder(folder)
         self.cleanup_acls(mailbox_base_name)
 
@@ -675,7 +675,7 @@ class IMAP(object):
             log.warning(_("Downcasing mailbox name %r") % (mailbox_base_name))
             mailbox_base_name = mailbox_base_name.lower()
 
-        return self.has_folder('user%s%s' %(self.imap.separator, mailbox_base_name))
+        return self.has_folder('user%s%s' %(self.get_separator(), mailbox_base_name))
 
     def user_mailbox_quota(self, mailbox_quota):
         pass
@@ -687,6 +687,9 @@ class IMAP(object):
         if old_name == new_name and partition == None:
             return
 
+        if not self.has_folder(old_name):
+            log.error(_("INBOX folder to rename (%s) does not exist") % (old_name))
+
         if not self.has_folder(new_name) or not partition == None:
             log.info(_("Renaming INBOX from %s to %s") % (old_name,new_name))
             try:
@@ -1023,9 +1026,9 @@ class IMAP(object):
                 #if acceptable:
                     #folder_name = "%s@%s" % (folder.split(self.separator)[1].split('@')[0],folder.split('@')[1])
 
-                folder_name = "%s@%s" % (folder.split(self.imap.separator)[1].split('@')[0],folder.split('@')[1])
+                folder_name = "%s@%s" % (folder.split(self.get_separator())[1].split('@')[0],folder.split('@')[1])
             else:
-                folder_name = "%s" % (folder.split(self.imap.separator)[1])
+                folder_name = "%s" % (folder.split(self.get_separator())[1])
 
             if not folder_name == None:
                 if not folder_name in folders:


commit 919a49642431156183b5f6d7d2e6c9ea8c97793b
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Wed Apr 23 12:02:15 2014 +0200

    LSUB with a pattern does not return the expected results at all

diff --git a/pykolab/cli/cmd_remove_user_subscription.py b/pykolab/cli/cmd_remove_user_subscription.py
index 17ff818..a09bb31 100644
--- a/pykolab/cli/cmd_remove_user_subscription.py
+++ b/pykolab/cli/cmd_remove_user_subscription.py
@@ -74,7 +74,7 @@ def execute(*args, **kw):
         sys.exit(1)
 
     _folders = imap.lm(folder_pattern)
-    _subscribed_folders = imap.lsub(folder_pattern)
+    _subscribed_folders = imap.lsub()
     unsubscribed_folders = []
 
     for _folder in _folders:
@@ -89,8 +89,8 @@ def execute(*args, **kw):
 
         print "\n".join(unsubscribed_folders)
     else:
-        print >> sys.stderr, _("User %s not be unsubscribed from any folders.") % (
+        print >> sys.stderr, _("User %s was not unsubscribed from any folders.") % (
                 user
             )
 
-        sys.exit(1)
\ No newline at end of file
+        sys.exit(1)




More information about the commits mailing list