Page对象初始化删除timeout提示,以后废弃

This commit is contained in:
g1879 2024-09-11 00:59:13 +08:00
parent 6a96b227af
commit e54171710b
7 changed files with 17 additions and 25 deletions

View File

@ -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):

View File

@ -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: 超时时间
"""
...

View File

@ -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()

View File

@ -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则只返回namevaluedomain
:return: cookies信息
:return: cookies组成的列表
"""
...

View File

@ -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)

View File

@ -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文件使用默认配置
"""
...

View File

@ -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
"""
...