當前位置: 首頁>>代碼示例>>Python>>正文


Python hug.get方法代碼示例

本文整理匯總了Python中hug.get方法的典型用法代碼示例。如果您正苦於以下問題:Python hug.get方法的具體用法?Python hug.get怎麽用?Python hug.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在hug的用法示例。


在下文中一共展示了hug.get方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_home

# 需要導入模塊: import hug [as 別名]
# 或者: from hug import get [as 別名]
def test_home(tracked_requests):
    with app_with_scout() as app:
        response = TestApp(app).get("/")

    assert response.status_int == 200
    assert response.text == '"Welcome home."'
    assert len(tracked_requests) == 1
    tracked_request = tracked_requests[0]
    assert tracked_request.tags["path"] == "/"
    assert tracked_request.active_spans == []
    assert len(tracked_request.complete_spans) == 2
    assert (
        tracked_request.complete_spans[0].operation
        == "Controller/tests.integration.test_hug.home"
    )
    assert tracked_request.complete_spans[1].operation == "Middleware" 
開發者ID:scoutapp,項目名稱:scout_apm_python,代碼行數:18,代碼來源:test_hug.py

示例2: a_redis_call

# 需要導入模塊: import hug [as 別名]
# 或者: from hug import get [as 別名]
def a_redis_call(rname, ape=1):
    """Simple redis call."""
    if ape == 1:
        return "no valid api key specified, nice try though".format(**locals())
    if r.sismember('ape', ape) != 1:
        return "no valid api key specified, nice try though".format(**locals())
    else:
        coolness = r.get(rname).decode('utf8')
        r.decr(ape)
        numleft = r.get(str(ape))
        print(numleft)
        return "Authenticated w {ape}. You have {numleft} queries left. This\
             is the {rname} value you requested: {coolness}".format(**locals()) 
開發者ID:jamesacampbell,項目名稱:python-examples,代碼行數:15,代碼來源:hug_api_example.py

示例3: inference

# 需要導入模塊: import hug [as 別名]
# 或者: from hug import get [as 別名]
def inference(request, body, response):
    """Makes an inference to a certain model"""
    print(body)
    if request.headers.get('CONTENT-TYPE') == 'application/gzip':
        try:
            original_data = gzip.decompress(request.stream.read())
            input_docs = json.loads(str(original_data, 'utf-8'))["docs"]
            model_name = json.loads(str(original_data, 'utf-8'))["model_name"]
        except Exception:
            response.status = hug.HTTP_500
            return {'status': 'unexpected gzip error'}
    elif request.headers.get('CONTENT-TYPE') == 'application/json':
        if isinstance(body, str):
            body = json.loads(body)
        model_name = body.get('model_name')
        input_docs = body.get('docs')
    else:
        response.status = status_codes.HTTP_400
        return {'status': 'Content-Type header must be application/json or application/gzip'}
    if not model_name:
        response.status = status_codes.HTTP_400
        return {'status': 'model_name is required'}
    # If we've already initialized it, no use in reinitializing
    if not services.get(model_name):
        services[model_name] = Service(model_name)
    if not isinstance(input_docs, list):  # check if it's an array instead
        response.status = status_codes.HTTP_400
        return {'status': 'request not in proper format '}
    headers = parse_headers(request.headers)
    parsed_doc = services[model_name].get_service_inference(input_docs, headers)
    resp_format = request.headers["RESPONSE-FORMAT"]
    ret = format_response(resp_format, parsed_doc)
    if request.headers.get('CONTENT-TYPE') == 'application/gzip':
        response.content_type = resp_format
        response.body = ret
        # no return due to the fact that hug seems to assume json type upon return
    else:
        return ret 
開發者ID:NervanaSystems,項目名稱:nlp-architect,代碼行數:40,代碼來源:serve.py


注:本文中的hug.get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。