[CalendarServer-changes] [13059] CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/ directorybackedaddressbook.py
source_changes at macosforge.org
source_changes at macosforge.org
Mon Mar 31 13:16:25 PDT 2014
Revision: 13059
http://trac.calendarserver.org//changeset/13059
Author: gaya at apple.com
Date: 2014-03-31 13:16:25 -0700 (Mon, 31 Mar 2014)
Log Message:
-----------
clean up
Modified Paths:
--------------
CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directorybackedaddressbook.py
Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directorybackedaddressbook.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directorybackedaddressbook.py 2014-03-31 19:35:17 UTC (rev 13058)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directorybackedaddressbook.py 2014-03-31 20:16:25 UTC (rev 13059)
@@ -37,8 +37,8 @@
from txdav.carddav.datastore.query.filter import IsNotDefined, TextMatch, \
ParameterFilter
from txdav.who.idirectory import FieldName as CalFieldName
-from txdav.who.vcard import recordTypeToVCardKindMap, vCardKindToRecordTypeMap, \
- vCardPropToParamMap, vCardConstantProperties, vCardFromRecord
+from txdav.who.vcard import vCardKindToRecordTypeMap, vCardPropToParamMap, \
+ vCardConstantProperties, vCardFromRecord
from txdav.xml import element as davxml
from txdav.xml.base import twisted_dav_namespace, dav_namespace, parse_date, \
twisted_private_namespace
@@ -54,6 +54,7 @@
log = Logger()
+MatchFlags_none = MatchFlags.NOT & ~MatchFlags.NOT # can't import MatchFlags_none
class DirectoryBackedAddressBookResource (CalDAVResource):
"""
@@ -180,39 +181,6 @@
# LATER "X-ADDRESSBOOKSERVER-MEMBER": FieldName.membersUIDs,
}
- allowedRecordTypes = set(self.directory.recordTypes()) & set(recordTypeToVCardKindMap.keys())
- log.debug("doAddressBookDirectoryQuery: allowedRecordTypes={allowedRecordTypes}", allowedRecordTypes=allowedRecordTypes,)
-
- '''
- expressions = []
- for recordType in allowedRecordTypes:
-
- #log.debug("doAddressBookDirectoryQuery: recordType={recordType}", recordType=recordType,)
-
- kind = recordTypeToVCardKindMap[recordType]
- constantProperties = vCardConstantProperties.copy()
- constantProperties["KIND"] = kind
- # add KIND as constant so that query can be skipped if addressBookFilter needs a different kind
-
- propNames, expression = expressionFromABFilter(addressBookFilter, vcardPropToRecordFieldMap, constantProperties=constantProperties)
- #log.debug("doAddressBookDirectoryQuery: recordType={recordType}, expression={expression!r}, propNames={propNames}", recordType=recordType, expression=expression, propNames=propNames)
- if expression:
- recordTypeExpression = MatchExpression(FieldName.recordType, recordType, MatchType.equals)
- if expression is True:
- expression = recordTypeExpression
- else:
- expression = CompoundExpression((expression, recordTypeExpression,), Operand.AND)
-
- if expression:
- expressions.append(expression)
-
- if expressions:
- if expressions > 1:
- expression = CompoundExpression(expressions, Operand.OR)
- else:
- expression = expressions[0]
- '''
-
propNames, expression = expressionFromABFilter(
addressBookFilter, vcardPropToRecordFieldMap, vCardConstantProperties
)
@@ -220,8 +188,8 @@
if expression:
if defaultKind and "KIND" not in propNames:
defaultRecordExpression = MatchExpression(
- FieldName.recordType,
- vCardKindToRecordTypeMap[defaultKind],
+ FieldName.recordType,
+ vCardKindToRecordTypeMap[defaultKind],
MatchType.equals
)
if expression is True:
@@ -239,13 +207,12 @@
], Operand.OR
)
- log.debug("doAddressBookDirectoryQuery: expression={expression!r}, propNames={propNames}", expression=expression, propNames=propNames)
maxRecords = int(maxResults * 1.2)
# keep trying query till we get results based on filter. Especially when doing "all results" query
while True:
- log.debug("doAddressBookDirectoryQuery: expression={expression!r}, ", expression=expression)
+ log.debug("doAddressBookDirectoryQuery: expression={expression!r}, propNames={propNames}", expression=expression, propNames=propNames)
records = yield self.directory.recordsFromExpression(expression)
log.debug("doAddressBookDirectoryQuery: #records={n}, records={records!r}", n=len(records), records=records)
@@ -385,6 +352,10 @@
# change types and flags
matchFlags &= ~MatchFlags.caseInsensitive
matchType = MatchType.equals
+ elif fieldName == FieldName.uid:
+ # special case uid until I figure out how to do a case-sens collation
+ matchFlags &= ~MatchFlags.caseInsensitive
+ uMatchString = matchString.decode("utf-8")
else:
uMatchString = matchString.decode("utf-8")
@@ -396,7 +367,7 @@
return defined # all records have this property so no records do not have it
else:
# this may generate inefficient LDAP query string
- matchFlags = MatchFlags.NOT & MatchFlags.caseInsensitive if defined else MatchFlags.NOT
+ matchFlags = MatchFlags_none if defined else MatchFlags.NOT
matchList = [matchExpression(fieldName, "", MatchType.startsWith, matchFlags) for fieldName in searchableFields]
return andOrExpression(allOf, matchList)
@@ -499,7 +470,7 @@
elif textMatchElement.negate:
matchFlags = MatchFlags.NOT
else:
- matchFlags = MatchFlags.NOT & MatchFlags.caseInsensitive # MatchFlags.none
+ matchFlags = MatchFlags_none
matchList = [matchExpression(fieldName, matchString.decode("utf-8"), matchType, matchFlags) for fieldName in searchableFields]
matchList.extend(matchList)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140331/b9d16b50/attachment-0001.html>
More information about the calendarserver-changes
mailing list