Ticket #11522: ticket11522_puny_code.patch
File ticket11522_puny_code.patch, 2.5 KB (added by , 15 years ago) |
---|
-
django/http/__init__.py
317 317 yield value 318 318 319 319 def __setitem__(self, header, value): 320 header, value = self._convert_to_ascii(header, value) 320 # Conversion to ASCII is done later on using iri_to_uri for a proper 321 # puny-code friendly encoding. 322 # 323 # See: HttpRequest.build_absolute_uri 324 # fix_location_header 325 if header != 'Location' and isinstance(value, unicode): 326 header, value = self._convert_to_ascii(header, value) 321 327 self._headers[header.lower()] = (header, value) 322 328 323 329 def __delitem__(self, header): -
django/utils/encoding.py
1 1 import types 2 2 import urllib 3 import urlparse 3 4 import locale 4 5 import datetime 5 6 import codecs … … 136 137 # section 3.1 of RFC 3987. 137 138 if iri is None: 138 139 return iri 139 return urllib.quote(smart_str(iri), safe='/#%[]=:;$&()+,!?*')140 140 141 if isinstance(iri, unicode): 142 parts = urlparse.urlsplit(iri) 141 143 144 if parts.hostname: 145 hostname = parts.hostname.encode('idna') 146 else: 147 hostname = None 148 149 # Fix auth part 150 if parts.username or parts.password: 151 username = urllib.quote(parts.username.encode("utf-8")) 152 if parts.password: 153 password = urllib.quote(parts.password.encode("utf-8")) 154 username = username + ":" + password 155 hostname = username + "@" + hostname 156 157 # add the port 158 if parts.port: 159 hostname += ":" + str(parts.port) 160 161 path = urllib.quote(parts.path.encode("utf-8"), safe="/:~+") 162 query = urllib.quote(parts.query.encode("utf-8"), safe="=%&[]:;$()+,!?*/") 163 164 return urlparse.urlunsplit([parts.scheme, 165 hostname, 166 path, 167 query, 168 parts.fragment]) 169 else: 170 return urllib.quote(smart_str(iri), safe='/#%[]=:;$&()+,!?*') 171 172 142 173 # The encoding of the default system locale but falls back to the 143 174 # given fallback encoding if the encoding is unsupported by python or could 144 175 # not be determined. See tickets #10335 and #5846