Bases: HTTPClient
Overview of the CANFAR Server.
This class is a subclass of the HTTPClient
class and inherits its
attributes and methods.
Examples:
>>> from canfar.overview import Overview
>>> overview = Overview()
>>> overview.availability()
True
Source code in canfar/overview.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73 | class Overview(HTTPClient):
"""Overview of the CANFAR Server.
This class is a subclass of the `HTTPClient` class and inherits its
attributes and methods.
Examples:
>>> from canfar.overview import Overview
>>> overview = Overview()
>>> overview.availability()
True
"""
@model_validator(mode="after")
def _update_base_url(self) -> Self:
"""Update base URL for the server.
Returns:
Self: The current object.
"""
url: str = str(self.client.base_url)
base: str = url.split("/v", maxsplit=1)[0]
# The overview endpoint is not versioned, so need to remove it
self.client.base_url = URL(base)
self.asynclient.base_url = URL(base)
return self
def availability(self) -> bool:
"""Check if the server backend is available.
Returns:
bool: True if the server is available, False otherwise.
"""
response: Response = self.client.get("availability")
data: str = response.text
if not data:
log.error("No data returned from availability endpoint.")
return False
root = ElementTree.fromstring(data)
available = root.find(
".//{http://www.ivoa.net/xml/VOSIAvailability/v1.0}available",
)
availaibility: str | None = available.text if available is not None else None
note = root.find(
".//{http://www.ivoa.net/xml/VOSIAvailability/v1.0}note",
)
notify: str | None = note.text if note is not None else None
if availaibility is None:
log.error("No availability information found in the response.")
return False
log.info(notify if notify else "No additional information provided.")
return availaibility == "true"
|
availability
Check if the server backend is available.
RETURNS |
DESCRIPTION |
bool
|
True if the server is available, False otherwise.
TYPE:
bool
|
Source code in canfar/overview.py
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73 | def availability(self) -> bool:
"""Check if the server backend is available.
Returns:
bool: True if the server is available, False otherwise.
"""
response: Response = self.client.get("availability")
data: str = response.text
if not data:
log.error("No data returned from availability endpoint.")
return False
root = ElementTree.fromstring(data)
available = root.find(
".//{http://www.ivoa.net/xml/VOSIAvailability/v1.0}available",
)
availaibility: str | None = available.text if available is not None else None
note = root.find(
".//{http://www.ivoa.net/xml/VOSIAvailability/v1.0}note",
)
notify: str | None = note.text if note is not None else None
if availaibility is None:
log.error("No availability information found in the response.")
return False
log.info(notify if notify else "No additional information provided.")
return availaibility == "true"
|