Skip to content

Commit

Permalink
urllib.unqoute doesn't take 'safe' as an arg. Add a test and fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
calebbrown committed Apr 18, 2012
1 parent 7118970 commit e569fc1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion oauthlib/oauth1/rfc5849/utils.py
Expand Up @@ -104,7 +104,7 @@ def escape(u):
def unescape(s): def unescape(s):
if not isinstance(s, str): if not isinstance(s, str):
raise ValueError('Only string objects are unescapable.') raise ValueError('Only string objects are unescapable.')
return urllib.unquote(s, safe='~').decode('utf-8') return urllib.unquote(s).decode('utf-8')




def urlencode(query): def urlencode(query):
Expand Down
12 changes: 8 additions & 4 deletions tests/oauth1/rfc5849/test_utils.py
Expand Up @@ -39,7 +39,7 @@ class UtilsTests(TestCase):
oauth_signature_method="HMAC-SHA1", oauth_signature_method="HMAC-SHA1",
oauth_timestamp="137131201", oauth_timestamp="137131201",
oauth_nonce="7d8f3e4a", oauth_nonce="7d8f3e4a",
oauth_signature="djosJKDKJSD8743243%2Fjdk33klY%3D" """.strip() oauth_signature="djosJKDKJSD8743243%2Fjdk33klY%3D" """.strip()




def test_filter_params(self): def test_filter_params(self):
Expand Down Expand Up @@ -73,7 +73,7 @@ def test_filter_oauth_params(self):
# should not be present in the filtered params # should not be present in the filtered params
filtered_params = filter_oauth_params(self.sample_params_list) filtered_params = filter_oauth_params(self.sample_params_list)
self.assertEqual(len(filtered_params), 2) self.assertEqual(len(filtered_params), 2)

self.assertTrue(filtered_params[0][0].startswith('oauth')) self.assertTrue(filtered_params[0][0].startswith('oauth'))
self.assertTrue(filtered_params[1][0].startswith('oauth')) self.assertTrue(filtered_params[1][0].startswith('oauth'))


Expand All @@ -86,7 +86,7 @@ def test_filter_oauth_params(self):
# should not be present in the filtered params # should not be present in the filtered params
filtered_params = filter_oauth_params(self.sample_params_dict) filtered_params = filter_oauth_params(self.sample_params_dict)
self.assertEqual(len(filtered_params), 2) self.assertEqual(len(filtered_params), 2)

self.assertTrue(filtered_params[0][0].startswith('oauth')) self.assertTrue(filtered_params[0][0].startswith('oauth'))
self.assertTrue(filtered_params[1][0].startswith('oauth')) self.assertTrue(filtered_params[1][0].startswith('oauth'))


Expand All @@ -95,7 +95,7 @@ def test_utf8_str(self):
# check against crazy string # check against crazy string
crazy_string = "àçéghîłñôßûÿž♬♨♧" crazy_string = "àçéghîłñôßûÿž♬♨♧"
self.assertTrue(isinstance(utf8_str(crazy_string), str)) self.assertTrue(isinstance(utf8_str(crazy_string), str))

# check against crazy unicode # check against crazy unicode
crazy_unicode = utf8_str(u"àçéghîłñôßûÿž♬♨♧") crazy_unicode = utf8_str(u"àçéghîłñôßûÿž♬♨♧")
self.assertTrue(isinstance(crazy_unicode, str)) self.assertTrue(isinstance(crazy_unicode, str))
Expand Down Expand Up @@ -129,6 +129,10 @@ def test_escape(self):
self.assertRaises(ValueError, escape, "I am a string type. Not a unicode type.") self.assertRaises(ValueError, escape, "I am a string type. Not a unicode type.")
self.assertEqual(escape(u"I am a unicode type."), u"I%20am%20a%20unicode%20type.") self.assertEqual(escape(u"I am a unicode type."), u"I%20am%20a%20unicode%20type.")


def test_unescape(self):
self.assertRaises(ValueError, unescape, u"I am a unicode type. Not a string type.")
self.assertEqual(unescape("I%20am%20a%20unicode%20type."), u'I am a unicode type.')

def test_urlencode(self): def test_urlencode(self):


self.assertEqual(urlencode(self.sample_params_unicode_list), "notoauth=shouldnotbehere&oauth_consumer_key=9djdj82h48djs9d2&oauth_token=kkk9d7dh3k39sjv7&notoautheither=shouldnotbehere") self.assertEqual(urlencode(self.sample_params_unicode_list), "notoauth=shouldnotbehere&oauth_consumer_key=9djdj82h48djs9d2&oauth_token=kkk9d7dh3k39sjv7&notoautheither=shouldnotbehere")
Expand Down

0 comments on commit e569fc1

Please sign in to comment.