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