More typing hints with strict checks
This commit is contained in:
parent
fd0986908c
commit
3e49ee8612
131 changed files with 18509 additions and 40 deletions
8
CHANGES
8
CHANGES
|
@ -2,6 +2,14 @@
|
|||
Changes
|
||||
=======
|
||||
|
||||
1.0.0 (*2023-09-16*)
|
||||
====================
|
||||
|
||||
- Refactor setup.py to pyproject.toml
|
||||
- Configurable parameters for pyppeteer call
|
||||
- Changing default parameters for pyppeteer
|
||||
- Support of Mathjax
|
||||
|
||||
0.1.1 (*2020-07-08*)
|
||||
====================
|
||||
|
||||
|
|
|
@ -8,7 +8,8 @@ version = "1.0.0"
|
|||
requires-python = ">=3.8"
|
||||
dependencies = [
|
||||
"Sphinx>=7.0.0",
|
||||
"pyppeteer"
|
||||
"pyppeteer",
|
||||
"typing_extensions"
|
||||
]
|
||||
license = {text = "EUPL-1.2"}
|
||||
authors = [
|
||||
|
@ -51,14 +52,14 @@ pyppeteer = "sphinx_pyppeteer_builder"
|
|||
[project.optional-dependencies]
|
||||
tests = [
|
||||
"pytest",
|
||||
"flake8",
|
||||
"pyright",
|
||||
"pylint",
|
||||
"pytest-cov"
|
||||
]
|
||||
setup = [
|
||||
"Sphinx",
|
||||
"pytest-runner",
|
||||
"flake8",
|
||||
"pyright",
|
||||
"pylint",
|
||||
"babel",
|
||||
"flit",
|
||||
|
@ -98,3 +99,76 @@ include = [
|
|||
"*.py",
|
||||
]
|
||||
|
||||
[tool.pyright]
|
||||
analyzeUnannotatedFunctions = true
|
||||
deprecateTypingAliases = true
|
||||
enableExperimentalFeatures = false
|
||||
enableTypeIgnoreComments = false
|
||||
reportAssertAlwaysTrue = "warning"
|
||||
reportCallInDefaultInitializer = "information"
|
||||
reportConstantRedefinition = "warning"
|
||||
reportDeprecated = "warning"
|
||||
reportDuplicateImport = "warning"
|
||||
reportFunctionMemberAccess = "warning"
|
||||
reportGeneralTypeIssues = "error"
|
||||
reportImplicitOverride = "warning"
|
||||
reportImplicitStringConcatenation = "information"
|
||||
reportImportCycles = "error"
|
||||
reportIncompatibleMethodOverride = "warning"
|
||||
reportIncompatibleVariableOverride = "warning"
|
||||
reportIncompleteStub = "warning"
|
||||
reportInconsistentConstructor = "warning"
|
||||
reportInvalidStringEscapeSequence = "error"
|
||||
reportInvalidStubStatement = "warning"
|
||||
reportInvalidTypeVarUse = "warning"
|
||||
reportMatchNotExhaustive = "warning"
|
||||
reportMissingImports = "error"
|
||||
reportMissingModuleSource = "warning"
|
||||
reportMissingParameterType = "error"
|
||||
reportMissingSuperCall = "warning"
|
||||
reportMissingTypeArgument = "error"
|
||||
reportMissingTypeStubs = "warning"
|
||||
reportOptionalCall = "error"
|
||||
reportOptionalContextManager = "error"
|
||||
reportOptionalIterable = "error"
|
||||
reportOptionalMemberAccess = "error"
|
||||
reportOptionalOperand = "error"
|
||||
reportOptionalSubscript = "error"
|
||||
reportOverlappingOverload = "warning"
|
||||
reportPrivateImportUsage = "error"
|
||||
reportPrivateUsage = "warning"
|
||||
reportPropertyTypeMismatch = "error"
|
||||
reportSelfClsParameterName = "error"
|
||||
reportShadowedImports = "warning"
|
||||
reportTypeCommentUsage = "warning"
|
||||
reportTypedDictNotRequiredAccess = "error"
|
||||
reportUnboundVariable = "error"
|
||||
reportUndefinedVariable = "error"
|
||||
reportUninitializedInstanceVariable = "warning"
|
||||
reportUnknownArgumentType = "error"
|
||||
reportUnknownLambdaType = "error"
|
||||
reportUnknownMemberType = "error"
|
||||
reportUnknownParameterType = "error"
|
||||
reportUnknownVariableType = "error"
|
||||
reportUnnecessaryCast = "warning"
|
||||
reportUnnecessaryComparison = "warning"
|
||||
reportUnnecessaryContains = "warning"
|
||||
reportUnnecessaryIsInstance = "warning"
|
||||
reportUnnecessaryTypeIgnoreComment = "warning"
|
||||
reportUnsupportedDunderAll = "warning"
|
||||
reportUntypedBaseClass = "error"
|
||||
reportUntypedClassDecorator = "error"
|
||||
reportUntypedFunctionDecorator = "error"
|
||||
reportUntypedNamedTuple = "error"
|
||||
reportUnusedCallResult = "warning"
|
||||
reportUnusedClass = "information"
|
||||
reportUnusedCoroutine = "error"
|
||||
reportUnusedExpression = "warning"
|
||||
reportUnusedFunction = "information"
|
||||
reportUnusedImport = "information"
|
||||
reportUnusedVariable = "warning"
|
||||
reportWildcardImportFromLibrary = "error"
|
||||
strictDictionaryInference = true
|
||||
strictListInference = true
|
||||
strictParameterNoneValue = true
|
||||
strictSetInference = true
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
from copy import deepcopy
|
||||
|
||||
from .pyppeteer_builder import PyppeteerPDFBuilder
|
||||
from typing import Dict, Any
|
||||
from typing import Dict, Any, Callable, Optional, List
|
||||
from sphinx.application import Sphinx
|
||||
from sphinx.config import Config
|
||||
from sphinx.util.osutil import make_filename
|
||||
|
@ -12,7 +12,7 @@ import pkg_resources
|
|||
__version__ = pkg_resources.get_distribution(__package__).version
|
||||
__version_info__ = tuple(int(v) for v in __version__.split('.'))
|
||||
|
||||
DEFAULT_PDF_OPTIONS = {
|
||||
DEFAULT_PDF_OPTIONS: Dict[str, Optional[bool|str|Dict[str,Optional[bool|str]]]] = {
|
||||
'printBackground': True,
|
||||
'format': 'A4',
|
||||
'margin': {
|
||||
|
@ -23,18 +23,18 @@ DEFAULT_PDF_OPTIONS = {
|
|||
}
|
||||
}
|
||||
|
||||
DEFAULT_PYPPETEER_ARGS = [
|
||||
DEFAULT_PYPPETEER_ARGS: List[str] = [
|
||||
'--allow-file-access-from-file',
|
||||
'--disable-web-security',
|
||||
'--no-sandbox',
|
||||
]
|
||||
]
|
||||
|
||||
|
||||
def on_config_inited(app, config: Config):
|
||||
def on_config_inited(app: Sphinx, config: Config):
|
||||
""" Change config on the fly """
|
||||
pdf_options = deepcopy(DEFAULT_PDF_OPTIONS)
|
||||
pdf_options:Dict[str, Any] = deepcopy(DEFAULT_PDF_OPTIONS)
|
||||
pdf_options.update(app.config.pyppeteer_pdf_options)
|
||||
app.config.pyppeteer_pdf_options = pdf_options
|
||||
app.config["pyppeteer_pdf_options"] = pdf_options
|
||||
app.set_html_assets_policy("always")
|
||||
|
||||
|
||||
|
@ -42,11 +42,13 @@ def setup(app: Sphinx) -> Dict[str, Any]:
|
|||
app.setup_extension('sphinx.builders.html')
|
||||
|
||||
app.add_builder(PyppeteerPDFBuilder)
|
||||
app.connect('config-inited', on_config_inited)
|
||||
_ = app.connect('config-inited', on_config_inited)
|
||||
|
||||
theme_options_func:Callable[[Config], str] = lambda self:\
|
||||
self.html_theme_options
|
||||
app.add_config_value(
|
||||
'pyppeteer_theme_options',
|
||||
lambda self: self.html_theme_options,
|
||||
theme_options_func,
|
||||
'pyppeteer'
|
||||
)
|
||||
app.add_config_value(
|
||||
|
@ -59,29 +61,44 @@ def setup(app: Sphinx) -> Dict[str, Any]:
|
|||
DEFAULT_PYPPETEER_ARGS,
|
||||
'pyppeteer'
|
||||
)
|
||||
|
||||
basename_func:Callable[[Config], str] = lambda self:\
|
||||
make_filename(self.project)
|
||||
app.add_config_value(
|
||||
'pyppeteer_basename',
|
||||
lambda self: make_filename(self.project),
|
||||
basename_func,
|
||||
'pyppeteer'
|
||||
)
|
||||
|
||||
theme_func:Callable[[Config], str] = lambda self:\
|
||||
self.html_theme
|
||||
app.add_config_value(
|
||||
'pyppeteer_theme',
|
||||
lambda self: self.html_theme,
|
||||
theme_func,
|
||||
'pyppeteer'
|
||||
)
|
||||
|
||||
title_func:Callable[[Config], str] = lambda self:\
|
||||
self.html_title
|
||||
app.add_config_value(
|
||||
'pyppeteer_title',
|
||||
lambda self: self.html_title,
|
||||
title_func,
|
||||
'pyppeteer'
|
||||
)
|
||||
|
||||
theme_path_func:Callable[[Config], str] = lambda self:\
|
||||
self.html_theme_path
|
||||
app.add_config_value(
|
||||
'pyppeteer_theme_path',
|
||||
lambda self: self.html_theme_path,
|
||||
theme_path_func,
|
||||
'pyppeteer'
|
||||
)
|
||||
|
||||
short_title_func:Callable[[Config], str] = lambda self:\
|
||||
self.html_short_title
|
||||
app.add_config_value(
|
||||
'pyppeteer_short_title',
|
||||
lambda self: self.html_short_title,
|
||||
short_title_func,
|
||||
'pyppeteer'
|
||||
)
|
||||
app.add_config_value(
|
||||
|
|
|
@ -1,9 +1,20 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import logging
|
||||
from sphinx.util import logging as sphinx_logging
|
||||
import sys
|
||||
from logging import StreamHandler, Formatter, LogRecord, DEBUG
|
||||
|
||||
from typing import TYPE_CHECKING, Optional, TextIO
|
||||
from typing_extensions import override
|
||||
|
||||
from sphinx.util.logging import getLogger, SphinxLoggerAdapter
|
||||
|
||||
logger: SphinxLoggerAdapter = getLogger('pyppeteer')
|
||||
|
||||
if TYPE_CHECKING:
|
||||
_StreamHandler = StreamHandler[TextIO]
|
||||
else:
|
||||
_StreamHandler = StreamHandler
|
||||
|
||||
logger = sphinx_logging.getLogger('pyppeteer')
|
||||
ppsphinx_log_inited = False
|
||||
|
||||
|
||||
|
@ -14,9 +25,9 @@ def init_ppsphinx_log() -> None:
|
|||
if ppsphinx_log_inited:
|
||||
return
|
||||
|
||||
formatter = logging.Formatter('%(message)s')
|
||||
formatter = Formatter('%(message)s')
|
||||
pphandler = SphinxPyppeteerHandler()
|
||||
pphandler.setLevel(logging.DEBUG)
|
||||
pphandler.setLevel(DEBUG)
|
||||
pphandler.setFormatter(formatter)
|
||||
logger_names = (
|
||||
'pyppeteer',
|
||||
|
@ -36,16 +47,17 @@ def init_ppsphinx_log() -> None:
|
|||
'pyppeteer.worker',
|
||||
)
|
||||
for logger_name in logger_names:
|
||||
pplogger = logging.getLogger(logger_name)
|
||||
pplogger.addHandler(pphandler)
|
||||
pplogger = getLogger(logger_name)
|
||||
pplogger.logger.addHandler(pphandler)
|
||||
|
||||
|
||||
class SphinxPyppeteerHandler(logging.StreamHandler):
|
||||
class SphinxPyppeteerHandler(_StreamHandler):
|
||||
"""
|
||||
Resend Pyppeteer logging to Sphinx output.
|
||||
"""
|
||||
def __init__(self):
|
||||
super(SphinxPyppeteerHandler, self).__init__()
|
||||
def __init__(self, stream: Optional[TextIO]=None) -> None:
|
||||
super(SphinxPyppeteerHandler, self).__init__(stream or sys.stderr)
|
||||
|
||||
def emit(self, record):
|
||||
@override
|
||||
def emit(self, record: LogRecord) -> None:
|
||||
logger.handle(record)
|
||||
|
|
|
@ -2,18 +2,25 @@
|
|||
|
||||
import os
|
||||
import asyncio
|
||||
from typing import Dict, Set, Tuple
|
||||
from typing import Set, Optional, Dict, Any
|
||||
|
||||
from typing_extensions import override
|
||||
|
||||
from sphinx.builders.singlehtml import SingleFileHTMLBuilder
|
||||
from sphinx.util.display import progress_message, logging
|
||||
from sphinx.util.display import progress_message
|
||||
from sphinx.util.logging import getLogger, SphinxLoggerAdapter
|
||||
from sphinx.util.osutil import os_path
|
||||
from sphinx.config import Config
|
||||
from sphinx.application import Sphinx
|
||||
from sphinx.environment import BuildEnvironment
|
||||
from sphinx.theming import Theme
|
||||
from sphinx.locale import __
|
||||
|
||||
import pyppeteer
|
||||
from .loghandler import init_ppsphinx_log
|
||||
|
||||
|
||||
logger = logging.getLogger('pyppeteer*')
|
||||
logger: SphinxLoggerAdapter = getLogger('pyppeteer*')
|
||||
|
||||
|
||||
class PyppeteerPDFBuilder(SingleFileHTMLBuilder):
|
||||
|
@ -22,30 +29,44 @@ class PyppeteerPDFBuilder(SingleFileHTMLBuilder):
|
|||
embedded = True
|
||||
search = False
|
||||
|
||||
def __init__(self, app: Sphinx, env: BuildEnvironment) -> None:
|
||||
self.config: Config
|
||||
self.theme: Theme
|
||||
self.globalcontext: Dict[str, Any]
|
||||
self.outdir: str
|
||||
super(PyppeteerPDFBuilder, self).__init__(app, env)
|
||||
|
||||
def _get_translations_js(self) -> str:
|
||||
return ""
|
||||
|
||||
@override
|
||||
def copy_translation_js(self) -> None:
|
||||
return
|
||||
|
||||
@override
|
||||
def copy_stemmer_js(self) -> None:
|
||||
return
|
||||
|
||||
@override
|
||||
def copy_html_favicon(self) -> None:
|
||||
return
|
||||
|
||||
def get_theme_config(self) -> Tuple[str, Dict]:
|
||||
@override
|
||||
def get_theme_config(self) -> tuple[str, Dict[str, Any]]:
|
||||
return (
|
||||
self.config.pyppeteer_theme,
|
||||
self.config.pyppeteer_theme_options
|
||||
)
|
||||
|
||||
@override
|
||||
def init_js_files(self) -> None:
|
||||
return
|
||||
|
||||
@override
|
||||
def add_js_file(self, filename: str, **kwargs: str) -> None:
|
||||
return
|
||||
|
||||
@override
|
||||
def prepare_writing(self, docnames: Set[str]) -> None:
|
||||
super(PyppeteerPDFBuilder, self).prepare_writing(docnames)
|
||||
if self.config.pyppeteer_style is not None:
|
||||
|
@ -64,20 +85,22 @@ class PyppeteerPDFBuilder(SingleFileHTMLBuilder):
|
|||
self.globalcontext['style'] = stylename
|
||||
self.globalcontext['favicon'] = None
|
||||
|
||||
@override
|
||||
def finish(self) -> None:
|
||||
super(PyppeteerPDFBuilder, self).finish()
|
||||
progress_message('Starting conversion to PDF with Pyppeteer')
|
||||
infile = os.path.join(
|
||||
_ = progress_message('Starting conversion to PDF with Pyppeteer')
|
||||
infile:str = os.path.join(
|
||||
self.outdir,
|
||||
os_path(self.config.master_doc) + self.out_suffix
|
||||
)
|
||||
outfile = os.path.join(
|
||||
outfile:str = os.path.join(
|
||||
self.outdir,
|
||||
self.config.pyppeteer_basename + '.pdf'
|
||||
)
|
||||
|
||||
url = 'file://' + infile
|
||||
pdf_options = self.config.pyppeteer_pdf_options
|
||||
url:str = 'file://' + infile
|
||||
pdf_options:Dict[str, Optional[bool|str|Dict[str,Optional[bool|str]]]] \
|
||||
= self.config.pyppeteer_pdf_options
|
||||
pdf_options['path'] = outfile
|
||||
init_ppsphinx_log()
|
||||
|
||||
|
@ -86,7 +109,7 @@ class PyppeteerPDFBuilder(SingleFileHTMLBuilder):
|
|||
self.generate_pdf(url, pdf_options)
|
||||
)
|
||||
|
||||
async def generate_pdf(self, url: str, pdf_options: dict) -> None:
|
||||
async def generate_pdf(self, url: str, pdf_options: Dict[str, Optional[bool|str|Dict[str,Optional[bool|str]]]]) -> None:
|
||||
"""
|
||||
Generate PDF
|
||||
|
||||
|
@ -105,8 +128,8 @@ class PyppeteerPDFBuilder(SingleFileHTMLBuilder):
|
|||
})
|
||||
try:
|
||||
page = await browser.newPage()
|
||||
await page.goto(url, {"waitUntil": ["networkidle2"]})
|
||||
await page.pdf(pdf_options)
|
||||
_ = await page.goto(url, {"waitUntil": ["networkidle2"]})
|
||||
_ = await page.pdf(pdf_options)
|
||||
await browser.close()
|
||||
finally:
|
||||
await browser.close()
|
||||
|
|
19
typings/pyppeteer/__init__.pyi
Normal file
19
typings/pyppeteer/__init__.pyi
Normal file
|
@ -0,0 +1,19 @@
|
|||
"""
|
||||
This type stub file was generated by pyright.
|
||||
"""
|
||||
|
||||
import logging
|
||||
import os
|
||||
from appdirs import AppDirs
|
||||
from importlib.metadata import version
|
||||
from pyppeteer.launcher import connect, defaultArgs, executablePath, launch
|
||||
|
||||
"""Meta data for pyppeteer."""
|
||||
__version__ = ...
|
||||
__chromium_revision__ = ...
|
||||
__base_puppeteer_version__ = ...
|
||||
__pyppeteer_home__: str = ...
|
||||
DEBUG = ...
|
||||
version = ...
|
||||
version_info = ...
|
||||
__all__ = ['connect', 'launch', 'executablePath', 'defaultArgs', 'version', 'version_info']
|
202
typings/pyppeteer/browser.pyi
Normal file
202
typings/pyppeteer/browser.pyi
Normal file
|
@ -0,0 +1,202 @@
|
|||
"""
|
||||
This type stub file was generated by pyright.
|
||||
"""
|
||||
|
||||
from subprocess import Popen
|
||||
from typing import Any, Awaitable, Callable, Dict, List, Optional
|
||||
from pyee import EventEmitter
|
||||
from pyppeteer.connection import Connection
|
||||
from pyppeteer.page import Page
|
||||
from pyppeteer.target import Target
|
||||
|
||||
"""Browser module."""
|
||||
logger = ...
|
||||
class Browser(EventEmitter):
|
||||
"""Browser class.
|
||||
|
||||
A Browser object is created when pyppeteer connects to chrome, either
|
||||
through :func:`~pyppeteer.launcher.launch` or
|
||||
:func:`~pyppeteer.launcher.connect`.
|
||||
"""
|
||||
Events = ...
|
||||
def __init__(self, connection: Connection, contextIds: List[str], ignoreHTTPSErrors: bool, defaultViewport: Optional[Dict], process: Optional[Popen] = ..., closeCallback: Callable[[], Awaitable[None]] = ..., **kwargs: Any) -> None:
|
||||
...
|
||||
|
||||
@property
|
||||
def process(self) -> Optional[Popen]:
|
||||
"""Return process of this browser.
|
||||
|
||||
If browser instance is created by :func:`pyppeteer.launcher.connect`,
|
||||
return ``None``.
|
||||
"""
|
||||
...
|
||||
|
||||
async def createIncogniteBrowserContext(self) -> BrowserContext:
|
||||
"""[Deprecated] Miss spelled method.
|
||||
|
||||
Use :meth:`createIncognitoBrowserContext` method instead.
|
||||
"""
|
||||
...
|
||||
|
||||
async def createIncognitoBrowserContext(self) -> BrowserContext:
|
||||
"""Create a new incognito browser context.
|
||||
|
||||
This won't share cookies/cache with other browser contexts.
|
||||
|
||||
.. code::
|
||||
|
||||
browser = await launch()
|
||||
# Create a new incognito browser context.
|
||||
context = await browser.createIncognitoBrowserContext()
|
||||
# Create a new page in a pristine context.
|
||||
page = await context.newPage()
|
||||
# Do stuff
|
||||
await page.goto('https://example.com')
|
||||
...
|
||||
"""
|
||||
...
|
||||
|
||||
@property
|
||||
def browserContexts(self) -> List[BrowserContext]:
|
||||
"""Return a list of all open browser contexts.
|
||||
|
||||
In a newly created browser, this will return a single instance of
|
||||
``[BrowserContext]``
|
||||
"""
|
||||
...
|
||||
|
||||
@staticmethod
|
||||
async def create(connection: Connection, contextIds: List[str], ignoreHTTPSErrors: bool, defaultViewport: Optional[Dict], process: Optional[Popen] = ..., closeCallback: Callable[[], Awaitable[None]] = ..., **kwargs: Any) -> Browser:
|
||||
"""Create browser object."""
|
||||
...
|
||||
|
||||
@property
|
||||
def wsEndpoint(self) -> str:
|
||||
"""Return websocket end point url."""
|
||||
...
|
||||
|
||||
async def newPage(self) -> Page:
|
||||
"""Make new page on this browser and return its object."""
|
||||
...
|
||||
|
||||
def targets(self) -> List[Target]:
|
||||
"""Get a list of all active targets inside the browser.
|
||||
|
||||
In case of multiple browser contexts, the method will return a list
|
||||
with all the targets in all browser contexts.
|
||||
"""
|
||||
...
|
||||
|
||||
async def pages(self) -> List[Page]:
|
||||
"""Get all pages of this browser.
|
||||
|
||||
Non visible pages, such as ``"background_page"``, will not be listed
|
||||
here. You can find then using :meth:`pyppeteer.target.Target.page`.
|
||||
|
||||
In case of multiple browser contexts, this method will return a list
|
||||
with all the pages in all browser contexts.
|
||||
"""
|
||||
...
|
||||
|
||||
async def version(self) -> str:
|
||||
"""Get version of the browser."""
|
||||
...
|
||||
|
||||
async def userAgent(self) -> str:
|
||||
"""Return browser's original user agent.
|
||||
|
||||
.. note::
|
||||
Pages can override browser user agent with
|
||||
:meth:`pyppeteer.page.Page.setUserAgent`.
|
||||
"""
|
||||
...
|
||||
|
||||
async def close(self) -> None:
|
||||
"""Close connections and terminate browser process."""
|
||||
...
|
||||
|
||||
async def disconnect(self) -> None:
|
||||
"""Disconnect browser."""
|
||||
...
|
||||
|
||||
|
||||
|
||||
class BrowserContext(EventEmitter):
|
||||
"""BrowserContext provides multiple independent browser sessions.
|
||||
|
||||
When a browser is launched, it has a single BrowserContext used by default.
|
||||
The method `browser.newPage()` creates a page in the default browser
|
||||
context.
|
||||
|
||||
If a page opens another page, e.g. with a ``window.open`` call, the popup
|
||||
will belong to the parent page's browser context.
|
||||
|
||||
Pyppeteer allows creation of "incognito" browser context with
|
||||
``browser.createIncognitoBrowserContext()`` method.
|
||||
"incognito" browser contexts don't write any browser data to disk.
|
||||
|
||||
.. code::
|
||||
|
||||
# Create new incognito browser context
|
||||
context = await browser.createIncognitoBrowserContext()
|
||||
# Create a new page inside context
|
||||
page = await context.newPage()
|
||||
# ... do stuff with page ...
|
||||
await page.goto('https://example.com')
|
||||
# Dispose context once it's no longer needed
|
||||
await context.close()
|
||||
"""
|
||||
Events = ...
|
||||
def __init__(self, browser: Browser, contextId: Optional[str]) -> None:
|
||||
...
|
||||
|
||||
def targets(self) -> List[Target]:
|
||||
"""Return a list of all active targets inside the browser context."""
|
||||
...
|
||||
|
||||
async def pages(self) -> List[Page]:
|
||||
"""Return list of all open pages.
|
||||
|
||||
Non-visible pages, such as ``"background_page"``, will not be listed
|
||||
here. You can find them using :meth:`pyppeteer.target.Target.page`.
|
||||
"""
|
||||
...
|
||||
|
||||
def isIncognite(self) -> bool:
|
||||
"""[Deprecated] Miss spelled method.
|
||||
|
||||
Use :meth:`isIncognito` method instead.
|
||||
"""
|
||||
...
|
||||
|
||||
def isIncognito(self) -> bool:
|
||||
"""Return whether BrowserContext is incognito.
|
||||
|
||||
The default browser context is the only non-incognito browser context.
|
||||
|
||||
.. note::
|
||||
The default browser context cannot be closed.
|
||||
"""
|
||||
...
|
||||
|
||||
async def newPage(self) -> Page:
|
||||
"""Create a new page in the browser context."""
|
||||
...
|
||||
|
||||
@property
|
||||
def browser(self) -> Browser:
|
||||
"""Return the browser this browser context belongs to."""
|
||||
...
|
||||
|
||||
async def close(self) -> None:
|
||||
"""Close the browser context.
|
||||
|
||||
All the targets that belongs to the browser context will be closed.
|
||||
|
||||
.. note::
|
||||
Only incognito browser context can be closed.
|
||||
"""
|
||||
...
|
||||
|
||||
|
||||
|
49
typings/pyppeteer/chromium_downloader.pyi
Normal file
49
typings/pyppeteer/chromium_downloader.pyi
Normal file
|
@ -0,0 +1,49 @@
|
|||
"""
|
||||
This type stub file was generated by pyright.
|
||||
"""
|
||||
|
||||
from io import BytesIO
|
||||
from pathlib import Path
|
||||
|
||||
"""Chromium download module."""
|
||||
logger = ...
|
||||
handler = ...
|
||||
DOWNLOADS_FOLDER = ...
|
||||
DEFAULT_DOWNLOAD_HOST = ...
|
||||
DOWNLOAD_HOST = ...
|
||||
BASE_URL = ...
|
||||
REVISION = ...
|
||||
NO_PROGRESS_BAR = ...
|
||||
if NO_PROGRESS_BAR.lower() in ('1', 'true'):
|
||||
NO_PROGRESS_BAR = ...
|
||||
windowsArchive = ...
|
||||
downloadURLs = ...
|
||||
chromiumExecutable = ...
|
||||
def current_platform() -> str:
|
||||
"""Get current platform name by short string."""
|
||||
...
|
||||
|
||||
def get_url() -> str:
|
||||
"""Get chromium download url."""
|
||||
...
|
||||
|
||||
def download_zip(url: str) -> BytesIO:
|
||||
"""Download data from url."""
|
||||
...
|
||||
|
||||
def extract_zip(data: BytesIO, path: Path) -> None:
|
||||
"""Extract zipped data to path."""
|
||||
...
|
||||
|
||||
def download_chromium() -> None:
|
||||
"""Download and extract chromium."""
|
||||
...
|
||||
|
||||
def chromium_executable() -> Path:
|
||||
"""Get path of the chromium executable."""
|
||||
...
|
||||
|
||||
def check_chromium() -> bool:
|
||||
"""Check if chromium is placed at correct path."""
|
||||
...
|
||||
|
9
typings/pyppeteer/command.pyi
Normal file
9
typings/pyppeteer/command.pyi
Normal file
|
@ -0,0 +1,9 @@
|
|||
"""
|
||||
This type stub file was generated by pyright.
|
||||
"""
|
||||
|
||||
"""Commands for Pyppeteer."""
|
||||
def install() -> None:
|
||||
"""Download chromium if not install."""
|
||||
...
|
||||
|
81
typings/pyppeteer/connection.pyi
Normal file
81
typings/pyppeteer/connection.pyi
Normal file
|
@ -0,0 +1,81 @@
|
|||
"""
|
||||
This type stub file was generated by pyright.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
from typing import Awaitable, Callable, Dict, TYPE_CHECKING, Union
|
||||
from pyee import EventEmitter
|
||||
|
||||
"""Connection/Session management module."""
|
||||
if TYPE_CHECKING:
|
||||
...
|
||||
logger = ...
|
||||
logger_connection = ...
|
||||
logger_session = ...
|
||||
class Connection(EventEmitter):
|
||||
"""Connection management class."""
|
||||
def __init__(self, url: str, loop: asyncio.AbstractEventLoop, delay: int = ...) -> None:
|
||||
"""Make connection.
|
||||
|
||||
:arg str url: WebSocket url to connect devtool.
|
||||
:arg int delay: delay to wait before processing received messages.
|
||||
"""
|
||||
...
|
||||
|
||||
@property
|
||||
def url(self) -> str:
|
||||
"""Get connected WebSocket url."""
|
||||
...
|
||||
|
||||
def send(self, method: str, params: dict = ...) -> Awaitable:
|
||||
"""Send message via the connection."""
|
||||
...
|
||||
|
||||
def setClosedCallback(self, callback: Callable[[], None]) -> None:
|
||||
"""Set closed callback."""
|
||||
...
|
||||
|
||||
async def dispose(self) -> None:
|
||||
"""Close all connection."""
|
||||
...
|
||||
|
||||
async def createSession(self, targetInfo: Dict) -> CDPSession:
|
||||
"""Create new session."""
|
||||
...
|
||||
|
||||
|
||||
|
||||
class CDPSession(EventEmitter):
|
||||
"""Chrome Devtools Protocol Session.
|
||||
|
||||
The :class:`CDPSession` instances are used to talk raw Chrome Devtools
|
||||
Protocol:
|
||||
|
||||
* protocol methods can be called with :meth:`send` method.
|
||||
* protocol events can be subscribed to with :meth:`on` method.
|
||||
|
||||
Documentation on DevTools Protocol can be found
|
||||
`here <https://chromedevtools.github.io/devtools-protocol/>`__.
|
||||
"""
|
||||
def __init__(self, connection: Union[Connection, CDPSession], targetType: str, sessionId: str, loop: asyncio.AbstractEventLoop) -> None:
|
||||
"""Make new session."""
|
||||
...
|
||||
|
||||
def send(self, method: str, params: dict = ...) -> Awaitable:
|
||||
"""Send message to the connected session.
|
||||
|
||||
:arg str method: Protocol method name.
|
||||
:arg dict params: Optional method parameters.
|
||||
"""
|
||||
...
|
||||
|
||||
async def detach(self) -> None:
|
||||
"""Detach session from target.
|
||||
|
||||
Once detached, session won't emit any events and can't be used to send
|
||||
messages.
|
||||
"""
|
||||
...
|
||||
|
||||
|
||||
|
144
typings/pyppeteer/coverage.pyi
Normal file
144
typings/pyppeteer/coverage.pyi
Normal file
|
@ -0,0 +1,144 @@
|
|||
"""
|
||||
This type stub file was generated by pyright.
|
||||
"""
|
||||
|
||||
from typing import Any, Dict, List
|
||||
from pyppeteer.connection import CDPSession
|
||||
|
||||
"""Coverage module."""
|
||||
logger = ...
|
||||
class Coverage:
|
||||
"""Coverage class.
|
||||
|
||||
Coverage gathers information about parts of JavaScript and CSS that were
|
||||
used by the page.
|
||||
|
||||
An example of using JavaScript and CSS coverage to get percentage of
|
||||
initially executed code::
|
||||
|
||||
# Enable both JavaScript and CSS coverage
|
||||
await page.coverage.startJSCoverage()
|
||||
await page.coverage.startCSSCoverage()
|
||||
|
||||
# Navigate to page
|
||||
await page.goto('https://example.com')
|
||||
# Disable JS and CSS coverage and get results
|
||||
jsCoverage = await page.coverage.stopJSCoverage()
|
||||
cssCoverage = await page.coverage.stopCSSCoverage()
|
||||
totalBytes = 0
|
||||
usedBytes = 0
|
||||
coverage = jsCoverage + cssCoverage
|
||||
for entry in coverage:
|
||||
totalBytes += len(entry['text'])
|
||||
for range in entry['ranges']:
|
||||
usedBytes += range['end'] - range['start'] - 1
|
||||
|
||||
print('Bytes used: {}%'.format(usedBytes / totalBytes * 100))
|
||||
"""
|
||||
def __init__(self, client: CDPSession) -> None:
|
||||
...
|
||||
|
||||
async def startJSCoverage(self, options: Dict[str, Any] = ..., **kwargs: Any) -> None:
|
||||
"""Start JS coverage measurement.
|
||||
|
||||
Available options are:
|
||||
|
||||
* ``resetOnNavigation`` (bool): Whether to reset coverage on every
|
||||
navigation. Defaults to ``True``.
|
||||
* ``reportAnonymousScript`` (bool): Whether anonymous script generated
|
||||
by the page should be reported. Defaults to ``False``.
|
||||
|
||||
.. note::
|
||||
Anonymous scripts are ones that don't have an associated url. These
|
||||
are scripts that are dynamically created on the page using ``eval``
|
||||
of ``new Function``. If ``reportAnonymousScript`` is set to
|
||||
``True``, anonymous scripts will have
|
||||
``__pyppeteer_evaluation_script__`` as their url.
|
||||
"""
|
||||
...
|
||||
|
||||
async def stopJSCoverage(self) -> List:
|
||||
"""Stop JS coverage measurement and get result.
|
||||
|
||||
Return list of coverage reports for all scripts. Each report includes:
|
||||
|
||||
* ``url`` (str): Script url.
|
||||
* ``text`` (str): Script content.
|
||||
* ``ranges`` (List[Dict]): Script ranges that were executed. Ranges are
|
||||
sorted and non-overlapping.
|
||||
|
||||
* ``start`` (int): A start offset in text, inclusive.
|
||||
* ``end`` (int): An end offset in text, exclusive.
|
||||
|
||||
.. note::
|
||||
JavaScript coverage doesn't include anonymous scripts by default.
|
||||
However, scripts with sourceURLs are reported.
|
||||
"""
|
||||
...
|
||||
|
||||
async def startCSSCoverage(self, options: Dict[str, Any] = ..., **kwargs: Any) -> None:
|
||||
"""Start CSS coverage measurement.
|
||||
|
||||
Available options are:
|
||||
|
||||
* ``resetOnNavigation`` (bool): Whether to reset coverage on every
|
||||
navigation. Defaults to ``True``.
|
||||
"""
|
||||
...
|
||||
|
||||
async def stopCSSCoverage(self) -> List:
|
||||
"""Stop CSS coverage measurement and get result.
|
||||
|
||||
Return list of coverage reports for all non-anonymous scripts. Each
|
||||
report includes:
|
||||
|
||||
* ``url`` (str): StyleSheet url.
|
||||
* ``text`` (str): StyleSheet content.
|
||||
* ``ranges`` (List[Dict]): StyleSheet ranges that were executed. Ranges
|
||||
are sorted and non-overlapping.
|
||||
|
||||
* ``start`` (int): A start offset in text, inclusive.
|
||||
* ``end`` (int): An end offset in text, exclusive.
|
||||
|
||||
.. note::
|
||||
CSS coverage doesn't include dynamically injected style tags without
|
||||
sourceURLs (but currently includes... to be fixed).
|
||||
"""
|
||||
...
|
||||
|
||||
|
||||
|
||||
class JSCoverage:
|
||||
"""JavaScript Coverage class."""
|
||||
def __init__(self, client: CDPSession) -> None:
|
||||
...
|
||||
|
||||
async def start(self, options: Dict[str, Any] = ..., **kwargs: Any) -> None:
|
||||
"""Start coverage measurement."""
|
||||
...
|
||||
|
||||
async def stop(self) -> List:
|
||||
"""Stop coverage measurement and return results."""
|
||||
...
|
||||
|
||||
|
||||
|
||||
class CSSCoverage:
|
||||
"""CSS Coverage class."""
|
||||
def __init__(self, client: CDPSession) -> None:
|
||||
...
|
||||
|
||||
async def start(self, options: Dict[str, Any] = ..., **kwargs: Any) -> None:
|
||||
"""Start coverage measurement."""
|
||||
...
|
||||
|
||||
async def stop(self) -> List:
|
||||
"""Stop coverage measurement and return results."""
|
||||
...
|
||||
|
||||
|
||||
|
||||
def convertToDisjointRanges(nestedRanges: List[Any]) -> List[Any]:
|
||||
"""Convert ranges."""
|
||||
...
|
||||
|
69
typings/pyppeteer/dialog.pyi
Normal file
69
typings/pyppeteer/dialog.pyi
Normal file
|
@ -0,0 +1,69 @@
|
|||
"""
|
||||
This type stub file was generated by pyright.
|
||||
"""
|
||||
|
||||
from pyppeteer.connection import CDPSession
|
||||
|
||||
"""Dialog module."""
|
||||
class Dialog:
|
||||
"""Dialog class.
|
||||
|
||||
Dialog objects are dispatched by page via the ``dialog`` event.
|
||||
|
||||
An example of using ``Dialog`` class:
|
||||
|
||||
.. code::
|
||||
|
||||
browser = await launch()
|
||||
page = await browser.newPage()
|
||||
|
||||
async def close_dialog(dialog):
|
||||
print(dialog.message)
|
||||
await dialog.dismiss()
|
||||
await browser.close()
|
||||
|
||||
page.on(
|
||||
'dialog',
|
||||
lambda dialog: asyncio.ensure_future(close_dialog(dialog))
|
||||
)
|
||||
await page.evaluate('() => alert("1")')
|
||||
"""
|
||||
Type = ...
|
||||
def __init__(self, client: CDPSession, type: str, message: str, defaultValue: str = ...) -> None:
|
||||
...
|
||||
|
||||
@property
|
||||
def type(self) -> str:
|
||||
"""Get dialog type.
|
||||
|
||||
One of ``alert``, ``beforeunload``, ``confirm``, or ``prompt``.
|
||||
"""
|
||||
...
|
||||
|
||||
@property
|
||||
def message(self) -> str:
|
||||
"""Get dialog message."""
|
||||
...
|
||||
|
||||
@property
|
||||
def defaultValue(self) -> str:
|
||||
"""If dialog is prompt, get default prompt value.
|
||||
|
||||
If dialog is not prompt, return empty string (``''``).
|
||||
"""
|
||||
...
|
||||
|
||||
async def accept(self, promptText: str = ...) -> None:
|
||||
"""Accept the dialog.
|
||||
|
||||
* ``promptText`` (str): A text to enter in prompt. If the dialog's type
|
||||
is not prompt, this does not cause any effect.
|
||||
"""
|
||||
...
|
||||
|
||||
async def dismiss(self) -> None:
|
||||
"""Dismiss the dialog."""
|
||||
...
|
||||
|
||||
|
||||
|
232
typings/pyppeteer/element_handle.pyi
Normal file
232
typings/pyppeteer/element_handle.pyi
Normal file
|
@ -0,0 +1,232 @@
|
|||
"""
|
||||
This type stub file was generated by pyright.
|
||||
"""
|
||||
|
||||
from typing import Any, Dict, List, Optional, TYPE_CHECKING
|
||||
from pyppeteer.connection import CDPSession
|
||||
from pyppeteer.execution_context import ExecutionContext, JSHandle
|
||||
from pyppeteer.frame_manager import Frame, FrameManager
|
||||
|
||||
"""Element handle module."""
|
||||
if TYPE_CHECKING:
|
||||
...
|
||||
logger = ...
|
||||
class ElementHandle(JSHandle):
|
||||
"""ElementHandle class.
|
||||
|
||||
This class represents an in-page DOM element. ElementHandle can be created
|
||||
by the :meth:`pyppeteer.page.Page.querySelector` method.
|
||||
|
||||
ElementHandle prevents DOM element from garbage collection unless the
|
||||
handle is disposed. ElementHandles are automatically disposed when their
|
||||
origin frame gets navigated.
|
||||
|
||||
ElementHandle isinstance can be used as arguments in
|
||||
:meth:`pyppeteer.page.Page.querySelectorEval` and
|
||||
:meth:`pyppeteer.page.Page.evaluate` methods.
|
||||
"""
|
||||
def __init__(self, context: ExecutionContext, client: CDPSession, remoteObject: dict, page: Any, frameManager: FrameManager) -> None:
|
||||
...
|
||||
|
||||
def asElement(self) -> ElementHandle:
|
||||
"""Return this ElementHandle."""
|
||||
...
|
||||
|
||||
async def contentFrame(self) -> Optional[Frame]:
|
||||
"""Return the content frame for the element handle.
|
||||
|
||||
Return ``None`` if this handle is not referencing iframe.
|
||||
"""
|
||||
...
|
||||
|
||||
async def hover(self) -> None:
|
||||
"""Move mouse over to center of this element.
|
||||
|
||||
If needed, this method scrolls element into view. If this element is
|
||||
detached from DOM tree, the method raises an ``ElementHandleError``.
|
||||
"""
|
||||
...
|
||||
|
||||
async def click(self, options: Dict[str, Any] = ..., **kwargs: Any) -> None:
|
||||
"""Click the center of this element.
|
||||
|
||||
If needed, this method scrolls element into view. If the element is
|
||||
detached from DOM, the method raises ``ElementHandleError``.
|
||||
|
||||
``options`` can contain the following fields:
|
||||
|
||||
* ``button`` (str): ``left``, ``right``, of ``middle``, defaults to
|
||||
``left``.
|
||||
* ``clickCount`` (int): Defaults to 1.
|
||||
* ``delay`` (int|float): Time to wait between ``mousedown`` and
|
||||
``mouseup`` in milliseconds. Defaults to 0.
|
||||
"""
|
||||
...
|
||||
|
||||
async def uploadFile(self, *filePaths: str) -> dict:
|
||||
"""Upload files."""
|
||||
...
|
||||
|
||||
async def tap(self) -> None:
|
||||
"""Tap the center of this element.
|
||||
|
||||
If needed, this method scrolls element into view. If the element is
|
||||
detached from DOM, the method raises ``ElementHandleError``.
|
||||
"""
|
||||
...
|
||||
|
||||
async def focus(self) -> None:
|
||||
"""Focus on this element."""
|
||||
...
|
||||
|
||||
async def type(self, text: str, options: Dict[str, Any] = ..., **kwargs: Any) -> None:
|
||||
"""Focus the element and then type text.
|
||||
|
||||
Details see :meth:`pyppeteer.input.Keyboard.type` method.
|
||||
"""
|
||||
...
|
||||
|
||||
async def press(self, key: str, options: Dict[str, Any] = ..., **kwargs: Any) -> None:
|
||||
"""Press ``key`` onto the element.
|
||||
|
||||
This method focuses the element, and then uses
|
||||
:meth:`pyppeteer.input.keyboard.down` and
|
||||
:meth:`pyppeteer.input.keyboard.up`.
|
||||
|
||||
:arg str key: Name of key to press, such as ``ArrowLeft``.
|
||||
|
||||
This method accepts the following options:
|
||||
|
||||
* ``text`` (str): If specified, generates an input event with this
|
||||
text.
|
||||
* ``delay`` (int|float): Time to wait between ``keydown`` and
|
||||
``keyup``. Defaults to 0.
|
||||
"""
|
||||
...
|
||||
|
||||
async def boundingBox(self) -> Optional[Dict[str, float]]:
|
||||
"""Return bounding box of this element.
|
||||
|
||||
If the element is not visible, return ``None``.
|
||||
|
||||
This method returns dictionary of bounding box, which contains:
|
||||
|
||||
* ``x`` (int): The X coordinate of the element in pixels.
|
||||
* ``y`` (int): The Y coordinate of the element in pixels.
|
||||
* ``width`` (int): The width of the element in pixels.
|
||||
* ``height`` (int): The height of the element in pixels.
|
||||
"""
|
||||
...
|
||||
|
||||
async def boxModel(self) -> Optional[Dict]:
|
||||
"""Return boxes of element.
|
||||
|
||||
Return ``None`` if element is not visible. Boxes are represented as an
|
||||
list of points; each Point is a dictionary ``{x, y}``. Box points are
|
||||
sorted clock-wise.
|
||||
|
||||
Returned value is a dictionary with the following fields:
|
||||
|
||||
* ``content`` (List[Dict]): Content box.
|
||||
* ``padding`` (List[Dict]): Padding box.
|
||||
* ``border`` (List[Dict]): Border box.
|
||||
* ``margin`` (List[Dict]): Margin box.
|
||||
* ``width`` (int): Element's width.
|
||||
* ``height`` (int): Element's height.
|
||||
"""
|
||||
...
|
||||
|
||||
async def screenshot(self, options: Dict[str, Any] = ..., **kwargs: Any) -> bytes:
|
||||
"""Take a screenshot of this element.
|
||||
|
||||
If the element is detached from DOM, this method raises an
|
||||
``ElementHandleError``.
|
||||
|
||||
Available options are same as :meth:`pyppeteer.page.Page.screenshot`.
|
||||
"""
|
||||
...
|
||||
|
||||
async def querySelector(self, selector: str) -> Optional[ElementHandle]:
|
||||
"""Return first element which matches ``selector`` under this element.
|
||||
|
||||
If no element matches the ``selector``, returns ``None``.
|
||||
"""
|
||||
...
|
||||
|
||||
async def querySelectorAll(self, selector: str) -> List[ElementHandle]:
|
||||
"""Return all elements which match ``selector`` under this element.
|
||||
|
||||
If no element matches the ``selector``, returns empty list (``[]``).
|
||||
"""
|
||||
...
|
||||
|
||||
async def querySelectorEval(self, selector: str, pageFunction: str, *args: Any) -> Any:
|
||||
"""Run ``Page.querySelectorEval`` within the element.
|
||||
|
||||
This method runs ``document.querySelector`` within the element and
|
||||
passes it as the first argument to ``pageFunction``. If there is no
|
||||
element matching ``selector``, the method raises
|
||||
``ElementHandleError``.
|
||||
|
||||
If ``pageFunction`` returns a promise, then wait for the promise to
|
||||
resolve and return its value.
|
||||
|
||||
``ElementHandle.Jeval`` is a shortcut of this method.
|
||||
|
||||
Example:
|
||||
|
||||
.. code:: python
|
||||
|
||||
tweetHandle = await page.querySelector('.tweet')
|
||||
assert (await tweetHandle.querySelectorEval('.like', 'node => node.innerText')) == 100
|
||||
assert (await tweetHandle.Jeval('.retweets', 'node => node.innerText')) == 10
|
||||
"""
|
||||
...
|
||||
|
||||
async def querySelectorAllEval(self, selector: str, pageFunction: str, *args: Any) -> Any:
|
||||
"""Run ``Page.querySelectorAllEval`` within the element.
|
||||
|
||||
This method runs ``Array.from(document.querySelectorAll)`` within the
|
||||
element and passes it as the first argument to ``pageFunction``. If
|
||||
there is no element matching ``selector``, the method raises
|
||||
``ElementHandleError``.
|
||||
|
||||
If ``pageFunction`` returns a promise, then wait for the promise to
|
||||
resolve and return its value.
|
||||
|
||||
Example:
|
||||
|
||||
.. code:: html
|
||||
|
||||
<div class="feed">
|
||||
<div class="tweet">Hello!</div>
|
||||
<div class="tweet">Hi!</div>
|
||||
</div>
|
||||
|
||||
.. code:: python
|
||||
|
||||
feedHandle = await page.J('.feed')
|
||||
assert (await feedHandle.JJeval('.tweet', '(nodes => nodes.map(n => n.innerText))')) == ['Hello!', 'Hi!']
|
||||
"""
|
||||
...
|
||||
|
||||
J = ...
|
||||
JJ = ...
|
||||
Jeval = ...
|
||||
JJeval = ...
|
||||
async def xpath(self, expression: str) -> List[ElementHandle]:
|
||||
"""Evaluate the XPath expression relative to this elementHandle.
|
||||
|
||||
If there are no such elements, return an empty list.
|
||||
|
||||
:arg str expression: XPath string to be evaluated.
|
||||
"""
|
||||
...
|
||||
|
||||
Jx = ...
|
||||
async def isIntersectingViewport(self) -> bool:
|
||||
"""Return ``True`` if the element is visible in the viewport."""
|
||||
...
|
||||
|
||||
|
||||
|
19
typings/pyppeteer/emulation_manager.pyi
Normal file
19
typings/pyppeteer/emulation_manager.pyi
Normal file
|
@ -0,0 +1,19 @@
|
|||
"""
|
||||
This type stub file was generated by pyright.
|
||||
"""
|
||||
|
||||
from pyppeteer.connection import CDPSession
|
||||
|
||||
"""Emulation Manager module."""
|
||||
class EmulationManager:
|
||||
"""EmulationManager class."""
|
||||
def __init__(self, client: CDPSession) -> None:
|
||||
"""Make new emulation manager."""
|
||||
...
|
||||
|
||||
async def emulateViewport(self, viewport: dict) -> bool:
|
||||
"""Evaluate viewport."""
|
||||
...
|
||||
|
||||
|
||||
|
37
typings/pyppeteer/errors.pyi
Normal file
37
typings/pyppeteer/errors.pyi
Normal file
|
@ -0,0 +1,37 @@
|
|||
"""
|
||||
This type stub file was generated by pyright.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
|
||||
"""Exceptions for pyppeteer package."""
|
||||
class PyppeteerError(Exception):
|
||||
"""Base exception for pyppeteer."""
|
||||
...
|
||||
|
||||
|
||||
class BrowserError(PyppeteerError):
|
||||
"""Exception raised from browser."""
|
||||
...
|
||||
|
||||
|
||||
class ElementHandleError(PyppeteerError):
|
||||
"""ElementHandle related exception."""
|
||||
...
|
||||
|
||||
|
||||
class NetworkError(PyppeteerError):
|
||||
"""Network/Protocol related exception."""
|
||||
...
|
||||
|
||||
|
||||
class PageError(PyppeteerError):
|
||||
"""Page/Frame related exception."""
|
||||
...
|
||||
|
||||
|
||||
class TimeoutError(asyncio.TimeoutError):
|
||||
"""Timeout Error class."""
|
||||
...
|
||||
|
||||
|
88
typings/pyppeteer/execution_context.pyi
Normal file
88
typings/pyppeteer/execution_context.pyi
Normal file
|
@ -0,0 +1,88 @@
|
|||
"""
|
||||
This type stub file was generated by pyright.
|
||||
"""
|
||||
|
||||
from typing import Any, Dict, Optional, TYPE_CHECKING
|
||||
from pyppeteer.connection import CDPSession
|
||||
from pyppeteer.element_handle import ElementHandle
|
||||
from pyppeteer.frame_manager import Frame
|
||||
|
||||
"""Execution Context Module."""
|
||||
if TYPE_CHECKING:
|
||||
...
|
||||
logger = ...
|
||||
EVALUATION_SCRIPT_URL = ...
|
||||
SOURCE_URL_REGEX = ...
|
||||
class ExecutionContext:
|
||||
"""Execution Context class."""
|
||||
def __init__(self, client: CDPSession, contextPayload: Dict, objectHandleFactory: Any, frame: Frame = ...) -> None:
|
||||
...
|
||||
|
||||
@property
|
||||
def frame(self) -> Optional[Frame]:
|
||||
"""Return frame associated with this execution context."""
|
||||
...
|
||||
|
||||
async def evaluate(self, pageFunction: str, *args: Any, force_expr: bool = ...) -> Any:
|
||||
"""Execute ``pageFunction`` on this context.
|
||||
|
||||
Details see :meth:`pyppeteer.page.Page.evaluate`.
|
||||
"""
|
||||
...
|
||||
|
||||
async def evaluateHandle(self, pageFunction: str, *args: Any, force_expr: bool = ...) -> JSHandle:
|
||||
"""Execute ``pageFunction`` on this context.
|
||||
|
||||
Details see :meth:`pyppeteer.page.Page.evaluateHandle`.
|
||||
"""
|
||||
...
|
||||
|
||||
async def queryObjects(self, prototypeHandle: JSHandle) -> JSHandle:
|
||||
"""Send query.
|
||||
|
||||
Details see :meth:`pyppeteer.page.Page.queryObjects`.
|
||||
"""
|
||||
...
|
||||
|
||||
|
||||
|
||||
class JSHandle:
|
||||
"""JSHandle class.
|
||||
|
||||
JSHandle represents an in-page JavaScript object. JSHandle can be created
|
||||
with the :meth:`~pyppeteer.page.Page.evaluateHandle` method.
|
||||
"""
|
||||
def __init__(self, context: ExecutionContext, client: CDPSession, remoteObject: Dict) -> None:
|
||||
...
|
||||
|
||||
@property
|
||||
def executionContext(self) -> ExecutionContext:
|
||||
"""Get execution context of this handle."""
|
||||
...
|
||||
|
||||
async def getProperty(self, propertyName: str) -> JSHandle:
|
||||
"""Get property value of ``propertyName``."""
|
||||
...
|
||||
|
||||
async def getProperties(self) -> Dict[str, JSHandle]:
|
||||
"""Get all properties of this handle."""
|
||||
...
|
||||
|
||||
async def jsonValue(self) -> Dict:
|
||||
"""Get Jsonized value of this object."""
|
||||
...
|
||||
|
||||
def asElement(self) -> Optional[ElementHandle]:
|
||||
"""Return either null or the object handle itself."""
|
||||
...
|
||||
|
||||
async def dispose(self) -> None:
|
||||
"""Stop referencing the handle."""
|
||||
...
|
||||
|
||||
def toString(self) -> str:
|
||||
"""Get string representation."""
|
||||
...
|
||||
|
||||
|
||||
|
270
typings/pyppeteer/frame_manager.pyi
Normal file
270
typings/pyppeteer/frame_manager.pyi
Normal file
|
@ -0,0 +1,270 @@
|
|||
"""
|
||||
This type stub file was generated by pyright.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
from typing import Any, Awaitable, Dict, Generator, List, Optional, Union
|
||||
from pyee import EventEmitter
|
||||
from pyppeteer.connection import CDPSession
|
||||
from pyppeteer.element_handle import |