diff options
| author | Tom Christie | 2013-04-10 09:24:24 +0100 | 
|---|---|---|
| committer | Tom Christie | 2013-04-10 09:24:24 +0100 | 
| commit | 3f91379e4eaf07418a99fda1932af91511c55e7b (patch) | |
| tree | 7d2e5019bbb506564585d007c2819a5a56ba1efa /rest_framework/compat.py | |
| parent | c2280e34ece1867432c87a9654d31a708281b05a (diff) | |
| download | django-rest-framework-3f91379e4eaf07418a99fda1932af91511c55e7b.tar.bz2 | |
Fix 1.3 compat issue.  Closes #780
Diffstat (limited to 'rest_framework/compat.py')
| -rw-r--r-- | rest_framework/compat.py | 10 | 
1 files changed, 7 insertions, 3 deletions
| diff --git a/rest_framework/compat.py b/rest_framework/compat.py index 6551723a..067e9018 100644 --- a/rest_framework/compat.py +++ b/rest_framework/compat.py @@ -400,19 +400,23 @@ except ImportError:  try:      from django.utils.html import smart_urlquote  except ImportError: +    import re +    from django.utils.encoding import smart_str      try:          from urllib.parse import quote, urlsplit, urlunsplit      except ImportError:     # Python 2          from urllib import quote          from urlparse import urlsplit, urlunsplit +    unquoted_percents_re = re.compile(r'%(?![0-9A-Fa-f]{2})') +      def smart_urlquote(url):          "Quotes a URL if it isn't already quoted."          # Handle IDN before quoting.          scheme, netloc, path, query, fragment = urlsplit(url)          try: -            netloc = netloc.encode('idna').decode('ascii') # IDN -> ACE -        except UnicodeError: # invalid domain part +            netloc = netloc.encode('idna').decode('ascii')  # IDN -> ACE +        except UnicodeError:  # invalid domain part              pass          else:              url = urlunsplit((scheme, netloc, path, query, fragment)) @@ -421,7 +425,7 @@ except ImportError:          # contains a % not followed by two hexadecimal digits. See #9655.          if '%' not in url or unquoted_percents_re.search(url):              # See http://bugs.python.org/issue2637 -            url = quote(force_bytes(url), safe=b'!*\'();:@&=+$,/?#[]~') +            url = quote(smart_str(url), safe=b'!*\'();:@&=+$,/?#[]~')          return force_text(url) | 
