From f2fb17e4c5db1869e99f11f4fad030a396dbda07 Mon Sep 17 00:00:00 2001 From: Harmon Date: Fri, 29 Jan 2021 10:26:16 -0600 Subject: [PATCH] Replace APIMethod.require_auth with APIMethod.execute kwarg Replace APIMethod.require_auth with APIMethod.execute require_auth keyword-only argument --- tweepy/binder.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tweepy/binder.py b/tweepy/binder.py index 07f11af..ac3f5f8 100644 --- a/tweepy/binder.py +++ b/tweepy/binder.py @@ -23,15 +23,9 @@ class APIMethod: self.payload_type = kwargs.pop('payload_type', None) self.payload_list = kwargs.pop('payload_list', False) self.allowed_param = kwargs.pop('allowed_param', []) - self.require_auth = kwargs.pop('require_auth', False) self.upload_api = kwargs.pop('upload_api', False) self.session = requests.Session() - # If authentication is required and no credentials - # are provided, throw an error. - if self.require_auth and not api.auth: - raise TweepError('Authentication required!') - self.parser = kwargs.pop('parser', api.parser) self.headers = kwargs.pop('headers', {}) self.build_parameters(args, kwargs) @@ -72,7 +66,12 @@ class APIMethod: log.debug("PARAMS: %r", self.session.params) def execute(self, method, *, json_payload=None, post_data=None, - return_cursors=False, use_cache=True): + require_auth=False, return_cursors=False, use_cache=True): + # If authentication is required and no credentials + # are provided, throw an error. + if require_auth and not self.api.auth: + raise TweepError('Authentication required!') + self.api.cached_result = False # Build the request URL @@ -186,6 +185,7 @@ def bind_api(*args, **kwargs): http_method = kwargs.pop('method', 'GET') json_payload = kwargs.pop('json_payload', None) post_data = kwargs.pop('post_data', None) + require_auth = kwargs.pop('require_auth', False) return_cursors = kwargs.pop('return_cursors', False) use_cache = kwargs.pop('use_cache', True) @@ -196,7 +196,8 @@ def bind_api(*args, **kwargs): else: return method.execute( http_method, json_payload=json_payload, post_data=post_data, - return_cursors=return_cursors, use_cache=use_cache + require_auth=require_auth, return_cursors=return_cursors, + use_cache=use_cache ) finally: method.session.close() -- 2.25.1