diff --git a/DrissionPage/_pages/chromium_page.py b/DrissionPage/_pages/chromium_page.py index 29d4ee3..a6c66b2 100644 --- a/DrissionPage/_pages/chromium_page.py +++ b/DrissionPage/_pages/chromium_page.py @@ -19,6 +19,7 @@ class ChromiumPage(ChromiumBase): _PAGES = {} def __new__(cls, addr_or_opts=None, tab_id=None, timeout=None): + # 即将废弃timeout browser = Chromium(addr_or_opts=addr_or_opts) if browser.id in cls._PAGES: r = cls._PAGES[browser.id] @@ -32,6 +33,7 @@ class ChromiumPage(ChromiumBase): return r def __init__(self, addr_or_opts=None, tab_id=None, timeout=None): + # 即将废弃timeout if hasattr(self, '_created'): return self._created = True @@ -39,7 +41,7 @@ class ChromiumPage(ChromiumBase): self.tab = self super().__init__(self.browser, tab_id) self._type = 'ChromiumPage' - self.set.timeouts(base=timeout) + self.set.timeouts(base=timeout) # 即将废弃 self._tab = self def __repr__(self): diff --git a/DrissionPage/_pages/chromium_page.pyi b/DrissionPage/_pages/chromium_page.pyi index cdf0727..4d3b410 100644 --- a/DrissionPage/_pages/chromium_page.pyi +++ b/DrissionPage/_pages/chromium_page.pyi @@ -27,23 +27,19 @@ class ChromiumPage(ChromiumBase): def __new__(cls, addr_or_opts: Union[str, int, ChromiumOptions] = None, - tab_id: str = None, - timeout: float = None): + tab_id: str = None): """ :param addr_or_opts: 浏览器地址:端口、ChromiumOptions对象或端口数字(int) :param tab_id: 要控制的标签页id,不指定默认为激活的 - :param timeout: 超时时间(秒) """ ... def __init__(self, addr_or_opts: Union[str, int, ChromiumOptions] = None, - tab_id: str = None, - timeout: float = None): + tab_id: str = None): """ :param addr_or_opts: 浏览器地址:端口、ChromiumOptions对象或端口数字(int) :param tab_id: 要控制的标签页id,不指定默认为激活的 - :param timeout: 超时时间(秒) """ ... diff --git a/DrissionPage/_pages/session_page.py b/DrissionPage/_pages/session_page.py index c3ee1fa..12f7bab 100644 --- a/DrissionPage/_pages/session_page.py +++ b/DrissionPage/_pages/session_page.py @@ -22,16 +22,17 @@ from .._units.setter import SessionPageSetter class SessionPage(BasePage): - def __init__(self, session_or_options=None): + def __init__(self, session_or_options=None, timeout=None): super().__init__() self._response = None self._set = None self._encoding = None self._type = 'SessionPage' self._page = self - self._timeout = 10 self._set_session_options(session_or_options) self._s_set_runtime_settings() + if timeout is not None: # 即将废弃 + self._timeout = timeout if not self._session: self._create_session() diff --git a/DrissionPage/_pages/session_page.pyi b/DrissionPage/_pages/session_page.pyi index 1658528..28eb42a 100644 --- a/DrissionPage/_pages/session_page.pyi +++ b/DrissionPage/_pages/session_page.pyi @@ -32,8 +32,7 @@ class SessionPage(BasePage): _encoding: Optional[str] = ... _page: SessionPage = ... - def __init__(self, - session_or_options: Union[Session, SessionOptions] = None): + def __init__(self, session_or_options: Union[Session, SessionOptions] = None): """ :param session_or_options: Session对象或SessionOptions对象 """ @@ -260,7 +259,7 @@ class SessionPage(BasePage): """返回cookies :param all_domains: 是否返回所有域的cookies :param all_info: 是否返回所有信息,False则只返回name、value、domain - :return: cookies信息 + :return: cookies组成的列表 """ ... diff --git a/DrissionPage/_pages/web_page.py b/DrissionPage/_pages/web_page.py index d8003fe..77094fe 100644 --- a/DrissionPage/_pages/web_page.py +++ b/DrissionPage/_pages/web_page.py @@ -17,15 +17,11 @@ from .._units.setter import WebPageSetter class WebPage(SessionPage, ChromiumPage, BasePage): def __new__(cls, mode='d', timeout=None, chromium_options=None, session_or_options=None): - """初始化函数 - :param mode: 'd' 或 's',即driver模式和session模式 - :param timeout: 超时时间(秒),d模式时为寻找元素时间,s模式时为连接时间,默认10秒 - :param chromium_options: Driver对象,只使用s模式时应传入False - :param session_or_options: Session对象或SessionOptions对象,只使用d模式时应传入False - """ + # 即将废弃timeout return super().__new__(cls, chromium_options) def __init__(self, mode='d', timeout=None, chromium_options=None, session_or_options=None): + # 即将废弃timeout if hasattr(self, '_created'): return @@ -40,7 +36,7 @@ class WebPage(SessionPage, ChromiumPage, BasePage): if not chromium_options: chromium_options = ChromiumOptions(read_file=chromium_options) chromium_options.set_timeouts(base=self._timeout).set_paths(download_path=self.download_path) - super(SessionPage, self).__init__(addr_or_opts=chromium_options, timeout=timeout) + super(SessionPage, self).__init__(addr_or_opts=chromium_options, timeout=timeout) # 即将废弃timeout self._type = 'WebPage' self.change_mode(mode, go=False, copy_cookies=False) diff --git a/DrissionPage/_pages/web_page.pyi b/DrissionPage/_pages/web_page.pyi index 97815c2..1ad05a9 100644 --- a/DrissionPage/_pages/web_page.pyi +++ b/DrissionPage/_pages/web_page.pyi @@ -35,14 +35,12 @@ class WebPage(SessionPage, ChromiumPage, BasePage): def __init__(self, mode: str = 'd', - timeout: float = None, chromium_options: Union[ChromiumOptions, bool] = None, session_or_options: Union[Session, SessionOptions, bool] = None) -> None: """初始化函数 :param mode: 'd' 或 's',即driver模式和session模式 - :param timeout: 超时时间(秒),d模式时为寻找元素时间,s模式时为连接时间,默认10秒 - :param chromium_options: ChromiumOptions对象,只使用s模式时应传入False - :param session_or_options: Session对象或SessionOptions对象,只使用d模式时应传入False + :param chromium_options: ChromiumOptions对象,传入None时从默认ini文件读取,传入False时不读取ini文件,使用默认配置 + :param session_or_options: Session对象或SessionOptions对象,传入None时从默认ini文件读取,传入False时不读取ini文件,使用默认配置 """ ... diff --git a/DrissionPage/_units/waiter.pyi b/DrissionPage/_units/waiter.pyi index c8febe6..df5cd8c 100644 --- a/DrissionPage/_units/waiter.pyi +++ b/DrissionPage/_units/waiter.pyi @@ -151,11 +151,11 @@ class BaseWaiter(OriginWaiter): """等待自动填写上传文件路径""" ... - def download_begin(self, timeout: float = None, cancel_it: bool = False) -> Union[DownloadMission, bool]: + def download_begin(self, timeout: float = None, cancel_it: bool = False) -> Union[DownloadMission, bool, dict]: """等待浏览器下载开始,可将其拦截 :param timeout: 超时时间(秒),None使用页面对象超时时间 :param cancel_it: 是否取消该任务 - :return: 成功返回任务对象,失败返回False + :return: 成功返回任务对象(cancel_it为True时返回dict格式的下载信息),失败返回False """ ...