diff options
| author | Michael Merickel <michael@merickel.org> | 2017-07-12 20:06:48 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-07-12 20:06:48 -0500 |
| commit | d45f41f7423ef9064b827ef4d4d72bd41fd875f9 (patch) | |
| tree | b348ca6562eb1c80ea1baacdc0481ee6e95731b7 /docs/narr/firstapp.rst | |
| parent | b8658e94f00962a78e3f8a4c97dd4fbc9e440a31 (diff) | |
| parent | 0958d268b4b5451c615e05b2b4657d2afb5a7cd4 (diff) | |
| download | pyramid-d45f41f7423ef9064b827ef4d4d72bd41fd875f9.tar.gz pyramid-d45f41f7423ef9064b827ef4d4d72bd41fd875f9.tar.bz2 pyramid-d45f41f7423ef9064b827ef4d4d72bd41fd875f9.zip | |
Merge pull request #3119 from stevepiercy/docs-context-manager
Update docs to use a Configurator context manager
Diffstat (limited to 'docs/narr/firstapp.rst')
| -rw-r--r-- | docs/narr/firstapp.rst | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/docs/narr/firstapp.rst b/docs/narr/firstapp.rst index 63142edac..db55f2f9c 100644 --- a/docs/narr/firstapp.rst +++ b/docs/narr/firstapp.rst @@ -60,7 +60,7 @@ Imports The above ``helloworld.py`` script uses the following set of import statements: .. literalinclude:: helloworld.py - :linenos: + :lineno-match: :lines: 1-3 The script imports the :class:`~pyramid.config.Configurator` class from the @@ -83,7 +83,7 @@ The above script, beneath its set of imports, defines a function named ``hello_world``. .. literalinclude:: helloworld.py - :linenos: + :lineno-match: :pyobject: hello_world The function accepts a single argument (``request``) and it returns an instance @@ -125,7 +125,7 @@ imports and function definitions, placed within the confines of an ``if`` statement: .. literalinclude:: helloworld.py - :linenos: + :lineno-match: :lines: 9-15 Let's break this down piece by piece. @@ -134,7 +134,7 @@ Configurator Construction ~~~~~~~~~~~~~~~~~~~~~~~~~ .. literalinclude:: helloworld.py - :linenos: + :lineno-match: :lines: 9-10 The ``if __name__ == '__main__':`` line in the code sample above represents a @@ -153,8 +153,8 @@ code within the ``if`` statement to execute if this module is imported from another; the code within the ``if`` block should only be run during a direct script execution. -The ``config = Configurator()`` line above creates an instance of the -:class:`~pyramid.config.Configurator` class. The resulting ``config`` object +The ``with Configurator() as config:`` line above creates an instance of the +:class:`~pyramid.config.Configurator` class using a :term:`context manager`. The resulting ``config`` object represents an API which the script uses to configure this particular :app:`Pyramid` application. Methods called on the Configurator will cause registrations to be made in an :term:`application registry` associated with the @@ -166,7 +166,7 @@ Adding Configuration ~~~~~~~~~~~~~~~~~~~~ .. literalinclude:: helloworld.py - :linenos: + :lineno-match: :lines: 11-12 The first line above calls the :meth:`pyramid.config.Configurator.add_route` @@ -185,7 +185,7 @@ WSGI Application Creation ~~~~~~~~~~~~~~~~~~~~~~~~~ .. literalinclude:: helloworld.py - :linenos: + :lineno-match: :lines: 13 After configuring views and ending configuration, the script creates a WSGI @@ -212,7 +212,7 @@ WSGI Application Serving ~~~~~~~~~~~~~~~~~~~~~~~~ .. literalinclude:: helloworld.py - :linenos: + :lineno-match: :lines: 14-15 Finally, we actually serve the application to requestors by starting up a WSGI |
