comparison libervia/backend/plugins/plugin_misc_upload.py @ 4270:0d7bb4df2343

Reformatted code base using black.
author Goffi <goffi@goffi.org>
date Wed, 19 Jun 2024 18:44:57 +0200
parents 4b842c1fb686
children
comparison
equal deleted inserted replaced
4269:64a85ce8be70 4270:0d7bb4df2343
66 async_=True, 66 async_=True,
67 ) 67 )
68 self._upload_callbacks = [] 68 self._upload_callbacks = []
69 69
70 def _file_upload( 70 def _file_upload(
71 self, filepath, filename, upload_jid_s="", options='', profile=C.PROF_KEY_NONE 71 self, filepath, filename, upload_jid_s="", options="", profile=C.PROF_KEY_NONE
72 ): 72 ):
73 client = self.host.get_client(profile) 73 client = self.host.get_client(profile)
74 upload_jid = jid.JID(upload_jid_s) if upload_jid_s else None 74 upload_jid = jid.JID(upload_jid_s) if upload_jid_s else None
75 options = data_format.deserialise(options) 75 options = data_format.deserialise(options)
76 76
77 return defer.ensureDeferred(self.file_upload( 77 return defer.ensureDeferred(
78 client, filepath, filename or None, upload_jid, options 78 self.file_upload(client, filepath, filename or None, upload_jid, options)
79 )) 79 )
80 80
81 async def file_upload(self, client, filepath, filename, upload_jid, options): 81 async def file_upload(self, client, filepath, filename, upload_jid, options):
82 """Send a file using best available method 82 """Send a file using best available method
83 83
84 parameters are the same as for [upload] 84 parameters are the same as for [upload]
85 @return (dict): action dictionary, with progress id in case of success, else xmlui 85 @return (dict): action dictionary, with progress id in case of success, else xmlui
86 message 86 message
87 """ 87 """
88 try: 88 try:
89 progress_id, __ = await self.upload( 89 progress_id, __ = await self.upload(
90 client, filepath, filename, upload_jid, options) 90 client, filepath, filename, upload_jid, options
91 )
91 except Exception as e: 92 except Exception as e:
92 if (isinstance(e, jabber_error.StanzaError) 93 if (
93 and e.condition == 'not-acceptable'): 94 isinstance(e, jabber_error.StanzaError)
95 and e.condition == "not-acceptable"
96 ):
94 reason = e.text 97 reason = e.text
95 else: 98 else:
96 reason = str(e) 99 reason = str(e)
97 msg = D_("Can't upload file: {reason}").format(reason=reason) 100 msg = D_("Can't upload file: {reason}").format(reason=reason)
98 log.warning(msg) 101 log.warning(msg)
108 self, 111 self,
109 client: SatXMPPEntity, 112 client: SatXMPPEntity,
110 filepath: Union[Path, str], 113 filepath: Union[Path, str],
111 filename: Optional[str] = None, 114 filename: Optional[str] = None,
112 upload_jid: Optional[jid.JID] = None, 115 upload_jid: Optional[jid.JID] = None,
113 extra: Optional[dict]=None 116 extra: Optional[dict] = None,
114 ) -> Tuple[str, defer.Deferred]: 117 ) -> Tuple[str, defer.Deferred]:
115 """Send a file using best available method 118 """Send a file using best available method
116 119
117 @param filepath: absolute path to the file 120 @param filepath: absolute path to the file
118 @param filename: name to use for the upload 121 @param filename: name to use for the upload