本文整理匯總了Python中werkzeug.wrappers.Request.application方法的典型用法代碼示例。如果您正苦於以下問題:Python Request.application方法的具體用法?Python Request.application怎麽用?Python Request.application使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類werkzeug.wrappers.Request
的用法示例。
在下文中一共展示了Request.application方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: application
# 需要導入模塊: from werkzeug.wrappers import Request [as 別名]
# 或者: from werkzeug.wrappers.Request import application [as 別名]
def application(request):
file_path = request.path.lstrip(URL_PREFIX)
full_path = os.path.join(BASE_PATH, file_path)
# Protect against path traversal attacks, if they make it this far.
if not full_path.startswith(BASE_PATH):
# DANGER!
return Response("Suspicious url", status=403)
format = request.args.get('format', None)
if format == 'raw':
# Let nginx serve raw files
accel_path = os.path.join('/accelredir/', file_path)
return Response('', headers={'X-Accel-Redirect': accel_path})
try:
extension = get_extension(full_path, format)
if extension and extension in handlers:
return handlers[extension](full_path, format)
else:
return Response("No handlers for format %s" % extension, status=400)
except FileNotFoundError:
return Response("Not found", status=404)
return Response(full_path)
示例2: respond_with_json
# 需要導入模塊: from werkzeug.wrappers import Request [as 別名]
# 或者: from werkzeug.wrappers.Request import application [as 別名]
def respond_with_json(
self,
response_json,
status: int = 200,
headers: Optional[Mapping[str, str]] = None,
content_type: str = "application/json"):
"""
Registers a respond handler function which responds with a serialized JSON object.
:param response_json: a JSON-serializable python object
:param status: the HTTP status of the response
:param headers: the HTTP headers to be sent (excluding the Content-Type header)
:param content_type: the content type header to be sent
"""
response_data = json.dumps(response_json, indent=4)
self.respond_with_data(response_data, status, headers, content_type=content_type)
示例3: start
# 需要導入模塊: from werkzeug.wrappers import Request [as 別名]
# 或者: from werkzeug.wrappers.Request import application [as 別名]
def start(self):
"""
Start the server in a thread.
This method returns immediately (e.g. does not block), and it's the caller's
responsibility to stop the server (by calling :py:meth:`stop`) when it is no longer needed).
If the sever is not stopped by the caller and execution reaches the end, the
program needs to be terminated by Ctrl+C or by signal as it will not terminate until
the thred is stopped.
If the sever is already running :py:class:`HTTPServerError` will be raised. If you are
unsure, call :py:meth:`is_running` first.
There's a context interface of this class which stops the server when the context block ends.
"""
if self.is_running():
raise HTTPServerError("Server is already running")
self.server = make_server(self.host, self.port, self.application, ssl_context=self.ssl_context)
self.port = self.server.port # Update port (needed if `port` was set to 0)
self.server_thread = threading.Thread(target=self.thread_target)
self.server_thread.start()
示例4: run_telenium
# 需要導入模塊: from werkzeug.wrappers import Request [as 別名]
# 或者: from werkzeug.wrappers.Request import application [as 別名]
def run_telenium():
Logger.info("TeleniumClient: Started at 0.0.0.0:9901")
register_input_provider()
dispatcher.add_method(rpc_version, "version")
dispatcher.add_method(rpc_ping, "ping")
dispatcher.add_method(rpc_get_token, "get_token")
dispatcher.add_method(rpc_app_quit, "app_quit")
dispatcher.add_method(rpc_app_ready, "app_ready")
dispatcher.add_method(rpc_select, "select")
dispatcher.add_method(rpc_highlight, "highlight")
dispatcher.add_method(rpc_getattr, "getattr")
dispatcher.add_method(rpc_setattr, "setattr")
dispatcher.add_method(rpc_element, "element")
dispatcher.add_method(rpc_execute, "execute")
dispatcher.add_method(rpc_pick, "pick")
dispatcher.add_method(rpc_click_on, "click_on")
dispatcher.add_method(rpc_drag, "drag")
dispatcher.add_method(rpc_send_keycode, "send_keycode")
run_simple("0.0.0.0", 9901, application)
示例5: test_environ_builder_basics
# 需要導入模塊: from werkzeug.wrappers import Request [as 別名]
# 或者: from werkzeug.wrappers.Request import application [as 別名]
def test_environ_builder_basics(self):
b = EnvironBuilder()
self.assert_is_none(b.content_type)
b.method = 'POST'
self.assert_equal(b.content_type, 'application/x-www-form-urlencoded')
b.files.add_file('test', BytesIO(b'test contents'), 'test.txt')
self.assert_equal(b.files['test'].content_type, 'text/plain')
self.assert_equal(b.content_type, 'multipart/form-data')
b.form['test'] = 'normal value'
req = b.get_request()
b.close()
self.assert_strict_equal(req.url, u'http://localhost/')
self.assert_strict_equal(req.method, 'POST')
self.assert_strict_equal(req.form['test'], u'normal value')
self.assert_equal(req.files['test'].content_type, 'text/plain')
self.assert_strict_equal(req.files['test'].filename, u'test.txt')
self.assert_strict_equal(req.files['test'].read(), b'test contents')
示例6: test_correct_open_invocation_on_redirect
# 需要導入模塊: from werkzeug.wrappers import Request [as 別名]
# 或者: from werkzeug.wrappers.Request import application [as 別名]
def test_correct_open_invocation_on_redirect(self):
class MyClient(Client):
counter = 0
def open(self, *args, **kwargs):
self.counter += 1
env = kwargs.setdefault('environ_overrides', {})
env['werkzeug._foo'] = self.counter
return Client.open(self, *args, **kwargs)
@Request.application
def test_app(request):
return Response(str(request.environ['werkzeug._foo']))
c = MyClient(test_app, response_wrapper=Response)
self.assert_strict_equal(c.get('/').data, b'1')
self.assert_strict_equal(c.get('/').data, b'2')
self.assert_strict_equal(c.get('/').data, b'3')
示例7: _application
# 需要導入模塊: from werkzeug.wrappers import Request [as 別名]
# 或者: from werkzeug.wrappers.Request import application [as 別名]
def _application(self, request):
# Add the shutdown method if it is available and has not already
# been added. This won't be executed via the engine timers.
shutdown_func = request.environ.get('werkzeug.server.shutdown')
shutdown_func_name = "shutdown_rpc_server"
if shutdown_func and shutdown_func_name not in self._dispatcher:
# Add it to the dispatcher directly.
self._dispatcher.add_method(shutdown_func, shutdown_func_name)
# Get a response using the method dispatcher and return it.
response = JSONRPCResponseManager.handle(
request.data, self._dispatcher
)
return Response(response.json, mimetype='application/json')
示例8: application
# 需要導入模塊: from werkzeug.wrappers import Request [as 別名]
# 或者: from werkzeug.wrappers.Request import application [as 別名]
def application(request):
return Response('Hello World!')
示例9: application
# 需要導入模塊: from werkzeug.wrappers import Request [as 別名]
# 或者: from werkzeug.wrappers.Request import application [as 別名]
def application(self, request: Request):
"""
Entry point of werkzeug.
This method is called for each request, and it then calls the undecorated
:py:meth:`dispatch` method to serve the request.
:param request: the request object from the werkzeug library
:return: the response object what the dispatch returned
"""
request.get_data()
response = self.dispatch(request)
self.log.append((request, response))
return response
示例10: return_reponse
# 需要導入模塊: from werkzeug.wrappers import Request [as 別名]
# 或者: from werkzeug.wrappers.Request import application [as 別名]
def return_reponse(self, data):
return Response(self.backend._process_response(data),
status=http_status_code(data), mimetype='application/json')
示例11: application
# 需要導入模塊: from werkzeug.wrappers import Request [as 別名]
# 或者: from werkzeug.wrappers.Request import application [as 別名]
def application(self, request):
log.debug("Got helper request - {}".format(request.data))
response = JSONRPCResponseManager.handle(request.data, dispatcher)
return Response(response.json, mimetype='application/json')
示例12: run
# 需要導入模塊: from werkzeug.wrappers import Request [as 別名]
# 或者: from werkzeug.wrappers.Request import application [as 別名]
def run(self):
# start in a new thread
log.debug("Starting StackHut helper-server")
run_simple('localhost', 4000, self.application, threaded=True)
示例13: misocoin_app
# 需要導入模塊: from werkzeug.wrappers import Request [as 別名]
# 或者: from werkzeug.wrappers.Request import application [as 別名]
def misocoin_app(request):
response = JSONRPCResponseManager.handle(request.data, dispatcher)
return Response(response.json, mimetype='application/json')
# Block management
# Handles the mining of blocks, as well as the automatic adjusting of difficulty
示例14: __init__
# 需要導入模塊: from werkzeug.wrappers import Request [as 別名]
# 或者: from werkzeug.wrappers.Request import application [as 別名]
def __init__(self, alexa, validate_requests=True):
"""
:param alexa: alexandra.app.App to wrap
:param validate_requests: Whether or not to do timestamp and
certificate validation.
"""
self.alexa = alexa
self.validate = validate_requests
# The Request.application decorator handles some boring parts of making
# this work with WSGI
示例15: wsgi_app
# 需要導入模塊: from werkzeug.wrappers import Request [as 別名]
# 或者: from werkzeug.wrappers.Request import application [as 別名]
def wsgi_app(self, request):
"""Incoming request handler.
:param request: Werkzeug request object
"""
try:
if request.method != 'POST':
abort(400)
try:
# Python 2.7 compatibility
data = request.data
if isinstance(data, str):
body = json.loads(data)
else:
body = json.loads(data.decode('utf-8'))
except ValueError:
abort(400)
if self.validate:
valid_cert = util.validate_request_certificate(
request.headers, request.data)
valid_ts = util.validate_request_timestamp(body)
if not valid_cert or not valid_ts:
log.error('failed to validate request')
abort(403)
resp_obj = self.alexa.dispatch_request(body)
return Response(response=json.dumps(resp_obj, indent=4),
status=200,
mimetype='application/json')
except HTTPException as exc:
log.exception('Failed to handle request')
return exc