From 4000f0116aa4032a5c68b886648bbda049bd6cde Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Fri, 1 Dec 2023 07:36:11 -0300 Subject: [PATCH] [view] refactoring: URL regex --- bauh/commons/regex.py | 3 +++ bauh/view/core/controller.py | 7 ++----- bauh/view/qt/thread.py | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) create mode 100644 bauh/commons/regex.py diff --git a/bauh/commons/regex.py b/bauh/commons/regex.py new file mode 100644 index 00000000..f2fecbe2 --- /dev/null +++ b/bauh/commons/regex.py @@ -0,0 +1,3 @@ +import re + +RE_URL = re.compile(r"^https?://.+$") diff --git a/bauh/view/core/controller.py b/bauh/view/core/controller.py index db902c02..4da5652b 100755 --- a/bauh/view/core/controller.py +++ b/bauh/view/core/controller.py @@ -1,5 +1,3 @@ -import re -import re import shutil import time import traceback @@ -17,6 +15,7 @@ from bauh.api.abstract.view import TabGroupComponent, MessageType from bauh.api.exception import NoInternetException from bauh.commons.boot import CreateConfigFile from bauh.commons.html import bold +from bauh.commons.regex import RE_URL from bauh.commons.util import sanitize_command_input from bauh.view.core.config import CoreConfigManager from bauh.view.core.settings import GenericSettingsManager @@ -25,8 +24,6 @@ from bauh.view.util import resource from bauh.view.util.resource import get_path from bauh.view.util.util import clean_app_files, restart_app -RE_IS_URL = re.compile(r'^https?://.+') - class GenericUpgradeRequirements(UpgradeRequirements): @@ -163,7 +160,7 @@ class GenericSoftwareManager(SoftwareManager, SettingsController): self.logger.info(f"Search query: {norm_query}") if norm_query: - is_url = bool(RE_IS_URL.match(norm_query)) + is_url = bool(RE_URL.match(norm_query)) disk_loader = self.disk_loader_factory.new() disk_loader.start() diff --git a/bauh/view/qt/thread.py b/bauh/view/qt/thread.py index 33447034..261df83f 100644 --- a/bauh/view/qt/thread.py +++ b/bauh/view/qt/thread.py @@ -27,6 +27,7 @@ from bauh.api.exception import NoInternetException from bauh.api.paths import LOGS_DIR from bauh.commons.html import bold from bauh.commons.internet import InternetChecker +from bauh.commons.regex import RE_URL from bauh.commons.system import ProcessHandler, SimpleProcess from bauh.commons.view_utils import get_human_size_str from bauh.view.core import timeshift @@ -1115,7 +1116,6 @@ class StartAsyncAction(QThread): class URLFileDownloader(QThread): signal_downloaded = pyqtSignal(str, bytes, object) - pattern_is_url: Pattern = re.compile(r"^https?://.+$") def __init__(self, max_workers: int = 50, request_timeout: int = 30, inactivity_timeout: int = 3, max_downloads: int = -1, parent: Optional[QWidget] = None): @@ -1159,7 +1159,7 @@ class URLFileDownloader(QThread): final_url = url.strip() if url else None if final_url: - if self.pattern_is_url.match(final_url): + if RE_URL.match(final_url): self._queue.put((final_url, id_)) else: self.signal_downloaded.emit(final_url, None, id_)