allow inserting invariants in python, logging
parent
30bf54f037
commit
6da1a295cf
|
@ -19,6 +19,9 @@ class UpEndEntry:
|
|||
def _arg(arg: Optional[Union[str, int]]) -> str:
|
||||
return f'"{escape(str(arg))}"' if arg else "?"
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.as_sexp()
|
||||
|
||||
|
||||
class UpEndError(RuntimeError):
|
||||
pass
|
||||
|
@ -29,7 +32,7 @@ class UpEndCheckError(UpEndError):
|
|||
|
||||
|
||||
UpEndOptionalTriplet = Tuple[Optional[str], Optional[str], Optional[str]]
|
||||
UpEndTriplet = Tuple[str, str, Union[str, int]]
|
||||
UpEndTriplet = Tuple[Optional[str], str, Union[str, int]]
|
||||
|
||||
|
||||
class UpEnd:
|
||||
|
@ -69,6 +72,11 @@ class UpEnd:
|
|||
if type(query) is str:
|
||||
query_out = query
|
||||
|
||||
if query_out is None:
|
||||
raise RuntimeError("Incorrect argument type.")
|
||||
|
||||
self.logger.debug(f"Querying: {query_out}")
|
||||
|
||||
result = self.session.get("obj", params={"query": query_out})
|
||||
if not result.ok:
|
||||
raise UpEndError(result.text)
|
||||
|
@ -80,7 +88,7 @@ class UpEnd:
|
|||
for chunk in request.iter_content(chunk_size=chunk_size):
|
||||
yield chunk
|
||||
|
||||
def insert(self, entry: Union[UpEndTriplet, UpEndEntry]):
|
||||
def insert(self, entry: Union[UpEndTriplet, UpEndEntry]) -> Dict[str, Any]:
|
||||
entry_out = None
|
||||
if type(entry) is tuple:
|
||||
entry_out = UpEndEntry(*entry)
|
||||
|
@ -88,6 +96,7 @@ class UpEnd:
|
|||
entry_out = entry
|
||||
if entry_out is None:
|
||||
raise RuntimeError("Incorrect argument type.")
|
||||
self.logger.debug(f"Inserting: {entry_out.as_sexp()}")
|
||||
request = self.session.put(
|
||||
f"obj",
|
||||
json={
|
||||
|
@ -97,3 +106,4 @@ class UpEnd:
|
|||
},
|
||||
)
|
||||
request.raise_for_status()
|
||||
return request.json()
|
||||
|
|
Loading…
Reference in New Issue