Commit 283320de authored by Michael (Doc) Norton's avatar Michael (Doc) Norton Committed by Joshua Roesslein
Browse files

Extract argument conversion to utility class

parent ad3cc4fc
......@@ -66,13 +66,9 @@ def bind_api(**config):
def build_parameters(self, args, kargs):
self.parameters = {}
for idx, arg in enumerate(args):
if isinstance(arg, unicode):
arg = arg.encode('utf-8')
elif not isinstance(arg, str):
arg = str(arg)
try:
self.parameters[self.allowed_param[idx]] = arg
self.parameters[self.allowed_param[idx]] = convert_to_utf8_str(arg)
except IndexError:
raise TweepError('Too many parameters supplied!')
......@@ -82,11 +78,7 @@ def bind_api(**config):
if k in self.parameters:
raise TweepError('Multiple values for parameter %s supplied!' % k)
if isinstance(arg, unicode):
arg = arg.encode('utf-8')
elif not isinstance(arg, str):
arg = str(arg)
self.parameters[k] = arg
self.parameters[k] = convert_to_utf8_str(arg)
def build_path(self):
for variable in re_path_template.findall(self.path):
......
......@@ -55,6 +55,16 @@ def unescape_html(text):
return re.sub("&#?\w+;", fixup, text)
def convert_to_utf8_str(arg):
# written by Michael Norton (http://docondev.blogspot.com/)
if isinstance(arg, unicode):
arg = arg.encode('utf-8')
elif not isinstance(arg, str):
arg = str(arg)
return arg
def import_simplejson():
try:
import simplejson as json
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment