From 1a5ec884f185a0681bc392e2619fdfafdf6bb968 Mon Sep 17 00:00:00 2001 From: g1879 Date: Fri, 8 Dec 2023 23:31:25 +0800 Subject: [PATCH] =?UTF-8?q?=5Fcommon=E6=94=B9=E5=90=8D=E4=B8=BA=5Ffunction?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/__init__.py | 2 +- DrissionPage/_base/base.py | 6 +++--- DrissionPage/_base/browser.py | 2 +- DrissionPage/_configs/chromium_options.py | 2 +- DrissionPage/_configs/session_options.py | 2 +- DrissionPage/_elements/chromium_element.py | 10 +++++----- DrissionPage/_elements/session_element.py | 4 ++-- DrissionPage/{_commons => _functions}/browser.py | 0 DrissionPage/{_commons => _functions}/browser.pyi | 0 DrissionPage/{_commons => _functions}/by.py | 0 DrissionPage/{_commons => _functions}/cli.py | 2 +- DrissionPage/{_commons => _functions}/keys.py | 0 DrissionPage/{_commons => _functions}/keys.pyi | 0 DrissionPage/{_commons => _functions}/locator.py | 0 DrissionPage/{_commons => _functions}/locator.pyi | 0 DrissionPage/{_commons => _functions}/settings.py | 0 DrissionPage/{_commons => _functions}/tools.py | 0 DrissionPage/{_commons => _functions}/tools.pyi | 0 DrissionPage/{_commons => _functions}/web.py | 0 DrissionPage/{_commons => _functions}/web.pyi | 0 DrissionPage/_pages/chromium_base.py | 8 ++++---- DrissionPage/_pages/chromium_page.py | 2 +- DrissionPage/_pages/chromium_tab.py | 2 +- DrissionPage/_pages/session_page.py | 4 +++- DrissionPage/_pages/session_page.pyi | 3 ++- DrissionPage/_pages/web_page.py | 2 +- DrissionPage/_units/actions.py | 4 ++-- DrissionPage/_units/clicker.py | 4 ++-- DrissionPage/_units/downloader.py | 2 +- DrissionPage/_units/screencast.py | 2 +- DrissionPage/_units/setter.py | 4 ++-- DrissionPage/_units/states.py | 2 +- DrissionPage/_units/waiter.py | 2 +- DrissionPage/common.py | 8 ++++---- setup.py | 2 +- 35 files changed, 42 insertions(+), 39 deletions(-) rename DrissionPage/{_commons => _functions}/browser.py (100%) rename DrissionPage/{_commons => _functions}/browser.pyi (100%) rename DrissionPage/{_commons => _functions}/by.py (100%) rename DrissionPage/{_commons => _functions}/cli.py (96%) rename DrissionPage/{_commons => _functions}/keys.py (100%) rename DrissionPage/{_commons => _functions}/keys.pyi (100%) rename DrissionPage/{_commons => _functions}/locator.py (100%) rename DrissionPage/{_commons => _functions}/locator.pyi (100%) rename DrissionPage/{_commons => _functions}/settings.py (100%) rename DrissionPage/{_commons => _functions}/tools.py (100%) rename DrissionPage/{_commons => _functions}/tools.pyi (100%) rename DrissionPage/{_commons => _functions}/web.py (100%) rename DrissionPage/{_commons => _functions}/web.pyi (100%) diff --git a/DrissionPage/__init__.py b/DrissionPage/__init__.py index b1205d5..01c6967 100644 --- a/DrissionPage/__init__.py +++ b/DrissionPage/__init__.py @@ -13,4 +13,4 @@ from ._configs.chromium_options import ChromiumOptions from ._configs.session_options import SessionOptions __all__ = ['ChromiumPage', 'ChromiumOptions', 'SessionOptions', 'SessionPage', 'WebPage', '__version__'] -__version__ = '4.0.0b17' +__version__ = '4.0.0b18' diff --git a/DrissionPage/_base/base.py b/DrissionPage/_base/base.py index 7568f90..22ced5a 100644 --- a/DrissionPage/_base/base.py +++ b/DrissionPage/_base/base.py @@ -8,9 +8,9 @@ from re import sub from DownloadKit import DownloadKit -from .._commons.settings import Settings -from .._commons.locator import get_loc -from .._commons.web import format_html +from .._functions.settings import Settings +from .._functions.locator import get_loc +from .._functions.web import format_html from .._elements.none_element import NoneElement from ..errors import ElementNotFoundError diff --git a/DrissionPage/_base/browser.py b/DrissionPage/_base/browser.py index 5d2ed0c..88da578 100644 --- a/DrissionPage/_base/browser.py +++ b/DrissionPage/_base/browser.py @@ -6,7 +6,7 @@ from time import sleep, perf_counter from .chromium_driver import BrowserDriver, ChromiumDriver -from .._commons.tools import stop_process_on_port, raise_error +from .._functions.tools import stop_process_on_port, raise_error from .._units.downloader import DownloadManager __ERROR__ = 'error' diff --git a/DrissionPage/_configs/chromium_options.py b/DrissionPage/_configs/chromium_options.py index fca7805..3d4515d 100644 --- a/DrissionPage/_configs/chromium_options.py +++ b/DrissionPage/_configs/chromium_options.py @@ -10,7 +10,7 @@ from tempfile import gettempdir, TemporaryDirectory from threading import Lock from .options_manage import OptionsManager -from .._commons.tools import port_is_using, clean_folder +from .._functions.tools import port_is_using, clean_folder class ChromiumOptions(object): diff --git a/DrissionPage/_configs/session_options.py b/DrissionPage/_configs/session_options.py index 88b396f..3331d98 100644 --- a/DrissionPage/_configs/session_options.py +++ b/DrissionPage/_configs/session_options.py @@ -9,7 +9,7 @@ from requests import Session from requests.structures import CaseInsensitiveDict from .options_manage import OptionsManager -from .._commons.web import cookies_to_tuple, set_session_cookies +from .._functions.web import cookies_to_tuple, set_session_cookies class SessionOptions(object): diff --git a/DrissionPage/_elements/chromium_element.py b/DrissionPage/_elements/chromium_element.py index a89ea63..f09b089 100644 --- a/DrissionPage/_elements/chromium_element.py +++ b/DrissionPage/_elements/chromium_element.py @@ -11,11 +11,11 @@ from time import perf_counter, sleep from .none_element import NoneElement from .session_element import make_session_ele from .._base.base import DrissionElement, BaseElement -from .._commons.keys import input_text_or_keys -from .._commons.locator import get_loc -from .._commons.settings import Settings -from .._commons.tools import get_usable_path -from .._commons.web import make_absolute_link, get_ele_txt, format_html, is_js_func, offset_scroll +from .._functions.keys import input_text_or_keys +from .._functions.locator import get_loc +from .._functions.settings import Settings +from .._functions.tools import get_usable_path +from .._functions.web import make_absolute_link, get_ele_txt, format_html, is_js_func, offset_scroll from .._units.clicker import Clicker from .._units.rect import ElementRect from .._units.scroller import ElementScroller diff --git a/DrissionPage/_elements/session_element.py b/DrissionPage/_elements/session_element.py index bd19b87..6bd6326 100644 --- a/DrissionPage/_elements/session_element.py +++ b/DrissionPage/_elements/session_element.py @@ -11,8 +11,8 @@ from lxml.html import HtmlElement, fromstring from .none_element import NoneElement from .._base.base import DrissionElement, BasePage, BaseElement -from .._commons.locator import get_loc -from .._commons.web import get_ele_txt, make_absolute_link +from .._functions.locator import get_loc +from .._functions.web import get_ele_txt, make_absolute_link class SessionElement(DrissionElement): diff --git a/DrissionPage/_commons/browser.py b/DrissionPage/_functions/browser.py similarity index 100% rename from DrissionPage/_commons/browser.py rename to DrissionPage/_functions/browser.py diff --git a/DrissionPage/_commons/browser.pyi b/DrissionPage/_functions/browser.pyi similarity index 100% rename from DrissionPage/_commons/browser.pyi rename to DrissionPage/_functions/browser.pyi diff --git a/DrissionPage/_commons/by.py b/DrissionPage/_functions/by.py similarity index 100% rename from DrissionPage/_commons/by.py rename to DrissionPage/_functions/by.py diff --git a/DrissionPage/_commons/cli.py b/DrissionPage/_functions/cli.py similarity index 96% rename from DrissionPage/_commons/cli.py rename to DrissionPage/_functions/cli.py index ec3bec8..a06b228 100644 --- a/DrissionPage/_commons/cli.py +++ b/DrissionPage/_functions/cli.py @@ -5,7 +5,7 @@ """ from click import command, option -from .._commons.tools import configs_to_here as ch +from .._functions.tools import configs_to_here as ch from .._configs.chromium_options import ChromiumOptions from .._pages.chromium_page import ChromiumPage diff --git a/DrissionPage/_commons/keys.py b/DrissionPage/_functions/keys.py similarity index 100% rename from DrissionPage/_commons/keys.py rename to DrissionPage/_functions/keys.py diff --git a/DrissionPage/_commons/keys.pyi b/DrissionPage/_functions/keys.pyi similarity index 100% rename from DrissionPage/_commons/keys.pyi rename to DrissionPage/_functions/keys.pyi diff --git a/DrissionPage/_commons/locator.py b/DrissionPage/_functions/locator.py similarity index 100% rename from DrissionPage/_commons/locator.py rename to DrissionPage/_functions/locator.py diff --git a/DrissionPage/_commons/locator.pyi b/DrissionPage/_functions/locator.pyi similarity index 100% rename from DrissionPage/_commons/locator.pyi rename to DrissionPage/_functions/locator.pyi diff --git a/DrissionPage/_commons/settings.py b/DrissionPage/_functions/settings.py similarity index 100% rename from DrissionPage/_commons/settings.py rename to DrissionPage/_functions/settings.py diff --git a/DrissionPage/_commons/tools.py b/DrissionPage/_functions/tools.py similarity index 100% rename from DrissionPage/_commons/tools.py rename to DrissionPage/_functions/tools.py diff --git a/DrissionPage/_commons/tools.pyi b/DrissionPage/_functions/tools.pyi similarity index 100% rename from DrissionPage/_commons/tools.pyi rename to DrissionPage/_functions/tools.pyi diff --git a/DrissionPage/_commons/web.py b/DrissionPage/_functions/web.py similarity index 100% rename from DrissionPage/_commons/web.py rename to DrissionPage/_functions/web.py diff --git a/DrissionPage/_commons/web.pyi b/DrissionPage/_functions/web.pyi similarity index 100% rename from DrissionPage/_commons/web.pyi rename to DrissionPage/_functions/web.pyi diff --git a/DrissionPage/_pages/chromium_base.py b/DrissionPage/_pages/chromium_base.py index 1bf2f13..c51228c 100644 --- a/DrissionPage/_pages/chromium_base.py +++ b/DrissionPage/_pages/chromium_base.py @@ -11,10 +11,10 @@ from time import perf_counter, sleep from urllib.parse import quote from .._base.base import BasePage -from .._commons.locator import get_loc, is_loc -from .._commons.settings import Settings -from .._commons.tools import get_usable_path, raise_error -from .._commons.web import location_in_viewport +from .._functions.locator import get_loc, is_loc +from .._functions.settings import Settings +from .._functions.tools import get_usable_path, raise_error +from .._functions.web import location_in_viewport from .._elements.chromium_element import ChromiumElement, run_js, make_chromium_ele from .._elements.none_element import NoneElement from .._elements.session_element import make_session_ele diff --git a/DrissionPage/_pages/chromium_page.py b/DrissionPage/_pages/chromium_page.py index 0fd998b..ee3282a 100644 --- a/DrissionPage/_pages/chromium_page.py +++ b/DrissionPage/_pages/chromium_page.py @@ -9,7 +9,7 @@ from time import sleep, perf_counter from requests import get from .._base.browser import Browser -from .._commons.browser import connect_browser +from .._functions.browser import connect_browser from .._configs.chromium_options import ChromiumOptions from .._pages.chromium_base import ChromiumBase, Timeout from .._pages.chromium_tab import ChromiumTab diff --git a/DrissionPage/_pages/chromium_tab.py b/DrissionPage/_pages/chromium_tab.py index 126153f..2890dc0 100644 --- a/DrissionPage/_pages/chromium_tab.py +++ b/DrissionPage/_pages/chromium_tab.py @@ -6,7 +6,7 @@ from copy import copy from .._base.base import BasePage -from .._commons.web import set_session_cookies, set_browser_cookies +from .._functions.web import set_session_cookies, set_browser_cookies from .._configs.session_options import SessionOptions from .._pages.chromium_base import ChromiumBase from .._pages.session_page import SessionPage diff --git a/DrissionPage/_pages/session_page.py b/DrissionPage/_pages/session_page.py index 112db23..e94a899 100644 --- a/DrissionPage/_pages/session_page.py +++ b/DrissionPage/_pages/session_page.py @@ -13,9 +13,9 @@ from requests.structures import CaseInsensitiveDict from tldextract import extract from .._base.base import BasePage -from .._commons.web import cookie_to_dict from .._configs.session_options import SessionOptions from .._elements.session_element import SessionElement, make_session_ele +from .._functions.web import cookie_to_dict from .._units.setter import SessionPageSetter @@ -139,6 +139,8 @@ class SessionPage(BasePage): :param kwargs: 连接参数 :return: url是否可用 """ + if isinstance(url, Path): + url = str(url.absolute()) if not url.lower().startswith('http'): if url.startswith('file:///'): url = url[8:] diff --git a/DrissionPage/_pages/session_page.pyi b/DrissionPage/_pages/session_page.pyi index a0e8775..75c73fe 100644 --- a/DrissionPage/_pages/session_page.pyi +++ b/DrissionPage/_pages/session_page.pyi @@ -3,6 +3,7 @@ @Author : g1879 @Contact : g1879@qq.com """ +from pathlib import Path from typing import Any, Union, Tuple, List, Optional from requests import Session, Response @@ -66,7 +67,7 @@ class SessionPage(BasePage): def download_path(self) -> str: ... def get(self, - url: str, + url: Union[Path, str], show_errmsg: bool | None = False, retry: int | None = None, interval: float | None = None, diff --git a/DrissionPage/_pages/web_page.py b/DrissionPage/_pages/web_page.py index 2f75d8e..d7b9b59 100644 --- a/DrissionPage/_pages/web_page.py +++ b/DrissionPage/_pages/web_page.py @@ -7,8 +7,8 @@ from .chromium_page import ChromiumPage from .chromium_tab import WebPageTab from .session_page import SessionPage from .._base.base import BasePage -from .._commons.web import set_session_cookies, set_browser_cookies from .._configs.chromium_options import ChromiumOptions +from .._functions.web import set_session_cookies, set_browser_cookies from .._units.setter import WebPageSetter diff --git a/DrissionPage/_units/actions.py b/DrissionPage/_units/actions.py index 308d102..4d6a0ff 100644 --- a/DrissionPage/_units/actions.py +++ b/DrissionPage/_units/actions.py @@ -5,8 +5,8 @@ """ from time import sleep, perf_counter -from .._commons.keys import modifierBit, keyDescriptionForString, input_text_or_keys -from .._commons.web import location_in_viewport +from .._functions.keys import modifierBit, keyDescriptionForString, input_text_or_keys +from .._functions.web import location_in_viewport class Actions: diff --git a/DrissionPage/_units/clicker.py b/DrissionPage/_units/clicker.py index 18359ff..e297862 100644 --- a/DrissionPage/_units/clicker.py +++ b/DrissionPage/_units/clicker.py @@ -5,8 +5,8 @@ """ from time import perf_counter, sleep -from .._commons.settings import Settings -from .._commons.web import offset_scroll +from .._functions.settings import Settings +from .._functions.web import offset_scroll from ..errors import CanNotClickError, CDPError, NoRectError diff --git a/DrissionPage/_units/downloader.py b/DrissionPage/_units/downloader.py index a81df80..f3bb017 100644 --- a/DrissionPage/_units/downloader.py +++ b/DrissionPage/_units/downloader.py @@ -8,7 +8,7 @@ from pathlib import Path from shutil import move from time import sleep, perf_counter -from .._commons.tools import get_usable_path +from .._functions.tools import get_usable_path class DownloadManager(object): diff --git a/DrissionPage/_units/screencast.py b/DrissionPage/_units/screencast.py index 592fc89..4b927a8 100644 --- a/DrissionPage/_units/screencast.py +++ b/DrissionPage/_units/screencast.py @@ -9,7 +9,7 @@ from pathlib import Path from threading import Thread from time import sleep, time -from .._commons.tools import clean_folder +from .._functions.tools import clean_folder class Screencast(object): diff --git a/DrissionPage/_units/setter.py b/DrissionPage/_units/setter.py index d0bd70c..fae9f5f 100644 --- a/DrissionPage/_units/setter.py +++ b/DrissionPage/_units/setter.py @@ -7,8 +7,8 @@ from pathlib import Path from requests.structures import CaseInsensitiveDict -from .._commons.tools import show_or_hide_browser -from .._commons.web import set_browser_cookies, set_session_cookies +from .._functions.tools import show_or_hide_browser +from .._functions.web import set_browser_cookies, set_session_cookies class BasePageSetter(object): diff --git a/DrissionPage/_units/states.py b/DrissionPage/_units/states.py index c178d5e..dc4a020 100644 --- a/DrissionPage/_units/states.py +++ b/DrissionPage/_units/states.py @@ -3,7 +3,7 @@ @Author : g1879 @Contact : g1879@qq.com """ -from .._commons.web import location_in_viewport +from .._functions.web import location_in_viewport from ..errors import CDPError, NoRectError, PageClosedError, ElementLostError diff --git a/DrissionPage/_units/waiter.py b/DrissionPage/_units/waiter.py index 0d09ed3..b27328d 100644 --- a/DrissionPage/_units/waiter.py +++ b/DrissionPage/_units/waiter.py @@ -1,7 +1,7 @@ # -*- coding:utf-8 -*- from time import sleep, perf_counter -from .._commons.settings import Settings +from .._functions.settings import Settings from ..errors import WaitTimeoutError, NoRectError diff --git a/DrissionPage/common.py b/DrissionPage/common.py index 32fabb2..44ab030 100644 --- a/DrissionPage/common.py +++ b/DrissionPage/common.py @@ -3,11 +3,11 @@ @Author : g1879 @Contact : g1879@qq.com """ -from ._commons.by import By -from ._commons.keys import Keys -from ._commons.settings import Settings -from ._commons.tools import wait_until, configs_to_here from ._elements.session_element import make_session_ele +from ._functions.by import By +from ._functions.keys import Keys +from ._functions.settings import Settings +from ._functions.tools import wait_until, configs_to_here from ._units.actions import Actions __all__ = ['make_session_ele', 'Actions', 'Keys', 'By', 'Settings', 'wait_until', 'configs_to_here'] diff --git a/setup.py b/setup.py index c2e223a..1180e6d 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ with open("README.md", "r", encoding='utf-8') as fh: setup( name="DrissionPage", - version="4.0.0b17", + version="4.0.0b18", author="g1879", author_email="g1879@qq.com", description="Python based web automation tool. It can control the browser and send and receive data packets.",