summaryrefslogtreecommitdiff
path: root/repoze/bfg/interfaces.py
blob: 71ef619c25f72026aaa5c0c6bb976c0a5a1bb254 (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
from zope.interface import Interface
from zope.interface import Attribute
from zope.deprecation import deprecated

from zope.component.interfaces import IObjectEvent

class IRequest(Interface):
    """ Marker interface for a request object """
    
class IResponse(Interface):
    status = Attribute('WSGI status code of response')
    headerlist = Attribute('List of response headers')
    app_iter = Attribute('Iterable representing the response body')

class IView(Interface):
    def __call__(context, request):
        """ Must return an object that implements IResponse """

class IRootPolicy(Interface):
    def __call__(environ):
        """ Return a root object """

class ITraverser(Interface):
    def __call__(environ):
        """ Return a tuple in the form (context, name, subpath), typically
        the result of an object graph traversal """

class ITraverserFactory(Interface):
    def __call__(context):
        """ Return an object that implements ITraverser """

class ITemplateRenderer(Interface):
    def implementation():
        """ Return the object that the underlying templating system
        uses to render the template; it is typically a callable that
        accepts arbitrary keyword arguments and returns a string or
        unicode object """

    def __call__(**kw):
        """ Call a the template implementation with the keywords
        passed in as arguments and return the result (a string or
        unicode object) """

class ITestingTemplateRenderer(Interface):
    def __call__(**kw):
        """ Accept keywords and process for test comparison purposes
        (usually set all keywords as attributes of self); return value
        is a string """

class ITemplateRendererFactory(Interface):
    def __call__(path, auto_reload=False):
        """ Return an object that implements ``ITemplateRenderer``  """

class INodeTemplateRenderer(Interface):
    def __call__(node, **kw):
        """ Return a string result given a node and a template path """

ITemplate = ITemplateRenderer
deprecated('ITemplate',
           ('repoze.bfg.interfaces.ITemplate should now be imported '
            'as repoze.bfg.interfaces.ITemplateRenderer'))
INodeTemplate = INodeTemplateRenderer
deprecated('INodeTemplate',
           ('repoze.bfg.interfaces.INodeTemplate should now be imported '
            'as repoze.bfg.interfaces.INodeTemplateRenderer'))
ITemplateFactory = ITemplateRendererFactory
deprecated('ITemplateFactory',
           ('repoze.bfg.interfaces.ITemplateFactory should now be imported '
            'as repoze.bfg.interfaces.ITemplateRendererFactory'))

class ISecurityPolicy(Interface):
    """ A utility that provides a mechanism to check authorization
       using authentication data """
    def permits(context, request, permission):
        """ Returns True if the combination of the authorization
        information in the context and the authentication data in
        the request allow the action implied by the permission """

    def authenticated_userid(request):
        """ Return the userid of the currently authenticated user or
        None if there is no currently authenticated user """

    def effective_principals(request):
        """ Return the list of 'effective' principals for the request.
        This must include the userid of the currently authenticated
        user if a user is currently authenticated."""

    def principals_allowed_by_permission(context, permission):
        """ Return a sequence of principal identifiers allowed by the
        ``permission`` in the model implied by ``context``.  This
        method may not be supported by a given security policy
        implementation, in which case, it should raise a
        ``NotImplementedError`` exception."""

class NoAuthorizationInformation(Exception):
    pass

class IViewPermission(Interface):
    def __call__(security_policy):
        """ Return True if the permission allows, return False if it denies. """

class IViewPermissionFactory(Interface):
    def __call__(context, request):
        """ Return an IViewPermission """

class IRouter(Interface):
    """WSGI application which routes requests to 'view' code based on
    a view registry."""

    registry = Attribute(
        """Component architecture registry local to this application.""")
    
class IRoutesContext(Interface):
    """ A context (model instance) that is created as a result of URL
    dispatching"""

class INewRequest(Interface):
    """ An event type that is emitted whenever repoze.bfg begins to
    process a new request """
    request = Attribute('The request object')
    
class INewResponse(Interface):
    """ An event type that is emitted whenever any repoze.bfg view
    returns a response."""
    response = Attribute('The response object')

class ISettings(Interface):
    """ Runtime settings for repoze.bfg """
    reload_templates = Attribute('Reload templates when they change')
    
class IWSGIApplicationCreatedEvent(IObjectEvent):
    """ Event issued after the application has been created and
    configured."""
    
    app = Attribute(u"Published application")

class ILocation(Interface):
    """Objects that have a structural location"""

    __parent__ = Attribute("The parent in the location hierarchy")

    __name__ = Attribute("The name within the parent")

class ILogger(Interface):
    """ Interface representing a PEP 282 logger """