stamp out paste.httpserver usage
| | |
| | | .. code-block:: python |
| | | :linenos: |
| | | |
| | | from pyramid.response import Response # explicit response objects, no TL |
| | | from paste.httpserver import serve # explicitly WSGI |
| | | from pyramid.response import Response # explicit response, no TL |
| | | from wsgiref.simple_server import make_server # explicitly WSGI |
| | | |
| | | def hello_world(request): # accepts a request; no request thread local reqd |
| | | # explicit response object means no response threadlocal |
| | |
| | | config = Configurator() # no global application object. |
| | | config.add_view(hello_world) # explicit non-decorator registration |
| | | app = config.make_wsgi_app() # explicitly WSGI |
| | | serve(app, host='0.0.0.0') # explicitly WSGI |
| | | server = make_server('0.0.0.0', 8080, app) |
| | | server.serve_forever() # explicitly WSGI |
| | | |
| | | Pyramid Doesn't Offer Pluggable Apps |
| | | ------------------------------------ |
| | |
| | | .. code-block:: python |
| | | :linenos: |
| | | |
| | | from paste.httpserver import serve |
| | | from wsgiref.simple_server import make_server |
| | | from pyramid.config import Configurator |
| | | from pyramid.response import Response |
| | | |
| | |
| | | config = Configurator() |
| | | config.add_view(hello_world) |
| | | app = config.make_wsgi_app() |
| | | serve(app) |
| | | server = make_server('0.0.0.0', 8080, app) |
| | | server.serve_forever() |
| | | |
| | | Pyramid has ~ 650 pages of documentation (printed), covering topics from the |
| | | very basic to the most advanced. *Nothing* is left undocumented, quite |
| | |
| | | .. code-block:: python |
| | | :linenos: |
| | | |
| | | from paste.httpserver import serve |
| | | from wsgiref.simple_server import make_server |
| | | from pyramid.config import Configurator |
| | | from pyramid.response import Response |
| | | |
| | |
| | | config = Configurator() |
| | | config.add_view(hello_world) |
| | | app = config.make_wsgi_app() |
| | | serve(app, host='0.0.0.0') |
| | | server = make_server('0.0.0.0', 8080, app) |
| | | server.serve_forever() |
| | | |
| | | When you start this application, all will be OK. However, what happens if we |
| | | try to add another view to the configuration with the same set of |
| | |
| | | .. code-block:: python |
| | | :linenos: |
| | | |
| | | from paste.httpserver import serve |
| | | from wsgiref.simple_server import make_server |
| | | from pyramid.config import Configurator |
| | | from pyramid.response import Response |
| | | |
| | |
| | | config.add_view(goodbye_world, name='hello') |
| | | |
| | | app = config.make_wsgi_app() |
| | | serve(app, host='0.0.0.0') |
| | | server = make_server('0.0.0.0', 8080, app) |
| | | server.serve_forever() |
| | | |
| | | The application now has two conflicting view configuration statements. When |
| | | we try to start it again, it won't start. Instead, we'll receive a traceback |
| | |
| | | .. code-block:: python |
| | | :linenos: |
| | | |
| | | from paste.httpserver import serve |
| | | from wsgiref.simple_server import make_server |
| | | from pyramid.config import Configurator |
| | | from pyramid.response import Response |
| | | |
| | |
| | | config.add_view(goodbye_world, name='hello') |
| | | |
| | | app = config.make_wsgi_app() |
| | | serve(app, host='0.0.0.0') |
| | | server = make_server('0.0.0.0', 8080, app) |
| | | server.serve_forever() |
| | | |
| | | We can prevent the two ``add_view`` calls from conflicting by issuing a call |
| | | to :meth:`~pyramid.config.Configurator.commit` between them: |
| | |
| | | .. code-block:: python |
| | | :linenos: |
| | | |
| | | from paste.httpserver import serve |
| | | from wsgiref.simple_server import make_server |
| | | from pyramid.config import Configurator |
| | | from pyramid.response import Response |
| | | |
| | |
| | | config.add_view(goodbye_world, name='hello') |
| | | |
| | | app = config.make_wsgi_app() |
| | | serve(app, host='0.0.0.0') |
| | | server = make_server('0.0.0.0', 8080, app) |
| | | server.serve_forever() |
| | | |
| | | In the above example we've issued a call to |
| | | :meth:`~pyramid.config.Configurator.commit` between the two ``add_view`` |
| | |
| | | .. code-block:: python |
| | | :linenos: |
| | | |
| | | from paste.httpserver import serve |
| | | from wsgiref.simple_server import make_server |
| | | from pyramid.config import Configurator |
| | | from pyramid.response import Response |
| | | |
| | |
| | | if __name__ == '__main__': |
| | | config = Configurator() |
| | | config.add_view(hello_world) |
| | | app = config.make_wsgi_app() |
| | | serve(app, host='0.0.0.0') |
| | | server = make_server('0.0.0.0', 8080, app) |
| | | server.serve_forever() |
| | | |
| | | We won't talk much about what this application does yet. Just note that the |
| | | "configuration' statements take place underneath the ``if __name__ == |
| | |
| | | .. code-block:: python |
| | | :linenos: |
| | | |
| | | from paste.httpserver import serve |
| | | from wsgiref.simple_server import make_server |
| | | from pyramid.response import Response |
| | | from pyramid.view import view_config |
| | | |
| | |
| | | config = Configurator() |
| | | config.scan() |
| | | app = config.make_wsgi_app() |
| | | serve(app, host='0.0.0.0') |
| | | server = make_server('0.0.0.0', 8080, app) |
| | | server.serve_forever() |
| | | |
| | | The scanning machinery imports each module and subpackage in a package or |
| | | module recursively, looking for special attributes attached to objects |
| | |
| | | |
| | | Like many other Python web frameworks, :app:`Pyramid` uses the :term:`WSGI` |
| | | protocol to connect an application and a web server together. The |
| | | :mod:`paste.httpserver` server is used in this example as a WSGI server for |
| | | convenience, as the ``paste`` package is a dependency of :app:`Pyramid` |
| | | itself. |
| | | :mod:`wsgiref` server is used in this example as a WSGI server for |
| | | convenience, as it is shipped within the Python standard library. |
| | | |
| | | The script also imports the :class:`pyramid.response.Response` class for |
| | | later use. An instance of this class will be used to create a web response. |
| | |
| | | :lines: 13 |
| | | |
| | | Finally, we actually serve the application to requestors by starting up a |
| | | WSGI server. We happen to use the :func:`paste.httpserver.serve` WSGI server |
| | | runner, passing it the ``app`` object (a :term:`router`) as the application |
| | | we wish to serve. We also pass in an argument ``host='0.0.0.0'``, meaning |
| | | "listen on all TCP interfaces." By default, the HTTP server listens |
| | | only on the ``127.0.0.1`` interface, which is problematic if you're running |
| | | the server on a remote system and you wish to access it with a web browser |
| | | from a local system. We don't specify a TCP port number to listen on; this |
| | | means we want to use the default TCP port, which is 8080. |
| | | WSGI server. We happen to use the :mod:`wsgiref` ``make_server`` server |
| | | maker for this purpose. We pass in as the first argument ``'0.0.0.0'``, |
| | | which means "listen on all TCP interfaces." By default, the HTTP server |
| | | listens only on the ``127.0.0.1`` interface, which is problematic if you're |
| | | running the server on a remote system and you wish to access it with a web |
| | | browser from a local system. We also specify a TCP port number to listen on, |
| | | which is 8080, passing it as the second argument. The final argument ios , |
| | | passing it the ``app`` object (a :term:`router`), which is the the |
| | | application we wish to serve. Finally, we call the server's |
| | | ``serve_forever`` method, which starts the main loop in which it will wait |
| | | for requests from the outside world. |
| | | |
| | | When this line is invoked, it causes the server to start listening on TCP |
| | | port 8080. The server will serve requests forever, or at least until we stop |
| | |
| | | .. code-block:: python |
| | | :linenos: |
| | | |
| | | from paste.httpserver import serve |
| | | from wsgiref.simple_server import make_server |
| | | from pyramid.config import Configurator |
| | | from mypackage.interfaces import IMyUtility |
| | | |
| | |
| | | config.registry.registerUtility(UtilityImplementation()) |
| | | config.scan() |
| | | app = config.make_wsgi_app() |
| | | serve(app, host='0.0.0.0') |
| | | server = make_server('0.0.0.0', 8080, app) |
| | | server.serve_forever() |
| | | |
| | | For full details, please read the `Venusian documentation |
| | | <http://docs.repoze.org/venusian>`_. |