Parameters now can be of any type.

The patch by Eugene (9133d0f10e) is nice, because you don't have to
manually encode() the parameters yourself. But it sucks a little,
because all your parameter values must be unicodes now.

Proposed patch encodes unicodes to utf-8 and allows the olde strs and
longs (I love to use longs in 'id' fields somewhy).
This commit is contained in:
Edward Hades 2011-02-28 19:10:07 +08:00 committed by Ryan McGrath
parent 9f8c04b0f2
commit 4e690f5568

View file

@ -176,7 +176,7 @@ class Twython(object):
# Then open and load that shiiit, yo. TODO: check HTTP method and junk, handle errors/authentication
if fn['method'] == 'POST':
resp, content = self.client.request(base, fn['method'], urllib.urlencode(dict([k, v.encode('utf-8')] for k, v in kwargs.items())), headers = self.headers)
resp, content = self.client.request(base, fn['method'], urllib.urlencode(dict([k, Twython.encode(v)] for k, v in kwargs.items())), headers = self.headers)
else:
url = base + "?" + "&".join(["%s=%s" %(key, value) for (key, value) in kwargs.iteritems()])
resp, content = self.client.request(url, fn['method'], headers = self.headers)
@ -463,3 +463,9 @@ class Twython(object):
except:
pass
return text
@staticmethod
def encode(text):
if isinstance(text, (str,unicode)):
return Twython.unicode2utf8(text)
return str(text)