Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Trying to serialize records across amp

  • Loading branch information
m0rgen committed Jan 31, 2014
1 parent a083b65 commit d5c1d581a861a2c0540be912b4cfa9d5d62fcb8d
Showing with 14 additions and 18 deletions.
  1. +4 −7 txdav/dps/client.py
  2. +4 −6 txdav/dps/protocol.py
  3. +6 −5 txdav/dps/service.py
@@ -14,28 +14,25 @@
# limitations under the License.
##

from txdav.dps.service import DirectoryService
from twext.who.idirectory import RecordType
from twext.python.log import Logger
from twisted.internet import reactor
import cPickle as pickle
import sys

log = Logger()

print sys.path
from txdav.dps.service import DirectoryService


def makeBetterRequest():

shortName = sys.argv[1]

ds = DirectoryService()
ds = DirectoryService(None)
d = ds.recordWithShortName(RecordType.user, shortName)

def gotResults(result):
result = pickle.loads(result)
print('Done: %s' % (result,))
def gotResults(record):
print('Done: %s' % (record,))
reactor.stop()
d.addCallback(gotResults)
reactor.run()
@@ -18,6 +18,7 @@
from twisted.protocols import amp
from twisted.internet.defer import inlineCallbacks, returnValue
from twext.python.log import Logger
import cPickle as pickle

log = Logger()

@@ -29,9 +30,7 @@ class RecordWithShortNameCommand(amp.Command):
('shortName', amp.String()),
]
response = [
('fullNames', amp.ListOf(amp.String())),
('shortNames', amp.ListOf(amp.String())),
('emailAddresses', amp.ListOf(amp.String())),
('record', amp.String()),
]


@@ -54,10 +53,9 @@ def recordWithShortName(self, recordType, shortName):
record = (yield self._directory.recordWithShortName(
RecordType.lookupByName(recordType), shortName)
)
record.service = None
response = {
"fullNames": [i.encode("utf-8") for i in record.fullNames],
"shortNames": [i.encode("utf-8") for i in record.shortNames],
"emailAddresses": [i.encode("utf-8") for i in record.emailAddresses],
"record": pickle.dumps(record),
}
log.debug("Responding with: {response}", response=response)
returnValue(response)
@@ -40,13 +40,14 @@
class DirectoryService(BaseDirectoryService):

def _getConnection(self):
path = config.DirectoryProxy.SocketPath
return ClientCreator(reactor, amp.AMP).connectUnix(path)
# path = config.DirectoryProxy.SocketPath
path = "data/Logs/state/directory-proxy.sock"
return ClientCreator(reactor, amp.AMP).connectUNIX(path)

def recordWithShortName(self, recordType, shortName):

def serialize(result):
return pickle.dumps(result)
def deserialize(result):
return pickle.loads(result['record'])

def call(ampProto):
return ampProto.callRemote(
@@ -55,7 +56,7 @@ def call(ampProto):
shortName=shortName.encode("utf-8")
)

return self._getConnection().addCallback(call).addCallback(serialize)
return self._getConnection().addCallback(call).addCallback(deserialize)



0 comments on commit d5c1d58

Please sign in to comment.
You can’t perform that action at this time.