From 536319e92aa400ba5096584896904d9533b8b28b Mon Sep 17 00:00:00 2001 From: Joshua Date: Thu, 28 Jan 2010 12:20:07 -0600 Subject: [PATCH] Allow additional karg parameters that are not listed in allowed_param. This allows Tweepy to support future parameters twitter may add without having to patch the library. --- CHANGELOG | 7 +++++++ tweepy/binder.py | 51 +++++++++++++++++++++--------------------------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 901caf5..7efd337 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,13 @@ All changes made to the library that might affect applications during upgrade will be listed here. + +1.5 -> 1.6 +=========================== ++ API methods now allow for kargs that are not listed in the + allowed_params list. This way Tweepy can support future parameters + twitter adds without having the patch the library. + 1.4 -> 1.5 =========================== + Models diff --git a/tweepy/binder.py b/tweepy/binder.py index 37a7cd4..453b024 100644 --- a/tweepy/binder.py +++ b/tweepy/binder.py @@ -44,35 +44,28 @@ def bind_api(path, parser, allowed_param=[], method='GET', require_auth=False, headers = kargs.pop('headers', {}) # build parameter dict - if allowed_param: - parameters = {} - for idx, arg in enumerate(args): - if isinstance(arg, unicode): - arg = arg.encode('utf-8') - elif not isinstance(arg, str): - arg = str(arg) + 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: - parameters[allowed_param[idx]] = arg - except IndexError: - raise TweepError('Too many parameters supplied!') - for k, arg in kargs.items(): - if arg is None: - continue - if k in parameters: - raise TweepError('Multiple values for parameter %s supplied!' % k) - if k not in allowed_param: - raise TweepError('Invalid parameter %s supplied!' % k) - - if isinstance(arg, unicode): - arg = arg.encode('utf-8') - elif not isinstance(arg, str): - arg = str(arg) - parameters[k] = arg - else: - if len(args) > 0 or len(kargs) > 0: - raise TweepError('This method takes no parameters!') - parameters = None + try: + parameters[allowed_param[idx]] = arg + except IndexError: + raise TweepError('Too many parameters supplied!') + for k, arg in kargs.items(): + if arg is None: + continue + if k in 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) + parameters[k] = arg # Pick correct URL root to use if search_api is False: @@ -81,7 +74,7 @@ def bind_api(path, parser, allowed_param=[], method='GET', require_auth=False, api_root = api.search_root # Build the request URL - if parameters: + if len(parameters): # Replace any template variables in path tpath = str(path) for template in re_path_template.findall(tpath): -- 2.25.1