summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2013-02-09 19:25:44 -0200
committerdrebs <drebs@leap.se>2013-02-09 20:21:48 -0200
commitf99762eef055742d841bae965ef3b1eec2ca4631 (patch)
treeb5af3f8a5ddb325110de07e9f4355c00f5b28144
parentbc6d05f8333ee775aa373817e2ece6323c62186f (diff)
Enforce doc.rev as bytes to match Twisted expectations.
-rw-r--r--backends/couch.py4
-rw-r--r--backends/leap_backend.py20
2 files changed, 21 insertions, 3 deletions
diff --git a/backends/couch.py b/backends/couch.py
index 8757f5af..d349efaf 100644
--- a/backends/couch.py
+++ b/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/backends/leap_backend.py b/backends/leap_backend.py
index 41027e50..d3ae6db6 100644
--- a/backends/leap_backend.py
+++ b/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."""