Skip to content
This repository has been archived by the owner on Feb 13, 2020. It is now read-only.

Commit

Permalink
Add more directory proxy commands
Browse files Browse the repository at this point in the history
  • Loading branch information
m0rgen committed Feb 4, 2014
1 parent 4bcd4af commit 6608e81
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
2 changes: 2 additions & 0 deletions txdav/dps/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def makeEvenBetterRequest():
print("guid: {r}".format(r=record))
records = (yield ds.recordsWithRecordType(RecordType.user))
print("recordType: {r}".format(r=records))
records = (yield ds.recordsWithEmailAddress("cdaboo@bitbucket.calendarserver.org"))
print("emailAddress: {r}".format(r=records))


def succeeded(result):
Expand Down
20 changes: 18 additions & 2 deletions txdav/dps/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def recordToDict(self, record):
@RecordWithShortNameCommand.responder
@inlineCallbacks
def recordWithShortName(self, recordType, shortName):
recordType = recordType.decode("utf-8")
recordType = recordType # keep as bytes
shortName = shortName.decode("utf-8")
log.debug("RecordWithShortName: {r} {n}", r=recordType, n=shortName)
record = (yield self._directory.recordWithShortName(
Expand Down Expand Up @@ -164,7 +164,7 @@ def recordWithGUID(self, guid):
@RecordsWithRecordTypeCommand.responder
@inlineCallbacks
def recordsWithRecordType(self, recordType):
recordType = recordType.decode("utf-8")
recordType = recordType # as bytes
log.debug("RecordsWithRecordType: {r}", r=recordType)
records = (yield self._directory.recordsWithRecordType(
RecordType.lookupByName(recordType))
Expand All @@ -177,3 +177,19 @@ def recordsWithRecordType(self, recordType):
}
log.debug("Responding with: {response}", response=response)
returnValue(response)


@RecordsWithEmailAddressCommand.responder
@inlineCallbacks
def recordsWithEmailAddress(self, emailAddress):
emailAddress = emailAddress.decode("utf-8")
log.debug("RecordsWithEmailAddress: {e}", e=emailAddress)
records = (yield self._directory.recordsWithEmailAddress(emailAddress))
fieldsList = []
for record in records:
fieldsList.append(self.recordToDict(record))
response = {
"fieldsList": pickle.dumps(fieldsList),
}
log.debug("Responding with: {response}", response=response)
returnValue(response)
17 changes: 16 additions & 1 deletion txdav/dps/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@

from .protocol import (
DirectoryProxyAMPProtocol, RecordWithShortNameCommand, RecordWithUIDCommand,
RecordWithGUIDCommand, RecordsWithRecordTypeCommand
RecordWithGUIDCommand, RecordsWithRecordTypeCommand,
RecordsWithEmailAddressCommand
)

from twisted.internet import reactor
Expand Down Expand Up @@ -160,6 +161,20 @@ def _call(ampProto):
return d


def recordsWithEmailAddress(self, emailAddress):

def _call(ampProto):
return ampProto.callRemote(
RecordsWithEmailAddressCommand,
emailAddress=emailAddress
)

d = self._getConnection()
d.addCallback(_call)
d.addCallback(self._processMultipleRecords)
return d


class DirectoryRecord(BaseDirectoryRecord):
pass

Expand Down

0 comments on commit 6608e81

Please sign in to comment.