diff options
author | drebs <drebs@leap.se> | 2013-02-09 19:25:44 -0200 |
---|---|---|
committer | drebs <drebs@leap.se> | 2013-02-09 20:21:48 -0200 |
commit | a0f36427f9473c7f2d759b9d0605b72d2c401731 (patch) | |
tree | a61c20e82711279112c36dbf6fc34b551b4bce22 /src/leap/soledad/backends | |
parent | 4c520d9ae0f677cc1b5cef20c197c1751335faea (diff) |
Enforce doc.rev as bytes to match Twisted expectations.
Diffstat (limited to 'src/leap/soledad/backends')
-rw-r--r-- | src/leap/soledad/backends/couch.py | 4 | ||||
-rw-r--r-- | src/leap/soledad/backends/leap_backend.py | 20 |
2 files changed, 21 insertions, 3 deletions
diff --git a/src/leap/soledad/backends/couch.py b/src/leap/soledad/backends/couch.py index 8757f5af..d349efaf 100644 --- a/src/leap/soledad/backends/couch.py +++ b/src/leap/soledad/backends/couch.py @@ -56,13 +56,13 @@ class CouchDatabase(ObjectStore): self._dbname = database # this will ensure that transaction and sync logs exist and are # up-to-date. - self.set_document_factory(LeapDocument) try: self._database = self._server[database] except ResourceNotFound: self._server.create(database) self._database = self._server[database] - super(CouchDatabase, self).__init__(replica_uid=replica_uid) + super(CouchDatabase, self).__init__(replica_uid=replica_uid, + document_factory=LeapDocument) #------------------------------------------------------------------------- # methods from Database diff --git a/src/leap/soledad/backends/leap_backend.py b/src/leap/soledad/backends/leap_backend.py index 41027e50..d3ae6db6 100644 --- a/src/leap/soledad/backends/leap_backend.py +++ b/src/leap/soledad/backends/leap_backend.py @@ -22,6 +22,8 @@ class NoSoledadInstance(Exception): class LeapDocument(Document): """ + Encryptable and syncable document. + LEAP Documents are standard u1db documents with cabability of returning an encrypted version of the document json string as well as setting document content based on an encrypted version of json string. @@ -37,7 +39,7 @@ class LeapDocument(Document): def get_encrypted_json(self): """ - Returns document's json serialization encrypted with user's public key. + Return document's json serialization encrypted with user's public key. """ if not self._soledad: raise NoSoledadInstance() @@ -67,6 +69,22 @@ class LeapDocument(Document): doc="Determine if document should be synced with server." ) + # Returning the revision as string solves the following exception in + # Twisted web: + # exceptions.TypeError: Can only pass-through bytes on Python 2 + def _get_rev(self): + if self._rev is None: + return None + return str(self._rev) + + def _set_rev(self, rev): + self._rev = rev + + rev = property( + _get_rev, + _set_rev, + doc="Wrapper to ensure `doc.rev` is always returned as bytes.") + class LeapDatabase(HTTPDatabase): """Implement the HTTP remote database API to a Leap server.""" |