json.py 文件源码

python
阅读 34 收藏 0 点赞 0 评论 0

项目:pscheduler 作者: perfsonar 项目源码 文件源码
def json_query(query, query_args=[], name = 'name', single = False):
    """Do a SQL query that selects one column containing JSON and dump
    the results, honoring the 'expanded' and 'pretty' arguments.  If
    the 'single' argument is True, the first-returned row will be
    returned as a single item instead of an array."""

    if request.method != 'GET':
        return not_allowed()

    try:
        cursor = dbcursor_query(query, query_args)
    except Exception as ex:
        return error(str(ex))

    if single and cursor.rowcount == 0:
        cursor.close()
        return not_found()
    result = []
    for row in cursor:
        this = base_url(None if single else row[0][name])
        row[0]['href'] = this
        result.append( row[0] if single or is_expanded() else this)
    cursor.close()
    return json_response(result[0] if single else result)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号