MCPcopy
hub / github.com/scrapy/scrapy / _load_handler

Method _load_handler

scrapy/core/downloader/handlers/__init__.py:86–129  ·  view source on GitHub ↗
(
        self, scheme: str, skip_lazy: bool = False
    )

Source from the content-addressed store, hash-verified

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

Callers 2

__init__Method · 0.95
_get_handlerMethod · 0.95

Calls 4

load_objectFunction · 0.90
global_object_nameFunction · 0.90
build_from_crawlerFunction · 0.90
errorMethod · 0.80

Tested by

no test coverage detected