2015-11-18 21:15:37 +00:00
|
|
|
from tornado import web
|
|
|
|
|
2016-07-31 13:30:06 +00:00
|
|
|
from sprockets.http import app, mixins, run
|
2015-11-18 21:15:37 +00:00
|
|
|
|
|
|
|
|
2015-11-19 22:29:07 +00:00
|
|
|
class StatusHandler(mixins.ErrorLogger, mixins.ErrorWriter,
|
|
|
|
web.RequestHandler):
|
|
|
|
"""Example that exercises the mix-ins in this library."""
|
2015-11-18 21:15:37 +00:00
|
|
|
|
|
|
|
def get(self, status_code):
|
|
|
|
"""
|
|
|
|
Returns the requested status.
|
|
|
|
|
|
|
|
:param int status_code: the status code to return
|
|
|
|
:queryparam str reason: optional reason phrase
|
|
|
|
|
|
|
|
"""
|
|
|
|
status_code = int(status_code)
|
|
|
|
if status_code >= 400:
|
2015-11-19 16:51:34 +00:00
|
|
|
kwargs = {'status_code': status_code}
|
2015-11-18 21:15:37 +00:00
|
|
|
if self.get_query_argument('reason', None):
|
2015-11-19 16:51:34 +00:00
|
|
|
kwargs['reason'] = self.get_query_argument('reason')
|
|
|
|
if self.get_query_argument('log_message', None):
|
|
|
|
kwargs['log_message'] = self.get_query_argument('log_message')
|
|
|
|
self.send_error(**kwargs)
|
2015-11-18 21:15:37 +00:00
|
|
|
else:
|
|
|
|
self.set_status(status_code)
|
|
|
|
|
|
|
|
|
2016-07-31 13:30:06 +00:00
|
|
|
class Application(app.Application):
|
|
|
|
|
|
|
|
def __init__(self, **kwargs):
|
|
|
|
kwargs['debug'] = True
|
2018-11-27 00:24:30 +00:00
|
|
|
super().__init__(
|
2016-07-31 13:30:06 +00:00
|
|
|
[web.url(r'/status/(?P<status_code>\d+)', StatusHandler)],
|
|
|
|
**kwargs)
|
2015-11-18 21:15:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2016-07-31 13:30:06 +00:00
|
|
|
run(Application)
|