summaryrefslogtreecommitdiff
path: root/paste/deploy/interfaces.py
blob: 3dbc44e218f9c56f81358214fb68dbd5f5110fb7 (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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org)
# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php

############################################################
## Functions
############################################################


def loadapp(uri, name=None, relative_to=None, global_conf=None):
    """
    Provided by ``paste.deploy.loadapp``.

    Load the specified URI as a WSGI application (returning IWSGIApp).
    The ``name`` can be in the URI (typically as ``#name``).  If it is
    and ``name`` is given, the keyword argument overrides the URI.

    If the URI contains a relative filename, then ``relative_to`` is
    used (if ``relative_to`` is not provided, then it is an error).

    ``global_conf`` is used to load the configuration (additions
    override the values).  ``global_conf`` is copied before modifying.
    """


def loadfilter(uri, name=None, relative_to=None, global_conf=None):
    """
    Provided by ``paste.deploy.loadfilter``.

    Like ``loadapp()``, except returns in IFilter object.
    """


def loadserver(uri, name=None, relative_to=None, global_conf=None):
    """
    Provided by ``paste.deploy.loadserver``.

    Like ``loadapp()``, except returns in IServer object.
    """


############################################################
## Factories
############################################################


class IPasteAppFactory(object):

    """
    This is the spec for the ``paste.app_factory``
    protocol/entry_point.
    """

    def __call__(global_conf, **local_conf):
        """
        Returns a WSGI application (IWSGIAPP) given the global
        configuration and the local configuration passed in as keyword
        arguments.

        All keys are strings, but values in local_conf may not be
        valid Python identifiers (if you use ``**kw`` you can still
        capture these values).
        """


class IPasteCompositFactory(object):

    """
    This is the spec for the ``paste.composit_factory``
    protocol/entry_point.

    This also produces WSGI applications, like ``paste.app_factory``,
    but is given more access to the context in which it is loaded.
    """

    def __call__(loader, global_conf, **local_conf):
        """
        Like IPasteAppFactory this returns a WSGI application
        (IWSGIApp).  The ``loader`` value conforms to the ``ILoader``
        interface, and can be used to load (contextually) more
        applications.
        """


class IPasteFilterFactory(object):

    """
    This is the spec for the ``paste.filter_factory``
    protocol/entry_point.
    """

    def __call__(global_conf, **local_conf):
        """
        Returns a IFilter object.
        """


class IPasteFilterAppFactory(object):

    """
    This is the spec for the ``paste.filter_app_factory``
    protocol/entry_point.
    """

    def __call__(wsgi_app, global_conf, **local_conf):
        """
        Returns a WSGI application that wraps ``wsgi_app``.

        Note that paste.deploy creates a wrapper for these
        objects that implement the IFilter interface.
        """


class IPasteServerFactory(object):

    """
    This is the spec for the ``paste.server_factory``
    protocol/entry_point.
    """

    def __call__(global_conf, **local_conf):
        """
        Returns a IServer object.
        """


class IPasteServerRunner(object):

    """
    This is the spec for the ``paste.server_runner``
    protocol/entry_point.
    """

    def __call__(wsgi_app, global_conf, **local_conf):
        """
        Serves the given WSGI application.  May serve once, many
        times, forever; nothing about how the server works is
        specified here.

        Note that paste.deploy creates a wrapper for these
        objects that implement the IServer interface.
        """


class ILoader(object):

    """
    This is an object passed into ``IPasteCompositFactory``.  It is
    currently implemented in ``paste.deploy.loadwsgi`` by
    ``ConfigLoader`` and ``EggLoader``.
    """

    def get_app(name_or_uri, global_conf=None):
        """
        Return an IWSGIApp object.  If the loader supports named
        applications, then you can use a simple name; otherwise
        you must use a full URI.

        Any global configuration you pass in will be added; you should
        generally pass through the global configuration you received.
        """

    def get_filter(name_or_uri, global_conf=None):
        """
        Return an IFilter object, like ``get_app``.
        """

    def get_server(name_or_uri, global_conf=None):
        """
        Return an IServer object, like ``get_app``.
        """


############################################################
## Objects
############################################################


class IWSGIApp(object):

    """
    This is an application that conforms to `PEP 333
    <http://www.python.org/peps/pep-0333.html>`_: Python Web Server
    Gateway Interface v1.0
    """

    def __call__(environ, start_response):
        """
        Calls ``start_response(status_code, header_list)`` and returns
        an iterator for the body of the response.
        """


class IFilter(object):

    """
    A filter is a simple case of middleware, where an object
    wraps a single WSGI application (IWSGIApp).
    """

    def __call__(wsgi_app):
        """
        Returns an IWSGIApp object, typically one that wraps the
        ``wsgi_app`` passed in.
        """


class IServer(object):

    """
    A simple server interface.
    """

    def __call__(wsgi_app):
        """
        Serves the given WSGI application.  May serve once, many
        times, forever; nothing about how the server works is
        specified here.
        """