本文整理汇总了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
示例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)
示例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!")
示例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!")
示例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
示例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))
示例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
示例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))
示例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())
示例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))
示例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
示例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
示例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
示例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:]})
示例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