@@ -135,11 +135,26 @@ def to_unicode_optional_iterator(x):
135
135
assert 'is not iterable' in str (e )
136
136
return x
137
137
else :
138
- return [ to_unicode (e ) for e in l ]
138
+ return [ to_unicode (e ) for e in l ]
139
+
140
+ def to_utf8_optional_iterator (x ):
141
+ """
142
+ Raise TypeError if x is a str or if x is an iterable which
143
+ contains a str.
144
+ """
145
+ if isinstance (x , basestring ):
146
+ return to_utf8 (x )
147
+
148
+ try :
149
+ l = list (x )
150
+ except TypeError , e :
151
+ assert 'is not iterable' in str (e )
152
+ return x
153
+ else :
154
+ return [ to_utf8_if_string (e ) for e in l ]
139
155
140
156
def escape (s ):
141
157
"""Escape a URL including any /."""
142
- s = to_unicode (s )
143
158
return urllib .quote (s .encode ('utf-8' ), safe = '~' )
144
159
145
160
def generate_timestamp ():
@@ -386,10 +401,14 @@ def to_header(self, realm=''):
386
401
387
402
def to_postdata (self ):
388
403
"""Serialize as post data for a POST request."""
404
+ d = {}
405
+ for k , v in self .iteritems ():
406
+ d [k .encode ('utf-8' )] = to_utf8_optional_iterator (v )
407
+
389
408
# tell urlencode to deal with sequence values and map them correctly
390
409
# to resulting querystring. for example self["k"] = ["v1", "v2"] will
391
410
# result in 'k=v1&k=v2' and not k=%5B%27v1%27%2C+%27v2%27%5D
392
- return urllib .urlencode (self , True ).replace ('+' , '%20' )
411
+ return urllib .urlencode (d , True ).replace ('+' , '%20' )
393
412
394
413
def to_url (self ):
395
414
"""Serialize as a URL for a GET request."""
@@ -797,7 +816,7 @@ def check(self, request, consumer, token, signature):
797
816
798
817
class SignatureMethod_HMAC_SHA1 (SignatureMethod ):
799
818
name = 'HMAC-SHA1'
800
-
819
+
801
820
def signing_base (self , request , consumer , token ):
802
821
if not hasattr (request , 'normalized_url' ) or request .normalized_url is None :
803
822
raise ValueError ("Base URL for request is not set." )
0 commit comments