[CalendarServer-changes] [11416] CalendarServer/branches/users/glyph/launchd-wrapper-bis/twext/ python

source_changes at macosforge.org source_changes at macosforge.org
Wed Jun 26 01:14:59 PDT 2013


Revision: 11416
          http://trac.calendarserver.org//changeset/11416
Author:   glyph at apple.com
Date:     2013-06-26 01:14:59 -0700 (Wed, 26 Jun 2013)
Log Message:
-----------
First passing unit test.

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/launchd-wrapper-bis/twext/python/launchd.py
    CalendarServer/branches/users/glyph/launchd-wrapper-bis/twext/python/test/test_launchd.py

Modified: CalendarServer/branches/users/glyph/launchd-wrapper-bis/twext/python/launchd.py
===================================================================
--- CalendarServer/branches/users/glyph/launchd-wrapper-bis/twext/python/launchd.py	2013-06-26 08:14:52 UTC (rev 11415)
+++ CalendarServer/branches/users/glyph/launchd-wrapper-bis/twext/python/launchd.py	2013-06-26 08:14:59 UTC (rev 11416)
@@ -55,6 +55,11 @@
 launch_data_t launch_data_dict_lookup(const launch_data_t, const char *);
 size_t launch_data_dict_get_count(const launch_data_t);
 
+void launch_data_dict_iterate(
+    const launch_data_t,
+    void (*)(const launch_data_t, const char *, void *),
+    void *);
+
 const char * launch_data_get_string(const launch_data_t);
 
 size_t launch_data_array_get_count(const launch_data_t);
@@ -94,9 +99,14 @@
 
     def keys(self):
         """
-        Keys.
+        Return keys in the dictionary.
         """
-        return []
+        keys = []
+        @ffi.callback("void (*)(const launch_data_t, const char *, void *)")
+        def icb(v, k, n):
+            keys.append(ffi.string(k))
+        lib.launch_data_dict_iterate(self.launchdata, icb, ffi.NULL)
+        return keys
 
 
     def __getitem__(self, key):
@@ -120,20 +130,37 @@
 
 
 def _launchify(launchvalue):
+    if launchvalue == ffi.NULL:
+        return None
     dtype = lib.launch_data_get_type(launchvalue)
-    if dtype == lib.LAUNCH_DATA_ERRNO:
-        raise LaunchErrno(launchvalue)
+
+    if dtype == lib.LAUNCH_DATA_DICTIONARY:
+        return LaunchDictionary(launchvalue)
+    elif dtype == lib.LAUNCH_DATA_ARRAY:
+        return LaunchArray(launchvalue)
+    elif dtype == lib.LAUNCH_DATA_FD:
+        return lib.launch_data_get_fd(launchvalue)
+    elif dtype == lib.LAUNCH_DATA_INTEGER:
+        return lib.launch_data_get_integer(launchvalue)
+    elif dtype == lib.LAUNCH_DATA_REAL:
+        raise TypeError("REALs unsupported.")
+    elif dtype == lib.LAUNCH_DATA_BOOL:
+        return lib.launch_data_get_bool(launchvalue)
     elif dtype == lib.LAUNCH_DATA_STRING:
         cvalue = lib.launch_data_get_string(launchvalue)
+        if cvalue == ffi.NULL:
+            return None
         pybytes = ffi.string(cvalue)
         pyunicode = pybytes.decode('utf-8')
         return pyunicode
-    elif dtype == lib.LAUNCH_DATA_ARRAY:
-        return LaunchArray(launchvalue)
-    elif dtype == lib.LAUNCH_DATA_DICTIONARY:
-        return LaunchDictionary(launchvalue)
-    elif dtype in lib.LAUNCH_DATA_FD:
-        return lib.launch_data_get_fd(launchvalue)
+    elif dtype == lib.LAUNCH_DATA_OPAQUE:
+        return launchvalue
+    elif dtype == lib.LAUNCH_DATA_ERRNO:
+        raise LaunchErrno(launchvalue)
+    elif dtype == lib.LAUNCH_DATA_MACHPORT:
+        return lib.launch_data_get_machport(launchvalue)
+    else:
+        raise TypeError("Unknown Launch Data Type", dtype)
 
 import sys
 

Modified: CalendarServer/branches/users/glyph/launchd-wrapper-bis/twext/python/test/test_launchd.py
===================================================================
--- CalendarServer/branches/users/glyph/launchd-wrapper-bis/twext/python/test/test_launchd.py	2013-06-26 08:14:52 UTC (rev 11415)
+++ CalendarServer/branches/users/glyph/launchd-wrapper-bis/twext/python/test/test_launchd.py	2013-06-26 08:14:59 UTC (rev 11416)
@@ -39,12 +39,13 @@
             lib.launch_data_alloc(lib.LAUNCH_DATA_DICTIONARY),
             lib.launch_data_free
         )
-        key1 = lib.launch_data_new_string("alpha")
+        key1 = ffi.new("char[]", "alpha")
         val1 = lib.launch_data_new_string("alpha-value")
-        key2 = lib.launch_data_new_string("beta")
+        key2 = ffi.new("char[]", "beta")
         val2 = lib.launch_data_new_string("beta-value")
-        lib.launch_data_dict_insert(self.testDict, key1, val1)
-        lib.launch_data_dict_insert(self.testDict, key2, val2)
+        lib.launch_data_dict_insert(self.testDict, val1, key1)
+        lib.launch_data_dict_insert(self.testDict, val2, key2)
+        self.assertEquals(lib.launch_data_dict_get_count(self.testDict), 2) 
 
 
     def test_launchDictionaryKeys(self):
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130626/808213db/attachment.html>


More information about the calendarserver-changes mailing list