biothings.hub.api¶
biothings.hub.api.managers¶
- class biothings.hub.api.manager.APIManager(log_folder=None, *args, **kwargs)[source]¶
Bases:
BaseManager
biothings.hub.api.handlers.base¶
- class biothings.hub.api.handlers.base.BaseHandler(application: Application, request: HTTPServerRequest, **kwargs: Any)[source]¶
Bases:
DefaultHandler
- class biothings.hub.api.handlers.base.DefaultHandler(application: Application, request: HTTPServerRequest, **kwargs: Any)[source]¶
Bases:
RequestHandler
- set_default_headers()[source]¶
Override this to set HTTP headers at the beginning of the request.
For example, this is the place to set a custom
Server
header. Note that setting such headers in the normal flow of request processing may not do what you want, since headers may be reset during error handling.
- write(result)[source]¶
Writes the given chunk to the output buffer.
To write the output to the network, use the flush() method below.
If the given chunk is a dictionary, we write it as JSON and set the Content-Type of the response to be
application/json
. (if you want to send JSON as a differentContent-Type
, callset_header
after callingwrite()
).Note that lists are not converted to JSON because of a potential cross-site security vulnerability. All JSON output should be wrapped in a dictionary. More details at http://haacked.com/archive/2009/06/25/json-hijacking.aspx/ and https://github.com/facebook/tornado/issues/1009
- write_error(status_code, **kwargs)[source]¶
Override to implement custom error pages.
write_error
may call write, render, set_header, etc to produce output as usual.If this error was caused by an uncaught exception (including HTTPError), an
exc_info
triple will be available askwargs["exc_info"]
. Note that this exception may not be the “current” exception for purposes of methods likesys.exc_info()
ortraceback.format_exc
.
- class biothings.hub.api.handlers.base.GenericHandler(application: Application, request: HTTPServerRequest, **kwargs: Any)[source]¶
Bases:
DefaultHandler
biothings.hub.api.handlers.log¶
- class biothings.hub.api.handlers.log.HubLogDirHandler(application: Application, request: HTTPServerRequest, **kwargs: Any)[source]¶
Bases:
DefaultCORSHeaderMixin
,RequestHandler
- class biothings.hub.api.handlers.log.HubLogFileHandler(application: Application, request: HTTPServerRequest, **kwargs: Any)[source]¶
Bases:
DefaultCORSHeaderMixin
,StaticFileHandler
biothings.hub.api.handlers.shell¶
biothings.hub.api.handlers.upload¶
- class biothings.hub.api.handlers.upload.UploadHandler(application: Application, request: HTTPServerRequest, **kwargs: Any)[source]¶
Bases:
GenericHandler
- data_received(chunk)[source]¶
Implement this method to handle streamed request data.
Requires the .stream_request_body decorator.
May be a coroutine for flow control.
- prepare()[source]¶
Called at the beginning of a request before get/post/etc.
Override this method to perform common initialization regardless of the request method.
Asynchronous support: Use
async def
or decorate this method with .gen.coroutine to make it asynchronous. If this method returns anAwaitable
execution will not proceed until theAwaitable
is done.New in version 3.1: Asynchronous support.
biothings.hub.api.handlers.ws¶
- class biothings.hub.api.handlers.ws.HubDBListener[source]¶
Bases:
ChangeListener
Get events from Hub DB and propagate them through the websocket instance
- class biothings.hub.api.handlers.ws.LogListener(*args, **kwargs)[source]¶
Bases:
ChangeListener
- class biothings.hub.api.handlers.ws.ShellListener(*args, **kwargs)[source]¶
Bases:
LogListener
- class biothings.hub.api.handlers.ws.WebSocketConnection(session, listeners)[source]¶
Bases:
SockJSConnection
Listen to Hub DB through a listener object, and publish events to any client connected
SockJSConnection.__init__() takes only a session as argument, and there’s no way to pass custom settings. In order to use that class, we need to use partial to partially init the instance with ‘listeners’ and let the rest use the ‘session’
- parameter:
pconn = partial(WebSocketConnection,listeners=listeners) ws_router = sockjs.tornado.SockJSRouter(pconn,”/path”)
- clients = {}¶
- on_open(info)[source]¶
Default on_open() handler.
Override when you need to do some initialization or request validation. If you return False, connection will be rejected.
You can also throw Tornado HTTPError to close connection.
- request
ConnectionInfo
object which contains caller IP address, query string parameters and cookies associated with this request (if any).