summaryrefslogtreecommitdiff
path: root/repoze/bfg/traversal.py
AgeCommit message (Collapse)Author
2010-10-25first pass at converting bfg to pyramid namespaceChris McDonough
2010-09-24- The ``repoze.bfg.traversal.traversal_path`` API now eagerly attemptsChris McDonough
to encode a Unicode ``path`` into ASCII before attempting to split it and decode its segments. This is for convenience, effectively to allow a (stored-as-Unicode-in-a-database, or retrieved-as-Unicode-from-a-request-parameter) Unicode path to be passed to ``find_model``, which eventually internally uses the ``traversal_path`` function under the hood. In version 1.2 and prior, if the ``path`` was Unicode, that Unicode was split on slashes and each resulting segment value was Unicode. An inappropriate call to the ``decode()`` method of a resulting Unicode path segment could cause a ``UnicodeDecodeError`` to occur even if the Unicode representation of the path contained no 'high order' characters (it effectively did a "double decode"). By converting the Unicode path argument to ASCII before we attempt to decode and split, genuine errors will occur in a more obvious place while also allowing us to handle (for convenience) the case that it's a Unicode representation formed entirely from ASCII-compatible characters.
2010-08-26avoid some getattrsChris McDonough
2010-08-26the goggles, they can be replacedChris McDonough
2010-07-24- A new method of the ``Configurator`` exists:Chris McDonough
``set_request_factory``. If used, this method will set the factory used by the :mod:`repoze.bfg` router to create all request objects. - The ``Configurator`` constructor takes an additional argument: ``request_factory``. If used, this argument will set the factory used by the :mod:`repoze.bfg` router to create all request objects. - The ``Hooks`` narrative chapter now contains a section about changing the request factory.
2010-07-23- New argument to ``repoze.bfg.configuration.Configurator.add_route``Chris McDonough
and the ``route`` ZCML directive: ``traverse``. If you would like to cause the ``context`` to be something other than the ``root`` object when this route matches, you can spell a traversal pattern as the ``traverse`` argument. This traversal pattern will be used as the traversal path: traversal will begin at the root object implied by this route (either the global root, or the object returned by the ``factory`` associated with this route). The syntax of the ``traverse`` argument is the same as it is for ``path``. For example, if the ``path`` provided is ``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 ``__getitem__`` will be called with the name ``1`` during the traversal phase. If the ``1`` object exists, it will become the ``context`` of the request. The Traversal narrative has more information about traversal. If the traversal path contains segment marker names which are not present in the path argument, a runtime error will occur. The ``traverse`` pattern should not contain segment markers that do not exist in the ``path``. A similar combining of routing and traversal is available when a route is matched which contains a ``*traverse`` remainder marker in its path. The ``traverse`` argument allows you to associate route patterns with an arbitrary traversal path without using a a ``*traverse`` remainder marker; instead you can use other match information. Note that the ``traverse`` argument is ignored when attached to a route that has a ``*traverse`` remainder marker in its path.
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-04-07- Replace the statement ``path = path.rstrip('/').lstrip('/')`` withChris McDonough
the simpler ``path = path.strip('/')`` in the ``repoze.bfg.traversal.traversal_path`` function.
2010-02-06- Remove magical feature of ``repoze.bfg.url.model_url`` whichChris McDonough
prepended a fully-expanded urldispatch route URL before a the model's path if it was noticed that the request had matched a route. This feature was ill-conceived, and didn't work in all scenarios.
2010-01-18Prep for b1Chris McDonough
Merge a bunch of paper-based docs fixes Configure logging during bfgshell.
2009-12-30Spellcheck.Chris McDonough
2009-12-24Roles.Chris McDonough
2009-12-09- General documentation freshening which takes imperativeChris McDonough
configuration into account in more places and uses glossary references more liberally.
2009-11-27Cleanup.Chris McDonough
2009-11-23- The ``repoze.bfg.scripting.get_root`` API now uses a 'real' WebObChris McDonough
request rather than a FakeRequest when it sets up the request as a threadlocal. - The ``repoze.bfg.traversal.traverse`` API now uses a 'real' WebOb request rather than a FakeRequest when it calls the traverser. - The ``repoze.bfg.request.FakeRequest`` class has been removed. ``repoze.bfg.url.route_url`` ``repoze.bfg.url.model_url`` ``repoze.bfg.url.static_url`` ``repoze.bfg.traversal.virtual_root`` Each of these functions now expects to be called with a request object that has a ``registry`` attribute which represents the current ZCA registry. Get rid of extraneous uses of ZCA threadlocal API.
2009-11-19Rearrange things to try to avoid circular import deps.Chris McDonough
2009-11-04- The ``bfgshell`` command did not function properly; it was stillChris McDonough
expecting to be able to call the root factory with a bare ``environ`` rather than a request object. - The ``repoze.bfg.scripting.get_app`` function now expects a ``request`` object as its second argument rather than an ``environ``.
2009-11-01- Deal with a potential circref in the traversal module.Chris McDonough
2009-10-30- The ``__call__`` of a plugin "traverser" implementation (registeredChris McDonough
as an adapter for ``ITraverser`` or ``ITraverserFactory``) will now receive a *request* as the single argument to its ``__call__`` method. In previous versions it was passed a WSGI ``environ`` object. The request object passed to the factory implements dictionary-like methods in such a way that existing traverser code which expects to be passed an environ will continue to work. - Fix docs.
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-10-26Readd backward compat for ITraverserFactory -> ITraverser change.Chris McDonough
2009-10-26Revert 6873, as it introduces an unnecessary providedBy for each request in ↵Chris McDonough
the 99% case, and its behavior can be emulated by returning a root object that implements some interface and registering a traverser for that interface.
2009-10-26The root factory may now return an object which implements ``ITraverser`` ↵Malthe Borch
directly. In this case, no adaptation is done before traversal. This feature is added such that a routes factory can implement its own traversal logic without establishing an artificial context only to get a hook into the traversal machinery.
2009-10-26Adapt to ``ITraverser`` instead of ``ITraverserFactory``. While this change ↵Malthe Borch
breaks backwards compatibility, migration is trivial.
2009-10-26Refactor; the ``_traverse`` is only used internally; the ``traverser`` ↵Malthe Borch
argument is never used. Note that this refactoring does away with a surplus traverser factory lookup.
2009-09-24- Sped up ``repoze.bfg.traversal.ModelGraphTraverser:__call__``Chris McDonough
slightly.
2009-09-23- Speed up ``repoze.bfg.traversal.model_path``.Chris McDonough
- Speed up ``repoze.bfg.traversal.model_path_tuple`` slightly. - Speed up ``repoze.bfg.traversal.traverse`` slightly. - In 0.8a7, the return value expected from an object implementing ``ITraverserFactory`` was changed from a sequence of values to a dictionary containing the keys ``context``, ``view_name``, ``subpath``, ``traversed``, ``virtual_root``, ``virtual_root_path``, and ``root``. Until now, old-style traversers which returned a sequence have continued to work but have generated a deprecation warning. In this release, traversers which return a sequence instead of a dictionary will no longer work.
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-21Minor speed tweak and coverage.Chris McDonough
2009-09-20- The way ``bfg_view`` declarations are scanned for has been modified.Chris McDonough
This should have no external effects. - An object implementing the ``IRenderer`` interface (and ``ITemplateRenderer`, which is a subclass of ``IRenderer``) must now accept an extra ``system`` argument in its ``__call__`` method implementation. Values computed by the system (as opposed to by the view) are passed by the system in the ``system`` parameter, which will always be a dictionary. Keys in the dictionary include: ``view`` (the view object that returned the value), ``renderer_name`` (the template name or simple name of the renderer), ``context`` (the context object passed to the view), and ``request`` (the request object passed to the view). Previously only ITemplateRenderers received system arguments as elements inside the main ``value`` dictionary.
2009-09-20- Speed: do not register an ITraverserFactory in configure.zcml;Chris McDonough
instead rely on queryAdapter and a manual default to ModelGraphTraverser. - Speed: do not register an IContextURL in configure.zcml; instead rely on queryAdapter and a manual default to TraversalContextURL. - General speed microimprovements for helloworld benchmark: replace try/excepts with statements which use 'in' keyword.
2009-09-18Accept a traverser rather than a registry in _traverse.Chris McDonough
2009-09-18Compulsive import reorderings.Chris McDonough
2009-08-04Reverse.Chris McDonough
2009-08-04- Allow ``repoze.bfg.traversal.find_interface`` API to use a classChris McDonough
object as the argument to compare against the ``model`` passed in. This means you can now do ``find_interface(model, SomeClass)`` and the first object which is found in the lineage which has ``SomeClass`` as its class (or the first object found which has ``SomeClass`` as any of its superclasses) will be returned.
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-24Merge noroutes branch to trunk.Chris McDonough
2009-06-24- ``model_url`` when passed a request that was generated as a resultChris McDonough
of a route match would fail in a call to ``route.generate``.
2009-06-22Useless marker.Chris McDonough
2009-06-22We weren't computing the virtual root correctly in a corner case.Chris McDonough
2009-06-22More micro-optimizations to the default traverser.Chris McDonough
Fix registerModels to use the right traversal info names.
2009-06-22- The values of ``subpath``, ``traversed``, and ``virtual_root_path``Chris McDonough
attached to the request object are always now tuples instead of lists (performance).
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-18- The matchdict related to the matching of a Routes route is availableChris McDonough
on the request as the ``matchdict`` attribute: ``request.matchdict``. If no route matched, this attribute will be None.
2009-06-15- Move LRU cache implementation into a separate packageChris McDonough
(``repoze.lru``).
2009-06-11Microspeedups.Chris McDonough
2009-06-11Merge unifyroutesandtraversal branch into trunkChris McDonough
2009-05-27- Remove backwards compatibility alias forChris McDonough
``repoze.bfg.traversal.split_path`` (deprecated since 0.6.5). This must now be imported as ``repoze.bfg.traversal.traversal_path``).