pyramid.scripting¶
- get_root(app, request=None)[source]¶
Return a tuple composed of
(root, closer)when provided a router instance as theappargument. Therootreturned is the application root object. Thecloserreturned is a callable (accepting no arguments) that should be called when your scripting application is finished using the root.requestis passed to the Pyramid application root factory to compute the root. Ifrequestis None, a default will be constructed using the registry's Request Factory via thepyramid.interfaces.IRequestFactory.blank()method.
- prepare(request=None, registry=None)[source]¶
This function pushes data onto the Pyramid threadlocal stack (request and registry), making those objects 'current'. It returns a dictionary useful for bootstrapping a Pyramid application in a scripting environment.
requestis passed to the Pyramid application root factory to compute the root. Ifrequestis None, a default will be constructed using the registry's Request Factory via thepyramid.interfaces.IRequestFactory.blank()method.If
registryis not supplied, the last registry loaded frompyramid.config.global_registrieswill be used. If you have loaded more than one Pyramid application in the current process, you may not want to use the last registry loaded, thus you can search theglobal_registriesand supply the appropriate one based on your own criteria.The function returns a dictionary composed of
root,closer,registry,requestandroot_factory. Therootreturned is the application's root resource object. Thecloserreturned is a callable (accepting no arguments) that should be called when your scripting application is finished using the root.registryis the resolved registry object.requestis the request object passed or the constructed request if no request is passed.root_factoryis the root factory used to construct the root.This function may be used as a context manager to call the
closerautomatically:registry = config.registry with prepare(registry) as env: request = env['request'] # ...
Changed in version 1.8: Added the ability to use the return value as a context manager.
Changed in version 2.0: Request finished callbacks added via
pyramid.request.Request.add_finished_callback()will be invoked by thecloser.