Allow additional karg parameters that are not listed in allowed_param.
authorJoshua <jroesslein@gmail.com>
Thu, 28 Jan 2010 18:20:07 +0000 (12:20 -0600)
committerJoshua <jroesslein@gmail.com>
Thu, 28 Jan 2010 18:22:56 +0000 (12:22 -0600)
This allows Tweepy to support future parameters twitter may add
without having to patch the library.

CHANGELOG
tweepy/binder.py

index 901caf58fe8645e0331121d8de47f4215eefd521..7efd33706b924da98993b967aad8fd0a1fc118bd 100644 (file)
--- 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
index 37a7cd4326b06acf6a242592b3634fc694a1d034..453b024c2b8d4a63cff0b27203a389eedcf5d79e 100644 (file)
@@ -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):