@@ -266,7 +266,7 @@ def get_plugin() -> Union[Search, Api]:
266266 for config in sorted (configs , key = attrgetter ("priority" ), reverse = True ):
267267 yield get_plugin ()
268268
269- def get_download_plugin (self , product : EOProduct ) -> Union [ Download , Api ] :
269+ def get_download_plugin (self , product : EOProduct ) -> PluginTopic :
270270 """Build and return the download plugin capable of downloading the given
271271 product.
272272
@@ -278,9 +278,9 @@ def get_download_plugin(self, product: EOProduct) -> Union[Download, Api]:
278278 if api := getattr (plugin_conf , "api" , None ):
279279 plugin_conf .api .products = plugin_conf .products
280280 plugin_conf .api .priority = plugin_conf .priority
281- plugin = cast (Api , self ._build_plugin (product .provider , api , Api ))
281+ return cast (Api , self ._build_plugin (product .provider , api , Api ))
282282 elif getattr (plugin_conf , "download" , None ):
283- plugin = next (
283+ return next (
284284 self .get_auth_or_download_plugins (
285285 "download" , product .provider , matching_url = matching_url
286286 )
@@ -289,11 +289,10 @@ def get_download_plugin(self, product: EOProduct) -> Union[Download, Api]:
289289 raise MisconfiguredError (
290290 f"No download plugin configured for provider { plugin_conf .name } ."
291291 )
292- return plugin
293292
294293 def get_auth_plugin (
295294 self , associated_plugin : PluginTopic , product : Optional [EOProduct ] = None
296- ) -> Optional [Authentication ]:
295+ ) -> Optional [PluginTopic ]:
297296 """Build and return the authentication plugin associated to the given
298297 search/download plugin
299298
@@ -307,7 +306,7 @@ def get_auth_plugin(
307306 :returns: The Authentication plugin
308307 """
309308 # matching url from product to download
310- matching_url = ""
309+ matching_url = None
311310 if product :
312311 matching_url = _get_matching_url_for_product (product )
313312 if not matching_url :
@@ -333,7 +332,7 @@ def get_auth_or_download_plugins(
333332 provider : str ,
334333 matching_url : Optional [str ] = None ,
335334 matching_conf : Optional [PluginConfig ] = None ,
336- ) -> Iterator [Authentication ]:
335+ ) -> Iterator [Union [ Authentication , Download ] ]:
337336 """Build and return the authentication plugin for the given provider and
338337 matching conf or url
339338
@@ -379,18 +378,17 @@ def get_auth_or_download_plugins(
379378 ):
380379 plugin_conf .priority = provider_conf .priority
381380 if plugin_type == "auth" :
382- plugin = cast (
381+ yield cast (
383382 Authentication ,
384383 self ._build_plugin (
385384 plugin_provider , plugin_conf , Authentication
386385 ),
387386 )
388387 else :
389- plugin = cast (
388+ yield cast (
390389 Download ,
391390 self ._build_plugin (plugin_provider , plugin_conf , Download ),
392391 )
393- yield plugin
394392 else :
395393 continue
396394
@@ -419,7 +417,11 @@ def get_auth(
419417 ):
420418 # not the plugin we were looking for
421419 continue
422- if auth_plugin and callable (getattr (auth_plugin , "authenticate" , None )):
420+ if (
421+ auth_plugin
422+ and isinstance (auth_plugin , Authentication )
423+ and callable (getattr (auth_plugin , "authenticate" , None ))
424+ ):
423425 try :
424426 auth = auth_plugin .authenticate ()
425427 return auth
0 commit comments