From ac6ffaec2097e34ad1f19b14323b282ea1d4b687 Mon Sep 17 00:00:00 2001 From: Sourcery AI <> Date: Sun, 29 Nov 2020 06:07:04 +0000 Subject: [PATCH] 'Refactored by Sourcery' --- userge/plugins/misc/gdrive.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/userge/plugins/misc/gdrive.py b/userge/plugins/misc/gdrive.py index 4f5660cfb..ae4b3213a 100644 --- a/userge/plugins/misc/gdrive.py +++ b/userge/plugins/misc/gdrive.py @@ -396,7 +396,7 @@ def _download_file(self, path: str, name: str, **kwargs) -> None: d_file_obj = MediaIoBaseDownload(d_f, request, chunksize=50 * 1024 * 1024) c_time = time.time() done = False - while done is False: + while not done: status, done = d_file_obj.next_chunk(num_retries=5) if self._is_canceled: raise ProcessCanceled @@ -756,12 +756,11 @@ def _get_file_id(self, filter_str: bool = False) -> tuple: link = self._message.filtered_input_str found = _GDRIVE_ID.search(link) if found and "folder" in link: - out = (found.group(1), "folder") + return found.group(1), "folder" elif found: - out = (found.group(1), "file") + return found.group(1), "file" else: - out = (link, "unknown") - return out + return link, "unknown" async def setup(self) -> None: """ Setup GDrive """ @@ -933,7 +932,7 @@ async def upload(self) -> None: except Exception as e_e: await self._message.err(e_e) return - file_path = dl_loc if dl_loc else self._message.input_str + file_path = dl_loc or self._message.input_str if not os.path.exists(file_path): await self._message.err("invalid file path provided?") return @@ -964,7 +963,7 @@ async def upload(self) -> None: out = f"**ERROR** : `{self._output._get_reason()}`" # pylint: disable=protected-access elif self._output is not None and not self._is_canceled: out = f"**Uploaded Successfully** __in {m_s} seconds__\n\n{self._output}" - elif self._output is not None and self._is_canceled: + elif self._output is not None: out = self._output else: out = "`failed to upload.. check logs?`" @@ -994,7 +993,7 @@ async def download(self) -> None: out = ( f"**Downloaded Successfully** __in {m_s} seconds__\n\n`{self._output}`" ) - elif self._output is not None and self._is_canceled: + elif self._output is not None: out = self._output else: out = "`failed to download.. check logs?`" @@ -1025,7 +1024,7 @@ async def copy(self) -> None: out = f"**ERROR** : `{self._output._get_reason()}`" # pylint: disable=protected-access elif self._output is not None and not self._is_canceled: out = f"**Copied Successfully** __in {m_s} seconds__\n\n{self._output}" - elif self._output is not None and self._is_canceled: + elif self._output is not None: out = self._output else: out = "`failed to copy.. check logs?`"