tabs拆分成两个文件;browser文件改名为chromium

This commit is contained in:
g1879 2024-08-23 00:04:02 +08:00
parent 987f94104b
commit 1c63a0e36c
28 changed files with 227 additions and 230 deletions

View File

@ -5,13 +5,12 @@
@Copyright: (c) 2024 by g1879, Inc. All Rights Reserved.
@License : BSD 3-Clause.
"""
from ._base.browser import Chromium
from ._base.chromium import Chromium
from ._configs.chromium_options import ChromiumOptions
from ._configs.session_options import SessionOptions
from ._pages.session_page import SessionPage
from ._pages.chromium_page import ChromiumPage
from ._pages.mix_page import MixPage
from ._pages.mix_page import MixPage as WebPage
from ._pages.session_page import SessionPage
__version__ = '4.1.0.0b20'

View File

@ -5,14 +5,13 @@
@Copyright: (c) 2024 by g1879, Inc. All Rights Reserved.
@License : BSD 3-Clause.
"""
from ._base.browser import Chromium
from ._base.chromium import Chromium
from ._configs.chromium_options import ChromiumOptions
from ._configs.session_options import SessionOptions
from ._pages.session_page import SessionPage
from ._pages.chromium_page import ChromiumPage
from ._pages.mix_page import MixPage
from ._pages.mix_page import MixPage as WebPage
from ._pages.session_page import SessionPage
__all__ = ['MixPage', 'WebPage', 'ChromiumPage', 'Chromium', 'ChromiumOptions', 'SessionOptions', 'SessionPage', '__version__']
__version__: str = ...

View File

@ -21,7 +21,8 @@ from .._functions.settings import Settings
from .._functions.tools import PortFinder
from .._functions.tools import raise_error
from .._pages.chromium_base import Timeout
from .._pages.tabs import ChromiumTab, MixTab
from .._pages.chromium_tab import ChromiumTab
from .._pages.mix_tab import MixTab
from .._units.downloader import DownloadManager
from .._units.setter import BrowserSetter
from .._units.states import BrowserStates

View File

@ -13,7 +13,8 @@ from .._configs.chromium_options import ChromiumOptions
from .._configs.session_options import SessionOptions
from .._functions.cookies import CookiesList
from .._pages.chromium_base import Timeout
from .._pages.tabs import ChromiumTab, MixTab
from .._pages.chromium_tab import ChromiumTab
from .._pages.mix_tab import MixTab
from .._units.downloader import DownloadManager
from .._units.setter import BrowserSetter
from .._units.states import BrowserStates

View File

@ -14,7 +14,7 @@ from .._functions.elements import SessionElementsList, ChromiumElementsList
from .._pages.chromium_base import ChromiumBase
from .._pages.chromium_frame import ChromiumFrame
from .._pages.chromium_page import ChromiumPage
from .._pages.tabs import ChromiumTab
from .._pages.chromium_tab import ChromiumTab
from .._pages.mix_page import MixPage
from .._units.clicker import Clicker
from .._units.rect import ElementRect

View File

@ -11,7 +11,7 @@ from typing import Union
from requests import Session
from requests.cookies import RequestsCookieJar
from .._base.browser import Chromium
from .._base.chromium import Chromium
from .._pages.chromium_base import ChromiumBase

View File

@ -12,7 +12,7 @@ from .._base.base import DrissionElement, BaseParser
from .._elements.chromium_element import ChromiumElement
from .._pages.chromium_base import ChromiumBase
from .._pages.chromium_page import ChromiumPage
from .._pages.tabs import ChromiumTab
from .._pages.chromium_tab import ChromiumTab
def get_ele_txt(e: DrissionElement) -> str:

View File

@ -9,10 +9,11 @@ from pathlib import Path
from typing import Union, Tuple, List, Any, Optional, Literal
from .chromium_page import ChromiumPage
from .chromium_tab import ChromiumTab
from .mix_page import MixPage
from .tabs import ChromiumTab, MixTab
from .mix_tab import MixTab
from .._base.base import BasePage
from .._base.browser import Chromium
from .._base.chromium import Chromium
from .._base.driver import Driver
from .._elements.chromium_element import ChromiumElement
from .._elements.session_element import SessionElement

View File

@ -9,7 +9,8 @@ from pathlib import Path
from typing import Union, Tuple, List, Any, Optional, Literal
from .chromium_base import ChromiumBase
from .tabs import ChromiumTab, MixTab
from .chromium_tab import ChromiumTab
from .mix_tab import MixTab
from .._elements.chromium_element import ChromiumElement, ShadowRoot
from .._functions.elements import ChromiumElementsList
from .._units.listener import FrameListener

View File

@ -7,7 +7,7 @@
"""
from time import sleep
from .._base.browser import Chromium
from .._base.chromium import Chromium
from .._functions.web import save_page
from .._pages.chromium_base import ChromiumBase
from .._units.setter import ChromiumPageSetter

View File

@ -8,10 +8,10 @@
from pathlib import Path
from typing import Union, Tuple, List, Optional
from .._base.browser import Chromium
from .._base.chromium import Chromium
from .._configs.chromium_options import ChromiumOptions
from .._pages.chromium_base import ChromiumBase
from .._pages.tabs import ChromiumTab
from .._pages.chromium_tab import ChromiumTab
from .._units.rect import TabRect
from .._units.setter import ChromiumPageSetter
from .._units.waiter import ChromiumPageWaiter

View File

@ -0,0 +1,70 @@
# -*- coding:utf-8 -*-
"""
@Author : g1879
@Contact : g1879@qq.com
@Copyright: (c) 2024 by g1879, Inc. All Rights Reserved.
@License : BSD 3-Clause.
"""
from copy import copy
from time import sleep
from .._functions.settings import Settings
from .._functions.web import save_page
from .._pages.chromium_base import ChromiumBase
from .._units.setter import TabSetter
from .._units.waiter import TabWaiter
class ChromiumTab(ChromiumBase):
_TABS = {}
def __new__(cls, browser, tab_id):
if Settings.singleton_tab_obj and tab_id in cls._TABS:
r = cls._TABS[tab_id]
while not hasattr(r, '_frame_id'):
sleep(.1)
return r
r = object.__new__(cls)
cls._TABS[tab_id] = r
return r
def __init__(self, browser, tab_id):
if Settings.singleton_tab_obj and hasattr(self, '_created'):
return
self._created = True
super().__init__(browser, tab_id)
self._tab = self
self._type = 'ChromiumTab'
def _d_set_runtime_settings(self):
self._timeouts = copy(self.browser.timeouts)
self.retry_times = self.browser.retry_times
self.retry_interval = self.browser.retry_interval
self._load_mode = self.browser._load_mode
self._download_path = self.browser.download_path
self._auto_handle_alert = self.browser._auto_handle_alert
def close(self, others=False):
self.browser.close_tabs(self.tab_id, others=others)
@property
def set(self):
if self._set is None:
self._set = TabSetter(self)
return self._set
@property
def wait(self):
if self._wait is None:
self._wait = TabWaiter(self)
return self._wait
def save(self, path=None, name=None, as_pdf=False, **kwargs):
return save_page(self, path, name, as_pdf, kwargs)
def __repr__(self):
return f'<ChromiumTab browser_id={self.browser.id} tab_id={self.tab_id}>'
def _on_disconnect(self):
ChromiumTab._TABS.pop(self.tab_id, None)

View File

@ -0,0 +1,108 @@
# -*- coding:utf-8 -*-
"""
@Author : g1879
@Contact : g1879@qq.com
@Copyright: (c) 2024 by g1879, Inc. All Rights Reserved.
@License : BSD 3-Clause.
"""
from pathlib import Path
from typing import Union, Optional
from .chromium_base import ChromiumBase
from .._base.chromium import Chromium
from .._units.rect import TabRect
from .._units.setter import TabSetter
from .._units.waiter import TabWaiter
class ChromiumTab(ChromiumBase):
"""实现浏览器标签页的类"""
_TABS: dict = ...
_tab: ChromiumTab = ...
_rect: Optional[TabRect] = ...
def __new__(cls, browser: Chromium, tab_id: str):
"""
:param browser: Browser对象
:param tab_id: 标签页id
"""
...
def __init__(self, browser: Chromium, tab_id: str):
"""
:param browser: Browser对象
:param tab_id: 标签页id
"""
...
def _d_set_runtime_settings(self) -> None:
"""重写设置浏览器运行参数方法"""
...
def close(self, others: bool = False) -> None:
"""关闭标签页
:param others: 是否关闭其它保留自己
:return: None
"""
...
@property
def set(self) -> TabSetter:
"""返回用于设置的对象"""
...
@property
def wait(self) -> TabWaiter:
"""返回用于等待的对象"""
...
def save(self,
path: Union[str, Path] = None,
name: str = None,
as_pdf: bool = False,
landscape: bool = False,
displayHeaderFooter: bool = False,
printBackground: bool = False,
scale: float = 1,
paperWidth: float = 8.5,
paperHeight: float = 11,
marginTop: float = 11,
marginBottom: float = 1,
marginLeft: float = 1,
marginRight: float = 1,
pageRanges: str = '',
headerTemplate: str = '',
footerTemplate: str = '',
preferCSSPageSize: bool = False,
generateTaggedPDF: bool = ...,
generateDocumentOutline: bool = ...) -> Union[bytes, str]:
"""把当前页面保存为文件如果path和name参数都为None只返回文本
:param path: 保存路径为None且name不为None时保存在当前路径
:param name: 文件名为None且path不为None时用title属性值
:param as_pdf: 为Ture保存为pdf否则为mhtml且忽略kwargs参数
:param landscape: 纸张方向as_pdf为True时才生效
:param displayHeaderFooter: 是否显示页头页脚as_pdf为True时才生效
:param printBackground: 是否打印背景图片as_pdf为True时才生效
:param scale: 缩放比例as_pdf为True时才生效
:param paperWidth: 页面宽度英寸as_pdf为True时才生效
:param paperHeight: 页面高度英寸as_pdf为True时才生效
:param marginTop: 上边距英寸as_pdf为True时才生效
:param marginBottom: 下边距英寸as_pdf为True时才生效
:param marginLeft: 左边距英寸as_pdf为True时才生效
:param marginRight: 右边距英寸as_pdf为True时才生效
:param pageRanges: 页面范围格式'1-5, 8, 11-13'as_pdf为True时才生效
:param headerTemplate: 页头HTML模板as_pdf为True时才生效
模板可包含以下class
- date日期
- title文档标题
- url文档url
- pageNumber当前页码
- totalPages总页数
示例<span class=title></span>
:param footerTemplate: 页脚HTML模板格式与页头的一样as_pdf为True时才生效
:param preferCSSPageSize: 是否使用css定义的页面大小as_pdf为True时才生效
:param generateTaggedPDF: 是否生成带标签的(可访问的)PDF默认为嵌入器选择as_pdf为True时才生效
:param generateDocumentOutline: 是否将文档大纲嵌入到PDF中as_pdf为True时才生效
:return: as_pdf为True时返回bytes否则返回文件文本
"""
...

View File

@ -11,8 +11,8 @@ from requests import Session, Response
from .chromium_frame import ChromiumFrame
from .chromium_page import ChromiumPage
from .mix_tab import MixTab
from .session_page import SessionPage
from .tabs import MixTab
from .._base.base import BasePage
from .._configs.chromium_options import ChromiumOptions
from .._configs.session_options import SessionOptions

View File

@ -5,74 +5,14 @@
@Copyright: (c) 2024 by g1879, Inc. All Rights Reserved.
@License : BSD 3-Clause.
"""
from copy import copy
from time import sleep
from .chromium_tab import ChromiumTab
from .._base.base import BasePage
from .._configs.session_options import SessionOptions
from .._functions.cookies import set_session_cookies, set_tab_cookies
from .._functions.settings import Settings
from .._functions.web import save_page
from .._pages.chromium_base import ChromiumBase
from .._pages.session_page import SessionPage
from .._units.setter import TabSetter, MixTabSetter
from .._units.waiter import TabWaiter
class ChromiumTab(ChromiumBase):
"""实现浏览器标签页的类"""
_TABS = {}
def __new__(cls, browser, tab_id):
if Settings.singleton_tab_obj and tab_id in cls._TABS:
r = cls._TABS[tab_id]
while not hasattr(r, '_frame_id'):
sleep(.1)
return r
r = object.__new__(cls)
cls._TABS[tab_id] = r
return r
def __init__(self, browser, tab_id):
if Settings.singleton_tab_obj and hasattr(self, '_created'):
return
self._created = True
super().__init__(browser, tab_id)
self._tab = self
self._type = 'ChromiumTab'
def _d_set_runtime_settings(self):
self._timeouts = copy(self.browser.timeouts)
self.retry_times = self.browser.retry_times
self.retry_interval = self.browser.retry_interval
self._load_mode = self.browser._load_mode
self._download_path = self.browser.download_path
self._auto_handle_alert = self.browser._auto_handle_alert
def close(self, others=False):
self.browser.close_tabs(self.tab_id, others=others)
@property
def set(self):
if self._set is None:
self._set = TabSetter(self)
return self._set
@property
def wait(self):
if self._wait is None:
self._wait = TabWaiter(self)
return self._wait
def save(self, path=None, name=None, as_pdf=False, **kwargs):
return save_page(self, path, name, as_pdf, kwargs)
def __repr__(self):
return f'<ChromiumTab browser_id={self.browser.id} tab_id={self.tab_id}>'
def _on_disconnect(self):
ChromiumTab._TABS.pop(self.tab_id, None)
from .._units.setter import MixTabSetter
class MixTab(SessionPage, ChromiumTab, BasePage):

View File

@ -5,114 +5,20 @@
@Copyright: (c) 2024 by g1879, Inc. All Rights Reserved.
@License : BSD 3-Clause.
"""
from pathlib import Path
from typing import Union, Tuple, Any, Optional, Literal
from requests import Session, Response
from .chromium_base import ChromiumBase
from .chromium_frame import ChromiumFrame
from .chromium_tab import ChromiumTab
from .session_page import SessionPage
from .._base.browser import Chromium
from .._base.chromium import Chromium
from .._elements.chromium_element import ChromiumElement
from .._elements.session_element import SessionElement
from .._functions.cookies import CookiesList
from .._functions.elements import SessionElementsList, ChromiumElementsList
from .._units.rect import TabRect
from .._units.setter import TabSetter, MixTabSetter
from .._units.waiter import TabWaiter, MixTabWaiter
class ChromiumTab(ChromiumBase):
_TABS: dict = ...
_tab: ChromiumTab = ...
_rect: Optional[TabRect] = ...
def __new__(cls, browser: Chromium, tab_id: str):
"""
:param browser: Browser对象
:param tab_id: 标签页id
"""
...
def __init__(self, browser: Chromium, tab_id: str):
"""
:param browser: Browser对象
:param tab_id: 标签页id
"""
...
def _d_set_runtime_settings(self) -> None:
"""重写设置浏览器运行参数方法"""
...
def close(self, others: bool = False) -> None:
"""关闭标签页
:param others: 是否关闭其它保留自己
:return: None
"""
...
@property
def set(self) -> TabSetter:
"""返回用于设置的对象"""
...
@property
def wait(self) -> TabWaiter:
"""返回用于等待的对象"""
...
def save(self,
path: Union[str, Path] = None,
name: str = None,
as_pdf: bool = False,
landscape: bool = False,
displayHeaderFooter: bool = False,
printBackground: bool = False,
scale: float = 1,
paperWidth: float = 8.5,
paperHeight: float = 11,
marginTop: float = 11,
marginBottom: float = 1,
marginLeft: float = 1,
marginRight: float = 1,
pageRanges: str = '',
headerTemplate: str = '',
footerTemplate: str = '',
preferCSSPageSize: bool = False,
generateTaggedPDF: bool = ...,
generateDocumentOutline: bool = ...) -> Union[bytes, str]:
"""把当前页面保存为文件如果path和name参数都为None只返回文本
:param path: 保存路径为None且name不为None时保存在当前路径
:param name: 文件名为None且path不为None时用title属性值
:param as_pdf: 为Ture保存为pdf否则为mhtml且忽略kwargs参数
:param landscape: 纸张方向as_pdf为True时才生效
:param displayHeaderFooter: 是否显示页头页脚as_pdf为True时才生效
:param printBackground: 是否打印背景图片as_pdf为True时才生效
:param scale: 缩放比例as_pdf为True时才生效
:param paperWidth: 页面宽度英寸as_pdf为True时才生效
:param paperHeight: 页面高度英寸as_pdf为True时才生效
:param marginTop: 上边距英寸as_pdf为True时才生效
:param marginBottom: 下边距英寸as_pdf为True时才生效
:param marginLeft: 左边距英寸as_pdf为True时才生效
:param marginRight: 右边距英寸as_pdf为True时才生效
:param pageRanges: 页面范围格式'1-5, 8, 11-13'as_pdf为True时才生效
:param headerTemplate: 页头HTML模板as_pdf为True时才生效
模板可包含以下class
- date日期
- title文档标题
- url文档url
- pageNumber当前页码
- totalPages总页数
示例<span class=title></span>
:param footerTemplate: 页脚HTML模板格式与页头的一样as_pdf为True时才生效
:param preferCSSPageSize: 是否使用css定义的页面大小as_pdf为True时才生效
:param generateTaggedPDF: 是否生成带标签的(可访问的)PDF默认为嵌入器选择as_pdf为True时才生效
:param generateDocumentOutline: 是否将文档大纲嵌入到PDF中as_pdf为True时才生效
:return: as_pdf为True时返回bytes否则返回文件文本
"""
...
from .._units.setter import MixTabSetter
from .._units.waiter import MixTabWaiter
class MixTab(SessionPage, ChromiumTab):

View File

@ -204,7 +204,7 @@ class Actions:
def key_down(self, key: Union[KEYS, str]) -> Actions:
"""按下键盘上的按键,
:param key: 使用Keys获取的按键'DEL'形式按键名称
:param key: 使用Keys获取的按键 'DEL' 形式按键名称
:return: self
"""
...

View File

@ -10,7 +10,8 @@ from typing import Union
from .downloader import DownloadMission
from .._elements.chromium_element import ChromiumElement
from .._pages.tabs import MixTab, ChromiumTab
from .._pages.chromium_tab import ChromiumTab
from .._pages.mix_tab import MixTab
class Clicker(object):

View File

@ -8,11 +8,11 @@
from http.cookiejar import Cookie, CookieJar
from typing import Union
from .._base.browser import Chromium
from .._base.chromium import Chromium
from .._pages.chromium_base import ChromiumBase
from .._pages.tabs import MixTab
from .._pages.session_page import SessionPage
from .._pages.mix_page import MixPage
from .._pages.mix_tab import MixTab
from .._pages.session_page import SessionPage
class BrowserCookiesSetter(object):

View File

@ -7,7 +7,7 @@
"""
from typing import Dict, Optional, Union, Literal
from .._base.browser import Chromium
from .._base.chromium import Chromium
from .._pages.chromium_base import ChromiumBase
FILE_EXISTS = Literal['skip', 'rename', 'overwrite', 's', 'r', 'o']

View File

@ -5,15 +5,15 @@
@Copyright: (c) 2024 by g1879, Inc. All Rights Reserved.
@License : BSD 3-Clause.
"""
from typing import Tuple, Union
from .._elements.chromium_element import ChromiumElement
from .._pages.chromium_base import ChromiumBase
from .._pages.chromium_frame import ChromiumFrame
from .._pages.chromium_page import ChromiumPage
from .._pages.tabs import ChromiumTab, MixTab
from .._pages.chromium_tab import ChromiumTab
from .._pages.mix_page import MixPage
from .._pages.mix_tab import MixTab
class ElementRect(object):

View File

@ -11,8 +11,9 @@ from .._elements.chromium_element import ChromiumElement
from .._pages.chromium_base import ChromiumBase
from .._pages.chromium_frame import ChromiumFrame
from .._pages.chromium_page import ChromiumPage
from .._pages.chromium_tab import ChromiumTab
from .._pages.mix_page import MixPage
from .._pages.tabs import ChromiumTab, MixTab
from .._pages.mix_tab import MixTab
class Scroller(object):

View File

@ -14,14 +14,15 @@ from requests.auth import HTTPBasicAuth
from .cookies_setter import SessionCookiesSetter, CookiesSetter, MixPageCookiesSetter, BrowserCookiesSetter
from .scroller import PageScroller
from .._base.base import BasePage
from .._base.browser import Chromium
from .._base.chromium import Chromium
from .._elements.chromium_element import ChromiumElement
from .._pages.chromium_base import ChromiumBase
from .._pages.chromium_frame import ChromiumFrame
from .._pages.chromium_page import ChromiumPage
from .._pages.tabs import ChromiumTab, MixTab
from .._pages.session_page import SessionPage
from .._pages.chromium_tab import ChromiumTab
from .._pages.mix_page import MixPage
from .._pages.mix_tab import MixTab
from .._pages.session_page import SessionPage
FILE_EXISTS = Literal['skip', 'rename', 'overwrite', 's', 'r', 'o']

View File

@ -7,7 +7,7 @@
"""
from typing import Union, Tuple, List, Optional, Literal
from .._base.browser import Chromium
from .._base.chromium import Chromium
from .._elements.chromium_element import ShadowRoot, ChromiumElement
from .._pages.chromium_base import ChromiumBase
from .._pages.chromium_frame import ChromiumFrame

View File

@ -8,13 +8,14 @@
from typing import Union, Tuple, List, Any
from .downloader import DownloadMission
from .._base.browser import Chromium
from .._base.chromium import Chromium
from .._elements.chromium_element import ChromiumElement
from .._pages.chromium_base import ChromiumBase
from .._pages.chromium_frame import ChromiumFrame
from .._pages.chromium_page import ChromiumPage
from .._pages.chromium_tab import ChromiumTab
from .._pages.mix_page import MixPage
from .._pages.tabs import ChromiumTab, MixTab
from .._pages.mix_tab import MixTab
class OriginWaiter(object):

View File

@ -5,7 +5,7 @@
@Copyright: (c) 2024 by g1879, Inc. All Rights Reserved.
@License : BSD 3-Clause.
"""
from ._base.browser import Chromium
from ._base.chromium import Chromium
from ._elements.session_element import make_session_ele
from ._functions.by import By
from ._functions.elements import get_eles

View File

@ -9,8 +9,9 @@ from ._elements.chromium_element import ChromiumElement, ShadowRoot
from ._elements.none_element import NoneElement
from ._elements.session_element import SessionElement
from ._pages.chromium_frame import ChromiumFrame
from ._pages.tabs import ChromiumTab, MixTab
from ._pages.tabs import MixTab as WebPageTab
from ._pages.chromium_tab import ChromiumTab
from ._pages.mix_tab import MixTab
from ._pages.mix_tab import MixTab as WebPageTab
__all__ = ['ChromiumElement', 'ShadowRoot', 'NoneElement', 'SessionElement', 'ChromiumFrame', 'ChromiumTab',
'MixTab', 'WebPageTab']

View File

@ -1,34 +0,0 @@
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<meta content="code-wXFsIBcC45" name="baidu-site-verification"/>
<title>DrissionPage</title>
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible"/>
<meta content="Description" name="description">
<meta content="width=device-width, initial-scale=1.0, minimum-scale=1.0" name="viewport">
<meta content="DrissionPage,文档,使用文档,教程,用户手册,api" name="Keywords">
<!-- <link href="//cdn.jsdelivr.net/npm/docsify@4/lib/themes/vue.css" rel="stylesheet">-->
<!-- Theme: Simple Dark -->
<!-- <link href="scripts/theme-simple-dark.css" rel="stylesheet">-->
<!--
<link href="//unpkg.com/gitalk/dist/gitalk.css" rel="stylesheet">
<link rel="stylesheet" href="./ignore/font.css">
-->
<!-- <style>
/* body {font-family: PingFang; } */
</style> -->
</head>
<body>
<div id="app"><a href="http://g1879.gitee.io/drissionpagedocs">DrissionPage文档</a></div>
<script>
window.location.replace("http://g1879.gitee.io/drissionpagedocs");
</script>
</body>
</html>