From 614f00c88733b5248922e2b610c96f7c8c3ff57c Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Fri, 19 Nov 2010 22:28:50 -0500 Subject: - Remove calls to config.begin()/config.end() from startup config code in tutorials and paster templates (no longer required). --- docs/narr/MyProject/myproject/__init__.py | 3 -- docs/narr/configuration.rst | 18 +++----- docs/narr/firstapp.rst | 49 ---------------------- docs/narr/project.rst | 8 ++-- docs/narr/unittesting.rst | 2 +- docs/tutorials/wiki/basiclayout.rst | 9 ++-- .../wiki/src/authorization/tutorial/__init__.py | 2 - .../wiki/src/basiclayout/tutorial/__init__.py | 2 - .../tutorials/wiki/src/models/tutorial/__init__.py | 2 - .../wiki/src/viewdecorators/tutorial/__init__.py | 2 - docs/tutorials/wiki/src/views/tutorial/__init__.py | 2 - docs/tutorials/wiki2/basiclayout.rst | 12 ++---- .../wiki2/src/authorization/tutorial/__init__.py | 2 - .../wiki2/src/basiclayout/tutorial/__init__.py | 2 - .../wiki2/src/models/tutorial/__init__.py | 2 - .../tutorials/wiki2/src/views/tutorial/__init__.py | 2 - 16 files changed, 17 insertions(+), 102 deletions(-) (limited to 'docs') diff --git a/docs/narr/MyProject/myproject/__init__.py b/docs/narr/MyProject/myproject/__init__.py index bfbbfd4df..580dfe546 100644 --- a/docs/narr/MyProject/myproject/__init__.py +++ b/docs/narr/MyProject/myproject/__init__.py @@ -5,11 +5,8 @@ def main(global_config, **settings): """ This function returns a Pyramid WSGI application. """ config = Configurator(root_factory=get_root, settings=settings) - config.begin() config.add_view('myproject.views.my_view', context='myproject.models.MyModel', renderer='myproject:templates/mytemplate.pt') config.add_static_view('static', 'myproject:static') - config.end() return config.make_wsgi_app() - diff --git a/docs/narr/configuration.rst b/docs/narr/configuration.rst index 6a91cbf75..ae02a5a6c 100644 --- a/docs/narr/configuration.rst +++ b/docs/narr/configuration.rst @@ -47,20 +47,16 @@ imperatively: if __name__ == '__main__': config = Configurator() - config.begin() config.add_view(hello_world) - config.end() app = config.make_wsgi_app() serve(app, host='0.0.0.0') -We won't talk much about what this application does yet. Just note -that the "configuration' statements take place underneath the ``if -__name__ == '__main__':`` stanza in the form of method calls on a -:term:`Configurator` object (e.g. ``config.begin()``, -``config.add_view(...)``, and ``config.end()``. These statements take -place one after the other, and are executed in order, so the full -power of Python, including conditionals, can be employed in this mode -of configuration. +We won't talk much about what this application does yet. Just note that the +"configuration' statements take place underneath the ``if __name__ == +'__main__':`` stanza in the form of method calls on a :term:`Configurator` +object (e.g. ``config.add_view(...)``). These statements take place one +after the other, and are executed in order, so the full power of Python, +including conditionals, can be employed in this mode of configuration. .. index:: single: view_config @@ -123,9 +119,7 @@ and its subpackages. For example: if __name__ == '__main__': from pyramid.configuration import Configurator config = Configurator() - config.begin() config.scan() - config.end() app = config.make_wsgi_app() serve(app, host='0.0.0.0') diff --git a/docs/narr/firstapp.rst b/docs/narr/firstapp.rst index bc21bf29f..9d3cad13c 100644 --- a/docs/narr/firstapp.rst +++ b/docs/narr/firstapp.rst @@ -38,10 +38,8 @@ configured imperatively: if __name__ == '__main__': config = Configurator() - config.begin() config.add_view(hello_world) config.add_view(goodbye_world, name='goodbye') - config.end() app = config.make_wsgi_app() serve(app, host='0.0.0.0') @@ -149,10 +147,8 @@ imports and function definitions is placed within the confines of an if __name__ == '__main__': config = Configurator() - config.begin() config.add_view(hello_world) config.add_view(goodbye_world, name='goodbye') - config.end() app = config.make_wsgi_app() serve(app, host='0.0.0.0') @@ -190,29 +186,6 @@ this particular :app:`Pyramid` application. Methods called on the Configurator will cause registrations to be made in a :term:`application registry` associated with the application. -Beginning Configuration -~~~~~~~~~~~~~~~~~~~~~~~ - -.. ignore-next-block -.. code-block:: python - - config.begin() - -The :meth:`pyramid.configuration.Configurator.begin` method tells -the system that application configuration has begun. In particular, -this causes the :term:`application registry` associated with this -configurator to become the "current" application registry, meaning -that code which attempts to use the application registry :term:`thread -local` will obtain the registry associated with the configurator. -This is an explicit step because it's sometimes convenient to use a -configurator without causing the registry associated with the -configurator to become "current". - -.. note:: - - See :ref:`threadlocals_chapter` for a discussion about what it - means for an application registry to be "current". - .. _adding_configuration: Adding Configuration @@ -281,28 +254,6 @@ important. We can register ``goodbye_world`` first and ``hello_world`` second; :app:`Pyramid` will still give us the most specific callable when a request is dispatched to it. -Ending Configuration -~~~~~~~~~~~~~~~~~~~~ - -.. ignore-next-block -.. code-block:: python - - config.end() - -The :meth:`pyramid.configuration.Configurator.end` method tells the -system that application configuration has ended. It is the inverse of -:meth:`pyramid.configuration.Configurator.begin`. In particular, -this causes the :term:`application registry` associated with this -configurator to no longer be the "current" application registry, -meaning that code which attempts to use the application registry -:term:`thread local` will no longer obtain the registry associated -with the configurator. - -.. note:: - - See :ref:`threadlocals_chapter` for a discussion about what it - means for an application registry to be "current". - .. index:: single: make_wsgi_app single: WSGI application diff --git a/docs/narr/project.rst b/docs/narr/project.rst index f47e9f293..6e466b284 100644 --- a/docs/narr/project.rst +++ b/docs/narr/project.rst @@ -740,14 +740,14 @@ also informs Python that the directory which contains it is a *package*. #. Line 2 imports the ``get_root`` function from :mod:`myproject.models` that we use later. -#. Lines 4-14 define a function that returns a :app:`Pyramid` +#. Lines 4-12 define a function that returns a :app:`Pyramid` WSGI application. This function is meant to be called by the :term:`PasteDeploy` framework as a result of running ``paster serve``. Within this function, configuration is performed. - Lines 9-11 register a "default view" (a view that has no ``name`` + Lines 8-10 register a "default view" (a view that has no ``name`` attribute). It is registered so that it will be found when the :term:`context` of the request is an instance of the :class:`myproject.models.MyModel` class. The first argument to @@ -761,11 +761,11 @@ also informs Python that the directory which contains it is a *package*. ``templates`` directory of the ``myproject`` package. The template file it actually points to is a :term:`Chameleon` ZPT template file. - Line 12 registers a static view, which will serve up the files from the + Line 11 registers a static view, which will serve up the files from the ``mypackage:static`` :term:`resource specification` (the ``static`` directory of the ``mypackage`` package). - Line 14 returns a :term:`WSGI` application to the caller of the function + Line 12 returns a :term:`WSGI` application to the caller of the function (Paste). ``views.py`` diff --git a/docs/narr/unittesting.rst b/docs/narr/unittesting.rst index 5cd8a0683..26035726b 100644 --- a/docs/narr/unittesting.rst +++ b/docs/narr/unittesting.rst @@ -1,4 +1,4 @@ -.. index:: +\.. index:: single: unit testing single: integration testing diff --git a/docs/tutorials/wiki/basiclayout.rst b/docs/tutorials/wiki/basiclayout.rst index c05a53831..a94a1632d 100644 --- a/docs/tutorials/wiki/basiclayout.rst +++ b/docs/tutorials/wiki/basiclayout.rst @@ -48,14 +48,11 @@ entry point happens to be the ``app`` function within the file named factory` and the settings keywords parsed by PasteDeploy. The root factory is named ``get_root``. -#. *Lines 16-18*. Begin configuration using the ``begin`` method of - the :meth:`pyramid.configuration.Configurator` class, load the +#. *Line 16*. Load the ``configure.zcml`` file from our package using the - :meth:`pyramid.configuration.Configurator.load_zcml` method, and - end configuration using the - :meth:`pyramid.configuration.Configurator.end` method. + :meth:`pyramid.configuration.Configurator.load_zcml` method. -#. *Line 19*. Use the +#. *Line 17*. Use the :meth:`pyramid.configuration.Configurator.make_wsgi_app` method to return a :term:`WSGI` application. diff --git a/docs/tutorials/wiki/src/authorization/tutorial/__init__.py b/docs/tutorials/wiki/src/authorization/tutorial/__init__.py index 124647ba9..a8a3c513e 100644 --- a/docs/tutorials/wiki/src/authorization/tutorial/__init__.py +++ b/docs/tutorials/wiki/src/authorization/tutorial/__init__.py @@ -16,7 +16,5 @@ def main(global_config, **settings): def get_root(request): return finder(request.environ) config = Configurator(root_factory=get_root, settings=settings) - config.begin() config.load_zcml('configure.zcml') - config.end() return config.make_wsgi_app() diff --git a/docs/tutorials/wiki/src/basiclayout/tutorial/__init__.py b/docs/tutorials/wiki/src/basiclayout/tutorial/__init__.py index f6cf8b479..45e4d722b 100644 --- a/docs/tutorials/wiki/src/basiclayout/tutorial/__init__.py +++ b/docs/tutorials/wiki/src/basiclayout/tutorial/__init__.py @@ -13,8 +13,6 @@ def main(global_config, **settings): def get_root(request): return finder(request.environ) config = Configurator(root_factory=get_root, settings=settings) - config.begin() config.load_zcml('configure.zcml') - config.end() return config.make_wsgi_app() diff --git a/docs/tutorials/wiki/src/models/tutorial/__init__.py b/docs/tutorials/wiki/src/models/tutorial/__init__.py index 7ef07e767..66e2f05ee 100644 --- a/docs/tutorials/wiki/src/models/tutorial/__init__.py +++ b/docs/tutorials/wiki/src/models/tutorial/__init__.py @@ -16,8 +16,6 @@ def main(global_config, **settings): def get_root(request): return finder(request.environ) config = Configurator(root_factory=get_root, settings=settings) - config.begin() config.load_zcml('configure.zcml') - config.end() return config.make_wsgi_app() diff --git a/docs/tutorials/wiki/src/viewdecorators/tutorial/__init__.py b/docs/tutorials/wiki/src/viewdecorators/tutorial/__init__.py index 7ef07e767..66e2f05ee 100644 --- a/docs/tutorials/wiki/src/viewdecorators/tutorial/__init__.py +++ b/docs/tutorials/wiki/src/viewdecorators/tutorial/__init__.py @@ -16,8 +16,6 @@ def main(global_config, **settings): def get_root(request): return finder(request.environ) config = Configurator(root_factory=get_root, settings=settings) - config.begin() config.load_zcml('configure.zcml') - config.end() return config.make_wsgi_app() diff --git a/docs/tutorials/wiki/src/views/tutorial/__init__.py b/docs/tutorials/wiki/src/views/tutorial/__init__.py index 7ef07e767..66e2f05ee 100644 --- a/docs/tutorials/wiki/src/views/tutorial/__init__.py +++ b/docs/tutorials/wiki/src/views/tutorial/__init__.py @@ -16,8 +16,6 @@ def main(global_config, **settings): def get_root(request): return finder(request.environ) config = Configurator(root_factory=get_root, settings=settings) - config.begin() config.load_zcml('configure.zcml') - config.end() return config.make_wsgi_app() diff --git a/docs/tutorials/wiki2/basiclayout.rst b/docs/tutorials/wiki2/basiclayout.rst index 9aca94fe5..9bcc17e97 100644 --- a/docs/tutorials/wiki2/basiclayout.rst +++ b/docs/tutorials/wiki2/basiclayout.rst @@ -52,10 +52,7 @@ entry point happens to be the ``app`` function within the file named deployment-related values such as ``reload_templates``, ``db_string``, etc. -#. *Line 15*. We call :meth:`pyramid.configuration.Configurator.begin` which - tells the configuration machinery we are starting configuration. - -#. *Line 16*. We call +#. *Line 15*. We call :meth:`pyramid.configuration.Configurator.add_static_view` with the arguments ``static`` (the name), and ``tutorial:static`` (the path). This registers a static resource view which will match any URL that starts with @@ -67,7 +64,7 @@ entry point happens to be the ``app`` function within the file named ``/static/foo``) will be used to compose a path to a static file resource, such as a CSS file. -#. *Lines 17-18*. Register a :term:`route configuration` via the +#. *Lines 16-17*. Register a :term:`route configuration` via the :meth:`pyramid.configuration.Configurator.add_route` method that will be used when the URL is ``/``. Since this route has an ``pattern`` equalling ``/`` it is the "default" route. The argument named ``view`` with the @@ -81,10 +78,7 @@ entry point happens to be the ``app`` function within the file named ``tutorial.views.my_view`` view returns a dictionary, a :term:`renderer` will use this template to create a response. -#. *Line 19*. We call :meth:`pyramid.configuration.Configurator.end` which - tells the configuration machinery we are ending configuration. - -#. *Line 20*. We use the +#. *Line 18*. We use the :meth:`pyramid.configuration.Configurator.make_wsgi_app` method to return a :term:`WSGI` application. diff --git a/docs/tutorials/wiki2/src/authorization/tutorial/__init__.py b/docs/tutorials/wiki2/src/authorization/tutorial/__init__.py index 4bddea74c..8269617f2 100644 --- a/docs/tutorials/wiki2/src/authorization/tutorial/__init__.py +++ b/docs/tutorials/wiki2/src/authorization/tutorial/__init__.py @@ -22,7 +22,6 @@ def main(global_config, **settings): root_factory='tutorial.models.RootFactory', authentication_policy=authn_policy, authorization_policy=authz_policy) - config.begin() config.add_static_view('static', 'tutorial:static') config.add_route('view_wiki', '/', view='tutorial.views.view_wiki') config.add_route('login', '/login', @@ -44,6 +43,5 @@ def main(global_config, **settings): config.add_view('tutorial.login.login', renderer='tutorial:templates/login.pt', context='pyramid.exceptions.Forbidden') - config.end() return config.make_wsgi_app() diff --git a/docs/tutorials/wiki2/src/basiclayout/tutorial/__init__.py b/docs/tutorials/wiki2/src/basiclayout/tutorial/__init__.py index 7a701fc02..0ae61fccd 100644 --- a/docs/tutorials/wiki2/src/basiclayout/tutorial/__init__.py +++ b/docs/tutorials/wiki2/src/basiclayout/tutorial/__init__.py @@ -12,11 +12,9 @@ def main(global_config, **settings): db_echo = settings.get('db_echo', 'false') initialize_sql(db_string, asbool(db_echo)) config = Configurator(settings=settings) - config.begin() config.add_static_view('static', 'tutorial:static') config.add_route('home', '/', view='tutorial.views.my_view', view_renderer='templates/mytemplate.pt') - config.end() return config.make_wsgi_app() diff --git a/docs/tutorials/wiki2/src/models/tutorial/__init__.py b/docs/tutorials/wiki2/src/models/tutorial/__init__.py index 10fcd0cbc..6e291ffdf 100644 --- a/docs/tutorials/wiki2/src/models/tutorial/__init__.py +++ b/docs/tutorials/wiki2/src/models/tutorial/__init__.py @@ -12,9 +12,7 @@ def main(global_config, **settings): db_echo = settings.get('db_echo', 'false') initialize_sql(db_string, asbool(db_echo)) config = Configurator(settings=settings) - config.begin() config.add_static_view('static', 'tutorial:static') config.add_route('home', '/', view='tutorial.views.my_view', view_renderer='templates/mytemplate.pt') - config.end() return config.make_wsgi_app() diff --git a/docs/tutorials/wiki2/src/views/tutorial/__init__.py b/docs/tutorials/wiki2/src/views/tutorial/__init__.py index 9ef923e0b..947ce9b93 100644 --- a/docs/tutorials/wiki2/src/views/tutorial/__init__.py +++ b/docs/tutorials/wiki2/src/views/tutorial/__init__.py @@ -12,7 +12,6 @@ def main(global_config, **settings): db_echo = settings.get('db_echo', 'false') initialize_sql(db_string, asbool(db_echo)) config = Configurator(settings=settings) - config.begin() config.add_static_view('static', 'tutorial:static') config.add_route('home', '/', view='tutorial.views.view_wiki') config.add_route('view_page', '/:pagename', @@ -24,6 +23,5 @@ def main(global_config, **settings): config.add_route('edit_page', '/:pagename/edit_page', view='tutorial.views.edit_page', view_renderer='tutorial:templates/edit.pt') - config.end() return config.make_wsgi_app() -- cgit v1.2.3