You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
raise an exception if the URL passed in is not a unicode object nor ascii
We can't submit a correct URL with arbitrary bytes -- we have to submit a utf-8 encoded unicode string. (Otherwise we'll cause either a rejection or a signature mismatch in the server, which is what has happened at SimpleGeo.)
If the caller passes in non-ascii things in a str then it would be better for them to change their code to decode it to unicode before passing it in than for us to decode it, since they have a better chance of knowing what encoding it is in -- if we did it we would be guessing.
""" Returns None if s is a unicode or an ascii string, else
93
+
returns the UnicodeDecodeError that results from attempting to
94
+
decode it as ascii. """
95
+
try:
96
+
s.decode('ascii')
97
+
exceptUnicodeDecodeError, le:
98
+
returnle
99
+
91
100
defescape(s):
92
101
"""Escape a URL including any /."""
93
-
returnurllib.quote(s, safe='~')
102
+
encerr=check_for_bad_encoding(s)
103
+
ifencerr:
104
+
raiseError('You are required to pass either a unicode object or an ascii string here. You passed a Python string object which contained non-ascii: %r. The UnicodeDecodeError that resulted from attempting to interpret it as ascii was: %s'% (encerr,))
raiseValueError("You are required to pass either a unicode object or an ascii string for `url'. You passed a Python string object which contained non-ascii: %r. The UnicodeDecodeError that resulted from attempting to interpret it as ascii was: %s"% (url, encerr,))
0 commit comments