-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path_metadata.py
More file actions
28 lines (21 loc) · 906 Bytes
/
_metadata.py
File metadata and controls
28 lines (21 loc) · 906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from typing import Any
from scrapy import Spider
from scrapy_spider_metadata._params import Args
ATTR_NAME = "metadata"
def get_spider_metadata(
spider_cls: type[Spider], *, normalize: bool = False
) -> dict[str, Any]:
"""Return the metadata for the spider class.
Return a copy of the ``metadata`` dict. If the spider class defines
:ref:`spider parameters <params>`, the returned dict will have an
additional ``param_schema`` key which value is the :ref:`JSON Schema
<params-schema>` for the parameters.
:param spider_cls: The spider class.
:param normalize: Normalize the returned schema.
:return: The complete spider metadata.
"""
base_metadata = getattr(spider_cls, ATTR_NAME, {})
result = base_metadata.copy()
if issubclass(spider_cls, Args):
result["param_schema"] = spider_cls.get_param_schema(normalize=normalize)
return result