Chris McDonough
2011-12-16 10f1b5c35072c5499f3504dc261fb3c67a90c70d
stamp out paste.httpserver usage
5 files modified
72 ■■■■■ changed files
docs/designdefense.rst 12 ●●●●● patch | view | raw | blame | history
docs/narr/advconfig.rst 20 ●●●●● patch | view | raw | blame | history
docs/narr/configuration.rst 11 ●●●● patch | view | raw | blame | history
docs/narr/firstapp.rst 24 ●●●● patch | view | raw | blame | history
docs/narr/hooks.rst 5 ●●●●● patch | view | raw | blame | history
docs/designdefense.rst
@@ -1628,8 +1628,8 @@
.. 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
@@ -1640,7 +1640,8 @@
       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
------------------------------------
@@ -1736,7 +1737,7 @@
.. 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
@@ -1747,7 +1748,8 @@
       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
docs/narr/advconfig.rst
@@ -27,7 +27,7 @@
.. 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
@@ -38,7 +38,8 @@
       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
@@ -47,7 +48,7 @@
.. 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
@@ -66,7 +67,8 @@
       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
@@ -170,7 +172,7 @@
.. 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
@@ -189,7 +191,8 @@
       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:
@@ -197,7 +200,7 @@
.. 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
@@ -218,7 +221,8 @@
       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``
docs/narr/configuration.rst
@@ -36,7 +36,7 @@
.. 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
@@ -46,8 +46,8 @@
   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__ ==
@@ -105,7 +105,7 @@
   .. 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
     
@@ -118,7 +118,8 @@
          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
docs/narr/firstapp.rst
@@ -54,9 +54,8 @@
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.
@@ -205,14 +204,17 @@
   :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
docs/narr/hooks.rst
@@ -812,7 +812,7 @@
.. 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
@@ -831,7 +831,8 @@
       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>`_.