mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
微调下载逻辑
This commit is contained in:
parent
ba1c3fb3cc
commit
8dd184e848
@ -215,8 +215,9 @@ class BrowserDriver(ChromiumDriver):
|
||||
return object.__new__(cls)
|
||||
|
||||
def __init__(self, tab_id, tab_type, address):
|
||||
if tab_id in BrowserDriver.BROWSERS:
|
||||
if hasattr(self, '_created'):
|
||||
return
|
||||
self._created = True
|
||||
BrowserDriver.BROWSERS[tab_id] = self
|
||||
super().__init__(tab_id, tab_type, address)
|
||||
|
||||
|
@ -146,9 +146,9 @@ class TabSetter(ChromiumBaseSetter):
|
||||
"""
|
||||
types = {'rename': 'rename', 'overwrite': 'overwrite', 'skip': 'skip', 'r': 'rename', 'o': 'overwrite',
|
||||
's': 'skip'}
|
||||
mode = types.get(mode, None)
|
||||
if not mode:
|
||||
raise ValueError(f"mode参数只能是'rename', 'overwrite', 'skip', 'r', 'o', 's' 之一,现在是:{mode}")
|
||||
mode = types.get(mode, mode)
|
||||
if mode not in types:
|
||||
raise ValueError(f'''mode参数只能是 '{"', '".join(types.keys())}' 之一,现在是:{mode}''')
|
||||
|
||||
self._page.browser._dl_mgr.set_file_exists(self._page.tab_id, mode)
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
"""
|
||||
from http.cookiejar import Cookie
|
||||
from pathlib import Path
|
||||
from typing import Union, Tuple
|
||||
from typing import Union, Tuple, Literal
|
||||
|
||||
from requests.adapters import HTTPAdapter
|
||||
from requests.auth import HTTPBasicAuth
|
||||
@ -19,6 +19,8 @@ from .chromium_tab import ChromiumTab
|
||||
from .session_page import SessionPage
|
||||
from .web_page import WebPage
|
||||
|
||||
FILE_EXISTS = Literal['skip', 'rename', 'overwrite', 's', 'r', 'o']
|
||||
|
||||
|
||||
class ChromiumBaseSetter(object):
|
||||
def __init__(self, page):
|
||||
@ -58,7 +60,7 @@ class TabSetter(ChromiumBaseSetter):
|
||||
|
||||
def download_file_name(self, name: str) -> None: ...
|
||||
|
||||
def when_download_file_exists(self, mode: str) -> None: ...
|
||||
def when_download_file_exists(self, mode: FILE_EXISTS) -> None: ...
|
||||
|
||||
|
||||
class ChromiumPageSetter(TabSetter):
|
||||
|
Loading…
x
Reference in New Issue
Block a user