couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Couchdb Wiki] Update of "Getting_started_with_Python" by JohannPhilippStrathausen
Date Mon, 29 Nov 2010 11:43:19 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Couchdb Wiki" for change notification.

The "Getting_started_with_Python" page has been changed by JohannPhilippStrathausen.
http://wiki.apache.org/couchdb/Getting_started_with_Python?action=diff&rev1=18&rev2=19

--------------------------------------------------

  Demonstration of basic API-interaction using Python. (note: as of python 2.6, one can use
"import json" for the same functionality in this script.)
  
  {{{#!python
- #! /usr/bin/python2.4
+ #! /usr/bin/python2.6
  
+ import httplib, json
- import httplib, simplejson  # http://cheeseshop.python.org/pypi/simplejson
-                             # Here only used for prettyprinting
  
  def prettyPrint(s):
      """Prettyprints the json response of an HTTPResponse object"""
  
      # HTTPResponse instance -> Python object -> str
-     print simplejson.dumps(simplejson.loads(s.read()), sort_keys=True, indent=4)
+     print simplejson.dumps(json.loads(s.read()), sort_keys=True, indent=4)
  
  class Couch:
      """Basic wrapper class for operations on a couchDB"""
@@ -118, +117 @@

          # XXX Crashed if resource is non-existent; not so for DELETE on db. Bug?
          # XXX Does not work any more, on has to specify an revid
          #     Either do html head to get the recten revid or provide it as parameter
-         r = self.delete(''.join(['/', dbName, '/', docId]))
+         r = self.delete(''.join(['/', dbName, '/', docId, '?revid=', rev_id]))
          prettyPrint(r)
  
      # Basic http methods

Mime
View raw message