(
self, scheme: str, skip_lazy: bool = False
)
| 84 | return self._load_handler(scheme) |
| 85 | |
| 86 | def _load_handler( |
| 87 | self, scheme: str, skip_lazy: bool = False |
| 88 | ) -> DownloadHandlerProtocol | None: |
| 89 | path = self._schemes[scheme] |
| 90 | try: |
| 91 | dhcls: type[DownloadHandlerProtocol] = load_object(path) |
| 92 | if skip_lazy: |
| 93 | if not hasattr(dhcls, "lazy"): |
| 94 | warnings.warn( |
| 95 | f"{global_object_name(dhcls)} doesn't define a 'lazy' attribute." |
| 96 | f" This is deprecated, please add 'lazy = True' (which is the current" |
| 97 | f" default value) to the class definition.", |
| 98 | category=ScrapyDeprecationWarning, |
| 99 | stacklevel=1, |
| 100 | ) |
| 101 | if getattr(dhcls, "lazy", True): |
| 102 | return None |
| 103 | dh = build_from_crawler( |
| 104 | dhcls, |
| 105 | self._crawler, |
| 106 | ) |
| 107 | except NotConfigured as ex: |
| 108 | self._notconfigured[scheme] = str(ex) |
| 109 | return None |
| 110 | except Exception as ex: |
| 111 | logger.error( |
| 112 | 'Loading "%(clspath)s" for scheme "%(scheme)s"', |
| 113 | {"clspath": path, "scheme": scheme}, |
| 114 | exc_info=True, |
| 115 | extra={"crawler": self._crawler}, |
| 116 | ) |
| 117 | self._notconfigured[scheme] = str(ex) |
| 118 | return None |
| 119 | self._handlers[scheme] = dh |
| 120 | if not inspect.iscoroutinefunction(dh.download_request): # pragma: no cover |
| 121 | warnings.warn( |
| 122 | f"{global_object_name(dh.download_request)} is not a coroutine function." |
| 123 | f" This is deprecated, please rewrite it to return a coroutine and remove" |
| 124 | f" the 'spider' argument.", |
| 125 | category=ScrapyDeprecationWarning, |
| 126 | stacklevel=1, |
| 127 | ) |
| 128 | self._old_style_handlers.add(scheme) |
| 129 | return dh |
| 130 | |
| 131 | def download_request( |
| 132 | self, request: Request, spider: Spider | None = None |
no test coverage detected