From 546378295e3971b2f4b84971c35bbe290a2d2ec5 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Mon, 3 Jul 2017 20:28:01 -0700 Subject: Link context manager term to glossary --- docs/narr/testing.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/narr') diff --git a/docs/narr/testing.rst b/docs/narr/testing.rst index f124ac562..594badcb6 100644 --- a/docs/narr/testing.rst +++ b/docs/narr/testing.rst @@ -158,7 +158,7 @@ Test setup using a context manager ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ An alternative style of setting up a test configuration is to use the ``with`` -statement and :func:`pyramid.testing.testConfig` to create a context manager. +statement and :func:`pyramid.testing.testConfig` to create a :term:`context manager`. The context manager will call :func:`pyramid.testing.setUp` before the code under test and :func:`pyramid.testing.tearDown` afterwards. -- cgit v1.2.3 From e2c59262a9784cd227c1ca99ab11878cfd44e746 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Mon, 3 Jul 2017 20:47:07 -0700 Subject: Update example apps to use config context manager --- docs/narr/configuration.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'docs/narr') diff --git a/docs/narr/configuration.rst b/docs/narr/configuration.rst index ee54e3acd..bbf01240e 100644 --- a/docs/narr/configuration.rst +++ b/docs/narr/configuration.rst @@ -47,9 +47,9 @@ configured imperatively: return Response('Hello world!') if __name__ == '__main__': - config = Configurator() - config.add_view(hello_world) - app = config.make_wsgi_app() + with Configurator() as config: + config.add_view(hello_world) + app = config.make_wsgi_app() server = make_server('0.0.0.0', 8080, app) server.serve_forever() @@ -116,9 +116,9 @@ and its subpackages. For example: return Response('Hello') if __name__ == '__main__': - config = Configurator() - config.scan() - app = config.make_wsgi_app() + with Configurator() as config: + config.scan() + app = config.make_wsgi_app() server = make_server('0.0.0.0', 8080, app) server.serve_forever() -- cgit v1.2.3 From 0fc3b3aecf7411e2fec59f67d6c5be432bed4f60 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Mon, 3 Jul 2017 20:58:55 -0700 Subject: Use lineno-match instead of linenos --- docs/narr/firstapp.rst | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'docs/narr') 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 -- cgit v1.2.3 From b6937e32be59a214bac5a8097bf5b200eb7b5ac8 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Mon, 3 Jul 2017 20:59:01 -0700 Subject: Update example apps to use config context manager --- docs/narr/helloworld.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'docs/narr') diff --git a/docs/narr/helloworld.py b/docs/narr/helloworld.py index c01329af9..29ed8e6f2 100644 --- a/docs/narr/helloworld.py +++ b/docs/narr/helloworld.py @@ -7,10 +7,9 @@ def hello_world(request): return Response('Hello %(name)s!' % request.matchdict) if __name__ == '__main__': - config = Configurator() - config.add_route('hello', '/hello/{name}') - config.add_view(hello_world, route_name='hello') - app = config.make_wsgi_app() + with Configurator() as config: + config.add_route('hello', '/hello/{name}') + config.add_view(hello_world, route_name='hello') + app = config.make_wsgi_app() server = make_server('0.0.0.0', 8080, app) server.serve_forever() - -- cgit v1.2.3