[CalendarServer-changes] [3375] PyOpenDirectory/trunk

source_changes at macosforge.org source_changes at macosforge.org
Thu Nov 13 07:57:43 PST 2008


Revision: 3375
          http://trac.macosforge.org/projects/calendarserver/changeset/3375
Author:   cdaboo at apple.com
Date:     2008-11-13 07:57:42 -0800 (Thu, 13 Nov 2008)
Log Message:
-----------
Allow client to optionally limit the number of records returned.

Modified Paths:
--------------
    PyOpenDirectory/trunk/pysrc/opendirectory.py
    PyOpenDirectory/trunk/src/CDirectoryService.cpp
    PyOpenDirectory/trunk/src/CDirectoryService.h
    PyOpenDirectory/trunk/src/PythonWrapper.cpp
    PyOpenDirectory/trunk/test.py

Modified: PyOpenDirectory/trunk/pysrc/opendirectory.py
===================================================================
--- PyOpenDirectory/trunk/pysrc/opendirectory.py	2008-11-13 00:10:41 UTC (rev 3374)
+++ PyOpenDirectory/trunk/pysrc/opendirectory.py	2008-11-13 15:57:42 UTC (rev 3375)
@@ -27,7 +27,7 @@
         C{None} on failure.
     """
 
-def listAllRecordsWithAttributes(obj, recordType, attributes):
+def listAllRecordsWithAttributes(obj, recordType, attributes, count=0):
     """
     List records in Open Directory, and return key attributes for each one.
     The attributes can be a C{str} for the attribute name, or a C{tuple} or C{list} where the first C{str}
@@ -36,11 +36,12 @@
     @param obj: C{object} the object obtained from an odInit call.
     @param recordType: C{str}, C{tuple} or C{list} containing the OD record types to lookup.
     @param attributes: C{list} or C{tuple} containing the attributes to return for each record.
+    @param count: C{int} maximum number of records to return (zero returns all).
     @return: C{dict} containing a C{dict} of attributes for each record found,  
         or C{None} otherwise.
     """
 
-def queryRecordsWithAttribute(obj, attr, value, matchType, casei, recordType, attributes):
+def queryRecordsWithAttribute(obj, attr, value, matchType, casei, recordType, attributes, count=0):
     """
     List records in Open Directory matching specified attribute/value, and return key attributes for each one.
     The attributes can be a C{str} for the attribute name, or a C{tuple} or C{list} where the first C{str}
@@ -53,11 +54,12 @@
     @param casei: C{True} to do case-insenstive match, C{False} otherwise.
     @param recordType: C{str}, C{tuple} or C{list} containing the OD record types to lookup.
     @param attributes: C{list} or C{tuple} containing the attributes to return for each record.
+    @param count: C{int} maximum number of records to return (zero returns all).
     @return: C{dict} containing a C{dict} of attributes for each record found,  
         or C{None} otherwise.
     """
 
-def queryRecordsWithAttributes(obj, compound, casei, recordType, attributes):
+def queryRecordsWithAttributes(obj, compound, casei, recordType, attributes, count=0):
     """
     List records in Open Directory matching specified criteria, and return key attributes for each one.
     The attributes can be a C{str} for the attribute name, or a C{tuple} or C{list} where the first C{str}
@@ -68,11 +70,12 @@
     @param casei: C{True} to do case-insenstive match, C{False} otherwise.
     @param recordType: C{str}, C{tuple} or C{list} containing the OD record types to lookup.
     @param attributes: C{list} or C{tuple} containing the attributes to return for each record.
+    @param count: C{int} maximum number of records to return (zero returns all).
     @return: C{dict} containing a C{dict} of attributes for each record found,  
         or C{None} otherwise.
     """
 
-def listAllRecordsWithAttributes_list(obj, recordType, attributes):
+def listAllRecordsWithAttributes_list(obj, recordType, attributes, count=0):
     """
     List records in Open Directory, and return key attributes for each one.
     The attributes can be a C{str} for the attribute name, or a C{tuple} or C{list} where the first C{str}
@@ -81,11 +84,12 @@
     @param obj: C{object} the object obtained from an odInit call.
     @param recordType: C{str}, C{tuple} or C{list} containing the OD record types to lookup.
     @param attributes: C{list} or C{tuple} containing the attributes to return for each record.
+    @param count: C{int} maximum number of records to return (zero returns all).
     @return: C{list} containing a C{list} of C{str} (record name) and C{dict} attributes 
         for each record found, or C{None} otherwise.
     """
 
-def queryRecordsWithAttribute_list(obj, attr, value, matchType, casei, recordType, attributes):
+def queryRecordsWithAttribute_list(obj, attr, value, matchType, casei, recordType, attributes, count=0):
     """
     List records in Open Directory matching specified attribute/value, and return key attributes for each one.
     The attributes can be a C{str} for the attribute name, or a C{tuple} or C{list} where the first C{str}
@@ -98,11 +102,12 @@
     @param casei: C{True} to do case-insenstive match, C{False} otherwise.
     @param recordType: C{str}, C{tuple} or C{list} containing the OD record types to lookup.
     @param attributes: C{list} or C{tuple} containing the attributes to return for each record.
+    @param count: C{int} maximum number of records to return (zero returns all).
     @return: C{list} containing a C{list} of C{str} (record name) and C{dict} attributes 
         for each record found, or C{None} otherwise.
     """
 
-def queryRecordsWithAttributes_list(obj, compound, casei, recordType, attributes, types=None):
+def queryRecordsWithAttributes_list(obj, compound, casei, recordType, attributes, count=0):
     """
     List records in Open Directory matching specified criteria, and return key attributes for each one.
     The attributes can be a C{str} for the attribute name, or a C{tuple} or C{list} where the first C{str}
@@ -113,6 +118,7 @@
     @param casei: C{True} to do case-insenstive match, C{False} otherwise.
     @param recordType: C{str}, C{tuple} or C{list} containing the OD record types to lookup.
     @param attributes: C{list} or C{tuple} containing the attributes to return for each record.
+    @param count: C{int} maximum number of records to return (zero returns all).
     @return: C{list} containing a C{list} of C{str} (record name) and C{dict} attributes 
         for each record found, or C{None} otherwise.
     """

Modified: PyOpenDirectory/trunk/src/CDirectoryService.cpp
===================================================================
--- PyOpenDirectory/trunk/src/CDirectoryService.cpp	2008-11-13 00:10:41 UTC (rev 3374)
+++ PyOpenDirectory/trunk/src/CDirectoryService.cpp	2008-11-13 15:57:42 UTC (rev 3375)
@@ -32,12 +32,6 @@
 
 extern PyObject* ODException_class;
 
-// This is copied from WhitePages
-#define        kDSStdRecordTypeResources                "dsRecTypeStandard:Resources"
-
-// Calendar attribute.
-#define        kDS1AttrCalendarPrincipalURI            "dsAttrTypeStandard:CalendarPrincipalURI"
-
 const int cBufferSize = 32 * 1024;        // 32K buffer for Directory Services operations
 
 #pragma mark -----Public API
@@ -83,19 +77,21 @@
 //
 // @param recordTypes: the record types to list.
 // @param attributes: CFArray of CFString listing the attributes to return for each record.
+// @param maxRecordCount: maximum number of records to return (zero returns all).
+// @param using_python: set to true if called as a Python module, false to call directly from C/C++.
 // @return: CFMutableArrayRef composed of CFMutableArrayRef with a CFStringRef/CFMutableDictionaryRef tuple for
 //          each record, where the CFStringRef is the record name and CFMutableDictionaryRef of CFStringRef key
 //            and value entries for each attribute/value requested in the record indexed by uid,
 //            or NULL if it fails.
 //
-CFMutableArrayRef CDirectoryService::ListAllRecordsWithAttributes(CFArrayRef recordTypes, CFDictionaryRef attributes, bool using_python)
+CFMutableArrayRef CDirectoryService::ListAllRecordsWithAttributes(CFArrayRef recordTypes, CFDictionaryRef attributes, UInt32 maxRecordCount, bool using_python)
 {
     try
     {
         StPythonThreadState threading(using_python);
 
         // Get attribute map
-        return _ListAllRecordsWithAttributes(recordTypes, NULL, attributes);
+        return _ListAllRecordsWithAttributes(recordTypes, NULL, attributes, maxRecordCount);
     }
     catch(CDirectoryServiceException& dserror)
     {
@@ -120,19 +116,21 @@
 // @param casei: true if case-insensitive match is to be used, false otherwise.
 // @param recordTypes: the record types to list.
 // @param attributes: CFArray of CFString listing the attributes to return for each record.
+// @param maxRecordCount: maximum number of records to return (zero returns all).
+// @param using_python: set to true if called as a Python module, false to call directly from C/C++.
 // @return: CFMutableArrayRef composed of CFMutableArrayRef with a CFStringRef/CFMutableDictionaryRef tuple for
 //          each record, where the CFStringRef is the record name and CFMutableDictionaryRef of CFStringRef key
 //          and value entries for each attribute/value requested in the record indexed by uid,
 //          or NULL if it fails.
 //
-CFMutableArrayRef CDirectoryService::QueryRecordsWithAttribute(const char* attr, const char* value, int matchType, bool casei, CFArrayRef recordTypes, CFDictionaryRef attributes, bool using_python)
+CFMutableArrayRef CDirectoryService::QueryRecordsWithAttribute(const char* attr, const char* value, int matchType, bool casei, CFArrayRef recordTypes, CFDictionaryRef attributes, UInt32 maxRecordCount, bool using_python)
 {
     try
     {
         StPythonThreadState threading(using_python);
 
         // Get attribute map
-        return _QueryRecordsWithAttributes(attr, value, matchType, NULL, casei, recordTypes, attributes);
+        return _QueryRecordsWithAttributes(attr, value, matchType, NULL, casei, recordTypes, attributes, maxRecordCount);
     }
     catch(CDirectoryServiceException& dserror)
     {
@@ -155,19 +153,21 @@
 // @param casei: true if case-insensitive match is to be used, false otherwise.
 // @param recordTypes: the record types to list.
 // @param attributes: CFArray of CFString listing the attributes to return for each record.
+// @param maxRecordCount: maximum number of records to return (zero returns all).
+// @param using_python: set to true if called as a Python module, false to call directly from C/C++.
 // @return: CFMutableArrayRef composed of CFMutableArrayRef with a CFStringRef/CFMutableDictionaryRef tuple for
 //          each record, where the CFStringRef is the record name and CFMutableDictionaryRef of CFStringRef key
 //          and value entries for each attribute/value requested in the record indexed by uid,
 //          or NULL if it fails.
 //
-CFMutableArrayRef CDirectoryService::QueryRecordsWithAttributes(const char* query, bool casei, CFArrayRef recordTypes, CFDictionaryRef attributes, bool using_python)
+CFMutableArrayRef CDirectoryService::QueryRecordsWithAttributes(const char* query, bool casei, CFArrayRef recordTypes, CFDictionaryRef attributes, UInt32 maxRecordCount, bool using_python)
 {
     try
     {
         StPythonThreadState threading(using_python);
 
         // Get attribute map
-        return _QueryRecordsWithAttributes(NULL, NULL, 0, query, casei, recordTypes, attributes);
+        return _QueryRecordsWithAttributes(NULL, NULL, 0, query, casei, recordTypes, attributes, maxRecordCount);
     }
     catch(CDirectoryServiceException& dserror)
     {
@@ -253,12 +253,13 @@
 // @param type: the record type to check.
 // @param names: a list of record names to target if NULL all records are matched.
 // @param attributes: a list of attributes to return.
+// @param maxRecordCount: maximum number of records to return (zero returns all).
 // @return: CFMutableArrayRef composed of CFMutableArrayRef with a CFStringRef/CFMutableDictionaryRef tuple for
 //          each record, where the CFStringRef is the record name and CFMutableDictionaryRef of CFStringRef key
 //          and value entries for each attribute/value requested in the record indexed by uid,
 //          or NULL if it fails.
 //
-CFMutableArrayRef CDirectoryService::_ListAllRecordsWithAttributes(CFArrayRef recordTypes, CFArrayRef names, CFDictionaryRef attributes)
+CFMutableArrayRef CDirectoryService::_ListAllRecordsWithAttributes(CFArrayRef recordTypes, CFArrayRef names, CFDictionaryRef attributes, UInt32 maxRecordCount)
 {
     CFMutableArrayRef result = NULL;
     CFMutableArrayRef record_tuple = NULL;
@@ -309,7 +310,7 @@
         do
         {
             // List all the appropriate records
-            UInt32 recCount = 0;
+            UInt32 recCount = maxRecordCount;
             tDirStatus err;
             do
             {
@@ -501,12 +502,13 @@
 // @param casei: true if case-insensitive match is to be used, false otherwise.
 // @param recordTypes: the record type to check.
 // @param attributes: a list of attributes to return.
+// @param maxRecordCount: maximum number of records to return (zero returns all).
 // @return: CFMutableArrayRef composed of CFMutableArrayRef with a CFStringRef/CFMutableDictionaryRef tuple for
 //          each record, where the CFStringRef is the record name and CFMutableDictionaryRef of CFStringRef key
 //          and value entries for each attribute/value requested in the record indexed by uid,
 //          or NULL if it fails.
 //
-CFMutableArrayRef CDirectoryService::_QueryRecordsWithAttributes(const char* attr, const char* value, int matchType, const char* compound, bool casei, CFArrayRef recordTypes, CFDictionaryRef attributes)
+CFMutableArrayRef CDirectoryService::_QueryRecordsWithAttributes(const char* attr, const char* value, int matchType, const char* compound, bool casei, CFArrayRef recordTypes, CFDictionaryRef attributes, UInt32 maxRecordCount)
 {
     CFMutableArrayRef result = NULL;
     CFMutableArrayRef record_tuple = NULL;
@@ -575,7 +577,7 @@
         do
         {
             // List all the appropriate records
-            UInt32 recCount = 0;
+            UInt32 recCount = maxRecordCount;
             tDirStatus err;
             do
             {

Modified: PyOpenDirectory/trunk/src/CDirectoryService.h
===================================================================
--- PyOpenDirectory/trunk/src/CDirectoryService.h	2008-11-13 00:10:41 UTC (rev 3374)
+++ PyOpenDirectory/trunk/src/CDirectoryService.h	2008-11-13 15:57:42 UTC (rev 3375)
@@ -31,9 +31,9 @@
     CDirectoryService(const char* nodename);
     ~CDirectoryService();
 
-    CFMutableArrayRef ListAllRecordsWithAttributes(CFArrayRef recordTypes, CFDictionaryRef attributes, bool using_python=true);
-    CFMutableArrayRef QueryRecordsWithAttribute(const char* attr, const char* value, int matchType, bool casei, CFArrayRef recordTypes, CFDictionaryRef attributes, bool using_python=true);
-    CFMutableArrayRef QueryRecordsWithAttributes(const char* query, bool casei, CFArrayRef recordTypes, CFDictionaryRef attributes, bool using_python=true);
+    CFMutableArrayRef ListAllRecordsWithAttributes(CFArrayRef recordTypes, CFDictionaryRef attributes, UInt32 maxRecordCount=0, bool using_python=true);
+    CFMutableArrayRef QueryRecordsWithAttribute(const char* attr, const char* value, int matchType, bool casei, CFArrayRef recordTypes, CFDictionaryRef attributes, UInt32 maxRecordCount=0, bool using_python=true);
+    CFMutableArrayRef QueryRecordsWithAttributes(const char* query, bool casei, CFArrayRef recordTypes, CFDictionaryRef attributes, UInt32 maxRecordCount=0, bool using_python=true);
 
     bool AuthenticateUserBasic(const char* nodename, const char* user, const char* pswd, bool& result, bool using_python=true);
     bool AuthenticateUserDigest(const char* nodename, const char* user, const char* challenge, const char* response, const char* method, bool& result, bool using_python=true);
@@ -67,8 +67,8 @@
     tDataBufferPtr        mData;
     UInt32                mDataSize;
 
-    CFMutableArrayRef _ListAllRecordsWithAttributes(CFArrayRef recordTypes, CFArrayRef names, CFDictionaryRef attrs);
-    CFMutableArrayRef _QueryRecordsWithAttributes(const char* attr, const char* value, int matchType, const char* compound, bool casei, CFArrayRef recordTypes, CFDictionaryRef attrs);
+    CFMutableArrayRef _ListAllRecordsWithAttributes(CFArrayRef recordTypes, CFArrayRef names, CFDictionaryRef attrs, UInt32 maxRecordCount);
+    CFMutableArrayRef _QueryRecordsWithAttributes(const char* attr, const char* value, int matchType, const char* compound, bool casei, CFArrayRef recordTypes, CFDictionaryRef attrs, UInt32 maxRecordCount);
 
     bool NativeAuthenticationBasicToNode(const char* nodename, const char* user, const char* pswd);
     bool NativeAuthenticationDigestToNode(const char* nodename, const char* user, const char* challenge, const char* response, const char* method);

Modified: PyOpenDirectory/trunk/src/PythonWrapper.cpp
===================================================================
--- PyOpenDirectory/trunk/src/PythonWrapper.cpp	2008-11-13 00:10:41 UTC (rev 3374)
+++ PyOpenDirectory/trunk/src/PythonWrapper.cpp	2008-11-13 15:57:42 UTC (rev 3375)
@@ -388,7 +388,8 @@
     PyObject* pyds;
     PyObject* recordType;
     PyObject* attributes;
-    if (!PyArg_ParseTuple(args, "OOO", &pyds, &recordType, &attributes) || !PyCObject_Check(pyds) || !PyTupleOrList::typeOK(attributes))
+	int maxRecordCount = 0;
+    if (!PyArg_ParseTuple(args, "OOO|i", &pyds, &recordType, &attributes, &maxRecordCount) || !PyCObject_Check(pyds) || !PyTupleOrList::typeOK(attributes))
     {
         PyErr_SetObject(ODException_class, Py_BuildValue("((s:i))", "DirectoryServices listAllRecordsWithAttributes: could not parse arguments", 0));
         return NULL;
@@ -428,7 +429,7 @@
     {
         std::auto_ptr<CDirectoryService> ds(dsmgr->GetService());
         CFMutableArrayRef results = NULL;
-        results = ds->ListAllRecordsWithAttributes(cfrecordtypes, cfattributes);
+        results = ds->ListAllRecordsWithAttributes(cfrecordtypes, cfattributes, maxRecordCount);
         if (results != NULL)
         {
             PyObject* result = list ? CFArrayArrayDictionaryToPyList(results) : CFArrayArrayDictionaryToPyDict(results);
@@ -457,7 +458,8 @@
     bool casei;
     PyObject* recordType;
     PyObject* attributes;
-    if (!PyArg_ParseTuple(args, "OssiOOO", &pyds, &attr, &value, &matchType, &caseio, &recordType, &attributes) ||
+	int maxRecordCount = 0;
+    if (!PyArg_ParseTuple(args, "OssiOOO|i", &pyds, &attr, &value, &matchType, &caseio, &recordType, &attributes, &maxRecordCount) ||
         !PyCObject_Check(pyds) || !PyBool_Check(caseio) || !PyTupleOrList::typeOK(attributes))
     {
         PyErr_SetObject(ODException_class, Py_BuildValue("((s:i))", "DirectoryServices queryRecordsWithAttribute: could not parse arguments", 0));
@@ -500,7 +502,7 @@
     {
         std::auto_ptr<CDirectoryService> ds(dsmgr->GetService());
         CFMutableArrayRef results = NULL;
-        results = ds->QueryRecordsWithAttribute(attr, value, matchType, casei, cfrecordtypes, cfattributes);
+        results = ds->QueryRecordsWithAttribute(attr, value, matchType, casei, cfrecordtypes, cfattributes, maxRecordCount);
         if (results != NULL)
         {
             PyObject* result = list ? CFArrayArrayDictionaryToPyList(results) : CFArrayArrayDictionaryToPyDict(results);
@@ -527,7 +529,8 @@
     bool casei;
     PyObject* recordType;
     PyObject* attributes;
-    if (!PyArg_ParseTuple(args, "OsOOO", &pyds, &query, &caseio, &recordType, &attributes) ||
+	int maxRecordCount = 0;
+    if (!PyArg_ParseTuple(args, "OsOOO|i", &pyds, &query, &caseio, &recordType, &attributes, &maxRecordCount) ||
         !PyCObject_Check(pyds) || !PyBool_Check(caseio) || !PyTupleOrList::typeOK(attributes))
     {
         PyErr_SetObject(ODException_class, Py_BuildValue("((s:i))", "DirectoryServices queryRecordsWithAttributes: could not parse arguments", 0));
@@ -570,7 +573,7 @@
     {
         std::auto_ptr<CDirectoryService> ds(dsmgr->GetService());
         CFMutableArrayRef results = NULL;
-        results = ds->QueryRecordsWithAttributes(query, casei, cfrecordtypes, cfattributes);
+        results = ds->QueryRecordsWithAttributes(query, casei, cfrecordtypes, cfattributes, maxRecordCount);
         if (results != NULL)
         {
             PyObject* result = list ? CFArrayArrayDictionaryToPyList(results) : CFArrayArrayDictionaryToPyDict(results);
@@ -629,7 +632,7 @@
 }
 
 /*
-def listAllRecordsWithAttributes(obj, recordType, attributes):
+def listAllRecordsWithAttributes(obj, recordType, attributes, count=0):
     """
     List records in Open Directory, and return key attributes for each one. The attributes
     can be a C{str} for the attribute name, or a C{tuple} or C{list} where the first C{str}
@@ -638,6 +641,7 @@
     @param obj: C{object} the object obtained from an odInit call.
     @param recordType: C{str}, C{tuple} or C{list} containing the OD record types to lookup.
     @param attributes: C{list} or C{tuple} containing the attributes to return for each record.
+	@param count: C{int} maximum number of records to return (zero returns all).
     @return: C{dict} containing a C{dict} of attributes for each record found,
         or C{None} otherwise.
  */
@@ -647,7 +651,7 @@
 }
 
 /*
-def queryRecordsWithAttribute(obj, attr, value, matchType, casei, recordType, attributes):
+def queryRecordsWithAttribute(obj, attr, value, matchType, casei, recordType, attributes, count=0):
     """
     List records in Open Directory matching specified attribute and value, and return key attributes for each one.
     The attributes can be a C{str} for the attribute name, or a C{tuple} or C{list} where the first C{str}
@@ -660,6 +664,7 @@
     @param casei: C{True} to do case-insenstive match, C{False} otherwise.
     @param recordType: C{str}, C{tuple} or C{list} containing the OD record types to lookup.
     @param attributes: C{list} or C{tuple} containing the attributes to return for each record.
+	@param count: C{int} maximum number of records to return (zero returns all).
     @return: C{dict} containing a C{dict} of attributes for each record found,
         or C{None} otherwise.
     """
@@ -670,7 +675,7 @@
 }
 
 /*
-def queryRecordsWithAttributes(obj, query, casei, recordType, attributes):
+def queryRecordsWithAttributes(obj, query, casei, recordType, attributes, count=0):
     """
     List records in Open Directory matching specified compound query, and return key attributes for each one.
     The attributes can be a C{str} for the attribute name, or a C{tuple} or C{list} where the first C{str}
@@ -681,6 +686,7 @@
     @param casei: C{True} to do case-insenstive match, C{False} otherwise.
     @param recordType: C{str}, C{tuple} or C{list} containing the OD record types to lookup.
     @param attributes: C{list} or C{tuple} containing the attributes to return for each record.
+	@param count: C{int} maximum number of records to return (zero returns all).
     @return: C{dict} containing a C{dict} of attributes for each record found,
         or C{None} otherwise.
     """
@@ -691,7 +697,7 @@
 }
 
 /*
-def listAllRecordsWithAttributes_list(obj, recordType, attributes):
+def listAllRecordsWithAttributes_list(obj, recordType, attributes, count=0):
     """
     List records in Open Directory, and return key attributes for each one.
     The attributes can be a C{str} for the attribute name, or a C{tuple} or C{list} where the first C{str}
@@ -700,6 +706,7 @@
     @param obj: C{object} the object obtained from an odInit call.
     @param recordType: C{str}, C{tuple} or C{list} containing the OD record types to lookup.
     @param attributes: C{list} or C{tuple} containing the attributes to return for each record.
+	@param count: C{int} maximum number of records to return (zero returns all).
     @return: C{list} containing a C{list} of C{str} (record name) and C{dict} attributes
          for each record found, or C{None} otherwise.
     """
@@ -710,7 +717,7 @@
 }
 
 /*
-def queryRecordsWithAttribute_list(obj, attr, value, matchType, casei, recordType, attributes):
+def queryRecordsWithAttribute_list(obj, attr, value, matchType, casei, recordType, attributes, count=0):
     """
     List records in Open Directory matching specified attribute and value, and return key attributes for each one.
     The attributes can be a C{str} for the attribute name, or a C{tuple} or C{list} where the first C{str}
@@ -723,6 +730,7 @@
     @param casei: C{True} to do case-insenstive match, C{False} otherwise.
     @param recordType: C{str}, C{tuple} or C{list} containing the OD record types to lookup.
     @param attributes: C{list} or C{tuple} containing the attributes to return for each record.
+	@param count: C{int} maximum number of records to return (zero returns all).
     @return: C{list} containing a C{list} of C{str} (record name) and C{dict} attributes
          for each record found, or C{None} otherwise.
     """
@@ -733,7 +741,7 @@
 }
 
 /*
-def queryRecordsWithAttributes_list(obj, query, casei, recordType, attributes):
+def queryRecordsWithAttributes_list(obj, query, casei, recordType, attributes, count=0):
     """
     List records in Open Directory matching specified compound query, and return key attributes for each one.
     The attributes can be a C{str} for the attribute name, or a C{tuple} or C{list} where the first C{str}
@@ -744,6 +752,7 @@
     @param casei: C{True} to do case-insenstive match, C{False} otherwise.
     @param recordType: C{str}, C{tuple} or C{list} containing the OD record types to lookup.
     @param attributes: C{list} or C{tuple} containing the attributes to return for each record.
+	@param count: C{int} maximum number of records to return (zero returns all).
     @return: C{list} containing a C{list} of C{str} (record name) and C{dict} attributes
          for each record found, or C{None} otherwise.
     """

Modified: PyOpenDirectory/trunk/test.py
===================================================================
--- PyOpenDirectory/trunk/test.py	2008-11-13 00:10:41 UTC (rev 3374)
+++ PyOpenDirectory/trunk/test.py	2008-11-13 15:57:42 UTC (rev 3375)
@@ -42,6 +42,20 @@
 				print "Name: %s" % n
 				print "dict: %s" % str(d[n])
 	
+	def listUsersCount():
+		d = opendirectory.listAllRecordsWithAttributes(ref, dsattributes.kDSStdRecordTypeUsers,
+													   (
+													   	dsattributes.kDS1AttrGeneratedUID,
+													    dsattributes.kDS1AttrDistinguishedName,
+													    ("dsAttrTypeStandard:JPEGPhoto", "base64"),
+													   ),
+													   10)
+		if d is None:
+			print "Failed to list users"
+		else:
+			names = [v for v in d.iterkeys()]
+			print "\nlistUsers 10 records, number of results = %d" % (len(names),)
+	
 	def listGroups():
 		d = opendirectory.listAllRecordsWithAttributes(ref, dsattributes.kDSStdRecordTypeGroups,
 													   [dsattributes.kDS1AttrGeneratedUID, dsattributes.kDSNAttrGroupMembers,])
@@ -68,7 +82,7 @@
 				print "Name: %s" % n
 				print "dict: %s" % str(d[n])
 	
-	def querySimple(title, attr, value, matchType, casei, recordType, attrs):
+	def querySimple(title, attr, value, matchType, casei, recordType, attrs, count=0):
 		d = opendirectory.queryRecordsWithAttribute(
 		    ref,
 		    attr,
@@ -76,10 +90,14 @@
 		    matchType,
 		    casei,
 			recordType,
-			attrs
+			attrs,
+			count
 		)
 		if d is None:
 			print "Failed to query users"
+		elif count:
+			names = [v for v in d.iterkeys()]
+			print "\n%s %d record limit, got number of results = %d" % (title, count, len(names),)
 		else:
 			names = [v for v in d.iterkeys()]
 			names.sort()
@@ -117,6 +135,30 @@
 			[dsattributes.kDS1AttrGeneratedUID, dsattributes.kDS1AttrDistinguishedName,]
 		)
 		
+	def queryUsersCountNotLimited():
+		querySimple(
+			"queryUsers",
+		    dsattributes.kDS1AttrFirstName,
+		    "cyrus",
+		    dsattributes.eDSExact,
+		    True,
+			dsattributes.kDSStdRecordTypeUsers,
+			[dsattributes.kDS1AttrGeneratedUID, dsattributes.kDS1AttrDistinguishedName,],
+			2
+		)
+		
+	def queryUsersCountLimited():
+		querySimple(
+			"queryUsers",
+		    dsattributes.kDS1AttrFirstName,
+		    "john",
+		    dsattributes.eDSExact,
+		    True,
+			dsattributes.kDSStdRecordTypeUsers,
+			[dsattributes.kDS1AttrGeneratedUID, dsattributes.kDS1AttrDistinguishedName,],
+			10
+		)
+		
 	def queryUsersCompoundOr():
 		queryCompound(
 			"queryUsersCompoundOr",
@@ -309,25 +351,29 @@
 		else:
 			print "Failed to authenticate user"
 	
-	#listUsers()
-	#listGroups()
-	#listComputers()
-	#queryUsers()
-	#queryUsersCompoundOr()
-	#queryUsersCompoundOrExact()
-	#queryUsersCompoundAnd()
-	#listUsers_list()
-	#listGroups_list()
-	#listComputers_list()
-	#queryUsers_list()
-	#queryUsersCompoundOr_list()
-	#queryUsersCompoundOrExact_list()
-	#queryUsersCompoundAnd_list()
+	listUsers()
+	listGroups()
+	listComputers()
+	queryUsers()
+	queryUsersCompoundOr()
+	queryUsersCompoundOrExact()
+	queryUsersCompoundAnd()
+	listUsers_list()
+	listGroups_list()
+	listComputers_list()
+	queryUsers_list()
+	queryUsersCompoundOr_list()
+	queryUsersCompoundOrExact_list()
+	queryUsersCompoundAnd_list()
 
 	listResourcesPlaces_list()
 	queryUsersGroups_list()
 	queryUsersGroupsPlaces_list()
 
+	listUsersCount()
+	queryUsersCountNotLimited()
+	queryUsersCountLimited()
+
 	#authentciateBasic()
 
 	ref = None
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20081113/83925198/attachment-0001.html>


More information about the calendarserver-changes mailing list