AI Newsletter Digest improvements: fixed QP soft line break decoding, URL extraction, and content cleaning
This commit is contained in:
247
skills/ghost-browser/.venv/bin/Activate.ps1
Normal file
247
skills/ghost-browser/.venv/bin/Activate.ps1
Normal file
@@ -0,0 +1,247 @@
|
||||
<#
|
||||
.Synopsis
|
||||
Activate a Python virtual environment for the current PowerShell session.
|
||||
|
||||
.Description
|
||||
Pushes the python executable for a virtual environment to the front of the
|
||||
$Env:PATH environment variable and sets the prompt to signify that you are
|
||||
in a Python virtual environment. Makes use of the command line switches as
|
||||
well as the `pyvenv.cfg` file values present in the virtual environment.
|
||||
|
||||
.Parameter VenvDir
|
||||
Path to the directory that contains the virtual environment to activate. The
|
||||
default value for this is the parent of the directory that the Activate.ps1
|
||||
script is located within.
|
||||
|
||||
.Parameter Prompt
|
||||
The prompt prefix to display when this virtual environment is activated. By
|
||||
default, this prompt is the name of the virtual environment folder (VenvDir)
|
||||
surrounded by parentheses and followed by a single space (ie. '(.venv) ').
|
||||
|
||||
.Example
|
||||
Activate.ps1
|
||||
Activates the Python virtual environment that contains the Activate.ps1 script.
|
||||
|
||||
.Example
|
||||
Activate.ps1 -Verbose
|
||||
Activates the Python virtual environment that contains the Activate.ps1 script,
|
||||
and shows extra information about the activation as it executes.
|
||||
|
||||
.Example
|
||||
Activate.ps1 -VenvDir C:\Users\MyUser\Common\.venv
|
||||
Activates the Python virtual environment located in the specified location.
|
||||
|
||||
.Example
|
||||
Activate.ps1 -Prompt "MyPython"
|
||||
Activates the Python virtual environment that contains the Activate.ps1 script,
|
||||
and prefixes the current prompt with the specified string (surrounded in
|
||||
parentheses) while the virtual environment is active.
|
||||
|
||||
.Notes
|
||||
On Windows, it may be required to enable this Activate.ps1 script by setting the
|
||||
execution policy for the user. You can do this by issuing the following PowerShell
|
||||
command:
|
||||
|
||||
PS C:\> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
|
||||
|
||||
For more information on Execution Policies:
|
||||
https://go.microsoft.com/fwlink/?LinkID=135170
|
||||
|
||||
#>
|
||||
Param(
|
||||
[Parameter(Mandatory = $false)]
|
||||
[String]
|
||||
$VenvDir,
|
||||
[Parameter(Mandatory = $false)]
|
||||
[String]
|
||||
$Prompt
|
||||
)
|
||||
|
||||
<# Function declarations --------------------------------------------------- #>
|
||||
|
||||
<#
|
||||
.Synopsis
|
||||
Remove all shell session elements added by the Activate script, including the
|
||||
addition of the virtual environment's Python executable from the beginning of
|
||||
the PATH variable.
|
||||
|
||||
.Parameter NonDestructive
|
||||
If present, do not remove this function from the global namespace for the
|
||||
session.
|
||||
|
||||
#>
|
||||
function global:deactivate ([switch]$NonDestructive) {
|
||||
# Revert to original values
|
||||
|
||||
# The prior prompt:
|
||||
if (Test-Path -Path Function:_OLD_VIRTUAL_PROMPT) {
|
||||
Copy-Item -Path Function:_OLD_VIRTUAL_PROMPT -Destination Function:prompt
|
||||
Remove-Item -Path Function:_OLD_VIRTUAL_PROMPT
|
||||
}
|
||||
|
||||
# The prior PYTHONHOME:
|
||||
if (Test-Path -Path Env:_OLD_VIRTUAL_PYTHONHOME) {
|
||||
Copy-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME -Destination Env:PYTHONHOME
|
||||
Remove-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME
|
||||
}
|
||||
|
||||
# The prior PATH:
|
||||
if (Test-Path -Path Env:_OLD_VIRTUAL_PATH) {
|
||||
Copy-Item -Path Env:_OLD_VIRTUAL_PATH -Destination Env:PATH
|
||||
Remove-Item -Path Env:_OLD_VIRTUAL_PATH
|
||||
}
|
||||
|
||||
# Just remove the VIRTUAL_ENV altogether:
|
||||
if (Test-Path -Path Env:VIRTUAL_ENV) {
|
||||
Remove-Item -Path env:VIRTUAL_ENV
|
||||
}
|
||||
|
||||
# Just remove VIRTUAL_ENV_PROMPT altogether.
|
||||
if (Test-Path -Path Env:VIRTUAL_ENV_PROMPT) {
|
||||
Remove-Item -Path env:VIRTUAL_ENV_PROMPT
|
||||
}
|
||||
|
||||
# Just remove the _PYTHON_VENV_PROMPT_PREFIX altogether:
|
||||
if (Get-Variable -Name "_PYTHON_VENV_PROMPT_PREFIX" -ErrorAction SilentlyContinue) {
|
||||
Remove-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Scope Global -Force
|
||||
}
|
||||
|
||||
# Leave deactivate function in the global namespace if requested:
|
||||
if (-not $NonDestructive) {
|
||||
Remove-Item -Path function:deactivate
|
||||
}
|
||||
}
|
||||
|
||||
<#
|
||||
.Description
|
||||
Get-PyVenvConfig parses the values from the pyvenv.cfg file located in the
|
||||
given folder, and returns them in a map.
|
||||
|
||||
For each line in the pyvenv.cfg file, if that line can be parsed into exactly
|
||||
two strings separated by `=` (with any amount of whitespace surrounding the =)
|
||||
then it is considered a `key = value` line. The left hand string is the key,
|
||||
the right hand is the value.
|
||||
|
||||
If the value starts with a `'` or a `"` then the first and last character is
|
||||
stripped from the value before being captured.
|
||||
|
||||
.Parameter ConfigDir
|
||||
Path to the directory that contains the `pyvenv.cfg` file.
|
||||
#>
|
||||
function Get-PyVenvConfig(
|
||||
[String]
|
||||
$ConfigDir
|
||||
) {
|
||||
Write-Verbose "Given ConfigDir=$ConfigDir, obtain values in pyvenv.cfg"
|
||||
|
||||
# Ensure the file exists, and issue a warning if it doesn't (but still allow the function to continue).
|
||||
$pyvenvConfigPath = Join-Path -Resolve -Path $ConfigDir -ChildPath 'pyvenv.cfg' -ErrorAction Continue
|
||||
|
||||
# An empty map will be returned if no config file is found.
|
||||
$pyvenvConfig = @{ }
|
||||
|
||||
if ($pyvenvConfigPath) {
|
||||
|
||||
Write-Verbose "File exists, parse `key = value` lines"
|
||||
$pyvenvConfigContent = Get-Content -Path $pyvenvConfigPath
|
||||
|
||||
$pyvenvConfigContent | ForEach-Object {
|
||||
$keyval = $PSItem -split "\s*=\s*", 2
|
||||
if ($keyval[0] -and $keyval[1]) {
|
||||
$val = $keyval[1]
|
||||
|
||||
# Remove extraneous quotations around a string value.
|
||||
if ("'""".Contains($val.Substring(0, 1))) {
|
||||
$val = $val.Substring(1, $val.Length - 2)
|
||||
}
|
||||
|
||||
$pyvenvConfig[$keyval[0]] = $val
|
||||
Write-Verbose "Adding Key: '$($keyval[0])'='$val'"
|
||||
}
|
||||
}
|
||||
}
|
||||
return $pyvenvConfig
|
||||
}
|
||||
|
||||
|
||||
<# Begin Activate script --------------------------------------------------- #>
|
||||
|
||||
# Determine the containing directory of this script
|
||||
$VenvExecPath = Split-Path -Parent $MyInvocation.MyCommand.Definition
|
||||
$VenvExecDir = Get-Item -Path $VenvExecPath
|
||||
|
||||
Write-Verbose "Activation script is located in path: '$VenvExecPath'"
|
||||
Write-Verbose "VenvExecDir Fullname: '$($VenvExecDir.FullName)"
|
||||
Write-Verbose "VenvExecDir Name: '$($VenvExecDir.Name)"
|
||||
|
||||
# Set values required in priority: CmdLine, ConfigFile, Default
|
||||
# First, get the location of the virtual environment, it might not be
|
||||
# VenvExecDir if specified on the command line.
|
||||
if ($VenvDir) {
|
||||
Write-Verbose "VenvDir given as parameter, using '$VenvDir' to determine values"
|
||||
}
|
||||
else {
|
||||
Write-Verbose "VenvDir not given as a parameter, using parent directory name as VenvDir."
|
||||
$VenvDir = $VenvExecDir.Parent.FullName.TrimEnd("\\/")
|
||||
Write-Verbose "VenvDir=$VenvDir"
|
||||
}
|
||||
|
||||
# Next, read the `pyvenv.cfg` file to determine any required value such
|
||||
# as `prompt`.
|
||||
$pyvenvCfg = Get-PyVenvConfig -ConfigDir $VenvDir
|
||||
|
||||
# Next, set the prompt from the command line, or the config file, or
|
||||
# just use the name of the virtual environment folder.
|
||||
if ($Prompt) {
|
||||
Write-Verbose "Prompt specified as argument, using '$Prompt'"
|
||||
}
|
||||
else {
|
||||
Write-Verbose "Prompt not specified as argument to script, checking pyvenv.cfg value"
|
||||
if ($pyvenvCfg -and $pyvenvCfg['prompt']) {
|
||||
Write-Verbose " Setting based on value in pyvenv.cfg='$($pyvenvCfg['prompt'])'"
|
||||
$Prompt = $pyvenvCfg['prompt'];
|
||||
}
|
||||
else {
|
||||
Write-Verbose " Setting prompt based on parent's directory's name. (Is the directory name passed to venv module when creating the virtual environment)"
|
||||
Write-Verbose " Got leaf-name of $VenvDir='$(Split-Path -Path $venvDir -Leaf)'"
|
||||
$Prompt = Split-Path -Path $venvDir -Leaf
|
||||
}
|
||||
}
|
||||
|
||||
Write-Verbose "Prompt = '$Prompt'"
|
||||
Write-Verbose "VenvDir='$VenvDir'"
|
||||
|
||||
# Deactivate any currently active virtual environment, but leave the
|
||||
# deactivate function in place.
|
||||
deactivate -nondestructive
|
||||
|
||||
# Now set the environment variable VIRTUAL_ENV, used by many tools to determine
|
||||
# that there is an activated venv.
|
||||
$env:VIRTUAL_ENV = $VenvDir
|
||||
|
||||
if (-not $Env:VIRTUAL_ENV_DISABLE_PROMPT) {
|
||||
|
||||
Write-Verbose "Setting prompt to '$Prompt'"
|
||||
|
||||
# Set the prompt to include the env name
|
||||
# Make sure _OLD_VIRTUAL_PROMPT is global
|
||||
function global:_OLD_VIRTUAL_PROMPT { "" }
|
||||
Copy-Item -Path function:prompt -Destination function:_OLD_VIRTUAL_PROMPT
|
||||
New-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Description "Python virtual environment prompt prefix" -Scope Global -Option ReadOnly -Visibility Public -Value $Prompt
|
||||
|
||||
function global:prompt {
|
||||
Write-Host -NoNewline -ForegroundColor Green "($_PYTHON_VENV_PROMPT_PREFIX) "
|
||||
_OLD_VIRTUAL_PROMPT
|
||||
}
|
||||
$env:VIRTUAL_ENV_PROMPT = $Prompt
|
||||
}
|
||||
|
||||
# Clear PYTHONHOME
|
||||
if (Test-Path -Path Env:PYTHONHOME) {
|
||||
Copy-Item -Path Env:PYTHONHOME -Destination Env:_OLD_VIRTUAL_PYTHONHOME
|
||||
Remove-Item -Path Env:PYTHONHOME
|
||||
}
|
||||
|
||||
# Add the venv to the PATH
|
||||
Copy-Item -Path Env:PATH -Destination Env:_OLD_VIRTUAL_PATH
|
||||
$Env:PATH = "$VenvExecDir$([System.IO.Path]::PathSeparator)$Env:PATH"
|
||||
69
skills/ghost-browser/.venv/bin/activate
Normal file
69
skills/ghost-browser/.venv/bin/activate
Normal file
@@ -0,0 +1,69 @@
|
||||
# This file must be used with "source bin/activate" *from bash*
|
||||
# you cannot run it directly
|
||||
|
||||
deactivate () {
|
||||
# reset old environment variables
|
||||
if [ -n "${_OLD_VIRTUAL_PATH:-}" ] ; then
|
||||
PATH="${_OLD_VIRTUAL_PATH:-}"
|
||||
export PATH
|
||||
unset _OLD_VIRTUAL_PATH
|
||||
fi
|
||||
if [ -n "${_OLD_VIRTUAL_PYTHONHOME:-}" ] ; then
|
||||
PYTHONHOME="${_OLD_VIRTUAL_PYTHONHOME:-}"
|
||||
export PYTHONHOME
|
||||
unset _OLD_VIRTUAL_PYTHONHOME
|
||||
fi
|
||||
|
||||
# This should detect bash and zsh, which have a hash command that must
|
||||
# be called to get it to forget past commands. Without forgetting
|
||||
# past commands the $PATH changes we made may not be respected
|
||||
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
|
||||
hash -r 2> /dev/null
|
||||
fi
|
||||
|
||||
if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then
|
||||
PS1="${_OLD_VIRTUAL_PS1:-}"
|
||||
export PS1
|
||||
unset _OLD_VIRTUAL_PS1
|
||||
fi
|
||||
|
||||
unset VIRTUAL_ENV
|
||||
unset VIRTUAL_ENV_PROMPT
|
||||
if [ ! "${1:-}" = "nondestructive" ] ; then
|
||||
# Self destruct!
|
||||
unset -f deactivate
|
||||
fi
|
||||
}
|
||||
|
||||
# unset irrelevant variables
|
||||
deactivate nondestructive
|
||||
|
||||
VIRTUAL_ENV=/home/openclaw/.openclaw/workspace/skills/ghost-browser/.venv
|
||||
export VIRTUAL_ENV
|
||||
|
||||
_OLD_VIRTUAL_PATH="$PATH"
|
||||
PATH="$VIRTUAL_ENV/"bin":$PATH"
|
||||
export PATH
|
||||
|
||||
# unset PYTHONHOME if set
|
||||
# this will fail if PYTHONHOME is set to the empty string (which is bad anyway)
|
||||
# could use `if (set -u; : $PYTHONHOME) ;` in bash
|
||||
if [ -n "${PYTHONHOME:-}" ] ; then
|
||||
_OLD_VIRTUAL_PYTHONHOME="${PYTHONHOME:-}"
|
||||
unset PYTHONHOME
|
||||
fi
|
||||
|
||||
if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then
|
||||
_OLD_VIRTUAL_PS1="${PS1:-}"
|
||||
PS1='(.venv) '"${PS1:-}"
|
||||
export PS1
|
||||
VIRTUAL_ENV_PROMPT='(.venv) '
|
||||
export VIRTUAL_ENV_PROMPT
|
||||
fi
|
||||
|
||||
# This should detect bash and zsh, which have a hash command that must
|
||||
# be called to get it to forget past commands. Without forgetting
|
||||
# past commands the $PATH changes we made may not be respected
|
||||
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
|
||||
hash -r 2> /dev/null
|
||||
fi
|
||||
26
skills/ghost-browser/.venv/bin/activate.csh
Normal file
26
skills/ghost-browser/.venv/bin/activate.csh
Normal file
@@ -0,0 +1,26 @@
|
||||
# This file must be used with "source bin/activate.csh" *from csh*.
|
||||
# You cannot run it directly.
|
||||
# Created by Davide Di Blasi <davidedb@gmail.com>.
|
||||
# Ported to Python 3.3 venv by Andrew Svetlov <andrew.svetlov@gmail.com>
|
||||
|
||||
alias deactivate 'test $?_OLD_VIRTUAL_PATH != 0 && setenv PATH "$_OLD_VIRTUAL_PATH" && unset _OLD_VIRTUAL_PATH; rehash; test $?_OLD_VIRTUAL_PROMPT != 0 && set prompt="$_OLD_VIRTUAL_PROMPT" && unset _OLD_VIRTUAL_PROMPT; unsetenv VIRTUAL_ENV; unsetenv VIRTUAL_ENV_PROMPT; test "\!:*" != "nondestructive" && unalias deactivate'
|
||||
|
||||
# Unset irrelevant variables.
|
||||
deactivate nondestructive
|
||||
|
||||
setenv VIRTUAL_ENV /home/openclaw/.openclaw/workspace/skills/ghost-browser/.venv
|
||||
|
||||
set _OLD_VIRTUAL_PATH="$PATH"
|
||||
setenv PATH "$VIRTUAL_ENV/"bin":$PATH"
|
||||
|
||||
|
||||
set _OLD_VIRTUAL_PROMPT="$prompt"
|
||||
|
||||
if (! "$?VIRTUAL_ENV_DISABLE_PROMPT") then
|
||||
set prompt = '(.venv) '"$prompt"
|
||||
setenv VIRTUAL_ENV_PROMPT '(.venv) '
|
||||
endif
|
||||
|
||||
alias pydoc python -m pydoc
|
||||
|
||||
rehash
|
||||
69
skills/ghost-browser/.venv/bin/activate.fish
Normal file
69
skills/ghost-browser/.venv/bin/activate.fish
Normal file
@@ -0,0 +1,69 @@
|
||||
# This file must be used with "source <venv>/bin/activate.fish" *from fish*
|
||||
# (https://fishshell.com/); you cannot run it directly.
|
||||
|
||||
function deactivate -d "Exit virtual environment and return to normal shell environment"
|
||||
# reset old environment variables
|
||||
if test -n "$_OLD_VIRTUAL_PATH"
|
||||
set -gx PATH $_OLD_VIRTUAL_PATH
|
||||
set -e _OLD_VIRTUAL_PATH
|
||||
end
|
||||
if test -n "$_OLD_VIRTUAL_PYTHONHOME"
|
||||
set -gx PYTHONHOME $_OLD_VIRTUAL_PYTHONHOME
|
||||
set -e _OLD_VIRTUAL_PYTHONHOME
|
||||
end
|
||||
|
||||
if test -n "$_OLD_FISH_PROMPT_OVERRIDE"
|
||||
set -e _OLD_FISH_PROMPT_OVERRIDE
|
||||
# prevents error when using nested fish instances (Issue #93858)
|
||||
if functions -q _old_fish_prompt
|
||||
functions -e fish_prompt
|
||||
functions -c _old_fish_prompt fish_prompt
|
||||
functions -e _old_fish_prompt
|
||||
end
|
||||
end
|
||||
|
||||
set -e VIRTUAL_ENV
|
||||
set -e VIRTUAL_ENV_PROMPT
|
||||
if test "$argv[1]" != "nondestructive"
|
||||
# Self-destruct!
|
||||
functions -e deactivate
|
||||
end
|
||||
end
|
||||
|
||||
# Unset irrelevant variables.
|
||||
deactivate nondestructive
|
||||
|
||||
set -gx VIRTUAL_ENV /home/openclaw/.openclaw/workspace/skills/ghost-browser/.venv
|
||||
|
||||
set -gx _OLD_VIRTUAL_PATH $PATH
|
||||
set -gx PATH "$VIRTUAL_ENV/"bin $PATH
|
||||
|
||||
# Unset PYTHONHOME if set.
|
||||
if set -q PYTHONHOME
|
||||
set -gx _OLD_VIRTUAL_PYTHONHOME $PYTHONHOME
|
||||
set -e PYTHONHOME
|
||||
end
|
||||
|
||||
if test -z "$VIRTUAL_ENV_DISABLE_PROMPT"
|
||||
# fish uses a function instead of an env var to generate the prompt.
|
||||
|
||||
# Save the current fish_prompt function as the function _old_fish_prompt.
|
||||
functions -c fish_prompt _old_fish_prompt
|
||||
|
||||
# With the original prompt function renamed, we can override with our own.
|
||||
function fish_prompt
|
||||
# Save the return status of the last command.
|
||||
set -l old_status $status
|
||||
|
||||
# Output the venv prompt; color taken from the blue of the Python logo.
|
||||
printf "%s%s%s" (set_color 4B8BBE) '(.venv) ' (set_color normal)
|
||||
|
||||
# Restore the return status of the previous command.
|
||||
echo "exit $old_status" | .
|
||||
# Output the original/"old" prompt.
|
||||
_old_fish_prompt
|
||||
end
|
||||
|
||||
set -gx _OLD_FISH_PROMPT_OVERRIDE "$VIRTUAL_ENV"
|
||||
set -gx VIRTUAL_ENV_PROMPT '(.venv) '
|
||||
end
|
||||
8
skills/ghost-browser/.venv/bin/mss
Executable file
8
skills/ghost-browser/.venv/bin/mss
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/home/openclaw/.openclaw/workspace/skills/ghost-browser/.venv/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
import re
|
||||
import sys
|
||||
from mss.__main__ import main
|
||||
if __name__ == '__main__':
|
||||
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
||||
sys.exit(main())
|
||||
8
skills/ghost-browser/.venv/bin/pip
Executable file
8
skills/ghost-browser/.venv/bin/pip
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/home/openclaw/.openclaw/workspace/skills/ghost-browser/.venv/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
import re
|
||||
import sys
|
||||
from pip._internal.cli.main import main
|
||||
if __name__ == '__main__':
|
||||
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
||||
sys.exit(main())
|
||||
8
skills/ghost-browser/.venv/bin/pip3
Executable file
8
skills/ghost-browser/.venv/bin/pip3
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/home/openclaw/.openclaw/workspace/skills/ghost-browser/.venv/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
import re
|
||||
import sys
|
||||
from pip._internal.cli.main import main
|
||||
if __name__ == '__main__':
|
||||
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
||||
sys.exit(main())
|
||||
8
skills/ghost-browser/.venv/bin/pip3.11
Executable file
8
skills/ghost-browser/.venv/bin/pip3.11
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/home/openclaw/.openclaw/workspace/skills/ghost-browser/.venv/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
import re
|
||||
import sys
|
||||
from pip._internal.cli.main import main
|
||||
if __name__ == '__main__':
|
||||
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
||||
sys.exit(main())
|
||||
1
skills/ghost-browser/.venv/bin/python
Symbolic link
1
skills/ghost-browser/.venv/bin/python
Symbolic link
@@ -0,0 +1 @@
|
||||
python3
|
||||
1
skills/ghost-browser/.venv/bin/python3
Symbolic link
1
skills/ghost-browser/.venv/bin/python3
Symbolic link
@@ -0,0 +1 @@
|
||||
/usr/bin/python3
|
||||
1
skills/ghost-browser/.venv/bin/python3.11
Symbolic link
1
skills/ghost-browser/.venv/bin/python3.11
Symbolic link
@@ -0,0 +1 @@
|
||||
python3
|
||||
8
skills/ghost-browser/.venv/bin/websockets
Executable file
8
skills/ghost-browser/.venv/bin/websockets
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/home/openclaw/.openclaw/workspace/skills/ghost-browser/.venv/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
import re
|
||||
import sys
|
||||
from websockets.cli import main
|
||||
if __name__ == '__main__':
|
||||
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
||||
sys.exit(main())
|
||||
@@ -0,0 +1,222 @@
|
||||
# don't import any costly modules
|
||||
import sys
|
||||
import os
|
||||
|
||||
|
||||
is_pypy = '__pypy__' in sys.builtin_module_names
|
||||
|
||||
|
||||
def warn_distutils_present():
|
||||
if 'distutils' not in sys.modules:
|
||||
return
|
||||
if is_pypy and sys.version_info < (3, 7):
|
||||
# PyPy for 3.6 unconditionally imports distutils, so bypass the warning
|
||||
# https://foss.heptapod.net/pypy/pypy/-/blob/be829135bc0d758997b3566062999ee8b23872b4/lib-python/3/site.py#L250
|
||||
return
|
||||
import warnings
|
||||
|
||||
warnings.warn(
|
||||
"Distutils was imported before Setuptools, but importing Setuptools "
|
||||
"also replaces the `distutils` module in `sys.modules`. This may lead "
|
||||
"to undesirable behaviors or errors. To avoid these issues, avoid "
|
||||
"using distutils directly, ensure that setuptools is installed in the "
|
||||
"traditional way (e.g. not an editable install), and/or make sure "
|
||||
"that setuptools is always imported before distutils."
|
||||
)
|
||||
|
||||
|
||||
def clear_distutils():
|
||||
if 'distutils' not in sys.modules:
|
||||
return
|
||||
import warnings
|
||||
|
||||
warnings.warn("Setuptools is replacing distutils.")
|
||||
mods = [
|
||||
name
|
||||
for name in sys.modules
|
||||
if name == "distutils" or name.startswith("distutils.")
|
||||
]
|
||||
for name in mods:
|
||||
del sys.modules[name]
|
||||
|
||||
|
||||
def enabled():
|
||||
"""
|
||||
Allow selection of distutils by environment variable.
|
||||
"""
|
||||
which = os.environ.get('SETUPTOOLS_USE_DISTUTILS', 'local')
|
||||
return which == 'local'
|
||||
|
||||
|
||||
def ensure_local_distutils():
|
||||
import importlib
|
||||
|
||||
clear_distutils()
|
||||
|
||||
# With the DistutilsMetaFinder in place,
|
||||
# perform an import to cause distutils to be
|
||||
# loaded from setuptools._distutils. Ref #2906.
|
||||
with shim():
|
||||
importlib.import_module('distutils')
|
||||
|
||||
# check that submodules load as expected
|
||||
core = importlib.import_module('distutils.core')
|
||||
assert '_distutils' in core.__file__, core.__file__
|
||||
assert 'setuptools._distutils.log' not in sys.modules
|
||||
|
||||
|
||||
def do_override():
|
||||
"""
|
||||
Ensure that the local copy of distutils is preferred over stdlib.
|
||||
|
||||
See https://github.com/pypa/setuptools/issues/417#issuecomment-392298401
|
||||
for more motivation.
|
||||
"""
|
||||
if enabled():
|
||||
warn_distutils_present()
|
||||
ensure_local_distutils()
|
||||
|
||||
|
||||
class _TrivialRe:
|
||||
def __init__(self, *patterns):
|
||||
self._patterns = patterns
|
||||
|
||||
def match(self, string):
|
||||
return all(pat in string for pat in self._patterns)
|
||||
|
||||
|
||||
class DistutilsMetaFinder:
|
||||
def find_spec(self, fullname, path, target=None):
|
||||
# optimization: only consider top level modules and those
|
||||
# found in the CPython test suite.
|
||||
if path is not None and not fullname.startswith('test.'):
|
||||
return
|
||||
|
||||
method_name = 'spec_for_{fullname}'.format(**locals())
|
||||
method = getattr(self, method_name, lambda: None)
|
||||
return method()
|
||||
|
||||
def spec_for_distutils(self):
|
||||
if self.is_cpython():
|
||||
return
|
||||
|
||||
import importlib
|
||||
import importlib.abc
|
||||
import importlib.util
|
||||
|
||||
try:
|
||||
mod = importlib.import_module('setuptools._distutils')
|
||||
except Exception:
|
||||
# There are a couple of cases where setuptools._distutils
|
||||
# may not be present:
|
||||
# - An older Setuptools without a local distutils is
|
||||
# taking precedence. Ref #2957.
|
||||
# - Path manipulation during sitecustomize removes
|
||||
# setuptools from the path but only after the hook
|
||||
# has been loaded. Ref #2980.
|
||||
# In either case, fall back to stdlib behavior.
|
||||
return
|
||||
|
||||
class DistutilsLoader(importlib.abc.Loader):
|
||||
def create_module(self, spec):
|
||||
mod.__name__ = 'distutils'
|
||||
return mod
|
||||
|
||||
def exec_module(self, module):
|
||||
pass
|
||||
|
||||
return importlib.util.spec_from_loader(
|
||||
'distutils', DistutilsLoader(), origin=mod.__file__
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def is_cpython():
|
||||
"""
|
||||
Suppress supplying distutils for CPython (build and tests).
|
||||
Ref #2965 and #3007.
|
||||
"""
|
||||
return os.path.isfile('pybuilddir.txt')
|
||||
|
||||
def spec_for_pip(self):
|
||||
"""
|
||||
Ensure stdlib distutils when running under pip.
|
||||
See pypa/pip#8761 for rationale.
|
||||
"""
|
||||
if self.pip_imported_during_build():
|
||||
return
|
||||
clear_distutils()
|
||||
self.spec_for_distutils = lambda: None
|
||||
|
||||
@classmethod
|
||||
def pip_imported_during_build(cls):
|
||||
"""
|
||||
Detect if pip is being imported in a build script. Ref #2355.
|
||||
"""
|
||||
import traceback
|
||||
|
||||
return any(
|
||||
cls.frame_file_is_setup(frame) for frame, line in traceback.walk_stack(None)
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def frame_file_is_setup(frame):
|
||||
"""
|
||||
Return True if the indicated frame suggests a setup.py file.
|
||||
"""
|
||||
# some frames may not have __file__ (#2940)
|
||||
return frame.f_globals.get('__file__', '').endswith('setup.py')
|
||||
|
||||
def spec_for_sensitive_tests(self):
|
||||
"""
|
||||
Ensure stdlib distutils when running select tests under CPython.
|
||||
|
||||
python/cpython#91169
|
||||
"""
|
||||
clear_distutils()
|
||||
self.spec_for_distutils = lambda: None
|
||||
|
||||
sensitive_tests = (
|
||||
[
|
||||
'test.test_distutils',
|
||||
'test.test_peg_generator',
|
||||
'test.test_importlib',
|
||||
]
|
||||
if sys.version_info < (3, 10)
|
||||
else [
|
||||
'test.test_distutils',
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
for name in DistutilsMetaFinder.sensitive_tests:
|
||||
setattr(
|
||||
DistutilsMetaFinder,
|
||||
f'spec_for_{name}',
|
||||
DistutilsMetaFinder.spec_for_sensitive_tests,
|
||||
)
|
||||
|
||||
|
||||
DISTUTILS_FINDER = DistutilsMetaFinder()
|
||||
|
||||
|
||||
def add_shim():
|
||||
DISTUTILS_FINDER in sys.meta_path or insert_shim()
|
||||
|
||||
|
||||
class shim:
|
||||
def __enter__(self):
|
||||
insert_shim()
|
||||
|
||||
def __exit__(self, exc, value, tb):
|
||||
remove_shim()
|
||||
|
||||
|
||||
def insert_shim():
|
||||
sys.meta_path.insert(0, DISTUTILS_FINDER)
|
||||
|
||||
|
||||
def remove_shim():
|
||||
try:
|
||||
sys.meta_path.remove(DISTUTILS_FINDER)
|
||||
except ValueError:
|
||||
pass
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
|
||||
__import__('_distutils_hack').do_override()
|
||||
@@ -0,0 +1 @@
|
||||
pip
|
||||
@@ -0,0 +1,199 @@
|
||||
Metadata-Version: 2.4
|
||||
Name: Deprecated
|
||||
Version: 1.3.1
|
||||
Summary: Python @deprecated decorator to deprecate old python classes, functions or methods.
|
||||
Home-page: https://github.com/laurent-laporte-pro/deprecated
|
||||
Author: Laurent LAPORTE
|
||||
Author-email: laurent.laporte.pro@gmail.com
|
||||
License: MIT
|
||||
Project-URL: Documentation, https://deprecated.readthedocs.io/en/latest/
|
||||
Project-URL: Source, https://github.com/laurent-laporte-pro/deprecated
|
||||
Project-URL: Bug Tracker, https://github.com/laurent-laporte-pro/deprecated/issues
|
||||
Keywords: deprecate,deprecated,deprecation,warning,warn,decorator
|
||||
Platform: any
|
||||
Classifier: Development Status :: 5 - Production/Stable
|
||||
Classifier: Environment :: Web Environment
|
||||
Classifier: Intended Audience :: Developers
|
||||
Classifier: License :: OSI Approved :: MIT License
|
||||
Classifier: Operating System :: OS Independent
|
||||
Classifier: Programming Language :: Python
|
||||
Classifier: Programming Language :: Python :: 2
|
||||
Classifier: Programming Language :: Python :: 2.7
|
||||
Classifier: Programming Language :: Python :: 3
|
||||
Classifier: Programming Language :: Python :: 3.4
|
||||
Classifier: Programming Language :: Python :: 3.5
|
||||
Classifier: Programming Language :: Python :: 3.6
|
||||
Classifier: Programming Language :: Python :: 3.7
|
||||
Classifier: Programming Language :: Python :: 3.8
|
||||
Classifier: Programming Language :: Python :: 3.9
|
||||
Classifier: Programming Language :: Python :: 3.10
|
||||
Classifier: Programming Language :: Python :: 3.11
|
||||
Classifier: Programming Language :: Python :: 3.12
|
||||
Classifier: Programming Language :: Python :: 3.13
|
||||
Classifier: Programming Language :: Python :: 3.14
|
||||
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
||||
Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*
|
||||
Description-Content-Type: text/x-rst
|
||||
License-File: LICENSE.rst
|
||||
Requires-Dist: wrapt<3,>=1.10
|
||||
Requires-Dist: inspect2; python_version < "3"
|
||||
Provides-Extra: dev
|
||||
Requires-Dist: tox; extra == "dev"
|
||||
Requires-Dist: PyTest; extra == "dev"
|
||||
Requires-Dist: PyTest-Cov; extra == "dev"
|
||||
Requires-Dist: bump2version<1; extra == "dev"
|
||||
Requires-Dist: setuptools; python_version >= "3.12" and extra == "dev"
|
||||
Dynamic: author
|
||||
Dynamic: author-email
|
||||
Dynamic: classifier
|
||||
Dynamic: description
|
||||
Dynamic: description-content-type
|
||||
Dynamic: home-page
|
||||
Dynamic: keywords
|
||||
Dynamic: license
|
||||
Dynamic: license-file
|
||||
Dynamic: platform
|
||||
Dynamic: project-url
|
||||
Dynamic: provides-extra
|
||||
Dynamic: requires-dist
|
||||
Dynamic: requires-python
|
||||
Dynamic: summary
|
||||
|
||||
|
||||
Deprecated Library
|
||||
------------------
|
||||
|
||||
Deprecated is Easy to Use
|
||||
`````````````````````````
|
||||
|
||||
If you need to mark a function or a method as deprecated,
|
||||
you can use the ``@deprecated`` decorator:
|
||||
|
||||
Save in a hello.py:
|
||||
|
||||
.. code:: python
|
||||
|
||||
from deprecated import deprecated
|
||||
|
||||
|
||||
@deprecated(version='1.2.1', reason="You should use another function")
|
||||
def some_old_function(x, y):
|
||||
return x + y
|
||||
|
||||
|
||||
class SomeClass(object):
|
||||
@deprecated(version='1.3.0', reason="This method is deprecated")
|
||||
def some_old_method(self, x, y):
|
||||
return x + y
|
||||
|
||||
|
||||
some_old_function(12, 34)
|
||||
obj = SomeClass()
|
||||
obj.some_old_method(5, 8)
|
||||
|
||||
|
||||
And Easy to Setup
|
||||
`````````````````
|
||||
|
||||
And run it:
|
||||
|
||||
.. code:: bash
|
||||
|
||||
$ pip install Deprecated
|
||||
$ python hello.py
|
||||
hello.py:15: DeprecationWarning: Call to deprecated function (or staticmethod) some_old_function.
|
||||
(You should use another function) -- Deprecated since version 1.2.0.
|
||||
some_old_function(12, 34)
|
||||
hello.py:17: DeprecationWarning: Call to deprecated method some_old_method.
|
||||
(This method is deprecated) -- Deprecated since version 1.3.0.
|
||||
obj.some_old_method(5, 8)
|
||||
|
||||
|
||||
You can document your code
|
||||
``````````````````````````
|
||||
|
||||
Have you ever wonder how to document that some functions, classes, methods, etc. are deprecated?
|
||||
This is now possible with the integrated Sphinx directives:
|
||||
|
||||
For instance, in hello_sphinx.py:
|
||||
|
||||
.. code:: python
|
||||
|
||||
from deprecated.sphinx import deprecated
|
||||
from deprecated.sphinx import versionadded
|
||||
from deprecated.sphinx import versionchanged
|
||||
|
||||
|
||||
@versionadded(version='1.0', reason="This function is new")
|
||||
def function_one():
|
||||
'''This is the function one'''
|
||||
|
||||
|
||||
@versionchanged(version='1.0', reason="This function is modified")
|
||||
def function_two():
|
||||
'''This is the function two'''
|
||||
|
||||
|
||||
@deprecated(version='1.0', reason="This function will be removed soon")
|
||||
def function_three():
|
||||
'''This is the function three'''
|
||||
|
||||
|
||||
function_one()
|
||||
function_two()
|
||||
function_three() # warns
|
||||
|
||||
help(function_one)
|
||||
help(function_two)
|
||||
help(function_three)
|
||||
|
||||
|
||||
The result it immediate
|
||||
```````````````````````
|
||||
|
||||
Run it:
|
||||
|
||||
.. code:: bash
|
||||
|
||||
$ python hello_sphinx.py
|
||||
|
||||
hello_sphinx.py:23: DeprecationWarning: Call to deprecated function (or staticmethod) function_three.
|
||||
(This function will be removed soon) -- Deprecated since version 1.0.
|
||||
function_three() # warns
|
||||
|
||||
Help on function function_one in module __main__:
|
||||
|
||||
function_one()
|
||||
This is the function one
|
||||
|
||||
.. versionadded:: 1.0
|
||||
This function is new
|
||||
|
||||
Help on function function_two in module __main__:
|
||||
|
||||
function_two()
|
||||
This is the function two
|
||||
|
||||
.. versionchanged:: 1.0
|
||||
This function is modified
|
||||
|
||||
Help on function function_three in module __main__:
|
||||
|
||||
function_three()
|
||||
This is the function three
|
||||
|
||||
.. deprecated:: 1.0
|
||||
This function will be removed soon
|
||||
|
||||
|
||||
Links
|
||||
`````
|
||||
|
||||
* `Python package index (PyPi) <https://pypi.org/project/Deprecated/>`_
|
||||
* `GitHub website <https://github.com/laurent-laporte-pro/deprecated>`_
|
||||
* `Read The Docs <https://readthedocs.org/projects/deprecated>`_
|
||||
* `EBook on Lulu.com <http://www.lulu.com/commerce/index.php?fBuyContent=21305117>`_
|
||||
* `StackOverFlow Q&A <https://stackoverflow.com/a/40301488/1513933>`_
|
||||
* `Development version
|
||||
<https://github.com/laurent-laporte-pro/deprecated/zipball/master#egg=Deprecated-dev>`_
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
deprecated-1.3.1.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
||||
deprecated-1.3.1.dist-info/METADATA,sha256=QJdnrCOHjBxpSIjOSsxD2razfvorQEmVZ_tcfZ3OWFI,5894
|
||||
deprecated-1.3.1.dist-info/RECORD,,
|
||||
deprecated-1.3.1.dist-info/WHEEL,sha256=JNWh1Fm1UdwIQV075glCn4MVuCRs0sotJIq-J6rbxCU,109
|
||||
deprecated-1.3.1.dist-info/licenses/LICENSE.rst,sha256=HoPt0VvkGbXVveNy4yXlJ_9PmRX1SOfHUxS0H2aZ6Dw,1081
|
||||
deprecated-1.3.1.dist-info/top_level.txt,sha256=nHbOYawKPQQE5lQl-toUB1JBRJjUyn_m_Mb8RVJ0RjA,11
|
||||
deprecated/__init__.py,sha256=owN3nj3UYte9J327NJNf_hNQTJovl813H_Q7YKhFX9M,398
|
||||
deprecated/__pycache__/__init__.cpython-311.pyc,,
|
||||
deprecated/__pycache__/classic.cpython-311.pyc,,
|
||||
deprecated/__pycache__/params.cpython-311.pyc,,
|
||||
deprecated/__pycache__/sphinx.cpython-311.pyc,,
|
||||
deprecated/classic.py,sha256=vWW-8nVvEejx4P9sf75vleE9JWbETaha_Sa-Bf9Beyo,10649
|
||||
deprecated/params.py,sha256=_bWRXLZGi2qF-EmZfgWjGe2G15WZabhOH_9Ntvt42cc,2870
|
||||
deprecated/sphinx.py,sha256=cOKnXbDyFAwDr5O7HBEpgQrx-J-qfp57sfdK_LabDxs,11109
|
||||
@@ -0,0 +1,6 @@
|
||||
Wheel-Version: 1.0
|
||||
Generator: setuptools (80.9.0)
|
||||
Root-Is-Purelib: true
|
||||
Tag: py2-none-any
|
||||
Tag: py3-none-any
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2017 Laurent LAPORTE
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1 @@
|
||||
deprecated
|
||||
@@ -0,0 +1,16 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Deprecated Library
|
||||
==================
|
||||
|
||||
Python ``@deprecated`` decorator to deprecate old python classes, functions or methods.
|
||||
|
||||
"""
|
||||
|
||||
__version__ = "1.3.1"
|
||||
__author__ = u"Laurent LAPORTE <laurent.laporte.pro@gmail.com>"
|
||||
__date__ = "2025-10-30"
|
||||
__credits__ = "(c) Laurent LAPORTE"
|
||||
|
||||
from deprecated.classic import deprecated
|
||||
from deprecated.params import deprecated_params
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,301 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Classic deprecation warning
|
||||
===========================
|
||||
|
||||
Classic ``@deprecated`` decorator to deprecate old python classes, functions or methods.
|
||||
|
||||
.. _The Warnings Filter: https://docs.python.org/3/library/warnings.html#the-warnings-filter
|
||||
"""
|
||||
import functools
|
||||
import inspect
|
||||
import platform
|
||||
import warnings
|
||||
|
||||
import wrapt
|
||||
|
||||
try:
|
||||
# If the C extension for wrapt was compiled and wrapt/_wrappers.pyd exists, then the
|
||||
# stack level that should be passed to warnings.warn should be 2. However, if using
|
||||
# a pure python wrapt, an extra stacklevel is required.
|
||||
import wrapt._wrappers
|
||||
|
||||
_routine_stacklevel = 2
|
||||
_class_stacklevel = 2
|
||||
except ImportError: # pragma: no cover
|
||||
_routine_stacklevel = 3
|
||||
if platform.python_implementation() == "PyPy":
|
||||
_class_stacklevel = 2
|
||||
else:
|
||||
_class_stacklevel = 3
|
||||
|
||||
string_types = (type(b''), type(u''))
|
||||
|
||||
|
||||
class ClassicAdapter(wrapt.AdapterFactory):
|
||||
"""
|
||||
Classic adapter -- *for advanced usage only*
|
||||
|
||||
This adapter is used to get the deprecation message according to the wrapped object type:
|
||||
class, function, standard method, static method, or class method.
|
||||
|
||||
This is the base class of the :class:`~deprecated.sphinx.SphinxAdapter` class
|
||||
which is used to update the wrapped object docstring.
|
||||
|
||||
You can also inherit this class to change the deprecation message.
|
||||
|
||||
In the following example, we change the message into "The ... is deprecated.":
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import inspect
|
||||
|
||||
from deprecated.classic import ClassicAdapter
|
||||
from deprecated.classic import deprecated
|
||||
|
||||
|
||||
class MyClassicAdapter(ClassicAdapter):
|
||||
def get_deprecated_msg(self, wrapped, instance):
|
||||
if instance is None:
|
||||
if inspect.isclass(wrapped):
|
||||
fmt = "The class {name} is deprecated."
|
||||
else:
|
||||
fmt = "The function {name} is deprecated."
|
||||
else:
|
||||
if inspect.isclass(instance):
|
||||
fmt = "The class method {name} is deprecated."
|
||||
else:
|
||||
fmt = "The method {name} is deprecated."
|
||||
if self.reason:
|
||||
fmt += " ({reason})"
|
||||
if self.version:
|
||||
fmt += " -- Deprecated since version {version}."
|
||||
return fmt.format(name=wrapped.__name__,
|
||||
reason=self.reason or "",
|
||||
version=self.version or "")
|
||||
|
||||
Then, you can use your ``MyClassicAdapter`` class like this in your source code:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@deprecated(reason="use another function", adapter_cls=MyClassicAdapter)
|
||||
def some_old_function(x, y):
|
||||
return x + y
|
||||
"""
|
||||
|
||||
def __init__(self, reason="", version="", action=None, category=DeprecationWarning, extra_stacklevel=0):
|
||||
"""
|
||||
Construct a wrapper adapter.
|
||||
|
||||
:type reason: str
|
||||
:param reason:
|
||||
Reason message which documents the deprecation in your library (can be omitted).
|
||||
|
||||
:type version: str
|
||||
:param version:
|
||||
Version of your project which deprecates this feature.
|
||||
If you follow the `Semantic Versioning <https://semver.org/>`_,
|
||||
the version number has the format "MAJOR.MINOR.PATCH".
|
||||
|
||||
:type action: Literal["default", "error", "ignore", "always", "module", "once"]
|
||||
:param action:
|
||||
A warning filter used to activate or not the deprecation warning.
|
||||
Can be one of "error", "ignore", "always", "default", "module", or "once".
|
||||
If ``None`` or empty, the global filtering mechanism is used.
|
||||
See: `The Warnings Filter`_ in the Python documentation.
|
||||
|
||||
:type category: Type[Warning]
|
||||
:param category:
|
||||
The warning category to use for the deprecation warning.
|
||||
By default, the category class is :class:`~DeprecationWarning`,
|
||||
you can inherit this class to define your own deprecation warning category.
|
||||
|
||||
:type extra_stacklevel: int
|
||||
:param extra_stacklevel:
|
||||
Number of additional stack levels to consider instrumentation rather than user code.
|
||||
With the default value of 0, the warning refers to where the class was instantiated
|
||||
or the function was called.
|
||||
|
||||
.. versionchanged:: 1.2.15
|
||||
Add the *extra_stacklevel* parameter.
|
||||
"""
|
||||
self.reason = reason or ""
|
||||
self.version = version or ""
|
||||
self.action = action
|
||||
self.category = category
|
||||
self.extra_stacklevel = extra_stacklevel
|
||||
super(ClassicAdapter, self).__init__()
|
||||
|
||||
def get_deprecated_msg(self, wrapped, instance):
|
||||
"""
|
||||
Get the deprecation warning message for the user.
|
||||
|
||||
:param wrapped: Wrapped class or function.
|
||||
|
||||
:param instance: The object to which the wrapped function was bound when it was called.
|
||||
|
||||
:return: The warning message.
|
||||
"""
|
||||
if instance is None:
|
||||
if inspect.isclass(wrapped):
|
||||
fmt = "Call to deprecated class {name}."
|
||||
else:
|
||||
fmt = "Call to deprecated function (or staticmethod) {name}."
|
||||
else:
|
||||
if inspect.isclass(instance):
|
||||
fmt = "Call to deprecated class method {name}."
|
||||
else:
|
||||
fmt = "Call to deprecated method {name}."
|
||||
if self.reason:
|
||||
fmt += " ({reason})"
|
||||
if self.version:
|
||||
fmt += " -- Deprecated since version {version}."
|
||||
return fmt.format(name=wrapped.__name__, reason=self.reason or "", version=self.version or "")
|
||||
|
||||
def __call__(self, wrapped):
|
||||
"""
|
||||
Decorate your class or function.
|
||||
|
||||
:param wrapped: Wrapped class or function.
|
||||
|
||||
:return: the decorated class or function.
|
||||
|
||||
.. versionchanged:: 1.2.4
|
||||
Don't pass arguments to :meth:`object.__new__` (other than *cls*).
|
||||
|
||||
.. versionchanged:: 1.2.8
|
||||
The warning filter is not set if the *action* parameter is ``None`` or empty.
|
||||
"""
|
||||
if inspect.isclass(wrapped):
|
||||
old_new1 = wrapped.__new__
|
||||
|
||||
def wrapped_cls(cls, *args, **kwargs):
|
||||
msg = self.get_deprecated_msg(wrapped, None)
|
||||
stacklevel = _class_stacklevel + self.extra_stacklevel
|
||||
if self.action:
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter(self.action, self.category)
|
||||
warnings.warn(msg, category=self.category, stacklevel=stacklevel)
|
||||
else:
|
||||
warnings.warn(msg, category=self.category, stacklevel=stacklevel)
|
||||
if old_new1 is object.__new__:
|
||||
return old_new1(cls)
|
||||
# actually, we don't know the real signature of *old_new1*
|
||||
return old_new1(cls, *args, **kwargs)
|
||||
|
||||
wrapped.__new__ = staticmethod(wrapped_cls)
|
||||
|
||||
elif inspect.isroutine(wrapped):
|
||||
@wrapt.decorator
|
||||
def wrapper_function(wrapped_, instance_, args_, kwargs_):
|
||||
msg = self.get_deprecated_msg(wrapped_, instance_)
|
||||
stacklevel = _routine_stacklevel + self.extra_stacklevel
|
||||
if self.action:
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter(self.action, self.category)
|
||||
warnings.warn(msg, category=self.category, stacklevel=stacklevel)
|
||||
else:
|
||||
warnings.warn(msg, category=self.category, stacklevel=stacklevel)
|
||||
return wrapped_(*args_, **kwargs_)
|
||||
|
||||
return wrapper_function(wrapped)
|
||||
|
||||
else: # pragma: no cover
|
||||
raise TypeError(repr(type(wrapped)))
|
||||
|
||||
return wrapped
|
||||
|
||||
|
||||
def deprecated(*args, **kwargs):
|
||||
"""
|
||||
This is a decorator which can be used to mark functions
|
||||
as deprecated. It will result in a warning being emitted
|
||||
when the function is used.
|
||||
|
||||
**Classic usage:**
|
||||
|
||||
To use this, decorate your deprecated function with **@deprecated** decorator:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from deprecated import deprecated
|
||||
|
||||
|
||||
@deprecated
|
||||
def some_old_function(x, y):
|
||||
return x + y
|
||||
|
||||
You can also decorate a class or a method:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from deprecated import deprecated
|
||||
|
||||
|
||||
class SomeClass(object):
|
||||
@deprecated
|
||||
def some_old_method(self, x, y):
|
||||
return x + y
|
||||
|
||||
|
||||
@deprecated
|
||||
class SomeOldClass(object):
|
||||
pass
|
||||
|
||||
You can give a *reason* message to help the developer to choose another function/class,
|
||||
and a *version* number to specify the starting version number of the deprecation.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from deprecated import deprecated
|
||||
|
||||
|
||||
@deprecated(reason="use another function", version='1.2.0')
|
||||
def some_old_function(x, y):
|
||||
return x + y
|
||||
|
||||
The *category* keyword argument allow you to specify the deprecation warning class of your choice.
|
||||
By default, :exc:`DeprecationWarning` is used, but you can choose :exc:`FutureWarning`,
|
||||
:exc:`PendingDeprecationWarning` or a custom subclass.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from deprecated import deprecated
|
||||
|
||||
|
||||
@deprecated(category=PendingDeprecationWarning)
|
||||
def some_old_function(x, y):
|
||||
return x + y
|
||||
|
||||
The *action* keyword argument allow you to locally change the warning filtering.
|
||||
*action* can be one of "error", "ignore", "always", "default", "module", or "once".
|
||||
If ``None``, empty or missing, the global filtering mechanism is used.
|
||||
See: `The Warnings Filter`_ in the Python documentation.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from deprecated import deprecated
|
||||
|
||||
|
||||
@deprecated(action="error")
|
||||
def some_old_function(x, y):
|
||||
return x + y
|
||||
|
||||
The *extra_stacklevel* keyword argument allows you to specify additional stack levels
|
||||
to consider instrumentation rather than user code. With the default value of 0, the
|
||||
warning refers to where the class was instantiated or the function was called.
|
||||
"""
|
||||
if args and isinstance(args[0], string_types):
|
||||
kwargs['reason'] = args[0]
|
||||
args = args[1:]
|
||||
|
||||
if args and not callable(args[0]):
|
||||
raise TypeError(repr(type(args[0])))
|
||||
|
||||
if args:
|
||||
adapter_cls = kwargs.pop('adapter_cls', ClassicAdapter)
|
||||
adapter = adapter_cls(**kwargs)
|
||||
wrapped = args[0]
|
||||
return adapter(wrapped)
|
||||
|
||||
return functools.partial(deprecated, **kwargs)
|
||||
@@ -0,0 +1,79 @@
|
||||
# coding: utf-8
|
||||
"""
|
||||
Parameters deprecation
|
||||
======================
|
||||
|
||||
.. _Tantale's Blog: https://tantale.github.io/
|
||||
.. _Deprecated Parameters: https://tantale.github.io/articles/deprecated_params/
|
||||
|
||||
This module introduces a :class:`deprecated_params` decorator to specify that one (or more)
|
||||
parameter(s) are deprecated: when the user executes a function with a deprecated parameter,
|
||||
he will see a warning message in the console.
|
||||
|
||||
The decorator is customizable, the user can specify the deprecated parameter names
|
||||
and associate to each of them a message providing the reason of the deprecation.
|
||||
As with the :func:`~deprecated.classic.deprecated` decorator, the user can specify
|
||||
a version number (using the *version* parameter) and also define the warning message category
|
||||
(a subclass of :class:`Warning`) and when to display the messages (using the *action* parameter).
|
||||
|
||||
The complete study concerning the implementation of this decorator is available on the `Tantale's blog`_,
|
||||
on the `Deprecated Parameters`_ page.
|
||||
"""
|
||||
import collections
|
||||
import functools
|
||||
import warnings
|
||||
|
||||
try:
|
||||
# noinspection PyPackageRequirements
|
||||
import inspect2 as inspect
|
||||
except ImportError:
|
||||
import inspect
|
||||
|
||||
|
||||
class DeprecatedParams(object):
|
||||
"""
|
||||
Decorator used to decorate a function which at least one
|
||||
of the parameters is deprecated.
|
||||
"""
|
||||
|
||||
def __init__(self, param, reason="", category=DeprecationWarning):
|
||||
self.messages = {} # type: dict[str, str]
|
||||
self.category = category
|
||||
self.populate_messages(param, reason=reason)
|
||||
|
||||
def populate_messages(self, param, reason=""):
|
||||
if isinstance(param, dict):
|
||||
self.messages.update(param)
|
||||
elif isinstance(param, str):
|
||||
fmt = "'{param}' parameter is deprecated"
|
||||
reason = reason or fmt.format(param=param)
|
||||
self.messages[param] = reason
|
||||
else:
|
||||
raise TypeError(param)
|
||||
|
||||
def check_params(self, signature, *args, **kwargs):
|
||||
binding = signature.bind(*args, **kwargs)
|
||||
bound = collections.OrderedDict(binding.arguments, **binding.kwargs)
|
||||
return [param for param in bound if param in self.messages]
|
||||
|
||||
def warn_messages(self, messages):
|
||||
# type: (list[str]) -> None
|
||||
for message in messages:
|
||||
warnings.warn(message, category=self.category, stacklevel=3)
|
||||
|
||||
def __call__(self, f):
|
||||
# type: (callable) -> callable
|
||||
signature = inspect.signature(f)
|
||||
|
||||
@functools.wraps(f)
|
||||
def wrapper(*args, **kwargs):
|
||||
invalid_params = self.check_params(signature, *args, **kwargs)
|
||||
self.warn_messages([self.messages[param] for param in invalid_params])
|
||||
return f(*args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
#: Decorator used to decorate a function which at least one
|
||||
#: of the parameters is deprecated.
|
||||
deprecated_params = DeprecatedParams
|
||||
@@ -0,0 +1,281 @@
|
||||
# coding: utf-8
|
||||
"""
|
||||
Sphinx directive integration
|
||||
============================
|
||||
|
||||
We usually need to document the life-cycle of functions and classes:
|
||||
when they are created, modified or deprecated.
|
||||
|
||||
To do that, `Sphinx <http://www.sphinx-doc.org>`_ has a set
|
||||
of `Paragraph-level markups <http://www.sphinx-doc.org/en/stable/markup/para.html>`_:
|
||||
|
||||
- ``versionadded``: to document the version of the project which added the described feature to the library,
|
||||
- ``versionchanged``: to document changes of a feature,
|
||||
- ``deprecated``: to document a deprecated feature.
|
||||
|
||||
The purpose of this module is to defined decorators which adds this Sphinx directives
|
||||
to the docstring of your function and classes.
|
||||
|
||||
Of course, the ``@deprecated`` decorator will emit a deprecation warning
|
||||
when the function/method is called or the class is constructed.
|
||||
"""
|
||||
import re
|
||||
import textwrap
|
||||
|
||||
from deprecated.classic import ClassicAdapter
|
||||
from deprecated.classic import deprecated as _classic_deprecated
|
||||
|
||||
|
||||
class SphinxAdapter(ClassicAdapter):
|
||||
"""
|
||||
Sphinx adapter -- *for advanced usage only*
|
||||
|
||||
This adapter override the :class:`~deprecated.classic.ClassicAdapter`
|
||||
in order to add the Sphinx directives to the end of the function/class docstring.
|
||||
Such a directive is a `Paragraph-level markup <http://www.sphinx-doc.org/en/stable/markup/para.html>`_
|
||||
|
||||
- The directive can be one of "versionadded", "versionchanged" or "deprecated".
|
||||
- The version number is added if provided.
|
||||
- The reason message is obviously added in the directive block if not empty.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
directive,
|
||||
reason="",
|
||||
version="",
|
||||
action=None,
|
||||
category=DeprecationWarning,
|
||||
extra_stacklevel=0,
|
||||
line_length=70,
|
||||
):
|
||||
"""
|
||||
Construct a wrapper adapter.
|
||||
|
||||
:type directive: str
|
||||
:param directive:
|
||||
Sphinx directive: can be one of "versionadded", "versionchanged" or "deprecated".
|
||||
|
||||
:type reason: str
|
||||
:param reason:
|
||||
Reason message which documents the deprecation in your library (can be omitted).
|
||||
|
||||
:type version: str
|
||||
:param version:
|
||||
Version of your project which deprecates this feature.
|
||||
If you follow the `Semantic Versioning <https://semver.org/>`_,
|
||||
the version number has the format "MAJOR.MINOR.PATCH".
|
||||
|
||||
:type action: Literal["default", "error", "ignore", "always", "module", "once"]
|
||||
:param action:
|
||||
A warning filter used to activate or not the deprecation warning.
|
||||
Can be one of "error", "ignore", "always", "default", "module", or "once".
|
||||
If ``None`` or empty, the global filtering mechanism is used.
|
||||
See: `The Warnings Filter`_ in the Python documentation.
|
||||
|
||||
:type category: Type[Warning]
|
||||
:param category:
|
||||
The warning category to use for the deprecation warning.
|
||||
By default, the category class is :class:`~DeprecationWarning`,
|
||||
you can inherit this class to define your own deprecation warning category.
|
||||
|
||||
:type extra_stacklevel: int
|
||||
:param extra_stacklevel:
|
||||
Number of additional stack levels to consider instrumentation rather than user code.
|
||||
With the default value of 0, the warning refers to where the class was instantiated
|
||||
or the function was called.
|
||||
|
||||
:type line_length: int
|
||||
:param line_length:
|
||||
Max line length of the directive text. If non nul, a long text is wrapped in several lines.
|
||||
|
||||
.. versionchanged:: 1.2.15
|
||||
Add the *extra_stacklevel* parameter.
|
||||
"""
|
||||
if not version:
|
||||
# https://github.com/laurent-laporte-pro/deprecated/issues/40
|
||||
raise ValueError("'version' argument is required in Sphinx directives")
|
||||
self.directive = directive
|
||||
self.line_length = line_length
|
||||
super(SphinxAdapter, self).__init__(
|
||||
reason=reason, version=version, action=action, category=category, extra_stacklevel=extra_stacklevel
|
||||
)
|
||||
|
||||
def __call__(self, wrapped):
|
||||
"""
|
||||
Add the Sphinx directive to your class or function.
|
||||
|
||||
:param wrapped: Wrapped class or function.
|
||||
|
||||
:return: the decorated class or function.
|
||||
"""
|
||||
# -- build the directive division
|
||||
fmt = ".. {directive}:: {version}" if self.version else ".. {directive}::"
|
||||
div_lines = [fmt.format(directive=self.directive, version=self.version)]
|
||||
width = self.line_length - 3 if self.line_length > 3 else 2**16
|
||||
reason = textwrap.dedent(self.reason).strip()
|
||||
for paragraph in reason.splitlines():
|
||||
if paragraph:
|
||||
div_lines.extend(
|
||||
textwrap.fill(
|
||||
paragraph,
|
||||
width=width,
|
||||
initial_indent=" ",
|
||||
subsequent_indent=" ",
|
||||
).splitlines()
|
||||
)
|
||||
else:
|
||||
div_lines.append("")
|
||||
|
||||
# -- get the docstring, normalize the trailing newlines
|
||||
# keep a consistent behaviour if the docstring starts with newline or directly on the first one
|
||||
docstring = wrapped.__doc__ or ""
|
||||
lines = docstring.splitlines(True) or [""]
|
||||
docstring = textwrap.dedent("".join(lines[1:])) if len(lines) > 1 else ""
|
||||
docstring = lines[0] + docstring
|
||||
if docstring:
|
||||
# An empty line must separate the original docstring and the directive.
|
||||
docstring = re.sub(r"\n+$", "", docstring, flags=re.DOTALL) + "\n\n"
|
||||
else:
|
||||
# Avoid "Explicit markup ends without a blank line" when the decorated function has no docstring
|
||||
docstring = "\n"
|
||||
|
||||
# -- append the directive division to the docstring
|
||||
docstring += "".join("{}\n".format(line) for line in div_lines)
|
||||
|
||||
wrapped.__doc__ = docstring
|
||||
if self.directive in {"versionadded", "versionchanged"}:
|
||||
return wrapped
|
||||
return super(SphinxAdapter, self).__call__(wrapped)
|
||||
|
||||
def get_deprecated_msg(self, wrapped, instance):
|
||||
"""
|
||||
Get the deprecation warning message (without Sphinx cross-referencing syntax) for the user.
|
||||
|
||||
:param wrapped: Wrapped class or function.
|
||||
|
||||
:param instance: The object to which the wrapped function was bound when it was called.
|
||||
|
||||
:return: The warning message.
|
||||
|
||||
.. versionadded:: 1.2.12
|
||||
Strip Sphinx cross-referencing syntax from warning message.
|
||||
|
||||
"""
|
||||
msg = super(SphinxAdapter, self).get_deprecated_msg(wrapped, instance)
|
||||
# Strip Sphinx cross-reference syntax (like ":function:", ":py:func:" and ":py:meth:")
|
||||
# Possible values are ":role:`foo`", ":domain:role:`foo`"
|
||||
# where ``role`` and ``domain`` should match "[a-zA-Z]+"
|
||||
msg = re.sub(r"(?: : [a-zA-Z]+ )? : [a-zA-Z]+ : (`[^`]*`)", r"\1", msg, flags=re.X)
|
||||
return msg
|
||||
|
||||
|
||||
def versionadded(reason="", version="", line_length=70):
|
||||
"""
|
||||
This decorator can be used to insert a "versionadded" directive
|
||||
in your function/class docstring in order to document the
|
||||
version of the project which adds this new functionality in your library.
|
||||
|
||||
:param str reason:
|
||||
Reason message which documents the addition in your library (can be omitted).
|
||||
|
||||
:param str version:
|
||||
Version of your project which adds this feature.
|
||||
If you follow the `Semantic Versioning <https://semver.org/>`_,
|
||||
the version number has the format "MAJOR.MINOR.PATCH", and,
|
||||
in the case of a new functionality, the "PATCH" component should be "0".
|
||||
|
||||
:type line_length: int
|
||||
:param line_length:
|
||||
Max line length of the directive text. If non nul, a long text is wrapped in several lines.
|
||||
|
||||
:return: the decorated function.
|
||||
"""
|
||||
adapter = SphinxAdapter(
|
||||
'versionadded',
|
||||
reason=reason,
|
||||
version=version,
|
||||
line_length=line_length,
|
||||
)
|
||||
return adapter
|
||||
|
||||
|
||||
def versionchanged(reason="", version="", line_length=70):
|
||||
"""
|
||||
This decorator can be used to insert a "versionchanged" directive
|
||||
in your function/class docstring in order to document the
|
||||
version of the project which modifies this functionality in your library.
|
||||
|
||||
:param str reason:
|
||||
Reason message which documents the modification in your library (can be omitted).
|
||||
|
||||
:param str version:
|
||||
Version of your project which modifies this feature.
|
||||
If you follow the `Semantic Versioning <https://semver.org/>`_,
|
||||
the version number has the format "MAJOR.MINOR.PATCH".
|
||||
|
||||
:type line_length: int
|
||||
:param line_length:
|
||||
Max line length of the directive text. If non nul, a long text is wrapped in several lines.
|
||||
|
||||
:return: the decorated function.
|
||||
"""
|
||||
adapter = SphinxAdapter(
|
||||
'versionchanged',
|
||||
reason=reason,
|
||||
version=version,
|
||||
line_length=line_length,
|
||||
)
|
||||
return adapter
|
||||
|
||||
|
||||
def deprecated(reason="", version="", line_length=70, **kwargs):
|
||||
"""
|
||||
This decorator can be used to insert a "deprecated" directive
|
||||
in your function/class docstring in order to document the
|
||||
version of the project which deprecates this functionality in your library.
|
||||
|
||||
:param str reason:
|
||||
Reason message which documents the deprecation in your library (can be omitted).
|
||||
|
||||
:param str version:
|
||||
Version of your project which deprecates this feature.
|
||||
If you follow the `Semantic Versioning <https://semver.org/>`_,
|
||||
the version number has the format "MAJOR.MINOR.PATCH".
|
||||
|
||||
:type line_length: int
|
||||
:param line_length:
|
||||
Max line length of the directive text. If non nul, a long text is wrapped in several lines.
|
||||
|
||||
Keyword arguments can be:
|
||||
|
||||
- "action":
|
||||
A warning filter used to activate or not the deprecation warning.
|
||||
Can be one of "error", "ignore", "always", "default", "module", or "once".
|
||||
If ``None``, empty or missing, the global filtering mechanism is used.
|
||||
|
||||
- "category":
|
||||
The warning category to use for the deprecation warning.
|
||||
By default, the category class is :class:`~DeprecationWarning`,
|
||||
you can inherit this class to define your own deprecation warning category.
|
||||
|
||||
- "extra_stacklevel":
|
||||
Number of additional stack levels to consider instrumentation rather than user code.
|
||||
With the default value of 0, the warning refers to where the class was instantiated
|
||||
or the function was called.
|
||||
|
||||
|
||||
:return: a decorator used to deprecate a function.
|
||||
|
||||
.. versionchanged:: 1.2.13
|
||||
Change the signature of the decorator to reflect the valid use cases.
|
||||
|
||||
.. versionchanged:: 1.2.15
|
||||
Add the *extra_stacklevel* parameter.
|
||||
"""
|
||||
directive = kwargs.pop('directive', 'deprecated')
|
||||
adapter_cls = kwargs.pop('adapter_cls', SphinxAdapter)
|
||||
kwargs["reason"] = reason
|
||||
kwargs["version"] = version
|
||||
kwargs["line_length"] = line_length
|
||||
return _classic_deprecated(directive=directive, adapter_cls=adapter_cls, **kwargs)
|
||||
@@ -0,0 +1 @@
|
||||
import os; var = 'SETUPTOOLS_USE_DISTUTILS'; enabled = os.environ.get(var, 'local') == 'local'; enabled and __import__('_distutils_hack').add_shim();
|
||||
@@ -0,0 +1 @@
|
||||
pip
|
||||
@@ -0,0 +1,117 @@
|
||||
Metadata-Version: 2.4
|
||||
Name: mss
|
||||
Version: 10.1.0
|
||||
Summary: An ultra fast cross-platform multiple screenshots module in pure python using ctypes.
|
||||
Project-URL: Homepage, https://github.com/BoboTiG/python-mss
|
||||
Project-URL: Documentation, https://python-mss.readthedocs.io
|
||||
Project-URL: Changelog, https://github.com/BoboTiG/python-mss/blob/main/CHANGELOG.md
|
||||
Project-URL: Source, https://github.com/BoboTiG/python-mss
|
||||
Project-URL: Sponsor, https://github.com/sponsors/BoboTiG
|
||||
Project-URL: Tracker, https://github.com/BoboTiG/python-mss/issues
|
||||
Project-URL: Released Versions, https://github.com/BoboTiG/python-mss/releases
|
||||
Author-email: Mickaël Schoentgen <contact@tiger-222.fr>
|
||||
Maintainer-email: Mickaël Schoentgen <contact@tiger-222.fr>
|
||||
License: MIT License
|
||||
Copyright (c) 2013-2025, Mickaël 'Tiger-222' Schoentgen
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
License-File: LICENSE.txt
|
||||
Keywords: BitBlt,CGGetActiveDisplayList,CGImageGetBitsPerPixel,EnumDisplayMonitors,XGetImage,XGetWindowAttributes,XRRGetScreenResourcesCurrent,ctypes,monitor,screen,screencapture,screengrab,screenshot
|
||||
Classifier: Development Status :: 5 - Production/Stable
|
||||
Classifier: Environment :: MacOS X
|
||||
Classifier: Intended Audience :: Developers
|
||||
Classifier: Intended Audience :: Education
|
||||
Classifier: Intended Audience :: End Users/Desktop
|
||||
Classifier: Intended Audience :: Information Technology
|
||||
Classifier: Intended Audience :: Science/Research
|
||||
Classifier: License :: OSI Approved :: MIT License
|
||||
Classifier: Operating System :: MacOS
|
||||
Classifier: Operating System :: Microsoft :: Windows
|
||||
Classifier: Operating System :: Unix
|
||||
Classifier: Programming Language :: Python
|
||||
Classifier: Programming Language :: Python :: 3
|
||||
Classifier: Programming Language :: Python :: 3 :: Only
|
||||
Classifier: Programming Language :: Python :: 3.9
|
||||
Classifier: Programming Language :: Python :: 3.10
|
||||
Classifier: Programming Language :: Python :: 3.11
|
||||
Classifier: Programming Language :: Python :: 3.12
|
||||
Classifier: Programming Language :: Python :: 3.13
|
||||
Classifier: Programming Language :: Python :: 3.14
|
||||
Classifier: Programming Language :: Python :: Implementation :: CPython
|
||||
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
||||
Classifier: Topic :: Multimedia :: Graphics :: Capture :: Screen Capture
|
||||
Classifier: Topic :: Software Development :: Libraries
|
||||
Requires-Python: >=3.9
|
||||
Provides-Extra: dev
|
||||
Requires-Dist: build==1.3.0; extra == 'dev'
|
||||
Requires-Dist: mypy==1.17.1; extra == 'dev'
|
||||
Requires-Dist: ruff==0.12.9; extra == 'dev'
|
||||
Requires-Dist: twine==6.1.0; extra == 'dev'
|
||||
Provides-Extra: docs
|
||||
Requires-Dist: shibuya==2025.7.24; extra == 'docs'
|
||||
Requires-Dist: sphinx-copybutton==0.5.2; extra == 'docs'
|
||||
Requires-Dist: sphinx-new-tab-link==0.8.0; extra == 'docs'
|
||||
Requires-Dist: sphinx==8.2.3; extra == 'docs'
|
||||
Provides-Extra: tests
|
||||
Requires-Dist: numpy==2.2.4; (sys_platform == 'linux' and python_version == '3.13') and extra == 'tests'
|
||||
Requires-Dist: pillow==11.3.0; (sys_platform == 'linux' and python_version == '3.13') and extra == 'tests'
|
||||
Requires-Dist: pytest-cov==6.2.1; extra == 'tests'
|
||||
Requires-Dist: pytest-rerunfailures==15.1; extra == 'tests'
|
||||
Requires-Dist: pytest==8.4.1; extra == 'tests'
|
||||
Requires-Dist: pyvirtualdisplay==3.0; (sys_platform == 'linux') and extra == 'tests'
|
||||
Description-Content-Type: text/markdown
|
||||
|
||||
# Python MSS
|
||||
|
||||
[](https://badge.fury.io/py/mss)
|
||||
[](https://anaconda.org/conda-forge/python-mss)
|
||||
[](https://github.com/BoboTiG/python-mss/actions/workflows/tests.yml)
|
||||
[](https://pepy.tech/project/mss)
|
||||
|
||||
> [!TIP]
|
||||
> Become **my boss** to help me work on this awesome software, and make the world better:
|
||||
>
|
||||
> [](https://www.patreon.com/mschoentgen)
|
||||
|
||||
```python
|
||||
from mss import mss
|
||||
|
||||
# The simplest use, save a screenshot of the 1st monitor
|
||||
with mss() as sct:
|
||||
sct.shot()
|
||||
```
|
||||
|
||||
An ultra-fast cross-platform multiple screenshots module in pure python using ctypes.
|
||||
|
||||
- **Python 3.9+**, PEP8 compliant, no dependency, thread-safe;
|
||||
- very basic, it will grab one screenshot by monitor or a screenshot of all monitors and save it to a PNG file;
|
||||
- but you can use PIL and benefit from all its formats (or add yours directly);
|
||||
- integrate well with Numpy and OpenCV;
|
||||
- it could be easily embedded into games and other software which require fast and platform optimized methods to grab screenshots (like AI, Computer Vision);
|
||||
- get the [source code on GitHub](https://github.com/BoboTiG/python-mss);
|
||||
- learn with a [bunch of examples](https://python-mss.readthedocs.io/examples.html);
|
||||
- you can [report a bug](https://github.com/BoboTiG/python-mss/issues);
|
||||
- need some help? Use the tag *python-mss* on [Stack Overflow](https://stackoverflow.com/questions/tagged/python-mss);
|
||||
- and there is a [complete, and beautiful, documentation](https://python-mss.readthedocs.io) :)
|
||||
- **MSS** stands for Multiple ScreenShots;
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
You can install it with pip:
|
||||
|
||||
```shell
|
||||
python -m pip install -U --user mss
|
||||
```
|
||||
|
||||
Or you can install it with Conda:
|
||||
|
||||
```shell
|
||||
conda install -c conda-forge python-mss
|
||||
```
|
||||
|
||||
In case of scaling and high DPI issues for external monitors: some packages (e.g. `mouseinfo` / `pyautogui` / `pyscreeze`) incorrectly call `SetProcessDpiAware()` during import process. To prevent that, import `mss` first.
|
||||
@@ -0,0 +1,30 @@
|
||||
../../../bin/mss,sha256=NEJMj7Rn4CWNBO0CDGB5_q963_iBS1lxq5bYuFwWriM,268
|
||||
mss-10.1.0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
||||
mss-10.1.0.dist-info/METADATA,sha256=Mq0Oaz68Q60Ydiwk8i2HA0-RgkipauctrztBSQ46SBE,6734
|
||||
mss-10.1.0.dist-info/RECORD,,
|
||||
mss-10.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
||||
mss-10.1.0.dist-info/entry_points.txt,sha256=t0KQ9eF2tTjVPVDrBk9cy4LYI94FVyLNA675sEt8wmo,42
|
||||
mss-10.1.0.dist-info/licenses/LICENSE.txt,sha256=0viwNHxH6vxASPNGCFNmHOt5hnLCpprG-pcjxDJghdM,1093
|
||||
mss/__init__.py,sha256=FkVcDvkEV7ahVCjOW00jnjsJOPX4beKprvY2pjFlKfU,941
|
||||
mss/__main__.py,sha256=lUeXKOE6umwg97ympNWPnGfyzYrm9Y1ZxhOIsEOLxII,2669
|
||||
mss/__pycache__/__init__.cpython-311.pyc,,
|
||||
mss/__pycache__/__main__.cpython-311.pyc,,
|
||||
mss/__pycache__/base.cpython-311.pyc,,
|
||||
mss/__pycache__/darwin.cpython-311.pyc,,
|
||||
mss/__pycache__/exception.cpython-311.pyc,,
|
||||
mss/__pycache__/factory.cpython-311.pyc,,
|
||||
mss/__pycache__/linux.cpython-311.pyc,,
|
||||
mss/__pycache__/models.cpython-311.pyc,,
|
||||
mss/__pycache__/screenshot.cpython-311.pyc,,
|
||||
mss/__pycache__/tools.cpython-311.pyc,,
|
||||
mss/__pycache__/windows.cpython-311.pyc,,
|
||||
mss/base.py,sha256=lAj-JrFilSoYy5Ht6aYOiCIQlpCZPNn_joPe8lWZ9pA,8824
|
||||
mss/darwin.py,sha256=m-isJ1fgPSeZ2NRywm3EoBiBOQx3_4cS5tJDWsdPpv0,7921
|
||||
mss/exception.py,sha256=mkbIM3wMxzdvHTQxB-j7pPkyPevv1fAX_2gBNnbVWaU,386
|
||||
mss/factory.py,sha256=uOF7_AvXX9Zsbd985dB5j0kukUe5Tl3hwvCCCdcLK4E,942
|
||||
mss/linux.py,sha256=tS9tNwDJago6KQjm4lLneaOifYl9LjBy6zTIJoyAsUA,17337
|
||||
mss/models.py,sha256=4rxTAMlBM56_jOXYtJ5U6OTZ62-90-21OGq3dMnBNtw,406
|
||||
mss/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
||||
mss/screenshot.py,sha256=c_olzSUkg-dtN1xtcxGE6rlMyFEvxDGN5TAeMJkOi74,3882
|
||||
mss/tools.py,sha256=jyyxogdp57jZemd5WefVNXKIuhQ3dfOh0cMHBLFqKdw,1983
|
||||
mss/windows.py,sha256=Hplz6zu-b3SBKlT8GZnINGKhqGaKG2UJ0JaPHvDkg-8,8817
|
||||
@@ -0,0 +1,4 @@
|
||||
Wheel-Version: 1.0
|
||||
Generator: hatchling 1.27.0
|
||||
Root-Is-Purelib: true
|
||||
Tag: py3-none-any
|
||||
@@ -0,0 +1,2 @@
|
||||
[console_scripts]
|
||||
mss = mss.__main__:main
|
||||
@@ -0,0 +1,8 @@
|
||||
MIT License
|
||||
Copyright (c) 2013-2025, Mickaël 'Tiger-222' Schoentgen
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
@@ -0,0 +1,27 @@
|
||||
"""An ultra fast cross-platform multiple screenshots module in pure python
|
||||
using ctypes.
|
||||
|
||||
This module is maintained by Mickaël Schoentgen <contact@tiger-222.fr>.
|
||||
|
||||
You can always get the latest version of this module at:
|
||||
https://github.com/BoboTiG/python-mss
|
||||
If that URL should fail, try contacting the author.
|
||||
"""
|
||||
|
||||
from mss.exception import ScreenShotError
|
||||
from mss.factory import mss
|
||||
|
||||
__version__ = "10.1.0"
|
||||
__author__ = "Mickaël Schoentgen"
|
||||
__date__ = "2013-2025"
|
||||
__copyright__ = f"""
|
||||
Copyright (c) {__date__}, {__author__}
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and its
|
||||
documentation for any purpose and without fee or royalty is hereby
|
||||
granted, provided that the above copyright notice appear in all copies
|
||||
and that both that copyright notice and this permission notice appear
|
||||
in supporting documentation or portions thereof, including
|
||||
modifications, that you make.
|
||||
"""
|
||||
__all__ = ("ScreenShotError", "mss")
|
||||
@@ -0,0 +1,83 @@
|
||||
"""This is part of the MSS Python's module.
|
||||
Source: https://github.com/BoboTiG/python-mss.
|
||||
"""
|
||||
|
||||
import os.path
|
||||
import sys
|
||||
from argparse import ArgumentParser
|
||||
|
||||
from mss import __version__
|
||||
from mss.exception import ScreenShotError
|
||||
from mss.factory import mss
|
||||
from mss.tools import to_png
|
||||
|
||||
|
||||
def main(*args: str) -> int:
|
||||
"""Main logic."""
|
||||
cli_args = ArgumentParser(prog="mss")
|
||||
cli_args.add_argument(
|
||||
"-c",
|
||||
"--coordinates",
|
||||
default="",
|
||||
type=str,
|
||||
help="the part of the screen to capture: top, left, width, height",
|
||||
)
|
||||
cli_args.add_argument(
|
||||
"-l",
|
||||
"--level",
|
||||
default=6,
|
||||
type=int,
|
||||
choices=list(range(10)),
|
||||
help="the PNG compression level",
|
||||
)
|
||||
cli_args.add_argument("-m", "--monitor", default=0, type=int, help="the monitor to screenshot")
|
||||
cli_args.add_argument("-o", "--output", default="monitor-{mon}.png", help="the output file name")
|
||||
cli_args.add_argument("--with-cursor", default=False, action="store_true", help="include the cursor")
|
||||
cli_args.add_argument(
|
||||
"-q",
|
||||
"--quiet",
|
||||
default=False,
|
||||
action="store_true",
|
||||
help="do not print created files",
|
||||
)
|
||||
cli_args.add_argument("-v", "--version", action="version", version=__version__)
|
||||
|
||||
options = cli_args.parse_args(args or None)
|
||||
kwargs = {"mon": options.monitor, "output": options.output}
|
||||
if options.coordinates:
|
||||
try:
|
||||
top, left, width, height = options.coordinates.split(",")
|
||||
except ValueError:
|
||||
print("Coordinates syntax: top, left, width, height")
|
||||
return 2
|
||||
|
||||
kwargs["mon"] = {
|
||||
"top": int(top),
|
||||
"left": int(left),
|
||||
"width": int(width),
|
||||
"height": int(height),
|
||||
}
|
||||
if options.output == "monitor-{mon}.png":
|
||||
kwargs["output"] = "sct-{top}x{left}_{width}x{height}.png"
|
||||
|
||||
try:
|
||||
with mss(with_cursor=options.with_cursor) as sct:
|
||||
if options.coordinates:
|
||||
output = kwargs["output"].format(**kwargs["mon"])
|
||||
sct_img = sct.grab(kwargs["mon"])
|
||||
to_png(sct_img.rgb, sct_img.size, level=options.level, output=output)
|
||||
if not options.quiet:
|
||||
print(os.path.realpath(output))
|
||||
else:
|
||||
for file_name in sct.save(**kwargs):
|
||||
if not options.quiet:
|
||||
print(os.path.realpath(file_name))
|
||||
return 0
|
||||
except ScreenShotError:
|
||||
if options.quiet:
|
||||
return 1
|
||||
raise
|
||||
|
||||
|
||||
if __name__ == "__main__": # pragma: nocover
|
||||
sys.exit(main())
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,261 @@
|
||||
"""This is part of the MSS Python's module.
|
||||
Source: https://github.com/BoboTiG/python-mss.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from abc import ABCMeta, abstractmethod
|
||||
from datetime import datetime
|
||||
from threading import Lock
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from mss.exception import ScreenShotError
|
||||
from mss.screenshot import ScreenShot
|
||||
from mss.tools import to_png
|
||||
|
||||
if TYPE_CHECKING: # pragma: nocover
|
||||
from collections.abc import Callable, Iterator
|
||||
|
||||
from mss.models import Monitor, Monitors
|
||||
|
||||
try:
|
||||
from datetime import UTC
|
||||
except ImportError: # pragma: nocover
|
||||
# Python < 3.11
|
||||
from datetime import timezone
|
||||
|
||||
UTC = timezone.utc
|
||||
|
||||
lock = Lock()
|
||||
|
||||
OPAQUE = 255
|
||||
|
||||
|
||||
class MSSBase(metaclass=ABCMeta):
|
||||
"""This class will be overloaded by a system specific one."""
|
||||
|
||||
__slots__ = {"_monitors", "cls_image", "compression_level", "with_cursor"}
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
/,
|
||||
*,
|
||||
compression_level: int = 6,
|
||||
with_cursor: bool = False,
|
||||
# Linux only
|
||||
display: bytes | str | None = None, # noqa: ARG002
|
||||
# Mac only
|
||||
max_displays: int = 32, # noqa: ARG002
|
||||
) -> None:
|
||||
self.cls_image: type[ScreenShot] = ScreenShot
|
||||
self.compression_level = compression_level
|
||||
self.with_cursor = with_cursor
|
||||
self._monitors: Monitors = []
|
||||
|
||||
def __enter__(self) -> MSSBase: # noqa:PYI034
|
||||
"""For the cool call `with MSS() as mss:`."""
|
||||
return self
|
||||
|
||||
def __exit__(self, *_: object) -> None:
|
||||
"""For the cool call `with MSS() as mss:`."""
|
||||
self.close()
|
||||
|
||||
@abstractmethod
|
||||
def _cursor_impl(self) -> ScreenShot | None:
|
||||
"""Retrieve all cursor data. Pixels have to be RGB."""
|
||||
|
||||
@abstractmethod
|
||||
def _grab_impl(self, monitor: Monitor, /) -> ScreenShot:
|
||||
"""Retrieve all pixels from a monitor. Pixels have to be RGB.
|
||||
That method has to be run using a threading lock.
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def _monitors_impl(self) -> None:
|
||||
"""Get positions of monitors (has to be run using a threading lock).
|
||||
It must populate self._monitors.
|
||||
"""
|
||||
|
||||
def close(self) -> None: # noqa:B027
|
||||
"""Clean-up."""
|
||||
|
||||
def grab(self, monitor: Monitor | tuple[int, int, int, int], /) -> ScreenShot:
|
||||
"""Retrieve screen pixels for a given monitor.
|
||||
|
||||
Note: *monitor* can be a tuple like the one PIL.Image.grab() accepts.
|
||||
|
||||
:param monitor: The coordinates and size of the box to capture.
|
||||
See :meth:`monitors <monitors>` for object details.
|
||||
:return :class:`ScreenShot <ScreenShot>`.
|
||||
"""
|
||||
# Convert PIL bbox style
|
||||
if isinstance(monitor, tuple):
|
||||
monitor = {
|
||||
"left": monitor[0],
|
||||
"top": monitor[1],
|
||||
"width": monitor[2] - monitor[0],
|
||||
"height": monitor[3] - monitor[1],
|
||||
}
|
||||
|
||||
with lock:
|
||||
screenshot = self._grab_impl(monitor)
|
||||
if self.with_cursor and (cursor := self._cursor_impl()):
|
||||
return self._merge(screenshot, cursor)
|
||||
return screenshot
|
||||
|
||||
@property
|
||||
def monitors(self) -> Monitors:
|
||||
"""Get positions of all monitors.
|
||||
If the monitor has rotation, you have to deal with it
|
||||
inside this method.
|
||||
|
||||
This method has to fill self._monitors with all information
|
||||
and use it as a cache:
|
||||
self._monitors[0] is a dict of all monitors together
|
||||
self._monitors[N] is a dict of the monitor N (with N > 0)
|
||||
|
||||
Each monitor is a dict with:
|
||||
{
|
||||
'left': the x-coordinate of the upper-left corner,
|
||||
'top': the y-coordinate of the upper-left corner,
|
||||
'width': the width,
|
||||
'height': the height
|
||||
}
|
||||
"""
|
||||
if not self._monitors:
|
||||
with lock:
|
||||
self._monitors_impl()
|
||||
|
||||
return self._monitors
|
||||
|
||||
def save(
|
||||
self,
|
||||
/,
|
||||
*,
|
||||
mon: int = 0,
|
||||
output: str = "monitor-{mon}.png",
|
||||
callback: Callable[[str], None] | None = None,
|
||||
) -> Iterator[str]:
|
||||
"""Grab a screenshot and save it to a file.
|
||||
|
||||
:param int mon: The monitor to screenshot (default=0).
|
||||
-1: grab one screenshot of all monitors
|
||||
0: grab one screenshot by monitor
|
||||
N: grab the screenshot of the monitor N
|
||||
|
||||
:param str output: The output filename.
|
||||
|
||||
It can take several keywords to customize the filename:
|
||||
- `{mon}`: the monitor number
|
||||
- `{top}`: the screenshot y-coordinate of the upper-left corner
|
||||
- `{left}`: the screenshot x-coordinate of the upper-left corner
|
||||
- `{width}`: the screenshot's width
|
||||
- `{height}`: the screenshot's height
|
||||
- `{date}`: the current date using the default formatter
|
||||
|
||||
As it is using the `format()` function, you can specify
|
||||
formatting options like `{date:%Y-%m-%s}`.
|
||||
|
||||
:param callable callback: Callback called before saving the
|
||||
screenshot to a file. Take the `output` argument as parameter.
|
||||
|
||||
:return generator: Created file(s).
|
||||
"""
|
||||
monitors = self.monitors
|
||||
if not monitors:
|
||||
msg = "No monitor found."
|
||||
raise ScreenShotError(msg)
|
||||
|
||||
if mon == 0:
|
||||
# One screenshot by monitor
|
||||
for idx, monitor in enumerate(monitors[1:], 1):
|
||||
fname = output.format(mon=idx, date=datetime.now(UTC) if "{date" in output else None, **monitor)
|
||||
if callable(callback):
|
||||
callback(fname)
|
||||
sct = self.grab(monitor)
|
||||
to_png(sct.rgb, sct.size, level=self.compression_level, output=fname)
|
||||
yield fname
|
||||
else:
|
||||
# A screenshot of all monitors together or
|
||||
# a screenshot of the monitor N.
|
||||
mon = 0 if mon == -1 else mon
|
||||
try:
|
||||
monitor = monitors[mon]
|
||||
except IndexError as exc:
|
||||
msg = f"Monitor {mon!r} does not exist."
|
||||
raise ScreenShotError(msg) from exc
|
||||
|
||||
output = output.format(mon=mon, date=datetime.now(UTC) if "{date" in output else None, **monitor)
|
||||
if callable(callback):
|
||||
callback(output)
|
||||
sct = self.grab(monitor)
|
||||
to_png(sct.rgb, sct.size, level=self.compression_level, output=output)
|
||||
yield output
|
||||
|
||||
def shot(self, /, **kwargs: Any) -> str:
|
||||
"""Helper to save the screenshot of the 1st monitor, by default.
|
||||
You can pass the same arguments as for ``save``.
|
||||
"""
|
||||
kwargs["mon"] = kwargs.get("mon", 1)
|
||||
return next(self.save(**kwargs))
|
||||
|
||||
@staticmethod
|
||||
def _merge(screenshot: ScreenShot, cursor: ScreenShot, /) -> ScreenShot:
|
||||
"""Create composite image by blending screenshot and mouse cursor."""
|
||||
(cx, cy), (cw, ch) = cursor.pos, cursor.size
|
||||
(x, y), (w, h) = screenshot.pos, screenshot.size
|
||||
|
||||
cx2, cy2 = cx + cw, cy + ch
|
||||
x2, y2 = x + w, y + h
|
||||
|
||||
overlap = cx < x2 and cx2 > x and cy < y2 and cy2 > y
|
||||
if not overlap:
|
||||
return screenshot
|
||||
|
||||
screen_raw = screenshot.raw
|
||||
cursor_raw = cursor.raw
|
||||
|
||||
cy, cy2 = (cy - y) * 4, (cy2 - y2) * 4
|
||||
cx, cx2 = (cx - x) * 4, (cx2 - x2) * 4
|
||||
start_count_y = -cy if cy < 0 else 0
|
||||
start_count_x = -cx if cx < 0 else 0
|
||||
stop_count_y = ch * 4 - max(cy2, 0)
|
||||
stop_count_x = cw * 4 - max(cx2, 0)
|
||||
rgb = range(3)
|
||||
|
||||
for count_y in range(start_count_y, stop_count_y, 4):
|
||||
pos_s = (count_y + cy) * w + cx
|
||||
pos_c = count_y * cw
|
||||
|
||||
for count_x in range(start_count_x, stop_count_x, 4):
|
||||
spos = pos_s + count_x
|
||||
cpos = pos_c + count_x
|
||||
alpha = cursor_raw[cpos + 3]
|
||||
|
||||
if not alpha:
|
||||
continue
|
||||
|
||||
if alpha == OPAQUE:
|
||||
screen_raw[spos : spos + 3] = cursor_raw[cpos : cpos + 3]
|
||||
else:
|
||||
alpha2 = alpha / 255
|
||||
for i in rgb:
|
||||
screen_raw[spos + i] = int(cursor_raw[cpos + i] * alpha2 + screen_raw[spos + i] * (1 - alpha2))
|
||||
|
||||
return screenshot
|
||||
|
||||
@staticmethod
|
||||
def _cfactory(
|
||||
attr: Any,
|
||||
func: str,
|
||||
argtypes: list[Any],
|
||||
restype: Any,
|
||||
/,
|
||||
errcheck: Callable | None = None,
|
||||
) -> None:
|
||||
"""Factory to create a ctypes function and automatically manage errors."""
|
||||
meth = getattr(attr, func)
|
||||
meth.argtypes = argtypes
|
||||
meth.restype = restype
|
||||
if errcheck:
|
||||
meth.errcheck = errcheck
|
||||
@@ -0,0 +1,217 @@
|
||||
"""This is part of the MSS Python's module.
|
||||
Source: https://github.com/BoboTiG/python-mss.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import ctypes
|
||||
import ctypes.util
|
||||
import sys
|
||||
from ctypes import POINTER, Structure, c_double, c_float, c_int32, c_ubyte, c_uint32, c_uint64, c_void_p
|
||||
from platform import mac_ver
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from mss.base import MSSBase
|
||||
from mss.exception import ScreenShotError
|
||||
from mss.screenshot import ScreenShot, Size
|
||||
|
||||
if TYPE_CHECKING: # pragma: nocover
|
||||
from mss.models import CFunctions, Monitor
|
||||
|
||||
__all__ = ("MSS",)
|
||||
|
||||
MAC_VERSION_CATALINA = 10.16
|
||||
|
||||
kCGWindowImageBoundsIgnoreFraming = 1 << 0 # noqa: N816
|
||||
kCGWindowImageNominalResolution = 1 << 4 # noqa: N816
|
||||
kCGWindowImageShouldBeOpaque = 1 << 1 # noqa: N816
|
||||
# Note: set `IMAGE_OPTIONS = 0` to turn on scaling (see issue #257 for more information)
|
||||
IMAGE_OPTIONS = kCGWindowImageBoundsIgnoreFraming | kCGWindowImageShouldBeOpaque | kCGWindowImageNominalResolution
|
||||
|
||||
|
||||
def cgfloat() -> type[c_double | c_float]:
|
||||
"""Get the appropriate value for a float."""
|
||||
return c_double if sys.maxsize > 2**32 else c_float
|
||||
|
||||
|
||||
class CGPoint(Structure):
|
||||
"""Structure that contains coordinates of a rectangle."""
|
||||
|
||||
_fields_ = (("x", cgfloat()), ("y", cgfloat()))
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"{type(self).__name__}(left={self.x} top={self.y})"
|
||||
|
||||
|
||||
class CGSize(Structure):
|
||||
"""Structure that contains dimensions of an rectangle."""
|
||||
|
||||
_fields_ = (("width", cgfloat()), ("height", cgfloat()))
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"{type(self).__name__}(width={self.width} height={self.height})"
|
||||
|
||||
|
||||
class CGRect(Structure):
|
||||
"""Structure that contains information about a rectangle."""
|
||||
|
||||
_fields_ = (("origin", CGPoint), ("size", CGSize))
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"{type(self).__name__}<{self.origin} {self.size}>"
|
||||
|
||||
|
||||
# C functions that will be initialised later.
|
||||
#
|
||||
# Available attr: core.
|
||||
#
|
||||
# Note: keep it sorted by cfunction.
|
||||
CFUNCTIONS: CFunctions = {
|
||||
# Syntax: cfunction: (attr, argtypes, restype)
|
||||
"CGDataProviderCopyData": ("core", [c_void_p], c_void_p),
|
||||
"CGDisplayBounds": ("core", [c_uint32], CGRect),
|
||||
"CGDisplayRotation": ("core", [c_uint32], c_float),
|
||||
"CFDataGetBytePtr": ("core", [c_void_p], c_void_p),
|
||||
"CFDataGetLength": ("core", [c_void_p], c_uint64),
|
||||
"CFRelease": ("core", [c_void_p], c_void_p),
|
||||
"CGDataProviderRelease": ("core", [c_void_p], c_void_p),
|
||||
"CGGetActiveDisplayList": ("core", [c_uint32, POINTER(c_uint32), POINTER(c_uint32)], c_int32),
|
||||
"CGImageGetBitsPerPixel": ("core", [c_void_p], int),
|
||||
"CGImageGetBytesPerRow": ("core", [c_void_p], int),
|
||||
"CGImageGetDataProvider": ("core", [c_void_p], c_void_p),
|
||||
"CGImageGetHeight": ("core", [c_void_p], int),
|
||||
"CGImageGetWidth": ("core", [c_void_p], int),
|
||||
"CGRectStandardize": ("core", [CGRect], CGRect),
|
||||
"CGRectUnion": ("core", [CGRect, CGRect], CGRect),
|
||||
"CGWindowListCreateImage": ("core", [CGRect, c_uint32, c_uint32, c_uint32], c_void_p),
|
||||
}
|
||||
|
||||
|
||||
class MSS(MSSBase):
|
||||
"""Multiple ScreenShots implementation for macOS.
|
||||
It uses intensively the CoreGraphics library.
|
||||
"""
|
||||
|
||||
__slots__ = {"core", "max_displays"}
|
||||
|
||||
def __init__(self, /, **kwargs: Any) -> None:
|
||||
"""MacOS initialisations."""
|
||||
super().__init__(**kwargs)
|
||||
|
||||
self.max_displays = kwargs.get("max_displays", 32)
|
||||
|
||||
self._init_library()
|
||||
self._set_cfunctions()
|
||||
|
||||
def _init_library(self) -> None:
|
||||
"""Load the CoreGraphics library."""
|
||||
version = float(".".join(mac_ver()[0].split(".")[:2]))
|
||||
if version < MAC_VERSION_CATALINA:
|
||||
coregraphics = ctypes.util.find_library("CoreGraphics")
|
||||
else:
|
||||
# macOS Big Sur and newer
|
||||
coregraphics = "/System/Library/Frameworks/CoreGraphics.framework/Versions/Current/CoreGraphics"
|
||||
|
||||
if not coregraphics:
|
||||
msg = "No CoreGraphics library found."
|
||||
raise ScreenShotError(msg)
|
||||
self.core = ctypes.cdll.LoadLibrary(coregraphics)
|
||||
|
||||
def _set_cfunctions(self) -> None:
|
||||
"""Set all ctypes functions and attach them to attributes."""
|
||||
cfactory = self._cfactory
|
||||
attrs = {"core": self.core}
|
||||
for func, (attr, argtypes, restype) in CFUNCTIONS.items():
|
||||
cfactory(attrs[attr], func, argtypes, restype)
|
||||
|
||||
def _monitors_impl(self) -> None:
|
||||
"""Get positions of monitors. It will populate self._monitors."""
|
||||
int_ = int
|
||||
core = self.core
|
||||
|
||||
# All monitors
|
||||
# We need to update the value with every single monitor found
|
||||
# using CGRectUnion. Else we will end with infinite values.
|
||||
all_monitors = CGRect()
|
||||
self._monitors.append({})
|
||||
|
||||
# Each monitor
|
||||
display_count = c_uint32(0)
|
||||
active_displays = (c_uint32 * self.max_displays)()
|
||||
core.CGGetActiveDisplayList(self.max_displays, active_displays, ctypes.byref(display_count))
|
||||
for idx in range(display_count.value):
|
||||
display = active_displays[idx]
|
||||
rect = core.CGDisplayBounds(display)
|
||||
rect = core.CGRectStandardize(rect)
|
||||
width, height = rect.size.width, rect.size.height
|
||||
|
||||
# 0.0: normal
|
||||
# 90.0: right
|
||||
# -90.0: left
|
||||
if core.CGDisplayRotation(display) in {90.0, -90.0}:
|
||||
width, height = height, width
|
||||
|
||||
self._monitors.append(
|
||||
{
|
||||
"left": int_(rect.origin.x),
|
||||
"top": int_(rect.origin.y),
|
||||
"width": int_(width),
|
||||
"height": int_(height),
|
||||
},
|
||||
)
|
||||
|
||||
# Update AiO monitor's values
|
||||
all_monitors = core.CGRectUnion(all_monitors, rect)
|
||||
|
||||
# Set the AiO monitor's values
|
||||
self._monitors[0] = {
|
||||
"left": int_(all_monitors.origin.x),
|
||||
"top": int_(all_monitors.origin.y),
|
||||
"width": int_(all_monitors.size.width),
|
||||
"height": int_(all_monitors.size.height),
|
||||
}
|
||||
|
||||
def _grab_impl(self, monitor: Monitor, /) -> ScreenShot:
|
||||
"""Retrieve all pixels from a monitor. Pixels have to be RGB."""
|
||||
core = self.core
|
||||
rect = CGRect((monitor["left"], monitor["top"]), (monitor["width"], monitor["height"]))
|
||||
|
||||
image_ref = core.CGWindowListCreateImage(rect, 1, 0, IMAGE_OPTIONS)
|
||||
if not image_ref:
|
||||
msg = "CoreGraphics.CGWindowListCreateImage() failed."
|
||||
raise ScreenShotError(msg)
|
||||
|
||||
width = core.CGImageGetWidth(image_ref)
|
||||
height = core.CGImageGetHeight(image_ref)
|
||||
prov = copy_data = None
|
||||
try:
|
||||
prov = core.CGImageGetDataProvider(image_ref)
|
||||
copy_data = core.CGDataProviderCopyData(prov)
|
||||
data_ref = core.CFDataGetBytePtr(copy_data)
|
||||
buf_len = core.CFDataGetLength(copy_data)
|
||||
raw = ctypes.cast(data_ref, POINTER(c_ubyte * buf_len))
|
||||
data = bytearray(raw.contents)
|
||||
|
||||
# Remove padding per row
|
||||
bytes_per_row = core.CGImageGetBytesPerRow(image_ref)
|
||||
bytes_per_pixel = core.CGImageGetBitsPerPixel(image_ref)
|
||||
bytes_per_pixel = (bytes_per_pixel + 7) // 8
|
||||
|
||||
if bytes_per_pixel * width != bytes_per_row:
|
||||
cropped = bytearray()
|
||||
for row in range(height):
|
||||
start = row * bytes_per_row
|
||||
end = start + width * bytes_per_pixel
|
||||
cropped.extend(data[start:end])
|
||||
data = cropped
|
||||
finally:
|
||||
if prov:
|
||||
core.CGDataProviderRelease(prov)
|
||||
if copy_data:
|
||||
core.CFRelease(copy_data)
|
||||
|
||||
return self.cls_image(data, monitor, size=Size(width, height))
|
||||
|
||||
def _cursor_impl(self) -> ScreenShot | None:
|
||||
"""Retrieve all cursor data. Pixels have to be RGB."""
|
||||
return None
|
||||
@@ -0,0 +1,15 @@
|
||||
"""This is part of the MSS Python's module.
|
||||
Source: https://github.com/BoboTiG/python-mss.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
|
||||
class ScreenShotError(Exception):
|
||||
"""Error handling class."""
|
||||
|
||||
def __init__(self, message: str, /, *, details: dict[str, Any] | None = None) -> None:
|
||||
super().__init__(message)
|
||||
self.details = details or {}
|
||||
@@ -0,0 +1,40 @@
|
||||
"""This is part of the MSS Python's module.
|
||||
Source: https://github.com/BoboTiG/python-mss.
|
||||
"""
|
||||
|
||||
import platform
|
||||
from typing import Any
|
||||
|
||||
from mss.base import MSSBase
|
||||
from mss.exception import ScreenShotError
|
||||
|
||||
|
||||
def mss(**kwargs: Any) -> MSSBase:
|
||||
"""Factory returning a proper MSS class instance.
|
||||
|
||||
It detects the platform we are running on
|
||||
and chooses the most adapted mss_class to take
|
||||
screenshots.
|
||||
|
||||
It then proxies its arguments to the class for
|
||||
instantiation.
|
||||
"""
|
||||
os_ = platform.system().lower()
|
||||
|
||||
if os_ == "darwin":
|
||||
from mss import darwin # noqa: PLC0415
|
||||
|
||||
return darwin.MSS(**kwargs)
|
||||
|
||||
if os_ == "linux":
|
||||
from mss import linux # noqa: PLC0415
|
||||
|
||||
return linux.MSS(**kwargs)
|
||||
|
||||
if os_ == "windows":
|
||||
from mss import windows # noqa: PLC0415
|
||||
|
||||
return windows.MSS(**kwargs)
|
||||
|
||||
msg = f"System {os_!r} not (yet?) implemented."
|
||||
raise ScreenShotError(msg)
|
||||
@@ -0,0 +1,481 @@
|
||||
"""This is part of the MSS Python's module.
|
||||
Source: https://github.com/BoboTiG/python-mss.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from contextlib import suppress
|
||||
from ctypes import (
|
||||
CFUNCTYPE,
|
||||
POINTER,
|
||||
Structure,
|
||||
byref,
|
||||
c_char_p,
|
||||
c_int,
|
||||
c_int32,
|
||||
c_long,
|
||||
c_short,
|
||||
c_ubyte,
|
||||
c_uint,
|
||||
c_uint32,
|
||||
c_ulong,
|
||||
c_ushort,
|
||||
c_void_p,
|
||||
cast,
|
||||
cdll,
|
||||
create_string_buffer,
|
||||
)
|
||||
from ctypes.util import find_library
|
||||
from threading import current_thread, local
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from mss.base import MSSBase, lock
|
||||
from mss.exception import ScreenShotError
|
||||
|
||||
if TYPE_CHECKING: # pragma: nocover
|
||||
from mss.models import CFunctions, Monitor
|
||||
from mss.screenshot import ScreenShot
|
||||
|
||||
__all__ = ("MSS",)
|
||||
|
||||
|
||||
PLAINMASK = 0x00FFFFFF
|
||||
ZPIXMAP = 2
|
||||
BITS_PER_PIXELS_32 = 32
|
||||
SUPPORTED_BITS_PER_PIXELS = {
|
||||
BITS_PER_PIXELS_32,
|
||||
}
|
||||
|
||||
|
||||
class Display(Structure):
|
||||
"""Structure that serves as the connection to the X server
|
||||
and that contains all the information about that X server.
|
||||
https://github.com/garrybodsworth/pyxlib-ctypes/blob/master/pyxlib/xlib.py#L831.
|
||||
"""
|
||||
|
||||
|
||||
class XErrorEvent(Structure):
|
||||
"""XErrorEvent to debug eventual errors.
|
||||
https://tronche.com/gui/x/xlib/event-handling/protocol-errors/default-handlers.html.
|
||||
"""
|
||||
|
||||
_fields_ = (
|
||||
("type", c_int),
|
||||
("display", POINTER(Display)), # Display the event was read from
|
||||
("serial", c_ulong), # serial number of failed request
|
||||
("error_code", c_ubyte), # error code of failed request
|
||||
("request_code", c_ubyte), # major op-code of failed request
|
||||
("minor_code", c_ubyte), # minor op-code of failed request
|
||||
("resourceid", c_void_p), # resource ID
|
||||
)
|
||||
|
||||
|
||||
class XFixesCursorImage(Structure):
|
||||
"""Cursor structure.
|
||||
/usr/include/X11/extensions/Xfixes.h
|
||||
https://github.com/freedesktop/xorg-libXfixes/blob/libXfixes-6.0.0/include/X11/extensions/Xfixes.h#L96.
|
||||
"""
|
||||
|
||||
_fields_ = (
|
||||
("x", c_short),
|
||||
("y", c_short),
|
||||
("width", c_ushort),
|
||||
("height", c_ushort),
|
||||
("xhot", c_ushort),
|
||||
("yhot", c_ushort),
|
||||
("cursor_serial", c_ulong),
|
||||
("pixels", POINTER(c_ulong)),
|
||||
("atom", c_ulong),
|
||||
("name", c_char_p),
|
||||
)
|
||||
|
||||
|
||||
class XImage(Structure):
|
||||
"""Description of an image as it exists in the client's memory.
|
||||
https://tronche.com/gui/x/xlib/graphics/images.html.
|
||||
"""
|
||||
|
||||
_fields_ = (
|
||||
("width", c_int), # size of image
|
||||
("height", c_int), # size of image
|
||||
("xoffset", c_int), # number of pixels offset in X direction
|
||||
("format", c_int), # XYBitmap, XYPixmap, ZPixmap
|
||||
("data", c_void_p), # pointer to image data
|
||||
("byte_order", c_int), # data byte order, LSBFirst, MSBFirst
|
||||
("bitmap_unit", c_int), # quant. of scanline 8, 16, 32
|
||||
("bitmap_bit_order", c_int), # LSBFirst, MSBFirst
|
||||
("bitmap_pad", c_int), # 8, 16, 32 either XY or ZPixmap
|
||||
("depth", c_int), # depth of image
|
||||
("bytes_per_line", c_int), # accelerator to next line
|
||||
("bits_per_pixel", c_int), # bits per pixel (ZPixmap)
|
||||
("red_mask", c_ulong), # bits in z arrangement
|
||||
("green_mask", c_ulong), # bits in z arrangement
|
||||
("blue_mask", c_ulong), # bits in z arrangement
|
||||
)
|
||||
|
||||
|
||||
class XRRCrtcInfo(Structure):
|
||||
"""Structure that contains CRTC information.
|
||||
https://gitlab.freedesktop.org/xorg/lib/libxrandr/-/blob/master/include/X11/extensions/Xrandr.h#L360.
|
||||
"""
|
||||
|
||||
_fields_ = (
|
||||
("timestamp", c_ulong),
|
||||
("x", c_int),
|
||||
("y", c_int),
|
||||
("width", c_uint),
|
||||
("height", c_uint),
|
||||
("mode", c_long),
|
||||
("rotation", c_int),
|
||||
("noutput", c_int),
|
||||
("outputs", POINTER(c_long)),
|
||||
("rotations", c_ushort),
|
||||
("npossible", c_int),
|
||||
("possible", POINTER(c_long)),
|
||||
)
|
||||
|
||||
|
||||
class XRRModeInfo(Structure):
|
||||
"""https://gitlab.freedesktop.org/xorg/lib/libxrandr/-/blob/master/include/X11/extensions/Xrandr.h#L248."""
|
||||
|
||||
|
||||
class XRRScreenResources(Structure):
|
||||
"""Structure that contains arrays of XIDs that point to the
|
||||
available outputs and associated CRTCs.
|
||||
https://gitlab.freedesktop.org/xorg/lib/libxrandr/-/blob/master/include/X11/extensions/Xrandr.h#L265.
|
||||
"""
|
||||
|
||||
_fields_ = (
|
||||
("timestamp", c_ulong),
|
||||
("configTimestamp", c_ulong),
|
||||
("ncrtc", c_int),
|
||||
("crtcs", POINTER(c_long)),
|
||||
("noutput", c_int),
|
||||
("outputs", POINTER(c_long)),
|
||||
("nmode", c_int),
|
||||
("modes", POINTER(XRRModeInfo)),
|
||||
)
|
||||
|
||||
|
||||
class XWindowAttributes(Structure):
|
||||
"""Attributes for the specified window."""
|
||||
|
||||
_fields_ = (
|
||||
("x", c_int32), # location of window
|
||||
("y", c_int32), # location of window
|
||||
("width", c_int32), # width of window
|
||||
("height", c_int32), # height of window
|
||||
("border_width", c_int32), # border width of window
|
||||
("depth", c_int32), # depth of window
|
||||
("visual", c_ulong), # the associated visual structure
|
||||
("root", c_ulong), # root of screen containing window
|
||||
("class", c_int32), # InputOutput, InputOnly
|
||||
("bit_gravity", c_int32), # one of bit gravity values
|
||||
("win_gravity", c_int32), # one of the window gravity values
|
||||
("backing_store", c_int32), # NotUseful, WhenMapped, Always
|
||||
("backing_planes", c_ulong), # planes to be preserved if possible
|
||||
("backing_pixel", c_ulong), # value to be used when restoring planes
|
||||
("save_under", c_int32), # boolean, should bits under be saved?
|
||||
("colormap", c_ulong), # color map to be associated with window
|
||||
("mapinstalled", c_uint32), # boolean, is color map currently installed
|
||||
("map_state", c_uint32), # IsUnmapped, IsUnviewable, IsViewable
|
||||
("all_event_masks", c_ulong), # set of events all people have interest in
|
||||
("your_event_mask", c_ulong), # my event mask
|
||||
("do_not_propagate_mask", c_ulong), # set of events that should not propagate
|
||||
("override_redirect", c_int32), # boolean value for override-redirect
|
||||
("screen", c_ulong), # back pointer to correct screen
|
||||
)
|
||||
|
||||
|
||||
_ERROR = {}
|
||||
_X11 = find_library("X11")
|
||||
_XFIXES = find_library("Xfixes")
|
||||
_XRANDR = find_library("Xrandr")
|
||||
|
||||
|
||||
@CFUNCTYPE(c_int, POINTER(Display), POINTER(XErrorEvent))
|
||||
def _error_handler(display: Display, event: XErrorEvent) -> int:
|
||||
"""Specifies the program's supplied error handler."""
|
||||
# Get the specific error message
|
||||
xlib = cdll.LoadLibrary(_X11) # type: ignore[arg-type]
|
||||
get_error = xlib.XGetErrorText
|
||||
get_error.argtypes = [POINTER(Display), c_int, c_char_p, c_int]
|
||||
get_error.restype = c_void_p
|
||||
|
||||
evt = event.contents
|
||||
error = create_string_buffer(1024)
|
||||
get_error(display, evt.error_code, error, len(error))
|
||||
|
||||
_ERROR[current_thread()] = {
|
||||
"error": error.value.decode("utf-8"),
|
||||
"error_code": evt.error_code,
|
||||
"minor_code": evt.minor_code,
|
||||
"request_code": evt.request_code,
|
||||
"serial": evt.serial,
|
||||
"type": evt.type,
|
||||
}
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
def _validate(retval: int, func: Any, args: tuple[Any, Any], /) -> tuple[Any, Any]:
|
||||
"""Validate the returned value of a C function call."""
|
||||
thread = current_thread()
|
||||
if retval != 0 and thread not in _ERROR:
|
||||
return args
|
||||
|
||||
details = _ERROR.pop(thread, {})
|
||||
msg = f"{func.__name__}() failed"
|
||||
raise ScreenShotError(msg, details=details)
|
||||
|
||||
|
||||
# C functions that will be initialised later.
|
||||
# See https://tronche.com/gui/x/xlib/function-index.html for details.
|
||||
#
|
||||
# Available attr: xfixes, xlib, xrandr.
|
||||
#
|
||||
# Note: keep it sorted by cfunction.
|
||||
CFUNCTIONS: CFunctions = {
|
||||
# Syntax: cfunction: (attr, argtypes, restype)
|
||||
"XCloseDisplay": ("xlib", [POINTER(Display)], c_void_p),
|
||||
"XDefaultRootWindow": ("xlib", [POINTER(Display)], POINTER(XWindowAttributes)),
|
||||
"XDestroyImage": ("xlib", [POINTER(XImage)], c_void_p),
|
||||
"XFixesGetCursorImage": ("xfixes", [POINTER(Display)], POINTER(XFixesCursorImage)),
|
||||
"XGetImage": (
|
||||
"xlib",
|
||||
[POINTER(Display), POINTER(Display), c_int, c_int, c_uint, c_uint, c_ulong, c_int],
|
||||
POINTER(XImage),
|
||||
),
|
||||
"XGetWindowAttributes": ("xlib", [POINTER(Display), POINTER(XWindowAttributes), POINTER(XWindowAttributes)], c_int),
|
||||
"XOpenDisplay": ("xlib", [c_char_p], POINTER(Display)),
|
||||
"XQueryExtension": ("xlib", [POINTER(Display), c_char_p, POINTER(c_int), POINTER(c_int), POINTER(c_int)], c_uint),
|
||||
"XRRFreeCrtcInfo": ("xrandr", [POINTER(XRRCrtcInfo)], c_void_p),
|
||||
"XRRFreeScreenResources": ("xrandr", [POINTER(XRRScreenResources)], c_void_p),
|
||||
"XRRGetCrtcInfo": ("xrandr", [POINTER(Display), POINTER(XRRScreenResources), c_long], POINTER(XRRCrtcInfo)),
|
||||
"XRRGetScreenResources": ("xrandr", [POINTER(Display), POINTER(Display)], POINTER(XRRScreenResources)),
|
||||
"XRRGetScreenResourcesCurrent": ("xrandr", [POINTER(Display), POINTER(Display)], POINTER(XRRScreenResources)),
|
||||
"XSetErrorHandler": ("xlib", [c_void_p], c_void_p),
|
||||
}
|
||||
|
||||
|
||||
class MSS(MSSBase):
|
||||
"""Multiple ScreenShots implementation for GNU/Linux.
|
||||
It uses intensively the Xlib and its Xrandr extension.
|
||||
"""
|
||||
|
||||
__slots__ = {"_handles", "xfixes", "xlib", "xrandr"}
|
||||
|
||||
def __init__(self, /, **kwargs: Any) -> None:
|
||||
"""GNU/Linux initialisations."""
|
||||
super().__init__(**kwargs)
|
||||
|
||||
# Available thread-specific variables
|
||||
self._handles = local()
|
||||
self._handles.display = None
|
||||
self._handles.drawable = None
|
||||
self._handles.original_error_handler = None
|
||||
self._handles.root = None
|
||||
|
||||
display = kwargs.get("display", b"")
|
||||
if not display:
|
||||
try:
|
||||
display = os.environ["DISPLAY"].encode("utf-8")
|
||||
except KeyError:
|
||||
msg = "$DISPLAY not set."
|
||||
raise ScreenShotError(msg) from None
|
||||
|
||||
if not isinstance(display, bytes):
|
||||
display = display.encode("utf-8")
|
||||
|
||||
if b":" not in display:
|
||||
msg = f"Bad display value: {display!r}."
|
||||
raise ScreenShotError(msg)
|
||||
|
||||
if not _X11:
|
||||
msg = "No X11 library found."
|
||||
raise ScreenShotError(msg)
|
||||
self.xlib = cdll.LoadLibrary(_X11)
|
||||
|
||||
if not _XRANDR:
|
||||
msg = "No Xrandr extension found."
|
||||
raise ScreenShotError(msg)
|
||||
self.xrandr = cdll.LoadLibrary(_XRANDR)
|
||||
|
||||
if self.with_cursor:
|
||||
if _XFIXES:
|
||||
self.xfixes = cdll.LoadLibrary(_XFIXES)
|
||||
else:
|
||||
self.with_cursor = False
|
||||
|
||||
self._set_cfunctions()
|
||||
|
||||
# Install the error handler to prevent interpreter crashes: any error will raise a ScreenShotError exception
|
||||
self._handles.original_error_handler = self.xlib.XSetErrorHandler(_error_handler)
|
||||
|
||||
self._handles.display = self.xlib.XOpenDisplay(display)
|
||||
if not self._handles.display:
|
||||
msg = f"Unable to open display: {display!r}."
|
||||
raise ScreenShotError(msg)
|
||||
|
||||
if not self._is_extension_enabled("RANDR"):
|
||||
msg = "Xrandr not enabled."
|
||||
raise ScreenShotError(msg)
|
||||
|
||||
self._handles.root = self.xlib.XDefaultRootWindow(self._handles.display)
|
||||
|
||||
# Fix for XRRGetScreenResources and XGetImage:
|
||||
# expected LP_Display instance instead of LP_XWindowAttributes
|
||||
self._handles.drawable = cast(self._handles.root, POINTER(Display))
|
||||
|
||||
def close(self) -> None:
|
||||
# Clean-up
|
||||
if self._handles.display:
|
||||
with lock:
|
||||
self.xlib.XCloseDisplay(self._handles.display)
|
||||
self._handles.display = None
|
||||
self._handles.drawable = None
|
||||
self._handles.root = None
|
||||
|
||||
# Remove our error handler
|
||||
if self._handles.original_error_handler:
|
||||
# It's required when exiting MSS to prevent letting `_error_handler()` as default handler.
|
||||
# Doing so would crash when using Tk/Tkinter, see issue #220.
|
||||
# Interesting technical stuff can be found here:
|
||||
# https://core.tcl-lang.org/tk/file?name=generic/tkError.c&ci=a527ef995862cb50
|
||||
# https://github.com/tcltk/tk/blob/b9cdafd83fe77499ff47fa373ce037aff3ae286a/generic/tkError.c
|
||||
self.xlib.XSetErrorHandler(self._handles.original_error_handler)
|
||||
self._handles.original_error_handler = None
|
||||
|
||||
# Also empty the error dict
|
||||
_ERROR.clear()
|
||||
|
||||
def _is_extension_enabled(self, name: str, /) -> bool:
|
||||
"""Return True if the given *extension* is enabled on the server."""
|
||||
major_opcode_return = c_int()
|
||||
first_event_return = c_int()
|
||||
first_error_return = c_int()
|
||||
|
||||
try:
|
||||
with lock:
|
||||
self.xlib.XQueryExtension(
|
||||
self._handles.display,
|
||||
name.encode("latin1"),
|
||||
byref(major_opcode_return),
|
||||
byref(first_event_return),
|
||||
byref(first_error_return),
|
||||
)
|
||||
except ScreenShotError:
|
||||
return False
|
||||
return True
|
||||
|
||||
def _set_cfunctions(self) -> None:
|
||||
"""Set all ctypes functions and attach them to attributes."""
|
||||
cfactory = self._cfactory
|
||||
attrs = {
|
||||
"xfixes": getattr(self, "xfixes", None),
|
||||
"xlib": self.xlib,
|
||||
"xrandr": self.xrandr,
|
||||
}
|
||||
for func, (attr, argtypes, restype) in CFUNCTIONS.items():
|
||||
with suppress(AttributeError):
|
||||
errcheck = None if func == "XSetErrorHandler" else _validate
|
||||
cfactory(attrs[attr], func, argtypes, restype, errcheck=errcheck)
|
||||
|
||||
def _monitors_impl(self) -> None:
|
||||
"""Get positions of monitors. It will populate self._monitors."""
|
||||
display = self._handles.display
|
||||
int_ = int
|
||||
xrandr = self.xrandr
|
||||
|
||||
# All monitors
|
||||
gwa = XWindowAttributes()
|
||||
self.xlib.XGetWindowAttributes(display, self._handles.root, byref(gwa))
|
||||
self._monitors.append(
|
||||
{"left": int_(gwa.x), "top": int_(gwa.y), "width": int_(gwa.width), "height": int_(gwa.height)},
|
||||
)
|
||||
|
||||
# Each monitor
|
||||
# A simple benchmark calling 10 times those 2 functions:
|
||||
# XRRGetScreenResources(): 0.1755971429956844 s
|
||||
# XRRGetScreenResourcesCurrent(): 0.0039125580078689 s
|
||||
# The second is faster by a factor of 44! So try to use it first.
|
||||
try:
|
||||
mon = xrandr.XRRGetScreenResourcesCurrent(display, self._handles.drawable).contents
|
||||
except AttributeError:
|
||||
mon = xrandr.XRRGetScreenResources(display, self._handles.drawable).contents
|
||||
|
||||
crtcs = mon.crtcs
|
||||
for idx in range(mon.ncrtc):
|
||||
crtc = xrandr.XRRGetCrtcInfo(display, mon, crtcs[idx]).contents
|
||||
if crtc.noutput == 0:
|
||||
xrandr.XRRFreeCrtcInfo(crtc)
|
||||
continue
|
||||
|
||||
self._monitors.append(
|
||||
{
|
||||
"left": int_(crtc.x),
|
||||
"top": int_(crtc.y),
|
||||
"width": int_(crtc.width),
|
||||
"height": int_(crtc.height),
|
||||
},
|
||||
)
|
||||
xrandr.XRRFreeCrtcInfo(crtc)
|
||||
xrandr.XRRFreeScreenResources(mon)
|
||||
|
||||
def _grab_impl(self, monitor: Monitor, /) -> ScreenShot:
|
||||
"""Retrieve all pixels from a monitor. Pixels have to be RGB."""
|
||||
ximage = self.xlib.XGetImage(
|
||||
self._handles.display,
|
||||
self._handles.drawable,
|
||||
monitor["left"],
|
||||
monitor["top"],
|
||||
monitor["width"],
|
||||
monitor["height"],
|
||||
PLAINMASK,
|
||||
ZPIXMAP,
|
||||
)
|
||||
|
||||
try:
|
||||
bits_per_pixel = ximage.contents.bits_per_pixel
|
||||
if bits_per_pixel not in SUPPORTED_BITS_PER_PIXELS:
|
||||
msg = f"[XImage] bits per pixel value not (yet?) implemented: {bits_per_pixel}."
|
||||
raise ScreenShotError(msg)
|
||||
|
||||
raw_data = cast(
|
||||
ximage.contents.data,
|
||||
POINTER(c_ubyte * monitor["height"] * monitor["width"] * 4),
|
||||
)
|
||||
data = bytearray(raw_data.contents)
|
||||
finally:
|
||||
# Free
|
||||
self.xlib.XDestroyImage(ximage)
|
||||
|
||||
return self.cls_image(data, monitor)
|
||||
|
||||
def _cursor_impl(self) -> ScreenShot:
|
||||
"""Retrieve all cursor data. Pixels have to be RGB."""
|
||||
# Read data of cursor/mouse-pointer
|
||||
ximage = self.xfixes.XFixesGetCursorImage(self._handles.display)
|
||||
if not (ximage and ximage.contents):
|
||||
msg = "Cannot read XFixesGetCursorImage()"
|
||||
raise ScreenShotError(msg)
|
||||
|
||||
cursor_img: XFixesCursorImage = ximage.contents
|
||||
region = {
|
||||
"left": cursor_img.x - cursor_img.xhot,
|
||||
"top": cursor_img.y - cursor_img.yhot,
|
||||
"width": cursor_img.width,
|
||||
"height": cursor_img.height,
|
||||
}
|
||||
|
||||
raw_data = cast(cursor_img.pixels, POINTER(c_ulong * region["height"] * region["width"]))
|
||||
raw = bytearray(raw_data.contents)
|
||||
|
||||
data = bytearray(region["height"] * region["width"] * 4)
|
||||
data[3::4] = raw[3::8]
|
||||
data[2::4] = raw[2::8]
|
||||
data[1::4] = raw[1::8]
|
||||
data[::4] = raw[::8]
|
||||
|
||||
return self.cls_image(data, region)
|
||||
@@ -0,0 +1,23 @@
|
||||
"""This is part of the MSS Python's module.
|
||||
Source: https://github.com/BoboTiG/python-mss.
|
||||
"""
|
||||
|
||||
from typing import Any, NamedTuple
|
||||
|
||||
Monitor = dict[str, int]
|
||||
Monitors = list[Monitor]
|
||||
|
||||
Pixel = tuple[int, int, int]
|
||||
Pixels = list[tuple[Pixel, ...]]
|
||||
|
||||
CFunctions = dict[str, tuple[str, list[Any], Any]]
|
||||
|
||||
|
||||
class Pos(NamedTuple):
|
||||
left: int
|
||||
top: int
|
||||
|
||||
|
||||
class Size(NamedTuple):
|
||||
width: int
|
||||
height: int
|
||||
@@ -0,0 +1,125 @@
|
||||
"""This is part of the MSS Python's module.
|
||||
Source: https://github.com/BoboTiG/python-mss.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from mss.exception import ScreenShotError
|
||||
from mss.models import Monitor, Pixel, Pixels, Pos, Size
|
||||
|
||||
if TYPE_CHECKING: # pragma: nocover
|
||||
from collections.abc import Iterator
|
||||
|
||||
|
||||
class ScreenShot:
|
||||
"""Screenshot object.
|
||||
|
||||
.. note::
|
||||
|
||||
A better name would have been *Image*, but to prevent collisions
|
||||
with PIL.Image, it has been decided to use *ScreenShot*.
|
||||
"""
|
||||
|
||||
__slots__ = {"__pixels", "__rgb", "pos", "raw", "size"}
|
||||
|
||||
def __init__(self, data: bytearray, monitor: Monitor, /, *, size: Size | None = None) -> None:
|
||||
self.__pixels: Pixels | None = None
|
||||
self.__rgb: bytes | None = None
|
||||
|
||||
#: Bytearray of the raw BGRA pixels retrieved by ctypes
|
||||
#: OS independent implementations.
|
||||
self.raw = data
|
||||
|
||||
#: NamedTuple of the screenshot coordinates.
|
||||
self.pos = Pos(monitor["left"], monitor["top"])
|
||||
|
||||
#: NamedTuple of the screenshot size.
|
||||
self.size = Size(monitor["width"], monitor["height"]) if size is None else size
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<{type(self).__name__} pos={self.left},{self.top} size={self.width}x{self.height}>"
|
||||
|
||||
@property
|
||||
def __array_interface__(self) -> dict[str, Any]:
|
||||
"""Numpy array interface support.
|
||||
It uses raw data in BGRA form.
|
||||
|
||||
See https://docs.scipy.org/doc/numpy/reference/arrays.interface.html
|
||||
"""
|
||||
return {
|
||||
"version": 3,
|
||||
"shape": (self.height, self.width, 4),
|
||||
"typestr": "|u1",
|
||||
"data": self.raw,
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def from_size(cls: type[ScreenShot], data: bytearray, width: int, height: int, /) -> ScreenShot:
|
||||
"""Instantiate a new class given only screenshot's data and size."""
|
||||
monitor = {"left": 0, "top": 0, "width": width, "height": height}
|
||||
return cls(data, monitor)
|
||||
|
||||
@property
|
||||
def bgra(self) -> bytes:
|
||||
"""BGRA values from the BGRA raw pixels."""
|
||||
return bytes(self.raw)
|
||||
|
||||
@property
|
||||
def height(self) -> int:
|
||||
"""Convenient accessor to the height size."""
|
||||
return self.size.height
|
||||
|
||||
@property
|
||||
def left(self) -> int:
|
||||
"""Convenient accessor to the left position."""
|
||||
return self.pos.left
|
||||
|
||||
@property
|
||||
def pixels(self) -> Pixels:
|
||||
""":return list: RGB tuples."""
|
||||
if not self.__pixels:
|
||||
rgb_tuples: Iterator[Pixel] = zip(self.raw[2::4], self.raw[1::4], self.raw[::4])
|
||||
self.__pixels = list(zip(*[iter(rgb_tuples)] * self.width))
|
||||
|
||||
return self.__pixels
|
||||
|
||||
@property
|
||||
def rgb(self) -> bytes:
|
||||
"""Compute RGB values from the BGRA raw pixels.
|
||||
|
||||
:return bytes: RGB pixels.
|
||||
"""
|
||||
if not self.__rgb:
|
||||
rgb = bytearray(self.height * self.width * 3)
|
||||
raw = self.raw
|
||||
rgb[::3] = raw[2::4]
|
||||
rgb[1::3] = raw[1::4]
|
||||
rgb[2::3] = raw[::4]
|
||||
self.__rgb = bytes(rgb)
|
||||
|
||||
return self.__rgb
|
||||
|
||||
@property
|
||||
def top(self) -> int:
|
||||
"""Convenient accessor to the top position."""
|
||||
return self.pos.top
|
||||
|
||||
@property
|
||||
def width(self) -> int:
|
||||
"""Convenient accessor to the width size."""
|
||||
return self.size.width
|
||||
|
||||
def pixel(self, coord_x: int, coord_y: int) -> Pixel:
|
||||
"""Returns the pixel value at a given position.
|
||||
|
||||
:param int coord_x: The x coordinate.
|
||||
:param int coord_y: The y coordinate.
|
||||
:return tuple: The pixel value as (R, G, B).
|
||||
"""
|
||||
try:
|
||||
return self.pixels[coord_y][coord_x]
|
||||
except IndexError as exc:
|
||||
msg = f"Pixel location ({coord_x}, {coord_y}) is out of range."
|
||||
raise ScreenShotError(msg) from exc
|
||||
@@ -0,0 +1,65 @@
|
||||
"""This is part of the MSS Python's module.
|
||||
Source: https://github.com/BoboTiG/python-mss.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import struct
|
||||
import zlib
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def to_png(data: bytes, size: tuple[int, int], /, *, level: int = 6, output: Path | str | None = None) -> bytes | None:
|
||||
"""Dump data to a PNG file. If `output` is `None`, create no file but return
|
||||
the whole PNG data.
|
||||
|
||||
:param bytes data: RGBRGB...RGB data.
|
||||
:param tuple size: The (width, height) pair.
|
||||
:param int level: PNG compression level.
|
||||
:param str output: Output file name.
|
||||
"""
|
||||
pack = struct.pack
|
||||
crc32 = zlib.crc32
|
||||
|
||||
width, height = size
|
||||
line = width * 3
|
||||
png_filter = pack(">B", 0)
|
||||
scanlines = b"".join([png_filter + data[y * line : y * line + line] for y in range(height)])
|
||||
|
||||
magic = pack(">8B", 137, 80, 78, 71, 13, 10, 26, 10)
|
||||
|
||||
# Header: size, marker, data, CRC32
|
||||
ihdr = [b"", b"IHDR", b"", b""]
|
||||
ihdr[2] = pack(">2I5B", width, height, 8, 2, 0, 0, 0)
|
||||
ihdr[3] = pack(">I", crc32(b"".join(ihdr[1:3])) & 0xFFFFFFFF)
|
||||
ihdr[0] = pack(">I", len(ihdr[2]))
|
||||
|
||||
# Data: size, marker, data, CRC32
|
||||
idat = [b"", b"IDAT", zlib.compress(scanlines, level), b""]
|
||||
idat[3] = pack(">I", crc32(b"".join(idat[1:3])) & 0xFFFFFFFF)
|
||||
idat[0] = pack(">I", len(idat[2]))
|
||||
|
||||
# Footer: size, marker, None, CRC32
|
||||
iend = [b"", b"IEND", b"", b""]
|
||||
iend[3] = pack(">I", crc32(iend[1]) & 0xFFFFFFFF)
|
||||
iend[0] = pack(">I", len(iend[2]))
|
||||
|
||||
if not output:
|
||||
# Returns raw bytes of the whole PNG data
|
||||
return magic + b"".join(ihdr + idat + iend)
|
||||
|
||||
with open(output, "wb") as fileh: # noqa: PTH123
|
||||
fileh.write(magic)
|
||||
fileh.write(b"".join(ihdr))
|
||||
fileh.write(b"".join(idat))
|
||||
fileh.write(b"".join(iend))
|
||||
|
||||
# Force write of file to disk
|
||||
fileh.flush()
|
||||
os.fsync(fileh.fileno())
|
||||
|
||||
return None
|
||||
@@ -0,0 +1,250 @@
|
||||
"""This is part of the MSS Python's module.
|
||||
Source: https://github.com/BoboTiG/python-mss.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import ctypes
|
||||
import sys
|
||||
from ctypes import POINTER, WINFUNCTYPE, Structure, c_int, c_void_p
|
||||
from ctypes.wintypes import (
|
||||
BOOL,
|
||||
DOUBLE,
|
||||
DWORD,
|
||||
HBITMAP,
|
||||
HDC,
|
||||
HGDIOBJ,
|
||||
HWND,
|
||||
INT,
|
||||
LONG,
|
||||
LPARAM,
|
||||
LPRECT,
|
||||
RECT,
|
||||
UINT,
|
||||
WORD,
|
||||
)
|
||||
from threading import local
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from mss.base import MSSBase
|
||||
from mss.exception import ScreenShotError
|
||||
|
||||
if TYPE_CHECKING: # pragma: nocover
|
||||
from mss.models import CFunctions, Monitor
|
||||
from mss.screenshot import ScreenShot
|
||||
|
||||
__all__ = ("MSS",)
|
||||
|
||||
|
||||
CAPTUREBLT = 0x40000000
|
||||
DIB_RGB_COLORS = 0
|
||||
SRCCOPY = 0x00CC0020
|
||||
|
||||
|
||||
class BITMAPINFOHEADER(Structure):
|
||||
"""Information about the dimensions and color format of a DIB."""
|
||||
|
||||
_fields_ = (
|
||||
("biSize", DWORD),
|
||||
("biWidth", LONG),
|
||||
("biHeight", LONG),
|
||||
("biPlanes", WORD),
|
||||
("biBitCount", WORD),
|
||||
("biCompression", DWORD),
|
||||
("biSizeImage", DWORD),
|
||||
("biXPelsPerMeter", LONG),
|
||||
("biYPelsPerMeter", LONG),
|
||||
("biClrUsed", DWORD),
|
||||
("biClrImportant", DWORD),
|
||||
)
|
||||
|
||||
|
||||
class BITMAPINFO(Structure):
|
||||
"""Structure that defines the dimensions and color information for a DIB."""
|
||||
|
||||
_fields_ = (("bmiHeader", BITMAPINFOHEADER), ("bmiColors", DWORD * 3))
|
||||
|
||||
|
||||
MONITORNUMPROC = WINFUNCTYPE(INT, DWORD, DWORD, POINTER(RECT), DOUBLE)
|
||||
|
||||
|
||||
# C functions that will be initialised later.
|
||||
#
|
||||
# Available attr: gdi32, user32.
|
||||
#
|
||||
# Note: keep it sorted by cfunction.
|
||||
CFUNCTIONS: CFunctions = {
|
||||
# Syntax: cfunction: (attr, argtypes, restype)
|
||||
"BitBlt": ("gdi32", [HDC, INT, INT, INT, INT, HDC, INT, INT, DWORD], BOOL),
|
||||
"CreateCompatibleBitmap": ("gdi32", [HDC, INT, INT], HBITMAP),
|
||||
"CreateCompatibleDC": ("gdi32", [HDC], HDC),
|
||||
"DeleteDC": ("gdi32", [HDC], HDC),
|
||||
"DeleteObject": ("gdi32", [HGDIOBJ], INT),
|
||||
"EnumDisplayMonitors": ("user32", [HDC, c_void_p, MONITORNUMPROC, LPARAM], BOOL),
|
||||
"GetDeviceCaps": ("gdi32", [HWND, INT], INT),
|
||||
"GetDIBits": ("gdi32", [HDC, HBITMAP, UINT, UINT, c_void_p, POINTER(BITMAPINFO), UINT], BOOL),
|
||||
"GetSystemMetrics": ("user32", [INT], INT),
|
||||
"GetWindowDC": ("user32", [HWND], HDC),
|
||||
"ReleaseDC": ("user32", [HWND, HDC], c_int),
|
||||
"SelectObject": ("gdi32", [HDC, HGDIOBJ], HGDIOBJ),
|
||||
}
|
||||
|
||||
|
||||
class MSS(MSSBase):
|
||||
"""Multiple ScreenShots implementation for Microsoft Windows."""
|
||||
|
||||
__slots__ = {"_handles", "gdi32", "user32"}
|
||||
|
||||
def __init__(self, /, **kwargs: Any) -> None:
|
||||
"""Windows initialisations."""
|
||||
super().__init__(**kwargs)
|
||||
|
||||
self.user32 = ctypes.WinDLL("user32")
|
||||
self.gdi32 = ctypes.WinDLL("gdi32")
|
||||
self._set_cfunctions()
|
||||
self._set_dpi_awareness()
|
||||
|
||||
# Available thread-specific variables
|
||||
self._handles = local()
|
||||
self._handles.region_width_height = (0, 0)
|
||||
self._handles.bmp = None
|
||||
self._handles.srcdc = self.user32.GetWindowDC(0)
|
||||
self._handles.memdc = self.gdi32.CreateCompatibleDC(self._handles.srcdc)
|
||||
|
||||
bmi = BITMAPINFO()
|
||||
bmi.bmiHeader.biSize = ctypes.sizeof(BITMAPINFOHEADER)
|
||||
bmi.bmiHeader.biPlanes = 1 # Always 1
|
||||
bmi.bmiHeader.biBitCount = 32 # See grab.__doc__ [2]
|
||||
bmi.bmiHeader.biCompression = 0 # 0 = BI_RGB (no compression)
|
||||
bmi.bmiHeader.biClrUsed = 0 # See grab.__doc__ [3]
|
||||
bmi.bmiHeader.biClrImportant = 0 # See grab.__doc__ [3]
|
||||
self._handles.bmi = bmi
|
||||
|
||||
def close(self) -> None:
|
||||
# Clean-up
|
||||
if self._handles.bmp:
|
||||
self.gdi32.DeleteObject(self._handles.bmp)
|
||||
self._handles.bmp = None
|
||||
|
||||
if self._handles.memdc:
|
||||
self.gdi32.DeleteDC(self._handles.memdc)
|
||||
self._handles.memdc = None
|
||||
|
||||
if self._handles.srcdc:
|
||||
self.user32.ReleaseDC(0, self._handles.srcdc)
|
||||
self._handles.srcdc = None
|
||||
|
||||
def _set_cfunctions(self) -> None:
|
||||
"""Set all ctypes functions and attach them to attributes."""
|
||||
cfactory = self._cfactory
|
||||
attrs = {
|
||||
"gdi32": self.gdi32,
|
||||
"user32": self.user32,
|
||||
}
|
||||
for func, (attr, argtypes, restype) in CFUNCTIONS.items():
|
||||
cfactory(attrs[attr], func, argtypes, restype)
|
||||
|
||||
def _set_dpi_awareness(self) -> None:
|
||||
"""Set DPI awareness to capture full screen on Hi-DPI monitors."""
|
||||
version = sys.getwindowsversion()[:2]
|
||||
if version >= (6, 3):
|
||||
# Windows 8.1+
|
||||
# Here 2 = PROCESS_PER_MONITOR_DPI_AWARE, which means:
|
||||
# per monitor DPI aware. This app checks for the DPI when it is
|
||||
# created and adjusts the scale factor whenever the DPI changes.
|
||||
# These applications are not automatically scaled by the system.
|
||||
ctypes.windll.shcore.SetProcessDpiAwareness(2)
|
||||
elif (6, 0) <= version < (6, 3):
|
||||
# Windows Vista, 7, 8, and Server 2012
|
||||
self.user32.SetProcessDPIAware()
|
||||
|
||||
def _monitors_impl(self) -> None:
|
||||
"""Get positions of monitors. It will populate self._monitors."""
|
||||
int_ = int
|
||||
user32 = self.user32
|
||||
get_system_metrics = user32.GetSystemMetrics
|
||||
|
||||
# All monitors
|
||||
self._monitors.append(
|
||||
{
|
||||
"left": int_(get_system_metrics(76)), # SM_XVIRTUALSCREEN
|
||||
"top": int_(get_system_metrics(77)), # SM_YVIRTUALSCREEN
|
||||
"width": int_(get_system_metrics(78)), # SM_CXVIRTUALSCREEN
|
||||
"height": int_(get_system_metrics(79)), # SM_CYVIRTUALSCREEN
|
||||
},
|
||||
)
|
||||
|
||||
# Each monitor
|
||||
def _callback(_monitor: int, _data: HDC, rect: LPRECT, _dc: LPARAM) -> int:
|
||||
"""Callback for monitorenumproc() function, it will return
|
||||
a RECT with appropriate values.
|
||||
"""
|
||||
rct = rect.contents
|
||||
self._monitors.append(
|
||||
{
|
||||
"left": int_(rct.left),
|
||||
"top": int_(rct.top),
|
||||
"width": int_(rct.right) - int_(rct.left),
|
||||
"height": int_(rct.bottom) - int_(rct.top),
|
||||
},
|
||||
)
|
||||
return 1
|
||||
|
||||
callback = MONITORNUMPROC(_callback)
|
||||
user32.EnumDisplayMonitors(0, 0, callback, 0)
|
||||
|
||||
def _grab_impl(self, monitor: Monitor, /) -> ScreenShot:
|
||||
"""Retrieve all pixels from a monitor. Pixels have to be RGB.
|
||||
|
||||
In the code, there are a few interesting things:
|
||||
|
||||
[1] bmi.bmiHeader.biHeight = -height
|
||||
|
||||
A bottom-up DIB is specified by setting the height to a
|
||||
positive number, while a top-down DIB is specified by
|
||||
setting the height to a negative number.
|
||||
https://msdn.microsoft.com/en-us/library/ms787796.aspx
|
||||
https://msdn.microsoft.com/en-us/library/dd144879%28v=vs.85%29.aspx
|
||||
|
||||
|
||||
[2] bmi.bmiHeader.biBitCount = 32
|
||||
image_data = create_string_buffer(height * width * 4)
|
||||
|
||||
We grab the image in RGBX mode, so that each word is 32bit
|
||||
and we have no striding.
|
||||
Inspired by https://github.com/zoofIO/flexx
|
||||
|
||||
|
||||
[3] bmi.bmiHeader.biClrUsed = 0
|
||||
bmi.bmiHeader.biClrImportant = 0
|
||||
|
||||
When biClrUsed and biClrImportant are set to zero, there
|
||||
is "no" color table, so we can read the pixels of the bitmap
|
||||
retrieved by gdi32.GetDIBits() as a sequence of RGB values.
|
||||
Thanks to http://stackoverflow.com/a/3688682
|
||||
"""
|
||||
srcdc, memdc = self._handles.srcdc, self._handles.memdc
|
||||
gdi = self.gdi32
|
||||
width, height = monitor["width"], monitor["height"]
|
||||
|
||||
if self._handles.region_width_height != (width, height):
|
||||
self._handles.region_width_height = (width, height)
|
||||
self._handles.bmi.bmiHeader.biWidth = width
|
||||
self._handles.bmi.bmiHeader.biHeight = -height # Why minus? [1]
|
||||
self._handles.data = ctypes.create_string_buffer(width * height * 4) # [2]
|
||||
if self._handles.bmp:
|
||||
gdi.DeleteObject(self._handles.bmp)
|
||||
self._handles.bmp = gdi.CreateCompatibleBitmap(srcdc, width, height)
|
||||
gdi.SelectObject(memdc, self._handles.bmp)
|
||||
|
||||
gdi.BitBlt(memdc, 0, 0, width, height, srcdc, monitor["left"], monitor["top"], SRCCOPY | CAPTUREBLT)
|
||||
bits = gdi.GetDIBits(memdc, self._handles.bmp, 0, height, self._handles.data, self._handles.bmi, DIB_RGB_COLORS)
|
||||
if bits != height:
|
||||
msg = "gdi32.GetDIBits() failed."
|
||||
raise ScreenShotError(msg)
|
||||
|
||||
return self.cls_image(bytearray(self._handles.data), monitor)
|
||||
|
||||
def _cursor_impl(self) -> ScreenShot | None:
|
||||
"""Retrieve all cursor data. Pixels have to be RGB."""
|
||||
return None
|
||||
@@ -0,0 +1 @@
|
||||
pip
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,137 @@
|
||||
nodriver-0.48.1.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
||||
nodriver-0.48.1.dist-info/METADATA,sha256=tukEaC-Am2VoGPWO0Zs8gLCFSp_eCduYmVUdATtHDPc,50775
|
||||
nodriver-0.48.1.dist-info/RECORD,,
|
||||
nodriver-0.48.1.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
||||
nodriver-0.48.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
||||
nodriver-0.48.1.dist-info/licenses/LICENSE.txt,sha256=bGgP8N3yFxPEOv_tPncF0Nv8xysKVbSzZmHblBWE4M8,32693
|
||||
nodriver-0.48.1.dist-info/top_level.txt,sha256=U7UILX_pQyzqtLZRLYsbSumg3X-j27LTmNupjE0ew28,9
|
||||
nodriver/__init__.py,sha256=gAvXhM6Oh4_pt5Ar0bQ1luFyN50Nmp24dtqwes5YJss,974
|
||||
nodriver/__pycache__/__init__.cpython-311.pyc,,
|
||||
nodriver/cdp/README.md,sha256=8AzcjSTEyKJKo5G4wkAwOy0mezkYsfcQSdHFsI3InC0,172
|
||||
nodriver/cdp/__init__.py,sha256=36di_SVOjVnKbm_rdni6kDTLimYYvXc1Ym00rrts-JA,778
|
||||
nodriver/cdp/__pycache__/__init__.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/accessibility.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/animation.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/audits.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/autofill.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/background_service.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/bluetooth_emulation.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/browser.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/cache_storage.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/cast.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/console.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/css.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/database.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/debugger.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/device_access.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/device_orientation.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/dom.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/dom_debugger.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/dom_snapshot.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/dom_storage.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/emulation.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/event_breakpoints.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/extensions.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/fed_cm.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/fetch.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/file_system.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/headless_experimental.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/heap_profiler.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/indexed_db.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/input_.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/inspector.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/io.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/layer_tree.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/log.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/media.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/memory.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/network.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/overlay.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/page.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/performance.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/performance_timeline.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/preload.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/profiler.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/pwa.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/runtime.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/schema.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/security.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/service_worker.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/storage.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/system_info.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/target.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/tethering.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/tracing.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/util.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/web_audio.cpython-311.pyc,,
|
||||
nodriver/cdp/__pycache__/web_authn.cpython-311.pyc,,
|
||||
nodriver/cdp/accessibility.py,sha256=t5tnjLrauedruNSxFTSFFpypsWtodx8JkLv54_s76ZY,24595
|
||||
nodriver/cdp/animation.py,sha256=MCG8JVJbOUwH7lc6ywZ0Mtfe4uCbgnKVQMDHSWf_WL8,15029
|
||||
nodriver/cdp/audits.py,sha256=KSfm951fCxRKp3EZ38p3F-s2ne0UNhpLReysEv41XeE,77332
|
||||
nodriver/cdp/autofill.py,sha256=MJHgP9g9xj8V1MtAP-SfsPzibfVW8_slMzykHmI5IKU,8884
|
||||
nodriver/cdp/background_service.py,sha256=PtNEdDOItjHH22dENRPR9pKGup8Z62KfR1RP0i1vs-I,6288
|
||||
nodriver/cdp/bluetooth_emulation.py,sha256=2kcWWpPHZyvHAye8ybppfchi5pP551g4eyLVwk32PHA,20099
|
||||
nodriver/cdp/browser.py,sha256=oiafeSGMSLqOUv3JUaoI5_nFy0QXF57HdzP-gNsKg80,26866
|
||||
nodriver/cdp/cache_storage.py,sha256=XDvEQ-f29jG0jL2XZYV_VqS6kmDLONudk2V2Zss9ykY,9556
|
||||
nodriver/cdp/cast.py,sha256=FGuV2aR1Lps74cZFwvZpls7kijQmkp_1jV8l3YX4-SA,4625
|
||||
nodriver/cdp/console.py,sha256=5sTj9fyBdcO3pEOESlyAlhsKDLXn2DdFRX-obU_FP3w,2993
|
||||
nodriver/cdp/css.py,sha256=l3iVF4gdLG8AH0kIPA1VqBjJ9KsajYBoGzBevn7L3wc,95408
|
||||
nodriver/cdp/database.py,sha256=VjhS9k46PS5MKRyD6RooaP1GHX4u4E3jrXi-tLOWviE,4362
|
||||
nodriver/cdp/debugger.py,sha256=Y29u5eZJItdylBVZTMJDwOQKCcVpmAwPeLbFVygHDt8,54915
|
||||
nodriver/cdp/device_access.py,sha256=Bxkk_IiIlRbMQcBdhihA9FCPq83pafQhBgQAj3Stjkc,3522
|
||||
nodriver/cdp/device_orientation.py,sha256=vngwahjv4HUZucWHFLPjEt44Yyt0X_P-gO2Su0y2PkY,1256
|
||||
nodriver/cdp/dom.py,sha256=vyAspHPCdWG9Rrmlde55gzyuPvcI6qNEMCQmuyNtol0,72253
|
||||
nodriver/cdp/dom_debugger.py,sha256=QzoAhX_SGtfMZ3VomLFOtrj13_6gzfggVRSj-yMnpLQ,10125
|
||||
nodriver/cdp/dom_snapshot.py,sha256=4IwxYtlHUUCTg0TG9CTxSLngIz3JRqAq7ZEXVQpGPCk,39543
|
||||
nodriver/cdp/dom_storage.py,sha256=5AVNr5qbkgTv0P_2WShX-yt9vMznWBAJKsDC4cI0UBY,6083
|
||||
nodriver/cdp/emulation.py,sha256=1ozc5Zungw24dWoVT2bzfm6p8dZBhbW3MnG3iMn64F8,54427
|
||||
nodriver/cdp/event_breakpoints.py,sha256=A7K1znk5CbCy0-qpEn60kxe8d6ZeNXaMozMgSN2269I,1566
|
||||
nodriver/cdp/extensions.py,sha256=ncyDjfEVtzNFMc483f5l7K1r_xN8dMYBAYp92bYRkUw,4821
|
||||
nodriver/cdp/fed_cm.py,sha256=VcK8B-hyXJmRn1-GQIgfPkPdn2AJTQCDV5QdK71_Mzw,8103
|
||||
nodriver/cdp/fetch.py,sha256=NHUHnpMovHUO2ZXLFUoeUUXYlnB5hkNoCgw0sAKYZ-o,21059
|
||||
nodriver/cdp/file_system.py,sha256=QDY06Eq75DH7Y04YQCKd-276h-liV3wIMOi-MHIeAts,3609
|
||||
nodriver/cdp/headless_experimental.py,sha256=loXq42MPDd6L4JGBxqaerGy5Y3YjGYuh_YWAZO8z_T4,5056
|
||||
nodriver/cdp/heap_profiler.py,sha256=KN3B_5qxhiiDF5eWs6v-bsJ0nr4MtuaslDXW-AvUT4U,14676
|
||||
nodriver/cdp/indexed_db.py,sha256=r6je0J6AMc7MMOuF4Exi1XHllunCil0FpDyYoqrzcJc,18249
|
||||
nodriver/cdp/input_.py,sha256=GzroLxmQuM-AlfwAVg0nUHF5zzoXX1SsZohNNTEwQDE,29223
|
||||
nodriver/cdp/inspector.py,sha256=mzWD7GLhkaoO4iXcrYw0HXaBe7_s9iKijPsWEIuoLqI,2150
|
||||
nodriver/cdp/io.py,sha256=y5gGVFgd8Xv9PuUq5vnFKtzQqzFwqE8N8obayksmOww,3147
|
||||
nodriver/cdp/layer_tree.py,sha256=qkmLiwft7L1CCB_kGlNkcLzGvsgNSjEZ0ZaYgSSS9QI,16035
|
||||
nodriver/cdp/log.py,sha256=pWXkfLB24QhEZ9SzGSyopew9WiSl6Dms6p7IcbPrqpg,5710
|
||||
nodriver/cdp/media.py,sha256=A_1OxD8E1IW_6E2nrgKbxvroBAvVskw4aJB0-0uaqW0,8851
|
||||
nodriver/cdp/memory.py,sha256=vrd-newqF1dRban8Xq859knH-ukOioJaJG9AmHJJy9s,8580
|
||||
nodriver/cdp/network.py,sha256=31GQRJwzJUYTCdBUQmXPQvJSdqw7Nq0Zmq6N_ErM6FU,175781
|
||||
nodriver/cdp/overlay.py,sha256=KUt-t7G88fAs7RIr2SEtR0-KotWnuN_kUbDkGTHhxe0,56026
|
||||
nodriver/cdp/page.py,sha256=BMJf5PnbcmJM28Mx8Ut7X9KtyqYXXKcXtJM_YJsB71s,139103
|
||||
nodriver/cdp/performance.py,sha256=CsfDaykaJrPw5Yd-kKVFn_hJvqPt595td3NwbR0YyjY,3214
|
||||
nodriver/cdp/performance_timeline.py,sha256=eOvb8KzhZrRjAZNMLK7hWePtheOEObsh0qZiAJLnnC0,7213
|
||||
nodriver/cdp/preload.py,sha256=UXhxiIUjHK8yCQqDvye9LbB2N4M7jXysZm6aeIQ4rCs,23460
|
||||
nodriver/cdp/profiler.py,sha256=ubaI7nubaGx7CHkHjXrrWi7TXBx-xCcnq4AH1AwNr3U,13859
|
||||
nodriver/cdp/pwa.py,sha256=yiaJyfr9iXGhk4RLy886gYWHBvZOdGGXCYSew1cTHYk,9887
|
||||
nodriver/cdp/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
||||
nodriver/cdp/runtime.py,sha256=IPlZxlbvlwmNQK9PfW0YMHZQSpXuAJRZ5nZeHEjSmEA,64639
|
||||
nodriver/cdp/schema.py,sha256=QRf-GojBhETC8sdFjbrzwTB6M-xrcqaoNs2vN9-LMY4,1214
|
||||
nodriver/cdp/security.py,sha256=nV1UCBSF0X4xz0XcOH6TKfKMooNE4xlKskFSZGFReuQ,18190
|
||||
nodriver/cdp/service_worker.py,sha256=63WEVKgeVekpZR3RzI2rQs5A4eq9lc06Bkbqrd5FXMI,11743
|
||||
nodriver/cdp/storage.py,sha256=RELXcv_b3ywc7LccRw8hNUNWPPk-rHFDChHoXPVWxPg,83856
|
||||
nodriver/cdp/system_info.py,sha256=n1V_nUjkl9qeEwopUE-p8OB5BFUeMoGxcDgi4_U7u4Y,12467
|
||||
nodriver/cdp/target.py,sha256=NVaG4TIQGjetBy1GOH_oONizIZ7lOm7OB0mYJxg-am8,28502
|
||||
nodriver/cdp/tethering.py,sha256=lROlLJiuxL1gvxWtFgSO-rccXenMQeoLZ3T90P3kAJU,1605
|
||||
nodriver/cdp/tracing.py,sha256=96kg2kVC6jrOiFd5PqBf_fEXlldLlQj0ltwWhvwh1qs,14083
|
||||
nodriver/cdp/util.py,sha256=F-AC9Igdqe442nmAxi8bk6iQLeo3G1s2cI2Jul14plg,472
|
||||
nodriver/cdp/web_audio.py,sha256=-Sm_GUWj7h6kPRDDlFZoZGi8EFqg365T1d4bOTaqAAc,18121
|
||||
nodriver/cdp/web_authn.py,sha256=9Fc_ygmyyfFCkSYkVpLcwoY8QHOldq8tVKeKXvcIG8k,21508
|
||||
nodriver/core/__pycache__/_contradict.cpython-311.pyc,,
|
||||
nodriver/core/__pycache__/browser.cpython-311.pyc,,
|
||||
nodriver/core/__pycache__/config.cpython-311.pyc,,
|
||||
nodriver/core/__pycache__/connection.cpython-311.pyc,,
|
||||
nodriver/core/__pycache__/element.cpython-311.pyc,,
|
||||
nodriver/core/__pycache__/tab.cpython-311.pyc,,
|
||||
nodriver/core/__pycache__/util.cpython-311.pyc,,
|
||||
nodriver/core/_contradict.py,sha256=vFIFWZvGEyGVIVf-ATegBasarRp_DhebBxCxUE0yTUo,4136
|
||||
nodriver/core/browser.py,sha256=899fnznMf_H3OcV-Ts_f6BkQVxaQIGGXYODPAuXmvg0,35163
|
||||
nodriver/core/config.py,sha256=VKrBYyl-tWE16HzrwS0QSy6mXwl_01pl4dhPCEaSuM4,10714
|
||||
nodriver/core/connection.py,sha256=RS1nHp85OnRrE-eYAEPnqaJXbdls5PvS3nA3bIvxUI4,18619
|
||||
nodriver/core/element.py,sha256=Lb5FD6ZktODtfBdNKOWKvlydspV0Geed1lfogNOf0tI,41323
|
||||
nodriver/core/tab.py,sha256=qtE7Bg8dMOribGPEFILWRsZ47DeQt4Cd0rurSy4BSAE,81387
|
||||
nodriver/core/util.py,sha256=zeXrO4FA_7_jBVNSBtWIQ_MesGcWW9cjyjeoxZZT3UQ,104001
|
||||
@@ -0,0 +1,5 @@
|
||||
Wheel-Version: 1.0
|
||||
Generator: setuptools (80.9.0)
|
||||
Root-Is-Purelib: true
|
||||
Tag: py3-none-any
|
||||
|
||||
@@ -0,0 +1,619 @@
|
||||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section 7.
|
||||
This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU Affero General Public License from time to time. Such new versions
|
||||
will be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU Affero General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU Affero General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU Affero General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
@@ -0,0 +1 @@
|
||||
nodriver
|
||||
@@ -0,0 +1,32 @@
|
||||
|
||||
|
||||
# Copyright 2024 by UltrafunkAmsterdam (https://github.com/UltrafunkAmsterdam)
|
||||
# All rights reserved.
|
||||
# This file is part of the nodriver package.
|
||||
# and is released under the "GNU AFFERO GENERAL PUBLIC LICENSE".
|
||||
# Please see the LICENSE.txt file that should have been included as part of this package.
|
||||
|
||||
from nodriver import cdp
|
||||
from nodriver.core import util
|
||||
from nodriver.core._contradict import ContraDict # noqa
|
||||
from nodriver.core._contradict import cdict
|
||||
from nodriver.core.browser import Browser, BrowserContext
|
||||
from nodriver.core.config import Config
|
||||
from nodriver.core.connection import Connection
|
||||
from nodriver.core.connection import ProtocolException
|
||||
from nodriver.core.element import Element
|
||||
from nodriver.core.tab import Tab
|
||||
from nodriver.core.util import loop, start
|
||||
|
||||
__all__ = [
|
||||
"loop",
|
||||
"Browser",
|
||||
"Tab",
|
||||
"cdp",
|
||||
"Config",
|
||||
"start",
|
||||
"util",
|
||||
"Element",
|
||||
"ContraDict",
|
||||
"ProtocolException"
|
||||
]
|
||||
Binary file not shown.
@@ -0,0 +1,4 @@
|
||||
|
||||
## Generated by PyCDP
|
||||
The modules of this package were generated by [pycdp], do not modify their contents because the
|
||||
changes will be overwritten in next generations.
|
||||
@@ -0,0 +1,6 @@
|
||||
# DO NOT EDIT THIS FILE!
|
||||
#
|
||||
# This file is generated from the CDP specification. If you need to make
|
||||
# changes, edit the generator and regenerate all of the modules.
|
||||
|
||||
from . import (accessibility, animation, audits, autofill, background_service, bluetooth_emulation, browser, css, cache_storage, cast, console, dom, dom_debugger, dom_snapshot, dom_storage, debugger, device_access, device_orientation, emulation, event_breakpoints, extensions, fed_cm, fetch, file_system, headless_experimental, heap_profiler, io, indexed_db, input_, inspector, layer_tree, log, media, memory, network, overlay, pwa, page, performance, performance_timeline, preload, profiler, runtime, schema, security, service_worker, storage, system_info, target, tethering, tracing, web_audio, web_authn)
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user