AnyBlok / Pyramid framework

AnyBlok/ Pyramid controllers

class anyblok_pyramid.controllers.PyramidException

Exception for web type

class anyblok_pyramid.controllers.PyramidMixin

Bases: anyblok.mixin.MixinType

The PyramidMixin class are used to define a behaviours on models:

  • Add new mixin class:

    @Declarations.register(Declarations.PyramidMixin)
    class MyMixinclass:
        pass
    
  • Remove a mixin class:

    Declarations.unregister(Declarations.PyramidMixin.MyMixinclass,
                            MyMixinclass)
    
class anyblok_pyramid.controllers.Pyramid

Bases: object

The Pyramid controller is a simple wrapper of the Pyramid controller

Pyramid can scan easily the view declarations to add them in the configuration. But the route have to add directlly in the configuration. This controller do all of them. The route and view are saved in the controller and the controller add them in the configuration at the start of the wsgi server

Warning

This case is only use by the script anyblok_wsgi, if you use an another script, you must include the includem pyramid_config or use the function make_config to get all the configuration

This Type is not an entry, no class are assembled in the registry. You must not add any class of this Type, the methods register and unregister raise an exception.

Add a view:

from anyblok import Declarations


@Declarations.Pyramid.add_view('route name')
def myview(request):
    ...

Note

The decorator add_view is just a wrapper of add_view

the args already filled by the wraper are:

  • view: is the decorated function
  • name: is the route name

Add a route:

from anyblok import Declarations


Declarations.Pyramid.add_route('route name', '/my/path')

Note

The function add_route is just a wrapper of add_route

The args already filled by the wraper are:

  • name: is the route name
  • pattern: is the path

Warning

It ‘s important to use the add_route of Pyramid, because when the view are add in configuration, this view check is the route name exist in the routes.

classmethod add_route(*args, **kwargs)

Declare a route to add it in the configuration of Pyramid:

from anyblok import Declarations


Declarations.Pyramid.add_route('route name', '/my/path')

Note

The function add_route is just a wrapper of add_route

The args already filled by the wraper are:

  • name: is the route name
  • pattern: is the path
classmethod add_view(endpoint, **kwargs)

Declare a view to add it in the configuration of Pyramid:

from anyblok import Declarations


@Declarations.Pyramid.add_view('route name')
def myview(request):
    ...

Note

The decorator add_view is just a wrapper of add_view

the args already filled by the wraper are:

  • view: is the decorated function
  • name: is the route name
classmethod register(parent, name, cls_)

Forbidden method, this method always raise when calls

Parameters:
  • parent – Existing global registry
  • name – Name of the new registry to add it
  • cls – Class Interface to add in registry
Exception:

PyramidException

routes = []

Route properties to add in pyramid configuration

classmethod unregister(child, cls_)

Forbidden method, this method always raise when calls

Parameters:
  • entry – entry declaration of the model where the cls_ must be removed
  • cls – Class Interface to remove in registry
Exception:

PyramidException

views = []

View properties to add in pyramid configuration

class anyblok_pyramid.controllers.PyramidBase

Bases: object

Warning

This class is not a controller, but base of HTTP and RPC controller

Warning

This class is not the Core.PyramidBase.

The declarations of HTTP and RPC controller is not the same, but they are few difference.

classmethod assemble_callback(registry)

Assemble callback is called to assemble all the controllers from the installed bloks

Parameters:registry – registry to update
classmethod authentificated()

Decorator which add the property authentificated with the value True

classmethod check_properties(**kwargs)

decorator which add the properties to check

Parameters:**kwargs – dict property: value to check
classmethod hook_insert_in_bases(registry, bases)

The difference between HTTP and RPC controller are the Core used by them. all of them must inherit of:

  • Core.PyramidBase
  • registry_base
Parameters:
  • registry – the current registry for the controller
  • bases – bases list which define the controller
classmethod load_namespace(registry, namespace, realregistryname=None)

Return the bases and the properties of the namespace

Parameters:
  • registry – the current registry
  • namespace – the namespace of the model
  • realregistryname – the name of the model if the namespace is a mixin
Return type:

the list od the bases and the properties

Exception:

PyramidException

classmethod properties_from_decorators(registryname, cls_)

Properties is used to make some check before call the view. This method get the view which are need this verification

Parameters:
  • registryname – the registry name
  • cls – a class of the registry name to take the properties
Return type:

dict to save in the registry

classmethod register(parent, name, cls_, **kwargs)

add new sub registry in the registry

Parameters:
  • parent – Existing global registry
  • name – Name of the new registry to add it
  • cls – Class Interface to add in registry
classmethod transform_base(registry, namespace, base, properties)

Detect specific declaration which must define by registry

Parameters:
  • registry – the current registry
  • namespace – the namespace of the controller
  • base – One of the base of the controller
  • properties – the properties of the controller
Return type:

new base

classmethod unregister(entry, cls_)

Remove the Interface from the registry

Parameters:
  • entry – entry declaration of the model where the cls_ must be removed
  • cls – Class Interface to remove in registry
class anyblok_pyramid.controllers.PyramidHTTP

Bases: anyblok_pyramid.controllers.PyramidBase

The PyramidHTTP controller is a simple wrapper of the Pyramid controller

At the start of the pyramid server, all routes and all the views must be known. But the routes and views are declared on the bloks. Then the declaration of the routes and the views must be done also if the bloks are not installed. When the controller is called then the view must be validated by the controller to be called

Warning

This case is only use by the script anyblok_wsgi, if you use an another script, you must include the includem pyramid_http_config or use the function make_config to get all the configuration

Add a view:

from anyblok import Declarations


@Declarations.register(Declaration.PyramidHTTP)
class MyController:

    @Declaration.PyramidHTTP.view()
    def myview(request):
        # route name == myview
        ...

    @Declaration.PyramidHTTP.view('myroute')
    def myotherview(request):
        # route name == myroute
        ...

Note

The decorator view is just a wrapper of add_view

the args already filled by the wraper are:

  • view: is the decorated function
  • name: the default value is the name of the method or the first args

Add a route:

from anyblok import Declarations


Declarations.PyramidHTTP.add_route('route name', '/my/path')

Note

The function add_route is just a wrapper of add_route

The args already filled by the wraper are:

  • name: is the route name
  • pattern: is the path

Warning

It ‘s important to use the add_route of PyramidHTTP, because when the view are add in configuration, this view check is the route name exist in the routes.

classmethod add_route(*args, **kwargs)

Declare a route to add it in the configuration of Pyramid:

from anyblok import Declarations


Declarations.PyramidHTTP.add_route('route name', '/my/path')

Note

The function add_route is just a wrapper of add_route

The args already filled by the wraper are:

  • name: is the route name
  • pattern: is the path
classmethod hook_insert_in_bases(registry, bases)

Define the Core class inherited by PyramidHTTP controllers

  • Core.PyramidBaseHTTP
  • super()
Parameters:
  • registry – the current registry for the controller
  • bases – bases list which define the controller
classmethod hook_view_from_decorators(registryname, cls_)

Save the decorated method by view

Parameters:
  • registryname – registry name of the controller
  • cls_ – the cls of the registry name
Return type:

dict {‘views’: {route name: function} }

routes = []

Route properties to add in pyramid configuration

classmethod view(**kwargs)

Declare a view to add it in the configuration of Pyramid:

from anyblok import Declarations


@Declarations.register(Declaration.PyramidHTTP)
class My controller:

    @Declaration.PyramidHTTP.view()
    def myview(request):
        # route name == myview
        ...

    @Declaration.PyramidHTTP.view('myroute')
    def myotherview(request):
        # route name == myroute
        ...

Note

The decorator view is just a wrapper of add_view

the args already filled by the wraper are:

  • view: is the decorated function

  • name: the default value is the name of the method or the first

    args

views = {}

View properties to add in pyramid configuration

class anyblok_pyramid.controllers.PyramidRPC

Bases: anyblok_pyramid.controllers.PyramidBase

classmethod add_route(*args, **kwargs)

Declare a route to add it in the configuration of Pyramid

classmethod hook_insert_in_bases(registry, bases)

Define the Core class inherited by Pyramid RPC controllers

  • Core.PyramidBaseRPC
  • super()
Parameters:
  • registry – the current registry for the controller
  • bases – bases list which define the controller
classmethod hook_view_from_decorators(registryname, cls_)

Save the decorated method by rpc method

Parameters:
  • registryname – registry name of the controller
  • cls_ – the cls of the registry name
Return type:

dict {‘views’: {route name: function} }

classmethod rpc_method(**kwargs)

Declare a rpc method to add it in the configuration of Pyramid RPC

class anyblok_pyramid.controllers.PyramidJsonRPC

Bases: anyblok_pyramid.controllers.PyramidRPC

The PyramidJsonRPC controller is a simple wrapper of the Pyramid JSON-RPC controller

At the start of the pyramid server, all routes and all the rpc methods must be known. But the routes and rpc methods are declared on the bloks. Then the declaration of the routes and the rpc methods must be done also if the bloks are not installed. When the controller is called then the rpc method must be validated by the controller to be called

Warning

This case is only use by the script anyblok_wsgi, if you use an another script, you must include the includem pyramid_jsonrpc_config or use the function make_config to get all the configuration

Add a rpc method:

from anyblok import Declarations


@Declarations.register(Declaration.PyramidJsonRPC)
class MyController:

    @Declaration.PyramidJsonRPC.rpc_method()
    def mymethod(request):
        # method name == mymethod
        ...

    @Declaration.PyramidJsonRPC.rpc_method('myroute')
    def myothermethod(request):
        # method name == myroute
        ...

Note

The decorator rpc_method is just a wrapper of add_jsonrpc_method

the args already filled by the wraper are:

  • view: is the decorated method

  • endpoint: the default value is the name of the method or the first

    args

Add a route:

from anyblok import Declarations


Declarations.PyramidJsonRPC.add_route(
    Declarations.PyramidJsonRPC.MyController, '/my/path')

Note

The function add_route is just a wrapper of add_jsonrpc_endpoint

The args already filled by the wraper are:

  • name: is the route name
  • pattern: is the path

Warning

It ‘s important to use the add_route of PyramidJsonRPC, because when the view are add in configuration, this view check is the rpc method exist in the routes.

classmethod hook_insert_in_bases(registry, bases)

Define the Core class inherited by PyramidJsonRPC controllers

  • Core.PyramidBaseJsonRPC
  • super()
Parameters:
  • registry – the current registry for the controller
  • bases – bases list which define the controller
methods = {}

RPC method properties to add in pyramid configuration

routes = []

Route properties to add in pyramid configuration

class anyblok_pyramid.controllers.PyramidXmlRPC

Bases: anyblok_pyramid.controllers.PyramidRPC

The PyramidXmlRPC controller is a simple wrapper of the Pyramid XML-RPC controller

At the start of the pyramid server, all routes and all the rpc methods must be known. But the routes and rpc methods are declared on the bloks. Then the declaration of the routes and the rpc methods must be done also if the bloks are not installed. When the controller is called then the rpc method must be validated by the controller to be called

Warning

This case is only use by the script anyblok_wsgi, if you use an another script, you must include the includem pyramid_xmlrpc_config or use the function make_config to get all the configuration

Add a rpc method:

from anyblok import Declarations


@Declarations.register(Declaration.PyramidXmlRPC)
class MyController:

    @Declaration.PyramidXmlRPC.rpc_method()
    def mymethod(request):
        # method name == mymethod
        ...

    @Declaration.PyramidXmlRPC.rpc_method('myroute')
    def myothermethod(request):
        # method name == myroute
        ...

Note

The decorator rpc_method is just a wrapper of add_xmlrpc_method

the args already filled by the wraper are:

  • view: is the decorated method

  • endpoint: the default value is the name of the method or the first

    args

Add a route:

from anyblok import Declarations


Declarations.PyramidXmlRPC.add_route(
    Declarations.PyramidXmlRPC.MyController, '/my/path')

Note

The function add_route is just a wrapper of add_xmlrpc_endpoint

The args already filled by the wraper are:

  • name: is the route name
  • pattern: is the path

Warning

It ‘s important to use the add_route of PyramidXmlRPC, because when the view are add in configuration, this view check is the rpc method exist in the routes.

classmethod hook_insert_in_bases(registry, bases)

Define the Core class inherited by PyramidXmlRPC controllers

  • Core.PyramidBaseXmlRPC
  • super()
Parameters:
  • registry – the current registry for the controller
  • bases – bases list which define the controller
methods = {}

RPC method properties to add in pyramid configuration

routes = []

Route properties to add in pyramid configuration

anyblok_pyramid.handler

class anyblok_pyramid.handler.Handler

Base class for all the pyramid handler.

call_controller(*args, **kwargs)

call the controller function and return the result

init_controller(request)

Get an instance of the controller

Parameters:request – http request get from pyramid
Return type:instance of Pyramid controller
Exception:HandlerException
class anyblok_pyramid.handler.HandlerHTTP(namespace, view)

Handler for all PyramidHTTP controllers

wrap_view(request)

Call and return the result of wanted controller

Parameters:request – http request got from pyramid
class anyblok_pyramid.handler.HandlerRPC(namespace, method)

Handler for all PyramidRPC controllers

wrap_view(request, *args, **kwargs)

Call and return the result of wanted controller

Parameters:
  • request – http request got from pyramid
  • *args – list of argument for rpc method
  • **kwargs – list of positional argument for rpc method

anyblok_pyramid.config

anyblok_pyramid.config.make_config(settings=<function define_settings>)

Return the configuration for pyramid

anyblok_pyramid.config.declare_static(config)

Pyramid includeme, add the static path of the blok

Parameters:config – the pyramid configuration
anyblok_pyramid.config.pyramid_config(config)

Pyramid includeme, add the route and view which are not added in the blok

Parameters:config – the pyramid configuration
anyblok_pyramid.config.pyramid_http_config(config)

Pyramid includeme, add the route and view which are added in the blok by PyramidHTTP Type

Parameters:config – the pyramid configuration
Exception:PyramidException
anyblok_pyramid.config._pyramid_rpc_config(cls, add_endpoint, add_method)

Add the route and view which are added in the blok

Parameters:
  • cls – PyramidRPC Type
  • add_endpoint – function to add route in configuation
  • add_method – function to add rpc_method in configuration
Exception:

PyramidException

anyblok_pyramid.config.pyramid_jsonrpc_config(config)

Pyramid includeme, add the route and view which are added in the blok by PyramidJsonRPC Type

Parameters:config – the pyramid configuration
anyblok_pyramid.config.pyramid_xmlrpc_config(config)

Pyramid includeme, add the route and view which are added in the blok by PyramidXmlRPC Type

Parameters:config – the pyramid configuration