server: fix python docstring formatting
This commit is contained in:
parent
f3aa0eb801
commit
9b3123a815
|
@ -135,7 +135,7 @@ _live_migrations = (
|
||||||
|
|
||||||
|
|
||||||
def create_app() -> Callable[[Any, Any], Any]:
|
def create_app() -> Callable[[Any, Any], Any]:
|
||||||
""" Create a WSGI compatible App object. """
|
"""Create a WSGI compatible App object."""
|
||||||
validate_config()
|
validate_config()
|
||||||
coloredlogs.install(fmt="[%(asctime)-15s] %(name)s %(message)s")
|
coloredlogs.install(fmt="[%(asctime)-15s] %(name)s %(message)s")
|
||||||
if config.config["debug"]:
|
if config.config["debug"]:
|
||||||
|
|
|
@ -25,7 +25,7 @@ RANK_MAP = OrderedDict(
|
||||||
|
|
||||||
|
|
||||||
def get_password_hash(salt: str, password: str) -> Tuple[str, int]:
|
def get_password_hash(salt: str, password: str) -> Tuple[str, int]:
|
||||||
""" Retrieve argon2id password hash. """
|
"""Retrieve argon2id password hash."""
|
||||||
return (
|
return (
|
||||||
pwhash.argon2id.str(
|
pwhash.argon2id.str(
|
||||||
(config.config["secret"] + salt + password).encode("utf8")
|
(config.config["secret"] + salt + password).encode("utf8")
|
||||||
|
@ -37,7 +37,7 @@ def get_password_hash(salt: str, password: str) -> Tuple[str, int]:
|
||||||
def get_sha256_legacy_password_hash(
|
def get_sha256_legacy_password_hash(
|
||||||
salt: str, password: str
|
salt: str, password: str
|
||||||
) -> Tuple[str, int]:
|
) -> Tuple[str, int]:
|
||||||
""" Retrieve old-style sha256 password hash. """
|
"""Retrieve old-style sha256 password hash."""
|
||||||
digest = hashlib.sha256()
|
digest = hashlib.sha256()
|
||||||
digest.update(config.config["secret"].encode("utf8"))
|
digest.update(config.config["secret"].encode("utf8"))
|
||||||
digest.update(salt.encode("utf8"))
|
digest.update(salt.encode("utf8"))
|
||||||
|
@ -46,7 +46,7 @@ def get_sha256_legacy_password_hash(
|
||||||
|
|
||||||
|
|
||||||
def get_sha1_legacy_password_hash(salt: str, password: str) -> Tuple[str, int]:
|
def get_sha1_legacy_password_hash(salt: str, password: str) -> Tuple[str, int]:
|
||||||
""" Retrieve old-style sha1 password hash. """
|
"""Retrieve old-style sha1 password hash."""
|
||||||
digest = hashlib.sha1()
|
digest = hashlib.sha1()
|
||||||
digest.update(b"1A2/$_4xVa")
|
digest.update(b"1A2/$_4xVa")
|
||||||
digest.update(salt.encode("utf8"))
|
digest.update(salt.encode("utf8"))
|
||||||
|
@ -125,7 +125,7 @@ def verify_privilege(user: model.User, privilege_name: str) -> None:
|
||||||
|
|
||||||
|
|
||||||
def generate_authentication_token(user: model.User) -> str:
|
def generate_authentication_token(user: model.User) -> str:
|
||||||
""" Generate nonguessable challenge (e.g. links in password reminder). """
|
"""Generate nonguessable challenge (e.g. links in password reminder)."""
|
||||||
assert user
|
assert user
|
||||||
digest = hashlib.md5()
|
digest = hashlib.md5()
|
||||||
digest.update(config.config["secret"].encode("utf8"))
|
digest.update(config.config["secret"].encode("utf8"))
|
||||||
|
|
|
@ -39,7 +39,7 @@ def download(url: str, use_video_downloader: bool = False) -> bytes:
|
||||||
length_tally = 0
|
length_tally = 0
|
||||||
try:
|
try:
|
||||||
with urllib.request.urlopen(request) as handle:
|
with urllib.request.urlopen(request) as handle:
|
||||||
while (chunk := handle.read(_dl_chunk_size)) :
|
while chunk := handle.read(_dl_chunk_size):
|
||||||
length_tally += len(chunk)
|
length_tally += len(chunk)
|
||||||
if length_tally > config.config["max_dl_filesize"]:
|
if length_tally > config.config["max_dl_filesize"]:
|
||||||
raise DownloadTooLargeError(
|
raise DownloadTooLargeError(
|
||||||
|
|
|
@ -83,12 +83,12 @@ def flip(source: Dict[Any, Any]) -> Dict[Any, Any]:
|
||||||
|
|
||||||
|
|
||||||
def is_valid_email(email: Optional[str]) -> bool:
|
def is_valid_email(email: Optional[str]) -> bool:
|
||||||
""" Return whether given email address is valid or empty. """
|
"""Return whether given email address is valid or empty."""
|
||||||
return not email or re.match(r"^[^@]*@[^@]*\.[^@]*$", email) is not None
|
return not email or re.match(r"^[^@]*@[^@]*\.[^@]*$", email) is not None
|
||||||
|
|
||||||
|
|
||||||
class dotdict(dict):
|
class dotdict(dict):
|
||||||
""" dot.notation access to dictionary attributes. """
|
"""dot.notation access to dictionary attributes."""
|
||||||
|
|
||||||
def __getattr__(self, attr: str) -> Any:
|
def __getattr__(self, attr: str) -> Any:
|
||||||
return self.get(attr)
|
return self.get(attr)
|
||||||
|
@ -98,7 +98,7 @@ class dotdict(dict):
|
||||||
|
|
||||||
|
|
||||||
def parse_time_range(value: str) -> Tuple[datetime, datetime]:
|
def parse_time_range(value: str) -> Tuple[datetime, datetime]:
|
||||||
""" Return tuple containing min/max time for given text representation. """
|
"""Return tuple containing min/max time for given text representation."""
|
||||||
one_day = timedelta(days=1)
|
one_day = timedelta(days=1)
|
||||||
one_second = timedelta(seconds=1)
|
one_second = timedelta(seconds=1)
|
||||||
almost_one_day = one_day - one_second
|
almost_one_day = one_day - one_second
|
||||||
|
|
|
@ -7,7 +7,7 @@ from szurubooru.rest.errors import HttpBadRequest
|
||||||
|
|
||||||
|
|
||||||
def _authenticate_basic_auth(username: str, password: str) -> model.User:
|
def _authenticate_basic_auth(username: str, password: str) -> model.User:
|
||||||
""" Try to authenticate user. Throw AuthError for invalid users. """
|
"""Try to authenticate user. Throw AuthError for invalid users."""
|
||||||
user = users.get_user_by_name(username)
|
user = users.get_user_by_name(username)
|
||||||
if not auth.is_valid_password(user, password):
|
if not auth.is_valid_password(user, password):
|
||||||
raise errors.AuthError("Invalid password.")
|
raise errors.AuthError("Invalid password.")
|
||||||
|
@ -17,7 +17,7 @@ def _authenticate_basic_auth(username: str, password: str) -> model.User:
|
||||||
def _authenticate_token(
|
def _authenticate_token(
|
||||||
username: str, token: str
|
username: str, token: str
|
||||||
) -> Tuple[model.User, model.UserToken]:
|
) -> Tuple[model.User, model.UserToken]:
|
||||||
""" Try to authenticate user. Throw AuthError for invalid users. """
|
"""Try to authenticate user. Throw AuthError for invalid users."""
|
||||||
user = users.get_user_by_name(username)
|
user = users.get_user_by_name(username)
|
||||||
user_token = user_tokens.get_by_user_and_token(user, token)
|
user_token = user_tokens.get_by_user_and_token(user, token)
|
||||||
if not auth.is_valid_token(user_token):
|
if not auth.is_valid_token(user_token):
|
||||||
|
@ -72,7 +72,7 @@ def _get_user(ctx: rest.Context, bump_login: bool) -> Optional[model.User]:
|
||||||
|
|
||||||
|
|
||||||
def process_request(ctx: rest.Context) -> None:
|
def process_request(ctx: rest.Context) -> None:
|
||||||
""" Bind the user to request. Update last login time if needed. """
|
"""Bind the user to request. Update last login time if needed."""
|
||||||
bump_login = ctx.get_param_as_bool("bump-login", default=False)
|
bump_login = ctx.get_param_as_bool("bump-login", default=False)
|
||||||
auth_user = _get_user(ctx, bump_login)
|
auth_user = _get_user(ctx, bump_login)
|
||||||
if auth_user:
|
if auth_user:
|
||||||
|
|
|
@ -11,7 +11,7 @@ from szurubooru.rest import context, errors, middleware, routes
|
||||||
|
|
||||||
|
|
||||||
def _json_serializer(obj: Any) -> str:
|
def _json_serializer(obj: Any) -> str:
|
||||||
""" JSON serializer for objects not serializable by default JSON code """
|
"""JSON serializer for objects not serializable by default JSON code"""
|
||||||
if isinstance(obj, datetime):
|
if isinstance(obj, datetime):
|
||||||
serial = obj.isoformat("T") + "Z"
|
serial = obj.isoformat("T") + "Z"
|
||||||
return serial
|
return serial
|
||||||
|
|
Loading…
Reference in New Issue