Skip to content
This repository
Browse code

Merge pull request #22 from akheron/master

Wrap continuous changes feed results to TrombiDict, enhance docs
  • Loading branch information...
commit 73ff83194d791b64ae6d3bad9380975740cf6b0b 2 parents 7c51c93 + 9e73167
Jyrki Pulliainen authored May 05, 2011
62  doc/python-api.rst
Source Rendered
@@ -86,14 +86,23 @@ Result objects
86 86
 .. class:: TrombiResult
87 87
 
88 88
    A generic result indicating a succesfull call. Used for example in
89  
-   :meth:`Database.list`. Subclasses
90  
-   :class:`TrombiObject`.
  89
+   :meth:`Database.list`. Subclasses :class:`TrombiObject`.
91 90
 
92 91
    .. attribute:: content
93 92
 
94 93
       Contains the result of the query. The result format is not
95 94
       specified.
96 95
 
  96
+.. class:: TrombiDict
  97
+
  98
+   A dict-like object for successful responses. Subclasses
  99
+   :class:`TrombiObject`.
  100
+
  101
+   .. method:: to_basetype()
  102
+
  103
+      Returns the copy of the contents of the :class:`TrombiDict`
  104
+      instance as a normal dict.
  105
+
97 106
 .. class:: ViewResult
98 107
 
99 108
    A special result object that represents a succesful view result.
@@ -246,8 +255,9 @@ argument.
246 255
 
247 256
    .. method:: info(callback)
248 257
 
249  
-      Request database information. Calls callback with a dict that
250  
-      contains the info (see `here`__ for the dict contents).
  258
+      Request database information. Calls callback with a
  259
+      :class:`TrombiDict` that contains the info (see `here`__ for the
  260
+      dict fields).
251 261
 
252 262
       __ http://techzone.couchbase.com/sites/default/files/uploads/all/documentation/couchbase-api-db.html#couchbase-api-db_db_get
253 263
 
@@ -358,25 +368,31 @@ argument.
358 368
 
359 369
    .. method:: changes(callback[, feed_type='normal', timeout=60, **kw])
360 370
 
361  
-      Fetches the ``_changes`` feed for the database. Has two optional
362  
-      keyword arguments, *timeout* and *feed_type*. *timeout* is
363  
-      in seconds and defaults to 60 seconds, which is CouchDB's
364  
-      default timeout for changes feed. *feed_type* is described in
365  
-      `CouchDB database API`_. Additional keyword arguments are
366  
-      converted to query parameters for the changes feed. For possible
367  
-      keyword arguments, see `CouchDB database API`_ entry of changes
368  
-      feed.
369  
-
370  
-      If *feed_type* is ``continous``, the callback is passed as
371  
-      both streaming and regular callback to the fetch function. The
372  
-      callback is called every time the changes feed sends a line of
373  
-      text that is JSON encoded. The argument to the callback is this
374  
-      line decoded. When the changes feed closes for some reason, the
375  
-      callback is called with *None* as an argument if the feed
376  
-      closed properly (ie. server closed the request with ``200 OK``).
377  
-      Otherwise the callback is called with the error object.
378  
-
379  
-      .. _CouchDB database API: http://wiki.apache.org/couchdb/HTTP_database_API#Changes
  371
+      Fetches the ``_changes`` feed for the database.
  372
+
  373
+      *feed_type* is ``"normal"``, ``"longpoll"`` or ``"continuous"``.
  374
+      The different feed types are described here__.
  375
+
  376
+      __ `changes feed API`_
  377
+
  378
+      With the continuous and longpoll feed types, the *timeout*
  379
+      parameter tells the server to close connection after this many
  380
+      seconds of idle time, even if there are no results. The default
  381
+      value of 60 seconds is also the default for CouchDB.
  382
+
  383
+      Additional keyword arguments are converted to query parameters
  384
+      for the changes feed. For possible keyword arguments, see here__.
  385
+
  386
+      __ `changes feed API`_
  387
+
  388
+      If *feed_type* is ``continous``, the callback is called for each
  389
+      line CouchDB sends. The line is JSON decoded and wrapped in a
  390
+      :class:`TrombiDict`, to denote a successful callback invocation.
  391
+      When the server timeout occurs, the callback is called with
  392
+      *None* as an argument. On error (e.g. HTTP client timeout), the
  393
+      callback is called with a :class:`TrombiErrorResponse` object.
  394
+
  395
+      .. _changes feed API: http://wiki.apache.org/couchdb/HTTP_database_API#Changes
380 396
 
381 397
    .. method:: temporary_view(callback, map_fun[, reduce_fun=None, language='javascript', **kwargs])
382 398
 
6  trombi/client.py
@@ -99,9 +99,7 @@ def __init__(self, data):
99 99
         super(TrombiResult, self).__init__()
100 100
 
101 101
 
102  
-class TrombiDict(dict):
103  
-    error = False
104  
-
  102
+class TrombiDict(TrombiObject, dict):
105 103
     def to_basetype(self):
106 104
         return dict(self)
107 105
 
@@ -544,7 +542,7 @@ def _stream(text):
544 542
                 #
545 543
                 # This also relieves us from handling exceptions in
546 544
                 # the handler.
547  
-                cb = functools.partial(callback, obj)
  545
+                cb = functools.partial(callback, TrombiDict(obj))
548 546
                 self.server.io_loop.add_callback(cb)
549 547
 
550 548
         couchdb_params = kw

0 notes on commit 73ff831

Please sign in to comment.
Something went wrong with that request. Please try again.