From fb93f91be989665d3116ae6518f1659c749ca178 Mon Sep 17 00:00:00 2001 From: Josh Gerdes Date: Fri, 17 Feb 2012 21:12:39 -0600 Subject: [PATCH] Added config value to allow user-defined encode safe list to be used with the encoding of url values (media_url, content_url, and full_url). I wanted to use absolute urls for the media_url config value (I did not want to encode : or /). --- hyde/model.py | 1 + hyde/site.py | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/hyde/model.py b/hyde/model.py index 7c91e30..4e33cc0 100644 --- a/hyde/model.py +++ b/hyde/model.py @@ -155,6 +155,7 @@ class Config(Expando): layout_root='layout', media_url='/media', base_url="/", + encode_safe=None, not_found='404.html', plugins = [], ignore = [ "*~", "*.bak", ".hg", ".git", ".svn"], diff --git a/hyde/site.py b/hyde/site.py index be17521..5fff397 100644 --- a/hyde/site.py +++ b/hyde/site.py @@ -425,6 +425,8 @@ class Site(object): .replace(os.sep, '/').encode("utf-8") if safe is not None: return quote(fpath, safe) + elif self.config.encode_safe is not None: + return quote(fpath, self.config.encode_safe) else: return quote(fpath) @@ -438,6 +440,8 @@ class Site(object): .replace(os.sep, '/').encode("utf-8") if safe is not None: return quote(fpath, safe) + elif self.config.encode_safe is not None: + return quote(fpath, self.config.encode_safe) else: return quote(fpath) @@ -447,6 +451,9 @@ class Site(object): configuration and returns the appropriate url. The return value is url encoded. """ + if safe is None and self.config.encode_safe is not None: + safe = self.config.encode_safe + if urlparse.urlparse(path)[:2] != ("",""): return path if self.is_media(path):