Reformatted code base using black.

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

View file

@ -57,7 +57,7 @@ SENDING = D_("Please select a file to send to {peer}")
SENDING_TITLE = D_("File sending")
CONFIRM = D_(
'{peer} wants to send the file "{name}" to you:\n{desc}\n\nThe file has a size of '
'{size_human}\n\nDo you accept ?'
"{size_human}\n\nDo you accept ?"
)
CONFIRM_TITLE = D_("Confirm file transfer")
CONFIRM_OVERWRITE = D_("File {} already exists, are you sure you want to overwrite ?")
@ -97,13 +97,19 @@ class FilePlugin:
name: str,
file_desc: str,
extra_s: str,
profile: str = C.PROF_KEY_NONE
profile: str = C.PROF_KEY_NONE,
) -> defer.Deferred:
client = self.host.get_client(profile)
d = defer.ensureDeferred(self.file_send(
client, jid.JID(peer_jid_s), filepath, name or None, file_desc or None,
data_format.deserialise(extra_s)
))
d = defer.ensureDeferred(
self.file_send(
client,
jid.JID(peer_jid_s),
filepath,
name or None,
file_desc or None,
data_format.deserialise(extra_s),
)
)
d.addCallback(data_format.serialise)
return d
@ -111,10 +117,10 @@ class FilePlugin:
self,
client: SatXMPPEntity,
peer_jid: jid.JID,
filepath: str|Path,
filename: str|None=None,
file_desc: str|None=None,
extra: dict|None=None
filepath: str | Path,
filename: str | None = None,
file_desc: str | None = None,
extra: dict | None = None,
) -> dict:
"""Send a file using best available method
@ -132,8 +138,9 @@ class FilePlugin:
if not filename:
filename = filepath.name
for manager, __ in self._file_managers:
if await utils.as_deferred(manager.can_handle_file_send,
client, peer_jid, str(filepath)):
if await utils.as_deferred(
manager.can_handle_file_send, client, peer_jid, str(filepath)
):
try:
method_name = manager.name
except AttributeError:
@ -144,19 +151,26 @@ class FilePlugin:
)
)
try:
file_data= await utils.as_deferred(
manager.file_send, client, peer_jid, str(filepath), filename, file_desc,
extra
file_data = await utils.as_deferred(
manager.file_send,
client,
peer_jid,
str(filepath),
filename,
file_desc,
extra,
)
except Exception as e:
log.warning(
_("Can't send {filepath} to {peer_jid} with {method_name}: "
"{reason}").format(
filepath=filepath,
peer_jid=peer_jid,
method_name=method_name,
reason=e
)
_(
"Can't send {filepath} to {peer_jid} with {method_name}: "
"{reason}"
).format(
filepath=filepath,
peer_jid=peer_jid,
method_name=method_name,
reason=e,
)
)
continue
if "progress" not in file_data:
@ -181,7 +195,7 @@ class FilePlugin:
return self.file_send(client, peer_jid, path)
def _file_send_menu(self, data, profile):
""" XMLUI activated by menu: return file sending UI
"""XMLUI activated by menu: return file sending UI
@param profile: %(doc_profile)s
"""
@ -215,13 +229,14 @@ class FilePlugin:
"""
m_data = (manager, priority)
if m_data in self._file_managers:
raise exceptions.ConflictError(
f"Manager {manager} is already registered"
)
if not hasattr(manager, "can_handle_file_send") or not hasattr(manager, "file_send"):
raise exceptions.ConflictError(f"Manager {manager} is already registered")
if not hasattr(manager, "can_handle_file_send") or not hasattr(
manager, "file_send"
):
raise ValueError(
f'{manager} must have both "can_handle_file_send" and "file_send" methods to '
'be registered')
"be registered"
)
self._file_managers.append(m_data)
self._file_managers.sort(key=lambda m: m[1], reverse=True)
@ -237,8 +252,7 @@ class FilePlugin:
# the overwrite check is done here
def open_file_write(self, client, file_path, transfer_data, file_data, stream_object):
"""create SatFile or FileStremaObject for the requested file and fill suitable data
"""
"""create SatFile or FileStremaObject for the requested file and fill suitable data"""
if stream_object:
assert "stream_object" not in transfer_data
transfer_data["stream_object"] = stream.FileStreamObject(