[CalendarServer-changes] [8852] CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav /directory
source_changes at macosforge.org
source_changes at macosforge.org
Tue Mar 13 12:24:47 PDT 2012
Revision: 8852
http://trac.macosforge.org/projects/calendarserver/changeset/8852
Author: gaya at apple.com
Date: 2012-03-13 12:24:47 -0700 (Tue, 13 Mar 2012)
Log Message:
-----------
add propertiesInAddressBookQuery()
Modified Paths:
--------------
CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/ldapdirectorybacker.py
CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/opendirectorybacker.py
Modified: CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/ldapdirectorybacker.py
===================================================================
--- CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/ldapdirectorybacker.py 2012-03-13 18:09:02 UTC (rev 8851)
+++ CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/ldapdirectorybacker.py 2012-03-13 19:24:47 UTC (rev 8852)
@@ -1,5 +1,5 @@
##
-# Copyright (c) 2006-2010 Apple Inc. All rights reserved.
+# Copyright (c) 2006-2012 Apple Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -35,12 +35,11 @@
from twisted.internet import reactor
from twisted.internet.defer import inlineCallbacks, returnValue, succeed
-from twistedcaldav import carddavxml
from twistedcaldav.directory.directory import DirectoryRecord
from twistedcaldav.directory.ldapdirectory import LdapDirectoryService
import ldap
-from twistedcaldav.directory.opendirectorybacker import VCardRecord, getDSFilter
+from twistedcaldav.directory.opendirectorybacker import VCardRecord, dsFilterFromAddressBookFilter, propertiesInAddressBookQuery
class LdapDirectoryBackingService(LdapDirectoryService):
@@ -176,33 +175,16 @@
#to do: use opendirectorybacker: _attributesForAddressBookQuery
def _ldapAttributesForAddressBookQuery(self, addressBookQuery, ldapDSAttrMap ):
- propertyNames = []
- #print( "addressBookQuery.qname=%r" % addressBookQuery.qname)
- if addressBookQuery.qname() == ("DAV:", "prop"):
+ etagRequested, propertyNames = propertiesInAddressBookQuery( addressBookQuery )
- for property in addressBookQuery.children:
- #print("property = %r" % property )
- if isinstance(property, carddavxml.AddressData):
- for addressProperty in property.children:
- #print("addressProperty = %r" % addressProperty )
- if isinstance(addressProperty, carddavxml.Property):
- #print("Adding property %r", addressProperty.attributes["name"])
- propertyNames.append(addressProperty.attributes["name"])
-
- elif not self.fakeETag and property.qname() == ("DAV:", "getetag"):
- # for a real etag == md5(vCard), we need all attributes
- propertyNames = None
- break;
-
+ if etagRequested and not self.fakeETag:
+ propertyNames = None
- if not len(propertyNames):
- #return self.returnedAttributes
- #return None
+ if not propertyNames:
result = ldapDSAttrMap.keys()
self.log_debug("_ldapAttributesForAddressBookQuery returning all props=%s" % result)
else:
- #propertyNames.append("X-INTERNAL-MINIMUM-VCARD-PROPERTIES") # these properties are required to make a vCard
queryAttributes = []
for prop in propertyNames:
searchAttr = ldapDSAttrMap.get()
@@ -238,7 +220,7 @@
searchMap = queryMap["searchMap"]
ldapDSAttrMap = queryMap["ldapDSAttrMap"]
- allRecords, filterAttributes, dsFilter = getDSFilter( addressBookFilter, searchMap );
+ allRecords, filterAttributes, dsFilter = dsFilterFromAddressBookFilter( addressBookFilter, searchMap );
#print("allRecords = %s, query = %s" % (allRecords, "None" if dsFilter is None else dsFilter.generate(),))
self.log_debug("vCardRecordsForAddressBookQuery: queryType = \"%s\" LDAP allRecords = %s, filterAttributes = %s, query = %s" % (queryType, allRecords, filterAttributes, "None" if dsFilter is None else dsFilter.generate(),))
Modified: CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/opendirectorybacker.py
===================================================================
--- CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/opendirectorybacker.py 2012-03-13 18:09:02 UTC (rev 8851)
+++ CalendarServer/branches/users/gaya/ldapdirectorybacker/twistedcaldav/directory/opendirectorybacker.py 2012-03-13 19:24:47 UTC (rev 8852)
@@ -1,5 +1,5 @@
##
-# Copyright (c) 2006-2010 Apple Inc. All rights reserved.
+# Copyright (c) 2006-2012 Apple Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -398,28 +398,14 @@
self.log_info("Timing: Directory query: %.1f ms (%d records, %.2f records/sec)" % (elaspedTime*1000, len(allResults), len(allResults)/elaspedTime))
return succeed(allResults)
- def attributesForAddressBookQuery(self, addressBookQuery, fakeETag=True ):
-
- propertyNames = []
- #print( "addressBookQuery.qname=%r" % addressBookQuery.qname)
- if addressBookQuery.qname() == ("DAV:", "prop"):
+ def _attributesForAddressBookQuery(self, addressBookQuery ):
+
+ etagRequested, propertyNames = propertiesInAddressBookQuery( addressBookQuery )
- for property in addressBookQuery.children:
- #print("property = %r" % property )
- if isinstance(property, carddavxml.AddressData):
- for addressProperty in property.children:
- #print("addressProperty = %r" % addressProperty )
- if isinstance(addressProperty, carddavxml.Property):
- #print("Adding property %r", addressProperty.attributes["name"])
- propertyNames.append(addressProperty.attributes["name"])
-
- elif not fakeETag and property.qname() == ("DAV:", "getetag"):
- # for a real etag == md5(vCard), we need all attributes
- propertyNames = None
- break;
-
-
- if not len(propertyNames):
+ if etagRequested and not self.fakeETag:
+ propertyNames = None
+
+ if not propertyNames:
#print("using all attributes")
return self.returnedAttributes
@@ -441,7 +427,7 @@
Get vCards for a given addressBookFilter and addressBookQuery
"""
- allRecords, filterAttributes, dsFilter = getDSFilter( addressBookFilter, searchMap=VCardRecord.dsqueryAttributesForProperty, allowedAttributes=self.allowedDSQueryAttributes );
+ allRecords, filterAttributes, dsFilter = dsFilterFromAddressBookFilter( addressBookFilter, searchMap=VCardRecord.dsqueryAttributesForProperty, allowedAttributes=self.allowedDSQueryAttributes );
#print("allRecords = %s, query = %s" % (allRecords, "None" if dsFilter is None else dsFilter.generate(),))
# testing:
@@ -455,7 +441,7 @@
limited = False
if not clear:
- queryAttributes = self.attributesForAddressBookQuery( addressBookQuery, fakeETag=self.fakeETag )
+ queryAttributes = self._attributesForAddressBookQuery( addressBookQuery )
attributes = filterAttributes + queryAttributes
#calc maxRecords from passed in maxResults allowing extra for second stage filtering in caller
@@ -481,7 +467,30 @@
#utility
-def getDSFilter(addressBookFilter, searchMap, allowedAttributes=None):
+def propertiesInAddressBookQuery( addressBookQuery ):
+
+ etagRequested = False
+ propertyNames = []
+ #print( "addressBookQuery.qname=%r" % addressBookQuery.qname)
+ if addressBookQuery.qname() == ("DAV:", "prop"):
+
+ for property in addressBookQuery.children:
+ #print("property = %r" % property )
+ if isinstance(property, carddavxml.AddressData):
+ for addressProperty in property.children:
+ #print("addressProperty = %r" % addressProperty )
+ if isinstance(addressProperty, carddavxml.Property):
+ #print("Adding property %r", addressProperty.attributes["name"])
+ propertyNames.append(addressProperty.attributes["name"])
+
+ elif property.qname() == ("DAV:", "getetag"):
+ # for a real etag == md5(vCard), we need all attributes
+ etagRequested = True
+
+ return (etagRequested, propertyNames if len(propertyNames) else None)
+
+
+def dsFilterFromAddressBookFilter(addressBookFilter, searchMap, allowedAttributes=None):
"""
Convert the supplied addressbook-query into a ds expression tree.
@@ -781,7 +790,7 @@
return (needsAllRecords, attributes, expr)
- #print("_getDSFilter")
+ #print("_dsFilterFromAddressBookFilter")
# Lets assume we have a valid filter from the outset
# Top-level filter contains zero or more prop-filters
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120313/cb570c59/attachment.html>
More information about the calendarserver-changes
mailing list