uiro package

uiro.controller module

class uiro.controller.BaseController

Bases: builtins.object

Base WSGI application class to handle Views.

Controllers try to call methods wrapped by uiro.view.view_config. But actually it will call _wrapped attribute of each Views:

  • Original View methods can be called without any decorators. This behavior is provided for ensuring depending-less tests.
  • When wrapped View raised ViewNotMatched, it will try next one.
  • All of views are not matched, it will return 404 response.

You can inherit this class and register views. Then, decorate views with uiro.view.view_config to apply configation to each views, such as witch views will be call or witch template to use.

class DashboardController(BaseController):
    @view_config(method='get')
    def get_view(self, request):
        return "Hello guys"

    @view_config(method='post')
    def post_view(self, request):
        return "Posted something"

Check the behavior of view_config for more detail.

resource(s, x)
views = []
class uiro.controller.ControllerMetaClass

Bases: builtins.type

exception uiro.controller.NotFound

Bases: builtins.Exception

Error for notifying the resource was not found.

uiro.db module

uiro.db.initdb(config)

Initializing database settings by using config from .ini file.

uiro.request module

class uiro.request.Request(environ, charset=None, unicode_errors=None, decode_param_names=None, **kw)

Bases: webob.request.BaseRequest

matched_dict
matching

uiro.static module

uiro.static.generate_static_matching(app, directory_serve_app=<class 'webob.static.DirectoryApp'>)

Creating a matching for WSGI application to serve static files for passed app.

Static files will be collected from directory named ‘static’ under passed application:

./blog/static/

This example is with an application named blog. URLs for static files in static directory will begin with /static/app_name/. so in blog app case, if the directory has css/main.css file, the file will be published like this:

yoursite.com/static/blog/css/main.css

And you can get this URL by reversing form matching object:

matching.reverse('blog:static', path=['css', 'main.css'])
uiro.static.get_static_app_matching(apps)

Returning a matching containing applications to serve static files correspond to each passed applications.

uiro.template module

uiro.template.get_app_template(name)

Getter function of templates for each applications.

Argument name will be interpreted as colon separated, the left value means application name, right value means a template name.

get_app_template(‘blog:dashboarb.mako’)

It will return a template for dashboard page of blog application.

uiro.template.get_lookups()

Returning the lookups

The global variable _lookups should not be imported directory by another modules. By importing directory, the value will not change evenif setup_lookup

uiro.template.setup_lookup(apps, lookup_class=<class 'mako.lookup.TemplateLookup'>)

Registering template directories of apps to Lookup.

Lookups will be set up as dictionary, app name as key and lookup for this app will be it’s value. Each lookups is correspond to each template directories of apps._lookups. The directory should be named ‘templates’, and put under app directory.

uiro.view module

class uiro.view.MethodPredicate(method)

Bases: builtins.object

Predicate class to checking Method of request object.

MethodPredicate is preserve views when the request method was not same with applied in instantiate.

exception uiro.view.ViewNotMatched

Bases: builtins.Exception

Called view was not apposite. This exception is to notify Controllers that called view was not apposite to the applied rquest.

uiro.view.get_base_wrappers(method='get', template_name='', predicates=(), wrappers=())

basic View Wrappers used by view_config.

uiro.view.preserve_view(*predicates)

Raising ViewNotMatched when applied request was not apposite.

preserve_view calls all Predicates and when return values of them was all True it will call a wrapped view. It raises ViewNotMatched if this is not the case.

Predicates: This decorator takes Predicates one or more, Predicate is callable to return True or False in response to inputted request. If the request was apposite it should return True.

uiro.view.render_template(template_name, template_getter=<function get_app_template at 0x7f8e6f98ae60>)

Decorator to specify which template to use for Wrapped Views.

It will return string rendered by specified template and returned dictionary from wrapped views as a context for template. The returned value was not dictionary, it does nothing, just returns the result.

uiro.view.view_config(method='get', template_name='', predicates=(), wrappers=(), base_wrappers_getter=<function get_base_wrappers at 0x7f8e6f3c7710>)

Creating Views applied some configurations and store it to _wrapped attribute on each Views.

  • _wrapped expects to be called by Controller (subclasses of uiro.controller.BaseController)
  • The original view will not be affected by this decorator.

Module contents

uiro.import_module_attribute(path, splitter=':')
uiro.main(global_conf, root, **settings)

Entry point to create Uiro application.

Setup all of necessary things:

  • Getting root matching
  • Initializing DB connection
  • Initializing Template Lookups
  • Collecting installed applications
  • Creating apps for serving static files

and will create/return Uiro application.