def _all_docs( conn, keys=None, paths=[], hthdrs={}, q={} ) : """ GET /<db>/_all_docs, if keys is None POST /<db>/_all_docs, if keys is a list of document keys to select query object `q` for GET descending=<bool> endkey=<key> endkey_docid=<id> group=<bool> group_level=<num> include_docs=<bool> key=<key> limit=<num> inclusive_end=<bool> reduce=<bool> skip=<num> stale='ok' startkey=<key> startkey_docid=<id> update_seq=<bool> Note that `q` object should provide .items() method with will return a list of key,value query parameters. """ hthdrs = conn.mixinhdrs( hthdrs, hdr_acceptjs, hdr_ctypejs ) if keys == None : method = 'GET' s, h, d = conn.get( paths, hthdrs, None, _query=q.items() ) else : method ='POST' body = rest.data2json({ 'keys' : keys }) s, h, d = conn.post( paths, hthdrs, body, _query=q.items() ) if s == OK : return s, h, d else : log.error( '%s request to /%s failed' % (method, '/'.join(paths)) ) return (None, None, None)
def _replicate( conn, body, paths=[], hthdrs={} ) : """POST /_replicate""" hthdrs = conn.mixinhdrs( hthdrs, hdr_acceptjs, hdr_ctypejs ) body = rest.data2json( body ) s, h, d = conn.post( paths, hthdrs, body ) if (s != ACCEPTED) or (not d['ok']) : s = h = d = None log.error( 'POST /_replicate request failed' ) return s, h, d
def _revs_diff( conn, revs=[], paths=[], hthdrs={} ) : """TODO : To be implemented""" hthdrs = conn.mixinhdrs( hthdrs, hdr_acceptjs ) body = rest.data2json( revs ) s, h, d = conn.post( paths, hthdrs, body ) if s == OK : return s, h, d else : log.error( 'POST request to /%s failed' % '/'.join(paths) ) return (None, None, None)
def _purge( conn, body, paths=[], hthdrs={} ) : """POST /<db>/_purge""" hthdrs = conn.mixinhdrs( hthdrs, hdr_acceptjs, hdr_ctypejs ) body = rest.data2json( body ) s, h, d = conn.post( paths, hthdrs, body ) if s == OK : return s, h, d else : log.error( 'POST request to /%s failed' % '/'.join(paths) ) return (None, None, None)
def _temp_view( conn, designdoc, paths=[], hthdrs={}, **query ) : """POST /<db>/_temp_view query, Same query parameters as that of design-doc views """ hthdrs = conn.mixinhdrs( hthdrs, hdr_acceptjs, hdr_ctypejs ) body = rest.data2json( designdoc ) s, h, d = conn.post( paths, hthdrs, body, _query=query.items() ) if s == OK : return s, h, d else : log.error( 'POST request to /%s failed' % '/'.join(paths) ) return (None, None, None)
def _bulk_docs( conn, docs, atomic=False, paths=[], hthdrs={} ) : """POST /<db>/_bulk_docs""" docs = { 'all_or_nothing' : atomic, 'docs' : docs, } body = rest.data2json( docs ) hthdrs = conn.mixinhdrs( hthdrs, hdr_acceptjs, hdr_ctypejs ) s, h, d = conn.post( paths, hthdrs, body ) if s == CREATED : return s, h, d else : log.error( 'POST request to /%s failed' % '/'.join(paths) ) return (None, None, None)
def _security( conn, paths=[], security=None, hthdrs={} ) : """ GET /<db>/_security PUT /<db>/_security """ hthdrs = conn.mixinhdrs( hthdrs, hdr_acceptjs, hdr_ctypejs ) if security == None : method = 'GET' s, h, d = conn.get( paths, hthdrs, None ) else : method = 'PUT' body = rest.data2json( security ) s, h, d = conn.put( paths, hthdrs, body ) if s == OK : return s, h, d else : log.error( '%s request to /%s failed' % (method, '/'.join(paths)) ) return (None, None, None)
def _config( conn, paths=[], hthdrs={}, **kwargs ) : """ GET /_config GET /_config/<section> GET /_config/<section>/<key> PUT /_config/<section>/<key> DELETE /_config/<section>/<key> """ hthdrs = conn.mixinhdrs( hthdrs, hdr_acceptjs, hdr_ctypejs ) if 'value' in kwargs : # PUT body = rest.data2json( kwargs['value'] ) method = 'PUT' s, h, d = conn.put( paths, hthdrs, body ) elif 'delete' in kwargs : method = 'DELETE' s, h, d = conn.delete( paths, hthdrs, None ) else : method = 'GET' s, h, d = conn.get( paths, hthdrs, None ) if s != OK : s = h = d = None log.error( '%s request to (%s) failed' % (method, paths) ) return s, h, d