Reformatted code base using black.

This commit is contained in:
Goffi 2024-06-19 18:44:57 +02:00
commit 53fdaa9d09

View file

@ -119,8 +119,10 @@ def aio(func):
Functions with this decorator are run in asyncio context
"""
def wrapper(*args, **kwargs):
return defer.Deferred.fromFuture(asyncio.ensure_future(func(*args, **kwargs)))
return wrapper
@ -134,14 +136,15 @@ def ensure_deferred(func):
to be used when the function is called by third party library (e.g. wokkel)
Otherwise, it's better to use ensureDeferred as early as possible.
"""
def wrapper(*args, **kwargs):
return defer.ensureDeferred(func(*args, **kwargs))
return wrapper
def xmpp_date(
timestamp: Optional[Union[float, int]] = None,
with_time: bool = True
timestamp: Optional[Union[float, int]] = None, with_time: bool = True
) -> str:
"""Return date according to XEP-0082 specification
@ -153,20 +156,17 @@ def xmpp_date(
@return(unicode): XEP-0082 formatted date and time
"""
dtime = datetime.datetime.fromtimestamp(
time.time() if timestamp is None else timestamp,
datetime.timezone.utc
time.time() if timestamp is None else timestamp, datetime.timezone.utc
)
return (
xmpp_datetime.format_datetime(dtime) if with_time
xmpp_datetime.format_datetime(dtime)
if with_time
else xmpp_datetime.format_date(dtime.date())
)
def parse_xmpp_date(
xmpp_date_str: str,
with_time: bool = True
) -> float:
def parse_xmpp_date(xmpp_date_str: str, with_time: bool = True) -> float:
"""Get timestamp from XEP-0082 datetime
@param xmpp_date_str: XEP-0082 formatted datetime or time
@ -194,7 +194,10 @@ def generate_password(vocabulary=None, size=20):
random.seed()
if vocabulary is None:
vocabulary = [
chr(i) for i in list(range(0x30, 0x3A)) + list(range(0x41, 0x5B)) + list(range(0x61, 0x7B))
chr(i)
for i in list(range(0x30, 0x3A))
+ list(range(0x41, 0x5B))
+ list(range(0x61, 0x7B))
]
return "".join([random.choice(vocabulary) for i in range(15)])
@ -268,7 +271,7 @@ def get_repository_data(module, as_string=True, is_path=False):
"{latesttag}\n"
"{latesttagdistance}",
],
text=True
text=True,
)
except subprocess.CalledProcessError as e:
log.error(f"Can't get repository data: {e}")
@ -279,7 +282,9 @@ def get_repository_data(module, as_string=True, is_path=False):
else:
hg_data = dict(list(zip(KEYS, hg_data_raw.split("\n"))))
try:
hg_data["modified"] = "+" in subprocess.check_output(["python3", hg_path, "id", "-i"], text=True)
hg_data["modified"] = "+" in subprocess.check_output(
["python3", hg_path, "id", "-i"], text=True
)
except subprocess.CalledProcessError:
pass
else:
@ -293,7 +298,7 @@ def get_repository_data(module, as_string=True, is_path=False):
else:
os.chdir(os.path.abspath(os.path.dirname(repos_root)))
try:
with open(".hg/dirstate", 'rb') as hg_dirstate:
with open(".hg/dirstate", "rb") as hg_dirstate:
hg_data["node"] = hg_dirstate.read(20).hex()
hg_data["node_short"] = hg_data["node"][:12]
except IOError:
@ -323,8 +328,7 @@ def get_repository_data(module, as_string=True, is_path=False):
else:
if version != C.APP_VERSION:
log.warning(
"Incompatible version ({version}) and pkg_version ({pkg_version})"
.format(
"Incompatible version ({version}) and pkg_version ({pkg_version})".format(
version=C.APP_VERSION, pkg_version=pkg_version
)
)