From e84116c068f45c68752f89062fa545dd40acd63f Mon Sep 17 00:00:00 2001 From: Ben Bangert Date: Thu, 18 Nov 2010 14:13:02 -0800 Subject: - URL Dispatch now allows for replacement markers to be located anywhere in the pattern, instead of immediately following a ``/``. - Added ``marker_pattern`` option to ``add_route`` to supply a dict of regular expressions to be used for markers in the pattern instead of the default regular expression that matched everything except a ``/``. --- docs/narr/urldispatch.rst | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) (limited to 'docs') diff --git a/docs/narr/urldispatch.rst b/docs/narr/urldispatch.rst index 4442be355..0170b36e2 100644 --- a/docs/narr/urldispatch.rst +++ b/docs/narr/urldispatch.rst @@ -208,16 +208,16 @@ and: /:foo/bar/baz -A patttern segment (an individual item between ``/`` characters in the -pattern) may either be a literal string (e.g. ``foo``) *or* it may be -a segment replacement marker (e.g. ``:foo``) or a certain combination -of both. +A pattern segment (an individual item between ``/`` characters in the pattern) +may either be a literal string (e.g. ``foo``) *or* it may be a replacement +marker (e.g. ``:foo``) or a certain combination of both. A replacement marker +does not need to be preceded by a ``/`` character. -A segment replacement marker is in the format ``:name``, where this -means "accept any characters up to the next nonalphaunumeric character +A replacement marker is in the format ``:name``, where this +means "accept any characters up to the next non-alphanumeric character and use this as the ``name`` matchdict value." For example, the following pattern defines one literal segment ("foo") and two dynamic -segments ("baz", and "bar"): +replacement markers ("baz", and "bar"): .. code-block:: text @@ -252,9 +252,21 @@ literal path ``/foo/biz`` will not match, because it does not contain a literal ``.html`` at the end of the segment represented by ``:name.html`` (it only contains ``biz``, not ``biz.html``). -This does not mean, however, that you can use two segment replacement -markers in the same segment. For instance, ``/:foo:bar`` is a -nonsensical route pattern. It will never match anything. +To capture both segments, two replacement markers can be used: + +.. code-block:: text + + foo/:name.:ext + +The literal path ``/foo/biz.html`` will match the above route pattern, and the +match result will be ``{'name': 'biz', 'ext': 'html'}``. This occurs because +the replacement marker ``:name`` has a literal part of ``.`` between the other +replacement marker ``:ext``. + +It is possible to use two replacement markers without any literal characters +between them, for instance ``/:foo:bar``. This would be a nonsensical pattern +without specifying any ``pattern_regexes`` to restrict valid values of each +replacement marker. Segments must contain at least one character in order to match a segment replacement marker. For example, for the URL ``/abc/``: @@ -471,6 +483,13 @@ represent neither predicates nor view configuration information. as ``path``. ``path`` continues to work as an alias for ``pattern``. +``marker_pattern`` + A dict of regular expression replacements for replacement markers in the + pattern to use when generating the complete regular expression used to + match the route. By default, every replacement marker in the pattern is + replaced with the regular expression ``[^/]+``. Values in this dict will + be used instead if present. + ``xhr`` This value should be either ``True`` or ``False``. If this value is specified and is ``True``, the :term:`request` must possess an -- cgit v1.2.3 From 4018adea20ee73cfeeaebb69e95e4b00dd5cf22e Mon Sep 17 00:00:00 2001 From: Ben Bangert Date: Thu, 18 Nov 2010 20:38:25 -0800 Subject: - URL Dispatch now uses the form ``{marker}`` to denote a replace marker in the route pattern instead of ``:marker``. The old syntax is still backwards compatible and accepted. The new format allows a regular expression for that marker location to be used instead of the default ``[^/]+``, for example ``{marker:\d+}`` is now valid to require the marker to be digits. --- docs/narr/urldispatch.rst | 140 ++++++++++++++++++++++++++++++---------------- 1 file changed, 92 insertions(+), 48 deletions(-) (limited to 'docs') diff --git a/docs/narr/urldispatch.rst b/docs/narr/urldispatch.rst index 0170b36e2..0d66f28a1 100644 --- a/docs/narr/urldispatch.rst +++ b/docs/narr/urldispatch.rst @@ -92,7 +92,17 @@ registry`. Here's an example: # pyramid.configuration.Configurator class; "myview" is assumed # to be a "view callable" function from views import myview - config.add_route('myroute', '/prefix/:one/:two', view=myview) + config.add_route('myroute', '/prefix/{one}/{two}', view=myview) + +.. versionchanged:: 1.0a4 + + Prior to 1.0a4, routes allow for a marker starting with a ``:``, for + example:: + + config.add_route('myroute', '/prefix/:one/:two', view=myview) + + Starting in 1.0a4, this style is deprecated in favor or ``{}`` usage + which allows for additional functionality. .. index:: single: route configuration; view callable @@ -116,7 +126,7 @@ Here's an example route configuration that references a view callable: # pyramid.configuration.Configurator class; "myview" is assumed # to be a "view callable" function from myproject.views import myview - config.add_route('myroute', '/prefix/:one/:two', view=myview) + config.add_route('myroute', '/prefix/{one}/{two}', view=myview) You can also pass a :term:`dotted Python name` as the ``view`` argument rather than an actual callable: @@ -128,7 +138,7 @@ rather than an actual callable: # pyramid.configuration.Configurator class; "myview" is assumed # to be a "view callable" function from myproject.views import myview - config.add_route('myroute', '/prefix/:one/:two', + config.add_route('myroute', '/prefix/{one}/{two}', view='myproject.views.myview') When a route configuration names a ``view`` attribute, the :term:`view @@ -200,20 +210,20 @@ the following patterns are equivalent: .. code-block:: text - :foo/bar/baz + {foo}/bar/baz and: .. code-block:: text - /:foo/bar/baz + /{foo}/bar/baz A pattern segment (an individual item between ``/`` characters in the pattern) may either be a literal string (e.g. ``foo``) *or* it may be a replacement -marker (e.g. ``:foo``) or a certain combination of both. A replacement marker +marker (e.g. ``{foo}``) or a certain combination of both. A replacement marker does not need to be preceded by a ``/`` character. -A replacement marker is in the format ``:name``, where this +A replacement marker is in the format ``{name}``, where this means "accept any characters up to the next non-alphanumeric character and use this as the ``name`` matchdict value." For example, the following pattern defines one literal segment ("foo") and two dynamic @@ -221,7 +231,7 @@ replacement markers ("baz", and "bar"): .. code-block:: text - foo/:baz/:bar + foo/{baz}/{bar} The above pattern will match these URLs, generating the following matchdicts: @@ -244,27 +254,27 @@ pattern. So, for instance, if this route pattern was used: .. code-block:: text - foo/:name.html + foo/{name}.html The literal path ``/foo/biz.html`` will match the above route pattern, and the match result will be ``{'name':u'biz'}``. However, the literal path ``/foo/biz`` will not match, because it does not contain a literal ``.html`` at the end of the segment represented by -``:name.html`` (it only contains ``biz``, not ``biz.html``). +``{name}.html`` (it only contains ``biz``, not ``biz.html``). To capture both segments, two replacement markers can be used: .. code-block:: text - foo/:name.:ext + foo/{name}.{ext} The literal path ``/foo/biz.html`` will match the above route pattern, and the match result will be ``{'name': 'biz', 'ext': 'html'}``. This occurs because -the replacement marker ``:name`` has a literal part of ``.`` between the other +the replacement marker ``{name}`` has a literal part of ``.`` between the other replacement marker ``:ext``. It is possible to use two replacement markers without any literal characters -between them, for instance ``/:foo:bar``. This would be a nonsensical pattern +between them, for instance ``/{foo}{bar}``. This would be a nonsensical pattern without specifying any ``pattern_regexes`` to restrict valid values of each replacement marker. @@ -282,7 +292,7 @@ pattern: .. code-block:: text - foo/:bar + foo/{bar} When matching the following URL: @@ -304,7 +314,7 @@ need to be preceded by a slash. For example: .. code-block:: text - foo/:baz/:bar*fizzle + foo/{baz}/{bar}*fizzle The above pattern will match these URLs, generating the following matchdicts: @@ -336,6 +346,24 @@ Will generate the following matchdict: {'fizzle':(u'La Pe\xf1a', u'a', u'b', u'c')} +By default, the ``*stararg`` will parse the remainder sections into a tuple +split by segment. Changing the regular expression used to match a marker can +also capture the remainder of the URL, for example: + +.. code-block:: text + + foo/{baz}/{bar}{fizzle:.*} + +The above pattern will match these URLs, generating the following matchdicts: + + foo/1/2/ -> {'baz':'1', 'bar':'2', 'fizzle':()} + foo/abc/def/a/b/c -> {'baz':'abc', 'bar':'def', 'fizzle': 'a/b/c')} + +This occurs because the default regular expression for a marker is ``[^/]+`` +which will match everything up to the first ``/``, while ``{filzzle:.*}`` will +result in a regular expression match of ``.*`` capturing the remainder into +a single value. + .. index:: single: route ordering @@ -360,12 +388,12 @@ be added in the following order: .. code-block:: text - members/:def + members/{def} members/abc In such a configuration, the ``members/abc`` pattern would *never* be matched; this is because the match ordering will always match -``members/:def`` first; the route configuration with ``members/abc`` +``members/{def}`` first; the route configuration with ``members/abc`` will never be evaluated. .. index:: @@ -446,8 +474,8 @@ represent neither predicates nor view configuration information. The syntax of the ``traverse`` argument is the same as it is for ``pattern``. For example, if the ``pattern`` provided is - ``articles/:article/edit``, and the ``traverse`` argument provided - is ``/:article``, when a request comes in that causes the route to + ``articles/{article}/edit``, and the ``traverse`` argument provided + is ``/{article}``, when a request comes in that causes the route to match in such a way that the ``article`` match value is '1' (when the request URI is ``/articles/1/edit``), the traversal path will be generated as ``/1``. This means that the root object's @@ -474,7 +502,7 @@ represent neither predicates nor view configuration information. **Predicate Arguments** ``pattern`` - The path of the route e.g. ``ideas/:idea``. This argument is + The path of the route e.g. ``ideas/{idea}``. This argument is required. See :ref:`route_path_pattern_syntax` for information about the syntax of route paths. If the path doesn't match the current URL, route matching continues. @@ -482,13 +510,6 @@ represent neither predicates nor view configuration information. .. note:: In earlier releases of this framework, this argument existed as ``path``. ``path`` continues to work as an alias for ``pattern``. - -``marker_pattern`` - A dict of regular expression replacements for replacement markers in the - pattern to use when generating the complete regular expression used to - match the route. By default, every replacement marker in the pattern is - replaced with the regular expression ``[^/]+``. Values in this dict will - be used instead if present. ``xhr`` This value should be either ``True`` or ``False``. If this value is @@ -663,7 +684,7 @@ match. For example: num_one_two_or_three = any_of('num', 'one', 'two', 'three') - config.add_route('num', '/:num', + config.add_route('num', '/{num}', custom_predicates=(num_one_two_or_three,)) The above ``any_of`` function generates a predicate which ensures that @@ -694,7 +715,7 @@ For instance, a predicate might do some type conversion of values: ymd_to_int = integers('year', 'month', 'day') - config.add_route('num', '/:year/:month/:day', + config.add_route('num', '/{year}/{month}/{day}', custom_predicates=(ymd_to_int,)) Note that a conversion predicate is still a predicate so it must @@ -702,6 +723,29 @@ return ``True`` or ``False``; a predicate that does *only* conversion, such as the one we demonstrate above should unconditionally return ``True``. +To avoid the try/except uncertainty, the route pattern can contain regular +expressions specifying requirements for that marker. For instance: + +.. code-block:: python + :linenos: + + def integers(*segment_names): + def predicate(info, request): + match = info['match'] + for segment_name in segment_names: + match[segment_name] = int(match[segment_name]) + return True + return predicate + + ymd_to_int = integers('year', 'month', 'day') + + config.add_route('num', '/{year:\d+}/{month:\d+}/{day:\d+}', + custom_predicates=(ymd_to_int,)) + +Now the try/except is no longer needed because the route will not match at +all unless these markers match ``\d+`` which requires them to be valid digits +for an ``int`` type conversion. + The ``match`` dictionary passed within ``info`` to each predicate attached to a route will be the same dictionary. Therefore, when registering a custom predicate which modifies the ``match`` dict, the @@ -732,9 +776,9 @@ An example of using the route in a set of route predicates: if info['route'].name in ('ymd', 'ym', 'y'): return info['match']['year'] == '2010' - config.add_route('y', '/:year', custom_predicates=(twenty_ten,)) - config.add_route('ym', '/:year/:month', custom_predicates=(twenty_ten,)) - config.add_route('ymd', '/:year/:month:/day', + config.add_route('y', '/{year}', custom_predicates=(twenty_ten,)) + config.add_route('ym', '/{year}/{month}', custom_predicates=(twenty_ten,)) + config.add_route('ymd', '/{year}/{month}/{day}', custom_predicates=(twenty_ten,)) The above predicate, when added to a number of route configurations @@ -833,7 +877,7 @@ The simplest route declaration which configures a route match to .. code-block:: python :linenos: - config.add_route('idea', 'site/:id', view='mypackage.views.site_view') + config.add_route('idea', 'site/{id}', view='mypackage.views.site_view') When a route configuration with a ``view`` attribute is added to the system, and an incoming request matches the *pattern* of the route @@ -841,12 +885,12 @@ configuration, the :term:`view callable` named as the ``view`` attribute of the route configuration will be invoked. In the case of the above example, when the URL of a request matches -``/site/:id``, the view callable at the Python dotted path name +``/site/{id}``, the view callable at the Python dotted path name ``mypackage.views.site_view`` will be called with the request. In other words, we've associated a view callable directly with a route pattern. -When the ``/site/:id`` route pattern matches during a request, the +When the ``/site/{id}`` route pattern matches during a request, the ``site_view`` view callable is invoked with that request as its sole argument. When this route matches, a ``matchdict`` will be generated and attached to the request as ``request.matchdict``. If the specific @@ -879,30 +923,30 @@ might add to your application: .. code-block:: python :linenos: - config.add_route('idea', 'ideas/:idea', view='mypackage.views.idea_view') - config.add_route('user', 'users/:user', view='mypackage.views.user_view') - config.add_route('tag', 'tags/:tags', view='mypackage.views.tag_view') + config.add_route('idea', 'ideas/{idea}', view='mypackage.views.idea_view') + config.add_route('user', 'users/{user}', view='mypackage.views.user_view') + config.add_route('tag', 'tags/{tags}', view='mypackage.views.tag_view') The above configuration will allow :app:`Pyramid` to service URLs in these forms: .. code-block:: text - /ideas/:idea - /users/:user - /tags/:tag + /ideas/{idea} + /users/{user} + /tags/{tag} -- When a URL matches the pattern ``/ideas/:idea``, the view callable +- When a URL matches the pattern ``/ideas/{idea}``, the view callable available at the dotted Python pathname ``mypackage.views.idea_view`` will be called. For the specific URL ``/ideas/1``, the ``matchdict`` generated and attached to the :term:`request` will consist of ``{'idea':'1'}``. -- When a URL matches the pattern ``/users/:user``, the view callable +- When a URL matches the pattern ``/users/{user}``, the view callable available at the dotted Python pathname ``mypackage.views.user_view`` will be called. For the specific URL ``/users/1``, the ``matchdict`` generated and attached to the :term:`request` will consist of ``{'user':'1'}``. -- When a URL matches the pattern ``/tags/:tag``, the view callable available +- When a URL matches the pattern ``/tags/{tag}``, the view callable available at the dotted Python pathname ``mypackage.views.tag_view`` will be called. For the specific URL ``/tags/1``, the ``matchdict`` generated and attached to the :term:`request` will consist of ``{'tag':'1'}``. @@ -930,7 +974,7 @@ An example of using a route with a factory: .. code-block:: python :linenos: - config.add_route('idea', 'ideas/:idea', + config.add_route('idea', 'ideas/{idea}', view='myproject.views.idea_view', factory='myproject.models.Idea') @@ -958,7 +1002,7 @@ a ``view`` declaration. .. code-block:: python :linenos: - config.add_route('idea', 'site/:id') + config.add_route('idea', 'site/{id}') config.add_view(route_name='idea', view='mypackage.views.site_view') This set of configuration parameters creates a configuration @@ -968,7 +1012,7 @@ completely equivalent to this example provided in .. code-block:: python :linenos: - config.add_route('idea', 'site/:id', view='mypackage.views.site_view') + config.add_route('idea', 'site/{id}', view='mypackage.views.site_view') In fact, the spelling which names a ``view`` attribute is just syntactic sugar for the more verbose spelling which contains separate @@ -1009,7 +1053,7 @@ Generating Route URLs Use the :func:`pyramid.url.route_url` function to generate URLs based on route patterns. For example, if you've configured a route with the ``name`` -"foo" and the ``pattern`` ":a/:b/:c", you might do this. +"foo" and the ``pattern`` "{a}/{b}/{c}", you might do this. .. ignore-next-block .. code-block:: python -- cgit v1.2.3 From 16c510efd5b05c503350e378beb94a9cd6a5de7d Mon Sep 17 00:00:00 2001 From: Ben Bangert Date: Thu, 18 Nov 2010 20:48:58 -0800 Subject: Ensure the version changed info is visible. --- docs/narr/urldispatch.rst | 1 - 1 file changed, 1 deletion(-) (limited to 'docs') diff --git a/docs/narr/urldispatch.rst b/docs/narr/urldispatch.rst index 0d66f28a1..1e5d84060 100644 --- a/docs/narr/urldispatch.rst +++ b/docs/narr/urldispatch.rst @@ -95,7 +95,6 @@ registry`. Here's an example: config.add_route('myroute', '/prefix/{one}/{two}', view=myview) .. versionchanged:: 1.0a4 - Prior to 1.0a4, routes allow for a marker starting with a ``:``, for example:: -- cgit v1.2.3 From 0f89f91a5bf4f26734235d01e81dffc77abba9c4 Mon Sep 17 00:00:00 2001 From: Ben Bangert Date: Thu, 18 Nov 2010 23:12:57 -0800 Subject: More colon references. --- docs/narr/urldispatch.rst | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'docs') diff --git a/docs/narr/urldispatch.rst b/docs/narr/urldispatch.rst index 1e5d84060..ae0ecf629 100644 --- a/docs/narr/urldispatch.rst +++ b/docs/narr/urldispatch.rst @@ -96,12 +96,8 @@ registry`. Here's an example: .. versionchanged:: 1.0a4 Prior to 1.0a4, routes allow for a marker starting with a ``:``, for - example:: - - config.add_route('myroute', '/prefix/:one/:two', view=myview) - - Starting in 1.0a4, this style is deprecated in favor or ``{}`` usage - which allows for additional functionality. + example ``/prefix/{one}``. Starting in 1.0a4, this style is deprecated + in favor or ``{}`` usage which allows for additional functionality. .. index:: single: route configuration; view callable @@ -280,9 +276,9 @@ replacement marker. Segments must contain at least one character in order to match a segment replacement marker. For example, for the URL ``/abc/``: -- ``/abc/:foo`` will not match. +- ``/abc/{foo}`` will not match. -- ``/:foo/`` will match. +- ``/{foo}/`` will match. Note that values representing path segments matched with a ``:segment`` match will be url-unquoted and decoded from UTF-8 into @@ -1246,7 +1242,7 @@ Such a ``factory`` might look like so: if article == '1': self.__acl__ = [ (Allow, 'editor', 'view') ] -If the route ``archives/:article`` is matched, and the article number +If the route ``archives/{article}`` is matched, and the article number is ``1``, :app:`Pyramid` will generate an ``Article`` :term:`context` with an ACL on it that allows the ``editor`` principal the ``view`` permission. Obviously you can do more generic things -- cgit v1.2.3 From 15c258849aa54eb99d272fbbef0e9c3d911d2cca Mon Sep 17 00:00:00 2001 From: Ben Bangert Date: Thu, 18 Nov 2010 23:25:14 -0800 Subject: There is no pattern_regexes. --- docs/narr/urldispatch.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs') diff --git a/docs/narr/urldispatch.rst b/docs/narr/urldispatch.rst index ae0ecf629..a86041e55 100644 --- a/docs/narr/urldispatch.rst +++ b/docs/narr/urldispatch.rst @@ -270,8 +270,8 @@ replacement marker ``:ext``. It is possible to use two replacement markers without any literal characters between them, for instance ``/{foo}{bar}``. This would be a nonsensical pattern -without specifying any ``pattern_regexes`` to restrict valid values of each -replacement marker. +without specifying a custom regular expression to restrict what a marker +captures. Segments must contain at least one character in order to match a segment replacement marker. For example, for the URL ``/abc/``: -- cgit v1.2.3 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