From 4e690f5568b450b27d0f54691e406219d5567832 Mon Sep 17 00:00:00 2001 From: Edward Hades Date: Mon, 28 Feb 2011 19:10:07 +0800 Subject: [PATCH] Parameters now can be of any type. The patch by Eugene (9133d0f10ec) 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). --- twython/twython.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/twython/twython.py b/twython/twython.py index 7ce8973..7232c20 100644 --- a/twython/twython.py +++ b/twython/twython.py @@ -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)