biothings.hub.api
biothings.hub.api.managers
- class biothings.hub.api.manager.APIManager(log_folder=None, *args, **kwargs)[source]
Bases:
BaseManager- get_pinfo()[source]
Return dict containing information about the current process (used to report in the hub)
- log_pytests(pytest_path, host)[source]
Run the pytests for the given pytest path and host. We create a LoggerFile object to redirect stdout and stderr to the logger.
- restore_running_apis()[source]
If some APIs were running but the hub stopped, re-start APIs as hub restarts
- test_api(api_id)[source]
Run pytests for the given api id. If no pytest path is found in the config_web_local.py then log an error. APITEST_CONFIG_ROOT: root directory containing the config_web APITEST_CONFIG: name of the config file containing the api web configuration APITEST_ROOT: root directory containing the conftest.py file for the pytests APITEST_PATH: path to the directory containing the pytests
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
Serverheader. 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_headerafter 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_errormay call write, render, set_header, etc to produce output as usual.If this error was caused by an uncaught exception (including HTTPError), an
exc_infotriple 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. There is no guarantee that
preparewill be called if an error occurs that is handled by the framework.Asynchronous support: Use
async defor decorate this method with .gen.coroutine to make it asynchronous. If this method returns anAwaitableexecution will not proceed until theAwaitableis done.Added in version 3.1: Asynchronous support.
biothings.hub.api.handlers.ws
- class biothings.hub.api.handlers.ws.HubDBListener[source]
Bases:
ChangeListenerGet 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:
SockJSConnectionListen 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
ConnectionInfoobject which contains caller IP address, query string parameters and cookies associated with this request (if any).