mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
publish: 5.8.16
This commit is contained in:
parent
b8d9fbcb2b
commit
c80ce08299
3 changed files with 48 additions and 2 deletions
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "royalnet"
|
name = "royalnet"
|
||||||
version = "5.8.15"
|
version = "5.8.16"
|
||||||
description = "A multipurpose bot and web framework"
|
description = "A multipurpose bot and web framework"
|
||||||
authors = ["Stefano Pigozzi <ste.pigozzi@gmail.com>"]
|
authors = ["Stefano Pigozzi <ste.pigozzi@gmail.com>"]
|
||||||
license = "AGPL-3.0+"
|
license = "AGPL-3.0+"
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
from typing import *
|
||||||
import logging
|
import logging
|
||||||
from .apierrors import MissingParameterError
|
from .apierrors import MissingParameterError
|
||||||
from royalnet.backpack.tables.tokens import Token
|
from royalnet.backpack.tables.tokens import Token
|
||||||
|
@ -18,6 +19,51 @@ class ApiData(dict):
|
||||||
def __missing__(self, key):
|
def __missing__(self, key):
|
||||||
raise MissingParameterError(f"Missing '{key}'")
|
raise MissingParameterError(f"Missing '{key}'")
|
||||||
|
|
||||||
|
def str(self, key, optional=False) -> Optional[str]:
|
||||||
|
if optional:
|
||||||
|
return self.get(key)
|
||||||
|
else:
|
||||||
|
return self[key]
|
||||||
|
|
||||||
|
def int(self, key, optional=False) -> Optional[int]:
|
||||||
|
value = self.str(key, optional)
|
||||||
|
if value is None:
|
||||||
|
return None
|
||||||
|
try:
|
||||||
|
return int(value)
|
||||||
|
except ValueError:
|
||||||
|
raise BadRequestError(f"Could not parse the value `{value}` as an int.")
|
||||||
|
|
||||||
|
def float(self, key, optional=False) -> Optional[float]:
|
||||||
|
value = self.str(key, optional)
|
||||||
|
if value is None:
|
||||||
|
return None
|
||||||
|
try:
|
||||||
|
return float(value)
|
||||||
|
except ValueError:
|
||||||
|
raise BadRequestError(f"Could not parse the value `{value}` as a float.")
|
||||||
|
|
||||||
|
_bool_values = {
|
||||||
|
"true": True,
|
||||||
|
"t": True,
|
||||||
|
"yes": True,
|
||||||
|
"y": True,
|
||||||
|
"false": False,
|
||||||
|
"f": False,
|
||||||
|
"no": False,
|
||||||
|
"n": False
|
||||||
|
}
|
||||||
|
|
||||||
|
def bool(self, key, optional=False) -> Optional[bool]:
|
||||||
|
value = self.str(key, optional)
|
||||||
|
if value is None:
|
||||||
|
return None
|
||||||
|
value = value.lower()
|
||||||
|
try:
|
||||||
|
return self._bool_values[value]
|
||||||
|
except KeyError:
|
||||||
|
raise BadRequestError(f"Could not parse the value `{value}` as a bool.")
|
||||||
|
|
||||||
async def token(self) -> Token:
|
async def token(self) -> Token:
|
||||||
token = await Token.find(self.star.alchemy, self.session, self["token"])
|
token = await Token.find(self.star.alchemy, self.session, self["token"])
|
||||||
if token is None:
|
if token is None:
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
semantic = "5.8.15"
|
semantic = "5.8.16"
|
||||||
|
|
Loading…
Reference in a new issue