Asphalt wrappers for Kyoukai.
Functions
resolve_reference (ref) |
Return the object pointed to by ref . |
Classes
Blueprint (name[, parent, prefix, ...]) |
A Blueprint class contains a Map of URL rules, which is checked and ran for every |
Component |
This is the base class for all Asphalt components. |
ConnectionLostEvent (source, topic, *, protocol) |
Dispatched when a connection is lost from the server. |
ConnectionMadeEvent (source, topic, *, protocol) |
Dispatched when a connection is made to the server. |
Context ([parent, default_timeout]) |
Contexts give request handlers and callbacks access to resources. |
CtxEvent (source, topic, *, ctx) |
|
Event (source, topic) |
The base class for all events. |
HTTPRequestContext (parent, request) |
The context subclass passed to all requests within Kyoukai. |
KyoukaiBaseComponent (app[, ip, port]) |
The base class for any component used by Kyoukai. |
KyoukaiComponent (app[, ip, port]) |
A component for Kyoukai. |
Request (environ[, populate_request, shallow]) |
Full featured request object implementing the following mixins: |
Response ([response, status, headers, ...]) |
Full featured response object implementing the following mixins: |
Route (function[, reverse_hooks, ...]) |
A route object is a wrapped function. |
RouteInvokedEvent (source, topic, *, ctx) |
Dispatched when a route is invoked. |
RouteMatchedEvent (source, topic, *, ctx) |
Dispatched when a route is matched. |
RouteReturnedEvent (source, topic, *, ctx, result) |
Dispatched after a route has returned. |
Rule (string[, defaults, subdomain, methods, ...]) |
A Rule represents one URL pattern. |
Signal (event_class, *[, source, topic]) |
Declaration of a signal that can be used to dispatch events. |
partial |
partial(func, *args, **keywords) - new function with partial application |
kyoukai.asphalt.
ConnectionMadeEvent
(source, topic, *, protocol)[source]¶Bases: asphalt.core.event.Event
Dispatched when a connection is made to the server.
This does NOT fire when using WSGI workers.
This has the protocol as the protocol
attribute.
kyoukai.asphalt.
ConnectionLostEvent
(source, topic, *, protocol)[source]¶Bases: kyoukai.asphalt.ConnectionMadeEvent
Dispatched when a connection is lost from the server.
This does NOT fire when using WSGI workers.
This has the protocol as the protocol
attribute.
kyoukai.asphalt.
RouteMatchedEvent
(source, topic, *, ctx)[source]¶Bases: kyoukai.asphalt.CtxEvent
Dispatched when a route is matched.
This has the context as the ctx
attribute, and the route can be accessed via ctx.route
.
kyoukai.asphalt.
RouteInvokedEvent
(source, topic, *, ctx)[source]¶Bases: kyoukai.asphalt.CtxEvent
Dispatched when a route is invoked.
This has the context as the ctx
attribute.
kyoukai.asphalt.
RouteReturnedEvent
(source, topic, *, ctx, result)[source]¶Bases: kyoukai.asphalt.CtxEvent
Dispatched after a route has returned.
This has the context as the ctx
attribute and the response as the result
attribute.
kyoukai.asphalt.
KyoukaiBaseComponent
(app, ip='127.0.0.1', port=4444, **cfg)[source]¶Bases: asphalt.core.component.Component
The base class for any component used by Kyoukai.
This one does not create a Server instance; it should be used when you are using a different HTTP server backend.
app
= None¶The application object for a this component.
ip
= None¶The IP address to boot the server on.
port
= None¶The port to boot the server on.
cfg
= None¶The config file to use.
server
= None¶The asyncio.Server
instance that is serving us today.
base_context
= None¶The base context for this server.
backend
= None¶The backend to use for the HTTP server.
kyoukai.asphalt.
KyoukaiComponent
(app, ip='127.0.0.1', port=4444, **cfg)[source]¶Bases: kyoukai.asphalt.KyoukaiBaseComponent
A component for Kyoukai.
This includes the built-in HTTP server.
Creates a new component.
Parameters: |
|
---|
start
(self, ctx)[source]¶Starts the webserver if required.
Parameters: | ctx (Context ) – The base context. |
---|
get_protocol
(ctx, serv_info)¶Gets the protocol to use for this webserver.
kyoukai.asphalt.
HTTPRequestContext
(parent, request)[source]¶Bases: asphalt.core.context.Context
The context subclass passed to all requests within Kyoukai.
request
= None¶The werkzeug.wrappers.Request
object this request is handling.
rule
= None¶The werkzeug.routing.Rule
object associated with this request.
environ
= None¶The WSGI environment for this request.
proto
= None¶The asyncio.Protocol
protocol handling this connection.
get_resources
(type=None, *, include_parents=True)¶Return the currently published resources specific to one type or all types.
Parameters: | |
---|---|
Return type: |
|
parent
¶Return the parent of this context or None
if there is no parent context.
Return type: | Optional [Context ] |
---|
publish_lazy_resource
(creator, types, alias='default', context_attr=None)¶Publish a “lazy” or “contextual” resource and dispatch a resource_published
event.
Instead of a concrete resource value, you supply a creator callable which is called with a
context object as its argument when the resource is being requested either via
request_resource()
or by context attribute access.
The return value of the creator callable will be cached so the creator will only be called
once per context instance.
If the creator callable is a coroutine function or returns an awaitable, it is resolved before storing the resource value and returning it to the requester. Note that this will NOT work when a context attribute has been specified for the resource.
Parameters: |
|
---|---|
Return type: |
|
Returns: | the resource handle |
Raises: | asphalt.core.context.ResourceConflict – if there is an existing resource creator for the given types or context variable |
publish_resource
(value, alias='default', context_attr=None, *, types=())¶Publish a resource and dispatch a resource_published
event.
Parameters: |
|
---|---|
Return type: |
|
Returns: | the resource handle |
Raises: | asphalt.core.context.ResourceConflict – if the resource conflicts with an existing one in any way |
remove_resource
(resource)¶Remove the given resource from the collection and dispatch a resource_removed
event.
Parameters: | resource (Resource ) – the resource to be removed |
---|---|
Raises: | LookupError – the given resource was not in the collection |
request_resource
(self, type, alias='default', *, timeout=None)¶Request a resource matching the given type and alias.
If no such resource was found, this method will wait timeout
seconds for it to become
available. The timeout does not apply to resolving awaitables created by lazy resource
creators.
Parameters: | |
---|---|
Returns: | the value contained by the requested resource (NOT a |
Raises: | asphalt.core.context.ResourceNotFound – if the requested resource does not become available in the allotted time |