rum.wsgiapp

RumApp

class rum.wsgiapp.RumApp(config=None, full_stack=True, debug=False, finalize=True, root_controller=<class 'rum.controller.RootController'>)

Rum’s WSGI interface and facade to all of Rum’s functionallity.

Parameters:
config
A filename or a dictionary with the application’s configuration. See Rum’s config format for details.
full_stack
Is RumApp the only WSGI app in the stack? Set to False if you are providing needed middleware yourself
debug
Enable for debug mode. MUST set to False on production.
finalize
Set to False if you want to further configure the RumApp instance and depend on rum.app` pointing to the current app. MUST call finalize() explicitly yourself when done and make sure it is really called (ie: in a finally clause).
root_controller
A rum.interfaces.IController implementation or a WSGI app that should be mounted at the root of the URL dispatch tree.

To be able to configure the app programatically after it has been initialized you can pass the finalize = False parameter when instantiating it and call rum.app.RumApp.finalize() when you’re done.

Warning

It is mandatory that finalize() is called or else bad things will happen.

add_middleware()

Wraps wsgi_app() with needed middleware.

Override this method to customize the way middleware is stacked.

load_config(config, **defaults)

Loads and initilizes the configuration for this RumApp

finalize()

When the finalize flag is False when initializing RumApp this method must be called after the app has been manually tweaked after initialization.

It is very important that this method is called.

call_in_context(func, *args, **kw)

Calls func with args as positional and kw as keyword arguments inside the context of this app.

It is neccesary to call this way any function that accesses any of the components accesible from this app when this app is not the current active app (ie: The one serving the request).

If you get a traceback saying that rum.app is None when using this app the this is probably what you’re looking for.

Warning

This is only here for compatibility with python < 2.6 (or python 2.5 without “from __future__ import with_statement”). It will be deprecated as soon as it is feasible to drop support for Python 2.4

connect_default_routes()

Connects default routes used by this app when not handling resources.

Override this method if you want to register controllers at whatever URL point you need.

register(resource, attributes={}, prefix=None)

Registers URL endpoints to handle resource and a endpoints to handle each of the resources which are values of attributes with resource as a parent. The keys of the attributes dict are the remote names from which each value can be accessed from resource.

Example:

register(Person, dict(addresses=Address, jobs=Job))

Will register Person at (usually) /persons and Address and Job at /persons/${person_id}/addresses and /persons/${person_id}/jobs respectively.

All operations on Address and Job when accessed at these endpoints will have a particular Person as a parent.

url_for(*args, **kw)

Generate a URL for the routes whose dict most closely resembles kw. raise a RoutesException if no url could be generated.

redirect_to(*args, **kw)

Isomorphic to url_for() but issues an HTTP redirect to the resulting URL. The redirect code can be set with the _code keyword argument (303 See Other by default).

If the _use_next flag is passed as a keyword arg. then it will try to use the URL the client provided through the _next_redirect arg. if provided, else it will use the URL that was requested explicitly.

dispatch(request)

Returns a controller to handle request. Raises a “404 Not Found” if no controller could be found.

fields_for_resource(resource)

Returns a list of rum.fields.Field for a resource or a rum.fields.Field for attribute attr of resource if attr is not None.

set_names(obj, singular, plural)

Registers the singular and plural names for obj and its instances.

names_for_resource(resource)

Return (singular, plural) names for resource.

render(data, possible_templates, renderer=None)

Renders the first template that can be loaded of possible_templates using the renderer named renderer with variables from the data dict.

mounted_at(mount_point='')

Sets up a dummy request so urls can be properly generated when using the app’s services outside of the context of a request handled by Rum.

Usage:

with rum_app.mounted_at('/admin'):
    url = rum_app.url_for(obj=some_obj, action='edit')
    form = rum_app.viewfactory(SomeClass, action='new')
    etc ...

This feature requires Python 2.6 or 2.5 with: “from __future__ import with_statement”

The components and special attributes of RumApp

RumApp.controllerfactory

RumApp.controllerfactory

This attribute is the rum.interfaces.IControllerFactory implementation that has been configured for this app. It’s job is to match routing arguments and return a rum.interfaces.IController implementator’s instance that will be used to handle the request.

RumApp.repositoryfactory

RumApp.repositoryfactory

This attribute is the rum.interfaces.IRepositoryFactory implementation that has been configured for this app. It’s job is to match routing arguments and return a rum.interfaces.IRepository implementator’s instance that will be used to broker access to the data source.

RumApp.viewfactory

RumApp.viewfactory

This attribute is the rum.interfaces.IViewFactory implementation that has been configured for this app. It’s job is to match routing arguments and return a rum.interfaces.IView or rum.interfaces.IInputView implementator’s instance that will be used to generate a view or validate input parameters for a resource.

RumApp.router

RumApp.router

This attribute is the rum.interfaces.IRouter implementation that has been configured for this app. It’s job is to match incoming URLs and HTTP methods and generate a routes dict.

The routes dict contains the following keys:
resource
The resource class that should be handled at this URL.
parent
The resource class resource is a child of.
remote_name
If parent is not None, remote_name is the name of the attribute of parent which is a colletion where resource can be found at.
prefix
This is usually None. If it’s not then it is the same value which was used when registering the resource in the rum.RumRouter. It is used to be able to mount the same resource at different URL points with diverging behaviours or security policies.

This routes dict can be accessed at the rum.wsgiutils.RumRequest.routes attribute (Remember that the current request object is accesible at rum.app.request.

RumApp.jsonencoder

RumApp.jsonencoder

The encoder that has been configured for this app to serialize objects into JSON format

RumApp.request

RumApp.request

A paste.registry.StackedObjectProxy that points to the current rum.wsgiutils.RumRequest.

It will be None if outside the scope of a request (ie: RumApp has not been been __call__ ed)