Reformatted code base using black.
This commit is contained in:
parent
56319cbad3
commit
53fdaa9d09
1 changed files with 12604 additions and 8966 deletions
|
|
@ -19,6 +19,7 @@
|
|||
"""Misc utils for both backend and frontends"""
|
||||
|
||||
import collections.abc
|
||||
|
||||
size_units = {
|
||||
"b": 1,
|
||||
"kb": 1000,
|
||||
|
|
@ -80,8 +81,10 @@ def recursive_update(ori: dict, update: dict):
|
|||
ori[k] = v
|
||||
return ori
|
||||
|
||||
|
||||
class OrderedSet(collections.abc.MutableSet):
|
||||
"""A mutable sequence which doesn't keep duplicates"""
|
||||
|
||||
# TODO: complete missing set methods
|
||||
|
||||
def __init__(self, values=None):
|
||||
|
|
@ -135,7 +138,8 @@ def parse_size(size):
|
|||
multiplier = size_units[symbol.lower()]
|
||||
except KeyError:
|
||||
raise ValueError(
|
||||
"unknown size multiplier symbole: {symbol!r} (size: {size!r})")
|
||||
"unknown size multiplier symbole: {symbol!r} (size: {size!r})"
|
||||
)
|
||||
else:
|
||||
return number * multiplier
|
||||
return number
|
||||
|
|
@ -143,7 +147,7 @@ def parse_size(size):
|
|||
raise ValueError(f"invalid size: {e}")
|
||||
|
||||
|
||||
def get_size_multiplier(size: int|str, suffix="o"):
|
||||
def get_size_multiplier(size: int | str, suffix="o"):
|
||||
"""Get multiplier of a file size"""
|
||||
size = int(size)
|
||||
# cf. https://stackoverflow.com/a/1094933 (thanks)
|
||||
|
|
@ -154,7 +158,7 @@ def get_size_multiplier(size: int|str, suffix="o"):
|
|||
return size, f"Yi{suffix}"
|
||||
|
||||
|
||||
def get_human_size(size: int|str, suffix: str="o", sep: str=" ") -> str:
|
||||
def get_human_size(size: int | str, suffix: str = "o", sep: str = " ") -> str:
|
||||
"""Return data size in a human readable format."""
|
||||
size, symbol = get_size_multiplier(size, suffix)
|
||||
return f"{size:.2f}{sep}{symbol}"
|
||||
|
|
|
|||
Loading…
Reference in a new issue