logging, assertions, comments twisty
authorMark Hammond <mhammond@skippinet.com.au>
Mon, 06 Apr 2009 11:09:54 +1000
changeset 157 45600ab47a25fd868d8943503ff3bc93279d6d37
parent 156 594f244499d407ca8b45d59eb7067165306d895f
child 158 37a8ed4fa05c0175fa774cf2bf60de098645a338
push id1
push userroot
push dateWed, 08 Apr 2009 01:46:05 +0000
logging, assertions, comments
--- a/server/python/junius/model.py
+++ b/server/python/junius/model.py
@@ -203,17 +203,22 @@ def get_db(couchname="local", dbname=_No
     except KeyError:
     logger.info("Connecting to couchdb at %s", dbinfo)
     db = CouchDB(dbinfo['host'], dbinfo['port'], dbname)
     DBs[key] = db
     return db
 def quote_id(doc_id):
-    return quote(doc_id, safe="")
+    # A '/' should be impossible now we base64 encode the string given
+    # by an extension - but it doesn't hurt.
+    # Note the '!' character seems to work fine with couch (ie, we use it
+    # unquoted when constructing views), so we allow that for no better
+    # reason than the logs etc are clearer...
+    return quote(doc_id, safe="!")
 class DocumentModel(object):
     """The layer between 'documents' and the 'database'.  Responsible for
        creating the unique ID for each document (other than the raw document),
        for fetching documents based on an ID, etc
     def __init__(self, db):
         self.db = db
@@ -227,16 +232,17 @@ class DocumentModel(object):
         """Open an attachment for the given docID.  As this is generally done
         when processing the document itself, so the raw ID of the document
         itself is known.  For this reason, a docid rather than the parts is
         Unlike open_document, this never returns None, but raises an
         exception if the attachment doesn't exist.
+        logger.debug("attempting to open attachment %s/%s", doc_id, attachment)
         return self.db.openDoc(quote_id(doc_id), attachment=attachment, **kw)
     def open_document(self, category, proto_id, ext_type, **kw):
         """Open the specific document, returning None if it doesn't exist"""
         docid = '%s!%s!%s' % (category, encode_proto_id(proto_id), ext_type)
         return self.open_document_by_id(docid, **kw)
     def open_document_by_id(self, doc_id, **kw):
@@ -253,16 +259,18 @@ class DocumentModel(object):
             result = None # indicate no doc exists.
             logger.debug("no document of that ID exists")
             logger.debug("opened document %(_id)r at revision %(_rev)s",
         return result
     def _prepare_raw_doc(self, account, docid, doc, doc_type):
+        assert docid
+        assert doc_type
         assert '_id' not in doc, doc # that isn't how you specify the ID.
         doc['_id'] = docid
         assert 'raindrop_account' not in doc, doc # we look after that!
         doc['raindrop_account'] = account.details['_id']
         assert 'type' not in doc, doc # we look after that!
         doc['type'] = doc_type