summaryrefslogtreecommitdiff
path: root/repoze/bfg/urldispatch.py
AgeCommit message (Collapse)Author
2010-10-25first pass at converting bfg to pyramid namespaceChris McDonough
2010-09-14- The ``add_route`` method of a Configurator now accepts aChris McDonough
``pregenerator`` argument. The pregenerator for the resulting route is called by ``route_url`` in order to adjust the set of arguments passed to it by the user for special purposes, such as Pylons 'subdomain' support. It will influence the URL returned by ``route_url``. See the ``repoze.bfg.interfaces.IRoutePregenerator`` interface for more information.
2010-09-08- The ``repoze.bfg.urldispatch.Route`` constructor (not an API) nowChris McDonough
accepts a different ordering of arguments. Previously it was ``(pattern, name, factory=None, predicates=())``. It is now ``(name, pattern, factory=None, predicates=())``. This is in support of consistency with ``configurator.add_route``. - The ``repoze.bfg.urldispatch.RoutesMapper.connect`` method (not an API) now accepts a different ordering of arguments. Previously it was ``(pattern, name, factory=None, predicates=())``. It is now ``(name, pattern, factory=None, predicates=())``. This is in support of consistency with ``configurator.add_route``. - The ``repoze.bfg.urldispatch.RoutesMapper`` object now has a ``get_route`` method which returns a single Route object or ``None``. - A new interface ``repoze.bfg.interfaces.IRoute`` was added. The ``repoze.bfg.urldispatch.Route`` object implements this interface. - The canonical attribute for accessing the routing pattern from a route object is now ``pattern`` rather than ``path``. - The argument to ``repoze.bfg.configuration.Configurator.add_route`` which was previously called ``path`` is now called ``pattern`` for better explicability. For backwards compatibility purposes, passing a keyword argument named ``path`` to ``add_route`` will still work indefinitely. - The ``path`` attribute to the ZCML ``route`` directive is now named ``pattern`` for better explicability. The older ``path`` attribute will continue to work indefinitely. - All narrative, API, and tutorial docs which referred to a route pattern as a ``path`` have now been updated to refer to them as a ``pattern``. - The routesalchemy template has been updated to use ``pattern`` in its route declarations rather than ``path``.
2010-07-30cmChris McDonough
2010-07-12- New internal exception: ``repoze.bfg.exceptions.URLDecodeError``.Chris McDonough
This URL is a subclass of the built-in Python exception named ``UnicodeDecodeError``. - When decoding a URL segment to Unicode fails, the exception raised is now ``repoze.bfg.exceptions.URLDecodeError`` instead of ``UnicodeDecodeError``. This makes it possible to register an exception view invoked specifically when ``repoze.bfg`` cannot decode a URL.
2010-06-30- A section named ``Custom Predicates`` was added to the URL DispatchChris McDonough
narrative chapter.
2010-06-30pass only match and route and document route minimallyChris McDonough
2010-06-30- In earlier versions, a custom route predicate associated with a urlChris McDonough
dispatch route (each of the predicate functions fed to the ``custom_predicates`` argument of ``repoze.bfg.configuration.Configurator.add_route``) has always required a 2-positional argument signature, e.g. ``(context, request)``. Before this release, the ``context`` argument was always ``None``. As of this release, the first argument passed to a predicate is now a dictionary conventionally named ``info`` consisting of ``match``, ``route``, and ``mapper``. ``match`` is a dictionary: it represents the arguments matched in the URL by the route. ``route`` is an object representing the route that matched. ``mapper`` is the url dispatch route mapper object. This is useful when predicates need access to the route match. For example:: def any_of(segment_name, *args): def predicate(info, request): if info['match'][segment_name] in args: return True num_one_two_or_three = any_of('num, 'one', 'two', 'three') add_route('/:num', custom_predicates=(num_one_two_or_three,))
2009-12-16Bug FixesChris McDonough
--------- - When a route with the same name as a previously registered route was added, the old route was not removed from the mapper's routelist. Symptom: the old registered route would be used (and possibly matched) during route lookup when it should not have had a chance to ever be used.
2009-12-01Unused assignment.Chris McDonough
2009-11-17Move configuration methods into Configurator.Chris McDonough
2009-11-12- Use ``alsoProvides`` in the urldispatch module to attach anChris McDonough
interface to the request rather than ``directlyProvides`` to avoid disturbing interfaces set in a NewRequest event handler.
2009-11-01- Header values returned by the ``authtktauthenticationpolicy``Chris McDonough
``remember`` and ``forget`` methods would be of type ``unicode`` if the ``cookie_name`` attribute was used in the ZCML declaration. This violated the WSGI spec, causing a ``TypeError`` to be raised when these headers were used under ``mod_wsgi``. - If a routes-only BFG app was mounted under a path in modwsgi, ala ``WSGIScriptAlias /myapp /Users/chrism/projects/modwsgi/env/bfg.wsgi``, the home route (a route with the path of ``'/'`` or ``''``) would not match when the path ``/myapp`` was visited (only when the path ``/myapp/`` was visited). This is now fixed: if the urldispatch root factory notes that the PATH_INFO is empty, it converts it to a single slash before trying to do matching.
2009-11-01- The routes root factory called route factories and the default routeChris McDonough
factory with an environ rather than a request. One of the symptoms of this bug: applications generated using the ``bfg_zodb`` paster template in 1.1a9 did not work properly.
2009-11-01- The ZCML ``route`` directive's attributes ``xhr``,Chris McDonough
``request_method``, ``path_info``, ``request_param``, ``header`` and ``accept`` are now *route* predicates rather than *view* predicates. If one or more of these predicates is specified in the route configuration, all of the predicates must return true for the route to match a request. If one or more of the route predicates associated with a route returns ``False`` when checked during a request, the route match fails, and the next match in the routelist is tried. This differs from the previous behavior, where no route predicates existed and all predicates were considered view predicates, because in that scenario, the next route was not tried.
2009-10-30FeaturesChris McDonough
-------- - In previous versions of BFG, the "root factory" (the ``get_root`` callable passed to ``make_app`` or a function pointed to by the ``factory`` attribute of a route) was called with a "bare" WSGI environment. In this version, and going forward, it will be called with a ``request`` object. The request object passed to the factory implements dictionary-like methods in such a way that existing root factory code which expects to be passed an environ will continue to work. Internal -------- - The request implements dictionary-like methods that mutate and query the WSGI environ. This is only for the purpose of backwards compatibility with root factories which expect an ``environ`` rather than a request. - The ``repoze.bfg.request.create_route_request_factory`` function, which returned a request factory was removed in favor of a ``repoze.bfg.request.route_request_interface`` function, which returns an interface. - The ``repoze.bfg.request.Request`` class, which is a subclass of ``webob.Request`` now defines its own ``__setattr__``, ``__getattr__`` and ``__delattr__`` methods, which override the default WebOb behavior. The default WebOb behavior stores attributes of the request in ``self.environ['webob.adhoc_attrs']``, and retrieves them from that dictionary during a ``__getattr__``. This behavior was undesirable for speed and "expectation" reasons. Now attributes of the ``request`` are stored in ``request.__dict__`` (as you otherwise might expect from an object that did not override these methods). - Reverse the order in which the router calls the request factory and the root factory. The request factory is now called first; the resulting request is passed to the root factory. - The ``repoze.bfg.request.request_factory`` function has been removed. Its functionality is no longer required. - The "routes root factory" that wraps the default root factory when there are routes mentioned in the configuration now attaches an interface to the request via ``zope.interface.directlyProvides``. This replaces logic in the (now-gone) ``repoze.bfg.request.request_factory`` function. - The ``route`` and ``view`` ZCML directives now register an interface as a named utility (retrieved from ``repoze.bfg.request.route_request_interface``) rather than a request factory (the previous return value of the now-missing ``repoze.bfg.request.create_route_request_factory``.
2009-10-29- The ``repoze.bfg.request.Request`` class, which is a subclass ofChris McDonough
``webob.Request`` now defines its own ``__setattr__``, ``__getattr__`` and ``__delattr__`` methods, which override the default WebOb behavior. The default WebOb behavior stores attributes of the request in ``self.environ['webob.adhoc_attrs']``, and retrieves them from that dictionary during a ``__getattr__``. This behavior was undesirable for speed and "expectation" reasons. Now attributes of the ``request`` are stored in ``request.__dict__`` (as you otherwise might expect from an object that did not override these methods). - The router no longer calls ``repoze.bfg.traversal._traverse`` and does its work "inline" (speed).
2009-09-23FeaturesChris McDonough
-------- - Speed up ``repoze.bfg.encode.urlencode`` (nee' ``repoze.bfg.url.urlencode``) slightly. - Speed up ``repoze.bfg.traversal.model_path`` and ``repoze.bfg.traversal.model_path_tuple`` slightly. Internal -------- - Move ``repoze.bfg.traversal._url_quote`` into ``repoze.bfg.encode`` as ``url_quote``. Backwards Incompatibilities --------------------------- - We previously had a Unicode-aware wrapper for the ``urllib.urlencode`` function named ``repoze.bfg.url.urlencode`` which delegated to the stdlib function, but which marshalled all unicode values to utf-8 strings before calling the stdlib version. A newer replacement now lives in ``repoze.bfg.encode`` (old imports will still work). The replacement does not delegate to the stdlib. The replacement diverges from the stdlib implementation and the previous ``repoze.bfg.url`` url implementation inasmuch as its ``doseq`` argument is a decoy: it always behaves in the ``doseq=True`` way (which is the only sane behavior) for speed purposes. The old import location (``repoze.bfg.url.urlencode``) still functions and has not been deprecated.
2009-09-20Minor speed tweaks.Chris McDonough
2009-09-18Compulsive import reorderings.Chris McDonough
2009-09-17- Add a ``repoze.bfg.url.static_url`` API which is capable ofChris McDonough
generating URLs to static resources defined by the ``<static>`` ZCML directive. See the "Views" narrative chapter's section titled "Generating Static Resource URLs" for more information.
2009-08-09- Change urldispatch internals: Route object is now constructed usingChris McDonough
a path, a name, and a factory instead of a name, a matcher, a generator, and a factory.
2009-06-26- Cause ``:segment`` matches in route paths to put a Unicode-decodedChris McDonough
and URL-dequoted value in the matchdict for the value matched. Previously a non-decoded non-URL-dequoted string was placed in the matchdict as the value. - Cause ``*remainder`` matches in route paths to put a *tuple* in the matchdict dictionary in order to be able to present Unicode-decoded and URL-dequoted values for the traversal path. Previously a non-decoded non-URL-dequoted string was placed in the matchdict as the value.
2009-06-25- Make ``route_url`` URL-quote segment replacements during generation.Chris McDonough
Remainder segments are not quoted.
2009-06-24Merge noroutes branch to trunk.Chris McDonough
2009-06-22Unused import.Chris McDonough
2009-06-22- Adding ``*path_info`` to a route no longer changes the PATH_INFO forChris McDonough
a request that matches using URL dispatch. This feature was only there to service the ``repoze.bfg.wsgi.wsgiapp2`` decorator and it did it wrong; use ``*subpath`` instead now. - The interface generation performed for named request factories had the wrong base classes.
2009-06-21Make urldispatch put matchdict into environ.Chris McDonough
Traverser no longer returns matchdict.
2009-06-21- Make Routes mapper responsible for doing magic to fix up PATH_INFOChris McDonough
and SCRIPT_NAME when a ``path_info`` key exists in the matchdict. This used to be done in the traverser, which made no sense.
2009-06-11Merge unifyroutesandtraversal branch into trunkChris McDonough
2009-06-03Revert urldispatch-context-as-dict-subclass committed in r5175. Let's not ↵Chris McDonough
make that promise yet.
2009-06-03- The default routes contextChris McDonough
(``repoze.bfg.urldispatch.DefaultRoutesContext``) object now subclasses from ``dict``. This means you can use the mapping protocol in views against it.
2009-06-01- It was not possible to register a custom ``IRoutesContextFactory``Chris McDonough
for use as a default context factory as documented in the "Hooks" chapter.
2009-05-27- Remove backwards compatibility alias forChris McDonough
``repoze.bfg.urldispatch.RoutesContext`` (deprecated since 0.6.3). This must now be imported as ``repoze.bfg.urldispatch.DefaultRoutesContext``.
2009-05-18FeaturesChris McDonough
-------- - Added a ``traverse`` function to the ``repoze.bfg.traversal`` module. This function may be used to retrieve certain values computed during path resolution. See the Traversal API chapter of the documentation for more information about this function. Deprecations ------------ - Internal: ``ITraverser`` callables should now return a dictionary rather than a tuple. Up until 0.7.0, all ITraversers were assumed to return a 3-tuple. In 0.7.1, ITraversers were assumed to return a 6-tuple. As (by evidence) it's likely we'll need to add further information to the return value of an ITraverser callable, 0.8 assumes that an ITraverser return a dictionary with certain elements in it. See the ``repoze.bfg.interfaces.ITraverser`` interface for the list of keys that should be present in the dictionary. ``ITraversers`` which return tuples will still work, although a deprecation warning will be issued. Backwards Incompatibilities --------------------------- - If your code used the ITraverser interface directly (not via an API function such as ``find_model``) via an adapter lookup, you'll need to change your code to expect a dictionary rather than a 3- or 6-tuple if your code ever gets return values from the default ModelGraphTraverser or RoutesModelTraverser adapters.
2009-05-16Speed up common case (use default factory).Chris McDonough
2009-05-16Don't do an alsoProvides if it's already a default routes context.Chris McDonough
2009-05-16- The ``RoutesMapper`` class in ``repoze.bfg.urldispatch`` has beenChris McDonough
removed, as well as its documentation. It had been deprecated since 0.6.3. Code in ``repoze.bfg.urldispatch.RoutesModelTraverser`` which catered to it has also been removed. - The semantics of the ``route`` ZCML directive have been simplified. Previously, it was assumed that to use a route, you wanted to map a route to an externally registered view. The new ``route`` directive instead has a ``view`` attribute which is required, specifying the dotted path to a view callable. When a route directive is processed, a view is *registered* using the name attribute of the route directive as its name and the callable as its value. The ``view_name`` and ``provides`` attributes of the ``route`` directive are therefore no longer used. Effectively, if you were previously using the ``route`` directive, it means you must change a pair of ZCML directives that look like this:: <route name="home" path="" view_name="login" factory=".models.root.Root" /> <view for=".models.root.Root" name="login" view=".views.login_view" /> To a ZCML directive that looks like this:: <route name="home" path="" view=".views.login_view" factory=".models.root.Root" /> In other words, to make old code work, remove the ``view`` directives that were only there to serve the purpose of backing ``route`` directives, and move their ``view=`` attribute into the ``route`` directive itself. This change also necessitated that the ``name`` attribute of the ``route`` directive is now required. If you were previously using ``route`` directives without a ``name`` attribute, you'll need to add one (the name is arbitrary, but must be unique among all ``route`` and ``view`` statements). The ``provides`` attribute of the ``route`` directive has also been removed. This directive specified a sequence of interface types that the generated context would be decorated with. Since route views are always generated now for a single interface (``repoze.bfg.IRoutesContext``) as opposed to being looked up arbitrarily, there is no need to decorate any context to ensure a view is found. - The Routes ``Route`` object used to resolve the match is now put into the environment as ``bfg.route`` when URL dispatch is used.
2009-05-10Minor speed and docs tweaks.Chris McDonough
2009-05-10- In version 0.6.3, passing a ``get_root`` callback (a "root factory")Chris McDonough
to ``repoze.bfg.router.make_app`` became optional if any ``route`` declaration was made in ZCML. The intent was to make it possible to disuse traversal entirely, instead relying entirely on URL dispatch (Routes) to resolve all contexts. However a compound set of bugs prevented usage of a Routes-based root view (a view which responds to "/"). One bug existed in `repoze.bfg.urldispatch``, another existed in Routes itself. To resolve this issue, the urldispatch module was fixed, and a fork of the Routes trunk was put into the "dev" index named ``Routes-1.11dev-chrism-home``. The source for the fork exists at `http://bitbucket.org/chrism/routes-home/ <http://bitbucket.org/chrism/routes-home/>`_; its contents have been reported to the upstream Routes developers and will hopefully be a part of the final Routes 1.11 release.
2009-05-01Remove dependencies on zope.deferredimport. zope.deferredimport wasChris McDonough
only used as a deprecation mechanism, so where possible we've kept around the deprecation warnings and we've used zope.deprectation instead. However, when cross-module deprecations were included, rather than introducing a cyclic dependency, we just removed the deprecation itself. As a result: - Since version 0.6.1, a deprecation warning has been emitted when the name ``model_url`` is imported from the ``repoze.bfg.traversal`` module. This import alias (and the deprecation warning) has been removed. Any import of the ``model_url`` function will now need to be done from ``repoze.bfg.url``; any import of the name ``model_url`` from ``repoze.bfg.traversal`` will now fail. This was done to remove a dependency on zope.deferredimport. - Since version 0.6.5, a deprecation warning has been emitted when the name ``RoutesModelTraverser`` is imported from the ``repoze.bfg.traversal`` module. This import alias (and the deprecation warning) has been removed. Any import of the ``RoutesModelTraverser`` class will now need to be done from ``repoze.bfg.urldispatch``; any import of the name ``RoutesModelTraverser`` from ``repoze.bfg.traversal`` will now fail. This was done to remove a dependency on zope.deferredimport.
2009-04-16- The interface for ``repoze.bfg.interfaces.ITraverser`` and theChris McDonough
built-in implementations that implement the interface (``repoze.bfg.traversal.ModelGraphTraverser``, and ``repoze.bfg.urldispatch.RoutesModelTraverser``) now expect the ``__call__`` method of an ITraverser to return 3 additional arguments: ``traversed``, ``virtual_root``, and ``virtual_root_path`` (the old contract was that the ``__call__`` method of an ITraverser returned; three arguments, the contract new is that it returns six). ``traversed`` will be a sequence of Unicode names that were traversed (including the virtual root path, if any) or ``None`` if no traversal was performed, ``virtual_root`` will be a model object representing the virtual root (or the physical root if traversal was not performed), and ``virtual_root_path`` will be a sequence representing the virtual root path (a sequence of Unicode names) or ``None`` if traversal was not performed. Six arguments are now returned from BFG ITraversers. They are returned in this order: ``context``, ``view_name``, ``subpath``, ``traversed``, ``virtual_root``, and ``virtual_root_path``. Places in the BFG code which called an ITraverser continue to accept a 3-argument return value, although BFG will generate and log a warning when one is encountered. - The request object now has the following attributes: ``traversed`` (the sequence of names traversed or ``None`` if traversal was not performed), ``virtual_root`` (the model object representing the virtual root, including the virtual root path if any), and ``virtual_root_path`` (the seuquence of names representing the virtual root path or ``None`` if traversal was not performed). - A new decorator named ``wsgiapp2`` was added to the ``repoze.bfg.wsgi`` module. This decorator performs the same function as ``repoze.bfg.wsgi.wsgiapp`` except it fixes up the ``SCRIPT_NAME``, and ``PATH_INFO`` environment values before invoking the WSGI subapplication. - The ``repoze.bfg.testing.DummyRequest`` object now has default attributes for ``traversed``, ``virtual_root``, and ``virtual_root_path``. - The RoutesModelTraverser now behaves more like the Routes "RoutesMiddleware" object when an element in the match dict is named ``path_info`` (usually when there's a pattern like ``http://foo/*path_info``). When this is the case, the ``PATH_INFO`` environment variable is set to the value in the match dict, and the ``SCRIPT_NAME`` is appended to with the prefix of the original ``PATH_INFO`` not including the value of the new variable. - The notfound debug now shows the traversed path, the virtual root, and the virtual root path too.
2009-01-27FeaturesChris McDonough
-------- - The ``repoze.bfg.url.model_url`` API now works against contexts derived from Routes URL dispatch (``Routes.util.url_for`` is called under the hood). - "Virtual root" support for traversal-based applications has been added. Virtual root support is useful when you'd like to host some model in a :mod:`repoze.bfg` model graph as an application under a URL pathname that does not include the model path itself. For more information, see the (new) "Virtual Hosting" chapter in the documentation. - A ``repoze.bfg.traversal.virtual_root`` API has been added. When called, it returns the virtual root object (or the physical root object if no virtual root has been specified). Implementation Changes ---------------------- - ``repoze.bfg.traversal.RoutesModelTraverser`` has been moved to ``repoze.bfg.urldispatch``. - ``model_url`` URL generation is now performed via an adapter lookup based on the context and the request. - ZCML which registers two adapters for the ``IContextURL`` interface has been added to the configure.zcml in ``repoze.bfg.includes``.
2009-01-25- The ``repoze.bfg.urldispatch.RoutesRootFactory`` now injects theChris McDonough
``wsgiorg.routing_args`` environment variable into the environ when a route matches. This is a tuple of ((), routing_args) where routing_args is the value that comes back from the routes mapper match (the "match dict"). - The ``repoze.bfg.traversal.RoutesModelTraverser`` class now wants to obtain the ``view_name`` and ``subpath`` from the ``wsgiorgs.routing_args`` environment variable. It falls back to obtaining these from the context for backwards compatibility.
2009-01-18context_factory -> factoryChris McDonough
context_interfaces -> provides
2009-01-18Merge "routesmapper branch" to trunk.Chris McDonough
2009-01-16- Add a section on "Using BFG Security With URL Dispatch" into theChris McDonough
urldispatch chapter of the documentation. Clean up "BFG" vernacular (replace with repoze.bfg).
2008-09-17 - Routes URL dispatch did not have access to the WSGI environment,Chris McDonough
so conditions such as method=GET did not work.
2008-09-16Document url dispatch in narrative form.Chris McDonough
2008-08-08 - Add ``find_context_from_path`` and ``find_root`` traversal APIs.Chris McDonough
In the process, make ITraverser a uni-adapter (on context) rather than a multiadapter (on context and request).