Beispiel #1
0
def getView(database_url,
            view_name,
            method="POST",
            documentHandler=None,
            **kwargs):
    dh = StreamingCouchDBDocHandler(documentHandler)
    resp = getResponse(database_url, view_name, method, **kwargs)
    return dh.generator(resp)
Beispiel #2
0
def getView(database_url,
            view_name,
            method="GET",
            documentHandler=None,
            **kwargs):
    json_headers = {"Content-Type": "application/json; charset=\"utf-8\""}
    get_head_args = [
        "key", "startkey", "startkey_docid", "endkey", "endkey_docid", "limit",
        "stale", "descending", "skip", "group", "group_level", "reduce",
        "include_docs", "inclusive_end", "update_seq"
    ]
    post_args = ["keys"]
    # Certain keys must be proper JSON values
    for foo in kwargs:
        if foo in ['startkey', 'endkey', 'key']:
            kwargs[foo] = json.dumps(kwargs[foo])

    query_args = {}
    post_data = {}
    for key in kwargs:
        val = kwargs[key]
        if key in get_head_args:
            if isinstance(val, types.BooleanType):
                query_args[key] = repr(val).lower()
            else:
                query_args[key] = val
        if key in post_args:
            post_data[key] = val

    if method is "POST" or post_data != {}:
        view_url = '?'.join([
            '/'.join([database_url, view_name]),
            urllib.urlencode(query_args)
        ])
        post_data = json.dumps(post_data)
        log.debug("POST " + view_url)
        log.debug("DATA " + post_data)
        view_req = urllib2.Request(view_url,
                                   data=post_data,
                                   headers=json_headers)
    else:
        view_url = '?'.join([
            '/'.join([database_url, view_name]),
            urllib.urlencode(query_args)
        ])
        log.error(view_url)
        view_req = urllib2.Request(view_url, headers=json_headers)
        log.debug("GET " + view_url)
    resp = urllib2.urlopen(view_req)

    dh = StreamingCouchDBDocHandler(documentHandler)
    return dh.generator(resp)
def getView(database_url, view_name, method="GET", documentHandler=None, **kwargs):    
    json_headers = { "Content-Type": "application/json; charset=\"utf-8\"" }
    get_head_args = ["key", "startkey", "startkey_docid", "endkey", 
                     "endkey_docid", "limit", "stale", "descending", "skip", 
                     "group", "group_level", "reduce", "include_docs", 
                     "inclusive_end", "update_seq"]
    post_args = ["keys"]
    # Certain keys must be proper JSON values
    for foo in kwargs:
        if foo in ['startkey','endkey','key']:
            kwargs[foo] = json.dumps(kwargs[foo])
    
    query_args = {}
    post_data = {}
    for key in kwargs:
        val = kwargs[key]
        if key in get_head_args:
            if isinstance(val, types.BooleanType):
                query_args[key] = repr(val).lower()
            else:
                query_args[key] = val
        if key in post_args:
            post_data[key] = val
            
    if method is "POST" or post_data != {}:
        view_url = '?'.join(['/'.join([database_url,view_name]),urllib.urlencode(query_args)]) 
        post_data = json.dumps(post_data)
        log.debug("POST "+view_url)
        log.debug("DATA " + post_data)
        view_req = urllib2.Request(view_url, data=post_data, headers=json_headers)
    else:        
        view_url = '?'.join(['/'.join([database_url,view_name]),urllib.urlencode(query_args)])
        log.error(view_url) 
        view_req = urllib2.Request(view_url, headers=json_headers)
        log.debug("GET "+view_url)  
    resp = urllib2.urlopen(view_req)
    
    dh = StreamingCouchDBDocHandler(documentHandler)
    return dh.generator(resp)
Beispiel #4
0
def getView(database_url, view_name, method="GET", documentHandler=None, **kwargs):    
    dh = StreamingCouchDBDocHandler(documentHandler)
    resp = getResponse(database_url,view_name,method,**kwargs)
    return dh.generator(resp)