# HG changeset patch # User paulb # Date 1202068645 0 # Node ID 73e60be1e6305a50f5e69453264758563ecd56a3 # Parent 140d4468641b8af9188bae7338fe45b8b743e767 [project @ 2008-02-03 19:57:25 by paulb] Added encode_url_without_query method. diff -r 140d4468641b -r 73e60be1e630 WebStack/Generic.py --- a/WebStack/Generic.py Sun Feb 03 19:57:00 2008 +0000 +++ b/WebStack/Generic.py Sun Feb 03 19:57:25 2008 +0000 @@ -34,7 +34,7 @@ directors. """ -import urllib +import urllib, urlparse from WebStack.Helpers.Request import Cookie, parse_header_value, ContentType, HeaderValue class EndOfResponse(Exception): @@ -241,6 +241,18 @@ except UnicodeError: return unicode(value, self.safe_default_charset) + def encode_url_without_query(self, url, encoding=None): + + """ + Encode the given full 'url', using the optional 'encoding' (if specified) or the + default encoding where 'encoding' is not specified, and produce a suitable encoded + URL. This method effectively performs URL-encoding on the path of 'url', leaving + the protocol scheme and host information intact. + """ + + scheme, netloc, path, query, fragment = urlparse.urlsplit(url) + return scheme + "://" + netloc + self.encode_path(path, encoding) + def encode_path(self, path, encoding=None): """