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/urldispatch.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/urldispatch.py')
| -rw-r--r-- | repoze/bfg/urldispatch.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/repoze/bfg/urldispatch.py b/repoze/bfg/urldispatch.py index 7a77fec5b..80880d8f0 100644 --- a/repoze/bfg/urldispatch.py +++ b/repoze/bfg/urldispatch.py @@ -3,6 +3,7 @@ from urllib import unquote from repoze.bfg.compat import all from repoze.bfg.encode import url_quote +from repoze.bfg.exceptions import URLDecodeError from repoze.bfg.traversal import traversal_path from repoze.bfg.traversal import quote_path_segment @@ -102,7 +103,15 @@ def _compile_route(route): if k == star: d[k] = traversal_path(v) else: - d[k] = unquote(v).decode('utf-8') + encoded = unquote(v) + try: + d[k] = encoded.decode('utf-8') + except UnicodeDecodeError, e: + raise URLDecodeError( + e.encoding, e.object, e.start, e.end, e.reason + ) + + return d |
