2323 API_HOST ,
2424 WEB_HOST ,
2525 pinned_session ,
26+ DEFAULT_TIMEOUT ,
2627)
2728
2829if six .PY3 :
@@ -130,7 +131,7 @@ def __repr__(self):
130131class DropboxOAuth2FlowBase (object ):
131132
132133 def __init__ (self , consumer_key , consumer_secret = None , locale = None , token_access_type = 'legacy' ,
133- scope = None , include_granted_scopes = None , use_pkce = False ):
134+ scope = None , include_granted_scopes = None , use_pkce = False , timeout = DEFAULT_TIMEOUT ):
134135 if scope is not None and (len (scope ) == 0 or not isinstance (scope , list )):
135136 raise BadInputException ("Scope list must be of type list" )
136137 if token_access_type is not None and token_access_type not in TOKEN_ACCESS_TYPES :
@@ -148,6 +149,7 @@ def __init__(self, consumer_key, consumer_secret=None, locale=None, token_access
148149 self .requests_session = pinned_session ()
149150 self .scope = scope
150151 self .include_granted_scopes = include_granted_scopes
152+ self ._timeout = timeout
151153
152154 if use_pkce :
153155 self .code_verifier = _generate_pkce_code_verifier ()
@@ -195,7 +197,7 @@ def _finish(self, code, redirect_uri, code_verifier):
195197 if redirect_uri is not None :
196198 params ['redirect_uri' ] = redirect_uri
197199
198- resp = self .requests_session .post (url , data = params )
200+ resp = self .requests_session .post (url , data = params , timeout = self . _timeout )
199201 resp .raise_for_status ()
200202
201203 d = resp .json ()
@@ -285,7 +287,7 @@ class DropboxOAuth2FlowNoRedirect(DropboxOAuth2FlowBase):
285287 """
286288
287289 def __init__ (self , consumer_key , consumer_secret = None , locale = None , token_access_type = 'legacy' ,
288- scope = None , include_granted_scopes = None , use_pkce = False ): # noqa: E501;
290+ scope = None , include_granted_scopes = None , use_pkce = False , timeout = DEFAULT_TIMEOUT ): # noqa: E501;
289291 """
290292 Construct an instance.
291293
@@ -311,6 +313,11 @@ def __init__(self, consumer_key, consumer_secret=None, locale=None, token_access
311313 :param bool use_pkce: Whether or not to use Sha256 based PKCE. PKCE should be only use on
312314 client apps which doesn't call your server. It is less secure than non-PKCE flow but
313315 can be used if you are unable to safely retrieve your app secret
316+ :param Optional[float] timeout: Maximum duration in seconds that
317+ client will wait for any single packet from the
318+ server. After the timeout the client will give up on
319+ connection. If `None`, client will wait forever. Defaults
320+ to 100 seconds.
314321 """
315322 super (DropboxOAuth2FlowNoRedirect , self ).__init__ (
316323 consumer_key = consumer_key ,
@@ -320,6 +327,7 @@ def __init__(self, consumer_key, consumer_secret=None, locale=None, token_access
320327 scope = scope ,
321328 include_granted_scopes = include_granted_scopes ,
322329 use_pkce = use_pkce ,
330+ timeout = timeout
323331 )
324332
325333 def start (self ):
@@ -365,7 +373,7 @@ class DropboxOAuth2Flow(DropboxOAuth2FlowBase):
365373 def __init__ (self , consumer_key , redirect_uri , session ,
366374 csrf_token_session_key , consumer_secret = None , locale = None ,
367375 token_access_type = 'legacy' , scope = None ,
368- include_granted_scopes = None , use_pkce = False ):
376+ include_granted_scopes = None , use_pkce = False , timeout = DEFAULT_TIMEOUT ):
369377 """
370378 Construct an instance.
371379
@@ -397,15 +405,23 @@ def __init__(self, consumer_key, redirect_uri, session,
397405 team - include team scopes in the grant
398406 Note: if this user has never linked the app, include_granted_scopes must be None
399407 :param bool use_pkce: Whether or not to use Sha256 based PKCE
408+ :param Optional[float] timeout: Maximum duration in seconds that
409+ client will wait for any single packet from the
410+ server. After the timeout the client will give up on
411+ connection. If `None`, client will wait forever. Defaults
412+ to 100 seconds.
400413 """
414+
401415 super (DropboxOAuth2Flow , self ).__init__ (
402416 consumer_key = consumer_key ,
403417 consumer_secret = consumer_secret ,
404418 locale = locale ,
405419 token_access_type = token_access_type ,
406420 scope = scope ,
407421 include_granted_scopes = include_granted_scopes ,
408- use_pkce = use_pkce )
422+ use_pkce = use_pkce ,
423+ timeout = timeout
424+ )
409425 self .redirect_uri = redirect_uri
410426 self .session = session
411427 self .csrf_token_session_key = csrf_token_session_key
0 commit comments