blob: 3cbafa0103d48a39d138ad3a165b4ecfb53e7870 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
.. index::
single: introspection
single: introspector
.. _using_introspection:
Pyramid Configuration Introspection
===================================
When Pyramid starts up, each call to a :term:`configuration directive` causes
one or more :term:`introspectable` objects to be registered with an
:term:`introspector`. This introspector can be queried by application code
to obtain information about the configuration of the running application.
This feature is useful for debug toolbars, command-line scripts which show
some aspect of configuration, and for runtime reporting of startup-time
configuration settings.
Using the Introspector
----------------------
Here's an example of using Pyramid's introspector:
.. code-block:: python
:linenos:
from pyramid.view import view_config
from pyramid.response import Response
@view_config(route_name='foo')
@view_config(route_name='bar')
def route_accepts(request):
introspector = request.registry.introspector
route_name = request.matched_route.name
route_intr = introspector.get('routes', route_name)
return Response(str(route_intr['accept']))
This view will return a response that contains the "accept" argument provided
to the ``add_route`` method of the route which matched when the view was
called. It used the :meth:`pyramid.interfaces.IIntrospector.get` method to
return an introspectable in the category ``routes`` with a
:term:`discriminator` equal to the matched route name. It then used the
returned introspectable to obtain an "accept" value.
The introspector has a number of other query-related methods: see
:class:`pyramid.interfaces.IIntrospector` for more information. The
introspectable returned by the query methods of the introspector has methods
and attributes described by :class:`pyramid.interfaces.IIntrospectable`.
Concrete Introspection Categories
---------------------------------
This is a list of concrete introspection categories provided by Pyramid.
``subscribers``
``response adapters``
``asset overrides``
``root factories``
``session factory``
``request factory``
``locale negotiator``
``translation directories``
``renderer factories``
``routes``
``authentication policy``
``authorization policy``
``default permission``
``tweens (implicit)``
``views``
``templates``
``permissions``
``view mapper``
|