@@ -181,7 +181,7 @@ def escape(s):
181
181
try :
182
182
return urllib .quote (s .encode ('utf-8' ), safe = '~' )
183
183
except AttributeError :
184
- return urllib . parse .quote (s .encode ('utf-8' ), safe = '~' )
184
+ return urlparse .quote (s .encode ('utf-8' ), safe = '~' )
185
185
186
186
def generate_timestamp ():
187
187
"""Get seconds since epoch (UTC)."""
@@ -231,8 +231,10 @@ def __init__(self, key, secret):
231
231
def __str__ (self ):
232
232
data = {'oauth_consumer_key' : self .key ,
233
233
'oauth_consumer_secret' : self .secret }
234
-
235
- return urllib .urlencode (data )
234
+ try :
235
+ return urllib .urlencode (data )
236
+ except AttributeError :
237
+ return urlparse .urlencode (data )
236
238
237
239
238
240
class Token (object ):
@@ -300,7 +302,10 @@ def to_string(self):
300
302
301
303
if self .callback_confirmed is not None :
302
304
data ['oauth_callback_confirmed' ] = self .callback_confirmed
303
- return urllib .urlencode (data )
305
+ try :
306
+ return urllib .urlencode (data )
307
+ except AttributeError :
308
+ return urlparse .urlencode (data )
304
309
305
310
@staticmethod
306
311
def from_string (s ):
@@ -434,7 +439,10 @@ def to_postdata(self):
434
439
# tell urlencode to deal with sequence values and map them correctly
435
440
# to resulting querystring. for example self["k"] = ["v1", "v2"] will
436
441
# result in 'k=v1&k=v2' and not k=%5B%27v1%27%2C+%27v2%27%5D
437
- return urllib .urlencode (d , True ).replace ('+' , '%20' )
442
+ try :
443
+ return urllib .urlencode (d , True ).replace ('+' , '%20' )
444
+ except AttributeError :
445
+ return urlparse .urlencode (d , True ).replace ('+' , '%20' )
438
446
439
447
def to_url (self ):
440
448
"""Serialize as a URL for a GET request."""
@@ -462,9 +470,14 @@ def to_url(self):
462
470
params = base_url [3 ]
463
471
fragment = base_url [5 ]
464
472
465
- url = (scheme , netloc , path , params ,
466
- urllib .urlencode (query , True ), fragment )
467
- return urlparse .urlunparse (url )
473
+ try :
474
+ url = (scheme , netloc , path , params ,
475
+ urllib .urlencode (query , True ), fragment )
476
+ return urllib .urlunparse (url )
477
+ except AttributeError :
478
+ url = (scheme , netloc , path , params ,
479
+ urlparse .urlencode (query , True ), fragment )
480
+ return urlparse .urlunparse (url )
468
481
469
482
def get_parameter (self , parameter ):
470
483
ret = self .get (parameter )
@@ -512,7 +525,10 @@ def get_normalized_parameters(self):
512
525
items .extend (url_items )
513
526
514
527
items .sort ()
515
- encoded_str = urllib .urlencode (items )
528
+ try :
529
+ encoded_str = urllib .urlencode (items )
530
+ except AttributeError :
531
+ encoded_str = urlparse .urlencode (items )
516
532
# Encode signature parameters per Oauth Core 1.0 protocol
517
533
# spec draft 7, section 3.6
518
534
# (http://tools.ietf.org/html/draft-hammer-oauth-07#section-3.6)
@@ -641,7 +657,7 @@ def _split_header(header):
641
657
try :
642
658
params [param_parts [0 ]] = urllib .unquote (param_parts [1 ].strip ('\" ' ))
643
659
except AttributeError :
644
- params [param_parts [0 ]] = urllib . parse .unquote (param_parts [1 ].strip ('\" ' ))
660
+ params [param_parts [0 ]] = urlparse .unquote (param_parts [1 ].strip ('\" ' ))
645
661
return params
646
662
647
663
@staticmethod
@@ -652,7 +668,7 @@ def _split_url_string(param_str):
652
668
try :
653
669
parameters [k ] = urllib .unquote (v [0 ])
654
670
except AttributeError :
655
- parameters [k ] = urllib . parse .unquote (v [0 ])
671
+ parameters [k ] = urlparse .unquote (v [0 ])
656
672
return parameters
657
673
658
674
@@ -704,13 +720,19 @@ def request(self, uri, method="GET", body='', headers=None,
704
720
parameters = parameters , body = body , is_form_encoded = is_form_encoded )
705
721
706
722
req .sign_request (self .method , self .consumer , self .token )
707
-
708
- schema , rest = urllib .splittype (uri )
723
+
724
+ try :
725
+ schema , rest = urllib .splittype (uri )
726
+ except AttributeError :
727
+ schema , rest = urlparse .splittype (uri )
709
728
if rest .startswith ('//' ):
710
729
hierpart = '//'
711
730
else :
712
731
hierpart = ''
713
- host , rest = urllib .splithost (rest )
732
+ try :
733
+ host , rest = urllib .splithost (rest )
734
+ except AttributeError :
735
+ host , rest = urlparse .splithost (rest )
714
736
715
737
realm = schema + ':' + hierpart + host
716
738
0 commit comments