Mercurial > piecrust2
diff piecrust/uriutil.py @ 329:422052d2e978
internal: Try handling URLs in a consistent way.
* Now URLs passed to, and returned from, routes will always be absolute URLs,
i.e. URLs including the site root.
* Validate the site root at config loading time to make sure it starts and ends
with a slash.
* Get rid of unused stuff.
* Add tests.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 31 Mar 2015 23:03:28 -0700 |
parents | b7ab1b503510 |
children | d4321317beae |
line wrap: on
line diff
--- a/piecrust/uriutil.py Tue Mar 31 22:38:56 2015 -0700 +++ b/piecrust/uriutil.py Tue Mar 31 23:03:28 2015 -0700 @@ -74,13 +74,20 @@ return pattern.sub(lambda m: reps[re.escape(m.group(0))], text) -def get_slug(app, uri): - site_root = app.config.get('site/root') - uri = uri[len(site_root):] - return uri.lstrip('/') +def split_uri(app, uri): + root = app.config.get('site/root') + uri_root = uri[:len(root)] + if uri_root != root: + raise Exception("URI '%s' is not a full URI." % uri) + uri = uri[len(root):] + return uri_root, uri def split_sub_uri(app, uri): + root = app.config.get('site/root') + if not uri.startswith(root): + raise Exception("URI '%s' is not a full URI." % uri) + pretty_urls = app.config.get('site/pretty_urls') if not pretty_urls: uri, ext = os.path.splitext(uri) @@ -97,5 +104,5 @@ if not pretty_urls: uri += ext - return (uri, page_num) + return uri, page_num