ripozo.dispatch package

Submodules

ripozo.dispatch.dispatch_base module

class ripozo.dispatch.dispatch_base.DispatcherBase[source]

Bases: object

This is an abstract base class that is responsible for handling the interface between a request and the resource as well as the interface between the resource and the response. A new subclass should be developed for every framework that ripozo is supposed to work with. Those extensions should be in separate repositories though. This specific base class is mostly for shortcuts and to give an idea of how to actually implement ripozo with a framework.

property adapter_formats

Returns the mutable _adapter_formats. If the _adapter_formats property is None then it first sets cls._adapter_formats to an empty dictionary.

Return type

dict

abstract property base_url
Returns

The base url including the domain and protocol This needs to be included so that the adapters can construct fully qualified urls. However, they have no way of directly identifying that so they need to be able to get it from the dispatcher.

Return type

unicode

property default_adapter
Returns

The AdapterBase subclass that is the default adapter to use when the client doesn’t explicitly request a specific adapter. If no default adapter is set when register_adapters is called, then the first adapter provided to register_adapters will be set as the default adapter.

Return type

AdapterBase

dispatch(endpoint_func, format_type, *args, **kwargs)[source]

A helper to dispatch the endpoint_func, get the ResourceBase subclass instance, get the appropriate AdapterBase subclass and return an instance created with the ResourceBase.

Parameters
  • endpoint_func (method) – The endpoint_func is responsible for actually get the ResourceBase response

  • format_type (unicode) – The format_type for the response format that should be returned.

  • args (list) – a list of args that wll be passed to the endpoint_func

  • kwargs (dict) – a dictionary of keyword args to pass to the endpoint_func

Returns

an instance of an AdapterBase subclass that can be used to find

Return type

get_adapter_for_type(format_type)[source]

Gets the appropriate adapter class for the specified format type. For example, if the format_type was siren it would return the SirenAdapter. Returns the default adapter If it cannot not find an adapter for the format_type.

Parameters

format_type (unicode) –

Returns

Return type

type

register_adapters(*adapter_classes)[source]

Registers a list of valid adapter classes with this dispatcher. It will take the formats attribute from the AdapterBase subclass and use each of those as a key with the value pointing.

If _default_adapter is not set, then the first adapter_class will be the default adapter to use when returning responses.

Parameters

adapter_classes (list) – A list of subclasses of AdapterBase that specify what formats are available for this dispatcher

Raises

AdapterFormatAlreadyRegisteredException

register_class_routes(klass)[source]

Register a subclass of the ResourceBase on the framework implementation. This is so that the actual actions on the resources can be dispatched to by the framework.

Parameters

klass (ripozo.viewsets.resource_base.ResourceBase) – The class whose endpoints must be registered

register_resources(*classes)[source]

A shortcut for register multiple classes at once.

Parameters

classes (list) – A list of ResourceBase subclasses that are being registered with this dispatcher.

abstract register_route(endpoint, endpoint_func=None, route=None, methods=None, **options)[source]

Registers an individual route on the framework. This method gives a specific framework the opportunity to actually dispatch the incoming requests appropriately.

Parameters
  • endpoint (unicode) – The name of the endpoint

  • endpoint_func (method) – The endpoint_func that is responsible for actually performing the actions requested

  • route (unicode) – The route template for this endpoint

  • methods (list) – A list of the methods on this route that will point to the endpoint_funct

  • options (dict) – A dictionary of additional options.

Module contents