~ubuntu-branches/ubuntu/hardy/pastedeploy/hardy

« back to all changes in this revision

Viewing changes to paste/deploy/interfaces.py

  • Committer: Bazaar Package Importer
  • Author(s): Piotr Ozarowski
  • Date: 2006-05-14 03:27:56 UTC
  • Revision ID: james.westby@ubuntu.com-20060514032756-qqd7u23ijat2ccbf
Tags: upstream-0.5
ImportĀ upstreamĀ versionĀ 0.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
############################################################
 
2
## Functions
 
3
############################################################
 
4
 
 
5
def loadapp(uri, name=None, relative_to=None, global_conf=None):
 
6
    """
 
7
    Provided by ``paste.deploy.loadapp``.
 
8
    
 
9
    Load the specified URI as a WSGI application (returning IWSGIApp).
 
10
    The ``name`` can be in the URI (typically as ``#name``).  If it is
 
11
    and ``name`` is given, the keyword argument overrides the URI.
 
12
 
 
13
    If the URI contains a relative filename, then ``relative_to`` is
 
14
    used (if ``relative_to`` is not provided, then it is an error).
 
15
 
 
16
    ``global_conf`` is used to load the configuration (additions
 
17
    override the values).  ``global_conf`` is copied before modifying.
 
18
    """
 
19
 
 
20
def loadfilter(uri, name=None, relative_to=None, global_conf=None):
 
21
    """
 
22
    Provided by ``paste.deploy.loadfilter``.
 
23
 
 
24
    Like ``loadapp()``, except returns in IFilter object.
 
25
    """
 
26
 
 
27
def loadserver(uri, name=None, relative_to=None, global_conf=None):
 
28
    """
 
29
    Provided by ``paste.deploy.loadserver``.
 
30
 
 
31
    Like ``loadapp()``, except returns in IServer object.
 
32
    """
 
33
 
 
34
############################################################
 
35
## Factories
 
36
############################################################
 
37
 
 
38
class IPasteAppFactory:
 
39
 
 
40
    """
 
41
    This is the spec for the ``paste.app_factory``
 
42
    protocol/entry_point.
 
43
    """
 
44
 
 
45
    def __call__(global_conf, **local_conf):
 
46
        """
 
47
        Returns a WSGI application (IWSGIAPP) given the global
 
48
        configuration and the local configuration passed in as keyword
 
49
        arguments.
 
50
 
 
51
        All keys are strings, but values in local_conf may not be
 
52
        valid Python identifiers (if you use ``**kw`` you can still
 
53
        capture these values).
 
54
        """
 
55
 
 
56
class IPasteCompositFactory:
 
57
 
 
58
    """
 
59
    This is the spec for the ``paste.composit_factory``
 
60
    protocol/entry_point.
 
61
 
 
62
    This also produces WSGI applications, like ``paste.app_factory``,
 
63
    but is given more access to the context in which it is loaded.
 
64
    """
 
65
 
 
66
    def __call__(loader, global_conf, **local_conf):
 
67
        """
 
68
        Like IPasteAppFactory this returns a WSGI application
 
69
        (IWSGIApp).  The ``loader`` value conforms to the ``ILoader``
 
70
        interface, and can be used to load (contextually) more
 
71
        applications.
 
72
        """
 
73
 
 
74
class IPasteFilterFactory:
 
75
 
 
76
    """
 
77
    This is the spec for the ``paste.filter_factory``
 
78
    protocol/entry_point.
 
79
    """
 
80
 
 
81
    def __call__(global_conf, **local_conf):
 
82
        """
 
83
        Returns a IFilter object.
 
84
        """
 
85
 
 
86
class IPasteFilterAppFactory:
 
87
 
 
88
    """
 
89
    This is the spec for the ``paste.filter_app_factory``
 
90
    protocol/entry_point.
 
91
    """
 
92
    
 
93
    def __call__(wsgi_app, global_conf, **local_conf):
 
94
        """
 
95
        Returns a WSGI application that wraps ``wsgi_app``.
 
96
 
 
97
        Note that paste.deploy creates a wrapper for these
 
98
        objects that implement the IFilter interface.
 
99
        """
 
100
 
 
101
class IPasteServerFactory:
 
102
 
 
103
    """
 
104
    This is the spec for the ``paste.server_factory``
 
105
    protocol/entry_point.
 
106
    """
 
107
 
 
108
    def __call__(global_conf, **local_conf):
 
109
        """
 
110
        Returns a IServer object.
 
111
        """
 
112
 
 
113
class IPasteServerRunner:
 
114
 
 
115
    """
 
116
    This is the spec for the ``paste.server_runner``
 
117
    protocol/entry_point.
 
118
    """
 
119
 
 
120
    def __call__(wsgi_app, global_conf, **local_conf):
 
121
        """
 
122
        Serves the given WSGI application.  May serve once, many
 
123
        times, forever; nothing about how the server works is
 
124
        specified here.
 
125
 
 
126
        Note that paste.deploy creates a wrapper for these
 
127
        objects that implement the IServer interface.
 
128
        """
 
129
 
 
130
class ILoader:
 
131
 
 
132
    """
 
133
    This is an object passed into ``IPasteCompositFactory``.  It is
 
134
    currently implemented in ``paste.deploy.loadwsgi`` by
 
135
    ``ConfigLoader`` and ``EggLoader``.
 
136
    """
 
137
 
 
138
    def get_app(name_or_uri, global_conf=None):
 
139
        """
 
140
        Return an IWSGIApp object.  If the loader supports named
 
141
        applications, then you can use a simple name; otherwise
 
142
        you must use a full URI.
 
143
 
 
144
        Any global configuration you pass in will be added; you should
 
145
        generally pass through the global configuration you received.
 
146
        """
 
147
 
 
148
    def get_filter(name_or_uri, global_conf=None):
 
149
        """
 
150
        Return an IFilter object, like ``get_app``.
 
151
        """
 
152
                   
 
153
    def get_server(name_or_uri, global_conf=None):
 
154
        """
 
155
        Return an IServer object, like ``get_app``.
 
156
        """
 
157
 
 
158
############################################################
 
159
## Objects
 
160
############################################################
 
161
 
 
162
class IWSGIApp:
 
163
 
 
164
    """
 
165
    This is an application that conforms to `PEP 333
 
166
    <http://www.python.org/peps/pep-0333.html>`_: Python Web Server
 
167
    Gateway Interface v1.0
 
168
    """
 
169
 
 
170
    def __call__(environ, start_response):
 
171
        """
 
172
        Calls ``start_response(status_code, header_list)`` and returns
 
173
        an iterator for the body of the response.
 
174
        """
 
175
 
 
176
class IFilter:
 
177
 
 
178
    """
 
179
    A filter is a simple case of middleware, where an object
 
180
    wraps a single WSGI application (IWSGIApp).
 
181
    """
 
182
 
 
183
    def __call__(wsgi_app):
 
184
        """
 
185
        Returns an IWSGIApp object, typically one that wraps the
 
186
        ``wsgi_app`` passed in.
 
187
        """
 
188
 
 
189
class IServer:
 
190
 
 
191
    """
 
192
    A simple server interface.
 
193
    """
 
194
 
 
195
    def __call__(wsgi_app):
 
196
        """
 
197
        Serves the given WSGI application.  May serve once, many
 
198
        times, forever; nothing about how the server works is
 
199
        specified here.
 
200
        """