-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiagnostic.py
More file actions
66 lines (48 loc) · 2.01 KB
/
diagnostic.py
File metadata and controls
66 lines (48 loc) · 2.01 KB
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
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
from abc import ABCMeta
from abc import abstractmethod
from dataclasses import dataclass
from typing import Optional
from . import constants
# ---------------------------------------------------------------------------
@dataclass(frozen=True)
class SRUDiagnostic:
"""Class to hold a SRU diagnostic.
See also:
* SRU Diagnostics: http://www.loc.gov/standards/sru/diagnostics/
* SRU Diagnostics List: http://www.loc.gov/standards/sru/diagnostics/diagnosticsList.html
"""
uri: str
"""Diagnostic's identifying URI."""
details: Optional[str] = None
"""Supplementary information available, often in a format
specified by the diagnostic or ``None``."""
message: Optional[str] = None
"""Human readable message to display to the end user or ``None``."""
def __post_init__(self):
if not self.message or not self.message.strip():
object.__setattr__(
self, "message", self.get_default_error_message(self.uri)
)
@staticmethod
def get_default_error_message(uri: str):
diag = constants.SRUDiagnostics.get_by_uri(uri)
if diag:
return diag.description
return None
# ---------------------------------------------------------------------------
class SRUDiagnosticList(metaclass=ABCMeta):
"""Container for non surrogate diagnostics for the request. The
will be put in the ``diagnostics`` part of the response."""
@abstractmethod
def add_diagnostic(
self, uri: str, details: Optional[str] = None, message: Optional[str] = None
) -> None:
"""Add a non surrogate diagnostic to the response.
Args:
uri: the diagnostic's identifying URI
details: supplementary information available, often
in a format specified by the diagnostic or ``None``
message: human readable message to display to the
end user or ``None``
"""
# ---------------------------------------------------------------------------