Commits

Andriy Kornatskyy committed 1e98a0b

Updated documentation with respect to intermediate and finishing routes

  • Participants
  • Parent commits a80b26e

Comments (0)

Files changed (2)

 .. literalinclude:: ../demos/hello/helloworld.py
    :lines: 9-13
 
+In addition let add a handler for not found response.
+
+.. literalinclude:: ../demos/hello/helloworld.py
+   :lines: 16-20
+
 The declaration and mapping of pattern to handler following. We create an
 instance of ``PathRouter`` class and pass mapping that in this partucular case
 is a tuple of two values: ``pattern`` and ``handler``.
 
 .. literalinclude:: ../demos/hello/helloworld.py
-   :lines: 16-19
+   :lines: 23-27
+
+The first pattern ``'/'`` will match only root path of the request (it is
+finishing route in match chain). The second pattern ``'/{any}'`` is a curly
+expression that is translated to regular expression that ultimately match
+any path and is finishing route as well.
 
 ``main`` function serves as `WSGI`_ application entry point. The only thing
 we do here is to get a value of `WSGI`_ environment variable ``PATH_INFO``
 (the remainder of the request URL's path) and pass to router
 :py:meth:`~wheezy.routing.router.PathRouter.match` method, in return we
 get ``handler`` and ``kwargs`` (parameters discovered from matching rule,
-that we ignore for now). Due to specific of the route that ends with ``/``
-our handler will match any incomming request.
+that we ignore for now).
 
 .. literalinclude:: ../demos/hello/helloworld.py
-   :lines: 22-24
+   :lines: 30-32
 
 The rest in the ``helloworld`` application launch a simple wsgi server.
 Try it by running::

doc/userguide.rst

 :ref:`helloworld` example you notice the following:
 
 .. literalinclude:: ../demos/hello/helloworld.py
-   :lines: 22-24
+   :lines: 29-31
 
 or more precisely::
 
 ``server_urls`` included into ``server/`` subpath. So effective path for
 ``server_time`` handler is ``server/time``.
 
+Note that route selected for ``'server/'`` pattern is intermediate (it is not
+finishing since there is included another after it). ``'time'`` pattern is
+finishing since it is the last in the match chain.
+
 Named Groups
 ------------
 
 ``url`` helper
 --------------
 
-There is :py:func:`wheezy.routing.url` function (that is actually just
-an exporting name for :py:func:`~wheezy.routing.router.url`) that let you
+There is :py:func:`wheezy.routing.router.url` function that let you
 make your url mapping more readable::
 
     from wheezy.routing import url
         url('posts', latest_posts, kwargs={'blog_id': 100})
     ]
 
+All it does just convers arguments to a tupple of four.
+
 .. _named:
 
 Named Mapping
 Adding Routes
 -------------
 
-You have an instance of :py:class:`wheezy.routing.PathRouter`
-(:py:class:`~wheezy.routing.router.PathRouter`). Call it method
-:py:meth:`~wheezy.routing.router.PathRouter.add_routes` to add any
-mapping you have. Here is how we do it in :ref:`helloworld` example:
+You have an instance of :py:class:`~wheezy.routing.router.PathRouter`.
+Call it method :py:meth:`~wheezy.routing.router.PathRouter.add_routes`
+to add any pattern mapping you have. Here is how we do it in
+:ref:`helloworld` example:
 
 .. literalinclude:: ../demos/hello/helloworld.py
-   :lines: 16-19
+   :lines: 24-27
 
 ... or :ref:`server time`:
 
 
 Every pattern mapping you add to router is translated to appropriate route
 match strategy. The available routing match strategies are definded in
-:py:mod:`~wheezy.routing.config` module by ``route_builders`` list and 
+:py:mod:`~wheezy.routing.config` module by ``route_builders`` list and
 include:
 
 #. plain
    :lines: 14-14
 
 The matching paths include: ``account/login``, ``blog/list``, etc. The
-strategy performs exact string marching.
+strategy performs string marching.
 
-In case the matching string ends with path segment delimiter character 
-``'/'``, the strategy is changed to match the beginning of path, thus 
-``server/`` pattern match any path starting with ``server/``, e.g. 
-``server/info``, etc.
+Finishing routes are matched by exact string ``equals`` operation, intermediate
+routes are matched with ``startswith`` string operation.
 
 Regex Route
 ~~~~~~~~~~~
 limitation that applies if you would like to build paths by name (reverse
 function to path matching). Use regex syntax only inside named groups,
 create them as much as necessary. The path build strategy simply replaces
-named groups with values supplied.
+named groups with values supplied. Optional named groups are supported.
 
 Curly Route
 ~~~~~~~~~~~
 .. literalinclude:: ../src/wheezy/routing/curly.py
    :lines: 9-9
 
-You define a named group by using curly brakets. The form of 
-curly expression (``pattern`` is optional and corresponds to segment by 
+You define a named group by using curly brakets. The form of
+curly expression (``pattern`` is optional and corresponds to segment by
 default)::
 
     {name[:pattern]}
-    
+
 The curly expression ``abc/{id}`` is convered into regex ``abc/(?P<id>[^/]+)``.
 
-The name inside curly expression can be constrained with the following 
+The name inside curly expression can be constrained with the following
 patterns:
 
 - ``i``, ``int``, ``number``, ``digits`` - one or more digits
 - ``s``, ``segment``, ``part`` - everything until ``'/'`` (path segment)
 - ``*``, ``a``, ``any``, ``rest`` - match anything
 
-Note that if pattern constraint doesn't corresponds to anything mentioned 
+Note that if pattern constraint doesn't corresponds to anything mentioned
 above than it is interpreted as a regular expression::
 
     locale:(en|ru)}/home => (?P<locale>(en|ru))/home
 
     posts/{year:i}/{month:i}
     account/{name:w}
-    
+
 You can extend recognized curly patterns::
 
     from wheezy.routing.curly import patterns
-    
+
     patterns['w'] = r'\w+'
 
 This way you can add your custom patterns.
 .. literalinclude:: ../demos/time/views.py
    :lines: 14-15
 
-You can pass optional values (``kwargs`` argument) that will be used 
+You can pass optional values (``kwargs`` argument) that will be used
 to replace named groups of the path matching pattern::
 
     >>> r = RegexRoute(