WebStack

Changeset

754:73e60be1e630
2008-02-03 paulb raw files shortlog changelog graph [project @ 2008-02-03 19:57:25 by paulb] Added encode_url_without_query method.
WebStack/Generic.py (file)
     1.1 --- a/WebStack/Generic.py	Sun Feb 03 19:57:00 2008 +0000
     1.2 +++ b/WebStack/Generic.py	Sun Feb 03 19:57:25 2008 +0000
     1.3 @@ -34,7 +34,7 @@
     1.4  directors.
     1.5  """
     1.6  
     1.7 -import urllib
     1.8 +import urllib, urlparse
     1.9  from WebStack.Helpers.Request import Cookie, parse_header_value, ContentType, HeaderValue
    1.10  
    1.11  class EndOfResponse(Exception):
    1.12 @@ -241,6 +241,18 @@
    1.13          except UnicodeError:
    1.14              return unicode(value, self.safe_default_charset)
    1.15  
    1.16 +    def encode_url_without_query(self, url, encoding=None):
    1.17 +
    1.18 +        """
    1.19 +        Encode the given full 'url', using the optional 'encoding' (if specified) or the
    1.20 +        default encoding where 'encoding' is not specified, and produce a suitable encoded
    1.21 +        URL. This method effectively performs URL-encoding on the path of 'url', leaving
    1.22 +        the protocol scheme and host information intact.
    1.23 +        """
    1.24 +
    1.25 +        scheme, netloc, path, query, fragment = urlparse.urlsplit(url)
    1.26 +        return scheme + "://" + netloc + self.encode_path(path, encoding)
    1.27 +
    1.28      def encode_path(self, path, encoding=None):
    1.29  
    1.30          """