From 3f12ce80f26646fa3f38b6c8b0ad2abcc67545f3 Mon Sep 17 00:00:00 2001 From: mahendra Date: Wed, 23 Feb 2011 18:15:45 +0530 Subject: [PATCH 1/3] Invoke parseResult for self.post() in openView() Also rename docId to designId in openView() arguments --- paisley/client.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/paisley/client.py b/paisley/client.py index d56bcb0..997821d 100644 --- a/paisley/client.py +++ b/paisley/client.py @@ -65,7 +65,7 @@ def __init__(self, host, port=5984, dbName=None, username=None, password=None): self.host = host self.port = int(port) self.username = username - self.password =password + self.password = password self.url_template = "http://%s:%s%%s" % (self.host, self.port) if dbName is not None: self.bindToDB(dbName) @@ -235,11 +235,11 @@ def deleteDoc(self, dbName, docId, revision): # View operations - def openView(self, dbName, docId, viewId, **kwargs): + def openView(self, dbName, designId, viewId, **kwargs): """ - Open a view of a document in a given database. + Open a view of a design document in a given database. """ - uri = "/%s/_design/%s/_view/%s" % (dbName, quote(docId), viewId) + uri = "/%s/_design/%s/_view/%s" % (dbName, quote(designId), viewId) for arg in kwargs.keys(): kwargs[arg] = json.dumps(kwargs[arg]) @@ -252,7 +252,7 @@ def openView(self, dbName, docId, viewId, **kwargs): keys = {'keys': options.pop('keys')} if options: uri += "?%s" % (urlencode(options),) - return self.post(uri, body=keys) + return self.post(uri, body=keys).addCallback(self.parseResult) elif kwargs: # if not keys we just encode everything in the url uri += "?%s" % (urlencode(kwargs),) From 7558b1a86f3e778c5c78f7e07ef1820a1e508d80 Mon Sep 17 00:00:00 2001 From: mahendra Date: Wed, 23 Feb 2011 18:17:52 +0530 Subject: [PATCH 2/3] Add support for accessing views through couchdb list functions --- paisley/client.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/paisley/client.py b/paisley/client.py index 997821d..e73b0e5 100644 --- a/paisley/client.py +++ b/paisley/client.py @@ -84,7 +84,7 @@ def bindToDB(self, dbName): """ for methname in ["createDB", "deleteDB", "infoDB", "listDoc", "openDoc", "saveDoc", "deleteDoc", "openView", - "tempView"]: + "tempView", "openList"]: method = getattr(self, methname) newMethod = partial(method, dbName) setattr(self, methname, newMethod) @@ -281,6 +281,33 @@ def tempView(self, dbName, view): d = self.post("/%s/_temp_view" % (dbName,), view) return d.addCallback(self.parseResult) + # List operations + + def openList(self, dbName, designId, listId, viewId, **kwargs): + """ + Open a list for a design document in a given database. + """ + + uri = "/%s/_design/%s/_list/%s/%s" % \ + (dbName, quote(designId), quote(listId), viewId) + + for arg in kwargs.keys(): + kwargs[arg] = json.dumps(kwargs[arg]) + + if not kwargs: + return self.get(uri) + elif 'keys' in kwargs: + # couchdb is crazy and requires that keys be passed in a post body + options = kwargs.copy() + keys = {'keys': options.pop('keys')} + if options: + uri += "?%s" % (urlencode(options),) + return self.post(uri, body=keys) + elif kwargs: + # if not keys we just encode everything in the url + uri += "?%s" % (urlencode(kwargs),) + return self.get(uri) + # Basic http methods From 76eea4541f03b9cb7f4bfca71dba32462abf1422 Mon Sep 17 00:00:00 2001 From: mahendra Date: Wed, 23 Feb 2011 18:18:51 +0530 Subject: [PATCH 3/3] Add documentation for the auth parameters --- paisley/client.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/paisley/client.py b/paisley/client.py index e73b0e5..5917154 100644 --- a/paisley/client.py +++ b/paisley/client.py @@ -48,7 +48,8 @@ class CouchDB(object): CouchDB client: hold methods for accessing a couchDB. """ - def __init__(self, host, port=5984, dbName=None, username=None, password=None): + def __init__(self, host, port=5984, dbName=None, + username=None, password=None): """ Initialize the client for given host. @@ -61,6 +62,12 @@ def __init__(self, host, port=5984, dbName=None, username=None, password=None): @param dbName: if specified, all calls needing a database name will use this one by default. @type dbName: C{str} + + @param username: username to use while connecting to couchdb + @type username: C{str} + + @param password: password to use while connection to couchdb + @type password: C{str} """ self.host = host self.port = int(port)