Skip to content

Commit 9234cad

Browse files
committed
Merge branch 'master' of github.com:joestump/python-oauth2
2 parents 82dd2cd + f0e846f commit 9234cad

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

oauth2/__init__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ def to_url(self):
420420
query = base_url[4]
421421
query = parse_qs(query)
422422
for k, v in self.items():
423-
query.setdefault(k, []).append(v)
423+
query.setdefault(k, []).append(to_utf8_optional_iterator(v))
424424

425425
try:
426426
scheme = base_url.scheme
@@ -615,8 +615,7 @@ def _split_url_string(param_str):
615615
class Client(httplib2.Http):
616616
"""OAuthClient is a worker to attempt to execute a request."""
617617

618-
def __init__(self, consumer, token=None, cache=None, timeout=None,
619-
proxy_info=None):
618+
def __init__(self, consumer, token=None, **kwargs):
620619

621620
if consumer is not None and not isinstance(consumer, Consumer):
622621
raise ValueError("Invalid consumer.")
@@ -628,7 +627,7 @@ def __init__(self, consumer, token=None, cache=None, timeout=None,
628627
self.token = token
629628
self.method = SignatureMethod_HMAC_SHA1()
630629

631-
httplib2.Http.__init__(self, cache=cache, timeout=timeout, proxy_info=proxy_info)
630+
super(Client, self).__init__(**kwargs)
632631

633632
def set_signature_method(self, method):
634633
if not isinstance(method, SignatureMethod):

tests/test_oauth.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import time
3232
import urllib
3333
import urlparse
34-
from types import ListType
3534
import mock
3635
import httplib2
3736

@@ -42,7 +41,7 @@
4241
from cgi import parse_qs, parse_qsl
4342

4443

45-
sys.path[0:0] = [os.path.join(os.path.dirname(__file__), ".."),]
44+
sys.path[0:0] = [os.path.join(os.path.dirname(__file__), "..")]
4645

4746

4847
class TestError(unittest.TestCase):
@@ -375,6 +374,32 @@ def test_get_nonoauth_parameters(self):
375374
req = oauth.Request("GET", "http://example.com", params)
376375
self.assertEquals(other_params, req.get_nonoauth_parameters())
377376

377+
def test_to_url_works_with_non_ascii_parameters(self):
378+
379+
oauth_params = {
380+
'oauth_consumer': 'asdfasdfasdf'
381+
}
382+
383+
other_params = {
384+
u'foo': u'baz',
385+
u'bar': u'foo',
386+
u'multi': [u'FOO',u'BAR'],
387+
u'uni_utf8': u'\xae',
388+
u'uni_unicode': u'\u00ae',
389+
u'uni_unicode_2': u'åÅøØ',
390+
}
391+
392+
params = oauth_params
393+
params.update(other_params)
394+
395+
req = oauth.Request("GET", "http://example.com", params)
396+
self.assertEquals(
397+
req.to_url(),
398+
'http://example.com?oauth_consumer=asdfasdfasdf&'
399+
'uni_unicode_2=%C3%A5%C3%85%C3%B8%C3%98&'
400+
'uni_utf8=%C2%AE&multi=%5B%27FOO%27%2C+%27BAR%27%5D&'
401+
'uni_unicode=%C2%AE&bar=foo&foo=baz')
402+
378403
def test_to_header(self):
379404
realm = "http://sp.example.com/"
380405

0 commit comments

Comments
 (0)