MCPcopy Create free account
hub / github.com/Materials-Consortia/optimade-python-tools / meta_values

Function meta_values

optimade/server/routers/utils.py:49–88  ·  view source on GitHub ↗

Helper to initialize the meta values

(
    config: ServerConfig,
    url: urllib.parse.ParseResult | urllib.parse.SplitResult | StarletteURL | str,
    data_returned: int | None,
    data_available: int,
    more_data_available: bool,
    schema: str | None = None,
    **kwargs,
)

Source from the content-addressed store, hash-verified

47
48
49def meta_values(
50 config: ServerConfig,
51 url: urllib.parse.ParseResult | urllib.parse.SplitResult | StarletteURL | str,
52 data_returned: int | None,
53 data_available: int,
54 more_data_available: bool,
55 schema: str | None = None,
56 **kwargs,
57) -> ResponseMeta:
58 """Helper to initialize the meta values"""
59 from optimade.models import ResponseMetaQuery
60
61 if isinstance(url, str):
62 url = urllib.parse.urlparse(url)
63
64 # To catch all (valid) variations of the version part of the URL, a regex is used
65 if re.match(r"/v[0-9]+(\.[0-9]+){,2}/.*", url.path) is not None:
66 url_path = re.sub(r"/v[0-9]+(\.[0-9]+){,2}/", "/", url.path)
67 else:
68 url_path = url.path
69
70 if schema is None:
71 schema = config.schema_url if not config.is_index else config.index_schema_url
72
73 if config.request_delay:
74 # Double-guard against the server setting an adversarially large request delay
75 kwargs["request_delay"] = min(config.request_delay, 10.0)
76
77 return ResponseMeta(
78 query=ResponseMetaQuery(representation=f"{url_path}?{url.query}"),
79 api_version=__api_version__,
80 time_stamp=datetime.now(),
81 data_returned=data_returned,
82 more_data_available=more_data_available,
83 provider=config.provider,
84 data_available=data_available,
85 implementation=config.implementation,
86 schema=schema,
87 **kwargs,
88 )
89
90
91def handle_response_fields(

Callers 7

general_exceptionFunction · 0.90
get_infoFunction · 0.90
get_entry_infoFunction · 0.90
get_infoFunction · 0.90
render_landing_pageFunction · 0.90
get_entriesFunction · 0.85
get_single_entryFunction · 0.85

Calls 2

ResponseMetaClass · 0.90
ResponseMetaQueryClass · 0.90

Tested by

no test coverage detected