diff options
| author | Chris McDonough <chrism@agendaless.com> | 2010-07-12 13:50:49 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2010-07-12 13:50:49 +0000 |
| commit | 0482bd06bcde5601ea2ab3b01b774e03f92160b7 (patch) | |
| tree | 5b182307301e402a343977fb44828696dc119d54 /repoze/bfg/traversal.py | |
| parent | 9336d44d79232b021cc5f871aa43a384958e1920 (diff) | |
| download | pyramid-0482bd06bcde5601ea2ab3b01b774e03f92160b7.tar.gz pyramid-0482bd06bcde5601ea2ab3b01b774e03f92160b7.tar.bz2 pyramid-0482bd06bcde5601ea2ab3b01b774e03f92160b7.zip | |
- New internal exception: ``repoze.bfg.exceptions.URLDecodeError``.
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.
Diffstat (limited to 'repoze/bfg/traversal.py')
| -rw-r--r-- | repoze/bfg/traversal.py | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/repoze/bfg/traversal.py b/repoze/bfg/traversal.py index cf2a808e8..d45881a3b 100644 --- a/repoze/bfg/traversal.py +++ b/repoze/bfg/traversal.py @@ -10,6 +10,7 @@ from repoze.bfg.interfaces import ITraverser from repoze.bfg.interfaces import VH_ROOT_KEY from repoze.bfg.encode import url_quote +from repoze.bfg.exceptions import URLDecodeError from repoze.bfg.location import lineage from repoze.bfg.request import Request from repoze.bfg.threadlocal import get_current_registry @@ -129,7 +130,7 @@ def model_path(model, *elements): ``__name__`` which (by error) is a dictionary, the :func:`repoze.bfg.traversal.model_path` function will attempt to append it to a string and it will cause a - :exc:`TypeError`. + :exc:`repoze.bfg.exceptions.URLDecodeError`. .. note:: The :term:`root` model *must* have a ``__name__`` attribute with a value of either ``None`` or the empty @@ -251,13 +252,14 @@ def traverse(model, path): Unicode during traversal: Each segment is URL-unquoted, and decoded into Unicode. Each segment is assumed to be encoded using the UTF-8 encoding (or a subset, such as ASCII); a - :exc:`TypeError` is raised if a segment cannot be decoded. If a - segment name is empty or if it is ``.``, it is ignored. If a - segment name is ``..``, the previous segment is deleted, and the - ``..`` is ignored. As a result of this process, the return values - ``view_name``, each element in the ``subpath``, each element in - ``traversed``, and each element in the ``virtual_root_path`` will - be Unicode as opposed to a string, and will be URL-decoded. + :exc:`repoze.bfg.exceptions.URLDecodeError` is raised if a segment + cannot be decoded. If a segment name is empty or if it is ``.``, + it is ignored. If a segment name is ``..``, the previous segment + is deleted, and the ``..`` is ignored. As a result of this + process, the return values ``view_name``, each element in the + ``subpath``, each element in ``traversed``, and each element in + the ``virtual_root_path`` will be Unicode as opposed to a string, + and will be URL-decoded. """ if hasattr(path, '__iter__'): @@ -370,11 +372,11 @@ def traversal_path(path): traverse a graph. The ``PATH_INFO`` is split on slashes, creating a list of segments. Each segment is URL-unquoted, and decoded into Unicode. Each segment is assumed to be encoded using the - UTF-8 encoding (or a subset, such as ASCII); a :exc:`TypeError` is - raised if a segment cannot be decoded. If a segment name is empty - or if it is ``.``, it is ignored. If a segment name is ``..``, - the previous segment is deleted, and the ``..`` is ignored. - Examples: + UTF-8 encoding (or a subset, such as ASCII); a + :exc:`repoze.bfg.exceptions.URLDecodeError` is raised if a segment + cannot be decoded. If a segment name is empty or if it is ``.``, + it is ignored. If a segment name is ``..``, the previous segment + is deleted, and the ``..`` is ignored. Examples: ``/`` @@ -432,9 +434,10 @@ def traversal_path(path): else: try: segment = segment.decode('utf-8') - except UnicodeDecodeError: - raise TypeError('Could not decode path segment %r using the ' - 'UTF-8 decoding scheme' % segment) + except UnicodeDecodeError, e: + raise URLDecodeError( + e.encoding, e.object, e.start, e.end, e.reason + ) clean.append(segment) return tuple(clean) |
