interface: check server response for some methods
some basic sanity checks Previously if the server sent back a malformed response, it could partially corrupt a wallet file. (as sometimes the response would get persisted, and issues would only arise later when the values were used)
This commit is contained in:
@@ -582,6 +582,30 @@ def is_non_negative_integer(val) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
def is_integer(val) -> bool:
|
||||
try:
|
||||
int(val)
|
||||
except:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
def is_real_number(val, *, as_str: bool = False) -> bool:
|
||||
if as_str: # only accept str
|
||||
if not isinstance(val, str):
|
||||
return False
|
||||
else: # only accept int/float/etc.
|
||||
if isinstance(val, str):
|
||||
return False
|
||||
try:
|
||||
Decimal(val)
|
||||
except:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
def chunks(items, size: int):
|
||||
"""Break up items, an iterable, into chunks of length size."""
|
||||
if size < 1:
|
||||
|
||||
Reference in New Issue
Block a user