The core application.
Classes
Kyoukai (application_name: str, *, …) |
The Kyoukai type is the core of the Kyoukai framework, and the core of your web application based upon the Kyoukai framework. |
kyoukai.app.
Kyoukai
(application_name: str, *, server_name: str = None, **kwargs)[source]¶Bases: object
The Kyoukai type is the core of the Kyoukai framework, and the core of your web application based upon the Kyoukai framework. It acts as a central router and request processor that takes in requests from the protocols and returns responses.
The application name is currently unused, but it is good practice to set it correctly anyway in case it is used in future editions of Kyoukai.
You normally create an application instance inside your component file, like so:
from kyoukai.app import Kyoukai
... # setup code
kyk = Kyoukai("my_app")
kyk.register_blueprint(whatever)
... # other setup
class MyContainer(ContainerComponent):
async def start(self, ctx):
self.add_component('kyoukai', KyoukaiComponent, ip="127.0.0.1", port=4444,
app="app:app")
Of course, you can also embed Kyoukai inside another app, by awaiting Kyoukai.start()
.
Parameters: |
|
---|
request_class
¶The class of request to spawn every request.
This should be a subclass of werkzeug.wrappers.Request
.
You can override this by passing request_class
as a keyword argument to the app.
alias of Request
response_class
¶The class of response to wrap automatically.
This should be a subclass of werkzeug.wrappers.Response
.
You can override this by passing response_class
as a keyword argument to the app.
alias of Response
context_class
= None¶The context class.
register_blueprint
(child)[source]¶Registers a child blueprint to this app’s root Blueprint.
This will set up the Blueprint tree, as well as setting up the routing table when finalized.
Parameters: | child (Blueprint ) – The child Blueprint to add. This must be an instance of Blueprint . |
---|
finalize
(**map_options)[source]¶Finalizes the app and blueprints.
This will calculate the current werkzeug.routing.Map
which is required for
routing to work.
Parameters: | map_options – The options to pass to the Map for routing. |
---|---|
Return type: | Map |
handle_httpexception
(self, ctx, exception, environ=None)[source]¶Handle a HTTP Exception.
Parameters: |
|
---|---|
Return type: | |
Returns: | A |
process_request
(self, request, parent_context)[source]¶Processes a Request and returns a Response object.
This is the main processing method of Kyoukai, and is meant to be used by one of the HTTP server backends, and not by client code.
Parameters: |
|
---|---|
Return type: | |
Returns: | A |
start
(self, ip='127.0.0.1', port=4444, *, component=None, base_context=None)[source]¶Runs the Kyoukai component asynchronously.
This will bypass Asphalt’s default runner, and allow you to run your app easily inside something else, for example.
Parameters: |
|
---|