当前位置: 首页>>代码示例>>Python>>正文


Python bottle.request方法代码示例

本文整理汇总了Python中bottle.request方法的典型用法代码示例。如果您正苦于以下问题:Python bottle.request方法的具体用法?Python bottle.request怎么用?Python bottle.request使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bottle的用法示例。


在下文中一共展示了bottle.request方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: topUp

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import request [as 别名]
def topUp(user):
    if request.GET.get('cancel','').strip():
        return "Refund cancelled by {}".format(user)

    refundAmount = float(request.GET.get('amount','').strip())

    userCredit = proxy.api.getUserAccountBalance(auth, user)

    if userCredit != refundAmount:
        return "Error: User Credit Balance and Refund Requested do not match for user: {}".format(user)

    proxy.api.adjustUserAccountBalance(auth, user, -1 * refundAmount, "Money refunded by the Simple Refund Page")

    return "<p>Updated balance is now {}</p><p>Please close this tab/window and return to PaperCut</p><p>We would email you at {}, but email it not currently configured</p>".format(
            "{0:.2f}".format(proxy.api.getUserAccountBalance(auth, user)),proxy.api.getUserProperty(auth, user, "email"))

    # now transfer the value to the external student system 
开发者ID:PaperCutSoftware,项目名称:PaperCutExamples,代码行数:19,代码来源:simpleRefundBalance.py

示例2: translate

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import request [as 别名]
def translate(self):
        """
        Processes a translation request.
        """
        translation_request = request_provider(self._style, request)
        logging.debug("REQUEST - " + repr(translation_request))

        translations = self._translator.translate(
            translation_request.segments,
            translation_request.settings
        )
        response_data = {
            'status': TranslationResponse.STATUS_OK,
            'segments': [translation.target_words for translation in translations],
        }
        translation_response = response_provider(self._style, **response_data)
        logging.debug("RESPONSE - " + repr(translation_response))

        response.content_type = translation_response.get_content_type()
        return repr(translation_response) 
开发者ID:EdinburghNLP,项目名称:nematus,代码行数:22,代码来源:server.py

示例3: validate_password

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import request [as 别名]
def validate_password(request, isTest=False):
    """ Validates the password given in the request
        against the stored Bcrypted one. """
    password = None
    try:
        password = request.forms.get('password').encode('utf-8')
    except AttributeError:
        return end(403, "No password in request")

    if 'PasswordBcrypt' in config:
        passcrypt = config['PasswordBcrypt'].encode('utf-8')
        if bcrypt.hashpw(password, passcrypt) != passcrypt:
            return end(403, "wrong password!")
    elif 'Password' in config and config['Password'] != password:
        return end(403, "wrong password!")
    elif isTest:
        return end(401, "There's no password in server configuration!") 
开发者ID:PhotoBackup,项目名称:server-bottle,代码行数:19,代码来源:photobackup.py

示例4: save_image

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import request [as 别名]
def save_image():
    """ Saves the given image to the parameterized directory. """
    answer = validate_password(request)
    if answer:
        return answer

    upfile = request.files.get('upfile')
    if not upfile:
        return end(401, "no file in the request!")

    filesize = -1
    try:
        filesize = int(request.forms.get('filesize'))
        return save_file(upfile, filesize)
    except TypeError:
        return end(400, "Missing file size in the request!") 
开发者ID:PhotoBackup,项目名称:server-bottle,代码行数:18,代码来源:photobackup.py

示例5: test

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import request [as 别名]
def test():
    """ Tests the server capabilities to handle POST requests. """
    answer = validate_password(request, True)
    if answer:
        return answer

    if not os.path.exists(config['MediaRoot']):
        return end(500, "'MediaRoot' directory does not exist!")

    testfile = os.path.join(config['MediaRoot'], '.test_file_to_write')
    try:
        with open(testfile, 'w') as tf:
            tf.write('')
        log.info("Test succeeded \o/")
        return {'uploaded_files': get_files() }
    except EnvironmentError:
        return end(500, "Can't write to 'MediaRoot' directory!")
    finally:
        os.remove(testfile)


# variables 
开发者ID:PhotoBackup,项目名称:server-bottle,代码行数:24,代码来源:photobackup.py

示例6: _route_flavors_id

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import request [as 别名]
def _route_flavors_id(flavor_id):
    """
    Route:  /compute/v2.0/flavors/<flavor_id>
    Method: GET, DELETE
    """
    utils.show_request(bottle.request)

    # nova flavor-delete <flavor_id>
    if bottle.request.method == 'DELETE':
        FLAVORS.delete(flavor_id)
        return

    # nova flavor-list
    if flavor_id == 'detail':
        return api_response.list_flavors(FLAVORS.list(), details=True)

    # nova flavor-show <flavor_id>
    return api_response.show_flavor(FLAVORS.show(flavor_id)) 
开发者ID:juergh,项目名称:dwarf,代码行数:20,代码来源:api.py

示例7: _route_flavors

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import request [as 别名]
def _route_flavors():
    """
    Route:  /compute/v2.0/flavors
    Method: GET, POST
    """
    utils.show_request(bottle.request)

    # nova flavor-create
    if bottle.request.method == 'POST':
        body = json.load(bottle.request.body)
        return api_response.create_flavor(FLAVORS.create(body['flavor']))

    # nova flavor-list (no details)
    return api_response.list_flavors(FLAVORS.list(), details=False)


# -----------------------------------------------------------------------------
# Bottle Keypair API routes 
开发者ID:juergh,项目名称:dwarf,代码行数:20,代码来源:api.py

示例8: _route_servers_id

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import request [as 别名]
def _route_servers_id(server_id):
    """
    Route:  /compute/v2.0/servers/<server_id>
    Method: GET, DELETE
    """
    utils.show_request(bottle.request)

    # nova delete <server_id>
    if bottle.request.method == 'DELETE':
        SERVERS.delete(server_id)
        return

    # nova list
    if server_id == 'detail':
        return api_response.list_servers(SERVERS.list(), details=True)

    # nova show <server_id>
    return api_response.show_server(SERVERS.show(server_id)) 
开发者ID:juergh,项目名称:dwarf,代码行数:20,代码来源:api.py

示例9: _route_images

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import request [as 别名]
def _route_images():
    """
    Route:  /image/v2/images
    Method: GET, POST
    """
    utils.show_request(bottle.request)

    # glance image-create
    if bottle.request.method == 'POST':
        bottle.response.status = 201
        image_md = json.load(bottle.request.body)
        return api_response.create_image(IMAGES.create(image_md))

    # glance image-list
    if (bottle.request.query.get('marker', None) is not None):
        # When the client wants more, tell it we're done
        return api_response.list_images([])
    else:
        # We don't 'do' marker, so return it all on the first call
        return api_response.list_images(IMAGES.list()) 
开发者ID:juergh,项目名称:dwarf,代码行数:22,代码来源:api.py

示例10: _route_images_id

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import request [as 别名]
def _route_images_id(image_id):
    """
    Route:  /image/v2/images/<image_id>
    Method: GET, DELETE, PATCH
    """
    utils.show_request(bottle.request)

    # glance image-delete
    if bottle.request.method == 'DELETE':
        bottle.response.status = 204
        IMAGES.delete(image_id)
        return

    # glance image-update
    if bottle.request.method == 'PATCH':
        image_ops = json.load(bottle.request.body)
        return api_response.update_image(IMAGES.update(image_id, image_ops))

    # glance image-show
    return api_response.show_image(IMAGES.show(image_id)) 
开发者ID:juergh,项目名称:dwarf,代码行数:22,代码来源:api.py

示例11: create_metadata_response

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import request [as 别名]
def create_metadata_response(self):
        def decorator(f):
            @functools.wraps(f)
            def wrapper():
                assert self._oauthlib, "BottleOAuth2 not initialized with OAuthLib"

                uri, http_method, body, headers = extract_params(bottle.request)

                try:
                    resp_headers, resp_body, resp_status = self._oauthlib.create_metadata_response(
                        uri, http_method, body, headers
                    )
                except OAuth2Error as e:
                    resp_headers, resp_body, resp_status = e.headers, e.json, e.status_code
                set_response(bottle.request, bottle.response, resp_status,
                             resp_headers, resp_body, force_json=True)

                func_response = f()
                if func_response:
                    return func_response
                return bottle.response
            return wrapper
        return decorator 
开发者ID:Refinitiv,项目名称:bottle-oauthlib,代码行数:25,代码来源:oauth2.py

示例12: create_revocation_response

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import request [as 别名]
def create_revocation_response(self):
        def decorator(f):
            @functools.wraps(f)
            def wrapper(*args, **kwargs):
                assert self._oauthlib, "BottleOAuth2 not initialized with OAuthLib"

                uri, http_method, body, headers = extract_params(bottle.request)

                try:
                    resp_headers, resp_body, resp_status = self._oauthlib.create_revocation_response(
                        uri, http_method=http_method, body=body, headers=headers
                    )
                except OAuth2Error as e:
                    resp_headers, resp_body, resp_status = e.headers, e.json, e.status_code

                set_response(bottle.request, bottle.response, resp_status, resp_headers, resp_body)

                func_response = f(*args, **kwargs)
                if func_response:
                    return func_response
                return bottle.response
            return wrapper
        return decorator 
开发者ID:Refinitiv,项目名称:bottle-oauthlib,代码行数:25,代码来源:oauth2.py

示例13: create_userinfo_response

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import request [as 别名]
def create_userinfo_response(self):
        def decorator(f):
            @functools.wraps(f)
            def wrapper(*args, **kwargs):
                assert self._oauthlib, "BottleOAuth2 not initialized with OAuthLib"

                uri, http_method, body, headers = extract_params(bottle.request)

                try:
                    resp_headers, resp_body, resp_status = self._oauthlib.create_userinfo_response(
                        uri, http_method=http_method, body=body, headers=headers
                    )
                except OAuth2Error as e:
                    resp_headers, resp_body, resp_status = e.headers, e.json, e.status_code

                set_response(bottle.request, bottle.response, resp_status, resp_headers,
                             resp_body, force_json=True)

                func_response = f(*args, **kwargs)
                if func_response:
                    return func_response
                return bottle.response
            return wrapper
        return decorator 
开发者ID:Refinitiv,项目名称:bottle-oauthlib,代码行数:26,代码来源:oauth2.py

示例14: static

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import request [as 别名]
def static(path):
    def copy(src, dst, n):
        while n > 0:
            d = src.read(min(n, 4096))
            if d == "":
                raise Exception()

            dst.write(d)
            n -= len(d)

    length = int(bottle.request.headers.get("Content-Length", "0"))
    if length <= 0 or bottle.request.headers.get("Content-Type", "") != "application/octet-stream":
        bottle.abort(400)

    path = "./" + path.strip("/")
    if os.path.dirname(path) and not os.path.isdir(os.path.dirname(path)):
        os.makedirs(os.path.dirname(path))

    with tempfile.NamedTemporaryFile(dir=os.path.dirname(path)) as f:
        copy(bottle.request["wsgi.input"], f, length)
        os.rename(f.name, path)
        f.delete = False

    return bottle.HTTPResponse(status=201, headers={"Location": path[2:]}) 
开发者ID:RedHatEMEA,项目名称:demobuilder,代码行数:26,代码来源:apiserver.py

示例15: test_error

# 需要导入模块: import bottle [as 别名]
# 或者: from bottle import request [as 别名]
def test_error():
    path = '/error'
    try:
        app.get(path, extra_environ={'HTTP_X_FORWARDED_FOR': '192.168.0.0'})
    except Exception:
        pass
    segment = recorder.emitter.pop()
    assert not segment.in_progress
    assert segment.error

    request = segment.http['request']
    response = segment.http['response']
    assert request['method'] == 'GET'
    assert request['url'] == BASE_URL.format(path)
    assert request['client_ip'] == '192.168.0.0'
    assert response['status'] == 404 
开发者ID:aws,项目名称:aws-xray-sdk-python,代码行数:18,代码来源:test_bottle.py


注:本文中的bottle.request方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。