Contents
AnyBlok / Pyramid framework¶
AnyBlok / Pyramid controllers¶
-
exception
anyblok_pyramid.controllers.
PyramidException
Bases:
Exception
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 theroute
have to add directlly in the configuration. This controller do all of them. Theroute
andview
are saved in the controller and the controller add them in the configuration at the start of the wsgi serverWarning
This case is only use by the script
anyblok_wsgi
, if you use an another script, you must include the includemepyramid_config
or use the functionmake_config
to get all the configurationThis
Type
is not an entry, no class are assembled in the registry. You must not add any class of thisType
, the methodsregister
andunregister
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_viewthe 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_routeThe 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_routeThe 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_viewthe 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
unload_callback
() Clear known routes and known views
-
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
- entry – entry declaration of the model where the
-
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
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
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
- entry – entry declaration of the model where the
-
classmethod
-
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 includemepyramid_http_config
or use the functionmake_config
to get all the configurationAdd 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_viewthe 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_routeThe 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_routeThe 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
unload_callback
() Clear known routes and known views
-
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_viewthe 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
-
classmethod
-
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 includemepyramid_jsonrpc_config
or use the functionmake_config
to get all the configurationAdd 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_methodthe 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_endpointThe 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
-
classmethod
unload_callback
() Clear known routes and known methods
-
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 includemepyramid_xmlrpc_config
or use the functionmake_config
to get all the configurationAdd 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_methodthe 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_endpointThe 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
-
classmethod
unload_callback
() Clear known routes and known methods
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.pyramid_config¶
-
class
anyblok_pyramid.pyramid_config.
Configurator
(*args, **kwargs) Bases:
pyramid.config.Configurator
Overwrite the Pyramid Configurator
-
default_setting
() Call all the entry point
anyblok_pyramid.settings
to update the argument settingthe callable need to have one parametter, it is a dict:
def settings_callable(setting): ...
We add the entry point by the setup file:
setup( ..., entry_points={ 'anyblok_pyramid.settings': [ settings_callable=path:settings_callable, ... ], }, ..., )
-
include_from_entry_point
() Call all the entry point
anyblok_pyramid.includeme
to update the pyramid configurationthe callable need to have one parametter(the instance of
Configurator
class, self):def config_callable(config): config.include(...)
We add the entry point by the setup file:
setup( ..., entry_points={ 'anyblok_pyramid.includeme': [ config_callable=path:config_callable, ... ], }, ..., )
-
pyramid_config.settings¶
-
anyblok_pyramid.pyramid_config.
pyramid_settings
(settings) Add in settings the default value for pyramid configuration
Parameters: settings – dict of the existing settings
-
anyblok_pyramid.pyramid_config.
beaker_settings
(settings) Add in settings the default value for beaker configuration
Parameters: settings – dict of the existing settings
pyramid_config.includeme¶
-
anyblok_pyramid.pyramid_config.
pyramid_beaker
(config) Add beaker includeme in pyramid configuration
Parameters: config – Pyramid configurator instance
-
anyblok_pyramid.pyramid_config.
declare_static
(config) Pyramid includeme, add the static path of the blok
Parameters: config – Pyramid configurator instance
-
anyblok_pyramid.pyramid_config.
pyramid_config
(config) Pyramid includeme, add the route and view which are not added in the blok
Parameters: config – Pyramid configurator instance
-
anyblok_pyramid.pyramid_config.
pyramid_http_config
(config) Pyramid includemee, add the route and view which are added in the blok by
PyramidHTTP
TypeParameters: config – Pyramid configurator instance Exception: PyramidException
-
anyblok_pyramid.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.pyramid_config.
pyramid_jsonrpc_config
(config) Pyramid includemee, add the route and view which are added in the blok by
PyramidJsonRPC
TypeParameters: config – Pyramid configurator instance
-
anyblok_pyramid.pyramid_config.
pyramid_xmlrpc_config
(config) Pyramid includemee, add the route and view which are added in the blok by
PyramidXmlRPC
TypeParameters: config – Pyramid configurator instance
anyblok_pyramid.scripts module¶
-
anyblok_pyramid.scripts.
anyblok_wsgi
(application, configuration_groups, **kwargs) Parameters: - application – name of the application
- configuration_groups – list configuration groupe to load
- **kwargs – ArgumentParser named arguments