diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..cae972d --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,33 @@ +--- +name: Bug report +about: Report a problem so we can fix it +title: "[bug] " +labels: bug +--- + +**Do not report security vulnerabilities here.** See [SECURITY.md](../../SECURITY.md). + +## Describe the bug +A clear and concise description of what went wrong. + +## To reproduce +Steps to reproduce the behavior: +1. Run '...' +2. Type '...' +3. See error + +## Expected behavior +What you expected to happen instead. + +## Environment +- Component: client (Rust) / server (Python) / scripts +- OS: +- Client version (`hack-house --version` or commit): +- Sandbox backend (if relevant): local / docker / multipass +- TLS mode: TLS / `--no-tls` / `--insecure` + +## Logs / output +Paste relevant terminal output. **Redact the room password and any secrets.** + +## Additional context +Anything else that might help. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..956dd46 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,22 @@ +--- +name: Feature request +about: Suggest an idea or enhancement +title: "[feat] " +labels: enhancement +--- + +## Problem / motivation +What are you trying to do, and what's missing or painful today? + +## Proposed solution +A clear and concise description of what you want to happen. + +## Alternatives considered +Other approaches you thought about. + +## Security / privacy impact +Does this touch encryption, the zero-knowledge server model, authentication, or +sandbox permissions? If so, describe the impact. + +## Additional context +Anything else — mockups, links, prior art. diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..9e1c038 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,26 @@ +## Summary +What does this PR change, and why? + +## Related issues +Closes # + +## Type of change +- [ ] Bug fix +- [ ] New feature +- [ ] Refactor / cleanup +- [ ] Documentation +- [ ] Tests + +## Checklist +- [ ] `cargo build` and `cargo test` pass (client) +- [ ] `cargo fmt` and `cargo clippy` are clean +- [ ] `pytest` passes (server) +- [ ] I did not commit secrets, `.venv`, or build artifacts +- [ ] I updated docs / `CHANGELOG.md` where relevant + +## Security / privacy impact +Does this affect encryption, the zero-knowledge server model, authentication, +or sandbox permissions? If so, explain. If not, write "none". + +## How to test +Steps for a reviewer to verify the change. diff --git a/.gitignore b/.gitignore index b1b09fa..990493a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,18 +1,25 @@ -/__pycache__/ -/i-try/ -/venv/ -test_rsa.py -.gitignore -commiter.py -__pycache__ +# Python +__pycache__/ *.pyc -.idea +/venv/ +.venv/ +.pytest_cache/ +.benchmarks/ +build/ +dist/ +*.egg-info/ +cmd_chat.egg-info/ +secured_console_chat.egg-info/ + +# Secrets / keys *.pem -__pycache__ -cmd_chat.egg-info -build -dist + +# Editor / OS +.idea/ + +# Project scratch +/i-try/ +test_rsa.py +commiter.py true.txt -secured_console_chat.egg-info -.pytest_cache//.venv/ /downloads/ diff --git a/.venv/bin/Activate.ps1 b/.venv/bin/Activate.ps1 deleted file mode 100644 index b49d77b..0000000 --- a/.venv/bin/Activate.ps1 +++ /dev/null @@ -1,247 +0,0 @@ -<# -.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" diff --git a/.venv/bin/activate b/.venv/bin/activate deleted file mode 100644 index becd02a..0000000 --- a/.venv/bin/activate +++ /dev/null @@ -1,70 +0,0 @@ -# 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 - - # Call hash to forget past commands. Without forgetting - # past commands the $PATH changes we made may not be respected - hash -r 2> /dev/null - - 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 - -# on Windows, a path can contain colons and backslashes and has to be converted: -if [ "${OSTYPE:-}" = "cygwin" ] || [ "${OSTYPE:-}" = "msys" ] ; then - # transform D:\path\to\venv to /d/path/to/venv on MSYS - # and to /cygdrive/d/path/to/venv on Cygwin - export VIRTUAL_ENV=$(cygpath /home/dell/coding/learning/cmd-chat/.venv) -else - # use the path as-is - export VIRTUAL_ENV=/home/dell/coding/learning/cmd-chat/.venv -fi - -_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 - -# Call hash to forget past commands. Without forgetting -# past commands the $PATH changes we made may not be respected -hash -r 2> /dev/null diff --git a/.venv/bin/activate.csh b/.venv/bin/activate.csh deleted file mode 100644 index f67318e..0000000 --- a/.venv/bin/activate.csh +++ /dev/null @@ -1,27 +0,0 @@ -# This file must be used with "source bin/activate.csh" *from csh*. -# You cannot run it directly. - -# Created by Davide Di Blasi . -# Ported to Python 3.3 venv by Andrew Svetlov - -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/dell/coding/learning/cmd-chat/.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 diff --git a/.venv/bin/activate.fish b/.venv/bin/activate.fish deleted file mode 100644 index b6b56d3..0000000 --- a/.venv/bin/activate.fish +++ /dev/null @@ -1,69 +0,0 @@ -# This file must be used with "source /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/dell/coding/learning/cmd-chat/.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 diff --git a/.venv/bin/httpx b/.venv/bin/httpx deleted file mode 100755 index 39ddca7..0000000 --- a/.venv/bin/httpx +++ /dev/null @@ -1,6 +0,0 @@ -#!/home/dell/coding/learning/cmd-chat/.venv/bin/python3 -import sys -from httpx import main -if __name__ == '__main__': - sys.argv[0] = sys.argv[0].removesuffix('.exe') - sys.exit(main()) diff --git a/.venv/bin/idna b/.venv/bin/idna deleted file mode 100755 index 4311358..0000000 --- a/.venv/bin/idna +++ /dev/null @@ -1,6 +0,0 @@ -#!/home/dell/coding/learning/cmd-chat/.venv/bin/python3 -import sys -from idna.cli import main -if __name__ == '__main__': - sys.argv[0] = sys.argv[0].removesuffix('.exe') - sys.exit(main()) diff --git a/.venv/bin/markdown-it b/.venv/bin/markdown-it deleted file mode 100755 index 823c8d4..0000000 --- a/.venv/bin/markdown-it +++ /dev/null @@ -1,6 +0,0 @@ -#!/home/dell/coding/learning/cmd-chat/.venv/bin/python3 -import sys -from markdown_it.cli.parse import main -if __name__ == '__main__': - sys.argv[0] = sys.argv[0].removesuffix('.exe') - sys.exit(main()) diff --git a/.venv/bin/normalizer b/.venv/bin/normalizer deleted file mode 100755 index f5bb08a..0000000 --- a/.venv/bin/normalizer +++ /dev/null @@ -1,6 +0,0 @@ -#!/home/dell/coding/learning/cmd-chat/.venv/bin/python3 -import sys -from charset_normalizer.cli import cli_detect -if __name__ == '__main__': - sys.argv[0] = sys.argv[0].removesuffix('.exe') - sys.exit(cli_detect()) diff --git a/.venv/bin/pip b/.venv/bin/pip deleted file mode 100755 index 451e201..0000000 --- a/.venv/bin/pip +++ /dev/null @@ -1,8 +0,0 @@ -#!/home/dell/coding/learning/cmd-chat/.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()) diff --git a/.venv/bin/pip3 b/.venv/bin/pip3 deleted file mode 100755 index 451e201..0000000 --- a/.venv/bin/pip3 +++ /dev/null @@ -1,8 +0,0 @@ -#!/home/dell/coding/learning/cmd-chat/.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()) diff --git a/.venv/bin/pip3.12 b/.venv/bin/pip3.12 deleted file mode 100755 index 451e201..0000000 --- a/.venv/bin/pip3.12 +++ /dev/null @@ -1,8 +0,0 @@ -#!/home/dell/coding/learning/cmd-chat/.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()) diff --git a/.venv/bin/py.test b/.venv/bin/py.test deleted file mode 100755 index 2fe52ad..0000000 --- a/.venv/bin/py.test +++ /dev/null @@ -1,6 +0,0 @@ -#!/home/dell/coding/learning/cmd-chat/.venv/bin/python3 -import sys -from pytest import console_main -if __name__ == '__main__': - sys.argv[0] = sys.argv[0].removesuffix('.exe') - sys.exit(console_main()) diff --git a/.venv/bin/pygmentize b/.venv/bin/pygmentize deleted file mode 100755 index d0d43a7..0000000 --- a/.venv/bin/pygmentize +++ /dev/null @@ -1,6 +0,0 @@ -#!/home/dell/coding/learning/cmd-chat/.venv/bin/python3 -import sys -from pygments.cmdline import main -if __name__ == '__main__': - sys.argv[0] = sys.argv[0].removesuffix('.exe') - sys.exit(main()) diff --git a/.venv/bin/pytest b/.venv/bin/pytest deleted file mode 100755 index 2fe52ad..0000000 --- a/.venv/bin/pytest +++ /dev/null @@ -1,6 +0,0 @@ -#!/home/dell/coding/learning/cmd-chat/.venv/bin/python3 -import sys -from pytest import console_main -if __name__ == '__main__': - sys.argv[0] = sys.argv[0].removesuffix('.exe') - sys.exit(console_main()) diff --git a/.venv/bin/python b/.venv/bin/python deleted file mode 120000 index b8a0adb..0000000 --- a/.venv/bin/python +++ /dev/null @@ -1 +0,0 @@ -python3 \ No newline at end of file diff --git a/.venv/bin/python3 b/.venv/bin/python3 deleted file mode 120000 index ae65fda..0000000 --- a/.venv/bin/python3 +++ /dev/null @@ -1 +0,0 @@ -/usr/bin/python3 \ No newline at end of file diff --git a/.venv/bin/python3.12 b/.venv/bin/python3.12 deleted file mode 120000 index b8a0adb..0000000 --- a/.venv/bin/python3.12 +++ /dev/null @@ -1 +0,0 @@ -python3 \ No newline at end of file diff --git a/.venv/bin/sanic b/.venv/bin/sanic deleted file mode 100755 index 383fe05..0000000 --- a/.venv/bin/sanic +++ /dev/null @@ -1,6 +0,0 @@ -#!/home/dell/coding/learning/cmd-chat/.venv/bin/python3 -import sys -from sanic.__main__ import main -if __name__ == '__main__': - sys.argv[0] = sys.argv[0].removesuffix('.exe') - sys.exit(main()) diff --git a/.venv/bin/websockets b/.venv/bin/websockets deleted file mode 100755 index 9f9a4e9..0000000 --- a/.venv/bin/websockets +++ /dev/null @@ -1,6 +0,0 @@ -#!/home/dell/coding/learning/cmd-chat/.venv/bin/python3 -import sys -from websockets.cli import main -if __name__ == '__main__': - sys.argv[0] = sys.argv[0].removesuffix('.exe') - sys.exit(main()) diff --git a/.venv/lib/python3.12/site-packages/81d243bd2c585b0f4821__mypyc.cpython-312-x86_64-linux-gnu.so b/.venv/lib/python3.12/site-packages/81d243bd2c585b0f4821__mypyc.cpython-312-x86_64-linux-gnu.so deleted file mode 100755 index 83590cf..0000000 Binary files a/.venv/lib/python3.12/site-packages/81d243bd2c585b0f4821__mypyc.cpython-312-x86_64-linux-gnu.so and /dev/null differ diff --git a/.venv/lib/python3.12/site-packages/_cffi_backend.cpython-312-x86_64-linux-gnu.so b/.venv/lib/python3.12/site-packages/_cffi_backend.cpython-312-x86_64-linux-gnu.so deleted file mode 100755 index 156ee43..0000000 Binary files a/.venv/lib/python3.12/site-packages/_cffi_backend.cpython-312-x86_64-linux-gnu.so and /dev/null differ diff --git a/.venv/lib/python3.12/site-packages/_distutils_hack/__init__.py b/.venv/lib/python3.12/site-packages/_distutils_hack/__init__.py deleted file mode 100644 index 94f71b9..0000000 --- a/.venv/lib/python3.12/site-packages/_distutils_hack/__init__.py +++ /dev/null @@ -1,239 +0,0 @@ -# don't import any costly modules -import os -import sys - -report_url = ( - "https://github.com/pypa/setuptools/issues/new?template=distutils-deprecation.yml" -) - - -def warn_distutils_present(): - if 'distutils' not in sys.modules: - 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. Support for replacing " - "an already imported distutils is deprecated. In the future, " - "this condition will fail. " - f"Register concerns at {report_url}" - ) - 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') - if which == 'stdlib': - import warnings - - warnings.warn( - "Reliance on distutils from stdlib is deprecated. Users " - "must rely on setuptools to provide the distutils module. " - "Avoid importing distutils or import setuptools first, " - "and avoid setting SETUPTOOLS_USE_DISTUTILS=stdlib. " - f"Register concerns at {report_url}" - ) - 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) -> None: - 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 None - - 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 None - - 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 None - - 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 sys.version_info >= (3, 12) or 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) -> None: - insert_shim() - - def __exit__(self, exc: object, value: object, tb: object) -> None: - _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 - - -if sys.version_info < (3, 12): - # DistutilsMetaFinder can only be disabled in Python < 3.12 (PEP 632) - remove_shim = _remove_shim diff --git a/.venv/lib/python3.12/site-packages/_distutils_hack/override.py b/.venv/lib/python3.12/site-packages/_distutils_hack/override.py deleted file mode 100644 index 2cc433a..0000000 --- a/.venv/lib/python3.12/site-packages/_distutils_hack/override.py +++ /dev/null @@ -1 +0,0 @@ -__import__('_distutils_hack').do_override() diff --git a/.venv/lib/python3.12/site-packages/_pytest/__init__.py b/.venv/lib/python3.12/site-packages/_pytest/__init__.py deleted file mode 100644 index 8eb8ec9..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/__init__.py +++ /dev/null @@ -1,13 +0,0 @@ -from __future__ import annotations - - -__all__ = ["__version__", "version_tuple"] - -try: - from ._version import version as __version__ - from ._version import version_tuple -except ImportError: # pragma: no cover - # broken installation, we don't even try - # unknown only works because we do poor mans version compare - __version__ = "unknown" - version_tuple = (0, 0, "unknown") diff --git a/.venv/lib/python3.12/site-packages/_pytest/_argcomplete.py b/.venv/lib/python3.12/site-packages/_pytest/_argcomplete.py deleted file mode 100644 index 59426ef..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/_argcomplete.py +++ /dev/null @@ -1,117 +0,0 @@ -"""Allow bash-completion for argparse with argcomplete if installed. - -Needs argcomplete>=0.5.6 for python 3.2/3.3 (older versions fail -to find the magic string, so _ARGCOMPLETE env. var is never set, and -this does not need special code). - -Function try_argcomplete(parser) should be called directly before -the call to ArgumentParser.parse_args(). - -The filescompleter is what you normally would use on the positional -arguments specification, in order to get "dirname/" after "dirn" -instead of the default "dirname ": - - optparser.add_argument(Config._file_or_dir, nargs='*').completer=filescompleter - -Other, application specific, completers should go in the file -doing the add_argument calls as they need to be specified as .completer -attributes as well. (If argcomplete is not installed, the function the -attribute points to will not be used). - -SPEEDUP -======= - -The generic argcomplete script for bash-completion -(/etc/bash_completion.d/python-argcomplete.sh) -uses a python program to determine startup script generated by pip. -You can speed up completion somewhat by changing this script to include - # PYTHON_ARGCOMPLETE_OK -so the python-argcomplete-check-easy-install-script does not -need to be called to find the entry point of the code and see if that is -marked with PYTHON_ARGCOMPLETE_OK. - -INSTALL/DEBUGGING -================= - -To include this support in another application that has setup.py generated -scripts: - -- Add the line: - # PYTHON_ARGCOMPLETE_OK - near the top of the main python entry point. - -- Include in the file calling parse_args(): - from _argcomplete import try_argcomplete, filescompleter - Call try_argcomplete just before parse_args(), and optionally add - filescompleter to the positional arguments' add_argument(). - -If things do not work right away: - -- Switch on argcomplete debugging with (also helpful when doing custom - completers): - export _ARC_DEBUG=1 - -- Run: - python-argcomplete-check-easy-install-script $(which appname) - echo $? - will echo 0 if the magic line has been found, 1 if not. - -- Sometimes it helps to find early on errors using: - _ARGCOMPLETE=1 _ARC_DEBUG=1 appname - which should throw a KeyError: 'COMPLINE' (which is properly set by the - global argcomplete script). -""" - -from __future__ import annotations - -import argparse -from glob import glob -import os -import sys -from typing import Any - - -class FastFilesCompleter: - """Fast file completer class.""" - - def __init__(self, directories: bool = True) -> None: - self.directories = directories - - def __call__(self, prefix: str, **kwargs: Any) -> list[str]: - # Only called on non option completions. - if os.sep in prefix[1:]: - prefix_dir = len(os.path.dirname(prefix) + os.sep) - else: - prefix_dir = 0 - completion = [] - globbed = [] - if "*" not in prefix and "?" not in prefix: - # We are on unix, otherwise no bash. - if not prefix or prefix[-1] == os.sep: - globbed.extend(glob(prefix + ".*")) - prefix += "*" - globbed.extend(glob(prefix)) - for x in sorted(globbed): - if os.path.isdir(x): - x += "/" - # Append stripping the prefix (like bash, not like compgen). - completion.append(x[prefix_dir:]) - return completion - - -if os.environ.get("_ARGCOMPLETE"): - try: - import argcomplete.completers - except ImportError: - sys.exit(-1) - filescompleter: FastFilesCompleter | None = FastFilesCompleter() - - def try_argcomplete(parser: argparse.ArgumentParser) -> None: - argcomplete.autocomplete(parser, always_complete_options=False) - -else: - - def try_argcomplete(parser: argparse.ArgumentParser) -> None: - pass - - filescompleter = None diff --git a/.venv/lib/python3.12/site-packages/_pytest/_code/__init__.py b/.venv/lib/python3.12/site-packages/_pytest/_code/__init__.py deleted file mode 100644 index 7f67a2e..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/_code/__init__.py +++ /dev/null @@ -1,26 +0,0 @@ -"""Python inspection/code generation API.""" - -from __future__ import annotations - -from .code import Code -from .code import ExceptionInfo -from .code import filter_traceback -from .code import Frame -from .code import getfslineno -from .code import Traceback -from .code import TracebackEntry -from .source import getrawcode -from .source import Source - - -__all__ = [ - "Code", - "ExceptionInfo", - "Frame", - "Source", - "Traceback", - "TracebackEntry", - "filter_traceback", - "getfslineno", - "getrawcode", -] diff --git a/.venv/lib/python3.12/site-packages/_pytest/_code/code.py b/.venv/lib/python3.12/site-packages/_pytest/_code/code.py deleted file mode 100644 index 4cf99a7..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/_code/code.py +++ /dev/null @@ -1,1571 +0,0 @@ -# mypy: allow-untyped-defs -from __future__ import annotations - -import ast -from collections.abc import Callable -from collections.abc import Iterable -from collections.abc import Mapping -from collections.abc import Sequence -import dataclasses -import inspect -from inspect import CO_VARARGS -from inspect import CO_VARKEYWORDS -from io import StringIO -import os -from pathlib import Path -import re -import sys -from traceback import extract_tb -from traceback import format_exception -from traceback import format_exception_only -from traceback import FrameSummary -from types import CodeType -from types import FrameType -from types import TracebackType -from typing import Any -from typing import ClassVar -from typing import Final -from typing import final -from typing import Generic -from typing import Literal -from typing import overload -from typing import SupportsIndex -from typing import TypeAlias -from typing import TypeVar - -import pluggy - -import _pytest -from _pytest._code.source import findsource -from _pytest._code.source import getrawcode -from _pytest._code.source import getstatementrange_ast -from _pytest._code.source import Source -from _pytest._io import TerminalWriter -from _pytest._io.saferepr import safeformat -from _pytest._io.saferepr import saferepr -from _pytest.compat import get_real_func -from _pytest.deprecated import check_ispytest -from _pytest.pathlib import absolutepath -from _pytest.pathlib import bestrelpath - - -if sys.version_info < (3, 11): - from exceptiongroup import BaseExceptionGroup - -TracebackStyle = Literal["long", "short", "line", "no", "native", "value", "auto"] - -EXCEPTION_OR_MORE = type[BaseException] | tuple[type[BaseException], ...] - - -class Code: - """Wrapper around Python code objects.""" - - __slots__ = ("raw",) - - def __init__(self, obj: CodeType) -> None: - self.raw = obj - - @classmethod - def from_function(cls, obj: object) -> Code: - return cls(getrawcode(obj)) - - def __eq__(self, other): - return self.raw == other.raw - - # Ignore type because of https://github.com/python/mypy/issues/4266. - __hash__ = None # type: ignore - - @property - def firstlineno(self) -> int: - return self.raw.co_firstlineno - 1 - - @property - def name(self) -> str: - return self.raw.co_name - - @property - def path(self) -> Path | str: - """Return a path object pointing to source code, or an ``str`` in - case of ``OSError`` / non-existing file.""" - if not self.raw.co_filename: - return "" - try: - p = absolutepath(self.raw.co_filename) - # maybe don't try this checking - if not p.exists(): - raise OSError("path check failed.") - return p - except OSError: - # XXX maybe try harder like the weird logic - # in the standard lib [linecache.updatecache] does? - return self.raw.co_filename - - @property - def fullsource(self) -> Source | None: - """Return a _pytest._code.Source object for the full source file of the code.""" - full, _ = findsource(self.raw) - return full - - def source(self) -> Source: - """Return a _pytest._code.Source object for the code object's source only.""" - # return source only for that part of code - return Source(self.raw) - - def getargs(self, var: bool = False) -> tuple[str, ...]: - """Return a tuple with the argument names for the code object. - - If 'var' is set True also return the names of the variable and - keyword arguments when present. - """ - # Handy shortcut for getting args. - raw = self.raw - argcount = raw.co_argcount - if var: - argcount += raw.co_flags & CO_VARARGS - argcount += raw.co_flags & CO_VARKEYWORDS - return raw.co_varnames[:argcount] - - -class Frame: - """Wrapper around a Python frame holding f_locals and f_globals - in which expressions can be evaluated.""" - - __slots__ = ("raw",) - - def __init__(self, frame: FrameType) -> None: - self.raw = frame - - @property - def lineno(self) -> int: - return self.raw.f_lineno - 1 - - @property - def f_globals(self) -> dict[str, Any]: - return self.raw.f_globals - - @property - def f_locals(self) -> dict[str, Any]: - return self.raw.f_locals - - @property - def code(self) -> Code: - return Code(self.raw.f_code) - - @property - def statement(self) -> Source: - """Statement this frame is at.""" - if self.code.fullsource is None: - return Source("") - return self.code.fullsource.getstatement(self.lineno) - - def eval(self, code, **vars): - """Evaluate 'code' in the frame. - - 'vars' are optional additional local variables. - - Returns the result of the evaluation. - """ - f_locals = self.f_locals.copy() - f_locals.update(vars) - return eval(code, self.f_globals, f_locals) - - def repr(self, object: object) -> str: - """Return a 'safe' (non-recursive, one-line) string repr for 'object'.""" - return saferepr(object) - - def getargs(self, var: bool = False): - """Return a list of tuples (name, value) for all arguments. - - If 'var' is set True, also include the variable and keyword arguments - when present. - """ - retval = [] - for arg in self.code.getargs(var): - try: - retval.append((arg, self.f_locals[arg])) - except KeyError: - pass # this can occur when using Psyco - return retval - - -class TracebackEntry: - """A single entry in a Traceback.""" - - __slots__ = ("_rawentry", "_repr_style") - - def __init__( - self, - rawentry: TracebackType, - repr_style: Literal["short", "long"] | None = None, - ) -> None: - self._rawentry: Final = rawentry - self._repr_style: Final = repr_style - - def with_repr_style( - self, repr_style: Literal["short", "long"] | None - ) -> TracebackEntry: - return TracebackEntry(self._rawentry, repr_style) - - @property - def lineno(self) -> int: - return self._rawentry.tb_lineno - 1 - - def get_python_framesummary(self) -> FrameSummary: - # Python's built-in traceback module implements all the nitty gritty - # details to get column numbers of out frames. - stack_summary = extract_tb(self._rawentry, limit=1) - return stack_summary[0] - - # Column and end line numbers introduced in python 3.11 - if sys.version_info < (3, 11): - - @property - def end_lineno_relative(self) -> int | None: - return None - - @property - def colno(self) -> int | None: - return None - - @property - def end_colno(self) -> int | None: - return None - else: - - @property - def end_lineno_relative(self) -> int | None: - frame_summary = self.get_python_framesummary() - if frame_summary.end_lineno is None: # pragma: no cover - return None - return frame_summary.end_lineno - 1 - self.frame.code.firstlineno - - @property - def colno(self) -> int | None: - """Starting byte offset of the expression in the traceback entry.""" - return self.get_python_framesummary().colno - - @property - def end_colno(self) -> int | None: - """Ending byte offset of the expression in the traceback entry.""" - return self.get_python_framesummary().end_colno - - @property - def frame(self) -> Frame: - return Frame(self._rawentry.tb_frame) - - @property - def relline(self) -> int: - return self.lineno - self.frame.code.firstlineno - - def __repr__(self) -> str: - return f"" - - @property - def statement(self) -> Source: - """_pytest._code.Source object for the current statement.""" - source = self.frame.code.fullsource - assert source is not None - return source.getstatement(self.lineno) - - @property - def path(self) -> Path | str: - """Path to the source code.""" - return self.frame.code.path - - @property - def locals(self) -> dict[str, Any]: - """Locals of underlying frame.""" - return self.frame.f_locals - - def getfirstlinesource(self) -> int: - return self.frame.code.firstlineno - - def getsource( - self, astcache: dict[str | Path, ast.AST] | None = None - ) -> Source | None: - """Return failing source code.""" - # we use the passed in astcache to not reparse asttrees - # within exception info printing - source = self.frame.code.fullsource - if source is None: - return None - key = astnode = None - if astcache is not None: - key = self.frame.code.path - if key is not None: - astnode = astcache.get(key, None) - start = self.getfirstlinesource() - try: - astnode, _, end = getstatementrange_ast( - self.lineno, source, astnode=astnode - ) - except SyntaxError: - end = self.lineno + 1 - else: - if key is not None and astcache is not None: - astcache[key] = astnode - return source[start:end] - - source = property(getsource) - - def ishidden(self, excinfo: ExceptionInfo[BaseException] | None) -> bool: - """Return True if the current frame has a var __tracebackhide__ - resolving to True. - - If __tracebackhide__ is a callable, it gets called with the - ExceptionInfo instance and can decide whether to hide the traceback. - - Mostly for internal use. - """ - tbh: bool | Callable[[ExceptionInfo[BaseException] | None], bool] = False - for maybe_ns_dct in (self.frame.f_locals, self.frame.f_globals): - # in normal cases, f_locals and f_globals are dictionaries - # however via `exec(...)` / `eval(...)` they can be other types - # (even incorrect types!). - # as such, we suppress all exceptions while accessing __tracebackhide__ - try: - tbh = maybe_ns_dct["__tracebackhide__"] - except Exception: - pass - else: - break - if tbh and callable(tbh): - return tbh(excinfo) - return tbh - - def __str__(self) -> str: - name = self.frame.code.name - try: - line = str(self.statement).lstrip() - except KeyboardInterrupt: - raise - except BaseException: - line = "???" - # This output does not quite match Python's repr for traceback entries, - # but changing it to do so would break certain plugins. See - # https://github.com/pytest-dev/pytest/pull/7535/ for details. - return f" File '{self.path}':{self.lineno + 1} in {name}\n {line}\n" - - @property - def name(self) -> str: - """co_name of underlying code.""" - return self.frame.code.raw.co_name - - -class Traceback(list[TracebackEntry]): - """Traceback objects encapsulate and offer higher level access to Traceback entries.""" - - def __init__( - self, - tb: TracebackType | Iterable[TracebackEntry], - ) -> None: - """Initialize from given python traceback object and ExceptionInfo.""" - if isinstance(tb, TracebackType): - - def f(cur: TracebackType) -> Iterable[TracebackEntry]: - cur_: TracebackType | None = cur - while cur_ is not None: - yield TracebackEntry(cur_) - cur_ = cur_.tb_next - - super().__init__(f(tb)) - else: - super().__init__(tb) - - def cut( - self, - path: os.PathLike[str] | str | None = None, - lineno: int | None = None, - firstlineno: int | None = None, - excludepath: os.PathLike[str] | None = None, - ) -> Traceback: - """Return a Traceback instance wrapping part of this Traceback. - - By providing any combination of path, lineno and firstlineno, the - first frame to start the to-be-returned traceback is determined. - - This allows cutting the first part of a Traceback instance e.g. - for formatting reasons (removing some uninteresting bits that deal - with handling of the exception/traceback). - """ - path_ = None if path is None else os.fspath(path) - excludepath_ = None if excludepath is None else os.fspath(excludepath) - for x in self: - code = x.frame.code - codepath = code.path - if path is not None and str(codepath) != path_: - continue - if ( - excludepath is not None - and isinstance(codepath, Path) - and excludepath_ in (str(p) for p in codepath.parents) # type: ignore[operator] - ): - continue - if lineno is not None and x.lineno != lineno: - continue - if firstlineno is not None and x.frame.code.firstlineno != firstlineno: - continue - return Traceback(x._rawentry) - return self - - @overload - def __getitem__(self, key: SupportsIndex) -> TracebackEntry: ... - - @overload - def __getitem__(self, key: slice) -> Traceback: ... - - def __getitem__(self, key: SupportsIndex | slice) -> TracebackEntry | Traceback: - if isinstance(key, slice): - return self.__class__(super().__getitem__(key)) - else: - return super().__getitem__(key) - - def filter( - self, - excinfo_or_fn: ExceptionInfo[BaseException] | Callable[[TracebackEntry], bool], - /, - ) -> Traceback: - """Return a Traceback instance with certain items removed. - - If the filter is an `ExceptionInfo`, removes all the ``TracebackEntry``s - which are hidden (see ishidden() above). - - Otherwise, the filter is a function that gets a single argument, a - ``TracebackEntry`` instance, and should return True when the item should - be added to the ``Traceback``, False when not. - """ - if isinstance(excinfo_or_fn, ExceptionInfo): - fn = lambda x: not x.ishidden(excinfo_or_fn) # noqa: E731 - else: - fn = excinfo_or_fn - return Traceback(filter(fn, self)) - - def recursionindex(self) -> int | None: - """Return the index of the frame/TracebackEntry where recursion originates if - appropriate, None if no recursion occurred.""" - cache: dict[tuple[Any, int, int], list[dict[str, Any]]] = {} - for i, entry in enumerate(self): - # id for the code.raw is needed to work around - # the strange metaprogramming in the decorator lib from pypi - # which generates code objects that have hash/value equality - # XXX needs a test - key = entry.frame.code.path, id(entry.frame.code.raw), entry.lineno - values = cache.setdefault(key, []) - # Since Python 3.13 f_locals is a proxy, freeze it. - loc = dict(entry.frame.f_locals) - if values: - for otherloc in values: - if otherloc == loc: - return i - values.append(loc) - return None - - -def stringify_exception( - exc: BaseException, include_subexception_msg: bool = True -) -> str: - try: - notes = getattr(exc, "__notes__", []) - except KeyError: - # Workaround for https://github.com/python/cpython/issues/98778 on - # some 3.10 and 3.11 patch versions. - HTTPError = getattr(sys.modules.get("urllib.error", None), "HTTPError", ()) - if sys.version_info < (3, 12) and isinstance(exc, HTTPError): - notes = [] - else: # pragma: no cover - # exception not related to above bug, reraise - raise - if not include_subexception_msg and isinstance(exc, BaseExceptionGroup): - message = exc.message - else: - message = str(exc) - - return "\n".join( - [ - message, - *notes, - ] - ) - - -E = TypeVar("E", bound=BaseException, covariant=True) - - -@final -@dataclasses.dataclass -class ExceptionInfo(Generic[E]): - """Wraps sys.exc_info() objects and offers help for navigating the traceback.""" - - _assert_start_repr: ClassVar = "AssertionError('assert " - - _excinfo: tuple[type[E], E, TracebackType] | None - _striptext: str - _traceback: Traceback | None - - def __init__( - self, - excinfo: tuple[type[E], E, TracebackType] | None, - striptext: str = "", - traceback: Traceback | None = None, - *, - _ispytest: bool = False, - ) -> None: - check_ispytest(_ispytest) - self._excinfo = excinfo - self._striptext = striptext - self._traceback = traceback - - @classmethod - def from_exception( - cls, - # Ignoring error: "Cannot use a covariant type variable as a parameter". - # This is OK to ignore because this class is (conceptually) readonly. - # See https://github.com/python/mypy/issues/7049. - exception: E, # type: ignore[misc] - exprinfo: str | None = None, - ) -> ExceptionInfo[E]: - """Return an ExceptionInfo for an existing exception. - - The exception must have a non-``None`` ``__traceback__`` attribute, - otherwise this function fails with an assertion error. This means that - the exception must have been raised, or added a traceback with the - :py:meth:`~BaseException.with_traceback()` method. - - :param exprinfo: - A text string helping to determine if we should strip - ``AssertionError`` from the output. Defaults to the exception - message/``__str__()``. - - .. versionadded:: 7.4 - """ - assert exception.__traceback__, ( - "Exceptions passed to ExcInfo.from_exception(...)" - " must have a non-None __traceback__." - ) - exc_info = (type(exception), exception, exception.__traceback__) - return cls.from_exc_info(exc_info, exprinfo) - - @classmethod - def from_exc_info( - cls, - exc_info: tuple[type[E], E, TracebackType], - exprinfo: str | None = None, - ) -> ExceptionInfo[E]: - """Like :func:`from_exception`, but using old-style exc_info tuple.""" - _striptext = "" - if exprinfo is None and isinstance(exc_info[1], AssertionError): - exprinfo = getattr(exc_info[1], "msg", None) - if exprinfo is None: - exprinfo = saferepr(exc_info[1]) - if exprinfo and exprinfo.startswith(cls._assert_start_repr): - _striptext = "AssertionError: " - - return cls(exc_info, _striptext, _ispytest=True) - - @classmethod - def from_current(cls, exprinfo: str | None = None) -> ExceptionInfo[BaseException]: - """Return an ExceptionInfo matching the current traceback. - - .. warning:: - - Experimental API - - :param exprinfo: - A text string helping to determine if we should strip - ``AssertionError`` from the output. Defaults to the exception - message/``__str__()``. - """ - tup = sys.exc_info() - assert tup[0] is not None, "no current exception" - assert tup[1] is not None, "no current exception" - assert tup[2] is not None, "no current exception" - exc_info = (tup[0], tup[1], tup[2]) - return ExceptionInfo.from_exc_info(exc_info, exprinfo) - - @classmethod - def for_later(cls) -> ExceptionInfo[E]: - """Return an unfilled ExceptionInfo.""" - return cls(None, _ispytest=True) - - def fill_unfilled(self, exc_info: tuple[type[E], E, TracebackType]) -> None: - """Fill an unfilled ExceptionInfo created with ``for_later()``.""" - assert self._excinfo is None, "ExceptionInfo was already filled" - self._excinfo = exc_info - - @property - def type(self) -> type[E]: - """The exception class.""" - assert self._excinfo is not None, ( - ".type can only be used after the context manager exits" - ) - return self._excinfo[0] - - @property - def value(self) -> E: - """The exception value.""" - assert self._excinfo is not None, ( - ".value can only be used after the context manager exits" - ) - return self._excinfo[1] - - @property - def tb(self) -> TracebackType: - """The exception raw traceback.""" - assert self._excinfo is not None, ( - ".tb can only be used after the context manager exits" - ) - return self._excinfo[2] - - @property - def typename(self) -> str: - """The type name of the exception.""" - assert self._excinfo is not None, ( - ".typename can only be used after the context manager exits" - ) - return self.type.__name__ - - @property - def traceback(self) -> Traceback: - """The traceback.""" - if self._traceback is None: - self._traceback = Traceback(self.tb) - return self._traceback - - @traceback.setter - def traceback(self, value: Traceback) -> None: - self._traceback = value - - def __repr__(self) -> str: - if self._excinfo is None: - return "" - return f"<{self.__class__.__name__} {saferepr(self._excinfo[1])} tblen={len(self.traceback)}>" - - def exconly(self, tryshort: bool = False) -> str: - """Return the exception as a string. - - When 'tryshort' resolves to True, and the exception is an - AssertionError, only the actual exception part of the exception - representation is returned (so 'AssertionError: ' is removed from - the beginning). - """ - - def _get_single_subexc( - eg: BaseExceptionGroup[BaseException], - ) -> BaseException | None: - if len(eg.exceptions) != 1: - return None - if isinstance(e := eg.exceptions[0], BaseExceptionGroup): - return _get_single_subexc(e) - return e - - if ( - tryshort - and isinstance(self.value, BaseExceptionGroup) - and (subexc := _get_single_subexc(self.value)) is not None - ): - return f"{subexc!r} [single exception in {type(self.value).__name__}]" - - lines = format_exception_only(self.type, self.value) - text = "".join(lines) - text = text.rstrip() - if tryshort: - if text.startswith(self._striptext): - text = text[len(self._striptext) :] - return text - - def errisinstance(self, exc: EXCEPTION_OR_MORE) -> bool: - """Return True if the exception is an instance of exc. - - Consider using ``isinstance(excinfo.value, exc)`` instead. - """ - return isinstance(self.value, exc) - - def _getreprcrash(self) -> ReprFileLocation | None: - # Find last non-hidden traceback entry that led to the exception of the - # traceback, or None if all hidden. - for i in range(-1, -len(self.traceback) - 1, -1): - entry = self.traceback[i] - if not entry.ishidden(self): - path, lineno = entry.frame.code.raw.co_filename, entry.lineno - exconly = self.exconly(tryshort=True) - return ReprFileLocation(path, lineno + 1, exconly) - return None - - def getrepr( - self, - showlocals: bool = False, - style: TracebackStyle = "long", - abspath: bool = False, - tbfilter: bool | Callable[[ExceptionInfo[BaseException]], Traceback] = True, - funcargs: bool = False, - truncate_locals: bool = True, - truncate_args: bool = True, - chain: bool = True, - ) -> ReprExceptionInfo | ExceptionChainRepr: - """Return str()able representation of this exception info. - - :param bool showlocals: - Show locals per traceback entry. - Ignored if ``style=="native"``. - - :param str style: - long|short|line|no|native|value traceback style. - - :param bool abspath: - If paths should be changed to absolute or left unchanged. - - :param tbfilter: - A filter for traceback entries. - - * If false, don't hide any entries. - * If true, hide internal entries and entries that contain a local - variable ``__tracebackhide__ = True``. - * If a callable, delegates the filtering to the callable. - - Ignored if ``style`` is ``"native"``. - - :param bool funcargs: - Show fixtures ("funcargs" for legacy purposes) per traceback entry. - - :param bool truncate_locals: - With ``showlocals==True``, make sure locals can be safely represented as strings. - - :param bool truncate_args: - With ``showargs==True``, make sure args can be safely represented as strings. - - :param bool chain: - If chained exceptions in Python 3 should be shown. - - .. versionchanged:: 3.9 - - Added the ``chain`` parameter. - """ - if style == "native": - return ReprExceptionInfo( - reprtraceback=ReprTracebackNative( - format_exception( - self.type, - self.value, - self.traceback[0]._rawentry if self.traceback else None, - ) - ), - reprcrash=self._getreprcrash(), - ) - - fmt = FormattedExcinfo( - showlocals=showlocals, - style=style, - abspath=abspath, - tbfilter=tbfilter, - funcargs=funcargs, - truncate_locals=truncate_locals, - truncate_args=truncate_args, - chain=chain, - ) - return fmt.repr_excinfo(self) - - def match(self, regexp: str | re.Pattern[str]) -> Literal[True]: - """Check whether the regular expression `regexp` matches the string - representation of the exception using :func:`python:re.search`. - - If it matches `True` is returned, otherwise an `AssertionError` is raised. - """ - __tracebackhide__ = True - value = stringify_exception(self.value) - msg = ( - f"Regex pattern did not match.\n" - f" Expected regex: {regexp!r}\n" - f" Actual message: {value!r}" - ) - if regexp == value: - msg += "\n Did you mean to `re.escape()` the regex?" - assert re.search(regexp, value), msg - # Return True to allow for "assert excinfo.match()". - return True - - def _group_contains( - self, - exc_group: BaseExceptionGroup[BaseException], - expected_exception: EXCEPTION_OR_MORE, - match: str | re.Pattern[str] | None, - target_depth: int | None = None, - current_depth: int = 1, - ) -> bool: - """Return `True` if a `BaseExceptionGroup` contains a matching exception.""" - if (target_depth is not None) and (current_depth > target_depth): - # already descended past the target depth - return False - for exc in exc_group.exceptions: - if isinstance(exc, BaseExceptionGroup): - if self._group_contains( - exc, expected_exception, match, target_depth, current_depth + 1 - ): - return True - if (target_depth is not None) and (current_depth != target_depth): - # not at the target depth, no match - continue - if not isinstance(exc, expected_exception): - continue - if match is not None: - value = stringify_exception(exc) - if not re.search(match, value): - continue - return True - return False - - def group_contains( - self, - expected_exception: EXCEPTION_OR_MORE, - *, - match: str | re.Pattern[str] | None = None, - depth: int | None = None, - ) -> bool: - """Check whether a captured exception group contains a matching exception. - - :param Type[BaseException] | Tuple[Type[BaseException]] expected_exception: - The expected exception type, or a tuple if one of multiple possible - exception types are expected. - - :param str | re.Pattern[str] | None match: - If specified, a string containing a regular expression, - or a regular expression object, that is tested against the string - representation of the exception and its `PEP-678 ` `__notes__` - using :func:`re.search`. - - To match a literal string that may contain :ref:`special characters - `, the pattern can first be escaped with :func:`re.escape`. - - :param Optional[int] depth: - If `None`, will search for a matching exception at any nesting depth. - If >= 1, will only match an exception if it's at the specified depth (depth = 1 being - the exceptions contained within the topmost exception group). - - .. versionadded:: 8.0 - - .. warning:: - This helper makes it easy to check for the presence of specific exceptions, - but it is very bad for checking that the group does *not* contain - *any other exceptions*. - You should instead consider using :class:`pytest.RaisesGroup` - - """ - msg = "Captured exception is not an instance of `BaseExceptionGroup`" - assert isinstance(self.value, BaseExceptionGroup), msg - msg = "`depth` must be >= 1 if specified" - assert (depth is None) or (depth >= 1), msg - return self._group_contains(self.value, expected_exception, match, depth) - - -# Type alias for the `tbfilter` setting: -# bool: If True, it should be filtered using Traceback.filter() -# callable: A callable that takes an ExceptionInfo and returns the filtered traceback. -TracebackFilter: TypeAlias = bool | Callable[[ExceptionInfo[BaseException]], Traceback] - - -@dataclasses.dataclass -class FormattedExcinfo: - """Presenting information about failing Functions and Generators.""" - - # for traceback entries - flow_marker: ClassVar = ">" - fail_marker: ClassVar = "E" - - showlocals: bool = False - style: TracebackStyle = "long" - abspath: bool = True - tbfilter: TracebackFilter = True - funcargs: bool = False - truncate_locals: bool = True - truncate_args: bool = True - chain: bool = True - astcache: dict[str | Path, ast.AST] = dataclasses.field( - default_factory=dict, init=False, repr=False - ) - - def _getindent(self, source: Source) -> int: - # Figure out indent for the given source. - try: - s = str(source.getstatement(len(source) - 1)) - except KeyboardInterrupt: - raise - except BaseException: - try: - s = str(source[-1]) - except KeyboardInterrupt: - raise - except BaseException: - return 0 - return 4 + (len(s) - len(s.lstrip())) - - def _getentrysource(self, entry: TracebackEntry) -> Source | None: - source = entry.getsource(self.astcache) - if source is not None: - source = source.deindent() - return source - - def repr_args(self, entry: TracebackEntry) -> ReprFuncArgs | None: - if self.funcargs: - args = [] - for argname, argvalue in entry.frame.getargs(var=True): - if self.truncate_args: - str_repr = saferepr(argvalue) - else: - str_repr = saferepr(argvalue, maxsize=None) - args.append((argname, str_repr)) - return ReprFuncArgs(args) - return None - - def get_source( - self, - source: Source | None, - line_index: int = -1, - excinfo: ExceptionInfo[BaseException] | None = None, - short: bool = False, - end_line_index: int | None = None, - colno: int | None = None, - end_colno: int | None = None, - ) -> list[str]: - """Return formatted and marked up source lines.""" - lines = [] - if source is not None and line_index < 0: - line_index += len(source) - if source is None or line_index >= len(source.lines) or line_index < 0: - # `line_index` could still be outside `range(len(source.lines))` if - # we're processing AST with pathological position attributes. - source = Source("???") - line_index = 0 - space_prefix = " " - if short: - lines.append(space_prefix + source.lines[line_index].strip()) - lines.extend( - self.get_highlight_arrows_for_line( - raw_line=source.raw_lines[line_index], - line=source.lines[line_index].strip(), - lineno=line_index, - end_lineno=end_line_index, - colno=colno, - end_colno=end_colno, - ) - ) - else: - for line in source.lines[:line_index]: - lines.append(space_prefix + line) - lines.append(self.flow_marker + " " + source.lines[line_index]) - lines.extend( - self.get_highlight_arrows_for_line( - raw_line=source.raw_lines[line_index], - line=source.lines[line_index], - lineno=line_index, - end_lineno=end_line_index, - colno=colno, - end_colno=end_colno, - ) - ) - for line in source.lines[line_index + 1 :]: - lines.append(space_prefix + line) - if excinfo is not None: - indent = 4 if short else self._getindent(source) - lines.extend(self.get_exconly(excinfo, indent=indent, markall=True)) - return lines - - def get_highlight_arrows_for_line( - self, - line: str, - raw_line: str, - lineno: int | None, - end_lineno: int | None, - colno: int | None, - end_colno: int | None, - ) -> list[str]: - """Return characters highlighting a source line. - - Example with colno and end_colno pointing to the bar expression: - "foo() + bar()" - returns " ^^^^^" - """ - if lineno != end_lineno: - # Don't handle expressions that span multiple lines. - return [] - if colno is None or end_colno is None: - # Can't do anything without column information. - return [] - - num_stripped_chars = len(raw_line) - len(line) - - start_char_offset = _byte_offset_to_character_offset(raw_line, colno) - end_char_offset = _byte_offset_to_character_offset(raw_line, end_colno) - num_carets = end_char_offset - start_char_offset - # If the highlight would span the whole line, it is redundant, don't - # show it. - if num_carets >= len(line.strip()): - return [] - - highlights = " " - highlights += " " * (start_char_offset - num_stripped_chars + 1) - highlights += "^" * num_carets - return [highlights] - - def get_exconly( - self, - excinfo: ExceptionInfo[BaseException], - indent: int = 4, - markall: bool = False, - ) -> list[str]: - lines = [] - indentstr = " " * indent - # Get the real exception information out. - exlines = excinfo.exconly(tryshort=True).split("\n") - failindent = self.fail_marker + indentstr[1:] - for line in exlines: - lines.append(failindent + line) - if not markall: - failindent = indentstr - return lines - - def repr_locals(self, locals: Mapping[str, object]) -> ReprLocals | None: - if self.showlocals: - lines = [] - keys = [loc for loc in locals if loc[0] != "@"] - keys.sort() - for name in keys: - value = locals[name] - if name == "__builtins__": - lines.append("__builtins__ = ") - else: - # This formatting could all be handled by the - # _repr() function, which is only reprlib.Repr in - # disguise, so is very configurable. - if self.truncate_locals: - str_repr = saferepr(value) - else: - str_repr = safeformat(value) - # if len(str_repr) < 70 or not isinstance(value, (list, tuple, dict)): - lines.append(f"{name:<10} = {str_repr}") - # else: - # self._line("%-10s =\\" % (name,)) - # # XXX - # pprint.pprint(value, stream=self.excinfowriter) - return ReprLocals(lines) - return None - - def repr_traceback_entry( - self, - entry: TracebackEntry | None, - excinfo: ExceptionInfo[BaseException] | None = None, - ) -> ReprEntry: - lines: list[str] = [] - style = ( - entry._repr_style - if entry is not None and entry._repr_style is not None - else self.style - ) - if style in ("short", "long") and entry is not None: - source = self._getentrysource(entry) - if source is None: - source = Source("???") - line_index = 0 - end_line_index, colno, end_colno = None, None, None - else: - line_index = entry.relline - end_line_index = entry.end_lineno_relative - colno = entry.colno - end_colno = entry.end_colno - short = style == "short" - reprargs = self.repr_args(entry) if not short else None - s = self.get_source( - source=source, - line_index=line_index, - excinfo=excinfo, - short=short, - end_line_index=end_line_index, - colno=colno, - end_colno=end_colno, - ) - lines.extend(s) - if short: - message = f"in {entry.name}" - else: - message = (excinfo and excinfo.typename) or "" - entry_path = entry.path - path = self._makepath(entry_path) - reprfileloc = ReprFileLocation(path, entry.lineno + 1, message) - localsrepr = self.repr_locals(entry.locals) - return ReprEntry(lines, reprargs, localsrepr, reprfileloc, style) - elif style == "value": - if excinfo: - lines.extend(str(excinfo.value).split("\n")) - return ReprEntry(lines, None, None, None, style) - else: - if excinfo: - lines.extend(self.get_exconly(excinfo, indent=4)) - return ReprEntry(lines, None, None, None, style) - - def _makepath(self, path: Path | str) -> str: - if not self.abspath and isinstance(path, Path): - try: - np = bestrelpath(Path.cwd(), path) - except OSError: - return str(path) - if len(np) < len(str(path)): - return np - return str(path) - - def repr_traceback(self, excinfo: ExceptionInfo[BaseException]) -> ReprTraceback: - traceback = filter_excinfo_traceback(self.tbfilter, excinfo) - - if isinstance(excinfo.value, RecursionError): - traceback, extraline = self._truncate_recursive_traceback(traceback) - else: - extraline = None - - if not traceback: - if extraline is None: - extraline = "All traceback entries are hidden. Pass `--full-trace` to see hidden and internal frames." - entries = [self.repr_traceback_entry(None, excinfo)] - return ReprTraceback(entries, extraline, style=self.style) - - last = traceback[-1] - if self.style == "value": - entries = [self.repr_traceback_entry(last, excinfo)] - return ReprTraceback(entries, None, style=self.style) - - entries = [ - self.repr_traceback_entry(entry, excinfo if last == entry else None) - for entry in traceback - ] - return ReprTraceback(entries, extraline, style=self.style) - - def _truncate_recursive_traceback( - self, traceback: Traceback - ) -> tuple[Traceback, str | None]: - """Truncate the given recursive traceback trying to find the starting - point of the recursion. - - The detection is done by going through each traceback entry and - finding the point in which the locals of the frame are equal to the - locals of a previous frame (see ``recursionindex()``). - - Handle the situation where the recursion process might raise an - exception (for example comparing numpy arrays using equality raises a - TypeError), in which case we do our best to warn the user of the - error and show a limited traceback. - """ - try: - recursionindex = traceback.recursionindex() - except Exception as e: - max_frames = 10 - extraline: str | None = ( - "!!! Recursion error detected, but an error occurred locating the origin of recursion.\n" - " The following exception happened when comparing locals in the stack frame:\n" - f" {type(e).__name__}: {e!s}\n" - f" Displaying first and last {max_frames} stack frames out of {len(traceback)}." - ) - # Type ignored because adding two instances of a List subtype - # currently incorrectly has type List instead of the subtype. - traceback = traceback[:max_frames] + traceback[-max_frames:] # type: ignore - else: - if recursionindex is not None: - extraline = "!!! Recursion detected (same locals & position)" - traceback = traceback[: recursionindex + 1] - else: - extraline = None - - return traceback, extraline - - def repr_excinfo(self, excinfo: ExceptionInfo[BaseException]) -> ExceptionChainRepr: - repr_chain: list[tuple[ReprTraceback, ReprFileLocation | None, str | None]] = [] - e: BaseException | None = excinfo.value - excinfo_: ExceptionInfo[BaseException] | None = excinfo - descr = None - seen: set[int] = set() - while e is not None and id(e) not in seen: - seen.add(id(e)) - - if excinfo_: - # Fall back to native traceback as a temporary workaround until - # full support for exception groups added to ExceptionInfo. - # See https://github.com/pytest-dev/pytest/issues/9159 - reprtraceback: ReprTraceback | ReprTracebackNative - if isinstance(e, BaseExceptionGroup): - # don't filter any sub-exceptions since they shouldn't have any internal frames - traceback = filter_excinfo_traceback(self.tbfilter, excinfo) - reprtraceback = ReprTracebackNative( - format_exception( - type(excinfo.value), - excinfo.value, - traceback[0]._rawentry if traceback else None, - ) - ) - if not traceback: - reprtraceback.extraline = ( - "All traceback entries are hidden. " - "Pass `--full-trace` to see hidden and internal frames." - ) - - else: - reprtraceback = self.repr_traceback(excinfo_) - reprcrash = excinfo_._getreprcrash() - else: - # Fallback to native repr if the exception doesn't have a traceback: - # ExceptionInfo objects require a full traceback to work. - reprtraceback = ReprTracebackNative(format_exception(type(e), e, None)) - reprcrash = None - repr_chain += [(reprtraceback, reprcrash, descr)] - - if e.__cause__ is not None and self.chain: - e = e.__cause__ - excinfo_ = ExceptionInfo.from_exception(e) if e.__traceback__ else None - descr = "The above exception was the direct cause of the following exception:" - elif ( - e.__context__ is not None and not e.__suppress_context__ and self.chain - ): - e = e.__context__ - excinfo_ = ExceptionInfo.from_exception(e) if e.__traceback__ else None - descr = "During handling of the above exception, another exception occurred:" - else: - e = None - repr_chain.reverse() - return ExceptionChainRepr(repr_chain) - - -@dataclasses.dataclass(eq=False) -class TerminalRepr: - def __str__(self) -> str: - # FYI this is called from pytest-xdist's serialization of exception - # information. - io = StringIO() - tw = TerminalWriter(file=io) - self.toterminal(tw) - return io.getvalue().strip() - - def __repr__(self) -> str: - return f"<{self.__class__} instance at {id(self):0x}>" - - def toterminal(self, tw: TerminalWriter) -> None: - raise NotImplementedError() - - -# This class is abstract -- only subclasses are instantiated. -@dataclasses.dataclass(eq=False) -class ExceptionRepr(TerminalRepr): - # Provided by subclasses. - reprtraceback: ReprTraceback - reprcrash: ReprFileLocation | None - sections: list[tuple[str, str, str]] = dataclasses.field( - init=False, default_factory=list - ) - - def addsection(self, name: str, content: str, sep: str = "-") -> None: - self.sections.append((name, content, sep)) - - def toterminal(self, tw: TerminalWriter) -> None: - for name, content, sep in self.sections: - tw.sep(sep, name) - tw.line(content) - - -@dataclasses.dataclass(eq=False) -class ExceptionChainRepr(ExceptionRepr): - chain: Sequence[tuple[ReprTraceback, ReprFileLocation | None, str | None]] - - def __init__( - self, - chain: Sequence[tuple[ReprTraceback, ReprFileLocation | None, str | None]], - ) -> None: - # reprcrash and reprtraceback of the outermost (the newest) exception - # in the chain. - super().__init__( - reprtraceback=chain[-1][0], - reprcrash=chain[-1][1], - ) - self.chain = chain - - def toterminal(self, tw: TerminalWriter) -> None: - for element in self.chain: - element[0].toterminal(tw) - if element[2] is not None: - tw.line("") - tw.line(element[2], yellow=True) - super().toterminal(tw) - - -@dataclasses.dataclass(eq=False) -class ReprExceptionInfo(ExceptionRepr): - reprtraceback: ReprTraceback - reprcrash: ReprFileLocation | None - - def toterminal(self, tw: TerminalWriter) -> None: - self.reprtraceback.toterminal(tw) - super().toterminal(tw) - - -@dataclasses.dataclass(eq=False) -class ReprTraceback(TerminalRepr): - reprentries: Sequence[ReprEntry | ReprEntryNative] - extraline: str | None - style: TracebackStyle - - entrysep: ClassVar = "_ " - - def toterminal(self, tw: TerminalWriter) -> None: - # The entries might have different styles. - for i, entry in enumerate(self.reprentries): - if entry.style == "long": - tw.line("") - entry.toterminal(tw) - if i < len(self.reprentries) - 1: - next_entry = self.reprentries[i + 1] - if entry.style == "long" or ( - entry.style == "short" and next_entry.style == "long" - ): - tw.sep(self.entrysep) - - if self.extraline: - tw.line(self.extraline) - - -class ReprTracebackNative(ReprTraceback): - def __init__(self, tblines: Sequence[str]) -> None: - self.reprentries = [ReprEntryNative(tblines)] - self.extraline = None - self.style = "native" - - -@dataclasses.dataclass(eq=False) -class ReprEntryNative(TerminalRepr): - lines: Sequence[str] - - style: ClassVar[TracebackStyle] = "native" - - def toterminal(self, tw: TerminalWriter) -> None: - tw.write("".join(self.lines)) - - -@dataclasses.dataclass(eq=False) -class ReprEntry(TerminalRepr): - lines: Sequence[str] - reprfuncargs: ReprFuncArgs | None - reprlocals: ReprLocals | None - reprfileloc: ReprFileLocation | None - style: TracebackStyle - - def _write_entry_lines(self, tw: TerminalWriter) -> None: - """Write the source code portions of a list of traceback entries with syntax highlighting. - - Usually entries are lines like these: - - " x = 1" - "> assert x == 2" - "E assert 1 == 2" - - This function takes care of rendering the "source" portions of it (the lines without - the "E" prefix) using syntax highlighting, taking care to not highlighting the ">" - character, as doing so might break line continuations. - """ - if not self.lines: - return - - if self.style == "value": - # Using tw.write instead of tw.line for testing purposes due to TWMock implementation; - # lines written with TWMock.line and TWMock._write_source cannot be distinguished - # from each other, whereas lines written with TWMock.write are marked with TWMock.WRITE - for line in self.lines: - tw.write(line) - tw.write("\n") - return - - # separate indents and source lines that are not failures: we want to - # highlight the code but not the indentation, which may contain markers - # such as "> assert 0" - fail_marker = f"{FormattedExcinfo.fail_marker} " - indent_size = len(fail_marker) - indents: list[str] = [] - source_lines: list[str] = [] - failure_lines: list[str] = [] - for index, line in enumerate(self.lines): - is_failure_line = line.startswith(fail_marker) - if is_failure_line: - # from this point on all lines are considered part of the failure - failure_lines.extend(self.lines[index:]) - break - else: - indents.append(line[:indent_size]) - source_lines.append(line[indent_size:]) - - tw._write_source(source_lines, indents) - - # failure lines are always completely red and bold - for line in failure_lines: - tw.line(line, bold=True, red=True) - - def toterminal(self, tw: TerminalWriter) -> None: - if self.style == "short": - if self.reprfileloc: - self.reprfileloc.toterminal(tw) - self._write_entry_lines(tw) - if self.reprlocals: - self.reprlocals.toterminal(tw, indent=" " * 8) - return - - if self.reprfuncargs: - self.reprfuncargs.toterminal(tw) - - self._write_entry_lines(tw) - - if self.reprlocals: - tw.line("") - self.reprlocals.toterminal(tw) - if self.reprfileloc: - if self.lines: - tw.line("") - self.reprfileloc.toterminal(tw) - - def __str__(self) -> str: - return "{}\n{}\n{}".format( - "\n".join(self.lines), self.reprlocals, self.reprfileloc - ) - - -@dataclasses.dataclass(eq=False) -class ReprFileLocation(TerminalRepr): - path: str - lineno: int - message: str - - def __post_init__(self) -> None: - self.path = str(self.path) - - def toterminal(self, tw: TerminalWriter) -> None: - # Filename and lineno output for each entry, using an output format - # that most editors understand. - msg = self.message - i = msg.find("\n") - if i != -1: - msg = msg[:i] - tw.write(self.path, bold=True, red=True) - tw.line(f":{self.lineno}: {msg}") - - -@dataclasses.dataclass(eq=False) -class ReprLocals(TerminalRepr): - lines: Sequence[str] - - def toterminal(self, tw: TerminalWriter, indent="") -> None: - for line in self.lines: - tw.line(indent + line) - - -@dataclasses.dataclass(eq=False) -class ReprFuncArgs(TerminalRepr): - args: Sequence[tuple[str, object]] - - def toterminal(self, tw: TerminalWriter) -> None: - if self.args: - linesofar = "" - for name, value in self.args: - ns = f"{name} = {value}" - if len(ns) + len(linesofar) + 2 > tw.fullwidth: - if linesofar: - tw.line(linesofar) - linesofar = ns - else: - if linesofar: - linesofar += ", " + ns - else: - linesofar = ns - if linesofar: - tw.line(linesofar) - tw.line("") - - -def getfslineno(obj: object) -> tuple[str | Path, int]: - """Return source location (path, lineno) for the given object. - - If the source cannot be determined return ("", -1). - - The line number is 0-based. - """ - # xxx let decorators etc specify a sane ordering - # NOTE: this used to be done in _pytest.compat.getfslineno, initially added - # in 6ec13a2b9. It ("place_as") appears to be something very custom. - obj = get_real_func(obj) - if hasattr(obj, "place_as"): - obj = obj.place_as - - try: - code = Code.from_function(obj) - except TypeError: - try: - fn = inspect.getsourcefile(obj) or inspect.getfile(obj) # type: ignore[arg-type] - except TypeError: - return "", -1 - - fspath = (fn and absolutepath(fn)) or "" - lineno = -1 - if fspath: - try: - _, lineno = findsource(obj) - except OSError: - pass - return fspath, lineno - - return code.path, code.firstlineno - - -def _byte_offset_to_character_offset(str, offset): - """Converts a byte based offset in a string to a code-point.""" - as_utf8 = str.encode("utf-8") - return len(as_utf8[:offset].decode("utf-8", errors="replace")) - - -# Relative paths that we use to filter traceback entries from appearing to the user; -# see filter_traceback. -# note: if we need to add more paths than what we have now we should probably use a list -# for better maintenance. - -_PLUGGY_DIR = Path(pluggy.__file__.rstrip("oc")) -# pluggy is either a package or a single module depending on the version -if _PLUGGY_DIR.name == "__init__.py": - _PLUGGY_DIR = _PLUGGY_DIR.parent -_PYTEST_DIR = Path(_pytest.__file__).parent - - -def filter_traceback(entry: TracebackEntry) -> bool: - """Return True if a TracebackEntry instance should be included in tracebacks. - - We hide traceback entries of: - - * dynamically generated code (no code to show up for it); - * internal traceback from pytest or its internal libraries, py and pluggy. - """ - # entry.path might sometimes return a str object when the entry - # points to dynamically generated code. - # See https://bitbucket.org/pytest-dev/py/issues/71. - raw_filename = entry.frame.code.raw.co_filename - is_generated = "<" in raw_filename and ">" in raw_filename - if is_generated: - return False - - # entry.path might point to a non-existing file, in which case it will - # also return a str object. See #1133. - p = Path(entry.path) - - parents = p.parents - if _PLUGGY_DIR in parents: - return False - if _PYTEST_DIR in parents: - return False - - return True - - -def filter_excinfo_traceback( - tbfilter: TracebackFilter, excinfo: ExceptionInfo[BaseException] -) -> Traceback: - """Filter the exception traceback in ``excinfo`` according to ``tbfilter``.""" - if callable(tbfilter): - return tbfilter(excinfo) - elif tbfilter: - return excinfo.traceback.filter(excinfo) - else: - return excinfo.traceback diff --git a/.venv/lib/python3.12/site-packages/_pytest/_code/source.py b/.venv/lib/python3.12/site-packages/_pytest/_code/source.py deleted file mode 100644 index 99c242d..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/_code/source.py +++ /dev/null @@ -1,225 +0,0 @@ -# mypy: allow-untyped-defs -from __future__ import annotations - -import ast -from bisect import bisect_right -from collections.abc import Iterable -from collections.abc import Iterator -import inspect -import textwrap -import tokenize -import types -from typing import overload -import warnings - - -class Source: - """An immutable object holding a source code fragment. - - When using Source(...), the source lines are deindented. - """ - - def __init__(self, obj: object = None) -> None: - if not obj: - self.lines: list[str] = [] - self.raw_lines: list[str] = [] - elif isinstance(obj, Source): - self.lines = obj.lines - self.raw_lines = obj.raw_lines - elif isinstance(obj, tuple | list): - self.lines = deindent(x.rstrip("\n") for x in obj) - self.raw_lines = list(x.rstrip("\n") for x in obj) - elif isinstance(obj, str): - self.lines = deindent(obj.split("\n")) - self.raw_lines = obj.split("\n") - else: - try: - rawcode = getrawcode(obj) - src = inspect.getsource(rawcode) - except TypeError: - src = inspect.getsource(obj) # type: ignore[arg-type] - self.lines = deindent(src.split("\n")) - self.raw_lines = src.split("\n") - - def __eq__(self, other: object) -> bool: - if not isinstance(other, Source): - return NotImplemented - return self.lines == other.lines - - # Ignore type because of https://github.com/python/mypy/issues/4266. - __hash__ = None # type: ignore - - @overload - def __getitem__(self, key: int) -> str: ... - - @overload - def __getitem__(self, key: slice) -> Source: ... - - def __getitem__(self, key: int | slice) -> str | Source: - if isinstance(key, int): - return self.lines[key] - else: - if key.step not in (None, 1): - raise IndexError("cannot slice a Source with a step") - newsource = Source() - newsource.lines = self.lines[key.start : key.stop] - newsource.raw_lines = self.raw_lines[key.start : key.stop] - return newsource - - def __iter__(self) -> Iterator[str]: - return iter(self.lines) - - def __len__(self) -> int: - return len(self.lines) - - def strip(self) -> Source: - """Return new Source object with trailing and leading blank lines removed.""" - start, end = 0, len(self) - while start < end and not self.lines[start].strip(): - start += 1 - while end > start and not self.lines[end - 1].strip(): - end -= 1 - source = Source() - source.raw_lines = self.raw_lines - source.lines[:] = self.lines[start:end] - return source - - def indent(self, indent: str = " " * 4) -> Source: - """Return a copy of the source object with all lines indented by the - given indent-string.""" - newsource = Source() - newsource.raw_lines = self.raw_lines - newsource.lines = [(indent + line) for line in self.lines] - return newsource - - def getstatement(self, lineno: int) -> Source: - """Return Source statement which contains the given linenumber - (counted from 0).""" - start, end = self.getstatementrange(lineno) - return self[start:end] - - def getstatementrange(self, lineno: int) -> tuple[int, int]: - """Return (start, end) tuple which spans the minimal statement region - which containing the given lineno.""" - if not (0 <= lineno < len(self)): - raise IndexError("lineno out of range") - _ast, start, end = getstatementrange_ast(lineno, self) - return start, end - - def deindent(self) -> Source: - """Return a new Source object deindented.""" - newsource = Source() - newsource.lines[:] = deindent(self.lines) - newsource.raw_lines = self.raw_lines - return newsource - - def __str__(self) -> str: - return "\n".join(self.lines) - - -# -# helper functions -# - - -def findsource(obj) -> tuple[Source | None, int]: - try: - sourcelines, lineno = inspect.findsource(obj) - except Exception: - return None, -1 - source = Source() - source.lines = [line.rstrip() for line in sourcelines] - source.raw_lines = sourcelines - return source, lineno - - -def getrawcode(obj: object, trycall: bool = True) -> types.CodeType: - """Return code object for given function.""" - try: - return obj.__code__ # type: ignore[attr-defined,no-any-return] - except AttributeError: - pass - if trycall: - call = getattr(obj, "__call__", None) - if call and not isinstance(obj, type): - return getrawcode(call, trycall=False) - raise TypeError(f"could not get code object for {obj!r}") - - -def deindent(lines: Iterable[str]) -> list[str]: - return textwrap.dedent("\n".join(lines)).splitlines() - - -def get_statement_startend2(lineno: int, node: ast.AST) -> tuple[int, int | None]: - # Flatten all statements and except handlers into one lineno-list. - # AST's line numbers start indexing at 1. - values: list[int] = [] - for x in ast.walk(node): - if isinstance(x, ast.stmt | ast.ExceptHandler): - # The lineno points to the class/def, so need to include the decorators. - if isinstance(x, ast.ClassDef | ast.FunctionDef | ast.AsyncFunctionDef): - for d in x.decorator_list: - values.append(d.lineno - 1) - values.append(x.lineno - 1) - for name in ("finalbody", "orelse"): - val: list[ast.stmt] | None = getattr(x, name, None) - if val: - # Treat the finally/orelse part as its own statement. - values.append(val[0].lineno - 1 - 1) - values.sort() - insert_index = bisect_right(values, lineno) - start = values[insert_index - 1] - if insert_index >= len(values): - end = None - else: - end = values[insert_index] - return start, end - - -def getstatementrange_ast( - lineno: int, - source: Source, - assertion: bool = False, - astnode: ast.AST | None = None, -) -> tuple[ast.AST, int, int]: - if astnode is None: - content = str(source) - # See #4260: - # Don't produce duplicate warnings when compiling source to find AST. - with warnings.catch_warnings(): - warnings.simplefilter("ignore") - astnode = ast.parse(content, "source", "exec") - - start, end = get_statement_startend2(lineno, astnode) - # We need to correct the end: - # - ast-parsing strips comments - # - there might be empty lines - # - we might have lesser indented code blocks at the end - if end is None: - end = len(source.lines) - - if end > start + 1: - # Make sure we don't span differently indented code blocks - # by using the BlockFinder helper used which inspect.getsource() uses itself. - block_finder = inspect.BlockFinder() - # If we start with an indented line, put blockfinder to "started" mode. - block_finder.started = ( - bool(source.lines[start]) and source.lines[start][0].isspace() - ) - it = ((x + "\n") for x in source.lines[start:end]) - try: - for tok in tokenize.generate_tokens(lambda: next(it)): - block_finder.tokeneater(*tok) - except (inspect.EndOfBlock, IndentationError): - end = block_finder.last + start - except Exception: - pass - - # The end might still point to a comment or empty line, correct it. - while end: - line = source.lines[end - 1].lstrip() - if line.startswith("#") or not line: - end -= 1 - else: - break - return astnode, start, end diff --git a/.venv/lib/python3.12/site-packages/_pytest/_io/__init__.py b/.venv/lib/python3.12/site-packages/_pytest/_io/__init__.py deleted file mode 100644 index b0155b1..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/_io/__init__.py +++ /dev/null @@ -1,10 +0,0 @@ -from __future__ import annotations - -from .terminalwriter import get_terminal_width -from .terminalwriter import TerminalWriter - - -__all__ = [ - "TerminalWriter", - "get_terminal_width", -] diff --git a/.venv/lib/python3.12/site-packages/_pytest/_io/pprint.py b/.venv/lib/python3.12/site-packages/_pytest/_io/pprint.py deleted file mode 100644 index 28f0690..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/_io/pprint.py +++ /dev/null @@ -1,673 +0,0 @@ -# mypy: allow-untyped-defs -# This module was imported from the cpython standard library -# (https://github.com/python/cpython/) at commit -# c5140945c723ae6c4b7ee81ff720ac8ea4b52cfd (python3.12). -# -# -# Original Author: Fred L. Drake, Jr. -# fdrake@acm.org -# -# This is a simple little module I wrote to make life easier. I didn't -# see anything quite like it in the library, though I may have overlooked -# something. I wrote this when I was trying to read some heavily nested -# tuples with fairly non-descriptive content. This is modeled very much -# after Lisp/Scheme - style pretty-printing of lists. If you find it -# useful, thank small children who sleep at night. -from __future__ import annotations - -import collections as _collections -from collections.abc import Callable -from collections.abc import Iterator -import dataclasses as _dataclasses -from io import StringIO as _StringIO -import re -import types as _types -from typing import Any -from typing import IO - - -class _safe_key: - """Helper function for key functions when sorting unorderable objects. - - The wrapped-object will fallback to a Py2.x style comparison for - unorderable types (sorting first comparing the type name and then by - the obj ids). Does not work recursively, so dict.items() must have - _safe_key applied to both the key and the value. - - """ - - __slots__ = ["obj"] - - def __init__(self, obj): - self.obj = obj - - def __lt__(self, other): - try: - return self.obj < other.obj - except TypeError: - return (str(type(self.obj)), id(self.obj)) < ( - str(type(other.obj)), - id(other.obj), - ) - - -def _safe_tuple(t): - """Helper function for comparing 2-tuples""" - return _safe_key(t[0]), _safe_key(t[1]) - - -class PrettyPrinter: - def __init__( - self, - indent: int = 4, - width: int = 80, - depth: int | None = None, - ) -> None: - """Handle pretty printing operations onto a stream using a set of - configured parameters. - - indent - Number of spaces to indent for each level of nesting. - - width - Attempted maximum number of columns in the output. - - depth - The maximum depth to print out nested structures. - - """ - if indent < 0: - raise ValueError("indent must be >= 0") - if depth is not None and depth <= 0: - raise ValueError("depth must be > 0") - if not width: - raise ValueError("width must be != 0") - self._depth = depth - self._indent_per_level = indent - self._width = width - - def pformat(self, object: Any) -> str: - sio = _StringIO() - self._format(object, sio, 0, 0, set(), 0) - return sio.getvalue() - - def _format( - self, - object: Any, - stream: IO[str], - indent: int, - allowance: int, - context: set[int], - level: int, - ) -> None: - objid = id(object) - if objid in context: - stream.write(_recursion(object)) - return - - p = self._dispatch.get(type(object).__repr__, None) - if p is not None: - context.add(objid) - p(self, object, stream, indent, allowance, context, level + 1) - context.remove(objid) - elif ( - _dataclasses.is_dataclass(object) - and not isinstance(object, type) - and object.__dataclass_params__.repr # type:ignore[attr-defined] - and - # Check dataclass has generated repr method. - hasattr(object.__repr__, "__wrapped__") - and "__create_fn__" in object.__repr__.__wrapped__.__qualname__ - ): - context.add(objid) - self._pprint_dataclass( - object, stream, indent, allowance, context, level + 1 - ) - context.remove(objid) - else: - stream.write(self._repr(object, context, level)) - - def _pprint_dataclass( - self, - object: Any, - stream: IO[str], - indent: int, - allowance: int, - context: set[int], - level: int, - ) -> None: - cls_name = object.__class__.__name__ - items = [ - (f.name, getattr(object, f.name)) - for f in _dataclasses.fields(object) - if f.repr - ] - stream.write(cls_name + "(") - self._format_namespace_items(items, stream, indent, allowance, context, level) - stream.write(")") - - _dispatch: dict[ - Callable[..., str], - Callable[[PrettyPrinter, Any, IO[str], int, int, set[int], int], None], - ] = {} - - def _pprint_dict( - self, - object: Any, - stream: IO[str], - indent: int, - allowance: int, - context: set[int], - level: int, - ) -> None: - write = stream.write - write("{") - items = sorted(object.items(), key=_safe_tuple) - self._format_dict_items(items, stream, indent, allowance, context, level) - write("}") - - _dispatch[dict.__repr__] = _pprint_dict - - def _pprint_ordered_dict( - self, - object: Any, - stream: IO[str], - indent: int, - allowance: int, - context: set[int], - level: int, - ) -> None: - if not len(object): - stream.write(repr(object)) - return - cls = object.__class__ - stream.write(cls.__name__ + "(") - self._pprint_dict(object, stream, indent, allowance, context, level) - stream.write(")") - - _dispatch[_collections.OrderedDict.__repr__] = _pprint_ordered_dict - - def _pprint_list( - self, - object: Any, - stream: IO[str], - indent: int, - allowance: int, - context: set[int], - level: int, - ) -> None: - stream.write("[") - self._format_items(object, stream, indent, allowance, context, level) - stream.write("]") - - _dispatch[list.__repr__] = _pprint_list - - def _pprint_tuple( - self, - object: Any, - stream: IO[str], - indent: int, - allowance: int, - context: set[int], - level: int, - ) -> None: - stream.write("(") - self._format_items(object, stream, indent, allowance, context, level) - stream.write(")") - - _dispatch[tuple.__repr__] = _pprint_tuple - - def _pprint_set( - self, - object: Any, - stream: IO[str], - indent: int, - allowance: int, - context: set[int], - level: int, - ) -> None: - if not len(object): - stream.write(repr(object)) - return - typ = object.__class__ - if typ is set: - stream.write("{") - endchar = "}" - else: - stream.write(typ.__name__ + "({") - endchar = "})" - object = sorted(object, key=_safe_key) - self._format_items(object, stream, indent, allowance, context, level) - stream.write(endchar) - - _dispatch[set.__repr__] = _pprint_set - _dispatch[frozenset.__repr__] = _pprint_set - - def _pprint_str( - self, - object: Any, - stream: IO[str], - indent: int, - allowance: int, - context: set[int], - level: int, - ) -> None: - write = stream.write - if not len(object): - write(repr(object)) - return - chunks = [] - lines = object.splitlines(True) - if level == 1: - indent += 1 - allowance += 1 - max_width1 = max_width = self._width - indent - for i, line in enumerate(lines): - rep = repr(line) - if i == len(lines) - 1: - max_width1 -= allowance - if len(rep) <= max_width1: - chunks.append(rep) - else: - # A list of alternating (non-space, space) strings - parts = re.findall(r"\S*\s*", line) - assert parts - assert not parts[-1] - parts.pop() # drop empty last part - max_width2 = max_width - current = "" - for j, part in enumerate(parts): - candidate = current + part - if j == len(parts) - 1 and i == len(lines) - 1: - max_width2 -= allowance - if len(repr(candidate)) > max_width2: - if current: - chunks.append(repr(current)) - current = part - else: - current = candidate - if current: - chunks.append(repr(current)) - if len(chunks) == 1: - write(rep) - return - if level == 1: - write("(") - for i, rep in enumerate(chunks): - if i > 0: - write("\n" + " " * indent) - write(rep) - if level == 1: - write(")") - - _dispatch[str.__repr__] = _pprint_str - - def _pprint_bytes( - self, - object: Any, - stream: IO[str], - indent: int, - allowance: int, - context: set[int], - level: int, - ) -> None: - write = stream.write - if len(object) <= 4: - write(repr(object)) - return - parens = level == 1 - if parens: - indent += 1 - allowance += 1 - write("(") - delim = "" - for rep in _wrap_bytes_repr(object, self._width - indent, allowance): - write(delim) - write(rep) - if not delim: - delim = "\n" + " " * indent - if parens: - write(")") - - _dispatch[bytes.__repr__] = _pprint_bytes - - def _pprint_bytearray( - self, - object: Any, - stream: IO[str], - indent: int, - allowance: int, - context: set[int], - level: int, - ) -> None: - write = stream.write - write("bytearray(") - self._pprint_bytes( - bytes(object), stream, indent + 10, allowance + 1, context, level + 1 - ) - write(")") - - _dispatch[bytearray.__repr__] = _pprint_bytearray - - def _pprint_mappingproxy( - self, - object: Any, - stream: IO[str], - indent: int, - allowance: int, - context: set[int], - level: int, - ) -> None: - stream.write("mappingproxy(") - self._format(object.copy(), stream, indent, allowance, context, level) - stream.write(")") - - _dispatch[_types.MappingProxyType.__repr__] = _pprint_mappingproxy - - def _pprint_simplenamespace( - self, - object: Any, - stream: IO[str], - indent: int, - allowance: int, - context: set[int], - level: int, - ) -> None: - if type(object) is _types.SimpleNamespace: - # The SimpleNamespace repr is "namespace" instead of the class - # name, so we do the same here. For subclasses; use the class name. - cls_name = "namespace" - else: - cls_name = object.__class__.__name__ - items = object.__dict__.items() - stream.write(cls_name + "(") - self._format_namespace_items(items, stream, indent, allowance, context, level) - stream.write(")") - - _dispatch[_types.SimpleNamespace.__repr__] = _pprint_simplenamespace - - def _format_dict_items( - self, - items: list[tuple[Any, Any]], - stream: IO[str], - indent: int, - allowance: int, - context: set[int], - level: int, - ) -> None: - if not items: - return - - write = stream.write - item_indent = indent + self._indent_per_level - delimnl = "\n" + " " * item_indent - for key, ent in items: - write(delimnl) - write(self._repr(key, context, level)) - write(": ") - self._format(ent, stream, item_indent, 1, context, level) - write(",") - - write("\n" + " " * indent) - - def _format_namespace_items( - self, - items: list[tuple[Any, Any]], - stream: IO[str], - indent: int, - allowance: int, - context: set[int], - level: int, - ) -> None: - if not items: - return - - write = stream.write - item_indent = indent + self._indent_per_level - delimnl = "\n" + " " * item_indent - for key, ent in items: - write(delimnl) - write(key) - write("=") - if id(ent) in context: - # Special-case representation of recursion to match standard - # recursive dataclass repr. - write("...") - else: - self._format( - ent, - stream, - item_indent + len(key) + 1, - 1, - context, - level, - ) - - write(",") - - write("\n" + " " * indent) - - def _format_items( - self, - items: list[Any], - stream: IO[str], - indent: int, - allowance: int, - context: set[int], - level: int, - ) -> None: - if not items: - return - - write = stream.write - item_indent = indent + self._indent_per_level - delimnl = "\n" + " " * item_indent - - for item in items: - write(delimnl) - self._format(item, stream, item_indent, 1, context, level) - write(",") - - write("\n" + " " * indent) - - def _repr(self, object: Any, context: set[int], level: int) -> str: - return self._safe_repr(object, context.copy(), self._depth, level) - - def _pprint_default_dict( - self, - object: Any, - stream: IO[str], - indent: int, - allowance: int, - context: set[int], - level: int, - ) -> None: - rdf = self._repr(object.default_factory, context, level) - stream.write(f"{object.__class__.__name__}({rdf}, ") - self._pprint_dict(object, stream, indent, allowance, context, level) - stream.write(")") - - _dispatch[_collections.defaultdict.__repr__] = _pprint_default_dict - - def _pprint_counter( - self, - object: Any, - stream: IO[str], - indent: int, - allowance: int, - context: set[int], - level: int, - ) -> None: - stream.write(object.__class__.__name__ + "(") - - if object: - stream.write("{") - items = object.most_common() - self._format_dict_items(items, stream, indent, allowance, context, level) - stream.write("}") - - stream.write(")") - - _dispatch[_collections.Counter.__repr__] = _pprint_counter - - def _pprint_chain_map( - self, - object: Any, - stream: IO[str], - indent: int, - allowance: int, - context: set[int], - level: int, - ) -> None: - if not len(object.maps) or (len(object.maps) == 1 and not len(object.maps[0])): - stream.write(repr(object)) - return - - stream.write(object.__class__.__name__ + "(") - self._format_items(object.maps, stream, indent, allowance, context, level) - stream.write(")") - - _dispatch[_collections.ChainMap.__repr__] = _pprint_chain_map - - def _pprint_deque( - self, - object: Any, - stream: IO[str], - indent: int, - allowance: int, - context: set[int], - level: int, - ) -> None: - stream.write(object.__class__.__name__ + "(") - if object.maxlen is not None: - stream.write(f"maxlen={object.maxlen}, ") - stream.write("[") - - self._format_items(object, stream, indent, allowance + 1, context, level) - stream.write("])") - - _dispatch[_collections.deque.__repr__] = _pprint_deque - - def _pprint_user_dict( - self, - object: Any, - stream: IO[str], - indent: int, - allowance: int, - context: set[int], - level: int, - ) -> None: - self._format(object.data, stream, indent, allowance, context, level - 1) - - _dispatch[_collections.UserDict.__repr__] = _pprint_user_dict - - def _pprint_user_list( - self, - object: Any, - stream: IO[str], - indent: int, - allowance: int, - context: set[int], - level: int, - ) -> None: - self._format(object.data, stream, indent, allowance, context, level - 1) - - _dispatch[_collections.UserList.__repr__] = _pprint_user_list - - def _pprint_user_string( - self, - object: Any, - stream: IO[str], - indent: int, - allowance: int, - context: set[int], - level: int, - ) -> None: - self._format(object.data, stream, indent, allowance, context, level - 1) - - _dispatch[_collections.UserString.__repr__] = _pprint_user_string - - def _safe_repr( - self, object: Any, context: set[int], maxlevels: int | None, level: int - ) -> str: - typ = type(object) - if typ in _builtin_scalars: - return repr(object) - - r = getattr(typ, "__repr__", None) - - if issubclass(typ, dict) and r is dict.__repr__: - if not object: - return "{}" - objid = id(object) - if maxlevels and level >= maxlevels: - return "{...}" - if objid in context: - return _recursion(object) - context.add(objid) - components: list[str] = [] - append = components.append - level += 1 - for k, v in sorted(object.items(), key=_safe_tuple): - krepr = self._safe_repr(k, context, maxlevels, level) - vrepr = self._safe_repr(v, context, maxlevels, level) - append(f"{krepr}: {vrepr}") - context.remove(objid) - return "{{{}}}".format(", ".join(components)) - - if (issubclass(typ, list) and r is list.__repr__) or ( - issubclass(typ, tuple) and r is tuple.__repr__ - ): - if issubclass(typ, list): - if not object: - return "[]" - format = "[%s]" - elif len(object) == 1: - format = "(%s,)" - else: - if not object: - return "()" - format = "(%s)" - objid = id(object) - if maxlevels and level >= maxlevels: - return format % "..." - if objid in context: - return _recursion(object) - context.add(objid) - components = [] - append = components.append - level += 1 - for o in object: - orepr = self._safe_repr(o, context, maxlevels, level) - append(orepr) - context.remove(objid) - return format % ", ".join(components) - - return repr(object) - - -_builtin_scalars = frozenset( - {str, bytes, bytearray, float, complex, bool, type(None), int} -) - - -def _recursion(object: Any) -> str: - return f"" - - -def _wrap_bytes_repr(object: Any, width: int, allowance: int) -> Iterator[str]: - current = b"" - last = len(object) // 4 * 4 - for i in range(0, len(object), 4): - part = object[i : i + 4] - candidate = current + part - if i == last: - width -= allowance - if len(repr(candidate)) > width: - if current: - yield repr(current) - current = part - else: - current = candidate - if current: - yield repr(current) diff --git a/.venv/lib/python3.12/site-packages/_pytest/_io/saferepr.py b/.venv/lib/python3.12/site-packages/_pytest/_io/saferepr.py deleted file mode 100644 index cee70e3..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/_io/saferepr.py +++ /dev/null @@ -1,130 +0,0 @@ -from __future__ import annotations - -import pprint -import reprlib - - -def _try_repr_or_str(obj: object) -> str: - try: - return repr(obj) - except (KeyboardInterrupt, SystemExit): - raise - except BaseException: - return f'{type(obj).__name__}("{obj}")' - - -def _format_repr_exception(exc: BaseException, obj: object) -> str: - try: - exc_info = _try_repr_or_str(exc) - except (KeyboardInterrupt, SystemExit): - raise - except BaseException as inner_exc: - exc_info = f"unpresentable exception ({_try_repr_or_str(inner_exc)})" - return ( - f"<[{exc_info} raised in repr()] {type(obj).__name__} object at 0x{id(obj):x}>" - ) - - -def _ellipsize(s: str, maxsize: int) -> str: - if len(s) > maxsize: - i = max(0, (maxsize - 3) // 2) - j = max(0, maxsize - 3 - i) - return s[:i] + "..." + s[len(s) - j :] - return s - - -class SafeRepr(reprlib.Repr): - """ - repr.Repr that limits the resulting size of repr() and includes - information on exceptions raised during the call. - """ - - def __init__(self, maxsize: int | None, use_ascii: bool = False) -> None: - """ - :param maxsize: - If not None, will truncate the resulting repr to that specific size, using ellipsis - somewhere in the middle to hide the extra text. - If None, will not impose any size limits on the returning repr. - """ - super().__init__() - # ``maxstring`` is used by the superclass, and needs to be an int; using a - # very large number in case maxsize is None, meaning we want to disable - # truncation. - self.maxstring = maxsize if maxsize is not None else 1_000_000_000 - self.maxsize = maxsize - self.use_ascii = use_ascii - - def repr(self, x: object) -> str: - try: - if self.use_ascii: - s = ascii(x) - else: - s = super().repr(x) - except (KeyboardInterrupt, SystemExit): - raise - except BaseException as exc: - s = _format_repr_exception(exc, x) - if self.maxsize is not None: - s = _ellipsize(s, self.maxsize) - return s - - def repr_instance(self, x: object, level: int) -> str: - try: - s = repr(x) - except (KeyboardInterrupt, SystemExit): - raise - except BaseException as exc: - s = _format_repr_exception(exc, x) - if self.maxsize is not None: - s = _ellipsize(s, self.maxsize) - return s - - -def safeformat(obj: object) -> str: - """Return a pretty printed string for the given object. - - Failing __repr__ functions of user instances will be represented - with a short exception info. - """ - try: - return pprint.pformat(obj) - except Exception as exc: - return _format_repr_exception(exc, obj) - - -# Maximum size of overall repr of objects to display during assertion errors. -DEFAULT_REPR_MAX_SIZE = 240 - - -def saferepr( - obj: object, maxsize: int | None = DEFAULT_REPR_MAX_SIZE, use_ascii: bool = False -) -> str: - """Return a size-limited safe repr-string for the given object. - - Failing __repr__ functions of user instances will be represented - with a short exception info and 'saferepr' generally takes - care to never raise exceptions itself. - - This function is a wrapper around the Repr/reprlib functionality of the - stdlib. - """ - return SafeRepr(maxsize, use_ascii).repr(obj) - - -def saferepr_unlimited(obj: object, use_ascii: bool = True) -> str: - """Return an unlimited-size safe repr-string for the given object. - - As with saferepr, failing __repr__ functions of user instances - will be represented with a short exception info. - - This function is a wrapper around simple repr. - - Note: a cleaner solution would be to alter ``saferepr``this way - when maxsize=None, but that might affect some other code. - """ - try: - if use_ascii: - return ascii(obj) - return repr(obj) - except Exception as exc: - return _format_repr_exception(exc, obj) diff --git a/.venv/lib/python3.12/site-packages/_pytest/_io/terminalwriter.py b/.venv/lib/python3.12/site-packages/_pytest/_io/terminalwriter.py deleted file mode 100644 index 9191b4e..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/_io/terminalwriter.py +++ /dev/null @@ -1,258 +0,0 @@ -"""Helper functions for writing to terminals and files.""" - -from __future__ import annotations - -from collections.abc import Sequence -import os -import shutil -import sys -from typing import final -from typing import Literal -from typing import TextIO - -import pygments -from pygments.formatters.terminal import TerminalFormatter -from pygments.lexer import Lexer -from pygments.lexers.diff import DiffLexer -from pygments.lexers.python import PythonLexer - -from ..compat import assert_never -from .wcwidth import wcswidth - - -# This code was initially copied from py 1.8.1, file _io/terminalwriter.py. - - -def get_terminal_width() -> int: - width, _ = shutil.get_terminal_size(fallback=(80, 24)) - - # The Windows get_terminal_size may be bogus, let's sanify a bit. - if width < 40: - width = 80 - - return width - - -def should_do_markup(file: TextIO) -> bool: - if os.environ.get("PY_COLORS") == "1": - return True - if os.environ.get("PY_COLORS") == "0": - return False - if os.environ.get("NO_COLOR"): - return False - if os.environ.get("FORCE_COLOR"): - return True - return ( - hasattr(file, "isatty") and file.isatty() and os.environ.get("TERM") != "dumb" - ) - - -@final -class TerminalWriter: - _esctable = dict( - black=30, - red=31, - green=32, - yellow=33, - blue=34, - purple=35, - cyan=36, - white=37, - Black=40, - Red=41, - Green=42, - Yellow=43, - Blue=44, - Purple=45, - Cyan=46, - White=47, - bold=1, - light=2, - blink=5, - invert=7, - ) - - def __init__(self, file: TextIO | None = None) -> None: - if file is None: - file = sys.stdout - if hasattr(file, "isatty") and file.isatty() and sys.platform == "win32": - try: - import colorama - except ImportError: - pass - else: - file = colorama.AnsiToWin32(file).stream - assert file is not None - self._file = file - self.hasmarkup = should_do_markup(file) - self._current_line = "" - self._terminal_width: int | None = None - self.code_highlight = True - - @property - def fullwidth(self) -> int: - if self._terminal_width is not None: - return self._terminal_width - return get_terminal_width() - - @fullwidth.setter - def fullwidth(self, value: int) -> None: - self._terminal_width = value - - @property - def width_of_current_line(self) -> int: - """Return an estimate of the width so far in the current line.""" - return wcswidth(self._current_line) - - def markup(self, text: str, **markup: bool) -> str: - for name in markup: - if name not in self._esctable: - raise ValueError(f"unknown markup: {name!r}") - if self.hasmarkup: - esc = [self._esctable[name] for name, on in markup.items() if on] - if esc: - text = "".join(f"\x1b[{cod}m" for cod in esc) + text + "\x1b[0m" - return text - - def sep( - self, - sepchar: str, - title: str | None = None, - fullwidth: int | None = None, - **markup: bool, - ) -> None: - if fullwidth is None: - fullwidth = self.fullwidth - # The goal is to have the line be as long as possible - # under the condition that len(line) <= fullwidth. - if sys.platform == "win32": - # If we print in the last column on windows we are on a - # new line but there is no way to verify/neutralize this - # (we may not know the exact line width). - # So let's be defensive to avoid empty lines in the output. - fullwidth -= 1 - if title is not None: - # we want 2 + 2*len(fill) + len(title) <= fullwidth - # i.e. 2 + 2*len(sepchar)*N + len(title) <= fullwidth - # 2*len(sepchar)*N <= fullwidth - len(title) - 2 - # N <= (fullwidth - len(title) - 2) // (2*len(sepchar)) - N = max((fullwidth - len(title) - 2) // (2 * len(sepchar)), 1) - fill = sepchar * N - line = f"{fill} {title} {fill}" - else: - # we want len(sepchar)*N <= fullwidth - # i.e. N <= fullwidth // len(sepchar) - line = sepchar * (fullwidth // len(sepchar)) - # In some situations there is room for an extra sepchar at the right, - # in particular if we consider that with a sepchar like "_ " the - # trailing space is not important at the end of the line. - if len(line) + len(sepchar.rstrip()) <= fullwidth: - line += sepchar.rstrip() - - self.line(line, **markup) - - def write(self, msg: str, *, flush: bool = False, **markup: bool) -> None: - if msg: - current_line = msg.rsplit("\n", 1)[-1] - if "\n" in msg: - self._current_line = current_line - else: - self._current_line += current_line - - msg = self.markup(msg, **markup) - - self.write_raw(msg, flush=flush) - - def write_raw(self, msg: str, *, flush: bool = False) -> None: - try: - self._file.write(msg) - except UnicodeEncodeError: - # Some environments don't support printing general Unicode - # strings, due to misconfiguration or otherwise; in that case, - # print the string escaped to ASCII. - # When the Unicode situation improves we should consider - # letting the error propagate instead of masking it (see #7475 - # for one brief attempt). - msg = msg.encode("unicode-escape").decode("ascii") - self._file.write(msg) - - if flush: - self.flush() - - def line(self, s: str = "", **markup: bool) -> None: - self.write(s, **markup) - self.write("\n") - - def flush(self) -> None: - self._file.flush() - - def _write_source(self, lines: Sequence[str], indents: Sequence[str] = ()) -> None: - """Write lines of source code possibly highlighted. - - Keeping this private for now because the API is clunky. We should discuss how - to evolve the terminal writer so we can have more precise color support, for example - being able to write part of a line in one color and the rest in another, and so on. - """ - if indents and len(indents) != len(lines): - raise ValueError( - f"indents size ({len(indents)}) should have same size as lines ({len(lines)})" - ) - if not indents: - indents = [""] * len(lines) - source = "\n".join(lines) - new_lines = self._highlight(source).splitlines() - # Would be better to strict=True but that fails some CI jobs. - for indent, new_line in zip(indents, new_lines, strict=False): - self.line(indent + new_line) - - def _get_pygments_lexer(self, lexer: Literal["python", "diff"]) -> Lexer: - if lexer == "python": - return PythonLexer() - elif lexer == "diff": - return DiffLexer() - else: - assert_never(lexer) - - def _get_pygments_formatter(self) -> TerminalFormatter: - from _pytest.config.exceptions import UsageError - - theme = os.getenv("PYTEST_THEME") - theme_mode = os.getenv("PYTEST_THEME_MODE", "dark") - - try: - return TerminalFormatter(bg=theme_mode, style=theme) - except pygments.util.ClassNotFound as e: - raise UsageError( - f"PYTEST_THEME environment variable has an invalid value: '{theme}'. " - "Hint: See available pygments styles with `pygmentize -L styles`." - ) from e - except pygments.util.OptionError as e: - raise UsageError( - f"PYTEST_THEME_MODE environment variable has an invalid value: '{theme_mode}'. " - "The allowed values are 'dark' (default) and 'light'." - ) from e - - def _highlight( - self, source: str, lexer: Literal["diff", "python"] = "python" - ) -> str: - """Highlight the given source if we have markup support.""" - if not source or not self.hasmarkup or not self.code_highlight: - return source - - pygments_lexer = self._get_pygments_lexer(lexer) - pygments_formatter = self._get_pygments_formatter() - - highlighted: str = pygments.highlight( - source, pygments_lexer, pygments_formatter - ) - # pygments terminal formatter may add a newline when there wasn't one. - # We don't want this, remove. - if highlighted[-1] == "\n" and source[-1] != "\n": - highlighted = highlighted[:-1] - - # Some lexers will not set the initial color explicitly - # which may lead to the previous color being propagated to the - # start of the expression, so reset first. - highlighted = "\x1b[0m" + highlighted - - return highlighted diff --git a/.venv/lib/python3.12/site-packages/_pytest/_io/wcwidth.py b/.venv/lib/python3.12/site-packages/_pytest/_io/wcwidth.py deleted file mode 100644 index 23886ff..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/_io/wcwidth.py +++ /dev/null @@ -1,57 +0,0 @@ -from __future__ import annotations - -from functools import lru_cache -import unicodedata - - -@lru_cache(100) -def wcwidth(c: str) -> int: - """Determine how many columns are needed to display a character in a terminal. - - Returns -1 if the character is not printable. - Returns 0, 1 or 2 for other characters. - """ - o = ord(c) - - # ASCII fast path. - if 0x20 <= o < 0x07F: - return 1 - - # Some Cf/Zp/Zl characters which should be zero-width. - if ( - o == 0x0000 - or 0x200B <= o <= 0x200F - or 0x2028 <= o <= 0x202E - or 0x2060 <= o <= 0x2063 - ): - return 0 - - category = unicodedata.category(c) - - # Control characters. - if category == "Cc": - return -1 - - # Combining characters with zero width. - if category in ("Me", "Mn"): - return 0 - - # Full/Wide east asian characters. - if unicodedata.east_asian_width(c) in ("F", "W"): - return 2 - - return 1 - - -def wcswidth(s: str) -> int: - """Determine how many columns are needed to display a string in a terminal. - - Returns -1 if the string contains non-printable characters. - """ - width = 0 - for c in unicodedata.normalize("NFC", s): - wc = wcwidth(c) - if wc < 0: - return -1 - width += wc - return width diff --git a/.venv/lib/python3.12/site-packages/_pytest/_py/__init__.py b/.venv/lib/python3.12/site-packages/_pytest/_py/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/.venv/lib/python3.12/site-packages/_pytest/_py/error.py b/.venv/lib/python3.12/site-packages/_pytest/_py/error.py deleted file mode 100644 index dace237..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/_py/error.py +++ /dev/null @@ -1,119 +0,0 @@ -"""create errno-specific classes for IO or os calls.""" - -from __future__ import annotations - -from collections.abc import Callable -import errno -import os -import sys -from typing import TYPE_CHECKING -from typing import TypeVar - - -if TYPE_CHECKING: - from typing_extensions import ParamSpec - - P = ParamSpec("P") - -R = TypeVar("R") - - -class Error(EnvironmentError): - def __repr__(self) -> str: - return "{}.{} {!r}: {} ".format( - self.__class__.__module__, - self.__class__.__name__, - self.__class__.__doc__, - " ".join(map(str, self.args)), - # repr(self.args) - ) - - def __str__(self) -> str: - s = "[{}]: {}".format( - self.__class__.__doc__, - " ".join(map(str, self.args)), - ) - return s - - -_winerrnomap = { - 2: errno.ENOENT, - 3: errno.ENOENT, - 17: errno.EEXIST, - 18: errno.EXDEV, - 13: errno.EBUSY, # empty cd drive, but ENOMEDIUM seems unavailable - 22: errno.ENOTDIR, - 20: errno.ENOTDIR, - 267: errno.ENOTDIR, - 5: errno.EACCES, # anything better? -} - - -class ErrorMaker: - """lazily provides Exception classes for each possible POSIX errno - (as defined per the 'errno' module). All such instances - subclass EnvironmentError. - """ - - _errno2class: dict[int, type[Error]] = {} - - def __getattr__(self, name: str) -> type[Error]: - if name[0] == "_": - raise AttributeError(name) - eno = getattr(errno, name) - cls = self._geterrnoclass(eno) - setattr(self, name, cls) - return cls - - def _geterrnoclass(self, eno: int) -> type[Error]: - try: - return self._errno2class[eno] - except KeyError: - clsname = errno.errorcode.get(eno, f"UnknownErrno{eno}") - errorcls = type( - clsname, - (Error,), - {"__module__": "py.error", "__doc__": os.strerror(eno)}, - ) - self._errno2class[eno] = errorcls - return errorcls - - def checked_call( - self, func: Callable[P, R], *args: P.args, **kwargs: P.kwargs - ) -> R: - """Call a function and raise an errno-exception if applicable.""" - __tracebackhide__ = True - try: - return func(*args, **kwargs) - except Error: - raise - except OSError as value: - if not hasattr(value, "errno"): - raise - if sys.platform == "win32": - try: - # error: Invalid index type "Optional[int]" for "dict[int, int]"; expected type "int" [index] - # OK to ignore because we catch the KeyError below. - cls = self._geterrnoclass(_winerrnomap[value.errno]) # type:ignore[index] - except KeyError: - raise value - else: - # we are not on Windows, or we got a proper OSError - if value.errno is None: - cls = type( - "UnknownErrnoNone", - (Error,), - {"__module__": "py.error", "__doc__": None}, - ) - else: - cls = self._geterrnoclass(value.errno) - - raise cls(f"{func.__name__}{args!r}") - - -_error_maker = ErrorMaker() -checked_call = _error_maker.checked_call - - -def __getattr__(attr: str) -> type[Error]: - return getattr(_error_maker, attr) # type: ignore[no-any-return] diff --git a/.venv/lib/python3.12/site-packages/_pytest/_py/path.py b/.venv/lib/python3.12/site-packages/_pytest/_py/path.py deleted file mode 100644 index 998a781..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/_py/path.py +++ /dev/null @@ -1,1475 +0,0 @@ -# mypy: allow-untyped-defs -"""local path implementation.""" - -from __future__ import annotations - -import atexit -from collections.abc import Callable -from contextlib import contextmanager -import fnmatch -import importlib.util -import io -import os -from os.path import abspath -from os.path import dirname -from os.path import exists -from os.path import isabs -from os.path import isdir -from os.path import isfile -from os.path import islink -from os.path import normpath -import posixpath -from stat import S_ISDIR -from stat import S_ISLNK -from stat import S_ISREG -import sys -from typing import Any -from typing import cast -from typing import Literal -from typing import overload -from typing import TYPE_CHECKING -import uuid -import warnings - -from . import error - - -# Moved from local.py. -iswin32 = sys.platform == "win32" or (getattr(os, "_name", False) == "nt") - - -class Checkers: - _depend_on_existence = "exists", "link", "dir", "file" - - def __init__(self, path): - self.path = path - - def dotfile(self): - return self.path.basename.startswith(".") - - def ext(self, arg): - if not arg.startswith("."): - arg = "." + arg - return self.path.ext == arg - - def basename(self, arg): - return self.path.basename == arg - - def basestarts(self, arg): - return self.path.basename.startswith(arg) - - def relto(self, arg): - return self.path.relto(arg) - - def fnmatch(self, arg): - return self.path.fnmatch(arg) - - def endswith(self, arg): - return str(self.path).endswith(arg) - - def _evaluate(self, kw): - from .._code.source import getrawcode - - for name, value in kw.items(): - invert = False - meth = None - try: - meth = getattr(self, name) - except AttributeError: - if name[:3] == "not": - invert = True - try: - meth = getattr(self, name[3:]) - except AttributeError: - pass - if meth is None: - raise TypeError(f"no {name!r} checker available for {self.path!r}") - try: - if getrawcode(meth).co_argcount > 1: - if (not meth(value)) ^ invert: - return False - else: - if bool(value) ^ bool(meth()) ^ invert: - return False - except (error.ENOENT, error.ENOTDIR, error.EBUSY): - # EBUSY feels not entirely correct, - # but its kind of necessary since ENOMEDIUM - # is not accessible in python - for name in self._depend_on_existence: - if name in kw: - if kw.get(name): - return False - name = "not" + name - if name in kw: - if not kw.get(name): - return False - return True - - _statcache: Stat - - def _stat(self) -> Stat: - try: - return self._statcache - except AttributeError: - try: - self._statcache = self.path.stat() - except error.ELOOP: - self._statcache = self.path.lstat() - return self._statcache - - def dir(self): - return S_ISDIR(self._stat().mode) - - def file(self): - return S_ISREG(self._stat().mode) - - def exists(self): - return self._stat() - - def link(self): - st = self.path.lstat() - return S_ISLNK(st.mode) - - -class NeverRaised(Exception): - pass - - -class Visitor: - def __init__(self, fil, rec, ignore, bf, sort): - if isinstance(fil, (str, bytes)): - fil = FNMatcher(fil) - if isinstance(rec, str): - self.rec: Callable[[LocalPath], bool] = FNMatcher(rec) - elif not hasattr(rec, "__call__") and rec: - self.rec = lambda path: True - else: - self.rec = rec - self.fil = fil - self.ignore = ignore - self.breadthfirst = bf - self.optsort = cast(Callable[[Any], Any], sorted) if sort else (lambda x: x) - - def gen(self, path): - try: - entries = path.listdir() - except self.ignore: - return - rec = self.rec - dirs = self.optsort( - [p for p in entries if p.check(dir=1) and (rec is None or rec(p))] - ) - if not self.breadthfirst: - for subdir in dirs: - yield from self.gen(subdir) - for p in self.optsort(entries): - if self.fil is None or self.fil(p): - yield p - if self.breadthfirst: - for subdir in dirs: - yield from self.gen(subdir) - - -class FNMatcher: - def __init__(self, pattern): - self.pattern = pattern - - def __call__(self, path): - pattern = self.pattern - - if ( - pattern.find(path.sep) == -1 - and iswin32 - and pattern.find(posixpath.sep) != -1 - ): - # Running on Windows, the pattern has no Windows path separators, - # and the pattern has one or more Posix path separators. Replace - # the Posix path separators with the Windows path separator. - pattern = pattern.replace(posixpath.sep, path.sep) - - if pattern.find(path.sep) == -1: - name = path.basename - else: - name = str(path) # path.strpath # XXX svn? - if not os.path.isabs(pattern): - pattern = "*" + path.sep + pattern - return fnmatch.fnmatch(name, pattern) - - -def map_as_list(func, iter): - return list(map(func, iter)) - - -class Stat: - if TYPE_CHECKING: - - @property - def size(self) -> int: ... - - @property - def mtime(self) -> float: ... - - def __getattr__(self, name: str) -> Any: - return getattr(self._osstatresult, "st_" + name) - - def __init__(self, path, osstatresult): - self.path = path - self._osstatresult = osstatresult - - @property - def owner(self): - if iswin32: - raise NotImplementedError("XXX win32") - import pwd - - entry = error.checked_call(pwd.getpwuid, self.uid) # type:ignore[attr-defined,unused-ignore] - return entry[0] - - @property - def group(self): - """Return group name of file.""" - if iswin32: - raise NotImplementedError("XXX win32") - import grp - - entry = error.checked_call(grp.getgrgid, self.gid) # type:ignore[attr-defined,unused-ignore] - return entry[0] - - def isdir(self): - return S_ISDIR(self._osstatresult.st_mode) - - def isfile(self): - return S_ISREG(self._osstatresult.st_mode) - - def islink(self): - self.path.lstat() - return S_ISLNK(self._osstatresult.st_mode) - - -def getuserid(user): - import pwd - - if not isinstance(user, int): - user = pwd.getpwnam(user)[2] # type:ignore[attr-defined,unused-ignore] - return user - - -def getgroupid(group): - import grp - - if not isinstance(group, int): - group = grp.getgrnam(group)[2] # type:ignore[attr-defined,unused-ignore] - return group - - -class LocalPath: - """Object oriented interface to os.path and other local filesystem - related information. - """ - - class ImportMismatchError(ImportError): - """raised on pyimport() if there is a mismatch of __file__'s""" - - sep = os.sep - - def __init__(self, path=None, expanduser=False): - """Initialize and return a local Path instance. - - Path can be relative to the current directory. - If path is None it defaults to the current working directory. - If expanduser is True, tilde-expansion is performed. - Note that Path instances always carry an absolute path. - Note also that passing in a local path object will simply return - the exact same path object. Use new() to get a new copy. - """ - if path is None: - self.strpath = error.checked_call(os.getcwd) - else: - try: - path = os.fspath(path) - except TypeError: - raise ValueError( - "can only pass None, Path instances " - "or non-empty strings to LocalPath" - ) - if expanduser: - path = os.path.expanduser(path) - self.strpath = abspath(path) - - if sys.platform != "win32": - - def chown(self, user, group, rec=0): - """Change ownership to the given user and group. - user and group may be specified by a number or - by a name. if rec is True change ownership - recursively. - """ - uid = getuserid(user) - gid = getgroupid(group) - if rec: - for x in self.visit(rec=lambda x: x.check(link=0)): - if x.check(link=0): - error.checked_call(os.chown, str(x), uid, gid) - error.checked_call(os.chown, str(self), uid, gid) - - def readlink(self) -> str: - """Return value of a symbolic link.""" - # https://github.com/python/mypy/issues/12278 - return error.checked_call(os.readlink, self.strpath) # type: ignore[arg-type,return-value,unused-ignore] - - def mklinkto(self, oldname): - """Posix style hard link to another name.""" - error.checked_call(os.link, str(oldname), str(self)) - - def mksymlinkto(self, value, absolute=1): - """Create a symbolic link with the given value (pointing to another name).""" - if absolute: - error.checked_call(os.symlink, str(value), self.strpath) - else: - base = self.common(value) - # with posix local paths '/' is always a common base - relsource = self.__class__(value).relto(base) - reldest = self.relto(base) - n = reldest.count(self.sep) - target = self.sep.join(("..",) * n + (relsource,)) - error.checked_call(os.symlink, target, self.strpath) - - def __div__(self, other): - return self.join(os.fspath(other)) - - __truediv__ = __div__ # py3k - - @property - def basename(self): - """Basename part of path.""" - return self._getbyspec("basename")[0] - - @property - def dirname(self): - """Dirname part of path.""" - return self._getbyspec("dirname")[0] - - @property - def purebasename(self): - """Pure base name of the path.""" - return self._getbyspec("purebasename")[0] - - @property - def ext(self): - """Extension of the path (including the '.').""" - return self._getbyspec("ext")[0] - - def read_binary(self): - """Read and return a bytestring from reading the path.""" - with self.open("rb") as f: - return f.read() - - def read_text(self, encoding): - """Read and return a Unicode string from reading the path.""" - with self.open("r", encoding=encoding) as f: - return f.read() - - def read(self, mode="r"): - """Read and return a bytestring from reading the path.""" - with self.open(mode) as f: - return f.read() - - def readlines(self, cr=1): - """Read and return a list of lines from the path. if cr is False, the - newline will be removed from the end of each line.""" - mode = "r" - - if not cr: - content = self.read(mode) - return content.split("\n") - else: - f = self.open(mode) - try: - return f.readlines() - finally: - f.close() - - def load(self): - """(deprecated) return object unpickled from self.read()""" - f = self.open("rb") - try: - import pickle - - return error.checked_call(pickle.load, f) - finally: - f.close() - - def move(self, target): - """Move this path to target.""" - if target.relto(self): - raise error.EINVAL(target, "cannot move path into a subdirectory of itself") - try: - self.rename(target) - except error.EXDEV: # invalid cross-device link - self.copy(target) - self.remove() - - def fnmatch(self, pattern): - """Return true if the basename/fullname matches the glob-'pattern'. - - valid pattern characters:: - - * matches everything - ? matches any single character - [seq] matches any character in seq - [!seq] matches any char not in seq - - If the pattern contains a path-separator then the full path - is used for pattern matching and a '*' is prepended to the - pattern. - - if the pattern doesn't contain a path-separator the pattern - is only matched against the basename. - """ - return FNMatcher(pattern)(self) - - def relto(self, relpath): - """Return a string which is the relative part of the path - to the given 'relpath'. - """ - if not isinstance(relpath, str | LocalPath): - raise TypeError(f"{relpath!r}: not a string or path object") - strrelpath = str(relpath) - if strrelpath and strrelpath[-1] != self.sep: - strrelpath += self.sep - # assert strrelpath[-1] == self.sep - # assert strrelpath[-2] != self.sep - strself = self.strpath - if sys.platform == "win32" or getattr(os, "_name", None) == "nt": - if os.path.normcase(strself).startswith(os.path.normcase(strrelpath)): - return strself[len(strrelpath) :] - elif strself.startswith(strrelpath): - return strself[len(strrelpath) :] - return "" - - def ensure_dir(self, *args): - """Ensure the path joined with args is a directory.""" - return self.ensure(*args, dir=True) - - def bestrelpath(self, dest): - """Return a string which is a relative path from self - (assumed to be a directory) to dest such that - self.join(bestrelpath) == dest and if not such - path can be determined return dest. - """ - try: - if self == dest: - return os.curdir - base = self.common(dest) - if not base: # can be the case on windows - return str(dest) - self2base = self.relto(base) - reldest = dest.relto(base) - if self2base: - n = self2base.count(self.sep) + 1 - else: - n = 0 - lst = [os.pardir] * n - if reldest: - lst.append(reldest) - target = dest.sep.join(lst) - return target - except AttributeError: - return str(dest) - - def exists(self): - return self.check() - - def isdir(self): - return self.check(dir=1) - - def isfile(self): - return self.check(file=1) - - def parts(self, reverse=False): - """Return a root-first list of all ancestor directories - plus the path itself. - """ - current = self - lst = [self] - while 1: - last = current - current = current.dirpath() - if last == current: - break - lst.append(current) - if not reverse: - lst.reverse() - return lst - - def common(self, other): - """Return the common part shared with the other path - or None if there is no common part. - """ - last = None - for x, y in zip(self.parts(), other.parts()): - if x != y: - return last - last = x - return last - - def __add__(self, other): - """Return new path object with 'other' added to the basename""" - return self.new(basename=self.basename + str(other)) - - def visit(self, fil=None, rec=None, ignore=NeverRaised, bf=False, sort=False): - """Yields all paths below the current one - - fil is a filter (glob pattern or callable), if not matching the - path will not be yielded, defaulting to None (everything is - returned) - - rec is a filter (glob pattern or callable) that controls whether - a node is descended, defaulting to None - - ignore is an Exception class that is ignoredwhen calling dirlist() - on any of the paths (by default, all exceptions are reported) - - bf if True will cause a breadthfirst search instead of the - default depthfirst. Default: False - - sort if True will sort entries within each directory level. - """ - yield from Visitor(fil, rec, ignore, bf, sort).gen(self) - - def _sortlist(self, res, sort): - if sort: - if hasattr(sort, "__call__"): - warnings.warn( - DeprecationWarning( - "listdir(sort=callable) is deprecated and breaks on python3" - ), - stacklevel=3, - ) - res.sort(sort) - else: - res.sort() - - def __fspath__(self): - return self.strpath - - def __hash__(self): - s = self.strpath - if iswin32: - s = s.lower() - return hash(s) - - def __eq__(self, other): - s1 = os.fspath(self) - try: - s2 = os.fspath(other) - except TypeError: - return False - if iswin32: - s1 = s1.lower() - try: - s2 = s2.lower() - except AttributeError: - return False - return s1 == s2 - - def __ne__(self, other): - return not (self == other) - - def __lt__(self, other): - return os.fspath(self) < os.fspath(other) - - def __gt__(self, other): - return os.fspath(self) > os.fspath(other) - - def samefile(self, other): - """Return True if 'other' references the same file as 'self'.""" - other = os.fspath(other) - if not isabs(other): - other = abspath(other) - if self == other: - return True - if not hasattr(os.path, "samefile"): - return False - return error.checked_call(os.path.samefile, self.strpath, other) - - def remove(self, rec=1, ignore_errors=False): - """Remove a file or directory (or a directory tree if rec=1). - if ignore_errors is True, errors while removing directories will - be ignored. - """ - if self.check(dir=1, link=0): - if rec: - # force remove of readonly files on windows - if iswin32: - self.chmod(0o700, rec=1) - import shutil - - error.checked_call( - shutil.rmtree, self.strpath, ignore_errors=ignore_errors - ) - else: - error.checked_call(os.rmdir, self.strpath) - else: - if iswin32: - self.chmod(0o700) - error.checked_call(os.remove, self.strpath) - - def computehash(self, hashtype="md5", chunksize=524288): - """Return hexdigest of hashvalue for this file.""" - try: - try: - import hashlib as mod - except ImportError: - if hashtype == "sha1": - hashtype = "sha" - mod = __import__(hashtype) - hash = getattr(mod, hashtype)() - except (AttributeError, ImportError): - raise ValueError(f"Don't know how to compute {hashtype!r} hash") - f = self.open("rb") - try: - while 1: - buf = f.read(chunksize) - if not buf: - return hash.hexdigest() - hash.update(buf) - finally: - f.close() - - def new(self, **kw): - """Create a modified version of this path. - the following keyword arguments modify various path parts:: - - a:/some/path/to/a/file.ext - xx drive - xxxxxxxxxxxxxxxxx dirname - xxxxxxxx basename - xxxx purebasename - xxx ext - """ - obj = object.__new__(self.__class__) - if not kw: - obj.strpath = self.strpath - return obj - drive, dirname, _basename, purebasename, ext = self._getbyspec( - "drive,dirname,basename,purebasename,ext" - ) - if "basename" in kw: - if "purebasename" in kw or "ext" in kw: - raise ValueError(f"invalid specification {kw!r}") - else: - pb = kw.setdefault("purebasename", purebasename) - try: - ext = kw["ext"] - except KeyError: - pass - else: - if ext and not ext.startswith("."): - ext = "." + ext - kw["basename"] = pb + ext - - if "dirname" in kw and not kw["dirname"]: - kw["dirname"] = drive - else: - kw.setdefault("dirname", dirname) - kw.setdefault("sep", self.sep) - obj.strpath = normpath("{dirname}{sep}{basename}".format(**kw)) - return obj - - def _getbyspec(self, spec: str) -> list[str]: - """See new for what 'spec' can be.""" - res = [] - parts = self.strpath.split(self.sep) - - args = filter(None, spec.split(",")) - for name in args: - if name == "drive": - res.append(parts[0]) - elif name == "dirname": - res.append(self.sep.join(parts[:-1])) - else: - basename = parts[-1] - if name == "basename": - res.append(basename) - else: - i = basename.rfind(".") - if i == -1: - purebasename, ext = basename, "" - else: - purebasename, ext = basename[:i], basename[i:] - if name == "purebasename": - res.append(purebasename) - elif name == "ext": - res.append(ext) - else: - raise ValueError(f"invalid part specification {name!r}") - return res - - def dirpath(self, *args, **kwargs): - """Return the directory path joined with any given path arguments.""" - if not kwargs: - path = object.__new__(self.__class__) - path.strpath = dirname(self.strpath) - if args: - path = path.join(*args) - return path - return self.new(basename="").join(*args, **kwargs) - - def join(self, *args: os.PathLike[str], abs: bool = False) -> LocalPath: - """Return a new path by appending all 'args' as path - components. if abs=1 is used restart from root if any - of the args is an absolute path. - """ - sep = self.sep - strargs = [os.fspath(arg) for arg in args] - strpath = self.strpath - if abs: - newargs: list[str] = [] - for arg in reversed(strargs): - if isabs(arg): - strpath = arg - strargs = newargs - break - newargs.insert(0, arg) - # special case for when we have e.g. strpath == "/" - actual_sep = "" if strpath.endswith(sep) else sep - for arg in strargs: - arg = arg.strip(sep) - if iswin32: - # allow unix style paths even on windows. - arg = arg.strip("/") - arg = arg.replace("/", sep) - strpath = strpath + actual_sep + arg - actual_sep = sep - obj = object.__new__(self.__class__) - obj.strpath = normpath(strpath) - return obj - - def open(self, mode="r", ensure=False, encoding=None): - """Return an opened file with the given mode. - - If ensure is True, create parent directories if needed. - """ - if ensure: - self.dirpath().ensure(dir=1) - if encoding: - return error.checked_call( - io.open, - self.strpath, - mode, - encoding=encoding, - ) - return error.checked_call(open, self.strpath, mode) - - def _fastjoin(self, name): - child = object.__new__(self.__class__) - child.strpath = self.strpath + self.sep + name - return child - - def islink(self): - return islink(self.strpath) - - def check(self, **kw): - """Check a path for existence and properties. - - Without arguments, return True if the path exists, otherwise False. - - valid checkers:: - - file = 1 # is a file - file = 0 # is not a file (may not even exist) - dir = 1 # is a dir - link = 1 # is a link - exists = 1 # exists - - You can specify multiple checker definitions, for example:: - - path.check(file=1, link=1) # a link pointing to a file - """ - if not kw: - return exists(self.strpath) - if len(kw) == 1: - if "dir" in kw: - return not kw["dir"] ^ isdir(self.strpath) - if "file" in kw: - return not kw["file"] ^ isfile(self.strpath) - if not kw: - kw = {"exists": 1} - return Checkers(self)._evaluate(kw) - - _patternchars = set("*?[" + os.sep) - - def listdir(self, fil=None, sort=None): - """List directory contents, possibly filter by the given fil func - and possibly sorted. - """ - if fil is None and sort is None: - names = error.checked_call(os.listdir, self.strpath) - return map_as_list(self._fastjoin, names) - if isinstance(fil, str): - if not self._patternchars.intersection(fil): - child = self._fastjoin(fil) - if exists(child.strpath): - return [child] - return [] - fil = FNMatcher(fil) - names = error.checked_call(os.listdir, self.strpath) - res = [] - for name in names: - child = self._fastjoin(name) - if fil is None or fil(child): - res.append(child) - self._sortlist(res, sort) - return res - - def size(self) -> int: - """Return size of the underlying file object""" - return self.stat().size - - def mtime(self) -> float: - """Return last modification time of the path.""" - return self.stat().mtime - - def copy(self, target, mode=False, stat=False): - """Copy path to target. - - If mode is True, will copy permission from path to target. - If stat is True, copy permission, last modification - time, last access time, and flags from path to target. - """ - if self.check(file=1): - if target.check(dir=1): - target = target.join(self.basename) - assert self != target - copychunked(self, target) - if mode: - copymode(self.strpath, target.strpath) - if stat: - copystat(self, target) - else: - - def rec(p): - return p.check(link=0) - - for x in self.visit(rec=rec): - relpath = x.relto(self) - newx = target.join(relpath) - newx.dirpath().ensure(dir=1) - if x.check(link=1): - newx.mksymlinkto(x.readlink()) - continue - elif x.check(file=1): - copychunked(x, newx) - elif x.check(dir=1): - newx.ensure(dir=1) - if mode: - copymode(x.strpath, newx.strpath) - if stat: - copystat(x, newx) - - def rename(self, target): - """Rename this path to target.""" - target = os.fspath(target) - return error.checked_call(os.rename, self.strpath, target) - - def dump(self, obj, bin=1): - """Pickle object into path location""" - f = self.open("wb") - import pickle - - try: - error.checked_call(pickle.dump, obj, f, bin) - finally: - f.close() - - def mkdir(self, *args): - """Create & return the directory joined with args.""" - p = self.join(*args) - error.checked_call(os.mkdir, os.fspath(p)) - return p - - def write_binary(self, data, ensure=False): - """Write binary data into path. If ensure is True create - missing parent directories. - """ - if ensure: - self.dirpath().ensure(dir=1) - with self.open("wb") as f: - f.write(data) - - def write_text(self, data, encoding, ensure=False): - """Write text data into path using the specified encoding. - If ensure is True create missing parent directories. - """ - if ensure: - self.dirpath().ensure(dir=1) - with self.open("w", encoding=encoding) as f: - f.write(data) - - def write(self, data, mode="w", ensure=False): - """Write data into path. If ensure is True create - missing parent directories. - """ - if ensure: - self.dirpath().ensure(dir=1) - if "b" in mode: - if not isinstance(data, bytes): - raise ValueError("can only process bytes") - else: - if not isinstance(data, str): - if not isinstance(data, bytes): - data = str(data) - else: - data = data.decode(sys.getdefaultencoding()) - f = self.open(mode) - try: - f.write(data) - finally: - f.close() - - def _ensuredirs(self): - parent = self.dirpath() - if parent == self: - return self - if parent.check(dir=0): - parent._ensuredirs() - if self.check(dir=0): - try: - self.mkdir() - except error.EEXIST: - # race condition: file/dir created by another thread/process. - # complain if it is not a dir - if self.check(dir=0): - raise - return self - - def ensure(self, *args, **kwargs): - """Ensure that an args-joined path exists (by default as - a file). if you specify a keyword argument 'dir=True' - then the path is forced to be a directory path. - """ - p = self.join(*args) - if kwargs.get("dir", 0): - return p._ensuredirs() - else: - p.dirpath()._ensuredirs() - if not p.check(file=1): - p.open("wb").close() - return p - - @overload - def stat(self, raising: Literal[True] = ...) -> Stat: ... - - @overload - def stat(self, raising: Literal[False]) -> Stat | None: ... - - def stat(self, raising: bool = True) -> Stat | None: - """Return an os.stat() tuple.""" - if raising: - return Stat(self, error.checked_call(os.stat, self.strpath)) - try: - return Stat(self, os.stat(self.strpath)) - except KeyboardInterrupt: - raise - except Exception: - return None - - def lstat(self) -> Stat: - """Return an os.lstat() tuple.""" - return Stat(self, error.checked_call(os.lstat, self.strpath)) - - def setmtime(self, mtime=None): - """Set modification time for the given path. if 'mtime' is None - (the default) then the file's mtime is set to current time. - - Note that the resolution for 'mtime' is platform dependent. - """ - if mtime is None: - return error.checked_call(os.utime, self.strpath, mtime) - try: - return error.checked_call(os.utime, self.strpath, (-1, mtime)) - except error.EINVAL: - return error.checked_call(os.utime, self.strpath, (self.atime(), mtime)) - - def chdir(self): - """Change directory to self and return old current directory""" - try: - old = self.__class__() - except error.ENOENT: - old = None - error.checked_call(os.chdir, self.strpath) - return old - - @contextmanager - def as_cwd(self): - """ - Return a context manager, which changes to the path's dir during the - managed "with" context. - On __enter__ it returns the old dir, which might be ``None``. - """ - old = self.chdir() - try: - yield old - finally: - if old is not None: - old.chdir() - - def realpath(self): - """Return a new path which contains no symbolic links.""" - return self.__class__(os.path.realpath(self.strpath)) - - def atime(self): - """Return last access time of the path.""" - return self.stat().atime - - def __repr__(self): - return f"local({self.strpath!r})" - - def __str__(self): - """Return string representation of the Path.""" - return self.strpath - - def chmod(self, mode, rec=0): - """Change permissions to the given mode. If mode is an - integer it directly encodes the os-specific modes. - if rec is True perform recursively. - """ - if not isinstance(mode, int): - raise TypeError(f"mode {mode!r} must be an integer") - if rec: - for x in self.visit(rec=rec): - error.checked_call(os.chmod, str(x), mode) - error.checked_call(os.chmod, self.strpath, mode) - - def pypkgpath(self): - """Return the Python package path by looking for the last - directory upwards which still contains an __init__.py. - Return None if a pkgpath cannot be determined. - """ - pkgpath = None - for parent in self.parts(reverse=True): - if parent.isdir(): - if not parent.join("__init__.py").exists(): - break - if not isimportable(parent.basename): - break - pkgpath = parent - return pkgpath - - def _ensuresyspath(self, ensuremode, path): - if ensuremode: - s = str(path) - if ensuremode == "append": - if s not in sys.path: - sys.path.append(s) - else: - if s != sys.path[0]: - sys.path.insert(0, s) - - def pyimport(self, modname=None, ensuresyspath=True): - """Return path as an imported python module. - - If modname is None, look for the containing package - and construct an according module name. - The module will be put/looked up in sys.modules. - if ensuresyspath is True then the root dir for importing - the file (taking __init__.py files into account) will - be prepended to sys.path if it isn't there already. - If ensuresyspath=="append" the root dir will be appended - if it isn't already contained in sys.path. - if ensuresyspath is False no modification of syspath happens. - - Special value of ensuresyspath=="importlib" is intended - purely for using in pytest, it is capable only of importing - separate .py files outside packages, e.g. for test suite - without any __init__.py file. It effectively allows having - same-named test modules in different places and offers - mild opt-in via this option. Note that it works only in - recent versions of python. - """ - if not self.check(): - raise error.ENOENT(self) - - if ensuresyspath == "importlib": - if modname is None: - modname = self.purebasename - spec = importlib.util.spec_from_file_location(modname, str(self)) - if spec is None or spec.loader is None: - raise ImportError(f"Can't find module {modname} at location {self!s}") - mod = importlib.util.module_from_spec(spec) - spec.loader.exec_module(mod) - return mod - - pkgpath = None - if modname is None: - pkgpath = self.pypkgpath() - if pkgpath is not None: - pkgroot = pkgpath.dirpath() - names = self.new(ext="").relto(pkgroot).split(self.sep) - if names[-1] == "__init__": - names.pop() - modname = ".".join(names) - else: - pkgroot = self.dirpath() - modname = self.purebasename - - self._ensuresyspath(ensuresyspath, pkgroot) - __import__(modname) - mod = sys.modules[modname] - if self.basename == "__init__.py": - return mod # we don't check anything as we might - # be in a namespace package ... too icky to check - modfile = mod.__file__ - assert modfile is not None - if modfile[-4:] in (".pyc", ".pyo"): - modfile = modfile[:-1] - elif modfile.endswith("$py.class"): - modfile = modfile[:-9] + ".py" - if modfile.endswith(os.sep + "__init__.py"): - if self.basename != "__init__.py": - modfile = modfile[:-12] - try: - issame = self.samefile(modfile) - except error.ENOENT: - issame = False - if not issame: - ignore = os.getenv("PY_IGNORE_IMPORTMISMATCH") - if ignore != "1": - raise self.ImportMismatchError(modname, modfile, self) - return mod - else: - try: - return sys.modules[modname] - except KeyError: - # we have a custom modname, do a pseudo-import - import types - - mod = types.ModuleType(modname) - mod.__file__ = str(self) - sys.modules[modname] = mod - try: - with open(str(self), "rb") as f: - exec(f.read(), mod.__dict__) - except BaseException: - del sys.modules[modname] - raise - return mod - - def sysexec(self, *argv: os.PathLike[str], **popen_opts: Any) -> str: - """Return stdout text from executing a system child process, - where the 'self' path points to executable. - The process is directly invoked and not through a system shell. - """ - from subprocess import PIPE - from subprocess import Popen - - popen_opts.pop("stdout", None) - popen_opts.pop("stderr", None) - proc = Popen( - [str(self)] + [str(arg) for arg in argv], - **popen_opts, - stdout=PIPE, - stderr=PIPE, - ) - stdout: str | bytes - stdout, stderr = proc.communicate() - ret = proc.wait() - if isinstance(stdout, bytes): - stdout = stdout.decode(sys.getdefaultencoding()) - if ret != 0: - if isinstance(stderr, bytes): - stderr = stderr.decode(sys.getdefaultencoding()) - raise RuntimeError( - ret, - ret, - str(self), - stdout, - stderr, - ) - return stdout - - @classmethod - def sysfind(cls, name, checker=None, paths=None): - """Return a path object found by looking at the systems - underlying PATH specification. If the checker is not None - it will be invoked to filter matching paths. If a binary - cannot be found, None is returned - Note: This is probably not working on plain win32 systems - but may work on cygwin. - """ - if isabs(name): - p = local(name) - if p.check(file=1): - return p - else: - if paths is None: - if iswin32: - paths = os.environ["Path"].split(";") - if "" not in paths and "." not in paths: - paths.append(".") - try: - systemroot = os.environ["SYSTEMROOT"] - except KeyError: - pass - else: - paths = [ - path.replace("%SystemRoot%", systemroot) for path in paths - ] - else: - paths = os.environ["PATH"].split(":") - tryadd = [] - if iswin32: - tryadd += os.environ["PATHEXT"].split(os.pathsep) - tryadd.append("") - - for x in paths: - for addext in tryadd: - p = local(x).join(name, abs=True) + addext - try: - if p.check(file=1): - if checker: - if not checker(p): - continue - return p - except error.EACCES: - pass - return None - - @classmethod - def _gethomedir(cls): - try: - x = os.environ["HOME"] - except KeyError: - try: - x = os.environ["HOMEDRIVE"] + os.environ["HOMEPATH"] - except KeyError: - return None - return cls(x) - - # """ - # special class constructors for local filesystem paths - # """ - @classmethod - def get_temproot(cls): - """Return the system's temporary directory - (where tempfiles are usually created in) - """ - import tempfile - - return local(tempfile.gettempdir()) - - @classmethod - def mkdtemp(cls, rootdir=None): - """Return a Path object pointing to a fresh new temporary directory - (which we created ourselves). - """ - import tempfile - - if rootdir is None: - rootdir = cls.get_temproot() - path = error.checked_call(tempfile.mkdtemp, dir=str(rootdir)) - return cls(path) - - @classmethod - def make_numbered_dir( - cls, prefix="session-", rootdir=None, keep=3, lock_timeout=172800 - ): # two days - """Return unique directory with a number greater than the current - maximum one. The number is assumed to start directly after prefix. - if keep is true directories with a number less than (maxnum-keep) - will be removed. If .lock files are used (lock_timeout non-zero), - algorithm is multi-process safe. - """ - if rootdir is None: - rootdir = cls.get_temproot() - - nprefix = prefix.lower() - - def parse_num(path): - """Parse the number out of a path (if it matches the prefix)""" - nbasename = path.basename.lower() - if nbasename.startswith(nprefix): - try: - return int(nbasename[len(nprefix) :]) - except ValueError: - pass - - def create_lockfile(path): - """Exclusively create lockfile. Throws when failed""" - mypid = os.getpid() - lockfile = path.join(".lock") - if hasattr(lockfile, "mksymlinkto"): - lockfile.mksymlinkto(str(mypid)) - else: - fd = error.checked_call( - os.open, str(lockfile), os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o644 - ) - with os.fdopen(fd, "w") as f: - f.write(str(mypid)) - return lockfile - - def atexit_remove_lockfile(lockfile): - """Ensure lockfile is removed at process exit""" - mypid = os.getpid() - - def try_remove_lockfile(): - # in a fork() situation, only the last process should - # remove the .lock, otherwise the other processes run the - # risk of seeing their temporary dir disappear. For now - # we remove the .lock in the parent only (i.e. we assume - # that the children finish before the parent). - if os.getpid() != mypid: - return - try: - lockfile.remove() - except error.Error: - pass - - atexit.register(try_remove_lockfile) - - # compute the maximum number currently in use with the prefix - lastmax = None - while True: - maxnum = -1 - for path in rootdir.listdir(): - num = parse_num(path) - if num is not None: - maxnum = max(maxnum, num) - - # make the new directory - try: - udir = rootdir.mkdir(prefix + str(maxnum + 1)) - if lock_timeout: - lockfile = create_lockfile(udir) - atexit_remove_lockfile(lockfile) - except (error.EEXIST, error.ENOENT, error.EBUSY): - # race condition (1): another thread/process created the dir - # in the meantime - try again - # race condition (2): another thread/process spuriously acquired - # lock treating empty directory as candidate - # for removal - try again - # race condition (3): another thread/process tried to create the lock at - # the same time (happened in Python 3.3 on Windows) - # https://ci.appveyor.com/project/pytestbot/py/build/1.0.21/job/ffi85j4c0lqwsfwa - if lastmax == maxnum: - raise - lastmax = maxnum - continue - break - - def get_mtime(path): - """Read file modification time""" - try: - return path.lstat().mtime - except error.Error: - pass - - garbage_prefix = prefix + "garbage-" - - def is_garbage(path): - """Check if path denotes directory scheduled for removal""" - bn = path.basename - return bn.startswith(garbage_prefix) - - # prune old directories - udir_time = get_mtime(udir) - if keep and udir_time: - for path in rootdir.listdir(): - num = parse_num(path) - if num is not None and num <= (maxnum - keep): - try: - # try acquiring lock to remove directory as exclusive user - if lock_timeout: - create_lockfile(path) - except (error.EEXIST, error.ENOENT, error.EBUSY): - path_time = get_mtime(path) - if not path_time: - # assume directory doesn't exist now - continue - if abs(udir_time - path_time) < lock_timeout: - # assume directory with lockfile exists - # and lock timeout hasn't expired yet - continue - - # path dir locked for exclusive use - # and scheduled for removal to avoid another thread/process - # treating it as a new directory or removal candidate - garbage_path = rootdir.join(garbage_prefix + str(uuid.uuid4())) - try: - path.rename(garbage_path) - garbage_path.remove(rec=1) - except KeyboardInterrupt: - raise - except Exception: # this might be error.Error, WindowsError ... - pass - if is_garbage(path): - try: - path.remove(rec=1) - except KeyboardInterrupt: - raise - except Exception: # this might be error.Error, WindowsError ... - pass - - # make link... - try: - username = os.environ["USER"] # linux, et al - except KeyError: - try: - username = os.environ["USERNAME"] # windows - except KeyError: - username = "current" - - src = str(udir) - dest = src[: src.rfind("-")] + "-" + username - try: - os.unlink(dest) - except OSError: - pass - try: - os.symlink(src, dest) - except (OSError, AttributeError, NotImplementedError): - pass - - return udir - - -def copymode(src, dest): - """Copy permission from src to dst.""" - import shutil - - shutil.copymode(src, dest) - - -def copystat(src, dest): - """Copy permission, last modification time, - last access time, and flags from src to dst.""" - import shutil - - shutil.copystat(str(src), str(dest)) - - -def copychunked(src, dest): - chunksize = 524288 # half a meg of bytes - fsrc = src.open("rb") - try: - fdest = dest.open("wb") - try: - while 1: - buf = fsrc.read(chunksize) - if not buf: - break - fdest.write(buf) - finally: - fdest.close() - finally: - fsrc.close() - - -def isimportable(name): - if name and (name[0].isalpha() or name[0] == "_"): - name = name.replace("_", "") - return not name or name.isalnum() - - -local = LocalPath diff --git a/.venv/lib/python3.12/site-packages/_pytest/_version.py b/.venv/lib/python3.12/site-packages/_pytest/_version.py deleted file mode 100644 index 98976dd..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/_version.py +++ /dev/null @@ -1,24 +0,0 @@ -# file generated by vcs-versioning -# don't change, don't track in version control -from __future__ import annotations - -__all__ = [ - "__version__", - "__version_tuple__", - "version", - "version_tuple", - "__commit_id__", - "commit_id", -] - -version: str -__version__: str -__version_tuple__: tuple[int | str, ...] -version_tuple: tuple[int | str, ...] -commit_id: str | None -__commit_id__: str | None - -__version__ = version = '9.0.3' -__version_tuple__ = version_tuple = (9, 0, 3) - -__commit_id__ = commit_id = None diff --git a/.venv/lib/python3.12/site-packages/_pytest/assertion/__init__.py b/.venv/lib/python3.12/site-packages/_pytest/assertion/__init__.py deleted file mode 100644 index 22f3ca8..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/assertion/__init__.py +++ /dev/null @@ -1,208 +0,0 @@ -# mypy: allow-untyped-defs -"""Support for presenting detailed information in failing assertions.""" - -from __future__ import annotations - -from collections.abc import Generator -import sys -from typing import Any -from typing import Protocol -from typing import TYPE_CHECKING - -from _pytest.assertion import rewrite -from _pytest.assertion import truncate -from _pytest.assertion import util -from _pytest.assertion.rewrite import assertstate_key -from _pytest.config import Config -from _pytest.config import hookimpl -from _pytest.config.argparsing import Parser -from _pytest.nodes import Item - - -if TYPE_CHECKING: - from _pytest.main import Session - - -def pytest_addoption(parser: Parser) -> None: - group = parser.getgroup("debugconfig") - group.addoption( - "--assert", - action="store", - dest="assertmode", - choices=("rewrite", "plain"), - default="rewrite", - metavar="MODE", - help=( - "Control assertion debugging tools.\n" - "'plain' performs no assertion debugging.\n" - "'rewrite' (the default) rewrites assert statements in test modules" - " on import to provide assert expression information." - ), - ) - parser.addini( - "enable_assertion_pass_hook", - type="bool", - default=False, - help="Enables the pytest_assertion_pass hook. " - "Make sure to delete any previously generated pyc cache files.", - ) - - parser.addini( - "truncation_limit_lines", - default=None, - help="Set threshold of LINES after which truncation will take effect", - ) - parser.addini( - "truncation_limit_chars", - default=None, - help=("Set threshold of CHARS after which truncation will take effect"), - ) - - Config._add_verbosity_ini( - parser, - Config.VERBOSITY_ASSERTIONS, - help=( - "Specify a verbosity level for assertions, overriding the main level. " - "Higher levels will provide more detailed explanation when an assertion fails." - ), - ) - - -def register_assert_rewrite(*names: str) -> None: - """Register one or more module names to be rewritten on import. - - This function will make sure that this module or all modules inside - the package will get their assert statements rewritten. - Thus you should make sure to call this before the module is - actually imported, usually in your __init__.py if you are a plugin - using a package. - - :param names: The module names to register. - """ - for name in names: - if not isinstance(name, str): - msg = "expected module names as *args, got {0} instead" # type: ignore[unreachable] - raise TypeError(msg.format(repr(names))) - rewrite_hook: RewriteHook - for hook in sys.meta_path: - if isinstance(hook, rewrite.AssertionRewritingHook): - rewrite_hook = hook - break - else: - rewrite_hook = DummyRewriteHook() - rewrite_hook.mark_rewrite(*names) - - -class RewriteHook(Protocol): - def mark_rewrite(self, *names: str) -> None: ... - - -class DummyRewriteHook: - """A no-op import hook for when rewriting is disabled.""" - - def mark_rewrite(self, *names: str) -> None: - pass - - -class AssertionState: - """State for the assertion plugin.""" - - def __init__(self, config: Config, mode) -> None: - self.mode = mode - self.trace = config.trace.root.get("assertion") - self.hook: rewrite.AssertionRewritingHook | None = None - - -def install_importhook(config: Config) -> rewrite.AssertionRewritingHook: - """Try to install the rewrite hook, raise SystemError if it fails.""" - config.stash[assertstate_key] = AssertionState(config, "rewrite") - config.stash[assertstate_key].hook = hook = rewrite.AssertionRewritingHook(config) - sys.meta_path.insert(0, hook) - config.stash[assertstate_key].trace("installed rewrite import hook") - - def undo() -> None: - hook = config.stash[assertstate_key].hook - if hook is not None and hook in sys.meta_path: - sys.meta_path.remove(hook) - - config.add_cleanup(undo) - return hook - - -def pytest_collection(session: Session) -> None: - # This hook is only called when test modules are collected - # so for example not in the managing process of pytest-xdist - # (which does not collect test modules). - assertstate = session.config.stash.get(assertstate_key, None) - if assertstate: - if assertstate.hook is not None: - assertstate.hook.set_session(session) - - -@hookimpl(wrapper=True, tryfirst=True) -def pytest_runtest_protocol(item: Item) -> Generator[None, object, object]: - """Setup the pytest_assertrepr_compare and pytest_assertion_pass hooks. - - The rewrite module will use util._reprcompare if it exists to use custom - reporting via the pytest_assertrepr_compare hook. This sets up this custom - comparison for the test. - """ - ihook = item.ihook - - def callbinrepr(op, left: object, right: object) -> str | None: - """Call the pytest_assertrepr_compare hook and prepare the result. - - This uses the first result from the hook and then ensures the - following: - * Overly verbose explanations are truncated unless configured otherwise - (eg. if running in verbose mode). - * Embedded newlines are escaped to help util.format_explanation() - later. - * If the rewrite mode is used embedded %-characters are replaced - to protect later % formatting. - - The result can be formatted by util.format_explanation() for - pretty printing. - """ - hook_result = ihook.pytest_assertrepr_compare( - config=item.config, op=op, left=left, right=right - ) - for new_expl in hook_result: - if new_expl: - new_expl = truncate.truncate_if_required(new_expl, item) - new_expl = [line.replace("\n", "\\n") for line in new_expl] - res = "\n~".join(new_expl) - if item.config.getvalue("assertmode") == "rewrite": - res = res.replace("%", "%%") - return res - return None - - saved_assert_hooks = util._reprcompare, util._assertion_pass - util._reprcompare = callbinrepr - util._config = item.config - - if ihook.pytest_assertion_pass.get_hookimpls(): - - def call_assertion_pass_hook(lineno: int, orig: str, expl: str) -> None: - ihook.pytest_assertion_pass(item=item, lineno=lineno, orig=orig, expl=expl) - - util._assertion_pass = call_assertion_pass_hook - - try: - return (yield) - finally: - util._reprcompare, util._assertion_pass = saved_assert_hooks - util._config = None - - -def pytest_sessionfinish(session: Session) -> None: - assertstate = session.config.stash.get(assertstate_key, None) - if assertstate: - if assertstate.hook is not None: - assertstate.hook.set_session(None) - - -def pytest_assertrepr_compare( - config: Config, op: str, left: Any, right: Any -) -> list[str] | None: - return util.assertrepr_compare(config=config, op=op, left=left, right=right) diff --git a/.venv/lib/python3.12/site-packages/_pytest/assertion/rewrite.py b/.venv/lib/python3.12/site-packages/_pytest/assertion/rewrite.py deleted file mode 100644 index 566549d..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/assertion/rewrite.py +++ /dev/null @@ -1,1202 +0,0 @@ -"""Rewrite assertion AST to produce nice error messages.""" - -from __future__ import annotations - -import ast -from collections import defaultdict -from collections.abc import Callable -from collections.abc import Iterable -from collections.abc import Iterator -from collections.abc import Sequence -import errno -import functools -import importlib.abc -import importlib.machinery -import importlib.util -import io -import itertools -import marshal -import os -from pathlib import Path -from pathlib import PurePath -import struct -import sys -import tokenize -import types -from typing import IO -from typing import TYPE_CHECKING - - -if sys.version_info >= (3, 12): - from importlib.resources.abc import TraversableResources -else: - from importlib.abc import TraversableResources -if sys.version_info < (3, 11): - from importlib.readers import FileReader -else: - from importlib.resources.readers import FileReader - - -from _pytest._io.saferepr import DEFAULT_REPR_MAX_SIZE -from _pytest._io.saferepr import saferepr -from _pytest._io.saferepr import saferepr_unlimited -from _pytest._version import version -from _pytest.assertion import util -from _pytest.config import Config -from _pytest.fixtures import FixtureFunctionDefinition -from _pytest.main import Session -from _pytest.pathlib import absolutepath -from _pytest.pathlib import fnmatch_ex -from _pytest.stash import StashKey - - -# fmt: off -from _pytest.assertion.util import format_explanation as _format_explanation # noqa:F401, isort:skip -# fmt:on - -if TYPE_CHECKING: - from _pytest.assertion import AssertionState - - -class Sentinel: - pass - - -assertstate_key = StashKey["AssertionState"]() - -# pytest caches rewritten pycs in pycache dirs -PYTEST_TAG = f"{sys.implementation.cache_tag}-pytest-{version}" -PYC_EXT = ".py" + ((__debug__ and "c") or "o") -PYC_TAIL = "." + PYTEST_TAG + PYC_EXT - -# Special marker that denotes we have just left a scope definition -_SCOPE_END_MARKER = Sentinel() - - -class AssertionRewritingHook(importlib.abc.MetaPathFinder, importlib.abc.Loader): - """PEP302/PEP451 import hook which rewrites asserts.""" - - def __init__(self, config: Config) -> None: - self.config = config - try: - self.fnpats = config.getini("python_files") - except ValueError: - self.fnpats = ["test_*.py", "*_test.py"] - self.session: Session | None = None - self._rewritten_names: dict[str, Path] = {} - self._must_rewrite: set[str] = set() - # flag to guard against trying to rewrite a pyc file while we are already writing another pyc file, - # which might result in infinite recursion (#3506) - self._writing_pyc = False - self._basenames_to_check_rewrite = {"conftest"} - self._marked_for_rewrite_cache: dict[str, bool] = {} - self._session_paths_checked = False - - def set_session(self, session: Session | None) -> None: - self.session = session - self._session_paths_checked = False - - # Indirection so we can mock calls to find_spec originated from the hook during testing - _find_spec = importlib.machinery.PathFinder.find_spec - - def find_spec( - self, - name: str, - path: Sequence[str | bytes] | None = None, - target: types.ModuleType | None = None, - ) -> importlib.machinery.ModuleSpec | None: - if self._writing_pyc: - return None - state = self.config.stash[assertstate_key] - if self._early_rewrite_bailout(name, state): - return None - state.trace(f"find_module called for: {name}") - - # Type ignored because mypy is confused about the `self` binding here. - spec = self._find_spec(name, path) # type: ignore - - if spec is None and path is not None: - # With --import-mode=importlib, PathFinder cannot find spec without modifying `sys.path`, - # causing inability to assert rewriting (#12659). - # At this point, try using the file path to find the module spec. - for _path_str in path: - spec = importlib.util.spec_from_file_location(name, _path_str) - if spec is not None: - break - - if ( - # the import machinery could not find a file to import - spec is None - # this is a namespace package (without `__init__.py`) - # there's nothing to rewrite there - or spec.origin is None - # we can only rewrite source files - or not isinstance(spec.loader, importlib.machinery.SourceFileLoader) - # if the file doesn't exist, we can't rewrite it - or not os.path.exists(spec.origin) - ): - return None - else: - fn = spec.origin - - if not self._should_rewrite(name, fn, state): - return None - - return importlib.util.spec_from_file_location( - name, - fn, - loader=self, - submodule_search_locations=spec.submodule_search_locations, - ) - - def create_module( - self, spec: importlib.machinery.ModuleSpec - ) -> types.ModuleType | None: - return None # default behaviour is fine - - def exec_module(self, module: types.ModuleType) -> None: - assert module.__spec__ is not None - assert module.__spec__.origin is not None - fn = Path(module.__spec__.origin) - state = self.config.stash[assertstate_key] - - self._rewritten_names[module.__name__] = fn - - # The requested module looks like a test file, so rewrite it. This is - # the most magical part of the process: load the source, rewrite the - # asserts, and load the rewritten source. We also cache the rewritten - # module code in a special pyc. We must be aware of the possibility of - # concurrent pytest processes rewriting and loading pycs. To avoid - # tricky race conditions, we maintain the following invariant: The - # cached pyc is always a complete, valid pyc. Operations on it must be - # atomic. POSIX's atomic rename comes in handy. - write = not sys.dont_write_bytecode - cache_dir = get_cache_dir(fn) - if write: - ok = try_makedirs(cache_dir) - if not ok: - write = False - state.trace(f"read only directory: {cache_dir}") - - cache_name = fn.name[:-3] + PYC_TAIL - pyc = cache_dir / cache_name - # Notice that even if we're in a read-only directory, I'm going - # to check for a cached pyc. This may not be optimal... - co = _read_pyc(fn, pyc, state.trace) - if co is None: - state.trace(f"rewriting {fn!r}") - source_stat, co = _rewrite_test(fn, self.config) - if write: - self._writing_pyc = True - try: - _write_pyc(state, co, source_stat, pyc) - finally: - self._writing_pyc = False - else: - state.trace(f"found cached rewritten pyc for {fn}") - exec(co, module.__dict__) - - def _early_rewrite_bailout(self, name: str, state: AssertionState) -> bool: - """A fast way to get out of rewriting modules. - - Profiling has shown that the call to PathFinder.find_spec (inside of - the find_spec from this class) is a major slowdown, so, this method - tries to filter what we're sure won't be rewritten before getting to - it. - """ - if self.session is not None and not self._session_paths_checked: - self._session_paths_checked = True - for initial_path in self.session._initialpaths: - # Make something as c:/projects/my_project/path.py -> - # ['c:', 'projects', 'my_project', 'path.py'] - parts = str(initial_path).split(os.sep) - # add 'path' to basenames to be checked. - self._basenames_to_check_rewrite.add(os.path.splitext(parts[-1])[0]) - - # Note: conftest already by default in _basenames_to_check_rewrite. - parts = name.split(".") - if parts[-1] in self._basenames_to_check_rewrite: - return False - - # For matching the name it must be as if it was a filename. - path = PurePath(*parts).with_suffix(".py") - - for pat in self.fnpats: - # if the pattern contains subdirectories ("tests/**.py" for example) we can't bail out based - # on the name alone because we need to match against the full path - if os.path.dirname(pat): - return False - if fnmatch_ex(pat, path): - return False - - if self._is_marked_for_rewrite(name, state): - return False - - state.trace(f"early skip of rewriting module: {name}") - return True - - def _should_rewrite(self, name: str, fn: str, state: AssertionState) -> bool: - # always rewrite conftest files - if os.path.basename(fn) == "conftest.py": - state.trace(f"rewriting conftest file: {fn!r}") - return True - - if self.session is not None: - if self.session.isinitpath(absolutepath(fn)): - state.trace(f"matched test file (was specified on cmdline): {fn!r}") - return True - - # modules not passed explicitly on the command line are only - # rewritten if they match the naming convention for test files - fn_path = PurePath(fn) - for pat in self.fnpats: - if fnmatch_ex(pat, fn_path): - state.trace(f"matched test file {fn!r}") - return True - - return self._is_marked_for_rewrite(name, state) - - def _is_marked_for_rewrite(self, name: str, state: AssertionState) -> bool: - try: - return self._marked_for_rewrite_cache[name] - except KeyError: - for marked in self._must_rewrite: - if name == marked or name.startswith(marked + "."): - state.trace(f"matched marked file {name!r} (from {marked!r})") - self._marked_for_rewrite_cache[name] = True - return True - - self._marked_for_rewrite_cache[name] = False - return False - - def mark_rewrite(self, *names: str) -> None: - """Mark import names as needing to be rewritten. - - The named module or package as well as any nested modules will - be rewritten on import. - """ - already_imported = ( - set(names).intersection(sys.modules).difference(self._rewritten_names) - ) - for name in already_imported: - mod = sys.modules[name] - if not AssertionRewriter.is_rewrite_disabled( - mod.__doc__ or "" - ) and not isinstance(mod.__loader__, type(self)): - self._warn_already_imported(name) - self._must_rewrite.update(names) - self._marked_for_rewrite_cache.clear() - - def _warn_already_imported(self, name: str) -> None: - from _pytest.warning_types import PytestAssertRewriteWarning - - self.config.issue_config_time_warning( - PytestAssertRewriteWarning( - f"Module already imported so cannot be rewritten; {name}" - ), - stacklevel=5, - ) - - def get_data(self, pathname: str | bytes) -> bytes: - """Optional PEP302 get_data API.""" - with open(pathname, "rb") as f: - return f.read() - - def get_resource_reader(self, name: str) -> TraversableResources: - return FileReader(types.SimpleNamespace(path=self._rewritten_names[name])) # type: ignore[arg-type] - - -def _write_pyc_fp( - fp: IO[bytes], source_stat: os.stat_result, co: types.CodeType -) -> None: - # Technically, we don't have to have the same pyc format as - # (C)Python, since these "pycs" should never be seen by builtin - # import. However, there's little reason to deviate. - fp.write(importlib.util.MAGIC_NUMBER) - # https://www.python.org/dev/peps/pep-0552/ - flags = b"\x00\x00\x00\x00" - fp.write(flags) - # as of now, bytecode header expects 32-bit numbers for size and mtime (#4903) - mtime = int(source_stat.st_mtime) & 0xFFFFFFFF - size = source_stat.st_size & 0xFFFFFFFF - # " bool: - proc_pyc = f"{pyc}.{os.getpid()}" - try: - with open(proc_pyc, "wb") as fp: - _write_pyc_fp(fp, source_stat, co) - except OSError as e: - state.trace(f"error writing pyc file at {proc_pyc}: errno={e.errno}") - return False - - try: - os.replace(proc_pyc, pyc) - except OSError as e: - state.trace(f"error writing pyc file at {pyc}: {e}") - # we ignore any failure to write the cache file - # there are many reasons, permission-denied, pycache dir being a - # file etc. - return False - return True - - -def _rewrite_test(fn: Path, config: Config) -> tuple[os.stat_result, types.CodeType]: - """Read and rewrite *fn* and return the code object.""" - stat = os.stat(fn) - source = fn.read_bytes() - strfn = str(fn) - tree = ast.parse(source, filename=strfn) - rewrite_asserts(tree, source, strfn, config) - co = compile(tree, strfn, "exec", dont_inherit=True) - return stat, co - - -def _read_pyc( - source: Path, pyc: Path, trace: Callable[[str], None] = lambda x: None -) -> types.CodeType | None: - """Possibly read a pytest pyc containing rewritten code. - - Return rewritten code if successful or None if not. - """ - try: - fp = open(pyc, "rb") - except OSError: - return None - with fp: - try: - stat_result = os.stat(source) - mtime = int(stat_result.st_mtime) - size = stat_result.st_size - data = fp.read(16) - except OSError as e: - trace(f"_read_pyc({source}): OSError {e}") - return None - # Check for invalid or out of date pyc file. - if len(data) != (16): - trace(f"_read_pyc({source}): invalid pyc (too short)") - return None - if data[:4] != importlib.util.MAGIC_NUMBER: - trace(f"_read_pyc({source}): invalid pyc (bad magic number)") - return None - if data[4:8] != b"\x00\x00\x00\x00": - trace(f"_read_pyc({source}): invalid pyc (unsupported flags)") - return None - mtime_data = data[8:12] - if int.from_bytes(mtime_data, "little") != mtime & 0xFFFFFFFF: - trace(f"_read_pyc({source}): out of date") - return None - size_data = data[12:16] - if int.from_bytes(size_data, "little") != size & 0xFFFFFFFF: - trace(f"_read_pyc({source}): invalid pyc (incorrect size)") - return None - try: - co = marshal.load(fp) - except Exception as e: - trace(f"_read_pyc({source}): marshal.load error {e}") - return None - if not isinstance(co, types.CodeType): - trace(f"_read_pyc({source}): not a code object") - return None - return co - - -def rewrite_asserts( - mod: ast.Module, - source: bytes, - module_path: str | None = None, - config: Config | None = None, -) -> None: - """Rewrite the assert statements in mod.""" - AssertionRewriter(module_path, config, source).run(mod) - - -def _saferepr(obj: object) -> str: - r"""Get a safe repr of an object for assertion error messages. - - The assertion formatting (util.format_explanation()) requires - newlines to be escaped since they are a special character for it. - Normally assertion.util.format_explanation() does this but for a - custom repr it is possible to contain one of the special escape - sequences, especially '\n{' and '\n}' are likely to be present in - JSON reprs. - """ - if isinstance(obj, types.MethodType): - # for bound methods, skip redundant information - return obj.__name__ - - maxsize = _get_maxsize_for_saferepr(util._config) - if not maxsize: - return saferepr_unlimited(obj).replace("\n", "\\n") - return saferepr(obj, maxsize=maxsize).replace("\n", "\\n") - - -def _get_maxsize_for_saferepr(config: Config | None) -> int | None: - """Get `maxsize` configuration for saferepr based on the given config object.""" - if config is None: - verbosity = 0 - else: - verbosity = config.get_verbosity(Config.VERBOSITY_ASSERTIONS) - if verbosity >= 2: - return None - if verbosity >= 1: - return DEFAULT_REPR_MAX_SIZE * 10 - return DEFAULT_REPR_MAX_SIZE - - -def _format_assertmsg(obj: object) -> str: - r"""Format the custom assertion message given. - - For strings this simply replaces newlines with '\n~' so that - util.format_explanation() will preserve them instead of escaping - newlines. For other objects saferepr() is used first. - """ - # reprlib appears to have a bug which means that if a string - # contains a newline it gets escaped, however if an object has a - # .__repr__() which contains newlines it does not get escaped. - # However in either case we want to preserve the newline. - replaces = [("\n", "\n~"), ("%", "%%")] - if not isinstance(obj, str): - obj = saferepr(obj, _get_maxsize_for_saferepr(util._config)) - replaces.append(("\\n", "\n~")) - - for r1, r2 in replaces: - obj = obj.replace(r1, r2) - - return obj - - -def _should_repr_global_name(obj: object) -> bool: - if callable(obj): - # For pytest fixtures the __repr__ method provides more information than the function name. - return isinstance(obj, FixtureFunctionDefinition) - - try: - return not hasattr(obj, "__name__") - except Exception: - return True - - -def _format_boolop(explanations: Iterable[str], is_or: bool) -> str: - explanation = "(" + ((is_or and " or ") or " and ").join(explanations) + ")" - return explanation.replace("%", "%%") - - -def _call_reprcompare( - ops: Sequence[str], - results: Sequence[bool], - expls: Sequence[str], - each_obj: Sequence[object], -) -> str: - for i, res, expl in zip(range(len(ops)), results, expls, strict=True): - try: - done = not res - except Exception: - done = True - if done: - break - if util._reprcompare is not None: - custom = util._reprcompare(ops[i], each_obj[i], each_obj[i + 1]) - if custom is not None: - return custom - return expl - - -def _call_assertion_pass(lineno: int, orig: str, expl: str) -> None: - if util._assertion_pass is not None: - util._assertion_pass(lineno, orig, expl) - - -def _check_if_assertion_pass_impl() -> bool: - """Check if any plugins implement the pytest_assertion_pass hook - in order not to generate explanation unnecessarily (might be expensive).""" - return True if util._assertion_pass else False - - -UNARY_MAP = {ast.Not: "not %s", ast.Invert: "~%s", ast.USub: "-%s", ast.UAdd: "+%s"} - -BINOP_MAP = { - ast.BitOr: "|", - ast.BitXor: "^", - ast.BitAnd: "&", - ast.LShift: "<<", - ast.RShift: ">>", - ast.Add: "+", - ast.Sub: "-", - ast.Mult: "*", - ast.Div: "/", - ast.FloorDiv: "//", - ast.Mod: "%%", # escaped for string formatting - ast.Eq: "==", - ast.NotEq: "!=", - ast.Lt: "<", - ast.LtE: "<=", - ast.Gt: ">", - ast.GtE: ">=", - ast.Pow: "**", - ast.Is: "is", - ast.IsNot: "is not", - ast.In: "in", - ast.NotIn: "not in", - ast.MatMult: "@", -} - - -def traverse_node(node: ast.AST) -> Iterator[ast.AST]: - """Recursively yield node and all its children in depth-first order.""" - yield node - for child in ast.iter_child_nodes(node): - yield from traverse_node(child) - - -@functools.lru_cache(maxsize=1) -def _get_assertion_exprs(src: bytes) -> dict[int, str]: - """Return a mapping from {lineno: "assertion test expression"}.""" - ret: dict[int, str] = {} - - depth = 0 - lines: list[str] = [] - assert_lineno: int | None = None - seen_lines: set[int] = set() - - def _write_and_reset() -> None: - nonlocal depth, lines, assert_lineno, seen_lines - assert assert_lineno is not None - ret[assert_lineno] = "".join(lines).rstrip().rstrip("\\") - depth = 0 - lines = [] - assert_lineno = None - seen_lines = set() - - tokens = tokenize.tokenize(io.BytesIO(src).readline) - for tp, source, (lineno, offset), _, line in tokens: - if tp == tokenize.NAME and source == "assert": - assert_lineno = lineno - elif assert_lineno is not None: - # keep track of depth for the assert-message `,` lookup - if tp == tokenize.OP and source in "([{": - depth += 1 - elif tp == tokenize.OP and source in ")]}": - depth -= 1 - - if not lines: - lines.append(line[offset:]) - seen_lines.add(lineno) - # a non-nested comma separates the expression from the message - elif depth == 0 and tp == tokenize.OP and source == ",": - # one line assert with message - if lineno in seen_lines and len(lines) == 1: - offset_in_trimmed = offset + len(lines[-1]) - len(line) - lines[-1] = lines[-1][:offset_in_trimmed] - # multi-line assert with message - elif lineno in seen_lines: - lines[-1] = lines[-1][:offset] - # multi line assert with escaped newline before message - else: - lines.append(line[:offset]) - _write_and_reset() - elif tp in {tokenize.NEWLINE, tokenize.ENDMARKER}: - _write_and_reset() - elif lines and lineno not in seen_lines: - lines.append(line) - seen_lines.add(lineno) - - return ret - - -class AssertionRewriter(ast.NodeVisitor): - """Assertion rewriting implementation. - - The main entrypoint is to call .run() with an ast.Module instance, - this will then find all the assert statements and rewrite them to - provide intermediate values and a detailed assertion error. See - http://pybites.blogspot.be/2011/07/behind-scenes-of-pytests-new-assertion.html - for an overview of how this works. - - The entry point here is .run() which will iterate over all the - statements in an ast.Module and for each ast.Assert statement it - finds call .visit() with it. Then .visit_Assert() takes over and - is responsible for creating new ast statements to replace the - original assert statement: it rewrites the test of an assertion - to provide intermediate values and replace it with an if statement - which raises an assertion error with a detailed explanation in - case the expression is false and calls pytest_assertion_pass hook - if expression is true. - - For this .visit_Assert() uses the visitor pattern to visit all the - AST nodes of the ast.Assert.test field, each visit call returning - an AST node and the corresponding explanation string. During this - state is kept in several instance attributes: - - :statements: All the AST statements which will replace the assert - statement. - - :variables: This is populated by .variable() with each variable - used by the statements so that they can all be set to None at - the end of the statements. - - :variable_counter: Counter to create new unique variables needed - by statements. Variables are created using .variable() and - have the form of "@py_assert0". - - :expl_stmts: The AST statements which will be executed to get - data from the assertion. This is the code which will construct - the detailed assertion message that is used in the AssertionError - or for the pytest_assertion_pass hook. - - :explanation_specifiers: A dict filled by .explanation_param() - with %-formatting placeholders and their corresponding - expressions to use in the building of an assertion message. - This is used by .pop_format_context() to build a message. - - :stack: A stack of the explanation_specifiers dicts maintained by - .push_format_context() and .pop_format_context() which allows - to build another %-formatted string while already building one. - - :scope: A tuple containing the current scope used for variables_overwrite. - - :variables_overwrite: A dict filled with references to variables - that change value within an assert. This happens when a variable is - reassigned with the walrus operator - - This state, except the variables_overwrite, is reset on every new assert - statement visited and used by the other visitors. - """ - - def __init__( - self, module_path: str | None, config: Config | None, source: bytes - ) -> None: - super().__init__() - self.module_path = module_path - self.config = config - if config is not None: - self.enable_assertion_pass_hook = config.getini( - "enable_assertion_pass_hook" - ) - else: - self.enable_assertion_pass_hook = False - self.source = source - self.scope: tuple[ast.AST, ...] = () - self.variables_overwrite: defaultdict[tuple[ast.AST, ...], dict[str, str]] = ( - defaultdict(dict) - ) - - def run(self, mod: ast.Module) -> None: - """Find all assert statements in *mod* and rewrite them.""" - if not mod.body: - # Nothing to do. - return - - # We'll insert some special imports at the top of the module, but after any - # docstrings and __future__ imports, so first figure out where that is. - doc = getattr(mod, "docstring", None) - expect_docstring = doc is None - if doc is not None and self.is_rewrite_disabled(doc): - return - pos = 0 - for item in mod.body: - match item: - case ast.Expr(value=ast.Constant(value=str() as doc)) if ( - expect_docstring - ): - if self.is_rewrite_disabled(doc): - return - expect_docstring = False - case ast.ImportFrom(level=0, module="__future__"): - pass - case _: - break - pos += 1 - # Special case: for a decorated function, set the lineno to that of the - # first decorator, not the `def`. Issue #4984. - if isinstance(item, ast.FunctionDef) and item.decorator_list: - lineno = item.decorator_list[0].lineno - else: - lineno = item.lineno - # Now actually insert the special imports. - aliases = [ - ast.alias("builtins", "@py_builtins", lineno=lineno, col_offset=0), - ast.alias( - "_pytest.assertion.rewrite", - "@pytest_ar", - lineno=lineno, - col_offset=0, - ), - ] - imports = [ - ast.Import([alias], lineno=lineno, col_offset=0) for alias in aliases - ] - mod.body[pos:pos] = imports - - # Collect asserts. - self.scope = (mod,) - nodes: list[ast.AST | Sentinel] = [mod] - while nodes: - node = nodes.pop() - if isinstance(node, ast.FunctionDef | ast.AsyncFunctionDef | ast.ClassDef): - self.scope = tuple((*self.scope, node)) - nodes.append(_SCOPE_END_MARKER) - if node == _SCOPE_END_MARKER: - self.scope = self.scope[:-1] - continue - assert isinstance(node, ast.AST) - for name, field in ast.iter_fields(node): - if isinstance(field, list): - new: list[ast.AST] = [] - for i, child in enumerate(field): - if isinstance(child, ast.Assert): - # Transform assert. - new.extend(self.visit(child)) - else: - new.append(child) - if isinstance(child, ast.AST): - nodes.append(child) - setattr(node, name, new) - elif ( - isinstance(field, ast.AST) - # Don't recurse into expressions as they can't contain - # asserts. - and not isinstance(field, ast.expr) - ): - nodes.append(field) - - @staticmethod - def is_rewrite_disabled(docstring: str) -> bool: - return "PYTEST_DONT_REWRITE" in docstring - - def variable(self) -> str: - """Get a new variable.""" - # Use a character invalid in python identifiers to avoid clashing. - name = "@py_assert" + str(next(self.variable_counter)) - self.variables.append(name) - return name - - def assign(self, expr: ast.expr) -> ast.Name: - """Give *expr* a name.""" - name = self.variable() - self.statements.append(ast.Assign([ast.Name(name, ast.Store())], expr)) - return ast.copy_location(ast.Name(name, ast.Load()), expr) - - def display(self, expr: ast.expr) -> ast.expr: - """Call saferepr on the expression.""" - return self.helper("_saferepr", expr) - - def helper(self, name: str, *args: ast.expr) -> ast.expr: - """Call a helper in this module.""" - py_name = ast.Name("@pytest_ar", ast.Load()) - attr = ast.Attribute(py_name, name, ast.Load()) - return ast.Call(attr, list(args), []) - - def builtin(self, name: str) -> ast.Attribute: - """Return the builtin called *name*.""" - builtin_name = ast.Name("@py_builtins", ast.Load()) - return ast.Attribute(builtin_name, name, ast.Load()) - - def explanation_param(self, expr: ast.expr) -> str: - """Return a new named %-formatting placeholder for expr. - - This creates a %-formatting placeholder for expr in the - current formatting context, e.g. ``%(py0)s``. The placeholder - and expr are placed in the current format context so that it - can be used on the next call to .pop_format_context(). - """ - specifier = "py" + str(next(self.variable_counter)) - self.explanation_specifiers[specifier] = expr - return "%(" + specifier + ")s" - - def push_format_context(self) -> None: - """Create a new formatting context. - - The format context is used for when an explanation wants to - have a variable value formatted in the assertion message. In - this case the value required can be added using - .explanation_param(). Finally .pop_format_context() is used - to format a string of %-formatted values as added by - .explanation_param(). - """ - self.explanation_specifiers: dict[str, ast.expr] = {} - self.stack.append(self.explanation_specifiers) - - def pop_format_context(self, expl_expr: ast.expr) -> ast.Name: - """Format the %-formatted string with current format context. - - The expl_expr should be an str ast.expr instance constructed from - the %-placeholders created by .explanation_param(). This will - add the required code to format said string to .expl_stmts and - return the ast.Name instance of the formatted string. - """ - current = self.stack.pop() - if self.stack: - self.explanation_specifiers = self.stack[-1] - keys: list[ast.expr | None] = [ast.Constant(key) for key in current.keys()] - format_dict = ast.Dict(keys, list(current.values())) - form = ast.BinOp(expl_expr, ast.Mod(), format_dict) - name = "@py_format" + str(next(self.variable_counter)) - if self.enable_assertion_pass_hook: - self.format_variables.append(name) - self.expl_stmts.append(ast.Assign([ast.Name(name, ast.Store())], form)) - return ast.Name(name, ast.Load()) - - def generic_visit(self, node: ast.AST) -> tuple[ast.Name, str]: - """Handle expressions we don't have custom code for.""" - assert isinstance(node, ast.expr) - res = self.assign(node) - return res, self.explanation_param(self.display(res)) - - def visit_Assert(self, assert_: ast.Assert) -> list[ast.stmt]: - """Return the AST statements to replace the ast.Assert instance. - - This rewrites the test of an assertion to provide - intermediate values and replace it with an if statement which - raises an assertion error with a detailed explanation in case - the expression is false. - """ - if isinstance(assert_.test, ast.Tuple) and len(assert_.test.elts) >= 1: - import warnings - - from _pytest.warning_types import PytestAssertRewriteWarning - - # TODO: This assert should not be needed. - assert self.module_path is not None - warnings.warn_explicit( - PytestAssertRewriteWarning( - "assertion is always true, perhaps remove parentheses?" - ), - category=None, - filename=self.module_path, - lineno=assert_.lineno, - ) - - self.statements: list[ast.stmt] = [] - self.variables: list[str] = [] - self.variable_counter = itertools.count() - - if self.enable_assertion_pass_hook: - self.format_variables: list[str] = [] - - self.stack: list[dict[str, ast.expr]] = [] - self.expl_stmts: list[ast.stmt] = [] - self.push_format_context() - # Rewrite assert into a bunch of statements. - top_condition, explanation = self.visit(assert_.test) - - negation = ast.UnaryOp(ast.Not(), top_condition) - - if self.enable_assertion_pass_hook: # Experimental pytest_assertion_pass hook - msg = self.pop_format_context(ast.Constant(explanation)) - - # Failed - if assert_.msg: - assertmsg = self.helper("_format_assertmsg", assert_.msg) - gluestr = "\n>assert " - else: - assertmsg = ast.Constant("") - gluestr = "assert " - err_explanation = ast.BinOp(ast.Constant(gluestr), ast.Add(), msg) - err_msg = ast.BinOp(assertmsg, ast.Add(), err_explanation) - err_name = ast.Name("AssertionError", ast.Load()) - fmt = self.helper("_format_explanation", err_msg) - exc = ast.Call(err_name, [fmt], []) - raise_ = ast.Raise(exc, None) - statements_fail = [] - statements_fail.extend(self.expl_stmts) - statements_fail.append(raise_) - - # Passed - fmt_pass = self.helper("_format_explanation", msg) - orig = _get_assertion_exprs(self.source)[assert_.lineno] - hook_call_pass = ast.Expr( - self.helper( - "_call_assertion_pass", - ast.Constant(assert_.lineno), - ast.Constant(orig), - fmt_pass, - ) - ) - # If any hooks implement assert_pass hook - hook_impl_test = ast.If( - self.helper("_check_if_assertion_pass_impl"), - [*self.expl_stmts, hook_call_pass], - [], - ) - statements_pass: list[ast.stmt] = [hook_impl_test] - - # Test for assertion condition - main_test = ast.If(negation, statements_fail, statements_pass) - self.statements.append(main_test) - if self.format_variables: - variables: list[ast.expr] = [ - ast.Name(name, ast.Store()) for name in self.format_variables - ] - clear_format = ast.Assign(variables, ast.Constant(None)) - self.statements.append(clear_format) - - else: # Original assertion rewriting - # Create failure message. - body = self.expl_stmts - self.statements.append(ast.If(negation, body, [])) - if assert_.msg: - assertmsg = self.helper("_format_assertmsg", assert_.msg) - explanation = "\n>assert " + explanation - else: - assertmsg = ast.Constant("") - explanation = "assert " + explanation - template = ast.BinOp(assertmsg, ast.Add(), ast.Constant(explanation)) - msg = self.pop_format_context(template) - fmt = self.helper("_format_explanation", msg) - err_name = ast.Name("AssertionError", ast.Load()) - exc = ast.Call(err_name, [fmt], []) - raise_ = ast.Raise(exc, None) - - body.append(raise_) - - # Clear temporary variables by setting them to None. - if self.variables: - variables = [ast.Name(name, ast.Store()) for name in self.variables] - clear = ast.Assign(variables, ast.Constant(None)) - self.statements.append(clear) - # Fix locations (line numbers/column offsets). - for stmt in self.statements: - for node in traverse_node(stmt): - if getattr(node, "lineno", None) is None: - # apply the assertion location to all generated ast nodes without source location - # and preserve the location of existing nodes or generated nodes with an correct location. - ast.copy_location(node, assert_) - return self.statements - - def visit_NamedExpr(self, name: ast.NamedExpr) -> tuple[ast.NamedExpr, str]: - # This method handles the 'walrus operator' repr of the target - # name if it's a local variable or _should_repr_global_name() - # thinks it's acceptable. - locs = ast.Call(self.builtin("locals"), [], []) - target_id = name.target.id - inlocs = ast.Compare(ast.Constant(target_id), [ast.In()], [locs]) - dorepr = self.helper("_should_repr_global_name", name) - test = ast.BoolOp(ast.Or(), [inlocs, dorepr]) - expr = ast.IfExp(test, self.display(name), ast.Constant(target_id)) - return name, self.explanation_param(expr) - - def visit_Name(self, name: ast.Name) -> tuple[ast.Name, str]: - # Display the repr of the name if it's a local variable or - # _should_repr_global_name() thinks it's acceptable. - locs = ast.Call(self.builtin("locals"), [], []) - inlocs = ast.Compare(ast.Constant(name.id), [ast.In()], [locs]) - dorepr = self.helper("_should_repr_global_name", name) - test = ast.BoolOp(ast.Or(), [inlocs, dorepr]) - expr = ast.IfExp(test, self.display(name), ast.Constant(name.id)) - return name, self.explanation_param(expr) - - def visit_BoolOp(self, boolop: ast.BoolOp) -> tuple[ast.Name, str]: - res_var = self.variable() - expl_list = self.assign(ast.List([], ast.Load())) - app = ast.Attribute(expl_list, "append", ast.Load()) - is_or = int(isinstance(boolop.op, ast.Or)) - body = save = self.statements - fail_save = self.expl_stmts - levels = len(boolop.values) - 1 - self.push_format_context() - # Process each operand, short-circuiting if needed. - for i, v in enumerate(boolop.values): - if i: - fail_inner: list[ast.stmt] = [] - # cond is set in a prior loop iteration below - self.expl_stmts.append(ast.If(cond, fail_inner, [])) # noqa: F821 - self.expl_stmts = fail_inner - match v: - # Check if the left operand is an ast.NamedExpr and the value has already been visited - case ast.Compare( - left=ast.NamedExpr(target=ast.Name(id=target_id)) - ) if target_id in [ - e.id for e in boolop.values[:i] if hasattr(e, "id") - ]: - pytest_temp = self.variable() - self.variables_overwrite[self.scope][target_id] = v.left # type:ignore[assignment] - # mypy's false positive, we're checking that the 'target' attribute exists. - v.left.target.id = pytest_temp # type:ignore[attr-defined] - self.push_format_context() - res, expl = self.visit(v) - body.append(ast.Assign([ast.Name(res_var, ast.Store())], res)) - expl_format = self.pop_format_context(ast.Constant(expl)) - call = ast.Call(app, [expl_format], []) - self.expl_stmts.append(ast.Expr(call)) - if i < levels: - cond: ast.expr = res - if is_or: - cond = ast.UnaryOp(ast.Not(), cond) - inner: list[ast.stmt] = [] - self.statements.append(ast.If(cond, inner, [])) - self.statements = body = inner - self.statements = save - self.expl_stmts = fail_save - expl_template = self.helper("_format_boolop", expl_list, ast.Constant(is_or)) - expl = self.pop_format_context(expl_template) - return ast.Name(res_var, ast.Load()), self.explanation_param(expl) - - def visit_UnaryOp(self, unary: ast.UnaryOp) -> tuple[ast.Name, str]: - pattern = UNARY_MAP[unary.op.__class__] - operand_res, operand_expl = self.visit(unary.operand) - res = self.assign(ast.copy_location(ast.UnaryOp(unary.op, operand_res), unary)) - return res, pattern % (operand_expl,) - - def visit_BinOp(self, binop: ast.BinOp) -> tuple[ast.Name, str]: - symbol = BINOP_MAP[binop.op.__class__] - left_expr, left_expl = self.visit(binop.left) - right_expr, right_expl = self.visit(binop.right) - explanation = f"({left_expl} {symbol} {right_expl})" - res = self.assign( - ast.copy_location(ast.BinOp(left_expr, binop.op, right_expr), binop) - ) - return res, explanation - - def visit_Call(self, call: ast.Call) -> tuple[ast.Name, str]: - new_func, func_expl = self.visit(call.func) - arg_expls = [] - new_args = [] - new_kwargs = [] - for arg in call.args: - if isinstance(arg, ast.Name) and arg.id in self.variables_overwrite.get( - self.scope, {} - ): - arg = self.variables_overwrite[self.scope][arg.id] # type:ignore[assignment] - res, expl = self.visit(arg) - arg_expls.append(expl) - new_args.append(res) - for keyword in call.keywords: - match keyword.value: - case ast.Name(id=id) if id in self.variables_overwrite.get( - self.scope, {} - ): - keyword.value = self.variables_overwrite[self.scope][id] # type:ignore[assignment] - res, expl = self.visit(keyword.value) - new_kwargs.append(ast.keyword(keyword.arg, res)) - if keyword.arg: - arg_expls.append(keyword.arg + "=" + expl) - else: # **args have `arg` keywords with an .arg of None - arg_expls.append("**" + expl) - - expl = "{}({})".format(func_expl, ", ".join(arg_expls)) - new_call = ast.copy_location(ast.Call(new_func, new_args, new_kwargs), call) - res = self.assign(new_call) - res_expl = self.explanation_param(self.display(res)) - outer_expl = f"{res_expl}\n{{{res_expl} = {expl}\n}}" - return res, outer_expl - - def visit_Starred(self, starred: ast.Starred) -> tuple[ast.Starred, str]: - # A Starred node can appear in a function call. - res, expl = self.visit(starred.value) - new_starred = ast.Starred(res, starred.ctx) - return new_starred, "*" + expl - - def visit_Attribute(self, attr: ast.Attribute) -> tuple[ast.Name, str]: - if not isinstance(attr.ctx, ast.Load): - return self.generic_visit(attr) - value, value_expl = self.visit(attr.value) - res = self.assign( - ast.copy_location(ast.Attribute(value, attr.attr, ast.Load()), attr) - ) - res_expl = self.explanation_param(self.display(res)) - pat = "%s\n{%s = %s.%s\n}" - expl = pat % (res_expl, res_expl, value_expl, attr.attr) - return res, expl - - def visit_Compare(self, comp: ast.Compare) -> tuple[ast.expr, str]: - self.push_format_context() - # We first check if we have overwritten a variable in the previous assert - match comp.left: - case ast.Name(id=name_id) if name_id in self.variables_overwrite.get( - self.scope, {} - ): - comp.left = self.variables_overwrite[self.scope][name_id] # type: ignore[assignment] - case ast.NamedExpr(target=ast.Name(id=target_id)): - self.variables_overwrite[self.scope][target_id] = comp.left # type: ignore[assignment] - left_res, left_expl = self.visit(comp.left) - if isinstance(comp.left, ast.Compare | ast.BoolOp): - left_expl = f"({left_expl})" - res_variables = [self.variable() for i in range(len(comp.ops))] - load_names: list[ast.expr] = [ast.Name(v, ast.Load()) for v in res_variables] - store_names = [ast.Name(v, ast.Store()) for v in res_variables] - it = zip(range(len(comp.ops)), comp.ops, comp.comparators, strict=True) - expls: list[ast.expr] = [] - syms: list[ast.expr] = [] - results = [left_res] - for i, op, next_operand in it: - match (next_operand, left_res): - case ( - ast.NamedExpr(target=ast.Name(id=target_id)), - ast.Name(id=name_id), - ) if target_id == name_id: - next_operand.target.id = self.variable() - self.variables_overwrite[self.scope][name_id] = next_operand # type: ignore[assignment] - - next_res, next_expl = self.visit(next_operand) - if isinstance(next_operand, ast.Compare | ast.BoolOp): - next_expl = f"({next_expl})" - results.append(next_res) - sym = BINOP_MAP[op.__class__] - syms.append(ast.Constant(sym)) - expl = f"{left_expl} {sym} {next_expl}" - expls.append(ast.Constant(expl)) - res_expr = ast.copy_location(ast.Compare(left_res, [op], [next_res]), comp) - self.statements.append(ast.Assign([store_names[i]], res_expr)) - left_res, left_expl = next_res, next_expl - # Use pytest.assertion.util._reprcompare if that's available. - expl_call = self.helper( - "_call_reprcompare", - ast.Tuple(syms, ast.Load()), - ast.Tuple(load_names, ast.Load()), - ast.Tuple(expls, ast.Load()), - ast.Tuple(results, ast.Load()), - ) - if len(comp.ops) > 1: - res: ast.expr = ast.BoolOp(ast.And(), load_names) - else: - res = load_names[0] - - return res, self.explanation_param(self.pop_format_context(expl_call)) - - -def try_makedirs(cache_dir: Path) -> bool: - """Attempt to create the given directory and sub-directories exist. - - Returns True if successful or if it already exists. - """ - try: - os.makedirs(cache_dir, exist_ok=True) - except (FileNotFoundError, NotADirectoryError, FileExistsError): - # One of the path components was not a directory: - # - we're in a zip file - # - it is a file - return False - except PermissionError: - return False - except OSError as e: - # as of now, EROFS doesn't have an equivalent OSError-subclass - # - # squashfuse_ll returns ENOSYS "OSError: [Errno 38] Function not - # implemented" for a read-only error - if e.errno in {errno.EROFS, errno.ENOSYS}: - return False - raise - return True - - -def get_cache_dir(file_path: Path) -> Path: - """Return the cache directory to write .pyc files for the given .py file path.""" - if sys.pycache_prefix: - # given: - # prefix = '/tmp/pycs' - # path = '/home/user/proj/test_app.py' - # we want: - # '/tmp/pycs/home/user/proj' - return Path(sys.pycache_prefix) / Path(*file_path.parts[1:-1]) - else: - # classic pycache directory - return file_path.parent / "__pycache__" diff --git a/.venv/lib/python3.12/site-packages/_pytest/assertion/truncate.py b/.venv/lib/python3.12/site-packages/_pytest/assertion/truncate.py deleted file mode 100644 index 5820e6e..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/assertion/truncate.py +++ /dev/null @@ -1,137 +0,0 @@ -"""Utilities for truncating assertion output. - -Current default behaviour is to truncate assertion explanations at -terminal lines, unless running with an assertions verbosity level of at least 2 or running on CI. -""" - -from __future__ import annotations - -from _pytest.compat import running_on_ci -from _pytest.config import Config -from _pytest.nodes import Item - - -DEFAULT_MAX_LINES = 8 -DEFAULT_MAX_CHARS = DEFAULT_MAX_LINES * 80 -USAGE_MSG = "use '-vv' to show" - - -def truncate_if_required(explanation: list[str], item: Item) -> list[str]: - """Truncate this assertion explanation if the given test item is eligible.""" - should_truncate, max_lines, max_chars = _get_truncation_parameters(item) - if should_truncate: - return _truncate_explanation( - explanation, - max_lines=max_lines, - max_chars=max_chars, - ) - return explanation - - -def _get_truncation_parameters(item: Item) -> tuple[bool, int, int]: - """Return the truncation parameters related to the given item, as (should truncate, max lines, max chars).""" - # We do not need to truncate if one of conditions is met: - # 1. Verbosity level is 2 or more; - # 2. Test is being run in CI environment; - # 3. Both truncation_limit_lines and truncation_limit_chars - # .ini parameters are set to 0 explicitly. - max_lines = item.config.getini("truncation_limit_lines") - max_lines = int(max_lines if max_lines is not None else DEFAULT_MAX_LINES) - - max_chars = item.config.getini("truncation_limit_chars") - max_chars = int(max_chars if max_chars is not None else DEFAULT_MAX_CHARS) - - verbose = item.config.get_verbosity(Config.VERBOSITY_ASSERTIONS) - - should_truncate = verbose < 2 and not running_on_ci() - should_truncate = should_truncate and (max_lines > 0 or max_chars > 0) - - return should_truncate, max_lines, max_chars - - -def _truncate_explanation( - input_lines: list[str], - max_lines: int, - max_chars: int, -) -> list[str]: - """Truncate given list of strings that makes up the assertion explanation. - - Truncates to either max_lines, or max_chars - whichever the input reaches - first, taking the truncation explanation into account. The remaining lines - will be replaced by a usage message. - """ - # Check if truncation required - input_char_count = len("".join(input_lines)) - # The length of the truncation explanation depends on the number of lines - # removed but is at least 68 characters: - # The real value is - # 64 (for the base message: - # '...\n...Full output truncated (1 line hidden), use '-vv' to show")' - # ) - # + 1 (for plural) - # + int(math.log10(len(input_lines) - max_lines)) (number of hidden line, at least 1) - # + 3 for the '...' added to the truncated line - # But if there's more than 100 lines it's very likely that we're going to - # truncate, so we don't need the exact value using log10. - tolerable_max_chars = ( - max_chars + 70 # 64 + 1 (for plural) + 2 (for '99') + 3 for '...' - ) - # The truncation explanation add two lines to the output - tolerable_max_lines = max_lines + 2 - if ( - len(input_lines) <= tolerable_max_lines - and input_char_count <= tolerable_max_chars - ): - return input_lines - # Truncate first to max_lines, and then truncate to max_chars if necessary - if max_lines > 0: - truncated_explanation = input_lines[:max_lines] - else: - truncated_explanation = input_lines - truncated_char = True - # We reevaluate the need to truncate chars following removal of some lines - if len("".join(truncated_explanation)) > tolerable_max_chars and max_chars > 0: - truncated_explanation = _truncate_by_char_count( - truncated_explanation, max_chars - ) - else: - truncated_char = False - - if truncated_explanation == input_lines: - # No truncation happened, so we do not need to add any explanations - return truncated_explanation - - truncated_line_count = len(input_lines) - len(truncated_explanation) - if truncated_explanation[-1]: - # Add ellipsis and take into account part-truncated final line - truncated_explanation[-1] = truncated_explanation[-1] + "..." - if truncated_char: - # It's possible that we did not remove any char from this line - truncated_line_count += 1 - else: - # Add proper ellipsis when we were able to fit a full line exactly - truncated_explanation[-1] = "..." - return [ - *truncated_explanation, - "", - f"...Full output truncated ({truncated_line_count} line" - f"{'' if truncated_line_count == 1 else 's'} hidden), {USAGE_MSG}", - ] - - -def _truncate_by_char_count(input_lines: list[str], max_chars: int) -> list[str]: - # Find point at which input length exceeds total allowed length - iterated_char_count = 0 - for iterated_index, input_line in enumerate(input_lines): - if iterated_char_count + len(input_line) > max_chars: - break - iterated_char_count += len(input_line) - - # Create truncated explanation with modified final line - truncated_result = input_lines[:iterated_index] - final_line = input_lines[iterated_index] - if final_line: - final_line_truncate_point = max_chars - iterated_char_count - final_line = final_line[:final_line_truncate_point] - truncated_result.append(final_line) - return truncated_result diff --git a/.venv/lib/python3.12/site-packages/_pytest/assertion/util.py b/.venv/lib/python3.12/site-packages/_pytest/assertion/util.py deleted file mode 100644 index f35d83a..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/assertion/util.py +++ /dev/null @@ -1,615 +0,0 @@ -# mypy: allow-untyped-defs -"""Utilities for assertion debugging.""" - -from __future__ import annotations - -import collections.abc -from collections.abc import Callable -from collections.abc import Iterable -from collections.abc import Mapping -from collections.abc import Sequence -from collections.abc import Set as AbstractSet -import pprint -from typing import Any -from typing import Literal -from typing import Protocol -from unicodedata import normalize - -from _pytest import outcomes -import _pytest._code -from _pytest._io.pprint import PrettyPrinter -from _pytest._io.saferepr import saferepr -from _pytest._io.saferepr import saferepr_unlimited -from _pytest.compat import running_on_ci -from _pytest.config import Config - - -# The _reprcompare attribute on the util module is used by the new assertion -# interpretation code and assertion rewriter to detect this plugin was -# loaded and in turn call the hooks defined here as part of the -# DebugInterpreter. -_reprcompare: Callable[[str, object, object], str | None] | None = None - -# Works similarly as _reprcompare attribute. Is populated with the hook call -# when pytest_runtest_setup is called. -_assertion_pass: Callable[[int, str, str], None] | None = None - -# Config object which is assigned during pytest_runtest_protocol. -_config: Config | None = None - - -class _HighlightFunc(Protocol): - def __call__(self, source: str, lexer: Literal["diff", "python"] = "python") -> str: - """Apply highlighting to the given source.""" - - -def dummy_highlighter(source: str, lexer: Literal["diff", "python"] = "python") -> str: - """Dummy highlighter that returns the text unprocessed. - - Needed for _notin_text, as the diff gets post-processed to only show the "+" part. - """ - return source - - -def format_explanation(explanation: str) -> str: - r"""Format an explanation. - - Normally all embedded newlines are escaped, however there are - three exceptions: \n{, \n} and \n~. The first two are intended - cover nested explanations, see function and attribute explanations - for examples (.visit_Call(), visit_Attribute()). The last one is - for when one explanation needs to span multiple lines, e.g. when - displaying diffs. - """ - lines = _split_explanation(explanation) - result = _format_lines(lines) - return "\n".join(result) - - -def _split_explanation(explanation: str) -> list[str]: - r"""Return a list of individual lines in the explanation. - - This will return a list of lines split on '\n{', '\n}' and '\n~'. - Any other newlines will be escaped and appear in the line as the - literal '\n' characters. - """ - raw_lines = (explanation or "").split("\n") - lines = [raw_lines[0]] - for values in raw_lines[1:]: - if values and values[0] in ["{", "}", "~", ">"]: - lines.append(values) - else: - lines[-1] += "\\n" + values - return lines - - -def _format_lines(lines: Sequence[str]) -> list[str]: - """Format the individual lines. - - This will replace the '{', '}' and '~' characters of our mini formatting - language with the proper 'where ...', 'and ...' and ' + ...' text, taking - care of indentation along the way. - - Return a list of formatted lines. - """ - result = list(lines[:1]) - stack = [0] - stackcnt = [0] - for line in lines[1:]: - if line.startswith("{"): - if stackcnt[-1]: - s = "and " - else: - s = "where " - stack.append(len(result)) - stackcnt[-1] += 1 - stackcnt.append(0) - result.append(" +" + " " * (len(stack) - 1) + s + line[1:]) - elif line.startswith("}"): - stack.pop() - stackcnt.pop() - result[stack[-1]] += line[1:] - else: - assert line[0] in ["~", ">"] - stack[-1] += 1 - indent = len(stack) if line.startswith("~") else len(stack) - 1 - result.append(" " * indent + line[1:]) - assert len(stack) == 1 - return result - - -def issequence(x: Any) -> bool: - return isinstance(x, collections.abc.Sequence) and not isinstance(x, str) - - -def istext(x: Any) -> bool: - return isinstance(x, str) - - -def isdict(x: Any) -> bool: - return isinstance(x, dict) - - -def isset(x: Any) -> bool: - return isinstance(x, set | frozenset) - - -def isnamedtuple(obj: Any) -> bool: - return isinstance(obj, tuple) and getattr(obj, "_fields", None) is not None - - -def isdatacls(obj: Any) -> bool: - return getattr(obj, "__dataclass_fields__", None) is not None - - -def isattrs(obj: Any) -> bool: - return getattr(obj, "__attrs_attrs__", None) is not None - - -def isiterable(obj: Any) -> bool: - try: - iter(obj) - return not istext(obj) - except Exception: - return False - - -def has_default_eq( - obj: object, -) -> bool: - """Check if an instance of an object contains the default eq - - First, we check if the object's __eq__ attribute has __code__, - if so, we check the equally of the method code filename (__code__.co_filename) - to the default one generated by the dataclass and attr module - for dataclasses the default co_filename is , for attrs class, the __eq__ should contain "attrs eq generated" - """ - # inspired from https://github.com/willmcgugan/rich/blob/07d51ffc1aee6f16bd2e5a25b4e82850fb9ed778/rich/pretty.py#L68 - if hasattr(obj.__eq__, "__code__") and hasattr(obj.__eq__.__code__, "co_filename"): - code_filename = obj.__eq__.__code__.co_filename - - if isattrs(obj): - return "attrs generated " in code_filename - - return code_filename == "" # data class - return True - - -def assertrepr_compare( - config, op: str, left: Any, right: Any, use_ascii: bool = False -) -> list[str] | None: - """Return specialised explanations for some operators/operands.""" - verbose = config.get_verbosity(Config.VERBOSITY_ASSERTIONS) - - # Strings which normalize equal are often hard to distinguish when printed; use ascii() to make this easier. - # See issue #3246. - use_ascii = ( - isinstance(left, str) - and isinstance(right, str) - and normalize("NFD", left) == normalize("NFD", right) - ) - - if verbose > 1: - left_repr = saferepr_unlimited(left, use_ascii=use_ascii) - right_repr = saferepr_unlimited(right, use_ascii=use_ascii) - else: - # XXX: "15 chars indentation" is wrong - # ("E AssertionError: assert "); should use term width. - maxsize = ( - 80 - 15 - len(op) - 2 - ) // 2 # 15 chars indentation, 1 space around op - - left_repr = saferepr(left, maxsize=maxsize, use_ascii=use_ascii) - right_repr = saferepr(right, maxsize=maxsize, use_ascii=use_ascii) - - summary = f"{left_repr} {op} {right_repr}" - highlighter = config.get_terminal_writer()._highlight - - explanation = None - try: - if op == "==": - explanation = _compare_eq_any(left, right, highlighter, verbose) - elif op == "not in": - if istext(left) and istext(right): - explanation = _notin_text(left, right, verbose) - elif op == "!=": - if isset(left) and isset(right): - explanation = ["Both sets are equal"] - elif op == ">=": - if isset(left) and isset(right): - explanation = _compare_gte_set(left, right, highlighter, verbose) - elif op == "<=": - if isset(left) and isset(right): - explanation = _compare_lte_set(left, right, highlighter, verbose) - elif op == ">": - if isset(left) and isset(right): - explanation = _compare_gt_set(left, right, highlighter, verbose) - elif op == "<": - if isset(left) and isset(right): - explanation = _compare_lt_set(left, right, highlighter, verbose) - - except outcomes.Exit: - raise - except Exception: - repr_crash = _pytest._code.ExceptionInfo.from_current()._getreprcrash() - explanation = [ - f"(pytest_assertion plugin: representation of details failed: {repr_crash}.", - " Probably an object has a faulty __repr__.)", - ] - - if not explanation: - return None - - if explanation[0] != "": - explanation = ["", *explanation] - return [summary, *explanation] - - -def _compare_eq_any( - left: Any, right: Any, highlighter: _HighlightFunc, verbose: int = 0 -) -> list[str]: - explanation = [] - if istext(left) and istext(right): - explanation = _diff_text(left, right, highlighter, verbose) - else: - from _pytest.python_api import ApproxBase - - if isinstance(left, ApproxBase) or isinstance(right, ApproxBase): - # Although the common order should be obtained == expected, this ensures both ways - approx_side = left if isinstance(left, ApproxBase) else right - other_side = right if isinstance(left, ApproxBase) else left - - explanation = approx_side._repr_compare(other_side) - elif type(left) is type(right) and ( - isdatacls(left) or isattrs(left) or isnamedtuple(left) - ): - # Note: unlike dataclasses/attrs, namedtuples compare only the - # field values, not the type or field names. But this branch - # intentionally only handles the same-type case, which was often - # used in older code bases before dataclasses/attrs were available. - explanation = _compare_eq_cls(left, right, highlighter, verbose) - elif issequence(left) and issequence(right): - explanation = _compare_eq_sequence(left, right, highlighter, verbose) - elif isset(left) and isset(right): - explanation = _compare_eq_set(left, right, highlighter, verbose) - elif isdict(left) and isdict(right): - explanation = _compare_eq_dict(left, right, highlighter, verbose) - - if isiterable(left) and isiterable(right): - expl = _compare_eq_iterable(left, right, highlighter, verbose) - explanation.extend(expl) - - return explanation - - -def _diff_text( - left: str, right: str, highlighter: _HighlightFunc, verbose: int = 0 -) -> list[str]: - """Return the explanation for the diff between text. - - Unless --verbose is used this will skip leading and trailing - characters which are identical to keep the diff minimal. - """ - from difflib import ndiff - - explanation: list[str] = [] - - if verbose < 1: - i = 0 # just in case left or right has zero length - for i in range(min(len(left), len(right))): - if left[i] != right[i]: - break - if i > 42: - i -= 10 # Provide some context - explanation = [ - f"Skipping {i} identical leading characters in diff, use -v to show" - ] - left = left[i:] - right = right[i:] - if len(left) == len(right): - for i in range(len(left)): - if left[-i] != right[-i]: - break - if i > 42: - i -= 10 # Provide some context - explanation += [ - f"Skipping {i} identical trailing " - "characters in diff, use -v to show" - ] - left = left[:-i] - right = right[:-i] - keepends = True - if left.isspace() or right.isspace(): - left = repr(str(left)) - right = repr(str(right)) - explanation += ["Strings contain only whitespace, escaping them using repr()"] - # "right" is the expected base against which we compare "left", - # see https://github.com/pytest-dev/pytest/issues/3333 - explanation.extend( - highlighter( - "\n".join( - line.strip("\n") - for line in ndiff(right.splitlines(keepends), left.splitlines(keepends)) - ), - lexer="diff", - ).splitlines() - ) - return explanation - - -def _compare_eq_iterable( - left: Iterable[Any], - right: Iterable[Any], - highlighter: _HighlightFunc, - verbose: int = 0, -) -> list[str]: - if verbose <= 0 and not running_on_ci(): - return ["Use -v to get more diff"] - # dynamic import to speedup pytest - import difflib - - left_formatting = PrettyPrinter().pformat(left).splitlines() - right_formatting = PrettyPrinter().pformat(right).splitlines() - - explanation = ["", "Full diff:"] - # "right" is the expected base against which we compare "left", - # see https://github.com/pytest-dev/pytest/issues/3333 - explanation.extend( - highlighter( - "\n".join( - line.rstrip() - for line in difflib.ndiff(right_formatting, left_formatting) - ), - lexer="diff", - ).splitlines() - ) - return explanation - - -def _compare_eq_sequence( - left: Sequence[Any], - right: Sequence[Any], - highlighter: _HighlightFunc, - verbose: int = 0, -) -> list[str]: - comparing_bytes = isinstance(left, bytes) and isinstance(right, bytes) - explanation: list[str] = [] - len_left = len(left) - len_right = len(right) - for i in range(min(len_left, len_right)): - if left[i] != right[i]: - if comparing_bytes: - # when comparing bytes, we want to see their ascii representation - # instead of their numeric values (#5260) - # using a slice gives us the ascii representation: - # >>> s = b'foo' - # >>> s[0] - # 102 - # >>> s[0:1] - # b'f' - left_value = left[i : i + 1] - right_value = right[i : i + 1] - else: - left_value = left[i] - right_value = right[i] - - explanation.append( - f"At index {i} diff:" - f" {highlighter(repr(left_value))} != {highlighter(repr(right_value))}" - ) - break - - if comparing_bytes: - # when comparing bytes, it doesn't help to show the "sides contain one or more - # items" longer explanation, so skip it - - return explanation - - len_diff = len_left - len_right - if len_diff: - if len_diff > 0: - dir_with_more = "Left" - extra = saferepr(left[len_right]) - else: - len_diff = 0 - len_diff - dir_with_more = "Right" - extra = saferepr(right[len_left]) - - if len_diff == 1: - explanation += [ - f"{dir_with_more} contains one more item: {highlighter(extra)}" - ] - else: - explanation += [ - f"{dir_with_more} contains {len_diff} more items, first extra item: {highlighter(extra)}" - ] - return explanation - - -def _compare_eq_set( - left: AbstractSet[Any], - right: AbstractSet[Any], - highlighter: _HighlightFunc, - verbose: int = 0, -) -> list[str]: - explanation = [] - explanation.extend(_set_one_sided_diff("left", left, right, highlighter)) - explanation.extend(_set_one_sided_diff("right", right, left, highlighter)) - return explanation - - -def _compare_gt_set( - left: AbstractSet[Any], - right: AbstractSet[Any], - highlighter: _HighlightFunc, - verbose: int = 0, -) -> list[str]: - explanation = _compare_gte_set(left, right, highlighter) - if not explanation: - return ["Both sets are equal"] - return explanation - - -def _compare_lt_set( - left: AbstractSet[Any], - right: AbstractSet[Any], - highlighter: _HighlightFunc, - verbose: int = 0, -) -> list[str]: - explanation = _compare_lte_set(left, right, highlighter) - if not explanation: - return ["Both sets are equal"] - return explanation - - -def _compare_gte_set( - left: AbstractSet[Any], - right: AbstractSet[Any], - highlighter: _HighlightFunc, - verbose: int = 0, -) -> list[str]: - return _set_one_sided_diff("right", right, left, highlighter) - - -def _compare_lte_set( - left: AbstractSet[Any], - right: AbstractSet[Any], - highlighter: _HighlightFunc, - verbose: int = 0, -) -> list[str]: - return _set_one_sided_diff("left", left, right, highlighter) - - -def _set_one_sided_diff( - posn: str, - set1: AbstractSet[Any], - set2: AbstractSet[Any], - highlighter: _HighlightFunc, -) -> list[str]: - explanation = [] - diff = set1 - set2 - if diff: - explanation.append(f"Extra items in the {posn} set:") - for item in diff: - explanation.append(highlighter(saferepr(item))) - return explanation - - -def _compare_eq_dict( - left: Mapping[Any, Any], - right: Mapping[Any, Any], - highlighter: _HighlightFunc, - verbose: int = 0, -) -> list[str]: - explanation: list[str] = [] - set_left = set(left) - set_right = set(right) - common = set_left.intersection(set_right) - same = {k: left[k] for k in common if left[k] == right[k]} - if same and verbose < 2: - explanation += [f"Omitting {len(same)} identical items, use -vv to show"] - elif same: - explanation += ["Common items:"] - explanation += highlighter(pprint.pformat(same)).splitlines() - diff = {k for k in common if left[k] != right[k]} - if diff: - explanation += ["Differing items:"] - for k in diff: - explanation += [ - highlighter(saferepr({k: left[k]})) - + " != " - + highlighter(saferepr({k: right[k]})) - ] - extra_left = set_left - set_right - len_extra_left = len(extra_left) - if len_extra_left: - explanation.append( - f"Left contains {len_extra_left} more item{'' if len_extra_left == 1 else 's'}:" - ) - explanation.extend( - highlighter(pprint.pformat({k: left[k] for k in extra_left})).splitlines() - ) - extra_right = set_right - set_left - len_extra_right = len(extra_right) - if len_extra_right: - explanation.append( - f"Right contains {len_extra_right} more item{'' if len_extra_right == 1 else 's'}:" - ) - explanation.extend( - highlighter(pprint.pformat({k: right[k] for k in extra_right})).splitlines() - ) - return explanation - - -def _compare_eq_cls( - left: Any, right: Any, highlighter: _HighlightFunc, verbose: int -) -> list[str]: - if not has_default_eq(left): - return [] - if isdatacls(left): - import dataclasses - - all_fields = dataclasses.fields(left) - fields_to_check = [info.name for info in all_fields if info.compare] - elif isattrs(left): - all_fields = left.__attrs_attrs__ - fields_to_check = [field.name for field in all_fields if getattr(field, "eq")] - elif isnamedtuple(left): - fields_to_check = left._fields - else: - assert False - - indent = " " - same = [] - diff = [] - for field in fields_to_check: - if getattr(left, field) == getattr(right, field): - same.append(field) - else: - diff.append(field) - - explanation = [] - if same or diff: - explanation += [""] - if same and verbose < 2: - explanation.append(f"Omitting {len(same)} identical items, use -vv to show") - elif same: - explanation += ["Matching attributes:"] - explanation += highlighter(pprint.pformat(same)).splitlines() - if diff: - explanation += ["Differing attributes:"] - explanation += highlighter(pprint.pformat(diff)).splitlines() - for field in diff: - field_left = getattr(left, field) - field_right = getattr(right, field) - explanation += [ - "", - f"Drill down into differing attribute {field}:", - f"{indent}{field}: {highlighter(repr(field_left))} != {highlighter(repr(field_right))}", - ] - explanation += [ - indent + line - for line in _compare_eq_any( - field_left, field_right, highlighter, verbose - ) - ] - return explanation - - -def _notin_text(term: str, text: str, verbose: int = 0) -> list[str]: - index = text.find(term) - head = text[:index] - tail = text[index + len(term) :] - correct_text = head + tail - diff = _diff_text(text, correct_text, dummy_highlighter, verbose) - newdiff = [f"{saferepr(term, maxsize=42)} is contained here:"] - for line in diff: - if line.startswith("Skipping"): - continue - if line.startswith("- "): - continue - if line.startswith("+ "): - newdiff.append(" " + line[2:]) - else: - newdiff.append(line) - return newdiff diff --git a/.venv/lib/python3.12/site-packages/_pytest/cacheprovider.py b/.venv/lib/python3.12/site-packages/_pytest/cacheprovider.py deleted file mode 100644 index 4383f10..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/cacheprovider.py +++ /dev/null @@ -1,646 +0,0 @@ -# mypy: allow-untyped-defs -"""Implementation of the cache provider.""" - -# This plugin was not named "cache" to avoid conflicts with the external -# pytest-cache version. -from __future__ import annotations - -from collections.abc import Generator -from collections.abc import Iterable -import dataclasses -import errno -import json -import os -from pathlib import Path -import tempfile -from typing import final - -from .pathlib import resolve_from_str -from .pathlib import rm_rf -from .reports import CollectReport -from _pytest import nodes -from _pytest._io import TerminalWriter -from _pytest.config import Config -from _pytest.config import ExitCode -from _pytest.config import hookimpl -from _pytest.config.argparsing import Parser -from _pytest.deprecated import check_ispytest -from _pytest.fixtures import fixture -from _pytest.fixtures import FixtureRequest -from _pytest.main import Session -from _pytest.nodes import Directory -from _pytest.nodes import File -from _pytest.reports import TestReport - - -README_CONTENT = """\ -# pytest cache directory # - -This directory contains data from the pytest's cache plugin, -which provides the `--lf` and `--ff` options, as well as the `cache` fixture. - -**Do not** commit this to version control. - -See [the docs](https://docs.pytest.org/en/stable/how-to/cache.html) for more information. -""" - -CACHEDIR_TAG_CONTENT = b"""\ -Signature: 8a477f597d28d172789f06886806bc55 -# This file is a cache directory tag created by pytest. -# For information about cache directory tags, see: -# https://bford.info/cachedir/spec.html -""" - - -@final -@dataclasses.dataclass -class Cache: - """Instance of the `cache` fixture.""" - - _cachedir: Path = dataclasses.field(repr=False) - _config: Config = dataclasses.field(repr=False) - - # Sub-directory under cache-dir for directories created by `mkdir()`. - _CACHE_PREFIX_DIRS = "d" - - # Sub-directory under cache-dir for values created by `set()`. - _CACHE_PREFIX_VALUES = "v" - - def __init__( - self, cachedir: Path, config: Config, *, _ispytest: bool = False - ) -> None: - check_ispytest(_ispytest) - self._cachedir = cachedir - self._config = config - - @classmethod - def for_config(cls, config: Config, *, _ispytest: bool = False) -> Cache: - """Create the Cache instance for a Config. - - :meta private: - """ - check_ispytest(_ispytest) - cachedir = cls.cache_dir_from_config(config, _ispytest=True) - if config.getoption("cacheclear") and cachedir.is_dir(): - cls.clear_cache(cachedir, _ispytest=True) - return cls(cachedir, config, _ispytest=True) - - @classmethod - def clear_cache(cls, cachedir: Path, _ispytest: bool = False) -> None: - """Clear the sub-directories used to hold cached directories and values. - - :meta private: - """ - check_ispytest(_ispytest) - for prefix in (cls._CACHE_PREFIX_DIRS, cls._CACHE_PREFIX_VALUES): - d = cachedir / prefix - if d.is_dir(): - rm_rf(d) - - @staticmethod - def cache_dir_from_config(config: Config, *, _ispytest: bool = False) -> Path: - """Get the path to the cache directory for a Config. - - :meta private: - """ - check_ispytest(_ispytest) - return resolve_from_str(config.getini("cache_dir"), config.rootpath) - - def warn(self, fmt: str, *, _ispytest: bool = False, **args: object) -> None: - """Issue a cache warning. - - :meta private: - """ - check_ispytest(_ispytest) - import warnings - - from _pytest.warning_types import PytestCacheWarning - - warnings.warn( - PytestCacheWarning(fmt.format(**args) if args else fmt), - self._config.hook, - stacklevel=3, - ) - - def _mkdir(self, path: Path) -> None: - self._ensure_cache_dir_and_supporting_files() - path.mkdir(exist_ok=True, parents=True) - - def mkdir(self, name: str) -> Path: - """Return a directory path object with the given name. - - If the directory does not yet exist, it will be created. You can use - it to manage files to e.g. store/retrieve database dumps across test - sessions. - - .. versionadded:: 7.0 - - :param name: - Must be a string not containing a ``/`` separator. - Make sure the name contains your plugin or application - identifiers to prevent clashes with other cache users. - """ - path = Path(name) - if len(path.parts) > 1: - raise ValueError("name is not allowed to contain path separators") - res = self._cachedir.joinpath(self._CACHE_PREFIX_DIRS, path) - self._mkdir(res) - return res - - def _getvaluepath(self, key: str) -> Path: - return self._cachedir.joinpath(self._CACHE_PREFIX_VALUES, Path(key)) - - def get(self, key: str, default): - """Return the cached value for the given key. - - If no value was yet cached or the value cannot be read, the specified - default is returned. - - :param key: - Must be a ``/`` separated value. Usually the first - name is the name of your plugin or your application. - :param default: - The value to return in case of a cache-miss or invalid cache value. - """ - path = self._getvaluepath(key) - try: - with path.open("r", encoding="UTF-8") as f: - return json.load(f) - except (ValueError, OSError): - return default - - def set(self, key: str, value: object) -> None: - """Save value for the given key. - - :param key: - Must be a ``/`` separated value. Usually the first - name is the name of your plugin or your application. - :param value: - Must be of any combination of basic python types, - including nested types like lists of dictionaries. - """ - path = self._getvaluepath(key) - try: - self._mkdir(path.parent) - except OSError as exc: - self.warn( - f"could not create cache path {path}: {exc}", - _ispytest=True, - ) - return - data = json.dumps(value, ensure_ascii=False, indent=2) - try: - f = path.open("w", encoding="UTF-8") - except OSError as exc: - self.warn( - f"cache could not write path {path}: {exc}", - _ispytest=True, - ) - else: - with f: - f.write(data) - - def _ensure_cache_dir_and_supporting_files(self) -> None: - """Create the cache dir and its supporting files.""" - if self._cachedir.is_dir(): - return - - self._cachedir.parent.mkdir(parents=True, exist_ok=True) - with tempfile.TemporaryDirectory( - prefix="pytest-cache-files-", - dir=self._cachedir.parent, - ) as newpath: - path = Path(newpath) - - # Reset permissions to the default, see #12308. - # Note: there's no way to get the current umask atomically, eek. - umask = os.umask(0o022) - os.umask(umask) - path.chmod(0o777 - umask) - - with open(path.joinpath("README.md"), "x", encoding="UTF-8") as f: - f.write(README_CONTENT) - with open(path.joinpath(".gitignore"), "x", encoding="UTF-8") as f: - f.write("# Created by pytest automatically.\n*\n") - with open(path.joinpath("CACHEDIR.TAG"), "xb") as f: - f.write(CACHEDIR_TAG_CONTENT) - - try: - path.rename(self._cachedir) - except OSError as e: - # If 2 concurrent pytests both race to the rename, the loser - # gets "Directory not empty" from the rename. In this case, - # everything is handled so just continue (while letting the - # temporary directory be cleaned up). - # On Windows, the error is a FileExistsError which translates to EEXIST. - if e.errno not in (errno.ENOTEMPTY, errno.EEXIST): - raise - else: - # Create a directory in place of the one we just moved so that - # `TemporaryDirectory`'s cleanup doesn't complain. - # - # TODO: pass ignore_cleanup_errors=True when we no longer support python < 3.10. - # See https://github.com/python/cpython/issues/74168. Note that passing - # delete=False would do the wrong thing in case of errors and isn't supported - # until python 3.12. - path.mkdir() - - -class LFPluginCollWrapper: - def __init__(self, lfplugin: LFPlugin) -> None: - self.lfplugin = lfplugin - self._collected_at_least_one_failure = False - - @hookimpl(wrapper=True) - def pytest_make_collect_report( - self, collector: nodes.Collector - ) -> Generator[None, CollectReport, CollectReport]: - res = yield - if isinstance(collector, Session | Directory): - # Sort any lf-paths to the beginning. - lf_paths = self.lfplugin._last_failed_paths - - # Use stable sort to prioritize last failed. - def sort_key(node: nodes.Item | nodes.Collector) -> bool: - return node.path in lf_paths - - res.result = sorted( - res.result, - key=sort_key, - reverse=True, - ) - - elif isinstance(collector, File): - if collector.path in self.lfplugin._last_failed_paths: - result = res.result - lastfailed = self.lfplugin.lastfailed - - # Only filter with known failures. - if not self._collected_at_least_one_failure: - if not any(x.nodeid in lastfailed for x in result): - return res - self.lfplugin.config.pluginmanager.register( - LFPluginCollSkipfiles(self.lfplugin), "lfplugin-collskip" - ) - self._collected_at_least_one_failure = True - - session = collector.session - result[:] = [ - x - for x in result - if x.nodeid in lastfailed - # Include any passed arguments (not trivial to filter). - or session.isinitpath(x.path) - # Keep all sub-collectors. - or isinstance(x, nodes.Collector) - ] - - return res - - -class LFPluginCollSkipfiles: - def __init__(self, lfplugin: LFPlugin) -> None: - self.lfplugin = lfplugin - - @hookimpl - def pytest_make_collect_report( - self, collector: nodes.Collector - ) -> CollectReport | None: - if isinstance(collector, File): - if collector.path not in self.lfplugin._last_failed_paths: - self.lfplugin._skipped_files += 1 - - return CollectReport( - collector.nodeid, "passed", longrepr=None, result=[] - ) - return None - - -class LFPlugin: - """Plugin which implements the --lf (run last-failing) option.""" - - def __init__(self, config: Config) -> None: - self.config = config - active_keys = "lf", "failedfirst" - self.active = any(config.getoption(key) for key in active_keys) - assert config.cache - self.lastfailed: dict[str, bool] = config.cache.get("cache/lastfailed", {}) - self._previously_failed_count: int | None = None - self._report_status: str | None = None - self._skipped_files = 0 # count skipped files during collection due to --lf - - if config.getoption("lf"): - self._last_failed_paths = self.get_last_failed_paths() - config.pluginmanager.register( - LFPluginCollWrapper(self), "lfplugin-collwrapper" - ) - - def get_last_failed_paths(self) -> set[Path]: - """Return a set with all Paths of the previously failed nodeids and - their parents.""" - rootpath = self.config.rootpath - result = set() - for nodeid in self.lastfailed: - path = rootpath / nodeid.split("::")[0] - result.add(path) - result.update(path.parents) - return {x for x in result if x.exists()} - - def pytest_report_collectionfinish(self) -> str | None: - if self.active and self.config.get_verbosity() >= 0: - return f"run-last-failure: {self._report_status}" - return None - - def pytest_runtest_logreport(self, report: TestReport) -> None: - if (report.when == "call" and report.passed) or report.skipped: - self.lastfailed.pop(report.nodeid, None) - elif report.failed: - self.lastfailed[report.nodeid] = True - - def pytest_collectreport(self, report: CollectReport) -> None: - passed = report.outcome in ("passed", "skipped") - if passed: - if report.nodeid in self.lastfailed: - self.lastfailed.pop(report.nodeid) - self.lastfailed.update((item.nodeid, True) for item in report.result) - else: - self.lastfailed[report.nodeid] = True - - @hookimpl(wrapper=True, tryfirst=True) - def pytest_collection_modifyitems( - self, config: Config, items: list[nodes.Item] - ) -> Generator[None]: - res = yield - - if not self.active: - return res - - if self.lastfailed: - previously_failed = [] - previously_passed = [] - for item in items: - if item.nodeid in self.lastfailed: - previously_failed.append(item) - else: - previously_passed.append(item) - self._previously_failed_count = len(previously_failed) - - if not previously_failed: - # Running a subset of all tests with recorded failures - # only outside of it. - self._report_status = ( - f"{len(self.lastfailed)} known failures not in selected tests" - ) - else: - if self.config.getoption("lf"): - items[:] = previously_failed - config.hook.pytest_deselected(items=previously_passed) - else: # --failedfirst - items[:] = previously_failed + previously_passed - - noun = "failure" if self._previously_failed_count == 1 else "failures" - suffix = " first" if self.config.getoption("failedfirst") else "" - self._report_status = ( - f"rerun previous {self._previously_failed_count} {noun}{suffix}" - ) - - if self._skipped_files > 0: - files_noun = "file" if self._skipped_files == 1 else "files" - self._report_status += f" (skipped {self._skipped_files} {files_noun})" - else: - self._report_status = "no previously failed tests, " - if self.config.getoption("last_failed_no_failures") == "none": - self._report_status += "deselecting all items." - config.hook.pytest_deselected(items=items[:]) - items[:] = [] - else: - self._report_status += "not deselecting items." - - return res - - def pytest_sessionfinish(self, session: Session) -> None: - config = self.config - if config.getoption("cacheshow") or hasattr(config, "workerinput"): - return - - assert config.cache is not None - saved_lastfailed = config.cache.get("cache/lastfailed", {}) - if saved_lastfailed != self.lastfailed: - config.cache.set("cache/lastfailed", self.lastfailed) - - -class NFPlugin: - """Plugin which implements the --nf (run new-first) option.""" - - def __init__(self, config: Config) -> None: - self.config = config - self.active = config.option.newfirst - assert config.cache is not None - self.cached_nodeids = set(config.cache.get("cache/nodeids", [])) - - @hookimpl(wrapper=True, tryfirst=True) - def pytest_collection_modifyitems(self, items: list[nodes.Item]) -> Generator[None]: - res = yield - - if self.active: - new_items: dict[str, nodes.Item] = {} - other_items: dict[str, nodes.Item] = {} - for item in items: - if item.nodeid not in self.cached_nodeids: - new_items[item.nodeid] = item - else: - other_items[item.nodeid] = item - - items[:] = self._get_increasing_order( - new_items.values() - ) + self._get_increasing_order(other_items.values()) - self.cached_nodeids.update(new_items) - else: - self.cached_nodeids.update(item.nodeid for item in items) - - return res - - def _get_increasing_order(self, items: Iterable[nodes.Item]) -> list[nodes.Item]: - return sorted(items, key=lambda item: item.path.stat().st_mtime, reverse=True) - - def pytest_sessionfinish(self) -> None: - config = self.config - if config.getoption("cacheshow") or hasattr(config, "workerinput"): - return - - if config.getoption("collectonly"): - return - - assert config.cache is not None - config.cache.set("cache/nodeids", sorted(self.cached_nodeids)) - - -def pytest_addoption(parser: Parser) -> None: - """Add command-line options for cache functionality. - - :param parser: Parser object to add command-line options to. - """ - group = parser.getgroup("general") - group.addoption( - "--lf", - "--last-failed", - action="store_true", - dest="lf", - help="Rerun only the tests that failed at the last run (or all if none failed)", - ) - group.addoption( - "--ff", - "--failed-first", - action="store_true", - dest="failedfirst", - help="Run all tests, but run the last failures first. " - "This may re-order tests and thus lead to " - "repeated fixture setup/teardown.", - ) - group.addoption( - "--nf", - "--new-first", - action="store_true", - dest="newfirst", - help="Run tests from new files first, then the rest of the tests " - "sorted by file mtime", - ) - group.addoption( - "--cache-show", - action="append", - nargs="?", - dest="cacheshow", - help=( - "Show cache contents, don't perform collection or tests. " - "Optional argument: glob (default: '*')." - ), - ) - group.addoption( - "--cache-clear", - action="store_true", - dest="cacheclear", - help="Remove all cache contents at start of test run", - ) - cache_dir_default = ".pytest_cache" - if "TOX_ENV_DIR" in os.environ: - cache_dir_default = os.path.join(os.environ["TOX_ENV_DIR"], cache_dir_default) - parser.addini("cache_dir", default=cache_dir_default, help="Cache directory path") - group.addoption( - "--lfnf", - "--last-failed-no-failures", - action="store", - dest="last_failed_no_failures", - choices=("all", "none"), - default="all", - help="With ``--lf``, determines whether to execute tests when there " - "are no previously (known) failures or when no " - "cached ``lastfailed`` data was found. " - "``all`` (the default) runs the full test suite again. " - "``none`` just emits a message about no known failures and exits successfully.", - ) - - -def pytest_cmdline_main(config: Config) -> int | ExitCode | None: - if config.option.cacheshow and not config.option.help: - from _pytest.main import wrap_session - - return wrap_session(config, cacheshow) - return None - - -@hookimpl(tryfirst=True) -def pytest_configure(config: Config) -> None: - """Configure cache system and register related plugins. - - Creates the Cache instance and registers the last-failed (LFPlugin) - and new-first (NFPlugin) plugins with the plugin manager. - - :param config: pytest configuration object. - """ - config.cache = Cache.for_config(config, _ispytest=True) - config.pluginmanager.register(LFPlugin(config), "lfplugin") - config.pluginmanager.register(NFPlugin(config), "nfplugin") - - -@fixture -def cache(request: FixtureRequest) -> Cache: - """Return a cache object that can persist state between testing sessions. - - cache.get(key, default) - cache.set(key, value) - - Keys must be ``/`` separated strings, where the first part is usually the - name of your plugin or application to avoid clashes with other cache users. - - Values can be any object handled by the json stdlib module. - """ - assert request.config.cache is not None - return request.config.cache - - -def pytest_report_header(config: Config) -> str | None: - """Display cachedir with --cache-show and if non-default.""" - if config.option.verbose > 0 or config.getini("cache_dir") != ".pytest_cache": - assert config.cache is not None - cachedir = config.cache._cachedir - # TODO: evaluate generating upward relative paths - # starting with .., ../.. if sensible - - try: - displaypath = cachedir.relative_to(config.rootpath) - except ValueError: - displaypath = cachedir - return f"cachedir: {displaypath}" - return None - - -def cacheshow(config: Config, session: Session) -> int: - """Display cache contents when --cache-show is used. - - Shows cached values and directories matching the specified glob pattern - (default: '*'). Displays cache location, cached test results, and - any cached directories created by plugins. - - :param config: pytest configuration object. - :param session: pytest session object. - :returns: Exit code (0 for success). - """ - from pprint import pformat - - assert config.cache is not None - - tw = TerminalWriter() - tw.line("cachedir: " + str(config.cache._cachedir)) - if not config.cache._cachedir.is_dir(): - tw.line("cache is empty") - return 0 - - glob = config.option.cacheshow[0] - if glob is None: - glob = "*" - - dummy = object() - basedir = config.cache._cachedir - vdir = basedir / Cache._CACHE_PREFIX_VALUES - tw.sep("-", f"cache values for {glob!r}") - for valpath in sorted(x for x in vdir.rglob(glob) if x.is_file()): - key = str(valpath.relative_to(vdir)) - val = config.cache.get(key, dummy) - if val is dummy: - tw.line(f"{key} contains unreadable content, will be ignored") - else: - tw.line(f"{key} contains:") - for line in pformat(val).splitlines(): - tw.line(" " + line) - - ddir = basedir / Cache._CACHE_PREFIX_DIRS - if ddir.is_dir(): - contents = sorted(ddir.rglob(glob)) - tw.sep("-", f"cache directories for {glob!r}") - for p in contents: - # if p.is_dir(): - # print("%s/" % p.relative_to(basedir)) - if p.is_file(): - key = str(p.relative_to(basedir)) - tw.line(f"{key} is a file of length {p.stat().st_size}") - return 0 diff --git a/.venv/lib/python3.12/site-packages/_pytest/capture.py b/.venv/lib/python3.12/site-packages/_pytest/capture.py deleted file mode 100644 index 6d98676..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/capture.py +++ /dev/null @@ -1,1144 +0,0 @@ -# mypy: allow-untyped-defs -"""Per-test stdout/stderr capturing mechanism.""" - -from __future__ import annotations - -import abc -import collections -from collections.abc import Generator -from collections.abc import Iterable -from collections.abc import Iterator -import contextlib -import io -from io import UnsupportedOperation -import os -import sys -from tempfile import TemporaryFile -from types import TracebackType -from typing import Any -from typing import AnyStr -from typing import BinaryIO -from typing import cast -from typing import Final -from typing import final -from typing import Generic -from typing import Literal -from typing import NamedTuple -from typing import TextIO -from typing import TYPE_CHECKING - - -if TYPE_CHECKING: - from typing_extensions import Self - -from _pytest.config import Config -from _pytest.config import hookimpl -from _pytest.config.argparsing import Parser -from _pytest.deprecated import check_ispytest -from _pytest.fixtures import fixture -from _pytest.fixtures import SubRequest -from _pytest.nodes import Collector -from _pytest.nodes import File -from _pytest.nodes import Item -from _pytest.reports import CollectReport - - -_CaptureMethod = Literal["fd", "sys", "no", "tee-sys"] - - -def pytest_addoption(parser: Parser) -> None: - group = parser.getgroup("general") - group.addoption( - "--capture", - action="store", - default="fd", - metavar="method", - choices=["fd", "sys", "no", "tee-sys"], - help="Per-test capturing method: one of fd|sys|no|tee-sys", - ) - group._addoption( # private to use reserved lower-case short option - "-s", - action="store_const", - const="no", - dest="capture", - help="Shortcut for --capture=no", - ) - - -def _colorama_workaround() -> None: - """Ensure colorama is imported so that it attaches to the correct stdio - handles on Windows. - - colorama uses the terminal on import time. So if something does the - first import of colorama while I/O capture is active, colorama will - fail in various ways. - """ - if sys.platform.startswith("win32"): - try: - import colorama # noqa: F401 - except ImportError: - pass - - -def _readline_workaround() -> None: - """Ensure readline is imported early so it attaches to the correct stdio handles. - - This isn't a problem with the default GNU readline implementation, but in - some configurations, Python uses libedit instead (on macOS, and for prebuilt - binaries such as used by uv). - - In theory this is only needed if readline.backend == "libedit", but the - workaround consists of importing readline here, so we already worked around - the issue by the time we could check if we need to. - """ - try: - import readline # noqa: F401 - except ImportError: - pass - - -def _windowsconsoleio_workaround(stream: TextIO) -> None: - """Workaround for Windows Unicode console handling. - - Python 3.6 implemented Unicode console handling for Windows. This works - by reading/writing to the raw console handle using - ``{Read,Write}ConsoleW``. - - The problem is that we are going to ``dup2`` over the stdio file - descriptors when doing ``FDCapture`` and this will ``CloseHandle`` the - handles used by Python to write to the console. Though there is still some - weirdness and the console handle seems to only be closed randomly and not - on the first call to ``CloseHandle``, or maybe it gets reopened with the - same handle value when we suspend capturing. - - The workaround in this case will reopen stdio with a different fd which - also means a different handle by replicating the logic in - "Py_lifecycle.c:initstdio/create_stdio". - - :param stream: - In practice ``sys.stdout`` or ``sys.stderr``, but given - here as parameter for unittesting purposes. - - See https://github.com/pytest-dev/py/issues/103. - """ - if not sys.platform.startswith("win32") or hasattr(sys, "pypy_version_info"): - return - - # Bail out if ``stream`` doesn't seem like a proper ``io`` stream (#2666). - if not hasattr(stream, "buffer"): # type: ignore[unreachable,unused-ignore] - return - - raw_stdout = stream.buffer.raw if hasattr(stream.buffer, "raw") else stream.buffer - - if not isinstance(raw_stdout, io._WindowsConsoleIO): # type: ignore[attr-defined,unused-ignore] - return - - def _reopen_stdio(f, mode): - if not hasattr(stream.buffer, "raw") and mode[0] == "w": - buffering = 0 - else: - buffering = -1 - - return io.TextIOWrapper( - open(os.dup(f.fileno()), mode, buffering), - f.encoding, - f.errors, - f.newlines, - f.line_buffering, - ) - - sys.stdin = _reopen_stdio(sys.stdin, "rb") - sys.stdout = _reopen_stdio(sys.stdout, "wb") - sys.stderr = _reopen_stdio(sys.stderr, "wb") - - -@hookimpl(wrapper=True) -def pytest_load_initial_conftests(early_config: Config) -> Generator[None]: - ns = early_config.known_args_namespace - if ns.capture == "fd": - _windowsconsoleio_workaround(sys.stdout) - _colorama_workaround() - _readline_workaround() - pluginmanager = early_config.pluginmanager - capman = CaptureManager(ns.capture) - pluginmanager.register(capman, "capturemanager") - - # Make sure that capturemanager is properly reset at final shutdown. - early_config.add_cleanup(capman.stop_global_capturing) - - # Finally trigger conftest loading but while capturing (issue #93). - capman.start_global_capturing() - try: - try: - yield - finally: - capman.suspend_global_capture() - except BaseException: - out, err = capman.read_global_capture() - sys.stdout.write(out) - sys.stderr.write(err) - raise - - -# IO Helpers. - - -class EncodedFile(io.TextIOWrapper): - __slots__ = () - - @property - def name(self) -> str: - # Ensure that file.name is a string. Workaround for a Python bug - # fixed in >=3.7.4: https://bugs.python.org/issue36015 - return repr(self.buffer) - - @property - def mode(self) -> str: - # TextIOWrapper doesn't expose a mode, but at least some of our - # tests check it. - assert hasattr(self.buffer, "mode") - return cast(str, self.buffer.mode.replace("b", "")) - - -class CaptureIO(io.TextIOWrapper): - def __init__(self) -> None: - super().__init__(io.BytesIO(), encoding="UTF-8", newline="", write_through=True) - - def getvalue(self) -> str: - assert isinstance(self.buffer, io.BytesIO) - return self.buffer.getvalue().decode("UTF-8") - - -class TeeCaptureIO(CaptureIO): - def __init__(self, other: TextIO) -> None: - self._other = other - super().__init__() - - def write(self, s: str) -> int: - super().write(s) - return self._other.write(s) - - -class DontReadFromInput(TextIO): - @property - def encoding(self) -> str: - assert sys.__stdin__ is not None - return sys.__stdin__.encoding - - def read(self, size: int = -1) -> str: - raise OSError( - "pytest: reading from stdin while output is captured! Consider using `-s`." - ) - - readline = read - - def __next__(self) -> str: - return self.readline() - - def readlines(self, hint: int | None = -1) -> list[str]: - raise OSError( - "pytest: reading from stdin while output is captured! Consider using `-s`." - ) - - def __iter__(self) -> Iterator[str]: - return self - - def fileno(self) -> int: - raise UnsupportedOperation("redirected stdin is pseudofile, has no fileno()") - - def flush(self) -> None: - raise UnsupportedOperation("redirected stdin is pseudofile, has no flush()") - - def isatty(self) -> bool: - return False - - def close(self) -> None: - pass - - def readable(self) -> bool: - return False - - def seek(self, offset: int, whence: int = 0) -> int: - raise UnsupportedOperation("redirected stdin is pseudofile, has no seek(int)") - - def seekable(self) -> bool: - return False - - def tell(self) -> int: - raise UnsupportedOperation("redirected stdin is pseudofile, has no tell()") - - def truncate(self, size: int | None = None) -> int: - raise UnsupportedOperation("cannot truncate stdin") - - def write(self, data: str) -> int: - raise UnsupportedOperation("cannot write to stdin") - - def writelines(self, lines: Iterable[str]) -> None: - raise UnsupportedOperation("Cannot write to stdin") - - def writable(self) -> bool: - return False - - def __enter__(self) -> Self: - return self - - def __exit__( - self, - type: type[BaseException] | None, - value: BaseException | None, - traceback: TracebackType | None, - ) -> None: - pass - - @property - def buffer(self) -> BinaryIO: - # The str/bytes doesn't actually matter in this type, so OK to fake. - return self # type: ignore[return-value] - - -# Capture classes. - - -class CaptureBase(abc.ABC, Generic[AnyStr]): - EMPTY_BUFFER: AnyStr - - @abc.abstractmethod - def __init__(self, fd: int) -> None: - raise NotImplementedError() - - @abc.abstractmethod - def start(self) -> None: - raise NotImplementedError() - - @abc.abstractmethod - def done(self) -> None: - raise NotImplementedError() - - @abc.abstractmethod - def suspend(self) -> None: - raise NotImplementedError() - - @abc.abstractmethod - def resume(self) -> None: - raise NotImplementedError() - - @abc.abstractmethod - def writeorg(self, data: AnyStr) -> None: - raise NotImplementedError() - - @abc.abstractmethod - def snap(self) -> AnyStr: - raise NotImplementedError() - - -patchsysdict = {0: "stdin", 1: "stdout", 2: "stderr"} - - -class NoCapture(CaptureBase[str]): - EMPTY_BUFFER = "" - - def __init__(self, fd: int) -> None: - pass - - def start(self) -> None: - pass - - def done(self) -> None: - pass - - def suspend(self) -> None: - pass - - def resume(self) -> None: - pass - - def snap(self) -> str: - return "" - - def writeorg(self, data: str) -> None: - pass - - -class SysCaptureBase(CaptureBase[AnyStr]): - def __init__( - self, fd: int, tmpfile: TextIO | None = None, *, tee: bool = False - ) -> None: - name = patchsysdict[fd] - self._old: TextIO = getattr(sys, name) - self.name = name - if tmpfile is None: - if name == "stdin": - tmpfile = DontReadFromInput() - else: - tmpfile = CaptureIO() if not tee else TeeCaptureIO(self._old) - self.tmpfile = tmpfile - self._state = "initialized" - - def repr(self, class_name: str) -> str: - return "<{} {} _old={} _state={!r} tmpfile={!r}>".format( - class_name, - self.name, - (hasattr(self, "_old") and repr(self._old)) or "", - self._state, - self.tmpfile, - ) - - def __repr__(self) -> str: - return "<{} {} _old={} _state={!r} tmpfile={!r}>".format( - self.__class__.__name__, - self.name, - (hasattr(self, "_old") and repr(self._old)) or "", - self._state, - self.tmpfile, - ) - - def _assert_state(self, op: str, states: tuple[str, ...]) -> None: - assert self._state in states, ( - "cannot {} in state {!r}: expected one of {}".format( - op, self._state, ", ".join(states) - ) - ) - - def start(self) -> None: - self._assert_state("start", ("initialized",)) - setattr(sys, self.name, self.tmpfile) - self._state = "started" - - def done(self) -> None: - self._assert_state("done", ("initialized", "started", "suspended", "done")) - if self._state == "done": - return - setattr(sys, self.name, self._old) - del self._old - self.tmpfile.close() - self._state = "done" - - def suspend(self) -> None: - self._assert_state("suspend", ("started", "suspended")) - setattr(sys, self.name, self._old) - self._state = "suspended" - - def resume(self) -> None: - self._assert_state("resume", ("started", "suspended")) - if self._state == "started": - return - setattr(sys, self.name, self.tmpfile) - self._state = "started" - - -class SysCaptureBinary(SysCaptureBase[bytes]): - EMPTY_BUFFER = b"" - - def snap(self) -> bytes: - self._assert_state("snap", ("started", "suspended")) - self.tmpfile.seek(0) - res = self.tmpfile.buffer.read() - self.tmpfile.seek(0) - self.tmpfile.truncate() - return res - - def writeorg(self, data: bytes) -> None: - self._assert_state("writeorg", ("started", "suspended")) - self._old.flush() - self._old.buffer.write(data) - self._old.buffer.flush() - - -class SysCapture(SysCaptureBase[str]): - EMPTY_BUFFER = "" - - def snap(self) -> str: - self._assert_state("snap", ("started", "suspended")) - assert isinstance(self.tmpfile, CaptureIO) - res = self.tmpfile.getvalue() - self.tmpfile.seek(0) - self.tmpfile.truncate() - return res - - def writeorg(self, data: str) -> None: - self._assert_state("writeorg", ("started", "suspended")) - self._old.write(data) - self._old.flush() - - -class FDCaptureBase(CaptureBase[AnyStr]): - def __init__(self, targetfd: int) -> None: - self.targetfd = targetfd - - try: - os.fstat(targetfd) - except OSError: - # FD capturing is conceptually simple -- create a temporary file, - # redirect the FD to it, redirect back when done. But when the - # target FD is invalid it throws a wrench into this lovely scheme. - # - # Tests themselves shouldn't care if the FD is valid, FD capturing - # should work regardless of external circumstances. So falling back - # to just sys capturing is not a good option. - # - # Further complications are the need to support suspend() and the - # possibility of FD reuse (e.g. the tmpfile getting the very same - # target FD). The following approach is robust, I believe. - self.targetfd_invalid: int | None = os.open(os.devnull, os.O_RDWR) - os.dup2(self.targetfd_invalid, targetfd) - else: - self.targetfd_invalid = None - self.targetfd_save = os.dup(targetfd) - - if targetfd == 0: - self.tmpfile = open(os.devnull, encoding="utf-8") - self.syscapture: CaptureBase[str] = SysCapture(targetfd) - else: - self.tmpfile = EncodedFile( - TemporaryFile(buffering=0), - encoding="utf-8", - errors="replace", - newline="", - write_through=True, - ) - if targetfd in patchsysdict: - self.syscapture = SysCapture(targetfd, self.tmpfile) - else: - self.syscapture = NoCapture(targetfd) - - self._state = "initialized" - - def __repr__(self) -> str: - return ( - f"<{self.__class__.__name__} {self.targetfd} oldfd={self.targetfd_save} " - f"_state={self._state!r} tmpfile={self.tmpfile!r}>" - ) - - def _assert_state(self, op: str, states: tuple[str, ...]) -> None: - assert self._state in states, ( - "cannot {} in state {!r}: expected one of {}".format( - op, self._state, ", ".join(states) - ) - ) - - def start(self) -> None: - """Start capturing on targetfd using memorized tmpfile.""" - self._assert_state("start", ("initialized",)) - os.dup2(self.tmpfile.fileno(), self.targetfd) - self.syscapture.start() - self._state = "started" - - def done(self) -> None: - """Stop capturing, restore streams, return original capture file, - seeked to position zero.""" - self._assert_state("done", ("initialized", "started", "suspended", "done")) - if self._state == "done": - return - os.dup2(self.targetfd_save, self.targetfd) - os.close(self.targetfd_save) - if self.targetfd_invalid is not None: - if self.targetfd_invalid != self.targetfd: - os.close(self.targetfd) - os.close(self.targetfd_invalid) - self.syscapture.done() - self.tmpfile.close() - self._state = "done" - - def suspend(self) -> None: - self._assert_state("suspend", ("started", "suspended")) - if self._state == "suspended": - return - self.syscapture.suspend() - os.dup2(self.targetfd_save, self.targetfd) - self._state = "suspended" - - def resume(self) -> None: - self._assert_state("resume", ("started", "suspended")) - if self._state == "started": - return - self.syscapture.resume() - os.dup2(self.tmpfile.fileno(), self.targetfd) - self._state = "started" - - -class FDCaptureBinary(FDCaptureBase[bytes]): - """Capture IO to/from a given OS-level file descriptor. - - snap() produces `bytes`. - """ - - EMPTY_BUFFER = b"" - - def snap(self) -> bytes: - self._assert_state("snap", ("started", "suspended")) - self.tmpfile.seek(0) - res = self.tmpfile.buffer.read() - self.tmpfile.seek(0) - self.tmpfile.truncate() - return res # type: ignore[return-value] - - def writeorg(self, data: bytes) -> None: - """Write to original file descriptor.""" - self._assert_state("writeorg", ("started", "suspended")) - os.write(self.targetfd_save, data) - - -class FDCapture(FDCaptureBase[str]): - """Capture IO to/from a given OS-level file descriptor. - - snap() produces text. - """ - - EMPTY_BUFFER = "" - - def snap(self) -> str: - self._assert_state("snap", ("started", "suspended")) - self.tmpfile.seek(0) - res = self.tmpfile.read() - self.tmpfile.seek(0) - self.tmpfile.truncate() - return res - - def writeorg(self, data: str) -> None: - """Write to original file descriptor.""" - self._assert_state("writeorg", ("started", "suspended")) - # XXX use encoding of original stream - os.write(self.targetfd_save, data.encode("utf-8")) - - -# MultiCapture - - -# Generic NamedTuple only supported since Python 3.11. -if sys.version_info >= (3, 11) or TYPE_CHECKING: - - @final - class CaptureResult(NamedTuple, Generic[AnyStr]): - """The result of :method:`caplog.readouterr() `.""" - - out: AnyStr - err: AnyStr - -else: - - class CaptureResult( - collections.namedtuple("CaptureResult", ["out", "err"]), # noqa: PYI024 - Generic[AnyStr], - ): - """The result of :method:`caplog.readouterr() `.""" - - __slots__ = () - - -class MultiCapture(Generic[AnyStr]): - _state = None - _in_suspended = False - - def __init__( - self, - in_: CaptureBase[AnyStr] | None, - out: CaptureBase[AnyStr] | None, - err: CaptureBase[AnyStr] | None, - ) -> None: - self.in_: CaptureBase[AnyStr] | None = in_ - self.out: CaptureBase[AnyStr] | None = out - self.err: CaptureBase[AnyStr] | None = err - - def __repr__(self) -> str: - return ( - f"" - ) - - def start_capturing(self) -> None: - self._state = "started" - if self.in_: - self.in_.start() - if self.out: - self.out.start() - if self.err: - self.err.start() - - def pop_outerr_to_orig(self) -> tuple[AnyStr, AnyStr]: - """Pop current snapshot out/err capture and flush to orig streams.""" - out, err = self.readouterr() - if out: - assert self.out is not None - self.out.writeorg(out) - if err: - assert self.err is not None - self.err.writeorg(err) - return out, err - - def suspend_capturing(self, in_: bool = False) -> None: - self._state = "suspended" - if self.out: - self.out.suspend() - if self.err: - self.err.suspend() - if in_ and self.in_: - self.in_.suspend() - self._in_suspended = True - - def resume_capturing(self) -> None: - self._state = "started" - if self.out: - self.out.resume() - if self.err: - self.err.resume() - if self._in_suspended: - assert self.in_ is not None - self.in_.resume() - self._in_suspended = False - - def stop_capturing(self) -> None: - """Stop capturing and reset capturing streams.""" - if self._state == "stopped": - raise ValueError("was already stopped") - self._state = "stopped" - if self.out: - self.out.done() - if self.err: - self.err.done() - if self.in_: - self.in_.done() - - def is_started(self) -> bool: - """Whether actively capturing -- not suspended or stopped.""" - return self._state == "started" - - def readouterr(self) -> CaptureResult[AnyStr]: - out = self.out.snap() if self.out else "" - err = self.err.snap() if self.err else "" - # TODO: This type error is real, need to fix. - return CaptureResult(out, err) # type: ignore[arg-type] - - -def _get_multicapture(method: _CaptureMethod) -> MultiCapture[str]: - if method == "fd": - return MultiCapture(in_=FDCapture(0), out=FDCapture(1), err=FDCapture(2)) - elif method == "sys": - return MultiCapture(in_=SysCapture(0), out=SysCapture(1), err=SysCapture(2)) - elif method == "no": - return MultiCapture(in_=None, out=None, err=None) - elif method == "tee-sys": - return MultiCapture( - in_=None, out=SysCapture(1, tee=True), err=SysCapture(2, tee=True) - ) - raise ValueError(f"unknown capturing method: {method!r}") - - -# CaptureManager and CaptureFixture - - -class CaptureManager: - """The capture plugin. - - Manages that the appropriate capture method is enabled/disabled during - collection and each test phase (setup, call, teardown). After each of - those points, the captured output is obtained and attached to the - collection/runtest report. - - There are two levels of capture: - - * global: enabled by default and can be suppressed by the ``-s`` - option. This is always enabled/disabled during collection and each test - phase. - - * fixture: when a test function or one of its fixture depend on the - ``capsys`` or ``capfd`` fixtures. In this case special handling is - needed to ensure the fixtures take precedence over the global capture. - """ - - def __init__(self, method: _CaptureMethod) -> None: - self._method: Final = method - self._global_capturing: MultiCapture[str] | None = None - self._capture_fixture: CaptureFixture[Any] | None = None - - def __repr__(self) -> str: - return ( - f"" - ) - - def is_capturing(self) -> str | bool: - if self.is_globally_capturing(): - return "global" - if self._capture_fixture: - return f"fixture {self._capture_fixture.request.fixturename}" - return False - - # Global capturing control - - def is_globally_capturing(self) -> bool: - return self._method != "no" - - def start_global_capturing(self) -> None: - assert self._global_capturing is None - self._global_capturing = _get_multicapture(self._method) - self._global_capturing.start_capturing() - - def stop_global_capturing(self) -> None: - if self._global_capturing is not None: - self._global_capturing.pop_outerr_to_orig() - self._global_capturing.stop_capturing() - self._global_capturing = None - - def resume_global_capture(self) -> None: - # During teardown of the python process, and on rare occasions, capture - # attributes can be `None` while trying to resume global capture. - if self._global_capturing is not None: - self._global_capturing.resume_capturing() - - def suspend_global_capture(self, in_: bool = False) -> None: - if self._global_capturing is not None: - self._global_capturing.suspend_capturing(in_=in_) - - def suspend(self, in_: bool = False) -> None: - # Need to undo local capsys-et-al if it exists before disabling global capture. - self.suspend_fixture() - self.suspend_global_capture(in_) - - def resume(self) -> None: - self.resume_global_capture() - self.resume_fixture() - - def read_global_capture(self) -> CaptureResult[str]: - assert self._global_capturing is not None - return self._global_capturing.readouterr() - - # Fixture Control - - def set_fixture(self, capture_fixture: CaptureFixture[Any]) -> None: - if self._capture_fixture: - current_fixture = self._capture_fixture.request.fixturename - requested_fixture = capture_fixture.request.fixturename - capture_fixture.request.raiseerror( - f"cannot use {requested_fixture} and {current_fixture} at the same time" - ) - self._capture_fixture = capture_fixture - - def unset_fixture(self) -> None: - self._capture_fixture = None - - def activate_fixture(self) -> None: - """If the current item is using ``capsys`` or ``capfd``, activate - them so they take precedence over the global capture.""" - if self._capture_fixture: - self._capture_fixture._start() - - def deactivate_fixture(self) -> None: - """Deactivate the ``capsys`` or ``capfd`` fixture of this item, if any.""" - if self._capture_fixture: - self._capture_fixture.close() - - def suspend_fixture(self) -> None: - if self._capture_fixture: - self._capture_fixture._suspend() - - def resume_fixture(self) -> None: - if self._capture_fixture: - self._capture_fixture._resume() - - # Helper context managers - - @contextlib.contextmanager - def global_and_fixture_disabled(self) -> Generator[None]: - """Context manager to temporarily disable global and current fixture capturing.""" - do_fixture = self._capture_fixture and self._capture_fixture._is_started() - if do_fixture: - self.suspend_fixture() - do_global = self._global_capturing and self._global_capturing.is_started() - if do_global: - self.suspend_global_capture() - try: - yield - finally: - if do_global: - self.resume_global_capture() - if do_fixture: - self.resume_fixture() - - @contextlib.contextmanager - def item_capture(self, when: str, item: Item) -> Generator[None]: - self.resume_global_capture() - self.activate_fixture() - try: - yield - finally: - self.deactivate_fixture() - self.suspend_global_capture(in_=False) - - out, err = self.read_global_capture() - item.add_report_section(when, "stdout", out) - item.add_report_section(when, "stderr", err) - - # Hooks - - @hookimpl(wrapper=True) - def pytest_make_collect_report( - self, collector: Collector - ) -> Generator[None, CollectReport, CollectReport]: - if isinstance(collector, File): - self.resume_global_capture() - try: - rep = yield - finally: - self.suspend_global_capture() - out, err = self.read_global_capture() - if out: - rep.sections.append(("Captured stdout", out)) - if err: - rep.sections.append(("Captured stderr", err)) - else: - rep = yield - return rep - - @hookimpl(wrapper=True) - def pytest_runtest_setup(self, item: Item) -> Generator[None]: - with self.item_capture("setup", item): - return (yield) - - @hookimpl(wrapper=True) - def pytest_runtest_call(self, item: Item) -> Generator[None]: - with self.item_capture("call", item): - return (yield) - - @hookimpl(wrapper=True) - def pytest_runtest_teardown(self, item: Item) -> Generator[None]: - with self.item_capture("teardown", item): - return (yield) - - @hookimpl(tryfirst=True) - def pytest_keyboard_interrupt(self) -> None: - self.stop_global_capturing() - - @hookimpl(tryfirst=True) - def pytest_internalerror(self) -> None: - self.stop_global_capturing() - - -class CaptureFixture(Generic[AnyStr]): - """Object returned by the :fixture:`capsys`, :fixture:`capsysbinary`, - :fixture:`capfd` and :fixture:`capfdbinary` fixtures.""" - - def __init__( - self, - captureclass: type[CaptureBase[AnyStr]], - request: SubRequest, - *, - config: dict[str, Any] | None = None, - _ispytest: bool = False, - ) -> None: - check_ispytest(_ispytest) - self.captureclass: type[CaptureBase[AnyStr]] = captureclass - self.request = request - self._config = config if config else {} - self._capture: MultiCapture[AnyStr] | None = None - self._captured_out: AnyStr = self.captureclass.EMPTY_BUFFER - self._captured_err: AnyStr = self.captureclass.EMPTY_BUFFER - - def _start(self) -> None: - if self._capture is None: - self._capture = MultiCapture( - in_=None, - out=self.captureclass(1, **self._config), - err=self.captureclass(2, **self._config), - ) - self._capture.start_capturing() - - def close(self) -> None: - if self._capture is not None: - out, err = self._capture.pop_outerr_to_orig() - self._captured_out += out - self._captured_err += err - self._capture.stop_capturing() - self._capture = None - - def readouterr(self) -> CaptureResult[AnyStr]: - """Read and return the captured output so far, resetting the internal - buffer. - - :returns: - The captured content as a namedtuple with ``out`` and ``err`` - string attributes. - """ - captured_out, captured_err = self._captured_out, self._captured_err - if self._capture is not None: - out, err = self._capture.readouterr() - captured_out += out - captured_err += err - self._captured_out = self.captureclass.EMPTY_BUFFER - self._captured_err = self.captureclass.EMPTY_BUFFER - return CaptureResult(captured_out, captured_err) - - def _suspend(self) -> None: - """Suspend this fixture's own capturing temporarily.""" - if self._capture is not None: - self._capture.suspend_capturing() - - def _resume(self) -> None: - """Resume this fixture's own capturing temporarily.""" - if self._capture is not None: - self._capture.resume_capturing() - - def _is_started(self) -> bool: - """Whether actively capturing -- not disabled or closed.""" - if self._capture is not None: - return self._capture.is_started() - return False - - @contextlib.contextmanager - def disabled(self) -> Generator[None]: - """Temporarily disable capturing while inside the ``with`` block.""" - capmanager: CaptureManager = self.request.config.pluginmanager.getplugin( - "capturemanager" - ) - with capmanager.global_and_fixture_disabled(): - yield - - -# The fixtures. - - -@fixture -def capsys(request: SubRequest) -> Generator[CaptureFixture[str]]: - r"""Enable text capturing of writes to ``sys.stdout`` and ``sys.stderr``. - - The captured output is made available via ``capsys.readouterr()`` method - calls, which return a ``(out, err)`` namedtuple. - ``out`` and ``err`` will be ``text`` objects. - - Returns an instance of :class:`CaptureFixture[str] `. - - Example: - - .. code-block:: python - - def test_output(capsys): - print("hello") - captured = capsys.readouterr() - assert captured.out == "hello\n" - """ - capman: CaptureManager = request.config.pluginmanager.getplugin("capturemanager") - capture_fixture = CaptureFixture(SysCapture, request, _ispytest=True) - capman.set_fixture(capture_fixture) - capture_fixture._start() - yield capture_fixture - capture_fixture.close() - capman.unset_fixture() - - -@fixture -def capteesys(request: SubRequest) -> Generator[CaptureFixture[str]]: - r"""Enable simultaneous text capturing and pass-through of writes - to ``sys.stdout`` and ``sys.stderr`` as defined by ``--capture=``. - - - The captured output is made available via ``capteesys.readouterr()`` method - calls, which return a ``(out, err)`` namedtuple. - ``out`` and ``err`` will be ``text`` objects. - - The output is also passed-through, allowing it to be "live-printed", - reported, or both as defined by ``--capture=``. - - Returns an instance of :class:`CaptureFixture[str] `. - - Example: - - .. code-block:: python - - def test_output(capteesys): - print("hello") - captured = capteesys.readouterr() - assert captured.out == "hello\n" - """ - capman: CaptureManager = request.config.pluginmanager.getplugin("capturemanager") - capture_fixture = CaptureFixture( - SysCapture, request, config=dict(tee=True), _ispytest=True - ) - capman.set_fixture(capture_fixture) - capture_fixture._start() - yield capture_fixture - capture_fixture.close() - capman.unset_fixture() - - -@fixture -def capsysbinary(request: SubRequest) -> Generator[CaptureFixture[bytes]]: - r"""Enable bytes capturing of writes to ``sys.stdout`` and ``sys.stderr``. - - The captured output is made available via ``capsysbinary.readouterr()`` - method calls, which return a ``(out, err)`` namedtuple. - ``out`` and ``err`` will be ``bytes`` objects. - - Returns an instance of :class:`CaptureFixture[bytes] `. - - Example: - - .. code-block:: python - - def test_output(capsysbinary): - print("hello") - captured = capsysbinary.readouterr() - assert captured.out == b"hello\n" - """ - capman: CaptureManager = request.config.pluginmanager.getplugin("capturemanager") - capture_fixture = CaptureFixture(SysCaptureBinary, request, _ispytest=True) - capman.set_fixture(capture_fixture) - capture_fixture._start() - yield capture_fixture - capture_fixture.close() - capman.unset_fixture() - - -@fixture -def capfd(request: SubRequest) -> Generator[CaptureFixture[str]]: - r"""Enable text capturing of writes to file descriptors ``1`` and ``2``. - - The captured output is made available via ``capfd.readouterr()`` method - calls, which return a ``(out, err)`` namedtuple. - ``out`` and ``err`` will be ``text`` objects. - - Returns an instance of :class:`CaptureFixture[str] `. - - Example: - - .. code-block:: python - - def test_system_echo(capfd): - os.system('echo "hello"') - captured = capfd.readouterr() - assert captured.out == "hello\n" - """ - capman: CaptureManager = request.config.pluginmanager.getplugin("capturemanager") - capture_fixture = CaptureFixture(FDCapture, request, _ispytest=True) - capman.set_fixture(capture_fixture) - capture_fixture._start() - yield capture_fixture - capture_fixture.close() - capman.unset_fixture() - - -@fixture -def capfdbinary(request: SubRequest) -> Generator[CaptureFixture[bytes]]: - r"""Enable bytes capturing of writes to file descriptors ``1`` and ``2``. - - The captured output is made available via ``capfd.readouterr()`` method - calls, which return a ``(out, err)`` namedtuple. - ``out`` and ``err`` will be ``byte`` objects. - - Returns an instance of :class:`CaptureFixture[bytes] `. - - Example: - - .. code-block:: python - - def test_system_echo(capfdbinary): - os.system('echo "hello"') - captured = capfdbinary.readouterr() - assert captured.out == b"hello\n" - - """ - capman: CaptureManager = request.config.pluginmanager.getplugin("capturemanager") - capture_fixture = CaptureFixture(FDCaptureBinary, request, _ispytest=True) - capman.set_fixture(capture_fixture) - capture_fixture._start() - yield capture_fixture - capture_fixture.close() - capman.unset_fixture() diff --git a/.venv/lib/python3.12/site-packages/_pytest/compat.py b/.venv/lib/python3.12/site-packages/_pytest/compat.py deleted file mode 100644 index 72c3d09..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/compat.py +++ /dev/null @@ -1,314 +0,0 @@ -# mypy: allow-untyped-defs -"""Python version compatibility code and random general utilities.""" - -from __future__ import annotations - -from collections.abc import Callable -import enum -import functools -import inspect -from inspect import Parameter -from inspect import Signature -import os -from pathlib import Path -import sys -from typing import Any -from typing import Final -from typing import NoReturn - -import py - - -if sys.version_info >= (3, 14): - from annotationlib import Format - - -#: constant to prepare valuing pylib path replacements/lazy proxies later on -# intended for removal in pytest 8.0 or 9.0 - -# fmt: off -# intentional space to create a fake difference for the verification -LEGACY_PATH = py.path. local -# fmt: on - - -def legacy_path(path: str | os.PathLike[str]) -> LEGACY_PATH: - """Internal wrapper to prepare lazy proxies for legacy_path instances""" - return LEGACY_PATH(path) - - -# fmt: off -# Singleton type for NOTSET, as described in: -# https://www.python.org/dev/peps/pep-0484/#support-for-singleton-types-in-unions -class NotSetType(enum.Enum): - token = 0 -NOTSET: Final = NotSetType.token -# fmt: on - - -def iscoroutinefunction(func: object) -> bool: - """Return True if func is a coroutine function (a function defined with async - def syntax, and doesn't contain yield), or a function decorated with - @asyncio.coroutine. - - Note: copied and modified from Python 3.5's builtin coroutines.py to avoid - importing asyncio directly, which in turns also initializes the "logging" - module as a side-effect (see issue #8). - """ - return inspect.iscoroutinefunction(func) or getattr(func, "_is_coroutine", False) - - -def is_async_function(func: object) -> bool: - """Return True if the given function seems to be an async function or - an async generator.""" - return iscoroutinefunction(func) or inspect.isasyncgenfunction(func) - - -def signature(obj: Callable[..., Any]) -> Signature: - """Return signature without evaluating annotations.""" - if sys.version_info >= (3, 14): - return inspect.signature(obj, annotation_format=Format.STRING) - return inspect.signature(obj) - - -def getlocation(function, curdir: str | os.PathLike[str] | None = None) -> str: - function = get_real_func(function) - fn = Path(inspect.getfile(function)) - lineno = function.__code__.co_firstlineno - if curdir is not None: - try: - relfn = fn.relative_to(curdir) - except ValueError: - pass - else: - return f"{relfn}:{lineno + 1}" - return f"{fn}:{lineno + 1}" - - -def num_mock_patch_args(function) -> int: - """Return number of arguments used up by mock arguments (if any).""" - patchings = getattr(function, "patchings", None) - if not patchings: - return 0 - - mock_sentinel = getattr(sys.modules.get("mock"), "DEFAULT", object()) - ut_mock_sentinel = getattr(sys.modules.get("unittest.mock"), "DEFAULT", object()) - - return len( - [ - p - for p in patchings - if not p.attribute_name - and (p.new is mock_sentinel or p.new is ut_mock_sentinel) - ] - ) - - -def getfuncargnames( - function: Callable[..., object], - *, - name: str = "", - cls: type | None = None, -) -> tuple[str, ...]: - """Return the names of a function's mandatory arguments. - - Should return the names of all function arguments that: - * Aren't bound to an instance or type as in instance or class methods. - * Don't have default values. - * Aren't bound with functools.partial. - * Aren't replaced with mocks. - - The cls arguments indicate that the function should be treated as a bound - method even though it's not unless the function is a static method. - - The name parameter should be the original name in which the function was collected. - """ - # TODO(RonnyPfannschmidt): This function should be refactored when we - # revisit fixtures. The fixture mechanism should ask the node for - # the fixture names, and not try to obtain directly from the - # function object well after collection has occurred. - - # The parameters attribute of a Signature object contains an - # ordered mapping of parameter names to Parameter instances. This - # creates a tuple of the names of the parameters that don't have - # defaults. - try: - parameters = signature(function).parameters.values() - except (ValueError, TypeError) as e: - from _pytest.outcomes import fail - - fail( - f"Could not determine arguments of {function!r}: {e}", - pytrace=False, - ) - - arg_names = tuple( - p.name - for p in parameters - if ( - p.kind is Parameter.POSITIONAL_OR_KEYWORD - or p.kind is Parameter.KEYWORD_ONLY - ) - and p.default is Parameter.empty - ) - if not name: - name = function.__name__ - - # If this function should be treated as a bound method even though - # it's passed as an unbound method or function, and its first parameter - # wasn't defined as positional only, remove the first parameter name. - if not any(p.kind is Parameter.POSITIONAL_ONLY for p in parameters) and ( - # Not using `getattr` because we don't want to resolve the staticmethod. - # Not using `cls.__dict__` because we want to check the entire MRO. - cls - and not isinstance( - inspect.getattr_static(cls, name, default=None), staticmethod - ) - ): - arg_names = arg_names[1:] - # Remove any names that will be replaced with mocks. - if hasattr(function, "__wrapped__"): - arg_names = arg_names[num_mock_patch_args(function) :] - return arg_names - - -def get_default_arg_names(function: Callable[..., Any]) -> tuple[str, ...]: - # Note: this code intentionally mirrors the code at the beginning of - # getfuncargnames, to get the arguments which were excluded from its result - # because they had default values. - return tuple( - p.name - for p in signature(function).parameters.values() - if p.kind in (Parameter.POSITIONAL_OR_KEYWORD, Parameter.KEYWORD_ONLY) - and p.default is not Parameter.empty - ) - - -_non_printable_ascii_translate_table = { - i: f"\\x{i:02x}" for i in range(128) if i not in range(32, 127) -} -_non_printable_ascii_translate_table.update( - {ord("\t"): "\\t", ord("\r"): "\\r", ord("\n"): "\\n"} -) - - -def ascii_escaped(val: bytes | str) -> str: - r"""If val is pure ASCII, return it as an str, otherwise, escape - bytes objects into a sequence of escaped bytes: - - b'\xc3\xb4\xc5\xd6' -> r'\xc3\xb4\xc5\xd6' - - and escapes strings into a sequence of escaped unicode ids, e.g.: - - r'4\nV\U00043efa\x0eMXWB\x1e\u3028\u15fd\xcd\U0007d944' - - Note: - The obvious "v.decode('unicode-escape')" will return - valid UTF-8 unicode if it finds them in bytes, but we - want to return escaped bytes for any byte, even if they match - a UTF-8 string. - """ - if isinstance(val, bytes): - ret = val.decode("ascii", "backslashreplace") - else: - ret = val.encode("unicode_escape").decode("ascii") - return ret.translate(_non_printable_ascii_translate_table) - - -def get_real_func(obj): - """Get the real function object of the (possibly) wrapped object by - :func:`functools.wraps`, or :func:`functools.partial`.""" - obj = inspect.unwrap(obj) - - if isinstance(obj, functools.partial): - obj = obj.func - return obj - - -def getimfunc(func): - try: - return func.__func__ - except AttributeError: - return func - - -def safe_getattr(object: Any, name: str, default: Any) -> Any: - """Like getattr but return default upon any Exception or any OutcomeException. - - Attribute access can potentially fail for 'evil' Python objects. - See issue #214. - It catches OutcomeException because of #2490 (issue #580), new outcomes - are derived from BaseException instead of Exception (for more details - check #2707). - """ - from _pytest.outcomes import TEST_OUTCOME - - try: - return getattr(object, name, default) - except TEST_OUTCOME: - return default - - -def safe_isclass(obj: object) -> bool: - """Ignore any exception via isinstance on Python 3.""" - try: - return inspect.isclass(obj) - except Exception: - return False - - -def get_user_id() -> int | None: - """Return the current process's real user id or None if it could not be - determined. - - :return: The user id or None if it could not be determined. - """ - # mypy follows the version and platform checking expectation of PEP 484: - # https://mypy.readthedocs.io/en/stable/common_issues.html?highlight=platform#python-version-and-system-platform-checks - # Containment checks are too complex for mypy v1.5.0 and cause failure. - if sys.platform == "win32" or sys.platform == "emscripten": - # win32 does not have a getuid() function. - # Emscripten has a return 0 stub. - return None - else: - # On other platforms, a return value of -1 is assumed to indicate that - # the current process's real user id could not be determined. - ERROR = -1 - uid = os.getuid() - return uid if uid != ERROR else None - - -if sys.version_info >= (3, 11): - from typing import assert_never -else: - - def assert_never(value: NoReturn) -> NoReturn: - assert False, f"Unhandled value: {value} ({type(value).__name__})" - - -class CallableBool: - """ - A bool-like object that can also be called, returning its true/false value. - - Used for backwards compatibility in cases where something was supposed to be a method - but was implemented as a simple attribute by mistake (see `TerminalReporter.isatty`). - - Do not use in new code. - """ - - def __init__(self, value: bool) -> None: - self._value = value - - def __bool__(self) -> bool: - return self._value - - def __call__(self) -> bool: - return self._value - - -def running_on_ci() -> bool: - """Check if we're currently running on a CI system.""" - # Only enable CI mode if one of these env variables is defined and non-empty. - # Note: review `regendoc` tox env in case this list is changed. - env_vars = ["CI", "BUILD_NUMBER"] - return any(os.environ.get(var) for var in env_vars) diff --git a/.venv/lib/python3.12/site-packages/_pytest/config/__init__.py b/.venv/lib/python3.12/site-packages/_pytest/config/__init__.py deleted file mode 100644 index a027dbc..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/config/__init__.py +++ /dev/null @@ -1,2203 +0,0 @@ -# mypy: allow-untyped-defs -"""Command line options, config-file and conftest.py processing.""" - -from __future__ import annotations - -import argparse -import builtins -import collections.abc -from collections.abc import Callable -from collections.abc import Generator -from collections.abc import Iterable -from collections.abc import Iterator -from collections.abc import Mapping -from collections.abc import MutableMapping -from collections.abc import Sequence -import contextlib -import copy -import dataclasses -import enum -from functools import lru_cache -import glob -import importlib.metadata -import inspect -import os -import pathlib -import re -import shlex -import sys -from textwrap import dedent -import types -from types import FunctionType -from typing import Any -from typing import cast -from typing import Final -from typing import final -from typing import IO -from typing import TextIO -from typing import TYPE_CHECKING -import warnings - -import pluggy -from pluggy import HookimplMarker -from pluggy import HookimplOpts -from pluggy import HookspecMarker -from pluggy import HookspecOpts -from pluggy import PluginManager - -from .compat import PathAwareHookProxy -from .exceptions import PrintHelp as PrintHelp -from .exceptions import UsageError as UsageError -from .findpaths import ConfigValue -from .findpaths import determine_setup -from _pytest import __version__ -import _pytest._code -from _pytest._code import ExceptionInfo -from _pytest._code import filter_traceback -from _pytest._code.code import TracebackStyle -from _pytest._io import TerminalWriter -from _pytest.compat import assert_never -from _pytest.config.argparsing import Argument -from _pytest.config.argparsing import FILE_OR_DIR -from _pytest.config.argparsing import Parser -import _pytest.deprecated -import _pytest.hookspec -from _pytest.outcomes import fail -from _pytest.outcomes import Skipped -from _pytest.pathlib import absolutepath -from _pytest.pathlib import bestrelpath -from _pytest.pathlib import import_path -from _pytest.pathlib import ImportMode -from _pytest.pathlib import resolve_package_path -from _pytest.pathlib import safe_exists -from _pytest.stash import Stash -from _pytest.warning_types import PytestConfigWarning -from _pytest.warning_types import warn_explicit_for - - -if TYPE_CHECKING: - from _pytest.assertion.rewrite import AssertionRewritingHook - from _pytest.cacheprovider import Cache - from _pytest.terminal import TerminalReporter - -_PluggyPlugin = object -"""A type to represent plugin objects. - -Plugins can be any namespace, so we can't narrow it down much, but we use an -alias to make the intent clear. - -Ideally this type would be provided by pluggy itself. -""" - - -hookimpl = HookimplMarker("pytest") -hookspec = HookspecMarker("pytest") - - -@final -class ExitCode(enum.IntEnum): - """Encodes the valid exit codes by pytest. - - Currently users and plugins may supply other exit codes as well. - - .. versionadded:: 5.0 - """ - - #: Tests passed. - OK = 0 - #: Tests failed. - TESTS_FAILED = 1 - #: pytest was interrupted. - INTERRUPTED = 2 - #: An internal error got in the way. - INTERNAL_ERROR = 3 - #: pytest was misused. - USAGE_ERROR = 4 - #: pytest couldn't find tests. - NO_TESTS_COLLECTED = 5 - - __module__ = "pytest" - - -class ConftestImportFailure(Exception): - def __init__( - self, - path: pathlib.Path, - *, - cause: Exception, - ) -> None: - self.path = path - self.cause = cause - - def __str__(self) -> str: - return f"{type(self.cause).__name__}: {self.cause} (from {self.path})" - - -def filter_traceback_for_conftest_import_failure( - entry: _pytest._code.TracebackEntry, -) -> bool: - """Filter tracebacks entries which point to pytest internals or importlib. - - Make a special case for importlib because we use it to import test modules and conftest files - in _pytest.pathlib.import_path. - """ - return filter_traceback(entry) and "importlib" not in str(entry.path).split(os.sep) - - -def print_conftest_import_error(e: ConftestImportFailure, file: TextIO) -> None: - exc_info = ExceptionInfo.from_exception(e.cause) - tw = TerminalWriter(file) - tw.line(f"ImportError while loading conftest '{e.path}'.", red=True) - exc_info.traceback = exc_info.traceback.filter( - filter_traceback_for_conftest_import_failure - ) - exc_repr = ( - exc_info.getrepr(style="short", chain=False) - if exc_info.traceback - else exc_info.exconly() - ) - formatted_tb = str(exc_repr) - for line in formatted_tb.splitlines(): - tw.line(line.rstrip(), red=True) - - -def print_usage_error(e: UsageError, file: TextIO) -> None: - tw = TerminalWriter(file) - for msg in e.args: - tw.line(f"ERROR: {msg}\n", red=True) - - -def main( - args: list[str] | os.PathLike[str] | None = None, - plugins: Sequence[str | _PluggyPlugin] | None = None, -) -> int | ExitCode: - """Perform an in-process test run. - - :param args: - List of command line arguments. If `None` or not given, defaults to reading - arguments directly from the process command line (:data:`sys.argv`). - :param plugins: List of plugin objects to be auto-registered during initialization. - - :returns: An exit code. - """ - # Handle a single `--version` argument early to avoid starting up the entire pytest infrastructure. - new_args = sys.argv[1:] if args is None else args - if isinstance(new_args, Sequence) and new_args.count("--version") == 1: - sys.stdout.write(f"pytest {__version__}\n") - return ExitCode.OK - - old_pytest_version = os.environ.get("PYTEST_VERSION") - try: - os.environ["PYTEST_VERSION"] = __version__ - try: - config = _prepareconfig(new_args, plugins) - except ConftestImportFailure as e: - print_conftest_import_error(e, file=sys.stderr) - return ExitCode.USAGE_ERROR - - try: - ret: ExitCode | int = config.hook.pytest_cmdline_main(config=config) - try: - return ExitCode(ret) - except ValueError: - return ret - finally: - config._ensure_unconfigure() - except UsageError as e: - print_usage_error(e, file=sys.stderr) - return ExitCode.USAGE_ERROR - finally: - if old_pytest_version is None: - os.environ.pop("PYTEST_VERSION", None) - else: - os.environ["PYTEST_VERSION"] = old_pytest_version - - -def console_main() -> int: - """The CLI entry point of pytest. - - This function is not meant for programmable use; use `main()` instead. - """ - # https://docs.python.org/3/library/signal.html#note-on-sigpipe - try: - code = main() - sys.stdout.flush() - return code - except BrokenPipeError: - # Python flushes standard streams on exit; redirect remaining output - # to devnull to avoid another BrokenPipeError at shutdown - devnull = os.open(os.devnull, os.O_WRONLY) - os.dup2(devnull, sys.stdout.fileno()) - return 1 # Python exits with error code 1 on EPIPE - - -class cmdline: # compatibility namespace - main = staticmethod(main) - - -def filename_arg(path: str, optname: str) -> str: - """Argparse type validator for filename arguments. - - :path: Path of filename. - :optname: Name of the option. - """ - if os.path.isdir(path): - raise UsageError(f"{optname} must be a filename, given: {path}") - return path - - -def directory_arg(path: str, optname: str) -> str: - """Argparse type validator for directory arguments. - - :path: Path of directory. - :optname: Name of the option. - """ - if not os.path.isdir(path): - raise UsageError(f"{optname} must be a directory, given: {path}") - return path - - -# Plugins that cannot be disabled via "-p no:X" currently. -essential_plugins = ( - "mark", - "main", - "runner", - "fixtures", - "helpconfig", # Provides -p. -) - -default_plugins = ( - *essential_plugins, - "python", - "terminal", - "debugging", - "unittest", - "capture", - "skipping", - "legacypath", - "tmpdir", - "monkeypatch", - "recwarn", - "pastebin", - "assertion", - "junitxml", - "doctest", - "cacheprovider", - "setuponly", - "setupplan", - "stepwise", - "unraisableexception", - "threadexception", - "warnings", - "logging", - "reports", - "faulthandler", - "subtests", -) - -builtin_plugins = { - *default_plugins, - "pytester", - "pytester_assertions", - "terminalprogress", -} - - -def get_config( - args: Iterable[str] | None = None, - plugins: Sequence[str | _PluggyPlugin] | None = None, -) -> Config: - # Subsequent calls to main will create a fresh instance. - pluginmanager = PytestPluginManager() - invocation_params = Config.InvocationParams( - args=args or (), - plugins=plugins, - dir=pathlib.Path.cwd(), - ) - config = Config(pluginmanager, invocation_params=invocation_params) - - if invocation_params.args: - # Handle any "-p no:plugin" args. - pluginmanager.consider_preparse(invocation_params.args, exclude_only=True) - - for spec in default_plugins: - pluginmanager.import_plugin(spec) - - return config - - -def get_plugin_manager() -> PytestPluginManager: - """Obtain a new instance of the - :py:class:`pytest.PytestPluginManager`, with default plugins - already loaded. - - This function can be used by integration with other tools, like hooking - into pytest to run tests into an IDE. - """ - return get_config().pluginmanager - - -def _prepareconfig( - args: list[str] | os.PathLike[str], - plugins: Sequence[str | _PluggyPlugin] | None = None, -) -> Config: - if isinstance(args, os.PathLike): - args = [os.fspath(args)] - elif not isinstance(args, list): - msg = ( # type:ignore[unreachable] - "`args` parameter expected to be a list of strings, got: {!r} (type: {})" - ) - raise TypeError(msg.format(args, type(args))) - - initial_config = get_config(args, plugins) - pluginmanager = initial_config.pluginmanager - try: - if plugins: - for plugin in plugins: - if isinstance(plugin, str): - pluginmanager.consider_pluginarg(plugin) - else: - pluginmanager.register(plugin) - config: Config = pluginmanager.hook.pytest_cmdline_parse( - pluginmanager=pluginmanager, args=args - ) - return config - except BaseException: - initial_config._ensure_unconfigure() - raise - - -def _get_directory(path: pathlib.Path) -> pathlib.Path: - """Get the directory of a path - itself if already a directory.""" - if path.is_file(): - return path.parent - else: - return path - - -def _get_legacy_hook_marks( - method: Any, - hook_type: str, - opt_names: tuple[str, ...], -) -> dict[str, bool]: - if TYPE_CHECKING: - # abuse typeguard from importlib to avoid massive method type union that's lacking an alias - assert inspect.isroutine(method) - known_marks: set[str] = {m.name for m in getattr(method, "pytestmark", [])} - must_warn: list[str] = [] - opts: dict[str, bool] = {} - for opt_name in opt_names: - opt_attr = getattr(method, opt_name, AttributeError) - if opt_attr is not AttributeError: - must_warn.append(f"{opt_name}={opt_attr}") - opts[opt_name] = True - elif opt_name in known_marks: - must_warn.append(f"{opt_name}=True") - opts[opt_name] = True - else: - opts[opt_name] = False - if must_warn: - hook_opts = ", ".join(must_warn) - message = _pytest.deprecated.HOOK_LEGACY_MARKING.format( - type=hook_type, - fullname=method.__qualname__, - hook_opts=hook_opts, - ) - warn_explicit_for(cast(FunctionType, method), message) - return opts - - -@final -class PytestPluginManager(PluginManager): - """A :py:class:`pluggy.PluginManager ` with - additional pytest-specific functionality: - - * Loading plugins from the command line, ``PYTEST_PLUGINS`` env variable and - ``pytest_plugins`` global variables found in plugins being loaded. - * ``conftest.py`` loading during start-up. - """ - - def __init__(self) -> None: - from _pytest.assertion import DummyRewriteHook - from _pytest.assertion import RewriteHook - - super().__init__("pytest") - - # -- State related to local conftest plugins. - # All loaded conftest modules. - self._conftest_plugins: set[types.ModuleType] = set() - # All conftest modules applicable for a directory. - # This includes the directory's own conftest modules as well - # as those of its parent directories. - self._dirpath2confmods: dict[pathlib.Path, list[types.ModuleType]] = {} - # Cutoff directory above which conftests are no longer discovered. - self._confcutdir: pathlib.Path | None = None - # If set, conftest loading is skipped. - self._noconftest = False - - # _getconftestmodules()'s call to _get_directory() causes a stat - # storm when it's called potentially thousands of times in a test - # session (#9478), often with the same path, so cache it. - self._get_directory = lru_cache(256)(_get_directory) - - # plugins that were explicitly skipped with pytest.skip - # list of (module name, skip reason) - # previously we would issue a warning when a plugin was skipped, but - # since we refactored warnings as first citizens of Config, they are - # just stored here to be used later. - self.skipped_plugins: list[tuple[str, str]] = [] - - self.add_hookspecs(_pytest.hookspec) - self.register(self) - if os.environ.get("PYTEST_DEBUG"): - err: IO[str] = sys.stderr - encoding: str = getattr(err, "encoding", "utf8") - try: - err = open( - os.dup(err.fileno()), - mode=err.mode, - buffering=1, - encoding=encoding, - ) - except Exception: - pass - self.trace.root.setwriter(err.write) - self.enable_tracing() - - # Config._consider_importhook will set a real object if required. - self.rewrite_hook: RewriteHook = DummyRewriteHook() - # Used to know when we are importing conftests after the pytest_configure stage. - self._configured = False - - def parse_hookimpl_opts( - self, plugin: _PluggyPlugin, name: str - ) -> HookimplOpts | None: - """:meta private:""" - # pytest hooks are always prefixed with "pytest_", - # so we avoid accessing possibly non-readable attributes - # (see issue #1073). - if not name.startswith("pytest_"): - return None - # Ignore names which cannot be hooks. - if name == "pytest_plugins": - return None - - opts = super().parse_hookimpl_opts(plugin, name) - if opts is not None: - return opts - - method = getattr(plugin, name) - # Consider only actual functions for hooks (#3775). - if not inspect.isroutine(method): - return None - # Collect unmarked hooks as long as they have the `pytest_' prefix. - legacy = _get_legacy_hook_marks( - method, "impl", ("tryfirst", "trylast", "optionalhook", "hookwrapper") - ) - return cast(HookimplOpts, legacy) - - def parse_hookspec_opts(self, module_or_class, name: str) -> HookspecOpts | None: - """:meta private:""" - opts = super().parse_hookspec_opts(module_or_class, name) - if opts is None: - method = getattr(module_or_class, name) - if name.startswith("pytest_"): - legacy = _get_legacy_hook_marks( - method, "spec", ("firstresult", "historic") - ) - opts = cast(HookspecOpts, legacy) - return opts - - def register(self, plugin: _PluggyPlugin, name: str | None = None) -> str | None: - if name in _pytest.deprecated.DEPRECATED_EXTERNAL_PLUGINS: - warnings.warn( - PytestConfigWarning( - "{} plugin has been merged into the core, " - "please remove it from your requirements.".format( - name.replace("_", "-") - ) - ) - ) - return None - plugin_name = super().register(plugin, name) - if plugin_name is not None: - self.hook.pytest_plugin_registered.call_historic( - kwargs=dict( - plugin=plugin, - plugin_name=plugin_name, - manager=self, - ) - ) - - if isinstance(plugin, types.ModuleType): - self.consider_module(plugin) - return plugin_name - - def getplugin(self, name: str): - # Support deprecated naming because plugins (xdist e.g.) use it. - plugin: _PluggyPlugin | None = self.get_plugin(name) - return plugin - - def hasplugin(self, name: str) -> bool: - """Return whether a plugin with the given name is registered.""" - return bool(self.get_plugin(name)) - - def pytest_configure(self, config: Config) -> None: - """:meta private:""" - # XXX now that the pluginmanager exposes hookimpl(tryfirst...) - # we should remove tryfirst/trylast as markers. - config.addinivalue_line( - "markers", - "tryfirst: mark a hook implementation function such that the " - "plugin machinery will try to call it first/as early as possible. " - "DEPRECATED, use @pytest.hookimpl(tryfirst=True) instead.", - ) - config.addinivalue_line( - "markers", - "trylast: mark a hook implementation function such that the " - "plugin machinery will try to call it last/as late as possible. " - "DEPRECATED, use @pytest.hookimpl(trylast=True) instead.", - ) - self._configured = True - - # - # Internal API for local conftest plugin handling. - # - def _set_initial_conftests( - self, - args: Sequence[str | pathlib.Path], - pyargs: bool, - noconftest: bool, - rootpath: pathlib.Path, - confcutdir: pathlib.Path | None, - invocation_dir: pathlib.Path, - importmode: ImportMode | str, - *, - consider_namespace_packages: bool, - ) -> None: - """Load initial conftest files given a preparsed "namespace". - - As conftest files may add their own command line options which have - arguments ('--my-opt somepath') we might get some false positives. - All builtin and 3rd party plugins will have been loaded, however, so - common options will not confuse our logic here. - """ - self._confcutdir = ( - absolutepath(invocation_dir / confcutdir) if confcutdir else None - ) - self._noconftest = noconftest - self._using_pyargs = pyargs - foundanchor = False - for initial_path in args: - path = str(initial_path) - # remove node-id syntax - i = path.find("::") - if i != -1: - path = path[:i] - anchor = absolutepath(invocation_dir / path) - - # Ensure we do not break if what appears to be an anchor - # is in fact a very long option (#10169, #11394). - if safe_exists(anchor): - self._try_load_conftest( - anchor, - importmode, - rootpath, - consider_namespace_packages=consider_namespace_packages, - ) - foundanchor = True - if not foundanchor: - self._try_load_conftest( - invocation_dir, - importmode, - rootpath, - consider_namespace_packages=consider_namespace_packages, - ) - - def _is_in_confcutdir(self, path: pathlib.Path) -> bool: - """Whether to consider the given path to load conftests from.""" - if self._confcutdir is None: - return True - # The semantics here are literally: - # Do not load a conftest if it is found upwards from confcut dir. - # But this is *not* the same as: - # Load only conftests from confcutdir or below. - # At first glance they might seem the same thing, however we do support use cases where - # we want to load conftests that are not found in confcutdir or below, but are found - # in completely different directory hierarchies like packages installed - # in out-of-source trees. - # (see #9767 for a regression where the logic was inverted). - return path not in self._confcutdir.parents - - def _try_load_conftest( - self, - anchor: pathlib.Path, - importmode: str | ImportMode, - rootpath: pathlib.Path, - *, - consider_namespace_packages: bool, - ) -> None: - self._loadconftestmodules( - anchor, - importmode, - rootpath, - consider_namespace_packages=consider_namespace_packages, - ) - # let's also consider test* subdirs - if anchor.is_dir(): - for x in anchor.glob("test*"): - if x.is_dir(): - self._loadconftestmodules( - x, - importmode, - rootpath, - consider_namespace_packages=consider_namespace_packages, - ) - - def _loadconftestmodules( - self, - path: pathlib.Path, - importmode: str | ImportMode, - rootpath: pathlib.Path, - *, - consider_namespace_packages: bool, - ) -> None: - if self._noconftest: - return - - directory = self._get_directory(path) - - # Optimization: avoid repeated searches in the same directory. - # Assumes always called with same importmode and rootpath. - if directory in self._dirpath2confmods: - return - - clist = [] - for parent in reversed((directory, *directory.parents)): - if self._is_in_confcutdir(parent): - conftestpath = parent / "conftest.py" - if conftestpath.is_file(): - mod = self._importconftest( - conftestpath, - importmode, - rootpath, - consider_namespace_packages=consider_namespace_packages, - ) - clist.append(mod) - self._dirpath2confmods[directory] = clist - - def _getconftestmodules(self, path: pathlib.Path) -> Sequence[types.ModuleType]: - directory = self._get_directory(path) - return self._dirpath2confmods.get(directory, ()) - - def _rget_with_confmod( - self, - name: str, - path: pathlib.Path, - ) -> tuple[types.ModuleType, Any]: - modules = self._getconftestmodules(path) - for mod in reversed(modules): - try: - return mod, getattr(mod, name) - except AttributeError: - continue - raise KeyError(name) - - def _importconftest( - self, - conftestpath: pathlib.Path, - importmode: str | ImportMode, - rootpath: pathlib.Path, - *, - consider_namespace_packages: bool, - ) -> types.ModuleType: - conftestpath_plugin_name = str(conftestpath) - existing = self.get_plugin(conftestpath_plugin_name) - if existing is not None: - return cast(types.ModuleType, existing) - - # conftest.py files there are not in a Python package all have module - # name "conftest", and thus conflict with each other. Clear the existing - # before loading the new one, otherwise the existing one will be - # returned from the module cache. - pkgpath = resolve_package_path(conftestpath) - if pkgpath is None: - try: - del sys.modules[conftestpath.stem] - except KeyError: - pass - - try: - mod = import_path( - conftestpath, - mode=importmode, - root=rootpath, - consider_namespace_packages=consider_namespace_packages, - ) - except Exception as e: - assert e.__traceback__ is not None - raise ConftestImportFailure(conftestpath, cause=e) from e - - self._check_non_top_pytest_plugins(mod, conftestpath) - - self._conftest_plugins.add(mod) - dirpath = conftestpath.parent - if dirpath in self._dirpath2confmods: - for path, mods in self._dirpath2confmods.items(): - if dirpath in path.parents or path == dirpath: - if mod in mods: - raise AssertionError( - f"While trying to load conftest path {conftestpath!s}, " - f"found that the module {mod} is already loaded with path {mod.__file__}. " - "This is not supposed to happen. Please report this issue to pytest." - ) - mods.append(mod) - self.trace(f"loading conftestmodule {mod!r}") - self.consider_conftest(mod, registration_name=conftestpath_plugin_name) - return mod - - def _check_non_top_pytest_plugins( - self, - mod: types.ModuleType, - conftestpath: pathlib.Path, - ) -> None: - if ( - hasattr(mod, "pytest_plugins") - and self._configured - and not self._using_pyargs - ): - msg = ( - "Defining 'pytest_plugins' in a non-top-level conftest is no longer supported:\n" - "It affects the entire test suite instead of just below the conftest as expected.\n" - " {}\n" - "Please move it to a top level conftest file at the rootdir:\n" - " {}\n" - "For more information, visit:\n" - " https://docs.pytest.org/en/stable/deprecations.html#pytest-plugins-in-non-top-level-conftest-files" - ) - fail(msg.format(conftestpath, self._confcutdir), pytrace=False) - - # - # API for bootstrapping plugin loading - # - # - - def consider_preparse( - self, args: Sequence[str], *, exclude_only: bool = False - ) -> None: - """:meta private:""" - i = 0 - n = len(args) - while i < n: - opt = args[i] - i += 1 - if isinstance(opt, str): - if opt == "-p": - try: - parg = args[i] - except IndexError: - return - i += 1 - elif opt.startswith("-p"): - parg = opt[2:] - else: - continue - parg = parg.strip() - if exclude_only and not parg.startswith("no:"): - continue - self.consider_pluginarg(parg) - - def consider_pluginarg(self, arg: str) -> None: - """:meta private:""" - if arg.startswith("no:"): - name = arg[3:] - if name in essential_plugins: - raise UsageError(f"plugin {name} cannot be disabled") - - if name.endswith("conftest.py"): - raise UsageError( - f"Blocking conftest files using -p is not supported: -p no:{name}\n" - "conftest.py files are not plugins and cannot be disabled via -p.\n" - ) - - # PR #4304: remove stepwise if cacheprovider is blocked. - if name == "cacheprovider": - self.set_blocked("stepwise") - self.set_blocked("pytest_stepwise") - - self.set_blocked(name) - if not name.startswith("pytest_"): - self.set_blocked("pytest_" + name) - else: - name = arg - # Unblock the plugin. - self.unblock(name) - if not name.startswith("pytest_"): - self.unblock("pytest_" + name) - self.import_plugin(arg, consider_entry_points=True) - - def consider_conftest( - self, conftestmodule: types.ModuleType, registration_name: str - ) -> None: - """:meta private:""" - self.register(conftestmodule, name=registration_name) - - def consider_env(self) -> None: - """:meta private:""" - self._import_plugin_specs(os.environ.get("PYTEST_PLUGINS")) - - def consider_module(self, mod: types.ModuleType) -> None: - """:meta private:""" - self._import_plugin_specs(getattr(mod, "pytest_plugins", [])) - - def _import_plugin_specs( - self, spec: None | types.ModuleType | str | Sequence[str] - ) -> None: - plugins = _get_plugin_specs_as_list(spec) - for import_spec in plugins: - self.import_plugin(import_spec) - - def import_plugin(self, modname: str, consider_entry_points: bool = False) -> None: - """Import a plugin with ``modname``. - - If ``consider_entry_points`` is True, entry point names are also - considered to find a plugin. - """ - # Most often modname refers to builtin modules, e.g. "pytester", - # "terminal" or "capture". Those plugins are registered under their - # basename for historic purposes but must be imported with the - # _pytest prefix. - assert isinstance(modname, str), ( - f"module name as text required, got {modname!r}" - ) - if self.is_blocked(modname) or self.get_plugin(modname) is not None: - return - - importspec = "_pytest." + modname if modname in builtin_plugins else modname - self.rewrite_hook.mark_rewrite(importspec) - - if consider_entry_points: - loaded = self.load_setuptools_entrypoints("pytest11", name=modname) - if loaded: - return - - try: - __import__(importspec) - except ImportError as e: - raise ImportError( - f'Error importing plugin "{modname}": {e.args[0]}' - ).with_traceback(e.__traceback__) from e - - except Skipped as e: - self.skipped_plugins.append((modname, e.msg or "")) - else: - mod = sys.modules[importspec] - self.register(mod, modname) - - -def _get_plugin_specs_as_list( - specs: None | types.ModuleType | str | Sequence[str], -) -> list[str]: - """Parse a plugins specification into a list of plugin names.""" - # None means empty. - if specs is None: - return [] - # Workaround for #3899 - a submodule which happens to be called "pytest_plugins". - if isinstance(specs, types.ModuleType): - return [] - # Comma-separated list. - if isinstance(specs, str): - return specs.split(",") if specs else [] - # Direct specification. - if isinstance(specs, collections.abc.Sequence): - return list(specs) - raise UsageError( - f"Plugins may be specified as a sequence or a ','-separated string of plugin names. Got: {specs!r}" - ) - - -class Notset: - def __repr__(self): - return "" - - -notset = Notset() - - -def _iter_rewritable_modules(package_files: Iterable[str]) -> Iterator[str]: - """Given an iterable of file names in a source distribution, return the "names" that should - be marked for assertion rewrite. - - For example the package "pytest_mock/__init__.py" should be added as "pytest_mock" in - the assertion rewrite mechanism. - - This function has to deal with dist-info based distributions and egg based distributions - (which are still very much in use for "editable" installs). - - Here are the file names as seen in a dist-info based distribution: - - pytest_mock/__init__.py - pytest_mock/_version.py - pytest_mock/plugin.py - pytest_mock.egg-info/PKG-INFO - - Here are the file names as seen in an egg based distribution: - - src/pytest_mock/__init__.py - src/pytest_mock/_version.py - src/pytest_mock/plugin.py - src/pytest_mock.egg-info/PKG-INFO - LICENSE - setup.py - - We have to take in account those two distribution flavors in order to determine which - names should be considered for assertion rewriting. - - More information: - https://github.com/pytest-dev/pytest-mock/issues/167 - """ - package_files = list(package_files) - seen_some = False - for fn in package_files: - is_simple_module = "/" not in fn and fn.endswith(".py") - is_package = fn.count("/") == 1 and fn.endswith("__init__.py") - if is_simple_module: - module_name, _ = os.path.splitext(fn) - # we ignore "setup.py" at the root of the distribution - # as well as editable installation finder modules made by setuptools - if module_name != "setup" and not module_name.startswith("__editable__"): - seen_some = True - yield module_name - elif is_package: - package_name = os.path.dirname(fn) - seen_some = True - yield package_name - - if not seen_some: - # At this point we did not find any packages or modules suitable for assertion - # rewriting, so we try again by stripping the first path component (to account for - # "src" based source trees for example). - # This approach lets us have the common case continue to be fast, as egg-distributions - # are rarer. - new_package_files = [] - for fn in package_files: - parts = fn.split("/") - new_fn = "/".join(parts[1:]) - if new_fn: - new_package_files.append(new_fn) - if new_package_files: - yield from _iter_rewritable_modules(new_package_files) - - -class _DeprecatedInicfgProxy(MutableMapping[str, Any]): - """Compatibility proxy for the deprecated Config.inicfg.""" - - __slots__ = ("_config",) - - def __init__(self, config: Config) -> None: - self._config = config - - def __getitem__(self, key: str) -> Any: - return self._config._inicfg[key].value - - def __setitem__(self, key: str, value: Any) -> None: - self._config._inicfg[key] = ConfigValue(value, origin="override", mode="toml") - - def __delitem__(self, key: str) -> None: - del self._config._inicfg[key] - - def __iter__(self) -> Iterator[str]: - return iter(self._config._inicfg) - - def __len__(self) -> int: - return len(self._config._inicfg) - - -@final -class Config: - """Access to configuration values, pluginmanager and plugin hooks. - - :param PytestPluginManager pluginmanager: - A pytest PluginManager. - - :param InvocationParams invocation_params: - Object containing parameters regarding the :func:`pytest.main` - invocation. - """ - - @final - @dataclasses.dataclass(frozen=True) - class InvocationParams: - """Holds parameters passed during :func:`pytest.main`. - - The object attributes are read-only. - - .. versionadded:: 5.1 - - .. note:: - - Note that the environment variable ``PYTEST_ADDOPTS`` and the ``addopts`` - configuration option are handled by pytest, not being included in the ``args`` attribute. - - Plugins accessing ``InvocationParams`` must be aware of that. - """ - - args: tuple[str, ...] - """The command-line arguments as passed to :func:`pytest.main`.""" - plugins: Sequence[str | _PluggyPlugin] | None - """Extra plugins, might be `None`.""" - dir: pathlib.Path - """The directory from which :func:`pytest.main` was invoked.""" - - def __init__( - self, - *, - args: Iterable[str], - plugins: Sequence[str | _PluggyPlugin] | None, - dir: pathlib.Path, - ) -> None: - object.__setattr__(self, "args", tuple(args)) - object.__setattr__(self, "plugins", plugins) - object.__setattr__(self, "dir", dir) - - class ArgsSource(enum.Enum): - """Indicates the source of the test arguments. - - .. versionadded:: 7.2 - """ - - #: Command line arguments. - ARGS = enum.auto() - #: Invocation directory. - INVOCATION_DIR = enum.auto() - INCOVATION_DIR = INVOCATION_DIR # backwards compatibility alias - #: 'testpaths' configuration value. - TESTPATHS = enum.auto() - - # Set by cacheprovider plugin. - cache: Cache - - def __init__( - self, - pluginmanager: PytestPluginManager, - *, - invocation_params: InvocationParams | None = None, - ) -> None: - if invocation_params is None: - invocation_params = self.InvocationParams( - args=(), plugins=None, dir=pathlib.Path.cwd() - ) - - self.option = argparse.Namespace() - """Access to command line option as attributes. - - :type: argparse.Namespace - """ - - self.invocation_params = invocation_params - """The parameters with which pytest was invoked. - - :type: InvocationParams - """ - - self._parser = Parser( - usage=f"%(prog)s [options] [{FILE_OR_DIR}] [{FILE_OR_DIR}] [...]", - processopt=self._processopt, - _ispytest=True, - ) - self.pluginmanager = pluginmanager - """The plugin manager handles plugin registration and hook invocation. - - :type: PytestPluginManager - """ - - self.stash = Stash() - """A place where plugins can store information on the config for their - own use. - - :type: Stash - """ - # Deprecated alias. Was never public. Can be removed in a few releases. - self._store = self.stash - - self.trace = self.pluginmanager.trace.root.get("config") - self.hook: pluggy.HookRelay = PathAwareHookProxy(self.pluginmanager.hook) # type: ignore[assignment] - self._inicache: dict[str, Any] = {} - self._opt2dest: dict[str, str] = {} - self._cleanup_stack = contextlib.ExitStack() - self.pluginmanager.register(self, "pytestconfig") - self._configured = False - self.hook.pytest_addoption.call_historic( - kwargs=dict(parser=self._parser, pluginmanager=self.pluginmanager) - ) - self.args_source = Config.ArgsSource.ARGS - self.args: list[str] = [] - - @property - def inicfg(self) -> _DeprecatedInicfgProxy: - return _DeprecatedInicfgProxy(self) - - @property - def rootpath(self) -> pathlib.Path: - """The path to the :ref:`rootdir `. - - .. versionadded:: 6.1 - """ - return self._rootpath - - @property - def inipath(self) -> pathlib.Path | None: - """The path to the :ref:`configfile `. - - .. versionadded:: 6.1 - """ - return self._inipath - - def add_cleanup(self, func: Callable[[], None]) -> None: - """Add a function to be called when the config object gets out of - use (usually coinciding with pytest_unconfigure). - """ - self._cleanup_stack.callback(func) - - def _do_configure(self) -> None: - assert not self._configured - self._configured = True - self.hook.pytest_configure.call_historic(kwargs=dict(config=self)) - - def _ensure_unconfigure(self) -> None: - try: - if self._configured: - self._configured = False - try: - self.hook.pytest_unconfigure(config=self) - finally: - self.hook.pytest_configure._call_history = [] - finally: - try: - self._cleanup_stack.close() - finally: - self._cleanup_stack = contextlib.ExitStack() - - def get_terminal_writer(self) -> TerminalWriter: - terminalreporter: TerminalReporter | None = self.pluginmanager.get_plugin( - "terminalreporter" - ) - assert terminalreporter is not None - return terminalreporter._tw - - def pytest_cmdline_parse( - self, pluginmanager: PytestPluginManager, args: list[str] - ) -> Config: - try: - self.parse(args) - except UsageError: - # Handle `--version --version` and `--help` here in a minimal fashion. - # This gets done via helpconfig normally, but its - # pytest_cmdline_main is not called in case of errors. - if getattr(self.option, "version", False) or "--version" in args: - from _pytest.helpconfig import show_version_verbose - - # Note that `--version` (single argument) is handled early by `Config.main()`, so the only - # way we are reaching this point is via `--version --version`. - show_version_verbose(self) - elif ( - getattr(self.option, "help", False) or "--help" in args or "-h" in args - ): - self._parser.optparser.print_help() - sys.stdout.write( - "\nNOTE: displaying only minimal help due to UsageError.\n\n" - ) - - raise - - return self - - def notify_exception( - self, - excinfo: ExceptionInfo[BaseException], - option: argparse.Namespace | None = None, - ) -> None: - if option and getattr(option, "fulltrace", False): - style: TracebackStyle = "long" - else: - style = "native" - excrepr = excinfo.getrepr( - funcargs=True, showlocals=getattr(option, "showlocals", False), style=style - ) - res = self.hook.pytest_internalerror(excrepr=excrepr, excinfo=excinfo) - if not any(res): - for line in str(excrepr).split("\n"): - sys.stderr.write(f"INTERNALERROR> {line}\n") - sys.stderr.flush() - - def cwd_relative_nodeid(self, nodeid: str) -> str: - # nodeid's are relative to the rootpath, compute relative to cwd. - if self.invocation_params.dir != self.rootpath: - base_path_part, *nodeid_part = nodeid.split("::") - # Only process path part - fullpath = self.rootpath / base_path_part - relative_path = bestrelpath(self.invocation_params.dir, fullpath) - - nodeid = "::".join([relative_path, *nodeid_part]) - return nodeid - - @classmethod - def fromdictargs(cls, option_dict: Mapping[str, Any], args: list[str]) -> Config: - """Constructor usable for subprocesses.""" - config = get_config(args) - config.option.__dict__.update(option_dict) - config.parse(args, addopts=False) - for x in config.option.plugins: - config.pluginmanager.consider_pluginarg(x) - return config - - def _processopt(self, opt: Argument) -> None: - for name in opt._short_opts + opt._long_opts: - self._opt2dest[name] = opt.dest - - if hasattr(opt, "default"): - if not hasattr(self.option, opt.dest): - setattr(self.option, opt.dest, opt.default) - - @hookimpl(trylast=True) - def pytest_load_initial_conftests(self, early_config: Config) -> None: - # We haven't fully parsed the command line arguments yet, so - # early_config.args it not set yet. But we need it for - # discovering the initial conftests. So "pre-run" the logic here. - # It will be done for real in `parse()`. - args, _args_source = early_config._decide_args( - args=early_config.known_args_namespace.file_or_dir, - pyargs=early_config.known_args_namespace.pyargs, - testpaths=early_config.getini("testpaths"), - invocation_dir=early_config.invocation_params.dir, - rootpath=early_config.rootpath, - warn=False, - ) - self.pluginmanager._set_initial_conftests( - args=args, - pyargs=early_config.known_args_namespace.pyargs, - noconftest=early_config.known_args_namespace.noconftest, - rootpath=early_config.rootpath, - confcutdir=early_config.known_args_namespace.confcutdir, - invocation_dir=early_config.invocation_params.dir, - importmode=early_config.known_args_namespace.importmode, - consider_namespace_packages=early_config.getini( - "consider_namespace_packages" - ), - ) - - def _consider_importhook(self) -> None: - """Install the PEP 302 import hook if using assertion rewriting. - - Needs to parse the --assert= option from the commandline - and find all the installed plugins to mark them for rewriting - by the importhook. - """ - mode = getattr(self.known_args_namespace, "assertmode", "plain") - - disable_autoload = getattr( - self.known_args_namespace, "disable_plugin_autoload", False - ) or bool(os.environ.get("PYTEST_DISABLE_PLUGIN_AUTOLOAD")) - if mode == "rewrite": - import _pytest.assertion - - try: - hook = _pytest.assertion.install_importhook(self) - except SystemError: - mode = "plain" - else: - self._mark_plugins_for_rewrite(hook, disable_autoload) - self._warn_about_missing_assertion(mode) - - def _mark_plugins_for_rewrite( - self, hook: AssertionRewritingHook, disable_autoload: bool - ) -> None: - """Given an importhook, mark for rewrite any top-level - modules or packages in the distribution package for - all pytest plugins.""" - self.pluginmanager.rewrite_hook = hook - - if disable_autoload: - # We don't autoload from distribution package entry points, - # no need to continue. - return - - package_files = ( - str(file) - for dist in importlib.metadata.distributions() - if any(ep.group == "pytest11" for ep in dist.entry_points) - for file in dist.files or [] - ) - - for name in _iter_rewritable_modules(package_files): - hook.mark_rewrite(name) - - def _configure_python_path(self) -> None: - # `pythonpath = a b` will set `sys.path` to `[a, b, x, y, z, ...]` - for path in reversed(self.getini("pythonpath")): - sys.path.insert(0, str(path)) - self.add_cleanup(self._unconfigure_python_path) - - def _unconfigure_python_path(self) -> None: - for path in self.getini("pythonpath"): - path_str = str(path) - if path_str in sys.path: - sys.path.remove(path_str) - - def _validate_args(self, args: list[str], via: str) -> list[str]: - """Validate known args.""" - self._parser.extra_info["config source"] = via - try: - self._parser.parse_known_and_unknown_args( - args, namespace=copy.copy(self.option) - ) - finally: - self._parser.extra_info.pop("config source", None) - - return args - - def _decide_args( - self, - *, - args: list[str], - pyargs: bool, - testpaths: list[str], - invocation_dir: pathlib.Path, - rootpath: pathlib.Path, - warn: bool, - ) -> tuple[list[str], ArgsSource]: - """Decide the args (initial paths/nodeids) to use given the relevant inputs. - - :param warn: Whether can issue warnings. - - :returns: The args and the args source. Guaranteed to be non-empty. - """ - if args: - source = Config.ArgsSource.ARGS - result = args - else: - if invocation_dir == rootpath: - source = Config.ArgsSource.TESTPATHS - if pyargs: - result = testpaths - else: - result = [] - for path in testpaths: - result.extend(sorted(glob.iglob(path, recursive=True))) - if testpaths and not result: - if warn: - warning_text = ( - "No files were found in testpaths; " - "consider removing or adjusting your testpaths configuration. " - "Searching recursively from the current directory instead." - ) - self.issue_config_time_warning( - PytestConfigWarning(warning_text), stacklevel=3 - ) - else: - result = [] - if not result: - source = Config.ArgsSource.INVOCATION_DIR - result = [str(invocation_dir)] - return result, source - - @hookimpl(wrapper=True) - def pytest_collection(self) -> Generator[None, object, object]: - # Validate invalid configuration keys after collection is done so we - # take in account options added by late-loading conftest files. - try: - return (yield) - finally: - self._validate_config_options() - - def _checkversion(self) -> None: - import pytest - - minver_ini_value = self._inicfg.get("minversion", None) - minver = minver_ini_value.value if minver_ini_value is not None else None - if minver: - # Imported lazily to improve start-up time. - from packaging.version import Version - - if not isinstance(minver, str): - raise pytest.UsageError( - f"{self.inipath}: 'minversion' must be a single value" - ) - - if Version(minver) > Version(pytest.__version__): - raise pytest.UsageError( - f"{self.inipath}: 'minversion' requires pytest-{minver}, actual pytest-{pytest.__version__}'" - ) - - def _validate_config_options(self) -> None: - for key in sorted(self._get_unknown_ini_keys()): - self._warn_or_fail_if_strict(f"Unknown config option: {key}\n") - - def _validate_plugins(self) -> None: - required_plugins = sorted(self.getini("required_plugins")) - if not required_plugins: - return - - # Imported lazily to improve start-up time. - from packaging.requirements import InvalidRequirement - from packaging.requirements import Requirement - from packaging.version import Version - - plugin_info = self.pluginmanager.list_plugin_distinfo() - plugin_dist_info = {dist.project_name: dist.version for _, dist in plugin_info} - - missing_plugins = [] - for required_plugin in required_plugins: - try: - req = Requirement(required_plugin) - except InvalidRequirement: - missing_plugins.append(required_plugin) - continue - - if req.name not in plugin_dist_info: - missing_plugins.append(required_plugin) - elif not req.specifier.contains( - Version(plugin_dist_info[req.name]), prereleases=True - ): - missing_plugins.append(required_plugin) - - if missing_plugins: - raise UsageError( - "Missing required plugins: {}".format(", ".join(missing_plugins)), - ) - - def _warn_or_fail_if_strict(self, message: str) -> None: - strict_config = self.getini("strict_config") - if strict_config is None: - strict_config = self.getini("strict") - if strict_config: - raise UsageError(message) - - self.issue_config_time_warning(PytestConfigWarning(message), stacklevel=3) - - def _get_unknown_ini_keys(self) -> set[str]: - known_keys = self._parser._inidict.keys() | self._parser._ini_aliases.keys() - return self._inicfg.keys() - known_keys - - def parse(self, args: list[str], addopts: bool = True) -> None: - # Parse given cmdline arguments into this config object. - assert self.args == [], ( - "can only parse cmdline args at most once per Config object" - ) - - self.hook.pytest_addhooks.call_historic( - kwargs=dict(pluginmanager=self.pluginmanager) - ) - - if addopts: - env_addopts = os.environ.get("PYTEST_ADDOPTS", "") - if len(env_addopts): - args[:] = ( - self._validate_args(shlex.split(env_addopts), "via PYTEST_ADDOPTS") - + args - ) - - ns = self._parser.parse_known_args(args, namespace=copy.copy(self.option)) - rootpath, inipath, inicfg, ignored_config_files = determine_setup( - inifile=ns.inifilename, - override_ini=ns.override_ini, - args=ns.file_or_dir, - rootdir_cmd_arg=ns.rootdir or None, - invocation_dir=self.invocation_params.dir, - ) - self._rootpath = rootpath - self._inipath = inipath - self._ignored_config_files = ignored_config_files - self._inicfg = inicfg - self._parser.extra_info["rootdir"] = str(self.rootpath) - self._parser.extra_info["inifile"] = str(self.inipath) - - self._parser.addini("addopts", "Extra command line options", "args") - self._parser.addini("minversion", "Minimally required pytest version") - self._parser.addini( - "pythonpath", type="paths", help="Add paths to sys.path", default=[] - ) - self._parser.addini( - "required_plugins", - "Plugins that must be present for pytest to run", - type="args", - default=[], - ) - - if addopts: - args[:] = ( - self._validate_args(self.getini("addopts"), "via addopts config") + args - ) - - self.known_args_namespace = self._parser.parse_known_args( - args, namespace=copy.copy(self.option) - ) - self._checkversion() - self._consider_importhook() - self._configure_python_path() - self.pluginmanager.consider_preparse(args, exclude_only=False) - if ( - not os.environ.get("PYTEST_DISABLE_PLUGIN_AUTOLOAD") - and not self.known_args_namespace.disable_plugin_autoload - ): - # Autoloading from distribution package entry point has - # not been disabled. - self.pluginmanager.load_setuptools_entrypoints("pytest11") - # Otherwise only plugins explicitly specified in PYTEST_PLUGINS - # are going to be loaded. - self.pluginmanager.consider_env() - - self._parser.parse_known_args(args, namespace=self.known_args_namespace) - - self._validate_plugins() - self._warn_about_skipped_plugins() - - if self.known_args_namespace.confcutdir is None: - if self.inipath is not None: - confcutdir = str(self.inipath.parent) - else: - confcutdir = str(self.rootpath) - self.known_args_namespace.confcutdir = confcutdir - try: - self.hook.pytest_load_initial_conftests( - early_config=self, args=args, parser=self._parser - ) - except ConftestImportFailure as e: - if self.known_args_namespace.help or self.known_args_namespace.version: - # we don't want to prevent --help/--version to work - # so just let it pass and print a warning at the end - self.issue_config_time_warning( - PytestConfigWarning(f"could not load initial conftests: {e.path}"), - stacklevel=2, - ) - else: - raise - - try: - self._parser.parse(args, namespace=self.option) - except PrintHelp: - return - - self.args, self.args_source = self._decide_args( - args=getattr(self.option, FILE_OR_DIR), - pyargs=self.option.pyargs, - testpaths=self.getini("testpaths"), - invocation_dir=self.invocation_params.dir, - rootpath=self.rootpath, - warn=True, - ) - - def issue_config_time_warning(self, warning: Warning, stacklevel: int) -> None: - """Issue and handle a warning during the "configure" stage. - - During ``pytest_configure`` we can't capture warnings using the ``catch_warnings_for_item`` - function because it is not possible to have hook wrappers around ``pytest_configure``. - - This function is mainly intended for plugins that need to issue warnings during - ``pytest_configure`` (or similar stages). - - :param warning: The warning instance. - :param stacklevel: stacklevel forwarded to warnings.warn. - """ - if self.pluginmanager.is_blocked("warnings"): - return - - cmdline_filters = self.known_args_namespace.pythonwarnings or [] - config_filters = self.getini("filterwarnings") - - with warnings.catch_warnings(record=True) as records: - warnings.simplefilter("always", type(warning)) - apply_warning_filters(config_filters, cmdline_filters) - warnings.warn(warning, stacklevel=stacklevel) - - if records: - frame = sys._getframe(stacklevel - 1) - location = frame.f_code.co_filename, frame.f_lineno, frame.f_code.co_name - self.hook.pytest_warning_recorded.call_historic( - kwargs=dict( - warning_message=records[0], - when="config", - nodeid="", - location=location, - ) - ) - - def addinivalue_line(self, name: str, line: str) -> None: - """Add a line to a configuration option. The option must have been - declared but might not yet be set in which case the line becomes - the first line in its value.""" - x = self.getini(name) - assert isinstance(x, list) - x.append(line) # modifies the cached list inline - - def getini(self, name: str) -> Any: - """Return configuration value the an :ref:`configuration file `. - - If a configuration value is not defined in a - :ref:`configuration file `, then the ``default`` value - provided while registering the configuration through - :func:`parser.addini ` will be returned. - Please note that you can even provide ``None`` as a valid - default value. - - If ``default`` is not provided while registering using - :func:`parser.addini `, then a default value - based on the ``type`` parameter passed to - :func:`parser.addini ` will be returned. - The default values based on ``type`` are: - ``paths``, ``pathlist``, ``args`` and ``linelist`` : empty list ``[]`` - ``bool`` : ``False`` - ``string`` : empty string ``""`` - ``int`` : ``0`` - ``float`` : ``0.0`` - - If neither the ``default`` nor the ``type`` parameter is passed - while registering the configuration through - :func:`parser.addini `, then the configuration - is treated as a string and a default empty string '' is returned. - - If the specified name hasn't been registered through a prior - :func:`parser.addini ` call (usually from a - plugin), a ValueError is raised. - """ - canonical_name = self._parser._ini_aliases.get(name, name) - try: - return self._inicache[canonical_name] - except KeyError: - pass - self._inicache[canonical_name] = val = self._getini(canonical_name) - return val - - # Meant for easy monkeypatching by legacypath plugin. - # Can be inlined back (with no cover removed) once legacypath is gone. - def _getini_unknown_type(self, name: str, type: str, value: object): - msg = ( - f"Option {name} has unknown configuration type {type} with value {value!r}" - ) - raise ValueError(msg) # pragma: no cover - - def _getini(self, name: str): - # If this is an alias, resolve to canonical name. - canonical_name = self._parser._ini_aliases.get(name, name) - - try: - _description, type, default = self._parser._inidict[canonical_name] - except KeyError as e: - raise ValueError(f"unknown configuration value: {name!r}") from e - - # Collect all possible values (canonical name + aliases) from _inicfg. - # Each candidate is (ConfigValue, is_canonical). - candidates = [] - if canonical_name in self._inicfg: - candidates.append((self._inicfg[canonical_name], True)) - for alias, target in self._parser._ini_aliases.items(): - if target == canonical_name and alias in self._inicfg: - candidates.append((self._inicfg[alias], False)) - - if not candidates: - return default - - # Pick the best candidate based on precedence: - # 1. CLI override takes precedence over file, then - # 2. Canonical name takes precedence over alias. - selected = max(candidates, key=lambda x: (x[0].origin == "override", x[1]))[0] - value = selected.value - mode = selected.mode - - if mode == "ini": - # In ini mode, values are always str | list[str]. - assert isinstance(value, (str, list)) - return self._getini_ini(name, canonical_name, type, value, default) - elif mode == "toml": - return self._getini_toml(name, canonical_name, type, value, default) - else: - assert_never(mode) - - def _getini_ini( - self, - name: str, - canonical_name: str, - type: str, - value: str | list[str], - default: Any, - ): - """Handle config values read in INI mode. - - In INI mode, values are stored as str or list[str] only, and coerced - from string based on the registered type. - """ - # Note: some coercions are only required if we are reading from .ini - # files, because the file format doesn't contain type information, but - # when reading from toml (in ini mode) we will get either str or list of - # str values (see load_config_dict_from_file). For example: - # - # ini: - # a_line_list = "tests acceptance" - # - # in this case, we need to split the string to obtain a list of strings. - # - # toml (ini mode): - # a_line_list = ["tests", "acceptance"] - # - # in this case, we already have a list ready to use. - if type == "paths": - dp = ( - self.inipath.parent - if self.inipath is not None - else self.invocation_params.dir - ) - input_values = shlex.split(value) if isinstance(value, str) else value - return [dp / x for x in input_values] - elif type == "args": - return shlex.split(value) if isinstance(value, str) else value - elif type == "linelist": - if isinstance(value, str): - return [t for t in map(lambda x: x.strip(), value.split("\n")) if t] - else: - return value - elif type == "bool": - return _strtobool(str(value).strip()) - elif type == "string": - return value - elif type == "int": - if not isinstance(value, str): - raise TypeError( - f"Expected an int string for option {name} of type integer, but got: {value!r}" - ) from None - return int(value) - elif type == "float": - if not isinstance(value, str): - raise TypeError( - f"Expected a float string for option {name} of type float, but got: {value!r}" - ) from None - return float(value) - else: - return self._getini_unknown_type(name, type, value) - - def _getini_toml( - self, - name: str, - canonical_name: str, - type: str, - value: object, - default: Any, - ): - """Handle TOML config values with strict type validation and no coercion. - - In TOML mode, values already have native types from TOML parsing. - We validate types match expectations exactly, including list items. - """ - value_type = builtins.type(value).__name__ - if type == "paths": - # Expect a list of strings. - if not isinstance(value, list): - raise TypeError( - f"{self.inipath}: config option '{name}' expects a list for type 'paths', " - f"got {value_type}: {value!r}" - ) - for i, item in enumerate(value): - if not isinstance(item, str): - item_type = builtins.type(item).__name__ - raise TypeError( - f"{self.inipath}: config option '{name}' expects a list of strings, " - f"but item at index {i} is {item_type}: {item!r}" - ) - dp = ( - self.inipath.parent - if self.inipath is not None - else self.invocation_params.dir - ) - return [dp / x for x in value] - elif type in {"args", "linelist"}: - # Expect a list of strings. - if not isinstance(value, list): - raise TypeError( - f"{self.inipath}: config option '{name}' expects a list for type '{type}', " - f"got {value_type}: {value!r}" - ) - for i, item in enumerate(value): - if not isinstance(item, str): - item_type = builtins.type(item).__name__ - raise TypeError( - f"{self.inipath}: config option '{name}' expects a list of strings, " - f"but item at index {i} is {item_type}: {item!r}" - ) - return list(value) - elif type == "bool": - # Expect a boolean. - if not isinstance(value, bool): - raise TypeError( - f"{self.inipath}: config option '{name}' expects a bool, " - f"got {value_type}: {value!r}" - ) - return value - elif type == "int": - # Expect an integer (but not bool, which is a subclass of int). - if not isinstance(value, int) or isinstance(value, bool): - raise TypeError( - f"{self.inipath}: config option '{name}' expects an int, " - f"got {value_type}: {value!r}" - ) - return value - elif type == "float": - # Expect a float or integer only. - if not isinstance(value, (float, int)) or isinstance(value, bool): - raise TypeError( - f"{self.inipath}: config option '{name}' expects a float, " - f"got {value_type}: {value!r}" - ) - return value - elif type == "string": - # Expect a string. - if not isinstance(value, str): - raise TypeError( - f"{self.inipath}: config option '{name}' expects a string, " - f"got {value_type}: {value!r}" - ) - return value - else: - return self._getini_unknown_type(name, type, value) - - def _getconftest_pathlist( - self, name: str, path: pathlib.Path - ) -> list[pathlib.Path] | None: - try: - mod, relroots = self.pluginmanager._rget_with_confmod(name, path) - except KeyError: - return None - assert mod.__file__ is not None - modpath = pathlib.Path(mod.__file__).parent - values: list[pathlib.Path] = [] - for relroot in relroots: - if isinstance(relroot, os.PathLike): - relroot = pathlib.Path(relroot) - else: - relroot = relroot.replace("/", os.sep) - relroot = absolutepath(modpath / relroot) - values.append(relroot) - return values - - def getoption(self, name: str, default: Any = notset, skip: bool = False): - """Return command line option value. - - :param name: Name of the option. You may also specify - the literal ``--OPT`` option instead of the "dest" option name. - :param default: Fallback value if no option of that name is **declared** via :hook:`pytest_addoption`. - Note this parameter will be ignored when the option is **declared** even if the option's value is ``None``. - :param skip: If ``True``, raise :func:`pytest.skip` if option is undeclared or has a ``None`` value. - Note that even if ``True``, if a default was specified it will be returned instead of a skip. - """ - name = self._opt2dest.get(name, name) - try: - val = getattr(self.option, name) - if val is None and skip: - raise AttributeError(name) - return val - except AttributeError as e: - if default is not notset: - return default - if skip: - import pytest - - pytest.skip(f"no {name!r} option found") - raise ValueError(f"no option named {name!r}") from e - - def getvalue(self, name: str, path=None): - """Deprecated, use getoption() instead.""" - return self.getoption(name) - - def getvalueorskip(self, name: str, path=None): - """Deprecated, use getoption(skip=True) instead.""" - return self.getoption(name, skip=True) - - #: Verbosity type for failed assertions (see :confval:`verbosity_assertions`). - VERBOSITY_ASSERTIONS: Final = "assertions" - #: Verbosity type for test case execution (see :confval:`verbosity_test_cases`). - VERBOSITY_TEST_CASES: Final = "test_cases" - #: Verbosity type for failed subtests (see :confval:`verbosity_subtests`). - VERBOSITY_SUBTESTS: Final = "subtests" - - _VERBOSITY_INI_DEFAULT: Final = "auto" - - def get_verbosity(self, verbosity_type: str | None = None) -> int: - r"""Retrieve the verbosity level for a fine-grained verbosity type. - - :param verbosity_type: Verbosity type to get level for. If a level is - configured for the given type, that value will be returned. If the - given type is not a known verbosity type, the global verbosity - level will be returned. If the given type is None (default), the - global verbosity level will be returned. - - To configure a level for a fine-grained verbosity type, the - configuration file should have a setting for the configuration name - and a numeric value for the verbosity level. A special value of "auto" - can be used to explicitly use the global verbosity level. - - Example: - - .. tab:: toml - - .. code-block:: toml - - [tool.pytest] - verbosity_assertions = 2 - - .. tab:: ini - - .. code-block:: ini - - [pytest] - verbosity_assertions = 2 - - .. code-block:: console - - pytest -v - - .. code-block:: python - - print(config.get_verbosity()) # 1 - print(config.get_verbosity(Config.VERBOSITY_ASSERTIONS)) # 2 - """ - global_level = self.getoption("verbose", default=0) - assert isinstance(global_level, int) - if verbosity_type is None: - return global_level - - ini_name = Config._verbosity_ini_name(verbosity_type) - if ini_name not in self._parser._inidict: - return global_level - - level = self.getini(ini_name) - if level == Config._VERBOSITY_INI_DEFAULT: - return global_level - - return int(level) - - @staticmethod - def _verbosity_ini_name(verbosity_type: str) -> str: - return f"verbosity_{verbosity_type}" - - @staticmethod - def _add_verbosity_ini(parser: Parser, verbosity_type: str, help: str) -> None: - """Add a output verbosity configuration option for the given output type. - - :param parser: Parser for command line arguments and config-file values. - :param verbosity_type: Fine-grained verbosity category. - :param help: Description of the output this type controls. - - The value should be retrieved via a call to - :py:func:`config.get_verbosity(type) `. - """ - parser.addini( - Config._verbosity_ini_name(verbosity_type), - help=help, - type="string", - default=Config._VERBOSITY_INI_DEFAULT, - ) - - def _warn_about_missing_assertion(self, mode: str) -> None: - if not _assertion_supported(): - if mode == "plain": - warning_text = ( - "ASSERTIONS ARE NOT EXECUTED" - " and FAILING TESTS WILL PASS. Are you" - " using python -O?" - ) - else: - warning_text = ( - "assertions not in test modules or" - " plugins will be ignored" - " because assert statements are not executed " - "by the underlying Python interpreter " - "(are you using python -O?)\n" - ) - self.issue_config_time_warning( - PytestConfigWarning(warning_text), - stacklevel=3, - ) - - def _warn_about_skipped_plugins(self) -> None: - for module_name, msg in self.pluginmanager.skipped_plugins: - self.issue_config_time_warning( - PytestConfigWarning(f"skipped plugin {module_name!r}: {msg}"), - stacklevel=2, - ) - - -def _assertion_supported() -> bool: - try: - assert False - except AssertionError: - return True - else: - return False # type: ignore[unreachable] - - -def create_terminal_writer( - config: Config, file: TextIO | None = None -) -> TerminalWriter: - """Create a TerminalWriter instance configured according to the options - in the config object. - - Every code which requires a TerminalWriter object and has access to a - config object should use this function. - """ - tw = TerminalWriter(file=file) - - if config.option.color == "yes": - tw.hasmarkup = True - elif config.option.color == "no": - tw.hasmarkup = False - - if config.option.code_highlight == "yes": - tw.code_highlight = True - elif config.option.code_highlight == "no": - tw.code_highlight = False - - return tw - - -def _strtobool(val: str) -> bool: - """Convert a string representation of truth to True or False. - - True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values - are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if - 'val' is anything else. - - .. note:: Copied from distutils.util. - """ - val = val.lower() - if val in ("y", "yes", "t", "true", "on", "1"): - return True - elif val in ("n", "no", "f", "false", "off", "0"): - return False - else: - raise ValueError(f"invalid truth value {val!r}") - - -@lru_cache(maxsize=50) -def parse_warning_filter( - arg: str, *, escape: bool -) -> tuple[warnings._ActionKind, str, type[Warning], str, int]: - """Parse a warnings filter string. - - This is copied from warnings._setoption with the following changes: - - * Does not apply the filter. - * Escaping is optional. - * Raises UsageError so we get nice error messages on failure. - """ - __tracebackhide__ = True - error_template = dedent( - f"""\ - while parsing the following warning configuration: - - {arg} - - This error occurred: - - {{error}} - """ - ) - - parts = arg.split(":") - if len(parts) > 5: - doc_url = ( - "https://docs.python.org/3/library/warnings.html#describing-warning-filters" - ) - error = dedent( - f"""\ - Too many fields ({len(parts)}), expected at most 5 separated by colons: - - action:message:category:module:line - - For more information please consult: {doc_url} - """ - ) - raise UsageError(error_template.format(error=error)) - - while len(parts) < 5: - parts.append("") - action_, message, category_, module, lineno_ = (s.strip() for s in parts) - try: - action: warnings._ActionKind = warnings._getaction(action_) # type: ignore[attr-defined] - except warnings._OptionError as e: - raise UsageError(error_template.format(error=str(e))) from None - try: - category: type[Warning] = _resolve_warning_category(category_) - except ImportError: - raise - except Exception: - exc_info = ExceptionInfo.from_current() - exception_text = exc_info.getrepr(style="native") - raise UsageError(error_template.format(error=exception_text)) from None - if message and escape: - message = re.escape(message) - if module and escape: - module = re.escape(module) + r"\Z" - if lineno_: - try: - lineno = int(lineno_) - if lineno < 0: - raise ValueError("number is negative") - except ValueError as e: - raise UsageError( - error_template.format(error=f"invalid lineno {lineno_!r}: {e}") - ) from None - else: - lineno = 0 - try: - re.compile(message) - re.compile(module) - except re.error as e: - raise UsageError( - error_template.format(error=f"Invalid regex {e.pattern!r}: {e}") - ) from None - return action, message, category, module, lineno - - -def _resolve_warning_category(category: str) -> type[Warning]: - """ - Copied from warnings._getcategory, but changed so it lets exceptions (specially ImportErrors) - propagate so we can get access to their tracebacks (#9218). - """ - __tracebackhide__ = True - if not category: - return Warning - - if "." not in category: - import builtins as m - - klass = category - else: - module, _, klass = category.rpartition(".") - m = __import__(module, None, None, [klass]) - cat = getattr(m, klass) - if not issubclass(cat, Warning): - raise UsageError(f"{cat} is not a Warning subclass") - return cast(type[Warning], cat) - - -def apply_warning_filters( - config_filters: Iterable[str], cmdline_filters: Iterable[str] -) -> None: - """Applies pytest-configured filters to the warnings module""" - # Filters should have this precedence: cmdline options, config. - # Filters should be applied in the inverse order of precedence. - for arg in config_filters: - try: - warnings.filterwarnings(*parse_warning_filter(arg, escape=False)) - except ImportError as e: - warnings.warn( - f"Failed to import filter module '{e.name}': {arg}", PytestConfigWarning - ) - continue - - for arg in cmdline_filters: - try: - warnings.filterwarnings(*parse_warning_filter(arg, escape=True)) - except ImportError as e: - warnings.warn( - f"Failed to import filter module '{e.name}': {arg}", PytestConfigWarning - ) - continue diff --git a/.venv/lib/python3.12/site-packages/_pytest/config/argparsing.py b/.venv/lib/python3.12/site-packages/_pytest/config/argparsing.py deleted file mode 100644 index 8216ad8..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/config/argparsing.py +++ /dev/null @@ -1,578 +0,0 @@ -# mypy: allow-untyped-defs -from __future__ import annotations - -import argparse -from collections.abc import Callable -from collections.abc import Mapping -from collections.abc import Sequence -import os -import sys -from typing import Any -from typing import final -from typing import Literal -from typing import NoReturn - -from .exceptions import UsageError -import _pytest._io -from _pytest.deprecated import check_ispytest - - -FILE_OR_DIR = "file_or_dir" - - -class NotSet: - def __repr__(self) -> str: - return "" - - -NOT_SET = NotSet() - - -@final -class Parser: - """Parser for command line arguments and config-file values. - - :ivar extra_info: Dict of generic param -> value to display in case - there's an error processing the command line arguments. - """ - - def __init__( - self, - usage: str | None = None, - processopt: Callable[[Argument], None] | None = None, - *, - _ispytest: bool = False, - ) -> None: - check_ispytest(_ispytest) - - from _pytest._argcomplete import filescompleter - - self._processopt = processopt - self.extra_info: dict[str, Any] = {} - self.optparser = PytestArgumentParser(self, usage, self.extra_info) - anonymous_arggroup = self.optparser.add_argument_group("Custom options") - self._anonymous = OptionGroup( - anonymous_arggroup, "_anonymous", self, _ispytest=True - ) - self._groups = [self._anonymous] - file_or_dir_arg = self.optparser.add_argument(FILE_OR_DIR, nargs="*") - file_or_dir_arg.completer = filescompleter # type: ignore - - self._inidict: dict[str, tuple[str, str, Any]] = {} - # Maps alias -> canonical name. - self._ini_aliases: dict[str, str] = {} - - @property - def prog(self) -> str: - return self.optparser.prog - - @prog.setter - def prog(self, value: str) -> None: - self.optparser.prog = value - - def processoption(self, option: Argument) -> None: - if self._processopt: - if option.dest: - self._processopt(option) - - def getgroup( - self, name: str, description: str = "", after: str | None = None - ) -> OptionGroup: - """Get (or create) a named option Group. - - :param name: Name of the option group. - :param description: Long description for --help output. - :param after: Name of another group, used for ordering --help output. - :returns: The option group. - - The returned group object has an ``addoption`` method with the same - signature as :func:`parser.addoption ` but - will be shown in the respective group in the output of - ``pytest --help``. - """ - for group in self._groups: - if group.name == name: - return group - - arggroup = self.optparser.add_argument_group(description or name) - group = OptionGroup(arggroup, name, self, _ispytest=True) - i = 0 - for i, grp in enumerate(self._groups): - if grp.name == after: - break - self._groups.insert(i + 1, group) - # argparse doesn't provide a way to control `--help` order, so must - # access its internals ☹. - self.optparser._action_groups.insert(i + 1, self.optparser._action_groups.pop()) - return group - - def addoption(self, *opts: str, **attrs: Any) -> None: - """Register a command line option. - - :param opts: - Option names, can be short or long options. - :param attrs: - Same attributes as the argparse library's :meth:`add_argument() - ` function accepts. - - After command line parsing, options are available on the pytest config - object via ``config.option.NAME`` where ``NAME`` is usually set - by passing a ``dest`` attribute, for example - ``addoption("--long", dest="NAME", ...)``. - """ - self._anonymous.addoption(*opts, **attrs) - - def parse( - self, - args: Sequence[str | os.PathLike[str]], - namespace: argparse.Namespace | None = None, - ) -> argparse.Namespace: - """Parse the arguments. - - Unlike ``parse_known_args`` and ``parse_known_and_unknown_args``, - raises PrintHelp on `--help` and UsageError on unknown flags - - :meta private: - """ - from _pytest._argcomplete import try_argcomplete - - try_argcomplete(self.optparser) - strargs = [os.fspath(x) for x in args] - if namespace is None: - namespace = argparse.Namespace() - try: - namespace._raise_print_help = True - return self.optparser.parse_intermixed_args(strargs, namespace=namespace) - finally: - del namespace._raise_print_help - - def parse_known_args( - self, - args: Sequence[str | os.PathLike[str]], - namespace: argparse.Namespace | None = None, - ) -> argparse.Namespace: - """Parse the known arguments at this point. - - :returns: An argparse namespace object. - """ - return self.parse_known_and_unknown_args(args, namespace=namespace)[0] - - def parse_known_and_unknown_args( - self, - args: Sequence[str | os.PathLike[str]], - namespace: argparse.Namespace | None = None, - ) -> tuple[argparse.Namespace, list[str]]: - """Parse the known arguments at this point, and also return the - remaining unknown flag arguments. - - :returns: - A tuple containing an argparse namespace object for the known - arguments, and a list of unknown flag arguments. - """ - strargs = [os.fspath(x) for x in args] - if sys.version_info < (3, 12, 8) or (3, 13) <= sys.version_info < (3, 13, 1): - # Older argparse have a bugged parse_known_intermixed_args. - namespace, unknown = self.optparser.parse_known_args(strargs, namespace) - assert namespace is not None - file_or_dir = getattr(namespace, FILE_OR_DIR) - unknown_flags: list[str] = [] - for arg in unknown: - (unknown_flags if arg.startswith("-") else file_or_dir).append(arg) - return namespace, unknown_flags - else: - return self.optparser.parse_known_intermixed_args(strargs, namespace) - - def addini( - self, - name: str, - help: str, - type: Literal[ - "string", "paths", "pathlist", "args", "linelist", "bool", "int", "float" - ] - | None = None, - default: Any = NOT_SET, - *, - aliases: Sequence[str] = (), - ) -> None: - """Register a configuration file option. - - :param name: - Name of the configuration. - :param type: - Type of the configuration. Can be: - - * ``string``: a string - * ``bool``: a boolean - * ``args``: a list of strings, separated as in a shell - * ``linelist``: a list of strings, separated by line breaks - * ``paths``: a list of :class:`pathlib.Path`, separated as in a shell - * ``pathlist``: a list of ``py.path``, separated as in a shell - * ``int``: an integer - * ``float``: a floating-point number - - .. versionadded:: 8.4 - - The ``float`` and ``int`` types. - - For ``paths`` and ``pathlist`` types, they are considered relative to the config-file. - In case the execution is happening without a config-file defined, - they will be considered relative to the current working directory (for example with ``--override-ini``). - - .. versionadded:: 7.0 - The ``paths`` variable type. - - .. versionadded:: 8.1 - Use the current working directory to resolve ``paths`` and ``pathlist`` in the absence of a config-file. - - Defaults to ``string`` if ``None`` or not passed. - :param default: - Default value if no config-file option exists but is queried. - :param aliases: - Additional names by which this option can be referenced. - Aliases resolve to the canonical name. - - .. versionadded:: 9.0 - The ``aliases`` parameter. - - The value of configuration keys can be retrieved via a call to - :py:func:`config.getini(name) `. - """ - assert type in ( - None, - "string", - "paths", - "pathlist", - "args", - "linelist", - "bool", - "int", - "float", - ) - if type is None: - type = "string" - if default is NOT_SET: - default = get_ini_default_for_type(type) - - self._inidict[name] = (help, type, default) - - for alias in aliases: - if alias in self._inidict: - raise ValueError( - f"alias {alias!r} conflicts with existing configuration option" - ) - if (already := self._ini_aliases.get(alias)) is not None: - raise ValueError(f"{alias!r} is already an alias of {already!r}") - self._ini_aliases[alias] = name - - -def get_ini_default_for_type( - type: Literal[ - "string", "paths", "pathlist", "args", "linelist", "bool", "int", "float" - ], -) -> Any: - """ - Used by addini to get the default value for a given config option type, when - default is not supplied. - """ - if type in ("paths", "pathlist", "args", "linelist"): - return [] - elif type == "bool": - return False - elif type == "int": - return 0 - elif type == "float": - return 0.0 - else: - return "" - - -class ArgumentError(Exception): - """Raised if an Argument instance is created with invalid or - inconsistent arguments.""" - - def __init__(self, msg: str, option: Argument | str) -> None: - self.msg = msg - self.option_id = str(option) - - def __str__(self) -> str: - if self.option_id: - return f"option {self.option_id}: {self.msg}" - else: - return self.msg - - -class Argument: - """Class that mimics the necessary behaviour of optparse.Option. - - It's currently a least effort implementation and ignoring choices - and integer prefixes. - - https://docs.python.org/3/library/optparse.html#optparse-standard-option-types - """ - - def __init__(self, *names: str, **attrs: Any) -> None: - """Store params in private vars for use in add_argument.""" - self._attrs = attrs - self._short_opts: list[str] = [] - self._long_opts: list[str] = [] - try: - self.type = attrs["type"] - except KeyError: - pass - try: - # Attribute existence is tested in Config._processopt. - self.default = attrs["default"] - except KeyError: - pass - self._set_opt_strings(names) - dest: str | None = attrs.get("dest") - if dest: - self.dest = dest - elif self._long_opts: - self.dest = self._long_opts[0][2:].replace("-", "_") - else: - try: - self.dest = self._short_opts[0][1:] - except IndexError as e: - self.dest = "???" # Needed for the error repr. - raise ArgumentError("need a long or short option", self) from e - - def names(self) -> list[str]: - return self._short_opts + self._long_opts - - def attrs(self) -> Mapping[str, Any]: - # Update any attributes set by processopt. - for attr in ("default", "dest", "help", self.dest): - try: - self._attrs[attr] = getattr(self, attr) - except AttributeError: - pass - return self._attrs - - def _set_opt_strings(self, opts: Sequence[str]) -> None: - """Directly from optparse. - - Might not be necessary as this is passed to argparse later on. - """ - for opt in opts: - if len(opt) < 2: - raise ArgumentError( - f"invalid option string {opt!r}: " - "must be at least two characters long", - self, - ) - elif len(opt) == 2: - if not (opt[0] == "-" and opt[1] != "-"): - raise ArgumentError( - f"invalid short option string {opt!r}: " - "must be of the form -x, (x any non-dash char)", - self, - ) - self._short_opts.append(opt) - else: - if not (opt[0:2] == "--" and opt[2] != "-"): - raise ArgumentError( - f"invalid long option string {opt!r}: " - "must start with --, followed by non-dash", - self, - ) - self._long_opts.append(opt) - - def __repr__(self) -> str: - args: list[str] = [] - if self._short_opts: - args += ["_short_opts: " + repr(self._short_opts)] - if self._long_opts: - args += ["_long_opts: " + repr(self._long_opts)] - args += ["dest: " + repr(self.dest)] - if hasattr(self, "type"): - args += ["type: " + repr(self.type)] - if hasattr(self, "default"): - args += ["default: " + repr(self.default)] - return "Argument({})".format(", ".join(args)) - - -class OptionGroup: - """A group of options shown in its own section.""" - - def __init__( - self, - arggroup: argparse._ArgumentGroup, - name: str, - parser: Parser | None, - _ispytest: bool = False, - ) -> None: - check_ispytest(_ispytest) - self._arggroup = arggroup - self.name = name - self.options: list[Argument] = [] - self.parser = parser - - def addoption(self, *opts: str, **attrs: Any) -> None: - """Add an option to this group. - - If a shortened version of a long option is specified, it will - be suppressed in the help. ``addoption('--twowords', '--two-words')`` - results in help showing ``--two-words`` only, but ``--twowords`` gets - accepted **and** the automatic destination is in ``args.twowords``. - - :param opts: - Option names, can be short or long options. - :param attrs: - Same attributes as the argparse library's :meth:`add_argument() - ` function accepts. - """ - conflict = set(opts).intersection( - name for opt in self.options for name in opt.names() - ) - if conflict: - raise ValueError(f"option names {conflict} already added") - option = Argument(*opts, **attrs) - self._addoption_instance(option, shortupper=False) - - def _addoption(self, *opts: str, **attrs: Any) -> None: - option = Argument(*opts, **attrs) - self._addoption_instance(option, shortupper=True) - - def _addoption_instance(self, option: Argument, shortupper: bool = False) -> None: - if not shortupper: - for opt in option._short_opts: - if opt[0] == "-" and opt[1].islower(): - raise ValueError("lowercase shortoptions reserved") - - if self.parser: - self.parser.processoption(option) - - self._arggroup.add_argument(*option.names(), **option.attrs()) - self.options.append(option) - - -class PytestArgumentParser(argparse.ArgumentParser): - def __init__( - self, - parser: Parser, - usage: str | None, - extra_info: dict[str, str], - ) -> None: - self._parser = parser - super().__init__( - usage=usage, - add_help=False, - formatter_class=DropShorterLongHelpFormatter, - allow_abbrev=False, - fromfile_prefix_chars="@", - ) - # extra_info is a dict of (param -> value) to display if there's - # an usage error to provide more contextual information to the user. - self.extra_info = extra_info - - def error(self, message: str) -> NoReturn: - """Transform argparse error message into UsageError.""" - msg = f"{self.prog}: error: {message}" - if self.extra_info: - msg += "\n" + "\n".join( - f" {k}: {v}" for k, v in sorted(self.extra_info.items()) - ) - raise UsageError(self.format_usage() + msg) - - -class DropShorterLongHelpFormatter(argparse.HelpFormatter): - """Shorten help for long options that differ only in extra hyphens. - - - Collapse **long** options that are the same except for extra hyphens. - - Shortcut if there are only two options and one of them is a short one. - - Cache result on the action object as this is called at least 2 times. - """ - - def __init__(self, *args: Any, **kwargs: Any) -> None: - # Use more accurate terminal width. - if "width" not in kwargs: - kwargs["width"] = _pytest._io.get_terminal_width() - super().__init__(*args, **kwargs) - - def _format_action_invocation(self, action: argparse.Action) -> str: - orgstr = super()._format_action_invocation(action) - if orgstr and orgstr[0] != "-": # only optional arguments - return orgstr - res: str | None = getattr(action, "_formatted_action_invocation", None) - if res: - return res - options = orgstr.split(", ") - if len(options) == 2 and (len(options[0]) == 2 or len(options[1]) == 2): - # a shortcut for '-h, --help' or '--abc', '-a' - action._formatted_action_invocation = orgstr # type: ignore - return orgstr - return_list = [] - short_long: dict[str, str] = {} - for option in options: - if len(option) == 2 or option[2] == " ": - continue - if not option.startswith("--"): - raise ArgumentError( - f'long optional argument without "--": [{option}]', option - ) - xxoption = option[2:] - shortened = xxoption.replace("-", "") - if shortened not in short_long or len(short_long[shortened]) < len( - xxoption - ): - short_long[shortened] = xxoption - # now short_long has been filled out to the longest with dashes - # **and** we keep the right option ordering from add_argument - for option in options: - if len(option) == 2 or option[2] == " ": - return_list.append(option) - if option[2:] == short_long.get(option.replace("-", "")): - return_list.append(option.replace(" ", "=", 1)) - formatted_action_invocation = ", ".join(return_list) - action._formatted_action_invocation = formatted_action_invocation # type: ignore - return formatted_action_invocation - - def _split_lines(self, text, width): - """Wrap lines after splitting on original newlines. - - This allows to have explicit line breaks in the help text. - """ - import textwrap - - lines = [] - for line in text.splitlines(): - lines.extend(textwrap.wrap(line.strip(), width)) - return lines - - -class OverrideIniAction(argparse.Action): - """Custom argparse action that makes a CLI flag equivalent to overriding an - option, in addition to behaving like `store_true`. - - This can simplify things since code only needs to inspect the config option - and not consider the CLI flag. - """ - - def __init__( - self, - option_strings: Sequence[str], - dest: str, - nargs: int | str | None = None, - *args, - ini_option: str, - ini_value: str, - **kwargs, - ) -> None: - super().__init__(option_strings, dest, 0, *args, **kwargs) - self.ini_option = ini_option - self.ini_value = ini_value - - def __call__( - self, - parser: argparse.ArgumentParser, - namespace: argparse.Namespace, - *args, - **kwargs, - ) -> None: - setattr(namespace, self.dest, True) - current_overrides = getattr(namespace, "override_ini", None) - if current_overrides is None: - current_overrides = [] - current_overrides.append(f"{self.ini_option}={self.ini_value}") - setattr(namespace, "override_ini", current_overrides) diff --git a/.venv/lib/python3.12/site-packages/_pytest/config/compat.py b/.venv/lib/python3.12/site-packages/_pytest/config/compat.py deleted file mode 100644 index 21eab4c..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/config/compat.py +++ /dev/null @@ -1,85 +0,0 @@ -from __future__ import annotations - -from collections.abc import Mapping -import functools -from pathlib import Path -from typing import Any -import warnings - -import pluggy - -from ..compat import LEGACY_PATH -from ..compat import legacy_path -from ..deprecated import HOOK_LEGACY_PATH_ARG - - -# hookname: (Path, LEGACY_PATH) -imply_paths_hooks: Mapping[str, tuple[str, str]] = { - "pytest_ignore_collect": ("collection_path", "path"), - "pytest_collect_file": ("file_path", "path"), - "pytest_pycollect_makemodule": ("module_path", "path"), - "pytest_report_header": ("start_path", "startdir"), - "pytest_report_collectionfinish": ("start_path", "startdir"), -} - - -def _check_path(path: Path, fspath: LEGACY_PATH) -> None: - if Path(fspath) != path: - raise ValueError( - f"Path({fspath!r}) != {path!r}\n" - "if both path and fspath are given they need to be equal" - ) - - -class PathAwareHookProxy: - """ - this helper wraps around hook callers - until pluggy supports fixingcalls, this one will do - - it currently doesn't return full hook caller proxies for fixed hooks, - this may have to be changed later depending on bugs - """ - - def __init__(self, hook_relay: pluggy.HookRelay) -> None: - self._hook_relay = hook_relay - - def __dir__(self) -> list[str]: - return dir(self._hook_relay) - - def __getattr__(self, key: str) -> pluggy.HookCaller: - hook: pluggy.HookCaller = getattr(self._hook_relay, key) - if key not in imply_paths_hooks: - self.__dict__[key] = hook - return hook - else: - path_var, fspath_var = imply_paths_hooks[key] - - @functools.wraps(hook) - def fixed_hook(**kw: Any) -> Any: - path_value: Path | None = kw.pop(path_var, None) - fspath_value: LEGACY_PATH | None = kw.pop(fspath_var, None) - if fspath_value is not None: - warnings.warn( - HOOK_LEGACY_PATH_ARG.format( - pylib_path_arg=fspath_var, pathlib_path_arg=path_var - ), - stacklevel=2, - ) - if path_value is not None: - if fspath_value is not None: - _check_path(path_value, fspath_value) - else: - fspath_value = legacy_path(path_value) - else: - assert fspath_value is not None - path_value = Path(fspath_value) - - kw[path_var] = path_value - kw[fspath_var] = fspath_value - return hook(**kw) - - fixed_hook.name = hook.name # type: ignore[attr-defined] - fixed_hook.spec = hook.spec # type: ignore[attr-defined] - fixed_hook.__name__ = key - self.__dict__[key] = fixed_hook - return fixed_hook # type: ignore[return-value] diff --git a/.venv/lib/python3.12/site-packages/_pytest/config/exceptions.py b/.venv/lib/python3.12/site-packages/_pytest/config/exceptions.py deleted file mode 100644 index d84a9ea..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/config/exceptions.py +++ /dev/null @@ -1,15 +0,0 @@ -from __future__ import annotations - -from typing import final - - -@final -class UsageError(Exception): - """Error in pytest usage or invocation.""" - - __module__ = "pytest" - - -class PrintHelp(Exception): - """Raised when pytest should print its help to skip the rest of the - argument parsing and validation.""" diff --git a/.venv/lib/python3.12/site-packages/_pytest/config/findpaths.py b/.venv/lib/python3.12/site-packages/_pytest/config/findpaths.py deleted file mode 100644 index 3c628a0..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/config/findpaths.py +++ /dev/null @@ -1,350 +0,0 @@ -from __future__ import annotations - -from collections.abc import Iterable -from collections.abc import Sequence -from dataclasses import dataclass -from dataclasses import KW_ONLY -import os -from pathlib import Path -import sys -from typing import Literal -from typing import TypeAlias - -import iniconfig - -from .exceptions import UsageError -from _pytest.outcomes import fail -from _pytest.pathlib import absolutepath -from _pytest.pathlib import commonpath -from _pytest.pathlib import safe_exists - - -@dataclass(frozen=True) -class ConfigValue: - """Represents a configuration value with its origin and parsing mode. - - This allows tracking whether a value came from a configuration file - or from a CLI override (--override-ini), which is important for - determining precedence when dealing with ini option aliases. - - The mode tracks the parsing mode/data model used for the value: - - "ini": from INI files or [tool.pytest.ini_options], where the only - supported value types are `str` or `list[str]`. - - "toml": from TOML files (not in INI mode), where native TOML types - are preserved. - """ - - value: object - _: KW_ONLY - origin: Literal["file", "override"] - mode: Literal["ini", "toml"] - - -ConfigDict: TypeAlias = dict[str, ConfigValue] - - -def _parse_ini_config(path: Path) -> iniconfig.IniConfig: - """Parse the given generic '.ini' file using legacy IniConfig parser, returning - the parsed object. - - Raise UsageError if the file cannot be parsed. - """ - try: - return iniconfig.IniConfig(str(path)) - except iniconfig.ParseError as exc: - raise UsageError(str(exc)) from exc - - -def load_config_dict_from_file( - filepath: Path, -) -> ConfigDict | None: - """Load pytest configuration from the given file path, if supported. - - Return None if the file does not contain valid pytest configuration. - """ - # Configuration from ini files are obtained from the [pytest] section, if present. - if filepath.suffix == ".ini": - iniconfig = _parse_ini_config(filepath) - - if "pytest" in iniconfig: - return { - k: ConfigValue(v, origin="file", mode="ini") - for k, v in iniconfig["pytest"].items() - } - else: - # "pytest.ini" files are always the source of configuration, even if empty. - if filepath.name in {"pytest.ini", ".pytest.ini"}: - return {} - - # '.cfg' files are considered if they contain a "[tool:pytest]" section. - elif filepath.suffix == ".cfg": - iniconfig = _parse_ini_config(filepath) - - if "tool:pytest" in iniconfig.sections: - return { - k: ConfigValue(v, origin="file", mode="ini") - for k, v in iniconfig["tool:pytest"].items() - } - elif "pytest" in iniconfig.sections: - # If a setup.cfg contains a "[pytest]" section, we raise a failure to indicate users that - # plain "[pytest]" sections in setup.cfg files is no longer supported (#3086). - fail(CFG_PYTEST_SECTION.format(filename="setup.cfg"), pytrace=False) - - # '.toml' files are considered if they contain a [tool.pytest] table (toml mode) - # or [tool.pytest.ini_options] table (ini mode) for pyproject.toml, - # or [pytest] table (toml mode) for pytest.toml/.pytest.toml. - elif filepath.suffix == ".toml": - if sys.version_info >= (3, 11): - import tomllib - else: - import tomli as tomllib - - toml_text = filepath.read_text(encoding="utf-8") - try: - config = tomllib.loads(toml_text) - except tomllib.TOMLDecodeError as exc: - raise UsageError(f"{filepath}: {exc}") from exc - - # pytest.toml and .pytest.toml use [pytest] table directly. - if filepath.name in ("pytest.toml", ".pytest.toml"): - pytest_config = config.get("pytest", {}) - if pytest_config: - # TOML mode - preserve native TOML types. - return { - k: ConfigValue(v, origin="file", mode="toml") - for k, v in pytest_config.items() - } - # "pytest.toml" files are always the source of configuration, even if empty. - return {} - - # pyproject.toml uses [tool.pytest] or [tool.pytest.ini_options]. - else: - tool_pytest = config.get("tool", {}).get("pytest", {}) - - # Check for toml mode config: [tool.pytest] with content outside of ini_options. - toml_config = {k: v for k, v in tool_pytest.items() if k != "ini_options"} - # Check for ini mode config: [tool.pytest.ini_options]. - ini_config = tool_pytest.get("ini_options", None) - - if toml_config and ini_config: - raise UsageError( - f"{filepath}: Cannot use both [tool.pytest] (native TOML types) and " - "[tool.pytest.ini_options] (string-based INI format) simultaneously. " - "Please use [tool.pytest] with native TOML types (recommended) " - "or [tool.pytest.ini_options] for backwards compatibility." - ) - - if toml_config: - # TOML mode - preserve native TOML types. - return { - k: ConfigValue(v, origin="file", mode="toml") - for k, v in toml_config.items() - } - - elif ini_config is not None: - # INI mode - TOML supports richer data types than INI files, but we need to - # convert all scalar values to str for compatibility with the INI system. - def make_scalar(v: object) -> str | list[str]: - return v if isinstance(v, list) else str(v) - - return { - k: ConfigValue(make_scalar(v), origin="file", mode="ini") - for k, v in ini_config.items() - } - - return None - - -def locate_config( - invocation_dir: Path, - args: Iterable[Path], -) -> tuple[Path | None, Path | None, ConfigDict, Sequence[str]]: - """Search in the list of arguments for a valid ini-file for pytest, - and return a tuple of (rootdir, inifile, cfg-dict, ignored-config-files), where - ignored-config-files is a list of config basenames found that contain - pytest configuration but were ignored.""" - config_names = [ - "pytest.toml", - ".pytest.toml", - "pytest.ini", - ".pytest.ini", - "pyproject.toml", - "tox.ini", - "setup.cfg", - ] - args = [x for x in args if not str(x).startswith("-")] - if not args: - args = [invocation_dir] - found_pyproject_toml: Path | None = None - ignored_config_files: list[str] = [] - - for arg in args: - argpath = absolutepath(arg) - for base in (argpath, *argpath.parents): - for config_name in config_names: - p = base / config_name - if p.is_file(): - if p.name == "pyproject.toml" and found_pyproject_toml is None: - found_pyproject_toml = p - ini_config = load_config_dict_from_file(p) - if ini_config is not None: - index = config_names.index(config_name) - for remainder in config_names[index + 1 :]: - p2 = base / remainder - if ( - p2.is_file() - and load_config_dict_from_file(p2) is not None - ): - ignored_config_files.append(remainder) - return base, p, ini_config, ignored_config_files - if found_pyproject_toml is not None: - return found_pyproject_toml.parent, found_pyproject_toml, {}, [] - return None, None, {}, [] - - -def get_common_ancestor( - invocation_dir: Path, - paths: Iterable[Path], -) -> Path: - common_ancestor: Path | None = None - for path in paths: - if not path.exists(): - continue - if common_ancestor is None: - common_ancestor = path - else: - if common_ancestor in path.parents or path == common_ancestor: - continue - elif path in common_ancestor.parents: - common_ancestor = path - else: - shared = commonpath(path, common_ancestor) - if shared is not None: - common_ancestor = shared - if common_ancestor is None: - common_ancestor = invocation_dir - elif common_ancestor.is_file(): - common_ancestor = common_ancestor.parent - return common_ancestor - - -def get_dirs_from_args(args: Iterable[str]) -> list[Path]: - def is_option(x: str) -> bool: - return x.startswith("-") - - def get_file_part_from_node_id(x: str) -> str: - return x.split("::")[0] - - def get_dir_from_path(path: Path) -> Path: - if path.is_dir(): - return path - return path.parent - - # These look like paths but may not exist - possible_paths = ( - absolutepath(get_file_part_from_node_id(arg)) - for arg in args - if not is_option(arg) - ) - - return [get_dir_from_path(path) for path in possible_paths if safe_exists(path)] - - -def parse_override_ini(override_ini: Sequence[str] | None) -> ConfigDict: - """Parse the -o/--override-ini command line arguments and return the overrides. - - :raises UsageError: - If one of the values is malformed. - """ - overrides = {} - # override_ini is a list of "ini=value" options. - # Always use the last item if multiple values are set for same ini-name, - # e.g. -o foo=bar1 -o foo=bar2 will set foo to bar2. - for ini_config in override_ini or (): - try: - key, user_ini_value = ini_config.split("=", 1) - except ValueError as e: - raise UsageError( - f"-o/--override-ini expects option=value style (got: {ini_config!r})." - ) from e - else: - overrides[key] = ConfigValue(user_ini_value, origin="override", mode="ini") - return overrides - - -CFG_PYTEST_SECTION = "[pytest] section in {filename} files is no longer supported, change to [tool:pytest] instead." - - -def determine_setup( - *, - inifile: str | None, - override_ini: Sequence[str] | None, - args: Sequence[str], - rootdir_cmd_arg: str | None, - invocation_dir: Path, -) -> tuple[Path, Path | None, ConfigDict, Sequence[str]]: - """Determine the rootdir, inifile and ini configuration values from the - command line arguments. - - :param inifile: - The `--inifile` command line argument, if given. - :param override_ini: - The -o/--override-ini command line arguments, if given. - :param args: - The free command line arguments. - :param rootdir_cmd_arg: - The `--rootdir` command line argument, if given. - :param invocation_dir: - The working directory when pytest was invoked. - - :raises UsageError: - """ - rootdir = None - dirs = get_dirs_from_args(args) - ignored_config_files: Sequence[str] = [] - - if inifile: - inipath_ = absolutepath(inifile) - inipath: Path | None = inipath_ - inicfg = load_config_dict_from_file(inipath_) or {} - if rootdir_cmd_arg is None: - rootdir = inipath_.parent - else: - ancestor = get_common_ancestor(invocation_dir, dirs) - rootdir, inipath, inicfg, ignored_config_files = locate_config( - invocation_dir, [ancestor] - ) - if rootdir is None and rootdir_cmd_arg is None: - for possible_rootdir in (ancestor, *ancestor.parents): - if (possible_rootdir / "setup.py").is_file(): - rootdir = possible_rootdir - break - else: - if dirs != [ancestor]: - rootdir, inipath, inicfg, _ = locate_config(invocation_dir, dirs) - if rootdir is None: - rootdir = get_common_ancestor( - invocation_dir, [invocation_dir, ancestor] - ) - if is_fs_root(rootdir): - rootdir = ancestor - if rootdir_cmd_arg: - rootdir = absolutepath(os.path.expandvars(rootdir_cmd_arg)) - if not rootdir.is_dir(): - raise UsageError( - f"Directory '{rootdir}' not found. Check your '--rootdir' option." - ) - - ini_overrides = parse_override_ini(override_ini) - inicfg.update(ini_overrides) - - assert rootdir is not None - return rootdir, inipath, inicfg, ignored_config_files - - -def is_fs_root(p: Path) -> bool: - r""" - Return True if the given path is pointing to the root of the - file system ("/" on Unix and "C:\\" on Windows for example). - """ - return os.path.splitdrive(str(p))[1] == os.sep diff --git a/.venv/lib/python3.12/site-packages/_pytest/debugging.py b/.venv/lib/python3.12/site-packages/_pytest/debugging.py deleted file mode 100644 index de1b268..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/debugging.py +++ /dev/null @@ -1,407 +0,0 @@ -# mypy: allow-untyped-defs -# ruff: noqa: T100 -"""Interactive debugging with PDB, the Python Debugger.""" - -from __future__ import annotations - -import argparse -from collections.abc import Callable -from collections.abc import Generator -import functools -import sys -import types -from typing import Any -import unittest - -from _pytest import outcomes -from _pytest._code import ExceptionInfo -from _pytest.capture import CaptureManager -from _pytest.config import Config -from _pytest.config import ConftestImportFailure -from _pytest.config import hookimpl -from _pytest.config import PytestPluginManager -from _pytest.config.argparsing import Parser -from _pytest.config.exceptions import UsageError -from _pytest.nodes import Node -from _pytest.reports import BaseReport -from _pytest.runner import CallInfo - - -def _validate_usepdb_cls(value: str) -> tuple[str, str]: - """Validate syntax of --pdbcls option.""" - try: - modname, classname = value.split(":") - except ValueError as e: - raise argparse.ArgumentTypeError( - f"{value!r} is not in the format 'modname:classname'" - ) from e - return (modname, classname) - - -def pytest_addoption(parser: Parser) -> None: - group = parser.getgroup("general") - group.addoption( - "--pdb", - dest="usepdb", - action="store_true", - help="Start the interactive Python debugger on errors or KeyboardInterrupt", - ) - group.addoption( - "--pdbcls", - dest="usepdb_cls", - metavar="modulename:classname", - type=_validate_usepdb_cls, - help="Specify a custom interactive Python debugger for use with --pdb." - "For example: --pdbcls=IPython.terminal.debugger:TerminalPdb", - ) - group.addoption( - "--trace", - dest="trace", - action="store_true", - help="Immediately break when running each test", - ) - - -def pytest_configure(config: Config) -> None: - import pdb - - if config.getvalue("trace"): - config.pluginmanager.register(PdbTrace(), "pdbtrace") - if config.getvalue("usepdb"): - config.pluginmanager.register(PdbInvoke(), "pdbinvoke") - - pytestPDB._saved.append( - (pdb.set_trace, pytestPDB._pluginmanager, pytestPDB._config) - ) - pdb.set_trace = pytestPDB.set_trace - pytestPDB._pluginmanager = config.pluginmanager - pytestPDB._config = config - - # NOTE: not using pytest_unconfigure, since it might get called although - # pytest_configure was not (if another plugin raises UsageError). - def fin() -> None: - ( - pdb.set_trace, - pytestPDB._pluginmanager, - pytestPDB._config, - ) = pytestPDB._saved.pop() - - config.add_cleanup(fin) - - -class pytestPDB: - """Pseudo PDB that defers to the real pdb.""" - - _pluginmanager: PytestPluginManager | None = None - _config: Config | None = None - _saved: list[ - tuple[Callable[..., None], PytestPluginManager | None, Config | None] - ] = [] - _recursive_debug = 0 - _wrapped_pdb_cls: tuple[type[Any], type[Any]] | None = None - - @classmethod - def _is_capturing(cls, capman: CaptureManager | None) -> str | bool: - if capman: - return capman.is_capturing() - return False - - @classmethod - def _import_pdb_cls(cls, capman: CaptureManager | None): - if not cls._config: - import pdb - - # Happens when using pytest.set_trace outside of a test. - return pdb.Pdb - - usepdb_cls = cls._config.getvalue("usepdb_cls") - - if cls._wrapped_pdb_cls and cls._wrapped_pdb_cls[0] == usepdb_cls: - return cls._wrapped_pdb_cls[1] - - if usepdb_cls: - modname, classname = usepdb_cls - - try: - __import__(modname) - mod = sys.modules[modname] - - # Handle --pdbcls=pdb:pdb.Pdb (useful e.g. with pdbpp). - parts = classname.split(".") - pdb_cls = getattr(mod, parts[0]) - for part in parts[1:]: - pdb_cls = getattr(pdb_cls, part) - except Exception as exc: - value = ":".join((modname, classname)) - raise UsageError( - f"--pdbcls: could not import {value!r}: {exc}" - ) from exc - else: - import pdb - - pdb_cls = pdb.Pdb - - wrapped_cls = cls._get_pdb_wrapper_class(pdb_cls, capman) - cls._wrapped_pdb_cls = (usepdb_cls, wrapped_cls) - return wrapped_cls - - @classmethod - def _get_pdb_wrapper_class(cls, pdb_cls, capman: CaptureManager | None): - import _pytest.config - - class PytestPdbWrapper(pdb_cls): - _pytest_capman = capman - _continued = False - - def do_debug(self, arg): - cls._recursive_debug += 1 - ret = super().do_debug(arg) - cls._recursive_debug -= 1 - return ret - - if hasattr(pdb_cls, "do_debug"): - do_debug.__doc__ = pdb_cls.do_debug.__doc__ - - def do_continue(self, arg): - ret = super().do_continue(arg) - if cls._recursive_debug == 0: - assert cls._config is not None - tw = _pytest.config.create_terminal_writer(cls._config) - tw.line() - - capman = self._pytest_capman - capturing = pytestPDB._is_capturing(capman) - if capturing: - if capturing == "global": - tw.sep(">", "PDB continue (IO-capturing resumed)") - else: - tw.sep( - ">", - f"PDB continue (IO-capturing resumed for {capturing})", - ) - assert capman is not None - capman.resume() - else: - tw.sep(">", "PDB continue") - assert cls._pluginmanager is not None - cls._pluginmanager.hook.pytest_leave_pdb(config=cls._config, pdb=self) - self._continued = True - return ret - - if hasattr(pdb_cls, "do_continue"): - do_continue.__doc__ = pdb_cls.do_continue.__doc__ - - do_c = do_cont = do_continue - - def do_quit(self, arg): - # Raise Exit outcome when quit command is used in pdb. - # - # This is a bit of a hack - it would be better if BdbQuit - # could be handled, but this would require to wrap the - # whole pytest run, and adjust the report etc. - ret = super().do_quit(arg) - - if cls._recursive_debug == 0: - outcomes.exit("Quitting debugger") - - return ret - - if hasattr(pdb_cls, "do_quit"): - do_quit.__doc__ = pdb_cls.do_quit.__doc__ - - do_q = do_quit - do_exit = do_quit - - def setup(self, f, tb): - """Suspend on setup(). - - Needed after do_continue resumed, and entering another - breakpoint again. - """ - ret = super().setup(f, tb) - if not ret and self._continued: - # pdb.setup() returns True if the command wants to exit - # from the interaction: do not suspend capturing then. - if self._pytest_capman: - self._pytest_capman.suspend_global_capture(in_=True) - return ret - - def get_stack(self, f, t): - stack, i = super().get_stack(f, t) - if f is None: - # Find last non-hidden frame. - i = max(0, len(stack) - 1) - while i and stack[i][0].f_locals.get("__tracebackhide__", False): - i -= 1 - return stack, i - - return PytestPdbWrapper - - @classmethod - def _init_pdb(cls, method, *args, **kwargs): - """Initialize PDB debugging, dropping any IO capturing.""" - import _pytest.config - - if cls._pluginmanager is None: - capman: CaptureManager | None = None - else: - capman = cls._pluginmanager.getplugin("capturemanager") - if capman: - capman.suspend(in_=True) - - if cls._config: - tw = _pytest.config.create_terminal_writer(cls._config) - tw.line() - - if cls._recursive_debug == 0: - # Handle header similar to pdb.set_trace in py37+. - header = kwargs.pop("header", None) - if header is not None: - tw.sep(">", header) - else: - capturing = cls._is_capturing(capman) - if capturing == "global": - tw.sep(">", f"PDB {method} (IO-capturing turned off)") - elif capturing: - tw.sep( - ">", - f"PDB {method} (IO-capturing turned off for {capturing})", - ) - else: - tw.sep(">", f"PDB {method}") - - _pdb = cls._import_pdb_cls(capman)(**kwargs) - - if cls._pluginmanager: - cls._pluginmanager.hook.pytest_enter_pdb(config=cls._config, pdb=_pdb) - return _pdb - - @classmethod - def set_trace(cls, *args, **kwargs) -> None: - """Invoke debugging via ``Pdb.set_trace``, dropping any IO capturing.""" - frame = sys._getframe().f_back - _pdb = cls._init_pdb("set_trace", *args, **kwargs) - _pdb.set_trace(frame) - - -class PdbInvoke: - def pytest_exception_interact( - self, node: Node, call: CallInfo[Any], report: BaseReport - ) -> None: - capman = node.config.pluginmanager.getplugin("capturemanager") - if capman: - capman.suspend_global_capture(in_=True) - out, err = capman.read_global_capture() - sys.stdout.write(out) - sys.stdout.write(err) - assert call.excinfo is not None - - if not isinstance(call.excinfo.value, unittest.SkipTest): - _enter_pdb(node, call.excinfo, report) - - def pytest_internalerror(self, excinfo: ExceptionInfo[BaseException]) -> None: - exc_or_tb = _postmortem_exc_or_tb(excinfo) - post_mortem(exc_or_tb) - - -class PdbTrace: - @hookimpl(wrapper=True) - def pytest_pyfunc_call(self, pyfuncitem) -> Generator[None, object, object]: - wrap_pytest_function_for_tracing(pyfuncitem) - return (yield) - - -def wrap_pytest_function_for_tracing(pyfuncitem) -> None: - """Change the Python function object of the given Function item by a - wrapper which actually enters pdb before calling the python function - itself, effectively leaving the user in the pdb prompt in the first - statement of the function.""" - _pdb = pytestPDB._init_pdb("runcall") - testfunction = pyfuncitem.obj - - # we can't just return `partial(pdb.runcall, testfunction)` because (on - # python < 3.7.4) runcall's first param is `func`, which means we'd get - # an exception if one of the kwargs to testfunction was called `func`. - @functools.wraps(testfunction) - def wrapper(*args, **kwargs) -> None: - func = functools.partial(testfunction, *args, **kwargs) - _pdb.runcall(func) - - pyfuncitem.obj = wrapper - - -def maybe_wrap_pytest_function_for_tracing(pyfuncitem) -> None: - """Wrap the given pytestfunct item for tracing support if --trace was given in - the command line.""" - if pyfuncitem.config.getvalue("trace"): - wrap_pytest_function_for_tracing(pyfuncitem) - - -def _enter_pdb( - node: Node, excinfo: ExceptionInfo[BaseException], rep: BaseReport -) -> BaseReport: - # XXX we reuse the TerminalReporter's terminalwriter - # because this seems to avoid some encoding related troubles - # for not completely clear reasons. - tw = node.config.pluginmanager.getplugin("terminalreporter")._tw - tw.line() - - showcapture = node.config.option.showcapture - - for sectionname, content in ( - ("stdout", rep.capstdout), - ("stderr", rep.capstderr), - ("log", rep.caplog), - ): - if showcapture in (sectionname, "all") and content: - tw.sep(">", "captured " + sectionname) - if content[-1:] == "\n": - content = content[:-1] - tw.line(content) - - tw.sep(">", "traceback") - rep.toterminal(tw) - tw.sep(">", "entering PDB") - tb_or_exc = _postmortem_exc_or_tb(excinfo) - rep._pdbshown = True # type: ignore[attr-defined] - post_mortem(tb_or_exc) - return rep - - -def _postmortem_exc_or_tb( - excinfo: ExceptionInfo[BaseException], -) -> types.TracebackType | BaseException: - from doctest import UnexpectedException - - get_exc = sys.version_info >= (3, 13) - if isinstance(excinfo.value, UnexpectedException): - # A doctest.UnexpectedException is not useful for post_mortem. - # Use the underlying exception instead: - underlying_exc = excinfo.value - if get_exc: - return underlying_exc.exc_info[1] - - return underlying_exc.exc_info[2] - elif isinstance(excinfo.value, ConftestImportFailure): - # A config.ConftestImportFailure is not useful for post_mortem. - # Use the underlying exception instead: - cause = excinfo.value.cause - if get_exc: - return cause - - assert cause.__traceback__ is not None - return cause.__traceback__ - else: - assert excinfo._excinfo is not None - if get_exc: - return excinfo._excinfo[1] - - return excinfo._excinfo[2] - - -def post_mortem(tb_or_exc: types.TracebackType | BaseException) -> None: - p = pytestPDB._init_pdb("post_mortem") - p.reset() - p.interaction(None, tb_or_exc) - if p.quitting: - outcomes.exit("Quitting debugger") diff --git a/.venv/lib/python3.12/site-packages/_pytest/deprecated.py b/.venv/lib/python3.12/site-packages/_pytest/deprecated.py deleted file mode 100644 index cb5d2e9..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/deprecated.py +++ /dev/null @@ -1,99 +0,0 @@ -"""Deprecation messages and bits of code used elsewhere in the codebase that -is planned to be removed in the next pytest release. - -Keeping it in a central location makes it easy to track what is deprecated and should -be removed when the time comes. - -All constants defined in this module should be either instances of -:class:`PytestWarning`, or :class:`UnformattedWarning` -in case of warnings which need to format their messages. -""" - -from __future__ import annotations - -from warnings import warn - -from _pytest.warning_types import PytestDeprecationWarning -from _pytest.warning_types import PytestRemovedIn9Warning -from _pytest.warning_types import PytestRemovedIn10Warning -from _pytest.warning_types import UnformattedWarning - - -# set of plugins which have been integrated into the core; we use this list to ignore -# them during registration to avoid conflicts -DEPRECATED_EXTERNAL_PLUGINS = { - "pytest_catchlog", - "pytest_capturelog", - "pytest_faulthandler", - "pytest_subtests", -} - - -# This could have been removed pytest 8, but it's harmless and common, so no rush to remove. -YIELD_FIXTURE = PytestDeprecationWarning( - "@pytest.yield_fixture is deprecated.\n" - "Use @pytest.fixture instead; they are the same." -) - -# This deprecation is never really meant to be removed. -PRIVATE = PytestDeprecationWarning("A private pytest class or function was used.") - - -HOOK_LEGACY_PATH_ARG = UnformattedWarning( - PytestRemovedIn9Warning, - "The ({pylib_path_arg}: py.path.local) argument is deprecated, please use ({pathlib_path_arg}: pathlib.Path)\n" - "see https://docs.pytest.org/en/latest/deprecations.html" - "#py-path-local-arguments-for-hooks-replaced-with-pathlib-path", -) - -NODE_CTOR_FSPATH_ARG = UnformattedWarning( - PytestRemovedIn9Warning, - "The (fspath: py.path.local) argument to {node_type_name} is deprecated. " - "Please use the (path: pathlib.Path) argument instead.\n" - "See https://docs.pytest.org/en/latest/deprecations.html" - "#fspath-argument-for-node-constructors-replaced-with-pathlib-path", -) - -HOOK_LEGACY_MARKING = UnformattedWarning( - PytestDeprecationWarning, - "The hook{type} {fullname} uses old-style configuration options (marks or attributes).\n" - "Please use the pytest.hook{type}({hook_opts}) decorator instead\n" - " to configure the hooks.\n" - " See https://docs.pytest.org/en/latest/deprecations.html" - "#configuring-hook-specs-impls-using-markers", -) - -MARKED_FIXTURE = PytestRemovedIn9Warning( - "Marks applied to fixtures have no effect\n" - "See docs: https://docs.pytest.org/en/stable/deprecations.html#applying-a-mark-to-a-fixture-function" -) - -MONKEYPATCH_LEGACY_NAMESPACE_PACKAGES = PytestRemovedIn10Warning( - "monkeypatch.syspath_prepend() called with pkg_resources legacy namespace packages detected.\n" - "Legacy namespace packages (using pkg_resources.declare_namespace) are deprecated.\n" - "Please use native namespace packages (PEP 420) instead.\n" - "See https://docs.pytest.org/en/stable/deprecations.html#monkeypatch-fixup-namespace-packages" -) - -# You want to make some `__init__` or function "private". -# -# def my_private_function(some, args): -# ... -# -# Do this: -# -# def my_private_function(some, args, *, _ispytest: bool = False): -# check_ispytest(_ispytest) -# ... -# -# Change all internal/allowed calls to -# -# my_private_function(some, args, _ispytest=True) -# -# All other calls will get the default _ispytest=False and trigger -# the warning (possibly error in the future). - - -def check_ispytest(ispytest: bool) -> None: - if not ispytest: - warn(PRIVATE, stacklevel=3) diff --git a/.venv/lib/python3.12/site-packages/_pytest/doctest.py b/.venv/lib/python3.12/site-packages/_pytest/doctest.py deleted file mode 100644 index cd255f5..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/doctest.py +++ /dev/null @@ -1,736 +0,0 @@ -# mypy: allow-untyped-defs -"""Discover and run doctests in modules and test files.""" - -from __future__ import annotations - -import bdb -from collections.abc import Callable -from collections.abc import Generator -from collections.abc import Iterable -from collections.abc import Sequence -from contextlib import contextmanager -import functools -import inspect -import os -from pathlib import Path -import platform -import re -import sys -import traceback -import types -from typing import Any -from typing import TYPE_CHECKING -import warnings - -from _pytest import outcomes -from _pytest._code.code import ExceptionInfo -from _pytest._code.code import ReprFileLocation -from _pytest._code.code import TerminalRepr -from _pytest._io import TerminalWriter -from _pytest.compat import safe_getattr -from _pytest.config import Config -from _pytest.config.argparsing import Parser -from _pytest.fixtures import fixture -from _pytest.fixtures import TopRequest -from _pytest.nodes import Collector -from _pytest.nodes import Item -from _pytest.outcomes import OutcomeException -from _pytest.outcomes import skip -from _pytest.pathlib import fnmatch_ex -from _pytest.python import Module -from _pytest.python_api import approx -from _pytest.warning_types import PytestWarning - - -if TYPE_CHECKING: - import doctest - - from typing_extensions import Self - -DOCTEST_REPORT_CHOICE_NONE = "none" -DOCTEST_REPORT_CHOICE_CDIFF = "cdiff" -DOCTEST_REPORT_CHOICE_NDIFF = "ndiff" -DOCTEST_REPORT_CHOICE_UDIFF = "udiff" -DOCTEST_REPORT_CHOICE_ONLY_FIRST_FAILURE = "only_first_failure" - -DOCTEST_REPORT_CHOICES = ( - DOCTEST_REPORT_CHOICE_NONE, - DOCTEST_REPORT_CHOICE_CDIFF, - DOCTEST_REPORT_CHOICE_NDIFF, - DOCTEST_REPORT_CHOICE_UDIFF, - DOCTEST_REPORT_CHOICE_ONLY_FIRST_FAILURE, -) - -# Lazy definition of runner class -RUNNER_CLASS = None -# Lazy definition of output checker class -CHECKER_CLASS: type[doctest.OutputChecker] | None = None - - -def pytest_addoption(parser: Parser) -> None: - parser.addini( - "doctest_optionflags", - "Option flags for doctests", - type="args", - default=["ELLIPSIS"], - ) - parser.addini( - "doctest_encoding", "Encoding used for doctest files", default="utf-8" - ) - group = parser.getgroup("collect") - group.addoption( - "--doctest-modules", - action="store_true", - default=False, - help="Run doctests in all .py modules", - dest="doctestmodules", - ) - group.addoption( - "--doctest-report", - type=str.lower, - default="udiff", - help="Choose another output format for diffs on doctest failure", - choices=DOCTEST_REPORT_CHOICES, - dest="doctestreport", - ) - group.addoption( - "--doctest-glob", - action="append", - default=[], - metavar="pat", - help="Doctests file matching pattern, default: test*.txt", - dest="doctestglob", - ) - group.addoption( - "--doctest-ignore-import-errors", - action="store_true", - default=False, - help="Ignore doctest collection errors", - dest="doctest_ignore_import_errors", - ) - group.addoption( - "--doctest-continue-on-failure", - action="store_true", - default=False, - help="For a given doctest, continue to run after the first failure", - dest="doctest_continue_on_failure", - ) - - -def pytest_unconfigure() -> None: - global RUNNER_CLASS - - RUNNER_CLASS = None - - -def pytest_collect_file( - file_path: Path, - parent: Collector, -) -> DoctestModule | DoctestTextfile | None: - config = parent.config - if file_path.suffix == ".py": - if config.option.doctestmodules and not any( - (_is_setup_py(file_path), _is_main_py(file_path)) - ): - return DoctestModule.from_parent(parent, path=file_path) - elif _is_doctest(config, file_path, parent): - return DoctestTextfile.from_parent(parent, path=file_path) - return None - - -def _is_setup_py(path: Path) -> bool: - if path.name != "setup.py": - return False - contents = path.read_bytes() - return b"setuptools" in contents or b"distutils" in contents - - -def _is_doctest(config: Config, path: Path, parent: Collector) -> bool: - if path.suffix in (".txt", ".rst") and parent.session.isinitpath(path): - return True - globs = config.getoption("doctestglob") or ["test*.txt"] - return any(fnmatch_ex(glob, path) for glob in globs) - - -def _is_main_py(path: Path) -> bool: - return path.name == "__main__.py" - - -class ReprFailDoctest(TerminalRepr): - def __init__( - self, reprlocation_lines: Sequence[tuple[ReprFileLocation, Sequence[str]]] - ) -> None: - self.reprlocation_lines = reprlocation_lines - - def toterminal(self, tw: TerminalWriter) -> None: - for reprlocation, lines in self.reprlocation_lines: - for line in lines: - tw.line(line) - reprlocation.toterminal(tw) - - -class MultipleDoctestFailures(Exception): - def __init__(self, failures: Sequence[doctest.DocTestFailure]) -> None: - super().__init__() - self.failures = failures - - -def _init_runner_class() -> type[doctest.DocTestRunner]: - import doctest - - class PytestDoctestRunner(doctest.DebugRunner): - """Runner to collect failures. - - Note that the out variable in this case is a list instead of a - stdout-like object. - """ - - def __init__( - self, - checker: doctest.OutputChecker | None = None, - verbose: bool | None = None, - optionflags: int = 0, - continue_on_failure: bool = True, - ) -> None: - super().__init__(checker=checker, verbose=verbose, optionflags=optionflags) - self.continue_on_failure = continue_on_failure - - def report_failure( - self, - out, - test: doctest.DocTest, - example: doctest.Example, - got: str, - ) -> None: - failure = doctest.DocTestFailure(test, example, got) - if self.continue_on_failure: - out.append(failure) - else: - raise failure - - def report_unexpected_exception( - self, - out, - test: doctest.DocTest, - example: doctest.Example, - exc_info: tuple[type[BaseException], BaseException, types.TracebackType], - ) -> None: - if isinstance(exc_info[1], OutcomeException): - raise exc_info[1] - if isinstance(exc_info[1], bdb.BdbQuit): - outcomes.exit("Quitting debugger") - failure = doctest.UnexpectedException(test, example, exc_info) - if self.continue_on_failure: - out.append(failure) - else: - raise failure - - return PytestDoctestRunner - - -def _get_runner( - checker: doctest.OutputChecker | None = None, - verbose: bool | None = None, - optionflags: int = 0, - continue_on_failure: bool = True, -) -> doctest.DocTestRunner: - # We need this in order to do a lazy import on doctest - global RUNNER_CLASS - if RUNNER_CLASS is None: - RUNNER_CLASS = _init_runner_class() - # Type ignored because the continue_on_failure argument is only defined on - # PytestDoctestRunner, which is lazily defined so can't be used as a type. - return RUNNER_CLASS( # type: ignore - checker=checker, - verbose=verbose, - optionflags=optionflags, - continue_on_failure=continue_on_failure, - ) - - -class DoctestItem(Item): - def __init__( - self, - name: str, - parent: DoctestTextfile | DoctestModule, - runner: doctest.DocTestRunner, - dtest: doctest.DocTest, - ) -> None: - super().__init__(name, parent) - self.runner = runner - self.dtest = dtest - - # Stuff needed for fixture support. - self.obj = None - fm = self.session._fixturemanager - fixtureinfo = fm.getfixtureinfo(node=self, func=None, cls=None) - self._fixtureinfo = fixtureinfo - self.fixturenames = fixtureinfo.names_closure - self._initrequest() - - @classmethod - def from_parent( # type: ignore[override] - cls, - parent: DoctestTextfile | DoctestModule, - *, - name: str, - runner: doctest.DocTestRunner, - dtest: doctest.DocTest, - ) -> Self: - # incompatible signature due to imposed limits on subclass - """The public named constructor.""" - return super().from_parent(name=name, parent=parent, runner=runner, dtest=dtest) - - def _initrequest(self) -> None: - self.funcargs: dict[str, object] = {} - self._request = TopRequest(self, _ispytest=True) # type: ignore[arg-type] - - def setup(self) -> None: - self._request._fillfixtures() - globs = dict(getfixture=self._request.getfixturevalue) - for name, value in self._request.getfixturevalue("doctest_namespace").items(): - globs[name] = value - self.dtest.globs.update(globs) - - def runtest(self) -> None: - _check_all_skipped(self.dtest) - self._disable_output_capturing_for_darwin() - failures: list[doctest.DocTestFailure] = [] - # Type ignored because we change the type of `out` from what - # doctest expects. - self.runner.run(self.dtest, out=failures) # type: ignore[arg-type] - if failures: - raise MultipleDoctestFailures(failures) - - def _disable_output_capturing_for_darwin(self) -> None: - """Disable output capturing. Otherwise, stdout is lost to doctest (#985).""" - if platform.system() != "Darwin": - return - capman = self.config.pluginmanager.getplugin("capturemanager") - if capman: - capman.suspend_global_capture(in_=True) - out, err = capman.read_global_capture() - sys.stdout.write(out) - sys.stderr.write(err) - - # TODO: Type ignored -- breaks Liskov Substitution. - def repr_failure( # type: ignore[override] - self, - excinfo: ExceptionInfo[BaseException], - ) -> str | TerminalRepr: - import doctest - - failures: ( - Sequence[doctest.DocTestFailure | doctest.UnexpectedException] | None - ) = None - if isinstance( - excinfo.value, doctest.DocTestFailure | doctest.UnexpectedException - ): - failures = [excinfo.value] - elif isinstance(excinfo.value, MultipleDoctestFailures): - failures = excinfo.value.failures - - if failures is None: - return super().repr_failure(excinfo) - - reprlocation_lines = [] - for failure in failures: - example = failure.example - test = failure.test - filename = test.filename - if test.lineno is None: - lineno = None - else: - lineno = test.lineno + example.lineno + 1 - message = type(failure).__name__ - # TODO: ReprFileLocation doesn't expect a None lineno. - reprlocation = ReprFileLocation(filename, lineno, message) # type: ignore[arg-type] - checker = _get_checker() - report_choice = _get_report_choice(self.config.getoption("doctestreport")) - if lineno is not None: - assert failure.test.docstring is not None - lines = failure.test.docstring.splitlines(False) - # add line numbers to the left of the error message - assert test.lineno is not None - lines = [ - f"{i + test.lineno + 1:03d} {x}" for (i, x) in enumerate(lines) - ] - # trim docstring error lines to 10 - lines = lines[max(example.lineno - 9, 0) : example.lineno + 1] - else: - lines = [ - "EXAMPLE LOCATION UNKNOWN, not showing all tests of that example" - ] - indent = ">>>" - for line in example.source.splitlines(): - lines.append(f"??? {indent} {line}") - indent = "..." - if isinstance(failure, doctest.DocTestFailure): - lines += checker.output_difference( - example, failure.got, report_choice - ).split("\n") - else: - inner_excinfo = ExceptionInfo.from_exc_info(failure.exc_info) - lines += [f"UNEXPECTED EXCEPTION: {inner_excinfo.value!r}"] - lines += [ - x.strip("\n") for x in traceback.format_exception(*failure.exc_info) - ] - reprlocation_lines.append((reprlocation, lines)) - return ReprFailDoctest(reprlocation_lines) - - def reportinfo(self) -> tuple[os.PathLike[str] | str, int | None, str]: - return self.path, self.dtest.lineno, f"[doctest] {self.name}" - - -def _get_flag_lookup() -> dict[str, int]: - import doctest - - return dict( - DONT_ACCEPT_TRUE_FOR_1=doctest.DONT_ACCEPT_TRUE_FOR_1, - DONT_ACCEPT_BLANKLINE=doctest.DONT_ACCEPT_BLANKLINE, - NORMALIZE_WHITESPACE=doctest.NORMALIZE_WHITESPACE, - ELLIPSIS=doctest.ELLIPSIS, - IGNORE_EXCEPTION_DETAIL=doctest.IGNORE_EXCEPTION_DETAIL, - COMPARISON_FLAGS=doctest.COMPARISON_FLAGS, - ALLOW_UNICODE=_get_allow_unicode_flag(), - ALLOW_BYTES=_get_allow_bytes_flag(), - NUMBER=_get_number_flag(), - ) - - -def get_optionflags(config: Config) -> int: - optionflags_str = config.getini("doctest_optionflags") - flag_lookup_table = _get_flag_lookup() - flag_acc = 0 - for flag in optionflags_str: - flag_acc |= flag_lookup_table[flag] - return flag_acc - - -def _get_continue_on_failure(config: Config) -> bool: - continue_on_failure: bool = config.getvalue("doctest_continue_on_failure") - if continue_on_failure: - # We need to turn off this if we use pdb since we should stop at - # the first failure. - if config.getvalue("usepdb"): - continue_on_failure = False - return continue_on_failure - - -class DoctestTextfile(Module): - obj = None - - def collect(self) -> Iterable[DoctestItem]: - import doctest - - # Inspired by doctest.testfile; ideally we would use it directly, - # but it doesn't support passing a custom checker. - encoding = self.config.getini("doctest_encoding") - text = self.path.read_text(encoding) - filename = str(self.path) - name = self.path.name - globs = {"__name__": "__main__"} - - optionflags = get_optionflags(self.config) - - runner = _get_runner( - verbose=False, - optionflags=optionflags, - checker=_get_checker(), - continue_on_failure=_get_continue_on_failure(self.config), - ) - - parser = doctest.DocTestParser() - test = parser.get_doctest(text, globs, name, filename, 0) - if test.examples: - yield DoctestItem.from_parent( - self, name=test.name, runner=runner, dtest=test - ) - - -def _check_all_skipped(test: doctest.DocTest) -> None: - """Raise pytest.skip() if all examples in the given DocTest have the SKIP - option set.""" - import doctest - - all_skipped = all(x.options.get(doctest.SKIP, False) for x in test.examples) - if all_skipped: - skip("all tests skipped by +SKIP option") - - -def _is_mocked(obj: object) -> bool: - """Return if an object is possibly a mock object by checking the - existence of a highly improbable attribute.""" - return ( - safe_getattr(obj, "pytest_mock_example_attribute_that_shouldnt_exist", None) - is not None - ) - - -@contextmanager -def _patch_unwrap_mock_aware() -> Generator[None]: - """Context manager which replaces ``inspect.unwrap`` with a version - that's aware of mock objects and doesn't recurse into them.""" - real_unwrap = inspect.unwrap - - def _mock_aware_unwrap( - func: Callable[..., Any], *, stop: Callable[[Any], Any] | None = None - ) -> Any: - try: - if stop is None or stop is _is_mocked: - return real_unwrap(func, stop=_is_mocked) - _stop = stop - return real_unwrap(func, stop=lambda obj: _is_mocked(obj) or _stop(func)) - except Exception as e: - warnings.warn( - f"Got {e!r} when unwrapping {func!r}. This is usually caused " - "by a violation of Python's object protocol; see e.g. " - "https://github.com/pytest-dev/pytest/issues/5080", - PytestWarning, - ) - raise - - inspect.unwrap = _mock_aware_unwrap - try: - yield - finally: - inspect.unwrap = real_unwrap - - -class DoctestModule(Module): - def collect(self) -> Iterable[DoctestItem]: - import doctest - - class MockAwareDocTestFinder(doctest.DocTestFinder): - py_ver_info_minor = sys.version_info[:2] - is_find_lineno_broken = ( - py_ver_info_minor < (3, 11) - or (py_ver_info_minor == (3, 11) and sys.version_info.micro < 9) - or (py_ver_info_minor == (3, 12) and sys.version_info.micro < 3) - ) - if is_find_lineno_broken: - - def _find_lineno(self, obj, source_lines): - """On older Pythons, doctest code does not take into account - `@property`. https://github.com/python/cpython/issues/61648 - - Moreover, wrapped Doctests need to be unwrapped so the correct - line number is returned. #8796 - """ - if isinstance(obj, property): - obj = getattr(obj, "fget", obj) - - if hasattr(obj, "__wrapped__"): - # Get the main obj in case of it being wrapped - obj = inspect.unwrap(obj) - - # Type ignored because this is a private function. - return super()._find_lineno( # type:ignore[misc] - obj, - source_lines, - ) - - if sys.version_info < (3, 13): - - def _from_module(self, module, object): - """`cached_property` objects are never considered a part - of the 'current module'. As such they are skipped by doctest. - Here we override `_from_module` to check the underlying - function instead. https://github.com/python/cpython/issues/107995 - """ - if isinstance(object, functools.cached_property): - object = object.func - - # Type ignored because this is a private function. - return super()._from_module(module, object) # type: ignore[misc] - - try: - module = self.obj - except Collector.CollectError: - if self.config.getvalue("doctest_ignore_import_errors"): - skip(f"unable to import module {self.path!r}") - else: - raise - - # While doctests currently don't support fixtures directly, we still - # need to pick up autouse fixtures. - self.session._fixturemanager.parsefactories(self) - - # Uses internal doctest module parsing mechanism. - finder = MockAwareDocTestFinder() - optionflags = get_optionflags(self.config) - runner = _get_runner( - verbose=False, - optionflags=optionflags, - checker=_get_checker(), - continue_on_failure=_get_continue_on_failure(self.config), - ) - - for test in finder.find(module, module.__name__): - if test.examples: # skip empty doctests - yield DoctestItem.from_parent( - self, name=test.name, runner=runner, dtest=test - ) - - -def _init_checker_class() -> type[doctest.OutputChecker]: - import doctest - - class LiteralsOutputChecker(doctest.OutputChecker): - # Based on doctest_nose_plugin.py from the nltk project - # (https://github.com/nltk/nltk) and on the "numtest" doctest extension - # by Sebastien Boisgerault (https://github.com/boisgera/numtest). - - _unicode_literal_re = re.compile(r"(\W|^)[uU]([rR]?[\'\"])", re.UNICODE) - _bytes_literal_re = re.compile(r"(\W|^)[bB]([rR]?[\'\"])", re.UNICODE) - _number_re = re.compile( - r""" - (?P - (?P - (?P [+-]?\d*)\.(?P\d+) - | - (?P [+-]?\d+)\. - ) - (?: - [Ee] - (?P [+-]?\d+) - )? - | - (?P [+-]?\d+) - (?: - [Ee] - (?P [+-]?\d+) - ) - ) - """, - re.VERBOSE, - ) - - def check_output(self, want: str, got: str, optionflags: int) -> bool: - if super().check_output(want, got, optionflags): - return True - - allow_unicode = optionflags & _get_allow_unicode_flag() - allow_bytes = optionflags & _get_allow_bytes_flag() - allow_number = optionflags & _get_number_flag() - - if not allow_unicode and not allow_bytes and not allow_number: - return False - - def remove_prefixes(regex: re.Pattern[str], txt: str) -> str: - return re.sub(regex, r"\1\2", txt) - - if allow_unicode: - want = remove_prefixes(self._unicode_literal_re, want) - got = remove_prefixes(self._unicode_literal_re, got) - - if allow_bytes: - want = remove_prefixes(self._bytes_literal_re, want) - got = remove_prefixes(self._bytes_literal_re, got) - - if allow_number: - got = self._remove_unwanted_precision(want, got) - - return super().check_output(want, got, optionflags) - - def _remove_unwanted_precision(self, want: str, got: str) -> str: - wants = list(self._number_re.finditer(want)) - gots = list(self._number_re.finditer(got)) - if len(wants) != len(gots): - return got - offset = 0 - for w, g in zip(wants, gots, strict=True): - fraction: str | None = w.group("fraction") - exponent: str | None = w.group("exponent1") - if exponent is None: - exponent = w.group("exponent2") - precision = 0 if fraction is None else len(fraction) - if exponent is not None: - precision -= int(exponent) - if float(w.group()) == approx(float(g.group()), abs=10**-precision): - # They're close enough. Replace the text we actually - # got with the text we want, so that it will match when we - # check the string literally. - got = ( - got[: g.start() + offset] + w.group() + got[g.end() + offset :] - ) - offset += w.end() - w.start() - (g.end() - g.start()) - return got - - return LiteralsOutputChecker - - -def _get_checker() -> doctest.OutputChecker: - """Return a doctest.OutputChecker subclass that supports some - additional options: - - * ALLOW_UNICODE and ALLOW_BYTES options to ignore u'' and b'' - prefixes (respectively) in string literals. Useful when the same - doctest should run in Python 2 and Python 3. - - * NUMBER to ignore floating-point differences smaller than the - precision of the literal number in the doctest. - - An inner class is used to avoid importing "doctest" at the module - level. - """ - global CHECKER_CLASS - if CHECKER_CLASS is None: - CHECKER_CLASS = _init_checker_class() - return CHECKER_CLASS() - - -def _get_allow_unicode_flag() -> int: - """Register and return the ALLOW_UNICODE flag.""" - import doctest - - return doctest.register_optionflag("ALLOW_UNICODE") - - -def _get_allow_bytes_flag() -> int: - """Register and return the ALLOW_BYTES flag.""" - import doctest - - return doctest.register_optionflag("ALLOW_BYTES") - - -def _get_number_flag() -> int: - """Register and return the NUMBER flag.""" - import doctest - - return doctest.register_optionflag("NUMBER") - - -def _get_report_choice(key: str) -> int: - """Return the actual `doctest` module flag value. - - We want to do it as late as possible to avoid importing `doctest` and all - its dependencies when parsing options, as it adds overhead and breaks tests. - """ - import doctest - - return { - DOCTEST_REPORT_CHOICE_UDIFF: doctest.REPORT_UDIFF, - DOCTEST_REPORT_CHOICE_CDIFF: doctest.REPORT_CDIFF, - DOCTEST_REPORT_CHOICE_NDIFF: doctest.REPORT_NDIFF, - DOCTEST_REPORT_CHOICE_ONLY_FIRST_FAILURE: doctest.REPORT_ONLY_FIRST_FAILURE, - DOCTEST_REPORT_CHOICE_NONE: 0, - }[key] - - -@fixture(scope="session") -def doctest_namespace() -> dict[str, Any]: - """Fixture that returns a :py:class:`dict` that will be injected into the - namespace of doctests. - - Usually this fixture is used in conjunction with another ``autouse`` fixture: - - .. code-block:: python - - @pytest.fixture(autouse=True) - def add_np(doctest_namespace): - doctest_namespace["np"] = numpy - - For more details: :ref:`doctest_namespace`. - """ - return dict() diff --git a/.venv/lib/python3.12/site-packages/_pytest/faulthandler.py b/.venv/lib/python3.12/site-packages/_pytest/faulthandler.py deleted file mode 100644 index 080cf58..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/faulthandler.py +++ /dev/null @@ -1,119 +0,0 @@ -from __future__ import annotations - -from collections.abc import Generator -import os -import sys - -from _pytest.config import Config -from _pytest.config.argparsing import Parser -from _pytest.nodes import Item -from _pytest.stash import StashKey -import pytest - - -fault_handler_original_stderr_fd_key = StashKey[int]() -fault_handler_stderr_fd_key = StashKey[int]() - - -def pytest_addoption(parser: Parser) -> None: - help_timeout = ( - "Dump the traceback of all threads if a test takes " - "more than TIMEOUT seconds to finish" - ) - help_exit_on_timeout = ( - "Exit the test process if a test takes more than " - "faulthandler_timeout seconds to finish" - ) - parser.addini("faulthandler_timeout", help_timeout, default=0.0) - parser.addini( - "faulthandler_exit_on_timeout", help_exit_on_timeout, type="bool", default=False - ) - - -def pytest_configure(config: Config) -> None: - import faulthandler - - # at teardown we want to restore the original faulthandler fileno - # but faulthandler has no api to return the original fileno - # so here we stash the stderr fileno to be used at teardown - # sys.stderr and sys.__stderr__ may be closed or patched during the session - # so we can't rely on their values being good at that point (#11572). - stderr_fileno = get_stderr_fileno() - if faulthandler.is_enabled(): - config.stash[fault_handler_original_stderr_fd_key] = stderr_fileno - config.stash[fault_handler_stderr_fd_key] = os.dup(stderr_fileno) - faulthandler.enable(file=config.stash[fault_handler_stderr_fd_key]) - - -def pytest_unconfigure(config: Config) -> None: - import faulthandler - - faulthandler.disable() - # Close the dup file installed during pytest_configure. - if fault_handler_stderr_fd_key in config.stash: - os.close(config.stash[fault_handler_stderr_fd_key]) - del config.stash[fault_handler_stderr_fd_key] - # Re-enable the faulthandler if it was originally enabled. - if fault_handler_original_stderr_fd_key in config.stash: - faulthandler.enable(config.stash[fault_handler_original_stderr_fd_key]) - del config.stash[fault_handler_original_stderr_fd_key] - - -def get_stderr_fileno() -> int: - try: - fileno = sys.stderr.fileno() - # The Twisted Logger will return an invalid file descriptor since it is not backed - # by an FD. So, let's also forward this to the same code path as with pytest-xdist. - if fileno == -1: - raise AttributeError() - return fileno - except (AttributeError, ValueError): - # pytest-xdist monkeypatches sys.stderr with an object that is not an actual file. - # https://docs.python.org/3/library/faulthandler.html#issue-with-file-descriptors - # This is potentially dangerous, but the best we can do. - assert sys.__stderr__ is not None - return sys.__stderr__.fileno() - - -def get_timeout_config_value(config: Config) -> float: - return float(config.getini("faulthandler_timeout") or 0.0) - - -def get_exit_on_timeout_config_value(config: Config) -> bool: - exit_on_timeout = config.getini("faulthandler_exit_on_timeout") - assert isinstance(exit_on_timeout, bool) - return exit_on_timeout - - -@pytest.hookimpl(wrapper=True, trylast=True) -def pytest_runtest_protocol(item: Item) -> Generator[None, object, object]: - timeout = get_timeout_config_value(item.config) - exit_on_timeout = get_exit_on_timeout_config_value(item.config) - if timeout > 0: - import faulthandler - - stderr = item.config.stash[fault_handler_stderr_fd_key] - faulthandler.dump_traceback_later(timeout, file=stderr, exit=exit_on_timeout) - try: - return (yield) - finally: - faulthandler.cancel_dump_traceback_later() - else: - return (yield) - - -@pytest.hookimpl(tryfirst=True) -def pytest_enter_pdb() -> None: - """Cancel any traceback dumping due to timeout before entering pdb.""" - import faulthandler - - faulthandler.cancel_dump_traceback_later() - - -@pytest.hookimpl(tryfirst=True) -def pytest_exception_interact() -> None: - """Cancel any traceback dumping due to an interactive exception being - raised.""" - import faulthandler - - faulthandler.cancel_dump_traceback_later() diff --git a/.venv/lib/python3.12/site-packages/_pytest/fixtures.py b/.venv/lib/python3.12/site-packages/_pytest/fixtures.py deleted file mode 100644 index 27846db..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/fixtures.py +++ /dev/null @@ -1,2047 +0,0 @@ -# mypy: allow-untyped-defs -from __future__ import annotations - -import abc -from collections import defaultdict -from collections import deque -from collections import OrderedDict -from collections.abc import Callable -from collections.abc import Generator -from collections.abc import Iterable -from collections.abc import Iterator -from collections.abc import Mapping -from collections.abc import MutableMapping -from collections.abc import Sequence -from collections.abc import Set as AbstractSet -import dataclasses -import functools -import inspect -import os -from pathlib import Path -import sys -import types -from typing import Any -from typing import cast -from typing import Final -from typing import final -from typing import Generic -from typing import NoReturn -from typing import overload -from typing import TYPE_CHECKING -from typing import TypeVar -import warnings - -import _pytest -from _pytest import nodes -from _pytest._code import getfslineno -from _pytest._code import Source -from _pytest._code.code import FormattedExcinfo -from _pytest._code.code import TerminalRepr -from _pytest._io import TerminalWriter -from _pytest.compat import assert_never -from _pytest.compat import get_real_func -from _pytest.compat import getfuncargnames -from _pytest.compat import getimfunc -from _pytest.compat import getlocation -from _pytest.compat import NOTSET -from _pytest.compat import NotSetType -from _pytest.compat import safe_getattr -from _pytest.compat import safe_isclass -from _pytest.compat import signature -from _pytest.config import _PluggyPlugin -from _pytest.config import Config -from _pytest.config import ExitCode -from _pytest.config.argparsing import Parser -from _pytest.deprecated import check_ispytest -from _pytest.deprecated import MARKED_FIXTURE -from _pytest.deprecated import YIELD_FIXTURE -from _pytest.main import Session -from _pytest.mark import Mark -from _pytest.mark import ParameterSet -from _pytest.mark.structures import MarkDecorator -from _pytest.outcomes import fail -from _pytest.outcomes import skip -from _pytest.outcomes import TEST_OUTCOME -from _pytest.pathlib import absolutepath -from _pytest.pathlib import bestrelpath -from _pytest.scope import _ScopeName -from _pytest.scope import HIGH_SCOPES -from _pytest.scope import Scope -from _pytest.warning_types import PytestRemovedIn9Warning -from _pytest.warning_types import PytestWarning - - -if sys.version_info < (3, 11): - from exceptiongroup import BaseExceptionGroup - - -if TYPE_CHECKING: - from _pytest.python import CallSpec2 - from _pytest.python import Function - from _pytest.python import Metafunc - - -# The value of the fixture -- return/yield of the fixture function (type variable). -FixtureValue = TypeVar("FixtureValue", covariant=True) -# The type of the fixture function (type variable). -FixtureFunction = TypeVar("FixtureFunction", bound=Callable[..., object]) -# The type of a fixture function (type alias generic in fixture value). -_FixtureFunc = Callable[..., FixtureValue] | Callable[..., Generator[FixtureValue]] -# The type of FixtureDef.cached_result (type alias generic in fixture value). -_FixtureCachedResult = ( - tuple[ - # The result. - FixtureValue, - # Cache key. - object, - None, - ] - | tuple[ - None, - # Cache key. - object, - # The exception and the original traceback. - tuple[BaseException, types.TracebackType | None], - ] -) - - -def pytest_sessionstart(session: Session) -> None: - session._fixturemanager = FixtureManager(session) - - -def get_scope_package( - node: nodes.Item, - fixturedef: FixtureDef[object], -) -> nodes.Node | None: - from _pytest.python import Package - - for parent in node.iter_parents(): - if isinstance(parent, Package) and parent.nodeid == fixturedef.baseid: - return parent - return node.session - - -def get_scope_node(node: nodes.Node, scope: Scope) -> nodes.Node | None: - """Get the closest parent node (including self) which matches the given - scope. - - If there is no parent node for the scope (e.g. asking for class scope on a - Module, or on a Function when not defined in a class), returns None. - """ - import _pytest.python - - if scope is Scope.Function: - # Type ignored because this is actually safe, see: - # https://github.com/python/mypy/issues/4717 - return node.getparent(nodes.Item) # type: ignore[type-abstract] - elif scope is Scope.Class: - return node.getparent(_pytest.python.Class) - elif scope is Scope.Module: - return node.getparent(_pytest.python.Module) - elif scope is Scope.Package: - return node.getparent(_pytest.python.Package) - elif scope is Scope.Session: - return node.getparent(_pytest.main.Session) - else: - assert_never(scope) - - -# TODO: Try to use FixtureFunctionDefinition instead of the marker -def getfixturemarker(obj: object) -> FixtureFunctionMarker | None: - """Return fixturemarker or None if it doesn't exist""" - if isinstance(obj, FixtureFunctionDefinition): - return obj._fixture_function_marker - return None - - -# Algorithm for sorting on a per-parametrized resource setup basis. -# It is called for Session scope first and performs sorting -# down to the lower scopes such as to minimize number of "high scope" -# setups and teardowns. - - -@dataclasses.dataclass(frozen=True) -class ParamArgKey: - """A key for a high-scoped parameter used by an item. - - For use as a hashable key in `reorder_items`. The combination of fields - is meant to uniquely identify a particular "instance" of a param, - potentially shared by multiple items in a scope. - """ - - #: The param name. - argname: str - param_index: int - #: For scopes Package, Module, Class, the path to the file (directory in - #: Package's case) of the package/module/class where the item is defined. - scoped_item_path: Path | None - #: For Class scope, the class where the item is defined. - item_cls: type | None - - -_V = TypeVar("_V") -OrderedSet = dict[_V, None] - - -def get_param_argkeys(item: nodes.Item, scope: Scope) -> Iterator[ParamArgKey]: - """Return all ParamArgKeys for item matching the specified high scope.""" - assert scope is not Scope.Function - - try: - callspec: CallSpec2 = item.callspec # type: ignore[attr-defined] - except AttributeError: - return - - item_cls = None - if scope is Scope.Session: - scoped_item_path = None - elif scope is Scope.Package: - # Package key = module's directory. - scoped_item_path = item.path.parent - elif scope is Scope.Module: - scoped_item_path = item.path - elif scope is Scope.Class: - scoped_item_path = item.path - item_cls = item.cls # type: ignore[attr-defined] - else: - assert_never(scope) - - for argname in callspec.indices: - if callspec._arg2scope[argname] != scope: - continue - param_index = callspec.indices[argname] - yield ParamArgKey(argname, param_index, scoped_item_path, item_cls) - - -def reorder_items(items: Sequence[nodes.Item]) -> list[nodes.Item]: - argkeys_by_item: dict[Scope, dict[nodes.Item, OrderedSet[ParamArgKey]]] = {} - items_by_argkey: dict[Scope, dict[ParamArgKey, OrderedDict[nodes.Item, None]]] = {} - for scope in HIGH_SCOPES: - scoped_argkeys_by_item = argkeys_by_item[scope] = {} - scoped_items_by_argkey = items_by_argkey[scope] = defaultdict(OrderedDict) - for item in items: - argkeys = dict.fromkeys(get_param_argkeys(item, scope)) - if argkeys: - scoped_argkeys_by_item[item] = argkeys - for argkey in argkeys: - scoped_items_by_argkey[argkey][item] = None - - items_set = dict.fromkeys(items) - return list( - reorder_items_atscope( - items_set, argkeys_by_item, items_by_argkey, Scope.Session - ) - ) - - -def reorder_items_atscope( - items: OrderedSet[nodes.Item], - argkeys_by_item: Mapping[Scope, Mapping[nodes.Item, OrderedSet[ParamArgKey]]], - items_by_argkey: Mapping[ - Scope, Mapping[ParamArgKey, OrderedDict[nodes.Item, None]] - ], - scope: Scope, -) -> OrderedSet[nodes.Item]: - if scope is Scope.Function or len(items) < 3: - return items - - scoped_items_by_argkey = items_by_argkey[scope] - scoped_argkeys_by_item = argkeys_by_item[scope] - - ignore: set[ParamArgKey] = set() - items_deque = deque(items) - items_done: OrderedSet[nodes.Item] = {} - while items_deque: - no_argkey_items: OrderedSet[nodes.Item] = {} - slicing_argkey = None - while items_deque: - item = items_deque.popleft() - if item in items_done or item in no_argkey_items: - continue - argkeys = dict.fromkeys( - k for k in scoped_argkeys_by_item.get(item, ()) if k not in ignore - ) - if not argkeys: - no_argkey_items[item] = None - else: - slicing_argkey, _ = argkeys.popitem() - # We don't have to remove relevant items from later in the - # deque because they'll just be ignored. - matching_items = [ - i for i in scoped_items_by_argkey[slicing_argkey] if i in items - ] - for i in reversed(matching_items): - items_deque.appendleft(i) - # Fix items_by_argkey order. - for other_scope in HIGH_SCOPES: - other_scoped_items_by_argkey = items_by_argkey[other_scope] - for argkey in argkeys_by_item[other_scope].get(i, ()): - argkey_dict = other_scoped_items_by_argkey[argkey] - if not hasattr(sys, "pypy_version_info"): - argkey_dict[i] = None - argkey_dict.move_to_end(i, last=False) - else: - # Work around a bug in PyPy: - # https://github.com/pypy/pypy/issues/5257 - # https://github.com/pytest-dev/pytest/issues/13312 - bkp = argkey_dict.copy() - argkey_dict.clear() - argkey_dict[i] = None - argkey_dict.update(bkp) - break - if no_argkey_items: - reordered_no_argkey_items = reorder_items_atscope( - no_argkey_items, argkeys_by_item, items_by_argkey, scope.next_lower() - ) - items_done.update(reordered_no_argkey_items) - if slicing_argkey is not None: - ignore.add(slicing_argkey) - return items_done - - -@dataclasses.dataclass(frozen=True) -class FuncFixtureInfo: - """Fixture-related information for a fixture-requesting item (e.g. test - function). - - This is used to examine the fixtures which an item requests statically - (known during collection). This includes autouse fixtures, fixtures - requested by the `usefixtures` marker, fixtures requested in the function - parameters, and the transitive closure of these. - - An item may also request fixtures dynamically (using `request.getfixturevalue`); - these are not reflected here. - """ - - __slots__ = ("argnames", "initialnames", "name2fixturedefs", "names_closure") - - # Fixture names that the item requests directly by function parameters. - argnames: tuple[str, ...] - # Fixture names that the item immediately requires. These include - # argnames + fixture names specified via usefixtures and via autouse=True in - # fixture definitions. - initialnames: tuple[str, ...] - # The transitive closure of the fixture names that the item requires. - # Note: can't include dynamic dependencies (`request.getfixturevalue` calls). - names_closure: list[str] - # A map from a fixture name in the transitive closure to the FixtureDefs - # matching the name which are applicable to this function. - # There may be multiple overriding fixtures with the same name. The - # sequence is ordered from furthest to closes to the function. - name2fixturedefs: dict[str, Sequence[FixtureDef[Any]]] - - def prune_dependency_tree(self) -> None: - """Recompute names_closure from initialnames and name2fixturedefs. - - Can only reduce names_closure, which means that the new closure will - always be a subset of the old one. The order is preserved. - - This method is needed because direct parametrization may shadow some - of the fixtures that were included in the originally built dependency - tree. In this way the dependency tree can get pruned, and the closure - of argnames may get reduced. - """ - closure: set[str] = set() - working_set = set(self.initialnames) - while working_set: - argname = working_set.pop() - # Argname may be something not included in the original names_closure, - # in which case we ignore it. This currently happens with pseudo - # FixtureDefs which wrap 'get_direct_param_fixture_func(request)'. - # So they introduce the new dependency 'request' which might have - # been missing in the original tree (closure). - if argname not in closure and argname in self.names_closure: - closure.add(argname) - if argname in self.name2fixturedefs: - working_set.update(self.name2fixturedefs[argname][-1].argnames) - - self.names_closure[:] = sorted(closure, key=self.names_closure.index) - - -class FixtureRequest(abc.ABC): - """The type of the ``request`` fixture. - - A request object gives access to the requesting test context and has a - ``param`` attribute in case the fixture is parametrized. - """ - - def __init__( - self, - pyfuncitem: Function, - fixturename: str | None, - arg2fixturedefs: dict[str, Sequence[FixtureDef[Any]]], - fixture_defs: dict[str, FixtureDef[Any]], - *, - _ispytest: bool = False, - ) -> None: - check_ispytest(_ispytest) - #: Fixture for which this request is being performed. - self.fixturename: Final = fixturename - self._pyfuncitem: Final = pyfuncitem - # The FixtureDefs for each fixture name requested by this item. - # Starts from the statically-known fixturedefs resolved during - # collection. Dynamically requested fixtures (using - # `request.getfixturevalue("foo")`) are added dynamically. - self._arg2fixturedefs: Final = arg2fixturedefs - # The evaluated argnames so far, mapping to the FixtureDef they resolved - # to. - self._fixture_defs: Final = fixture_defs - # Notes on the type of `param`: - # -`request.param` is only defined in parametrized fixtures, and will raise - # AttributeError otherwise. Python typing has no notion of "undefined", so - # this cannot be reflected in the type. - # - Technically `param` is only (possibly) defined on SubRequest, not - # FixtureRequest, but the typing of that is still in flux so this cheats. - # - In the future we might consider using a generic for the param type, but - # for now just using Any. - self.param: Any - - @property - def _fixturemanager(self) -> FixtureManager: - return self._pyfuncitem.session._fixturemanager - - @property - @abc.abstractmethod - def _scope(self) -> Scope: - raise NotImplementedError() - - @property - def scope(self) -> _ScopeName: - """Scope string, one of "function", "class", "module", "package", "session".""" - return self._scope.value - - @abc.abstractmethod - def _check_scope( - self, - requested_fixturedef: FixtureDef[object], - requested_scope: Scope, - ) -> None: - raise NotImplementedError() - - @property - def fixturenames(self) -> list[str]: - """Names of all active fixtures in this request.""" - result = list(self._pyfuncitem.fixturenames) - result.extend(set(self._fixture_defs).difference(result)) - return result - - @property - @abc.abstractmethod - def node(self): - """Underlying collection node (depends on current request scope).""" - raise NotImplementedError() - - @property - def config(self) -> Config: - """The pytest config object associated with this request.""" - return self._pyfuncitem.config - - @property - def function(self): - """Test function object if the request has a per-function scope.""" - if self.scope != "function": - raise AttributeError( - f"function not available in {self.scope}-scoped context" - ) - return self._pyfuncitem.obj - - @property - def cls(self): - """Class (can be None) where the test function was collected.""" - if self.scope not in ("class", "function"): - raise AttributeError(f"cls not available in {self.scope}-scoped context") - clscol = self._pyfuncitem.getparent(_pytest.python.Class) - if clscol: - return clscol.obj - - @property - def instance(self): - """Instance (can be None) on which test function was collected.""" - if self.scope != "function": - return None - return getattr(self._pyfuncitem, "instance", None) - - @property - def module(self): - """Python module object where the test function was collected.""" - if self.scope not in ("function", "class", "module"): - raise AttributeError(f"module not available in {self.scope}-scoped context") - mod = self._pyfuncitem.getparent(_pytest.python.Module) - assert mod is not None - return mod.obj - - @property - def path(self) -> Path: - """Path where the test function was collected.""" - if self.scope not in ("function", "class", "module", "package"): - raise AttributeError(f"path not available in {self.scope}-scoped context") - return self._pyfuncitem.path - - @property - def keywords(self) -> MutableMapping[str, Any]: - """Keywords/markers dictionary for the underlying node.""" - node: nodes.Node = self.node - return node.keywords - - @property - def session(self) -> Session: - """Pytest session object.""" - return self._pyfuncitem.session - - @abc.abstractmethod - def addfinalizer(self, finalizer: Callable[[], object]) -> None: - """Add finalizer/teardown function to be called without arguments after - the last test within the requesting test context finished execution.""" - raise NotImplementedError() - - def applymarker(self, marker: str | MarkDecorator) -> None: - """Apply a marker to a single test function invocation. - - This method is useful if you don't want to have a keyword/marker - on all function invocations. - - :param marker: - An object created by a call to ``pytest.mark.NAME(...)``. - """ - self.node.add_marker(marker) - - def raiseerror(self, msg: str | None) -> NoReturn: - """Raise a FixtureLookupError exception. - - :param msg: - An optional custom error message. - """ - raise FixtureLookupError(None, self, msg) - - def getfixturevalue(self, argname: str) -> Any: - """Dynamically run a named fixture function. - - Declaring fixtures via function argument is recommended where possible. - But if you can only decide whether to use another fixture at test - setup time, you may use this function to retrieve it inside a fixture - or test function body. - - This method can be used during the test setup phase or the test run - phase, but during the test teardown phase a fixture's value may not - be available. - - :param argname: - The fixture name. - :raises pytest.FixtureLookupError: - If the given fixture could not be found. - """ - # Note that in addition to the use case described in the docstring, - # getfixturevalue() is also called by pytest itself during item and fixture - # setup to evaluate the fixtures that are requested statically - # (using function parameters, autouse, etc). - - fixturedef = self._get_active_fixturedef(argname) - assert fixturedef.cached_result is not None, ( - f'The fixture value for "{argname}" is not available. ' - "This can happen when the fixture has already been torn down." - ) - return fixturedef.cached_result[0] - - def _iter_chain(self) -> Iterator[SubRequest]: - """Yield all SubRequests in the chain, from self up. - - Note: does *not* yield the TopRequest. - """ - current = self - while isinstance(current, SubRequest): - yield current - current = current._parent_request - - def _get_active_fixturedef(self, argname: str) -> FixtureDef[object]: - if argname == "request": - return RequestFixtureDef(self) - - # If we already finished computing a fixture by this name in this item, - # return it. - fixturedef = self._fixture_defs.get(argname) - if fixturedef is not None: - self._check_scope(fixturedef, fixturedef._scope) - return fixturedef - - # Find the appropriate fixturedef. - fixturedefs = self._arg2fixturedefs.get(argname, None) - if fixturedefs is None: - # We arrive here because of a dynamic call to - # getfixturevalue(argname) which was naturally - # not known at parsing/collection time. - fixturedefs = self._fixturemanager.getfixturedefs(argname, self._pyfuncitem) - if fixturedefs is not None: - self._arg2fixturedefs[argname] = fixturedefs - # No fixtures defined with this name. - if fixturedefs is None: - raise FixtureLookupError(argname, self) - # The are no fixtures with this name applicable for the function. - if not fixturedefs: - raise FixtureLookupError(argname, self) - - # A fixture may override another fixture with the same name, e.g. a - # fixture in a module can override a fixture in a conftest, a fixture in - # a class can override a fixture in the module, and so on. - # An overriding fixture can request its own name (possibly indirectly); - # in this case it gets the value of the fixture it overrides, one level - # up. - # Check how many `argname`s deep we are, and take the next one. - # `fixturedefs` is sorted from furthest to closest, so use negative - # indexing to go in reverse. - index = -1 - for request in self._iter_chain(): - if request.fixturename == argname: - index -= 1 - # If already consumed all of the available levels, fail. - if -index > len(fixturedefs): - raise FixtureLookupError(argname, self) - fixturedef = fixturedefs[index] - - # Prepare a SubRequest object for calling the fixture. - try: - callspec = self._pyfuncitem.callspec - except AttributeError: - callspec = None - if callspec is not None and argname in callspec.params: - param = callspec.params[argname] - param_index = callspec.indices[argname] - # The parametrize invocation scope overrides the fixture's scope. - scope = callspec._arg2scope[argname] - else: - param = NOTSET - param_index = 0 - scope = fixturedef._scope - self._check_fixturedef_without_param(fixturedef) - # The parametrize invocation scope only controls caching behavior while - # allowing wider-scoped fixtures to keep depending on the parametrized - # fixture. Scope control is enforced for parametrized fixtures - # by recreating the whole fixture tree on parameter change. - # Hence `fixturedef._scope`, not `scope`. - self._check_scope(fixturedef, fixturedef._scope) - subrequest = SubRequest( - self, scope, param, param_index, fixturedef, _ispytest=True - ) - - # Make sure the fixture value is cached, running it if it isn't - fixturedef.execute(request=subrequest) - - self._fixture_defs[argname] = fixturedef - return fixturedef - - def _check_fixturedef_without_param(self, fixturedef: FixtureDef[object]) -> None: - """Check that this request is allowed to execute this fixturedef without - a param.""" - funcitem = self._pyfuncitem - has_params = fixturedef.params is not None - fixtures_not_supported = getattr(funcitem, "nofuncargs", False) - if has_params and fixtures_not_supported: - msg = ( - f"{funcitem.name} does not support fixtures, maybe unittest.TestCase subclass?\n" - f"Node id: {funcitem.nodeid}\n" - f"Function type: {type(funcitem).__name__}" - ) - fail(msg, pytrace=False) - if has_params: - frame = inspect.stack()[3] - frameinfo = inspect.getframeinfo(frame[0]) - source_path = absolutepath(frameinfo.filename) - source_lineno = frameinfo.lineno - try: - source_path_str = str(source_path.relative_to(funcitem.config.rootpath)) - except ValueError: - source_path_str = str(source_path) - location = getlocation(fixturedef.func, funcitem.config.rootpath) - msg = ( - "The requested fixture has no parameter defined for test:\n" - f" {funcitem.nodeid}\n\n" - f"Requested fixture '{fixturedef.argname}' defined in:\n" - f"{location}\n\n" - f"Requested here:\n" - f"{source_path_str}:{source_lineno}" - ) - fail(msg, pytrace=False) - - def _get_fixturestack(self) -> list[FixtureDef[Any]]: - values = [request._fixturedef for request in self._iter_chain()] - values.reverse() - return values - - -@final -class TopRequest(FixtureRequest): - """The type of the ``request`` fixture in a test function.""" - - def __init__(self, pyfuncitem: Function, *, _ispytest: bool = False) -> None: - super().__init__( - fixturename=None, - pyfuncitem=pyfuncitem, - arg2fixturedefs=pyfuncitem._fixtureinfo.name2fixturedefs.copy(), - fixture_defs={}, - _ispytest=_ispytest, - ) - - @property - def _scope(self) -> Scope: - return Scope.Function - - def _check_scope( - self, - requested_fixturedef: FixtureDef[object], - requested_scope: Scope, - ) -> None: - # TopRequest always has function scope so always valid. - pass - - @property - def node(self): - return self._pyfuncitem - - def __repr__(self) -> str: - return f"" - - def _fillfixtures(self) -> None: - item = self._pyfuncitem - for argname in item.fixturenames: - if argname not in item.funcargs: - item.funcargs[argname] = self.getfixturevalue(argname) - - def addfinalizer(self, finalizer: Callable[[], object]) -> None: - self.node.addfinalizer(finalizer) - - -@final -class SubRequest(FixtureRequest): - """The type of the ``request`` fixture in a fixture function requested - (transitively) by a test function.""" - - def __init__( - self, - request: FixtureRequest, - scope: Scope, - param: Any, - param_index: int, - fixturedef: FixtureDef[object], - *, - _ispytest: bool = False, - ) -> None: - super().__init__( - pyfuncitem=request._pyfuncitem, - fixturename=fixturedef.argname, - fixture_defs=request._fixture_defs, - arg2fixturedefs=request._arg2fixturedefs, - _ispytest=_ispytest, - ) - self._parent_request: Final[FixtureRequest] = request - self._scope_field: Final = scope - self._fixturedef: Final[FixtureDef[object]] = fixturedef - if param is not NOTSET: - self.param = param - self.param_index: Final = param_index - - def __repr__(self) -> str: - return f"" - - @property - def _scope(self) -> Scope: - return self._scope_field - - @property - def node(self): - scope = self._scope - if scope is Scope.Function: - # This might also be a non-function Item despite its attribute name. - node: nodes.Node | None = self._pyfuncitem - elif scope is Scope.Package: - node = get_scope_package(self._pyfuncitem, self._fixturedef) - else: - node = get_scope_node(self._pyfuncitem, scope) - if node is None and scope is Scope.Class: - # Fallback to function item itself. - node = self._pyfuncitem - assert node, ( - f'Could not obtain a node for scope "{scope}" for function {self._pyfuncitem!r}' - ) - return node - - def _check_scope( - self, - requested_fixturedef: FixtureDef[object], - requested_scope: Scope, - ) -> None: - if self._scope > requested_scope: - # Try to report something helpful. - argname = requested_fixturedef.argname - fixture_stack = "\n".join( - self._format_fixturedef_line(fixturedef) - for fixturedef in self._get_fixturestack() - ) - requested_fixture = self._format_fixturedef_line(requested_fixturedef) - fail( - f"ScopeMismatch: You tried to access the {requested_scope.value} scoped " - f"fixture {argname} with a {self._scope.value} scoped request object. " - f"Requesting fixture stack:\n{fixture_stack}\n" - f"Requested fixture:\n{requested_fixture}", - pytrace=False, - ) - - def _format_fixturedef_line(self, fixturedef: FixtureDef[object]) -> str: - factory = fixturedef.func - path, lineno = getfslineno(factory) - if isinstance(path, Path): - path = bestrelpath(self._pyfuncitem.session.path, path) - sig = signature(factory) - return f"{path}:{lineno + 1}: def {factory.__name__}{sig}" - - def addfinalizer(self, finalizer: Callable[[], object]) -> None: - self._fixturedef.addfinalizer(finalizer) - - -@final -class FixtureLookupError(LookupError): - """Could not return a requested fixture (missing or invalid).""" - - def __init__( - self, argname: str | None, request: FixtureRequest, msg: str | None = None - ) -> None: - self.argname = argname - self.request = request - self.fixturestack = request._get_fixturestack() - self.msg = msg - - def formatrepr(self) -> FixtureLookupErrorRepr: - tblines: list[str] = [] - addline = tblines.append - stack = [self.request._pyfuncitem.obj] - stack.extend(map(lambda x: x.func, self.fixturestack)) - msg = self.msg - # This function currently makes an assumption that a non-None msg means we - # have a non-empty `self.fixturestack`. This is currently true, but if - # somebody at some point want to extend the use of FixtureLookupError to - # new cases it might break. - # Add the assert to make it clearer to developer that this will fail, otherwise - # it crashes because `fspath` does not get set due to `stack` being empty. - assert self.msg is None or self.fixturestack, ( - "formatrepr assumptions broken, rewrite it to handle it" - ) - if msg is not None: - # The last fixture raise an error, let's present - # it at the requesting side. - stack = stack[:-1] - for function in stack: - fspath, lineno = getfslineno(function) - try: - lines, _ = inspect.getsourcelines(get_real_func(function)) - except (OSError, IndexError, TypeError): - error_msg = "file %s, line %s: source code not available" - addline(error_msg % (fspath, lineno + 1)) - else: - addline(f"file {fspath}, line {lineno + 1}") - for i, line in enumerate(lines): - line = line.rstrip() - addline(" " + line) - if line.lstrip().startswith("def"): - break - - if msg is None: - fm = self.request._fixturemanager - available = set() - parent = self.request._pyfuncitem.parent - assert parent is not None - for name, fixturedefs in fm._arg2fixturedefs.items(): - faclist = list(fm._matchfactories(fixturedefs, parent)) - if faclist: - available.add(name) - if self.argname in available: - msg = ( - f" recursive dependency involving fixture '{self.argname}' detected" - ) - else: - msg = f"fixture '{self.argname}' not found" - msg += "\n available fixtures: {}".format(", ".join(sorted(available))) - msg += "\n use 'pytest --fixtures [testpath]' for help on them." - - return FixtureLookupErrorRepr(fspath, lineno, tblines, msg, self.argname) - - -class FixtureLookupErrorRepr(TerminalRepr): - def __init__( - self, - filename: str | os.PathLike[str], - firstlineno: int, - tblines: Sequence[str], - errorstring: str, - argname: str | None, - ) -> None: - self.tblines = tblines - self.errorstring = errorstring - self.filename = filename - self.firstlineno = firstlineno - self.argname = argname - - def toterminal(self, tw: TerminalWriter) -> None: - # tw.line("FixtureLookupError: %s" %(self.argname), red=True) - for tbline in self.tblines: - tw.line(tbline.rstrip()) - lines = self.errorstring.split("\n") - if lines: - tw.line( - f"{FormattedExcinfo.fail_marker} {lines[0].strip()}", - red=True, - ) - for line in lines[1:]: - tw.line( - f"{FormattedExcinfo.flow_marker} {line.strip()}", - red=True, - ) - tw.line() - tw.line(f"{os.fspath(self.filename)}:{self.firstlineno + 1}") - - -def call_fixture_func( - fixturefunc: _FixtureFunc[FixtureValue], request: FixtureRequest, kwargs -) -> FixtureValue: - if inspect.isgeneratorfunction(fixturefunc): - fixturefunc = cast(Callable[..., Generator[FixtureValue]], fixturefunc) - generator = fixturefunc(**kwargs) - try: - fixture_result = next(generator) - except StopIteration: - raise ValueError(f"{request.fixturename} did not yield a value") from None - finalizer = functools.partial(_teardown_yield_fixture, fixturefunc, generator) - request.addfinalizer(finalizer) - else: - fixturefunc = cast(Callable[..., FixtureValue], fixturefunc) - fixture_result = fixturefunc(**kwargs) - return fixture_result - - -def _teardown_yield_fixture(fixturefunc, it) -> None: - """Execute the teardown of a fixture function by advancing the iterator - after the yield and ensure the iteration ends (if not it means there is - more than one yield in the function).""" - try: - next(it) - except StopIteration: - pass - else: - fs, lineno = getfslineno(fixturefunc) - fail( - f"fixture function has more than one 'yield':\n\n" - f"{Source(fixturefunc).indent()}\n" - f"{fs}:{lineno + 1}", - pytrace=False, - ) - - -def _eval_scope_callable( - scope_callable: Callable[[str, Config], _ScopeName], - fixture_name: str, - config: Config, -) -> _ScopeName: - try: - # Type ignored because there is no typing mechanism to specify - # keyword arguments, currently. - result = scope_callable(fixture_name=fixture_name, config=config) # type: ignore[call-arg] - except Exception as e: - raise TypeError( - f"Error evaluating {scope_callable} while defining fixture '{fixture_name}'.\n" - "Expected a function with the signature (*, fixture_name, config)" - ) from e - if not isinstance(result, str): - fail( - f"Expected {scope_callable} to return a 'str' while defining fixture '{fixture_name}', but it returned:\n" - f"{result!r}", - pytrace=False, - ) - return result - - -class FixtureDef(Generic[FixtureValue]): - """A container for a fixture definition. - - Note: At this time, only explicitly documented fields and methods are - considered public stable API. - """ - - def __init__( - self, - config: Config, - baseid: str | None, - argname: str, - func: _FixtureFunc[FixtureValue], - scope: Scope | _ScopeName | Callable[[str, Config], _ScopeName] | None, - params: Sequence[object] | None, - ids: tuple[object | None, ...] | Callable[[Any], object | None] | None = None, - *, - _ispytest: bool = False, - # only used in a deprecationwarning msg, can be removed in pytest9 - _autouse: bool = False, - ) -> None: - check_ispytest(_ispytest) - # The "base" node ID for the fixture. - # - # This is a node ID prefix. A fixture is only available to a node (e.g. - # a `Function` item) if the fixture's baseid is a nodeid of a parent of - # node. - # - # For a fixture found in a Collector's object (e.g. a `Module`s module, - # a `Class`'s class), the baseid is the Collector's nodeid. - # - # For a fixture found in a conftest plugin, the baseid is the conftest's - # directory path relative to the rootdir. - # - # For other plugins, the baseid is the empty string (always matches). - self.baseid: Final = baseid or "" - # Whether the fixture was found from a node or a conftest in the - # collection tree. Will be false for fixtures defined in non-conftest - # plugins. - self.has_location: Final = baseid is not None - # The fixture factory function. - self.func: Final = func - # The name by which the fixture may be requested. - self.argname: Final = argname - if scope is None: - scope = Scope.Function - elif callable(scope): - scope = _eval_scope_callable(scope, argname, config) - if isinstance(scope, str): - scope = Scope.from_user( - scope, descr=f"Fixture '{func.__name__}'", where=baseid - ) - self._scope: Final = scope - # If the fixture is directly parametrized, the parameter values. - self.params: Final = params - # If the fixture is directly parametrized, a tuple of explicit IDs to - # assign to the parameter values, or a callable to generate an ID given - # a parameter value. - self.ids: Final = ids - # The names requested by the fixtures. - self.argnames: Final = getfuncargnames(func, name=argname) - # If the fixture was executed, the current value of the fixture. - # Can change if the fixture is executed with different parameters. - self.cached_result: _FixtureCachedResult[FixtureValue] | None = None - self._finalizers: Final[list[Callable[[], object]]] = [] - - # only used to emit a deprecationwarning, can be removed in pytest9 - self._autouse = _autouse - - @property - def scope(self) -> _ScopeName: - """Scope string, one of "function", "class", "module", "package", "session".""" - return self._scope.value - - def addfinalizer(self, finalizer: Callable[[], object]) -> None: - self._finalizers.append(finalizer) - - def finish(self, request: SubRequest) -> None: - exceptions: list[BaseException] = [] - while self._finalizers: - fin = self._finalizers.pop() - try: - fin() - except BaseException as e: - exceptions.append(e) - node = request.node - node.ihook.pytest_fixture_post_finalizer(fixturedef=self, request=request) - # Even if finalization fails, we invalidate the cached fixture - # value and remove all finalizers because they may be bound methods - # which will keep instances alive. - self.cached_result = None - self._finalizers.clear() - if len(exceptions) == 1: - raise exceptions[0] - elif len(exceptions) > 1: - msg = f'errors while tearing down fixture "{self.argname}" of {node}' - raise BaseExceptionGroup(msg, exceptions[::-1]) - - def execute(self, request: SubRequest) -> FixtureValue: - """Return the value of this fixture, executing it if not cached.""" - # Ensure that the dependent fixtures requested by this fixture are loaded. - # This needs to be done before checking if we have a cached value, since - # if a dependent fixture has their cache invalidated, e.g. due to - # parametrization, they finalize themselves and fixtures depending on it - # (which will likely include this fixture) setting `self.cached_result = None`. - # See #4871 - requested_fixtures_that_should_finalize_us = [] - for argname in self.argnames: - fixturedef = request._get_active_fixturedef(argname) - # Saves requested fixtures in a list so we later can add our finalizer - # to them, ensuring that if a requested fixture gets torn down we get torn - # down first. This is generally handled by SetupState, but still currently - # needed when this fixture is not parametrized but depends on a parametrized - # fixture. - requested_fixtures_that_should_finalize_us.append(fixturedef) - - # Check for (and return) cached value/exception. - if self.cached_result is not None: - request_cache_key = self.cache_key(request) - cache_key = self.cached_result[1] - try: - # Attempt to make a normal == check: this might fail for objects - # which do not implement the standard comparison (like numpy arrays -- #6497). - cache_hit = bool(request_cache_key == cache_key) - except (ValueError, RuntimeError): - # If the comparison raises, use 'is' as fallback. - cache_hit = request_cache_key is cache_key - - if cache_hit: - if self.cached_result[2] is not None: - exc, exc_tb = self.cached_result[2] - raise exc.with_traceback(exc_tb) - else: - return self.cached_result[0] - # We have a previous but differently parametrized fixture instance - # so we need to tear it down before creating a new one. - self.finish(request) - assert self.cached_result is None - - # Add finalizer to requested fixtures we saved previously. - # We make sure to do this after checking for cached value to avoid - # adding our finalizer multiple times. (#12135) - finalizer = functools.partial(self.finish, request=request) - for parent_fixture in requested_fixtures_that_should_finalize_us: - parent_fixture.addfinalizer(finalizer) - - ihook = request.node.ihook - try: - # Setup the fixture, run the code in it, and cache the value - # in self.cached_result. - result: FixtureValue = ihook.pytest_fixture_setup( - fixturedef=self, request=request - ) - finally: - # Schedule our finalizer, even if the setup failed. - request.node.addfinalizer(finalizer) - - return result - - def cache_key(self, request: SubRequest) -> object: - return getattr(request, "param", None) - - def __repr__(self) -> str: - return f"" - - -class RequestFixtureDef(FixtureDef[FixtureRequest]): - """A custom FixtureDef for the special "request" fixture. - - A new one is generated on-demand whenever "request" is requested. - """ - - def __init__(self, request: FixtureRequest) -> None: - super().__init__( - config=request.config, - baseid=None, - argname="request", - func=lambda: request, - scope=Scope.Function, - params=None, - _ispytest=True, - ) - self.cached_result = (request, [0], None) - - def addfinalizer(self, finalizer: Callable[[], object]) -> None: - pass - - -def resolve_fixture_function( - fixturedef: FixtureDef[FixtureValue], request: FixtureRequest -) -> _FixtureFunc[FixtureValue]: - """Get the actual callable that can be called to obtain the fixture - value.""" - fixturefunc = fixturedef.func - # The fixture function needs to be bound to the actual - # request.instance so that code working with "fixturedef" behaves - # as expected. - instance = request.instance - if instance is not None: - # Handle the case where fixture is defined not in a test class, but some other class - # (for example a plugin class with a fixture), see #2270. - if hasattr(fixturefunc, "__self__") and not isinstance( - instance, - fixturefunc.__self__.__class__, - ): - return fixturefunc - fixturefunc = getimfunc(fixturedef.func) - if fixturefunc != fixturedef.func: - fixturefunc = fixturefunc.__get__(instance) - return fixturefunc - - -def pytest_fixture_setup( - fixturedef: FixtureDef[FixtureValue], request: SubRequest -) -> FixtureValue: - """Execution of fixture setup.""" - kwargs = {} - for argname in fixturedef.argnames: - kwargs[argname] = request.getfixturevalue(argname) - - fixturefunc = resolve_fixture_function(fixturedef, request) - my_cache_key = fixturedef.cache_key(request) - - if inspect.isasyncgenfunction(fixturefunc) or inspect.iscoroutinefunction( - fixturefunc - ): - auto_str = " with autouse=True" if fixturedef._autouse else "" - - warnings.warn( - PytestRemovedIn9Warning( - f"{request.node.name!r} requested an async fixture " - f"{request.fixturename!r}{auto_str}, with no plugin or hook that " - "handled it. This is usually an error, as pytest does not natively " - "support it. " - "This will turn into an error in pytest 9.\n" - "See: https://docs.pytest.org/en/stable/deprecations.html#sync-test-depending-on-async-fixture" - ), - # no stacklevel will point at users code, so we just point here - stacklevel=1, - ) - - try: - result = call_fixture_func(fixturefunc, request, kwargs) - except TEST_OUTCOME as e: - if isinstance(e, skip.Exception): - # The test requested a fixture which caused a skip. - # Don't show the fixture as the skip location, as then the user - # wouldn't know which test skipped. - e._use_item_location = True - fixturedef.cached_result = (None, my_cache_key, (e, e.__traceback__)) - raise - fixturedef.cached_result = (result, my_cache_key, None) - return result - - -@final -@dataclasses.dataclass(frozen=True) -class FixtureFunctionMarker: - scope: _ScopeName | Callable[[str, Config], _ScopeName] - params: tuple[object, ...] | None - autouse: bool = False - ids: tuple[object | None, ...] | Callable[[Any], object | None] | None = None - name: str | None = None - - _ispytest: dataclasses.InitVar[bool] = False - - def __post_init__(self, _ispytest: bool) -> None: - check_ispytest(_ispytest) - - def __call__(self, function: FixtureFunction) -> FixtureFunctionDefinition: - if inspect.isclass(function): - raise ValueError("class fixtures not supported (maybe in the future)") - - if isinstance(function, FixtureFunctionDefinition): - raise ValueError( - f"@pytest.fixture is being applied more than once to the same function {function.__name__!r}" - ) - - if hasattr(function, "pytestmark"): - warnings.warn(MARKED_FIXTURE, stacklevel=2) - - fixture_definition = FixtureFunctionDefinition( - function=function, fixture_function_marker=self, _ispytest=True - ) - - name = self.name or function.__name__ - if name == "request": - location = getlocation(function) - fail( - f"'request' is a reserved word for fixtures, use another name:\n {location}", - pytrace=False, - ) - - return fixture_definition - - -# TODO: paramspec/return type annotation tracking and storing -class FixtureFunctionDefinition: - def __init__( - self, - *, - function: Callable[..., Any], - fixture_function_marker: FixtureFunctionMarker, - instance: object | None = None, - _ispytest: bool = False, - ) -> None: - check_ispytest(_ispytest) - self.name = fixture_function_marker.name or function.__name__ - # In order to show the function that this fixture contains in messages. - # Set the __name__ to be same as the function __name__ or the given fixture name. - self.__name__ = self.name - self._fixture_function_marker = fixture_function_marker - if instance is not None: - self._fixture_function = cast( - Callable[..., Any], function.__get__(instance) - ) - else: - self._fixture_function = function - functools.update_wrapper(self, function) - - def __repr__(self) -> str: - return f"" - - def __get__(self, instance, owner=None): - """Behave like a method if the function it was applied to was a method.""" - return FixtureFunctionDefinition( - function=self._fixture_function, - fixture_function_marker=self._fixture_function_marker, - instance=instance, - _ispytest=True, - ) - - def __call__(self, *args: Any, **kwds: Any) -> Any: - message = ( - f'Fixture "{self.name}" called directly. Fixtures are not meant to be called directly,\n' - "but are created automatically when test functions request them as parameters.\n" - "See https://docs.pytest.org/en/stable/explanation/fixtures.html for more information about fixtures, and\n" - "https://docs.pytest.org/en/stable/deprecations.html#calling-fixtures-directly" - ) - fail(message, pytrace=False) - - def _get_wrapped_function(self) -> Callable[..., Any]: - return self._fixture_function - - -@overload -def fixture( - fixture_function: Callable[..., object], - *, - scope: _ScopeName | Callable[[str, Config], _ScopeName] = ..., - params: Iterable[object] | None = ..., - autouse: bool = ..., - ids: Sequence[object | None] | Callable[[Any], object | None] | None = ..., - name: str | None = ..., -) -> FixtureFunctionDefinition: ... - - -@overload -def fixture( - fixture_function: None = ..., - *, - scope: _ScopeName | Callable[[str, Config], _ScopeName] = ..., - params: Iterable[object] | None = ..., - autouse: bool = ..., - ids: Sequence[object | None] | Callable[[Any], object | None] | None = ..., - name: str | None = None, -) -> FixtureFunctionMarker: ... - - -def fixture( - fixture_function: FixtureFunction | None = None, - *, - scope: _ScopeName | Callable[[str, Config], _ScopeName] = "function", - params: Iterable[object] | None = None, - autouse: bool = False, - ids: Sequence[object | None] | Callable[[Any], object | None] | None = None, - name: str | None = None, -) -> FixtureFunctionMarker | FixtureFunctionDefinition: - """Decorator to mark a fixture factory function. - - This decorator can be used, with or without parameters, to define a - fixture function. - - The name of the fixture function can later be referenced to cause its - invocation ahead of running tests: test modules or classes can use the - ``pytest.mark.usefixtures(fixturename)`` marker. - - Test functions can directly use fixture names as input arguments in which - case the fixture instance returned from the fixture function will be - injected. - - Fixtures can provide their values to test functions using ``return`` or - ``yield`` statements. When using ``yield`` the code block after the - ``yield`` statement is executed as teardown code regardless of the test - outcome, and must yield exactly once. - - :param scope: - The scope for which this fixture is shared; one of ``"function"`` - (default), ``"class"``, ``"module"``, ``"package"`` or ``"session"``. - - This parameter may also be a callable which receives ``(fixture_name, config)`` - as parameters, and must return a ``str`` with one of the values mentioned above. - - See :ref:`dynamic scope` in the docs for more information. - - :param params: - An optional list of parameters which will cause multiple invocations - of the fixture function and all of the tests using it. The current - parameter is available in ``request.param``. - - :param autouse: - If True, the fixture func is activated for all tests that can see it. - If False (the default), an explicit reference is needed to activate - the fixture. - - :param ids: - Sequence of ids each corresponding to the params so that they are - part of the test id. If no ids are provided they will be generated - automatically from the params. - - :param name: - The name of the fixture. This defaults to the name of the decorated - function. If a fixture is used in the same module in which it is - defined, the function name of the fixture will be shadowed by the - function arg that requests the fixture; one way to resolve this is to - name the decorated function ``fixture_`` and then use - ``@pytest.fixture(name='')``. - """ - fixture_marker = FixtureFunctionMarker( - scope=scope, - params=tuple(params) if params is not None else None, - autouse=autouse, - ids=None if ids is None else ids if callable(ids) else tuple(ids), - name=name, - _ispytest=True, - ) - - # Direct decoration. - if fixture_function: - return fixture_marker(fixture_function) - - return fixture_marker - - -def yield_fixture( - fixture_function=None, - *args, - scope="function", - params=None, - autouse=False, - ids=None, - name=None, -): - """(Return a) decorator to mark a yield-fixture factory function. - - .. deprecated:: 3.0 - Use :py:func:`pytest.fixture` directly instead. - """ - warnings.warn(YIELD_FIXTURE, stacklevel=2) - return fixture( - fixture_function, - *args, - scope=scope, - params=params, - autouse=autouse, - ids=ids, - name=name, - ) - - -@fixture(scope="session") -def pytestconfig(request: FixtureRequest) -> Config: - """Session-scoped fixture that returns the session's :class:`pytest.Config` - object. - - Example:: - - def test_foo(pytestconfig): - if pytestconfig.get_verbosity() > 0: - ... - - """ - return request.config - - -def pytest_addoption(parser: Parser) -> None: - parser.addini( - "usefixtures", - type="args", - default=[], - help="List of default fixtures to be used with this project", - ) - group = parser.getgroup("general") - group.addoption( - "--fixtures", - "--funcargs", - action="store_true", - dest="showfixtures", - default=False, - help="Show available fixtures, sorted by plugin appearance " - "(fixtures with leading '_' are only shown with '-v')", - ) - group.addoption( - "--fixtures-per-test", - action="store_true", - dest="show_fixtures_per_test", - default=False, - help="Show fixtures per test", - ) - - -def pytest_cmdline_main(config: Config) -> int | ExitCode | None: - if config.option.showfixtures: - showfixtures(config) - return 0 - if config.option.show_fixtures_per_test: - show_fixtures_per_test(config) - return 0 - return None - - -def _get_direct_parametrize_args(node: nodes.Node) -> set[str]: - """Return all direct parametrization arguments of a node, so we don't - mistake them for fixtures. - - Check https://github.com/pytest-dev/pytest/issues/5036. - - These things are done later as well when dealing with parametrization - so this could be improved. - """ - parametrize_argnames: set[str] = set() - for marker in node.iter_markers(name="parametrize"): - if not marker.kwargs.get("indirect", False): - p_argnames, _ = ParameterSet._parse_parametrize_args( - *marker.args, **marker.kwargs - ) - parametrize_argnames.update(p_argnames) - return parametrize_argnames - - -def deduplicate_names(*seqs: Iterable[str]) -> tuple[str, ...]: - """De-duplicate the sequence of names while keeping the original order.""" - # Ideally we would use a set, but it does not preserve insertion order. - return tuple(dict.fromkeys(name for seq in seqs for name in seq)) - - -class FixtureManager: - """pytest fixture definitions and information is stored and managed - from this class. - - During collection fm.parsefactories() is called multiple times to parse - fixture function definitions into FixtureDef objects and internal - data structures. - - During collection of test functions, metafunc-mechanics instantiate - a FuncFixtureInfo object which is cached per node/func-name. - This FuncFixtureInfo object is later retrieved by Function nodes - which themselves offer a fixturenames attribute. - - The FuncFixtureInfo object holds information about fixtures and FixtureDefs - relevant for a particular function. An initial list of fixtures is - assembled like this: - - - config-defined usefixtures - - autouse-marked fixtures along the collection chain up from the function - - usefixtures markers at module/class/function level - - test function funcargs - - Subsequently the funcfixtureinfo.fixturenames attribute is computed - as the closure of the fixtures needed to setup the initial fixtures, - i.e. fixtures needed by fixture functions themselves are appended - to the fixturenames list. - - Upon the test-setup phases all fixturenames are instantiated, retrieved - by a lookup of their FuncFixtureInfo. - """ - - def __init__(self, session: Session) -> None: - self.session = session - self.config: Config = session.config - # Maps a fixture name (argname) to all of the FixtureDefs in the test - # suite/plugins defined with this name. Populated by parsefactories(). - # TODO: The order of the FixtureDefs list of each arg is significant, - # explain. - self._arg2fixturedefs: Final[dict[str, list[FixtureDef[Any]]]] = {} - self._holderobjseen: Final[set[object]] = set() - # A mapping from a nodeid to a list of autouse fixtures it defines. - self._nodeid_autousenames: Final[dict[str, list[str]]] = { - "": self.config.getini("usefixtures"), - } - session.config.pluginmanager.register(self, "funcmanage") - - def getfixtureinfo( - self, - node: nodes.Item, - func: Callable[..., object] | None, - cls: type | None, - ) -> FuncFixtureInfo: - """Calculate the :class:`FuncFixtureInfo` for an item. - - If ``func`` is None, or if the item sets an attribute - ``nofuncargs = True``, then ``func`` is not examined at all. - - :param node: - The item requesting the fixtures. - :param func: - The item's function. - :param cls: - If the function is a method, the method's class. - """ - if func is not None and not getattr(node, "nofuncargs", False): - argnames = getfuncargnames(func, name=node.name, cls=cls) - else: - argnames = () - usefixturesnames = self._getusefixturesnames(node) - autousenames = self._getautousenames(node) - initialnames = deduplicate_names(autousenames, usefixturesnames, argnames) - - direct_parametrize_args = _get_direct_parametrize_args(node) - - names_closure, arg2fixturedefs = self.getfixtureclosure( - parentnode=node, - initialnames=initialnames, - ignore_args=direct_parametrize_args, - ) - - return FuncFixtureInfo(argnames, initialnames, names_closure, arg2fixturedefs) - - def pytest_plugin_registered(self, plugin: _PluggyPlugin, plugin_name: str) -> None: - # Fixtures defined in conftest plugins are only visible to within the - # conftest's directory. This is unlike fixtures in non-conftest plugins - # which have global visibility. So for conftests, construct the base - # nodeid from the plugin name (which is the conftest path). - if plugin_name and plugin_name.endswith("conftest.py"): - # Note: we explicitly do *not* use `plugin.__file__` here -- The - # difference is that plugin_name has the correct capitalization on - # case-insensitive systems (Windows) and other normalization issues - # (issue #11816). - conftestpath = absolutepath(plugin_name) - try: - nodeid = str(conftestpath.parent.relative_to(self.config.rootpath)) - except ValueError: - nodeid = "" - if nodeid == ".": - nodeid = "" - if os.sep != nodes.SEP: - nodeid = nodeid.replace(os.sep, nodes.SEP) - else: - nodeid = None - - self.parsefactories(plugin, nodeid) - - def _getautousenames(self, node: nodes.Node) -> Iterator[str]: - """Return the names of autouse fixtures applicable to node.""" - for parentnode in node.listchain(): - basenames = self._nodeid_autousenames.get(parentnode.nodeid) - if basenames: - yield from basenames - - def _getusefixturesnames(self, node: nodes.Item) -> Iterator[str]: - """Return the names of usefixtures fixtures applicable to node.""" - for marker_node, mark in node.iter_markers_with_node(name="usefixtures"): - if not mark.args: - marker_node.warn( - PytestWarning( - f"usefixtures() in {node.nodeid} without arguments has no effect" - ) - ) - yield from mark.args - - def getfixtureclosure( - self, - parentnode: nodes.Node, - initialnames: tuple[str, ...], - ignore_args: AbstractSet[str], - ) -> tuple[list[str], dict[str, Sequence[FixtureDef[Any]]]]: - # Collect the closure of all fixtures, starting with the given - # fixturenames as the initial set. As we have to visit all - # factory definitions anyway, we also return an arg2fixturedefs - # mapping so that the caller can reuse it and does not have - # to re-discover fixturedefs again for each fixturename - # (discovering matching fixtures for a given name/node is expensive). - - fixturenames_closure = list(initialnames) - - arg2fixturedefs: dict[str, Sequence[FixtureDef[Any]]] = {} - - # Track the index for each fixture name in the simulated stack. - # Needed for handling override chains correctly, similar to _get_active_fixturedef. - # Using negative indices: -1 is the most specific (last), -2 is second to last, etc. - current_indices: dict[str, int] = {} - - def process_argname(argname: str) -> None: - # Optimization: already processed this argname. - if current_indices.get(argname) == -1: - return - - if argname not in fixturenames_closure: - fixturenames_closure.append(argname) - - if argname in ignore_args: - return - - fixturedefs = arg2fixturedefs.get(argname) - if not fixturedefs: - fixturedefs = self.getfixturedefs(argname, parentnode) - if not fixturedefs: - # Fixture not defined or not visible (will error during runtest). - return - arg2fixturedefs[argname] = fixturedefs - - index = current_indices.get(argname, -1) - if -index > len(fixturedefs): - # Exhausted the override chain (will error during runtest). - return - fixturedef = fixturedefs[index] - - current_indices[argname] = index - 1 - for dep in fixturedef.argnames: - process_argname(dep) - current_indices[argname] = index - - for name in initialnames: - process_argname(name) - - def sort_by_scope(arg_name: str) -> Scope: - try: - fixturedefs = arg2fixturedefs[arg_name] - except KeyError: - return Scope.Function - else: - return fixturedefs[-1]._scope - - fixturenames_closure.sort(key=sort_by_scope, reverse=True) - return fixturenames_closure, arg2fixturedefs - - def pytest_generate_tests(self, metafunc: Metafunc) -> None: - """Generate new tests based on parametrized fixtures used by the given metafunc""" - - def get_parametrize_mark_argnames(mark: Mark) -> Sequence[str]: - args, _ = ParameterSet._parse_parametrize_args(*mark.args, **mark.kwargs) - return args - - for argname in metafunc.fixturenames: - # Get the FixtureDefs for the argname. - fixture_defs = metafunc._arg2fixturedefs.get(argname) - if not fixture_defs: - # Will raise FixtureLookupError at setup time if not parametrized somewhere - # else (e.g @pytest.mark.parametrize) - continue - - # If the test itself parametrizes using this argname, give it - # precedence. - if any( - argname in get_parametrize_mark_argnames(mark) - for mark in metafunc.definition.iter_markers("parametrize") - ): - continue - - # In the common case we only look at the fixture def with the - # closest scope (last in the list). But if the fixture overrides - # another fixture, while requesting the super fixture, keep going - # in case the super fixture is parametrized (#1953). - for fixturedef in reversed(fixture_defs): - # Fixture is parametrized, apply it and stop. - if fixturedef.params is not None: - metafunc.parametrize( - argname, - fixturedef.params, - indirect=True, - scope=fixturedef.scope, - ids=fixturedef.ids, - ) - break - - # Not requesting the overridden super fixture, stop. - if argname not in fixturedef.argnames: - break - - # Try next super fixture, if any. - - def pytest_collection_modifyitems(self, items: list[nodes.Item]) -> None: - # Separate parametrized setups. - items[:] = reorder_items(items) - - def _register_fixture( - self, - *, - name: str, - func: _FixtureFunc[object], - nodeid: str | None, - scope: Scope | _ScopeName | Callable[[str, Config], _ScopeName] = "function", - params: Sequence[object] | None = None, - ids: tuple[object | None, ...] | Callable[[Any], object | None] | None = None, - autouse: bool = False, - ) -> None: - """Register a fixture - - :param name: - The fixture's name. - :param func: - The fixture's implementation function. - :param nodeid: - The visibility of the fixture. The fixture will be available to the - node with this nodeid and its children in the collection tree. - None means that the fixture is visible to the entire collection tree, - e.g. a fixture defined for general use in a plugin. - :param scope: - The fixture's scope. - :param params: - The fixture's parametrization params. - :param ids: - The fixture's IDs. - :param autouse: - Whether this is an autouse fixture. - """ - fixture_def = FixtureDef( - config=self.config, - baseid=nodeid, - argname=name, - func=func, - scope=scope, - params=params, - ids=ids, - _ispytest=True, - _autouse=autouse, - ) - - faclist = self._arg2fixturedefs.setdefault(name, []) - if fixture_def.has_location: - faclist.append(fixture_def) - else: - # fixturedefs with no location are at the front - # so this inserts the current fixturedef after the - # existing fixturedefs from external plugins but - # before the fixturedefs provided in conftests. - i = len([f for f in faclist if not f.has_location]) - faclist.insert(i, fixture_def) - if autouse: - self._nodeid_autousenames.setdefault(nodeid or "", []).append(name) - - @overload - def parsefactories( - self, - node_or_obj: nodes.Node, - ) -> None: - raise NotImplementedError() - - @overload - def parsefactories( - self, - node_or_obj: object, - nodeid: str | None, - ) -> None: - raise NotImplementedError() - - def parsefactories( - self, - node_or_obj: nodes.Node | object, - nodeid: str | NotSetType | None = NOTSET, - ) -> None: - """Collect fixtures from a collection node or object. - - Found fixtures are parsed into `FixtureDef`s and saved. - - If `node_or_object` is a collection node (with an underlying Python - object), the node's object is traversed and the node's nodeid is used to - determine the fixtures' visibility. `nodeid` must not be specified in - this case. - - If `node_or_object` is an object (e.g. a plugin), the object is - traversed and the given `nodeid` is used to determine the fixtures' - visibility. `nodeid` must be specified in this case; None and "" mean - total visibility. - """ - if nodeid is not NOTSET: - holderobj = node_or_obj - else: - assert isinstance(node_or_obj, nodes.Node) - holderobj = cast(object, node_or_obj.obj) # type: ignore[attr-defined] - assert isinstance(node_or_obj.nodeid, str) - nodeid = node_or_obj.nodeid - if holderobj in self._holderobjseen: - return - - # Avoid accessing `@property` (and other descriptors) when iterating fixtures. - if not safe_isclass(holderobj) and not isinstance(holderobj, types.ModuleType): - holderobj_tp: object = type(holderobj) - else: - holderobj_tp = holderobj - - self._holderobjseen.add(holderobj) - for name in dir(holderobj): - # The attribute can be an arbitrary descriptor, so the attribute - # access below can raise. safe_getattr() ignores such exceptions. - obj_ub = safe_getattr(holderobj_tp, name, None) - if type(obj_ub) is FixtureFunctionDefinition: - marker = obj_ub._fixture_function_marker - if marker.name: - fixture_name = marker.name - else: - fixture_name = name - - # OK we know it is a fixture -- now safe to look up on the _instance_. - try: - obj = getattr(holderobj, name) - # if the fixture is named in the decorator we cannot find it in the module - except AttributeError: - obj = obj_ub - - func = obj._get_wrapped_function() - - self._register_fixture( - name=fixture_name, - nodeid=nodeid, - func=func, - scope=marker.scope, - params=marker.params, - ids=marker.ids, - autouse=marker.autouse, - ) - - def getfixturedefs( - self, argname: str, node: nodes.Node - ) -> Sequence[FixtureDef[Any]] | None: - """Get FixtureDefs for a fixture name which are applicable - to a given node. - - Returns None if there are no fixtures at all defined with the given - name. (This is different from the case in which there are fixtures - with the given name, but none applicable to the node. In this case, - an empty result is returned). - - :param argname: Name of the fixture to search for. - :param node: The requesting Node. - """ - try: - fixturedefs = self._arg2fixturedefs[argname] - except KeyError: - return None - return tuple(self._matchfactories(fixturedefs, node)) - - def _matchfactories( - self, fixturedefs: Iterable[FixtureDef[Any]], node: nodes.Node - ) -> Iterator[FixtureDef[Any]]: - parentnodeids = {n.nodeid for n in node.iter_parents()} - for fixturedef in fixturedefs: - if fixturedef.baseid in parentnodeids: - yield fixturedef - - -def show_fixtures_per_test(config: Config) -> int | ExitCode: - from _pytest.main import wrap_session - - return wrap_session(config, _show_fixtures_per_test) - - -_PYTEST_DIR = Path(_pytest.__file__).parent - - -def _pretty_fixture_path(invocation_dir: Path, func) -> str: - loc = Path(getlocation(func, invocation_dir)) - prefix = Path("...", "_pytest") - try: - return str(prefix / loc.relative_to(_PYTEST_DIR)) - except ValueError: - return bestrelpath(invocation_dir, loc) - - -def _show_fixtures_per_test(config: Config, session: Session) -> None: - import _pytest.config - - session.perform_collect() - invocation_dir = config.invocation_params.dir - tw = _pytest.config.create_terminal_writer(config) - verbose = config.get_verbosity() - - def get_best_relpath(func) -> str: - loc = getlocation(func, invocation_dir) - return bestrelpath(invocation_dir, Path(loc)) - - def write_fixture(fixture_def: FixtureDef[object]) -> None: - argname = fixture_def.argname - if verbose <= 0 and argname.startswith("_"): - return - prettypath = _pretty_fixture_path(invocation_dir, fixture_def.func) - tw.write(f"{argname}", green=True) - tw.write(f" -- {prettypath}", yellow=True) - tw.write("\n") - fixture_doc = inspect.getdoc(fixture_def.func) - if fixture_doc: - write_docstring( - tw, - fixture_doc.split("\n\n", maxsplit=1)[0] - if verbose <= 0 - else fixture_doc, - ) - else: - tw.line(" no docstring available", red=True) - - def write_item(item: nodes.Item) -> None: - # Not all items have _fixtureinfo attribute. - info: FuncFixtureInfo | None = getattr(item, "_fixtureinfo", None) - if info is None or not info.name2fixturedefs: - # This test item does not use any fixtures. - return - tw.line() - tw.sep("-", f"fixtures used by {item.name}") - # TODO: Fix this type ignore. - tw.sep("-", f"({get_best_relpath(item.function)})") # type: ignore[attr-defined] - # dict key not used in loop but needed for sorting. - for _, fixturedefs in sorted(info.name2fixturedefs.items()): - assert fixturedefs is not None - if not fixturedefs: - continue - # Last item is expected to be the one used by the test item. - write_fixture(fixturedefs[-1]) - - for session_item in session.items: - write_item(session_item) - - -def showfixtures(config: Config) -> int | ExitCode: - from _pytest.main import wrap_session - - return wrap_session(config, _showfixtures_main) - - -def _showfixtures_main(config: Config, session: Session) -> None: - import _pytest.config - - session.perform_collect() - invocation_dir = config.invocation_params.dir - tw = _pytest.config.create_terminal_writer(config) - verbose = config.get_verbosity() - - fm = session._fixturemanager - - available = [] - seen: set[tuple[str, str]] = set() - - for argname, fixturedefs in fm._arg2fixturedefs.items(): - assert fixturedefs is not None - if not fixturedefs: - continue - for fixturedef in fixturedefs: - loc = getlocation(fixturedef.func, invocation_dir) - if (fixturedef.argname, loc) in seen: - continue - seen.add((fixturedef.argname, loc)) - available.append( - ( - len(fixturedef.baseid), - fixturedef.func.__module__, - _pretty_fixture_path(invocation_dir, fixturedef.func), - fixturedef.argname, - fixturedef, - ) - ) - - available.sort() - currentmodule = None - for baseid, module, prettypath, argname, fixturedef in available: - if currentmodule != module: - if not module.startswith("_pytest."): - tw.line() - tw.sep("-", f"fixtures defined from {module}") - currentmodule = module - if verbose <= 0 and argname.startswith("_"): - continue - tw.write(f"{argname}", green=True) - if fixturedef.scope != "function": - tw.write(f" [{fixturedef.scope} scope]", cyan=True) - tw.write(f" -- {prettypath}", yellow=True) - tw.write("\n") - doc = inspect.getdoc(fixturedef.func) - if doc: - write_docstring( - tw, doc.split("\n\n", maxsplit=1)[0] if verbose <= 0 else doc - ) - else: - tw.line(" no docstring available", red=True) - tw.line() - - -def write_docstring(tw: TerminalWriter, doc: str, indent: str = " ") -> None: - for line in doc.split("\n"): - tw.line(indent + line) diff --git a/.venv/lib/python3.12/site-packages/_pytest/freeze_support.py b/.venv/lib/python3.12/site-packages/_pytest/freeze_support.py deleted file mode 100644 index 959ff07..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/freeze_support.py +++ /dev/null @@ -1,45 +0,0 @@ -"""Provides a function to report all internal modules for using freezing -tools.""" - -from __future__ import annotations - -from collections.abc import Iterator -import types - - -def freeze_includes() -> list[str]: - """Return a list of module names used by pytest that should be - included by cx_freeze.""" - import _pytest - - result = list(_iter_all_modules(_pytest)) - return result - - -def _iter_all_modules( - package: str | types.ModuleType, - prefix: str = "", -) -> Iterator[str]: - """Iterate over the names of all modules that can be found in the given - package, recursively. - - >>> import _pytest - >>> list(_iter_all_modules(_pytest)) - ['_pytest._argcomplete', '_pytest._code.code', ...] - """ - import os - import pkgutil - - if isinstance(package, str): - path = package - else: - # Type ignored because typeshed doesn't define ModuleType.__path__ - # (only defined on packages). - package_path = package.__path__ - path, prefix = package_path[0], package.__name__ + "." - for _, name, is_package in pkgutil.iter_modules([path]): - if is_package: - for m in _iter_all_modules(os.path.join(path, name), prefix=name + "."): - yield prefix + m - else: - yield prefix + name diff --git a/.venv/lib/python3.12/site-packages/_pytest/helpconfig.py b/.venv/lib/python3.12/site-packages/_pytest/helpconfig.py deleted file mode 100644 index 6a22c9f..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/helpconfig.py +++ /dev/null @@ -1,293 +0,0 @@ -# mypy: allow-untyped-defs -"""Version info, help messages, tracing configuration.""" - -from __future__ import annotations - -import argparse -from collections.abc import Generator -from collections.abc import Sequence -import os -import sys -from typing import Any - -from _pytest.config import Config -from _pytest.config import ExitCode -from _pytest.config import PrintHelp -from _pytest.config.argparsing import Parser -from _pytest.terminal import TerminalReporter -import pytest - - -class HelpAction(argparse.Action): - """An argparse Action that will raise a PrintHelp exception in order to skip - the rest of the argument parsing when --help is passed. - - This prevents argparse from raising UsageError when `--help` is used along - with missing required arguments when any are defined, for example by - ``pytest_addoption``. This is similar to the way that the builtin argparse - --help option is implemented by raising SystemExit. - - To opt in to this behavior, the parse caller must set - `namespace._raise_print_help = True`. Otherwise it just sets the option. - """ - - def __init__( - self, option_strings: Sequence[str], dest: str, *, help: str | None = None - ) -> None: - super().__init__( - option_strings=option_strings, - dest=dest, - nargs=0, - const=True, - default=False, - help=help, - ) - - def __call__( - self, - parser: argparse.ArgumentParser, - namespace: argparse.Namespace, - values: str | Sequence[Any] | None, - option_string: str | None = None, - ) -> None: - setattr(namespace, self.dest, self.const) - - if getattr(namespace, "_raise_print_help", False): - raise PrintHelp - - -def pytest_addoption(parser: Parser) -> None: - group = parser.getgroup("debugconfig") - group.addoption( - "--version", - "-V", - action="count", - default=0, - dest="version", - help="Display pytest version and information about plugins. " - "When given twice, also display information about plugins.", - ) - group._addoption( # private to use reserved lower-case short option - "-h", - "--help", - action=HelpAction, - dest="help", - help="Show help message and configuration info", - ) - group._addoption( # private to use reserved lower-case short option - "-p", - action="append", - dest="plugins", - default=[], - metavar="name", - help="Early-load given plugin module name or entry point (multi-allowed). " - "To avoid loading of plugins, use the `no:` prefix, e.g. " - "`no:doctest`. See also --disable-plugin-autoload.", - ) - group.addoption( - "--disable-plugin-autoload", - action="store_true", - default=False, - help="Disable plugin auto-loading through entry point packaging metadata. " - "Only plugins explicitly specified in -p or env var PYTEST_PLUGINS will be loaded.", - ) - group.addoption( - "--traceconfig", - "--trace-config", - action="store_true", - default=False, - help="Trace considerations of conftest.py files", - ) - group.addoption( - "--debug", - action="store", - nargs="?", - const="pytestdebug.log", - dest="debug", - metavar="DEBUG_FILE_NAME", - help="Store internal tracing debug information in this log file. " - "This file is opened with 'w' and truncated as a result, care advised. " - "Default: pytestdebug.log.", - ) - group._addoption( # private to use reserved lower-case short option - "-o", - "--override-ini", - dest="override_ini", - action="append", - help='Override configuration option with "option=value" style, ' - "e.g. `-o strict_xfail=True -o cache_dir=cache`.", - ) - - -@pytest.hookimpl(wrapper=True) -def pytest_cmdline_parse() -> Generator[None, Config, Config]: - config = yield - - if config.option.debug: - # --debug | --debug was provided. - path = config.option.debug - debugfile = open(path, "w", encoding="utf-8") - debugfile.write( - "versions pytest-{}, " - "python-{}\ninvocation_dir={}\ncwd={}\nargs={}\n\n".format( - pytest.__version__, - ".".join(map(str, sys.version_info)), - config.invocation_params.dir, - os.getcwd(), - config.invocation_params.args, - ) - ) - config.trace.root.setwriter(debugfile.write) - undo_tracing = config.pluginmanager.enable_tracing() - sys.stderr.write(f"writing pytest debug information to {path}\n") - - def unset_tracing() -> None: - debugfile.close() - sys.stderr.write(f"wrote pytest debug information to {debugfile.name}\n") - config.trace.root.setwriter(None) - undo_tracing() - - config.add_cleanup(unset_tracing) - - return config - - -def show_version_verbose(config: Config) -> None: - """Show verbose pytest version installation, including plugins.""" - sys.stdout.write( - f"This is pytest version {pytest.__version__}, imported from {pytest.__file__}\n" - ) - plugininfo = getpluginversioninfo(config) - if plugininfo: - for line in plugininfo: - sys.stdout.write(line + "\n") - - -def pytest_cmdline_main(config: Config) -> int | ExitCode | None: - # Note: a single `--version` argument is handled directly by `Config.main()` to avoid starting up the entire - # pytest infrastructure just to display the version (#13574). - if config.option.version > 1: - show_version_verbose(config) - return ExitCode.OK - elif config.option.help: - config._do_configure() - showhelp(config) - config._ensure_unconfigure() - return ExitCode.OK - return None - - -def showhelp(config: Config) -> None: - import textwrap - - reporter: TerminalReporter | None = config.pluginmanager.get_plugin( - "terminalreporter" - ) - assert reporter is not None - tw = reporter._tw - tw.write(config._parser.optparser.format_help()) - tw.line() - tw.line( - "[pytest] configuration options in the first " - "pytest.toml|pytest.ini|tox.ini|setup.cfg|pyproject.toml file found:" - ) - tw.line() - - columns = tw.fullwidth # costly call - indent_len = 24 # based on argparse's max_help_position=24 - indent = " " * indent_len - for name in config._parser._inidict: - help, type, _default = config._parser._inidict[name] - if help is None: - raise TypeError(f"help argument cannot be None for {name}") - spec = f"{name} ({type}):" - tw.write(f" {spec}") - spec_len = len(spec) - if spec_len > (indent_len - 3): - # Display help starting at a new line. - tw.line() - helplines = textwrap.wrap( - help, - columns, - initial_indent=indent, - subsequent_indent=indent, - break_on_hyphens=False, - ) - - for line in helplines: - tw.line(line) - else: - # Display help starting after the spec, following lines indented. - tw.write(" " * (indent_len - spec_len - 2)) - wrapped = textwrap.wrap(help, columns - indent_len, break_on_hyphens=False) - - if wrapped: - tw.line(wrapped[0]) - for line in wrapped[1:]: - tw.line(indent + line) - - tw.line() - tw.line("Environment variables:") - vars = [ - ( - "CI", - "When set to a non-empty value, pytest knows it is running in a " - "CI process and does not truncate summary info", - ), - ("BUILD_NUMBER", "Equivalent to CI"), - ("PYTEST_ADDOPTS", "Extra command line options"), - ("PYTEST_PLUGINS", "Comma-separated plugins to load during startup"), - ("PYTEST_DISABLE_PLUGIN_AUTOLOAD", "Set to disable plugin auto-loading"), - ("PYTEST_DEBUG", "Set to enable debug tracing of pytest's internals"), - ("PYTEST_DEBUG_TEMPROOT", "Override the system temporary directory"), - ("PYTEST_THEME", "The Pygments style to use for code output"), - ("PYTEST_THEME_MODE", "Set the PYTEST_THEME to be either 'dark' or 'light'"), - ] - for name, help in vars: - tw.line(f" {name:<24} {help}") - tw.line() - tw.line() - - tw.line("to see available markers type: pytest --markers") - tw.line("to see available fixtures type: pytest --fixtures") - tw.line( - "(shown according to specified file_or_dir or current dir " - "if not specified; fixtures with leading '_' are only shown " - "with the '-v' option" - ) - - for warningreport in reporter.stats.get("warnings", []): - tw.line("warning : " + warningreport.message, red=True) - - -def getpluginversioninfo(config: Config) -> list[str]: - lines = [] - plugininfo = config.pluginmanager.list_plugin_distinfo() - if plugininfo: - lines.append("registered third-party plugins:") - for plugin, dist in plugininfo: - loc = getattr(plugin, "__file__", repr(plugin)) - content = f"{dist.project_name}-{dist.version} at {loc}" - lines.append(" " + content) - return lines - - -def pytest_report_header(config: Config) -> list[str]: - lines = [] - if config.option.debug or config.option.traceconfig: - lines.append(f"using: pytest-{pytest.__version__}") - - verinfo = getpluginversioninfo(config) - if verinfo: - lines.extend(verinfo) - - if config.option.traceconfig: - lines.append("active plugins:") - items = config.pluginmanager.list_name_plugin() - for name, plugin in items: - if hasattr(plugin, "__file__"): - r = plugin.__file__ - else: - r = repr(plugin) - lines.append(f" {name:<20}: {r}") - return lines diff --git a/.venv/lib/python3.12/site-packages/_pytest/hookspec.py b/.venv/lib/python3.12/site-packages/_pytest/hookspec.py deleted file mode 100644 index dab3fb6..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/hookspec.py +++ /dev/null @@ -1,1342 +0,0 @@ -# mypy: allow-untyped-defs -# ruff: noqa: T100 -"""Hook specifications for pytest plugins which are invoked by pytest itself -and by builtin plugins.""" - -from __future__ import annotations - -from collections.abc import Mapping -from collections.abc import Sequence -from pathlib import Path -from typing import Any -from typing import TYPE_CHECKING - -from pluggy import HookspecMarker - -from .deprecated import HOOK_LEGACY_PATH_ARG - - -if TYPE_CHECKING: - import pdb - from typing import Literal - import warnings - - from _pytest._code.code import ExceptionInfo - from _pytest._code.code import ExceptionRepr - from _pytest.compat import LEGACY_PATH - from _pytest.config import _PluggyPlugin - from _pytest.config import Config - from _pytest.config import ExitCode - from _pytest.config import PytestPluginManager - from _pytest.config.argparsing import Parser - from _pytest.fixtures import FixtureDef - from _pytest.fixtures import SubRequest - from _pytest.main import Session - from _pytest.nodes import Collector - from _pytest.nodes import Item - from _pytest.outcomes import Exit - from _pytest.python import Class - from _pytest.python import Function - from _pytest.python import Metafunc - from _pytest.python import Module - from _pytest.reports import CollectReport - from _pytest.reports import TestReport - from _pytest.runner import CallInfo - from _pytest.terminal import TerminalReporter - from _pytest.terminal import TestShortLogReport - - -hookspec = HookspecMarker("pytest") - -# ------------------------------------------------------------------------- -# Initialization hooks called for every plugin -# ------------------------------------------------------------------------- - - -@hookspec(historic=True) -def pytest_addhooks(pluginmanager: PytestPluginManager) -> None: - """Called at plugin registration time to allow adding new hooks via a call to - :func:`pluginmanager.add_hookspecs(module_or_class, prefix) `. - - :param pluginmanager: The pytest plugin manager. - - .. note:: - This hook is incompatible with hook wrappers. - - Use in conftest plugins - ======================= - - If a conftest plugin implements this hook, it will be called immediately - when the conftest is registered. - """ - - -@hookspec(historic=True) -def pytest_plugin_registered( - plugin: _PluggyPlugin, - plugin_name: str, - manager: PytestPluginManager, -) -> None: - """A new pytest plugin got registered. - - :param plugin: The plugin module or instance. - :param plugin_name: The name by which the plugin is registered. - :param manager: The pytest plugin manager. - - .. note:: - This hook is incompatible with hook wrappers. - - Use in conftest plugins - ======================= - - If a conftest plugin implements this hook, it will be called immediately - when the conftest is registered, once for each plugin registered thus far - (including itself!), and for all plugins thereafter when they are - registered. - """ - - -@hookspec(historic=True) -def pytest_addoption(parser: Parser, pluginmanager: PytestPluginManager) -> None: - """Register argparse-style options and config-style config values, - called once at the beginning of a test run. - - :param parser: - To add command line options, call - :py:func:`parser.addoption(...) `. - To add config-file values call :py:func:`parser.addini(...) - `. - - :param pluginmanager: - The pytest plugin manager, which can be used to install :py:func:`~pytest.hookspec`'s - or :py:func:`~pytest.hookimpl`'s and allow one plugin to call another plugin's hooks - to change how command line options are added. - - Options can later be accessed through the - :py:class:`config ` object, respectively: - - - :py:func:`config.getoption(name) ` to - retrieve the value of a command line option. - - - :py:func:`config.getini(name) ` to retrieve - a value read from a configuration file. - - The config object is passed around on many internal objects via the ``.config`` - attribute or can be retrieved as the ``pytestconfig`` fixture. - - .. note:: - This hook is incompatible with hook wrappers. - - Use in conftest plugins - ======================= - - If a conftest plugin implements this hook, it will be called immediately - when the conftest is registered. - - This hook is only called for :ref:`initial conftests `. - """ - - -@hookspec(historic=True) -def pytest_configure(config: Config) -> None: - """Allow plugins and conftest files to perform initial configuration. - - .. note:: - This hook is incompatible with hook wrappers. - - :param config: The pytest config object. - - Use in conftest plugins - ======================= - - This hook is called for every :ref:`initial conftest ` file - after command line options have been parsed. After that, the hook is called - for other conftest files as they are registered. - """ - - -# ------------------------------------------------------------------------- -# Bootstrapping hooks called for plugins registered early enough: -# internal and 3rd party plugins. -# ------------------------------------------------------------------------- - - -@hookspec(firstresult=True) -def pytest_cmdline_parse( - pluginmanager: PytestPluginManager, args: list[str] -) -> Config | None: - """Return an initialized :class:`~pytest.Config`, parsing the specified args. - - Stops at first non-None result, see :ref:`firstresult`. - - .. note:: - This hook is only called for plugin classes passed to the - ``plugins`` arg when using `pytest.main`_ to perform an in-process - test run. - - :param pluginmanager: The pytest plugin manager. - :param args: List of arguments passed on the command line. - :returns: A pytest config object. - - Use in conftest plugins - ======================= - - This hook is not called for conftest files. - """ - - -def pytest_load_initial_conftests( - early_config: Config, parser: Parser, args: list[str] -) -> None: - """Called to implement the loading of :ref:`initial conftest files - ` ahead of command line option parsing. - - :param early_config: The pytest config object. - :param args: Arguments passed on the command line. - :param parser: To add command line options. - - Use in conftest plugins - ======================= - - This hook is not called for conftest files. - """ - - -@hookspec(firstresult=True) -def pytest_cmdline_main(config: Config) -> ExitCode | int | None: - """Called for performing the main command line action. - - The default implementation will invoke the configure hooks and - :hook:`pytest_runtestloop`. - - Stops at first non-None result, see :ref:`firstresult`. - - :param config: The pytest config object. - :returns: The exit code. - - Use in conftest plugins - ======================= - - This hook is only called for :ref:`initial conftests `. - """ - - -# ------------------------------------------------------------------------- -# collection hooks -# ------------------------------------------------------------------------- - - -@hookspec(firstresult=True) -def pytest_collection(session: Session) -> object | None: - """Perform the collection phase for the given session. - - Stops at first non-None result, see :ref:`firstresult`. - The return value is not used, but only stops further processing. - - The default collection phase is this (see individual hooks for full details): - - 1. Starting from ``session`` as the initial collector: - - 1. ``pytest_collectstart(collector)`` - 2. ``report = pytest_make_collect_report(collector)`` - 3. ``pytest_exception_interact(collector, call, report)`` if an interactive exception occurred - 4. For each collected node: - - 1. If an item, ``pytest_itemcollected(item)`` - 2. If a collector, recurse into it. - - 5. ``pytest_collectreport(report)`` - - 2. ``pytest_collection_modifyitems(session, config, items)`` - - 1. ``pytest_deselected(items)`` for any deselected items (may be called multiple times) - - 3. Set ``session.items`` to the list of collected items - 4. ``pytest_collection_finish(session)`` - 5. Set ``session.testscollected`` to the number of collected items - - You can implement this hook to only perform some action before collection, - for example the terminal plugin uses it to start displaying the collection - counter (and returns `None`). - - :param session: The pytest session object. - - Use in conftest plugins - ======================= - - This hook is only called for :ref:`initial conftests `. - """ - - -def pytest_collection_modifyitems( - session: Session, config: Config, items: list[Item] -) -> None: - """Called after collection has been performed. May filter or re-order - the items in-place. - - When items are deselected (filtered out from ``items``), - the hook :hook:`pytest_deselected` must be called explicitly - with the deselected items to properly notify other plugins, - e.g. with ``config.hook.pytest_deselected(items=deselected_items)``. - - :param session: The pytest session object. - :param config: The pytest config object. - :param items: List of item objects. - - Use in conftest plugins - ======================= - - Any conftest plugin can implement this hook. - """ - - -def pytest_collection_finish(session: Session) -> None: - """Called after collection has been performed and modified. - - :param session: The pytest session object. - - Use in conftest plugins - ======================= - - Any conftest plugin can implement this hook. - """ - - -@hookspec( - firstresult=True, - warn_on_impl_args={ - "path": HOOK_LEGACY_PATH_ARG.format( - pylib_path_arg="path", pathlib_path_arg="collection_path" - ), - }, -) -def pytest_ignore_collect( - collection_path: Path, path: LEGACY_PATH, config: Config -) -> bool | None: - """Return ``True`` to ignore this path for collection. - - Return ``None`` to let other plugins ignore the path for collection. - - Returning ``False`` will forcefully *not* ignore this path for collection, - without giving a chance for other plugins to ignore this path. - - This hook is consulted for all files and directories prior to calling - more specific hooks. - - Stops at first non-None result, see :ref:`firstresult`. - - :param collection_path: The path to analyze. - :type collection_path: pathlib.Path - :param path: The path to analyze (deprecated). - :param config: The pytest config object. - - .. versionchanged:: 7.0.0 - The ``collection_path`` parameter was added as a :class:`pathlib.Path` - equivalent of the ``path`` parameter. The ``path`` parameter - has been deprecated. - - Use in conftest plugins - ======================= - - Any conftest file can implement this hook. For a given collection path, only - conftest files in parent directories of the collection path are consulted - (if the path is a directory, its own conftest file is *not* consulted - a - directory cannot ignore itself!). - """ - - -@hookspec(firstresult=True) -def pytest_collect_directory(path: Path, parent: Collector) -> Collector | None: - """Create a :class:`~pytest.Collector` for the given directory, or None if - not relevant. - - .. versionadded:: 8.0 - - For best results, the returned collector should be a subclass of - :class:`~pytest.Directory`, but this is not required. - - The new node needs to have the specified ``parent`` as a parent. - - Stops at first non-None result, see :ref:`firstresult`. - - :param path: The path to analyze. - :type path: pathlib.Path - - See :ref:`custom directory collectors` for a simple example of use of this - hook. - - Use in conftest plugins - ======================= - - Any conftest file can implement this hook. For a given collection path, only - conftest files in parent directories of the collection path are consulted - (if the path is a directory, its own conftest file is *not* consulted - a - directory cannot collect itself!). - """ - - -@hookspec( - warn_on_impl_args={ - "path": HOOK_LEGACY_PATH_ARG.format( - pylib_path_arg="path", pathlib_path_arg="file_path" - ), - }, -) -def pytest_collect_file( - file_path: Path, path: LEGACY_PATH, parent: Collector -) -> Collector | None: - """Create a :class:`~pytest.Collector` for the given path, or None if not relevant. - - For best results, the returned collector should be a subclass of - :class:`~pytest.File`, but this is not required. - - The new node needs to have the specified ``parent`` as a parent. - - :param file_path: The path to analyze. - :type file_path: pathlib.Path - :param path: The path to collect (deprecated). - - .. versionchanged:: 7.0.0 - The ``file_path`` parameter was added as a :class:`pathlib.Path` - equivalent of the ``path`` parameter. The ``path`` parameter - has been deprecated. - - Use in conftest plugins - ======================= - - Any conftest file can implement this hook. For a given file path, only - conftest files in parent directories of the file path are consulted. - """ - - -# logging hooks for collection - - -def pytest_collectstart(collector: Collector) -> None: - """Collector starts collecting. - - :param collector: - The collector. - - Use in conftest plugins - ======================= - - Any conftest file can implement this hook. For a given collector, only - conftest files in the collector's directory and its parent directories are - consulted. - """ - - -def pytest_itemcollected(item: Item) -> None: - """We just collected a test item. - - :param item: - The item. - - Use in conftest plugins - ======================= - - Any conftest file can implement this hook. For a given item, only conftest - files in the item's directory and its parent directories are consulted. - """ - - -def pytest_collectreport(report: CollectReport) -> None: - """Collector finished collecting. - - :param report: - The collect report. - - Use in conftest plugins - ======================= - - Any conftest file can implement this hook. For a given collector, only - conftest files in the collector's directory and its parent directories are - consulted. - """ - - -def pytest_deselected(items: Sequence[Item]) -> None: - """Called for deselected test items, e.g. by keyword. - - Note that this hook has two integration aspects for plugins: - - - it can be *implemented* to be notified of deselected items - - it must be *called* from :hook:`pytest_collection_modifyitems` - implementations when items are deselected (to properly notify other plugins). - - May be called multiple times. - - :param items: - The items. - - Use in conftest plugins - ======================= - - Any conftest file can implement this hook. - """ - - -@hookspec(firstresult=True) -def pytest_make_collect_report(collector: Collector) -> CollectReport | None: - """Perform :func:`collector.collect() ` and return - a :class:`~pytest.CollectReport`. - - Stops at first non-None result, see :ref:`firstresult`. - - :param collector: - The collector. - - Use in conftest plugins - ======================= - - Any conftest file can implement this hook. For a given collector, only - conftest files in the collector's directory and its parent directories are - consulted. - """ - - -# ------------------------------------------------------------------------- -# Python test function related hooks -# ------------------------------------------------------------------------- - - -@hookspec( - firstresult=True, - warn_on_impl_args={ - "path": HOOK_LEGACY_PATH_ARG.format( - pylib_path_arg="path", pathlib_path_arg="module_path" - ), - }, -) -def pytest_pycollect_makemodule( - module_path: Path, path: LEGACY_PATH, parent -) -> Module | None: - """Return a :class:`pytest.Module` collector or None for the given path. - - This hook will be called for each matching test module path. - The :hook:`pytest_collect_file` hook needs to be used if you want to - create test modules for files that do not match as a test module. - - Stops at first non-None result, see :ref:`firstresult`. - - :param module_path: The path of the module to collect. - :type module_path: pathlib.Path - :param path: The path of the module to collect (deprecated). - - .. versionchanged:: 7.0.0 - The ``module_path`` parameter was added as a :class:`pathlib.Path` - equivalent of the ``path`` parameter. - - The ``path`` parameter has been deprecated in favor of ``fspath``. - - Use in conftest plugins - ======================= - - Any conftest file can implement this hook. For a given parent collector, - only conftest files in the collector's directory and its parent directories - are consulted. - """ - - -@hookspec(firstresult=True) -def pytest_pycollect_makeitem( - collector: Module | Class, name: str, obj: object -) -> None | Item | Collector | list[Item | Collector]: - """Return a custom item/collector for a Python object in a module, or None. - - Stops at first non-None result, see :ref:`firstresult`. - - :param collector: - The module/class collector. - :param name: - The name of the object in the module/class. - :param obj: - The object. - :returns: - The created items/collectors. - - Use in conftest plugins - ======================= - - Any conftest file can implement this hook. For a given collector, only - conftest files in the collector's directory and its parent directories - are consulted. - """ - - -@hookspec(firstresult=True) -def pytest_pyfunc_call(pyfuncitem: Function) -> object | None: - """Call underlying test function. - - Stops at first non-None result, see :ref:`firstresult`. - - :param pyfuncitem: - The function item. - - Use in conftest plugins - ======================= - - Any conftest file can implement this hook. For a given item, only - conftest files in the item's directory and its parent directories - are consulted. - """ - - -def pytest_generate_tests(metafunc: Metafunc) -> None: - """Generate (multiple) parametrized calls to a test function. - - :param metafunc: - The :class:`~pytest.Metafunc` helper for the test function. - - Use in conftest plugins - ======================= - - Any conftest file can implement this hook. For a given function definition, - only conftest files in the functions's directory and its parent directories - are consulted. - """ - - -@hookspec(firstresult=True) -def pytest_make_parametrize_id(config: Config, val: object, argname: str) -> str | None: - """Return a user-friendly string representation of the given ``val`` - that will be used by @pytest.mark.parametrize calls, or None if the hook - doesn't know about ``val``. - - The parameter name is available as ``argname``, if required. - - Stops at first non-None result, see :ref:`firstresult`. - - :param config: The pytest config object. - :param val: The parametrized value. - :param argname: The automatic parameter name produced by pytest. - - Use in conftest plugins - ======================= - - Any conftest file can implement this hook. - """ - - -# ------------------------------------------------------------------------- -# runtest related hooks -# ------------------------------------------------------------------------- - - -@hookspec(firstresult=True) -def pytest_runtestloop(session: Session) -> object | None: - """Perform the main runtest loop (after collection finished). - - The default hook implementation performs the runtest protocol for all items - collected in the session (``session.items``), unless the collection failed - or the ``collectonly`` pytest option is set. - - If at any point :py:func:`pytest.exit` is called, the loop is - terminated immediately. - - If at any point ``session.shouldfail`` or ``session.shouldstop`` are set, the - loop is terminated after the runtest protocol for the current item is finished. - - :param session: The pytest session object. - - Stops at first non-None result, see :ref:`firstresult`. - The return value is not used, but only stops further processing. - - Use in conftest plugins - ======================= - - Any conftest file can implement this hook. - """ - - -@hookspec(firstresult=True) -def pytest_runtest_protocol(item: Item, nextitem: Item | None) -> object | None: - """Perform the runtest protocol for a single test item. - - The default runtest protocol is this (see individual hooks for full details): - - - ``pytest_runtest_logstart(nodeid, location)`` - - - Setup phase: - - ``call = pytest_runtest_setup(item)`` (wrapped in ``CallInfo(when="setup")``) - - ``report = pytest_runtest_makereport(item, call)`` - - ``pytest_runtest_logreport(report)`` - - ``pytest_exception_interact(call, report)`` if an interactive exception occurred - - - Call phase, if the setup passed and the ``setuponly`` pytest option is not set: - - ``call = pytest_runtest_call(item)`` (wrapped in ``CallInfo(when="call")``) - - ``report = pytest_runtest_makereport(item, call)`` - - ``pytest_runtest_logreport(report)`` - - ``pytest_exception_interact(call, report)`` if an interactive exception occurred - - - Teardown phase: - - ``call = pytest_runtest_teardown(item, nextitem)`` (wrapped in ``CallInfo(when="teardown")``) - - ``report = pytest_runtest_makereport(item, call)`` - - ``pytest_runtest_logreport(report)`` - - ``pytest_exception_interact(call, report)`` if an interactive exception occurred - - - ``pytest_runtest_logfinish(nodeid, location)`` - - :param item: Test item for which the runtest protocol is performed. - :param nextitem: The scheduled-to-be-next test item (or None if this is the end my friend). - - Stops at first non-None result, see :ref:`firstresult`. - The return value is not used, but only stops further processing. - - Use in conftest plugins - ======================= - - Any conftest file can implement this hook. - """ - - -def pytest_runtest_logstart(nodeid: str, location: tuple[str, int | None, str]) -> None: - """Called at the start of running the runtest protocol for a single item. - - See :hook:`pytest_runtest_protocol` for a description of the runtest protocol. - - :param nodeid: Full node ID of the item. - :param location: A tuple of ``(filename, lineno, testname)`` - where ``filename`` is a file path relative to ``config.rootpath`` - and ``lineno`` is 0-based. - - Use in conftest plugins - ======================= - - Any conftest file can implement this hook. For a given item, only conftest - files in the item's directory and its parent directories are consulted. - """ - - -def pytest_runtest_logfinish( - nodeid: str, location: tuple[str, int | None, str] -) -> None: - """Called at the end of running the runtest protocol for a single item. - - See :hook:`pytest_runtest_protocol` for a description of the runtest protocol. - - :param nodeid: Full node ID of the item. - :param location: A tuple of ``(filename, lineno, testname)`` - where ``filename`` is a file path relative to ``config.rootpath`` - and ``lineno`` is 0-based. - - Use in conftest plugins - ======================= - - Any conftest file can implement this hook. For a given item, only conftest - files in the item's directory and its parent directories are consulted. - """ - - -def pytest_runtest_setup(item: Item) -> None: - """Called to perform the setup phase for a test item. - - The default implementation runs ``setup()`` on ``item`` and all of its - parents (which haven't been setup yet). This includes obtaining the - values of fixtures required by the item (which haven't been obtained - yet). - - :param item: - The item. - - Use in conftest plugins - ======================= - - Any conftest file can implement this hook. For a given item, only conftest - files in the item's directory and its parent directories are consulted. - """ - - -def pytest_runtest_call(item: Item) -> None: - """Called to run the test for test item (the call phase). - - The default implementation calls ``item.runtest()``. - - :param item: - The item. - - Use in conftest plugins - ======================= - - Any conftest file can implement this hook. For a given item, only conftest - files in the item's directory and its parent directories are consulted. - """ - - -def pytest_runtest_teardown(item: Item, nextitem: Item | None) -> None: - """Called to perform the teardown phase for a test item. - - The default implementation runs the finalizers and calls ``teardown()`` - on ``item`` and all of its parents (which need to be torn down). This - includes running the teardown phase of fixtures required by the item (if - they go out of scope). - - :param item: - The item. - :param nextitem: - The scheduled-to-be-next test item (None if no further test item is - scheduled). This argument is used to perform exact teardowns, i.e. - calling just enough finalizers so that nextitem only needs to call - setup functions. - - Use in conftest plugins - ======================= - - Any conftest file can implement this hook. For a given item, only conftest - files in the item's directory and its parent directories are consulted. - """ - - -@hookspec(firstresult=True) -def pytest_runtest_makereport(item: Item, call: CallInfo[None]) -> TestReport | None: - """Called to create a :class:`~pytest.TestReport` for each of - the setup, call and teardown runtest phases of a test item. - - See :hook:`pytest_runtest_protocol` for a description of the runtest protocol. - - :param item: The item. - :param call: The :class:`~pytest.CallInfo` for the phase. - - Stops at first non-None result, see :ref:`firstresult`. - - Use in conftest plugins - ======================= - - Any conftest file can implement this hook. For a given item, only conftest - files in the item's directory and its parent directories are consulted. - """ - - -def pytest_runtest_logreport(report: TestReport) -> None: - """Process the :class:`~pytest.TestReport` produced for each - of the setup, call and teardown runtest phases of an item. - - See :hook:`pytest_runtest_protocol` for a description of the runtest protocol. - - Use in conftest plugins - ======================= - - Any conftest file can implement this hook. For a given item, only conftest - files in the item's directory and its parent directories are consulted. - """ - - -@hookspec(firstresult=True) -def pytest_report_to_serializable( - config: Config, - report: CollectReport | TestReport, -) -> dict[str, Any] | None: - """Serialize the given report object into a data structure suitable for - sending over the wire, e.g. converted to JSON. - - :param config: The pytest config object. - :param report: The report. - - Use in conftest plugins - ======================= - - Any conftest file can implement this hook. The exact details may depend - on the plugin which calls the hook. - """ - - -@hookspec(firstresult=True) -def pytest_report_from_serializable( - config: Config, - data: dict[str, Any], -) -> CollectReport | TestReport | None: - """Restore a report object previously serialized with - :hook:`pytest_report_to_serializable`. - - :param config: The pytest config object. - - Use in conftest plugins - ======================= - - Any conftest file can implement this hook. The exact details may depend - on the plugin which calls the hook. - """ - - -# ------------------------------------------------------------------------- -# Fixture related hooks -# ------------------------------------------------------------------------- - - -@hookspec(firstresult=True) -def pytest_fixture_setup( - fixturedef: FixtureDef[Any], request: SubRequest -) -> object | None: - """Perform fixture setup execution. - - :param fixturedef: - The fixture definition object. - :param request: - The fixture request object. - :returns: - The return value of the call to the fixture function. - - Stops at first non-None result, see :ref:`firstresult`. - - .. note:: - If the fixture function returns None, other implementations of - this hook function will continue to be called, according to the - behavior of the :ref:`firstresult` option. - - Use in conftest plugins - ======================= - - Any conftest file can implement this hook. For a given fixture, only - conftest files in the fixture scope's directory and its parent directories - are consulted. - """ - - -def pytest_fixture_post_finalizer( - fixturedef: FixtureDef[Any], request: SubRequest -) -> None: - """Called after fixture teardown, but before the cache is cleared, so - the fixture result ``fixturedef.cached_result`` is still available (not - ``None``). - - :param fixturedef: - The fixture definition object. - :param request: - The fixture request object. - - Use in conftest plugins - ======================= - - Any conftest file can implement this hook. For a given fixture, only - conftest files in the fixture scope's directory and its parent directories - are consulted. - """ - - -# ------------------------------------------------------------------------- -# test session related hooks -# ------------------------------------------------------------------------- - - -def pytest_sessionstart(session: Session) -> None: - """Called after the ``Session`` object has been created and before performing collection - and entering the run test loop. - - :param session: The pytest session object. - - Use in conftest plugins - ======================= - - This hook is only called for :ref:`initial conftests `. - """ - - -def pytest_sessionfinish( - session: Session, - exitstatus: int | ExitCode, -) -> None: - """Called after whole test run finished, right before returning the exit status to the system. - - :param session: The pytest session object. - :param exitstatus: The status which pytest will return to the system. - - Use in conftest plugins - ======================= - - Any conftest file can implement this hook. - """ - - -def pytest_unconfigure(config: Config) -> None: - """Called before test process is exited. - - :param config: The pytest config object. - - Use in conftest plugins - ======================= - - Any conftest file can implement this hook. - """ - - -# ------------------------------------------------------------------------- -# hooks for customizing the assert methods -# ------------------------------------------------------------------------- - - -def pytest_assertrepr_compare( - config: Config, op: str, left: object, right: object -) -> list[str] | None: - """Return explanation for comparisons in failing assert expressions. - - Return None for no custom explanation, otherwise return a list - of strings. The strings will be joined by newlines but any newlines - *in* a string will be escaped. Note that all but the first line will - be indented slightly, the intention is for the first line to be a summary. - - :param config: The pytest config object. - :param op: The operator, e.g. `"=="`, `"!="`, `"not in"`. - :param left: The left operand. - :param right: The right operand. - - Use in conftest plugins - ======================= - - Any conftest file can implement this hook. For a given item, only conftest - files in the item's directory and its parent directories are consulted. - """ - - -def pytest_assertion_pass(item: Item, lineno: int, orig: str, expl: str) -> None: - """Called whenever an assertion passes. - - .. versionadded:: 5.0 - - Use this hook to do some processing after a passing assertion. - The original assertion information is available in the `orig` string - and the pytest introspected assertion information is available in the - `expl` string. - - This hook must be explicitly enabled by the :confval:`enable_assertion_pass_hook` - configuration option: - - .. tab:: toml - - .. code-block:: toml - - [pytest] - enable_assertion_pass_hook = true - - .. tab:: ini - - .. code-block:: ini - - [pytest] - enable_assertion_pass_hook = true - - You need to **clean the .pyc** files in your project directory and interpreter libraries - when enabling this option, as assertions will require to be re-written. - - :param item: pytest item object of current test. - :param lineno: Line number of the assert statement. - :param orig: String with the original assertion. - :param expl: String with the assert explanation. - - Use in conftest plugins - ======================= - - Any conftest file can implement this hook. For a given item, only conftest - files in the item's directory and its parent directories are consulted. - """ - - -# ------------------------------------------------------------------------- -# Hooks for influencing reporting (invoked from _pytest_terminal). -# ------------------------------------------------------------------------- - - -@hookspec( - warn_on_impl_args={ - "startdir": HOOK_LEGACY_PATH_ARG.format( - pylib_path_arg="startdir", pathlib_path_arg="start_path" - ), - }, -) -def pytest_report_header( # type:ignore[empty-body] - config: Config, start_path: Path, startdir: LEGACY_PATH -) -> str | list[str]: - """Return a string or list of strings to be displayed as header info for terminal reporting. - - :param config: The pytest config object. - :param start_path: The starting dir. - :type start_path: pathlib.Path - :param startdir: The starting dir (deprecated). - - .. note:: - - Lines returned by a plugin are displayed before those of plugins which - ran before it. - If you want to have your line(s) displayed first, use - :ref:`trylast=True `. - - .. versionchanged:: 7.0.0 - The ``start_path`` parameter was added as a :class:`pathlib.Path` - equivalent of the ``startdir`` parameter. The ``startdir`` parameter - has been deprecated. - - Use in conftest plugins - ======================= - - This hook is only called for :ref:`initial conftests `. - """ - - -@hookspec( - warn_on_impl_args={ - "startdir": HOOK_LEGACY_PATH_ARG.format( - pylib_path_arg="startdir", pathlib_path_arg="start_path" - ), - }, -) -def pytest_report_collectionfinish( # type:ignore[empty-body] - config: Config, - start_path: Path, - startdir: LEGACY_PATH, - items: Sequence[Item], -) -> str | list[str]: - """Return a string or list of strings to be displayed after collection - has finished successfully. - - These strings will be displayed after the standard "collected X items" message. - - .. versionadded:: 3.2 - - :param config: The pytest config object. - :param start_path: The starting dir. - :type start_path: pathlib.Path - :param startdir: The starting dir (deprecated). - :param items: List of pytest items that are going to be executed; this list should not be modified. - - .. note:: - - Lines returned by a plugin are displayed before those of plugins which - ran before it. - If you want to have your line(s) displayed first, use - :ref:`trylast=True `. - - .. versionchanged:: 7.0.0 - The ``start_path`` parameter was added as a :class:`pathlib.Path` - equivalent of the ``startdir`` parameter. The ``startdir`` parameter - has been deprecated. - - Use in conftest plugins - ======================= - - Any conftest plugin can implement this hook. - """ - - -@hookspec(firstresult=True) -def pytest_report_teststatus( # type:ignore[empty-body] - report: CollectReport | TestReport, config: Config -) -> TestShortLogReport | tuple[str, str, str | tuple[str, Mapping[str, bool]]]: - """Return result-category, shortletter and verbose word for status - reporting. - - The result-category is a category in which to count the result, for - example "passed", "skipped", "error" or the empty string. - - The shortletter is shown as testing progresses, for example ".", "s", - "E" or the empty string. - - The verbose word is shown as testing progresses in verbose mode, for - example "PASSED", "SKIPPED", "ERROR" or the empty string. - - pytest may style these implicitly according to the report outcome. - To provide explicit styling, return a tuple for the verbose word, - for example ``"rerun", "R", ("RERUN", {"yellow": True})``. - - :param report: The report object whose status is to be returned. - :param config: The pytest config object. - :returns: The test status. - - Stops at first non-None result, see :ref:`firstresult`. - - Use in conftest plugins - ======================= - - Any conftest plugin can implement this hook. - """ - - -def pytest_terminal_summary( - terminalreporter: TerminalReporter, - exitstatus: ExitCode, - config: Config, -) -> None: - """Add a section to terminal summary reporting. - - :param terminalreporter: The internal terminal reporter object. - :param exitstatus: The exit status that will be reported back to the OS. - :param config: The pytest config object. - - .. versionadded:: 4.2 - The ``config`` parameter. - - Use in conftest plugins - ======================= - - Any conftest plugin can implement this hook. - """ - - -@hookspec(historic=True) -def pytest_warning_recorded( - warning_message: warnings.WarningMessage, - when: Literal["config", "collect", "runtest"], - nodeid: str, - location: tuple[str, int, str] | None, -) -> None: - """Process a warning captured by the internal pytest warnings plugin. - - :param warning_message: - The captured warning. This is the same object produced by :class:`warnings.catch_warnings`, - and contains the same attributes as the parameters of :py:func:`warnings.showwarning`. - - :param when: - Indicates when the warning was captured. Possible values: - - * ``"config"``: during pytest configuration/initialization stage. - * ``"collect"``: during test collection. - * ``"runtest"``: during test execution. - - :param nodeid: - Full id of the item. Empty string for warnings that are not specific to - a particular node. - - :param location: - When available, holds information about the execution context of the captured - warning (filename, linenumber, function). ``function`` evaluates to - when the execution context is at the module level. - - .. versionadded:: 6.0 - - Use in conftest plugins - ======================= - - Any conftest file can implement this hook. If the warning is specific to a - particular node, only conftest files in parent directories of the node are - consulted. - """ - - -# ------------------------------------------------------------------------- -# Hooks for influencing skipping -# ------------------------------------------------------------------------- - - -def pytest_markeval_namespace( # type:ignore[empty-body] - config: Config, -) -> dict[str, Any]: - """Called when constructing the globals dictionary used for - evaluating string conditions in xfail/skipif markers. - - This is useful when the condition for a marker requires - objects that are expensive or impossible to obtain during - collection time, which is required by normal boolean - conditions. - - .. versionadded:: 6.2 - - :param config: The pytest config object. - :returns: A dictionary of additional globals to add. - - Use in conftest plugins - ======================= - - Any conftest file can implement this hook. For a given item, only conftest - files in parent directories of the item are consulted. - """ - - -# ------------------------------------------------------------------------- -# error handling and internal debugging hooks -# ------------------------------------------------------------------------- - - -def pytest_internalerror( - excrepr: ExceptionRepr, - excinfo: ExceptionInfo[BaseException], -) -> bool | None: - """Called for internal errors. - - Return True to suppress the fallback handling of printing an - INTERNALERROR message directly to sys.stderr. - - :param excrepr: The exception repr object. - :param excinfo: The exception info. - - Use in conftest plugins - ======================= - - Any conftest plugin can implement this hook. - """ - - -def pytest_keyboard_interrupt( - excinfo: ExceptionInfo[KeyboardInterrupt | Exit], -) -> None: - """Called for keyboard interrupt. - - :param excinfo: The exception info. - - Use in conftest plugins - ======================= - - Any conftest plugin can implement this hook. - """ - - -def pytest_exception_interact( - node: Item | Collector, - call: CallInfo[Any], - report: CollectReport | TestReport, -) -> None: - """Called when an exception was raised which can potentially be - interactively handled. - - May be called during collection (see :hook:`pytest_make_collect_report`), - in which case ``report`` is a :class:`~pytest.CollectReport`. - - May be called during runtest of an item (see :hook:`pytest_runtest_protocol`), - in which case ``report`` is a :class:`~pytest.TestReport`. - - This hook is not called if the exception that was raised is an internal - exception like ``skip.Exception``. - - :param node: - The item or collector. - :param call: - The call information. Contains the exception. - :param report: - The collection or test report. - - Use in conftest plugins - ======================= - - Any conftest file can implement this hook. For a given node, only conftest - files in parent directories of the node are consulted. - """ - - -def pytest_enter_pdb(config: Config, pdb: pdb.Pdb) -> None: - """Called upon pdb.set_trace(). - - Can be used by plugins to take special action just before the python - debugger enters interactive mode. - - :param config: The pytest config object. - :param pdb: The Pdb instance. - - Use in conftest plugins - ======================= - - Any conftest plugin can implement this hook. - """ - - -def pytest_leave_pdb(config: Config, pdb: pdb.Pdb) -> None: - """Called when leaving pdb (e.g. with continue after pdb.set_trace()). - - Can be used by plugins to take special action just after the python - debugger leaves interactive mode. - - :param config: The pytest config object. - :param pdb: The Pdb instance. - - Use in conftest plugins - ======================= - - Any conftest plugin can implement this hook. - """ diff --git a/.venv/lib/python3.12/site-packages/_pytest/junitxml.py b/.venv/lib/python3.12/site-packages/_pytest/junitxml.py deleted file mode 100644 index ae8d2b9..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/junitxml.py +++ /dev/null @@ -1,695 +0,0 @@ -# mypy: allow-untyped-defs -"""Report test results in JUnit-XML format, for use with Jenkins and build -integration servers. - -Based on initial code from Ross Lawley. - -Output conforms to -https://github.com/jenkinsci/xunit-plugin/blob/master/src/main/resources/org/jenkinsci/plugins/xunit/types/model/xsd/junit-10.xsd -""" - -from __future__ import annotations - -from collections.abc import Callable -import functools -import os -import platform -import re -import xml.etree.ElementTree as ET - -from _pytest import nodes -from _pytest import timing -from _pytest._code.code import ExceptionRepr -from _pytest._code.code import ReprFileLocation -from _pytest.config import Config -from _pytest.config import filename_arg -from _pytest.config.argparsing import Parser -from _pytest.fixtures import FixtureRequest -from _pytest.reports import TestReport -from _pytest.stash import StashKey -from _pytest.terminal import TerminalReporter -import pytest - - -xml_key = StashKey["LogXML"]() - - -def bin_xml_escape(arg: object) -> str: - r"""Visually escape invalid XML characters. - - For example, transforms - 'hello\aworld\b' - into - 'hello#x07world#x08' - Note that the #xABs are *not* XML escapes - missing the ampersand «. - The idea is to escape visually for the user rather than for XML itself. - """ - - def repl(matchobj: re.Match[str]) -> str: - i = ord(matchobj.group()) - if i <= 0xFF: - return f"#x{i:02X}" - else: - return f"#x{i:04X}" - - # The spec range of valid chars is: - # Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] - # For an unknown(?) reason, we disallow #x7F (DEL) as well. - illegal_xml_re = ( - "[^\u0009\u000a\u000d\u0020-\u007e\u0080-\ud7ff\ue000-\ufffd\u10000-\u10ffff]" - ) - return re.sub(illegal_xml_re, repl, str(arg)) - - -def merge_family(left, right) -> None: - result = {} - for kl, vl in left.items(): - for kr, vr in right.items(): - if not isinstance(vl, list): - raise TypeError(type(vl)) - result[kl] = vl + vr - left.update(result) - - -families = { # pylint: disable=dict-init-mutate - "_base": {"testcase": ["classname", "name"]}, - "_base_legacy": {"testcase": ["file", "line", "url"]}, -} -# xUnit 1.x inherits legacy attributes. -families["xunit1"] = families["_base"].copy() -merge_family(families["xunit1"], families["_base_legacy"]) - -# xUnit 2.x uses strict base attributes. -families["xunit2"] = families["_base"] - - -class _NodeReporter: - def __init__(self, nodeid: str | TestReport, xml: LogXML) -> None: - self.id = nodeid - self.xml = xml - self.add_stats = self.xml.add_stats - self.family = self.xml.family - self.duration = 0.0 - self.properties: list[tuple[str, str]] = [] - self.nodes: list[ET.Element] = [] - self.attrs: dict[str, str] = {} - - def append(self, node: ET.Element) -> None: - self.xml.add_stats(node.tag) - self.nodes.append(node) - - def add_property(self, name: str, value: object) -> None: - self.properties.append((str(name), bin_xml_escape(value))) - - def add_attribute(self, name: str, value: object) -> None: - self.attrs[str(name)] = bin_xml_escape(value) - - def make_properties_node(self) -> ET.Element | None: - """Return a Junit node containing custom properties, if any.""" - if self.properties: - properties = ET.Element("properties") - for name, value in self.properties: - properties.append(ET.Element("property", name=name, value=value)) - return properties - return None - - def record_testreport(self, testreport: TestReport) -> None: - names = mangle_test_address(testreport.nodeid) - existing_attrs = self.attrs - classnames = names[:-1] - if self.xml.prefix: - classnames.insert(0, self.xml.prefix) - attrs: dict[str, str] = { - "classname": ".".join(classnames), - "name": bin_xml_escape(names[-1]), - "file": testreport.location[0], - } - if testreport.location[1] is not None: - attrs["line"] = str(testreport.location[1]) - if hasattr(testreport, "url"): - attrs["url"] = testreport.url - self.attrs = attrs - self.attrs.update(existing_attrs) # Restore any user-defined attributes. - - # Preserve legacy testcase behavior. - if self.family == "xunit1": - return - - # Filter out attributes not permitted by this test family. - # Including custom attributes because they are not valid here. - temp_attrs = {} - for key in self.attrs: - if key in families[self.family]["testcase"]: - temp_attrs[key] = self.attrs[key] - self.attrs = temp_attrs - - def to_xml(self) -> ET.Element: - testcase = ET.Element("testcase", self.attrs, time=f"{self.duration:.3f}") - properties = self.make_properties_node() - if properties is not None: - testcase.append(properties) - testcase.extend(self.nodes) - return testcase - - def _add_simple(self, tag: str, message: str, data: str | None = None) -> None: - node = ET.Element(tag, message=message) - node.text = bin_xml_escape(data) - self.append(node) - - def write_captured_output(self, report: TestReport) -> None: - if not self.xml.log_passing_tests and report.passed: - return - - content_out = report.capstdout - content_log = report.caplog - content_err = report.capstderr - if self.xml.logging == "no": - return - content_all = "" - if self.xml.logging in ["log", "all"]: - content_all = self._prepare_content(content_log, " Captured Log ") - if self.xml.logging in ["system-out", "out-err", "all"]: - content_all += self._prepare_content(content_out, " Captured Out ") - self._write_content(report, content_all, "system-out") - content_all = "" - if self.xml.logging in ["system-err", "out-err", "all"]: - content_all += self._prepare_content(content_err, " Captured Err ") - self._write_content(report, content_all, "system-err") - content_all = "" - if content_all: - self._write_content(report, content_all, "system-out") - - def _prepare_content(self, content: str, header: str) -> str: - return "\n".join([header.center(80, "-"), content, ""]) - - def _write_content(self, report: TestReport, content: str, jheader: str) -> None: - tag = ET.Element(jheader) - tag.text = bin_xml_escape(content) - self.append(tag) - - def append_pass(self, report: TestReport) -> None: - self.add_stats("passed") - - def append_failure(self, report: TestReport) -> None: - # msg = str(report.longrepr.reprtraceback.extraline) - if hasattr(report, "wasxfail"): - self._add_simple("skipped", "xfail-marked test passes unexpectedly") - else: - assert report.longrepr is not None - reprcrash: ReprFileLocation | None = getattr( - report.longrepr, "reprcrash", None - ) - if reprcrash is not None: - message = reprcrash.message - else: - message = str(report.longrepr) - message = bin_xml_escape(message) - self._add_simple("failure", message, str(report.longrepr)) - - def append_collect_error(self, report: TestReport) -> None: - # msg = str(report.longrepr.reprtraceback.extraline) - assert report.longrepr is not None - self._add_simple("error", "collection failure", str(report.longrepr)) - - def append_collect_skipped(self, report: TestReport) -> None: - self._add_simple("skipped", "collection skipped", str(report.longrepr)) - - def append_error(self, report: TestReport) -> None: - assert report.longrepr is not None - reprcrash: ReprFileLocation | None = getattr(report.longrepr, "reprcrash", None) - if reprcrash is not None: - reason = reprcrash.message - else: - reason = str(report.longrepr) - - if report.when == "teardown": - msg = f'failed on teardown with "{reason}"' - else: - msg = f'failed on setup with "{reason}"' - self._add_simple("error", bin_xml_escape(msg), str(report.longrepr)) - - def append_skipped(self, report: TestReport) -> None: - if hasattr(report, "wasxfail"): - xfailreason = report.wasxfail - if xfailreason.startswith("reason: "): - xfailreason = xfailreason[8:] - xfailreason = bin_xml_escape(xfailreason) - skipped = ET.Element("skipped", type="pytest.xfail", message=xfailreason) - self.append(skipped) - else: - assert isinstance(report.longrepr, tuple) - filename, lineno, skipreason = report.longrepr - if skipreason.startswith("Skipped: "): - skipreason = skipreason[9:] - details = f"{filename}:{lineno}: {skipreason}" - - skipped = ET.Element( - "skipped", type="pytest.skip", message=bin_xml_escape(skipreason) - ) - skipped.text = bin_xml_escape(details) - self.append(skipped) - self.write_captured_output(report) - - def finalize(self) -> None: - data = self.to_xml() - self.__dict__.clear() - # Type ignored because mypy doesn't like overriding a method. - # Also the return value doesn't match... - self.to_xml = lambda: data # type: ignore[method-assign] - - -def _warn_incompatibility_with_xunit2( - request: FixtureRequest, fixture_name: str -) -> None: - """Emit a PytestWarning about the given fixture being incompatible with newer xunit revisions.""" - from _pytest.warning_types import PytestWarning - - xml = request.config.stash.get(xml_key, None) - if xml is not None and xml.family not in ("xunit1", "legacy"): - request.node.warn( - PytestWarning( - f"{fixture_name} is incompatible with junit_family '{xml.family}' (use 'legacy' or 'xunit1')" - ) - ) - - -@pytest.fixture -def record_property(request: FixtureRequest) -> Callable[[str, object], None]: - """Add extra properties to the calling test. - - User properties become part of the test report and are available to the - configured reporters, like JUnit XML. - - The fixture is callable with ``name, value``. The value is automatically - XML-encoded. - - Example:: - - def test_function(record_property): - record_property("example_key", 1) - """ - _warn_incompatibility_with_xunit2(request, "record_property") - - def append_property(name: str, value: object) -> None: - request.node.user_properties.append((name, value)) - - return append_property - - -@pytest.fixture -def record_xml_attribute(request: FixtureRequest) -> Callable[[str, object], None]: - """Add extra xml attributes to the tag for the calling test. - - The fixture is callable with ``name, value``. The value is - automatically XML-encoded. - """ - from _pytest.warning_types import PytestExperimentalApiWarning - - request.node.warn( - PytestExperimentalApiWarning("record_xml_attribute is an experimental feature") - ) - - _warn_incompatibility_with_xunit2(request, "record_xml_attribute") - - # Declare noop - def add_attr_noop(name: str, value: object) -> None: - pass - - attr_func = add_attr_noop - - xml = request.config.stash.get(xml_key, None) - if xml is not None: - node_reporter = xml.node_reporter(request.node.nodeid) - attr_func = node_reporter.add_attribute - - return attr_func - - -def _check_record_param_type(param: str, v: str) -> None: - """Used by record_testsuite_property to check that the given parameter name is of the proper - type.""" - __tracebackhide__ = True - if not isinstance(v, str): - msg = "{param} parameter needs to be a string, but {g} given" # type: ignore[unreachable] - raise TypeError(msg.format(param=param, g=type(v).__name__)) - - -@pytest.fixture(scope="session") -def record_testsuite_property(request: FixtureRequest) -> Callable[[str, object], None]: - """Record a new ```` tag as child of the root ````. - - This is suitable to writing global information regarding the entire test - suite, and is compatible with ``xunit2`` JUnit family. - - This is a ``session``-scoped fixture which is called with ``(name, value)``. Example: - - .. code-block:: python - - def test_foo(record_testsuite_property): - record_testsuite_property("ARCH", "PPC") - record_testsuite_property("STORAGE_TYPE", "CEPH") - - :param name: - The property name. - :param value: - The property value. Will be converted to a string. - - .. warning:: - - Currently this fixture **does not work** with the - `pytest-xdist `__ plugin. See - :issue:`7767` for details. - """ - __tracebackhide__ = True - - def record_func(name: str, value: object) -> None: - """No-op function in case --junit-xml was not passed in the command-line.""" - __tracebackhide__ = True - _check_record_param_type("name", name) - - xml = request.config.stash.get(xml_key, None) - if xml is not None: - record_func = xml.add_global_property - return record_func - - -def pytest_addoption(parser: Parser) -> None: - group = parser.getgroup("terminal reporting") - group.addoption( - "--junitxml", - "--junit-xml", - action="store", - dest="xmlpath", - metavar="path", - type=functools.partial(filename_arg, optname="--junitxml"), - default=None, - help="Create junit-xml style report file at given path", - ) - group.addoption( - "--junitprefix", - "--junit-prefix", - action="store", - metavar="str", - default=None, - help="Prepend prefix to classnames in junit-xml output", - ) - parser.addini( - "junit_suite_name", "Test suite name for JUnit report", default="pytest" - ) - parser.addini( - "junit_logging", - "Write captured log messages to JUnit report: " - "one of no|log|system-out|system-err|out-err|all", - default="no", - ) - parser.addini( - "junit_log_passing_tests", - "Capture log information for passing tests to JUnit report: ", - type="bool", - default=True, - ) - parser.addini( - "junit_duration_report", - "Duration time to report: one of total|call", - default="total", - ) # choices=['total', 'call']) - parser.addini( - "junit_family", - "Emit XML for schema: one of legacy|xunit1|xunit2", - default="xunit2", - ) - - -def pytest_configure(config: Config) -> None: - xmlpath = config.option.xmlpath - # Prevent opening xmllog on worker nodes (xdist). - if xmlpath and not hasattr(config, "workerinput"): - junit_family = config.getini("junit_family") - config.stash[xml_key] = LogXML( - xmlpath, - config.option.junitprefix, - config.getini("junit_suite_name"), - config.getini("junit_logging"), - config.getini("junit_duration_report"), - junit_family, - config.getini("junit_log_passing_tests"), - ) - config.pluginmanager.register(config.stash[xml_key]) - - -def pytest_unconfigure(config: Config) -> None: - xml = config.stash.get(xml_key, None) - if xml: - del config.stash[xml_key] - config.pluginmanager.unregister(xml) - - -def mangle_test_address(address: str) -> list[str]: - path, possible_open_bracket, params = address.partition("[") - names = path.split("::") - # Convert file path to dotted path. - names[0] = names[0].replace(nodes.SEP, ".") - names[0] = re.sub(r"\.py$", "", names[0]) - # Put any params back. - names[-1] += possible_open_bracket + params - return names - - -class LogXML: - def __init__( - self, - logfile, - prefix: str | None, - suite_name: str = "pytest", - logging: str = "no", - report_duration: str = "total", - family="xunit1", - log_passing_tests: bool = True, - ) -> None: - logfile = os.path.expanduser(os.path.expandvars(logfile)) - self.logfile = os.path.normpath(os.path.abspath(logfile)) - self.prefix = prefix - self.suite_name = suite_name - self.logging = logging - self.log_passing_tests = log_passing_tests - self.report_duration = report_duration - self.family = family - self.stats: dict[str, int] = dict.fromkeys( - ["error", "passed", "failure", "skipped"], 0 - ) - self.node_reporters: dict[tuple[str | TestReport, object], _NodeReporter] = {} - self.node_reporters_ordered: list[_NodeReporter] = [] - self.global_properties: list[tuple[str, str]] = [] - - # List of reports that failed on call but teardown is pending. - self.open_reports: list[TestReport] = [] - self.cnt_double_fail_tests = 0 - - # Replaces convenience family with real family. - if self.family == "legacy": - self.family = "xunit1" - - def finalize(self, report: TestReport) -> None: - nodeid = getattr(report, "nodeid", report) - # Local hack to handle xdist report order. - workernode = getattr(report, "node", None) - reporter = self.node_reporters.pop((nodeid, workernode)) - - for propname, propvalue in report.user_properties: - reporter.add_property(propname, str(propvalue)) - - if reporter is not None: - reporter.finalize() - - def node_reporter(self, report: TestReport | str) -> _NodeReporter: - nodeid: str | TestReport = getattr(report, "nodeid", report) - # Local hack to handle xdist report order. - workernode = getattr(report, "node", None) - - key = nodeid, workernode - - if key in self.node_reporters: - # TODO: breaks for --dist=each - return self.node_reporters[key] - - reporter = _NodeReporter(nodeid, self) - - self.node_reporters[key] = reporter - self.node_reporters_ordered.append(reporter) - - return reporter - - def add_stats(self, key: str) -> None: - if key in self.stats: - self.stats[key] += 1 - - def _opentestcase(self, report: TestReport) -> _NodeReporter: - reporter = self.node_reporter(report) - reporter.record_testreport(report) - return reporter - - def pytest_runtest_logreport(self, report: TestReport) -> None: - """Handle a setup/call/teardown report, generating the appropriate - XML tags as necessary. - - Note: due to plugins like xdist, this hook may be called in interlaced - order with reports from other nodes. For example: - - Usual call order: - -> setup node1 - -> call node1 - -> teardown node1 - -> setup node2 - -> call node2 - -> teardown node2 - - Possible call order in xdist: - -> setup node1 - -> call node1 - -> setup node2 - -> call node2 - -> teardown node2 - -> teardown node1 - """ - close_report = None - if report.passed: - if report.when == "call": # ignore setup/teardown - reporter = self._opentestcase(report) - reporter.append_pass(report) - elif report.failed: - if report.when == "teardown": - # The following vars are needed when xdist plugin is used. - report_wid = getattr(report, "worker_id", None) - report_ii = getattr(report, "item_index", None) - close_report = next( - ( - rep - for rep in self.open_reports - if ( - rep.nodeid == report.nodeid - and getattr(rep, "item_index", None) == report_ii - and getattr(rep, "worker_id", None) == report_wid - ) - ), - None, - ) - if close_report: - # We need to open new testcase in case we have failure in - # call and error in teardown in order to follow junit - # schema. - self.finalize(close_report) - self.cnt_double_fail_tests += 1 - reporter = self._opentestcase(report) - if report.when == "call": - reporter.append_failure(report) - self.open_reports.append(report) - if not self.log_passing_tests: - reporter.write_captured_output(report) - else: - reporter.append_error(report) - elif report.skipped: - reporter = self._opentestcase(report) - reporter.append_skipped(report) - self.update_testcase_duration(report) - if report.when == "teardown": - reporter = self._opentestcase(report) - reporter.write_captured_output(report) - - self.finalize(report) - report_wid = getattr(report, "worker_id", None) - report_ii = getattr(report, "item_index", None) - close_report = next( - ( - rep - for rep in self.open_reports - if ( - rep.nodeid == report.nodeid - and getattr(rep, "item_index", None) == report_ii - and getattr(rep, "worker_id", None) == report_wid - ) - ), - None, - ) - if close_report: - self.open_reports.remove(close_report) - - def update_testcase_duration(self, report: TestReport) -> None: - """Accumulate total duration for nodeid from given report and update - the Junit.testcase with the new total if already created.""" - if self.report_duration in {"total", report.when}: - reporter = self.node_reporter(report) - reporter.duration += getattr(report, "duration", 0.0) - - def pytest_collectreport(self, report: TestReport) -> None: - if not report.passed: - reporter = self._opentestcase(report) - if report.failed: - reporter.append_collect_error(report) - else: - reporter.append_collect_skipped(report) - - def pytest_internalerror(self, excrepr: ExceptionRepr) -> None: - reporter = self.node_reporter("internal") - reporter.attrs.update(classname="pytest", name="internal") - reporter._add_simple("error", "internal error", str(excrepr)) - - def pytest_sessionstart(self) -> None: - self.suite_start = timing.Instant() - - def pytest_sessionfinish(self) -> None: - dirname = os.path.dirname(os.path.abspath(self.logfile)) - # exist_ok avoids filesystem race conditions between checking path existence and requesting creation - os.makedirs(dirname, exist_ok=True) - - with open(self.logfile, "w", encoding="utf-8") as logfile: - duration = self.suite_start.elapsed() - - numtests = ( - self.stats["passed"] - + self.stats["failure"] - + self.stats["skipped"] - + self.stats["error"] - - self.cnt_double_fail_tests - ) - logfile.write('') - - suite_node = ET.Element( - "testsuite", - name=self.suite_name, - errors=str(self.stats["error"]), - failures=str(self.stats["failure"]), - skipped=str(self.stats["skipped"]), - tests=str(numtests), - time=f"{duration.seconds:.3f}", - timestamp=self.suite_start.as_utc().astimezone().isoformat(), - hostname=platform.node(), - ) - global_properties = self._get_global_properties_node() - if global_properties is not None: - suite_node.append(global_properties) - for node_reporter in self.node_reporters_ordered: - suite_node.append(node_reporter.to_xml()) - testsuites = ET.Element("testsuites") - testsuites.set("name", "pytest tests") - testsuites.append(suite_node) - logfile.write(ET.tostring(testsuites, encoding="unicode")) - - def pytest_terminal_summary( - self, terminalreporter: TerminalReporter, config: pytest.Config - ) -> None: - if config.get_verbosity() >= 0: - terminalreporter.write_sep("-", f"generated xml file: {self.logfile}") - - def add_global_property(self, name: str, value: object) -> None: - __tracebackhide__ = True - _check_record_param_type("name", name) - self.global_properties.append((name, bin_xml_escape(value))) - - def _get_global_properties_node(self) -> ET.Element | None: - """Return a Junit node containing custom properties, if any.""" - if self.global_properties: - properties = ET.Element("properties") - for name, value in self.global_properties: - properties.append(ET.Element("property", name=name, value=value)) - return properties - return None diff --git a/.venv/lib/python3.12/site-packages/_pytest/legacypath.py b/.venv/lib/python3.12/site-packages/_pytest/legacypath.py deleted file mode 100644 index 59e8ef6..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/legacypath.py +++ /dev/null @@ -1,468 +0,0 @@ -# mypy: allow-untyped-defs -"""Add backward compatibility support for the legacy py path type.""" - -from __future__ import annotations - -import dataclasses -from pathlib import Path -import shlex -import subprocess -from typing import Final -from typing import final -from typing import TYPE_CHECKING - -from iniconfig import SectionWrapper - -from _pytest.cacheprovider import Cache -from _pytest.compat import LEGACY_PATH -from _pytest.compat import legacy_path -from _pytest.config import Config -from _pytest.config import hookimpl -from _pytest.config import PytestPluginManager -from _pytest.deprecated import check_ispytest -from _pytest.fixtures import fixture -from _pytest.fixtures import FixtureRequest -from _pytest.main import Session -from _pytest.monkeypatch import MonkeyPatch -from _pytest.nodes import Collector -from _pytest.nodes import Item -from _pytest.nodes import Node -from _pytest.pytester import HookRecorder -from _pytest.pytester import Pytester -from _pytest.pytester import RunResult -from _pytest.terminal import TerminalReporter -from _pytest.tmpdir import TempPathFactory - - -if TYPE_CHECKING: - import pexpect - - -@final -class Testdir: - """ - Similar to :class:`Pytester`, but this class works with legacy legacy_path objects instead. - - All methods just forward to an internal :class:`Pytester` instance, converting results - to `legacy_path` objects as necessary. - """ - - __test__ = False - - CLOSE_STDIN: Final = Pytester.CLOSE_STDIN - TimeoutExpired: Final = Pytester.TimeoutExpired - - def __init__(self, pytester: Pytester, *, _ispytest: bool = False) -> None: - check_ispytest(_ispytest) - self._pytester = pytester - - @property - def tmpdir(self) -> LEGACY_PATH: - """Temporary directory where tests are executed.""" - return legacy_path(self._pytester.path) - - @property - def test_tmproot(self) -> LEGACY_PATH: - return legacy_path(self._pytester._test_tmproot) - - @property - def request(self): - return self._pytester._request - - @property - def plugins(self): - return self._pytester.plugins - - @plugins.setter - def plugins(self, plugins): - self._pytester.plugins = plugins - - @property - def monkeypatch(self) -> MonkeyPatch: - return self._pytester._monkeypatch - - def make_hook_recorder(self, pluginmanager) -> HookRecorder: - """See :meth:`Pytester.make_hook_recorder`.""" - return self._pytester.make_hook_recorder(pluginmanager) - - def chdir(self) -> None: - """See :meth:`Pytester.chdir`.""" - return self._pytester.chdir() - - def finalize(self) -> None: - return self._pytester._finalize() - - def makefile(self, ext, *args, **kwargs) -> LEGACY_PATH: - """See :meth:`Pytester.makefile`.""" - if ext and not ext.startswith("."): - # pytester.makefile is going to throw a ValueError in a way that - # testdir.makefile did not, because - # pathlib.Path is stricter suffixes than py.path - # This ext arguments is likely user error, but since testdir has - # allowed this, we will prepend "." as a workaround to avoid breaking - # testdir usage that worked before - ext = "." + ext - return legacy_path(self._pytester.makefile(ext, *args, **kwargs)) - - def makeconftest(self, source) -> LEGACY_PATH: - """See :meth:`Pytester.makeconftest`.""" - return legacy_path(self._pytester.makeconftest(source)) - - def makeini(self, source) -> LEGACY_PATH: - """See :meth:`Pytester.makeini`.""" - return legacy_path(self._pytester.makeini(source)) - - def getinicfg(self, source: str) -> SectionWrapper: - """See :meth:`Pytester.getinicfg`.""" - return self._pytester.getinicfg(source) - - def makepyprojecttoml(self, source) -> LEGACY_PATH: - """See :meth:`Pytester.makepyprojecttoml`.""" - return legacy_path(self._pytester.makepyprojecttoml(source)) - - def makepyfile(self, *args, **kwargs) -> LEGACY_PATH: - """See :meth:`Pytester.makepyfile`.""" - return legacy_path(self._pytester.makepyfile(*args, **kwargs)) - - def maketxtfile(self, *args, **kwargs) -> LEGACY_PATH: - """See :meth:`Pytester.maketxtfile`.""" - return legacy_path(self._pytester.maketxtfile(*args, **kwargs)) - - def syspathinsert(self, path=None) -> None: - """See :meth:`Pytester.syspathinsert`.""" - return self._pytester.syspathinsert(path) - - def mkdir(self, name) -> LEGACY_PATH: - """See :meth:`Pytester.mkdir`.""" - return legacy_path(self._pytester.mkdir(name)) - - def mkpydir(self, name) -> LEGACY_PATH: - """See :meth:`Pytester.mkpydir`.""" - return legacy_path(self._pytester.mkpydir(name)) - - def copy_example(self, name=None) -> LEGACY_PATH: - """See :meth:`Pytester.copy_example`.""" - return legacy_path(self._pytester.copy_example(name)) - - def getnode(self, config: Config, arg) -> Item | Collector | None: - """See :meth:`Pytester.getnode`.""" - return self._pytester.getnode(config, arg) - - def getpathnode(self, path): - """See :meth:`Pytester.getpathnode`.""" - return self._pytester.getpathnode(path) - - def genitems(self, colitems: list[Item | Collector]) -> list[Item]: - """See :meth:`Pytester.genitems`.""" - return self._pytester.genitems(colitems) - - def runitem(self, source): - """See :meth:`Pytester.runitem`.""" - return self._pytester.runitem(source) - - def inline_runsource(self, source, *cmdlineargs): - """See :meth:`Pytester.inline_runsource`.""" - return self._pytester.inline_runsource(source, *cmdlineargs) - - def inline_genitems(self, *args): - """See :meth:`Pytester.inline_genitems`.""" - return self._pytester.inline_genitems(*args) - - def inline_run(self, *args, plugins=(), no_reraise_ctrlc: bool = False): - """See :meth:`Pytester.inline_run`.""" - return self._pytester.inline_run( - *args, plugins=plugins, no_reraise_ctrlc=no_reraise_ctrlc - ) - - def runpytest_inprocess(self, *args, **kwargs) -> RunResult: - """See :meth:`Pytester.runpytest_inprocess`.""" - return self._pytester.runpytest_inprocess(*args, **kwargs) - - def runpytest(self, *args, **kwargs) -> RunResult: - """See :meth:`Pytester.runpytest`.""" - return self._pytester.runpytest(*args, **kwargs) - - def parseconfig(self, *args) -> Config: - """See :meth:`Pytester.parseconfig`.""" - return self._pytester.parseconfig(*args) - - def parseconfigure(self, *args) -> Config: - """See :meth:`Pytester.parseconfigure`.""" - return self._pytester.parseconfigure(*args) - - def getitem(self, source, funcname="test_func"): - """See :meth:`Pytester.getitem`.""" - return self._pytester.getitem(source, funcname) - - def getitems(self, source): - """See :meth:`Pytester.getitems`.""" - return self._pytester.getitems(source) - - def getmodulecol(self, source, configargs=(), withinit=False): - """See :meth:`Pytester.getmodulecol`.""" - return self._pytester.getmodulecol( - source, configargs=configargs, withinit=withinit - ) - - def collect_by_name(self, modcol: Collector, name: str) -> Item | Collector | None: - """See :meth:`Pytester.collect_by_name`.""" - return self._pytester.collect_by_name(modcol, name) - - def popen( - self, - cmdargs, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - stdin=CLOSE_STDIN, - **kw, - ): - """See :meth:`Pytester.popen`.""" - return self._pytester.popen(cmdargs, stdout, stderr, stdin, **kw) - - def run(self, *cmdargs, timeout=None, stdin=CLOSE_STDIN) -> RunResult: - """See :meth:`Pytester.run`.""" - return self._pytester.run(*cmdargs, timeout=timeout, stdin=stdin) - - def runpython(self, script) -> RunResult: - """See :meth:`Pytester.runpython`.""" - return self._pytester.runpython(script) - - def runpython_c(self, command): - """See :meth:`Pytester.runpython_c`.""" - return self._pytester.runpython_c(command) - - def runpytest_subprocess(self, *args, timeout=None) -> RunResult: - """See :meth:`Pytester.runpytest_subprocess`.""" - return self._pytester.runpytest_subprocess(*args, timeout=timeout) - - def spawn_pytest(self, string: str, expect_timeout: float = 10.0) -> pexpect.spawn: - """See :meth:`Pytester.spawn_pytest`.""" - return self._pytester.spawn_pytest(string, expect_timeout=expect_timeout) - - def spawn(self, cmd: str, expect_timeout: float = 10.0) -> pexpect.spawn: - """See :meth:`Pytester.spawn`.""" - return self._pytester.spawn(cmd, expect_timeout=expect_timeout) - - def __repr__(self) -> str: - return f"" - - def __str__(self) -> str: - return str(self.tmpdir) - - -class LegacyTestdirPlugin: - @staticmethod - @fixture - def testdir(pytester: Pytester) -> Testdir: - """ - Identical to :fixture:`pytester`, and provides an instance whose methods return - legacy ``LEGACY_PATH`` objects instead when applicable. - - New code should avoid using :fixture:`testdir` in favor of :fixture:`pytester`. - """ - return Testdir(pytester, _ispytest=True) - - -@final -@dataclasses.dataclass -class TempdirFactory: - """Backward compatibility wrapper that implements ``py.path.local`` - for :class:`TempPathFactory`. - - .. note:: - These days, it is preferred to use ``tmp_path_factory``. - - :ref:`About the tmpdir and tmpdir_factory fixtures`. - - """ - - _tmppath_factory: TempPathFactory - - def __init__( - self, tmppath_factory: TempPathFactory, *, _ispytest: bool = False - ) -> None: - check_ispytest(_ispytest) - self._tmppath_factory = tmppath_factory - - def mktemp(self, basename: str, numbered: bool = True) -> LEGACY_PATH: - """Same as :meth:`TempPathFactory.mktemp`, but returns a ``py.path.local`` object.""" - return legacy_path(self._tmppath_factory.mktemp(basename, numbered).resolve()) - - def getbasetemp(self) -> LEGACY_PATH: - """Same as :meth:`TempPathFactory.getbasetemp`, but returns a ``py.path.local`` object.""" - return legacy_path(self._tmppath_factory.getbasetemp().resolve()) - - -class LegacyTmpdirPlugin: - @staticmethod - @fixture(scope="session") - def tmpdir_factory(request: FixtureRequest) -> TempdirFactory: - """Return a :class:`pytest.TempdirFactory` instance for the test session.""" - # Set dynamically by pytest_configure(). - return request.config._tmpdirhandler # type: ignore - - @staticmethod - @fixture - def tmpdir(tmp_path: Path) -> LEGACY_PATH: - """Return a temporary directory (as `legacy_path`_ object) - which is unique to each test function invocation. - The temporary directory is created as a subdirectory - of the base temporary directory, with configurable retention, - as discussed in :ref:`temporary directory location and retention`. - - .. note:: - These days, it is preferred to use ``tmp_path``. - - :ref:`About the tmpdir and tmpdir_factory fixtures`. - - .. _legacy_path: https://py.readthedocs.io/en/latest/path.html - """ - return legacy_path(tmp_path) - - -def Cache_makedir(self: Cache, name: str) -> LEGACY_PATH: - """Return a directory path object with the given name. - - Same as :func:`mkdir`, but returns a legacy py path instance. - """ - return legacy_path(self.mkdir(name)) - - -def FixtureRequest_fspath(self: FixtureRequest) -> LEGACY_PATH: - """(deprecated) The file system path of the test module which collected this test.""" - return legacy_path(self.path) - - -def TerminalReporter_startdir(self: TerminalReporter) -> LEGACY_PATH: - """The directory from which pytest was invoked. - - Prefer to use ``startpath`` which is a :class:`pathlib.Path`. - - :type: LEGACY_PATH - """ - return legacy_path(self.startpath) - - -def Config_invocation_dir(self: Config) -> LEGACY_PATH: - """The directory from which pytest was invoked. - - Prefer to use :attr:`invocation_params.dir `, - which is a :class:`pathlib.Path`. - - :type: LEGACY_PATH - """ - return legacy_path(str(self.invocation_params.dir)) - - -def Config_rootdir(self: Config) -> LEGACY_PATH: - """The path to the :ref:`rootdir `. - - Prefer to use :attr:`rootpath`, which is a :class:`pathlib.Path`. - - :type: LEGACY_PATH - """ - return legacy_path(str(self.rootpath)) - - -def Config_inifile(self: Config) -> LEGACY_PATH | None: - """The path to the :ref:`configfile `. - - Prefer to use :attr:`inipath`, which is a :class:`pathlib.Path`. - - :type: Optional[LEGACY_PATH] - """ - return legacy_path(str(self.inipath)) if self.inipath else None - - -def Session_startdir(self: Session) -> LEGACY_PATH: - """The path from which pytest was invoked. - - Prefer to use ``startpath`` which is a :class:`pathlib.Path`. - - :type: LEGACY_PATH - """ - return legacy_path(self.startpath) - - -def Config__getini_unknown_type(self, name: str, type: str, value: str | list[str]): - if type == "pathlist": - # TODO: This assert is probably not valid in all cases. - assert self.inipath is not None - dp = self.inipath.parent - input_values = shlex.split(value) if isinstance(value, str) else value - return [legacy_path(str(dp / x)) for x in input_values] - else: - raise ValueError(f"unknown configuration type: {type}", value) - - -def Node_fspath(self: Node) -> LEGACY_PATH: - """(deprecated) returns a legacy_path copy of self.path""" - return legacy_path(self.path) - - -def Node_fspath_set(self: Node, value: LEGACY_PATH) -> None: - self.path = Path(value) - - -@hookimpl(tryfirst=True) -def pytest_load_initial_conftests(early_config: Config) -> None: - """Monkeypatch legacy path attributes in several classes, as early as possible.""" - mp = MonkeyPatch() - early_config.add_cleanup(mp.undo) - - # Add Cache.makedir(). - mp.setattr(Cache, "makedir", Cache_makedir, raising=False) - - # Add FixtureRequest.fspath property. - mp.setattr(FixtureRequest, "fspath", property(FixtureRequest_fspath), raising=False) - - # Add TerminalReporter.startdir property. - mp.setattr( - TerminalReporter, "startdir", property(TerminalReporter_startdir), raising=False - ) - - # Add Config.{invocation_dir,rootdir,inifile} properties. - mp.setattr(Config, "invocation_dir", property(Config_invocation_dir), raising=False) - mp.setattr(Config, "rootdir", property(Config_rootdir), raising=False) - mp.setattr(Config, "inifile", property(Config_inifile), raising=False) - - # Add Session.startdir property. - mp.setattr(Session, "startdir", property(Session_startdir), raising=False) - - # Add pathlist configuration type. - mp.setattr(Config, "_getini_unknown_type", Config__getini_unknown_type) - - # Add Node.fspath property. - mp.setattr(Node, "fspath", property(Node_fspath, Node_fspath_set), raising=False) - - -@hookimpl -def pytest_configure(config: Config) -> None: - """Installs the LegacyTmpdirPlugin if the ``tmpdir`` plugin is also installed.""" - if config.pluginmanager.has_plugin("tmpdir"): - mp = MonkeyPatch() - config.add_cleanup(mp.undo) - # Create TmpdirFactory and attach it to the config object. - # - # This is to comply with existing plugins which expect the handler to be - # available at pytest_configure time, but ideally should be moved entirely - # to the tmpdir_factory session fixture. - try: - tmp_path_factory = config._tmp_path_factory # type: ignore[attr-defined] - except AttributeError: - # tmpdir plugin is blocked. - pass - else: - _tmpdirhandler = TempdirFactory(tmp_path_factory, _ispytest=True) - mp.setattr(config, "_tmpdirhandler", _tmpdirhandler, raising=False) - - config.pluginmanager.register(LegacyTmpdirPlugin, "legacypath-tmpdir") - - -@hookimpl -def pytest_plugin_registered(plugin: object, manager: PytestPluginManager) -> None: - # pytester is not loaded by default and is commonly loaded from a conftest, - # so checking for it in `pytest_configure` is not enough. - is_pytester = plugin is manager.get_plugin("pytester") - if is_pytester and not manager.is_registered(LegacyTestdirPlugin): - manager.register(LegacyTestdirPlugin, "legacypath-pytester") diff --git a/.venv/lib/python3.12/site-packages/_pytest/logging.py b/.venv/lib/python3.12/site-packages/_pytest/logging.py deleted file mode 100644 index e4fed57..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/logging.py +++ /dev/null @@ -1,960 +0,0 @@ -# mypy: allow-untyped-defs -"""Access and control log capturing.""" - -from __future__ import annotations - -from collections.abc import Generator -from collections.abc import Mapping -from collections.abc import Set as AbstractSet -from contextlib import contextmanager -from contextlib import nullcontext -from datetime import datetime -from datetime import timedelta -from datetime import timezone -import io -from io import StringIO -import logging -from logging import LogRecord -import os -from pathlib import Path -import re -from types import TracebackType -from typing import final -from typing import Generic -from typing import Literal -from typing import TYPE_CHECKING -from typing import TypeVar - -from _pytest import nodes -from _pytest._io import TerminalWriter -from _pytest.capture import CaptureManager -from _pytest.config import _strtobool -from _pytest.config import Config -from _pytest.config import create_terminal_writer -from _pytest.config import hookimpl -from _pytest.config import UsageError -from _pytest.config.argparsing import Parser -from _pytest.deprecated import check_ispytest -from _pytest.fixtures import fixture -from _pytest.fixtures import FixtureRequest -from _pytest.main import Session -from _pytest.stash import StashKey -from _pytest.terminal import TerminalReporter - - -if TYPE_CHECKING: - logging_StreamHandler = logging.StreamHandler[StringIO] -else: - logging_StreamHandler = logging.StreamHandler - -DEFAULT_LOG_FORMAT = "%(levelname)-8s %(name)s:%(filename)s:%(lineno)d %(message)s" -DEFAULT_LOG_DATE_FORMAT = "%H:%M:%S" -_ANSI_ESCAPE_SEQ = re.compile(r"\x1b\[[\d;]+m") -caplog_handler_key = StashKey["LogCaptureHandler"]() -caplog_records_key = StashKey[dict[str, list[logging.LogRecord]]]() - - -def _remove_ansi_escape_sequences(text: str) -> str: - return _ANSI_ESCAPE_SEQ.sub("", text) - - -class DatetimeFormatter(logging.Formatter): - """A logging formatter which formats record with - :func:`datetime.datetime.strftime` formatter instead of - :func:`time.strftime` in case of microseconds in format string. - """ - - def formatTime(self, record: LogRecord, datefmt: str | None = None) -> str: - if datefmt and "%f" in datefmt: - ct = self.converter(record.created) - tz = timezone(timedelta(seconds=ct.tm_gmtoff), ct.tm_zone) - # Construct `datetime.datetime` object from `struct_time` - # and msecs information from `record` - # Using int() instead of round() to avoid it exceeding 1_000_000 and causing a ValueError (#11861). - dt = datetime(*ct[0:6], microsecond=int(record.msecs * 1000), tzinfo=tz) - return dt.strftime(datefmt) - # Use `logging.Formatter` for non-microsecond formats - return super().formatTime(record, datefmt) - - -class ColoredLevelFormatter(DatetimeFormatter): - """A logging formatter which colorizes the %(levelname)..s part of the - log format passed to __init__.""" - - LOGLEVEL_COLOROPTS: Mapping[int, AbstractSet[str]] = { - logging.CRITICAL: {"red"}, - logging.ERROR: {"red", "bold"}, - logging.WARNING: {"yellow"}, - logging.WARN: {"yellow"}, - logging.INFO: {"green"}, - logging.DEBUG: {"purple"}, - logging.NOTSET: set(), - } - LEVELNAME_FMT_REGEX = re.compile(r"%\(levelname\)([+-.]?\d*(?:\.\d+)?s)") - - def __init__(self, terminalwriter: TerminalWriter, *args, **kwargs) -> None: - super().__init__(*args, **kwargs) - self._terminalwriter = terminalwriter - self._original_fmt = self._style._fmt - self._level_to_fmt_mapping: dict[int, str] = {} - - for level, color_opts in self.LOGLEVEL_COLOROPTS.items(): - self.add_color_level(level, *color_opts) - - def add_color_level(self, level: int, *color_opts: str) -> None: - """Add or update color opts for a log level. - - :param level: - Log level to apply a style to, e.g. ``logging.INFO``. - :param color_opts: - ANSI escape sequence color options. Capitalized colors indicates - background color, i.e. ``'green', 'Yellow', 'bold'`` will give bold - green text on yellow background. - - .. warning:: - This is an experimental API. - """ - assert self._fmt is not None - levelname_fmt_match = self.LEVELNAME_FMT_REGEX.search(self._fmt) - if not levelname_fmt_match: - return - levelname_fmt = levelname_fmt_match.group() - - formatted_levelname = levelname_fmt % {"levelname": logging.getLevelName(level)} - - # add ANSI escape sequences around the formatted levelname - color_kwargs = {name: True for name in color_opts} - colorized_formatted_levelname = self._terminalwriter.markup( - formatted_levelname, **color_kwargs - ) - self._level_to_fmt_mapping[level] = self.LEVELNAME_FMT_REGEX.sub( - colorized_formatted_levelname, self._fmt - ) - - def format(self, record: logging.LogRecord) -> str: - fmt = self._level_to_fmt_mapping.get(record.levelno, self._original_fmt) - self._style._fmt = fmt - return super().format(record) - - -class PercentStyleMultiline(logging.PercentStyle): - """A logging style with special support for multiline messages. - - If the message of a record consists of multiple lines, this style - formats the message as if each line were logged separately. - """ - - def __init__(self, fmt: str, auto_indent: int | str | bool | None) -> None: - super().__init__(fmt) - self._auto_indent = self._get_auto_indent(auto_indent) - - @staticmethod - def _get_auto_indent(auto_indent_option: int | str | bool | None) -> int: - """Determine the current auto indentation setting. - - Specify auto indent behavior (on/off/fixed) by passing in - extra={"auto_indent": [value]} to the call to logging.log() or - using a --log-auto-indent [value] command line or the - log_auto_indent [value] config option. - - Default behavior is auto-indent off. - - Using the string "True" or "on" or the boolean True as the value - turns auto indent on, using the string "False" or "off" or the - boolean False or the int 0 turns it off, and specifying a - positive integer fixes the indentation position to the value - specified. - - Any other values for the option are invalid, and will silently be - converted to the default. - - :param None|bool|int|str auto_indent_option: - User specified option for indentation from command line, config - or extra kwarg. Accepts int, bool or str. str option accepts the - same range of values as boolean config options, as well as - positive integers represented in str form. - - :returns: - Indentation value, which can be - -1 (automatically determine indentation) or - 0 (auto-indent turned off) or - >0 (explicitly set indentation position). - """ - if auto_indent_option is None: - return 0 - elif isinstance(auto_indent_option, bool): - if auto_indent_option: - return -1 - else: - return 0 - elif isinstance(auto_indent_option, int): - return int(auto_indent_option) - elif isinstance(auto_indent_option, str): - try: - return int(auto_indent_option) - except ValueError: - pass - try: - if _strtobool(auto_indent_option): - return -1 - except ValueError: - return 0 - - return 0 - - def format(self, record: logging.LogRecord) -> str: - if "\n" in record.message: - if hasattr(record, "auto_indent"): - # Passed in from the "extra={}" kwarg on the call to logging.log(). - auto_indent = self._get_auto_indent(record.auto_indent) - else: - auto_indent = self._auto_indent - - if auto_indent: - lines = record.message.splitlines() - formatted = self._fmt % {**record.__dict__, "message": lines[0]} - - if auto_indent < 0: - indentation = _remove_ansi_escape_sequences(formatted).find( - lines[0] - ) - else: - # Optimizes logging by allowing a fixed indentation. - indentation = auto_indent - lines[0] = formatted - return ("\n" + " " * indentation).join(lines) - return self._fmt % record.__dict__ - - -def get_option_ini(config: Config, *names: str): - for name in names: - ret = config.getoption(name) # 'default' arg won't work as expected - if ret is None: - ret = config.getini(name) - if ret: - return ret - - -def pytest_addoption(parser: Parser) -> None: - """Add options to control log capturing.""" - group = parser.getgroup("logging") - - def add_option_ini(option, dest, default=None, type=None, **kwargs): - parser.addini( - dest, default=default, type=type, help="Default value for " + option - ) - group.addoption(option, dest=dest, **kwargs) - - add_option_ini( - "--log-level", - dest="log_level", - default=None, - metavar="LEVEL", - help=( - "Level of messages to catch/display." - " Not set by default, so it depends on the root/parent log handler's" - ' effective level, where it is "WARNING" by default.' - ), - ) - add_option_ini( - "--log-format", - dest="log_format", - default=DEFAULT_LOG_FORMAT, - help="Log format used by the logging module", - ) - add_option_ini( - "--log-date-format", - dest="log_date_format", - default=DEFAULT_LOG_DATE_FORMAT, - help="Log date format used by the logging module", - ) - parser.addini( - "log_cli", - default=False, - type="bool", - help='Enable log display during test run (also known as "live logging")', - ) - add_option_ini( - "--log-cli-level", dest="log_cli_level", default=None, help="CLI logging level" - ) - add_option_ini( - "--log-cli-format", - dest="log_cli_format", - default=None, - help="Log format used by the logging module", - ) - add_option_ini( - "--log-cli-date-format", - dest="log_cli_date_format", - default=None, - help="Log date format used by the logging module", - ) - add_option_ini( - "--log-file", - dest="log_file", - default=None, - help="Path to a file when logging will be written to", - ) - add_option_ini( - "--log-file-mode", - dest="log_file_mode", - default="w", - choices=["w", "a"], - help="Log file open mode", - ) - add_option_ini( - "--log-file-level", - dest="log_file_level", - default=None, - help="Log file logging level", - ) - add_option_ini( - "--log-file-format", - dest="log_file_format", - default=None, - help="Log format used by the logging module", - ) - add_option_ini( - "--log-file-date-format", - dest="log_file_date_format", - default=None, - help="Log date format used by the logging module", - ) - add_option_ini( - "--log-auto-indent", - dest="log_auto_indent", - default=None, - help="Auto-indent multiline messages passed to the logging module. Accepts true|on, false|off or an integer.", - ) - group.addoption( - "--log-disable", - action="append", - default=[], - dest="logger_disable", - help="Disable a logger by name. Can be passed multiple times.", - ) - - -_HandlerType = TypeVar("_HandlerType", bound=logging.Handler) - - -# Not using @contextmanager for performance reasons. -class catching_logs(Generic[_HandlerType]): - """Context manager that prepares the whole logging machinery properly.""" - - __slots__ = ("handler", "level", "orig_level") - - def __init__(self, handler: _HandlerType, level: int | None = None) -> None: - self.handler = handler - self.level = level - - def __enter__(self) -> _HandlerType: - root_logger = logging.getLogger() - if self.level is not None: - self.handler.setLevel(self.level) - root_logger.addHandler(self.handler) - if self.level is not None: - self.orig_level = root_logger.level - root_logger.setLevel(min(self.orig_level, self.level)) - return self.handler - - def __exit__( - self, - exc_type: type[BaseException] | None, - exc_val: BaseException | None, - exc_tb: TracebackType | None, - ) -> None: - root_logger = logging.getLogger() - if self.level is not None: - root_logger.setLevel(self.orig_level) - root_logger.removeHandler(self.handler) - - -class LogCaptureHandler(logging_StreamHandler): - """A logging handler that stores log records and the log text.""" - - def __init__(self) -> None: - """Create a new log handler.""" - super().__init__(StringIO()) - self.records: list[logging.LogRecord] = [] - - def emit(self, record: logging.LogRecord) -> None: - """Keep the log records in a list in addition to the log text.""" - self.records.append(record) - super().emit(record) - - def reset(self) -> None: - self.records = [] - self.stream = StringIO() - - def clear(self) -> None: - self.records.clear() - self.stream = StringIO() - - def handleError(self, record: logging.LogRecord) -> None: - if logging.raiseExceptions: - # Fail the test if the log message is bad (emit failed). - # The default behavior of logging is to print "Logging error" - # to stderr with the call stack and some extra details. - # pytest wants to make such mistakes visible during testing. - raise # noqa: PLE0704 - - -@final -class LogCaptureFixture: - """Provides access and control of log capturing.""" - - def __init__(self, item: nodes.Node, *, _ispytest: bool = False) -> None: - check_ispytest(_ispytest) - self._item = item - self._initial_handler_level: int | None = None - # Dict of log name -> log level. - self._initial_logger_levels: dict[str | None, int] = {} - self._initial_disabled_logging_level: int | None = None - - def _finalize(self) -> None: - """Finalize the fixture. - - This restores the log levels and the disabled logging levels changed by :meth:`set_level`. - """ - # Restore log levels. - if self._initial_handler_level is not None: - self.handler.setLevel(self._initial_handler_level) - for logger_name, level in self._initial_logger_levels.items(): - logger = logging.getLogger(logger_name) - logger.setLevel(level) - # Disable logging at the original disabled logging level. - if self._initial_disabled_logging_level is not None: - logging.disable(self._initial_disabled_logging_level) - self._initial_disabled_logging_level = None - - @property - def handler(self) -> LogCaptureHandler: - """Get the logging handler used by the fixture.""" - return self._item.stash[caplog_handler_key] - - def get_records( - self, when: Literal["setup", "call", "teardown"] - ) -> list[logging.LogRecord]: - """Get the logging records for one of the possible test phases. - - :param when: - Which test phase to obtain the records from. - Valid values are: "setup", "call" and "teardown". - - :returns: The list of captured records at the given stage. - - .. versionadded:: 3.4 - """ - return self._item.stash[caplog_records_key].get(when, []) - - @property - def text(self) -> str: - """The formatted log text.""" - return _remove_ansi_escape_sequences(self.handler.stream.getvalue()) - - @property - def records(self) -> list[logging.LogRecord]: - """The list of log records.""" - return self.handler.records - - @property - def record_tuples(self) -> list[tuple[str, int, str]]: - """A list of a stripped down version of log records intended - for use in assertion comparison. - - The format of the tuple is: - - (logger_name, log_level, message) - """ - return [(r.name, r.levelno, r.getMessage()) for r in self.records] - - @property - def messages(self) -> list[str]: - """A list of format-interpolated log messages. - - Unlike 'records', which contains the format string and parameters for - interpolation, log messages in this list are all interpolated. - - Unlike 'text', which contains the output from the handler, log - messages in this list are unadorned with levels, timestamps, etc, - making exact comparisons more reliable. - - Note that traceback or stack info (from :func:`logging.exception` or - the `exc_info` or `stack_info` arguments to the logging functions) is - not included, as this is added by the formatter in the handler. - - .. versionadded:: 3.7 - """ - return [r.getMessage() for r in self.records] - - def clear(self) -> None: - """Reset the list of log records and the captured log text.""" - self.handler.clear() - - def _force_enable_logging( - self, level: int | str, logger_obj: logging.Logger - ) -> int: - """Enable the desired logging level if the global level was disabled via ``logging.disabled``. - - Only enables logging levels greater than or equal to the requested ``level``. - - Does nothing if the desired ``level`` wasn't disabled. - - :param level: - The logger level caplog should capture. - All logging is enabled if a non-standard logging level string is supplied. - Valid level strings are in :data:`logging._nameToLevel`. - :param logger_obj: The logger object to check. - - :return: The original disabled logging level. - """ - original_disable_level: int = logger_obj.manager.disable - - if isinstance(level, str): - # Try to translate the level string to an int for `logging.disable()` - level = logging.getLevelName(level) - - if not isinstance(level, int): - # The level provided was not valid, so just un-disable all logging. - logging.disable(logging.NOTSET) - elif not logger_obj.isEnabledFor(level): - # Each level is `10` away from other levels. - # https://docs.python.org/3/library/logging.html#logging-levels - disable_level = max(level - 10, logging.NOTSET) - logging.disable(disable_level) - - return original_disable_level - - def set_level(self, level: int | str, logger: str | None = None) -> None: - """Set the threshold level of a logger for the duration of a test. - - Logging messages which are less severe than this level will not be captured. - - .. versionchanged:: 3.4 - The levels of the loggers changed by this function will be - restored to their initial values at the end of the test. - - Will enable the requested logging level if it was disabled via :func:`logging.disable`. - - :param level: The level. - :param logger: The logger to update. If not given, the root logger. - """ - logger_obj = logging.getLogger(logger) - # Save the original log-level to restore it during teardown. - self._initial_logger_levels.setdefault(logger, logger_obj.level) - logger_obj.setLevel(level) - if self._initial_handler_level is None: - self._initial_handler_level = self.handler.level - self.handler.setLevel(level) - initial_disabled_logging_level = self._force_enable_logging(level, logger_obj) - if self._initial_disabled_logging_level is None: - self._initial_disabled_logging_level = initial_disabled_logging_level - - @contextmanager - def at_level(self, level: int | str, logger: str | None = None) -> Generator[None]: - """Context manager that sets the level for capturing of logs. After - the end of the 'with' statement the level is restored to its original - value. - - Will enable the requested logging level if it was disabled via :func:`logging.disable`. - - :param level: The level. - :param logger: The logger to update. If not given, the root logger. - """ - logger_obj = logging.getLogger(logger) - orig_level = logger_obj.level - logger_obj.setLevel(level) - handler_orig_level = self.handler.level - self.handler.setLevel(level) - original_disable_level = self._force_enable_logging(level, logger_obj) - try: - yield - finally: - logger_obj.setLevel(orig_level) - self.handler.setLevel(handler_orig_level) - logging.disable(original_disable_level) - - @contextmanager - def filtering(self, filter_: logging.Filter) -> Generator[None]: - """Context manager that temporarily adds the given filter to the caplog's - :meth:`handler` for the 'with' statement block, and removes that filter at the - end of the block. - - :param filter_: A custom :class:`logging.Filter` object. - - .. versionadded:: 7.5 - """ - self.handler.addFilter(filter_) - try: - yield - finally: - self.handler.removeFilter(filter_) - - -@fixture -def caplog(request: FixtureRequest) -> Generator[LogCaptureFixture]: - """Access and control log capturing. - - Captured logs are available through the following properties/methods:: - - * caplog.messages -> list of format-interpolated log messages - * caplog.text -> string containing formatted log output - * caplog.records -> list of logging.LogRecord instances - * caplog.record_tuples -> list of (logger_name, level, message) tuples - * caplog.clear() -> clear captured records and formatted log output string - """ - result = LogCaptureFixture(request.node, _ispytest=True) - yield result - result._finalize() - - -def get_log_level_for_setting(config: Config, *setting_names: str) -> int | None: - for setting_name in setting_names: - log_level = config.getoption(setting_name) - if log_level is None: - log_level = config.getini(setting_name) - if log_level: - break - else: - return None - - if isinstance(log_level, str): - log_level = log_level.upper() - try: - return int(getattr(logging, log_level, log_level)) - except ValueError as e: - # Python logging does not recognise this as a logging level - raise UsageError( - f"'{log_level}' is not recognized as a logging level name for " - f"'{setting_name}'. Please consider passing the " - "logging level num instead." - ) from e - - -# run after terminalreporter/capturemanager are configured -@hookimpl(trylast=True) -def pytest_configure(config: Config) -> None: - config.pluginmanager.register(LoggingPlugin(config), "logging-plugin") - - -class LoggingPlugin: - """Attaches to the logging module and captures log messages for each test.""" - - def __init__(self, config: Config) -> None: - """Create a new plugin to capture log messages. - - The formatter can be safely shared across all handlers so - create a single one for the entire test session here. - """ - self._config = config - - # Report logging. - self.formatter = self._create_formatter( - get_option_ini(config, "log_format"), - get_option_ini(config, "log_date_format"), - get_option_ini(config, "log_auto_indent"), - ) - self.log_level = get_log_level_for_setting(config, "log_level") - self.caplog_handler = LogCaptureHandler() - self.caplog_handler.setFormatter(self.formatter) - self.report_handler = LogCaptureHandler() - self.report_handler.setFormatter(self.formatter) - - # File logging. - self.log_file_level = get_log_level_for_setting( - config, "log_file_level", "log_level" - ) - log_file = get_option_ini(config, "log_file") or os.devnull - if log_file != os.devnull: - directory = os.path.dirname(os.path.abspath(log_file)) - if not os.path.isdir(directory): - os.makedirs(directory) - - self.log_file_mode = get_option_ini(config, "log_file_mode") or "w" - self.log_file_handler = _FileHandler( - log_file, mode=self.log_file_mode, encoding="UTF-8" - ) - log_file_format = get_option_ini(config, "log_file_format", "log_format") - log_file_date_format = get_option_ini( - config, "log_file_date_format", "log_date_format" - ) - - log_file_formatter = DatetimeFormatter( - log_file_format, datefmt=log_file_date_format - ) - self.log_file_handler.setFormatter(log_file_formatter) - - # CLI/live logging. - self.log_cli_level = get_log_level_for_setting( - config, "log_cli_level", "log_level" - ) - if self._log_cli_enabled(): - terminal_reporter = config.pluginmanager.get_plugin("terminalreporter") - # Guaranteed by `_log_cli_enabled()`. - assert terminal_reporter is not None - capture_manager = config.pluginmanager.get_plugin("capturemanager") - # if capturemanager plugin is disabled, live logging still works. - self.log_cli_handler: ( - _LiveLoggingStreamHandler | _LiveLoggingNullHandler - ) = _LiveLoggingStreamHandler(terminal_reporter, capture_manager) - else: - self.log_cli_handler = _LiveLoggingNullHandler() - log_cli_formatter = self._create_formatter( - get_option_ini(config, "log_cli_format", "log_format"), - get_option_ini(config, "log_cli_date_format", "log_date_format"), - get_option_ini(config, "log_auto_indent"), - ) - self.log_cli_handler.setFormatter(log_cli_formatter) - self._disable_loggers(loggers_to_disable=config.option.logger_disable) - - def _disable_loggers(self, loggers_to_disable: list[str]) -> None: - if not loggers_to_disable: - return - - for name in loggers_to_disable: - logger = logging.getLogger(name) - logger.disabled = True - - def _create_formatter(self, log_format, log_date_format, auto_indent): - # Color option doesn't exist if terminal plugin is disabled. - color = getattr(self._config.option, "color", "no") - if color != "no" and ColoredLevelFormatter.LEVELNAME_FMT_REGEX.search( - log_format - ): - formatter: logging.Formatter = ColoredLevelFormatter( - create_terminal_writer(self._config), log_format, log_date_format - ) - else: - formatter = DatetimeFormatter(log_format, log_date_format) - - formatter._style = PercentStyleMultiline( - formatter._style._fmt, auto_indent=auto_indent - ) - - return formatter - - def set_log_path(self, fname: str) -> None: - """Set the filename parameter for Logging.FileHandler(). - - Creates parent directory if it does not exist. - - .. warning:: - This is an experimental API. - """ - fpath = Path(fname) - - if not fpath.is_absolute(): - fpath = self._config.rootpath / fpath - - if not fpath.parent.exists(): - fpath.parent.mkdir(exist_ok=True, parents=True) - - # https://github.com/python/mypy/issues/11193 - stream: io.TextIOWrapper = fpath.open(mode=self.log_file_mode, encoding="UTF-8") # type: ignore[assignment] - old_stream = self.log_file_handler.setStream(stream) - if old_stream: - old_stream.close() - - def _log_cli_enabled(self) -> bool: - """Return whether live logging is enabled.""" - enabled = self._config.getoption( - "--log-cli-level" - ) is not None or self._config.getini("log_cli") - if not enabled: - return False - - terminal_reporter = self._config.pluginmanager.get_plugin("terminalreporter") - if terminal_reporter is None: - # terminal reporter is disabled e.g. by pytest-xdist. - return False - - return True - - @hookimpl(wrapper=True, tryfirst=True) - def pytest_sessionstart(self) -> Generator[None]: - self.log_cli_handler.set_when("sessionstart") - - with catching_logs(self.log_cli_handler, level=self.log_cli_level): - with catching_logs(self.log_file_handler, level=self.log_file_level): - return (yield) - - @hookimpl(wrapper=True, tryfirst=True) - def pytest_collection(self) -> Generator[None]: - self.log_cli_handler.set_when("collection") - - with catching_logs(self.log_cli_handler, level=self.log_cli_level): - with catching_logs(self.log_file_handler, level=self.log_file_level): - return (yield) - - @hookimpl(wrapper=True) - def pytest_runtestloop(self, session: Session) -> Generator[None, object, object]: - if session.config.option.collectonly: - return (yield) - - if self._log_cli_enabled() and self._config.get_verbosity() < 1: - # The verbose flag is needed to avoid messy test progress output. - self._config.option.verbose = 1 - - with catching_logs(self.log_cli_handler, level=self.log_cli_level): - with catching_logs(self.log_file_handler, level=self.log_file_level): - return (yield) # Run all the tests. - - @hookimpl - def pytest_runtest_logstart(self) -> None: - self.log_cli_handler.reset() - self.log_cli_handler.set_when("start") - - @hookimpl - def pytest_runtest_logreport(self) -> None: - self.log_cli_handler.set_when("logreport") - - @contextmanager - def _runtest_for(self, item: nodes.Item, when: str) -> Generator[None]: - """Implement the internals of the pytest_runtest_xxx() hooks.""" - with ( - catching_logs( - self.caplog_handler, - level=self.log_level, - ) as caplog_handler, - catching_logs( - self.report_handler, - level=self.log_level, - ) as report_handler, - ): - caplog_handler.reset() - report_handler.reset() - item.stash[caplog_records_key][when] = caplog_handler.records - item.stash[caplog_handler_key] = caplog_handler - - try: - yield - finally: - log = report_handler.stream.getvalue().strip() - item.add_report_section(when, "log", log) - - @hookimpl(wrapper=True) - def pytest_runtest_setup(self, item: nodes.Item) -> Generator[None]: - self.log_cli_handler.set_when("setup") - - empty: dict[str, list[logging.LogRecord]] = {} - item.stash[caplog_records_key] = empty - with self._runtest_for(item, "setup"): - yield - - @hookimpl(wrapper=True) - def pytest_runtest_call(self, item: nodes.Item) -> Generator[None]: - self.log_cli_handler.set_when("call") - - with self._runtest_for(item, "call"): - yield - - @hookimpl(wrapper=True) - def pytest_runtest_teardown(self, item: nodes.Item) -> Generator[None]: - self.log_cli_handler.set_when("teardown") - - try: - with self._runtest_for(item, "teardown"): - yield - finally: - del item.stash[caplog_records_key] - del item.stash[caplog_handler_key] - - @hookimpl - def pytest_runtest_logfinish(self) -> None: - self.log_cli_handler.set_when("finish") - - @hookimpl(wrapper=True, tryfirst=True) - def pytest_sessionfinish(self) -> Generator[None]: - self.log_cli_handler.set_when("sessionfinish") - - with catching_logs(self.log_cli_handler, level=self.log_cli_level): - with catching_logs(self.log_file_handler, level=self.log_file_level): - return (yield) - - @hookimpl - def pytest_unconfigure(self) -> None: - # Close the FileHandler explicitly. - # (logging.shutdown might have lost the weakref?!) - self.log_file_handler.close() - - -class _FileHandler(logging.FileHandler): - """A logging FileHandler with pytest tweaks.""" - - def handleError(self, record: logging.LogRecord) -> None: - # Handled by LogCaptureHandler. - pass - - -class _LiveLoggingStreamHandler(logging_StreamHandler): - """A logging StreamHandler used by the live logging feature: it will - write a newline before the first log message in each test. - - During live logging we must also explicitly disable stdout/stderr - capturing otherwise it will get captured and won't appear in the - terminal. - """ - - # Officially stream needs to be a IO[str], but TerminalReporter - # isn't. So force it. - stream: TerminalReporter = None # type: ignore - - def __init__( - self, - terminal_reporter: TerminalReporter, - capture_manager: CaptureManager | None, - ) -> None: - super().__init__(stream=terminal_reporter) # type: ignore[arg-type] - self.capture_manager = capture_manager - self.reset() - self.set_when(None) - self._test_outcome_written = False - - def reset(self) -> None: - """Reset the handler; should be called before the start of each test.""" - self._first_record_emitted = False - - def set_when(self, when: str | None) -> None: - """Prepare for the given test phase (setup/call/teardown).""" - self._when = when - self._section_name_shown = False - if when == "start": - self._test_outcome_written = False - - def emit(self, record: logging.LogRecord) -> None: - ctx_manager = ( - self.capture_manager.global_and_fixture_disabled() - if self.capture_manager - else nullcontext() - ) - with ctx_manager: - if not self._first_record_emitted: - self.stream.write("\n") - self._first_record_emitted = True - elif self._when in ("teardown", "finish"): - if not self._test_outcome_written: - self._test_outcome_written = True - self.stream.write("\n") - if not self._section_name_shown and self._when: - self.stream.section("live log " + self._when, sep="-", bold=True) - self._section_name_shown = True - super().emit(record) - - def handleError(self, record: logging.LogRecord) -> None: - # Handled by LogCaptureHandler. - pass - - -class _LiveLoggingNullHandler(logging.NullHandler): - """A logging handler used when live logging is disabled.""" - - def reset(self) -> None: - pass - - def set_when(self, when: str) -> None: - pass - - def handleError(self, record: logging.LogRecord) -> None: - # Handled by LogCaptureHandler. - pass diff --git a/.venv/lib/python3.12/site-packages/_pytest/main.py b/.venv/lib/python3.12/site-packages/_pytest/main.py deleted file mode 100644 index 9bc930d..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/main.py +++ /dev/null @@ -1,1203 +0,0 @@ -"""Core implementation of the testing process: init, session, runtest loop.""" - -from __future__ import annotations - -import argparse -from collections.abc import Callable -from collections.abc import Iterable -from collections.abc import Iterator -from collections.abc import Sequence -from collections.abc import Set as AbstractSet -import dataclasses -import fnmatch -import functools -import importlib -import importlib.util -import os -from pathlib import Path -import sys -from typing import final -from typing import Literal -from typing import overload -from typing import TYPE_CHECKING -import warnings - -import pluggy - -from _pytest import nodes -import _pytest._code -from _pytest.config import Config -from _pytest.config import directory_arg -from _pytest.config import ExitCode -from _pytest.config import hookimpl -from _pytest.config import PytestPluginManager -from _pytest.config import UsageError -from _pytest.config.argparsing import OverrideIniAction -from _pytest.config.argparsing import Parser -from _pytest.config.compat import PathAwareHookProxy -from _pytest.outcomes import exit -from _pytest.pathlib import absolutepath -from _pytest.pathlib import bestrelpath -from _pytest.pathlib import fnmatch_ex -from _pytest.pathlib import safe_exists -from _pytest.pathlib import samefile_nofollow -from _pytest.pathlib import scandir -from _pytest.reports import CollectReport -from _pytest.reports import TestReport -from _pytest.runner import collect_one_node -from _pytest.runner import SetupState -from _pytest.warning_types import PytestWarning - - -if TYPE_CHECKING: - from typing_extensions import Self - - from _pytest.fixtures import FixtureManager - - -def pytest_addoption(parser: Parser) -> None: - group = parser.getgroup("general") - group._addoption( # private to use reserved lower-case short option - "-x", - "--exitfirst", - action="store_const", - dest="maxfail", - const=1, - help="Exit instantly on first error or failed test", - ) - group.addoption( - "--maxfail", - metavar="num", - action="store", - type=int, - dest="maxfail", - default=0, - help="Exit after first num failures or errors", - ) - group.addoption( - "--strict-config", - action=OverrideIniAction, - ini_option="strict_config", - ini_value="true", - help="Enables the strict_config option", - ) - group.addoption( - "--strict-markers", - action=OverrideIniAction, - ini_option="strict_markers", - ini_value="true", - help="Enables the strict_markers option", - ) - group.addoption( - "--strict", - action=OverrideIniAction, - ini_option="strict", - ini_value="true", - help="Enables the strict option", - ) - parser.addini( - "strict_config", - "Any warnings encountered while parsing the `pytest` section of the " - "configuration file raise errors", - type="bool", - # None => fallback to `strict`. - default=None, - ) - parser.addini( - "strict_markers", - "Markers not registered in the `markers` section of the configuration " - "file raise errors", - type="bool", - # None => fallback to `strict`. - default=None, - ) - parser.addini( - "strict", - "Enables all strictness options, currently: " - "strict_config, strict_markers, strict_xfail, strict_parametrization_ids", - type="bool", - default=False, - ) - - group = parser.getgroup("pytest-warnings") - group.addoption( - "-W", - "--pythonwarnings", - action="append", - help="Set which warnings to report, see -W option of Python itself", - ) - parser.addini( - "filterwarnings", - type="linelist", - help="Each line specifies a pattern for " - "warnings.filterwarnings. " - "Processed after -W/--pythonwarnings.", - ) - - group = parser.getgroup("collect", "collection") - group.addoption( - "--collectonly", - "--collect-only", - "--co", - action="store_true", - help="Only collect tests, don't execute them", - ) - group.addoption( - "--pyargs", - action="store_true", - help="Try to interpret all arguments as Python packages", - ) - group.addoption( - "--ignore", - action="append", - metavar="path", - help="Ignore path during collection (multi-allowed)", - ) - group.addoption( - "--ignore-glob", - action="append", - metavar="path", - help="Ignore path pattern during collection (multi-allowed)", - ) - group.addoption( - "--deselect", - action="append", - metavar="nodeid_prefix", - help="Deselect item (via node id prefix) during collection (multi-allowed)", - ) - group.addoption( - "--confcutdir", - dest="confcutdir", - default=None, - metavar="dir", - type=functools.partial(directory_arg, optname="--confcutdir"), - help="Only load conftest.py's relative to specified dir", - ) - group.addoption( - "--noconftest", - action="store_true", - dest="noconftest", - default=False, - help="Don't load any conftest.py files", - ) - group.addoption( - "--keepduplicates", - "--keep-duplicates", - action="store_true", - dest="keepduplicates", - default=False, - help="Keep duplicate tests", - ) - group.addoption( - "--collect-in-virtualenv", - action="store_true", - dest="collect_in_virtualenv", - default=False, - help="Don't ignore tests in a local virtualenv directory", - ) - group.addoption( - "--continue-on-collection-errors", - action="store_true", - default=False, - dest="continue_on_collection_errors", - help="Force test execution even if collection errors occur", - ) - group.addoption( - "--import-mode", - default="prepend", - choices=["prepend", "append", "importlib"], - dest="importmode", - help="Prepend/append to sys.path when importing test modules and conftest " - "files. Default: prepend.", - ) - parser.addini( - "norecursedirs", - "Directory patterns to avoid for recursion", - type="args", - default=[ - "*.egg", - ".*", - "_darcs", - "build", - "CVS", - "dist", - "node_modules", - "venv", - "{arch}", - ], - ) - parser.addini( - "testpaths", - "Directories to search for tests when no files or directories are given on the " - "command line", - type="args", - default=[], - ) - parser.addini( - "collect_imported_tests", - "Whether to collect tests in imported modules outside `testpaths`", - type="bool", - default=True, - ) - parser.addini( - "consider_namespace_packages", - type="bool", - default=False, - help="Consider namespace packages when resolving module names during import", - ) - - group = parser.getgroup("debugconfig", "test session debugging and configuration") - group._addoption( # private to use reserved lower-case short option - "-c", - "--config-file", - metavar="FILE", - type=str, - dest="inifilename", - help="Load configuration from `FILE` instead of trying to locate one of the " - "implicit configuration files.", - ) - group.addoption( - "--rootdir", - action="store", - dest="rootdir", - help="Define root directory for tests. Can be relative path: 'root_dir', './root_dir', " - "'root_dir/another_dir/'; absolute path: '/home/user/root_dir'; path with variables: " - "'$HOME/root_dir'.", - ) - group.addoption( - "--basetemp", - dest="basetemp", - default=None, - type=validate_basetemp, - metavar="dir", - help=( - "Base temporary directory for this test run. " - "(Warning: this directory is removed if it exists.)" - ), - ) - - -def validate_basetemp(path: str) -> str: - # GH 7119 - msg = "basetemp must not be empty, the current working directory or any parent directory of it" - - # empty path - if not path: - raise argparse.ArgumentTypeError(msg) - - def is_ancestor(base: Path, query: Path) -> bool: - """Return whether query is an ancestor of base.""" - if base == query: - return True - return query in base.parents - - # check if path is an ancestor of cwd - if is_ancestor(Path.cwd(), Path(path).absolute()): - raise argparse.ArgumentTypeError(msg) - - # check symlinks for ancestors - if is_ancestor(Path.cwd().resolve(), Path(path).resolve()): - raise argparse.ArgumentTypeError(msg) - - return path - - -def wrap_session( - config: Config, doit: Callable[[Config, Session], int | ExitCode | None] -) -> int | ExitCode: - """Skeleton command line program.""" - session = Session.from_config(config) - session.exitstatus = ExitCode.OK - initstate = 0 - try: - try: - config._do_configure() - initstate = 1 - config.hook.pytest_sessionstart(session=session) - initstate = 2 - session.exitstatus = doit(config, session) or 0 - except UsageError: - session.exitstatus = ExitCode.USAGE_ERROR - raise - except Failed: - session.exitstatus = ExitCode.TESTS_FAILED - except (KeyboardInterrupt, exit.Exception): - excinfo = _pytest._code.ExceptionInfo.from_current() - exitstatus: int | ExitCode = ExitCode.INTERRUPTED - if isinstance(excinfo.value, exit.Exception): - if excinfo.value.returncode is not None: - exitstatus = excinfo.value.returncode - if initstate < 2: - sys.stderr.write(f"{excinfo.typename}: {excinfo.value.msg}\n") - config.hook.pytest_keyboard_interrupt(excinfo=excinfo) - session.exitstatus = exitstatus - except BaseException: - session.exitstatus = ExitCode.INTERNAL_ERROR - excinfo = _pytest._code.ExceptionInfo.from_current() - try: - config.notify_exception(excinfo, config.option) - except exit.Exception as exc: - if exc.returncode is not None: - session.exitstatus = exc.returncode - sys.stderr.write(f"{type(exc).__name__}: {exc}\n") - else: - if isinstance(excinfo.value, SystemExit): - sys.stderr.write("mainloop: caught unexpected SystemExit!\n") - - finally: - # Explicitly break reference cycle. - excinfo = None # type: ignore - os.chdir(session.startpath) - if initstate >= 2: - try: - config.hook.pytest_sessionfinish( - session=session, exitstatus=session.exitstatus - ) - except exit.Exception as exc: - if exc.returncode is not None: - session.exitstatus = exc.returncode - sys.stderr.write(f"{type(exc).__name__}: {exc}\n") - config._ensure_unconfigure() - return session.exitstatus - - -def pytest_cmdline_main(config: Config) -> int | ExitCode: - return wrap_session(config, _main) - - -def _main(config: Config, session: Session) -> int | ExitCode | None: - """Default command line protocol for initialization, session, - running tests and reporting.""" - config.hook.pytest_collection(session=session) - config.hook.pytest_runtestloop(session=session) - - if session.testsfailed: - return ExitCode.TESTS_FAILED - elif session.testscollected == 0: - return ExitCode.NO_TESTS_COLLECTED - return None - - -def pytest_collection(session: Session) -> None: - session.perform_collect() - - -def pytest_runtestloop(session: Session) -> bool: - if session.testsfailed and not session.config.option.continue_on_collection_errors: - raise session.Interrupted( - f"{session.testsfailed} error{'s' if session.testsfailed != 1 else ''} during collection" - ) - - if session.config.option.collectonly: - return True - - for i, item in enumerate(session.items): - nextitem = session.items[i + 1] if i + 1 < len(session.items) else None - item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem) - if session.shouldfail: - raise session.Failed(session.shouldfail) - if session.shouldstop: - raise session.Interrupted(session.shouldstop) - return True - - -def _in_venv(path: Path) -> bool: - """Attempt to detect if ``path`` is the root of a Virtual Environment by - checking for the existence of the pyvenv.cfg file. - - [https://peps.python.org/pep-0405/] - - For regression protection we also check for conda environments that do not include pyenv.cfg yet -- - https://github.com/conda/conda/issues/13337 is the conda issue tracking adding pyenv.cfg. - - Checking for the `conda-meta/history` file per https://github.com/pytest-dev/pytest/issues/12652#issuecomment-2246336902. - - """ - try: - return ( - path.joinpath("pyvenv.cfg").is_file() - or path.joinpath("conda-meta", "history").is_file() - ) - except OSError: - return False - - -def pytest_ignore_collect(collection_path: Path, config: Config) -> bool | None: - if collection_path.name == "__pycache__": - return True - - ignore_paths = config._getconftest_pathlist( - "collect_ignore", path=collection_path.parent - ) - ignore_paths = ignore_paths or [] - excludeopt = config.getoption("ignore") - if excludeopt: - ignore_paths.extend(absolutepath(x) for x in excludeopt) - - if collection_path in ignore_paths: - return True - - ignore_globs = config._getconftest_pathlist( - "collect_ignore_glob", path=collection_path.parent - ) - ignore_globs = ignore_globs or [] - excludeglobopt = config.getoption("ignore_glob") - if excludeglobopt: - ignore_globs.extend(absolutepath(x) for x in excludeglobopt) - - if any(fnmatch.fnmatch(str(collection_path), str(glob)) for glob in ignore_globs): - return True - - allow_in_venv = config.getoption("collect_in_virtualenv") - if not allow_in_venv and _in_venv(collection_path): - return True - - if collection_path.is_dir(): - norecursepatterns = config.getini("norecursedirs") - if any(fnmatch_ex(pat, collection_path) for pat in norecursepatterns): - return True - - return None - - -def pytest_collect_directory( - path: Path, parent: nodes.Collector -) -> nodes.Collector | None: - return Dir.from_parent(parent, path=path) - - -def pytest_collection_modifyitems(items: list[nodes.Item], config: Config) -> None: - deselect_prefixes = tuple(config.getoption("deselect") or []) - if not deselect_prefixes: - return - - remaining = [] - deselected = [] - for colitem in items: - if colitem.nodeid.startswith(deselect_prefixes): - deselected.append(colitem) - else: - remaining.append(colitem) - - if deselected: - config.hook.pytest_deselected(items=deselected) - items[:] = remaining - - -class FSHookProxy: - def __init__( - self, - pm: PytestPluginManager, - remove_mods: AbstractSet[object], - ) -> None: - self.pm = pm - self.remove_mods = remove_mods - - def __getattr__(self, name: str) -> pluggy.HookCaller: - x = self.pm.subset_hook_caller(name, remove_plugins=self.remove_mods) - self.__dict__[name] = x - return x - - -class Interrupted(KeyboardInterrupt): - """Signals that the test run was interrupted.""" - - __module__ = "builtins" # For py3. - - -class Failed(Exception): - """Signals a stop as failed test run.""" - - -@dataclasses.dataclass -class _bestrelpath_cache(dict[Path, str]): - __slots__ = ("path",) - - path: Path - - def __missing__(self, path: Path) -> str: - r = bestrelpath(self.path, path) - self[path] = r - return r - - -@final -class Dir(nodes.Directory): - """Collector of files in a file system directory. - - .. versionadded:: 8.0 - - .. note:: - - Python directories with an `__init__.py` file are instead collected by - :class:`~pytest.Package` by default. Both are :class:`~pytest.Directory` - collectors. - """ - - @classmethod - def from_parent( # type: ignore[override] - cls, - parent: nodes.Collector, - *, - path: Path, - ) -> Self: - """The public constructor. - - :param parent: The parent collector of this Dir. - :param path: The directory's path. - :type path: pathlib.Path - """ - return super().from_parent(parent=parent, path=path) - - def collect(self) -> Iterable[nodes.Item | nodes.Collector]: - config = self.config - col: nodes.Collector | None - cols: Sequence[nodes.Collector] - ihook = self.ihook - for direntry in scandir(self.path): - if direntry.is_dir(): - path = Path(direntry.path) - if not self.session.isinitpath(path, with_parents=True): - if ihook.pytest_ignore_collect(collection_path=path, config=config): - continue - col = ihook.pytest_collect_directory(path=path, parent=self) - if col is not None: - yield col - - elif direntry.is_file(): - path = Path(direntry.path) - if not self.session.isinitpath(path): - if ihook.pytest_ignore_collect(collection_path=path, config=config): - continue - cols = ihook.pytest_collect_file(file_path=path, parent=self) - yield from cols - - -@final -class Session(nodes.Collector): - """The root of the collection tree. - - ``Session`` collects the initial paths given as arguments to pytest. - """ - - Interrupted = Interrupted - Failed = Failed - # Set on the session by runner.pytest_sessionstart. - _setupstate: SetupState - # Set on the session by fixtures.pytest_sessionstart. - _fixturemanager: FixtureManager - exitstatus: int | ExitCode - - def __init__(self, config: Config) -> None: - super().__init__( - name="", - path=config.rootpath, - fspath=None, - parent=None, - config=config, - session=self, - nodeid="", - ) - self.testsfailed = 0 - self.testscollected = 0 - self._shouldstop: bool | str = False - self._shouldfail: bool | str = False - self.trace = config.trace.root.get("collection") - self._initialpaths: frozenset[Path] = frozenset() - self._initialpaths_with_parents: frozenset[Path] = frozenset() - self._notfound: list[tuple[str, Sequence[nodes.Collector]]] = [] - self._initial_parts: list[CollectionArgument] = [] - self._collection_cache: dict[nodes.Collector, CollectReport] = {} - self.items: list[nodes.Item] = [] - - self._bestrelpathcache: dict[Path, str] = _bestrelpath_cache(config.rootpath) - - self.config.pluginmanager.register(self, name="session") - - @classmethod - def from_config(cls, config: Config) -> Session: - session: Session = cls._create(config=config) - return session - - def __repr__(self) -> str: - return ( - f"<{self.__class__.__name__} {self.name} " - f"exitstatus=%r " - f"testsfailed={self.testsfailed} " - f"testscollected={self.testscollected}>" - ) % getattr(self, "exitstatus", "") - - @property - def shouldstop(self) -> bool | str: - return self._shouldstop - - @shouldstop.setter - def shouldstop(self, value: bool | str) -> None: - # The runner checks shouldfail and assumes that if it is set we are - # definitely stopping, so prevent unsetting it. - if value is False and self._shouldstop: - warnings.warn( - PytestWarning( - "session.shouldstop cannot be unset after it has been set; ignoring." - ), - stacklevel=2, - ) - return - self._shouldstop = value - - @property - def shouldfail(self) -> bool | str: - return self._shouldfail - - @shouldfail.setter - def shouldfail(self, value: bool | str) -> None: - # The runner checks shouldfail and assumes that if it is set we are - # definitely stopping, so prevent unsetting it. - if value is False and self._shouldfail: - warnings.warn( - PytestWarning( - "session.shouldfail cannot be unset after it has been set; ignoring." - ), - stacklevel=2, - ) - return - self._shouldfail = value - - @property - def startpath(self) -> Path: - """The path from which pytest was invoked. - - .. versionadded:: 7.0.0 - """ - return self.config.invocation_params.dir - - def _node_location_to_relpath(self, node_path: Path) -> str: - # bestrelpath is a quite slow function. - return self._bestrelpathcache[node_path] - - @hookimpl(tryfirst=True) - def pytest_collectstart(self) -> None: - if self.shouldfail: - raise self.Failed(self.shouldfail) - if self.shouldstop: - raise self.Interrupted(self.shouldstop) - - @hookimpl(tryfirst=True) - def pytest_runtest_logreport(self, report: TestReport | CollectReport) -> None: - if report.failed and not hasattr(report, "wasxfail"): - self.testsfailed += 1 - maxfail = self.config.getvalue("maxfail") - if maxfail and self.testsfailed >= maxfail: - self.shouldfail = f"stopping after {self.testsfailed} failures" - - pytest_collectreport = pytest_runtest_logreport - - def isinitpath( - self, - path: str | os.PathLike[str], - *, - with_parents: bool = False, - ) -> bool: - """Is path an initial path? - - An initial path is a path explicitly given to pytest on the command - line. - - :param with_parents: - If set, also return True if the path is a parent of an initial path. - - .. versionchanged:: 8.0 - Added the ``with_parents`` parameter. - """ - # Optimization: Path(Path(...)) is much slower than isinstance. - path_ = path if isinstance(path, Path) else Path(path) - if with_parents: - return path_ in self._initialpaths_with_parents - else: - return path_ in self._initialpaths - - def gethookproxy(self, fspath: os.PathLike[str]) -> pluggy.HookRelay: - # Optimization: Path(Path(...)) is much slower than isinstance. - path = fspath if isinstance(fspath, Path) else Path(fspath) - pm = self.config.pluginmanager - # Check if we have the common case of running - # hooks with all conftest.py files. - my_conftestmodules = pm._getconftestmodules(path) - remove_mods = pm._conftest_plugins.difference(my_conftestmodules) - proxy: pluggy.HookRelay - if remove_mods: - # One or more conftests are not in use at this path. - proxy = PathAwareHookProxy(FSHookProxy(pm, remove_mods)) # type: ignore[arg-type,assignment] - else: - # All plugins are active for this fspath. - proxy = self.config.hook - return proxy - - def _collect_path( - self, - path: Path, - path_cache: dict[Path, Sequence[nodes.Collector]], - ) -> Sequence[nodes.Collector]: - """Create a Collector for the given path. - - `path_cache` makes it so the same Collectors are returned for the same - path. - """ - if path in path_cache: - return path_cache[path] - - if path.is_dir(): - ihook = self.gethookproxy(path.parent) - col: nodes.Collector | None = ihook.pytest_collect_directory( - path=path, parent=self - ) - cols: Sequence[nodes.Collector] = (col,) if col is not None else () - - elif path.is_file(): - ihook = self.gethookproxy(path) - cols = ihook.pytest_collect_file(file_path=path, parent=self) - - else: - # Broken symlink or invalid/missing file. - cols = () - - path_cache[path] = cols - return cols - - @overload - def perform_collect( - self, args: Sequence[str] | None = ..., genitems: Literal[True] = ... - ) -> Sequence[nodes.Item]: ... - - @overload - def perform_collect( - self, args: Sequence[str] | None = ..., genitems: bool = ... - ) -> Sequence[nodes.Item | nodes.Collector]: ... - - def perform_collect( - self, args: Sequence[str] | None = None, genitems: bool = True - ) -> Sequence[nodes.Item | nodes.Collector]: - """Perform the collection phase for this session. - - This is called by the default :hook:`pytest_collection` hook - implementation; see the documentation of this hook for more details. - For testing purposes, it may also be called directly on a fresh - ``Session``. - - This function normally recursively expands any collectors collected - from the session to their items, and only items are returned. For - testing purposes, this may be suppressed by passing ``genitems=False``, - in which case the return value contains these collectors unexpanded, - and ``session.items`` is empty. - """ - if args is None: - args = self.config.args - - self.trace("perform_collect", self, args) - self.trace.root.indent += 1 - - hook = self.config.hook - - self._notfound = [] - self._initial_parts = [] - self._collection_cache = {} - self.items = [] - items: Sequence[nodes.Item | nodes.Collector] = self.items - consider_namespace_packages: bool = self.config.getini( - "consider_namespace_packages" - ) - try: - initialpaths: list[Path] = [] - initialpaths_with_parents: list[Path] = [] - - collection_args = [ - resolve_collection_argument( - self.config.invocation_params.dir, - arg, - i, - as_pypath=self.config.option.pyargs, - consider_namespace_packages=consider_namespace_packages, - ) - for i, arg in enumerate(args) - ] - - if not self.config.getoption("keepduplicates"): - # Normalize the collection arguments -- remove duplicates and overlaps. - self._initial_parts = normalize_collection_arguments(collection_args) - else: - self._initial_parts = collection_args - - for collection_argument in self._initial_parts: - initialpaths.append(collection_argument.path) - initialpaths_with_parents.append(collection_argument.path) - initialpaths_with_parents.extend(collection_argument.path.parents) - self._initialpaths = frozenset(initialpaths) - self._initialpaths_with_parents = frozenset(initialpaths_with_parents) - - rep = collect_one_node(self) - self.ihook.pytest_collectreport(report=rep) - self.trace.root.indent -= 1 - if self._notfound: - errors = [] - for arg, collectors in self._notfound: - if collectors: - errors.append( - f"not found: {arg}\n(no match in any of {collectors!r})" - ) - else: - errors.append(f"found no collectors for {arg}") - - raise UsageError(*errors) - - if not genitems: - items = rep.result - else: - if rep.passed: - for node in rep.result: - self.items.extend(self.genitems(node)) - - self.config.pluginmanager.check_pending() - hook.pytest_collection_modifyitems( - session=self, config=self.config, items=items - ) - finally: - self._notfound = [] - self._initial_parts = [] - self._collection_cache = {} - hook.pytest_collection_finish(session=self) - - if genitems: - self.testscollected = len(items) - - return items - - def _collect_one_node( - self, - node: nodes.Collector, - handle_dupes: bool = True, - ) -> tuple[CollectReport, bool]: - if node in self._collection_cache and handle_dupes: - rep = self._collection_cache[node] - return rep, True - else: - rep = collect_one_node(node) - self._collection_cache[node] = rep - return rep, False - - def collect(self) -> Iterator[nodes.Item | nodes.Collector]: - # This is a cache for the root directories of the initial paths. - # We can't use collection_cache for Session because of its special - # role as the bootstrapping collector. - path_cache: dict[Path, Sequence[nodes.Collector]] = {} - - pm = self.config.pluginmanager - - for collection_argument in self._initial_parts: - self.trace("processing argument", collection_argument) - self.trace.root.indent += 1 - - argpath = collection_argument.path - names = collection_argument.parts - parametrization = collection_argument.parametrization - module_name = collection_argument.module_name - - # resolve_collection_argument() ensures this. - if argpath.is_dir(): - assert not names, f"invalid arg {(argpath, names)!r}" - - paths = [argpath] - # Add relevant parents of the path, from the root, e.g. - # /a/b/c.py -> [/, /a, /a/b, /a/b/c.py] - if module_name is None: - # Paths outside of the confcutdir should not be considered. - for path in argpath.parents: - if not pm._is_in_confcutdir(path): - break - paths.insert(0, path) - else: - # For --pyargs arguments, only consider paths matching the module - # name. Paths beyond the package hierarchy are not included. - module_name_parts = module_name.split(".") - for i, path in enumerate(argpath.parents, 2): - if i > len(module_name_parts) or path.stem != module_name_parts[-i]: - break - paths.insert(0, path) - - # Start going over the parts from the root, collecting each level - # and discarding all nodes which don't match the level's part. - any_matched_in_initial_part = False - notfound_collectors = [] - work: list[tuple[nodes.Collector | nodes.Item, list[Path | str]]] = [ - (self, [*paths, *names]) - ] - while work: - matchnode, matchparts = work.pop() - - # Pop'd all of the parts, this is a match. - if not matchparts: - yield matchnode - any_matched_in_initial_part = True - continue - - # Should have been matched by now, discard. - if not isinstance(matchnode, nodes.Collector): - continue - - # Collect this level of matching. - # Collecting Session (self) is done directly to avoid endless - # recursion to this function. - subnodes: Sequence[nodes.Collector | nodes.Item] - if isinstance(matchnode, Session): - assert isinstance(matchparts[0], Path) - subnodes = matchnode._collect_path(matchparts[0], path_cache) - else: - # For backward compat, files given directly multiple - # times on the command line should not be deduplicated. - handle_dupes = not ( - len(matchparts) == 1 - and isinstance(matchparts[0], Path) - and matchparts[0].is_file() - ) - rep, duplicate = self._collect_one_node(matchnode, handle_dupes) - if not duplicate and not rep.passed: - # Report collection failures here to avoid failing to - # run some test specified in the command line because - # the module could not be imported (#134). - matchnode.ihook.pytest_collectreport(report=rep) - if not rep.passed: - continue - subnodes = rep.result - - # Prune this level. - any_matched_in_collector = False - for node in reversed(subnodes): - # Path part e.g. `/a/b/` in `/a/b/test_file.py::TestIt::test_it`. - if isinstance(matchparts[0], Path): - is_match = node.path == matchparts[0] - if sys.platform == "win32" and not is_match: - # In case the file paths do not match, fallback to samefile() to - # account for short-paths on Windows (#11895). But use a version - # which doesn't resolve symlinks, otherwise we might match the - # same file more than once (#12039). - is_match = samefile_nofollow(node.path, matchparts[0]) - - # Name part e.g. `TestIt` in `/a/b/test_file.py::TestIt::test_it`. - else: - if len(matchparts) == 1: - # This the last part, one parametrization goes. - if parametrization is not None: - # A parametrized arg must match exactly. - is_match = node.name == matchparts[0] + parametrization - else: - # A non-parameterized arg matches all parametrizations (if any). - # TODO: Remove the hacky split once the collection structure - # contains parametrization. - is_match = node.name.split("[")[0] == matchparts[0] - else: - is_match = node.name == matchparts[0] - if is_match: - work.append((node, matchparts[1:])) - any_matched_in_collector = True - - if not any_matched_in_collector: - notfound_collectors.append(matchnode) - - if not any_matched_in_initial_part: - report_arg = "::".join((str(argpath), *names)) - self._notfound.append((report_arg, notfound_collectors)) - - self.trace.root.indent -= 1 - - def genitems(self, node: nodes.Item | nodes.Collector) -> Iterator[nodes.Item]: - self.trace("genitems", node) - if isinstance(node, nodes.Item): - node.ihook.pytest_itemcollected(item=node) - yield node - else: - assert isinstance(node, nodes.Collector) - # For backward compat, dedup only applies to files. - handle_dupes = not isinstance(node, nodes.File) - rep, duplicate = self._collect_one_node(node, handle_dupes) - if rep.passed: - for subnode in rep.result: - yield from self.genitems(subnode) - if not duplicate: - node.ihook.pytest_collectreport(report=rep) - - -def search_pypath( - module_name: str, *, consider_namespace_packages: bool = False -) -> str | None: - """Search sys.path for the given a dotted module name, and return its file - system path if found.""" - try: - spec = importlib.util.find_spec(module_name) - # AttributeError: looks like package module, but actually filename - # ImportError: module does not exist - # ValueError: not a module name - except (AttributeError, ImportError, ValueError): - return None - - if spec is None: - return None - - if ( - spec.submodule_search_locations is None - or len(spec.submodule_search_locations) == 0 - ): - # Must be a simple module. - return spec.origin - - if consider_namespace_packages: - # If submodule_search_locations is set, it's a package (regular or namespace). - # Typically there is a single entry, but documentation claims it can be empty too - # (e.g. if the package has no physical location). - return spec.submodule_search_locations[0] - - if spec.origin is None: - # This is only the case for namespace packages - return None - - return os.path.dirname(spec.origin) - - -@dataclasses.dataclass(frozen=True) -class CollectionArgument: - """A resolved collection argument.""" - - path: Path - parts: Sequence[str] - parametrization: str | None - module_name: str | None - original_index: int - - -def resolve_collection_argument( - invocation_path: Path, - arg: str, - arg_index: int, - *, - as_pypath: bool = False, - consider_namespace_packages: bool = False, -) -> CollectionArgument: - """Parse path arguments optionally containing selection parts and return (fspath, names). - - Command-line arguments can point to files and/or directories, and optionally contain - parts for specific tests selection, for example: - - "pkg/tests/test_foo.py::TestClass::test_foo" - - This function ensures the path exists, and returns a resolved `CollectionArgument`: - - CollectionArgument( - path=Path("/full/path/to/pkg/tests/test_foo.py"), - parts=["TestClass", "test_foo"], - module_name=None, - ) - - When as_pypath is True, expects that the command-line argument actually contains - module paths instead of file-system paths: - - "pkg.tests.test_foo::TestClass::test_foo[a,b]" - - In which case we search sys.path for a matching module, and then return the *path* to the - found module, which may look like this: - - CollectionArgument( - path=Path("/home/u/myvenv/lib/site-packages/pkg/tests/test_foo.py"), - parts=["TestClass", "test_foo"], - parametrization="[a,b]", - module_name="pkg.tests.test_foo", - ) - - If the path doesn't exist, raise UsageError. - If the path is a directory and selection parts are present, raise UsageError. - """ - base, squacket, rest = arg.partition("[") - strpath, *parts = base.split("::") - if squacket and not parts: - raise UsageError(f"path cannot contain [] parametrization: {arg}") - parametrization = f"{squacket}{rest}" if squacket else None - module_name = None - if as_pypath: - pyarg_strpath = search_pypath( - strpath, consider_namespace_packages=consider_namespace_packages - ) - if pyarg_strpath is not None: - module_name = strpath - strpath = pyarg_strpath - fspath = invocation_path / strpath - fspath = absolutepath(fspath) - if not safe_exists(fspath): - msg = ( - "module or package not found: {arg} (missing __init__.py?)" - if as_pypath - else "file or directory not found: {arg}" - ) - raise UsageError(msg.format(arg=arg)) - if parts and fspath.is_dir(): - msg = ( - "package argument cannot contain :: selection parts: {arg}" - if as_pypath - else "directory argument cannot contain :: selection parts: {arg}" - ) - raise UsageError(msg.format(arg=arg)) - return CollectionArgument( - path=fspath, - parts=parts, - parametrization=parametrization, - module_name=module_name, - original_index=arg_index, - ) - - -def is_collection_argument_subsumed_by( - arg: CollectionArgument, by: CollectionArgument -) -> bool: - """Check if `arg` is subsumed (contained) by `by`.""" - # First check path subsumption. - if by.path != arg.path: - # `by` subsumes `arg` if `by` is a parent directory of `arg` and has no - # parts (collects everything in that directory). - if not by.parts: - return arg.path.is_relative_to(by.path) - return False - # Paths are equal, check parts. - # For example: ("TestClass",) is a prefix of ("TestClass", "test_method"). - if len(by.parts) > len(arg.parts) or arg.parts[: len(by.parts)] != by.parts: - return False - # Paths and parts are equal, check parametrization. - # A `by` without parametrization (None) matches everything, e.g. - # `pytest x.py::test_it` matches `x.py::test_it[0]`. Otherwise must be - # exactly equal. - if by.parametrization is not None and by.parametrization != arg.parametrization: - return False - return True - - -def normalize_collection_arguments( - collection_args: Sequence[CollectionArgument], -) -> list[CollectionArgument]: - """Normalize collection arguments to eliminate overlapping paths and parts. - - Detects when collection arguments overlap in either paths or parts and only - keeps the shorter prefix, or the earliest argument if duplicate, preserving - order. The result is prefix-free. - """ - # A quadratic algorithm is not acceptable since large inputs are possible. - # So this uses an O(n*log(n)) algorithm which takes advantage of the - # property that after sorting, a collection argument will immediately - # precede collection arguments it subsumes. An O(n) algorithm is not worth - # it. - collection_args_sorted = sorted( - collection_args, - key=lambda arg: (arg.path, arg.parts, arg.parametrization or ""), - ) - normalized: list[CollectionArgument] = [] - last_kept = None - for arg in collection_args_sorted: - if last_kept is None or not is_collection_argument_subsumed_by(arg, last_kept): - normalized.append(arg) - last_kept = arg - normalized.sort(key=lambda arg: arg.original_index) - return normalized diff --git a/.venv/lib/python3.12/site-packages/_pytest/mark/__init__.py b/.venv/lib/python3.12/site-packages/_pytest/mark/__init__.py deleted file mode 100644 index 841d781..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/mark/__init__.py +++ /dev/null @@ -1,301 +0,0 @@ -"""Generic mechanism for marking and selecting python functions.""" - -from __future__ import annotations - -import collections -from collections.abc import Collection -from collections.abc import Iterable -from collections.abc import Set as AbstractSet -import dataclasses -from typing import TYPE_CHECKING - -from .expression import Expression -from .structures import _HiddenParam -from .structures import EMPTY_PARAMETERSET_OPTION -from .structures import get_empty_parameterset_mark -from .structures import HIDDEN_PARAM -from .structures import Mark -from .structures import MARK_GEN -from .structures import MarkDecorator -from .structures import MarkGenerator -from .structures import ParameterSet -from _pytest.config import Config -from _pytest.config import ExitCode -from _pytest.config import hookimpl -from _pytest.config import UsageError -from _pytest.config.argparsing import NOT_SET -from _pytest.config.argparsing import Parser -from _pytest.stash import StashKey - - -if TYPE_CHECKING: - from _pytest.nodes import Item - - -__all__ = [ - "HIDDEN_PARAM", - "MARK_GEN", - "Mark", - "MarkDecorator", - "MarkGenerator", - "ParameterSet", - "get_empty_parameterset_mark", -] - - -old_mark_config_key = StashKey[Config | None]() - - -def param( - *values: object, - marks: MarkDecorator | Collection[MarkDecorator | Mark] = (), - id: str | _HiddenParam | None = None, -) -> ParameterSet: - """Specify a parameter in `pytest.mark.parametrize`_ calls or - :ref:`parametrized fixtures `. - - .. code-block:: python - - @pytest.mark.parametrize( - "test_input,expected", - [ - ("3+5", 8), - pytest.param("6*9", 42, marks=pytest.mark.xfail), - ], - ) - def test_eval(test_input, expected): - assert eval(test_input) == expected - - :param values: Variable args of the values of the parameter set, in order. - - :param marks: - A single mark or a list of marks to be applied to this parameter set. - - :ref:`pytest.mark.usefixtures ` cannot be added via this parameter. - - :type id: str | Literal[pytest.HIDDEN_PARAM] | None - :param id: - The id to attribute to this parameter set. - - .. versionadded:: 8.4 - :ref:`hidden-param` means to hide the parameter set - from the test name. Can only be used at most 1 time, as - test names need to be unique. - """ - return ParameterSet.param(*values, marks=marks, id=id) - - -def pytest_addoption(parser: Parser) -> None: - group = parser.getgroup("general") - group._addoption( # private to use reserved lower-case short option - "-k", - action="store", - dest="keyword", - default="", - metavar="EXPRESSION", - help="Only run tests which match the given substring expression. " - "An expression is a Python evaluable expression " - "where all names are substring-matched against test names " - "and their parent classes. Example: -k 'test_method or test_" - "other' matches all test functions and classes whose name " - "contains 'test_method' or 'test_other', while -k 'not test_method' " - "matches those that don't contain 'test_method' in their names. " - "-k 'not test_method and not test_other' will eliminate the matches. " - "Additionally keywords are matched to classes and functions " - "containing extra names in their 'extra_keyword_matches' set, " - "as well as functions which have names assigned directly to them. " - "The matching is case-insensitive.", - ) - - group._addoption( # private to use reserved lower-case short option - "-m", - action="store", - dest="markexpr", - default="", - metavar="MARKEXPR", - help="Only run tests matching given mark expression. " - "For example: -m 'mark1 and not mark2'.", - ) - - group.addoption( - "--markers", - action="store_true", - help="show markers (builtin, plugin and per-project ones).", - ) - - parser.addini("markers", "Register new markers for test functions", "linelist") - parser.addini(EMPTY_PARAMETERSET_OPTION, "Default marker for empty parametersets") - - -@hookimpl(tryfirst=True) -def pytest_cmdline_main(config: Config) -> int | ExitCode | None: - import _pytest.config - - if config.option.markers: - config._do_configure() - tw = _pytest.config.create_terminal_writer(config) - for line in config.getini("markers"): - parts = line.split(":", 1) - name = parts[0] - rest = parts[1] if len(parts) == 2 else "" - tw.write(f"@pytest.mark.{name}:", bold=True) - tw.line(rest) - tw.line() - config._ensure_unconfigure() - return 0 - - return None - - -@dataclasses.dataclass -class KeywordMatcher: - """A matcher for keywords. - - Given a list of names, matches any substring of one of these names. The - string inclusion check is case-insensitive. - - Will match on the name of colitem, including the names of its parents. - Only matches names of items which are either a :class:`Class` or a - :class:`Function`. - - Additionally, matches on names in the 'extra_keyword_matches' set of - any item, as well as names directly assigned to test functions. - """ - - __slots__ = ("_names",) - - _names: AbstractSet[str] - - @classmethod - def from_item(cls, item: Item) -> KeywordMatcher: - mapped_names = set() - - # Add the names of the current item and any parent items, - # except the Session and root Directory's which are not - # interesting for matching. - import pytest - - for node in item.listchain(): - if isinstance(node, pytest.Session): - continue - if isinstance(node, pytest.Directory) and isinstance( - node.parent, pytest.Session - ): - continue - mapped_names.add(node.name) - - # Add the names added as extra keywords to current or parent items. - mapped_names.update(item.listextrakeywords()) - - # Add the names attached to the current function through direct assignment. - function_obj = getattr(item, "function", None) - if function_obj: - mapped_names.update(function_obj.__dict__) - - # Add the markers to the keywords as we no longer handle them correctly. - mapped_names.update(mark.name for mark in item.iter_markers()) - - return cls(mapped_names) - - def __call__(self, subname: str, /, **kwargs: str | int | bool | None) -> bool: - if kwargs: - raise UsageError("Keyword expressions do not support call parameters.") - subname = subname.lower() - return any(subname in name.lower() for name in self._names) - - -def deselect_by_keyword(items: list[Item], config: Config) -> None: - keywordexpr = config.option.keyword.lstrip() - if not keywordexpr: - return - - expr = _parse_expression(keywordexpr, "Wrong expression passed to '-k'") - - remaining = [] - deselected = [] - for colitem in items: - if not expr.evaluate(KeywordMatcher.from_item(colitem)): - deselected.append(colitem) - else: - remaining.append(colitem) - - if deselected: - config.hook.pytest_deselected(items=deselected) - items[:] = remaining - - -@dataclasses.dataclass -class MarkMatcher: - """A matcher for markers which are present. - - Tries to match on any marker names, attached to the given colitem. - """ - - __slots__ = ("own_mark_name_mapping",) - - own_mark_name_mapping: dict[str, list[Mark]] - - @classmethod - def from_markers(cls, markers: Iterable[Mark]) -> MarkMatcher: - mark_name_mapping = collections.defaultdict(list) - for mark in markers: - mark_name_mapping[mark.name].append(mark) - return cls(mark_name_mapping) - - def __call__(self, name: str, /, **kwargs: str | int | bool | None) -> bool: - if not (matches := self.own_mark_name_mapping.get(name, [])): - return False - - for mark in matches: # pylint: disable=consider-using-any-or-all - if all(mark.kwargs.get(k, NOT_SET) == v for k, v in kwargs.items()): - return True - return False - - -def deselect_by_mark(items: list[Item], config: Config) -> None: - matchexpr = config.option.markexpr - if not matchexpr: - return - - expr = _parse_expression(matchexpr, "Wrong expression passed to '-m'") - remaining: list[Item] = [] - deselected: list[Item] = [] - for item in items: - if expr.evaluate(MarkMatcher.from_markers(item.iter_markers())): - remaining.append(item) - else: - deselected.append(item) - if deselected: - config.hook.pytest_deselected(items=deselected) - items[:] = remaining - - -def _parse_expression(expr: str, exc_message: str) -> Expression: - try: - return Expression.compile(expr) - except SyntaxError as e: - raise UsageError( - f"{exc_message}: {e.text}: at column {e.offset}: {e.msg}" - ) from None - - -def pytest_collection_modifyitems(items: list[Item], config: Config) -> None: - deselect_by_keyword(items, config) - deselect_by_mark(items, config) - - -def pytest_configure(config: Config) -> None: - config.stash[old_mark_config_key] = MARK_GEN._config - MARK_GEN._config = config - - empty_parameterset = config.getini(EMPTY_PARAMETERSET_OPTION) - - if empty_parameterset not in ("skip", "xfail", "fail_at_collect", None, ""): - raise UsageError( - f"{EMPTY_PARAMETERSET_OPTION!s} must be one of skip, xfail or fail_at_collect" - f" but it is {empty_parameterset!r}" - ) - - -def pytest_unconfigure(config: Config) -> None: - MARK_GEN._config = config.stash.get(old_mark_config_key, None) diff --git a/.venv/lib/python3.12/site-packages/_pytest/mark/expression.py b/.venv/lib/python3.12/site-packages/_pytest/mark/expression.py deleted file mode 100644 index 3bdbd03..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/mark/expression.py +++ /dev/null @@ -1,353 +0,0 @@ -r"""Evaluate match expressions, as used by `-k` and `-m`. - -The grammar is: - -expression: expr? EOF -expr: and_expr ('or' and_expr)* -and_expr: not_expr ('and' not_expr)* -not_expr: 'not' not_expr | '(' expr ')' | ident kwargs? - -ident: (\w|:|\+|-|\.|\[|\]|\\|/)+ -kwargs: ('(' name '=' value ( ', ' name '=' value )* ')') -name: a valid ident, but not a reserved keyword -value: (unescaped) string literal | (-)?[0-9]+ | 'False' | 'True' | 'None' - -The semantics are: - -- Empty expression evaluates to False. -- ident evaluates to True or False according to a provided matcher function. -- ident with parentheses and keyword arguments evaluates to True or False according to a provided matcher function. -- or/and/not evaluate according to the usual boolean semantics. -""" - -from __future__ import annotations - -import ast -from collections.abc import Iterator -from collections.abc import Mapping -from collections.abc import Sequence -import dataclasses -import enum -import keyword -import re -import types -from typing import Final -from typing import final -from typing import Literal -from typing import NoReturn -from typing import overload -from typing import Protocol - - -__all__ = [ - "Expression", - "ExpressionMatcher", -] - - -FILE_NAME: Final = "" - - -class TokenType(enum.Enum): - LPAREN = "left parenthesis" - RPAREN = "right parenthesis" - OR = "or" - AND = "and" - NOT = "not" - IDENT = "identifier" - EOF = "end of input" - EQUAL = "=" - STRING = "string literal" - COMMA = "," - - -@dataclasses.dataclass(frozen=True) -class Token: - __slots__ = ("pos", "type", "value") - type: TokenType - value: str - pos: int - - -class Scanner: - __slots__ = ("current", "input", "tokens") - - def __init__(self, input: str) -> None: - self.input = input - self.tokens = self.lex(input) - self.current = next(self.tokens) - - def lex(self, input: str) -> Iterator[Token]: - pos = 0 - while pos < len(input): - if input[pos] in (" ", "\t"): - pos += 1 - elif input[pos] == "(": - yield Token(TokenType.LPAREN, "(", pos) - pos += 1 - elif input[pos] == ")": - yield Token(TokenType.RPAREN, ")", pos) - pos += 1 - elif input[pos] == "=": - yield Token(TokenType.EQUAL, "=", pos) - pos += 1 - elif input[pos] == ",": - yield Token(TokenType.COMMA, ",", pos) - pos += 1 - elif (quote_char := input[pos]) in ("'", '"'): - end_quote_pos = input.find(quote_char, pos + 1) - if end_quote_pos == -1: - raise SyntaxError( - f'closing quote "{quote_char}" is missing', - (FILE_NAME, 1, pos + 1, input), - ) - value = input[pos : end_quote_pos + 1] - if (backslash_pos := input.find("\\")) != -1: - raise SyntaxError( - r'escaping with "\" not supported in marker expression', - (FILE_NAME, 1, backslash_pos + 1, input), - ) - yield Token(TokenType.STRING, value, pos) - pos += len(value) - else: - match = re.match(r"(:?\w|:|\+|-|\.|\[|\]|\\|/)+", input[pos:]) - if match: - value = match.group(0) - if value == "or": - yield Token(TokenType.OR, value, pos) - elif value == "and": - yield Token(TokenType.AND, value, pos) - elif value == "not": - yield Token(TokenType.NOT, value, pos) - else: - yield Token(TokenType.IDENT, value, pos) - pos += len(value) - else: - raise SyntaxError( - f'unexpected character "{input[pos]}"', - (FILE_NAME, 1, pos + 1, input), - ) - yield Token(TokenType.EOF, "", pos) - - @overload - def accept(self, type: TokenType, *, reject: Literal[True]) -> Token: ... - - @overload - def accept( - self, type: TokenType, *, reject: Literal[False] = False - ) -> Token | None: ... - - def accept(self, type: TokenType, *, reject: bool = False) -> Token | None: - if self.current.type is type: - token = self.current - if token.type is not TokenType.EOF: - self.current = next(self.tokens) - return token - if reject: - self.reject((type,)) - return None - - def reject(self, expected: Sequence[TokenType]) -> NoReturn: - raise SyntaxError( - "expected {}; got {}".format( - " OR ".join(type.value for type in expected), - self.current.type.value, - ), - (FILE_NAME, 1, self.current.pos + 1, self.input), - ) - - -# True, False and None are legal match expression identifiers, -# but illegal as Python identifiers. To fix this, this prefix -# is added to identifiers in the conversion to Python AST. -IDENT_PREFIX = "$" - - -def expression(s: Scanner) -> ast.Expression: - if s.accept(TokenType.EOF): - ret: ast.expr = ast.Constant(False) - else: - ret = expr(s) - s.accept(TokenType.EOF, reject=True) - return ast.fix_missing_locations(ast.Expression(ret)) - - -def expr(s: Scanner) -> ast.expr: - ret = and_expr(s) - while s.accept(TokenType.OR): - rhs = and_expr(s) - ret = ast.BoolOp(ast.Or(), [ret, rhs]) - return ret - - -def and_expr(s: Scanner) -> ast.expr: - ret = not_expr(s) - while s.accept(TokenType.AND): - rhs = not_expr(s) - ret = ast.BoolOp(ast.And(), [ret, rhs]) - return ret - - -def not_expr(s: Scanner) -> ast.expr: - if s.accept(TokenType.NOT): - return ast.UnaryOp(ast.Not(), not_expr(s)) - if s.accept(TokenType.LPAREN): - ret = expr(s) - s.accept(TokenType.RPAREN, reject=True) - return ret - ident = s.accept(TokenType.IDENT) - if ident: - name = ast.Name(IDENT_PREFIX + ident.value, ast.Load()) - if s.accept(TokenType.LPAREN): - ret = ast.Call(func=name, args=[], keywords=all_kwargs(s)) - s.accept(TokenType.RPAREN, reject=True) - else: - ret = name - return ret - - s.reject((TokenType.NOT, TokenType.LPAREN, TokenType.IDENT)) - - -BUILTIN_MATCHERS = {"True": True, "False": False, "None": None} - - -def single_kwarg(s: Scanner) -> ast.keyword: - keyword_name = s.accept(TokenType.IDENT, reject=True) - if not keyword_name.value.isidentifier(): - raise SyntaxError( - f"not a valid python identifier {keyword_name.value}", - (FILE_NAME, 1, keyword_name.pos + 1, s.input), - ) - if keyword.iskeyword(keyword_name.value): - raise SyntaxError( - f"unexpected reserved python keyword `{keyword_name.value}`", - (FILE_NAME, 1, keyword_name.pos + 1, s.input), - ) - s.accept(TokenType.EQUAL, reject=True) - - if value_token := s.accept(TokenType.STRING): - value: str | int | bool | None = value_token.value[1:-1] # strip quotes - else: - value_token = s.accept(TokenType.IDENT, reject=True) - if (number := value_token.value).isdigit() or ( - number.startswith("-") and number[1:].isdigit() - ): - value = int(number) - elif value_token.value in BUILTIN_MATCHERS: - value = BUILTIN_MATCHERS[value_token.value] - else: - raise SyntaxError( - f'unexpected character/s "{value_token.value}"', - (FILE_NAME, 1, value_token.pos + 1, s.input), - ) - - ret = ast.keyword(keyword_name.value, ast.Constant(value)) - return ret - - -def all_kwargs(s: Scanner) -> list[ast.keyword]: - ret = [single_kwarg(s)] - while s.accept(TokenType.COMMA): - ret.append(single_kwarg(s)) - return ret - - -class ExpressionMatcher(Protocol): - """A callable which, given an identifier and optional kwargs, should return - whether it matches in an :class:`Expression` evaluation. - - Should be prepared to handle arbitrary strings as input. - - If no kwargs are provided, the expression of the form `foo`. - If kwargs are provided, the expression is of the form `foo(1, b=True, "s")`. - - If the expression is not supported (e.g. don't want to accept the kwargs - syntax variant), should raise :class:`~pytest.UsageError`. - - Example:: - - def matcher(name: str, /, **kwargs: str | int | bool | None) -> bool: - # Match `cat`. - if name == "cat" and not kwargs: - return True - # Match `dog(barks=True)`. - if name == "dog" and kwargs == {"barks": False}: - return True - return False - """ - - def __call__(self, name: str, /, **kwargs: str | int | bool | None) -> bool: ... - - -@dataclasses.dataclass -class MatcherNameAdapter: - matcher: ExpressionMatcher - name: str - - def __bool__(self) -> bool: - return self.matcher(self.name) - - def __call__(self, **kwargs: str | int | bool | None) -> bool: - return self.matcher(self.name, **kwargs) - - -class MatcherAdapter(Mapping[str, MatcherNameAdapter]): - """Adapts a matcher function to a locals mapping as required by eval().""" - - def __init__(self, matcher: ExpressionMatcher) -> None: - self.matcher = matcher - - def __getitem__(self, key: str) -> MatcherNameAdapter: - return MatcherNameAdapter(matcher=self.matcher, name=key[len(IDENT_PREFIX) :]) - - def __iter__(self) -> Iterator[str]: - raise NotImplementedError() - - def __len__(self) -> int: - raise NotImplementedError() - - -@final -class Expression: - """A compiled match expression as used by -k and -m. - - The expression can be evaluated against different matchers. - """ - - __slots__ = ("_code", "input") - - def __init__(self, input: str, code: types.CodeType) -> None: - #: The original input line, as a string. - self.input: Final = input - self._code: Final = code - - @classmethod - def compile(cls, input: str) -> Expression: - """Compile a match expression. - - :param input: The input expression - one line. - - :raises SyntaxError: If the expression is malformed. - """ - astexpr = expression(Scanner(input)) - code = compile( - astexpr, - filename="", - mode="eval", - ) - return Expression(input, code) - - def evaluate(self, matcher: ExpressionMatcher) -> bool: - """Evaluate the match expression. - - :param matcher: - A callback which determines whether an identifier matches or not. - See the :class:`ExpressionMatcher` protocol for details and example. - - :returns: Whether the expression matches or not. - - :raises UsageError: - If the matcher doesn't support the expression. Cannot happen if the - matcher supports all expressions. - """ - return bool(eval(self._code, {"__builtins__": {}}, MatcherAdapter(matcher))) diff --git a/.venv/lib/python3.12/site-packages/_pytest/mark/structures.py b/.venv/lib/python3.12/site-packages/_pytest/mark/structures.py deleted file mode 100644 index 97842fc..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/mark/structures.py +++ /dev/null @@ -1,664 +0,0 @@ -# mypy: allow-untyped-defs -from __future__ import annotations - -import collections.abc -from collections.abc import Callable -from collections.abc import Collection -from collections.abc import Iterable -from collections.abc import Iterator -from collections.abc import Mapping -from collections.abc import MutableMapping -from collections.abc import Sequence -import dataclasses -import enum -import inspect -from typing import Any -from typing import final -from typing import NamedTuple -from typing import overload -from typing import TYPE_CHECKING -from typing import TypeVar -import warnings - -from .._code import getfslineno -from ..compat import NOTSET -from ..compat import NotSetType -from _pytest.config import Config -from _pytest.deprecated import check_ispytest -from _pytest.deprecated import MARKED_FIXTURE -from _pytest.outcomes import fail -from _pytest.raises import AbstractRaises -from _pytest.scope import _ScopeName -from _pytest.warning_types import PytestUnknownMarkWarning - - -if TYPE_CHECKING: - from ..nodes import Node - - -EMPTY_PARAMETERSET_OPTION = "empty_parameter_set_mark" - - -# Singleton type for HIDDEN_PARAM, as described in: -# https://www.python.org/dev/peps/pep-0484/#support-for-singleton-types-in-unions -class _HiddenParam(enum.Enum): - token = 0 - - -#: Can be used as a parameter set id to hide it from the test name. -HIDDEN_PARAM = _HiddenParam.token - - -def istestfunc(func) -> bool: - return callable(func) and getattr(func, "__name__", "") != "" - - -def get_empty_parameterset_mark( - config: Config, argnames: Sequence[str], func -) -> MarkDecorator: - from ..nodes import Collector - - argslisting = ", ".join(argnames) - - _fs, lineno = getfslineno(func) - reason = f"got empty parameter set for ({argslisting})" - requested_mark = config.getini(EMPTY_PARAMETERSET_OPTION) - if requested_mark in ("", None, "skip"): - mark = MARK_GEN.skip(reason=reason) - elif requested_mark == "xfail": - mark = MARK_GEN.xfail(reason=reason, run=False) - elif requested_mark == "fail_at_collect": - raise Collector.CollectError( - f"Empty parameter set in '{func.__name__}' at line {lineno + 1}" - ) - else: - raise LookupError(requested_mark) - return mark - - -class ParameterSet(NamedTuple): - """A set of values for a set of parameters along with associated marks and - an optional ID for the set. - - Examples:: - - pytest.param(1, 2, 3) - # ParameterSet(values=(1, 2, 3), marks=(), id=None) - - pytest.param("hello", id="greeting") - # ParameterSet(values=("hello",), marks=(), id="greeting") - - # Parameter set with marks - pytest.param(42, marks=pytest.mark.xfail) - # ParameterSet(values=(42,), marks=(MarkDecorator(...),), id=None) - - # From parametrize mark (parameter names + list of parameter sets) - pytest.mark.parametrize( - ("a", "b", "expected"), - [ - (1, 2, 3), - pytest.param(40, 2, 42, id="everything"), - ], - ) - # ParameterSet(values=(1, 2, 3), marks=(), id=None) - # ParameterSet(values=(40, 2, 42), marks=(), id="everything") - """ - - values: Sequence[object | NotSetType] - marks: Collection[MarkDecorator | Mark] - id: str | _HiddenParam | None - - @classmethod - def param( - cls, - *values: object, - marks: MarkDecorator | Collection[MarkDecorator | Mark] = (), - id: str | _HiddenParam | None = None, - ) -> ParameterSet: - if isinstance(marks, MarkDecorator): - marks = (marks,) - else: - assert isinstance(marks, collections.abc.Collection) - if any(i.name == "usefixtures" for i in marks): - raise ValueError( - "pytest.param cannot add pytest.mark.usefixtures; see " - "https://docs.pytest.org/en/stable/reference/reference.html#pytest-param" - ) - - if id is not None: - if not isinstance(id, str) and id is not HIDDEN_PARAM: - raise TypeError( - "Expected id to be a string or a `pytest.HIDDEN_PARAM` sentinel, " - f"got {type(id)}: {id!r}", - ) - return cls(values, marks, id) - - @classmethod - def extract_from( - cls, - parameterset: ParameterSet | Sequence[object] | object, - force_tuple: bool = False, - ) -> ParameterSet: - """Extract from an object or objects. - - :param parameterset: - A legacy style parameterset that may or may not be a tuple, - and may or may not be wrapped into a mess of mark objects. - - :param force_tuple: - Enforce tuple wrapping so single argument tuple values - don't get decomposed and break tests. - """ - if isinstance(parameterset, cls): - return parameterset - if force_tuple: - return cls.param(parameterset) - else: - # TODO: Refactor to fix this type-ignore. Currently the following - # passes type-checking but crashes: - # - # @pytest.mark.parametrize(('x', 'y'), [1, 2]) - # def test_foo(x, y): pass - return cls(parameterset, marks=[], id=None) # type: ignore[arg-type] - - @staticmethod - def _parse_parametrize_args( - argnames: str | Sequence[str], - argvalues: Iterable[ParameterSet | Sequence[object] | object], - *args, - **kwargs, - ) -> tuple[Sequence[str], bool]: - if isinstance(argnames, str): - argnames = [x.strip() for x in argnames.split(",") if x.strip()] - force_tuple = len(argnames) == 1 - else: - force_tuple = False - return argnames, force_tuple - - @staticmethod - def _parse_parametrize_parameters( - argvalues: Iterable[ParameterSet | Sequence[object] | object], - force_tuple: bool, - ) -> list[ParameterSet]: - return [ - ParameterSet.extract_from(x, force_tuple=force_tuple) for x in argvalues - ] - - @classmethod - def _for_parametrize( - cls, - argnames: str | Sequence[str], - argvalues: Iterable[ParameterSet | Sequence[object] | object], - func, - config: Config, - nodeid: str, - ) -> tuple[Sequence[str], list[ParameterSet]]: - argnames, force_tuple = cls._parse_parametrize_args(argnames, argvalues) - parameters = cls._parse_parametrize_parameters(argvalues, force_tuple) - del argvalues - - if parameters: - # Check all parameter sets have the correct number of values. - for param in parameters: - if len(param.values) != len(argnames): - msg = ( - '{nodeid}: in "parametrize" the number of names ({names_len}):\n' - " {names}\n" - "must be equal to the number of values ({values_len}):\n" - " {values}" - ) - fail( - msg.format( - nodeid=nodeid, - values=param.values, - names=argnames, - names_len=len(argnames), - values_len=len(param.values), - ), - pytrace=False, - ) - else: - # Empty parameter set (likely computed at runtime): create a single - # parameter set with NOTSET values, with the "empty parameter set" mark applied to it. - mark = get_empty_parameterset_mark(config, argnames, func) - parameters.append( - ParameterSet( - values=(NOTSET,) * len(argnames), marks=[mark], id="NOTSET" - ) - ) - return argnames, parameters - - -@final -@dataclasses.dataclass(frozen=True) -class Mark: - """A pytest mark.""" - - #: Name of the mark. - name: str - #: Positional arguments of the mark decorator. - args: tuple[Any, ...] - #: Keyword arguments of the mark decorator. - kwargs: Mapping[str, Any] - - #: Source Mark for ids with parametrize Marks. - _param_ids_from: Mark | None = dataclasses.field(default=None, repr=False) - #: Resolved/generated ids with parametrize Marks. - _param_ids_generated: Sequence[str] | None = dataclasses.field( - default=None, repr=False - ) - - def __init__( - self, - name: str, - args: tuple[Any, ...], - kwargs: Mapping[str, Any], - param_ids_from: Mark | None = None, - param_ids_generated: Sequence[str] | None = None, - *, - _ispytest: bool = False, - ) -> None: - """:meta private:""" - check_ispytest(_ispytest) - # Weirdness to bypass frozen=True. - object.__setattr__(self, "name", name) - object.__setattr__(self, "args", args) - object.__setattr__(self, "kwargs", kwargs) - object.__setattr__(self, "_param_ids_from", param_ids_from) - object.__setattr__(self, "_param_ids_generated", param_ids_generated) - - def _has_param_ids(self) -> bool: - return "ids" in self.kwargs or len(self.args) >= 4 - - def combined_with(self, other: Mark) -> Mark: - """Return a new Mark which is a combination of this - Mark and another Mark. - - Combines by appending args and merging kwargs. - - :param Mark other: The mark to combine with. - :rtype: Mark - """ - assert self.name == other.name - - # Remember source of ids with parametrize Marks. - param_ids_from: Mark | None = None - if self.name == "parametrize": - if other._has_param_ids(): - param_ids_from = other - elif self._has_param_ids(): - param_ids_from = self - - return Mark( - self.name, - self.args + other.args, - dict(self.kwargs, **other.kwargs), - param_ids_from=param_ids_from, - _ispytest=True, - ) - - -# A generic parameter designating an object to which a Mark may -# be applied -- a test function (callable) or class. -# Note: a lambda is not allowed, but this can't be represented. -Markable = TypeVar("Markable", bound=Callable[..., object] | type) - - -@dataclasses.dataclass -class MarkDecorator: - """A decorator for applying a mark on test functions and classes. - - ``MarkDecorators`` are created with ``pytest.mark``:: - - mark1 = pytest.mark.NAME # Simple MarkDecorator - mark2 = pytest.mark.NAME(name1=value) # Parametrized MarkDecorator - - and can then be applied as decorators to test functions:: - - @mark2 - def test_function(): - pass - - When a ``MarkDecorator`` is called, it does the following: - - 1. If called with a single class as its only positional argument and no - additional keyword arguments, it attaches the mark to the class so it - gets applied automatically to all test cases found in that class. - - 2. If called with a single function as its only positional argument and - no additional keyword arguments, it attaches the mark to the function, - containing all the arguments already stored internally in the - ``MarkDecorator``. - - 3. When called in any other case, it returns a new ``MarkDecorator`` - instance with the original ``MarkDecorator``'s content updated with - the arguments passed to this call. - - Note: The rules above prevent a ``MarkDecorator`` from storing only a - single function or class reference as its positional argument with no - additional keyword or positional arguments. You can work around this by - using `with_args()`. - """ - - mark: Mark - - def __init__(self, mark: Mark, *, _ispytest: bool = False) -> None: - """:meta private:""" - check_ispytest(_ispytest) - self.mark = mark - - @property - def name(self) -> str: - """Alias for mark.name.""" - return self.mark.name - - @property - def args(self) -> tuple[Any, ...]: - """Alias for mark.args.""" - return self.mark.args - - @property - def kwargs(self) -> Mapping[str, Any]: - """Alias for mark.kwargs.""" - return self.mark.kwargs - - @property - def markname(self) -> str: - """:meta private:""" - return self.name # for backward-compat (2.4.1 had this attr) - - def with_args(self, *args: object, **kwargs: object) -> MarkDecorator: - """Return a MarkDecorator with extra arguments added. - - Unlike calling the MarkDecorator, with_args() can be used even - if the sole argument is a callable/class. - """ - mark = Mark(self.name, args, kwargs, _ispytest=True) - return MarkDecorator(self.mark.combined_with(mark), _ispytest=True) - - # Type ignored because the overloads overlap with an incompatible - # return type. Not much we can do about that. Thankfully mypy picks - # the first match so it works out even if we break the rules. - @overload - def __call__(self, arg: Markable) -> Markable: # type: ignore[overload-overlap] - pass - - @overload - def __call__(self, *args: object, **kwargs: object) -> MarkDecorator: - pass - - def __call__(self, *args: object, **kwargs: object): - """Call the MarkDecorator.""" - if args and not kwargs: - func = args[0] - is_class = inspect.isclass(func) - # For staticmethods/classmethods, the marks are eventually fetched from the - # function object, not the descriptor, so unwrap. - unwrapped_func = func - if isinstance(func, staticmethod | classmethod): - unwrapped_func = func.__func__ - if len(args) == 1 and (istestfunc(unwrapped_func) or is_class): - store_mark(unwrapped_func, self.mark, stacklevel=3) - return func - return self.with_args(*args, **kwargs) - - -def get_unpacked_marks( - obj: object | type, - *, - consider_mro: bool = True, -) -> list[Mark]: - """Obtain the unpacked marks that are stored on an object. - - If obj is a class and consider_mro is true, return marks applied to - this class and all of its super-classes in MRO order. If consider_mro - is false, only return marks applied directly to this class. - """ - if isinstance(obj, type): - if not consider_mro: - mark_lists = [obj.__dict__.get("pytestmark", [])] - else: - mark_lists = [ - x.__dict__.get("pytestmark", []) for x in reversed(obj.__mro__) - ] - mark_list = [] - for item in mark_lists: - if isinstance(item, list): - mark_list.extend(item) - else: - mark_list.append(item) - else: - mark_attribute = getattr(obj, "pytestmark", []) - if isinstance(mark_attribute, list): - mark_list = mark_attribute - else: - mark_list = [mark_attribute] - return list(normalize_mark_list(mark_list)) - - -def normalize_mark_list( - mark_list: Iterable[Mark | MarkDecorator], -) -> Iterable[Mark]: - """ - Normalize an iterable of Mark or MarkDecorator objects into a list of marks - by retrieving the `mark` attribute on MarkDecorator instances. - - :param mark_list: marks to normalize - :returns: A new list of the extracted Mark objects - """ - for mark in mark_list: - mark_obj = getattr(mark, "mark", mark) - if not isinstance(mark_obj, Mark): - raise TypeError(f"got {mark_obj!r} instead of Mark") - yield mark_obj - - -def store_mark(obj, mark: Mark, *, stacklevel: int = 2) -> None: - """Store a Mark on an object. - - This is used to implement the Mark declarations/decorators correctly. - """ - assert isinstance(mark, Mark), mark - - from ..fixtures import getfixturemarker - - if getfixturemarker(obj) is not None: - warnings.warn(MARKED_FIXTURE, stacklevel=stacklevel) - - # Always reassign name to avoid updating pytestmark in a reference that - # was only borrowed. - obj.pytestmark = [*get_unpacked_marks(obj, consider_mro=False), mark] - - -# Typing for builtin pytest marks. This is cheating; it gives builtin marks -# special privilege, and breaks modularity. But practicality beats purity... -if TYPE_CHECKING: - - class _SkipMarkDecorator(MarkDecorator): - @overload # type: ignore[override,no-overload-impl] - def __call__(self, arg: Markable) -> Markable: ... - - @overload - def __call__(self, reason: str = ...) -> MarkDecorator: ... - - class _SkipifMarkDecorator(MarkDecorator): - def __call__( # type: ignore[override] - self, - condition: str | bool = ..., - *conditions: str | bool, - reason: str = ..., - ) -> MarkDecorator: ... - - class _XfailMarkDecorator(MarkDecorator): - @overload # type: ignore[override,no-overload-impl] - def __call__(self, arg: Markable) -> Markable: ... - - @overload - def __call__( - self, - condition: str | bool = True, - *conditions: str | bool, - reason: str = ..., - run: bool = ..., - raises: None - | type[BaseException] - | tuple[type[BaseException], ...] - | AbstractRaises[BaseException] = ..., - strict: bool = ..., - ) -> MarkDecorator: ... - - class _ParametrizeMarkDecorator(MarkDecorator): - def __call__( # type: ignore[override] - self, - argnames: str | Sequence[str], - argvalues: Iterable[ParameterSet | Sequence[object] | object], - *, - indirect: bool | Sequence[str] = ..., - ids: Iterable[None | str | float | int | bool] - | Callable[[Any], object | None] - | None = ..., - scope: _ScopeName | None = ..., - ) -> MarkDecorator: ... - - class _UsefixturesMarkDecorator(MarkDecorator): - def __call__(self, *fixtures: str) -> MarkDecorator: # type: ignore[override] - ... - - class _FilterwarningsMarkDecorator(MarkDecorator): - def __call__(self, *filters: str) -> MarkDecorator: # type: ignore[override] - ... - - -@final -class MarkGenerator: - """Factory for :class:`MarkDecorator` objects - exposed as - a ``pytest.mark`` singleton instance. - - Example:: - - import pytest - - - @pytest.mark.slowtest - def test_function(): - pass - - applies a 'slowtest' :class:`Mark` on ``test_function``. - """ - - # See TYPE_CHECKING above. - if TYPE_CHECKING: - skip: _SkipMarkDecorator - skipif: _SkipifMarkDecorator - xfail: _XfailMarkDecorator - parametrize: _ParametrizeMarkDecorator - usefixtures: _UsefixturesMarkDecorator - filterwarnings: _FilterwarningsMarkDecorator - - def __init__(self, *, _ispytest: bool = False) -> None: - check_ispytest(_ispytest) - self._config: Config | None = None - self._markers: set[str] = set() - - def __getattr__(self, name: str) -> MarkDecorator: - """Generate a new :class:`MarkDecorator` with the given name.""" - if name[0] == "_": - raise AttributeError("Marker name must NOT start with underscore") - - if self._config is not None: - # We store a set of markers as a performance optimisation - if a mark - # name is in the set we definitely know it, but a mark may be known and - # not in the set. We therefore start by updating the set! - if name not in self._markers: - for line in self._config.getini("markers"): - # example lines: "skipif(condition): skip the given test if..." - # or "hypothesis: tests which use Hypothesis", so to get the - # marker name we split on both `:` and `(`. - marker = line.split(":")[0].split("(")[0].strip() - self._markers.add(marker) - - # If the name is not in the set of known marks after updating, - # then it really is time to issue a warning or an error. - if name not in self._markers: - # Raise a specific error for common misspellings of "parametrize". - if name in ["parameterize", "parametrise", "parameterise"]: - __tracebackhide__ = True - fail(f"Unknown '{name}' mark, did you mean 'parametrize'?") - - strict_markers = self._config.getini("strict_markers") - if strict_markers is None: - strict_markers = self._config.getini("strict") - if strict_markers: - fail( - f"{name!r} not found in `markers` configuration option", - pytrace=False, - ) - - warnings.warn( - f"Unknown pytest.mark.{name} - is this a typo? You can register " - "custom marks to avoid this warning - for details, see " - "https://docs.pytest.org/en/stable/how-to/mark.html", - PytestUnknownMarkWarning, - 2, - ) - - return MarkDecorator(Mark(name, (), {}, _ispytest=True), _ispytest=True) - - -MARK_GEN = MarkGenerator(_ispytest=True) - - -@final -class NodeKeywords(MutableMapping[str, Any]): - __slots__ = ("_markers", "node", "parent") - - def __init__(self, node: Node) -> None: - self.node = node - self.parent = node.parent - self._markers = {node.name: True} - - def __getitem__(self, key: str) -> Any: - try: - return self._markers[key] - except KeyError: - if self.parent is None: - raise - return self.parent.keywords[key] - - def __setitem__(self, key: str, value: Any) -> None: - self._markers[key] = value - - # Note: we could've avoided explicitly implementing some of the methods - # below and use the collections.abc fallback, but that would be slow. - - def __contains__(self, key: object) -> bool: - return key in self._markers or ( - self.parent is not None and key in self.parent.keywords - ) - - def update( # type: ignore[override] - self, - other: Mapping[str, Any] | Iterable[tuple[str, Any]] = (), - **kwds: Any, - ) -> None: - self._markers.update(other) - self._markers.update(kwds) - - def __delitem__(self, key: str) -> None: - raise ValueError("cannot delete key in keywords dict") - - def __iter__(self) -> Iterator[str]: - # Doesn't need to be fast. - yield from self._markers - if self.parent is not None: - for keyword in self.parent.keywords: - # self._marks and self.parent.keywords can have duplicates. - if keyword not in self._markers: - yield keyword - - def __len__(self) -> int: - # Doesn't need to be fast. - return sum(1 for keyword in self) - - def __repr__(self) -> str: - return f"" diff --git a/.venv/lib/python3.12/site-packages/_pytest/monkeypatch.py b/.venv/lib/python3.12/site-packages/_pytest/monkeypatch.py deleted file mode 100644 index 07cc3fc..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/monkeypatch.py +++ /dev/null @@ -1,435 +0,0 @@ -# mypy: allow-untyped-defs -"""Monkeypatching and mocking functionality.""" - -from __future__ import annotations - -from collections.abc import Generator -from collections.abc import Mapping -from collections.abc import MutableMapping -from contextlib import contextmanager -import os -from pathlib import Path -import re -import sys -from typing import Any -from typing import final -from typing import overload -from typing import TypeVar -import warnings - -from _pytest.deprecated import MONKEYPATCH_LEGACY_NAMESPACE_PACKAGES -from _pytest.fixtures import fixture -from _pytest.warning_types import PytestWarning - - -RE_IMPORT_ERROR_NAME = re.compile(r"^No module named (.*)$") - - -K = TypeVar("K") -V = TypeVar("V") - - -@fixture -def monkeypatch() -> Generator[MonkeyPatch]: - """A convenient fixture for monkey-patching. - - The fixture provides these methods to modify objects, dictionaries, or - :data:`os.environ`: - - * :meth:`monkeypatch.setattr(obj, name, value, raising=True) ` - * :meth:`monkeypatch.delattr(obj, name, raising=True) ` - * :meth:`monkeypatch.setitem(mapping, name, value) ` - * :meth:`monkeypatch.delitem(obj, name, raising=True) ` - * :meth:`monkeypatch.setenv(name, value, prepend=None) ` - * :meth:`monkeypatch.delenv(name, raising=True) ` - * :meth:`monkeypatch.syspath_prepend(path) ` - * :meth:`monkeypatch.chdir(path) ` - * :meth:`monkeypatch.context() ` - - All modifications will be undone after the requesting test function or - fixture has finished. The ``raising`` parameter determines if a :class:`KeyError` - or :class:`AttributeError` will be raised if the set/deletion operation does not have the - specified target. - - To undo modifications done by the fixture in a contained scope, - use :meth:`context() `. - """ - mpatch = MonkeyPatch() - yield mpatch - mpatch.undo() - - -def resolve(name: str) -> object: - # Simplified from zope.dottedname. - parts = name.split(".") - - used = parts.pop(0) - found: object = __import__(used) - for part in parts: - used += "." + part - try: - found = getattr(found, part) - except AttributeError: - pass - else: - continue - # We use explicit un-nesting of the handling block in order - # to avoid nested exceptions. - try: - __import__(used) - except ImportError as ex: - expected = str(ex).split()[-1] - if expected == used: - raise - else: - raise ImportError(f"import error in {used}: {ex}") from ex - found = annotated_getattr(found, part, used) - return found - - -def annotated_getattr(obj: object, name: str, ann: str) -> object: - try: - obj = getattr(obj, name) - except AttributeError as e: - raise AttributeError( - f"{type(obj).__name__!r} object at {ann} has no attribute {name!r}" - ) from e - return obj - - -def derive_importpath(import_path: str, raising: bool) -> tuple[str, object]: - if not isinstance(import_path, str) or "." not in import_path: - raise TypeError(f"must be absolute import path string, not {import_path!r}") - module, attr = import_path.rsplit(".", 1) - target = resolve(module) - if raising: - annotated_getattr(target, attr, ann=module) - return attr, target - - -class Notset: - def __repr__(self) -> str: - return "" - - -notset = Notset() - - -@final -class MonkeyPatch: - """Helper to conveniently monkeypatch attributes/items/environment - variables/syspath. - - Returned by the :fixture:`monkeypatch` fixture. - - .. versionchanged:: 6.2 - Can now also be used directly as `pytest.MonkeyPatch()`, for when - the fixture is not available. In this case, use - :meth:`with MonkeyPatch.context() as mp: ` or remember to call - :meth:`undo` explicitly. - """ - - def __init__(self) -> None: - self._setattr: list[tuple[object, str, object]] = [] - self._setitem: list[tuple[Mapping[Any, Any], object, object]] = [] - self._cwd: str | None = None - self._savesyspath: list[str] | None = None - - @classmethod - @contextmanager - def context(cls) -> Generator[MonkeyPatch]: - """Context manager that returns a new :class:`MonkeyPatch` object - which undoes any patching done inside the ``with`` block upon exit. - - Example: - - .. code-block:: python - - import functools - - - def test_partial(monkeypatch): - with monkeypatch.context() as m: - m.setattr(functools, "partial", 3) - - Useful in situations where it is desired to undo some patches before the test ends, - such as mocking ``stdlib`` functions that might break pytest itself if mocked (for examples - of this see :issue:`3290`). - """ - m = cls() - try: - yield m - finally: - m.undo() - - @overload - def setattr( - self, - target: str, - name: object, - value: Notset = ..., - raising: bool = ..., - ) -> None: ... - - @overload - def setattr( - self, - target: object, - name: str, - value: object, - raising: bool = ..., - ) -> None: ... - - def setattr( - self, - target: str | object, - name: object | str, - value: object = notset, - raising: bool = True, - ) -> None: - """ - Set attribute value on target, memorizing the old value. - - For example: - - .. code-block:: python - - import os - - monkeypatch.setattr(os, "getcwd", lambda: "/") - - The code above replaces the :func:`os.getcwd` function by a ``lambda`` which - always returns ``"/"``. - - For convenience, you can specify a string as ``target`` which - will be interpreted as a dotted import path, with the last part - being the attribute name: - - .. code-block:: python - - monkeypatch.setattr("os.getcwd", lambda: "/") - - Raises :class:`AttributeError` if the attribute does not exist, unless - ``raising`` is set to False. - - **Where to patch** - - ``monkeypatch.setattr`` works by (temporarily) changing the object that a name points to with another one. - There can be many names pointing to any individual object, so for patching to work you must ensure - that you patch the name used by the system under test. - - See the section :ref:`Where to patch ` in the :mod:`unittest.mock` - docs for a complete explanation, which is meant for :func:`unittest.mock.patch` but - applies to ``monkeypatch.setattr`` as well. - """ - __tracebackhide__ = True - import inspect - - if isinstance(value, Notset): - if not isinstance(target, str): - raise TypeError( - "use setattr(target, name, value) or " - "setattr(target, value) with target being a dotted " - "import string" - ) - value = name - name, target = derive_importpath(target, raising) - else: - if not isinstance(name, str): - raise TypeError( - "use setattr(target, name, value) with name being a string or " - "setattr(target, value) with target being a dotted " - "import string" - ) - - oldval = getattr(target, name, notset) - if raising and oldval is notset: - raise AttributeError(f"{target!r} has no attribute {name!r}") - - # avoid class descriptors like staticmethod/classmethod - if inspect.isclass(target): - oldval = target.__dict__.get(name, notset) - self._setattr.append((target, name, oldval)) - setattr(target, name, value) - - def delattr( - self, - target: object | str, - name: str | Notset = notset, - raising: bool = True, - ) -> None: - """Delete attribute ``name`` from ``target``. - - If no ``name`` is specified and ``target`` is a string - it will be interpreted as a dotted import path with the - last part being the attribute name. - - Raises AttributeError it the attribute does not exist, unless - ``raising`` is set to False. - """ - __tracebackhide__ = True - import inspect - - if isinstance(name, Notset): - if not isinstance(target, str): - raise TypeError( - "use delattr(target, name) or " - "delattr(target) with target being a dotted " - "import string" - ) - name, target = derive_importpath(target, raising) - - if not hasattr(target, name): - if raising: - raise AttributeError(name) - else: - oldval = getattr(target, name, notset) - # Avoid class descriptors like staticmethod/classmethod. - if inspect.isclass(target): - oldval = target.__dict__.get(name, notset) - self._setattr.append((target, name, oldval)) - delattr(target, name) - - def setitem(self, dic: Mapping[K, V], name: K, value: V) -> None: - """Set dictionary entry ``name`` to value.""" - self._setitem.append((dic, name, dic.get(name, notset))) - # Not all Mapping types support indexing, but MutableMapping doesn't support TypedDict - dic[name] = value # type: ignore[index] - - def delitem(self, dic: Mapping[K, V], name: K, raising: bool = True) -> None: - """Delete ``name`` from dict. - - Raises ``KeyError`` if it doesn't exist, unless ``raising`` is set to - False. - """ - if name not in dic: - if raising: - raise KeyError(name) - else: - self._setitem.append((dic, name, dic.get(name, notset))) - # Not all Mapping types support indexing, but MutableMapping doesn't support TypedDict - del dic[name] # type: ignore[attr-defined] - - def setenv(self, name: str, value: str, prepend: str | None = None) -> None: - """Set environment variable ``name`` to ``value``. - - If ``prepend`` is a character, read the current environment variable - value and prepend the ``value`` adjoined with the ``prepend`` - character. - """ - if not isinstance(value, str): - warnings.warn( # type: ignore[unreachable] - PytestWarning( - f"Value of environment variable {name} type should be str, but got " - f"{value!r} (type: {type(value).__name__}); converted to str implicitly" - ), - stacklevel=2, - ) - value = str(value) - if prepend and name in os.environ: - value = value + prepend + os.environ[name] - self.setitem(os.environ, name, value) - - def delenv(self, name: str, raising: bool = True) -> None: - """Delete ``name`` from the environment. - - Raises ``KeyError`` if it does not exist, unless ``raising`` is set to - False. - """ - environ: MutableMapping[str, str] = os.environ - self.delitem(environ, name, raising=raising) - - def syspath_prepend(self, path) -> None: - """Prepend ``path`` to ``sys.path`` list of import locations.""" - if self._savesyspath is None: - self._savesyspath = sys.path[:] - sys.path.insert(0, str(path)) - - # https://github.com/pypa/setuptools/blob/d8b901bc/docs/pkg_resources.txt#L162-L171 - # this is only needed when pkg_resources was already loaded by the namespace package - if "pkg_resources" in sys.modules: - import pkg_resources - from pkg_resources import fixup_namespace_packages - - # Only issue deprecation warning if this call would actually have an - # effect for this specific path. - if ( - hasattr(pkg_resources, "_namespace_packages") - and pkg_resources._namespace_packages - ): - path_obj = Path(str(path)) - for ns_pkg in pkg_resources._namespace_packages: - if ns_pkg is None: - continue - ns_pkg_path = path_obj / ns_pkg.replace(".", os.sep) - if ns_pkg_path.is_dir(): - warnings.warn( - MONKEYPATCH_LEGACY_NAMESPACE_PACKAGES, stacklevel=2 - ) - break - - fixup_namespace_packages(str(path)) - - # A call to syspathinsert() usually means that the caller wants to - # import some dynamically created files, thus with python3 we - # invalidate its import caches. - # This is especially important when any namespace package is in use, - # since then the mtime based FileFinder cache (that gets created in - # this case already) gets not invalidated when writing the new files - # quickly afterwards. - from importlib import invalidate_caches - - invalidate_caches() - - def chdir(self, path: str | os.PathLike[str]) -> None: - """Change the current working directory to the specified path. - - :param path: - The path to change into. - """ - if self._cwd is None: - self._cwd = os.getcwd() - os.chdir(path) - - def undo(self) -> None: - """Undo previous changes. - - This call consumes the undo stack. Calling it a second time has no - effect unless you do more monkeypatching after the undo call. - - There is generally no need to call `undo()`, since it is - called automatically during tear-down. - - .. note:: - The same `monkeypatch` fixture is used across a - single test function invocation. If `monkeypatch` is used both by - the test function itself and one of the test fixtures, - calling `undo()` will undo all of the changes made in - both functions. - - Prefer to use :meth:`context() ` instead. - """ - for obj, name, value in reversed(self._setattr): - if value is not notset: - setattr(obj, name, value) - else: - delattr(obj, name) - self._setattr[:] = [] - for dictionary, key, value in reversed(self._setitem): - if value is notset: - try: - # Not all Mapping types support indexing, but MutableMapping doesn't support TypedDict - del dictionary[key] # type: ignore[attr-defined] - except KeyError: - pass # Was already deleted, so we have the desired state. - else: - # Not all Mapping types support indexing, but MutableMapping doesn't support TypedDict - dictionary[key] = value # type: ignore[index] - self._setitem[:] = [] - if self._savesyspath is not None: - sys.path[:] = self._savesyspath - self._savesyspath = None - - if self._cwd is not None: - os.chdir(self._cwd) - self._cwd = None diff --git a/.venv/lib/python3.12/site-packages/_pytest/nodes.py b/.venv/lib/python3.12/site-packages/_pytest/nodes.py deleted file mode 100644 index 6690f6a..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/nodes.py +++ /dev/null @@ -1,772 +0,0 @@ -# mypy: allow-untyped-defs -from __future__ import annotations - -import abc -from collections.abc import Callable -from collections.abc import Iterable -from collections.abc import Iterator -from collections.abc import MutableMapping -from functools import cached_property -from functools import lru_cache -import os -import pathlib -from pathlib import Path -from typing import Any -from typing import cast -from typing import NoReturn -from typing import overload -from typing import TYPE_CHECKING -from typing import TypeVar -import warnings - -import pluggy - -import _pytest._code -from _pytest._code import getfslineno -from _pytest._code.code import ExceptionInfo -from _pytest._code.code import TerminalRepr -from _pytest._code.code import Traceback -from _pytest._code.code import TracebackStyle -from _pytest.compat import LEGACY_PATH -from _pytest.compat import signature -from _pytest.config import Config -from _pytest.config import ConftestImportFailure -from _pytest.config.compat import _check_path -from _pytest.deprecated import NODE_CTOR_FSPATH_ARG -from _pytest.mark.structures import Mark -from _pytest.mark.structures import MarkDecorator -from _pytest.mark.structures import NodeKeywords -from _pytest.outcomes import fail -from _pytest.pathlib import absolutepath -from _pytest.stash import Stash -from _pytest.warning_types import PytestWarning - - -if TYPE_CHECKING: - from typing_extensions import Self - - # Imported here due to circular import. - from _pytest.main import Session - - -SEP = "/" - -tracebackcutdir = Path(_pytest.__file__).parent - - -_T = TypeVar("_T") - - -def _imply_path( - node_type: type[Node], - path: Path | None, - fspath: LEGACY_PATH | None, -) -> Path: - if fspath is not None: - warnings.warn( - NODE_CTOR_FSPATH_ARG.format( - node_type_name=node_type.__name__, - ), - stacklevel=6, - ) - if path is not None: - if fspath is not None: - _check_path(path, fspath) - return path - else: - assert fspath is not None - return Path(fspath) - - -_NodeType = TypeVar("_NodeType", bound="Node") - - -class NodeMeta(abc.ABCMeta): - """Metaclass used by :class:`Node` to enforce that direct construction raises - :class:`Failed`. - - This behaviour supports the indirection introduced with :meth:`Node.from_parent`, - the named constructor to be used instead of direct construction. The design - decision to enforce indirection with :class:`NodeMeta` was made as a - temporary aid for refactoring the collection tree, which was diagnosed to - have :class:`Node` objects whose creational patterns were overly entangled. - Once the refactoring is complete, this metaclass can be removed. - - See https://github.com/pytest-dev/pytest/projects/3 for an overview of the - progress on detangling the :class:`Node` classes. - """ - - def __call__(cls, *k, **kw) -> NoReturn: - msg = ( - "Direct construction of {name} has been deprecated, please use {name}.from_parent.\n" - "See " - "https://docs.pytest.org/en/stable/deprecations.html#node-construction-changed-to-node-from-parent" - " for more details." - ).format(name=f"{cls.__module__}.{cls.__name__}") - fail(msg, pytrace=False) - - def _create(cls: type[_T], *k, **kw) -> _T: - try: - return super().__call__(*k, **kw) # type: ignore[no-any-return,misc] - except TypeError: - sig = signature(getattr(cls, "__init__")) - known_kw = {k: v for k, v in kw.items() if k in sig.parameters} - from .warning_types import PytestDeprecationWarning - - warnings.warn( - PytestDeprecationWarning( - f"{cls} is not using a cooperative constructor and only takes {set(known_kw)}.\n" - "See https://docs.pytest.org/en/stable/deprecations.html" - "#constructors-of-custom-pytest-node-subclasses-should-take-kwargs " - "for more details." - ) - ) - - return super().__call__(*k, **known_kw) # type: ignore[no-any-return,misc] - - -class Node(abc.ABC, metaclass=NodeMeta): - r"""Base class of :class:`Collector` and :class:`Item`, the components of - the test collection tree. - - ``Collector``\'s are the internal nodes of the tree, and ``Item``\'s are the - leaf nodes. - """ - - # Implemented in the legacypath plugin. - #: A ``LEGACY_PATH`` copy of the :attr:`path` attribute. Intended for usage - #: for methods not migrated to ``pathlib.Path`` yet, such as - #: :meth:`Item.reportinfo `. Will be deprecated in - #: a future release, prefer using :attr:`path` instead. - fspath: LEGACY_PATH - - # Use __slots__ to make attribute access faster. - # Note that __dict__ is still available. - __slots__ = ( - "__dict__", - "_nodeid", - "_store", - "config", - "name", - "parent", - "path", - "session", - ) - - def __init__( - self, - name: str, - parent: Node | None = None, - config: Config | None = None, - session: Session | None = None, - fspath: LEGACY_PATH | None = None, - path: Path | None = None, - nodeid: str | None = None, - ) -> None: - #: A unique name within the scope of the parent node. - self.name: str = name - - #: The parent collector node. - self.parent = parent - - if config: - #: The pytest config object. - self.config: Config = config - else: - if not parent: - raise TypeError("config or parent must be provided") - self.config = parent.config - - if session: - #: The pytest session this node is part of. - self.session: Session = session - else: - if not parent: - raise TypeError("session or parent must be provided") - self.session = parent.session - - if path is None and fspath is None: - path = getattr(parent, "path", None) - #: Filesystem path where this node was collected from (can be None). - self.path: pathlib.Path = _imply_path(type(self), path, fspath=fspath) - - # The explicit annotation is to avoid publicly exposing NodeKeywords. - #: Keywords/markers collected from all scopes. - self.keywords: MutableMapping[str, Any] = NodeKeywords(self) - - #: The marker objects belonging to this node. - self.own_markers: list[Mark] = [] - - #: Allow adding of extra keywords to use for matching. - self.extra_keyword_matches: set[str] = set() - - if nodeid is not None: - assert "::()" not in nodeid - self._nodeid = nodeid - else: - if not self.parent: - raise TypeError("nodeid or parent must be provided") - self._nodeid = self.parent.nodeid + "::" + self.name - - #: A place where plugins can store information on the node for their - #: own use. - self.stash: Stash = Stash() - # Deprecated alias. Was never public. Can be removed in a few releases. - self._store = self.stash - - @classmethod - def from_parent(cls, parent: Node, **kw) -> Self: - """Public constructor for Nodes. - - This indirection got introduced in order to enable removing - the fragile logic from the node constructors. - - Subclasses can use ``super().from_parent(...)`` when overriding the - construction. - - :param parent: The parent node of this Node. - """ - if "config" in kw: - raise TypeError("config is not a valid argument for from_parent") - if "session" in kw: - raise TypeError("session is not a valid argument for from_parent") - return cls._create(parent=parent, **kw) - - @property - def ihook(self) -> pluggy.HookRelay: - """fspath-sensitive hook proxy used to call pytest hooks.""" - return self.session.gethookproxy(self.path) - - def __repr__(self) -> str: - return "<{} {}>".format(self.__class__.__name__, getattr(self, "name", None)) - - def warn(self, warning: Warning) -> None: - """Issue a warning for this Node. - - Warnings will be displayed after the test session, unless explicitly suppressed. - - :param Warning warning: - The warning instance to issue. - - :raises ValueError: If ``warning`` instance is not a subclass of Warning. - - Example usage: - - .. code-block:: python - - node.warn(PytestWarning("some message")) - node.warn(UserWarning("some message")) - - .. versionchanged:: 6.2 - Any subclass of :class:`Warning` is now accepted, rather than only - :class:`PytestWarning ` subclasses. - """ - # enforce type checks here to avoid getting a generic type error later otherwise. - if not isinstance(warning, Warning): - raise ValueError( - f"warning must be an instance of Warning or subclass, got {warning!r}" - ) - path, lineno = get_fslocation_from_item(self) - assert lineno is not None - warnings.warn_explicit( - warning, - category=None, - filename=str(path), - lineno=lineno + 1, - ) - - # Methods for ordering nodes. - - @property - def nodeid(self) -> str: - """A ::-separated string denoting its collection tree address.""" - return self._nodeid - - def __hash__(self) -> int: - return hash(self._nodeid) - - def setup(self) -> None: - pass - - def teardown(self) -> None: - pass - - def iter_parents(self) -> Iterator[Node]: - """Iterate over all parent collectors starting from and including self - up to the root of the collection tree. - - .. versionadded:: 8.1 - """ - parent: Node | None = self - while parent is not None: - yield parent - parent = parent.parent - - def listchain(self) -> list[Node]: - """Return a list of all parent collectors starting from the root of the - collection tree down to and including self.""" - chain = [] - item: Node | None = self - while item is not None: - chain.append(item) - item = item.parent - chain.reverse() - return chain - - def add_marker(self, marker: str | MarkDecorator, append: bool = True) -> None: - """Dynamically add a marker object to the node. - - :param marker: - The marker. - :param append: - Whether to append the marker, or prepend it. - """ - from _pytest.mark import MARK_GEN - - if isinstance(marker, MarkDecorator): - marker_ = marker - elif isinstance(marker, str): - marker_ = getattr(MARK_GEN, marker) - else: - raise ValueError("is not a string or pytest.mark.* Marker") - self.keywords[marker_.name] = marker_ - if append: - self.own_markers.append(marker_.mark) - else: - self.own_markers.insert(0, marker_.mark) - - def iter_markers(self, name: str | None = None) -> Iterator[Mark]: - """Iterate over all markers of the node. - - :param name: If given, filter the results by the name attribute. - :returns: An iterator of the markers of the node. - """ - return (x[1] for x in self.iter_markers_with_node(name=name)) - - def iter_markers_with_node( - self, name: str | None = None - ) -> Iterator[tuple[Node, Mark]]: - """Iterate over all markers of the node. - - :param name: If given, filter the results by the name attribute. - :returns: An iterator of (node, mark) tuples. - """ - for node in self.iter_parents(): - for mark in node.own_markers: - if name is None or getattr(mark, "name", None) == name: - yield node, mark - - @overload - def get_closest_marker(self, name: str) -> Mark | None: ... - - @overload - def get_closest_marker(self, name: str, default: Mark) -> Mark: ... - - def get_closest_marker(self, name: str, default: Mark | None = None) -> Mark | None: - """Return the first marker matching the name, from closest (for - example function) to farther level (for example module level). - - :param default: Fallback return value if no marker was found. - :param name: Name to filter by. - """ - return next(self.iter_markers(name=name), default) - - def listextrakeywords(self) -> set[str]: - """Return a set of all extra keywords in self and any parents.""" - extra_keywords: set[str] = set() - for item in self.listchain(): - extra_keywords.update(item.extra_keyword_matches) - return extra_keywords - - def listnames(self) -> list[str]: - return [x.name for x in self.listchain()] - - def addfinalizer(self, fin: Callable[[], object]) -> None: - """Register a function to be called without arguments when this node is - finalized. - - This method can only be called when this node is active - in a setup chain, for example during self.setup(). - """ - self.session._setupstate.addfinalizer(fin, self) - - def getparent(self, cls: type[_NodeType]) -> _NodeType | None: - """Get the closest parent node (including self) which is an instance of - the given class. - - :param cls: The node class to search for. - :returns: The node, if found. - """ - for node in self.iter_parents(): - if isinstance(node, cls): - return node - return None - - def _traceback_filter(self, excinfo: ExceptionInfo[BaseException]) -> Traceback: - return excinfo.traceback - - def _repr_failure_py( - self, - excinfo: ExceptionInfo[BaseException], - style: TracebackStyle | None = None, - ) -> TerminalRepr: - from _pytest.fixtures import FixtureLookupError - - if isinstance(excinfo.value, ConftestImportFailure): - excinfo = ExceptionInfo.from_exception(excinfo.value.cause) - if isinstance(excinfo.value, fail.Exception): - if not excinfo.value.pytrace: - style = "value" - if isinstance(excinfo.value, FixtureLookupError): - return excinfo.value.formatrepr() - - tbfilter: bool | Callable[[ExceptionInfo[BaseException]], Traceback] - if self.config.getoption("fulltrace", False): - style = "long" - tbfilter = False - else: - tbfilter = self._traceback_filter - if style == "auto": - style = "long" - # XXX should excinfo.getrepr record all data and toterminal() process it? - if style is None: - if self.config.getoption("tbstyle", "auto") == "short": - style = "short" - else: - style = "long" - - if self.config.get_verbosity() > 1: - truncate_locals = False - else: - truncate_locals = True - - truncate_args = False if self.config.get_verbosity() > 2 else True - - # excinfo.getrepr() formats paths relative to the CWD if `abspath` is False. - # It is possible for a fixture/test to change the CWD while this code runs, which - # would then result in the user seeing confusing paths in the failure message. - # To fix this, if the CWD changed, always display the full absolute path. - # It will be better to just always display paths relative to invocation_dir, but - # this requires a lot of plumbing (#6428). - try: - abspath = Path(os.getcwd()) != self.config.invocation_params.dir - except OSError: - abspath = True - - return excinfo.getrepr( - funcargs=True, - abspath=abspath, - showlocals=self.config.getoption("showlocals", False), - style=style, - tbfilter=tbfilter, - truncate_locals=truncate_locals, - truncate_args=truncate_args, - ) - - def repr_failure( - self, - excinfo: ExceptionInfo[BaseException], - style: TracebackStyle | None = None, - ) -> str | TerminalRepr: - """Return a representation of a collection or test failure. - - .. seealso:: :ref:`non-python tests` - - :param excinfo: Exception information for the failure. - """ - return self._repr_failure_py(excinfo, style) - - -def get_fslocation_from_item(node: Node) -> tuple[str | Path, int | None]: - """Try to extract the actual location from a node, depending on available attributes: - - * "location": a pair (path, lineno) - * "obj": a Python object that the node wraps. - * "path": just a path - - :rtype: A tuple of (str|Path, int) with filename and 0-based line number. - """ - # See Item.location. - location: tuple[str, int | None, str] | None = getattr(node, "location", None) - if location is not None: - return location[:2] - obj = getattr(node, "obj", None) - if obj is not None: - return getfslineno(obj) - return getattr(node, "path", "unknown location"), -1 - - -class Collector(Node, abc.ABC): - """Base class of all collectors. - - Collector create children through `collect()` and thus iteratively build - the collection tree. - """ - - class CollectError(Exception): - """An error during collection, contains a custom message.""" - - @abc.abstractmethod - def collect(self) -> Iterable[Item | Collector]: - """Collect children (items and collectors) for this collector.""" - raise NotImplementedError("abstract") - - # TODO: This omits the style= parameter which breaks Liskov Substitution. - def repr_failure( # type: ignore[override] - self, excinfo: ExceptionInfo[BaseException] - ) -> str | TerminalRepr: - """Return a representation of a collection failure. - - :param excinfo: Exception information for the failure. - """ - if isinstance(excinfo.value, self.CollectError) and not self.config.getoption( - "fulltrace", False - ): - exc = excinfo.value - return str(exc.args[0]) - - # Respect explicit tbstyle option, but default to "short" - # (_repr_failure_py uses "long" with "fulltrace" option always). - tbstyle = self.config.getoption("tbstyle", "auto") - if tbstyle == "auto": - tbstyle = "short" - - return self._repr_failure_py(excinfo, style=tbstyle) - - def _traceback_filter(self, excinfo: ExceptionInfo[BaseException]) -> Traceback: - if hasattr(self, "path"): - traceback = excinfo.traceback - ntraceback = traceback.cut(path=self.path) - if ntraceback == traceback: - ntraceback = ntraceback.cut(excludepath=tracebackcutdir) - return ntraceback.filter(excinfo) - return excinfo.traceback - - -@lru_cache(maxsize=1000) -def _check_initialpaths_for_relpath( - initial_paths: frozenset[Path], path: Path -) -> str | None: - if path in initial_paths: - return "" - - for parent in path.parents: - if parent in initial_paths: - return str(path.relative_to(parent)) - - return None - - -class FSCollector(Collector, abc.ABC): - """Base class for filesystem collectors.""" - - def __init__( - self, - fspath: LEGACY_PATH | None = None, - path_or_parent: Path | Node | None = None, - path: Path | None = None, - name: str | None = None, - parent: Node | None = None, - config: Config | None = None, - session: Session | None = None, - nodeid: str | None = None, - ) -> None: - if path_or_parent: - if isinstance(path_or_parent, Node): - assert parent is None - parent = cast(FSCollector, path_or_parent) - elif isinstance(path_or_parent, Path): - assert path is None - path = path_or_parent - - path = _imply_path(type(self), path, fspath=fspath) - if name is None: - name = path.name - if parent is not None and parent.path != path: - try: - rel = path.relative_to(parent.path) - except ValueError: - pass - else: - name = str(rel) - name = name.replace(os.sep, SEP) - self.path = path - - if session is None: - assert parent is not None - session = parent.session - - if nodeid is None: - try: - nodeid = str(self.path.relative_to(session.config.rootpath)) - except ValueError: - nodeid = _check_initialpaths_for_relpath(session._initialpaths, path) - - if nodeid and os.sep != SEP: - nodeid = nodeid.replace(os.sep, SEP) - - super().__init__( - name=name, - parent=parent, - config=config, - session=session, - nodeid=nodeid, - path=path, - ) - - @classmethod - def from_parent( - cls, - parent, - *, - fspath: LEGACY_PATH | None = None, - path: Path | None = None, - **kw, - ) -> Self: - """The public constructor.""" - return super().from_parent(parent=parent, fspath=fspath, path=path, **kw) - - -class File(FSCollector, abc.ABC): - """Base class for collecting tests from a file. - - :ref:`non-python tests`. - """ - - -class Directory(FSCollector, abc.ABC): - """Base class for collecting files from a directory. - - A basic directory collector does the following: goes over the files and - sub-directories in the directory and creates collectors for them by calling - the hooks :hook:`pytest_collect_directory` and :hook:`pytest_collect_file`, - after checking that they are not ignored using - :hook:`pytest_ignore_collect`. - - The default directory collectors are :class:`~pytest.Dir` and - :class:`~pytest.Package`. - - .. versionadded:: 8.0 - - :ref:`custom directory collectors`. - """ - - -class Item(Node, abc.ABC): - """Base class of all test invocation items. - - Note that for a single function there might be multiple test invocation items. - """ - - nextitem = None - - def __init__( - self, - name, - parent=None, - config: Config | None = None, - session: Session | None = None, - nodeid: str | None = None, - **kw, - ) -> None: - # The first two arguments are intentionally passed positionally, - # to keep plugins who define a node type which inherits from - # (pytest.Item, pytest.File) working (see issue #8435). - # They can be made kwargs when the deprecation above is done. - super().__init__( - name, - parent, - config=config, - session=session, - nodeid=nodeid, - **kw, - ) - self._report_sections: list[tuple[str, str, str]] = [] - - #: A list of tuples (name, value) that holds user defined properties - #: for this test. - self.user_properties: list[tuple[str, object]] = [] - - self._check_item_and_collector_diamond_inheritance() - - def _check_item_and_collector_diamond_inheritance(self) -> None: - """ - Check if the current type inherits from both File and Collector - at the same time, emitting a warning accordingly (#8447). - """ - cls = type(self) - - # We inject an attribute in the type to avoid issuing this warning - # for the same class more than once, which is not helpful. - # It is a hack, but was deemed acceptable in order to avoid - # flooding the user in the common case. - attr_name = "_pytest_diamond_inheritance_warning_shown" - if getattr(cls, attr_name, False): - return - setattr(cls, attr_name, True) - - problems = ", ".join( - base.__name__ for base in cls.__bases__ if issubclass(base, Collector) - ) - if problems: - warnings.warn( - f"{cls.__name__} is an Item subclass and should not be a collector, " - f"however its bases {problems} are collectors.\n" - "Please split the Collectors and the Item into separate node types.\n" - "Pytest Doc example: https://docs.pytest.org/en/latest/example/nonpython.html\n" - "example pull request on a plugin: https://github.com/asmeurer/pytest-flakes/pull/40/", - PytestWarning, - ) - - @abc.abstractmethod - def runtest(self) -> None: - """Run the test case for this item. - - Must be implemented by subclasses. - - .. seealso:: :ref:`non-python tests` - """ - raise NotImplementedError("runtest must be implemented by Item subclass") - - def add_report_section(self, when: str, key: str, content: str) -> None: - """Add a new report section, similar to what's done internally to add - stdout and stderr captured output:: - - item.add_report_section("call", "stdout", "report section contents") - - :param str when: - One of the possible capture states, ``"setup"``, ``"call"``, ``"teardown"``. - :param str key: - Name of the section, can be customized at will. Pytest uses ``"stdout"`` and - ``"stderr"`` internally. - :param str content: - The full contents as a string. - """ - if content: - self._report_sections.append((when, key, content)) - - def reportinfo(self) -> tuple[os.PathLike[str] | str, int | None, str]: - """Get location information for this item for test reports. - - Returns a tuple with three elements: - - - The path of the test (default ``self.path``) - - The 0-based line number of the test (default ``None``) - - A name of the test to be shown (default ``""``) - - .. seealso:: :ref:`non-python tests` - """ - return self.path, None, "" - - @cached_property - def location(self) -> tuple[str, int | None, str]: - """ - Returns a tuple of ``(relfspath, lineno, testname)`` for this item - where ``relfspath`` is file path relative to ``config.rootpath`` - and lineno is a 0-based line number. - """ - location = self.reportinfo() - path = absolutepath(location[0]) - relfspath = self.session._node_location_to_relpath(path) - assert type(location[2]) is str - return (relfspath, location[1], location[2]) diff --git a/.venv/lib/python3.12/site-packages/_pytest/outcomes.py b/.venv/lib/python3.12/site-packages/_pytest/outcomes.py deleted file mode 100644 index 766be95..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/outcomes.py +++ /dev/null @@ -1,308 +0,0 @@ -"""Exception classes and constants handling test outcomes as well as -functions creating them.""" - -from __future__ import annotations - -import sys -from typing import Any -from typing import ClassVar -from typing import NoReturn - -from .warning_types import PytestDeprecationWarning - - -class OutcomeException(BaseException): - """OutcomeException and its subclass instances indicate and contain info - about test and collection outcomes.""" - - def __init__(self, msg: str | None = None, pytrace: bool = True) -> None: - if msg is not None and not isinstance(msg, str): - error_msg = ( # type: ignore[unreachable] - "{} expected string as 'msg' parameter, got '{}' instead.\n" - "Perhaps you meant to use a mark?" - ) - raise TypeError(error_msg.format(type(self).__name__, type(msg).__name__)) - super().__init__(msg) - self.msg = msg - self.pytrace = pytrace - - def __repr__(self) -> str: - if self.msg is not None: - return self.msg - return f"<{self.__class__.__name__} instance>" - - __str__ = __repr__ - - -TEST_OUTCOME = (OutcomeException, Exception) - - -class Skipped(OutcomeException): - # XXX hackish: on 3k we fake to live in the builtins - # in order to have Skipped exception printing shorter/nicer - __module__ = "builtins" - - def __init__( - self, - msg: str | None = None, - pytrace: bool = True, - allow_module_level: bool = False, - *, - _use_item_location: bool = False, - ) -> None: - super().__init__(msg=msg, pytrace=pytrace) - self.allow_module_level = allow_module_level - # If true, the skip location is reported as the item's location, - # instead of the place that raises the exception/calls skip(). - self._use_item_location = _use_item_location - - -class Failed(OutcomeException): - """Raised from an explicit call to pytest.fail().""" - - __module__ = "builtins" - - -class Exit(Exception): - """Raised for immediate program exits (no tracebacks/summaries).""" - - def __init__( - self, msg: str = "unknown reason", returncode: int | None = None - ) -> None: - self.msg = msg - self.returncode = returncode - super().__init__(msg) - - -class XFailed(Failed): - """Raised from an explicit call to pytest.xfail().""" - - -class _Exit: - """Exit testing process. - - :param reason: - The message to show as the reason for exiting pytest. reason has a default value - only because `msg` is deprecated. - - :param returncode: - Return code to be used when exiting pytest. None means the same as ``0`` (no error), - same as :func:`sys.exit`. - - :raises pytest.exit.Exception: - The exception that is raised. - """ - - Exception: ClassVar[type[Exit]] = Exit - - def __call__(self, reason: str = "", returncode: int | None = None) -> NoReturn: - __tracebackhide__ = True - raise Exit(msg=reason, returncode=returncode) - - -exit: _Exit = _Exit() - - -class _Skip: - """Skip an executing test with the given message. - - This function should be called only during testing (setup, call or teardown) or - during collection by using the ``allow_module_level`` flag. This function can - be called in doctests as well. - - :param reason: - The message to show the user as reason for the skip. - - :param allow_module_level: - Allows this function to be called at module level. - Raising the skip exception at module level will stop - the execution of the module and prevent the collection of all tests in the module, - even those defined before the `skip` call. - - Defaults to False. - - :raises pytest.skip.Exception: - The exception that is raised. - - .. note:: - It is better to use the :ref:`pytest.mark.skipif ref` marker when - possible to declare a test to be skipped under certain conditions - like mismatching platforms or dependencies. - Similarly, use the ``# doctest: +SKIP`` directive (see :py:data:`doctest.SKIP`) - to skip a doctest statically. - """ - - Exception: ClassVar[type[Skipped]] = Skipped - - def __call__(self, reason: str = "", allow_module_level: bool = False) -> NoReturn: - __tracebackhide__ = True - raise Skipped(msg=reason, allow_module_level=allow_module_level) - - -skip: _Skip = _Skip() - - -class _Fail: - """Explicitly fail an executing test with the given message. - - :param reason: - The message to show the user as reason for the failure. - - :param pytrace: - If False, msg represents the full failure information and no - python traceback will be reported. - - :raises pytest.fail.Exception: - The exception that is raised. - """ - - Exception: ClassVar[type[Failed]] = Failed - - def __call__(self, reason: str = "", pytrace: bool = True) -> NoReturn: - __tracebackhide__ = True - raise Failed(msg=reason, pytrace=pytrace) - - -fail: _Fail = _Fail() - - -class _XFail: - """Imperatively xfail an executing test or setup function with the given reason. - - This function should be called only during testing (setup, call or teardown). - - No other code is executed after using ``xfail()`` (it is implemented - internally by raising an exception). - - :param reason: - The message to show the user as reason for the xfail. - - .. note:: - It is better to use the :ref:`pytest.mark.xfail ref` marker when - possible to declare a test to be xfailed under certain conditions - like known bugs or missing features. - - :raises pytest.xfail.Exception: - The exception that is raised. - """ - - Exception: ClassVar[type[XFailed]] = XFailed - - def __call__(self, reason: str = "") -> NoReturn: - __tracebackhide__ = True - raise XFailed(msg=reason) - - -xfail: _XFail = _XFail() - - -def importorskip( - modname: str, - minversion: str | None = None, - reason: str | None = None, - *, - exc_type: type[ImportError] | None = None, -) -> Any: - """Import and return the requested module ``modname``, or skip the - current test if the module cannot be imported. - - :param modname: - The name of the module to import. - :param minversion: - If given, the imported module's ``__version__`` attribute must be at - least this minimal version, otherwise the test is still skipped. - :param reason: - If given, this reason is shown as the message when the module cannot - be imported. - :param exc_type: - The exception that should be captured in order to skip modules. - Must be :py:class:`ImportError` or a subclass. - - If the module can be imported but raises :class:`ImportError`, pytest will - issue a warning to the user, as often users expect the module not to be - found (which would raise :class:`ModuleNotFoundError` instead). - - This warning can be suppressed by passing ``exc_type=ImportError`` explicitly. - - See :ref:`import-or-skip-import-error` for details. - - - :returns: - The imported module. This should be assigned to its canonical name. - - :raises pytest.skip.Exception: - If the module cannot be imported. - - Example:: - - docutils = pytest.importorskip("docutils") - - .. versionadded:: 8.2 - - The ``exc_type`` parameter. - """ - import warnings - - __tracebackhide__ = True - compile(modname, "", "eval") # to catch syntaxerrors - - # Until pytest 9.1, we will warn the user if we catch ImportError (instead of ModuleNotFoundError), - # as this might be hiding an installation/environment problem, which is not usually what is intended - # when using importorskip() (#11523). - # In 9.1, to keep the function signature compatible, we just change the code below to: - # 1. Use `exc_type = ModuleNotFoundError` if `exc_type` is not given. - # 2. Remove `warn_on_import` and the warning handling. - if exc_type is None: - exc_type = ImportError - warn_on_import_error = True - else: - warn_on_import_error = False - - skipped: Skipped | None = None - warning: Warning | None = None - - with warnings.catch_warnings(): - # Make sure to ignore ImportWarnings that might happen because - # of existing directories with the same name we're trying to - # import but without a __init__.py file. - warnings.simplefilter("ignore") - - try: - __import__(modname) - except exc_type as exc: - # Do not raise or issue warnings inside the catch_warnings() block. - if reason is None: - reason = f"could not import {modname!r}: {exc}" - skipped = Skipped(reason, allow_module_level=True) - - if warn_on_import_error and not isinstance(exc, ModuleNotFoundError): - lines = [ - "", - f"Module '{modname}' was found, but when imported by pytest it raised:", - f" {exc!r}", - "In pytest 9.1 this warning will become an error by default.", - "You can fix the underlying problem, or alternatively overwrite this behavior and silence this " - "warning by passing exc_type=ImportError explicitly.", - "See https://docs.pytest.org/en/stable/deprecations.html#pytest-importorskip-default-behavior-regarding-importerror", - ] - warning = PytestDeprecationWarning("\n".join(lines)) - - if warning: - warnings.warn(warning, stacklevel=2) - if skipped: - raise skipped - - mod = sys.modules[modname] - if minversion is None: - return mod - verattr = getattr(mod, "__version__", None) - if minversion is not None: - # Imported lazily to improve start-up time. - from packaging.version import Version - - if verattr is None or Version(verattr) < Version(minversion): - raise Skipped( - f"module {modname!r} has __version__ {verattr!r}, required is: {minversion!r}", - allow_module_level=True, - ) - return mod diff --git a/.venv/lib/python3.12/site-packages/_pytest/pastebin.py b/.venv/lib/python3.12/site-packages/_pytest/pastebin.py deleted file mode 100644 index c7b39d9..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/pastebin.py +++ /dev/null @@ -1,117 +0,0 @@ -# mypy: allow-untyped-defs -"""Submit failure or test session information to a pastebin service.""" - -from __future__ import annotations - -from io import StringIO -import tempfile -from typing import IO - -from _pytest.config import Config -from _pytest.config import create_terminal_writer -from _pytest.config.argparsing import Parser -from _pytest.stash import StashKey -from _pytest.terminal import TerminalReporter -import pytest - - -pastebinfile_key = StashKey[IO[bytes]]() - - -def pytest_addoption(parser: Parser) -> None: - group = parser.getgroup("terminal reporting") - group.addoption( - "--pastebin", - metavar="mode", - action="store", - dest="pastebin", - default=None, - choices=["failed", "all"], - help="Send failed|all info to bpaste.net pastebin service", - ) - - -@pytest.hookimpl(trylast=True) -def pytest_configure(config: Config) -> None: - if config.option.pastebin == "all": - tr = config.pluginmanager.getplugin("terminalreporter") - # If no terminal reporter plugin is present, nothing we can do here; - # this can happen when this function executes in a worker node - # when using pytest-xdist, for example. - if tr is not None: - # pastebin file will be UTF-8 encoded binary file. - config.stash[pastebinfile_key] = tempfile.TemporaryFile("w+b") - oldwrite = tr._tw.write - - def tee_write(s, **kwargs): - oldwrite(s, **kwargs) - if isinstance(s, str): - s = s.encode("utf-8") - config.stash[pastebinfile_key].write(s) - - tr._tw.write = tee_write - - -def pytest_unconfigure(config: Config) -> None: - if pastebinfile_key in config.stash: - pastebinfile = config.stash[pastebinfile_key] - # Get terminal contents and delete file. - pastebinfile.seek(0) - sessionlog = pastebinfile.read() - pastebinfile.close() - del config.stash[pastebinfile_key] - # Undo our patching in the terminal reporter. - tr = config.pluginmanager.getplugin("terminalreporter") - del tr._tw.__dict__["write"] - # Write summary. - tr.write_sep("=", "Sending information to Paste Service") - pastebinurl = create_new_paste(sessionlog) - tr.write_line(f"pastebin session-log: {pastebinurl}\n") - - -def create_new_paste(contents: str | bytes) -> str: - """Create a new paste using the bpaste.net service. - - :contents: Paste contents string. - :returns: URL to the pasted contents, or an error message. - """ - import re - from urllib.error import HTTPError - from urllib.parse import urlencode - from urllib.request import urlopen - - params = {"code": contents, "lexer": "text", "expiry": "1week"} - url = "https://bpa.st" - try: - response: str = ( - urlopen(url, data=urlencode(params).encode("ascii")).read().decode("utf-8") - ) - except HTTPError as e: - with e: # HTTPErrors are also http responses that must be closed! - return f"bad response: {e}" - except OSError as e: # eg urllib.error.URLError - return f"bad response: {e}" - m = re.search(r'href="/raw/(\w+)"', response) - if m: - return f"{url}/show/{m.group(1)}" - else: - return "bad response: invalid format ('" + response + "')" - - -def pytest_terminal_summary(terminalreporter: TerminalReporter) -> None: - if terminalreporter.config.option.pastebin != "failed": - return - if "failed" in terminalreporter.stats: - terminalreporter.write_sep("=", "Sending information to Paste Service") - for rep in terminalreporter.stats["failed"]: - try: - msg = rep.longrepr.reprtraceback.reprentries[-1].reprfileloc - except AttributeError: - msg = terminalreporter._getfailureheadline(rep) - file = StringIO() - tw = create_terminal_writer(terminalreporter.config, file) - rep.toterminal(tw) - s = file.getvalue() - assert len(s) - pastebinurl = create_new_paste(s) - terminalreporter.write_line(f"{msg} --> {pastebinurl}") diff --git a/.venv/lib/python3.12/site-packages/_pytest/pathlib.py b/.venv/lib/python3.12/site-packages/_pytest/pathlib.py deleted file mode 100644 index cd15434..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/pathlib.py +++ /dev/null @@ -1,1063 +0,0 @@ -from __future__ import annotations - -import atexit -from collections.abc import Callable -from collections.abc import Iterable -from collections.abc import Iterator -import contextlib -from enum import Enum -from errno import EBADF -from errno import ELOOP -from errno import ENOENT -from errno import ENOTDIR -import fnmatch -from functools import partial -from importlib.machinery import ModuleSpec -from importlib.machinery import PathFinder -import importlib.util -import itertools -import os -from os.path import expanduser -from os.path import expandvars -from os.path import isabs -from os.path import sep -from pathlib import Path -from pathlib import PurePath -from posixpath import sep as posix_sep -import shutil -import sys -import types -from types import ModuleType -from typing import Any -from typing import TypeVar -import uuid -import warnings - -from _pytest.compat import assert_never -from _pytest.outcomes import skip -from _pytest.warning_types import PytestWarning - - -if sys.version_info < (3, 11): - from importlib._bootstrap_external import _NamespaceLoader as NamespaceLoader -else: - from importlib.machinery import NamespaceLoader - -LOCK_TIMEOUT = 60 * 60 * 24 * 3 - -_AnyPurePath = TypeVar("_AnyPurePath", bound=PurePath) - -# The following function, variables and comments were -# copied from cpython 3.9 Lib/pathlib.py file. - -# EBADF - guard against macOS `stat` throwing EBADF -_IGNORED_ERRORS = (ENOENT, ENOTDIR, EBADF, ELOOP) - -_IGNORED_WINERRORS = ( - 21, # ERROR_NOT_READY - drive exists but is not accessible - 1921, # ERROR_CANT_RESOLVE_FILENAME - fix for broken symlink pointing to itself -) - - -def _ignore_error(exception: Exception) -> bool: - return ( - getattr(exception, "errno", None) in _IGNORED_ERRORS - or getattr(exception, "winerror", None) in _IGNORED_WINERRORS - ) - - -def get_lock_path(path: _AnyPurePath) -> _AnyPurePath: - return path.joinpath(".lock") - - -def on_rm_rf_error( - func: Callable[..., Any] | None, - path: str, - excinfo: BaseException - | tuple[type[BaseException], BaseException, types.TracebackType | None], - *, - start_path: Path, -) -> bool: - """Handle known read-only errors during rmtree. - - The returned value is used only by our own tests. - """ - if isinstance(excinfo, BaseException): - exc = excinfo - else: - exc = excinfo[1] - - # Another process removed the file in the middle of the "rm_rf" (xdist for example). - # More context: https://github.com/pytest-dev/pytest/issues/5974#issuecomment-543799018 - if isinstance(exc, FileNotFoundError): - return False - - if not isinstance(exc, PermissionError): - warnings.warn( - PytestWarning(f"(rm_rf) error removing {path}\n{type(exc)}: {exc}") - ) - return False - - if func not in (os.rmdir, os.remove, os.unlink): - if func not in (os.open,): - warnings.warn( - PytestWarning( - f"(rm_rf) unknown function {func} when removing {path}:\n{type(exc)}: {exc}" - ) - ) - return False - - # Chmod + retry. - import stat - - def chmod_rw(p: str) -> None: - mode = os.stat(p).st_mode - os.chmod(p, mode | stat.S_IRUSR | stat.S_IWUSR) - - # For files, we need to recursively go upwards in the directories to - # ensure they all are also writable. - p = Path(path) - if p.is_file(): - for parent in p.parents: - chmod_rw(str(parent)) - # Stop when we reach the original path passed to rm_rf. - if parent == start_path: - break - chmod_rw(str(path)) - - func(path) - return True - - -def ensure_extended_length_path(path: Path) -> Path: - """Get the extended-length version of a path (Windows). - - On Windows, by default, the maximum length of a path (MAX_PATH) is 260 - characters, and operations on paths longer than that fail. But it is possible - to overcome this by converting the path to "extended-length" form before - performing the operation: - https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#maximum-path-length-limitation - - On Windows, this function returns the extended-length absolute version of path. - On other platforms it returns path unchanged. - """ - if sys.platform.startswith("win32"): - path = path.resolve() - path = Path(get_extended_length_path_str(str(path))) - return path - - -def get_extended_length_path_str(path: str) -> str: - """Convert a path to a Windows extended length path.""" - long_path_prefix = "\\\\?\\" - unc_long_path_prefix = "\\\\?\\UNC\\" - if path.startswith((long_path_prefix, unc_long_path_prefix)): - return path - # UNC - if path.startswith("\\\\"): - return unc_long_path_prefix + path[2:] - return long_path_prefix + path - - -def rm_rf(path: Path) -> None: - """Remove the path contents recursively, even if some elements - are read-only.""" - path = ensure_extended_length_path(path) - onerror = partial(on_rm_rf_error, start_path=path) - if sys.version_info >= (3, 12): - shutil.rmtree(str(path), onexc=onerror) - else: - shutil.rmtree(str(path), onerror=onerror) - - -def find_prefixed(root: Path, prefix: str) -> Iterator[os.DirEntry[str]]: - """Find all elements in root that begin with the prefix, case-insensitive.""" - l_prefix = prefix.lower() - for x in os.scandir(root): - if x.name.lower().startswith(l_prefix): - yield x - - -def extract_suffixes(iter: Iterable[os.DirEntry[str]], prefix: str) -> Iterator[str]: - """Return the parts of the paths following the prefix. - - :param iter: Iterator over path names. - :param prefix: Expected prefix of the path names. - """ - p_len = len(prefix) - for entry in iter: - yield entry.name[p_len:] - - -def find_suffixes(root: Path, prefix: str) -> Iterator[str]: - """Combine find_prefixes and extract_suffixes.""" - return extract_suffixes(find_prefixed(root, prefix), prefix) - - -def parse_num(maybe_num: str) -> int: - """Parse number path suffixes, returns -1 on error.""" - try: - return int(maybe_num) - except ValueError: - return -1 - - -def _force_symlink(root: Path, target: str | PurePath, link_to: str | Path) -> None: - """Helper to create the current symlink. - - It's full of race conditions that are reasonably OK to ignore - for the context of best effort linking to the latest test run. - - The presumption being that in case of much parallelism - the inaccuracy is going to be acceptable. - """ - current_symlink = root.joinpath(target) - try: - current_symlink.unlink() - except OSError: - pass - try: - current_symlink.symlink_to(link_to) - except Exception: - pass - - -def make_numbered_dir(root: Path, prefix: str, mode: int = 0o700) -> Path: - """Create a directory with an increased number as suffix for the given prefix.""" - for i in range(10): - # try up to 10 times to create the folder - max_existing = max(map(parse_num, find_suffixes(root, prefix)), default=-1) - new_number = max_existing + 1 - new_path = root.joinpath(f"{prefix}{new_number}") - try: - new_path.mkdir(mode=mode) - except Exception: - pass - else: - _force_symlink(root, prefix + "current", new_path) - return new_path - else: - raise OSError( - "could not create numbered dir with prefix " - f"{prefix} in {root} after 10 tries" - ) - - -def create_cleanup_lock(p: Path) -> Path: - """Create a lock to prevent premature folder cleanup.""" - lock_path = get_lock_path(p) - try: - fd = os.open(str(lock_path), os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o644) - except FileExistsError as e: - raise OSError(f"cannot create lockfile in {p}") from e - else: - pid = os.getpid() - spid = str(pid).encode() - os.write(fd, spid) - os.close(fd) - if not lock_path.is_file(): - raise OSError("lock path got renamed after successful creation") - return lock_path - - -def register_cleanup_lock_removal( - lock_path: Path, register: Any = atexit.register -) -> Any: - """Register a cleanup function for removing a lock, by default on atexit.""" - pid = os.getpid() - - def cleanup_on_exit(lock_path: Path = lock_path, original_pid: int = pid) -> None: - current_pid = os.getpid() - if current_pid != original_pid: - # fork - return - try: - lock_path.unlink() - except OSError: - pass - - return register(cleanup_on_exit) - - -def maybe_delete_a_numbered_dir(path: Path) -> None: - """Remove a numbered directory if its lock can be obtained and it does - not seem to be in use.""" - path = ensure_extended_length_path(path) - lock_path = None - try: - lock_path = create_cleanup_lock(path) - parent = path.parent - - garbage = parent.joinpath(f"garbage-{uuid.uuid4()}") - path.rename(garbage) - rm_rf(garbage) - except OSError: - # known races: - # * other process did a cleanup at the same time - # * deletable folder was found - # * process cwd (Windows) - return - finally: - # If we created the lock, ensure we remove it even if we failed - # to properly remove the numbered dir. - if lock_path is not None: - try: - lock_path.unlink() - except OSError: - pass - - -def ensure_deletable(path: Path, consider_lock_dead_if_created_before: float) -> bool: - """Check if `path` is deletable based on whether the lock file is expired.""" - if path.is_symlink(): - return False - lock = get_lock_path(path) - try: - if not lock.is_file(): - return True - except OSError: - # we might not have access to the lock file at all, in this case assume - # we don't have access to the entire directory (#7491). - return False - try: - lock_time = lock.stat().st_mtime - except Exception: - return False - else: - if lock_time < consider_lock_dead_if_created_before: - # We want to ignore any errors while trying to remove the lock such as: - # - PermissionDenied, like the file permissions have changed since the lock creation; - # - FileNotFoundError, in case another pytest process got here first; - # and any other cause of failure. - with contextlib.suppress(OSError): - lock.unlink() - return True - return False - - -def try_cleanup(path: Path, consider_lock_dead_if_created_before: float) -> None: - """Try to cleanup a folder if we can ensure it's deletable.""" - if ensure_deletable(path, consider_lock_dead_if_created_before): - maybe_delete_a_numbered_dir(path) - - -def cleanup_candidates(root: Path, prefix: str, keep: int) -> Iterator[Path]: - """List candidates for numbered directories to be removed - follows py.path.""" - max_existing = max(map(parse_num, find_suffixes(root, prefix)), default=-1) - max_delete = max_existing - keep - entries = find_prefixed(root, prefix) - entries, entries2 = itertools.tee(entries) - numbers = map(parse_num, extract_suffixes(entries2, prefix)) - for entry, number in zip(entries, numbers, strict=True): - if number <= max_delete: - yield Path(entry) - - -def cleanup_dead_symlinks(root: Path) -> None: - for left_dir in root.iterdir(): - if left_dir.is_symlink(): - if not left_dir.resolve().exists(): - left_dir.unlink() - - -def cleanup_numbered_dir( - root: Path, prefix: str, keep: int, consider_lock_dead_if_created_before: float -) -> None: - """Cleanup for lock driven numbered directories.""" - if not root.exists(): - return - for path in cleanup_candidates(root, prefix, keep): - try_cleanup(path, consider_lock_dead_if_created_before) - for path in root.glob("garbage-*"): - try_cleanup(path, consider_lock_dead_if_created_before) - - cleanup_dead_symlinks(root) - - -def make_numbered_dir_with_cleanup( - root: Path, - prefix: str, - keep: int, - lock_timeout: float, - mode: int, -) -> Path: - """Create a numbered dir with a cleanup lock and remove old ones.""" - e = None - for i in range(10): - try: - p = make_numbered_dir(root, prefix, mode) - # Only lock the current dir when keep is not 0 - if keep != 0: - lock_path = create_cleanup_lock(p) - register_cleanup_lock_removal(lock_path) - except Exception as exc: - e = exc - else: - consider_lock_dead_if_created_before = p.stat().st_mtime - lock_timeout - # Register a cleanup for program exit - atexit.register( - cleanup_numbered_dir, - root, - prefix, - keep, - consider_lock_dead_if_created_before, - ) - return p - assert e is not None - raise e - - -def resolve_from_str(input: str, rootpath: Path) -> Path: - input = expanduser(input) - input = expandvars(input) - if isabs(input): - return Path(input) - else: - return rootpath.joinpath(input) - - -def fnmatch_ex(pattern: str, path: str | os.PathLike[str]) -> bool: - """A port of FNMatcher from py.path.common which works with PurePath() instances. - - The difference between this algorithm and PurePath.match() is that the - latter matches "**" glob expressions for each part of the path, while - this algorithm uses the whole path instead. - - For example: - "tests/foo/bar/doc/test_foo.py" matches pattern "tests/**/doc/test*.py" - with this algorithm, but not with PurePath.match(). - - This algorithm was ported to keep backward-compatibility with existing - settings which assume paths match according this logic. - - References: - * https://bugs.python.org/issue29249 - * https://bugs.python.org/issue34731 - """ - path = PurePath(path) - iswin32 = sys.platform.startswith("win") - - if iswin32 and sep not in pattern and posix_sep in pattern: - # Running on Windows, the pattern has no Windows path separators, - # and the pattern has one or more Posix path separators. Replace - # the Posix path separators with the Windows path separator. - pattern = pattern.replace(posix_sep, sep) - - if sep not in pattern: - name = path.name - else: - name = str(path) - if path.is_absolute() and not os.path.isabs(pattern): - pattern = f"*{os.sep}{pattern}" - return fnmatch.fnmatch(name, pattern) - - -def parts(s: str) -> set[str]: - parts = s.split(sep) - return {sep.join(parts[: i + 1]) or sep for i in range(len(parts))} - - -def symlink_or_skip( - src: os.PathLike[str] | str, - dst: os.PathLike[str] | str, - **kwargs: Any, -) -> None: - """Make a symlink, or skip the test in case symlinks are not supported.""" - try: - os.symlink(src, dst, **kwargs) - except OSError as e: - skip(f"symlinks not supported: {e}") - - -class ImportMode(Enum): - """Possible values for `mode` parameter of `import_path`.""" - - prepend = "prepend" - append = "append" - importlib = "importlib" - - -class ImportPathMismatchError(ImportError): - """Raised on import_path() if there is a mismatch of __file__'s. - - This can happen when `import_path` is called multiple times with different filenames that has - the same basename but reside in packages - (for example "/tests1/test_foo.py" and "/tests2/test_foo.py"). - """ - - -def import_path( - path: str | os.PathLike[str], - *, - mode: str | ImportMode = ImportMode.prepend, - root: Path, - consider_namespace_packages: bool, -) -> ModuleType: - """ - Import and return a module from the given path, which can be a file (a module) or - a directory (a package). - - :param path: - Path to the file to import. - - :param mode: - Controls the underlying import mechanism that will be used: - - * ImportMode.prepend: the directory containing the module (or package, taking - `__init__.py` files into account) will be put at the *start* of `sys.path` before - being imported with `importlib.import_module`. - - * ImportMode.append: same as `prepend`, but the directory will be appended - to the end of `sys.path`, if not already in `sys.path`. - - * ImportMode.importlib: uses more fine control mechanisms provided by `importlib` - to import the module, which avoids having to muck with `sys.path` at all. It effectively - allows having same-named test modules in different places. - - :param root: - Used as an anchor when mode == ImportMode.importlib to obtain - a unique name for the module being imported so it can safely be stored - into ``sys.modules``. - - :param consider_namespace_packages: - If True, consider namespace packages when resolving module names. - - :raises ImportPathMismatchError: - If after importing the given `path` and the module `__file__` - are different. Only raised in `prepend` and `append` modes. - """ - path = Path(path) - mode = ImportMode(mode) - - if not path.exists(): - raise ImportError(path) - - if mode is ImportMode.importlib: - # Try to import this module using the standard import mechanisms, but - # without touching sys.path. - try: - pkg_root, module_name = resolve_pkg_root_and_module_name( - path, consider_namespace_packages=consider_namespace_packages - ) - except CouldNotResolvePathError: - pass - else: - # If the given module name is already in sys.modules, do not import it again. - with contextlib.suppress(KeyError): - return sys.modules[module_name] - - mod = _import_module_using_spec( - module_name, path, pkg_root, insert_modules=False - ) - if mod is not None: - return mod - - # Could not import the module with the current sys.path, so we fall back - # to importing the file as a single module, not being a part of a package. - module_name = module_name_from_path(path, root) - with contextlib.suppress(KeyError): - return sys.modules[module_name] - - mod = _import_module_using_spec( - module_name, path, path.parent, insert_modules=True - ) - if mod is None: - raise ImportError(f"Can't find module {module_name} at location {path}") - return mod - - try: - pkg_root, module_name = resolve_pkg_root_and_module_name( - path, consider_namespace_packages=consider_namespace_packages - ) - except CouldNotResolvePathError: - pkg_root, module_name = path.parent, path.stem - - # Change sys.path permanently: restoring it at the end of this function would cause surprising - # problems because of delayed imports: for example, a conftest.py file imported by this function - # might have local imports, which would fail at runtime if we restored sys.path. - if mode is ImportMode.append: - if str(pkg_root) not in sys.path: - sys.path.append(str(pkg_root)) - elif mode is ImportMode.prepend: - if str(pkg_root) != sys.path[0]: - sys.path.insert(0, str(pkg_root)) - else: - assert_never(mode) - - importlib.import_module(module_name) - - mod = sys.modules[module_name] - if path.name == "__init__.py": - return mod - - ignore = os.environ.get("PY_IGNORE_IMPORTMISMATCH", "") - if ignore != "1": - module_file = mod.__file__ - if module_file is None: - raise ImportPathMismatchError(module_name, module_file, path) - - if module_file.endswith((".pyc", ".pyo")): - module_file = module_file[:-1] - if module_file.endswith(os.sep + "__init__.py"): - module_file = module_file[: -(len(os.sep + "__init__.py"))] - - try: - is_same = _is_same(str(path), module_file) - except FileNotFoundError: - is_same = False - - if not is_same: - raise ImportPathMismatchError(module_name, module_file, path) - - return mod - - -def _import_module_using_spec( - module_name: str, module_path: Path, module_location: Path, *, insert_modules: bool -) -> ModuleType | None: - """ - Tries to import a module by its canonical name, path, and its parent location. - - :param module_name: - The expected module name, will become the key of `sys.modules`. - - :param module_path: - The file path of the module, for example `/foo/bar/test_demo.py`. - If module is a package, pass the path to the `__init__.py` of the package. - If module is a namespace package, pass directory path. - - :param module_location: - The parent location of the module. - If module is a package, pass the directory containing the `__init__.py` file. - - :param insert_modules: - If True, will call `insert_missing_modules` to create empty intermediate modules - with made-up module names (when importing test files not reachable from `sys.path`). - - Example 1 of parent_module_*: - - module_name: "a.b.c.demo" - module_path: Path("a/b/c/demo.py") - module_location: Path("a/b/c/") - if "a.b.c" is package ("a/b/c/__init__.py" exists), then - parent_module_name: "a.b.c" - parent_module_path: Path("a/b/c/__init__.py") - parent_module_location: Path("a/b/c/") - else: - parent_module_name: "a.b.c" - parent_module_path: Path("a/b/c") - parent_module_location: Path("a/b/") - - Example 2 of parent_module_*: - - module_name: "a.b.c" - module_path: Path("a/b/c/__init__.py") - module_location: Path("a/b/c/") - if "a.b" is package ("a/b/__init__.py" exists), then - parent_module_name: "a.b" - parent_module_path: Path("a/b/__init__.py") - parent_module_location: Path("a/b/") - else: - parent_module_name: "a.b" - parent_module_path: Path("a/b/") - parent_module_location: Path("a/") - """ - # Attempt to import the parent module, seems is our responsibility: - # https://github.com/python/cpython/blob/73906d5c908c1e0b73c5436faeff7d93698fc074/Lib/importlib/_bootstrap.py#L1308-L1311 - parent_module_name, _, name = module_name.rpartition(".") - parent_module: ModuleType | None = None - if parent_module_name: - parent_module = sys.modules.get(parent_module_name) - # If the parent_module lacks the `__path__` attribute, AttributeError when finding a submodule's spec, - # requiring re-import according to the path. - need_reimport = not hasattr(parent_module, "__path__") - if parent_module is None or need_reimport: - # Get parent_location based on location, get parent_path based on path. - if module_path.name == "__init__.py": - # If the current module is in a package, - # need to leave the package first and then enter the parent module. - parent_module_path = module_path.parent.parent - else: - parent_module_path = module_path.parent - - if (parent_module_path / "__init__.py").is_file(): - # If the parent module is a package, loading by __init__.py file. - parent_module_path = parent_module_path / "__init__.py" - - parent_module = _import_module_using_spec( - parent_module_name, - parent_module_path, - parent_module_path.parent, - insert_modules=insert_modules, - ) - - # Checking with sys.meta_path first in case one of its hooks can import this module, - # such as our own assertion-rewrite hook. - for meta_importer in sys.meta_path: - module_name_of_meta = getattr(meta_importer.__class__, "__module__", "") - if module_name_of_meta == "_pytest.assertion.rewrite" and module_path.is_file(): - # Import modules in subdirectories by module_path - # to ensure assertion rewrites are not missed (#12659). - find_spec_path = [str(module_location), str(module_path)] - else: - find_spec_path = [str(module_location)] - - spec = meta_importer.find_spec(module_name, find_spec_path) - - if spec_matches_module_path(spec, module_path): - break - else: - loader = None - if module_path.is_dir(): - # The `spec_from_file_location` matches a loader based on the file extension by default. - # For a namespace package, need to manually specify a loader. - loader = NamespaceLoader(name, module_path, PathFinder()) # type: ignore[arg-type] - - spec = importlib.util.spec_from_file_location( - module_name, str(module_path), loader=loader - ) - - if spec_matches_module_path(spec, module_path): - assert spec is not None - # Find spec and import this module. - mod = importlib.util.module_from_spec(spec) - sys.modules[module_name] = mod - spec.loader.exec_module(mod) # type: ignore[union-attr] - - # Set this module as an attribute of the parent module (#12194). - if parent_module is not None: - setattr(parent_module, name, mod) - - if insert_modules: - insert_missing_modules(sys.modules, module_name) - return mod - - return None - - -def spec_matches_module_path(module_spec: ModuleSpec | None, module_path: Path) -> bool: - """Return true if the given ModuleSpec can be used to import the given module path.""" - if module_spec is None: - return False - - if module_spec.origin: - return Path(module_spec.origin) == module_path - - # Compare the path with the `module_spec.submodule_Search_Locations` in case - # the module is part of a namespace package. - # https://docs.python.org/3/library/importlib.html#importlib.machinery.ModuleSpec.submodule_search_locations - if module_spec.submodule_search_locations: # can be None. - for path in module_spec.submodule_search_locations: - if Path(path) == module_path: - return True - - return False - - -# Implement a special _is_same function on Windows which returns True if the two filenames -# compare equal, to circumvent os.path.samefile returning False for mounts in UNC (#7678). -if sys.platform.startswith("win"): - - def _is_same(f1: str, f2: str) -> bool: - return Path(f1) == Path(f2) or os.path.samefile(f1, f2) - -else: - - def _is_same(f1: str, f2: str) -> bool: - return os.path.samefile(f1, f2) - - -def module_name_from_path(path: Path, root: Path) -> str: - """ - Return a dotted module name based on the given path, anchored on root. - - For example: path="projects/src/tests/test_foo.py" and root="/projects", the - resulting module name will be "src.tests.test_foo". - """ - path = path.with_suffix("") - try: - relative_path = path.relative_to(root) - except ValueError: - # If we can't get a relative path to root, use the full path, except - # for the first part ("d:\\" or "/" depending on the platform, for example). - path_parts = path.parts[1:] - else: - # Use the parts for the relative path to the root path. - path_parts = relative_path.parts - - # Module name for packages do not contain the __init__ file, unless - # the `__init__.py` file is at the root. - if len(path_parts) >= 2 and path_parts[-1] == "__init__": - path_parts = path_parts[:-1] - - # Module names cannot contain ".", normalize them to "_". This prevents - # a directory having a "." in the name (".env.310" for example) causing extra intermediate modules. - # Also, important to replace "." at the start of paths, as those are considered relative imports. - path_parts = tuple(x.replace(".", "_") for x in path_parts) - - return ".".join(path_parts) - - -def insert_missing_modules(modules: dict[str, ModuleType], module_name: str) -> None: - """ - Used by ``import_path`` to create intermediate modules when using mode=importlib. - - When we want to import a module as "src.tests.test_foo" for example, we need - to create empty modules "src" and "src.tests" after inserting "src.tests.test_foo", - otherwise "src.tests.test_foo" is not importable by ``__import__``. - """ - module_parts = module_name.split(".") - while module_name: - parent_module_name, _, child_name = module_name.rpartition(".") - if parent_module_name: - parent_module = modules.get(parent_module_name) - if parent_module is None: - try: - # If sys.meta_path is empty, calling import_module will issue - # a warning and raise ModuleNotFoundError. To avoid the - # warning, we check sys.meta_path explicitly and raise the error - # ourselves to fall back to creating a dummy module. - if not sys.meta_path: - raise ModuleNotFoundError - parent_module = importlib.import_module(parent_module_name) - except ModuleNotFoundError: - parent_module = ModuleType( - module_name, - doc="Empty module created by pytest's importmode=importlib.", - ) - modules[parent_module_name] = parent_module - - # Add child attribute to the parent that can reference the child - # modules. - if not hasattr(parent_module, child_name): - setattr(parent_module, child_name, modules[module_name]) - - module_parts.pop(-1) - module_name = ".".join(module_parts) - - -def resolve_package_path(path: Path) -> Path | None: - """Return the Python package path by looking for the last - directory upwards which still contains an __init__.py. - - Returns None if it cannot be determined. - """ - result = None - for parent in itertools.chain((path,), path.parents): - if parent.is_dir(): - if not (parent / "__init__.py").is_file(): - break - if not parent.name.isidentifier(): - break - result = parent - return result - - -def resolve_pkg_root_and_module_name( - path: Path, *, consider_namespace_packages: bool = False -) -> tuple[Path, str]: - """ - Return the path to the directory of the root package that contains the - given Python file, and its module name: - - src/ - app/ - __init__.py - core/ - __init__.py - models.py - - Passing the full path to `models.py` will yield Path("src") and "app.core.models". - - If consider_namespace_packages is True, then we additionally check upwards in the hierarchy - for namespace packages: - - https://packaging.python.org/en/latest/guides/packaging-namespace-packages - - Raises CouldNotResolvePathError if the given path does not belong to a package (missing any __init__.py files). - """ - pkg_root: Path | None = None - pkg_path = resolve_package_path(path) - if pkg_path is not None: - pkg_root = pkg_path.parent - if consider_namespace_packages: - start = pkg_root if pkg_root is not None else path.parent - for candidate in (start, *start.parents): - module_name = compute_module_name(candidate, path) - if module_name and is_importable(module_name, path): - # Point the pkg_root to the root of the namespace package. - pkg_root = candidate - break - - if pkg_root is not None: - module_name = compute_module_name(pkg_root, path) - if module_name: - return pkg_root, module_name - - raise CouldNotResolvePathError(f"Could not resolve for {path}") - - -def is_importable(module_name: str, module_path: Path) -> bool: - """ - Return if the given module path could be imported normally by Python, akin to the user - entering the REPL and importing the corresponding module name directly, and corresponds - to the module_path specified. - - :param module_name: - Full module name that we want to check if is importable. - For example, "app.models". - - :param module_path: - Full path to the python module/package we want to check if is importable. - For example, "/projects/src/app/models.py". - """ - try: - # Note this is different from what we do in ``_import_module_using_spec``, where we explicitly search through - # sys.meta_path to be able to pass the path of the module that we want to import (``meta_importer.find_spec``). - # Using importlib.util.find_spec() is different, it gives the same results as trying to import - # the module normally in the REPL. - spec = importlib.util.find_spec(module_name) - except (ImportError, ValueError, ImportWarning): - return False - else: - return spec_matches_module_path(spec, module_path) - - -def compute_module_name(root: Path, module_path: Path) -> str | None: - """Compute a module name based on a path and a root anchor.""" - try: - path_without_suffix = module_path.with_suffix("") - except ValueError: - # Empty paths (such as Path.cwd()) might break meta_path hooks (like our own assertion rewriter). - return None - - try: - relative = path_without_suffix.relative_to(root) - except ValueError: # pragma: no cover - return None - names = list(relative.parts) - if not names: - return None - if names[-1] == "__init__": - names.pop() - return ".".join(names) - - -class CouldNotResolvePathError(Exception): - """Custom exception raised by resolve_pkg_root_and_module_name.""" - - -def scandir( - path: str | os.PathLike[str], - sort_key: Callable[[os.DirEntry[str]], object] = lambda entry: entry.name, -) -> list[os.DirEntry[str]]: - """Scan a directory recursively, in breadth-first order. - - The returned entries are sorted according to the given key. - The default is to sort by name. - If the directory does not exist, return an empty list. - """ - entries = [] - # Attempt to create a scandir iterator for the given path. - try: - scandir_iter = os.scandir(path) - except FileNotFoundError: - # If the directory does not exist, return an empty list. - return [] - # Use the scandir iterator in a context manager to ensure it is properly closed. - with scandir_iter as s: - for entry in s: - try: - entry.is_file() - except OSError as err: - if _ignore_error(err): - continue - # Reraise non-ignorable errors to avoid hiding issues. - raise - entries.append(entry) - entries.sort(key=sort_key) # type: ignore[arg-type] - return entries - - -def visit( - path: str | os.PathLike[str], recurse: Callable[[os.DirEntry[str]], bool] -) -> Iterator[os.DirEntry[str]]: - """Walk a directory recursively, in breadth-first order. - - The `recurse` predicate determines whether a directory is recursed. - - Entries at each directory level are sorted. - """ - entries = scandir(path) - yield from entries - for entry in entries: - if entry.is_dir() and recurse(entry): - yield from visit(entry.path, recurse) - - -def absolutepath(path: str | os.PathLike[str]) -> Path: - """Convert a path to an absolute path using os.path.abspath. - - Prefer this over Path.resolve() (see #6523). - Prefer this over Path.absolute() (not public, doesn't normalize). - """ - return Path(os.path.abspath(path)) - - -def commonpath(path1: Path, path2: Path) -> Path | None: - """Return the common part shared with the other path, or None if there is - no common part. - - If one path is relative and one is absolute, returns None. - """ - try: - return Path(os.path.commonpath((str(path1), str(path2)))) - except ValueError: - return None - - -def bestrelpath(directory: Path, dest: Path) -> str: - """Return a string which is a relative path from directory to dest such - that directory/bestrelpath == dest. - - The paths must be either both absolute or both relative. - - If no such path can be determined, returns dest. - """ - assert isinstance(directory, Path) - assert isinstance(dest, Path) - if dest == directory: - return os.curdir - # Find the longest common directory. - base = commonpath(directory, dest) - # Can be the case on Windows for two absolute paths on different drives. - # Can be the case for two relative paths without common prefix. - # Can be the case for a relative path and an absolute path. - if not base: - return str(dest) - reldirectory = directory.relative_to(base) - reldest = dest.relative_to(base) - return os.path.join( - # Back from directory to base. - *([os.pardir] * len(reldirectory.parts)), - # Forward from base to dest. - *reldest.parts, - ) - - -def safe_exists(p: Path) -> bool: - """Like Path.exists(), but account for input arguments that might be too long (#11394).""" - try: - return p.exists() - except (ValueError, OSError): - # ValueError: stat: path too long for Windows - # OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect - return False - - -def samefile_nofollow(p1: Path, p2: Path) -> bool: - """Test whether two paths reference the same actual file or directory. - - Unlike Path.samefile(), does not resolve symlinks. - """ - return os.path.samestat(p1.lstat(), p2.lstat()) diff --git a/.venv/lib/python3.12/site-packages/_pytest/py.typed b/.venv/lib/python3.12/site-packages/_pytest/py.typed deleted file mode 100644 index e69de29..0000000 diff --git a/.venv/lib/python3.12/site-packages/_pytest/pytester.py b/.venv/lib/python3.12/site-packages/_pytest/pytester.py deleted file mode 100644 index 1cd5f05..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/pytester.py +++ /dev/null @@ -1,1791 +0,0 @@ -# mypy: allow-untyped-defs -"""(Disabled by default) support for testing pytest and pytest plugins. - -PYTEST_DONT_REWRITE -""" - -from __future__ import annotations - -import collections.abc -from collections.abc import Callable -from collections.abc import Generator -from collections.abc import Iterable -from collections.abc import Sequence -import contextlib -from fnmatch import fnmatch -import gc -import importlib -from io import StringIO -import locale -import os -from pathlib import Path -import platform -import re -import shutil -import subprocess -import sys -import traceback -from typing import Any -from typing import Final -from typing import final -from typing import IO -from typing import Literal -from typing import overload -from typing import TextIO -from typing import TYPE_CHECKING -from weakref import WeakKeyDictionary - -from iniconfig import IniConfig -from iniconfig import SectionWrapper - -from _pytest import timing -from _pytest._code import Source -from _pytest.capture import _get_multicapture -from _pytest.compat import NOTSET -from _pytest.compat import NotSetType -from _pytest.config import _PluggyPlugin -from _pytest.config import Config -from _pytest.config import ExitCode -from _pytest.config import hookimpl -from _pytest.config import main -from _pytest.config import PytestPluginManager -from _pytest.config.argparsing import Parser -from _pytest.deprecated import check_ispytest -from _pytest.fixtures import fixture -from _pytest.fixtures import FixtureRequest -from _pytest.main import Session -from _pytest.monkeypatch import MonkeyPatch -from _pytest.nodes import Collector -from _pytest.nodes import Item -from _pytest.outcomes import fail -from _pytest.outcomes import importorskip -from _pytest.outcomes import skip -from _pytest.pathlib import bestrelpath -from _pytest.pathlib import make_numbered_dir -from _pytest.reports import CollectReport -from _pytest.reports import TestReport -from _pytest.tmpdir import TempPathFactory -from _pytest.warning_types import PytestFDWarning - - -if TYPE_CHECKING: - import pexpect - - -pytest_plugins = ["pytester_assertions"] - - -IGNORE_PAM = [ # filenames added when obtaining details about the current user - "/var/lib/sss/mc/passwd" -] - - -def pytest_addoption(parser: Parser) -> None: - parser.addoption( - "--lsof", - action="store_true", - dest="lsof", - default=False, - help="Run FD checks if lsof is available", - ) - - parser.addoption( - "--runpytest", - default="inprocess", - dest="runpytest", - choices=("inprocess", "subprocess"), - help=( - "Run pytest sub runs in tests using an 'inprocess' " - "or 'subprocess' (python -m main) method" - ), - ) - - parser.addini( - "pytester_example_dir", help="Directory to take the pytester example files from" - ) - - -def pytest_configure(config: Config) -> None: - if config.getvalue("lsof"): - checker = LsofFdLeakChecker() - if checker.matching_platform(): - config.pluginmanager.register(checker) - - config.addinivalue_line( - "markers", - "pytester_example_path(*path_segments): join the given path " - "segments to `pytester_example_dir` for this test.", - ) - - -class LsofFdLeakChecker: - def get_open_files(self) -> list[tuple[str, str]]: - if sys.version_info >= (3, 11): - # New in Python 3.11, ignores utf-8 mode - encoding = locale.getencoding() - else: - encoding = locale.getpreferredencoding(False) - out = subprocess.run( - ("lsof", "-Ffn0", "-p", str(os.getpid())), - stdout=subprocess.PIPE, - stderr=subprocess.DEVNULL, - check=True, - text=True, - encoding=encoding, - ).stdout - - def isopen(line: str) -> bool: - return line.startswith("f") and ( - "deleted" not in line - and "mem" not in line - and "txt" not in line - and "cwd" not in line - ) - - open_files = [] - - for line in out.split("\n"): - if isopen(line): - fields = line.split("\0") - fd = fields[0][1:] - filename = fields[1][1:] - if filename in IGNORE_PAM: - continue - if filename.startswith("/"): - open_files.append((fd, filename)) - - return open_files - - def matching_platform(self) -> bool: - try: - subprocess.run(("lsof", "-v"), check=True) - except (OSError, subprocess.CalledProcessError): - return False - else: - return True - - @hookimpl(wrapper=True, tryfirst=True) - def pytest_runtest_protocol(self, item: Item) -> Generator[None, object, object]: - lines1 = self.get_open_files() - try: - return (yield) - finally: - if hasattr(sys, "pypy_version_info"): - gc.collect() - lines2 = self.get_open_files() - - new_fds = {t[0] for t in lines2} - {t[0] for t in lines1} - leaked_files = [t for t in lines2 if t[0] in new_fds] - if leaked_files: - error = [ - f"***** {len(leaked_files)} FD leakage detected", - *(str(f) for f in leaked_files), - "*** Before:", - *(str(f) for f in lines1), - "*** After:", - *(str(f) for f in lines2), - f"***** {len(leaked_files)} FD leakage detected", - "*** function {}:{}: {} ".format(*item.location), - "See issue #2366", - ] - item.warn(PytestFDWarning("\n".join(error))) - - -# used at least by pytest-xdist plugin - - -@fixture -def _pytest(request: FixtureRequest) -> PytestArg: - """Return a helper which offers a gethookrecorder(hook) method which - returns a HookRecorder instance which helps to make assertions about called - hooks.""" - return PytestArg(request) - - -class PytestArg: - def __init__(self, request: FixtureRequest) -> None: - self._request = request - - def gethookrecorder(self, hook) -> HookRecorder: - hookrecorder = HookRecorder(hook._pm) - self._request.addfinalizer(hookrecorder.finish_recording) - return hookrecorder - - -def get_public_names(values: Iterable[str]) -> list[str]: - """Only return names from iterator values without a leading underscore.""" - return [x for x in values if x[0] != "_"] - - -@final -class RecordedHookCall: - """A recorded call to a hook. - - The arguments to the hook call are set as attributes. - For example: - - .. code-block:: python - - calls = hook_recorder.getcalls("pytest_runtest_setup") - # Suppose pytest_runtest_setup was called once with `item=an_item`. - assert calls[0].item is an_item - """ - - def __init__(self, name: str, kwargs) -> None: - self.__dict__.update(kwargs) - self._name = name - - def __repr__(self) -> str: - d = self.__dict__.copy() - del d["_name"] - return f"" - - if TYPE_CHECKING: - # The class has undetermined attributes, this tells mypy about it. - def __getattr__(self, key: str): ... - - -@final -class HookRecorder: - """Record all hooks called in a plugin manager. - - Hook recorders are created by :class:`Pytester`. - - This wraps all the hook calls in the plugin manager, recording each call - before propagating the normal calls. - """ - - def __init__( - self, pluginmanager: PytestPluginManager, *, _ispytest: bool = False - ) -> None: - check_ispytest(_ispytest) - - self._pluginmanager = pluginmanager - self.calls: list[RecordedHookCall] = [] - self.ret: int | ExitCode | None = None - - def before(hook_name: str, hook_impls, kwargs) -> None: - self.calls.append(RecordedHookCall(hook_name, kwargs)) - - def after(outcome, hook_name: str, hook_impls, kwargs) -> None: - pass - - self._undo_wrapping = pluginmanager.add_hookcall_monitoring(before, after) - - def finish_recording(self) -> None: - self._undo_wrapping() - - def getcalls(self, names: str | Iterable[str]) -> list[RecordedHookCall]: - """Get all recorded calls to hooks with the given names (or name).""" - if isinstance(names, str): - names = names.split() - return [call for call in self.calls if call._name in names] - - def assert_contains(self, entries: Sequence[tuple[str, str]]) -> None: - __tracebackhide__ = True - i = 0 - entries = list(entries) - # Since Python 3.13, f_locals is not a dict, but eval requires a dict. - backlocals = dict(sys._getframe(1).f_locals) - while entries: - name, check = entries.pop(0) - for ind, call in enumerate(self.calls[i:]): - if call._name == name: - print("NAMEMATCH", name, call) - if eval(check, backlocals, call.__dict__): - print("CHECKERMATCH", repr(check), "->", call) - else: - print("NOCHECKERMATCH", repr(check), "-", call) - continue - i += ind + 1 - break - print("NONAMEMATCH", name, "with", call) - else: - fail(f"could not find {name!r} check {check!r}") - - def popcall(self, name: str) -> RecordedHookCall: - __tracebackhide__ = True - for i, call in enumerate(self.calls): - if call._name == name: - del self.calls[i] - return call - lines = [f"could not find call {name!r}, in:"] - lines.extend([f" {x}" for x in self.calls]) - fail("\n".join(lines)) - - def getcall(self, name: str) -> RecordedHookCall: - values = self.getcalls(name) - assert len(values) == 1, (name, values) - return values[0] - - # functionality for test reports - - @overload - def getreports( - self, - names: Literal["pytest_collectreport"], - ) -> Sequence[CollectReport]: ... - - @overload - def getreports( - self, - names: Literal["pytest_runtest_logreport"], - ) -> Sequence[TestReport]: ... - - @overload - def getreports( - self, - names: str | Iterable[str] = ( - "pytest_collectreport", - "pytest_runtest_logreport", - ), - ) -> Sequence[CollectReport | TestReport]: ... - - def getreports( - self, - names: str | Iterable[str] = ( - "pytest_collectreport", - "pytest_runtest_logreport", - ), - ) -> Sequence[CollectReport | TestReport]: - return [x.report for x in self.getcalls(names)] - - def matchreport( - self, - inamepart: str = "", - names: str | Iterable[str] = ( - "pytest_runtest_logreport", - "pytest_collectreport", - ), - when: str | None = None, - ) -> CollectReport | TestReport: - """Return a testreport whose dotted import path matches.""" - values = [] - for rep in self.getreports(names=names): - if not when and rep.when != "call" and rep.passed: - # setup/teardown passing reports - let's ignore those - continue - if when and rep.when != when: - continue - if not inamepart or inamepart in rep.nodeid.split("::"): - values.append(rep) - if not values: - raise ValueError( - f"could not find test report matching {inamepart!r}: " - "no test reports at all!" - ) - if len(values) > 1: - raise ValueError( - f"found 2 or more testreports matching {inamepart!r}: {values}" - ) - return values[0] - - @overload - def getfailures( - self, - names: Literal["pytest_collectreport"], - ) -> Sequence[CollectReport]: ... - - @overload - def getfailures( - self, - names: Literal["pytest_runtest_logreport"], - ) -> Sequence[TestReport]: ... - - @overload - def getfailures( - self, - names: str | Iterable[str] = ( - "pytest_collectreport", - "pytest_runtest_logreport", - ), - ) -> Sequence[CollectReport | TestReport]: ... - - def getfailures( - self, - names: str | Iterable[str] = ( - "pytest_collectreport", - "pytest_runtest_logreport", - ), - ) -> Sequence[CollectReport | TestReport]: - return [rep for rep in self.getreports(names) if rep.failed] - - def getfailedcollections(self) -> Sequence[CollectReport]: - return self.getfailures("pytest_collectreport") - - def listoutcomes( - self, - ) -> tuple[ - Sequence[TestReport], - Sequence[CollectReport | TestReport], - Sequence[CollectReport | TestReport], - ]: - passed = [] - skipped = [] - failed = [] - for rep in self.getreports( - ("pytest_collectreport", "pytest_runtest_logreport") - ): - if rep.passed: - if rep.when == "call": - assert isinstance(rep, TestReport) - passed.append(rep) - elif rep.skipped: - skipped.append(rep) - else: - assert rep.failed, f"Unexpected outcome: {rep!r}" - failed.append(rep) - return passed, skipped, failed - - def countoutcomes(self) -> list[int]: - return [len(x) for x in self.listoutcomes()] - - def assertoutcome(self, passed: int = 0, skipped: int = 0, failed: int = 0) -> None: - __tracebackhide__ = True - from _pytest.pytester_assertions import assertoutcome - - outcomes = self.listoutcomes() - assertoutcome( - outcomes, - passed=passed, - skipped=skipped, - failed=failed, - ) - - def clear(self) -> None: - self.calls[:] = [] - - -@fixture -def linecomp() -> LineComp: - """A :class: `LineComp` instance for checking that an input linearly - contains a sequence of strings.""" - return LineComp() - - -@fixture(name="LineMatcher") -def LineMatcher_fixture(request: FixtureRequest) -> type[LineMatcher]: - """A reference to the :class: `LineMatcher`. - - This is instantiable with a list of lines (without their trailing newlines). - This is useful for testing large texts, such as the output of commands. - """ - return LineMatcher - - -@fixture -def pytester( - request: FixtureRequest, tmp_path_factory: TempPathFactory, monkeypatch: MonkeyPatch -) -> Pytester: - """ - Facilities to write tests/configuration files, execute pytest in isolation, and match - against expected output, perfect for black-box testing of pytest plugins. - - It attempts to isolate the test run from external factors as much as possible, modifying - the current working directory to ``path`` and environment variables during initialization. - - It is particularly useful for testing plugins. It is similar to the :fixture:`tmp_path` - fixture but provides methods which aid in testing pytest itself. - """ - return Pytester(request, tmp_path_factory, monkeypatch, _ispytest=True) - - -@fixture -def _sys_snapshot() -> Generator[None]: - snappaths = SysPathsSnapshot() - snapmods = SysModulesSnapshot() - yield - snapmods.restore() - snappaths.restore() - - -@fixture -def _config_for_test() -> Generator[Config]: - from _pytest.config import get_config - - config = get_config() - yield config - config._ensure_unconfigure() # cleanup, e.g. capman closing tmpfiles. - - -# Regex to match the session duration string in the summary: "74.34s". -rex_session_duration = re.compile(r"\d+\.\d\ds") -# Regex to match all the counts and phrases in the summary line: "34 passed, 111 skipped". -rex_outcome = re.compile(r"(\d+) (\w+)") - - -@final -class RunResult: - """The result of running a command from :class:`~pytest.Pytester`.""" - - def __init__( - self, - ret: int | ExitCode, - outlines: list[str], - errlines: list[str], - duration: float, - ) -> None: - try: - self.ret: int | ExitCode = ExitCode(ret) - """The return value.""" - except ValueError: - self.ret = ret - self.outlines = outlines - """List of lines captured from stdout.""" - self.errlines = errlines - """List of lines captured from stderr.""" - self.stdout = LineMatcher(outlines) - """:class:`~pytest.LineMatcher` of stdout. - - Use e.g. :func:`str(stdout) ` to reconstruct stdout, or the commonly used - :func:`stdout.fnmatch_lines() ` method. - """ - self.stderr = LineMatcher(errlines) - """:class:`~pytest.LineMatcher` of stderr.""" - self.duration = duration - """Duration in seconds.""" - - def __repr__(self) -> str: - return ( - f"" - ) - - def parseoutcomes(self) -> dict[str, int]: - """Return a dictionary of outcome noun -> count from parsing the terminal - output that the test process produced. - - The returned nouns will always be in plural form:: - - ======= 1 failed, 1 passed, 1 warning, 1 error in 0.13s ==== - - Will return ``{"failed": 1, "passed": 1, "warnings": 1, "errors": 1}``. - """ - return self.parse_summary_nouns(self.outlines) - - @classmethod - def parse_summary_nouns(cls, lines) -> dict[str, int]: - """Extract the nouns from a pytest terminal summary line. - - It always returns the plural noun for consistency:: - - ======= 1 failed, 1 passed, 1 warning, 1 error in 0.13s ==== - - Will return ``{"failed": 1, "passed": 1, "warnings": 1, "errors": 1}``. - """ - for line in reversed(lines): - if rex_session_duration.search(line): - outcomes = rex_outcome.findall(line) - ret = {noun: int(count) for (count, noun) in outcomes} - break - else: - raise ValueError("Pytest terminal summary report not found") - - to_plural = { - "warning": "warnings", - "error": "errors", - } - return {to_plural.get(k, k): v for k, v in ret.items()} - - def assert_outcomes( - self, - passed: int = 0, - skipped: int = 0, - failed: int = 0, - errors: int = 0, - xpassed: int = 0, - xfailed: int = 0, - warnings: int | None = None, - deselected: int | None = None, - ) -> None: - """ - Assert that the specified outcomes appear with the respective - numbers (0 means it didn't occur) in the text output from a test run. - - ``warnings`` and ``deselected`` are only checked if not None. - """ - __tracebackhide__ = True - from _pytest.pytester_assertions import assert_outcomes - - outcomes = self.parseoutcomes() - assert_outcomes( - outcomes, - passed=passed, - skipped=skipped, - failed=failed, - errors=errors, - xpassed=xpassed, - xfailed=xfailed, - warnings=warnings, - deselected=deselected, - ) - - -class SysModulesSnapshot: - def __init__(self, preserve: Callable[[str], bool] | None = None) -> None: - self.__preserve = preserve - self.__saved = dict(sys.modules) - - def restore(self) -> None: - if self.__preserve: - self.__saved.update( - (k, m) for k, m in sys.modules.items() if self.__preserve(k) - ) - sys.modules.clear() - sys.modules.update(self.__saved) - - -class SysPathsSnapshot: - def __init__(self) -> None: - self.__saved = list(sys.path), list(sys.meta_path) - - def restore(self) -> None: - sys.path[:], sys.meta_path[:] = self.__saved - - -@final -class Pytester: - """ - Facilities to write tests/configuration files, execute pytest in isolation, and match - against expected output, perfect for black-box testing of pytest plugins. - - It attempts to isolate the test run from external factors as much as possible, modifying - the current working directory to :attr:`path` and environment variables during initialization. - """ - - __test__ = False - - CLOSE_STDIN: Final = NOTSET - - class TimeoutExpired(Exception): - pass - - def __init__( - self, - request: FixtureRequest, - tmp_path_factory: TempPathFactory, - monkeypatch: MonkeyPatch, - *, - _ispytest: bool = False, - ) -> None: - check_ispytest(_ispytest) - self._request = request - self._mod_collections: WeakKeyDictionary[Collector, list[Item | Collector]] = ( - WeakKeyDictionary() - ) - if request.function: - name: str = request.function.__name__ - else: - name = request.node.name - self._name = name - self._path: Path = tmp_path_factory.mktemp(name, numbered=True) - #: A list of plugins to use with :py:meth:`parseconfig` and - #: :py:meth:`runpytest`. Initially this is an empty list but plugins can - #: be added to the list. - #: - #: When running in subprocess mode, specify plugins by name (str) - adding - #: plugin objects directly is not supported. - self.plugins: list[str | _PluggyPlugin] = [] - self._sys_path_snapshot = SysPathsSnapshot() - self._sys_modules_snapshot = self.__take_sys_modules_snapshot() - self._request.addfinalizer(self._finalize) - self._method = self._request.config.getoption("--runpytest") - self._test_tmproot = tmp_path_factory.mktemp(f"tmp-{name}", numbered=True) - - self._monkeypatch = mp = monkeypatch - self.chdir() - mp.setenv("PYTEST_DEBUG_TEMPROOT", str(self._test_tmproot)) - # Ensure no unexpected caching via tox. - mp.delenv("TOX_ENV_DIR", raising=False) - # Discard outer pytest options. - mp.delenv("PYTEST_ADDOPTS", raising=False) - # Ensure no user config is used. - tmphome = str(self.path) - mp.setenv("HOME", tmphome) - mp.setenv("USERPROFILE", tmphome) - # Do not use colors for inner runs by default. - mp.setenv("PY_COLORS", "0") - - @property - def path(self) -> Path: - """Temporary directory path used to create files/run tests from, etc.""" - return self._path - - def __repr__(self) -> str: - return f"" - - def _finalize(self) -> None: - """ - Clean up global state artifacts. - - Some methods modify the global interpreter state and this tries to - clean this up. It does not remove the temporary directory however so - it can be looked at after the test run has finished. - """ - self._sys_modules_snapshot.restore() - self._sys_path_snapshot.restore() - - def __take_sys_modules_snapshot(self) -> SysModulesSnapshot: - # Some zope modules used by twisted-related tests keep internal state - # and can't be deleted; we had some trouble in the past with - # `zope.interface` for example. - # - # Preserve readline due to https://bugs.python.org/issue41033. - # pexpect issues a SIGWINCH. - def preserve_module(name): - return name.startswith(("zope", "readline")) - - return SysModulesSnapshot(preserve=preserve_module) - - def make_hook_recorder(self, pluginmanager: PytestPluginManager) -> HookRecorder: - """Create a new :class:`HookRecorder` for a :class:`PytestPluginManager`.""" - pluginmanager.reprec = reprec = HookRecorder(pluginmanager, _ispytest=True) # type: ignore[attr-defined] - self._request.addfinalizer(reprec.finish_recording) - return reprec - - def chdir(self) -> None: - """Cd into the temporary directory. - - This is done automatically upon instantiation. - """ - self._monkeypatch.chdir(self.path) - - def _makefile( - self, - ext: str, - lines: Sequence[Any | bytes], - files: dict[str, str], - encoding: str = "utf-8", - ) -> Path: - items = list(files.items()) - - if ext is None: - raise TypeError("ext must not be None") - - if ext and not ext.startswith("."): - raise ValueError( - f"pytester.makefile expects a file extension, try .{ext} instead of {ext}" - ) - - def to_text(s: Any | bytes) -> str: - return s.decode(encoding) if isinstance(s, bytes) else str(s) - - if lines: - source = "\n".join(to_text(x) for x in lines) - basename = self._name - items.insert(0, (basename, source)) - - ret = None - for basename, value in items: - p = self.path.joinpath(basename).with_suffix(ext) - p.parent.mkdir(parents=True, exist_ok=True) - source_ = Source(value) - source = "\n".join(to_text(line) for line in source_.lines) - p.write_text(source.strip(), encoding=encoding) - if ret is None: - ret = p - assert ret is not None - return ret - - def makefile(self, ext: str, *args: str, **kwargs: str) -> Path: - r"""Create new text file(s) in the test directory. - - :param ext: - The extension the file(s) should use, including the dot, e.g. `.py`. - :param args: - All args are treated as strings and joined using newlines. - The result is written as contents to the file. The name of the - file is based on the test function requesting this fixture. - :param kwargs: - Each keyword is the name of a file, while the value of it will - be written as contents of the file. - :returns: - The first created file. - - Examples: - - .. code-block:: python - - pytester.makefile(".txt", "line1", "line2") - - pytester.makefile(".ini", pytest="[pytest]\naddopts=-rs\n") - - To create binary files, use :meth:`pathlib.Path.write_bytes` directly: - - .. code-block:: python - - filename = pytester.path.joinpath("foo.bin") - filename.write_bytes(b"...") - """ - return self._makefile(ext, args, kwargs) - - def makeconftest(self, source: str) -> Path: - """Write a conftest.py file. - - :param source: The contents. - :returns: The conftest.py file. - """ - return self.makepyfile(conftest=source) - - def makeini(self, source: str) -> Path: - """Write a tox.ini file. - - :param source: The contents. - :returns: The tox.ini file. - """ - return self.makefile(".ini", tox=source) - - def maketoml(self, source: str) -> Path: - """Write a pytest.toml file. - - :param source: The contents. - :returns: The pytest.toml file. - - .. versionadded:: 9.0 - """ - return self.makefile(".toml", pytest=source) - - def getinicfg(self, source: str) -> SectionWrapper: - """Return the pytest section from the tox.ini config file.""" - p = self.makeini(source) - return IniConfig(str(p))["pytest"] - - def makepyprojecttoml(self, source: str) -> Path: - """Write a pyproject.toml file. - - :param source: The contents. - :returns: The pyproject.ini file. - - .. versionadded:: 6.0 - """ - return self.makefile(".toml", pyproject=source) - - def makepyfile(self, *args, **kwargs) -> Path: - r"""Shortcut for .makefile() with a .py extension. - - Defaults to the test name with a '.py' extension, e.g test_foobar.py, overwriting - existing files. - - Examples: - - .. code-block:: python - - def test_something(pytester): - # Initial file is created test_something.py. - pytester.makepyfile("foobar") - # To create multiple files, pass kwargs accordingly. - pytester.makepyfile(custom="foobar") - # At this point, both 'test_something.py' & 'custom.py' exist in the test directory. - - """ - return self._makefile(".py", args, kwargs) - - def maketxtfile(self, *args, **kwargs) -> Path: - r"""Shortcut for .makefile() with a .txt extension. - - Defaults to the test name with a '.txt' extension, e.g test_foobar.txt, overwriting - existing files. - - Examples: - - .. code-block:: python - - def test_something(pytester): - # Initial file is created test_something.txt. - pytester.maketxtfile("foobar") - # To create multiple files, pass kwargs accordingly. - pytester.maketxtfile(custom="foobar") - # At this point, both 'test_something.txt' & 'custom.txt' exist in the test directory. - - """ - return self._makefile(".txt", args, kwargs) - - def syspathinsert(self, path: str | os.PathLike[str] | None = None) -> None: - """Prepend a directory to sys.path, defaults to :attr:`path`. - - This is undone automatically when this object dies at the end of each - test. - - :param path: - The path. - """ - if path is None: - path = self.path - - self._monkeypatch.syspath_prepend(str(path)) - - def mkdir(self, name: str | os.PathLike[str]) -> Path: - """Create a new (sub)directory. - - :param name: - The name of the directory, relative to the pytester path. - :returns: - The created directory. - :rtype: pathlib.Path - """ - p = self.path / name - p.mkdir() - return p - - def mkpydir(self, name: str | os.PathLike[str]) -> Path: - """Create a new python package. - - This creates a (sub)directory with an empty ``__init__.py`` file so it - gets recognised as a Python package. - """ - p = self.path / name - p.mkdir() - p.joinpath("__init__.py").touch() - return p - - def copy_example(self, name: str | None = None) -> Path: - """Copy file from project's directory into the testdir. - - :param name: - The name of the file to copy. - :return: - Path to the copied directory (inside ``self.path``). - :rtype: pathlib.Path - """ - example_dir_ = self._request.config.getini("pytester_example_dir") - if example_dir_ is None: - raise ValueError("pytester_example_dir is unset, can't copy examples") - example_dir: Path = self._request.config.rootpath / example_dir_ - - for extra_element in self._request.node.iter_markers("pytester_example_path"): - assert extra_element.args - example_dir = example_dir.joinpath(*extra_element.args) - - if name is None: - func_name = self._name - maybe_dir = example_dir / func_name - maybe_file = example_dir / (func_name + ".py") - - if maybe_dir.is_dir(): - example_path = maybe_dir - elif maybe_file.is_file(): - example_path = maybe_file - else: - raise LookupError( - f"{func_name} can't be found as module or package in {example_dir}" - ) - else: - example_path = example_dir.joinpath(name) - - if example_path.is_dir() and not example_path.joinpath("__init__.py").is_file(): - shutil.copytree(example_path, self.path, symlinks=True, dirs_exist_ok=True) - return self.path - elif example_path.is_file(): - result = self.path.joinpath(example_path.name) - shutil.copy(example_path, result) - return result - else: - raise LookupError( - f'example "{example_path}" is not found as a file or directory' - ) - - def getnode(self, config: Config, arg: str | os.PathLike[str]) -> Collector | Item: - """Get the collection node of a file. - - :param config: - A pytest config. - See :py:meth:`parseconfig` and :py:meth:`parseconfigure` for creating it. - :param arg: - Path to the file. - :returns: - The node. - """ - session = Session.from_config(config) - assert "::" not in str(arg) - p = Path(os.path.abspath(arg)) - config.hook.pytest_sessionstart(session=session) - res = session.perform_collect([str(p)], genitems=False)[0] - config.hook.pytest_sessionfinish(session=session, exitstatus=ExitCode.OK) - return res - - def getpathnode(self, path: str | os.PathLike[str]) -> Collector | Item: - """Return the collection node of a file. - - This is like :py:meth:`getnode` but uses :py:meth:`parseconfigure` to - create the (configured) pytest Config instance. - - :param path: - Path to the file. - :returns: - The node. - """ - path = Path(path) - config = self.parseconfigure(path) - session = Session.from_config(config) - x = bestrelpath(session.path, path) - config.hook.pytest_sessionstart(session=session) - res = session.perform_collect([x], genitems=False)[0] - config.hook.pytest_sessionfinish(session=session, exitstatus=ExitCode.OK) - return res - - def genitems(self, colitems: Sequence[Item | Collector]) -> list[Item]: - """Generate all test items from a collection node. - - This recurses into the collection node and returns a list of all the - test items contained within. - - :param colitems: - The collection nodes. - :returns: - The collected items. - """ - session = colitems[0].session - result: list[Item] = [] - for colitem in colitems: - result.extend(session.genitems(colitem)) - return result - - def runitem(self, source: str) -> Any: - """Run the "test_func" Item. - - The calling test instance (class containing the test method) must - provide a ``.getrunner()`` method which should return a runner which - can run the test protocol for a single item, e.g. - ``_pytest.runner.runtestprotocol``. - """ - # used from runner functional tests - item = self.getitem(source) - # the test class where we are called from wants to provide the runner - testclassinstance = self._request.instance - runner = testclassinstance.getrunner() - return runner(item) - - def inline_runsource(self, source: str, *cmdlineargs) -> HookRecorder: - """Run a test module in process using ``pytest.main()``. - - This run writes "source" into a temporary file and runs - ``pytest.main()`` on it, returning a :py:class:`HookRecorder` instance - for the result. - - :param source: The source code of the test module. - :param cmdlineargs: Any extra command line arguments to use. - """ - p = self.makepyfile(source) - values = [*list(cmdlineargs), p] - return self.inline_run(*values) - - def inline_genitems(self, *args) -> tuple[list[Item], HookRecorder]: - """Run ``pytest.main(['--collect-only'])`` in-process. - - Runs the :py:func:`pytest.main` function to run all of pytest inside - the test process itself like :py:meth:`inline_run`, but returns a - tuple of the collected items and a :py:class:`HookRecorder` instance. - """ - rec = self.inline_run("--collect-only", *args) - items = [x.item for x in rec.getcalls("pytest_itemcollected")] - return items, rec - - def inline_run( - self, - *args: str | os.PathLike[str], - plugins=(), - no_reraise_ctrlc: bool = False, - ) -> HookRecorder: - """Run ``pytest.main()`` in-process, returning a HookRecorder. - - Runs the :py:func:`pytest.main` function to run all of pytest inside - the test process itself. This means it can return a - :py:class:`HookRecorder` instance which gives more detailed results - from that run than can be done by matching stdout/stderr from - :py:meth:`runpytest`. - - :param args: - Command line arguments to pass to :py:func:`pytest.main`. - :param plugins: - Extra plugin instances the ``pytest.main()`` instance should use. - :param no_reraise_ctrlc: - Typically we reraise keyboard interrupts from the child run. If - True, the KeyboardInterrupt exception is captured. - """ - from _pytest.unraisableexception import gc_collect_iterations_key - - # (maybe a cpython bug?) the importlib cache sometimes isn't updated - # properly between file creation and inline_run (especially if imports - # are interspersed with file creation) - importlib.invalidate_caches() - - plugins = list(plugins) - finalizers = [] - try: - # Any sys.module or sys.path changes done while running pytest - # inline should be reverted after the test run completes to avoid - # clashing with later inline tests run within the same pytest test, - # e.g. just because they use matching test module names. - finalizers.append(self.__take_sys_modules_snapshot().restore) - finalizers.append(SysPathsSnapshot().restore) - - # Important note: - # - our tests should not leave any other references/registrations - # laying around other than possibly loaded test modules - # referenced from sys.modules, as nothing will clean those up - # automatically - - rec = [] - - class PytesterHelperPlugin: - @staticmethod - def pytest_configure(config: Config) -> None: - rec.append(self.make_hook_recorder(config.pluginmanager)) - - # The unraisable plugin GC collect slows down inline - # pytester runs too much. - config.stash[gc_collect_iterations_key] = 0 - - plugins.append(PytesterHelperPlugin()) - ret = main([str(x) for x in args], plugins=plugins) - if len(rec) == 1: - reprec = rec.pop() - else: - - class reprec: # type: ignore - pass - - reprec.ret = ret - - # Typically we reraise keyboard interrupts from the child run - # because it's our user requesting interruption of the testing. - if ret == ExitCode.INTERRUPTED and not no_reraise_ctrlc: - calls = reprec.getcalls("pytest_keyboard_interrupt") - if calls and calls[-1].excinfo.type == KeyboardInterrupt: - raise KeyboardInterrupt() - return reprec - finally: - for finalizer in finalizers: - finalizer() - - def runpytest_inprocess( - self, *args: str | os.PathLike[str], **kwargs: Any - ) -> RunResult: - """Return result of running pytest in-process, providing a similar - interface to what self.runpytest() provides.""" - syspathinsert = kwargs.pop("syspathinsert", False) - - if syspathinsert: - self.syspathinsert() - instant = timing.Instant() - capture = _get_multicapture("sys") - capture.start_capturing() - try: - try: - reprec = self.inline_run(*args, **kwargs) - except SystemExit as e: - ret = e.args[0] - try: - ret = ExitCode(e.args[0]) - except ValueError: - pass - - class reprec: # type: ignore - ret = ret - - except Exception: - traceback.print_exc() - - class reprec: # type: ignore - ret = ExitCode(3) - - finally: - out, err = capture.readouterr() - capture.stop_capturing() - sys.stdout.write(out) - sys.stderr.write(err) - - assert reprec.ret is not None - res = RunResult( - reprec.ret, out.splitlines(), err.splitlines(), instant.elapsed().seconds - ) - res.reprec = reprec # type: ignore - return res - - def runpytest(self, *args: str | os.PathLike[str], **kwargs: Any) -> RunResult: - """Run pytest inline or in a subprocess, depending on the command line - option "--runpytest" and return a :py:class:`~pytest.RunResult`.""" - new_args = self._ensure_basetemp(args) - if self._method == "inprocess": - return self.runpytest_inprocess(*new_args, **kwargs) - elif self._method == "subprocess": - return self.runpytest_subprocess(*new_args, **kwargs) - raise RuntimeError(f"Unrecognized runpytest option: {self._method}") - - def _ensure_basetemp( - self, args: Sequence[str | os.PathLike[str]] - ) -> list[str | os.PathLike[str]]: - new_args = list(args) - for x in new_args: - if str(x).startswith("--basetemp"): - break - else: - new_args.append( - "--basetemp={}".format(self.path.parent.joinpath("basetemp")) - ) - return new_args - - def parseconfig(self, *args: str | os.PathLike[str]) -> Config: - """Return a new pytest :class:`pytest.Config` instance from given - commandline args. - - This invokes the pytest bootstrapping code in _pytest.config to create a - new :py:class:`pytest.PytestPluginManager` and call the - :hook:`pytest_cmdline_parse` hook to create a new :class:`pytest.Config` - instance. - - If :attr:`plugins` has been populated they should be plugin modules - to be registered with the plugin manager. - """ - import _pytest.config - - new_args = [str(x) for x in self._ensure_basetemp(args)] - - config = _pytest.config._prepareconfig(new_args, self.plugins) - # we don't know what the test will do with this half-setup config - # object and thus we make sure it gets unconfigured properly in any - # case (otherwise capturing could still be active, for example) - self._request.addfinalizer(config._ensure_unconfigure) - return config - - def parseconfigure(self, *args: str | os.PathLike[str]) -> Config: - """Return a new pytest configured Config instance. - - Returns a new :py:class:`pytest.Config` instance like - :py:meth:`parseconfig`, but also calls the :hook:`pytest_configure` - hook. - """ - config = self.parseconfig(*args) - config._do_configure() - return config - - def getitem( - self, source: str | os.PathLike[str], funcname: str = "test_func" - ) -> Item: - """Return the test item for a test function. - - Writes the source to a python file and runs pytest's collection on - the resulting module, returning the test item for the requested - function name. - - :param source: - The module source. - :param funcname: - The name of the test function for which to return a test item. - :returns: - The test item. - """ - items = self.getitems(source) - for item in items: - if item.name == funcname: - return item - assert 0, f"{funcname!r} item not found in module:\n{source}\nitems: {items}" - - def getitems(self, source: str | os.PathLike[str]) -> list[Item]: - """Return all test items collected from the module. - - Writes the source to a Python file and runs pytest's collection on - the resulting module, returning all test items contained within. - """ - modcol = self.getmodulecol(source) - return self.genitems([modcol]) - - def getmodulecol( - self, - source: str | os.PathLike[str], - configargs=(), - *, - withinit: bool = False, - ): - """Return the module collection node for ``source``. - - Writes ``source`` to a file using :py:meth:`makepyfile` and then - runs the pytest collection on it, returning the collection node for the - test module. - - :param source: - The source code of the module to collect. - - :param configargs: - Any extra arguments to pass to :py:meth:`parseconfigure`. - - :param withinit: - Whether to also write an ``__init__.py`` file to the same - directory to ensure it is a package. - """ - if isinstance(source, os.PathLike): - path = self.path.joinpath(source) - assert not withinit, "not supported for paths" - else: - kw = {self._name: str(source)} - path = self.makepyfile(**kw) - if withinit: - self.makepyfile(__init__="#") - self.config = config = self.parseconfigure(path, *configargs) - return self.getnode(config, path) - - def collect_by_name(self, modcol: Collector, name: str) -> Item | Collector | None: - """Return the collection node for name from the module collection. - - Searches a module collection node for a collection node matching the - given name. - - :param modcol: A module collection node; see :py:meth:`getmodulecol`. - :param name: The name of the node to return. - """ - if modcol not in self._mod_collections: - self._mod_collections[modcol] = list(modcol.collect()) - for colitem in self._mod_collections[modcol]: - if colitem.name == name: - return colitem - return None - - def popen( - self, - cmdargs: Sequence[str | os.PathLike[str]], - stdout: int | TextIO = subprocess.PIPE, - stderr: int | TextIO = subprocess.PIPE, - stdin: NotSetType | bytes | IO[Any] | int = CLOSE_STDIN, - **kw, - ): - """Invoke :py:class:`subprocess.Popen`. - - Calls :py:class:`subprocess.Popen` making sure the current working - directory is in ``PYTHONPATH``. - - You probably want to use :py:meth:`run` instead. - """ - env = os.environ.copy() - env["PYTHONPATH"] = os.pathsep.join( - filter(None, [os.getcwd(), env.get("PYTHONPATH", "")]) - ) - kw["env"] = env - - if stdin is self.CLOSE_STDIN: - kw["stdin"] = subprocess.PIPE - elif isinstance(stdin, bytes): - kw["stdin"] = subprocess.PIPE - else: - kw["stdin"] = stdin - - popen = subprocess.Popen(cmdargs, stdout=stdout, stderr=stderr, **kw) - if stdin is self.CLOSE_STDIN: - assert popen.stdin is not None - popen.stdin.close() - elif isinstance(stdin, bytes): - assert popen.stdin is not None - popen.stdin.write(stdin) - - return popen - - def run( - self, - *cmdargs: str | os.PathLike[str], - timeout: float | None = None, - stdin: NotSetType | bytes | IO[Any] | int = CLOSE_STDIN, - ) -> RunResult: - """Run a command with arguments. - - Run a process using :py:class:`subprocess.Popen` saving the stdout and - stderr. - - :param cmdargs: - The sequence of arguments to pass to :py:class:`subprocess.Popen`, - with path-like objects being converted to :py:class:`str` - automatically. - :param timeout: - The period in seconds after which to timeout and raise - :py:class:`Pytester.TimeoutExpired`. - :param stdin: - Optional standard input. - - - If it is ``CLOSE_STDIN`` (Default), then this method calls - :py:class:`subprocess.Popen` with ``stdin=subprocess.PIPE``, and - the standard input is closed immediately after the new command is - started. - - - If it is of type :py:class:`bytes`, these bytes are sent to the - standard input of the command. - - - Otherwise, it is passed through to :py:class:`subprocess.Popen`. - For further information in this case, consult the document of the - ``stdin`` parameter in :py:class:`subprocess.Popen`. - :type stdin: _pytest.compat.NotSetType | bytes | IO[Any] | int - :returns: - The result. - - """ - __tracebackhide__ = True - - cmdargs = tuple(os.fspath(arg) for arg in cmdargs) - p1 = self.path.joinpath("stdout") - p2 = self.path.joinpath("stderr") - print("running:", *cmdargs) - print(" in:", Path.cwd()) - - with p1.open("w", encoding="utf8") as f1, p2.open("w", encoding="utf8") as f2: - instant = timing.Instant() - popen = self.popen( - cmdargs, - stdin=stdin, - stdout=f1, - stderr=f2, - ) - if popen.stdin is not None: - popen.stdin.close() - - def handle_timeout() -> None: - __tracebackhide__ = True - - timeout_message = f"{timeout} second timeout expired running: {cmdargs}" - - popen.kill() - popen.wait() - raise self.TimeoutExpired(timeout_message) - - if timeout is None: - ret = popen.wait() - else: - try: - ret = popen.wait(timeout) - except subprocess.TimeoutExpired: - handle_timeout() - f1.flush() - f2.flush() - - with p1.open(encoding="utf8") as f1, p2.open(encoding="utf8") as f2: - out = f1.read().splitlines() - err = f2.read().splitlines() - - self._dump_lines(out, sys.stdout) - self._dump_lines(err, sys.stderr) - - with contextlib.suppress(ValueError): - ret = ExitCode(ret) - return RunResult(ret, out, err, instant.elapsed().seconds) - - def _dump_lines(self, lines, fp): - try: - for line in lines: - print(line, file=fp) - except UnicodeEncodeError: - print(f"couldn't print to {fp} because of encoding") - - def _getpytestargs(self) -> tuple[str, ...]: - return sys.executable, "-mpytest" - - def runpython(self, script: os.PathLike[str]) -> RunResult: - """Run a python script using sys.executable as interpreter.""" - return self.run(sys.executable, script) - - def runpython_c(self, command: str) -> RunResult: - """Run ``python -c "command"``.""" - return self.run(sys.executable, "-c", command) - - def runpytest_subprocess( - self, *args: str | os.PathLike[str], timeout: float | None = None - ) -> RunResult: - """Run pytest as a subprocess with given arguments. - - Any plugins added to the :py:attr:`plugins` list will be added using the - ``-p`` command line option. Additionally ``--basetemp`` is used to put - any temporary files and directories in a numbered directory prefixed - with "runpytest-" to not conflict with the normal numbered pytest - location for temporary files and directories. - - :param args: - The sequence of arguments to pass to the pytest subprocess. - :param timeout: - The period in seconds after which to timeout and raise - :py:class:`Pytester.TimeoutExpired`. - :returns: - The result. - """ - __tracebackhide__ = True - p = make_numbered_dir(root=self.path, prefix="runpytest-", mode=0o700) - args = (f"--basetemp={p}", *args) - for plugin in self.plugins: - if not isinstance(plugin, str): - raise ValueError( - f"Specifying plugins as objects is not supported in pytester subprocess mode; " - f"specify by name instead: {plugin}" - ) - args = ("-p", plugin, *args) - args = self._getpytestargs() + args - return self.run(*args, timeout=timeout) - - def spawn_pytest(self, string: str, expect_timeout: float = 10.0) -> pexpect.spawn: - """Run pytest using pexpect. - - This makes sure to use the right pytest and sets up the temporary - directory locations. - - The pexpect child is returned. - """ - basetemp = self.path / "temp-pexpect" - basetemp.mkdir(mode=0o700) - invoke = " ".join(map(str, self._getpytestargs())) - cmd = f"{invoke} --basetemp={basetemp} {string}" - return self.spawn(cmd, expect_timeout=expect_timeout) - - def spawn(self, cmd: str, expect_timeout: float = 10.0) -> pexpect.spawn: - """Run a command using pexpect. - - The pexpect child is returned. - """ - pexpect = importorskip("pexpect", "3.0") - if hasattr(sys, "pypy_version_info") and "64" in platform.machine(): - skip("pypy-64 bit not supported") - if not hasattr(pexpect, "spawn"): - skip("pexpect.spawn not available") - logfile = self.path.joinpath("spawn.out").open("wb") - - child = pexpect.spawn(cmd, logfile=logfile, timeout=expect_timeout) - self._request.addfinalizer(logfile.close) - return child - - -class LineComp: - def __init__(self) -> None: - self.stringio = StringIO() - """:class:`python:io.StringIO()` instance used for input.""" - - def assert_contains_lines(self, lines2: Sequence[str]) -> None: - """Assert that ``lines2`` are contained (linearly) in :attr:`stringio`'s value. - - Lines are matched using :func:`LineMatcher.fnmatch_lines `. - """ - __tracebackhide__ = True - val = self.stringio.getvalue() - self.stringio.truncate(0) - self.stringio.seek(0) - lines1 = val.split("\n") - LineMatcher(lines1).fnmatch_lines(lines2) - - -class LineMatcher: - """Flexible matching of text. - - This is a convenience class to test large texts like the output of - commands. - - The constructor takes a list of lines without their trailing newlines, i.e. - ``text.splitlines()``. - """ - - def __init__(self, lines: list[str]) -> None: - self.lines = lines - self._log_output: list[str] = [] - - def __str__(self) -> str: - """Return the entire original text. - - .. versionadded:: 6.2 - You can use :meth:`str` in older versions. - """ - return "\n".join(self.lines) - - def _getlines(self, lines2: str | Sequence[str] | Source) -> Sequence[str]: - if isinstance(lines2, str): - lines2 = Source(lines2) - if isinstance(lines2, Source): - lines2 = lines2.strip().lines - return lines2 - - def fnmatch_lines_random(self, lines2: Sequence[str]) -> None: - """Check lines exist in the output in any order (using :func:`python:fnmatch.fnmatch`).""" - __tracebackhide__ = True - self._match_lines_random(lines2, fnmatch) - - def re_match_lines_random(self, lines2: Sequence[str]) -> None: - """Check lines exist in the output in any order (using :func:`python:re.match`).""" - __tracebackhide__ = True - self._match_lines_random(lines2, lambda name, pat: bool(re.match(pat, name))) - - def _match_lines_random( - self, lines2: Sequence[str], match_func: Callable[[str, str], bool] - ) -> None: - __tracebackhide__ = True - lines2 = self._getlines(lines2) - for line in lines2: - for x in self.lines: - if line == x or match_func(x, line): - self._log("matched: ", repr(line)) - break - else: - msg = f"line {line!r} not found in output" - self._log(msg) - self._fail(msg) - - def get_lines_after(self, fnline: str) -> Sequence[str]: - """Return all lines following the given line in the text. - - The given line can contain glob wildcards. - """ - for i, line in enumerate(self.lines): - if fnline == line or fnmatch(line, fnline): - return self.lines[i + 1 :] - raise ValueError(f"line {fnline!r} not found in output") - - def _log(self, *args) -> None: - self._log_output.append(" ".join(str(x) for x in args)) - - @property - def _log_text(self) -> str: - return "\n".join(self._log_output) - - def fnmatch_lines( - self, lines2: Sequence[str], *, consecutive: bool = False - ) -> None: - """Check lines exist in the output (using :func:`python:fnmatch.fnmatch`). - - The argument is a list of lines which have to match and can use glob - wildcards. If they do not match a pytest.fail() is called. The - matches and non-matches are also shown as part of the error message. - - :param lines2: String patterns to match. - :param consecutive: Match lines consecutively? - """ - __tracebackhide__ = True - self._match_lines(lines2, fnmatch, "fnmatch", consecutive=consecutive) - - def re_match_lines( - self, lines2: Sequence[str], *, consecutive: bool = False - ) -> None: - """Check lines exist in the output (using :func:`python:re.match`). - - The argument is a list of lines which have to match using ``re.match``. - If they do not match a pytest.fail() is called. - - The matches and non-matches are also shown as part of the error message. - - :param lines2: string patterns to match. - :param consecutive: match lines consecutively? - """ - __tracebackhide__ = True - self._match_lines( - lines2, - lambda name, pat: bool(re.match(pat, name)), - "re.match", - consecutive=consecutive, - ) - - def _match_lines( - self, - lines2: Sequence[str], - match_func: Callable[[str, str], bool], - match_nickname: str, - *, - consecutive: bool = False, - ) -> None: - """Underlying implementation of ``fnmatch_lines`` and ``re_match_lines``. - - :param Sequence[str] lines2: - List of string patterns to match. The actual format depends on - ``match_func``. - :param match_func: - A callable ``match_func(line, pattern)`` where line is the - captured line from stdout/stderr and pattern is the matching - pattern. - :param str match_nickname: - The nickname for the match function that will be logged to stdout - when a match occurs. - :param consecutive: - Match lines consecutively? - """ - if not isinstance(lines2, collections.abc.Sequence): - raise TypeError(f"invalid type for lines2: {type(lines2).__name__}") - lines2 = self._getlines(lines2) - lines1 = self.lines[:] - extralines = [] - __tracebackhide__ = True - wnick = len(match_nickname) + 1 - started = False - for line in lines2: - nomatchprinted = False - while lines1: - nextline = lines1.pop(0) - if line == nextline: - self._log("exact match:", repr(line)) - started = True - break - elif match_func(nextline, line): - self._log(f"{match_nickname}:", repr(line)) - self._log( - "{:>{width}}".format("with:", width=wnick), repr(nextline) - ) - started = True - break - else: - if consecutive and started: - msg = f"no consecutive match: {line!r}" - self._log(msg) - self._log( - "{:>{width}}".format("with:", width=wnick), repr(nextline) - ) - self._fail(msg) - if not nomatchprinted: - self._log( - "{:>{width}}".format("nomatch:", width=wnick), repr(line) - ) - nomatchprinted = True - self._log("{:>{width}}".format("and:", width=wnick), repr(nextline)) - extralines.append(nextline) - else: - msg = f"remains unmatched: {line!r}" - self._log(msg) - self._fail(msg) - self._log_output = [] - - def no_fnmatch_line(self, pat: str) -> None: - """Ensure captured lines do not match the given pattern, using ``fnmatch.fnmatch``. - - :param str pat: The pattern to match lines. - """ - __tracebackhide__ = True - self._no_match_line(pat, fnmatch, "fnmatch") - - def no_re_match_line(self, pat: str) -> None: - """Ensure captured lines do not match the given pattern, using ``re.match``. - - :param str pat: The regular expression to match lines. - """ - __tracebackhide__ = True - self._no_match_line( - pat, lambda name, pat: bool(re.match(pat, name)), "re.match" - ) - - def _no_match_line( - self, pat: str, match_func: Callable[[str, str], bool], match_nickname: str - ) -> None: - """Ensure captured lines does not have a the given pattern, using ``fnmatch.fnmatch``. - - :param str pat: The pattern to match lines. - """ - __tracebackhide__ = True - nomatch_printed = False - wnick = len(match_nickname) + 1 - for line in self.lines: - if match_func(line, pat): - msg = f"{match_nickname}: {pat!r}" - self._log(msg) - self._log("{:>{width}}".format("with:", width=wnick), repr(line)) - self._fail(msg) - else: - if not nomatch_printed: - self._log("{:>{width}}".format("nomatch:", width=wnick), repr(pat)) - nomatch_printed = True - self._log("{:>{width}}".format("and:", width=wnick), repr(line)) - self._log_output = [] - - def _fail(self, msg: str) -> None: - __tracebackhide__ = True - log_text = self._log_text - self._log_output = [] - fail(log_text) - - def str(self) -> str: - """Return the entire original text.""" - return str(self) diff --git a/.venv/lib/python3.12/site-packages/_pytest/pytester_assertions.py b/.venv/lib/python3.12/site-packages/_pytest/pytester_assertions.py deleted file mode 100644 index 915cc8a..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/pytester_assertions.py +++ /dev/null @@ -1,74 +0,0 @@ -"""Helper plugin for pytester; should not be loaded on its own.""" - -# This plugin contains assertions used by pytester. pytester cannot -# contain them itself, since it is imported by the `pytest` module, -# hence cannot be subject to assertion rewriting, which requires a -# module to not be already imported. -from __future__ import annotations - -from collections.abc import Sequence - -from _pytest.reports import CollectReport -from _pytest.reports import TestReport - - -def assertoutcome( - outcomes: tuple[ - Sequence[TestReport], - Sequence[CollectReport | TestReport], - Sequence[CollectReport | TestReport], - ], - passed: int = 0, - skipped: int = 0, - failed: int = 0, -) -> None: - __tracebackhide__ = True - - realpassed, realskipped, realfailed = outcomes - obtained = { - "passed": len(realpassed), - "skipped": len(realskipped), - "failed": len(realfailed), - } - expected = {"passed": passed, "skipped": skipped, "failed": failed} - assert obtained == expected, outcomes - - -def assert_outcomes( - outcomes: dict[str, int], - passed: int = 0, - skipped: int = 0, - failed: int = 0, - errors: int = 0, - xpassed: int = 0, - xfailed: int = 0, - warnings: int | None = None, - deselected: int | None = None, -) -> None: - """Assert that the specified outcomes appear with the respective - numbers (0 means it didn't occur) in the text output from a test run.""" - __tracebackhide__ = True - - obtained = { - "passed": outcomes.get("passed", 0), - "skipped": outcomes.get("skipped", 0), - "failed": outcomes.get("failed", 0), - "errors": outcomes.get("errors", 0), - "xpassed": outcomes.get("xpassed", 0), - "xfailed": outcomes.get("xfailed", 0), - } - expected = { - "passed": passed, - "skipped": skipped, - "failed": failed, - "errors": errors, - "xpassed": xpassed, - "xfailed": xfailed, - } - if warnings is not None: - obtained["warnings"] = outcomes.get("warnings", 0) - expected["warnings"] = warnings - if deselected is not None: - obtained["deselected"] = outcomes.get("deselected", 0) - expected["deselected"] = deselected - assert obtained == expected diff --git a/.venv/lib/python3.12/site-packages/_pytest/python.py b/.venv/lib/python3.12/site-packages/_pytest/python.py deleted file mode 100644 index e637518..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/python.py +++ /dev/null @@ -1,1772 +0,0 @@ -# mypy: allow-untyped-defs -"""Python test discovery, setup and run of test functions.""" - -from __future__ import annotations - -import abc -from collections import Counter -from collections import defaultdict -from collections.abc import Callable -from collections.abc import Generator -from collections.abc import Iterable -from collections.abc import Iterator -from collections.abc import Mapping -from collections.abc import Sequence -import dataclasses -import enum -import fnmatch -from functools import partial -import inspect -import itertools -import os -from pathlib import Path -import re -import textwrap -import types -from typing import Any -from typing import cast -from typing import final -from typing import Literal -from typing import NoReturn -from typing import TYPE_CHECKING -import warnings - -import _pytest -from _pytest import fixtures -from _pytest import nodes -from _pytest._code import filter_traceback -from _pytest._code import getfslineno -from _pytest._code.code import ExceptionInfo -from _pytest._code.code import TerminalRepr -from _pytest._code.code import Traceback -from _pytest._io.saferepr import saferepr -from _pytest.compat import ascii_escaped -from _pytest.compat import get_default_arg_names -from _pytest.compat import get_real_func -from _pytest.compat import getimfunc -from _pytest.compat import is_async_function -from _pytest.compat import LEGACY_PATH -from _pytest.compat import NOTSET -from _pytest.compat import safe_getattr -from _pytest.compat import safe_isclass -from _pytest.config import Config -from _pytest.config import hookimpl -from _pytest.config.argparsing import Parser -from _pytest.deprecated import check_ispytest -from _pytest.fixtures import FixtureDef -from _pytest.fixtures import FixtureRequest -from _pytest.fixtures import FuncFixtureInfo -from _pytest.fixtures import get_scope_node -from _pytest.main import Session -from _pytest.mark import ParameterSet -from _pytest.mark.structures import _HiddenParam -from _pytest.mark.structures import get_unpacked_marks -from _pytest.mark.structures import HIDDEN_PARAM -from _pytest.mark.structures import Mark -from _pytest.mark.structures import MarkDecorator -from _pytest.mark.structures import normalize_mark_list -from _pytest.outcomes import fail -from _pytest.outcomes import skip -from _pytest.pathlib import fnmatch_ex -from _pytest.pathlib import import_path -from _pytest.pathlib import ImportPathMismatchError -from _pytest.pathlib import scandir -from _pytest.scope import _ScopeName -from _pytest.scope import Scope -from _pytest.stash import StashKey -from _pytest.warning_types import PytestCollectionWarning -from _pytest.warning_types import PytestReturnNotNoneWarning - - -if TYPE_CHECKING: - from typing_extensions import Self - - -def pytest_addoption(parser: Parser) -> None: - parser.addini( - "python_files", - type="args", - # NOTE: default is also used in AssertionRewritingHook. - default=["test_*.py", "*_test.py"], - help="Glob-style file patterns for Python test module discovery", - ) - parser.addini( - "python_classes", - type="args", - default=["Test"], - help="Prefixes or glob names for Python test class discovery", - ) - parser.addini( - "python_functions", - type="args", - default=["test"], - help="Prefixes or glob names for Python test function and method discovery", - ) - parser.addini( - "disable_test_id_escaping_and_forfeit_all_rights_to_community_support", - type="bool", - default=False, - help="Disable string escape non-ASCII characters, might cause unwanted " - "side effects(use at your own risk)", - ) - parser.addini( - "strict_parametrization_ids", - type="bool", - # None => fallback to `strict`. - default=None, - help="Emit an error if non-unique parameter set IDs are detected", - ) - - -def pytest_generate_tests(metafunc: Metafunc) -> None: - for marker in metafunc.definition.iter_markers(name="parametrize"): - metafunc.parametrize(*marker.args, **marker.kwargs, _param_mark=marker) - - -def pytest_configure(config: Config) -> None: - config.addinivalue_line( - "markers", - "parametrize(argnames, argvalues): call a test function multiple " - "times passing in different arguments in turn. argvalues generally " - "needs to be a list of values if argnames specifies only one name " - "or a list of tuples of values if argnames specifies multiple names. " - "Example: @parametrize('arg1', [1,2]) would lead to two calls of the " - "decorated test function, one with arg1=1 and another with arg1=2." - "see https://docs.pytest.org/en/stable/how-to/parametrize.html for more info " - "and examples.", - ) - config.addinivalue_line( - "markers", - "usefixtures(fixturename1, fixturename2, ...): mark tests as needing " - "all of the specified fixtures. see " - "https://docs.pytest.org/en/stable/explanation/fixtures.html#usefixtures ", - ) - - -def async_fail(nodeid: str) -> None: - msg = ( - "async def functions are not natively supported.\n" - "You need to install a suitable plugin for your async framework, for example:\n" - " - anyio\n" - " - pytest-asyncio\n" - " - pytest-tornasync\n" - " - pytest-trio\n" - " - pytest-twisted" - ) - fail(msg, pytrace=False) - - -@hookimpl(trylast=True) -def pytest_pyfunc_call(pyfuncitem: Function) -> object | None: - testfunction = pyfuncitem.obj - if is_async_function(testfunction): - async_fail(pyfuncitem.nodeid) - funcargs = pyfuncitem.funcargs - testargs = {arg: funcargs[arg] for arg in pyfuncitem._fixtureinfo.argnames} - result = testfunction(**testargs) - if hasattr(result, "__await__") or hasattr(result, "__aiter__"): - async_fail(pyfuncitem.nodeid) - elif result is not None: - warnings.warn( - PytestReturnNotNoneWarning( - f"Test functions should return None, but {pyfuncitem.nodeid} returned {type(result)!r}.\n" - "Did you mean to use `assert` instead of `return`?\n" - "See https://docs.pytest.org/en/stable/how-to/assert.html#return-not-none for more information." - ) - ) - return True - - -def pytest_collect_directory( - path: Path, parent: nodes.Collector -) -> nodes.Collector | None: - pkginit = path / "__init__.py" - try: - has_pkginit = pkginit.is_file() - except PermissionError: - # See https://github.com/pytest-dev/pytest/issues/12120#issuecomment-2106349096. - return None - if has_pkginit: - return Package.from_parent(parent, path=path) - return None - - -def pytest_collect_file(file_path: Path, parent: nodes.Collector) -> Module | None: - if file_path.suffix == ".py": - if not parent.session.isinitpath(file_path): - if not path_matches_patterns( - file_path, parent.config.getini("python_files") - ): - return None - ihook = parent.session.gethookproxy(file_path) - module: Module = ihook.pytest_pycollect_makemodule( - module_path=file_path, parent=parent - ) - return module - return None - - -def path_matches_patterns(path: Path, patterns: Iterable[str]) -> bool: - """Return whether path matches any of the patterns in the list of globs given.""" - return any(fnmatch_ex(pattern, path) for pattern in patterns) - - -def pytest_pycollect_makemodule(module_path: Path, parent) -> Module: - return Module.from_parent(parent, path=module_path) - - -@hookimpl(trylast=True) -def pytest_pycollect_makeitem( - collector: Module | Class, name: str, obj: object -) -> None | nodes.Item | nodes.Collector | list[nodes.Item | nodes.Collector]: - assert isinstance(collector, Class | Module), type(collector) - # Nothing was collected elsewhere, let's do it here. - if safe_isclass(obj): - if collector.istestclass(obj, name): - return Class.from_parent(collector, name=name, obj=obj) - elif collector.istestfunction(obj, name): - # mock seems to store unbound methods (issue473), normalize it. - obj = getattr(obj, "__func__", obj) - # We need to try and unwrap the function if it's a functools.partial - # or a functools.wrapped. - # We mustn't if it's been wrapped with mock.patch (python 2 only). - if not (inspect.isfunction(obj) or inspect.isfunction(get_real_func(obj))): - filename, lineno = getfslineno(obj) - warnings.warn_explicit( - message=PytestCollectionWarning( - f"cannot collect {name!r} because it is not a function." - ), - category=None, - filename=str(filename), - lineno=lineno + 1, - ) - elif getattr(obj, "__test__", True): - if inspect.isgeneratorfunction(obj): - fail( - f"'yield' keyword is allowed in fixtures, but not in tests ({name})", - pytrace=False, - ) - return list(collector._genfunctions(name, obj)) - return None - return None - - -class PyobjMixin(nodes.Node): - """this mix-in inherits from Node to carry over the typing information - - as its intended to always mix in before a node - its position in the mro is unaffected""" - - _ALLOW_MARKERS = True - - @property - def module(self): - """Python module object this node was collected from (can be None).""" - node = self.getparent(Module) - return node.obj if node is not None else None - - @property - def cls(self): - """Python class object this node was collected from (can be None).""" - node = self.getparent(Class) - return node.obj if node is not None else None - - @property - def instance(self): - """Python instance object the function is bound to. - - Returns None if not a test method, e.g. for a standalone test function, - a class or a module. - """ - # Overridden by Function. - return None - - @property - def obj(self): - """Underlying Python object.""" - obj = getattr(self, "_obj", None) - if obj is None: - self._obj = obj = self._getobj() - # XXX evil hack - # used to avoid Function marker duplication - if self._ALLOW_MARKERS: - self.own_markers.extend(get_unpacked_marks(self.obj)) - # This assumes that `obj` is called before there is a chance - # to add custom keys to `self.keywords`, so no fear of overriding. - self.keywords.update((mark.name, mark) for mark in self.own_markers) - return obj - - @obj.setter - def obj(self, value): - self._obj = value - - def _getobj(self): - """Get the underlying Python object. May be overwritten by subclasses.""" - # TODO: Improve the type of `parent` such that assert/ignore aren't needed. - assert self.parent is not None - obj = self.parent.obj # type: ignore[attr-defined] - return getattr(obj, self.name) - - def getmodpath(self, stopatmodule: bool = True, includemodule: bool = False) -> str: - """Return Python path relative to the containing module.""" - parts = [] - for node in self.iter_parents(): - name = node.name - if isinstance(node, Module): - name = os.path.splitext(name)[0] - if stopatmodule: - if includemodule: - parts.append(name) - break - parts.append(name) - parts.reverse() - return ".".join(parts) - - def reportinfo(self) -> tuple[os.PathLike[str] | str, int | None, str]: - # XXX caching? - path, lineno = getfslineno(self.obj) - modpath = self.getmodpath() - return path, lineno, modpath - - -# As an optimization, these builtin attribute names are pre-ignored when -# iterating over an object during collection -- the pytest_pycollect_makeitem -# hook is not called for them. -# fmt: off -class _EmptyClass: pass # noqa: E701 -IGNORED_ATTRIBUTES = frozenset.union( - frozenset(), - # Module. - dir(types.ModuleType("empty_module")), - # Some extra module attributes the above doesn't catch. - {"__builtins__", "__file__", "__cached__"}, - # Class. - dir(_EmptyClass), - # Instance. - dir(_EmptyClass()), -) -del _EmptyClass -# fmt: on - - -class PyCollector(PyobjMixin, nodes.Collector, abc.ABC): - def funcnamefilter(self, name: str) -> bool: - return self._matches_prefix_or_glob_option("python_functions", name) - - def isnosetest(self, obj: object) -> bool: - """Look for the __test__ attribute, which is applied by the - @nose.tools.istest decorator. - """ - # We explicitly check for "is True" here to not mistakenly treat - # classes with a custom __getattr__ returning something truthy (like a - # function) as test classes. - return safe_getattr(obj, "__test__", False) is True - - def classnamefilter(self, name: str) -> bool: - return self._matches_prefix_or_glob_option("python_classes", name) - - def istestfunction(self, obj: object, name: str) -> bool: - if self.funcnamefilter(name) or self.isnosetest(obj): - if isinstance(obj, staticmethod | classmethod): - # staticmethods and classmethods need to be unwrapped. - obj = safe_getattr(obj, "__func__", False) - return callable(obj) and fixtures.getfixturemarker(obj) is None - else: - return False - - def istestclass(self, obj: object, name: str) -> bool: - if not (self.classnamefilter(name) or self.isnosetest(obj)): - return False - if inspect.isabstract(obj): - return False - return True - - def _matches_prefix_or_glob_option(self, option_name: str, name: str) -> bool: - """Check if the given name matches the prefix or glob-pattern defined - in configuration.""" - for option in self.config.getini(option_name): - if name.startswith(option): - return True - # Check that name looks like a glob-string before calling fnmatch - # because this is called for every name in each collected module, - # and fnmatch is somewhat expensive to call. - elif ("*" in option or "?" in option or "[" in option) and fnmatch.fnmatch( - name, option - ): - return True - return False - - def collect(self) -> Iterable[nodes.Item | nodes.Collector]: - if not getattr(self.obj, "__test__", True): - return [] - - # Avoid random getattrs and peek in the __dict__ instead. - dicts = [getattr(self.obj, "__dict__", {})] - if isinstance(self.obj, type): - for basecls in self.obj.__mro__: - dicts.append(basecls.__dict__) - - # In each class, nodes should be definition ordered. - # __dict__ is definition ordered. - seen: set[str] = set() - dict_values: list[list[nodes.Item | nodes.Collector]] = [] - collect_imported_tests = self.session.config.getini("collect_imported_tests") - ihook = self.ihook - for dic in dicts: - values: list[nodes.Item | nodes.Collector] = [] - # Note: seems like the dict can change during iteration - - # be careful not to remove the list() without consideration. - for name, obj in list(dic.items()): - if name in IGNORED_ATTRIBUTES: - continue - if name in seen: - continue - seen.add(name) - - if not collect_imported_tests and isinstance(self, Module): - # Do not collect functions and classes from other modules. - if inspect.isfunction(obj) or inspect.isclass(obj): - if obj.__module__ != self._getobj().__name__: - continue - - res = ihook.pytest_pycollect_makeitem( - collector=self, name=name, obj=obj - ) - if res is None: - continue - elif isinstance(res, list): - values.extend(res) - else: - values.append(res) - dict_values.append(values) - - # Between classes in the class hierarchy, reverse-MRO order -- nodes - # inherited from base classes should come before subclasses. - result = [] - for values in reversed(dict_values): - result.extend(values) - return result - - def _genfunctions(self, name: str, funcobj) -> Iterator[Function]: - modulecol = self.getparent(Module) - assert modulecol is not None - module = modulecol.obj - clscol = self.getparent(Class) - cls = (clscol and clscol.obj) or None - - definition = FunctionDefinition.from_parent(self, name=name, callobj=funcobj) - fixtureinfo = definition._fixtureinfo - - # pytest_generate_tests impls call metafunc.parametrize() which fills - # metafunc._calls, the outcome of the hook. - metafunc = Metafunc( - definition=definition, - fixtureinfo=fixtureinfo, - config=self.config, - cls=cls, - module=module, - _ispytest=True, - ) - methods = [] - if hasattr(module, "pytest_generate_tests"): - methods.append(module.pytest_generate_tests) - if cls is not None and hasattr(cls, "pytest_generate_tests"): - methods.append(cls().pytest_generate_tests) - self.ihook.pytest_generate_tests.call_extra(methods, dict(metafunc=metafunc)) - - if not metafunc._calls: - yield Function.from_parent(self, name=name, fixtureinfo=fixtureinfo) - else: - metafunc._recompute_direct_params_indices() - # Direct parametrizations taking place in module/class-specific - # `metafunc.parametrize` calls may have shadowed some fixtures, so make sure - # we update what the function really needs a.k.a its fixture closure. Note that - # direct parametrizations using `@pytest.mark.parametrize` have already been considered - # into making the closure using `ignore_args` arg to `getfixtureclosure`. - fixtureinfo.prune_dependency_tree() - - for callspec in metafunc._calls: - subname = f"{name}[{callspec.id}]" if callspec._idlist else name - yield Function.from_parent( - self, - name=subname, - callspec=callspec, - fixtureinfo=fixtureinfo, - keywords={callspec.id: True}, - originalname=name, - ) - - -def importtestmodule( - path: Path, - config: Config, -): - # We assume we are only called once per module. - importmode = config.getoption("--import-mode") - try: - mod = import_path( - path, - mode=importmode, - root=config.rootpath, - consider_namespace_packages=config.getini("consider_namespace_packages"), - ) - except SyntaxError as e: - raise nodes.Collector.CollectError( - ExceptionInfo.from_current().getrepr(style="short") - ) from e - except ImportPathMismatchError as e: - raise nodes.Collector.CollectError( - "import file mismatch:\n" - "imported module {!r} has this __file__ attribute:\n" - " {}\n" - "which is not the same as the test file we want to collect:\n" - " {}\n" - "HINT: remove __pycache__ / .pyc files and/or use a " - "unique basename for your test file modules".format(*e.args) - ) from e - except ImportError as e: - exc_info = ExceptionInfo.from_current() - if config.get_verbosity() < 2: - exc_info.traceback = exc_info.traceback.filter(filter_traceback) - exc_repr = ( - exc_info.getrepr(style="short") - if exc_info.traceback - else exc_info.exconly() - ) - formatted_tb = str(exc_repr) - raise nodes.Collector.CollectError( - f"ImportError while importing test module '{path}'.\n" - "Hint: make sure your test modules/packages have valid Python names.\n" - "Traceback:\n" - f"{formatted_tb}" - ) from e - except skip.Exception as e: - if e.allow_module_level: - raise - raise nodes.Collector.CollectError( - "Using pytest.skip outside of a test will skip the entire module. " - "If that's your intention, pass `allow_module_level=True`. " - "If you want to skip a specific test or an entire class, " - "use the @pytest.mark.skip or @pytest.mark.skipif decorators." - ) from e - config.pluginmanager.consider_module(mod) - return mod - - -class Module(nodes.File, PyCollector): - """Collector for test classes and functions in a Python module.""" - - def _getobj(self): - return importtestmodule(self.path, self.config) - - def collect(self) -> Iterable[nodes.Item | nodes.Collector]: - self._register_setup_module_fixture() - self._register_setup_function_fixture() - self.session._fixturemanager.parsefactories(self) - return super().collect() - - def _register_setup_module_fixture(self) -> None: - """Register an autouse, module-scoped fixture for the collected module object - that invokes setUpModule/tearDownModule if either or both are available. - - Using a fixture to invoke this methods ensures we play nicely and unsurprisingly with - other fixtures (#517). - """ - setup_module = _get_first_non_fixture_func( - self.obj, ("setUpModule", "setup_module") - ) - teardown_module = _get_first_non_fixture_func( - self.obj, ("tearDownModule", "teardown_module") - ) - - if setup_module is None and teardown_module is None: - return - - def xunit_setup_module_fixture(request) -> Generator[None]: - module = request.module - if setup_module is not None: - _call_with_optional_argument(setup_module, module) - yield - if teardown_module is not None: - _call_with_optional_argument(teardown_module, module) - - self.session._fixturemanager._register_fixture( - # Use a unique name to speed up lookup. - name=f"_xunit_setup_module_fixture_{self.obj.__name__}", - func=xunit_setup_module_fixture, - nodeid=self.nodeid, - scope="module", - autouse=True, - ) - - def _register_setup_function_fixture(self) -> None: - """Register an autouse, function-scoped fixture for the collected module object - that invokes setup_function/teardown_function if either or both are available. - - Using a fixture to invoke this methods ensures we play nicely and unsurprisingly with - other fixtures (#517). - """ - setup_function = _get_first_non_fixture_func(self.obj, ("setup_function",)) - teardown_function = _get_first_non_fixture_func( - self.obj, ("teardown_function",) - ) - if setup_function is None and teardown_function is None: - return - - def xunit_setup_function_fixture(request) -> Generator[None]: - if request.instance is not None: - # in this case we are bound to an instance, so we need to let - # setup_method handle this - yield - return - function = request.function - if setup_function is not None: - _call_with_optional_argument(setup_function, function) - yield - if teardown_function is not None: - _call_with_optional_argument(teardown_function, function) - - self.session._fixturemanager._register_fixture( - # Use a unique name to speed up lookup. - name=f"_xunit_setup_function_fixture_{self.obj.__name__}", - func=xunit_setup_function_fixture, - nodeid=self.nodeid, - scope="function", - autouse=True, - ) - - -class Package(nodes.Directory): - """Collector for files and directories in a Python packages -- directories - with an `__init__.py` file. - - .. note:: - - Directories without an `__init__.py` file are instead collected by - :class:`~pytest.Dir` by default. Both are :class:`~pytest.Directory` - collectors. - - .. versionchanged:: 8.0 - - Now inherits from :class:`~pytest.Directory`. - """ - - def __init__( - self, - fspath: LEGACY_PATH | None, - parent: nodes.Collector, - # NOTE: following args are unused: - config=None, - session=None, - nodeid=None, - path: Path | None = None, - ) -> None: - # NOTE: Could be just the following, but kept as-is for compat. - # super().__init__(self, fspath, parent=parent) - session = parent.session - super().__init__( - fspath=fspath, - path=path, - parent=parent, - config=config, - session=session, - nodeid=nodeid, - ) - - def setup(self) -> None: - init_mod = importtestmodule(self.path / "__init__.py", self.config) - - # Not using fixtures to call setup_module here because autouse fixtures - # from packages are not called automatically (#4085). - setup_module = _get_first_non_fixture_func( - init_mod, ("setUpModule", "setup_module") - ) - if setup_module is not None: - _call_with_optional_argument(setup_module, init_mod) - - teardown_module = _get_first_non_fixture_func( - init_mod, ("tearDownModule", "teardown_module") - ) - if teardown_module is not None: - func = partial(_call_with_optional_argument, teardown_module, init_mod) - self.addfinalizer(func) - - def collect(self) -> Iterable[nodes.Item | nodes.Collector]: - # Always collect __init__.py first. - def sort_key(entry: os.DirEntry[str]) -> object: - return (entry.name != "__init__.py", entry.name) - - config = self.config - col: nodes.Collector | None - cols: Sequence[nodes.Collector] - ihook = self.ihook - for direntry in scandir(self.path, sort_key): - if direntry.is_dir(): - path = Path(direntry.path) - if not self.session.isinitpath(path, with_parents=True): - if ihook.pytest_ignore_collect(collection_path=path, config=config): - continue - col = ihook.pytest_collect_directory(path=path, parent=self) - if col is not None: - yield col - - elif direntry.is_file(): - path = Path(direntry.path) - if not self.session.isinitpath(path): - if ihook.pytest_ignore_collect(collection_path=path, config=config): - continue - cols = ihook.pytest_collect_file(file_path=path, parent=self) - yield from cols - - -def _call_with_optional_argument(func, arg) -> None: - """Call the given function with the given argument if func accepts one argument, otherwise - calls func without arguments.""" - arg_count = func.__code__.co_argcount - if inspect.ismethod(func): - arg_count -= 1 - if arg_count: - func(arg) - else: - func() - - -def _get_first_non_fixture_func(obj: object, names: Iterable[str]) -> object | None: - """Return the attribute from the given object to be used as a setup/teardown - xunit-style function, but only if not marked as a fixture to avoid calling it twice. - """ - for name in names: - meth: object | None = getattr(obj, name, None) - if meth is not None and fixtures.getfixturemarker(meth) is None: - return meth - return None - - -class Class(PyCollector): - """Collector for test methods (and nested classes) in a Python class.""" - - @classmethod - def from_parent(cls, parent, *, name, obj=None, **kw) -> Self: # type: ignore[override] - """The public constructor.""" - return super().from_parent(name=name, parent=parent, **kw) - - def newinstance(self): - return self.obj() - - def collect(self) -> Iterable[nodes.Item | nodes.Collector]: - if not safe_getattr(self.obj, "__test__", True): - return [] - if hasinit(self.obj): - assert self.parent is not None - self.warn( - PytestCollectionWarning( - f"cannot collect test class {self.obj.__name__!r} because it has a " - f"__init__ constructor (from: {self.parent.nodeid})" - ) - ) - return [] - elif hasnew(self.obj): - assert self.parent is not None - self.warn( - PytestCollectionWarning( - f"cannot collect test class {self.obj.__name__!r} because it has a " - f"__new__ constructor (from: {self.parent.nodeid})" - ) - ) - return [] - - self._register_setup_class_fixture() - self._register_setup_method_fixture() - - self.session._fixturemanager.parsefactories(self.newinstance(), self.nodeid) - - return super().collect() - - def _register_setup_class_fixture(self) -> None: - """Register an autouse, class scoped fixture into the collected class object - that invokes setup_class/teardown_class if either or both are available. - - Using a fixture to invoke this methods ensures we play nicely and unsurprisingly with - other fixtures (#517). - """ - setup_class = _get_first_non_fixture_func(self.obj, ("setup_class",)) - teardown_class = _get_first_non_fixture_func(self.obj, ("teardown_class",)) - if setup_class is None and teardown_class is None: - return - - def xunit_setup_class_fixture(request) -> Generator[None]: - cls = request.cls - if setup_class is not None: - func = getimfunc(setup_class) - _call_with_optional_argument(func, cls) - yield - if teardown_class is not None: - func = getimfunc(teardown_class) - _call_with_optional_argument(func, cls) - - self.session._fixturemanager._register_fixture( - # Use a unique name to speed up lookup. - name=f"_xunit_setup_class_fixture_{self.obj.__qualname__}", - func=xunit_setup_class_fixture, - nodeid=self.nodeid, - scope="class", - autouse=True, - ) - - def _register_setup_method_fixture(self) -> None: - """Register an autouse, function scoped fixture into the collected class object - that invokes setup_method/teardown_method if either or both are available. - - Using a fixture to invoke these methods ensures we play nicely and unsurprisingly with - other fixtures (#517). - """ - setup_name = "setup_method" - setup_method = _get_first_non_fixture_func(self.obj, (setup_name,)) - teardown_name = "teardown_method" - teardown_method = _get_first_non_fixture_func(self.obj, (teardown_name,)) - if setup_method is None and teardown_method is None: - return - - def xunit_setup_method_fixture(request) -> Generator[None]: - instance = request.instance - method = request.function - if setup_method is not None: - func = getattr(instance, setup_name) - _call_with_optional_argument(func, method) - yield - if teardown_method is not None: - func = getattr(instance, teardown_name) - _call_with_optional_argument(func, method) - - self.session._fixturemanager._register_fixture( - # Use a unique name to speed up lookup. - name=f"_xunit_setup_method_fixture_{self.obj.__qualname__}", - func=xunit_setup_method_fixture, - nodeid=self.nodeid, - scope="function", - autouse=True, - ) - - -def hasinit(obj: object) -> bool: - init: object = getattr(obj, "__init__", None) - if init: - return init != object.__init__ - return False - - -def hasnew(obj: object) -> bool: - new: object = getattr(obj, "__new__", None) - if new: - return new != object.__new__ - return False - - -@final -@dataclasses.dataclass(frozen=True) -class IdMaker: - """Make IDs for a parametrization.""" - - __slots__ = ( - "argnames", - "config", - "func_name", - "idfn", - "ids", - "nodeid", - "parametersets", - ) - - # The argnames of the parametrization. - argnames: Sequence[str] - # The ParameterSets of the parametrization. - parametersets: Sequence[ParameterSet] - # Optionally, a user-provided callable to make IDs for parameters in a - # ParameterSet. - idfn: Callable[[Any], object | None] | None - # Optionally, explicit IDs for ParameterSets by index. - ids: Sequence[object | None] | None - # Optionally, the pytest config. - # Used for controlling ASCII escaping, determining parametrization ID - # strictness, and for calling the :hook:`pytest_make_parametrize_id` hook. - config: Config | None - # Optionally, the ID of the node being parametrized. - # Used only for clearer error messages. - nodeid: str | None - # Optionally, the ID of the function being parametrized. - # Used only for clearer error messages. - func_name: str | None - - def make_unique_parameterset_ids(self) -> list[str | _HiddenParam]: - """Make a unique identifier for each ParameterSet, that may be used to - identify the parametrization in a node ID. - - If strict_parametrization_ids is enabled, and duplicates are detected, - raises CollectError. Otherwise makes the IDs unique as follows: - - Format is -...-[counter], where prm_x_token is - - user-provided id, if given - - else an id derived from the value, applicable for certain types - - else - The counter suffix is appended only in case a string wouldn't be unique - otherwise. - """ - resolved_ids = list(self._resolve_ids()) - # All IDs must be unique! - if len(resolved_ids) != len(set(resolved_ids)): - # Record the number of occurrences of each ID. - id_counts = Counter(resolved_ids) - - if self._strict_parametrization_ids_enabled(): - parameters = ", ".join(self.argnames) - parametersets = ", ".join( - [saferepr(list(param.values)) for param in self.parametersets] - ) - ids = ", ".join( - id if id is not HIDDEN_PARAM else "" for id in resolved_ids - ) - duplicates = ", ".join( - id if id is not HIDDEN_PARAM else "" - for id, count in id_counts.items() - if count > 1 - ) - msg = textwrap.dedent(f""" - Duplicate parametrization IDs detected, but strict_parametrization_ids is set. - - Test name: {self.nodeid} - Parameters: {parameters} - Parameter sets: {parametersets} - IDs: {ids} - Duplicates: {duplicates} - - You can fix this problem using `@pytest.mark.parametrize(..., ids=...)` or `pytest.param(..., id=...)`. - """).strip() # noqa: E501 - raise nodes.Collector.CollectError(msg) - - # Map the ID to its next suffix. - id_suffixes: dict[str, int] = defaultdict(int) - # Suffix non-unique IDs to make them unique. - for index, id in enumerate(resolved_ids): - if id_counts[id] > 1: - if id is HIDDEN_PARAM: - self._complain_multiple_hidden_parameter_sets() - suffix = "" - if id and id[-1].isdigit(): - suffix = "_" - new_id = f"{id}{suffix}{id_suffixes[id]}" - while new_id in set(resolved_ids): - id_suffixes[id] += 1 - new_id = f"{id}{suffix}{id_suffixes[id]}" - resolved_ids[index] = new_id - id_suffixes[id] += 1 - assert len(resolved_ids) == len(set(resolved_ids)), ( - f"Internal error: {resolved_ids=}" - ) - return resolved_ids - - def _strict_parametrization_ids_enabled(self) -> bool: - if self.config is None: - return False - strict_parametrization_ids = self.config.getini("strict_parametrization_ids") - if strict_parametrization_ids is None: - strict_parametrization_ids = self.config.getini("strict") - return cast(bool, strict_parametrization_ids) - - def _resolve_ids(self) -> Iterable[str | _HiddenParam]: - """Resolve IDs for all ParameterSets (may contain duplicates).""" - for idx, parameterset in enumerate(self.parametersets): - if parameterset.id is not None: - # ID provided directly - pytest.param(..., id="...") - if parameterset.id is HIDDEN_PARAM: - yield HIDDEN_PARAM - else: - yield _ascii_escaped_by_config(parameterset.id, self.config) - elif self.ids and idx < len(self.ids) and self.ids[idx] is not None: - # ID provided in the IDs list - parametrize(..., ids=[...]). - if self.ids[idx] is HIDDEN_PARAM: - yield HIDDEN_PARAM - else: - yield self._idval_from_value_required(self.ids[idx], idx) - else: - # ID not provided - generate it. - yield "-".join( - self._idval(val, argname, idx) - for val, argname in zip( - parameterset.values, self.argnames, strict=True - ) - ) - - def _idval(self, val: object, argname: str, idx: int) -> str: - """Make an ID for a parameter in a ParameterSet.""" - idval = self._idval_from_function(val, argname, idx) - if idval is not None: - return idval - idval = self._idval_from_hook(val, argname) - if idval is not None: - return idval - idval = self._idval_from_value(val) - if idval is not None: - return idval - return self._idval_from_argname(argname, idx) - - def _idval_from_function(self, val: object, argname: str, idx: int) -> str | None: - """Try to make an ID for a parameter in a ParameterSet using the - user-provided id callable, if given.""" - if self.idfn is None: - return None - try: - id = self.idfn(val) - except Exception as e: - prefix = f"{self.nodeid}: " if self.nodeid is not None else "" - msg = "error raised while trying to determine id of parameter '{}' at position {}" - msg = prefix + msg.format(argname, idx) - raise ValueError(msg) from e - if id is None: - return None - return self._idval_from_value(id) - - def _idval_from_hook(self, val: object, argname: str) -> str | None: - """Try to make an ID for a parameter in a ParameterSet by calling the - :hook:`pytest_make_parametrize_id` hook.""" - if self.config: - id: str | None = self.config.hook.pytest_make_parametrize_id( - config=self.config, val=val, argname=argname - ) - return id - return None - - def _idval_from_value(self, val: object) -> str | None: - """Try to make an ID for a parameter in a ParameterSet from its value, - if the value type is supported.""" - if isinstance(val, str | bytes): - return _ascii_escaped_by_config(val, self.config) - elif val is None or isinstance(val, float | int | bool | complex): - return str(val) - elif isinstance(val, re.Pattern): - return ascii_escaped(val.pattern) - elif val is NOTSET: - # Fallback to default. Note that NOTSET is an enum.Enum. - pass - elif isinstance(val, enum.Enum): - return str(val) - elif isinstance(getattr(val, "__name__", None), str): - # Name of a class, function, module, etc. - name: str = getattr(val, "__name__") - return name - return None - - def _idval_from_value_required(self, val: object, idx: int) -> str: - """Like _idval_from_value(), but fails if the type is not supported.""" - id = self._idval_from_value(val) - if id is not None: - return id - - # Fail. - prefix = self._make_error_prefix() - msg = ( - f"{prefix}ids contains unsupported value {saferepr(val)} (type: {type(val)!r}) at index {idx}. " - "Supported types are: str, bytes, int, float, complex, bool, enum, regex or anything with a __name__." - ) - fail(msg, pytrace=False) - - @staticmethod - def _idval_from_argname(argname: str, idx: int) -> str: - """Make an ID for a parameter in a ParameterSet from the argument name - and the index of the ParameterSet.""" - return str(argname) + str(idx) - - def _complain_multiple_hidden_parameter_sets(self) -> NoReturn: - fail( - f"{self._make_error_prefix()}multiple instances of HIDDEN_PARAM " - "cannot be used in the same parametrize call, " - "because the tests names need to be unique." - ) - - def _make_error_prefix(self) -> str: - if self.func_name is not None: - return f"In {self.func_name}: " - elif self.nodeid is not None: - return f"In {self.nodeid}: " - else: - return "" - - -@final -@dataclasses.dataclass(frozen=True) -class CallSpec2: - """A planned parameterized invocation of a test function. - - Calculated during collection for a given test function's Metafunc. - Once collection is over, each callspec is turned into a single Item - and stored in item.callspec. - """ - - # arg name -> arg value which will be passed to a fixture or pseudo-fixture - # of the same name. (indirect or direct parametrization respectively) - params: dict[str, object] = dataclasses.field(default_factory=dict) - # arg name -> arg index. - indices: dict[str, int] = dataclasses.field(default_factory=dict) - # arg name -> parameter scope. - # Used for sorting parametrized resources. - _arg2scope: Mapping[str, Scope] = dataclasses.field(default_factory=dict) - # Parts which will be added to the item's name in `[..]` separated by "-". - _idlist: Sequence[str] = dataclasses.field(default_factory=tuple) - # Marks which will be applied to the item. - marks: list[Mark] = dataclasses.field(default_factory=list) - - def setmulti( - self, - *, - argnames: Iterable[str], - valset: Iterable[object], - id: str | _HiddenParam, - marks: Iterable[Mark | MarkDecorator], - scope: Scope, - param_index: int, - nodeid: str, - ) -> CallSpec2: - params = self.params.copy() - indices = self.indices.copy() - arg2scope = dict(self._arg2scope) - for arg, val in zip(argnames, valset, strict=True): - if arg in params: - raise nodes.Collector.CollectError( - f"{nodeid}: duplicate parametrization of {arg!r}" - ) - params[arg] = val - indices[arg] = param_index - arg2scope[arg] = scope - return CallSpec2( - params=params, - indices=indices, - _arg2scope=arg2scope, - _idlist=self._idlist if id is HIDDEN_PARAM else [*self._idlist, id], - marks=[*self.marks, *normalize_mark_list(marks)], - ) - - def getparam(self, name: str) -> object: - try: - return self.params[name] - except KeyError as e: - raise ValueError(name) from e - - @property - def id(self) -> str: - return "-".join(self._idlist) - - -def get_direct_param_fixture_func(request: FixtureRequest) -> Any: - return request.param - - -# Used for storing pseudo fixturedefs for direct parametrization. -name2pseudofixturedef_key = StashKey[dict[str, FixtureDef[Any]]]() - - -@final -class Metafunc: - """Objects passed to the :hook:`pytest_generate_tests` hook. - - They help to inspect a test function and to generate tests according to - test configuration or values specified in the class or module where a - test function is defined. - """ - - def __init__( - self, - definition: FunctionDefinition, - fixtureinfo: fixtures.FuncFixtureInfo, - config: Config, - cls=None, - module=None, - *, - _ispytest: bool = False, - ) -> None: - check_ispytest(_ispytest) - - #: Access to the underlying :class:`_pytest.python.FunctionDefinition`. - self.definition = definition - - #: Access to the :class:`pytest.Config` object for the test session. - self.config = config - - #: The module object where the test function is defined in. - self.module = module - - #: Underlying Python test function. - self.function = definition.obj - - #: Set of fixture names required by the test function. - self.fixturenames = fixtureinfo.names_closure - - #: Class object where the test function is defined in or ``None``. - self.cls = cls - - self._arg2fixturedefs = fixtureinfo.name2fixturedefs - - # Result of parametrize(). - self._calls: list[CallSpec2] = [] - - self._params_directness: dict[str, Literal["indirect", "direct"]] = {} - - def parametrize( - self, - argnames: str | Sequence[str], - argvalues: Iterable[ParameterSet | Sequence[object] | object], - indirect: bool | Sequence[str] = False, - ids: Iterable[object | None] | Callable[[Any], object | None] | None = None, - scope: _ScopeName | None = None, - *, - _param_mark: Mark | None = None, - ) -> None: - """Add new invocations to the underlying test function using the list - of argvalues for the given argnames. Parametrization is performed - during the collection phase. If you need to setup expensive resources - see about setting ``indirect`` to do it at test setup time instead. - - Can be called multiple times per test function (but only on different - argument names), in which case each call parametrizes all previous - parametrizations, e.g. - - :: - - unparametrized: t - parametrize ["x", "y"]: t[x], t[y] - parametrize [1, 2]: t[x-1], t[x-2], t[y-1], t[y-2] - - :param argnames: - A comma-separated string denoting one or more argument names, or - a list/tuple of argument strings. - - :param argvalues: - The list of argvalues determines how often a test is invoked with - different argument values. - - If only one argname was specified argvalues is a list of values. - If N argnames were specified, argvalues must be a list of - N-tuples, where each tuple-element specifies a value for its - respective argname. - - :param indirect: - A list of arguments' names (subset of argnames) or a boolean. - If True the list contains all names from the argnames. Each - argvalue corresponding to an argname in this list will - be passed as request.param to its respective argname fixture - function so that it can perform more expensive setups during the - setup phase of a test rather than at collection time. - - :param ids: - Sequence of (or generator for) ids for ``argvalues``, - or a callable to return part of the id for each argvalue. - - With sequences (and generators like ``itertools.count()``) the - returned ids should be of type ``string``, ``int``, ``float``, - ``bool``, or ``None``. - They are mapped to the corresponding index in ``argvalues``. - ``None`` means to use the auto-generated id. - - .. versionadded:: 8.4 - :ref:`hidden-param` means to hide the parameter set - from the test name. Can only be used at most 1 time, as - test names need to be unique. - - If it is a callable it will be called for each entry in - ``argvalues``, and the return value is used as part of the - auto-generated id for the whole set (where parts are joined with - dashes ("-")). - This is useful to provide more specific ids for certain items, e.g. - dates. Returning ``None`` will use an auto-generated id. - - If no ids are provided they will be generated automatically from - the argvalues. - - :param scope: - If specified it denotes the scope of the parameters. - The scope is used for grouping tests by parameter instances. - It will also override any fixture-function defined scope, allowing - to set a dynamic scope using test context or configuration. - """ - nodeid = self.definition.nodeid - - argnames, parametersets = ParameterSet._for_parametrize( - argnames, - argvalues, - self.function, - self.config, - nodeid=self.definition.nodeid, - ) - del argvalues - - if "request" in argnames: - fail( - f"{nodeid}: 'request' is a reserved name and cannot be used in @pytest.mark.parametrize", - pytrace=False, - ) - - if scope is not None: - scope_ = Scope.from_user( - scope, descr=f"parametrize() call in {self.function.__name__}" - ) - else: - scope_ = _find_parametrized_scope(argnames, self._arg2fixturedefs, indirect) - - self._validate_if_using_arg_names(argnames, indirect) - - # Use any already (possibly) generated ids with parametrize Marks. - if _param_mark and _param_mark._param_ids_from: - generated_ids = _param_mark._param_ids_from._param_ids_generated - if generated_ids is not None: - ids = generated_ids - - ids = self._resolve_parameter_set_ids( - argnames, ids, parametersets, nodeid=self.definition.nodeid - ) - - # Store used (possibly generated) ids with parametrize Marks. - if _param_mark and _param_mark._param_ids_from and generated_ids is None: - object.__setattr__(_param_mark._param_ids_from, "_param_ids_generated", ids) - - # Calculate directness. - arg_directness = self._resolve_args_directness(argnames, indirect) - self._params_directness.update(arg_directness) - - # Add direct parametrizations as fixturedefs to arg2fixturedefs by - # registering artificial "pseudo" FixtureDef's such that later at test - # setup time we can rely on FixtureDefs to exist for all argnames. - node = None - # For scopes higher than function, a "pseudo" FixtureDef might have - # already been created for the scope. We thus store and cache the - # FixtureDef on the node related to the scope. - if scope_ is Scope.Function: - name2pseudofixturedef = None - else: - collector = self.definition.parent - assert collector is not None - node = get_scope_node(collector, scope_) - if node is None: - # If used class scope and there is no class, use module-level - # collector (for now). - if scope_ is Scope.Class: - assert isinstance(collector, Module) - node = collector - # If used package scope and there is no package, use session - # (for now). - elif scope_ is Scope.Package: - node = collector.session - else: - assert False, f"Unhandled missing scope: {scope}" - default: dict[str, FixtureDef[Any]] = {} - name2pseudofixturedef = node.stash.setdefault( - name2pseudofixturedef_key, default - ) - for argname in argnames: - if arg_directness[argname] == "indirect": - continue - if name2pseudofixturedef is not None and argname in name2pseudofixturedef: - fixturedef = name2pseudofixturedef[argname] - else: - fixturedef = FixtureDef( - config=self.config, - baseid="", - argname=argname, - func=get_direct_param_fixture_func, - scope=scope_, - params=None, - ids=None, - _ispytest=True, - ) - if name2pseudofixturedef is not None: - name2pseudofixturedef[argname] = fixturedef - self._arg2fixturedefs[argname] = [fixturedef] - - # Create the new calls: if we are parametrize() multiple times (by applying the decorator - # more than once) then we accumulate those calls generating the cartesian product - # of all calls. - newcalls = [] - for callspec in self._calls or [CallSpec2()]: - for param_index, (param_id, param_set) in enumerate( - zip(ids, parametersets, strict=True) - ): - newcallspec = callspec.setmulti( - argnames=argnames, - valset=param_set.values, - id=param_id, - marks=param_set.marks, - scope=scope_, - param_index=param_index, - nodeid=nodeid, - ) - newcalls.append(newcallspec) - self._calls = newcalls - - def _resolve_parameter_set_ids( - self, - argnames: Sequence[str], - ids: Iterable[object | None] | Callable[[Any], object | None] | None, - parametersets: Sequence[ParameterSet], - nodeid: str, - ) -> list[str | _HiddenParam]: - """Resolve the actual ids for the given parameter sets. - - :param argnames: - Argument names passed to ``parametrize()``. - :param ids: - The `ids` parameter of the ``parametrize()`` call (see docs). - :param parametersets: - The parameter sets, each containing a set of values corresponding - to ``argnames``. - :param nodeid str: - The nodeid of the definition item that generated this - parametrization. - :returns: - List with ids for each parameter set given. - """ - if ids is None: - idfn = None - ids_ = None - elif callable(ids): - idfn = ids - ids_ = None - else: - idfn = None - ids_ = self._validate_ids(ids, parametersets, self.function.__name__) - id_maker = IdMaker( - argnames, - parametersets, - idfn, - ids_, - self.config, - nodeid=nodeid, - func_name=self.function.__name__, - ) - return id_maker.make_unique_parameterset_ids() - - def _validate_ids( - self, - ids: Iterable[object | None], - parametersets: Sequence[ParameterSet], - func_name: str, - ) -> list[object | None]: - try: - num_ids = len(ids) # type: ignore[arg-type] - except TypeError: - try: - iter(ids) - except TypeError as e: - raise TypeError("ids must be a callable or an iterable") from e - num_ids = len(parametersets) - - # num_ids == 0 is a special case: https://github.com/pytest-dev/pytest/issues/1849 - if num_ids != len(parametersets) and num_ids != 0: - msg = "In {}: {} parameter sets specified, with different number of ids: {}" - fail(msg.format(func_name, len(parametersets), num_ids), pytrace=False) - - return list(itertools.islice(ids, num_ids)) - - def _resolve_args_directness( - self, - argnames: Sequence[str], - indirect: bool | Sequence[str], - ) -> dict[str, Literal["indirect", "direct"]]: - """Resolve if each parametrized argument must be considered an indirect - parameter to a fixture of the same name, or a direct parameter to the - parametrized function, based on the ``indirect`` parameter of the - parametrized() call. - - :param argnames: - List of argument names passed to ``parametrize()``. - :param indirect: - Same as the ``indirect`` parameter of ``parametrize()``. - :returns - A dict mapping each arg name to either "indirect" or "direct". - """ - arg_directness: dict[str, Literal["indirect", "direct"]] - if isinstance(indirect, bool): - arg_directness = dict.fromkeys( - argnames, "indirect" if indirect else "direct" - ) - elif isinstance(indirect, Sequence): - arg_directness = dict.fromkeys(argnames, "direct") - for arg in indirect: - if arg not in argnames: - fail( - f"In {self.function.__name__}: indirect fixture '{arg}' doesn't exist", - pytrace=False, - ) - arg_directness[arg] = "indirect" - else: - fail( - f"In {self.function.__name__}: expected Sequence or boolean" - f" for indirect, got {type(indirect).__name__}", - pytrace=False, - ) - return arg_directness - - def _validate_if_using_arg_names( - self, - argnames: Sequence[str], - indirect: bool | Sequence[str], - ) -> None: - """Check if all argnames are being used, by default values, or directly/indirectly. - - :param List[str] argnames: List of argument names passed to ``parametrize()``. - :param indirect: Same as the ``indirect`` parameter of ``parametrize()``. - :raises ValueError: If validation fails. - """ - default_arg_names = set(get_default_arg_names(self.function)) - func_name = self.function.__name__ - for arg in argnames: - if arg not in self.fixturenames: - if arg in default_arg_names: - fail( - f"In {func_name}: function already takes an argument '{arg}' with a default value", - pytrace=False, - ) - else: - if isinstance(indirect, Sequence): - name = "fixture" if arg in indirect else "argument" - else: - name = "fixture" if indirect else "argument" - fail( - f"In {func_name}: function uses no {name} '{arg}'", - pytrace=False, - ) - - def _recompute_direct_params_indices(self) -> None: - for argname, param_type in self._params_directness.items(): - if param_type == "direct": - for i, callspec in enumerate(self._calls): - callspec.indices[argname] = i - - -def _find_parametrized_scope( - argnames: Sequence[str], - arg2fixturedefs: Mapping[str, Sequence[fixtures.FixtureDef[object]]], - indirect: bool | Sequence[str], -) -> Scope: - """Find the most appropriate scope for a parametrized call based on its arguments. - - When there's at least one direct argument, always use "function" scope. - - When a test function is parametrized and all its arguments are indirect - (e.g. fixtures), return the most narrow scope based on the fixtures used. - - Related to issue #1832, based on code posted by @Kingdread. - """ - if isinstance(indirect, Sequence): - all_arguments_are_fixtures = len(indirect) == len(argnames) - else: - all_arguments_are_fixtures = bool(indirect) - - if all_arguments_are_fixtures: - fixturedefs = arg2fixturedefs or {} - used_scopes = [ - fixturedef[-1]._scope - for name, fixturedef in fixturedefs.items() - if name in argnames - ] - # Takes the most narrow scope from used fixtures. - return min(used_scopes, default=Scope.Function) - - return Scope.Function - - -def _ascii_escaped_by_config(val: str | bytes, config: Config | None) -> str: - if config is None: - escape_option = False - else: - escape_option = config.getini( - "disable_test_id_escaping_and_forfeit_all_rights_to_community_support" - ) - # TODO: If escaping is turned off and the user passes bytes, - # will return a bytes. For now we ignore this but the - # code *probably* doesn't handle this case. - return val if escape_option else ascii_escaped(val) # type: ignore - - -class Function(PyobjMixin, nodes.Item): - """Item responsible for setting up and executing a Python test function. - - :param name: - The full function name, including any decorations like those - added by parametrization (``my_func[my_param]``). - :param parent: - The parent Node. - :param config: - The pytest Config object. - :param callspec: - If given, this function has been parametrized and the callspec contains - meta information about the parametrization. - :param callobj: - If given, the object which will be called when the Function is invoked, - otherwise the callobj will be obtained from ``parent`` using ``originalname``. - :param keywords: - Keywords bound to the function object for "-k" matching. - :param session: - The pytest Session object. - :param fixtureinfo: - Fixture information already resolved at this fixture node.. - :param originalname: - The attribute name to use for accessing the underlying function object. - Defaults to ``name``. Set this if name is different from the original name, - for example when it contains decorations like those added by parametrization - (``my_func[my_param]``). - """ - - # Disable since functions handle it themselves. - _ALLOW_MARKERS = False - - def __init__( - self, - name: str, - parent, - config: Config | None = None, - callspec: CallSpec2 | None = None, - callobj=NOTSET, - keywords: Mapping[str, Any] | None = None, - session: Session | None = None, - fixtureinfo: FuncFixtureInfo | None = None, - originalname: str | None = None, - ) -> None: - super().__init__(name, parent, config=config, session=session) - - if callobj is not NOTSET: - self._obj = callobj - self._instance = getattr(callobj, "__self__", None) - - #: Original function name, without any decorations (for example - #: parametrization adds a ``"[...]"`` suffix to function names), used to access - #: the underlying function object from ``parent`` (in case ``callobj`` is not given - #: explicitly). - #: - #: .. versionadded:: 3.0 - self.originalname = originalname or name - - # Note: when FunctionDefinition is introduced, we should change ``originalname`` - # to a readonly property that returns FunctionDefinition.name. - - self.own_markers.extend(get_unpacked_marks(self.obj)) - if callspec: - self.callspec = callspec - self.own_markers.extend(callspec.marks) - - # todo: this is a hell of a hack - # https://github.com/pytest-dev/pytest/issues/4569 - # Note: the order of the updates is important here; indicates what - # takes priority (ctor argument over function attributes over markers). - # Take own_markers only; NodeKeywords handles parent traversal on its own. - self.keywords.update((mark.name, mark) for mark in self.own_markers) - self.keywords.update(self.obj.__dict__) - if keywords: - self.keywords.update(keywords) - - if fixtureinfo is None: - fm = self.session._fixturemanager - fixtureinfo = fm.getfixtureinfo(self, self.obj, self.cls) - self._fixtureinfo: FuncFixtureInfo = fixtureinfo - self.fixturenames = fixtureinfo.names_closure - self._initrequest() - - # todo: determine sound type limitations - @classmethod - def from_parent(cls, parent, **kw) -> Self: - """The public constructor.""" - return super().from_parent(parent=parent, **kw) - - def _initrequest(self) -> None: - self.funcargs: dict[str, object] = {} - self._request = fixtures.TopRequest(self, _ispytest=True) - - @property - def function(self): - """Underlying python 'function' object.""" - return getimfunc(self.obj) - - @property - def instance(self): - try: - return self._instance - except AttributeError: - if isinstance(self.parent, Class): - # Each Function gets a fresh class instance. - self._instance = self._getinstance() - else: - self._instance = None - return self._instance - - def _getinstance(self): - if isinstance(self.parent, Class): - # Each Function gets a fresh class instance. - return self.parent.newinstance() - else: - return None - - def _getobj(self): - instance = self.instance - if instance is not None: - parent_obj = instance - else: - assert self.parent is not None - parent_obj = self.parent.obj # type: ignore[attr-defined] - return getattr(parent_obj, self.originalname) - - @property - def _pyfuncitem(self): - """(compatonly) for code expecting pytest-2.2 style request objects.""" - return self - - def runtest(self) -> None: - """Execute the underlying test function.""" - self.ihook.pytest_pyfunc_call(pyfuncitem=self) - - def setup(self) -> None: - self._request._fillfixtures() - - def _traceback_filter(self, excinfo: ExceptionInfo[BaseException]) -> Traceback: - if hasattr(self, "_obj") and not self.config.getoption("fulltrace", False): - code = _pytest._code.Code.from_function(get_real_func(self.obj)) - path, firstlineno = code.path, code.firstlineno - traceback = excinfo.traceback - ntraceback = traceback.cut(path=path, firstlineno=firstlineno) - if ntraceback == traceback: - ntraceback = ntraceback.cut(path=path) - if ntraceback == traceback: - ntraceback = ntraceback.filter(filter_traceback) - if not ntraceback: - ntraceback = traceback - ntraceback = ntraceback.filter(excinfo) - - # issue364: mark all but first and last frames to - # only show a single-line message for each frame. - if self.config.getoption("tbstyle", "auto") == "auto": - if len(ntraceback) > 2: - ntraceback = Traceback( - ( - ntraceback[0], - *(t.with_repr_style("short") for t in ntraceback[1:-1]), - ntraceback[-1], - ) - ) - - return ntraceback - return excinfo.traceback - - # TODO: Type ignored -- breaks Liskov Substitution. - def repr_failure( # type: ignore[override] - self, - excinfo: ExceptionInfo[BaseException], - ) -> str | TerminalRepr: - style = self.config.getoption("tbstyle", "auto") - if style == "auto": - style = "long" - return self._repr_failure_py(excinfo, style=style) - - -class FunctionDefinition(Function): - """This class is a stop gap solution until we evolve to have actual function - definition nodes and manage to get rid of ``metafunc``.""" - - def runtest(self) -> None: - raise RuntimeError("function definitions are not supposed to be run as tests") - - setup = runtest diff --git a/.venv/lib/python3.12/site-packages/_pytest/python_api.py b/.venv/lib/python3.12/site-packages/_pytest/python_api.py deleted file mode 100644 index bab70aa..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/python_api.py +++ /dev/null @@ -1,819 +0,0 @@ -# mypy: allow-untyped-defs -from __future__ import annotations - -from collections.abc import Collection -from collections.abc import Mapping -from collections.abc import Sequence -from collections.abc import Sized -from decimal import Decimal -import math -from numbers import Complex -import pprint -import sys -from typing import Any -from typing import TYPE_CHECKING - - -if TYPE_CHECKING: - from numpy import ndarray - - -def _compare_approx( - full_object: object, - message_data: Sequence[tuple[str, str, str]], - number_of_elements: int, - different_ids: Sequence[object], - max_abs_diff: float, - max_rel_diff: float, -) -> list[str]: - message_list = list(message_data) - message_list.insert(0, ("Index", "Obtained", "Expected")) - max_sizes = [0, 0, 0] - for index, obtained, expected in message_list: - max_sizes[0] = max(max_sizes[0], len(index)) - max_sizes[1] = max(max_sizes[1], len(obtained)) - max_sizes[2] = max(max_sizes[2], len(expected)) - explanation = [ - f"comparison failed. Mismatched elements: {len(different_ids)} / {number_of_elements}:", - f"Max absolute difference: {max_abs_diff}", - f"Max relative difference: {max_rel_diff}", - ] + [ - f"{indexes:<{max_sizes[0]}} | {obtained:<{max_sizes[1]}} | {expected:<{max_sizes[2]}}" - for indexes, obtained, expected in message_list - ] - return explanation - - -# builtin pytest.approx helper - - -class ApproxBase: - """Provide shared utilities for making approximate comparisons between - numbers or sequences of numbers.""" - - # Tell numpy to use our `__eq__` operator instead of its. - __array_ufunc__ = None - __array_priority__ = 100 - - def __init__(self, expected, rel=None, abs=None, nan_ok: bool = False) -> None: - __tracebackhide__ = True - self.expected = expected - self.abs = abs - self.rel = rel - self.nan_ok = nan_ok - self._check_type() - - def __repr__(self) -> str: - raise NotImplementedError - - def _repr_compare(self, other_side: Any) -> list[str]: - return [ - "comparison failed", - f"Obtained: {other_side}", - f"Expected: {self}", - ] - - def __eq__(self, actual) -> bool: - return all( - a == self._approx_scalar(x) for a, x in self._yield_comparisons(actual) - ) - - def __bool__(self): - __tracebackhide__ = True - raise AssertionError( - "approx() is not supported in a boolean context.\nDid you mean: `assert a == approx(b)`?" - ) - - # Ignore type because of https://github.com/python/mypy/issues/4266. - __hash__ = None # type: ignore - - def __ne__(self, actual) -> bool: - return not (actual == self) - - def _approx_scalar(self, x) -> ApproxScalar: - if isinstance(x, Decimal): - return ApproxDecimal(x, rel=self.rel, abs=self.abs, nan_ok=self.nan_ok) - return ApproxScalar(x, rel=self.rel, abs=self.abs, nan_ok=self.nan_ok) - - def _yield_comparisons(self, actual): - """Yield all the pairs of numbers to be compared. - - This is used to implement the `__eq__` method. - """ - raise NotImplementedError - - def _check_type(self) -> None: - """Raise a TypeError if the expected value is not a valid type.""" - # This is only a concern if the expected value is a sequence. In every - # other case, the approx() function ensures that the expected value has - # a numeric type. For this reason, the default is to do nothing. The - # classes that deal with sequences should reimplement this method to - # raise if there are any non-numeric elements in the sequence. - - -def _recursive_sequence_map(f, x): - """Recursively map a function over a sequence of arbitrary depth""" - if isinstance(x, list | tuple): - seq_type = type(x) - return seq_type(_recursive_sequence_map(f, xi) for xi in x) - elif _is_sequence_like(x): - return [_recursive_sequence_map(f, xi) for xi in x] - else: - return f(x) - - -class ApproxNumpy(ApproxBase): - """Perform approximate comparisons where the expected value is numpy array.""" - - def __repr__(self) -> str: - list_scalars = _recursive_sequence_map( - self._approx_scalar, self.expected.tolist() - ) - return f"approx({list_scalars!r})" - - def _repr_compare(self, other_side: ndarray | list[Any]) -> list[str]: - import itertools - import math - - def get_value_from_nested_list( - nested_list: list[Any], nd_index: tuple[Any, ...] - ) -> Any: - """ - Helper function to get the value out of a nested list, given an n-dimensional index. - This mimics numpy's indexing, but for raw nested python lists. - """ - value: Any = nested_list - for i in nd_index: - value = value[i] - return value - - np_array_shape = self.expected.shape - approx_side_as_seq = _recursive_sequence_map( - self._approx_scalar, self.expected.tolist() - ) - - # convert other_side to numpy array to ensure shape attribute is available - other_side_as_array = _as_numpy_array(other_side) - assert other_side_as_array is not None - - if np_array_shape != other_side_as_array.shape: - return [ - "Impossible to compare arrays with different shapes.", - f"Shapes: {np_array_shape} and {other_side_as_array.shape}", - ] - - number_of_elements = self.expected.size - max_abs_diff = -math.inf - max_rel_diff = -math.inf - different_ids = [] - for index in itertools.product(*(range(i) for i in np_array_shape)): - approx_value = get_value_from_nested_list(approx_side_as_seq, index) - other_value = get_value_from_nested_list(other_side_as_array, index) - if approx_value != other_value: - abs_diff = abs(approx_value.expected - other_value) - max_abs_diff = max(max_abs_diff, abs_diff) - if other_value == 0.0: - max_rel_diff = math.inf - else: - max_rel_diff = max(max_rel_diff, abs_diff / abs(other_value)) - different_ids.append(index) - - message_data = [ - ( - str(index), - str(get_value_from_nested_list(other_side_as_array, index)), - str(get_value_from_nested_list(approx_side_as_seq, index)), - ) - for index in different_ids - ] - return _compare_approx( - self.expected, - message_data, - number_of_elements, - different_ids, - max_abs_diff, - max_rel_diff, - ) - - def __eq__(self, actual) -> bool: - import numpy as np - - # self.expected is supposed to always be an array here. - - if not np.isscalar(actual): - try: - actual = np.asarray(actual) - except Exception as e: - raise TypeError(f"cannot compare '{actual}' to numpy.ndarray") from e - - if not np.isscalar(actual) and actual.shape != self.expected.shape: - return False - - return super().__eq__(actual) - - def _yield_comparisons(self, actual): - import numpy as np - - # `actual` can either be a numpy array or a scalar, it is treated in - # `__eq__` before being passed to `ApproxBase.__eq__`, which is the - # only method that calls this one. - - if np.isscalar(actual): - for i in np.ndindex(self.expected.shape): - yield actual, self.expected[i].item() - else: - for i in np.ndindex(self.expected.shape): - yield actual[i].item(), self.expected[i].item() - - -class ApproxMapping(ApproxBase): - """Perform approximate comparisons where the expected value is a mapping - with numeric values (the keys can be anything).""" - - def __repr__(self) -> str: - return f"approx({ ({k: self._approx_scalar(v) for k, v in self.expected.items()})!r})" - - def _repr_compare(self, other_side: Mapping[object, float]) -> list[str]: - import math - - if len(self.expected) != len(other_side): - return [ - "Impossible to compare mappings with different sizes.", - f"Lengths: {len(self.expected)} and {len(other_side)}", - ] - - if self.expected.keys() != other_side.keys(): - return [ - "comparison failed.", - f"Mappings has different keys: expected {self.expected.keys()} but got {other_side.keys()}", - ] - - approx_side_as_map = { - k: self._approx_scalar(v) for k, v in self.expected.items() - } - - number_of_elements = len(approx_side_as_map) - max_abs_diff = -math.inf - max_rel_diff = -math.inf - different_ids = [] - for approx_key, approx_value in approx_side_as_map.items(): - other_value = other_side[approx_key] - if approx_value != other_value: - if approx_value.expected is not None and other_value is not None: - try: - max_abs_diff = max( - max_abs_diff, abs(approx_value.expected - other_value) - ) - if approx_value.expected == 0.0: - max_rel_diff = math.inf - else: - max_rel_diff = max( - max_rel_diff, - abs( - (approx_value.expected - other_value) - / approx_value.expected - ), - ) - except ZeroDivisionError: - pass - different_ids.append(approx_key) - - message_data = [ - (str(key), str(other_side[key]), str(approx_side_as_map[key])) - for key in different_ids - ] - - return _compare_approx( - self.expected, - message_data, - number_of_elements, - different_ids, - max_abs_diff, - max_rel_diff, - ) - - def __eq__(self, actual) -> bool: - try: - if set(actual.keys()) != set(self.expected.keys()): - return False - except AttributeError: - return False - - return super().__eq__(actual) - - def _yield_comparisons(self, actual): - for k in self.expected.keys(): - yield actual[k], self.expected[k] - - def _check_type(self) -> None: - __tracebackhide__ = True - for key, value in self.expected.items(): - if isinstance(value, type(self.expected)): - msg = "pytest.approx() does not support nested dictionaries: key={!r} value={!r}\n full mapping={}" - raise TypeError(msg.format(key, value, pprint.pformat(self.expected))) - - -class ApproxSequenceLike(ApproxBase): - """Perform approximate comparisons where the expected value is a sequence of numbers.""" - - def __repr__(self) -> str: - seq_type = type(self.expected) - if seq_type not in (tuple, list): - seq_type = list - return f"approx({seq_type(self._approx_scalar(x) for x in self.expected)!r})" - - def _repr_compare(self, other_side: Sequence[float]) -> list[str]: - import math - - if len(self.expected) != len(other_side): - return [ - "Impossible to compare lists with different sizes.", - f"Lengths: {len(self.expected)} and {len(other_side)}", - ] - - approx_side_as_map = _recursive_sequence_map(self._approx_scalar, self.expected) - - number_of_elements = len(approx_side_as_map) - max_abs_diff = -math.inf - max_rel_diff = -math.inf - different_ids = [] - for i, (approx_value, other_value) in enumerate( - zip(approx_side_as_map, other_side, strict=True) - ): - if approx_value != other_value: - try: - abs_diff = abs(approx_value.expected - other_value) - max_abs_diff = max(max_abs_diff, abs_diff) - # Ignore non-numbers for the diff calculations (#13012). - except TypeError: - pass - else: - if other_value == 0.0: - max_rel_diff = math.inf - else: - max_rel_diff = max(max_rel_diff, abs_diff / abs(other_value)) - different_ids.append(i) - message_data = [ - (str(i), str(other_side[i]), str(approx_side_as_map[i])) - for i in different_ids - ] - - return _compare_approx( - self.expected, - message_data, - number_of_elements, - different_ids, - max_abs_diff, - max_rel_diff, - ) - - def __eq__(self, actual) -> bool: - try: - if len(actual) != len(self.expected): - return False - except TypeError: - return False - return super().__eq__(actual) - - def _yield_comparisons(self, actual): - return zip(actual, self.expected, strict=True) - - def _check_type(self) -> None: - __tracebackhide__ = True - for index, x in enumerate(self.expected): - if isinstance(x, type(self.expected)): - msg = "pytest.approx() does not support nested data structures: {!r} at index {}\n full sequence: {}" - raise TypeError(msg.format(x, index, pprint.pformat(self.expected))) - - -class ApproxScalar(ApproxBase): - """Perform approximate comparisons where the expected value is a single number.""" - - # Using Real should be better than this Union, but not possible yet: - # https://github.com/python/typeshed/pull/3108 - DEFAULT_ABSOLUTE_TOLERANCE: float | Decimal = 1e-12 - DEFAULT_RELATIVE_TOLERANCE: float | Decimal = 1e-6 - - def __repr__(self) -> str: - """Return a string communicating both the expected value and the - tolerance for the comparison being made. - - For example, ``1.0 ± 1e-6``, ``(3+4j) ± 5e-6 ∠ ±180°``. - """ - # Don't show a tolerance for values that aren't compared using - # tolerances, i.e. non-numerics and infinities. Need to call abs to - # handle complex numbers, e.g. (inf + 1j). - if ( - isinstance(self.expected, bool) - or (not isinstance(self.expected, Complex | Decimal)) - or math.isinf(abs(self.expected) or isinstance(self.expected, bool)) - ): - return str(self.expected) - - # If a sensible tolerance can't be calculated, self.tolerance will - # raise a ValueError. In this case, display '???'. - try: - if 1e-3 <= self.tolerance < 1e3: - vetted_tolerance = f"{self.tolerance:n}" - else: - vetted_tolerance = f"{self.tolerance:.1e}" - - if ( - isinstance(self.expected, Complex) - and self.expected.imag - and not math.isinf(self.tolerance) - ): - vetted_tolerance += " ∠ ±180°" - except ValueError: - vetted_tolerance = "???" - - return f"{self.expected} ± {vetted_tolerance}" - - def __eq__(self, actual) -> bool: - """Return whether the given value is equal to the expected value - within the pre-specified tolerance.""" - - def is_bool(val: Any) -> bool: - # Check if `val` is a native bool or numpy bool. - if isinstance(val, bool): - return True - if np := sys.modules.get("numpy"): - return isinstance(val, np.bool_) - return False - - asarray = _as_numpy_array(actual) - if asarray is not None: - # Call ``__eq__()`` manually to prevent infinite-recursion with - # numpy<1.13. See #3748. - return all(self.__eq__(a) for a in asarray.flat) - - # Short-circuit exact equality, except for bool and np.bool_ - if is_bool(self.expected) and not is_bool(actual): - return False - elif actual == self.expected: - return True - - # If either type is non-numeric, fall back to strict equality. - # NB: we need Complex, rather than just Number, to ensure that __abs__, - # __sub__, and __float__ are defined. Also, consider bool to be - # non-numeric, even though it has the required arithmetic. - if is_bool(self.expected) or not ( - isinstance(self.expected, Complex | Decimal) - and isinstance(actual, Complex | Decimal) - ): - return False - - # Allow the user to control whether NaNs are considered equal to each - # other or not. The abs() calls are for compatibility with complex - # numbers. - if math.isnan(abs(self.expected)): - return self.nan_ok and math.isnan(abs(actual)) - - # Infinity shouldn't be approximately equal to anything but itself, but - # if there's a relative tolerance, it will be infinite and infinity - # will seem approximately equal to everything. The equal-to-itself - # case would have been short circuited above, so here we can just - # return false if the expected value is infinite. The abs() call is - # for compatibility with complex numbers. - if math.isinf(abs(self.expected)): - return False - - # Return true if the two numbers are within the tolerance. - result: bool = abs(self.expected - actual) <= self.tolerance - return result - - __hash__ = None - - @property - def tolerance(self): - """Return the tolerance for the comparison. - - This could be either an absolute tolerance or a relative tolerance, - depending on what the user specified or which would be larger. - """ - - def set_default(x, default): - return x if x is not None else default - - # Figure out what the absolute tolerance should be. ``self.abs`` is - # either None or a value specified by the user. - absolute_tolerance = set_default(self.abs, self.DEFAULT_ABSOLUTE_TOLERANCE) - - if absolute_tolerance < 0: - raise ValueError( - f"absolute tolerance can't be negative: {absolute_tolerance}" - ) - if math.isnan(absolute_tolerance): - raise ValueError("absolute tolerance can't be NaN.") - - # If the user specified an absolute tolerance but not a relative one, - # just return the absolute tolerance. - if self.rel is None: - if self.abs is not None: - return absolute_tolerance - - # Figure out what the relative tolerance should be. ``self.rel`` is - # either None or a value specified by the user. This is done after - # we've made sure the user didn't ask for an absolute tolerance only, - # because we don't want to raise errors about the relative tolerance if - # we aren't even going to use it. - relative_tolerance = set_default( - self.rel, self.DEFAULT_RELATIVE_TOLERANCE - ) * abs(self.expected) - - if relative_tolerance < 0: - raise ValueError( - f"relative tolerance can't be negative: {relative_tolerance}" - ) - if math.isnan(relative_tolerance): - raise ValueError("relative tolerance can't be NaN.") - - # Return the larger of the relative and absolute tolerances. - return max(relative_tolerance, absolute_tolerance) - - -class ApproxDecimal(ApproxScalar): - """Perform approximate comparisons where the expected value is a Decimal.""" - - DEFAULT_ABSOLUTE_TOLERANCE = Decimal("1e-12") - DEFAULT_RELATIVE_TOLERANCE = Decimal("1e-6") - - def __repr__(self) -> str: - if isinstance(self.rel, float): - rel = Decimal.from_float(self.rel) - else: - rel = self.rel - - if isinstance(self.abs, float): - abs_ = Decimal.from_float(self.abs) - else: - abs_ = self.abs - - tol_str = "???" - if rel is not None and Decimal("1e-3") <= rel <= Decimal("1e3"): - tol_str = f"{rel:.1e}" - elif abs_ is not None: - tol_str = f"{abs_:.1e}" - - return f"{self.expected} ± {tol_str}" - - -def approx(expected, rel=None, abs=None, nan_ok: bool = False) -> ApproxBase: - """Assert that two numbers (or two ordered sequences of numbers) are equal to each other - within some tolerance. - - Due to the :doc:`python:tutorial/floatingpoint`, numbers that we - would intuitively expect to be equal are not always so:: - - >>> 0.1 + 0.2 == 0.3 - False - - This problem is commonly encountered when writing tests, e.g. when making - sure that floating-point values are what you expect them to be. One way to - deal with this problem is to assert that two floating-point numbers are - equal to within some appropriate tolerance:: - - >>> abs((0.1 + 0.2) - 0.3) < 1e-6 - True - - However, comparisons like this are tedious to write and difficult to - understand. Furthermore, absolute comparisons like the one above are - usually discouraged because there's no tolerance that works well for all - situations. ``1e-6`` is good for numbers around ``1``, but too small for - very big numbers and too big for very small ones. It's better to express - the tolerance as a fraction of the expected value, but relative comparisons - like that are even more difficult to write correctly and concisely. - - The ``approx`` class performs floating-point comparisons using a syntax - that's as intuitive as possible:: - - >>> from pytest import approx - >>> 0.1 + 0.2 == approx(0.3) - True - - The same syntax also works for ordered sequences of numbers:: - - >>> (0.1 + 0.2, 0.2 + 0.4) == approx((0.3, 0.6)) - True - - ``numpy`` arrays:: - - >>> import numpy as np # doctest: +SKIP - >>> np.array([0.1, 0.2]) + np.array([0.2, 0.4]) == approx(np.array([0.3, 0.6])) # doctest: +SKIP - True - - And for a ``numpy`` array against a scalar:: - - >>> import numpy as np # doctest: +SKIP - >>> np.array([0.1, 0.2]) + np.array([0.2, 0.1]) == approx(0.3) # doctest: +SKIP - True - - Only ordered sequences are supported, because ``approx`` needs - to infer the relative position of the sequences without ambiguity. This means - ``sets`` and other unordered sequences are not supported. - - Finally, dictionary *values* can also be compared:: - - >>> {'a': 0.1 + 0.2, 'b': 0.2 + 0.4} == approx({'a': 0.3, 'b': 0.6}) - True - - The comparison will be true if both mappings have the same keys and their - respective values match the expected tolerances. - - **Tolerances** - - By default, ``approx`` considers numbers within a relative tolerance of - ``1e-6`` (i.e. one part in a million) of its expected value to be equal. - This treatment would lead to surprising results if the expected value was - ``0.0``, because nothing but ``0.0`` itself is relatively close to ``0.0``. - To handle this case less surprisingly, ``approx`` also considers numbers - within an absolute tolerance of ``1e-12`` of its expected value to be - equal. Infinity and NaN are special cases. Infinity is only considered - equal to itself, regardless of the relative tolerance. NaN is not - considered equal to anything by default, but you can make it be equal to - itself by setting the ``nan_ok`` argument to True. (This is meant to - facilitate comparing arrays that use NaN to mean "no data".) - - Both the relative and absolute tolerances can be changed by passing - arguments to the ``approx`` constructor:: - - >>> 1.0001 == approx(1) - False - >>> 1.0001 == approx(1, rel=1e-3) - True - >>> 1.0001 == approx(1, abs=1e-3) - True - - If you specify ``abs`` but not ``rel``, the comparison will not consider - the relative tolerance at all. In other words, two numbers that are within - the default relative tolerance of ``1e-6`` will still be considered unequal - if they exceed the specified absolute tolerance. If you specify both - ``abs`` and ``rel``, the numbers will be considered equal if either - tolerance is met:: - - >>> 1 + 1e-8 == approx(1) - True - >>> 1 + 1e-8 == approx(1, abs=1e-12) - False - >>> 1 + 1e-8 == approx(1, rel=1e-6, abs=1e-12) - True - - **Non-numeric types** - - You can also use ``approx`` to compare non-numeric types, or dicts and - sequences containing non-numeric types, in which case it falls back to - strict equality. This can be useful for comparing dicts and sequences that - can contain optional values:: - - >>> {"required": 1.0000005, "optional": None} == approx({"required": 1, "optional": None}) - True - >>> [None, 1.0000005] == approx([None,1]) - True - >>> ["foo", 1.0000005] == approx([None,1]) - False - - If you're thinking about using ``approx``, then you might want to know how - it compares to other good ways of comparing floating-point numbers. All of - these algorithms are based on relative and absolute tolerances and should - agree for the most part, but they do have meaningful differences: - - - ``math.isclose(a, b, rel_tol=1e-9, abs_tol=0.0)``: True if the relative - tolerance is met w.r.t. either ``a`` or ``b`` or if the absolute - tolerance is met. Because the relative tolerance is calculated w.r.t. - both ``a`` and ``b``, this test is symmetric (i.e. neither ``a`` nor - ``b`` is a "reference value"). You have to specify an absolute tolerance - if you want to compare to ``0.0`` because there is no tolerance by - default. More information: :py:func:`math.isclose`. - - - ``numpy.isclose(a, b, rtol=1e-5, atol=1e-8)``: True if the difference - between ``a`` and ``b`` is less that the sum of the relative tolerance - w.r.t. ``b`` and the absolute tolerance. Because the relative tolerance - is only calculated w.r.t. ``b``, this test is asymmetric and you can - think of ``b`` as the reference value. Support for comparing sequences - is provided by :py:func:`numpy.allclose`. More information: - :std:doc:`numpy:reference/generated/numpy.isclose`. - - - ``unittest.TestCase.assertAlmostEqual(a, b)``: True if ``a`` and ``b`` - are within an absolute tolerance of ``1e-7``. No relative tolerance is - considered , so this function is not appropriate for very large or very - small numbers. Also, it's only available in subclasses of ``unittest.TestCase`` - and it's ugly because it doesn't follow PEP8. More information: - :py:meth:`unittest.TestCase.assertAlmostEqual`. - - - ``a == pytest.approx(b, rel=1e-6, abs=1e-12)``: True if the relative - tolerance is met w.r.t. ``b`` or if the absolute tolerance is met. - Because the relative tolerance is only calculated w.r.t. ``b``, this test - is asymmetric and you can think of ``b`` as the reference value. In the - special case that you explicitly specify an absolute tolerance but not a - relative tolerance, only the absolute tolerance is considered. - - .. note:: - - ``approx`` can handle numpy arrays, but we recommend the - specialised test helpers in :std:doc:`numpy:reference/routines.testing` - if you need support for comparisons, NaNs, or ULP-based tolerances. - - To match strings using regex, you can use - `Matches `_ - from the - `re_assert package `_. - - - .. note:: - - Unlike built-in equality, this function considers - booleans unequal to numeric zero or one. For example:: - - >>> 1 == approx(True) - False - - .. warning:: - - .. versionchanged:: 3.2 - - In order to avoid inconsistent behavior, :py:exc:`TypeError` is - raised for ``>``, ``>=``, ``<`` and ``<=`` comparisons. - The example below illustrates the problem:: - - assert approx(0.1) > 0.1 + 1e-10 # calls approx(0.1).__gt__(0.1 + 1e-10) - assert 0.1 + 1e-10 > approx(0.1) # calls approx(0.1).__lt__(0.1 + 1e-10) - - In the second example one expects ``approx(0.1).__le__(0.1 + 1e-10)`` - to be called. But instead, ``approx(0.1).__lt__(0.1 + 1e-10)`` is used to - comparison. This is because the call hierarchy of rich comparisons - follows a fixed behavior. More information: :py:meth:`object.__ge__` - - .. versionchanged:: 3.7.1 - ``approx`` raises ``TypeError`` when it encounters a dict value or - sequence element of non-numeric type. - - .. versionchanged:: 6.1.0 - ``approx`` falls back to strict equality for non-numeric types instead - of raising ``TypeError``. - """ - # Delegate the comparison to a class that knows how to deal with the type - # of the expected value (e.g. int, float, list, dict, numpy.array, etc). - # - # The primary responsibility of these classes is to implement ``__eq__()`` - # and ``__repr__()``. The former is used to actually check if some - # "actual" value is equivalent to the given expected value within the - # allowed tolerance. The latter is used to show the user the expected - # value and tolerance, in the case that a test failed. - # - # The actual logic for making approximate comparisons can be found in - # ApproxScalar, which is used to compare individual numbers. All of the - # other Approx classes eventually delegate to this class. The ApproxBase - # class provides some convenient methods and overloads, but isn't really - # essential. - - __tracebackhide__ = True - - if isinstance(expected, Decimal): - cls: type[ApproxBase] = ApproxDecimal - elif isinstance(expected, Mapping): - cls = ApproxMapping - elif _is_numpy_array(expected): - expected = _as_numpy_array(expected) - cls = ApproxNumpy - elif _is_sequence_like(expected): - cls = ApproxSequenceLike - elif isinstance(expected, Collection) and not isinstance(expected, str | bytes): - msg = f"pytest.approx() only supports ordered sequences, but got: {expected!r}" - raise TypeError(msg) - else: - cls = ApproxScalar - - return cls(expected, rel, abs, nan_ok) - - -def _is_sequence_like(expected: object) -> bool: - return ( - hasattr(expected, "__getitem__") - and isinstance(expected, Sized) - and not isinstance(expected, str | bytes) - ) - - -def _is_numpy_array(obj: object) -> bool: - """ - Return true if the given object is implicitly convertible to ndarray, - and numpy is already imported. - """ - return _as_numpy_array(obj) is not None - - -def _as_numpy_array(obj: object) -> ndarray | None: - """ - Return an ndarray if the given object is implicitly convertible to ndarray, - and numpy is already imported, otherwise None. - """ - np: Any = sys.modules.get("numpy") - if np is not None: - # avoid infinite recursion on numpy scalars, which have __array__ - if np.isscalar(obj): - return None - elif isinstance(obj, np.ndarray): - return obj - elif hasattr(obj, "__array__") or hasattr("obj", "__array_interface__"): - return np.asarray(obj) - return None diff --git a/.venv/lib/python3.12/site-packages/_pytest/raises.py b/.venv/lib/python3.12/site-packages/_pytest/raises.py deleted file mode 100644 index 7c246fd..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/raises.py +++ /dev/null @@ -1,1517 +0,0 @@ -from __future__ import annotations - -from abc import ABC -from abc import abstractmethod -import re -from re import Pattern -import sys -from textwrap import indent -from typing import Any -from typing import cast -from typing import final -from typing import Generic -from typing import get_args -from typing import get_origin -from typing import Literal -from typing import overload -from typing import TYPE_CHECKING -import warnings - -from _pytest._code import ExceptionInfo -from _pytest._code.code import stringify_exception -from _pytest.outcomes import fail -from _pytest.warning_types import PytestWarning - - -if TYPE_CHECKING: - from collections.abc import Callable - from collections.abc import Sequence - - # for some reason Sphinx does not play well with 'from types import TracebackType' - import types - from typing import TypeGuard - - from typing_extensions import ParamSpec - from typing_extensions import TypeVar - - P = ParamSpec("P") - - # this conditional definition is because we want to allow a TypeVar default - BaseExcT_co_default = TypeVar( - "BaseExcT_co_default", - bound=BaseException, - default=BaseException, - covariant=True, - ) - - # Use short name because it shows up in docs. - E = TypeVar("E", bound=BaseException, default=BaseException) -else: - from typing import TypeVar - - BaseExcT_co_default = TypeVar( - "BaseExcT_co_default", bound=BaseException, covariant=True - ) - -# RaisesGroup doesn't work with a default. -BaseExcT_co = TypeVar("BaseExcT_co", bound=BaseException, covariant=True) -BaseExcT_1 = TypeVar("BaseExcT_1", bound=BaseException) -BaseExcT_2 = TypeVar("BaseExcT_2", bound=BaseException) -ExcT_1 = TypeVar("ExcT_1", bound=Exception) -ExcT_2 = TypeVar("ExcT_2", bound=Exception) - -if sys.version_info < (3, 11): - from exceptiongroup import BaseExceptionGroup - from exceptiongroup import ExceptionGroup - - -# String patterns default to including the unicode flag. -_REGEX_NO_FLAGS = re.compile(r"").flags - - -# pytest.raises helper -@overload -def raises( - expected_exception: type[E] | tuple[type[E], ...], - *, - match: str | re.Pattern[str] | None = ..., - check: Callable[[E], bool] = ..., -) -> RaisesExc[E]: ... - - -@overload -def raises( - *, - match: str | re.Pattern[str], - # If exception_type is not provided, check() must do any typechecks itself. - check: Callable[[BaseException], bool] = ..., -) -> RaisesExc[BaseException]: ... - - -@overload -def raises(*, check: Callable[[BaseException], bool]) -> RaisesExc[BaseException]: ... - - -@overload -def raises( - expected_exception: type[E] | tuple[type[E], ...], - func: Callable[..., Any], - *args: Any, - **kwargs: Any, -) -> ExceptionInfo[E]: ... - - -def raises( - expected_exception: type[E] | tuple[type[E], ...] | None = None, - *args: Any, - **kwargs: Any, -) -> RaisesExc[BaseException] | ExceptionInfo[E]: - r"""Assert that a code block/function call raises an exception type, or one of its subclasses. - - :param expected_exception: - The expected exception type, or a tuple if one of multiple possible - exception types are expected. Note that subclasses of the passed exceptions - will also match. - - This is not a required parameter, you may opt to only use ``match`` and/or - ``check`` for verifying the raised exception. - - :kwparam str | re.Pattern[str] | None match: - If specified, a string containing a regular expression, - or a regular expression object, that is tested against the string - representation of the exception and its :pep:`678` `__notes__` - using :func:`re.search`. - - To match a literal string that may contain :ref:`special characters - `, the pattern can first be escaped with :func:`re.escape`. - - (This is only used when ``pytest.raises`` is used as a context manager, - and passed through to the function otherwise. - When using ``pytest.raises`` as a function, you can use: - ``pytest.raises(Exc, func, match="passed on").match("my pattern")``.) - - :kwparam Callable[[BaseException], bool] check: - - .. versionadded:: 8.4 - - If specified, a callable that will be called with the exception as a parameter - after checking the type and the match regex if specified. - If it returns ``True`` it will be considered a match, if not it will - be considered a failed match. - - - Use ``pytest.raises`` as a context manager, which will capture the exception of the given - type, or any of its subclasses:: - - >>> import pytest - >>> with pytest.raises(ZeroDivisionError): - ... 1/0 - - If the code block does not raise the expected exception (:class:`ZeroDivisionError` in the example - above), or no exception at all, the check will fail instead. - - You can also use the keyword argument ``match`` to assert that the - exception matches a text or regex:: - - >>> with pytest.raises(ValueError, match='must be 0 or None'): - ... raise ValueError("value must be 0 or None") - - >>> with pytest.raises(ValueError, match=r'must be \d+$'): - ... raise ValueError("value must be 42") - - The ``match`` argument searches the formatted exception string, which includes any - `PEP-678 `__ ``__notes__``: - - >>> with pytest.raises(ValueError, match=r"had a note added"): # doctest: +SKIP - ... e = ValueError("value must be 42") - ... e.add_note("had a note added") - ... raise e - - The ``check`` argument, if provided, must return True when passed the raised exception - for the match to be successful, otherwise an :exc:`AssertionError` is raised. - - >>> import errno - >>> with pytest.raises(OSError, check=lambda e: e.errno == errno.EACCES): - ... raise OSError(errno.EACCES, "no permission to view") - - The context manager produces an :class:`ExceptionInfo` object which can be used to inspect the - details of the captured exception:: - - >>> with pytest.raises(ValueError) as exc_info: - ... raise ValueError("value must be 42") - >>> assert exc_info.type is ValueError - >>> assert exc_info.value.args[0] == "value must be 42" - - .. warning:: - - Given that ``pytest.raises`` matches subclasses, be wary of using it to match :class:`Exception` like this:: - - # Careful, this will catch ANY exception raised. - with pytest.raises(Exception): - some_function() - - Because :class:`Exception` is the base class of almost all exceptions, it is easy for this to hide - real bugs, where the user wrote this expecting a specific exception, but some other exception is being - raised due to a bug introduced during a refactoring. - - Avoid using ``pytest.raises`` to catch :class:`Exception` unless certain that you really want to catch - **any** exception raised. - - .. note:: - - When using ``pytest.raises`` as a context manager, it's worthwhile to - note that normal context manager rules apply and that the exception - raised *must* be the final line in the scope of the context manager. - Lines of code after that, within the scope of the context manager will - not be executed. For example:: - - >>> value = 15 - >>> with pytest.raises(ValueError) as exc_info: - ... if value > 10: - ... raise ValueError("value must be <= 10") - ... assert exc_info.type is ValueError # This will not execute. - - Instead, the following approach must be taken (note the difference in - scope):: - - >>> with pytest.raises(ValueError) as exc_info: - ... if value > 10: - ... raise ValueError("value must be <= 10") - ... - >>> assert exc_info.type is ValueError - - **Expecting exception groups** - - When expecting exceptions wrapped in :exc:`BaseExceptionGroup` or - :exc:`ExceptionGroup`, you should instead use :class:`pytest.RaisesGroup`. - - **Using with** ``pytest.mark.parametrize`` - - When using :ref:`pytest.mark.parametrize ref` - it is possible to parametrize tests such that - some runs raise an exception and others do not. - - See :ref:`parametrizing_conditional_raising` for an example. - - .. seealso:: - - :ref:`assertraises` for more examples and detailed discussion. - - **Legacy form** - - It is possible to specify a callable by passing a to-be-called lambda:: - - >>> raises(ZeroDivisionError, lambda: 1/0) - - - or you can specify an arbitrary callable with arguments:: - - >>> def f(x): return 1/x - ... - >>> raises(ZeroDivisionError, f, 0) - - >>> raises(ZeroDivisionError, f, x=0) - - - The form above is fully supported but discouraged for new code because the - context manager form is regarded as more readable and less error-prone. - - .. note:: - Similar to caught exception objects in Python, explicitly clearing - local references to returned ``ExceptionInfo`` objects can - help the Python interpreter speed up its garbage collection. - - Clearing those references breaks a reference cycle - (``ExceptionInfo`` --> caught exception --> frame stack raising - the exception --> current frame stack --> local variables --> - ``ExceptionInfo``) which makes Python keep all objects referenced - from that cycle (including all local variables in the current - frame) alive until the next cyclic garbage collection run. - More detailed information can be found in the official Python - documentation for :ref:`the try statement `. - """ - __tracebackhide__ = True - - if not args: - if set(kwargs) - {"match", "check", "expected_exception"}: - msg = "Unexpected keyword arguments passed to pytest.raises: " - msg += ", ".join(sorted(kwargs)) - msg += "\nUse context-manager form instead?" - raise TypeError(msg) - - if expected_exception is None: - return RaisesExc(**kwargs) - return RaisesExc(expected_exception, **kwargs) - - if not expected_exception: - raise ValueError( - f"Expected an exception type or a tuple of exception types, but got `{expected_exception!r}`. " - f"Raising exceptions is already understood as failing the test, so you don't need " - f"any special code to say 'this should never raise an exception'." - ) - func = args[0] - if not callable(func): - raise TypeError(f"{func!r} object (type: {type(func)}) must be callable") - with RaisesExc(expected_exception) as excinfo: - func(*args[1:], **kwargs) - try: - return excinfo - finally: - del excinfo - - -# note: RaisesExc/RaisesGroup uses fail() internally, so this alias -# indicates (to [internal] plugins?) that `pytest.raises` will -# raise `_pytest.outcomes.Failed`, where -# `outcomes.Failed is outcomes.fail.Exception is raises.Exception` -# note: this is *not* the same as `_pytest.main.Failed` -# note: mypy does not recognize this attribute, and it's not possible -# to use a protocol/decorator like the others in outcomes due to -# https://github.com/python/mypy/issues/18715 -raises.Exception = fail.Exception # type: ignore[attr-defined] - - -def _match_pattern(match: Pattern[str]) -> str | Pattern[str]: - """Helper function to remove redundant `re.compile` calls when printing regex""" - return match.pattern if match.flags == _REGEX_NO_FLAGS else match - - -def repr_callable(fun: Callable[[BaseExcT_1], bool]) -> str: - """Get the repr of a ``check`` parameter. - - Split out so it can be monkeypatched (e.g. by hypothesis) - """ - return repr(fun) - - -def backquote(s: str) -> str: - return "`" + s + "`" - - -def _exception_type_name( - e: type[BaseException] | tuple[type[BaseException], ...], -) -> str: - if isinstance(e, type): - return e.__name__ - if len(e) == 1: - return e[0].__name__ - return "(" + ", ".join(ee.__name__ for ee in e) + ")" - - -def _check_raw_type( - expected_type: type[BaseException] | tuple[type[BaseException], ...] | None, - exception: BaseException, -) -> str | None: - if expected_type is None or expected_type == (): - return None - - if not isinstance( - exception, - expected_type, - ): - actual_type_str = backquote(_exception_type_name(type(exception)) + "()") - expected_type_str = backquote(_exception_type_name(expected_type)) - if ( - isinstance(exception, BaseExceptionGroup) - and isinstance(expected_type, type) - and not issubclass(expected_type, BaseExceptionGroup) - ): - return f"Unexpected nested {actual_type_str}, expected {expected_type_str}" - return f"{actual_type_str} is not an instance of {expected_type_str}" - return None - - -def is_fully_escaped(s: str) -> bool: - # we know we won't compile with re.VERBOSE, so whitespace doesn't need to be escaped - metacharacters = "{}()+.*?^$[]" - return not any( - c in metacharacters and (i == 0 or s[i - 1] != "\\") for (i, c) in enumerate(s) - ) - - -def unescape(s: str) -> str: - return re.sub(r"\\([{}()+-.*?^$\[\]\s\\])", r"\1", s) - - -# These classes conceptually differ from ExceptionInfo in that ExceptionInfo is tied, and -# constructed from, a particular exception - whereas these are constructed with expected -# exceptions, and later allow matching towards particular exceptions. -# But there's overlap in `ExceptionInfo.match` and `AbstractRaises._check_match`, as with -# `AbstractRaises.matches` and `ExceptionInfo.errisinstance`+`ExceptionInfo.group_contains`. -# The interaction between these classes should perhaps be improved. -class AbstractRaises(ABC, Generic[BaseExcT_co]): - """ABC with common functionality shared between RaisesExc and RaisesGroup""" - - def __init__( - self, - *, - match: str | Pattern[str] | None, - check: Callable[[BaseExcT_co], bool] | None, - ) -> None: - if isinstance(match, str): - # juggle error in order to avoid context to fail (necessary?) - re_error = None - try: - self.match: Pattern[str] | None = re.compile(match) - except re.error as e: - re_error = e - if re_error is not None: - fail(f"Invalid regex pattern provided to 'match': {re_error}") - if match == "": - warnings.warn( - PytestWarning( - "matching against an empty string will *always* pass. If you want " - "to check for an empty message you need to pass '^$'. If you don't " - "want to match you should pass `None` or leave out the parameter." - ), - stacklevel=2, - ) - else: - self.match = match - - # check if this is a fully escaped regex and has ^$ to match fully - # in which case we can do a proper diff on error - self.rawmatch: str | None = None - if isinstance(match, str) or ( - isinstance(match, Pattern) and match.flags == _REGEX_NO_FLAGS - ): - if isinstance(match, Pattern): - match = match.pattern - if ( - match - and match[0] == "^" - and match[-1] == "$" - and is_fully_escaped(match[1:-1]) - ): - self.rawmatch = unescape(match[1:-1]) - - self.check = check - self._fail_reason: str | None = None - - # used to suppress repeated printing of `repr(self.check)` - self._nested: bool = False - - # set in self._parse_exc - self.is_baseexception = False - - def _parse_exc( - self, exc: type[BaseExcT_1] | types.GenericAlias, expected: str - ) -> type[BaseExcT_1]: - if isinstance(exc, type) and issubclass(exc, BaseException): - if not issubclass(exc, Exception): - self.is_baseexception = True - return exc - # because RaisesGroup does not support variable number of exceptions there's - # still a use for RaisesExc(ExceptionGroup[Exception]). - origin_exc: type[BaseException] | None = get_origin(exc) - if origin_exc and issubclass(origin_exc, BaseExceptionGroup): - exc_type = get_args(exc)[0] - if ( - issubclass(origin_exc, ExceptionGroup) and exc_type in (Exception, Any) - ) or ( - issubclass(origin_exc, BaseExceptionGroup) - and exc_type in (BaseException, Any) - ): - if not issubclass(origin_exc, ExceptionGroup): - self.is_baseexception = True - return cast(type[BaseExcT_1], origin_exc) - else: - raise ValueError( - f"Only `ExceptionGroup[Exception]` or `BaseExceptionGroup[BaseException]` " - f"are accepted as generic types but got `{exc}`. " - f"As `raises` will catch all instances of the specified group regardless of the " - f"generic argument specific nested exceptions has to be checked " - f"with `RaisesGroup`." - ) - # unclear if the Type/ValueError distinction is even helpful here - msg = f"Expected {expected}, but got " - if isinstance(exc, type): # type: ignore[unreachable] - raise ValueError(msg + f"{exc.__name__!r}") - if isinstance(exc, BaseException): # type: ignore[unreachable] - raise TypeError(msg + f"an exception instance: {type(exc).__name__}") - raise TypeError(msg + repr(type(exc).__name__)) - - @property - def fail_reason(self) -> str | None: - """Set after a call to :meth:`matches` to give a human-readable reason for why the match failed. - When used as a context manager the string will be printed as the reason for the - test failing.""" - return self._fail_reason - - def _check_check( - self: AbstractRaises[BaseExcT_1], - exception: BaseExcT_1, - ) -> bool: - if self.check is None: - return True - - if self.check(exception): - return True - - check_repr = "" if self._nested else " " + repr_callable(self.check) - self._fail_reason = f"check{check_repr} did not return True" - return False - - # TODO: harmonize with ExceptionInfo.match - def _check_match(self, e: BaseException) -> bool: - if self.match is None or re.search( - self.match, - stringified_exception := stringify_exception( - e, include_subexception_msg=False - ), - ): - return True - - # if we're matching a group, make sure we're explicit to reduce confusion - # if they're trying to match an exception contained within the group - maybe_specify_type = ( - f" the `{_exception_type_name(type(e))}()`" - if isinstance(e, BaseExceptionGroup) - else "" - ) - if isinstance(self.rawmatch, str): - # TODO: it instructs to use `-v` to print leading text, but that doesn't work - # I also don't know if this is the proper entry point, or tool to use at all - from _pytest.assertion.util import _diff_text - from _pytest.assertion.util import dummy_highlighter - - diff = _diff_text(self.rawmatch, stringified_exception, dummy_highlighter) - self._fail_reason = ("\n" if diff[0][0] == "-" else "") + "\n".join(diff) - return False - - self._fail_reason = ( - f"Regex pattern did not match{maybe_specify_type}.\n" - f" Expected regex: {_match_pattern(self.match)!r}\n" - f" Actual message: {stringified_exception!r}" - ) - if _match_pattern(self.match) == stringified_exception: - self._fail_reason += "\n Did you mean to `re.escape()` the regex?" - return False - - @abstractmethod - def matches( - self: AbstractRaises[BaseExcT_1], exception: BaseException - ) -> TypeGuard[BaseExcT_1]: - """Check if an exception matches the requirements of this AbstractRaises. - If it fails, :meth:`AbstractRaises.fail_reason` should be set. - """ - - -@final -class RaisesExc(AbstractRaises[BaseExcT_co_default]): - """ - .. versionadded:: 8.4 - - - This is the class constructed when calling :func:`pytest.raises`, but may be used - directly as a helper class with :class:`RaisesGroup` when you want to specify - requirements on sub-exceptions. - - You don't need this if you only want to specify the type, since :class:`RaisesGroup` - accepts ``type[BaseException]``. - - :param type[BaseException] | tuple[type[BaseException]] | None expected_exception: - The expected type, or one of several possible types. - May be ``None`` in order to only make use of ``match`` and/or ``check`` - - The type is checked with :func:`isinstance`, and does not need to be an exact match. - If that is wanted you can use the ``check`` parameter. - - :kwparam str | Pattern[str] match: - A regex to match. - - :kwparam Callable[[BaseException], bool] check: - If specified, a callable that will be called with the exception as a parameter - after checking the type and the match regex if specified. - If it returns ``True`` it will be considered a match, if not it will - be considered a failed match. - - :meth:`RaisesExc.matches` can also be used standalone to check individual exceptions. - - Examples:: - - with RaisesGroup(RaisesExc(ValueError, match="string")) - ... - with RaisesGroup(RaisesExc(check=lambda x: x.args == (3, "hello"))): - ... - with RaisesGroup(RaisesExc(check=lambda x: type(x) is ValueError)): - ... - """ - - # Trio bundled hypothesis monkeypatching, we will probably instead assume that - # hypothesis will handle that in their pytest plugin by the time this is released. - # Alternatively we could add a version of get_pretty_function_description ourselves - # https://github.com/HypothesisWorks/hypothesis/blob/8ced2f59f5c7bea3344e35d2d53e1f8f8eb9fcd8/hypothesis-python/src/hypothesis/internal/reflection.py#L439 - - # At least one of the three parameters must be passed. - @overload - def __init__( - self, - expected_exception: ( - type[BaseExcT_co_default] | tuple[type[BaseExcT_co_default], ...] - ), - /, - *, - match: str | Pattern[str] | None = ..., - check: Callable[[BaseExcT_co_default], bool] | None = ..., - ) -> None: ... - - @overload - def __init__( - self: RaisesExc[BaseException], # Give E a value. - /, - *, - match: str | Pattern[str] | None, - # If exception_type is not provided, check() must do any typechecks itself. - check: Callable[[BaseException], bool] | None = ..., - ) -> None: ... - - @overload - def __init__(self, /, *, check: Callable[[BaseException], bool]) -> None: ... - - def __init__( - self, - expected_exception: ( - type[BaseExcT_co_default] | tuple[type[BaseExcT_co_default], ...] | None - ) = None, - /, - *, - match: str | Pattern[str] | None = None, - check: Callable[[BaseExcT_co_default], bool] | None = None, - ): - super().__init__(match=match, check=check) - if isinstance(expected_exception, tuple): - expected_exceptions = expected_exception - elif expected_exception is None: - expected_exceptions = () - else: - expected_exceptions = (expected_exception,) - - if (expected_exceptions == ()) and match is None and check is None: - raise ValueError("You must specify at least one parameter to match on.") - - self.expected_exceptions = tuple( - self._parse_exc(e, expected="a BaseException type") - for e in expected_exceptions - ) - - self._just_propagate = False - - def matches( - self, - exception: BaseException | None, - ) -> TypeGuard[BaseExcT_co_default]: - """Check if an exception matches the requirements of this :class:`RaisesExc`. - If it fails, :attr:`RaisesExc.fail_reason` will be set. - - Examples:: - - assert RaisesExc(ValueError).matches(my_exception): - # is equivalent to - assert isinstance(my_exception, ValueError) - - # this can be useful when checking e.g. the ``__cause__`` of an exception. - with pytest.raises(ValueError) as excinfo: - ... - assert RaisesExc(SyntaxError, match="foo").matches(excinfo.value.__cause__) - # above line is equivalent to - assert isinstance(excinfo.value.__cause__, SyntaxError) - assert re.search("foo", str(excinfo.value.__cause__) - - """ - self._just_propagate = False - if exception is None: - self._fail_reason = "exception is None" - return False - if not self._check_type(exception): - self._just_propagate = True - return False - - if not self._check_match(exception): - return False - - return self._check_check(exception) - - def __repr__(self) -> str: - parameters = [] - if self.expected_exceptions: - parameters.append(_exception_type_name(self.expected_exceptions)) - if self.match is not None: - # If no flags were specified, discard the redundant re.compile() here. - parameters.append( - f"match={_match_pattern(self.match)!r}", - ) - if self.check is not None: - parameters.append(f"check={repr_callable(self.check)}") - return f"RaisesExc({', '.join(parameters)})" - - def _check_type(self, exception: BaseException) -> TypeGuard[BaseExcT_co_default]: - self._fail_reason = _check_raw_type(self.expected_exceptions, exception) - return self._fail_reason is None - - def __enter__(self) -> ExceptionInfo[BaseExcT_co_default]: - self.excinfo: ExceptionInfo[BaseExcT_co_default] = ExceptionInfo.for_later() - return self.excinfo - - # TODO: move common code into superclass - def __exit__( - self, - exc_type: type[BaseException] | None, - exc_val: BaseException | None, - exc_tb: types.TracebackType | None, - ) -> bool: - __tracebackhide__ = True - if exc_type is None: - if not self.expected_exceptions: - fail("DID NOT RAISE any exception") - if len(self.expected_exceptions) > 1: - fail(f"DID NOT RAISE any of {self.expected_exceptions!r}") - - fail(f"DID NOT RAISE {self.expected_exceptions[0]!r}") - - assert self.excinfo is not None, ( - "Internal error - should have been constructed in __enter__" - ) - - if not self.matches(exc_val): - if self._just_propagate: - return False - raise AssertionError(self._fail_reason) - - # Cast to narrow the exception type now that it's verified.... - # even though the TypeGuard in self.matches should be narrowing - exc_info = cast( - "tuple[type[BaseExcT_co_default], BaseExcT_co_default, types.TracebackType]", - (exc_type, exc_val, exc_tb), - ) - self.excinfo.fill_unfilled(exc_info) - return True - - -@final -class RaisesGroup(AbstractRaises[BaseExceptionGroup[BaseExcT_co]]): - """ - .. versionadded:: 8.4 - - Contextmanager for checking for an expected :exc:`ExceptionGroup`. - This works similar to :func:`pytest.raises`, but allows for specifying the structure of an :exc:`ExceptionGroup`. - :meth:`ExceptionInfo.group_contains` also tries to handle exception groups, - but it is very bad at checking that you *didn't* get unexpected exceptions. - - The catching behaviour differs from :ref:`except* `, being much - stricter about the structure by default. - By using ``allow_unwrapped=True`` and ``flatten_subgroups=True`` you can match - :ref:`except* ` fully when expecting a single exception. - - :param args: - Any number of exception types, :class:`RaisesGroup` or :class:`RaisesExc` - to specify the exceptions contained in this exception. - All specified exceptions must be present in the raised group, *and no others*. - - If you expect a variable number of exceptions you need to use - :func:`pytest.raises(ExceptionGroup) ` and manually check - the contained exceptions. Consider making use of :meth:`RaisesExc.matches`. - - It does not care about the order of the exceptions, so - ``RaisesGroup(ValueError, TypeError)`` - is equivalent to - ``RaisesGroup(TypeError, ValueError)``. - :kwparam str | re.Pattern[str] | None match: - If specified, a string containing a regular expression, - or a regular expression object, that is tested against the string - representation of the exception group and its :pep:`678` `__notes__` - using :func:`re.search`. - - To match a literal string that may contain :ref:`special characters - `, the pattern can first be escaped with :func:`re.escape`. - - Note that " (5 subgroups)" will be stripped from the ``repr`` before matching. - :kwparam Callable[[E], bool] check: - If specified, a callable that will be called with the group as a parameter - after successfully matching the expected exceptions. If it returns ``True`` - it will be considered a match, if not it will be considered a failed match. - :kwparam bool allow_unwrapped: - If expecting a single exception or :class:`RaisesExc` it will match even - if the exception is not inside an exceptiongroup. - - Using this together with ``match``, ``check`` or expecting multiple exceptions - will raise an error. - :kwparam bool flatten_subgroups: - "flatten" any groups inside the raised exception group, extracting all exceptions - inside any nested groups, before matching. Without this it expects you to - fully specify the nesting structure by passing :class:`RaisesGroup` as expected - parameter. - - Examples:: - - with RaisesGroup(ValueError): - raise ExceptionGroup("", (ValueError(),)) - # match - with RaisesGroup( - ValueError, - ValueError, - RaisesExc(TypeError, match="^expected int$"), - match="^my group$", - ): - raise ExceptionGroup( - "my group", - [ - ValueError(), - TypeError("expected int"), - ValueError(), - ], - ) - # check - with RaisesGroup( - KeyboardInterrupt, - match="^hello$", - check=lambda x: isinstance(x.__cause__, ValueError), - ): - raise BaseExceptionGroup("hello", [KeyboardInterrupt()]) from ValueError - # nested groups - with RaisesGroup(RaisesGroup(ValueError)): - raise ExceptionGroup("", (ExceptionGroup("", (ValueError(),)),)) - - # flatten_subgroups - with RaisesGroup(ValueError, flatten_subgroups=True): - raise ExceptionGroup("", (ExceptionGroup("", (ValueError(),)),)) - - # allow_unwrapped - with RaisesGroup(ValueError, allow_unwrapped=True): - raise ValueError - - - :meth:`RaisesGroup.matches` can also be used directly to check a standalone exception group. - - - The matching algorithm is greedy, which means cases such as this may fail:: - - with RaisesGroup(ValueError, RaisesExc(ValueError, match="hello")): - raise ExceptionGroup("", (ValueError("hello"), ValueError("goodbye"))) - - even though it generally does not care about the order of the exceptions in the group. - To avoid the above you should specify the first :exc:`ValueError` with a :class:`RaisesExc` as well. - - .. note:: - When raised exceptions don't match the expected ones, you'll get a detailed error - message explaining why. This includes ``repr(check)`` if set, which in Python can be - overly verbose, showing memory locations etc etc. - - If installed and imported (in e.g. ``conftest.py``), the ``hypothesis`` library will - monkeypatch this output to provide shorter & more readable repr's. - """ - - # allow_unwrapped=True requires: singular exception, exception not being - # RaisesGroup instance, match is None, check is None - @overload - def __init__( - self, - expected_exception: type[BaseExcT_co] | RaisesExc[BaseExcT_co], - /, - *, - allow_unwrapped: Literal[True], - flatten_subgroups: bool = False, - ) -> None: ... - - # flatten_subgroups = True also requires no nested RaisesGroup - @overload - def __init__( - self, - expected_exception: type[BaseExcT_co] | RaisesExc[BaseExcT_co], - /, - *other_exceptions: type[BaseExcT_co] | RaisesExc[BaseExcT_co], - flatten_subgroups: Literal[True], - match: str | Pattern[str] | None = None, - check: Callable[[BaseExceptionGroup[BaseExcT_co]], bool] | None = None, - ) -> None: ... - - # simplify the typevars if possible (the following 3 are equivalent but go simpler->complicated) - # ... the first handles RaisesGroup[ValueError], the second RaisesGroup[ExceptionGroup[ValueError]], - # the third RaisesGroup[ValueError | ExceptionGroup[ValueError]]. - # ... otherwise, we will get results like RaisesGroup[ValueError | ExceptionGroup[Never]] (I think) - # (technically correct but misleading) - @overload - def __init__( - self: RaisesGroup[ExcT_1], - expected_exception: type[ExcT_1] | RaisesExc[ExcT_1], - /, - *other_exceptions: type[ExcT_1] | RaisesExc[ExcT_1], - match: str | Pattern[str] | None = None, - check: Callable[[ExceptionGroup[ExcT_1]], bool] | None = None, - ) -> None: ... - - @overload - def __init__( - self: RaisesGroup[ExceptionGroup[ExcT_2]], - expected_exception: RaisesGroup[ExcT_2], - /, - *other_exceptions: RaisesGroup[ExcT_2], - match: str | Pattern[str] | None = None, - check: Callable[[ExceptionGroup[ExceptionGroup[ExcT_2]]], bool] | None = None, - ) -> None: ... - - @overload - def __init__( - self: RaisesGroup[ExcT_1 | ExceptionGroup[ExcT_2]], - expected_exception: type[ExcT_1] | RaisesExc[ExcT_1] | RaisesGroup[ExcT_2], - /, - *other_exceptions: type[ExcT_1] | RaisesExc[ExcT_1] | RaisesGroup[ExcT_2], - match: str | Pattern[str] | None = None, - check: ( - Callable[[ExceptionGroup[ExcT_1 | ExceptionGroup[ExcT_2]]], bool] | None - ) = None, - ) -> None: ... - - # same as the above 3 but handling BaseException - @overload - def __init__( - self: RaisesGroup[BaseExcT_1], - expected_exception: type[BaseExcT_1] | RaisesExc[BaseExcT_1], - /, - *other_exceptions: type[BaseExcT_1] | RaisesExc[BaseExcT_1], - match: str | Pattern[str] | None = None, - check: Callable[[BaseExceptionGroup[BaseExcT_1]], bool] | None = None, - ) -> None: ... - - @overload - def __init__( - self: RaisesGroup[BaseExceptionGroup[BaseExcT_2]], - expected_exception: RaisesGroup[BaseExcT_2], - /, - *other_exceptions: RaisesGroup[BaseExcT_2], - match: str | Pattern[str] | None = None, - check: ( - Callable[[BaseExceptionGroup[BaseExceptionGroup[BaseExcT_2]]], bool] | None - ) = None, - ) -> None: ... - - @overload - def __init__( - self: RaisesGroup[BaseExcT_1 | BaseExceptionGroup[BaseExcT_2]], - expected_exception: type[BaseExcT_1] - | RaisesExc[BaseExcT_1] - | RaisesGroup[BaseExcT_2], - /, - *other_exceptions: type[BaseExcT_1] - | RaisesExc[BaseExcT_1] - | RaisesGroup[BaseExcT_2], - match: str | Pattern[str] | None = None, - check: ( - Callable[ - [BaseExceptionGroup[BaseExcT_1 | BaseExceptionGroup[BaseExcT_2]]], - bool, - ] - | None - ) = None, - ) -> None: ... - - def __init__( - self: RaisesGroup[ExcT_1 | BaseExcT_1 | BaseExceptionGroup[BaseExcT_2]], - expected_exception: type[BaseExcT_1] - | RaisesExc[BaseExcT_1] - | RaisesGroup[BaseExcT_2], - /, - *other_exceptions: type[BaseExcT_1] - | RaisesExc[BaseExcT_1] - | RaisesGroup[BaseExcT_2], - allow_unwrapped: bool = False, - flatten_subgroups: bool = False, - match: str | Pattern[str] | None = None, - check: ( - Callable[[BaseExceptionGroup[BaseExcT_1]], bool] - | Callable[[ExceptionGroup[ExcT_1]], bool] - | None - ) = None, - ): - # The type hint on the `self` and `check` parameters uses different formats - # that are *very* hard to reconcile while adhering to the overloads, so we cast - # it to avoid an error when passing it to super().__init__ - check = cast( - "Callable[[BaseExceptionGroup[ExcT_1|BaseExcT_1|BaseExceptionGroup[BaseExcT_2]]], bool]", - check, - ) - super().__init__(match=match, check=check) - self.allow_unwrapped = allow_unwrapped - self.flatten_subgroups: bool = flatten_subgroups - self.is_baseexception = False - - if allow_unwrapped and other_exceptions: - raise ValueError( - "You cannot specify multiple exceptions with `allow_unwrapped=True.`" - " If you want to match one of multiple possible exceptions you should" - " use a `RaisesExc`." - " E.g. `RaisesExc(check=lambda e: isinstance(e, (...)))`", - ) - if allow_unwrapped and isinstance(expected_exception, RaisesGroup): - raise ValueError( - "`allow_unwrapped=True` has no effect when expecting a `RaisesGroup`." - " You might want it in the expected `RaisesGroup`, or" - " `flatten_subgroups=True` if you don't care about the structure.", - ) - if allow_unwrapped and (match is not None or check is not None): - raise ValueError( - "`allow_unwrapped=True` bypasses the `match` and `check` parameters" - " if the exception is unwrapped. If you intended to match/check the" - " exception you should use a `RaisesExc` object. If you want to match/check" - " the exceptiongroup when the exception *is* wrapped you need to" - " do e.g. `if isinstance(exc.value, ExceptionGroup):" - " assert RaisesGroup(...).matches(exc.value)` afterwards.", - ) - - self.expected_exceptions: tuple[ - type[BaseExcT_co] | RaisesExc[BaseExcT_co] | RaisesGroup[BaseException], ... - ] = tuple( - self._parse_excgroup(e, "a BaseException type, RaisesExc, or RaisesGroup") - for e in ( - expected_exception, - *other_exceptions, - ) - ) - - def _parse_excgroup( - self, - exc: ( - type[BaseExcT_co] - | types.GenericAlias - | RaisesExc[BaseExcT_1] - | RaisesGroup[BaseExcT_2] - ), - expected: str, - ) -> type[BaseExcT_co] | RaisesExc[BaseExcT_1] | RaisesGroup[BaseExcT_2]: - # verify exception type and set `self.is_baseexception` - if isinstance(exc, RaisesGroup): - if self.flatten_subgroups: - raise ValueError( - "You cannot specify a nested structure inside a RaisesGroup with" - " `flatten_subgroups=True`. The parameter will flatten subgroups" - " in the raised exceptiongroup before matching, which would never" - " match a nested structure.", - ) - self.is_baseexception |= exc.is_baseexception - exc._nested = True - return exc - elif isinstance(exc, RaisesExc): - self.is_baseexception |= exc.is_baseexception - exc._nested = True - return exc - elif isinstance(exc, tuple): - raise TypeError( - f"Expected {expected}, but got {type(exc).__name__!r}.\n" - "RaisesGroup does not support tuples of exception types when expecting one of " - "several possible exception types like RaisesExc.\n" - "If you meant to expect a group with multiple exceptions, list them as separate arguments." - ) - else: - return super()._parse_exc(exc, expected) - - @overload - def __enter__( - self: RaisesGroup[ExcT_1], - ) -> ExceptionInfo[ExceptionGroup[ExcT_1]]: ... - @overload - def __enter__( - self: RaisesGroup[BaseExcT_1], - ) -> ExceptionInfo[BaseExceptionGroup[BaseExcT_1]]: ... - - def __enter__(self) -> ExceptionInfo[BaseExceptionGroup[BaseException]]: - self.excinfo: ExceptionInfo[BaseExceptionGroup[BaseExcT_co]] = ( - ExceptionInfo.for_later() - ) - return self.excinfo - - def __repr__(self) -> str: - reqs = [ - e.__name__ if isinstance(e, type) else repr(e) - for e in self.expected_exceptions - ] - if self.allow_unwrapped: - reqs.append(f"allow_unwrapped={self.allow_unwrapped}") - if self.flatten_subgroups: - reqs.append(f"flatten_subgroups={self.flatten_subgroups}") - if self.match is not None: - # If no flags were specified, discard the redundant re.compile() here. - reqs.append(f"match={_match_pattern(self.match)!r}") - if self.check is not None: - reqs.append(f"check={repr_callable(self.check)}") - return f"RaisesGroup({', '.join(reqs)})" - - def _unroll_exceptions( - self, - exceptions: Sequence[BaseException], - ) -> Sequence[BaseException]: - """Used if `flatten_subgroups=True`.""" - res: list[BaseException] = [] - for exc in exceptions: - if isinstance(exc, BaseExceptionGroup): - res.extend(self._unroll_exceptions(exc.exceptions)) - - else: - res.append(exc) - return res - - @overload - def matches( - self: RaisesGroup[ExcT_1], - exception: BaseException | None, - ) -> TypeGuard[ExceptionGroup[ExcT_1]]: ... - @overload - def matches( - self: RaisesGroup[BaseExcT_1], - exception: BaseException | None, - ) -> TypeGuard[BaseExceptionGroup[BaseExcT_1]]: ... - - def matches( - self, - exception: BaseException | None, - ) -> bool: - """Check if an exception matches the requirements of this RaisesGroup. - If it fails, `RaisesGroup.fail_reason` will be set. - - Example:: - - with pytest.raises(TypeError) as excinfo: - ... - assert RaisesGroup(ValueError).matches(excinfo.value.__cause__) - # the above line is equivalent to - myexc = excinfo.value.__cause - assert isinstance(myexc, BaseExceptionGroup) - assert len(myexc.exceptions) == 1 - assert isinstance(myexc.exceptions[0], ValueError) - """ - self._fail_reason = None - if exception is None: - self._fail_reason = "exception is None" - return False - if not isinstance(exception, BaseExceptionGroup): - # we opt to only print type of the exception here, as the repr would - # likely be quite long - not_group_msg = f"`{type(exception).__name__}()` is not an exception group" - if len(self.expected_exceptions) > 1: - self._fail_reason = not_group_msg - return False - # if we have 1 expected exception, check if it would work even if - # allow_unwrapped is not set - res = self._check_expected(self.expected_exceptions[0], exception) - if res is None and self.allow_unwrapped: - return True - - if res is None: - self._fail_reason = ( - f"{not_group_msg}, but would match with `allow_unwrapped=True`" - ) - elif self.allow_unwrapped: - self._fail_reason = res - else: - self._fail_reason = not_group_msg - return False - - actual_exceptions: Sequence[BaseException] = exception.exceptions - if self.flatten_subgroups: - actual_exceptions = self._unroll_exceptions(actual_exceptions) - - if not self._check_match(exception): - self._fail_reason = cast(str, self._fail_reason) - old_reason = self._fail_reason - if ( - len(actual_exceptions) == len(self.expected_exceptions) == 1 - and isinstance(expected := self.expected_exceptions[0], type) - and isinstance(actual := actual_exceptions[0], expected) - and self._check_match(actual) - ): - assert self.match is not None, "can't be None if _check_match failed" - assert self._fail_reason is old_reason is not None - self._fail_reason += ( - f"\n" - f" but matched the expected `{self._repr_expected(expected)}`.\n" - f" You might want " - f"`RaisesGroup(RaisesExc({expected.__name__}, match={_match_pattern(self.match)!r}))`" - ) - else: - self._fail_reason = old_reason - return False - - # do the full check on expected exceptions - if not self._check_exceptions( - exception, - actual_exceptions, - ): - self._fail_reason = cast(str, self._fail_reason) - assert self._fail_reason is not None - old_reason = self._fail_reason - # if we're not expecting a nested structure, and there is one, do a second - # pass where we try flattening it - if ( - not self.flatten_subgroups - and not any( - isinstance(e, RaisesGroup) for e in self.expected_exceptions - ) - and any(isinstance(e, BaseExceptionGroup) for e in actual_exceptions) - and self._check_exceptions( - exception, - self._unroll_exceptions(exception.exceptions), - ) - ): - # only indent if it's a single-line reason. In a multi-line there's already - # indented lines that this does not belong to. - indent = " " if "\n" not in self._fail_reason else "" - self._fail_reason = ( - old_reason - + f"\n{indent}Did you mean to use `flatten_subgroups=True`?" - ) - else: - self._fail_reason = old_reason - return False - - # Only run `self.check` once we know `exception` is of the correct type. - if not self._check_check(exception): - reason = ( - cast(str, self._fail_reason) + f" on the {type(exception).__name__}" - ) - if ( - len(actual_exceptions) == len(self.expected_exceptions) == 1 - and isinstance(expected := self.expected_exceptions[0], type) - # we explicitly break typing here :) - and self._check_check(actual_exceptions[0]) # type: ignore[arg-type] - ): - self._fail_reason = reason + ( - f", but did return True for the expected {self._repr_expected(expected)}." - f" You might want RaisesGroup(RaisesExc({expected.__name__}, check=<...>))" - ) - else: - self._fail_reason = reason - return False - - return True - - @staticmethod - def _check_expected( - expected_type: ( - type[BaseException] | RaisesExc[BaseException] | RaisesGroup[BaseException] - ), - exception: BaseException, - ) -> str | None: - """Helper method for `RaisesGroup.matches` and `RaisesGroup._check_exceptions` - to check one of potentially several expected exceptions.""" - if isinstance(expected_type, type): - return _check_raw_type(expected_type, exception) - res = expected_type.matches(exception) - if res: - return None - assert expected_type.fail_reason is not None - if expected_type.fail_reason.startswith("\n"): - return f"\n{expected_type!r}: {indent(expected_type.fail_reason, ' ')}" - return f"{expected_type!r}: {expected_type.fail_reason}" - - @staticmethod - def _repr_expected(e: type[BaseException] | AbstractRaises[BaseException]) -> str: - """Get the repr of an expected type/RaisesExc/RaisesGroup, but we only want - the name if it's a type""" - if isinstance(e, type): - return _exception_type_name(e) - return repr(e) - - @overload - def _check_exceptions( - self: RaisesGroup[ExcT_1], - _exception: Exception, - actual_exceptions: Sequence[Exception], - ) -> TypeGuard[ExceptionGroup[ExcT_1]]: ... - @overload - def _check_exceptions( - self: RaisesGroup[BaseExcT_1], - _exception: BaseException, - actual_exceptions: Sequence[BaseException], - ) -> TypeGuard[BaseExceptionGroup[BaseExcT_1]]: ... - - def _check_exceptions( - self, - _exception: BaseException, - actual_exceptions: Sequence[BaseException], - ) -> bool: - """Helper method for RaisesGroup.matches that attempts to pair up expected and actual exceptions""" - # The _exception parameter is not used, but necessary for the TypeGuard - - # full table with all results - results = ResultHolder(self.expected_exceptions, actual_exceptions) - - # (indexes of) raised exceptions that haven't (yet) found an expected - remaining_actual = list(range(len(actual_exceptions))) - # (indexes of) expected exceptions that haven't found a matching raised - failed_expected: list[int] = [] - # successful greedy matches - matches: dict[int, int] = {} - - # loop over expected exceptions first to get a more predictable result - for i_exp, expected in enumerate(self.expected_exceptions): - for i_rem in remaining_actual: - res = self._check_expected(expected, actual_exceptions[i_rem]) - results.set_result(i_exp, i_rem, res) - if res is None: - remaining_actual.remove(i_rem) - matches[i_exp] = i_rem - break - else: - failed_expected.append(i_exp) - - # All exceptions matched up successfully - if not remaining_actual and not failed_expected: - return True - - # in case of a single expected and single raised we simplify the output - if 1 == len(actual_exceptions) == len(self.expected_exceptions): - assert not matches - self._fail_reason = res - return False - - # The test case is failing, so we can do a slow and exhaustive check to find - # duplicate matches etc that will be helpful in debugging - for i_exp, expected in enumerate(self.expected_exceptions): - for i_actual, actual in enumerate(actual_exceptions): - if results.has_result(i_exp, i_actual): - continue - results.set_result( - i_exp, i_actual, self._check_expected(expected, actual) - ) - - successful_str = ( - f"{len(matches)} matched exception{'s' if len(matches) > 1 else ''}. " - if matches - else "" - ) - - # all expected were found - if not failed_expected and results.no_match_for_actual(remaining_actual): - self._fail_reason = ( - f"{successful_str}Unexpected exception(s):" - f" {[actual_exceptions[i] for i in remaining_actual]!r}" - ) - return False - # all raised exceptions were expected - if not remaining_actual and results.no_match_for_expected(failed_expected): - no_match_for_str = ", ".join( - self._repr_expected(self.expected_exceptions[i]) - for i in failed_expected - ) - self._fail_reason = f"{successful_str}Too few exceptions raised, found no match for: [{no_match_for_str}]" - return False - - # if there's only one remaining and one failed, and the unmatched didn't match anything else, - # we elect to only print why the remaining and the failed didn't match. - if ( - 1 == len(remaining_actual) == len(failed_expected) - and results.no_match_for_actual(remaining_actual) - and results.no_match_for_expected(failed_expected) - ): - self._fail_reason = f"{successful_str}{results.get_result(failed_expected[0], remaining_actual[0])}" - return False - - # there's both expected and raised exceptions without matches - s = "" - if matches: - s += f"\n{successful_str}" - indent_1 = " " * 2 - indent_2 = " " * 4 - - if not remaining_actual: - s += "\nToo few exceptions raised!" - elif not failed_expected: - s += "\nUnexpected exception(s)!" - - if failed_expected: - s += "\nThe following expected exceptions did not find a match:" - rev_matches = {v: k for k, v in matches.items()} - for i_failed in failed_expected: - s += ( - f"\n{indent_1}{self._repr_expected(self.expected_exceptions[i_failed])}" - ) - for i_actual, actual in enumerate(actual_exceptions): - if results.get_result(i_exp, i_actual) is None: - # we print full repr of match target - s += ( - f"\n{indent_2}It matches {backquote(repr(actual))} which was paired with " - + backquote( - self._repr_expected( - self.expected_exceptions[rev_matches[i_actual]] - ) - ) - ) - - if remaining_actual: - s += "\nThe following raised exceptions did not find a match" - for i_actual in remaining_actual: - s += f"\n{indent_1}{actual_exceptions[i_actual]!r}:" - for i_exp, expected in enumerate(self.expected_exceptions): - res = results.get_result(i_exp, i_actual) - if i_exp in failed_expected: - assert res is not None - if res[0] != "\n": - s += "\n" - s += indent(res, indent_2) - if res is None: - # we print full repr of match target - s += ( - f"\n{indent_2}It matches {backquote(self._repr_expected(expected))} " - f"which was paired with {backquote(repr(actual_exceptions[matches[i_exp]]))}" - ) - - if len(self.expected_exceptions) == len(actual_exceptions) and possible_match( - results - ): - s += ( - "\nThere exist a possible match when attempting an exhaustive check," - " but RaisesGroup uses a greedy algorithm. " - "Please make your expected exceptions more stringent with `RaisesExc` etc" - " so the greedy algorithm can function." - ) - self._fail_reason = s - return False - - def __exit__( - self, - exc_type: type[BaseException] | None, - exc_val: BaseException | None, - exc_tb: types.TracebackType | None, - ) -> bool: - __tracebackhide__ = True - if exc_type is None: - fail(f"DID NOT RAISE any exception, expected `{self.expected_type()}`") - - assert self.excinfo is not None, ( - "Internal error - should have been constructed in __enter__" - ) - - # group_str is the only thing that differs between RaisesExc and RaisesGroup... - # I might just scrap it? Or make it part of fail_reason - group_str = ( - "(group)" - if self.allow_unwrapped and not issubclass(exc_type, BaseExceptionGroup) - else "group" - ) - - if not self.matches(exc_val): - fail(f"Raised exception {group_str} did not match: {self._fail_reason}") - - # Cast to narrow the exception type now that it's verified.... - # even though the TypeGuard in self.matches should be narrowing - exc_info = cast( - "tuple[type[BaseExceptionGroup[BaseExcT_co]], BaseExceptionGroup[BaseExcT_co], types.TracebackType]", - (exc_type, exc_val, exc_tb), - ) - self.excinfo.fill_unfilled(exc_info) - return True - - def expected_type(self) -> str: - subexcs = [] - for e in self.expected_exceptions: - if isinstance(e, RaisesExc): - subexcs.append(repr(e)) - elif isinstance(e, RaisesGroup): - subexcs.append(e.expected_type()) - elif isinstance(e, type): - subexcs.append(e.__name__) - else: # pragma: no cover - raise AssertionError("unknown type") - group_type = "Base" if self.is_baseexception else "" - return f"{group_type}ExceptionGroup({', '.join(subexcs)})" - - -@final -class NotChecked: - """Singleton for unchecked values in ResultHolder""" - - -class ResultHolder: - """Container for results of checking exceptions. - Used in RaisesGroup._check_exceptions and possible_match. - """ - - def __init__( - self, - expected_exceptions: tuple[ - type[BaseException] | AbstractRaises[BaseException], ... - ], - actual_exceptions: Sequence[BaseException], - ) -> None: - self.results: list[list[str | type[NotChecked] | None]] = [ - [NotChecked for _ in expected_exceptions] for _ in actual_exceptions - ] - - def set_result(self, expected: int, actual: int, result: str | None) -> None: - self.results[actual][expected] = result - - def get_result(self, expected: int, actual: int) -> str | None: - res = self.results[actual][expected] - assert res is not NotChecked - # mypy doesn't support identity checking against anything but None - return res # type: ignore[return-value] - - def has_result(self, expected: int, actual: int) -> bool: - return self.results[actual][expected] is not NotChecked - - def no_match_for_expected(self, expected: list[int]) -> bool: - for i in expected: - for actual_results in self.results: - assert actual_results[i] is not NotChecked - if actual_results[i] is None: - return False - return True - - def no_match_for_actual(self, actual: list[int]) -> bool: - for i in actual: - for res in self.results[i]: - assert res is not NotChecked - if res is None: - return False - return True - - -def possible_match(results: ResultHolder, used: set[int] | None = None) -> bool: - if used is None: - used = set() - curr_row = len(used) - if curr_row == len(results.results): - return True - return any( - val is None and i not in used and possible_match(results, used | {i}) - for (i, val) in enumerate(results.results[curr_row]) - ) diff --git a/.venv/lib/python3.12/site-packages/_pytest/recwarn.py b/.venv/lib/python3.12/site-packages/_pytest/recwarn.py deleted file mode 100644 index e3db717..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/recwarn.py +++ /dev/null @@ -1,367 +0,0 @@ -# mypy: allow-untyped-defs -"""Record warnings during test function execution.""" - -from __future__ import annotations - -from collections.abc import Callable -from collections.abc import Generator -from collections.abc import Iterator -from pprint import pformat -import re -from types import TracebackType -from typing import Any -from typing import final -from typing import overload -from typing import TYPE_CHECKING -from typing import TypeVar - - -if TYPE_CHECKING: - from typing_extensions import Self - -import warnings - -from _pytest.deprecated import check_ispytest -from _pytest.fixtures import fixture -from _pytest.outcomes import Exit -from _pytest.outcomes import fail - - -T = TypeVar("T") - - -@fixture -def recwarn() -> Generator[WarningsRecorder]: - """Return a :class:`WarningsRecorder` instance that records all warnings emitted by test functions. - - See :ref:`warnings` for information on warning categories. - """ - wrec = WarningsRecorder(_ispytest=True) - with wrec: - warnings.simplefilter("default") - yield wrec - - -@overload -def deprecated_call( - *, match: str | re.Pattern[str] | None = ... -) -> WarningsRecorder: ... - - -@overload -def deprecated_call(func: Callable[..., T], *args: Any, **kwargs: Any) -> T: ... - - -def deprecated_call( - func: Callable[..., Any] | None = None, *args: Any, **kwargs: Any -) -> WarningsRecorder | Any: - """Assert that code produces a ``DeprecationWarning`` or ``PendingDeprecationWarning`` or ``FutureWarning``. - - This function can be used as a context manager:: - - >>> import warnings - >>> def api_call_v2(): - ... warnings.warn('use v3 of this api', DeprecationWarning) - ... return 200 - - >>> import pytest - >>> with pytest.deprecated_call(): - ... assert api_call_v2() == 200 - - It can also be used by passing a function and ``*args`` and ``**kwargs``, - in which case it will ensure calling ``func(*args, **kwargs)`` produces one of - the warnings types above. The return value is the return value of the function. - - In the context manager form you may use the keyword argument ``match`` to assert - that the warning matches a text or regex. - - The context manager produces a list of :class:`warnings.WarningMessage` objects, - one for each warning raised. - """ - __tracebackhide__ = True - if func is not None: - args = (func, *args) - return warns( - (DeprecationWarning, PendingDeprecationWarning, FutureWarning), *args, **kwargs - ) - - -@overload -def warns( - expected_warning: type[Warning] | tuple[type[Warning], ...] = ..., - *, - match: str | re.Pattern[str] | None = ..., -) -> WarningsChecker: ... - - -@overload -def warns( - expected_warning: type[Warning] | tuple[type[Warning], ...], - func: Callable[..., T], - *args: Any, - **kwargs: Any, -) -> T: ... - - -def warns( - expected_warning: type[Warning] | tuple[type[Warning], ...] = Warning, - *args: Any, - match: str | re.Pattern[str] | None = None, - **kwargs: Any, -) -> WarningsChecker | Any: - r"""Assert that code raises a particular class of warning. - - Specifically, the parameter ``expected_warning`` can be a warning class or tuple - of warning classes, and the code inside the ``with`` block must issue at least one - warning of that class or classes. - - This helper produces a list of :class:`warnings.WarningMessage` objects, one for - each warning emitted (regardless of whether it is an ``expected_warning`` or not). - Since pytest 8.0, unmatched warnings are also re-emitted when the context closes. - - This function can be used as a context manager:: - - >>> import pytest - >>> with pytest.warns(RuntimeWarning): - ... warnings.warn("my warning", RuntimeWarning) - - In the context manager form you may use the keyword argument ``match`` to assert - that the warning matches a text or regex:: - - >>> with pytest.warns(UserWarning, match='must be 0 or None'): - ... warnings.warn("value must be 0 or None", UserWarning) - - >>> with pytest.warns(UserWarning, match=r'must be \d+$'): - ... warnings.warn("value must be 42", UserWarning) - - >>> with pytest.warns(UserWarning): # catch re-emitted warning - ... with pytest.warns(UserWarning, match=r'must be \d+$'): - ... warnings.warn("this is not here", UserWarning) - Traceback (most recent call last): - ... - Failed: DID NOT WARN. No warnings of type ...UserWarning... were emitted... - - **Using with** ``pytest.mark.parametrize`` - - When using :ref:`pytest.mark.parametrize ref` it is possible to parametrize tests - such that some runs raise a warning and others do not. - - This could be achieved in the same way as with exceptions, see - :ref:`parametrizing_conditional_raising` for an example. - - """ - __tracebackhide__ = True - if not args: - if kwargs: - argnames = ", ".join(sorted(kwargs)) - raise TypeError( - f"Unexpected keyword arguments passed to pytest.warns: {argnames}" - "\nUse context-manager form instead?" - ) - return WarningsChecker(expected_warning, match_expr=match, _ispytest=True) - else: - func = args[0] - if not callable(func): - raise TypeError(f"{func!r} object (type: {type(func)}) must be callable") - with WarningsChecker(expected_warning, _ispytest=True): - return func(*args[1:], **kwargs) - - -class WarningsRecorder(warnings.catch_warnings): - """A context manager to record raised warnings. - - Each recorded warning is an instance of :class:`warnings.WarningMessage`. - - Adapted from `warnings.catch_warnings`. - - .. note:: - ``DeprecationWarning`` and ``PendingDeprecationWarning`` are treated - differently; see :ref:`ensuring_function_triggers`. - - """ - - def __init__(self, *, _ispytest: bool = False) -> None: - check_ispytest(_ispytest) - super().__init__(record=True) - self._entered = False - self._list: list[warnings.WarningMessage] = [] - - @property - def list(self) -> list[warnings.WarningMessage]: - """The list of recorded warnings.""" - return self._list - - def __getitem__(self, i: int) -> warnings.WarningMessage: - """Get a recorded warning by index.""" - return self._list[i] - - def __iter__(self) -> Iterator[warnings.WarningMessage]: - """Iterate through the recorded warnings.""" - return iter(self._list) - - def __len__(self) -> int: - """The number of recorded warnings.""" - return len(self._list) - - def pop(self, cls: type[Warning] = Warning) -> warnings.WarningMessage: - """Pop the first recorded warning which is an instance of ``cls``, - but not an instance of a child class of any other match. - Raises ``AssertionError`` if there is no match. - """ - best_idx: int | None = None - for i, w in enumerate(self._list): - if w.category == cls: - return self._list.pop(i) # exact match, stop looking - if issubclass(w.category, cls) and ( - best_idx is None - or not issubclass(w.category, self._list[best_idx].category) - ): - best_idx = i - if best_idx is not None: - return self._list.pop(best_idx) - __tracebackhide__ = True - raise AssertionError(f"{cls!r} not found in warning list") - - def clear(self) -> None: - """Clear the list of recorded warnings.""" - self._list[:] = [] - - # Type ignored because we basically want the `catch_warnings` generic type - # parameter to be ourselves but that is not possible(?). - def __enter__(self) -> Self: # type: ignore[override] - if self._entered: - __tracebackhide__ = True - raise RuntimeError(f"Cannot enter {self!r} twice") - _list = super().__enter__() - # record=True means it's None. - assert _list is not None - self._list = _list - warnings.simplefilter("always") - return self - - def __exit__( - self, - exc_type: type[BaseException] | None, - exc_val: BaseException | None, - exc_tb: TracebackType | None, - ) -> None: - if not self._entered: - __tracebackhide__ = True - raise RuntimeError(f"Cannot exit {self!r} without entering first") - - super().__exit__(exc_type, exc_val, exc_tb) - - # Built-in catch_warnings does not reset entered state so we do it - # manually here for this context manager to become reusable. - self._entered = False - - -@final -class WarningsChecker(WarningsRecorder): - def __init__( - self, - expected_warning: type[Warning] | tuple[type[Warning], ...] = Warning, - match_expr: str | re.Pattern[str] | None = None, - *, - _ispytest: bool = False, - ) -> None: - check_ispytest(_ispytest) - super().__init__(_ispytest=True) - - msg = "exceptions must be derived from Warning, not %s" - if isinstance(expected_warning, tuple): - for exc in expected_warning: - if not issubclass(exc, Warning): - raise TypeError(msg % type(exc)) - expected_warning_tup = expected_warning - elif isinstance(expected_warning, type) and issubclass( - expected_warning, Warning - ): - expected_warning_tup = (expected_warning,) - else: - raise TypeError(msg % type(expected_warning)) - - self.expected_warning = expected_warning_tup - self.match_expr = match_expr - - def matches(self, warning: warnings.WarningMessage) -> bool: - assert self.expected_warning is not None - return issubclass(warning.category, self.expected_warning) and bool( - self.match_expr is None or re.search(self.match_expr, str(warning.message)) - ) - - def __exit__( - self, - exc_type: type[BaseException] | None, - exc_val: BaseException | None, - exc_tb: TracebackType | None, - ) -> None: - super().__exit__(exc_type, exc_val, exc_tb) - - __tracebackhide__ = True - - # BaseExceptions like pytest.{skip,fail,xfail,exit} or Ctrl-C within - # pytest.warns should *not* trigger "DID NOT WARN" and get suppressed - # when the warning doesn't happen. Control-flow exceptions should always - # propagate. - if exc_val is not None and ( - not isinstance(exc_val, Exception) - # Exit is an Exception, not a BaseException, for some reason. - or isinstance(exc_val, Exit) - ): - return - - def found_str() -> str: - return pformat([record.message for record in self], indent=2) - - try: - if not any(issubclass(w.category, self.expected_warning) for w in self): - fail( - f"DID NOT WARN. No warnings of type {self.expected_warning} were emitted.\n" - f" Emitted warnings: {found_str()}." - ) - elif not any(self.matches(w) for w in self): - fail( - f"DID NOT WARN. No warnings of type {self.expected_warning} matching the regex were emitted.\n" - f" Regex: {self.match_expr}\n" - f" Emitted warnings: {found_str()}." - ) - finally: - # Whether or not any warnings matched, we want to re-emit all unmatched warnings. - for w in self: - if not self.matches(w): - warnings.warn_explicit( - message=w.message, - category=w.category, - filename=w.filename, - lineno=w.lineno, - module=w.__module__, - source=w.source, - ) - - # Currently in Python it is possible to pass other types than an - # `str` message when creating `Warning` instances, however this - # causes an exception when :func:`warnings.filterwarnings` is used - # to filter those warnings. See - # https://github.com/python/cpython/issues/103577 for a discussion. - # While this can be considered a bug in CPython, we put guards in - # pytest as the error message produced without this check in place - # is confusing (#10865). - for w in self: - if type(w.message) is not UserWarning: - # If the warning was of an incorrect type then `warnings.warn()` - # creates a UserWarning. Any other warning must have been specified - # explicitly. - continue - if not w.message.args: - # UserWarning() without arguments must have been specified explicitly. - continue - msg = w.message.args[0] - if isinstance(msg, str): - continue - # It's possible that UserWarning was explicitly specified, and - # its first argument was not a string. But that case can't be - # distinguished from an invalid type. - raise TypeError( - f"Warning must be str or Warning, got {msg!r} (type {type(msg).__name__})" - ) diff --git a/.venv/lib/python3.12/site-packages/_pytest/reports.py b/.venv/lib/python3.12/site-packages/_pytest/reports.py deleted file mode 100644 index 011a69d..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/reports.py +++ /dev/null @@ -1,694 +0,0 @@ -# mypy: allow-untyped-defs -from __future__ import annotations - -from collections.abc import Iterable -from collections.abc import Iterator -from collections.abc import Mapping -from collections.abc import Sequence -import dataclasses -from io import StringIO -import os -from pprint import pprint -import sys -from typing import Any -from typing import cast -from typing import final -from typing import Literal -from typing import NoReturn -from typing import TYPE_CHECKING - -from _pytest._code.code import ExceptionChainRepr -from _pytest._code.code import ExceptionInfo -from _pytest._code.code import ExceptionRepr -from _pytest._code.code import ReprEntry -from _pytest._code.code import ReprEntryNative -from _pytest._code.code import ReprExceptionInfo -from _pytest._code.code import ReprFileLocation -from _pytest._code.code import ReprFuncArgs -from _pytest._code.code import ReprLocals -from _pytest._code.code import ReprTraceback -from _pytest._code.code import TerminalRepr -from _pytest._io import TerminalWriter -from _pytest.config import Config -from _pytest.nodes import Collector -from _pytest.nodes import Item -from _pytest.outcomes import fail -from _pytest.outcomes import skip - - -if sys.version_info < (3, 11): - from exceptiongroup import BaseExceptionGroup - - -if TYPE_CHECKING: - from typing_extensions import Self - - from _pytest.runner import CallInfo - - -def getworkerinfoline(node): - try: - return node._workerinfocache - except AttributeError: - d = node.workerinfo - ver = "{}.{}.{}".format(*d["version_info"][:3]) - node._workerinfocache = s = "[{}] {} -- Python {} {}".format( - d["id"], d["sysplatform"], ver, d["executable"] - ) - return s - - -class BaseReport: - when: str | None - location: tuple[str, int | None, str] | None - longrepr: ( - None | ExceptionInfo[BaseException] | tuple[str, int, str] | str | TerminalRepr - ) - sections: list[tuple[str, str]] - nodeid: str - outcome: Literal["passed", "failed", "skipped"] - - def __init__(self, **kw: Any) -> None: - self.__dict__.update(kw) - - if TYPE_CHECKING: - # Can have arbitrary fields given to __init__(). - def __getattr__(self, key: str) -> Any: ... - - def toterminal(self, out: TerminalWriter) -> None: - if hasattr(self, "node"): - worker_info = getworkerinfoline(self.node) - if worker_info: - out.line(worker_info) - - longrepr = self.longrepr - if longrepr is None: - return - - if hasattr(longrepr, "toterminal"): - longrepr_terminal = cast(TerminalRepr, longrepr) - longrepr_terminal.toterminal(out) - else: - try: - s = str(longrepr) - except UnicodeEncodeError: - s = "" - out.line(s) - - def get_sections(self, prefix: str) -> Iterator[tuple[str, str]]: - for name, content in self.sections: - if name.startswith(prefix): - yield prefix, content - - @property - def longreprtext(self) -> str: - """Read-only property that returns the full string representation of - ``longrepr``. - - .. versionadded:: 3.0 - """ - file = StringIO() - tw = TerminalWriter(file) - tw.hasmarkup = False - self.toterminal(tw) - exc = file.getvalue() - return exc.strip() - - @property - def caplog(self) -> str: - """Return captured log lines, if log capturing is enabled. - - .. versionadded:: 3.5 - """ - return "\n".join( - content for (prefix, content) in self.get_sections("Captured log") - ) - - @property - def capstdout(self) -> str: - """Return captured text from stdout, if capturing is enabled. - - .. versionadded:: 3.0 - """ - return "".join( - content for (prefix, content) in self.get_sections("Captured stdout") - ) - - @property - def capstderr(self) -> str: - """Return captured text from stderr, if capturing is enabled. - - .. versionadded:: 3.0 - """ - return "".join( - content for (prefix, content) in self.get_sections("Captured stderr") - ) - - @property - def passed(self) -> bool: - """Whether the outcome is passed.""" - return self.outcome == "passed" - - @property - def failed(self) -> bool: - """Whether the outcome is failed.""" - return self.outcome == "failed" - - @property - def skipped(self) -> bool: - """Whether the outcome is skipped.""" - return self.outcome == "skipped" - - @property - def fspath(self) -> str: - """The path portion of the reported node, as a string.""" - return self.nodeid.split("::")[0] - - @property - def count_towards_summary(self) -> bool: - """**Experimental** Whether this report should be counted towards the - totals shown at the end of the test session: "1 passed, 1 failure, etc". - - .. note:: - - This function is considered **experimental**, so beware that it is subject to changes - even in patch releases. - """ - return True - - @property - def head_line(self) -> str | None: - """**Experimental** The head line shown with longrepr output for this - report, more commonly during traceback representation during - failures:: - - ________ Test.foo ________ - - - In the example above, the head_line is "Test.foo". - - .. note:: - - This function is considered **experimental**, so beware that it is subject to changes - even in patch releases. - """ - if self.location is not None: - _fspath, _lineno, domain = self.location - return domain - return None - - def _get_verbose_word_with_markup( - self, config: Config, default_markup: Mapping[str, bool] - ) -> tuple[str, Mapping[str, bool]]: - _category, _short, verbose = config.hook.pytest_report_teststatus( - report=self, config=config - ) - - if isinstance(verbose, str): - return verbose, default_markup - - if isinstance(verbose, Sequence) and len(verbose) == 2: - word, markup = verbose - if isinstance(word, str) and isinstance(markup, Mapping): - return word, markup - - fail( # pragma: no cover - "pytest_report_teststatus() hook (from a plugin) returned " - f"an invalid verbose value: {verbose!r}.\nExpected either a string " - "or a tuple of (word, markup)." - ) - - def _to_json(self) -> dict[str, Any]: - """Return the contents of this report as a dict of builtin entries, - suitable for serialization. - - This was originally the serialize_report() function from xdist (ca03269). - - Experimental method. - """ - return _report_to_json(self) - - @classmethod - def _from_json(cls, reportdict: dict[str, object]) -> Self: - """Create either a TestReport or CollectReport, depending on the calling class. - - It is the callers responsibility to know which class to pass here. - - This was originally the serialize_report() function from xdist (ca03269). - - Experimental method. - """ - kwargs = _report_kwargs_from_json(reportdict) - return cls(**kwargs) - - -def _report_unserialization_failure( - type_name: str, report_class: type[BaseReport], reportdict -) -> NoReturn: - url = "https://github.com/pytest-dev/pytest/issues" - stream = StringIO() - pprint("-" * 100, stream=stream) - pprint(f"INTERNALERROR: Unknown entry type returned: {type_name}", stream=stream) - pprint(f"report_name: {report_class}", stream=stream) - pprint(reportdict, stream=stream) - pprint(f"Please report this bug at {url}", stream=stream) - pprint("-" * 100, stream=stream) - raise RuntimeError(stream.getvalue()) - - -def _format_failed_longrepr( - item: Item, call: CallInfo[None], excinfo: ExceptionInfo[BaseException] -): - if call.when == "call": - longrepr = item.repr_failure(excinfo) - else: - # Exception in setup or teardown. - longrepr = item._repr_failure_py( - excinfo, style=item.config.getoption("tbstyle", "auto") - ) - return longrepr - - -def _format_exception_group_all_skipped_longrepr( - item: Item, - excinfo: ExceptionInfo[BaseExceptionGroup[BaseException | BaseExceptionGroup]], -) -> tuple[str, int, str]: - r = excinfo._getreprcrash() - assert r is not None, ( - "There should always be a traceback entry for skipping a test." - ) - if all( - getattr(skip, "_use_item_location", False) for skip in excinfo.value.exceptions - ): - path, line = item.reportinfo()[:2] - assert line is not None - loc = (os.fspath(path), line + 1) - default_msg = "skipped" - else: - loc = (str(r.path), r.lineno) - default_msg = r.message - - # Get all unique skip messages. - msgs: list[str] = [] - for exception in excinfo.value.exceptions: - m = getattr(exception, "msg", None) or ( - exception.args[0] if exception.args else None - ) - if m and m not in msgs: - msgs.append(m) - - reason = "; ".join(msgs) if msgs else default_msg - longrepr = (*loc, reason) - return longrepr - - -class TestReport(BaseReport): - """Basic test report object (also used for setup and teardown calls if - they fail). - - Reports can contain arbitrary extra attributes. - """ - - __test__ = False - - # Defined by skipping plugin. - # xfail reason if xfailed, otherwise not defined. Use hasattr to distinguish. - wasxfail: str - - def __init__( - self, - nodeid: str, - location: tuple[str, int | None, str], - keywords: Mapping[str, Any], - outcome: Literal["passed", "failed", "skipped"], - longrepr: None - | ExceptionInfo[BaseException] - | tuple[str, int, str] - | str - | TerminalRepr, - when: Literal["setup", "call", "teardown"], - sections: Iterable[tuple[str, str]] = (), - duration: float = 0, - start: float = 0, - stop: float = 0, - user_properties: Iterable[tuple[str, object]] | None = None, - **extra, - ) -> None: - #: Normalized collection nodeid. - self.nodeid = nodeid - - #: A (filesystempath, lineno, domaininfo) tuple indicating the - #: actual location of a test item - it might be different from the - #: collected one e.g. if a method is inherited from a different module. - #: The filesystempath may be relative to ``config.rootdir``. - #: The line number is 0-based. - self.location: tuple[str, int | None, str] = location - - #: A name -> value dictionary containing all keywords and - #: markers associated with a test invocation. - self.keywords: Mapping[str, Any] = keywords - - #: Test outcome, always one of "passed", "failed", "skipped". - self.outcome = outcome - - #: None or a failure representation. - self.longrepr = longrepr - - #: One of 'setup', 'call', 'teardown' to indicate runtest phase. - self.when: Literal["setup", "call", "teardown"] = when - - #: User properties is a list of tuples (name, value) that holds user - #: defined properties of the test. - self.user_properties = list(user_properties or []) - - #: Tuples of str ``(heading, content)`` with extra information - #: for the test report. Used by pytest to add text captured - #: from ``stdout``, ``stderr``, and intercepted logging events. May - #: be used by other plugins to add arbitrary information to reports. - self.sections = list(sections) - - #: Time it took to run just the test. - self.duration: float = duration - - #: The system time when the call started, in seconds since the epoch. - self.start: float = start - #: The system time when the call ended, in seconds since the epoch. - self.stop: float = stop - - self.__dict__.update(extra) - - def __repr__(self) -> str: - return f"<{self.__class__.__name__} {self.nodeid!r} when={self.when!r} outcome={self.outcome!r}>" - - @classmethod - def from_item_and_call(cls, item: Item, call: CallInfo[None]) -> TestReport: - """Create and fill a TestReport with standard item and call info. - - :param item: The item. - :param call: The call info. - """ - when = call.when - # Remove "collect" from the Literal type -- only for collection calls. - assert when != "collect" - duration = call.duration - start = call.start - stop = call.stop - keywords = {x: 1 for x in item.keywords} - excinfo = call.excinfo - sections = [] - if not call.excinfo: - outcome: Literal["passed", "failed", "skipped"] = "passed" - longrepr: ( - None - | ExceptionInfo[BaseException] - | tuple[str, int, str] - | str - | TerminalRepr - ) = None - else: - if not isinstance(excinfo, ExceptionInfo): - outcome = "failed" - longrepr = excinfo - elif isinstance(excinfo.value, skip.Exception): - outcome = "skipped" - r = excinfo._getreprcrash() - assert r is not None, ( - "There should always be a traceback entry for skipping a test." - ) - if excinfo.value._use_item_location: - path, line = item.reportinfo()[:2] - assert line is not None - longrepr = (os.fspath(path), line + 1, r.message) - else: - longrepr = (str(r.path), r.lineno, r.message) - elif isinstance(excinfo.value, BaseExceptionGroup) and ( - excinfo.value.split(skip.Exception)[1] is None - ): - # All exceptions in the group are skip exceptions. - outcome = "skipped" - excinfo = cast( - ExceptionInfo[ - BaseExceptionGroup[BaseException | BaseExceptionGroup] - ], - excinfo, - ) - longrepr = _format_exception_group_all_skipped_longrepr(item, excinfo) - else: - outcome = "failed" - longrepr = _format_failed_longrepr(item, call, excinfo) - for rwhen, key, content in item._report_sections: - sections.append((f"Captured {key} {rwhen}", content)) - return cls( - item.nodeid, - item.location, - keywords, - outcome, - longrepr, - when, - sections, - duration, - start, - stop, - user_properties=item.user_properties, - ) - - -@final -class CollectReport(BaseReport): - """Collection report object. - - Reports can contain arbitrary extra attributes. - """ - - when = "collect" - - def __init__( - self, - nodeid: str, - outcome: Literal["passed", "failed", "skipped"], - longrepr: None - | ExceptionInfo[BaseException] - | tuple[str, int, str] - | str - | TerminalRepr, - result: list[Item | Collector] | None, - sections: Iterable[tuple[str, str]] = (), - **extra, - ) -> None: - #: Normalized collection nodeid. - self.nodeid = nodeid - - #: Test outcome, always one of "passed", "failed", "skipped". - self.outcome = outcome - - #: None or a failure representation. - self.longrepr = longrepr - - #: The collected items and collection nodes. - self.result = result or [] - - #: Tuples of str ``(heading, content)`` with extra information - #: for the test report. Used by pytest to add text captured - #: from ``stdout``, ``stderr``, and intercepted logging events. May - #: be used by other plugins to add arbitrary information to reports. - self.sections = list(sections) - - self.__dict__.update(extra) - - @property - def location( # type:ignore[override] - self, - ) -> tuple[str, int | None, str] | None: - return (self.fspath, None, self.fspath) - - def __repr__(self) -> str: - return f"" - - -class CollectErrorRepr(TerminalRepr): - def __init__(self, msg: str) -> None: - self.longrepr = msg - - def toterminal(self, out: TerminalWriter) -> None: - out.line(self.longrepr, red=True) - - -def pytest_report_to_serializable( - report: CollectReport | TestReport, -) -> dict[str, Any] | None: - if isinstance(report, TestReport | CollectReport): - data = report._to_json() - data["$report_type"] = report.__class__.__name__ - return data - # TODO: Check if this is actually reachable. - return None # type: ignore[unreachable] - - -def pytest_report_from_serializable( - data: dict[str, Any], -) -> CollectReport | TestReport | None: - if "$report_type" in data: - if data["$report_type"] == "TestReport": - return TestReport._from_json(data) - elif data["$report_type"] == "CollectReport": - return CollectReport._from_json(data) - assert False, "Unknown report_type unserialize data: {}".format( - data["$report_type"] - ) - return None - - -def _report_to_json(report: BaseReport) -> dict[str, Any]: - """Return the contents of this report as a dict of builtin entries, - suitable for serialization. - - This was originally the serialize_report() function from xdist (ca03269). - """ - - def serialize_repr_entry( - entry: ReprEntry | ReprEntryNative, - ) -> dict[str, Any]: - data = dataclasses.asdict(entry) - for key, value in data.items(): - if hasattr(value, "__dict__"): - data[key] = dataclasses.asdict(value) - entry_data = {"type": type(entry).__name__, "data": data} - return entry_data - - def serialize_repr_traceback(reprtraceback: ReprTraceback) -> dict[str, Any]: - result = dataclasses.asdict(reprtraceback) - result["reprentries"] = [ - serialize_repr_entry(x) for x in reprtraceback.reprentries - ] - return result - - def serialize_repr_crash( - reprcrash: ReprFileLocation | None, - ) -> dict[str, Any] | None: - if reprcrash is not None: - return dataclasses.asdict(reprcrash) - else: - return None - - def serialize_exception_longrepr(rep: BaseReport) -> dict[str, Any]: - assert rep.longrepr is not None - # TODO: Investigate whether the duck typing is really necessary here. - longrepr = cast(ExceptionRepr, rep.longrepr) - result: dict[str, Any] = { - "reprcrash": serialize_repr_crash(longrepr.reprcrash), - "reprtraceback": serialize_repr_traceback(longrepr.reprtraceback), - "sections": longrepr.sections, - } - if isinstance(longrepr, ExceptionChainRepr): - result["chain"] = [] - for repr_traceback, repr_crash, description in longrepr.chain: - result["chain"].append( - ( - serialize_repr_traceback(repr_traceback), - serialize_repr_crash(repr_crash), - description, - ) - ) - else: - result["chain"] = None - return result - - d = report.__dict__.copy() - if hasattr(report.longrepr, "toterminal"): - if hasattr(report.longrepr, "reprtraceback") and hasattr( - report.longrepr, "reprcrash" - ): - d["longrepr"] = serialize_exception_longrepr(report) - else: - d["longrepr"] = str(report.longrepr) - else: - d["longrepr"] = report.longrepr - for name in d: - if isinstance(d[name], os.PathLike): - d[name] = os.fspath(d[name]) - elif name == "result": - d[name] = None # for now - return d - - -def _report_kwargs_from_json(reportdict: dict[str, Any]) -> dict[str, Any]: - """Return **kwargs that can be used to construct a TestReport or - CollectReport instance. - - This was originally the serialize_report() function from xdist (ca03269). - """ - - def deserialize_repr_entry(entry_data): - data = entry_data["data"] - entry_type = entry_data["type"] - if entry_type == "ReprEntry": - reprfuncargs = None - reprfileloc = None - reprlocals = None - if data["reprfuncargs"]: - reprfuncargs = ReprFuncArgs(**data["reprfuncargs"]) - if data["reprfileloc"]: - reprfileloc = ReprFileLocation(**data["reprfileloc"]) - if data["reprlocals"]: - reprlocals = ReprLocals(data["reprlocals"]["lines"]) - - reprentry: ReprEntry | ReprEntryNative = ReprEntry( - lines=data["lines"], - reprfuncargs=reprfuncargs, - reprlocals=reprlocals, - reprfileloc=reprfileloc, - style=data["style"], - ) - elif entry_type == "ReprEntryNative": - reprentry = ReprEntryNative(data["lines"]) - else: - _report_unserialization_failure(entry_type, TestReport, reportdict) - return reprentry - - def deserialize_repr_traceback(repr_traceback_dict): - repr_traceback_dict["reprentries"] = [ - deserialize_repr_entry(x) for x in repr_traceback_dict["reprentries"] - ] - return ReprTraceback(**repr_traceback_dict) - - def deserialize_repr_crash(repr_crash_dict: dict[str, Any] | None): - if repr_crash_dict is not None: - return ReprFileLocation(**repr_crash_dict) - else: - return None - - if ( - reportdict["longrepr"] - and "reprcrash" in reportdict["longrepr"] - and "reprtraceback" in reportdict["longrepr"] - ): - reprtraceback = deserialize_repr_traceback( - reportdict["longrepr"]["reprtraceback"] - ) - reprcrash = deserialize_repr_crash(reportdict["longrepr"]["reprcrash"]) - if reportdict["longrepr"]["chain"]: - chain = [] - for repr_traceback_data, repr_crash_data, description in reportdict[ - "longrepr" - ]["chain"]: - chain.append( - ( - deserialize_repr_traceback(repr_traceback_data), - deserialize_repr_crash(repr_crash_data), - description, - ) - ) - exception_info: ExceptionChainRepr | ReprExceptionInfo = ExceptionChainRepr( - chain - ) - else: - exception_info = ReprExceptionInfo( - reprtraceback=reprtraceback, - reprcrash=reprcrash, - ) - - for section in reportdict["longrepr"]["sections"]: - exception_info.addsection(*section) - reportdict["longrepr"] = exception_info - - return reportdict diff --git a/.venv/lib/python3.12/site-packages/_pytest/runner.py b/.venv/lib/python3.12/site-packages/_pytest/runner.py deleted file mode 100644 index 9c20ff9..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/runner.py +++ /dev/null @@ -1,580 +0,0 @@ -# mypy: allow-untyped-defs -"""Basic collect and runtest protocol implementations.""" - -from __future__ import annotations - -import bdb -from collections.abc import Callable -import dataclasses -import os -import sys -import types -from typing import cast -from typing import final -from typing import Generic -from typing import Literal -from typing import TYPE_CHECKING -from typing import TypeVar - -from .config import Config -from .reports import BaseReport -from .reports import CollectErrorRepr -from .reports import CollectReport -from .reports import TestReport -from _pytest import timing -from _pytest._code.code import ExceptionChainRepr -from _pytest._code.code import ExceptionInfo -from _pytest._code.code import TerminalRepr -from _pytest.config.argparsing import Parser -from _pytest.deprecated import check_ispytest -from _pytest.nodes import Collector -from _pytest.nodes import Directory -from _pytest.nodes import Item -from _pytest.nodes import Node -from _pytest.outcomes import Exit -from _pytest.outcomes import OutcomeException -from _pytest.outcomes import Skipped -from _pytest.outcomes import TEST_OUTCOME - - -if sys.version_info < (3, 11): - from exceptiongroup import BaseExceptionGroup - -if TYPE_CHECKING: - from _pytest.main import Session - from _pytest.terminal import TerminalReporter - -# -# pytest plugin hooks. - - -def pytest_addoption(parser: Parser) -> None: - group = parser.getgroup("terminal reporting", "Reporting", after="general") - group.addoption( - "--durations", - action="store", - type=int, - default=None, - metavar="N", - help="Show N slowest setup/test durations (N=0 for all)", - ) - group.addoption( - "--durations-min", - action="store", - type=float, - default=None, - metavar="N", - help="Minimal duration in seconds for inclusion in slowest list. " - "Default: 0.005 (or 0.0 if -vv is given).", - ) - - -def pytest_terminal_summary(terminalreporter: TerminalReporter) -> None: - durations = terminalreporter.config.option.durations - durations_min = terminalreporter.config.option.durations_min - verbose = terminalreporter.config.get_verbosity() - if durations is None: - return - if durations_min is None: - durations_min = 0.005 if verbose < 2 else 0.0 - tr = terminalreporter - dlist = [] - for replist in tr.stats.values(): - for rep in replist: - if hasattr(rep, "duration"): - dlist.append(rep) - if not dlist: - return - dlist.sort(key=lambda x: x.duration, reverse=True) - if not durations: - tr.write_sep("=", "slowest durations") - else: - tr.write_sep("=", f"slowest {durations} durations") - dlist = dlist[:durations] - - for i, rep in enumerate(dlist): - if rep.duration < durations_min: - tr.write_line("") - message = f"({len(dlist) - i} durations < {durations_min:g}s hidden." - if terminalreporter.config.option.durations_min is None: - message += " Use -vv to show these durations." - message += ")" - tr.write_line(message) - break - tr.write_line(f"{rep.duration:02.2f}s {rep.when:<8} {rep.nodeid}") - - -def pytest_sessionstart(session: Session) -> None: - session._setupstate = SetupState() - - -def pytest_sessionfinish(session: Session) -> None: - session._setupstate.teardown_exact(None) - - -def pytest_runtest_protocol(item: Item, nextitem: Item | None) -> bool: - ihook = item.ihook - ihook.pytest_runtest_logstart(nodeid=item.nodeid, location=item.location) - runtestprotocol(item, nextitem=nextitem) - ihook.pytest_runtest_logfinish(nodeid=item.nodeid, location=item.location) - return True - - -def runtestprotocol( - item: Item, log: bool = True, nextitem: Item | None = None -) -> list[TestReport]: - hasrequest = hasattr(item, "_request") - if hasrequest and not item._request: # type: ignore[attr-defined] - # This only happens if the item is re-run, as is done by - # pytest-rerunfailures. - item._initrequest() # type: ignore[attr-defined] - rep = call_and_report(item, "setup", log) - reports = [rep] - if rep.passed: - if item.config.getoption("setupshow", False): - show_test_item(item) - if not item.config.getoption("setuponly", False): - reports.append(call_and_report(item, "call", log)) - # If the session is about to fail or stop, teardown everything - this is - # necessary to correctly report fixture teardown errors (see #11706) - if item.session.shouldfail or item.session.shouldstop: - nextitem = None - reports.append(call_and_report(item, "teardown", log, nextitem=nextitem)) - # After all teardown hooks have been called - # want funcargs and request info to go away. - if hasrequest: - item._request = False # type: ignore[attr-defined] - item.funcargs = None # type: ignore[attr-defined] - return reports - - -def show_test_item(item: Item) -> None: - """Show test function, parameters and the fixtures of the test item.""" - tw = item.config.get_terminal_writer() - tw.line() - tw.write(" " * 8) - tw.write(item.nodeid) - used_fixtures = sorted(getattr(item, "fixturenames", [])) - if used_fixtures: - tw.write(" (fixtures used: {})".format(", ".join(used_fixtures))) - tw.flush() - - -def pytest_runtest_setup(item: Item) -> None: - _update_current_test_var(item, "setup") - item.session._setupstate.setup(item) - - -def pytest_runtest_call(item: Item) -> None: - _update_current_test_var(item, "call") - try: - del sys.last_type - del sys.last_value - del sys.last_traceback - if sys.version_info >= (3, 12, 0): - del sys.last_exc # type:ignore[attr-defined] - except AttributeError: - pass - try: - item.runtest() - except Exception as e: - # Store trace info to allow postmortem debugging - sys.last_type = type(e) - sys.last_value = e - if sys.version_info >= (3, 12, 0): - sys.last_exc = e # type:ignore[attr-defined] - assert e.__traceback__ is not None - # Skip *this* frame - sys.last_traceback = e.__traceback__.tb_next - raise - - -def pytest_runtest_teardown(item: Item, nextitem: Item | None) -> None: - _update_current_test_var(item, "teardown") - item.session._setupstate.teardown_exact(nextitem) - _update_current_test_var(item, None) - - -def _update_current_test_var( - item: Item, when: Literal["setup", "call", "teardown"] | None -) -> None: - """Update :envvar:`PYTEST_CURRENT_TEST` to reflect the current item and stage. - - If ``when`` is None, delete ``PYTEST_CURRENT_TEST`` from the environment. - """ - var_name = "PYTEST_CURRENT_TEST" - if when: - value = f"{item.nodeid} ({when})" - # don't allow null bytes on environment variables (see #2644, #2957) - value = value.replace("\x00", "(null)") - os.environ[var_name] = value - else: - os.environ.pop(var_name) - - -def pytest_report_teststatus(report: BaseReport) -> tuple[str, str, str] | None: - if report.when in ("setup", "teardown"): - if report.failed: - # category, shortletter, verbose-word - return "error", "E", "ERROR" - elif report.skipped: - return "skipped", "s", "SKIPPED" - else: - return "", "", "" - return None - - -# -# Implementation - - -def call_and_report( - item: Item, when: Literal["setup", "call", "teardown"], log: bool = True, **kwds -) -> TestReport: - ihook = item.ihook - if when == "setup": - runtest_hook: Callable[..., None] = ihook.pytest_runtest_setup - elif when == "call": - runtest_hook = ihook.pytest_runtest_call - elif when == "teardown": - runtest_hook = ihook.pytest_runtest_teardown - else: - assert False, f"Unhandled runtest hook case: {when}" - - call = CallInfo.from_call( - lambda: runtest_hook(item=item, **kwds), - when=when, - reraise=get_reraise_exceptions(item.config), - ) - report: TestReport = ihook.pytest_runtest_makereport(item=item, call=call) - if log: - ihook.pytest_runtest_logreport(report=report) - if check_interactive_exception(call, report): - ihook.pytest_exception_interact(node=item, call=call, report=report) - return report - - -def get_reraise_exceptions(config: Config) -> tuple[type[BaseException], ...]: - """Return exception types that should not be suppressed in general.""" - reraise: tuple[type[BaseException], ...] = (Exit,) - if not config.getoption("usepdb", False): - reraise += (KeyboardInterrupt,) - return reraise - - -def check_interactive_exception(call: CallInfo[object], report: BaseReport) -> bool: - """Check whether the call raised an exception that should be reported as - interactive.""" - if call.excinfo is None: - # Didn't raise. - return False - if hasattr(report, "wasxfail"): - # Exception was expected. - return False - if isinstance(call.excinfo.value, Skipped | bdb.BdbQuit): - # Special control flow exception. - return False - return True - - -TResult = TypeVar("TResult", covariant=True) - - -@final -@dataclasses.dataclass -class CallInfo(Generic[TResult]): - """Result/Exception info of a function invocation.""" - - _result: TResult | None - #: The captured exception of the call, if it raised. - excinfo: ExceptionInfo[BaseException] | None - #: The system time when the call started, in seconds since the epoch. - start: float - #: The system time when the call ended, in seconds since the epoch. - stop: float - #: The call duration, in seconds. - duration: float - #: The context of invocation: "collect", "setup", "call" or "teardown". - when: Literal["collect", "setup", "call", "teardown"] - - def __init__( - self, - result: TResult | None, - excinfo: ExceptionInfo[BaseException] | None, - start: float, - stop: float, - duration: float, - when: Literal["collect", "setup", "call", "teardown"], - *, - _ispytest: bool = False, - ) -> None: - check_ispytest(_ispytest) - self._result = result - self.excinfo = excinfo - self.start = start - self.stop = stop - self.duration = duration - self.when = when - - @property - def result(self) -> TResult: - """The return value of the call, if it didn't raise. - - Can only be accessed if excinfo is None. - """ - if self.excinfo is not None: - raise AttributeError(f"{self!r} has no valid result") - # The cast is safe because an exception wasn't raised, hence - # _result has the expected function return type (which may be - # None, that's why a cast and not an assert). - return cast(TResult, self._result) - - @classmethod - def from_call( - cls, - func: Callable[[], TResult], - when: Literal["collect", "setup", "call", "teardown"], - reraise: type[BaseException] | tuple[type[BaseException], ...] | None = None, - ) -> CallInfo[TResult]: - """Call func, wrapping the result in a CallInfo. - - :param func: - The function to call. Called without arguments. - :type func: Callable[[], _pytest.runner.TResult] - :param when: - The phase in which the function is called. - :param reraise: - Exception or exceptions that shall propagate if raised by the - function, instead of being wrapped in the CallInfo. - """ - excinfo = None - instant = timing.Instant() - try: - result: TResult | None = func() - except BaseException: - excinfo = ExceptionInfo.from_current() - if reraise is not None and isinstance(excinfo.value, reraise): - raise - result = None - duration = instant.elapsed() - return cls( - start=duration.start.time, - stop=duration.stop.time, - duration=duration.seconds, - when=when, - result=result, - excinfo=excinfo, - _ispytest=True, - ) - - def __repr__(self) -> str: - if self.excinfo is None: - return f"" - return f"" - - -def pytest_runtest_makereport(item: Item, call: CallInfo[None]) -> TestReport: - return TestReport.from_item_and_call(item, call) - - -def pytest_make_collect_report(collector: Collector) -> CollectReport: - def collect() -> list[Item | Collector]: - # Before collecting, if this is a Directory, load the conftests. - # If a conftest import fails to load, it is considered a collection - # error of the Directory collector. This is why it's done inside of the - # CallInfo wrapper. - # - # Note: initial conftests are loaded early, not here. - if isinstance(collector, Directory): - collector.config.pluginmanager._loadconftestmodules( - collector.path, - collector.config.getoption("importmode"), - rootpath=collector.config.rootpath, - consider_namespace_packages=collector.config.getini( - "consider_namespace_packages" - ), - ) - - return list(collector.collect()) - - call = CallInfo.from_call( - collect, "collect", reraise=(KeyboardInterrupt, SystemExit) - ) - longrepr: None | tuple[str, int, str] | str | TerminalRepr = None - if not call.excinfo: - outcome: Literal["passed", "skipped", "failed"] = "passed" - else: - skip_exceptions = [Skipped] - unittest = sys.modules.get("unittest") - if unittest is not None: - skip_exceptions.append(unittest.SkipTest) - if isinstance(call.excinfo.value, tuple(skip_exceptions)): - outcome = "skipped" - r_ = collector._repr_failure_py(call.excinfo, "line") - assert isinstance(r_, ExceptionChainRepr), repr(r_) - r = r_.reprcrash - assert r - longrepr = (str(r.path), r.lineno, r.message) - else: - outcome = "failed" - errorinfo = collector.repr_failure(call.excinfo) - if not hasattr(errorinfo, "toterminal"): - assert isinstance(errorinfo, str) - errorinfo = CollectErrorRepr(errorinfo) - longrepr = errorinfo - result = call.result if not call.excinfo else None - rep = CollectReport(collector.nodeid, outcome, longrepr, result) - rep.call = call # type: ignore # see collect_one_node - return rep - - -class SetupState: - """Shared state for setting up/tearing down test items or collectors - in a session. - - Suppose we have a collection tree as follows: - - - - - - - - The SetupState maintains a stack. The stack starts out empty: - - [] - - During the setup phase of item1, setup(item1) is called. What it does - is: - - push session to stack, run session.setup() - push mod1 to stack, run mod1.setup() - push item1 to stack, run item1.setup() - - The stack is: - - [session, mod1, item1] - - While the stack is in this shape, it is allowed to add finalizers to - each of session, mod1, item1 using addfinalizer(). - - During the teardown phase of item1, teardown_exact(item2) is called, - where item2 is the next item to item1. What it does is: - - pop item1 from stack, run its teardowns - pop mod1 from stack, run its teardowns - - mod1 was popped because it ended its purpose with item1. The stack is: - - [session] - - During the setup phase of item2, setup(item2) is called. What it does - is: - - push mod2 to stack, run mod2.setup() - push item2 to stack, run item2.setup() - - Stack: - - [session, mod2, item2] - - During the teardown phase of item2, teardown_exact(None) is called, - because item2 is the last item. What it does is: - - pop item2 from stack, run its teardowns - pop mod2 from stack, run its teardowns - pop session from stack, run its teardowns - - Stack: - - [] - - The end! - """ - - def __init__(self) -> None: - # The stack is in the dict insertion order. - self.stack: dict[ - Node, - tuple[ - # Node's finalizers. - list[Callable[[], object]], - # Node's exception and original traceback, if its setup raised. - tuple[OutcomeException | Exception, types.TracebackType | None] | None, - ], - ] = {} - - def setup(self, item: Item) -> None: - """Setup objects along the collector chain to the item.""" - needed_collectors = item.listchain() - - # If a collector fails its setup, fail its entire subtree of items. - # The setup is not retried for each item - the same exception is used. - for col, (finalizers, exc) in self.stack.items(): - assert col in needed_collectors, "previous item was not torn down properly" - if exc: - raise exc[0].with_traceback(exc[1]) - - for col in needed_collectors[len(self.stack) :]: - assert col not in self.stack - # Push onto the stack. - self.stack[col] = ([col.teardown], None) - try: - col.setup() - except TEST_OUTCOME as exc: - self.stack[col] = (self.stack[col][0], (exc, exc.__traceback__)) - raise - - def addfinalizer(self, finalizer: Callable[[], object], node: Node) -> None: - """Attach a finalizer to the given node. - - The node must be currently active in the stack. - """ - assert node and not isinstance(node, tuple) - assert callable(finalizer) - assert node in self.stack, (node, self.stack) - self.stack[node][0].append(finalizer) - - def teardown_exact(self, nextitem: Item | None) -> None: - """Teardown the current stack up until reaching nodes that nextitem - also descends from. - - When nextitem is None (meaning we're at the last item), the entire - stack is torn down. - """ - needed_collectors = (nextitem and nextitem.listchain()) or [] - exceptions: list[BaseException] = [] - while self.stack: - if list(self.stack.keys()) == needed_collectors[: len(self.stack)]: - break - node, (finalizers, _) = self.stack.popitem() - these_exceptions = [] - while finalizers: - fin = finalizers.pop() - try: - fin() - except TEST_OUTCOME as e: - these_exceptions.append(e) - - if len(these_exceptions) == 1: - exceptions.extend(these_exceptions) - elif these_exceptions: - msg = f"errors while tearing down {node!r}" - exceptions.append(BaseExceptionGroup(msg, these_exceptions[::-1])) - - if len(exceptions) == 1: - raise exceptions[0] - elif exceptions: - raise BaseExceptionGroup("errors during test teardown", exceptions[::-1]) - if nextitem is None: - assert not self.stack - - -def collect_one_node(collector: Collector) -> CollectReport: - ihook = collector.ihook - ihook.pytest_collectstart(collector=collector) - rep: CollectReport = ihook.pytest_make_collect_report(collector=collector) - call = rep.__dict__.pop("call", None) - if call and check_interactive_exception(call, rep): - ihook.pytest_exception_interact(node=collector, call=call, report=rep) - return rep diff --git a/.venv/lib/python3.12/site-packages/_pytest/scope.py b/.venv/lib/python3.12/site-packages/_pytest/scope.py deleted file mode 100644 index 2b007e8..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/scope.py +++ /dev/null @@ -1,91 +0,0 @@ -""" -Scope definition and related utilities. - -Those are defined here, instead of in the 'fixtures' module because -their use is spread across many other pytest modules, and centralizing it in 'fixtures' -would cause circular references. - -Also this makes the module light to import, as it should. -""" - -from __future__ import annotations - -from enum import Enum -from functools import total_ordering -from typing import Literal - - -_ScopeName = Literal["session", "package", "module", "class", "function"] - - -@total_ordering -class Scope(Enum): - """ - Represents one of the possible fixture scopes in pytest. - - Scopes are ordered from lower to higher, that is: - - ->>> higher ->>> - - Function < Class < Module < Package < Session - - <<<- lower <<<- - """ - - # Scopes need to be listed from lower to higher. - Function = "function" - Class = "class" - Module = "module" - Package = "package" - Session = "session" - - def next_lower(self) -> Scope: - """Return the next lower scope.""" - index = _SCOPE_INDICES[self] - if index == 0: - raise ValueError(f"{self} is the lower-most scope") - return _ALL_SCOPES[index - 1] - - def next_higher(self) -> Scope: - """Return the next higher scope.""" - index = _SCOPE_INDICES[self] - if index == len(_SCOPE_INDICES) - 1: - raise ValueError(f"{self} is the upper-most scope") - return _ALL_SCOPES[index + 1] - - def __lt__(self, other: Scope) -> bool: - self_index = _SCOPE_INDICES[self] - other_index = _SCOPE_INDICES[other] - return self_index < other_index - - @classmethod - def from_user( - cls, scope_name: _ScopeName, descr: str, where: str | None = None - ) -> Scope: - """ - Given a scope name from the user, return the equivalent Scope enum. Should be used - whenever we want to convert a user provided scope name to its enum object. - - If the scope name is invalid, construct a user friendly message and call pytest.fail. - """ - from _pytest.outcomes import fail - - try: - # Holding this reference is necessary for mypy at the moment. - scope = Scope(scope_name) - except ValueError: - fail( - "{} {}got an unexpected scope value '{}'".format( - descr, f"from {where} " if where else "", scope_name - ), - pytrace=False, - ) - return scope - - -_ALL_SCOPES = list(Scope) -_SCOPE_INDICES = {scope: index for index, scope in enumerate(_ALL_SCOPES)} - - -# Ordered list of scopes which can contain many tests (in practice all except Function). -HIGH_SCOPES = [x for x in Scope if x is not Scope.Function] diff --git a/.venv/lib/python3.12/site-packages/_pytest/setuponly.py b/.venv/lib/python3.12/site-packages/_pytest/setuponly.py deleted file mode 100644 index 7e6b46b..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/setuponly.py +++ /dev/null @@ -1,98 +0,0 @@ -from __future__ import annotations - -from collections.abc import Generator - -from _pytest._io.saferepr import saferepr -from _pytest.config import Config -from _pytest.config import ExitCode -from _pytest.config.argparsing import Parser -from _pytest.fixtures import FixtureDef -from _pytest.fixtures import SubRequest -from _pytest.scope import Scope -import pytest - - -def pytest_addoption(parser: Parser) -> None: - group = parser.getgroup("debugconfig") - group.addoption( - "--setuponly", - "--setup-only", - action="store_true", - help="Only setup fixtures, do not execute tests", - ) - group.addoption( - "--setupshow", - "--setup-show", - action="store_true", - help="Show setup of fixtures while executing tests", - ) - - -@pytest.hookimpl(wrapper=True) -def pytest_fixture_setup( - fixturedef: FixtureDef[object], request: SubRequest -) -> Generator[None, object, object]: - try: - return (yield) - finally: - if request.config.option.setupshow: - if hasattr(request, "param"): - # Save the fixture parameter so ._show_fixture_action() can - # display it now and during the teardown (in .finish()). - if fixturedef.ids: - if callable(fixturedef.ids): - param = fixturedef.ids(request.param) - else: - param = fixturedef.ids[request.param_index] - else: - param = request.param - fixturedef.cached_param = param # type: ignore[attr-defined] - _show_fixture_action(fixturedef, request.config, "SETUP") - - -def pytest_fixture_post_finalizer( - fixturedef: FixtureDef[object], request: SubRequest -) -> None: - if fixturedef.cached_result is not None: - config = request.config - if config.option.setupshow: - _show_fixture_action(fixturedef, request.config, "TEARDOWN") - if hasattr(fixturedef, "cached_param"): - del fixturedef.cached_param - - -def _show_fixture_action( - fixturedef: FixtureDef[object], config: Config, msg: str -) -> None: - capman = config.pluginmanager.getplugin("capturemanager") - if capman: - capman.suspend_global_capture() - - tw = config.get_terminal_writer() - tw.line() - # Use smaller indentation the higher the scope: Session = 0, Package = 1, etc. - scope_indent = list(reversed(Scope)).index(fixturedef._scope) - tw.write(" " * 2 * scope_indent) - - scopename = fixturedef.scope[0].upper() - tw.write(f"{msg:<8} {scopename} {fixturedef.argname}") - - if msg == "SETUP": - deps = sorted(arg for arg in fixturedef.argnames if arg != "request") - if deps: - tw.write(" (fixtures used: {})".format(", ".join(deps))) - - if hasattr(fixturedef, "cached_param"): - tw.write(f"[{saferepr(fixturedef.cached_param, maxsize=42)}]") - - tw.flush() - - if capman: - capman.resume_global_capture() - - -@pytest.hookimpl(tryfirst=True) -def pytest_cmdline_main(config: Config) -> int | ExitCode | None: - if config.option.setuponly: - config.option.setupshow = True - return None diff --git a/.venv/lib/python3.12/site-packages/_pytest/setupplan.py b/.venv/lib/python3.12/site-packages/_pytest/setupplan.py deleted file mode 100644 index 4e124cc..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/setupplan.py +++ /dev/null @@ -1,39 +0,0 @@ -from __future__ import annotations - -from _pytest.config import Config -from _pytest.config import ExitCode -from _pytest.config.argparsing import Parser -from _pytest.fixtures import FixtureDef -from _pytest.fixtures import SubRequest -import pytest - - -def pytest_addoption(parser: Parser) -> None: - group = parser.getgroup("debugconfig") - group.addoption( - "--setupplan", - "--setup-plan", - action="store_true", - help="Show what fixtures and tests would be executed but " - "don't execute anything", - ) - - -@pytest.hookimpl(tryfirst=True) -def pytest_fixture_setup( - fixturedef: FixtureDef[object], request: SubRequest -) -> object | None: - # Will return a dummy fixture if the setuponly option is provided. - if request.config.option.setupplan: - my_cache_key = fixturedef.cache_key(request) - fixturedef.cached_result = (None, my_cache_key, None) - return fixturedef.cached_result - return None - - -@pytest.hookimpl(tryfirst=True) -def pytest_cmdline_main(config: Config) -> int | ExitCode | None: - if config.option.setupplan: - config.option.setuponly = True - config.option.setupshow = True - return None diff --git a/.venv/lib/python3.12/site-packages/_pytest/skipping.py b/.venv/lib/python3.12/site-packages/_pytest/skipping.py deleted file mode 100644 index 3b06762..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/skipping.py +++ /dev/null @@ -1,321 +0,0 @@ -# mypy: allow-untyped-defs -"""Support for skip/xfail functions and markers.""" - -from __future__ import annotations - -from collections.abc import Generator -from collections.abc import Mapping -import dataclasses -import os -import platform -import sys -import traceback - -from _pytest.config import Config -from _pytest.config import hookimpl -from _pytest.config.argparsing import Parser -from _pytest.mark.structures import Mark -from _pytest.nodes import Item -from _pytest.outcomes import fail -from _pytest.outcomes import skip -from _pytest.outcomes import xfail -from _pytest.raises import AbstractRaises -from _pytest.reports import BaseReport -from _pytest.reports import TestReport -from _pytest.runner import CallInfo -from _pytest.stash import StashKey - - -def pytest_addoption(parser: Parser) -> None: - group = parser.getgroup("general") - group.addoption( - "--runxfail", - action="store_true", - dest="runxfail", - default=False, - help="Report the results of xfail tests as if they were not marked", - ) - - parser.addini( - "strict_xfail", - "Default for the strict parameter of xfail " - "markers when not given explicitly (default: False) (alias: xfail_strict)", - type="bool", - # None => fallback to `strict`. - default=None, - aliases=["xfail_strict"], - ) - - -def pytest_configure(config: Config) -> None: - if config.option.runxfail: - # yay a hack - import pytest - - old = pytest.xfail - config.add_cleanup(lambda: setattr(pytest, "xfail", old)) - - def nop(*args, **kwargs): - pass - - nop.Exception = xfail.Exception # type: ignore[attr-defined] - setattr(pytest, "xfail", nop) - - config.addinivalue_line( - "markers", - "skip(reason=None): skip the given test function with an optional reason. " - 'Example: skip(reason="no way of currently testing this") skips the ' - "test.", - ) - config.addinivalue_line( - "markers", - "skipif(condition, ..., *, reason=...): " - "skip the given test function if any of the conditions evaluate to True. " - "Example: skipif(sys.platform == 'win32') skips the test if we are on the win32 platform. " - "See https://docs.pytest.org/en/stable/reference/reference.html#pytest-mark-skipif", - ) - config.addinivalue_line( - "markers", - "xfail(condition, ..., *, reason=..., run=True, raises=None, strict=strict_xfail): " - "mark the test function as an expected failure if any of the conditions " - "evaluate to True. Optionally specify a reason for better reporting " - "and run=False if you don't even want to execute the test function. " - "If only specific exception(s) are expected, you can list them in " - "raises, and if the test fails in other ways, it will be reported as " - "a true failure. See https://docs.pytest.org/en/stable/reference/reference.html#pytest-mark-xfail", - ) - - -def evaluate_condition(item: Item, mark: Mark, condition: object) -> tuple[bool, str]: - """Evaluate a single skipif/xfail condition. - - If an old-style string condition is given, it is eval()'d, otherwise the - condition is bool()'d. If this fails, an appropriately formatted pytest.fail - is raised. - - Returns (result, reason). The reason is only relevant if the result is True. - """ - # String condition. - if isinstance(condition, str): - globals_ = { - "os": os, - "sys": sys, - "platform": platform, - "config": item.config, - } - for dictionary in reversed( - item.ihook.pytest_markeval_namespace(config=item.config) - ): - if not isinstance(dictionary, Mapping): - raise ValueError( - f"pytest_markeval_namespace() needs to return a dict, got {dictionary!r}" - ) - globals_.update(dictionary) - if hasattr(item, "obj"): - globals_.update(item.obj.__globals__) - try: - filename = f"<{mark.name} condition>" - condition_code = compile(condition, filename, "eval") - result = eval(condition_code, globals_) - except SyntaxError as exc: - msglines = [ - f"Error evaluating {mark.name!r} condition", - " " + condition, - " " + " " * (exc.offset or 0) + "^", - "SyntaxError: invalid syntax", - ] - fail("\n".join(msglines), pytrace=False) - except Exception as exc: - msglines = [ - f"Error evaluating {mark.name!r} condition", - " " + condition, - *traceback.format_exception_only(type(exc), exc), - ] - fail("\n".join(msglines), pytrace=False) - - # Boolean condition. - else: - try: - result = bool(condition) - except Exception as exc: - msglines = [ - f"Error evaluating {mark.name!r} condition as a boolean", - *traceback.format_exception_only(type(exc), exc), - ] - fail("\n".join(msglines), pytrace=False) - - reason = mark.kwargs.get("reason", None) - if reason is None: - if isinstance(condition, str): - reason = "condition: " + condition - else: - # XXX better be checked at collection time - msg = ( - f"Error evaluating {mark.name!r}: " - + "you need to specify reason=STRING when using booleans as conditions." - ) - fail(msg, pytrace=False) - - return result, reason - - -@dataclasses.dataclass(frozen=True) -class Skip: - """The result of evaluate_skip_marks().""" - - reason: str = "unconditional skip" - - -def evaluate_skip_marks(item: Item) -> Skip | None: - """Evaluate skip and skipif marks on item, returning Skip if triggered.""" - for mark in item.iter_markers(name="skipif"): - if "condition" not in mark.kwargs: - conditions = mark.args - else: - conditions = (mark.kwargs["condition"],) - - # Unconditional. - if not conditions: - reason = mark.kwargs.get("reason", "") - return Skip(reason) - - # If any of the conditions are true. - for condition in conditions: - result, reason = evaluate_condition(item, mark, condition) - if result: - return Skip(reason) - - for mark in item.iter_markers(name="skip"): - try: - return Skip(*mark.args, **mark.kwargs) - except TypeError as e: - raise TypeError(str(e) + " - maybe you meant pytest.mark.skipif?") from None - - return None - - -@dataclasses.dataclass(frozen=True) -class Xfail: - """The result of evaluate_xfail_marks().""" - - __slots__ = ("raises", "reason", "run", "strict") - - reason: str - run: bool - strict: bool - raises: ( - type[BaseException] - | tuple[type[BaseException], ...] - | AbstractRaises[BaseException] - | None - ) - - -def evaluate_xfail_marks(item: Item) -> Xfail | None: - """Evaluate xfail marks on item, returning Xfail if triggered.""" - for mark in item.iter_markers(name="xfail"): - run = mark.kwargs.get("run", True) - strict = mark.kwargs.get("strict") - if strict is None: - strict = item.config.getini("strict_xfail") - if strict is None: - strict = item.config.getini("strict") - raises = mark.kwargs.get("raises", None) - if "condition" not in mark.kwargs: - conditions = mark.args - else: - conditions = (mark.kwargs["condition"],) - - # Unconditional. - if not conditions: - reason = mark.kwargs.get("reason", "") - return Xfail(reason, run, strict, raises) - - # If any of the conditions are true. - for condition in conditions: - result, reason = evaluate_condition(item, mark, condition) - if result: - return Xfail(reason, run, strict, raises) - - return None - - -# Saves the xfail mark evaluation. Can be refreshed during call if None. -xfailed_key = StashKey[Xfail | None]() - - -@hookimpl(tryfirst=True) -def pytest_runtest_setup(item: Item) -> None: - skipped = evaluate_skip_marks(item) - if skipped: - raise skip.Exception(skipped.reason, _use_item_location=True) - - item.stash[xfailed_key] = xfailed = evaluate_xfail_marks(item) - if xfailed and not item.config.option.runxfail and not xfailed.run: - xfail("[NOTRUN] " + xfailed.reason) - - -@hookimpl(wrapper=True) -def pytest_runtest_call(item: Item) -> Generator[None]: - xfailed = item.stash.get(xfailed_key, None) - if xfailed is None: - item.stash[xfailed_key] = xfailed = evaluate_xfail_marks(item) - - if xfailed and not item.config.option.runxfail and not xfailed.run: - xfail("[NOTRUN] " + xfailed.reason) - - try: - return (yield) - finally: - # The test run may have added an xfail mark dynamically. - xfailed = item.stash.get(xfailed_key, None) - if xfailed is None: - item.stash[xfailed_key] = xfailed = evaluate_xfail_marks(item) - - -@hookimpl(wrapper=True) -def pytest_runtest_makereport( - item: Item, call: CallInfo[None] -) -> Generator[None, TestReport, TestReport]: - rep = yield - xfailed = item.stash.get(xfailed_key, None) - if item.config.option.runxfail: - pass # don't interfere - elif call.excinfo and isinstance(call.excinfo.value, xfail.Exception): - assert call.excinfo.value.msg is not None - rep.wasxfail = call.excinfo.value.msg - rep.outcome = "skipped" - elif not rep.skipped and xfailed: - if call.excinfo: - raises = xfailed.raises - if raises is None or ( - ( - isinstance(raises, type | tuple) - and isinstance(call.excinfo.value, raises) - ) - or ( - isinstance(raises, AbstractRaises) - and raises.matches(call.excinfo.value) - ) - ): - rep.outcome = "skipped" - rep.wasxfail = xfailed.reason - else: - rep.outcome = "failed" - elif call.when == "call": - if xfailed.strict: - rep.outcome = "failed" - rep.longrepr = "[XPASS(strict)] " + xfailed.reason - else: - rep.outcome = "passed" - rep.wasxfail = xfailed.reason - return rep - - -def pytest_report_teststatus(report: BaseReport) -> tuple[str, str, str] | None: - if hasattr(report, "wasxfail"): - if report.skipped: - return "xfailed", "x", "XFAIL" - elif report.passed: - return "xpassed", "X", "XPASS" - return None diff --git a/.venv/lib/python3.12/site-packages/_pytest/stash.py b/.venv/lib/python3.12/site-packages/_pytest/stash.py deleted file mode 100644 index 6a9ff88..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/stash.py +++ /dev/null @@ -1,116 +0,0 @@ -from __future__ import annotations - -from typing import Any -from typing import cast -from typing import Generic -from typing import TypeVar - - -__all__ = ["Stash", "StashKey"] - - -T = TypeVar("T") -D = TypeVar("D") - - -class StashKey(Generic[T]): - """``StashKey`` is an object used as a key to a :class:`Stash`. - - A ``StashKey`` is associated with the type ``T`` of the value of the key. - - A ``StashKey`` is unique and cannot conflict with another key. - - .. versionadded:: 7.0 - """ - - __slots__ = () - - -class Stash: - r"""``Stash`` is a type-safe heterogeneous mutable mapping that - allows keys and value types to be defined separately from - where it (the ``Stash``) is created. - - Usually you will be given an object which has a ``Stash``, for example - :class:`~pytest.Config` or a :class:`~_pytest.nodes.Node`: - - .. code-block:: python - - stash: Stash = some_object.stash - - If a module or plugin wants to store data in this ``Stash``, it creates - :class:`StashKey`\s for its keys (at the module level): - - .. code-block:: python - - # At the top-level of the module - some_str_key = StashKey[str]() - some_bool_key = StashKey[bool]() - - To store information: - - .. code-block:: python - - # Value type must match the key. - stash[some_str_key] = "value" - stash[some_bool_key] = True - - To retrieve the information: - - .. code-block:: python - - # The static type of some_str is str. - some_str = stash[some_str_key] - # The static type of some_bool is bool. - some_bool = stash[some_bool_key] - - .. versionadded:: 7.0 - """ - - __slots__ = ("_storage",) - - def __init__(self) -> None: - self._storage: dict[StashKey[Any], object] = {} - - def __setitem__(self, key: StashKey[T], value: T) -> None: - """Set a value for key.""" - self._storage[key] = value - - def __getitem__(self, key: StashKey[T]) -> T: - """Get the value for key. - - Raises ``KeyError`` if the key wasn't set before. - """ - return cast(T, self._storage[key]) - - def get(self, key: StashKey[T], default: D) -> T | D: - """Get the value for key, or return default if the key wasn't set - before.""" - try: - return self[key] - except KeyError: - return default - - def setdefault(self, key: StashKey[T], default: T) -> T: - """Return the value of key if already set, otherwise set the value - of key to default and return default.""" - try: - return self[key] - except KeyError: - self[key] = default - return default - - def __delitem__(self, key: StashKey[T]) -> None: - """Delete the value for key. - - Raises ``KeyError`` if the key wasn't set before. - """ - del self._storage[key] - - def __contains__(self, key: StashKey[T]) -> bool: - """Return whether key was set.""" - return key in self._storage - - def __len__(self) -> int: - """Return how many items exist in the stash.""" - return len(self._storage) diff --git a/.venv/lib/python3.12/site-packages/_pytest/stepwise.py b/.venv/lib/python3.12/site-packages/_pytest/stepwise.py deleted file mode 100644 index 8901540..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/stepwise.py +++ /dev/null @@ -1,209 +0,0 @@ -from __future__ import annotations - -import dataclasses -from datetime import datetime -from datetime import timedelta -from typing import Any -from typing import TYPE_CHECKING - -from _pytest import nodes -from _pytest.cacheprovider import Cache -from _pytest.config import Config -from _pytest.config.argparsing import Parser -from _pytest.main import Session -from _pytest.reports import TestReport - - -if TYPE_CHECKING: - from typing_extensions import Self - -STEPWISE_CACHE_DIR = "cache/stepwise" - - -def pytest_addoption(parser: Parser) -> None: - group = parser.getgroup("general") - group.addoption( - "--sw", - "--stepwise", - action="store_true", - default=False, - dest="stepwise", - help="Exit on test failure and continue from last failing test next time", - ) - group.addoption( - "--sw-skip", - "--stepwise-skip", - action="store_true", - default=False, - dest="stepwise_skip", - help="Ignore the first failing test but stop on the next failing test. " - "Implicitly enables --stepwise.", - ) - group.addoption( - "--sw-reset", - "--stepwise-reset", - action="store_true", - default=False, - dest="stepwise_reset", - help="Resets stepwise state, restarting the stepwise workflow. " - "Implicitly enables --stepwise.", - ) - - -def pytest_configure(config: Config) -> None: - # --stepwise-skip/--stepwise-reset implies stepwise. - if config.option.stepwise_skip or config.option.stepwise_reset: - config.option.stepwise = True - if config.getoption("stepwise"): - config.pluginmanager.register(StepwisePlugin(config), "stepwiseplugin") - - -def pytest_sessionfinish(session: Session) -> None: - if not session.config.getoption("stepwise"): - assert session.config.cache is not None - if hasattr(session.config, "workerinput"): - # Do not update cache if this process is a xdist worker to prevent - # race conditions (#10641). - return - - -@dataclasses.dataclass -class StepwiseCacheInfo: - # The nodeid of the last failed test. - last_failed: str | None - - # The number of tests in the last time --stepwise was run. - # We use this information as a simple way to invalidate the cache information, avoiding - # confusing behavior in case the cache is stale. - last_test_count: int | None - - # The date when the cache was last updated, for information purposes only. - last_cache_date_str: str - - @property - def last_cache_date(self) -> datetime: - return datetime.fromisoformat(self.last_cache_date_str) - - @classmethod - def empty(cls) -> Self: - return cls( - last_failed=None, - last_test_count=None, - last_cache_date_str=datetime.now().isoformat(), - ) - - def update_date_to_now(self) -> None: - self.last_cache_date_str = datetime.now().isoformat() - - -class StepwisePlugin: - def __init__(self, config: Config) -> None: - self.config = config - self.session: Session | None = None - self.report_status: list[str] = [] - assert config.cache is not None - self.cache: Cache = config.cache - self.skip: bool = config.getoption("stepwise_skip") - self.reset: bool = config.getoption("stepwise_reset") - self.cached_info = self._load_cached_info() - - def _load_cached_info(self) -> StepwiseCacheInfo: - cached_dict: dict[str, Any] | None = self.cache.get(STEPWISE_CACHE_DIR, None) - if cached_dict: - try: - return StepwiseCacheInfo( - cached_dict["last_failed"], - cached_dict["last_test_count"], - cached_dict["last_cache_date_str"], - ) - except (KeyError, TypeError) as e: - error = f"{type(e).__name__}: {e}" - self.report_status.append(f"error reading cache, discarding ({error})") - - # Cache not found or error during load, return a new cache. - return StepwiseCacheInfo.empty() - - def pytest_sessionstart(self, session: Session) -> None: - self.session = session - - def pytest_collection_modifyitems( - self, config: Config, items: list[nodes.Item] - ) -> None: - last_test_count = self.cached_info.last_test_count - self.cached_info.last_test_count = len(items) - - if self.reset: - self.report_status.append("resetting state, not skipping.") - self.cached_info.last_failed = None - return - - if not self.cached_info.last_failed: - self.report_status.append("no previously failed tests, not skipping.") - return - - if last_test_count is not None and last_test_count != len(items): - self.report_status.append( - f"test count changed, not skipping (now {len(items)} tests, previously {last_test_count})." - ) - self.cached_info.last_failed = None - return - - # Check all item nodes until we find a match on last failed. - failed_index = None - for index, item in enumerate(items): - if item.nodeid == self.cached_info.last_failed: - failed_index = index - break - - # If the previously failed test was not found among the test items, - # do not skip any tests. - if failed_index is None: - self.report_status.append("previously failed test not found, not skipping.") - else: - cache_age = datetime.now() - self.cached_info.last_cache_date - # Round up to avoid showing microseconds. - cache_age = timedelta(seconds=int(cache_age.total_seconds())) - self.report_status.append( - f"skipping {failed_index} already passed items (cache from {cache_age} ago," - f" use --sw-reset to discard)." - ) - deselected = items[:failed_index] - del items[:failed_index] - config.hook.pytest_deselected(items=deselected) - - def pytest_runtest_logreport(self, report: TestReport) -> None: - if report.failed: - if self.skip: - # Remove test from the failed ones (if it exists) and unset the skip option - # to make sure the following tests will not be skipped. - if report.nodeid == self.cached_info.last_failed: - self.cached_info.last_failed = None - - self.skip = False - else: - # Mark test as the last failing and interrupt the test session. - self.cached_info.last_failed = report.nodeid - assert self.session is not None - self.session.shouldstop = ( - "Test failed, continuing from this test next run." - ) - - else: - # If the test was actually run and did pass. - if report.when == "call": - # Remove test from the failed ones, if exists. - if report.nodeid == self.cached_info.last_failed: - self.cached_info.last_failed = None - - def pytest_report_collectionfinish(self) -> list[str] | None: - if self.config.get_verbosity() >= 0 and self.report_status: - return [f"stepwise: {x}" for x in self.report_status] - return None - - def pytest_sessionfinish(self) -> None: - if hasattr(self.config, "workerinput"): - # Do not update cache if this process is a xdist worker to prevent - # race conditions (#10641). - return - self.cached_info.update_date_to_now() - self.cache.set(STEPWISE_CACHE_DIR, dataclasses.asdict(self.cached_info)) diff --git a/.venv/lib/python3.12/site-packages/_pytest/subtests.py b/.venv/lib/python3.12/site-packages/_pytest/subtests.py deleted file mode 100644 index e0ceb27..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/subtests.py +++ /dev/null @@ -1,411 +0,0 @@ -"""Builtin plugin that adds subtests support.""" - -from __future__ import annotations - -from collections import defaultdict -from collections.abc import Callable -from collections.abc import Iterator -from collections.abc import Mapping -from contextlib import AbstractContextManager -from contextlib import contextmanager -from contextlib import ExitStack -from contextlib import nullcontext -import dataclasses -import time -from types import TracebackType -from typing import Any -from typing import TYPE_CHECKING - -import pluggy - -from _pytest._code import ExceptionInfo -from _pytest._io.saferepr import saferepr -from _pytest.capture import CaptureFixture -from _pytest.capture import FDCapture -from _pytest.capture import SysCapture -from _pytest.config import Config -from _pytest.config import hookimpl -from _pytest.config.argparsing import Parser -from _pytest.deprecated import check_ispytest -from _pytest.fixtures import fixture -from _pytest.fixtures import SubRequest -from _pytest.logging import catching_logs -from _pytest.logging import LogCaptureHandler -from _pytest.logging import LoggingPlugin -from _pytest.reports import TestReport -from _pytest.runner import CallInfo -from _pytest.runner import check_interactive_exception -from _pytest.runner import get_reraise_exceptions -from _pytest.stash import StashKey - - -if TYPE_CHECKING: - from typing_extensions import Self - - -def pytest_addoption(parser: Parser) -> None: - Config._add_verbosity_ini( - parser, - Config.VERBOSITY_SUBTESTS, - help=( - "Specify verbosity level for subtests. " - "Higher levels will generate output for passed subtests. Failed subtests are always reported." - ), - ) - - -@dataclasses.dataclass(frozen=True, slots=True, kw_only=True) -class SubtestContext: - """The values passed to Subtests.test() that are included in the test report.""" - - msg: str | None - kwargs: Mapping[str, Any] - - def _to_json(self) -> dict[str, Any]: - return dataclasses.asdict(self) - - @classmethod - def _from_json(cls, d: dict[str, Any]) -> Self: - return cls(msg=d["msg"], kwargs=d["kwargs"]) - - -@dataclasses.dataclass(init=False) -class SubtestReport(TestReport): - context: SubtestContext - - @property - def head_line(self) -> str: - _, _, domain = self.location - return f"{domain} {self._sub_test_description()}" - - def _sub_test_description(self) -> str: - parts = [] - if self.context.msg is not None: - parts.append(f"[{self.context.msg}]") - if self.context.kwargs: - params_desc = ", ".join( - f"{k}={saferepr(v)}" for (k, v) in self.context.kwargs.items() - ) - parts.append(f"({params_desc})") - return " ".join(parts) or "()" - - def _to_json(self) -> dict[str, Any]: - data = super()._to_json() - del data["context"] - data["_report_type"] = "SubTestReport" - data["_subtest.context"] = self.context._to_json() - return data - - @classmethod - def _from_json(cls, reportdict: dict[str, Any]) -> SubtestReport: - report = super()._from_json(reportdict) - report.context = SubtestContext._from_json(reportdict["_subtest.context"]) - return report - - @classmethod - def _new( - cls, - test_report: TestReport, - context: SubtestContext, - captured_output: Captured | None, - captured_logs: CapturedLogs | None, - ) -> Self: - result = super()._from_json(test_report._to_json()) - result.context = context - - if captured_output: - if captured_output.out: - result.sections.append(("Captured stdout call", captured_output.out)) - if captured_output.err: - result.sections.append(("Captured stderr call", captured_output.err)) - - if captured_logs and (log := captured_logs.handler.stream.getvalue()): - result.sections.append(("Captured log call", log)) - - return result - - -@fixture -def subtests(request: SubRequest) -> Subtests: - """Provides subtests functionality.""" - capmam = request.node.config.pluginmanager.get_plugin("capturemanager") - suspend_capture_ctx = ( - capmam.global_and_fixture_disabled if capmam is not None else nullcontext - ) - return Subtests(request.node.ihook, suspend_capture_ctx, request, _ispytest=True) - - -class Subtests: - """Subtests fixture, enables declaring subtests inside test functions via the :meth:`test` method.""" - - def __init__( - self, - ihook: pluggy.HookRelay, - suspend_capture_ctx: Callable[[], AbstractContextManager[None]], - request: SubRequest, - *, - _ispytest: bool = False, - ) -> None: - check_ispytest(_ispytest) - self._ihook = ihook - self._suspend_capture_ctx = suspend_capture_ctx - self._request = request - - def test( - self, - msg: str | None = None, - **kwargs: Any, - ) -> _SubTestContextManager: - """ - Context manager for subtests, capturing exceptions raised inside the subtest scope and - reporting assertion failures and errors individually. - - Usage - ----- - - .. code-block:: python - - def test(subtests): - for i in range(5): - with subtests.test("custom message", i=i): - assert i % 2 == 0 - - :param msg: - If given, the message will be shown in the test report in case of subtest failure. - - :param kwargs: - Arbitrary values that are also added to the subtest report. - """ - return _SubTestContextManager( - self._ihook, - msg, - kwargs, - request=self._request, - suspend_capture_ctx=self._suspend_capture_ctx, - config=self._request.config, - ) - - -@dataclasses.dataclass -class _SubTestContextManager: - """ - Context manager for subtests, capturing exceptions raised inside the subtest scope and handling - them through the pytest machinery. - """ - - # Note: initially the logic for this context manager was implemented directly - # in Subtests.test() as a @contextmanager, however, it is not possible to control the output fully when - # exiting from it due to an exception when in `--exitfirst` mode, so this was refactored into an - # explicit context manager class (pytest-dev/pytest-subtests#134). - - ihook: pluggy.HookRelay - msg: str | None - kwargs: dict[str, Any] - suspend_capture_ctx: Callable[[], AbstractContextManager[None]] - request: SubRequest - config: Config - - def __enter__(self) -> None: - __tracebackhide__ = True - - self._start = time.time() - self._precise_start = time.perf_counter() - self._exc_info = None - - self._exit_stack = ExitStack() - self._captured_output = self._exit_stack.enter_context( - capturing_output(self.request) - ) - self._captured_logs = self._exit_stack.enter_context( - capturing_logs(self.request) - ) - - def __exit__( - self, - exc_type: type[BaseException] | None, - exc_val: BaseException | None, - exc_tb: TracebackType | None, - ) -> bool: - __tracebackhide__ = True - if exc_val is not None: - exc_info = ExceptionInfo.from_exception(exc_val) - else: - exc_info = None - - self._exit_stack.close() - - precise_stop = time.perf_counter() - duration = precise_stop - self._precise_start - stop = time.time() - - call_info = CallInfo[None]( - None, - exc_info, - start=self._start, - stop=stop, - duration=duration, - when="call", - _ispytest=True, - ) - report = self.ihook.pytest_runtest_makereport( - item=self.request.node, call=call_info - ) - sub_report = SubtestReport._new( - report, - SubtestContext(msg=self.msg, kwargs=self.kwargs), - captured_output=self._captured_output, - captured_logs=self._captured_logs, - ) - - if sub_report.failed: - failed_subtests = self.config.stash[failed_subtests_key] - failed_subtests[self.request.node.nodeid] += 1 - - with self.suspend_capture_ctx(): - self.ihook.pytest_runtest_logreport(report=sub_report) - - if check_interactive_exception(call_info, sub_report): - self.ihook.pytest_exception_interact( - node=self.request.node, call=call_info, report=sub_report - ) - - if exc_val is not None: - if isinstance(exc_val, get_reraise_exceptions(self.config)): - return False - if self.request.session.shouldfail: - return False - return True - - -@contextmanager -def capturing_output(request: SubRequest) -> Iterator[Captured]: - option = request.config.getoption("capture", None) - - capman = request.config.pluginmanager.getplugin("capturemanager") - if getattr(capman, "_capture_fixture", None): - # capsys or capfd are active, subtest should not capture. - fixture = None - elif option == "sys": - fixture = CaptureFixture(SysCapture, request, _ispytest=True) - elif option == "fd": - fixture = CaptureFixture(FDCapture, request, _ispytest=True) - else: - fixture = None - - if fixture is not None: - fixture._start() - - captured = Captured() - try: - yield captured - finally: - if fixture is not None: - out, err = fixture.readouterr() - fixture.close() - captured.out = out - captured.err = err - - -@contextmanager -def capturing_logs( - request: SubRequest, -) -> Iterator[CapturedLogs | None]: - logging_plugin: LoggingPlugin | None = request.config.pluginmanager.getplugin( - "logging-plugin" - ) - if logging_plugin is None: - yield None - else: - handler = LogCaptureHandler() - handler.setFormatter(logging_plugin.formatter) - - captured_logs = CapturedLogs(handler) - with catching_logs(handler, level=logging_plugin.log_level): - yield captured_logs - - -@dataclasses.dataclass -class Captured: - out: str = "" - err: str = "" - - -@dataclasses.dataclass -class CapturedLogs: - handler: LogCaptureHandler - - -def pytest_report_to_serializable(report: TestReport) -> dict[str, Any] | None: - if isinstance(report, SubtestReport): - return report._to_json() - return None - - -def pytest_report_from_serializable(data: dict[str, Any]) -> SubtestReport | None: - if data.get("_report_type") == "SubTestReport": - return SubtestReport._from_json(data) - return None - - -# Dict of nodeid -> number of failed subtests. -# Used to fail top-level tests that passed but contain failed subtests. -failed_subtests_key = StashKey[defaultdict[str, int]]() - - -def pytest_configure(config: Config) -> None: - config.stash[failed_subtests_key] = defaultdict(lambda: 0) - - -@hookimpl(tryfirst=True) -def pytest_report_teststatus( - report: TestReport, - config: Config, -) -> tuple[str, str, str | Mapping[str, bool]] | None: - if report.when != "call": - return None - - quiet = config.get_verbosity(Config.VERBOSITY_SUBTESTS) == 0 - if isinstance(report, SubtestReport): - outcome = report.outcome - description = report._sub_test_description() - - if hasattr(report, "wasxfail"): - if quiet: - return "", "", "" - elif outcome == "skipped": - category = "xfailed" - short = "y" # x letter is used for regular xfail, y for subtest xfail - status = "SUBXFAIL" - # outcome == "passed" in an xfail is only possible via a @pytest.mark.xfail mark, which - # is not applicable to a subtest, which only handles pytest.xfail(). - else: # pragma: no cover - # This should not normally happen, unless some plugin is setting wasxfail without - # the correct outcome. Pytest expects the call outcome to be either skipped or - # passed in case of xfail. - # Let's pass this report to the next hook. - return None - return category, short, f"{status}{description}" - - if report.failed: - return outcome, "u", f"SUBFAILED{description}" - else: - if report.passed: - if quiet: - return "", "", "" - else: - return f"subtests {outcome}", "u", f"SUBPASSED{description}" - elif report.skipped: - if quiet: - return "", "", "" - else: - return outcome, "-", f"SUBSKIPPED{description}" - - else: - failed_subtests_count = config.stash[failed_subtests_key][report.nodeid] - # Top-level test, fail if it contains failed subtests and it has passed. - if report.passed and failed_subtests_count > 0: - report.outcome = "failed" - suffix = "s" if failed_subtests_count > 1 else "" - report.longrepr = f"contains {failed_subtests_count} failed subtest{suffix}" - - return None diff --git a/.venv/lib/python3.12/site-packages/_pytest/terminal.py b/.venv/lib/python3.12/site-packages/_pytest/terminal.py deleted file mode 100644 index e66e4f4..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/terminal.py +++ /dev/null @@ -1,1763 +0,0 @@ -# mypy: allow-untyped-defs -"""Terminal reporting of the full testing process. - -This is a good source for looking at the various reporting hooks. -""" - -from __future__ import annotations - -import argparse -from collections import Counter -from collections.abc import Callable -from collections.abc import Generator -from collections.abc import Mapping -from collections.abc import Sequence -import dataclasses -import datetime -from functools import partial -import inspect -from pathlib import Path -import platform -import sys -import textwrap -from typing import Any -from typing import ClassVar -from typing import final -from typing import Literal -from typing import NamedTuple -from typing import TextIO -from typing import TYPE_CHECKING -import warnings - -import pluggy - -from _pytest import compat -from _pytest import nodes -from _pytest import timing -from _pytest._code import ExceptionInfo -from _pytest._code.code import ExceptionRepr -from _pytest._io import TerminalWriter -from _pytest._io.wcwidth import wcswidth -import _pytest._version -from _pytest.compat import running_on_ci -from _pytest.config import _PluggyPlugin -from _pytest.config import Config -from _pytest.config import ExitCode -from _pytest.config import hookimpl -from _pytest.config.argparsing import Parser -from _pytest.nodes import Item -from _pytest.nodes import Node -from _pytest.pathlib import absolutepath -from _pytest.pathlib import bestrelpath -from _pytest.reports import BaseReport -from _pytest.reports import CollectReport -from _pytest.reports import TestReport - - -if TYPE_CHECKING: - from _pytest.main import Session - - -REPORT_COLLECTING_RESOLUTION = 0.5 - -KNOWN_TYPES = ( - "failed", - "passed", - "skipped", - "deselected", - "xfailed", - "xpassed", - "warnings", - "error", - "subtests passed", - "subtests failed", - "subtests skipped", -) - -_REPORTCHARS_DEFAULT = "fE" - - -class MoreQuietAction(argparse.Action): - """A modified copy of the argparse count action which counts down and updates - the legacy quiet attribute at the same time. - - Used to unify verbosity handling. - """ - - def __init__( - self, - option_strings: Sequence[str], - dest: str, - default: object = None, - required: bool = False, - help: str | None = None, - ) -> None: - super().__init__( - option_strings=option_strings, - dest=dest, - nargs=0, - default=default, - required=required, - help=help, - ) - - def __call__( - self, - parser: argparse.ArgumentParser, - namespace: argparse.Namespace, - values: str | Sequence[object] | None, - option_string: str | None = None, - ) -> None: - new_count = getattr(namespace, self.dest, 0) - 1 - setattr(namespace, self.dest, new_count) - # todo Deprecate config.quiet - namespace.quiet = getattr(namespace, "quiet", 0) + 1 - - -class TestShortLogReport(NamedTuple): - """Used to store the test status result category, shortletter and verbose word. - For example ``"rerun", "R", ("RERUN", {"yellow": True})``. - - :ivar category: - The class of result, for example ``“passed”``, ``“skipped”``, ``“error”``, or the empty string. - - :ivar letter: - The short letter shown as testing progresses, for example ``"."``, ``"s"``, ``"E"``, or the empty string. - - :ivar word: - Verbose word is shown as testing progresses in verbose mode, for example ``"PASSED"``, ``"SKIPPED"``, - ``"ERROR"``, or the empty string. - """ - - category: str - letter: str - word: str | tuple[str, Mapping[str, bool]] - - -def pytest_addoption(parser: Parser) -> None: - group = parser.getgroup("terminal reporting", "Reporting", after="general") - group._addoption( # private to use reserved lower-case short option - "-v", - "--verbose", - action="count", - default=0, - dest="verbose", - help="Increase verbosity", - ) - group.addoption( - "--no-header", - action="store_true", - default=False, - dest="no_header", - help="Disable header", - ) - group.addoption( - "--no-summary", - action="store_true", - default=False, - dest="no_summary", - help="Disable summary", - ) - group.addoption( - "--no-fold-skipped", - action="store_false", - dest="fold_skipped", - default=True, - help="Do not fold skipped tests in short summary.", - ) - group.addoption( - "--force-short-summary", - action="store_true", - dest="force_short_summary", - default=False, - help="Force condensed summary output regardless of verbosity level.", - ) - group._addoption( # private to use reserved lower-case short option - "-q", - "--quiet", - action=MoreQuietAction, - default=0, - dest="verbose", - help="Decrease verbosity", - ) - group.addoption( - "--verbosity", - dest="verbose", - type=int, - default=0, - help="Set verbosity. Default: 0.", - ) - group._addoption( # private to use reserved lower-case short option - "-r", - action="store", - dest="reportchars", - default=_REPORTCHARS_DEFAULT, - metavar="chars", - help="Show extra test summary info as specified by chars: (f)ailed, " - "(E)rror, (s)kipped, (x)failed, (X)passed, " - "(p)assed, (P)assed with output, (a)ll except passed (p/P), or (A)ll. " - "(w)arnings are enabled by default (see --disable-warnings), " - "'N' can be used to reset the list. (default: 'fE').", - ) - group.addoption( - "--disable-warnings", - "--disable-pytest-warnings", - default=False, - dest="disable_warnings", - action="store_true", - help="Disable warnings summary", - ) - group._addoption( # private to use reserved lower-case short option - "-l", - "--showlocals", - action="store_true", - dest="showlocals", - default=False, - help="Show locals in tracebacks (disabled by default)", - ) - group.addoption( - "--no-showlocals", - action="store_false", - dest="showlocals", - help="Hide locals in tracebacks (negate --showlocals passed through addopts)", - ) - group.addoption( - "--tb", - metavar="style", - action="store", - dest="tbstyle", - default="auto", - choices=["auto", "long", "short", "no", "line", "native"], - help="Traceback print mode (auto/long/short/line/native/no)", - ) - group.addoption( - "--xfail-tb", - action="store_true", - dest="xfail_tb", - default=False, - help="Show tracebacks for xfail (as long as --tb != no)", - ) - group.addoption( - "--show-capture", - action="store", - dest="showcapture", - choices=["no", "stdout", "stderr", "log", "all"], - default="all", - help="Controls how captured stdout/stderr/log is shown on failed tests. " - "Default: all.", - ) - group.addoption( - "--fulltrace", - "--full-trace", - action="store_true", - default=False, - help="Don't cut any tracebacks (default is to cut)", - ) - group.addoption( - "--color", - metavar="color", - action="store", - dest="color", - default="auto", - choices=["yes", "no", "auto"], - help="Color terminal output (yes/no/auto)", - ) - group.addoption( - "--code-highlight", - default="yes", - choices=["yes", "no"], - help="Whether code should be highlighted (only if --color is also enabled). " - "Default: yes.", - ) - - parser.addini( - "console_output_style", - help='Console output: "classic", or with additional progress information ' - '("progress" (percentage) | "count" | "progress-even-when-capture-no" (forces ' - "progress even when capture=no)", - default="progress", - ) - Config._add_verbosity_ini( - parser, - Config.VERBOSITY_TEST_CASES, - help=( - "Specify a verbosity level for test case execution, overriding the main level. " - "Higher levels will provide more detailed information about each test case executed." - ), - ) - - -def pytest_configure(config: Config) -> None: - reporter = TerminalReporter(config, sys.stdout) - config.pluginmanager.register(reporter, "terminalreporter") - if config.option.debug or config.option.traceconfig: - - def mywriter(tags, args): - msg = " ".join(map(str, args)) - reporter.write_line("[traceconfig] " + msg) - - config.trace.root.setprocessor("pytest:config", mywriter) - - # See terminalprogress.py. - # On Windows it's safe to load by default. - if sys.platform == "win32": - config.pluginmanager.import_plugin("terminalprogress") - - -def getreportopt(config: Config) -> str: - reportchars: str = config.option.reportchars - - old_aliases = {"F", "S"} - reportopts = "" - for char in reportchars: - if char in old_aliases: - char = char.lower() - if char == "a": - reportopts = "sxXEf" - elif char == "A": - reportopts = "PpsxXEf" - elif char == "N": - reportopts = "" - elif char not in reportopts: - reportopts += char - - if not config.option.disable_warnings and "w" not in reportopts: - reportopts = "w" + reportopts - elif config.option.disable_warnings and "w" in reportopts: - reportopts = reportopts.replace("w", "") - - return reportopts - - -@hookimpl(trylast=True) # after _pytest.runner -def pytest_report_teststatus(report: BaseReport) -> tuple[str, str, str]: - letter = "F" - if report.passed: - letter = "." - elif report.skipped: - letter = "s" - - outcome: str = report.outcome - if report.when in ("collect", "setup", "teardown") and outcome == "failed": - outcome = "error" - letter = "E" - - return outcome, letter, outcome.upper() - - -@dataclasses.dataclass -class WarningReport: - """Simple structure to hold warnings information captured by ``pytest_warning_recorded``. - - :ivar str message: - User friendly message about the warning. - :ivar str|None nodeid: - nodeid that generated the warning (see ``get_location``). - :ivar tuple fslocation: - File system location of the source of the warning (see ``get_location``). - """ - - message: str - nodeid: str | None = None - fslocation: tuple[str, int] | None = None - - count_towards_summary: ClassVar = True - - def get_location(self, config: Config) -> str | None: - """Return the more user-friendly information about the location of a warning, or None.""" - if self.nodeid: - return self.nodeid - if self.fslocation: - filename, linenum = self.fslocation - relpath = bestrelpath(config.invocation_params.dir, absolutepath(filename)) - return f"{relpath}:{linenum}" - return None - - -@final -class TerminalReporter: - def __init__(self, config: Config, file: TextIO | None = None) -> None: - import _pytest.config - - self.config = config - self._numcollected = 0 - self._session: Session | None = None - self._showfspath: bool | None = None - - self.stats: dict[str, list[Any]] = {} - self._main_color: str | None = None - self._known_types: list[str] | None = None - self.startpath = config.invocation_params.dir - if file is None: - file = sys.stdout - self._tw = _pytest.config.create_terminal_writer(config, file) - self._screen_width = self._tw.fullwidth - self.currentfspath: None | Path | str | int = None - self.reportchars = getreportopt(config) - self.foldskipped = config.option.fold_skipped - self.hasmarkup = self._tw.hasmarkup - # isatty should be a method but was wrongly implemented as a boolean. - # We use CallableBool here to support both. - self.isatty = compat.CallableBool(file.isatty()) - self._progress_nodeids_reported: set[str] = set() - self._timing_nodeids_reported: set[str] = set() - self._show_progress_info = self._determine_show_progress_info() - self._collect_report_last_write = timing.Instant() - self._already_displayed_warnings: int | None = None - self._keyboardinterrupt_memo: ExceptionRepr | None = None - - def _determine_show_progress_info( - self, - ) -> Literal["progress", "count", "times", False]: - """Return whether we should display progress information based on the current config.""" - # do not show progress if we are not capturing output (#3038) unless explicitly - # overridden by progress-even-when-capture-no - if ( - self.config.getoption("capture", "no") == "no" - and self.config.getini("console_output_style") - != "progress-even-when-capture-no" - ): - return False - # do not show progress if we are showing fixture setup/teardown - if self.config.getoption("setupshow", False): - return False - cfg: str = self.config.getini("console_output_style") - if cfg in {"progress", "progress-even-when-capture-no"}: - return "progress" - elif cfg == "count": - return "count" - elif cfg == "times": - return "times" - else: - return False - - @property - def verbosity(self) -> int: - verbosity: int = self.config.option.verbose - return verbosity - - @property - def showheader(self) -> bool: - return self.verbosity >= 0 - - @property - def no_header(self) -> bool: - return bool(self.config.option.no_header) - - @property - def no_summary(self) -> bool: - return bool(self.config.option.no_summary) - - @property - def showfspath(self) -> bool: - if self._showfspath is None: - return self.config.get_verbosity(Config.VERBOSITY_TEST_CASES) >= 0 - return self._showfspath - - @showfspath.setter - def showfspath(self, value: bool | None) -> None: - self._showfspath = value - - @property - def showlongtestinfo(self) -> bool: - return self.config.get_verbosity(Config.VERBOSITY_TEST_CASES) > 0 - - @property - def reported_progress(self) -> int: - """The amount of items reported in the progress so far. - - :meta private: - """ - return len(self._progress_nodeids_reported) - - def hasopt(self, char: str) -> bool: - char = {"xfailed": "x", "skipped": "s"}.get(char, char) - return char in self.reportchars - - def write_fspath_result(self, nodeid: str, res: str, **markup: bool) -> None: - fspath = self.config.rootpath / nodeid.split("::")[0] - if self.currentfspath is None or fspath != self.currentfspath: - if self.currentfspath is not None and self._show_progress_info: - self._write_progress_information_filling_space() - self.currentfspath = fspath - relfspath = bestrelpath(self.startpath, fspath) - self._tw.line() - self._tw.write(relfspath + " ") - self._tw.write(res, flush=True, **markup) - - def write_ensure_prefix(self, prefix: str, extra: str = "", **kwargs) -> None: - if self.currentfspath != prefix: - self._tw.line() - self.currentfspath = prefix - self._tw.write(prefix) - if extra: - self._tw.write(extra, **kwargs) - self.currentfspath = -2 - - def ensure_newline(self) -> None: - if self.currentfspath: - self._tw.line() - self.currentfspath = None - - def wrap_write( - self, - content: str, - *, - flush: bool = False, - margin: int = 8, - line_sep: str = "\n", - **markup: bool, - ) -> None: - """Wrap message with margin for progress info.""" - width_of_current_line = self._tw.width_of_current_line - wrapped = line_sep.join( - textwrap.wrap( - " " * width_of_current_line + content, - width=self._screen_width - margin, - drop_whitespace=True, - replace_whitespace=False, - ), - ) - wrapped = wrapped[width_of_current_line:] - self._tw.write(wrapped, flush=flush, **markup) - - def write(self, content: str, *, flush: bool = False, **markup: bool) -> None: - self._tw.write(content, flush=flush, **markup) - - def write_raw(self, content: str, *, flush: bool = False) -> None: - self._tw.write_raw(content, flush=flush) - - def flush(self) -> None: - self._tw.flush() - - def write_line(self, line: str | bytes, **markup: bool) -> None: - if not isinstance(line, str): - line = str(line, errors="replace") - self.ensure_newline() - self._tw.line(line, **markup) - - def rewrite(self, line: str, **markup: bool) -> None: - """Rewinds the terminal cursor to the beginning and writes the given line. - - :param erase: - If True, will also add spaces until the full terminal width to ensure - previous lines are properly erased. - - The rest of the keyword arguments are markup instructions. - """ - erase = markup.pop("erase", False) - if erase: - fill_count = self._tw.fullwidth - len(line) - 1 - fill = " " * fill_count - else: - fill = "" - line = str(line) - self._tw.write("\r" + line + fill, **markup) - - def write_sep( - self, - sep: str, - title: str | None = None, - fullwidth: int | None = None, - **markup: bool, - ) -> None: - self.ensure_newline() - self._tw.sep(sep, title, fullwidth, **markup) - - def section(self, title: str, sep: str = "=", **kw: bool) -> None: - self._tw.sep(sep, title, **kw) - - def line(self, msg: str, **kw: bool) -> None: - self._tw.line(msg, **kw) - - def _add_stats(self, category: str, items: Sequence[Any]) -> None: - set_main_color = category not in self.stats - self.stats.setdefault(category, []).extend(items) - if set_main_color: - self._set_main_color() - - def pytest_internalerror(self, excrepr: ExceptionRepr) -> bool: - for line in str(excrepr).split("\n"): - self.write_line("INTERNALERROR> " + line) - return True - - def pytest_warning_recorded( - self, - warning_message: warnings.WarningMessage, - nodeid: str, - ) -> None: - from _pytest.warnings import warning_record_to_str - - fslocation = warning_message.filename, warning_message.lineno - message = warning_record_to_str(warning_message) - - warning_report = WarningReport( - fslocation=fslocation, message=message, nodeid=nodeid - ) - self._add_stats("warnings", [warning_report]) - - def pytest_plugin_registered(self, plugin: _PluggyPlugin) -> None: - if self.config.option.traceconfig: - msg = f"PLUGIN registered: {plugin}" - # XXX This event may happen during setup/teardown time - # which unfortunately captures our output here - # which garbles our output if we use self.write_line. - self.write_line(msg) - - def pytest_deselected(self, items: Sequence[Item]) -> None: - self._add_stats("deselected", items) - - def pytest_runtest_logstart( - self, nodeid: str, location: tuple[str, int | None, str] - ) -> None: - fspath, lineno, domain = location - # Ensure that the path is printed before the - # 1st test of a module starts running. - if self.showlongtestinfo: - line = self._locationline(nodeid, fspath, lineno, domain) - self.write_ensure_prefix(line, "") - self.flush() - elif self.showfspath: - self.write_fspath_result(nodeid, "") - self.flush() - - def pytest_runtest_logreport(self, report: TestReport) -> None: - self._tests_ran = True - rep = report - - res = TestShortLogReport( - *self.config.hook.pytest_report_teststatus(report=rep, config=self.config) - ) - category, letter, word = res.category, res.letter, res.word - if not isinstance(word, tuple): - markup = None - else: - word, markup = word - self._add_stats(category, [rep]) - if not letter and not word: - # Probably passed setup/teardown. - return - if markup is None: - was_xfail = hasattr(report, "wasxfail") - if rep.passed and not was_xfail: - markup = {"green": True} - elif rep.passed and was_xfail: - markup = {"yellow": True} - elif rep.failed: - markup = {"red": True} - elif rep.skipped: - markup = {"yellow": True} - else: - markup = {} - self._progress_nodeids_reported.add(rep.nodeid) - if self.config.get_verbosity(Config.VERBOSITY_TEST_CASES) <= 0: - self._tw.write(letter, **markup) - # When running in xdist, the logreport and logfinish of multiple - # items are interspersed, e.g. `logreport`, `logreport`, - # `logfinish`, `logfinish`. To avoid the "past edge" calculation - # from getting confused and overflowing (#7166), do the past edge - # printing here and not in logfinish, except for the 100% which - # should only be printed after all teardowns are finished. - if self._show_progress_info and not self._is_last_item: - self._write_progress_information_if_past_edge() - else: - line = self._locationline(rep.nodeid, *rep.location) - running_xdist = hasattr(rep, "node") - if not running_xdist: - self.write_ensure_prefix(line, word, **markup) - if rep.skipped or hasattr(report, "wasxfail"): - reason = _get_raw_skip_reason(rep) - if self.config.get_verbosity(Config.VERBOSITY_TEST_CASES) < 2: - available_width = ( - (self._tw.fullwidth - self._tw.width_of_current_line) - - len(" [100%]") - - 1 - ) - formatted_reason = _format_trimmed( - " ({})", reason, available_width - ) - else: - formatted_reason = f" ({reason})" - - if reason and formatted_reason is not None: - self.wrap_write(formatted_reason) - if self._show_progress_info: - self._write_progress_information_filling_space() - else: - self.ensure_newline() - self._tw.write(f"[{rep.node.gateway.id}]") - if self._show_progress_info: - self._tw.write( - self._get_progress_information_message() + " ", cyan=True - ) - else: - self._tw.write(" ") - self._tw.write(word, **markup) - self._tw.write(" " + line) - self.currentfspath = -2 - self.flush() - - @property - def _is_last_item(self) -> bool: - assert self._session is not None - return self.reported_progress == self._session.testscollected - - @hookimpl(wrapper=True) - def pytest_runtestloop(self) -> Generator[None, object, object]: - result = yield - - # Write the final/100% progress -- deferred until the loop is complete. - if ( - self.config.get_verbosity(Config.VERBOSITY_TEST_CASES) <= 0 - and self._show_progress_info - and self.reported_progress - ): - self._write_progress_information_filling_space() - - return result - - def _get_progress_information_message(self) -> str: - assert self._session - collected = self._session.testscollected - if self._show_progress_info == "count": - if collected: - progress = self.reported_progress - counter_format = f"{{:{len(str(collected))}d}}" - format_string = f" [{counter_format}/{{}}]" - return format_string.format(progress, collected) - return f" [ {collected} / {collected} ]" - if self._show_progress_info == "times": - if not collected: - return "" - all_reports = ( - self._get_reports_to_display("passed") - + self._get_reports_to_display("xpassed") - + self._get_reports_to_display("failed") - + self._get_reports_to_display("xfailed") - + self._get_reports_to_display("skipped") - + self._get_reports_to_display("error") - + self._get_reports_to_display("") - ) - current_location = all_reports[-1].location[0] - not_reported = [ - r for r in all_reports if r.nodeid not in self._timing_nodeids_reported - ] - tests_in_module = sum( - i.location[0] == current_location for i in self._session.items - ) - tests_completed = sum( - r.when == "setup" - for r in not_reported - if r.location[0] == current_location - ) - last_in_module = tests_completed == tests_in_module - if self.showlongtestinfo or last_in_module: - self._timing_nodeids_reported.update(r.nodeid for r in not_reported) - return format_node_duration( - sum(r.duration for r in not_reported if isinstance(r, TestReport)) - ) - return "" - if collected: - return f" [{self.reported_progress * 100 // collected:3d}%]" - return " [100%]" - - def _write_progress_information_if_past_edge(self) -> None: - w = self._width_of_current_line - if self._show_progress_info == "count": - assert self._session - num_tests = self._session.testscollected - progress_length = len(f" [{num_tests}/{num_tests}]") - elif self._show_progress_info == "times": - progress_length = len(" 99h 59m") - else: - progress_length = len(" [100%]") - past_edge = w + progress_length + 1 >= self._screen_width - if past_edge: - main_color, _ = self._get_main_color() - msg = self._get_progress_information_message() - self._tw.write(msg + "\n", **{main_color: True}) - - def _write_progress_information_filling_space(self) -> None: - color, _ = self._get_main_color() - msg = self._get_progress_information_message() - w = self._width_of_current_line - fill = self._tw.fullwidth - w - 1 - self.write(msg.rjust(fill), flush=True, **{color: True}) - - @property - def _width_of_current_line(self) -> int: - """Return the width of the current line.""" - return self._tw.width_of_current_line - - def pytest_collection(self) -> None: - if self.isatty(): - if self.config.option.verbose >= 0: - self.write("collecting ... ", flush=True, bold=True) - elif self.config.option.verbose >= 1: - self.write("collecting ... ", flush=True, bold=True) - - def pytest_collectreport(self, report: CollectReport) -> None: - if report.failed: - self._add_stats("error", [report]) - elif report.skipped: - self._add_stats("skipped", [report]) - items = [x for x in report.result if isinstance(x, Item)] - self._numcollected += len(items) - if self.isatty(): - self.report_collect() - - def report_collect(self, final: bool = False) -> None: - if self.config.option.verbose < 0: - return - - if not final: - # Only write the "collecting" report every `REPORT_COLLECTING_RESOLUTION`. - if ( - self._collect_report_last_write.elapsed().seconds - < REPORT_COLLECTING_RESOLUTION - ): - return - self._collect_report_last_write = timing.Instant() - - errors = len(self.stats.get("error", [])) - skipped = len(self.stats.get("skipped", [])) - deselected = len(self.stats.get("deselected", [])) - selected = self._numcollected - deselected - line = "collected " if final else "collecting " - line += ( - str(self._numcollected) + " item" + ("" if self._numcollected == 1 else "s") - ) - if errors: - line += f" / {errors} error{'s' if errors != 1 else ''}" - if deselected: - line += f" / {deselected} deselected" - if skipped: - line += f" / {skipped} skipped" - if self._numcollected > selected: - line += f" / {selected} selected" - if self.isatty(): - self.rewrite(line, bold=True, erase=True) - if final: - self.write("\n") - else: - self.write_line(line) - - @hookimpl(trylast=True) - def pytest_sessionstart(self, session: Session) -> None: - self._session = session - self._session_start = timing.Instant() - if not self.showheader: - return - self.write_sep("=", "test session starts", bold=True) - verinfo = platform.python_version() - if not self.no_header: - msg = f"platform {sys.platform} -- Python {verinfo}" - pypy_version_info = getattr(sys, "pypy_version_info", None) - if pypy_version_info: - verinfo = ".".join(map(str, pypy_version_info[:3])) - msg += f"[pypy-{verinfo}-{pypy_version_info[3]}]" - msg += f", pytest-{_pytest._version.version}, pluggy-{pluggy.__version__}" - if ( - self.verbosity > 0 - or self.config.option.debug - or getattr(self.config.option, "pastebin", None) - ): - msg += " -- " + str(sys.executable) - self.write_line(msg) - lines = self.config.hook.pytest_report_header( - config=self.config, start_path=self.startpath - ) - self._write_report_lines_from_hooks(lines) - - def _write_report_lines_from_hooks( - self, lines: Sequence[str | Sequence[str]] - ) -> None: - for line_or_lines in reversed(lines): - if isinstance(line_or_lines, str): - self.write_line(line_or_lines) - else: - for line in line_or_lines: - self.write_line(line) - - def pytest_report_header(self, config: Config) -> list[str]: - result = [f"rootdir: {config.rootpath}"] - - if config.inipath: - warning = "" - if config._ignored_config_files: - warning = f" (WARNING: ignoring pytest config in {', '.join(config._ignored_config_files)}!)" - result.append( - "configfile: " + bestrelpath(config.rootpath, config.inipath) + warning - ) - - if config.args_source == Config.ArgsSource.TESTPATHS: - testpaths: list[str] = config.getini("testpaths") - result.append("testpaths: {}".format(", ".join(testpaths))) - - plugininfo = config.pluginmanager.list_plugin_distinfo() - if plugininfo: - result.append( - "plugins: {}".format(", ".join(_plugin_nameversions(plugininfo))) - ) - return result - - def pytest_collection_finish(self, session: Session) -> None: - self.report_collect(True) - - lines = self.config.hook.pytest_report_collectionfinish( - config=self.config, - start_path=self.startpath, - items=session.items, - ) - self._write_report_lines_from_hooks(lines) - - if self.config.getoption("collectonly"): - if session.items: - if self.config.option.verbose > -1: - self._tw.line("") - self._printcollecteditems(session.items) - - failed = self.stats.get("failed") - if failed: - self._tw.sep("!", "collection failures") - for rep in failed: - rep.toterminal(self._tw) - - def _printcollecteditems(self, items: Sequence[Item]) -> None: - test_cases_verbosity = self.config.get_verbosity(Config.VERBOSITY_TEST_CASES) - if test_cases_verbosity < 0: - if test_cases_verbosity < -1: - counts = Counter(item.nodeid.split("::", 1)[0] for item in items) - for name, count in sorted(counts.items()): - self._tw.line(f"{name}: {count}") - else: - for item in items: - self._tw.line(item.nodeid) - return - stack: list[Node] = [] - indent = "" - for item in items: - needed_collectors = item.listchain()[1:] # strip root node - while stack: - if stack == needed_collectors[: len(stack)]: - break - stack.pop() - for col in needed_collectors[len(stack) :]: - stack.append(col) - indent = (len(stack) - 1) * " " - self._tw.line(f"{indent}{col}") - if test_cases_verbosity >= 1: - obj = getattr(col, "obj", None) - doc = inspect.getdoc(obj) if obj else None - if doc: - for line in doc.splitlines(): - self._tw.line("{}{}".format(indent + " ", line)) - - @hookimpl(wrapper=True) - def pytest_sessionfinish( - self, session: Session, exitstatus: int | ExitCode - ) -> Generator[None]: - result = yield - self._tw.line("") - summary_exit_codes = ( - ExitCode.OK, - ExitCode.TESTS_FAILED, - ExitCode.INTERRUPTED, - ExitCode.USAGE_ERROR, - ExitCode.NO_TESTS_COLLECTED, - ) - if exitstatus in summary_exit_codes and not self.no_summary: - self.config.hook.pytest_terminal_summary( - terminalreporter=self, exitstatus=exitstatus, config=self.config - ) - if session.shouldfail: - self.write_sep("!", str(session.shouldfail), red=True) - if exitstatus == ExitCode.INTERRUPTED: - self._report_keyboardinterrupt() - self._keyboardinterrupt_memo = None - elif session.shouldstop: - self.write_sep("!", str(session.shouldstop), red=True) - self.summary_stats() - return result - - @hookimpl(wrapper=True) - def pytest_terminal_summary(self) -> Generator[None]: - self.summary_errors() - self.summary_failures() - self.summary_xfailures() - self.summary_warnings() - self.summary_passes() - self.summary_xpasses() - try: - return (yield) - finally: - self.short_test_summary() - # Display any extra warnings from teardown here (if any). - self.summary_warnings() - - def pytest_keyboard_interrupt(self, excinfo: ExceptionInfo[BaseException]) -> None: - self._keyboardinterrupt_memo = excinfo.getrepr(funcargs=True) - - def pytest_unconfigure(self) -> None: - if self._keyboardinterrupt_memo is not None: - self._report_keyboardinterrupt() - - def _report_keyboardinterrupt(self) -> None: - excrepr = self._keyboardinterrupt_memo - assert excrepr is not None - assert excrepr.reprcrash is not None - msg = excrepr.reprcrash.message - self.write_sep("!", msg) - if "KeyboardInterrupt" in msg: - if self.config.option.fulltrace: - excrepr.toterminal(self._tw) - else: - excrepr.reprcrash.toterminal(self._tw) - self._tw.line( - "(to show a full traceback on KeyboardInterrupt use --full-trace)", - yellow=True, - ) - - def _locationline( - self, nodeid: str, fspath: str, lineno: int | None, domain: str - ) -> str: - def mkrel(nodeid: str) -> str: - line = self.config.cwd_relative_nodeid(nodeid) - if domain and line.endswith(domain): - line = line[: -len(domain)] - values = domain.split("[") - values[0] = values[0].replace(".", "::") # don't replace '.' in params - line += "[".join(values) - return line - - # fspath comes from testid which has a "/"-normalized path. - if fspath: - res = mkrel(nodeid) - if self.verbosity >= 2 and nodeid.split("::")[0] != fspath.replace( - "\\", nodes.SEP - ): - res += " <- " + bestrelpath(self.startpath, Path(fspath)) - else: - res = "[location]" - return res + " " - - def _getfailureheadline(self, rep): - head_line = rep.head_line - if head_line: - return head_line - return "test session" # XXX? - - def _getcrashline(self, rep): - try: - return str(rep.longrepr.reprcrash) - except AttributeError: - try: - return str(rep.longrepr)[:50] - except AttributeError: - return "" - - # - # Summaries for sessionfinish. - # - def getreports(self, name: str): - return [x for x in self.stats.get(name, ()) if not hasattr(x, "_pdbshown")] - - def summary_warnings(self) -> None: - if self.hasopt("w"): - all_warnings: list[WarningReport] | None = self.stats.get("warnings") - if not all_warnings: - return - - final = self._already_displayed_warnings is not None - if final: - warning_reports = all_warnings[self._already_displayed_warnings :] - else: - warning_reports = all_warnings - self._already_displayed_warnings = len(warning_reports) - if not warning_reports: - return - - reports_grouped_by_message: dict[str, list[WarningReport]] = {} - for wr in warning_reports: - reports_grouped_by_message.setdefault(wr.message, []).append(wr) - - def collapsed_location_report(reports: list[WarningReport]) -> str: - locations = [] - for w in reports: - location = w.get_location(self.config) - if location: - locations.append(location) - - if len(locations) < 10: - return "\n".join(map(str, locations)) - - counts_by_filename = Counter( - str(loc).split("::", 1)[0] for loc in locations - ) - return "\n".join( - "{}: {} warning{}".format(k, v, "s" if v > 1 else "") - for k, v in counts_by_filename.items() - ) - - title = "warnings summary (final)" if final else "warnings summary" - self.write_sep("=", title, yellow=True, bold=False) - for message, message_reports in reports_grouped_by_message.items(): - maybe_location = collapsed_location_report(message_reports) - if maybe_location: - self._tw.line(maybe_location) - lines = message.splitlines() - indented = "\n".join(" " + x for x in lines) - message = indented.rstrip() - else: - message = message.rstrip() - self._tw.line(message) - self._tw.line() - self._tw.line( - "-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html" - ) - - def summary_passes(self) -> None: - self.summary_passes_combined("passed", "PASSES", "P") - - def summary_xpasses(self) -> None: - self.summary_passes_combined("xpassed", "XPASSES", "X") - - def summary_passes_combined( - self, which_reports: str, sep_title: str, needed_opt: str - ) -> None: - if self.config.option.tbstyle != "no": - if self.hasopt(needed_opt): - reports: list[TestReport] = self.getreports(which_reports) - if not reports: - return - self.write_sep("=", sep_title) - for rep in reports: - if rep.sections: - msg = self._getfailureheadline(rep) - self.write_sep("_", msg, green=True, bold=True) - self._outrep_summary(rep) - self._handle_teardown_sections(rep.nodeid) - - def _get_teardown_reports(self, nodeid: str) -> list[TestReport]: - reports = self.getreports("") - return [ - report - for report in reports - if report.when == "teardown" and report.nodeid == nodeid - ] - - def _handle_teardown_sections(self, nodeid: str) -> None: - for report in self._get_teardown_reports(nodeid): - self.print_teardown_sections(report) - - def print_teardown_sections(self, rep: TestReport) -> None: - showcapture = self.config.option.showcapture - if showcapture == "no": - return - for secname, content in rep.sections: - if showcapture != "all" and showcapture not in secname: - continue - if "teardown" in secname: - self._tw.sep("-", secname) - if content[-1:] == "\n": - content = content[:-1] - self._tw.line(content) - - def summary_failures(self) -> None: - style = self.config.option.tbstyle - self.summary_failures_combined("failed", "FAILURES", style=style) - - def summary_xfailures(self) -> None: - show_tb = self.config.option.xfail_tb - style = self.config.option.tbstyle if show_tb else "no" - self.summary_failures_combined("xfailed", "XFAILURES", style=style) - - def summary_failures_combined( - self, - which_reports: str, - sep_title: str, - *, - style: str, - needed_opt: str | None = None, - ) -> None: - if style != "no": - if not needed_opt or self.hasopt(needed_opt): - reports: list[BaseReport] = self.getreports(which_reports) - if not reports: - return - self.write_sep("=", sep_title) - if style == "line": - for rep in reports: - line = self._getcrashline(rep) - self._outrep_summary(rep) - self.write_line(line) - else: - for rep in reports: - msg = self._getfailureheadline(rep) - self.write_sep("_", msg, red=True, bold=True) - self._outrep_summary(rep) - self._handle_teardown_sections(rep.nodeid) - - def summary_errors(self) -> None: - if self.config.option.tbstyle != "no": - reports: list[BaseReport] = self.getreports("error") - if not reports: - return - self.write_sep("=", "ERRORS") - for rep in self.stats["error"]: - msg = self._getfailureheadline(rep) - if rep.when == "collect": - msg = "ERROR collecting " + msg - else: - msg = f"ERROR at {rep.when} of {msg}" - self.write_sep("_", msg, red=True, bold=True) - self._outrep_summary(rep) - - def _outrep_summary(self, rep: BaseReport) -> None: - rep.toterminal(self._tw) - showcapture = self.config.option.showcapture - if showcapture == "no": - return - for secname, content in rep.sections: - if showcapture != "all" and showcapture not in secname: - continue - self._tw.sep("-", secname) - if content[-1:] == "\n": - content = content[:-1] - self._tw.line(content) - - def summary_stats(self) -> None: - if self.verbosity < -1: - return - - session_duration = self._session_start.elapsed() - (parts, main_color) = self.build_summary_stats_line() - line_parts = [] - - display_sep = self.verbosity >= 0 - if display_sep: - fullwidth = self._tw.fullwidth - for text, markup in parts: - with_markup = self._tw.markup(text, **markup) - if display_sep: - fullwidth += len(with_markup) - len(text) - line_parts.append(with_markup) - msg = ", ".join(line_parts) - - main_markup = {main_color: True} - duration = f" in {format_session_duration(session_duration.seconds)}" - duration_with_markup = self._tw.markup(duration, **main_markup) - if display_sep: - fullwidth += len(duration_with_markup) - len(duration) - msg += duration_with_markup - - if display_sep: - markup_for_end_sep = self._tw.markup("", **main_markup) - if markup_for_end_sep.endswith("\x1b[0m"): - markup_for_end_sep = markup_for_end_sep[:-4] - fullwidth += len(markup_for_end_sep) - msg += markup_for_end_sep - - if display_sep: - self.write_sep("=", msg, fullwidth=fullwidth, **main_markup) - else: - self.write_line(msg, **main_markup) - - def short_test_summary(self) -> None: - if not self.reportchars: - return - - def show_simple(lines: list[str], *, stat: str) -> None: - failed = self.stats.get(stat, []) - if not failed: - return - config = self.config - for rep in failed: - color = _color_for_type.get(stat, _color_for_type_default) - line = _get_line_with_reprcrash_message( - config, rep, self._tw, {color: True} - ) - lines.append(line) - - def show_xfailed(lines: list[str]) -> None: - xfailed = self.stats.get("xfailed", []) - for rep in xfailed: - verbose_word, verbose_markup = rep._get_verbose_word_with_markup( - self.config, {_color_for_type["warnings"]: True} - ) - markup_word = self._tw.markup(verbose_word, **verbose_markup) - nodeid = _get_node_id_with_markup(self._tw, self.config, rep) - line = f"{markup_word} {nodeid}" - reason = rep.wasxfail - if reason: - line += " - " + str(reason) - - lines.append(line) - - def show_xpassed(lines: list[str]) -> None: - xpassed = self.stats.get("xpassed", []) - for rep in xpassed: - verbose_word, verbose_markup = rep._get_verbose_word_with_markup( - self.config, {_color_for_type["warnings"]: True} - ) - markup_word = self._tw.markup(verbose_word, **verbose_markup) - nodeid = _get_node_id_with_markup(self._tw, self.config, rep) - line = f"{markup_word} {nodeid}" - reason = rep.wasxfail - if reason: - line += " - " + str(reason) - lines.append(line) - - def show_skipped_folded(lines: list[str]) -> None: - skipped: list[CollectReport] = self.stats.get("skipped", []) - fskips = _folded_skips(self.startpath, skipped) if skipped else [] - if not fskips: - return - verbose_word, verbose_markup = skipped[0]._get_verbose_word_with_markup( - self.config, {_color_for_type["warnings"]: True} - ) - markup_word = self._tw.markup(verbose_word, **verbose_markup) - prefix = "Skipped: " - for num, fspath, lineno, reason in fskips: - if reason.startswith(prefix): - reason = reason[len(prefix) :] - if lineno is not None: - lines.append(f"{markup_word} [{num}] {fspath}:{lineno}: {reason}") - else: - lines.append(f"{markup_word} [{num}] {fspath}: {reason}") - - def show_skipped_unfolded(lines: list[str]) -> None: - skipped: list[CollectReport] = self.stats.get("skipped", []) - - for rep in skipped: - assert rep.longrepr is not None - assert isinstance(rep.longrepr, tuple), (rep, rep.longrepr) - assert len(rep.longrepr) == 3, (rep, rep.longrepr) - - verbose_word, verbose_markup = rep._get_verbose_word_with_markup( - self.config, {_color_for_type["warnings"]: True} - ) - markup_word = self._tw.markup(verbose_word, **verbose_markup) - nodeid = _get_node_id_with_markup(self._tw, self.config, rep) - line = f"{markup_word} {nodeid}" - reason = rep.longrepr[2] - if reason: - line += " - " + str(reason) - lines.append(line) - - def show_skipped(lines: list[str]) -> None: - if self.foldskipped: - show_skipped_folded(lines) - else: - show_skipped_unfolded(lines) - - REPORTCHAR_ACTIONS: Mapping[str, Callable[[list[str]], None]] = { - "x": show_xfailed, - "X": show_xpassed, - "f": partial(show_simple, stat="failed"), - "s": show_skipped, - "p": partial(show_simple, stat="passed"), - "E": partial(show_simple, stat="error"), - } - - lines: list[str] = [] - for char in self.reportchars: - action = REPORTCHAR_ACTIONS.get(char) - if action: # skipping e.g. "P" (passed with output) here. - action(lines) - - if lines: - self.write_sep("=", "short test summary info", cyan=True, bold=True) - for line in lines: - self.write_line(line) - - def _get_main_color(self) -> tuple[str, list[str]]: - if self._main_color is None or self._known_types is None or self._is_last_item: - self._set_main_color() - assert self._main_color - assert self._known_types - return self._main_color, self._known_types - - def _determine_main_color(self, unknown_type_seen: bool) -> str: - stats = self.stats - if "failed" in stats or "error" in stats: - main_color = "red" - elif "warnings" in stats or "xpassed" in stats or unknown_type_seen: - main_color = "yellow" - elif "passed" in stats or not self._is_last_item: - main_color = "green" - else: - main_color = "yellow" - return main_color - - def _set_main_color(self) -> None: - unknown_types: list[str] = [] - for found_type in self.stats: - if found_type: # setup/teardown reports have an empty key, ignore them - if found_type not in KNOWN_TYPES and found_type not in unknown_types: - unknown_types.append(found_type) - self._known_types = list(KNOWN_TYPES) + unknown_types - self._main_color = self._determine_main_color(bool(unknown_types)) - - def build_summary_stats_line(self) -> tuple[list[tuple[str, dict[str, bool]]], str]: - """ - Build the parts used in the last summary stats line. - - The summary stats line is the line shown at the end, "=== 12 passed, 2 errors in Xs===". - - This function builds a list of the "parts" that make up for the text in that line, in - the example above it would be:: - - [ - ("12 passed", {"green": True}), - ("2 errors", {"red": True} - ] - - That last dict for each line is a "markup dictionary", used by TerminalWriter to - color output. - - The final color of the line is also determined by this function, and is the second - element of the returned tuple. - """ - if self.config.getoption("collectonly"): - return self._build_collect_only_summary_stats_line() - else: - return self._build_normal_summary_stats_line() - - def _get_reports_to_display(self, key: str) -> list[Any]: - """Get test/collection reports for the given status key, such as `passed` or `error`.""" - reports = self.stats.get(key, []) - return [x for x in reports if getattr(x, "count_towards_summary", True)] - - def _build_normal_summary_stats_line( - self, - ) -> tuple[list[tuple[str, dict[str, bool]]], str]: - main_color, known_types = self._get_main_color() - parts = [] - - for key in known_types: - reports = self._get_reports_to_display(key) - if reports: - count = len(reports) - color = _color_for_type.get(key, _color_for_type_default) - markup = {color: True, "bold": color == main_color} - parts.append(("%d %s" % pluralize(count, key), markup)) # noqa: UP031 - - if not parts: - parts = [("no tests ran", {_color_for_type_default: True})] - - return parts, main_color - - def _build_collect_only_summary_stats_line( - self, - ) -> tuple[list[tuple[str, dict[str, bool]]], str]: - deselected = len(self._get_reports_to_display("deselected")) - errors = len(self._get_reports_to_display("error")) - - if self._numcollected == 0: - parts = [("no tests collected", {"yellow": True})] - main_color = "yellow" - - elif deselected == 0: - main_color = "green" - collected_output = "%d %s collected" % pluralize(self._numcollected, "test") # noqa: UP031 - parts = [(collected_output, {main_color: True})] - else: - all_tests_were_deselected = self._numcollected == deselected - if all_tests_were_deselected: - main_color = "yellow" - collected_output = f"no tests collected ({deselected} deselected)" - else: - main_color = "green" - selected = self._numcollected - deselected - collected_output = f"{selected}/{self._numcollected} tests collected ({deselected} deselected)" - - parts = [(collected_output, {main_color: True})] - - if errors: - main_color = _color_for_type["error"] - parts += [("%d %s" % pluralize(errors, "error"), {main_color: True})] # noqa: UP031 - - return parts, main_color - - -def _get_node_id_with_markup(tw: TerminalWriter, config: Config, rep: BaseReport): - nodeid = config.cwd_relative_nodeid(rep.nodeid) - path, *parts = nodeid.split("::") - if parts: - parts_markup = tw.markup("::".join(parts), bold=True) - return path + "::" + parts_markup - else: - return path - - -def _format_trimmed(format: str, msg: str, available_width: int) -> str | None: - """Format msg into format, ellipsizing it if doesn't fit in available_width. - - Returns None if even the ellipsis can't fit. - """ - # Only use the first line. - i = msg.find("\n") - if i != -1: - msg = msg[:i] - - ellipsis = "..." - format_width = wcswidth(format.format("")) - if format_width + len(ellipsis) > available_width: - return None - - if format_width + wcswidth(msg) > available_width: - available_width -= len(ellipsis) - msg = msg[:available_width] - while format_width + wcswidth(msg) > available_width: - msg = msg[:-1] - msg += ellipsis - - return format.format(msg) - - -def _get_line_with_reprcrash_message( - config: Config, rep: BaseReport, tw: TerminalWriter, word_markup: dict[str, bool] -) -> str: - """Get summary line for a report, trying to add reprcrash message.""" - verbose_word, verbose_markup = rep._get_verbose_word_with_markup( - config, word_markup - ) - word = tw.markup(verbose_word, **verbose_markup) - node = _get_node_id_with_markup(tw, config, rep) - - line = f"{word} {node}" - line_width = wcswidth(line) - - msg: str | None - try: - if isinstance(rep.longrepr, str): - msg = rep.longrepr - else: - # Type ignored intentionally -- possible AttributeError expected. - msg = rep.longrepr.reprcrash.message # type: ignore[union-attr] - except AttributeError: - pass - else: - if ( - running_on_ci() or config.option.verbose >= 2 - ) and not config.option.force_short_summary: - msg = f" - {msg}" - else: - available_width = tw.fullwidth - line_width - msg = _format_trimmed(" - {}", msg, available_width) - if msg is not None: - line += msg - - return line - - -def _folded_skips( - startpath: Path, - skipped: Sequence[CollectReport], -) -> list[tuple[int, str, int | None, str]]: - d: dict[tuple[str, int | None, str], list[CollectReport]] = {} - for event in skipped: - assert event.longrepr is not None - assert isinstance(event.longrepr, tuple), (event, event.longrepr) - assert len(event.longrepr) == 3, (event, event.longrepr) - fspath, lineno, reason = event.longrepr - # For consistency, report all fspaths in relative form. - fspath = bestrelpath(startpath, Path(fspath)) - keywords = getattr(event, "keywords", {}) - # Folding reports with global pytestmark variable. - # This is a workaround, because for now we cannot identify the scope of a skip marker - # TODO: Revisit after marks scope would be fixed. - if ( - event.when == "setup" - and "skip" in keywords - and "pytestmark" not in keywords - ): - key: tuple[str, int | None, str] = (fspath, None, reason) - else: - key = (fspath, lineno, reason) - d.setdefault(key, []).append(event) - values: list[tuple[int, str, int | None, str]] = [] - for key, events in d.items(): - values.append((len(events), *key)) - return values - - -_color_for_type = { - "failed": "red", - "error": "red", - "warnings": "yellow", - "passed": "green", - "subtests passed": "green", - "subtests failed": "red", -} -_color_for_type_default = "yellow" - - -def pluralize(count: int, noun: str) -> tuple[int, str]: - # No need to pluralize words such as `failed` or `passed`. - if noun not in ["error", "warnings", "test"]: - return count, noun - - # The `warnings` key is plural. To avoid API breakage, we keep it that way but - # set it to singular here so we can determine plurality in the same way as we do - # for `error`. - noun = noun.replace("warnings", "warning") - - return count, noun + "s" if count != 1 else noun - - -def _plugin_nameversions(plugininfo) -> list[str]: - values: list[str] = [] - for plugin, dist in plugininfo: - # Gets us name and version! - name = f"{dist.project_name}-{dist.version}" - # Questionable convenience, but it keeps things short. - if name.startswith("pytest-"): - name = name[7:] - # We decided to print python package names they can have more than one plugin. - if name not in values: - values.append(name) - return values - - -def format_session_duration(seconds: float) -> str: - """Format the given seconds in a human readable manner to show in the final summary.""" - if seconds < 60: - return f"{seconds:.2f}s" - else: - dt = datetime.timedelta(seconds=int(seconds)) - return f"{seconds:.2f}s ({dt})" - - -def format_node_duration(seconds: float) -> str: - """Format the given seconds in a human readable manner to show in the test progress.""" - # The formatting is designed to be compact and readable, with at most 7 characters - # for durations below 100 hours. - if seconds < 0.00001: - return f" {seconds * 1000000:.3f}us" - if seconds < 0.0001: - return f" {seconds * 1000000:.2f}us" - if seconds < 0.001: - return f" {seconds * 1000000:.1f}us" - if seconds < 0.01: - return f" {seconds * 1000:.3f}ms" - if seconds < 0.1: - return f" {seconds * 1000:.2f}ms" - if seconds < 1: - return f" {seconds * 1000:.1f}ms" - if seconds < 60: - return f" {seconds:.3f}s" - if seconds < 3600: - return f" {seconds // 60:.0f}m {seconds % 60:.0f}s" - return f" {seconds // 3600:.0f}h {(seconds % 3600) // 60:.0f}m" - - -def _get_raw_skip_reason(report: TestReport) -> str: - """Get the reason string of a skip/xfail/xpass test report. - - The string is just the part given by the user. - """ - if hasattr(report, "wasxfail"): - reason = report.wasxfail - if reason.startswith("reason: "): - reason = reason[len("reason: ") :] - return reason - else: - assert report.skipped - assert isinstance(report.longrepr, tuple) - _, _, reason = report.longrepr - if reason.startswith("Skipped: "): - reason = reason[len("Skipped: ") :] - elif reason == "Skipped": - reason = "" - return reason - - -class TerminalProgressPlugin: - """Terminal progress reporting plugin using OSC 9;4 ANSI sequences. - - Emits OSC 9;4 sequences to indicate test progress to terminal - tabs/windows/etc. - - Not all terminal emulators support this feature. - - Ref: https://conemu.github.io/en/AnsiEscapeCodes.html#ConEmu_specific_OSC - """ - - def __init__(self, tr: TerminalReporter) -> None: - self._tr = tr - self._session: Session | None = None - self._has_failures = False - - def _emit_progress( - self, - state: Literal["remove", "normal", "error", "indeterminate", "paused"], - progress: int | None = None, - ) -> None: - """Emit OSC 9;4 sequence for indicating progress to the terminal. - - :param state: - Progress state to set. - :param progress: - Progress value 0-100. Required for "normal", optional for "error" - and "paused", otherwise ignored. - """ - assert progress is None or 0 <= progress <= 100 - - # OSC 9;4 sequence: ESC ] 9 ; 4 ; state ; progress ST - # ST can be ESC \ or BEL. ESC \ seems better supported. - match state: - case "remove": - sequence = "\x1b]9;4;0;\x1b\\" - case "normal": - assert progress is not None - sequence = f"\x1b]9;4;1;{progress}\x1b\\" - case "error": - if progress is not None: - sequence = f"\x1b]9;4;2;{progress}\x1b\\" - else: - sequence = "\x1b]9;4;2;\x1b\\" - case "indeterminate": - sequence = "\x1b]9;4;3;\x1b\\" - case "paused": - if progress is not None: - sequence = f"\x1b]9;4;4;{progress}\x1b\\" - else: - sequence = "\x1b]9;4;4;\x1b\\" - - self._tr.write_raw(sequence, flush=True) - - @hookimpl - def pytest_sessionstart(self, session: Session) -> None: - self._session = session - # Show indeterminate progress during collection. - self._emit_progress("indeterminate") - - @hookimpl - def pytest_collection_finish(self) -> None: - assert self._session is not None - if self._session.testscollected > 0: - # Switch from indeterminate to 0% progress. - self._emit_progress("normal", 0) - - @hookimpl - def pytest_runtest_logreport(self, report: TestReport) -> None: - if report.failed: - self._has_failures = True - - # Let's consider the "call" phase for progress. - if report.when != "call": - return - - # Calculate and emit progress. - assert self._session is not None - collected = self._session.testscollected - if collected > 0: - reported = self._tr.reported_progress - progress = min(reported * 100 // collected, 100) - self._emit_progress("error" if self._has_failures else "normal", progress) - - @hookimpl - def pytest_sessionfinish(self) -> None: - self._emit_progress("remove") diff --git a/.venv/lib/python3.12/site-packages/_pytest/terminalprogress.py b/.venv/lib/python3.12/site-packages/_pytest/terminalprogress.py deleted file mode 100644 index 287f0d5..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/terminalprogress.py +++ /dev/null @@ -1,30 +0,0 @@ -# A plugin to register the TerminalProgressPlugin plugin. -# -# This plugin is not loaded by default due to compatibility issues (#13896), -# but can be enabled in one of these ways: -# - The terminal plugin enables it in a few cases where it's safe, and not -# blocked by the user (using e.g. `-p no:terminalprogress`). -# - The user explicitly requests it, e.g. using `-p terminalprogress`. -# -# In a few years, if it's safe, we can consider enabling it by default. Then, -# this file will become unnecessary and can be inlined into terminal.py. - -from __future__ import annotations - -import os - -from _pytest.config import Config -from _pytest.config import hookimpl -from _pytest.terminal import TerminalProgressPlugin -from _pytest.terminal import TerminalReporter - - -@hookimpl(trylast=True) -def pytest_configure(config: Config) -> None: - reporter: TerminalReporter | None = config.pluginmanager.get_plugin( - "terminalreporter" - ) - - if reporter is not None and reporter.isatty() and os.environ.get("TERM") != "dumb": - plugin = TerminalProgressPlugin(reporter) - config.pluginmanager.register(plugin, name="terminalprogress-plugin") diff --git a/.venv/lib/python3.12/site-packages/_pytest/threadexception.py b/.venv/lib/python3.12/site-packages/_pytest/threadexception.py deleted file mode 100644 index eb57783..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/threadexception.py +++ /dev/null @@ -1,152 +0,0 @@ -from __future__ import annotations - -import collections -from collections.abc import Callable -import functools -import sys -import threading -import traceback -from typing import NamedTuple -from typing import TYPE_CHECKING -import warnings - -from _pytest.config import Config -from _pytest.nodes import Item -from _pytest.stash import StashKey -from _pytest.tracemalloc import tracemalloc_message -import pytest - - -if TYPE_CHECKING: - pass - -if sys.version_info < (3, 11): - from exceptiongroup import ExceptionGroup - - -class ThreadExceptionMeta(NamedTuple): - msg: str - cause_msg: str - exc_value: BaseException | None - - -thread_exceptions: StashKey[collections.deque[ThreadExceptionMeta | BaseException]] = ( - StashKey() -) - - -def collect_thread_exception(config: Config) -> None: - pop_thread_exception = config.stash[thread_exceptions].pop - errors: list[pytest.PytestUnhandledThreadExceptionWarning | RuntimeError] = [] - meta = None - hook_error = None - try: - while True: - try: - meta = pop_thread_exception() - except IndexError: - break - - if isinstance(meta, BaseException): - hook_error = RuntimeError("Failed to process thread exception") - hook_error.__cause__ = meta - errors.append(hook_error) - continue - - msg = meta.msg - try: - warnings.warn(pytest.PytestUnhandledThreadExceptionWarning(msg)) - except pytest.PytestUnhandledThreadExceptionWarning as e: - # This except happens when the warning is treated as an error (e.g. `-Werror`). - if meta.exc_value is not None: - # Exceptions have a better way to show the traceback, but - # warnings do not, so hide the traceback from the msg and - # set the cause so the traceback shows up in the right place. - e.args = (meta.cause_msg,) - e.__cause__ = meta.exc_value - errors.append(e) - - if len(errors) == 1: - raise errors[0] - if errors: - raise ExceptionGroup("multiple thread exception warnings", errors) - finally: - del errors, meta, hook_error - - -def cleanup( - *, config: Config, prev_hook: Callable[[threading.ExceptHookArgs], object] -) -> None: - try: - try: - # We don't join threads here, so exceptions raised from any - # threads still running by the time _threading_atexits joins them - # do not get captured (see #13027). - collect_thread_exception(config) - finally: - threading.excepthook = prev_hook - finally: - del config.stash[thread_exceptions] - - -def thread_exception_hook( - args: threading.ExceptHookArgs, - /, - *, - append: Callable[[ThreadExceptionMeta | BaseException], object], -) -> None: - try: - # we need to compute these strings here as they might change after - # the excepthook finishes and before the metadata object is - # collected by a pytest hook - thread_name = "" if args.thread is None else args.thread.name - summary = f"Exception in thread {thread_name}" - traceback_message = "\n\n" + "".join( - traceback.format_exception( - args.exc_type, - args.exc_value, - args.exc_traceback, - ) - ) - tracemalloc_tb = "\n" + tracemalloc_message(args.thread) - msg = summary + traceback_message + tracemalloc_tb - cause_msg = summary + tracemalloc_tb - - append( - ThreadExceptionMeta( - # Compute these strings here as they might change later - msg=msg, - cause_msg=cause_msg, - exc_value=args.exc_value, - ) - ) - except BaseException as e: - append(e) - # Raising this will cause the exception to be logged twice, once in our - # collect_thread_exception and once by sys.excepthook - # which is fine - this should never happen anyway and if it does - # it should probably be reported as a pytest bug. - raise - - -def pytest_configure(config: Config) -> None: - prev_hook = threading.excepthook - deque: collections.deque[ThreadExceptionMeta | BaseException] = collections.deque() - config.stash[thread_exceptions] = deque - config.add_cleanup(functools.partial(cleanup, config=config, prev_hook=prev_hook)) - threading.excepthook = functools.partial(thread_exception_hook, append=deque.append) - - -@pytest.hookimpl(trylast=True) -def pytest_runtest_setup(item: Item) -> None: - collect_thread_exception(item.config) - - -@pytest.hookimpl(trylast=True) -def pytest_runtest_call(item: Item) -> None: - collect_thread_exception(item.config) - - -@pytest.hookimpl(trylast=True) -def pytest_runtest_teardown(item: Item) -> None: - collect_thread_exception(item.config) diff --git a/.venv/lib/python3.12/site-packages/_pytest/timing.py b/.venv/lib/python3.12/site-packages/_pytest/timing.py deleted file mode 100644 index 51c3db2..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/timing.py +++ /dev/null @@ -1,95 +0,0 @@ -"""Indirection for time functions. - -We intentionally grab some "time" functions internally to avoid tests mocking "time" to affect -pytest runtime information (issue #185). - -Fixture "mock_timing" also interacts with this module for pytest's own tests. -""" - -from __future__ import annotations - -import dataclasses -from datetime import datetime -from datetime import timezone -from time import perf_counter -from time import sleep -from time import time -from typing import TYPE_CHECKING - - -if TYPE_CHECKING: - from pytest import MonkeyPatch - - -@dataclasses.dataclass(frozen=True) -class Instant: - """ - Represents an instant in time, used to both get the timestamp value and to measure - the duration of a time span. - - Inspired by Rust's `std::time::Instant`. - """ - - # Creation time of this instant, using time.time(), to measure actual time. - # Note: using a `lambda` to correctly get the mocked time via `MockTiming`. - time: float = dataclasses.field(default_factory=lambda: time(), init=False) - - # Performance counter tick of the instant, used to measure precise elapsed time. - # Note: using a `lambda` to correctly get the mocked time via `MockTiming`. - perf_count: float = dataclasses.field( - default_factory=lambda: perf_counter(), init=False - ) - - def elapsed(self) -> Duration: - """Measure the duration since `Instant` was created.""" - return Duration(start=self, stop=Instant()) - - def as_utc(self) -> datetime: - """Instant as UTC datetime.""" - return datetime.fromtimestamp(self.time, timezone.utc) - - -@dataclasses.dataclass(frozen=True) -class Duration: - """A span of time as measured by `Instant.elapsed()`.""" - - start: Instant - stop: Instant - - @property - def seconds(self) -> float: - """Elapsed time of the duration in seconds, measured using a performance counter for precise timing.""" - return self.stop.perf_count - self.start.perf_count - - -@dataclasses.dataclass -class MockTiming: - """Mocks _pytest.timing with a known object that can be used to control timing in tests - deterministically. - - pytest itself should always use functions from `_pytest.timing` instead of `time` directly. - - This then allows us more control over time during testing, if testing code also - uses `_pytest.timing` functions. - - Time is static, and only advances through `sleep` calls, thus tests might sleep over large - numbers and obtain accurate time() calls at the end, making tests reliable and instant.""" - - _current_time: float = datetime(2020, 5, 22, 14, 20, 50).timestamp() - - def sleep(self, seconds: float) -> None: - self._current_time += seconds - - def time(self) -> float: - return self._current_time - - def patch(self, monkeypatch: MonkeyPatch) -> None: - # pylint: disable-next=import-self - from _pytest import timing # noqa: PLW0406 - - monkeypatch.setattr(timing, "sleep", self.sleep) - monkeypatch.setattr(timing, "time", self.time) - monkeypatch.setattr(timing, "perf_counter", self.time) - - -__all__ = ["perf_counter", "sleep", "time"] diff --git a/.venv/lib/python3.12/site-packages/_pytest/tmpdir.py b/.venv/lib/python3.12/site-packages/_pytest/tmpdir.py deleted file mode 100644 index 66ca9f1..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/tmpdir.py +++ /dev/null @@ -1,337 +0,0 @@ -# mypy: allow-untyped-defs -"""Support for providing temporary directories to test functions.""" - -from __future__ import annotations - -from collections.abc import Generator -import dataclasses -import os -from pathlib import Path -import re -from shutil import rmtree -import stat -import tempfile -from typing import Any -from typing import final -from typing import Literal - -from .pathlib import cleanup_dead_symlinks -from .pathlib import LOCK_TIMEOUT -from .pathlib import make_numbered_dir -from .pathlib import make_numbered_dir_with_cleanup -from .pathlib import rm_rf -from _pytest.compat import get_user_id -from _pytest.config import Config -from _pytest.config import ExitCode -from _pytest.config import hookimpl -from _pytest.config.argparsing import Parser -from _pytest.deprecated import check_ispytest -from _pytest.fixtures import fixture -from _pytest.fixtures import FixtureRequest -from _pytest.monkeypatch import MonkeyPatch -from _pytest.nodes import Item -from _pytest.reports import TestReport -from _pytest.stash import StashKey - - -tmppath_result_key = StashKey[dict[str, bool]]() -RetentionType = Literal["all", "failed", "none"] - - -@final -@dataclasses.dataclass -class TempPathFactory: - """Factory for temporary directories under the common base temp directory, - as discussed at :ref:`temporary directory location and retention`. - """ - - _given_basetemp: Path | None - # pluggy TagTracerSub, not currently exposed, so Any. - _trace: Any - _basetemp: Path | None - _retention_count: int - _retention_policy: RetentionType - - def __init__( - self, - given_basetemp: Path | None, - retention_count: int, - retention_policy: RetentionType, - trace, - basetemp: Path | None = None, - *, - _ispytest: bool = False, - ) -> None: - check_ispytest(_ispytest) - if given_basetemp is None: - self._given_basetemp = None - else: - # Use os.path.abspath() to get absolute path instead of resolve() as it - # does not work the same in all platforms (see #4427). - # Path.absolute() exists, but it is not public (see https://bugs.python.org/issue25012). - self._given_basetemp = Path(os.path.abspath(str(given_basetemp))) - self._trace = trace - self._retention_count = retention_count - self._retention_policy = retention_policy - self._basetemp = basetemp - - @classmethod - def from_config( - cls, - config: Config, - *, - _ispytest: bool = False, - ) -> TempPathFactory: - """Create a factory according to pytest configuration. - - :meta private: - """ - check_ispytest(_ispytest) - count = int(config.getini("tmp_path_retention_count")) - if count < 0: - raise ValueError( - f"tmp_path_retention_count must be >= 0. Current input: {count}." - ) - - policy = config.getini("tmp_path_retention_policy") - if policy not in ("all", "failed", "none"): - raise ValueError( - f"tmp_path_retention_policy must be either all, failed, none. Current input: {policy}." - ) - - return cls( - given_basetemp=config.option.basetemp, - trace=config.trace.get("tmpdir"), - retention_count=count, - retention_policy=policy, - _ispytest=True, - ) - - def _ensure_relative_to_basetemp(self, basename: str) -> str: - basename = os.path.normpath(basename) - if (self.getbasetemp() / basename).resolve().parent != self.getbasetemp(): - raise ValueError(f"{basename} is not a normalized and relative path") - return basename - - def mktemp(self, basename: str, numbered: bool = True) -> Path: - """Create a new temporary directory managed by the factory. - - :param basename: - Directory base name, must be a relative path. - - :param numbered: - If ``True``, ensure the directory is unique by adding a numbered - suffix greater than any existing one: ``basename="foo-"`` and ``numbered=True`` - means that this function will create directories named ``"foo-0"``, - ``"foo-1"``, ``"foo-2"`` and so on. - - :returns: - The path to the new directory. - """ - basename = self._ensure_relative_to_basetemp(basename) - if not numbered: - p = self.getbasetemp().joinpath(basename) - p.mkdir(mode=0o700) - else: - p = make_numbered_dir(root=self.getbasetemp(), prefix=basename, mode=0o700) - self._trace("mktemp", p) - return p - - def getbasetemp(self) -> Path: - """Return the base temporary directory, creating it if needed. - - :returns: - The base temporary directory. - """ - if self._basetemp is not None: - return self._basetemp - - if self._given_basetemp is not None: - basetemp = self._given_basetemp - if basetemp.exists(): - rm_rf(basetemp) - basetemp.mkdir(mode=0o700) - basetemp = basetemp.resolve() - else: - from_env = os.environ.get("PYTEST_DEBUG_TEMPROOT") - temproot = Path(from_env or tempfile.gettempdir()).resolve() - user = get_user() or "unknown" - # use a sub-directory in the temproot to speed-up - # make_numbered_dir() call - rootdir = temproot.joinpath(f"pytest-of-{user}") - try: - rootdir.mkdir(mode=0o700, exist_ok=True) - except OSError: - # getuser() likely returned illegal characters for the platform, use unknown back off mechanism - rootdir = temproot.joinpath("pytest-of-unknown") - rootdir.mkdir(mode=0o700, exist_ok=True) - # Because we use exist_ok=True with a predictable name, make sure - # we are the owners, to prevent any funny business (on unix, where - # temproot is usually shared). - # Also, to keep things private, fixup any world-readable temp - # rootdir's permissions. Historically 0o755 was used, so we can't - # just error out on this, at least for a while. - # Don't follow symlinks, otherwise we're open to symlink-swapping - # TOCTOU vulnerability. - # This check makes us vulnerable to a DoS - a user can `mkdir - # /tmp/pytest-of-otheruser` and then `otheruser` will fail this - # check. For now we don't consider it a real problem. otheruser can - # change their TMPDIR or --basetemp, and maybe give the prankster a - # good scolding. - uid = get_user_id() - if uid is not None: - stat_follow_symlinks = ( - False if os.stat in os.supports_follow_symlinks else True - ) - rootdir_stat = rootdir.stat(follow_symlinks=stat_follow_symlinks) - if stat.S_ISLNK(rootdir_stat.st_mode): - raise OSError( - f"The temporary directory {rootdir} is a symbolic link. " - "Fix this and try again." - ) - if rootdir_stat.st_uid != uid: - raise OSError( - f"The temporary directory {rootdir} is not owned by the current user. " - "Fix this and try again." - ) - if (rootdir_stat.st_mode & 0o077) != 0: - chmod_follow_symlinks = ( - False if os.chmod in os.supports_follow_symlinks else True - ) - rootdir.chmod( - rootdir_stat.st_mode & ~0o077, - follow_symlinks=chmod_follow_symlinks, - ) - keep = self._retention_count - if self._retention_policy == "none": - keep = 0 - basetemp = make_numbered_dir_with_cleanup( - prefix="pytest-", - root=rootdir, - keep=keep, - lock_timeout=LOCK_TIMEOUT, - mode=0o700, - ) - assert basetemp is not None, basetemp - self._basetemp = basetemp - self._trace("new basetemp", basetemp) - return basetemp - - -def get_user() -> str | None: - """Return the current user name, or None if getuser() does not work - in the current environment (see #1010).""" - try: - # In some exotic environments, getpass may not be importable. - import getpass - - return getpass.getuser() - except (ImportError, OSError, KeyError): - return None - - -def pytest_configure(config: Config) -> None: - """Create a TempPathFactory and attach it to the config object. - - This is to comply with existing plugins which expect the handler to be - available at pytest_configure time, but ideally should be moved entirely - to the tmp_path_factory session fixture. - """ - mp = MonkeyPatch() - config.add_cleanup(mp.undo) - _tmp_path_factory = TempPathFactory.from_config(config, _ispytest=True) - mp.setattr(config, "_tmp_path_factory", _tmp_path_factory, raising=False) - - -def pytest_addoption(parser: Parser) -> None: - parser.addini( - "tmp_path_retention_count", - help="How many sessions should we keep the `tmp_path` directories, according to `tmp_path_retention_policy`.", - default="3", - # NOTE: Would have been better as an `int` but can't change it now. - type="string", - ) - - parser.addini( - "tmp_path_retention_policy", - help="Controls which directories created by the `tmp_path` fixture are kept around, based on test outcome. " - "(all/failed/none)", - type="string", - default="all", - ) - - -@fixture(scope="session") -def tmp_path_factory(request: FixtureRequest) -> TempPathFactory: - """Return a :class:`pytest.TempPathFactory` instance for the test session.""" - # Set dynamically by pytest_configure() above. - return request.config._tmp_path_factory # type: ignore - - -def _mk_tmp(request: FixtureRequest, factory: TempPathFactory) -> Path: - name = request.node.name - name = re.sub(r"[\W]", "_", name) - MAXVAL = 30 - name = name[:MAXVAL] - return factory.mktemp(name, numbered=True) - - -@fixture -def tmp_path( - request: FixtureRequest, tmp_path_factory: TempPathFactory -) -> Generator[Path]: - """Return a temporary directory (as :class:`pathlib.Path` object) - which is unique to each test function invocation. - The temporary directory is created as a subdirectory - of the base temporary directory, with configurable retention, - as discussed in :ref:`temporary directory location and retention`. - """ - path = _mk_tmp(request, tmp_path_factory) - yield path - - # Remove the tmpdir if the policy is "failed" and the test passed. - policy = tmp_path_factory._retention_policy - result_dict = request.node.stash[tmppath_result_key] - - if policy == "failed" and result_dict.get("call", True): - # We do a "best effort" to remove files, but it might not be possible due to some leaked resource, - # permissions, etc, in which case we ignore it. - rmtree(path, ignore_errors=True) - - del request.node.stash[tmppath_result_key] - - -def pytest_sessionfinish(session, exitstatus: int | ExitCode): - """After each session, remove base directory if all the tests passed, - the policy is "failed", and the basetemp is not specified by a user. - """ - tmp_path_factory: TempPathFactory = session.config._tmp_path_factory - basetemp = tmp_path_factory._basetemp - if basetemp is None: - return - - policy = tmp_path_factory._retention_policy - if ( - exitstatus == 0 - and policy == "failed" - and tmp_path_factory._given_basetemp is None - ): - if basetemp.is_dir(): - # We do a "best effort" to remove files, but it might not be possible due to some leaked resource, - # permissions, etc, in which case we ignore it. - rmtree(basetemp, ignore_errors=True) - - # Remove dead symlinks. - if basetemp.is_dir(): - cleanup_dead_symlinks(basetemp) - - -@hookimpl(wrapper=True, tryfirst=True) -def pytest_runtest_makereport( - item: Item, call -) -> Generator[None, TestReport, TestReport]: - rep = yield - assert rep.when is not None - empty: dict[str, bool] = {} - item.stash.setdefault(tmppath_result_key, empty)[rep.when] = rep.passed - return rep diff --git a/.venv/lib/python3.12/site-packages/_pytest/tracemalloc.py b/.venv/lib/python3.12/site-packages/_pytest/tracemalloc.py deleted file mode 100644 index 5d0b198..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/tracemalloc.py +++ /dev/null @@ -1,24 +0,0 @@ -from __future__ import annotations - - -def tracemalloc_message(source: object) -> str: - if source is None: - return "" - - try: - import tracemalloc - except ImportError: - return "" - - tb = tracemalloc.get_object_traceback(source) - if tb is not None: - formatted_tb = "\n".join(tb.format()) - # Use a leading new line to better separate the (large) output - # from the traceback to the previous warning text. - return f"\nObject allocated at:\n{formatted_tb}" - # No need for a leading new line. - url = "https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings" - return ( - "Enable tracemalloc to get traceback where the object was allocated.\n" - f"See {url} for more info." - ) diff --git a/.venv/lib/python3.12/site-packages/_pytest/unittest.py b/.venv/lib/python3.12/site-packages/_pytest/unittest.py deleted file mode 100644 index 31be884..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/unittest.py +++ /dev/null @@ -1,632 +0,0 @@ -# mypy: allow-untyped-defs -"""Discover and run std-library "unittest" style tests.""" - -from __future__ import annotations - -from collections.abc import Callable -from collections.abc import Generator -from collections.abc import Iterable -from collections.abc import Iterator -from enum import auto -from enum import Enum -import inspect -import sys -import traceback -import types -from typing import Any -from typing import TYPE_CHECKING -from unittest import TestCase - -import _pytest._code -from _pytest._code import ExceptionInfo -from _pytest.compat import assert_never -from _pytest.compat import is_async_function -from _pytest.config import hookimpl -from _pytest.fixtures import FixtureRequest -from _pytest.monkeypatch import MonkeyPatch -from _pytest.nodes import Collector -from _pytest.nodes import Item -from _pytest.outcomes import exit -from _pytest.outcomes import fail -from _pytest.outcomes import skip -from _pytest.outcomes import xfail -from _pytest.python import Class -from _pytest.python import Function -from _pytest.python import Module -from _pytest.runner import CallInfo -from _pytest.runner import check_interactive_exception -from _pytest.subtests import SubtestContext -from _pytest.subtests import SubtestReport - - -if sys.version_info[:2] < (3, 11): - from exceptiongroup import ExceptionGroup - -if TYPE_CHECKING: - from types import TracebackType - import unittest - - import twisted.trial.unittest - - -_SysExcInfoType = ( - tuple[type[BaseException], BaseException, types.TracebackType] - | tuple[None, None, None] -) - - -def pytest_pycollect_makeitem( - collector: Module | Class, name: str, obj: object -) -> UnitTestCase | None: - try: - # Has unittest been imported? - ut = sys.modules["unittest"] - # Is obj a subclass of unittest.TestCase? - # Type ignored because `ut` is an opaque module. - if not issubclass(obj, ut.TestCase): # type: ignore - return None - except Exception: - return None - # Is obj a concrete class? - # Abstract classes can't be instantiated so no point collecting them. - if inspect.isabstract(obj): - return None - # Yes, so let's collect it. - return UnitTestCase.from_parent(collector, name=name, obj=obj) - - -class UnitTestCase(Class): - # Marker for fixturemanger.getfixtureinfo() - # to declare that our children do not support funcargs. - nofuncargs = True - - def newinstance(self): - # TestCase __init__ takes the method (test) name. The TestCase - # constructor treats the name "runTest" as a special no-op, so it can be - # used when a dummy instance is needed. While unittest.TestCase has a - # default, some subclasses omit the default (#9610), so always supply - # it. - return self.obj("runTest") - - def collect(self) -> Iterable[Item | Collector]: - from unittest import TestLoader - - cls = self.obj - if not getattr(cls, "__test__", True): - return - - skipped = _is_skipped(cls) - if not skipped: - self._register_unittest_setup_method_fixture(cls) - self._register_unittest_setup_class_fixture(cls) - self._register_setup_class_fixture() - - self.session._fixturemanager.parsefactories(self.newinstance(), self.nodeid) - - loader = TestLoader() - foundsomething = False - for name in loader.getTestCaseNames(self.obj): - x = getattr(self.obj, name) - if not getattr(x, "__test__", True): - continue - yield TestCaseFunction.from_parent(self, name=name) - foundsomething = True - - if not foundsomething: - runtest = getattr(self.obj, "runTest", None) - if runtest is not None: - ut = sys.modules.get("twisted.trial.unittest", None) - if ut is None or runtest != ut.TestCase.runTest: - yield TestCaseFunction.from_parent(self, name="runTest") - - def _register_unittest_setup_class_fixture(self, cls: type) -> None: - """Register an auto-use fixture to invoke setUpClass and - tearDownClass (#517).""" - setup = getattr(cls, "setUpClass", None) - teardown = getattr(cls, "tearDownClass", None) - if setup is None and teardown is None: - return None - cleanup = getattr(cls, "doClassCleanups", lambda: None) - - def process_teardown_exceptions() -> None: - # tearDown_exceptions is a list set in the class containing exc_infos for errors during - # teardown for the class. - exc_infos = getattr(cls, "tearDown_exceptions", None) - if not exc_infos: - return - exceptions = [exc for (_, exc, _) in exc_infos] - # If a single exception, raise it directly as this provides a more readable - # error (hopefully this will improve in #12255). - if len(exceptions) == 1: - raise exceptions[0] - else: - raise ExceptionGroup("Unittest class cleanup errors", exceptions) - - def unittest_setup_class_fixture( - request: FixtureRequest, - ) -> Generator[None]: - cls = request.cls - if _is_skipped(cls): - reason = cls.__unittest_skip_why__ - raise skip.Exception(reason, _use_item_location=True) - if setup is not None: - try: - setup() - # unittest does not call the cleanup function for every BaseException, so we - # follow this here. - except Exception: - cleanup() - process_teardown_exceptions() - raise - yield - try: - if teardown is not None: - teardown() - finally: - cleanup() - process_teardown_exceptions() - - self.session._fixturemanager._register_fixture( - # Use a unique name to speed up lookup. - name=f"_unittest_setUpClass_fixture_{cls.__qualname__}", - func=unittest_setup_class_fixture, - nodeid=self.nodeid, - scope="class", - autouse=True, - ) - - def _register_unittest_setup_method_fixture(self, cls: type) -> None: - """Register an auto-use fixture to invoke setup_method and - teardown_method (#517).""" - setup = getattr(cls, "setup_method", None) - teardown = getattr(cls, "teardown_method", None) - if setup is None and teardown is None: - return None - - def unittest_setup_method_fixture( - request: FixtureRequest, - ) -> Generator[None]: - self = request.instance - if _is_skipped(self): - reason = self.__unittest_skip_why__ - raise skip.Exception(reason, _use_item_location=True) - if setup is not None: - setup(self, request.function) - yield - if teardown is not None: - teardown(self, request.function) - - self.session._fixturemanager._register_fixture( - # Use a unique name to speed up lookup. - name=f"_unittest_setup_method_fixture_{cls.__qualname__}", - func=unittest_setup_method_fixture, - nodeid=self.nodeid, - scope="function", - autouse=True, - ) - - -class TestCaseFunction(Function): - nofuncargs = True - failfast = False - _excinfo: list[_pytest._code.ExceptionInfo[BaseException]] | None = None - - def _getinstance(self): - assert isinstance(self.parent, UnitTestCase) - return self.parent.obj(self.name) - - # Backward compat for pytest-django; can be removed after pytest-django - # updates + some slack. - @property - def _testcase(self): - return self.instance - - def setup(self) -> None: - # A bound method to be called during teardown() if set (see 'runtest()'). - self._explicit_tearDown: Callable[[], None] | None = None - super().setup() - if sys.version_info < (3, 11): - # A cache of the subTest errors and non-subtest skips in self._outcome. - # Compute and cache these lists once, instead of computing them again and again for each subtest (#13965). - self._cached_errors_and_skips: tuple[list[Any], list[Any]] | None = None - - def teardown(self) -> None: - if self._explicit_tearDown is not None: - self._explicit_tearDown() - self._explicit_tearDown = None - self._obj = None - del self._instance - super().teardown() - - def startTest(self, testcase: unittest.TestCase) -> None: - pass - - def _addexcinfo(self, rawexcinfo: _SysExcInfoType) -> None: - rawexcinfo = _handle_twisted_exc_info(rawexcinfo) - try: - excinfo = _pytest._code.ExceptionInfo[BaseException].from_exc_info( - rawexcinfo # type: ignore[arg-type] - ) - # Invoke the attributes to trigger storing the traceback - # trial causes some issue there. - _ = excinfo.value - _ = excinfo.traceback - except TypeError: - try: - try: - values = traceback.format_exception(*rawexcinfo) - values.insert( - 0, - "NOTE: Incompatible Exception Representation, " - "displaying natively:\n\n", - ) - fail("".join(values), pytrace=False) - except (fail.Exception, KeyboardInterrupt): - raise - except BaseException: - fail( - "ERROR: Unknown Incompatible Exception " - f"representation:\n{rawexcinfo!r}", - pytrace=False, - ) - except KeyboardInterrupt: - raise - except fail.Exception: - excinfo = _pytest._code.ExceptionInfo.from_current() - self.__dict__.setdefault("_excinfo", []).append(excinfo) - - def addError( - self, testcase: unittest.TestCase, rawexcinfo: _SysExcInfoType - ) -> None: - try: - if isinstance(rawexcinfo[1], exit.Exception): - exit(rawexcinfo[1].msg) - except TypeError: - pass - self._addexcinfo(rawexcinfo) - - def addFailure( - self, testcase: unittest.TestCase, rawexcinfo: _SysExcInfoType - ) -> None: - self._addexcinfo(rawexcinfo) - - def addSkip( - self, testcase: unittest.TestCase, reason: str, *, handle_subtests: bool = True - ) -> None: - from unittest.case import _SubTest # type: ignore[attr-defined] - - def add_skip() -> None: - try: - raise skip.Exception(reason, _use_item_location=True) - except skip.Exception: - self._addexcinfo(sys.exc_info()) - - if not handle_subtests: - add_skip() - return - - if isinstance(testcase, _SubTest): - add_skip() - if self._excinfo is not None: - exc_info = self._excinfo[-1] - self.addSubTest(testcase.test_case, testcase, exc_info) - else: - # For python < 3.11: the non-subtest skips have to be added by `add_skip` only after all subtest - # failures are processed by `_addSubTest`: `self.instance._outcome` has no attribute - # `skipped/errors` anymore. - # We also need to check if `self.instance._outcome` is `None` (this happens if the test - # class/method is decorated with `unittest.skip`, see pytest-dev/pytest-subtests#173). - if sys.version_info < (3, 11) and self.instance._outcome is not None: - subtest_errors, _ = self._obtain_errors_and_skips() - if len(subtest_errors) == 0: - add_skip() - else: - add_skip() - - def addExpectedFailure( - self, - testcase: unittest.TestCase, - rawexcinfo: _SysExcInfoType, - reason: str = "", - ) -> None: - try: - xfail(str(reason)) - except xfail.Exception: - self._addexcinfo(sys.exc_info()) - - def addUnexpectedSuccess( - self, - testcase: unittest.TestCase, - reason: twisted.trial.unittest.Todo | None = None, - ) -> None: - msg = "Unexpected success" - if reason: - msg += f": {reason.reason}" - # Preserve unittest behaviour - fail the test. Explicitly not an XPASS. - try: - fail(msg, pytrace=False) - except fail.Exception: - self._addexcinfo(sys.exc_info()) - - def addSuccess(self, testcase: unittest.TestCase) -> None: - pass - - def stopTest(self, testcase: unittest.TestCase) -> None: - pass - - def addDuration(self, testcase: unittest.TestCase, elapsed: float) -> None: - pass - - def runtest(self) -> None: - from _pytest.debugging import maybe_wrap_pytest_function_for_tracing - - testcase = self.instance - assert testcase is not None - - maybe_wrap_pytest_function_for_tracing(self) - - # Let the unittest framework handle async functions. - if is_async_function(self.obj): - testcase(result=self) - else: - # When --pdb is given, we want to postpone calling tearDown() otherwise - # when entering the pdb prompt, tearDown() would have probably cleaned up - # instance variables, which makes it difficult to debug. - # Arguably we could always postpone tearDown(), but this changes the moment where the - # TestCase instance interacts with the results object, so better to only do it - # when absolutely needed. - # We need to consider if the test itself is skipped, or the whole class. - assert isinstance(self.parent, UnitTestCase) - skipped = _is_skipped(self.obj) or _is_skipped(self.parent.obj) - if self.config.getoption("usepdb") and not skipped: - self._explicit_tearDown = testcase.tearDown - setattr(testcase, "tearDown", lambda *args: None) - - # We need to update the actual bound method with self.obj, because - # wrap_pytest_function_for_tracing replaces self.obj by a wrapper. - setattr(testcase, self.name, self.obj) - try: - testcase(result=self) - finally: - delattr(testcase, self.name) - - def _traceback_filter( - self, excinfo: _pytest._code.ExceptionInfo[BaseException] - ) -> _pytest._code.Traceback: - traceback = super()._traceback_filter(excinfo) - ntraceback = traceback.filter( - lambda x: not x.frame.f_globals.get("__unittest"), - ) - if not ntraceback: - ntraceback = traceback - return ntraceback - - def addSubTest( - self, - test_case: Any, - test: TestCase, - exc_info: ExceptionInfo[BaseException] - | tuple[type[BaseException], BaseException, TracebackType] - | None, - ) -> None: - # Importing this private symbol locally in case this symbol is renamed/removed in the future; importing - # it globally would break pytest entirely, importing it locally only will break unittests using `addSubTest`. - from unittest.case import _subtest_msg_sentinel # type: ignore[attr-defined] - - exception_info: ExceptionInfo[BaseException] | None - match exc_info: - case tuple(): - exception_info = ExceptionInfo(exc_info, _ispytest=True) - case ExceptionInfo() | None: - exception_info = exc_info - case unreachable: - assert_never(unreachable) - - call_info = CallInfo[None]( - None, - exception_info, - start=0, - stop=0, - duration=0, - when="call", - _ispytest=True, - ) - msg = None if test._message is _subtest_msg_sentinel else str(test._message) # type: ignore[attr-defined] - report = self.ihook.pytest_runtest_makereport(item=self, call=call_info) - sub_report = SubtestReport._new( - report, - SubtestContext(msg=msg, kwargs=dict(test.params)), # type: ignore[attr-defined] - captured_output=None, - captured_logs=None, - ) - self.ihook.pytest_runtest_logreport(report=sub_report) - if check_interactive_exception(call_info, sub_report): - self.ihook.pytest_exception_interact( - node=self, call=call_info, report=sub_report - ) - - # For python < 3.11: add non-subtest skips once all subtest failures are processed by # `_addSubTest`. - if sys.version_info < (3, 11): - subtest_errors, non_subtest_skip = self._obtain_errors_and_skips() - - # Check if we have non-subtest skips: if there are also sub failures, non-subtest skips are not treated in - # `_addSubTest` and have to be added using `add_skip` after all subtest failures are processed. - if len(non_subtest_skip) > 0 and len(subtest_errors) > 0: - # Make sure we have processed the last subtest failure - last_subset_error = subtest_errors[-1] - if exc_info is last_subset_error[-1]: - # Add non-subtest skips (as they could not be treated in `_addSkip`) - for testcase, reason in non_subtest_skip: - self.addSkip(testcase, reason, handle_subtests=False) - - def _obtain_errors_and_skips(self) -> tuple[list[Any], list[Any]]: - """Compute or obtain the cached values for subtest errors and non-subtest skips.""" - from unittest.case import _SubTest # type: ignore[attr-defined] - - assert sys.version_info < (3, 11), ( - "This workaround only should be used in Python 3.10" - ) - if self._cached_errors_and_skips is not None: - return self._cached_errors_and_skips - - subtest_errors = [ - (x, y) - for x, y in self.instance._outcome.errors - if isinstance(x, _SubTest) and y is not None - ] - - non_subtest_skips = [ - (x, y) - for x, y in self.instance._outcome.skipped - if not isinstance(x, _SubTest) - ] - self._cached_errors_and_skips = (subtest_errors, non_subtest_skips) - return subtest_errors, non_subtest_skips - - -@hookimpl(tryfirst=True) -def pytest_runtest_makereport(item: Item, call: CallInfo[None]) -> None: - if isinstance(item, TestCaseFunction): - if item._excinfo: - call.excinfo = item._excinfo.pop(0) - try: - del call.result - except AttributeError: - pass - - # Convert unittest.SkipTest to pytest.skip. - # This covers explicit `raise unittest.SkipTest`. - unittest = sys.modules.get("unittest") - if unittest and call.excinfo and isinstance(call.excinfo.value, unittest.SkipTest): - excinfo = call.excinfo - call2 = CallInfo[None].from_call(lambda: skip(str(excinfo.value)), call.when) - call.excinfo = call2.excinfo - - -def _is_skipped(obj) -> bool: - """Return True if the given object has been marked with @unittest.skip.""" - return bool(getattr(obj, "__unittest_skip__", False)) - - -def pytest_configure() -> None: - """Register the TestCaseFunction class as an IReporter if twisted.trial is available.""" - if _get_twisted_version() is not TwistedVersion.NotInstalled: - from twisted.trial.itrial import IReporter - from zope.interface import classImplements - - classImplements(TestCaseFunction, IReporter) - - -class TwistedVersion(Enum): - """ - The Twisted version installed in the environment. - - We have different workarounds in place for different versions of Twisted. - """ - - # Twisted version 24 or prior. - Version24 = auto() - # Twisted version 25 or later. - Version25 = auto() - # Twisted version is not available. - NotInstalled = auto() - - -def _get_twisted_version() -> TwistedVersion: - # We need to check if "twisted.trial.unittest" is specifically present in sys.modules. - # This is because we intend to integrate with Trial only when it's actively running - # the test suite, but not needed when only other Twisted components are in use. - if "twisted.trial.unittest" not in sys.modules: - return TwistedVersion.NotInstalled - - import importlib.metadata - - import packaging.version - - version_str = importlib.metadata.version("twisted") - version = packaging.version.parse(version_str) - if version.major <= 24: - return TwistedVersion.Version24 - else: - return TwistedVersion.Version25 - - -# Name of the attribute in `twisted.python.Failure` instances that stores -# the `sys.exc_info()` tuple. -# See twisted.trial support in `pytest_runtest_protocol`. -TWISTED_RAW_EXCINFO_ATTR = "_twisted_raw_excinfo" - - -@hookimpl(wrapper=True) -def pytest_runtest_protocol(item: Item) -> Iterator[None]: - if _get_twisted_version() is TwistedVersion.Version24: - import twisted.python.failure as ut - - # Monkeypatch `Failure.__init__` to store the raw exception info. - original__init__ = ut.Failure.__init__ - - def store_raw_exception_info( - self, exc_value=None, exc_type=None, exc_tb=None, captureVars=None - ): # pragma: no cover - if exc_value is None: - raw_exc_info = sys.exc_info() - else: - if exc_type is None: - exc_type = type(exc_value) - if exc_tb is None: - exc_tb = sys.exc_info()[2] - raw_exc_info = (exc_type, exc_value, exc_tb) - setattr(self, TWISTED_RAW_EXCINFO_ATTR, tuple(raw_exc_info)) - try: - original__init__( - self, exc_value, exc_type, exc_tb, captureVars=captureVars - ) - except TypeError: # pragma: no cover - original__init__(self, exc_value, exc_type, exc_tb) - - with MonkeyPatch.context() as patcher: - patcher.setattr(ut.Failure, "__init__", store_raw_exception_info) - return (yield) - else: - return (yield) - - -def _handle_twisted_exc_info( - rawexcinfo: _SysExcInfoType | BaseException, -) -> _SysExcInfoType: - """ - Twisted passes a custom Failure instance to `addError()` instead of using `sys.exc_info()`. - Therefore, if `rawexcinfo` is a `Failure` instance, convert it into the equivalent `sys.exc_info()` tuple - as expected by pytest. - """ - twisted_version = _get_twisted_version() - if twisted_version is TwistedVersion.NotInstalled: - # Unfortunately, because we cannot import `twisted.python.failure` at the top of the file - # and use it in the signature, we need to use `type:ignore` here because we cannot narrow - # the type properly in the `if` statement above. - return rawexcinfo # type:ignore[return-value] - elif twisted_version is TwistedVersion.Version24: - # Twisted calls addError() passing its own classes (like `twisted.python.Failure`), which violates - # the `addError()` signature, so we extract the original `sys.exc_info()` tuple which is stored - # in the object. - if hasattr(rawexcinfo, TWISTED_RAW_EXCINFO_ATTR): - saved_exc_info = getattr(rawexcinfo, TWISTED_RAW_EXCINFO_ATTR) - # Delete the attribute from the original object to avoid leaks. - delattr(rawexcinfo, TWISTED_RAW_EXCINFO_ATTR) - return saved_exc_info # type:ignore[no-any-return] - return rawexcinfo # type:ignore[return-value] - elif twisted_version is TwistedVersion.Version25: - if isinstance(rawexcinfo, BaseException): - import twisted.python.failure - - if isinstance(rawexcinfo, twisted.python.failure.Failure): - tb = rawexcinfo.__traceback__ - if tb is None: - tb = sys.exc_info()[2] - return type(rawexcinfo.value), rawexcinfo.value, tb - - return rawexcinfo # type:ignore[return-value] - else: - # Ideally we would use assert_never() here, but it is not available in all Python versions - # we support, plus we do not require `type_extensions` currently. - assert False, f"Unexpected Twisted version: {twisted_version}" diff --git a/.venv/lib/python3.12/site-packages/_pytest/unraisableexception.py b/.venv/lib/python3.12/site-packages/_pytest/unraisableexception.py deleted file mode 100644 index 0faca36..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/unraisableexception.py +++ /dev/null @@ -1,163 +0,0 @@ -from __future__ import annotations - -import collections -from collections.abc import Callable -import functools -import gc -import sys -import traceback -from typing import NamedTuple -from typing import TYPE_CHECKING -import warnings - -from _pytest.config import Config -from _pytest.nodes import Item -from _pytest.stash import StashKey -from _pytest.tracemalloc import tracemalloc_message -import pytest - - -if TYPE_CHECKING: - pass - -if sys.version_info < (3, 11): - from exceptiongroup import ExceptionGroup - - -# This is a stash item and not a simple constant to allow pytester to override it. -gc_collect_iterations_key = StashKey[int]() - - -def gc_collect_harder(iterations: int) -> None: - for _ in range(iterations): - gc.collect() - - -class UnraisableMeta(NamedTuple): - msg: str - cause_msg: str - exc_value: BaseException | None - - -unraisable_exceptions: StashKey[collections.deque[UnraisableMeta | BaseException]] = ( - StashKey() -) - - -def collect_unraisable(config: Config) -> None: - pop_unraisable = config.stash[unraisable_exceptions].pop - errors: list[pytest.PytestUnraisableExceptionWarning | RuntimeError] = [] - meta = None - hook_error = None - try: - while True: - try: - meta = pop_unraisable() - except IndexError: - break - - if isinstance(meta, BaseException): - hook_error = RuntimeError("Failed to process unraisable exception") - hook_error.__cause__ = meta - errors.append(hook_error) - continue - - msg = meta.msg - try: - warnings.warn(pytest.PytestUnraisableExceptionWarning(msg)) - except pytest.PytestUnraisableExceptionWarning as e: - # This except happens when the warning is treated as an error (e.g. `-Werror`). - if meta.exc_value is not None: - # Exceptions have a better way to show the traceback, but - # warnings do not, so hide the traceback from the msg and - # set the cause so the traceback shows up in the right place. - e.args = (meta.cause_msg,) - e.__cause__ = meta.exc_value - errors.append(e) - - if len(errors) == 1: - raise errors[0] - if errors: - raise ExceptionGroup("multiple unraisable exception warnings", errors) - finally: - del errors, meta, hook_error - - -def cleanup( - *, config: Config, prev_hook: Callable[[sys.UnraisableHookArgs], object] -) -> None: - # A single collection doesn't necessarily collect everything. - # Constant determined experimentally by the Trio project. - gc_collect_iterations = config.stash.get(gc_collect_iterations_key, 5) - try: - try: - gc_collect_harder(gc_collect_iterations) - collect_unraisable(config) - finally: - sys.unraisablehook = prev_hook - finally: - del config.stash[unraisable_exceptions] - - -def unraisable_hook( - unraisable: sys.UnraisableHookArgs, - /, - *, - append: Callable[[UnraisableMeta | BaseException], object], -) -> None: - try: - # we need to compute these strings here as they might change after - # the unraisablehook finishes and before the metadata object is - # collected by a pytest hook - err_msg = ( - "Exception ignored in" if unraisable.err_msg is None else unraisable.err_msg - ) - summary = f"{err_msg}: {unraisable.object!r}" - traceback_message = "\n\n" + "".join( - traceback.format_exception( - unraisable.exc_type, - unraisable.exc_value, - unraisable.exc_traceback, - ) - ) - tracemalloc_tb = "\n" + tracemalloc_message(unraisable.object) - msg = summary + traceback_message + tracemalloc_tb - cause_msg = summary + tracemalloc_tb - - append( - UnraisableMeta( - msg=msg, - cause_msg=cause_msg, - exc_value=unraisable.exc_value, - ) - ) - except BaseException as e: - append(e) - # Raising this will cause the exception to be logged twice, once in our - # collect_unraisable and once by the unraisablehook calling machinery - # which is fine - this should never happen anyway and if it does - # it should probably be reported as a pytest bug. - raise - - -def pytest_configure(config: Config) -> None: - prev_hook = sys.unraisablehook - deque: collections.deque[UnraisableMeta | BaseException] = collections.deque() - config.stash[unraisable_exceptions] = deque - config.add_cleanup(functools.partial(cleanup, config=config, prev_hook=prev_hook)) - sys.unraisablehook = functools.partial(unraisable_hook, append=deque.append) - - -@pytest.hookimpl(trylast=True) -def pytest_runtest_setup(item: Item) -> None: - collect_unraisable(item.config) - - -@pytest.hookimpl(trylast=True) -def pytest_runtest_call(item: Item) -> None: - collect_unraisable(item.config) - - -@pytest.hookimpl(trylast=True) -def pytest_runtest_teardown(item: Item) -> None: - collect_unraisable(item.config) diff --git a/.venv/lib/python3.12/site-packages/_pytest/warning_types.py b/.venv/lib/python3.12/site-packages/_pytest/warning_types.py deleted file mode 100644 index 93071b4..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/warning_types.py +++ /dev/null @@ -1,172 +0,0 @@ -from __future__ import annotations - -import dataclasses -import inspect -from types import FunctionType -from typing import Any -from typing import final -from typing import Generic -from typing import TypeVar -import warnings - - -class PytestWarning(UserWarning): - """Base class for all warnings emitted by pytest.""" - - __module__ = "pytest" - - -@final -class PytestAssertRewriteWarning(PytestWarning): - """Warning emitted by the pytest assert rewrite module.""" - - __module__ = "pytest" - - -@final -class PytestCacheWarning(PytestWarning): - """Warning emitted by the cache plugin in various situations.""" - - __module__ = "pytest" - - -@final -class PytestConfigWarning(PytestWarning): - """Warning emitted for configuration issues.""" - - __module__ = "pytest" - - -@final -class PytestCollectionWarning(PytestWarning): - """Warning emitted when pytest is not able to collect a file or symbol in a module.""" - - __module__ = "pytest" - - -class PytestDeprecationWarning(PytestWarning, DeprecationWarning): - """Warning class for features that will be removed in a future version.""" - - __module__ = "pytest" - - -class PytestRemovedIn9Warning(PytestDeprecationWarning): - """Warning class for features that will be removed in pytest 9.""" - - __module__ = "pytest" - - -class PytestRemovedIn10Warning(PytestDeprecationWarning): - """Warning class for features that will be removed in pytest 10.""" - - __module__ = "pytest" - - -@final -class PytestExperimentalApiWarning(PytestWarning, FutureWarning): - """Warning category used to denote experiments in pytest. - - Use sparingly as the API might change or even be removed completely in a - future version. - """ - - __module__ = "pytest" - - @classmethod - def simple(cls, apiname: str) -> PytestExperimentalApiWarning: - return cls(f"{apiname} is an experimental api that may change over time") - - -@final -class PytestReturnNotNoneWarning(PytestWarning): - """ - Warning emitted when a test function returns a value other than ``None``. - - See :ref:`return-not-none` for details. - """ - - __module__ = "pytest" - - -@final -class PytestUnknownMarkWarning(PytestWarning): - """Warning emitted on use of unknown markers. - - See :ref:`mark` for details. - """ - - __module__ = "pytest" - - -@final -class PytestUnraisableExceptionWarning(PytestWarning): - """An unraisable exception was reported. - - Unraisable exceptions are exceptions raised in :meth:`__del__ ` - implementations and similar situations when the exception cannot be raised - as normal. - """ - - __module__ = "pytest" - - -@final -class PytestUnhandledThreadExceptionWarning(PytestWarning): - """An unhandled exception occurred in a :class:`~threading.Thread`. - - Such exceptions don't propagate normally. - """ - - __module__ = "pytest" - - -_W = TypeVar("_W", bound=PytestWarning) - - -@final -@dataclasses.dataclass -class UnformattedWarning(Generic[_W]): - """A warning meant to be formatted during runtime. - - This is used to hold warnings that need to format their message at runtime, - as opposed to a direct message. - """ - - category: type[_W] - template: str - - def format(self, **kwargs: Any) -> _W: - """Return an instance of the warning category, formatted with given kwargs.""" - return self.category(self.template.format(**kwargs)) - - -@final -class PytestFDWarning(PytestWarning): - """When the lsof plugin finds leaked fds.""" - - __module__ = "pytest" - - -def warn_explicit_for(method: FunctionType, message: PytestWarning) -> None: - """ - Issue the warning :param:`message` for the definition of the given :param:`method` - - this helps to log warnings for functions defined prior to finding an issue with them - (like hook wrappers being marked in a legacy mechanism) - """ - lineno = method.__code__.co_firstlineno - filename = inspect.getfile(method) - module = method.__module__ - mod_globals = method.__globals__ - try: - warnings.warn_explicit( - message, - type(message), - filename=filename, - module=module, - registry=mod_globals.setdefault("__warningregistry__", {}), - lineno=lineno, - ) - except Warning as w: - # If warnings are errors (e.g. -Werror), location information gets lost, so we add it to the message. - raise type(w)(f"{w}\n at {filename}:{lineno}") from None diff --git a/.venv/lib/python3.12/site-packages/_pytest/warnings.py b/.venv/lib/python3.12/site-packages/_pytest/warnings.py deleted file mode 100644 index 1dbf002..0000000 --- a/.venv/lib/python3.12/site-packages/_pytest/warnings.py +++ /dev/null @@ -1,151 +0,0 @@ -# mypy: allow-untyped-defs -from __future__ import annotations - -from collections.abc import Generator -from contextlib import contextmanager -from contextlib import ExitStack -import sys -from typing import Literal -import warnings - -from _pytest.config import apply_warning_filters -from _pytest.config import Config -from _pytest.config import parse_warning_filter -from _pytest.main import Session -from _pytest.nodes import Item -from _pytest.terminal import TerminalReporter -from _pytest.tracemalloc import tracemalloc_message -import pytest - - -@contextmanager -def catch_warnings_for_item( - config: Config, - ihook, - when: Literal["config", "collect", "runtest"], - item: Item | None, - *, - record: bool = True, -) -> Generator[None]: - """Context manager that catches warnings generated in the contained execution block. - - ``item`` can be None if we are not in the context of an item execution. - - Each warning captured triggers the ``pytest_warning_recorded`` hook. - """ - config_filters = config.getini("filterwarnings") - cmdline_filters = config.known_args_namespace.pythonwarnings or [] - with warnings.catch_warnings(record=record) as log: - if not sys.warnoptions: - # If user is not explicitly configuring warning filters, show deprecation warnings by default (#2908). - warnings.filterwarnings("always", category=DeprecationWarning) - warnings.filterwarnings("always", category=PendingDeprecationWarning) - - warnings.filterwarnings("error", category=pytest.PytestRemovedIn9Warning) - - apply_warning_filters(config_filters, cmdline_filters) - - # apply filters from "filterwarnings" marks - nodeid = "" if item is None else item.nodeid - if item is not None: - for mark in item.iter_markers(name="filterwarnings"): - for arg in mark.args: - warnings.filterwarnings(*parse_warning_filter(arg, escape=False)) - - try: - yield - finally: - if record: - # mypy can't infer that record=True means log is not None; help it. - assert log is not None - - for warning_message in log: - ihook.pytest_warning_recorded.call_historic( - kwargs=dict( - warning_message=warning_message, - nodeid=nodeid, - when=when, - location=None, - ) - ) - - -def warning_record_to_str(warning_message: warnings.WarningMessage) -> str: - """Convert a warnings.WarningMessage to a string.""" - return warnings.formatwarning( - str(warning_message.message), - warning_message.category, - warning_message.filename, - warning_message.lineno, - warning_message.line, - ) + tracemalloc_message(warning_message.source) - - -@pytest.hookimpl(wrapper=True, tryfirst=True) -def pytest_runtest_protocol(item: Item) -> Generator[None, object, object]: - with catch_warnings_for_item( - config=item.config, ihook=item.ihook, when="runtest", item=item - ): - return (yield) - - -@pytest.hookimpl(wrapper=True, tryfirst=True) -def pytest_collection(session: Session) -> Generator[None, object, object]: - config = session.config - with catch_warnings_for_item( - config=config, ihook=config.hook, when="collect", item=None - ): - return (yield) - - -@pytest.hookimpl(wrapper=True) -def pytest_terminal_summary( - terminalreporter: TerminalReporter, -) -> Generator[None]: - config = terminalreporter.config - with catch_warnings_for_item( - config=config, ihook=config.hook, when="config", item=None - ): - return (yield) - - -@pytest.hookimpl(wrapper=True) -def pytest_sessionfinish(session: Session) -> Generator[None]: - config = session.config - with catch_warnings_for_item( - config=config, ihook=config.hook, when="config", item=None - ): - return (yield) - - -@pytest.hookimpl(wrapper=True) -def pytest_load_initial_conftests( - early_config: Config, -) -> Generator[None]: - with catch_warnings_for_item( - config=early_config, ihook=early_config.hook, when="config", item=None - ): - return (yield) - - -def pytest_configure(config: Config) -> None: - with ExitStack() as stack: - stack.enter_context( - catch_warnings_for_item( - config=config, - ihook=config.hook, - when="config", - item=None, - # this disables recording because the terminalreporter has - # finished by the time it comes to reporting logged warnings - # from the end of config cleanup. So for now, this is only - # useful for setting a warning filter with an 'error' action. - record=False, - ) - ) - config.addinivalue_line( - "markers", - "filterwarnings(warning): add a warning filter to the given test. " - "see https://docs.pytest.org/en/stable/how-to/capture-warnings.html#pytest-mark-filterwarnings ", - ) - config.add_cleanup(stack.pop_all().close) diff --git a/.venv/lib/python3.12/site-packages/_yaml/__init__.py b/.venv/lib/python3.12/site-packages/_yaml/__init__.py deleted file mode 100644 index 7baa8c4..0000000 --- a/.venv/lib/python3.12/site-packages/_yaml/__init__.py +++ /dev/null @@ -1,33 +0,0 @@ -# This is a stub package designed to roughly emulate the _yaml -# extension module, which previously existed as a standalone module -# and has been moved into the `yaml` package namespace. -# It does not perfectly mimic its old counterpart, but should get -# close enough for anyone who's relying on it even when they shouldn't. -import yaml - -# in some circumstances, the yaml module we imoprted may be from a different version, so we need -# to tread carefully when poking at it here (it may not have the attributes we expect) -if not getattr(yaml, '__with_libyaml__', False): - from sys import version_info - - exc = ModuleNotFoundError if version_info >= (3, 6) else ImportError - raise exc("No module named '_yaml'") -else: - from yaml._yaml import * - import warnings - warnings.warn( - 'The _yaml extension module is now located at yaml._yaml' - ' and its location is subject to change. To use the' - ' LibYAML-based parser and emitter, import from `yaml`:' - ' `from yaml import CLoader as Loader, CDumper as Dumper`.', - DeprecationWarning - ) - del warnings - # Don't `del yaml` here because yaml is actually an existing - # namespace member of _yaml. - -__name__ = '_yaml' -# If the module is top-level (i.e. not a part of any specific package) -# then the attribute should be set to ''. -# https://docs.python.org/3.8/library/types.html -__package__ = '' diff --git a/.venv/lib/python3.12/site-packages/aiofiles-25.1.0.dist-info/INSTALLER b/.venv/lib/python3.12/site-packages/aiofiles-25.1.0.dist-info/INSTALLER deleted file mode 100644 index a1b589e..0000000 --- a/.venv/lib/python3.12/site-packages/aiofiles-25.1.0.dist-info/INSTALLER +++ /dev/null @@ -1 +0,0 @@ -pip diff --git a/.venv/lib/python3.12/site-packages/aiofiles-25.1.0.dist-info/METADATA b/.venv/lib/python3.12/site-packages/aiofiles-25.1.0.dist-info/METADATA deleted file mode 100644 index 9fc5423..0000000 --- a/.venv/lib/python3.12/site-packages/aiofiles-25.1.0.dist-info/METADATA +++ /dev/null @@ -1,209 +0,0 @@ -Metadata-Version: 2.4 -Name: aiofiles -Version: 25.1.0 -Summary: File support for asyncio. -Project-URL: Changelog, https://github.com/Tinche/aiofiles#history -Project-URL: Bug Tracker, https://github.com/Tinche/aiofiles/issues -Project-URL: Repository, https://github.com/Tinche/aiofiles -Author-email: Tin Tvrtkovic -License: Apache-2.0 -License-File: LICENSE -License-File: NOTICE -Classifier: Development Status :: 5 - Production/Stable -Classifier: Framework :: AsyncIO -Classifier: License :: OSI Approved :: Apache Software License -Classifier: Operating System :: OS Independent -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 -Requires-Python: >=3.9 -Description-Content-Type: text/markdown - -# aiofiles: file support for asyncio - -[![PyPI](https://img.shields.io/pypi/v/aiofiles.svg)](https://pypi.python.org/pypi/aiofiles) -[![Build](https://github.com/Tinche/aiofiles/workflows/CI/badge.svg)](https://github.com/Tinche/aiofiles/actions) -[![Coverage](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/Tinche/882f02e3df32136c847ba90d2688f06e/raw/covbadge.json)](https://github.com/Tinche/aiofiles/actions/workflows/main.yml) -[![Supported Python versions](https://img.shields.io/pypi/pyversions/aiofiles.svg)](https://github.com/Tinche/aiofiles) -[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) - -**aiofiles** is an Apache2 licensed library, written in Python, for handling local -disk files in asyncio applications. - -Ordinary local file IO is blocking, and cannot easily and portably be made -asynchronous. This means doing file IO may interfere with asyncio applications, -which shouldn't block the executing thread. aiofiles helps with this by -introducing asynchronous versions of files that support delegating operations to -a separate thread pool. - -```python -async with aiofiles.open('filename', mode='r') as f: - contents = await f.read() -print(contents) -'My file contents' -``` - -Asynchronous iteration is also supported. - -```python -async with aiofiles.open('filename') as f: - async for line in f: - ... -``` - -Asynchronous interface to tempfile module. - -```python -async with aiofiles.tempfile.TemporaryFile('wb') as f: - await f.write(b'Hello, World!') -``` - -## Features - -- a file API very similar to Python's standard, blocking API -- support for buffered and unbuffered binary files, and buffered text files -- support for `async`/`await` ([PEP 492](https://peps.python.org/pep-0492/)) constructs -- async interface to tempfile module - -## Installation - -To install aiofiles, simply: - -```shell -pip install aiofiles -``` - -## Usage - -Files are opened using the `aiofiles.open()` coroutine, which in addition to -mirroring the builtin `open` accepts optional `loop` and `executor` -arguments. If `loop` is absent, the default loop will be used, as per the -set asyncio policy. If `executor` is not specified, the default event loop -executor will be used. - -In case of success, an asynchronous file object is returned with an -API identical to an ordinary file, except the following methods are coroutines -and delegate to an executor: - -- `close` -- `flush` -- `isatty` -- `read` -- `readall` -- `read1` -- `readinto` -- `readline` -- `readlines` -- `seek` -- `seekable` -- `tell` -- `truncate` -- `writable` -- `write` -- `writelines` - -In case of failure, one of the usual exceptions will be raised. - -`aiofiles.stdin`, `aiofiles.stdout`, `aiofiles.stderr`, -`aiofiles.stdin_bytes`, `aiofiles.stdout_bytes`, and -`aiofiles.stderr_bytes` provide async access to `sys.stdin`, -`sys.stdout`, `sys.stderr`, and their corresponding `.buffer` properties. - -The `aiofiles.os` module contains executor-enabled coroutine versions of -several useful `os` functions that deal with files: - -- `stat` -- `statvfs` -- `sendfile` -- `rename` -- `renames` -- `replace` -- `remove` -- `unlink` -- `mkdir` -- `makedirs` -- `rmdir` -- `removedirs` -- `link` -- `symlink` -- `readlink` -- `listdir` -- `scandir` -- `access` -- `getcwd` -- `path.abspath` -- `path.exists` -- `path.isfile` -- `path.isdir` -- `path.islink` -- `path.ismount` -- `path.getsize` -- `path.getatime` -- `path.getctime` -- `path.samefile` -- `path.sameopenfile` - -### Tempfile - -**aiofiles.tempfile** implements the following interfaces: - -- TemporaryFile -- NamedTemporaryFile -- SpooledTemporaryFile -- TemporaryDirectory - -Results return wrapped with a context manager allowing use with async with and async for. - -```python -async with aiofiles.tempfile.NamedTemporaryFile('wb+') as f: - await f.write(b'Line1\n Line2') - await f.seek(0) - async for line in f: - print(line) - -async with aiofiles.tempfile.TemporaryDirectory() as d: - filename = os.path.join(d, "file.ext") -``` - -### Writing tests for aiofiles - -Real file IO can be mocked by patching `aiofiles.threadpool.sync_open` -as desired. The return type also needs to be registered with the -`aiofiles.threadpool.wrap` dispatcher: - -```python -aiofiles.threadpool.wrap.register(mock.MagicMock)( - lambda *args, **kwargs: aiofiles.threadpool.AsyncBufferedIOBase(*args, **kwargs) -) - -async def test_stuff(): - write_data = 'data' - read_file_chunks = [ - b'file chunks 1', - b'file chunks 2', - b'file chunks 3', - b'', - ] - file_chunks_iter = iter(read_file_chunks) - - mock_file_stream = mock.MagicMock( - read=lambda *args, **kwargs: next(file_chunks_iter) - ) - - with mock.patch('aiofiles.threadpool.sync_open', return_value=mock_file_stream) as mock_open: - async with aiofiles.open('filename', 'w') as f: - await f.write(write_data) - assert await f.read() == b'file chunks 1' - - mock_file_stream.write.assert_called_once_with(write_data) -``` - -### Contributing - -Contributions are very welcome. Tests can be run with `tox`, please ensure -the coverage at least stays the same before you submit a pull request. diff --git a/.venv/lib/python3.12/site-packages/aiofiles-25.1.0.dist-info/RECORD b/.venv/lib/python3.12/site-packages/aiofiles-25.1.0.dist-info/RECORD deleted file mode 100644 index 93459bd..0000000 --- a/.venv/lib/python3.12/site-packages/aiofiles-25.1.0.dist-info/RECORD +++ /dev/null @@ -1,26 +0,0 @@ -aiofiles-25.1.0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4 -aiofiles-25.1.0.dist-info/METADATA,sha256=a5a5kHMVigDdsBKlFINLSMPsX3Ms4Fn_zecASBdZqLU,6291 -aiofiles-25.1.0.dist-info/RECORD,, -aiofiles-25.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87 -aiofiles-25.1.0.dist-info/licenses/LICENSE,sha256=y16Ofl9KOYjhBjwULGDcLfdWBfTEZRXnduOspt-XbhQ,11325 -aiofiles-25.1.0.dist-info/licenses/NOTICE,sha256=EExY0dRQvWR0wJ2LZLwBgnM6YKw9jCU-M0zegpRSD_E,55 -aiofiles/__init__.py,sha256=DYqUwak6MVosBjbAsgyEnFFP-HUZCG5h7X4owoeyYHw,345 -aiofiles/__pycache__/__init__.cpython-312.pyc,, -aiofiles/__pycache__/base.cpython-312.pyc,, -aiofiles/__pycache__/os.cpython-312.pyc,, -aiofiles/__pycache__/ospath.cpython-312.pyc,, -aiofiles/base.py,sha256=-fvh41PnictTZL3cg98HoN4h6jdebi5d7Mfh81zOBOc,2046 -aiofiles/os.py,sha256=slJ5oUNHVW1xWVuuIWQiYjw30n3L48H7oX4CJvD_1d4,1078 -aiofiles/ospath.py,sha256=c-Kqw4wMCZ-YRt8Jleb697cANwJQM9qux6lq97949C8,678 -aiofiles/tempfile/__init__.py,sha256=twoC7vaQ-JjFzh2Bbd-3-o0hmExH3CYJUmQcuiVwZfg,10207 -aiofiles/tempfile/__pycache__/__init__.cpython-312.pyc,, -aiofiles/tempfile/__pycache__/temptypes.cpython-312.pyc,, -aiofiles/tempfile/temptypes.py,sha256=3_hlc6l9r5wmino1fDrt4TpFlX4IKoR5IP_bBYVVuHg,2037 -aiofiles/threadpool/__init__.py,sha256=-65UURmzUHsGTXUz0TARdSzyXIfkCFtbczAQLEPpEcU,3140 -aiofiles/threadpool/__pycache__/__init__.cpython-312.pyc,, -aiofiles/threadpool/__pycache__/binary.cpython-312.pyc,, -aiofiles/threadpool/__pycache__/text.cpython-312.pyc,, -aiofiles/threadpool/__pycache__/utils.cpython-312.pyc,, -aiofiles/threadpool/binary.py,sha256=hp-km9VCRu0MLz_wAEUfbCz7OL7xtn9iGAawabpnp5U,2315 -aiofiles/threadpool/text.py,sha256=fNmpw2PEkj0BZSldipJXAgZqVGLxALcfOMiuDQ54Eas,1223 -aiofiles/threadpool/utils.py,sha256=VtIJ9KErbcIT9_Yz4V4rZgNEUjBH3cAYxzKQBMpEzik,1850 diff --git a/.venv/lib/python3.12/site-packages/aiofiles-25.1.0.dist-info/WHEEL b/.venv/lib/python3.12/site-packages/aiofiles-25.1.0.dist-info/WHEEL deleted file mode 100644 index 12228d4..0000000 --- a/.venv/lib/python3.12/site-packages/aiofiles-25.1.0.dist-info/WHEEL +++ /dev/null @@ -1,4 +0,0 @@ -Wheel-Version: 1.0 -Generator: hatchling 1.27.0 -Root-Is-Purelib: true -Tag: py3-none-any diff --git a/.venv/lib/python3.12/site-packages/aiofiles-25.1.0.dist-info/licenses/LICENSE b/.venv/lib/python3.12/site-packages/aiofiles-25.1.0.dist-info/licenses/LICENSE deleted file mode 100644 index e06d208..0000000 --- a/.venv/lib/python3.12/site-packages/aiofiles-25.1.0.dist-info/licenses/LICENSE +++ /dev/null @@ -1,202 +0,0 @@ -Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright {yyyy} {name of copyright owner} - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - diff --git a/.venv/lib/python3.12/site-packages/aiofiles-25.1.0.dist-info/licenses/NOTICE b/.venv/lib/python3.12/site-packages/aiofiles-25.1.0.dist-info/licenses/NOTICE deleted file mode 100644 index d134f28..0000000 --- a/.venv/lib/python3.12/site-packages/aiofiles-25.1.0.dist-info/licenses/NOTICE +++ /dev/null @@ -1,2 +0,0 @@ -Asyncio support for files -Copyright 2016 Tin Tvrtkovic diff --git a/.venv/lib/python3.12/site-packages/aiofiles/__init__.py b/.venv/lib/python3.12/site-packages/aiofiles/__init__.py deleted file mode 100644 index 5f62158..0000000 --- a/.venv/lib/python3.12/site-packages/aiofiles/__init__.py +++ /dev/null @@ -1,23 +0,0 @@ -"""Utilities for asyncio-friendly file handling.""" - -from . import tempfile -from .threadpool import ( - open, - stderr, - stderr_bytes, - stdin, - stdin_bytes, - stdout, - stdout_bytes, -) - -__all__ = [ - "open", - "tempfile", - "stdin", - "stdout", - "stderr", - "stdin_bytes", - "stdout_bytes", - "stderr_bytes", -] diff --git a/.venv/lib/python3.12/site-packages/aiofiles/base.py b/.venv/lib/python3.12/site-packages/aiofiles/base.py deleted file mode 100644 index ef1f81d..0000000 --- a/.venv/lib/python3.12/site-packages/aiofiles/base.py +++ /dev/null @@ -1,79 +0,0 @@ -from asyncio import get_running_loop -from collections.abc import Awaitable -from contextlib import AbstractAsyncContextManager -from functools import partial, wraps - - -def wrap(func): - @wraps(func) - async def run(*args, loop=None, executor=None, **kwargs): - if loop is None: - loop = get_running_loop() - pfunc = partial(func, *args, **kwargs) - return await loop.run_in_executor(executor, pfunc) - - return run - - -class AsyncBase: - def __init__(self, file, loop, executor): - self._file = file - self._executor = executor - self._ref_loop = loop - - @property - def _loop(self): - return self._ref_loop or get_running_loop() - - def __aiter__(self): - """We are our own iterator.""" - return self - - def __repr__(self): - return super().__repr__() + " wrapping " + repr(self._file) - - async def __anext__(self): - """Simulate normal file iteration.""" - - if line := await self.readline(): - return line - raise StopAsyncIteration - - -class AsyncIndirectBase(AsyncBase): - def __init__(self, name, loop, executor, indirect): - self._indirect = indirect - self._name = name - super().__init__(None, loop, executor) - - @property - def _file(self): - return self._indirect() - - @_file.setter - def _file(self, v): - pass # discard writes - - -class AiofilesContextManager(Awaitable, AbstractAsyncContextManager): - """An adjusted async context manager for aiofiles.""" - - __slots__ = ("_coro", "_obj") - - def __init__(self, coro): - self._coro = coro - self._obj = None - - def __await__(self): - if self._obj is None: - self._obj = yield from self._coro.__await__() - return self._obj - - async def __aenter__(self): - return await self - - async def __aexit__(self, exc_type, exc_val, exc_tb): - await get_running_loop().run_in_executor( - None, self._obj._file.__exit__, exc_type, exc_val, exc_tb - ) - self._obj = None diff --git a/.venv/lib/python3.12/site-packages/aiofiles/os.py b/.venv/lib/python3.12/site-packages/aiofiles/os.py deleted file mode 100644 index 153d65d..0000000 --- a/.venv/lib/python3.12/site-packages/aiofiles/os.py +++ /dev/null @@ -1,61 +0,0 @@ -"""Async executor versions of file functions from the os module.""" - -import os - -from . import ospath as path -from .base import wrap - -__all__ = [ - "path", - "stat", - "rename", - "renames", - "replace", - "remove", - "unlink", - "mkdir", - "makedirs", - "rmdir", - "removedirs", - "symlink", - "readlink", - "listdir", - "scandir", - "access", - "wrap", - "getcwd", -] - -access = wrap(os.access) - -getcwd = wrap(os.getcwd) - -listdir = wrap(os.listdir) - -makedirs = wrap(os.makedirs) -mkdir = wrap(os.mkdir) - -readlink = wrap(os.readlink) -remove = wrap(os.remove) -removedirs = wrap(os.removedirs) -rename = wrap(os.rename) -renames = wrap(os.renames) -replace = wrap(os.replace) -rmdir = wrap(os.rmdir) - -scandir = wrap(os.scandir) -stat = wrap(os.stat) -symlink = wrap(os.symlink) - -unlink = wrap(os.unlink) - - -if hasattr(os, "link"): - __all__ += ["link"] - link = wrap(os.link) -if hasattr(os, "sendfile"): - __all__ += ["sendfile"] - sendfile = wrap(os.sendfile) -if hasattr(os, "statvfs"): - __all__ += ["statvfs"] - statvfs = wrap(os.statvfs) diff --git a/.venv/lib/python3.12/site-packages/aiofiles/ospath.py b/.venv/lib/python3.12/site-packages/aiofiles/ospath.py deleted file mode 100644 index f47f150..0000000 --- a/.venv/lib/python3.12/site-packages/aiofiles/ospath.py +++ /dev/null @@ -1,37 +0,0 @@ -"""Async executor versions of file functions from the os.path module.""" - -from os import path - -from .base import wrap - -__all__ = [ - "abspath", - "getatime", - "getctime", - "getmtime", - "getsize", - "exists", - "isdir", - "isfile", - "islink", - "ismount", - "samefile", - "sameopenfile", -] - -abspath = wrap(path.abspath) - -getatime = wrap(path.getatime) -getctime = wrap(path.getctime) -getmtime = wrap(path.getmtime) -getsize = wrap(path.getsize) - -exists = wrap(path.exists) - -isdir = wrap(path.isdir) -isfile = wrap(path.isfile) -islink = wrap(path.islink) -ismount = wrap(path.ismount) - -samefile = wrap(path.samefile) -sameopenfile = wrap(path.sameopenfile) diff --git a/.venv/lib/python3.12/site-packages/aiofiles/tempfile/__init__.py b/.venv/lib/python3.12/site-packages/aiofiles/tempfile/__init__.py deleted file mode 100644 index b1c32c8..0000000 --- a/.venv/lib/python3.12/site-packages/aiofiles/tempfile/__init__.py +++ /dev/null @@ -1,357 +0,0 @@ -import asyncio -import sys -from functools import partial, singledispatch -from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOBase -from tempfile import NamedTemporaryFile as syncNamedTemporaryFile -from tempfile import SpooledTemporaryFile as syncSpooledTemporaryFile -from tempfile import TemporaryDirectory as syncTemporaryDirectory -from tempfile import TemporaryFile as syncTemporaryFile -from tempfile import _TemporaryFileWrapper as syncTemporaryFileWrapper - -from ..base import AiofilesContextManager -from ..threadpool.binary import AsyncBufferedIOBase, AsyncBufferedReader, AsyncFileIO -from ..threadpool.text import AsyncTextIOWrapper -from .temptypes import AsyncSpooledTemporaryFile, AsyncTemporaryDirectory - -__all__ = [ - "NamedTemporaryFile", - "TemporaryFile", - "SpooledTemporaryFile", - "TemporaryDirectory", -] - - -# ================================================================ -# Public methods for async open and return of temp file/directory -# objects with async interface -# ================================================================ -if sys.version_info >= (3, 12): - - def NamedTemporaryFile( - mode="w+b", - buffering=-1, - encoding=None, - newline=None, - suffix=None, - prefix=None, - dir=None, - delete=True, - delete_on_close=True, - loop=None, - executor=None, - ): - """Async open a named temporary file""" - return AiofilesContextManager( - _temporary_file( - named=True, - mode=mode, - buffering=buffering, - encoding=encoding, - newline=newline, - suffix=suffix, - prefix=prefix, - dir=dir, - delete=delete, - delete_on_close=delete_on_close, - loop=loop, - executor=executor, - ) - ) - -else: - - def NamedTemporaryFile( - mode="w+b", - buffering=-1, - encoding=None, - newline=None, - suffix=None, - prefix=None, - dir=None, - delete=True, - loop=None, - executor=None, - ): - """Async open a named temporary file""" - return AiofilesContextManager( - _temporary_file( - named=True, - mode=mode, - buffering=buffering, - encoding=encoding, - newline=newline, - suffix=suffix, - prefix=prefix, - dir=dir, - delete=delete, - loop=loop, - executor=executor, - ) - ) - - -def TemporaryFile( - mode="w+b", - buffering=-1, - encoding=None, - newline=None, - suffix=None, - prefix=None, - dir=None, - loop=None, - executor=None, -): - """Async open an unnamed temporary file""" - return AiofilesContextManager( - _temporary_file( - named=False, - mode=mode, - buffering=buffering, - encoding=encoding, - newline=newline, - suffix=suffix, - prefix=prefix, - dir=dir, - loop=loop, - executor=executor, - ) - ) - - -def SpooledTemporaryFile( - max_size=0, - mode="w+b", - buffering=-1, - encoding=None, - newline=None, - suffix=None, - prefix=None, - dir=None, - loop=None, - executor=None, -): - """Async open a spooled temporary file""" - return AiofilesContextManager( - _spooled_temporary_file( - max_size=max_size, - mode=mode, - buffering=buffering, - encoding=encoding, - newline=newline, - suffix=suffix, - prefix=prefix, - dir=dir, - loop=loop, - executor=executor, - ) - ) - - -def TemporaryDirectory(suffix=None, prefix=None, dir=None, loop=None, executor=None): - """Async open a temporary directory""" - return AiofilesContextManagerTempDir( - _temporary_directory( - suffix=suffix, prefix=prefix, dir=dir, loop=loop, executor=executor - ) - ) - - -# ========================================================= -# Internal coroutines to open new temp files/directories -# ========================================================= -if sys.version_info >= (3, 12): - - async def _temporary_file( - named=True, - mode="w+b", - buffering=-1, - encoding=None, - newline=None, - suffix=None, - prefix=None, - dir=None, - delete=True, - delete_on_close=True, - loop=None, - executor=None, - max_size=0, - ): - """Async method to open a temporary file with async interface""" - if loop is None: - loop = asyncio.get_running_loop() - - if named: - cb = partial( - syncNamedTemporaryFile, - mode=mode, - buffering=buffering, - encoding=encoding, - newline=newline, - suffix=suffix, - prefix=prefix, - dir=dir, - delete=delete, - delete_on_close=delete_on_close, - ) - else: - cb = partial( - syncTemporaryFile, - mode=mode, - buffering=buffering, - encoding=encoding, - newline=newline, - suffix=suffix, - prefix=prefix, - dir=dir, - ) - - f = await loop.run_in_executor(executor, cb) - - # Wrap based on type of underlying IO object - if type(f) is syncTemporaryFileWrapper: - # _TemporaryFileWrapper was used (named files) - result = wrap(f.file, f, loop=loop, executor=executor) - result._closer = f._closer - return result - # IO object was returned directly without wrapper - return wrap(f, f, loop=loop, executor=executor) - -else: - - async def _temporary_file( - named=True, - mode="w+b", - buffering=-1, - encoding=None, - newline=None, - suffix=None, - prefix=None, - dir=None, - delete=True, - loop=None, - executor=None, - max_size=0, - ): - """Async method to open a temporary file with async interface""" - if loop is None: - loop = asyncio.get_running_loop() - - if named: - cb = partial( - syncNamedTemporaryFile, - mode=mode, - buffering=buffering, - encoding=encoding, - newline=newline, - suffix=suffix, - prefix=prefix, - dir=dir, - delete=delete, - ) - else: - cb = partial( - syncTemporaryFile, - mode=mode, - buffering=buffering, - encoding=encoding, - newline=newline, - suffix=suffix, - prefix=prefix, - dir=dir, - ) - - f = await loop.run_in_executor(executor, cb) - - # Wrap based on type of underlying IO object - if type(f) is syncTemporaryFileWrapper: - # _TemporaryFileWrapper was used (named files) - result = wrap(f.file, f, loop=loop, executor=executor) - # add delete property - result.delete = f.delete - return result - # IO object was returned directly without wrapper - return wrap(f, f, loop=loop, executor=executor) - - -async def _spooled_temporary_file( - max_size=0, - mode="w+b", - buffering=-1, - encoding=None, - newline=None, - suffix=None, - prefix=None, - dir=None, - loop=None, - executor=None, -): - """Open a spooled temporary file with async interface""" - if loop is None: - loop = asyncio.get_running_loop() - - cb = partial( - syncSpooledTemporaryFile, - max_size=max_size, - mode=mode, - buffering=buffering, - encoding=encoding, - newline=newline, - suffix=suffix, - prefix=prefix, - dir=dir, - ) - - f = await loop.run_in_executor(executor, cb) - - # Single interface provided by SpooledTemporaryFile for all modes - return AsyncSpooledTemporaryFile(f, loop=loop, executor=executor) - - -async def _temporary_directory( - suffix=None, prefix=None, dir=None, loop=None, executor=None -): - """Async method to open a temporary directory with async interface""" - if loop is None: - loop = asyncio.get_running_loop() - - cb = partial(syncTemporaryDirectory, suffix, prefix, dir) - f = await loop.run_in_executor(executor, cb) - - return AsyncTemporaryDirectory(f, loop=loop, executor=executor) - - -class AiofilesContextManagerTempDir(AiofilesContextManager): - """With returns the directory location, not the object (matching sync lib)""" - - async def __aenter__(self): - self._obj = await self._coro - return self._obj.name - - -@singledispatch -def wrap(base_io_obj, file, *, loop=None, executor=None): - """Wrap the object with interface based on type of underlying IO""" - - msg = f"Unsupported IO type: {base_io_obj}" - raise TypeError(msg) - - -@wrap.register(TextIOBase) -def _(base_io_obj, file, *, loop=None, executor=None): - return AsyncTextIOWrapper(file, loop=loop, executor=executor) - - -@wrap.register(BufferedWriter) -def _(base_io_obj, file, *, loop=None, executor=None): - return AsyncBufferedIOBase(file, loop=loop, executor=executor) - - -@wrap.register(BufferedReader) -@wrap.register(BufferedRandom) -def _(base_io_obj, file, *, loop=None, executor=None): - return AsyncBufferedReader(file, loop=loop, executor=executor) - - -@wrap.register(FileIO) -def _(base_io_obj, file, *, loop=None, executor=None): - return AsyncFileIO(file, loop=loop, executor=executor) diff --git a/.venv/lib/python3.12/site-packages/aiofiles/tempfile/temptypes.py b/.venv/lib/python3.12/site-packages/aiofiles/tempfile/temptypes.py deleted file mode 100644 index 8ae5032..0000000 --- a/.venv/lib/python3.12/site-packages/aiofiles/tempfile/temptypes.py +++ /dev/null @@ -1,70 +0,0 @@ -"""Async wrappers for spooled temp files and temp directory objects""" - -from functools import partial - -from ..base import AsyncBase -from ..threadpool.utils import ( - cond_delegate_to_executor, - delegate_to_executor, - proxy_property_directly, -) - - -@delegate_to_executor("fileno", "rollover") -@cond_delegate_to_executor( - "close", - "flush", - "isatty", - "read", - "readline", - "readlines", - "seek", - "tell", - "truncate", -) -@proxy_property_directly("closed", "encoding", "mode", "name", "newlines") -class AsyncSpooledTemporaryFile(AsyncBase): - """Async wrapper for SpooledTemporaryFile class""" - - async def _check(self): - if self._file._rolled: - return - max_size = self._file._max_size - if max_size and self._file.tell() > max_size: - await self.rollover() - - async def write(self, s): - """Implementation to anticipate rollover""" - if self._file._rolled: - cb = partial(self._file.write, s) - return await self._loop.run_in_executor(self._executor, cb) - - file = self._file._file # reference underlying base IO object - rv = file.write(s) - await self._check() - return rv - - async def writelines(self, iterable): - """Implementation to anticipate rollover""" - if self._file._rolled: - cb = partial(self._file.writelines, iterable) - return await self._loop.run_in_executor(self._executor, cb) - - file = self._file._file # reference underlying base IO object - rv = file.writelines(iterable) - await self._check() - return rv - - -@delegate_to_executor("cleanup") -@proxy_property_directly("name") -class AsyncTemporaryDirectory: - """Async wrapper for TemporaryDirectory class""" - - def __init__(self, file, loop, executor): - self._file = file - self._loop = loop - self._executor = executor - - async def close(self): - await self.cleanup() diff --git a/.venv/lib/python3.12/site-packages/aiofiles/threadpool/__init__.py b/.venv/lib/python3.12/site-packages/aiofiles/threadpool/__init__.py deleted file mode 100644 index 8054034..0000000 --- a/.venv/lib/python3.12/site-packages/aiofiles/threadpool/__init__.py +++ /dev/null @@ -1,141 +0,0 @@ -"""Handle files using a thread pool executor.""" - -import asyncio -import sys -from functools import partial, singledispatch -from io import ( - BufferedIOBase, - BufferedRandom, - BufferedReader, - BufferedWriter, - FileIO, - TextIOBase, -) - -from ..base import AiofilesContextManager -from .binary import ( - AsyncBufferedIOBase, - AsyncBufferedReader, - AsyncFileIO, - AsyncIndirectBufferedIOBase, -) -from .text import AsyncTextIndirectIOWrapper, AsyncTextIOWrapper - -sync_open = open - -__all__ = ( - "open", - "stdin", - "stdout", - "stderr", - "stdin_bytes", - "stdout_bytes", - "stderr_bytes", -) - - -def open( - file, - mode="r", - buffering=-1, - encoding=None, - errors=None, - newline=None, - closefd=True, - opener=None, - *, - loop=None, - executor=None, -): - return AiofilesContextManager( - _open( - file, - mode=mode, - buffering=buffering, - encoding=encoding, - errors=errors, - newline=newline, - closefd=closefd, - opener=opener, - loop=loop, - executor=executor, - ) - ) - - -async def _open( - file, - mode="r", - buffering=-1, - encoding=None, - errors=None, - newline=None, - closefd=True, - opener=None, - *, - loop=None, - executor=None, -): - """Open an asyncio file.""" - if loop is None: - loop = asyncio.get_running_loop() - cb = partial( - sync_open, - file, - mode=mode, - buffering=buffering, - encoding=encoding, - errors=errors, - newline=newline, - closefd=closefd, - opener=opener, - ) - f = await loop.run_in_executor(executor, cb) - - return wrap(f, loop=loop, executor=executor) - - -@singledispatch -def wrap(file, *, loop=None, executor=None): - msg = f"Unsupported io type: {file}." - raise TypeError(msg) - - -@wrap.register(TextIOBase) -def _(file, *, loop=None, executor=None): - return AsyncTextIOWrapper(file, loop=loop, executor=executor) - - -@wrap.register(BufferedWriter) -@wrap.register(BufferedIOBase) -def _(file, *, loop=None, executor=None): - return AsyncBufferedIOBase(file, loop=loop, executor=executor) - - -@wrap.register(BufferedReader) -@wrap.register(BufferedRandom) -def _(file, *, loop=None, executor=None): - return AsyncBufferedReader(file, loop=loop, executor=executor) - - -@wrap.register(FileIO) -def _(file, *, loop=None, executor=None): - return AsyncFileIO(file, loop=loop, executor=executor) - - -stdin = AsyncTextIndirectIOWrapper("sys.stdin", None, None, indirect=lambda: sys.stdin) -stdout = AsyncTextIndirectIOWrapper( - "sys.stdout", None, None, indirect=lambda: sys.stdout -) -stderr = AsyncTextIndirectIOWrapper( - "sys.stderr", None, None, indirect=lambda: sys.stderr -) -stdin_bytes = AsyncIndirectBufferedIOBase( - "sys.stdin.buffer", None, None, indirect=lambda: sys.stdin.buffer -) -stdout_bytes = AsyncIndirectBufferedIOBase( - "sys.stdout.buffer", None, None, indirect=lambda: sys.stdout.buffer -) -stderr_bytes = AsyncIndirectBufferedIOBase( - "sys.stderr.buffer", None, None, indirect=lambda: sys.stderr.buffer -) diff --git a/.venv/lib/python3.12/site-packages/aiofiles/threadpool/binary.py b/.venv/lib/python3.12/site-packages/aiofiles/threadpool/binary.py deleted file mode 100644 index 63fcaff..0000000 --- a/.venv/lib/python3.12/site-packages/aiofiles/threadpool/binary.py +++ /dev/null @@ -1,104 +0,0 @@ -from ..base import AsyncBase, AsyncIndirectBase -from .utils import delegate_to_executor, proxy_method_directly, proxy_property_directly - - -@delegate_to_executor( - "close", - "flush", - "isatty", - "read", - "read1", - "readinto", - "readline", - "readlines", - "seek", - "seekable", - "tell", - "truncate", - "writable", - "write", - "writelines", -) -@proxy_method_directly("detach", "fileno", "readable") -@proxy_property_directly("closed", "raw", "name", "mode") -class AsyncBufferedIOBase(AsyncBase): - """The asyncio executor version of io.BufferedWriter and BufferedIOBase.""" - - -@delegate_to_executor("peek") -class AsyncBufferedReader(AsyncBufferedIOBase): - """The asyncio executor version of io.BufferedReader and Random.""" - - -@delegate_to_executor( - "close", - "flush", - "isatty", - "read", - "readall", - "readinto", - "readline", - "readlines", - "seek", - "seekable", - "tell", - "truncate", - "writable", - "write", - "writelines", -) -@proxy_method_directly("fileno", "readable") -@proxy_property_directly("closed", "name", "mode") -class AsyncFileIO(AsyncBase): - """The asyncio executor version of io.FileIO.""" - - -@delegate_to_executor( - "close", - "flush", - "isatty", - "read", - "read1", - "readinto", - "readline", - "readlines", - "seek", - "seekable", - "tell", - "truncate", - "writable", - "write", - "writelines", -) -@proxy_method_directly("detach", "fileno", "readable") -@proxy_property_directly("closed", "raw", "name", "mode") -class AsyncIndirectBufferedIOBase(AsyncIndirectBase): - """The indirect asyncio executor version of io.BufferedWriter and BufferedIOBase.""" - - -@delegate_to_executor("peek") -class AsyncIndirectBufferedReader(AsyncIndirectBufferedIOBase): - """The indirect asyncio executor version of io.BufferedReader and Random.""" - - -@delegate_to_executor( - "close", - "flush", - "isatty", - "read", - "readall", - "readinto", - "readline", - "readlines", - "seek", - "seekable", - "tell", - "truncate", - "writable", - "write", - "writelines", -) -@proxy_method_directly("fileno", "readable") -@proxy_property_directly("closed", "name", "mode") -class AsyncIndirectFileIO(AsyncIndirectBase): - """The indirect asyncio executor version of io.FileIO.""" diff --git a/.venv/lib/python3.12/site-packages/aiofiles/threadpool/text.py b/.venv/lib/python3.12/site-packages/aiofiles/threadpool/text.py deleted file mode 100644 index 0e62590..0000000 --- a/.venv/lib/python3.12/site-packages/aiofiles/threadpool/text.py +++ /dev/null @@ -1,64 +0,0 @@ -from ..base import AsyncBase, AsyncIndirectBase -from .utils import delegate_to_executor, proxy_method_directly, proxy_property_directly - - -@delegate_to_executor( - "close", - "flush", - "isatty", - "read", - "readable", - "readline", - "readlines", - "seek", - "seekable", - "tell", - "truncate", - "write", - "writable", - "writelines", -) -@proxy_method_directly("detach", "fileno", "readable") -@proxy_property_directly( - "buffer", - "closed", - "encoding", - "errors", - "line_buffering", - "newlines", - "name", - "mode", -) -class AsyncTextIOWrapper(AsyncBase): - """The asyncio executor version of io.TextIOWrapper.""" - - -@delegate_to_executor( - "close", - "flush", - "isatty", - "read", - "readable", - "readline", - "readlines", - "seek", - "seekable", - "tell", - "truncate", - "write", - "writable", - "writelines", -) -@proxy_method_directly("detach", "fileno", "readable") -@proxy_property_directly( - "buffer", - "closed", - "encoding", - "errors", - "line_buffering", - "newlines", - "name", - "mode", -) -class AsyncTextIndirectIOWrapper(AsyncIndirectBase): - """The indirect asyncio executor version of io.TextIOWrapper.""" diff --git a/.venv/lib/python3.12/site-packages/aiofiles/threadpool/utils.py b/.venv/lib/python3.12/site-packages/aiofiles/threadpool/utils.py deleted file mode 100644 index fd9767a..0000000 --- a/.venv/lib/python3.12/site-packages/aiofiles/threadpool/utils.py +++ /dev/null @@ -1,71 +0,0 @@ -import functools - - -def delegate_to_executor(*attrs): - def cls_builder(cls): - for attr_name in attrs: - setattr(cls, attr_name, _make_delegate_method(attr_name)) - return cls - - return cls_builder - - -def proxy_method_directly(*attrs): - def cls_builder(cls): - for attr_name in attrs: - setattr(cls, attr_name, _make_proxy_method(attr_name)) - return cls - - return cls_builder - - -def proxy_property_directly(*attrs): - def cls_builder(cls): - for attr_name in attrs: - setattr(cls, attr_name, _make_proxy_property(attr_name)) - return cls - - return cls_builder - - -def cond_delegate_to_executor(*attrs): - def cls_builder(cls): - for attr_name in attrs: - setattr(cls, attr_name, _make_cond_delegate_method(attr_name)) - return cls - - return cls_builder - - -def _make_delegate_method(attr_name): - async def method(self, *args, **kwargs): - cb = functools.partial(getattr(self._file, attr_name), *args, **kwargs) - return await self._loop.run_in_executor(self._executor, cb) - - return method - - -def _make_proxy_method(attr_name): - def method(self, *args, **kwargs): - return getattr(self._file, attr_name)(*args, **kwargs) - - return method - - -def _make_proxy_property(attr_name): - def proxy_property(self): - return getattr(self._file, attr_name) - - return property(proxy_property) - - -def _make_cond_delegate_method(attr_name): - """For spooled temp files, delegate only if rolled to file object""" - - async def method(self, *args, **kwargs): - if self._file._rolled: - cb = functools.partial(getattr(self._file, attr_name), *args, **kwargs) - return await self._loop.run_in_executor(self._executor, cb) - return getattr(self._file, attr_name)(*args, **kwargs) - - return method diff --git a/.venv/lib/python3.12/site-packages/annotated_types-0.7.0.dist-info/INSTALLER b/.venv/lib/python3.12/site-packages/annotated_types-0.7.0.dist-info/INSTALLER deleted file mode 100644 index a1b589e..0000000 --- a/.venv/lib/python3.12/site-packages/annotated_types-0.7.0.dist-info/INSTALLER +++ /dev/null @@ -1 +0,0 @@ -pip diff --git a/.venv/lib/python3.12/site-packages/annotated_types-0.7.0.dist-info/METADATA b/.venv/lib/python3.12/site-packages/annotated_types-0.7.0.dist-info/METADATA deleted file mode 100644 index 3ac05cf..0000000 --- a/.venv/lib/python3.12/site-packages/annotated_types-0.7.0.dist-info/METADATA +++ /dev/null @@ -1,295 +0,0 @@ -Metadata-Version: 2.3 -Name: annotated-types -Version: 0.7.0 -Summary: Reusable constraint types to use with typing.Annotated -Project-URL: Homepage, https://github.com/annotated-types/annotated-types -Project-URL: Source, https://github.com/annotated-types/annotated-types -Project-URL: Changelog, https://github.com/annotated-types/annotated-types/releases -Author-email: Adrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com>, Samuel Colvin , Zac Hatfield-Dodds -License-File: LICENSE -Classifier: Development Status :: 4 - Beta -Classifier: Environment :: Console -Classifier: Environment :: MacOS X -Classifier: Intended Audience :: Developers -Classifier: Intended Audience :: Information Technology -Classifier: License :: OSI Approved :: MIT License -Classifier: Operating System :: POSIX :: Linux -Classifier: Operating System :: Unix -Classifier: Programming Language :: Python :: 3 :: Only -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: Topic :: Software Development :: Libraries :: Python Modules -Classifier: Typing :: Typed -Requires-Python: >=3.8 -Requires-Dist: typing-extensions>=4.0.0; python_version < '3.9' -Description-Content-Type: text/markdown - -# annotated-types - -[![CI](https://github.com/annotated-types/annotated-types/workflows/CI/badge.svg?event=push)](https://github.com/annotated-types/annotated-types/actions?query=event%3Apush+branch%3Amain+workflow%3ACI) -[![pypi](https://img.shields.io/pypi/v/annotated-types.svg)](https://pypi.python.org/pypi/annotated-types) -[![versions](https://img.shields.io/pypi/pyversions/annotated-types.svg)](https://github.com/annotated-types/annotated-types) -[![license](https://img.shields.io/github/license/annotated-types/annotated-types.svg)](https://github.com/annotated-types/annotated-types/blob/main/LICENSE) - -[PEP-593](https://peps.python.org/pep-0593/) added `typing.Annotated` as a way of -adding context-specific metadata to existing types, and specifies that -`Annotated[T, x]` _should_ be treated as `T` by any tool or library without special -logic for `x`. - -This package provides metadata objects which can be used to represent common -constraints such as upper and lower bounds on scalar values and collection sizes, -a `Predicate` marker for runtime checks, and -descriptions of how we intend these metadata to be interpreted. In some cases, -we also note alternative representations which do not require this package. - -## Install - -```bash -pip install annotated-types -``` - -## Examples - -```python -from typing import Annotated -from annotated_types import Gt, Len, Predicate - -class MyClass: - age: Annotated[int, Gt(18)] # Valid: 19, 20, ... - # Invalid: 17, 18, "19", 19.0, ... - factors: list[Annotated[int, Predicate(is_prime)]] # Valid: 2, 3, 5, 7, 11, ... - # Invalid: 4, 8, -2, 5.0, "prime", ... - - my_list: Annotated[list[int], Len(0, 10)] # Valid: [], [10, 20, 30, 40, 50] - # Invalid: (1, 2), ["abc"], [0] * 20 -``` - -## Documentation - -_While `annotated-types` avoids runtime checks for performance, users should not -construct invalid combinations such as `MultipleOf("non-numeric")` or `Annotated[int, Len(3)]`. -Downstream implementors may choose to raise an error, emit a warning, silently ignore -a metadata item, etc., if the metadata objects described below are used with an -incompatible type - or for any other reason!_ - -### Gt, Ge, Lt, Le - -Express inclusive and/or exclusive bounds on orderable values - which may be numbers, -dates, times, strings, sets, etc. Note that the boundary value need not be of the -same type that was annotated, so long as they can be compared: `Annotated[int, Gt(1.5)]` -is fine, for example, and implies that the value is an integer x such that `x > 1.5`. - -We suggest that implementors may also interpret `functools.partial(operator.le, 1.5)` -as being equivalent to `Gt(1.5)`, for users who wish to avoid a runtime dependency on -the `annotated-types` package. - -To be explicit, these types have the following meanings: - -* `Gt(x)` - value must be "Greater Than" `x` - equivalent to exclusive minimum -* `Ge(x)` - value must be "Greater than or Equal" to `x` - equivalent to inclusive minimum -* `Lt(x)` - value must be "Less Than" `x` - equivalent to exclusive maximum -* `Le(x)` - value must be "Less than or Equal" to `x` - equivalent to inclusive maximum - -### Interval - -`Interval(gt, ge, lt, le)` allows you to specify an upper and lower bound with a single -metadata object. `None` attributes should be ignored, and non-`None` attributes -treated as per the single bounds above. - -### MultipleOf - -`MultipleOf(multiple_of=x)` might be interpreted in two ways: - -1. Python semantics, implying `value % multiple_of == 0`, or -2. [JSONschema semantics](https://json-schema.org/draft/2020-12/json-schema-validation.html#rfc.section.6.2.1), - where `int(value / multiple_of) == value / multiple_of`. - -We encourage users to be aware of these two common interpretations and their -distinct behaviours, especially since very large or non-integer numbers make -it easy to cause silent data corruption due to floating-point imprecision. - -We encourage libraries to carefully document which interpretation they implement. - -### MinLen, MaxLen, Len - -`Len()` implies that `min_length <= len(value) <= max_length` - lower and upper bounds are inclusive. - -As well as `Len()` which can optionally include upper and lower bounds, we also -provide `MinLen(x)` and `MaxLen(y)` which are equivalent to `Len(min_length=x)` -and `Len(max_length=y)` respectively. - -`Len`, `MinLen`, and `MaxLen` may be used with any type which supports `len(value)`. - -Examples of usage: - -* `Annotated[list, MaxLen(10)]` (or `Annotated[list, Len(max_length=10))`) - list must have a length of 10 or less -* `Annotated[str, MaxLen(10)]` - string must have a length of 10 or less -* `Annotated[list, MinLen(3))` (or `Annotated[list, Len(min_length=3))`) - list must have a length of 3 or more -* `Annotated[list, Len(4, 6)]` - list must have a length of 4, 5, or 6 -* `Annotated[list, Len(8, 8)]` - list must have a length of exactly 8 - -#### Changed in v0.4.0 - -* `min_inclusive` has been renamed to `min_length`, no change in meaning -* `max_exclusive` has been renamed to `max_length`, upper bound is now **inclusive** instead of **exclusive** -* The recommendation that slices are interpreted as `Len` has been removed due to ambiguity and different semantic - meaning of the upper bound in slices vs. `Len` - -See [issue #23](https://github.com/annotated-types/annotated-types/issues/23) for discussion. - -### Timezone - -`Timezone` can be used with a `datetime` or a `time` to express which timezones -are allowed. `Annotated[datetime, Timezone(None)]` must be a naive datetime. -`Timezone[...]` ([literal ellipsis](https://docs.python.org/3/library/constants.html#Ellipsis)) -expresses that any timezone-aware datetime is allowed. You may also pass a specific -timezone string or [`tzinfo`](https://docs.python.org/3/library/datetime.html#tzinfo-objects) -object such as `Timezone(timezone.utc)` or `Timezone("Africa/Abidjan")` to express that you only -allow a specific timezone, though we note that this is often a symptom of fragile design. - -#### Changed in v0.x.x - -* `Timezone` accepts [`tzinfo`](https://docs.python.org/3/library/datetime.html#tzinfo-objects) objects instead of - `timezone`, extending compatibility to [`zoneinfo`](https://docs.python.org/3/library/zoneinfo.html) and third party libraries. - -### Unit - -`Unit(unit: str)` expresses that the annotated numeric value is the magnitude of -a quantity with the specified unit. For example, `Annotated[float, Unit("m/s")]` -would be a float representing a velocity in meters per second. - -Please note that `annotated_types` itself makes no attempt to parse or validate -the unit string in any way. That is left entirely to downstream libraries, -such as [`pint`](https://pint.readthedocs.io) or -[`astropy.units`](https://docs.astropy.org/en/stable/units/). - -An example of how a library might use this metadata: - -```python -from annotated_types import Unit -from typing import Annotated, TypeVar, Callable, Any, get_origin, get_args - -# given a type annotated with a unit: -Meters = Annotated[float, Unit("m")] - - -# you can cast the annotation to a specific unit type with any -# callable that accepts a string and returns the desired type -T = TypeVar("T") -def cast_unit(tp: Any, unit_cls: Callable[[str], T]) -> T | None: - if get_origin(tp) is Annotated: - for arg in get_args(tp): - if isinstance(arg, Unit): - return unit_cls(arg.unit) - return None - - -# using `pint` -import pint -pint_unit = cast_unit(Meters, pint.Unit) - - -# using `astropy.units` -import astropy.units as u -astropy_unit = cast_unit(Meters, u.Unit) -``` - -### Predicate - -`Predicate(func: Callable)` expresses that `func(value)` is truthy for valid values. -Users should prefer the statically inspectable metadata above, but if you need -the full power and flexibility of arbitrary runtime predicates... here it is. - -For some common constraints, we provide generic types: - -* `IsLower = Annotated[T, Predicate(str.islower)]` -* `IsUpper = Annotated[T, Predicate(str.isupper)]` -* `IsDigit = Annotated[T, Predicate(str.isdigit)]` -* `IsFinite = Annotated[T, Predicate(math.isfinite)]` -* `IsNotFinite = Annotated[T, Predicate(Not(math.isfinite))]` -* `IsNan = Annotated[T, Predicate(math.isnan)]` -* `IsNotNan = Annotated[T, Predicate(Not(math.isnan))]` -* `IsInfinite = Annotated[T, Predicate(math.isinf)]` -* `IsNotInfinite = Annotated[T, Predicate(Not(math.isinf))]` - -so that you can write e.g. `x: IsFinite[float] = 2.0` instead of the longer -(but exactly equivalent) `x: Annotated[float, Predicate(math.isfinite)] = 2.0`. - -Some libraries might have special logic to handle known or understandable predicates, -for example by checking for `str.isdigit` and using its presence to both call custom -logic to enforce digit-only strings, and customise some generated external schema. -Users are therefore encouraged to avoid indirection like `lambda s: s.lower()`, in -favor of introspectable methods such as `str.lower` or `re.compile("pattern").search`. - -To enable basic negation of commonly used predicates like `math.isnan` without introducing introspection that makes it impossible for implementers to introspect the predicate we provide a `Not` wrapper that simply negates the predicate in an introspectable manner. Several of the predicates listed above are created in this manner. - -We do not specify what behaviour should be expected for predicates that raise -an exception. For example `Annotated[int, Predicate(str.isdigit)]` might silently -skip invalid constraints, or statically raise an error; or it might try calling it -and then propagate or discard the resulting -`TypeError: descriptor 'isdigit' for 'str' objects doesn't apply to a 'int' object` -exception. We encourage libraries to document the behaviour they choose. - -### Doc - -`doc()` can be used to add documentation information in `Annotated`, for function and method parameters, variables, class attributes, return types, and any place where `Annotated` can be used. - -It expects a value that can be statically analyzed, as the main use case is for static analysis, editors, documentation generators, and similar tools. - -It returns a `DocInfo` class with a single attribute `documentation` containing the value passed to `doc()`. - -This is the early adopter's alternative form of the [`typing-doc` proposal](https://github.com/tiangolo/fastapi/blob/typing-doc/typing_doc.md). - -### Integrating downstream types with `GroupedMetadata` - -Implementers may choose to provide a convenience wrapper that groups multiple pieces of metadata. -This can help reduce verbosity and cognitive overhead for users. -For example, an implementer like Pydantic might provide a `Field` or `Meta` type that accepts keyword arguments and transforms these into low-level metadata: - -```python -from dataclasses import dataclass -from typing import Iterator -from annotated_types import GroupedMetadata, Ge - -@dataclass -class Field(GroupedMetadata): - ge: int | None = None - description: str | None = None - - def __iter__(self) -> Iterator[object]: - # Iterating over a GroupedMetadata object should yield annotated-types - # constraint metadata objects which describe it as fully as possible, - # and may include other unknown objects too. - if self.ge is not None: - yield Ge(self.ge) - if self.description is not None: - yield Description(self.description) -``` - -Libraries consuming annotated-types constraints should check for `GroupedMetadata` and unpack it by iterating over the object and treating the results as if they had been "unpacked" in the `Annotated` type. The same logic should be applied to the [PEP 646 `Unpack` type](https://peps.python.org/pep-0646/), so that `Annotated[T, Field(...)]`, `Annotated[T, Unpack[Field(...)]]` and `Annotated[T, *Field(...)]` are all treated consistently. - -Libraries consuming annotated-types should also ignore any metadata they do not recongize that came from unpacking a `GroupedMetadata`, just like they ignore unrecognized metadata in `Annotated` itself. - -Our own `annotated_types.Interval` class is a `GroupedMetadata` which unpacks itself into `Gt`, `Lt`, etc., so this is not an abstract concern. Similarly, `annotated_types.Len` is a `GroupedMetadata` which unpacks itself into `MinLen` (optionally) and `MaxLen`. - -### Consuming metadata - -We intend to not be prescriptive as to _how_ the metadata and constraints are used, but as an example of how one might parse constraints from types annotations see our [implementation in `test_main.py`](https://github.com/annotated-types/annotated-types/blob/f59cf6d1b5255a0fe359b93896759a180bec30ae/tests/test_main.py#L94-L103). - -It is up to the implementer to determine how this metadata is used. -You could use the metadata for runtime type checking, for generating schemas or to generate example data, amongst other use cases. - -## Design & History - -This package was designed at the PyCon 2022 sprints by the maintainers of Pydantic -and Hypothesis, with the goal of making it as easy as possible for end-users to -provide more informative annotations for use by runtime libraries. - -It is deliberately minimal, and following PEP-593 allows considerable downstream -discretion in what (if anything!) they choose to support. Nonetheless, we expect -that staying simple and covering _only_ the most common use-cases will give users -and maintainers the best experience we can. If you'd like more constraints for your -types - follow our lead, by defining them and documenting them downstream! diff --git a/.venv/lib/python3.12/site-packages/annotated_types-0.7.0.dist-info/RECORD b/.venv/lib/python3.12/site-packages/annotated_types-0.7.0.dist-info/RECORD deleted file mode 100644 index a66e278..0000000 --- a/.venv/lib/python3.12/site-packages/annotated_types-0.7.0.dist-info/RECORD +++ /dev/null @@ -1,10 +0,0 @@ -annotated_types-0.7.0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4 -annotated_types-0.7.0.dist-info/METADATA,sha256=7ltqxksJJ0wCYFGBNIQCWTlWQGeAH0hRFdnK3CB895E,15046 -annotated_types-0.7.0.dist-info/RECORD,, -annotated_types-0.7.0.dist-info/WHEEL,sha256=zEMcRr9Kr03x1ozGwg5v9NQBKn3kndp6LSoSlVg-jhU,87 -annotated_types-0.7.0.dist-info/licenses/LICENSE,sha256=_hBJiEsaDZNCkB6I4H8ykl0ksxIdmXK2poBfuYJLCV0,1083 -annotated_types/__init__.py,sha256=RynLsRKUEGI0KimXydlD1fZEfEzWwDo0Uon3zOKhG1Q,13819 -annotated_types/__pycache__/__init__.cpython-312.pyc,, -annotated_types/__pycache__/test_cases.cpython-312.pyc,, -annotated_types/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0 -annotated_types/test_cases.py,sha256=zHFX6EpcMbGJ8FzBYDbO56bPwx_DYIVSKbZM-4B3_lg,6421 diff --git a/.venv/lib/python3.12/site-packages/annotated_types-0.7.0.dist-info/WHEEL b/.venv/lib/python3.12/site-packages/annotated_types-0.7.0.dist-info/WHEEL deleted file mode 100644 index 516596c..0000000 --- a/.venv/lib/python3.12/site-packages/annotated_types-0.7.0.dist-info/WHEEL +++ /dev/null @@ -1,4 +0,0 @@ -Wheel-Version: 1.0 -Generator: hatchling 1.24.2 -Root-Is-Purelib: true -Tag: py3-none-any diff --git a/.venv/lib/python3.12/site-packages/annotated_types-0.7.0.dist-info/licenses/LICENSE b/.venv/lib/python3.12/site-packages/annotated_types-0.7.0.dist-info/licenses/LICENSE deleted file mode 100644 index d99323a..0000000 --- a/.venv/lib/python3.12/site-packages/annotated_types-0.7.0.dist-info/licenses/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2022 the contributors - -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. diff --git a/.venv/lib/python3.12/site-packages/annotated_types/__init__.py b/.venv/lib/python3.12/site-packages/annotated_types/__init__.py deleted file mode 100644 index 74e0dee..0000000 --- a/.venv/lib/python3.12/site-packages/annotated_types/__init__.py +++ /dev/null @@ -1,432 +0,0 @@ -import math -import sys -import types -from dataclasses import dataclass -from datetime import tzinfo -from typing import TYPE_CHECKING, Any, Callable, Iterator, Optional, SupportsFloat, SupportsIndex, TypeVar, Union - -if sys.version_info < (3, 8): - from typing_extensions import Protocol, runtime_checkable -else: - from typing import Protocol, runtime_checkable - -if sys.version_info < (3, 9): - from typing_extensions import Annotated, Literal -else: - from typing import Annotated, Literal - -if sys.version_info < (3, 10): - EllipsisType = type(Ellipsis) - KW_ONLY = {} - SLOTS = {} -else: - from types import EllipsisType - - KW_ONLY = {"kw_only": True} - SLOTS = {"slots": True} - - -__all__ = ( - 'BaseMetadata', - 'GroupedMetadata', - 'Gt', - 'Ge', - 'Lt', - 'Le', - 'Interval', - 'MultipleOf', - 'MinLen', - 'MaxLen', - 'Len', - 'Timezone', - 'Predicate', - 'LowerCase', - 'UpperCase', - 'IsDigits', - 'IsFinite', - 'IsNotFinite', - 'IsNan', - 'IsNotNan', - 'IsInfinite', - 'IsNotInfinite', - 'doc', - 'DocInfo', - '__version__', -) - -__version__ = '0.7.0' - - -T = TypeVar('T') - - -# arguments that start with __ are considered -# positional only -# see https://peps.python.org/pep-0484/#positional-only-arguments - - -class SupportsGt(Protocol): - def __gt__(self: T, __other: T) -> bool: - ... - - -class SupportsGe(Protocol): - def __ge__(self: T, __other: T) -> bool: - ... - - -class SupportsLt(Protocol): - def __lt__(self: T, __other: T) -> bool: - ... - - -class SupportsLe(Protocol): - def __le__(self: T, __other: T) -> bool: - ... - - -class SupportsMod(Protocol): - def __mod__(self: T, __other: T) -> T: - ... - - -class SupportsDiv(Protocol): - def __div__(self: T, __other: T) -> T: - ... - - -class BaseMetadata: - """Base class for all metadata. - - This exists mainly so that implementers - can do `isinstance(..., BaseMetadata)` while traversing field annotations. - """ - - __slots__ = () - - -@dataclass(frozen=True, **SLOTS) -class Gt(BaseMetadata): - """Gt(gt=x) implies that the value must be greater than x. - - It can be used with any type that supports the ``>`` operator, - including numbers, dates and times, strings, sets, and so on. - """ - - gt: SupportsGt - - -@dataclass(frozen=True, **SLOTS) -class Ge(BaseMetadata): - """Ge(ge=x) implies that the value must be greater than or equal to x. - - It can be used with any type that supports the ``>=`` operator, - including numbers, dates and times, strings, sets, and so on. - """ - - ge: SupportsGe - - -@dataclass(frozen=True, **SLOTS) -class Lt(BaseMetadata): - """Lt(lt=x) implies that the value must be less than x. - - It can be used with any type that supports the ``<`` operator, - including numbers, dates and times, strings, sets, and so on. - """ - - lt: SupportsLt - - -@dataclass(frozen=True, **SLOTS) -class Le(BaseMetadata): - """Le(le=x) implies that the value must be less than or equal to x. - - It can be used with any type that supports the ``<=`` operator, - including numbers, dates and times, strings, sets, and so on. - """ - - le: SupportsLe - - -@runtime_checkable -class GroupedMetadata(Protocol): - """A grouping of multiple objects, like typing.Unpack. - - `GroupedMetadata` on its own is not metadata and has no meaning. - All of the constraints and metadata should be fully expressable - in terms of the `BaseMetadata`'s returned by `GroupedMetadata.__iter__()`. - - Concrete implementations should override `GroupedMetadata.__iter__()` - to add their own metadata. - For example: - - >>> @dataclass - >>> class Field(GroupedMetadata): - >>> gt: float | None = None - >>> description: str | None = None - ... - >>> def __iter__(self) -> Iterable[object]: - >>> if self.gt is not None: - >>> yield Gt(self.gt) - >>> if self.description is not None: - >>> yield Description(self.gt) - - Also see the implementation of `Interval` below for an example. - - Parsers should recognize this and unpack it so that it can be used - both with and without unpacking: - - - `Annotated[int, Field(...)]` (parser must unpack Field) - - `Annotated[int, *Field(...)]` (PEP-646) - """ # noqa: trailing-whitespace - - @property - def __is_annotated_types_grouped_metadata__(self) -> Literal[True]: - return True - - def __iter__(self) -> Iterator[object]: - ... - - if not TYPE_CHECKING: - __slots__ = () # allow subclasses to use slots - - def __init_subclass__(cls, *args: Any, **kwargs: Any) -> None: - # Basic ABC like functionality without the complexity of an ABC - super().__init_subclass__(*args, **kwargs) - if cls.__iter__ is GroupedMetadata.__iter__: - raise TypeError("Can't subclass GroupedMetadata without implementing __iter__") - - def __iter__(self) -> Iterator[object]: # noqa: F811 - raise NotImplementedError # more helpful than "None has no attribute..." type errors - - -@dataclass(frozen=True, **KW_ONLY, **SLOTS) -class Interval(GroupedMetadata): - """Interval can express inclusive or exclusive bounds with a single object. - - It accepts keyword arguments ``gt``, ``ge``, ``lt``, and/or ``le``, which - are interpreted the same way as the single-bound constraints. - """ - - gt: Union[SupportsGt, None] = None - ge: Union[SupportsGe, None] = None - lt: Union[SupportsLt, None] = None - le: Union[SupportsLe, None] = None - - def __iter__(self) -> Iterator[BaseMetadata]: - """Unpack an Interval into zero or more single-bounds.""" - if self.gt is not None: - yield Gt(self.gt) - if self.ge is not None: - yield Ge(self.ge) - if self.lt is not None: - yield Lt(self.lt) - if self.le is not None: - yield Le(self.le) - - -@dataclass(frozen=True, **SLOTS) -class MultipleOf(BaseMetadata): - """MultipleOf(multiple_of=x) might be interpreted in two ways: - - 1. Python semantics, implying ``value % multiple_of == 0``, or - 2. JSONschema semantics, where ``int(value / multiple_of) == value / multiple_of`` - - We encourage users to be aware of these two common interpretations, - and libraries to carefully document which they implement. - """ - - multiple_of: Union[SupportsDiv, SupportsMod] - - -@dataclass(frozen=True, **SLOTS) -class MinLen(BaseMetadata): - """ - MinLen() implies minimum inclusive length, - e.g. ``len(value) >= min_length``. - """ - - min_length: Annotated[int, Ge(0)] - - -@dataclass(frozen=True, **SLOTS) -class MaxLen(BaseMetadata): - """ - MaxLen() implies maximum inclusive length, - e.g. ``len(value) <= max_length``. - """ - - max_length: Annotated[int, Ge(0)] - - -@dataclass(frozen=True, **SLOTS) -class Len(GroupedMetadata): - """ - Len() implies that ``min_length <= len(value) <= max_length``. - - Upper bound may be omitted or ``None`` to indicate no upper length bound. - """ - - min_length: Annotated[int, Ge(0)] = 0 - max_length: Optional[Annotated[int, Ge(0)]] = None - - def __iter__(self) -> Iterator[BaseMetadata]: - """Unpack a Len into zone or more single-bounds.""" - if self.min_length > 0: - yield MinLen(self.min_length) - if self.max_length is not None: - yield MaxLen(self.max_length) - - -@dataclass(frozen=True, **SLOTS) -class Timezone(BaseMetadata): - """Timezone(tz=...) requires a datetime to be aware (or ``tz=None``, naive). - - ``Annotated[datetime, Timezone(None)]`` must be a naive datetime. - ``Timezone[...]`` (the ellipsis literal) expresses that the datetime must be - tz-aware but any timezone is allowed. - - You may also pass a specific timezone string or tzinfo object such as - ``Timezone(timezone.utc)`` or ``Timezone("Africa/Abidjan")`` to express that - you only allow a specific timezone, though we note that this is often - a symptom of poor design. - """ - - tz: Union[str, tzinfo, EllipsisType, None] - - -@dataclass(frozen=True, **SLOTS) -class Unit(BaseMetadata): - """Indicates that the value is a physical quantity with the specified unit. - - It is intended for usage with numeric types, where the value represents the - magnitude of the quantity. For example, ``distance: Annotated[float, Unit('m')]`` - or ``speed: Annotated[float, Unit('m/s')]``. - - Interpretation of the unit string is left to the discretion of the consumer. - It is suggested to follow conventions established by python libraries that work - with physical quantities, such as - - - ``pint`` : - - ``astropy.units``: - - For indicating a quantity with a certain dimensionality but without a specific unit - it is recommended to use square brackets, e.g. `Annotated[float, Unit('[time]')]`. - Note, however, ``annotated_types`` itself makes no use of the unit string. - """ - - unit: str - - -@dataclass(frozen=True, **SLOTS) -class Predicate(BaseMetadata): - """``Predicate(func: Callable)`` implies `func(value)` is truthy for valid values. - - Users should prefer statically inspectable metadata, but if you need the full - power and flexibility of arbitrary runtime predicates... here it is. - - We provide a few predefined predicates for common string constraints: - ``IsLower = Predicate(str.islower)``, ``IsUpper = Predicate(str.isupper)``, and - ``IsDigits = Predicate(str.isdigit)``. Users are encouraged to use methods which - can be given special handling, and avoid indirection like ``lambda s: s.lower()``. - - Some libraries might have special logic to handle certain predicates, e.g. by - checking for `str.isdigit` and using its presence to both call custom logic to - enforce digit-only strings, and customise some generated external schema. - - We do not specify what behaviour should be expected for predicates that raise - an exception. For example `Annotated[int, Predicate(str.isdigit)]` might silently - skip invalid constraints, or statically raise an error; or it might try calling it - and then propagate or discard the resulting exception. - """ - - func: Callable[[Any], bool] - - def __repr__(self) -> str: - if getattr(self.func, "__name__", "") == "": - return f"{self.__class__.__name__}({self.func!r})" - if isinstance(self.func, (types.MethodType, types.BuiltinMethodType)) and ( - namespace := getattr(self.func.__self__, "__name__", None) - ): - return f"{self.__class__.__name__}({namespace}.{self.func.__name__})" - if isinstance(self.func, type(str.isascii)): # method descriptor - return f"{self.__class__.__name__}({self.func.__qualname__})" - return f"{self.__class__.__name__}({self.func.__name__})" - - -@dataclass -class Not: - func: Callable[[Any], bool] - - def __call__(self, __v: Any) -> bool: - return not self.func(__v) - - -_StrType = TypeVar("_StrType", bound=str) - -LowerCase = Annotated[_StrType, Predicate(str.islower)] -""" -Return True if the string is a lowercase string, False otherwise. - -A string is lowercase if all cased characters in the string are lowercase and there is at least one cased character in the string. -""" # noqa: E501 -UpperCase = Annotated[_StrType, Predicate(str.isupper)] -""" -Return True if the string is an uppercase string, False otherwise. - -A string is uppercase if all cased characters in the string are uppercase and there is at least one cased character in the string. -""" # noqa: E501 -IsDigit = Annotated[_StrType, Predicate(str.isdigit)] -IsDigits = IsDigit # type: ignore # plural for backwards compatibility, see #63 -""" -Return True if the string is a digit string, False otherwise. - -A string is a digit string if all characters in the string are digits and there is at least one character in the string. -""" # noqa: E501 -IsAscii = Annotated[_StrType, Predicate(str.isascii)] -""" -Return True if all characters in the string are ASCII, False otherwise. - -ASCII characters have code points in the range U+0000-U+007F. Empty string is ASCII too. -""" - -_NumericType = TypeVar('_NumericType', bound=Union[SupportsFloat, SupportsIndex]) -IsFinite = Annotated[_NumericType, Predicate(math.isfinite)] -"""Return True if x is neither an infinity nor a NaN, and False otherwise.""" -IsNotFinite = Annotated[_NumericType, Predicate(Not(math.isfinite))] -"""Return True if x is one of infinity or NaN, and False otherwise""" -IsNan = Annotated[_NumericType, Predicate(math.isnan)] -"""Return True if x is a NaN (not a number), and False otherwise.""" -IsNotNan = Annotated[_NumericType, Predicate(Not(math.isnan))] -"""Return True if x is anything but NaN (not a number), and False otherwise.""" -IsInfinite = Annotated[_NumericType, Predicate(math.isinf)] -"""Return True if x is a positive or negative infinity, and False otherwise.""" -IsNotInfinite = Annotated[_NumericType, Predicate(Not(math.isinf))] -"""Return True if x is neither a positive or negative infinity, and False otherwise.""" - -try: - from typing_extensions import DocInfo, doc # type: ignore [attr-defined] -except ImportError: - - @dataclass(frozen=True, **SLOTS) - class DocInfo: # type: ignore [no-redef] - """ " - The return value of doc(), mainly to be used by tools that want to extract the - Annotated documentation at runtime. - """ - - documentation: str - """The documentation string passed to doc().""" - - def doc( - documentation: str, - ) -> DocInfo: - """ - Add documentation to a type annotation inside of Annotated. - - For example: - - >>> def hi(name: Annotated[int, doc("The name of the user")]) -> None: ... - """ - return DocInfo(documentation) diff --git a/.venv/lib/python3.12/site-packages/annotated_types/py.typed b/.venv/lib/python3.12/site-packages/annotated_types/py.typed deleted file mode 100644 index e69de29..0000000 diff --git a/.venv/lib/python3.12/site-packages/annotated_types/test_cases.py b/.venv/lib/python3.12/site-packages/annotated_types/test_cases.py deleted file mode 100644 index d9164d6..0000000 --- a/.venv/lib/python3.12/site-packages/annotated_types/test_cases.py +++ /dev/null @@ -1,151 +0,0 @@ -import math -import sys -from datetime import date, datetime, timedelta, timezone -from decimal import Decimal -from typing import Any, Dict, Iterable, Iterator, List, NamedTuple, Set, Tuple - -if sys.version_info < (3, 9): - from typing_extensions import Annotated -else: - from typing import Annotated - -import annotated_types as at - - -class Case(NamedTuple): - """ - A test case for `annotated_types`. - """ - - annotation: Any - valid_cases: Iterable[Any] - invalid_cases: Iterable[Any] - - -def cases() -> Iterable[Case]: - # Gt, Ge, Lt, Le - yield Case(Annotated[int, at.Gt(4)], (5, 6, 1000), (4, 0, -1)) - yield Case(Annotated[float, at.Gt(0.5)], (0.6, 0.7, 0.8, 0.9), (0.5, 0.0, -0.1)) - yield Case( - Annotated[datetime, at.Gt(datetime(2000, 1, 1))], - [datetime(2000, 1, 2), datetime(2000, 1, 3)], - [datetime(2000, 1, 1), datetime(1999, 12, 31)], - ) - yield Case( - Annotated[datetime, at.Gt(date(2000, 1, 1))], - [date(2000, 1, 2), date(2000, 1, 3)], - [date(2000, 1, 1), date(1999, 12, 31)], - ) - yield Case( - Annotated[datetime, at.Gt(Decimal('1.123'))], - [Decimal('1.1231'), Decimal('123')], - [Decimal('1.123'), Decimal('0')], - ) - - yield Case(Annotated[int, at.Ge(4)], (4, 5, 6, 1000, 4), (0, -1)) - yield Case(Annotated[float, at.Ge(0.5)], (0.5, 0.6, 0.7, 0.8, 0.9), (0.4, 0.0, -0.1)) - yield Case( - Annotated[datetime, at.Ge(datetime(2000, 1, 1))], - [datetime(2000, 1, 2), datetime(2000, 1, 3)], - [datetime(1998, 1, 1), datetime(1999, 12, 31)], - ) - - yield Case(Annotated[int, at.Lt(4)], (0, -1), (4, 5, 6, 1000, 4)) - yield Case(Annotated[float, at.Lt(0.5)], (0.4, 0.0, -0.1), (0.5, 0.6, 0.7, 0.8, 0.9)) - yield Case( - Annotated[datetime, at.Lt(datetime(2000, 1, 1))], - [datetime(1999, 12, 31), datetime(1999, 12, 31)], - [datetime(2000, 1, 2), datetime(2000, 1, 3)], - ) - - yield Case(Annotated[int, at.Le(4)], (4, 0, -1), (5, 6, 1000)) - yield Case(Annotated[float, at.Le(0.5)], (0.5, 0.0, -0.1), (0.6, 0.7, 0.8, 0.9)) - yield Case( - Annotated[datetime, at.Le(datetime(2000, 1, 1))], - [datetime(2000, 1, 1), datetime(1999, 12, 31)], - [datetime(2000, 1, 2), datetime(2000, 1, 3)], - ) - - # Interval - yield Case(Annotated[int, at.Interval(gt=4)], (5, 6, 1000), (4, 0, -1)) - yield Case(Annotated[int, at.Interval(gt=4, lt=10)], (5, 6), (4, 10, 1000, 0, -1)) - yield Case(Annotated[float, at.Interval(ge=0.5, le=1)], (0.5, 0.9, 1), (0.49, 1.1)) - yield Case( - Annotated[datetime, at.Interval(gt=datetime(2000, 1, 1), le=datetime(2000, 1, 3))], - [datetime(2000, 1, 2), datetime(2000, 1, 3)], - [datetime(2000, 1, 1), datetime(2000, 1, 4)], - ) - - yield Case(Annotated[int, at.MultipleOf(multiple_of=3)], (0, 3, 9), (1, 2, 4)) - yield Case(Annotated[float, at.MultipleOf(multiple_of=0.5)], (0, 0.5, 1, 1.5), (0.4, 1.1)) - - # lengths - - yield Case(Annotated[str, at.MinLen(3)], ('123', '1234', 'x' * 10), ('', '1', '12')) - yield Case(Annotated[str, at.Len(3)], ('123', '1234', 'x' * 10), ('', '1', '12')) - yield Case(Annotated[List[int], at.MinLen(3)], ([1, 2, 3], [1, 2, 3, 4], [1] * 10), ([], [1], [1, 2])) - yield Case(Annotated[List[int], at.Len(3)], ([1, 2, 3], [1, 2, 3, 4], [1] * 10), ([], [1], [1, 2])) - - yield Case(Annotated[str, at.MaxLen(4)], ('', '1234'), ('12345', 'x' * 10)) - yield Case(Annotated[str, at.Len(0, 4)], ('', '1234'), ('12345', 'x' * 10)) - yield Case(Annotated[List[str], at.MaxLen(4)], ([], ['a', 'bcdef'], ['a', 'b', 'c']), (['a'] * 5, ['b'] * 10)) - yield Case(Annotated[List[str], at.Len(0, 4)], ([], ['a', 'bcdef'], ['a', 'b', 'c']), (['a'] * 5, ['b'] * 10)) - - yield Case(Annotated[str, at.Len(3, 5)], ('123', '12345'), ('', '1', '12', '123456', 'x' * 10)) - yield Case(Annotated[str, at.Len(3, 3)], ('123',), ('12', '1234')) - - yield Case(Annotated[Dict[int, int], at.Len(2, 3)], [{1: 1, 2: 2}], [{}, {1: 1}, {1: 1, 2: 2, 3: 3, 4: 4}]) - yield Case(Annotated[Set[int], at.Len(2, 3)], ({1, 2}, {1, 2, 3}), (set(), {1}, {1, 2, 3, 4})) - yield Case(Annotated[Tuple[int, ...], at.Len(2, 3)], ((1, 2), (1, 2, 3)), ((), (1,), (1, 2, 3, 4))) - - # Timezone - - yield Case( - Annotated[datetime, at.Timezone(None)], [datetime(2000, 1, 1)], [datetime(2000, 1, 1, tzinfo=timezone.utc)] - ) - yield Case( - Annotated[datetime, at.Timezone(...)], [datetime(2000, 1, 1, tzinfo=timezone.utc)], [datetime(2000, 1, 1)] - ) - yield Case( - Annotated[datetime, at.Timezone(timezone.utc)], - [datetime(2000, 1, 1, tzinfo=timezone.utc)], - [datetime(2000, 1, 1), datetime(2000, 1, 1, tzinfo=timezone(timedelta(hours=6)))], - ) - yield Case( - Annotated[datetime, at.Timezone('Europe/London')], - [datetime(2000, 1, 1, tzinfo=timezone(timedelta(0), name='Europe/London'))], - [datetime(2000, 1, 1), datetime(2000, 1, 1, tzinfo=timezone(timedelta(hours=6)))], - ) - - # Quantity - - yield Case(Annotated[float, at.Unit(unit='m')], (5, 4.2), ('5m', '4.2m')) - - # predicate types - - yield Case(at.LowerCase[str], ['abc', 'foobar'], ['', 'A', 'Boom']) - yield Case(at.UpperCase[str], ['ABC', 'DEFO'], ['', 'a', 'abc', 'AbC']) - yield Case(at.IsDigit[str], ['123'], ['', 'ab', 'a1b2']) - yield Case(at.IsAscii[str], ['123', 'foo bar'], ['£100', '😊', 'whatever 👀']) - - yield Case(Annotated[int, at.Predicate(lambda x: x % 2 == 0)], [0, 2, 4], [1, 3, 5]) - - yield Case(at.IsFinite[float], [1.23], [math.nan, math.inf, -math.inf]) - yield Case(at.IsNotFinite[float], [math.nan, math.inf], [1.23]) - yield Case(at.IsNan[float], [math.nan], [1.23, math.inf]) - yield Case(at.IsNotNan[float], [1.23, math.inf], [math.nan]) - yield Case(at.IsInfinite[float], [math.inf], [math.nan, 1.23]) - yield Case(at.IsNotInfinite[float], [math.nan, 1.23], [math.inf]) - - # check stacked predicates - yield Case(at.IsInfinite[Annotated[float, at.Predicate(lambda x: x > 0)]], [math.inf], [-math.inf, 1.23, math.nan]) - - # doc - yield Case(Annotated[int, at.doc("A number")], [1, 2], []) - - # custom GroupedMetadata - class MyCustomGroupedMetadata(at.GroupedMetadata): - def __iter__(self) -> Iterator[at.Predicate]: - yield at.Predicate(lambda x: float(x).is_integer()) - - yield Case(Annotated[float, MyCustomGroupedMetadata()], [0, 2.0], [0.01, 1.5]) diff --git a/.venv/lib/python3.12/site-packages/anyio-4.13.0.dist-info/INSTALLER b/.venv/lib/python3.12/site-packages/anyio-4.13.0.dist-info/INSTALLER deleted file mode 100644 index a1b589e..0000000 --- a/.venv/lib/python3.12/site-packages/anyio-4.13.0.dist-info/INSTALLER +++ /dev/null @@ -1 +0,0 @@ -pip diff --git a/.venv/lib/python3.12/site-packages/anyio-4.13.0.dist-info/METADATA b/.venv/lib/python3.12/site-packages/anyio-4.13.0.dist-info/METADATA deleted file mode 100644 index 2de1cd5..0000000 --- a/.venv/lib/python3.12/site-packages/anyio-4.13.0.dist-info/METADATA +++ /dev/null @@ -1,105 +0,0 @@ -Metadata-Version: 2.4 -Name: anyio -Version: 4.13.0 -Summary: High-level concurrency and networking framework on top of asyncio or Trio -Author-email: Alex Grönholm -License-Expression: MIT -Project-URL: Documentation, https://anyio.readthedocs.io/en/latest/ -Project-URL: Changelog, https://anyio.readthedocs.io/en/stable/versionhistory.html -Project-URL: Source code, https://github.com/agronholm/anyio -Project-URL: Issue tracker, https://github.com/agronholm/anyio/issues -Classifier: Development Status :: 5 - Production/Stable -Classifier: Intended Audience :: Developers -Classifier: Framework :: AnyIO -Classifier: Typing :: Typed -Classifier: Programming Language :: Python -Classifier: Programming Language :: Python :: 3 -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 -Requires-Python: >=3.10 -Description-Content-Type: text/x-rst -License-File: LICENSE -Requires-Dist: exceptiongroup>=1.0.2; python_version < "3.11" -Requires-Dist: idna>=2.8 -Requires-Dist: typing_extensions>=4.5; python_version < "3.13" -Provides-Extra: trio -Requires-Dist: trio>=0.32.0; extra == "trio" -Dynamic: license-file - -.. image:: https://github.com/agronholm/anyio/actions/workflows/test.yml/badge.svg - :target: https://github.com/agronholm/anyio/actions/workflows/test.yml - :alt: Build Status -.. image:: https://coveralls.io/repos/github/agronholm/anyio/badge.svg?branch=master - :target: https://coveralls.io/github/agronholm/anyio?branch=master - :alt: Code Coverage -.. image:: https://readthedocs.org/projects/anyio/badge/?version=latest - :target: https://anyio.readthedocs.io/en/latest/?badge=latest - :alt: Documentation -.. image:: https://badges.gitter.im/gitterHQ/gitter.svg - :target: https://gitter.im/python-trio/AnyIO - :alt: Gitter chat -.. image:: https://tidelift.com/badges/package/pypi/anyio - :target: https://tidelift.com/subscription/pkg/pypi-anyio - :alt: Tidelift - -AnyIO is an asynchronous networking and concurrency library that works on top of either asyncio_ or -Trio_. It implements Trio-like `structured concurrency`_ (SC) on top of asyncio and works in harmony -with the native SC of Trio itself. - -Applications and libraries written against AnyIO's API will run unmodified on either asyncio_ or -Trio_. AnyIO can also be adopted into a library or application incrementally – bit by bit, no full -refactoring necessary. It will blend in with the native libraries of your chosen backend. - -To find out why you might want to use AnyIO's APIs instead of asyncio's, you can read about it -`here `_. - -Documentation -------------- - -View full documentation at: https://anyio.readthedocs.io/ - -Features --------- - -AnyIO offers the following functionality: - -* Task groups (nurseries_ in trio terminology) -* High-level networking (TCP, UDP and UNIX sockets) - - * `Happy eyeballs`_ algorithm for TCP connections (more robust than that of asyncio on Python - 3.8) - * async/await style UDP sockets (unlike asyncio where you still have to use Transports and - Protocols) - -* A versatile API for byte streams and object streams -* Inter-task synchronization and communication (locks, conditions, events, semaphores, object - streams) -* Worker threads -* Subprocesses -* Subinterpreter support for code parallelization (on Python 3.13 and later) -* Asynchronous file I/O (using worker threads) -* Signal handling -* Asynchronous version of the functools_ module - -AnyIO also comes with its own pytest_ plugin which also supports asynchronous fixtures. -It even works with the popular Hypothesis_ library. - -.. _asyncio: https://docs.python.org/3/library/asyncio.html -.. _Trio: https://github.com/python-trio/trio -.. _structured concurrency: https://en.wikipedia.org/wiki/Structured_concurrency -.. _nurseries: https://trio.readthedocs.io/en/stable/reference-core.html#nurseries-and-spawning -.. _Happy eyeballs: https://en.wikipedia.org/wiki/Happy_Eyeballs -.. _pytest: https://docs.pytest.org/en/latest/ -.. _functools: https://docs.python.org/3/library/functools.html -.. _Hypothesis: https://hypothesis.works/ - -Security contact information ----------------------------- - -To report a security vulnerability, please use the `Tidelift security contact`_. -Tidelift will coordinate the fix and disclosure. - -.. _Tidelift security contact: https://tidelift.com/security diff --git a/.venv/lib/python3.12/site-packages/anyio-4.13.0.dist-info/RECORD b/.venv/lib/python3.12/site-packages/anyio-4.13.0.dist-info/RECORD deleted file mode 100644 index e5f678c..0000000 --- a/.venv/lib/python3.12/site-packages/anyio-4.13.0.dist-info/RECORD +++ /dev/null @@ -1,92 +0,0 @@ -anyio-4.13.0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4 -anyio-4.13.0.dist-info/METADATA,sha256=F0EYfiPlmTRwmJN2JktNxJg1GNnl0wHhzOWmz7pFvjM,4513 -anyio-4.13.0.dist-info/RECORD,, -anyio-4.13.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91 -anyio-4.13.0.dist-info/entry_points.txt,sha256=_d6Yu6uiaZmNe0CydowirE9Cmg7zUL2g08tQpoS3Qvc,39 -anyio-4.13.0.dist-info/licenses/LICENSE,sha256=U2GsncWPLvX9LpsJxoKXwX8ElQkJu8gCO9uC6s8iwrA,1081 -anyio-4.13.0.dist-info/top_level.txt,sha256=QglSMiWX8_5dpoVAEIHdEYzvqFMdSYWmCj6tYw2ITkQ,6 -anyio/__init__.py,sha256=7iDVqMUprUuKNY91FuoKqayAhR-OY136YDPI6P78HHk,6170 -anyio/__pycache__/__init__.cpython-312.pyc,, -anyio/__pycache__/from_thread.cpython-312.pyc,, -anyio/__pycache__/functools.cpython-312.pyc,, -anyio/__pycache__/lowlevel.cpython-312.pyc,, -anyio/__pycache__/pytest_plugin.cpython-312.pyc,, -anyio/__pycache__/to_interpreter.cpython-312.pyc,, -anyio/__pycache__/to_process.cpython-312.pyc,, -anyio/__pycache__/to_thread.cpython-312.pyc,, -anyio/_backends/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0 -anyio/_backends/__pycache__/__init__.cpython-312.pyc,, -anyio/_backends/__pycache__/_asyncio.cpython-312.pyc,, -anyio/_backends/__pycache__/_trio.cpython-312.pyc,, -anyio/_backends/_asyncio.py,sha256=kuqlg2sBUsFdgY80xSDAw60Gx_4WNCl9iSL5XlY6lCU,99476 -anyio/_backends/_trio.py,sha256=l9U-TsKRxzmTQxSMvOhn0bNeFn_iRx3Ho30jvR5Bdu0,41366 -anyio/_core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0 -anyio/_core/__pycache__/__init__.cpython-312.pyc,, -anyio/_core/__pycache__/_asyncio_selector_thread.cpython-312.pyc,, -anyio/_core/__pycache__/_contextmanagers.cpython-312.pyc,, -anyio/_core/__pycache__/_eventloop.cpython-312.pyc,, -anyio/_core/__pycache__/_exceptions.cpython-312.pyc,, -anyio/_core/__pycache__/_fileio.cpython-312.pyc,, -anyio/_core/__pycache__/_resources.cpython-312.pyc,, -anyio/_core/__pycache__/_signals.cpython-312.pyc,, -anyio/_core/__pycache__/_sockets.cpython-312.pyc,, -anyio/_core/__pycache__/_streams.cpython-312.pyc,, -anyio/_core/__pycache__/_subprocesses.cpython-312.pyc,, -anyio/_core/__pycache__/_synchronization.cpython-312.pyc,, -anyio/_core/__pycache__/_tasks.cpython-312.pyc,, -anyio/_core/__pycache__/_tempfile.cpython-312.pyc,, -anyio/_core/__pycache__/_testing.cpython-312.pyc,, -anyio/_core/__pycache__/_typedattr.cpython-312.pyc,, -anyio/_core/_asyncio_selector_thread.py,sha256=2PdxFM3cs02Kp6BSppbvmRT7q7asreTW5FgBxEsflBo,5626 -anyio/_core/_contextmanagers.py,sha256=YInBCabiEeS-UaP_Jdxa1CaFC71ETPW8HZTHIM8Rsc8,7215 -anyio/_core/_eventloop.py,sha256=c2EdcBX-xnKwxPcC4Pjn3_qG9I-x4IWFO2R9RqCGjM4,6448 -anyio/_core/_exceptions.py,sha256=Y3aq-Wxd7Q2HqwSg7nZPvRsHEuGazv_qeet6gqEBdPk,4407 -anyio/_core/_fileio.py,sha256=CKi1gFNiW2G4knWeBE7He7-rptQwgYjDUWfG8DSlvLs,25665 -anyio/_core/_resources.py,sha256=NbmU5O5UX3xEyACnkmYX28Fmwdl-f-ny0tHym26e0w0,435 -anyio/_core/_signals.py,sha256=mjTBB2hTKNPRlU0IhnijeQedpWOGERDiMjSlJQsFrug,1016 -anyio/_core/_sockets.py,sha256=RBXHcUqZt5gg_-OOfgHVv8uq2FSKk1uVUzTdpjBoI1o,34977 -anyio/_core/_streams.py,sha256=FczFwIgDpnkK0bODWJXMpsUJYdvAD04kaUaGzJU8DK0,1806 -anyio/_core/_subprocesses.py,sha256=tkmkPKEkEaiMD8C9WRZBlmgjOYRDRbZdte6e-unay2E,7916 -anyio/_core/_synchronization.py,sha256=9G3fvRsPNrrWJ_Z6gD_80wXq8I8qgAyhwM8PvHQnT2c,21061 -anyio/_core/_tasks.py,sha256=pVB7K6AAulzUM8YgXAeqNZG44nSyZ1bYJjH8GznC00I,5435 -anyio/_core/_tempfile.py,sha256=jE2w59FRF3yRo4vjkjfZF2YcqsBZvc66VWRwrJGDYGk,19624 -anyio/_core/_testing.py,sha256=u7MPqGXwpTxqI7hclSdNA30z2GH1Nw258uwKvy_RfBg,2340 -anyio/_core/_typedattr.py,sha256=P4ozZikn3-DbpoYcvyghS_FOYAgbmUxeoU8-L_07pZM,2508 -anyio/abc/__init__.py,sha256=6mWhcl_pGXhrgZVHP_TCfMvIXIOp9mroEFM90fYCU_U,2869 -anyio/abc/__pycache__/__init__.cpython-312.pyc,, -anyio/abc/__pycache__/_eventloop.cpython-312.pyc,, -anyio/abc/__pycache__/_resources.cpython-312.pyc,, -anyio/abc/__pycache__/_sockets.cpython-312.pyc,, -anyio/abc/__pycache__/_streams.cpython-312.pyc,, -anyio/abc/__pycache__/_subprocesses.cpython-312.pyc,, -anyio/abc/__pycache__/_tasks.cpython-312.pyc,, -anyio/abc/__pycache__/_testing.cpython-312.pyc,, -anyio/abc/_eventloop.py,sha256=39lYnmtvoHaZw22sWBKOTA_zv7bamOnr8O49PqgDXdw,10629 -anyio/abc/_resources.py,sha256=DrYvkNN1hH6Uvv5_5uKySvDsnknGVDe8FCKfko0VtN8,783 -anyio/abc/_sockets.py,sha256=OmVDrfemVvF9c5K1tpBgQyV6fn5v0XyCExLAqBOGz9o,13124 -anyio/abc/_streams.py,sha256=HYvna1iZbWcwLROTO6IhLX79RTRLPShZMWe0sG1q54I,7481 -anyio/abc/_subprocesses.py,sha256=cumAPJTktOQtw63IqG0lDpyZqu_l1EElvQHMiwJgL08,2067 -anyio/abc/_tasks.py,sha256=KC7wrciE48AINOI-AhPutnFhe1ewfP7QnamFlDzqesQ,3721 -anyio/abc/_testing.py,sha256=tBJUzkSfOXJw23fe8qSJ03kJlShOYjjaEyFB6k6MYT8,1821 -anyio/from_thread.py,sha256=L-0w1HxJ6BSb-KuVi57k5Tkc3yzQrx3QK5tAxMPcY-0,19141 -anyio/functools.py,sha256=5AWM1iYTKkTzptvUhQDdLSh5GvbBW-vcs-SAUfIfA9A,12076 -anyio/lowlevel.py,sha256=AyKLVK3LaWSoK39LkCKxE4_GDMLKZBNqTrLUgk63y80,5158 -anyio/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0 -anyio/pytest_plugin.py,sha256=t6h4KJstqIxfxwTZ1YO8vpUVuB99nfCLltn0NHfatHo,12775 -anyio/streams/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0 -anyio/streams/__pycache__/__init__.cpython-312.pyc,, -anyio/streams/__pycache__/buffered.cpython-312.pyc,, -anyio/streams/__pycache__/file.cpython-312.pyc,, -anyio/streams/__pycache__/memory.cpython-312.pyc,, -anyio/streams/__pycache__/stapled.cpython-312.pyc,, -anyio/streams/__pycache__/text.cpython-312.pyc,, -anyio/streams/__pycache__/tls.cpython-312.pyc,, -anyio/streams/buffered.py,sha256=2R3PeJhe4EXrdYqz44Y6-Eg9R6DrmlsYrP36Ir43-po,6263 -anyio/streams/file.py,sha256=msnrotVKGMQomUu_Rj2qz9MvIdUp6d3JGr7MOEO8kV4,4428 -anyio/streams/memory.py,sha256=F0zwzvFJKAhX_LRZGoKzzqDC2oMM-f-yyTBrEYEGOaU,10740 -anyio/streams/stapled.py,sha256=T8Xqwf8K6EgURPxbt1N4i7A8BAk-gScv-GRhjLXIf_o,4390 -anyio/streams/text.py,sha256=BcVAGJw1VRvtIqnv-o0Rb0pwH7p8vwlvl21xHq522ag,5765 -anyio/streams/tls.py,sha256=DQVkXUvsTEYKkBO8dlVU7j_5H8QOtLy4sGi1Wrjqevo,15303 -anyio/to_interpreter.py,sha256=_mLngrMy97TMR6VbW4Y6YzDUk9ZuPcQMPlkuyRh3C9k,7100 -anyio/to_process.py,sha256=J7gAA_YOuoHqnpDAf5fm1Qu6kOmTzdFbiDNvnV755vk,9798 -anyio/to_thread.py,sha256=f6h_k2d743GBv9FhAnhM_YpTvWgIrzBy9cOE0eJ1UJw,2693 diff --git a/.venv/lib/python3.12/site-packages/anyio-4.13.0.dist-info/WHEEL b/.venv/lib/python3.12/site-packages/anyio-4.13.0.dist-info/WHEEL deleted file mode 100644 index 14a883f..0000000 --- a/.venv/lib/python3.12/site-packages/anyio-4.13.0.dist-info/WHEEL +++ /dev/null @@ -1,5 +0,0 @@ -Wheel-Version: 1.0 -Generator: setuptools (82.0.1) -Root-Is-Purelib: true -Tag: py3-none-any - diff --git a/.venv/lib/python3.12/site-packages/anyio-4.13.0.dist-info/entry_points.txt b/.venv/lib/python3.12/site-packages/anyio-4.13.0.dist-info/entry_points.txt deleted file mode 100644 index 44dd9bd..0000000 --- a/.venv/lib/python3.12/site-packages/anyio-4.13.0.dist-info/entry_points.txt +++ /dev/null @@ -1,2 +0,0 @@ -[pytest11] -anyio = anyio.pytest_plugin diff --git a/.venv/lib/python3.12/site-packages/anyio-4.13.0.dist-info/licenses/LICENSE b/.venv/lib/python3.12/site-packages/anyio-4.13.0.dist-info/licenses/LICENSE deleted file mode 100644 index 104eebf..0000000 --- a/.venv/lib/python3.12/site-packages/anyio-4.13.0.dist-info/licenses/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2018 Alex Grönholm - -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. diff --git a/.venv/lib/python3.12/site-packages/anyio-4.13.0.dist-info/top_level.txt b/.venv/lib/python3.12/site-packages/anyio-4.13.0.dist-info/top_level.txt deleted file mode 100644 index c77c069..0000000 --- a/.venv/lib/python3.12/site-packages/anyio-4.13.0.dist-info/top_level.txt +++ /dev/null @@ -1 +0,0 @@ -anyio diff --git a/.venv/lib/python3.12/site-packages/anyio/__init__.py b/.venv/lib/python3.12/site-packages/anyio/__init__.py deleted file mode 100644 index d23c5a5..0000000 --- a/.venv/lib/python3.12/site-packages/anyio/__init__.py +++ /dev/null @@ -1,111 +0,0 @@ -from __future__ import annotations - -from ._core._contextmanagers import AsyncContextManagerMixin as AsyncContextManagerMixin -from ._core._contextmanagers import ContextManagerMixin as ContextManagerMixin -from ._core._eventloop import current_time as current_time -from ._core._eventloop import get_all_backends as get_all_backends -from ._core._eventloop import get_available_backends as get_available_backends -from ._core._eventloop import get_cancelled_exc_class as get_cancelled_exc_class -from ._core._eventloop import run as run -from ._core._eventloop import sleep as sleep -from ._core._eventloop import sleep_forever as sleep_forever -from ._core._eventloop import sleep_until as sleep_until -from ._core._exceptions import BrokenResourceError as BrokenResourceError -from ._core._exceptions import BrokenWorkerInterpreter as BrokenWorkerInterpreter -from ._core._exceptions import BrokenWorkerProcess as BrokenWorkerProcess -from ._core._exceptions import BusyResourceError as BusyResourceError -from ._core._exceptions import ClosedResourceError as ClosedResourceError -from ._core._exceptions import ConnectionFailed as ConnectionFailed -from ._core._exceptions import DelimiterNotFound as DelimiterNotFound -from ._core._exceptions import EndOfStream as EndOfStream -from ._core._exceptions import IncompleteRead as IncompleteRead -from ._core._exceptions import NoEventLoopError as NoEventLoopError -from ._core._exceptions import RunFinishedError as RunFinishedError -from ._core._exceptions import TypedAttributeLookupError as TypedAttributeLookupError -from ._core._exceptions import WouldBlock as WouldBlock -from ._core._fileio import AsyncFile as AsyncFile -from ._core._fileio import Path as Path -from ._core._fileio import open_file as open_file -from ._core._fileio import wrap_file as wrap_file -from ._core._resources import aclose_forcefully as aclose_forcefully -from ._core._signals import open_signal_receiver as open_signal_receiver -from ._core._sockets import TCPConnectable as TCPConnectable -from ._core._sockets import UNIXConnectable as UNIXConnectable -from ._core._sockets import as_connectable as as_connectable -from ._core._sockets import connect_tcp as connect_tcp -from ._core._sockets import connect_unix as connect_unix -from ._core._sockets import create_connected_udp_socket as create_connected_udp_socket -from ._core._sockets import ( - create_connected_unix_datagram_socket as create_connected_unix_datagram_socket, -) -from ._core._sockets import create_tcp_listener as create_tcp_listener -from ._core._sockets import create_udp_socket as create_udp_socket -from ._core._sockets import create_unix_datagram_socket as create_unix_datagram_socket -from ._core._sockets import create_unix_listener as create_unix_listener -from ._core._sockets import getaddrinfo as getaddrinfo -from ._core._sockets import getnameinfo as getnameinfo -from ._core._sockets import notify_closing as notify_closing -from ._core._sockets import wait_readable as wait_readable -from ._core._sockets import wait_socket_readable as wait_socket_readable -from ._core._sockets import wait_socket_writable as wait_socket_writable -from ._core._sockets import wait_writable as wait_writable -from ._core._streams import create_memory_object_stream as create_memory_object_stream -from ._core._subprocesses import open_process as open_process -from ._core._subprocesses import run_process as run_process -from ._core._synchronization import CapacityLimiter as CapacityLimiter -from ._core._synchronization import ( - CapacityLimiterStatistics as CapacityLimiterStatistics, -) -from ._core._synchronization import Condition as Condition -from ._core._synchronization import ConditionStatistics as ConditionStatistics -from ._core._synchronization import Event as Event -from ._core._synchronization import EventStatistics as EventStatistics -from ._core._synchronization import Lock as Lock -from ._core._synchronization import LockStatistics as LockStatistics -from ._core._synchronization import ResourceGuard as ResourceGuard -from ._core._synchronization import Semaphore as Semaphore -from ._core._synchronization import SemaphoreStatistics as SemaphoreStatistics -from ._core._tasks import TASK_STATUS_IGNORED as TASK_STATUS_IGNORED -from ._core._tasks import CancelScope as CancelScope -from ._core._tasks import create_task_group as create_task_group -from ._core._tasks import current_effective_deadline as current_effective_deadline -from ._core._tasks import fail_after as fail_after -from ._core._tasks import move_on_after as move_on_after -from ._core._tempfile import NamedTemporaryFile as NamedTemporaryFile -from ._core._tempfile import SpooledTemporaryFile as SpooledTemporaryFile -from ._core._tempfile import TemporaryDirectory as TemporaryDirectory -from ._core._tempfile import TemporaryFile as TemporaryFile -from ._core._tempfile import gettempdir as gettempdir -from ._core._tempfile import gettempdirb as gettempdirb -from ._core._tempfile import mkdtemp as mkdtemp -from ._core._tempfile import mkstemp as mkstemp -from ._core._testing import TaskInfo as TaskInfo -from ._core._testing import get_current_task as get_current_task -from ._core._testing import get_running_tasks as get_running_tasks -from ._core._testing import wait_all_tasks_blocked as wait_all_tasks_blocked -from ._core._typedattr import TypedAttributeProvider as TypedAttributeProvider -from ._core._typedattr import TypedAttributeSet as TypedAttributeSet -from ._core._typedattr import typed_attribute as typed_attribute - -# Re-export imports so they look like they live directly in this package -for __value in list(locals().values()): - if getattr(__value, "__module__", "").startswith("anyio."): - __value.__module__ = __name__ - - -del __value - - -def __getattr__(attr: str) -> type[BrokenWorkerInterpreter]: - """Support deprecated aliases.""" - if attr == "BrokenWorkerIntepreter": - import warnings - - warnings.warn( - "The 'BrokenWorkerIntepreter' alias is deprecated, use 'BrokenWorkerInterpreter' instead.", - DeprecationWarning, - stacklevel=2, - ) - return BrokenWorkerInterpreter - - raise AttributeError(f"module {__name__!r} has no attribute {attr!r}") diff --git a/.venv/lib/python3.12/site-packages/anyio/_backends/__init__.py b/.venv/lib/python3.12/site-packages/anyio/_backends/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/.venv/lib/python3.12/site-packages/anyio/_backends/_asyncio.py b/.venv/lib/python3.12/site-packages/anyio/_backends/_asyncio.py deleted file mode 100644 index 9f1ddc2..0000000 --- a/.venv/lib/python3.12/site-packages/anyio/_backends/_asyncio.py +++ /dev/null @@ -1,2996 +0,0 @@ -from __future__ import annotations - -import array -import asyncio -import concurrent.futures -import contextvars -import math -import os -import socket -import sys -import threading -import weakref -from asyncio import ( - AbstractEventLoop, - CancelledError, - all_tasks, - create_task, - current_task, - get_running_loop, - sleep, -) -from asyncio.base_events import _run_until_complete_cb # type: ignore[attr-defined] -from collections import OrderedDict, deque -from collections.abc import ( - AsyncGenerator, - AsyncIterator, - Awaitable, - Callable, - Collection, - Coroutine, - Iterable, - Sequence, -) -from concurrent.futures import Future -from contextlib import AbstractContextManager, suppress -from contextvars import Context, copy_context -from dataclasses import dataclass, field -from functools import partial, wraps -from inspect import ( - CORO_RUNNING, - CORO_SUSPENDED, - getcoroutinestate, - iscoroutine, -) -from io import IOBase -from os import PathLike -from queue import Queue -from signal import Signals -from socket import AddressFamily, SocketKind -from threading import Thread -from types import CodeType, TracebackType -from typing import ( - IO, - TYPE_CHECKING, - Any, - ParamSpec, - TypeVar, - cast, -) -from weakref import WeakKeyDictionary - -from .. import ( - CapacityLimiterStatistics, - EventStatistics, - LockStatistics, - TaskInfo, - abc, -) -from .._core._eventloop import ( - claim_worker_thread, - set_current_async_library, - threadlocals, -) -from .._core._exceptions import ( - BrokenResourceError, - BusyResourceError, - ClosedResourceError, - EndOfStream, - RunFinishedError, - WouldBlock, -) -from .._core._sockets import convert_ipv6_sockaddr -from .._core._streams import create_memory_object_stream -from .._core._synchronization import ( - CapacityLimiter as BaseCapacityLimiter, -) -from .._core._synchronization import Event as BaseEvent -from .._core._synchronization import Lock as BaseLock -from .._core._synchronization import ( - ResourceGuard, - SemaphoreStatistics, -) -from .._core._synchronization import Semaphore as BaseSemaphore -from .._core._tasks import CancelScope as BaseCancelScope -from ..abc import ( - AsyncBackend, - IPSockAddrType, - SocketListener, - UDPPacketType, - UNIXDatagramPacketType, -) -from ..abc._eventloop import StrOrBytesPath -from ..lowlevel import RunVar -from ..streams.memory import MemoryObjectReceiveStream, MemoryObjectSendStream - -if TYPE_CHECKING: - from _typeshed import FileDescriptorLike -else: - FileDescriptorLike = object - -if sys.version_info >= (3, 11): - from asyncio import Runner - from typing import TypeVarTuple, Unpack -else: - import contextvars - import enum - import signal - from asyncio import coroutines, events, exceptions, tasks - - from exceptiongroup import BaseExceptionGroup - from typing_extensions import TypeVarTuple, Unpack - - class _State(enum.Enum): - CREATED = "created" - INITIALIZED = "initialized" - CLOSED = "closed" - - class Runner: - # Copied from CPython 3.11 - def __init__( - self, - *, - debug: bool | None = None, - loop_factory: Callable[[], AbstractEventLoop] | None = None, - ): - self._state = _State.CREATED - self._debug = debug - self._loop_factory = loop_factory - self._loop: AbstractEventLoop | None = None - self._context = None - self._interrupt_count = 0 - self._set_event_loop = False - - def __enter__(self) -> Runner: - self._lazy_init() - return self - - def __exit__( - self, - exc_type: type[BaseException] | None, - exc_val: BaseException | None, - exc_tb: TracebackType | None, - ) -> None: - self.close() - - def close(self) -> None: - """Shutdown and close event loop.""" - loop = self._loop - if self._state is not _State.INITIALIZED or loop is None: - return - try: - _cancel_all_tasks(loop) - loop.run_until_complete(loop.shutdown_asyncgens()) - if hasattr(loop, "shutdown_default_executor"): - loop.run_until_complete(loop.shutdown_default_executor()) - else: - loop.run_until_complete(_shutdown_default_executor(loop)) - finally: - if self._set_event_loop: - events.set_event_loop(None) - loop.close() - self._loop = None - self._state = _State.CLOSED - - def get_loop(self) -> AbstractEventLoop: - """Return embedded event loop.""" - self._lazy_init() - return self._loop - - def run(self, coro: Coroutine[T_Retval], *, context=None) -> T_Retval: - """Run a coroutine inside the embedded event loop.""" - if not coroutines.iscoroutine(coro): - raise ValueError(f"a coroutine was expected, got {coro!r}") - - if events._get_running_loop() is not None: - # fail fast with short traceback - raise RuntimeError( - "Runner.run() cannot be called from a running event loop" - ) - - self._lazy_init() - - if context is None: - context = self._context - task = context.run(self._loop.create_task, coro) - - if ( - threading.current_thread() is threading.main_thread() - and signal.getsignal(signal.SIGINT) is signal.default_int_handler - ): - sigint_handler = partial(self._on_sigint, main_task=task) - try: - signal.signal(signal.SIGINT, sigint_handler) - except ValueError: - # `signal.signal` may throw if `threading.main_thread` does - # not support signals (e.g. embedded interpreter with signals - # not registered - see gh-91880) - sigint_handler = None - else: - sigint_handler = None - - self._interrupt_count = 0 - try: - return self._loop.run_until_complete(task) - except exceptions.CancelledError: - if self._interrupt_count > 0: - uncancel = getattr(task, "uncancel", None) - if uncancel is not None and uncancel() == 0: - raise KeyboardInterrupt # noqa: B904 - raise # CancelledError - finally: - if ( - sigint_handler is not None - and signal.getsignal(signal.SIGINT) is sigint_handler - ): - signal.signal(signal.SIGINT, signal.default_int_handler) - - def _lazy_init(self) -> None: - if self._state is _State.CLOSED: - raise RuntimeError("Runner is closed") - if self._state is _State.INITIALIZED: - return - if self._loop_factory is None: - self._loop = events.new_event_loop() - if not self._set_event_loop: - # Call set_event_loop only once to avoid calling - # attach_loop multiple times on child watchers - events.set_event_loop(self._loop) - self._set_event_loop = True - else: - self._loop = self._loop_factory() - if self._debug is not None: - self._loop.set_debug(self._debug) - self._context = contextvars.copy_context() - self._state = _State.INITIALIZED - - def _on_sigint(self, signum, frame, main_task: asyncio.Task) -> None: - self._interrupt_count += 1 - if self._interrupt_count == 1 and not main_task.done(): - main_task.cancel() - # wakeup loop if it is blocked by select() with long timeout - self._loop.call_soon_threadsafe(lambda: None) - return - raise KeyboardInterrupt() - - def _cancel_all_tasks(loop: AbstractEventLoop) -> None: - to_cancel = tasks.all_tasks(loop) - if not to_cancel: - return - - for task in to_cancel: - task.cancel() - - loop.run_until_complete(tasks.gather(*to_cancel, return_exceptions=True)) - - for task in to_cancel: - if task.cancelled(): - continue - if task.exception() is not None: - loop.call_exception_handler( - { - "message": "unhandled exception during asyncio.run() shutdown", - "exception": task.exception(), - "task": task, - } - ) - - async def _shutdown_default_executor(loop: AbstractEventLoop) -> None: - """Schedule the shutdown of the default executor.""" - - def _do_shutdown(future: asyncio.futures.Future) -> None: - try: - loop._default_executor.shutdown(wait=True) # type: ignore[attr-defined] - loop.call_soon_threadsafe(future.set_result, None) - except Exception as ex: - loop.call_soon_threadsafe(future.set_exception, ex) - - loop._executor_shutdown_called = True - if loop._default_executor is None: - return - future = loop.create_future() - thread = threading.Thread(target=_do_shutdown, args=(future,)) - thread.start() - try: - await future - finally: - thread.join() - - -T_Retval = TypeVar("T_Retval") -T_contra = TypeVar("T_contra", contravariant=True) -PosArgsT = TypeVarTuple("PosArgsT") -P = ParamSpec("P") - -_root_task: RunVar[asyncio.Task | None] = RunVar("_root_task") - - -def find_root_task() -> asyncio.Task: - root_task = _root_task.get(None) - if root_task is not None and not root_task.done(): - return root_task - - # Look for a task that has been started via run_until_complete() - for task in all_tasks(): - if task._callbacks and not task.done(): - callbacks = [cb for cb, context in task._callbacks] - for cb in callbacks: - if ( - cb is _run_until_complete_cb - or getattr(cb, "__module__", None) == "uvloop.loop" - ): - _root_task.set(task) - return task - - # Look up the topmost task in the AnyIO task tree, if possible - task = cast(asyncio.Task, current_task()) - state = _task_states.get(task) - if state: - cancel_scope = state.cancel_scope - while cancel_scope and cancel_scope._parent_scope is not None: - cancel_scope = cancel_scope._parent_scope - - if cancel_scope is not None: - return cast(asyncio.Task, cancel_scope._host_task) - - return task - - -def get_callable_name(func: Callable) -> str: - module = getattr(func, "__module__", None) - qualname = getattr(func, "__qualname__", None) - return ".".join([x for x in (module, qualname) if x]) - - -# -# Event loop -# - -_run_vars: WeakKeyDictionary[asyncio.AbstractEventLoop, Any] = WeakKeyDictionary() - - -def _task_started(task: asyncio.Task) -> bool: - """Return ``True`` if the task has been started and has not finished.""" - # The task coro should never be None here, as we never add finished tasks to the - # task list - coro = task.get_coro() - assert coro is not None - try: - return getcoroutinestate(coro) in (CORO_RUNNING, CORO_SUSPENDED) - except AttributeError: - # task coro is async_genenerator_asend https://bugs.python.org/issue37771 - raise Exception(f"Cannot determine if task {task} has started or not") from None - - -# -# Timeouts and cancellation -# - - -def is_anyio_cancellation(exc: CancelledError) -> bool: - # Sometimes third party frameworks catch a CancelledError and raise a new one, so as - # a workaround we have to look at the previous ones in __context__ too for a - # matching cancel message - while True: - if ( - exc.args - and isinstance(exc.args[0], str) - and exc.args[0].startswith("Cancelled via cancel scope ") - ): - return True - - if isinstance(exc.__context__, CancelledError): - exc = exc.__context__ - continue - - return False - - -class CancelScope(BaseCancelScope): - def __new__( - cls, *, deadline: float = math.inf, shield: bool = False - ) -> CancelScope: - return object.__new__(cls) - - def __init__(self, deadline: float = math.inf, shield: bool = False): - self._deadline = deadline - self._shield = shield - self._parent_scope: CancelScope | None = None - self._child_scopes: set[CancelScope] = set() - self._cancel_called = False - self._cancel_reason: str | None = None - self._cancelled_caught = False - self._active = False - self._timeout_handle: asyncio.TimerHandle | None = None - self._cancel_handle: asyncio.Handle | None = None - self._tasks: set[asyncio.Task] = set() - self._host_task: asyncio.Task | None = None - if sys.version_info >= (3, 11): - self._pending_uncancellations: int | None = 0 - else: - self._pending_uncancellations = None - - def __enter__(self) -> CancelScope: - if self._active: - raise RuntimeError( - "Each CancelScope may only be used for a single 'with' block" - ) - - self._host_task = host_task = cast(asyncio.Task, current_task()) - self._tasks.add(host_task) - try: - task_state = _task_states[host_task] - except KeyError: - task_state = TaskState(None, self) - _task_states[host_task] = task_state - else: - self._parent_scope = task_state.cancel_scope - task_state.cancel_scope = self - if self._parent_scope is not None: - # If using an eager task factory, the parent scope may not even contain - # the host task - self._parent_scope._child_scopes.add(self) - self._parent_scope._tasks.discard(host_task) - - self._timeout() - self._active = True - - # Start cancelling the host task if the scope was cancelled before entering - if self._cancel_called: - self._deliver_cancellation(self) - - return self - - def __exit__( - self, - exc_type: type[BaseException] | None, - exc_val: BaseException | None, - exc_tb: TracebackType | None, - ) -> bool: - del exc_tb - - if not self._active: - raise RuntimeError("This cancel scope is not active") - if current_task() is not self._host_task: - raise RuntimeError( - "Attempted to exit cancel scope in a different task than it was " - "entered in" - ) - - assert self._host_task is not None - host_task_state = _task_states.get(self._host_task) - if host_task_state is None or host_task_state.cancel_scope is not self: - raise RuntimeError( - "Attempted to exit a cancel scope that isn't the current tasks's " - "current cancel scope" - ) - - try: - self._active = False - if self._timeout_handle: - self._timeout_handle.cancel() - self._timeout_handle = None - - self._tasks.remove(self._host_task) - if self._parent_scope is not None: - self._parent_scope._child_scopes.remove(self) - self._parent_scope._tasks.add(self._host_task) - - host_task_state.cancel_scope = self._parent_scope - - # Restart the cancellation effort in the closest visible, cancelled parent - # scope if necessary - self._restart_cancellation_in_parent() - - # We only swallow the exception iff it was an AnyIO CancelledError, either - # directly as exc_val or inside an exception group and there are no cancelled - # parent cancel scopes visible to us here - if self._cancel_called and not self._parent_cancellation_is_visible_to_us: - # For each level-cancel() call made on the host task, call uncancel() - while self._pending_uncancellations: - self._host_task.uncancel() - self._pending_uncancellations -= 1 - - # Update cancelled_caught and check for exceptions we must not swallow - if isinstance(exc_val, BaseExceptionGroup): - cancelleds_caught, remaining = exc_val.split( - lambda exc: ( - isinstance(exc, CancelledError) - and is_anyio_cancellation(exc) - ) - ) - - if cancelleds_caught is None: - return False - - self._cancelled_caught = True - - if remaining is None: - return True - - context = remaining.__context__ - try: - # Preserve __cause__ and __suppress_context__ by avoiding `raise - # ... from ...` - raise remaining - finally: - # Preserve __context__ - remaining.__context__ = context - del context - else: - if isinstance(exc_val, CancelledError) and is_anyio_cancellation( - exc_val - ): - self._cancelled_caught = True - return True - else: - return False - else: - if self._pending_uncancellations: - assert self._parent_scope is not None - assert self._parent_scope._pending_uncancellations is not None - self._parent_scope._pending_uncancellations += ( - self._pending_uncancellations - ) - self._pending_uncancellations = 0 - - return False - finally: - self._host_task = None - del exc_val - - @property - def _effectively_cancelled(self) -> bool: - cancel_scope: CancelScope | None = self - while cancel_scope is not None: - if cancel_scope._cancel_called: - return True - - if cancel_scope.shield: - return False - - cancel_scope = cancel_scope._parent_scope - - return False - - @property - def _parent_cancellation_is_visible_to_us(self) -> bool: - return ( - self._parent_scope is not None - and not self.shield - and self._parent_scope._effectively_cancelled - ) - - def _timeout(self) -> None: - if self._deadline != math.inf: - loop = get_running_loop() - if loop.time() >= self._deadline: - self.cancel("deadline exceeded") - else: - self._timeout_handle = loop.call_at(self._deadline, self._timeout) - - def _deliver_cancellation(self, origin: CancelScope) -> bool: - """ - Deliver cancellation to directly contained tasks and nested cancel scopes. - - Schedule another run at the end if we still have tasks eligible for - cancellation. - - :param origin: the cancel scope that originated the cancellation - :return: ``True`` if the delivery needs to be retried on the next cycle - - """ - should_retry = False - current = current_task() - for task in self._tasks: - should_retry = True - if task._must_cancel: # type: ignore[attr-defined] - continue - - # The task is eligible for cancellation if it has started - if task is not current and (task is self._host_task or _task_started(task)): - waiter = task._fut_waiter # type: ignore[attr-defined] - if not isinstance(waiter, asyncio.Future) or not waiter.done(): - task.cancel(origin._cancel_reason) - if ( - task is origin._host_task - and origin._pending_uncancellations is not None - ): - origin._pending_uncancellations += 1 - - # Deliver cancellation to child scopes that aren't shielded or running their own - # cancellation callbacks - for scope in self._child_scopes: - if not scope._shield and not scope.cancel_called: - should_retry = scope._deliver_cancellation(origin) or should_retry - - # Schedule another callback if there are still tasks left - if origin is self: - if should_retry: - self._cancel_handle = get_running_loop().call_soon( - self._deliver_cancellation, origin - ) - else: - self._cancel_handle = None - - return should_retry - - def _restart_cancellation_in_parent(self) -> None: - """ - Restart the cancellation effort in the closest directly cancelled parent scope. - - """ - scope = self._parent_scope - while scope is not None: - if scope._cancel_called: - if scope._cancel_handle is None: - scope._deliver_cancellation(scope) - - break - - # No point in looking beyond any shielded scope - if scope._shield: - break - - scope = scope._parent_scope - - def cancel(self, reason: str | None = None) -> None: - if not self._cancel_called: - if self._timeout_handle: - self._timeout_handle.cancel() - self._timeout_handle = None - - self._cancel_called = True - self._cancel_reason = f"Cancelled via cancel scope {id(self):x}" - if task := current_task(): - self._cancel_reason += f" by {task}" - - if reason: - self._cancel_reason += f"; reason: {reason}" - - if self._host_task is not None: - self._deliver_cancellation(self) - - @property - def deadline(self) -> float: - return self._deadline - - @deadline.setter - def deadline(self, value: float) -> None: - self._deadline = float(value) - if self._timeout_handle is not None: - self._timeout_handle.cancel() - self._timeout_handle = None - - if self._active and not self._cancel_called: - self._timeout() - - @property - def cancel_called(self) -> bool: - return self._cancel_called - - @property - def cancelled_caught(self) -> bool: - return self._cancelled_caught - - @property - def shield(self) -> bool: - return self._shield - - @shield.setter - def shield(self, value: bool) -> None: - if self._shield != value: - self._shield = value - if not value: - self._restart_cancellation_in_parent() - - -# -# Task states -# - - -class TaskState: - """ - Encapsulates auxiliary task information that cannot be added to the Task instance - itself because there are no guarantees about its implementation. - """ - - __slots__ = "parent_id", "cancel_scope", "__weakref__" - - def __init__(self, parent_id: int | None, cancel_scope: CancelScope | None): - self.parent_id = parent_id - self.cancel_scope = cancel_scope - - -_task_states: WeakKeyDictionary[asyncio.Task, TaskState] = WeakKeyDictionary() - - -# -# Task groups -# - - -class _AsyncioTaskStatus(abc.TaskStatus): - def __init__(self, future: asyncio.Future, parent_id: int): - self._future = future - self._parent_id = parent_id - - def started(self, value: T_contra | None = None) -> None: - try: - self._future.set_result(value) - except asyncio.InvalidStateError: - if not self._future.cancelled(): - raise RuntimeError( - "called 'started' twice on the same task status" - ) from None - - task = cast(asyncio.Task, current_task()) - _task_states[task].parent_id = self._parent_id - - -if sys.version_info >= (3, 12): - _eager_task_factory_code: CodeType | None = asyncio.eager_task_factory.__code__ -else: - _eager_task_factory_code = None - - -class TaskGroup(abc.TaskGroup): - def __init__(self) -> None: - self.cancel_scope: CancelScope = CancelScope() - self._active = False - self._exceptions: list[BaseException] = [] - self._tasks: set[asyncio.Task] = set() - self._on_completed_fut: asyncio.Future[None] | None = None - - async def __aenter__(self) -> TaskGroup: - self.cancel_scope.__enter__() - self._active = True - return self - - async def __aexit__( - self, - exc_type: type[BaseException] | None, - exc_val: BaseException | None, - exc_tb: TracebackType | None, - ) -> bool: - try: - if exc_val is not None: - self.cancel_scope.cancel() - if not isinstance(exc_val, CancelledError): - self._exceptions.append(exc_val) - - loop = get_running_loop() - try: - if self._tasks: - with CancelScope() as wait_scope: - while self._tasks: - self._on_completed_fut = loop.create_future() - - try: - await self._on_completed_fut - except CancelledError as exc: - # Shield the scope against further cancellation attempts, - # as they're not productive (#695) - wait_scope.shield = True - self.cancel_scope.cancel() - - # Set exc_val from the cancellation exception if it was - # previously unset. However, we should not replace a native - # cancellation exception with one raise by a cancel scope. - if exc_val is None or ( - isinstance(exc_val, CancelledError) - and not is_anyio_cancellation(exc) - ): - exc_val = exc - - self._on_completed_fut = None - else: - # If there are no child tasks to wait on, run at least one checkpoint - # anyway - await AsyncIOBackend.cancel_shielded_checkpoint() - - self._active = False - if self._exceptions: - # The exception that got us here should already have been - # added to self._exceptions so it's ok to break exception - # chaining and avoid adding a "During handling of above..." - # for each nesting level. - raise BaseExceptionGroup( - "unhandled errors in a TaskGroup", self._exceptions - ) from None - elif exc_val: - raise exc_val - except BaseException as exc: - if self.cancel_scope.__exit__(type(exc), exc, exc.__traceback__): - return True - - raise - - return self.cancel_scope.__exit__(exc_type, exc_val, exc_tb) - finally: - del exc_val, exc_tb, self._exceptions - - def _spawn( - self, - func: Callable[[Unpack[PosArgsT]], Awaitable[Any]], - args: tuple[Unpack[PosArgsT]], - name: object, - task_status_future: asyncio.Future | None = None, - ) -> asyncio.Task: - def task_done(_task: asyncio.Task) -> None: - if sys.version_info >= (3, 14) and self.cancel_scope._host_task is not None: - asyncio.future_discard_from_awaited_by( - _task, self.cancel_scope._host_task - ) - - task_state = _task_states[_task] - assert task_state.cancel_scope is not None - assert _task in task_state.cancel_scope._tasks - task_state.cancel_scope._tasks.remove(_task) - self._tasks.remove(task) - del _task_states[_task] - - if self._on_completed_fut is not None and not self._tasks: - try: - self._on_completed_fut.set_result(None) - except asyncio.InvalidStateError: - pass - - try: - exc = _task.exception() - except CancelledError as e: - while isinstance(e.__context__, CancelledError): - e = e.__context__ - - exc = e - - if exc is not None: - # The future can only be in the cancelled state if the host task was - # cancelled, so return immediately instead of adding one more - # CancelledError to the exceptions list - if task_status_future is not None and task_status_future.cancelled(): - return - - if task_status_future is None or task_status_future.done(): - if not isinstance(exc, CancelledError): - self._exceptions.append(exc) - - if not self.cancel_scope._effectively_cancelled: - self.cancel_scope.cancel() - else: - task_status_future.set_exception(exc) - elif task_status_future is not None and not task_status_future.done(): - task_status_future.set_exception( - RuntimeError("Child exited without calling task_status.started()") - ) - - if not self._active: - raise RuntimeError( - "This task group is not active; no new tasks can be started." - ) - - kwargs = {} - if task_status_future: - parent_id = id(current_task()) - kwargs["task_status"] = _AsyncioTaskStatus( - task_status_future, id(self.cancel_scope._host_task) - ) - else: - parent_id = id(self.cancel_scope._host_task) - - coro = func(*args, **kwargs) - if not iscoroutine(coro): - prefix = f"{func.__module__}." if hasattr(func, "__module__") else "" - raise TypeError( - f"Expected {prefix}{func.__qualname__}() to return a coroutine, but " - f"the return value ({coro!r}) is not a coroutine object" - ) - - name = get_callable_name(func) if name is None else str(name) - loop = asyncio.get_running_loop() - if ( - (factory := loop.get_task_factory()) - and getattr(factory, "__code__", None) is _eager_task_factory_code - and (closure := getattr(factory, "__closure__", None)) - ): - custom_task_constructor = closure[0].cell_contents - task = custom_task_constructor(coro, loop=loop, name=name) - else: - task = create_task(coro, name=name) - - # Make the spawned task inherit the task group's cancel scope - _task_states[task] = TaskState( - parent_id=parent_id, cancel_scope=self.cancel_scope - ) - self.cancel_scope._tasks.add(task) - self._tasks.add(task) - if sys.version_info >= (3, 14) and self.cancel_scope._host_task is not None: - asyncio.future_add_to_awaited_by(task, self.cancel_scope._host_task) - - task.add_done_callback(task_done) - return task - - def start_soon( - self, - func: Callable[[Unpack[PosArgsT]], Awaitable[Any]], - *args: Unpack[PosArgsT], - name: object = None, - ) -> None: - self._spawn(func, args, name) - - async def start( - self, func: Callable[..., Awaitable[Any]], *args: object, name: object = None - ) -> Any: - future: asyncio.Future = asyncio.Future() - task = self._spawn(func, args, name, future) - - # If the task raises an exception after sending a start value without a switch - # point between, the task group is cancelled and this method never proceeds to - # process the completed future. That's why we have to have a shielded cancel - # scope here. - try: - return await future - except CancelledError: - # Cancel the task and wait for it to exit before returning - task.cancel() - with CancelScope(shield=True), suppress(CancelledError): - await task - - raise - - -# -# Threads -# - -_Retval_Queue_Type = tuple[T_Retval | None, BaseException | None] - - -class WorkerThread(Thread): - MAX_IDLE_TIME = 10 # seconds - - def __init__( - self, - root_task: asyncio.Task, - workers: set[WorkerThread], - idle_workers: deque[WorkerThread], - ): - super().__init__(name="AnyIO worker thread") - self.root_task = root_task - self.workers = workers - self.idle_workers = idle_workers - self.loop = root_task._loop - self.queue: Queue[ - tuple[Context, Callable, tuple, asyncio.Future, CancelScope] | None - ] = Queue(2) - self.idle_since = AsyncIOBackend.current_time() - self.stopping = False - - def _report_result( - self, future: asyncio.Future, result: Any, exc: BaseException | None - ) -> None: - self.idle_since = AsyncIOBackend.current_time() - if not self.stopping: - self.idle_workers.append(self) - - if not future.cancelled(): - if exc is not None: - if isinstance(exc, StopIteration): - new_exc = RuntimeError("coroutine raised StopIteration") - new_exc.__cause__ = exc - exc = new_exc - - future.set_exception(exc) - else: - future.set_result(result) - - def run(self) -> None: - with claim_worker_thread(AsyncIOBackend, self.loop): - while True: - item = self.queue.get() - if item is None: - # Shutdown command received - return - - context, func, args, future, cancel_scope = item - if not future.cancelled(): - result = None - exception: BaseException | None = None - threadlocals.current_cancel_scope = cancel_scope - try: - result = context.run(func, *args) - except BaseException as exc: - exception = exc - finally: - del threadlocals.current_cancel_scope - - if not self.loop.is_closed(): - self.loop.call_soon_threadsafe( - self._report_result, future, result, exception - ) - - del result, exception - - self.queue.task_done() - del item, context, func, args, future, cancel_scope - - def stop(self, f: asyncio.Task | None = None) -> None: - self.stopping = True - self.queue.put_nowait(None) - self.workers.discard(self) - try: - self.idle_workers.remove(self) - except ValueError: - pass - - -_threadpool_idle_workers: RunVar[deque[WorkerThread]] = RunVar( - "_threadpool_idle_workers" -) -_threadpool_workers: RunVar[set[WorkerThread]] = RunVar("_threadpool_workers") - - -# -# Subprocesses -# - - -@dataclass(eq=False) -class StreamReaderWrapper(abc.ByteReceiveStream): - _stream: asyncio.StreamReader - - async def receive(self, max_bytes: int = 65536) -> bytes: - data = await self._stream.read(max_bytes) - if data: - return data - else: - raise EndOfStream - - async def aclose(self) -> None: - self._stream.set_exception(ClosedResourceError()) - await AsyncIOBackend.checkpoint() - - -@dataclass(eq=False) -class StreamWriterWrapper(abc.ByteSendStream): - _stream: asyncio.StreamWriter - _closed: bool = field(init=False, default=False) - - async def send(self, item: bytes) -> None: - await AsyncIOBackend.checkpoint_if_cancelled() - stream_paused = self._stream._protocol._paused # type: ignore[attr-defined] - try: - self._stream.write(item) - await self._stream.drain() - except (ConnectionResetError, BrokenPipeError, RuntimeError) as exc: - # If closed by us and/or the peer: - # * on stdlib, drain() raises ConnectionResetError or BrokenPipeError - # * on uvloop and Winloop, write() eventually starts raising RuntimeError - if self._closed: - raise ClosedResourceError from exc - elif self._stream.is_closing(): - raise BrokenResourceError from exc - - raise - - if not stream_paused: - await AsyncIOBackend.cancel_shielded_checkpoint() - - async def aclose(self) -> None: - self._closed = True - self._stream.close() - await AsyncIOBackend.checkpoint() - - -@dataclass(eq=False) -class Process(abc.Process): - _process: asyncio.subprocess.Process - _stdin: StreamWriterWrapper | None - _stdout: StreamReaderWrapper | None - _stderr: StreamReaderWrapper | None - - async def aclose(self) -> None: - with CancelScope(shield=True) as scope: - if self._stdin: - await self._stdin.aclose() - if self._stdout: - await self._stdout.aclose() - if self._stderr: - await self._stderr.aclose() - - scope.shield = False - try: - await self.wait() - except BaseException: - scope.shield = True - self.kill() - await self.wait() - raise - - async def wait(self) -> int: - return await self._process.wait() - - def terminate(self) -> None: - self._process.terminate() - - def kill(self) -> None: - self._process.kill() - - def send_signal(self, signal: int) -> None: - self._process.send_signal(signal) - - @property - def pid(self) -> int: - return self._process.pid - - @property - def returncode(self) -> int | None: - return self._process.returncode - - @property - def stdin(self) -> abc.ByteSendStream | None: - return self._stdin - - @property - def stdout(self) -> abc.ByteReceiveStream | None: - return self._stdout - - @property - def stderr(self) -> abc.ByteReceiveStream | None: - return self._stderr - - -def _forcibly_shutdown_process_pool_on_exit( - workers: set[Process], _task: object -) -> None: - """ - Forcibly shuts down worker processes belonging to this event loop.""" - child_watcher: asyncio.AbstractChildWatcher | None = None # type: ignore[name-defined] - if sys.version_info < (3, 12): - try: - child_watcher = asyncio.get_event_loop_policy().get_child_watcher() - except NotImplementedError: - pass - - # Close as much as possible (w/o async/await) to avoid warnings - for process in workers.copy(): - if process.returncode is not None: - continue - - process._stdin._stream._transport.close() # type: ignore[union-attr] - process._stdout._stream._transport.close() # type: ignore[union-attr] - process._stderr._stream._transport.close() # type: ignore[union-attr] - process.kill() - if child_watcher: - child_watcher.remove_child_handler(process.pid) - - -async def _shutdown_process_pool_on_exit(workers: set[abc.Process]) -> None: - """ - Shuts down worker processes belonging to this event loop. - - NOTE: this only works when the event loop was started using asyncio.run() or - anyio.run(). - - """ - process: abc.Process - try: - await sleep(math.inf) - except asyncio.CancelledError: - workers = workers.copy() - for process in workers: - if process.returncode is None: - process.kill() - - for process in workers: - await process.aclose() - - -# -# Sockets and networking -# - - -class StreamProtocol(asyncio.Protocol): - read_queue: deque[bytes] - read_event: asyncio.Event - write_event: asyncio.Event - exception: Exception | None = None - is_at_eof: bool = False - - def connection_made(self, transport: asyncio.BaseTransport) -> None: - self.read_queue = deque() - self.read_event = asyncio.Event() - self.write_event = asyncio.Event() - self.write_event.set() - cast(asyncio.Transport, transport).set_write_buffer_limits(0) - - def connection_lost(self, exc: Exception | None) -> None: - if exc: - self.exception = exc - - self.read_event.set() - self.write_event.set() - - def data_received(self, data: bytes) -> None: - # ProactorEventloop sometimes sends bytearray instead of bytes - self.read_queue.append(bytes(data)) - self.read_event.set() - - def eof_received(self) -> bool | None: - self.is_at_eof = True - self.read_event.set() - return True - - def pause_writing(self) -> None: - self.write_event = asyncio.Event() - - def resume_writing(self) -> None: - self.write_event.set() - - -class DatagramProtocol(asyncio.DatagramProtocol): - read_queue: deque[tuple[bytes, IPSockAddrType]] - read_event: asyncio.Event - write_event: asyncio.Event - exception: Exception | None = None - - def connection_made(self, transport: asyncio.BaseTransport) -> None: - self.read_queue = deque(maxlen=100) # arbitrary value - self.read_event = asyncio.Event() - self.write_event = asyncio.Event() - self.write_event.set() - - def connection_lost(self, exc: Exception | None) -> None: - self.read_event.set() - self.write_event.set() - - def datagram_received(self, data: bytes, addr: IPSockAddrType) -> None: - addr = convert_ipv6_sockaddr(addr) - self.read_queue.append((data, addr)) - self.read_event.set() - - def error_received(self, exc: Exception) -> None: - self.exception = exc - - def pause_writing(self) -> None: - self.write_event.clear() - - def resume_writing(self) -> None: - self.write_event.set() - - -class SocketStream(abc.SocketStream): - def __init__(self, transport: asyncio.Transport, protocol: StreamProtocol): - self._transport = transport - self._protocol = protocol - self._receive_guard = ResourceGuard("reading from") - self._send_guard = ResourceGuard("writing to") - self._closed = False - - @property - def _raw_socket(self) -> socket.socket: - return self._transport.get_extra_info("socket") - - async def receive(self, max_bytes: int = 65536) -> bytes: - with self._receive_guard: - if ( - not self._protocol.read_event.is_set() - and not self._transport.is_closing() - and not self._protocol.is_at_eof - ): - self._transport.resume_reading() - await self._protocol.read_event.wait() - self._transport.pause_reading() - else: - await AsyncIOBackend.checkpoint() - - try: - chunk = self._protocol.read_queue.popleft() - except IndexError: - if self._closed: - raise ClosedResourceError from None - elif self._protocol.exception: - raise BrokenResourceError from self._protocol.exception - else: - raise EndOfStream from None - - if len(chunk) > max_bytes: - # Split the oversized chunk - chunk, leftover = chunk[:max_bytes], chunk[max_bytes:] - self._protocol.read_queue.appendleft(leftover) - - # If the read queue is empty, clear the flag so that the next call will - # block until data is available - if not self._protocol.read_queue: - self._protocol.read_event.clear() - - return chunk - - async def send(self, item: bytes) -> None: - with self._send_guard: - await AsyncIOBackend.checkpoint() - - if self._closed: - raise ClosedResourceError - elif self._protocol.exception is not None: - raise BrokenResourceError from self._protocol.exception - - try: - self._transport.write(item) - except RuntimeError as exc: - if self._transport.is_closing(): - raise BrokenResourceError from exc - else: - raise - - await self._protocol.write_event.wait() - - async def send_eof(self) -> None: - try: - self._transport.write_eof() - except OSError: - pass - - async def aclose(self) -> None: - self._closed = True - if not self._transport.is_closing(): - try: - self._transport.write_eof() - except OSError: - pass - - self._transport.close() - await sleep(0) - self._transport.abort() - - -class _RawSocketMixin: - _receive_future: asyncio.Future | None = None - _send_future: asyncio.Future | None = None - _closing = False - - def __init__(self, raw_socket: socket.socket): - self.__raw_socket = raw_socket - self._receive_guard = ResourceGuard("reading from") - self._send_guard = ResourceGuard("writing to") - - @property - def _raw_socket(self) -> socket.socket: - return self.__raw_socket - - def _wait_until_readable(self, loop: asyncio.AbstractEventLoop) -> asyncio.Future: - def callback(f: object) -> None: - del self._receive_future - loop.remove_reader(self.__raw_socket) - - f = self._receive_future = asyncio.Future() - loop.add_reader(self.__raw_socket, f.set_result, None) - f.add_done_callback(callback) - return f - - def _wait_until_writable(self, loop: asyncio.AbstractEventLoop) -> asyncio.Future: - def callback(f: object) -> None: - del self._send_future - loop.remove_writer(self.__raw_socket) - - f = self._send_future = asyncio.Future() - loop.add_writer(self.__raw_socket, f.set_result, None) - f.add_done_callback(callback) - return f - - async def aclose(self) -> None: - if not self._closing: - self._closing = True - if self.__raw_socket.fileno() != -1: - self.__raw_socket.close() - - if self._receive_future: - self._receive_future.set_result(None) - if self._send_future: - self._send_future.set_result(None) - - -class UNIXSocketStream(_RawSocketMixin, abc.UNIXSocketStream): - async def send_eof(self) -> None: - with self._send_guard: - self._raw_socket.shutdown(socket.SHUT_WR) - - async def receive(self, max_bytes: int = 65536) -> bytes: - loop = get_running_loop() - await AsyncIOBackend.checkpoint() - with self._receive_guard: - while True: - try: - data = self._raw_socket.recv(max_bytes) - except BlockingIOError: - await self._wait_until_readable(loop) - except OSError as exc: - if self._closing: - raise ClosedResourceError from None - else: - raise BrokenResourceError from exc - else: - if not data: - raise EndOfStream - - return data - - async def send(self, item: bytes) -> None: - loop = get_running_loop() - await AsyncIOBackend.checkpoint() - with self._send_guard: - view = memoryview(item) - while view: - try: - bytes_sent = self._raw_socket.send(view) - except BlockingIOError: - await self._wait_until_writable(loop) - except OSError as exc: - if self._closing: - raise ClosedResourceError from None - else: - raise BrokenResourceError from exc - else: - view = view[bytes_sent:] - - async def receive_fds(self, msglen: int, maxfds: int) -> tuple[bytes, list[int]]: - if not isinstance(msglen, int) or msglen < 0: - raise ValueError("msglen must be a non-negative integer") - if not isinstance(maxfds, int) or maxfds < 1: - raise ValueError("maxfds must be a positive integer") - - loop = get_running_loop() - fds = array.array("i") - await AsyncIOBackend.checkpoint() - with self._receive_guard: - while True: - try: - message, ancdata, flags, addr = self._raw_socket.recvmsg( - msglen, socket.CMSG_LEN(maxfds * fds.itemsize) - ) - except BlockingIOError: - await self._wait_until_readable(loop) - except OSError as exc: - if self._closing: - raise ClosedResourceError from None - else: - raise BrokenResourceError from exc - else: - if not message and not ancdata: - raise EndOfStream - - break - - for cmsg_level, cmsg_type, cmsg_data in ancdata: - if cmsg_level != socket.SOL_SOCKET or cmsg_type != socket.SCM_RIGHTS: - raise RuntimeError( - f"Received unexpected ancillary data; message = {message!r}, " - f"cmsg_level = {cmsg_level}, cmsg_type = {cmsg_type}" - ) - - fds.frombytes(cmsg_data[: len(cmsg_data) - (len(cmsg_data) % fds.itemsize)]) - - return message, list(fds) - - async def send_fds(self, message: bytes, fds: Collection[int | IOBase]) -> None: - if not message: - raise ValueError("message must not be empty") - if not fds: - raise ValueError("fds must not be empty") - - loop = get_running_loop() - filenos: list[int] = [] - for fd in fds: - if isinstance(fd, int): - filenos.append(fd) - elif isinstance(fd, IOBase): - filenos.append(fd.fileno()) - - fdarray = array.array("i", filenos) - await AsyncIOBackend.checkpoint() - with self._send_guard: - while True: - try: - # The ignore can be removed after mypy picks up - # https://github.com/python/typeshed/pull/5545 - self._raw_socket.sendmsg( - [message], [(socket.SOL_SOCKET, socket.SCM_RIGHTS, fdarray)] - ) - break - except BlockingIOError: - await self._wait_until_writable(loop) - except OSError as exc: - if self._closing: - raise ClosedResourceError from None - else: - raise BrokenResourceError from exc - - -class TCPSocketListener(abc.SocketListener): - _accept_scope: CancelScope | None = None - _closed = False - - def __init__(self, raw_socket: socket.socket): - self.__raw_socket = raw_socket - self._loop = cast(asyncio.BaseEventLoop, get_running_loop()) - self._accept_guard = ResourceGuard("accepting connections from") - - @property - def _raw_socket(self) -> socket.socket: - return self.__raw_socket - - async def accept(self) -> abc.SocketStream: - if self._closed: - raise ClosedResourceError - - with self._accept_guard: - await AsyncIOBackend.checkpoint() - with CancelScope() as self._accept_scope: - try: - client_sock, _addr = await self._loop.sock_accept(self._raw_socket) - except asyncio.CancelledError: - # Workaround for https://bugs.python.org/issue41317 - try: - self._loop.remove_reader(self._raw_socket) - except (ValueError, NotImplementedError): - pass - - if self._closed: - raise ClosedResourceError from None - - raise - finally: - self._accept_scope = None - - client_sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) - transport, protocol = await self._loop.connect_accepted_socket( - StreamProtocol, client_sock - ) - return SocketStream(transport, protocol) - - async def aclose(self) -> None: - if self._closed: - return - - self._closed = True - if self._accept_scope: - # Workaround for https://bugs.python.org/issue41317 - try: - self._loop.remove_reader(self._raw_socket) - except (ValueError, NotImplementedError): - pass - - self._accept_scope.cancel() - await sleep(0) - - self._raw_socket.close() - - -class UNIXSocketListener(abc.SocketListener): - def __init__(self, raw_socket: socket.socket): - self.__raw_socket = raw_socket - self._loop = get_running_loop() - self._accept_guard = ResourceGuard("accepting connections from") - self._closed = False - - async def accept(self) -> abc.SocketStream: - await AsyncIOBackend.checkpoint() - with self._accept_guard: - while True: - try: - client_sock, _ = self.__raw_socket.accept() - client_sock.setblocking(False) - return UNIXSocketStream(client_sock) - except BlockingIOError: - f: asyncio.Future = asyncio.Future() - self._loop.add_reader(self.__raw_socket, f.set_result, None) - f.add_done_callback( - lambda _: self._loop.remove_reader(self.__raw_socket) - ) - await f - except OSError as exc: - if self._closed: - raise ClosedResourceError from None - else: - raise BrokenResourceError from exc - - async def aclose(self) -> None: - self._closed = True - self.__raw_socket.close() - - @property - def _raw_socket(self) -> socket.socket: - return self.__raw_socket - - -class UDPSocket(abc.UDPSocket): - def __init__( - self, transport: asyncio.DatagramTransport, protocol: DatagramProtocol - ): - self._transport = transport - self._protocol = protocol - self._receive_guard = ResourceGuard("reading from") - self._send_guard = ResourceGuard("writing to") - self._closed = False - - @property - def _raw_socket(self) -> socket.socket: - return self._transport.get_extra_info("socket") - - async def aclose(self) -> None: - self._closed = True - if not self._transport.is_closing(): - self._transport.close() - - async def receive(self) -> tuple[bytes, IPSockAddrType]: - with self._receive_guard: - await AsyncIOBackend.checkpoint() - - # If the buffer is empty, ask for more data - if not self._protocol.read_queue and not self._transport.is_closing(): - self._protocol.read_event.clear() - await self._protocol.read_event.wait() - - try: - return self._protocol.read_queue.popleft() - except IndexError: - if self._closed: - raise ClosedResourceError from None - else: - raise BrokenResourceError from None - - async def send(self, item: UDPPacketType) -> None: - with self._send_guard: - await AsyncIOBackend.checkpoint() - await self._protocol.write_event.wait() - if self._closed: - raise ClosedResourceError - elif self._transport.is_closing(): - raise BrokenResourceError - else: - self._transport.sendto(*item) - - -class ConnectedUDPSocket(abc.ConnectedUDPSocket): - def __init__( - self, transport: asyncio.DatagramTransport, protocol: DatagramProtocol - ): - self._transport = transport - self._protocol = protocol - self._receive_guard = ResourceGuard("reading from") - self._send_guard = ResourceGuard("writing to") - self._closed = False - - @property - def _raw_socket(self) -> socket.socket: - return self._transport.get_extra_info("socket") - - async def aclose(self) -> None: - self._closed = True - if not self._transport.is_closing(): - self._transport.close() - - async def receive(self) -> bytes: - with self._receive_guard: - await AsyncIOBackend.checkpoint() - - # If the buffer is empty, ask for more data - if not self._protocol.read_queue and not self._transport.is_closing(): - self._protocol.read_event.clear() - await self._protocol.read_event.wait() - - try: - packet = self._protocol.read_queue.popleft() - except IndexError: - if self._closed: - raise ClosedResourceError from None - else: - raise BrokenResourceError from None - - return packet[0] - - async def send(self, item: bytes) -> None: - with self._send_guard: - await AsyncIOBackend.checkpoint() - await self._protocol.write_event.wait() - if self._closed: - raise ClosedResourceError - elif self._transport.is_closing(): - raise BrokenResourceError - else: - self._transport.sendto(item) - - -class UNIXDatagramSocket(_RawSocketMixin, abc.UNIXDatagramSocket): - async def receive(self) -> UNIXDatagramPacketType: - loop = get_running_loop() - await AsyncIOBackend.checkpoint() - with self._receive_guard: - while True: - try: - data = self._raw_socket.recvfrom(65536) - except BlockingIOError: - await self._wait_until_readable(loop) - except OSError as exc: - if self._closing: - raise ClosedResourceError from None - else: - raise BrokenResourceError from exc - else: - return data - - async def send(self, item: UNIXDatagramPacketType) -> None: - loop = get_running_loop() - await AsyncIOBackend.checkpoint() - with self._send_guard: - while True: - try: - self._raw_socket.sendto(*item) - except BlockingIOError: - await self._wait_until_writable(loop) - except OSError as exc: - if self._closing: - raise ClosedResourceError from None - else: - raise BrokenResourceError from exc - else: - return - - -class ConnectedUNIXDatagramSocket(_RawSocketMixin, abc.ConnectedUNIXDatagramSocket): - async def receive(self) -> bytes: - loop = get_running_loop() - await AsyncIOBackend.checkpoint() - with self._receive_guard: - while True: - try: - data = self._raw_socket.recv(65536) - except BlockingIOError: - await self._wait_until_readable(loop) - except OSError as exc: - if self._closing: - raise ClosedResourceError from None - else: - raise BrokenResourceError from exc - else: - return data - - async def send(self, item: bytes) -> None: - loop = get_running_loop() - await AsyncIOBackend.checkpoint() - with self._send_guard: - while True: - try: - self._raw_socket.send(item) - except BlockingIOError: - await self._wait_until_writable(loop) - except OSError as exc: - if self._closing: - raise ClosedResourceError from None - else: - raise BrokenResourceError from exc - else: - return - - -_read_events: RunVar[dict[int, asyncio.Future[bool]]] = RunVar("read_events") -_write_events: RunVar[dict[int, asyncio.Future[bool]]] = RunVar("write_events") - - -# -# Synchronization -# - - -class Event(BaseEvent): - def __new__(cls) -> Event: - return object.__new__(cls) - - def __init__(self) -> None: - self._event = asyncio.Event() - - def set(self) -> None: - self._event.set() - - def is_set(self) -> bool: - return self._event.is_set() - - async def wait(self) -> None: - if self.is_set(): - await AsyncIOBackend.checkpoint() - else: - await self._event.wait() - - def statistics(self) -> EventStatistics: - return EventStatistics(len(self._event._waiters)) - - -class Lock(BaseLock): - def __new__(cls, *, fast_acquire: bool = False) -> Lock: - return object.__new__(cls) - - def __init__(self, *, fast_acquire: bool = False) -> None: - self._fast_acquire = fast_acquire - self._owner_task: asyncio.Task | None = None - self._waiters: deque[tuple[asyncio.Task, asyncio.Future]] = deque() - - async def acquire(self) -> None: - task = cast(asyncio.Task, current_task()) - if self._owner_task is None and not self._waiters: - await AsyncIOBackend.checkpoint_if_cancelled() - self._owner_task = task - - # Unless on the "fast path", yield control of the event loop so that other - # tasks can run too - if not self._fast_acquire: - try: - await AsyncIOBackend.cancel_shielded_checkpoint() - except CancelledError: - self.release() - raise - - return - - if self._owner_task == task: - raise RuntimeError("Attempted to acquire an already held Lock") - - fut: asyncio.Future[None] = asyncio.Future() - item = task, fut - self._waiters.append(item) - try: - await fut - except CancelledError: - self._waiters.remove(item) - if self._owner_task is task: - self.release() - - raise - - self._waiters.remove(item) - - def acquire_nowait(self) -> None: - task = cast(asyncio.Task, current_task()) - if self._owner_task is None and not self._waiters: - self._owner_task = task - return - - if self._owner_task is task: - raise RuntimeError("Attempted to acquire an already held Lock") - - raise WouldBlock - - def locked(self) -> bool: - return self._owner_task is not None - - def release(self) -> None: - if self._owner_task != current_task(): - raise RuntimeError("The current task is not holding this lock") - - for task, fut in self._waiters: - if not fut.cancelled(): - self._owner_task = task - fut.set_result(None) - return - - self._owner_task = None - - def statistics(self) -> LockStatistics: - task_info = AsyncIOTaskInfo(self._owner_task) if self._owner_task else None - return LockStatistics(self.locked(), task_info, len(self._waiters)) - - -class Semaphore(BaseSemaphore): - def __new__( - cls, - initial_value: int, - *, - max_value: int | None = None, - fast_acquire: bool = False, - ) -> Semaphore: - return object.__new__(cls) - - def __init__( - self, - initial_value: int, - *, - max_value: int | None = None, - fast_acquire: bool = False, - ): - super().__init__(initial_value, max_value=max_value) - self._value = initial_value - self._max_value = max_value - self._fast_acquire = fast_acquire - self._waiters: deque[asyncio.Future[None]] = deque() - - async def acquire(self) -> None: - if self._value > 0 and not self._waiters: - await AsyncIOBackend.checkpoint_if_cancelled() - self._value -= 1 - - # Unless on the "fast path", yield control of the event loop so that other - # tasks can run too - if not self._fast_acquire: - try: - await AsyncIOBackend.cancel_shielded_checkpoint() - except CancelledError: - self.release() - raise - - return - - fut: asyncio.Future[None] = asyncio.Future() - self._waiters.append(fut) - try: - await fut - except CancelledError: - try: - self._waiters.remove(fut) - except ValueError: - self.release() - - raise - - def acquire_nowait(self) -> None: - if self._value == 0: - raise WouldBlock - - self._value -= 1 - - def release(self) -> None: - if self._max_value is not None and self._value == self._max_value: - raise ValueError("semaphore released too many times") - - for fut in self._waiters: - if not fut.cancelled(): - fut.set_result(None) - self._waiters.remove(fut) - return - - self._value += 1 - - @property - def value(self) -> int: - return self._value - - @property - def max_value(self) -> int | None: - return self._max_value - - def statistics(self) -> SemaphoreStatistics: - return SemaphoreStatistics(len(self._waiters)) - - -class CapacityLimiter(BaseCapacityLimiter): - _total_tokens: float = 0 - - def __new__(cls, total_tokens: float) -> CapacityLimiter: - return object.__new__(cls) - - def __init__(self, total_tokens: float): - self._borrowers: set[Any] = set() - self._wait_queue: OrderedDict[Any, asyncio.Event] = OrderedDict() - self.total_tokens = total_tokens - - async def __aenter__(self) -> None: - await self.acquire() - - async def __aexit__( - self, - exc_type: type[BaseException] | None, - exc_val: BaseException | None, - exc_tb: TracebackType | None, - ) -> None: - self.release() - - @property - def total_tokens(self) -> float: - return self._total_tokens - - @total_tokens.setter - def total_tokens(self, value: float) -> None: - if not isinstance(value, int) and not math.isinf(value): - raise TypeError("total_tokens must be an int or math.inf") - - if value < 0: - raise ValueError("total_tokens must be >= 0") - - waiters_to_notify = max(value - self._total_tokens, 0) - self._total_tokens = value - - # Notify waiting tasks that they have acquired the limiter - while self._wait_queue and waiters_to_notify: - event = self._wait_queue.popitem(last=False)[1] - event.set() - waiters_to_notify -= 1 - - @property - def borrowed_tokens(self) -> int: - return len(self._borrowers) - - @property - def available_tokens(self) -> float: - return self._total_tokens - len(self._borrowers) - - def _notify_next_waiter(self) -> None: - """Notify the next task in line if this limiter has free capacity now.""" - if self._wait_queue and len(self._borrowers) < self._total_tokens: - event = self._wait_queue.popitem(last=False)[1] - event.set() - - def acquire_nowait(self) -> None: - self.acquire_on_behalf_of_nowait(current_task()) - - def acquire_on_behalf_of_nowait(self, borrower: object) -> None: - if borrower in self._borrowers: - raise RuntimeError( - "this borrower is already holding one of this CapacityLimiter's tokens" - ) - - if self._wait_queue or len(self._borrowers) >= self._total_tokens: - raise WouldBlock - - self._borrowers.add(borrower) - - async def acquire(self) -> None: - return await self.acquire_on_behalf_of(current_task()) - - async def acquire_on_behalf_of(self, borrower: object) -> None: - await AsyncIOBackend.checkpoint_if_cancelled() - try: - self.acquire_on_behalf_of_nowait(borrower) - except WouldBlock: - event = asyncio.Event() - self._wait_queue[borrower] = event - try: - await event.wait() - except BaseException: - self._wait_queue.pop(borrower, None) - if event.is_set(): - self._notify_next_waiter() - - raise - - self._borrowers.add(borrower) - else: - try: - await AsyncIOBackend.cancel_shielded_checkpoint() - except BaseException: - self.release() - raise - - def release(self) -> None: - self.release_on_behalf_of(current_task()) - - def release_on_behalf_of(self, borrower: object) -> None: - try: - self._borrowers.remove(borrower) - except KeyError: - raise RuntimeError( - "this borrower isn't holding any of this CapacityLimiter's tokens" - ) from None - - self._notify_next_waiter() - - def statistics(self) -> CapacityLimiterStatistics: - return CapacityLimiterStatistics( - self.borrowed_tokens, - self.total_tokens, - tuple(self._borrowers), - len(self._wait_queue), - ) - - -_default_thread_limiter: RunVar[CapacityLimiter] = RunVar("_default_thread_limiter") - - -# -# Operating system signals -# - - -class _SignalReceiver: - def __init__(self, signals: tuple[Signals, ...]): - self._signals = signals - self._loop = get_running_loop() - self._signal_queue: deque[Signals] = deque() - self._future: asyncio.Future = asyncio.Future() - self._handled_signals: set[Signals] = set() - - def _deliver(self, signum: Signals) -> None: - self._signal_queue.append(signum) - if not self._future.done(): - self._future.set_result(None) - - def __enter__(self) -> _SignalReceiver: - for sig in set(self._signals): - self._loop.add_signal_handler(sig, self._deliver, sig) - self._handled_signals.add(sig) - - return self - - def __exit__( - self, - exc_type: type[BaseException] | None, - exc_val: BaseException | None, - exc_tb: TracebackType | None, - ) -> None: - for sig in self._handled_signals: - self._loop.remove_signal_handler(sig) - - def __aiter__(self) -> _SignalReceiver: - return self - - async def __anext__(self) -> Signals: - await AsyncIOBackend.checkpoint() - if not self._signal_queue: - self._future = asyncio.Future() - await self._future - - return self._signal_queue.popleft() - - -# -# Testing and debugging -# - - -class AsyncIOTaskInfo(TaskInfo): - def __init__(self, task: asyncio.Task): - task_state = _task_states.get(task) - if task_state is None: - parent_id = None - else: - parent_id = task_state.parent_id - - coro = task.get_coro() - assert coro is not None, "created TaskInfo from a completed Task" - super().__init__(id(task), parent_id, task.get_name(), coro) - self._task = weakref.ref(task) - - def has_pending_cancellation(self) -> bool: - if not (task := self._task()): - # If the task isn't around anymore, it won't have a pending cancellation - return False - - if task._must_cancel: # type: ignore[attr-defined] - return True - elif ( - isinstance(task._fut_waiter, asyncio.Future) # type: ignore[attr-defined] - and task._fut_waiter.cancelled() # type: ignore[attr-defined] - ): - return True - - if task_state := _task_states.get(task): - if cancel_scope := task_state.cancel_scope: - return cancel_scope._effectively_cancelled - - return False - - -class TestRunner(abc.TestRunner): - _send_stream: MemoryObjectSendStream[tuple[Awaitable[Any], asyncio.Future[Any]]] - - def __init__( - self, - *, - debug: bool | None = None, - use_uvloop: bool = False, - loop_factory: Callable[[], AbstractEventLoop] | None = None, - ) -> None: - if use_uvloop and loop_factory is None: - if sys.platform != "win32": - import uvloop - - loop_factory = uvloop.new_event_loop - else: - import winloop - - loop_factory = winloop.new_event_loop - - self._runner = Runner(debug=debug, loop_factory=loop_factory) - self._exceptions: list[BaseException] = [] - self._runner_task: asyncio.Task | None = None - - def __enter__(self) -> TestRunner: - self._runner.__enter__() - self.get_loop().set_exception_handler(self._exception_handler) - return self - - def __exit__( - self, - exc_type: type[BaseException] | None, - exc_val: BaseException | None, - exc_tb: TracebackType | None, - ) -> None: - self._runner.__exit__(exc_type, exc_val, exc_tb) - - def get_loop(self) -> AbstractEventLoop: - return self._runner.get_loop() - - def _exception_handler( - self, loop: asyncio.AbstractEventLoop, context: dict[str, Any] - ) -> None: - if isinstance(context.get("exception"), Exception): - self._exceptions.append(context["exception"]) - else: - loop.default_exception_handler(context) - - def _raise_async_exceptions(self) -> None: - # Re-raise any exceptions raised in asynchronous callbacks - if self._exceptions: - exceptions, self._exceptions = self._exceptions, [] - if len(exceptions) == 1: - raise exceptions[0] - elif exceptions: - raise BaseExceptionGroup( - "Multiple exceptions occurred in asynchronous callbacks", exceptions - ) - - async def _run_tests_and_fixtures( - self, - receive_stream: MemoryObjectReceiveStream[ - tuple[Awaitable[T_Retval], asyncio.Future[T_Retval]] - ], - ) -> None: - from _pytest.outcomes import OutcomeException - - with receive_stream, self._send_stream: - async for coro, future in receive_stream: - try: - retval = await coro - except CancelledError as exc: - if not future.cancelled(): - future.cancel(*exc.args) - - raise - except BaseException as exc: - if not future.cancelled(): - future.set_exception(exc) - - if not isinstance(exc, (Exception, OutcomeException)): - raise - else: - if not future.cancelled(): - future.set_result(retval) - - async def _call_in_runner_task( - self, - func: Callable[P, Awaitable[T_Retval]], - /, - *args: P.args, - **kwargs: P.kwargs, - ) -> T_Retval: - if not self._runner_task: - self._send_stream, receive_stream = create_memory_object_stream[ - tuple[Awaitable[Any], asyncio.Future] - ](1) - self._runner_task = self.get_loop().create_task( - self._run_tests_and_fixtures(receive_stream) - ) - - coro = func(*args, **kwargs) - future: asyncio.Future[T_Retval] = self.get_loop().create_future() - self._send_stream.send_nowait((coro, future)) - return await future - - def run_asyncgen_fixture( - self, - fixture_func: Callable[..., AsyncGenerator[T_Retval, Any]], - kwargs: dict[str, Any], - ) -> Iterable[T_Retval]: - asyncgen = fixture_func(**kwargs) - fixturevalue: T_Retval = self.get_loop().run_until_complete( - self._call_in_runner_task(asyncgen.asend, None) - ) - self._raise_async_exceptions() - - yield fixturevalue - - try: - self.get_loop().run_until_complete( - self._call_in_runner_task(asyncgen.asend, None) - ) - except StopAsyncIteration: - self._raise_async_exceptions() - else: - self.get_loop().run_until_complete(asyncgen.aclose()) - raise RuntimeError("Async generator fixture did not stop") - - def run_fixture( - self, - fixture_func: Callable[..., Coroutine[Any, Any, T_Retval]], - kwargs: dict[str, Any], - ) -> T_Retval: - retval = self.get_loop().run_until_complete( - self._call_in_runner_task(fixture_func, **kwargs) - ) - self._raise_async_exceptions() - return retval - - def run_test( - self, test_func: Callable[..., Coroutine[Any, Any, Any]], kwargs: dict[str, Any] - ) -> None: - try: - self.get_loop().run_until_complete( - self._call_in_runner_task(test_func, **kwargs) - ) - except Exception as exc: - self._exceptions.append(exc) - - self._raise_async_exceptions() - - -class AsyncIOBackend(AsyncBackend): - @classmethod - def run( - cls, - func: Callable[[Unpack[PosArgsT]], Awaitable[T_Retval]], - args: tuple[Unpack[PosArgsT]], - kwargs: dict[str, Any], - options: dict[str, Any], - ) -> T_Retval: - @wraps(func) - async def wrapper() -> T_Retval: - task = cast(asyncio.Task, current_task()) - task.set_name(get_callable_name(func)) - _task_states[task] = TaskState(None, None) - - try: - return await func(*args) - finally: - del _task_states[task] - - debug = options.get("debug", None) - loop_factory = options.get("loop_factory", None) - if loop_factory is None and options.get("use_uvloop", False): - if sys.platform != "win32": - import uvloop - - loop_factory = uvloop.new_event_loop - else: - import winloop - - loop_factory = winloop.new_event_loop - - with Runner(debug=debug, loop_factory=loop_factory) as runner: - return runner.run(wrapper()) - - @classmethod - def current_token(cls) -> object: - return get_running_loop() - - @classmethod - def current_time(cls) -> float: - return get_running_loop().time() - - @classmethod - def cancelled_exception_class(cls) -> type[BaseException]: - return CancelledError - - @classmethod - async def checkpoint(cls) -> None: - await sleep(0) - - @classmethod - async def checkpoint_if_cancelled(cls) -> None: - task = current_task() - if task is None: - return - - try: - cancel_scope = _task_states[task].cancel_scope - except KeyError: - return - - while cancel_scope: - if cancel_scope.cancel_called: - await sleep(0) - elif cancel_scope.shield: - break - else: - cancel_scope = cancel_scope._parent_scope - - @classmethod - async def cancel_shielded_checkpoint(cls) -> None: - with CancelScope(shield=True): - await sleep(0) - - @classmethod - async def sleep(cls, delay: float) -> None: - await sleep(delay) - - @classmethod - def create_cancel_scope( - cls, *, deadline: float = math.inf, shield: bool = False - ) -> CancelScope: - return CancelScope(deadline=deadline, shield=shield) - - @classmethod - def current_effective_deadline(cls) -> float: - if (task := current_task()) is None: - return math.inf - - try: - cancel_scope = _task_states[task].cancel_scope - except KeyError: - return math.inf - - deadline = math.inf - while cancel_scope: - deadline = min(deadline, cancel_scope.deadline) - if cancel_scope._cancel_called: - deadline = -math.inf - break - elif cancel_scope.shield: - break - else: - cancel_scope = cancel_scope._parent_scope - - return deadline - - @classmethod - def create_task_group(cls) -> abc.TaskGroup: - return TaskGroup() - - @classmethod - def create_event(cls) -> abc.Event: - return Event() - - @classmethod - def create_lock(cls, *, fast_acquire: bool) -> abc.Lock: - return Lock(fast_acquire=fast_acquire) - - @classmethod - def create_semaphore( - cls, - initial_value: int, - *, - max_value: int | None = None, - fast_acquire: bool = False, - ) -> abc.Semaphore: - return Semaphore(initial_value, max_value=max_value, fast_acquire=fast_acquire) - - @classmethod - def create_capacity_limiter(cls, total_tokens: float) -> abc.CapacityLimiter: - return CapacityLimiter(total_tokens) - - @classmethod - async def run_sync_in_worker_thread( # type: ignore[return] - cls, - func: Callable[[Unpack[PosArgsT]], T_Retval], - args: tuple[Unpack[PosArgsT]], - abandon_on_cancel: bool = False, - limiter: abc.CapacityLimiter | None = None, - ) -> T_Retval: - await cls.checkpoint() - - # If this is the first run in this event loop thread, set up the necessary - # variables - try: - idle_workers = _threadpool_idle_workers.get() - workers = _threadpool_workers.get() - except LookupError: - idle_workers = deque() - workers = set() - _threadpool_idle_workers.set(idle_workers) - _threadpool_workers.set(workers) - - async with limiter or cls.current_default_thread_limiter(): - with CancelScope(shield=not abandon_on_cancel) as scope: - future = asyncio.Future[T_Retval]() - root_task = find_root_task() - if not idle_workers: - worker = WorkerThread(root_task, workers, idle_workers) - worker.start() - workers.add(worker) - root_task.add_done_callback( - worker.stop, context=contextvars.Context() - ) - else: - worker = idle_workers.pop() - - # Prune any other workers that have been idle for MAX_IDLE_TIME - # seconds or longer - now = cls.current_time() - while idle_workers: - if ( - now - idle_workers[0].idle_since - < WorkerThread.MAX_IDLE_TIME - ): - break - - expired_worker = idle_workers.popleft() - expired_worker.root_task.remove_done_callback( - expired_worker.stop - ) - expired_worker.stop() - - context = copy_context() - context.run(set_current_async_library, None) - if abandon_on_cancel or scope._parent_scope is None: - worker_scope = scope - else: - worker_scope = scope._parent_scope - - worker.queue.put_nowait((context, func, args, future, worker_scope)) - return await future - - @classmethod - def check_cancelled(cls) -> None: - scope: CancelScope | None = threadlocals.current_cancel_scope - while scope is not None: - if scope.cancel_called: - raise CancelledError(f"Cancelled by cancel scope {id(scope):x}") - - if scope.shield: - return - - scope = scope._parent_scope - - @classmethod - def run_async_from_thread( - cls, - func: Callable[[Unpack[PosArgsT]], Awaitable[T_Retval]], - args: tuple[Unpack[PosArgsT]], - token: object, - ) -> T_Retval: - async def task_wrapper() -> T_Retval: - __tracebackhide__ = True - if scope is not None: - task = cast(asyncio.Task, current_task()) - _task_states[task] = TaskState(None, scope) - scope._tasks.add(task) - try: - return await func(*args) - except CancelledError as exc: - raise concurrent.futures.CancelledError(str(exc)) from None - finally: - if scope is not None: - scope._tasks.discard(task) - - loop = cast( - "AbstractEventLoop", token or threadlocals.current_token.native_token - ) - if loop.is_closed(): - raise RunFinishedError - - context = copy_context() - context.run(set_current_async_library, "asyncio") - scope = getattr(threadlocals, "current_cancel_scope", None) - f: concurrent.futures.Future[T_Retval] = context.run( - asyncio.run_coroutine_threadsafe, task_wrapper(), loop=loop - ) - return f.result() - - @classmethod - def run_sync_from_thread( - cls, - func: Callable[[Unpack[PosArgsT]], T_Retval], - args: tuple[Unpack[PosArgsT]], - token: object, - ) -> T_Retval: - @wraps(func) - def wrapper() -> None: - try: - set_current_async_library("asyncio") - f.set_result(func(*args)) - except BaseException as exc: - f.set_exception(exc) - if not isinstance(exc, Exception): - raise - - loop = cast( - "AbstractEventLoop", token or threadlocals.current_token.native_token - ) - if loop.is_closed(): - raise RunFinishedError - - f: concurrent.futures.Future[T_Retval] = Future() - loop.call_soon_threadsafe(wrapper) - return f.result() - - @classmethod - async def open_process( - cls, - command: StrOrBytesPath | Sequence[StrOrBytesPath], - *, - stdin: int | IO[Any] | None, - stdout: int | IO[Any] | None, - stderr: int | IO[Any] | None, - **kwargs: Any, - ) -> Process: - await cls.checkpoint() - if isinstance(command, PathLike): - command = os.fspath(command) - - if isinstance(command, (str, bytes)): - process = await asyncio.create_subprocess_shell( - command, - stdin=stdin, - stdout=stdout, - stderr=stderr, - **kwargs, - ) - else: - process = await asyncio.create_subprocess_exec( - *command, - stdin=stdin, - stdout=stdout, - stderr=stderr, - **kwargs, - ) - - stdin_stream = StreamWriterWrapper(process.stdin) if process.stdin else None - stdout_stream = StreamReaderWrapper(process.stdout) if process.stdout else None - stderr_stream = StreamReaderWrapper(process.stderr) if process.stderr else None - return Process(process, stdin_stream, stdout_stream, stderr_stream) - - @classmethod - def setup_process_pool_exit_at_shutdown(cls, workers: set[abc.Process]) -> None: - create_task( - _shutdown_process_pool_on_exit(workers), - name="AnyIO process pool shutdown task", - ) - find_root_task().add_done_callback( - partial(_forcibly_shutdown_process_pool_on_exit, workers) # type:ignore[arg-type] - ) - - @classmethod - async def connect_tcp( - cls, host: str, port: int, local_address: IPSockAddrType | None = None - ) -> abc.SocketStream: - transport, protocol = cast( - tuple[asyncio.Transport, StreamProtocol], - await get_running_loop().create_connection( - StreamProtocol, host, port, local_addr=local_address - ), - ) - transport.pause_reading() - return SocketStream(transport, protocol) - - @classmethod - async def connect_unix(cls, path: str | bytes) -> abc.UNIXSocketStream: - await cls.checkpoint() - loop = get_running_loop() - raw_socket = socket.socket(socket.AF_UNIX) - raw_socket.setblocking(False) - while True: - try: - raw_socket.connect(path) - except BlockingIOError: - f: asyncio.Future = asyncio.Future() - loop.add_writer(raw_socket, f.set_result, None) - f.add_done_callback(lambda _: loop.remove_writer(raw_socket)) - await f - except BaseException: - raw_socket.close() - raise - else: - return UNIXSocketStream(raw_socket) - - @classmethod - def create_tcp_listener(cls, sock: socket.socket) -> SocketListener: - return TCPSocketListener(sock) - - @classmethod - def create_unix_listener(cls, sock: socket.socket) -> SocketListener: - return UNIXSocketListener(sock) - - @classmethod - async def create_udp_socket( - cls, - family: AddressFamily, - local_address: IPSockAddrType | None, - remote_address: IPSockAddrType | None, - reuse_port: bool, - ) -> UDPSocket | ConnectedUDPSocket: - transport, protocol = await get_running_loop().create_datagram_endpoint( - DatagramProtocol, - local_addr=local_address, - remote_addr=remote_address, - family=family, - reuse_port=reuse_port, - ) - if protocol.exception: - transport.close() - raise protocol.exception - - if not remote_address: - return UDPSocket(transport, protocol) - else: - return ConnectedUDPSocket(transport, protocol) - - @classmethod - async def create_unix_datagram_socket( # type: ignore[override] - cls, raw_socket: socket.socket, remote_path: str | bytes | None - ) -> abc.UNIXDatagramSocket | abc.ConnectedUNIXDatagramSocket: - await cls.checkpoint() - loop = get_running_loop() - - if remote_path: - while True: - try: - raw_socket.connect(remote_path) - except BlockingIOError: - f: asyncio.Future = asyncio.Future() - loop.add_writer(raw_socket, f.set_result, None) - f.add_done_callback(lambda _: loop.remove_writer(raw_socket)) - await f - except BaseException: - raw_socket.close() - raise - else: - return ConnectedUNIXDatagramSocket(raw_socket) - else: - return UNIXDatagramSocket(raw_socket) - - @classmethod - async def getaddrinfo( - cls, - host: bytes | str | None, - port: str | int | None, - *, - family: int | AddressFamily = 0, - type: int | SocketKind = 0, - proto: int = 0, - flags: int = 0, - ) -> Sequence[ - tuple[ - AddressFamily, - SocketKind, - int, - str, - tuple[str, int] | tuple[str, int, int, int] | tuple[int, bytes], - ] - ]: - return await get_running_loop().getaddrinfo( - host, port, family=family, type=type, proto=proto, flags=flags - ) - - @classmethod - async def getnameinfo( - cls, sockaddr: IPSockAddrType, flags: int = 0 - ) -> tuple[str, str]: - return await get_running_loop().getnameinfo(sockaddr, flags) - - @classmethod - async def wait_readable(cls, obj: FileDescriptorLike) -> None: - try: - read_events = _read_events.get() - except LookupError: - read_events = {} - _read_events.set(read_events) - - fd = obj if isinstance(obj, int) else obj.fileno() - if read_events.get(fd): - raise BusyResourceError("reading from") - - loop = get_running_loop() - fut: asyncio.Future[bool] = loop.create_future() - - def cb() -> None: - try: - del read_events[fd] - except KeyError: - pass - else: - remove_reader(fd) - - try: - fut.set_result(True) - except asyncio.InvalidStateError: - pass - - try: - loop.add_reader(fd, cb) - except NotImplementedError: - from anyio._core._asyncio_selector_thread import get_selector - - selector = get_selector() - selector.add_reader(fd, cb) - remove_reader = selector.remove_reader - else: - remove_reader = loop.remove_reader - - read_events[fd] = fut - try: - success = await fut - finally: - try: - del read_events[fd] - except KeyError: - pass - else: - remove_reader(fd) - - if not success: - raise ClosedResourceError - - @classmethod - async def wait_writable(cls, obj: FileDescriptorLike) -> None: - try: - write_events = _write_events.get() - except LookupError: - write_events = {} - _write_events.set(write_events) - - fd = obj if isinstance(obj, int) else obj.fileno() - if write_events.get(fd): - raise BusyResourceError("writing to") - - loop = get_running_loop() - fut: asyncio.Future[bool] = loop.create_future() - - def cb() -> None: - try: - del write_events[fd] - except KeyError: - pass - else: - remove_writer(fd) - - try: - fut.set_result(True) - except asyncio.InvalidStateError: - pass - - try: - loop.add_writer(fd, cb) - except NotImplementedError: - from anyio._core._asyncio_selector_thread import get_selector - - selector = get_selector() - selector.add_writer(fd, cb) - remove_writer = selector.remove_writer - else: - remove_writer = loop.remove_writer - - write_events[fd] = fut - try: - success = await fut - finally: - try: - del write_events[fd] - except KeyError: - pass - else: - remove_writer(fd) - - if not success: - raise ClosedResourceError - - @classmethod - def notify_closing(cls, obj: FileDescriptorLike) -> None: - fd = obj if isinstance(obj, int) else obj.fileno() - loop = get_running_loop() - - try: - write_events = _write_events.get() - except LookupError: - pass - else: - try: - fut = write_events.pop(fd) - except KeyError: - pass - else: - try: - fut.set_result(False) - except asyncio.InvalidStateError: - pass - - try: - loop.remove_writer(fd) - except NotImplementedError: - from anyio._core._asyncio_selector_thread import get_selector - - get_selector().remove_writer(fd) - - try: - read_events = _read_events.get() - except LookupError: - pass - else: - try: - fut = read_events.pop(fd) - except KeyError: - pass - else: - try: - fut.set_result(False) - except asyncio.InvalidStateError: - pass - - try: - loop.remove_reader(fd) - except NotImplementedError: - from anyio._core._asyncio_selector_thread import get_selector - - get_selector().remove_reader(fd) - - @classmethod - async def wrap_listener_socket(cls, sock: socket.socket) -> SocketListener: - return TCPSocketListener(sock) - - @classmethod - async def wrap_stream_socket(cls, sock: socket.socket) -> SocketStream: - transport, protocol = await get_running_loop().create_connection( - StreamProtocol, sock=sock - ) - return SocketStream(transport, protocol) - - @classmethod - async def wrap_unix_stream_socket(cls, sock: socket.socket) -> UNIXSocketStream: - return UNIXSocketStream(sock) - - @classmethod - async def wrap_udp_socket(cls, sock: socket.socket) -> UDPSocket: - transport, protocol = await get_running_loop().create_datagram_endpoint( - DatagramProtocol, sock=sock - ) - return UDPSocket(transport, protocol) - - @classmethod - async def wrap_connected_udp_socket(cls, sock: socket.socket) -> ConnectedUDPSocket: - transport, protocol = await get_running_loop().create_datagram_endpoint( - DatagramProtocol, sock=sock - ) - return ConnectedUDPSocket(transport, protocol) - - @classmethod - async def wrap_unix_datagram_socket(cls, sock: socket.socket) -> UNIXDatagramSocket: - return UNIXDatagramSocket(sock) - - @classmethod - async def wrap_connected_unix_datagram_socket( - cls, sock: socket.socket - ) -> ConnectedUNIXDatagramSocket: - return ConnectedUNIXDatagramSocket(sock) - - @classmethod - def current_default_thread_limiter(cls) -> CapacityLimiter: - try: - return _default_thread_limiter.get() - except LookupError: - limiter = CapacityLimiter(40) - _default_thread_limiter.set(limiter) - return limiter - - @classmethod - def open_signal_receiver( - cls, *signals: Signals - ) -> AbstractContextManager[AsyncIterator[Signals]]: - return _SignalReceiver(signals) - - @classmethod - def get_current_task(cls) -> TaskInfo: - return AsyncIOTaskInfo(current_task()) # type: ignore[arg-type] - - @classmethod - def get_running_tasks(cls) -> Sequence[TaskInfo]: - return [AsyncIOTaskInfo(task) for task in all_tasks() if not task.done()] - - @classmethod - async def wait_all_tasks_blocked(cls) -> None: - await cls.checkpoint() - this_task = current_task() - while True: - for task in all_tasks(): - if task is this_task: - continue - - waiter = task._fut_waiter # type: ignore[attr-defined] - if waiter is None or waiter.done(): - await sleep(0.1) - break - else: - return - - @classmethod - def create_test_runner(cls, options: dict[str, Any]) -> TestRunner: - return TestRunner(**options) - - -backend_class = AsyncIOBackend diff --git a/.venv/lib/python3.12/site-packages/anyio/_backends/_trio.py b/.venv/lib/python3.12/site-packages/anyio/_backends/_trio.py deleted file mode 100644 index b85a10a..0000000 --- a/.venv/lib/python3.12/site-packages/anyio/_backends/_trio.py +++ /dev/null @@ -1,1343 +0,0 @@ -from __future__ import annotations - -import array -import math -import os -import socket -import sys -import types -import weakref -from collections.abc import ( - AsyncGenerator, - AsyncIterator, - Awaitable, - Callable, - Collection, - Coroutine, - Iterable, - Sequence, -) -from contextlib import AbstractContextManager -from dataclasses import dataclass -from io import IOBase -from os import PathLike -from signal import Signals -from socket import AddressFamily, SocketKind -from types import TracebackType -from typing import ( - IO, - TYPE_CHECKING, - Any, - Generic, - NoReturn, - ParamSpec, - TypeVar, - cast, - overload, -) - -import trio.from_thread -import trio.lowlevel -from outcome import Error, Outcome, Value -from trio.lowlevel import ( - current_root_task, - current_task, - notify_closing, - wait_readable, - wait_writable, -) -from trio.socket import SocketType as TrioSocketType -from trio.to_thread import run_sync - -from .. import ( - CapacityLimiterStatistics, - EventStatistics, - LockStatistics, - RunFinishedError, - TaskInfo, - WouldBlock, - abc, -) -from .._core._eventloop import claim_worker_thread -from .._core._exceptions import ( - BrokenResourceError, - BusyResourceError, - ClosedResourceError, - EndOfStream, -) -from .._core._sockets import convert_ipv6_sockaddr -from .._core._streams import create_memory_object_stream -from .._core._synchronization import ( - CapacityLimiter as BaseCapacityLimiter, -) -from .._core._synchronization import Event as BaseEvent -from .._core._synchronization import Lock as BaseLock -from .._core._synchronization import ( - ResourceGuard, - SemaphoreStatistics, -) -from .._core._synchronization import Semaphore as BaseSemaphore -from .._core._tasks import CancelScope as BaseCancelScope -from ..abc import IPSockAddrType, UDPPacketType, UNIXDatagramPacketType -from ..abc._eventloop import AsyncBackend, StrOrBytesPath -from ..streams.memory import MemoryObjectSendStream - -if TYPE_CHECKING: - from _typeshed import FileDescriptorLike - -if sys.version_info >= (3, 11): - from typing import TypeVarTuple, Unpack -else: - from exceptiongroup import BaseExceptionGroup - from typing_extensions import TypeVarTuple, Unpack - -T = TypeVar("T") -T_Retval = TypeVar("T_Retval") -T_SockAddr = TypeVar("T_SockAddr", str, IPSockAddrType) -PosArgsT = TypeVarTuple("PosArgsT") -P = ParamSpec("P") - - -# -# Event loop -# - -RunVar = trio.lowlevel.RunVar - - -# -# Timeouts and cancellation -# - - -class CancelScope(BaseCancelScope): - def __new__( - cls, original: trio.CancelScope | None = None, **kwargs: object - ) -> CancelScope: - return object.__new__(cls) - - def __init__(self, original: trio.CancelScope | None = None, **kwargs: Any) -> None: - self.__original = original or trio.CancelScope(**kwargs) - - def __enter__(self) -> CancelScope: - self.__original.__enter__() - return self - - def __exit__( - self, - exc_type: type[BaseException] | None, - exc_val: BaseException | None, - exc_tb: TracebackType | None, - ) -> bool: - return self.__original.__exit__(exc_type, exc_val, exc_tb) - - def cancel(self, reason: str | None = None) -> None: - self.__original.cancel(reason) - - @property - def deadline(self) -> float: - return self.__original.deadline - - @deadline.setter - def deadline(self, value: float) -> None: - self.__original.deadline = value - - @property - def cancel_called(self) -> bool: - return self.__original.cancel_called - - @property - def cancelled_caught(self) -> bool: - return self.__original.cancelled_caught - - @property - def shield(self) -> bool: - return self.__original.shield - - @shield.setter - def shield(self, value: bool) -> None: - self.__original.shield = value - - -# -# Task groups -# - - -class TaskGroup(abc.TaskGroup): - def __init__(self) -> None: - self._active = False - self._nursery_manager = trio.open_nursery(strict_exception_groups=True) - self.cancel_scope = None # type: ignore[assignment] - - async def __aenter__(self) -> TaskGroup: - self._active = True - self._nursery = await self._nursery_manager.__aenter__() - self.cancel_scope = CancelScope(self._nursery.cancel_scope) - return self - - async def __aexit__( - self, - exc_type: type[BaseException] | None, - exc_val: BaseException | None, - exc_tb: TracebackType | None, - ) -> bool: - try: - # trio.Nursery.__exit__ returns bool; .open_nursery has wrong type - return await self._nursery_manager.__aexit__(exc_type, exc_val, exc_tb) # type: ignore[return-value] - except BaseExceptionGroup as exc: - if not exc.split(trio.Cancelled)[1]: - raise trio.Cancelled._create() from exc - - raise - finally: - del exc_val, exc_tb - self._active = False - - def start_soon( - self, - func: Callable[[Unpack[PosArgsT]], Awaitable[Any]], - *args: Unpack[PosArgsT], - name: object = None, - ) -> None: - if not self._active: - raise RuntimeError( - "This task group is not active; no new tasks can be started." - ) - - self._nursery.start_soon(func, *args, name=name) - - async def start( - self, func: Callable[..., Awaitable[Any]], *args: object, name: object = None - ) -> Any: - if not self._active: - raise RuntimeError( - "This task group is not active; no new tasks can be started." - ) - - return await self._nursery.start(func, *args, name=name) - - -# -# Subprocesses -# - - -@dataclass(eq=False) -class ReceiveStreamWrapper(abc.ByteReceiveStream): - _stream: trio.abc.ReceiveStream - - async def receive(self, max_bytes: int | None = None) -> bytes: - try: - data = await self._stream.receive_some(max_bytes) - except trio.ClosedResourceError as exc: - raise ClosedResourceError from exc.__cause__ - except trio.BrokenResourceError as exc: - raise BrokenResourceError from exc.__cause__ - - if data: - return bytes(data) - else: - raise EndOfStream - - async def aclose(self) -> None: - await self._stream.aclose() - - -@dataclass(eq=False) -class SendStreamWrapper(abc.ByteSendStream): - _stream: trio.abc.SendStream - - async def send(self, item: bytes) -> None: - try: - await self._stream.send_all(item) - except trio.ClosedResourceError as exc: - raise ClosedResourceError from exc.__cause__ - except trio.BrokenResourceError as exc: - raise BrokenResourceError from exc.__cause__ - - async def aclose(self) -> None: - await self._stream.aclose() - - -@dataclass(eq=False) -class Process(abc.Process): - _process: trio.Process - _stdin: abc.ByteSendStream | None - _stdout: abc.ByteReceiveStream | None - _stderr: abc.ByteReceiveStream | None - - async def aclose(self) -> None: - with CancelScope(shield=True): - if self._stdin: - await self._stdin.aclose() - if self._stdout: - await self._stdout.aclose() - if self._stderr: - await self._stderr.aclose() - - try: - await self.wait() - except BaseException: - self.kill() - with CancelScope(shield=True): - await self.wait() - raise - - async def wait(self) -> int: - return await self._process.wait() - - def terminate(self) -> None: - self._process.terminate() - - def kill(self) -> None: - self._process.kill() - - def send_signal(self, signal: Signals) -> None: - self._process.send_signal(signal) - - @property - def pid(self) -> int: - return self._process.pid - - @property - def returncode(self) -> int | None: - return self._process.returncode - - @property - def stdin(self) -> abc.ByteSendStream | None: - return self._stdin - - @property - def stdout(self) -> abc.ByteReceiveStream | None: - return self._stdout - - @property - def stderr(self) -> abc.ByteReceiveStream | None: - return self._stderr - - -class _ProcessPoolShutdownInstrument(trio.abc.Instrument): - def after_run(self) -> None: - super().after_run() - - -current_default_worker_process_limiter: trio.lowlevel.RunVar = RunVar( - "current_default_worker_process_limiter" -) - - -async def _shutdown_process_pool(workers: set[abc.Process]) -> None: - try: - await trio.sleep(math.inf) - except trio.Cancelled: - for process in workers: - if process.returncode is None: - process.kill() - - with CancelScope(shield=True): - for process in workers: - await process.aclose() - - -# -# Sockets and networking -# - - -class _TrioSocketMixin(Generic[T_SockAddr]): - def __init__(self, trio_socket: TrioSocketType) -> None: - self._trio_socket = trio_socket - self._closed = False - - def _check_closed(self) -> None: - if self._closed: - raise ClosedResourceError - if self._trio_socket.fileno() < 0: - raise BrokenResourceError - - @property - def _raw_socket(self) -> socket.socket: - return self._trio_socket._sock # type: ignore[attr-defined] - - async def aclose(self) -> None: - if self._trio_socket.fileno() >= 0: - self._closed = True - self._trio_socket.close() - - def _convert_socket_error(self, exc: BaseException) -> NoReturn: - if isinstance(exc, trio.ClosedResourceError): - raise ClosedResourceError from exc - elif self._trio_socket.fileno() < 0 and self._closed: - raise ClosedResourceError from None - elif isinstance(exc, OSError): - raise BrokenResourceError from exc - else: - raise exc - - -class SocketStream(_TrioSocketMixin, abc.SocketStream): - def __init__(self, trio_socket: TrioSocketType) -> None: - super().__init__(trio_socket) - self._receive_guard = ResourceGuard("reading from") - self._send_guard = ResourceGuard("writing to") - - async def receive(self, max_bytes: int = 65536) -> bytes: - with self._receive_guard: - try: - data = await self._trio_socket.recv(max_bytes) - except BaseException as exc: - self._convert_socket_error(exc) - - if data: - return data - else: - raise EndOfStream - - async def send(self, item: bytes) -> None: - with self._send_guard: - view = memoryview(item) - while view: - try: - bytes_sent = await self._trio_socket.send(view) - except BaseException as exc: - self._convert_socket_error(exc) - - view = view[bytes_sent:] - - async def send_eof(self) -> None: - self._trio_socket.shutdown(socket.SHUT_WR) - - -class UNIXSocketStream(SocketStream, abc.UNIXSocketStream): - async def receive_fds(self, msglen: int, maxfds: int) -> tuple[bytes, list[int]]: - if not isinstance(msglen, int) or msglen < 0: - raise ValueError("msglen must be a non-negative integer") - if not isinstance(maxfds, int) or maxfds < 1: - raise ValueError("maxfds must be a positive integer") - - fds = array.array("i") - await trio.lowlevel.checkpoint() - with self._receive_guard: - while True: - try: - message, ancdata, flags, addr = await self._trio_socket.recvmsg( - msglen, socket.CMSG_LEN(maxfds * fds.itemsize) - ) - except BaseException as exc: - self._convert_socket_error(exc) - else: - if not message and not ancdata: - raise EndOfStream - - break - - for cmsg_level, cmsg_type, cmsg_data in ancdata: - if cmsg_level != socket.SOL_SOCKET or cmsg_type != socket.SCM_RIGHTS: - raise RuntimeError( - f"Received unexpected ancillary data; message = {message!r}, " - f"cmsg_level = {cmsg_level}, cmsg_type = {cmsg_type}" - ) - - fds.frombytes(cmsg_data[: len(cmsg_data) - (len(cmsg_data) % fds.itemsize)]) - - return message, list(fds) - - async def send_fds(self, message: bytes, fds: Collection[int | IOBase]) -> None: - if not message: - raise ValueError("message must not be empty") - if not fds: - raise ValueError("fds must not be empty") - - filenos: list[int] = [] - for fd in fds: - if isinstance(fd, int): - filenos.append(fd) - elif isinstance(fd, IOBase): - filenos.append(fd.fileno()) - - fdarray = array.array("i", filenos) - await trio.lowlevel.checkpoint() - with self._send_guard: - while True: - try: - await self._trio_socket.sendmsg( - [message], - [ - ( - socket.SOL_SOCKET, - socket.SCM_RIGHTS, - fdarray, - ) - ], - ) - break - except BaseException as exc: - self._convert_socket_error(exc) - - -class TCPSocketListener(_TrioSocketMixin, abc.SocketListener): - def __init__(self, raw_socket: socket.socket): - super().__init__(trio.socket.from_stdlib_socket(raw_socket)) - self._accept_guard = ResourceGuard("accepting connections from") - - async def accept(self) -> SocketStream: - with self._accept_guard: - try: - trio_socket, _addr = await self._trio_socket.accept() - except BaseException as exc: - self._convert_socket_error(exc) - - trio_socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) - return SocketStream(trio_socket) - - -class UNIXSocketListener(_TrioSocketMixin, abc.SocketListener): - def __init__(self, raw_socket: socket.socket): - super().__init__(trio.socket.from_stdlib_socket(raw_socket)) - self._accept_guard = ResourceGuard("accepting connections from") - - async def accept(self) -> UNIXSocketStream: - with self._accept_guard: - try: - trio_socket, _addr = await self._trio_socket.accept() - except BaseException as exc: - self._convert_socket_error(exc) - - return UNIXSocketStream(trio_socket) - - -class UDPSocket(_TrioSocketMixin[IPSockAddrType], abc.UDPSocket): - def __init__(self, trio_socket: TrioSocketType) -> None: - super().__init__(trio_socket) - self._receive_guard = ResourceGuard("reading from") - self._send_guard = ResourceGuard("writing to") - - async def receive(self) -> tuple[bytes, IPSockAddrType]: - with self._receive_guard: - try: - data, addr = await self._trio_socket.recvfrom(65536) - return data, convert_ipv6_sockaddr(addr) - except BaseException as exc: - self._convert_socket_error(exc) - - async def send(self, item: UDPPacketType) -> None: - with self._send_guard: - try: - await self._trio_socket.sendto(*item) - except BaseException as exc: - self._convert_socket_error(exc) - - -class ConnectedUDPSocket(_TrioSocketMixin[IPSockAddrType], abc.ConnectedUDPSocket): - def __init__(self, trio_socket: TrioSocketType) -> None: - super().__init__(trio_socket) - self._receive_guard = ResourceGuard("reading from") - self._send_guard = ResourceGuard("writing to") - - async def receive(self) -> bytes: - with self._receive_guard: - try: - return await self._trio_socket.recv(65536) - except BaseException as exc: - self._convert_socket_error(exc) - - async def send(self, item: bytes) -> None: - with self._send_guard: - try: - await self._trio_socket.send(item) - except BaseException as exc: - self._convert_socket_error(exc) - - -class UNIXDatagramSocket(_TrioSocketMixin[str], abc.UNIXDatagramSocket): - def __init__(self, trio_socket: TrioSocketType) -> None: - super().__init__(trio_socket) - self._receive_guard = ResourceGuard("reading from") - self._send_guard = ResourceGuard("writing to") - - async def receive(self) -> UNIXDatagramPacketType: - with self._receive_guard: - try: - data, addr = await self._trio_socket.recvfrom(65536) - return data, addr - except BaseException as exc: - self._convert_socket_error(exc) - - async def send(self, item: UNIXDatagramPacketType) -> None: - with self._send_guard: - try: - await self._trio_socket.sendto(*item) - except BaseException as exc: - self._convert_socket_error(exc) - - -class ConnectedUNIXDatagramSocket( - _TrioSocketMixin[str], abc.ConnectedUNIXDatagramSocket -): - def __init__(self, trio_socket: TrioSocketType) -> None: - super().__init__(trio_socket) - self._receive_guard = ResourceGuard("reading from") - self._send_guard = ResourceGuard("writing to") - - async def receive(self) -> bytes: - with self._receive_guard: - try: - return await self._trio_socket.recv(65536) - except BaseException as exc: - self._convert_socket_error(exc) - - async def send(self, item: bytes) -> None: - with self._send_guard: - try: - await self._trio_socket.send(item) - except BaseException as exc: - self._convert_socket_error(exc) - - -# -# Synchronization -# - - -class Event(BaseEvent): - def __new__(cls) -> Event: - return object.__new__(cls) - - def __init__(self) -> None: - self.__original = trio.Event() - - def is_set(self) -> bool: - return self.__original.is_set() - - async def wait(self) -> None: - return await self.__original.wait() - - def statistics(self) -> EventStatistics: - orig_statistics = self.__original.statistics() - return EventStatistics(tasks_waiting=orig_statistics.tasks_waiting) - - def set(self) -> None: - self.__original.set() - - -class Lock(BaseLock): - def __new__(cls, *, fast_acquire: bool = False) -> Lock: - return object.__new__(cls) - - def __init__(self, *, fast_acquire: bool = False) -> None: - self._fast_acquire = fast_acquire - self.__original = trio.Lock() - - @staticmethod - def _convert_runtime_error_msg(exc: RuntimeError) -> None: - if exc.args == ("attempt to re-acquire an already held Lock",): - exc.args = ("Attempted to acquire an already held Lock",) - - async def acquire(self) -> None: - if not self._fast_acquire: - try: - await self.__original.acquire() - except RuntimeError as exc: - self._convert_runtime_error_msg(exc) - raise - - return - - # This is the "fast path" where we don't let other tasks run - await trio.lowlevel.checkpoint_if_cancelled() - try: - self.__original.acquire_nowait() - except trio.WouldBlock: - await self.__original._lot.park() - except RuntimeError as exc: - self._convert_runtime_error_msg(exc) - raise - - def acquire_nowait(self) -> None: - try: - self.__original.acquire_nowait() - except trio.WouldBlock: - raise WouldBlock from None - except RuntimeError as exc: - self._convert_runtime_error_msg(exc) - raise - - def locked(self) -> bool: - return self.__original.locked() - - def release(self) -> None: - self.__original.release() - - def statistics(self) -> LockStatistics: - orig_statistics = self.__original.statistics() - owner = TrioTaskInfo(orig_statistics.owner) if orig_statistics.owner else None - return LockStatistics( - orig_statistics.locked, owner, orig_statistics.tasks_waiting - ) - - -class Semaphore(BaseSemaphore): - def __new__( - cls, - initial_value: int, - *, - max_value: int | None = None, - fast_acquire: bool = False, - ) -> Semaphore: - return object.__new__(cls) - - def __init__( - self, - initial_value: int, - *, - max_value: int | None = None, - fast_acquire: bool = False, - ) -> None: - super().__init__(initial_value, max_value=max_value, fast_acquire=fast_acquire) - self.__original = trio.Semaphore(initial_value, max_value=max_value) - - async def acquire(self) -> None: - if not self._fast_acquire: - await self.__original.acquire() - return - - # This is the "fast path" where we don't let other tasks run - await trio.lowlevel.checkpoint_if_cancelled() - try: - self.__original.acquire_nowait() - except trio.WouldBlock: - await self.__original._lot.park() - - def acquire_nowait(self) -> None: - try: - self.__original.acquire_nowait() - except trio.WouldBlock: - raise WouldBlock from None - - @property - def max_value(self) -> int | None: - return self.__original.max_value - - @property - def value(self) -> int: - return self.__original.value - - def release(self) -> None: - self.__original.release() - - def statistics(self) -> SemaphoreStatistics: - orig_statistics = self.__original.statistics() - return SemaphoreStatistics(orig_statistics.tasks_waiting) - - -class CapacityLimiter(BaseCapacityLimiter): - def __new__( - cls, - total_tokens: float | None = None, - *, - original: trio.CapacityLimiter | None = None, - ) -> CapacityLimiter: - return object.__new__(cls) - - def __init__( - self, - total_tokens: float | None = None, - *, - original: trio.CapacityLimiter | None = None, - ) -> None: - if original is not None: - self.__original = original - else: - assert total_tokens is not None - self.__original = trio.CapacityLimiter(total_tokens) - - async def __aenter__(self) -> None: - return await self.__original.__aenter__() - - async def __aexit__( - self, - exc_type: type[BaseException] | None, - exc_val: BaseException | None, - exc_tb: TracebackType | None, - ) -> None: - await self.__original.__aexit__(exc_type, exc_val, exc_tb) - - @property - def total_tokens(self) -> float: - return self.__original.total_tokens - - @total_tokens.setter - def total_tokens(self, value: float) -> None: - self.__original.total_tokens = value - - @property - def borrowed_tokens(self) -> int: - return self.__original.borrowed_tokens - - @property - def available_tokens(self) -> float: - return self.__original.available_tokens - - def acquire_nowait(self) -> None: - self.__original.acquire_nowait() - - def acquire_on_behalf_of_nowait(self, borrower: object) -> None: - self.__original.acquire_on_behalf_of_nowait(borrower) - - async def acquire(self) -> None: - await self.__original.acquire() - - async def acquire_on_behalf_of(self, borrower: object) -> None: - await self.__original.acquire_on_behalf_of(borrower) - - def release(self) -> None: - return self.__original.release() - - def release_on_behalf_of(self, borrower: object) -> None: - return self.__original.release_on_behalf_of(borrower) - - def statistics(self) -> CapacityLimiterStatistics: - orig = self.__original.statistics() - return CapacityLimiterStatistics( - borrowed_tokens=orig.borrowed_tokens, - total_tokens=orig.total_tokens, - borrowers=tuple(orig.borrowers), - tasks_waiting=orig.tasks_waiting, - ) - - -_capacity_limiter_wrapper: trio.lowlevel.RunVar = RunVar("_capacity_limiter_wrapper") - - -# -# Signal handling -# - - -class _SignalReceiver: - _iterator: AsyncIterator[int] - - def __init__(self, signals: tuple[Signals, ...]): - self._signals = signals - - def __enter__(self) -> _SignalReceiver: - self._cm = trio.open_signal_receiver(*self._signals) - self._iterator = self._cm.__enter__() - return self - - def __exit__( - self, - exc_type: type[BaseException] | None, - exc_val: BaseException | None, - exc_tb: TracebackType | None, - ) -> bool | None: - return self._cm.__exit__(exc_type, exc_val, exc_tb) - - def __aiter__(self) -> _SignalReceiver: - return self - - async def __anext__(self) -> Signals: - signum = await self._iterator.__anext__() - return Signals(signum) - - -# -# Testing and debugging -# - - -class TestRunner(abc.TestRunner): - def __init__(self, **options: Any) -> None: - from queue import Queue - - self._call_queue: Queue[Callable[[], object]] = Queue() - self._send_stream: MemoryObjectSendStream | None = None - self._options = options - - def __exit__( - self, - exc_type: type[BaseException] | None, - exc_val: BaseException | None, - exc_tb: types.TracebackType | None, - ) -> None: - if self._send_stream: - self._send_stream.close() - while self._send_stream is not None: - self._call_queue.get()() - - async def _run_tests_and_fixtures(self) -> None: - self._send_stream, receive_stream = create_memory_object_stream(1) - with receive_stream: - async for coro, outcome_holder in receive_stream: - try: - retval = await coro - except BaseException as exc: - outcome_holder.append(Error(exc)) - else: - outcome_holder.append(Value(retval)) - - def _main_task_finished(self, outcome: object) -> None: - self._send_stream = None - - def _call_in_runner_task( - self, - func: Callable[P, Awaitable[T_Retval]], - /, - *args: P.args, - **kwargs: P.kwargs, - ) -> T_Retval: - if self._send_stream is None: - trio.lowlevel.start_guest_run( - self._run_tests_and_fixtures, - run_sync_soon_threadsafe=self._call_queue.put, - done_callback=self._main_task_finished, - **self._options, - ) - while self._send_stream is None: - self._call_queue.get()() - - outcome_holder: list[Outcome] = [] - self._send_stream.send_nowait((func(*args, **kwargs), outcome_holder)) - while not outcome_holder: - self._call_queue.get()() - - return outcome_holder[0].unwrap() - - def run_asyncgen_fixture( - self, - fixture_func: Callable[..., AsyncGenerator[T_Retval, Any]], - kwargs: dict[str, Any], - ) -> Iterable[T_Retval]: - asyncgen = fixture_func(**kwargs) - fixturevalue: T_Retval = self._call_in_runner_task(asyncgen.asend, None) - - yield fixturevalue - - try: - self._call_in_runner_task(asyncgen.asend, None) - except StopAsyncIteration: - pass - else: - self._call_in_runner_task(asyncgen.aclose) - raise RuntimeError("Async generator fixture did not stop") - - def run_fixture( - self, - fixture_func: Callable[..., Coroutine[Any, Any, T_Retval]], - kwargs: dict[str, Any], - ) -> T_Retval: - return self._call_in_runner_task(fixture_func, **kwargs) - - def run_test( - self, test_func: Callable[..., Coroutine[Any, Any, Any]], kwargs: dict[str, Any] - ) -> None: - self._call_in_runner_task(test_func, **kwargs) - - -class TrioTaskInfo(TaskInfo): - def __init__(self, task: trio.lowlevel.Task): - parent_id = None - if task.parent_nursery and task.parent_nursery.parent_task: - parent_id = id(task.parent_nursery.parent_task) - - super().__init__(id(task), parent_id, task.name, task.coro) - self._task = weakref.proxy(task) - - def has_pending_cancellation(self) -> bool: - try: - return self._task._cancel_status.effectively_cancelled - except ReferenceError: - # If the task is no longer around, it surely doesn't have a cancellation - # pending - return False - - -class TrioBackend(AsyncBackend): - @classmethod - def run( - cls, - func: Callable[[Unpack[PosArgsT]], Awaitable[T_Retval]], - args: tuple[Unpack[PosArgsT]], - kwargs: dict[str, Any], - options: dict[str, Any], - ) -> T_Retval: - return trio.run(func, *args) - - @classmethod - def current_token(cls) -> object: - return trio.lowlevel.current_trio_token() - - @classmethod - def current_time(cls) -> float: - return trio.current_time() - - @classmethod - def cancelled_exception_class(cls) -> type[BaseException]: - return trio.Cancelled - - @classmethod - async def checkpoint(cls) -> None: - await trio.lowlevel.checkpoint() - - @classmethod - async def checkpoint_if_cancelled(cls) -> None: - await trio.lowlevel.checkpoint_if_cancelled() - - @classmethod - async def cancel_shielded_checkpoint(cls) -> None: - await trio.lowlevel.cancel_shielded_checkpoint() - - @classmethod - async def sleep(cls, delay: float) -> None: - await trio.sleep(delay) - - @classmethod - def create_cancel_scope( - cls, *, deadline: float = math.inf, shield: bool = False - ) -> abc.CancelScope: - return CancelScope(deadline=deadline, shield=shield) - - @classmethod - def current_effective_deadline(cls) -> float: - return trio.current_effective_deadline() - - @classmethod - def create_task_group(cls) -> abc.TaskGroup: - return TaskGroup() - - @classmethod - def create_event(cls) -> abc.Event: - return Event() - - @classmethod - def create_lock(cls, *, fast_acquire: bool) -> Lock: - return Lock(fast_acquire=fast_acquire) - - @classmethod - def create_semaphore( - cls, - initial_value: int, - *, - max_value: int | None = None, - fast_acquire: bool = False, - ) -> abc.Semaphore: - return Semaphore(initial_value, max_value=max_value, fast_acquire=fast_acquire) - - @classmethod - def create_capacity_limiter(cls, total_tokens: float) -> CapacityLimiter: - return CapacityLimiter(total_tokens) - - @classmethod - async def run_sync_in_worker_thread( - cls, - func: Callable[[Unpack[PosArgsT]], T_Retval], - args: tuple[Unpack[PosArgsT]], - abandon_on_cancel: bool = False, - limiter: abc.CapacityLimiter | None = None, - ) -> T_Retval: - def wrapper() -> T_Retval: - with claim_worker_thread(TrioBackend, token): - return func(*args) - - token = TrioBackend.current_token() - return await run_sync( - wrapper, - abandon_on_cancel=abandon_on_cancel, - limiter=cast(trio.CapacityLimiter, limiter), - ) - - @classmethod - def check_cancelled(cls) -> None: - trio.from_thread.check_cancelled() - - @classmethod - def run_async_from_thread( - cls, - func: Callable[[Unpack[PosArgsT]], Awaitable[T_Retval]], - args: tuple[Unpack[PosArgsT]], - token: object, - ) -> T_Retval: - trio_token = cast("trio.lowlevel.TrioToken | None", token) - try: - return trio.from_thread.run(func, *args, trio_token=trio_token) - except trio.RunFinishedError: - raise RunFinishedError from None - - @classmethod - def run_sync_from_thread( - cls, - func: Callable[[Unpack[PosArgsT]], T_Retval], - args: tuple[Unpack[PosArgsT]], - token: object, - ) -> T_Retval: - trio_token = cast("trio.lowlevel.TrioToken | None", token) - try: - return trio.from_thread.run_sync(func, *args, trio_token=trio_token) - except trio.RunFinishedError: - raise RunFinishedError from None - - @classmethod - async def open_process( - cls, - command: StrOrBytesPath | Sequence[StrOrBytesPath], - *, - stdin: int | IO[Any] | None, - stdout: int | IO[Any] | None, - stderr: int | IO[Any] | None, - **kwargs: Any, - ) -> Process: - def convert_item(item: StrOrBytesPath) -> str: - str_or_bytes = os.fspath(item) - if isinstance(str_or_bytes, str): - return str_or_bytes - else: - return os.fsdecode(str_or_bytes) - - if isinstance(command, (str, bytes, PathLike)): - process = await trio.lowlevel.open_process( - convert_item(command), - stdin=stdin, - stdout=stdout, - stderr=stderr, - shell=True, - **kwargs, - ) - else: - process = await trio.lowlevel.open_process( - [convert_item(item) for item in command], - stdin=stdin, - stdout=stdout, - stderr=stderr, - shell=False, - **kwargs, - ) - - stdin_stream = SendStreamWrapper(process.stdin) if process.stdin else None - stdout_stream = ReceiveStreamWrapper(process.stdout) if process.stdout else None - stderr_stream = ReceiveStreamWrapper(process.stderr) if process.stderr else None - return Process(process, stdin_stream, stdout_stream, stderr_stream) - - @classmethod - def setup_process_pool_exit_at_shutdown(cls, workers: set[abc.Process]) -> None: - trio.lowlevel.spawn_system_task(_shutdown_process_pool, workers) - - @classmethod - async def connect_tcp( - cls, host: str, port: int, local_address: IPSockAddrType | None = None - ) -> SocketStream: - family = socket.AF_INET6 if ":" in host else socket.AF_INET - trio_socket = trio.socket.socket(family) - trio_socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) - if local_address: - await trio_socket.bind(local_address) - - try: - await trio_socket.connect((host, port)) - except BaseException: - trio_socket.close() - raise - - return SocketStream(trio_socket) - - @classmethod - async def connect_unix(cls, path: str | bytes) -> abc.UNIXSocketStream: - trio_socket = trio.socket.socket(socket.AF_UNIX) - try: - await trio_socket.connect(path) - except BaseException: - trio_socket.close() - raise - - return UNIXSocketStream(trio_socket) - - @classmethod - def create_tcp_listener(cls, sock: socket.socket) -> abc.SocketListener: - return TCPSocketListener(sock) - - @classmethod - def create_unix_listener(cls, sock: socket.socket) -> abc.SocketListener: - return UNIXSocketListener(sock) - - @classmethod - async def create_udp_socket( - cls, - family: socket.AddressFamily, - local_address: IPSockAddrType | None, - remote_address: IPSockAddrType | None, - reuse_port: bool, - ) -> UDPSocket | ConnectedUDPSocket: - trio_socket = trio.socket.socket(family=family, type=socket.SOCK_DGRAM) - - if reuse_port: - trio_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1) - - if local_address: - await trio_socket.bind(local_address) - - if remote_address: - await trio_socket.connect(remote_address) - return ConnectedUDPSocket(trio_socket) - else: - return UDPSocket(trio_socket) - - @classmethod - @overload - async def create_unix_datagram_socket( - cls, raw_socket: socket.socket, remote_path: None - ) -> abc.UNIXDatagramSocket: ... - - @classmethod - @overload - async def create_unix_datagram_socket( - cls, raw_socket: socket.socket, remote_path: str | bytes - ) -> abc.ConnectedUNIXDatagramSocket: ... - - @classmethod - async def create_unix_datagram_socket( - cls, raw_socket: socket.socket, remote_path: str | bytes | None - ) -> abc.UNIXDatagramSocket | abc.ConnectedUNIXDatagramSocket: - trio_socket = trio.socket.from_stdlib_socket(raw_socket) - - if remote_path: - await trio_socket.connect(remote_path) - return ConnectedUNIXDatagramSocket(trio_socket) - else: - return UNIXDatagramSocket(trio_socket) - - @classmethod - async def getaddrinfo( - cls, - host: bytes | str | None, - port: str | int | None, - *, - family: int | AddressFamily = 0, - type: int | SocketKind = 0, - proto: int = 0, - flags: int = 0, - ) -> Sequence[ - tuple[ - AddressFamily, - SocketKind, - int, - str, - tuple[str, int] | tuple[str, int, int, int] | tuple[int, bytes], - ] - ]: - return await trio.socket.getaddrinfo(host, port, family, type, proto, flags) - - @classmethod - async def getnameinfo( - cls, sockaddr: IPSockAddrType, flags: int = 0 - ) -> tuple[str, str]: - return await trio.socket.getnameinfo(sockaddr, flags) - - @classmethod - async def wait_readable(cls, obj: FileDescriptorLike) -> None: - try: - await wait_readable(obj) - except trio.ClosedResourceError as exc: - raise ClosedResourceError().with_traceback(exc.__traceback__) from None - except trio.BusyResourceError: - raise BusyResourceError("reading from") from None - - @classmethod - async def wait_writable(cls, obj: FileDescriptorLike) -> None: - try: - await wait_writable(obj) - except trio.ClosedResourceError as exc: - raise ClosedResourceError().with_traceback(exc.__traceback__) from None - except trio.BusyResourceError: - raise BusyResourceError("writing to") from None - - @classmethod - def notify_closing(cls, obj: FileDescriptorLike) -> None: - notify_closing(obj) - - @classmethod - async def wrap_listener_socket(cls, sock: socket.socket) -> abc.SocketListener: - return TCPSocketListener(sock) - - @classmethod - async def wrap_stream_socket(cls, sock: socket.socket) -> SocketStream: - trio_sock = trio.socket.from_stdlib_socket(sock) - return SocketStream(trio_sock) - - @classmethod - async def wrap_unix_stream_socket(cls, sock: socket.socket) -> UNIXSocketStream: - trio_sock = trio.socket.from_stdlib_socket(sock) - return UNIXSocketStream(trio_sock) - - @classmethod - async def wrap_udp_socket(cls, sock: socket.socket) -> UDPSocket: - trio_sock = trio.socket.from_stdlib_socket(sock) - return UDPSocket(trio_sock) - - @classmethod - async def wrap_connected_udp_socket(cls, sock: socket.socket) -> ConnectedUDPSocket: - trio_sock = trio.socket.from_stdlib_socket(sock) - return ConnectedUDPSocket(trio_sock) - - @classmethod - async def wrap_unix_datagram_socket(cls, sock: socket.socket) -> UNIXDatagramSocket: - trio_sock = trio.socket.from_stdlib_socket(sock) - return UNIXDatagramSocket(trio_sock) - - @classmethod - async def wrap_connected_unix_datagram_socket( - cls, sock: socket.socket - ) -> ConnectedUNIXDatagramSocket: - trio_sock = trio.socket.from_stdlib_socket(sock) - return ConnectedUNIXDatagramSocket(trio_sock) - - @classmethod - def current_default_thread_limiter(cls) -> CapacityLimiter: - try: - return _capacity_limiter_wrapper.get() - except LookupError: - limiter = CapacityLimiter( - original=trio.to_thread.current_default_thread_limiter() - ) - _capacity_limiter_wrapper.set(limiter) - return limiter - - @classmethod - def open_signal_receiver( - cls, *signals: Signals - ) -> AbstractContextManager[AsyncIterator[Signals]]: - return _SignalReceiver(signals) - - @classmethod - def get_current_task(cls) -> TaskInfo: - task = current_task() - return TrioTaskInfo(task) - - @classmethod - def get_running_tasks(cls) -> Sequence[TaskInfo]: - root_task = current_root_task() - assert root_task - task_infos = [TrioTaskInfo(root_task)] - nurseries = root_task.child_nurseries - while nurseries: - new_nurseries: list[trio.Nursery] = [] - for nursery in nurseries: - for task in nursery.child_tasks: - task_infos.append(TrioTaskInfo(task)) - new_nurseries.extend(task.child_nurseries) - - nurseries = new_nurseries - - return task_infos - - @classmethod - async def wait_all_tasks_blocked(cls) -> None: - from trio.testing import wait_all_tasks_blocked - - await wait_all_tasks_blocked() - - @classmethod - def create_test_runner(cls, options: dict[str, Any]) -> TestRunner: - return TestRunner(**options) - - -backend_class = TrioBackend diff --git a/.venv/lib/python3.12/site-packages/anyio/_core/__init__.py b/.venv/lib/python3.12/site-packages/anyio/_core/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/.venv/lib/python3.12/site-packages/anyio/_core/_asyncio_selector_thread.py b/.venv/lib/python3.12/site-packages/anyio/_core/_asyncio_selector_thread.py deleted file mode 100644 index 9f35bae..0000000 --- a/.venv/lib/python3.12/site-packages/anyio/_core/_asyncio_selector_thread.py +++ /dev/null @@ -1,167 +0,0 @@ -from __future__ import annotations - -import asyncio -import socket -import threading -from collections.abc import Callable -from selectors import EVENT_READ, EVENT_WRITE, DefaultSelector -from typing import TYPE_CHECKING, Any - -if TYPE_CHECKING: - from _typeshed import FileDescriptorLike - -_selector_lock = threading.Lock() -_selector: Selector | None = None - - -class Selector: - def __init__(self) -> None: - self._thread = threading.Thread(target=self.run, name="AnyIO socket selector") - self._selector = DefaultSelector() - self._send, self._receive = socket.socketpair() - self._send.setblocking(False) - self._receive.setblocking(False) - # This somewhat reduces the amount of memory wasted queueing up data - # for wakeups. With these settings, maximum number of 1-byte sends - # before getting BlockingIOError: - # Linux 4.8: 6 - # macOS (darwin 15.5): 1 - # Windows 10: 525347 - # Windows you're weird. (And on Windows setting SNDBUF to 0 makes send - # blocking, even on non-blocking sockets, so don't do that.) - self._receive.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1) - self._send.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1) - # On Windows this is a TCP socket so this might matter. On other - # platforms this fails b/c AF_UNIX sockets aren't actually TCP. - try: - self._send.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) - except OSError: - pass - - self._selector.register(self._receive, EVENT_READ) - self._closed = False - - def start(self) -> None: - self._thread.start() - threading._register_atexit(self._stop) # type: ignore[attr-defined] - - def _stop(self) -> None: - global _selector - self._closed = True - self._notify_self() - self._send.close() - self._thread.join() - self._selector.unregister(self._receive) - self._receive.close() - self._selector.close() - _selector = None - assert not self._selector.get_map(), ( - "selector still has registered file descriptors after shutdown" - ) - - def _notify_self(self) -> None: - try: - self._send.send(b"\x00") - except BlockingIOError: - pass - - def add_reader(self, fd: FileDescriptorLike, callback: Callable[[], Any]) -> None: - loop = asyncio.get_running_loop() - try: - key = self._selector.get_key(fd) - except KeyError: - self._selector.register(fd, EVENT_READ, {EVENT_READ: (loop, callback)}) - else: - if EVENT_READ in key.data: - raise ValueError( - "this file descriptor is already registered for reading" - ) - - key.data[EVENT_READ] = loop, callback - self._selector.modify(fd, key.events | EVENT_READ, key.data) - - self._notify_self() - - def add_writer(self, fd: FileDescriptorLike, callback: Callable[[], Any]) -> None: - loop = asyncio.get_running_loop() - try: - key = self._selector.get_key(fd) - except KeyError: - self._selector.register(fd, EVENT_WRITE, {EVENT_WRITE: (loop, callback)}) - else: - if EVENT_WRITE in key.data: - raise ValueError( - "this file descriptor is already registered for writing" - ) - - key.data[EVENT_WRITE] = loop, callback - self._selector.modify(fd, key.events | EVENT_WRITE, key.data) - - self._notify_self() - - def remove_reader(self, fd: FileDescriptorLike) -> bool: - try: - key = self._selector.get_key(fd) - except KeyError: - return False - - if new_events := key.events ^ EVENT_READ: - del key.data[EVENT_READ] - self._selector.modify(fd, new_events, key.data) - else: - self._selector.unregister(fd) - - return True - - def remove_writer(self, fd: FileDescriptorLike) -> bool: - try: - key = self._selector.get_key(fd) - except KeyError: - return False - - if new_events := key.events ^ EVENT_WRITE: - del key.data[EVENT_WRITE] - self._selector.modify(fd, new_events, key.data) - else: - self._selector.unregister(fd) - - return True - - def run(self) -> None: - while not self._closed: - for key, events in self._selector.select(): - if key.fileobj is self._receive: - try: - while self._receive.recv(4096): - pass - except BlockingIOError: - pass - - continue - - if events & EVENT_READ: - loop, callback = key.data[EVENT_READ] - self.remove_reader(key.fd) - try: - loop.call_soon_threadsafe(callback) - except RuntimeError: - pass # the loop was already closed - - if events & EVENT_WRITE: - loop, callback = key.data[EVENT_WRITE] - self.remove_writer(key.fd) - try: - loop.call_soon_threadsafe(callback) - except RuntimeError: - pass # the loop was already closed - - -def get_selector() -> Selector: - global _selector - - with _selector_lock: - if _selector is None: - _selector = Selector() - _selector.start() - - return _selector diff --git a/.venv/lib/python3.12/site-packages/anyio/_core/_contextmanagers.py b/.venv/lib/python3.12/site-packages/anyio/_core/_contextmanagers.py deleted file mode 100644 index 302f32b..0000000 --- a/.venv/lib/python3.12/site-packages/anyio/_core/_contextmanagers.py +++ /dev/null @@ -1,200 +0,0 @@ -from __future__ import annotations - -from abc import abstractmethod -from contextlib import AbstractAsyncContextManager, AbstractContextManager -from inspect import isasyncgen, iscoroutine, isgenerator -from types import TracebackType -from typing import Protocol, TypeVar, cast, final - -_T_co = TypeVar("_T_co", covariant=True) -_ExitT_co = TypeVar("_ExitT_co", covariant=True, bound="bool | None") - - -class _SupportsCtxMgr(Protocol[_T_co, _ExitT_co]): - def __contextmanager__(self) -> AbstractContextManager[_T_co, _ExitT_co]: ... - - -class _SupportsAsyncCtxMgr(Protocol[_T_co, _ExitT_co]): - def __asynccontextmanager__( - self, - ) -> AbstractAsyncContextManager[_T_co, _ExitT_co]: ... - - -class ContextManagerMixin: - """ - Mixin class providing context manager functionality via a generator-based - implementation. - - This class allows you to implement a context manager via :meth:`__contextmanager__` - which should return a generator. The mechanics are meant to mirror those of - :func:`@contextmanager `. - - .. note:: Classes using this mix-in are not reentrant as context managers, meaning - that once you enter it, you can't re-enter before first exiting it. - - .. seealso:: :doc:`contextmanagers` - """ - - __cm: AbstractContextManager[object, bool | None] | None = None - - @final - def __enter__(self: _SupportsCtxMgr[_T_co, bool | None]) -> _T_co: - # Needed for mypy to assume self still has the __cm member - assert isinstance(self, ContextManagerMixin) - if self.__cm is not None: - raise RuntimeError( - f"this {self.__class__.__qualname__} has already been entered" - ) - - cm = self.__contextmanager__() - if not isinstance(cm, AbstractContextManager): - if isgenerator(cm): - raise TypeError( - "__contextmanager__() returned a generator object instead of " - "a context manager. Did you forget to add the @contextmanager " - "decorator?" - ) - - raise TypeError( - f"__contextmanager__() did not return a context manager object, " - f"but {cm.__class__!r}" - ) - - if cm is self: - raise TypeError( - f"{self.__class__.__qualname__}.__contextmanager__() returned " - f"self. Did you forget to add the @contextmanager decorator and a " - f"'yield' statement?" - ) - - value = cm.__enter__() - self.__cm = cm - return value - - @final - def __exit__( - self: _SupportsCtxMgr[object, _ExitT_co], - exc_type: type[BaseException] | None, - exc_val: BaseException | None, - exc_tb: TracebackType | None, - ) -> _ExitT_co: - # Needed for mypy to assume self still has the __cm member - assert isinstance(self, ContextManagerMixin) - if self.__cm is None: - raise RuntimeError( - f"this {self.__class__.__qualname__} has not been entered yet" - ) - - # Prevent circular references - cm = self.__cm - del self.__cm - - return cast(_ExitT_co, cm.__exit__(exc_type, exc_val, exc_tb)) - - @abstractmethod - def __contextmanager__(self) -> AbstractContextManager[object, bool | None]: - """ - Implement your context manager logic here. - - This method **must** be decorated with - :func:`@contextmanager `. - - .. note:: Remember that the ``yield`` will raise any exception raised in the - enclosed context block, so use a ``finally:`` block to clean up resources! - - :return: a context manager object - """ - - -class AsyncContextManagerMixin: - """ - Mixin class providing async context manager functionality via a generator-based - implementation. - - This class allows you to implement a context manager via - :meth:`__asynccontextmanager__`. The mechanics are meant to mirror those of - :func:`@asynccontextmanager `. - - .. note:: Classes using this mix-in are not reentrant as context managers, meaning - that once you enter it, you can't re-enter before first exiting it. - - .. seealso:: :doc:`contextmanagers` - """ - - __cm: AbstractAsyncContextManager[object, bool | None] | None = None - - @final - async def __aenter__(self: _SupportsAsyncCtxMgr[_T_co, bool | None]) -> _T_co: - # Needed for mypy to assume self still has the __cm member - assert isinstance(self, AsyncContextManagerMixin) - if self.__cm is not None: - raise RuntimeError( - f"this {self.__class__.__qualname__} has already been entered" - ) - - cm = self.__asynccontextmanager__() - if not isinstance(cm, AbstractAsyncContextManager): - if isasyncgen(cm): - raise TypeError( - "__asynccontextmanager__() returned an async generator instead of " - "an async context manager. Did you forget to add the " - "@asynccontextmanager decorator?" - ) - elif iscoroutine(cm): - cm.close() - raise TypeError( - "__asynccontextmanager__() returned a coroutine object instead of " - "an async context manager. Did you forget to add the " - "@asynccontextmanager decorator and a 'yield' statement?" - ) - - raise TypeError( - f"__asynccontextmanager__() did not return an async context manager, " - f"but {cm.__class__!r}" - ) - - if cm is self: - raise TypeError( - f"{self.__class__.__qualname__}.__asynccontextmanager__() returned " - f"self. Did you forget to add the @asynccontextmanager decorator and a " - f"'yield' statement?" - ) - - value = await cm.__aenter__() - self.__cm = cm - return value - - @final - async def __aexit__( - self: _SupportsAsyncCtxMgr[object, _ExitT_co], - exc_type: type[BaseException] | None, - exc_val: BaseException | None, - exc_tb: TracebackType | None, - ) -> _ExitT_co: - assert isinstance(self, AsyncContextManagerMixin) - if self.__cm is None: - raise RuntimeError( - f"this {self.__class__.__qualname__} has not been entered yet" - ) - - # Prevent circular references - cm = self.__cm - del self.__cm - - return cast(_ExitT_co, await cm.__aexit__(exc_type, exc_val, exc_tb)) - - @abstractmethod - def __asynccontextmanager__( - self, - ) -> AbstractAsyncContextManager[object, bool | None]: - """ - Implement your async context manager logic here. - - This method **must** be decorated with - :func:`@asynccontextmanager `. - - .. note:: Remember that the ``yield`` will raise any exception raised in the - enclosed context block, so use a ``finally:`` block to clean up resources! - - :return: an async context manager object - """ diff --git a/.venv/lib/python3.12/site-packages/anyio/_core/_eventloop.py b/.venv/lib/python3.12/site-packages/anyio/_core/_eventloop.py deleted file mode 100644 index 59a69cc..0000000 --- a/.venv/lib/python3.12/site-packages/anyio/_core/_eventloop.py +++ /dev/null @@ -1,234 +0,0 @@ -from __future__ import annotations - -import math -import sys -import threading -from collections.abc import Awaitable, Callable, Generator -from contextlib import contextmanager -from contextvars import Token -from importlib import import_module -from typing import TYPE_CHECKING, Any, TypeVar - -from ._exceptions import NoEventLoopError - -if sys.version_info >= (3, 11): - from typing import TypeVarTuple, Unpack -else: - from typing_extensions import TypeVarTuple, Unpack - -sniffio: Any -try: - import sniffio -except ModuleNotFoundError: - sniffio = None - -if TYPE_CHECKING: - from ..abc import AsyncBackend - -# This must be updated when new backends are introduced -BACKENDS = "asyncio", "trio" - -T_Retval = TypeVar("T_Retval") -PosArgsT = TypeVarTuple("PosArgsT") - -threadlocals = threading.local() -loaded_backends: dict[str, type[AsyncBackend]] = {} - - -def run( - func: Callable[[Unpack[PosArgsT]], Awaitable[T_Retval]], - *args: Unpack[PosArgsT], - backend: str = "asyncio", - backend_options: dict[str, Any] | None = None, -) -> T_Retval: - """ - Run the given coroutine function in an asynchronous event loop. - - The current thread must not be already running an event loop. - - :param func: a coroutine function - :param args: positional arguments to ``func`` - :param backend: name of the asynchronous event loop implementation – currently - either ``asyncio`` or ``trio`` - :param backend_options: keyword arguments to call the backend ``run()`` - implementation with (documented :ref:`here `) - :return: the return value of the coroutine function - :raises RuntimeError: if an asynchronous event loop is already running in this - thread - :raises LookupError: if the named backend is not found - - """ - if asynclib_name := current_async_library(): - raise RuntimeError(f"Already running {asynclib_name} in this thread") - - try: - async_backend = get_async_backend(backend) - except ImportError as exc: - raise LookupError(f"No such backend: {backend}") from exc - - token = None - if asynclib_name is None: - # Since we're in control of the event loop, we can cache the name of the async - # library - token = set_current_async_library(backend) - - try: - backend_options = backend_options or {} - return async_backend.run(func, args, {}, backend_options) - finally: - reset_current_async_library(token) - - -async def sleep(delay: float) -> None: - """ - Pause the current task for the specified duration. - - :param delay: the duration, in seconds - - """ - return await get_async_backend().sleep(delay) - - -async def sleep_forever() -> None: - """ - Pause the current task until it's cancelled. - - This is a shortcut for ``sleep(math.inf)``. - - .. versionadded:: 3.1 - - """ - await sleep(math.inf) - - -async def sleep_until(deadline: float) -> None: - """ - Pause the current task until the given time. - - :param deadline: the absolute time to wake up at (according to the internal - monotonic clock of the event loop) - - .. versionadded:: 3.1 - - """ - now = current_time() - await sleep(max(deadline - now, 0)) - - -def current_time() -> float: - """ - Return the current value of the event loop's internal clock. - - :return: the clock value (seconds) - :raises NoEventLoopError: if no supported asynchronous event loop is running in the - current thread - - """ - return get_async_backend().current_time() - - -def get_all_backends() -> tuple[str, ...]: - """Return a tuple of the names of all built-in backends.""" - return BACKENDS - - -def get_available_backends() -> tuple[str, ...]: - """ - Test for the availability of built-in backends. - - :return a tuple of the built-in backend names that were successfully imported - - .. versionadded:: 4.12 - - """ - available_backends: list[str] = [] - for backend_name in get_all_backends(): - try: - get_async_backend(backend_name) - except ImportError: - continue - - available_backends.append(backend_name) - - return tuple(available_backends) - - -def get_cancelled_exc_class() -> type[BaseException]: - """ - Return the current async library's cancellation exception class. - - :raises NoEventLoopError: if no supported asynchronous event loop is running in the - current thread - - """ - return get_async_backend().cancelled_exception_class() - - -# -# Private API -# - - -@contextmanager -def claim_worker_thread( - backend_class: type[AsyncBackend], token: object -) -> Generator[Any, None, None]: - from ..lowlevel import EventLoopToken - - threadlocals.current_token = EventLoopToken(backend_class, token) - try: - yield - finally: - del threadlocals.current_token - - -def get_async_backend(asynclib_name: str | None = None) -> type[AsyncBackend]: - if asynclib_name is None: - asynclib_name = current_async_library() - if not asynclib_name: - raise NoEventLoopError( - f"Not currently running on any asynchronous event loop. " - f"Available async backends: {', '.join(get_all_backends())}" - ) - - # We use our own dict instead of sys.modules to get the already imported back-end - # class because the appropriate modules in sys.modules could potentially be only - # partially initialized - try: - return loaded_backends[asynclib_name] - except KeyError: - module = import_module(f"anyio._backends._{asynclib_name}") - loaded_backends[asynclib_name] = module.backend_class - return module.backend_class - - -def current_async_library() -> str | None: - if sniffio is None: - # If sniffio is not installed, we assume we're either running asyncio or nothing - import asyncio - - try: - asyncio.get_running_loop() - return "asyncio" - except RuntimeError: - pass - else: - try: - return sniffio.current_async_library() - except sniffio.AsyncLibraryNotFoundError: - pass - - return None - - -def set_current_async_library(asynclib_name: str | None) -> Token | None: - # no-op if sniffio is not installed - if sniffio is None: - return None - - return sniffio.current_async_library_cvar.set(asynclib_name) - - -def reset_current_async_library(token: Token | None) -> None: - if token is not None: - sniffio.current_async_library_cvar.reset(token) diff --git a/.venv/lib/python3.12/site-packages/anyio/_core/_exceptions.py b/.venv/lib/python3.12/site-packages/anyio/_core/_exceptions.py deleted file mode 100644 index 3776bed..0000000 --- a/.venv/lib/python3.12/site-packages/anyio/_core/_exceptions.py +++ /dev/null @@ -1,156 +0,0 @@ -from __future__ import annotations - -import sys -from collections.abc import Generator -from textwrap import dedent -from typing import Any - -if sys.version_info < (3, 11): - from exceptiongroup import BaseExceptionGroup - - -class BrokenResourceError(Exception): - """ - Raised when trying to use a resource that has been rendered unusable due to external - causes (e.g. a send stream whose peer has disconnected). - """ - - -class BrokenWorkerProcess(Exception): - """ - Raised by :meth:`~anyio.to_process.run_sync` if the worker process terminates abruptly or - otherwise misbehaves. - """ - - -class BrokenWorkerInterpreter(Exception): - """ - Raised by :meth:`~anyio.to_interpreter.run_sync` if an unexpected exception is - raised in the subinterpreter. - """ - - def __init__(self, excinfo: Any): - # This was adapted from concurrent.futures.interpreter.ExecutionFailed - msg = excinfo.formatted - if not msg: - if excinfo.type and excinfo.msg: - msg = f"{excinfo.type.__name__}: {excinfo.msg}" - else: - msg = excinfo.type.__name__ or excinfo.msg - - super().__init__(msg) - self.excinfo = excinfo - - def __str__(self) -> str: - try: - formatted = self.excinfo.errdisplay - except Exception: - return super().__str__() - else: - return dedent( - f""" - {super().__str__()} - - Uncaught in the interpreter: - - {formatted} - """.strip() - ) - - -class BusyResourceError(Exception): - """ - Raised when two tasks are trying to read from or write to the same resource - concurrently. - """ - - def __init__(self, action: str): - super().__init__(f"Another task is already {action} this resource") - - -class ClosedResourceError(Exception): - """Raised when trying to use a resource that has been closed.""" - - -class ConnectionFailed(OSError): - """ - Raised when a connection attempt fails. - - .. note:: This class inherits from :exc:`OSError` for backwards compatibility. - """ - - -def iterate_exceptions( - exception: BaseException, -) -> Generator[BaseException, None, None]: - if isinstance(exception, BaseExceptionGroup): - for exc in exception.exceptions: - yield from iterate_exceptions(exc) - else: - yield exception - - -class DelimiterNotFound(Exception): - """ - Raised during - :meth:`~anyio.streams.buffered.BufferedByteReceiveStream.receive_until` if the - maximum number of bytes has been read without the delimiter being found. - """ - - def __init__(self, max_bytes: int) -> None: - super().__init__( - f"The delimiter was not found among the first {max_bytes} bytes" - ) - - -class EndOfStream(Exception): - """ - Raised when trying to read from a stream that has been closed from the other end. - """ - - -class IncompleteRead(Exception): - """ - Raised during - :meth:`~anyio.streams.buffered.BufferedByteReceiveStream.receive_exactly` or - :meth:`~anyio.streams.buffered.BufferedByteReceiveStream.receive_until` if the - connection is closed before the requested amount of bytes has been read. - """ - - def __init__(self) -> None: - super().__init__( - "The stream was closed before the read operation could be completed" - ) - - -class TypedAttributeLookupError(LookupError): - """ - Raised by :meth:`~anyio.TypedAttributeProvider.extra` when the given typed attribute - is not found and no default value has been given. - """ - - -class WouldBlock(Exception): - """Raised by ``X_nowait`` functions if ``X()`` would block.""" - - -class NoEventLoopError(RuntimeError): - """ - Raised by several functions that require an event loop to be running in the current - thread when there is no running event loop. - - This is also raised by :func:`.from_thread.run` and :func:`.from_thread.run_sync` - if not calling from an AnyIO worker thread, and no ``token`` was passed. - """ - - -class RunFinishedError(RuntimeError): - """ - Raised by :func:`.from_thread.run` and :func:`.from_thread.run_sync` if the event - loop associated with the explicitly passed token has already finished. - """ - - def __init__(self) -> None: - super().__init__( - "The event loop associated with the given token has already finished" - ) diff --git a/.venv/lib/python3.12/site-packages/anyio/_core/_fileio.py b/.venv/lib/python3.12/site-packages/anyio/_core/_fileio.py deleted file mode 100644 index 3bb8c84..0000000 --- a/.venv/lib/python3.12/site-packages/anyio/_core/_fileio.py +++ /dev/null @@ -1,799 +0,0 @@ -from __future__ import annotations - -import os -import pathlib -import sys -from collections.abc import ( - AsyncIterator, - Callable, - Iterable, - Iterator, - Sequence, -) -from dataclasses import dataclass -from functools import partial -from os import PathLike -from typing import ( - IO, - TYPE_CHECKING, - Any, - AnyStr, - ClassVar, - Final, - Generic, - overload, -) - -from .. import to_thread -from ..abc import AsyncResource - -if TYPE_CHECKING: - from types import ModuleType - - from _typeshed import OpenBinaryMode, OpenTextMode, ReadableBuffer, WriteableBuffer -else: - ReadableBuffer = OpenBinaryMode = OpenTextMode = WriteableBuffer = object - - -class AsyncFile(AsyncResource, Generic[AnyStr]): - """ - An asynchronous file object. - - This class wraps a standard file object and provides async friendly versions of the - following blocking methods (where available on the original file object): - - * read - * read1 - * readline - * readlines - * readinto - * readinto1 - * write - * writelines - * truncate - * seek - * tell - * flush - - All other methods are directly passed through. - - This class supports the asynchronous context manager protocol which closes the - underlying file at the end of the context block. - - This class also supports asynchronous iteration:: - - async with await open_file(...) as f: - async for line in f: - print(line) - """ - - def __init__(self, fp: IO[AnyStr]) -> None: - self._fp: Any = fp - - def __getattr__(self, name: str) -> object: - return getattr(self._fp, name) - - @property - def wrapped(self) -> IO[AnyStr]: - """The wrapped file object.""" - return self._fp - - async def __aiter__(self) -> AsyncIterator[AnyStr]: - while True: - line = await self.readline() - if line: - yield line - else: - break - - async def aclose(self) -> None: - return await to_thread.run_sync(self._fp.close) - - async def read(self, size: int = -1) -> AnyStr: - return await to_thread.run_sync(self._fp.read, size) - - async def read1(self: AsyncFile[bytes], size: int = -1) -> bytes: - return await to_thread.run_sync(self._fp.read1, size) - - async def readline(self) -> AnyStr: - return await to_thread.run_sync(self._fp.readline) - - async def readlines(self) -> list[AnyStr]: - return await to_thread.run_sync(self._fp.readlines) - - async def readinto(self: AsyncFile[bytes], b: WriteableBuffer) -> int: - return await to_thread.run_sync(self._fp.readinto, b) - - async def readinto1(self: AsyncFile[bytes], b: WriteableBuffer) -> int: - return await to_thread.run_sync(self._fp.readinto1, b) - - @overload - async def write(self: AsyncFile[bytes], b: ReadableBuffer) -> int: ... - - @overload - async def write(self: AsyncFile[str], b: str) -> int: ... - - async def write(self, b: ReadableBuffer | str) -> int: - return await to_thread.run_sync(self._fp.write, b) - - @overload - async def writelines( - self: AsyncFile[bytes], lines: Iterable[ReadableBuffer] - ) -> None: ... - - @overload - async def writelines(self: AsyncFile[str], lines: Iterable[str]) -> None: ... - - async def writelines(self, lines: Iterable[ReadableBuffer] | Iterable[str]) -> None: - return await to_thread.run_sync(self._fp.writelines, lines) - - async def truncate(self, size: int | None = None) -> int: - return await to_thread.run_sync(self._fp.truncate, size) - - async def seek(self, offset: int, whence: int | None = os.SEEK_SET) -> int: - return await to_thread.run_sync(self._fp.seek, offset, whence) - - async def tell(self) -> int: - return await to_thread.run_sync(self._fp.tell) - - async def flush(self) -> None: - return await to_thread.run_sync(self._fp.flush) - - -@overload -async def open_file( - file: str | PathLike[str] | int, - mode: OpenBinaryMode, - buffering: int = ..., - encoding: str | None = ..., - errors: str | None = ..., - newline: str | None = ..., - closefd: bool = ..., - opener: Callable[[str, int], int] | None = ..., -) -> AsyncFile[bytes]: ... - - -@overload -async def open_file( - file: str | PathLike[str] | int, - mode: OpenTextMode = ..., - buffering: int = ..., - encoding: str | None = ..., - errors: str | None = ..., - newline: str | None = ..., - closefd: bool = ..., - opener: Callable[[str, int], int] | None = ..., -) -> AsyncFile[str]: ... - - -async def open_file( - file: str | PathLike[str] | int, - mode: str = "r", - buffering: int = -1, - encoding: str | None = None, - errors: str | None = None, - newline: str | None = None, - closefd: bool = True, - opener: Callable[[str, int], int] | None = None, -) -> AsyncFile[Any]: - """ - Open a file asynchronously. - - The arguments are exactly the same as for the builtin :func:`open`. - - :return: an asynchronous file object - - """ - fp = await to_thread.run_sync( - open, file, mode, buffering, encoding, errors, newline, closefd, opener - ) - return AsyncFile(fp) - - -def wrap_file(file: IO[AnyStr]) -> AsyncFile[AnyStr]: - """ - Wrap an existing file as an asynchronous file. - - :param file: an existing file-like object - :return: an asynchronous file object - - """ - return AsyncFile(file) - - -@dataclass(eq=False) -class _PathIterator(AsyncIterator["Path"]): - iterator: Iterator[PathLike[str]] - - async def __anext__(self) -> Path: - nextval = await to_thread.run_sync( - next, self.iterator, None, abandon_on_cancel=True - ) - if nextval is None: - raise StopAsyncIteration from None - - return Path(nextval) - - -class Path: - """ - An asynchronous version of :class:`pathlib.Path`. - - This class cannot be substituted for :class:`pathlib.Path` or - :class:`pathlib.PurePath`, but it is compatible with the :class:`os.PathLike` - interface. - - It implements the Python 3.10 version of :class:`pathlib.Path` interface, except for - the deprecated :meth:`~pathlib.Path.link_to` method. - - Some methods may be unavailable or have limited functionality, based on the Python - version: - - * :meth:`~pathlib.Path.copy` (available on Python 3.14 or later) - * :meth:`~pathlib.Path.copy_into` (available on Python 3.14 or later) - * :meth:`~pathlib.Path.from_uri` (available on Python 3.13 or later) - * :meth:`~pathlib.PurePath.full_match` (available on Python 3.13 or later) - * :attr:`~pathlib.Path.info` (available on Python 3.14 or later) - * :meth:`~pathlib.Path.is_junction` (available on Python 3.12 or later) - * :meth:`~pathlib.PurePath.match` (the ``case_sensitive`` parameter is only - available on Python 3.13 or later) - * :meth:`~pathlib.Path.move` (available on Python 3.14 or later) - * :meth:`~pathlib.Path.move_into` (available on Python 3.14 or later) - * :meth:`~pathlib.PurePath.relative_to` (the ``walk_up`` parameter is only available - on Python 3.12 or later) - * :meth:`~pathlib.Path.walk` (available on Python 3.12 or later) - - Any methods that do disk I/O need to be awaited on. These methods are: - - * :meth:`~pathlib.Path.absolute` - * :meth:`~pathlib.Path.chmod` - * :meth:`~pathlib.Path.cwd` - * :meth:`~pathlib.Path.exists` - * :meth:`~pathlib.Path.expanduser` - * :meth:`~pathlib.Path.group` - * :meth:`~pathlib.Path.hardlink_to` - * :meth:`~pathlib.Path.home` - * :meth:`~pathlib.Path.is_block_device` - * :meth:`~pathlib.Path.is_char_device` - * :meth:`~pathlib.Path.is_dir` - * :meth:`~pathlib.Path.is_fifo` - * :meth:`~pathlib.Path.is_file` - * :meth:`~pathlib.Path.is_junction` - * :meth:`~pathlib.Path.is_mount` - * :meth:`~pathlib.Path.is_socket` - * :meth:`~pathlib.Path.is_symlink` - * :meth:`~pathlib.Path.lchmod` - * :meth:`~pathlib.Path.lstat` - * :meth:`~pathlib.Path.mkdir` - * :meth:`~pathlib.Path.open` - * :meth:`~pathlib.Path.owner` - * :meth:`~pathlib.Path.read_bytes` - * :meth:`~pathlib.Path.read_text` - * :meth:`~pathlib.Path.readlink` - * :meth:`~pathlib.Path.rename` - * :meth:`~pathlib.Path.replace` - * :meth:`~pathlib.Path.resolve` - * :meth:`~pathlib.Path.rmdir` - * :meth:`~pathlib.Path.samefile` - * :meth:`~pathlib.Path.stat` - * :meth:`~pathlib.Path.symlink_to` - * :meth:`~pathlib.Path.touch` - * :meth:`~pathlib.Path.unlink` - * :meth:`~pathlib.Path.walk` - * :meth:`~pathlib.Path.write_bytes` - * :meth:`~pathlib.Path.write_text` - - Additionally, the following methods return an async iterator yielding - :class:`~.Path` objects: - - * :meth:`~pathlib.Path.glob` - * :meth:`~pathlib.Path.iterdir` - * :meth:`~pathlib.Path.rglob` - """ - - __slots__ = "_path", "__weakref__" - - __weakref__: Any - - def __init__(self, *args: str | PathLike[str]) -> None: - self._path: Final[pathlib.Path] = pathlib.Path(*args) - - def __fspath__(self) -> str: - return self._path.__fspath__() - - if sys.version_info >= (3, 15): - - def __vfspath__(self) -> str: - return self._path.__vfspath__() - - def __str__(self) -> str: - return self._path.__str__() - - def __repr__(self) -> str: - return f"{self.__class__.__name__}({self.as_posix()!r})" - - def __bytes__(self) -> bytes: - return self._path.__bytes__() - - def __hash__(self) -> int: - return self._path.__hash__() - - def __eq__(self, other: object) -> bool: - target = other._path if isinstance(other, Path) else other - return self._path.__eq__(target) - - def __lt__(self, other: pathlib.PurePath | Path) -> bool: - target = other._path if isinstance(other, Path) else other - return self._path.__lt__(target) - - def __le__(self, other: pathlib.PurePath | Path) -> bool: - target = other._path if isinstance(other, Path) else other - return self._path.__le__(target) - - def __gt__(self, other: pathlib.PurePath | Path) -> bool: - target = other._path if isinstance(other, Path) else other - return self._path.__gt__(target) - - def __ge__(self, other: pathlib.PurePath | Path) -> bool: - target = other._path if isinstance(other, Path) else other - return self._path.__ge__(target) - - def __truediv__(self, other: str | PathLike[str]) -> Path: - return Path(self._path / other) - - def __rtruediv__(self, other: str | PathLike[str]) -> Path: - return Path(other) / self - - @property - def parts(self) -> tuple[str, ...]: - return self._path.parts - - @property - def drive(self) -> str: - return self._path.drive - - @property - def root(self) -> str: - return self._path.root - - @property - def anchor(self) -> str: - return self._path.anchor - - @property - def parents(self) -> Sequence[Path]: - return tuple(Path(p) for p in self._path.parents) - - @property - def parent(self) -> Path: - return Path(self._path.parent) - - @property - def name(self) -> str: - return self._path.name - - @property - def suffix(self) -> str: - return self._path.suffix - - @property - def suffixes(self) -> list[str]: - return self._path.suffixes - - @property - def stem(self) -> str: - return self._path.stem - - async def absolute(self) -> Path: - path = await to_thread.run_sync(self._path.absolute) - return Path(path) - - def as_posix(self) -> str: - return self._path.as_posix() - - def as_uri(self) -> str: - return self._path.as_uri() - - if sys.version_info >= (3, 13): - parser: ClassVar[ModuleType] = pathlib.Path.parser - - @classmethod - def from_uri(cls, uri: str) -> Path: - return Path(pathlib.Path.from_uri(uri)) - - def full_match( - self, path_pattern: str, *, case_sensitive: bool | None = None - ) -> bool: - return self._path.full_match(path_pattern, case_sensitive=case_sensitive) - - def match( - self, path_pattern: str, *, case_sensitive: bool | None = None - ) -> bool: - return self._path.match(path_pattern, case_sensitive=case_sensitive) - else: - - def match(self, path_pattern: str) -> bool: - return self._path.match(path_pattern) - - if sys.version_info >= (3, 14): - - @property - def info(self) -> Any: # TODO: add return type annotation when Typeshed gets it - return self._path.info - - async def copy( - self, - target: str | os.PathLike[str], - *, - follow_symlinks: bool = True, - preserve_metadata: bool = False, - ) -> Path: - func = partial( - self._path.copy, - follow_symlinks=follow_symlinks, - preserve_metadata=preserve_metadata, - ) - return Path(await to_thread.run_sync(func, pathlib.Path(target))) - - async def copy_into( - self, - target_dir: str | os.PathLike[str], - *, - follow_symlinks: bool = True, - preserve_metadata: bool = False, - ) -> Path: - func = partial( - self._path.copy_into, - follow_symlinks=follow_symlinks, - preserve_metadata=preserve_metadata, - ) - return Path(await to_thread.run_sync(func, pathlib.Path(target_dir))) - - async def move(self, target: str | os.PathLike[str]) -> Path: - # Upstream does not handle anyio.Path properly as a PathLike - target = pathlib.Path(target) - return Path(await to_thread.run_sync(self._path.move, target)) - - async def move_into( - self, - target_dir: str | os.PathLike[str], - ) -> Path: - return Path(await to_thread.run_sync(self._path.move_into, target_dir)) - - def is_relative_to(self, other: str | PathLike[str]) -> bool: - try: - self.relative_to(other) - return True - except ValueError: - return False - - async def chmod(self, mode: int, *, follow_symlinks: bool = True) -> None: - func = partial(os.chmod, follow_symlinks=follow_symlinks) - return await to_thread.run_sync(func, self._path, mode) - - @classmethod - async def cwd(cls) -> Path: - path = await to_thread.run_sync(pathlib.Path.cwd) - return cls(path) - - async def exists(self) -> bool: - return await to_thread.run_sync(self._path.exists, abandon_on_cancel=True) - - async def expanduser(self) -> Path: - return Path( - await to_thread.run_sync(self._path.expanduser, abandon_on_cancel=True) - ) - - if sys.version_info < (3, 12): - # Python 3.11 and earlier - def glob(self, pattern: str) -> AsyncIterator[Path]: - gen = self._path.glob(pattern) - return _PathIterator(gen) - elif (3, 12) <= sys.version_info < (3, 13): - # changed in Python 3.12: - # - The case_sensitive parameter was added. - def glob( - self, - pattern: str, - *, - case_sensitive: bool | None = None, - ) -> AsyncIterator[Path]: - gen = self._path.glob(pattern, case_sensitive=case_sensitive) - return _PathIterator(gen) - elif sys.version_info >= (3, 13): - # Changed in Python 3.13: - # - The recurse_symlinks parameter was added. - # - The pattern parameter accepts a path-like object. - def glob( # type: ignore[misc] # mypy doesn't allow for differing signatures in a conditional block - self, - pattern: str | PathLike[str], - *, - case_sensitive: bool | None = None, - recurse_symlinks: bool = False, - ) -> AsyncIterator[Path]: - gen = self._path.glob( - pattern, # type: ignore[arg-type] - case_sensitive=case_sensitive, - recurse_symlinks=recurse_symlinks, - ) - return _PathIterator(gen) - - async def group(self) -> str: - return await to_thread.run_sync(self._path.group, abandon_on_cancel=True) - - async def hardlink_to( - self, target: str | bytes | PathLike[str] | PathLike[bytes] - ) -> None: - if isinstance(target, Path): - target = target._path - - await to_thread.run_sync(os.link, target, self) - - @classmethod - async def home(cls) -> Path: - home_path = await to_thread.run_sync(pathlib.Path.home) - return cls(home_path) - - def is_absolute(self) -> bool: - return self._path.is_absolute() - - async def is_block_device(self) -> bool: - return await to_thread.run_sync( - self._path.is_block_device, abandon_on_cancel=True - ) - - async def is_char_device(self) -> bool: - return await to_thread.run_sync( - self._path.is_char_device, abandon_on_cancel=True - ) - - async def is_dir(self) -> bool: - return await to_thread.run_sync(self._path.is_dir, abandon_on_cancel=True) - - async def is_fifo(self) -> bool: - return await to_thread.run_sync(self._path.is_fifo, abandon_on_cancel=True) - - async def is_file(self) -> bool: - return await to_thread.run_sync(self._path.is_file, abandon_on_cancel=True) - - if sys.version_info >= (3, 12): - - async def is_junction(self) -> bool: - return await to_thread.run_sync(self._path.is_junction) - - async def is_mount(self) -> bool: - return await to_thread.run_sync( - os.path.ismount, self._path, abandon_on_cancel=True - ) - - if sys.version_info < (3, 15): - - def is_reserved(self) -> bool: - return self._path.is_reserved() - - async def is_socket(self) -> bool: - return await to_thread.run_sync(self._path.is_socket, abandon_on_cancel=True) - - async def is_symlink(self) -> bool: - return await to_thread.run_sync(self._path.is_symlink, abandon_on_cancel=True) - - async def iterdir(self) -> AsyncIterator[Path]: - gen = ( - self._path.iterdir() - if sys.version_info < (3, 13) - else await to_thread.run_sync(self._path.iterdir, abandon_on_cancel=True) - ) - async for path in _PathIterator(gen): - yield path - - def joinpath(self, *args: str | PathLike[str]) -> Path: - return Path(self._path.joinpath(*args)) - - async def lchmod(self, mode: int) -> None: - await to_thread.run_sync(self._path.lchmod, mode) - - async def lstat(self) -> os.stat_result: - return await to_thread.run_sync(self._path.lstat, abandon_on_cancel=True) - - async def mkdir( - self, mode: int = 0o777, parents: bool = False, exist_ok: bool = False - ) -> None: - await to_thread.run_sync(self._path.mkdir, mode, parents, exist_ok) - - @overload - async def open( - self, - mode: OpenBinaryMode, - buffering: int = ..., - encoding: str | None = ..., - errors: str | None = ..., - newline: str | None = ..., - ) -> AsyncFile[bytes]: ... - - @overload - async def open( - self, - mode: OpenTextMode = ..., - buffering: int = ..., - encoding: str | None = ..., - errors: str | None = ..., - newline: str | None = ..., - ) -> AsyncFile[str]: ... - - async def open( - self, - mode: str = "r", - buffering: int = -1, - encoding: str | None = None, - errors: str | None = None, - newline: str | None = None, - ) -> AsyncFile[Any]: - fp = await to_thread.run_sync( - self._path.open, mode, buffering, encoding, errors, newline - ) - return AsyncFile(fp) - - async def owner(self) -> str: - return await to_thread.run_sync(self._path.owner, abandon_on_cancel=True) - - async def read_bytes(self) -> bytes: - return await to_thread.run_sync(self._path.read_bytes) - - async def read_text( - self, encoding: str | None = None, errors: str | None = None - ) -> str: - return await to_thread.run_sync(self._path.read_text, encoding, errors) - - if sys.version_info >= (3, 12): - - def relative_to( - self, *other: str | PathLike[str], walk_up: bool = False - ) -> Path: - # relative_to() should work with any PathLike but it doesn't - others = [pathlib.Path(other) for other in other] - return Path(self._path.relative_to(*others, walk_up=walk_up)) - - else: - - def relative_to(self, *other: str | PathLike[str]) -> Path: - return Path(self._path.relative_to(*other)) - - async def readlink(self) -> Path: - target = await to_thread.run_sync(os.readlink, self._path) - return Path(target) - - async def rename(self, target: str | pathlib.PurePath | Path) -> Path: - if isinstance(target, Path): - target = target._path - - await to_thread.run_sync(self._path.rename, target) - return Path(target) - - async def replace(self, target: str | pathlib.PurePath | Path) -> Path: - if isinstance(target, Path): - target = target._path - - await to_thread.run_sync(self._path.replace, target) - return Path(target) - - async def resolve(self, strict: bool = False) -> Path: - func = partial(self._path.resolve, strict=strict) - return Path(await to_thread.run_sync(func, abandon_on_cancel=True)) - - if sys.version_info < (3, 12): - # Pre Python 3.12 - def rglob(self, pattern: str) -> AsyncIterator[Path]: - gen = self._path.rglob(pattern) - return _PathIterator(gen) - elif (3, 12) <= sys.version_info < (3, 13): - # Changed in Python 3.12: - # - The case_sensitive parameter was added. - def rglob( - self, pattern: str, *, case_sensitive: bool | None = None - ) -> AsyncIterator[Path]: - gen = self._path.rglob(pattern, case_sensitive=case_sensitive) - return _PathIterator(gen) - elif sys.version_info >= (3, 13): - # Changed in Python 3.13: - # - The recurse_symlinks parameter was added. - # - The pattern parameter accepts a path-like object. - def rglob( # type: ignore[misc] # mypy doesn't allow for differing signatures in a conditional block - self, - pattern: str | PathLike[str], - *, - case_sensitive: bool | None = None, - recurse_symlinks: bool = False, - ) -> AsyncIterator[Path]: - gen = self._path.rglob( - pattern, # type: ignore[arg-type] - case_sensitive=case_sensitive, - recurse_symlinks=recurse_symlinks, - ) - return _PathIterator(gen) - - async def rmdir(self) -> None: - await to_thread.run_sync(self._path.rmdir) - - async def samefile(self, other_path: str | PathLike[str]) -> bool: - if isinstance(other_path, Path): - other_path = other_path._path - - return await to_thread.run_sync( - self._path.samefile, other_path, abandon_on_cancel=True - ) - - async def stat(self, *, follow_symlinks: bool = True) -> os.stat_result: - func = partial(os.stat, follow_symlinks=follow_symlinks) - return await to_thread.run_sync(func, self._path, abandon_on_cancel=True) - - async def symlink_to( - self, - target: str | bytes | PathLike[str] | PathLike[bytes], - target_is_directory: bool = False, - ) -> None: - if isinstance(target, Path): - target = target._path - - await to_thread.run_sync(self._path.symlink_to, target, target_is_directory) - - async def touch(self, mode: int = 0o666, exist_ok: bool = True) -> None: - await to_thread.run_sync(self._path.touch, mode, exist_ok) - - async def unlink(self, missing_ok: bool = False) -> None: - try: - await to_thread.run_sync(self._path.unlink) - except FileNotFoundError: - if not missing_ok: - raise - - if sys.version_info >= (3, 12): - - async def walk( - self, - top_down: bool = True, - on_error: Callable[[OSError], object] | None = None, - follow_symlinks: bool = False, - ) -> AsyncIterator[tuple[Path, list[str], list[str]]]: - def get_next_value() -> tuple[pathlib.Path, list[str], list[str]] | None: - try: - return next(gen) - except StopIteration: - return None - - gen = self._path.walk(top_down, on_error, follow_symlinks) - while True: - value = await to_thread.run_sync(get_next_value) - if value is None: - return - - root, dirs, paths = value - yield Path(root), dirs, paths - - def with_name(self, name: str) -> Path: - return Path(self._path.with_name(name)) - - def with_stem(self, stem: str) -> Path: - return Path(self._path.with_name(stem + self._path.suffix)) - - def with_suffix(self, suffix: str) -> Path: - return Path(self._path.with_suffix(suffix)) - - def with_segments(self, *pathsegments: str | PathLike[str]) -> Path: - return Path(*pathsegments) - - async def write_bytes(self, data: bytes) -> int: - return await to_thread.run_sync(self._path.write_bytes, data) - - async def write_text( - self, - data: str, - encoding: str | None = None, - errors: str | None = None, - newline: str | None = None, - ) -> int: - return await to_thread.run_sync( - self._path.write_text, data, encoding, errors, newline - ) - - -PathLike.register(Path) diff --git a/.venv/lib/python3.12/site-packages/anyio/_core/_resources.py b/.venv/lib/python3.12/site-packages/anyio/_core/_resources.py deleted file mode 100644 index b9a5344..0000000 --- a/.venv/lib/python3.12/site-packages/anyio/_core/_resources.py +++ /dev/null @@ -1,18 +0,0 @@ -from __future__ import annotations - -from ..abc import AsyncResource -from ._tasks import CancelScope - - -async def aclose_forcefully(resource: AsyncResource) -> None: - """ - Close an asynchronous resource in a cancelled scope. - - Doing this closes the resource without waiting on anything. - - :param resource: the resource to close - - """ - with CancelScope() as scope: - scope.cancel() - await resource.aclose() diff --git a/.venv/lib/python3.12/site-packages/anyio/_core/_signals.py b/.venv/lib/python3.12/site-packages/anyio/_core/_signals.py deleted file mode 100644 index e24c79e..0000000 --- a/.venv/lib/python3.12/site-packages/anyio/_core/_signals.py +++ /dev/null @@ -1,29 +0,0 @@ -from __future__ import annotations - -from collections.abc import AsyncIterator -from contextlib import AbstractContextManager -from signal import Signals - -from ._eventloop import get_async_backend - - -def open_signal_receiver( - *signals: Signals, -) -> AbstractContextManager[AsyncIterator[Signals]]: - """ - Start receiving operating system signals. - - :param signals: signals to receive (e.g. ``signal.SIGINT``) - :return: an asynchronous context manager for an asynchronous iterator which yields - signal numbers - :raises NoEventLoopError: if no supported asynchronous event loop is running in the - current thread - - .. warning:: Windows does not support signals natively so it is best to avoid - relying on this in cross-platform applications. - - .. warning:: On asyncio, this permanently replaces any previous signal handler for - the given signals, as set via :meth:`~asyncio.loop.add_signal_handler`. - - """ - return get_async_backend().open_signal_receiver(*signals) diff --git a/.venv/lib/python3.12/site-packages/anyio/_core/_sockets.py b/.venv/lib/python3.12/site-packages/anyio/_core/_sockets.py deleted file mode 100644 index 6c99b3a..0000000 --- a/.venv/lib/python3.12/site-packages/anyio/_core/_sockets.py +++ /dev/null @@ -1,1003 +0,0 @@ -from __future__ import annotations - -import errno -import os -import socket -import ssl -import stat -import sys -from collections.abc import Awaitable -from dataclasses import dataclass -from ipaddress import IPv4Address, IPv6Address, ip_address -from os import PathLike, chmod -from socket import AddressFamily, SocketKind -from typing import TYPE_CHECKING, Any, Literal, cast, overload - -from .. import ConnectionFailed, to_thread -from ..abc import ( - ByteStreamConnectable, - ConnectedUDPSocket, - ConnectedUNIXDatagramSocket, - IPAddressType, - IPSockAddrType, - SocketListener, - SocketStream, - UDPSocket, - UNIXDatagramSocket, - UNIXSocketStream, -) -from ..streams.stapled import MultiListener -from ..streams.tls import TLSConnectable, TLSStream -from ._eventloop import get_async_backend -from ._resources import aclose_forcefully -from ._synchronization import Event -from ._tasks import create_task_group, move_on_after - -if TYPE_CHECKING: - from _typeshed import FileDescriptorLike -else: - FileDescriptorLike = object - -if sys.version_info < (3, 11): - from exceptiongroup import ExceptionGroup - -if sys.version_info >= (3, 12): - from typing import override -else: - from typing_extensions import override - -if sys.version_info < (3, 13): - from typing_extensions import deprecated -else: - from warnings import deprecated - -IPPROTO_IPV6 = getattr(socket, "IPPROTO_IPV6", 41) # https://bugs.python.org/issue29515 - -AnyIPAddressFamily = Literal[ - AddressFamily.AF_UNSPEC, AddressFamily.AF_INET, AddressFamily.AF_INET6 -] -IPAddressFamily = Literal[AddressFamily.AF_INET, AddressFamily.AF_INET6] - - -# tls_hostname given -@overload -async def connect_tcp( - remote_host: IPAddressType, - remote_port: int, - *, - local_host: IPAddressType | None = ..., - ssl_context: ssl.SSLContext | None = ..., - tls_standard_compatible: bool = ..., - tls_hostname: str, - happy_eyeballs_delay: float = ..., -) -> TLSStream: ... - - -# ssl_context given -@overload -async def connect_tcp( - remote_host: IPAddressType, - remote_port: int, - *, - local_host: IPAddressType | None = ..., - ssl_context: ssl.SSLContext, - tls_standard_compatible: bool = ..., - tls_hostname: str | None = ..., - happy_eyeballs_delay: float = ..., -) -> TLSStream: ... - - -# tls=True -@overload -async def connect_tcp( - remote_host: IPAddressType, - remote_port: int, - *, - local_host: IPAddressType | None = ..., - tls: Literal[True], - ssl_context: ssl.SSLContext | None = ..., - tls_standard_compatible: bool = ..., - tls_hostname: str | None = ..., - happy_eyeballs_delay: float = ..., -) -> TLSStream: ... - - -# tls=False -@overload -async def connect_tcp( - remote_host: IPAddressType, - remote_port: int, - *, - local_host: IPAddressType | None = ..., - tls: Literal[False], - ssl_context: ssl.SSLContext | None = ..., - tls_standard_compatible: bool = ..., - tls_hostname: str | None = ..., - happy_eyeballs_delay: float = ..., -) -> SocketStream: ... - - -# No TLS arguments -@overload -async def connect_tcp( - remote_host: IPAddressType, - remote_port: int, - *, - local_host: IPAddressType | None = ..., - happy_eyeballs_delay: float = ..., -) -> SocketStream: ... - - -async def connect_tcp( - remote_host: IPAddressType, - remote_port: int, - *, - local_host: IPAddressType | None = None, - tls: bool = False, - ssl_context: ssl.SSLContext | None = None, - tls_standard_compatible: bool = True, - tls_hostname: str | None = None, - happy_eyeballs_delay: float = 0.25, -) -> SocketStream | TLSStream: - """ - Connect to a host using the TCP protocol. - - This function implements the stateless version of the Happy Eyeballs algorithm (RFC - 6555). If ``remote_host`` is a host name that resolves to multiple IP addresses, - each one is tried until one connection attempt succeeds. If the first attempt does - not connected within 250 milliseconds, a second attempt is started using the next - address in the list, and so on. On IPv6 enabled systems, an IPv6 address (if - available) is tried first. - - When the connection has been established, a TLS handshake will be done if either - ``ssl_context`` or ``tls_hostname`` is not ``None``, or if ``tls`` is ``True``. - - :param remote_host: the IP address or host name to connect to - :param remote_port: port on the target host to connect to - :param local_host: the interface address or name to bind the socket to before - connecting - :param tls: ``True`` to do a TLS handshake with the connected stream and return a - :class:`~anyio.streams.tls.TLSStream` instead - :param ssl_context: the SSL context object to use (if omitted, a default context is - created) - :param tls_standard_compatible: If ``True``, performs the TLS shutdown handshake - before closing the stream and requires that the server does this as well. - Otherwise, :exc:`~ssl.SSLEOFError` may be raised during reads from the stream. - Some protocols, such as HTTP, require this option to be ``False``. - See :meth:`~ssl.SSLContext.wrap_socket` for details. - :param tls_hostname: host name to check the server certificate against (defaults to - the value of ``remote_host``) - :param happy_eyeballs_delay: delay (in seconds) before starting the next connection - attempt - :return: a socket stream object if no TLS handshake was done, otherwise a TLS stream - :raises ConnectionFailed: if the connection fails - - """ - # Placed here due to https://github.com/python/mypy/issues/7057 - connected_stream: SocketStream | None = None - - async def try_connect(remote_host: str, event: Event) -> None: - nonlocal connected_stream - try: - stream = await asynclib.connect_tcp(remote_host, remote_port, local_address) - except OSError as exc: - oserrors.append(exc) - return - else: - if connected_stream is None: - connected_stream = stream - tg.cancel_scope.cancel() - else: - await stream.aclose() - finally: - event.set() - - asynclib = get_async_backend() - local_address: IPSockAddrType | None = None - family = socket.AF_UNSPEC - if local_host: - gai_res = await getaddrinfo(str(local_host), None) - family, *_, local_address = gai_res[0] - - target_host = str(remote_host) - try: - addr_obj = ip_address(remote_host) - except ValueError: - addr_obj = None - - if addr_obj is not None: - if isinstance(addr_obj, IPv6Address): - target_addrs = [(socket.AF_INET6, addr_obj.compressed)] - else: - target_addrs = [(socket.AF_INET, addr_obj.compressed)] - else: - # getaddrinfo() will raise an exception if name resolution fails - gai_res = await getaddrinfo( - target_host, remote_port, family=family, type=socket.SOCK_STREAM - ) - - # Organize the list so that the first address is an IPv6 address (if available) - # and the second one is an IPv4 addresses. The rest can be in whatever order. - v6_found = v4_found = False - target_addrs = [] - for af, *_, sa in gai_res: - if af == socket.AF_INET6 and not v6_found: - v6_found = True - target_addrs.insert(0, (af, sa[0])) - elif af == socket.AF_INET and not v4_found and v6_found: - v4_found = True - target_addrs.insert(1, (af, sa[0])) - else: - target_addrs.append((af, sa[0])) - - oserrors: list[OSError] = [] - try: - async with create_task_group() as tg: - for _af, addr in target_addrs: - event = Event() - tg.start_soon(try_connect, addr, event) - with move_on_after(happy_eyeballs_delay): - await event.wait() - - if connected_stream is None: - cause = ( - oserrors[0] - if len(oserrors) == 1 - else ExceptionGroup("multiple connection attempts failed", oserrors) - ) - raise OSError("All connection attempts failed") from cause - finally: - oserrors.clear() - - if tls or tls_hostname or ssl_context: - try: - return await TLSStream.wrap( - connected_stream, - server_side=False, - hostname=tls_hostname or str(remote_host), - ssl_context=ssl_context, - standard_compatible=tls_standard_compatible, - ) - except BaseException: - await aclose_forcefully(connected_stream) - raise - - return connected_stream - - -async def connect_unix(path: str | bytes | PathLike[Any]) -> UNIXSocketStream: - """ - Connect to the given UNIX socket. - - Not available on Windows. - - :param path: path to the socket - :return: a socket stream object - :raises ConnectionFailed: if the connection fails - - """ - path = os.fspath(path) - return await get_async_backend().connect_unix(path) - - -async def create_tcp_listener( - *, - local_host: IPAddressType | None = None, - local_port: int = 0, - family: AnyIPAddressFamily = socket.AddressFamily.AF_UNSPEC, - backlog: int = 65536, - reuse_port: bool = False, -) -> MultiListener[SocketStream]: - """ - Create a TCP socket listener. - - :param local_port: port number to listen on - :param local_host: IP address of the interface to listen on. If omitted, listen on - all IPv4 and IPv6 interfaces. To listen on all interfaces on a specific address - family, use ``0.0.0.0`` for IPv4 or ``::`` for IPv6. - :param family: address family (used if ``local_host`` was omitted) - :param backlog: maximum number of queued incoming connections (up to a maximum of - 2**16, or 65536) - :param reuse_port: ``True`` to allow multiple sockets to bind to the same - address/port (not supported on Windows) - :return: a multi-listener object containing one or more socket listeners - :raises OSError: if there's an error creating a socket, or binding to one or more - interfaces failed - - """ - asynclib = get_async_backend() - backlog = min(backlog, 65536) - local_host = str(local_host) if local_host is not None else None - - def setup_raw_socket( - fam: AddressFamily, - bind_addr: tuple[str, int] | tuple[str, int, int, int], - *, - v6only: bool = True, - ) -> socket.socket: - sock = socket.socket(fam) - try: - sock.setblocking(False) - - if fam == AddressFamily.AF_INET6: - sock.setsockopt(IPPROTO_IPV6, socket.IPV6_V6ONLY, v6only) - - # For Windows, enable exclusive address use. For others, enable address - # reuse. - if sys.platform == "win32": - sock.setsockopt(socket.SOL_SOCKET, socket.SO_EXCLUSIVEADDRUSE, 1) - else: - sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - - if reuse_port: - sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1) - - # Workaround for #554 - if fam == socket.AF_INET6 and "%" in bind_addr[0]: - addr, scope_id = bind_addr[0].split("%", 1) - bind_addr = (addr, bind_addr[1], 0, int(scope_id)) - - sock.bind(bind_addr) - sock.listen(backlog) - except BaseException: - sock.close() - raise - - return sock - - # We passing type=0 on non-Windows platforms as a workaround for a uvloop bug - # where we don't get the correct scope ID for IPv6 link-local addresses when passing - # type=socket.SOCK_STREAM to getaddrinfo(): - # https://github.com/MagicStack/uvloop/issues/539 - gai_res = await getaddrinfo( - local_host, - local_port, - family=family, - type=socket.SOCK_STREAM if sys.platform == "win32" else 0, - flags=socket.AI_PASSIVE | socket.AI_ADDRCONFIG, - ) - - # The set comprehension is here to work around a glibc bug: - # https://sourceware.org/bugzilla/show_bug.cgi?id=14969 - sockaddrs = sorted({res for res in gai_res if res[1] == SocketKind.SOCK_STREAM}) - - # Special case for dual-stack binding on the "any" interface - if ( - local_host is None - and family == AddressFamily.AF_UNSPEC - and socket.has_dualstack_ipv6() - and any(fam == AddressFamily.AF_INET6 for fam, *_ in gai_res) - ): - raw_socket = setup_raw_socket( - AddressFamily.AF_INET6, ("::", local_port), v6only=False - ) - listener = asynclib.create_tcp_listener(raw_socket) - return MultiListener([listener]) - - errors: list[OSError] = [] - try: - for _ in range(len(sockaddrs)): - listeners: list[SocketListener] = [] - bound_ephemeral_port = local_port - try: - for fam, *_, sockaddr in sockaddrs: - sockaddr = sockaddr[0], bound_ephemeral_port, *sockaddr[2:] - raw_socket = setup_raw_socket(fam, sockaddr) - - # Store the assigned port if an ephemeral port was requested, so - # we'll bind to the same port on all interfaces - if local_port == 0 and len(gai_res) > 1: - bound_ephemeral_port = raw_socket.getsockname()[1] - - listeners.append(asynclib.create_tcp_listener(raw_socket)) - except BaseException as exc: - for listener in listeners: - await listener.aclose() - - # If an ephemeral port was requested but binding the assigned port - # failed for another interface, rotate the address list and try again - if ( - isinstance(exc, OSError) - and exc.errno == errno.EADDRINUSE - and local_port == 0 - and bound_ephemeral_port - ): - errors.append(exc) - sockaddrs.append(sockaddrs.pop(0)) - continue - - raise - - return MultiListener(listeners) - - raise OSError( - f"Could not create {len(sockaddrs)} listeners with a consistent port" - ) from ExceptionGroup("Several bind attempts failed", errors) - finally: - del errors # Prevent reference cycles - - -async def create_unix_listener( - path: str | bytes | PathLike[Any], - *, - mode: int | None = None, - backlog: int = 65536, -) -> SocketListener: - """ - Create a UNIX socket listener. - - Not available on Windows. - - :param path: path of the socket - :param mode: permissions to set on the socket - :param backlog: maximum number of queued incoming connections (up to a maximum of - 2**16, or 65536) - :return: a listener object - - .. versionchanged:: 3.0 - If a socket already exists on the file system in the given path, it will be - removed first. - - """ - backlog = min(backlog, 65536) - raw_socket = await setup_unix_local_socket(path, mode, socket.SOCK_STREAM) - try: - raw_socket.listen(backlog) - return get_async_backend().create_unix_listener(raw_socket) - except BaseException: - raw_socket.close() - raise - - -async def create_udp_socket( - family: AnyIPAddressFamily = AddressFamily.AF_UNSPEC, - *, - local_host: IPAddressType | None = None, - local_port: int = 0, - reuse_port: bool = False, -) -> UDPSocket: - """ - Create a UDP socket. - - If ``port`` has been given, the socket will be bound to this port on the local - machine, making this socket suitable for providing UDP based services. - - :param family: address family (``AF_INET`` or ``AF_INET6``) – automatically - determined from ``local_host`` if omitted - :param local_host: IP address or host name of the local interface to bind to - :param local_port: local port to bind to - :param reuse_port: ``True`` to allow multiple sockets to bind to the same - address/port (not supported on Windows) - :return: a UDP socket - - """ - if family is AddressFamily.AF_UNSPEC and not local_host: - raise ValueError('Either "family" or "local_host" must be given') - - if local_host: - gai_res = await getaddrinfo( - str(local_host), - local_port, - family=family, - type=socket.SOCK_DGRAM, - flags=socket.AI_PASSIVE | socket.AI_ADDRCONFIG, - ) - family = cast(AnyIPAddressFamily, gai_res[0][0]) - local_address = gai_res[0][-1] - elif family is AddressFamily.AF_INET6: - local_address = ("::", 0) - else: - local_address = ("0.0.0.0", 0) - - sock = await get_async_backend().create_udp_socket( - family, local_address, None, reuse_port - ) - return cast(UDPSocket, sock) - - -async def create_connected_udp_socket( - remote_host: IPAddressType, - remote_port: int, - *, - family: AnyIPAddressFamily = AddressFamily.AF_UNSPEC, - local_host: IPAddressType | None = None, - local_port: int = 0, - reuse_port: bool = False, -) -> ConnectedUDPSocket: - """ - Create a connected UDP socket. - - Connected UDP sockets can only communicate with the specified remote host/port, an - any packets sent from other sources are dropped. - - :param remote_host: remote host to set as the default target - :param remote_port: port on the remote host to set as the default target - :param family: address family (``AF_INET`` or ``AF_INET6``) – automatically - determined from ``local_host`` or ``remote_host`` if omitted - :param local_host: IP address or host name of the local interface to bind to - :param local_port: local port to bind to - :param reuse_port: ``True`` to allow multiple sockets to bind to the same - address/port (not supported on Windows) - :return: a connected UDP socket - - """ - local_address = None - if local_host: - gai_res = await getaddrinfo( - str(local_host), - local_port, - family=family, - type=socket.SOCK_DGRAM, - flags=socket.AI_PASSIVE | socket.AI_ADDRCONFIG, - ) - family = cast(AnyIPAddressFamily, gai_res[0][0]) - local_address = gai_res[0][-1] - - gai_res = await getaddrinfo( - str(remote_host), remote_port, family=family, type=socket.SOCK_DGRAM - ) - family = cast(AnyIPAddressFamily, gai_res[0][0]) - remote_address = gai_res[0][-1] - - sock = await get_async_backend().create_udp_socket( - family, local_address, remote_address, reuse_port - ) - return cast(ConnectedUDPSocket, sock) - - -async def create_unix_datagram_socket( - *, - local_path: None | str | bytes | PathLike[Any] = None, - local_mode: int | None = None, -) -> UNIXDatagramSocket: - """ - Create a UNIX datagram socket. - - Not available on Windows. - - If ``local_path`` has been given, the socket will be bound to this path, making this - socket suitable for receiving datagrams from other processes. Other processes can - send datagrams to this socket only if ``local_path`` is set. - - If a socket already exists on the file system in the ``local_path``, it will be - removed first. - - :param local_path: the path on which to bind to - :param local_mode: permissions to set on the local socket - :return: a UNIX datagram socket - - """ - raw_socket = await setup_unix_local_socket( - local_path, local_mode, socket.SOCK_DGRAM - ) - return await get_async_backend().create_unix_datagram_socket(raw_socket, None) - - -async def create_connected_unix_datagram_socket( - remote_path: str | bytes | PathLike[Any], - *, - local_path: None | str | bytes | PathLike[Any] = None, - local_mode: int | None = None, -) -> ConnectedUNIXDatagramSocket: - """ - Create a connected UNIX datagram socket. - - Connected datagram sockets can only communicate with the specified remote path. - - If ``local_path`` has been given, the socket will be bound to this path, making - this socket suitable for receiving datagrams from other processes. Other processes - can send datagrams to this socket only if ``local_path`` is set. - - If a socket already exists on the file system in the ``local_path``, it will be - removed first. - - :param remote_path: the path to set as the default target - :param local_path: the path on which to bind to - :param local_mode: permissions to set on the local socket - :return: a connected UNIX datagram socket - - """ - remote_path = os.fspath(remote_path) - raw_socket = await setup_unix_local_socket( - local_path, local_mode, socket.SOCK_DGRAM - ) - return await get_async_backend().create_unix_datagram_socket( - raw_socket, remote_path - ) - - -async def getaddrinfo( - host: bytes | str | None, - port: str | int | None, - *, - family: int | AddressFamily = 0, - type: int | SocketKind = 0, - proto: int = 0, - flags: int = 0, -) -> list[tuple[AddressFamily, SocketKind, int, str, tuple[str, int]]]: - """ - Look up a numeric IP address given a host name. - - Internationalized domain names are translated according to the (non-transitional) - IDNA 2008 standard. - - .. note:: 4-tuple IPv6 socket addresses are automatically converted to 2-tuples of - (host, port), unlike what :func:`socket.getaddrinfo` does. - - :param host: host name - :param port: port number - :param family: socket family (`'AF_INET``, ...) - :param type: socket type (``SOCK_STREAM``, ...) - :param proto: protocol number - :param flags: flags to pass to upstream ``getaddrinfo()`` - :return: list of tuples containing (family, type, proto, canonname, sockaddr) - - .. seealso:: :func:`socket.getaddrinfo` - - """ - # Handle unicode hostnames - if isinstance(host, str): - try: - encoded_host: bytes | None = host.encode("ascii") - except UnicodeEncodeError: - import idna - - encoded_host = idna.encode(host, uts46=True) - else: - encoded_host = host - - gai_res = await get_async_backend().getaddrinfo( - encoded_host, port, family=family, type=type, proto=proto, flags=flags - ) - return [ - (family, type, proto, canonname, convert_ipv6_sockaddr(sockaddr)) - for family, type, proto, canonname, sockaddr in gai_res - # filter out IPv6 results when IPv6 is disabled - if not isinstance(sockaddr[0], int) - ] - - -def getnameinfo(sockaddr: IPSockAddrType, flags: int = 0) -> Awaitable[tuple[str, str]]: - """ - Look up the host name of an IP address. - - :param sockaddr: socket address (e.g. (ipaddress, port) for IPv4) - :param flags: flags to pass to upstream ``getnameinfo()`` - :return: a tuple of (host name, service name) - :raises NoEventLoopError: if no supported asynchronous event loop is running in the - current thread - - .. seealso:: :func:`socket.getnameinfo` - - """ - return get_async_backend().getnameinfo(sockaddr, flags) - - -@deprecated("This function is deprecated; use `wait_readable` instead") -def wait_socket_readable(sock: socket.socket) -> Awaitable[None]: - """ - .. deprecated:: 4.7.0 - Use :func:`wait_readable` instead. - - Wait until the given socket has data to be read. - - .. warning:: Only use this on raw sockets that have not been wrapped by any higher - level constructs like socket streams! - - :param sock: a socket object - :raises ~anyio.ClosedResourceError: if the socket was closed while waiting for the - socket to become readable - :raises ~anyio.BusyResourceError: if another task is already waiting for the socket - to become readable - :raises NoEventLoopError: if no supported asynchronous event loop is running in the - current thread - - """ - return get_async_backend().wait_readable(sock.fileno()) - - -@deprecated("This function is deprecated; use `wait_writable` instead") -def wait_socket_writable(sock: socket.socket) -> Awaitable[None]: - """ - .. deprecated:: 4.7.0 - Use :func:`wait_writable` instead. - - Wait until the given socket can be written to. - - This does **NOT** work on Windows when using the asyncio backend with a proactor - event loop (default on py3.8+). - - .. warning:: Only use this on raw sockets that have not been wrapped by any higher - level constructs like socket streams! - - :param sock: a socket object - :raises ~anyio.ClosedResourceError: if the socket was closed while waiting for the - socket to become writable - :raises ~anyio.BusyResourceError: if another task is already waiting for the socket - to become writable - :raises NoEventLoopError: if no supported asynchronous event loop is running in the - current thread - - """ - return get_async_backend().wait_writable(sock.fileno()) - - -def wait_readable(obj: FileDescriptorLike) -> Awaitable[None]: - """ - Wait until the given object has data to be read. - - On Unix systems, ``obj`` must either be an integer file descriptor, or else an - object with a ``.fileno()`` method which returns an integer file descriptor. Any - kind of file descriptor can be passed, though the exact semantics will depend on - your kernel. For example, this probably won't do anything useful for on-disk files. - - On Windows systems, ``obj`` must either be an integer ``SOCKET`` handle, or else an - object with a ``.fileno()`` method which returns an integer ``SOCKET`` handle. File - descriptors aren't supported, and neither are handles that refer to anything besides - a ``SOCKET``. - - On backends where this functionality is not natively provided (asyncio - ``ProactorEventLoop`` on Windows), it is provided using a separate selector thread - which is set to shut down when the interpreter shuts down. - - .. warning:: Don't use this on raw sockets that have been wrapped by any higher - level constructs like socket streams! - - :param obj: an object with a ``.fileno()`` method or an integer handle - :raises ~anyio.ClosedResourceError: if the object was closed while waiting for the - object to become readable - :raises ~anyio.BusyResourceError: if another task is already waiting for the object - to become readable - :raises NoEventLoopError: if no supported asynchronous event loop is running in the - current thread - - """ - return get_async_backend().wait_readable(obj) - - -def wait_writable(obj: FileDescriptorLike) -> Awaitable[None]: - """ - Wait until the given object can be written to. - - :param obj: an object with a ``.fileno()`` method or an integer handle - :raises ~anyio.ClosedResourceError: if the object was closed while waiting for the - object to become writable - :raises ~anyio.BusyResourceError: if another task is already waiting for the object - to become writable - :raises NoEventLoopError: if no supported asynchronous event loop is running in the - current thread - - .. seealso:: See the documentation of :func:`wait_readable` for the definition of - ``obj`` and notes on backend compatibility. - - .. warning:: Don't use this on raw sockets that have been wrapped by any higher - level constructs like socket streams! - - """ - return get_async_backend().wait_writable(obj) - - -def notify_closing(obj: FileDescriptorLike) -> None: - """ - Call this before closing a file descriptor (on Unix) or socket (on - Windows). This will cause any `wait_readable` or `wait_writable` - calls on the given object to immediately wake up and raise - `~anyio.ClosedResourceError`. - - This doesn't actually close the object – you still have to do that - yourself afterwards. Also, you want to be careful to make sure no - new tasks start waiting on the object in between when you call this - and when it's actually closed. So to close something properly, you - usually want to do these steps in order: - - 1. Explicitly mark the object as closed, so that any new attempts - to use it will abort before they start. - 2. Call `notify_closing` to wake up any already-existing users. - 3. Actually close the object. - - It's also possible to do them in a different order if that's more - convenient, *but only if* you make sure not to have any checkpoints in - between the steps. This way they all happen in a single atomic - step, so other tasks won't be able to tell what order they happened - in anyway. - - :param obj: an object with a ``.fileno()`` method or an integer handle - :raises NoEventLoopError: if no supported asynchronous event loop is running in the - current thread - - """ - get_async_backend().notify_closing(obj) - - -# -# Private API -# - - -def convert_ipv6_sockaddr( - sockaddr: tuple[str, int, int, int] | tuple[str, int], -) -> tuple[str, int]: - """ - Convert a 4-tuple IPv6 socket address to a 2-tuple (address, port) format. - - If the scope ID is nonzero, it is added to the address, separated with ``%``. - Otherwise the flow id and scope id are simply cut off from the tuple. - Any other kinds of socket addresses are returned as-is. - - :param sockaddr: the result of :meth:`~socket.socket.getsockname` - :return: the converted socket address - - """ - # This is more complicated than it should be because of MyPy - if isinstance(sockaddr, tuple) and len(sockaddr) == 4: - host, port, flowinfo, scope_id = sockaddr - if scope_id: - # PyPy (as of v7.3.11) leaves the interface name in the result, so - # we discard it and only get the scope ID from the end - # (https://foss.heptapod.net/pypy/pypy/-/issues/3938) - host = host.split("%")[0] - - # Add scope_id to the address - return f"{host}%{scope_id}", port - else: - return host, port - else: - return sockaddr - - -async def setup_unix_local_socket( - path: None | str | bytes | PathLike[Any], - mode: int | None, - socktype: int, -) -> socket.socket: - """ - Create a UNIX local socket object, deleting the socket at the given path if it - exists. - - Not available on Windows. - - :param path: path of the socket - :param mode: permissions to set on the socket - :param socktype: socket.SOCK_STREAM or socket.SOCK_DGRAM - - """ - path_str: str | None - if path is not None: - path_str = os.fsdecode(path) - - # Linux abstract namespace sockets aren't backed by a concrete file so skip stat call - if not path_str.startswith("\0"): - # Copied from pathlib... - try: - stat_result = os.stat(path) - except OSError as e: - if e.errno not in ( - errno.ENOENT, - errno.ENOTDIR, - errno.EBADF, - errno.ELOOP, - ): - raise - else: - if stat.S_ISSOCK(stat_result.st_mode): - os.unlink(path) - else: - path_str = None - - raw_socket = socket.socket(socket.AF_UNIX, socktype) - raw_socket.setblocking(False) - - if path_str is not None: - try: - await to_thread.run_sync(raw_socket.bind, path_str, abandon_on_cancel=True) - if mode is not None: - await to_thread.run_sync(chmod, path_str, mode, abandon_on_cancel=True) - except BaseException: - raw_socket.close() - raise - - return raw_socket - - -@dataclass -class TCPConnectable(ByteStreamConnectable): - """ - Connects to a TCP server at the given host and port. - - :param host: host name or IP address of the server - :param port: TCP port number of the server - """ - - host: str | IPv4Address | IPv6Address - port: int - - def __post_init__(self) -> None: - if self.port < 1 or self.port > 65535: - raise ValueError("TCP port number out of range") - - @override - async def connect(self) -> SocketStream: - try: - return await connect_tcp(self.host, self.port) - except OSError as exc: - raise ConnectionFailed( - f"error connecting to {self.host}:{self.port}: {exc}" - ) from exc - - -@dataclass -class UNIXConnectable(ByteStreamConnectable): - """ - Connects to a UNIX domain socket at the given path. - - :param path: the file system path of the socket - """ - - path: str | bytes | PathLike[str] | PathLike[bytes] - - @override - async def connect(self) -> UNIXSocketStream: - try: - return await connect_unix(self.path) - except OSError as exc: - raise ConnectionFailed(f"error connecting to {self.path!r}: {exc}") from exc - - -def as_connectable( - remote: ByteStreamConnectable - | tuple[str | IPv4Address | IPv6Address, int] - | str - | bytes - | PathLike[str], - /, - *, - tls: bool = False, - ssl_context: ssl.SSLContext | None = None, - tls_hostname: str | None = None, - tls_standard_compatible: bool = True, -) -> ByteStreamConnectable: - """ - Return a byte stream connectable from the given object. - - If a bytestream connectable is given, it is returned unchanged. - If a tuple of (host, port) is given, a TCP connectable is returned. - If a string or bytes path is given, a UNIX connectable is returned. - - If ``tls=True``, the connectable will be wrapped in a - :class:`~.streams.tls.TLSConnectable`. - - :param remote: a connectable, a tuple of (host, port) or a path to a UNIX socket - :param tls: if ``True``, wrap the plaintext connectable in a - :class:`~.streams.tls.TLSConnectable`, using the provided TLS settings) - :param ssl_context: if ``tls=True``, the SSLContext object to use (if not provided, - a secure default will be created) - :param tls_hostname: if ``tls=True``, host name of the server to use for checking - the server certificate (defaults to the host portion of the address for TCP - connectables) - :param tls_standard_compatible: if ``False`` and ``tls=True``, makes the TLS stream - skip the closing handshake when closing the connection, so it won't raise an - exception if the server does the same - - """ - connectable: TCPConnectable | UNIXConnectable | TLSConnectable - if isinstance(remote, ByteStreamConnectable): - return remote - elif isinstance(remote, tuple) and len(remote) == 2: - connectable = TCPConnectable(*remote) - elif isinstance(remote, (str, bytes, PathLike)): - connectable = UNIXConnectable(remote) - else: - raise TypeError(f"cannot convert {remote!r} to a connectable") - - if tls: - if not tls_hostname and isinstance(connectable, TCPConnectable): - tls_hostname = str(connectable.host) - - connectable = TLSConnectable( - connectable, - ssl_context=ssl_context, - hostname=tls_hostname, - standard_compatible=tls_standard_compatible, - ) - - return connectable diff --git a/.venv/lib/python3.12/site-packages/anyio/_core/_streams.py b/.venv/lib/python3.12/site-packages/anyio/_core/_streams.py deleted file mode 100644 index 2b9c7df..0000000 --- a/.venv/lib/python3.12/site-packages/anyio/_core/_streams.py +++ /dev/null @@ -1,52 +0,0 @@ -from __future__ import annotations - -import math -from typing import TypeVar -from warnings import warn - -from ..streams.memory import ( - MemoryObjectReceiveStream, - MemoryObjectSendStream, - _MemoryObjectStreamState, -) - -T_Item = TypeVar("T_Item") - - -class create_memory_object_stream( - tuple[MemoryObjectSendStream[T_Item], MemoryObjectReceiveStream[T_Item]], -): - """ - Create a memory object stream. - - The stream's item type can be annotated like - :func:`create_memory_object_stream[T_Item]`. - - :param max_buffer_size: number of items held in the buffer until ``send()`` starts - blocking - :param item_type: old way of marking the streams with the right generic type for - static typing (does nothing on AnyIO 4) - - .. deprecated:: 4.0 - Use ``create_memory_object_stream[YourItemType](...)`` instead. - :return: a tuple of (send stream, receive stream) - - """ - - def __new__( # type: ignore[misc] - cls, max_buffer_size: float = 0, item_type: object = None - ) -> tuple[MemoryObjectSendStream[T_Item], MemoryObjectReceiveStream[T_Item]]: - if max_buffer_size != math.inf and not isinstance(max_buffer_size, int): - raise ValueError("max_buffer_size must be either an integer or math.inf") - if max_buffer_size < 0: - raise ValueError("max_buffer_size cannot be negative") - if item_type is not None: - warn( - "The item_type argument has been deprecated in AnyIO 4.0. " - "Use create_memory_object_stream[YourItemType](...) instead.", - DeprecationWarning, - stacklevel=2, - ) - - state = _MemoryObjectStreamState[T_Item](max_buffer_size) - return (MemoryObjectSendStream(state), MemoryObjectReceiveStream(state)) diff --git a/.venv/lib/python3.12/site-packages/anyio/_core/_subprocesses.py b/.venv/lib/python3.12/site-packages/anyio/_core/_subprocesses.py deleted file mode 100644 index 9796f8b..0000000 --- a/.venv/lib/python3.12/site-packages/anyio/_core/_subprocesses.py +++ /dev/null @@ -1,196 +0,0 @@ -from __future__ import annotations - -from collections.abc import AsyncIterable, Iterable, Mapping, Sequence -from io import BytesIO -from os import PathLike -from subprocess import PIPE, CalledProcessError, CompletedProcess -from typing import IO, Any, TypeAlias, cast - -from ..abc import Process -from ._eventloop import get_async_backend -from ._tasks import create_task_group - -StrOrBytesPath: TypeAlias = str | bytes | PathLike[str] | PathLike[bytes] - - -async def run_process( - command: StrOrBytesPath | Sequence[StrOrBytesPath], - *, - input: bytes | None = None, - stdin: int | IO[Any] | None = None, - stdout: int | IO[Any] | None = PIPE, - stderr: int | IO[Any] | None = PIPE, - check: bool = True, - cwd: StrOrBytesPath | None = None, - env: Mapping[str, str] | None = None, - startupinfo: Any = None, - creationflags: int = 0, - start_new_session: bool = False, - pass_fds: Sequence[int] = (), - user: str | int | None = None, - group: str | int | None = None, - extra_groups: Iterable[str | int] | None = None, - umask: int = -1, -) -> CompletedProcess[bytes]: - """ - Run an external command in a subprocess and wait until it completes. - - .. seealso:: :func:`subprocess.run` - - :param command: either a string to pass to the shell, or an iterable of strings - containing the executable name or path and its arguments - :param input: bytes passed to the standard input of the subprocess - :param stdin: one of :data:`subprocess.PIPE`, :data:`subprocess.DEVNULL`, - a file-like object, or `None`; ``input`` overrides this - :param stdout: one of :data:`subprocess.PIPE`, :data:`subprocess.DEVNULL`, - a file-like object, or `None` - :param stderr: one of :data:`subprocess.PIPE`, :data:`subprocess.DEVNULL`, - :data:`subprocess.STDOUT`, a file-like object, or `None` - :param check: if ``True``, raise :exc:`~subprocess.CalledProcessError` if the - process terminates with a return code other than 0 - :param cwd: If not ``None``, change the working directory to this before running the - command - :param env: if not ``None``, this mapping replaces the inherited environment - variables from the parent process - :param startupinfo: an instance of :class:`subprocess.STARTUPINFO` that can be used - to specify process startup parameters (Windows only) - :param creationflags: flags that can be used to control the creation of the - subprocess (see :class:`subprocess.Popen` for the specifics) - :param start_new_session: if ``true`` the setsid() system call will be made in the - child process prior to the execution of the subprocess. (POSIX only) - :param pass_fds: sequence of file descriptors to keep open between the parent and - child processes. (POSIX only) - :param user: effective user to run the process as (Python >= 3.9, POSIX only) - :param group: effective group to run the process as (Python >= 3.9, POSIX only) - :param extra_groups: supplementary groups to set in the subprocess (Python >= 3.9, - POSIX only) - :param umask: if not negative, this umask is applied in the child process before - running the given command (Python >= 3.9, POSIX only) - :return: an object representing the completed process - :raises ~subprocess.CalledProcessError: if ``check`` is ``True`` and the process - exits with a nonzero return code - - """ - - async def drain_stream(stream: AsyncIterable[bytes], index: int) -> None: - buffer = BytesIO() - async for chunk in stream: - buffer.write(chunk) - - stream_contents[index] = buffer.getvalue() - - if stdin is not None and input is not None: - raise ValueError("only one of stdin and input is allowed") - - async with await open_process( - command, - stdin=PIPE if input else stdin, - stdout=stdout, - stderr=stderr, - cwd=cwd, - env=env, - startupinfo=startupinfo, - creationflags=creationflags, - start_new_session=start_new_session, - pass_fds=pass_fds, - user=user, - group=group, - extra_groups=extra_groups, - umask=umask, - ) as process: - stream_contents: list[bytes | None] = [None, None] - async with create_task_group() as tg: - if process.stdout: - tg.start_soon(drain_stream, process.stdout, 0) - - if process.stderr: - tg.start_soon(drain_stream, process.stderr, 1) - - if process.stdin and input: - await process.stdin.send(input) - await process.stdin.aclose() - - await process.wait() - - output, errors = stream_contents - if check and process.returncode != 0: - raise CalledProcessError(cast(int, process.returncode), command, output, errors) - - return CompletedProcess(command, cast(int, process.returncode), output, errors) - - -async def open_process( - command: StrOrBytesPath | Sequence[StrOrBytesPath], - *, - stdin: int | IO[Any] | None = PIPE, - stdout: int | IO[Any] | None = PIPE, - stderr: int | IO[Any] | None = PIPE, - cwd: StrOrBytesPath | None = None, - env: Mapping[str, str] | None = None, - startupinfo: Any = None, - creationflags: int = 0, - start_new_session: bool = False, - pass_fds: Sequence[int] = (), - user: str | int | None = None, - group: str | int | None = None, - extra_groups: Iterable[str | int] | None = None, - umask: int = -1, -) -> Process: - """ - Start an external command in a subprocess. - - .. seealso:: :class:`subprocess.Popen` - - :param command: either a string to pass to the shell, or an iterable of strings - containing the executable name or path and its arguments - :param stdin: one of :data:`subprocess.PIPE`, :data:`subprocess.DEVNULL`, a - file-like object, or ``None`` - :param stdout: one of :data:`subprocess.PIPE`, :data:`subprocess.DEVNULL`, - a file-like object, or ``None`` - :param stderr: one of :data:`subprocess.PIPE`, :data:`subprocess.DEVNULL`, - :data:`subprocess.STDOUT`, a file-like object, or ``None`` - :param cwd: If not ``None``, the working directory is changed before executing - :param env: If env is not ``None``, it must be a mapping that defines the - environment variables for the new process - :param creationflags: flags that can be used to control the creation of the - subprocess (see :class:`subprocess.Popen` for the specifics) - :param startupinfo: an instance of :class:`subprocess.STARTUPINFO` that can be used - to specify process startup parameters (Windows only) - :param start_new_session: if ``true`` the setsid() system call will be made in the - child process prior to the execution of the subprocess. (POSIX only) - :param pass_fds: sequence of file descriptors to keep open between the parent and - child processes. (POSIX only) - :param user: effective user to run the process as (POSIX only) - :param group: effective group to run the process as (POSIX only) - :param extra_groups: supplementary groups to set in the subprocess (POSIX only) - :param umask: if not negative, this umask is applied in the child process before - running the given command (POSIX only) - :return: an asynchronous process object - - """ - kwargs: dict[str, Any] = {} - if user is not None: - kwargs["user"] = user - - if group is not None: - kwargs["group"] = group - - if extra_groups is not None: - kwargs["extra_groups"] = group - - if umask >= 0: - kwargs["umask"] = umask - - return await get_async_backend().open_process( - command, - stdin=stdin, - stdout=stdout, - stderr=stderr, - cwd=cwd, - env=env, - startupinfo=startupinfo, - creationflags=creationflags, - start_new_session=start_new_session, - pass_fds=pass_fds, - **kwargs, - ) diff --git a/.venv/lib/python3.12/site-packages/anyio/_core/_synchronization.py b/.venv/lib/python3.12/site-packages/anyio/_core/_synchronization.py deleted file mode 100644 index 9c6f9a0..0000000 --- a/.venv/lib/python3.12/site-packages/anyio/_core/_synchronization.py +++ /dev/null @@ -1,757 +0,0 @@ -from __future__ import annotations - -import math -from collections import deque -from collections.abc import Callable -from dataclasses import dataclass -from types import TracebackType -from typing import TypeVar - -from ..lowlevel import checkpoint_if_cancelled -from ._eventloop import get_async_backend -from ._exceptions import BusyResourceError, NoEventLoopError -from ._tasks import CancelScope -from ._testing import TaskInfo, get_current_task - -T = TypeVar("T") - - -@dataclass(frozen=True) -class EventStatistics: - """ - :ivar int tasks_waiting: number of tasks waiting on :meth:`~.Event.wait` - """ - - tasks_waiting: int - - -@dataclass(frozen=True) -class CapacityLimiterStatistics: - """ - :ivar int borrowed_tokens: number of tokens currently borrowed by tasks - :ivar float total_tokens: total number of available tokens - :ivar tuple borrowers: tasks or other objects currently holding tokens borrowed from - this limiter - :ivar int tasks_waiting: number of tasks waiting on - :meth:`~.CapacityLimiter.acquire` or - :meth:`~.CapacityLimiter.acquire_on_behalf_of` - """ - - borrowed_tokens: int - total_tokens: float - borrowers: tuple[object, ...] - tasks_waiting: int - - -@dataclass(frozen=True) -class LockStatistics: - """ - :ivar bool locked: flag indicating if this lock is locked or not - :ivar ~anyio.TaskInfo owner: task currently holding the lock (or ``None`` if the - lock is not held by any task) - :ivar int tasks_waiting: number of tasks waiting on :meth:`~.Lock.acquire` - """ - - locked: bool - owner: TaskInfo | None - tasks_waiting: int - - -@dataclass(frozen=True) -class ConditionStatistics: - """ - :ivar int tasks_waiting: number of tasks blocked on :meth:`~.Condition.wait` - :ivar ~anyio.LockStatistics lock_statistics: statistics of the underlying - :class:`~.Lock` - """ - - tasks_waiting: int - lock_statistics: LockStatistics - - -@dataclass(frozen=True) -class SemaphoreStatistics: - """ - :ivar int tasks_waiting: number of tasks waiting on :meth:`~.Semaphore.acquire` - - """ - - tasks_waiting: int - - -class Event: - def __new__(cls) -> Event: - try: - return get_async_backend().create_event() - except NoEventLoopError: - return EventAdapter() - - def set(self) -> None: - """Set the flag, notifying all listeners.""" - raise NotImplementedError - - def is_set(self) -> bool: - """Return ``True`` if the flag is set, ``False`` if not.""" - raise NotImplementedError - - async def wait(self) -> None: - """ - Wait until the flag has been set. - - If the flag has already been set when this method is called, it returns - immediately. - - """ - raise NotImplementedError - - def statistics(self) -> EventStatistics: - """Return statistics about the current state of this event.""" - raise NotImplementedError - - -class EventAdapter(Event): - _internal_event: Event | None = None - _is_set: bool = False - - def __new__(cls) -> EventAdapter: - return object.__new__(cls) - - @property - def _event(self) -> Event: - if self._internal_event is None: - self._internal_event = get_async_backend().create_event() - if self._is_set: - self._internal_event.set() - - return self._internal_event - - def set(self) -> None: - if self._internal_event is None: - self._is_set = True - else: - self._event.set() - - def is_set(self) -> bool: - if self._internal_event is None: - return self._is_set - - return self._internal_event.is_set() - - async def wait(self) -> None: - await self._event.wait() - - def statistics(self) -> EventStatistics: - if self._internal_event is None: - return EventStatistics(tasks_waiting=0) - - return self._internal_event.statistics() - - -class Lock: - def __new__(cls, *, fast_acquire: bool = False) -> Lock: - try: - return get_async_backend().create_lock(fast_acquire=fast_acquire) - except NoEventLoopError: - return LockAdapter(fast_acquire=fast_acquire) - - async def __aenter__(self) -> None: - await self.acquire() - - async def __aexit__( - self, - exc_type: type[BaseException] | None, - exc_val: BaseException | None, - exc_tb: TracebackType | None, - ) -> None: - self.release() - - async def acquire(self) -> None: - """Acquire the lock.""" - raise NotImplementedError - - def acquire_nowait(self) -> None: - """ - Acquire the lock, without blocking. - - :raises ~anyio.WouldBlock: if the operation would block - - """ - raise NotImplementedError - - def release(self) -> None: - """Release the lock.""" - raise NotImplementedError - - def locked(self) -> bool: - """Return True if the lock is currently held.""" - raise NotImplementedError - - def statistics(self) -> LockStatistics: - """ - Return statistics about the current state of this lock. - - .. versionadded:: 3.0 - """ - raise NotImplementedError - - -class LockAdapter(Lock): - _internal_lock: Lock | None = None - - def __new__(cls, *, fast_acquire: bool = False) -> LockAdapter: - return object.__new__(cls) - - def __init__(self, *, fast_acquire: bool = False): - self._fast_acquire = fast_acquire - - @property - def _lock(self) -> Lock: - if self._internal_lock is None: - self._internal_lock = get_async_backend().create_lock( - fast_acquire=self._fast_acquire - ) - - return self._internal_lock - - async def __aenter__(self) -> None: - await self._lock.acquire() - - async def __aexit__( - self, - exc_type: type[BaseException] | None, - exc_val: BaseException | None, - exc_tb: TracebackType | None, - ) -> None: - if self._internal_lock is not None: - self._internal_lock.release() - - async def acquire(self) -> None: - """Acquire the lock.""" - await self._lock.acquire() - - def acquire_nowait(self) -> None: - """ - Acquire the lock, without blocking. - - :raises ~anyio.WouldBlock: if the operation would block - - """ - self._lock.acquire_nowait() - - def release(self) -> None: - """Release the lock.""" - self._lock.release() - - def locked(self) -> bool: - """Return True if the lock is currently held.""" - return self._lock.locked() - - def statistics(self) -> LockStatistics: - """ - Return statistics about the current state of this lock. - - .. versionadded:: 3.0 - - """ - if self._internal_lock is None: - return LockStatistics(False, None, 0) - - return self._internal_lock.statistics() - - -class Condition: - _owner_task: TaskInfo | None = None - - def __init__(self, lock: Lock | None = None): - self._lock = lock or Lock() - self._waiters: deque[Event] = deque() - - async def __aenter__(self) -> None: - await self.acquire() - - async def __aexit__( - self, - exc_type: type[BaseException] | None, - exc_val: BaseException | None, - exc_tb: TracebackType | None, - ) -> None: - self.release() - - def _check_acquired(self) -> None: - if self._owner_task != get_current_task(): - raise RuntimeError("The current task is not holding the underlying lock") - - async def acquire(self) -> None: - """Acquire the underlying lock.""" - await self._lock.acquire() - self._owner_task = get_current_task() - - def acquire_nowait(self) -> None: - """ - Acquire the underlying lock, without blocking. - - :raises ~anyio.WouldBlock: if the operation would block - - """ - self._lock.acquire_nowait() - self._owner_task = get_current_task() - - def release(self) -> None: - """Release the underlying lock.""" - self._lock.release() - - def locked(self) -> bool: - """Return True if the lock is set.""" - return self._lock.locked() - - def notify(self, n: int = 1) -> None: - """Notify exactly n listeners.""" - self._check_acquired() - for _ in range(n): - try: - event = self._waiters.popleft() - except IndexError: - break - - event.set() - - def notify_all(self) -> None: - """Notify all the listeners.""" - self._check_acquired() - for event in self._waiters: - event.set() - - self._waiters.clear() - - async def wait(self) -> None: - """Wait for a notification.""" - await checkpoint_if_cancelled() - self._check_acquired() - event = Event() - self._waiters.append(event) - self.release() - try: - await event.wait() - except BaseException: - if not event.is_set(): - self._waiters.remove(event) - elif self._waiters: - # This task was notified by could not act on it, so pass - # it on to the next task - self._waiters.popleft().set() - - raise - finally: - with CancelScope(shield=True): - await self.acquire() - - async def wait_for(self, predicate: Callable[[], T]) -> T: - """ - Wait until a predicate becomes true. - - :param predicate: a callable that returns a truthy value when the condition is - met - :return: the result of the predicate - - .. versionadded:: 4.11.0 - - """ - while not (result := predicate()): - await self.wait() - - return result - - def statistics(self) -> ConditionStatistics: - """ - Return statistics about the current state of this condition. - - .. versionadded:: 3.0 - """ - return ConditionStatistics(len(self._waiters), self._lock.statistics()) - - -class Semaphore: - def __new__( - cls, - initial_value: int, - *, - max_value: int | None = None, - fast_acquire: bool = False, - ) -> Semaphore: - try: - return get_async_backend().create_semaphore( - initial_value, max_value=max_value, fast_acquire=fast_acquire - ) - except NoEventLoopError: - return SemaphoreAdapter(initial_value, max_value=max_value) - - def __init__( - self, - initial_value: int, - *, - max_value: int | None = None, - fast_acquire: bool = False, - ): - if not isinstance(initial_value, int): - raise TypeError("initial_value must be an integer") - if initial_value < 0: - raise ValueError("initial_value must be >= 0") - if max_value is not None: - if not isinstance(max_value, int): - raise TypeError("max_value must be an integer or None") - if max_value < initial_value: - raise ValueError( - "max_value must be equal to or higher than initial_value" - ) - - self._fast_acquire = fast_acquire - - async def __aenter__(self) -> Semaphore: - await self.acquire() - return self - - async def __aexit__( - self, - exc_type: type[BaseException] | None, - exc_val: BaseException | None, - exc_tb: TracebackType | None, - ) -> None: - self.release() - - async def acquire(self) -> None: - """Decrement the semaphore value, blocking if necessary.""" - raise NotImplementedError - - def acquire_nowait(self) -> None: - """ - Acquire the underlying lock, without blocking. - - :raises ~anyio.WouldBlock: if the operation would block - - """ - raise NotImplementedError - - def release(self) -> None: - """Increment the semaphore value.""" - raise NotImplementedError - - @property - def value(self) -> int: - """The current value of the semaphore.""" - raise NotImplementedError - - @property - def max_value(self) -> int | None: - """The maximum value of the semaphore.""" - raise NotImplementedError - - def statistics(self) -> SemaphoreStatistics: - """ - Return statistics about the current state of this semaphore. - - .. versionadded:: 3.0 - """ - raise NotImplementedError - - -class SemaphoreAdapter(Semaphore): - _internal_semaphore: Semaphore | None = None - - def __new__( - cls, - initial_value: int, - *, - max_value: int | None = None, - fast_acquire: bool = False, - ) -> SemaphoreAdapter: - return object.__new__(cls) - - def __init__( - self, - initial_value: int, - *, - max_value: int | None = None, - fast_acquire: bool = False, - ) -> None: - super().__init__(initial_value, max_value=max_value, fast_acquire=fast_acquire) - self._initial_value = initial_value - self._max_value = max_value - - @property - def _semaphore(self) -> Semaphore: - if self._internal_semaphore is None: - self._internal_semaphore = get_async_backend().create_semaphore( - self._initial_value, max_value=self._max_value - ) - - return self._internal_semaphore - - async def acquire(self) -> None: - await self._semaphore.acquire() - - def acquire_nowait(self) -> None: - self._semaphore.acquire_nowait() - - def release(self) -> None: - self._semaphore.release() - - @property - def value(self) -> int: - if self._internal_semaphore is None: - return self._initial_value - - return self._semaphore.value - - @property - def max_value(self) -> int | None: - return self._max_value - - def statistics(self) -> SemaphoreStatistics: - if self._internal_semaphore is None: - return SemaphoreStatistics(tasks_waiting=0) - - return self._semaphore.statistics() - - -class CapacityLimiter: - def __new__(cls, total_tokens: float) -> CapacityLimiter: - try: - return get_async_backend().create_capacity_limiter(total_tokens) - except NoEventLoopError: - return CapacityLimiterAdapter(total_tokens) - - async def __aenter__(self) -> None: - raise NotImplementedError - - async def __aexit__( - self, - exc_type: type[BaseException] | None, - exc_val: BaseException | None, - exc_tb: TracebackType | None, - ) -> None: - raise NotImplementedError - - @property - def total_tokens(self) -> float: - """ - The total number of tokens available for borrowing. - - This is a read-write property. If the total number of tokens is increased, the - proportionate number of tasks waiting on this limiter will be granted their - tokens. - - .. versionchanged:: 3.0 - The property is now writable. - .. versionchanged:: 4.12 - The value can now be set to 0. - - """ - raise NotImplementedError - - @total_tokens.setter - def total_tokens(self, value: float) -> None: - raise NotImplementedError - - @property - def borrowed_tokens(self) -> int: - """The number of tokens that have currently been borrowed.""" - raise NotImplementedError - - @property - def available_tokens(self) -> float: - """The number of tokens currently available to be borrowed""" - raise NotImplementedError - - def acquire_nowait(self) -> None: - """ - Acquire a token for the current task without waiting for one to become - available. - - :raises ~anyio.WouldBlock: if there are no tokens available for borrowing - - """ - raise NotImplementedError - - def acquire_on_behalf_of_nowait(self, borrower: object) -> None: - """ - Acquire a token without waiting for one to become available. - - :param borrower: the entity borrowing a token - :raises ~anyio.WouldBlock: if there are no tokens available for borrowing - - """ - raise NotImplementedError - - async def acquire(self) -> None: - """ - Acquire a token for the current task, waiting if necessary for one to become - available. - - """ - raise NotImplementedError - - async def acquire_on_behalf_of(self, borrower: object) -> None: - """ - Acquire a token, waiting if necessary for one to become available. - - :param borrower: the entity borrowing a token - - """ - raise NotImplementedError - - def release(self) -> None: - """ - Release the token held by the current task. - - :raises RuntimeError: if the current task has not borrowed a token from this - limiter. - - """ - raise NotImplementedError - - def release_on_behalf_of(self, borrower: object) -> None: - """ - Release the token held by the given borrower. - - :raises RuntimeError: if the borrower has not borrowed a token from this - limiter. - - """ - raise NotImplementedError - - def statistics(self) -> CapacityLimiterStatistics: - """ - Return statistics about the current state of this limiter. - - .. versionadded:: 3.0 - - """ - raise NotImplementedError - - -class CapacityLimiterAdapter(CapacityLimiter): - _internal_limiter: CapacityLimiter | None = None - - def __new__(cls, total_tokens: float) -> CapacityLimiterAdapter: - return object.__new__(cls) - - def __init__(self, total_tokens: float) -> None: - self.total_tokens = total_tokens - - @property - def _limiter(self) -> CapacityLimiter: - if self._internal_limiter is None: - self._internal_limiter = get_async_backend().create_capacity_limiter( - self._total_tokens - ) - - return self._internal_limiter - - async def __aenter__(self) -> None: - await self._limiter.__aenter__() - - async def __aexit__( - self, - exc_type: type[BaseException] | None, - exc_val: BaseException | None, - exc_tb: TracebackType | None, - ) -> None: - return await self._limiter.__aexit__(exc_type, exc_val, exc_tb) - - @property - def total_tokens(self) -> float: - if self._internal_limiter is None: - return self._total_tokens - - return self._internal_limiter.total_tokens - - @total_tokens.setter - def total_tokens(self, value: float) -> None: - if not isinstance(value, int) and value is not math.inf: - raise TypeError("total_tokens must be an int or math.inf") - elif value < 1: - raise ValueError("total_tokens must be >= 1") - - if self._internal_limiter is None: - self._total_tokens = value - return - - self._limiter.total_tokens = value - - @property - def borrowed_tokens(self) -> int: - if self._internal_limiter is None: - return 0 - - return self._internal_limiter.borrowed_tokens - - @property - def available_tokens(self) -> float: - if self._internal_limiter is None: - return self._total_tokens - - return self._internal_limiter.available_tokens - - def acquire_nowait(self) -> None: - self._limiter.acquire_nowait() - - def acquire_on_behalf_of_nowait(self, borrower: object) -> None: - self._limiter.acquire_on_behalf_of_nowait(borrower) - - async def acquire(self) -> None: - await self._limiter.acquire() - - async def acquire_on_behalf_of(self, borrower: object) -> None: - await self._limiter.acquire_on_behalf_of(borrower) - - def release(self) -> None: - self._limiter.release() - - def release_on_behalf_of(self, borrower: object) -> None: - self._limiter.release_on_behalf_of(borrower) - - def statistics(self) -> CapacityLimiterStatistics: - if self._internal_limiter is None: - return CapacityLimiterStatistics( - borrowed_tokens=0, - total_tokens=self.total_tokens, - borrowers=(), - tasks_waiting=0, - ) - - return self._internal_limiter.statistics() - - -class ResourceGuard: - """ - A context manager for ensuring that a resource is only used by a single task at a - time. - - Entering this context manager while the previous has not exited it yet will trigger - :exc:`BusyResourceError`. - - :param action: the action to guard against (visible in the :exc:`BusyResourceError` - when triggered, e.g. "Another task is already {action} this resource") - - .. versionadded:: 4.1 - """ - - __slots__ = "action", "_guarded" - - def __init__(self, action: str = "using"): - self.action: str = action - self._guarded = False - - def __enter__(self) -> None: - if self._guarded: - raise BusyResourceError(self.action) - - self._guarded = True - - def __exit__( - self, - exc_type: type[BaseException] | None, - exc_val: BaseException | None, - exc_tb: TracebackType | None, - ) -> None: - self._guarded = False diff --git a/.venv/lib/python3.12/site-packages/anyio/_core/_tasks.py b/.venv/lib/python3.12/site-packages/anyio/_core/_tasks.py deleted file mode 100644 index 0688bfe..0000000 --- a/.venv/lib/python3.12/site-packages/anyio/_core/_tasks.py +++ /dev/null @@ -1,173 +0,0 @@ -from __future__ import annotations - -import math -from collections.abc import Generator -from contextlib import contextmanager -from types import TracebackType - -from ..abc._tasks import TaskGroup, TaskStatus -from ._eventloop import get_async_backend - - -class _IgnoredTaskStatus(TaskStatus[object]): - def started(self, value: object = None) -> None: - pass - - -TASK_STATUS_IGNORED = _IgnoredTaskStatus() - - -class CancelScope: - """ - Wraps a unit of work that can be made separately cancellable. - - :param deadline: The time (clock value) when this scope is cancelled automatically - :param shield: ``True`` to shield the cancel scope from external cancellation - :raises NoEventLoopError: if no supported asynchronous event loop is running in the - current thread - """ - - def __new__( - cls, *, deadline: float = math.inf, shield: bool = False - ) -> CancelScope: - return get_async_backend().create_cancel_scope(shield=shield, deadline=deadline) - - def cancel(self, reason: str | None = None) -> None: - """ - Cancel this scope immediately. - - :param reason: a message describing the reason for the cancellation - - """ - raise NotImplementedError - - @property - def deadline(self) -> float: - """ - The time (clock value) when this scope is cancelled automatically. - - Will be ``float('inf')`` if no timeout has been set. - - """ - raise NotImplementedError - - @deadline.setter - def deadline(self, value: float) -> None: - raise NotImplementedError - - @property - def cancel_called(self) -> bool: - """``True`` if :meth:`cancel` has been called.""" - raise NotImplementedError - - @property - def cancelled_caught(self) -> bool: - """ - ``True`` if this scope suppressed a cancellation exception it itself raised. - - This is typically used to check if any work was interrupted, or to see if the - scope was cancelled due to its deadline being reached. The value will, however, - only be ``True`` if the cancellation was triggered by the scope itself (and not - an outer scope). - - """ - raise NotImplementedError - - @property - def shield(self) -> bool: - """ - ``True`` if this scope is shielded from external cancellation. - - While a scope is shielded, it will not receive cancellations from outside. - - """ - raise NotImplementedError - - @shield.setter - def shield(self, value: bool) -> None: - raise NotImplementedError - - def __enter__(self) -> CancelScope: - raise NotImplementedError - - def __exit__( - self, - exc_type: type[BaseException] | None, - exc_val: BaseException | None, - exc_tb: TracebackType | None, - ) -> bool: - raise NotImplementedError - - -@contextmanager -def fail_after( - delay: float | None, shield: bool = False -) -> Generator[CancelScope, None, None]: - """ - Create a context manager which raises a :class:`TimeoutError` if does not finish in - time. - - :param delay: maximum allowed time (in seconds) before raising the exception, or - ``None`` to disable the timeout - :param shield: ``True`` to shield the cancel scope from external cancellation - :return: a context manager that yields a cancel scope - :rtype: :class:`~typing.ContextManager`\\[:class:`~anyio.CancelScope`\\] - :raises NoEventLoopError: if no supported asynchronous event loop is running in the - current thread - - """ - current_time = get_async_backend().current_time - deadline = (current_time() + delay) if delay is not None else math.inf - with get_async_backend().create_cancel_scope( - deadline=deadline, shield=shield - ) as cancel_scope: - yield cancel_scope - - if cancel_scope.cancelled_caught and current_time() >= cancel_scope.deadline: - raise TimeoutError - - -def move_on_after(delay: float | None, shield: bool = False) -> CancelScope: - """ - Create a cancel scope with a deadline that expires after the given delay. - - :param delay: maximum allowed time (in seconds) before exiting the context block, or - ``None`` to disable the timeout - :param shield: ``True`` to shield the cancel scope from external cancellation - :return: a cancel scope - :raises NoEventLoopError: if no supported asynchronous event loop is running in the - current thread - - """ - deadline = ( - (get_async_backend().current_time() + delay) if delay is not None else math.inf - ) - return get_async_backend().create_cancel_scope(deadline=deadline, shield=shield) - - -def current_effective_deadline() -> float: - """ - Return the nearest deadline among all the cancel scopes effective for the current - task. - - :return: a clock value from the event loop's internal clock (or ``float('inf')`` if - there is no deadline in effect, or ``float('-inf')`` if the current scope has - been cancelled) - :rtype: float - :raises NoEventLoopError: if no supported asynchronous event loop is running in the - current thread - - """ - return get_async_backend().current_effective_deadline() - - -def create_task_group() -> TaskGroup: - """ - Create a task group. - - :return: a task group - :raises NoEventLoopError: if no supported asynchronous event loop is running in the - current thread - - """ - return get_async_backend().create_task_group() diff --git a/.venv/lib/python3.12/site-packages/anyio/_core/_tempfile.py b/.venv/lib/python3.12/site-packages/anyio/_core/_tempfile.py deleted file mode 100644 index 75a09f7..0000000 --- a/.venv/lib/python3.12/site-packages/anyio/_core/_tempfile.py +++ /dev/null @@ -1,613 +0,0 @@ -from __future__ import annotations - -import os -import sys -import tempfile -from collections.abc import Iterable -from io import BytesIO, TextIOWrapper -from types import TracebackType -from typing import ( - TYPE_CHECKING, - Any, - AnyStr, - Generic, - overload, -) - -from .. import to_thread -from .._core._fileio import AsyncFile -from ..lowlevel import checkpoint_if_cancelled - -if TYPE_CHECKING: - from _typeshed import OpenBinaryMode, OpenTextMode, ReadableBuffer, WriteableBuffer - - -class TemporaryFile(Generic[AnyStr]): - """ - An asynchronous temporary file that is automatically created and cleaned up. - - This class provides an asynchronous context manager interface to a temporary file. - The file is created using Python's standard `tempfile.TemporaryFile` function in a - background thread, and is wrapped as an asynchronous file using `AsyncFile`. - - :param mode: The mode in which the file is opened. Defaults to "w+b". - :param buffering: The buffering policy (-1 means the default buffering). - :param encoding: The encoding used to decode or encode the file. Only applicable in - text mode. - :param newline: Controls how universal newlines mode works (only applicable in text - mode). - :param suffix: The suffix for the temporary file name. - :param prefix: The prefix for the temporary file name. - :param dir: The directory in which the temporary file is created. - :param errors: The error handling scheme used for encoding/decoding errors. - """ - - _async_file: AsyncFile[AnyStr] - - @overload - def __init__( - self: TemporaryFile[bytes], - mode: OpenBinaryMode = ..., - buffering: int = ..., - encoding: str | None = ..., - newline: str | None = ..., - suffix: str | None = ..., - prefix: str | None = ..., - dir: str | None = ..., - *, - errors: str | None = ..., - ): ... - @overload - def __init__( - self: TemporaryFile[str], - mode: OpenTextMode, - buffering: int = ..., - encoding: str | None = ..., - newline: str | None = ..., - suffix: str | None = ..., - prefix: str | None = ..., - dir: str | None = ..., - *, - errors: str | None = ..., - ): ... - - def __init__( - self, - mode: OpenTextMode | OpenBinaryMode = "w+b", - buffering: int = -1, - encoding: str | None = None, - newline: str | None = None, - suffix: str | None = None, - prefix: str | None = None, - dir: str | None = None, - *, - errors: str | None = None, - ) -> None: - self.mode = mode - self.buffering = buffering - self.encoding = encoding - self.newline = newline - self.suffix: str | None = suffix - self.prefix: str | None = prefix - self.dir: str | None = dir - self.errors = errors - - async def __aenter__(self) -> AsyncFile[AnyStr]: - fp = await to_thread.run_sync( - lambda: tempfile.TemporaryFile( - self.mode, - self.buffering, - self.encoding, - self.newline, - self.suffix, - self.prefix, - self.dir, - errors=self.errors, - ) - ) - self._async_file = AsyncFile(fp) - return self._async_file - - async def __aexit__( - self, - exc_type: type[BaseException] | None, - exc_value: BaseException | None, - traceback: TracebackType | None, - ) -> None: - await self._async_file.aclose() - - -class NamedTemporaryFile(Generic[AnyStr]): - """ - An asynchronous named temporary file that is automatically created and cleaned up. - - This class provides an asynchronous context manager for a temporary file with a - visible name in the file system. It uses Python's standard - :func:`~tempfile.NamedTemporaryFile` function and wraps the file object with - :class:`AsyncFile` for asynchronous operations. - - :param mode: The mode in which the file is opened. Defaults to "w+b". - :param buffering: The buffering policy (-1 means the default buffering). - :param encoding: The encoding used to decode or encode the file. Only applicable in - text mode. - :param newline: Controls how universal newlines mode works (only applicable in text - mode). - :param suffix: The suffix for the temporary file name. - :param prefix: The prefix for the temporary file name. - :param dir: The directory in which the temporary file is created. - :param delete: Whether to delete the file when it is closed. - :param errors: The error handling scheme used for encoding/decoding errors. - :param delete_on_close: (Python 3.12+) Whether to delete the file on close. - """ - - _async_file: AsyncFile[AnyStr] - - @overload - def __init__( - self: NamedTemporaryFile[bytes], - mode: OpenBinaryMode = ..., - buffering: int = ..., - encoding: str | None = ..., - newline: str | None = ..., - suffix: str | None = ..., - prefix: str | None = ..., - dir: str | None = ..., - delete: bool = ..., - *, - errors: str | None = ..., - delete_on_close: bool = ..., - ): ... - @overload - def __init__( - self: NamedTemporaryFile[str], - mode: OpenTextMode, - buffering: int = ..., - encoding: str | None = ..., - newline: str | None = ..., - suffix: str | None = ..., - prefix: str | None = ..., - dir: str | None = ..., - delete: bool = ..., - *, - errors: str | None = ..., - delete_on_close: bool = ..., - ): ... - - def __init__( - self, - mode: OpenBinaryMode | OpenTextMode = "w+b", - buffering: int = -1, - encoding: str | None = None, - newline: str | None = None, - suffix: str | None = None, - prefix: str | None = None, - dir: str | None = None, - delete: bool = True, - *, - errors: str | None = None, - delete_on_close: bool = True, - ) -> None: - self._params: dict[str, Any] = { - "mode": mode, - "buffering": buffering, - "encoding": encoding, - "newline": newline, - "suffix": suffix, - "prefix": prefix, - "dir": dir, - "delete": delete, - "errors": errors, - } - if sys.version_info >= (3, 12): - self._params["delete_on_close"] = delete_on_close - - async def __aenter__(self) -> AsyncFile[AnyStr]: - fp = await to_thread.run_sync( - lambda: tempfile.NamedTemporaryFile(**self._params) - ) - self._async_file = AsyncFile(fp) - return self._async_file - - async def __aexit__( - self, - exc_type: type[BaseException] | None, - exc_value: BaseException | None, - traceback: TracebackType | None, - ) -> None: - await self._async_file.aclose() - - -class SpooledTemporaryFile(AsyncFile[AnyStr]): - """ - An asynchronous spooled temporary file that starts in memory and is spooled to disk. - - This class provides an asynchronous interface to a spooled temporary file, much like - Python's standard :class:`~tempfile.SpooledTemporaryFile`. It supports asynchronous - write operations and provides a method to force a rollover to disk. - - :param max_size: Maximum size in bytes before the file is rolled over to disk. - :param mode: The mode in which the file is opened. Defaults to "w+b". - :param buffering: The buffering policy (-1 means the default buffering). - :param encoding: The encoding used to decode or encode the file (text mode only). - :param newline: Controls how universal newlines mode works (text mode only). - :param suffix: The suffix for the temporary file name. - :param prefix: The prefix for the temporary file name. - :param dir: The directory in which the temporary file is created. - :param errors: The error handling scheme used for encoding/decoding errors. - """ - - _rolled: bool = False - - @overload - def __init__( - self: SpooledTemporaryFile[bytes], - max_size: int = ..., - mode: OpenBinaryMode = ..., - buffering: int = ..., - encoding: str | None = ..., - newline: str | None = ..., - suffix: str | None = ..., - prefix: str | None = ..., - dir: str | None = ..., - *, - errors: str | None = ..., - ): ... - @overload - def __init__( - self: SpooledTemporaryFile[str], - max_size: int = ..., - mode: OpenTextMode = ..., - buffering: int = ..., - encoding: str | None = ..., - newline: str | None = ..., - suffix: str | None = ..., - prefix: str | None = ..., - dir: str | None = ..., - *, - errors: str | None = ..., - ): ... - - def __init__( - self, - max_size: int = 0, - mode: OpenBinaryMode | OpenTextMode = "w+b", - buffering: int = -1, - encoding: str | None = None, - newline: str | None = None, - suffix: str | None = None, - prefix: str | None = None, - dir: str | None = None, - *, - errors: str | None = None, - ) -> None: - self._tempfile_params: dict[str, Any] = { - "mode": mode, - "buffering": buffering, - "encoding": encoding, - "newline": newline, - "suffix": suffix, - "prefix": prefix, - "dir": dir, - "errors": errors, - } - self._max_size = max_size - if "b" in mode: - super().__init__(BytesIO()) # type: ignore[arg-type] - else: - super().__init__( - TextIOWrapper( # type: ignore[arg-type] - BytesIO(), - encoding=encoding, - errors=errors, - newline=newline, - write_through=True, - ) - ) - - async def aclose(self) -> None: - if not self._rolled: - self._fp.close() - return - - await super().aclose() - - async def _check(self) -> None: - if self._rolled or self._fp.tell() <= self._max_size: - return - - await self.rollover() - - async def rollover(self) -> None: - if self._rolled: - return - - self._rolled = True - buffer = self._fp - buffer.seek(0) - self._fp = await to_thread.run_sync( - lambda: tempfile.TemporaryFile(**self._tempfile_params) - ) - await self.write(buffer.read()) - buffer.close() - - @property - def closed(self) -> bool: - return self._fp.closed - - async def read(self, size: int = -1) -> AnyStr: - if not self._rolled: - await checkpoint_if_cancelled() - return self._fp.read(size) - - return await super().read(size) # type: ignore[return-value] - - async def read1(self: SpooledTemporaryFile[bytes], size: int = -1) -> bytes: - if not self._rolled: - await checkpoint_if_cancelled() - return self._fp.read1(size) - - return await super().read1(size) - - async def readline(self) -> AnyStr: - if not self._rolled: - await checkpoint_if_cancelled() - return self._fp.readline() - - return await super().readline() # type: ignore[return-value] - - async def readlines(self) -> list[AnyStr]: - if not self._rolled: - await checkpoint_if_cancelled() - return self._fp.readlines() - - return await super().readlines() # type: ignore[return-value] - - async def readinto(self: SpooledTemporaryFile[bytes], b: WriteableBuffer) -> int: - if not self._rolled: - await checkpoint_if_cancelled() - self._fp.readinto(b) - - return await super().readinto(b) - - async def readinto1(self: SpooledTemporaryFile[bytes], b: WriteableBuffer) -> int: - if not self._rolled: - await checkpoint_if_cancelled() - self._fp.readinto(b) - - return await super().readinto1(b) - - async def seek(self, offset: int, whence: int | None = os.SEEK_SET) -> int: - if not self._rolled: - await checkpoint_if_cancelled() - return self._fp.seek(offset, whence) - - return await super().seek(offset, whence) - - async def tell(self) -> int: - if not self._rolled: - await checkpoint_if_cancelled() - return self._fp.tell() - - return await super().tell() - - async def truncate(self, size: int | None = None) -> int: - if not self._rolled: - await checkpoint_if_cancelled() - return self._fp.truncate(size) - - return await super().truncate(size) - - @overload - async def write(self: SpooledTemporaryFile[bytes], b: ReadableBuffer) -> int: ... - @overload - async def write(self: SpooledTemporaryFile[str], b: str) -> int: ... - - async def write(self, b: ReadableBuffer | str) -> int: - """ - Asynchronously write data to the spooled temporary file. - - If the file has not yet been rolled over, the data is written synchronously, - and a rollover is triggered if the size exceeds the maximum size. - - :param s: The data to write. - :return: The number of bytes written. - :raises RuntimeError: If the underlying file is not initialized. - - """ - if not self._rolled: - await checkpoint_if_cancelled() - result = self._fp.write(b) - await self._check() - return result - - return await super().write(b) # type: ignore[misc] - - @overload - async def writelines( - self: SpooledTemporaryFile[bytes], lines: Iterable[ReadableBuffer] - ) -> None: ... - @overload - async def writelines( - self: SpooledTemporaryFile[str], lines: Iterable[str] - ) -> None: ... - - async def writelines(self, lines: Iterable[str] | Iterable[ReadableBuffer]) -> None: - """ - Asynchronously write a list of lines to the spooled temporary file. - - If the file has not yet been rolled over, the lines are written synchronously, - and a rollover is triggered if the size exceeds the maximum size. - - :param lines: An iterable of lines to write. - :raises RuntimeError: If the underlying file is not initialized. - - """ - if not self._rolled: - await checkpoint_if_cancelled() - result = self._fp.writelines(lines) - await self._check() - return result - - return await super().writelines(lines) # type: ignore[misc] - - -class TemporaryDirectory(Generic[AnyStr]): - """ - An asynchronous temporary directory that is created and cleaned up automatically. - - This class provides an asynchronous context manager for creating a temporary - directory. It wraps Python's standard :class:`~tempfile.TemporaryDirectory` to - perform directory creation and cleanup operations in a background thread. - - :param suffix: Suffix to be added to the temporary directory name. - :param prefix: Prefix to be added to the temporary directory name. - :param dir: The parent directory where the temporary directory is created. - :param ignore_cleanup_errors: Whether to ignore errors during cleanup - :param delete: Whether to delete the directory upon closing (Python 3.12+). - """ - - def __init__( - self, - suffix: AnyStr | None = None, - prefix: AnyStr | None = None, - dir: AnyStr | None = None, - *, - ignore_cleanup_errors: bool = False, - delete: bool = True, - ) -> None: - self.suffix: AnyStr | None = suffix - self.prefix: AnyStr | None = prefix - self.dir: AnyStr | None = dir - self.ignore_cleanup_errors = ignore_cleanup_errors - self.delete = delete - - self._tempdir: tempfile.TemporaryDirectory | None = None - - async def __aenter__(self) -> str: - params: dict[str, Any] = { - "suffix": self.suffix, - "prefix": self.prefix, - "dir": self.dir, - "ignore_cleanup_errors": self.ignore_cleanup_errors, - } - if sys.version_info >= (3, 12): - params["delete"] = self.delete - - self._tempdir = await to_thread.run_sync( - lambda: tempfile.TemporaryDirectory(**params) - ) - return await to_thread.run_sync(self._tempdir.__enter__) - - async def __aexit__( - self, - exc_type: type[BaseException] | None, - exc_value: BaseException | None, - traceback: TracebackType | None, - ) -> None: - if self._tempdir is not None: - await to_thread.run_sync( - self._tempdir.__exit__, exc_type, exc_value, traceback - ) - - async def cleanup(self) -> None: - if self._tempdir is not None: - await to_thread.run_sync(self._tempdir.cleanup) - - -@overload -async def mkstemp( - suffix: str | None = None, - prefix: str | None = None, - dir: str | None = None, - text: bool = False, -) -> tuple[int, str]: ... - - -@overload -async def mkstemp( - suffix: bytes | None = None, - prefix: bytes | None = None, - dir: bytes | None = None, - text: bool = False, -) -> tuple[int, bytes]: ... - - -async def mkstemp( - suffix: AnyStr | None = None, - prefix: AnyStr | None = None, - dir: AnyStr | None = None, - text: bool = False, -) -> tuple[int, str | bytes]: - """ - Asynchronously create a temporary file and return an OS-level handle and the file - name. - - This function wraps `tempfile.mkstemp` and executes it in a background thread. - - :param suffix: Suffix to be added to the file name. - :param prefix: Prefix to be added to the file name. - :param dir: Directory in which the temporary file is created. - :param text: Whether the file is opened in text mode. - :return: A tuple containing the file descriptor and the file name. - - """ - return await to_thread.run_sync(tempfile.mkstemp, suffix, prefix, dir, text) - - -@overload -async def mkdtemp( - suffix: str | None = None, - prefix: str | None = None, - dir: str | None = None, -) -> str: ... - - -@overload -async def mkdtemp( - suffix: bytes | None = None, - prefix: bytes | None = None, - dir: bytes | None = None, -) -> bytes: ... - - -async def mkdtemp( - suffix: AnyStr | None = None, - prefix: AnyStr | None = None, - dir: AnyStr | None = None, -) -> str | bytes: - """ - Asynchronously create a temporary directory and return its path. - - This function wraps `tempfile.mkdtemp` and executes it in a background thread. - - :param suffix: Suffix to be added to the directory name. - :param prefix: Prefix to be added to the directory name. - :param dir: Parent directory where the temporary directory is created. - :return: The path of the created temporary directory. - - """ - return await to_thread.run_sync(tempfile.mkdtemp, suffix, prefix, dir) - - -async def gettempdir() -> str: - """ - Asynchronously return the name of the directory used for temporary files. - - This function wraps `tempfile.gettempdir` and executes it in a background thread. - - :return: The path of the temporary directory as a string. - - """ - return await to_thread.run_sync(tempfile.gettempdir) - - -async def gettempdirb() -> bytes: - """ - Asynchronously return the name of the directory used for temporary files in bytes. - - This function wraps `tempfile.gettempdirb` and executes it in a background thread. - - :return: The path of the temporary directory as bytes. - - """ - return await to_thread.run_sync(tempfile.gettempdirb) diff --git a/.venv/lib/python3.12/site-packages/anyio/_core/_testing.py b/.venv/lib/python3.12/site-packages/anyio/_core/_testing.py deleted file mode 100644 index 369e65c..0000000 --- a/.venv/lib/python3.12/site-packages/anyio/_core/_testing.py +++ /dev/null @@ -1,82 +0,0 @@ -from __future__ import annotations - -from collections.abc import Awaitable, Generator -from typing import Any, cast - -from ._eventloop import get_async_backend - - -class TaskInfo: - """ - Represents an asynchronous task. - - :ivar int id: the unique identifier of the task - :ivar parent_id: the identifier of the parent task, if any - :vartype parent_id: Optional[int] - :ivar str name: the description of the task (if any) - :ivar ~collections.abc.Coroutine coro: the coroutine object of the task - """ - - __slots__ = "_name", "id", "parent_id", "name", "coro" - - def __init__( - self, - id: int, - parent_id: int | None, - name: str | None, - coro: Generator[Any, Any, Any] | Awaitable[Any], - ): - func = get_current_task - self._name = f"{func.__module__}.{func.__qualname__}" - self.id: int = id - self.parent_id: int | None = parent_id - self.name: str | None = name - self.coro: Generator[Any, Any, Any] | Awaitable[Any] = coro - - def __eq__(self, other: object) -> bool: - if isinstance(other, TaskInfo): - return self.id == other.id - - return NotImplemented - - def __hash__(self) -> int: - return hash(self.id) - - def __repr__(self) -> str: - return f"{self.__class__.__name__}(id={self.id!r}, name={self.name!r})" - - def has_pending_cancellation(self) -> bool: - """ - Return ``True`` if the task has a cancellation pending, ``False`` otherwise. - - """ - return False - - -def get_current_task() -> TaskInfo: - """ - Return the current task. - - :return: a representation of the current task - :raises NoEventLoopError: if no supported asynchronous event loop is running in the - current thread - - """ - return get_async_backend().get_current_task() - - -def get_running_tasks() -> list[TaskInfo]: - """ - Return a list of running tasks in the current event loop. - - :return: a list of task info objects - :raises NoEventLoopError: if no supported asynchronous event loop is running in the - current thread - - """ - return cast("list[TaskInfo]", get_async_backend().get_running_tasks()) - - -async def wait_all_tasks_blocked() -> None: - """Wait until all other tasks are waiting for something.""" - await get_async_backend().wait_all_tasks_blocked() diff --git a/.venv/lib/python3.12/site-packages/anyio/_core/_typedattr.py b/.venv/lib/python3.12/site-packages/anyio/_core/_typedattr.py deleted file mode 100644 index f358a44..0000000 --- a/.venv/lib/python3.12/site-packages/anyio/_core/_typedattr.py +++ /dev/null @@ -1,81 +0,0 @@ -from __future__ import annotations - -from collections.abc import Callable, Mapping -from typing import Any, TypeVar, final, overload - -from ._exceptions import TypedAttributeLookupError - -T_Attr = TypeVar("T_Attr") -T_Default = TypeVar("T_Default") -undefined = object() - - -def typed_attribute() -> Any: - """Return a unique object, used to mark typed attributes.""" - return object() - - -class TypedAttributeSet: - """ - Superclass for typed attribute collections. - - Checks that every public attribute of every subclass has a type annotation. - """ - - def __init_subclass__(cls) -> None: - annotations: dict[str, Any] = getattr(cls, "__annotations__", {}) - for attrname in dir(cls): - if not attrname.startswith("_") and attrname not in annotations: - raise TypeError( - f"Attribute {attrname!r} is missing its type annotation" - ) - - super().__init_subclass__() - - -class TypedAttributeProvider: - """Base class for classes that wish to provide typed extra attributes.""" - - @property - def extra_attributes(self) -> Mapping[T_Attr, Callable[[], T_Attr]]: - """ - A mapping of the extra attributes to callables that return the corresponding - values. - - If the provider wraps another provider, the attributes from that wrapper should - also be included in the returned mapping (but the wrapper may override the - callables from the wrapped instance). - - """ - return {} - - @overload - def extra(self, attribute: T_Attr) -> T_Attr: ... - - @overload - def extra(self, attribute: T_Attr, default: T_Default) -> T_Attr | T_Default: ... - - @final - def extra(self, attribute: Any, default: object = undefined) -> object: - """ - extra(attribute, default=undefined) - - Return the value of the given typed extra attribute. - - :param attribute: the attribute (member of a :class:`~TypedAttributeSet`) to - look for - :param default: the value that should be returned if no value is found for the - attribute - :raises ~anyio.TypedAttributeLookupError: if the search failed and no default - value was given - - """ - try: - getter = self.extra_attributes[attribute] - except KeyError: - if default is undefined: - raise TypedAttributeLookupError("Attribute not found") from None - else: - return default - - return getter() diff --git a/.venv/lib/python3.12/site-packages/anyio/abc/__init__.py b/.venv/lib/python3.12/site-packages/anyio/abc/__init__.py deleted file mode 100644 index d560ce3..0000000 --- a/.venv/lib/python3.12/site-packages/anyio/abc/__init__.py +++ /dev/null @@ -1,58 +0,0 @@ -from __future__ import annotations - -from ._eventloop import AsyncBackend as AsyncBackend -from ._resources import AsyncResource as AsyncResource -from ._sockets import ConnectedUDPSocket as ConnectedUDPSocket -from ._sockets import ConnectedUNIXDatagramSocket as ConnectedUNIXDatagramSocket -from ._sockets import IPAddressType as IPAddressType -from ._sockets import IPSockAddrType as IPSockAddrType -from ._sockets import SocketAttribute as SocketAttribute -from ._sockets import SocketListener as SocketListener -from ._sockets import SocketStream as SocketStream -from ._sockets import UDPPacketType as UDPPacketType -from ._sockets import UDPSocket as UDPSocket -from ._sockets import UNIXDatagramPacketType as UNIXDatagramPacketType -from ._sockets import UNIXDatagramSocket as UNIXDatagramSocket -from ._sockets import UNIXSocketStream as UNIXSocketStream -from ._streams import AnyByteReceiveStream as AnyByteReceiveStream -from ._streams import AnyByteSendStream as AnyByteSendStream -from ._streams import AnyByteStream as AnyByteStream -from ._streams import AnyByteStreamConnectable as AnyByteStreamConnectable -from ._streams import AnyUnreliableByteReceiveStream as AnyUnreliableByteReceiveStream -from ._streams import AnyUnreliableByteSendStream as AnyUnreliableByteSendStream -from ._streams import AnyUnreliableByteStream as AnyUnreliableByteStream -from ._streams import ByteReceiveStream as ByteReceiveStream -from ._streams import ByteSendStream as ByteSendStream -from ._streams import ByteStream as ByteStream -from ._streams import ByteStreamConnectable as ByteStreamConnectable -from ._streams import Listener as Listener -from ._streams import ObjectReceiveStream as ObjectReceiveStream -from ._streams import ObjectSendStream as ObjectSendStream -from ._streams import ObjectStream as ObjectStream -from ._streams import ObjectStreamConnectable as ObjectStreamConnectable -from ._streams import UnreliableObjectReceiveStream as UnreliableObjectReceiveStream -from ._streams import UnreliableObjectSendStream as UnreliableObjectSendStream -from ._streams import UnreliableObjectStream as UnreliableObjectStream -from ._subprocesses import Process as Process -from ._tasks import TaskGroup as TaskGroup -from ._tasks import TaskStatus as TaskStatus -from ._testing import TestRunner as TestRunner - -# Re-exported here, for backwards compatibility -# isort: off -from .._core._synchronization import ( - CapacityLimiter as CapacityLimiter, - Condition as Condition, - Event as Event, - Lock as Lock, - Semaphore as Semaphore, -) -from .._core._tasks import CancelScope as CancelScope -from ..from_thread import BlockingPortal as BlockingPortal - -# Re-export imports so they look like they live directly in this package -for __value in list(locals().values()): - if getattr(__value, "__module__", "").startswith("anyio.abc."): - __value.__module__ = __name__ - -del __value diff --git a/.venv/lib/python3.12/site-packages/anyio/abc/_eventloop.py b/.venv/lib/python3.12/site-packages/anyio/abc/_eventloop.py deleted file mode 100644 index ae06288..0000000 --- a/.venv/lib/python3.12/site-packages/anyio/abc/_eventloop.py +++ /dev/null @@ -1,409 +0,0 @@ -from __future__ import annotations - -import math -import sys -from abc import ABCMeta, abstractmethod -from collections.abc import AsyncIterator, Awaitable, Callable, Sequence -from contextlib import AbstractContextManager -from os import PathLike -from signal import Signals -from socket import AddressFamily, SocketKind, socket -from typing import ( - IO, - TYPE_CHECKING, - Any, - TypeAlias, - TypeVar, - overload, -) - -if sys.version_info >= (3, 11): - from typing import TypeVarTuple, Unpack -else: - from typing_extensions import TypeVarTuple, Unpack - -if TYPE_CHECKING: - from _typeshed import FileDescriptorLike - - from .._core._synchronization import CapacityLimiter, Event, Lock, Semaphore - from .._core._tasks import CancelScope - from .._core._testing import TaskInfo - from ._sockets import ( - ConnectedUDPSocket, - ConnectedUNIXDatagramSocket, - IPSockAddrType, - SocketListener, - SocketStream, - UDPSocket, - UNIXDatagramSocket, - UNIXSocketStream, - ) - from ._subprocesses import Process - from ._tasks import TaskGroup - from ._testing import TestRunner - -T_Retval = TypeVar("T_Retval") -PosArgsT = TypeVarTuple("PosArgsT") -StrOrBytesPath: TypeAlias = str | bytes | PathLike[str] | PathLike[bytes] - - -class AsyncBackend(metaclass=ABCMeta): - @classmethod - @abstractmethod - def run( - cls, - func: Callable[[Unpack[PosArgsT]], Awaitable[T_Retval]], - args: tuple[Unpack[PosArgsT]], - kwargs: dict[str, Any], - options: dict[str, Any], - ) -> T_Retval: - """ - Run the given coroutine function in an asynchronous event loop. - - The current thread must not be already running an event loop. - - :param func: a coroutine function - :param args: positional arguments to ``func`` - :param kwargs: positional arguments to ``func`` - :param options: keyword arguments to call the backend ``run()`` implementation - with - :return: the return value of the coroutine function - """ - - @classmethod - @abstractmethod - def current_token(cls) -> object: - """ - Return an object that allows other threads to run code inside the event loop. - - :return: a token object, specific to the event loop running in the current - thread - """ - - @classmethod - @abstractmethod - def current_time(cls) -> float: - """ - Return the current value of the event loop's internal clock. - - :return: the clock value (seconds) - """ - - @classmethod - @abstractmethod - def cancelled_exception_class(cls) -> type[BaseException]: - """Return the exception class that is raised in a task if it's cancelled.""" - - @classmethod - @abstractmethod - async def checkpoint(cls) -> None: - """ - Check if the task has been cancelled, and allow rescheduling of other tasks. - - This is effectively the same as running :meth:`checkpoint_if_cancelled` and then - :meth:`cancel_shielded_checkpoint`. - """ - - @classmethod - async def checkpoint_if_cancelled(cls) -> None: - """ - Check if the current task group has been cancelled. - - This will check if the task has been cancelled, but will not allow other tasks - to be scheduled if not. - - """ - if cls.current_effective_deadline() == -math.inf: - await cls.checkpoint() - - @classmethod - async def cancel_shielded_checkpoint(cls) -> None: - """ - Allow the rescheduling of other tasks. - - This will give other tasks the opportunity to run, but without checking if the - current task group has been cancelled, unlike with :meth:`checkpoint`. - - """ - with cls.create_cancel_scope(shield=True): - await cls.sleep(0) - - @classmethod - @abstractmethod - async def sleep(cls, delay: float) -> None: - """ - Pause the current task for the specified duration. - - :param delay: the duration, in seconds - """ - - @classmethod - @abstractmethod - def create_cancel_scope( - cls, *, deadline: float = math.inf, shield: bool = False - ) -> CancelScope: - pass - - @classmethod - @abstractmethod - def current_effective_deadline(cls) -> float: - """ - Return the nearest deadline among all the cancel scopes effective for the - current task. - - :return: - - a clock value from the event loop's internal clock - - ``inf`` if there is no deadline in effect - - ``-inf`` if the current scope has been cancelled - :rtype: float - """ - - @classmethod - @abstractmethod - def create_task_group(cls) -> TaskGroup: - pass - - @classmethod - @abstractmethod - def create_event(cls) -> Event: - pass - - @classmethod - @abstractmethod - def create_lock(cls, *, fast_acquire: bool) -> Lock: - pass - - @classmethod - @abstractmethod - def create_semaphore( - cls, - initial_value: int, - *, - max_value: int | None = None, - fast_acquire: bool = False, - ) -> Semaphore: - pass - - @classmethod - @abstractmethod - def create_capacity_limiter(cls, total_tokens: float) -> CapacityLimiter: - pass - - @classmethod - @abstractmethod - async def run_sync_in_worker_thread( - cls, - func: Callable[[Unpack[PosArgsT]], T_Retval], - args: tuple[Unpack[PosArgsT]], - abandon_on_cancel: bool = False, - limiter: CapacityLimiter | None = None, - ) -> T_Retval: - pass - - @classmethod - @abstractmethod - def check_cancelled(cls) -> None: - pass - - @classmethod - @abstractmethod - def run_async_from_thread( - cls, - func: Callable[[Unpack[PosArgsT]], Awaitable[T_Retval]], - args: tuple[Unpack[PosArgsT]], - token: object, - ) -> T_Retval: - pass - - @classmethod - @abstractmethod - def run_sync_from_thread( - cls, - func: Callable[[Unpack[PosArgsT]], T_Retval], - args: tuple[Unpack[PosArgsT]], - token: object, - ) -> T_Retval: - pass - - @classmethod - @abstractmethod - async def open_process( - cls, - command: StrOrBytesPath | Sequence[StrOrBytesPath], - *, - stdin: int | IO[Any] | None, - stdout: int | IO[Any] | None, - stderr: int | IO[Any] | None, - **kwargs: Any, - ) -> Process: - pass - - @classmethod - @abstractmethod - def setup_process_pool_exit_at_shutdown(cls, workers: set[Process]) -> None: - pass - - @classmethod - @abstractmethod - async def connect_tcp( - cls, host: str, port: int, local_address: IPSockAddrType | None = None - ) -> SocketStream: - pass - - @classmethod - @abstractmethod - async def connect_unix(cls, path: str | bytes) -> UNIXSocketStream: - pass - - @classmethod - @abstractmethod - def create_tcp_listener(cls, sock: socket) -> SocketListener: - pass - - @classmethod - @abstractmethod - def create_unix_listener(cls, sock: socket) -> SocketListener: - pass - - @classmethod - @abstractmethod - async def create_udp_socket( - cls, - family: AddressFamily, - local_address: IPSockAddrType | None, - remote_address: IPSockAddrType | None, - reuse_port: bool, - ) -> UDPSocket | ConnectedUDPSocket: - pass - - @classmethod - @overload - async def create_unix_datagram_socket( - cls, raw_socket: socket, remote_path: None - ) -> UNIXDatagramSocket: ... - - @classmethod - @overload - async def create_unix_datagram_socket( - cls, raw_socket: socket, remote_path: str | bytes - ) -> ConnectedUNIXDatagramSocket: ... - - @classmethod - @abstractmethod - async def create_unix_datagram_socket( - cls, raw_socket: socket, remote_path: str | bytes | None - ) -> UNIXDatagramSocket | ConnectedUNIXDatagramSocket: - pass - - @classmethod - @abstractmethod - async def getaddrinfo( - cls, - host: bytes | str | None, - port: str | int | None, - *, - family: int | AddressFamily = 0, - type: int | SocketKind = 0, - proto: int = 0, - flags: int = 0, - ) -> Sequence[ - tuple[ - AddressFamily, - SocketKind, - int, - str, - tuple[str, int] | tuple[str, int, int, int] | tuple[int, bytes], - ] - ]: - pass - - @classmethod - @abstractmethod - async def getnameinfo( - cls, sockaddr: IPSockAddrType, flags: int = 0 - ) -> tuple[str, str]: - pass - - @classmethod - @abstractmethod - async def wait_readable(cls, obj: FileDescriptorLike) -> None: - pass - - @classmethod - @abstractmethod - async def wait_writable(cls, obj: FileDescriptorLike) -> None: - pass - - @classmethod - @abstractmethod - def notify_closing(cls, obj: FileDescriptorLike) -> None: - pass - - @classmethod - @abstractmethod - async def wrap_listener_socket(cls, sock: socket) -> SocketListener: - pass - - @classmethod - @abstractmethod - async def wrap_stream_socket(cls, sock: socket) -> SocketStream: - pass - - @classmethod - @abstractmethod - async def wrap_unix_stream_socket(cls, sock: socket) -> UNIXSocketStream: - pass - - @classmethod - @abstractmethod - async def wrap_udp_socket(cls, sock: socket) -> UDPSocket: - pass - - @classmethod - @abstractmethod - async def wrap_connected_udp_socket(cls, sock: socket) -> ConnectedUDPSocket: - pass - - @classmethod - @abstractmethod - async def wrap_unix_datagram_socket(cls, sock: socket) -> UNIXDatagramSocket: - pass - - @classmethod - @abstractmethod - async def wrap_connected_unix_datagram_socket( - cls, sock: socket - ) -> ConnectedUNIXDatagramSocket: - pass - - @classmethod - @abstractmethod - def current_default_thread_limiter(cls) -> CapacityLimiter: - pass - - @classmethod - @abstractmethod - def open_signal_receiver( - cls, *signals: Signals - ) -> AbstractContextManager[AsyncIterator[Signals]]: - pass - - @classmethod - @abstractmethod - def get_current_task(cls) -> TaskInfo: - pass - - @classmethod - @abstractmethod - def get_running_tasks(cls) -> Sequence[TaskInfo]: - pass - - @classmethod - @abstractmethod - async def wait_all_tasks_blocked(cls) -> None: - pass - - @classmethod - @abstractmethod - def create_test_runner(cls, options: dict[str, Any]) -> TestRunner: - pass diff --git a/.venv/lib/python3.12/site-packages/anyio/abc/_resources.py b/.venv/lib/python3.12/site-packages/anyio/abc/_resources.py deleted file mode 100644 index 10df115..0000000 --- a/.venv/lib/python3.12/site-packages/anyio/abc/_resources.py +++ /dev/null @@ -1,33 +0,0 @@ -from __future__ import annotations - -from abc import ABCMeta, abstractmethod -from types import TracebackType -from typing import TypeVar - -T = TypeVar("T") - - -class AsyncResource(metaclass=ABCMeta): - """ - Abstract base class for all closeable asynchronous resources. - - Works as an asynchronous context manager which returns the instance itself on enter, - and calls :meth:`aclose` on exit. - """ - - __slots__ = () - - async def __aenter__(self: T) -> T: - return self - - async def __aexit__( - self, - exc_type: type[BaseException] | None, - exc_val: BaseException | None, - exc_tb: TracebackType | None, - ) -> None: - await self.aclose() - - @abstractmethod - async def aclose(self) -> None: - """Close the resource.""" diff --git a/.venv/lib/python3.12/site-packages/anyio/abc/_sockets.py b/.venv/lib/python3.12/site-packages/anyio/abc/_sockets.py deleted file mode 100644 index feb26bd..0000000 --- a/.venv/lib/python3.12/site-packages/anyio/abc/_sockets.py +++ /dev/null @@ -1,399 +0,0 @@ -from __future__ import annotations - -import errno -import socket -from abc import abstractmethod -from collections.abc import Callable, Collection, Mapping -from contextlib import AsyncExitStack -from io import IOBase -from ipaddress import IPv4Address, IPv6Address -from socket import AddressFamily -from typing import Any, TypeAlias, TypeVar - -from .._core._eventloop import get_async_backend -from .._core._typedattr import ( - TypedAttributeProvider, - TypedAttributeSet, - typed_attribute, -) -from ._streams import ByteStream, Listener, UnreliableObjectStream -from ._tasks import TaskGroup - -IPAddressType: TypeAlias = str | IPv4Address | IPv6Address -IPSockAddrType: TypeAlias = tuple[str, int] -SockAddrType: TypeAlias = IPSockAddrType | str -UDPPacketType: TypeAlias = tuple[bytes, IPSockAddrType] -UNIXDatagramPacketType: TypeAlias = tuple[bytes, str] -T_Retval = TypeVar("T_Retval") - - -def _validate_socket( - sock_or_fd: socket.socket | int, - sock_type: socket.SocketKind, - addr_family: socket.AddressFamily = socket.AF_UNSPEC, - *, - require_connected: bool = False, - require_bound: bool = False, -) -> socket.socket: - if isinstance(sock_or_fd, int): - try: - sock = socket.socket(fileno=sock_or_fd) - except OSError as exc: - if exc.errno == errno.ENOTSOCK: - raise ValueError( - "the file descriptor does not refer to a socket" - ) from exc - elif require_connected: - raise ValueError("the socket must be connected") from exc - elif require_bound: - raise ValueError("the socket must be bound to a local address") from exc - else: - raise - elif isinstance(sock_or_fd, socket.socket): - sock = sock_or_fd - else: - raise TypeError( - f"expected an int or socket, got {type(sock_or_fd).__qualname__} instead" - ) - - try: - if require_connected: - try: - sock.getpeername() - except OSError as exc: - raise ValueError("the socket must be connected") from exc - - if require_bound: - try: - if sock.family in (socket.AF_INET, socket.AF_INET6): - bound_addr = sock.getsockname()[1] - else: - bound_addr = sock.getsockname() - except OSError: - bound_addr = None - - if not bound_addr: - raise ValueError("the socket must be bound to a local address") - - if addr_family != socket.AF_UNSPEC and sock.family != addr_family: - raise ValueError( - f"address family mismatch: expected {addr_family.name}, got " - f"{sock.family.name}" - ) - - if sock.type != sock_type: - raise ValueError( - f"socket type mismatch: expected {sock_type.name}, got {sock.type.name}" - ) - except BaseException: - # Avoid ResourceWarning from the locally constructed socket object - if isinstance(sock_or_fd, int): - sock.detach() - - raise - - sock.setblocking(False) - return sock - - -class SocketAttribute(TypedAttributeSet): - """ - .. attribute:: family - :type: socket.AddressFamily - - the address family of the underlying socket - - .. attribute:: local_address - :type: tuple[str, int] | str - - the local address the underlying socket is connected to - - .. attribute:: local_port - :type: int - - for IP based sockets, the local port the underlying socket is bound to - - .. attribute:: raw_socket - :type: socket.socket - - the underlying stdlib socket object - - .. attribute:: remote_address - :type: tuple[str, int] | str - - the remote address the underlying socket is connected to - - .. attribute:: remote_port - :type: int - - for IP based sockets, the remote port the underlying socket is connected to - """ - - family: AddressFamily = typed_attribute() - local_address: SockAddrType = typed_attribute() - local_port: int = typed_attribute() - raw_socket: socket.socket = typed_attribute() - remote_address: SockAddrType = typed_attribute() - remote_port: int = typed_attribute() - - -class _SocketProvider(TypedAttributeProvider): - @property - def extra_attributes(self) -> Mapping[Any, Callable[[], Any]]: - from .._core._sockets import convert_ipv6_sockaddr as convert - - attributes: dict[Any, Callable[[], Any]] = { - SocketAttribute.family: lambda: self._raw_socket.family, - SocketAttribute.local_address: lambda: convert( - self._raw_socket.getsockname() - ), - SocketAttribute.raw_socket: lambda: self._raw_socket, - } - try: - peername: tuple[str, int] | None = convert(self._raw_socket.getpeername()) - except OSError: - peername = None - - # Provide the remote address for connected sockets - if peername is not None: - attributes[SocketAttribute.remote_address] = lambda: peername - - # Provide local and remote ports for IP based sockets - if self._raw_socket.family in (AddressFamily.AF_INET, AddressFamily.AF_INET6): - attributes[SocketAttribute.local_port] = lambda: ( - self._raw_socket.getsockname()[1] - ) - if peername is not None: - remote_port = peername[1] - attributes[SocketAttribute.remote_port] = lambda: remote_port - - return attributes - - @property - @abstractmethod - def _raw_socket(self) -> socket.socket: - pass - - -class SocketStream(ByteStream, _SocketProvider): - """ - Transports bytes over a socket. - - Supports all relevant extra attributes from :class:`~SocketAttribute`. - """ - - @classmethod - async def from_socket(cls, sock_or_fd: socket.socket | int) -> SocketStream: - """ - Wrap an existing socket object or file descriptor as a socket stream. - - The newly created socket wrapper takes ownership of the socket being passed in. - The existing socket must already be connected. - - :param sock_or_fd: a socket object or file descriptor - :return: a socket stream - - """ - sock = _validate_socket(sock_or_fd, socket.SOCK_STREAM, require_connected=True) - return await get_async_backend().wrap_stream_socket(sock) - - -class UNIXSocketStream(SocketStream): - @classmethod - async def from_socket(cls, sock_or_fd: socket.socket | int) -> UNIXSocketStream: - """ - Wrap an existing socket object or file descriptor as a UNIX socket stream. - - The newly created socket wrapper takes ownership of the socket being passed in. - The existing socket must already be connected. - - :param sock_or_fd: a socket object or file descriptor - :return: a UNIX socket stream - - """ - sock = _validate_socket( - sock_or_fd, socket.SOCK_STREAM, socket.AF_UNIX, require_connected=True - ) - return await get_async_backend().wrap_unix_stream_socket(sock) - - @abstractmethod - async def send_fds(self, message: bytes, fds: Collection[int | IOBase]) -> None: - """ - Send file descriptors along with a message to the peer. - - :param message: a non-empty bytestring - :param fds: a collection of files (either numeric file descriptors or open file - or socket objects) - """ - - @abstractmethod - async def receive_fds(self, msglen: int, maxfds: int) -> tuple[bytes, list[int]]: - """ - Receive file descriptors along with a message from the peer. - - :param msglen: length of the message to expect from the peer - :param maxfds: maximum number of file descriptors to expect from the peer - :return: a tuple of (message, file descriptors) - """ - - -class SocketListener(Listener[SocketStream], _SocketProvider): - """ - Listens to incoming socket connections. - - Supports all relevant extra attributes from :class:`~SocketAttribute`. - """ - - @classmethod - async def from_socket( - cls, - sock_or_fd: socket.socket | int, - ) -> SocketListener: - """ - Wrap an existing socket object or file descriptor as a socket listener. - - The newly created listener takes ownership of the socket being passed in. - - :param sock_or_fd: a socket object or file descriptor - :return: a socket listener - - """ - sock = _validate_socket(sock_or_fd, socket.SOCK_STREAM, require_bound=True) - return await get_async_backend().wrap_listener_socket(sock) - - @abstractmethod - async def accept(self) -> SocketStream: - """Accept an incoming connection.""" - - async def serve( - self, - handler: Callable[[SocketStream], Any], - task_group: TaskGroup | None = None, - ) -> None: - from .. import create_task_group - - async with AsyncExitStack() as stack: - if task_group is None: - task_group = await stack.enter_async_context(create_task_group()) - - while True: - stream = await self.accept() - task_group.start_soon(handler, stream) - - -class UDPSocket(UnreliableObjectStream[UDPPacketType], _SocketProvider): - """ - Represents an unconnected UDP socket. - - Supports all relevant extra attributes from :class:`~SocketAttribute`. - """ - - @classmethod - async def from_socket(cls, sock_or_fd: socket.socket | int) -> UDPSocket: - """ - Wrap an existing socket object or file descriptor as a UDP socket. - - The newly created socket wrapper takes ownership of the socket being passed in. - The existing socket must be bound to a local address. - - :param sock_or_fd: a socket object or file descriptor - :return: a UDP socket - - """ - sock = _validate_socket(sock_or_fd, socket.SOCK_DGRAM, require_bound=True) - return await get_async_backend().wrap_udp_socket(sock) - - async def sendto(self, data: bytes, host: str, port: int) -> None: - """ - Alias for :meth:`~.UnreliableObjectSendStream.send` ((data, (host, port))). - - """ - return await self.send((data, (host, port))) - - -class ConnectedUDPSocket(UnreliableObjectStream[bytes], _SocketProvider): - """ - Represents an connected UDP socket. - - Supports all relevant extra attributes from :class:`~SocketAttribute`. - """ - - @classmethod - async def from_socket(cls, sock_or_fd: socket.socket | int) -> ConnectedUDPSocket: - """ - Wrap an existing socket object or file descriptor as a connected UDP socket. - - The newly created socket wrapper takes ownership of the socket being passed in. - The existing socket must already be connected. - - :param sock_or_fd: a socket object or file descriptor - :return: a connected UDP socket - - """ - sock = _validate_socket( - sock_or_fd, - socket.SOCK_DGRAM, - require_connected=True, - ) - return await get_async_backend().wrap_connected_udp_socket(sock) - - -class UNIXDatagramSocket( - UnreliableObjectStream[UNIXDatagramPacketType], _SocketProvider -): - """ - Represents an unconnected Unix datagram socket. - - Supports all relevant extra attributes from :class:`~SocketAttribute`. - """ - - @classmethod - async def from_socket( - cls, - sock_or_fd: socket.socket | int, - ) -> UNIXDatagramSocket: - """ - Wrap an existing socket object or file descriptor as a UNIX datagram - socket. - - The newly created socket wrapper takes ownership of the socket being passed in. - - :param sock_or_fd: a socket object or file descriptor - :return: a UNIX datagram socket - - """ - sock = _validate_socket(sock_or_fd, socket.SOCK_DGRAM, socket.AF_UNIX) - return await get_async_backend().wrap_unix_datagram_socket(sock) - - async def sendto(self, data: bytes, path: str) -> None: - """Alias for :meth:`~.UnreliableObjectSendStream.send` ((data, path)).""" - return await self.send((data, path)) - - -class ConnectedUNIXDatagramSocket(UnreliableObjectStream[bytes], _SocketProvider): - """ - Represents a connected Unix datagram socket. - - Supports all relevant extra attributes from :class:`~SocketAttribute`. - """ - - @classmethod - async def from_socket( - cls, - sock_or_fd: socket.socket | int, - ) -> ConnectedUNIXDatagramSocket: - """ - Wrap an existing socket object or file descriptor as a connected UNIX datagram - socket. - - The newly created socket wrapper takes ownership of the socket being passed in. - The existing socket must already be connected. - - :param sock_or_fd: a socket object or file descriptor - :return: a connected UNIX datagram socket - - """ - sock = _validate_socket( - sock_or_fd, socket.SOCK_DGRAM, socket.AF_UNIX, require_connected=True - ) - return await get_async_backend().wrap_connected_unix_datagram_socket(sock) diff --git a/.venv/lib/python3.12/site-packages/anyio/abc/_streams.py b/.venv/lib/python3.12/site-packages/anyio/abc/_streams.py deleted file mode 100644 index 186e3f5..0000000 --- a/.venv/lib/python3.12/site-packages/anyio/abc/_streams.py +++ /dev/null @@ -1,233 +0,0 @@ -from __future__ import annotations - -from abc import ABCMeta, abstractmethod -from collections.abc import Callable -from typing import Any, Generic, TypeAlias, TypeVar - -from .._core._exceptions import EndOfStream -from .._core._typedattr import TypedAttributeProvider -from ._resources import AsyncResource -from ._tasks import TaskGroup - -T_Item = TypeVar("T_Item") -T_co = TypeVar("T_co", covariant=True) -T_contra = TypeVar("T_contra", contravariant=True) - - -class UnreliableObjectReceiveStream( - Generic[T_co], AsyncResource, TypedAttributeProvider -): - """ - An interface for receiving objects. - - This interface makes no guarantees that the received messages arrive in the order in - which they were sent, or that no messages are missed. - - Asynchronously iterating over objects of this type will yield objects matching the - given type parameter. - """ - - def __aiter__(self) -> UnreliableObjectReceiveStream[T_co]: - return self - - async def __anext__(self) -> T_co: - try: - return await self.receive() - except EndOfStream: - raise StopAsyncIteration from None - - @abstractmethod - async def receive(self) -> T_co: - """ - Receive the next item. - - :raises ~anyio.ClosedResourceError: if the receive stream has been explicitly - closed - :raises ~anyio.EndOfStream: if this stream has been closed from the other end - :raises ~anyio.BrokenResourceError: if this stream has been rendered unusable - due to external causes - """ - - -class UnreliableObjectSendStream( - Generic[T_contra], AsyncResource, TypedAttributeProvider -): - """ - An interface for sending objects. - - This interface makes no guarantees that the messages sent will reach the - recipient(s) in the same order in which they were sent, or at all. - """ - - @abstractmethod - async def send(self, item: T_contra) -> None: - """ - Send an item to the peer(s). - - :param item: the item to send - :raises ~anyio.ClosedResourceError: if the send stream has been explicitly - closed - :raises ~anyio.BrokenResourceError: if this stream has been rendered unusable - due to external causes - """ - - -class UnreliableObjectStream( - UnreliableObjectReceiveStream[T_Item], UnreliableObjectSendStream[T_Item] -): - """ - A bidirectional message stream which does not guarantee the order or reliability of - message delivery. - """ - - -class ObjectReceiveStream(UnreliableObjectReceiveStream[T_co]): - """ - A receive message stream which guarantees that messages are received in the same - order in which they were sent, and that no messages are missed. - """ - - -class ObjectSendStream(UnreliableObjectSendStream[T_contra]): - """ - A send message stream which guarantees that messages are delivered in the same order - in which they were sent, without missing any messages in the middle. - """ - - -class ObjectStream( - ObjectReceiveStream[T_Item], - ObjectSendStream[T_Item], - UnreliableObjectStream[T_Item], -): - """ - A bidirectional message stream which guarantees the order and reliability of message - delivery. - """ - - @abstractmethod - async def send_eof(self) -> None: - """ - Send an end-of-file indication to the peer. - - You should not try to send any further data to this stream after calling this - method. This method is idempotent (does nothing on successive calls). - """ - - -class ByteReceiveStream(AsyncResource, TypedAttributeProvider): - """ - An interface for receiving bytes from a single peer. - - Iterating this byte stream will yield a byte string of arbitrary length, but no more - than 65536 bytes. - """ - - def __aiter__(self) -> ByteReceiveStream: - return self - - async def __anext__(self) -> bytes: - try: - return await self.receive() - except EndOfStream: - raise StopAsyncIteration from None - - @abstractmethod - async def receive(self, max_bytes: int = 65536) -> bytes: - """ - Receive at most ``max_bytes`` bytes from the peer. - - .. note:: Implementers of this interface should not return an empty - :class:`bytes` object, and users should ignore them. - - :param max_bytes: maximum number of bytes to receive - :return: the received bytes - :raises ~anyio.EndOfStream: if this stream has been closed from the other end - """ - - -class ByteSendStream(AsyncResource, TypedAttributeProvider): - """An interface for sending bytes to a single peer.""" - - @abstractmethod - async def send(self, item: bytes) -> None: - """ - Send the given bytes to the peer. - - :param item: the bytes to send - """ - - -class ByteStream(ByteReceiveStream, ByteSendStream): - """A bidirectional byte stream.""" - - @abstractmethod - async def send_eof(self) -> None: - """ - Send an end-of-file indication to the peer. - - You should not try to send any further data to this stream after calling this - method. This method is idempotent (does nothing on successive calls). - """ - - -#: Type alias for all unreliable bytes-oriented receive streams. -AnyUnreliableByteReceiveStream: TypeAlias = ( - UnreliableObjectReceiveStream[bytes] | ByteReceiveStream -) -#: Type alias for all unreliable bytes-oriented send streams. -AnyUnreliableByteSendStream: TypeAlias = ( - UnreliableObjectSendStream[bytes] | ByteSendStream -) -#: Type alias for all unreliable bytes-oriented streams. -AnyUnreliableByteStream: TypeAlias = UnreliableObjectStream[bytes] | ByteStream -#: Type alias for all bytes-oriented receive streams. -AnyByteReceiveStream: TypeAlias = ObjectReceiveStream[bytes] | ByteReceiveStream -#: Type alias for all bytes-oriented send streams. -AnyByteSendStream: TypeAlias = ObjectSendStream[bytes] | ByteSendStream -#: Type alias for all bytes-oriented streams. -AnyByteStream: TypeAlias = ObjectStream[bytes] | ByteStream - - -class Listener(Generic[T_co], AsyncResource, TypedAttributeProvider): - """An interface for objects that let you accept incoming connections.""" - - @abstractmethod - async def serve( - self, handler: Callable[[T_co], Any], task_group: TaskGroup | None = None - ) -> None: - """ - Accept incoming connections as they come in and start tasks to handle them. - - :param handler: a callable that will be used to handle each accepted connection - :param task_group: the task group that will be used to start tasks for handling - each accepted connection (if omitted, an ad-hoc task group will be created) - """ - - -class ObjectStreamConnectable(Generic[T_co], metaclass=ABCMeta): - @abstractmethod - async def connect(self) -> ObjectStream[T_co]: - """ - Connect to the remote endpoint. - - :return: an object stream connected to the remote end - :raises ConnectionFailed: if the connection fails - """ - - -class ByteStreamConnectable(metaclass=ABCMeta): - @abstractmethod - async def connect(self) -> ByteStream: - """ - Connect to the remote endpoint. - - :return: a bytestream connected to the remote end - :raises ConnectionFailed: if the connection fails - """ - - -#: Type alias for all connectables returning bytestreams or bytes-oriented object streams -AnyByteStreamConnectable: TypeAlias = ( - ObjectStreamConnectable[bytes] | ByteStreamConnectable -) diff --git a/.venv/lib/python3.12/site-packages/anyio/abc/_subprocesses.py b/.venv/lib/python3.12/site-packages/anyio/abc/_subprocesses.py deleted file mode 100644 index ce0564c..0000000 --- a/.venv/lib/python3.12/site-packages/anyio/abc/_subprocesses.py +++ /dev/null @@ -1,79 +0,0 @@ -from __future__ import annotations - -from abc import abstractmethod -from signal import Signals - -from ._resources import AsyncResource -from ._streams import ByteReceiveStream, ByteSendStream - - -class Process(AsyncResource): - """An asynchronous version of :class:`subprocess.Popen`.""" - - @abstractmethod - async def wait(self) -> int: - """ - Wait until the process exits. - - :return: the exit code of the process - """ - - @abstractmethod - def terminate(self) -> None: - """ - Terminates the process, gracefully if possible. - - On Windows, this calls ``TerminateProcess()``. - On POSIX systems, this sends ``SIGTERM`` to the process. - - .. seealso:: :meth:`subprocess.Popen.terminate` - """ - - @abstractmethod - def kill(self) -> None: - """ - Kills the process. - - On Windows, this calls ``TerminateProcess()``. - On POSIX systems, this sends ``SIGKILL`` to the process. - - .. seealso:: :meth:`subprocess.Popen.kill` - """ - - @abstractmethod - def send_signal(self, signal: Signals) -> None: - """ - Send a signal to the subprocess. - - .. seealso:: :meth:`subprocess.Popen.send_signal` - - :param signal: the signal number (e.g. :data:`signal.SIGHUP`) - """ - - @property - @abstractmethod - def pid(self) -> int: - """The process ID of the process.""" - - @property - @abstractmethod - def returncode(self) -> int | None: - """ - The return code of the process. If the process has not yet terminated, this will - be ``None``. - """ - - @property - @abstractmethod - def stdin(self) -> ByteSendStream | None: - """The stream for the standard input of the process.""" - - @property - @abstractmethod - def stdout(self) -> ByteReceiveStream | None: - """The stream for the standard output of the process.""" - - @property - @abstractmethod - def stderr(self) -> ByteReceiveStream | None: - """The stream for the standard error output of the process.""" diff --git a/.venv/lib/python3.12/site-packages/anyio/abc/_tasks.py b/.venv/lib/python3.12/site-packages/anyio/abc/_tasks.py deleted file mode 100644 index 516b3ec..0000000 --- a/.venv/lib/python3.12/site-packages/anyio/abc/_tasks.py +++ /dev/null @@ -1,117 +0,0 @@ -from __future__ import annotations - -import sys -from abc import ABCMeta, abstractmethod -from collections.abc import Awaitable, Callable -from types import TracebackType -from typing import TYPE_CHECKING, Any, Protocol, overload - -if sys.version_info >= (3, 13): - from typing import TypeVar -else: - from typing_extensions import TypeVar - -if sys.version_info >= (3, 11): - from typing import TypeVarTuple, Unpack -else: - from typing_extensions import TypeVarTuple, Unpack - -if TYPE_CHECKING: - from .._core._tasks import CancelScope - -T_Retval = TypeVar("T_Retval") -T_contra = TypeVar("T_contra", contravariant=True, default=None) -PosArgsT = TypeVarTuple("PosArgsT") - - -class TaskStatus(Protocol[T_contra]): - @overload - def started(self: TaskStatus[None]) -> None: ... - - @overload - def started(self, value: T_contra) -> None: ... - - def started(self, value: T_contra | None = None) -> None: - """ - Signal that the task has started. - - :param value: object passed back to the starter of the task - """ - - -class TaskGroup(metaclass=ABCMeta): - """ - Groups several asynchronous tasks together. - - :ivar cancel_scope: the cancel scope inherited by all child tasks - :vartype cancel_scope: CancelScope - - .. note:: On asyncio, support for eager task factories is considered to be - **experimental**. In particular, they don't follow the usual semantics of new - tasks being scheduled on the next iteration of the event loop, and may thus - cause unexpected behavior in code that wasn't written with such semantics in - mind. - """ - - cancel_scope: CancelScope - - @abstractmethod - def start_soon( - self, - func: Callable[[Unpack[PosArgsT]], Awaitable[Any]], - *args: Unpack[PosArgsT], - name: object = None, - ) -> None: - """ - Start a new task in this task group. - - :param func: a coroutine function - :param args: positional arguments to call the function with - :param name: name of the task, for the purposes of introspection and debugging - - .. versionadded:: 3.0 - """ - - @abstractmethod - async def start( - self, - func: Callable[..., Awaitable[Any]], - *args: object, - name: object = None, - ) -> Any: - """ - Start a new task and wait until it signals for readiness. - - The target callable must accept a keyword argument ``task_status`` (of type - :class:`TaskStatus`). Awaiting on this method will return whatever was passed to - ``task_status.started()`` (``None`` by default). - - .. note:: The :class:`TaskStatus` class is generic, and the type argument should - indicate the type of the value that will be passed to - ``task_status.started()``. - - :param func: a coroutine function that accepts the ``task_status`` keyword - argument - :param args: positional arguments to call the function with - :param name: an optional name for the task, for introspection and debugging - :return: the value passed to ``task_status.started()`` - :raises RuntimeError: if the task finishes without calling - ``task_status.started()`` - - .. seealso:: :ref:`start_initialize` - - .. versionadded:: 3.0 - """ - - @abstractmethod - async def __aenter__(self) -> TaskGroup: - """Enter the task group context and allow starting new tasks.""" - - @abstractmethod - async def __aexit__( - self, - exc_type: type[BaseException] | None, - exc_val: BaseException | None, - exc_tb: TracebackType | None, - ) -> bool: - """Exit the task group context waiting for all tasks to finish.""" diff --git a/.venv/lib/python3.12/site-packages/anyio/abc/_testing.py b/.venv/lib/python3.12/site-packages/anyio/abc/_testing.py deleted file mode 100644 index 7c50ed7..0000000 --- a/.venv/lib/python3.12/site-packages/anyio/abc/_testing.py +++ /dev/null @@ -1,65 +0,0 @@ -from __future__ import annotations - -import types -from abc import ABCMeta, abstractmethod -from collections.abc import AsyncGenerator, Callable, Coroutine, Iterable -from typing import Any, TypeVar - -_T = TypeVar("_T") - - -class TestRunner(metaclass=ABCMeta): - """ - Encapsulates a running event loop. Every call made through this object will use the - same event loop. - """ - - def __enter__(self) -> TestRunner: - return self - - @abstractmethod - def __exit__( - self, - exc_type: type[BaseException] | None, - exc_val: BaseException | None, - exc_tb: types.TracebackType | None, - ) -> bool | None: ... - - @abstractmethod - def run_asyncgen_fixture( - self, - fixture_func: Callable[..., AsyncGenerator[_T, Any]], - kwargs: dict[str, Any], - ) -> Iterable[_T]: - """ - Run an async generator fixture. - - :param fixture_func: the fixture function - :param kwargs: keyword arguments to call the fixture function with - :return: an iterator yielding the value yielded from the async generator - """ - - @abstractmethod - def run_fixture( - self, - fixture_func: Callable[..., Coroutine[Any, Any, _T]], - kwargs: dict[str, Any], - ) -> _T: - """ - Run an async fixture. - - :param fixture_func: the fixture function - :param kwargs: keyword arguments to call the fixture function with - :return: the return value of the fixture function - """ - - @abstractmethod - def run_test( - self, test_func: Callable[..., Coroutine[Any, Any, Any]], kwargs: dict[str, Any] - ) -> None: - """ - Run an async test function. - - :param test_func: the test function - :param kwargs: keyword arguments to call the test function with - """ diff --git a/.venv/lib/python3.12/site-packages/anyio/from_thread.py b/.venv/lib/python3.12/site-packages/anyio/from_thread.py deleted file mode 100644 index 837de5e..0000000 --- a/.venv/lib/python3.12/site-packages/anyio/from_thread.py +++ /dev/null @@ -1,578 +0,0 @@ -from __future__ import annotations - -__all__ = ( - "BlockingPortal", - "BlockingPortalProvider", - "check_cancelled", - "run", - "run_sync", - "start_blocking_portal", -) - -import sys -from collections.abc import Awaitable, Callable, Generator -from concurrent.futures import Future -from contextlib import ( - AbstractAsyncContextManager, - AbstractContextManager, - contextmanager, -) -from dataclasses import dataclass, field -from functools import partial -from inspect import isawaitable -from threading import Lock, Thread, current_thread, get_ident -from types import TracebackType -from typing import ( - Any, - Generic, - TypeVar, - cast, - overload, -) - -from ._core._eventloop import ( - get_cancelled_exc_class, - threadlocals, -) -from ._core._eventloop import run as run_eventloop -from ._core._exceptions import NoEventLoopError -from ._core._synchronization import Event -from ._core._tasks import CancelScope, create_task_group -from .abc._tasks import TaskStatus -from .lowlevel import EventLoopToken, current_token - -if sys.version_info >= (3, 11): - from typing import TypeVarTuple, Unpack -else: - from typing_extensions import TypeVarTuple, Unpack - -T_Retval = TypeVar("T_Retval") -T_co = TypeVar("T_co", covariant=True) -PosArgsT = TypeVarTuple("PosArgsT") - - -def _token_or_error(token: EventLoopToken | None) -> EventLoopToken: - if token is not None: - return token - - try: - return threadlocals.current_token - except AttributeError: - raise NoEventLoopError( - "Not running inside an AnyIO worker thread, and no event loop token was " - "provided" - ) from None - - -def run( - func: Callable[[Unpack[PosArgsT]], Awaitable[T_Retval]], - *args: Unpack[PosArgsT], - token: EventLoopToken | None = None, -) -> T_Retval: - """ - Call a coroutine function from a worker thread. - - :param func: a coroutine function - :param args: positional arguments for the callable - :param token: an event loop token to use to get back to the event loop thread - (required if calling this function from outside an AnyIO worker thread) - :return: the return value of the coroutine function - :raises MissingTokenError: if no token was provided and called from outside an - AnyIO worker thread - :raises RunFinishedError: if the event loop tied to ``token`` is no longer running - - .. versionchanged:: 4.11.0 - Added the ``token`` parameter. - - """ - explicit_token = token is not None - token = _token_or_error(token) - return token.backend_class.run_async_from_thread( - func, args, token=token.native_token if explicit_token else None - ) - - -def run_sync( - func: Callable[[Unpack[PosArgsT]], T_Retval], - *args: Unpack[PosArgsT], - token: EventLoopToken | None = None, -) -> T_Retval: - """ - Call a function in the event loop thread from a worker thread. - - :param func: a callable - :param args: positional arguments for the callable - :param token: an event loop token to use to get back to the event loop thread - (required if calling this function from outside an AnyIO worker thread) - :return: the return value of the callable - :raises MissingTokenError: if no token was provided and called from outside an - AnyIO worker thread - :raises RunFinishedError: if the event loop tied to ``token`` is no longer running - - .. versionchanged:: 4.11.0 - Added the ``token`` parameter. - - """ - explicit_token = token is not None - token = _token_or_error(token) - return token.backend_class.run_sync_from_thread( - func, args, token=token.native_token if explicit_token else None - ) - - -class _BlockingAsyncContextManager(Generic[T_co], AbstractContextManager): - _enter_future: Future[T_co] - _exit_future: Future[bool | None] - _exit_event: Event - _exit_exc_info: tuple[ - type[BaseException] | None, BaseException | None, TracebackType | None - ] = (None, None, None) - - def __init__( - self, async_cm: AbstractAsyncContextManager[T_co], portal: BlockingPortal - ): - self._async_cm = async_cm - self._portal = portal - - async def run_async_cm(self) -> bool | None: - try: - self._exit_event = Event() - value = await self._async_cm.__aenter__() - except BaseException as exc: - self._enter_future.set_exception(exc) - raise - else: - self._enter_future.set_result(value) - - try: - # Wait for the sync context manager to exit. - # This next statement can raise `get_cancelled_exc_class()` if - # something went wrong in a task group in this async context - # manager. - await self._exit_event.wait() - finally: - # In case of cancellation, it could be that we end up here before - # `_BlockingAsyncContextManager.__exit__` is called, and an - # `_exit_exc_info` has been set. - result = await self._async_cm.__aexit__(*self._exit_exc_info) - - return result - - def __enter__(self) -> T_co: - self._enter_future = Future() - self._exit_future = self._portal.start_task_soon(self.run_async_cm) - return self._enter_future.result() - - def __exit__( - self, - __exc_type: type[BaseException] | None, - __exc_value: BaseException | None, - __traceback: TracebackType | None, - ) -> bool | None: - self._exit_exc_info = __exc_type, __exc_value, __traceback - self._portal.call(self._exit_event.set) - return self._exit_future.result() - - -class _BlockingPortalTaskStatus(TaskStatus): - def __init__(self, future: Future): - self._future = future - - def started(self, value: object = None) -> None: - self._future.set_result(value) - - -class BlockingPortal: - """ - An object that lets external threads run code in an asynchronous event loop. - - :raises NoEventLoopError: if no supported asynchronous event loop is running in the - current thread - """ - - def __init__(self) -> None: - self._token = current_token() - self._event_loop_thread_id: int | None = get_ident() - self._stop_event = Event() - self._task_group = create_task_group() - - async def __aenter__(self) -> BlockingPortal: - await self._task_group.__aenter__() - return self - - async def __aexit__( - self, - exc_type: type[BaseException] | None, - exc_val: BaseException | None, - exc_tb: TracebackType | None, - ) -> bool: - await self.stop() - return await self._task_group.__aexit__(exc_type, exc_val, exc_tb) - - def _check_running(self) -> None: - if self._event_loop_thread_id is None: - raise RuntimeError("This portal is not running") - if self._event_loop_thread_id == get_ident(): - raise RuntimeError( - "This method cannot be called from the event loop thread" - ) - - async def sleep_until_stopped(self) -> None: - """Sleep until :meth:`stop` is called.""" - await self._stop_event.wait() - - async def stop(self, cancel_remaining: bool = False) -> None: - """ - Signal the portal to shut down. - - This marks the portal as no longer accepting new calls and exits from - :meth:`sleep_until_stopped`. - - :param cancel_remaining: ``True`` to cancel all the remaining tasks, ``False`` - to let them finish before returning - - """ - self._event_loop_thread_id = None - self._stop_event.set() - if cancel_remaining: - self._task_group.cancel_scope.cancel("the blocking portal is shutting down") - - async def _call_func( - self, - func: Callable[[Unpack[PosArgsT]], Awaitable[T_Retval] | T_Retval], - args: tuple[Unpack[PosArgsT]], - kwargs: dict[str, Any], - future: Future[T_Retval], - ) -> None: - def callback(f: Future[T_Retval]) -> None: - if f.cancelled(): - if self._event_loop_thread_id == get_ident(): - scope.cancel("the future was cancelled") - elif self._event_loop_thread_id is not None: - self.call(scope.cancel, "the future was cancelled") - - try: - retval_or_awaitable = func(*args, **kwargs) - if isawaitable(retval_or_awaitable): - with CancelScope() as scope: - future.add_done_callback(callback) - retval = await retval_or_awaitable - else: - retval = retval_or_awaitable - except get_cancelled_exc_class(): - future.cancel() - future.set_running_or_notify_cancel() - except BaseException as exc: - if not future.cancelled(): - future.set_exception(exc) - - # Let base exceptions fall through - if not isinstance(exc, Exception): - raise - else: - if not future.cancelled(): - future.set_result(retval) - finally: - scope = None # type: ignore[assignment] - - def _spawn_task_from_thread( - self, - func: Callable[[Unpack[PosArgsT]], Awaitable[T_Retval] | T_Retval], - args: tuple[Unpack[PosArgsT]], - kwargs: dict[str, Any], - name: object, - future: Future[T_Retval], - ) -> None: - """ - Spawn a new task using the given callable. - - :param func: a callable - :param args: positional arguments to be passed to the callable - :param kwargs: keyword arguments to be passed to the callable - :param name: name of the task (will be coerced to a string if not ``None``) - :param future: a future that will resolve to the return value of the callable, - or the exception raised during its execution - - """ - run_sync( - partial(self._task_group.start_soon, name=name), - self._call_func, - func, - args, - kwargs, - future, - token=self._token, - ) - - @overload - def call( - self, - func: Callable[[Unpack[PosArgsT]], Awaitable[T_Retval]], - *args: Unpack[PosArgsT], - ) -> T_Retval: ... - - @overload - def call( - self, func: Callable[[Unpack[PosArgsT]], T_Retval], *args: Unpack[PosArgsT] - ) -> T_Retval: ... - - def call( - self, - func: Callable[[Unpack[PosArgsT]], Awaitable[T_Retval] | T_Retval], - *args: Unpack[PosArgsT], - ) -> T_Retval: - """ - Call the given function in the event loop thread. - - If the callable returns a coroutine object, it is awaited on. - - :param func: any callable - :raises RuntimeError: if the portal is not running or if this method is called - from within the event loop thread - - """ - return cast(T_Retval, self.start_task_soon(func, *args).result()) - - @overload - def start_task_soon( - self, - func: Callable[[Unpack[PosArgsT]], Awaitable[T_Retval]], - *args: Unpack[PosArgsT], - name: object = None, - ) -> Future[T_Retval]: ... - - @overload - def start_task_soon( - self, - func: Callable[[Unpack[PosArgsT]], T_Retval], - *args: Unpack[PosArgsT], - name: object = None, - ) -> Future[T_Retval]: ... - - def start_task_soon( - self, - func: Callable[[Unpack[PosArgsT]], Awaitable[T_Retval] | T_Retval], - *args: Unpack[PosArgsT], - name: object = None, - ) -> Future[T_Retval]: - """ - Start a task in the portal's task group. - - The task will be run inside a cancel scope which can be cancelled by cancelling - the returned future. - - :param func: the target function - :param args: positional arguments passed to ``func`` - :param name: name of the task (will be coerced to a string if not ``None``) - :return: a future that resolves with the return value of the callable if the - task completes successfully, or with the exception raised in the task - :raises RuntimeError: if the portal is not running or if this method is called - from within the event loop thread - :rtype: concurrent.futures.Future[T_Retval] - - .. versionadded:: 3.0 - - """ - self._check_running() - f: Future[T_Retval] = Future() - self._spawn_task_from_thread(func, args, {}, name, f) - return f - - def start_task( - self, - func: Callable[..., Awaitable[T_Retval]], - *args: object, - name: object = None, - ) -> tuple[Future[T_Retval], Any]: - """ - Start a task in the portal's task group and wait until it signals for readiness. - - This method works the same way as :meth:`.abc.TaskGroup.start`. - - :param func: the target function - :param args: positional arguments passed to ``func`` - :param name: name of the task (will be coerced to a string if not ``None``) - :return: a tuple of (future, task_status_value) where the ``task_status_value`` - is the value passed to ``task_status.started()`` from within the target - function - :rtype: tuple[concurrent.futures.Future[T_Retval], Any] - - .. versionadded:: 3.0 - - """ - - def task_done(future: Future[T_Retval]) -> None: - if not task_status_future.done(): - if future.cancelled(): - task_status_future.cancel() - elif future.exception(): - task_status_future.set_exception(future.exception()) - else: - exc = RuntimeError( - "Task exited without calling task_status.started()" - ) - task_status_future.set_exception(exc) - - self._check_running() - task_status_future: Future = Future() - task_status = _BlockingPortalTaskStatus(task_status_future) - f: Future = Future() - f.add_done_callback(task_done) - self._spawn_task_from_thread(func, args, {"task_status": task_status}, name, f) - return f, task_status_future.result() - - def wrap_async_context_manager( - self, cm: AbstractAsyncContextManager[T_co] - ) -> AbstractContextManager[T_co]: - """ - Wrap an async context manager as a synchronous context manager via this portal. - - Spawns a task that will call both ``__aenter__()`` and ``__aexit__()``, stopping - in the middle until the synchronous context manager exits. - - :param cm: an asynchronous context manager - :return: a synchronous context manager - - .. versionadded:: 2.1 - - """ - return _BlockingAsyncContextManager(cm, self) - - -@dataclass -class BlockingPortalProvider: - """ - A manager for a blocking portal. Used as a context manager. The first thread to - enter this context manager causes a blocking portal to be started with the specific - parameters, and the last thread to exit causes the portal to be shut down. Thus, - there will be exactly one blocking portal running in this context as long as at - least one thread has entered this context manager. - - The parameters are the same as for :func:`~anyio.run`. - - :param backend: name of the backend - :param backend_options: backend options - - .. versionadded:: 4.4 - """ - - backend: str = "asyncio" - backend_options: dict[str, Any] | None = None - _lock: Lock = field(init=False, default_factory=Lock) - _leases: int = field(init=False, default=0) - _portal: BlockingPortal = field(init=False) - _portal_cm: AbstractContextManager[BlockingPortal] | None = field( - init=False, default=None - ) - - def __enter__(self) -> BlockingPortal: - with self._lock: - if self._portal_cm is None: - self._portal_cm = start_blocking_portal( - self.backend, self.backend_options - ) - self._portal = self._portal_cm.__enter__() - - self._leases += 1 - return self._portal - - def __exit__( - self, - exc_type: type[BaseException] | None, - exc_val: BaseException | None, - exc_tb: TracebackType | None, - ) -> None: - portal_cm: AbstractContextManager[BlockingPortal] | None = None - with self._lock: - assert self._portal_cm - assert self._leases > 0 - self._leases -= 1 - if not self._leases: - portal_cm = self._portal_cm - self._portal_cm = None - del self._portal - - if portal_cm: - portal_cm.__exit__(None, None, None) - - -@contextmanager -def start_blocking_portal( - backend: str = "asyncio", - backend_options: dict[str, Any] | None = None, - *, - name: str | None = None, -) -> Generator[BlockingPortal, Any, None]: - """ - Start a new event loop in a new thread and run a blocking portal in its main task. - - The parameters are the same as for :func:`~anyio.run`. - - :param backend: name of the backend - :param backend_options: backend options - :param name: name of the thread - :return: a context manager that yields a blocking portal - - .. versionchanged:: 3.0 - Usage as a context manager is now required. - - """ - - async def run_portal() -> None: - async with BlockingPortal() as portal_: - if name is None: - current_thread().name = f"{backend}-portal-{id(portal_):x}" - - future.set_result(portal_) - await portal_.sleep_until_stopped() - - def run_blocking_portal() -> None: - if future.set_running_or_notify_cancel(): - try: - run_eventloop( - run_portal, backend=backend, backend_options=backend_options - ) - except BaseException as exc: - if not future.done(): - future.set_exception(exc) - - future: Future[BlockingPortal] = Future() - thread = Thread(target=run_blocking_portal, daemon=True, name=name) - thread.start() - try: - cancel_remaining_tasks = False - portal = future.result() - try: - yield portal - except BaseException: - cancel_remaining_tasks = True - raise - finally: - try: - portal.call(portal.stop, cancel_remaining_tasks) - except RuntimeError: - pass - finally: - thread.join() - - -def check_cancelled() -> None: - """ - Check if the cancel scope of the host task's running the current worker thread has - been cancelled. - - If the host task's current cancel scope has indeed been cancelled, the - backend-specific cancellation exception will be raised. - - :raises RuntimeError: if the current thread was not spawned by - :func:`.to_thread.run_sync` - - """ - try: - token: EventLoopToken = threadlocals.current_token - except AttributeError: - raise NoEventLoopError( - "This function can only be called inside an AnyIO worker thread" - ) from None - - token.backend_class.check_cancelled() diff --git a/.venv/lib/python3.12/site-packages/anyio/functools.py b/.venv/lib/python3.12/site-packages/anyio/functools.py deleted file mode 100644 index f1d6c7c..0000000 --- a/.venv/lib/python3.12/site-packages/anyio/functools.py +++ /dev/null @@ -1,409 +0,0 @@ -from __future__ import annotations - -__all__ = ( - "AsyncCacheInfo", - "AsyncCacheParameters", - "AsyncLRUCacheWrapper", - "cache", - "lru_cache", - "reduce", -) - -import functools -import sys -from collections import OrderedDict -from collections.abc import ( - AsyncIterable, - Awaitable, - Callable, - Coroutine, - Hashable, - Iterable, -) -from functools import update_wrapper -from inspect import iscoroutinefunction -from typing import ( - Any, - Generic, - NamedTuple, - TypedDict, - TypeVar, - cast, - final, - overload, -) -from weakref import WeakKeyDictionary - -from ._core._eventloop import current_time -from ._core._synchronization import Lock -from .lowlevel import RunVar, checkpoint - -if sys.version_info >= (3, 11): - from typing import ParamSpec -else: - from typing_extensions import ParamSpec - -T = TypeVar("T") -S = TypeVar("S") -P = ParamSpec("P") -lru_cache_items: RunVar[ - WeakKeyDictionary[ - AsyncLRUCacheWrapper[Any, Any], - OrderedDict[ - Hashable, - tuple[_InitialMissingType, Lock, float | None] - | tuple[Any, None, float | None], - ], - ] -] = RunVar("lru_cache_items") - - -class _InitialMissingType: - pass - - -initial_missing: _InitialMissingType = _InitialMissingType() - - -class AsyncCacheInfo(NamedTuple): - hits: int - misses: int - maxsize: int | None - currsize: int - ttl: int | None - - -class AsyncCacheParameters(TypedDict): - maxsize: int | None - typed: bool - always_checkpoint: bool - ttl: int | None - - -class _LRUMethodWrapper(Generic[T]): - def __init__(self, wrapper: AsyncLRUCacheWrapper[..., T], instance: object): - self.__wrapper = wrapper - self.__instance = instance - - def cache_info(self) -> AsyncCacheInfo: - return self.__wrapper.cache_info() - - def cache_parameters(self) -> AsyncCacheParameters: - return self.__wrapper.cache_parameters() - - def cache_clear(self) -> None: - self.__wrapper.cache_clear() - - async def __call__(self, *args: Any, **kwargs: Any) -> T: - if self.__instance is None: - return await self.__wrapper(*args, **kwargs) - - return await self.__wrapper(self.__instance, *args, **kwargs) - - -@final -class AsyncLRUCacheWrapper(Generic[P, T]): - def __init__( - self, - func: Callable[P, Awaitable[T]], - maxsize: int | None, - typed: bool, - always_checkpoint: bool, - ttl: int | None, - ): - self.__wrapped__ = func - self._hits: int = 0 - self._misses: int = 0 - self._maxsize = max(maxsize, 0) if maxsize is not None else None - self._currsize: int = 0 - self._typed = typed - self._always_checkpoint = always_checkpoint - self._ttl = ttl - update_wrapper(self, func) - - def cache_info(self) -> AsyncCacheInfo: - return AsyncCacheInfo( - self._hits, self._misses, self._maxsize, self._currsize, self._ttl - ) - - def cache_parameters(self) -> AsyncCacheParameters: - return { - "maxsize": self._maxsize, - "typed": self._typed, - "always_checkpoint": self._always_checkpoint, - "ttl": self._ttl, - } - - def cache_clear(self) -> None: - if cache := lru_cache_items.get(None): - cache.pop(self, None) - self._hits = self._misses = self._currsize = 0 - - async def __call__(self, *args: P.args, **kwargs: P.kwargs) -> T: - # Easy case first: if maxsize == 0, no caching is done - if self._maxsize == 0: - value = await self.__wrapped__(*args, **kwargs) - self._misses += 1 - return value - - # The key is constructed as a flat tuple to avoid memory overhead - key: tuple[Any, ...] = args - if kwargs: - # initial_missing is used as a separator - key += (initial_missing,) + sum(kwargs.items(), ()) - - if self._typed: - key += tuple(type(arg) for arg in args) - if kwargs: - key += (initial_missing,) + tuple(type(val) for val in kwargs.values()) - - try: - cache = lru_cache_items.get() - except LookupError: - cache = WeakKeyDictionary() - lru_cache_items.set(cache) - - try: - cache_entry = cache[self] - except KeyError: - cache_entry = cache[self] = OrderedDict() - - cached_value: T | _InitialMissingType - try: - cached_value, lock, expires_at = cache_entry[key] - except KeyError: - # We're the first task to call this function - cached_value, lock, expires_at = ( - initial_missing, - Lock(fast_acquire=not self._always_checkpoint), - None, - ) - cache_entry[key] = cached_value, lock, expires_at - - if lock is None: - if expires_at is not None and current_time() >= expires_at: - self._currsize -= 1 - cached_value, lock, expires_at = ( - initial_missing, - Lock(fast_acquire=not self._always_checkpoint), - None, - ) - cache_entry[key] = cached_value, lock, expires_at - else: - # The value was already cached - self._hits += 1 - cache_entry.move_to_end(key) - if self._always_checkpoint: - await checkpoint() - - return cast(T, cached_value) - - async with lock: - # Check if another task filled the cache while we acquired the lock - if (cached_value := cache_entry[key][0]) is initial_missing: - self._misses += 1 - if self._maxsize is not None and self._currsize >= self._maxsize: - cache_entry.popitem(last=False) - else: - self._currsize += 1 - - value = await self.__wrapped__(*args, **kwargs) - expires_at = ( - current_time() + self._ttl if self._ttl is not None else None - ) - cache_entry[key] = value, None, expires_at - else: - # Another task filled the cache while we were waiting for the lock - self._hits += 1 - cache_entry.move_to_end(key) - value = cast(T, cached_value) - - return value - - def __get__( - self, instance: object, owner: type | None = None - ) -> _LRUMethodWrapper[T]: - wrapper = _LRUMethodWrapper(self, instance) - update_wrapper(wrapper, self.__wrapped__) - return wrapper - - -class _LRUCacheWrapper(Generic[T]): - def __init__( - self, maxsize: int | None, typed: bool, always_checkpoint: bool, ttl: int | None - ): - self._maxsize = maxsize - self._typed = typed - self._always_checkpoint = always_checkpoint - self._ttl = ttl - - @overload - def __call__( # type: ignore[overload-overlap] - self, func: Callable[P, Coroutine[Any, Any, T]], / - ) -> AsyncLRUCacheWrapper[P, T]: ... - - @overload - def __call__( - self, func: Callable[..., T], / - ) -> functools._lru_cache_wrapper[T]: ... - - def __call__( - self, f: Callable[P, Coroutine[Any, Any, T]] | Callable[..., T], / - ) -> AsyncLRUCacheWrapper[P, T] | functools._lru_cache_wrapper[T]: - if iscoroutinefunction(f): - return AsyncLRUCacheWrapper( - f, self._maxsize, self._typed, self._always_checkpoint, self._ttl - ) - - return functools.lru_cache(maxsize=self._maxsize, typed=self._typed)(f) # type: ignore[arg-type] - - -@overload -def cache( # type: ignore[overload-overlap] - func: Callable[P, Coroutine[Any, Any, T]], / -) -> AsyncLRUCacheWrapper[P, T]: ... - - -@overload -def cache(func: Callable[..., T], /) -> functools._lru_cache_wrapper[T]: ... - - -def cache( - func: Callable[..., T] | Callable[P, Coroutine[Any, Any, T]], / -) -> AsyncLRUCacheWrapper[P, T] | functools._lru_cache_wrapper[T]: - """ - A convenient shortcut for :func:`lru_cache` with ``maxsize=None``. - - This is the asynchronous equivalent to :func:`functools.cache`. - - """ - return lru_cache(maxsize=None)(func) - - -@overload -def lru_cache( - *, - maxsize: int | None = ..., - typed: bool = ..., - always_checkpoint: bool = ..., - ttl: int | None = ..., -) -> _LRUCacheWrapper[Any]: ... - - -@overload -def lru_cache( # type: ignore[overload-overlap] - func: Callable[P, Coroutine[Any, Any, T]], / -) -> AsyncLRUCacheWrapper[P, T]: ... - - -@overload -def lru_cache(func: Callable[..., T], /) -> functools._lru_cache_wrapper[T]: ... - - -def lru_cache( - func: Callable[P, Coroutine[Any, Any, T]] | Callable[..., T] | None = None, - /, - *, - maxsize: int | None = 128, - typed: bool = False, - always_checkpoint: bool = False, - ttl: int | None = None, -) -> ( - AsyncLRUCacheWrapper[P, T] | functools._lru_cache_wrapper[T] | _LRUCacheWrapper[Any] -): - """ - An asynchronous version of :func:`functools.lru_cache`. - - If a synchronous function is passed, the standard library - :func:`functools.lru_cache` is applied instead. - - :param always_checkpoint: if ``True``, every call to the cached function will be - guaranteed to yield control to the event loop at least once - :param ttl: time in seconds after which to invalidate cache entries - - .. note:: Caches and locks are managed on a per-event loop basis. - - """ - if func is None: - return _LRUCacheWrapper[Any](maxsize, typed, always_checkpoint, ttl) - - if not callable(func): - raise TypeError("the first argument must be callable") - - return _LRUCacheWrapper[T](maxsize, typed, always_checkpoint, ttl)(func) - - -@overload -async def reduce( - function: Callable[[T, S], Awaitable[T]], - iterable: Iterable[S] | AsyncIterable[S], - /, - initial: T, -) -> T: ... - - -@overload -async def reduce( - function: Callable[[T, T], Awaitable[T]], - iterable: Iterable[T] | AsyncIterable[T], - /, -) -> T: ... - - -async def reduce( # type: ignore[misc] - function: Callable[[T, T], Awaitable[T]] | Callable[[T, S], Awaitable[T]], - iterable: Iterable[T] | Iterable[S] | AsyncIterable[T] | AsyncIterable[S], - /, - initial: T | _InitialMissingType = initial_missing, -) -> T: - """ - Asynchronous version of :func:`functools.reduce`. - - :param function: a coroutine function that takes two arguments: the accumulated - value and the next element from the iterable - :param iterable: an iterable or async iterable - :param initial: the initial value (if missing, the first element of the iterable is - used as the initial value) - - """ - element: Any - function_called = False - if isinstance(iterable, AsyncIterable): - async_it = iterable.__aiter__() - if initial is initial_missing: - try: - value = cast(T, await async_it.__anext__()) - except StopAsyncIteration: - raise TypeError( - "reduce() of empty sequence with no initial value" - ) from None - else: - value = cast(T, initial) - - async for element in async_it: - value = await function(value, element) - function_called = True - elif isinstance(iterable, Iterable): - it = iter(iterable) - if initial is initial_missing: - try: - value = cast(T, next(it)) - except StopIteration: - raise TypeError( - "reduce() of empty sequence with no initial value" - ) from None - else: - value = cast(T, initial) - - for element in it: - value = await function(value, element) - function_called = True - else: - raise TypeError("reduce() argument 2 must be an iterable or async iterable") - - # Make sure there is at least one checkpoint, even if an empty iterable and an - # initial value were given - if not function_called: - await checkpoint() - - return value diff --git a/.venv/lib/python3.12/site-packages/anyio/lowlevel.py b/.venv/lib/python3.12/site-packages/anyio/lowlevel.py deleted file mode 100644 index ffbb75a..0000000 --- a/.venv/lib/python3.12/site-packages/anyio/lowlevel.py +++ /dev/null @@ -1,196 +0,0 @@ -from __future__ import annotations - -__all__ = ( - "EventLoopToken", - "RunvarToken", - "RunVar", - "checkpoint", - "checkpoint_if_cancelled", - "cancel_shielded_checkpoint", - "current_token", -) - -import enum -from dataclasses import dataclass -from types import TracebackType -from typing import Any, Generic, Literal, TypeVar, final, overload -from weakref import WeakKeyDictionary - -from ._core._eventloop import get_async_backend -from .abc import AsyncBackend - -T = TypeVar("T") -D = TypeVar("D") - - -async def checkpoint() -> None: - """ - Check for cancellation and allow the scheduler to switch to another task. - - Equivalent to (but more efficient than):: - - await checkpoint_if_cancelled() - await cancel_shielded_checkpoint() - - .. versionadded:: 3.0 - - """ - await get_async_backend().checkpoint() - - -async def checkpoint_if_cancelled() -> None: - """ - Enter a checkpoint if the enclosing cancel scope has been cancelled. - - This does not allow the scheduler to switch to a different task. - - .. versionadded:: 3.0 - - """ - await get_async_backend().checkpoint_if_cancelled() - - -async def cancel_shielded_checkpoint() -> None: - """ - Allow the scheduler to switch to another task but without checking for cancellation. - - Equivalent to (but potentially more efficient than):: - - with CancelScope(shield=True): - await checkpoint() - - .. versionadded:: 3.0 - - """ - await get_async_backend().cancel_shielded_checkpoint() - - -@final -@dataclass(frozen=True, repr=False) -class EventLoopToken: - """ - An opaque object that holds a reference to an event loop. - - .. versionadded:: 4.11.0 - """ - - backend_class: type[AsyncBackend] - native_token: object - - -def current_token() -> EventLoopToken: - """ - Return a token object that can be used to call code in the current event loop from - another thread. - - :raises NoEventLoopError: if no supported asynchronous event loop is running in the - current thread - - .. versionadded:: 4.11.0 - - """ - backend_class = get_async_backend() - raw_token = backend_class.current_token() - return EventLoopToken(backend_class, raw_token) - - -_run_vars: WeakKeyDictionary[object, dict[RunVar[Any], Any]] = WeakKeyDictionary() - - -class _NoValueSet(enum.Enum): - NO_VALUE_SET = enum.auto() - - -class RunvarToken(Generic[T]): - __slots__ = "_var", "_value", "_redeemed" - - def __init__(self, var: RunVar[T], value: T | Literal[_NoValueSet.NO_VALUE_SET]): - self._var = var - self._value: T | Literal[_NoValueSet.NO_VALUE_SET] = value - self._redeemed = False - - def __enter__(self) -> RunvarToken[T]: - return self - - def __exit__( - self, - exc_type: type[BaseException] | None, - exc_val: BaseException | None, - exc_tb: TracebackType | None, - ) -> None: - self._var.reset(self) - - -class RunVar(Generic[T]): - """ - Like a :class:`~contextvars.ContextVar`, except scoped to the running event loop. - - Can be used as a context manager, Just like :class:`~contextvars.ContextVar`, that - will reset the variable to its previous value when the context block is exited. - """ - - __slots__ = "_name", "_default" - - NO_VALUE_SET: Literal[_NoValueSet.NO_VALUE_SET] = _NoValueSet.NO_VALUE_SET - - def __init__( - self, name: str, default: T | Literal[_NoValueSet.NO_VALUE_SET] = NO_VALUE_SET - ): - self._name = name - self._default = default - - @property - def _current_vars(self) -> dict[RunVar[T], T]: - native_token = current_token().native_token - try: - return _run_vars[native_token] - except KeyError: - run_vars = _run_vars[native_token] = {} - return run_vars - - @overload - def get(self, default: D) -> T | D: ... - - @overload - def get(self) -> T: ... - - def get( - self, default: D | Literal[_NoValueSet.NO_VALUE_SET] = NO_VALUE_SET - ) -> T | D: - try: - return self._current_vars[self] - except KeyError: - if default is not RunVar.NO_VALUE_SET: - return default - elif self._default is not RunVar.NO_VALUE_SET: - return self._default - - raise LookupError( - f'Run variable "{self._name}" has no value and no default set' - ) - - def set(self, value: T) -> RunvarToken[T]: - current_vars = self._current_vars - token = RunvarToken(self, current_vars.get(self, RunVar.NO_VALUE_SET)) - current_vars[self] = value - return token - - def reset(self, token: RunvarToken[T]) -> None: - if token._var is not self: - raise ValueError("This token does not belong to this RunVar") - - if token._redeemed: - raise ValueError("This token has already been used") - - if token._value is _NoValueSet.NO_VALUE_SET: - try: - del self._current_vars[self] - except KeyError: - pass - else: - self._current_vars[self] = token._value - - token._redeemed = True - - def __repr__(self) -> str: - return f"" diff --git a/.venv/lib/python3.12/site-packages/anyio/py.typed b/.venv/lib/python3.12/site-packages/anyio/py.typed deleted file mode 100644 index e69de29..0000000 diff --git a/.venv/lib/python3.12/site-packages/anyio/pytest_plugin.py b/.venv/lib/python3.12/site-packages/anyio/pytest_plugin.py deleted file mode 100644 index a5183f0..0000000 --- a/.venv/lib/python3.12/site-packages/anyio/pytest_plugin.py +++ /dev/null @@ -1,363 +0,0 @@ -from __future__ import annotations - -import dataclasses -import socket -import sys -from collections.abc import Callable, Generator, Iterator -from contextlib import ExitStack, contextmanager -from inspect import isasyncgenfunction, iscoroutinefunction, ismethod -from typing import Any, cast - -import pytest -from _pytest.fixtures import FuncFixtureInfo, SubRequest -from _pytest.outcomes import Exit -from _pytest.python import CallSpec2 -from _pytest.scope import Scope - -from . import get_available_backends -from ._core._eventloop import ( - current_async_library, - get_async_backend, - reset_current_async_library, - set_current_async_library, -) -from ._core._exceptions import iterate_exceptions -from .abc import TestRunner - -if sys.version_info < (3, 11): - from exceptiongroup import ExceptionGroup - -_current_runner: TestRunner | None = None -_runner_stack: ExitStack | None = None -_runner_leases = 0 - - -def extract_backend_and_options(backend: object) -> tuple[str, dict[str, Any]]: - if isinstance(backend, str): - return backend, {} - elif isinstance(backend, tuple) and len(backend) == 2: - if isinstance(backend[0], str) and isinstance(backend[1], dict): - return cast(tuple[str, dict[str, Any]], backend) - - raise TypeError("anyio_backend must be either a string or tuple of (string, dict)") - - -@contextmanager -def get_runner( - backend_name: str, backend_options: dict[str, Any] -) -> Iterator[TestRunner]: - global _current_runner, _runner_leases, _runner_stack - if _current_runner is None: - asynclib = get_async_backend(backend_name) - _runner_stack = ExitStack() - if current_async_library() is None: - # Since we're in control of the event loop, we can cache the name of the - # async library - token = set_current_async_library(backend_name) - _runner_stack.callback(reset_current_async_library, token) - - backend_options = backend_options or {} - _current_runner = _runner_stack.enter_context( - asynclib.create_test_runner(backend_options) - ) - - _runner_leases += 1 - try: - yield _current_runner - finally: - _runner_leases -= 1 - if not _runner_leases: - assert _runner_stack is not None - _runner_stack.close() - _runner_stack = _current_runner = None - - -def pytest_addoption(parser: pytest.Parser) -> None: - parser.addini( - "anyio_mode", - default="strict", - help='AnyIO plugin mode (either "strict" or "auto")', - ) - - -def pytest_configure(config: pytest.Config) -> None: - config.addinivalue_line( - "markers", - "anyio: mark the (coroutine function) test to be run asynchronously via anyio.", - ) - if ( - config.getini("anyio_mode") == "auto" - and config.pluginmanager.has_plugin("asyncio") - and config.getini("asyncio_mode") == "auto" - ): - config.issue_config_time_warning( - pytest.PytestConfigWarning( - "AnyIO auto mode has been enabled together with pytest-asyncio auto " - "mode. This may cause unexpected behavior." - ), - 1, - ) - - -@pytest.hookimpl(hookwrapper=True) -def pytest_fixture_setup(fixturedef: Any, request: Any) -> Generator[Any]: - def wrapper(anyio_backend: Any, request: SubRequest, **kwargs: Any) -> Any: - # Rebind any fixture methods to the request instance - if ( - request.instance - and ismethod(func) - and type(func.__self__) is type(request.instance) - ): - local_func = func.__func__.__get__(request.instance) - else: - local_func = func - - backend_name, backend_options = extract_backend_and_options(anyio_backend) - if has_backend_arg: - kwargs["anyio_backend"] = anyio_backend - - if has_request_arg: - kwargs["request"] = request - - with get_runner(backend_name, backend_options) as runner: - if isasyncgenfunction(local_func): - yield from runner.run_asyncgen_fixture(local_func, kwargs) - else: - yield runner.run_fixture(local_func, kwargs) - - # Only apply this to coroutine functions and async generator functions in requests - # that involve the anyio_backend fixture - func = fixturedef.func - if isasyncgenfunction(func) or iscoroutinefunction(func): - if "anyio_backend" in request.fixturenames: - fixturedef.func = wrapper - original_argname = fixturedef.argnames - - if not (has_backend_arg := "anyio_backend" in fixturedef.argnames): - fixturedef.argnames += ("anyio_backend",) - - if not (has_request_arg := "request" in fixturedef.argnames): - fixturedef.argnames += ("request",) - - try: - return (yield) - finally: - fixturedef.func = func - fixturedef.argnames = original_argname - - return (yield) - - -@pytest.hookimpl(tryfirst=True) -def pytest_pycollect_makeitem( - collector: pytest.Module | pytest.Class, name: str, obj: object -) -> None: - if collector.istestfunction(obj, name): - inner_func = obj.hypothesis.inner_test if hasattr(obj, "hypothesis") else obj - if iscoroutinefunction(inner_func): - anyio_auto_mode = collector.config.getini("anyio_mode") == "auto" - marker = collector.get_closest_marker("anyio") - own_markers = getattr(obj, "pytestmark", ()) - if ( - anyio_auto_mode - or marker - or any(marker.name == "anyio" for marker in own_markers) - ): - pytest.mark.usefixtures("anyio_backend")(obj) - - -def pytest_collection_finish(session: pytest.Session) -> None: - for i, item in reversed(list(enumerate(session.items))): - if ( - isinstance(item, pytest.Function) - and iscoroutinefunction(item.function) - and item.get_closest_marker("anyio") is not None - and "anyio_backend" not in item.fixturenames - ): - new_items = [] - try: - cs_fields = {f.name for f in dataclasses.fields(CallSpec2)} - except TypeError: - cs_fields = set() - - for param_index, backend in enumerate(get_available_backends()): - if "_arg2scope" in cs_fields: # pytest >= 8 - callspec = CallSpec2( - params={"anyio_backend": backend}, - indices={"anyio_backend": param_index}, - _arg2scope={"anyio_backend": Scope.Module}, - _idlist=[backend], - marks=[], - ) - else: # pytest 7.x - callspec = CallSpec2( # type: ignore[call-arg] - funcargs={}, - params={"anyio_backend": backend}, - indices={"anyio_backend": param_index}, - arg2scope={"anyio_backend": Scope.Module}, - idlist=[backend], - marks=[], - ) - - fi = item._fixtureinfo - new_names_closure = list(fi.names_closure) - if "anyio_backend" not in new_names_closure: - new_names_closure.append("anyio_backend") - - new_fixtureinfo = FuncFixtureInfo( - argnames=fi.argnames, - initialnames=fi.initialnames, - names_closure=new_names_closure, - name2fixturedefs=fi.name2fixturedefs, - ) - new_item = pytest.Function.from_parent( - item.parent, - name=f"{item.originalname}[{backend}]", - callspec=callspec, - callobj=item.obj, - fixtureinfo=new_fixtureinfo, - keywords=item.keywords, - originalname=item.originalname, - ) - new_items.append(new_item) - - session.items[i : i + 1] = new_items - - -@pytest.hookimpl(tryfirst=True) -def pytest_pyfunc_call(pyfuncitem: Any) -> bool | None: - def run_with_hypothesis(**kwargs: Any) -> None: - with get_runner(backend_name, backend_options) as runner: - runner.run_test(original_func, kwargs) - - backend = pyfuncitem.funcargs.get("anyio_backend") - if backend: - backend_name, backend_options = extract_backend_and_options(backend) - - if hasattr(pyfuncitem.obj, "hypothesis"): - # Wrap the inner test function unless it's already wrapped - original_func = pyfuncitem.obj.hypothesis.inner_test - if original_func.__qualname__ != run_with_hypothesis.__qualname__: - if iscoroutinefunction(original_func): - pyfuncitem.obj.hypothesis.inner_test = run_with_hypothesis - - return None - - if iscoroutinefunction(pyfuncitem.obj): - funcargs = pyfuncitem.funcargs - testargs = {arg: funcargs[arg] for arg in pyfuncitem._fixtureinfo.argnames} - with get_runner(backend_name, backend_options) as runner: - try: - runner.run_test(pyfuncitem.obj, testargs) - except ExceptionGroup as excgrp: - for exc in iterate_exceptions(excgrp): - if isinstance(exc, (Exit, KeyboardInterrupt, SystemExit)): - raise exc from excgrp - - raise - - return True - - return None - - -@pytest.fixture(scope="module", params=get_available_backends()) -def anyio_backend(request: Any) -> Any: - return request.param - - -@pytest.fixture -def anyio_backend_name(anyio_backend: Any) -> str: - if isinstance(anyio_backend, str): - return anyio_backend - else: - return anyio_backend[0] - - -@pytest.fixture -def anyio_backend_options(anyio_backend: Any) -> dict[str, Any]: - if isinstance(anyio_backend, str): - return {} - else: - return anyio_backend[1] - - -class FreePortFactory: - """ - Manages port generation based on specified socket kind, ensuring no duplicate - ports are generated. - - This class provides functionality for generating available free ports on the - system. It is initialized with a specific socket kind and can generate ports - for given address families while avoiding reuse of previously generated ports. - - Users should not instantiate this class directly, but use the - ``free_tcp_port_factory`` and ``free_udp_port_factory`` fixtures instead. For simple - uses cases, ``free_tcp_port`` and ``free_udp_port`` can be used instead. - """ - - def __init__(self, kind: socket.SocketKind) -> None: - self._kind = kind - self._generated = set[int]() - - @property - def kind(self) -> socket.SocketKind: - """ - The type of socket connection (e.g., :data:`~socket.SOCK_STREAM` or - :data:`~socket.SOCK_DGRAM`) used to bind for checking port availability - - """ - return self._kind - - def __call__(self, family: socket.AddressFamily | None = None) -> int: - """ - Return an unbound port for the given address family. - - :param family: if omitted, both IPv4 and IPv6 addresses will be tried - :return: a port number - - """ - if family is not None: - families = [family] - else: - families = [socket.AF_INET] - if socket.has_ipv6: - families.append(socket.AF_INET6) - - while True: - port = 0 - with ExitStack() as stack: - for family in families: - sock = stack.enter_context(socket.socket(family, self._kind)) - addr = "::1" if family == socket.AF_INET6 else "127.0.0.1" - try: - sock.bind((addr, port)) - except OSError: - break - - if not port: - port = sock.getsockname()[1] - else: - if port not in self._generated: - self._generated.add(port) - return port - - -@pytest.fixture(scope="session") -def free_tcp_port_factory() -> FreePortFactory: - return FreePortFactory(socket.SOCK_STREAM) - - -@pytest.fixture(scope="session") -def free_udp_port_factory() -> FreePortFactory: - return FreePortFactory(socket.SOCK_DGRAM) - - -@pytest.fixture -def free_tcp_port(free_tcp_port_factory: Callable[[], int]) -> int: - return free_tcp_port_factory() - - -@pytest.fixture -def free_udp_port(free_udp_port_factory: Callable[[], int]) -> int: - return free_udp_port_factory() diff --git a/.venv/lib/python3.12/site-packages/anyio/streams/__init__.py b/.venv/lib/python3.12/site-packages/anyio/streams/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/.venv/lib/python3.12/site-packages/anyio/streams/buffered.py b/.venv/lib/python3.12/site-packages/anyio/streams/buffered.py deleted file mode 100644 index 57c7cd7..0000000 --- a/.venv/lib/python3.12/site-packages/anyio/streams/buffered.py +++ /dev/null @@ -1,188 +0,0 @@ -from __future__ import annotations - -__all__ = ( - "BufferedByteReceiveStream", - "BufferedByteStream", - "BufferedConnectable", -) - -import sys -from collections.abc import Callable, Iterable, Mapping -from dataclasses import dataclass, field -from typing import Any, SupportsIndex - -from .. import ClosedResourceError, DelimiterNotFound, EndOfStream, IncompleteRead -from ..abc import ( - AnyByteReceiveStream, - AnyByteStream, - AnyByteStreamConnectable, - ByteReceiveStream, - ByteStream, - ByteStreamConnectable, -) - -if sys.version_info >= (3, 12): - from typing import override -else: - from typing_extensions import override - - -@dataclass(eq=False) -class BufferedByteReceiveStream(ByteReceiveStream): - """ - Wraps any bytes-based receive stream and uses a buffer to provide sophisticated - receiving capabilities in the form of a byte stream. - """ - - receive_stream: AnyByteReceiveStream - _buffer: bytearray = field(init=False, default_factory=bytearray) - _closed: bool = field(init=False, default=False) - - async def aclose(self) -> None: - await self.receive_stream.aclose() - self._closed = True - - @property - def buffer(self) -> bytes: - """The bytes currently in the buffer.""" - return bytes(self._buffer) - - @property - def extra_attributes(self) -> Mapping[Any, Callable[[], Any]]: - return self.receive_stream.extra_attributes - - def feed_data(self, data: Iterable[SupportsIndex], /) -> None: - """ - Append data directly into the buffer. - - Any data in the buffer will be consumed by receive operations before receiving - anything from the wrapped stream. - - :param data: the data to append to the buffer (can be bytes or anything else - that supports ``__index__()``) - - """ - self._buffer.extend(data) - - async def receive(self, max_bytes: int = 65536) -> bytes: - if self._closed: - raise ClosedResourceError - - if self._buffer: - chunk = bytes(self._buffer[:max_bytes]) - del self._buffer[:max_bytes] - return chunk - elif isinstance(self.receive_stream, ByteReceiveStream): - return await self.receive_stream.receive(max_bytes) - else: - # With a bytes-oriented object stream, we need to handle any surplus bytes - # we get from the receive() call - chunk = await self.receive_stream.receive() - if len(chunk) > max_bytes: - # Save the surplus bytes in the buffer - self._buffer.extend(chunk[max_bytes:]) - return chunk[:max_bytes] - else: - return chunk - - async def receive_exactly(self, nbytes: int) -> bytes: - """ - Read exactly the given amount of bytes from the stream. - - :param nbytes: the number of bytes to read - :return: the bytes read - :raises ~anyio.IncompleteRead: if the stream was closed before the requested - amount of bytes could be read from the stream - - """ - while True: - remaining = nbytes - len(self._buffer) - if remaining <= 0: - retval = self._buffer[:nbytes] - del self._buffer[:nbytes] - return bytes(retval) - - try: - if isinstance(self.receive_stream, ByteReceiveStream): - chunk = await self.receive_stream.receive(remaining) - else: - chunk = await self.receive_stream.receive() - except EndOfStream as exc: - raise IncompleteRead from exc - - self._buffer.extend(chunk) - - async def receive_until(self, delimiter: bytes, max_bytes: int) -> bytes: - """ - Read from the stream until the delimiter is found or max_bytes have been read. - - :param delimiter: the marker to look for in the stream - :param max_bytes: maximum number of bytes that will be read before raising - :exc:`~anyio.DelimiterNotFound` - :return: the bytes read (not including the delimiter) - :raises ~anyio.IncompleteRead: if the stream was closed before the delimiter - was found - :raises ~anyio.DelimiterNotFound: if the delimiter is not found within the - bytes read up to the maximum allowed - - """ - delimiter_size = len(delimiter) - offset = 0 - while True: - # Check if the delimiter can be found in the current buffer - index = self._buffer.find(delimiter, offset) - if index >= 0: - found = self._buffer[:index] - del self._buffer[: index + len(delimiter) :] - return bytes(found) - - # Check if the buffer is already at or over the limit - if len(self._buffer) >= max_bytes: - raise DelimiterNotFound(max_bytes) - - # Read more data into the buffer from the socket - try: - data = await self.receive_stream.receive() - except EndOfStream as exc: - raise IncompleteRead from exc - - # Move the offset forward and add the new data to the buffer - offset = max(len(self._buffer) - delimiter_size + 1, 0) - self._buffer.extend(data) - - -class BufferedByteStream(BufferedByteReceiveStream, ByteStream): - """ - A full-duplex variant of :class:`BufferedByteReceiveStream`. All writes are passed - through to the wrapped stream as-is. - """ - - def __init__(self, stream: AnyByteStream): - """ - :param stream: the stream to be wrapped - - """ - super().__init__(stream) - self._stream = stream - - @override - async def send_eof(self) -> None: - await self._stream.send_eof() - - @override - async def send(self, item: bytes) -> None: - await self._stream.send(item) - - -class BufferedConnectable(ByteStreamConnectable): - def __init__(self, connectable: AnyByteStreamConnectable): - """ - :param connectable: the connectable to wrap - - """ - self.connectable = connectable - - @override - async def connect(self) -> BufferedByteStream: - stream = await self.connectable.connect() - return BufferedByteStream(stream) diff --git a/.venv/lib/python3.12/site-packages/anyio/streams/file.py b/.venv/lib/python3.12/site-packages/anyio/streams/file.py deleted file mode 100644 index 79c3d50..0000000 --- a/.venv/lib/python3.12/site-packages/anyio/streams/file.py +++ /dev/null @@ -1,154 +0,0 @@ -from __future__ import annotations - -__all__ = ( - "FileReadStream", - "FileStreamAttribute", - "FileWriteStream", -) - -from collections.abc import Callable, Mapping -from io import SEEK_SET, UnsupportedOperation -from os import PathLike -from pathlib import Path -from typing import IO, Any - -from .. import ( - BrokenResourceError, - ClosedResourceError, - EndOfStream, - TypedAttributeSet, - to_thread, - typed_attribute, -) -from ..abc import ByteReceiveStream, ByteSendStream - - -class FileStreamAttribute(TypedAttributeSet): - #: the open file descriptor - file: IO[bytes] = typed_attribute() - #: the path of the file on the file system, if available (file must be a real file) - path: Path = typed_attribute() - #: the file number, if available (file must be a real file or a TTY) - fileno: int = typed_attribute() - - -class _BaseFileStream: - def __init__(self, file: IO[bytes]): - self._file = file - - async def aclose(self) -> None: - await to_thread.run_sync(self._file.close) - - @property - def extra_attributes(self) -> Mapping[Any, Callable[[], Any]]: - attributes: dict[Any, Callable[[], Any]] = { - FileStreamAttribute.file: lambda: self._file, - } - - if hasattr(self._file, "name"): - attributes[FileStreamAttribute.path] = lambda: Path(self._file.name) - - try: - self._file.fileno() - except UnsupportedOperation: - pass - else: - attributes[FileStreamAttribute.fileno] = lambda: self._file.fileno() - - return attributes - - -class FileReadStream(_BaseFileStream, ByteReceiveStream): - """ - A byte stream that reads from a file in the file system. - - :param file: a file that has been opened for reading in binary mode - - .. versionadded:: 3.0 - """ - - @classmethod - async def from_path(cls, path: str | PathLike[str]) -> FileReadStream: - """ - Create a file read stream by opening the given file. - - :param path: path of the file to read from - - """ - file = await to_thread.run_sync(Path(path).open, "rb") - return cls(file) - - async def receive(self, max_bytes: int = 65536) -> bytes: - try: - data = await to_thread.run_sync(self._file.read, max_bytes) - except ValueError: - raise ClosedResourceError from None - except OSError as exc: - raise BrokenResourceError from exc - - if data: - return data - else: - raise EndOfStream - - async def seek(self, position: int, whence: int = SEEK_SET) -> int: - """ - Seek the file to the given position. - - .. seealso:: :meth:`io.IOBase.seek` - - .. note:: Not all file descriptors are seekable. - - :param position: position to seek the file to - :param whence: controls how ``position`` is interpreted - :return: the new absolute position - :raises OSError: if the file is not seekable - - """ - return await to_thread.run_sync(self._file.seek, position, whence) - - async def tell(self) -> int: - """ - Return the current stream position. - - .. note:: Not all file descriptors are seekable. - - :return: the current absolute position - :raises OSError: if the file is not seekable - - """ - return await to_thread.run_sync(self._file.tell) - - -class FileWriteStream(_BaseFileStream, ByteSendStream): - """ - A byte stream that writes to a file in the file system. - - :param file: a file that has been opened for writing in binary mode - - .. versionadded:: 3.0 - """ - - @classmethod - async def from_path( - cls, path: str | PathLike[str], append: bool = False - ) -> FileWriteStream: - """ - Create a file write stream by opening the given file for writing. - - :param path: path of the file to write to - :param append: if ``True``, open the file for appending; if ``False``, any - existing file at the given path will be truncated - - """ - mode = "ab" if append else "wb" - file = await to_thread.run_sync(Path(path).open, mode) - return cls(file) - - async def send(self, item: bytes) -> None: - try: - await to_thread.run_sync(self._file.write, item) - except ValueError: - raise ClosedResourceError from None - except OSError as exc: - raise BrokenResourceError from exc diff --git a/.venv/lib/python3.12/site-packages/anyio/streams/memory.py b/.venv/lib/python3.12/site-packages/anyio/streams/memory.py deleted file mode 100644 index a3fa0c3..0000000 --- a/.venv/lib/python3.12/site-packages/anyio/streams/memory.py +++ /dev/null @@ -1,325 +0,0 @@ -from __future__ import annotations - -__all__ = ( - "MemoryObjectReceiveStream", - "MemoryObjectSendStream", - "MemoryObjectStreamStatistics", -) - -import warnings -from collections import OrderedDict, deque -from dataclasses import dataclass, field -from types import TracebackType -from typing import Generic, NamedTuple, TypeVar - -from .. import ( - BrokenResourceError, - ClosedResourceError, - EndOfStream, - WouldBlock, -) -from .._core._testing import TaskInfo, get_current_task -from ..abc import Event, ObjectReceiveStream, ObjectSendStream -from ..lowlevel import checkpoint - -T_Item = TypeVar("T_Item") -T_co = TypeVar("T_co", covariant=True) -T_contra = TypeVar("T_contra", contravariant=True) - - -class MemoryObjectStreamStatistics(NamedTuple): - current_buffer_used: int #: number of items stored in the buffer - #: maximum number of items that can be stored on this stream (or :data:`math.inf`) - max_buffer_size: float - open_send_streams: int #: number of unclosed clones of the send stream - open_receive_streams: int #: number of unclosed clones of the receive stream - #: number of tasks blocked on :meth:`MemoryObjectSendStream.send` - tasks_waiting_send: int - #: number of tasks blocked on :meth:`MemoryObjectReceiveStream.receive` - tasks_waiting_receive: int - - -@dataclass(eq=False) -class _MemoryObjectItemReceiver(Generic[T_Item]): - task_info: TaskInfo = field(init=False, default_factory=get_current_task) - item: T_Item = field(init=False) - - def __repr__(self) -> str: - # When item is not defined, we get following error with default __repr__: - # AttributeError: 'MemoryObjectItemReceiver' object has no attribute 'item' - item = getattr(self, "item", None) - return f"{self.__class__.__name__}(task_info={self.task_info}, item={item!r})" - - -@dataclass(eq=False) -class _MemoryObjectStreamState(Generic[T_Item]): - max_buffer_size: float = field() - buffer: deque[T_Item] = field(init=False, default_factory=deque) - open_send_channels: int = field(init=False, default=0) - open_receive_channels: int = field(init=False, default=0) - waiting_receivers: OrderedDict[Event, _MemoryObjectItemReceiver[T_Item]] = field( - init=False, default_factory=OrderedDict - ) - waiting_senders: OrderedDict[Event, T_Item] = field( - init=False, default_factory=OrderedDict - ) - - def statistics(self) -> MemoryObjectStreamStatistics: - return MemoryObjectStreamStatistics( - len(self.buffer), - self.max_buffer_size, - self.open_send_channels, - self.open_receive_channels, - len(self.waiting_senders), - len(self.waiting_receivers), - ) - - -@dataclass(eq=False) -class MemoryObjectReceiveStream(Generic[T_co], ObjectReceiveStream[T_co]): - _state: _MemoryObjectStreamState[T_co] - _closed: bool = field(init=False, default=False) - - def __post_init__(self) -> None: - self._state.open_receive_channels += 1 - - def receive_nowait(self) -> T_co: - """ - Receive the next item if it can be done without waiting. - - :return: the received item - :raises ~anyio.ClosedResourceError: if this send stream has been closed - :raises ~anyio.EndOfStream: if the buffer is empty and this stream has been - closed from the sending end - :raises ~anyio.WouldBlock: if there are no items in the buffer and no tasks - waiting to send - - """ - if self._closed: - raise ClosedResourceError - - if self._state.waiting_senders: - # Get the item from the next sender - send_event, item = self._state.waiting_senders.popitem(last=False) - self._state.buffer.append(item) - send_event.set() - - if self._state.buffer: - return self._state.buffer.popleft() - elif not self._state.open_send_channels: - raise EndOfStream - - raise WouldBlock - - async def receive(self) -> T_co: - await checkpoint() - try: - return self.receive_nowait() - except WouldBlock: - # Add ourselves in the queue - receive_event = Event() - receiver = _MemoryObjectItemReceiver[T_co]() - self._state.waiting_receivers[receive_event] = receiver - - try: - await receive_event.wait() - finally: - self._state.waiting_receivers.pop(receive_event, None) - - try: - return receiver.item - except AttributeError: - raise EndOfStream from None - - def clone(self) -> MemoryObjectReceiveStream[T_co]: - """ - Create a clone of this receive stream. - - Each clone can be closed separately. Only when all clones have been closed will - the receiving end of the memory stream be considered closed by the sending ends. - - :return: the cloned stream - - """ - if self._closed: - raise ClosedResourceError - - return MemoryObjectReceiveStream(_state=self._state) - - def close(self) -> None: - """ - Close the stream. - - This works the exact same way as :meth:`aclose`, but is provided as a special - case for the benefit of synchronous callbacks. - - """ - if not self._closed: - self._closed = True - self._state.open_receive_channels -= 1 - if self._state.open_receive_channels == 0: - send_events = list(self._state.waiting_senders.keys()) - for event in send_events: - event.set() - - async def aclose(self) -> None: - self.close() - - def statistics(self) -> MemoryObjectStreamStatistics: - """ - Return statistics about the current state of this stream. - - .. versionadded:: 3.0 - """ - return self._state.statistics() - - def __enter__(self) -> MemoryObjectReceiveStream[T_co]: - return self - - def __exit__( - self, - exc_type: type[BaseException] | None, - exc_val: BaseException | None, - exc_tb: TracebackType | None, - ) -> None: - self.close() - - def __del__(self) -> None: - if not self._closed: - warnings.warn( - f"Unclosed <{self.__class__.__name__} at {id(self):x}>", - ResourceWarning, - stacklevel=1, - source=self, - ) - - -@dataclass(eq=False) -class MemoryObjectSendStream(Generic[T_contra], ObjectSendStream[T_contra]): - _state: _MemoryObjectStreamState[T_contra] - _closed: bool = field(init=False, default=False) - - def __post_init__(self) -> None: - self._state.open_send_channels += 1 - - def send_nowait(self, item: T_contra) -> None: - """ - Send an item immediately if it can be done without waiting. - - :param item: the item to send - :raises ~anyio.ClosedResourceError: if this send stream has been closed - :raises ~anyio.BrokenResourceError: if the stream has been closed from the - receiving end - :raises ~anyio.WouldBlock: if the buffer is full and there are no tasks waiting - to receive - - """ - if self._closed: - raise ClosedResourceError - if not self._state.open_receive_channels: - raise BrokenResourceError - - while self._state.waiting_receivers: - receive_event, receiver = self._state.waiting_receivers.popitem(last=False) - if not receiver.task_info.has_pending_cancellation(): - receiver.item = item - receive_event.set() - return - - if len(self._state.buffer) < self._state.max_buffer_size: - self._state.buffer.append(item) - else: - raise WouldBlock - - async def send(self, item: T_contra) -> None: - """ - Send an item to the stream. - - If the buffer is full, this method blocks until there is again room in the - buffer or the item can be sent directly to a receiver. - - :param item: the item to send - :raises ~anyio.ClosedResourceError: if this send stream has been closed - :raises ~anyio.BrokenResourceError: if the stream has been closed from the - receiving end - - """ - await checkpoint() - try: - self.send_nowait(item) - except WouldBlock: - # Wait until there's someone on the receiving end - send_event = Event() - self._state.waiting_senders[send_event] = item - try: - await send_event.wait() - except BaseException: - self._state.waiting_senders.pop(send_event, None) - raise - - if send_event in self._state.waiting_senders: - del self._state.waiting_senders[send_event] - raise BrokenResourceError from None - - def clone(self) -> MemoryObjectSendStream[T_contra]: - """ - Create a clone of this send stream. - - Each clone can be closed separately. Only when all clones have been closed will - the sending end of the memory stream be considered closed by the receiving ends. - - :return: the cloned stream - - """ - if self._closed: - raise ClosedResourceError - - return MemoryObjectSendStream(_state=self._state) - - def close(self) -> None: - """ - Close the stream. - - This works the exact same way as :meth:`aclose`, but is provided as a special - case for the benefit of synchronous callbacks. - - """ - if not self._closed: - self._closed = True - self._state.open_send_channels -= 1 - if self._state.open_send_channels == 0: - receive_events = list(self._state.waiting_receivers.keys()) - self._state.waiting_receivers.clear() - for event in receive_events: - event.set() - - async def aclose(self) -> None: - self.close() - - def statistics(self) -> MemoryObjectStreamStatistics: - """ - Return statistics about the current state of this stream. - - .. versionadded:: 3.0 - """ - return self._state.statistics() - - def __enter__(self) -> MemoryObjectSendStream[T_contra]: - return self - - def __exit__( - self, - exc_type: type[BaseException] | None, - exc_val: BaseException | None, - exc_tb: TracebackType | None, - ) -> None: - self.close() - - def __del__(self) -> None: - if not self._closed: - warnings.warn( - f"Unclosed <{self.__class__.__name__} at {id(self):x}>", - ResourceWarning, - stacklevel=1, - source=self, - ) diff --git a/.venv/lib/python3.12/site-packages/anyio/streams/stapled.py b/.venv/lib/python3.12/site-packages/anyio/streams/stapled.py deleted file mode 100644 index 9248b68..0000000 --- a/.venv/lib/python3.12/site-packages/anyio/streams/stapled.py +++ /dev/null @@ -1,147 +0,0 @@ -from __future__ import annotations - -__all__ = ( - "MultiListener", - "StapledByteStream", - "StapledObjectStream", -) - -from collections.abc import Callable, Mapping, Sequence -from dataclasses import dataclass -from typing import Any, Generic, TypeVar - -from ..abc import ( - ByteReceiveStream, - ByteSendStream, - ByteStream, - Listener, - ObjectReceiveStream, - ObjectSendStream, - ObjectStream, - TaskGroup, -) - -T_Item = TypeVar("T_Item") -T_Stream = TypeVar("T_Stream") - - -@dataclass(eq=False) -class StapledByteStream(ByteStream): - """ - Combines two byte streams into a single, bidirectional byte stream. - - Extra attributes will be provided from both streams, with the receive stream - providing the values in case of a conflict. - - :param ByteSendStream send_stream: the sending byte stream - :param ByteReceiveStream receive_stream: the receiving byte stream - """ - - send_stream: ByteSendStream - receive_stream: ByteReceiveStream - - async def receive(self, max_bytes: int = 65536) -> bytes: - return await self.receive_stream.receive(max_bytes) - - async def send(self, item: bytes) -> None: - await self.send_stream.send(item) - - async def send_eof(self) -> None: - await self.send_stream.aclose() - - async def aclose(self) -> None: - await self.send_stream.aclose() - await self.receive_stream.aclose() - - @property - def extra_attributes(self) -> Mapping[Any, Callable[[], Any]]: - return { - **self.send_stream.extra_attributes, - **self.receive_stream.extra_attributes, - } - - -@dataclass(eq=False) -class StapledObjectStream(Generic[T_Item], ObjectStream[T_Item]): - """ - Combines two object streams into a single, bidirectional object stream. - - Extra attributes will be provided from both streams, with the receive stream - providing the values in case of a conflict. - - :param ObjectSendStream send_stream: the sending object stream - :param ObjectReceiveStream receive_stream: the receiving object stream - """ - - send_stream: ObjectSendStream[T_Item] - receive_stream: ObjectReceiveStream[T_Item] - - async def receive(self) -> T_Item: - return await self.receive_stream.receive() - - async def send(self, item: T_Item) -> None: - await self.send_stream.send(item) - - async def send_eof(self) -> None: - await self.send_stream.aclose() - - async def aclose(self) -> None: - await self.send_stream.aclose() - await self.receive_stream.aclose() - - @property - def extra_attributes(self) -> Mapping[Any, Callable[[], Any]]: - return { - **self.send_stream.extra_attributes, - **self.receive_stream.extra_attributes, - } - - -@dataclass(eq=False) -class MultiListener(Generic[T_Stream], Listener[T_Stream]): - """ - Combines multiple listeners into one, serving connections from all of them at once. - - Any MultiListeners in the given collection of listeners will have their listeners - moved into this one. - - Extra attributes are provided from each listener, with each successive listener - overriding any conflicting attributes from the previous one. - - :param listeners: listeners to serve - :type listeners: Sequence[Listener[T_Stream]] - """ - - listeners: Sequence[Listener[T_Stream]] - - def __post_init__(self) -> None: - listeners: list[Listener[T_Stream]] = [] - for listener in self.listeners: - if isinstance(listener, MultiListener): - listeners.extend(listener.listeners) - del listener.listeners[:] # type: ignore[attr-defined] - else: - listeners.append(listener) - - self.listeners = listeners - - async def serve( - self, handler: Callable[[T_Stream], Any], task_group: TaskGroup | None = None - ) -> None: - from .. import create_task_group - - async with create_task_group() as tg: - for listener in self.listeners: - tg.start_soon(listener.serve, handler, task_group) - - async def aclose(self) -> None: - for listener in self.listeners: - await listener.aclose() - - @property - def extra_attributes(self) -> Mapping[Any, Callable[[], Any]]: - attributes: dict = {} - for listener in self.listeners: - attributes.update(listener.extra_attributes) - - return attributes diff --git a/.venv/lib/python3.12/site-packages/anyio/streams/text.py b/.venv/lib/python3.12/site-packages/anyio/streams/text.py deleted file mode 100644 index 296cd25..0000000 --- a/.venv/lib/python3.12/site-packages/anyio/streams/text.py +++ /dev/null @@ -1,176 +0,0 @@ -from __future__ import annotations - -__all__ = ( - "TextConnectable", - "TextReceiveStream", - "TextSendStream", - "TextStream", -) - -import codecs -import sys -from collections.abc import Callable, Mapping -from dataclasses import InitVar, dataclass, field -from typing import Any - -from ..abc import ( - AnyByteReceiveStream, - AnyByteSendStream, - AnyByteStream, - AnyByteStreamConnectable, - ObjectReceiveStream, - ObjectSendStream, - ObjectStream, - ObjectStreamConnectable, -) - -if sys.version_info >= (3, 12): - from typing import override -else: - from typing_extensions import override - - -@dataclass(eq=False) -class TextReceiveStream(ObjectReceiveStream[str]): - """ - Stream wrapper that decodes bytes to strings using the given encoding. - - Decoding is done using :class:`~codecs.IncrementalDecoder` which returns any - completely received unicode characters as soon as they come in. - - :param transport_stream: any bytes-based receive stream - :param encoding: character encoding to use for decoding bytes to strings (defaults - to ``utf-8``) - :param errors: handling scheme for decoding errors (defaults to ``strict``; see the - `codecs module documentation`_ for a comprehensive list of options) - - .. _codecs module documentation: - https://docs.python.org/3/library/codecs.html#codec-objects - """ - - transport_stream: AnyByteReceiveStream - encoding: InitVar[str] = "utf-8" - errors: InitVar[str] = "strict" - _decoder: codecs.IncrementalDecoder = field(init=False) - - def __post_init__(self, encoding: str, errors: str) -> None: - decoder_class = codecs.getincrementaldecoder(encoding) - self._decoder = decoder_class(errors=errors) - - async def receive(self) -> str: - while True: - chunk = await self.transport_stream.receive() - decoded = self._decoder.decode(chunk) - if decoded: - return decoded - - async def aclose(self) -> None: - await self.transport_stream.aclose() - self._decoder.reset() - - @property - def extra_attributes(self) -> Mapping[Any, Callable[[], Any]]: - return self.transport_stream.extra_attributes - - -@dataclass(eq=False) -class TextSendStream(ObjectSendStream[str]): - """ - Sends strings to the wrapped stream as bytes using the given encoding. - - :param AnyByteSendStream transport_stream: any bytes-based send stream - :param str encoding: character encoding to use for encoding strings to bytes - (defaults to ``utf-8``) - :param str errors: handling scheme for encoding errors (defaults to ``strict``; see - the `codecs module documentation`_ for a comprehensive list of options) - - .. _codecs module documentation: - https://docs.python.org/3/library/codecs.html#codec-objects - """ - - transport_stream: AnyByteSendStream - encoding: InitVar[str] = "utf-8" - errors: str = "strict" - _encoder: Callable[..., tuple[bytes, int]] = field(init=False) - - def __post_init__(self, encoding: str) -> None: - self._encoder = codecs.getencoder(encoding) - - async def send(self, item: str) -> None: - encoded = self._encoder(item, self.errors)[0] - await self.transport_stream.send(encoded) - - async def aclose(self) -> None: - await self.transport_stream.aclose() - - @property - def extra_attributes(self) -> Mapping[Any, Callable[[], Any]]: - return self.transport_stream.extra_attributes - - -@dataclass(eq=False) -class TextStream(ObjectStream[str]): - """ - A bidirectional stream that decodes bytes to strings on receive and encodes strings - to bytes on send. - - Extra attributes will be provided from both streams, with the receive stream - providing the values in case of a conflict. - - :param AnyByteStream transport_stream: any bytes-based stream - :param str encoding: character encoding to use for encoding/decoding strings to/from - bytes (defaults to ``utf-8``) - :param str errors: handling scheme for encoding errors (defaults to ``strict``; see - the `codecs module documentation`_ for a comprehensive list of options) - - .. _codecs module documentation: - https://docs.python.org/3/library/codecs.html#codec-objects - """ - - transport_stream: AnyByteStream - encoding: InitVar[str] = "utf-8" - errors: InitVar[str] = "strict" - _receive_stream: TextReceiveStream = field(init=False) - _send_stream: TextSendStream = field(init=False) - - def __post_init__(self, encoding: str, errors: str) -> None: - self._receive_stream = TextReceiveStream( - self.transport_stream, encoding=encoding, errors=errors - ) - self._send_stream = TextSendStream( - self.transport_stream, encoding=encoding, errors=errors - ) - - async def receive(self) -> str: - return await self._receive_stream.receive() - - async def send(self, item: str) -> None: - await self._send_stream.send(item) - - async def send_eof(self) -> None: - await self.transport_stream.send_eof() - - async def aclose(self) -> None: - await self._send_stream.aclose() - await self._receive_stream.aclose() - - @property - def extra_attributes(self) -> Mapping[Any, Callable[[], Any]]: - return { - **self._send_stream.extra_attributes, - **self._receive_stream.extra_attributes, - } - - -class TextConnectable(ObjectStreamConnectable[str]): - def __init__(self, connectable: AnyByteStreamConnectable): - """ - :param connectable: the bytestream endpoint to wrap - - """ - self.connectable = connectable - - @override - async def connect(self) -> TextStream: - stream = await self.connectable.connect() - return TextStream(stream) diff --git a/.venv/lib/python3.12/site-packages/anyio/streams/tls.py b/.venv/lib/python3.12/site-packages/anyio/streams/tls.py deleted file mode 100644 index e2a7ca5..0000000 --- a/.venv/lib/python3.12/site-packages/anyio/streams/tls.py +++ /dev/null @@ -1,421 +0,0 @@ -from __future__ import annotations - -__all__ = ( - "TLSAttribute", - "TLSConnectable", - "TLSListener", - "TLSStream", -) - -import logging -import re -import ssl -import sys -from collections.abc import Callable, Mapping -from dataclasses import dataclass -from functools import wraps -from ssl import SSLContext -from typing import Any, TypeAlias, TypeVar - -from .. import ( - BrokenResourceError, - EndOfStream, - aclose_forcefully, - get_cancelled_exc_class, - to_thread, -) -from .._core._typedattr import TypedAttributeSet, typed_attribute -from ..abc import ( - AnyByteStream, - AnyByteStreamConnectable, - ByteStream, - ByteStreamConnectable, - Listener, - TaskGroup, -) - -if sys.version_info >= (3, 11): - from typing import TypeVarTuple, Unpack -else: - from typing_extensions import TypeVarTuple, Unpack - -if sys.version_info >= (3, 12): - from typing import override -else: - from typing_extensions import override - -T_Retval = TypeVar("T_Retval") -PosArgsT = TypeVarTuple("PosArgsT") -_PCTRTT: TypeAlias = tuple[tuple[str, str], ...] -_PCTRTTT: TypeAlias = tuple[_PCTRTT, ...] - - -class TLSAttribute(TypedAttributeSet): - """Contains Transport Layer Security related attributes.""" - - #: the selected ALPN protocol - alpn_protocol: str | None = typed_attribute() - #: the channel binding for type ``tls-unique`` - channel_binding_tls_unique: bytes = typed_attribute() - #: the selected cipher - cipher: tuple[str, str, int] = typed_attribute() - #: the peer certificate in dictionary form (see :meth:`ssl.SSLSocket.getpeercert` - # for more information) - peer_certificate: None | (dict[str, str | _PCTRTTT | _PCTRTT]) = typed_attribute() - #: the peer certificate in binary form - peer_certificate_binary: bytes | None = typed_attribute() - #: ``True`` if this is the server side of the connection - server_side: bool = typed_attribute() - #: ciphers shared by the client during the TLS handshake (``None`` if this is the - #: client side) - shared_ciphers: list[tuple[str, str, int]] | None = typed_attribute() - #: the :class:`~ssl.SSLObject` used for encryption - ssl_object: ssl.SSLObject = typed_attribute() - #: ``True`` if this stream does (and expects) a closing TLS handshake when the - #: stream is being closed - standard_compatible: bool = typed_attribute() - #: the TLS protocol version (e.g. ``TLSv1.2``) - tls_version: str = typed_attribute() - - -@dataclass(eq=False) -class TLSStream(ByteStream): - """ - A stream wrapper that encrypts all sent data and decrypts received data. - - This class has no public initializer; use :meth:`wrap` instead. - All extra attributes from :class:`~TLSAttribute` are supported. - - :var AnyByteStream transport_stream: the wrapped stream - - """ - - transport_stream: AnyByteStream - standard_compatible: bool - _ssl_object: ssl.SSLObject - _read_bio: ssl.MemoryBIO - _write_bio: ssl.MemoryBIO - - @classmethod - async def wrap( - cls, - transport_stream: AnyByteStream, - *, - server_side: bool | None = None, - hostname: str | None = None, - ssl_context: ssl.SSLContext | None = None, - standard_compatible: bool = True, - ) -> TLSStream: - """ - Wrap an existing stream with Transport Layer Security. - - This performs a TLS handshake with the peer. - - :param transport_stream: a bytes-transporting stream to wrap - :param server_side: ``True`` if this is the server side of the connection, - ``False`` if this is the client side (if omitted, will be set to ``False`` - if ``hostname`` has been provided, ``False`` otherwise). Used only to create - a default context when an explicit context has not been provided. - :param hostname: host name of the peer (if host name checking is desired) - :param ssl_context: the SSLContext object to use (if not provided, a secure - default will be created) - :param standard_compatible: if ``False``, skip the closing handshake when - closing the connection, and don't raise an exception if the peer does the - same - :raises ~ssl.SSLError: if the TLS handshake fails - - """ - if server_side is None: - server_side = not hostname - - if not ssl_context: - purpose = ( - ssl.Purpose.CLIENT_AUTH if server_side else ssl.Purpose.SERVER_AUTH - ) - ssl_context = ssl.create_default_context(purpose) - - # Re-enable detection of unexpected EOFs if it was disabled by Python - if hasattr(ssl, "OP_IGNORE_UNEXPECTED_EOF"): - ssl_context.options &= ~ssl.OP_IGNORE_UNEXPECTED_EOF - - bio_in = ssl.MemoryBIO() - bio_out = ssl.MemoryBIO() - - # External SSLContext implementations may do blocking I/O in wrap_bio(), - # but the standard library implementation won't - if type(ssl_context) is ssl.SSLContext: - ssl_object = ssl_context.wrap_bio( - bio_in, bio_out, server_side=server_side, server_hostname=hostname - ) - else: - ssl_object = await to_thread.run_sync( - ssl_context.wrap_bio, - bio_in, - bio_out, - server_side, - hostname, - None, - ) - - wrapper = cls( - transport_stream=transport_stream, - standard_compatible=standard_compatible, - _ssl_object=ssl_object, - _read_bio=bio_in, - _write_bio=bio_out, - ) - await wrapper._call_sslobject_method(ssl_object.do_handshake) - return wrapper - - async def _call_sslobject_method( - self, func: Callable[[Unpack[PosArgsT]], T_Retval], *args: Unpack[PosArgsT] - ) -> T_Retval: - while True: - try: - result = func(*args) - except ssl.SSLWantReadError: - try: - # Flush any pending writes first - if self._write_bio.pending: - await self.transport_stream.send(self._write_bio.read()) - - data = await self.transport_stream.receive() - except EndOfStream: - self._read_bio.write_eof() - except OSError as exc: - self._read_bio.write_eof() - self._write_bio.write_eof() - raise BrokenResourceError from exc - else: - self._read_bio.write(data) - except ssl.SSLWantWriteError: - await self.transport_stream.send(self._write_bio.read()) - except ssl.SSLSyscallError as exc: - self._read_bio.write_eof() - self._write_bio.write_eof() - raise BrokenResourceError from exc - except ssl.SSLError as exc: - self._read_bio.write_eof() - self._write_bio.write_eof() - if isinstance(exc, ssl.SSLEOFError) or ( - exc.strerror and "UNEXPECTED_EOF_WHILE_READING" in exc.strerror - ): - if self.standard_compatible: - raise BrokenResourceError from exc - else: - raise EndOfStream from None - - raise - else: - # Flush any pending writes first - if self._write_bio.pending: - await self.transport_stream.send(self._write_bio.read()) - - return result - - async def unwrap(self) -> tuple[AnyByteStream, bytes]: - """ - Does the TLS closing handshake. - - :return: a tuple of (wrapped byte stream, bytes left in the read buffer) - - """ - await self._call_sslobject_method(self._ssl_object.unwrap) - self._read_bio.write_eof() - self._write_bio.write_eof() - return self.transport_stream, self._read_bio.read() - - async def aclose(self) -> None: - if self.standard_compatible: - try: - await self.unwrap() - except BaseException: - await aclose_forcefully(self.transport_stream) - raise - - await self.transport_stream.aclose() - - async def receive(self, max_bytes: int = 65536) -> bytes: - data = await self._call_sslobject_method(self._ssl_object.read, max_bytes) - if not data: - raise EndOfStream - - return data - - async def send(self, item: bytes) -> None: - await self._call_sslobject_method(self._ssl_object.write, item) - - async def send_eof(self) -> None: - tls_version = self.extra(TLSAttribute.tls_version) - match = re.match(r"TLSv(\d+)(?:\.(\d+))?", tls_version) - if match: - major, minor = int(match.group(1)), int(match.group(2) or 0) - if (major, minor) < (1, 3): - raise NotImplementedError( - f"send_eof() requires at least TLSv1.3; current " - f"session uses {tls_version}" - ) - - raise NotImplementedError( - "send_eof() has not yet been implemented for TLS streams" - ) - - @property - def extra_attributes(self) -> Mapping[Any, Callable[[], Any]]: - return { - **self.transport_stream.extra_attributes, - TLSAttribute.alpn_protocol: self._ssl_object.selected_alpn_protocol, - TLSAttribute.channel_binding_tls_unique: ( - self._ssl_object.get_channel_binding - ), - TLSAttribute.cipher: self._ssl_object.cipher, - TLSAttribute.peer_certificate: lambda: self._ssl_object.getpeercert(False), - TLSAttribute.peer_certificate_binary: lambda: self._ssl_object.getpeercert( - True - ), - TLSAttribute.server_side: lambda: self._ssl_object.server_side, - TLSAttribute.shared_ciphers: lambda: ( - self._ssl_object.shared_ciphers() - if self._ssl_object.server_side - else None - ), - TLSAttribute.standard_compatible: lambda: self.standard_compatible, - TLSAttribute.ssl_object: lambda: self._ssl_object, - TLSAttribute.tls_version: self._ssl_object.version, - } - - -@dataclass(eq=False) -class TLSListener(Listener[TLSStream]): - """ - A convenience listener that wraps another listener and auto-negotiates a TLS session - on every accepted connection. - - If the TLS handshake times out or raises an exception, - :meth:`handle_handshake_error` is called to do whatever post-mortem processing is - deemed necessary. - - Supports only the :attr:`~TLSAttribute.standard_compatible` extra attribute. - - :param Listener listener: the listener to wrap - :param ssl_context: the SSL context object - :param standard_compatible: a flag passed through to :meth:`TLSStream.wrap` - :param handshake_timeout: time limit for the TLS handshake - (passed to :func:`~anyio.fail_after`) - """ - - listener: Listener[Any] - ssl_context: ssl.SSLContext - standard_compatible: bool = True - handshake_timeout: float = 30 - - @staticmethod - async def handle_handshake_error(exc: BaseException, stream: AnyByteStream) -> None: - """ - Handle an exception raised during the TLS handshake. - - This method does 3 things: - - #. Forcefully closes the original stream - #. Logs the exception (unless it was a cancellation exception) using the - ``anyio.streams.tls`` logger - #. Reraises the exception if it was a base exception or a cancellation exception - - :param exc: the exception - :param stream: the original stream - - """ - await aclose_forcefully(stream) - - # Log all except cancellation exceptions - if not isinstance(exc, get_cancelled_exc_class()): - # CPython (as of 3.11.5) returns incorrect `sys.exc_info()` here when using - # any asyncio implementation, so we explicitly pass the exception to log - # (https://github.com/python/cpython/issues/108668). Trio does not have this - # issue because it works around the CPython bug. - logging.getLogger(__name__).exception( - "Error during TLS handshake", exc_info=exc - ) - - # Only reraise base exceptions and cancellation exceptions - if not isinstance(exc, Exception) or isinstance(exc, get_cancelled_exc_class()): - raise - - async def serve( - self, - handler: Callable[[TLSStream], Any], - task_group: TaskGroup | None = None, - ) -> None: - @wraps(handler) - async def handler_wrapper(stream: AnyByteStream) -> None: - from .. import fail_after - - try: - with fail_after(self.handshake_timeout): - wrapped_stream = await TLSStream.wrap( - stream, - ssl_context=self.ssl_context, - standard_compatible=self.standard_compatible, - ) - except BaseException as exc: - await self.handle_handshake_error(exc, stream) - else: - await handler(wrapped_stream) - - await self.listener.serve(handler_wrapper, task_group) - - async def aclose(self) -> None: - await self.listener.aclose() - - @property - def extra_attributes(self) -> Mapping[Any, Callable[[], Any]]: - return { - TLSAttribute.standard_compatible: lambda: self.standard_compatible, - } - - -class TLSConnectable(ByteStreamConnectable): - """ - Wraps another connectable and does TLS negotiation after a successful connection. - - :param connectable: the connectable to wrap - :param hostname: host name of the server (if host name checking is desired) - :param ssl_context: the SSLContext object to use (if not provided, a secure default - will be created) - :param standard_compatible: if ``False``, skip the closing handshake when closing - the connection, and don't raise an exception if the server does the same - """ - - def __init__( - self, - connectable: AnyByteStreamConnectable, - *, - hostname: str | None = None, - ssl_context: ssl.SSLContext | None = None, - standard_compatible: bool = True, - ) -> None: - self.connectable = connectable - self.ssl_context: SSLContext = ssl_context or ssl.create_default_context( - ssl.Purpose.SERVER_AUTH - ) - if not isinstance(self.ssl_context, ssl.SSLContext): - raise TypeError( - "ssl_context must be an instance of ssl.SSLContext, not " - f"{type(self.ssl_context).__name__}" - ) - self.hostname = hostname - self.standard_compatible = standard_compatible - - @override - async def connect(self) -> TLSStream: - stream = await self.connectable.connect() - try: - return await TLSStream.wrap( - stream, - hostname=self.hostname, - ssl_context=self.ssl_context, - standard_compatible=self.standard_compatible, - ) - except BaseException: - await aclose_forcefully(stream) - raise diff --git a/.venv/lib/python3.12/site-packages/anyio/to_interpreter.py b/.venv/lib/python3.12/site-packages/anyio/to_interpreter.py deleted file mode 100644 index 694dbe7..0000000 --- a/.venv/lib/python3.12/site-packages/anyio/to_interpreter.py +++ /dev/null @@ -1,246 +0,0 @@ -from __future__ import annotations - -__all__ = ( - "run_sync", - "current_default_interpreter_limiter", -) - -import atexit -import os -import sys -from collections import deque -from collections.abc import Callable -from typing import Any, Final, TypeVar - -from . import current_time, to_thread -from ._core._exceptions import BrokenWorkerInterpreter -from ._core._synchronization import CapacityLimiter -from .lowlevel import RunVar - -if sys.version_info >= (3, 11): - from typing import TypeVarTuple, Unpack -else: - from typing_extensions import TypeVarTuple, Unpack - -if sys.version_info >= (3, 14): - from concurrent.interpreters import ExecutionFailed, create - - def _interp_call( - func: Callable[..., Any], args: tuple[Any, ...] - ) -> tuple[Any, bool]: - try: - retval = func(*args) - except BaseException as exc: - return exc, True - else: - return retval, False - - class _Worker: - last_used: float = 0 - - def __init__(self) -> None: - self._interpreter = create() - - def destroy(self) -> None: - self._interpreter.close() - - def call( - self, - func: Callable[..., T_Retval], - args: tuple[Any, ...], - ) -> T_Retval: - try: - res, is_exception = self._interpreter.call(_interp_call, func, args) - except ExecutionFailed as exc: - raise BrokenWorkerInterpreter(exc.excinfo) from exc - - if is_exception: - raise res - - return res -elif sys.version_info >= (3, 13): - import _interpqueues - import _interpreters - - UNBOUND: Final = 2 # I have no clue how this works, but it was used in the stdlib - FMT_UNPICKLED: Final = 0 - FMT_PICKLED: Final = 1 - QUEUE_PICKLE_ARGS: Final = (FMT_PICKLED, UNBOUND) - QUEUE_UNPICKLE_ARGS: Final = (FMT_UNPICKLED, UNBOUND) - - _run_func = compile( - """ -import _interpqueues -from _interpreters import NotShareableError -from pickle import loads, dumps, HIGHEST_PROTOCOL - -QUEUE_PICKLE_ARGS = (1, 2) -QUEUE_UNPICKLE_ARGS = (0, 2) - -item = _interpqueues.get(queue_id)[0] -try: - func, args = loads(item) - retval = func(*args) -except BaseException as exc: - is_exception = True - retval = exc -else: - is_exception = False - -try: - _interpqueues.put(queue_id, (retval, is_exception), *QUEUE_UNPICKLE_ARGS) -except NotShareableError: - retval = dumps(retval, HIGHEST_PROTOCOL) - _interpqueues.put(queue_id, (retval, is_exception), *QUEUE_PICKLE_ARGS) - """, - "", - "exec", - ) - - class _Worker: - last_used: float = 0 - - def __init__(self) -> None: - self._interpreter_id = _interpreters.create() - self._queue_id = _interpqueues.create(1, *QUEUE_UNPICKLE_ARGS) - _interpreters.set___main___attrs( - self._interpreter_id, {"queue_id": self._queue_id} - ) - - def destroy(self) -> None: - _interpqueues.destroy(self._queue_id) - _interpreters.destroy(self._interpreter_id) - - def call( - self, - func: Callable[..., T_Retval], - args: tuple[Any, ...], - ) -> T_Retval: - import pickle - - item = pickle.dumps((func, args), pickle.HIGHEST_PROTOCOL) - _interpqueues.put(self._queue_id, item, *QUEUE_PICKLE_ARGS) - exc_info = _interpreters.exec(self._interpreter_id, _run_func) - if exc_info: - raise BrokenWorkerInterpreter(exc_info) - - res = _interpqueues.get(self._queue_id) - (res, is_exception), fmt = res[:2] - if fmt == FMT_PICKLED: - res = pickle.loads(res) - - if is_exception: - raise res - - return res -else: - - class _Worker: - last_used: float = 0 - - def __init__(self) -> None: - raise RuntimeError("subinterpreters require at least Python 3.13") - - def call( - self, - func: Callable[..., T_Retval], - args: tuple[Any, ...], - ) -> T_Retval: - raise NotImplementedError - - def destroy(self) -> None: - pass - - -DEFAULT_CPU_COUNT: Final = 8 # this is just an arbitrarily selected value -MAX_WORKER_IDLE_TIME = ( - 30 # seconds a subinterpreter can be idle before becoming eligible for pruning -) - -T_Retval = TypeVar("T_Retval") -PosArgsT = TypeVarTuple("PosArgsT") - -_idle_workers = RunVar[deque[_Worker]]("_available_workers") -_default_interpreter_limiter = RunVar[CapacityLimiter]("_default_interpreter_limiter") - - -def _stop_workers(workers: deque[_Worker]) -> None: - for worker in workers: - worker.destroy() - - workers.clear() - - -async def run_sync( - func: Callable[[Unpack[PosArgsT]], T_Retval], - *args: Unpack[PosArgsT], - limiter: CapacityLimiter | None = None, -) -> T_Retval: - """ - Call the given function with the given arguments in a subinterpreter. - - .. warning:: On Python 3.13, the :mod:`concurrent.interpreters` module was not yet - available, so the code path for that Python version relies on an undocumented, - private API. As such, it is recommended to not rely on this function for anything - mission-critical on Python 3.13. - - :param func: a callable - :param args: the positional arguments for the callable - :param limiter: capacity limiter to use to limit the total number of subinterpreters - running (if omitted, the default limiter is used) - :return: the result of the call - :raises BrokenWorkerInterpreter: if there's an internal error in a subinterpreter - - """ - if limiter is None: - limiter = current_default_interpreter_limiter() - - try: - idle_workers = _idle_workers.get() - except LookupError: - idle_workers = deque() - _idle_workers.set(idle_workers) - atexit.register(_stop_workers, idle_workers) - - async with limiter: - try: - worker = idle_workers.pop() - except IndexError: - worker = _Worker() - - try: - return await to_thread.run_sync( - worker.call, - func, - args, - limiter=limiter, - ) - finally: - # Prune workers that have been idle for too long - now = current_time() - while idle_workers: - if now - idle_workers[0].last_used <= MAX_WORKER_IDLE_TIME: - break - - await to_thread.run_sync(idle_workers.popleft().destroy, limiter=limiter) - - worker.last_used = current_time() - idle_workers.append(worker) - - -def current_default_interpreter_limiter() -> CapacityLimiter: - """ - Return the capacity limiter used by default to limit the number of concurrently - running subinterpreters. - - Defaults to the number of CPU cores. - - :return: a capacity limiter object - - """ - try: - return _default_interpreter_limiter.get() - except LookupError: - limiter = CapacityLimiter(os.cpu_count() or DEFAULT_CPU_COUNT) - _default_interpreter_limiter.set(limiter) - return limiter diff --git a/.venv/lib/python3.12/site-packages/anyio/to_process.py b/.venv/lib/python3.12/site-packages/anyio/to_process.py deleted file mode 100644 index b289234..0000000 --- a/.venv/lib/python3.12/site-packages/anyio/to_process.py +++ /dev/null @@ -1,266 +0,0 @@ -from __future__ import annotations - -__all__ = ( - "current_default_process_limiter", - "process_worker", - "run_sync", -) - -import os -import pickle -import subprocess -import sys -from collections import deque -from collections.abc import Callable -from importlib.util import module_from_spec, spec_from_file_location -from typing import TypeVar, cast - -from ._core._eventloop import current_time, get_async_backend, get_cancelled_exc_class -from ._core._exceptions import BrokenWorkerProcess -from ._core._subprocesses import open_process -from ._core._synchronization import CapacityLimiter -from ._core._tasks import CancelScope, fail_after -from .abc import ByteReceiveStream, ByteSendStream, Process -from .lowlevel import RunVar, checkpoint_if_cancelled -from .streams.buffered import BufferedByteReceiveStream - -if sys.version_info >= (3, 11): - from typing import TypeVarTuple, Unpack -else: - from typing_extensions import TypeVarTuple, Unpack - -WORKER_MAX_IDLE_TIME = 300 # 5 minutes - -T_Retval = TypeVar("T_Retval") -PosArgsT = TypeVarTuple("PosArgsT") - -_process_pool_workers: RunVar[set[Process]] = RunVar("_process_pool_workers") -_process_pool_idle_workers: RunVar[deque[tuple[Process, float]]] = RunVar( - "_process_pool_idle_workers" -) -_default_process_limiter: RunVar[CapacityLimiter] = RunVar("_default_process_limiter") - - -async def run_sync( # type: ignore[return] - func: Callable[[Unpack[PosArgsT]], T_Retval], - *args: Unpack[PosArgsT], - cancellable: bool = False, - limiter: CapacityLimiter | None = None, -) -> T_Retval: - """ - Call the given function with the given arguments in a worker process. - - If the ``cancellable`` option is enabled and the task waiting for its completion is - cancelled, the worker process running it will be abruptly terminated using SIGKILL - (or ``terminateProcess()`` on Windows). - - :param func: a callable - :param args: positional arguments for the callable - :param cancellable: ``True`` to allow cancellation of the operation while it's - running - :param limiter: capacity limiter to use to limit the total amount of processes - running (if omitted, the default limiter is used) - :raises NoEventLoopError: if no supported asynchronous event loop is running in the - current thread - :return: an awaitable that yields the return value of the function. - - """ - - async def send_raw_command(pickled_cmd: bytes) -> object: - try: - await stdin.send(pickled_cmd) - response = await buffered.receive_until(b"\n", 50) - status, length = response.split(b" ") - if status not in (b"RETURN", b"EXCEPTION"): - raise RuntimeError( - f"Worker process returned unexpected response: {response!r}" - ) - - pickled_response = await buffered.receive_exactly(int(length)) - except BaseException as exc: - workers.discard(process) - try: - process.kill() - with CancelScope(shield=True): - await process.aclose() - except ProcessLookupError: - pass - - if isinstance(exc, get_cancelled_exc_class()): - raise - else: - raise BrokenWorkerProcess from exc - - retval = pickle.loads(pickled_response) - if status == b"EXCEPTION": - assert isinstance(retval, BaseException) - raise retval - else: - return retval - - # First pickle the request before trying to reserve a worker process - await checkpoint_if_cancelled() - request = pickle.dumps(("run", func, args), protocol=pickle.HIGHEST_PROTOCOL) - - # If this is the first run in this event loop thread, set up the necessary variables - try: - workers = _process_pool_workers.get() - idle_workers = _process_pool_idle_workers.get() - except LookupError: - workers = set() - idle_workers = deque() - _process_pool_workers.set(workers) - _process_pool_idle_workers.set(idle_workers) - get_async_backend().setup_process_pool_exit_at_shutdown(workers) - - async with limiter or current_default_process_limiter(): - # Pop processes from the pool (starting from the most recently used) until we - # find one that hasn't exited yet - process: Process - while idle_workers: - process, idle_since = idle_workers.pop() - if process.returncode is None: - stdin = cast(ByteSendStream, process.stdin) - buffered = BufferedByteReceiveStream( - cast(ByteReceiveStream, process.stdout) - ) - - # Prune any other workers that have been idle for WORKER_MAX_IDLE_TIME - # seconds or longer - now = current_time() - killed_processes: list[Process] = [] - while idle_workers: - if now - idle_workers[0][1] < WORKER_MAX_IDLE_TIME: - break - - process_to_kill, idle_since = idle_workers.popleft() - process_to_kill.kill() - workers.remove(process_to_kill) - killed_processes.append(process_to_kill) - - with CancelScope(shield=True): - for killed_process in killed_processes: - await killed_process.aclose() - - break - - workers.remove(process) - else: - command = [sys.executable, "-u", "-m", __name__] - process = await open_process( - command, stdin=subprocess.PIPE, stdout=subprocess.PIPE - ) - try: - stdin = cast(ByteSendStream, process.stdin) - buffered = BufferedByteReceiveStream( - cast(ByteReceiveStream, process.stdout) - ) - with fail_after(20): - message = await buffered.receive(6) - - if message != b"READY\n": - raise BrokenWorkerProcess( - f"Worker process returned unexpected response: {message!r}" - ) - - main_module_path = getattr(sys.modules["__main__"], "__file__", None) - pickled = pickle.dumps( - ("init", sys.path, main_module_path), - protocol=pickle.HIGHEST_PROTOCOL, - ) - await send_raw_command(pickled) - except (BrokenWorkerProcess, get_cancelled_exc_class()): - raise - except BaseException as exc: - process.kill() - raise BrokenWorkerProcess( - "Error during worker process initialization" - ) from exc - - workers.add(process) - - with CancelScope(shield=not cancellable): - try: - return cast(T_Retval, await send_raw_command(request)) - finally: - if process in workers: - idle_workers.append((process, current_time())) - - -def current_default_process_limiter() -> CapacityLimiter: - """ - Return the capacity limiter that is used by default to limit the number of worker - processes. - - :return: a capacity limiter object - - """ - try: - return _default_process_limiter.get() - except LookupError: - limiter = CapacityLimiter(os.cpu_count() or 2) - _default_process_limiter.set(limiter) - return limiter - - -def process_worker() -> None: - # Redirect standard streams to os.devnull so that user code won't interfere with the - # parent-worker communication - stdin = sys.stdin - stdout = sys.stdout - sys.stdin = open(os.devnull) - sys.stdout = open(os.devnull, "w") - - stdout.buffer.write(b"READY\n") - while True: - retval = exception = None - try: - command, *args = pickle.load(stdin.buffer) - except EOFError: - return - except BaseException as exc: - exception = exc - else: - if command == "run": - func, args = args - try: - retval = func(*args) - except BaseException as exc: - exception = exc - elif command == "init": - main_module_path: str | None - sys.path, main_module_path = args - del sys.modules["__main__"] - if main_module_path and os.path.isfile(main_module_path): - # Load the parent's main module but as __mp_main__ instead of - # __main__ (like multiprocessing does) to avoid infinite recursion - try: - spec = spec_from_file_location("__mp_main__", main_module_path) - if spec and spec.loader: - main = module_from_spec(spec) - spec.loader.exec_module(main) - sys.modules["__main__"] = main - except BaseException as exc: - exception = exc - try: - if exception is not None: - status = b"EXCEPTION" - pickled = pickle.dumps(exception, pickle.HIGHEST_PROTOCOL) - else: - status = b"RETURN" - pickled = pickle.dumps(retval, pickle.HIGHEST_PROTOCOL) - except BaseException as exc: - exception = exc - status = b"EXCEPTION" - pickled = pickle.dumps(exc, pickle.HIGHEST_PROTOCOL) - - stdout.buffer.write(b"%s %d\n" % (status, len(pickled))) - stdout.buffer.write(pickled) - - # Respect SIGTERM - if isinstance(exception, SystemExit): - raise exception - - -if __name__ == "__main__": - process_worker() diff --git a/.venv/lib/python3.12/site-packages/anyio/to_thread.py b/.venv/lib/python3.12/site-packages/anyio/to_thread.py deleted file mode 100644 index 83c79d1..0000000 --- a/.venv/lib/python3.12/site-packages/anyio/to_thread.py +++ /dev/null @@ -1,78 +0,0 @@ -from __future__ import annotations - -__all__ = ( - "run_sync", - "current_default_thread_limiter", -) - -import sys -from collections.abc import Callable -from typing import TypeVar -from warnings import warn - -from ._core._eventloop import get_async_backend -from .abc import CapacityLimiter - -if sys.version_info >= (3, 11): - from typing import TypeVarTuple, Unpack -else: - from typing_extensions import TypeVarTuple, Unpack - -T_Retval = TypeVar("T_Retval") -PosArgsT = TypeVarTuple("PosArgsT") - - -async def run_sync( - func: Callable[[Unpack[PosArgsT]], T_Retval], - *args: Unpack[PosArgsT], - abandon_on_cancel: bool = False, - cancellable: bool | None = None, - limiter: CapacityLimiter | None = None, -) -> T_Retval: - """ - Call the given function with the given arguments in a worker thread. - - If the ``abandon_on_cancel`` option is enabled and the task waiting for its - completion is cancelled, the thread will still run its course but its - return value (or any raised exception) will be ignored. - - :param func: a callable - :param args: positional arguments for the callable - :param abandon_on_cancel: ``True`` to abandon the thread (leaving it to run - unchecked on own) if the host task is cancelled, ``False`` to ignore - cancellations in the host task until the operation has completed in the worker - thread - :param cancellable: deprecated alias of ``abandon_on_cancel``; will override - ``abandon_on_cancel`` if both parameters are passed - :param limiter: capacity limiter to use to limit the total amount of threads running - (if omitted, the default limiter is used) - :raises NoEventLoopError: if no supported asynchronous event loop is running in the - current thread - :return: an awaitable that yields the return value of the function. - - """ - if cancellable is not None: - abandon_on_cancel = cancellable - warn( - "The `cancellable=` keyword argument to `anyio.to_thread.run_sync` is " - "deprecated since AnyIO 4.1.0; use `abandon_on_cancel=` instead", - DeprecationWarning, - stacklevel=2, - ) - - return await get_async_backend().run_sync_in_worker_thread( - func, args, abandon_on_cancel=abandon_on_cancel, limiter=limiter - ) - - -def current_default_thread_limiter() -> CapacityLimiter: - """ - Return the capacity limiter that is used by default to limit the number of - concurrent threads. - - :return: a capacity limiter object - :raises NoEventLoopError: if no supported asynchronous event loop is running in the - current thread - - """ - return get_async_backend().current_default_thread_limiter() diff --git a/.venv/lib/python3.12/site-packages/certifi-2026.5.20.dist-info/INSTALLER b/.venv/lib/python3.12/site-packages/certifi-2026.5.20.dist-info/INSTALLER deleted file mode 100644 index a1b589e..0000000 --- a/.venv/lib/python3.12/site-packages/certifi-2026.5.20.dist-info/INSTALLER +++ /dev/null @@ -1 +0,0 @@ -pip diff --git a/.venv/lib/python3.12/site-packages/certifi-2026.5.20.dist-info/METADATA b/.venv/lib/python3.12/site-packages/certifi-2026.5.20.dist-info/METADATA deleted file mode 100644 index 7b7bb30..0000000 --- a/.venv/lib/python3.12/site-packages/certifi-2026.5.20.dist-info/METADATA +++ /dev/null @@ -1,78 +0,0 @@ -Metadata-Version: 2.4 -Name: certifi -Version: 2026.5.20 -Summary: Python package for providing Mozilla's CA Bundle. -Home-page: https://github.com/certifi/python-certifi -Author: Kenneth Reitz -Author-email: me@kennethreitz.com -License: MPL-2.0 -Project-URL: Source, https://github.com/certifi/python-certifi -Classifier: Development Status :: 5 - Production/Stable -Classifier: Intended Audience :: Developers -Classifier: License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0) -Classifier: Natural Language :: English -Classifier: Programming Language :: Python -Classifier: Programming Language :: Python :: 3 -Classifier: Programming Language :: Python :: 3 :: Only -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 -Requires-Python: >=3.7 -License-File: LICENSE -Dynamic: author -Dynamic: author-email -Dynamic: classifier -Dynamic: description -Dynamic: home-page -Dynamic: license -Dynamic: license-file -Dynamic: project-url -Dynamic: requires-python -Dynamic: summary - -Certifi: Python SSL Certificates -================================ - -Certifi provides Mozilla's carefully curated collection of Root Certificates for -validating the trustworthiness of SSL certificates while verifying the identity -of TLS hosts. It has been extracted from the `Requests`_ project. - -Installation ------------- - -``certifi`` is available on PyPI. Simply install it with ``pip``:: - - $ pip install certifi - -Usage ------ - -To reference the installed certificate authority (CA) bundle, you can use the -built-in function:: - - >>> import certifi - - >>> certifi.where() - '/usr/local/lib/python3.7/site-packages/certifi/cacert.pem' - -Or from the command line:: - - $ python -m certifi - /usr/local/lib/python3.7/site-packages/certifi/cacert.pem - -Enjoy! - -.. _`Requests`: https://requests.readthedocs.io/en/master/ - -Addition/Removal of Certificates --------------------------------- - -Certifi does not support any addition/removal or other modification of the -CA trust store content. This project is intended to provide a reliable and -highly portable root of trust to python deployments. Look to upstream projects -for methods to use alternate trust. diff --git a/.venv/lib/python3.12/site-packages/certifi-2026.5.20.dist-info/RECORD b/.venv/lib/python3.12/site-packages/certifi-2026.5.20.dist-info/RECORD deleted file mode 100644 index c69462d..0000000 --- a/.venv/lib/python3.12/site-packages/certifi-2026.5.20.dist-info/RECORD +++ /dev/null @@ -1,14 +0,0 @@ -certifi-2026.5.20.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4 -certifi-2026.5.20.dist-info/METADATA,sha256=HDiCa8lfd0TGlQFongDjoaLJOhWJiJN84y707Vwd8PY,2474 -certifi-2026.5.20.dist-info/RECORD,, -certifi-2026.5.20.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91 -certifi-2026.5.20.dist-info/licenses/LICENSE,sha256=6TcW2mucDVpKHfYP5pWzcPBpVgPSH2-D8FPkLPwQyvc,989 -certifi-2026.5.20.dist-info/top_level.txt,sha256=KMu4vUCfsjLrkPbSNdgdekS-pVJzBAJFO__nI8NF6-U,8 -certifi/__init__.py,sha256=-8ljc7w7fyi5Kyi06c1_L0lG_kD_J0FvbUTa8mEpdzQ,94 -certifi/__main__.py,sha256=xBBoj905TUWBLRGANOcf7oi6e-3dMP4cEoG9OyMs11g,243 -certifi/__pycache__/__init__.cpython-312.pyc,, -certifi/__pycache__/__main__.cpython-312.pyc,, -certifi/__pycache__/core.cpython-312.pyc,, -certifi/cacert.pem,sha256=fO9UDGrzvwo8fQBwvT_XquNPiqgFtAjRwnoByK6zBd8,236095 -certifi/core.py,sha256=XFXycndG5pf37ayeF8N32HUuDafsyhkVMbO4BAPWHa0,3394 -certifi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0 diff --git a/.venv/lib/python3.12/site-packages/certifi-2026.5.20.dist-info/WHEEL b/.venv/lib/python3.12/site-packages/certifi-2026.5.20.dist-info/WHEEL deleted file mode 100644 index 14a883f..0000000 --- a/.venv/lib/python3.12/site-packages/certifi-2026.5.20.dist-info/WHEEL +++ /dev/null @@ -1,5 +0,0 @@ -Wheel-Version: 1.0 -Generator: setuptools (82.0.1) -Root-Is-Purelib: true -Tag: py3-none-any - diff --git a/.venv/lib/python3.12/site-packages/certifi-2026.5.20.dist-info/licenses/LICENSE b/.venv/lib/python3.12/site-packages/certifi-2026.5.20.dist-info/licenses/LICENSE deleted file mode 100644 index 62b076c..0000000 --- a/.venv/lib/python3.12/site-packages/certifi-2026.5.20.dist-info/licenses/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -This package contains a modified version of ca-bundle.crt: - -ca-bundle.crt -- Bundle of CA Root Certificates - -This is a bundle of X.509 certificates of public Certificate Authorities -(CA). These were automatically extracted from Mozilla's root certificates -file (certdata.txt). This file can be found in the mozilla source tree: -https://hg.mozilla.org/mozilla-central/file/tip/security/nss/lib/ckfw/builtins/certdata.txt -It contains the certificates in PEM format and therefore -can be directly used with curl / libcurl / php_curl, or with -an Apache+mod_ssl webserver for SSL client authentication. -Just configure this file as the SSLCACertificateFile.# - -***** BEGIN LICENSE BLOCK ***** -This Source Code Form is subject to the terms of the Mozilla Public License, -v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain -one at http://mozilla.org/MPL/2.0/. - -***** END LICENSE BLOCK ***** -@(#) $RCSfile: certdata.txt,v $ $Revision: 1.80 $ $Date: 2011/11/03 15:11:58 $ diff --git a/.venv/lib/python3.12/site-packages/certifi-2026.5.20.dist-info/top_level.txt b/.venv/lib/python3.12/site-packages/certifi-2026.5.20.dist-info/top_level.txt deleted file mode 100644 index 963eac5..0000000 --- a/.venv/lib/python3.12/site-packages/certifi-2026.5.20.dist-info/top_level.txt +++ /dev/null @@ -1 +0,0 @@ -certifi diff --git a/.venv/lib/python3.12/site-packages/certifi/__init__.py b/.venv/lib/python3.12/site-packages/certifi/__init__.py deleted file mode 100644 index 004dd55..0000000 --- a/.venv/lib/python3.12/site-packages/certifi/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -from .core import contents, where - -__all__ = ["contents", "where"] -__version__ = "2026.05.20" diff --git a/.venv/lib/python3.12/site-packages/certifi/__main__.py b/.venv/lib/python3.12/site-packages/certifi/__main__.py deleted file mode 100644 index 8945b5d..0000000 --- a/.venv/lib/python3.12/site-packages/certifi/__main__.py +++ /dev/null @@ -1,12 +0,0 @@ -import argparse - -from certifi import contents, where - -parser = argparse.ArgumentParser() -parser.add_argument("-c", "--contents", action="store_true") -args = parser.parse_args() - -if args.contents: - print(contents()) -else: - print(where()) diff --git a/.venv/lib/python3.12/site-packages/certifi/core.py b/.venv/lib/python3.12/site-packages/certifi/core.py deleted file mode 100644 index 1c9661c..0000000 --- a/.venv/lib/python3.12/site-packages/certifi/core.py +++ /dev/null @@ -1,83 +0,0 @@ -""" -certifi.py -~~~~~~~~~~ - -This module returns the installation location of cacert.pem or its contents. -""" -import sys -import atexit - -def exit_cacert_ctx() -> None: - _CACERT_CTX.__exit__(None, None, None) # type: ignore[union-attr] - - -if sys.version_info >= (3, 11): - - from importlib.resources import as_file, files - - _CACERT_CTX = None - _CACERT_PATH = None - - def where() -> str: - # This is slightly terrible, but we want to delay extracting the file - # in cases where we're inside of a zipimport situation until someone - # actually calls where(), but we don't want to re-extract the file - # on every call of where(), so we'll do it once then store it in a - # global variable. - global _CACERT_CTX - global _CACERT_PATH - if _CACERT_PATH is None: - # This is slightly janky, the importlib.resources API wants you to - # manage the cleanup of this file, so it doesn't actually return a - # path, it returns a context manager that will give you the path - # when you enter it and will do any cleanup when you leave it. In - # the common case of not needing a temporary file, it will just - # return the file system location and the __exit__() is a no-op. - # - # We also have to hold onto the actual context manager, because - # it will do the cleanup whenever it gets garbage collected, so - # we will also store that at the global level as well. - _CACERT_CTX = as_file(files("certifi").joinpath("cacert.pem")) - _CACERT_PATH = str(_CACERT_CTX.__enter__()) - atexit.register(exit_cacert_ctx) - - return _CACERT_PATH - - def contents() -> str: - return files("certifi").joinpath("cacert.pem").read_text(encoding="ascii") - -else: - - from importlib.resources import path as get_path, read_text - - _CACERT_CTX = None - _CACERT_PATH = None - - def where() -> str: - # This is slightly terrible, but we want to delay extracting the - # file in cases where we're inside of a zipimport situation until - # someone actually calls where(), but we don't want to re-extract - # the file on every call of where(), so we'll do it once then store - # it in a global variable. - global _CACERT_CTX - global _CACERT_PATH - if _CACERT_PATH is None: - # This is slightly janky, the importlib.resources API wants you - # to manage the cleanup of this file, so it doesn't actually - # return a path, it returns a context manager that will give - # you the path when you enter it and will do any cleanup when - # you leave it. In the common case of not needing a temporary - # file, it will just return the file system location and the - # __exit__() is a no-op. - # - # We also have to hold onto the actual context manager, because - # it will do the cleanup whenever it gets garbage collected, so - # we will also store that at the global level as well. - _CACERT_CTX = get_path("certifi", "cacert.pem") - _CACERT_PATH = str(_CACERT_CTX.__enter__()) - atexit.register(exit_cacert_ctx) - - return _CACERT_PATH - - def contents() -> str: - return read_text("certifi", "cacert.pem", encoding="ascii") diff --git a/.venv/lib/python3.12/site-packages/certifi/py.typed b/.venv/lib/python3.12/site-packages/certifi/py.typed deleted file mode 100644 index e69de29..0000000 diff --git a/.venv/lib/python3.12/site-packages/cffi-2.0.0.dist-info/INSTALLER b/.venv/lib/python3.12/site-packages/cffi-2.0.0.dist-info/INSTALLER deleted file mode 100644 index a1b589e..0000000 --- a/.venv/lib/python3.12/site-packages/cffi-2.0.0.dist-info/INSTALLER +++ /dev/null @@ -1 +0,0 @@ -pip diff --git a/.venv/lib/python3.12/site-packages/cffi-2.0.0.dist-info/METADATA b/.venv/lib/python3.12/site-packages/cffi-2.0.0.dist-info/METADATA deleted file mode 100644 index 67508e5..0000000 --- a/.venv/lib/python3.12/site-packages/cffi-2.0.0.dist-info/METADATA +++ /dev/null @@ -1,68 +0,0 @@ -Metadata-Version: 2.4 -Name: cffi -Version: 2.0.0 -Summary: Foreign Function Interface for Python calling C code. -Author: Armin Rigo, Maciej Fijalkowski -Maintainer: Matt Davis, Matt Clay, Matti Picus -License-Expression: MIT -Project-URL: Documentation, https://cffi.readthedocs.io/ -Project-URL: Changelog, https://cffi.readthedocs.io/en/latest/whatsnew.html -Project-URL: Downloads, https://github.com/python-cffi/cffi/releases -Project-URL: Contact, https://groups.google.com/forum/#!forum/python-cffi -Project-URL: Source Code, https://github.com/python-cffi/cffi -Project-URL: Issue Tracker, https://github.com/python-cffi/cffi/issues -Classifier: Programming Language :: Python -Classifier: Programming Language :: Python :: 3 -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 :: Free Threading :: 2 - Beta -Classifier: Programming Language :: Python :: Implementation :: CPython -Requires-Python: >=3.9 -Description-Content-Type: text/markdown -License-File: LICENSE -License-File: AUTHORS -Requires-Dist: pycparser; implementation_name != "PyPy" -Dynamic: license-file - -[![GitHub Actions Status](https://github.com/python-cffi/cffi/actions/workflows/ci.yaml/badge.svg?branch=main)](https://github.com/python-cffi/cffi/actions/workflows/ci.yaml?query=branch%3Amain++) -[![PyPI version](https://img.shields.io/pypi/v/cffi.svg)](https://pypi.org/project/cffi) -[![Read the Docs](https://img.shields.io/badge/docs-latest-blue.svg)][Documentation] - - -CFFI -==== - -Foreign Function Interface for Python calling C code. - -Please see the [Documentation] or uncompiled in the `doc/` subdirectory. - -Download --------- - -[Download page](https://github.com/python-cffi/cffi/releases) - -Source Code ------------ - -Source code is publicly available on -[GitHub](https://github.com/python-cffi/cffi). - -Contact -------- - -[Mailing list](https://groups.google.com/forum/#!forum/python-cffi) - -Testing/development tips ------------------------- - -After `git clone` or `wget && tar`, we will get a directory called `cffi` or `cffi-x.x.x`. we call it `repo-directory`. To run tests under CPython, run the following in the `repo-directory`: - - pip install pytest - pip install -e . # editable install of CFFI for local development - pytest src/c/ testing/ - -[Documentation]: http://cffi.readthedocs.org/ diff --git a/.venv/lib/python3.12/site-packages/cffi-2.0.0.dist-info/RECORD b/.venv/lib/python3.12/site-packages/cffi-2.0.0.dist-info/RECORD deleted file mode 100644 index 6f82298..0000000 --- a/.venv/lib/python3.12/site-packages/cffi-2.0.0.dist-info/RECORD +++ /dev/null @@ -1,49 +0,0 @@ -_cffi_backend.cpython-312-x86_64-linux-gnu.so,sha256=AGLtw5fn9u4Cmwk3BbGlsXG7VZEvQekABMyEGuRZmcE,348808 -cffi-2.0.0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4 -cffi-2.0.0.dist-info/METADATA,sha256=uYzn40F68Im8EtXHNBLZs7FoPM-OxzyYbDWsjJvhujk,2559 -cffi-2.0.0.dist-info/RECORD,, -cffi-2.0.0.dist-info/WHEEL,sha256=aSgG0F4rGPZtV0iTEIfy6dtHq6g67Lze3uLfk0vWn88,151 -cffi-2.0.0.dist-info/entry_points.txt,sha256=y6jTxnyeuLnL-XJcDv8uML3n6wyYiGRg8MTp_QGJ9Ho,75 -cffi-2.0.0.dist-info/licenses/AUTHORS,sha256=KmemC7-zN1nWfWRf8TG45ta8TK_CMtdR_Kw-2k0xTMg,208 -cffi-2.0.0.dist-info/licenses/LICENSE,sha256=W6JN3FcGf5JJrdZEw6_EGl1tw34jQz73Wdld83Cwr2M,1123 -cffi-2.0.0.dist-info/top_level.txt,sha256=rE7WR3rZfNKxWI9-jn6hsHCAl7MDkB-FmuQbxWjFehQ,19 -cffi/__init__.py,sha256=-ksBQ7MfDzVvbBlV_ftYBWAmEqfA86ljIzMxzaZeAlI,511 -cffi/__pycache__/__init__.cpython-312.pyc,, -cffi/__pycache__/_imp_emulation.cpython-312.pyc,, -cffi/__pycache__/_shimmed_dist_utils.cpython-312.pyc,, -cffi/__pycache__/api.cpython-312.pyc,, -cffi/__pycache__/backend_ctypes.cpython-312.pyc,, -cffi/__pycache__/cffi_opcode.cpython-312.pyc,, -cffi/__pycache__/commontypes.cpython-312.pyc,, -cffi/__pycache__/cparser.cpython-312.pyc,, -cffi/__pycache__/error.cpython-312.pyc,, -cffi/__pycache__/ffiplatform.cpython-312.pyc,, -cffi/__pycache__/lock.cpython-312.pyc,, -cffi/__pycache__/model.cpython-312.pyc,, -cffi/__pycache__/pkgconfig.cpython-312.pyc,, -cffi/__pycache__/recompiler.cpython-312.pyc,, -cffi/__pycache__/setuptools_ext.cpython-312.pyc,, -cffi/__pycache__/vengine_cpy.cpython-312.pyc,, -cffi/__pycache__/vengine_gen.cpython-312.pyc,, -cffi/__pycache__/verifier.cpython-312.pyc,, -cffi/_cffi_errors.h,sha256=zQXt7uR_m8gUW-fI2hJg0KoSkJFwXv8RGUkEDZ177dQ,3908 -cffi/_cffi_include.h,sha256=Exhmgm9qzHWzWivjfTe0D7Xp4rPUkVxdNuwGhMTMzbw,15055 -cffi/_embedding.h,sha256=Ai33FHblE7XSpHOCp8kPcWwN5_9BV14OvN0JVa6ITpw,18786 -cffi/_imp_emulation.py,sha256=RxREG8zAbI2RPGBww90u_5fi8sWdahpdipOoPzkp7C0,2960 -cffi/_shimmed_dist_utils.py,sha256=Bjj2wm8yZbvFvWEx5AEfmqaqZyZFhYfoyLLQHkXZuao,2230 -cffi/api.py,sha256=alBv6hZQkjpmZplBphdaRn2lPO9-CORs_M7ixabvZWI,42169 -cffi/backend_ctypes.py,sha256=h5ZIzLc6BFVXnGyc9xPqZWUS7qGy7yFSDqXe68Sa8z4,42454 -cffi/cffi_opcode.py,sha256=JDV5l0R0_OadBX_uE7xPPTYtMdmpp8I9UYd6av7aiDU,5731 -cffi/commontypes.py,sha256=7N6zPtCFlvxXMWhHV08psUjdYIK2XgsN3yo5dgua_v4,2805 -cffi/cparser.py,sha256=QUTfmlL-aO-MYR8bFGlvAUHc36OQr7XYLe0WLkGFjRo,44790 -cffi/error.py,sha256=v6xTiS4U0kvDcy4h_BDRo5v39ZQuj-IMRYLv5ETddZs,877 -cffi/ffiplatform.py,sha256=avxFjdikYGJoEtmJO7ewVmwG_VEVl6EZ_WaNhZYCqv4,3584 -cffi/lock.py,sha256=l9TTdwMIMpi6jDkJGnQgE9cvTIR7CAntIJr8EGHt3pY,747 -cffi/model.py,sha256=W30UFQZE73jL5Mx5N81YT77us2W2iJjTm0XYfnwz1cg,21797 -cffi/parse_c_type.h,sha256=OdwQfwM9ktq6vlCB43exFQmxDBtj2MBNdK8LYl15tjw,5976 -cffi/pkgconfig.py,sha256=LP1w7vmWvmKwyqLaU1Z243FOWGNQMrgMUZrvgFuOlco,4374 -cffi/recompiler.py,sha256=78J6lMEEOygXNmjN9-fOFFO3j7eW-iFxSrxfvQb54bY,65509 -cffi/setuptools_ext.py,sha256=0rCwBJ1W7FHWtiMKfNXsSST88V8UXrui5oeXFlDNLG8,9411 -cffi/vengine_cpy.py,sha256=oyQKD23kpE0aChUKA8Jg0e723foPiYzLYEdb-J0MiNs,43881 -cffi/vengine_gen.py,sha256=DUlEIrDiVin1Pnhn1sfoamnS5NLqfJcOdhRoeSNeJRg,26939 -cffi/verifier.py,sha256=oX8jpaohg2Qm3aHcznidAdvrVm5N4sQYG0a3Eo5mIl4,11182 diff --git a/.venv/lib/python3.12/site-packages/cffi-2.0.0.dist-info/WHEEL b/.venv/lib/python3.12/site-packages/cffi-2.0.0.dist-info/WHEEL deleted file mode 100644 index e21e9f2..0000000 --- a/.venv/lib/python3.12/site-packages/cffi-2.0.0.dist-info/WHEEL +++ /dev/null @@ -1,6 +0,0 @@ -Wheel-Version: 1.0 -Generator: setuptools (80.9.0) -Root-Is-Purelib: false -Tag: cp312-cp312-manylinux_2_17_x86_64 -Tag: cp312-cp312-manylinux2014_x86_64 - diff --git a/.venv/lib/python3.12/site-packages/cffi-2.0.0.dist-info/entry_points.txt b/.venv/lib/python3.12/site-packages/cffi-2.0.0.dist-info/entry_points.txt deleted file mode 100644 index 4b0274f..0000000 --- a/.venv/lib/python3.12/site-packages/cffi-2.0.0.dist-info/entry_points.txt +++ /dev/null @@ -1,2 +0,0 @@ -[distutils.setup_keywords] -cffi_modules = cffi.setuptools_ext:cffi_modules diff --git a/.venv/lib/python3.12/site-packages/cffi-2.0.0.dist-info/licenses/AUTHORS b/.venv/lib/python3.12/site-packages/cffi-2.0.0.dist-info/licenses/AUTHORS deleted file mode 100644 index 370a25d..0000000 --- a/.venv/lib/python3.12/site-packages/cffi-2.0.0.dist-info/licenses/AUTHORS +++ /dev/null @@ -1,8 +0,0 @@ -This package has been mostly done by Armin Rigo with help from -Maciej Fijałkowski. The idea is heavily based (although not directly -copied) from LuaJIT ffi by Mike Pall. - - -Other contributors: - - Google Inc. diff --git a/.venv/lib/python3.12/site-packages/cffi-2.0.0.dist-info/licenses/LICENSE b/.venv/lib/python3.12/site-packages/cffi-2.0.0.dist-info/licenses/LICENSE deleted file mode 100644 index 0a1dbfb..0000000 --- a/.venv/lib/python3.12/site-packages/cffi-2.0.0.dist-info/licenses/LICENSE +++ /dev/null @@ -1,23 +0,0 @@ - -Except when otherwise stated (look for LICENSE files in directories or -information at the beginning of each file) all software and -documentation is licensed as follows: - - MIT No Attribution - - 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. - - 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. - diff --git a/.venv/lib/python3.12/site-packages/cffi-2.0.0.dist-info/top_level.txt b/.venv/lib/python3.12/site-packages/cffi-2.0.0.dist-info/top_level.txt deleted file mode 100644 index f645779..0000000 --- a/.venv/lib/python3.12/site-packages/cffi-2.0.0.dist-info/top_level.txt +++ /dev/null @@ -1,2 +0,0 @@ -_cffi_backend -cffi diff --git a/.venv/lib/python3.12/site-packages/cffi/__init__.py b/.venv/lib/python3.12/site-packages/cffi/__init__.py deleted file mode 100644 index c99ec3d..0000000 --- a/.venv/lib/python3.12/site-packages/cffi/__init__.py +++ /dev/null @@ -1,14 +0,0 @@ -__all__ = ['FFI', 'VerificationError', 'VerificationMissing', 'CDefError', - 'FFIError'] - -from .api import FFI -from .error import CDefError, FFIError, VerificationError, VerificationMissing -from .error import PkgConfigError - -__version__ = "2.0.0" -__version_info__ = (2, 0, 0) - -# The verifier module file names are based on the CRC32 of a string that -# contains the following version number. It may be older than __version__ -# if nothing is clearly incompatible. -__version_verifier_modules__ = "0.8.6" diff --git a/.venv/lib/python3.12/site-packages/cffi/_cffi_errors.h b/.venv/lib/python3.12/site-packages/cffi/_cffi_errors.h deleted file mode 100644 index 158e059..0000000 --- a/.venv/lib/python3.12/site-packages/cffi/_cffi_errors.h +++ /dev/null @@ -1,149 +0,0 @@ -#ifndef CFFI_MESSAGEBOX -# ifdef _MSC_VER -# define CFFI_MESSAGEBOX 1 -# else -# define CFFI_MESSAGEBOX 0 -# endif -#endif - - -#if CFFI_MESSAGEBOX -/* Windows only: logic to take the Python-CFFI embedding logic - initialization errors and display them in a background thread - with MessageBox. The idea is that if the whole program closes - as a result of this problem, then likely it is already a console - program and you can read the stderr output in the console too. - If it is not a console program, then it will likely show its own - dialog to complain, or generally not abruptly close, and for this - case the background thread should stay alive. -*/ -static void *volatile _cffi_bootstrap_text; - -static PyObject *_cffi_start_error_capture(void) -{ - PyObject *result = NULL; - PyObject *x, *m, *bi; - - if (InterlockedCompareExchangePointer(&_cffi_bootstrap_text, - (void *)1, NULL) != NULL) - return (PyObject *)1; - - m = PyImport_AddModule("_cffi_error_capture"); - if (m == NULL) - goto error; - - result = PyModule_GetDict(m); - if (result == NULL) - goto error; - -#if PY_MAJOR_VERSION >= 3 - bi = PyImport_ImportModule("builtins"); -#else - bi = PyImport_ImportModule("__builtin__"); -#endif - if (bi == NULL) - goto error; - PyDict_SetItemString(result, "__builtins__", bi); - Py_DECREF(bi); - - x = PyRun_String( - "import sys\n" - "class FileLike:\n" - " def write(self, x):\n" - " try:\n" - " of.write(x)\n" - " except: pass\n" - " self.buf += x\n" - " def flush(self):\n" - " pass\n" - "fl = FileLike()\n" - "fl.buf = ''\n" - "of = sys.stderr\n" - "sys.stderr = fl\n" - "def done():\n" - " sys.stderr = of\n" - " return fl.buf\n", /* make sure the returned value stays alive */ - Py_file_input, - result, result); - Py_XDECREF(x); - - error: - if (PyErr_Occurred()) - { - PyErr_WriteUnraisable(Py_None); - PyErr_Clear(); - } - return result; -} - -#pragma comment(lib, "user32.lib") - -static DWORD WINAPI _cffi_bootstrap_dialog(LPVOID ignored) -{ - Sleep(666); /* may be interrupted if the whole process is closing */ -#if PY_MAJOR_VERSION >= 3 - MessageBoxW(NULL, (wchar_t *)_cffi_bootstrap_text, - L"Python-CFFI error", - MB_OK | MB_ICONERROR); -#else - MessageBoxA(NULL, (char *)_cffi_bootstrap_text, - "Python-CFFI error", - MB_OK | MB_ICONERROR); -#endif - _cffi_bootstrap_text = NULL; - return 0; -} - -static void _cffi_stop_error_capture(PyObject *ecap) -{ - PyObject *s; - void *text; - - if (ecap == (PyObject *)1) - return; - - if (ecap == NULL) - goto error; - - s = PyRun_String("done()", Py_eval_input, ecap, ecap); - if (s == NULL) - goto error; - - /* Show a dialog box, but in a background thread, and - never show multiple dialog boxes at once. */ -#if PY_MAJOR_VERSION >= 3 - text = PyUnicode_AsWideCharString(s, NULL); -#else - text = PyString_AsString(s); -#endif - - _cffi_bootstrap_text = text; - - if (text != NULL) - { - HANDLE h; - h = CreateThread(NULL, 0, _cffi_bootstrap_dialog, - NULL, 0, NULL); - if (h != NULL) - CloseHandle(h); - } - /* decref the string, but it should stay alive as 'fl.buf' - in the small module above. It will really be freed only if - we later get another similar error. So it's a leak of at - most one copy of the small module. That's fine for this - situation which is usually a "fatal error" anyway. */ - Py_DECREF(s); - PyErr_Clear(); - return; - - error: - _cffi_bootstrap_text = NULL; - PyErr_Clear(); -} - -#else - -static PyObject *_cffi_start_error_capture(void) { return NULL; } -static void _cffi_stop_error_capture(PyObject *ecap) { } - -#endif diff --git a/.venv/lib/python3.12/site-packages/cffi/_cffi_include.h b/.venv/lib/python3.12/site-packages/cffi/_cffi_include.h deleted file mode 100644 index 908a1d7..0000000 --- a/.venv/lib/python3.12/site-packages/cffi/_cffi_include.h +++ /dev/null @@ -1,389 +0,0 @@ -#define _CFFI_ - -/* We try to define Py_LIMITED_API before including Python.h. - - Mess: we can only define it if Py_DEBUG, Py_TRACE_REFS and - Py_REF_DEBUG are not defined. This is a best-effort approximation: - we can learn about Py_DEBUG from pyconfig.h, but it is unclear if - the same works for the other two macros. Py_DEBUG implies them, - but not the other way around. - - The implementation is messy (issue #350): on Windows, with _MSC_VER, - we have to define Py_LIMITED_API even before including pyconfig.h. - In that case, we guess what pyconfig.h will do to the macros above, - and check our guess after the #include. - - Note that on Windows, with CPython 3.x, you need >= 3.5 and virtualenv - version >= 16.0.0. With older versions of either, you don't get a - copy of PYTHON3.DLL in the virtualenv. We can't check the version of - CPython *before* we even include pyconfig.h. ffi.set_source() puts - a ``#define _CFFI_NO_LIMITED_API'' at the start of this file if it is - running on Windows < 3.5, as an attempt at fixing it, but that's - arguably wrong because it may not be the target version of Python. - Still better than nothing I guess. As another workaround, you can - remove the definition of Py_LIMITED_API here. - - See also 'py_limited_api' in cffi/setuptools_ext.py. -*/ -#if !defined(_CFFI_USE_EMBEDDING) && !defined(Py_LIMITED_API) -# ifdef _MSC_VER -# if !defined(_DEBUG) && !defined(Py_DEBUG) && !defined(Py_TRACE_REFS) && !defined(Py_REF_DEBUG) && !defined(_CFFI_NO_LIMITED_API) -# define Py_LIMITED_API -# endif -# include - /* sanity-check: Py_LIMITED_API will cause crashes if any of these - are also defined. Normally, the Python file PC/pyconfig.h does not - cause any of these to be defined, with the exception that _DEBUG - causes Py_DEBUG. Double-check that. */ -# ifdef Py_LIMITED_API -# if defined(Py_DEBUG) -# error "pyconfig.h unexpectedly defines Py_DEBUG, but Py_LIMITED_API is set" -# endif -# if defined(Py_TRACE_REFS) -# error "pyconfig.h unexpectedly defines Py_TRACE_REFS, but Py_LIMITED_API is set" -# endif -# if defined(Py_REF_DEBUG) -# error "pyconfig.h unexpectedly defines Py_REF_DEBUG, but Py_LIMITED_API is set" -# endif -# endif -# else -# include -# if !defined(Py_DEBUG) && !defined(Py_TRACE_REFS) && !defined(Py_REF_DEBUG) && !defined(_CFFI_NO_LIMITED_API) -# define Py_LIMITED_API -# endif -# endif -#endif - -#include -#ifdef __cplusplus -extern "C" { -#endif -#include -#include "parse_c_type.h" - -/* this block of #ifs should be kept exactly identical between - c/_cffi_backend.c, cffi/vengine_cpy.py, cffi/vengine_gen.py - and cffi/_cffi_include.h */ -#if defined(_MSC_VER) -# include /* for alloca() */ -# if _MSC_VER < 1600 /* MSVC < 2010 */ - typedef __int8 int8_t; - typedef __int16 int16_t; - typedef __int32 int32_t; - typedef __int64 int64_t; - typedef unsigned __int8 uint8_t; - typedef unsigned __int16 uint16_t; - typedef unsigned __int32 uint32_t; - typedef unsigned __int64 uint64_t; - typedef __int8 int_least8_t; - typedef __int16 int_least16_t; - typedef __int32 int_least32_t; - typedef __int64 int_least64_t; - typedef unsigned __int8 uint_least8_t; - typedef unsigned __int16 uint_least16_t; - typedef unsigned __int32 uint_least32_t; - typedef unsigned __int64 uint_least64_t; - typedef __int8 int_fast8_t; - typedef __int16 int_fast16_t; - typedef __int32 int_fast32_t; - typedef __int64 int_fast64_t; - typedef unsigned __int8 uint_fast8_t; - typedef unsigned __int16 uint_fast16_t; - typedef unsigned __int32 uint_fast32_t; - typedef unsigned __int64 uint_fast64_t; - typedef __int64 intmax_t; - typedef unsigned __int64 uintmax_t; -# else -# include -# endif -# if _MSC_VER < 1800 /* MSVC < 2013 */ -# ifndef __cplusplus - typedef unsigned char _Bool; -# endif -# endif -# define _cffi_float_complex_t _Fcomplex /* include for it */ -# define _cffi_double_complex_t _Dcomplex /* include for it */ -#else -# include -# if (defined (__SVR4) && defined (__sun)) || defined(_AIX) || defined(__hpux) -# include -# endif -# define _cffi_float_complex_t float _Complex -# define _cffi_double_complex_t double _Complex -#endif - -#ifdef __GNUC__ -# define _CFFI_UNUSED_FN __attribute__((unused)) -#else -# define _CFFI_UNUSED_FN /* nothing */ -#endif - -#ifdef __cplusplus -# ifndef _Bool - typedef bool _Bool; /* semi-hackish: C++ has no _Bool; bool is builtin */ -# endif -#endif - -/********** CPython-specific section **********/ -#ifndef PYPY_VERSION - - -#if PY_MAJOR_VERSION >= 3 -# define PyInt_FromLong PyLong_FromLong -#endif - -#define _cffi_from_c_double PyFloat_FromDouble -#define _cffi_from_c_float PyFloat_FromDouble -#define _cffi_from_c_long PyInt_FromLong -#define _cffi_from_c_ulong PyLong_FromUnsignedLong -#define _cffi_from_c_longlong PyLong_FromLongLong -#define _cffi_from_c_ulonglong PyLong_FromUnsignedLongLong -#define _cffi_from_c__Bool PyBool_FromLong - -#define _cffi_to_c_double PyFloat_AsDouble -#define _cffi_to_c_float PyFloat_AsDouble - -#define _cffi_from_c_int(x, type) \ - (((type)-1) > 0 ? /* unsigned */ \ - (sizeof(type) < sizeof(long) ? \ - PyInt_FromLong((long)x) : \ - sizeof(type) == sizeof(long) ? \ - PyLong_FromUnsignedLong((unsigned long)x) : \ - PyLong_FromUnsignedLongLong((unsigned long long)x)) : \ - (sizeof(type) <= sizeof(long) ? \ - PyInt_FromLong((long)x) : \ - PyLong_FromLongLong((long long)x))) - -#define _cffi_to_c_int(o, type) \ - ((type)( \ - sizeof(type) == 1 ? (((type)-1) > 0 ? (type)_cffi_to_c_u8(o) \ - : (type)_cffi_to_c_i8(o)) : \ - sizeof(type) == 2 ? (((type)-1) > 0 ? (type)_cffi_to_c_u16(o) \ - : (type)_cffi_to_c_i16(o)) : \ - sizeof(type) == 4 ? (((type)-1) > 0 ? (type)_cffi_to_c_u32(o) \ - : (type)_cffi_to_c_i32(o)) : \ - sizeof(type) == 8 ? (((type)-1) > 0 ? (type)_cffi_to_c_u64(o) \ - : (type)_cffi_to_c_i64(o)) : \ - (Py_FatalError("unsupported size for type " #type), (type)0))) - -#define _cffi_to_c_i8 \ - ((int(*)(PyObject *))_cffi_exports[1]) -#define _cffi_to_c_u8 \ - ((int(*)(PyObject *))_cffi_exports[2]) -#define _cffi_to_c_i16 \ - ((int(*)(PyObject *))_cffi_exports[3]) -#define _cffi_to_c_u16 \ - ((int(*)(PyObject *))_cffi_exports[4]) -#define _cffi_to_c_i32 \ - ((int(*)(PyObject *))_cffi_exports[5]) -#define _cffi_to_c_u32 \ - ((unsigned int(*)(PyObject *))_cffi_exports[6]) -#define _cffi_to_c_i64 \ - ((long long(*)(PyObject *))_cffi_exports[7]) -#define _cffi_to_c_u64 \ - ((unsigned long long(*)(PyObject *))_cffi_exports[8]) -#define _cffi_to_c_char \ - ((int(*)(PyObject *))_cffi_exports[9]) -#define _cffi_from_c_pointer \ - ((PyObject *(*)(char *, struct _cffi_ctypedescr *))_cffi_exports[10]) -#define _cffi_to_c_pointer \ - ((char *(*)(PyObject *, struct _cffi_ctypedescr *))_cffi_exports[11]) -#define _cffi_get_struct_layout \ - not used any more -#define _cffi_restore_errno \ - ((void(*)(void))_cffi_exports[13]) -#define _cffi_save_errno \ - ((void(*)(void))_cffi_exports[14]) -#define _cffi_from_c_char \ - ((PyObject *(*)(char))_cffi_exports[15]) -#define _cffi_from_c_deref \ - ((PyObject *(*)(char *, struct _cffi_ctypedescr *))_cffi_exports[16]) -#define _cffi_to_c \ - ((int(*)(char *, struct _cffi_ctypedescr *, PyObject *))_cffi_exports[17]) -#define _cffi_from_c_struct \ - ((PyObject *(*)(char *, struct _cffi_ctypedescr *))_cffi_exports[18]) -#define _cffi_to_c_wchar_t \ - ((_cffi_wchar_t(*)(PyObject *))_cffi_exports[19]) -#define _cffi_from_c_wchar_t \ - ((PyObject *(*)(_cffi_wchar_t))_cffi_exports[20]) -#define _cffi_to_c_long_double \ - ((long double(*)(PyObject *))_cffi_exports[21]) -#define _cffi_to_c__Bool \ - ((_Bool(*)(PyObject *))_cffi_exports[22]) -#define _cffi_prepare_pointer_call_argument \ - ((Py_ssize_t(*)(struct _cffi_ctypedescr *, \ - PyObject *, char **))_cffi_exports[23]) -#define _cffi_convert_array_from_object \ - ((int(*)(char *, struct _cffi_ctypedescr *, PyObject *))_cffi_exports[24]) -#define _CFFI_CPIDX 25 -#define _cffi_call_python \ - ((void(*)(struct _cffi_externpy_s *, char *))_cffi_exports[_CFFI_CPIDX]) -#define _cffi_to_c_wchar3216_t \ - ((int(*)(PyObject *))_cffi_exports[26]) -#define _cffi_from_c_wchar3216_t \ - ((PyObject *(*)(int))_cffi_exports[27]) -#define _CFFI_NUM_EXPORTS 28 - -struct _cffi_ctypedescr; - -static void *_cffi_exports[_CFFI_NUM_EXPORTS]; - -#define _cffi_type(index) ( \ - assert((((uintptr_t)_cffi_types[index]) & 1) == 0), \ - (struct _cffi_ctypedescr *)_cffi_types[index]) - -static PyObject *_cffi_init(const char *module_name, Py_ssize_t version, - const struct _cffi_type_context_s *ctx) -{ - PyObject *module, *o_arg, *new_module; - void *raw[] = { - (void *)module_name, - (void *)version, - (void *)_cffi_exports, - (void *)ctx, - }; - - module = PyImport_ImportModule("_cffi_backend"); - if (module == NULL) - goto failure; - - o_arg = PyLong_FromVoidPtr((void *)raw); - if (o_arg == NULL) - goto failure; - - new_module = PyObject_CallMethod( - module, (char *)"_init_cffi_1_0_external_module", (char *)"O", o_arg); - - Py_DECREF(o_arg); - Py_DECREF(module); - return new_module; - - failure: - Py_XDECREF(module); - return NULL; -} - - -#ifdef HAVE_WCHAR_H -typedef wchar_t _cffi_wchar_t; -#else -typedef uint16_t _cffi_wchar_t; /* same random pick as _cffi_backend.c */ -#endif - -_CFFI_UNUSED_FN static uint16_t _cffi_to_c_char16_t(PyObject *o) -{ - if (sizeof(_cffi_wchar_t) == 2) - return (uint16_t)_cffi_to_c_wchar_t(o); - else - return (uint16_t)_cffi_to_c_wchar3216_t(o); -} - -_CFFI_UNUSED_FN static PyObject *_cffi_from_c_char16_t(uint16_t x) -{ - if (sizeof(_cffi_wchar_t) == 2) - return _cffi_from_c_wchar_t((_cffi_wchar_t)x); - else - return _cffi_from_c_wchar3216_t((int)x); -} - -_CFFI_UNUSED_FN static int _cffi_to_c_char32_t(PyObject *o) -{ - if (sizeof(_cffi_wchar_t) == 4) - return (int)_cffi_to_c_wchar_t(o); - else - return (int)_cffi_to_c_wchar3216_t(o); -} - -_CFFI_UNUSED_FN static PyObject *_cffi_from_c_char32_t(unsigned int x) -{ - if (sizeof(_cffi_wchar_t) == 4) - return _cffi_from_c_wchar_t((_cffi_wchar_t)x); - else - return _cffi_from_c_wchar3216_t((int)x); -} - -union _cffi_union_alignment_u { - unsigned char m_char; - unsigned short m_short; - unsigned int m_int; - unsigned long m_long; - unsigned long long m_longlong; - float m_float; - double m_double; - long double m_longdouble; -}; - -struct _cffi_freeme_s { - struct _cffi_freeme_s *next; - union _cffi_union_alignment_u alignment; -}; - -_CFFI_UNUSED_FN static int -_cffi_convert_array_argument(struct _cffi_ctypedescr *ctptr, PyObject *arg, - char **output_data, Py_ssize_t datasize, - struct _cffi_freeme_s **freeme) -{ - char *p; - if (datasize < 0) - return -1; - - p = *output_data; - if (p == NULL) { - struct _cffi_freeme_s *fp = (struct _cffi_freeme_s *)PyObject_Malloc( - offsetof(struct _cffi_freeme_s, alignment) + (size_t)datasize); - if (fp == NULL) - return -1; - fp->next = *freeme; - *freeme = fp; - p = *output_data = (char *)&fp->alignment; - } - memset((void *)p, 0, (size_t)datasize); - return _cffi_convert_array_from_object(p, ctptr, arg); -} - -_CFFI_UNUSED_FN static void -_cffi_free_array_arguments(struct _cffi_freeme_s *freeme) -{ - do { - void *p = (void *)freeme; - freeme = freeme->next; - PyObject_Free(p); - } while (freeme != NULL); -} - -/********** end CPython-specific section **********/ -#else -_CFFI_UNUSED_FN -static void (*_cffi_call_python_org)(struct _cffi_externpy_s *, char *); -# define _cffi_call_python _cffi_call_python_org -#endif - - -#define _cffi_array_len(array) (sizeof(array) / sizeof((array)[0])) - -#define _cffi_prim_int(size, sign) \ - ((size) == 1 ? ((sign) ? _CFFI_PRIM_INT8 : _CFFI_PRIM_UINT8) : \ - (size) == 2 ? ((sign) ? _CFFI_PRIM_INT16 : _CFFI_PRIM_UINT16) : \ - (size) == 4 ? ((sign) ? _CFFI_PRIM_INT32 : _CFFI_PRIM_UINT32) : \ - (size) == 8 ? ((sign) ? _CFFI_PRIM_INT64 : _CFFI_PRIM_UINT64) : \ - _CFFI__UNKNOWN_PRIM) - -#define _cffi_prim_float(size) \ - ((size) == sizeof(float) ? _CFFI_PRIM_FLOAT : \ - (size) == sizeof(double) ? _CFFI_PRIM_DOUBLE : \ - (size) == sizeof(long double) ? _CFFI__UNKNOWN_LONG_DOUBLE : \ - _CFFI__UNKNOWN_FLOAT_PRIM) - -#define _cffi_check_int(got, got_nonpos, expected) \ - ((got_nonpos) == (expected <= 0) && \ - (got) == (unsigned long long)expected) - -#ifdef MS_WIN32 -# define _cffi_stdcall __stdcall -#else -# define _cffi_stdcall /* nothing */ -#endif - -#ifdef __cplusplus -} -#endif diff --git a/.venv/lib/python3.12/site-packages/cffi/_embedding.h b/.venv/lib/python3.12/site-packages/cffi/_embedding.h deleted file mode 100644 index 64c04f6..0000000 --- a/.venv/lib/python3.12/site-packages/cffi/_embedding.h +++ /dev/null @@ -1,550 +0,0 @@ - -/***** Support code for embedding *****/ - -#ifdef __cplusplus -extern "C" { -#endif - - -#if defined(_WIN32) -# define CFFI_DLLEXPORT __declspec(dllexport) -#elif defined(__GNUC__) -# define CFFI_DLLEXPORT __attribute__((visibility("default"))) -#else -# define CFFI_DLLEXPORT /* nothing */ -#endif - - -/* There are two global variables of type _cffi_call_python_fnptr: - - * _cffi_call_python, which we declare just below, is the one called - by ``extern "Python"`` implementations. - - * _cffi_call_python_org, which on CPython is actually part of the - _cffi_exports[] array, is the function pointer copied from - _cffi_backend. If _cffi_start_python() fails, then this is set - to NULL; otherwise, it should never be NULL. - - After initialization is complete, both are equal. However, the - first one remains equal to &_cffi_start_and_call_python until the - very end of initialization, when we are (or should be) sure that - concurrent threads also see a completely initialized world, and - only then is it changed. -*/ -#undef _cffi_call_python -typedef void (*_cffi_call_python_fnptr)(struct _cffi_externpy_s *, char *); -static void _cffi_start_and_call_python(struct _cffi_externpy_s *, char *); -static _cffi_call_python_fnptr _cffi_call_python = &_cffi_start_and_call_python; - - -#ifndef _MSC_VER - /* --- Assuming a GCC not infinitely old --- */ -# define cffi_compare_and_swap(l,o,n) __sync_bool_compare_and_swap(l,o,n) -# define cffi_write_barrier() __sync_synchronize() -# if !defined(__amd64__) && !defined(__x86_64__) && \ - !defined(__i386__) && !defined(__i386) -# define cffi_read_barrier() __sync_synchronize() -# else -# define cffi_read_barrier() (void)0 -# endif -#else - /* --- Windows threads version --- */ -# include -# define cffi_compare_and_swap(l,o,n) \ - (InterlockedCompareExchangePointer(l,n,o) == (o)) -# define cffi_write_barrier() InterlockedCompareExchange(&_cffi_dummy,0,0) -# define cffi_read_barrier() (void)0 -static volatile LONG _cffi_dummy; -#endif - -#ifdef WITH_THREAD -# ifndef _MSC_VER -# include - static pthread_mutex_t _cffi_embed_startup_lock; -# else - static CRITICAL_SECTION _cffi_embed_startup_lock; -# endif - static char _cffi_embed_startup_lock_ready = 0; -#endif - -static void _cffi_acquire_reentrant_mutex(void) -{ - static void *volatile lock = NULL; - - while (!cffi_compare_and_swap(&lock, NULL, (void *)1)) { - /* should ideally do a spin loop instruction here, but - hard to do it portably and doesn't really matter I - think: pthread_mutex_init() should be very fast, and - this is only run at start-up anyway. */ - } - -#ifdef WITH_THREAD - if (!_cffi_embed_startup_lock_ready) { -# ifndef _MSC_VER - pthread_mutexattr_t attr; - pthread_mutexattr_init(&attr); - pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); - pthread_mutex_init(&_cffi_embed_startup_lock, &attr); -# else - InitializeCriticalSection(&_cffi_embed_startup_lock); -# endif - _cffi_embed_startup_lock_ready = 1; - } -#endif - - while (!cffi_compare_and_swap(&lock, (void *)1, NULL)) - ; - -#ifndef _MSC_VER - pthread_mutex_lock(&_cffi_embed_startup_lock); -#else - EnterCriticalSection(&_cffi_embed_startup_lock); -#endif -} - -static void _cffi_release_reentrant_mutex(void) -{ -#ifndef _MSC_VER - pthread_mutex_unlock(&_cffi_embed_startup_lock); -#else - LeaveCriticalSection(&_cffi_embed_startup_lock); -#endif -} - - -/********** CPython-specific section **********/ -#ifndef PYPY_VERSION - -#include "_cffi_errors.h" - - -#define _cffi_call_python_org _cffi_exports[_CFFI_CPIDX] - -PyMODINIT_FUNC _CFFI_PYTHON_STARTUP_FUNC(void); /* forward */ - -static void _cffi_py_initialize(void) -{ - /* XXX use initsigs=0, which "skips initialization registration of - signal handlers, which might be useful when Python is - embedded" according to the Python docs. But review and think - if it should be a user-controllable setting. - - XXX we should also give a way to write errors to a buffer - instead of to stderr. - - XXX if importing 'site' fails, CPython (any version) calls - exit(). Should we try to work around this behavior here? - */ - Py_InitializeEx(0); -} - -static int _cffi_initialize_python(void) -{ - /* This initializes Python, imports _cffi_backend, and then the - present .dll/.so is set up as a CPython C extension module. - */ - int result; - PyGILState_STATE state; - PyObject *pycode=NULL, *global_dict=NULL, *x; - PyObject *builtins; - - state = PyGILState_Ensure(); - - /* Call the initxxx() function from the present module. It will - create and initialize us as a CPython extension module, instead - of letting the startup Python code do it---it might reimport - the same .dll/.so and get maybe confused on some platforms. - It might also have troubles locating the .dll/.so again for all - I know. - */ - (void)_CFFI_PYTHON_STARTUP_FUNC(); - if (PyErr_Occurred()) - goto error; - - /* Now run the Python code provided to ffi.embedding_init_code(). - */ - pycode = Py_CompileString(_CFFI_PYTHON_STARTUP_CODE, - "", - Py_file_input); - if (pycode == NULL) - goto error; - global_dict = PyDict_New(); - if (global_dict == NULL) - goto error; - builtins = PyEval_GetBuiltins(); - if (builtins == NULL) - goto error; - if (PyDict_SetItemString(global_dict, "__builtins__", builtins) < 0) - goto error; - x = PyEval_EvalCode( -#if PY_MAJOR_VERSION < 3 - (PyCodeObject *) -#endif - pycode, global_dict, global_dict); - if (x == NULL) - goto error; - Py_DECREF(x); - - /* Done! Now if we've been called from - _cffi_start_and_call_python() in an ``extern "Python"``, we can - only hope that the Python code did correctly set up the - corresponding @ffi.def_extern() function. Otherwise, the - general logic of ``extern "Python"`` functions (inside the - _cffi_backend module) will find that the reference is still - missing and print an error. - */ - result = 0; - done: - Py_XDECREF(pycode); - Py_XDECREF(global_dict); - PyGILState_Release(state); - return result; - - error:; - { - /* Print as much information as potentially useful. - Debugging load-time failures with embedding is not fun - */ - PyObject *ecap; - PyObject *exception, *v, *tb, *f, *modules, *mod; - PyErr_Fetch(&exception, &v, &tb); - ecap = _cffi_start_error_capture(); - f = PySys_GetObject((char *)"stderr"); - if (f != NULL && f != Py_None) { - PyFile_WriteString( - "Failed to initialize the Python-CFFI embedding logic:\n\n", f); - } - - if (exception != NULL) { - PyErr_NormalizeException(&exception, &v, &tb); - PyErr_Display(exception, v, tb); - } - Py_XDECREF(exception); - Py_XDECREF(v); - Py_XDECREF(tb); - - if (f != NULL && f != Py_None) { - PyFile_WriteString("\nFrom: " _CFFI_MODULE_NAME - "\ncompiled with cffi version: 2.0.0" - "\n_cffi_backend module: ", f); - modules = PyImport_GetModuleDict(); - mod = PyDict_GetItemString(modules, "_cffi_backend"); - if (mod == NULL) { - PyFile_WriteString("not loaded", f); - } - else { - v = PyObject_GetAttrString(mod, "__file__"); - PyFile_WriteObject(v, f, 0); - Py_XDECREF(v); - } - PyFile_WriteString("\nsys.path: ", f); - PyFile_WriteObject(PySys_GetObject((char *)"path"), f, 0); - PyFile_WriteString("\n\n", f); - } - _cffi_stop_error_capture(ecap); - } - result = -1; - goto done; -} - -#if PY_VERSION_HEX < 0x03080000 -PyAPI_DATA(char *) _PyParser_TokenNames[]; /* from CPython */ -#endif - -static int _cffi_carefully_make_gil(void) -{ - /* This does the basic initialization of Python. It can be called - completely concurrently from unrelated threads. It assumes - that we don't hold the GIL before (if it exists), and we don't - hold it afterwards. - - (What it really does used to be completely different in Python 2 - and Python 3, with the Python 2 solution avoiding the spin-lock - around the Py_InitializeEx() call. However, after recent changes - to CPython 2.7 (issue #358) it no longer works. So we use the - Python 3 solution everywhere.) - - This initializes Python by calling Py_InitializeEx(). - Important: this must not be called concurrently at all. - So we use a global variable as a simple spin lock. This global - variable must be from 'libpythonX.Y.so', not from this - cffi-based extension module, because it must be shared from - different cffi-based extension modules. - - In Python < 3.8, we choose - _PyParser_TokenNames[0] as a completely arbitrary pointer value - that is never written to. The default is to point to the - string "ENDMARKER". We change it temporarily to point to the - next character in that string. (Yes, I know it's REALLY - obscure.) - - In Python >= 3.8, this string array is no longer writable, so - instead we pick PyCapsuleType.tp_version_tag. We can't change - Python < 3.8 because someone might use a mixture of cffi - embedded modules, some of which were compiled before this file - changed. - - In Python >= 3.12, this stopped working because that particular - tp_version_tag gets modified during interpreter startup. It's - arguably a bad idea before 3.12 too, but again we can't change - that because someone might use a mixture of cffi embedded - modules, and no-one reported a bug so far. In Python >= 3.12 - we go instead for PyCapsuleType.tp_as_buffer, which is supposed - to always be NULL. We write to it temporarily a pointer to - a struct full of NULLs, which is semantically the same. - */ - -#ifdef WITH_THREAD -# if PY_VERSION_HEX < 0x03080000 - char *volatile *lock = (char *volatile *)_PyParser_TokenNames; - char *old_value, *locked_value; - - while (1) { /* spin loop */ - old_value = *lock; - locked_value = old_value + 1; - if (old_value[0] == 'E') { - assert(old_value[1] == 'N'); - if (cffi_compare_and_swap(lock, old_value, locked_value)) - break; - } - else { - assert(old_value[0] == 'N'); - /* should ideally do a spin loop instruction here, but - hard to do it portably and doesn't really matter I - think: PyEval_InitThreads() should be very fast, and - this is only run at start-up anyway. */ - } - } -# else -# if PY_VERSION_HEX < 0x030C0000 - int volatile *lock = (int volatile *)&PyCapsule_Type.tp_version_tag; - int old_value, locked_value = -42; - assert(!(PyCapsule_Type.tp_flags & Py_TPFLAGS_HAVE_VERSION_TAG)); -# else - static struct ebp_s { PyBufferProcs buf; int mark; } empty_buffer_procs; - empty_buffer_procs.mark = -42; - PyBufferProcs *volatile *lock = (PyBufferProcs *volatile *) - &PyCapsule_Type.tp_as_buffer; - PyBufferProcs *old_value, *locked_value = &empty_buffer_procs.buf; -# endif - - while (1) { /* spin loop */ - old_value = *lock; - if (old_value == 0) { - if (cffi_compare_and_swap(lock, old_value, locked_value)) - break; - } - else { -# if PY_VERSION_HEX < 0x030C0000 - assert(old_value == locked_value); -# else - /* The pointer should point to a possibly different - empty_buffer_procs from another C extension module */ - assert(((struct ebp_s *)old_value)->mark == -42); -# endif - /* should ideally do a spin loop instruction here, but - hard to do it portably and doesn't really matter I - think: PyEval_InitThreads() should be very fast, and - this is only run at start-up anyway. */ - } - } -# endif -#endif - - /* call Py_InitializeEx() */ - if (!Py_IsInitialized()) { - _cffi_py_initialize(); -#if PY_VERSION_HEX < 0x03070000 - PyEval_InitThreads(); -#endif - PyEval_SaveThread(); /* release the GIL */ - /* the returned tstate must be the one that has been stored into the - autoTLSkey by _PyGILState_Init() called from Py_Initialize(). */ - } - else { -#if PY_VERSION_HEX < 0x03070000 - /* PyEval_InitThreads() is always a no-op from CPython 3.7 */ - PyGILState_STATE state = PyGILState_Ensure(); - PyEval_InitThreads(); - PyGILState_Release(state); -#endif - } - -#ifdef WITH_THREAD - /* release the lock */ - while (!cffi_compare_and_swap(lock, locked_value, old_value)) - ; -#endif - - return 0; -} - -/********** end CPython-specific section **********/ - - -#else - - -/********** PyPy-specific section **********/ - -PyMODINIT_FUNC _CFFI_PYTHON_STARTUP_FUNC(const void *[]); /* forward */ - -static struct _cffi_pypy_init_s { - const char *name; - void *func; /* function pointer */ - const char *code; -} _cffi_pypy_init = { - _CFFI_MODULE_NAME, - _CFFI_PYTHON_STARTUP_FUNC, - _CFFI_PYTHON_STARTUP_CODE, -}; - -extern int pypy_carefully_make_gil(const char *); -extern int pypy_init_embedded_cffi_module(int, struct _cffi_pypy_init_s *); - -static int _cffi_carefully_make_gil(void) -{ - return pypy_carefully_make_gil(_CFFI_MODULE_NAME); -} - -static int _cffi_initialize_python(void) -{ - return pypy_init_embedded_cffi_module(0xB011, &_cffi_pypy_init); -} - -/********** end PyPy-specific section **********/ - - -#endif - - -#ifdef __GNUC__ -__attribute__((noinline)) -#endif -static _cffi_call_python_fnptr _cffi_start_python(void) -{ - /* Delicate logic to initialize Python. This function can be - called multiple times concurrently, e.g. when the process calls - its first ``extern "Python"`` functions in multiple threads at - once. It can also be called recursively, in which case we must - ignore it. We also have to consider what occurs if several - different cffi-based extensions reach this code in parallel - threads---it is a different copy of the code, then, and we - can't have any shared global variable unless it comes from - 'libpythonX.Y.so'. - - Idea: - - * _cffi_carefully_make_gil(): "carefully" call - PyEval_InitThreads() (possibly with Py_InitializeEx() first). - - * then we use a (local) custom lock to make sure that a call to this - cffi-based extension will wait if another call to the *same* - extension is running the initialization in another thread. - It is reentrant, so that a recursive call will not block, but - only one from a different thread. - - * then we grab the GIL and (Python 2) we call Py_InitializeEx(). - At this point, concurrent calls to Py_InitializeEx() are not - possible: we have the GIL. - - * do the rest of the specific initialization, which may - temporarily release the GIL but not the custom lock. - Only release the custom lock when we are done. - */ - static char called = 0; - - if (_cffi_carefully_make_gil() != 0) - return NULL; - - _cffi_acquire_reentrant_mutex(); - - /* Here the GIL exists, but we don't have it. We're only protected - from concurrency by the reentrant mutex. */ - - /* This file only initializes the embedded module once, the first - time this is called, even if there are subinterpreters. */ - if (!called) { - called = 1; /* invoke _cffi_initialize_python() only once, - but don't set '_cffi_call_python' right now, - otherwise concurrent threads won't call - this function at all (we need them to wait) */ - if (_cffi_initialize_python() == 0) { - /* now initialization is finished. Switch to the fast-path. */ - - /* We would like nobody to see the new value of - '_cffi_call_python' without also seeing the rest of the - data initialized. However, this is not possible. But - the new value of '_cffi_call_python' is the function - 'cffi_call_python()' from _cffi_backend. So: */ - cffi_write_barrier(); - /* ^^^ we put a write barrier here, and a corresponding - read barrier at the start of cffi_call_python(). This - ensures that after that read barrier, we see everything - done here before the write barrier. - */ - - assert(_cffi_call_python_org != NULL); - _cffi_call_python = (_cffi_call_python_fnptr)_cffi_call_python_org; - } - else { - /* initialization failed. Reset this to NULL, even if it was - already set to some other value. Future calls to - _cffi_start_python() are still forced to occur, and will - always return NULL from now on. */ - _cffi_call_python_org = NULL; - } - } - - _cffi_release_reentrant_mutex(); - - return (_cffi_call_python_fnptr)_cffi_call_python_org; -} - -static -void _cffi_start_and_call_python(struct _cffi_externpy_s *externpy, char *args) -{ - _cffi_call_python_fnptr fnptr; - int current_err = errno; -#ifdef _MSC_VER - int current_lasterr = GetLastError(); -#endif - fnptr = _cffi_start_python(); - if (fnptr == NULL) { - fprintf(stderr, "function %s() called, but initialization code " - "failed. Returning 0.\n", externpy->name); - memset(args, 0, externpy->size_of_result); - } -#ifdef _MSC_VER - SetLastError(current_lasterr); -#endif - errno = current_err; - - if (fnptr != NULL) - fnptr(externpy, args); -} - - -/* The cffi_start_python() function makes sure Python is initialized - and our cffi module is set up. It can be called manually from the - user C code. The same effect is obtained automatically from any - dll-exported ``extern "Python"`` function. This function returns - -1 if initialization failed, 0 if all is OK. */ -_CFFI_UNUSED_FN -static int cffi_start_python(void) -{ - if (_cffi_call_python == &_cffi_start_and_call_python) { - if (_cffi_start_python() == NULL) - return -1; - } - cffi_read_barrier(); - return 0; -} - -#undef cffi_compare_and_swap -#undef cffi_write_barrier -#undef cffi_read_barrier - -#ifdef __cplusplus -} -#endif diff --git a/.venv/lib/python3.12/site-packages/cffi/_imp_emulation.py b/.venv/lib/python3.12/site-packages/cffi/_imp_emulation.py deleted file mode 100644 index 136abdd..0000000 --- a/.venv/lib/python3.12/site-packages/cffi/_imp_emulation.py +++ /dev/null @@ -1,83 +0,0 @@ - -try: - # this works on Python < 3.12 - from imp import * - -except ImportError: - # this is a limited emulation for Python >= 3.12. - # Note that this is used only for tests or for the old ffi.verify(). - # This is copied from the source code of Python 3.11. - - from _imp import (acquire_lock, release_lock, - is_builtin, is_frozen) - - from importlib._bootstrap import _load - - from importlib import machinery - import os - import sys - import tokenize - - SEARCH_ERROR = 0 - PY_SOURCE = 1 - PY_COMPILED = 2 - C_EXTENSION = 3 - PY_RESOURCE = 4 - PKG_DIRECTORY = 5 - C_BUILTIN = 6 - PY_FROZEN = 7 - PY_CODERESOURCE = 8 - IMP_HOOK = 9 - - def get_suffixes(): - extensions = [(s, 'rb', C_EXTENSION) - for s in machinery.EXTENSION_SUFFIXES] - source = [(s, 'r', PY_SOURCE) for s in machinery.SOURCE_SUFFIXES] - bytecode = [(s, 'rb', PY_COMPILED) for s in machinery.BYTECODE_SUFFIXES] - return extensions + source + bytecode - - def find_module(name, path=None): - if not isinstance(name, str): - raise TypeError("'name' must be a str, not {}".format(type(name))) - elif not isinstance(path, (type(None), list)): - # Backwards-compatibility - raise RuntimeError("'path' must be None or a list, " - "not {}".format(type(path))) - - if path is None: - if is_builtin(name): - return None, None, ('', '', C_BUILTIN) - elif is_frozen(name): - return None, None, ('', '', PY_FROZEN) - else: - path = sys.path - - for entry in path: - package_directory = os.path.join(entry, name) - for suffix in ['.py', machinery.BYTECODE_SUFFIXES[0]]: - package_file_name = '__init__' + suffix - file_path = os.path.join(package_directory, package_file_name) - if os.path.isfile(file_path): - return None, package_directory, ('', '', PKG_DIRECTORY) - for suffix, mode, type_ in get_suffixes(): - file_name = name + suffix - file_path = os.path.join(entry, file_name) - if os.path.isfile(file_path): - break - else: - continue - break # Break out of outer loop when breaking out of inner loop. - else: - raise ImportError(name, name=name) - - encoding = None - if 'b' not in mode: - with open(file_path, 'rb') as file: - encoding = tokenize.detect_encoding(file.readline)[0] - file = open(file_path, mode, encoding=encoding) - return file, file_path, (suffix, mode, type_) - - def load_dynamic(name, path, file=None): - loader = machinery.ExtensionFileLoader(name, path) - spec = machinery.ModuleSpec(name=name, loader=loader, origin=path) - return _load(spec) diff --git a/.venv/lib/python3.12/site-packages/cffi/_shimmed_dist_utils.py b/.venv/lib/python3.12/site-packages/cffi/_shimmed_dist_utils.py deleted file mode 100644 index c3d2312..0000000 --- a/.venv/lib/python3.12/site-packages/cffi/_shimmed_dist_utils.py +++ /dev/null @@ -1,45 +0,0 @@ -""" -Temporary shim module to indirect the bits of distutils we need from setuptools/distutils while providing useful -error messages beyond `No module named 'distutils' on Python >= 3.12, or when setuptools' vendored distutils is broken. - -This is a compromise to avoid a hard-dep on setuptools for Python >= 3.12, since many users don't need runtime compilation support from CFFI. -""" -import sys - -try: - # import setuptools first; this is the most robust way to ensure its embedded distutils is available - # (the .pth shim should usually work, but this is even more robust) - import setuptools -except Exception as ex: - if sys.version_info >= (3, 12): - # Python 3.12 has no built-in distutils to fall back on, so any import problem is fatal - raise Exception("This CFFI feature requires setuptools on Python >= 3.12. The setuptools module is missing or non-functional.") from ex - - # silently ignore on older Pythons (support fallback to stdlib distutils where available) -else: - del setuptools - -try: - # bring in just the bits of distutils we need, whether they really came from setuptools or stdlib-embedded distutils - from distutils import log, sysconfig - from distutils.ccompiler import CCompiler - from distutils.command.build_ext import build_ext - from distutils.core import Distribution, Extension - from distutils.dir_util import mkpath - from distutils.errors import DistutilsSetupError, CompileError, LinkError - from distutils.log import set_threshold, set_verbosity - - if sys.platform == 'win32': - try: - # FUTURE: msvc9compiler module was removed in setuptools 74; consider removing, as it's only used by an ancient patch in `recompiler` - from distutils.msvc9compiler import MSVCCompiler - except ImportError: - MSVCCompiler = None -except Exception as ex: - if sys.version_info >= (3, 12): - raise Exception("This CFFI feature requires setuptools on Python >= 3.12. Please install the setuptools package.") from ex - - # anything older, just let the underlying distutils import error fly - raise Exception("This CFFI feature requires distutils. Please install the distutils or setuptools package.") from ex - -del sys diff --git a/.venv/lib/python3.12/site-packages/cffi/api.py b/.venv/lib/python3.12/site-packages/cffi/api.py deleted file mode 100644 index 5a474f3..0000000 --- a/.venv/lib/python3.12/site-packages/cffi/api.py +++ /dev/null @@ -1,967 +0,0 @@ -import sys, types -from .lock import allocate_lock -from .error import CDefError -from . import model - -try: - callable -except NameError: - # Python 3.1 - from collections import Callable - callable = lambda x: isinstance(x, Callable) - -try: - basestring -except NameError: - # Python 3.x - basestring = str - -_unspecified = object() - - - -class FFI(object): - r''' - The main top-level class that you instantiate once, or once per module. - - Example usage: - - ffi = FFI() - ffi.cdef(""" - int printf(const char *, ...); - """) - - C = ffi.dlopen(None) # standard library - -or- - C = ffi.verify() # use a C compiler: verify the decl above is right - - C.printf("hello, %s!\n", ffi.new("char[]", "world")) - ''' - - def __init__(self, backend=None): - """Create an FFI instance. The 'backend' argument is used to - select a non-default backend, mostly for tests. - """ - if backend is None: - # You need PyPy (>= 2.0 beta), or a CPython (>= 2.6) with - # _cffi_backend.so compiled. - import _cffi_backend as backend - from . import __version__ - if backend.__version__ != __version__: - # bad version! Try to be as explicit as possible. - if hasattr(backend, '__file__'): - # CPython - raise Exception("Version mismatch: this is the 'cffi' package version %s, located in %r. When we import the top-level '_cffi_backend' extension module, we get version %s, located in %r. The two versions should be equal; check your installation." % ( - __version__, __file__, - backend.__version__, backend.__file__)) - else: - # PyPy - raise Exception("Version mismatch: this is the 'cffi' package version %s, located in %r. This interpreter comes with a built-in '_cffi_backend' module, which is version %s. The two versions should be equal; check your installation." % ( - __version__, __file__, backend.__version__)) - # (If you insist you can also try to pass the option - # 'backend=backend_ctypes.CTypesBackend()', but don't - # rely on it! It's probably not going to work well.) - - from . import cparser - self._backend = backend - self._lock = allocate_lock() - self._parser = cparser.Parser() - self._cached_btypes = {} - self._parsed_types = types.ModuleType('parsed_types').__dict__ - self._new_types = types.ModuleType('new_types').__dict__ - self._function_caches = [] - self._libraries = [] - self._cdefsources = [] - self._included_ffis = [] - self._windows_unicode = None - self._init_once_cache = {} - self._cdef_version = None - self._embedding = None - self._typecache = model.get_typecache(backend) - if hasattr(backend, 'set_ffi'): - backend.set_ffi(self) - for name in list(backend.__dict__): - if name.startswith('RTLD_'): - setattr(self, name, getattr(backend, name)) - # - with self._lock: - self.BVoidP = self._get_cached_btype(model.voidp_type) - self.BCharA = self._get_cached_btype(model.char_array_type) - if isinstance(backend, types.ModuleType): - # _cffi_backend: attach these constants to the class - if not hasattr(FFI, 'NULL'): - FFI.NULL = self.cast(self.BVoidP, 0) - FFI.CData, FFI.CType = backend._get_types() - else: - # ctypes backend: attach these constants to the instance - self.NULL = self.cast(self.BVoidP, 0) - self.CData, self.CType = backend._get_types() - self.buffer = backend.buffer - - def cdef(self, csource, override=False, packed=False, pack=None): - """Parse the given C source. This registers all declared functions, - types, and global variables. The functions and global variables can - then be accessed via either 'ffi.dlopen()' or 'ffi.verify()'. - The types can be used in 'ffi.new()' and other functions. - If 'packed' is specified as True, all structs declared inside this - cdef are packed, i.e. laid out without any field alignment at all. - Alternatively, 'pack' can be a small integer, and requests for - alignment greater than that are ignored (pack=1 is equivalent to - packed=True). - """ - self._cdef(csource, override=override, packed=packed, pack=pack) - - def embedding_api(self, csource, packed=False, pack=None): - self._cdef(csource, packed=packed, pack=pack, dllexport=True) - if self._embedding is None: - self._embedding = '' - - def _cdef(self, csource, override=False, **options): - if not isinstance(csource, str): # unicode, on Python 2 - if not isinstance(csource, basestring): - raise TypeError("cdef() argument must be a string") - csource = csource.encode('ascii') - with self._lock: - self._cdef_version = object() - self._parser.parse(csource, override=override, **options) - self._cdefsources.append(csource) - if override: - for cache in self._function_caches: - cache.clear() - finishlist = self._parser._recomplete - if finishlist: - self._parser._recomplete = [] - for tp in finishlist: - tp.finish_backend_type(self, finishlist) - - def dlopen(self, name, flags=0): - """Load and return a dynamic library identified by 'name'. - The standard C library can be loaded by passing None. - Note that functions and types declared by 'ffi.cdef()' are not - linked to a particular library, just like C headers; in the - library we only look for the actual (untyped) symbols. - """ - if not (isinstance(name, basestring) or - name is None or - isinstance(name, self.CData)): - raise TypeError("dlopen(name): name must be a file name, None, " - "or an already-opened 'void *' handle") - with self._lock: - lib, function_cache = _make_ffi_library(self, name, flags) - self._function_caches.append(function_cache) - self._libraries.append(lib) - return lib - - def dlclose(self, lib): - """Close a library obtained with ffi.dlopen(). After this call, - access to functions or variables from the library will fail - (possibly with a segmentation fault). - """ - type(lib).__cffi_close__(lib) - - def _typeof_locked(self, cdecl): - # call me with the lock! - key = cdecl - if key in self._parsed_types: - return self._parsed_types[key] - # - if not isinstance(cdecl, str): # unicode, on Python 2 - cdecl = cdecl.encode('ascii') - # - type = self._parser.parse_type(cdecl) - really_a_function_type = type.is_raw_function - if really_a_function_type: - type = type.as_function_pointer() - btype = self._get_cached_btype(type) - result = btype, really_a_function_type - self._parsed_types[key] = result - return result - - def _typeof(self, cdecl, consider_function_as_funcptr=False): - # string -> ctype object - try: - result = self._parsed_types[cdecl] - except KeyError: - with self._lock: - result = self._typeof_locked(cdecl) - # - btype, really_a_function_type = result - if really_a_function_type and not consider_function_as_funcptr: - raise CDefError("the type %r is a function type, not a " - "pointer-to-function type" % (cdecl,)) - return btype - - def typeof(self, cdecl): - """Parse the C type given as a string and return the - corresponding object. - It can also be used on 'cdata' instance to get its C type. - """ - if isinstance(cdecl, basestring): - return self._typeof(cdecl) - if isinstance(cdecl, self.CData): - return self._backend.typeof(cdecl) - if isinstance(cdecl, types.BuiltinFunctionType): - res = _builtin_function_type(cdecl) - if res is not None: - return res - if (isinstance(cdecl, types.FunctionType) - and hasattr(cdecl, '_cffi_base_type')): - with self._lock: - return self._get_cached_btype(cdecl._cffi_base_type) - raise TypeError(type(cdecl)) - - def sizeof(self, cdecl): - """Return the size in bytes of the argument. It can be a - string naming a C type, or a 'cdata' instance. - """ - if isinstance(cdecl, basestring): - BType = self._typeof(cdecl) - return self._backend.sizeof(BType) - else: - return self._backend.sizeof(cdecl) - - def alignof(self, cdecl): - """Return the natural alignment size in bytes of the C type - given as a string. - """ - if isinstance(cdecl, basestring): - cdecl = self._typeof(cdecl) - return self._backend.alignof(cdecl) - - def offsetof(self, cdecl, *fields_or_indexes): - """Return the offset of the named field inside the given - structure or array, which must be given as a C type name. - You can give several field names in case of nested structures. - You can also give numeric values which correspond to array - items, in case of an array type. - """ - if isinstance(cdecl, basestring): - cdecl = self._typeof(cdecl) - return self._typeoffsetof(cdecl, *fields_or_indexes)[1] - - def new(self, cdecl, init=None): - """Allocate an instance according to the specified C type and - return a pointer to it. The specified C type must be either a - pointer or an array: ``new('X *')`` allocates an X and returns - a pointer to it, whereas ``new('X[n]')`` allocates an array of - n X'es and returns an array referencing it (which works - mostly like a pointer, like in C). You can also use - ``new('X[]', n)`` to allocate an array of a non-constant - length n. - - The memory is initialized following the rules of declaring a - global variable in C: by default it is zero-initialized, but - an explicit initializer can be given which can be used to - fill all or part of the memory. - - When the returned object goes out of scope, the memory - is freed. In other words the returned object has - ownership of the value of type 'cdecl' that it points to. This - means that the raw data can be used as long as this object is - kept alive, but must not be used for a longer time. Be careful - about that when copying the pointer to the memory somewhere - else, e.g. into another structure. - """ - if isinstance(cdecl, basestring): - cdecl = self._typeof(cdecl) - return self._backend.newp(cdecl, init) - - def new_allocator(self, alloc=None, free=None, - should_clear_after_alloc=True): - """Return a new allocator, i.e. a function that behaves like ffi.new() - but uses the provided low-level 'alloc' and 'free' functions. - - 'alloc' is called with the size as argument. If it returns NULL, a - MemoryError is raised. 'free' is called with the result of 'alloc' - as argument. Both can be either Python function or directly C - functions. If 'free' is None, then no free function is called. - If both 'alloc' and 'free' are None, the default is used. - - If 'should_clear_after_alloc' is set to False, then the memory - returned by 'alloc' is assumed to be already cleared (or you are - fine with garbage); otherwise CFFI will clear it. - """ - compiled_ffi = self._backend.FFI() - allocator = compiled_ffi.new_allocator(alloc, free, - should_clear_after_alloc) - def allocate(cdecl, init=None): - if isinstance(cdecl, basestring): - cdecl = self._typeof(cdecl) - return allocator(cdecl, init) - return allocate - - def cast(self, cdecl, source): - """Similar to a C cast: returns an instance of the named C - type initialized with the given 'source'. The source is - casted between integers or pointers of any type. - """ - if isinstance(cdecl, basestring): - cdecl = self._typeof(cdecl) - return self._backend.cast(cdecl, source) - - def string(self, cdata, maxlen=-1): - """Return a Python string (or unicode string) from the 'cdata'. - If 'cdata' is a pointer or array of characters or bytes, returns - the null-terminated string. The returned string extends until - the first null character, or at most 'maxlen' characters. If - 'cdata' is an array then 'maxlen' defaults to its length. - - If 'cdata' is a pointer or array of wchar_t, returns a unicode - string following the same rules. - - If 'cdata' is a single character or byte or a wchar_t, returns - it as a string or unicode string. - - If 'cdata' is an enum, returns the value of the enumerator as a - string, or 'NUMBER' if the value is out of range. - """ - return self._backend.string(cdata, maxlen) - - def unpack(self, cdata, length): - """Unpack an array of C data of the given length, - returning a Python string/unicode/list. - - If 'cdata' is a pointer to 'char', returns a byte string. - It does not stop at the first null. This is equivalent to: - ffi.buffer(cdata, length)[:] - - If 'cdata' is a pointer to 'wchar_t', returns a unicode string. - 'length' is measured in wchar_t's; it is not the size in bytes. - - If 'cdata' is a pointer to anything else, returns a list of - 'length' items. This is a faster equivalent to: - [cdata[i] for i in range(length)] - """ - return self._backend.unpack(cdata, length) - - #def buffer(self, cdata, size=-1): - # """Return a read-write buffer object that references the raw C data - # pointed to by the given 'cdata'. The 'cdata' must be a pointer or - # an array. Can be passed to functions expecting a buffer, or directly - # manipulated with: - # - # buf[:] get a copy of it in a regular string, or - # buf[idx] as a single character - # buf[:] = ... - # buf[idx] = ... change the content - # """ - # note that 'buffer' is a type, set on this instance by __init__ - - def from_buffer(self, cdecl, python_buffer=_unspecified, - require_writable=False): - """Return a cdata of the given type pointing to the data of the - given Python object, which must support the buffer interface. - Note that this is not meant to be used on the built-in types - str or unicode (you can build 'char[]' arrays explicitly) - but only on objects containing large quantities of raw data - in some other format, like 'array.array' or numpy arrays. - - The first argument is optional and default to 'char[]'. - """ - if python_buffer is _unspecified: - cdecl, python_buffer = self.BCharA, cdecl - elif isinstance(cdecl, basestring): - cdecl = self._typeof(cdecl) - return self._backend.from_buffer(cdecl, python_buffer, - require_writable) - - def memmove(self, dest, src, n): - """ffi.memmove(dest, src, n) copies n bytes of memory from src to dest. - - Like the C function memmove(), the memory areas may overlap; - apart from that it behaves like the C function memcpy(). - - 'src' can be any cdata ptr or array, or any Python buffer object. - 'dest' can be any cdata ptr or array, or a writable Python buffer - object. The size to copy, 'n', is always measured in bytes. - - Unlike other methods, this one supports all Python buffer including - byte strings and bytearrays---but it still does not support - non-contiguous buffers. - """ - return self._backend.memmove(dest, src, n) - - def callback(self, cdecl, python_callable=None, error=None, onerror=None): - """Return a callback object or a decorator making such a - callback object. 'cdecl' must name a C function pointer type. - The callback invokes the specified 'python_callable' (which may - be provided either directly or via a decorator). Important: the - callback object must be manually kept alive for as long as the - callback may be invoked from the C level. - """ - def callback_decorator_wrap(python_callable): - if not callable(python_callable): - raise TypeError("the 'python_callable' argument " - "is not callable") - return self._backend.callback(cdecl, python_callable, - error, onerror) - if isinstance(cdecl, basestring): - cdecl = self._typeof(cdecl, consider_function_as_funcptr=True) - if python_callable is None: - return callback_decorator_wrap # decorator mode - else: - return callback_decorator_wrap(python_callable) # direct mode - - def getctype(self, cdecl, replace_with=''): - """Return a string giving the C type 'cdecl', which may be itself - a string or a object. If 'replace_with' is given, it gives - extra text to append (or insert for more complicated C types), like - a variable name, or '*' to get actually the C type 'pointer-to-cdecl'. - """ - if isinstance(cdecl, basestring): - cdecl = self._typeof(cdecl) - replace_with = replace_with.strip() - if (replace_with.startswith('*') - and '&[' in self._backend.getcname(cdecl, '&')): - replace_with = '(%s)' % replace_with - elif replace_with and not replace_with[0] in '[(': - replace_with = ' ' + replace_with - return self._backend.getcname(cdecl, replace_with) - - def gc(self, cdata, destructor, size=0): - """Return a new cdata object that points to the same - data. Later, when this new cdata object is garbage-collected, - 'destructor(old_cdata_object)' will be called. - - The optional 'size' gives an estimate of the size, used to - trigger the garbage collection more eagerly. So far only used - on PyPy. It tells the GC that the returned object keeps alive - roughly 'size' bytes of external memory. - """ - return self._backend.gcp(cdata, destructor, size) - - def _get_cached_btype(self, type): - assert self._lock.acquire(False) is False - # call me with the lock! - try: - BType = self._cached_btypes[type] - except KeyError: - finishlist = [] - BType = type.get_cached_btype(self, finishlist) - for type in finishlist: - type.finish_backend_type(self, finishlist) - return BType - - def verify(self, source='', tmpdir=None, **kwargs): - """Verify that the current ffi signatures compile on this - machine, and return a dynamic library object. The dynamic - library can be used to call functions and access global - variables declared in this 'ffi'. The library is compiled - by the C compiler: it gives you C-level API compatibility - (including calling macros). This is unlike 'ffi.dlopen()', - which requires binary compatibility in the signatures. - """ - from .verifier import Verifier, _caller_dir_pycache - # - # If set_unicode(True) was called, insert the UNICODE and - # _UNICODE macro declarations - if self._windows_unicode: - self._apply_windows_unicode(kwargs) - # - # Set the tmpdir here, and not in Verifier.__init__: it picks - # up the caller's directory, which we want to be the caller of - # ffi.verify(), as opposed to the caller of Veritier(). - tmpdir = tmpdir or _caller_dir_pycache() - # - # Make a Verifier() and use it to load the library. - self.verifier = Verifier(self, source, tmpdir, **kwargs) - lib = self.verifier.load_library() - # - # Save the loaded library for keep-alive purposes, even - # if the caller doesn't keep it alive itself (it should). - self._libraries.append(lib) - return lib - - def _get_errno(self): - return self._backend.get_errno() - def _set_errno(self, errno): - self._backend.set_errno(errno) - errno = property(_get_errno, _set_errno, None, - "the value of 'errno' from/to the C calls") - - def getwinerror(self, code=-1): - return self._backend.getwinerror(code) - - def _pointer_to(self, ctype): - with self._lock: - return model.pointer_cache(self, ctype) - - def addressof(self, cdata, *fields_or_indexes): - """Return the address of a . - If 'fields_or_indexes' are given, returns the address of that - field or array item in the structure or array, recursively in - case of nested structures. - """ - try: - ctype = self._backend.typeof(cdata) - except TypeError: - if '__addressof__' in type(cdata).__dict__: - return type(cdata).__addressof__(cdata, *fields_or_indexes) - raise - if fields_or_indexes: - ctype, offset = self._typeoffsetof(ctype, *fields_or_indexes) - else: - if ctype.kind == "pointer": - raise TypeError("addressof(pointer)") - offset = 0 - ctypeptr = self._pointer_to(ctype) - return self._backend.rawaddressof(ctypeptr, cdata, offset) - - def _typeoffsetof(self, ctype, field_or_index, *fields_or_indexes): - ctype, offset = self._backend.typeoffsetof(ctype, field_or_index) - for field1 in fields_or_indexes: - ctype, offset1 = self._backend.typeoffsetof(ctype, field1, 1) - offset += offset1 - return ctype, offset - - def include(self, ffi_to_include): - """Includes the typedefs, structs, unions and enums defined - in another FFI instance. Usage is similar to a #include in C, - where a part of the program might include types defined in - another part for its own usage. Note that the include() - method has no effect on functions, constants and global - variables, which must anyway be accessed directly from the - lib object returned by the original FFI instance. - """ - if not isinstance(ffi_to_include, FFI): - raise TypeError("ffi.include() expects an argument that is also of" - " type cffi.FFI, not %r" % ( - type(ffi_to_include).__name__,)) - if ffi_to_include is self: - raise ValueError("self.include(self)") - with ffi_to_include._lock: - with self._lock: - self._parser.include(ffi_to_include._parser) - self._cdefsources.append('[') - self._cdefsources.extend(ffi_to_include._cdefsources) - self._cdefsources.append(']') - self._included_ffis.append(ffi_to_include) - - def new_handle(self, x): - return self._backend.newp_handle(self.BVoidP, x) - - def from_handle(self, x): - return self._backend.from_handle(x) - - def release(self, x): - self._backend.release(x) - - def set_unicode(self, enabled_flag): - """Windows: if 'enabled_flag' is True, enable the UNICODE and - _UNICODE defines in C, and declare the types like TCHAR and LPTCSTR - to be (pointers to) wchar_t. If 'enabled_flag' is False, - declare these types to be (pointers to) plain 8-bit characters. - This is mostly for backward compatibility; you usually want True. - """ - if self._windows_unicode is not None: - raise ValueError("set_unicode() can only be called once") - enabled_flag = bool(enabled_flag) - if enabled_flag: - self.cdef("typedef wchar_t TBYTE;" - "typedef wchar_t TCHAR;" - "typedef const wchar_t *LPCTSTR;" - "typedef const wchar_t *PCTSTR;" - "typedef wchar_t *LPTSTR;" - "typedef wchar_t *PTSTR;" - "typedef TBYTE *PTBYTE;" - "typedef TCHAR *PTCHAR;") - else: - self.cdef("typedef char TBYTE;" - "typedef char TCHAR;" - "typedef const char *LPCTSTR;" - "typedef const char *PCTSTR;" - "typedef char *LPTSTR;" - "typedef char *PTSTR;" - "typedef TBYTE *PTBYTE;" - "typedef TCHAR *PTCHAR;") - self._windows_unicode = enabled_flag - - def _apply_windows_unicode(self, kwds): - defmacros = kwds.get('define_macros', ()) - if not isinstance(defmacros, (list, tuple)): - raise TypeError("'define_macros' must be a list or tuple") - defmacros = list(defmacros) + [('UNICODE', '1'), - ('_UNICODE', '1')] - kwds['define_macros'] = defmacros - - def _apply_embedding_fix(self, kwds): - # must include an argument like "-lpython2.7" for the compiler - def ensure(key, value): - lst = kwds.setdefault(key, []) - if value not in lst: - lst.append(value) - # - if '__pypy__' in sys.builtin_module_names: - import os - if sys.platform == "win32": - # we need 'libpypy-c.lib'. Current distributions of - # pypy (>= 4.1) contain it as 'libs/python27.lib'. - pythonlib = "python{0[0]}{0[1]}".format(sys.version_info) - if hasattr(sys, 'prefix'): - ensure('library_dirs', os.path.join(sys.prefix, 'libs')) - else: - # we need 'libpypy-c.{so,dylib}', which should be by - # default located in 'sys.prefix/bin' for installed - # systems. - if sys.version_info < (3,): - pythonlib = "pypy-c" - else: - pythonlib = "pypy3-c" - if hasattr(sys, 'prefix'): - ensure('library_dirs', os.path.join(sys.prefix, 'bin')) - # On uninstalled pypy's, the libpypy-c is typically found in - # .../pypy/goal/. - if hasattr(sys, 'prefix'): - ensure('library_dirs', os.path.join(sys.prefix, 'pypy', 'goal')) - else: - if sys.platform == "win32": - template = "python%d%d" - if hasattr(sys, 'gettotalrefcount'): - template += '_d' - else: - try: - import sysconfig - except ImportError: # 2.6 - from cffi._shimmed_dist_utils import sysconfig - template = "python%d.%d" - if sysconfig.get_config_var('DEBUG_EXT'): - template += sysconfig.get_config_var('DEBUG_EXT') - pythonlib = (template % - (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff)) - if hasattr(sys, 'abiflags'): - pythonlib += sys.abiflags - ensure('libraries', pythonlib) - if sys.platform == "win32": - ensure('extra_link_args', '/MANIFEST') - - def set_source(self, module_name, source, source_extension='.c', **kwds): - import os - if hasattr(self, '_assigned_source'): - raise ValueError("set_source() cannot be called several times " - "per ffi object") - if not isinstance(module_name, basestring): - raise TypeError("'module_name' must be a string") - if os.sep in module_name or (os.altsep and os.altsep in module_name): - raise ValueError("'module_name' must not contain '/': use a dotted " - "name to make a 'package.module' location") - self._assigned_source = (str(module_name), source, - source_extension, kwds) - - def set_source_pkgconfig(self, module_name, pkgconfig_libs, source, - source_extension='.c', **kwds): - from . import pkgconfig - if not isinstance(pkgconfig_libs, list): - raise TypeError("the pkgconfig_libs argument must be a list " - "of package names") - kwds2 = pkgconfig.flags_from_pkgconfig(pkgconfig_libs) - pkgconfig.merge_flags(kwds, kwds2) - self.set_source(module_name, source, source_extension, **kwds) - - def distutils_extension(self, tmpdir='build', verbose=True): - from cffi._shimmed_dist_utils import mkpath - from .recompiler import recompile - # - if not hasattr(self, '_assigned_source'): - if hasattr(self, 'verifier'): # fallback, 'tmpdir' ignored - return self.verifier.get_extension() - raise ValueError("set_source() must be called before" - " distutils_extension()") - module_name, source, source_extension, kwds = self._assigned_source - if source is None: - raise TypeError("distutils_extension() is only for C extension " - "modules, not for dlopen()-style pure Python " - "modules") - mkpath(tmpdir) - ext, updated = recompile(self, module_name, - source, tmpdir=tmpdir, extradir=tmpdir, - source_extension=source_extension, - call_c_compiler=False, **kwds) - if verbose: - if updated: - sys.stderr.write("regenerated: %r\n" % (ext.sources[0],)) - else: - sys.stderr.write("not modified: %r\n" % (ext.sources[0],)) - return ext - - def emit_c_code(self, filename): - from .recompiler import recompile - # - if not hasattr(self, '_assigned_source'): - raise ValueError("set_source() must be called before emit_c_code()") - module_name, source, source_extension, kwds = self._assigned_source - if source is None: - raise TypeError("emit_c_code() is only for C extension modules, " - "not for dlopen()-style pure Python modules") - recompile(self, module_name, source, - c_file=filename, call_c_compiler=False, - uses_ffiplatform=False, **kwds) - - def emit_python_code(self, filename): - from .recompiler import recompile - # - if not hasattr(self, '_assigned_source'): - raise ValueError("set_source() must be called before emit_c_code()") - module_name, source, source_extension, kwds = self._assigned_source - if source is not None: - raise TypeError("emit_python_code() is only for dlopen()-style " - "pure Python modules, not for C extension modules") - recompile(self, module_name, source, - c_file=filename, call_c_compiler=False, - uses_ffiplatform=False, **kwds) - - def compile(self, tmpdir='.', verbose=0, target=None, debug=None): - """The 'target' argument gives the final file name of the - compiled DLL. Use '*' to force distutils' choice, suitable for - regular CPython C API modules. Use a file name ending in '.*' - to ask for the system's default extension for dynamic libraries - (.so/.dll/.dylib). - - The default is '*' when building a non-embedded C API extension, - and (module_name + '.*') when building an embedded library. - """ - from .recompiler import recompile - # - if not hasattr(self, '_assigned_source'): - raise ValueError("set_source() must be called before compile()") - module_name, source, source_extension, kwds = self._assigned_source - return recompile(self, module_name, source, tmpdir=tmpdir, - target=target, source_extension=source_extension, - compiler_verbose=verbose, debug=debug, **kwds) - - def init_once(self, func, tag): - # Read _init_once_cache[tag], which is either (False, lock) if - # we're calling the function now in some thread, or (True, result). - # Don't call setdefault() in most cases, to avoid allocating and - # immediately freeing a lock; but still use setdefaut() to avoid - # races. - try: - x = self._init_once_cache[tag] - except KeyError: - x = self._init_once_cache.setdefault(tag, (False, allocate_lock())) - # Common case: we got (True, result), so we return the result. - if x[0]: - return x[1] - # Else, it's a lock. Acquire it to serialize the following tests. - with x[1]: - # Read again from _init_once_cache the current status. - x = self._init_once_cache[tag] - if x[0]: - return x[1] - # Call the function and store the result back. - result = func() - self._init_once_cache[tag] = (True, result) - return result - - def embedding_init_code(self, pysource): - if self._embedding: - raise ValueError("embedding_init_code() can only be called once") - # fix 'pysource' before it gets dumped into the C file: - # - remove empty lines at the beginning, so it starts at "line 1" - # - dedent, if all non-empty lines are indented - # - check for SyntaxErrors - import re - match = re.match(r'\s*\n', pysource) - if match: - pysource = pysource[match.end():] - lines = pysource.splitlines() or [''] - prefix = re.match(r'\s*', lines[0]).group() - for i in range(1, len(lines)): - line = lines[i] - if line.rstrip(): - while not line.startswith(prefix): - prefix = prefix[:-1] - i = len(prefix) - lines = [line[i:]+'\n' for line in lines] - pysource = ''.join(lines) - # - compile(pysource, "cffi_init", "exec") - # - self._embedding = pysource - - def def_extern(self, *args, **kwds): - raise ValueError("ffi.def_extern() is only available on API-mode FFI " - "objects") - - def list_types(self): - """Returns the user type names known to this FFI instance. - This returns a tuple containing three lists of names: - (typedef_names, names_of_structs, names_of_unions) - """ - typedefs = [] - structs = [] - unions = [] - for key in self._parser._declarations: - if key.startswith('typedef '): - typedefs.append(key[8:]) - elif key.startswith('struct '): - structs.append(key[7:]) - elif key.startswith('union '): - unions.append(key[6:]) - typedefs.sort() - structs.sort() - unions.sort() - return (typedefs, structs, unions) - - -def _load_backend_lib(backend, name, flags): - import os - if not isinstance(name, basestring): - if sys.platform != "win32" or name is not None: - return backend.load_library(name, flags) - name = "c" # Windows: load_library(None) fails, but this works - # on Python 2 (backward compatibility hack only) - first_error = None - if '.' in name or '/' in name or os.sep in name: - try: - return backend.load_library(name, flags) - except OSError as e: - first_error = e - import ctypes.util - path = ctypes.util.find_library(name) - if path is None: - if name == "c" and sys.platform == "win32" and sys.version_info >= (3,): - raise OSError("dlopen(None) cannot work on Windows for Python 3 " - "(see http://bugs.python.org/issue23606)") - msg = ("ctypes.util.find_library() did not manage " - "to locate a library called %r" % (name,)) - if first_error is not None: - msg = "%s. Additionally, %s" % (first_error, msg) - raise OSError(msg) - return backend.load_library(path, flags) - -def _make_ffi_library(ffi, libname, flags): - backend = ffi._backend - backendlib = _load_backend_lib(backend, libname, flags) - # - def accessor_function(name): - key = 'function ' + name - tp, _ = ffi._parser._declarations[key] - BType = ffi._get_cached_btype(tp) - value = backendlib.load_function(BType, name) - library.__dict__[name] = value - # - def accessor_variable(name): - key = 'variable ' + name - tp, _ = ffi._parser._declarations[key] - BType = ffi._get_cached_btype(tp) - read_variable = backendlib.read_variable - write_variable = backendlib.write_variable - setattr(FFILibrary, name, property( - lambda self: read_variable(BType, name), - lambda self, value: write_variable(BType, name, value))) - # - def addressof_var(name): - try: - return addr_variables[name] - except KeyError: - with ffi._lock: - if name not in addr_variables: - key = 'variable ' + name - tp, _ = ffi._parser._declarations[key] - BType = ffi._get_cached_btype(tp) - if BType.kind != 'array': - BType = model.pointer_cache(ffi, BType) - p = backendlib.load_function(BType, name) - addr_variables[name] = p - return addr_variables[name] - # - def accessor_constant(name): - raise NotImplementedError("non-integer constant '%s' cannot be " - "accessed from a dlopen() library" % (name,)) - # - def accessor_int_constant(name): - library.__dict__[name] = ffi._parser._int_constants[name] - # - accessors = {} - accessors_version = [False] - addr_variables = {} - # - def update_accessors(): - if accessors_version[0] is ffi._cdef_version: - return - # - for key, (tp, _) in ffi._parser._declarations.items(): - if not isinstance(tp, model.EnumType): - tag, name = key.split(' ', 1) - if tag == 'function': - accessors[name] = accessor_function - elif tag == 'variable': - accessors[name] = accessor_variable - elif tag == 'constant': - accessors[name] = accessor_constant - else: - for i, enumname in enumerate(tp.enumerators): - def accessor_enum(name, tp=tp, i=i): - tp.check_not_partial() - library.__dict__[name] = tp.enumvalues[i] - accessors[enumname] = accessor_enum - for name in ffi._parser._int_constants: - accessors.setdefault(name, accessor_int_constant) - accessors_version[0] = ffi._cdef_version - # - def make_accessor(name): - with ffi._lock: - if name in library.__dict__ or name in FFILibrary.__dict__: - return # added by another thread while waiting for the lock - if name not in accessors: - update_accessors() - if name not in accessors: - raise AttributeError(name) - accessors[name](name) - # - class FFILibrary(object): - def __getattr__(self, name): - make_accessor(name) - return getattr(self, name) - def __setattr__(self, name, value): - try: - property = getattr(self.__class__, name) - except AttributeError: - make_accessor(name) - setattr(self, name, value) - else: - property.__set__(self, value) - def __dir__(self): - with ffi._lock: - update_accessors() - return accessors.keys() - def __addressof__(self, name): - if name in library.__dict__: - return library.__dict__[name] - if name in FFILibrary.__dict__: - return addressof_var(name) - make_accessor(name) - if name in library.__dict__: - return library.__dict__[name] - if name in FFILibrary.__dict__: - return addressof_var(name) - raise AttributeError("cffi library has no function or " - "global variable named '%s'" % (name,)) - def __cffi_close__(self): - backendlib.close_lib() - self.__dict__.clear() - # - if isinstance(libname, basestring): - try: - if not isinstance(libname, str): # unicode, on Python 2 - libname = libname.encode('utf-8') - FFILibrary.__name__ = 'FFILibrary_%s' % libname - except UnicodeError: - pass - library = FFILibrary() - return library, library.__dict__ - -def _builtin_function_type(func): - # a hack to make at least ffi.typeof(builtin_function) work, - # if the builtin function was obtained by 'vengine_cpy'. - import sys - try: - module = sys.modules[func.__module__] - ffi = module._cffi_original_ffi - types_of_builtin_funcs = module._cffi_types_of_builtin_funcs - tp = types_of_builtin_funcs[func] - except (KeyError, AttributeError, TypeError): - return None - else: - with ffi._lock: - return ffi._get_cached_btype(tp) diff --git a/.venv/lib/python3.12/site-packages/cffi/backend_ctypes.py b/.venv/lib/python3.12/site-packages/cffi/backend_ctypes.py deleted file mode 100644 index e7956a7..0000000 --- a/.venv/lib/python3.12/site-packages/cffi/backend_ctypes.py +++ /dev/null @@ -1,1121 +0,0 @@ -import ctypes, ctypes.util, operator, sys -from . import model - -if sys.version_info < (3,): - bytechr = chr -else: - unicode = str - long = int - xrange = range - bytechr = lambda num: bytes([num]) - -class CTypesType(type): - pass - -class CTypesData(object): - __metaclass__ = CTypesType - __slots__ = ['__weakref__'] - __name__ = '' - - def __init__(self, *args): - raise TypeError("cannot instantiate %r" % (self.__class__,)) - - @classmethod - def _newp(cls, init): - raise TypeError("expected a pointer or array ctype, got '%s'" - % (cls._get_c_name(),)) - - @staticmethod - def _to_ctypes(value): - raise TypeError - - @classmethod - def _arg_to_ctypes(cls, *value): - try: - ctype = cls._ctype - except AttributeError: - raise TypeError("cannot create an instance of %r" % (cls,)) - if value: - res = cls._to_ctypes(*value) - if not isinstance(res, ctype): - res = cls._ctype(res) - else: - res = cls._ctype() - return res - - @classmethod - def _create_ctype_obj(cls, init): - if init is None: - return cls._arg_to_ctypes() - else: - return cls._arg_to_ctypes(init) - - @staticmethod - def _from_ctypes(ctypes_value): - raise TypeError - - @classmethod - def _get_c_name(cls, replace_with=''): - return cls._reftypename.replace(' &', replace_with) - - @classmethod - def _fix_class(cls): - cls.__name__ = 'CData<%s>' % (cls._get_c_name(),) - cls.__qualname__ = 'CData<%s>' % (cls._get_c_name(),) - cls.__module__ = 'ffi' - - def _get_own_repr(self): - raise NotImplementedError - - def _addr_repr(self, address): - if address == 0: - return 'NULL' - else: - if address < 0: - address += 1 << (8*ctypes.sizeof(ctypes.c_void_p)) - return '0x%x' % address - - def __repr__(self, c_name=None): - own = self._get_own_repr() - return '' % (c_name or self._get_c_name(), own) - - def _convert_to_address(self, BClass): - if BClass is None: - raise TypeError("cannot convert %r to an address" % ( - self._get_c_name(),)) - else: - raise TypeError("cannot convert %r to %r" % ( - self._get_c_name(), BClass._get_c_name())) - - @classmethod - def _get_size(cls): - return ctypes.sizeof(cls._ctype) - - def _get_size_of_instance(self): - return ctypes.sizeof(self._ctype) - - @classmethod - def _cast_from(cls, source): - raise TypeError("cannot cast to %r" % (cls._get_c_name(),)) - - def _cast_to_integer(self): - return self._convert_to_address(None) - - @classmethod - def _alignment(cls): - return ctypes.alignment(cls._ctype) - - def __iter__(self): - raise TypeError("cdata %r does not support iteration" % ( - self._get_c_name()),) - - def _make_cmp(name): - cmpfunc = getattr(operator, name) - def cmp(self, other): - v_is_ptr = not isinstance(self, CTypesGenericPrimitive) - w_is_ptr = (isinstance(other, CTypesData) and - not isinstance(other, CTypesGenericPrimitive)) - if v_is_ptr and w_is_ptr: - return cmpfunc(self._convert_to_address(None), - other._convert_to_address(None)) - elif v_is_ptr or w_is_ptr: - return NotImplemented - else: - if isinstance(self, CTypesGenericPrimitive): - self = self._value - if isinstance(other, CTypesGenericPrimitive): - other = other._value - return cmpfunc(self, other) - cmp.func_name = name - return cmp - - __eq__ = _make_cmp('__eq__') - __ne__ = _make_cmp('__ne__') - __lt__ = _make_cmp('__lt__') - __le__ = _make_cmp('__le__') - __gt__ = _make_cmp('__gt__') - __ge__ = _make_cmp('__ge__') - - def __hash__(self): - return hash(self._convert_to_address(None)) - - def _to_string(self, maxlen): - raise TypeError("string(): %r" % (self,)) - - -class CTypesGenericPrimitive(CTypesData): - __slots__ = [] - - def __hash__(self): - return hash(self._value) - - def _get_own_repr(self): - return repr(self._from_ctypes(self._value)) - - -class CTypesGenericArray(CTypesData): - __slots__ = [] - - @classmethod - def _newp(cls, init): - return cls(init) - - def __iter__(self): - for i in xrange(len(self)): - yield self[i] - - def _get_own_repr(self): - return self._addr_repr(ctypes.addressof(self._blob)) - - -class CTypesGenericPtr(CTypesData): - __slots__ = ['_address', '_as_ctype_ptr'] - _automatic_casts = False - kind = "pointer" - - @classmethod - def _newp(cls, init): - return cls(init) - - @classmethod - def _cast_from(cls, source): - if source is None: - address = 0 - elif isinstance(source, CTypesData): - address = source._cast_to_integer() - elif isinstance(source, (int, long)): - address = source - else: - raise TypeError("bad type for cast to %r: %r" % - (cls, type(source).__name__)) - return cls._new_pointer_at(address) - - @classmethod - def _new_pointer_at(cls, address): - self = cls.__new__(cls) - self._address = address - self._as_ctype_ptr = ctypes.cast(address, cls._ctype) - return self - - def _get_own_repr(self): - try: - return self._addr_repr(self._address) - except AttributeError: - return '???' - - def _cast_to_integer(self): - return self._address - - def __nonzero__(self): - return bool(self._address) - __bool__ = __nonzero__ - - @classmethod - def _to_ctypes(cls, value): - if not isinstance(value, CTypesData): - raise TypeError("unexpected %s object" % type(value).__name__) - address = value._convert_to_address(cls) - return ctypes.cast(address, cls._ctype) - - @classmethod - def _from_ctypes(cls, ctypes_ptr): - address = ctypes.cast(ctypes_ptr, ctypes.c_void_p).value or 0 - return cls._new_pointer_at(address) - - @classmethod - def _initialize(cls, ctypes_ptr, value): - if value: - ctypes_ptr.contents = cls._to_ctypes(value).contents - - def _convert_to_address(self, BClass): - if (BClass in (self.__class__, None) or BClass._automatic_casts - or self._automatic_casts): - return self._address - else: - return CTypesData._convert_to_address(self, BClass) - - -class CTypesBaseStructOrUnion(CTypesData): - __slots__ = ['_blob'] - - @classmethod - def _create_ctype_obj(cls, init): - # may be overridden - raise TypeError("cannot instantiate opaque type %s" % (cls,)) - - def _get_own_repr(self): - return self._addr_repr(ctypes.addressof(self._blob)) - - @classmethod - def _offsetof(cls, fieldname): - return getattr(cls._ctype, fieldname).offset - - def _convert_to_address(self, BClass): - if getattr(BClass, '_BItem', None) is self.__class__: - return ctypes.addressof(self._blob) - else: - return CTypesData._convert_to_address(self, BClass) - - @classmethod - def _from_ctypes(cls, ctypes_struct_or_union): - self = cls.__new__(cls) - self._blob = ctypes_struct_or_union - return self - - @classmethod - def _to_ctypes(cls, value): - return value._blob - - def __repr__(self, c_name=None): - return CTypesData.__repr__(self, c_name or self._get_c_name(' &')) - - -class CTypesBackend(object): - - PRIMITIVE_TYPES = { - 'char': ctypes.c_char, - 'short': ctypes.c_short, - 'int': ctypes.c_int, - 'long': ctypes.c_long, - 'long long': ctypes.c_longlong, - 'signed char': ctypes.c_byte, - 'unsigned char': ctypes.c_ubyte, - 'unsigned short': ctypes.c_ushort, - 'unsigned int': ctypes.c_uint, - 'unsigned long': ctypes.c_ulong, - 'unsigned long long': ctypes.c_ulonglong, - 'float': ctypes.c_float, - 'double': ctypes.c_double, - '_Bool': ctypes.c_bool, - } - - for _name in ['unsigned long long', 'unsigned long', - 'unsigned int', 'unsigned short', 'unsigned char']: - _size = ctypes.sizeof(PRIMITIVE_TYPES[_name]) - PRIMITIVE_TYPES['uint%d_t' % (8*_size)] = PRIMITIVE_TYPES[_name] - if _size == ctypes.sizeof(ctypes.c_void_p): - PRIMITIVE_TYPES['uintptr_t'] = PRIMITIVE_TYPES[_name] - if _size == ctypes.sizeof(ctypes.c_size_t): - PRIMITIVE_TYPES['size_t'] = PRIMITIVE_TYPES[_name] - - for _name in ['long long', 'long', 'int', 'short', 'signed char']: - _size = ctypes.sizeof(PRIMITIVE_TYPES[_name]) - PRIMITIVE_TYPES['int%d_t' % (8*_size)] = PRIMITIVE_TYPES[_name] - if _size == ctypes.sizeof(ctypes.c_void_p): - PRIMITIVE_TYPES['intptr_t'] = PRIMITIVE_TYPES[_name] - PRIMITIVE_TYPES['ptrdiff_t'] = PRIMITIVE_TYPES[_name] - if _size == ctypes.sizeof(ctypes.c_size_t): - PRIMITIVE_TYPES['ssize_t'] = PRIMITIVE_TYPES[_name] - - - def __init__(self): - self.RTLD_LAZY = 0 # not supported anyway by ctypes - self.RTLD_NOW = 0 - self.RTLD_GLOBAL = ctypes.RTLD_GLOBAL - self.RTLD_LOCAL = ctypes.RTLD_LOCAL - - def set_ffi(self, ffi): - self.ffi = ffi - - def _get_types(self): - return CTypesData, CTypesType - - def load_library(self, path, flags=0): - cdll = ctypes.CDLL(path, flags) - return CTypesLibrary(self, cdll) - - def new_void_type(self): - class CTypesVoid(CTypesData): - __slots__ = [] - _reftypename = 'void &' - @staticmethod - def _from_ctypes(novalue): - return None - @staticmethod - def _to_ctypes(novalue): - if novalue is not None: - raise TypeError("None expected, got %s object" % - (type(novalue).__name__,)) - return None - CTypesVoid._fix_class() - return CTypesVoid - - def new_primitive_type(self, name): - if name == 'wchar_t': - raise NotImplementedError(name) - ctype = self.PRIMITIVE_TYPES[name] - if name == 'char': - kind = 'char' - elif name in ('float', 'double'): - kind = 'float' - else: - if name in ('signed char', 'unsigned char'): - kind = 'byte' - elif name == '_Bool': - kind = 'bool' - else: - kind = 'int' - is_signed = (ctype(-1).value == -1) - # - def _cast_source_to_int(source): - if isinstance(source, (int, long, float)): - source = int(source) - elif isinstance(source, CTypesData): - source = source._cast_to_integer() - elif isinstance(source, bytes): - source = ord(source) - elif source is None: - source = 0 - else: - raise TypeError("bad type for cast to %r: %r" % - (CTypesPrimitive, type(source).__name__)) - return source - # - kind1 = kind - class CTypesPrimitive(CTypesGenericPrimitive): - __slots__ = ['_value'] - _ctype = ctype - _reftypename = '%s &' % name - kind = kind1 - - def __init__(self, value): - self._value = value - - @staticmethod - def _create_ctype_obj(init): - if init is None: - return ctype() - return ctype(CTypesPrimitive._to_ctypes(init)) - - if kind == 'int' or kind == 'byte': - @classmethod - def _cast_from(cls, source): - source = _cast_source_to_int(source) - source = ctype(source).value # cast within range - return cls(source) - def __int__(self): - return self._value - - if kind == 'bool': - @classmethod - def _cast_from(cls, source): - if not isinstance(source, (int, long, float)): - source = _cast_source_to_int(source) - return cls(bool(source)) - def __int__(self): - return int(self._value) - - if kind == 'char': - @classmethod - def _cast_from(cls, source): - source = _cast_source_to_int(source) - source = bytechr(source & 0xFF) - return cls(source) - def __int__(self): - return ord(self._value) - - if kind == 'float': - @classmethod - def _cast_from(cls, source): - if isinstance(source, float): - pass - elif isinstance(source, CTypesGenericPrimitive): - if hasattr(source, '__float__'): - source = float(source) - else: - source = int(source) - else: - source = _cast_source_to_int(source) - source = ctype(source).value # fix precision - return cls(source) - def __int__(self): - return int(self._value) - def __float__(self): - return self._value - - _cast_to_integer = __int__ - - if kind == 'int' or kind == 'byte' or kind == 'bool': - @staticmethod - def _to_ctypes(x): - if not isinstance(x, (int, long)): - if isinstance(x, CTypesData): - x = int(x) - else: - raise TypeError("integer expected, got %s" % - type(x).__name__) - if ctype(x).value != x: - if not is_signed and x < 0: - raise OverflowError("%s: negative integer" % name) - else: - raise OverflowError("%s: integer out of bounds" - % name) - return x - - if kind == 'char': - @staticmethod - def _to_ctypes(x): - if isinstance(x, bytes) and len(x) == 1: - return x - if isinstance(x, CTypesPrimitive): # > - return x._value - raise TypeError("character expected, got %s" % - type(x).__name__) - def __nonzero__(self): - return ord(self._value) != 0 - else: - def __nonzero__(self): - return self._value != 0 - __bool__ = __nonzero__ - - if kind == 'float': - @staticmethod - def _to_ctypes(x): - if not isinstance(x, (int, long, float, CTypesData)): - raise TypeError("float expected, got %s" % - type(x).__name__) - return ctype(x).value - - @staticmethod - def _from_ctypes(value): - return getattr(value, 'value', value) - - @staticmethod - def _initialize(blob, init): - blob.value = CTypesPrimitive._to_ctypes(init) - - if kind == 'char': - def _to_string(self, maxlen): - return self._value - if kind == 'byte': - def _to_string(self, maxlen): - return chr(self._value & 0xff) - # - CTypesPrimitive._fix_class() - return CTypesPrimitive - - def new_pointer_type(self, BItem): - getbtype = self.ffi._get_cached_btype - if BItem is getbtype(model.PrimitiveType('char')): - kind = 'charp' - elif BItem in (getbtype(model.PrimitiveType('signed char')), - getbtype(model.PrimitiveType('unsigned char'))): - kind = 'bytep' - elif BItem is getbtype(model.void_type): - kind = 'voidp' - else: - kind = 'generic' - # - class CTypesPtr(CTypesGenericPtr): - __slots__ = ['_own'] - if kind == 'charp': - __slots__ += ['__as_strbuf'] - _BItem = BItem - if hasattr(BItem, '_ctype'): - _ctype = ctypes.POINTER(BItem._ctype) - _bitem_size = ctypes.sizeof(BItem._ctype) - else: - _ctype = ctypes.c_void_p - if issubclass(BItem, CTypesGenericArray): - _reftypename = BItem._get_c_name('(* &)') - else: - _reftypename = BItem._get_c_name(' * &') - - def __init__(self, init): - ctypeobj = BItem._create_ctype_obj(init) - if kind == 'charp': - self.__as_strbuf = ctypes.create_string_buffer( - ctypeobj.value + b'\x00') - self._as_ctype_ptr = ctypes.cast( - self.__as_strbuf, self._ctype) - else: - self._as_ctype_ptr = ctypes.pointer(ctypeobj) - self._address = ctypes.cast(self._as_ctype_ptr, - ctypes.c_void_p).value - self._own = True - - def __add__(self, other): - if isinstance(other, (int, long)): - return self._new_pointer_at(self._address + - other * self._bitem_size) - else: - return NotImplemented - - def __sub__(self, other): - if isinstance(other, (int, long)): - return self._new_pointer_at(self._address - - other * self._bitem_size) - elif type(self) is type(other): - return (self._address - other._address) // self._bitem_size - else: - return NotImplemented - - def __getitem__(self, index): - if getattr(self, '_own', False) and index != 0: - raise IndexError - return BItem._from_ctypes(self._as_ctype_ptr[index]) - - def __setitem__(self, index, value): - self._as_ctype_ptr[index] = BItem._to_ctypes(value) - - if kind == 'charp' or kind == 'voidp': - @classmethod - def _arg_to_ctypes(cls, *value): - if value and isinstance(value[0], bytes): - return ctypes.c_char_p(value[0]) - else: - return super(CTypesPtr, cls)._arg_to_ctypes(*value) - - if kind == 'charp' or kind == 'bytep': - def _to_string(self, maxlen): - if maxlen < 0: - maxlen = sys.maxsize - p = ctypes.cast(self._as_ctype_ptr, - ctypes.POINTER(ctypes.c_char)) - n = 0 - while n < maxlen and p[n] != b'\x00': - n += 1 - return b''.join([p[i] for i in range(n)]) - - def _get_own_repr(self): - if getattr(self, '_own', False): - return 'owning %d bytes' % ( - ctypes.sizeof(self._as_ctype_ptr.contents),) - return super(CTypesPtr, self)._get_own_repr() - # - if (BItem is self.ffi._get_cached_btype(model.void_type) or - BItem is self.ffi._get_cached_btype(model.PrimitiveType('char'))): - CTypesPtr._automatic_casts = True - # - CTypesPtr._fix_class() - return CTypesPtr - - def new_array_type(self, CTypesPtr, length): - if length is None: - brackets = ' &[]' - else: - brackets = ' &[%d]' % length - BItem = CTypesPtr._BItem - getbtype = self.ffi._get_cached_btype - if BItem is getbtype(model.PrimitiveType('char')): - kind = 'char' - elif BItem in (getbtype(model.PrimitiveType('signed char')), - getbtype(model.PrimitiveType('unsigned char'))): - kind = 'byte' - else: - kind = 'generic' - # - class CTypesArray(CTypesGenericArray): - __slots__ = ['_blob', '_own'] - if length is not None: - _ctype = BItem._ctype * length - else: - __slots__.append('_ctype') - _reftypename = BItem._get_c_name(brackets) - _declared_length = length - _CTPtr = CTypesPtr - - def __init__(self, init): - if length is None: - if isinstance(init, (int, long)): - len1 = init - init = None - elif kind == 'char' and isinstance(init, bytes): - len1 = len(init) + 1 # extra null - else: - init = tuple(init) - len1 = len(init) - self._ctype = BItem._ctype * len1 - self._blob = self._ctype() - self._own = True - if init is not None: - self._initialize(self._blob, init) - - @staticmethod - def _initialize(blob, init): - if isinstance(init, bytes): - init = [init[i:i+1] for i in range(len(init))] - else: - if isinstance(init, CTypesGenericArray): - if (len(init) != len(blob) or - not isinstance(init, CTypesArray)): - raise TypeError("length/type mismatch: %s" % (init,)) - init = tuple(init) - if len(init) > len(blob): - raise IndexError("too many initializers") - addr = ctypes.cast(blob, ctypes.c_void_p).value - PTR = ctypes.POINTER(BItem._ctype) - itemsize = ctypes.sizeof(BItem._ctype) - for i, value in enumerate(init): - p = ctypes.cast(addr + i * itemsize, PTR) - BItem._initialize(p.contents, value) - - def __len__(self): - return len(self._blob) - - def __getitem__(self, index): - if not (0 <= index < len(self._blob)): - raise IndexError - return BItem._from_ctypes(self._blob[index]) - - def __setitem__(self, index, value): - if not (0 <= index < len(self._blob)): - raise IndexError - self._blob[index] = BItem._to_ctypes(value) - - if kind == 'char' or kind == 'byte': - def _to_string(self, maxlen): - if maxlen < 0: - maxlen = len(self._blob) - p = ctypes.cast(self._blob, - ctypes.POINTER(ctypes.c_char)) - n = 0 - while n < maxlen and p[n] != b'\x00': - n += 1 - return b''.join([p[i] for i in range(n)]) - - def _get_own_repr(self): - if getattr(self, '_own', False): - return 'owning %d bytes' % (ctypes.sizeof(self._blob),) - return super(CTypesArray, self)._get_own_repr() - - def _convert_to_address(self, BClass): - if BClass in (CTypesPtr, None) or BClass._automatic_casts: - return ctypes.addressof(self._blob) - else: - return CTypesData._convert_to_address(self, BClass) - - @staticmethod - def _from_ctypes(ctypes_array): - self = CTypesArray.__new__(CTypesArray) - self._blob = ctypes_array - return self - - @staticmethod - def _arg_to_ctypes(value): - return CTypesPtr._arg_to_ctypes(value) - - def __add__(self, other): - if isinstance(other, (int, long)): - return CTypesPtr._new_pointer_at( - ctypes.addressof(self._blob) + - other * ctypes.sizeof(BItem._ctype)) - else: - return NotImplemented - - @classmethod - def _cast_from(cls, source): - raise NotImplementedError("casting to %r" % ( - cls._get_c_name(),)) - # - CTypesArray._fix_class() - return CTypesArray - - def _new_struct_or_union(self, kind, name, base_ctypes_class): - # - class struct_or_union(base_ctypes_class): - pass - struct_or_union.__name__ = '%s_%s' % (kind, name) - kind1 = kind - # - class CTypesStructOrUnion(CTypesBaseStructOrUnion): - __slots__ = ['_blob'] - _ctype = struct_or_union - _reftypename = '%s &' % (name,) - _kind = kind = kind1 - # - CTypesStructOrUnion._fix_class() - return CTypesStructOrUnion - - def new_struct_type(self, name): - return self._new_struct_or_union('struct', name, ctypes.Structure) - - def new_union_type(self, name): - return self._new_struct_or_union('union', name, ctypes.Union) - - def complete_struct_or_union(self, CTypesStructOrUnion, fields, tp, - totalsize=-1, totalalignment=-1, sflags=0, - pack=0): - if totalsize >= 0 or totalalignment >= 0: - raise NotImplementedError("the ctypes backend of CFFI does not support " - "structures completed by verify(); please " - "compile and install the _cffi_backend module.") - struct_or_union = CTypesStructOrUnion._ctype - fnames = [fname for (fname, BField, bitsize) in fields] - btypes = [BField for (fname, BField, bitsize) in fields] - bitfields = [bitsize for (fname, BField, bitsize) in fields] - # - bfield_types = {} - cfields = [] - for (fname, BField, bitsize) in fields: - if bitsize < 0: - cfields.append((fname, BField._ctype)) - bfield_types[fname] = BField - else: - cfields.append((fname, BField._ctype, bitsize)) - bfield_types[fname] = Ellipsis - if sflags & 8: - struct_or_union._pack_ = 1 - elif pack: - struct_or_union._pack_ = pack - struct_or_union._fields_ = cfields - CTypesStructOrUnion._bfield_types = bfield_types - # - @staticmethod - def _create_ctype_obj(init): - result = struct_or_union() - if init is not None: - initialize(result, init) - return result - CTypesStructOrUnion._create_ctype_obj = _create_ctype_obj - # - def initialize(blob, init): - if is_union: - if len(init) > 1: - raise ValueError("union initializer: %d items given, but " - "only one supported (use a dict if needed)" - % (len(init),)) - if not isinstance(init, dict): - if isinstance(init, (bytes, unicode)): - raise TypeError("union initializer: got a str") - init = tuple(init) - if len(init) > len(fnames): - raise ValueError("too many values for %s initializer" % - CTypesStructOrUnion._get_c_name()) - init = dict(zip(fnames, init)) - addr = ctypes.addressof(blob) - for fname, value in init.items(): - BField, bitsize = name2fieldtype[fname] - assert bitsize < 0, \ - "not implemented: initializer with bit fields" - offset = CTypesStructOrUnion._offsetof(fname) - PTR = ctypes.POINTER(BField._ctype) - p = ctypes.cast(addr + offset, PTR) - BField._initialize(p.contents, value) - is_union = CTypesStructOrUnion._kind == 'union' - name2fieldtype = dict(zip(fnames, zip(btypes, bitfields))) - # - for fname, BField, bitsize in fields: - if fname == '': - raise NotImplementedError("nested anonymous structs/unions") - if hasattr(CTypesStructOrUnion, fname): - raise ValueError("the field name %r conflicts in " - "the ctypes backend" % fname) - if bitsize < 0: - def getter(self, fname=fname, BField=BField, - offset=CTypesStructOrUnion._offsetof(fname), - PTR=ctypes.POINTER(BField._ctype)): - addr = ctypes.addressof(self._blob) - p = ctypes.cast(addr + offset, PTR) - return BField._from_ctypes(p.contents) - def setter(self, value, fname=fname, BField=BField): - setattr(self._blob, fname, BField._to_ctypes(value)) - # - if issubclass(BField, CTypesGenericArray): - setter = None - if BField._declared_length == 0: - def getter(self, fname=fname, BFieldPtr=BField._CTPtr, - offset=CTypesStructOrUnion._offsetof(fname), - PTR=ctypes.POINTER(BField._ctype)): - addr = ctypes.addressof(self._blob) - p = ctypes.cast(addr + offset, PTR) - return BFieldPtr._from_ctypes(p) - # - else: - def getter(self, fname=fname, BField=BField): - return BField._from_ctypes(getattr(self._blob, fname)) - def setter(self, value, fname=fname, BField=BField): - # xxx obscure workaround - value = BField._to_ctypes(value) - oldvalue = getattr(self._blob, fname) - setattr(self._blob, fname, value) - if value != getattr(self._blob, fname): - setattr(self._blob, fname, oldvalue) - raise OverflowError("value too large for bitfield") - setattr(CTypesStructOrUnion, fname, property(getter, setter)) - # - CTypesPtr = self.ffi._get_cached_btype(model.PointerType(tp)) - for fname in fnames: - if hasattr(CTypesPtr, fname): - raise ValueError("the field name %r conflicts in " - "the ctypes backend" % fname) - def getter(self, fname=fname): - return getattr(self[0], fname) - def setter(self, value, fname=fname): - setattr(self[0], fname, value) - setattr(CTypesPtr, fname, property(getter, setter)) - - def new_function_type(self, BArgs, BResult, has_varargs): - nameargs = [BArg._get_c_name() for BArg in BArgs] - if has_varargs: - nameargs.append('...') - nameargs = ', '.join(nameargs) - # - class CTypesFunctionPtr(CTypesGenericPtr): - __slots__ = ['_own_callback', '_name'] - _ctype = ctypes.CFUNCTYPE(getattr(BResult, '_ctype', None), - *[BArg._ctype for BArg in BArgs], - use_errno=True) - _reftypename = BResult._get_c_name('(* &)(%s)' % (nameargs,)) - - def __init__(self, init, error=None): - # create a callback to the Python callable init() - import traceback - assert not has_varargs, "varargs not supported for callbacks" - if getattr(BResult, '_ctype', None) is not None: - error = BResult._from_ctypes( - BResult._create_ctype_obj(error)) - else: - error = None - def callback(*args): - args2 = [] - for arg, BArg in zip(args, BArgs): - args2.append(BArg._from_ctypes(arg)) - try: - res2 = init(*args2) - res2 = BResult._to_ctypes(res2) - except: - traceback.print_exc() - res2 = error - if issubclass(BResult, CTypesGenericPtr): - if res2: - res2 = ctypes.cast(res2, ctypes.c_void_p).value - # .value: http://bugs.python.org/issue1574593 - else: - res2 = None - #print repr(res2) - return res2 - if issubclass(BResult, CTypesGenericPtr): - # The only pointers callbacks can return are void*s: - # http://bugs.python.org/issue5710 - callback_ctype = ctypes.CFUNCTYPE( - ctypes.c_void_p, - *[BArg._ctype for BArg in BArgs], - use_errno=True) - else: - callback_ctype = CTypesFunctionPtr._ctype - self._as_ctype_ptr = callback_ctype(callback) - self._address = ctypes.cast(self._as_ctype_ptr, - ctypes.c_void_p).value - self._own_callback = init - - @staticmethod - def _initialize(ctypes_ptr, value): - if value: - raise NotImplementedError("ctypes backend: not supported: " - "initializers for function pointers") - - def __repr__(self): - c_name = getattr(self, '_name', None) - if c_name: - i = self._reftypename.index('(* &)') - if self._reftypename[i-1] not in ' )*': - c_name = ' ' + c_name - c_name = self._reftypename.replace('(* &)', c_name) - return CTypesData.__repr__(self, c_name) - - def _get_own_repr(self): - if getattr(self, '_own_callback', None) is not None: - return 'calling %r' % (self._own_callback,) - return super(CTypesFunctionPtr, self)._get_own_repr() - - def __call__(self, *args): - if has_varargs: - assert len(args) >= len(BArgs) - extraargs = args[len(BArgs):] - args = args[:len(BArgs)] - else: - assert len(args) == len(BArgs) - ctypes_args = [] - for arg, BArg in zip(args, BArgs): - ctypes_args.append(BArg._arg_to_ctypes(arg)) - if has_varargs: - for i, arg in enumerate(extraargs): - if arg is None: - ctypes_args.append(ctypes.c_void_p(0)) # NULL - continue - if not isinstance(arg, CTypesData): - raise TypeError( - "argument %d passed in the variadic part " - "needs to be a cdata object (got %s)" % - (1 + len(BArgs) + i, type(arg).__name__)) - ctypes_args.append(arg._arg_to_ctypes(arg)) - result = self._as_ctype_ptr(*ctypes_args) - return BResult._from_ctypes(result) - # - CTypesFunctionPtr._fix_class() - return CTypesFunctionPtr - - def new_enum_type(self, name, enumerators, enumvalues, CTypesInt): - assert isinstance(name, str) - reverse_mapping = dict(zip(reversed(enumvalues), - reversed(enumerators))) - # - class CTypesEnum(CTypesInt): - __slots__ = [] - _reftypename = '%s &' % name - - def _get_own_repr(self): - value = self._value - try: - return '%d: %s' % (value, reverse_mapping[value]) - except KeyError: - return str(value) - - def _to_string(self, maxlen): - value = self._value - try: - return reverse_mapping[value] - except KeyError: - return str(value) - # - CTypesEnum._fix_class() - return CTypesEnum - - def get_errno(self): - return ctypes.get_errno() - - def set_errno(self, value): - ctypes.set_errno(value) - - def string(self, b, maxlen=-1): - return b._to_string(maxlen) - - def buffer(self, bptr, size=-1): - raise NotImplementedError("buffer() with ctypes backend") - - def sizeof(self, cdata_or_BType): - if isinstance(cdata_or_BType, CTypesData): - return cdata_or_BType._get_size_of_instance() - else: - assert issubclass(cdata_or_BType, CTypesData) - return cdata_or_BType._get_size() - - def alignof(self, BType): - assert issubclass(BType, CTypesData) - return BType._alignment() - - def newp(self, BType, source): - if not issubclass(BType, CTypesData): - raise TypeError - return BType._newp(source) - - def cast(self, BType, source): - return BType._cast_from(source) - - def callback(self, BType, source, error, onerror): - assert onerror is None # XXX not implemented - return BType(source, error) - - _weakref_cache_ref = None - - def gcp(self, cdata, destructor, size=0): - if self._weakref_cache_ref is None: - import weakref - class MyRef(weakref.ref): - def __eq__(self, other): - myref = self() - return self is other or ( - myref is not None and myref is other()) - def __ne__(self, other): - return not (self == other) - def __hash__(self): - try: - return self._hash - except AttributeError: - self._hash = hash(self()) - return self._hash - self._weakref_cache_ref = {}, MyRef - weak_cache, MyRef = self._weakref_cache_ref - - if destructor is None: - try: - del weak_cache[MyRef(cdata)] - except KeyError: - raise TypeError("Can remove destructor only on a object " - "previously returned by ffi.gc()") - return None - - def remove(k): - cdata, destructor = weak_cache.pop(k, (None, None)) - if destructor is not None: - destructor(cdata) - - new_cdata = self.cast(self.typeof(cdata), cdata) - assert new_cdata is not cdata - weak_cache[MyRef(new_cdata, remove)] = (cdata, destructor) - return new_cdata - - typeof = type - - def getcname(self, BType, replace_with): - return BType._get_c_name(replace_with) - - def typeoffsetof(self, BType, fieldname, num=0): - if isinstance(fieldname, str): - if num == 0 and issubclass(BType, CTypesGenericPtr): - BType = BType._BItem - if not issubclass(BType, CTypesBaseStructOrUnion): - raise TypeError("expected a struct or union ctype") - BField = BType._bfield_types[fieldname] - if BField is Ellipsis: - raise TypeError("not supported for bitfields") - return (BField, BType._offsetof(fieldname)) - elif isinstance(fieldname, (int, long)): - if issubclass(BType, CTypesGenericArray): - BType = BType._CTPtr - if not issubclass(BType, CTypesGenericPtr): - raise TypeError("expected an array or ptr ctype") - BItem = BType._BItem - offset = BItem._get_size() * fieldname - if offset > sys.maxsize: - raise OverflowError - return (BItem, offset) - else: - raise TypeError(type(fieldname)) - - def rawaddressof(self, BTypePtr, cdata, offset=None): - if isinstance(cdata, CTypesBaseStructOrUnion): - ptr = ctypes.pointer(type(cdata)._to_ctypes(cdata)) - elif isinstance(cdata, CTypesGenericPtr): - if offset is None or not issubclass(type(cdata)._BItem, - CTypesBaseStructOrUnion): - raise TypeError("unexpected cdata type") - ptr = type(cdata)._to_ctypes(cdata) - elif isinstance(cdata, CTypesGenericArray): - ptr = type(cdata)._to_ctypes(cdata) - else: - raise TypeError("expected a ") - if offset: - ptr = ctypes.cast( - ctypes.c_void_p( - ctypes.cast(ptr, ctypes.c_void_p).value + offset), - type(ptr)) - return BTypePtr._from_ctypes(ptr) - - -class CTypesLibrary(object): - - def __init__(self, backend, cdll): - self.backend = backend - self.cdll = cdll - - def load_function(self, BType, name): - c_func = getattr(self.cdll, name) - funcobj = BType._from_ctypes(c_func) - funcobj._name = name - return funcobj - - def read_variable(self, BType, name): - try: - ctypes_obj = BType._ctype.in_dll(self.cdll, name) - except AttributeError as e: - raise NotImplementedError(e) - return BType._from_ctypes(ctypes_obj) - - def write_variable(self, BType, name, value): - new_ctypes_obj = BType._to_ctypes(value) - ctypes_obj = BType._ctype.in_dll(self.cdll, name) - ctypes.memmove(ctypes.addressof(ctypes_obj), - ctypes.addressof(new_ctypes_obj), - ctypes.sizeof(BType._ctype)) diff --git a/.venv/lib/python3.12/site-packages/cffi/cffi_opcode.py b/.venv/lib/python3.12/site-packages/cffi/cffi_opcode.py deleted file mode 100644 index 6421df6..0000000 --- a/.venv/lib/python3.12/site-packages/cffi/cffi_opcode.py +++ /dev/null @@ -1,187 +0,0 @@ -from .error import VerificationError - -class CffiOp(object): - def __init__(self, op, arg): - self.op = op - self.arg = arg - - def as_c_expr(self): - if self.op is None: - assert isinstance(self.arg, str) - return '(_cffi_opcode_t)(%s)' % (self.arg,) - classname = CLASS_NAME[self.op] - return '_CFFI_OP(_CFFI_OP_%s, %s)' % (classname, self.arg) - - def as_python_bytes(self): - if self.op is None and self.arg.isdigit(): - value = int(self.arg) # non-negative: '-' not in self.arg - if value >= 2**31: - raise OverflowError("cannot emit %r: limited to 2**31-1" - % (self.arg,)) - return format_four_bytes(value) - if isinstance(self.arg, str): - raise VerificationError("cannot emit to Python: %r" % (self.arg,)) - return format_four_bytes((self.arg << 8) | self.op) - - def __str__(self): - classname = CLASS_NAME.get(self.op, self.op) - return '(%s %s)' % (classname, self.arg) - -def format_four_bytes(num): - return '\\x%02X\\x%02X\\x%02X\\x%02X' % ( - (num >> 24) & 0xFF, - (num >> 16) & 0xFF, - (num >> 8) & 0xFF, - (num ) & 0xFF) - -OP_PRIMITIVE = 1 -OP_POINTER = 3 -OP_ARRAY = 5 -OP_OPEN_ARRAY = 7 -OP_STRUCT_UNION = 9 -OP_ENUM = 11 -OP_FUNCTION = 13 -OP_FUNCTION_END = 15 -OP_NOOP = 17 -OP_BITFIELD = 19 -OP_TYPENAME = 21 -OP_CPYTHON_BLTN_V = 23 # varargs -OP_CPYTHON_BLTN_N = 25 # noargs -OP_CPYTHON_BLTN_O = 27 # O (i.e. a single arg) -OP_CONSTANT = 29 -OP_CONSTANT_INT = 31 -OP_GLOBAL_VAR = 33 -OP_DLOPEN_FUNC = 35 -OP_DLOPEN_CONST = 37 -OP_GLOBAL_VAR_F = 39 -OP_EXTERN_PYTHON = 41 - -PRIM_VOID = 0 -PRIM_BOOL = 1 -PRIM_CHAR = 2 -PRIM_SCHAR = 3 -PRIM_UCHAR = 4 -PRIM_SHORT = 5 -PRIM_USHORT = 6 -PRIM_INT = 7 -PRIM_UINT = 8 -PRIM_LONG = 9 -PRIM_ULONG = 10 -PRIM_LONGLONG = 11 -PRIM_ULONGLONG = 12 -PRIM_FLOAT = 13 -PRIM_DOUBLE = 14 -PRIM_LONGDOUBLE = 15 - -PRIM_WCHAR = 16 -PRIM_INT8 = 17 -PRIM_UINT8 = 18 -PRIM_INT16 = 19 -PRIM_UINT16 = 20 -PRIM_INT32 = 21 -PRIM_UINT32 = 22 -PRIM_INT64 = 23 -PRIM_UINT64 = 24 -PRIM_INTPTR = 25 -PRIM_UINTPTR = 26 -PRIM_PTRDIFF = 27 -PRIM_SIZE = 28 -PRIM_SSIZE = 29 -PRIM_INT_LEAST8 = 30 -PRIM_UINT_LEAST8 = 31 -PRIM_INT_LEAST16 = 32 -PRIM_UINT_LEAST16 = 33 -PRIM_INT_LEAST32 = 34 -PRIM_UINT_LEAST32 = 35 -PRIM_INT_LEAST64 = 36 -PRIM_UINT_LEAST64 = 37 -PRIM_INT_FAST8 = 38 -PRIM_UINT_FAST8 = 39 -PRIM_INT_FAST16 = 40 -PRIM_UINT_FAST16 = 41 -PRIM_INT_FAST32 = 42 -PRIM_UINT_FAST32 = 43 -PRIM_INT_FAST64 = 44 -PRIM_UINT_FAST64 = 45 -PRIM_INTMAX = 46 -PRIM_UINTMAX = 47 -PRIM_FLOATCOMPLEX = 48 -PRIM_DOUBLECOMPLEX = 49 -PRIM_CHAR16 = 50 -PRIM_CHAR32 = 51 - -_NUM_PRIM = 52 -_UNKNOWN_PRIM = -1 -_UNKNOWN_FLOAT_PRIM = -2 -_UNKNOWN_LONG_DOUBLE = -3 - -_IO_FILE_STRUCT = -1 - -PRIMITIVE_TO_INDEX = { - 'char': PRIM_CHAR, - 'short': PRIM_SHORT, - 'int': PRIM_INT, - 'long': PRIM_LONG, - 'long long': PRIM_LONGLONG, - 'signed char': PRIM_SCHAR, - 'unsigned char': PRIM_UCHAR, - 'unsigned short': PRIM_USHORT, - 'unsigned int': PRIM_UINT, - 'unsigned long': PRIM_ULONG, - 'unsigned long long': PRIM_ULONGLONG, - 'float': PRIM_FLOAT, - 'double': PRIM_DOUBLE, - 'long double': PRIM_LONGDOUBLE, - '_cffi_float_complex_t': PRIM_FLOATCOMPLEX, - '_cffi_double_complex_t': PRIM_DOUBLECOMPLEX, - '_Bool': PRIM_BOOL, - 'wchar_t': PRIM_WCHAR, - 'char16_t': PRIM_CHAR16, - 'char32_t': PRIM_CHAR32, - 'int8_t': PRIM_INT8, - 'uint8_t': PRIM_UINT8, - 'int16_t': PRIM_INT16, - 'uint16_t': PRIM_UINT16, - 'int32_t': PRIM_INT32, - 'uint32_t': PRIM_UINT32, - 'int64_t': PRIM_INT64, - 'uint64_t': PRIM_UINT64, - 'intptr_t': PRIM_INTPTR, - 'uintptr_t': PRIM_UINTPTR, - 'ptrdiff_t': PRIM_PTRDIFF, - 'size_t': PRIM_SIZE, - 'ssize_t': PRIM_SSIZE, - 'int_least8_t': PRIM_INT_LEAST8, - 'uint_least8_t': PRIM_UINT_LEAST8, - 'int_least16_t': PRIM_INT_LEAST16, - 'uint_least16_t': PRIM_UINT_LEAST16, - 'int_least32_t': PRIM_INT_LEAST32, - 'uint_least32_t': PRIM_UINT_LEAST32, - 'int_least64_t': PRIM_INT_LEAST64, - 'uint_least64_t': PRIM_UINT_LEAST64, - 'int_fast8_t': PRIM_INT_FAST8, - 'uint_fast8_t': PRIM_UINT_FAST8, - 'int_fast16_t': PRIM_INT_FAST16, - 'uint_fast16_t': PRIM_UINT_FAST16, - 'int_fast32_t': PRIM_INT_FAST32, - 'uint_fast32_t': PRIM_UINT_FAST32, - 'int_fast64_t': PRIM_INT_FAST64, - 'uint_fast64_t': PRIM_UINT_FAST64, - 'intmax_t': PRIM_INTMAX, - 'uintmax_t': PRIM_UINTMAX, - } - -F_UNION = 0x01 -F_CHECK_FIELDS = 0x02 -F_PACKED = 0x04 -F_EXTERNAL = 0x08 -F_OPAQUE = 0x10 - -G_FLAGS = dict([('_CFFI_' + _key, globals()[_key]) - for _key in ['F_UNION', 'F_CHECK_FIELDS', 'F_PACKED', - 'F_EXTERNAL', 'F_OPAQUE']]) - -CLASS_NAME = {} -for _name, _value in list(globals().items()): - if _name.startswith('OP_') and isinstance(_value, int): - CLASS_NAME[_value] = _name[3:] diff --git a/.venv/lib/python3.12/site-packages/cffi/commontypes.py b/.venv/lib/python3.12/site-packages/cffi/commontypes.py deleted file mode 100644 index d4dae35..0000000 --- a/.venv/lib/python3.12/site-packages/cffi/commontypes.py +++ /dev/null @@ -1,82 +0,0 @@ -import sys -from . import model -from .error import FFIError - - -COMMON_TYPES = {} - -try: - # fetch "bool" and all simple Windows types - from _cffi_backend import _get_common_types - _get_common_types(COMMON_TYPES) -except ImportError: - pass - -COMMON_TYPES['FILE'] = model.unknown_type('FILE', '_IO_FILE') -COMMON_TYPES['bool'] = '_Bool' # in case we got ImportError above -COMMON_TYPES['float _Complex'] = '_cffi_float_complex_t' -COMMON_TYPES['double _Complex'] = '_cffi_double_complex_t' - -for _type in model.PrimitiveType.ALL_PRIMITIVE_TYPES: - if _type.endswith('_t'): - COMMON_TYPES[_type] = _type -del _type - -_CACHE = {} - -def resolve_common_type(parser, commontype): - try: - return _CACHE[commontype] - except KeyError: - cdecl = COMMON_TYPES.get(commontype, commontype) - if not isinstance(cdecl, str): - result, quals = cdecl, 0 # cdecl is already a BaseType - elif cdecl in model.PrimitiveType.ALL_PRIMITIVE_TYPES: - result, quals = model.PrimitiveType(cdecl), 0 - elif cdecl == 'set-unicode-needed': - raise FFIError("The Windows type %r is only available after " - "you call ffi.set_unicode()" % (commontype,)) - else: - if commontype == cdecl: - raise FFIError( - "Unsupported type: %r. Please look at " - "http://cffi.readthedocs.io/en/latest/cdef.html#ffi-cdef-limitations " - "and file an issue if you think this type should really " - "be supported." % (commontype,)) - result, quals = parser.parse_type_and_quals(cdecl) # recursive - - assert isinstance(result, model.BaseTypeByIdentity) - _CACHE[commontype] = result, quals - return result, quals - - -# ____________________________________________________________ -# extra types for Windows (most of them are in commontypes.c) - - -def win_common_types(): - return { - "UNICODE_STRING": model.StructType( - "_UNICODE_STRING", - ["Length", - "MaximumLength", - "Buffer"], - [model.PrimitiveType("unsigned short"), - model.PrimitiveType("unsigned short"), - model.PointerType(model.PrimitiveType("wchar_t"))], - [-1, -1, -1]), - "PUNICODE_STRING": "UNICODE_STRING *", - "PCUNICODE_STRING": "const UNICODE_STRING *", - - "TBYTE": "set-unicode-needed", - "TCHAR": "set-unicode-needed", - "LPCTSTR": "set-unicode-needed", - "PCTSTR": "set-unicode-needed", - "LPTSTR": "set-unicode-needed", - "PTSTR": "set-unicode-needed", - "PTBYTE": "set-unicode-needed", - "PTCHAR": "set-unicode-needed", - } - -if sys.platform == 'win32': - COMMON_TYPES.update(win_common_types()) diff --git a/.venv/lib/python3.12/site-packages/cffi/cparser.py b/.venv/lib/python3.12/site-packages/cffi/cparser.py deleted file mode 100644 index dd590d8..0000000 --- a/.venv/lib/python3.12/site-packages/cffi/cparser.py +++ /dev/null @@ -1,1015 +0,0 @@ -from . import model -from .commontypes import COMMON_TYPES, resolve_common_type -from .error import FFIError, CDefError -try: - from . import _pycparser as pycparser -except ImportError: - import pycparser -import weakref, re, sys - -try: - if sys.version_info < (3,): - import thread as _thread - else: - import _thread - lock = _thread.allocate_lock() -except ImportError: - lock = None - -def _workaround_for_static_import_finders(): - # Issue #392: packaging tools like cx_Freeze can not find these - # because pycparser uses exec dynamic import. This is an obscure - # workaround. This function is never called. - import pycparser.yacctab - import pycparser.lextab - -CDEF_SOURCE_STRING = "" -_r_comment = re.compile(r"/\*.*?\*/|//([^\n\\]|\\.)*?$", - re.DOTALL | re.MULTILINE) -_r_define = re.compile(r"^\s*#\s*define\s+([A-Za-z_][A-Za-z_0-9]*)" - r"\b((?:[^\n\\]|\\.)*?)$", - re.DOTALL | re.MULTILINE) -_r_line_directive = re.compile(r"^[ \t]*#[ \t]*(?:line|\d+)\b.*$", re.MULTILINE) -_r_partial_enum = re.compile(r"=\s*\.\.\.\s*[,}]|\.\.\.\s*\}") -_r_enum_dotdotdot = re.compile(r"__dotdotdot\d+__$") -_r_partial_array = re.compile(r"\[\s*\.\.\.\s*\]") -_r_words = re.compile(r"\w+|\S") -_parser_cache = None -_r_int_literal = re.compile(r"-?0?x?[0-9a-f]+[lu]*$", re.IGNORECASE) -_r_stdcall1 = re.compile(r"\b(__stdcall|WINAPI)\b") -_r_stdcall2 = re.compile(r"[(]\s*(__stdcall|WINAPI)\b") -_r_cdecl = re.compile(r"\b__cdecl\b") -_r_extern_python = re.compile(r'\bextern\s*"' - r'(Python|Python\s*\+\s*C|C\s*\+\s*Python)"\s*.') -_r_star_const_space = re.compile( # matches "* const " - r"[*]\s*((const|volatile|restrict)\b\s*)+") -_r_int_dotdotdot = re.compile(r"(\b(int|long|short|signed|unsigned|char)\s*)+" - r"\.\.\.") -_r_float_dotdotdot = re.compile(r"\b(double|float)\s*\.\.\.") - -def _get_parser(): - global _parser_cache - if _parser_cache is None: - _parser_cache = pycparser.CParser() - return _parser_cache - -def _workaround_for_old_pycparser(csource): - # Workaround for a pycparser issue (fixed between pycparser 2.10 and - # 2.14): "char*const***" gives us a wrong syntax tree, the same as - # for "char***(*const)". This means we can't tell the difference - # afterwards. But "char(*const(***))" gives us the right syntax - # tree. The issue only occurs if there are several stars in - # sequence with no parenthesis in between, just possibly qualifiers. - # Attempt to fix it by adding some parentheses in the source: each - # time we see "* const" or "* const *", we add an opening - # parenthesis before each star---the hard part is figuring out where - # to close them. - parts = [] - while True: - match = _r_star_const_space.search(csource) - if not match: - break - #print repr(''.join(parts)+csource), '=>', - parts.append(csource[:match.start()]) - parts.append('('); closing = ')' - parts.append(match.group()) # e.g. "* const " - endpos = match.end() - if csource.startswith('*', endpos): - parts.append('('); closing += ')' - level = 0 - i = endpos - while i < len(csource): - c = csource[i] - if c == '(': - level += 1 - elif c == ')': - if level == 0: - break - level -= 1 - elif c in ',;=': - if level == 0: - break - i += 1 - csource = csource[endpos:i] + closing + csource[i:] - #print repr(''.join(parts)+csource) - parts.append(csource) - return ''.join(parts) - -def _preprocess_extern_python(csource): - # input: `extern "Python" int foo(int);` or - # `extern "Python" { int foo(int); }` - # output: - # void __cffi_extern_python_start; - # int foo(int); - # void __cffi_extern_python_stop; - # - # input: `extern "Python+C" int foo(int);` - # output: - # void __cffi_extern_python_plus_c_start; - # int foo(int); - # void __cffi_extern_python_stop; - parts = [] - while True: - match = _r_extern_python.search(csource) - if not match: - break - endpos = match.end() - 1 - #print - #print ''.join(parts)+csource - #print '=>' - parts.append(csource[:match.start()]) - if 'C' in match.group(1): - parts.append('void __cffi_extern_python_plus_c_start; ') - else: - parts.append('void __cffi_extern_python_start; ') - if csource[endpos] == '{': - # grouping variant - closing = csource.find('}', endpos) - if closing < 0: - raise CDefError("'extern \"Python\" {': no '}' found") - if csource.find('{', endpos + 1, closing) >= 0: - raise NotImplementedError("cannot use { } inside a block " - "'extern \"Python\" { ... }'") - parts.append(csource[endpos+1:closing]) - csource = csource[closing+1:] - else: - # non-grouping variant - semicolon = csource.find(';', endpos) - if semicolon < 0: - raise CDefError("'extern \"Python\": no ';' found") - parts.append(csource[endpos:semicolon+1]) - csource = csource[semicolon+1:] - parts.append(' void __cffi_extern_python_stop;') - #print ''.join(parts)+csource - #print - parts.append(csource) - return ''.join(parts) - -def _warn_for_string_literal(csource): - if '"' not in csource: - return - for line in csource.splitlines(): - if '"' in line and not line.lstrip().startswith('#'): - import warnings - warnings.warn("String literal found in cdef() or type source. " - "String literals are ignored here, but you should " - "remove them anyway because some character sequences " - "confuse pre-parsing.") - break - -def _warn_for_non_extern_non_static_global_variable(decl): - if not decl.storage: - import warnings - warnings.warn("Global variable '%s' in cdef(): for consistency " - "with C it should have a storage class specifier " - "(usually 'extern')" % (decl.name,)) - -def _remove_line_directives(csource): - # _r_line_directive matches whole lines, without the final \n, if they - # start with '#line' with some spacing allowed, or '#NUMBER'. This - # function stores them away and replaces them with exactly the string - # '#line@N', where N is the index in the list 'line_directives'. - line_directives = [] - def replace(m): - i = len(line_directives) - line_directives.append(m.group()) - return '#line@%d' % i - csource = _r_line_directive.sub(replace, csource) - return csource, line_directives - -def _put_back_line_directives(csource, line_directives): - def replace(m): - s = m.group() - if not s.startswith('#line@'): - raise AssertionError("unexpected #line directive " - "(should have been processed and removed") - return line_directives[int(s[6:])] - return _r_line_directive.sub(replace, csource) - -def _preprocess(csource): - # First, remove the lines of the form '#line N "filename"' because - # the "filename" part could confuse the rest - csource, line_directives = _remove_line_directives(csource) - # Remove comments. NOTE: this only work because the cdef() section - # should not contain any string literals (except in line directives)! - def replace_keeping_newlines(m): - return ' ' + m.group().count('\n') * '\n' - csource = _r_comment.sub(replace_keeping_newlines, csource) - # Remove the "#define FOO x" lines - macros = {} - for match in _r_define.finditer(csource): - macroname, macrovalue = match.groups() - macrovalue = macrovalue.replace('\\\n', '').strip() - macros[macroname] = macrovalue - csource = _r_define.sub('', csource) - # - if pycparser.__version__ < '2.14': - csource = _workaround_for_old_pycparser(csource) - # - # BIG HACK: replace WINAPI or __stdcall with "volatile const". - # It doesn't make sense for the return type of a function to be - # "volatile volatile const", so we abuse it to detect __stdcall... - # Hack number 2 is that "int(volatile *fptr)();" is not valid C - # syntax, so we place the "volatile" before the opening parenthesis. - csource = _r_stdcall2.sub(' volatile volatile const(', csource) - csource = _r_stdcall1.sub(' volatile volatile const ', csource) - csource = _r_cdecl.sub(' ', csource) - # - # Replace `extern "Python"` with start/end markers - csource = _preprocess_extern_python(csource) - # - # Now there should not be any string literal left; warn if we get one - _warn_for_string_literal(csource) - # - # Replace "[...]" with "[__dotdotdotarray__]" - csource = _r_partial_array.sub('[__dotdotdotarray__]', csource) - # - # Replace "...}" with "__dotdotdotNUM__}". This construction should - # occur only at the end of enums; at the end of structs we have "...;}" - # and at the end of vararg functions "...);". Also replace "=...[,}]" - # with ",__dotdotdotNUM__[,}]": this occurs in the enums too, when - # giving an unknown value. - matches = list(_r_partial_enum.finditer(csource)) - for number, match in enumerate(reversed(matches)): - p = match.start() - if csource[p] == '=': - p2 = csource.find('...', p, match.end()) - assert p2 > p - csource = '%s,__dotdotdot%d__ %s' % (csource[:p], number, - csource[p2+3:]) - else: - assert csource[p:p+3] == '...' - csource = '%s __dotdotdot%d__ %s' % (csource[:p], number, - csource[p+3:]) - # Replace "int ..." or "unsigned long int..." with "__dotdotdotint__" - csource = _r_int_dotdotdot.sub(' __dotdotdotint__ ', csource) - # Replace "float ..." or "double..." with "__dotdotdotfloat__" - csource = _r_float_dotdotdot.sub(' __dotdotdotfloat__ ', csource) - # Replace all remaining "..." with the same name, "__dotdotdot__", - # which is declared with a typedef for the purpose of C parsing. - csource = csource.replace('...', ' __dotdotdot__ ') - # Finally, put back the line directives - csource = _put_back_line_directives(csource, line_directives) - return csource, macros - -def _common_type_names(csource): - # Look in the source for what looks like usages of types from the - # list of common types. A "usage" is approximated here as the - # appearance of the word, minus a "definition" of the type, which - # is the last word in a "typedef" statement. Approximative only - # but should be fine for all the common types. - look_for_words = set(COMMON_TYPES) - look_for_words.add(';') - look_for_words.add(',') - look_for_words.add('(') - look_for_words.add(')') - look_for_words.add('typedef') - words_used = set() - is_typedef = False - paren = 0 - previous_word = '' - for word in _r_words.findall(csource): - if word in look_for_words: - if word == ';': - if is_typedef: - words_used.discard(previous_word) - look_for_words.discard(previous_word) - is_typedef = False - elif word == 'typedef': - is_typedef = True - paren = 0 - elif word == '(': - paren += 1 - elif word == ')': - paren -= 1 - elif word == ',': - if is_typedef and paren == 0: - words_used.discard(previous_word) - look_for_words.discard(previous_word) - else: # word in COMMON_TYPES - words_used.add(word) - previous_word = word - return words_used - - -class Parser(object): - - def __init__(self): - self._declarations = {} - self._included_declarations = set() - self._anonymous_counter = 0 - self._structnode2type = weakref.WeakKeyDictionary() - self._options = {} - self._int_constants = {} - self._recomplete = [] - self._uses_new_feature = None - - def _parse(self, csource): - csource, macros = _preprocess(csource) - # XXX: for more efficiency we would need to poke into the - # internals of CParser... the following registers the - # typedefs, because their presence or absence influences the - # parsing itself (but what they are typedef'ed to plays no role) - ctn = _common_type_names(csource) - typenames = [] - for name in sorted(self._declarations): - if name.startswith('typedef '): - name = name[8:] - typenames.append(name) - ctn.discard(name) - typenames += sorted(ctn) - # - csourcelines = [] - csourcelines.append('# 1 ""') - for typename in typenames: - csourcelines.append('typedef int %s;' % typename) - csourcelines.append('typedef int __dotdotdotint__, __dotdotdotfloat__,' - ' __dotdotdot__;') - # this forces pycparser to consider the following in the file - # called from line 1 - csourcelines.append('# 1 "%s"' % (CDEF_SOURCE_STRING,)) - csourcelines.append(csource) - csourcelines.append('') # see test_missing_newline_bug - fullcsource = '\n'.join(csourcelines) - if lock is not None: - lock.acquire() # pycparser is not thread-safe... - try: - ast = _get_parser().parse(fullcsource) - except pycparser.c_parser.ParseError as e: - self.convert_pycparser_error(e, csource) - finally: - if lock is not None: - lock.release() - # csource will be used to find buggy source text - return ast, macros, csource - - def _convert_pycparser_error(self, e, csource): - # xxx look for ":NUM:" at the start of str(e) - # and interpret that as a line number. This will not work if - # the user gives explicit ``# NUM "FILE"`` directives. - line = None - msg = str(e) - match = re.match(r"%s:(\d+):" % (CDEF_SOURCE_STRING,), msg) - if match: - linenum = int(match.group(1), 10) - csourcelines = csource.splitlines() - if 1 <= linenum <= len(csourcelines): - line = csourcelines[linenum-1] - return line - - def convert_pycparser_error(self, e, csource): - line = self._convert_pycparser_error(e, csource) - - msg = str(e) - if line: - msg = 'cannot parse "%s"\n%s' % (line.strip(), msg) - else: - msg = 'parse error\n%s' % (msg,) - raise CDefError(msg) - - def parse(self, csource, override=False, packed=False, pack=None, - dllexport=False): - if packed: - if packed != True: - raise ValueError("'packed' should be False or True; use " - "'pack' to give another value") - if pack: - raise ValueError("cannot give both 'pack' and 'packed'") - pack = 1 - elif pack: - if pack & (pack - 1): - raise ValueError("'pack' must be a power of two, not %r" % - (pack,)) - else: - pack = 0 - prev_options = self._options - try: - self._options = {'override': override, - 'packed': pack, - 'dllexport': dllexport} - self._internal_parse(csource) - finally: - self._options = prev_options - - def _internal_parse(self, csource): - ast, macros, csource = self._parse(csource) - # add the macros - self._process_macros(macros) - # find the first "__dotdotdot__" and use that as a separator - # between the repeated typedefs and the real csource - iterator = iter(ast.ext) - for decl in iterator: - if decl.name == '__dotdotdot__': - break - else: - assert 0 - current_decl = None - # - try: - self._inside_extern_python = '__cffi_extern_python_stop' - for decl in iterator: - current_decl = decl - if isinstance(decl, pycparser.c_ast.Decl): - self._parse_decl(decl) - elif isinstance(decl, pycparser.c_ast.Typedef): - if not decl.name: - raise CDefError("typedef does not declare any name", - decl) - quals = 0 - if (isinstance(decl.type.type, pycparser.c_ast.IdentifierType) and - decl.type.type.names[-1].startswith('__dotdotdot')): - realtype = self._get_unknown_type(decl) - elif (isinstance(decl.type, pycparser.c_ast.PtrDecl) and - isinstance(decl.type.type, pycparser.c_ast.TypeDecl) and - isinstance(decl.type.type.type, - pycparser.c_ast.IdentifierType) and - decl.type.type.type.names[-1].startswith('__dotdotdot')): - realtype = self._get_unknown_ptr_type(decl) - else: - realtype, quals = self._get_type_and_quals( - decl.type, name=decl.name, partial_length_ok=True, - typedef_example="*(%s *)0" % (decl.name,)) - self._declare('typedef ' + decl.name, realtype, quals=quals) - elif decl.__class__.__name__ == 'Pragma': - # skip pragma, only in pycparser 2.15 - import warnings - warnings.warn( - "#pragma in cdef() are entirely ignored. " - "They should be removed for now, otherwise your " - "code might behave differently in a future version " - "of CFFI if #pragma support gets added. Note that " - "'#pragma pack' needs to be replaced with the " - "'packed' keyword argument to cdef().") - else: - raise CDefError("unexpected <%s>: this construct is valid " - "C but not valid in cdef()" % - decl.__class__.__name__, decl) - except CDefError as e: - if len(e.args) == 1: - e.args = e.args + (current_decl,) - raise - except FFIError as e: - msg = self._convert_pycparser_error(e, csource) - if msg: - e.args = (e.args[0] + "\n *** Err: %s" % msg,) - raise - - def _add_constants(self, key, val): - if key in self._int_constants: - if self._int_constants[key] == val: - return # ignore identical double declarations - raise FFIError( - "multiple declarations of constant: %s" % (key,)) - self._int_constants[key] = val - - def _add_integer_constant(self, name, int_str): - int_str = int_str.lower().rstrip("ul") - neg = int_str.startswith('-') - if neg: - int_str = int_str[1:] - # "010" is not valid oct in py3 - if (int_str.startswith("0") and int_str != '0' - and not int_str.startswith("0x")): - int_str = "0o" + int_str[1:] - pyvalue = int(int_str, 0) - if neg: - pyvalue = -pyvalue - self._add_constants(name, pyvalue) - self._declare('macro ' + name, pyvalue) - - def _process_macros(self, macros): - for key, value in macros.items(): - value = value.strip() - if _r_int_literal.match(value): - self._add_integer_constant(key, value) - elif value == '...': - self._declare('macro ' + key, value) - else: - raise CDefError( - 'only supports one of the following syntax:\n' - ' #define %s ... (literally dot-dot-dot)\n' - ' #define %s NUMBER (with NUMBER an integer' - ' constant, decimal/hex/octal)\n' - 'got:\n' - ' #define %s %s' - % (key, key, key, value)) - - def _declare_function(self, tp, quals, decl): - tp = self._get_type_pointer(tp, quals) - if self._options.get('dllexport'): - tag = 'dllexport_python ' - elif self._inside_extern_python == '__cffi_extern_python_start': - tag = 'extern_python ' - elif self._inside_extern_python == '__cffi_extern_python_plus_c_start': - tag = 'extern_python_plus_c ' - else: - tag = 'function ' - self._declare(tag + decl.name, tp) - - def _parse_decl(self, decl): - node = decl.type - if isinstance(node, pycparser.c_ast.FuncDecl): - tp, quals = self._get_type_and_quals(node, name=decl.name) - assert isinstance(tp, model.RawFunctionType) - self._declare_function(tp, quals, decl) - else: - if isinstance(node, pycparser.c_ast.Struct): - self._get_struct_union_enum_type('struct', node) - elif isinstance(node, pycparser.c_ast.Union): - self._get_struct_union_enum_type('union', node) - elif isinstance(node, pycparser.c_ast.Enum): - self._get_struct_union_enum_type('enum', node) - elif not decl.name: - raise CDefError("construct does not declare any variable", - decl) - # - if decl.name: - tp, quals = self._get_type_and_quals(node, - partial_length_ok=True) - if tp.is_raw_function: - self._declare_function(tp, quals, decl) - elif (tp.is_integer_type() and - hasattr(decl, 'init') and - hasattr(decl.init, 'value') and - _r_int_literal.match(decl.init.value)): - self._add_integer_constant(decl.name, decl.init.value) - elif (tp.is_integer_type() and - isinstance(decl.init, pycparser.c_ast.UnaryOp) and - decl.init.op == '-' and - hasattr(decl.init.expr, 'value') and - _r_int_literal.match(decl.init.expr.value)): - self._add_integer_constant(decl.name, - '-' + decl.init.expr.value) - elif (tp is model.void_type and - decl.name.startswith('__cffi_extern_python_')): - # hack: `extern "Python"` in the C source is replaced - # with "void __cffi_extern_python_start;" and - # "void __cffi_extern_python_stop;" - self._inside_extern_python = decl.name - else: - if self._inside_extern_python !='__cffi_extern_python_stop': - raise CDefError( - "cannot declare constants or " - "variables with 'extern \"Python\"'") - if (quals & model.Q_CONST) and not tp.is_array_type: - self._declare('constant ' + decl.name, tp, quals=quals) - else: - _warn_for_non_extern_non_static_global_variable(decl) - self._declare('variable ' + decl.name, tp, quals=quals) - - def parse_type(self, cdecl): - return self.parse_type_and_quals(cdecl)[0] - - def parse_type_and_quals(self, cdecl): - ast, macros = self._parse('void __dummy(\n%s\n);' % cdecl)[:2] - assert not macros - exprnode = ast.ext[-1].type.args.params[0] - if isinstance(exprnode, pycparser.c_ast.ID): - raise CDefError("unknown identifier '%s'" % (exprnode.name,)) - return self._get_type_and_quals(exprnode.type) - - def _declare(self, name, obj, included=False, quals=0): - if name in self._declarations: - prevobj, prevquals = self._declarations[name] - if prevobj is obj and prevquals == quals: - return - if not self._options.get('override'): - raise FFIError( - "multiple declarations of %s (for interactive usage, " - "try cdef(xx, override=True))" % (name,)) - assert '__dotdotdot__' not in name.split() - self._declarations[name] = (obj, quals) - if included: - self._included_declarations.add(obj) - - def _extract_quals(self, type): - quals = 0 - if isinstance(type, (pycparser.c_ast.TypeDecl, - pycparser.c_ast.PtrDecl)): - if 'const' in type.quals: - quals |= model.Q_CONST - if 'volatile' in type.quals: - quals |= model.Q_VOLATILE - if 'restrict' in type.quals: - quals |= model.Q_RESTRICT - return quals - - def _get_type_pointer(self, type, quals, declname=None): - if isinstance(type, model.RawFunctionType): - return type.as_function_pointer() - if (isinstance(type, model.StructOrUnionOrEnum) and - type.name.startswith('$') and type.name[1:].isdigit() and - type.forcename is None and declname is not None): - return model.NamedPointerType(type, declname, quals) - return model.PointerType(type, quals) - - def _get_type_and_quals(self, typenode, name=None, partial_length_ok=False, - typedef_example=None): - # first, dereference typedefs, if we have it already parsed, we're good - if (isinstance(typenode, pycparser.c_ast.TypeDecl) and - isinstance(typenode.type, pycparser.c_ast.IdentifierType) and - len(typenode.type.names) == 1 and - ('typedef ' + typenode.type.names[0]) in self._declarations): - tp, quals = self._declarations['typedef ' + typenode.type.names[0]] - quals |= self._extract_quals(typenode) - return tp, quals - # - if isinstance(typenode, pycparser.c_ast.ArrayDecl): - # array type - if typenode.dim is None: - length = None - else: - length = self._parse_constant( - typenode.dim, partial_length_ok=partial_length_ok) - # a hack: in 'typedef int foo_t[...][...];', don't use '...' as - # the length but use directly the C expression that would be - # generated by recompiler.py. This lets the typedef be used in - # many more places within recompiler.py - if typedef_example is not None: - if length == '...': - length = '_cffi_array_len(%s)' % (typedef_example,) - typedef_example = "*" + typedef_example - # - tp, quals = self._get_type_and_quals(typenode.type, - partial_length_ok=partial_length_ok, - typedef_example=typedef_example) - return model.ArrayType(tp, length), quals - # - if isinstance(typenode, pycparser.c_ast.PtrDecl): - # pointer type - itemtype, itemquals = self._get_type_and_quals(typenode.type) - tp = self._get_type_pointer(itemtype, itemquals, declname=name) - quals = self._extract_quals(typenode) - return tp, quals - # - if isinstance(typenode, pycparser.c_ast.TypeDecl): - quals = self._extract_quals(typenode) - type = typenode.type - if isinstance(type, pycparser.c_ast.IdentifierType): - # assume a primitive type. get it from .names, but reduce - # synonyms to a single chosen combination - names = list(type.names) - if names != ['signed', 'char']: # keep this unmodified - prefixes = {} - while names: - name = names[0] - if name in ('short', 'long', 'signed', 'unsigned'): - prefixes[name] = prefixes.get(name, 0) + 1 - del names[0] - else: - break - # ignore the 'signed' prefix below, and reorder the others - newnames = [] - for prefix in ('unsigned', 'short', 'long'): - for i in range(prefixes.get(prefix, 0)): - newnames.append(prefix) - if not names: - names = ['int'] # implicitly - if names == ['int']: # but kill it if 'short' or 'long' - if 'short' in prefixes or 'long' in prefixes: - names = [] - names = newnames + names - ident = ' '.join(names) - if ident == 'void': - return model.void_type, quals - if ident == '__dotdotdot__': - raise FFIError(':%d: bad usage of "..."' % - typenode.coord.line) - tp0, quals0 = resolve_common_type(self, ident) - return tp0, (quals | quals0) - # - if isinstance(type, pycparser.c_ast.Struct): - # 'struct foobar' - tp = self._get_struct_union_enum_type('struct', type, name) - return tp, quals - # - if isinstance(type, pycparser.c_ast.Union): - # 'union foobar' - tp = self._get_struct_union_enum_type('union', type, name) - return tp, quals - # - if isinstance(type, pycparser.c_ast.Enum): - # 'enum foobar' - tp = self._get_struct_union_enum_type('enum', type, name) - return tp, quals - # - if isinstance(typenode, pycparser.c_ast.FuncDecl): - # a function type - return self._parse_function_type(typenode, name), 0 - # - # nested anonymous structs or unions end up here - if isinstance(typenode, pycparser.c_ast.Struct): - return self._get_struct_union_enum_type('struct', typenode, name, - nested=True), 0 - if isinstance(typenode, pycparser.c_ast.Union): - return self._get_struct_union_enum_type('union', typenode, name, - nested=True), 0 - # - raise FFIError(":%d: bad or unsupported type declaration" % - typenode.coord.line) - - def _parse_function_type(self, typenode, funcname=None): - params = list(getattr(typenode.args, 'params', [])) - for i, arg in enumerate(params): - if not hasattr(arg, 'type'): - raise CDefError("%s arg %d: unknown type '%s'" - " (if you meant to use the old C syntax of giving" - " untyped arguments, it is not supported)" - % (funcname or 'in expression', i + 1, - getattr(arg, 'name', '?'))) - ellipsis = ( - len(params) > 0 and - isinstance(params[-1].type, pycparser.c_ast.TypeDecl) and - isinstance(params[-1].type.type, - pycparser.c_ast.IdentifierType) and - params[-1].type.type.names == ['__dotdotdot__']) - if ellipsis: - params.pop() - if not params: - raise CDefError( - "%s: a function with only '(...)' as argument" - " is not correct C" % (funcname or 'in expression')) - args = [self._as_func_arg(*self._get_type_and_quals(argdeclnode.type)) - for argdeclnode in params] - if not ellipsis and args == [model.void_type]: - args = [] - result, quals = self._get_type_and_quals(typenode.type) - # the 'quals' on the result type are ignored. HACK: we absure them - # to detect __stdcall functions: we textually replace "__stdcall" - # with "volatile volatile const" above. - abi = None - if hasattr(typenode.type, 'quals'): # else, probable syntax error anyway - if typenode.type.quals[-3:] == ['volatile', 'volatile', 'const']: - abi = '__stdcall' - return model.RawFunctionType(tuple(args), result, ellipsis, abi) - - def _as_func_arg(self, type, quals): - if isinstance(type, model.ArrayType): - return model.PointerType(type.item, quals) - elif isinstance(type, model.RawFunctionType): - return type.as_function_pointer() - else: - return type - - def _get_struct_union_enum_type(self, kind, type, name=None, nested=False): - # First, a level of caching on the exact 'type' node of the AST. - # This is obscure, but needed because pycparser "unrolls" declarations - # such as "typedef struct { } foo_t, *foo_p" and we end up with - # an AST that is not a tree, but a DAG, with the "type" node of the - # two branches foo_t and foo_p of the trees being the same node. - # It's a bit silly but detecting "DAG-ness" in the AST tree seems - # to be the only way to distinguish this case from two independent - # structs. See test_struct_with_two_usages. - try: - return self._structnode2type[type] - except KeyError: - pass - # - # Note that this must handle parsing "struct foo" any number of - # times and always return the same StructType object. Additionally, - # one of these times (not necessarily the first), the fields of - # the struct can be specified with "struct foo { ...fields... }". - # If no name is given, then we have to create a new anonymous struct - # with no caching; in this case, the fields are either specified - # right now or never. - # - force_name = name - name = type.name - # - # get the type or create it if needed - if name is None: - # 'force_name' is used to guess a more readable name for - # anonymous structs, for the common case "typedef struct { } foo". - if force_name is not None: - explicit_name = '$%s' % force_name - else: - self._anonymous_counter += 1 - explicit_name = '$%d' % self._anonymous_counter - tp = None - else: - explicit_name = name - key = '%s %s' % (kind, name) - tp, _ = self._declarations.get(key, (None, None)) - # - if tp is None: - if kind == 'struct': - tp = model.StructType(explicit_name, None, None, None) - elif kind == 'union': - tp = model.UnionType(explicit_name, None, None, None) - elif kind == 'enum': - if explicit_name == '__dotdotdot__': - raise CDefError("Enums cannot be declared with ...") - tp = self._build_enum_type(explicit_name, type.values) - else: - raise AssertionError("kind = %r" % (kind,)) - if name is not None: - self._declare(key, tp) - else: - if kind == 'enum' and type.values is not None: - raise NotImplementedError( - "enum %s: the '{}' declaration should appear on the first " - "time the enum is mentioned, not later" % explicit_name) - if not tp.forcename: - tp.force_the_name(force_name) - if tp.forcename and '$' in tp.name: - self._declare('anonymous %s' % tp.forcename, tp) - # - self._structnode2type[type] = tp - # - # enums: done here - if kind == 'enum': - return tp - # - # is there a 'type.decls'? If yes, then this is the place in the - # C sources that declare the fields. If no, then just return the - # existing type, possibly still incomplete. - if type.decls is None: - return tp - # - if tp.fldnames is not None: - raise CDefError("duplicate declaration of struct %s" % name) - fldnames = [] - fldtypes = [] - fldbitsize = [] - fldquals = [] - for decl in type.decls: - if (isinstance(decl.type, pycparser.c_ast.IdentifierType) and - ''.join(decl.type.names) == '__dotdotdot__'): - # XXX pycparser is inconsistent: 'names' should be a list - # of strings, but is sometimes just one string. Use - # str.join() as a way to cope with both. - self._make_partial(tp, nested) - continue - if decl.bitsize is None: - bitsize = -1 - else: - bitsize = self._parse_constant(decl.bitsize) - self._partial_length = False - type, fqual = self._get_type_and_quals(decl.type, - partial_length_ok=True) - if self._partial_length: - self._make_partial(tp, nested) - if isinstance(type, model.StructType) and type.partial: - self._make_partial(tp, nested) - fldnames.append(decl.name or '') - fldtypes.append(type) - fldbitsize.append(bitsize) - fldquals.append(fqual) - tp.fldnames = tuple(fldnames) - tp.fldtypes = tuple(fldtypes) - tp.fldbitsize = tuple(fldbitsize) - tp.fldquals = tuple(fldquals) - if fldbitsize != [-1] * len(fldbitsize): - if isinstance(tp, model.StructType) and tp.partial: - raise NotImplementedError("%s: using both bitfields and '...;'" - % (tp,)) - tp.packed = self._options.get('packed') - if tp.completed: # must be re-completed: it is not opaque any more - tp.completed = 0 - self._recomplete.append(tp) - return tp - - def _make_partial(self, tp, nested): - if not isinstance(tp, model.StructOrUnion): - raise CDefError("%s cannot be partial" % (tp,)) - if not tp.has_c_name() and not nested: - raise NotImplementedError("%s is partial but has no C name" %(tp,)) - tp.partial = True - - def _parse_constant(self, exprnode, partial_length_ok=False): - # for now, limited to expressions that are an immediate number - # or positive/negative number - if isinstance(exprnode, pycparser.c_ast.Constant): - s = exprnode.value - if '0' <= s[0] <= '9': - s = s.rstrip('uUlL') - try: - if s.startswith('0'): - return int(s, 8) - else: - return int(s, 10) - except ValueError: - if len(s) > 1: - if s.lower()[0:2] == '0x': - return int(s, 16) - elif s.lower()[0:2] == '0b': - return int(s, 2) - raise CDefError("invalid constant %r" % (s,)) - elif s[0] == "'" and s[-1] == "'" and ( - len(s) == 3 or (len(s) == 4 and s[1] == "\\")): - return ord(s[-2]) - else: - raise CDefError("invalid constant %r" % (s,)) - # - if (isinstance(exprnode, pycparser.c_ast.UnaryOp) and - exprnode.op == '+'): - return self._parse_constant(exprnode.expr) - # - if (isinstance(exprnode, pycparser.c_ast.UnaryOp) and - exprnode.op == '-'): - return -self._parse_constant(exprnode.expr) - # load previously defined int constant - if (isinstance(exprnode, pycparser.c_ast.ID) and - exprnode.name in self._int_constants): - return self._int_constants[exprnode.name] - # - if (isinstance(exprnode, pycparser.c_ast.ID) and - exprnode.name == '__dotdotdotarray__'): - if partial_length_ok: - self._partial_length = True - return '...' - raise FFIError(":%d: unsupported '[...]' here, cannot derive " - "the actual array length in this context" - % exprnode.coord.line) - # - if isinstance(exprnode, pycparser.c_ast.BinaryOp): - left = self._parse_constant(exprnode.left) - right = self._parse_constant(exprnode.right) - if exprnode.op == '+': - return left + right - elif exprnode.op == '-': - return left - right - elif exprnode.op == '*': - return left * right - elif exprnode.op == '/': - return self._c_div(left, right) - elif exprnode.op == '%': - return left - self._c_div(left, right) * right - elif exprnode.op == '<<': - return left << right - elif exprnode.op == '>>': - return left >> right - elif exprnode.op == '&': - return left & right - elif exprnode.op == '|': - return left | right - elif exprnode.op == '^': - return left ^ right - # - raise FFIError(":%d: unsupported expression: expected a " - "simple numeric constant" % exprnode.coord.line) - - def _c_div(self, a, b): - result = a // b - if ((a < 0) ^ (b < 0)) and (a % b) != 0: - result += 1 - return result - - def _build_enum_type(self, explicit_name, decls): - if decls is not None: - partial = False - enumerators = [] - enumvalues = [] - nextenumvalue = 0 - for enum in decls.enumerators: - if _r_enum_dotdotdot.match(enum.name): - partial = True - continue - if enum.value is not None: - nextenumvalue = self._parse_constant(enum.value) - enumerators.append(enum.name) - enumvalues.append(nextenumvalue) - self._add_constants(enum.name, nextenumvalue) - nextenumvalue += 1 - enumerators = tuple(enumerators) - enumvalues = tuple(enumvalues) - tp = model.EnumType(explicit_name, enumerators, enumvalues) - tp.partial = partial - else: # opaque enum - tp = model.EnumType(explicit_name, (), ()) - return tp - - def include(self, other): - for name, (tp, quals) in other._declarations.items(): - if name.startswith('anonymous $enum_$'): - continue # fix for test_anonymous_enum_include - kind = name.split(' ', 1)[0] - if kind in ('struct', 'union', 'enum', 'anonymous', 'typedef'): - self._declare(name, tp, included=True, quals=quals) - for k, v in other._int_constants.items(): - self._add_constants(k, v) - - def _get_unknown_type(self, decl): - typenames = decl.type.type.names - if typenames == ['__dotdotdot__']: - return model.unknown_type(decl.name) - - if typenames == ['__dotdotdotint__']: - if self._uses_new_feature is None: - self._uses_new_feature = "'typedef int... %s'" % decl.name - return model.UnknownIntegerType(decl.name) - - if typenames == ['__dotdotdotfloat__']: - # note: not for 'long double' so far - if self._uses_new_feature is None: - self._uses_new_feature = "'typedef float... %s'" % decl.name - return model.UnknownFloatType(decl.name) - - raise FFIError(':%d: unsupported usage of "..." in typedef' - % decl.coord.line) - - def _get_unknown_ptr_type(self, decl): - if decl.type.type.type.names == ['__dotdotdot__']: - return model.unknown_ptr_type(decl.name) - raise FFIError(':%d: unsupported usage of "..." in typedef' - % decl.coord.line) diff --git a/.venv/lib/python3.12/site-packages/cffi/error.py b/.venv/lib/python3.12/site-packages/cffi/error.py deleted file mode 100644 index 0a27247..0000000 --- a/.venv/lib/python3.12/site-packages/cffi/error.py +++ /dev/null @@ -1,31 +0,0 @@ - -class FFIError(Exception): - __module__ = 'cffi' - -class CDefError(Exception): - __module__ = 'cffi' - def __str__(self): - try: - current_decl = self.args[1] - filename = current_decl.coord.file - linenum = current_decl.coord.line - prefix = '%s:%d: ' % (filename, linenum) - except (AttributeError, TypeError, IndexError): - prefix = '' - return '%s%s' % (prefix, self.args[0]) - -class VerificationError(Exception): - """ An error raised when verification fails - """ - __module__ = 'cffi' - -class VerificationMissing(Exception): - """ An error raised when incomplete structures are passed into - cdef, but no verification has been done - """ - __module__ = 'cffi' - -class PkgConfigError(Exception): - """ An error raised for missing modules in pkg-config - """ - __module__ = 'cffi' diff --git a/.venv/lib/python3.12/site-packages/cffi/ffiplatform.py b/.venv/lib/python3.12/site-packages/cffi/ffiplatform.py deleted file mode 100644 index adca28f..0000000 --- a/.venv/lib/python3.12/site-packages/cffi/ffiplatform.py +++ /dev/null @@ -1,113 +0,0 @@ -import sys, os -from .error import VerificationError - - -LIST_OF_FILE_NAMES = ['sources', 'include_dirs', 'library_dirs', - 'extra_objects', 'depends'] - -def get_extension(srcfilename, modname, sources=(), **kwds): - from cffi._shimmed_dist_utils import Extension - allsources = [srcfilename] - for src in sources: - allsources.append(os.path.normpath(src)) - return Extension(name=modname, sources=allsources, **kwds) - -def compile(tmpdir, ext, compiler_verbose=0, debug=None): - """Compile a C extension module using distutils.""" - - saved_environ = os.environ.copy() - try: - outputfilename = _build(tmpdir, ext, compiler_verbose, debug) - outputfilename = os.path.abspath(outputfilename) - finally: - # workaround for a distutils bugs where some env vars can - # become longer and longer every time it is used - for key, value in saved_environ.items(): - if os.environ.get(key) != value: - os.environ[key] = value - return outputfilename - -def _build(tmpdir, ext, compiler_verbose=0, debug=None): - # XXX compact but horrible :-( - from cffi._shimmed_dist_utils import Distribution, CompileError, LinkError, set_threshold, set_verbosity - - dist = Distribution({'ext_modules': [ext]}) - dist.parse_config_files() - options = dist.get_option_dict('build_ext') - if debug is None: - debug = sys.flags.debug - options['debug'] = ('ffiplatform', debug) - options['force'] = ('ffiplatform', True) - options['build_lib'] = ('ffiplatform', tmpdir) - options['build_temp'] = ('ffiplatform', tmpdir) - # - try: - old_level = set_threshold(0) or 0 - try: - set_verbosity(compiler_verbose) - dist.run_command('build_ext') - cmd_obj = dist.get_command_obj('build_ext') - [soname] = cmd_obj.get_outputs() - finally: - set_threshold(old_level) - except (CompileError, LinkError) as e: - raise VerificationError('%s: %s' % (e.__class__.__name__, e)) - # - return soname - -try: - from os.path import samefile -except ImportError: - def samefile(f1, f2): - return os.path.abspath(f1) == os.path.abspath(f2) - -def maybe_relative_path(path): - if not os.path.isabs(path): - return path # already relative - dir = path - names = [] - while True: - prevdir = dir - dir, name = os.path.split(prevdir) - if dir == prevdir or not dir: - return path # failed to make it relative - names.append(name) - try: - if samefile(dir, os.curdir): - names.reverse() - return os.path.join(*names) - except OSError: - pass - -# ____________________________________________________________ - -try: - int_or_long = (int, long) - import cStringIO -except NameError: - int_or_long = int # Python 3 - import io as cStringIO - -def _flatten(x, f): - if isinstance(x, str): - f.write('%ds%s' % (len(x), x)) - elif isinstance(x, dict): - keys = sorted(x.keys()) - f.write('%dd' % len(keys)) - for key in keys: - _flatten(key, f) - _flatten(x[key], f) - elif isinstance(x, (list, tuple)): - f.write('%dl' % len(x)) - for value in x: - _flatten(value, f) - elif isinstance(x, int_or_long): - f.write('%di' % (x,)) - else: - raise TypeError( - "the keywords to verify() contains unsupported object %r" % (x,)) - -def flatten(x): - f = cStringIO.StringIO() - _flatten(x, f) - return f.getvalue() diff --git a/.venv/lib/python3.12/site-packages/cffi/lock.py b/.venv/lib/python3.12/site-packages/cffi/lock.py deleted file mode 100644 index db91b71..0000000 --- a/.venv/lib/python3.12/site-packages/cffi/lock.py +++ /dev/null @@ -1,30 +0,0 @@ -import sys - -if sys.version_info < (3,): - try: - from thread import allocate_lock - except ImportError: - from dummy_thread import allocate_lock -else: - try: - from _thread import allocate_lock - except ImportError: - from _dummy_thread import allocate_lock - - -##import sys -##l1 = allocate_lock - -##class allocate_lock(object): -## def __init__(self): -## self._real = l1() -## def __enter__(self): -## for i in range(4, 0, -1): -## print sys._getframe(i).f_code -## print -## return self._real.__enter__() -## def __exit__(self, *args): -## return self._real.__exit__(*args) -## def acquire(self, f): -## assert f is False -## return self._real.acquire(f) diff --git a/.venv/lib/python3.12/site-packages/cffi/model.py b/.venv/lib/python3.12/site-packages/cffi/model.py deleted file mode 100644 index e5f4cae..0000000 --- a/.venv/lib/python3.12/site-packages/cffi/model.py +++ /dev/null @@ -1,618 +0,0 @@ -import types -import weakref - -from .lock import allocate_lock -from .error import CDefError, VerificationError, VerificationMissing - -# type qualifiers -Q_CONST = 0x01 -Q_RESTRICT = 0x02 -Q_VOLATILE = 0x04 - -def qualify(quals, replace_with): - if quals & Q_CONST: - replace_with = ' const ' + replace_with.lstrip() - if quals & Q_VOLATILE: - replace_with = ' volatile ' + replace_with.lstrip() - if quals & Q_RESTRICT: - # It seems that __restrict is supported by gcc and msvc. - # If you hit some different compiler, add a #define in - # _cffi_include.h for it (and in its copies, documented there) - replace_with = ' __restrict ' + replace_with.lstrip() - return replace_with - - -class BaseTypeByIdentity(object): - is_array_type = False - is_raw_function = False - - def get_c_name(self, replace_with='', context='a C file', quals=0): - result = self.c_name_with_marker - assert result.count('&') == 1 - # some logic duplication with ffi.getctype()... :-( - replace_with = replace_with.strip() - if replace_with: - if replace_with.startswith('*') and '&[' in result: - replace_with = '(%s)' % replace_with - elif not replace_with[0] in '[(': - replace_with = ' ' + replace_with - replace_with = qualify(quals, replace_with) - result = result.replace('&', replace_with) - if '$' in result: - raise VerificationError( - "cannot generate '%s' in %s: unknown type name" - % (self._get_c_name(), context)) - return result - - def _get_c_name(self): - return self.c_name_with_marker.replace('&', '') - - def has_c_name(self): - return '$' not in self._get_c_name() - - def is_integer_type(self): - return False - - def get_cached_btype(self, ffi, finishlist, can_delay=False): - try: - BType = ffi._cached_btypes[self] - except KeyError: - BType = self.build_backend_type(ffi, finishlist) - BType2 = ffi._cached_btypes.setdefault(self, BType) - assert BType2 is BType - return BType - - def __repr__(self): - return '<%s>' % (self._get_c_name(),) - - def _get_items(self): - return [(name, getattr(self, name)) for name in self._attrs_] - - -class BaseType(BaseTypeByIdentity): - - def __eq__(self, other): - return (self.__class__ == other.__class__ and - self._get_items() == other._get_items()) - - def __ne__(self, other): - return not self == other - - def __hash__(self): - return hash((self.__class__, tuple(self._get_items()))) - - -class VoidType(BaseType): - _attrs_ = () - - def __init__(self): - self.c_name_with_marker = 'void&' - - def build_backend_type(self, ffi, finishlist): - return global_cache(self, ffi, 'new_void_type') - -void_type = VoidType() - - -class BasePrimitiveType(BaseType): - def is_complex_type(self): - return False - - -class PrimitiveType(BasePrimitiveType): - _attrs_ = ('name',) - - ALL_PRIMITIVE_TYPES = { - 'char': 'c', - 'short': 'i', - 'int': 'i', - 'long': 'i', - 'long long': 'i', - 'signed char': 'i', - 'unsigned char': 'i', - 'unsigned short': 'i', - 'unsigned int': 'i', - 'unsigned long': 'i', - 'unsigned long long': 'i', - 'float': 'f', - 'double': 'f', - 'long double': 'f', - '_cffi_float_complex_t': 'j', - '_cffi_double_complex_t': 'j', - '_Bool': 'i', - # the following types are not primitive in the C sense - 'wchar_t': 'c', - 'char16_t': 'c', - 'char32_t': 'c', - 'int8_t': 'i', - 'uint8_t': 'i', - 'int16_t': 'i', - 'uint16_t': 'i', - 'int32_t': 'i', - 'uint32_t': 'i', - 'int64_t': 'i', - 'uint64_t': 'i', - 'int_least8_t': 'i', - 'uint_least8_t': 'i', - 'int_least16_t': 'i', - 'uint_least16_t': 'i', - 'int_least32_t': 'i', - 'uint_least32_t': 'i', - 'int_least64_t': 'i', - 'uint_least64_t': 'i', - 'int_fast8_t': 'i', - 'uint_fast8_t': 'i', - 'int_fast16_t': 'i', - 'uint_fast16_t': 'i', - 'int_fast32_t': 'i', - 'uint_fast32_t': 'i', - 'int_fast64_t': 'i', - 'uint_fast64_t': 'i', - 'intptr_t': 'i', - 'uintptr_t': 'i', - 'intmax_t': 'i', - 'uintmax_t': 'i', - 'ptrdiff_t': 'i', - 'size_t': 'i', - 'ssize_t': 'i', - } - - def __init__(self, name): - assert name in self.ALL_PRIMITIVE_TYPES - self.name = name - self.c_name_with_marker = name + '&' - - def is_char_type(self): - return self.ALL_PRIMITIVE_TYPES[self.name] == 'c' - def is_integer_type(self): - return self.ALL_PRIMITIVE_TYPES[self.name] == 'i' - def is_float_type(self): - return self.ALL_PRIMITIVE_TYPES[self.name] == 'f' - def is_complex_type(self): - return self.ALL_PRIMITIVE_TYPES[self.name] == 'j' - - def build_backend_type(self, ffi, finishlist): - return global_cache(self, ffi, 'new_primitive_type', self.name) - - -class UnknownIntegerType(BasePrimitiveType): - _attrs_ = ('name',) - - def __init__(self, name): - self.name = name - self.c_name_with_marker = name + '&' - - def is_integer_type(self): - return True - - def build_backend_type(self, ffi, finishlist): - raise NotImplementedError("integer type '%s' can only be used after " - "compilation" % self.name) - -class UnknownFloatType(BasePrimitiveType): - _attrs_ = ('name', ) - - def __init__(self, name): - self.name = name - self.c_name_with_marker = name + '&' - - def build_backend_type(self, ffi, finishlist): - raise NotImplementedError("float type '%s' can only be used after " - "compilation" % self.name) - - -class BaseFunctionType(BaseType): - _attrs_ = ('args', 'result', 'ellipsis', 'abi') - - def __init__(self, args, result, ellipsis, abi=None): - self.args = args - self.result = result - self.ellipsis = ellipsis - self.abi = abi - # - reprargs = [arg._get_c_name() for arg in self.args] - if self.ellipsis: - reprargs.append('...') - reprargs = reprargs or ['void'] - replace_with = self._base_pattern % (', '.join(reprargs),) - if abi is not None: - replace_with = replace_with[:1] + abi + ' ' + replace_with[1:] - self.c_name_with_marker = ( - self.result.c_name_with_marker.replace('&', replace_with)) - - -class RawFunctionType(BaseFunctionType): - # Corresponds to a C type like 'int(int)', which is the C type of - # a function, but not a pointer-to-function. The backend has no - # notion of such a type; it's used temporarily by parsing. - _base_pattern = '(&)(%s)' - is_raw_function = True - - def build_backend_type(self, ffi, finishlist): - raise CDefError("cannot render the type %r: it is a function " - "type, not a pointer-to-function type" % (self,)) - - def as_function_pointer(self): - return FunctionPtrType(self.args, self.result, self.ellipsis, self.abi) - - -class FunctionPtrType(BaseFunctionType): - _base_pattern = '(*&)(%s)' - - def build_backend_type(self, ffi, finishlist): - result = self.result.get_cached_btype(ffi, finishlist) - args = [] - for tp in self.args: - args.append(tp.get_cached_btype(ffi, finishlist)) - abi_args = () - if self.abi == "__stdcall": - if not self.ellipsis: # __stdcall ignored for variadic funcs - try: - abi_args = (ffi._backend.FFI_STDCALL,) - except AttributeError: - pass - return global_cache(self, ffi, 'new_function_type', - tuple(args), result, self.ellipsis, *abi_args) - - def as_raw_function(self): - return RawFunctionType(self.args, self.result, self.ellipsis, self.abi) - - -class PointerType(BaseType): - _attrs_ = ('totype', 'quals') - - def __init__(self, totype, quals=0): - self.totype = totype - self.quals = quals - extra = " *&" - if totype.is_array_type: - extra = "(%s)" % (extra.lstrip(),) - extra = qualify(quals, extra) - self.c_name_with_marker = totype.c_name_with_marker.replace('&', extra) - - def build_backend_type(self, ffi, finishlist): - BItem = self.totype.get_cached_btype(ffi, finishlist, can_delay=True) - return global_cache(self, ffi, 'new_pointer_type', BItem) - -voidp_type = PointerType(void_type) - -def ConstPointerType(totype): - return PointerType(totype, Q_CONST) - -const_voidp_type = ConstPointerType(void_type) - - -class NamedPointerType(PointerType): - _attrs_ = ('totype', 'name') - - def __init__(self, totype, name, quals=0): - PointerType.__init__(self, totype, quals) - self.name = name - self.c_name_with_marker = name + '&' - - -class ArrayType(BaseType): - _attrs_ = ('item', 'length') - is_array_type = True - - def __init__(self, item, length): - self.item = item - self.length = length - # - if length is None: - brackets = '&[]' - elif length == '...': - brackets = '&[/*...*/]' - else: - brackets = '&[%s]' % length - self.c_name_with_marker = ( - self.item.c_name_with_marker.replace('&', brackets)) - - def length_is_unknown(self): - return isinstance(self.length, str) - - def resolve_length(self, newlength): - return ArrayType(self.item, newlength) - - def build_backend_type(self, ffi, finishlist): - if self.length_is_unknown(): - raise CDefError("cannot render the type %r: unknown length" % - (self,)) - self.item.get_cached_btype(ffi, finishlist) # force the item BType - BPtrItem = PointerType(self.item).get_cached_btype(ffi, finishlist) - return global_cache(self, ffi, 'new_array_type', BPtrItem, self.length) - -char_array_type = ArrayType(PrimitiveType('char'), None) - - -class StructOrUnionOrEnum(BaseTypeByIdentity): - _attrs_ = ('name',) - forcename = None - - def build_c_name_with_marker(self): - name = self.forcename or '%s %s' % (self.kind, self.name) - self.c_name_with_marker = name + '&' - - def force_the_name(self, forcename): - self.forcename = forcename - self.build_c_name_with_marker() - - def get_official_name(self): - assert self.c_name_with_marker.endswith('&') - return self.c_name_with_marker[:-1] - - -class StructOrUnion(StructOrUnionOrEnum): - fixedlayout = None - completed = 0 - partial = False - packed = 0 - - def __init__(self, name, fldnames, fldtypes, fldbitsize, fldquals=None): - self.name = name - self.fldnames = fldnames - self.fldtypes = fldtypes - self.fldbitsize = fldbitsize - self.fldquals = fldquals - self.build_c_name_with_marker() - - def anonymous_struct_fields(self): - if self.fldtypes is not None: - for name, type in zip(self.fldnames, self.fldtypes): - if name == '' and isinstance(type, StructOrUnion): - yield type - - def enumfields(self, expand_anonymous_struct_union=True): - fldquals = self.fldquals - if fldquals is None: - fldquals = (0,) * len(self.fldnames) - for name, type, bitsize, quals in zip(self.fldnames, self.fldtypes, - self.fldbitsize, fldquals): - if (name == '' and isinstance(type, StructOrUnion) - and expand_anonymous_struct_union): - # nested anonymous struct/union - for result in type.enumfields(): - yield result - else: - yield (name, type, bitsize, quals) - - def force_flatten(self): - # force the struct or union to have a declaration that lists - # directly all fields returned by enumfields(), flattening - # nested anonymous structs/unions. - names = [] - types = [] - bitsizes = [] - fldquals = [] - for name, type, bitsize, quals in self.enumfields(): - names.append(name) - types.append(type) - bitsizes.append(bitsize) - fldquals.append(quals) - self.fldnames = tuple(names) - self.fldtypes = tuple(types) - self.fldbitsize = tuple(bitsizes) - self.fldquals = tuple(fldquals) - - def get_cached_btype(self, ffi, finishlist, can_delay=False): - BType = StructOrUnionOrEnum.get_cached_btype(self, ffi, finishlist, - can_delay) - if not can_delay: - self.finish_backend_type(ffi, finishlist) - return BType - - def finish_backend_type(self, ffi, finishlist): - if self.completed: - if self.completed != 2: - raise NotImplementedError("recursive structure declaration " - "for '%s'" % (self.name,)) - return - BType = ffi._cached_btypes[self] - # - self.completed = 1 - # - if self.fldtypes is None: - pass # not completing it: it's an opaque struct - # - elif self.fixedlayout is None: - fldtypes = [tp.get_cached_btype(ffi, finishlist) - for tp in self.fldtypes] - lst = list(zip(self.fldnames, fldtypes, self.fldbitsize)) - extra_flags = () - if self.packed: - if self.packed == 1: - extra_flags = (8,) # SF_PACKED - else: - extra_flags = (0, self.packed) - ffi._backend.complete_struct_or_union(BType, lst, self, - -1, -1, *extra_flags) - # - else: - fldtypes = [] - fieldofs, fieldsize, totalsize, totalalignment = self.fixedlayout - for i in range(len(self.fldnames)): - fsize = fieldsize[i] - ftype = self.fldtypes[i] - # - if isinstance(ftype, ArrayType) and ftype.length_is_unknown(): - # fix the length to match the total size - BItemType = ftype.item.get_cached_btype(ffi, finishlist) - nlen, nrest = divmod(fsize, ffi.sizeof(BItemType)) - if nrest != 0: - self._verification_error( - "field '%s.%s' has a bogus size?" % ( - self.name, self.fldnames[i] or '{}')) - ftype = ftype.resolve_length(nlen) - self.fldtypes = (self.fldtypes[:i] + (ftype,) + - self.fldtypes[i+1:]) - # - BFieldType = ftype.get_cached_btype(ffi, finishlist) - if isinstance(ftype, ArrayType) and ftype.length is None: - assert fsize == 0 - else: - bitemsize = ffi.sizeof(BFieldType) - if bitemsize != fsize: - self._verification_error( - "field '%s.%s' is declared as %d bytes, but is " - "really %d bytes" % (self.name, - self.fldnames[i] or '{}', - bitemsize, fsize)) - fldtypes.append(BFieldType) - # - lst = list(zip(self.fldnames, fldtypes, self.fldbitsize, fieldofs)) - ffi._backend.complete_struct_or_union(BType, lst, self, - totalsize, totalalignment) - self.completed = 2 - - def _verification_error(self, msg): - raise VerificationError(msg) - - def check_not_partial(self): - if self.partial and self.fixedlayout is None: - raise VerificationMissing(self._get_c_name()) - - def build_backend_type(self, ffi, finishlist): - self.check_not_partial() - finishlist.append(self) - # - return global_cache(self, ffi, 'new_%s_type' % self.kind, - self.get_official_name(), key=self) - - -class StructType(StructOrUnion): - kind = 'struct' - - -class UnionType(StructOrUnion): - kind = 'union' - - -class EnumType(StructOrUnionOrEnum): - kind = 'enum' - partial = False - partial_resolved = False - - def __init__(self, name, enumerators, enumvalues, baseinttype=None): - self.name = name - self.enumerators = enumerators - self.enumvalues = enumvalues - self.baseinttype = baseinttype - self.build_c_name_with_marker() - - def force_the_name(self, forcename): - StructOrUnionOrEnum.force_the_name(self, forcename) - if self.forcename is None: - name = self.get_official_name() - self.forcename = '$' + name.replace(' ', '_') - - def check_not_partial(self): - if self.partial and not self.partial_resolved: - raise VerificationMissing(self._get_c_name()) - - def build_backend_type(self, ffi, finishlist): - self.check_not_partial() - base_btype = self.build_baseinttype(ffi, finishlist) - return global_cache(self, ffi, 'new_enum_type', - self.get_official_name(), - self.enumerators, self.enumvalues, - base_btype, key=self) - - def build_baseinttype(self, ffi, finishlist): - if self.baseinttype is not None: - return self.baseinttype.get_cached_btype(ffi, finishlist) - # - if self.enumvalues: - smallest_value = min(self.enumvalues) - largest_value = max(self.enumvalues) - else: - import warnings - try: - # XXX! The goal is to ensure that the warnings.warn() - # will not suppress the warning. We want to get it - # several times if we reach this point several times. - __warningregistry__.clear() - except NameError: - pass - warnings.warn("%r has no values explicitly defined; " - "guessing that it is equivalent to 'unsigned int'" - % self._get_c_name()) - smallest_value = largest_value = 0 - if smallest_value < 0: # needs a signed type - sign = 1 - candidate1 = PrimitiveType("int") - candidate2 = PrimitiveType("long") - else: - sign = 0 - candidate1 = PrimitiveType("unsigned int") - candidate2 = PrimitiveType("unsigned long") - btype1 = candidate1.get_cached_btype(ffi, finishlist) - btype2 = candidate2.get_cached_btype(ffi, finishlist) - size1 = ffi.sizeof(btype1) - size2 = ffi.sizeof(btype2) - if (smallest_value >= ((-1) << (8*size1-1)) and - largest_value < (1 << (8*size1-sign))): - return btype1 - if (smallest_value >= ((-1) << (8*size2-1)) and - largest_value < (1 << (8*size2-sign))): - return btype2 - raise CDefError("%s values don't all fit into either 'long' " - "or 'unsigned long'" % self._get_c_name()) - -def unknown_type(name, structname=None): - if structname is None: - structname = '$%s' % name - tp = StructType(structname, None, None, None) - tp.force_the_name(name) - tp.origin = "unknown_type" - return tp - -def unknown_ptr_type(name, structname=None): - if structname is None: - structname = '$$%s' % name - tp = StructType(structname, None, None, None) - return NamedPointerType(tp, name) - - -global_lock = allocate_lock() -_typecache_cffi_backend = weakref.WeakValueDictionary() - -def get_typecache(backend): - # returns _typecache_cffi_backend if backend is the _cffi_backend - # module, or type(backend).__typecache if backend is an instance of - # CTypesBackend (or some FakeBackend class during tests) - if isinstance(backend, types.ModuleType): - return _typecache_cffi_backend - with global_lock: - if not hasattr(type(backend), '__typecache'): - type(backend).__typecache = weakref.WeakValueDictionary() - return type(backend).__typecache - -def global_cache(srctype, ffi, funcname, *args, **kwds): - key = kwds.pop('key', (funcname, args)) - assert not kwds - try: - return ffi._typecache[key] - except KeyError: - pass - try: - res = getattr(ffi._backend, funcname)(*args) - except NotImplementedError as e: - raise NotImplementedError("%s: %r: %s" % (funcname, srctype, e)) - # note that setdefault() on WeakValueDictionary is not atomic - # and contains a rare bug (http://bugs.python.org/issue19542); - # we have to use a lock and do it ourselves - cache = ffi._typecache - with global_lock: - res1 = cache.get(key) - if res1 is None: - cache[key] = res - return res - else: - return res1 - -def pointer_cache(ffi, BType): - return global_cache('?', ffi, 'new_pointer_type', BType) - -def attach_exception_info(e, name): - if e.args and type(e.args[0]) is str: - e.args = ('%s: %s' % (name, e.args[0]),) + e.args[1:] diff --git a/.venv/lib/python3.12/site-packages/cffi/parse_c_type.h b/.venv/lib/python3.12/site-packages/cffi/parse_c_type.h deleted file mode 100644 index 84e4ef8..0000000 --- a/.venv/lib/python3.12/site-packages/cffi/parse_c_type.h +++ /dev/null @@ -1,181 +0,0 @@ - -/* This part is from file 'cffi/parse_c_type.h'. It is copied at the - beginning of C sources generated by CFFI's ffi.set_source(). */ - -typedef void *_cffi_opcode_t; - -#define _CFFI_OP(opcode, arg) (_cffi_opcode_t)(opcode | (((uintptr_t)(arg)) << 8)) -#define _CFFI_GETOP(cffi_opcode) ((unsigned char)(uintptr_t)cffi_opcode) -#define _CFFI_GETARG(cffi_opcode) (((intptr_t)cffi_opcode) >> 8) - -#define _CFFI_OP_PRIMITIVE 1 -#define _CFFI_OP_POINTER 3 -#define _CFFI_OP_ARRAY 5 -#define _CFFI_OP_OPEN_ARRAY 7 -#define _CFFI_OP_STRUCT_UNION 9 -#define _CFFI_OP_ENUM 11 -#define _CFFI_OP_FUNCTION 13 -#define _CFFI_OP_FUNCTION_END 15 -#define _CFFI_OP_NOOP 17 -#define _CFFI_OP_BITFIELD 19 -#define _CFFI_OP_TYPENAME 21 -#define _CFFI_OP_CPYTHON_BLTN_V 23 // varargs -#define _CFFI_OP_CPYTHON_BLTN_N 25 // noargs -#define _CFFI_OP_CPYTHON_BLTN_O 27 // O (i.e. a single arg) -#define _CFFI_OP_CONSTANT 29 -#define _CFFI_OP_CONSTANT_INT 31 -#define _CFFI_OP_GLOBAL_VAR 33 -#define _CFFI_OP_DLOPEN_FUNC 35 -#define _CFFI_OP_DLOPEN_CONST 37 -#define _CFFI_OP_GLOBAL_VAR_F 39 -#define _CFFI_OP_EXTERN_PYTHON 41 - -#define _CFFI_PRIM_VOID 0 -#define _CFFI_PRIM_BOOL 1 -#define _CFFI_PRIM_CHAR 2 -#define _CFFI_PRIM_SCHAR 3 -#define _CFFI_PRIM_UCHAR 4 -#define _CFFI_PRIM_SHORT 5 -#define _CFFI_PRIM_USHORT 6 -#define _CFFI_PRIM_INT 7 -#define _CFFI_PRIM_UINT 8 -#define _CFFI_PRIM_LONG 9 -#define _CFFI_PRIM_ULONG 10 -#define _CFFI_PRIM_LONGLONG 11 -#define _CFFI_PRIM_ULONGLONG 12 -#define _CFFI_PRIM_FLOAT 13 -#define _CFFI_PRIM_DOUBLE 14 -#define _CFFI_PRIM_LONGDOUBLE 15 - -#define _CFFI_PRIM_WCHAR 16 -#define _CFFI_PRIM_INT8 17 -#define _CFFI_PRIM_UINT8 18 -#define _CFFI_PRIM_INT16 19 -#define _CFFI_PRIM_UINT16 20 -#define _CFFI_PRIM_INT32 21 -#define _CFFI_PRIM_UINT32 22 -#define _CFFI_PRIM_INT64 23 -#define _CFFI_PRIM_UINT64 24 -#define _CFFI_PRIM_INTPTR 25 -#define _CFFI_PRIM_UINTPTR 26 -#define _CFFI_PRIM_PTRDIFF 27 -#define _CFFI_PRIM_SIZE 28 -#define _CFFI_PRIM_SSIZE 29 -#define _CFFI_PRIM_INT_LEAST8 30 -#define _CFFI_PRIM_UINT_LEAST8 31 -#define _CFFI_PRIM_INT_LEAST16 32 -#define _CFFI_PRIM_UINT_LEAST16 33 -#define _CFFI_PRIM_INT_LEAST32 34 -#define _CFFI_PRIM_UINT_LEAST32 35 -#define _CFFI_PRIM_INT_LEAST64 36 -#define _CFFI_PRIM_UINT_LEAST64 37 -#define _CFFI_PRIM_INT_FAST8 38 -#define _CFFI_PRIM_UINT_FAST8 39 -#define _CFFI_PRIM_INT_FAST16 40 -#define _CFFI_PRIM_UINT_FAST16 41 -#define _CFFI_PRIM_INT_FAST32 42 -#define _CFFI_PRIM_UINT_FAST32 43 -#define _CFFI_PRIM_INT_FAST64 44 -#define _CFFI_PRIM_UINT_FAST64 45 -#define _CFFI_PRIM_INTMAX 46 -#define _CFFI_PRIM_UINTMAX 47 -#define _CFFI_PRIM_FLOATCOMPLEX 48 -#define _CFFI_PRIM_DOUBLECOMPLEX 49 -#define _CFFI_PRIM_CHAR16 50 -#define _CFFI_PRIM_CHAR32 51 - -#define _CFFI__NUM_PRIM 52 -#define _CFFI__UNKNOWN_PRIM (-1) -#define _CFFI__UNKNOWN_FLOAT_PRIM (-2) -#define _CFFI__UNKNOWN_LONG_DOUBLE (-3) - -#define _CFFI__IO_FILE_STRUCT (-1) - - -struct _cffi_global_s { - const char *name; - void *address; - _cffi_opcode_t type_op; - void *size_or_direct_fn; // OP_GLOBAL_VAR: size, or 0 if unknown - // OP_CPYTHON_BLTN_*: addr of direct function -}; - -struct _cffi_getconst_s { - unsigned long long value; - const struct _cffi_type_context_s *ctx; - int gindex; -}; - -struct _cffi_struct_union_s { - const char *name; - int type_index; // -> _cffi_types, on a OP_STRUCT_UNION - int flags; // _CFFI_F_* flags below - size_t size; - int alignment; - int first_field_index; // -> _cffi_fields array - int num_fields; -}; -#define _CFFI_F_UNION 0x01 // is a union, not a struct -#define _CFFI_F_CHECK_FIELDS 0x02 // complain if fields are not in the - // "standard layout" or if some are missing -#define _CFFI_F_PACKED 0x04 // for CHECK_FIELDS, assume a packed struct -#define _CFFI_F_EXTERNAL 0x08 // in some other ffi.include() -#define _CFFI_F_OPAQUE 0x10 // opaque - -struct _cffi_field_s { - const char *name; - size_t field_offset; - size_t field_size; - _cffi_opcode_t field_type_op; -}; - -struct _cffi_enum_s { - const char *name; - int type_index; // -> _cffi_types, on a OP_ENUM - int type_prim; // _CFFI_PRIM_xxx - const char *enumerators; // comma-delimited string -}; - -struct _cffi_typename_s { - const char *name; - int type_index; /* if opaque, points to a possibly artificial - OP_STRUCT which is itself opaque */ -}; - -struct _cffi_type_context_s { - _cffi_opcode_t *types; - const struct _cffi_global_s *globals; - const struct _cffi_field_s *fields; - const struct _cffi_struct_union_s *struct_unions; - const struct _cffi_enum_s *enums; - const struct _cffi_typename_s *typenames; - int num_globals; - int num_struct_unions; - int num_enums; - int num_typenames; - const char *const *includes; - int num_types; - int flags; /* future extension */ -}; - -struct _cffi_parse_info_s { - const struct _cffi_type_context_s *ctx; - _cffi_opcode_t *output; - unsigned int output_size; - size_t error_location; - const char *error_message; -}; - -struct _cffi_externpy_s { - const char *name; - size_t size_of_result; - void *reserved1, *reserved2; -}; - -#ifdef _CFFI_INTERNAL -static int parse_c_type(struct _cffi_parse_info_s *info, const char *input); -static int search_in_globals(const struct _cffi_type_context_s *ctx, - const char *search, size_t search_len); -static int search_in_struct_unions(const struct _cffi_type_context_s *ctx, - const char *search, size_t search_len); -#endif diff --git a/.venv/lib/python3.12/site-packages/cffi/pkgconfig.py b/.venv/lib/python3.12/site-packages/cffi/pkgconfig.py deleted file mode 100644 index 5c93f15..0000000 --- a/.venv/lib/python3.12/site-packages/cffi/pkgconfig.py +++ /dev/null @@ -1,121 +0,0 @@ -# pkg-config, https://www.freedesktop.org/wiki/Software/pkg-config/ integration for cffi -import sys, os, subprocess - -from .error import PkgConfigError - - -def merge_flags(cfg1, cfg2): - """Merge values from cffi config flags cfg2 to cf1 - - Example: - merge_flags({"libraries": ["one"]}, {"libraries": ["two"]}) - {"libraries": ["one", "two"]} - """ - for key, value in cfg2.items(): - if key not in cfg1: - cfg1[key] = value - else: - if not isinstance(cfg1[key], list): - raise TypeError("cfg1[%r] should be a list of strings" % (key,)) - if not isinstance(value, list): - raise TypeError("cfg2[%r] should be a list of strings" % (key,)) - cfg1[key].extend(value) - return cfg1 - - -def call(libname, flag, encoding=sys.getfilesystemencoding()): - """Calls pkg-config and returns the output if found - """ - a = ["pkg-config", "--print-errors"] - a.append(flag) - a.append(libname) - try: - pc = subprocess.Popen(a, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - except EnvironmentError as e: - raise PkgConfigError("cannot run pkg-config: %s" % (str(e).strip(),)) - - bout, berr = pc.communicate() - if pc.returncode != 0: - try: - berr = berr.decode(encoding) - except Exception: - pass - raise PkgConfigError(berr.strip()) - - if sys.version_info >= (3,) and not isinstance(bout, str): # Python 3.x - try: - bout = bout.decode(encoding) - except UnicodeDecodeError: - raise PkgConfigError("pkg-config %s %s returned bytes that cannot " - "be decoded with encoding %r:\n%r" % - (flag, libname, encoding, bout)) - - if os.altsep != '\\' and '\\' in bout: - raise PkgConfigError("pkg-config %s %s returned an unsupported " - "backslash-escaped output:\n%r" % - (flag, libname, bout)) - return bout - - -def flags_from_pkgconfig(libs): - r"""Return compiler line flags for FFI.set_source based on pkg-config output - - Usage - ... - ffibuilder.set_source("_foo", pkgconfig = ["libfoo", "libbar >= 1.8.3"]) - - If pkg-config is installed on build machine, then arguments include_dirs, - library_dirs, libraries, define_macros, extra_compile_args and - extra_link_args are extended with an output of pkg-config for libfoo and - libbar. - - Raises PkgConfigError in case the pkg-config call fails. - """ - - def get_include_dirs(string): - return [x[2:] for x in string.split() if x.startswith("-I")] - - def get_library_dirs(string): - return [x[2:] for x in string.split() if x.startswith("-L")] - - def get_libraries(string): - return [x[2:] for x in string.split() if x.startswith("-l")] - - # convert -Dfoo=bar to list of tuples [("foo", "bar")] expected by distutils - def get_macros(string): - def _macro(x): - x = x[2:] # drop "-D" - if '=' in x: - return tuple(x.split("=", 1)) # "-Dfoo=bar" => ("foo", "bar") - else: - return (x, None) # "-Dfoo" => ("foo", None) - return [_macro(x) for x in string.split() if x.startswith("-D")] - - def get_other_cflags(string): - return [x for x in string.split() if not x.startswith("-I") and - not x.startswith("-D")] - - def get_other_libs(string): - return [x for x in string.split() if not x.startswith("-L") and - not x.startswith("-l")] - - # return kwargs for given libname - def kwargs(libname): - fse = sys.getfilesystemencoding() - all_cflags = call(libname, "--cflags") - all_libs = call(libname, "--libs") - return { - "include_dirs": get_include_dirs(all_cflags), - "library_dirs": get_library_dirs(all_libs), - "libraries": get_libraries(all_libs), - "define_macros": get_macros(all_cflags), - "extra_compile_args": get_other_cflags(all_cflags), - "extra_link_args": get_other_libs(all_libs), - } - - # merge all arguments together - ret = {} - for libname in libs: - lib_flags = kwargs(libname) - merge_flags(ret, lib_flags) - return ret diff --git a/.venv/lib/python3.12/site-packages/cffi/recompiler.py b/.venv/lib/python3.12/site-packages/cffi/recompiler.py deleted file mode 100644 index 7734a34..0000000 --- a/.venv/lib/python3.12/site-packages/cffi/recompiler.py +++ /dev/null @@ -1,1598 +0,0 @@ -import io, os, sys, sysconfig -from . import ffiplatform, model -from .error import VerificationError -from .cffi_opcode import * - -VERSION_BASE = 0x2601 -VERSION_EMBEDDED = 0x2701 -VERSION_CHAR16CHAR32 = 0x2801 - -USE_LIMITED_API = ((sys.platform != 'win32' or sys.version_info < (3, 0) or - sys.version_info >= (3, 5)) and - not sysconfig.get_config_var("Py_GIL_DISABLED")) # free-threaded doesn't yet support limited API - -class GlobalExpr: - def __init__(self, name, address, type_op, size=0, check_value=0): - self.name = name - self.address = address - self.type_op = type_op - self.size = size - self.check_value = check_value - - def as_c_expr(self): - return ' { "%s", (void *)%s, %s, (void *)%s },' % ( - self.name, self.address, self.type_op.as_c_expr(), self.size) - - def as_python_expr(self): - return "b'%s%s',%d" % (self.type_op.as_python_bytes(), self.name, - self.check_value) - -class FieldExpr: - def __init__(self, name, field_offset, field_size, fbitsize, field_type_op): - self.name = name - self.field_offset = field_offset - self.field_size = field_size - self.fbitsize = fbitsize - self.field_type_op = field_type_op - - def as_c_expr(self): - spaces = " " * len(self.name) - return (' { "%s", %s,\n' % (self.name, self.field_offset) + - ' %s %s,\n' % (spaces, self.field_size) + - ' %s %s },' % (spaces, self.field_type_op.as_c_expr())) - - def as_python_expr(self): - raise NotImplementedError - - def as_field_python_expr(self): - if self.field_type_op.op == OP_NOOP: - size_expr = '' - elif self.field_type_op.op == OP_BITFIELD: - size_expr = format_four_bytes(self.fbitsize) - else: - raise NotImplementedError - return "b'%s%s%s'" % (self.field_type_op.as_python_bytes(), - size_expr, - self.name) - -class StructUnionExpr: - def __init__(self, name, type_index, flags, size, alignment, comment, - first_field_index, c_fields): - self.name = name - self.type_index = type_index - self.flags = flags - self.size = size - self.alignment = alignment - self.comment = comment - self.first_field_index = first_field_index - self.c_fields = c_fields - - def as_c_expr(self): - return (' { "%s", %d, %s,' % (self.name, self.type_index, self.flags) - + '\n %s, %s, ' % (self.size, self.alignment) - + '%d, %d ' % (self.first_field_index, len(self.c_fields)) - + ('/* %s */ ' % self.comment if self.comment else '') - + '},') - - def as_python_expr(self): - flags = eval(self.flags, G_FLAGS) - fields_expr = [c_field.as_field_python_expr() - for c_field in self.c_fields] - return "(b'%s%s%s',%s)" % ( - format_four_bytes(self.type_index), - format_four_bytes(flags), - self.name, - ','.join(fields_expr)) - -class EnumExpr: - def __init__(self, name, type_index, size, signed, allenums): - self.name = name - self.type_index = type_index - self.size = size - self.signed = signed - self.allenums = allenums - - def as_c_expr(self): - return (' { "%s", %d, _cffi_prim_int(%s, %s),\n' - ' "%s" },' % (self.name, self.type_index, - self.size, self.signed, self.allenums)) - - def as_python_expr(self): - prim_index = { - (1, 0): PRIM_UINT8, (1, 1): PRIM_INT8, - (2, 0): PRIM_UINT16, (2, 1): PRIM_INT16, - (4, 0): PRIM_UINT32, (4, 1): PRIM_INT32, - (8, 0): PRIM_UINT64, (8, 1): PRIM_INT64, - }[self.size, self.signed] - return "b'%s%s%s\\x00%s'" % (format_four_bytes(self.type_index), - format_four_bytes(prim_index), - self.name, self.allenums) - -class TypenameExpr: - def __init__(self, name, type_index): - self.name = name - self.type_index = type_index - - def as_c_expr(self): - return ' { "%s", %d },' % (self.name, self.type_index) - - def as_python_expr(self): - return "b'%s%s'" % (format_four_bytes(self.type_index), self.name) - - -# ____________________________________________________________ - - -class Recompiler: - _num_externpy = 0 - - def __init__(self, ffi, module_name, target_is_python=False): - self.ffi = ffi - self.module_name = module_name - self.target_is_python = target_is_python - self._version = VERSION_BASE - - def needs_version(self, ver): - self._version = max(self._version, ver) - - def collect_type_table(self): - self._typesdict = {} - self._generate("collecttype") - # - all_decls = sorted(self._typesdict, key=str) - # - # prepare all FUNCTION bytecode sequences first - self.cffi_types = [] - for tp in all_decls: - if tp.is_raw_function: - assert self._typesdict[tp] is None - self._typesdict[tp] = len(self.cffi_types) - self.cffi_types.append(tp) # placeholder - for tp1 in tp.args: - assert isinstance(tp1, (model.VoidType, - model.BasePrimitiveType, - model.PointerType, - model.StructOrUnionOrEnum, - model.FunctionPtrType)) - if self._typesdict[tp1] is None: - self._typesdict[tp1] = len(self.cffi_types) - self.cffi_types.append(tp1) # placeholder - self.cffi_types.append('END') # placeholder - # - # prepare all OTHER bytecode sequences - for tp in all_decls: - if not tp.is_raw_function and self._typesdict[tp] is None: - self._typesdict[tp] = len(self.cffi_types) - self.cffi_types.append(tp) # placeholder - if tp.is_array_type and tp.length is not None: - self.cffi_types.append('LEN') # placeholder - assert None not in self._typesdict.values() - # - # collect all structs and unions and enums - self._struct_unions = {} - self._enums = {} - for tp in all_decls: - if isinstance(tp, model.StructOrUnion): - self._struct_unions[tp] = None - elif isinstance(tp, model.EnumType): - self._enums[tp] = None - for i, tp in enumerate(sorted(self._struct_unions, - key=lambda tp: tp.name)): - self._struct_unions[tp] = i - for i, tp in enumerate(sorted(self._enums, - key=lambda tp: tp.name)): - self._enums[tp] = i - # - # emit all bytecode sequences now - for tp in all_decls: - method = getattr(self, '_emit_bytecode_' + tp.__class__.__name__) - method(tp, self._typesdict[tp]) - # - # consistency check - for op in self.cffi_types: - assert isinstance(op, CffiOp) - self.cffi_types = tuple(self.cffi_types) # don't change any more - - def _enum_fields(self, tp): - # When producing C, expand all anonymous struct/union fields. - # That's necessary to have C code checking the offsets of the - # individual fields contained in them. When producing Python, - # don't do it and instead write it like it is, with the - # corresponding fields having an empty name. Empty names are - # recognized at runtime when we import the generated Python - # file. - expand_anonymous_struct_union = not self.target_is_python - return tp.enumfields(expand_anonymous_struct_union) - - def _do_collect_type(self, tp): - if not isinstance(tp, model.BaseTypeByIdentity): - if isinstance(tp, tuple): - for x in tp: - self._do_collect_type(x) - return - if tp not in self._typesdict: - self._typesdict[tp] = None - if isinstance(tp, model.FunctionPtrType): - self._do_collect_type(tp.as_raw_function()) - elif isinstance(tp, model.StructOrUnion): - if tp.fldtypes is not None and ( - tp not in self.ffi._parser._included_declarations): - for name1, tp1, _, _ in self._enum_fields(tp): - self._do_collect_type(self._field_type(tp, name1, tp1)) - else: - for _, x in tp._get_items(): - self._do_collect_type(x) - - def _generate(self, step_name): - lst = self.ffi._parser._declarations.items() - for name, (tp, quals) in sorted(lst): - kind, realname = name.split(' ', 1) - try: - method = getattr(self, '_generate_cpy_%s_%s' % (kind, - step_name)) - except AttributeError: - raise VerificationError( - "not implemented in recompile(): %r" % name) - try: - self._current_quals = quals - method(tp, realname) - except Exception as e: - model.attach_exception_info(e, name) - raise - - # ---------- - - ALL_STEPS = ["global", "field", "struct_union", "enum", "typename"] - - def collect_step_tables(self): - # collect the declarations for '_cffi_globals', '_cffi_typenames', etc. - self._lsts = {} - for step_name in self.ALL_STEPS: - self._lsts[step_name] = [] - self._seen_struct_unions = set() - self._generate("ctx") - self._add_missing_struct_unions() - # - for step_name in self.ALL_STEPS: - lst = self._lsts[step_name] - if step_name != "field": - lst.sort(key=lambda entry: entry.name) - self._lsts[step_name] = tuple(lst) # don't change any more - # - # check for a possible internal inconsistency: _cffi_struct_unions - # should have been generated with exactly self._struct_unions - lst = self._lsts["struct_union"] - for tp, i in self._struct_unions.items(): - assert i < len(lst) - assert lst[i].name == tp.name - assert len(lst) == len(self._struct_unions) - # same with enums - lst = self._lsts["enum"] - for tp, i in self._enums.items(): - assert i < len(lst) - assert lst[i].name == tp.name - assert len(lst) == len(self._enums) - - # ---------- - - def _prnt(self, what=''): - self._f.write(what + '\n') - - def write_source_to_f(self, f, preamble): - if self.target_is_python: - assert preamble is None - self.write_py_source_to_f(f) - else: - assert preamble is not None - self.write_c_source_to_f(f, preamble) - - def _rel_readlines(self, filename): - g = open(os.path.join(os.path.dirname(__file__), filename), 'r') - lines = g.readlines() - g.close() - return lines - - def write_c_source_to_f(self, f, preamble): - self._f = f - prnt = self._prnt - if self.ffi._embedding is not None: - prnt('#define _CFFI_USE_EMBEDDING') - if not USE_LIMITED_API: - prnt('#define _CFFI_NO_LIMITED_API') - # - # first the '#include' (actually done by inlining the file's content) - lines = self._rel_readlines('_cffi_include.h') - i = lines.index('#include "parse_c_type.h"\n') - lines[i:i+1] = self._rel_readlines('parse_c_type.h') - prnt(''.join(lines)) - # - # if we have ffi._embedding != None, we give it here as a macro - # and include an extra file - base_module_name = self.module_name.split('.')[-1] - if self.ffi._embedding is not None: - prnt('#define _CFFI_MODULE_NAME "%s"' % (self.module_name,)) - prnt('static const char _CFFI_PYTHON_STARTUP_CODE[] = {') - self._print_string_literal_in_array(self.ffi._embedding) - prnt('0 };') - prnt('#ifdef PYPY_VERSION') - prnt('# define _CFFI_PYTHON_STARTUP_FUNC _cffi_pypyinit_%s' % ( - base_module_name,)) - prnt('#elif PY_MAJOR_VERSION >= 3') - prnt('# define _CFFI_PYTHON_STARTUP_FUNC PyInit_%s' % ( - base_module_name,)) - prnt('#else') - prnt('# define _CFFI_PYTHON_STARTUP_FUNC init%s' % ( - base_module_name,)) - prnt('#endif') - lines = self._rel_readlines('_embedding.h') - i = lines.index('#include "_cffi_errors.h"\n') - lines[i:i+1] = self._rel_readlines('_cffi_errors.h') - prnt(''.join(lines)) - self.needs_version(VERSION_EMBEDDED) - # - # then paste the C source given by the user, verbatim. - prnt('/************************************************************/') - prnt() - prnt(preamble) - prnt() - prnt('/************************************************************/') - prnt() - # - # the declaration of '_cffi_types' - prnt('static void *_cffi_types[] = {') - typeindex2type = dict([(i, tp) for (tp, i) in self._typesdict.items()]) - for i, op in enumerate(self.cffi_types): - comment = '' - if i in typeindex2type: - comment = ' // ' + typeindex2type[i]._get_c_name() - prnt('/* %2d */ %s,%s' % (i, op.as_c_expr(), comment)) - if not self.cffi_types: - prnt(' 0') - prnt('};') - prnt() - # - # call generate_cpy_xxx_decl(), for every xxx found from - # ffi._parser._declarations. This generates all the functions. - self._seen_constants = set() - self._generate("decl") - # - # the declaration of '_cffi_globals' and '_cffi_typenames' - nums = {} - for step_name in self.ALL_STEPS: - lst = self._lsts[step_name] - nums[step_name] = len(lst) - if nums[step_name] > 0: - prnt('static const struct _cffi_%s_s _cffi_%ss[] = {' % ( - step_name, step_name)) - for entry in lst: - prnt(entry.as_c_expr()) - prnt('};') - prnt() - # - # the declaration of '_cffi_includes' - if self.ffi._included_ffis: - prnt('static const char * const _cffi_includes[] = {') - for ffi_to_include in self.ffi._included_ffis: - try: - included_module_name, included_source = ( - ffi_to_include._assigned_source[:2]) - except AttributeError: - raise VerificationError( - "ffi object %r includes %r, but the latter has not " - "been prepared with set_source()" % ( - self.ffi, ffi_to_include,)) - if included_source is None: - raise VerificationError( - "not implemented yet: ffi.include() of a Python-based " - "ffi inside a C-based ffi") - prnt(' "%s",' % (included_module_name,)) - prnt(' NULL') - prnt('};') - prnt() - # - # the declaration of '_cffi_type_context' - prnt('static const struct _cffi_type_context_s _cffi_type_context = {') - prnt(' _cffi_types,') - for step_name in self.ALL_STEPS: - if nums[step_name] > 0: - prnt(' _cffi_%ss,' % step_name) - else: - prnt(' NULL, /* no %ss */' % step_name) - for step_name in self.ALL_STEPS: - if step_name != "field": - prnt(' %d, /* num_%ss */' % (nums[step_name], step_name)) - if self.ffi._included_ffis: - prnt(' _cffi_includes,') - else: - prnt(' NULL, /* no includes */') - prnt(' %d, /* num_types */' % (len(self.cffi_types),)) - flags = 0 - if self._num_externpy > 0 or self.ffi._embedding is not None: - flags |= 1 # set to mean that we use extern "Python" - prnt(' %d, /* flags */' % flags) - prnt('};') - prnt() - # - # the init function - prnt('#ifdef __GNUC__') - prnt('# pragma GCC visibility push(default) /* for -fvisibility= */') - prnt('#endif') - prnt() - prnt('#ifdef PYPY_VERSION') - prnt('PyMODINIT_FUNC') - prnt('_cffi_pypyinit_%s(const void *p[])' % (base_module_name,)) - prnt('{') - if flags & 1: - prnt(' if (((intptr_t)p[0]) >= 0x0A03) {') - prnt(' _cffi_call_python_org = ' - '(void(*)(struct _cffi_externpy_s *, char *))p[1];') - prnt(' }') - prnt(' p[0] = (const void *)0x%x;' % self._version) - prnt(' p[1] = &_cffi_type_context;') - prnt('#if PY_MAJOR_VERSION >= 3') - prnt(' return NULL;') - prnt('#endif') - prnt('}') - # on Windows, distutils insists on putting init_cffi_xyz in - # 'export_symbols', so instead of fighting it, just give up and - # give it one - prnt('# ifdef _MSC_VER') - prnt(' PyMODINIT_FUNC') - prnt('# if PY_MAJOR_VERSION >= 3') - prnt(' PyInit_%s(void) { return NULL; }' % (base_module_name,)) - prnt('# else') - prnt(' init%s(void) { }' % (base_module_name,)) - prnt('# endif') - prnt('# endif') - prnt('#elif PY_MAJOR_VERSION >= 3') - prnt('PyMODINIT_FUNC') - prnt('PyInit_%s(void)' % (base_module_name,)) - prnt('{') - prnt(' return _cffi_init("%s", 0x%x, &_cffi_type_context);' % ( - self.module_name, self._version)) - prnt('}') - prnt('#else') - prnt('PyMODINIT_FUNC') - prnt('init%s(void)' % (base_module_name,)) - prnt('{') - prnt(' _cffi_init("%s", 0x%x, &_cffi_type_context);' % ( - self.module_name, self._version)) - prnt('}') - prnt('#endif') - prnt() - prnt('#ifdef __GNUC__') - prnt('# pragma GCC visibility pop') - prnt('#endif') - self._version = None - - def _to_py(self, x): - if isinstance(x, str): - return "b'%s'" % (x,) - if isinstance(x, (list, tuple)): - rep = [self._to_py(item) for item in x] - if len(rep) == 1: - rep.append('') - return "(%s)" % (','.join(rep),) - return x.as_python_expr() # Py2: unicode unexpected; Py3: bytes unexp. - - def write_py_source_to_f(self, f): - self._f = f - prnt = self._prnt - # - # header - prnt("# auto-generated file") - prnt("import _cffi_backend") - # - # the 'import' of the included ffis - num_includes = len(self.ffi._included_ffis or ()) - for i in range(num_includes): - ffi_to_include = self.ffi._included_ffis[i] - try: - included_module_name, included_source = ( - ffi_to_include._assigned_source[:2]) - except AttributeError: - raise VerificationError( - "ffi object %r includes %r, but the latter has not " - "been prepared with set_source()" % ( - self.ffi, ffi_to_include,)) - if included_source is not None: - raise VerificationError( - "not implemented yet: ffi.include() of a C-based " - "ffi inside a Python-based ffi") - prnt('from %s import ffi as _ffi%d' % (included_module_name, i)) - prnt() - prnt("ffi = _cffi_backend.FFI('%s'," % (self.module_name,)) - prnt(" _version = 0x%x," % (self._version,)) - self._version = None - # - # the '_types' keyword argument - self.cffi_types = tuple(self.cffi_types) # don't change any more - types_lst = [op.as_python_bytes() for op in self.cffi_types] - prnt(' _types = %s,' % (self._to_py(''.join(types_lst)),)) - typeindex2type = dict([(i, tp) for (tp, i) in self._typesdict.items()]) - # - # the keyword arguments from ALL_STEPS - for step_name in self.ALL_STEPS: - lst = self._lsts[step_name] - if len(lst) > 0 and step_name != "field": - prnt(' _%ss = %s,' % (step_name, self._to_py(lst))) - # - # the '_includes' keyword argument - if num_includes > 0: - prnt(' _includes = (%s,),' % ( - ', '.join(['_ffi%d' % i for i in range(num_includes)]),)) - # - # the footer - prnt(')') - - # ---------- - - def _gettypenum(self, type): - # a KeyError here is a bug. please report it! :-) - return self._typesdict[type] - - def _convert_funcarg_to_c(self, tp, fromvar, tovar, errcode): - extraarg = '' - if isinstance(tp, model.BasePrimitiveType) and not tp.is_complex_type(): - if tp.is_integer_type() and tp.name != '_Bool': - converter = '_cffi_to_c_int' - extraarg = ', %s' % tp.name - elif isinstance(tp, model.UnknownFloatType): - # don't check with is_float_type(): it may be a 'long - # double' here, and _cffi_to_c_double would loose precision - converter = '(%s)_cffi_to_c_double' % (tp.get_c_name(''),) - else: - cname = tp.get_c_name('') - converter = '(%s)_cffi_to_c_%s' % (cname, - tp.name.replace(' ', '_')) - if cname in ('char16_t', 'char32_t'): - self.needs_version(VERSION_CHAR16CHAR32) - errvalue = '-1' - # - elif isinstance(tp, model.PointerType): - self._convert_funcarg_to_c_ptr_or_array(tp, fromvar, - tovar, errcode) - return - # - elif (isinstance(tp, model.StructOrUnionOrEnum) or - isinstance(tp, model.BasePrimitiveType)): - # a struct (not a struct pointer) as a function argument; - # or, a complex (the same code works) - self._prnt(' if (_cffi_to_c((char *)&%s, _cffi_type(%d), %s) < 0)' - % (tovar, self._gettypenum(tp), fromvar)) - self._prnt(' %s;' % errcode) - return - # - elif isinstance(tp, model.FunctionPtrType): - converter = '(%s)_cffi_to_c_pointer' % tp.get_c_name('') - extraarg = ', _cffi_type(%d)' % self._gettypenum(tp) - errvalue = 'NULL' - # - else: - raise NotImplementedError(tp) - # - self._prnt(' %s = %s(%s%s);' % (tovar, converter, fromvar, extraarg)) - self._prnt(' if (%s == (%s)%s && PyErr_Occurred())' % ( - tovar, tp.get_c_name(''), errvalue)) - self._prnt(' %s;' % errcode) - - def _extra_local_variables(self, tp, localvars, freelines): - if isinstance(tp, model.PointerType): - localvars.add('Py_ssize_t datasize') - localvars.add('struct _cffi_freeme_s *large_args_free = NULL') - freelines.add('if (large_args_free != NULL)' - ' _cffi_free_array_arguments(large_args_free);') - - def _convert_funcarg_to_c_ptr_or_array(self, tp, fromvar, tovar, errcode): - self._prnt(' datasize = _cffi_prepare_pointer_call_argument(') - self._prnt(' _cffi_type(%d), %s, (char **)&%s);' % ( - self._gettypenum(tp), fromvar, tovar)) - self._prnt(' if (datasize != 0) {') - self._prnt(' %s = ((size_t)datasize) <= 640 ? ' - '(%s)alloca((size_t)datasize) : NULL;' % ( - tovar, tp.get_c_name(''))) - self._prnt(' if (_cffi_convert_array_argument(_cffi_type(%d), %s, ' - '(char **)&%s,' % (self._gettypenum(tp), fromvar, tovar)) - self._prnt(' datasize, &large_args_free) < 0)') - self._prnt(' %s;' % errcode) - self._prnt(' }') - - def _convert_expr_from_c(self, tp, var, context): - if isinstance(tp, model.BasePrimitiveType): - if tp.is_integer_type() and tp.name != '_Bool': - return '_cffi_from_c_int(%s, %s)' % (var, tp.name) - elif isinstance(tp, model.UnknownFloatType): - return '_cffi_from_c_double(%s)' % (var,) - elif tp.name != 'long double' and not tp.is_complex_type(): - cname = tp.name.replace(' ', '_') - if cname in ('char16_t', 'char32_t'): - self.needs_version(VERSION_CHAR16CHAR32) - return '_cffi_from_c_%s(%s)' % (cname, var) - else: - return '_cffi_from_c_deref((char *)&%s, _cffi_type(%d))' % ( - var, self._gettypenum(tp)) - elif isinstance(tp, (model.PointerType, model.FunctionPtrType)): - return '_cffi_from_c_pointer((char *)%s, _cffi_type(%d))' % ( - var, self._gettypenum(tp)) - elif isinstance(tp, model.ArrayType): - return '_cffi_from_c_pointer((char *)%s, _cffi_type(%d))' % ( - var, self._gettypenum(model.PointerType(tp.item))) - elif isinstance(tp, model.StructOrUnion): - if tp.fldnames is None: - raise TypeError("'%s' is used as %s, but is opaque" % ( - tp._get_c_name(), context)) - return '_cffi_from_c_struct((char *)&%s, _cffi_type(%d))' % ( - var, self._gettypenum(tp)) - elif isinstance(tp, model.EnumType): - return '_cffi_from_c_deref((char *)&%s, _cffi_type(%d))' % ( - var, self._gettypenum(tp)) - else: - raise NotImplementedError(tp) - - # ---------- - # typedefs - - def _typedef_type(self, tp, name): - return self._global_type(tp, "(*(%s *)0)" % (name,)) - - def _generate_cpy_typedef_collecttype(self, tp, name): - self._do_collect_type(self._typedef_type(tp, name)) - - def _generate_cpy_typedef_decl(self, tp, name): - pass - - def _typedef_ctx(self, tp, name): - type_index = self._typesdict[tp] - self._lsts["typename"].append(TypenameExpr(name, type_index)) - - def _generate_cpy_typedef_ctx(self, tp, name): - tp = self._typedef_type(tp, name) - self._typedef_ctx(tp, name) - if getattr(tp, "origin", None) == "unknown_type": - self._struct_ctx(tp, tp.name, approxname=None) - elif isinstance(tp, model.NamedPointerType): - self._struct_ctx(tp.totype, tp.totype.name, approxname=tp.name, - named_ptr=tp) - - # ---------- - # function declarations - - def _generate_cpy_function_collecttype(self, tp, name): - self._do_collect_type(tp.as_raw_function()) - if tp.ellipsis and not self.target_is_python: - self._do_collect_type(tp) - - def _generate_cpy_function_decl(self, tp, name): - assert not self.target_is_python - assert isinstance(tp, model.FunctionPtrType) - if tp.ellipsis: - # cannot support vararg functions better than this: check for its - # exact type (including the fixed arguments), and build it as a - # constant function pointer (no CPython wrapper) - self._generate_cpy_constant_decl(tp, name) - return - prnt = self._prnt - numargs = len(tp.args) - if numargs == 0: - argname = 'noarg' - elif numargs == 1: - argname = 'arg0' - else: - argname = 'args' - # - # ------------------------------ - # the 'd' version of the function, only for addressof(lib, 'func') - arguments = [] - call_arguments = [] - context = 'argument of %s' % name - for i, type in enumerate(tp.args): - arguments.append(type.get_c_name(' x%d' % i, context)) - call_arguments.append('x%d' % i) - repr_arguments = ', '.join(arguments) - repr_arguments = repr_arguments or 'void' - if tp.abi: - abi = tp.abi + ' ' - else: - abi = '' - name_and_arguments = '%s_cffi_d_%s(%s)' % (abi, name, repr_arguments) - prnt('static %s' % (tp.result.get_c_name(name_and_arguments),)) - prnt('{') - call_arguments = ', '.join(call_arguments) - result_code = 'return ' - if isinstance(tp.result, model.VoidType): - result_code = '' - prnt(' %s%s(%s);' % (result_code, name, call_arguments)) - prnt('}') - # - prnt('#ifndef PYPY_VERSION') # ------------------------------ - # - prnt('static PyObject *') - prnt('_cffi_f_%s(PyObject *self, PyObject *%s)' % (name, argname)) - prnt('{') - # - context = 'argument of %s' % name - for i, type in enumerate(tp.args): - arg = type.get_c_name(' x%d' % i, context) - prnt(' %s;' % arg) - # - localvars = set() - freelines = set() - for type in tp.args: - self._extra_local_variables(type, localvars, freelines) - for decl in sorted(localvars): - prnt(' %s;' % (decl,)) - # - if not isinstance(tp.result, model.VoidType): - result_code = 'result = ' - context = 'result of %s' % name - result_decl = ' %s;' % tp.result.get_c_name(' result', context) - prnt(result_decl) - prnt(' PyObject *pyresult;') - else: - result_decl = None - result_code = '' - # - if len(tp.args) > 1: - rng = range(len(tp.args)) - for i in rng: - prnt(' PyObject *arg%d;' % i) - prnt() - prnt(' if (!PyArg_UnpackTuple(args, "%s", %d, %d, %s))' % ( - name, len(rng), len(rng), - ', '.join(['&arg%d' % i for i in rng]))) - prnt(' return NULL;') - prnt() - # - for i, type in enumerate(tp.args): - self._convert_funcarg_to_c(type, 'arg%d' % i, 'x%d' % i, - 'return NULL') - prnt() - # - prnt(' Py_BEGIN_ALLOW_THREADS') - prnt(' _cffi_restore_errno();') - call_arguments = ['x%d' % i for i in range(len(tp.args))] - call_arguments = ', '.join(call_arguments) - prnt(' { %s%s(%s); }' % (result_code, name, call_arguments)) - prnt(' _cffi_save_errno();') - prnt(' Py_END_ALLOW_THREADS') - prnt() - # - prnt(' (void)self; /* unused */') - if numargs == 0: - prnt(' (void)noarg; /* unused */') - if result_code: - prnt(' pyresult = %s;' % - self._convert_expr_from_c(tp.result, 'result', 'result type')) - for freeline in freelines: - prnt(' ' + freeline) - prnt(' return pyresult;') - else: - for freeline in freelines: - prnt(' ' + freeline) - prnt(' Py_INCREF(Py_None);') - prnt(' return Py_None;') - prnt('}') - # - prnt('#else') # ------------------------------ - # - # the PyPy version: need to replace struct/union arguments with - # pointers, and if the result is a struct/union, insert a first - # arg that is a pointer to the result. We also do that for - # complex args and return type. - def need_indirection(type): - return (isinstance(type, model.StructOrUnion) or - (isinstance(type, model.PrimitiveType) and - type.is_complex_type())) - difference = False - arguments = [] - call_arguments = [] - context = 'argument of %s' % name - for i, type in enumerate(tp.args): - indirection = '' - if need_indirection(type): - indirection = '*' - difference = True - arg = type.get_c_name(' %sx%d' % (indirection, i), context) - arguments.append(arg) - call_arguments.append('%sx%d' % (indirection, i)) - tp_result = tp.result - if need_indirection(tp_result): - context = 'result of %s' % name - arg = tp_result.get_c_name(' *result', context) - arguments.insert(0, arg) - tp_result = model.void_type - result_decl = None - result_code = '*result = ' - difference = True - if difference: - repr_arguments = ', '.join(arguments) - repr_arguments = repr_arguments or 'void' - name_and_arguments = '%s_cffi_f_%s(%s)' % (abi, name, - repr_arguments) - prnt('static %s' % (tp_result.get_c_name(name_and_arguments),)) - prnt('{') - if result_decl: - prnt(result_decl) - call_arguments = ', '.join(call_arguments) - prnt(' { %s%s(%s); }' % (result_code, name, call_arguments)) - if result_decl: - prnt(' return result;') - prnt('}') - else: - prnt('# define _cffi_f_%s _cffi_d_%s' % (name, name)) - # - prnt('#endif') # ------------------------------ - prnt() - - def _generate_cpy_function_ctx(self, tp, name): - if tp.ellipsis and not self.target_is_python: - self._generate_cpy_constant_ctx(tp, name) - return - type_index = self._typesdict[tp.as_raw_function()] - numargs = len(tp.args) - if self.target_is_python: - meth_kind = OP_DLOPEN_FUNC - elif numargs == 0: - meth_kind = OP_CPYTHON_BLTN_N # 'METH_NOARGS' - elif numargs == 1: - meth_kind = OP_CPYTHON_BLTN_O # 'METH_O' - else: - meth_kind = OP_CPYTHON_BLTN_V # 'METH_VARARGS' - self._lsts["global"].append( - GlobalExpr(name, '_cffi_f_%s' % name, - CffiOp(meth_kind, type_index), - size='_cffi_d_%s' % name)) - - # ---------- - # named structs or unions - - def _field_type(self, tp_struct, field_name, tp_field): - if isinstance(tp_field, model.ArrayType): - actual_length = tp_field.length - if actual_length == '...': - ptr_struct_name = tp_struct.get_c_name('*') - actual_length = '_cffi_array_len(((%s)0)->%s)' % ( - ptr_struct_name, field_name) - tp_item = self._field_type(tp_struct, '%s[0]' % field_name, - tp_field.item) - tp_field = model.ArrayType(tp_item, actual_length) - return tp_field - - def _struct_collecttype(self, tp): - self._do_collect_type(tp) - if self.target_is_python: - # also requires nested anon struct/unions in ABI mode, recursively - for fldtype in tp.anonymous_struct_fields(): - self._struct_collecttype(fldtype) - - def _struct_decl(self, tp, cname, approxname): - if tp.fldtypes is None: - return - prnt = self._prnt - checkfuncname = '_cffi_checkfld_%s' % (approxname,) - prnt('_CFFI_UNUSED_FN') - prnt('static void %s(%s *p)' % (checkfuncname, cname)) - prnt('{') - prnt(' /* only to generate compile-time warnings or errors */') - prnt(' (void)p;') - for fname, ftype, fbitsize, fqual in self._enum_fields(tp): - try: - if ftype.is_integer_type() or fbitsize >= 0: - # accept all integers, but complain on float or double - if fname != '': - prnt(" (void)((p->%s) | 0); /* check that '%s.%s' is " - "an integer */" % (fname, cname, fname)) - continue - # only accept exactly the type declared, except that '[]' - # is interpreted as a '*' and so will match any array length. - # (It would also match '*', but that's harder to detect...) - while (isinstance(ftype, model.ArrayType) - and (ftype.length is None or ftype.length == '...')): - ftype = ftype.item - fname = fname + '[0]' - prnt(' { %s = &p->%s; (void)tmp; }' % ( - ftype.get_c_name('*tmp', 'field %r'%fname, quals=fqual), - fname)) - except VerificationError as e: - prnt(' /* %s */' % str(e)) # cannot verify it, ignore - prnt('}') - prnt('struct _cffi_align_%s { char x; %s y; };' % (approxname, cname)) - prnt() - - def _struct_ctx(self, tp, cname, approxname, named_ptr=None): - type_index = self._typesdict[tp] - reason_for_not_expanding = None - flags = [] - if isinstance(tp, model.UnionType): - flags.append("_CFFI_F_UNION") - if tp.fldtypes is None: - flags.append("_CFFI_F_OPAQUE") - reason_for_not_expanding = "opaque" - if (tp not in self.ffi._parser._included_declarations and - (named_ptr is None or - named_ptr not in self.ffi._parser._included_declarations)): - if tp.fldtypes is None: - pass # opaque - elif tp.partial or any(tp.anonymous_struct_fields()): - pass # field layout obtained silently from the C compiler - else: - flags.append("_CFFI_F_CHECK_FIELDS") - if tp.packed: - if tp.packed > 1: - raise NotImplementedError( - "%r is declared with 'pack=%r'; only 0 or 1 are " - "supported in API mode (try to use \"...;\", which " - "does not require a 'pack' declaration)" % - (tp, tp.packed)) - flags.append("_CFFI_F_PACKED") - else: - flags.append("_CFFI_F_EXTERNAL") - reason_for_not_expanding = "external" - flags = '|'.join(flags) or '0' - c_fields = [] - if reason_for_not_expanding is None: - enumfields = list(self._enum_fields(tp)) - for fldname, fldtype, fbitsize, fqual in enumfields: - fldtype = self._field_type(tp, fldname, fldtype) - self._check_not_opaque(fldtype, - "field '%s.%s'" % (tp.name, fldname)) - # cname is None for _add_missing_struct_unions() only - op = OP_NOOP - if fbitsize >= 0: - op = OP_BITFIELD - size = '%d /* bits */' % fbitsize - elif cname is None or ( - isinstance(fldtype, model.ArrayType) and - fldtype.length is None): - size = '(size_t)-1' - else: - size = 'sizeof(((%s)0)->%s)' % ( - tp.get_c_name('*') if named_ptr is None - else named_ptr.name, - fldname) - if cname is None or fbitsize >= 0: - offset = '(size_t)-1' - elif named_ptr is not None: - offset = '(size_t)(((char *)&((%s)4096)->%s) - (char *)4096)' % ( - named_ptr.name, fldname) - else: - offset = 'offsetof(%s, %s)' % (tp.get_c_name(''), fldname) - c_fields.append( - FieldExpr(fldname, offset, size, fbitsize, - CffiOp(op, self._typesdict[fldtype]))) - first_field_index = len(self._lsts["field"]) - self._lsts["field"].extend(c_fields) - # - if cname is None: # unknown name, for _add_missing_struct_unions - size = '(size_t)-2' - align = -2 - comment = "unnamed" - else: - if named_ptr is not None: - size = 'sizeof(*(%s)0)' % (named_ptr.name,) - align = '-1 /* unknown alignment */' - else: - size = 'sizeof(%s)' % (cname,) - align = 'offsetof(struct _cffi_align_%s, y)' % (approxname,) - comment = None - else: - size = '(size_t)-1' - align = -1 - first_field_index = -1 - comment = reason_for_not_expanding - self._lsts["struct_union"].append( - StructUnionExpr(tp.name, type_index, flags, size, align, comment, - first_field_index, c_fields)) - self._seen_struct_unions.add(tp) - - def _check_not_opaque(self, tp, location): - while isinstance(tp, model.ArrayType): - tp = tp.item - if isinstance(tp, model.StructOrUnion) and tp.fldtypes is None: - raise TypeError( - "%s is of an opaque type (not declared in cdef())" % location) - - def _add_missing_struct_unions(self): - # not very nice, but some struct declarations might be missing - # because they don't have any known C name. Check that they are - # not partial (we can't complete or verify them!) and emit them - # anonymously. - lst = list(self._struct_unions.items()) - lst.sort(key=lambda tp_order: tp_order[1]) - for tp, order in lst: - if tp not in self._seen_struct_unions: - if tp.partial: - raise NotImplementedError("internal inconsistency: %r is " - "partial but was not seen at " - "this point" % (tp,)) - if tp.name.startswith('$') and tp.name[1:].isdigit(): - approxname = tp.name[1:] - elif tp.name == '_IO_FILE' and tp.forcename == 'FILE': - approxname = 'FILE' - self._typedef_ctx(tp, 'FILE') - else: - raise NotImplementedError("internal inconsistency: %r" % - (tp,)) - self._struct_ctx(tp, None, approxname) - - def _generate_cpy_struct_collecttype(self, tp, name): - self._struct_collecttype(tp) - _generate_cpy_union_collecttype = _generate_cpy_struct_collecttype - - def _struct_names(self, tp): - cname = tp.get_c_name('') - if ' ' in cname: - return cname, cname.replace(' ', '_') - else: - return cname, '_' + cname - - def _generate_cpy_struct_decl(self, tp, name): - self._struct_decl(tp, *self._struct_names(tp)) - _generate_cpy_union_decl = _generate_cpy_struct_decl - - def _generate_cpy_struct_ctx(self, tp, name): - self._struct_ctx(tp, *self._struct_names(tp)) - _generate_cpy_union_ctx = _generate_cpy_struct_ctx - - # ---------- - # 'anonymous' declarations. These are produced for anonymous structs - # or unions; the 'name' is obtained by a typedef. - - def _generate_cpy_anonymous_collecttype(self, tp, name): - if isinstance(tp, model.EnumType): - self._generate_cpy_enum_collecttype(tp, name) - else: - self._struct_collecttype(tp) - - def _generate_cpy_anonymous_decl(self, tp, name): - if isinstance(tp, model.EnumType): - self._generate_cpy_enum_decl(tp) - else: - self._struct_decl(tp, name, 'typedef_' + name) - - def _generate_cpy_anonymous_ctx(self, tp, name): - if isinstance(tp, model.EnumType): - self._enum_ctx(tp, name) - else: - self._struct_ctx(tp, name, 'typedef_' + name) - - # ---------- - # constants, declared with "static const ..." - - def _generate_cpy_const(self, is_int, name, tp=None, category='const', - check_value=None): - if (category, name) in self._seen_constants: - raise VerificationError( - "duplicate declaration of %s '%s'" % (category, name)) - self._seen_constants.add((category, name)) - # - prnt = self._prnt - funcname = '_cffi_%s_%s' % (category, name) - if is_int: - prnt('static int %s(unsigned long long *o)' % funcname) - prnt('{') - prnt(' int n = (%s) <= 0;' % (name,)) - prnt(' *o = (unsigned long long)((%s) | 0);' - ' /* check that %s is an integer */' % (name, name)) - if check_value is not None: - if check_value > 0: - check_value = '%dU' % (check_value,) - prnt(' if (!_cffi_check_int(*o, n, %s))' % (check_value,)) - prnt(' n |= 2;') - prnt(' return n;') - prnt('}') - else: - assert check_value is None - prnt('static void %s(char *o)' % funcname) - prnt('{') - prnt(' *(%s)o = %s;' % (tp.get_c_name('*'), name)) - prnt('}') - prnt() - - def _generate_cpy_constant_collecttype(self, tp, name): - is_int = tp.is_integer_type() - if not is_int or self.target_is_python: - self._do_collect_type(tp) - - def _generate_cpy_constant_decl(self, tp, name): - is_int = tp.is_integer_type() - self._generate_cpy_const(is_int, name, tp) - - def _generate_cpy_constant_ctx(self, tp, name): - if not self.target_is_python and tp.is_integer_type(): - type_op = CffiOp(OP_CONSTANT_INT, -1) - else: - if self.target_is_python: - const_kind = OP_DLOPEN_CONST - else: - const_kind = OP_CONSTANT - type_index = self._typesdict[tp] - type_op = CffiOp(const_kind, type_index) - self._lsts["global"].append( - GlobalExpr(name, '_cffi_const_%s' % name, type_op)) - - # ---------- - # enums - - def _generate_cpy_enum_collecttype(self, tp, name): - self._do_collect_type(tp) - - def _generate_cpy_enum_decl(self, tp, name=None): - for enumerator in tp.enumerators: - self._generate_cpy_const(True, enumerator) - - def _enum_ctx(self, tp, cname): - type_index = self._typesdict[tp] - type_op = CffiOp(OP_ENUM, -1) - if self.target_is_python: - tp.check_not_partial() - for enumerator, enumvalue in zip(tp.enumerators, tp.enumvalues): - self._lsts["global"].append( - GlobalExpr(enumerator, '_cffi_const_%s' % enumerator, type_op, - check_value=enumvalue)) - # - if cname is not None and '$' not in cname and not self.target_is_python: - size = "sizeof(%s)" % cname - signed = "((%s)-1) <= 0" % cname - else: - basetp = tp.build_baseinttype(self.ffi, []) - size = self.ffi.sizeof(basetp) - signed = int(int(self.ffi.cast(basetp, -1)) < 0) - allenums = ",".join(tp.enumerators) - self._lsts["enum"].append( - EnumExpr(tp.name, type_index, size, signed, allenums)) - - def _generate_cpy_enum_ctx(self, tp, name): - self._enum_ctx(tp, tp._get_c_name()) - - # ---------- - # macros: for now only for integers - - def _generate_cpy_macro_collecttype(self, tp, name): - pass - - def _generate_cpy_macro_decl(self, tp, name): - if tp == '...': - check_value = None - else: - check_value = tp # an integer - self._generate_cpy_const(True, name, check_value=check_value) - - def _generate_cpy_macro_ctx(self, tp, name): - if tp == '...': - if self.target_is_python: - raise VerificationError( - "cannot use the syntax '...' in '#define %s ...' when " - "using the ABI mode" % (name,)) - check_value = None - else: - check_value = tp # an integer - type_op = CffiOp(OP_CONSTANT_INT, -1) - self._lsts["global"].append( - GlobalExpr(name, '_cffi_const_%s' % name, type_op, - check_value=check_value)) - - # ---------- - # global variables - - def _global_type(self, tp, global_name): - if isinstance(tp, model.ArrayType): - actual_length = tp.length - if actual_length == '...': - actual_length = '_cffi_array_len(%s)' % (global_name,) - tp_item = self._global_type(tp.item, '%s[0]' % global_name) - tp = model.ArrayType(tp_item, actual_length) - return tp - - def _generate_cpy_variable_collecttype(self, tp, name): - self._do_collect_type(self._global_type(tp, name)) - - def _generate_cpy_variable_decl(self, tp, name): - prnt = self._prnt - tp = self._global_type(tp, name) - if isinstance(tp, model.ArrayType) and tp.length is None: - tp = tp.item - ampersand = '' - else: - ampersand = '&' - # This code assumes that casts from "tp *" to "void *" is a - # no-op, i.e. a function that returns a "tp *" can be called - # as if it returned a "void *". This should be generally true - # on any modern machine. The only exception to that rule (on - # uncommon architectures, and as far as I can tell) might be - # if 'tp' were a function type, but that is not possible here. - # (If 'tp' is a function _pointer_ type, then casts from "fn_t - # **" to "void *" are again no-ops, as far as I can tell.) - decl = '*_cffi_var_%s(void)' % (name,) - prnt('static ' + tp.get_c_name(decl, quals=self._current_quals)) - prnt('{') - prnt(' return %s(%s);' % (ampersand, name)) - prnt('}') - prnt() - - def _generate_cpy_variable_ctx(self, tp, name): - tp = self._global_type(tp, name) - type_index = self._typesdict[tp] - if self.target_is_python: - op = OP_GLOBAL_VAR - else: - op = OP_GLOBAL_VAR_F - self._lsts["global"].append( - GlobalExpr(name, '_cffi_var_%s' % name, CffiOp(op, type_index))) - - # ---------- - # extern "Python" - - def _generate_cpy_extern_python_collecttype(self, tp, name): - assert isinstance(tp, model.FunctionPtrType) - self._do_collect_type(tp) - _generate_cpy_dllexport_python_collecttype = \ - _generate_cpy_extern_python_plus_c_collecttype = \ - _generate_cpy_extern_python_collecttype - - def _extern_python_decl(self, tp, name, tag_and_space): - prnt = self._prnt - if isinstance(tp.result, model.VoidType): - size_of_result = '0' - else: - context = 'result of %s' % name - size_of_result = '(int)sizeof(%s)' % ( - tp.result.get_c_name('', context),) - prnt('static struct _cffi_externpy_s _cffi_externpy__%s =' % name) - prnt(' { "%s.%s", %s, 0, 0 };' % ( - self.module_name, name, size_of_result)) - prnt() - # - arguments = [] - context = 'argument of %s' % name - for i, type in enumerate(tp.args): - arg = type.get_c_name(' a%d' % i, context) - arguments.append(arg) - # - repr_arguments = ', '.join(arguments) - repr_arguments = repr_arguments or 'void' - name_and_arguments = '%s(%s)' % (name, repr_arguments) - if tp.abi == "__stdcall": - name_and_arguments = '_cffi_stdcall ' + name_and_arguments - # - def may_need_128_bits(tp): - return (isinstance(tp, model.PrimitiveType) and - tp.name == 'long double') - # - size_of_a = max(len(tp.args)*8, 8) - if may_need_128_bits(tp.result): - size_of_a = max(size_of_a, 16) - if isinstance(tp.result, model.StructOrUnion): - size_of_a = 'sizeof(%s) > %d ? sizeof(%s) : %d' % ( - tp.result.get_c_name(''), size_of_a, - tp.result.get_c_name(''), size_of_a) - prnt('%s%s' % (tag_and_space, tp.result.get_c_name(name_and_arguments))) - prnt('{') - prnt(' char a[%s];' % size_of_a) - prnt(' char *p = a;') - for i, type in enumerate(tp.args): - arg = 'a%d' % i - if (isinstance(type, model.StructOrUnion) or - may_need_128_bits(type)): - arg = '&' + arg - type = model.PointerType(type) - prnt(' *(%s)(p + %d) = %s;' % (type.get_c_name('*'), i*8, arg)) - prnt(' _cffi_call_python(&_cffi_externpy__%s, p);' % name) - if not isinstance(tp.result, model.VoidType): - prnt(' return *(%s)p;' % (tp.result.get_c_name('*'),)) - prnt('}') - prnt() - self._num_externpy += 1 - - def _generate_cpy_extern_python_decl(self, tp, name): - self._extern_python_decl(tp, name, 'static ') - - def _generate_cpy_dllexport_python_decl(self, tp, name): - self._extern_python_decl(tp, name, 'CFFI_DLLEXPORT ') - - def _generate_cpy_extern_python_plus_c_decl(self, tp, name): - self._extern_python_decl(tp, name, '') - - def _generate_cpy_extern_python_ctx(self, tp, name): - if self.target_is_python: - raise VerificationError( - "cannot use 'extern \"Python\"' in the ABI mode") - if tp.ellipsis: - raise NotImplementedError("a vararg function is extern \"Python\"") - type_index = self._typesdict[tp] - type_op = CffiOp(OP_EXTERN_PYTHON, type_index) - self._lsts["global"].append( - GlobalExpr(name, '&_cffi_externpy__%s' % name, type_op, name)) - - _generate_cpy_dllexport_python_ctx = \ - _generate_cpy_extern_python_plus_c_ctx = \ - _generate_cpy_extern_python_ctx - - def _print_string_literal_in_array(self, s): - prnt = self._prnt - prnt('// # NB. this is not a string because of a size limit in MSVC') - if not isinstance(s, bytes): # unicode - s = s.encode('utf-8') # -> bytes - else: - s.decode('utf-8') # got bytes, check for valid utf-8 - try: - s.decode('ascii') - except UnicodeDecodeError: - s = b'# -*- encoding: utf8 -*-\n' + s - for line in s.splitlines(True): - comment = line - if type('//') is bytes: # python2 - line = map(ord, line) # make a list of integers - else: # python3 - # type(line) is bytes, which enumerates like a list of integers - comment = ascii(comment)[1:-1] - prnt(('// ' + comment).rstrip()) - printed_line = '' - for c in line: - if len(printed_line) >= 76: - prnt(printed_line) - printed_line = '' - printed_line += '%d,' % (c,) - prnt(printed_line) - - # ---------- - # emitting the opcodes for individual types - - def _emit_bytecode_VoidType(self, tp, index): - self.cffi_types[index] = CffiOp(OP_PRIMITIVE, PRIM_VOID) - - def _emit_bytecode_PrimitiveType(self, tp, index): - prim_index = PRIMITIVE_TO_INDEX[tp.name] - self.cffi_types[index] = CffiOp(OP_PRIMITIVE, prim_index) - - def _emit_bytecode_UnknownIntegerType(self, tp, index): - s = ('_cffi_prim_int(sizeof(%s), (\n' - ' ((%s)-1) | 0 /* check that %s is an integer type */\n' - ' ) <= 0)' % (tp.name, tp.name, tp.name)) - self.cffi_types[index] = CffiOp(OP_PRIMITIVE, s) - - def _emit_bytecode_UnknownFloatType(self, tp, index): - s = ('_cffi_prim_float(sizeof(%s) *\n' - ' (((%s)1) / 2) * 2 /* integer => 0, float => 1 */\n' - ' )' % (tp.name, tp.name)) - self.cffi_types[index] = CffiOp(OP_PRIMITIVE, s) - - def _emit_bytecode_RawFunctionType(self, tp, index): - self.cffi_types[index] = CffiOp(OP_FUNCTION, self._typesdict[tp.result]) - index += 1 - for tp1 in tp.args: - realindex = self._typesdict[tp1] - if index != realindex: - if isinstance(tp1, model.PrimitiveType): - self._emit_bytecode_PrimitiveType(tp1, index) - else: - self.cffi_types[index] = CffiOp(OP_NOOP, realindex) - index += 1 - flags = int(tp.ellipsis) - if tp.abi is not None: - if tp.abi == '__stdcall': - flags |= 2 - else: - raise NotImplementedError("abi=%r" % (tp.abi,)) - self.cffi_types[index] = CffiOp(OP_FUNCTION_END, flags) - - def _emit_bytecode_PointerType(self, tp, index): - self.cffi_types[index] = CffiOp(OP_POINTER, self._typesdict[tp.totype]) - - _emit_bytecode_ConstPointerType = _emit_bytecode_PointerType - _emit_bytecode_NamedPointerType = _emit_bytecode_PointerType - - def _emit_bytecode_FunctionPtrType(self, tp, index): - raw = tp.as_raw_function() - self.cffi_types[index] = CffiOp(OP_POINTER, self._typesdict[raw]) - - def _emit_bytecode_ArrayType(self, tp, index): - item_index = self._typesdict[tp.item] - if tp.length is None: - self.cffi_types[index] = CffiOp(OP_OPEN_ARRAY, item_index) - elif tp.length == '...': - raise VerificationError( - "type %s badly placed: the '...' array length can only be " - "used on global arrays or on fields of structures" % ( - str(tp).replace('/*...*/', '...'),)) - else: - assert self.cffi_types[index + 1] == 'LEN' - self.cffi_types[index] = CffiOp(OP_ARRAY, item_index) - self.cffi_types[index + 1] = CffiOp(None, str(tp.length)) - - def _emit_bytecode_StructType(self, tp, index): - struct_index = self._struct_unions[tp] - self.cffi_types[index] = CffiOp(OP_STRUCT_UNION, struct_index) - _emit_bytecode_UnionType = _emit_bytecode_StructType - - def _emit_bytecode_EnumType(self, tp, index): - enum_index = self._enums[tp] - self.cffi_types[index] = CffiOp(OP_ENUM, enum_index) - - -if sys.version_info >= (3,): - NativeIO = io.StringIO -else: - class NativeIO(io.BytesIO): - def write(self, s): - if isinstance(s, unicode): - s = s.encode('ascii') - super(NativeIO, self).write(s) - -def _is_file_like(maybefile): - # compare to xml.etree.ElementTree._get_writer - return hasattr(maybefile, 'write') - -def _make_c_or_py_source(ffi, module_name, preamble, target_file, verbose): - if verbose: - print("generating %s" % (target_file,)) - recompiler = Recompiler(ffi, module_name, - target_is_python=(preamble is None)) - recompiler.collect_type_table() - recompiler.collect_step_tables() - if _is_file_like(target_file): - recompiler.write_source_to_f(target_file, preamble) - return True - f = NativeIO() - recompiler.write_source_to_f(f, preamble) - output = f.getvalue() - try: - with open(target_file, 'r') as f1: - if f1.read(len(output) + 1) != output: - raise IOError - if verbose: - print("(already up-to-date)") - return False # already up-to-date - except IOError: - tmp_file = '%s.~%d' % (target_file, os.getpid()) - with open(tmp_file, 'w') as f1: - f1.write(output) - try: - os.rename(tmp_file, target_file) - except OSError: - os.unlink(target_file) - os.rename(tmp_file, target_file) - return True - -def make_c_source(ffi, module_name, preamble, target_c_file, verbose=False): - assert preamble is not None - return _make_c_or_py_source(ffi, module_name, preamble, target_c_file, - verbose) - -def make_py_source(ffi, module_name, target_py_file, verbose=False): - return _make_c_or_py_source(ffi, module_name, None, target_py_file, - verbose) - -def _modname_to_file(outputdir, modname, extension): - parts = modname.split('.') - try: - os.makedirs(os.path.join(outputdir, *parts[:-1])) - except OSError: - pass - parts[-1] += extension - return os.path.join(outputdir, *parts), parts - - -# Aaargh. Distutils is not tested at all for the purpose of compiling -# DLLs that are not extension modules. Here are some hacks to work -# around that, in the _patch_for_*() functions... - -def _patch_meth(patchlist, cls, name, new_meth): - old = getattr(cls, name) - patchlist.append((cls, name, old)) - setattr(cls, name, new_meth) - return old - -def _unpatch_meths(patchlist): - for cls, name, old_meth in reversed(patchlist): - setattr(cls, name, old_meth) - -def _patch_for_embedding(patchlist): - if sys.platform == 'win32': - # we must not remove the manifest when building for embedding! - # FUTURE: this module was removed in setuptools 74; this is likely dead code and should be removed, - # since the toolchain it supports (VS2005-2008) is also long dead. - from cffi._shimmed_dist_utils import MSVCCompiler - if MSVCCompiler is not None: - _patch_meth(patchlist, MSVCCompiler, '_remove_visual_c_ref', - lambda self, manifest_file: manifest_file) - - if sys.platform == 'darwin': - # we must not make a '-bundle', but a '-dynamiclib' instead - from cffi._shimmed_dist_utils import CCompiler - def my_link_shared_object(self, *args, **kwds): - if '-bundle' in self.linker_so: - self.linker_so = list(self.linker_so) - i = self.linker_so.index('-bundle') - self.linker_so[i] = '-dynamiclib' - return old_link_shared_object(self, *args, **kwds) - old_link_shared_object = _patch_meth(patchlist, CCompiler, - 'link_shared_object', - my_link_shared_object) - -def _patch_for_target(patchlist, target): - from cffi._shimmed_dist_utils import build_ext - # if 'target' is different from '*', we need to patch some internal - # method to just return this 'target' value, instead of having it - # built from module_name - if target.endswith('.*'): - target = target[:-2] - if sys.platform == 'win32': - target += '.dll' - elif sys.platform == 'darwin': - target += '.dylib' - else: - target += '.so' - _patch_meth(patchlist, build_ext, 'get_ext_filename', - lambda self, ext_name: target) - - -def recompile(ffi, module_name, preamble, tmpdir='.', call_c_compiler=True, - c_file=None, source_extension='.c', extradir=None, - compiler_verbose=1, target=None, debug=None, - uses_ffiplatform=True, **kwds): - if not isinstance(module_name, str): - module_name = module_name.encode('ascii') - if ffi._windows_unicode: - ffi._apply_windows_unicode(kwds) - if preamble is not None: - if call_c_compiler and _is_file_like(c_file): - raise TypeError("Writing to file-like objects is not supported " - "with call_c_compiler=True") - embedding = (ffi._embedding is not None) - if embedding: - ffi._apply_embedding_fix(kwds) - if c_file is None: - c_file, parts = _modname_to_file(tmpdir, module_name, - source_extension) - if extradir: - parts = [extradir] + parts - ext_c_file = os.path.join(*parts) - else: - ext_c_file = c_file - # - if target is None: - if embedding: - target = '%s.*' % module_name - else: - target = '*' - # - if uses_ffiplatform: - ext = ffiplatform.get_extension(ext_c_file, module_name, **kwds) - else: - ext = None - updated = make_c_source(ffi, module_name, preamble, c_file, - verbose=compiler_verbose) - if call_c_compiler: - patchlist = [] - cwd = os.getcwd() - try: - if embedding: - _patch_for_embedding(patchlist) - if target != '*': - _patch_for_target(patchlist, target) - if compiler_verbose: - if tmpdir == '.': - msg = 'the current directory is' - else: - msg = 'setting the current directory to' - print('%s %r' % (msg, os.path.abspath(tmpdir))) - os.chdir(tmpdir) - outputfilename = ffiplatform.compile('.', ext, - compiler_verbose, debug) - finally: - os.chdir(cwd) - _unpatch_meths(patchlist) - return outputfilename - else: - return ext, updated - else: - if c_file is None: - c_file, _ = _modname_to_file(tmpdir, module_name, '.py') - updated = make_py_source(ffi, module_name, c_file, - verbose=compiler_verbose) - if call_c_compiler: - return c_file - else: - return None, updated - diff --git a/.venv/lib/python3.12/site-packages/cffi/setuptools_ext.py b/.venv/lib/python3.12/site-packages/cffi/setuptools_ext.py deleted file mode 100644 index 5cdd246..0000000 --- a/.venv/lib/python3.12/site-packages/cffi/setuptools_ext.py +++ /dev/null @@ -1,229 +0,0 @@ -import os -import sys -import sysconfig - -try: - basestring -except NameError: - # Python 3.x - basestring = str - -def error(msg): - from cffi._shimmed_dist_utils import DistutilsSetupError - raise DistutilsSetupError(msg) - - -def execfile(filename, glob): - # We use execfile() (here rewritten for Python 3) instead of - # __import__() to load the build script. The problem with - # a normal import is that in some packages, the intermediate - # __init__.py files may already try to import the file that - # we are generating. - with open(filename) as f: - src = f.read() - src += '\n' # Python 2.6 compatibility - code = compile(src, filename, 'exec') - exec(code, glob, glob) - - -def add_cffi_module(dist, mod_spec): - from cffi.api import FFI - - if not isinstance(mod_spec, basestring): - error("argument to 'cffi_modules=...' must be a str or a list of str," - " not %r" % (type(mod_spec).__name__,)) - mod_spec = str(mod_spec) - try: - build_file_name, ffi_var_name = mod_spec.split(':') - except ValueError: - error("%r must be of the form 'path/build.py:ffi_variable'" % - (mod_spec,)) - if not os.path.exists(build_file_name): - ext = '' - rewritten = build_file_name.replace('.', '/') + '.py' - if os.path.exists(rewritten): - ext = ' (rewrite cffi_modules to [%r])' % ( - rewritten + ':' + ffi_var_name,) - error("%r does not name an existing file%s" % (build_file_name, ext)) - - mod_vars = {'__name__': '__cffi__', '__file__': build_file_name} - execfile(build_file_name, mod_vars) - - try: - ffi = mod_vars[ffi_var_name] - except KeyError: - error("%r: object %r not found in module" % (mod_spec, - ffi_var_name)) - if not isinstance(ffi, FFI): - ffi = ffi() # maybe it's a function instead of directly an ffi - if not isinstance(ffi, FFI): - error("%r is not an FFI instance (got %r)" % (mod_spec, - type(ffi).__name__)) - if not hasattr(ffi, '_assigned_source'): - error("%r: the set_source() method was not called" % (mod_spec,)) - module_name, source, source_extension, kwds = ffi._assigned_source - if ffi._windows_unicode: - kwds = kwds.copy() - ffi._apply_windows_unicode(kwds) - - if source is None: - _add_py_module(dist, ffi, module_name) - else: - _add_c_module(dist, ffi, module_name, source, source_extension, kwds) - -def _set_py_limited_api(Extension, kwds): - """ - Add py_limited_api to kwds if setuptools >= 26 is in use. - Do not alter the setting if it already exists. - Setuptools takes care of ignoring the flag on Python 2 and PyPy. - - CPython itself should ignore the flag in a debugging version - (by not listing .abi3.so in the extensions it supports), but - it doesn't so far, creating troubles. That's why we check - for "not hasattr(sys, 'gettotalrefcount')" (the 2.7 compatible equivalent - of 'd' not in sys.abiflags). (http://bugs.python.org/issue28401) - - On Windows, with CPython <= 3.4, it's better not to use py_limited_api - because virtualenv *still* doesn't copy PYTHON3.DLL on these versions. - Recently (2020) we started shipping only >= 3.5 wheels, though. So - we'll give it another try and set py_limited_api on Windows >= 3.5. - """ - from cffi._shimmed_dist_utils import log - from cffi import recompiler - - if ('py_limited_api' not in kwds and not hasattr(sys, 'gettotalrefcount') - and recompiler.USE_LIMITED_API): - import setuptools - try: - setuptools_major_version = int(setuptools.__version__.partition('.')[0]) - if setuptools_major_version >= 26: - kwds['py_limited_api'] = True - except ValueError: # certain development versions of setuptools - # If we don't know the version number of setuptools, we - # try to set 'py_limited_api' anyway. At worst, we get a - # warning. - kwds['py_limited_api'] = True - - if sysconfig.get_config_var("Py_GIL_DISABLED"): - if kwds.get('py_limited_api'): - log.info("Ignoring py_limited_api=True for free-threaded build.") - - kwds['py_limited_api'] = False - - if kwds.get('py_limited_api') is False: - # avoid setting Py_LIMITED_API if py_limited_api=False - # which _cffi_include.h does unless _CFFI_NO_LIMITED_API is defined - kwds.setdefault("define_macros", []).append(("_CFFI_NO_LIMITED_API", None)) - return kwds - -def _add_c_module(dist, ffi, module_name, source, source_extension, kwds): - # We are a setuptools extension. Need this build_ext for py_limited_api. - from setuptools.command.build_ext import build_ext - from cffi._shimmed_dist_utils import Extension, log, mkpath - from cffi import recompiler - - allsources = ['$PLACEHOLDER'] - allsources.extend(kwds.pop('sources', [])) - kwds = _set_py_limited_api(Extension, kwds) - ext = Extension(name=module_name, sources=allsources, **kwds) - - def make_mod(tmpdir, pre_run=None): - c_file = os.path.join(tmpdir, module_name + source_extension) - log.info("generating cffi module %r" % c_file) - mkpath(tmpdir) - # a setuptools-only, API-only hook: called with the "ext" and "ffi" - # arguments just before we turn the ffi into C code. To use it, - # subclass the 'distutils.command.build_ext.build_ext' class and - # add a method 'def pre_run(self, ext, ffi)'. - if pre_run is not None: - pre_run(ext, ffi) - updated = recompiler.make_c_source(ffi, module_name, source, c_file) - if not updated: - log.info("already up-to-date") - return c_file - - if dist.ext_modules is None: - dist.ext_modules = [] - dist.ext_modules.append(ext) - - base_class = dist.cmdclass.get('build_ext', build_ext) - class build_ext_make_mod(base_class): - def run(self): - if ext.sources[0] == '$PLACEHOLDER': - pre_run = getattr(self, 'pre_run', None) - ext.sources[0] = make_mod(self.build_temp, pre_run) - base_class.run(self) - dist.cmdclass['build_ext'] = build_ext_make_mod - # NB. multiple runs here will create multiple 'build_ext_make_mod' - # classes. Even in this case the 'build_ext' command should be - # run once; but just in case, the logic above does nothing if - # called again. - - -def _add_py_module(dist, ffi, module_name): - from setuptools.command.build_py import build_py - from setuptools.command.build_ext import build_ext - from cffi._shimmed_dist_utils import log, mkpath - from cffi import recompiler - - def generate_mod(py_file): - log.info("generating cffi module %r" % py_file) - mkpath(os.path.dirname(py_file)) - updated = recompiler.make_py_source(ffi, module_name, py_file) - if not updated: - log.info("already up-to-date") - - base_class = dist.cmdclass.get('build_py', build_py) - class build_py_make_mod(base_class): - def run(self): - base_class.run(self) - module_path = module_name.split('.') - module_path[-1] += '.py' - generate_mod(os.path.join(self.build_lib, *module_path)) - def get_source_files(self): - # This is called from 'setup.py sdist' only. Exclude - # the generate .py module in this case. - saved_py_modules = self.py_modules - try: - if saved_py_modules: - self.py_modules = [m for m in saved_py_modules - if m != module_name] - return base_class.get_source_files(self) - finally: - self.py_modules = saved_py_modules - dist.cmdclass['build_py'] = build_py_make_mod - - # distutils and setuptools have no notion I could find of a - # generated python module. If we don't add module_name to - # dist.py_modules, then things mostly work but there are some - # combination of options (--root and --record) that will miss - # the module. So we add it here, which gives a few apparently - # harmless warnings about not finding the file outside the - # build directory. - # Then we need to hack more in get_source_files(); see above. - if dist.py_modules is None: - dist.py_modules = [] - dist.py_modules.append(module_name) - - # the following is only for "build_ext -i" - base_class_2 = dist.cmdclass.get('build_ext', build_ext) - class build_ext_make_mod(base_class_2): - def run(self): - base_class_2.run(self) - if self.inplace: - # from get_ext_fullpath() in distutils/command/build_ext.py - module_path = module_name.split('.') - package = '.'.join(module_path[:-1]) - build_py = self.get_finalized_command('build_py') - package_dir = build_py.get_package_dir(package) - file_name = module_path[-1] + '.py' - generate_mod(os.path.join(package_dir, file_name)) - dist.cmdclass['build_ext'] = build_ext_make_mod - -def cffi_modules(dist, attr, value): - assert attr == 'cffi_modules' - if isinstance(value, basestring): - value = [value] - - for cffi_module in value: - add_cffi_module(dist, cffi_module) diff --git a/.venv/lib/python3.12/site-packages/cffi/vengine_cpy.py b/.venv/lib/python3.12/site-packages/cffi/vengine_cpy.py deleted file mode 100644 index 02e6a47..0000000 --- a/.venv/lib/python3.12/site-packages/cffi/vengine_cpy.py +++ /dev/null @@ -1,1087 +0,0 @@ -# -# DEPRECATED: implementation for ffi.verify() -# -import sys -from . import model -from .error import VerificationError -from . import _imp_emulation as imp - - -class VCPythonEngine(object): - _class_key = 'x' - _gen_python_module = True - - def __init__(self, verifier): - self.verifier = verifier - self.ffi = verifier.ffi - self._struct_pending_verification = {} - self._types_of_builtin_functions = {} - - def patch_extension_kwds(self, kwds): - pass - - def find_module(self, module_name, path, so_suffixes): - try: - f, filename, descr = imp.find_module(module_name, path) - except ImportError: - return None - if f is not None: - f.close() - # Note that after a setuptools installation, there are both .py - # and .so files with the same basename. The code here relies on - # imp.find_module() locating the .so in priority. - if descr[0] not in so_suffixes: - return None - return filename - - def collect_types(self): - self._typesdict = {} - self._generate("collecttype") - - def _prnt(self, what=''): - self._f.write(what + '\n') - - def _gettypenum(self, type): - # a KeyError here is a bug. please report it! :-) - return self._typesdict[type] - - def _do_collect_type(self, tp): - if ((not isinstance(tp, model.PrimitiveType) - or tp.name == 'long double') - and tp not in self._typesdict): - num = len(self._typesdict) - self._typesdict[tp] = num - - def write_source_to_f(self): - self.collect_types() - # - # The new module will have a _cffi_setup() function that receives - # objects from the ffi world, and that calls some setup code in - # the module. This setup code is split in several independent - # functions, e.g. one per constant. The functions are "chained" - # by ending in a tail call to each other. - # - # This is further split in two chained lists, depending on if we - # can do it at import-time or if we must wait for _cffi_setup() to - # provide us with the objects. This is needed because we - # need the values of the enum constants in order to build the - # that we may have to pass to _cffi_setup(). - # - # The following two 'chained_list_constants' items contains - # the head of these two chained lists, as a string that gives the - # call to do, if any. - self._chained_list_constants = ['((void)lib,0)', '((void)lib,0)'] - # - prnt = self._prnt - # first paste some standard set of lines that are mostly '#define' - prnt(cffimod_header) - prnt() - # then paste the C source given by the user, verbatim. - prnt(self.verifier.preamble) - prnt() - # - # call generate_cpy_xxx_decl(), for every xxx found from - # ffi._parser._declarations. This generates all the functions. - self._generate("decl") - # - # implement the function _cffi_setup_custom() as calling the - # head of the chained list. - self._generate_setup_custom() - prnt() - # - # produce the method table, including the entries for the - # generated Python->C function wrappers, which are done - # by generate_cpy_function_method(). - prnt('static PyMethodDef _cffi_methods[] = {') - self._generate("method") - prnt(' {"_cffi_setup", _cffi_setup, METH_VARARGS, NULL},') - prnt(' {NULL, NULL, 0, NULL} /* Sentinel */') - prnt('};') - prnt() - # - # standard init. - modname = self.verifier.get_module_name() - constants = self._chained_list_constants[False] - prnt('#if PY_MAJOR_VERSION >= 3') - prnt() - prnt('static struct PyModuleDef _cffi_module_def = {') - prnt(' PyModuleDef_HEAD_INIT,') - prnt(' "%s",' % modname) - prnt(' NULL,') - prnt(' -1,') - prnt(' _cffi_methods,') - prnt(' NULL, NULL, NULL, NULL') - prnt('};') - prnt() - prnt('PyMODINIT_FUNC') - prnt('PyInit_%s(void)' % modname) - prnt('{') - prnt(' PyObject *lib;') - prnt(' lib = PyModule_Create(&_cffi_module_def);') - prnt(' if (lib == NULL)') - prnt(' return NULL;') - prnt(' if (%s < 0 || _cffi_init() < 0) {' % (constants,)) - prnt(' Py_DECREF(lib);') - prnt(' return NULL;') - prnt(' }') - prnt('#if Py_GIL_DISABLED') - prnt(' PyUnstable_Module_SetGIL(lib, Py_MOD_GIL_NOT_USED);') - prnt('#endif') - prnt(' return lib;') - prnt('}') - prnt() - prnt('#else') - prnt() - prnt('PyMODINIT_FUNC') - prnt('init%s(void)' % modname) - prnt('{') - prnt(' PyObject *lib;') - prnt(' lib = Py_InitModule("%s", _cffi_methods);' % modname) - prnt(' if (lib == NULL)') - prnt(' return;') - prnt(' if (%s < 0 || _cffi_init() < 0)' % (constants,)) - prnt(' return;') - prnt(' return;') - prnt('}') - prnt() - prnt('#endif') - - def load_library(self, flags=None): - # XXX review all usages of 'self' here! - # import it as a new extension module - imp.acquire_lock() - try: - if hasattr(sys, "getdlopenflags"): - previous_flags = sys.getdlopenflags() - try: - if hasattr(sys, "setdlopenflags") and flags is not None: - sys.setdlopenflags(flags) - module = imp.load_dynamic(self.verifier.get_module_name(), - self.verifier.modulefilename) - except ImportError as e: - error = "importing %r: %s" % (self.verifier.modulefilename, e) - raise VerificationError(error) - finally: - if hasattr(sys, "setdlopenflags"): - sys.setdlopenflags(previous_flags) - finally: - imp.release_lock() - # - # call loading_cpy_struct() to get the struct layout inferred by - # the C compiler - self._load(module, 'loading') - # - # the C code will need the objects. Collect them in - # order in a list. - revmapping = dict([(value, key) - for (key, value) in self._typesdict.items()]) - lst = [revmapping[i] for i in range(len(revmapping))] - lst = list(map(self.ffi._get_cached_btype, lst)) - # - # build the FFILibrary class and instance and call _cffi_setup(). - # this will set up some fields like '_cffi_types', and only then - # it will invoke the chained list of functions that will really - # build (notably) the constant objects, as if they are - # pointers, and store them as attributes on the 'library' object. - class FFILibrary(object): - _cffi_python_module = module - _cffi_ffi = self.ffi - _cffi_dir = [] - def __dir__(self): - return FFILibrary._cffi_dir + list(self.__dict__) - library = FFILibrary() - if module._cffi_setup(lst, VerificationError, library): - import warnings - warnings.warn("reimporting %r might overwrite older definitions" - % (self.verifier.get_module_name())) - # - # finally, call the loaded_cpy_xxx() functions. This will perform - # the final adjustments, like copying the Python->C wrapper - # functions from the module to the 'library' object, and setting - # up the FFILibrary class with properties for the global C variables. - self._load(module, 'loaded', library=library) - module._cffi_original_ffi = self.ffi - module._cffi_types_of_builtin_funcs = self._types_of_builtin_functions - return library - - def _get_declarations(self): - lst = [(key, tp) for (key, (tp, qual)) in - self.ffi._parser._declarations.items()] - lst.sort() - return lst - - def _generate(self, step_name): - for name, tp in self._get_declarations(): - kind, realname = name.split(' ', 1) - try: - method = getattr(self, '_generate_cpy_%s_%s' % (kind, - step_name)) - except AttributeError: - raise VerificationError( - "not implemented in verify(): %r" % name) - try: - method(tp, realname) - except Exception as e: - model.attach_exception_info(e, name) - raise - - def _load(self, module, step_name, **kwds): - for name, tp in self._get_declarations(): - kind, realname = name.split(' ', 1) - method = getattr(self, '_%s_cpy_%s' % (step_name, kind)) - try: - method(tp, realname, module, **kwds) - except Exception as e: - model.attach_exception_info(e, name) - raise - - def _generate_nothing(self, tp, name): - pass - - def _loaded_noop(self, tp, name, module, **kwds): - pass - - # ---------- - - def _convert_funcarg_to_c(self, tp, fromvar, tovar, errcode): - extraarg = '' - if isinstance(tp, model.PrimitiveType): - if tp.is_integer_type() and tp.name != '_Bool': - converter = '_cffi_to_c_int' - extraarg = ', %s' % tp.name - elif tp.is_complex_type(): - raise VerificationError( - "not implemented in verify(): complex types") - else: - converter = '(%s)_cffi_to_c_%s' % (tp.get_c_name(''), - tp.name.replace(' ', '_')) - errvalue = '-1' - # - elif isinstance(tp, model.PointerType): - self._convert_funcarg_to_c_ptr_or_array(tp, fromvar, - tovar, errcode) - return - # - elif isinstance(tp, (model.StructOrUnion, model.EnumType)): - # a struct (not a struct pointer) as a function argument - self._prnt(' if (_cffi_to_c((char *)&%s, _cffi_type(%d), %s) < 0)' - % (tovar, self._gettypenum(tp), fromvar)) - self._prnt(' %s;' % errcode) - return - # - elif isinstance(tp, model.FunctionPtrType): - converter = '(%s)_cffi_to_c_pointer' % tp.get_c_name('') - extraarg = ', _cffi_type(%d)' % self._gettypenum(tp) - errvalue = 'NULL' - # - else: - raise NotImplementedError(tp) - # - self._prnt(' %s = %s(%s%s);' % (tovar, converter, fromvar, extraarg)) - self._prnt(' if (%s == (%s)%s && PyErr_Occurred())' % ( - tovar, tp.get_c_name(''), errvalue)) - self._prnt(' %s;' % errcode) - - def _extra_local_variables(self, tp, localvars, freelines): - if isinstance(tp, model.PointerType): - localvars.add('Py_ssize_t datasize') - localvars.add('struct _cffi_freeme_s *large_args_free = NULL') - freelines.add('if (large_args_free != NULL)' - ' _cffi_free_array_arguments(large_args_free);') - - def _convert_funcarg_to_c_ptr_or_array(self, tp, fromvar, tovar, errcode): - self._prnt(' datasize = _cffi_prepare_pointer_call_argument(') - self._prnt(' _cffi_type(%d), %s, (char **)&%s);' % ( - self._gettypenum(tp), fromvar, tovar)) - self._prnt(' if (datasize != 0) {') - self._prnt(' %s = ((size_t)datasize) <= 640 ? ' - 'alloca((size_t)datasize) : NULL;' % (tovar,)) - self._prnt(' if (_cffi_convert_array_argument(_cffi_type(%d), %s, ' - '(char **)&%s,' % (self._gettypenum(tp), fromvar, tovar)) - self._prnt(' datasize, &large_args_free) < 0)') - self._prnt(' %s;' % errcode) - self._prnt(' }') - - def _convert_expr_from_c(self, tp, var, context): - if isinstance(tp, model.PrimitiveType): - if tp.is_integer_type() and tp.name != '_Bool': - return '_cffi_from_c_int(%s, %s)' % (var, tp.name) - elif tp.name != 'long double': - return '_cffi_from_c_%s(%s)' % (tp.name.replace(' ', '_'), var) - else: - return '_cffi_from_c_deref((char *)&%s, _cffi_type(%d))' % ( - var, self._gettypenum(tp)) - elif isinstance(tp, (model.PointerType, model.FunctionPtrType)): - return '_cffi_from_c_pointer((char *)%s, _cffi_type(%d))' % ( - var, self._gettypenum(tp)) - elif isinstance(tp, model.ArrayType): - return '_cffi_from_c_pointer((char *)%s, _cffi_type(%d))' % ( - var, self._gettypenum(model.PointerType(tp.item))) - elif isinstance(tp, model.StructOrUnion): - if tp.fldnames is None: - raise TypeError("'%s' is used as %s, but is opaque" % ( - tp._get_c_name(), context)) - return '_cffi_from_c_struct((char *)&%s, _cffi_type(%d))' % ( - var, self._gettypenum(tp)) - elif isinstance(tp, model.EnumType): - return '_cffi_from_c_deref((char *)&%s, _cffi_type(%d))' % ( - var, self._gettypenum(tp)) - else: - raise NotImplementedError(tp) - - # ---------- - # typedefs: generates no code so far - - _generate_cpy_typedef_collecttype = _generate_nothing - _generate_cpy_typedef_decl = _generate_nothing - _generate_cpy_typedef_method = _generate_nothing - _loading_cpy_typedef = _loaded_noop - _loaded_cpy_typedef = _loaded_noop - - # ---------- - # function declarations - - def _generate_cpy_function_collecttype(self, tp, name): - assert isinstance(tp, model.FunctionPtrType) - if tp.ellipsis: - self._do_collect_type(tp) - else: - # don't call _do_collect_type(tp) in this common case, - # otherwise test_autofilled_struct_as_argument fails - for type in tp.args: - self._do_collect_type(type) - self._do_collect_type(tp.result) - - def _generate_cpy_function_decl(self, tp, name): - assert isinstance(tp, model.FunctionPtrType) - if tp.ellipsis: - # cannot support vararg functions better than this: check for its - # exact type (including the fixed arguments), and build it as a - # constant function pointer (no CPython wrapper) - self._generate_cpy_const(False, name, tp) - return - prnt = self._prnt - numargs = len(tp.args) - if numargs == 0: - argname = 'noarg' - elif numargs == 1: - argname = 'arg0' - else: - argname = 'args' - prnt('static PyObject *') - prnt('_cffi_f_%s(PyObject *self, PyObject *%s)' % (name, argname)) - prnt('{') - # - context = 'argument of %s' % name - for i, type in enumerate(tp.args): - prnt(' %s;' % type.get_c_name(' x%d' % i, context)) - # - localvars = set() - freelines = set() - for type in tp.args: - self._extra_local_variables(type, localvars, freelines) - for decl in sorted(localvars): - prnt(' %s;' % (decl,)) - # - if not isinstance(tp.result, model.VoidType): - result_code = 'result = ' - context = 'result of %s' % name - prnt(' %s;' % tp.result.get_c_name(' result', context)) - prnt(' PyObject *pyresult;') - else: - result_code = '' - # - if len(tp.args) > 1: - rng = range(len(tp.args)) - for i in rng: - prnt(' PyObject *arg%d;' % i) - prnt() - prnt(' if (!PyArg_ParseTuple(args, "%s:%s", %s))' % ( - 'O' * numargs, name, ', '.join(['&arg%d' % i for i in rng]))) - prnt(' return NULL;') - prnt() - # - for i, type in enumerate(tp.args): - self._convert_funcarg_to_c(type, 'arg%d' % i, 'x%d' % i, - 'return NULL') - prnt() - # - prnt(' Py_BEGIN_ALLOW_THREADS') - prnt(' _cffi_restore_errno();') - prnt(' { %s%s(%s); }' % ( - result_code, name, - ', '.join(['x%d' % i for i in range(len(tp.args))]))) - prnt(' _cffi_save_errno();') - prnt(' Py_END_ALLOW_THREADS') - prnt() - # - prnt(' (void)self; /* unused */') - if numargs == 0: - prnt(' (void)noarg; /* unused */') - if result_code: - prnt(' pyresult = %s;' % - self._convert_expr_from_c(tp.result, 'result', 'result type')) - for freeline in freelines: - prnt(' ' + freeline) - prnt(' return pyresult;') - else: - for freeline in freelines: - prnt(' ' + freeline) - prnt(' Py_INCREF(Py_None);') - prnt(' return Py_None;') - prnt('}') - prnt() - - def _generate_cpy_function_method(self, tp, name): - if tp.ellipsis: - return - numargs = len(tp.args) - if numargs == 0: - meth = 'METH_NOARGS' - elif numargs == 1: - meth = 'METH_O' - else: - meth = 'METH_VARARGS' - self._prnt(' {"%s", _cffi_f_%s, %s, NULL},' % (name, name, meth)) - - _loading_cpy_function = _loaded_noop - - def _loaded_cpy_function(self, tp, name, module, library): - if tp.ellipsis: - return - func = getattr(module, name) - setattr(library, name, func) - self._types_of_builtin_functions[func] = tp - - # ---------- - # named structs - - _generate_cpy_struct_collecttype = _generate_nothing - def _generate_cpy_struct_decl(self, tp, name): - assert name == tp.name - self._generate_struct_or_union_decl(tp, 'struct', name) - def _generate_cpy_struct_method(self, tp, name): - self._generate_struct_or_union_method(tp, 'struct', name) - def _loading_cpy_struct(self, tp, name, module): - self._loading_struct_or_union(tp, 'struct', name, module) - def _loaded_cpy_struct(self, tp, name, module, **kwds): - self._loaded_struct_or_union(tp) - - _generate_cpy_union_collecttype = _generate_nothing - def _generate_cpy_union_decl(self, tp, name): - assert name == tp.name - self._generate_struct_or_union_decl(tp, 'union', name) - def _generate_cpy_union_method(self, tp, name): - self._generate_struct_or_union_method(tp, 'union', name) - def _loading_cpy_union(self, tp, name, module): - self._loading_struct_or_union(tp, 'union', name, module) - def _loaded_cpy_union(self, tp, name, module, **kwds): - self._loaded_struct_or_union(tp) - - def _generate_struct_or_union_decl(self, tp, prefix, name): - if tp.fldnames is None: - return # nothing to do with opaque structs - checkfuncname = '_cffi_check_%s_%s' % (prefix, name) - layoutfuncname = '_cffi_layout_%s_%s' % (prefix, name) - cname = ('%s %s' % (prefix, name)).strip() - # - prnt = self._prnt - prnt('static void %s(%s *p)' % (checkfuncname, cname)) - prnt('{') - prnt(' /* only to generate compile-time warnings or errors */') - prnt(' (void)p;') - for fname, ftype, fbitsize, fqual in tp.enumfields(): - if (isinstance(ftype, model.PrimitiveType) - and ftype.is_integer_type()) or fbitsize >= 0: - # accept all integers, but complain on float or double - prnt(' (void)((p->%s) << 1);' % fname) - else: - # only accept exactly the type declared. - try: - prnt(' { %s = &p->%s; (void)tmp; }' % ( - ftype.get_c_name('*tmp', 'field %r'%fname, quals=fqual), - fname)) - except VerificationError as e: - prnt(' /* %s */' % str(e)) # cannot verify it, ignore - prnt('}') - prnt('static PyObject *') - prnt('%s(PyObject *self, PyObject *noarg)' % (layoutfuncname,)) - prnt('{') - prnt(' struct _cffi_aligncheck { char x; %s y; };' % cname) - prnt(' static Py_ssize_t nums[] = {') - prnt(' sizeof(%s),' % cname) - prnt(' offsetof(struct _cffi_aligncheck, y),') - for fname, ftype, fbitsize, fqual in tp.enumfields(): - if fbitsize >= 0: - continue # xxx ignore fbitsize for now - prnt(' offsetof(%s, %s),' % (cname, fname)) - if isinstance(ftype, model.ArrayType) and ftype.length is None: - prnt(' 0, /* %s */' % ftype._get_c_name()) - else: - prnt(' sizeof(((%s *)0)->%s),' % (cname, fname)) - prnt(' -1') - prnt(' };') - prnt(' (void)self; /* unused */') - prnt(' (void)noarg; /* unused */') - prnt(' return _cffi_get_struct_layout(nums);') - prnt(' /* the next line is not executed, but compiled */') - prnt(' %s(0);' % (checkfuncname,)) - prnt('}') - prnt() - - def _generate_struct_or_union_method(self, tp, prefix, name): - if tp.fldnames is None: - return # nothing to do with opaque structs - layoutfuncname = '_cffi_layout_%s_%s' % (prefix, name) - self._prnt(' {"%s", %s, METH_NOARGS, NULL},' % (layoutfuncname, - layoutfuncname)) - - def _loading_struct_or_union(self, tp, prefix, name, module): - if tp.fldnames is None: - return # nothing to do with opaque structs - layoutfuncname = '_cffi_layout_%s_%s' % (prefix, name) - # - function = getattr(module, layoutfuncname) - layout = function() - if isinstance(tp, model.StructOrUnion) and tp.partial: - # use the function()'s sizes and offsets to guide the - # layout of the struct - totalsize = layout[0] - totalalignment = layout[1] - fieldofs = layout[2::2] - fieldsize = layout[3::2] - tp.force_flatten() - assert len(fieldofs) == len(fieldsize) == len(tp.fldnames) - tp.fixedlayout = fieldofs, fieldsize, totalsize, totalalignment - else: - cname = ('%s %s' % (prefix, name)).strip() - self._struct_pending_verification[tp] = layout, cname - - def _loaded_struct_or_union(self, tp): - if tp.fldnames is None: - return # nothing to do with opaque structs - self.ffi._get_cached_btype(tp) # force 'fixedlayout' to be considered - - if tp in self._struct_pending_verification: - # check that the layout sizes and offsets match the real ones - def check(realvalue, expectedvalue, msg): - if realvalue != expectedvalue: - raise VerificationError( - "%s (we have %d, but C compiler says %d)" - % (msg, expectedvalue, realvalue)) - ffi = self.ffi - BStruct = ffi._get_cached_btype(tp) - layout, cname = self._struct_pending_verification.pop(tp) - check(layout[0], ffi.sizeof(BStruct), "wrong total size") - check(layout[1], ffi.alignof(BStruct), "wrong total alignment") - i = 2 - for fname, ftype, fbitsize, fqual in tp.enumfields(): - if fbitsize >= 0: - continue # xxx ignore fbitsize for now - check(layout[i], ffi.offsetof(BStruct, fname), - "wrong offset for field %r" % (fname,)) - if layout[i+1] != 0: - BField = ffi._get_cached_btype(ftype) - check(layout[i+1], ffi.sizeof(BField), - "wrong size for field %r" % (fname,)) - i += 2 - assert i == len(layout) - - # ---------- - # 'anonymous' declarations. These are produced for anonymous structs - # or unions; the 'name' is obtained by a typedef. - - _generate_cpy_anonymous_collecttype = _generate_nothing - - def _generate_cpy_anonymous_decl(self, tp, name): - if isinstance(tp, model.EnumType): - self._generate_cpy_enum_decl(tp, name, '') - else: - self._generate_struct_or_union_decl(tp, '', name) - - def _generate_cpy_anonymous_method(self, tp, name): - if not isinstance(tp, model.EnumType): - self._generate_struct_or_union_method(tp, '', name) - - def _loading_cpy_anonymous(self, tp, name, module): - if isinstance(tp, model.EnumType): - self._loading_cpy_enum(tp, name, module) - else: - self._loading_struct_or_union(tp, '', name, module) - - def _loaded_cpy_anonymous(self, tp, name, module, **kwds): - if isinstance(tp, model.EnumType): - self._loaded_cpy_enum(tp, name, module, **kwds) - else: - self._loaded_struct_or_union(tp) - - # ---------- - # constants, likely declared with '#define' - - def _generate_cpy_const(self, is_int, name, tp=None, category='const', - vartp=None, delayed=True, size_too=False, - check_value=None): - prnt = self._prnt - funcname = '_cffi_%s_%s' % (category, name) - prnt('static int %s(PyObject *lib)' % funcname) - prnt('{') - prnt(' PyObject *o;') - prnt(' int res;') - if not is_int: - prnt(' %s;' % (vartp or tp).get_c_name(' i', name)) - else: - assert category == 'const' - # - if check_value is not None: - self._check_int_constant_value(name, check_value) - # - if not is_int: - if category == 'var': - realexpr = '&' + name - else: - realexpr = name - prnt(' i = (%s);' % (realexpr,)) - prnt(' o = %s;' % (self._convert_expr_from_c(tp, 'i', - 'variable type'),)) - assert delayed - else: - prnt(' o = _cffi_from_c_int_const(%s);' % name) - prnt(' if (o == NULL)') - prnt(' return -1;') - if size_too: - prnt(' {') - prnt(' PyObject *o1 = o;') - prnt(' o = Py_BuildValue("On", o1, (Py_ssize_t)sizeof(%s));' - % (name,)) - prnt(' Py_DECREF(o1);') - prnt(' if (o == NULL)') - prnt(' return -1;') - prnt(' }') - prnt(' res = PyObject_SetAttrString(lib, "%s", o);' % name) - prnt(' Py_DECREF(o);') - prnt(' if (res < 0)') - prnt(' return -1;') - prnt(' return %s;' % self._chained_list_constants[delayed]) - self._chained_list_constants[delayed] = funcname + '(lib)' - prnt('}') - prnt() - - def _generate_cpy_constant_collecttype(self, tp, name): - is_int = isinstance(tp, model.PrimitiveType) and tp.is_integer_type() - if not is_int: - self._do_collect_type(tp) - - def _generate_cpy_constant_decl(self, tp, name): - is_int = isinstance(tp, model.PrimitiveType) and tp.is_integer_type() - self._generate_cpy_const(is_int, name, tp) - - _generate_cpy_constant_method = _generate_nothing - _loading_cpy_constant = _loaded_noop - _loaded_cpy_constant = _loaded_noop - - # ---------- - # enums - - def _check_int_constant_value(self, name, value, err_prefix=''): - prnt = self._prnt - if value <= 0: - prnt(' if ((%s) > 0 || (long)(%s) != %dL) {' % ( - name, name, value)) - else: - prnt(' if ((%s) <= 0 || (unsigned long)(%s) != %dUL) {' % ( - name, name, value)) - prnt(' char buf[64];') - prnt(' if ((%s) <= 0)' % name) - prnt(' snprintf(buf, 63, "%%ld", (long)(%s));' % name) - prnt(' else') - prnt(' snprintf(buf, 63, "%%lu", (unsigned long)(%s));' % - name) - prnt(' PyErr_Format(_cffi_VerificationError,') - prnt(' "%s%s has the real value %s, not %s",') - prnt(' "%s", "%s", buf, "%d");' % ( - err_prefix, name, value)) - prnt(' return -1;') - prnt(' }') - - def _enum_funcname(self, prefix, name): - # "$enum_$1" => "___D_enum____D_1" - name = name.replace('$', '___D_') - return '_cffi_e_%s_%s' % (prefix, name) - - def _generate_cpy_enum_decl(self, tp, name, prefix='enum'): - if tp.partial: - for enumerator in tp.enumerators: - self._generate_cpy_const(True, enumerator, delayed=False) - return - # - funcname = self._enum_funcname(prefix, name) - prnt = self._prnt - prnt('static int %s(PyObject *lib)' % funcname) - prnt('{') - for enumerator, enumvalue in zip(tp.enumerators, tp.enumvalues): - self._check_int_constant_value(enumerator, enumvalue, - "enum %s: " % name) - prnt(' return %s;' % self._chained_list_constants[True]) - self._chained_list_constants[True] = funcname + '(lib)' - prnt('}') - prnt() - - _generate_cpy_enum_collecttype = _generate_nothing - _generate_cpy_enum_method = _generate_nothing - - def _loading_cpy_enum(self, tp, name, module): - if tp.partial: - enumvalues = [getattr(module, enumerator) - for enumerator in tp.enumerators] - tp.enumvalues = tuple(enumvalues) - tp.partial_resolved = True - - def _loaded_cpy_enum(self, tp, name, module, library): - for enumerator, enumvalue in zip(tp.enumerators, tp.enumvalues): - setattr(library, enumerator, enumvalue) - - # ---------- - # macros: for now only for integers - - def _generate_cpy_macro_decl(self, tp, name): - if tp == '...': - check_value = None - else: - check_value = tp # an integer - self._generate_cpy_const(True, name, check_value=check_value) - - _generate_cpy_macro_collecttype = _generate_nothing - _generate_cpy_macro_method = _generate_nothing - _loading_cpy_macro = _loaded_noop - _loaded_cpy_macro = _loaded_noop - - # ---------- - # global variables - - def _generate_cpy_variable_collecttype(self, tp, name): - if isinstance(tp, model.ArrayType): - tp_ptr = model.PointerType(tp.item) - else: - tp_ptr = model.PointerType(tp) - self._do_collect_type(tp_ptr) - - def _generate_cpy_variable_decl(self, tp, name): - if isinstance(tp, model.ArrayType): - tp_ptr = model.PointerType(tp.item) - self._generate_cpy_const(False, name, tp, vartp=tp_ptr, - size_too = tp.length_is_unknown()) - else: - tp_ptr = model.PointerType(tp) - self._generate_cpy_const(False, name, tp_ptr, category='var') - - _generate_cpy_variable_method = _generate_nothing - _loading_cpy_variable = _loaded_noop - - def _loaded_cpy_variable(self, tp, name, module, library): - value = getattr(library, name) - if isinstance(tp, model.ArrayType): # int a[5] is "constant" in the - # sense that "a=..." is forbidden - if tp.length_is_unknown(): - assert isinstance(value, tuple) - (value, size) = value - BItemType = self.ffi._get_cached_btype(tp.item) - length, rest = divmod(size, self.ffi.sizeof(BItemType)) - if rest != 0: - raise VerificationError( - "bad size: %r does not seem to be an array of %s" % - (name, tp.item)) - tp = tp.resolve_length(length) - # 'value' is a which we have to replace with - # a if the N is actually known - if tp.length is not None: - BArray = self.ffi._get_cached_btype(tp) - value = self.ffi.cast(BArray, value) - setattr(library, name, value) - return - # remove ptr= from the library instance, and replace - # it by a property on the class, which reads/writes into ptr[0]. - ptr = value - delattr(library, name) - def getter(library): - return ptr[0] - def setter(library, value): - ptr[0] = value - setattr(type(library), name, property(getter, setter)) - type(library)._cffi_dir.append(name) - - # ---------- - - def _generate_setup_custom(self): - prnt = self._prnt - prnt('static int _cffi_setup_custom(PyObject *lib)') - prnt('{') - prnt(' return %s;' % self._chained_list_constants[True]) - prnt('}') - -cffimod_header = r''' -#include -#include - -/* this block of #ifs should be kept exactly identical between - c/_cffi_backend.c, cffi/vengine_cpy.py, cffi/vengine_gen.py - and cffi/_cffi_include.h */ -#if defined(_MSC_VER) -# include /* for alloca() */ -# if _MSC_VER < 1600 /* MSVC < 2010 */ - typedef __int8 int8_t; - typedef __int16 int16_t; - typedef __int32 int32_t; - typedef __int64 int64_t; - typedef unsigned __int8 uint8_t; - typedef unsigned __int16 uint16_t; - typedef unsigned __int32 uint32_t; - typedef unsigned __int64 uint64_t; - typedef __int8 int_least8_t; - typedef __int16 int_least16_t; - typedef __int32 int_least32_t; - typedef __int64 int_least64_t; - typedef unsigned __int8 uint_least8_t; - typedef unsigned __int16 uint_least16_t; - typedef unsigned __int32 uint_least32_t; - typedef unsigned __int64 uint_least64_t; - typedef __int8 int_fast8_t; - typedef __int16 int_fast16_t; - typedef __int32 int_fast32_t; - typedef __int64 int_fast64_t; - typedef unsigned __int8 uint_fast8_t; - typedef unsigned __int16 uint_fast16_t; - typedef unsigned __int32 uint_fast32_t; - typedef unsigned __int64 uint_fast64_t; - typedef __int64 intmax_t; - typedef unsigned __int64 uintmax_t; -# else -# include -# endif -# if _MSC_VER < 1800 /* MSVC < 2013 */ -# ifndef __cplusplus - typedef unsigned char _Bool; -# endif -# endif -# define _cffi_float_complex_t _Fcomplex /* include for it */ -# define _cffi_double_complex_t _Dcomplex /* include for it */ -#else -# include -# if (defined (__SVR4) && defined (__sun)) || defined(_AIX) || defined(__hpux) -# include -# endif -# define _cffi_float_complex_t float _Complex -# define _cffi_double_complex_t double _Complex -#endif - -#if PY_MAJOR_VERSION < 3 -# undef PyCapsule_CheckExact -# undef PyCapsule_GetPointer -# define PyCapsule_CheckExact(capsule) (PyCObject_Check(capsule)) -# define PyCapsule_GetPointer(capsule, name) \ - (PyCObject_AsVoidPtr(capsule)) -#endif - -#if PY_MAJOR_VERSION >= 3 -# define PyInt_FromLong PyLong_FromLong -#endif - -#define _cffi_from_c_double PyFloat_FromDouble -#define _cffi_from_c_float PyFloat_FromDouble -#define _cffi_from_c_long PyInt_FromLong -#define _cffi_from_c_ulong PyLong_FromUnsignedLong -#define _cffi_from_c_longlong PyLong_FromLongLong -#define _cffi_from_c_ulonglong PyLong_FromUnsignedLongLong -#define _cffi_from_c__Bool PyBool_FromLong - -#define _cffi_to_c_double PyFloat_AsDouble -#define _cffi_to_c_float PyFloat_AsDouble - -#define _cffi_from_c_int_const(x) \ - (((x) > 0) ? \ - ((unsigned long long)(x) <= (unsigned long long)LONG_MAX) ? \ - PyInt_FromLong((long)(x)) : \ - PyLong_FromUnsignedLongLong((unsigned long long)(x)) : \ - ((long long)(x) >= (long long)LONG_MIN) ? \ - PyInt_FromLong((long)(x)) : \ - PyLong_FromLongLong((long long)(x))) - -#define _cffi_from_c_int(x, type) \ - (((type)-1) > 0 ? /* unsigned */ \ - (sizeof(type) < sizeof(long) ? \ - PyInt_FromLong((long)x) : \ - sizeof(type) == sizeof(long) ? \ - PyLong_FromUnsignedLong((unsigned long)x) : \ - PyLong_FromUnsignedLongLong((unsigned long long)x)) : \ - (sizeof(type) <= sizeof(long) ? \ - PyInt_FromLong((long)x) : \ - PyLong_FromLongLong((long long)x))) - -#define _cffi_to_c_int(o, type) \ - ((type)( \ - sizeof(type) == 1 ? (((type)-1) > 0 ? (type)_cffi_to_c_u8(o) \ - : (type)_cffi_to_c_i8(o)) : \ - sizeof(type) == 2 ? (((type)-1) > 0 ? (type)_cffi_to_c_u16(o) \ - : (type)_cffi_to_c_i16(o)) : \ - sizeof(type) == 4 ? (((type)-1) > 0 ? (type)_cffi_to_c_u32(o) \ - : (type)_cffi_to_c_i32(o)) : \ - sizeof(type) == 8 ? (((type)-1) > 0 ? (type)_cffi_to_c_u64(o) \ - : (type)_cffi_to_c_i64(o)) : \ - (Py_FatalError("unsupported size for type " #type), (type)0))) - -#define _cffi_to_c_i8 \ - ((int(*)(PyObject *))_cffi_exports[1]) -#define _cffi_to_c_u8 \ - ((int(*)(PyObject *))_cffi_exports[2]) -#define _cffi_to_c_i16 \ - ((int(*)(PyObject *))_cffi_exports[3]) -#define _cffi_to_c_u16 \ - ((int(*)(PyObject *))_cffi_exports[4]) -#define _cffi_to_c_i32 \ - ((int(*)(PyObject *))_cffi_exports[5]) -#define _cffi_to_c_u32 \ - ((unsigned int(*)(PyObject *))_cffi_exports[6]) -#define _cffi_to_c_i64 \ - ((long long(*)(PyObject *))_cffi_exports[7]) -#define _cffi_to_c_u64 \ - ((unsigned long long(*)(PyObject *))_cffi_exports[8]) -#define _cffi_to_c_char \ - ((int(*)(PyObject *))_cffi_exports[9]) -#define _cffi_from_c_pointer \ - ((PyObject *(*)(char *, CTypeDescrObject *))_cffi_exports[10]) -#define _cffi_to_c_pointer \ - ((char *(*)(PyObject *, CTypeDescrObject *))_cffi_exports[11]) -#define _cffi_get_struct_layout \ - ((PyObject *(*)(Py_ssize_t[]))_cffi_exports[12]) -#define _cffi_restore_errno \ - ((void(*)(void))_cffi_exports[13]) -#define _cffi_save_errno \ - ((void(*)(void))_cffi_exports[14]) -#define _cffi_from_c_char \ - ((PyObject *(*)(char))_cffi_exports[15]) -#define _cffi_from_c_deref \ - ((PyObject *(*)(char *, CTypeDescrObject *))_cffi_exports[16]) -#define _cffi_to_c \ - ((int(*)(char *, CTypeDescrObject *, PyObject *))_cffi_exports[17]) -#define _cffi_from_c_struct \ - ((PyObject *(*)(char *, CTypeDescrObject *))_cffi_exports[18]) -#define _cffi_to_c_wchar_t \ - ((wchar_t(*)(PyObject *))_cffi_exports[19]) -#define _cffi_from_c_wchar_t \ - ((PyObject *(*)(wchar_t))_cffi_exports[20]) -#define _cffi_to_c_long_double \ - ((long double(*)(PyObject *))_cffi_exports[21]) -#define _cffi_to_c__Bool \ - ((_Bool(*)(PyObject *))_cffi_exports[22]) -#define _cffi_prepare_pointer_call_argument \ - ((Py_ssize_t(*)(CTypeDescrObject *, PyObject *, char **))_cffi_exports[23]) -#define _cffi_convert_array_from_object \ - ((int(*)(char *, CTypeDescrObject *, PyObject *))_cffi_exports[24]) -#define _CFFI_NUM_EXPORTS 25 - -typedef struct _ctypedescr CTypeDescrObject; - -static void *_cffi_exports[_CFFI_NUM_EXPORTS]; -static PyObject *_cffi_types, *_cffi_VerificationError; - -static int _cffi_setup_custom(PyObject *lib); /* forward */ - -static PyObject *_cffi_setup(PyObject *self, PyObject *args) -{ - PyObject *library; - int was_alive = (_cffi_types != NULL); - (void)self; /* unused */ - if (!PyArg_ParseTuple(args, "OOO", &_cffi_types, &_cffi_VerificationError, - &library)) - return NULL; - Py_INCREF(_cffi_types); - Py_INCREF(_cffi_VerificationError); - if (_cffi_setup_custom(library) < 0) - return NULL; - return PyBool_FromLong(was_alive); -} - -union _cffi_union_alignment_u { - unsigned char m_char; - unsigned short m_short; - unsigned int m_int; - unsigned long m_long; - unsigned long long m_longlong; - float m_float; - double m_double; - long double m_longdouble; -}; - -struct _cffi_freeme_s { - struct _cffi_freeme_s *next; - union _cffi_union_alignment_u alignment; -}; - -#ifdef __GNUC__ - __attribute__((unused)) -#endif -static int _cffi_convert_array_argument(CTypeDescrObject *ctptr, PyObject *arg, - char **output_data, Py_ssize_t datasize, - struct _cffi_freeme_s **freeme) -{ - char *p; - if (datasize < 0) - return -1; - - p = *output_data; - if (p == NULL) { - struct _cffi_freeme_s *fp = (struct _cffi_freeme_s *)PyObject_Malloc( - offsetof(struct _cffi_freeme_s, alignment) + (size_t)datasize); - if (fp == NULL) - return -1; - fp->next = *freeme; - *freeme = fp; - p = *output_data = (char *)&fp->alignment; - } - memset((void *)p, 0, (size_t)datasize); - return _cffi_convert_array_from_object(p, ctptr, arg); -} - -#ifdef __GNUC__ - __attribute__((unused)) -#endif -static void _cffi_free_array_arguments(struct _cffi_freeme_s *freeme) -{ - do { - void *p = (void *)freeme; - freeme = freeme->next; - PyObject_Free(p); - } while (freeme != NULL); -} - -static int _cffi_init(void) -{ - PyObject *module, *c_api_object = NULL; - - module = PyImport_ImportModule("_cffi_backend"); - if (module == NULL) - goto failure; - - c_api_object = PyObject_GetAttrString(module, "_C_API"); - if (c_api_object == NULL) - goto failure; - if (!PyCapsule_CheckExact(c_api_object)) { - PyErr_SetNone(PyExc_ImportError); - goto failure; - } - memcpy(_cffi_exports, PyCapsule_GetPointer(c_api_object, "cffi"), - _CFFI_NUM_EXPORTS * sizeof(void *)); - - Py_DECREF(module); - Py_DECREF(c_api_object); - return 0; - - failure: - Py_XDECREF(module); - Py_XDECREF(c_api_object); - return -1; -} - -#define _cffi_type(num) ((CTypeDescrObject *)PyList_GET_ITEM(_cffi_types, num)) - -/**********/ -''' diff --git a/.venv/lib/python3.12/site-packages/cffi/vengine_gen.py b/.venv/lib/python3.12/site-packages/cffi/vengine_gen.py deleted file mode 100644 index bffc821..0000000 --- a/.venv/lib/python3.12/site-packages/cffi/vengine_gen.py +++ /dev/null @@ -1,679 +0,0 @@ -# -# DEPRECATED: implementation for ffi.verify() -# -import sys, os -import types - -from . import model -from .error import VerificationError - - -class VGenericEngine(object): - _class_key = 'g' - _gen_python_module = False - - def __init__(self, verifier): - self.verifier = verifier - self.ffi = verifier.ffi - self.export_symbols = [] - self._struct_pending_verification = {} - - def patch_extension_kwds(self, kwds): - # add 'export_symbols' to the dictionary. Note that we add the - # list before filling it. When we fill it, it will thus also show - # up in kwds['export_symbols']. - kwds.setdefault('export_symbols', self.export_symbols) - - def find_module(self, module_name, path, so_suffixes): - for so_suffix in so_suffixes: - basename = module_name + so_suffix - if path is None: - path = sys.path - for dirname in path: - filename = os.path.join(dirname, basename) - if os.path.isfile(filename): - return filename - - def collect_types(self): - pass # not needed in the generic engine - - def _prnt(self, what=''): - self._f.write(what + '\n') - - def write_source_to_f(self): - prnt = self._prnt - # first paste some standard set of lines that are mostly '#include' - prnt(cffimod_header) - # then paste the C source given by the user, verbatim. - prnt(self.verifier.preamble) - # - # call generate_gen_xxx_decl(), for every xxx found from - # ffi._parser._declarations. This generates all the functions. - self._generate('decl') - # - # on Windows, distutils insists on putting init_cffi_xyz in - # 'export_symbols', so instead of fighting it, just give up and - # give it one - if sys.platform == 'win32': - if sys.version_info >= (3,): - prefix = 'PyInit_' - else: - prefix = 'init' - modname = self.verifier.get_module_name() - prnt("void %s%s(void) { }\n" % (prefix, modname)) - - def load_library(self, flags=0): - # import it with the CFFI backend - backend = self.ffi._backend - # needs to make a path that contains '/', on Posix - filename = os.path.join(os.curdir, self.verifier.modulefilename) - module = backend.load_library(filename, flags) - # - # call loading_gen_struct() to get the struct layout inferred by - # the C compiler - self._load(module, 'loading') - - # build the FFILibrary class and instance, this is a module subclass - # because modules are expected to have usually-constant-attributes and - # in PyPy this means the JIT is able to treat attributes as constant, - # which we want. - class FFILibrary(types.ModuleType): - _cffi_generic_module = module - _cffi_ffi = self.ffi - _cffi_dir = [] - def __dir__(self): - return FFILibrary._cffi_dir - library = FFILibrary("") - # - # finally, call the loaded_gen_xxx() functions. This will set - # up the 'library' object. - self._load(module, 'loaded', library=library) - return library - - def _get_declarations(self): - lst = [(key, tp) for (key, (tp, qual)) in - self.ffi._parser._declarations.items()] - lst.sort() - return lst - - def _generate(self, step_name): - for name, tp in self._get_declarations(): - kind, realname = name.split(' ', 1) - try: - method = getattr(self, '_generate_gen_%s_%s' % (kind, - step_name)) - except AttributeError: - raise VerificationError( - "not implemented in verify(): %r" % name) - try: - method(tp, realname) - except Exception as e: - model.attach_exception_info(e, name) - raise - - def _load(self, module, step_name, **kwds): - for name, tp in self._get_declarations(): - kind, realname = name.split(' ', 1) - method = getattr(self, '_%s_gen_%s' % (step_name, kind)) - try: - method(tp, realname, module, **kwds) - except Exception as e: - model.attach_exception_info(e, name) - raise - - def _generate_nothing(self, tp, name): - pass - - def _loaded_noop(self, tp, name, module, **kwds): - pass - - # ---------- - # typedefs: generates no code so far - - _generate_gen_typedef_decl = _generate_nothing - _loading_gen_typedef = _loaded_noop - _loaded_gen_typedef = _loaded_noop - - # ---------- - # function declarations - - def _generate_gen_function_decl(self, tp, name): - assert isinstance(tp, model.FunctionPtrType) - if tp.ellipsis: - # cannot support vararg functions better than this: check for its - # exact type (including the fixed arguments), and build it as a - # constant function pointer (no _cffi_f_%s wrapper) - self._generate_gen_const(False, name, tp) - return - prnt = self._prnt - numargs = len(tp.args) - argnames = [] - for i, type in enumerate(tp.args): - indirection = '' - if isinstance(type, model.StructOrUnion): - indirection = '*' - argnames.append('%sx%d' % (indirection, i)) - context = 'argument of %s' % name - arglist = [type.get_c_name(' %s' % arg, context) - for type, arg in zip(tp.args, argnames)] - tpresult = tp.result - if isinstance(tpresult, model.StructOrUnion): - arglist.insert(0, tpresult.get_c_name(' *r', context)) - tpresult = model.void_type - arglist = ', '.join(arglist) or 'void' - wrappername = '_cffi_f_%s' % name - self.export_symbols.append(wrappername) - if tp.abi: - abi = tp.abi + ' ' - else: - abi = '' - funcdecl = ' %s%s(%s)' % (abi, wrappername, arglist) - context = 'result of %s' % name - prnt(tpresult.get_c_name(funcdecl, context)) - prnt('{') - # - if isinstance(tp.result, model.StructOrUnion): - result_code = '*r = ' - elif not isinstance(tp.result, model.VoidType): - result_code = 'return ' - else: - result_code = '' - prnt(' %s%s(%s);' % (result_code, name, ', '.join(argnames))) - prnt('}') - prnt() - - _loading_gen_function = _loaded_noop - - def _loaded_gen_function(self, tp, name, module, library): - assert isinstance(tp, model.FunctionPtrType) - if tp.ellipsis: - newfunction = self._load_constant(False, tp, name, module) - else: - indirections = [] - base_tp = tp - if (any(isinstance(typ, model.StructOrUnion) for typ in tp.args) - or isinstance(tp.result, model.StructOrUnion)): - indirect_args = [] - for i, typ in enumerate(tp.args): - if isinstance(typ, model.StructOrUnion): - typ = model.PointerType(typ) - indirections.append((i, typ)) - indirect_args.append(typ) - indirect_result = tp.result - if isinstance(indirect_result, model.StructOrUnion): - if indirect_result.fldtypes is None: - raise TypeError("'%s' is used as result type, " - "but is opaque" % ( - indirect_result._get_c_name(),)) - indirect_result = model.PointerType(indirect_result) - indirect_args.insert(0, indirect_result) - indirections.insert(0, ("result", indirect_result)) - indirect_result = model.void_type - tp = model.FunctionPtrType(tuple(indirect_args), - indirect_result, tp.ellipsis) - BFunc = self.ffi._get_cached_btype(tp) - wrappername = '_cffi_f_%s' % name - newfunction = module.load_function(BFunc, wrappername) - for i, typ in indirections: - newfunction = self._make_struct_wrapper(newfunction, i, typ, - base_tp) - setattr(library, name, newfunction) - type(library)._cffi_dir.append(name) - - def _make_struct_wrapper(self, oldfunc, i, tp, base_tp): - backend = self.ffi._backend - BType = self.ffi._get_cached_btype(tp) - if i == "result": - ffi = self.ffi - def newfunc(*args): - res = ffi.new(BType) - oldfunc(res, *args) - return res[0] - else: - def newfunc(*args): - args = args[:i] + (backend.newp(BType, args[i]),) + args[i+1:] - return oldfunc(*args) - newfunc._cffi_base_type = base_tp - return newfunc - - # ---------- - # named structs - - def _generate_gen_struct_decl(self, tp, name): - assert name == tp.name - self._generate_struct_or_union_decl(tp, 'struct', name) - - def _loading_gen_struct(self, tp, name, module): - self._loading_struct_or_union(tp, 'struct', name, module) - - def _loaded_gen_struct(self, tp, name, module, **kwds): - self._loaded_struct_or_union(tp) - - def _generate_gen_union_decl(self, tp, name): - assert name == tp.name - self._generate_struct_or_union_decl(tp, 'union', name) - - def _loading_gen_union(self, tp, name, module): - self._loading_struct_or_union(tp, 'union', name, module) - - def _loaded_gen_union(self, tp, name, module, **kwds): - self._loaded_struct_or_union(tp) - - def _generate_struct_or_union_decl(self, tp, prefix, name): - if tp.fldnames is None: - return # nothing to do with opaque structs - checkfuncname = '_cffi_check_%s_%s' % (prefix, name) - layoutfuncname = '_cffi_layout_%s_%s' % (prefix, name) - cname = ('%s %s' % (prefix, name)).strip() - # - prnt = self._prnt - prnt('static void %s(%s *p)' % (checkfuncname, cname)) - prnt('{') - prnt(' /* only to generate compile-time warnings or errors */') - prnt(' (void)p;') - for fname, ftype, fbitsize, fqual in tp.enumfields(): - if (isinstance(ftype, model.PrimitiveType) - and ftype.is_integer_type()) or fbitsize >= 0: - # accept all integers, but complain on float or double - prnt(' (void)((p->%s) << 1);' % fname) - else: - # only accept exactly the type declared. - try: - prnt(' { %s = &p->%s; (void)tmp; }' % ( - ftype.get_c_name('*tmp', 'field %r'%fname, quals=fqual), - fname)) - except VerificationError as e: - prnt(' /* %s */' % str(e)) # cannot verify it, ignore - prnt('}') - self.export_symbols.append(layoutfuncname) - prnt('intptr_t %s(intptr_t i)' % (layoutfuncname,)) - prnt('{') - prnt(' struct _cffi_aligncheck { char x; %s y; };' % cname) - prnt(' static intptr_t nums[] = {') - prnt(' sizeof(%s),' % cname) - prnt(' offsetof(struct _cffi_aligncheck, y),') - for fname, ftype, fbitsize, fqual in tp.enumfields(): - if fbitsize >= 0: - continue # xxx ignore fbitsize for now - prnt(' offsetof(%s, %s),' % (cname, fname)) - if isinstance(ftype, model.ArrayType) and ftype.length is None: - prnt(' 0, /* %s */' % ftype._get_c_name()) - else: - prnt(' sizeof(((%s *)0)->%s),' % (cname, fname)) - prnt(' -1') - prnt(' };') - prnt(' return nums[i];') - prnt(' /* the next line is not executed, but compiled */') - prnt(' %s(0);' % (checkfuncname,)) - prnt('}') - prnt() - - def _loading_struct_or_union(self, tp, prefix, name, module): - if tp.fldnames is None: - return # nothing to do with opaque structs - layoutfuncname = '_cffi_layout_%s_%s' % (prefix, name) - # - BFunc = self.ffi._typeof_locked("intptr_t(*)(intptr_t)")[0] - function = module.load_function(BFunc, layoutfuncname) - layout = [] - num = 0 - while True: - x = function(num) - if x < 0: break - layout.append(x) - num += 1 - if isinstance(tp, model.StructOrUnion) and tp.partial: - # use the function()'s sizes and offsets to guide the - # layout of the struct - totalsize = layout[0] - totalalignment = layout[1] - fieldofs = layout[2::2] - fieldsize = layout[3::2] - tp.force_flatten() - assert len(fieldofs) == len(fieldsize) == len(tp.fldnames) - tp.fixedlayout = fieldofs, fieldsize, totalsize, totalalignment - else: - cname = ('%s %s' % (prefix, name)).strip() - self._struct_pending_verification[tp] = layout, cname - - def _loaded_struct_or_union(self, tp): - if tp.fldnames is None: - return # nothing to do with opaque structs - self.ffi._get_cached_btype(tp) # force 'fixedlayout' to be considered - - if tp in self._struct_pending_verification: - # check that the layout sizes and offsets match the real ones - def check(realvalue, expectedvalue, msg): - if realvalue != expectedvalue: - raise VerificationError( - "%s (we have %d, but C compiler says %d)" - % (msg, expectedvalue, realvalue)) - ffi = self.ffi - BStruct = ffi._get_cached_btype(tp) - layout, cname = self._struct_pending_verification.pop(tp) - check(layout[0], ffi.sizeof(BStruct), "wrong total size") - check(layout[1], ffi.alignof(BStruct), "wrong total alignment") - i = 2 - for fname, ftype, fbitsize, fqual in tp.enumfields(): - if fbitsize >= 0: - continue # xxx ignore fbitsize for now - check(layout[i], ffi.offsetof(BStruct, fname), - "wrong offset for field %r" % (fname,)) - if layout[i+1] != 0: - BField = ffi._get_cached_btype(ftype) - check(layout[i+1], ffi.sizeof(BField), - "wrong size for field %r" % (fname,)) - i += 2 - assert i == len(layout) - - # ---------- - # 'anonymous' declarations. These are produced for anonymous structs - # or unions; the 'name' is obtained by a typedef. - - def _generate_gen_anonymous_decl(self, tp, name): - if isinstance(tp, model.EnumType): - self._generate_gen_enum_decl(tp, name, '') - else: - self._generate_struct_or_union_decl(tp, '', name) - - def _loading_gen_anonymous(self, tp, name, module): - if isinstance(tp, model.EnumType): - self._loading_gen_enum(tp, name, module, '') - else: - self._loading_struct_or_union(tp, '', name, module) - - def _loaded_gen_anonymous(self, tp, name, module, **kwds): - if isinstance(tp, model.EnumType): - self._loaded_gen_enum(tp, name, module, **kwds) - else: - self._loaded_struct_or_union(tp) - - # ---------- - # constants, likely declared with '#define' - - def _generate_gen_const(self, is_int, name, tp=None, category='const', - check_value=None): - prnt = self._prnt - funcname = '_cffi_%s_%s' % (category, name) - self.export_symbols.append(funcname) - if check_value is not None: - assert is_int - assert category == 'const' - prnt('int %s(char *out_error)' % funcname) - prnt('{') - self._check_int_constant_value(name, check_value) - prnt(' return 0;') - prnt('}') - elif is_int: - assert category == 'const' - prnt('int %s(long long *out_value)' % funcname) - prnt('{') - prnt(' *out_value = (long long)(%s);' % (name,)) - prnt(' return (%s) <= 0;' % (name,)) - prnt('}') - else: - assert tp is not None - assert check_value is None - if category == 'var': - ampersand = '&' - else: - ampersand = '' - extra = '' - if category == 'const' and isinstance(tp, model.StructOrUnion): - extra = 'const *' - ampersand = '&' - prnt(tp.get_c_name(' %s%s(void)' % (extra, funcname), name)) - prnt('{') - prnt(' return (%s%s);' % (ampersand, name)) - prnt('}') - prnt() - - def _generate_gen_constant_decl(self, tp, name): - is_int = isinstance(tp, model.PrimitiveType) and tp.is_integer_type() - self._generate_gen_const(is_int, name, tp) - - _loading_gen_constant = _loaded_noop - - def _load_constant(self, is_int, tp, name, module, check_value=None): - funcname = '_cffi_const_%s' % name - if check_value is not None: - assert is_int - self._load_known_int_constant(module, funcname) - value = check_value - elif is_int: - BType = self.ffi._typeof_locked("long long*")[0] - BFunc = self.ffi._typeof_locked("int(*)(long long*)")[0] - function = module.load_function(BFunc, funcname) - p = self.ffi.new(BType) - negative = function(p) - value = int(p[0]) - if value < 0 and not negative: - BLongLong = self.ffi._typeof_locked("long long")[0] - value += (1 << (8*self.ffi.sizeof(BLongLong))) - else: - assert check_value is None - fntypeextra = '(*)(void)' - if isinstance(tp, model.StructOrUnion): - fntypeextra = '*' + fntypeextra - BFunc = self.ffi._typeof_locked(tp.get_c_name(fntypeextra, name))[0] - function = module.load_function(BFunc, funcname) - value = function() - if isinstance(tp, model.StructOrUnion): - value = value[0] - return value - - def _loaded_gen_constant(self, tp, name, module, library): - is_int = isinstance(tp, model.PrimitiveType) and tp.is_integer_type() - value = self._load_constant(is_int, tp, name, module) - setattr(library, name, value) - type(library)._cffi_dir.append(name) - - # ---------- - # enums - - def _check_int_constant_value(self, name, value): - prnt = self._prnt - if value <= 0: - prnt(' if ((%s) > 0 || (long)(%s) != %dL) {' % ( - name, name, value)) - else: - prnt(' if ((%s) <= 0 || (unsigned long)(%s) != %dUL) {' % ( - name, name, value)) - prnt(' char buf[64];') - prnt(' if ((%s) <= 0)' % name) - prnt(' sprintf(buf, "%%ld", (long)(%s));' % name) - prnt(' else') - prnt(' sprintf(buf, "%%lu", (unsigned long)(%s));' % - name) - prnt(' sprintf(out_error, "%s has the real value %s, not %s",') - prnt(' "%s", buf, "%d");' % (name[:100], value)) - prnt(' return -1;') - prnt(' }') - - def _load_known_int_constant(self, module, funcname): - BType = self.ffi._typeof_locked("char[]")[0] - BFunc = self.ffi._typeof_locked("int(*)(char*)")[0] - function = module.load_function(BFunc, funcname) - p = self.ffi.new(BType, 256) - if function(p) < 0: - error = self.ffi.string(p) - if sys.version_info >= (3,): - error = str(error, 'utf-8') - raise VerificationError(error) - - def _enum_funcname(self, prefix, name): - # "$enum_$1" => "___D_enum____D_1" - name = name.replace('$', '___D_') - return '_cffi_e_%s_%s' % (prefix, name) - - def _generate_gen_enum_decl(self, tp, name, prefix='enum'): - if tp.partial: - for enumerator in tp.enumerators: - self._generate_gen_const(True, enumerator) - return - # - funcname = self._enum_funcname(prefix, name) - self.export_symbols.append(funcname) - prnt = self._prnt - prnt('int %s(char *out_error)' % funcname) - prnt('{') - for enumerator, enumvalue in zip(tp.enumerators, tp.enumvalues): - self._check_int_constant_value(enumerator, enumvalue) - prnt(' return 0;') - prnt('}') - prnt() - - def _loading_gen_enum(self, tp, name, module, prefix='enum'): - if tp.partial: - enumvalues = [self._load_constant(True, tp, enumerator, module) - for enumerator in tp.enumerators] - tp.enumvalues = tuple(enumvalues) - tp.partial_resolved = True - else: - funcname = self._enum_funcname(prefix, name) - self._load_known_int_constant(module, funcname) - - def _loaded_gen_enum(self, tp, name, module, library): - for enumerator, enumvalue in zip(tp.enumerators, tp.enumvalues): - setattr(library, enumerator, enumvalue) - type(library)._cffi_dir.append(enumerator) - - # ---------- - # macros: for now only for integers - - def _generate_gen_macro_decl(self, tp, name): - if tp == '...': - check_value = None - else: - check_value = tp # an integer - self._generate_gen_const(True, name, check_value=check_value) - - _loading_gen_macro = _loaded_noop - - def _loaded_gen_macro(self, tp, name, module, library): - if tp == '...': - check_value = None - else: - check_value = tp # an integer - value = self._load_constant(True, tp, name, module, - check_value=check_value) - setattr(library, name, value) - type(library)._cffi_dir.append(name) - - # ---------- - # global variables - - def _generate_gen_variable_decl(self, tp, name): - if isinstance(tp, model.ArrayType): - if tp.length_is_unknown(): - prnt = self._prnt - funcname = '_cffi_sizeof_%s' % (name,) - self.export_symbols.append(funcname) - prnt("size_t %s(void)" % funcname) - prnt("{") - prnt(" return sizeof(%s);" % (name,)) - prnt("}") - tp_ptr = model.PointerType(tp.item) - self._generate_gen_const(False, name, tp_ptr) - else: - tp_ptr = model.PointerType(tp) - self._generate_gen_const(False, name, tp_ptr, category='var') - - _loading_gen_variable = _loaded_noop - - def _loaded_gen_variable(self, tp, name, module, library): - if isinstance(tp, model.ArrayType): # int a[5] is "constant" in the - # sense that "a=..." is forbidden - if tp.length_is_unknown(): - funcname = '_cffi_sizeof_%s' % (name,) - BFunc = self.ffi._typeof_locked('size_t(*)(void)')[0] - function = module.load_function(BFunc, funcname) - size = function() - BItemType = self.ffi._get_cached_btype(tp.item) - length, rest = divmod(size, self.ffi.sizeof(BItemType)) - if rest != 0: - raise VerificationError( - "bad size: %r does not seem to be an array of %s" % - (name, tp.item)) - tp = tp.resolve_length(length) - tp_ptr = model.PointerType(tp.item) - value = self._load_constant(False, tp_ptr, name, module) - # 'value' is a which we have to replace with - # a if the N is actually known - if tp.length is not None: - BArray = self.ffi._get_cached_btype(tp) - value = self.ffi.cast(BArray, value) - setattr(library, name, value) - type(library)._cffi_dir.append(name) - return - # remove ptr= from the library instance, and replace - # it by a property on the class, which reads/writes into ptr[0]. - funcname = '_cffi_var_%s' % name - BFunc = self.ffi._typeof_locked(tp.get_c_name('*(*)(void)', name))[0] - function = module.load_function(BFunc, funcname) - ptr = function() - def getter(library): - return ptr[0] - def setter(library, value): - ptr[0] = value - setattr(type(library), name, property(getter, setter)) - type(library)._cffi_dir.append(name) - -cffimod_header = r''' -#include -#include -#include -#include -#include /* XXX for ssize_t on some platforms */ - -/* this block of #ifs should be kept exactly identical between - c/_cffi_backend.c, cffi/vengine_cpy.py, cffi/vengine_gen.py - and cffi/_cffi_include.h */ -#if defined(_MSC_VER) -# include /* for alloca() */ -# if _MSC_VER < 1600 /* MSVC < 2010 */ - typedef __int8 int8_t; - typedef __int16 int16_t; - typedef __int32 int32_t; - typedef __int64 int64_t; - typedef unsigned __int8 uint8_t; - typedef unsigned __int16 uint16_t; - typedef unsigned __int32 uint32_t; - typedef unsigned __int64 uint64_t; - typedef __int8 int_least8_t; - typedef __int16 int_least16_t; - typedef __int32 int_least32_t; - typedef __int64 int_least64_t; - typedef unsigned __int8 uint_least8_t; - typedef unsigned __int16 uint_least16_t; - typedef unsigned __int32 uint_least32_t; - typedef unsigned __int64 uint_least64_t; - typedef __int8 int_fast8_t; - typedef __int16 int_fast16_t; - typedef __int32 int_fast32_t; - typedef __int64 int_fast64_t; - typedef unsigned __int8 uint_fast8_t; - typedef unsigned __int16 uint_fast16_t; - typedef unsigned __int32 uint_fast32_t; - typedef unsigned __int64 uint_fast64_t; - typedef __int64 intmax_t; - typedef unsigned __int64 uintmax_t; -# else -# include -# endif -# if _MSC_VER < 1800 /* MSVC < 2013 */ -# ifndef __cplusplus - typedef unsigned char _Bool; -# endif -# endif -# define _cffi_float_complex_t _Fcomplex /* include for it */ -# define _cffi_double_complex_t _Dcomplex /* include for it */ -#else -# include -# if (defined (__SVR4) && defined (__sun)) || defined(_AIX) || defined(__hpux) -# include -# endif -# define _cffi_float_complex_t float _Complex -# define _cffi_double_complex_t double _Complex -#endif -''' diff --git a/.venv/lib/python3.12/site-packages/cffi/verifier.py b/.venv/lib/python3.12/site-packages/cffi/verifier.py deleted file mode 100644 index e392a2b..0000000 --- a/.venv/lib/python3.12/site-packages/cffi/verifier.py +++ /dev/null @@ -1,306 +0,0 @@ -# -# DEPRECATED: implementation for ffi.verify() -# -import sys, os, binascii, shutil, io -from . import __version_verifier_modules__ -from . import ffiplatform -from .error import VerificationError - -if sys.version_info >= (3, 3): - import importlib.machinery - def _extension_suffixes(): - return importlib.machinery.EXTENSION_SUFFIXES[:] -else: - import imp - def _extension_suffixes(): - return [suffix for suffix, _, type in imp.get_suffixes() - if type == imp.C_EXTENSION] - - -if sys.version_info >= (3,): - NativeIO = io.StringIO -else: - class NativeIO(io.BytesIO): - def write(self, s): - if isinstance(s, unicode): - s = s.encode('ascii') - super(NativeIO, self).write(s) - - -class Verifier(object): - - def __init__(self, ffi, preamble, tmpdir=None, modulename=None, - ext_package=None, tag='', force_generic_engine=False, - source_extension='.c', flags=None, relative_to=None, **kwds): - if ffi._parser._uses_new_feature: - raise VerificationError( - "feature not supported with ffi.verify(), but only " - "with ffi.set_source(): %s" % (ffi._parser._uses_new_feature,)) - self.ffi = ffi - self.preamble = preamble - if not modulename: - flattened_kwds = ffiplatform.flatten(kwds) - vengine_class = _locate_engine_class(ffi, force_generic_engine) - self._vengine = vengine_class(self) - self._vengine.patch_extension_kwds(kwds) - self.flags = flags - self.kwds = self.make_relative_to(kwds, relative_to) - # - if modulename: - if tag: - raise TypeError("can't specify both 'modulename' and 'tag'") - else: - key = '\x00'.join(['%d.%d' % sys.version_info[:2], - __version_verifier_modules__, - preamble, flattened_kwds] + - ffi._cdefsources) - if sys.version_info >= (3,): - key = key.encode('utf-8') - k1 = hex(binascii.crc32(key[0::2]) & 0xffffffff) - k1 = k1.lstrip('0x').rstrip('L') - k2 = hex(binascii.crc32(key[1::2]) & 0xffffffff) - k2 = k2.lstrip('0').rstrip('L') - modulename = '_cffi_%s_%s%s%s' % (tag, self._vengine._class_key, - k1, k2) - suffix = _get_so_suffixes()[0] - self.tmpdir = tmpdir or _caller_dir_pycache() - self.sourcefilename = os.path.join(self.tmpdir, modulename + source_extension) - self.modulefilename = os.path.join(self.tmpdir, modulename + suffix) - self.ext_package = ext_package - self._has_source = False - self._has_module = False - - def write_source(self, file=None): - """Write the C source code. It is produced in 'self.sourcefilename', - which can be tweaked beforehand.""" - with self.ffi._lock: - if self._has_source and file is None: - raise VerificationError( - "source code already written") - self._write_source(file) - - def compile_module(self): - """Write the C source code (if not done already) and compile it. - This produces a dynamic link library in 'self.modulefilename'.""" - with self.ffi._lock: - if self._has_module: - raise VerificationError("module already compiled") - if not self._has_source: - self._write_source() - self._compile_module() - - def load_library(self): - """Get a C module from this Verifier instance. - Returns an instance of a FFILibrary class that behaves like the - objects returned by ffi.dlopen(), but that delegates all - operations to the C module. If necessary, the C code is written - and compiled first. - """ - with self.ffi._lock: - if not self._has_module: - self._locate_module() - if not self._has_module: - if not self._has_source: - self._write_source() - self._compile_module() - return self._load_library() - - def get_module_name(self): - basename = os.path.basename(self.modulefilename) - # kill both the .so extension and the other .'s, as introduced - # by Python 3: 'basename.cpython-33m.so' - basename = basename.split('.', 1)[0] - # and the _d added in Python 2 debug builds --- but try to be - # conservative and not kill a legitimate _d - if basename.endswith('_d') and hasattr(sys, 'gettotalrefcount'): - basename = basename[:-2] - return basename - - def get_extension(self): - if not self._has_source: - with self.ffi._lock: - if not self._has_source: - self._write_source() - sourcename = ffiplatform.maybe_relative_path(self.sourcefilename) - modname = self.get_module_name() - return ffiplatform.get_extension(sourcename, modname, **self.kwds) - - def generates_python_module(self): - return self._vengine._gen_python_module - - def make_relative_to(self, kwds, relative_to): - if relative_to and os.path.dirname(relative_to): - dirname = os.path.dirname(relative_to) - kwds = kwds.copy() - for key in ffiplatform.LIST_OF_FILE_NAMES: - if key in kwds: - lst = kwds[key] - if not isinstance(lst, (list, tuple)): - raise TypeError("keyword '%s' should be a list or tuple" - % (key,)) - lst = [os.path.join(dirname, fn) for fn in lst] - kwds[key] = lst - return kwds - - # ---------- - - def _locate_module(self): - if not os.path.isfile(self.modulefilename): - if self.ext_package: - try: - pkg = __import__(self.ext_package, None, None, ['__doc__']) - except ImportError: - return # cannot import the package itself, give up - # (e.g. it might be called differently before installation) - path = pkg.__path__ - else: - path = None - filename = self._vengine.find_module(self.get_module_name(), path, - _get_so_suffixes()) - if filename is None: - return - self.modulefilename = filename - self._vengine.collect_types() - self._has_module = True - - def _write_source_to(self, file): - self._vengine._f = file - try: - self._vengine.write_source_to_f() - finally: - del self._vengine._f - - def _write_source(self, file=None): - if file is not None: - self._write_source_to(file) - else: - # Write our source file to an in memory file. - f = NativeIO() - self._write_source_to(f) - source_data = f.getvalue() - - # Determine if this matches the current file - if os.path.exists(self.sourcefilename): - with open(self.sourcefilename, "r") as fp: - needs_written = not (fp.read() == source_data) - else: - needs_written = True - - # Actually write the file out if it doesn't match - if needs_written: - _ensure_dir(self.sourcefilename) - with open(self.sourcefilename, "w") as fp: - fp.write(source_data) - - # Set this flag - self._has_source = True - - def _compile_module(self): - # compile this C source - tmpdir = os.path.dirname(self.sourcefilename) - outputfilename = ffiplatform.compile(tmpdir, self.get_extension()) - try: - same = ffiplatform.samefile(outputfilename, self.modulefilename) - except OSError: - same = False - if not same: - _ensure_dir(self.modulefilename) - shutil.move(outputfilename, self.modulefilename) - self._has_module = True - - def _load_library(self): - assert self._has_module - if self.flags is not None: - return self._vengine.load_library(self.flags) - else: - return self._vengine.load_library() - -# ____________________________________________________________ - -_FORCE_GENERIC_ENGINE = False # for tests - -def _locate_engine_class(ffi, force_generic_engine): - if _FORCE_GENERIC_ENGINE: - force_generic_engine = True - if not force_generic_engine: - if '__pypy__' in sys.builtin_module_names: - force_generic_engine = True - else: - try: - import _cffi_backend - except ImportError: - _cffi_backend = '?' - if ffi._backend is not _cffi_backend: - force_generic_engine = True - if force_generic_engine: - from . import vengine_gen - return vengine_gen.VGenericEngine - else: - from . import vengine_cpy - return vengine_cpy.VCPythonEngine - -# ____________________________________________________________ - -_TMPDIR = None - -def _caller_dir_pycache(): - if _TMPDIR: - return _TMPDIR - result = os.environ.get('CFFI_TMPDIR') - if result: - return result - filename = sys._getframe(2).f_code.co_filename - return os.path.abspath(os.path.join(os.path.dirname(filename), - '__pycache__')) - -def set_tmpdir(dirname): - """Set the temporary directory to use instead of __pycache__.""" - global _TMPDIR - _TMPDIR = dirname - -def cleanup_tmpdir(tmpdir=None, keep_so=False): - """Clean up the temporary directory by removing all files in it - called `_cffi_*.{c,so}` as well as the `build` subdirectory.""" - tmpdir = tmpdir or _caller_dir_pycache() - try: - filelist = os.listdir(tmpdir) - except OSError: - return - if keep_so: - suffix = '.c' # only remove .c files - else: - suffix = _get_so_suffixes()[0].lower() - for fn in filelist: - if fn.lower().startswith('_cffi_') and ( - fn.lower().endswith(suffix) or fn.lower().endswith('.c')): - try: - os.unlink(os.path.join(tmpdir, fn)) - except OSError: - pass - clean_dir = [os.path.join(tmpdir, 'build')] - for dir in clean_dir: - try: - for fn in os.listdir(dir): - fn = os.path.join(dir, fn) - if os.path.isdir(fn): - clean_dir.append(fn) - else: - os.unlink(fn) - except OSError: - pass - -def _get_so_suffixes(): - suffixes = _extension_suffixes() - if not suffixes: - # bah, no C_EXTENSION available. Occurs on pypy without cpyext - if sys.platform == 'win32': - suffixes = [".pyd"] - else: - suffixes = [".so"] - - return suffixes - -def _ensure_dir(filename): - dirname = os.path.dirname(filename) - if dirname and not os.path.isdir(dirname): - os.makedirs(dirname) diff --git a/.venv/lib/python3.12/site-packages/charset_normalizer-3.4.7.dist-info/INSTALLER b/.venv/lib/python3.12/site-packages/charset_normalizer-3.4.7.dist-info/INSTALLER deleted file mode 100644 index a1b589e..0000000 --- a/.venv/lib/python3.12/site-packages/charset_normalizer-3.4.7.dist-info/INSTALLER +++ /dev/null @@ -1 +0,0 @@ -pip diff --git a/.venv/lib/python3.12/site-packages/charset_normalizer-3.4.7.dist-info/METADATA b/.venv/lib/python3.12/site-packages/charset_normalizer-3.4.7.dist-info/METADATA deleted file mode 100644 index 6b5a360..0000000 --- a/.venv/lib/python3.12/site-packages/charset_normalizer-3.4.7.dist-info/METADATA +++ /dev/null @@ -1,808 +0,0 @@ -Metadata-Version: 2.4 -Name: charset-normalizer -Version: 3.4.7 -Summary: The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet. -Author-email: "Ahmed R. TAHRI" -Maintainer-email: "Ahmed R. TAHRI" -License: MIT -Project-URL: Changelog, https://github.com/jawah/charset_normalizer/blob/master/CHANGELOG.md -Project-URL: Documentation, https://charset-normalizer.readthedocs.io/ -Project-URL: Code, https://github.com/jawah/charset_normalizer -Project-URL: Issue tracker, https://github.com/jawah/charset_normalizer/issues -Keywords: encoding,charset,charset-detector,detector,normalization,unicode,chardet,detect -Classifier: Development Status :: 5 - Production/Stable -Classifier: Intended Audience :: Developers -Classifier: Operating System :: OS Independent -Classifier: Programming Language :: Python -Classifier: Programming Language :: Python :: 3 -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: Programming Language :: Python :: 3 :: Only -Classifier: Programming Language :: Python :: Implementation :: CPython -Classifier: Programming Language :: Python :: Implementation :: PyPy -Classifier: Programming Language :: Python :: Free Threading :: 4 - Resilient -Classifier: Topic :: Text Processing :: Linguistic -Classifier: Topic :: Utilities -Classifier: Typing :: Typed -Requires-Python: >=3.7 -Description-Content-Type: text/markdown -License-File: LICENSE -Provides-Extra: unicode-backport -Dynamic: license-file - -

Charset Detection, for Everyone 👋

- -

- The Real First Universal Charset Detector
- - - - - Download Count Total - - - - -

-

- Featured Packages
- - Static Badge - - - Static Badge - -

-

- In other language (unofficial port - by the community)
- - Static Badge - -

- -> A library that helps you read text from an unknown charset encoding.
Motivated by `chardet`, -> I'm trying to resolve the issue by taking a new approach. -> All IANA character set names for which the Python core library provides codecs are supported. -> You can also register your own set of codecs, and yes, it would work as-is. - -

- >>>>> 👉 Try Me Online Now, Then Adopt Me 👈 <<<<< -

- -This project offers you an alternative to **Universal Charset Encoding Detector**, also known as **Chardet**. - -| Feature | [Chardet](https://github.com/chardet/chardet) | Charset Normalizer | [cChardet](https://github.com/PyYoshi/cChardet) | -|--------------------------------------------------|:---------------------------------------------:|:-----------------------------------------------------------------------------------------------:|:-----------------------------------------------:| -| `Fast` | ✅ | ✅ | ✅ | -| `Universal`[^1] | ❌ | ✅ | ❌ | -| `Reliable` **without** distinguishable standards | ✅ | ✅ | ✅ | -| `Reliable` **with** distinguishable standards | ✅ | ✅ | ✅ | -| `License` | _Disputed_[^2]
_restrictive_ | MIT | MPL-1.1
_restrictive_ | -| `Native Python` | ✅ | ✅ | ❌ | -| `Detect spoken language` | ✅ | ✅ | N/A | -| `UnicodeDecodeError Safety` | ✅ | ✅ | ❌ | -| `Whl Size (min)` | 500 kB | 150 kB | ~200 kB | -| `Supported Encoding` | 99 | [99](https://charset-normalizer.readthedocs.io/en/latest/user/support.html#supported-encodings) | 40 | -| `Can register custom encoding` | ❌ | ✅ | ❌ | - -

-Reading Normalized TextCat Reading Text -

- -[^1]: They are clearly using specific code for a specific encoding even if covering most of used one. -[^2]: Chardet 7.0+ was relicensed from LGPL-2.1 to MIT following an AI-assisted rewrite. This relicensing is disputed on two independent grounds: **(a)** the original author [contests](https://github.com/chardet/chardet/issues/327) that the maintainer had the right to relicense, arguing the rewrite is a derivative work of the LGPL-licensed codebase since it was not a clean room implementation; **(b)** the copyright claim itself is [questionable](https://github.com/chardet/chardet/issues/334) given the code was primarily generated by an LLM, and AI-generated output may not be copyrightable under most jurisdictions. Either issue alone could undermine the MIT license. Beyond licensing, the rewrite raises questions about responsible use of AI in open source: key architectural ideas pioneered by charset-normalizer - notably decode-first validity filtering (our foundational approach since v1) and encoding pairwise similarity with the same algorithm and threshold — surfaced in chardet 7 without acknowledgment. The project also imported test files from charset-normalizer to train and benchmark against it, then claimed superior accuracy on those very files. Charset-normalizer has always been MIT-licensed, encoding-agnostic by design, and built on a verifiable human-authored history. - -## ⚡ Performance - -This package offer better performances (99th, and 95th) against Chardet. Here are some numbers. - -| Package | Accuracy | Mean per file (ms) | File per sec (est) | -|---------------------------------------------------|:--------:|:------------------:|:------------------:| -| [chardet 7.1](https://github.com/chardet/chardet) | 89 % | 3 ms | 333 file/sec | -| charset-normalizer | **97 %** | 3 ms | 333 file/sec | - -| Package | 99th percentile | 95th percentile | 50th percentile | -|---------------------------------------------------|:---------------:|:---------------:|:---------------:| -| [chardet 7.1](https://github.com/chardet/chardet) | 32 ms | 17 ms | < 1 ms | -| charset-normalizer | 16 ms | 10 ms | 1 ms | - -_updated as of March 2026 using CPython 3.12, Charset-Normalizer 3.4.6, and Chardet 7.1.0_ - -~Chardet's performance on larger file (1MB+) are very poor. Expect huge difference on large payload.~ No longer the case since Chardet 7.0+ - -> Stats are generated using 400+ files using default parameters. More details on used files, see GHA workflows. -> And yes, these results might change at any time. The dataset can be updated to include more files. -> The actual delays heavily depends on your CPU capabilities. The factors should remain the same. -> Chardet claims on his documentation to have a greater accuracy than us based on the dataset they trained Chardet on(...) -> Well, it's normal, the opposite would have been worrying. Whereas charset-normalizer don't train on anything, our solution -> is based on a completely different algorithm, still heuristic through, it does not need weights across every encoding tables. - -## ✨ Installation - -Using pip: - -```sh -pip install charset-normalizer -U -``` - -## 🚀 Basic Usage - -### CLI -This package comes with a CLI. - -``` -usage: normalizer [-h] [-v] [-a] [-n] [-m] [-r] [-f] [-t THRESHOLD] - file [file ...] - -The Real First Universal Charset Detector. Discover originating encoding used -on text file. Normalize text to unicode. - -positional arguments: - files File(s) to be analysed - -optional arguments: - -h, --help show this help message and exit - -v, --verbose Display complementary information about file if any. - Stdout will contain logs about the detection process. - -a, --with-alternative - Output complementary possibilities if any. Top-level - JSON WILL be a list. - -n, --normalize Permit to normalize input file. If not set, program - does not write anything. - -m, --minimal Only output the charset detected to STDOUT. Disabling - JSON output. - -r, --replace Replace file when trying to normalize it instead of - creating a new one. - -f, --force Replace file without asking if you are sure, use this - flag with caution. - -t THRESHOLD, --threshold THRESHOLD - Define a custom maximum amount of chaos allowed in - decoded content. 0. <= chaos <= 1. - --version Show version information and exit. -``` - -```bash -normalizer ./data/sample.1.fr.srt -``` - -or - -```bash -python -m charset_normalizer ./data/sample.1.fr.srt -``` - -🎉 Since version 1.4.0 the CLI produce easily usable stdout result in JSON format. - -```json -{ - "path": "/home/default/projects/charset_normalizer/data/sample.1.fr.srt", - "encoding": "cp1252", - "encoding_aliases": [ - "1252", - "windows_1252" - ], - "alternative_encodings": [ - "cp1254", - "cp1256", - "cp1258", - "iso8859_14", - "iso8859_15", - "iso8859_16", - "iso8859_3", - "iso8859_9", - "latin_1", - "mbcs" - ], - "language": "French", - "alphabets": [ - "Basic Latin", - "Latin-1 Supplement" - ], - "has_sig_or_bom": false, - "chaos": 0.149, - "coherence": 97.152, - "unicode_path": null, - "is_preferred": true -} -``` - -### Python -*Just print out normalized text* -```python -from charset_normalizer import from_path - -results = from_path('./my_subtitle.srt') - -print(str(results.best())) -``` - -*Upgrade your code without effort* -```python -from charset_normalizer import detect -``` - -The above code will behave the same as **chardet**. We ensure that we offer the best (reasonable) BC result possible. - -See the docs for advanced usage : [readthedocs.io](https://charset-normalizer.readthedocs.io/en/latest/) - -## 😇 Why - -When I started using Chardet, I noticed that it was not suited to my expectations, and I wanted to propose a -reliable alternative using a completely different method. Also! I never back down on a good challenge! - -I **don't care** about the **originating charset** encoding, because **two different tables** can -produce **two identical rendered string.** -What I want is to get readable text, the best I can. - -In a way, **I'm brute forcing text decoding.** How cool is that ? 😎 - -Don't confuse package **ftfy** with charset-normalizer or chardet. ftfy goal is to repair Unicode string whereas charset-normalizer to convert raw file in unknown encoding to unicode. - -## 🍰 How - - - Discard all charset encoding table that could not fit the binary content. - - Measure noise, or the mess once opened (by chunks) with a corresponding charset encoding. - - Extract matches with the lowest mess detected. - - Additionally, we measure coherence / probe for a language. - -**Wait a minute**, what is noise/mess and coherence according to **YOU ?** - -*Noise :* I opened hundred of text files, **written by humans**, with the wrong encoding table. **I observed**, then -**I established** some ground rules about **what is obvious** when **it seems like** a mess (aka. defining noise in rendered text). - I know that my interpretation of what is noise is probably incomplete, feel free to contribute in order to - improve or rewrite it. - -*Coherence :* For each language there is on earth, we have computed ranked letter appearance occurrences (the best we can). So I thought -that intel is worth something here. So I use those records against decoded text to check if I can detect intelligent design. - -## ⚡ Known limitations - - - Language detection is unreliable when text contains two or more languages sharing identical letters. (eg. HTML (english tags) + Turkish content (Sharing Latin characters)) - - Every charset detector heavily depends on sufficient content. In common cases, do not bother run detection on very tiny content. - -## ⚠️ About Python EOLs - -**If you are running:** - -- Python >=2.7,<3.5: Unsupported -- Python 3.5: charset-normalizer < 2.1 -- Python 3.6: charset-normalizer < 3.1 - -Upgrade your Python interpreter as soon as possible. - -## 👤 Contributing - -Contributions, issues and feature requests are very much welcome.
-Feel free to check [issues page](https://github.com/ousret/charset_normalizer/issues) if you want to contribute. - -## 📝 License - -Copyright © [Ahmed TAHRI @Ousret](https://github.com/Ousret).
-This project is [MIT](https://github.com/Ousret/charset_normalizer/blob/master/LICENSE) licensed. - -Characters frequencies used in this project © 2012 [Denny Vrandečić](http://simia.net/letters/) - -## 💼 For Enterprise - -Professional support for charset-normalizer is available as part of the [Tidelift -Subscription][1]. Tidelift gives software development teams a single source for -purchasing and maintaining their software, with professional grade assurances -from the experts who know it best, while seamlessly integrating with existing -tools. - -[1]: https://tidelift.com/subscription/pkg/pypi-charset-normalizer?utm_source=pypi-charset-normalizer&utm_medium=readme - -[![OpenSSF Best Practices](https://www.bestpractices.dev/projects/7297/badge)](https://www.bestpractices.dev/projects/7297) - -# Changelog -All notable changes to charset-normalizer will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - -## [3.4.7](https://github.com/Ousret/charset_normalizer/compare/3.4.6...3.4.7) (2026-04-02) - -### Changed -- Pre-built optimized version using mypy[c] v1.20. -- Relax `setuptools` constraint to `setuptools>=68,<82.1`. - -### Fixed -- Correctly remove SIG remnant in utf-7 decoded string. (#718) (#716) - -## [3.4.6](https://github.com/Ousret/charset_normalizer/compare/3.4.5...3.4.6) (2026-03-15) - -### Changed -- Flattened the logic in `charset_normalizer.md` for higher performance. Removed `eligible(..)` and `feed(...)` - in favor of `feed_info(...)`. -- Raised upper bound for mypy[c] to 1.20, for our optimized version. -- Updated `UNICODE_RANGES_COMBINED` using Unicode blocks v17. - -### Fixed -- Edge case where noise difference between two candidates can be almost insignificant. (#672) -- CLI `--normalize` writing to wrong path when passing multiple files in. (#702) - -### Misc -- Freethreaded pre-built wheels now shipped in PyPI starting with 3.14t. (#616) - -## [3.4.5](https://github.com/Ousret/charset_normalizer/compare/3.4.4...3.4.5) (2026-03-06) - -### Changed -- Update `setuptools` constraint to `setuptools>=68,<=82`. -- Raised upper bound of mypyc for the optional pre-built extension to v1.19.1 - -### Fixed -- Add explicit link to lib math in our optimized build. (#692) -- Logger level not restored correctly for empty byte sequences. (#701) -- TypeError when passing bytearray to from_bytes. (#703) - -### Misc -- Applied safe micro-optimizations in both our noise detector and language detector. -- Rewrote the `query_yes_no` function (inside CLI) to avoid using ambiguous licensed code. -- Added `cd.py` submodule into mypyc optional compilation to reduce further the performance impact. - -## [3.4.4](https://github.com/Ousret/charset_normalizer/compare/3.4.2...3.4.4) (2025-10-13) - -### Changed -- Bound `setuptools` to a specific constraint `setuptools>=68,<=81`. -- Raised upper bound of mypyc for the optional pre-built extension to v1.18.2 - -### Removed -- `setuptools-scm` as a build dependency. - -### Misc -- Enforced hashes in `dev-requirements.txt` and created `ci-requirements.txt` for security purposes. -- Additional pre-built wheels for riscv64, s390x, and armv7l architectures. -- Restore ` multiple.intoto.jsonl` in GitHub releases in addition to individual attestation file per wheel. - -## [3.4.3](https://github.com/Ousret/charset_normalizer/compare/3.4.2...3.4.3) (2025-08-09) - -### Changed -- mypy(c) is no longer a required dependency at build time if `CHARSET_NORMALIZER_USE_MYPYC` isn't set to `1`. (#595) (#583) -- automatically lower confidence on small bytes samples that are not Unicode in `detect` output legacy function. (#391) - -### Added -- Custom build backend to overcome inability to mark mypy as an optional dependency in the build phase. -- Support for Python 3.14 - -### Fixed -- sdist archive contained useless directories. -- automatically fallback on valid UTF-16 or UTF-32 even if the md says it's noisy. (#633) - -### Misc -- SBOM are automatically published to the relevant GitHub release to comply with regulatory changes. - Each published wheel comes with its SBOM. We choose CycloneDX as the format. -- Prebuilt optimized wheel are no longer distributed by default for CPython 3.7 due to a change in cibuildwheel. - -## [3.4.2](https://github.com/Ousret/charset_normalizer/compare/3.4.1...3.4.2) (2025-05-02) - -### Fixed -- Addressed the DeprecationWarning in our CLI regarding `argparse.FileType` by backporting the target class into the package. (#591) -- Improved the overall reliability of the detector with CJK Ideographs. (#605) (#587) - -### Changed -- Optional mypyc compilation upgraded to version 1.15 for Python >= 3.8 - -## [3.4.1](https://github.com/Ousret/charset_normalizer/compare/3.4.0...3.4.1) (2024-12-24) - -### Changed -- Project metadata are now stored using `pyproject.toml` instead of `setup.cfg` using setuptools as the build backend. -- Enforce annotation delayed loading for a simpler and consistent types in the project. -- Optional mypyc compilation upgraded to version 1.14 for Python >= 3.8 - -### Added -- pre-commit configuration. -- noxfile. - -### Removed -- `build-requirements.txt` as per using `pyproject.toml` native build configuration. -- `bin/integration.py` and `bin/serve.py` in favor of downstream integration test (see noxfile). -- `setup.cfg` in favor of `pyproject.toml` metadata configuration. -- Unused `utils.range_scan` function. - -### Fixed -- Converting content to Unicode bytes may insert `utf_8` instead of preferred `utf-8`. (#572) -- Deprecation warning "'count' is passed as positional argument" when converting to Unicode bytes on Python 3.13+ - -## [3.4.0](https://github.com/Ousret/charset_normalizer/compare/3.3.2...3.4.0) (2024-10-08) - -### Added -- Argument `--no-preemptive` in the CLI to prevent the detector to search for hints. -- Support for Python 3.13 (#512) - -### Fixed -- Relax the TypeError exception thrown when trying to compare a CharsetMatch with anything else than a CharsetMatch. -- Improved the general reliability of the detector based on user feedbacks. (#520) (#509) (#498) (#407) (#537) -- Declared charset in content (preemptive detection) not changed when converting to utf-8 bytes. (#381) - -## [3.3.2](https://github.com/Ousret/charset_normalizer/compare/3.3.1...3.3.2) (2023-10-31) - -### Fixed -- Unintentional memory usage regression when using large payload that match several encoding (#376) -- Regression on some detection case showcased in the documentation (#371) - -### Added -- Noise (md) probe that identify malformed arabic representation due to the presence of letters in isolated form (credit to my wife) - -## [3.3.1](https://github.com/Ousret/charset_normalizer/compare/3.3.0...3.3.1) (2023-10-22) - -### Changed -- Optional mypyc compilation upgraded to version 1.6.1 for Python >= 3.8 -- Improved the general detection reliability based on reports from the community - -## [3.3.0](https://github.com/Ousret/charset_normalizer/compare/3.2.0...3.3.0) (2023-09-30) - -### Added -- Allow to execute the CLI (e.g. normalizer) through `python -m charset_normalizer.cli` or `python -m charset_normalizer` -- Support for 9 forgotten encoding that are supported by Python but unlisted in `encoding.aliases` as they have no alias (#323) - -### Removed -- (internal) Redundant utils.is_ascii function and unused function is_private_use_only -- (internal) charset_normalizer.assets is moved inside charset_normalizer.constant - -### Changed -- (internal) Unicode code blocks in constants are updated using the latest v15.0.0 definition to improve detection -- Optional mypyc compilation upgraded to version 1.5.1 for Python >= 3.8 - -### Fixed -- Unable to properly sort CharsetMatch when both chaos/noise and coherence were close due to an unreachable condition in \_\_lt\_\_ (#350) - -## [3.2.0](https://github.com/Ousret/charset_normalizer/compare/3.1.0...3.2.0) (2023-06-07) - -### Changed -- Typehint for function `from_path` no longer enforce `PathLike` as its first argument -- Minor improvement over the global detection reliability - -### Added -- Introduce function `is_binary` that relies on main capabilities, and optimized to detect binaries -- Propagate `enable_fallback` argument throughout `from_bytes`, `from_path`, and `from_fp` that allow a deeper control over the detection (default True) -- Explicit support for Python 3.12 - -### Fixed -- Edge case detection failure where a file would contain 'very-long' camel cased word (Issue #289) - -## [3.1.0](https://github.com/Ousret/charset_normalizer/compare/3.0.1...3.1.0) (2023-03-06) - -### Added -- Argument `should_rename_legacy` for legacy function `detect` and disregard any new arguments without errors (PR #262) - -### Removed -- Support for Python 3.6 (PR #260) - -### Changed -- Optional speedup provided by mypy/c 1.0.1 - -## [3.0.1](https://github.com/Ousret/charset_normalizer/compare/3.0.0...3.0.1) (2022-11-18) - -### Fixed -- Multi-bytes cutter/chunk generator did not always cut correctly (PR #233) - -### Changed -- Speedup provided by mypy/c 0.990 on Python >= 3.7 - -## [3.0.0](https://github.com/Ousret/charset_normalizer/compare/2.1.1...3.0.0) (2022-10-20) - -### Added -- Extend the capability of explain=True when cp_isolation contains at most two entries (min one), will log in details of the Mess-detector results -- Support for alternative language frequency set in charset_normalizer.assets.FREQUENCIES -- Add parameter `language_threshold` in `from_bytes`, `from_path` and `from_fp` to adjust the minimum expected coherence ratio -- `normalizer --version` now specify if current version provide extra speedup (meaning mypyc compilation whl) - -### Changed -- Build with static metadata using 'build' frontend -- Make the language detection stricter -- Optional: Module `md.py` can be compiled using Mypyc to provide an extra speedup up to 4x faster than v2.1 - -### Fixed -- CLI with opt --normalize fail when using full path for files -- TooManyAccentuatedPlugin induce false positive on the mess detection when too few alpha character have been fed to it -- Sphinx warnings when generating the documentation - -### Removed -- Coherence detector no longer return 'Simple English' instead return 'English' -- Coherence detector no longer return 'Classical Chinese' instead return 'Chinese' -- Breaking: Method `first()` and `best()` from CharsetMatch -- UTF-7 will no longer appear as "detected" without a recognized SIG/mark (is unreliable/conflict with ASCII) -- Breaking: Class aliases CharsetDetector, CharsetDoctor, CharsetNormalizerMatch and CharsetNormalizerMatches -- Breaking: Top-level function `normalize` -- Breaking: Properties `chaos_secondary_pass`, `coherence_non_latin` and `w_counter` from CharsetMatch -- Support for the backport `unicodedata2` - -## [3.0.0rc1](https://github.com/Ousret/charset_normalizer/compare/3.0.0b2...3.0.0rc1) (2022-10-18) - -### Added -- Extend the capability of explain=True when cp_isolation contains at most two entries (min one), will log in details of the Mess-detector results -- Support for alternative language frequency set in charset_normalizer.assets.FREQUENCIES -- Add parameter `language_threshold` in `from_bytes`, `from_path` and `from_fp` to adjust the minimum expected coherence ratio - -### Changed -- Build with static metadata using 'build' frontend -- Make the language detection stricter - -### Fixed -- CLI with opt --normalize fail when using full path for files -- TooManyAccentuatedPlugin induce false positive on the mess detection when too few alpha character have been fed to it - -### Removed -- Coherence detector no longer return 'Simple English' instead return 'English' -- Coherence detector no longer return 'Classical Chinese' instead return 'Chinese' - -## [3.0.0b2](https://github.com/Ousret/charset_normalizer/compare/3.0.0b1...3.0.0b2) (2022-08-21) - -### Added -- `normalizer --version` now specify if current version provide extra speedup (meaning mypyc compilation whl) - -### Removed -- Breaking: Method `first()` and `best()` from CharsetMatch -- UTF-7 will no longer appear as "detected" without a recognized SIG/mark (is unreliable/conflict with ASCII) - -### Fixed -- Sphinx warnings when generating the documentation - -## [3.0.0b1](https://github.com/Ousret/charset_normalizer/compare/2.1.0...3.0.0b1) (2022-08-15) - -### Changed -- Optional: Module `md.py` can be compiled using Mypyc to provide an extra speedup up to 4x faster than v2.1 - -### Removed -- Breaking: Class aliases CharsetDetector, CharsetDoctor, CharsetNormalizerMatch and CharsetNormalizerMatches -- Breaking: Top-level function `normalize` -- Breaking: Properties `chaos_secondary_pass`, `coherence_non_latin` and `w_counter` from CharsetMatch -- Support for the backport `unicodedata2` - -## [2.1.1](https://github.com/Ousret/charset_normalizer/compare/2.1.0...2.1.1) (2022-08-19) - -### Deprecated -- Function `normalize` scheduled for removal in 3.0 - -### Changed -- Removed useless call to decode in fn is_unprintable (#206) - -### Fixed -- Third-party library (i18n xgettext) crashing not recognizing utf_8 (PEP 263) with underscore from [@aleksandernovikov](https://github.com/aleksandernovikov) (#204) - -## [2.1.0](https://github.com/Ousret/charset_normalizer/compare/2.0.12...2.1.0) (2022-06-19) - -### Added -- Output the Unicode table version when running the CLI with `--version` (PR #194) - -### Changed -- Re-use decoded buffer for single byte character sets from [@nijel](https://github.com/nijel) (PR #175) -- Fixing some performance bottlenecks from [@deedy5](https://github.com/deedy5) (PR #183) - -### Fixed -- Workaround potential bug in cpython with Zero Width No-Break Space located in Arabic Presentation Forms-B, Unicode 1.1 not acknowledged as space (PR #175) -- CLI default threshold aligned with the API threshold from [@oleksandr-kuzmenko](https://github.com/oleksandr-kuzmenko) (PR #181) - -### Removed -- Support for Python 3.5 (PR #192) - -### Deprecated -- Use of backport unicodedata from `unicodedata2` as Python is quickly catching up, scheduled for removal in 3.0 (PR #194) - -## [2.0.12](https://github.com/Ousret/charset_normalizer/compare/2.0.11...2.0.12) (2022-02-12) - -### Fixed -- ASCII miss-detection on rare cases (PR #170) - -## [2.0.11](https://github.com/Ousret/charset_normalizer/compare/2.0.10...2.0.11) (2022-01-30) - -### Added -- Explicit support for Python 3.11 (PR #164) - -### Changed -- The logging behavior have been completely reviewed, now using only TRACE and DEBUG levels (PR #163 #165) - -## [2.0.10](https://github.com/Ousret/charset_normalizer/compare/2.0.9...2.0.10) (2022-01-04) - -### Fixed -- Fallback match entries might lead to UnicodeDecodeError for large bytes sequence (PR #154) - -### Changed -- Skipping the language-detection (CD) on ASCII (PR #155) - -## [2.0.9](https://github.com/Ousret/charset_normalizer/compare/2.0.8...2.0.9) (2021-12-03) - -### Changed -- Moderating the logging impact (since 2.0.8) for specific environments (PR #147) - -### Fixed -- Wrong logging level applied when setting kwarg `explain` to True (PR #146) - -## [2.0.8](https://github.com/Ousret/charset_normalizer/compare/2.0.7...2.0.8) (2021-11-24) -### Changed -- Improvement over Vietnamese detection (PR #126) -- MD improvement on trailing data and long foreign (non-pure latin) data (PR #124) -- Efficiency improvements in cd/alphabet_languages from [@adbar](https://github.com/adbar) (PR #122) -- call sum() without an intermediary list following PEP 289 recommendations from [@adbar](https://github.com/adbar) (PR #129) -- Code style as refactored by Sourcery-AI (PR #131) -- Minor adjustment on the MD around european words (PR #133) -- Remove and replace SRTs from assets / tests (PR #139) -- Initialize the library logger with a `NullHandler` by default from [@nmaynes](https://github.com/nmaynes) (PR #135) -- Setting kwarg `explain` to True will add provisionally (bounded to function lifespan) a specific stream handler (PR #135) - -### Fixed -- Fix large (misleading) sequence giving UnicodeDecodeError (PR #137) -- Avoid using too insignificant chunk (PR #137) - -### Added -- Add and expose function `set_logging_handler` to configure a specific StreamHandler from [@nmaynes](https://github.com/nmaynes) (PR #135) -- Add `CHANGELOG.md` entries, format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) (PR #141) - -## [2.0.7](https://github.com/Ousret/charset_normalizer/compare/2.0.6...2.0.7) (2021-10-11) -### Added -- Add support for Kazakh (Cyrillic) language detection (PR #109) - -### Changed -- Further, improve inferring the language from a given single-byte code page (PR #112) -- Vainly trying to leverage PEP263 when PEP3120 is not supported (PR #116) -- Refactoring for potential performance improvements in loops from [@adbar](https://github.com/adbar) (PR #113) -- Various detection improvement (MD+CD) (PR #117) - -### Removed -- Remove redundant logging entry about detected language(s) (PR #115) - -### Fixed -- Fix a minor inconsistency between Python 3.5 and other versions regarding language detection (PR #117 #102) - -## [2.0.6](https://github.com/Ousret/charset_normalizer/compare/2.0.5...2.0.6) (2021-09-18) -### Fixed -- Unforeseen regression with the loss of the backward-compatibility with some older minor of Python 3.5.x (PR #100) -- Fix CLI crash when using --minimal output in certain cases (PR #103) - -### Changed -- Minor improvement to the detection efficiency (less than 1%) (PR #106 #101) - -## [2.0.5](https://github.com/Ousret/charset_normalizer/compare/2.0.4...2.0.5) (2021-09-14) -### Changed -- The project now comply with: flake8, mypy, isort and black to ensure a better overall quality (PR #81) -- The BC-support with v1.x was improved, the old staticmethods are restored (PR #82) -- The Unicode detection is slightly improved (PR #93) -- Add syntax sugar \_\_bool\_\_ for results CharsetMatches list-container (PR #91) - -### Removed -- The project no longer raise warning on tiny content given for detection, will be simply logged as warning instead (PR #92) - -### Fixed -- In some rare case, the chunks extractor could cut in the middle of a multi-byte character and could mislead the mess detection (PR #95) -- Some rare 'space' characters could trip up the UnprintablePlugin/Mess detection (PR #96) -- The MANIFEST.in was not exhaustive (PR #78) - -## [2.0.4](https://github.com/Ousret/charset_normalizer/compare/2.0.3...2.0.4) (2021-07-30) -### Fixed -- The CLI no longer raise an unexpected exception when no encoding has been found (PR #70) -- Fix accessing the 'alphabets' property when the payload contains surrogate characters (PR #68) -- The logger could mislead (explain=True) on detected languages and the impact of one MBCS match (PR #72) -- Submatch factoring could be wrong in rare edge cases (PR #72) -- Multiple files given to the CLI were ignored when publishing results to STDOUT. (After the first path) (PR #72) -- Fix line endings from CRLF to LF for certain project files (PR #67) - -### Changed -- Adjust the MD to lower the sensitivity, thus improving the global detection reliability (PR #69 #76) -- Allow fallback on specified encoding if any (PR #71) - -## [2.0.3](https://github.com/Ousret/charset_normalizer/compare/2.0.2...2.0.3) (2021-07-16) -### Changed -- Part of the detection mechanism has been improved to be less sensitive, resulting in more accurate detection results. Especially ASCII. (PR #63) -- According to the community wishes, the detection will fall back on ASCII or UTF-8 in a last-resort case. (PR #64) - -## [2.0.2](https://github.com/Ousret/charset_normalizer/compare/2.0.1...2.0.2) (2021-07-15) -### Fixed -- Empty/Too small JSON payload miss-detection fixed. Report from [@tseaver](https://github.com/tseaver) (PR #59) - -### Changed -- Don't inject unicodedata2 into sys.modules from [@akx](https://github.com/akx) (PR #57) - -## [2.0.1](https://github.com/Ousret/charset_normalizer/compare/2.0.0...2.0.1) (2021-07-13) -### Fixed -- Make it work where there isn't a filesystem available, dropping assets frequencies.json. Report from [@sethmlarson](https://github.com/sethmlarson). (PR #55) -- Using explain=False permanently disable the verbose output in the current runtime (PR #47) -- One log entry (language target preemptive) was not show in logs when using explain=True (PR #47) -- Fix undesired exception (ValueError) on getitem of instance CharsetMatches (PR #52) - -### Changed -- Public function normalize default args values were not aligned with from_bytes (PR #53) - -### Added -- You may now use charset aliases in cp_isolation and cp_exclusion arguments (PR #47) - -## [2.0.0](https://github.com/Ousret/charset_normalizer/compare/1.4.1...2.0.0) (2021-07-02) -### Changed -- 4x to 5 times faster than the previous 1.4.0 release. At least 2x faster than Chardet. -- Accent has been made on UTF-8 detection, should perform rather instantaneous. -- The backward compatibility with Chardet has been greatly improved. The legacy detect function returns an identical charset name whenever possible. -- The detection mechanism has been slightly improved, now Turkish content is detected correctly (most of the time) -- The program has been rewritten to ease the readability and maintainability. (+Using static typing)+ -- utf_7 detection has been reinstated. - -### Removed -- This package no longer require anything when used with Python 3.5 (Dropped cached_property) -- Removed support for these languages: Catalan, Esperanto, Kazakh, Baque, Volapük, Azeri, Galician, Nynorsk, Macedonian, and Serbocroatian. -- The exception hook on UnicodeDecodeError has been removed. - -### Deprecated -- Methods coherence_non_latin, w_counter, chaos_secondary_pass of the class CharsetMatch are now deprecated and scheduled for removal in v3.0 - -### Fixed -- The CLI output used the relative path of the file(s). Should be absolute. - -## [1.4.1](https://github.com/Ousret/charset_normalizer/compare/1.4.0...1.4.1) (2021-05-28) -### Fixed -- Logger configuration/usage no longer conflict with others (PR #44) - -## [1.4.0](https://github.com/Ousret/charset_normalizer/compare/1.3.9...1.4.0) (2021-05-21) -### Removed -- Using standard logging instead of using the package loguru. -- Dropping nose test framework in favor of the maintained pytest. -- Choose to not use dragonmapper package to help with gibberish Chinese/CJK text. -- Require cached_property only for Python 3.5 due to constraint. Dropping for every other interpreter version. -- Stop support for UTF-7 that does not contain a SIG. -- Dropping PrettyTable, replaced with pure JSON output in CLI. - -### Fixed -- BOM marker in a CharsetNormalizerMatch instance could be False in rare cases even if obviously present. Due to the sub-match factoring process. -- Not searching properly for the BOM when trying utf32/16 parent codec. - -### Changed -- Improving the package final size by compressing frequencies.json. -- Huge improvement over the larges payload. - -### Added -- CLI now produces JSON consumable output. -- Return ASCII if given sequences fit. Given reasonable confidence. - -## [1.3.9](https://github.com/Ousret/charset_normalizer/compare/1.3.8...1.3.9) (2021-05-13) - -### Fixed -- In some very rare cases, you may end up getting encode/decode errors due to a bad bytes payload (PR #40) - -## [1.3.8](https://github.com/Ousret/charset_normalizer/compare/1.3.7...1.3.8) (2021-05-12) - -### Fixed -- Empty given payload for detection may cause an exception if trying to access the `alphabets` property. (PR #39) - -## [1.3.7](https://github.com/Ousret/charset_normalizer/compare/1.3.6...1.3.7) (2021-05-12) - -### Fixed -- The legacy detect function should return UTF-8-SIG if sig is present in the payload. (PR #38) - -## [1.3.6](https://github.com/Ousret/charset_normalizer/compare/1.3.5...1.3.6) (2021-02-09) - -### Changed -- Amend the previous release to allow prettytable 2.0 (PR #35) - -## [1.3.5](https://github.com/Ousret/charset_normalizer/compare/1.3.4...1.3.5) (2021-02-08) - -### Fixed -- Fix error while using the package with a python pre-release interpreter (PR #33) - -### Changed -- Dependencies refactoring, constraints revised. - -### Added -- Add python 3.9 and 3.10 to the supported interpreters - -MIT License - -Copyright (c) 2025 TAHRI Ahmed R. - -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. diff --git a/.venv/lib/python3.12/site-packages/charset_normalizer-3.4.7.dist-info/RECORD b/.venv/lib/python3.12/site-packages/charset_normalizer-3.4.7.dist-info/RECORD deleted file mode 100644 index b2f7f04..0000000 --- a/.venv/lib/python3.12/site-packages/charset_normalizer-3.4.7.dist-info/RECORD +++ /dev/null @@ -1,36 +0,0 @@ -../../../bin/normalizer,sha256=sIQLF5kUgKnaENC8Hr1-ThrvkgdsHeHT4LEp9mkO85I,218 -81d243bd2c585b0f4821__mypyc.cpython-312-x86_64-linux-gnu.so,sha256=xPTGB-9iuOqJ5RfI3qaB1WzuFAm1oYWbgN1Jz9U1wn0,433312 -charset_normalizer-3.4.7.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4 -charset_normalizer-3.4.7.dist-info/METADATA,sha256=K8lK8L8LaZ1YmKvWLt3zEkpIxiCOC58xNhzFQrfQJxQ,40931 -charset_normalizer-3.4.7.dist-info/RECORD,, -charset_normalizer-3.4.7.dist-info/WHEEL,sha256=Tc3fF66yn9Kh-hkUUsdKQyuB9Lw0CDoeANnEbSVc3f4,190 -charset_normalizer-3.4.7.dist-info/entry_points.txt,sha256=ADSTKrkXZ3hhdOVFi6DcUEHQRS0xfxDIE_pEz4wLIXA,65 -charset_normalizer-3.4.7.dist-info/licenses/LICENSE,sha256=bQ1Bv-FwrGx9wkjJpj4lTQ-0WmDVCoJX0K-SxuJJuIc,1071 -charset_normalizer-3.4.7.dist-info/top_level.txt,sha256=c_vZbitqecT2GfK3zdxSTLCn8C-6pGnHQY5o_5Y32M0,47 -charset_normalizer/__init__.py,sha256=OKRxRv2Zhnqk00tqkN0c1BtJjm165fWXLydE52IKuHc,1590 -charset_normalizer/__main__.py,sha256=yzYxMR-IhKRHYwcSlavEv8oGdwxsR89mr2X09qXGdps,109 -charset_normalizer/__pycache__/__init__.cpython-312.pyc,, -charset_normalizer/__pycache__/__main__.cpython-312.pyc,, -charset_normalizer/__pycache__/api.cpython-312.pyc,, -charset_normalizer/__pycache__/cd.cpython-312.pyc,, -charset_normalizer/__pycache__/constant.cpython-312.pyc,, -charset_normalizer/__pycache__/legacy.cpython-312.pyc,, -charset_normalizer/__pycache__/md.cpython-312.pyc,, -charset_normalizer/__pycache__/models.cpython-312.pyc,, -charset_normalizer/__pycache__/utils.cpython-312.pyc,, -charset_normalizer/__pycache__/version.cpython-312.pyc,, -charset_normalizer/api.py,sha256=387F3n23MlMu-xfSbFULW2DLGsBmVrZVGhnkiGXeKBo,38844 -charset_normalizer/cd.cpython-312-x86_64-linux-gnu.so,sha256=gOe65H__3O8_4a-aSVMB8gxHsRxVyQDUqqaIurPmIhE,15912 -charset_normalizer/cd.py,sha256=v0iPJweGsRegXywrM1LzUgqW9bJ1KFvIblQHP1jm5FQ,15174 -charset_normalizer/cli/__init__.py,sha256=D8I86lFk2-py45JvqxniTirSj_sFyE6sjaY_0-G1shc,136 -charset_normalizer/cli/__main__.py,sha256=E9FFSV1E2iOE_B2B1tJHQT9ExJqc60Ks_c-08sNawh8,11940 -charset_normalizer/cli/__pycache__/__init__.cpython-312.pyc,, -charset_normalizer/cli/__pycache__/__main__.cpython-312.pyc,, -charset_normalizer/constant.py,sha256=yvLAWDrdSC743Cu4amhwHLIO-FGuRTOTZouCzZKGikc,44431 -charset_normalizer/legacy.py,sha256=yBIFMNABNPE5JkdKOWyVo36fZtV9nm8bf37LrDWulz8,2661 -charset_normalizer/md.cpython-312-x86_64-linux-gnu.so,sha256=iYaQbya7NVRR7xg5FtK1yAKS5shmTFwmtkqqQbbvEWs,15912 -charset_normalizer/md.py,sha256=AYCdfDX79FrgoId3zXqmbCuDcbGr1NRuGqgJN94Rx9Q,30441 -charset_normalizer/models.py,sha256=FbaQnI6ECmVmyHRSvVM5fHNeMAQ3KSGdwLjGcQqWDws,12821 -charset_normalizer/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0 -charset_normalizer/utils.py,sha256=9cpi-_0-vC9pGDfuoarhC6VlF_Jxwx5Jsa_8I4w2D8k,12282 -charset_normalizer/version.py,sha256=2LxFuGp3BBuIwt95cp64y7v8bCNHcMAi08IfXt_47Co,115 diff --git a/.venv/lib/python3.12/site-packages/charset_normalizer-3.4.7.dist-info/WHEEL b/.venv/lib/python3.12/site-packages/charset_normalizer-3.4.7.dist-info/WHEEL deleted file mode 100644 index 0493eaf..0000000 --- a/.venv/lib/python3.12/site-packages/charset_normalizer-3.4.7.dist-info/WHEEL +++ /dev/null @@ -1,7 +0,0 @@ -Wheel-Version: 1.0 -Generator: setuptools (82.0.1) -Root-Is-Purelib: false -Tag: cp312-cp312-manylinux_2_17_x86_64 -Tag: cp312-cp312-manylinux2014_x86_64 -Tag: cp312-cp312-manylinux_2_28_x86_64 - diff --git a/.venv/lib/python3.12/site-packages/charset_normalizer-3.4.7.dist-info/entry_points.txt b/.venv/lib/python3.12/site-packages/charset_normalizer-3.4.7.dist-info/entry_points.txt deleted file mode 100644 index 65619e7..0000000 --- a/.venv/lib/python3.12/site-packages/charset_normalizer-3.4.7.dist-info/entry_points.txt +++ /dev/null @@ -1,2 +0,0 @@ -[console_scripts] -normalizer = charset_normalizer.cli:cli_detect diff --git a/.venv/lib/python3.12/site-packages/charset_normalizer-3.4.7.dist-info/licenses/LICENSE b/.venv/lib/python3.12/site-packages/charset_normalizer-3.4.7.dist-info/licenses/LICENSE deleted file mode 100644 index 9725772..0000000 --- a/.venv/lib/python3.12/site-packages/charset_normalizer-3.4.7.dist-info/licenses/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2025 TAHRI Ahmed R. - -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. diff --git a/.venv/lib/python3.12/site-packages/charset_normalizer-3.4.7.dist-info/top_level.txt b/.venv/lib/python3.12/site-packages/charset_normalizer-3.4.7.dist-info/top_level.txt deleted file mode 100644 index 89847be..0000000 --- a/.venv/lib/python3.12/site-packages/charset_normalizer-3.4.7.dist-info/top_level.txt +++ /dev/null @@ -1,2 +0,0 @@ -81d243bd2c585b0f4821__mypyc -charset_normalizer diff --git a/.venv/lib/python3.12/site-packages/charset_normalizer/__init__.py b/.venv/lib/python3.12/site-packages/charset_normalizer/__init__.py deleted file mode 100644 index 0d3a379..0000000 --- a/.venv/lib/python3.12/site-packages/charset_normalizer/__init__.py +++ /dev/null @@ -1,48 +0,0 @@ -""" -Charset-Normalizer -~~~~~~~~~~~~~~ -The Real First Universal Charset Detector. -A library that helps you read text from an unknown charset encoding. -Motivated by chardet, This package is trying to resolve the issue by taking a new approach. -All IANA character set names for which the Python core library provides codecs are supported. - -Basic usage: - >>> from charset_normalizer import from_bytes - >>> results = from_bytes('Bсеки човек има право на образование. Oбразованието!'.encode('utf_8')) - >>> best_guess = results.best() - >>> str(best_guess) - 'Bсеки човек има право на образование. Oбразованието!' - -Others methods and usages are available - see the full documentation -at . -:copyright: (c) 2021 by Ahmed TAHRI -:license: MIT, see LICENSE for more details. -""" - -from __future__ import annotations - -import logging - -from .api import from_bytes, from_fp, from_path, is_binary -from .legacy import detect -from .models import CharsetMatch, CharsetMatches -from .utils import set_logging_handler -from .version import VERSION, __version__ - -__all__ = ( - "from_fp", - "from_path", - "from_bytes", - "is_binary", - "detect", - "CharsetMatch", - "CharsetMatches", - "__version__", - "VERSION", - "set_logging_handler", -) - -# Attach a NullHandler to the top level logger by default -# https://docs.python.org/3.3/howto/logging.html#configuring-logging-for-a-library - -logging.getLogger("charset_normalizer").addHandler(logging.NullHandler()) diff --git a/.venv/lib/python3.12/site-packages/charset_normalizer/__main__.py b/.venv/lib/python3.12/site-packages/charset_normalizer/__main__.py deleted file mode 100644 index e0e76f7..0000000 --- a/.venv/lib/python3.12/site-packages/charset_normalizer/__main__.py +++ /dev/null @@ -1,6 +0,0 @@ -from __future__ import annotations - -from .cli import cli_detect - -if __name__ == "__main__": - cli_detect() diff --git a/.venv/lib/python3.12/site-packages/charset_normalizer/api.py b/.venv/lib/python3.12/site-packages/charset_normalizer/api.py deleted file mode 100644 index 50cb955..0000000 --- a/.venv/lib/python3.12/site-packages/charset_normalizer/api.py +++ /dev/null @@ -1,988 +0,0 @@ -from __future__ import annotations - -import logging -from os import PathLike -from typing import BinaryIO - -from .cd import ( - coherence_ratio, - encoding_languages, - mb_encoding_languages, - merge_coherence_ratios, -) -from .constant import ( - IANA_SUPPORTED, - IANA_SUPPORTED_SIMILAR, - TOO_BIG_SEQUENCE, - TOO_SMALL_SEQUENCE, - TRACE, -) -from .md import mess_ratio -from .models import CharsetMatch, CharsetMatches -from .utils import ( - any_specified_encoding, - cut_sequence_chunks, - iana_name, - identify_sig_or_bom, - is_multi_byte_encoding, - should_strip_sig_or_bom, -) - -logger = logging.getLogger("charset_normalizer") -explain_handler = logging.StreamHandler() -explain_handler.setFormatter( - logging.Formatter("%(asctime)s | %(levelname)s | %(message)s") -) - -# Pre-compute a reordered encoding list: multibyte first, then single-byte. -# This allows the mb_definitive_match optimization to fire earlier, skipping -# all single-byte encodings for genuine CJK content. Multibyte codecs -# hard-fail (UnicodeDecodeError) on single-byte data almost instantly, so -# testing them first costs negligible time for non-CJK files. -_mb_supported: list[str] = [] -_sb_supported: list[str] = [] - -for _supported_enc in IANA_SUPPORTED: - try: - if is_multi_byte_encoding(_supported_enc): - _mb_supported.append(_supported_enc) - else: - _sb_supported.append(_supported_enc) - except ImportError: - _sb_supported.append(_supported_enc) - -IANA_SUPPORTED_MB_FIRST: list[str] = _mb_supported + _sb_supported - - -def from_bytes( - sequences: bytes | bytearray, - steps: int = 5, - chunk_size: int = 512, - threshold: float = 0.2, - cp_isolation: list[str] | None = None, - cp_exclusion: list[str] | None = None, - preemptive_behaviour: bool = True, - explain: bool = False, - language_threshold: float = 0.1, - enable_fallback: bool = True, -) -> CharsetMatches: - """ - Given a raw bytes sequence, return the best possibles charset usable to render str objects. - If there is no results, it is a strong indicator that the source is binary/not text. - By default, the process will extract 5 blocks of 512o each to assess the mess and coherence of a given sequence. - And will give up a particular code page after 20% of measured mess. Those criteria are customizable at will. - - The preemptive behavior DOES NOT replace the traditional detection workflow, it prioritize a particular code page - but never take it for granted. Can improve the performance. - - You may want to focus your attention to some code page or/and not others, use cp_isolation and cp_exclusion for that - purpose. - - This function will strip the SIG in the payload/sequence every time except on UTF-16, UTF-32. - By default the library does not setup any handler other than the NullHandler, if you choose to set the 'explain' - toggle to True it will alter the logger configuration to add a StreamHandler that is suitable for debugging. - Custom logging format and handler can be set manually. - """ - - if not isinstance(sequences, (bytearray, bytes)): - raise TypeError( - "Expected object of type bytes or bytearray, got: {}".format( - type(sequences) - ) - ) - - if explain: - previous_logger_level: int = logger.level - logger.addHandler(explain_handler) - logger.setLevel(TRACE) - - length: int = len(sequences) - - if length == 0: - logger.debug("Encoding detection on empty bytes, assuming utf_8 intention.") - if explain: # Defensive: ensure exit path clean handler - logger.removeHandler(explain_handler) - logger.setLevel(previous_logger_level) - return CharsetMatches([CharsetMatch(sequences, "utf_8", 0.0, False, [], "")]) - - if cp_isolation is not None: - logger.log( - TRACE, - "cp_isolation is set. use this flag for debugging purpose. " - "limited list of encoding allowed : %s.", - ", ".join(cp_isolation), - ) - cp_isolation = [iana_name(cp, False) for cp in cp_isolation] - else: - cp_isolation = [] - - if cp_exclusion is not None: - logger.log( - TRACE, - "cp_exclusion is set. use this flag for debugging purpose. " - "limited list of encoding excluded : %s.", - ", ".join(cp_exclusion), - ) - cp_exclusion = [iana_name(cp, False) for cp in cp_exclusion] - else: - cp_exclusion = [] - - if length <= (chunk_size * steps): - logger.log( - TRACE, - "override steps (%i) and chunk_size (%i) as content does not fit (%i byte(s) given) parameters.", - steps, - chunk_size, - length, - ) - steps = 1 - chunk_size = length - - if steps > 1 and length / steps < chunk_size: - chunk_size = int(length / steps) - - is_too_small_sequence: bool = len(sequences) < TOO_SMALL_SEQUENCE - is_too_large_sequence: bool = len(sequences) >= TOO_BIG_SEQUENCE - - if is_too_small_sequence: - logger.log( - TRACE, - "Trying to detect encoding from a tiny portion of ({}) byte(s).".format( - length - ), - ) - elif is_too_large_sequence: - logger.log( - TRACE, - "Using lazy str decoding because the payload is quite large, ({}) byte(s).".format( - length - ), - ) - - prioritized_encodings: list[str] = [] - - specified_encoding: str | None = ( - any_specified_encoding(sequences) if preemptive_behaviour else None - ) - - if specified_encoding is not None: - prioritized_encodings.append(specified_encoding) - logger.log( - TRACE, - "Detected declarative mark in sequence. Priority +1 given for %s.", - specified_encoding, - ) - - tested: set[str] = set() - tested_but_hard_failure: list[str] = [] - tested_but_soft_failure: list[str] = [] - soft_failure_skip: set[str] = set() - success_fast_tracked: set[str] = set() - - # Cache for decoded payload deduplication: hash(decoded_payload) -> (mean_mess_ratio, cd_ratios_merged, passed) - # When multiple encodings decode to the exact same string, we can skip the expensive - # mess_ratio and coherence_ratio analysis and reuse the results from the first encoding. - payload_result_cache: dict[int, tuple[float, list[tuple[str, float]], bool]] = {} - - # When a definitive result (chaos=0.0 and good coherence) is found after testing - # the prioritized encodings (ascii, utf_8), we can significantly reduce the remaining - # work. Encodings that target completely different language families (e.g., Cyrillic - # when the definitive match is Latin) are skipped entirely. - # Additionally, for same-family encodings that pass chaos probing, we reuse the - # definitive match's coherence ratios instead of recomputing them — a major savings - # since coherence_ratio accounts for ~30% of total time on slow Latin files. - definitive_match_found: bool = False - definitive_target_languages: set[str] = set() - # After the definitive match fires, we cap the number of additional same-family - # single-byte encodings that pass chaos probing. Once we've accumulated enough - # good candidates (N), further same-family SB encodings are unlikely to produce - # a better best() result and just waste mess_ratio + coherence_ratio time. - # The first encoding to trigger the definitive match is NOT counted (it's already in). - post_definitive_sb_success_count: int = 0 - POST_DEFINITIVE_SB_CAP: int = 7 - - # When a non-UTF multibyte encoding passes chaos probing with significant multibyte - # content (decoded length < 98% of raw length), skip all remaining single-byte encodings. - # Rationale: multi-byte decoders (CJK) have strict byte-sequence validation — if they - # decode without error AND pass chaos probing with substantial multibyte content, the - # data is genuinely multibyte encoded. Single-byte encodings will always decode (every - # byte maps to something) but waste time on mess_ratio before failing. - # The 98% threshold prevents false triggers on files that happen to have a few valid - # multibyte pairs (e.g., cp424/_ude_1.txt where big5 decodes with 99% ratio). - mb_definitive_match_found: bool = False - - fallback_ascii: CharsetMatch | None = None - fallback_u8: CharsetMatch | None = None - fallback_specified: CharsetMatch | None = None - - results: CharsetMatches = CharsetMatches() - - early_stop_results: CharsetMatches = CharsetMatches() - - sig_encoding, sig_payload = identify_sig_or_bom(sequences) - - if sig_encoding is not None: - prioritized_encodings.append(sig_encoding) - logger.log( - TRACE, - "Detected a SIG or BOM mark on first %i byte(s). Priority +1 given for %s.", - len(sig_payload), - sig_encoding, - ) - - prioritized_encodings.append("ascii") - - if "utf_8" not in prioritized_encodings: - prioritized_encodings.append("utf_8") - - for encoding_iana in prioritized_encodings + IANA_SUPPORTED_MB_FIRST: - if cp_isolation and encoding_iana not in cp_isolation: - continue - - if cp_exclusion and encoding_iana in cp_exclusion: - continue - - if encoding_iana in tested: - continue - - tested.add(encoding_iana) - - decoded_payload: str | None = None - bom_or_sig_available: bool = sig_encoding == encoding_iana - strip_sig_or_bom: bool = bom_or_sig_available and should_strip_sig_or_bom( - encoding_iana - ) - - if encoding_iana in {"utf_16", "utf_32"} and not bom_or_sig_available: - logger.log( - TRACE, - "Encoding %s won't be tested as-is because it require a BOM. Will try some sub-encoder LE/BE.", - encoding_iana, - ) - continue - if encoding_iana in {"utf_7"} and not bom_or_sig_available: - logger.log( - TRACE, - "Encoding %s won't be tested as-is because detection is unreliable without BOM/SIG.", - encoding_iana, - ) - continue - - # Skip encodings similar to ones that already soft-failed (high mess ratio). - # Checked BEFORE the expensive decode attempt. - if encoding_iana in soft_failure_skip: - logger.log( - TRACE, - "%s is deemed too similar to a code page that was already considered unsuited. Continuing!", - encoding_iana, - ) - continue - - # Skip encodings that were already fast-tracked from a similar successful encoding. - if encoding_iana in success_fast_tracked: - logger.log( - TRACE, - "Skipping %s: already fast-tracked from a similar successful encoding.", - encoding_iana, - ) - continue - - try: - is_multi_byte_decoder: bool = is_multi_byte_encoding(encoding_iana) - except (ModuleNotFoundError, ImportError): # Defensive: - logger.log( - TRACE, - "Encoding %s does not provide an IncrementalDecoder", - encoding_iana, - ) - continue - - # When we've already found a definitive match (chaos=0.0 with good coherence) - # after testing the prioritized encodings, skip encodings that target - # completely different language families. This avoids running expensive - # mess_ratio + coherence_ratio on clearly unrelated candidates (e.g., Cyrillic - # when the definitive match is Latin-based). - if definitive_match_found: - if not is_multi_byte_decoder: - enc_languages = set(encoding_languages(encoding_iana)) - else: - enc_languages = set(mb_encoding_languages(encoding_iana)) - if not enc_languages.intersection(definitive_target_languages): - logger.log( - TRACE, - "Skipping %s: definitive match already found, this encoding targets different languages (%s vs %s).", - encoding_iana, - enc_languages, - definitive_target_languages, - ) - continue - - # After the definitive match, cap the number of additional same-family - # single-byte encodings that pass chaos probing. This avoids testing the - # tail of rare, low-value same-family encodings (mac_iceland, cp860, etc.) - # that almost never change best() but each cost ~1-2ms of mess_ratio + coherence. - if ( - definitive_match_found - and not is_multi_byte_decoder - and post_definitive_sb_success_count >= POST_DEFINITIVE_SB_CAP - ): - logger.log( - TRACE, - "Skipping %s: already accumulated %d same-family results after definitive match (cap=%d).", - encoding_iana, - post_definitive_sb_success_count, - POST_DEFINITIVE_SB_CAP, - ) - continue - - # When a multibyte encoding with significant multibyte content has already - # passed chaos probing, skip all single-byte encodings. They will either fail - # chaos probing (wasting mess_ratio time) or produce inferior results. - if mb_definitive_match_found and not is_multi_byte_decoder: - logger.log( - TRACE, - "Skipping single-byte %s: multi-byte definitive match already found.", - encoding_iana, - ) - continue - - try: - if is_too_large_sequence and is_multi_byte_decoder is False: - str( - ( - sequences[: int(50e4)] - if strip_sig_or_bom is False - else sequences[len(sig_payload) : int(50e4)] - ), - encoding=encoding_iana, - ) - else: - # UTF-7 BOM is encoded in modified Base64 whose byte boundary - # can overlap with the next character. Stripping raw SIG bytes - # before decoding may leave stray bytes that decode as garbage. - # Decode the full sequence and remove the leading BOM char instead. - # see https://github.com/jawah/charset_normalizer/issues/718 - # and https://github.com/jawah/charset_normalizer/issues/716 - if encoding_iana == "utf_7" and bom_or_sig_available: - decoded_payload = str( - sequences, - encoding=encoding_iana, - ) - if decoded_payload and decoded_payload[0] == "\ufeff": - decoded_payload = decoded_payload[1:] - else: - decoded_payload = str( - ( - sequences - if strip_sig_or_bom is False - else sequences[len(sig_payload) :] - ), - encoding=encoding_iana, - ) - except (UnicodeDecodeError, LookupError) as e: - if not isinstance(e, LookupError): - logger.log( - TRACE, - "Code page %s does not fit given bytes sequence at ALL. %s", - encoding_iana, - str(e), - ) - tested_but_hard_failure.append(encoding_iana) - continue - - r_ = range( - 0 if not bom_or_sig_available else len(sig_payload), - length, - int(length / steps), - ) - - multi_byte_bonus: bool = ( - is_multi_byte_decoder - and decoded_payload is not None - and len(decoded_payload) < length - ) - - if multi_byte_bonus: - logger.log( - TRACE, - "Code page %s is a multi byte encoding table and it appear that at least one character " - "was encoded using n-bytes.", - encoding_iana, - ) - - # Payload-hash deduplication: if another encoding already decoded to the - # exact same string, reuse its mess_ratio and coherence results entirely. - # This is strictly more general than the old IANA_SUPPORTED_SIMILAR approach - # because it catches ALL identical decoding, not just pre-mapped ones. - if decoded_payload is not None and not is_multi_byte_decoder: - payload_hash: int = hash(decoded_payload) - cached = payload_result_cache.get(payload_hash) - if cached is not None: - cached_mess, cached_cd, cached_passed = cached - if cached_passed: - # The previous encoding with identical output passed chaos probing. - fast_match = CharsetMatch( - sequences, - encoding_iana, - cached_mess, - bom_or_sig_available, - cached_cd, - ( - decoded_payload - if ( - is_too_large_sequence is False - or encoding_iana - in [specified_encoding, "ascii", "utf_8"] - ) - else None - ), - preemptive_declaration=specified_encoding, - ) - results.append(fast_match) - success_fast_tracked.add(encoding_iana) - logger.log( - TRACE, - "%s fast-tracked (identical decoded payload to a prior encoding, chaos=%f %%).", - encoding_iana, - round(cached_mess * 100, ndigits=3), - ) - - if ( - encoding_iana in [specified_encoding, "ascii", "utf_8"] - and cached_mess < 0.1 - ): - if cached_mess == 0.0: - logger.debug( - "Encoding detection: %s is most likely the one.", - fast_match.encoding, - ) - if explain: - logger.removeHandler(explain_handler) - logger.setLevel(previous_logger_level) - return CharsetMatches([fast_match]) - early_stop_results.append(fast_match) - - if ( - len(early_stop_results) - and (specified_encoding is None or specified_encoding in tested) - and "ascii" in tested - and "utf_8" in tested - ): - probable_result: CharsetMatch = early_stop_results.best() # type: ignore[assignment] - logger.debug( - "Encoding detection: %s is most likely the one.", - probable_result.encoding, - ) - if explain: - logger.removeHandler(explain_handler) - logger.setLevel(previous_logger_level) - return CharsetMatches([probable_result]) - - continue - else: - # The previous encoding with identical output failed chaos probing. - tested_but_soft_failure.append(encoding_iana) - logger.log( - TRACE, - "%s fast-skipped (identical decoded payload to a prior encoding that failed chaos probing).", - encoding_iana, - ) - # Prepare fallbacks for special encodings even when skipped. - if enable_fallback and encoding_iana in [ - "ascii", - "utf_8", - specified_encoding, - "utf_16", - "utf_32", - ]: - fallback_entry = CharsetMatch( - sequences, - encoding_iana, - threshold, - bom_or_sig_available, - [], - decoded_payload, - preemptive_declaration=specified_encoding, - ) - if encoding_iana == specified_encoding: - fallback_specified = fallback_entry - elif encoding_iana == "ascii": - fallback_ascii = fallback_entry - else: - fallback_u8 = fallback_entry - continue - - max_chunk_gave_up: int = int(len(r_) / 4) - - max_chunk_gave_up = max(max_chunk_gave_up, 2) - early_stop_count: int = 0 - lazy_str_hard_failure = False - - md_chunks: list[str] = [] - md_ratios = [] - - try: - for chunk in cut_sequence_chunks( - sequences, - encoding_iana, - r_, - chunk_size, - bom_or_sig_available, - strip_sig_or_bom, - sig_payload, - is_multi_byte_decoder, - decoded_payload, - ): - md_chunks.append(chunk) - - md_ratios.append( - mess_ratio( - chunk, - threshold, - explain is True and 1 <= len(cp_isolation) <= 2, - ) - ) - - if md_ratios[-1] >= threshold: - early_stop_count += 1 - - if (early_stop_count >= max_chunk_gave_up) or ( - bom_or_sig_available and strip_sig_or_bom is False - ): - break - except ( - UnicodeDecodeError - ) as e: # Lazy str loading may have missed something there - logger.log( - TRACE, - "LazyStr Loading: After MD chunk decode, code page %s does not fit given bytes sequence at ALL. %s", - encoding_iana, - str(e), - ) - early_stop_count = max_chunk_gave_up - lazy_str_hard_failure = True - - # We might want to check the sequence again with the whole content - # Only if initial MD tests passes - if ( - not lazy_str_hard_failure - and is_too_large_sequence - and not is_multi_byte_decoder - ): - try: - sequences[int(50e3) :].decode(encoding_iana, errors="strict") - except UnicodeDecodeError as e: - logger.log( - TRACE, - "LazyStr Loading: After final lookup, code page %s does not fit given bytes sequence at ALL. %s", - encoding_iana, - str(e), - ) - tested_but_hard_failure.append(encoding_iana) - continue - - mean_mess_ratio: float = sum(md_ratios) / len(md_ratios) if md_ratios else 0.0 - if mean_mess_ratio >= threshold or early_stop_count >= max_chunk_gave_up: - tested_but_soft_failure.append(encoding_iana) - if encoding_iana in IANA_SUPPORTED_SIMILAR: - soft_failure_skip.update(IANA_SUPPORTED_SIMILAR[encoding_iana]) - # Cache this soft-failure so identical decoding from other encodings - # can be skipped immediately. - if decoded_payload is not None and not is_multi_byte_decoder: - payload_result_cache.setdefault( - hash(decoded_payload), (mean_mess_ratio, [], False) - ) - logger.log( - TRACE, - "%s was excluded because of initial chaos probing. Gave up %i time(s). " - "Computed mean chaos is %f %%.", - encoding_iana, - early_stop_count, - round(mean_mess_ratio * 100, ndigits=3), - ) - # Preparing those fallbacks in case we got nothing. - if ( - enable_fallback - and encoding_iana - in ["ascii", "utf_8", specified_encoding, "utf_16", "utf_32"] - and not lazy_str_hard_failure - ): - fallback_entry = CharsetMatch( - sequences, - encoding_iana, - threshold, - bom_or_sig_available, - [], - decoded_payload, - preemptive_declaration=specified_encoding, - ) - if encoding_iana == specified_encoding: - fallback_specified = fallback_entry - elif encoding_iana == "ascii": - fallback_ascii = fallback_entry - else: - fallback_u8 = fallback_entry - continue - - logger.log( - TRACE, - "%s passed initial chaos probing. Mean measured chaos is %f %%", - encoding_iana, - round(mean_mess_ratio * 100, ndigits=3), - ) - - if not is_multi_byte_decoder: - target_languages: list[str] = encoding_languages(encoding_iana) - else: - target_languages = mb_encoding_languages(encoding_iana) - - if target_languages: - logger.log( - TRACE, - "{} should target any language(s) of {}".format( - encoding_iana, str(target_languages) - ), - ) - - cd_ratios = [] - - # Run coherence detection on all chunks. We previously tried limiting to - # 1-2 chunks for post-definitive encodings to save time, but this caused - # coverage regressions by producing unrepresentative coherence scores. - # The SB cap and language-family skip optimizations provide sufficient - # speedup without sacrificing coherence accuracy. - if encoding_iana != "ascii": - # We shall skip the CD when its about ASCII - # Most of the time its not relevant to run "language-detection" on it. - for chunk in md_chunks: - chunk_languages = coherence_ratio( - chunk, - language_threshold, - ",".join(target_languages) if target_languages else None, - ) - - cd_ratios.append(chunk_languages) - cd_ratios_merged = merge_coherence_ratios(cd_ratios) - else: - cd_ratios_merged = merge_coherence_ratios(cd_ratios) - - if cd_ratios_merged: - logger.log( - TRACE, - "We detected language {} using {}".format( - cd_ratios_merged, encoding_iana - ), - ) - - current_match = CharsetMatch( - sequences, - encoding_iana, - mean_mess_ratio, - bom_or_sig_available, - cd_ratios_merged, - ( - decoded_payload - if ( - is_too_large_sequence is False - or encoding_iana in [specified_encoding, "ascii", "utf_8"] - ) - else None - ), - preemptive_declaration=specified_encoding, - ) - - results.append(current_match) - - # Cache the successful result for payload-hash deduplication. - if decoded_payload is not None and not is_multi_byte_decoder: - payload_result_cache.setdefault( - hash(decoded_payload), - (mean_mess_ratio, cd_ratios_merged, True), - ) - - # Count post-definitive same-family SB successes for the early termination cap. - # Only count low-mess encodings (< 2%) toward the cap. High-mess encodings are - # marginal results that shouldn't prevent better-quality candidates from being - # tested. For example, iso8859_4 (mess=0%) should not be skipped just because - # 7 high-mess Latin encodings (cp1252 at 8%, etc.) were tried first. - if ( - definitive_match_found - and not is_multi_byte_decoder - and mean_mess_ratio < 0.02 - ): - post_definitive_sb_success_count += 1 - - if ( - encoding_iana in [specified_encoding, "ascii", "utf_8"] - and mean_mess_ratio < 0.1 - ): - # If md says nothing to worry about, then... stop immediately! - if mean_mess_ratio == 0.0: - logger.debug( - "Encoding detection: %s is most likely the one.", - current_match.encoding, - ) - if explain: # Defensive: ensure exit path clean handler - logger.removeHandler(explain_handler) - logger.setLevel(previous_logger_level) - return CharsetMatches([current_match]) - - early_stop_results.append(current_match) - - if ( - len(early_stop_results) - and (specified_encoding is None or specified_encoding in tested) - and "ascii" in tested - and "utf_8" in tested - ): - probable_result = early_stop_results.best() # type: ignore[assignment] - logger.debug( - "Encoding detection: %s is most likely the one.", - probable_result.encoding, # type: ignore[union-attr] - ) - if explain: # Defensive: ensure exit path clean handler - logger.removeHandler(explain_handler) - logger.setLevel(previous_logger_level) - - return CharsetMatches([probable_result]) - - # Once we find a result with good coherence (>= 0.5) after testing the - # prioritized encodings (ascii, utf_8), activate "definitive mode": skip - # encodings that target completely different language families. This avoids - # running expensive mess_ratio + coherence_ratio on clearly unrelated - # candidates (e.g., Cyrillic encodings when the match is Latin-based). - # We require coherence >= 0.5 to avoid false positives (e.g., cp1251 decoding - # Hebrew text with 0.0 chaos but wrong language detection at coherence 0.33). - if not definitive_match_found and not is_multi_byte_decoder: - best_coherence = ( - max((v for _, v in cd_ratios_merged), default=0.0) - if cd_ratios_merged - else 0.0 - ) - if best_coherence >= 0.5 and "ascii" in tested and "utf_8" in tested: - definitive_match_found = True - definitive_target_languages.update(target_languages) - logger.log( - TRACE, - "Definitive match found: %s (chaos=%.3f, coherence=%.2f). Encodings targeting different language families will be skipped.", - encoding_iana, - mean_mess_ratio, - best_coherence, - ) - - # When a non-UTF multibyte encoding passes chaos probing with significant - # multibyte content (decoded < 98% of raw), activate mb_definitive_match. - # This skips all remaining single-byte encodings which would either soft-fail - # (running expensive mess_ratio for nothing) or produce inferior results. - if ( - not mb_definitive_match_found - and is_multi_byte_decoder - and multi_byte_bonus - and decoded_payload is not None - and len(decoded_payload) < length * 0.98 - and encoding_iana - not in { - "utf_8", - "utf_8_sig", - "utf_16", - "utf_16_be", - "utf_16_le", - "utf_32", - "utf_32_be", - "utf_32_le", - "utf_7", - } - and "ascii" in tested - and "utf_8" in tested - ): - mb_definitive_match_found = True - logger.log( - TRACE, - "Multi-byte definitive match: %s (chaos=%.3f, decoded=%d/%d=%.1f%%). Single-byte encodings will be skipped.", - encoding_iana, - mean_mess_ratio, - len(decoded_payload), - length, - len(decoded_payload) / length * 100, - ) - - if encoding_iana == sig_encoding: - logger.debug( - "Encoding detection: %s is most likely the one as we detected a BOM or SIG within " - "the beginning of the sequence.", - encoding_iana, - ) - if explain: # Defensive: ensure exit path clean handler - logger.removeHandler(explain_handler) - logger.setLevel(previous_logger_level) - return CharsetMatches([results[encoding_iana]]) - - if len(results) == 0: - if fallback_u8 or fallback_ascii or fallback_specified: - logger.log( - TRACE, - "Nothing got out of the detection process. Using ASCII/UTF-8/Specified fallback.", - ) - - if fallback_specified: - logger.debug( - "Encoding detection: %s will be used as a fallback match", - fallback_specified.encoding, - ) - results.append(fallback_specified) - elif ( - (fallback_u8 and fallback_ascii is None) - or ( - fallback_u8 - and fallback_ascii - and fallback_u8.fingerprint != fallback_ascii.fingerprint - ) - or (fallback_u8 is not None) - ): - logger.debug("Encoding detection: utf_8 will be used as a fallback match") - results.append(fallback_u8) - elif fallback_ascii: - logger.debug("Encoding detection: ascii will be used as a fallback match") - results.append(fallback_ascii) - - if results: - logger.debug( - "Encoding detection: Found %s as plausible (best-candidate) for content. With %i alternatives.", - results.best().encoding, # type: ignore - len(results) - 1, - ) - else: - logger.debug("Encoding detection: Unable to determine any suitable charset.") - - if explain: - logger.removeHandler(explain_handler) - logger.setLevel(previous_logger_level) - - return results - - -def from_fp( - fp: BinaryIO, - steps: int = 5, - chunk_size: int = 512, - threshold: float = 0.20, - cp_isolation: list[str] | None = None, - cp_exclusion: list[str] | None = None, - preemptive_behaviour: bool = True, - explain: bool = False, - language_threshold: float = 0.1, - enable_fallback: bool = True, -) -> CharsetMatches: - """ - Same thing than the function from_bytes but using a file pointer that is already ready. - Will not close the file pointer. - """ - return from_bytes( - fp.read(), - steps, - chunk_size, - threshold, - cp_isolation, - cp_exclusion, - preemptive_behaviour, - explain, - language_threshold, - enable_fallback, - ) - - -def from_path( - path: str | bytes | PathLike, # type: ignore[type-arg] - steps: int = 5, - chunk_size: int = 512, - threshold: float = 0.20, - cp_isolation: list[str] | None = None, - cp_exclusion: list[str] | None = None, - preemptive_behaviour: bool = True, - explain: bool = False, - language_threshold: float = 0.1, - enable_fallback: bool = True, -) -> CharsetMatches: - """ - Same thing than the function from_bytes but with one extra step. Opening and reading given file path in binary mode. - Can raise IOError. - """ - with open(path, "rb") as fp: - return from_fp( - fp, - steps, - chunk_size, - threshold, - cp_isolation, - cp_exclusion, - preemptive_behaviour, - explain, - language_threshold, - enable_fallback, - ) - - -def is_binary( - fp_or_path_or_payload: PathLike | str | BinaryIO | bytes, # type: ignore[type-arg] - steps: int = 5, - chunk_size: int = 512, - threshold: float = 0.20, - cp_isolation: list[str] | None = None, - cp_exclusion: list[str] | None = None, - preemptive_behaviour: bool = True, - explain: bool = False, - language_threshold: float = 0.1, - enable_fallback: bool = False, -) -> bool: - """ - Detect if the given input (file, bytes, or path) points to a binary file. aka. not a string. - Based on the same main heuristic algorithms and default kwargs at the sole exception that fallbacks match - are disabled to be stricter around ASCII-compatible but unlikely to be a string. - """ - if isinstance(fp_or_path_or_payload, (str, PathLike)): - guesses = from_path( - fp_or_path_or_payload, - steps=steps, - chunk_size=chunk_size, - threshold=threshold, - cp_isolation=cp_isolation, - cp_exclusion=cp_exclusion, - preemptive_behaviour=preemptive_behaviour, - explain=explain, - language_threshold=language_threshold, - enable_fallback=enable_fallback, - ) - elif isinstance( - fp_or_path_or_payload, - ( - bytes, - bytearray, - ), - ): - guesses = from_bytes( - fp_or_path_or_payload, - steps=steps, - chunk_size=chunk_size, - threshold=threshold, - cp_isolation=cp_isolation, - cp_exclusion=cp_exclusion, - preemptive_behaviour=preemptive_behaviour, - explain=explain, - language_threshold=language_threshold, - enable_fallback=enable_fallback, - ) - else: - guesses = from_fp( - fp_or_path_or_payload, - steps=steps, - chunk_size=chunk_size, - threshold=threshold, - cp_isolation=cp_isolation, - cp_exclusion=cp_exclusion, - preemptive_behaviour=preemptive_behaviour, - explain=explain, - language_threshold=language_threshold, - enable_fallback=enable_fallback, - ) - - return not guesses diff --git a/.venv/lib/python3.12/site-packages/charset_normalizer/cd.cpython-312-x86_64-linux-gnu.so b/.venv/lib/python3.12/site-packages/charset_normalizer/cd.cpython-312-x86_64-linux-gnu.so deleted file mode 100755 index dffe3e4..0000000 Binary files a/.venv/lib/python3.12/site-packages/charset_normalizer/cd.cpython-312-x86_64-linux-gnu.so and /dev/null differ diff --git a/.venv/lib/python3.12/site-packages/charset_normalizer/cd.py b/.venv/lib/python3.12/site-packages/charset_normalizer/cd.py deleted file mode 100644 index 9545d35..0000000 --- a/.venv/lib/python3.12/site-packages/charset_normalizer/cd.py +++ /dev/null @@ -1,454 +0,0 @@ -from __future__ import annotations - -import importlib -from codecs import IncrementalDecoder -from collections import Counter -from functools import lru_cache -from typing import Counter as TypeCounter - -from .constant import ( - FREQUENCIES, - KO_NAMES, - LANGUAGE_SUPPORTED_COUNT, - TOO_SMALL_SEQUENCE, - ZH_NAMES, - _FREQUENCIES_SET, - _FREQUENCIES_RANK, -) -from .md import is_suspiciously_successive_range -from .models import CoherenceMatches -from .utils import ( - is_accentuated, - is_latin, - is_multi_byte_encoding, - is_unicode_range_secondary, - unicode_range, -) - - -def encoding_unicode_range(iana_name: str) -> list[str]: - """ - Return associated unicode ranges in a single byte code page. - """ - if is_multi_byte_encoding(iana_name): - raise OSError( # Defensive: - "Function not supported on multi-byte code page" - ) - - decoder = importlib.import_module(f"encodings.{iana_name}").IncrementalDecoder - - p: IncrementalDecoder = decoder(errors="ignore") - seen_ranges: dict[str, int] = {} - character_count: int = 0 - - for i in range(0x40, 0xFF): - chunk: str = p.decode(bytes([i])) - - if chunk: - character_range: str | None = unicode_range(chunk) - - if character_range is None: - continue - - if is_unicode_range_secondary(character_range) is False: - if character_range not in seen_ranges: - seen_ranges[character_range] = 0 - seen_ranges[character_range] += 1 - character_count += 1 - - return sorted( - [ - character_range - for character_range in seen_ranges - if seen_ranges[character_range] / character_count >= 0.15 - ] - ) - - -def unicode_range_languages(primary_range: str) -> list[str]: - """ - Return inferred languages used with a unicode range. - """ - languages: list[str] = [] - - for language, characters in FREQUENCIES.items(): - for character in characters: - if unicode_range(character) == primary_range: - languages.append(language) - break - - return languages - - -@lru_cache() -def encoding_languages(iana_name: str) -> list[str]: - """ - Single-byte encoding language association. Some code page are heavily linked to particular language(s). - This function does the correspondence. - """ - unicode_ranges: list[str] = encoding_unicode_range(iana_name) - primary_range: str | None = None - - for specified_range in unicode_ranges: - if "Latin" not in specified_range: - primary_range = specified_range - break - - if primary_range is None: - return ["Latin Based"] - - return unicode_range_languages(primary_range) - - -@lru_cache() -def mb_encoding_languages(iana_name: str) -> list[str]: - """ - Multi-byte encoding language association. Some code page are heavily linked to particular language(s). - This function does the correspondence. - """ - if ( - iana_name.startswith("shift_") - or iana_name.startswith("iso2022_jp") - or iana_name.startswith("euc_j") - or iana_name == "cp932" - ): - return ["Japanese"] - if iana_name.startswith("gb") or iana_name in ZH_NAMES: - return ["Chinese"] - if iana_name.startswith("iso2022_kr") or iana_name in KO_NAMES: - return ["Korean"] - - return [] - - -@lru_cache(maxsize=LANGUAGE_SUPPORTED_COUNT) -def get_target_features(language: str) -> tuple[bool, bool]: - """ - Determine main aspects from a supported language if it contains accents and if is pure Latin. - """ - target_have_accents: bool = False - target_pure_latin: bool = True - - for character in FREQUENCIES[language]: - if not target_have_accents and is_accentuated(character): - target_have_accents = True - if target_pure_latin and is_latin(character) is False: - target_pure_latin = False - - return target_have_accents, target_pure_latin - - -def alphabet_languages( - characters: list[str], ignore_non_latin: bool = False -) -> list[str]: - """ - Return associated languages associated to given characters. - """ - languages: list[tuple[str, float]] = [] - - characters_set: frozenset[str] = frozenset(characters) - source_have_accents = any(is_accentuated(character) for character in characters) - - for language, language_characters in FREQUENCIES.items(): - target_have_accents, target_pure_latin = get_target_features(language) - - if ignore_non_latin and target_pure_latin is False: - continue - - if target_have_accents is False and source_have_accents: - continue - - character_count: int = len(language_characters) - - character_match_count: int = len(_FREQUENCIES_SET[language] & characters_set) - - ratio: float = character_match_count / character_count - - if ratio >= 0.2: - languages.append((language, ratio)) - - languages = sorted(languages, key=lambda x: x[1], reverse=True) - - return [compatible_language[0] for compatible_language in languages] - - -def characters_popularity_compare( - language: str, ordered_characters: list[str] -) -> float: - """ - Determine if a ordered characters list (by occurrence from most appearance to rarest) match a particular language. - The result is a ratio between 0. (absolutely no correspondence) and 1. (near perfect fit). - Beware that is function is not strict on the match in order to ease the detection. (Meaning close match is 1.) - """ - if language not in FREQUENCIES: - raise ValueError(f"{language} not available") # Defensive: - - character_approved_count: int = 0 - frequencies_language_set: frozenset[str] = _FREQUENCIES_SET[language] - lang_rank: dict[str, int] = _FREQUENCIES_RANK[language] - - ordered_characters_count: int = len(ordered_characters) - target_language_characters_count: int = len(FREQUENCIES[language]) - - large_alphabet: bool = target_language_characters_count > 26 - - expected_projection_ratio: float = ( - target_language_characters_count / ordered_characters_count - ) - - # Pre-built rank dict for ordered_characters (avoids repeated list slicing). - ordered_rank: dict[str, int] = { - char: rank for rank, char in enumerate(ordered_characters) - } - - # Pre-compute characters common to both orderings. - # Avoids repeated `c in ordered_rank` dict lookups in the inner counts. - common_chars: list[tuple[int, int]] = [ - (lr, ordered_rank[c]) for c, lr in lang_rank.items() if c in ordered_rank - ] - - # Pre-extract lr and orr arrays for faster iteration in the inner loop. - # Plain integer loops with local arrays are much faster under mypyc than - # generator expression sums over a list of tuples. - common_count: int = len(common_chars) - common_lr: list[int] = [p[0] for p in common_chars] - common_orr: list[int] = [p[1] for p in common_chars] - - for character, character_rank in zip( - ordered_characters, range(0, ordered_characters_count) - ): - if character not in frequencies_language_set: - continue - - character_rank_in_language: int = lang_rank[character] - character_rank_projection: int = int(character_rank * expected_projection_ratio) - - if ( - large_alphabet is False - and abs(character_rank_projection - character_rank_in_language) > 4 - ): - continue - - if ( - large_alphabet is True - and abs(character_rank_projection - character_rank_in_language) - < target_language_characters_count / 3 - ): - character_approved_count += 1 - continue - - # Count how many characters appear "before" in both orderings, - # and how many appear "at or after" in both orderings. - # Single pass over pre-extracted arrays — much faster under mypyc - # than two generator expression sums. - before_match_count: int = 0 - after_match_count: int = 0 - for i in range(common_count): - lr_i: int = common_lr[i] - orr_i: int = common_orr[i] - if lr_i < character_rank_in_language: - if orr_i < character_rank: - before_match_count += 1 - else: - if orr_i >= character_rank: - after_match_count += 1 - - after_len: int = target_language_characters_count - character_rank_in_language - - if character_rank_in_language == 0 and before_match_count <= 4: - character_approved_count += 1 - continue - - if after_len == 0 and after_match_count <= 4: - character_approved_count += 1 - continue - - if ( - character_rank_in_language > 0 - and before_match_count / character_rank_in_language >= 0.4 - ) or (after_len > 0 and after_match_count / after_len >= 0.4): - character_approved_count += 1 - continue - - return character_approved_count / len(ordered_characters) - - -def alpha_unicode_split(decoded_sequence: str) -> list[str]: - """ - Given a decoded text sequence, return a list of str. Unicode range / alphabet separation. - Ex. a text containing English/Latin with a bit a Hebrew will return two items in the resulting list; - One containing the latin letters and the other hebrew. - """ - layers: dict[str, list[str]] = {} - - # Fast path: track single-layer key to skip dict iteration for single-script text. - single_layer_key: str | None = None - multi_layer: bool = False - - # Cache the last character_range and its resolved layer to avoid repeated - # is_suspiciously_successive_range calls for consecutive same-range chars. - prev_character_range: str | None = None - prev_layer_target: str | None = None - - for character in decoded_sequence: - if character.isalpha() is False: - continue - - # ASCII fast-path: a-z and A-Z are always "Basic Latin". - # Avoids unicode_range() function call overhead for the most common case. - character_ord: int = ord(character) - if character_ord < 128: - character_range: str | None = "Basic Latin" - else: - character_range = unicode_range(character) - - if character_range is None: - continue - - # Fast path: same range as previous character → reuse cached layer target. - if character_range == prev_character_range: - if prev_layer_target is not None: - layers[prev_layer_target].append(character) - continue - - layer_target_range: str | None = None - - if multi_layer: - for discovered_range in layers: - if ( - is_suspiciously_successive_range(discovered_range, character_range) - is False - ): - layer_target_range = discovered_range - break - elif single_layer_key is not None: - if ( - is_suspiciously_successive_range(single_layer_key, character_range) - is False - ): - layer_target_range = single_layer_key - - if layer_target_range is None: - layer_target_range = character_range - - if layer_target_range not in layers: - layers[layer_target_range] = [] - if single_layer_key is None: - single_layer_key = layer_target_range - else: - multi_layer = True - - layers[layer_target_range].append(character) - - # Cache for next iteration - prev_character_range = character_range - prev_layer_target = layer_target_range - - return ["".join(chars).lower() for chars in layers.values()] - - -def merge_coherence_ratios(results: list[CoherenceMatches]) -> CoherenceMatches: - """ - This function merge results previously given by the function coherence_ratio. - The return type is the same as coherence_ratio. - """ - per_language_ratios: dict[str, list[float]] = {} - for result in results: - for sub_result in result: - language, ratio = sub_result - if language not in per_language_ratios: - per_language_ratios[language] = [ratio] - continue - per_language_ratios[language].append(ratio) - - merge = [ - ( - language, - round( - sum(per_language_ratios[language]) / len(per_language_ratios[language]), - 4, - ), - ) - for language in per_language_ratios - ] - - return sorted(merge, key=lambda x: x[1], reverse=True) - - -def filter_alt_coherence_matches(results: CoherenceMatches) -> CoherenceMatches: - """ - We shall NOT return "English—" in CoherenceMatches because it is an alternative - of "English". This function only keeps the best match and remove the em-dash in it. - """ - index_results: dict[str, list[float]] = dict() - - for result in results: - language, ratio = result - no_em_name: str = language.replace("—", "") - - if no_em_name not in index_results: - index_results[no_em_name] = [] - - index_results[no_em_name].append(ratio) - - if any(len(index_results[e]) > 1 for e in index_results): - filtered_results: CoherenceMatches = [] - - for language in index_results: - filtered_results.append((language, max(index_results[language]))) - - return filtered_results - - return results - - -@lru_cache(maxsize=2048) -def coherence_ratio( - decoded_sequence: str, threshold: float = 0.1, lg_inclusion: str | None = None -) -> CoherenceMatches: - """ - Detect ANY language that can be identified in given sequence. The sequence will be analysed by layers. - A layer = Character extraction by alphabets/ranges. - """ - - results: list[tuple[str, float]] = [] - ignore_non_latin: bool = False - - sufficient_match_count: int = 0 - - lg_inclusion_list = lg_inclusion.split(",") if lg_inclusion is not None else [] - if "Latin Based" in lg_inclusion_list: - ignore_non_latin = True - lg_inclusion_list.remove("Latin Based") - - for layer in alpha_unicode_split(decoded_sequence): - sequence_frequencies: TypeCounter[str] = Counter(layer) - most_common = sequence_frequencies.most_common() - - character_count: int = len(layer) - - if character_count <= TOO_SMALL_SEQUENCE: - continue - - popular_character_ordered: list[str] = [c for c, o in most_common] - - for language in lg_inclusion_list or alphabet_languages( - popular_character_ordered, ignore_non_latin - ): - ratio: float = characters_popularity_compare( - language, popular_character_ordered - ) - - if ratio < threshold: - continue - elif ratio >= 0.8: - sufficient_match_count += 1 - - results.append((language, round(ratio, 4))) - - if sufficient_match_count >= 3: - break - - return sorted( - filter_alt_coherence_matches(results), key=lambda x: x[1], reverse=True - ) diff --git a/.venv/lib/python3.12/site-packages/charset_normalizer/cli/__init__.py b/.venv/lib/python3.12/site-packages/charset_normalizer/cli/__init__.py deleted file mode 100644 index 543a5a4..0000000 --- a/.venv/lib/python3.12/site-packages/charset_normalizer/cli/__init__.py +++ /dev/null @@ -1,8 +0,0 @@ -from __future__ import annotations - -from .__main__ import cli_detect, query_yes_no - -__all__ = ( - "cli_detect", - "query_yes_no", -) diff --git a/.venv/lib/python3.12/site-packages/charset_normalizer/cli/__main__.py b/.venv/lib/python3.12/site-packages/charset_normalizer/cli/__main__.py deleted file mode 100644 index ad843c1..0000000 --- a/.venv/lib/python3.12/site-packages/charset_normalizer/cli/__main__.py +++ /dev/null @@ -1,362 +0,0 @@ -from __future__ import annotations - -import argparse -import sys -import typing -from json import dumps -from os.path import abspath, basename, dirname, join, realpath -from platform import python_version -from unicodedata import unidata_version - -import charset_normalizer.md as md_module -from charset_normalizer import from_fp -from charset_normalizer.models import CliDetectionResult -from charset_normalizer.version import __version__ - - -def query_yes_no(question: str, default: str = "yes") -> bool: # Defensive: - """Ask a yes/no question via input() and return the answer as a bool.""" - prompt = " [Y/n] " if default == "yes" else " [y/N] " - - while True: - choice = input(question + prompt).strip().lower() - if not choice: - return default == "yes" - if choice in ("y", "yes"): - return True - if choice in ("n", "no"): - return False - print("Please respond with 'y' or 'n'.") - - -class FileType: - """Factory for creating file object types - - Instances of FileType are typically passed as type= arguments to the - ArgumentParser add_argument() method. - - Keyword Arguments: - - mode -- A string indicating how the file is to be opened. Accepts the - same values as the builtin open() function. - - bufsize -- The file's desired buffer size. Accepts the same values as - the builtin open() function. - - encoding -- The file's encoding. Accepts the same values as the - builtin open() function. - - errors -- A string indicating how encoding and decoding errors are to - be handled. Accepts the same value as the builtin open() function. - - Backported from CPython 3.12 - """ - - def __init__( - self, - mode: str = "r", - bufsize: int = -1, - encoding: str | None = None, - errors: str | None = None, - ): - self._mode = mode - self._bufsize = bufsize - self._encoding = encoding - self._errors = errors - - def __call__(self, string: str) -> typing.IO: # type: ignore[type-arg] - # the special argument "-" means sys.std{in,out} - if string == "-": - if "r" in self._mode: - return sys.stdin.buffer if "b" in self._mode else sys.stdin - elif any(c in self._mode for c in "wax"): - return sys.stdout.buffer if "b" in self._mode else sys.stdout - else: - msg = f'argument "-" with mode {self._mode}' - raise ValueError(msg) - - # all other arguments are used as file names - try: - return open(string, self._mode, self._bufsize, self._encoding, self._errors) - except OSError as e: - message = f"can't open '{string}': {e}" - raise argparse.ArgumentTypeError(message) - - def __repr__(self) -> str: - args = self._mode, self._bufsize - kwargs = [("encoding", self._encoding), ("errors", self._errors)] - args_str = ", ".join( - [repr(arg) for arg in args if arg != -1] - + [f"{kw}={arg!r}" for kw, arg in kwargs if arg is not None] - ) - return f"{type(self).__name__}({args_str})" - - -def cli_detect(argv: list[str] | None = None) -> int: - """ - CLI assistant using ARGV and ArgumentParser - :param argv: - :return: 0 if everything is fine, anything else equal trouble - """ - parser = argparse.ArgumentParser( - description="The Real First Universal Charset Detector. " - "Discover originating encoding used on text file. " - "Normalize text to unicode." - ) - - parser.add_argument( - "files", type=FileType("rb"), nargs="+", help="File(s) to be analysed" - ) - parser.add_argument( - "-v", - "--verbose", - action="store_true", - default=False, - dest="verbose", - help="Display complementary information about file if any. " - "Stdout will contain logs about the detection process.", - ) - parser.add_argument( - "-a", - "--with-alternative", - action="store_true", - default=False, - dest="alternatives", - help="Output complementary possibilities if any. Top-level JSON WILL be a list.", - ) - parser.add_argument( - "-n", - "--normalize", - action="store_true", - default=False, - dest="normalize", - help="Permit to normalize input file. If not set, program does not write anything.", - ) - parser.add_argument( - "-m", - "--minimal", - action="store_true", - default=False, - dest="minimal", - help="Only output the charset detected to STDOUT. Disabling JSON output.", - ) - parser.add_argument( - "-r", - "--replace", - action="store_true", - default=False, - dest="replace", - help="Replace file when trying to normalize it instead of creating a new one.", - ) - parser.add_argument( - "-f", - "--force", - action="store_true", - default=False, - dest="force", - help="Replace file without asking if you are sure, use this flag with caution.", - ) - parser.add_argument( - "-i", - "--no-preemptive", - action="store_true", - default=False, - dest="no_preemptive", - help="Disable looking at a charset declaration to hint the detector.", - ) - parser.add_argument( - "-t", - "--threshold", - action="store", - default=0.2, - type=float, - dest="threshold", - help="Define a custom maximum amount of noise allowed in decoded content. 0. <= noise <= 1.", - ) - parser.add_argument( - "--version", - action="version", - version="Charset-Normalizer {} - Python {} - Unicode {} - SpeedUp {}".format( - __version__, - python_version(), - unidata_version, - "OFF" if md_module.__file__.lower().endswith(".py") else "ON", - ), - help="Show version information and exit.", - ) - - args = parser.parse_args(argv) - - if args.replace is True and args.normalize is False: - if args.files: - for my_file in args.files: - my_file.close() - print("Use --replace in addition of --normalize only.", file=sys.stderr) - return 1 - - if args.force is True and args.replace is False: - if args.files: - for my_file in args.files: - my_file.close() - print("Use --force in addition of --replace only.", file=sys.stderr) - return 1 - - if args.threshold < 0.0 or args.threshold > 1.0: - if args.files: - for my_file in args.files: - my_file.close() - print("--threshold VALUE should be between 0. AND 1.", file=sys.stderr) - return 1 - - x_ = [] - - for my_file in args.files: - matches = from_fp( - my_file, - threshold=args.threshold, - explain=args.verbose, - preemptive_behaviour=args.no_preemptive is False, - ) - - best_guess = matches.best() - - if best_guess is None: - print( - 'Unable to identify originating encoding for "{}". {}'.format( - my_file.name, - ( - "Maybe try increasing maximum amount of chaos." - if args.threshold < 1.0 - else "" - ), - ), - file=sys.stderr, - ) - x_.append( - CliDetectionResult( - abspath(my_file.name), - None, - [], - [], - "Unknown", - [], - False, - 1.0, - 0.0, - None, - True, - ) - ) - else: - cli_result = CliDetectionResult( - abspath(my_file.name), - best_guess.encoding, - best_guess.encoding_aliases, - [ - cp - for cp in best_guess.could_be_from_charset - if cp != best_guess.encoding - ], - best_guess.language, - best_guess.alphabets, - best_guess.bom, - best_guess.percent_chaos, - best_guess.percent_coherence, - None, - True, - ) - x_.append(cli_result) - - if len(matches) > 1 and args.alternatives: - for el in matches: - if el != best_guess: - x_.append( - CliDetectionResult( - abspath(my_file.name), - el.encoding, - el.encoding_aliases, - [ - cp - for cp in el.could_be_from_charset - if cp != el.encoding - ], - el.language, - el.alphabets, - el.bom, - el.percent_chaos, - el.percent_coherence, - None, - False, - ) - ) - - if args.normalize is True: - if best_guess.encoding.startswith("utf") is True: - print( - '"{}" file does not need to be normalized, as it already came from unicode.'.format( - my_file.name - ), - file=sys.stderr, - ) - if my_file.closed is False: - my_file.close() - continue - - dir_path = dirname(realpath(my_file.name)) - file_name = basename(realpath(my_file.name)) - - o_: list[str] = file_name.split(".") - - if args.replace is False: - o_.insert(-1, best_guess.encoding) - if my_file.closed is False: - my_file.close() - elif ( - args.force is False - and query_yes_no( - 'Are you sure to normalize "{}" by replacing it ?'.format( - my_file.name - ), - "no", - ) - is False - ): - if my_file.closed is False: - my_file.close() - continue - - try: - cli_result.unicode_path = join(dir_path, ".".join(o_)) - - with open(cli_result.unicode_path, "wb") as fp: - fp.write(best_guess.output()) - except OSError as e: # Defensive: - print(str(e), file=sys.stderr) - if my_file.closed is False: - my_file.close() - return 2 - - if my_file.closed is False: - my_file.close() - - if args.minimal is False: - print( - dumps( - [el.__dict__ for el in x_] if len(x_) > 1 else x_[0].__dict__, - ensure_ascii=True, - indent=4, - ) - ) - else: - for my_file in args.files: - print( - ", ".join( - [ - el.encoding or "undefined" - for el in x_ - if el.path == abspath(my_file.name) - ] - ) - ) - - return 0 - - -if __name__ == "__main__": # Defensive: - cli_detect() diff --git a/.venv/lib/python3.12/site-packages/charset_normalizer/constant.py b/.venv/lib/python3.12/site-packages/charset_normalizer/constant.py deleted file mode 100644 index e1297d2..0000000 --- a/.venv/lib/python3.12/site-packages/charset_normalizer/constant.py +++ /dev/null @@ -1,2050 +0,0 @@ -from __future__ import annotations - -from codecs import BOM_UTF8, BOM_UTF16_BE, BOM_UTF16_LE, BOM_UTF32_BE, BOM_UTF32_LE -from encodings.aliases import aliases -from re import IGNORECASE -from re import compile as re_compile - -# Contain for each eligible encoding a list of/item bytes SIG/BOM -ENCODING_MARKS: dict[str, bytes | list[bytes]] = { - "utf_8": BOM_UTF8, - "utf_7": [ - b"\x2b\x2f\x76\x38\x2d", - b"\x2b\x2f\x76\x38", - b"\x2b\x2f\x76\x39", - b"\x2b\x2f\x76\x2b", - b"\x2b\x2f\x76\x2f", - ], - "gb18030": b"\x84\x31\x95\x33", - "utf_32": [BOM_UTF32_BE, BOM_UTF32_LE], - "utf_16": [BOM_UTF16_BE, BOM_UTF16_LE], -} - -TOO_SMALL_SEQUENCE: int = 32 -TOO_BIG_SEQUENCE: int = int(10e6) - -UTF8_MAXIMAL_ALLOCATION: int = 1_112_064 - -# Up-to-date Unicode ucd/17.0.0 -UNICODE_RANGES_COMBINED: dict[str, range] = { - "Control character": range(32), - "Basic Latin": range(32, 128), - "Latin-1 Supplement": range(128, 256), - "Latin Extended-A": range(256, 384), - "Latin Extended-B": range(384, 592), - "IPA Extensions": range(592, 688), - "Spacing Modifier Letters": range(688, 768), - "Combining Diacritical Marks": range(768, 880), - "Greek and Coptic": range(880, 1024), - "Cyrillic": range(1024, 1280), - "Cyrillic Supplement": range(1280, 1328), - "Armenian": range(1328, 1424), - "Hebrew": range(1424, 1536), - "Arabic": range(1536, 1792), - "Syriac": range(1792, 1872), - "Arabic Supplement": range(1872, 1920), - "Thaana": range(1920, 1984), - "NKo": range(1984, 2048), - "Samaritan": range(2048, 2112), - "Mandaic": range(2112, 2144), - "Syriac Supplement": range(2144, 2160), - "Arabic Extended-B": range(2160, 2208), - "Arabic Extended-A": range(2208, 2304), - "Devanagari": range(2304, 2432), - "Bengali": range(2432, 2560), - "Gurmukhi": range(2560, 2688), - "Gujarati": range(2688, 2816), - "Oriya": range(2816, 2944), - "Tamil": range(2944, 3072), - "Telugu": range(3072, 3200), - "Kannada": range(3200, 3328), - "Malayalam": range(3328, 3456), - "Sinhala": range(3456, 3584), - "Thai": range(3584, 3712), - "Lao": range(3712, 3840), - "Tibetan": range(3840, 4096), - "Myanmar": range(4096, 4256), - "Georgian": range(4256, 4352), - "Hangul Jamo": range(4352, 4608), - "Ethiopic": range(4608, 4992), - "Ethiopic Supplement": range(4992, 5024), - "Cherokee": range(5024, 5120), - "Unified Canadian Aboriginal Syllabics": range(5120, 5760), - "Ogham": range(5760, 5792), - "Runic": range(5792, 5888), - "Tagalog": range(5888, 5920), - "Hanunoo": range(5920, 5952), - "Buhid": range(5952, 5984), - "Tagbanwa": range(5984, 6016), - "Khmer": range(6016, 6144), - "Mongolian": range(6144, 6320), - "Unified Canadian Aboriginal Syllabics Extended": range(6320, 6400), - "Limbu": range(6400, 6480), - "Tai Le": range(6480, 6528), - "New Tai Lue": range(6528, 6624), - "Khmer Symbols": range(6624, 6656), - "Buginese": range(6656, 6688), - "Tai Tham": range(6688, 6832), - "Combining Diacritical Marks Extended": range(6832, 6912), - "Balinese": range(6912, 7040), - "Sundanese": range(7040, 7104), - "Batak": range(7104, 7168), - "Lepcha": range(7168, 7248), - "Ol Chiki": range(7248, 7296), - "Cyrillic Extended-C": range(7296, 7312), - "Georgian Extended": range(7312, 7360), - "Sundanese Supplement": range(7360, 7376), - "Vedic Extensions": range(7376, 7424), - "Phonetic Extensions": range(7424, 7552), - "Phonetic Extensions Supplement": range(7552, 7616), - "Combining Diacritical Marks Supplement": range(7616, 7680), - "Latin Extended Additional": range(7680, 7936), - "Greek Extended": range(7936, 8192), - "General Punctuation": range(8192, 8304), - "Superscripts and Subscripts": range(8304, 8352), - "Currency Symbols": range(8352, 8400), - "Combining Diacritical Marks for Symbols": range(8400, 8448), - "Letterlike Symbols": range(8448, 8528), - "Number Forms": range(8528, 8592), - "Arrows": range(8592, 8704), - "Mathematical Operators": range(8704, 8960), - "Miscellaneous Technical": range(8960, 9216), - "Control Pictures": range(9216, 9280), - "Optical Character Recognition": range(9280, 9312), - "Enclosed Alphanumerics": range(9312, 9472), - "Box Drawing": range(9472, 9600), - "Block Elements": range(9600, 9632), - "Geometric Shapes": range(9632, 9728), - "Miscellaneous Symbols": range(9728, 9984), - "Dingbats": range(9984, 10176), - "Miscellaneous Mathematical Symbols-A": range(10176, 10224), - "Supplemental Arrows-A": range(10224, 10240), - "Braille Patterns": range(10240, 10496), - "Supplemental Arrows-B": range(10496, 10624), - "Miscellaneous Mathematical Symbols-B": range(10624, 10752), - "Supplemental Mathematical Operators": range(10752, 11008), - "Miscellaneous Symbols and Arrows": range(11008, 11264), - "Glagolitic": range(11264, 11360), - "Latin Extended-C": range(11360, 11392), - "Coptic": range(11392, 11520), - "Georgian Supplement": range(11520, 11568), - "Tifinagh": range(11568, 11648), - "Ethiopic Extended": range(11648, 11744), - "Cyrillic Extended-A": range(11744, 11776), - "Supplemental Punctuation": range(11776, 11904), - "CJK Radicals Supplement": range(11904, 12032), - "Kangxi Radicals": range(12032, 12256), - "Ideographic Description Characters": range(12272, 12288), - "CJK Symbols and Punctuation": range(12288, 12352), - "Hiragana": range(12352, 12448), - "Katakana": range(12448, 12544), - "Bopomofo": range(12544, 12592), - "Hangul Compatibility Jamo": range(12592, 12688), - "Kanbun": range(12688, 12704), - "Bopomofo Extended": range(12704, 12736), - "CJK Strokes": range(12736, 12784), - "Katakana Phonetic Extensions": range(12784, 12800), - "Enclosed CJK Letters and Months": range(12800, 13056), - "CJK Compatibility": range(13056, 13312), - "CJK Unified Ideographs Extension A": range(13312, 19904), - "Yijing Hexagram Symbols": range(19904, 19968), - "CJK Unified Ideographs": range(19968, 40960), - "Yi Syllables": range(40960, 42128), - "Yi Radicals": range(42128, 42192), - "Lisu": range(42192, 42240), - "Vai": range(42240, 42560), - "Cyrillic Extended-B": range(42560, 42656), - "Bamum": range(42656, 42752), - "Modifier Tone Letters": range(42752, 42784), - "Latin Extended-D": range(42784, 43008), - "Syloti Nagri": range(43008, 43056), - "Common Indic Number Forms": range(43056, 43072), - "Phags-pa": range(43072, 43136), - "Saurashtra": range(43136, 43232), - "Devanagari Extended": range(43232, 43264), - "Kayah Li": range(43264, 43312), - "Rejang": range(43312, 43360), - "Hangul Jamo Extended-A": range(43360, 43392), - "Javanese": range(43392, 43488), - "Myanmar Extended-B": range(43488, 43520), - "Cham": range(43520, 43616), - "Myanmar Extended-A": range(43616, 43648), - "Tai Viet": range(43648, 43744), - "Meetei Mayek Extensions": range(43744, 43776), - "Ethiopic Extended-A": range(43776, 43824), - "Latin Extended-E": range(43824, 43888), - "Cherokee Supplement": range(43888, 43968), - "Meetei Mayek": range(43968, 44032), - "Hangul Syllables": range(44032, 55216), - "Hangul Jamo Extended-B": range(55216, 55296), - "High Surrogates": range(55296, 56192), - "High Private Use Surrogates": range(56192, 56320), - "Low Surrogates": range(56320, 57344), - "Private Use Area": range(57344, 63744), - "CJK Compatibility Ideographs": range(63744, 64256), - "Alphabetic Presentation Forms": range(64256, 64336), - "Arabic Presentation Forms-A": range(64336, 65024), - "Variation Selectors": range(65024, 65040), - "Vertical Forms": range(65040, 65056), - "Combining Half Marks": range(65056, 65072), - "CJK Compatibility Forms": range(65072, 65104), - "Small Form Variants": range(65104, 65136), - "Arabic Presentation Forms-B": range(65136, 65280), - "Halfwidth and Fullwidth Forms": range(65280, 65520), - "Specials": range(65520, 65536), - "Linear B Syllabary": range(65536, 65664), - "Linear B Ideograms": range(65664, 65792), - "Aegean Numbers": range(65792, 65856), - "Ancient Greek Numbers": range(65856, 65936), - "Ancient Symbols": range(65936, 66000), - "Phaistos Disc": range(66000, 66048), - "Lycian": range(66176, 66208), - "Carian": range(66208, 66272), - "Coptic Epact Numbers": range(66272, 66304), - "Old Italic": range(66304, 66352), - "Gothic": range(66352, 66384), - "Old Permic": range(66384, 66432), - "Ugaritic": range(66432, 66464), - "Old Persian": range(66464, 66528), - "Deseret": range(66560, 66640), - "Shavian": range(66640, 66688), - "Osmanya": range(66688, 66736), - "Osage": range(66736, 66816), - "Elbasan": range(66816, 66864), - "Caucasian Albanian": range(66864, 66928), - "Vithkuqi": range(66928, 67008), - "Todhri": range(67008, 67072), - "Linear A": range(67072, 67456), - "Latin Extended-F": range(67456, 67520), - "Cypriot Syllabary": range(67584, 67648), - "Imperial Aramaic": range(67648, 67680), - "Palmyrene": range(67680, 67712), - "Nabataean": range(67712, 67760), - "Hatran": range(67808, 67840), - "Phoenician": range(67840, 67872), - "Lydian": range(67872, 67904), - "Sidetic": range(67904, 67936), - "Meroitic Hieroglyphs": range(67968, 68000), - "Meroitic Cursive": range(68000, 68096), - "Kharoshthi": range(68096, 68192), - "Old South Arabian": range(68192, 68224), - "Old North Arabian": range(68224, 68256), - "Manichaean": range(68288, 68352), - "Avestan": range(68352, 68416), - "Inscriptional Parthian": range(68416, 68448), - "Inscriptional Pahlavi": range(68448, 68480), - "Psalter Pahlavi": range(68480, 68528), - "Old Turkic": range(68608, 68688), - "Old Hungarian": range(68736, 68864), - "Hanifi Rohingya": range(68864, 68928), - "Garay": range(68928, 69008), - "Rumi Numeral Symbols": range(69216, 69248), - "Yezidi": range(69248, 69312), - "Arabic Extended-C": range(69312, 69376), - "Old Sogdian": range(69376, 69424), - "Sogdian": range(69424, 69488), - "Old Uyghur": range(69488, 69552), - "Chorasmian": range(69552, 69600), - "Elymaic": range(69600, 69632), - "Brahmi": range(69632, 69760), - "Kaithi": range(69760, 69840), - "Sora Sompeng": range(69840, 69888), - "Chakma": range(69888, 69968), - "Mahajani": range(69968, 70016), - "Sharada": range(70016, 70112), - "Sinhala Archaic Numbers": range(70112, 70144), - "Khojki": range(70144, 70224), - "Multani": range(70272, 70320), - "Khudawadi": range(70320, 70400), - "Grantha": range(70400, 70528), - "Tulu-Tigalari": range(70528, 70656), - "Newa": range(70656, 70784), - "Tirhuta": range(70784, 70880), - "Siddham": range(71040, 71168), - "Modi": range(71168, 71264), - "Mongolian Supplement": range(71264, 71296), - "Takri": range(71296, 71376), - "Myanmar Extended-C": range(71376, 71424), - "Ahom": range(71424, 71504), - "Dogra": range(71680, 71760), - "Warang Citi": range(71840, 71936), - "Dives Akuru": range(71936, 72032), - "Nandinagari": range(72096, 72192), - "Zanabazar Square": range(72192, 72272), - "Soyombo": range(72272, 72368), - "Unified Canadian Aboriginal Syllabics Extended-A": range(72368, 72384), - "Pau Cin Hau": range(72384, 72448), - "Devanagari Extended-A": range(72448, 72544), - "Sharada Supplement": range(72544, 72576), - "Sunuwar": range(72640, 72704), - "Bhaiksuki": range(72704, 72816), - "Marchen": range(72816, 72896), - "Masaram Gondi": range(72960, 73056), - "Gunjala Gondi": range(73056, 73136), - "Tolong Siki": range(73136, 73200), - "Makasar": range(73440, 73472), - "Kawi": range(73472, 73568), - "Lisu Supplement": range(73648, 73664), - "Tamil Supplement": range(73664, 73728), - "Cuneiform": range(73728, 74752), - "Cuneiform Numbers and Punctuation": range(74752, 74880), - "Early Dynastic Cuneiform": range(74880, 75088), - "Cypro-Minoan": range(77712, 77824), - "Egyptian Hieroglyphs": range(77824, 78896), - "Egyptian Hieroglyph Format Controls": range(78896, 78944), - "Egyptian Hieroglyphs Extended-A": range(78944, 82944), - "Anatolian Hieroglyphs": range(82944, 83584), - "Gurung Khema": range(90368, 90432), - "Bamum Supplement": range(92160, 92736), - "Mro": range(92736, 92784), - "Tangsa": range(92784, 92880), - "Bassa Vah": range(92880, 92928), - "Pahawh Hmong": range(92928, 93072), - "Kirat Rai": range(93504, 93568), - "Medefaidrin": range(93760, 93856), - "Beria Erfe": range(93856, 93920), - "Miao": range(93952, 94112), - "Ideographic Symbols and Punctuation": range(94176, 94208), - "Tangut": range(94208, 100352), - "Tangut Components": range(100352, 101120), - "Khitan Small Script": range(101120, 101632), - "Tangut Supplement": range(101632, 101760), - "Tangut Components Supplement": range(101760, 101888), - "Kana Extended-B": range(110576, 110592), - "Kana Supplement": range(110592, 110848), - "Kana Extended-A": range(110848, 110896), - "Small Kana Extension": range(110896, 110960), - "Nushu": range(110960, 111360), - "Duployan": range(113664, 113824), - "Shorthand Format Controls": range(113824, 113840), - "Symbols for Legacy Computing Supplement": range(117760, 118464), - "Miscellaneous Symbols Supplement": range(118464, 118528), - "Znamenny Musical Notation": range(118528, 118736), - "Byzantine Musical Symbols": range(118784, 119040), - "Musical Symbols": range(119040, 119296), - "Ancient Greek Musical Notation": range(119296, 119376), - "Kaktovik Numerals": range(119488, 119520), - "Mayan Numerals": range(119520, 119552), - "Tai Xuan Jing Symbols": range(119552, 119648), - "Counting Rod Numerals": range(119648, 119680), - "Mathematical Alphanumeric Symbols": range(119808, 120832), - "Sutton SignWriting": range(120832, 121520), - "Latin Extended-G": range(122624, 122880), - "Glagolitic Supplement": range(122880, 122928), - "Cyrillic Extended-D": range(122928, 123024), - "Nyiakeng Puachue Hmong": range(123136, 123216), - "Toto": range(123536, 123584), - "Wancho": range(123584, 123648), - "Nag Mundari": range(124112, 124160), - "Ol Onal": range(124368, 124416), - "Tai Yo": range(124608, 124672), - "Ethiopic Extended-B": range(124896, 124928), - "Mende Kikakui": range(124928, 125152), - "Adlam": range(125184, 125280), - "Indic Siyaq Numbers": range(126064, 126144), - "Ottoman Siyaq Numbers": range(126208, 126288), - "Arabic Mathematical Alphabetic Symbols": range(126464, 126720), - "Mahjong Tiles": range(126976, 127024), - "Domino Tiles": range(127024, 127136), - "Playing Cards": range(127136, 127232), - "Enclosed Alphanumeric Supplement": range(127232, 127488), - "Enclosed Ideographic Supplement": range(127488, 127744), - "Miscellaneous Symbols and Pictographs": range(127744, 128512), - "Emoticons": range(128512, 128592), - "Ornamental Dingbats": range(128592, 128640), - "Transport and Map Symbols": range(128640, 128768), - "Alchemical Symbols": range(128768, 128896), - "Geometric Shapes Extended": range(128896, 129024), - "Supplemental Arrows-C": range(129024, 129280), - "Supplemental Symbols and Pictographs": range(129280, 129536), - "Chess Symbols": range(129536, 129648), - "Symbols and Pictographs Extended-A": range(129648, 129792), - "Symbols for Legacy Computing": range(129792, 130048), - "CJK Unified Ideographs Extension B": range(131072, 173792), - "CJK Unified Ideographs Extension C": range(173824, 177984), - "CJK Unified Ideographs Extension D": range(177984, 178208), - "CJK Unified Ideographs Extension E": range(178208, 183984), - "CJK Unified Ideographs Extension F": range(183984, 191472), - "CJK Unified Ideographs Extension I": range(191472, 192096), - "CJK Compatibility Ideographs Supplement": range(194560, 195104), - "CJK Unified Ideographs Extension G": range(196608, 201552), - "CJK Unified Ideographs Extension H": range(201552, 205744), - "CJK Unified Ideographs Extension J": range(205744, 210048), - "Tags": range(917504, 917632), - "Variation Selectors Supplement": range(917760, 918000), - "Supplementary Private Use Area-A": range(983040, 1048576), - "Supplementary Private Use Area-B": range(1048576, 1114112), -} - - -UNICODE_SECONDARY_RANGE_KEYWORD: list[str] = [ - "Supplement", - "Extended", - "Extensions", - "Modifier", - "Marks", - "Punctuation", - "Symbols", - "Forms", - "Operators", - "Miscellaneous", - "Drawing", - "Block", - "Shapes", - "Supplemental", - "Tags", -] - -RE_POSSIBLE_ENCODING_INDICATION = re_compile( - r"(?:(?:encoding)|(?:charset)|(?:coding))(?:[\:= ]{1,10})(?:[\"\']?)([a-zA-Z0-9\-_]+)(?:[\"\']?)", - IGNORECASE, -) - -IANA_NO_ALIASES = [ - "cp720", - "cp737", - "cp856", - "cp874", - "cp875", - "cp1006", - "koi8_r", - "koi8_t", - "koi8_u", -] - -IANA_SUPPORTED: list[str] = sorted( - filter( - lambda x: x.endswith("_codec") is False - and x not in {"rot_13", "tactis", "mbcs"}, - list(set(aliases.values())) + IANA_NO_ALIASES, - ) -) - -IANA_SUPPORTED_COUNT: int = len(IANA_SUPPORTED) - -# pre-computed code page that are similar using the function cp_similarity. -IANA_SUPPORTED_SIMILAR: dict[str, list[str]] = { - "cp037": ["cp1026", "cp1140", "cp273", "cp500"], - "cp1026": ["cp037", "cp1140", "cp273", "cp500"], - "cp1125": ["cp866"], - "cp1140": ["cp037", "cp1026", "cp273", "cp500"], - "cp1250": ["iso8859_2"], - "cp1251": ["kz1048", "ptcp154"], - "cp1252": ["iso8859_15", "iso8859_9", "latin_1"], - "cp1253": ["iso8859_7"], - "cp1254": ["iso8859_15", "iso8859_9", "latin_1"], - "cp1257": ["iso8859_13"], - "cp273": ["cp037", "cp1026", "cp1140", "cp500"], - "cp437": ["cp850", "cp858", "cp860", "cp861", "cp862", "cp863", "cp865"], - "cp500": ["cp037", "cp1026", "cp1140", "cp273"], - "cp850": ["cp437", "cp857", "cp858", "cp865"], - "cp857": ["cp850", "cp858", "cp865"], - "cp858": ["cp437", "cp850", "cp857", "cp865"], - "cp860": ["cp437", "cp861", "cp862", "cp863", "cp865"], - "cp861": ["cp437", "cp860", "cp862", "cp863", "cp865"], - "cp862": ["cp437", "cp860", "cp861", "cp863", "cp865"], - "cp863": ["cp437", "cp860", "cp861", "cp862", "cp865"], - "cp865": ["cp437", "cp850", "cp857", "cp858", "cp860", "cp861", "cp862", "cp863"], - "cp866": ["cp1125"], - "iso8859_10": ["iso8859_14", "iso8859_15", "iso8859_4", "iso8859_9", "latin_1"], - "iso8859_11": ["tis_620"], - "iso8859_13": ["cp1257"], - "iso8859_14": [ - "iso8859_10", - "iso8859_15", - "iso8859_16", - "iso8859_3", - "iso8859_9", - "latin_1", - ], - "iso8859_15": [ - "cp1252", - "cp1254", - "iso8859_10", - "iso8859_14", - "iso8859_16", - "iso8859_3", - "iso8859_9", - "latin_1", - ], - "iso8859_16": [ - "iso8859_14", - "iso8859_15", - "iso8859_2", - "iso8859_3", - "iso8859_9", - "latin_1", - ], - "iso8859_2": ["cp1250", "iso8859_16", "iso8859_4"], - "iso8859_3": ["iso8859_14", "iso8859_15", "iso8859_16", "iso8859_9", "latin_1"], - "iso8859_4": ["iso8859_10", "iso8859_2", "iso8859_9", "latin_1"], - "iso8859_7": ["cp1253"], - "iso8859_9": [ - "cp1252", - "cp1254", - "cp1258", - "iso8859_10", - "iso8859_14", - "iso8859_15", - "iso8859_16", - "iso8859_3", - "iso8859_4", - "latin_1", - ], - "kz1048": ["cp1251", "ptcp154"], - "latin_1": [ - "cp1252", - "cp1254", - "cp1258", - "iso8859_10", - "iso8859_14", - "iso8859_15", - "iso8859_16", - "iso8859_3", - "iso8859_4", - "iso8859_9", - ], - "mac_iceland": ["mac_roman", "mac_turkish"], - "mac_roman": ["mac_iceland", "mac_turkish"], - "mac_turkish": ["mac_iceland", "mac_roman"], - "ptcp154": ["cp1251", "kz1048"], - "tis_620": ["iso8859_11"], -} - - -CHARDET_CORRESPONDENCE: dict[str, str] = { - "iso2022_kr": "ISO-2022-KR", - "iso2022_jp": "ISO-2022-JP", - "euc_kr": "EUC-KR", - "tis_620": "TIS-620", - "utf_32": "UTF-32", - "euc_jp": "EUC-JP", - "koi8_r": "KOI8-R", - "iso8859_1": "ISO-8859-1", - "iso8859_2": "ISO-8859-2", - "iso8859_5": "ISO-8859-5", - "iso8859_6": "ISO-8859-6", - "iso8859_7": "ISO-8859-7", - "iso8859_8": "ISO-8859-8", - "utf_16": "UTF-16", - "cp855": "IBM855", - "mac_cyrillic": "MacCyrillic", - "gb2312": "GB2312", - "gb18030": "GB18030", - "cp932": "CP932", - "cp866": "IBM866", - "utf_8": "utf-8", - "utf_8_sig": "UTF-8-SIG", - "shift_jis": "SHIFT_JIS", - "big5": "Big5", - "cp1250": "windows-1250", - "cp1251": "windows-1251", - "cp1252": "Windows-1252", - "cp1253": "windows-1253", - "cp1255": "windows-1255", - "cp1256": "windows-1256", - "cp1254": "Windows-1254", - "cp949": "CP949", -} - - -COMMON_SAFE_ASCII_CHARACTERS: frozenset[str] = frozenset( - { - "<", - ">", - "=", - ":", - "/", - "&", - ";", - "{", - "}", - "[", - "]", - ",", - "|", - '"', - "-", - "(", - ")", - } -) - -# Sample character sets — replace with full lists if needed -COMMON_CHINESE_CHARACTERS = "的一是在不了有和人这中大为上个国我以要他时来用们生到作地于出就分对成会可主发年动同工也能下过子说产种面而方后多定行学法所民得经十三之进着等部度家电力里如水化高自二理起小物现实加量都两体制机当使点从业本去把性好应开它合还因由其些然前外天政四日那社义事平形相全表间样与关各重新线内数正心反你明看原又么利比或但质气第向道命此变条只没结解问意建月公无系军很情者最立代想已通并提直题党程展五果料象员革位入常文总次品式活设及管特件长求老头基资边流路级少图山统接知较将组见计别她手角期根论运农指几九区强放决西被干做必战先回则任取据处队南给色光门即保治北造百规热领七海口东导器压志世金增争济阶油思术极交受联什认六共权收证改清己美再采转更单风切打白教速花带安场身车例真务具万每目至达走积示议声报斗完类八离华名确才科张信马节话米整空元况今集温传土许步群广石记需段研界拉林律叫且究观越织装影算低持音众书布复容儿须际商非验连断深难近矿千周委素技备半办青省列习响约支般史感劳便团往酸历市克何除消构府太准精值号率族维划选标写存候毛亲快效斯院查江型眼王按格养易置派层片始却专状育厂京识适属圆包火住调满县局照参红细引听该铁价严龙飞" - -COMMON_JAPANESE_CHARACTERS = "日一国年大十二本中長出三時行見月分後前生五間上東四今金九入学高円子外八六下来気小七山話女北午百書先名川千水半男西電校語土木聞食車何南万毎白天母火右読友左休父雨" - -COMMON_KOREAN_CHARACTERS = "一二三四五六七八九十百千萬上下左右中人女子大小山川日月火水木金土父母天地國名年時文校學生" - -# Combine all into a frozenset -COMMON_CJK_CHARACTERS = frozenset( - "".join( - [ - COMMON_CHINESE_CHARACTERS, - COMMON_JAPANESE_CHARACTERS, - COMMON_KOREAN_CHARACTERS, - ] - ) -) - -KO_NAMES: frozenset[str] = frozenset({"johab", "cp949", "euc_kr"}) -ZH_NAMES: frozenset[str] = frozenset({"big5", "cp950", "big5hkscs", "hz"}) - -# Logging LEVEL below DEBUG -TRACE: int = 5 - - -# Language label that contain the em dash "—" -# character are to be considered alternative seq to origin -FREQUENCIES: dict[str, list[str]] = { - "English": [ - "e", - "a", - "t", - "i", - "o", - "n", - "s", - "r", - "h", - "l", - "d", - "c", - "u", - "m", - "f", - "p", - "g", - "w", - "y", - "b", - "v", - "k", - "x", - "j", - "z", - "q", - ], - "English—": [ - "e", - "a", - "t", - "i", - "o", - "n", - "s", - "r", - "h", - "l", - "d", - "c", - "m", - "u", - "f", - "p", - "g", - "w", - "b", - "y", - "v", - "k", - "j", - "x", - "z", - "q", - ], - "German": [ - "e", - "n", - "i", - "r", - "s", - "t", - "a", - "d", - "h", - "u", - "l", - "g", - "o", - "c", - "m", - "b", - "f", - "k", - "w", - "z", - "p", - "v", - "ü", - "ä", - "ö", - "j", - ], - "French": [ - "e", - "a", - "s", - "n", - "i", - "t", - "r", - "l", - "u", - "o", - "d", - "c", - "p", - "m", - "é", - "v", - "g", - "f", - "b", - "h", - "q", - "à", - "x", - "è", - "y", - "j", - ], - "Dutch": [ - "e", - "n", - "a", - "i", - "r", - "t", - "o", - "d", - "s", - "l", - "g", - "h", - "v", - "m", - "u", - "k", - "c", - "p", - "b", - "w", - "j", - "z", - "f", - "y", - "x", - "ë", - ], - "Italian": [ - "e", - "i", - "a", - "o", - "n", - "l", - "t", - "r", - "s", - "c", - "d", - "u", - "p", - "m", - "g", - "v", - "f", - "b", - "z", - "h", - "q", - "è", - "à", - "k", - "y", - "ò", - ], - "Polish": [ - "a", - "i", - "o", - "e", - "n", - "r", - "z", - "w", - "s", - "c", - "t", - "k", - "y", - "d", - "p", - "m", - "u", - "l", - "j", - "ł", - "g", - "b", - "h", - "ą", - "ę", - "ó", - ], - "Spanish": [ - "e", - "a", - "o", - "n", - "s", - "r", - "i", - "l", - "d", - "t", - "c", - "u", - "m", - "p", - "b", - "g", - "v", - "f", - "y", - "ó", - "h", - "q", - "í", - "j", - "z", - "á", - ], - "Russian": [ - "о", - "е", - "а", - "и", - "н", - "т", - "с", - "р", - "в", - "л", - "к", - "м", - "д", - "п", - "у", - "г", - "я", - "ы", - "з", - "б", - "й", - "ь", - "ч", - "х", - "ж", - "ц", - ], - # Jap-Kanji - "Japanese": [ - "日", - "一", - "人", - "年", - "大", - "十", - "二", - "本", - "中", - "長", - "出", - "三", - "時", - "行", - "見", - "月", - "分", - "後", - "前", - "生", - "五", - "間", - "上", - "東", - "四", - "今", - "金", - "九", - "入", - "学", - "高", - "円", - "子", - "外", - "八", - "六", - "下", - "来", - "気", - "小", - "七", - "山", - "話", - "女", - "北", - "午", - "百", - "書", - "先", - "名", - "川", - "千", - "水", - "半", - "男", - "西", - "電", - "校", - "語", - "土", - "木", - "聞", - "食", - "車", - "何", - "南", - "万", - "毎", - "白", - "天", - "母", - "火", - "右", - "読", - "友", - "左", - "休", - "父", - "雨", - ], - # Jap-Katakana - "Japanese—": [ - "ー", - "ン", - "ス", - "・", - "ル", - "ト", - "リ", - "イ", - "ア", - "ラ", - "ッ", - "ク", - "ド", - "シ", - "レ", - "ジ", - "タ", - "フ", - "ロ", - "カ", - "テ", - "マ", - "ィ", - "グ", - "バ", - "ム", - "プ", - "オ", - "コ", - "デ", - "ニ", - "ウ", - "メ", - "サ", - "ビ", - "ナ", - "ブ", - "ャ", - "エ", - "ュ", - "チ", - "キ", - "ズ", - "ダ", - "パ", - "ミ", - "ェ", - "ョ", - "ハ", - "セ", - "ベ", - "ガ", - "モ", - "ツ", - "ネ", - "ボ", - "ソ", - "ノ", - "ァ", - "ヴ", - "ワ", - "ポ", - "ペ", - "ピ", - "ケ", - "ゴ", - "ギ", - "ザ", - "ホ", - "ゲ", - "ォ", - "ヤ", - "ヒ", - "ユ", - "ヨ", - "ヘ", - "ゼ", - "ヌ", - "ゥ", - "ゾ", - "ヶ", - "ヂ", - "ヲ", - "ヅ", - "ヵ", - "ヱ", - "ヰ", - "ヮ", - "ヽ", - "゠", - "ヾ", - "ヷ", - "ヿ", - "ヸ", - "ヹ", - "ヺ", - ], - # Jap-Hiragana - "Japanese——": [ - "の", - "に", - "る", - "た", - "と", - "は", - "し", - "い", - "を", - "で", - "て", - "が", - "な", - "れ", - "か", - "ら", - "さ", - "っ", - "り", - "す", - "あ", - "も", - "こ", - "ま", - "う", - "く", - "よ", - "き", - "ん", - "め", - "お", - "け", - "そ", - "つ", - "だ", - "や", - "え", - "ど", - "わ", - "ち", - "み", - "せ", - "じ", - "ば", - "へ", - "び", - "ず", - "ろ", - "ほ", - "げ", - "む", - "べ", - "ひ", - "ょ", - "ゆ", - "ぶ", - "ご", - "ゃ", - "ね", - "ふ", - "ぐ", - "ぎ", - "ぼ", - "ゅ", - "づ", - "ざ", - "ぞ", - "ぬ", - "ぜ", - "ぱ", - "ぽ", - "ぷ", - "ぴ", - "ぃ", - "ぁ", - "ぇ", - "ぺ", - "ゞ", - "ぢ", - "ぉ", - "ぅ", - "ゐ", - "ゝ", - "ゑ", - "゛", - "゜", - "ゎ", - "ゔ", - "゚", - "ゟ", - "゙", - "ゕ", - "ゖ", - ], - "Portuguese": [ - "a", - "e", - "o", - "s", - "i", - "r", - "d", - "n", - "t", - "m", - "u", - "c", - "l", - "p", - "g", - "v", - "b", - "f", - "h", - "ã", - "q", - "é", - "ç", - "á", - "z", - "í", - ], - "Swedish": [ - "e", - "a", - "n", - "r", - "t", - "s", - "i", - "l", - "d", - "o", - "m", - "k", - "g", - "v", - "h", - "f", - "u", - "p", - "ä", - "c", - "b", - "ö", - "å", - "y", - "j", - "x", - ], - "Chinese": [ - "的", - "一", - "是", - "不", - "了", - "在", - "人", - "有", - "我", - "他", - "这", - "个", - "们", - "中", - "来", - "上", - "大", - "为", - "和", - "国", - "地", - "到", - "以", - "说", - "时", - "要", - "就", - "出", - "会", - "可", - "也", - "你", - "对", - "生", - "能", - "而", - "子", - "那", - "得", - "于", - "着", - "下", - "自", - "之", - "年", - "过", - "发", - "后", - "作", - "里", - "用", - "道", - "行", - "所", - "然", - "家", - "种", - "事", - "成", - "方", - "多", - "经", - "么", - "去", - "法", - "学", - "如", - "都", - "同", - "现", - "当", - "没", - "动", - "面", - "起", - "看", - "定", - "天", - "分", - "还", - "进", - "好", - "小", - "部", - "其", - "些", - "主", - "样", - "理", - "心", - "她", - "本", - "前", - "开", - "但", - "因", - "只", - "从", - "想", - "实", - ], - "Ukrainian": [ - "о", - "а", - "н", - "і", - "и", - "р", - "в", - "т", - "е", - "с", - "к", - "л", - "у", - "д", - "м", - "п", - "з", - "я", - "ь", - "б", - "г", - "й", - "ч", - "х", - "ц", - "ї", - ], - "Norwegian": [ - "e", - "r", - "n", - "t", - "a", - "s", - "i", - "o", - "l", - "d", - "g", - "k", - "m", - "v", - "f", - "p", - "u", - "b", - "h", - "å", - "y", - "j", - "ø", - "c", - "æ", - "w", - ], - "Finnish": [ - "a", - "i", - "n", - "t", - "e", - "s", - "l", - "o", - "u", - "k", - "ä", - "m", - "r", - "v", - "j", - "h", - "p", - "y", - "d", - "ö", - "g", - "c", - "b", - "f", - "w", - "z", - ], - "Vietnamese": [ - "n", - "h", - "t", - "i", - "c", - "g", - "a", - "o", - "u", - "m", - "l", - "r", - "à", - "đ", - "s", - "e", - "v", - "p", - "b", - "y", - "ư", - "d", - "á", - "k", - "ộ", - "ế", - ], - "Czech": [ - "o", - "e", - "a", - "n", - "t", - "s", - "i", - "l", - "v", - "r", - "k", - "d", - "u", - "m", - "p", - "í", - "c", - "h", - "z", - "á", - "y", - "j", - "b", - "ě", - "é", - "ř", - ], - "Hungarian": [ - "e", - "a", - "t", - "l", - "s", - "n", - "k", - "r", - "i", - "o", - "z", - "á", - "é", - "g", - "m", - "b", - "y", - "v", - "d", - "h", - "u", - "p", - "j", - "ö", - "f", - "c", - ], - "Korean": [ - "이", - "다", - "에", - "의", - "는", - "로", - "하", - "을", - "가", - "고", - "지", - "서", - "한", - "은", - "기", - "으", - "년", - "대", - "사", - "시", - "를", - "리", - "도", - "인", - "스", - "일", - ], - "Indonesian": [ - "a", - "n", - "e", - "i", - "r", - "t", - "u", - "s", - "d", - "k", - "m", - "l", - "g", - "p", - "b", - "o", - "h", - "y", - "j", - "c", - "w", - "f", - "v", - "z", - "x", - "q", - ], - "Turkish": [ - "a", - "e", - "i", - "n", - "r", - "l", - "ı", - "k", - "d", - "t", - "s", - "m", - "y", - "u", - "o", - "b", - "ü", - "ş", - "v", - "g", - "z", - "h", - "c", - "p", - "ç", - "ğ", - ], - "Romanian": [ - "e", - "i", - "a", - "r", - "n", - "t", - "u", - "l", - "o", - "c", - "s", - "d", - "p", - "m", - "ă", - "f", - "v", - "î", - "g", - "b", - "ș", - "ț", - "z", - "h", - "â", - "j", - ], - "Farsi": [ - "ا", - "ی", - "ر", - "د", - "ن", - "ه", - "و", - "م", - "ت", - "ب", - "س", - "ل", - "ک", - "ش", - "ز", - "ف", - "گ", - "ع", - "خ", - "ق", - "ج", - "آ", - "پ", - "ح", - "ط", - "ص", - ], - "Arabic": [ - "ا", - "ل", - "ي", - "م", - "و", - "ن", - "ر", - "ت", - "ب", - "ة", - "ع", - "د", - "س", - "ف", - "ه", - "ك", - "ق", - "أ", - "ح", - "ج", - "ش", - "ط", - "ص", - "ى", - "خ", - "إ", - ], - "Danish": [ - "e", - "r", - "n", - "t", - "a", - "i", - "s", - "d", - "l", - "o", - "g", - "m", - "k", - "f", - "v", - "u", - "b", - "h", - "p", - "å", - "y", - "ø", - "æ", - "c", - "j", - "w", - ], - "Serbian": [ - "а", - "и", - "о", - "е", - "н", - "р", - "с", - "у", - "т", - "к", - "ј", - "в", - "д", - "м", - "п", - "л", - "г", - "з", - "б", - "a", - "i", - "e", - "o", - "n", - "ц", - "ш", - ], - "Lithuanian": [ - "i", - "a", - "s", - "o", - "r", - "e", - "t", - "n", - "u", - "k", - "m", - "l", - "p", - "v", - "d", - "j", - "g", - "ė", - "b", - "y", - "ų", - "š", - "ž", - "c", - "ą", - "į", - ], - "Slovene": [ - "e", - "a", - "i", - "o", - "n", - "r", - "s", - "l", - "t", - "j", - "v", - "k", - "d", - "p", - "m", - "u", - "z", - "b", - "g", - "h", - "č", - "c", - "š", - "ž", - "f", - "y", - ], - "Slovak": [ - "o", - "a", - "e", - "n", - "i", - "r", - "v", - "t", - "s", - "l", - "k", - "d", - "m", - "p", - "u", - "c", - "h", - "j", - "b", - "z", - "á", - "y", - "ý", - "í", - "č", - "é", - ], - "Hebrew": [ - "י", - "ו", - "ה", - "ל", - "ר", - "ב", - "ת", - "מ", - "א", - "ש", - "נ", - "ע", - "ם", - "ד", - "ק", - "ח", - "פ", - "ס", - "כ", - "ג", - "ט", - "צ", - "ן", - "ז", - "ך", - ], - "Bulgarian": [ - "а", - "и", - "о", - "е", - "н", - "т", - "р", - "с", - "в", - "л", - "к", - "д", - "п", - "м", - "з", - "г", - "я", - "ъ", - "у", - "б", - "ч", - "ц", - "й", - "ж", - "щ", - "х", - ], - "Croatian": [ - "a", - "i", - "o", - "e", - "n", - "r", - "j", - "s", - "t", - "u", - "k", - "l", - "v", - "d", - "m", - "p", - "g", - "z", - "b", - "c", - "č", - "h", - "š", - "ž", - "ć", - "f", - ], - "Hindi": [ - "क", - "र", - "स", - "न", - "त", - "म", - "ह", - "प", - "य", - "ल", - "व", - "ज", - "द", - "ग", - "ब", - "श", - "ट", - "अ", - "ए", - "थ", - "भ", - "ड", - "च", - "ध", - "ष", - "इ", - ], - "Estonian": [ - "a", - "i", - "e", - "s", - "t", - "l", - "u", - "n", - "o", - "k", - "r", - "d", - "m", - "v", - "g", - "p", - "j", - "h", - "ä", - "b", - "õ", - "ü", - "f", - "c", - "ö", - "y", - ], - "Thai": [ - "า", - "น", - "ร", - "อ", - "ก", - "เ", - "ง", - "ม", - "ย", - "ล", - "ว", - "ด", - "ท", - "ส", - "ต", - "ะ", - "ป", - "บ", - "ค", - "ห", - "แ", - "จ", - "พ", - "ช", - "ข", - "ใ", - ], - "Greek": [ - "α", - "τ", - "ο", - "ι", - "ε", - "ν", - "ρ", - "σ", - "κ", - "η", - "π", - "ς", - "υ", - "μ", - "λ", - "ί", - "ό", - "ά", - "γ", - "έ", - "δ", - "ή", - "ω", - "χ", - "θ", - "ύ", - ], - "Tamil": [ - "க", - "த", - "ப", - "ட", - "ர", - "ம", - "ல", - "ன", - "வ", - "ற", - "ய", - "ள", - "ச", - "ந", - "இ", - "ண", - "அ", - "ஆ", - "ழ", - "ங", - "எ", - "உ", - "ஒ", - "ஸ", - ], - "Kazakh": [ - "а", - "ы", - "е", - "н", - "т", - "р", - "л", - "і", - "д", - "с", - "м", - "қ", - "к", - "о", - "б", - "и", - "у", - "ғ", - "ж", - "ң", - "з", - "ш", - "й", - "п", - "г", - "ө", - ], -} - -LANGUAGE_SUPPORTED_COUNT: int = len(FREQUENCIES) - -# Bit flags for unified character classification. -# A single unicodedata.name() call sets all relevant flags at once. -_LATIN: int = 1 -_ACCENTUATED: int = 1 << 1 -_CJK: int = 1 << 2 -_HANGUL: int = 1 << 3 -_KATAKANA: int = 1 << 4 -_HIRAGANA: int = 1 << 5 -_THAI: int = 1 << 6 -_ARABIC: int = 1 << 7 -_ARABIC_ISOLATED_FORM: int = 1 << 8 - -_ACCENT_KEYWORDS: tuple[str, ...] = ( - "WITH GRAVE", - "WITH ACUTE", - "WITH CEDILLA", - "WITH DIAERESIS", - "WITH CIRCUMFLEX", - "WITH TILDE", - "WITH MACRON", - "WITH RING ABOVE", -) - -# Pre-built lookup structures for FREQUENCIES (computed once at import time). -# character -> rank mapping per language (replaces list .index() calls). -_FREQUENCIES_RANK: dict[str, dict[str, int]] = { - lang: {char: rank for rank, char in enumerate(chars)} - for lang, chars in FREQUENCIES.items() -} - -# frozenset per language (avoids rebuilding set() per call). -_FREQUENCIES_SET: dict[str, frozenset[str]] = { - lang: frozenset(chars) for lang, chars in FREQUENCIES.items() -} diff --git a/.venv/lib/python3.12/site-packages/charset_normalizer/legacy.py b/.venv/lib/python3.12/site-packages/charset_normalizer/legacy.py deleted file mode 100644 index 293c1ef..0000000 --- a/.venv/lib/python3.12/site-packages/charset_normalizer/legacy.py +++ /dev/null @@ -1,79 +0,0 @@ -from __future__ import annotations - -from typing import TYPE_CHECKING, Any -from warnings import warn - -from .api import from_bytes -from .constant import CHARDET_CORRESPONDENCE, TOO_SMALL_SEQUENCE - -if TYPE_CHECKING: - from typing import TypedDict - - class ResultDict(TypedDict): - encoding: str | None - language: str - confidence: float | None - - -def detect( - byte_str: bytes, should_rename_legacy: bool = False, **kwargs: Any -) -> ResultDict: - """ - chardet legacy method - Detect the encoding of the given byte string. It should be mostly backward-compatible. - Encoding name will match Chardet own writing whenever possible. (Not on encoding name unsupported by it) - This function is deprecated and should be used to migrate your project easily, consult the documentation for - further information. Not planned for removal. - - :param byte_str: The byte sequence to examine. - :param should_rename_legacy: Should we rename legacy encodings - to their more modern equivalents? - """ - if len(kwargs): - warn( - f"charset-normalizer disregard arguments '{','.join(list(kwargs.keys()))}' in legacy function detect()" - ) - - if not isinstance(byte_str, (bytearray, bytes)): - raise TypeError( # pragma: nocover - f"Expected object of type bytes or bytearray, got: {type(byte_str)}" - ) - - if isinstance(byte_str, bytearray): - byte_str = bytes(byte_str) - - r = from_bytes(byte_str).best() - - encoding = r.encoding if r is not None else None - language = r.language if r is not None and r.language != "Unknown" else "" - confidence = 1.0 - r.chaos if r is not None else None - - # automatically lower confidence - # on small bytes samples. - # https://github.com/jawah/charset_normalizer/issues/391 - if ( - confidence is not None - and confidence >= 0.9 - and encoding - not in { - "utf_8", - "ascii", - } - and r.bom is False # type: ignore[union-attr] - and len(byte_str) < TOO_SMALL_SEQUENCE - ): - confidence -= 0.2 - - # Note: CharsetNormalizer does not return 'UTF-8-SIG' as the sig get stripped in the detection/normalization process - # but chardet does return 'utf-8-sig' and it is a valid codec name. - if r is not None and encoding == "utf_8" and r.bom: - encoding += "_sig" - - if should_rename_legacy is False and encoding in CHARDET_CORRESPONDENCE: - encoding = CHARDET_CORRESPONDENCE[encoding] - - return { - "encoding": encoding, - "language": language, - "confidence": confidence, - } diff --git a/.venv/lib/python3.12/site-packages/charset_normalizer/md.cpython-312-x86_64-linux-gnu.so b/.venv/lib/python3.12/site-packages/charset_normalizer/md.cpython-312-x86_64-linux-gnu.so deleted file mode 100755 index 87d31c7..0000000 Binary files a/.venv/lib/python3.12/site-packages/charset_normalizer/md.cpython-312-x86_64-linux-gnu.so and /dev/null differ diff --git a/.venv/lib/python3.12/site-packages/charset_normalizer/md.py b/.venv/lib/python3.12/site-packages/charset_normalizer/md.py deleted file mode 100644 index b41d9cf..0000000 --- a/.venv/lib/python3.12/site-packages/charset_normalizer/md.py +++ /dev/null @@ -1,936 +0,0 @@ -from __future__ import annotations - -import sys -from functools import lru_cache -from logging import getLogger - -if sys.version_info >= (3, 8): - from typing import final -else: - try: - from typing_extensions import final - except ImportError: - - def final(cls): # type: ignore[misc,no-untyped-def] - return cls - - -from .constant import ( - COMMON_CJK_CHARACTERS, - COMMON_SAFE_ASCII_CHARACTERS, - TRACE, - UNICODE_SECONDARY_RANGE_KEYWORD, - _ACCENTUATED, - _ARABIC, - _ARABIC_ISOLATED_FORM, - _CJK, - _HANGUL, - _HIRAGANA, - _KATAKANA, - _LATIN, - _THAI, -) -from .utils import ( - _character_flags, - is_emoticon, - is_punctuation, - is_separator, - is_symbol, - remove_accent, - unicode_range, -) - -# Combined bitmask for CJK/Hangul/Katakana/Hiragana/Thai glyph detection. -_GLYPH_MASK: int = _CJK | _HANGUL | _KATAKANA | _HIRAGANA | _THAI - - -@final -class CharInfo: - """Pre-computed character properties shared across all detectors. - - Instantiated once and reused via :meth:`update` on every character - in the hot loop so that redundant calls to str methods - (``isalpha``, ``isupper``, …) and cached utility functions - (``_character_flags``, ``is_punctuation``, …) are avoided when - several plugins need the same information. - """ - - __slots__ = ( - "character", - "printable", - "alpha", - "upper", - "lower", - "space", - "digit", - "is_ascii", - "case_variable", - "flags", - "accentuated", - "latin", - "is_cjk", - "is_arabic", - "is_glyph", - "punct", - "sym", - ) - - def __init__(self) -> None: - self.character: str = "" - self.printable: bool = False - self.alpha: bool = False - self.upper: bool = False - self.lower: bool = False - self.space: bool = False - self.digit: bool = False - self.is_ascii: bool = False - self.case_variable: bool = False - self.flags: int = 0 - self.accentuated: bool = False - self.latin: bool = False - self.is_cjk: bool = False - self.is_arabic: bool = False - self.is_glyph: bool = False - self.punct: bool = False - self.sym: bool = False - - def update(self, character: str) -> None: - """Update all properties for *character* (called once per character).""" - self.character = character - - # ASCII fast-path: for characters with ord < 128, we can skip - # _character_flags() entirely and derive most properties from ord. - o: int = ord(character) - if o < 128: - self.is_ascii = True - self.accentuated = False - self.is_cjk = False - self.is_arabic = False - self.is_glyph = False - # ASCII alpha: a-z (97-122) or A-Z (65-90) - if 65 <= o <= 90: - # Uppercase ASCII letter - self.alpha = True - self.upper = True - self.lower = False - self.space = False - self.digit = False - self.printable = True - self.case_variable = True - self.flags = _LATIN - self.latin = True - self.punct = False - self.sym = False - elif 97 <= o <= 122: - # Lowercase ASCII letter - self.alpha = True - self.upper = False - self.lower = True - self.space = False - self.digit = False - self.printable = True - self.case_variable = True - self.flags = _LATIN - self.latin = True - self.punct = False - self.sym = False - elif 48 <= o <= 57: - # ASCII digit 0-9 - self.alpha = False - self.upper = False - self.lower = False - self.space = False - self.digit = True - self.printable = True - self.case_variable = False - self.flags = 0 - self.latin = False - self.punct = False - self.sym = False - elif o == 32 or (9 <= o <= 13): - # Space, tab, newline, etc. - self.alpha = False - self.upper = False - self.lower = False - self.space = True - self.digit = False - self.printable = o == 32 - self.case_variable = False - self.flags = 0 - self.latin = False - self.punct = False - self.sym = False - else: - # Other ASCII (punctuation, symbols, control chars) - self.printable = character.isprintable() - self.alpha = False - self.upper = False - self.lower = False - self.space = False - self.digit = False - self.case_variable = False - self.flags = 0 - self.latin = False - self.punct = is_punctuation(character) if self.printable else False - self.sym = is_symbol(character) if self.printable else False - else: - # Non-ASCII path - self.is_ascii = False - self.printable = character.isprintable() - self.alpha = character.isalpha() - self.upper = character.isupper() - self.lower = character.islower() - self.space = character.isspace() - self.digit = character.isdigit() - self.case_variable = self.lower != self.upper - - # Flag-based classification (single unicodedata.name() call, lru-cached) - flags: int - if self.alpha: - flags = _character_flags(character) - else: - flags = 0 - self.flags = flags - self.accentuated = bool(flags & _ACCENTUATED) - self.latin = bool(flags & _LATIN) - self.is_cjk = bool(flags & _CJK) - self.is_arabic = bool(flags & _ARABIC) - self.is_glyph = bool(flags & _GLYPH_MASK) - - # Eagerly compute punct and sym (avoids property dispatch overhead - # on 300K+ accesses in the hot loop). - self.punct = is_punctuation(character) if self.printable else False - self.sym = is_symbol(character) if self.printable else False - - -class MessDetectorPlugin: - """ - Base abstract class used for mess detection plugins. - All detectors MUST extend and implement given methods. - """ - - __slots__ = () - - def feed_info(self, character: str, info: CharInfo) -> None: - """ - The main routine to be executed upon character. - Insert the logic in witch the text would be considered chaotic. - """ - raise NotImplementedError # Defensive: - - def reset(self) -> None: # Defensive: - """ - Permit to reset the plugin to the initial state. - """ - raise NotImplementedError - - @property - def ratio(self) -> float: - """ - Compute the chaos ratio based on what your feed() has seen. - Must NOT be lower than 0.; No restriction gt 0. - """ - raise NotImplementedError # Defensive: - - -@final -class TooManySymbolOrPunctuationPlugin(MessDetectorPlugin): - __slots__ = ( - "_punctuation_count", - "_symbol_count", - "_character_count", - "_last_printable_char", - "_frenzy_symbol_in_word", - ) - - def __init__(self) -> None: - self._punctuation_count: int = 0 - self._symbol_count: int = 0 - self._character_count: int = 0 - - self._last_printable_char: str | None = None - self._frenzy_symbol_in_word: bool = False - - def feed_info(self, character: str, info: CharInfo) -> None: - """Optimized feed using pre-computed character info.""" - self._character_count += 1 - - if ( - character != self._last_printable_char - and character not in COMMON_SAFE_ASCII_CHARACTERS - ): - if info.punct: - self._punctuation_count += 1 - elif not info.digit and info.sym and not is_emoticon(character): - self._symbol_count += 2 - - self._last_printable_char = character - - def reset(self) -> None: # Abstract - self._punctuation_count = 0 - self._character_count = 0 - self._symbol_count = 0 - - @property - def ratio(self) -> float: - if self._character_count == 0: - return 0.0 - - ratio_of_punctuation: float = ( - self._punctuation_count + self._symbol_count - ) / self._character_count - - return ratio_of_punctuation if ratio_of_punctuation >= 0.3 else 0.0 - - -@final -class TooManyAccentuatedPlugin(MessDetectorPlugin): - __slots__ = ("_character_count", "_accentuated_count") - - def __init__(self) -> None: - self._character_count: int = 0 - self._accentuated_count: int = 0 - - def feed_info(self, character: str, info: CharInfo) -> None: - """Optimized feed using pre-computed character info.""" - self._character_count += 1 - - if info.accentuated: - self._accentuated_count += 1 - - def reset(self) -> None: # Abstract - self._character_count = 0 - self._accentuated_count = 0 - - @property - def ratio(self) -> float: - if self._character_count < 8: - return 0.0 - - ratio_of_accentuation: float = self._accentuated_count / self._character_count - return ratio_of_accentuation if ratio_of_accentuation >= 0.35 else 0.0 - - -@final -class UnprintablePlugin(MessDetectorPlugin): - __slots__ = ("_unprintable_count", "_character_count") - - def __init__(self) -> None: - self._unprintable_count: int = 0 - self._character_count: int = 0 - - def feed_info(self, character: str, info: CharInfo) -> None: - """Optimized feed using pre-computed character info.""" - if ( - not info.space - and not info.printable - and character != "\x1a" - and character != "\ufeff" - ): - self._unprintable_count += 1 - self._character_count += 1 - - def reset(self) -> None: # Abstract - self._unprintable_count = 0 - - @property - def ratio(self) -> float: - if self._character_count == 0: # Defensive: - return 0.0 - - return (self._unprintable_count * 8) / self._character_count - - -@final -class SuspiciousDuplicateAccentPlugin(MessDetectorPlugin): - __slots__ = ( - "_successive_count", - "_character_count", - "_last_latin_character", - "_last_was_accentuated", - ) - - def __init__(self) -> None: - self._successive_count: int = 0 - self._character_count: int = 0 - - self._last_latin_character: str | None = None - self._last_was_accentuated: bool = False - - def feed_info(self, character: str, info: CharInfo) -> None: - """Optimized feed using pre-computed character info.""" - self._character_count += 1 - if ( - self._last_latin_character is not None - and info.accentuated - and self._last_was_accentuated - ): - if info.upper and self._last_latin_character.isupper(): - self._successive_count += 1 - if remove_accent(character) == remove_accent(self._last_latin_character): - self._successive_count += 1 - self._last_latin_character = character - self._last_was_accentuated = info.accentuated - - def reset(self) -> None: # Abstract - self._successive_count = 0 - self._character_count = 0 - self._last_latin_character = None - self._last_was_accentuated = False - - @property - def ratio(self) -> float: - if self._character_count == 0: - return 0.0 - - return (self._successive_count * 2) / self._character_count - - -@final -class SuspiciousRange(MessDetectorPlugin): - __slots__ = ( - "_suspicious_successive_range_count", - "_character_count", - "_last_printable_seen", - "_last_printable_range", - ) - - def __init__(self) -> None: - self._suspicious_successive_range_count: int = 0 - self._character_count: int = 0 - self._last_printable_seen: str | None = None - self._last_printable_range: str | None = None - - def feed_info(self, character: str, info: CharInfo) -> None: - """Optimized feed using pre-computed character info.""" - self._character_count += 1 - - if info.space or info.punct or character in COMMON_SAFE_ASCII_CHARACTERS: - self._last_printable_seen = None - self._last_printable_range = None - return - - if self._last_printable_seen is None: - self._last_printable_seen = character - self._last_printable_range = unicode_range(character) - return - - unicode_range_a: str | None = self._last_printable_range - unicode_range_b: str | None = unicode_range(character) - - if is_suspiciously_successive_range(unicode_range_a, unicode_range_b): - self._suspicious_successive_range_count += 1 - - self._last_printable_seen = character - self._last_printable_range = unicode_range_b - - def reset(self) -> None: # Abstract - self._character_count = 0 - self._suspicious_successive_range_count = 0 - self._last_printable_seen = None - self._last_printable_range = None - - @property - def ratio(self) -> float: - if self._character_count <= 13: - return 0.0 - - ratio_of_suspicious_range_usage: float = ( - self._suspicious_successive_range_count * 2 - ) / self._character_count - - return ratio_of_suspicious_range_usage - - -@final -class SuperWeirdWordPlugin(MessDetectorPlugin): - __slots__ = ( - "_word_count", - "_bad_word_count", - "_foreign_long_count", - "_is_current_word_bad", - "_foreign_long_watch", - "_character_count", - "_bad_character_count", - "_buffer_length", - "_buffer_last_char", - "_buffer_last_char_accentuated", - "_buffer_accent_count", - "_buffer_glyph_count", - "_buffer_upper_count", - ) - - def __init__(self) -> None: - self._word_count: int = 0 - self._bad_word_count: int = 0 - self._foreign_long_count: int = 0 - - self._is_current_word_bad: bool = False - self._foreign_long_watch: bool = False - - self._character_count: int = 0 - self._bad_character_count: int = 0 - - self._buffer_length: int = 0 - self._buffer_last_char: str | None = None - self._buffer_last_char_accentuated: bool = False - self._buffer_accent_count: int = 0 - self._buffer_glyph_count: int = 0 - self._buffer_upper_count: int = 0 - - def feed_info(self, character: str, info: CharInfo) -> None: - """Optimized feed using pre-computed character info.""" - if info.alpha: - self._buffer_length += 1 - self._buffer_last_char = character - - if info.upper: - self._buffer_upper_count += 1 - - self._buffer_last_char_accentuated = info.accentuated - - if info.accentuated: - self._buffer_accent_count += 1 - if ( - not self._foreign_long_watch - and (not info.latin or info.accentuated) - and not info.is_glyph - ): - self._foreign_long_watch = True - if info.is_glyph: - self._buffer_glyph_count += 1 - return - if not self._buffer_length: - return - if info.space or info.punct or is_separator(character): - self._word_count += 1 - buffer_length: int = self._buffer_length - - self._character_count += buffer_length - - if buffer_length >= 4: - if self._buffer_accent_count / buffer_length >= 0.5: - self._is_current_word_bad = True - elif ( - self._buffer_last_char_accentuated - and self._buffer_last_char.isupper() # type: ignore[union-attr] - and self._buffer_upper_count != buffer_length - ): - self._foreign_long_count += 1 - self._is_current_word_bad = True - elif self._buffer_glyph_count == 1: - self._is_current_word_bad = True - self._foreign_long_count += 1 - if buffer_length >= 24 and self._foreign_long_watch: - probable_camel_cased: bool = ( - self._buffer_upper_count > 0 - and self._buffer_upper_count / buffer_length <= 0.3 - ) - - if not probable_camel_cased: - self._foreign_long_count += 1 - self._is_current_word_bad = True - - if self._is_current_word_bad: - self._bad_word_count += 1 - self._bad_character_count += buffer_length - self._is_current_word_bad = False - - self._foreign_long_watch = False - self._buffer_length = 0 - self._buffer_last_char = None - self._buffer_last_char_accentuated = False - self._buffer_accent_count = 0 - self._buffer_glyph_count = 0 - self._buffer_upper_count = 0 - elif ( - character not in {"<", ">", "-", "=", "~", "|", "_"} - and not info.digit - and info.sym - ): - self._is_current_word_bad = True - self._buffer_length += 1 - self._buffer_last_char = character - self._buffer_last_char_accentuated = False - - def reset(self) -> None: # Abstract - self._buffer_length = 0 - self._buffer_last_char = None - self._buffer_last_char_accentuated = False - self._is_current_word_bad = False - self._foreign_long_watch = False - self._bad_word_count = 0 - self._word_count = 0 - self._character_count = 0 - self._bad_character_count = 0 - self._foreign_long_count = 0 - self._buffer_accent_count = 0 - self._buffer_glyph_count = 0 - self._buffer_upper_count = 0 - - @property - def ratio(self) -> float: - if self._word_count <= 10 and self._foreign_long_count == 0: - return 0.0 - - return self._bad_character_count / self._character_count - - -@final -class CjkUncommonPlugin(MessDetectorPlugin): - """ - Detect messy CJK text that probably means nothing. - """ - - __slots__ = ("_character_count", "_uncommon_count") - - def __init__(self) -> None: - self._character_count: int = 0 - self._uncommon_count: int = 0 - - def feed_info(self, character: str, info: CharInfo) -> None: - """Optimized feed using pre-computed character info.""" - self._character_count += 1 - - if character not in COMMON_CJK_CHARACTERS: - self._uncommon_count += 1 - - def reset(self) -> None: # Abstract - self._character_count = 0 - self._uncommon_count = 0 - - @property - def ratio(self) -> float: - if self._character_count < 8: - return 0.0 - - uncommon_form_usage: float = self._uncommon_count / self._character_count - - # we can be pretty sure it's garbage when uncommon characters are widely - # used. otherwise it could just be traditional chinese for example. - return uncommon_form_usage / 10 if uncommon_form_usage > 0.5 else 0.0 - - -@final -class ArchaicUpperLowerPlugin(MessDetectorPlugin): - __slots__ = ( - "_buf", - "_character_count_since_last_sep", - "_successive_upper_lower_count", - "_successive_upper_lower_count_final", - "_character_count", - "_last_alpha_seen", - "_last_alpha_seen_upper", - "_last_alpha_seen_lower", - "_current_ascii_only", - ) - - def __init__(self) -> None: - self._buf: bool = False - - self._character_count_since_last_sep: int = 0 - - self._successive_upper_lower_count: int = 0 - self._successive_upper_lower_count_final: int = 0 - - self._character_count: int = 0 - - self._last_alpha_seen: str | None = None - self._last_alpha_seen_upper: bool = False - self._last_alpha_seen_lower: bool = False - self._current_ascii_only: bool = True - - def feed_info(self, character: str, info: CharInfo) -> None: - """Optimized feed using pre-computed character info.""" - is_concerned: bool = info.alpha and info.case_variable - chunk_sep: bool = not is_concerned - - if chunk_sep and self._character_count_since_last_sep > 0: - if ( - self._character_count_since_last_sep <= 64 - and not info.digit - and not self._current_ascii_only - ): - self._successive_upper_lower_count_final += ( - self._successive_upper_lower_count - ) - - self._successive_upper_lower_count = 0 - self._character_count_since_last_sep = 0 - self._last_alpha_seen = None - self._buf = False - self._character_count += 1 - self._current_ascii_only = True - - return - - if self._current_ascii_only and not info.is_ascii: - self._current_ascii_only = False - - if self._last_alpha_seen is not None: - if (info.upper and self._last_alpha_seen_lower) or ( - info.lower and self._last_alpha_seen_upper - ): - if self._buf: - self._successive_upper_lower_count += 2 - self._buf = False - else: - self._buf = True - else: - self._buf = False - - self._character_count += 1 - self._character_count_since_last_sep += 1 - self._last_alpha_seen = character - self._last_alpha_seen_upper = info.upper - self._last_alpha_seen_lower = info.lower - - def reset(self) -> None: # Abstract - self._character_count = 0 - self._character_count_since_last_sep = 0 - self._successive_upper_lower_count = 0 - self._successive_upper_lower_count_final = 0 - self._last_alpha_seen = None - self._last_alpha_seen_upper = False - self._last_alpha_seen_lower = False - self._buf = False - self._current_ascii_only = True - - @property - def ratio(self) -> float: - if self._character_count == 0: # Defensive: - return 0.0 - - return self._successive_upper_lower_count_final / self._character_count - - -@final -class ArabicIsolatedFormPlugin(MessDetectorPlugin): - __slots__ = ("_character_count", "_isolated_form_count") - - def __init__(self) -> None: - self._character_count: int = 0 - self._isolated_form_count: int = 0 - - def reset(self) -> None: # Abstract - self._character_count = 0 - self._isolated_form_count = 0 - - def feed_info(self, character: str, info: CharInfo) -> None: - """Optimized feed using pre-computed character info.""" - self._character_count += 1 - - if info.flags & _ARABIC_ISOLATED_FORM: - self._isolated_form_count += 1 - - @property - def ratio(self) -> float: - if self._character_count < 8: - return 0.0 - - isolated_form_usage: float = self._isolated_form_count / self._character_count - - return isolated_form_usage - - -@lru_cache(maxsize=1024) -def is_suspiciously_successive_range( - unicode_range_a: str | None, unicode_range_b: str | None -) -> bool: - """ - Determine if two Unicode range seen next to each other can be considered as suspicious. - """ - if unicode_range_a is None or unicode_range_b is None: - return True - - if unicode_range_a == unicode_range_b: - return False - - if "Latin" in unicode_range_a and "Latin" in unicode_range_b: - return False - - if "Emoticons" in unicode_range_a or "Emoticons" in unicode_range_b: - return False - - # Latin characters can be accompanied with a combining diacritical mark - # eg. Vietnamese. - if ("Latin" in unicode_range_a or "Latin" in unicode_range_b) and ( - "Combining" in unicode_range_a or "Combining" in unicode_range_b - ): - return False - - keywords_range_a, keywords_range_b = ( - unicode_range_a.split(" "), - unicode_range_b.split(" "), - ) - - for el in keywords_range_a: - if el in UNICODE_SECONDARY_RANGE_KEYWORD: - continue - if el in keywords_range_b: - return False - - # Japanese Exception - range_a_jp_chars, range_b_jp_chars = ( - unicode_range_a - in ( - "Hiragana", - "Katakana", - ), - unicode_range_b in ("Hiragana", "Katakana"), - ) - if (range_a_jp_chars or range_b_jp_chars) and ( - "CJK" in unicode_range_a or "CJK" in unicode_range_b - ): - return False - if range_a_jp_chars and range_b_jp_chars: - return False - - if "Hangul" in unicode_range_a or "Hangul" in unicode_range_b: - if "CJK" in unicode_range_a or "CJK" in unicode_range_b: - return False - if unicode_range_a == "Basic Latin" or unicode_range_b == "Basic Latin": - return False - - # Chinese/Japanese use dedicated range for punctuation and/or separators. - if ("CJK" in unicode_range_a or "CJK" in unicode_range_b) or ( - unicode_range_a in ["Katakana", "Hiragana"] - and unicode_range_b in ["Katakana", "Hiragana"] - ): - if "Punctuation" in unicode_range_a or "Punctuation" in unicode_range_b: - return False - if "Forms" in unicode_range_a or "Forms" in unicode_range_b: - return False - if unicode_range_a == "Basic Latin" or unicode_range_b == "Basic Latin": - return False - - return True - - -@lru_cache(maxsize=2048) -def mess_ratio( - decoded_sequence: str, maximum_threshold: float = 0.2, debug: bool = False -) -> float: - """ - Compute a mess ratio given a decoded bytes sequence. The maximum threshold does stop the computation earlier. - """ - - seq_len: int = len(decoded_sequence) - - if seq_len < 511: - step: int = 32 - elif seq_len < 1024: - step = 64 - else: - step = 128 - - # Create each detector as a named local variable (unrolled from the generic loop). - # This eliminates per-character iteration over the detector list and - # per-character eligible() virtual dispatch, while keeping every plugin class - # intact and fully readable. - d_sp: TooManySymbolOrPunctuationPlugin = TooManySymbolOrPunctuationPlugin() - d_ta: TooManyAccentuatedPlugin = TooManyAccentuatedPlugin() - d_up: UnprintablePlugin = UnprintablePlugin() - d_sda: SuspiciousDuplicateAccentPlugin = SuspiciousDuplicateAccentPlugin() - d_sr: SuspiciousRange = SuspiciousRange() - d_sw: SuperWeirdWordPlugin = SuperWeirdWordPlugin() - d_cu: CjkUncommonPlugin = CjkUncommonPlugin() - d_au: ArchaicUpperLowerPlugin = ArchaicUpperLowerPlugin() - d_ai: ArabicIsolatedFormPlugin = ArabicIsolatedFormPlugin() - - # Local references for feed_info methods called in the hot loop. - d_sp_feed = d_sp.feed_info - d_ta_feed = d_ta.feed_info - d_up_feed = d_up.feed_info - d_sda_feed = d_sda.feed_info - d_sr_feed = d_sr.feed_info - d_sw_feed = d_sw.feed_info - d_cu_feed = d_cu.feed_info - d_au_feed = d_au.feed_info - d_ai_feed = d_ai.feed_info - - # Single reusable CharInfo object (avoids per-character allocation). - info: CharInfo = CharInfo() - info_update = info.update - - mean_mess_ratio: float - - for block_start in range(0, seq_len, step): - for character in decoded_sequence[block_start : block_start + step]: - # Pre-compute all character properties once (shared across all plugins). - info_update(character) - - # Detectors with eligible() == always True - d_up_feed(character, info) - d_sw_feed(character, info) - d_au_feed(character, info) - - # Detectors with eligible() == isprintable - if info.printable: - d_sp_feed(character, info) - d_sr_feed(character, info) - - # Detectors with eligible() == isalpha - if info.alpha: - d_ta_feed(character, info) - # SuspiciousDuplicateAccent: isalpha() and is_latin() - if info.latin: - d_sda_feed(character, info) - # CjkUncommon: is_cjk() - if info.is_cjk: - d_cu_feed(character, info) - # ArabicIsolatedForm: is_arabic() - if info.is_arabic: - d_ai_feed(character, info) - - mean_mess_ratio = ( - d_sp.ratio - + d_ta.ratio - + d_up.ratio - + d_sda.ratio - + d_sr.ratio - + d_sw.ratio - + d_cu.ratio - + d_au.ratio - + d_ai.ratio - ) - - if mean_mess_ratio >= maximum_threshold: - break - else: - # Flush last word buffer in SuperWeirdWordPlugin via trailing newline. - info_update("\n") - d_sw_feed("\n", info) - d_au_feed("\n", info) - d_up_feed("\n", info) - - mean_mess_ratio = ( - d_sp.ratio - + d_ta.ratio - + d_up.ratio - + d_sda.ratio - + d_sr.ratio - + d_sw.ratio - + d_cu.ratio - + d_au.ratio - + d_ai.ratio - ) - - if debug: # Defensive: - logger = getLogger("charset_normalizer") - - logger.log( - TRACE, - "Mess-detector extended-analysis start. " - f"intermediary_mean_mess_ratio_calc={step} mean_mess_ratio={mean_mess_ratio} " - f"maximum_threshold={maximum_threshold}", - ) - - if seq_len > 16: - logger.log(TRACE, f"Starting with: {decoded_sequence[:16]}") - logger.log(TRACE, f"Ending with: {decoded_sequence[-16::]}") - - for dt in [d_sp, d_ta, d_up, d_sda, d_sr, d_sw, d_cu, d_au, d_ai]: - logger.log(TRACE, f"{dt.__class__}: {dt.ratio}") - - return round(mean_mess_ratio, 3) diff --git a/.venv/lib/python3.12/site-packages/charset_normalizer/models.py b/.venv/lib/python3.12/site-packages/charset_normalizer/models.py deleted file mode 100644 index 382de15..0000000 --- a/.venv/lib/python3.12/site-packages/charset_normalizer/models.py +++ /dev/null @@ -1,369 +0,0 @@ -from __future__ import annotations - -from encodings.aliases import aliases -from json import dumps -from re import sub -from typing import Any, Iterator, List, Tuple - -from .constant import RE_POSSIBLE_ENCODING_INDICATION, TOO_BIG_SEQUENCE -from .utils import iana_name, is_multi_byte_encoding, unicode_range - - -class CharsetMatch: - def __init__( - self, - payload: bytes | bytearray, - guessed_encoding: str, - mean_mess_ratio: float, - has_sig_or_bom: bool, - languages: CoherenceMatches, - decoded_payload: str | None = None, - preemptive_declaration: str | None = None, - ): - self._payload: bytes | bytearray = payload - - self._encoding: str = guessed_encoding - self._mean_mess_ratio: float = mean_mess_ratio - self._languages: CoherenceMatches = languages - self._has_sig_or_bom: bool = has_sig_or_bom - self._unicode_ranges: list[str] | None = None - - self._leaves: list[CharsetMatch] = [] - self._mean_coherence_ratio: float = 0.0 - - self._output_payload: bytes | None = None - self._output_encoding: str | None = None - - self._string: str | None = decoded_payload - - self._preemptive_declaration: str | None = preemptive_declaration - - def __eq__(self, other: object) -> bool: - if not isinstance(other, CharsetMatch): - if isinstance(other, str): - return iana_name(other) == self.encoding - return False - return self.encoding == other.encoding and self.fingerprint == other.fingerprint - - def __lt__(self, other: object) -> bool: - """ - Implemented to make sorted available upon CharsetMatches items. - """ - if not isinstance(other, CharsetMatch): - raise ValueError - - chaos_difference: float = abs(self.chaos - other.chaos) - coherence_difference: float = abs(self.coherence - other.coherence) - - # Below 0.5% difference --> Use Coherence - if chaos_difference < 0.005 and coherence_difference > 0.02: - return self.coherence > other.coherence - elif chaos_difference < 0.005 and coherence_difference <= 0.02: - # When having a difficult decision, use the result that decoded as many multi-byte as possible. - # preserve RAM usage! - if len(self._payload) >= TOO_BIG_SEQUENCE: - return self.chaos < other.chaos - return self.multi_byte_usage > other.multi_byte_usage - - return self.chaos < other.chaos - - @property - def multi_byte_usage(self) -> float: - return 1.0 - (len(str(self)) / len(self.raw)) - - def __str__(self) -> str: - # Lazy Str Loading - if self._string is None: - self._string = str(self._payload, self._encoding, "strict") - # UTF-7 BOM is encoded in modified Base64 whose byte boundary - # can overlap with the next character, so raw-byte stripping - # is unreliable. Strip the decoded BOM character instead. - if ( - self._has_sig_or_bom - and self._encoding == "utf_7" - and self._string - and self._string[0] == "\ufeff" - ): - self._string = self._string[1:] - return self._string - - def __repr__(self) -> str: - return f"" - - def add_submatch(self, other: CharsetMatch) -> None: - if not isinstance(other, CharsetMatch) or other == self: - raise ValueError( - "Unable to add instance <{}> as a submatch of a CharsetMatch".format( - other.__class__ - ) - ) - - other._string = None # Unload RAM usage; dirty trick. - self._leaves.append(other) - - @property - def encoding(self) -> str: - return self._encoding - - @property - def encoding_aliases(self) -> list[str]: - """ - Encoding name are known by many name, using this could help when searching for IBM855 when it's listed as CP855. - """ - also_known_as: list[str] = [] - for u, p in aliases.items(): - if self.encoding == u: - also_known_as.append(p) - elif self.encoding == p: - also_known_as.append(u) - return also_known_as - - @property - def bom(self) -> bool: - return self._has_sig_or_bom - - @property - def byte_order_mark(self) -> bool: - return self._has_sig_or_bom - - @property - def languages(self) -> list[str]: - """ - Return the complete list of possible languages found in decoded sequence. - Usually not really useful. Returned list may be empty even if 'language' property return something != 'Unknown'. - """ - return [e[0] for e in self._languages] - - @property - def language(self) -> str: - """ - Most probable language found in decoded sequence. If none were detected or inferred, the property will return - "Unknown". - """ - if not self._languages: - # Trying to infer the language based on the given encoding - # Its either English or we should not pronounce ourselves in certain cases. - if "ascii" in self.could_be_from_charset: - return "English" - - # doing it there to avoid circular import - from charset_normalizer.cd import encoding_languages, mb_encoding_languages - - languages = ( - mb_encoding_languages(self.encoding) - if is_multi_byte_encoding(self.encoding) - else encoding_languages(self.encoding) - ) - - if len(languages) == 0 or "Latin Based" in languages: - return "Unknown" - - return languages[0] - - return self._languages[0][0] - - @property - def chaos(self) -> float: - return self._mean_mess_ratio - - @property - def coherence(self) -> float: - if not self._languages: - return 0.0 - return self._languages[0][1] - - @property - def percent_chaos(self) -> float: - return round(self.chaos * 100, ndigits=3) - - @property - def percent_coherence(self) -> float: - return round(self.coherence * 100, ndigits=3) - - @property - def raw(self) -> bytes | bytearray: - """ - Original untouched bytes. - """ - return self._payload - - @property - def submatch(self) -> list[CharsetMatch]: - return self._leaves - - @property - def has_submatch(self) -> bool: - return len(self._leaves) > 0 - - @property - def alphabets(self) -> list[str]: - if self._unicode_ranges is not None: - return self._unicode_ranges - # list detected ranges - detected_ranges: list[str | None] = [unicode_range(char) for char in str(self)] - # filter and sort - self._unicode_ranges = sorted(list({r for r in detected_ranges if r})) - return self._unicode_ranges - - @property - def could_be_from_charset(self) -> list[str]: - """ - The complete list of encoding that output the exact SAME str result and therefore could be the originating - encoding. - This list does include the encoding available in property 'encoding'. - """ - return [self._encoding] + [m.encoding for m in self._leaves] - - def output(self, encoding: str = "utf_8") -> bytes: - """ - Method to get re-encoded bytes payload using given target encoding. Default to UTF-8. - Any errors will be simply ignored by the encoder NOT replaced. - """ - if self._output_encoding is None or self._output_encoding != encoding: - self._output_encoding = encoding - decoded_string = str(self) - if ( - self._preemptive_declaration is not None - and self._preemptive_declaration.lower() - not in ["utf-8", "utf8", "utf_8"] - ): - patched_header = sub( - RE_POSSIBLE_ENCODING_INDICATION, - lambda m: m.string[m.span()[0] : m.span()[1]].replace( - m.groups()[0], - iana_name(self._output_encoding).replace("_", "-"), # type: ignore[arg-type] - ), - decoded_string[:8192], - count=1, - ) - - decoded_string = patched_header + decoded_string[8192:] - - self._output_payload = decoded_string.encode(encoding, "replace") - - return self._output_payload # type: ignore - - @property - def fingerprint(self) -> int: - """ - Retrieve a hash fingerprint of the decoded payload, used for deduplication. - """ - return hash(str(self)) - - -class CharsetMatches: - """ - Container with every CharsetMatch items ordered by default from most probable to the less one. - Act like a list(iterable) but does not implements all related methods. - """ - - def __init__(self, results: list[CharsetMatch] | None = None): - self._results: list[CharsetMatch] = sorted(results) if results else [] - - def __iter__(self) -> Iterator[CharsetMatch]: - yield from self._results - - def __getitem__(self, item: int | str) -> CharsetMatch: - """ - Retrieve a single item either by its position or encoding name (alias may be used here). - Raise KeyError upon invalid index or encoding not present in results. - """ - if isinstance(item, int): - return self._results[item] - if isinstance(item, str): - item = iana_name(item, False) - for result in self._results: - if item in result.could_be_from_charset: - return result - raise KeyError - - def __len__(self) -> int: - return len(self._results) - - def __bool__(self) -> bool: - return len(self._results) > 0 - - def append(self, item: CharsetMatch) -> None: - """ - Insert a single match. Will be inserted accordingly to preserve sort. - Can be inserted as a submatch. - """ - if not isinstance(item, CharsetMatch): - raise ValueError( - "Cannot append instance '{}' to CharsetMatches".format( - str(item.__class__) - ) - ) - # We should disable the submatch factoring when the input file is too heavy (conserve RAM usage) - if len(item.raw) < TOO_BIG_SEQUENCE: - for match in self._results: - if match.fingerprint == item.fingerprint and match.chaos == item.chaos: - match.add_submatch(item) - return - self._results.append(item) - self._results = sorted(self._results) - - def best(self) -> CharsetMatch | None: - """ - Simply return the first match. Strict equivalent to matches[0]. - """ - if not self._results: - return None - return self._results[0] - - def first(self) -> CharsetMatch | None: - """ - Redundant method, call the method best(). Kept for BC reasons. - """ - return self.best() - - -CoherenceMatch = Tuple[str, float] -CoherenceMatches = List[CoherenceMatch] - - -class CliDetectionResult: - def __init__( - self, - path: str, - encoding: str | None, - encoding_aliases: list[str], - alternative_encodings: list[str], - language: str, - alphabets: list[str], - has_sig_or_bom: bool, - chaos: float, - coherence: float, - unicode_path: str | None, - is_preferred: bool, - ): - self.path: str = path - self.unicode_path: str | None = unicode_path - self.encoding: str | None = encoding - self.encoding_aliases: list[str] = encoding_aliases - self.alternative_encodings: list[str] = alternative_encodings - self.language: str = language - self.alphabets: list[str] = alphabets - self.has_sig_or_bom: bool = has_sig_or_bom - self.chaos: float = chaos - self.coherence: float = coherence - self.is_preferred: bool = is_preferred - - @property - def __dict__(self) -> dict[str, Any]: # type: ignore - return { - "path": self.path, - "encoding": self.encoding, - "encoding_aliases": self.encoding_aliases, - "alternative_encodings": self.alternative_encodings, - "language": self.language, - "alphabets": self.alphabets, - "has_sig_or_bom": self.has_sig_or_bom, - "chaos": self.chaos, - "coherence": self.coherence, - "unicode_path": self.unicode_path, - "is_preferred": self.is_preferred, - } - - def to_json(self) -> str: - return dumps(self.__dict__, ensure_ascii=True, indent=4) diff --git a/.venv/lib/python3.12/site-packages/charset_normalizer/py.typed b/.venv/lib/python3.12/site-packages/charset_normalizer/py.typed deleted file mode 100644 index e69de29..0000000 diff --git a/.venv/lib/python3.12/site-packages/charset_normalizer/utils.py b/.venv/lib/python3.12/site-packages/charset_normalizer/utils.py deleted file mode 100644 index 0f529b5..0000000 --- a/.venv/lib/python3.12/site-packages/charset_normalizer/utils.py +++ /dev/null @@ -1,422 +0,0 @@ -from __future__ import annotations - -import importlib -import logging -import unicodedata -from bisect import bisect_right -from codecs import IncrementalDecoder -from encodings.aliases import aliases -from functools import lru_cache -from re import findall -from typing import Generator - -from _multibytecodec import ( # type: ignore[import-not-found,import] - MultibyteIncrementalDecoder, -) - -from .constant import ( - ENCODING_MARKS, - IANA_SUPPORTED_SIMILAR, - RE_POSSIBLE_ENCODING_INDICATION, - UNICODE_RANGES_COMBINED, - UNICODE_SECONDARY_RANGE_KEYWORD, - UTF8_MAXIMAL_ALLOCATION, - COMMON_CJK_CHARACTERS, - _LATIN, - _CJK, - _HANGUL, - _KATAKANA, - _HIRAGANA, - _THAI, - _ARABIC, - _ARABIC_ISOLATED_FORM, - _ACCENT_KEYWORDS, - _ACCENTUATED, -) - - -@lru_cache(maxsize=UTF8_MAXIMAL_ALLOCATION) -def _character_flags(character: str) -> int: - """Compute all name-based classification flags with a single unicodedata.name() call.""" - try: - desc: str = unicodedata.name(character) - except ValueError: - return 0 - - flags: int = 0 - - if "LATIN" in desc: - flags |= _LATIN - if "CJK" in desc: - flags |= _CJK - if "HANGUL" in desc: - flags |= _HANGUL - if "KATAKANA" in desc: - flags |= _KATAKANA - if "HIRAGANA" in desc: - flags |= _HIRAGANA - if "THAI" in desc: - flags |= _THAI - if "ARABIC" in desc: - flags |= _ARABIC - if "ISOLATED FORM" in desc: - flags |= _ARABIC_ISOLATED_FORM - - for kw in _ACCENT_KEYWORDS: - if kw in desc: - flags |= _ACCENTUATED - break - - return flags - - -@lru_cache(maxsize=UTF8_MAXIMAL_ALLOCATION) -def is_accentuated(character: str) -> bool: - return bool(_character_flags(character) & _ACCENTUATED) - - -@lru_cache(maxsize=UTF8_MAXIMAL_ALLOCATION) -def remove_accent(character: str) -> str: - decomposed: str = unicodedata.decomposition(character) - if not decomposed: - return character - - codes: list[str] = decomposed.split(" ") - - return chr(int(codes[0], 16)) - - -# Pre-built sorted lookup table for O(log n) binary search in unicode_range(). -# Each entry is (range_start, range_end_exclusive, range_name). -_UNICODE_RANGES_SORTED: list[tuple[int, int, str]] = sorted( - (ord_range.start, ord_range.stop, name) - for name, ord_range in UNICODE_RANGES_COMBINED.items() -) -_UNICODE_RANGE_STARTS: list[int] = [e[0] for e in _UNICODE_RANGES_SORTED] - - -@lru_cache(maxsize=UTF8_MAXIMAL_ALLOCATION) -def unicode_range(character: str) -> str | None: - """ - Retrieve the Unicode range official name from a single character. - """ - character_ord: int = ord(character) - - # Binary search: find the rightmost range whose start <= character_ord - idx = bisect_right(_UNICODE_RANGE_STARTS, character_ord) - 1 - if idx >= 0: - start, stop, name = _UNICODE_RANGES_SORTED[idx] - if character_ord < stop: - return name - - return None - - -@lru_cache(maxsize=UTF8_MAXIMAL_ALLOCATION) -def is_latin(character: str) -> bool: - return bool(_character_flags(character) & _LATIN) - - -@lru_cache(maxsize=UTF8_MAXIMAL_ALLOCATION) -def is_punctuation(character: str) -> bool: - character_category: str = unicodedata.category(character) - - if "P" in character_category: - return True - - character_range: str | None = unicode_range(character) - - if character_range is None: - return False - - return "Punctuation" in character_range - - -@lru_cache(maxsize=UTF8_MAXIMAL_ALLOCATION) -def is_symbol(character: str) -> bool: - character_category: str = unicodedata.category(character) - - if "S" in character_category or "N" in character_category: - return True - - character_range: str | None = unicode_range(character) - - if character_range is None: - return False - - return "Forms" in character_range and character_category != "Lo" - - -@lru_cache(maxsize=UTF8_MAXIMAL_ALLOCATION) -def is_emoticon(character: str) -> bool: - character_range: str | None = unicode_range(character) - - if character_range is None: - return False - - return "Emoticons" in character_range or "Pictographs" in character_range - - -@lru_cache(maxsize=UTF8_MAXIMAL_ALLOCATION) -def is_separator(character: str) -> bool: - if character.isspace() or character in {"|", "+", "<", ">"}: - return True - - character_category: str = unicodedata.category(character) - - return "Z" in character_category or character_category in {"Po", "Pd", "Pc"} - - -@lru_cache(maxsize=UTF8_MAXIMAL_ALLOCATION) -def is_case_variable(character: str) -> bool: - return character.islower() != character.isupper() - - -@lru_cache(maxsize=UTF8_MAXIMAL_ALLOCATION) -def is_cjk(character: str) -> bool: - return bool(_character_flags(character) & _CJK) - - -@lru_cache(maxsize=UTF8_MAXIMAL_ALLOCATION) -def is_hiragana(character: str) -> bool: - return bool(_character_flags(character) & _HIRAGANA) - - -@lru_cache(maxsize=UTF8_MAXIMAL_ALLOCATION) -def is_katakana(character: str) -> bool: - return bool(_character_flags(character) & _KATAKANA) - - -@lru_cache(maxsize=UTF8_MAXIMAL_ALLOCATION) -def is_hangul(character: str) -> bool: - return bool(_character_flags(character) & _HANGUL) - - -@lru_cache(maxsize=UTF8_MAXIMAL_ALLOCATION) -def is_thai(character: str) -> bool: - return bool(_character_flags(character) & _THAI) - - -@lru_cache(maxsize=UTF8_MAXIMAL_ALLOCATION) -def is_arabic(character: str) -> bool: - return bool(_character_flags(character) & _ARABIC) - - -@lru_cache(maxsize=UTF8_MAXIMAL_ALLOCATION) -def is_arabic_isolated_form(character: str) -> bool: - return bool(_character_flags(character) & _ARABIC_ISOLATED_FORM) - - -@lru_cache(maxsize=UTF8_MAXIMAL_ALLOCATION) -def is_cjk_uncommon(character: str) -> bool: - return character not in COMMON_CJK_CHARACTERS - - -@lru_cache(maxsize=len(UNICODE_RANGES_COMBINED)) -def is_unicode_range_secondary(range_name: str) -> bool: - return any(keyword in range_name for keyword in UNICODE_SECONDARY_RANGE_KEYWORD) - - -@lru_cache(maxsize=UTF8_MAXIMAL_ALLOCATION) -def is_unprintable(character: str) -> bool: - return ( - character.isspace() is False # includes \n \t \r \v - and character.isprintable() is False - and character != "\x1a" # Why? Its the ASCII substitute character. - and character != "\ufeff" # bug discovered in Python, - # Zero Width No-Break Space located in Arabic Presentation Forms-B, Unicode 1.1 not acknowledged as space. - ) - - -def any_specified_encoding( - sequence: bytes | bytearray, search_zone: int = 8192 -) -> str | None: - """ - Extract using ASCII-only decoder any specified encoding in the first n-bytes. - """ - if not isinstance(sequence, (bytes, bytearray)): - raise TypeError - - seq_len: int = len(sequence) - - results: list[str] = findall( - RE_POSSIBLE_ENCODING_INDICATION, - sequence[: min(seq_len, search_zone)].decode("ascii", errors="ignore"), - ) - - if len(results) == 0: - return None - - for specified_encoding in results: - specified_encoding = specified_encoding.lower().replace("-", "_") - - encoding_alias: str - encoding_iana: str - - for encoding_alias, encoding_iana in aliases.items(): - if encoding_alias == specified_encoding: - return encoding_iana - if encoding_iana == specified_encoding: - return encoding_iana - - return None - - -@lru_cache(maxsize=128) -def is_multi_byte_encoding(name: str) -> bool: - """ - Verify is a specific encoding is a multi byte one based on it IANA name - """ - return name in { - "utf_8", - "utf_8_sig", - "utf_16", - "utf_16_be", - "utf_16_le", - "utf_32", - "utf_32_le", - "utf_32_be", - "utf_7", - } or issubclass( - importlib.import_module(f"encodings.{name}").IncrementalDecoder, - MultibyteIncrementalDecoder, - ) - - -def identify_sig_or_bom(sequence: bytes | bytearray) -> tuple[str | None, bytes]: - """ - Identify and extract SIG/BOM in given sequence. - """ - - for iana_encoding in ENCODING_MARKS: - marks: bytes | list[bytes] = ENCODING_MARKS[iana_encoding] - - if isinstance(marks, bytes): - marks = [marks] - - for mark in marks: - if sequence.startswith(mark): - return iana_encoding, mark - - return None, b"" - - -def should_strip_sig_or_bom(iana_encoding: str) -> bool: - return iana_encoding not in {"utf_16", "utf_32"} - - -def iana_name(cp_name: str, strict: bool = True) -> str: - """Returns the Python normalized encoding name (Not the IANA official name).""" - cp_name = cp_name.lower().replace("-", "_") - - encoding_alias: str - encoding_iana: str - - for encoding_alias, encoding_iana in aliases.items(): - if cp_name in [encoding_alias, encoding_iana]: - return encoding_iana - - if strict: - raise ValueError(f"Unable to retrieve IANA for '{cp_name}'") - - return cp_name - - -def cp_similarity(iana_name_a: str, iana_name_b: str) -> float: - if is_multi_byte_encoding(iana_name_a) or is_multi_byte_encoding(iana_name_b): - return 0.0 - - decoder_a = importlib.import_module(f"encodings.{iana_name_a}").IncrementalDecoder - decoder_b = importlib.import_module(f"encodings.{iana_name_b}").IncrementalDecoder - - id_a: IncrementalDecoder = decoder_a(errors="ignore") - id_b: IncrementalDecoder = decoder_b(errors="ignore") - - character_match_count: int = 0 - - for i in range(256): - to_be_decoded: bytes = bytes([i]) - if id_a.decode(to_be_decoded) == id_b.decode(to_be_decoded): - character_match_count += 1 - - return character_match_count / 256 - - -def is_cp_similar(iana_name_a: str, iana_name_b: str) -> bool: - """ - Determine if two code page are at least 80% similar. IANA_SUPPORTED_SIMILAR dict was generated using - the function cp_similarity. - """ - return ( - iana_name_a in IANA_SUPPORTED_SIMILAR - and iana_name_b in IANA_SUPPORTED_SIMILAR[iana_name_a] - ) - - -def set_logging_handler( - name: str = "charset_normalizer", - level: int = logging.INFO, - format_string: str = "%(asctime)s | %(levelname)s | %(message)s", -) -> None: - logger = logging.getLogger(name) - logger.setLevel(level) - - handler = logging.StreamHandler() - handler.setFormatter(logging.Formatter(format_string)) - logger.addHandler(handler) - - -def cut_sequence_chunks( - sequences: bytes | bytearray, - encoding_iana: str, - offsets: range, - chunk_size: int, - bom_or_sig_available: bool, - strip_sig_or_bom: bool, - sig_payload: bytes, - is_multi_byte_decoder: bool, - decoded_payload: str | None = None, -) -> Generator[str, None, None]: - if decoded_payload and is_multi_byte_decoder is False: - for i in offsets: - chunk = decoded_payload[i : i + chunk_size] - if not chunk: - break - yield chunk - else: - for i in offsets: - chunk_end = i + chunk_size - if chunk_end > len(sequences) + 8: - continue - - cut_sequence = sequences[i : i + chunk_size] - - if bom_or_sig_available and strip_sig_or_bom is False: - cut_sequence = sig_payload + cut_sequence - - chunk = cut_sequence.decode( - encoding_iana, - errors="ignore" if is_multi_byte_decoder else "strict", - ) - - # multi-byte bad cutting detector and adjustment - # not the cleanest way to perform that fix but clever enough for now. - if is_multi_byte_decoder and i > 0: - chunk_partial_size_chk: int = min(chunk_size, 16) - - if ( - decoded_payload - and chunk[:chunk_partial_size_chk] not in decoded_payload - ): - for j in range(i, i - 4, -1): - cut_sequence = sequences[j:chunk_end] - - if bom_or_sig_available and strip_sig_or_bom is False: - cut_sequence = sig_payload + cut_sequence - - chunk = cut_sequence.decode(encoding_iana, errors="ignore") - - if chunk[:chunk_partial_size_chk] in decoded_payload: - break - - yield chunk diff --git a/.venv/lib/python3.12/site-packages/charset_normalizer/version.py b/.venv/lib/python3.12/site-packages/charset_normalizer/version.py deleted file mode 100644 index a93d367..0000000 --- a/.venv/lib/python3.12/site-packages/charset_normalizer/version.py +++ /dev/null @@ -1,8 +0,0 @@ -""" -Expose version -""" - -from __future__ import annotations - -__version__ = "3.4.7" -VERSION = __version__.split(".") diff --git a/.venv/lib/python3.12/site-packages/cryptography-48.0.0.dist-info/INSTALLER b/.venv/lib/python3.12/site-packages/cryptography-48.0.0.dist-info/INSTALLER deleted file mode 100644 index a1b589e..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography-48.0.0.dist-info/INSTALLER +++ /dev/null @@ -1 +0,0 @@ -pip diff --git a/.venv/lib/python3.12/site-packages/cryptography-48.0.0.dist-info/METADATA b/.venv/lib/python3.12/site-packages/cryptography-48.0.0.dist-info/METADATA deleted file mode 100644 index fbea0aa..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography-48.0.0.dist-info/METADATA +++ /dev/null @@ -1,110 +0,0 @@ -Metadata-Version: 2.4 -Name: cryptography -Version: 48.0.0 -Classifier: Development Status :: 5 - Production/Stable -Classifier: Intended Audience :: Developers -Classifier: Natural Language :: English -Classifier: Operating System :: MacOS :: MacOS X -Classifier: Operating System :: POSIX -Classifier: Operating System :: POSIX :: BSD -Classifier: Operating System :: POSIX :: Linux -Classifier: Operating System :: Microsoft :: Windows -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: Programming Language :: Python :: Free Threading :: 3 - Stable -Classifier: Topic :: Security :: Cryptography -Requires-Dist: cffi>=2.0.0 ; platform_python_implementation != 'PyPy' -Requires-Dist: typing-extensions>=4.13.2 ; python_full_version < '3.11' -Requires-Dist: bcrypt>=3.1.5 ; extra == 'ssh' -Provides-Extra: ssh -License-File: LICENSE -License-File: LICENSE.APACHE -License-File: LICENSE.BSD -Summary: cryptography is a package which provides cryptographic recipes and primitives to Python developers. -Author-email: The Python Cryptographic Authority and individual contributors -License-Expression: Apache-2.0 OR BSD-3-Clause -Requires-Python: >=3.9, !=3.9.0, !=3.9.1 -Description-Content-Type: text/x-rst; charset=UTF-8 -Project-URL: changelog, https://cryptography.io/en/latest/changelog/ -Project-URL: documentation, https://cryptography.io/ -Project-URL: homepage, https://github.com/pyca/cryptography -Project-URL: issues, https://github.com/pyca/cryptography/issues -Project-URL: source, https://github.com/pyca/cryptography/ - -pyca/cryptography -================= - -.. image:: https://img.shields.io/pypi/v/cryptography.svg - :target: https://pypi.org/project/cryptography/ - :alt: Latest Version - -.. image:: https://readthedocs.org/projects/cryptography/badge/?version=latest - :target: https://cryptography.io - :alt: Latest Docs - -.. image:: https://github.com/pyca/cryptography/actions/workflows/ci.yml/badge.svg - :target: https://github.com/pyca/cryptography/actions/workflows/ci.yml?query=branch%3Amain - -``cryptography`` is a package which provides cryptographic recipes and -primitives to Python developers. Our goal is for it to be your "cryptographic -standard library". It supports Python 3.9+ and PyPy3 7.3.11+. - -``cryptography`` includes both high level recipes and low level interfaces to -common cryptographic algorithms such as symmetric ciphers, message digests, and -key derivation functions. For example, to encrypt something with -``cryptography``'s high level symmetric encryption recipe: - -.. code-block:: pycon - - >>> from cryptography.fernet import Fernet - >>> # Put this somewhere safe! - >>> key = Fernet.generate_key() - >>> f = Fernet(key) - >>> token = f.encrypt(b"A really secret message. Not for prying eyes.") - >>> token - b'...' - >>> f.decrypt(token) - b'A really secret message. Not for prying eyes.' - -You can find more information in the `documentation`_. - -You can install ``cryptography`` with: - -.. code-block:: console - - $ pip install cryptography - -For full details see `the installation documentation`_. - -Discussion -~~~~~~~~~~ - -If you run into bugs, you can file them in our `issue tracker`_. - -We maintain a `cryptography-dev`_ mailing list for development discussion. - -You can also join ``#pyca`` on ``irc.libera.chat`` to ask questions or get -involved. - -Security -~~~~~~~~ - -Need to report a security issue? Please consult our `security reporting`_ -documentation. - - -.. _`documentation`: https://cryptography.io/ -.. _`the installation documentation`: https://cryptography.io/en/latest/installation/ -.. _`issue tracker`: https://github.com/pyca/cryptography/issues -.. _`cryptography-dev`: https://mail.python.org/mailman/listinfo/cryptography-dev -.. _`security reporting`: https://cryptography.io/en/latest/security/ - diff --git a/.venv/lib/python3.12/site-packages/cryptography-48.0.0.dist-info/RECORD b/.venv/lib/python3.12/site-packages/cryptography-48.0.0.dist-info/RECORD deleted file mode 100644 index 99dc725..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography-48.0.0.dist-info/RECORD +++ /dev/null @@ -1,196 +0,0 @@ -cryptography-48.0.0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4 -cryptography-48.0.0.dist-info/METADATA,sha256=Q_COX-Utpsgl5e4Ym9mF7hU3hgAgMy3Ly8XaVnneyQY,4343 -cryptography-48.0.0.dist-info/RECORD,, -cryptography-48.0.0.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0 -cryptography-48.0.0.dist-info/WHEEL,sha256=59dZFnCZ9Ah4-4Hov4_Ij4OuERDplrmrGrO0EnwpCG0,109 -cryptography-48.0.0.dist-info/licenses/LICENSE,sha256=Pgx8CRqUi4JTO6mP18u0BDLW8amsv4X1ki0vmak65rs,197 -cryptography-48.0.0.dist-info/licenses/LICENSE.APACHE,sha256=qsc7MUj20dcRHbyjIJn2jSbGRMaBOuHk8F9leaomY_4,11360 -cryptography-48.0.0.dist-info/licenses/LICENSE.BSD,sha256=YCxMdILeZHndLpeTzaJ15eY9dz2s0eymiSMqtwCPtPs,1532 -cryptography-48.0.0.dist-info/sboms/cryptography-rust.cyclonedx.json,sha256=1fzfm56UYqOyUDjSaZ_PR1FgbE0pmZk5bxNk6uJedaI,45613 -cryptography-48.0.0.dist-info/sboms/sbom.json,sha256=hj41wZWnr0WU1kaHtI0VS_cPesX716EgqQjDnxMp0yI,1206 -cryptography/__about__.py,sha256=4Ay52_5LrlJ_oTPcjtV4NXOcNzJhpo6iDZPEYbndzJI,445 -cryptography/__init__.py,sha256=mthuUrTd4FROCpUYrTIqhjz6s6T9djAZrV7nZ1oMm2o,364 -cryptography/__pycache__/__about__.cpython-312.pyc,, -cryptography/__pycache__/__init__.cpython-312.pyc,, -cryptography/__pycache__/exceptions.cpython-312.pyc,, -cryptography/__pycache__/fernet.cpython-312.pyc,, -cryptography/__pycache__/utils.cpython-312.pyc,, -cryptography/exceptions.py,sha256=835EWILc2fwxw-gyFMriciC2SqhViETB10LBSytnDIc,1087 -cryptography/fernet.py,sha256=3Cvxkh0KJSbX8HbnCHu4wfCW7U0GgfUA3v_qQ8a8iWc,6963 -cryptography/hazmat/__init__.py,sha256=5IwrLWrVp0AjEr_4FdWG_V057NSJGY_W4egNNsuct0g,455 -cryptography/hazmat/__pycache__/__init__.cpython-312.pyc,, -cryptography/hazmat/__pycache__/_oid.cpython-312.pyc,, -cryptography/hazmat/_oid.py,sha256=p8ThjwJB56Ci_rAIrjyJ1f8VjgD6e39es2dh8JIUBOw,17240 -cryptography/hazmat/asn1/__init__.py,sha256=AZVmLA09Q9-bq27G8fYr3dof-iRkh5KSX3zEPmNb-9w,744 -cryptography/hazmat/asn1/__pycache__/__init__.cpython-312.pyc,, -cryptography/hazmat/asn1/__pycache__/asn1.cpython-312.pyc,, -cryptography/hazmat/asn1/asn1.py,sha256=FZ6nZr3N1kKqNBQfh0qKtJ0cLUjwtGFemG82KNWOcfk,14724 -cryptography/hazmat/backends/__init__.py,sha256=O5jvKFQdZnXhKeqJ-HtulaEL9Ni7mr1mDzZY5kHlYhI,361 -cryptography/hazmat/backends/__pycache__/__init__.cpython-312.pyc,, -cryptography/hazmat/backends/openssl/__init__.py,sha256=p3jmJfnCag9iE5sdMrN6VvVEu55u46xaS_IjoI0SrmA,305 -cryptography/hazmat/backends/openssl/__pycache__/__init__.cpython-312.pyc,, -cryptography/hazmat/backends/openssl/__pycache__/backend.cpython-312.pyc,, -cryptography/hazmat/backends/openssl/backend.py,sha256=7A8JKJlQjG3-Fqdcyat2Eb7kHLYAAtGF0j9ooaWyaE0,10520 -cryptography/hazmat/bindings/__init__.py,sha256=s9oKCQ2ycFdXoERdS1imafueSkBsL9kvbyfghaauZ9Y,180 -cryptography/hazmat/bindings/__pycache__/__init__.cpython-312.pyc,, -cryptography/hazmat/bindings/_rust.abi3.so,sha256=UVbEIvZcX5Eb4cvajr3IhuE7RL74hDZf3cObn80DKeY,13844864 -cryptography/hazmat/bindings/_rust/__init__.pyi,sha256=uUnnvOq_uameYnBNpmsv3SRAVO0WQGpjI58aR1lL4Kw,2285 -cryptography/hazmat/bindings/_rust/_openssl.pyi,sha256=T_5TpYO8bghIPjAQ3BtAABqw-CcYskHp92wm5PNY6dc,228 -cryptography/hazmat/bindings/_rust/asn1.pyi,sha256=BrGjC8J6nwuS-r3EVcdXJB8ndotfY9mbQYOfpbPG0HA,354 -cryptography/hazmat/bindings/_rust/declarative_asn1.pyi,sha256=iSeRyyd3hN0VIUKg_p424AzQ-b7hW1b_53Yx50yniYY,3661 -cryptography/hazmat/bindings/_rust/exceptions.pyi,sha256=exXr2xw_0pB1kk93cYbM3MohbzoUkjOms1ZMUi0uQZE,640 -cryptography/hazmat/bindings/_rust/ocsp.pyi,sha256=VPVWuKHI9EMs09ZLRYAGvR0Iz0mCMmEzXAkgJHovpoM,4020 -cryptography/hazmat/bindings/_rust/openssl/__init__.pyi,sha256=JDCef29vXnrEMvF13JH9z1-W9ahiTZQAk5xhu_KH6po,1550 -cryptography/hazmat/bindings/_rust/openssl/aead.pyi,sha256=7d--xdc0vuzRe4S2uuQaGm-9GGKv4NcSLQcLyWcaD6s,4582 -cryptography/hazmat/bindings/_rust/openssl/ciphers.pyi,sha256=LhPzHWSXJq4grAJXn6zSvSSdV-aYIIscHDwIPlJGGPs,1315 -cryptography/hazmat/bindings/_rust/openssl/cmac.pyi,sha256=nPH0X57RYpsAkRowVpjQiHE566ThUTx7YXrsadmrmHk,564 -cryptography/hazmat/bindings/_rust/openssl/dh.pyi,sha256=Z3TC-G04-THtSdAOPLM1h2G7ml5bda1ElZUcn5wpuhk,1564 -cryptography/hazmat/bindings/_rust/openssl/dsa.pyi,sha256=qBtkgj2albt2qFcnZ9UDrhzoNhCVO7HTby5VSf1EXMI,1299 -cryptography/hazmat/bindings/_rust/openssl/ec.pyi,sha256=zJy0pRa5n-_p2dm45PxECB_-B6SVZyNKfjxFDpPqT38,1691 -cryptography/hazmat/bindings/_rust/openssl/ed25519.pyi,sha256=VXfXd5G6hUivg399R1DYdmW3eTb0EebzDTqjRC2gaRw,532 -cryptography/hazmat/bindings/_rust/openssl/ed448.pyi,sha256=Yx49lqdnjsD7bxiDV1kcaMrDktug5evi5a6zerMiy2s,514 -cryptography/hazmat/bindings/_rust/openssl/hashes.pyi,sha256=bFe3T13UeyRInUJMD-R5ArGTGLqWDiWo2Lv2KGzUbf4,1076 -cryptography/hazmat/bindings/_rust/openssl/hmac.pyi,sha256=BXZn7NDjL3JAbYW0SQ8pg1iyC5DbQXVhUAiwsi8DFR8,702 -cryptography/hazmat/bindings/_rust/openssl/hpke.pyi,sha256=wrz8c12gBNBAItz9jorr_W4s8rFYDE1Yel1z2I-Wd2s,2877 -cryptography/hazmat/bindings/_rust/openssl/kdf.pyi,sha256=HiiLdEB9nqMsTvMwiFppQpfPz6fHUz9_gpjEB_XAOXA,6619 -cryptography/hazmat/bindings/_rust/openssl/keys.pyi,sha256=teIt8M6ZEMJrn4s3W0UnW0DZ-30Jd68WnSsKKG124l0,912 -cryptography/hazmat/bindings/_rust/openssl/mldsa.pyi,sha256=HChNsjW0C_vO9OVD4FhEZrXO3_FiEq2ZTF59hlfcEdM,1073 -cryptography/hazmat/bindings/_rust/openssl/mlkem.pyi,sha256=byoeus4-lIOlWlEiRQdCc00qCkXpOB5peBY6yo9ik8s,835 -cryptography/hazmat/bindings/_rust/openssl/poly1305.pyi,sha256=_SW9NtQ5FDlAbdclFtWpT4lGmxKIKHpN-4j8J2BzYfQ,585 -cryptography/hazmat/bindings/_rust/openssl/rsa.pyi,sha256=2OQCNSXkxgc-3uw1xiCCloIQTV6p9_kK79Yu0rhZgPc,1364 -cryptography/hazmat/bindings/_rust/openssl/x25519.pyi,sha256=ewn4GpQyb7zPwE-ni7GtyQgMC0A1mLuqYsSyqv6nI_s,523 -cryptography/hazmat/bindings/_rust/openssl/x448.pyi,sha256=juTZTmli8jO_5Vcufg-vHvx_tCyezmSLIh_9PU3TczI,505 -cryptography/hazmat/bindings/_rust/pkcs12.pyi,sha256=vEEd5wDiZvb8ZGFaziLCaWLzAwoG_tvPUxLQw5_uOl8,1605 -cryptography/hazmat/bindings/_rust/pkcs7.pyi,sha256=txGBJijqZshEcqra6byPNbnisIdlxzOSIHP2hl9arPs,1601 -cryptography/hazmat/bindings/_rust/test_support.pyi,sha256=PPhld-WkO743iXFPebeG0LtgK0aTzGdjcIsay1Gm5GE,757 -cryptography/hazmat/bindings/_rust/x509.pyi,sha256=rmt4enscdvDQ7lBEHb2cASwN0d3TP3ymEVZcEJ-Rf3A,10152 -cryptography/hazmat/bindings/openssl/__init__.py,sha256=s9oKCQ2ycFdXoERdS1imafueSkBsL9kvbyfghaauZ9Y,180 -cryptography/hazmat/bindings/openssl/__pycache__/__init__.cpython-312.pyc,, -cryptography/hazmat/bindings/openssl/__pycache__/_conditional.cpython-312.pyc,, -cryptography/hazmat/bindings/openssl/__pycache__/binding.cpython-312.pyc,, -cryptography/hazmat/bindings/openssl/_conditional.py,sha256=vfzi-xHdStAcJQjLqqOlSos94L8D_tqFtBe7Ovw-KtY,5611 -cryptography/hazmat/bindings/openssl/binding.py,sha256=GnoZLYvCzXbKf4KldUXec-oz-hdVSa_sinZnqXgdS2s,4096 -cryptography/hazmat/decrepit/__init__.py,sha256=wHCbWfaefa-fk6THSw9th9fJUsStJo7245wfFBqmduA,216 -cryptography/hazmat/decrepit/__pycache__/__init__.cpython-312.pyc,, -cryptography/hazmat/decrepit/ciphers/__init__.py,sha256=wHCbWfaefa-fk6THSw9th9fJUsStJo7245wfFBqmduA,216 -cryptography/hazmat/decrepit/ciphers/__pycache__/__init__.cpython-312.pyc,, -cryptography/hazmat/decrepit/ciphers/__pycache__/algorithms.cpython-312.pyc,, -cryptography/hazmat/decrepit/ciphers/__pycache__/modes.cpython-312.pyc,, -cryptography/hazmat/decrepit/ciphers/algorithms.py,sha256=yqHt7k5OzF_KuvO8M9vTlNLtG7EotbvShyYKIaUJqhg,3566 -cryptography/hazmat/decrepit/ciphers/modes.py,sha256=Oq_PEwCke5OLczOfr_vzAOJ6wPx-rlsvHAXPBuh5b9o,1649 -cryptography/hazmat/primitives/__init__.py,sha256=s9oKCQ2ycFdXoERdS1imafueSkBsL9kvbyfghaauZ9Y,180 -cryptography/hazmat/primitives/__pycache__/__init__.cpython-312.pyc,, -cryptography/hazmat/primitives/__pycache__/_asymmetric.cpython-312.pyc,, -cryptography/hazmat/primitives/__pycache__/_cipheralgorithm.cpython-312.pyc,, -cryptography/hazmat/primitives/__pycache__/_modes.cpython-312.pyc,, -cryptography/hazmat/primitives/__pycache__/_serialization.cpython-312.pyc,, -cryptography/hazmat/primitives/__pycache__/cmac.cpython-312.pyc,, -cryptography/hazmat/primitives/__pycache__/constant_time.cpython-312.pyc,, -cryptography/hazmat/primitives/__pycache__/hashes.cpython-312.pyc,, -cryptography/hazmat/primitives/__pycache__/hmac.cpython-312.pyc,, -cryptography/hazmat/primitives/__pycache__/hpke.cpython-312.pyc,, -cryptography/hazmat/primitives/__pycache__/keywrap.cpython-312.pyc,, -cryptography/hazmat/primitives/__pycache__/padding.cpython-312.pyc,, -cryptography/hazmat/primitives/__pycache__/poly1305.cpython-312.pyc,, -cryptography/hazmat/primitives/_asymmetric.py,sha256=RhgcouUB6HTiFDBrR1LxqkMjpUxIiNvQ1r_zJjRG6qQ,532 -cryptography/hazmat/primitives/_cipheralgorithm.py,sha256=Eh3i7lwedHfi0eLSsH93PZxQKzY9I6lkK67vL4V5tOc,1522 -cryptography/hazmat/primitives/_modes.py,sha256=_EiAOD8Jb6WpFXluwkcUT3ECz_TH8xjGvbQlGkNm59Q,3075 -cryptography/hazmat/primitives/_serialization.py,sha256=hi0xJblBAZ8pmZx2lWa-lruphxvvvG3g9DNK0G8Odfs,4440 -cryptography/hazmat/primitives/asymmetric/__init__.py,sha256=s9oKCQ2ycFdXoERdS1imafueSkBsL9kvbyfghaauZ9Y,180 -cryptography/hazmat/primitives/asymmetric/__pycache__/__init__.cpython-312.pyc,, -cryptography/hazmat/primitives/asymmetric/__pycache__/dh.cpython-312.pyc,, -cryptography/hazmat/primitives/asymmetric/__pycache__/dsa.cpython-312.pyc,, -cryptography/hazmat/primitives/asymmetric/__pycache__/ec.cpython-312.pyc,, -cryptography/hazmat/primitives/asymmetric/__pycache__/ed25519.cpython-312.pyc,, -cryptography/hazmat/primitives/asymmetric/__pycache__/ed448.cpython-312.pyc,, -cryptography/hazmat/primitives/asymmetric/__pycache__/mldsa.cpython-312.pyc,, -cryptography/hazmat/primitives/asymmetric/__pycache__/mlkem.cpython-312.pyc,, -cryptography/hazmat/primitives/asymmetric/__pycache__/padding.cpython-312.pyc,, -cryptography/hazmat/primitives/asymmetric/__pycache__/rsa.cpython-312.pyc,, -cryptography/hazmat/primitives/asymmetric/__pycache__/types.cpython-312.pyc,, -cryptography/hazmat/primitives/asymmetric/__pycache__/utils.cpython-312.pyc,, -cryptography/hazmat/primitives/asymmetric/__pycache__/x25519.cpython-312.pyc,, -cryptography/hazmat/primitives/asymmetric/__pycache__/x448.cpython-312.pyc,, -cryptography/hazmat/primitives/asymmetric/dh.py,sha256=klvHVaxAFkUyaWXLytqYjBTh81Zx1ByCJNZVRcSDYX8,3912 -cryptography/hazmat/primitives/asymmetric/dsa.py,sha256=kQzTViqAI9PiELNOBco_n6MfP3N9ehIPkSduOpupt0M,4482 -cryptography/hazmat/primitives/asymmetric/ec.py,sha256=LklVCLLxbbQzqiE6HRaYTRauLMphYUw3tE6c8oBIxYQ,10183 -cryptography/hazmat/primitives/asymmetric/ed25519.py,sha256=mbffLvs-3PgCDeg1rQXVXh7GLntlVL4ATjkIEc4pt5M,2998 -cryptography/hazmat/primitives/asymmetric/ed448.py,sha256=n0dK6y-VLxuw-zvrDxuPT4598hymgX-1Ry_jq9aUQhE,4002 -cryptography/hazmat/primitives/asymmetric/mldsa.py,sha256=49DPIhoHEyfGVwL6DRc3WlJ20Rinq-ldtjsp91NpyMM,12226 -cryptography/hazmat/primitives/asymmetric/mlkem.py,sha256=wvVkeFT-4of-VcUAER2-zI_5hXT6rwTJPMCQ8gF9GTA,7901 -cryptography/hazmat/primitives/asymmetric/padding.py,sha256=vQ6l6gOg9HqcbOsvHrSiJRVLdEj9L4m4HkRGYziTyFA,2854 -cryptography/hazmat/primitives/asymmetric/rsa.py,sha256=lIE7lGe449W5URLTKCpvFGerITouKoZV9GwuTzScsSo,8492 -cryptography/hazmat/primitives/asymmetric/types.py,sha256=q3glpax4EHgNpkRSEXlhK43a07F3Dsk-rQ3bbjL9ZnM,3309 -cryptography/hazmat/primitives/asymmetric/utils.py,sha256=Qs8Re9GFPjW_tNp_73IeJEjPCf0slOIsWOxo6qymT6k,821 -cryptography/hazmat/primitives/asymmetric/x25519.py,sha256=lQcgUk-Piubj8ynFNWQeYme3tYZMgHQqkRKkIDOHLzo,3888 -cryptography/hazmat/primitives/asymmetric/x448.py,sha256=b37ig7k7poG6SJDry42j-ElCj5q4eQ0X5CFmN0Sn8z8,3913 -cryptography/hazmat/primitives/ciphers/__init__.py,sha256=eyEXmjk6_CZXaOPYDr7vAYGXr29QvzgWL2-4CSolLFs,680 -cryptography/hazmat/primitives/ciphers/__pycache__/__init__.cpython-312.pyc,, -cryptography/hazmat/primitives/ciphers/__pycache__/aead.cpython-312.pyc,, -cryptography/hazmat/primitives/ciphers/__pycache__/algorithms.cpython-312.pyc,, -cryptography/hazmat/primitives/ciphers/__pycache__/base.cpython-312.pyc,, -cryptography/hazmat/primitives/ciphers/__pycache__/modes.cpython-312.pyc,, -cryptography/hazmat/primitives/ciphers/aead.py,sha256=Fzlyx7w8KYQakzDp1zWgJnIr62zgZrgVh1u2h4exB54,634 -cryptography/hazmat/primitives/ciphers/algorithms.py,sha256=IGfCycYJOh1TvoI34rfw8KfJ_xmt1p_DpBht2Fghceo,3496 -cryptography/hazmat/primitives/ciphers/base.py,sha256=aBC7HHBBoixebmparVr0UlODs3VD0A7B6oz_AaRjDv8,4253 -cryptography/hazmat/primitives/ciphers/modes.py,sha256=pNI0cSLCLxr7lz7ApfUpVpFH5q_bzOpKW-QggmgQB74,6007 -cryptography/hazmat/primitives/cmac.py,sha256=sz_s6H_cYnOvx-VNWdIKhRhe3Ymp8z8J0D3CBqOX3gg,338 -cryptography/hazmat/primitives/constant_time.py,sha256=xdunWT0nf8OvKdcqUhhlFKayGp4_PgVJRU2W1wLSr_A,422 -cryptography/hazmat/primitives/hashes.py,sha256=M8BrlKB3U6DEtHvWTV5VRjpteHv1kS3Zxm_Bsk04cr8,5184 -cryptography/hazmat/primitives/hmac.py,sha256=RpB3z9z5skirCQrm7zQbtnp9pLMnAjrlTUvKqF5aDDc,423 -cryptography/hazmat/primitives/hpke.py,sha256=RsHissC5l-dTPn1p2JbcrIrAnDBrLqM5ugBFSGpmKu4,865 -cryptography/hazmat/primitives/kdf/__init__.py,sha256=v3yiYBGU272EojNXbwfYZdbbfI9cVOCCG3nXhTDda3k,1037 -cryptography/hazmat/primitives/kdf/__pycache__/__init__.cpython-312.pyc,, -cryptography/hazmat/primitives/kdf/__pycache__/argon2.cpython-312.pyc,, -cryptography/hazmat/primitives/kdf/__pycache__/concatkdf.cpython-312.pyc,, -cryptography/hazmat/primitives/kdf/__pycache__/hkdf.cpython-312.pyc,, -cryptography/hazmat/primitives/kdf/__pycache__/kbkdf.cpython-312.pyc,, -cryptography/hazmat/primitives/kdf/__pycache__/pbkdf2.cpython-312.pyc,, -cryptography/hazmat/primitives/kdf/__pycache__/scrypt.cpython-312.pyc,, -cryptography/hazmat/primitives/kdf/__pycache__/x963kdf.cpython-312.pyc,, -cryptography/hazmat/primitives/kdf/argon2.py,sha256=ZJx-enUlAA4o7b46C1wlzG_XAQQW0wIkFgUKkrM_wA8,632 -cryptography/hazmat/primitives/kdf/concatkdf.py,sha256=BFnOKS72txKF0yQvASr0Na7uhzvLHpUCckK5iNAC_aQ,591 -cryptography/hazmat/primitives/kdf/hkdf.py,sha256=M0lAEfRoc4kpp4-nwDj9yB-vNZukIOYEQrUlWsBNn9o,543 -cryptography/hazmat/primitives/kdf/kbkdf.py,sha256=C3w99vjFqhqzAxzFOH4zzvVoHkb5AC6Lz6AEQGV7d_g,737 -cryptography/hazmat/primitives/kdf/pbkdf2.py,sha256=Xchkk99s-Mk6b6KSCouqdk8FVyiNVOSFIenmnW3tLgQ,468 -cryptography/hazmat/primitives/kdf/scrypt.py,sha256=XyWUdUUmhuI9V6TqAPOvujCSMGv1XQdg0a21IWCmO-U,590 -cryptography/hazmat/primitives/kdf/x963kdf.py,sha256=QKjhRehuTsAstL384bKfvjuv1yfdamAHVhsBRWen2Vw,456 -cryptography/hazmat/primitives/keywrap.py,sha256=UI-0UESQxBXTKU1HrrRoUwDiFsrWif81qyXlV1e7kyY,5776 -cryptography/hazmat/primitives/padding.py,sha256=QT-U-NvV2eQGO1wVPbDiNGNSc9keRDS-ig5cQOrLz0E,1865 -cryptography/hazmat/primitives/poly1305.py,sha256=P5EPQV-RB_FJPahpg01u0Ts4S_PnAmsroxIGXbGeRRo,355 -cryptography/hazmat/primitives/serialization/__init__.py,sha256=Q7uTgDlt7n3WfsMT6jYwutC6DIg_7SEeoAm1GHZ5B5E,1705 -cryptography/hazmat/primitives/serialization/__pycache__/__init__.cpython-312.pyc,, -cryptography/hazmat/primitives/serialization/__pycache__/base.cpython-312.pyc,, -cryptography/hazmat/primitives/serialization/__pycache__/pkcs12.cpython-312.pyc,, -cryptography/hazmat/primitives/serialization/__pycache__/pkcs7.cpython-312.pyc,, -cryptography/hazmat/primitives/serialization/__pycache__/ssh.cpython-312.pyc,, -cryptography/hazmat/primitives/serialization/base.py,sha256=ikq5MJIwp_oUnjiaBco_PmQwOTYuGi-XkYUYHKy8Vo0,615 -cryptography/hazmat/primitives/serialization/pkcs12.py,sha256=mS9cFNG4afzvseoc5e1MWoY2VskfL8N8Y_OFjl67luY,5104 -cryptography/hazmat/primitives/serialization/pkcs7.py,sha256=mFM7OFuZ8cCxUGUoo4Cof6BnCHc_Ibx1AQjjfxnPlxo,13998 -cryptography/hazmat/primitives/serialization/ssh.py,sha256=HV6ZqIjqNNaNUL6M4gQyNJJtZ75EsiSZs6yxddqBrWI,53789 -cryptography/hazmat/primitives/twofactor/__init__.py,sha256=tmMZGB-g4IU1r7lIFqASU019zr0uPp_wEBYcwdDCKCA,258 -cryptography/hazmat/primitives/twofactor/__pycache__/__init__.cpython-312.pyc,, -cryptography/hazmat/primitives/twofactor/__pycache__/hotp.cpython-312.pyc,, -cryptography/hazmat/primitives/twofactor/__pycache__/totp.cpython-312.pyc,, -cryptography/hazmat/primitives/twofactor/hotp.py,sha256=ivZo5BrcCGWLsqql4nZV0XXCjyGPi_iHfDFltGlOJwk,3256 -cryptography/hazmat/primitives/twofactor/totp.py,sha256=m5LPpRL00kp4zY8gTjr55Hfz9aMlPS53kHmVkSQCmdY,1652 -cryptography/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0 -cryptography/utils.py,sha256=wCnykfmWmp6L5zUFou715snYL9_YLLHjpj4_NHmlhwU,4281 -cryptography/x509/__init__.py,sha256=zciyadRgnCp2DNPPm6ujEKd6EX-8_zOnwtCjJbZBatg,8273 -cryptography/x509/__pycache__/__init__.cpython-312.pyc,, -cryptography/x509/__pycache__/base.cpython-312.pyc,, -cryptography/x509/__pycache__/certificate_transparency.cpython-312.pyc,, -cryptography/x509/__pycache__/extensions.cpython-312.pyc,, -cryptography/x509/__pycache__/general_name.cpython-312.pyc,, -cryptography/x509/__pycache__/name.cpython-312.pyc,, -cryptography/x509/__pycache__/ocsp.cpython-312.pyc,, -cryptography/x509/__pycache__/oid.cpython-312.pyc,, -cryptography/x509/__pycache__/verification.cpython-312.pyc,, -cryptography/x509/base.py,sha256=8322G4opJ1a2juXU14Qi2y-G1V-cQHaudo7gAFbTPlM,25998 -cryptography/x509/certificate_transparency.py,sha256=JqoOIDhlwInrYMFW6IFn77WJ0viF-PB_rlZV3vs9MYc,797 -cryptography/x509/extensions.py,sha256=0AUgutLe26SLg1KaxSeo0fG7fUBAyK2tEgJl9c_AQRM,77968 -cryptography/x509/general_name.py,sha256=sP_rV11Qlpsk4x3XXGJY_Mv0Q_s9dtjeLckHsjpLQoQ,7836 -cryptography/x509/name.py,sha256=H0Bix4uAxk5Ndkmee3Lxv3UdXbdph2XBr-nTPxHo54U,15356 -cryptography/x509/ocsp.py,sha256=Yey6NdFV1MPjop24Mj_VenjEpg3kUaMopSWOK0AbeBs,12699 -cryptography/x509/oid.py,sha256=BUzgXXGVWilkBkdKPTm9R4qElE9gAGHgdYPMZAp7PJo,931 -cryptography/x509/verification.py,sha256=gR2C2c-XZQtblZhT5T5vjSKOtCb74ef2alPVmEcwFlM,958 diff --git a/.venv/lib/python3.12/site-packages/cryptography-48.0.0.dist-info/REQUESTED b/.venv/lib/python3.12/site-packages/cryptography-48.0.0.dist-info/REQUESTED deleted file mode 100644 index e69de29..0000000 diff --git a/.venv/lib/python3.12/site-packages/cryptography-48.0.0.dist-info/WHEEL b/.venv/lib/python3.12/site-packages/cryptography-48.0.0.dist-info/WHEEL deleted file mode 100644 index 4e7840d..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography-48.0.0.dist-info/WHEEL +++ /dev/null @@ -1,5 +0,0 @@ -Wheel-Version: 1.0 -Generator: maturin (1.13.1) -Root-Is-Purelib: false -Tag: cp311-abi3-manylinux_2_34_x86_64 - diff --git a/.venv/lib/python3.12/site-packages/cryptography-48.0.0.dist-info/licenses/LICENSE b/.venv/lib/python3.12/site-packages/cryptography-48.0.0.dist-info/licenses/LICENSE deleted file mode 100644 index b11f379..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography-48.0.0.dist-info/licenses/LICENSE +++ /dev/null @@ -1,3 +0,0 @@ -This software is made available under the terms of *either* of the licenses -found in LICENSE.APACHE or LICENSE.BSD. Contributions to cryptography are made -under the terms of *both* these licenses. diff --git a/.venv/lib/python3.12/site-packages/cryptography-48.0.0.dist-info/licenses/LICENSE.APACHE b/.venv/lib/python3.12/site-packages/cryptography-48.0.0.dist-info/licenses/LICENSE.APACHE deleted file mode 100644 index 62589ed..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography-48.0.0.dist-info/licenses/LICENSE.APACHE +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - https://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - https://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/.venv/lib/python3.12/site-packages/cryptography-48.0.0.dist-info/licenses/LICENSE.BSD b/.venv/lib/python3.12/site-packages/cryptography-48.0.0.dist-info/licenses/LICENSE.BSD deleted file mode 100644 index ec1a29d..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography-48.0.0.dist-info/licenses/LICENSE.BSD +++ /dev/null @@ -1,27 +0,0 @@ -Copyright (c) Individual contributors. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - 3. Neither the name of PyCA Cryptography nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/.venv/lib/python3.12/site-packages/cryptography-48.0.0.dist-info/sboms/cryptography-rust.cyclonedx.json b/.venv/lib/python3.12/site-packages/cryptography-48.0.0.dist-info/sboms/cryptography-rust.cyclonedx.json deleted file mode 100644 index 0e28622..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography-48.0.0.dist-info/sboms/cryptography-rust.cyclonedx.json +++ /dev/null @@ -1,1362 +0,0 @@ -{ - "bomFormat": "CycloneDX", - "specVersion": "1.5", - "version": 1, - "serialNumber": "urn:uuid:b0f888ff-baac-404b-ad7b-a394cb3cc7f7", - "metadata": { - "timestamp": "2026-05-04T22:46:52.633241040Z", - "tools": [ - { - "vendor": "CycloneDX", - "name": "cargo-cyclonedx", - "version": "0.5.9" - } - ], - "authors": [ - { - "name": "The cryptography developers", - "email": "cryptography-dev@python.org" - } - ], - "component": { - "type": "library", - "bom-ref": "path+file:///__w/cryptography/cryptography/tmpwheelhouse/.tmpXdQ78X/cryptography-48.0.0/src/rust#cryptography-rust@0.1.0", - "author": "The cryptography developers ", - "name": "cryptography-rust", - "version": "0.1.0", - "scope": "required", - "licenses": [ - { - "expression": "Apache-2.0 OR BSD-3-Clause" - } - ], - "purl": "pkg:cargo/cryptography-rust@0.1.0?download_url=file://.", - "components": [ - { - "type": "library", - "bom-ref": "path+file:///__w/cryptography/cryptography/tmpwheelhouse/.tmpXdQ78X/cryptography-48.0.0/src/rust#cryptography-rust@0.1.0 bin-target-0", - "name": "cryptography_rust", - "version": "0.1.0", - "purl": "pkg:cargo/cryptography-rust@0.1.0?download_url=file://.#src/lib.rs" - } - ] - }, - "properties": [ - { - "name": "cdx:rustc:sbom:target:all_targets", - "value": "true" - } - ] - }, - "components": [ - { - "type": "library", - "bom-ref": "path+file:///__w/cryptography/cryptography/tmpwheelhouse/.tmpXdQ78X/cryptography-48.0.0/src/rust/cryptography-cffi#0.1.0", - "author": "The cryptography developers ", - "name": "cryptography-cffi", - "version": "0.1.0", - "scope": "required", - "licenses": [ - { - "expression": "Apache-2.0 OR BSD-3-Clause" - } - ], - "purl": "pkg:cargo/cryptography-cffi@0.1.0?download_url=file://cryptography-cffi" - }, - { - "type": "library", - "bom-ref": "path+file:///__w/cryptography/cryptography/tmpwheelhouse/.tmpXdQ78X/cryptography-48.0.0/src/rust/cryptography-crypto#0.1.0", - "author": "The cryptography developers ", - "name": "cryptography-crypto", - "version": "0.1.0", - "scope": "required", - "licenses": [ - { - "expression": "Apache-2.0 OR BSD-3-Clause" - } - ], - "purl": "pkg:cargo/cryptography-crypto@0.1.0?download_url=file://cryptography-crypto" - }, - { - "type": "library", - "bom-ref": "path+file:///__w/cryptography/cryptography/tmpwheelhouse/.tmpXdQ78X/cryptography-48.0.0/src/rust/cryptography-keepalive#0.1.0", - "author": "The cryptography developers ", - "name": "cryptography-keepalive", - "version": "0.1.0", - "scope": "required", - "licenses": [ - { - "expression": "Apache-2.0 OR BSD-3-Clause" - } - ], - "purl": "pkg:cargo/cryptography-keepalive@0.1.0?download_url=file://cryptography-keepalive" - }, - { - "type": "library", - "bom-ref": "path+file:///__w/cryptography/cryptography/tmpwheelhouse/.tmpXdQ78X/cryptography-48.0.0/src/rust/cryptography-key-parsing#0.1.0", - "author": "The cryptography developers ", - "name": "cryptography-key-parsing", - "version": "0.1.0", - "scope": "required", - "licenses": [ - { - "expression": "Apache-2.0 OR BSD-3-Clause" - } - ], - "purl": "pkg:cargo/cryptography-key-parsing@0.1.0?download_url=file://cryptography-key-parsing" - }, - { - "type": "library", - "bom-ref": "path+file:///__w/cryptography/cryptography/tmpwheelhouse/.tmpXdQ78X/cryptography-48.0.0/src/rust/cryptography-openssl#0.1.0", - "author": "The cryptography developers ", - "name": "cryptography-openssl", - "version": "0.1.0", - "scope": "required", - "licenses": [ - { - "expression": "Apache-2.0 OR BSD-3-Clause" - } - ], - "purl": "pkg:cargo/cryptography-openssl@0.1.0?download_url=file://cryptography-openssl" - }, - { - "type": "library", - "bom-ref": "path+file:///__w/cryptography/cryptography/tmpwheelhouse/.tmpXdQ78X/cryptography-48.0.0/src/rust/cryptography-x509#0.1.0", - "author": "The cryptography developers ", - "name": "cryptography-x509", - "version": "0.1.0", - "scope": "required", - "licenses": [ - { - "expression": "Apache-2.0 OR BSD-3-Clause" - } - ], - "purl": "pkg:cargo/cryptography-x509@0.1.0?download_url=file://cryptography-x509" - }, - { - "type": "library", - "bom-ref": "path+file:///__w/cryptography/cryptography/tmpwheelhouse/.tmpXdQ78X/cryptography-48.0.0/src/rust/cryptography-x509-verification#0.1.0", - "author": "The cryptography developers ", - "name": "cryptography-x509-verification", - "version": "0.1.0", - "scope": "required", - "licenses": [ - { - "expression": "Apache-2.0 OR BSD-3-Clause" - } - ], - "purl": "pkg:cargo/cryptography-x509-verification@0.1.0?download_url=file://cryptography-x509-verification" - }, - { - "type": "library", - "bom-ref": "registry+https://github.com/rust-lang/crates.io-index#asn1@0.24.1", - "author": "Alex Gaynor ", - "name": "asn1", - "version": "0.24.1", - "description": "ASN.1 (DER) parser and writer for Rust.", - "scope": "required", - "hashes": [ - { - "alg": "SHA-256", - "content": "c9795210620c0cb3f9a7ce4f882808c38e1ef7b347c90591dceae0886e031fb1" - } - ], - "licenses": [ - { - "expression": "BSD-3-Clause" - } - ], - "purl": "pkg:cargo/asn1@0.24.1", - "externalReferences": [ - { - "type": "vcs", - "url": "https://github.com/alex/rust-asn1" - } - ] - }, - { - "type": "library", - "bom-ref": "registry+https://github.com/rust-lang/crates.io-index#asn1_derive@0.24.1", - "author": "Alex Gaynor ", - "name": "asn1_derive", - "version": "0.24.1", - "description": "#[derive] support for asn1", - "scope": "required", - "hashes": [ - { - "alg": "SHA-256", - "content": "909e307f1cc32bb8bccbd98f446e6d1bf03fa30f7b53a4337da7181ad30fa11a" - } - ], - "licenses": [ - { - "expression": "BSD-3-Clause" - } - ], - "purl": "pkg:cargo/asn1_derive@0.24.1", - "externalReferences": [ - { - "type": "vcs", - "url": "https://github.com/alex/rust-asn1" - } - ] - }, - { - "type": "library", - "bom-ref": "registry+https://github.com/rust-lang/crates.io-index#base64@0.22.1", - "author": "Marshall Pierce ", - "name": "base64", - "version": "0.22.1", - "description": "encodes and decodes base64 as bytes or utf8", - "scope": "required", - "hashes": [ - { - "alg": "SHA-256", - "content": "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" - } - ], - "licenses": [ - { - "expression": "MIT OR Apache-2.0" - } - ], - "purl": "pkg:cargo/base64@0.22.1", - "externalReferences": [ - { - "type": "documentation", - "url": "https://docs.rs/base64" - }, - { - "type": "vcs", - "url": "https://github.com/marshallpierce/rust-base64" - } - ] - }, - { - "type": "library", - "bom-ref": "registry+https://github.com/rust-lang/crates.io-index#bitflags@2.11.1", - "author": "The Rust Project Developers", - "name": "bitflags", - "version": "2.11.1", - "description": "A macro to generate structures which behave like bitflags. ", - "scope": "required", - "hashes": [ - { - "alg": "SHA-256", - "content": "c4512299f36f043ab09a583e57bceb5a5aab7a73db1805848e8fef3c9e8c78b3" - } - ], - "licenses": [ - { - "expression": "MIT OR Apache-2.0" - } - ], - "purl": "pkg:cargo/bitflags@2.11.1", - "externalReferences": [ - { - "type": "documentation", - "url": "https://docs.rs/bitflags" - }, - { - "type": "website", - "url": "https://github.com/bitflags/bitflags" - }, - { - "type": "vcs", - "url": "https://github.com/bitflags/bitflags" - } - ] - }, - { - "type": "library", - "bom-ref": "registry+https://github.com/rust-lang/crates.io-index#cc@1.2.61", - "author": "Alex Crichton ", - "name": "cc", - "version": "1.2.61", - "description": "A build-time dependency for Cargo build scripts to assist in invoking the native C compiler to compile native C code into a static archive to be linked into Rust code. ", - "scope": "excluded", - "hashes": [ - { - "alg": "SHA-256", - "content": "d16d90359e986641506914ba71350897565610e87ce0ad9e6f28569db3dd5c6d" - } - ], - "licenses": [ - { - "expression": "MIT OR Apache-2.0" - } - ], - "purl": "pkg:cargo/cc@1.2.61", - "externalReferences": [ - { - "type": "documentation", - "url": "https://docs.rs/cc" - }, - { - "type": "website", - "url": "https://github.com/rust-lang/cc-rs" - }, - { - "type": "vcs", - "url": "https://github.com/rust-lang/cc-rs" - } - ] - }, - { - "type": "library", - "bom-ref": "registry+https://github.com/rust-lang/crates.io-index#cfg-if@1.0.4", - "author": "Alex Crichton ", - "name": "cfg-if", - "version": "1.0.4", - "description": "A macro to ergonomically define an item depending on a large number of #[cfg] parameters. Structured like an if-else chain, the first matching branch is the item that gets emitted. ", - "scope": "required", - "hashes": [ - { - "alg": "SHA-256", - "content": "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" - } - ], - "licenses": [ - { - "expression": "MIT OR Apache-2.0" - } - ], - "purl": "pkg:cargo/cfg-if@1.0.4", - "externalReferences": [ - { - "type": "vcs", - "url": "https://github.com/rust-lang/cfg-if" - } - ] - }, - { - "type": "library", - "bom-ref": "registry+https://github.com/rust-lang/crates.io-index#find-msvc-tools@0.1.9", - "name": "find-msvc-tools", - "version": "0.1.9", - "description": "Find windows-specific tools, read MSVC versions from the registry and from COM interfaces", - "scope": "excluded", - "hashes": [ - { - "alg": "SHA-256", - "content": "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" - } - ], - "licenses": [ - { - "expression": "MIT OR Apache-2.0" - } - ], - "purl": "pkg:cargo/find-msvc-tools@0.1.9", - "externalReferences": [ - { - "type": "documentation", - "url": "https://docs.rs/find-msvc-tools" - }, - { - "type": "vcs", - "url": "https://github.com/rust-lang/cc-rs" - } - ] - }, - { - "type": "library", - "bom-ref": "registry+https://github.com/rust-lang/crates.io-index#foreign-types-shared@0.1.1", - "author": "Steven Fackler ", - "name": "foreign-types-shared", - "version": "0.1.1", - "description": "An internal crate used by foreign-types", - "scope": "required", - "hashes": [ - { - "alg": "SHA-256", - "content": "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - } - ], - "licenses": [ - { - "expression": "MIT OR Apache-2.0" - } - ], - "purl": "pkg:cargo/foreign-types-shared@0.1.1", - "externalReferences": [ - { - "type": "vcs", - "url": "https://github.com/sfackler/foreign-types" - } - ] - }, - { - "type": "library", - "bom-ref": "registry+https://github.com/rust-lang/crates.io-index#foreign-types@0.3.2", - "author": "Steven Fackler ", - "name": "foreign-types", - "version": "0.3.2", - "description": "A framework for Rust wrappers over C APIs", - "scope": "required", - "hashes": [ - { - "alg": "SHA-256", - "content": "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" - } - ], - "licenses": [ - { - "expression": "MIT OR Apache-2.0" - } - ], - "purl": "pkg:cargo/foreign-types@0.3.2", - "externalReferences": [ - { - "type": "vcs", - "url": "https://github.com/sfackler/foreign-types" - } - ] - }, - { - "type": "library", - "bom-ref": "registry+https://github.com/rust-lang/crates.io-index#heck@0.5.0", - "name": "heck", - "version": "0.5.0", - "description": "heck is a case conversion library.", - "scope": "required", - "hashes": [ - { - "alg": "SHA-256", - "content": "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" - } - ], - "licenses": [ - { - "expression": "MIT OR Apache-2.0" - } - ], - "purl": "pkg:cargo/heck@0.5.0", - "externalReferences": [ - { - "type": "vcs", - "url": "https://github.com/withoutboats/heck" - } - ] - }, - { - "type": "library", - "bom-ref": "registry+https://github.com/rust-lang/crates.io-index#itoa@1.0.18", - "author": "David Tolnay ", - "name": "itoa", - "version": "1.0.18", - "description": "Fast integer primitive to string conversion", - "scope": "required", - "hashes": [ - { - "alg": "SHA-256", - "content": "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" - } - ], - "licenses": [ - { - "expression": "MIT OR Apache-2.0" - } - ], - "purl": "pkg:cargo/itoa@1.0.18", - "externalReferences": [ - { - "type": "documentation", - "url": "https://docs.rs/itoa" - }, - { - "type": "vcs", - "url": "https://github.com/dtolnay/itoa" - } - ] - }, - { - "type": "library", - "bom-ref": "registry+https://github.com/rust-lang/crates.io-index#libc@0.2.186", - "author": "The Rust Project Developers", - "name": "libc", - "version": "0.2.186", - "description": "Raw FFI bindings to platform libraries like libc.", - "scope": "required", - "hashes": [ - { - "alg": "SHA-256", - "content": "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66" - } - ], - "licenses": [ - { - "expression": "MIT OR Apache-2.0" - } - ], - "purl": "pkg:cargo/libc@0.2.186", - "externalReferences": [ - { - "type": "vcs", - "url": "https://github.com/rust-lang/libc" - } - ] - }, - { - "type": "library", - "bom-ref": "registry+https://github.com/rust-lang/crates.io-index#once_cell@1.21.4", - "author": "Aleksey Kladov ", - "name": "once_cell", - "version": "1.21.4", - "description": "Single assignment cells and lazy values.", - "scope": "required", - "hashes": [ - { - "alg": "SHA-256", - "content": "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" - } - ], - "licenses": [ - { - "expression": "MIT OR Apache-2.0" - } - ], - "purl": "pkg:cargo/once_cell@1.21.4", - "externalReferences": [ - { - "type": "documentation", - "url": "https://docs.rs/once_cell" - }, - { - "type": "vcs", - "url": "https://github.com/matklad/once_cell" - } - ] - }, - { - "type": "library", - "bom-ref": "registry+https://github.com/rust-lang/crates.io-index#openssl-macros@0.1.1", - "name": "openssl-macros", - "version": "0.1.1", - "description": "Internal macros used by the openssl crate.", - "scope": "required", - "hashes": [ - { - "alg": "SHA-256", - "content": "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" - } - ], - "licenses": [ - { - "expression": "MIT OR Apache-2.0" - } - ], - "purl": "pkg:cargo/openssl-macros@0.1.1" - }, - { - "type": "library", - "bom-ref": "registry+https://github.com/rust-lang/crates.io-index#openssl-sys@0.9.115", - "author": "Alex Crichton , Steven Fackler ", - "name": "openssl-sys", - "version": "0.9.115", - "description": "FFI bindings to OpenSSL", - "scope": "required", - "hashes": [ - { - "alg": "SHA-256", - "content": "158fe5b292746440aa6e7a7e690e55aeb72d41505e2804c23c6973ad0e9c9781" - } - ], - "licenses": [ - { - "expression": "MIT" - } - ], - "purl": "pkg:cargo/openssl-sys@0.9.115", - "externalReferences": [ - { - "type": "other", - "url": "openssl" - }, - { - "type": "vcs", - "url": "https://github.com/rust-openssl/rust-openssl" - } - ] - }, - { - "type": "library", - "bom-ref": "registry+https://github.com/rust-lang/crates.io-index#openssl@0.10.79", - "author": "Steven Fackler ", - "name": "openssl", - "version": "0.10.79", - "description": "OpenSSL bindings", - "scope": "required", - "hashes": [ - { - "alg": "SHA-256", - "content": "bf0b434746ee2832f4f0baf10137e1cabb18cbe6912c69e2e33263c45250f542" - } - ], - "licenses": [ - { - "expression": "Apache-2.0" - } - ], - "purl": "pkg:cargo/openssl@0.10.79", - "externalReferences": [ - { - "type": "vcs", - "url": "https://github.com/rust-openssl/rust-openssl" - } - ] - }, - { - "type": "library", - "bom-ref": "registry+https://github.com/rust-lang/crates.io-index#pem@3.0.6", - "author": "Jonathan Creekmore ", - "name": "pem", - "version": "3.0.6", - "description": "Parse and encode PEM-encoded data.", - "scope": "required", - "hashes": [ - { - "alg": "SHA-256", - "content": "1d30c53c26bc5b31a98cd02d20f25a7c8567146caf63ed593a9d87b2775291be" - } - ], - "licenses": [ - { - "expression": "MIT" - } - ], - "purl": "pkg:cargo/pem@3.0.6", - "externalReferences": [ - { - "type": "documentation", - "url": "https://docs.rs/pem/" - }, - { - "type": "website", - "url": "https://github.com/jcreekmore/pem-rs.git" - }, - { - "type": "vcs", - "url": "https://github.com/jcreekmore/pem-rs.git" - } - ] - }, - { - "type": "library", - "bom-ref": "registry+https://github.com/rust-lang/crates.io-index#pkg-config@0.3.33", - "author": "Alex Crichton ", - "name": "pkg-config", - "version": "0.3.33", - "description": "A library to run the pkg-config system tool at build time in order to be used in Cargo build scripts. ", - "scope": "excluded", - "hashes": [ - { - "alg": "SHA-256", - "content": "19f132c84eca552bf34cab8ec81f1c1dcc229b811638f9d283dceabe58c5569e" - } - ], - "licenses": [ - { - "expression": "MIT OR Apache-2.0" - } - ], - "purl": "pkg:cargo/pkg-config@0.3.33", - "externalReferences": [ - { - "type": "documentation", - "url": "https://docs.rs/pkg-config" - }, - { - "type": "vcs", - "url": "https://github.com/rust-lang/pkg-config-rs" - } - ] - }, - { - "type": "library", - "bom-ref": "registry+https://github.com/rust-lang/crates.io-index#portable-atomic@1.13.1", - "name": "portable-atomic", - "version": "1.13.1", - "description": "Portable atomic types including support for 128-bit atomics, atomic float, etc. ", - "scope": "required", - "hashes": [ - { - "alg": "SHA-256", - "content": "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49" - } - ], - "licenses": [ - { - "expression": "Apache-2.0 OR MIT" - } - ], - "purl": "pkg:cargo/portable-atomic@1.13.1", - "externalReferences": [ - { - "type": "vcs", - "url": "https://github.com/taiki-e/portable-atomic" - } - ] - }, - { - "type": "library", - "bom-ref": "registry+https://github.com/rust-lang/crates.io-index#proc-macro2@1.0.106", - "author": "David Tolnay , Alex Crichton ", - "name": "proc-macro2", - "version": "1.0.106", - "description": "A substitute implementation of the compiler's `proc_macro` API to decouple token-based libraries from the procedural macro use case.", - "scope": "required", - "hashes": [ - { - "alg": "SHA-256", - "content": "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" - } - ], - "licenses": [ - { - "expression": "MIT OR Apache-2.0" - } - ], - "purl": "pkg:cargo/proc-macro2@1.0.106", - "externalReferences": [ - { - "type": "documentation", - "url": "https://docs.rs/proc-macro2" - }, - { - "type": "vcs", - "url": "https://github.com/dtolnay/proc-macro2" - } - ] - }, - { - "type": "library", - "bom-ref": "registry+https://github.com/rust-lang/crates.io-index#pyo3-build-config@0.28.3", - "author": "PyO3 Project and Contributors ", - "name": "pyo3-build-config", - "version": "0.28.3", - "description": "Build configuration for the PyO3 ecosystem", - "scope": "required", - "hashes": [ - { - "alg": "SHA-256", - "content": "e368e7ddfdeb98c9bca7f8383be1648fd84ab466bf2bc015e94008db6d35611e" - } - ], - "licenses": [ - { - "expression": "MIT OR Apache-2.0" - } - ], - "purl": "pkg:cargo/pyo3-build-config@0.28.3", - "externalReferences": [ - { - "type": "website", - "url": "https://github.com/pyo3/pyo3" - }, - { - "type": "vcs", - "url": "https://github.com/pyo3/pyo3" - } - ] - }, - { - "type": "library", - "bom-ref": "registry+https://github.com/rust-lang/crates.io-index#pyo3-ffi@0.28.3", - "author": "PyO3 Project and Contributors ", - "name": "pyo3-ffi", - "version": "0.28.3", - "description": "Python-API bindings for the PyO3 ecosystem", - "scope": "required", - "hashes": [ - { - "alg": "SHA-256", - "content": "7f29e10af80b1f7ccaf7f69eace800a03ecd13e883acfacc1e5d0988605f651e" - } - ], - "licenses": [ - { - "expression": "MIT OR Apache-2.0" - } - ], - "purl": "pkg:cargo/pyo3-ffi@0.28.3", - "externalReferences": [ - { - "type": "website", - "url": "https://github.com/pyo3/pyo3" - }, - { - "type": "other", - "url": "python" - }, - { - "type": "vcs", - "url": "https://github.com/pyo3/pyo3" - } - ] - }, - { - "type": "library", - "bom-ref": "registry+https://github.com/rust-lang/crates.io-index#pyo3-macros-backend@0.28.3", - "author": "PyO3 Project and Contributors ", - "name": "pyo3-macros-backend", - "version": "0.28.3", - "description": "Code generation for PyO3 package", - "scope": "required", - "hashes": [ - { - "alg": "SHA-256", - "content": "c4cdc218d835738f81c2338f822078af45b4afdf8b2e33cbb5916f108b813acb" - } - ], - "licenses": [ - { - "expression": "MIT OR Apache-2.0" - } - ], - "purl": "pkg:cargo/pyo3-macros-backend@0.28.3", - "externalReferences": [ - { - "type": "website", - "url": "https://github.com/pyo3/pyo3" - }, - { - "type": "vcs", - "url": "https://github.com/pyo3/pyo3" - } - ] - }, - { - "type": "library", - "bom-ref": "registry+https://github.com/rust-lang/crates.io-index#pyo3-macros@0.28.3", - "author": "PyO3 Project and Contributors ", - "name": "pyo3-macros", - "version": "0.28.3", - "description": "Proc macros for PyO3 package", - "scope": "required", - "hashes": [ - { - "alg": "SHA-256", - "content": "df6e520eff47c45997d2fc7dd8214b25dd1310918bbb2642156ef66a67f29813" - } - ], - "licenses": [ - { - "expression": "MIT OR Apache-2.0" - } - ], - "purl": "pkg:cargo/pyo3-macros@0.28.3", - "externalReferences": [ - { - "type": "website", - "url": "https://github.com/pyo3/pyo3" - }, - { - "type": "vcs", - "url": "https://github.com/pyo3/pyo3" - } - ] - }, - { - "type": "library", - "bom-ref": "registry+https://github.com/rust-lang/crates.io-index#pyo3@0.28.3", - "author": "PyO3 Project and Contributors ", - "name": "pyo3", - "version": "0.28.3", - "description": "Bindings to Python interpreter", - "scope": "required", - "hashes": [ - { - "alg": "SHA-256", - "content": "91fd8e38a3b50ed1167fb981cd6fd60147e091784c427b8f7183a7ee32c31c12" - } - ], - "licenses": [ - { - "expression": "MIT OR Apache-2.0" - } - ], - "purl": "pkg:cargo/pyo3@0.28.3", - "externalReferences": [ - { - "type": "documentation", - "url": "https://docs.rs/crate/pyo3/" - }, - { - "type": "website", - "url": "https://github.com/pyo3/pyo3" - }, - { - "type": "vcs", - "url": "https://github.com/pyo3/pyo3" - } - ] - }, - { - "type": "library", - "bom-ref": "registry+https://github.com/rust-lang/crates.io-index#quote@1.0.45", - "author": "David Tolnay ", - "name": "quote", - "version": "1.0.45", - "description": "Quasi-quoting macro quote!(...)", - "scope": "required", - "hashes": [ - { - "alg": "SHA-256", - "content": "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" - } - ], - "licenses": [ - { - "expression": "MIT OR Apache-2.0" - } - ], - "purl": "pkg:cargo/quote@1.0.45", - "externalReferences": [ - { - "type": "documentation", - "url": "https://docs.rs/quote/" - }, - { - "type": "vcs", - "url": "https://github.com/dtolnay/quote" - } - ] - }, - { - "type": "library", - "bom-ref": "registry+https://github.com/rust-lang/crates.io-index#self_cell@1.2.2", - "author": "Lukas Bergdoll ", - "name": "self_cell", - "version": "1.2.2", - "description": "Safe-to-use proc-macro-free self-referential structs in stable Rust.", - "scope": "required", - "hashes": [ - { - "alg": "SHA-256", - "content": "b12e76d157a900eb52e81bc6e9f3069344290341720e9178cde2407113ac8d89" - } - ], - "licenses": [ - { - "expression": "Apache-2.0 OR GPL-2.0-only" - } - ], - "purl": "pkg:cargo/self_cell@1.2.2", - "externalReferences": [ - { - "type": "documentation", - "url": "https://docs.rs/self_cell" - }, - { - "type": "vcs", - "url": "https://github.com/Voultapher/self_cell" - } - ] - }, - { - "type": "library", - "bom-ref": "registry+https://github.com/rust-lang/crates.io-index#shlex@1.3.0", - "author": "comex , Fenhl , Adrian Taylor , Alex Touchet , Daniel Parks , Garrett Berg ", - "name": "shlex", - "version": "1.3.0", - "description": "Split a string into shell words, like Python's shlex.", - "scope": "excluded", - "hashes": [ - { - "alg": "SHA-256", - "content": "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" - } - ], - "licenses": [ - { - "expression": "MIT OR Apache-2.0" - } - ], - "purl": "pkg:cargo/shlex@1.3.0", - "externalReferences": [ - { - "type": "vcs", - "url": "https://github.com/comex/rust-shlex" - } - ] - }, - { - "type": "library", - "bom-ref": "registry+https://github.com/rust-lang/crates.io-index#syn@2.0.117", - "author": "David Tolnay ", - "name": "syn", - "version": "2.0.117", - "description": "Parser for Rust source code", - "scope": "required", - "hashes": [ - { - "alg": "SHA-256", - "content": "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" - } - ], - "licenses": [ - { - "expression": "MIT OR Apache-2.0" - } - ], - "purl": "pkg:cargo/syn@2.0.117", - "externalReferences": [ - { - "type": "documentation", - "url": "https://docs.rs/syn" - }, - { - "type": "vcs", - "url": "https://github.com/dtolnay/syn" - } - ] - }, - { - "type": "library", - "bom-ref": "registry+https://github.com/rust-lang/crates.io-index#target-lexicon@0.13.5", - "author": "Dan Gohman ", - "name": "target-lexicon", - "version": "0.13.5", - "description": "LLVM target triple types", - "scope": "required", - "hashes": [ - { - "alg": "SHA-256", - "content": "adb6935a6f5c20170eeceb1a3835a49e12e19d792f6dd344ccc76a985ca5a6ca" - } - ], - "licenses": [ - { - "expression": "Apache-2.0 WITH LLVM-exception" - } - ], - "purl": "pkg:cargo/target-lexicon@0.13.5", - "externalReferences": [ - { - "type": "documentation", - "url": "https://docs.rs/target-lexicon/" - }, - { - "type": "vcs", - "url": "https://github.com/bytecodealliance/target-lexicon" - } - ] - }, - { - "type": "library", - "bom-ref": "registry+https://github.com/rust-lang/crates.io-index#unicode-ident@1.0.24", - "author": "David Tolnay ", - "name": "unicode-ident", - "version": "1.0.24", - "description": "Determine whether characters have the XID_Start or XID_Continue properties according to Unicode Standard Annex #31", - "scope": "required", - "hashes": [ - { - "alg": "SHA-256", - "content": "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" - } - ], - "licenses": [ - { - "expression": "(MIT OR Apache-2.0) AND Unicode-3.0" - } - ], - "purl": "pkg:cargo/unicode-ident@1.0.24", - "externalReferences": [ - { - "type": "documentation", - "url": "https://docs.rs/unicode-ident" - }, - { - "type": "vcs", - "url": "https://github.com/dtolnay/unicode-ident" - } - ] - }, - { - "type": "library", - "bom-ref": "registry+https://github.com/rust-lang/crates.io-index#vcpkg@0.2.15", - "author": "Jim McGrath ", - "name": "vcpkg", - "version": "0.2.15", - "description": "A library to find native dependencies in a vcpkg tree at build time in order to be used in Cargo build scripts. ", - "scope": "excluded", - "hashes": [ - { - "alg": "SHA-256", - "content": "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - } - ], - "licenses": [ - { - "expression": "MIT OR Apache-2.0" - } - ], - "purl": "pkg:cargo/vcpkg@0.2.15", - "externalReferences": [ - { - "type": "documentation", - "url": "https://docs.rs/vcpkg" - }, - { - "type": "vcs", - "url": "https://github.com/mcgoo/vcpkg-rs" - } - ] - } - ], - "dependencies": [ - { - "ref": "path+file:///__w/cryptography/cryptography/tmpwheelhouse/.tmpXdQ78X/cryptography-48.0.0/src/rust#cryptography-rust@0.1.0", - "dependsOn": [ - "registry+https://github.com/rust-lang/crates.io-index#asn1@0.24.1", - "registry+https://github.com/rust-lang/crates.io-index#base64@0.22.1", - "registry+https://github.com/rust-lang/crates.io-index#cfg-if@1.0.4", - "path+file:///__w/cryptography/cryptography/tmpwheelhouse/.tmpXdQ78X/cryptography-48.0.0/src/rust/cryptography-cffi#0.1.0", - "path+file:///__w/cryptography/cryptography/tmpwheelhouse/.tmpXdQ78X/cryptography-48.0.0/src/rust/cryptography-crypto#0.1.0", - "path+file:///__w/cryptography/cryptography/tmpwheelhouse/.tmpXdQ78X/cryptography-48.0.0/src/rust/cryptography-keepalive#0.1.0", - "path+file:///__w/cryptography/cryptography/tmpwheelhouse/.tmpXdQ78X/cryptography-48.0.0/src/rust/cryptography-key-parsing#0.1.0", - "path+file:///__w/cryptography/cryptography/tmpwheelhouse/.tmpXdQ78X/cryptography-48.0.0/src/rust/cryptography-openssl#0.1.0", - "path+file:///__w/cryptography/cryptography/tmpwheelhouse/.tmpXdQ78X/cryptography-48.0.0/src/rust/cryptography-x509#0.1.0", - "path+file:///__w/cryptography/cryptography/tmpwheelhouse/.tmpXdQ78X/cryptography-48.0.0/src/rust/cryptography-x509-verification#0.1.0", - "registry+https://github.com/rust-lang/crates.io-index#foreign-types-shared@0.1.1", - "registry+https://github.com/rust-lang/crates.io-index#openssl@0.10.79", - "registry+https://github.com/rust-lang/crates.io-index#openssl-sys@0.9.115", - "registry+https://github.com/rust-lang/crates.io-index#pem@3.0.6", - "registry+https://github.com/rust-lang/crates.io-index#pyo3@0.28.3", - "registry+https://github.com/rust-lang/crates.io-index#pyo3-build-config@0.28.3", - "registry+https://github.com/rust-lang/crates.io-index#self_cell@1.2.2" - ] - }, - { - "ref": "path+file:///__w/cryptography/cryptography/tmpwheelhouse/.tmpXdQ78X/cryptography-48.0.0/src/rust/cryptography-cffi#0.1.0", - "dependsOn": [ - "registry+https://github.com/rust-lang/crates.io-index#cc@1.2.61", - "registry+https://github.com/rust-lang/crates.io-index#openssl-sys@0.9.115", - "registry+https://github.com/rust-lang/crates.io-index#pyo3@0.28.3" - ] - }, - { - "ref": "path+file:///__w/cryptography/cryptography/tmpwheelhouse/.tmpXdQ78X/cryptography-48.0.0/src/rust/cryptography-crypto#0.1.0", - "dependsOn": [ - "registry+https://github.com/rust-lang/crates.io-index#openssl@0.10.79" - ] - }, - { - "ref": "path+file:///__w/cryptography/cryptography/tmpwheelhouse/.tmpXdQ78X/cryptography-48.0.0/src/rust/cryptography-keepalive#0.1.0", - "dependsOn": [ - "registry+https://github.com/rust-lang/crates.io-index#pyo3@0.28.3" - ] - }, - { - "ref": "path+file:///__w/cryptography/cryptography/tmpwheelhouse/.tmpXdQ78X/cryptography-48.0.0/src/rust/cryptography-key-parsing#0.1.0", - "dependsOn": [ - "registry+https://github.com/rust-lang/crates.io-index#asn1@0.24.1", - "registry+https://github.com/rust-lang/crates.io-index#cfg-if@1.0.4", - "path+file:///__w/cryptography/cryptography/tmpwheelhouse/.tmpXdQ78X/cryptography-48.0.0/src/rust/cryptography-crypto#0.1.0", - "path+file:///__w/cryptography/cryptography/tmpwheelhouse/.tmpXdQ78X/cryptography-48.0.0/src/rust/cryptography-openssl#0.1.0", - "path+file:///__w/cryptography/cryptography/tmpwheelhouse/.tmpXdQ78X/cryptography-48.0.0/src/rust/cryptography-x509#0.1.0", - "registry+https://github.com/rust-lang/crates.io-index#openssl@0.10.79", - "registry+https://github.com/rust-lang/crates.io-index#openssl-sys@0.9.115", - "registry+https://github.com/rust-lang/crates.io-index#pem@3.0.6" - ] - }, - { - "ref": "path+file:///__w/cryptography/cryptography/tmpwheelhouse/.tmpXdQ78X/cryptography-48.0.0/src/rust/cryptography-openssl#0.1.0", - "dependsOn": [ - "registry+https://github.com/rust-lang/crates.io-index#cfg-if@1.0.4", - "registry+https://github.com/rust-lang/crates.io-index#foreign-types@0.3.2", - "registry+https://github.com/rust-lang/crates.io-index#foreign-types-shared@0.1.1", - "registry+https://github.com/rust-lang/crates.io-index#openssl@0.10.79", - "registry+https://github.com/rust-lang/crates.io-index#openssl-sys@0.9.115" - ] - }, - { - "ref": "path+file:///__w/cryptography/cryptography/tmpwheelhouse/.tmpXdQ78X/cryptography-48.0.0/src/rust/cryptography-x509#0.1.0", - "dependsOn": [ - "registry+https://github.com/rust-lang/crates.io-index#asn1@0.24.1" - ] - }, - { - "ref": "path+file:///__w/cryptography/cryptography/tmpwheelhouse/.tmpXdQ78X/cryptography-48.0.0/src/rust/cryptography-x509-verification#0.1.0", - "dependsOn": [ - "registry+https://github.com/rust-lang/crates.io-index#asn1@0.24.1", - "path+file:///__w/cryptography/cryptography/tmpwheelhouse/.tmpXdQ78X/cryptography-48.0.0/src/rust/cryptography-x509#0.1.0" - ] - }, - { - "ref": "registry+https://github.com/rust-lang/crates.io-index#asn1@0.24.1", - "dependsOn": [ - "registry+https://github.com/rust-lang/crates.io-index#asn1_derive@0.24.1", - "registry+https://github.com/rust-lang/crates.io-index#itoa@1.0.18" - ] - }, - { - "ref": "registry+https://github.com/rust-lang/crates.io-index#asn1_derive@0.24.1", - "dependsOn": [ - "registry+https://github.com/rust-lang/crates.io-index#proc-macro2@1.0.106", - "registry+https://github.com/rust-lang/crates.io-index#quote@1.0.45", - "registry+https://github.com/rust-lang/crates.io-index#syn@2.0.117" - ] - }, - { - "ref": "registry+https://github.com/rust-lang/crates.io-index#base64@0.22.1" - }, - { - "ref": "registry+https://github.com/rust-lang/crates.io-index#bitflags@2.11.1" - }, - { - "ref": "registry+https://github.com/rust-lang/crates.io-index#cc@1.2.61", - "dependsOn": [ - "registry+https://github.com/rust-lang/crates.io-index#find-msvc-tools@0.1.9", - "registry+https://github.com/rust-lang/crates.io-index#shlex@1.3.0" - ] - }, - { - "ref": "registry+https://github.com/rust-lang/crates.io-index#cfg-if@1.0.4" - }, - { - "ref": "registry+https://github.com/rust-lang/crates.io-index#find-msvc-tools@0.1.9" - }, - { - "ref": "registry+https://github.com/rust-lang/crates.io-index#foreign-types-shared@0.1.1" - }, - { - "ref": "registry+https://github.com/rust-lang/crates.io-index#foreign-types@0.3.2", - "dependsOn": [ - "registry+https://github.com/rust-lang/crates.io-index#foreign-types-shared@0.1.1" - ] - }, - { - "ref": "registry+https://github.com/rust-lang/crates.io-index#heck@0.5.0" - }, - { - "ref": "registry+https://github.com/rust-lang/crates.io-index#itoa@1.0.18" - }, - { - "ref": "registry+https://github.com/rust-lang/crates.io-index#libc@0.2.186" - }, - { - "ref": "registry+https://github.com/rust-lang/crates.io-index#once_cell@1.21.4" - }, - { - "ref": "registry+https://github.com/rust-lang/crates.io-index#openssl-macros@0.1.1", - "dependsOn": [ - "registry+https://github.com/rust-lang/crates.io-index#proc-macro2@1.0.106", - "registry+https://github.com/rust-lang/crates.io-index#quote@1.0.45", - "registry+https://github.com/rust-lang/crates.io-index#syn@2.0.117" - ] - }, - { - "ref": "registry+https://github.com/rust-lang/crates.io-index#openssl-sys@0.9.115", - "dependsOn": [ - "registry+https://github.com/rust-lang/crates.io-index#cc@1.2.61", - "registry+https://github.com/rust-lang/crates.io-index#libc@0.2.186", - "registry+https://github.com/rust-lang/crates.io-index#pkg-config@0.3.33", - "registry+https://github.com/rust-lang/crates.io-index#vcpkg@0.2.15" - ] - }, - { - "ref": "registry+https://github.com/rust-lang/crates.io-index#openssl@0.10.79", - "dependsOn": [ - "registry+https://github.com/rust-lang/crates.io-index#bitflags@2.11.1", - "registry+https://github.com/rust-lang/crates.io-index#cfg-if@1.0.4", - "registry+https://github.com/rust-lang/crates.io-index#foreign-types@0.3.2", - "registry+https://github.com/rust-lang/crates.io-index#libc@0.2.186", - "registry+https://github.com/rust-lang/crates.io-index#openssl-macros@0.1.1", - "registry+https://github.com/rust-lang/crates.io-index#openssl-sys@0.9.115" - ] - }, - { - "ref": "registry+https://github.com/rust-lang/crates.io-index#pem@3.0.6", - "dependsOn": [ - "registry+https://github.com/rust-lang/crates.io-index#base64@0.22.1" - ] - }, - { - "ref": "registry+https://github.com/rust-lang/crates.io-index#pkg-config@0.3.33" - }, - { - "ref": "registry+https://github.com/rust-lang/crates.io-index#portable-atomic@1.13.1" - }, - { - "ref": "registry+https://github.com/rust-lang/crates.io-index#proc-macro2@1.0.106", - "dependsOn": [ - "registry+https://github.com/rust-lang/crates.io-index#unicode-ident@1.0.24" - ] - }, - { - "ref": "registry+https://github.com/rust-lang/crates.io-index#pyo3-build-config@0.28.3", - "dependsOn": [ - "registry+https://github.com/rust-lang/crates.io-index#target-lexicon@0.13.5" - ] - }, - { - "ref": "registry+https://github.com/rust-lang/crates.io-index#pyo3-ffi@0.28.3", - "dependsOn": [ - "registry+https://github.com/rust-lang/crates.io-index#libc@0.2.186", - "registry+https://github.com/rust-lang/crates.io-index#pyo3-build-config@0.28.3" - ] - }, - { - "ref": "registry+https://github.com/rust-lang/crates.io-index#pyo3-macros-backend@0.28.3", - "dependsOn": [ - "registry+https://github.com/rust-lang/crates.io-index#heck@0.5.0", - "registry+https://github.com/rust-lang/crates.io-index#proc-macro2@1.0.106", - "registry+https://github.com/rust-lang/crates.io-index#pyo3-build-config@0.28.3", - "registry+https://github.com/rust-lang/crates.io-index#quote@1.0.45", - "registry+https://github.com/rust-lang/crates.io-index#syn@2.0.117" - ] - }, - { - "ref": "registry+https://github.com/rust-lang/crates.io-index#pyo3-macros@0.28.3", - "dependsOn": [ - "registry+https://github.com/rust-lang/crates.io-index#proc-macro2@1.0.106", - "registry+https://github.com/rust-lang/crates.io-index#pyo3-macros-backend@0.28.3", - "registry+https://github.com/rust-lang/crates.io-index#quote@1.0.45", - "registry+https://github.com/rust-lang/crates.io-index#syn@2.0.117" - ] - }, - { - "ref": "registry+https://github.com/rust-lang/crates.io-index#pyo3@0.28.3", - "dependsOn": [ - "registry+https://github.com/rust-lang/crates.io-index#libc@0.2.186", - "registry+https://github.com/rust-lang/crates.io-index#once_cell@1.21.4", - "registry+https://github.com/rust-lang/crates.io-index#portable-atomic@1.13.1", - "registry+https://github.com/rust-lang/crates.io-index#pyo3-build-config@0.28.3", - "registry+https://github.com/rust-lang/crates.io-index#pyo3-ffi@0.28.3", - "registry+https://github.com/rust-lang/crates.io-index#pyo3-macros@0.28.3" - ] - }, - { - "ref": "registry+https://github.com/rust-lang/crates.io-index#quote@1.0.45", - "dependsOn": [ - "registry+https://github.com/rust-lang/crates.io-index#proc-macro2@1.0.106" - ] - }, - { - "ref": "registry+https://github.com/rust-lang/crates.io-index#self_cell@1.2.2" - }, - { - "ref": "registry+https://github.com/rust-lang/crates.io-index#shlex@1.3.0" - }, - { - "ref": "registry+https://github.com/rust-lang/crates.io-index#syn@2.0.117", - "dependsOn": [ - "registry+https://github.com/rust-lang/crates.io-index#proc-macro2@1.0.106", - "registry+https://github.com/rust-lang/crates.io-index#quote@1.0.45", - "registry+https://github.com/rust-lang/crates.io-index#unicode-ident@1.0.24" - ] - }, - { - "ref": "registry+https://github.com/rust-lang/crates.io-index#target-lexicon@0.13.5" - }, - { - "ref": "registry+https://github.com/rust-lang/crates.io-index#unicode-ident@1.0.24" - }, - { - "ref": "registry+https://github.com/rust-lang/crates.io-index#vcpkg@0.2.15" - } - ] -} \ No newline at end of file diff --git a/.venv/lib/python3.12/site-packages/cryptography-48.0.0.dist-info/sboms/sbom.json b/.venv/lib/python3.12/site-packages/cryptography-48.0.0.dist-info/sboms/sbom.json deleted file mode 100644 index f8e47c1..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography-48.0.0.dist-info/sboms/sbom.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - "bomFormat": "CycloneDX", - "specVersion": "1.5", - "version": 1, - "serialNumber": "urn:uuid:7b8d231f-c05f-4fe0-9e12-5dba4b373c50", - "metadata": { - "timestamp": "2026-05-02T09:34:54Z" - }, - "components": [ - { - "type": "library", - "name": "openssl", - "version": "4.0.0", - "purl": "pkg:generic/openssl@4.0.0?download_url=https://github.com/openssl/openssl/releases/download/openssl-4.0.0/openssl-4.0.0.tar.gz", - "hashes": [ - { - "alg": "SHA-256", - "content": "c32cf49a959c4f345f9606982dd36e7d28f7c58b19c2e25d75624d2b3d2f79ac" - } - ], - "externalReferences": [ - { - "type": "distribution", - "url": "https://github.com/openssl/openssl/releases/download/openssl-4.0.0/openssl-4.0.0.tar.gz" - } - ], - "properties": [ - { - "name": "build:operating-system", - "value": "linux" - }, - { - "name": "build:architecture", - "value": "x86_64" - }, - { - "name": "build:flags", - "value": "no-zlib no-shared no-module no-comp no-apps no-docs no-sm2-precomp no-atexit enable-ec_nistp_64_gcc_128" - } - ] - } - ] -} diff --git a/.venv/lib/python3.12/site-packages/cryptography/__about__.py b/.venv/lib/python3.12/site-packages/cryptography/__about__.py deleted file mode 100644 index c81901c..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/__about__.py +++ /dev/null @@ -1,17 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -__all__ = [ - "__author__", - "__copyright__", - "__version__", -] - -__version__ = "48.0.0" - - -__author__ = "The Python Cryptographic Authority and individual contributors" -__copyright__ = f"Copyright 2013-2026 {__author__}" diff --git a/.venv/lib/python3.12/site-packages/cryptography/__init__.py b/.venv/lib/python3.12/site-packages/cryptography/__init__.py deleted file mode 100644 index d374f75..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/__init__.py +++ /dev/null @@ -1,13 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -from cryptography.__about__ import __author__, __copyright__, __version__ - -__all__ = [ - "__author__", - "__copyright__", - "__version__", -] diff --git a/.venv/lib/python3.12/site-packages/cryptography/exceptions.py b/.venv/lib/python3.12/site-packages/cryptography/exceptions.py deleted file mode 100644 index fe125ea..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/exceptions.py +++ /dev/null @@ -1,52 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -import typing - -from cryptography.hazmat.bindings._rust import exceptions as rust_exceptions - -if typing.TYPE_CHECKING: - from cryptography.hazmat.bindings._rust import openssl as rust_openssl - -_Reasons = rust_exceptions._Reasons - - -class UnsupportedAlgorithm(Exception): - def __init__(self, message: str, reason: _Reasons | None = None) -> None: - super().__init__(message) - self._reason = reason - - -class AlreadyFinalized(Exception): - pass - - -class AlreadyUpdated(Exception): - pass - - -class NotYetFinalized(Exception): - pass - - -class InvalidTag(Exception): - pass - - -class InvalidSignature(Exception): - pass - - -class InternalError(Exception): - def __init__( - self, msg: str, err_code: list[rust_openssl.OpenSSLError] - ) -> None: - super().__init__(msg) - self.err_code = err_code - - -class InvalidKey(Exception): - pass diff --git a/.venv/lib/python3.12/site-packages/cryptography/fernet.py b/.venv/lib/python3.12/site-packages/cryptography/fernet.py deleted file mode 100644 index c6744ae..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/fernet.py +++ /dev/null @@ -1,224 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -import base64 -import binascii -import os -import time -import typing -from collections.abc import Iterable - -from cryptography import utils -from cryptography.exceptions import InvalidSignature -from cryptography.hazmat.primitives import hashes, padding -from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes -from cryptography.hazmat.primitives.hmac import HMAC - - -class InvalidToken(Exception): - pass - - -_MAX_CLOCK_SKEW = 60 - - -class Fernet: - def __init__( - self, - key: bytes | str, - backend: typing.Any = None, - ) -> None: - try: - key = base64.urlsafe_b64decode(key) - except binascii.Error as exc: - raise ValueError( - "Fernet key must be 32 url-safe base64-encoded bytes." - ) from exc - if len(key) != 32: - raise ValueError( - "Fernet key must be 32 url-safe base64-encoded bytes." - ) - - self._signing_key = key[:16] - self._encryption_key = key[16:] - - @classmethod - def generate_key(cls) -> bytes: - return base64.urlsafe_b64encode(os.urandom(32)) - - def encrypt(self, data: bytes) -> bytes: - return self.encrypt_at_time(data, int(time.time())) - - def encrypt_at_time(self, data: bytes, current_time: int) -> bytes: - iv = os.urandom(16) - return self._encrypt_from_parts(data, current_time, iv) - - def _encrypt_from_parts( - self, data: bytes, current_time: int, iv: bytes - ) -> bytes: - utils._check_bytes("data", data) - - padder = padding.PKCS7(algorithms.AES.block_size).padder() - padded_data = padder.update(data) + padder.finalize() - encryptor = Cipher( - algorithms.AES(self._encryption_key), - modes.CBC(iv), - ).encryptor() - ciphertext = encryptor.update(padded_data) + encryptor.finalize() - - basic_parts = ( - b"\x80" - + current_time.to_bytes(length=8, byteorder="big") - + iv - + ciphertext - ) - - h = HMAC(self._signing_key, hashes.SHA256()) - h.update(basic_parts) - hmac = h.finalize() - return base64.urlsafe_b64encode(basic_parts + hmac) - - def decrypt(self, token: bytes | str, ttl: int | None = None) -> bytes: - timestamp, data = Fernet._get_unverified_token_data(token) - if ttl is None: - time_info = None - else: - time_info = (ttl, int(time.time())) - return self._decrypt_data(data, timestamp, time_info) - - def decrypt_at_time( - self, token: bytes | str, ttl: int, current_time: int - ) -> bytes: - if ttl is None: - raise ValueError( - "decrypt_at_time() can only be used with a non-None ttl" - ) - timestamp, data = Fernet._get_unverified_token_data(token) - return self._decrypt_data(data, timestamp, (ttl, current_time)) - - def extract_timestamp(self, token: bytes | str) -> int: - timestamp, data = Fernet._get_unverified_token_data(token) - # Verify the token was not tampered with. - self._verify_signature(data) - return timestamp - - @staticmethod - def _get_unverified_token_data(token: bytes | str) -> tuple[int, bytes]: - if not isinstance(token, (str, bytes)): - raise TypeError("token must be bytes or str") - - try: - data = base64.urlsafe_b64decode(token) - except (TypeError, binascii.Error): - raise InvalidToken - - if not data or data[0] != 0x80: - raise InvalidToken - - if len(data) < 9: - raise InvalidToken - - timestamp = int.from_bytes(data[1:9], byteorder="big") - return timestamp, data - - def _verify_signature(self, data: bytes) -> None: - h = HMAC(self._signing_key, hashes.SHA256()) - h.update(data[:-32]) - try: - h.verify(data[-32:]) - except InvalidSignature: - raise InvalidToken - - def _decrypt_data( - self, - data: bytes, - timestamp: int, - time_info: tuple[int, int] | None, - ) -> bytes: - if time_info is not None: - ttl, current_time = time_info - if timestamp + ttl < current_time: - raise InvalidToken - - if current_time + _MAX_CLOCK_SKEW < timestamp: - raise InvalidToken - - self._verify_signature(data) - - iv = data[9:25] - ciphertext = data[25:-32] - decryptor = Cipher( - algorithms.AES(self._encryption_key), modes.CBC(iv) - ).decryptor() - plaintext_padded = decryptor.update(ciphertext) - try: - plaintext_padded += decryptor.finalize() - except ValueError: - raise InvalidToken - unpadder = padding.PKCS7(algorithms.AES.block_size).unpadder() - - unpadded = unpadder.update(plaintext_padded) - try: - unpadded += unpadder.finalize() - except ValueError: - raise InvalidToken - return unpadded - - -class MultiFernet: - def __init__(self, fernets: Iterable[Fernet]): - fernets = list(fernets) - if not fernets: - raise ValueError( - "MultiFernet requires at least one Fernet instance" - ) - self._fernets = fernets - - def encrypt(self, msg: bytes) -> bytes: - return self.encrypt_at_time(msg, int(time.time())) - - def encrypt_at_time(self, msg: bytes, current_time: int) -> bytes: - return self._fernets[0].encrypt_at_time(msg, current_time) - - def rotate(self, msg: bytes | str) -> bytes: - timestamp, data = Fernet._get_unverified_token_data(msg) - for f in self._fernets: - try: - p = f._decrypt_data(data, timestamp, None) - break - except InvalidToken: - pass - else: - raise InvalidToken - - iv = os.urandom(16) - return self._fernets[0]._encrypt_from_parts(p, timestamp, iv) - - def decrypt(self, msg: bytes | str, ttl: int | None = None) -> bytes: - for f in self._fernets: - try: - return f.decrypt(msg, ttl) - except InvalidToken: - pass - raise InvalidToken - - def decrypt_at_time( - self, msg: bytes | str, ttl: int, current_time: int - ) -> bytes: - for f in self._fernets: - try: - return f.decrypt_at_time(msg, ttl, current_time) - except InvalidToken: - pass - raise InvalidToken - - def extract_timestamp(self, msg: bytes | str) -> int: - for f in self._fernets: - try: - return f.extract_timestamp(msg) - except InvalidToken: - pass - raise InvalidToken diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/__init__.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/__init__.py deleted file mode 100644 index b9f1187..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/__init__.py +++ /dev/null @@ -1,13 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -""" -Hazardous Materials - -This is a "Hazardous Materials" module. You should ONLY use it if you're -100% absolutely sure that you know what you're doing because this module -is full of land mines, dragons, and dinosaurs with laser guns. -""" diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/_oid.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/_oid.py deleted file mode 100644 index 4bf138d..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/_oid.py +++ /dev/null @@ -1,356 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -from cryptography.hazmat.bindings._rust import ( - ObjectIdentifier as ObjectIdentifier, -) -from cryptography.hazmat.primitives import hashes - - -class ExtensionOID: - SUBJECT_DIRECTORY_ATTRIBUTES = ObjectIdentifier("2.5.29.9") - SUBJECT_KEY_IDENTIFIER = ObjectIdentifier("2.5.29.14") - KEY_USAGE = ObjectIdentifier("2.5.29.15") - PRIVATE_KEY_USAGE_PERIOD = ObjectIdentifier("2.5.29.16") - SUBJECT_ALTERNATIVE_NAME = ObjectIdentifier("2.5.29.17") - ISSUER_ALTERNATIVE_NAME = ObjectIdentifier("2.5.29.18") - BASIC_CONSTRAINTS = ObjectIdentifier("2.5.29.19") - NAME_CONSTRAINTS = ObjectIdentifier("2.5.29.30") - CRL_DISTRIBUTION_POINTS = ObjectIdentifier("2.5.29.31") - CERTIFICATE_POLICIES = ObjectIdentifier("2.5.29.32") - POLICY_MAPPINGS = ObjectIdentifier("2.5.29.33") - AUTHORITY_KEY_IDENTIFIER = ObjectIdentifier("2.5.29.35") - POLICY_CONSTRAINTS = ObjectIdentifier("2.5.29.36") - EXTENDED_KEY_USAGE = ObjectIdentifier("2.5.29.37") - FRESHEST_CRL = ObjectIdentifier("2.5.29.46") - INHIBIT_ANY_POLICY = ObjectIdentifier("2.5.29.54") - ISSUING_DISTRIBUTION_POINT = ObjectIdentifier("2.5.29.28") - AUTHORITY_INFORMATION_ACCESS = ObjectIdentifier("1.3.6.1.5.5.7.1.1") - SUBJECT_INFORMATION_ACCESS = ObjectIdentifier("1.3.6.1.5.5.7.1.11") - OCSP_NO_CHECK = ObjectIdentifier("1.3.6.1.5.5.7.48.1.5") - TLS_FEATURE = ObjectIdentifier("1.3.6.1.5.5.7.1.24") - CRL_NUMBER = ObjectIdentifier("2.5.29.20") - DELTA_CRL_INDICATOR = ObjectIdentifier("2.5.29.27") - PRECERT_SIGNED_CERTIFICATE_TIMESTAMPS = ObjectIdentifier( - "1.3.6.1.4.1.11129.2.4.2" - ) - PRECERT_POISON = ObjectIdentifier("1.3.6.1.4.1.11129.2.4.3") - SIGNED_CERTIFICATE_TIMESTAMPS = ObjectIdentifier("1.3.6.1.4.1.11129.2.4.5") - MS_CERTIFICATE_TEMPLATE = ObjectIdentifier("1.3.6.1.4.1.311.21.7") - ADMISSIONS = ObjectIdentifier("1.3.36.8.3.3") - - -class OCSPExtensionOID: - NONCE = ObjectIdentifier("1.3.6.1.5.5.7.48.1.2") - ACCEPTABLE_RESPONSES = ObjectIdentifier("1.3.6.1.5.5.7.48.1.4") - - -class CRLEntryExtensionOID: - CERTIFICATE_ISSUER = ObjectIdentifier("2.5.29.29") - CRL_REASON = ObjectIdentifier("2.5.29.21") - INVALIDITY_DATE = ObjectIdentifier("2.5.29.24") - - -class NameOID: - COMMON_NAME = ObjectIdentifier("2.5.4.3") - COUNTRY_NAME = ObjectIdentifier("2.5.4.6") - LOCALITY_NAME = ObjectIdentifier("2.5.4.7") - STATE_OR_PROVINCE_NAME = ObjectIdentifier("2.5.4.8") - STREET_ADDRESS = ObjectIdentifier("2.5.4.9") - ORGANIZATION_IDENTIFIER = ObjectIdentifier("2.5.4.97") - ORGANIZATION_NAME = ObjectIdentifier("2.5.4.10") - ORGANIZATIONAL_UNIT_NAME = ObjectIdentifier("2.5.4.11") - SERIAL_NUMBER = ObjectIdentifier("2.5.4.5") - SURNAME = ObjectIdentifier("2.5.4.4") - GIVEN_NAME = ObjectIdentifier("2.5.4.42") - TITLE = ObjectIdentifier("2.5.4.12") - INITIALS = ObjectIdentifier("2.5.4.43") - GENERATION_QUALIFIER = ObjectIdentifier("2.5.4.44") - X500_UNIQUE_IDENTIFIER = ObjectIdentifier("2.5.4.45") - DN_QUALIFIER = ObjectIdentifier("2.5.4.46") - PSEUDONYM = ObjectIdentifier("2.5.4.65") - USER_ID = ObjectIdentifier("0.9.2342.19200300.100.1.1") - DOMAIN_COMPONENT = ObjectIdentifier("0.9.2342.19200300.100.1.25") - EMAIL_ADDRESS = ObjectIdentifier("1.2.840.113549.1.9.1") - JURISDICTION_COUNTRY_NAME = ObjectIdentifier("1.3.6.1.4.1.311.60.2.1.3") - JURISDICTION_LOCALITY_NAME = ObjectIdentifier("1.3.6.1.4.1.311.60.2.1.1") - JURISDICTION_STATE_OR_PROVINCE_NAME = ObjectIdentifier( - "1.3.6.1.4.1.311.60.2.1.2" - ) - BUSINESS_CATEGORY = ObjectIdentifier("2.5.4.15") - POSTAL_ADDRESS = ObjectIdentifier("2.5.4.16") - POSTAL_CODE = ObjectIdentifier("2.5.4.17") - INN = ObjectIdentifier("1.2.643.3.131.1.1") - OGRN = ObjectIdentifier("1.2.643.100.1") - SNILS = ObjectIdentifier("1.2.643.100.3") - UNSTRUCTURED_NAME = ObjectIdentifier("1.2.840.113549.1.9.2") - - -class SignatureAlgorithmOID: - RSA_WITH_MD5 = ObjectIdentifier("1.2.840.113549.1.1.4") - RSA_WITH_SHA1 = ObjectIdentifier("1.2.840.113549.1.1.5") - # This is an alternate OID for RSA with SHA1 that is occasionally seen - _RSA_WITH_SHA1 = ObjectIdentifier("1.3.14.3.2.29") - RSA_WITH_SHA224 = ObjectIdentifier("1.2.840.113549.1.1.14") - RSA_WITH_SHA256 = ObjectIdentifier("1.2.840.113549.1.1.11") - RSA_WITH_SHA384 = ObjectIdentifier("1.2.840.113549.1.1.12") - RSA_WITH_SHA512 = ObjectIdentifier("1.2.840.113549.1.1.13") - RSA_WITH_SHA3_224 = ObjectIdentifier("2.16.840.1.101.3.4.3.13") - RSA_WITH_SHA3_256 = ObjectIdentifier("2.16.840.1.101.3.4.3.14") - RSA_WITH_SHA3_384 = ObjectIdentifier("2.16.840.1.101.3.4.3.15") - RSA_WITH_SHA3_512 = ObjectIdentifier("2.16.840.1.101.3.4.3.16") - RSASSA_PSS = ObjectIdentifier("1.2.840.113549.1.1.10") - ECDSA_WITH_SHA1 = ObjectIdentifier("1.2.840.10045.4.1") - ECDSA_WITH_SHA224 = ObjectIdentifier("1.2.840.10045.4.3.1") - ECDSA_WITH_SHA256 = ObjectIdentifier("1.2.840.10045.4.3.2") - ECDSA_WITH_SHA384 = ObjectIdentifier("1.2.840.10045.4.3.3") - ECDSA_WITH_SHA512 = ObjectIdentifier("1.2.840.10045.4.3.4") - ECDSA_WITH_SHA3_224 = ObjectIdentifier("2.16.840.1.101.3.4.3.9") - ECDSA_WITH_SHA3_256 = ObjectIdentifier("2.16.840.1.101.3.4.3.10") - ECDSA_WITH_SHA3_384 = ObjectIdentifier("2.16.840.1.101.3.4.3.11") - ECDSA_WITH_SHA3_512 = ObjectIdentifier("2.16.840.1.101.3.4.3.12") - DSA_WITH_SHA1 = ObjectIdentifier("1.2.840.10040.4.3") - DSA_WITH_SHA224 = ObjectIdentifier("2.16.840.1.101.3.4.3.1") - DSA_WITH_SHA256 = ObjectIdentifier("2.16.840.1.101.3.4.3.2") - DSA_WITH_SHA384 = ObjectIdentifier("2.16.840.1.101.3.4.3.3") - DSA_WITH_SHA512 = ObjectIdentifier("2.16.840.1.101.3.4.3.4") - ED25519 = ObjectIdentifier("1.3.101.112") - ED448 = ObjectIdentifier("1.3.101.113") - GOSTR3411_94_WITH_3410_2001 = ObjectIdentifier("1.2.643.2.2.3") - GOSTR3410_2012_WITH_3411_2012_256 = ObjectIdentifier("1.2.643.7.1.1.3.2") - GOSTR3410_2012_WITH_3411_2012_512 = ObjectIdentifier("1.2.643.7.1.1.3.3") - - -_SIG_OIDS_TO_HASH: dict[ObjectIdentifier, hashes.HashAlgorithm | None] = { - SignatureAlgorithmOID.RSA_WITH_MD5: hashes.MD5(), - SignatureAlgorithmOID.RSA_WITH_SHA1: hashes.SHA1(), - SignatureAlgorithmOID._RSA_WITH_SHA1: hashes.SHA1(), - SignatureAlgorithmOID.RSA_WITH_SHA224: hashes.SHA224(), - SignatureAlgorithmOID.RSA_WITH_SHA256: hashes.SHA256(), - SignatureAlgorithmOID.RSA_WITH_SHA384: hashes.SHA384(), - SignatureAlgorithmOID.RSA_WITH_SHA512: hashes.SHA512(), - SignatureAlgorithmOID.RSA_WITH_SHA3_224: hashes.SHA3_224(), - SignatureAlgorithmOID.RSA_WITH_SHA3_256: hashes.SHA3_256(), - SignatureAlgorithmOID.RSA_WITH_SHA3_384: hashes.SHA3_384(), - SignatureAlgorithmOID.RSA_WITH_SHA3_512: hashes.SHA3_512(), - SignatureAlgorithmOID.ECDSA_WITH_SHA1: hashes.SHA1(), - SignatureAlgorithmOID.ECDSA_WITH_SHA224: hashes.SHA224(), - SignatureAlgorithmOID.ECDSA_WITH_SHA256: hashes.SHA256(), - SignatureAlgorithmOID.ECDSA_WITH_SHA384: hashes.SHA384(), - SignatureAlgorithmOID.ECDSA_WITH_SHA512: hashes.SHA512(), - SignatureAlgorithmOID.ECDSA_WITH_SHA3_224: hashes.SHA3_224(), - SignatureAlgorithmOID.ECDSA_WITH_SHA3_256: hashes.SHA3_256(), - SignatureAlgorithmOID.ECDSA_WITH_SHA3_384: hashes.SHA3_384(), - SignatureAlgorithmOID.ECDSA_WITH_SHA3_512: hashes.SHA3_512(), - SignatureAlgorithmOID.DSA_WITH_SHA1: hashes.SHA1(), - SignatureAlgorithmOID.DSA_WITH_SHA224: hashes.SHA224(), - SignatureAlgorithmOID.DSA_WITH_SHA256: hashes.SHA256(), - SignatureAlgorithmOID.ED25519: None, - SignatureAlgorithmOID.ED448: None, - SignatureAlgorithmOID.GOSTR3411_94_WITH_3410_2001: None, - SignatureAlgorithmOID.GOSTR3410_2012_WITH_3411_2012_256: None, - SignatureAlgorithmOID.GOSTR3410_2012_WITH_3411_2012_512: None, -} - - -class HashAlgorithmOID: - SHA1 = ObjectIdentifier("1.3.14.3.2.26") - SHA224 = ObjectIdentifier("2.16.840.1.101.3.4.2.4") - SHA256 = ObjectIdentifier("2.16.840.1.101.3.4.2.1") - SHA384 = ObjectIdentifier("2.16.840.1.101.3.4.2.2") - SHA512 = ObjectIdentifier("2.16.840.1.101.3.4.2.3") - SHA3_224 = ObjectIdentifier("1.3.6.1.4.1.37476.3.2.1.99.7.224") - SHA3_256 = ObjectIdentifier("1.3.6.1.4.1.37476.3.2.1.99.7.256") - SHA3_384 = ObjectIdentifier("1.3.6.1.4.1.37476.3.2.1.99.7.384") - SHA3_512 = ObjectIdentifier("1.3.6.1.4.1.37476.3.2.1.99.7.512") - SHA3_224_NIST = ObjectIdentifier("2.16.840.1.101.3.4.2.7") - SHA3_256_NIST = ObjectIdentifier("2.16.840.1.101.3.4.2.8") - SHA3_384_NIST = ObjectIdentifier("2.16.840.1.101.3.4.2.9") - SHA3_512_NIST = ObjectIdentifier("2.16.840.1.101.3.4.2.10") - - -class PublicKeyAlgorithmOID: - DSA = ObjectIdentifier("1.2.840.10040.4.1") - EC_PUBLIC_KEY = ObjectIdentifier("1.2.840.10045.2.1") - RSAES_PKCS1_v1_5 = ObjectIdentifier("1.2.840.113549.1.1.1") - RSASSA_PSS = ObjectIdentifier("1.2.840.113549.1.1.10") - X25519 = ObjectIdentifier("1.3.101.110") - X448 = ObjectIdentifier("1.3.101.111") - ED25519 = ObjectIdentifier("1.3.101.112") - ED448 = ObjectIdentifier("1.3.101.113") - - -class ExtendedKeyUsageOID: - SERVER_AUTH = ObjectIdentifier("1.3.6.1.5.5.7.3.1") - CLIENT_AUTH = ObjectIdentifier("1.3.6.1.5.5.7.3.2") - CODE_SIGNING = ObjectIdentifier("1.3.6.1.5.5.7.3.3") - EMAIL_PROTECTION = ObjectIdentifier("1.3.6.1.5.5.7.3.4") - TIME_STAMPING = ObjectIdentifier("1.3.6.1.5.5.7.3.8") - OCSP_SIGNING = ObjectIdentifier("1.3.6.1.5.5.7.3.9") - ANY_EXTENDED_KEY_USAGE = ObjectIdentifier("2.5.29.37.0") - SMARTCARD_LOGON = ObjectIdentifier("1.3.6.1.4.1.311.20.2.2") - KERBEROS_PKINIT_KDC = ObjectIdentifier("1.3.6.1.5.2.3.5") - IPSEC_IKE = ObjectIdentifier("1.3.6.1.5.5.7.3.17") - BUNDLE_SECURITY = ObjectIdentifier("1.3.6.1.5.5.7.3.35") - CERTIFICATE_TRANSPARENCY = ObjectIdentifier("1.3.6.1.4.1.11129.2.4.4") - - -class OtherNameFormOID: - PERMANENT_IDENTIFIER = ObjectIdentifier("1.3.6.1.5.5.7.8.3") - HW_MODULE_NAME = ObjectIdentifier("1.3.6.1.5.5.7.8.4") - DNS_SRV = ObjectIdentifier("1.3.6.1.5.5.7.8.7") - NAI_REALM = ObjectIdentifier("1.3.6.1.5.5.7.8.8") - SMTP_UTF8_MAILBOX = ObjectIdentifier("1.3.6.1.5.5.7.8.9") - ACP_NODE_NAME = ObjectIdentifier("1.3.6.1.5.5.7.8.10") - BUNDLE_EID = ObjectIdentifier("1.3.6.1.5.5.7.8.11") - - -class AuthorityInformationAccessOID: - CA_ISSUERS = ObjectIdentifier("1.3.6.1.5.5.7.48.2") - OCSP = ObjectIdentifier("1.3.6.1.5.5.7.48.1") - - -class SubjectInformationAccessOID: - CA_REPOSITORY = ObjectIdentifier("1.3.6.1.5.5.7.48.5") - - -class CertificatePoliciesOID: - CPS_QUALIFIER = ObjectIdentifier("1.3.6.1.5.5.7.2.1") - CPS_USER_NOTICE = ObjectIdentifier("1.3.6.1.5.5.7.2.2") - ANY_POLICY = ObjectIdentifier("2.5.29.32.0") - - -class AttributeOID: - CHALLENGE_PASSWORD = ObjectIdentifier("1.2.840.113549.1.9.7") - UNSTRUCTURED_NAME = ObjectIdentifier("1.2.840.113549.1.9.2") - - -_OID_NAMES = { - NameOID.COMMON_NAME: "commonName", - NameOID.COUNTRY_NAME: "countryName", - NameOID.LOCALITY_NAME: "localityName", - NameOID.STATE_OR_PROVINCE_NAME: "stateOrProvinceName", - NameOID.STREET_ADDRESS: "streetAddress", - NameOID.ORGANIZATION_NAME: "organizationName", - NameOID.ORGANIZATIONAL_UNIT_NAME: "organizationalUnitName", - NameOID.SERIAL_NUMBER: "serialNumber", - NameOID.SURNAME: "surname", - NameOID.GIVEN_NAME: "givenName", - NameOID.TITLE: "title", - NameOID.GENERATION_QUALIFIER: "generationQualifier", - NameOID.X500_UNIQUE_IDENTIFIER: "x500UniqueIdentifier", - NameOID.DN_QUALIFIER: "dnQualifier", - NameOID.PSEUDONYM: "pseudonym", - NameOID.USER_ID: "userID", - NameOID.DOMAIN_COMPONENT: "domainComponent", - NameOID.EMAIL_ADDRESS: "emailAddress", - NameOID.JURISDICTION_COUNTRY_NAME: "jurisdictionCountryName", - NameOID.JURISDICTION_LOCALITY_NAME: "jurisdictionLocalityName", - NameOID.JURISDICTION_STATE_OR_PROVINCE_NAME: ( - "jurisdictionStateOrProvinceName" - ), - NameOID.BUSINESS_CATEGORY: "businessCategory", - NameOID.POSTAL_ADDRESS: "postalAddress", - NameOID.POSTAL_CODE: "postalCode", - NameOID.INN: "INN", - NameOID.OGRN: "OGRN", - NameOID.SNILS: "SNILS", - NameOID.UNSTRUCTURED_NAME: "unstructuredName", - SignatureAlgorithmOID.RSA_WITH_MD5: "md5WithRSAEncryption", - SignatureAlgorithmOID.RSA_WITH_SHA1: "sha1WithRSAEncryption", - SignatureAlgorithmOID.RSA_WITH_SHA224: "sha224WithRSAEncryption", - SignatureAlgorithmOID.RSA_WITH_SHA256: "sha256WithRSAEncryption", - SignatureAlgorithmOID.RSA_WITH_SHA384: "sha384WithRSAEncryption", - SignatureAlgorithmOID.RSA_WITH_SHA512: "sha512WithRSAEncryption", - SignatureAlgorithmOID.RSASSA_PSS: "rsassaPss", - SignatureAlgorithmOID.ECDSA_WITH_SHA1: "ecdsa-with-SHA1", - SignatureAlgorithmOID.ECDSA_WITH_SHA224: "ecdsa-with-SHA224", - SignatureAlgorithmOID.ECDSA_WITH_SHA256: "ecdsa-with-SHA256", - SignatureAlgorithmOID.ECDSA_WITH_SHA384: "ecdsa-with-SHA384", - SignatureAlgorithmOID.ECDSA_WITH_SHA512: "ecdsa-with-SHA512", - SignatureAlgorithmOID.DSA_WITH_SHA1: "dsa-with-sha1", - SignatureAlgorithmOID.DSA_WITH_SHA224: "dsa-with-sha224", - SignatureAlgorithmOID.DSA_WITH_SHA256: "dsa-with-sha256", - SignatureAlgorithmOID.ED25519: "ed25519", - SignatureAlgorithmOID.ED448: "ed448", - SignatureAlgorithmOID.GOSTR3411_94_WITH_3410_2001: ( - "GOST R 34.11-94 with GOST R 34.10-2001" - ), - SignatureAlgorithmOID.GOSTR3410_2012_WITH_3411_2012_256: ( - "GOST R 34.10-2012 with GOST R 34.11-2012 (256 bit)" - ), - SignatureAlgorithmOID.GOSTR3410_2012_WITH_3411_2012_512: ( - "GOST R 34.10-2012 with GOST R 34.11-2012 (512 bit)" - ), - HashAlgorithmOID.SHA1: "sha1", - HashAlgorithmOID.SHA224: "sha224", - HashAlgorithmOID.SHA256: "sha256", - HashAlgorithmOID.SHA384: "sha384", - HashAlgorithmOID.SHA512: "sha512", - HashAlgorithmOID.SHA3_224: "sha3_224", - HashAlgorithmOID.SHA3_256: "sha3_256", - HashAlgorithmOID.SHA3_384: "sha3_384", - HashAlgorithmOID.SHA3_512: "sha3_512", - HashAlgorithmOID.SHA3_224_NIST: "sha3_224", - HashAlgorithmOID.SHA3_256_NIST: "sha3_256", - HashAlgorithmOID.SHA3_384_NIST: "sha3_384", - HashAlgorithmOID.SHA3_512_NIST: "sha3_512", - PublicKeyAlgorithmOID.DSA: "dsaEncryption", - PublicKeyAlgorithmOID.EC_PUBLIC_KEY: "id-ecPublicKey", - PublicKeyAlgorithmOID.RSAES_PKCS1_v1_5: "rsaEncryption", - PublicKeyAlgorithmOID.X25519: "X25519", - PublicKeyAlgorithmOID.X448: "X448", - ExtendedKeyUsageOID.SERVER_AUTH: "serverAuth", - ExtendedKeyUsageOID.CLIENT_AUTH: "clientAuth", - ExtendedKeyUsageOID.CODE_SIGNING: "codeSigning", - ExtendedKeyUsageOID.EMAIL_PROTECTION: "emailProtection", - ExtendedKeyUsageOID.TIME_STAMPING: "timeStamping", - ExtendedKeyUsageOID.OCSP_SIGNING: "OCSPSigning", - ExtendedKeyUsageOID.SMARTCARD_LOGON: "msSmartcardLogin", - ExtendedKeyUsageOID.KERBEROS_PKINIT_KDC: "pkInitKDC", - ExtensionOID.SUBJECT_DIRECTORY_ATTRIBUTES: "subjectDirectoryAttributes", - ExtensionOID.SUBJECT_KEY_IDENTIFIER: "subjectKeyIdentifier", - ExtensionOID.KEY_USAGE: "keyUsage", - ExtensionOID.PRIVATE_KEY_USAGE_PERIOD: "privateKeyUsagePeriod", - ExtensionOID.SUBJECT_ALTERNATIVE_NAME: "subjectAltName", - ExtensionOID.ISSUER_ALTERNATIVE_NAME: "issuerAltName", - ExtensionOID.BASIC_CONSTRAINTS: "basicConstraints", - ExtensionOID.PRECERT_SIGNED_CERTIFICATE_TIMESTAMPS: ( - "signedCertificateTimestampList" - ), - ExtensionOID.SIGNED_CERTIFICATE_TIMESTAMPS: ( - "signedCertificateTimestampList" - ), - ExtensionOID.PRECERT_POISON: "ctPoison", - ExtensionOID.MS_CERTIFICATE_TEMPLATE: "msCertificateTemplate", - ExtensionOID.ADMISSIONS: "Admissions", - CRLEntryExtensionOID.CRL_REASON: "cRLReason", - CRLEntryExtensionOID.INVALIDITY_DATE: "invalidityDate", - CRLEntryExtensionOID.CERTIFICATE_ISSUER: "certificateIssuer", - ExtensionOID.NAME_CONSTRAINTS: "nameConstraints", - ExtensionOID.CRL_DISTRIBUTION_POINTS: "cRLDistributionPoints", - ExtensionOID.CERTIFICATE_POLICIES: "certificatePolicies", - ExtensionOID.POLICY_MAPPINGS: "policyMappings", - ExtensionOID.AUTHORITY_KEY_IDENTIFIER: "authorityKeyIdentifier", - ExtensionOID.POLICY_CONSTRAINTS: "policyConstraints", - ExtensionOID.EXTENDED_KEY_USAGE: "extendedKeyUsage", - ExtensionOID.FRESHEST_CRL: "freshestCRL", - ExtensionOID.INHIBIT_ANY_POLICY: "inhibitAnyPolicy", - ExtensionOID.ISSUING_DISTRIBUTION_POINT: "issuingDistributionPoint", - ExtensionOID.AUTHORITY_INFORMATION_ACCESS: "authorityInfoAccess", - ExtensionOID.SUBJECT_INFORMATION_ACCESS: "subjectInfoAccess", - ExtensionOID.OCSP_NO_CHECK: "OCSPNoCheck", - ExtensionOID.CRL_NUMBER: "cRLNumber", - ExtensionOID.DELTA_CRL_INDICATOR: "deltaCRLIndicator", - ExtensionOID.TLS_FEATURE: "TLSFeature", - AuthorityInformationAccessOID.OCSP: "OCSP", - AuthorityInformationAccessOID.CA_ISSUERS: "caIssuers", - SubjectInformationAccessOID.CA_REPOSITORY: "caRepository", - CertificatePoliciesOID.CPS_QUALIFIER: "id-qt-cps", - CertificatePoliciesOID.CPS_USER_NOTICE: "id-qt-unotice", - OCSPExtensionOID.NONCE: "OCSPNonce", - AttributeOID.CHALLENGE_PASSWORD: "challengePassword", -} diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/asn1/__init__.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/asn1/__init__.py deleted file mode 100644 index ac3d4bd..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/asn1/__init__.py +++ /dev/null @@ -1,43 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from cryptography.hazmat.asn1.asn1 import ( - TLV, - BitString, - Default, - Explicit, - GeneralizedTime, - IA5String, - Implicit, - Null, - PrintableString, - SetOf, - Size, - UTCTime, - Variant, - decode_der, - encode_der, - sequence, - set, -) - -__all__ = [ - "TLV", - "BitString", - "Default", - "Explicit", - "GeneralizedTime", - "IA5String", - "Implicit", - "Null", - "PrintableString", - "SetOf", - "Size", - "UTCTime", - "Variant", - "decode_der", - "encode_der", - "sequence", - "set", -] diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/asn1/asn1.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/asn1/asn1.py deleted file mode 100644 index aa18d7e..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/asn1/asn1.py +++ /dev/null @@ -1,419 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -import builtins -import dataclasses -import sys -import types -import typing - -if sys.version_info < (3, 11): - import typing_extensions - - LiteralString = typing_extensions.LiteralString -else: - LiteralString = typing.LiteralString - -from cryptography.hazmat.bindings._rust import declarative_asn1 - -if sys.version_info < (3, 10): - NoneType = type(None) -else: - NoneType = types.NoneType # type: ignore[nonetype-type] - -T = typing.TypeVar("T", covariant=True) -U = typing.TypeVar("U") -Tag = typing.TypeVar("Tag", bound=LiteralString) - - -@dataclasses.dataclass(frozen=True) -class Variant(typing.Generic[U, Tag]): - """ - A tagged variant for CHOICE fields with the same underlying type. - - Use this when you have multiple CHOICE alternatives with the same type - and need to distinguish between them: - - foo: ( - Annotated[Variant[int, typing.Literal["IntA"]], Implicit(0)] - | Annotated[Variant[int, typing.Literal["IntB"]], Implicit(1)] - ) - - Usage: - example = Example(foo=Variant(5, "IntA")) - decoded.foo.value # The int value - decoded.foo.tag # "IntA" or "IntB" - """ - - value: U - tag: str - - -decode_der = declarative_asn1.decode_der -encode_der = declarative_asn1.encode_der - - -def _is_union(field_type: type) -> bool: - # NOTE: types.UnionType for `T | U`, typing.Union for `Union[T, U]`. - # TODO: Drop the `hasattr()` once the minimum supported Python version - # is >= 3.10. - union_types = ( - (types.UnionType, typing.Union) - if hasattr(types, "UnionType") - else (typing.Union,) - ) - return typing.get_origin(field_type) in union_types - - -def _extract_annotation( - metadata: tuple, field_name: str -) -> declarative_asn1.Annotation: - default = None - encoding = None - size = None - for raw_annotation in metadata: - if isinstance(raw_annotation, Default): - if default is not None: - raise TypeError( - f"multiple DEFAULT annotations found in field " - f"'{field_name}'" - ) - default = raw_annotation.value - elif isinstance(raw_annotation, declarative_asn1.Encoding): - if encoding is not None: - raise TypeError( - f"multiple IMPLICIT/EXPLICIT annotations found in field " - f"'{field_name}'" - ) - encoding = raw_annotation - elif isinstance(raw_annotation, declarative_asn1.Size): - if size is not None: - raise TypeError( - f"multiple SIZE annotations found in field '{field_name}'" - ) - size = raw_annotation - else: - raise TypeError(f"unsupported annotation: {raw_annotation}") - - return declarative_asn1.Annotation( - default=default, encoding=encoding, size=size - ) - - -def _normalize_field_type( - field_type: typing.Any, field_name: str -) -> declarative_asn1.AnnotatedType: - # Strip the `Annotated[...]` off, and populate the annotation - # from it if it exists. - if typing.get_origin(field_type) is typing.Annotated: - annotation = _extract_annotation(field_type.__metadata__, field_name) - field_type, *_ = typing.get_args(field_type) - else: - annotation = declarative_asn1.Annotation() - - if annotation.size is not None and ( - typing.get_origin(field_type) not in (builtins.list, SetOf) - and field_type - not in ( - builtins.bytes, - builtins.str, - BitString, - IA5String, - PrintableString, - ) - ): - raise TypeError( - f"field '{field_name}' has a SIZE annotation, but SIZE " - "annotations are only supported for fields of types: " - "[SEQUENCE OF, SET OF, BIT STRING, OCTET STRING, UTF8String, " - "PrintableString, IA5String]" - ) - - if field_type is TLV: - if isinstance(annotation.encoding, Implicit): - raise TypeError( - f"field '{field_name}' has an IMPLICIT annotation, but " - "IMPLICIT annotations are not supported for TLV types." - ) - elif annotation.default is not None: - raise TypeError( - f"field '{field_name}' has a DEFAULT annotation, but " - "DEFAULT annotations are not supported for TLV types." - ) - - if hasattr(field_type, "__asn1_root__"): - root_type = field_type.__asn1_root__ - if not isinstance( - root_type, - (declarative_asn1.Type.Sequence, declarative_asn1.Type.Set), - ): - raise TypeError(f"unsupported root type: {root_type}") - return declarative_asn1.AnnotatedType( - typing.cast(declarative_asn1.Type, root_type), annotation - ) - elif _is_union(field_type): - union_args = typing.get_args(field_type) - if len(union_args) == 2 and NoneType in union_args: - # A Union between a type and None is an OPTIONAL - optional_type = ( - union_args[0] if union_args[1] is type(None) else union_args[1] - ) - if optional_type is TLV: - raise TypeError( - "optional TLV types (`TLV | None`) are not " - "currently supported" - ) - annotated_type = _normalize_field_type(optional_type, field_name) - - if not annotated_type.annotation.is_empty(): - raise TypeError( - "optional (`X | None`) types cannot have `X` " - "annotated: annotations must apply to the union " - "(i.e: `Annotated[X | None, annotation]`)" - ) - - if annotation.default is not None: - raise TypeError( - "optional (`X | None`) types should not have a DEFAULT " - "annotation" - ) - - rust_field_type = declarative_asn1.Type.Option(annotated_type) - - else: - # Otherwise, the Union is a CHOICE - if isinstance(annotation.encoding, Implicit): - # CHOICEs cannot be IMPLICIT. See X.680 section 31.2.9. - raise TypeError( - "CHOICE (`X | Y | ...`) types should not have an IMPLICIT " - "annotation" - ) - variants = [ - _type_to_variant(arg, field_name) - for arg in union_args - if arg is not type(None) - ] - - # Union types should either be all Variants - # (`Variant[..] | Variant[..] | etc`) or all non Variants - are_union_types_tagged = variants[0].tag_name is not None - if any( - (v.tag_name is not None) != are_union_types_tagged - for v in variants - ): - raise TypeError( - "When using `asn1.Variant` in a union, all the other " - "types in the union must also be `asn1.Variant`" - ) - - if are_union_types_tagged: - tags = {v.tag_name for v in variants} - if len(variants) != len(tags): - raise TypeError( - "When using `asn1.Variant` in a union, the tags used " - "must be unique" - ) - - rust_choice_type = declarative_asn1.Type.Choice(variants) - # If None is part of the union types, this is an OPTIONAL CHOICE - rust_field_type = ( - declarative_asn1.Type.Option( - declarative_asn1.AnnotatedType( - rust_choice_type, declarative_asn1.Annotation() - ) - ) - if NoneType in union_args - else rust_choice_type - ) - - elif typing.get_origin(field_type) is builtins.list: - inner_type = _normalize_field_type( - typing.get_args(field_type)[0], field_name - ) - rust_field_type = declarative_asn1.Type.SequenceOf(inner_type) - elif typing.get_origin(field_type) is SetOf: - inner_type = _normalize_field_type( - typing.get_args(field_type)[0], field_name - ) - rust_field_type = declarative_asn1.Type.SetOf(inner_type) - else: - rust_field_type = declarative_asn1.non_root_python_to_rust(field_type) - - return declarative_asn1.AnnotatedType(rust_field_type, annotation) - - -# Convert a type to a Variant. Used with types inside Union -# annotations (T1, T2, etc in `Union[T1, T2, ...]`). -def _type_to_variant( - t: typing.Any, field_name: str -) -> declarative_asn1.Variant: - is_annotated = typing.get_origin(t) is typing.Annotated - inner_type = typing.get_args(t)[0] if is_annotated else t - - # Check if this is a Variant[T, Tag] type - if typing.get_origin(inner_type) is Variant: - value_type, tag_literal = typing.get_args(inner_type) - if typing.get_origin(tag_literal) is not typing.Literal: - raise TypeError( - "When using `asn1.Variant` in a type annotation, the second " - "type parameter must be a `typing.Literal` type. E.g: " - '`Variant[int, typing.Literal["MyInt"]]`.' - ) - tag_name = typing.get_args(tag_literal)[0] - - if hasattr(value_type, "__asn1_root__"): - rust_type = value_type.__asn1_root__ - else: - rust_type = declarative_asn1.non_root_python_to_rust(value_type) - - if is_annotated: - ann_type = declarative_asn1.AnnotatedType( - rust_type, - _extract_annotation(t.__metadata__, field_name), - ) - else: - ann_type = declarative_asn1.AnnotatedType( - rust_type, - declarative_asn1.Annotation(), - ) - - return declarative_asn1.Variant(Variant, ann_type, tag_name) - else: - # Plain type (not a tagged Variant) - return declarative_asn1.Variant( - inner_type, - _normalize_field_type(t, field_name), - None, - ) - - -def _annotate_fields( - raw_fields: dict[str, type], -) -> dict[str, declarative_asn1.AnnotatedType]: - fields = {} - for field_name, field_type in raw_fields.items(): - # Recursively normalize the field type into something that the - # Rust code can understand. - annotated_field_type = _normalize_field_type(field_type, field_name) - fields[field_name] = annotated_field_type - - return fields - - -def _register_asn1_sequence(cls: type[U]) -> None: - raw_fields = typing.get_type_hints(cls, include_extras=True) - root = declarative_asn1.Type.Sequence(cls, _annotate_fields(raw_fields)) - - setattr(cls, "__asn1_root__", root) - - -def _register_asn1_set(cls: type[U]) -> None: - raw_fields = typing.get_type_hints(cls, include_extras=True) - root = declarative_asn1.Type.Set(cls, _annotate_fields(raw_fields)) - - setattr(cls, "__asn1_root__", root) - - -# Due to https://github.com/python/mypy/issues/19731, we can't define an alias -# for `dataclass_transform` that conditionally points to `typing` or -# `typing_extensions` depending on the Python version. We work around it by -# making the whole decorated class conditional on the Python version. -if sys.version_info < (3, 11): - - @typing_extensions.dataclass_transform(kw_only_default=True) - def sequence(cls: type[U]) -> type[U]: - # We use `dataclasses.dataclass` to add an __init__ method - # to the class with keyword-only parameters. - if sys.version_info >= (3, 10): - dataclass_cls = dataclasses.dataclass( - repr=False, - eq=False, - # `match_args` was added in Python 3.10 and defaults - # to True - match_args=False, - # `kw_only` was added in Python 3.10 and defaults to - # False - kw_only=True, - )(cls) - else: - dataclass_cls = dataclasses.dataclass( - repr=False, - eq=False, - )(cls) - _register_asn1_sequence(dataclass_cls) - return dataclass_cls - - @typing_extensions.dataclass_transform(kw_only_default=True) - def set(cls: type[U]) -> type[U]: - # We use `dataclasses.dataclass` to add an __init__ method - # to the class with keyword-only parameters. - if sys.version_info >= (3, 10): - dataclass_cls = dataclasses.dataclass( - repr=False, - eq=False, - # `match_args` was added in Python 3.10 and defaults - # to True - match_args=False, - # `kw_only` was added in Python 3.10 and defaults to - # False - kw_only=True, - )(cls) - else: - dataclass_cls = dataclasses.dataclass( - repr=False, - eq=False, - )(cls) - _register_asn1_set(dataclass_cls) - return dataclass_cls - -else: - - @typing.dataclass_transform(kw_only_default=True) - def sequence(cls: type[U]) -> type[U]: - # Only add an __init__ method, with keyword-only - # parameters. - dataclass_cls = dataclasses.dataclass( - repr=False, - eq=False, - match_args=False, - kw_only=True, - )(cls) - _register_asn1_sequence(dataclass_cls) - return dataclass_cls - - @typing.dataclass_transform(kw_only_default=True) - def set(cls: type[U]) -> type[U]: - # Only add an __init__ method, with keyword-only - # parameters. - dataclass_cls = dataclasses.dataclass( - repr=False, - eq=False, - match_args=False, - kw_only=True, - )(cls) - _register_asn1_set(dataclass_cls) - return dataclass_cls - - -# TODO: replace with `Default[U]` once the min Python version is >= 3.12 -@dataclasses.dataclass(frozen=True) -class Default(typing.Generic[U]): - value: U - - -SetOf = declarative_asn1.SetOf - -Explicit = declarative_asn1.Encoding.Explicit -Implicit = declarative_asn1.Encoding.Implicit -Size = declarative_asn1.Size - -PrintableString = declarative_asn1.PrintableString -IA5String = declarative_asn1.IA5String -UTCTime = declarative_asn1.UTCTime -GeneralizedTime = declarative_asn1.GeneralizedTime -BitString = declarative_asn1.BitString -TLV = declarative_asn1.Tlv -Null = declarative_asn1.Null diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/backends/__init__.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/backends/__init__.py deleted file mode 100644 index b4400aa..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/backends/__init__.py +++ /dev/null @@ -1,13 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -from typing import Any - - -def default_backend() -> Any: - from cryptography.hazmat.backends.openssl.backend import backend - - return backend diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/backends/openssl/__init__.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/backends/openssl/__init__.py deleted file mode 100644 index 51b0447..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/backends/openssl/__init__.py +++ /dev/null @@ -1,9 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -from cryptography.hazmat.backends.openssl.backend import backend - -__all__ = ["backend"] diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/backends/openssl/backend.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/backends/openssl/backend.py deleted file mode 100644 index ad64a2a..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/backends/openssl/backend.py +++ /dev/null @@ -1,312 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -from cryptography.hazmat.bindings._rust import openssl as rust_openssl -from cryptography.hazmat.bindings.openssl import binding -from cryptography.hazmat.primitives import hashes -from cryptography.hazmat.primitives._asymmetric import AsymmetricPadding -from cryptography.hazmat.primitives.asymmetric import ec -from cryptography.hazmat.primitives.asymmetric import utils as asym_utils -from cryptography.hazmat.primitives.asymmetric.padding import ( - MGF1, - OAEP, - PSS, - PKCS1v15, -) -from cryptography.hazmat.primitives.ciphers import ( - CipherAlgorithm, -) -from cryptography.hazmat.primitives.ciphers.algorithms import ( - AES, -) -from cryptography.hazmat.primitives.ciphers.modes import ( - CBC, - Mode, -) - - -class Backend: - """ - OpenSSL API binding interfaces. - """ - - name = "openssl" - - # TripleDES encryption is disallowed/deprecated throughout 2023 in - # FIPS 140-3. To keep it simple we denylist any use of TripleDES (TDEA). - _fips_ciphers = (AES,) - # Sometimes SHA1 is still permissible. That logic is contained - # within the various *_supported methods. - _fips_hashes = ( - hashes.SHA224, - hashes.SHA256, - hashes.SHA384, - hashes.SHA512, - hashes.SHA512_224, - hashes.SHA512_256, - hashes.SHA3_224, - hashes.SHA3_256, - hashes.SHA3_384, - hashes.SHA3_512, - hashes.SHAKE128, - hashes.SHAKE256, - ) - _fips_ecdh_curves = ( - ec.SECP224R1, - ec.SECP256R1, - ec.SECP384R1, - ec.SECP521R1, - ) - _fips_rsa_min_key_size = 2048 - _fips_rsa_min_public_exponent = 65537 - _fips_dsa_min_modulus = 1 << 2048 - _fips_dh_min_key_size = 2048 - _fips_dh_min_modulus = 1 << _fips_dh_min_key_size - - def __init__(self) -> None: - self._binding = binding.Binding() - self._ffi = self._binding.ffi - self._lib = self._binding.lib - self._fips_enabled = rust_openssl.is_fips_enabled() - - def __repr__(self) -> str: - return ( - f"" - ) - - def openssl_assert(self, ok: bool) -> None: - return binding._openssl_assert(ok) - - def _enable_fips(self) -> None: - # This function enables FIPS mode for OpenSSL 3.0.0 on installs that - # have the FIPS provider installed properly. - rust_openssl.enable_fips(rust_openssl._providers) - assert rust_openssl.is_fips_enabled() - self._fips_enabled = rust_openssl.is_fips_enabled() - - def openssl_version_text(self) -> str: - """ - Friendly string name of the loaded OpenSSL library. This is not - necessarily the same version as it was compiled against. - - Example: OpenSSL 3.2.1 30 Jan 2024 - """ - return rust_openssl.openssl_version_text() - - def openssl_version_number(self) -> int: - return rust_openssl.openssl_version() - - def hash_supported(self, algorithm: hashes.HashAlgorithm) -> bool: - if self._fips_enabled and not isinstance(algorithm, self._fips_hashes): - return False - - return rust_openssl.hashes.hash_supported(algorithm) - - def signature_hash_supported( - self, algorithm: hashes.HashAlgorithm - ) -> bool: - # Dedicated check for hashing algorithm use in message digest for - # signatures, e.g. RSA PKCS#1 v1.5 SHA1 (sha1WithRSAEncryption). - if self._fips_enabled and isinstance(algorithm, hashes.SHA1): - return False - return self.hash_supported(algorithm) - - def scrypt_supported(self) -> bool: - if self._fips_enabled: - return False - else: - return hasattr(rust_openssl.kdf.Scrypt, "derive") - - def argon2_supported(self) -> bool: - if self._fips_enabled: - return False - else: - return hasattr(rust_openssl.kdf.Argon2id, "derive") - - def hmac_supported(self, algorithm: hashes.HashAlgorithm) -> bool: - # FIPS mode still allows SHA1 for HMAC - if self._fips_enabled and isinstance(algorithm, hashes.SHA1): - return True - if rust_openssl.CRYPTOGRAPHY_IS_AWSLC: - return isinstance( - algorithm, - ( - hashes.MD5, - hashes.SHA1, - hashes.SHA224, - hashes.SHA256, - hashes.SHA384, - hashes.SHA512, - hashes.SHA512_224, - hashes.SHA512_256, - ), - ) - return self.hash_supported(algorithm) - - def cipher_supported(self, cipher: CipherAlgorithm, mode: Mode) -> bool: - if self._fips_enabled: - # FIPS mode requires AES. TripleDES is disallowed/deprecated in - # FIPS 140-3. - if not isinstance(cipher, self._fips_ciphers): - return False - - return rust_openssl.ciphers.cipher_supported(cipher, mode) - - def pbkdf2_hmac_supported(self, algorithm: hashes.HashAlgorithm) -> bool: - return self.hmac_supported(algorithm) - - def _consume_errors(self) -> list[rust_openssl.OpenSSLError]: - return rust_openssl.capture_error_stack() - - def _oaep_hash_supported(self, algorithm: hashes.HashAlgorithm) -> bool: - if self._fips_enabled and isinstance(algorithm, hashes.SHA1): - return False - - return isinstance( - algorithm, - ( - hashes.SHA1, - hashes.SHA224, - hashes.SHA256, - hashes.SHA384, - hashes.SHA512, - ), - ) - - def rsa_padding_supported(self, padding: AsymmetricPadding) -> bool: - if isinstance(padding, PKCS1v15): - return True - elif isinstance(padding, PSS) and isinstance(padding._mgf, MGF1): - # FIPS 186-4 only allows salt length == digest length for PSS - # It is technically acceptable to set an explicit salt length - # equal to the digest length and this will incorrectly fail, but - # since we don't do that in the tests and this method is - # private, we'll ignore that until we need to do otherwise. - if ( - self._fips_enabled - and padding._salt_length != PSS.DIGEST_LENGTH - ): - return False - return self.hash_supported(padding._mgf._algorithm) - elif isinstance(padding, OAEP) and isinstance(padding._mgf, MGF1): - return self._oaep_hash_supported( - padding._mgf._algorithm - ) and self._oaep_hash_supported(padding._algorithm) - else: - return False - - def rsa_encryption_supported(self, padding: AsymmetricPadding) -> bool: - if self._fips_enabled and isinstance(padding, PKCS1v15): - return False - else: - return self.rsa_padding_supported(padding) - - def dsa_supported(self) -> bool: - return ( - not rust_openssl.CRYPTOGRAPHY_IS_BORINGSSL - and not self._fips_enabled - ) - - def dsa_hash_supported(self, algorithm: hashes.HashAlgorithm) -> bool: - if not self.dsa_supported(): - return False - return self.signature_hash_supported(algorithm) - - def cmac_algorithm_supported(self, algorithm) -> bool: - return self.cipher_supported( - algorithm, CBC(b"\x00" * algorithm.block_size) - ) - - def elliptic_curve_supported(self, curve: ec.EllipticCurve) -> bool: - if self._fips_enabled and not isinstance( - curve, self._fips_ecdh_curves - ): - return False - - return rust_openssl.ec.curve_supported(curve) - - def elliptic_curve_signature_algorithm_supported( - self, - signature_algorithm: ec.EllipticCurveSignatureAlgorithm, - curve: ec.EllipticCurve, - ) -> bool: - # We only support ECDSA right now. - if not isinstance(signature_algorithm, ec.ECDSA): - return False - - return self.elliptic_curve_supported(curve) and ( - isinstance(signature_algorithm.algorithm, asym_utils.Prehashed) - or self.hash_supported(signature_algorithm.algorithm) - ) - - def elliptic_curve_exchange_algorithm_supported( - self, algorithm: ec.ECDH, curve: ec.EllipticCurve - ) -> bool: - return self.elliptic_curve_supported(curve) and isinstance( - algorithm, ec.ECDH - ) - - def dh_supported(self) -> bool: - return ( - not rust_openssl.CRYPTOGRAPHY_IS_BORINGSSL - and not rust_openssl.CRYPTOGRAPHY_IS_AWSLC - ) - - def dh_x942_serialization_supported(self) -> bool: - return self._lib.Cryptography_HAS_EVP_PKEY_DHX == 1 - - def x25519_supported(self) -> bool: - return not self._fips_enabled - - def x448_supported(self) -> bool: - if self._fips_enabled: - return False - return ( - not rust_openssl.CRYPTOGRAPHY_IS_LIBRESSL - and not rust_openssl.CRYPTOGRAPHY_IS_BORINGSSL - and not rust_openssl.CRYPTOGRAPHY_IS_AWSLC - ) - - def mlkem_supported(self) -> bool: - return ( - rust_openssl.CRYPTOGRAPHY_IS_AWSLC - or rust_openssl.CRYPTOGRAPHY_IS_BORINGSSL - or rust_openssl.CRYPTOGRAPHY_OPENSSL_350_OR_GREATER - ) - - def mldsa_supported(self) -> bool: - return ( - rust_openssl.CRYPTOGRAPHY_IS_AWSLC - or rust_openssl.CRYPTOGRAPHY_IS_BORINGSSL - or rust_openssl.CRYPTOGRAPHY_OPENSSL_350_OR_GREATER - ) - - def ed25519_supported(self) -> bool: - return True - - def ed448_supported(self) -> bool: - return ( - not rust_openssl.CRYPTOGRAPHY_IS_LIBRESSL - and not rust_openssl.CRYPTOGRAPHY_IS_BORINGSSL - and not rust_openssl.CRYPTOGRAPHY_IS_AWSLC - ) - - def ecdsa_deterministic_supported(self) -> bool: - return ( - rust_openssl.CRYPTOGRAPHY_OPENSSL_320_OR_GREATER - and not self._fips_enabled - ) - - def poly1305_supported(self) -> bool: - return not self._fips_enabled - - def pkcs7_supported(self) -> bool: - return True - - -backend = Backend() diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/__init__.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/__init__.py deleted file mode 100644 index b509336..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust.abi3.so b/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust.abi3.so deleted file mode 100755 index 2ab847a..0000000 Binary files a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust.abi3.so and /dev/null differ diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/__init__.pyi b/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/__init__.pyi deleted file mode 100644 index c3148f1..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/__init__.pyi +++ /dev/null @@ -1,67 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -import typing - -from cryptography.hazmat.primitives import padding -from cryptography.hazmat.primitives._serialization import ( - KeySerializationEncryptionBuilder, -) -from cryptography.utils import Buffer - -class PKCS7PaddingContext(padding.PaddingContext): - def __init__(self, block_size: int) -> None: ... - def update(self, data: Buffer) -> bytes: ... - def finalize(self) -> bytes: ... - -class ANSIX923PaddingContext(padding.PaddingContext): - def __init__(self, block_size: int) -> None: ... - def update(self, data: Buffer) -> bytes: ... - def finalize(self) -> bytes: ... - -class PKCS7UnpaddingContext(padding.PaddingContext): - def __init__(self, block_size: int) -> None: ... - def update(self, data: Buffer) -> bytes: ... - def finalize(self) -> bytes: ... - -class ANSIX923UnpaddingContext(padding.PaddingContext): - def __init__(self, block_size: int) -> None: ... - def update(self, data: Buffer) -> bytes: ... - def finalize(self) -> bytes: ... - -class Encoding: - PEM: typing.ClassVar[Encoding] - DER: typing.ClassVar[Encoding] - OpenSSH: typing.ClassVar[Encoding] - Raw: typing.ClassVar[Encoding] - X962: typing.ClassVar[Encoding] - SMIME: typing.ClassVar[Encoding] - -class PrivateFormat: - PKCS8: typing.ClassVar[PrivateFormat] - TraditionalOpenSSL: typing.ClassVar[PrivateFormat] - Raw: typing.ClassVar[PrivateFormat] - OpenSSH: typing.ClassVar[PrivateFormat] - PKCS12: typing.ClassVar[PrivateFormat] - def encryption_builder(self) -> KeySerializationEncryptionBuilder: ... - -class PublicFormat: - SubjectPublicKeyInfo: typing.ClassVar[PublicFormat] - PKCS1: typing.ClassVar[PublicFormat] - OpenSSH: typing.ClassVar[PublicFormat] - Raw: typing.ClassVar[PublicFormat] - CompressedPoint: typing.ClassVar[PublicFormat] - UncompressedPoint: typing.ClassVar[PublicFormat] - -class ParameterFormat: - PKCS3: typing.ClassVar[ParameterFormat] - -class ObjectIdentifier: - def __init__(self, value: str) -> None: ... - @property - def dotted_string(self) -> str: ... - @property - def _name(self) -> str: ... - -T = typing.TypeVar("T") diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/_openssl.pyi b/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/_openssl.pyi deleted file mode 100644 index 3d4ea4e..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/_openssl.pyi +++ /dev/null @@ -1,8 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -import typing - -lib: typing.Any -ffi: typing.Any diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/asn1.pyi b/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/asn1.pyi deleted file mode 100644 index 3b5f208..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/asn1.pyi +++ /dev/null @@ -1,7 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -def decode_dss_signature(signature: bytes) -> tuple[int, int]: ... -def encode_dss_signature(r: int, s: int) -> bytes: ... -def parse_spki_for_data(data: bytes) -> bytes: ... diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/declarative_asn1.pyi b/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/declarative_asn1.pyi deleted file mode 100644 index a4c0cb6..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/declarative_asn1.pyi +++ /dev/null @@ -1,127 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -import datetime -import typing - -def decode_der(cls: type, value: bytes) -> typing.Any: ... -def encode_der(value: typing.Any) -> bytes: ... -def non_root_python_to_rust(cls: type) -> Type: ... - -# Type is a Rust enum with tuple variants. For now, we express the type -# annotations like this: -class Type: - Sequence: typing.ClassVar[type] - SequenceOf: typing.ClassVar[type] - Set: typing.ClassVar[type] - SetOf: typing.ClassVar[type] - Option: typing.ClassVar[type] - Choice: typing.ClassVar[type] - PyBool: typing.ClassVar[type] - PyInt: typing.ClassVar[type] - PyBytes: typing.ClassVar[type] - PyStr: typing.ClassVar[type] - -class Annotation: - default: typing.Any | None - encoding: Encoding | None - size: Size | None - def __new__( - cls, - default: typing.Any | None = None, - encoding: Encoding | None = None, - size: Size | None = None, - ) -> Annotation: ... - def is_empty(self) -> bool: ... - -# Encoding is a Rust enum with tuple variants. For now, we express the type -# annotations like this: -class Encoding: - Implicit: typing.ClassVar[type] - Explicit: typing.ClassVar[type] - -class Size: - min: int - max: int | None - - def __new__(cls, min: int, max: int | None) -> Size: ... - @staticmethod - def exact(n: int) -> Size: ... - -class AnnotatedType: - inner: Type - annotation: Annotation - - def __new__(cls, inner: Type, annotation: Annotation) -> AnnotatedType: ... - -class AnnotatedTypeObject: - annotated_type: AnnotatedType - value: typing.Any - - def __new__( - cls, annotated_type: AnnotatedType, value: typing.Any - ) -> AnnotatedTypeObject: ... - -class Variant: - python_class: type - ann_type: AnnotatedType - tag_name: str | None - - def __new__( - cls, - python_class: type, - ann_type: AnnotatedType, - tag_name: str | None, - ) -> Variant: ... - -class PrintableString: - def __new__(cls, inner: str) -> PrintableString: ... - def __repr__(self) -> str: ... - def __eq__(self, other: object) -> bool: ... - def as_str(self) -> str: ... - -class IA5String: - def __new__(cls, inner: str) -> IA5String: ... - def __repr__(self) -> str: ... - def __eq__(self, other: object) -> bool: ... - def as_str(self) -> str: ... - -class UTCTime: - def __new__(cls, inner: datetime.datetime) -> UTCTime: ... - def __repr__(self) -> str: ... - def __eq__(self, other: object) -> bool: ... - def as_datetime(self) -> datetime.datetime: ... - -class GeneralizedTime: - def __new__(cls, inner: datetime.datetime) -> GeneralizedTime: ... - def __repr__(self) -> str: ... - def __eq__(self, other: object) -> bool: ... - def as_datetime(self) -> datetime.datetime: ... - -class BitString: - def __new__(cls, data: bytes, padding_bits: int) -> BitString: ... - def __repr__(self) -> str: ... - def __eq__(self, other: object) -> bool: ... - def as_bytes(self) -> bytes: ... - def padding_bits(self) -> int: ... - -class Tlv: - @property - def tag_bytes(self) -> bytes: ... - @property - def data(self) -> memoryview: ... - def parse(self, cls: type): ... - -T = typing.TypeVar("T") - -class SetOf(typing.Generic[T]): - def __new__(cls, inner: list[T]) -> SetOf[T]: ... - def as_list(self) -> list[T]: ... - def __eq__(self, other: object) -> bool: ... - def __repr__(self) -> str: ... - -class Null: - def __new__(cls) -> Null: ... - def __repr__(self) -> str: ... - def __eq__(self, other: object) -> bool: ... diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/exceptions.pyi b/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/exceptions.pyi deleted file mode 100644 index 09f46b1..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/exceptions.pyi +++ /dev/null @@ -1,17 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -class _Reasons: - BACKEND_MISSING_INTERFACE: _Reasons - UNSUPPORTED_HASH: _Reasons - UNSUPPORTED_CIPHER: _Reasons - UNSUPPORTED_PADDING: _Reasons - UNSUPPORTED_MGF: _Reasons - UNSUPPORTED_PUBLIC_KEY_ALGORITHM: _Reasons - UNSUPPORTED_ELLIPTIC_CURVE: _Reasons - UNSUPPORTED_SERIALIZATION: _Reasons - UNSUPPORTED_X509: _Reasons - UNSUPPORTED_EXCHANGE_ALGORITHM: _Reasons - UNSUPPORTED_DIFFIE_HELLMAN: _Reasons - UNSUPPORTED_MAC: _Reasons diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/ocsp.pyi b/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/ocsp.pyi deleted file mode 100644 index 103e96c..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/ocsp.pyi +++ /dev/null @@ -1,117 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -import datetime -from collections.abc import Iterator - -from cryptography import x509 -from cryptography.hazmat.primitives import hashes, serialization -from cryptography.hazmat.primitives.asymmetric.types import PrivateKeyTypes -from cryptography.x509 import ocsp - -class OCSPRequest: - @property - def issuer_key_hash(self) -> bytes: ... - @property - def issuer_name_hash(self) -> bytes: ... - @property - def hash_algorithm(self) -> hashes.HashAlgorithm: ... - @property - def serial_number(self) -> int: ... - def public_bytes(self, encoding: serialization.Encoding) -> bytes: ... - @property - def extensions(self) -> x509.Extensions: ... - -class OCSPResponse: - @property - def responses(self) -> Iterator[OCSPSingleResponse]: ... - @property - def response_status(self) -> ocsp.OCSPResponseStatus: ... - @property - def signature_algorithm_oid(self) -> x509.ObjectIdentifier: ... - @property - def signature_hash_algorithm( - self, - ) -> hashes.HashAlgorithm | None: ... - @property - def signature(self) -> bytes: ... - @property - def tbs_response_bytes(self) -> bytes: ... - @property - def certificates(self) -> list[x509.Certificate]: ... - @property - def responder_key_hash(self) -> bytes | None: ... - @property - def responder_name(self) -> x509.Name | None: ... - @property - def produced_at(self) -> datetime.datetime: ... - @property - def produced_at_utc(self) -> datetime.datetime: ... - @property - def certificate_status(self) -> ocsp.OCSPCertStatus: ... - @property - def revocation_time(self) -> datetime.datetime | None: ... - @property - def revocation_time_utc(self) -> datetime.datetime | None: ... - @property - def revocation_reason(self) -> x509.ReasonFlags | None: ... - @property - def this_update(self) -> datetime.datetime: ... - @property - def this_update_utc(self) -> datetime.datetime: ... - @property - def next_update(self) -> datetime.datetime | None: ... - @property - def next_update_utc(self) -> datetime.datetime | None: ... - @property - def issuer_key_hash(self) -> bytes: ... - @property - def issuer_name_hash(self) -> bytes: ... - @property - def hash_algorithm(self) -> hashes.HashAlgorithm: ... - @property - def serial_number(self) -> int: ... - @property - def extensions(self) -> x509.Extensions: ... - @property - def single_extensions(self) -> x509.Extensions: ... - def public_bytes(self, encoding: serialization.Encoding) -> bytes: ... - -class OCSPSingleResponse: - @property - def certificate_status(self) -> ocsp.OCSPCertStatus: ... - @property - def revocation_time(self) -> datetime.datetime | None: ... - @property - def revocation_time_utc(self) -> datetime.datetime | None: ... - @property - def revocation_reason(self) -> x509.ReasonFlags | None: ... - @property - def this_update(self) -> datetime.datetime: ... - @property - def this_update_utc(self) -> datetime.datetime: ... - @property - def next_update(self) -> datetime.datetime | None: ... - @property - def next_update_utc(self) -> datetime.datetime | None: ... - @property - def issuer_key_hash(self) -> bytes: ... - @property - def issuer_name_hash(self) -> bytes: ... - @property - def hash_algorithm(self) -> hashes.HashAlgorithm: ... - @property - def serial_number(self) -> int: ... - -def load_der_ocsp_request(data: bytes) -> ocsp.OCSPRequest: ... -def load_der_ocsp_response(data: bytes) -> ocsp.OCSPResponse: ... -def create_ocsp_request( - builder: ocsp.OCSPRequestBuilder, -) -> ocsp.OCSPRequest: ... -def create_ocsp_response( - status: ocsp.OCSPResponseStatus, - builder: ocsp.OCSPResponseBuilder | None, - private_key: PrivateKeyTypes | None, - hash_algorithm: hashes.HashAlgorithm | None, -) -> ocsp.OCSPResponse: ... diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/__init__.pyi b/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/__init__.pyi deleted file mode 100644 index 404a300..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/__init__.pyi +++ /dev/null @@ -1,80 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -import typing - -from cryptography.hazmat.bindings._rust.openssl import ( - aead, - ciphers, - cmac, - dh, - dsa, - ec, - ed448, - ed25519, - hashes, - hmac, - hpke, - kdf, - keys, - mldsa, - mlkem, - poly1305, - rsa, - x448, - x25519, -) - -__all__ = [ - "aead", - "ciphers", - "cmac", - "dh", - "dsa", - "ec", - "ed448", - "ed25519", - "hashes", - "hmac", - "hpke", - "kdf", - "keys", - "mldsa", - "mlkem", - "openssl_version", - "openssl_version_text", - "poly1305", - "raise_openssl_error", - "rsa", - "x448", - "x25519", -] - -CRYPTOGRAPHY_IS_LIBRESSL: bool -CRYPTOGRAPHY_IS_BORINGSSL: bool -CRYPTOGRAPHY_IS_AWSLC: bool -CRYPTOGRAPHY_OPENSSL_309_OR_GREATER: bool -CRYPTOGRAPHY_OPENSSL_320_OR_GREATER: bool -CRYPTOGRAPHY_OPENSSL_330_OR_GREATER: bool -CRYPTOGRAPHY_OPENSSL_350_OR_GREATER: bool - -class Providers: ... - -_legacy_provider_loaded: bool -_providers: Providers - -def openssl_version() -> int: ... -def openssl_version_text() -> str: ... -def raise_openssl_error() -> typing.NoReturn: ... -def capture_error_stack() -> list[OpenSSLError]: ... -def is_fips_enabled() -> bool: ... -def enable_fips(providers: Providers) -> None: ... - -class OpenSSLError: - @property - def lib(self) -> int: ... - @property - def reason(self) -> int: ... - @property - def reason_text(self) -> bytes: ... diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/aead.pyi b/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/aead.pyi deleted file mode 100644 index eb44608..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/aead.pyi +++ /dev/null @@ -1,189 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from collections.abc import Sequence - -from cryptography.utils import Buffer - -class AESGCM: - def __init__(self, key: Buffer) -> None: ... - @staticmethod - def generate_key(bit_length: int) -> bytes: ... - def encrypt( - self, - nonce: Buffer, - data: Buffer, - associated_data: Buffer | None, - ) -> bytes: ... - def decrypt( - self, - nonce: Buffer, - data: Buffer, - associated_data: Buffer | None, - ) -> bytes: ... - def encrypt_into( - self, - nonce: Buffer, - data: Buffer, - associated_data: Buffer | None, - buf: Buffer, - ) -> int: ... - def decrypt_into( - self, - nonce: Buffer, - data: Buffer, - associated_data: Buffer | None, - buf: Buffer, - ) -> int: ... - -class ChaCha20Poly1305: - def __init__(self, key: Buffer) -> None: ... - @staticmethod - def generate_key() -> bytes: ... - def encrypt( - self, - nonce: Buffer, - data: Buffer, - associated_data: Buffer | None, - ) -> bytes: ... - def encrypt_into( - self, - nonce: Buffer, - data: Buffer, - associated_data: Buffer | None, - buf: Buffer, - ) -> int: ... - def decrypt( - self, - nonce: Buffer, - data: Buffer, - associated_data: Buffer | None, - ) -> bytes: ... - def decrypt_into( - self, - nonce: Buffer, - data: Buffer, - associated_data: Buffer | None, - buf: Buffer, - ) -> int: ... - -class AESCCM: - def __init__(self, key: Buffer, tag_length: int = 16) -> None: ... - @staticmethod - def generate_key(bit_length: int) -> bytes: ... - def encrypt( - self, - nonce: Buffer, - data: Buffer, - associated_data: Buffer | None, - ) -> bytes: ... - def encrypt_into( - self, - nonce: Buffer, - data: Buffer, - associated_data: Buffer | None, - buf: Buffer, - ) -> int: ... - def decrypt( - self, - nonce: Buffer, - data: Buffer, - associated_data: Buffer | None, - ) -> bytes: ... - def decrypt_into( - self, - nonce: Buffer, - data: Buffer, - associated_data: Buffer | None, - buf: Buffer, - ) -> int: ... - -class AESSIV: - def __init__(self, key: Buffer) -> None: ... - @staticmethod - def generate_key(bit_length: int) -> bytes: ... - def encrypt( - self, - data: Buffer, - associated_data: Sequence[Buffer] | None, - ) -> bytes: ... - def encrypt_into( - self, - data: Buffer, - associated_data: Sequence[Buffer] | None, - buf: Buffer, - ) -> int: ... - def decrypt( - self, - data: Buffer, - associated_data: Sequence[Buffer] | None, - ) -> bytes: ... - def decrypt_into( - self, - data: Buffer, - associated_data: Sequence[Buffer] | None, - buf: Buffer, - ) -> int: ... - -class AESOCB3: - def __init__(self, key: Buffer) -> None: ... - @staticmethod - def generate_key(bit_length: int) -> bytes: ... - def encrypt( - self, - nonce: Buffer, - data: Buffer, - associated_data: Buffer | None, - ) -> bytes: ... - def encrypt_into( - self, - nonce: Buffer, - data: Buffer, - associated_data: Buffer | None, - buf: Buffer, - ) -> int: ... - def decrypt( - self, - nonce: Buffer, - data: Buffer, - associated_data: Buffer | None, - ) -> bytes: ... - def decrypt_into( - self, - nonce: Buffer, - data: Buffer, - associated_data: Buffer | None, - buf: Buffer, - ) -> int: ... - -class AESGCMSIV: - def __init__(self, key: Buffer) -> None: ... - @staticmethod - def generate_key(bit_length: int) -> bytes: ... - def encrypt( - self, - nonce: Buffer, - data: Buffer, - associated_data: Buffer | None, - ) -> bytes: ... - def encrypt_into( - self, - nonce: Buffer, - data: Buffer, - associated_data: Buffer | None, - buf: Buffer, - ) -> int: ... - def decrypt( - self, - nonce: Buffer, - data: Buffer, - associated_data: Buffer | None, - ) -> bytes: ... - def decrypt_into( - self, - nonce: Buffer, - data: Buffer, - associated_data: Buffer | None, - buf: Buffer, - ) -> int: ... diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/ciphers.pyi b/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/ciphers.pyi deleted file mode 100644 index a48fb01..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/ciphers.pyi +++ /dev/null @@ -1,38 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -import typing - -from cryptography.hazmat.primitives import ciphers -from cryptography.hazmat.primitives.ciphers import modes - -@typing.overload -def create_encryption_ctx( - algorithm: ciphers.CipherAlgorithm, mode: modes.ModeWithAuthenticationTag -) -> ciphers.AEADEncryptionContext: ... -@typing.overload -def create_encryption_ctx( - algorithm: ciphers.CipherAlgorithm, mode: modes.Mode | None -) -> ciphers.CipherContext: ... -@typing.overload -def create_decryption_ctx( - algorithm: ciphers.CipherAlgorithm, mode: modes.ModeWithAuthenticationTag -) -> ciphers.AEADDecryptionContext: ... -@typing.overload -def create_decryption_ctx( - algorithm: ciphers.CipherAlgorithm, mode: modes.Mode | None -) -> ciphers.CipherContext: ... -def cipher_supported( - algorithm: ciphers.CipherAlgorithm, mode: modes.Mode -) -> bool: ... -def _advance( - ctx: ciphers.AEADEncryptionContext | ciphers.AEADDecryptionContext, n: int -) -> None: ... -def _advance_aad( - ctx: ciphers.AEADEncryptionContext | ciphers.AEADDecryptionContext, n: int -) -> None: ... - -class CipherContext: ... -class AEADEncryptionContext: ... -class AEADDecryptionContext: ... diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/cmac.pyi b/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/cmac.pyi deleted file mode 100644 index 9c03508..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/cmac.pyi +++ /dev/null @@ -1,18 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -import typing - -from cryptography.hazmat.primitives import ciphers - -class CMAC: - def __init__( - self, - algorithm: ciphers.BlockCipherAlgorithm, - backend: typing.Any = None, - ) -> None: ... - def update(self, data: bytes) -> None: ... - def finalize(self) -> bytes: ... - def verify(self, signature: bytes) -> None: ... - def copy(self) -> CMAC: ... diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/dh.pyi b/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/dh.pyi deleted file mode 100644 index 08733d7..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/dh.pyi +++ /dev/null @@ -1,51 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -import typing - -from cryptography.hazmat.primitives.asymmetric import dh - -MIN_MODULUS_SIZE: int - -class DHPrivateKey: ... -class DHPublicKey: ... -class DHParameters: ... - -class DHPrivateNumbers: - def __init__(self, x: int, public_numbers: DHPublicNumbers) -> None: ... - def private_key(self, backend: typing.Any = None) -> dh.DHPrivateKey: ... - @property - def x(self) -> int: ... - @property - def public_numbers(self) -> DHPublicNumbers: ... - -class DHPublicNumbers: - def __init__( - self, y: int, parameter_numbers: DHParameterNumbers - ) -> None: ... - def public_key(self, backend: typing.Any = None) -> dh.DHPublicKey: ... - @property - def y(self) -> int: ... - @property - def parameter_numbers(self) -> DHParameterNumbers: ... - -class DHParameterNumbers: - def __init__(self, p: int, g: int, q: int | None = None) -> None: ... - def parameters(self, backend: typing.Any = None) -> dh.DHParameters: ... - @property - def p(self) -> int: ... - @property - def g(self) -> int: ... - @property - def q(self) -> int | None: ... - -def generate_parameters( - generator: int, key_size: int, backend: typing.Any = None -) -> dh.DHParameters: ... -def from_pem_parameters( - data: bytes, backend: typing.Any = None -) -> dh.DHParameters: ... -def from_der_parameters( - data: bytes, backend: typing.Any = None -) -> dh.DHParameters: ... diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/dsa.pyi b/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/dsa.pyi deleted file mode 100644 index 0922a4c..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/dsa.pyi +++ /dev/null @@ -1,41 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -import typing - -from cryptography.hazmat.primitives.asymmetric import dsa - -class DSAPrivateKey: ... -class DSAPublicKey: ... -class DSAParameters: ... - -class DSAPrivateNumbers: - def __init__(self, x: int, public_numbers: DSAPublicNumbers) -> None: ... - @property - def x(self) -> int: ... - @property - def public_numbers(self) -> DSAPublicNumbers: ... - def private_key(self, backend: typing.Any = None) -> dsa.DSAPrivateKey: ... - -class DSAPublicNumbers: - def __init__( - self, y: int, parameter_numbers: DSAParameterNumbers - ) -> None: ... - @property - def y(self) -> int: ... - @property - def parameter_numbers(self) -> DSAParameterNumbers: ... - def public_key(self, backend: typing.Any = None) -> dsa.DSAPublicKey: ... - -class DSAParameterNumbers: - def __init__(self, p: int, q: int, g: int) -> None: ... - @property - def p(self) -> int: ... - @property - def q(self) -> int: ... - @property - def g(self) -> int: ... - def parameters(self, backend: typing.Any = None) -> dsa.DSAParameters: ... - -def generate_parameters(key_size: int) -> dsa.DSAParameters: ... diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/ec.pyi b/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/ec.pyi deleted file mode 100644 index 5c3b7bf..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/ec.pyi +++ /dev/null @@ -1,52 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -import typing - -from cryptography.hazmat.primitives.asymmetric import ec - -class ECPrivateKey: ... -class ECPublicKey: ... - -class EllipticCurvePrivateNumbers: - def __init__( - self, private_value: int, public_numbers: EllipticCurvePublicNumbers - ) -> None: ... - def private_key( - self, backend: typing.Any = None - ) -> ec.EllipticCurvePrivateKey: ... - @property - def private_value(self) -> int: ... - @property - def public_numbers(self) -> EllipticCurvePublicNumbers: ... - -class EllipticCurvePublicNumbers: - def __init__(self, x: int, y: int, curve: ec.EllipticCurve) -> None: ... - def public_key( - self, backend: typing.Any = None - ) -> ec.EllipticCurvePublicKey: ... - @property - def x(self) -> int: ... - @property - def y(self) -> int: ... - @property - def curve(self) -> ec.EllipticCurve: ... - def __eq__(self, other: object) -> bool: ... - -def curve_supported(curve: ec.EllipticCurve) -> bool: ... -def generate_private_key( - curve: ec.EllipticCurve, backend: typing.Any = None -) -> ec.EllipticCurvePrivateKey: ... -def from_private_numbers( - numbers: ec.EllipticCurvePrivateNumbers, -) -> ec.EllipticCurvePrivateKey: ... -def from_public_numbers( - numbers: ec.EllipticCurvePublicNumbers, -) -> ec.EllipticCurvePublicKey: ... -def from_public_bytes( - curve: ec.EllipticCurve, data: bytes -) -> ec.EllipticCurvePublicKey: ... -def derive_private_key( - private_value: int, curve: ec.EllipticCurve -) -> ec.EllipticCurvePrivateKey: ... diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/ed25519.pyi b/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/ed25519.pyi deleted file mode 100644 index f85b3d1..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/ed25519.pyi +++ /dev/null @@ -1,13 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from cryptography.hazmat.primitives.asymmetric import ed25519 -from cryptography.utils import Buffer - -class Ed25519PrivateKey: ... -class Ed25519PublicKey: ... - -def generate_key() -> ed25519.Ed25519PrivateKey: ... -def from_private_bytes(data: Buffer) -> ed25519.Ed25519PrivateKey: ... -def from_public_bytes(data: bytes) -> ed25519.Ed25519PublicKey: ... diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/ed448.pyi b/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/ed448.pyi deleted file mode 100644 index c8ca0ec..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/ed448.pyi +++ /dev/null @@ -1,13 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from cryptography.hazmat.primitives.asymmetric import ed448 -from cryptography.utils import Buffer - -class Ed448PrivateKey: ... -class Ed448PublicKey: ... - -def generate_key() -> ed448.Ed448PrivateKey: ... -def from_private_bytes(data: Buffer) -> ed448.Ed448PrivateKey: ... -def from_public_bytes(data: bytes) -> ed448.Ed448PublicKey: ... diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/hashes.pyi b/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/hashes.pyi deleted file mode 100644 index 106b531..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/hashes.pyi +++ /dev/null @@ -1,30 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -import typing - -from cryptography.hazmat.primitives import hashes -from cryptography.utils import Buffer - -class Hash(hashes.HashContext): - def __init__( - self, algorithm: hashes.HashAlgorithm, backend: typing.Any = None - ) -> None: ... - @property - def algorithm(self) -> hashes.HashAlgorithm: ... - def update(self, data: Buffer) -> None: ... - def finalize(self) -> bytes: ... - def copy(self) -> Hash: ... - @staticmethod - def hash(algorithm: hashes.HashAlgorithm, data: Buffer) -> bytes: ... - -def hash_supported(algorithm: hashes.HashAlgorithm) -> bool: ... - -class XOFHash: - def __init__(self, algorithm: hashes.ExtendableOutputFunction) -> None: ... - @property - def algorithm(self) -> hashes.ExtendableOutputFunction: ... - def update(self, data: Buffer) -> None: ... - def squeeze(self, length: int) -> bytes: ... - def copy(self) -> XOFHash: ... diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/hmac.pyi b/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/hmac.pyi deleted file mode 100644 index 3883d1b..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/hmac.pyi +++ /dev/null @@ -1,22 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -import typing - -from cryptography.hazmat.primitives import hashes -from cryptography.utils import Buffer - -class HMAC(hashes.HashContext): - def __init__( - self, - key: Buffer, - algorithm: hashes.HashAlgorithm, - backend: typing.Any = None, - ) -> None: ... - @property - def algorithm(self) -> hashes.HashAlgorithm: ... - def update(self, data: Buffer) -> None: ... - def finalize(self) -> bytes: ... - def verify(self, signature: bytes) -> None: ... - def copy(self) -> HMAC: ... diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/hpke.pyi b/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/hpke.pyi deleted file mode 100644 index a9d8a11..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/hpke.pyi +++ /dev/null @@ -1,108 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from cryptography.hazmat.primitives.asymmetric import ec, mlkem, x25519 -from cryptography.utils import Buffer - -class KEM: - X25519: KEM - P256: KEM - P384: KEM - P521: KEM - MLKEM768: KEM - MLKEM1024: KEM - MLKEM768_X25519: KEM - MLKEM1024_P384: KEM - -class KDF: - HKDF_SHA256: KDF - HKDF_SHA384: KDF - HKDF_SHA512: KDF - SHAKE128: KDF - SHAKE256: KDF - -class AEAD: - AES_128_GCM: AEAD - AES_256_GCM: AEAD - CHACHA20_POLY1305: AEAD - -class MLKEM768X25519PrivateKey: - def __init__( - self, - mlkem_key: mlkem.MLKEM768PrivateKey, - x25519_key: x25519.X25519PrivateKey, - ) -> None: ... - def public_key(self) -> MLKEM768X25519PublicKey: ... - -class MLKEM768X25519PublicKey: - def __init__( - self, - mlkem_key: mlkem.MLKEM768PublicKey, - x25519_key: x25519.X25519PublicKey, - ) -> None: ... - -class MLKEM1024P384PrivateKey: - def __init__( - self, - mlkem_key: mlkem.MLKEM1024PrivateKey, - p384_key: ec.EllipticCurvePrivateKey, - ) -> None: ... - def public_key(self) -> MLKEM1024P384PublicKey: ... - -class MLKEM1024P384PublicKey: - def __init__( - self, - mlkem_key: mlkem.MLKEM1024PublicKey, - p384_key: ec.EllipticCurvePublicKey, - ) -> None: ... - -class Suite: - def __init__(self, kem: KEM, kdf: KDF, aead: AEAD) -> None: ... - def encrypt( - self, - plaintext: Buffer, - public_key: x25519.X25519PublicKey - | ec.EllipticCurvePublicKey - | mlkem.MLKEM768PublicKey - | mlkem.MLKEM1024PublicKey - | MLKEM768X25519PublicKey - | MLKEM1024P384PublicKey, - info: Buffer | None = None, - ) -> bytes: ... - def decrypt( - self, - ciphertext: Buffer, - private_key: x25519.X25519PrivateKey - | ec.EllipticCurvePrivateKey - | mlkem.MLKEM768PrivateKey - | mlkem.MLKEM1024PrivateKey - | MLKEM768X25519PrivateKey - | MLKEM1024P384PrivateKey, - info: Buffer | None = None, - ) -> bytes: ... - -def _encrypt_with_aad( - suite: Suite, - plaintext: Buffer, - public_key: x25519.X25519PublicKey - | ec.EllipticCurvePublicKey - | mlkem.MLKEM768PublicKey - | mlkem.MLKEM1024PublicKey - | MLKEM768X25519PublicKey - | MLKEM1024P384PublicKey, - info: Buffer | None = None, - aad: Buffer | None = None, -) -> bytes: ... -def _decrypt_with_aad( - suite: Suite, - ciphertext: Buffer, - private_key: x25519.X25519PrivateKey - | ec.EllipticCurvePrivateKey - | mlkem.MLKEM768PrivateKey - | mlkem.MLKEM1024PrivateKey - | MLKEM768X25519PrivateKey - | MLKEM1024P384PrivateKey, - info: Buffer | None = None, - aad: Buffer | None = None, -) -> bytes: ... diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/kdf.pyi b/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/kdf.pyi deleted file mode 100644 index bb37b96..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/kdf.pyi +++ /dev/null @@ -1,205 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -import typing - -from cryptography.hazmat.primitives.hashes import HashAlgorithm -from cryptography.hazmat.primitives.kdf.kbkdf import CounterLocation, Mode -from cryptography.utils import Buffer - -class PBKDF2HMAC: - def __init__( - self, - algorithm: HashAlgorithm, - length: int, - salt: bytes, - iterations: int, - backend: typing.Any = None, - ) -> None: ... - def derive(self, key_material: Buffer) -> bytes: ... - def derive_into(self, key_material: Buffer, buffer: Buffer) -> int: ... - def verify(self, key_material: bytes, expected_key: bytes) -> None: ... - -class Scrypt: - def __init__( - self, - salt: bytes, - length: int, - n: int, - r: int, - p: int, - backend: typing.Any = None, - ) -> None: ... - def derive(self, key_material: Buffer) -> bytes: ... - def derive_into(self, key_material: Buffer, buffer: Buffer) -> int: ... - def verify(self, key_material: bytes, expected_key: bytes) -> None: ... - -class Argon2d: - def __init__( - self, - *, - salt: bytes, - length: int, - iterations: int, - lanes: int, - memory_cost: int, - ad: bytes | None = None, - secret: bytes | None = None, - ) -> None: ... - def derive(self, key_material: bytes) -> bytes: ... - def derive_into(self, key_material: bytes, buffer: Buffer) -> int: ... - def verify(self, key_material: bytes, expected_key: bytes) -> None: ... - def derive_phc_encoded(self, key_material: bytes) -> str: ... - @classmethod - def verify_phc_encoded( - cls, key_material: bytes, phc_encoded: str, secret: bytes | None = None - ) -> None: ... - -class Argon2i: - def __init__( - self, - *, - salt: bytes, - length: int, - iterations: int, - lanes: int, - memory_cost: int, - ad: bytes | None = None, - secret: bytes | None = None, - ) -> None: ... - def derive(self, key_material: bytes) -> bytes: ... - def derive_into(self, key_material: bytes, buffer: Buffer) -> int: ... - def verify(self, key_material: bytes, expected_key: bytes) -> None: ... - def derive_phc_encoded(self, key_material: bytes) -> str: ... - @classmethod - def verify_phc_encoded( - cls, key_material: bytes, phc_encoded: str, secret: bytes | None = None - ) -> None: ... - -class Argon2id: - def __init__( - self, - *, - salt: bytes, - length: int, - iterations: int, - lanes: int, - memory_cost: int, - ad: bytes | None = None, - secret: bytes | None = None, - ) -> None: ... - def derive(self, key_material: bytes) -> bytes: ... - def derive_into(self, key_material: bytes, buffer: Buffer) -> int: ... - def verify(self, key_material: bytes, expected_key: bytes) -> None: ... - def derive_phc_encoded(self, key_material: bytes) -> str: ... - @classmethod - def verify_phc_encoded( - cls, key_material: bytes, phc_encoded: str, secret: bytes | None = None - ) -> None: ... - -class HKDF: - def __init__( - self, - algorithm: HashAlgorithm, - length: int, - salt: bytes | None, - info: bytes | None, - backend: typing.Any = None, - ): ... - @staticmethod - def extract( - algorithm: HashAlgorithm, salt: bytes | None, key_material: Buffer - ) -> bytes: ... - def derive(self, key_material: Buffer) -> bytes: ... - def derive_into(self, key_material: Buffer, buffer: Buffer) -> int: ... - def verify(self, key_material: bytes, expected_key: bytes) -> None: ... - -class HKDFExpand: - def __init__( - self, - algorithm: HashAlgorithm, - length: int, - info: bytes | None, - backend: typing.Any = None, - ): ... - def derive(self, key_material: Buffer) -> bytes: ... - def derive_into(self, key_material: Buffer, buffer: Buffer) -> int: ... - def verify(self, key_material: bytes, expected_key: bytes) -> None: ... - -class X963KDF: - def __init__( - self, - algorithm: HashAlgorithm, - length: int, - sharedinfo: bytes | None, - backend: typing.Any = None, - ) -> None: ... - def derive(self, key_material: Buffer) -> bytes: ... - def derive_into(self, key_material: Buffer, buffer: Buffer) -> int: ... - def verify(self, key_material: bytes, expected_key: bytes) -> None: ... - -class ConcatKDFHash: - def __init__( - self, - algorithm: HashAlgorithm, - length: int, - otherinfo: bytes | None, - backend: typing.Any = None, - ) -> None: ... - def derive(self, key_material: Buffer) -> bytes: ... - def derive_into(self, key_material: Buffer, buffer: Buffer) -> int: ... - def verify(self, key_material: bytes, expected_key: bytes) -> None: ... - -class ConcatKDFHMAC: - def __init__( - self, - algorithm: HashAlgorithm, - length: int, - salt: bytes | None, - otherinfo: bytes | None, - backend: typing.Any = None, - ) -> None: ... - def derive(self, key_material: Buffer) -> bytes: ... - def derive_into(self, key_material: Buffer, buffer: Buffer) -> int: ... - def verify(self, key_material: bytes, expected_key: bytes) -> None: ... - -class KBKDFHMAC: - def __init__( - self, - algorithm: HashAlgorithm, - mode: Mode, - length: int, - rlen: int, - llen: int | None, - location: CounterLocation, - label: bytes | None, - context: bytes | None, - fixed: bytes | None, - backend: typing.Any = None, - *, - break_location: int | None = None, - ) -> None: ... - def derive(self, key_material: Buffer) -> bytes: ... - def derive_into(self, key_material: Buffer, buffer: Buffer) -> int: ... - def verify(self, key_material: bytes, expected_key: bytes) -> None: ... - -class KBKDFCMAC: - def __init__( - self, - algorithm: typing.Any, - mode: Mode, - length: int, - rlen: int, - llen: int | None, - location: CounterLocation, - label: bytes | None, - context: bytes | None, - fixed: bytes | None, - backend: typing.Any = None, - *, - break_location: int | None = None, - ) -> None: ... - def derive(self, key_material: Buffer) -> bytes: ... - def derive_into(self, key_material: Buffer, buffer: Buffer) -> int: ... - def verify(self, key_material: bytes, expected_key: bytes) -> None: ... diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/keys.pyi b/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/keys.pyi deleted file mode 100644 index 404057e..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/keys.pyi +++ /dev/null @@ -1,34 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -import typing - -from cryptography.hazmat.primitives.asymmetric.types import ( - PrivateKeyTypes, - PublicKeyTypes, -) -from cryptography.utils import Buffer - -def load_der_private_key( - data: Buffer, - password: bytes | None, - backend: typing.Any = None, - *, - unsafe_skip_rsa_key_validation: bool = False, -) -> PrivateKeyTypes: ... -def load_pem_private_key( - data: Buffer, - password: bytes | None, - backend: typing.Any = None, - *, - unsafe_skip_rsa_key_validation: bool = False, -) -> PrivateKeyTypes: ... -def load_der_public_key( - data: bytes, - backend: typing.Any = None, -) -> PublicKeyTypes: ... -def load_pem_public_key( - data: bytes, - backend: typing.Any = None, -) -> PublicKeyTypes: ... diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/mldsa.pyi b/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/mldsa.pyi deleted file mode 100644 index 232469a..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/mldsa.pyi +++ /dev/null @@ -1,23 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from cryptography.hazmat.primitives.asymmetric import mldsa -from cryptography.utils import Buffer - -class MLDSA44PrivateKey: ... -class MLDSA44PublicKey: ... -class MLDSA65PrivateKey: ... -class MLDSA65PublicKey: ... -class MLDSA87PrivateKey: ... -class MLDSA87PublicKey: ... - -def generate_mldsa44_key() -> mldsa.MLDSA44PrivateKey: ... -def from_mldsa44_public_bytes(data: bytes) -> mldsa.MLDSA44PublicKey: ... -def from_mldsa44_seed_bytes(data: Buffer) -> mldsa.MLDSA44PrivateKey: ... -def generate_mldsa65_key() -> mldsa.MLDSA65PrivateKey: ... -def from_mldsa65_public_bytes(data: bytes) -> mldsa.MLDSA65PublicKey: ... -def from_mldsa65_seed_bytes(data: Buffer) -> mldsa.MLDSA65PrivateKey: ... -def generate_mldsa87_key() -> mldsa.MLDSA87PrivateKey: ... -def from_mldsa87_public_bytes(data: bytes) -> mldsa.MLDSA87PublicKey: ... -def from_mldsa87_seed_bytes(data: Buffer) -> mldsa.MLDSA87PrivateKey: ... diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/mlkem.pyi b/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/mlkem.pyi deleted file mode 100644 index 768a340..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/mlkem.pyi +++ /dev/null @@ -1,18 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from cryptography.hazmat.primitives.asymmetric import mlkem -from cryptography.utils import Buffer - -class MLKEM768PrivateKey: ... -class MLKEM768PublicKey: ... -class MLKEM1024PrivateKey: ... -class MLKEM1024PublicKey: ... - -def generate_mlkem768_key() -> mlkem.MLKEM768PrivateKey: ... -def from_mlkem768_seed_bytes(data: Buffer) -> mlkem.MLKEM768PrivateKey: ... -def from_mlkem768_public_bytes(data: Buffer) -> mlkem.MLKEM768PublicKey: ... -def generate_mlkem1024_key() -> mlkem.MLKEM1024PrivateKey: ... -def from_mlkem1024_seed_bytes(data: Buffer) -> mlkem.MLKEM1024PrivateKey: ... -def from_mlkem1024_public_bytes(data: Buffer) -> mlkem.MLKEM1024PublicKey: ... diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/poly1305.pyi b/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/poly1305.pyi deleted file mode 100644 index 45a2a39..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/poly1305.pyi +++ /dev/null @@ -1,15 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from cryptography.utils import Buffer - -class Poly1305: - def __init__(self, key: Buffer) -> None: ... - @staticmethod - def generate_tag(key: Buffer, data: Buffer) -> bytes: ... - @staticmethod - def verify_tag(key: Buffer, data: Buffer, tag: bytes) -> None: ... - def update(self, data: Buffer) -> None: ... - def finalize(self) -> bytes: ... - def verify(self, tag: bytes) -> None: ... diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/rsa.pyi b/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/rsa.pyi deleted file mode 100644 index ef7752d..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/rsa.pyi +++ /dev/null @@ -1,55 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -import typing - -from cryptography.hazmat.primitives.asymmetric import rsa - -class RSAPrivateKey: ... -class RSAPublicKey: ... - -class RSAPrivateNumbers: - def __init__( - self, - p: int, - q: int, - d: int, - dmp1: int, - dmq1: int, - iqmp: int, - public_numbers: RSAPublicNumbers, - ) -> None: ... - @property - def p(self) -> int: ... - @property - def q(self) -> int: ... - @property - def d(self) -> int: ... - @property - def dmp1(self) -> int: ... - @property - def dmq1(self) -> int: ... - @property - def iqmp(self) -> int: ... - @property - def public_numbers(self) -> RSAPublicNumbers: ... - def private_key( - self, - backend: typing.Any = None, - *, - unsafe_skip_rsa_key_validation: bool = False, - ) -> rsa.RSAPrivateKey: ... - -class RSAPublicNumbers: - def __init__(self, e: int, n: int) -> None: ... - @property - def n(self) -> int: ... - @property - def e(self) -> int: ... - def public_key(self, backend: typing.Any = None) -> rsa.RSAPublicKey: ... - -def generate_private_key( - public_exponent: int, - key_size: int, -) -> rsa.RSAPrivateKey: ... diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/x25519.pyi b/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/x25519.pyi deleted file mode 100644 index 38d2add..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/x25519.pyi +++ /dev/null @@ -1,13 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from cryptography.hazmat.primitives.asymmetric import x25519 -from cryptography.utils import Buffer - -class X25519PrivateKey: ... -class X25519PublicKey: ... - -def generate_key() -> x25519.X25519PrivateKey: ... -def from_private_bytes(data: Buffer) -> x25519.X25519PrivateKey: ... -def from_public_bytes(data: bytes) -> x25519.X25519PublicKey: ... diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/x448.pyi b/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/x448.pyi deleted file mode 100644 index 3ac0980..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/x448.pyi +++ /dev/null @@ -1,13 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from cryptography.hazmat.primitives.asymmetric import x448 -from cryptography.utils import Buffer - -class X448PrivateKey: ... -class X448PublicKey: ... - -def generate_key() -> x448.X448PrivateKey: ... -def from_private_bytes(data: Buffer) -> x448.X448PrivateKey: ... -def from_public_bytes(data: bytes) -> x448.X448PublicKey: ... diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/pkcs12.pyi b/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/pkcs12.pyi deleted file mode 100644 index b25becb..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/pkcs12.pyi +++ /dev/null @@ -1,52 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -import typing -from collections.abc import Iterable - -from cryptography import x509 -from cryptography.hazmat.primitives.asymmetric.types import PrivateKeyTypes -from cryptography.hazmat.primitives.serialization import ( - KeySerializationEncryption, -) -from cryptography.hazmat.primitives.serialization.pkcs12 import ( - PKCS12KeyAndCertificates, - PKCS12PrivateKeyTypes, -) -from cryptography.utils import Buffer - -class PKCS12Certificate: - def __init__( - self, cert: x509.Certificate, friendly_name: bytes | None - ) -> None: ... - @property - def friendly_name(self) -> bytes | None: ... - @property - def certificate(self) -> x509.Certificate: ... - -def load_key_and_certificates( - data: Buffer, - password: Buffer | None, - backend: typing.Any = None, -) -> tuple[ - PrivateKeyTypes | None, - x509.Certificate | None, - list[x509.Certificate], -]: ... -def load_pkcs12( - data: bytes, - password: bytes | None, - backend: typing.Any = None, -) -> PKCS12KeyAndCertificates: ... -def serialize_java_truststore( - certs: Iterable[PKCS12Certificate], - encryption_algorithm: KeySerializationEncryption, -) -> bytes: ... -def serialize_key_and_certificates( - name: bytes | None, - key: PKCS12PrivateKeyTypes | None, - cert: x509.Certificate | None, - cas: Iterable[x509.Certificate | PKCS12Certificate] | None, - encryption_algorithm: KeySerializationEncryption, -) -> bytes: ... diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/pkcs7.pyi b/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/pkcs7.pyi deleted file mode 100644 index 358b135..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/pkcs7.pyi +++ /dev/null @@ -1,50 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from collections.abc import Iterable - -from cryptography import x509 -from cryptography.hazmat.primitives import serialization -from cryptography.hazmat.primitives.asymmetric import rsa -from cryptography.hazmat.primitives.serialization import pkcs7 - -def serialize_certificates( - certs: list[x509.Certificate], - encoding: serialization.Encoding, -) -> bytes: ... -def encrypt_and_serialize( - builder: pkcs7.PKCS7EnvelopeBuilder, - content_encryption_algorithm: pkcs7.ContentEncryptionAlgorithm, - encoding: serialization.Encoding, - options: Iterable[pkcs7.PKCS7Options], -) -> bytes: ... -def sign_and_serialize( - builder: pkcs7.PKCS7SignatureBuilder, - encoding: serialization.Encoding, - options: Iterable[pkcs7.PKCS7Options], -) -> bytes: ... -def decrypt_der( - data: bytes, - certificate: x509.Certificate, - private_key: rsa.RSAPrivateKey, - options: Iterable[pkcs7.PKCS7Options], -) -> bytes: ... -def decrypt_pem( - data: bytes, - certificate: x509.Certificate, - private_key: rsa.RSAPrivateKey, - options: Iterable[pkcs7.PKCS7Options], -) -> bytes: ... -def decrypt_smime( - data: bytes, - certificate: x509.Certificate, - private_key: rsa.RSAPrivateKey, - options: Iterable[pkcs7.PKCS7Options], -) -> bytes: ... -def load_pem_pkcs7_certificates( - data: bytes, -) -> list[x509.Certificate]: ... -def load_der_pkcs7_certificates( - data: bytes, -) -> list[x509.Certificate]: ... diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/test_support.pyi b/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/test_support.pyi deleted file mode 100644 index c6c6d0b..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/test_support.pyi +++ /dev/null @@ -1,23 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from cryptography import x509 -from cryptography.hazmat.primitives import serialization -from cryptography.hazmat.primitives.serialization import pkcs7 -from cryptography.utils import Buffer - -class TestCertificate: - not_after_tag: int - not_before_tag: int - issuer_value_tags: list[int] - subject_value_tags: list[int] - -def test_parse_certificate(data: bytes) -> TestCertificate: ... -def pkcs7_verify( - encoding: serialization.Encoding, - sig: bytes, - msg: Buffer | None, - certs: list[x509.Certificate], - options: list[pkcs7.PKCS7Options], -) -> None: ... diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/x509.pyi b/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/x509.pyi deleted file mode 100644 index 196a3c6..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/x509.pyi +++ /dev/null @@ -1,312 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -import datetime -import typing -from collections.abc import Iterator - -from cryptography import x509 -from cryptography.hazmat.primitives import hashes, serialization -from cryptography.hazmat.primitives.asymmetric.ec import ECDSA -from cryptography.hazmat.primitives.asymmetric.padding import PSS, PKCS1v15 -from cryptography.hazmat.primitives.asymmetric.types import ( - CertificateIssuerPublicKeyTypes, - CertificatePublicKeyTypes, - PrivateKeyTypes, -) -from cryptography.x509 import certificate_transparency - -def load_pem_x509_certificate( - data: bytes, backend: typing.Any = None -) -> x509.Certificate: ... -def load_der_x509_certificate( - data: bytes, backend: typing.Any = None -) -> x509.Certificate: ... -def load_pem_x509_certificates( - data: bytes, -) -> list[x509.Certificate]: ... -def load_pem_x509_crl( - data: bytes, backend: typing.Any = None -) -> x509.CertificateRevocationList: ... -def load_der_x509_crl( - data: bytes, backend: typing.Any = None -) -> x509.CertificateRevocationList: ... -def load_pem_x509_csr( - data: bytes, backend: typing.Any = None -) -> x509.CertificateSigningRequest: ... -def load_der_x509_csr( - data: bytes, backend: typing.Any = None -) -> x509.CertificateSigningRequest: ... -def encode_name_bytes(name: x509.Name) -> bytes: ... -def encode_extension_value(extension: x509.ExtensionType) -> bytes: ... -def create_x509_certificate( - builder: x509.CertificateBuilder, - private_key: PrivateKeyTypes, - hash_algorithm: hashes.HashAlgorithm | None, - rsa_padding: PKCS1v15 | PSS | None, - ecdsa_deterministic: bool | None, -) -> x509.Certificate: ... -def create_x509_csr( - builder: x509.CertificateSigningRequestBuilder, - private_key: PrivateKeyTypes, - hash_algorithm: hashes.HashAlgorithm | None, - rsa_padding: PKCS1v15 | PSS | None, - ecdsa_deterministic: bool | None, -) -> x509.CertificateSigningRequest: ... -def create_revoked_certificate( - builder: x509.RevokedCertificateBuilder, -) -> x509.RevokedCertificate: ... -def create_x509_crl( - builder: x509.CertificateRevocationListBuilder, - private_key: PrivateKeyTypes, - hash_algorithm: hashes.HashAlgorithm | None, - rsa_padding: PKCS1v15 | PSS | None, - ecdsa_deterministic: bool | None, -) -> x509.CertificateRevocationList: ... - -class Sct: - @property - def version(self) -> certificate_transparency.Version: ... - @property - def log_id(self) -> bytes: ... - @property - def timestamp(self) -> datetime.datetime: ... - @property - def entry_type(self) -> certificate_transparency.LogEntryType: ... - @property - def signature_hash_algorithm(self) -> hashes.HashAlgorithm: ... - @property - def signature_algorithm( - self, - ) -> certificate_transparency.SignatureAlgorithm: ... - @property - def signature(self) -> bytes: ... - @property - def extension_bytes(self) -> bytes: ... - -class Certificate: - def fingerprint(self, algorithm: hashes.HashAlgorithm) -> bytes: ... - @property - def serial_number(self) -> int: ... - @property - def version(self) -> x509.Version: ... - def public_key(self) -> CertificatePublicKeyTypes: ... - @property - def public_key_algorithm_oid(self) -> x509.ObjectIdentifier: ... - @property - def not_valid_before(self) -> datetime.datetime: ... - @property - def not_valid_before_utc(self) -> datetime.datetime: ... - @property - def not_valid_after(self) -> datetime.datetime: ... - @property - def not_valid_after_utc(self) -> datetime.datetime: ... - @property - def issuer(self) -> x509.Name: ... - @property - def subject(self) -> x509.Name: ... - @property - def signature_hash_algorithm( - self, - ) -> hashes.HashAlgorithm | None: ... - @property - def signature_algorithm_oid(self) -> x509.ObjectIdentifier: ... - @property - def signature_algorithm_parameters( - self, - ) -> PSS | PKCS1v15 | ECDSA | None: ... - @property - def extensions(self) -> x509.Extensions: ... - @property - def signature(self) -> bytes: ... - @property - def tbs_certificate_bytes(self) -> bytes: ... - @property - def tbs_precertificate_bytes(self) -> bytes: ... - def __eq__(self, other: object) -> bool: ... - def __hash__(self) -> int: ... - def public_bytes(self, encoding: serialization.Encoding) -> bytes: ... - def verify_directly_issued_by(self, issuer: Certificate) -> None: ... - -class RevokedCertificate: - @property - def serial_number(self) -> int: ... - @property - def revocation_date(self) -> datetime.datetime: ... - @property - def revocation_date_utc(self) -> datetime.datetime: ... - @property - def extensions(self) -> x509.Extensions: ... - -class CertificateRevocationList: - def public_bytes(self, encoding: serialization.Encoding) -> bytes: ... - def fingerprint(self, algorithm: hashes.HashAlgorithm) -> bytes: ... - def get_revoked_certificate_by_serial_number( - self, serial_number: int - ) -> x509.RevokedCertificate | None: ... - @property - def signature_hash_algorithm( - self, - ) -> hashes.HashAlgorithm | None: ... - @property - def signature_algorithm_oid(self) -> x509.ObjectIdentifier: ... - @property - def signature_algorithm_parameters( - self, - ) -> PSS | PKCS1v15 | ECDSA | None: ... - @property - def issuer(self) -> x509.Name: ... - @property - def next_update(self) -> datetime.datetime | None: ... - @property - def next_update_utc(self) -> datetime.datetime | None: ... - @property - def last_update(self) -> datetime.datetime: ... - @property - def last_update_utc(self) -> datetime.datetime: ... - @property - def extensions(self) -> x509.Extensions: ... - @property - def signature(self) -> bytes: ... - @property - def tbs_certlist_bytes(self) -> bytes: ... - def __eq__(self, other: object) -> bool: ... - def __len__(self) -> int: ... - @typing.overload - def __getitem__(self, idx: int) -> x509.RevokedCertificate: ... - @typing.overload - def __getitem__(self, idx: slice) -> list[x509.RevokedCertificate]: ... - def __iter__(self) -> Iterator[x509.RevokedCertificate]: ... - def is_signature_valid( - self, public_key: CertificateIssuerPublicKeyTypes - ) -> bool: ... - -class CertificateSigningRequest: - def __eq__(self, other: object) -> bool: ... - def __hash__(self) -> int: ... - def public_key(self) -> CertificatePublicKeyTypes: ... - @property - def subject(self) -> x509.Name: ... - @property - def signature_hash_algorithm( - self, - ) -> hashes.HashAlgorithm | None: ... - @property - def signature_algorithm_oid(self) -> x509.ObjectIdentifier: ... - @property - def signature_algorithm_parameters( - self, - ) -> PSS | PKCS1v15 | ECDSA | None: ... - @property - def extensions(self) -> x509.Extensions: ... - @property - def attributes(self) -> x509.Attributes: ... - def public_bytes(self, encoding: serialization.Encoding) -> bytes: ... - @property - def signature(self) -> bytes: ... - @property - def tbs_certrequest_bytes(self) -> bytes: ... - @property - def is_signature_valid(self) -> bool: ... - -class PolicyBuilder: - def time(self, time: datetime.datetime) -> PolicyBuilder: ... - def store(self, store: Store) -> PolicyBuilder: ... - def max_chain_depth(self, max_chain_depth: int) -> PolicyBuilder: ... - def extension_policies( - self, *, ca_policy: ExtensionPolicy, ee_policy: ExtensionPolicy - ) -> PolicyBuilder: ... - def build_client_verifier(self) -> ClientVerifier: ... - def build_server_verifier( - self, subject: x509.verification.Subject - ) -> ServerVerifier: ... - -class Policy: - @property - def max_chain_depth(self) -> int: ... - @property - def subject(self) -> x509.verification.Subject | None: ... - @property - def validation_time(self) -> datetime.datetime: ... - @property - def extended_key_usage(self) -> x509.ObjectIdentifier: ... - @property - def minimum_rsa_modulus(self) -> int: ... - -class Criticality: - CRITICAL: Criticality - AGNOSTIC: Criticality - NON_CRITICAL: Criticality - -T = typing.TypeVar("T", contravariant=True, bound=x509.ExtensionType) - -MaybeExtensionValidatorCallback = typing.Callable[ - [ - Policy, - x509.Certificate, - T | None, - ], - None, -] - -PresentExtensionValidatorCallback = typing.Callable[ - [Policy, x509.Certificate, T], - None, -] - -class ExtensionPolicy: - @staticmethod - def permit_all() -> ExtensionPolicy: ... - @staticmethod - def webpki_defaults_ca() -> ExtensionPolicy: ... - @staticmethod - def webpki_defaults_ee() -> ExtensionPolicy: ... - def require_not_present( - self, extension_type: type[x509.ExtensionType] - ) -> ExtensionPolicy: ... - def may_be_present( - self, - extension_type: type[T], - criticality: Criticality, - validator: MaybeExtensionValidatorCallback[T] | None, - ) -> ExtensionPolicy: ... - def require_present( - self, - extension_type: type[T], - criticality: Criticality, - validator: PresentExtensionValidatorCallback[T] | None, - ) -> ExtensionPolicy: ... - -class VerifiedClient: - @property - def subjects(self) -> list[x509.GeneralName] | None: ... - @property - def chain(self) -> list[x509.Certificate]: ... - -class ClientVerifier: - @property - def policy(self) -> Policy: ... - @property - def store(self) -> Store: ... - def verify( - self, - leaf: x509.Certificate, - intermediates: list[x509.Certificate], - ) -> VerifiedClient: ... - -class ServerVerifier: - @property - def policy(self) -> Policy: ... - @property - def store(self) -> Store: ... - def verify( - self, - leaf: x509.Certificate, - intermediates: list[x509.Certificate], - ) -> list[x509.Certificate]: ... - -class Store: - def __init__(self, certs: list[x509.Certificate]) -> None: ... - -class VerificationError(Exception): ... diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/openssl/__init__.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/openssl/__init__.py deleted file mode 100644 index b509336..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/openssl/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/openssl/_conditional.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/openssl/_conditional.py deleted file mode 100644 index 1e447a5..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/openssl/_conditional.py +++ /dev/null @@ -1,199 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - - -def cryptography_has_set_cert_cb() -> list[str]: - return [ - "SSL_CTX_set_cert_cb", - "SSL_set_cert_cb", - ] - - -def cryptography_has_ssl_st() -> list[str]: - return [ - "SSL_ST_BEFORE", - "SSL_ST_OK", - "SSL_ST_INIT", - "SSL_ST_RENEGOTIATE", - ] - - -def cryptography_has_tls_st() -> list[str]: - return [ - "TLS_ST_BEFORE", - "TLS_ST_OK", - ] - - -def cryptography_has_ssl_sigalgs() -> list[str]: - return [ - "SSL_CTX_set1_sigalgs_list", - ] - - -def cryptography_has_psk() -> list[str]: - return [ - "SSL_CTX_use_psk_identity_hint", - "SSL_CTX_set_psk_server_callback", - "SSL_CTX_set_psk_client_callback", - ] - - -def cryptography_has_psk_tlsv13() -> list[str]: - return [ - "SSL_CTX_set_psk_find_session_callback", - "SSL_CTX_set_psk_use_session_callback", - "Cryptography_SSL_SESSION_new", - "SSL_CIPHER_find", - "SSL_SESSION_set1_master_key", - "SSL_SESSION_set_cipher", - "SSL_SESSION_set_protocol_version", - ] - - -def cryptography_has_custom_ext() -> list[str]: - return [ - "SSL_CTX_add_client_custom_ext", - "SSL_CTX_add_server_custom_ext", - "SSL_extension_supported", - ] - - -def cryptography_has_tlsv13_functions() -> list[str]: - return [ - "SSL_CTX_set_ciphersuites", - ] - - -def cryptography_has_tlsv13_hs_functions() -> list[str]: - return [ - "SSL_VERIFY_POST_HANDSHAKE", - "SSL_verify_client_post_handshake", - "SSL_CTX_set_post_handshake_auth", - "SSL_set_post_handshake_auth", - "SSL_SESSION_get_max_early_data", - "SSL_write_early_data", - "SSL_read_early_data", - "SSL_CTX_set_max_early_data", - ] - - -def cryptography_has_ssl_verify_client_post_handshake() -> list[str]: - return [ - "SSL_verify_client_post_handshake", - ] - - -def cryptography_has_engine() -> list[str]: - return [ - "ENGINE_by_id", - "ENGINE_init", - "ENGINE_finish", - "ENGINE_get_default_RAND", - "ENGINE_set_default_RAND", - "ENGINE_unregister_RAND", - "ENGINE_ctrl_cmd", - "ENGINE_free", - "ENGINE_get_name", - "ENGINE_ctrl_cmd_string", - "ENGINE_load_builtin_engines", - "ENGINE_load_private_key", - "ENGINE_load_public_key", - "SSL_CTX_set_client_cert_engine", - ] - - -def cryptography_has_verified_chain() -> list[str]: - return [ - "SSL_get0_verified_chain", - ] - - -def cryptography_has_srtp() -> list[str]: - return [ - "SSL_CTX_set_tlsext_use_srtp", - "SSL_set_tlsext_use_srtp", - "SSL_get_selected_srtp_profile", - ] - - -def cryptography_has_dtls_get_data_mtu() -> list[str]: - return [ - "DTLS_get_data_mtu", - ] - - -def cryptography_has_ssl_cookie() -> list[str]: - return [ - "SSL_OP_COOKIE_EXCHANGE", - "DTLS1_COOKIE_LENGTH", - "DTLSv1_listen", - "SSL_CTX_set_cookie_generate_cb", - "SSL_CTX_set_cookie_verify_cb", - ] - - -def cryptography_has_prime_checks() -> list[str]: - return [ - "BN_prime_checks_for_size", - ] - - -def cryptography_has_unexpected_eof_while_reading() -> list[str]: - return ["SSL_R_UNEXPECTED_EOF_WHILE_READING"] - - -def cryptography_has_ssl_op_ignore_unexpected_eof() -> list[str]: - return [ - "SSL_OP_IGNORE_UNEXPECTED_EOF", - ] - - -def cryptography_has_get_extms_support() -> list[str]: - return ["SSL_get_extms_support"] - - -def cryptography_has_ssl_get0_group_name() -> list[str]: - return ["SSL_get0_group_name"] - - -# This is a mapping of -# {condition: function-returning-names-dependent-on-that-condition} so we can -# loop over them and delete unsupported names at runtime. It will be removed -# when cffi supports #if in cdef. We use functions instead of just a dict of -# lists so we can use coverage to measure which are used. -CONDITIONAL_NAMES = { - "Cryptography_HAS_SET_CERT_CB": cryptography_has_set_cert_cb, - "Cryptography_HAS_SSL_ST": cryptography_has_ssl_st, - "Cryptography_HAS_TLS_ST": cryptography_has_tls_st, - "Cryptography_HAS_SIGALGS": cryptography_has_ssl_sigalgs, - "Cryptography_HAS_PSK": cryptography_has_psk, - "Cryptography_HAS_PSK_TLSv1_3": cryptography_has_psk_tlsv13, - "Cryptography_HAS_CUSTOM_EXT": cryptography_has_custom_ext, - "Cryptography_HAS_TLSv1_3_FUNCTIONS": cryptography_has_tlsv13_functions, - "Cryptography_HAS_TLSv1_3_HS_FUNCTIONS": ( - cryptography_has_tlsv13_hs_functions - ), - "Cryptography_HAS_SSL_VERIFY_CLIENT_POST_HANDSHAKE": ( - cryptography_has_ssl_verify_client_post_handshake - ), - "Cryptography_HAS_ENGINE": cryptography_has_engine, - "Cryptography_HAS_VERIFIED_CHAIN": cryptography_has_verified_chain, - "Cryptography_HAS_SRTP": cryptography_has_srtp, - "Cryptography_HAS_DTLS_GET_DATA_MTU": cryptography_has_dtls_get_data_mtu, - "Cryptography_HAS_SSL_COOKIE": cryptography_has_ssl_cookie, - "Cryptography_HAS_PRIME_CHECKS": cryptography_has_prime_checks, - "Cryptography_HAS_UNEXPECTED_EOF_WHILE_READING": ( - cryptography_has_unexpected_eof_while_reading - ), - "Cryptography_HAS_SSL_OP_IGNORE_UNEXPECTED_EOF": ( - cryptography_has_ssl_op_ignore_unexpected_eof - ), - "Cryptography_HAS_GET_EXTMS_SUPPORT": cryptography_has_get_extms_support, - "Cryptography_HAS_SSL_GET0_GROUP_NAME": ( - cryptography_has_ssl_get0_group_name - ), -} diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/openssl/binding.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/openssl/binding.py deleted file mode 100644 index 6a0cafd..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/bindings/openssl/binding.py +++ /dev/null @@ -1,122 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -import os -import sys -import threading -import types -import typing -import warnings -from collections.abc import Callable - -import cryptography -from cryptography.exceptions import InternalError -from cryptography.hazmat.bindings._rust import _openssl, openssl -from cryptography.hazmat.bindings.openssl._conditional import CONDITIONAL_NAMES - - -def _openssl_assert(ok: bool) -> None: - if not ok: - errors = openssl.capture_error_stack() - - raise InternalError( - "Unknown OpenSSL error. This error is commonly encountered when " - "another library is not cleaning up the OpenSSL error stack. If " - "you are using cryptography with another library that uses " - "OpenSSL try disabling it before reporting a bug. Otherwise " - "please file an issue at https://github.com/pyca/cryptography/" - "issues with information on how to reproduce " - f"this. ({errors!r})", - errors, - ) - - -def build_conditional_library( - lib: typing.Any, - conditional_names: dict[str, Callable[[], list[str]]], -) -> typing.Any: - conditional_lib = types.ModuleType("lib") - conditional_lib._original_lib = lib # type: ignore[attr-defined] - excluded_names = set() - for condition, names_cb in conditional_names.items(): - if not getattr(lib, condition): - excluded_names.update(names_cb()) - - for attr in dir(lib): - if attr not in excluded_names: - setattr(conditional_lib, attr, getattr(lib, attr)) - - return conditional_lib - - -class Binding: - """ - OpenSSL API wrapper. - """ - - lib: typing.ClassVar[typing.Any] = None - ffi: typing.Any = _openssl.ffi - _lib_loaded = False - _init_lock = threading.Lock() - - def __init__(self) -> None: - self._ensure_ffi_initialized() - - @classmethod - def _ensure_ffi_initialized(cls) -> None: - with cls._init_lock: - if not cls._lib_loaded: - cls.lib = build_conditional_library( - _openssl.lib, CONDITIONAL_NAMES - ) - cls._lib_loaded = True - - @classmethod - def init_static_locks(cls) -> None: - cls._ensure_ffi_initialized() - - -def _verify_package_version(version: str) -> None: - # Occasionally we run into situations where the version of the Python - # package does not match the version of the shared object that is loaded. - # This may occur in environments where multiple versions of cryptography - # are installed and available in the python path. To avoid errors cropping - # up later this code checks that the currently imported package and the - # shared object that were loaded have the same version and raise an - # ImportError if they do not - so_package_version = _openssl.ffi.string( - _openssl.lib.CRYPTOGRAPHY_PACKAGE_VERSION - ) - if version.encode("ascii") != so_package_version: - raise ImportError( - "The version of cryptography does not match the loaded " - "shared object. This can happen if you have multiple copies of " - "cryptography installed in your Python path. Please try creating " - "a new virtual environment to resolve this issue. " - f"Loaded python version: {version}, " - f"shared object version: {so_package_version}" - ) - - _openssl_assert( - _openssl.lib.OpenSSL_version_num() == openssl.openssl_version(), - ) - - -_verify_package_version(cryptography.__version__) - -Binding.init_static_locks() - -if ( - sys.platform == "win32" - and os.environ.get("PROCESSOR_ARCHITEW6432") is not None -): - warnings.warn( - "You are using cryptography on a 32-bit Python on a 64-bit Windows " - "Operating System. Cryptography will be significantly faster if you " - "switch to using a 64-bit Python.", - UserWarning, - stacklevel=2, - ) diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/decrepit/__init__.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/decrepit/__init__.py deleted file mode 100644 index 41d7318..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/decrepit/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/decrepit/ciphers/__init__.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/decrepit/ciphers/__init__.py deleted file mode 100644 index 41d7318..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/decrepit/ciphers/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/decrepit/ciphers/algorithms.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/decrepit/ciphers/algorithms.py deleted file mode 100644 index 703c8e4..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/decrepit/ciphers/algorithms.py +++ /dev/null @@ -1,142 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -import warnings - -from cryptography import utils -from cryptography.hazmat.primitives._cipheralgorithm import ( - BlockCipherAlgorithm, - CipherAlgorithm, - _verify_key_size, -) - - -class ARC4(CipherAlgorithm): - name = "RC4" - key_sizes = frozenset([40, 56, 64, 80, 128, 160, 192, 256]) - - def __init__(self, key: bytes): - self.key = _verify_key_size(self, key) - - @property - def key_size(self) -> int: - return len(self.key) * 8 - - -class TripleDES(BlockCipherAlgorithm): - name = "3DES" - block_size = 64 - key_sizes = frozenset([64, 128, 192]) - - def __init__(self, key: bytes): - if len(key) == 8: - warnings.warn( - "Single-key TripleDES (8-byte keys) is deprecated and " - "support will be removed in a future release. Use 24-byte " - "keys instead (e.g., key + key + key).", - utils.DeprecatedIn47, - stacklevel=2, - ) - key = key + key + key - elif len(key) == 16: - warnings.warn( - "Two-key TripleDES (16-byte keys) is deprecated and " - "support will be removed in a future release. Use 24-byte " - "keys instead (e.g., key + key[:8]).", - utils.DeprecatedIn47, - stacklevel=2, - ) - key = key + key[:8] - self.key = _verify_key_size(self, key) - - @property - def key_size(self) -> int: - return len(self.key) * 8 - - -# Not actually supported, marker for tests -class _DES: - key_size = 64 - - -class Blowfish(BlockCipherAlgorithm): - name = "Blowfish" - block_size = 64 - key_sizes = frozenset(range(32, 449, 8)) - - def __init__(self, key: bytes): - self.key = _verify_key_size(self, key) - - @property - def key_size(self) -> int: - return len(self.key) * 8 - - -class CAST5(BlockCipherAlgorithm): - name = "CAST5" - block_size = 64 - key_sizes = frozenset(range(40, 129, 8)) - - def __init__(self, key: bytes): - self.key = _verify_key_size(self, key) - - @property - def key_size(self) -> int: - return len(self.key) * 8 - - -class SEED(BlockCipherAlgorithm): - name = "SEED" - block_size = 128 - key_sizes = frozenset([128]) - - def __init__(self, key: bytes): - self.key = _verify_key_size(self, key) - - @property - def key_size(self) -> int: - return len(self.key) * 8 - - -class IDEA(BlockCipherAlgorithm): - name = "IDEA" - block_size = 64 - key_sizes = frozenset([128]) - - def __init__(self, key: bytes): - self.key = _verify_key_size(self, key) - - @property - def key_size(self) -> int: - return len(self.key) * 8 - - -class Camellia(BlockCipherAlgorithm): - name = "camellia" - block_size = 128 - key_sizes = frozenset([128, 192, 256]) - - def __init__(self, key: bytes): - self.key = _verify_key_size(self, key) - - @property - def key_size(self) -> int: - return len(self.key) * 8 - - -# This class only allows RC2 with a 128-bit key. No support for -# effective key bits or other key sizes is provided. -class RC2(BlockCipherAlgorithm): - name = "RC2" - block_size = 64 - key_sizes = frozenset([128]) - - def __init__(self, key: bytes): - self.key = _verify_key_size(self, key) - - @property - def key_size(self) -> int: - return len(self.key) * 8 diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/decrepit/ciphers/modes.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/decrepit/ciphers/modes.py deleted file mode 100644 index 1786bb0..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/decrepit/ciphers/modes.py +++ /dev/null @@ -1,53 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -from cryptography import utils -from cryptography.hazmat.primitives._modes import ( - ModeWithInitializationVector, - _check_iv_and_key_length, -) - - -class OFB(ModeWithInitializationVector): - name = "OFB" - - def __init__(self, initialization_vector: utils.Buffer): - utils._check_byteslike("initialization_vector", initialization_vector) - self._initialization_vector = initialization_vector - - @property - def initialization_vector(self) -> utils.Buffer: - return self._initialization_vector - - validate_for_algorithm = _check_iv_and_key_length - - -class CFB(ModeWithInitializationVector): - name = "CFB" - - def __init__(self, initialization_vector: utils.Buffer): - utils._check_byteslike("initialization_vector", initialization_vector) - self._initialization_vector = initialization_vector - - @property - def initialization_vector(self) -> utils.Buffer: - return self._initialization_vector - - validate_for_algorithm = _check_iv_and_key_length - - -class CFB8(ModeWithInitializationVector): - name = "CFB8" - - def __init__(self, initialization_vector: utils.Buffer): - utils._check_byteslike("initialization_vector", initialization_vector) - self._initialization_vector = initialization_vector - - @property - def initialization_vector(self) -> utils.Buffer: - return self._initialization_vector - - validate_for_algorithm = _check_iv_and_key_length diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/__init__.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/__init__.py deleted file mode 100644 index b509336..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/_asymmetric.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/_asymmetric.py deleted file mode 100644 index ea55ffd..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/_asymmetric.py +++ /dev/null @@ -1,19 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -import abc - -# This exists to break an import cycle. It is normally accessible from the -# asymmetric padding module. - - -class AsymmetricPadding(metaclass=abc.ABCMeta): - @property - @abc.abstractmethod - def name(self) -> str: - """ - A string naming this padding (e.g. "PSS", "PKCS1"). - """ diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/_cipheralgorithm.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/_cipheralgorithm.py deleted file mode 100644 index 305a9fd..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/_cipheralgorithm.py +++ /dev/null @@ -1,60 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -import abc - -from cryptography import utils - -# This exists to break an import cycle. It is normally accessible from the -# ciphers module. - - -class CipherAlgorithm(metaclass=abc.ABCMeta): - @property - @abc.abstractmethod - def name(self) -> str: - """ - A string naming this mode (e.g. "AES", "Camellia"). - """ - - @property - @abc.abstractmethod - def key_sizes(self) -> frozenset[int]: - """ - Valid key sizes for this algorithm in bits - """ - - @property - @abc.abstractmethod - def key_size(self) -> int: - """ - The size of the key being used as an integer in bits (e.g. 128, 256). - """ - - -class BlockCipherAlgorithm(CipherAlgorithm): - key: utils.Buffer - - @property - @abc.abstractmethod - def block_size(self) -> int: - """ - The size of a block as an integer in bits (e.g. 64, 128). - """ - - -def _verify_key_size( - algorithm: CipherAlgorithm, key: utils.Buffer -) -> utils.Buffer: - # Verify that the key is instance of bytes - utils._check_byteslike("key", key) - - # Verify that the key size matches the expected key size - if len(key) * 8 not in algorithm.key_sizes: - raise ValueError( - f"Invalid key size ({len(key) * 8}) for {algorithm.name}." - ) - return key diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/_modes.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/_modes.py deleted file mode 100644 index deae8bc..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/_modes.py +++ /dev/null @@ -1,105 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -import abc - -from cryptography import utils -from cryptography.exceptions import UnsupportedAlgorithm, _Reasons -from cryptography.hazmat.primitives._cipheralgorithm import ( - BlockCipherAlgorithm, - CipherAlgorithm, -) - - -class Mode(metaclass=abc.ABCMeta): - @property - @abc.abstractmethod - def name(self) -> str: - """ - A string naming this mode (e.g. "ECB", "CBC"). - """ - - @abc.abstractmethod - def validate_for_algorithm(self, algorithm: CipherAlgorithm) -> None: - """ - Checks that all the necessary invariants of this (mode, algorithm) - combination are met. - """ - - -class ModeWithInitializationVector(Mode, metaclass=abc.ABCMeta): - @property - @abc.abstractmethod - def initialization_vector(self) -> utils.Buffer: - """ - The value of the initialization vector for this mode as bytes. - """ - - -class ModeWithTweak(Mode, metaclass=abc.ABCMeta): - @property - @abc.abstractmethod - def tweak(self) -> utils.Buffer: - """ - The value of the tweak for this mode as bytes. - """ - - -class ModeWithNonce(Mode, metaclass=abc.ABCMeta): - @property - @abc.abstractmethod - def nonce(self) -> utils.Buffer: - """ - The value of the nonce for this mode as bytes. - """ - - -class ModeWithAuthenticationTag(Mode, metaclass=abc.ABCMeta): - @property - @abc.abstractmethod - def tag(self) -> bytes | None: - """ - The value of the tag supplied to the constructor of this mode. - """ - - -def _check_aes_key_length(self: Mode, algorithm: CipherAlgorithm) -> None: - if algorithm.key_size > 256 and algorithm.name == "AES": - raise ValueError( - "Only 128, 192, and 256 bit keys are allowed for this AES mode" - ) - - -def _check_iv_length( - self: ModeWithInitializationVector, algorithm: BlockCipherAlgorithm -) -> None: - iv_len = len(self.initialization_vector) - if iv_len * 8 != algorithm.block_size: - raise ValueError(f"Invalid IV size ({iv_len}) for {self.name}.") - - -def _check_nonce_length( - nonce: utils.Buffer, name: str, algorithm: CipherAlgorithm -) -> None: - if not isinstance(algorithm, BlockCipherAlgorithm): - raise UnsupportedAlgorithm( - f"{name} requires a block cipher algorithm", - _Reasons.UNSUPPORTED_CIPHER, - ) - if len(nonce) * 8 != algorithm.block_size: - raise ValueError(f"Invalid nonce size ({len(nonce)}) for {name}.") - - -def _check_iv_and_key_length( - self: ModeWithInitializationVector, algorithm: CipherAlgorithm -) -> None: - if not isinstance(algorithm, BlockCipherAlgorithm): - raise UnsupportedAlgorithm( - f"{self} requires a block cipher algorithm", - _Reasons.UNSUPPORTED_CIPHER, - ) - _check_aes_key_length(self, algorithm) - _check_iv_length(self, algorithm) diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/_serialization.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/_serialization.py deleted file mode 100644 index 9c3c474..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/_serialization.py +++ /dev/null @@ -1,136 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -import abc - -from cryptography import utils -from cryptography.hazmat.bindings._rust import Encoding as Encoding -from cryptography.hazmat.bindings._rust import ( - ParameterFormat as ParameterFormat, -) -from cryptography.hazmat.bindings._rust import PrivateFormat as PrivateFormat -from cryptography.hazmat.bindings._rust import PublicFormat as PublicFormat -from cryptography.hazmat.primitives.hashes import HashAlgorithm - -# This exists to break an import cycle. These classes are normally accessible -# from the serialization module. - - -class PBES(utils.Enum): - PBESv1SHA1And3KeyTripleDESCBC = "PBESv1 using SHA1 and 3-Key TripleDES" - PBESv2SHA256AndAES256CBC = "PBESv2 using SHA256 PBKDF2 and AES256 CBC" - - -class KeySerializationEncryption(metaclass=abc.ABCMeta): - pass - - -class BestAvailableEncryption(KeySerializationEncryption): - def __init__(self, password: bytes): - if not isinstance(password, bytes) or len(password) == 0: - raise ValueError("Password must be 1 or more bytes.") - - self.password = password - - -class NoEncryption(KeySerializationEncryption): - pass - - -class KeySerializationEncryptionBuilder: - def __init__( - self, - format: PrivateFormat, - *, - _kdf_rounds: int | None = None, - _hmac_hash: HashAlgorithm | None = None, - _key_cert_algorithm: PBES | None = None, - ) -> None: - self._format = format - - self._kdf_rounds = _kdf_rounds - self._hmac_hash = _hmac_hash - self._key_cert_algorithm = _key_cert_algorithm - - def kdf_rounds(self, rounds: int) -> KeySerializationEncryptionBuilder: - if self._kdf_rounds is not None: - raise ValueError("kdf_rounds already set") - - if not isinstance(rounds, int): - raise TypeError("kdf_rounds must be an integer") - - if rounds < 1: - raise ValueError("kdf_rounds must be a positive integer") - - return KeySerializationEncryptionBuilder( - self._format, - _kdf_rounds=rounds, - _hmac_hash=self._hmac_hash, - _key_cert_algorithm=self._key_cert_algorithm, - ) - - def hmac_hash( - self, algorithm: HashAlgorithm - ) -> KeySerializationEncryptionBuilder: - if self._format is not PrivateFormat.PKCS12: - raise TypeError( - "hmac_hash only supported with PrivateFormat.PKCS12" - ) - - if self._hmac_hash is not None: - raise ValueError("hmac_hash already set") - return KeySerializationEncryptionBuilder( - self._format, - _kdf_rounds=self._kdf_rounds, - _hmac_hash=algorithm, - _key_cert_algorithm=self._key_cert_algorithm, - ) - - def key_cert_algorithm( - self, algorithm: PBES - ) -> KeySerializationEncryptionBuilder: - if self._format is not PrivateFormat.PKCS12: - raise TypeError( - "key_cert_algorithm only supported with PrivateFormat.PKCS12" - ) - if self._key_cert_algorithm is not None: - raise ValueError("key_cert_algorithm already set") - return KeySerializationEncryptionBuilder( - self._format, - _kdf_rounds=self._kdf_rounds, - _hmac_hash=self._hmac_hash, - _key_cert_algorithm=algorithm, - ) - - def build(self, password: bytes) -> KeySerializationEncryption: - if not isinstance(password, bytes) or len(password) == 0: - raise ValueError("Password must be 1 or more bytes.") - - return _KeySerializationEncryption( - self._format, - password, - kdf_rounds=self._kdf_rounds, - hmac_hash=self._hmac_hash, - key_cert_algorithm=self._key_cert_algorithm, - ) - - -class _KeySerializationEncryption(KeySerializationEncryption): - def __init__( - self, - format: PrivateFormat, - password: bytes, - *, - kdf_rounds: int | None, - hmac_hash: HashAlgorithm | None, - key_cert_algorithm: PBES | None, - ): - self._format = format - self.password = password - - self._kdf_rounds = kdf_rounds - self._hmac_hash = hmac_hash - self._key_cert_algorithm = key_cert_algorithm diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/__init__.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/__init__.py deleted file mode 100644 index b509336..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/dh.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/dh.py deleted file mode 100644 index 2f6b834..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/dh.py +++ /dev/null @@ -1,159 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -import abc - -from cryptography.hazmat.bindings._rust import openssl as rust_openssl -from cryptography.hazmat.primitives import _serialization - -generate_parameters = rust_openssl.dh.generate_parameters - - -DHPrivateNumbers = rust_openssl.dh.DHPrivateNumbers -DHPublicNumbers = rust_openssl.dh.DHPublicNumbers -DHParameterNumbers = rust_openssl.dh.DHParameterNumbers - - -class DHParameters(metaclass=abc.ABCMeta): - @abc.abstractmethod - def generate_private_key(self) -> DHPrivateKey: - """ - Generates and returns a DHPrivateKey. - """ - - @abc.abstractmethod - def parameter_bytes( - self, - encoding: _serialization.Encoding, - format: _serialization.ParameterFormat, - ) -> bytes: - """ - Returns the parameters serialized as bytes. - """ - - @abc.abstractmethod - def parameter_numbers(self) -> DHParameterNumbers: - """ - Returns a DHParameterNumbers. - """ - - -DHParametersWithSerialization = DHParameters -DHParameters.register(rust_openssl.dh.DHParameters) - - -class DHPublicKey(metaclass=abc.ABCMeta): - @property - @abc.abstractmethod - def key_size(self) -> int: - """ - The bit length of the prime modulus. - """ - - @abc.abstractmethod - def parameters(self) -> DHParameters: - """ - The DHParameters object associated with this public key. - """ - - @abc.abstractmethod - def public_numbers(self) -> DHPublicNumbers: - """ - Returns a DHPublicNumbers. - """ - - @abc.abstractmethod - def public_bytes( - self, - encoding: _serialization.Encoding, - format: _serialization.PublicFormat, - ) -> bytes: - """ - Returns the key serialized as bytes. - """ - - @abc.abstractmethod - def __eq__(self, other: object) -> bool: - """ - Checks equality. - """ - - @abc.abstractmethod - def __copy__(self) -> DHPublicKey: - """ - Returns a copy. - """ - - @abc.abstractmethod - def __deepcopy__(self, memo: dict) -> DHPublicKey: - """ - Returns a deep copy. - """ - - -DHPublicKeyWithSerialization = DHPublicKey -DHPublicKey.register(rust_openssl.dh.DHPublicKey) - - -class DHPrivateKey(metaclass=abc.ABCMeta): - @property - @abc.abstractmethod - def key_size(self) -> int: - """ - The bit length of the prime modulus. - """ - - @abc.abstractmethod - def public_key(self) -> DHPublicKey: - """ - The DHPublicKey associated with this private key. - """ - - @abc.abstractmethod - def parameters(self) -> DHParameters: - """ - The DHParameters object associated with this private key. - """ - - @abc.abstractmethod - def exchange(self, peer_public_key: DHPublicKey) -> bytes: - """ - Given peer's DHPublicKey, carry out the key exchange and - return shared key as bytes. - """ - - @abc.abstractmethod - def private_numbers(self) -> DHPrivateNumbers: - """ - Returns a DHPrivateNumbers. - """ - - @abc.abstractmethod - def private_bytes( - self, - encoding: _serialization.Encoding, - format: _serialization.PrivateFormat, - encryption_algorithm: _serialization.KeySerializationEncryption, - ) -> bytes: - """ - Returns the key serialized as bytes. - """ - - @abc.abstractmethod - def __copy__(self) -> DHPrivateKey: - """ - Returns a copy. - """ - - @abc.abstractmethod - def __deepcopy__(self, memo: dict) -> DHPrivateKey: - """ - Returns a deep copy. - """ - - -DHPrivateKeyWithSerialization = DHPrivateKey -DHPrivateKey.register(rust_openssl.dh.DHPrivateKey) diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/dsa.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/dsa.py deleted file mode 100644 index f245557..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/dsa.py +++ /dev/null @@ -1,179 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -import abc -import typing - -from cryptography.hazmat.bindings._rust import openssl as rust_openssl -from cryptography.hazmat.primitives import _serialization, hashes -from cryptography.hazmat.primitives.asymmetric import utils as asym_utils -from cryptography.utils import Buffer - - -class DSAParameters(metaclass=abc.ABCMeta): - @abc.abstractmethod - def generate_private_key(self) -> DSAPrivateKey: - """ - Generates and returns a DSAPrivateKey. - """ - - @abc.abstractmethod - def parameter_numbers(self) -> DSAParameterNumbers: - """ - Returns a DSAParameterNumbers. - """ - - -DSAParametersWithNumbers = DSAParameters -DSAParameters.register(rust_openssl.dsa.DSAParameters) - - -class DSAPrivateKey(metaclass=abc.ABCMeta): - @property - @abc.abstractmethod - def key_size(self) -> int: - """ - The bit length of the prime modulus. - """ - - @abc.abstractmethod - def public_key(self) -> DSAPublicKey: - """ - The DSAPublicKey associated with this private key. - """ - - @abc.abstractmethod - def parameters(self) -> DSAParameters: - """ - The DSAParameters object associated with this private key. - """ - - @abc.abstractmethod - def sign( - self, - data: Buffer, - algorithm: asym_utils.Prehashed | hashes.HashAlgorithm, - ) -> bytes: - """ - Signs the data - """ - - @abc.abstractmethod - def private_numbers(self) -> DSAPrivateNumbers: - """ - Returns a DSAPrivateNumbers. - """ - - @abc.abstractmethod - def private_bytes( - self, - encoding: _serialization.Encoding, - format: _serialization.PrivateFormat, - encryption_algorithm: _serialization.KeySerializationEncryption, - ) -> bytes: - """ - Returns the key serialized as bytes. - """ - - @abc.abstractmethod - def __copy__(self) -> DSAPrivateKey: - """ - Returns a copy. - """ - - @abc.abstractmethod - def __deepcopy__(self, memo: dict) -> DSAPrivateKey: - """ - Returns a deep copy. - """ - - -DSAPrivateKeyWithSerialization = DSAPrivateKey -DSAPrivateKey.register(rust_openssl.dsa.DSAPrivateKey) - - -class DSAPublicKey(metaclass=abc.ABCMeta): - @property - @abc.abstractmethod - def key_size(self) -> int: - """ - The bit length of the prime modulus. - """ - - @abc.abstractmethod - def parameters(self) -> DSAParameters: - """ - The DSAParameters object associated with this public key. - """ - - @abc.abstractmethod - def public_numbers(self) -> DSAPublicNumbers: - """ - Returns a DSAPublicNumbers. - """ - - @abc.abstractmethod - def public_bytes( - self, - encoding: _serialization.Encoding, - format: _serialization.PublicFormat, - ) -> bytes: - """ - Returns the key serialized as bytes. - """ - - @abc.abstractmethod - def verify( - self, - signature: Buffer, - data: Buffer, - algorithm: asym_utils.Prehashed | hashes.HashAlgorithm, - ) -> None: - """ - Verifies the signature of the data. - """ - - @abc.abstractmethod - def __eq__(self, other: object) -> bool: - """ - Checks equality. - """ - - @abc.abstractmethod - def __copy__(self) -> DSAPublicKey: - """ - Returns a copy. - """ - - @abc.abstractmethod - def __deepcopy__(self, memo: dict) -> DSAPublicKey: - """ - Returns a deep copy. - """ - - -DSAPublicKeyWithSerialization = DSAPublicKey -DSAPublicKey.register(rust_openssl.dsa.DSAPublicKey) - -DSAPrivateNumbers = rust_openssl.dsa.DSAPrivateNumbers -DSAPublicNumbers = rust_openssl.dsa.DSAPublicNumbers -DSAParameterNumbers = rust_openssl.dsa.DSAParameterNumbers - - -def generate_parameters( - key_size: int, backend: typing.Any = None -) -> DSAParameters: - if key_size not in (1024, 2048, 3072, 4096): - raise ValueError("Key size must be 1024, 2048, 3072, or 4096 bits.") - - return rust_openssl.dsa.generate_parameters(key_size) - - -def generate_private_key( - key_size: int, backend: typing.Any = None -) -> DSAPrivateKey: - parameters = generate_parameters(key_size) - return parameters.generate_private_key() diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/ec.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/ec.py deleted file mode 100644 index 39e6751..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/ec.py +++ /dev/null @@ -1,369 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -import abc -import typing - -from cryptography import utils -from cryptography.exceptions import UnsupportedAlgorithm, _Reasons -from cryptography.hazmat._oid import ObjectIdentifier -from cryptography.hazmat.bindings._rust import openssl as rust_openssl -from cryptography.hazmat.primitives import _serialization, hashes -from cryptography.hazmat.primitives.asymmetric import utils as asym_utils - - -class EllipticCurveOID: - SECP192R1 = ObjectIdentifier("1.2.840.10045.3.1.1") - SECP224R1 = ObjectIdentifier("1.3.132.0.33") - SECP256K1 = ObjectIdentifier("1.3.132.0.10") - SECP256R1 = ObjectIdentifier("1.2.840.10045.3.1.7") - SECP384R1 = ObjectIdentifier("1.3.132.0.34") - SECP521R1 = ObjectIdentifier("1.3.132.0.35") - BRAINPOOLP256R1 = ObjectIdentifier("1.3.36.3.3.2.8.1.1.7") - BRAINPOOLP384R1 = ObjectIdentifier("1.3.36.3.3.2.8.1.1.11") - BRAINPOOLP512R1 = ObjectIdentifier("1.3.36.3.3.2.8.1.1.13") - - -class EllipticCurve(metaclass=abc.ABCMeta): - @property - @abc.abstractmethod - def name(self) -> str: - """ - The name of the curve. e.g. secp256r1. - """ - - @property - @abc.abstractmethod - def key_size(self) -> int: - """ - Bit size of a secret scalar for the curve. - """ - - @property - @abc.abstractmethod - def group_order(self) -> int: - """ - The order of the curve's group. - """ - - -class EllipticCurveSignatureAlgorithm(metaclass=abc.ABCMeta): - @property - @abc.abstractmethod - def algorithm( - self, - ) -> asym_utils.Prehashed | hashes.HashAlgorithm: - """ - The digest algorithm used with this signature. - """ - - -class EllipticCurvePrivateKey(metaclass=abc.ABCMeta): - @abc.abstractmethod - def exchange( - self, algorithm: ECDH, peer_public_key: EllipticCurvePublicKey - ) -> bytes: - """ - Performs a key exchange operation using the provided algorithm with the - provided peer's public key. - """ - - @abc.abstractmethod - def public_key(self) -> EllipticCurvePublicKey: - """ - The EllipticCurvePublicKey for this private key. - """ - - @property - @abc.abstractmethod - def curve(self) -> EllipticCurve: - """ - The EllipticCurve that this key is on. - """ - - @property - @abc.abstractmethod - def key_size(self) -> int: - """ - Bit size of a secret scalar for the curve. - """ - - @abc.abstractmethod - def sign( - self, - data: utils.Buffer, - signature_algorithm: EllipticCurveSignatureAlgorithm, - ) -> bytes: - """ - Signs the data - """ - - @abc.abstractmethod - def private_numbers(self) -> EllipticCurvePrivateNumbers: - """ - Returns an EllipticCurvePrivateNumbers. - """ - - @abc.abstractmethod - def private_bytes( - self, - encoding: _serialization.Encoding, - format: _serialization.PrivateFormat, - encryption_algorithm: _serialization.KeySerializationEncryption, - ) -> bytes: - """ - Returns the key serialized as bytes. - """ - - @abc.abstractmethod - def __copy__(self) -> EllipticCurvePrivateKey: - """ - Returns a copy. - """ - - @abc.abstractmethod - def __deepcopy__(self, memo: dict) -> EllipticCurvePrivateKey: - """ - Returns a deep copy. - """ - - -EllipticCurvePrivateKeyWithSerialization = EllipticCurvePrivateKey -EllipticCurvePrivateKey.register(rust_openssl.ec.ECPrivateKey) - - -class EllipticCurvePublicKey(metaclass=abc.ABCMeta): - @property - @abc.abstractmethod - def curve(self) -> EllipticCurve: - """ - The EllipticCurve that this key is on. - """ - - @property - @abc.abstractmethod - def key_size(self) -> int: - """ - Bit size of a secret scalar for the curve. - """ - - @abc.abstractmethod - def public_numbers(self) -> EllipticCurvePublicNumbers: - """ - Returns an EllipticCurvePublicNumbers. - """ - - @abc.abstractmethod - def public_bytes( - self, - encoding: _serialization.Encoding, - format: _serialization.PublicFormat, - ) -> bytes: - """ - Returns the key serialized as bytes. - """ - - @abc.abstractmethod - def verify( - self, - signature: utils.Buffer, - data: utils.Buffer, - signature_algorithm: EllipticCurveSignatureAlgorithm, - ) -> None: - """ - Verifies the signature of the data. - """ - - @classmethod - def from_encoded_point( - cls, curve: EllipticCurve, data: bytes - ) -> EllipticCurvePublicKey: - utils._check_bytes("data", data) - - if len(data) == 0: - raise ValueError("data must not be an empty byte string") - - if data[0] not in [0x02, 0x03, 0x04]: - raise ValueError("Unsupported elliptic curve point type") - - return rust_openssl.ec.from_public_bytes(curve, data) - - @abc.abstractmethod - def __eq__(self, other: object) -> bool: - """ - Checks equality. - """ - - @abc.abstractmethod - def __copy__(self) -> EllipticCurvePublicKey: - """ - Returns a copy. - """ - - @abc.abstractmethod - def __deepcopy__(self, memo: dict) -> EllipticCurvePublicKey: - """ - Returns a deep copy. - """ - - -EllipticCurvePublicKeyWithSerialization = EllipticCurvePublicKey -EllipticCurvePublicKey.register(rust_openssl.ec.ECPublicKey) - -EllipticCurvePrivateNumbers = rust_openssl.ec.EllipticCurvePrivateNumbers -EllipticCurvePublicNumbers = rust_openssl.ec.EllipticCurvePublicNumbers - - -class SECP521R1(EllipticCurve): - name = "secp521r1" - key_size = 521 - group_order = 0x1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA51868783BF2F966B7FCC0148F709A5D03BB5C9B8899C47AEBB6FB71E91386409 # noqa: E501 - - -class SECP384R1(EllipticCurve): - name = "secp384r1" - key_size = 384 - group_order = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC7634D81F4372DDF581A0DB248B0A77AECEC196ACCC52973 # noqa: E501 - - -class SECP256R1(EllipticCurve): - name = "secp256r1" - key_size = 256 - group_order = ( - 0xFFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551 - ) - - -class SECP256K1(EllipticCurve): - name = "secp256k1" - key_size = 256 - group_order = ( - 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - ) - - -class SECP224R1(EllipticCurve): - name = "secp224r1" - key_size = 224 - group_order = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFF16A2E0B8F03E13DD29455C5C2A3D - - -class SECP192R1(EllipticCurve): - name = "secp192r1" - key_size = 192 - group_order = 0xFFFFFFFFFFFFFFFFFFFFFFFF99DEF836146BC9B1B4D22831 - - -class BrainpoolP256R1(EllipticCurve): - name = "brainpoolP256r1" - key_size = 256 - group_order = ( - 0xA9FB57DBA1EEA9BC3E660A909D838D718C397AA3B561A6F7901E0E82974856A7 - ) - - -class BrainpoolP384R1(EllipticCurve): - name = "brainpoolP384r1" - key_size = 384 - group_order = 0x8CB91E82A3386D280F5D6F7E50E641DF152F7109ED5456B31F166E6CAC0425A7CF3AB6AF6B7FC3103B883202E9046565 # noqa: E501 - - -class BrainpoolP512R1(EllipticCurve): - name = "brainpoolP512r1" - key_size = 512 - group_order = 0xAADD9DB8DBE9C48B3FD4E6AE33C9FC07CB308DB3B3C9D20ED6639CCA70330870553E5C414CA92619418661197FAC10471DB1D381085DDADDB58796829CA90069 # noqa: E501 - - -_CURVE_TYPES: dict[str, EllipticCurve] = { - "prime192v1": SECP192R1(), - "prime256v1": SECP256R1(), - "secp192r1": SECP192R1(), - "secp224r1": SECP224R1(), - "secp256r1": SECP256R1(), - "secp384r1": SECP384R1(), - "secp521r1": SECP521R1(), - "secp256k1": SECP256K1(), - "brainpoolP256r1": BrainpoolP256R1(), - "brainpoolP384r1": BrainpoolP384R1(), - "brainpoolP512r1": BrainpoolP512R1(), -} - - -class ECDSA(EllipticCurveSignatureAlgorithm): - def __init__( - self, - algorithm: asym_utils.Prehashed | hashes.HashAlgorithm, - deterministic_signing: bool = False, - ): - from cryptography.hazmat.backends.openssl.backend import backend - - if ( - deterministic_signing - and not backend.ecdsa_deterministic_supported() - ): - raise UnsupportedAlgorithm( - "ECDSA with deterministic signature (RFC 6979) is not " - "supported by this version of OpenSSL.", - _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM, - ) - self._algorithm = algorithm - self._deterministic_signing = deterministic_signing - - @property - def algorithm( - self, - ) -> asym_utils.Prehashed | hashes.HashAlgorithm: - return self._algorithm - - @property - def deterministic_signing( - self, - ) -> bool: - return self._deterministic_signing - - -generate_private_key = rust_openssl.ec.generate_private_key - - -def derive_private_key( - private_value: int, - curve: EllipticCurve, - backend: typing.Any = None, -) -> EllipticCurvePrivateKey: - if not isinstance(private_value, int): - raise TypeError("private_value must be an integer type.") - - if private_value <= 0: - raise ValueError("private_value must be a positive integer.") - - return rust_openssl.ec.derive_private_key(private_value, curve) - - -class ECDH: - pass - - -_OID_TO_CURVE = { - EllipticCurveOID.SECP192R1: SECP192R1, - EllipticCurveOID.SECP224R1: SECP224R1, - EllipticCurveOID.SECP256K1: SECP256K1, - EllipticCurveOID.SECP256R1: SECP256R1, - EllipticCurveOID.SECP384R1: SECP384R1, - EllipticCurveOID.SECP521R1: SECP521R1, - EllipticCurveOID.BRAINPOOLP256R1: BrainpoolP256R1, - EllipticCurveOID.BRAINPOOLP384R1: BrainpoolP384R1, - EllipticCurveOID.BRAINPOOLP512R1: BrainpoolP512R1, -} - - -def get_curve_for_oid(oid: ObjectIdentifier) -> type[EllipticCurve]: - try: - return _OID_TO_CURVE[oid] - except KeyError: - raise LookupError( - "The provided object identifier has no matching elliptic " - "curve class" - ) diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/ed25519.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/ed25519.py deleted file mode 100644 index 70aec5b..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/ed25519.py +++ /dev/null @@ -1,116 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -import abc - -from cryptography.hazmat.bindings._rust import openssl as rust_openssl -from cryptography.hazmat.primitives import _serialization -from cryptography.utils import Buffer - - -class Ed25519PublicKey(metaclass=abc.ABCMeta): - @classmethod - def from_public_bytes(cls, data: bytes) -> Ed25519PublicKey: - return rust_openssl.ed25519.from_public_bytes(data) - - @abc.abstractmethod - def public_bytes( - self, - encoding: _serialization.Encoding, - format: _serialization.PublicFormat, - ) -> bytes: - """ - The serialized bytes of the public key. - """ - - @abc.abstractmethod - def public_bytes_raw(self) -> bytes: - """ - The raw bytes of the public key. - Equivalent to public_bytes(Raw, Raw). - """ - - @abc.abstractmethod - def verify(self, signature: Buffer, data: Buffer) -> None: - """ - Verify the signature. - """ - - @abc.abstractmethod - def __eq__(self, other: object) -> bool: - """ - Checks equality. - """ - - @abc.abstractmethod - def __copy__(self) -> Ed25519PublicKey: - """ - Returns a copy. - """ - - @abc.abstractmethod - def __deepcopy__(self, memo: dict) -> Ed25519PublicKey: - """ - Returns a deep copy. - """ - - -Ed25519PublicKey.register(rust_openssl.ed25519.Ed25519PublicKey) - - -class Ed25519PrivateKey(metaclass=abc.ABCMeta): - @classmethod - def generate(cls) -> Ed25519PrivateKey: - return rust_openssl.ed25519.generate_key() - - @classmethod - def from_private_bytes(cls, data: Buffer) -> Ed25519PrivateKey: - return rust_openssl.ed25519.from_private_bytes(data) - - @abc.abstractmethod - def public_key(self) -> Ed25519PublicKey: - """ - The Ed25519PublicKey derived from the private key. - """ - - @abc.abstractmethod - def private_bytes( - self, - encoding: _serialization.Encoding, - format: _serialization.PrivateFormat, - encryption_algorithm: _serialization.KeySerializationEncryption, - ) -> bytes: - """ - The serialized bytes of the private key. - """ - - @abc.abstractmethod - def private_bytes_raw(self) -> bytes: - """ - The raw bytes of the private key. - Equivalent to private_bytes(Raw, Raw, NoEncryption()). - """ - - @abc.abstractmethod - def sign(self, data: Buffer) -> bytes: - """ - Signs the data. - """ - - @abc.abstractmethod - def __copy__(self) -> Ed25519PrivateKey: - """ - Returns a copy. - """ - - @abc.abstractmethod - def __deepcopy__(self, memo: dict) -> Ed25519PrivateKey: - """ - Returns a deep copy. - """ - - -Ed25519PrivateKey.register(rust_openssl.ed25519.Ed25519PrivateKey) diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/ed448.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/ed448.py deleted file mode 100644 index 9ecb478..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/ed448.py +++ /dev/null @@ -1,143 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -import abc - -from cryptography.exceptions import UnsupportedAlgorithm, _Reasons -from cryptography.hazmat.bindings._rust import openssl as rust_openssl -from cryptography.hazmat.primitives import _serialization -from cryptography.utils import Buffer - - -class Ed448PublicKey(metaclass=abc.ABCMeta): - @classmethod - def from_public_bytes(cls, data: bytes) -> Ed448PublicKey: - from cryptography.hazmat.backends.openssl.backend import backend - - if not backend.ed448_supported(): - raise UnsupportedAlgorithm( - "ed448 is not supported by this version of OpenSSL.", - _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM, - ) - - return rust_openssl.ed448.from_public_bytes(data) - - @abc.abstractmethod - def public_bytes( - self, - encoding: _serialization.Encoding, - format: _serialization.PublicFormat, - ) -> bytes: - """ - The serialized bytes of the public key. - """ - - @abc.abstractmethod - def public_bytes_raw(self) -> bytes: - """ - The raw bytes of the public key. - Equivalent to public_bytes(Raw, Raw). - """ - - @abc.abstractmethod - def verify(self, signature: Buffer, data: Buffer) -> None: - """ - Verify the signature. - """ - - @abc.abstractmethod - def __eq__(self, other: object) -> bool: - """ - Checks equality. - """ - - @abc.abstractmethod - def __copy__(self) -> Ed448PublicKey: - """ - Returns a copy. - """ - - @abc.abstractmethod - def __deepcopy__(self, memo: dict) -> Ed448PublicKey: - """ - Returns a deep copy. - """ - - -if hasattr(rust_openssl, "ed448"): - Ed448PublicKey.register(rust_openssl.ed448.Ed448PublicKey) - - -class Ed448PrivateKey(metaclass=abc.ABCMeta): - @classmethod - def generate(cls) -> Ed448PrivateKey: - from cryptography.hazmat.backends.openssl.backend import backend - - if not backend.ed448_supported(): - raise UnsupportedAlgorithm( - "ed448 is not supported by this version of OpenSSL.", - _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM, - ) - - return rust_openssl.ed448.generate_key() - - @classmethod - def from_private_bytes(cls, data: Buffer) -> Ed448PrivateKey: - from cryptography.hazmat.backends.openssl.backend import backend - - if not backend.ed448_supported(): - raise UnsupportedAlgorithm( - "ed448 is not supported by this version of OpenSSL.", - _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM, - ) - - return rust_openssl.ed448.from_private_bytes(data) - - @abc.abstractmethod - def public_key(self) -> Ed448PublicKey: - """ - The Ed448PublicKey derived from the private key. - """ - - @abc.abstractmethod - def sign(self, data: Buffer) -> bytes: - """ - Signs the data. - """ - - @abc.abstractmethod - def private_bytes( - self, - encoding: _serialization.Encoding, - format: _serialization.PrivateFormat, - encryption_algorithm: _serialization.KeySerializationEncryption, - ) -> bytes: - """ - The serialized bytes of the private key. - """ - - @abc.abstractmethod - def private_bytes_raw(self) -> bytes: - """ - The raw bytes of the private key. - Equivalent to private_bytes(Raw, Raw, NoEncryption()). - """ - - @abc.abstractmethod - def __copy__(self) -> Ed448PrivateKey: - """ - Returns a copy. - """ - - @abc.abstractmethod - def __deepcopy__(self, memo: dict) -> Ed448PrivateKey: - """ - Returns a deep copy. - """ - - -if hasattr(rust_openssl, "x448"): - Ed448PrivateKey.register(rust_openssl.ed448.Ed448PrivateKey) diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/mldsa.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/mldsa.py deleted file mode 100644 index 0bd9684..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/mldsa.py +++ /dev/null @@ -1,441 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -import abc - -from cryptography.exceptions import UnsupportedAlgorithm, _Reasons -from cryptography.hazmat.bindings._rust import openssl as rust_openssl -from cryptography.hazmat.primitives import _serialization -from cryptography.utils import Buffer - - -class MLDSA44PublicKey(metaclass=abc.ABCMeta): - @classmethod - def from_public_bytes(cls, data: bytes) -> MLDSA44PublicKey: - from cryptography.hazmat.backends.openssl.backend import backend - - if not backend.mldsa_supported(): - raise UnsupportedAlgorithm( - "ML-DSA-44 is not supported by this backend.", - _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM, - ) - - return rust_openssl.mldsa.from_mldsa44_public_bytes(data) - - @abc.abstractmethod - def public_bytes( - self, - encoding: _serialization.Encoding, - format: _serialization.PublicFormat, - ) -> bytes: - """ - The serialized bytes of the public key. - """ - - @abc.abstractmethod - def public_bytes_raw(self) -> bytes: - """ - The raw bytes of the public key. - Equivalent to public_bytes(Raw, Raw). - - The public key is 1,312 bytes for MLDSA-44. - """ - - @abc.abstractmethod - def verify( - self, - signature: Buffer, - data: Buffer, - context: Buffer | None = None, - ) -> None: - """ - Verify the signature. - """ - - @abc.abstractmethod - def __eq__(self, other: object) -> bool: - """ - Checks equality. - """ - - @abc.abstractmethod - def __copy__(self) -> MLDSA44PublicKey: - """ - Returns a copy. - """ - - @abc.abstractmethod - def __deepcopy__(self, memo: dict) -> MLDSA44PublicKey: - """ - Returns a deep copy. - """ - - -if hasattr(rust_openssl, "mldsa"): - MLDSA44PublicKey.register(rust_openssl.mldsa.MLDSA44PublicKey) - - -class MLDSA44PrivateKey(metaclass=abc.ABCMeta): - @classmethod - def generate(cls) -> MLDSA44PrivateKey: - from cryptography.hazmat.backends.openssl.backend import backend - - if not backend.mldsa_supported(): - raise UnsupportedAlgorithm( - "ML-DSA-44 is not supported by this backend.", - _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM, - ) - - return rust_openssl.mldsa.generate_mldsa44_key() - - @classmethod - def from_seed_bytes(cls, data: Buffer) -> MLDSA44PrivateKey: - from cryptography.hazmat.backends.openssl.backend import backend - - if not backend.mldsa_supported(): - raise UnsupportedAlgorithm( - "ML-DSA-44 is not supported by this backend.", - _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM, - ) - - return rust_openssl.mldsa.from_mldsa44_seed_bytes(data) - - @abc.abstractmethod - def public_key(self) -> MLDSA44PublicKey: - """ - The MLDSA44PublicKey derived from the private key. - """ - - @abc.abstractmethod - def private_bytes( - self, - encoding: _serialization.Encoding, - format: _serialization.PrivateFormat, - encryption_algorithm: _serialization.KeySerializationEncryption, - ) -> bytes: - """ - The serialized bytes of the private key. - - This method only returns the serialization of the seed form of the - private key, never the expanded one. - """ - - @abc.abstractmethod - def private_bytes_raw(self) -> bytes: - """ - The raw bytes of the private key. - Equivalent to private_bytes(Raw, Raw, NoEncryption()). - - This method only returns the seed form of the private key (32 bytes). - """ - - @abc.abstractmethod - def sign(self, data: Buffer, context: Buffer | None = None) -> bytes: - """ - Signs the data. - """ - - @abc.abstractmethod - def __copy__(self) -> MLDSA44PrivateKey: - """ - Returns a copy. - """ - - @abc.abstractmethod - def __deepcopy__(self, memo: dict) -> MLDSA44PrivateKey: - """ - Returns a deep copy. - """ - - -if hasattr(rust_openssl, "mldsa"): - MLDSA44PrivateKey.register(rust_openssl.mldsa.MLDSA44PrivateKey) - - -class MLDSA65PublicKey(metaclass=abc.ABCMeta): - @classmethod - def from_public_bytes(cls, data: bytes) -> MLDSA65PublicKey: - from cryptography.hazmat.backends.openssl.backend import backend - - if not backend.mldsa_supported(): - raise UnsupportedAlgorithm( - "ML-DSA-65 is not supported by this backend.", - _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM, - ) - - return rust_openssl.mldsa.from_mldsa65_public_bytes(data) - - @abc.abstractmethod - def public_bytes( - self, - encoding: _serialization.Encoding, - format: _serialization.PublicFormat, - ) -> bytes: - """ - The serialized bytes of the public key. - """ - - @abc.abstractmethod - def public_bytes_raw(self) -> bytes: - """ - The raw bytes of the public key. - Equivalent to public_bytes(Raw, Raw). - - The public key is 1,952 bytes for MLDSA-65. - """ - - @abc.abstractmethod - def verify( - self, - signature: Buffer, - data: Buffer, - context: Buffer | None = None, - ) -> None: - """ - Verify the signature. - """ - - @abc.abstractmethod - def __eq__(self, other: object) -> bool: - """ - Checks equality. - """ - - @abc.abstractmethod - def __copy__(self) -> MLDSA65PublicKey: - """ - Returns a copy. - """ - - @abc.abstractmethod - def __deepcopy__(self, memo: dict) -> MLDSA65PublicKey: - """ - Returns a deep copy. - """ - - -if hasattr(rust_openssl, "mldsa"): - MLDSA65PublicKey.register(rust_openssl.mldsa.MLDSA65PublicKey) - - -class MLDSA65PrivateKey(metaclass=abc.ABCMeta): - @classmethod - def generate(cls) -> MLDSA65PrivateKey: - from cryptography.hazmat.backends.openssl.backend import backend - - if not backend.mldsa_supported(): - raise UnsupportedAlgorithm( - "ML-DSA-65 is not supported by this backend.", - _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM, - ) - - return rust_openssl.mldsa.generate_mldsa65_key() - - @classmethod - def from_seed_bytes(cls, data: Buffer) -> MLDSA65PrivateKey: - from cryptography.hazmat.backends.openssl.backend import backend - - if not backend.mldsa_supported(): - raise UnsupportedAlgorithm( - "ML-DSA-65 is not supported by this backend.", - _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM, - ) - - return rust_openssl.mldsa.from_mldsa65_seed_bytes(data) - - @abc.abstractmethod - def public_key(self) -> MLDSA65PublicKey: - """ - The MLDSA65PublicKey derived from the private key. - """ - - @abc.abstractmethod - def private_bytes( - self, - encoding: _serialization.Encoding, - format: _serialization.PrivateFormat, - encryption_algorithm: _serialization.KeySerializationEncryption, - ) -> bytes: - """ - The serialized bytes of the private key. - - This method only returns the serialization of the seed form of the - private key, never the expanded one. - """ - - @abc.abstractmethod - def private_bytes_raw(self) -> bytes: - """ - The raw bytes of the private key. - Equivalent to private_bytes(Raw, Raw, NoEncryption()). - - This method only returns the seed form of the private key (32 bytes). - """ - - @abc.abstractmethod - def sign(self, data: Buffer, context: Buffer | None = None) -> bytes: - """ - Signs the data. - """ - - @abc.abstractmethod - def __copy__(self) -> MLDSA65PrivateKey: - """ - Returns a copy. - """ - - @abc.abstractmethod - def __deepcopy__(self, memo: dict) -> MLDSA65PrivateKey: - """ - Returns a deep copy. - """ - - -if hasattr(rust_openssl, "mldsa"): - MLDSA65PrivateKey.register(rust_openssl.mldsa.MLDSA65PrivateKey) - - -class MLDSA87PublicKey(metaclass=abc.ABCMeta): - @classmethod - def from_public_bytes(cls, data: bytes) -> MLDSA87PublicKey: - from cryptography.hazmat.backends.openssl.backend import backend - - if not backend.mldsa_supported(): - raise UnsupportedAlgorithm( - "ML-DSA-87 is not supported by this backend.", - _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM, - ) - - return rust_openssl.mldsa.from_mldsa87_public_bytes(data) - - @abc.abstractmethod - def public_bytes( - self, - encoding: _serialization.Encoding, - format: _serialization.PublicFormat, - ) -> bytes: - """ - The serialized bytes of the public key. - """ - - @abc.abstractmethod - def public_bytes_raw(self) -> bytes: - """ - The raw bytes of the public key. - Equivalent to public_bytes(Raw, Raw). - - The public key is 2,592 bytes for MLDSA-87. - """ - - @abc.abstractmethod - def verify( - self, - signature: Buffer, - data: Buffer, - context: Buffer | None = None, - ) -> None: - """ - Verify the signature. - """ - - @abc.abstractmethod - def __eq__(self, other: object) -> bool: - """ - Checks equality. - """ - - @abc.abstractmethod - def __copy__(self) -> MLDSA87PublicKey: - """ - Returns a copy. - """ - - @abc.abstractmethod - def __deepcopy__(self, memo: dict) -> MLDSA87PublicKey: - """ - Returns a deep copy. - """ - - -if hasattr(rust_openssl, "mldsa"): - MLDSA87PublicKey.register(rust_openssl.mldsa.MLDSA87PublicKey) - - -class MLDSA87PrivateKey(metaclass=abc.ABCMeta): - @classmethod - def generate(cls) -> MLDSA87PrivateKey: - from cryptography.hazmat.backends.openssl.backend import backend - - if not backend.mldsa_supported(): - raise UnsupportedAlgorithm( - "ML-DSA-87 is not supported by this backend.", - _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM, - ) - - return rust_openssl.mldsa.generate_mldsa87_key() - - @classmethod - def from_seed_bytes(cls, data: Buffer) -> MLDSA87PrivateKey: - from cryptography.hazmat.backends.openssl.backend import backend - - if not backend.mldsa_supported(): - raise UnsupportedAlgorithm( - "ML-DSA-87 is not supported by this backend.", - _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM, - ) - - return rust_openssl.mldsa.from_mldsa87_seed_bytes(data) - - @abc.abstractmethod - def public_key(self) -> MLDSA87PublicKey: - """ - The MLDSA87PublicKey derived from the private key. - """ - - @abc.abstractmethod - def private_bytes( - self, - encoding: _serialization.Encoding, - format: _serialization.PrivateFormat, - encryption_algorithm: _serialization.KeySerializationEncryption, - ) -> bytes: - """ - The serialized bytes of the private key. - - This method only returns the serialization of the seed form of the - private key, never the expanded one. - """ - - @abc.abstractmethod - def private_bytes_raw(self) -> bytes: - """ - The raw bytes of the private key. - Equivalent to private_bytes(Raw, Raw, NoEncryption()). - - This method only returns the seed form of the private key (32 bytes). - """ - - @abc.abstractmethod - def sign(self, data: Buffer, context: Buffer | None = None) -> bytes: - """ - Signs the data. - """ - - @abc.abstractmethod - def __copy__(self) -> MLDSA87PrivateKey: - """ - Returns a copy. - """ - - @abc.abstractmethod - def __deepcopy__(self, memo: dict) -> MLDSA87PrivateKey: - """ - Returns a deep copy. - """ - - -if hasattr(rust_openssl, "mldsa"): - MLDSA87PrivateKey.register(rust_openssl.mldsa.MLDSA87PrivateKey) diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/mlkem.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/mlkem.py deleted file mode 100644 index 64bca11..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/mlkem.py +++ /dev/null @@ -1,278 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -import abc - -from cryptography.exceptions import UnsupportedAlgorithm, _Reasons -from cryptography.hazmat.bindings._rust import openssl as rust_openssl -from cryptography.hazmat.primitives import _serialization -from cryptography.utils import Buffer - - -class MLKEM768PublicKey(metaclass=abc.ABCMeta): - @classmethod - def from_public_bytes(cls, data: Buffer) -> MLKEM768PublicKey: - from cryptography.hazmat.backends.openssl.backend import backend - - if not backend.mlkem_supported(): - raise UnsupportedAlgorithm( - "ML-KEM-768 is not supported by this backend.", - _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM, - ) - - return rust_openssl.mlkem.from_mlkem768_public_bytes(data) - - @abc.abstractmethod - def encapsulate(self) -> tuple[bytes, bytes]: - """ - Encapsulate: returns (shared_secret, ciphertext). - """ - - @abc.abstractmethod - def public_bytes( - self, - encoding: _serialization.Encoding, - format: _serialization.PublicFormat, - ) -> bytes: - """ - The serialized bytes of the public key. - """ - - @abc.abstractmethod - def public_bytes_raw(self) -> bytes: - """ - The raw bytes of the public key. - Equivalent to public_bytes(Raw, Raw). - - The public key is 1,184 bytes for ML-KEM-768. - """ - - @abc.abstractmethod - def __eq__(self, other: object) -> bool: - """ - Checks equality. - """ - - @abc.abstractmethod - def __copy__(self) -> MLKEM768PublicKey: - """ - Returns a copy. - """ - - @abc.abstractmethod - def __deepcopy__(self, memo: dict) -> MLKEM768PublicKey: - """ - Returns a deep copy. - """ - - -if hasattr(rust_openssl, "mlkem"): - MLKEM768PublicKey.register(rust_openssl.mlkem.MLKEM768PublicKey) - - -class MLKEM768PrivateKey(metaclass=abc.ABCMeta): - @classmethod - def generate(cls) -> MLKEM768PrivateKey: - from cryptography.hazmat.backends.openssl.backend import backend - - if not backend.mlkem_supported(): - raise UnsupportedAlgorithm( - "ML-KEM-768 is not supported by this backend.", - _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM, - ) - - return rust_openssl.mlkem.generate_mlkem768_key() - - @classmethod - def from_seed_bytes(cls, data: Buffer) -> MLKEM768PrivateKey: - from cryptography.hazmat.backends.openssl.backend import backend - - if not backend.mlkem_supported(): - raise UnsupportedAlgorithm( - "ML-KEM-768 is not supported by this backend.", - _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM, - ) - - return rust_openssl.mlkem.from_mlkem768_seed_bytes(data) - - @abc.abstractmethod - def decapsulate(self, ciphertext: Buffer) -> bytes: - """ - Decapsulate: returns shared_secret. - """ - - @abc.abstractmethod - def public_key(self) -> MLKEM768PublicKey: - """ - The MLKEM768PublicKey derived from this private key. - """ - - @abc.abstractmethod - def private_bytes( - self, - encoding: _serialization.Encoding, - format: _serialization.PrivateFormat, - encryption_algorithm: _serialization.KeySerializationEncryption, - ) -> bytes: - """ - The serialized bytes of the private key. - """ - - @abc.abstractmethod - def private_bytes_raw(self) -> bytes: - """ - The raw bytes of the private key (64-byte seed). - Equivalent to private_bytes(Raw, Raw, NoEncryption()). - """ - - @abc.abstractmethod - def __copy__(self) -> MLKEM768PrivateKey: - """ - Returns a copy. - """ - - @abc.abstractmethod - def __deepcopy__(self, memo: dict) -> MLKEM768PrivateKey: - """ - Returns a deep copy. - """ - - -if hasattr(rust_openssl, "mlkem"): - MLKEM768PrivateKey.register(rust_openssl.mlkem.MLKEM768PrivateKey) - - -class MLKEM1024PublicKey(metaclass=abc.ABCMeta): - @classmethod - def from_public_bytes(cls, data: Buffer) -> MLKEM1024PublicKey: - from cryptography.hazmat.backends.openssl.backend import backend - - if not backend.mlkem_supported(): - raise UnsupportedAlgorithm( - "ML-KEM-1024 is not supported by this backend.", - _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM, - ) - - return rust_openssl.mlkem.from_mlkem1024_public_bytes(data) - - @abc.abstractmethod - def encapsulate(self) -> tuple[bytes, bytes]: - """ - Encapsulate: returns (shared_secret, ciphertext). - """ - - @abc.abstractmethod - def public_bytes( - self, - encoding: _serialization.Encoding, - format: _serialization.PublicFormat, - ) -> bytes: - """ - The serialized bytes of the public key. - """ - - @abc.abstractmethod - def public_bytes_raw(self) -> bytes: - """ - The raw bytes of the public key. - Equivalent to public_bytes(Raw, Raw). - - The public key is 1,568 bytes for ML-KEM-1024. - """ - - @abc.abstractmethod - def __eq__(self, other: object) -> bool: - """ - Checks equality. - """ - - @abc.abstractmethod - def __copy__(self) -> MLKEM1024PublicKey: - """ - Returns a copy. - """ - - @abc.abstractmethod - def __deepcopy__(self, memo: dict) -> MLKEM1024PublicKey: - """ - Returns a deep copy. - """ - - -if hasattr(rust_openssl, "mlkem"): - MLKEM1024PublicKey.register(rust_openssl.mlkem.MLKEM1024PublicKey) - - -class MLKEM1024PrivateKey(metaclass=abc.ABCMeta): - @classmethod - def generate(cls) -> MLKEM1024PrivateKey: - from cryptography.hazmat.backends.openssl.backend import backend - - if not backend.mlkem_supported(): - raise UnsupportedAlgorithm( - "ML-KEM-1024 is not supported by this backend.", - _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM, - ) - - return rust_openssl.mlkem.generate_mlkem1024_key() - - @classmethod - def from_seed_bytes(cls, data: Buffer) -> MLKEM1024PrivateKey: - from cryptography.hazmat.backends.openssl.backend import backend - - if not backend.mlkem_supported(): - raise UnsupportedAlgorithm( - "ML-KEM-1024 is not supported by this backend.", - _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM, - ) - - return rust_openssl.mlkem.from_mlkem1024_seed_bytes(data) - - @abc.abstractmethod - def decapsulate(self, ciphertext: Buffer) -> bytes: - """ - Decapsulate: returns shared_secret. - """ - - @abc.abstractmethod - def public_key(self) -> MLKEM1024PublicKey: - """ - The MLKEM1024PublicKey derived from this private key. - """ - - @abc.abstractmethod - def private_bytes( - self, - encoding: _serialization.Encoding, - format: _serialization.PrivateFormat, - encryption_algorithm: _serialization.KeySerializationEncryption, - ) -> bytes: - """ - The serialized bytes of the private key. - """ - - @abc.abstractmethod - def private_bytes_raw(self) -> bytes: - """ - The raw bytes of the private key (64-byte seed). - Equivalent to private_bytes(Raw, Raw, NoEncryption()). - """ - - @abc.abstractmethod - def __copy__(self) -> MLKEM1024PrivateKey: - """ - Returns a copy. - """ - - @abc.abstractmethod - def __deepcopy__(self, memo: dict) -> MLKEM1024PrivateKey: - """ - Returns a deep copy. - """ - - -if hasattr(rust_openssl, "mlkem"): - MLKEM1024PrivateKey.register(rust_openssl.mlkem.MLKEM1024PrivateKey) diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/padding.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/padding.py deleted file mode 100644 index 5121a28..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/padding.py +++ /dev/null @@ -1,111 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -import abc - -from cryptography.hazmat.primitives import hashes -from cryptography.hazmat.primitives._asymmetric import ( - AsymmetricPadding as AsymmetricPadding, -) -from cryptography.hazmat.primitives.asymmetric import rsa - - -class PKCS1v15(AsymmetricPadding): - name = "EMSA-PKCS1-v1_5" - - -class _MaxLength: - "Sentinel value for `MAX_LENGTH`." - - -class _Auto: - "Sentinel value for `AUTO`." - - -class _DigestLength: - "Sentinel value for `DIGEST_LENGTH`." - - -class PSS(AsymmetricPadding): - MAX_LENGTH = _MaxLength() - AUTO = _Auto() - DIGEST_LENGTH = _DigestLength() - name = "EMSA-PSS" - _salt_length: int | _MaxLength | _Auto | _DigestLength - - def __init__( - self, - mgf: MGF, - salt_length: int | _MaxLength | _Auto | _DigestLength, - ) -> None: - self._mgf = mgf - - if not isinstance( - salt_length, (int, _MaxLength, _Auto, _DigestLength) - ): - raise TypeError( - "salt_length must be an integer, MAX_LENGTH, " - "DIGEST_LENGTH, or AUTO" - ) - - if isinstance(salt_length, int) and salt_length < 0: - raise ValueError("salt_length must be zero or greater.") - - self._salt_length = salt_length - - @property - def mgf(self) -> MGF: - return self._mgf - - -class OAEP(AsymmetricPadding): - name = "EME-OAEP" - - def __init__( - self, - mgf: MGF, - algorithm: hashes.HashAlgorithm, - label: bytes | None, - ): - if not isinstance(algorithm, hashes.HashAlgorithm): - raise TypeError("Expected instance of hashes.HashAlgorithm.") - - self._mgf = mgf - self._algorithm = algorithm - self._label = label - - @property - def algorithm(self) -> hashes.HashAlgorithm: - return self._algorithm - - @property - def mgf(self) -> MGF: - return self._mgf - - -class MGF(metaclass=abc.ABCMeta): - _algorithm: hashes.HashAlgorithm - - -class MGF1(MGF): - def __init__(self, algorithm: hashes.HashAlgorithm): - if not isinstance(algorithm, hashes.HashAlgorithm): - raise TypeError("Expected instance of hashes.HashAlgorithm.") - - self._algorithm = algorithm - - -def calculate_max_pss_salt_length( - key: rsa.RSAPrivateKey | rsa.RSAPublicKey, - hash_algorithm: hashes.HashAlgorithm, -) -> int: - if not isinstance(key, (rsa.RSAPrivateKey, rsa.RSAPublicKey)): - raise TypeError("key must be an RSA public or private key") - # bit length - 1 per RFC 3447 - emlen = (key.key_size + 6) // 8 - salt_length = emlen - hash_algorithm.digest_size - 2 - assert salt_length >= 0 - return salt_length diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.py deleted file mode 100644 index d730ceb..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.py +++ /dev/null @@ -1,295 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -import abc -import random -import typing -from math import gcd, lcm - -from cryptography.hazmat.bindings._rust import openssl as rust_openssl -from cryptography.hazmat.primitives import _serialization, hashes -from cryptography.hazmat.primitives._asymmetric import AsymmetricPadding -from cryptography.hazmat.primitives.asymmetric import utils as asym_utils - - -class RSAPrivateKey(metaclass=abc.ABCMeta): - @abc.abstractmethod - def decrypt(self, ciphertext: bytes, padding: AsymmetricPadding) -> bytes: - """ - Decrypts the provided ciphertext. - """ - - @property - @abc.abstractmethod - def key_size(self) -> int: - """ - The bit length of the public modulus. - """ - - @abc.abstractmethod - def public_key(self) -> RSAPublicKey: - """ - The RSAPublicKey associated with this private key. - """ - - @abc.abstractmethod - def sign( - self, - data: bytes, - padding: AsymmetricPadding, - algorithm: asym_utils.Prehashed - | hashes.HashAlgorithm - | asym_utils.NoDigestInfo, - ) -> bytes: - """ - Signs the data. - """ - - @abc.abstractmethod - def private_numbers(self) -> RSAPrivateNumbers: - """ - Returns an RSAPrivateNumbers. - """ - - @abc.abstractmethod - def private_bytes( - self, - encoding: _serialization.Encoding, - format: _serialization.PrivateFormat, - encryption_algorithm: _serialization.KeySerializationEncryption, - ) -> bytes: - """ - Returns the key serialized as bytes. - """ - - @abc.abstractmethod - def __copy__(self) -> RSAPrivateKey: - """ - Returns a copy. - """ - - @abc.abstractmethod - def __deepcopy__(self, memo: dict) -> RSAPrivateKey: - """ - Returns a deep copy. - """ - - -RSAPrivateKeyWithSerialization = RSAPrivateKey -RSAPrivateKey.register(rust_openssl.rsa.RSAPrivateKey) - - -class RSAPublicKey(metaclass=abc.ABCMeta): - @abc.abstractmethod - def encrypt(self, plaintext: bytes, padding: AsymmetricPadding) -> bytes: - """ - Encrypts the given plaintext. - """ - - @property - @abc.abstractmethod - def key_size(self) -> int: - """ - The bit length of the public modulus. - """ - - @abc.abstractmethod - def public_numbers(self) -> RSAPublicNumbers: - """ - Returns an RSAPublicNumbers - """ - - @abc.abstractmethod - def public_bytes( - self, - encoding: _serialization.Encoding, - format: _serialization.PublicFormat, - ) -> bytes: - """ - Returns the key serialized as bytes. - """ - - @abc.abstractmethod - def verify( - self, - signature: bytes, - data: bytes, - padding: AsymmetricPadding, - algorithm: asym_utils.Prehashed | hashes.HashAlgorithm, - ) -> None: - """ - Verifies the signature of the data. - """ - - @abc.abstractmethod - def recover_data_from_signature( - self, - signature: bytes, - padding: AsymmetricPadding, - algorithm: hashes.HashAlgorithm | asym_utils.NoDigestInfo | None, - ) -> bytes: - """ - Recovers the original data from the signature. - """ - - @abc.abstractmethod - def __eq__(self, other: object) -> bool: - """ - Checks equality. - """ - - @abc.abstractmethod - def __copy__(self) -> RSAPublicKey: - """ - Returns a copy. - """ - - @abc.abstractmethod - def __deepcopy__(self, memo: dict) -> RSAPublicKey: - """ - Returns a deep copy. - """ - - -RSAPublicKeyWithSerialization = RSAPublicKey -RSAPublicKey.register(rust_openssl.rsa.RSAPublicKey) - -RSAPrivateNumbers = rust_openssl.rsa.RSAPrivateNumbers -RSAPublicNumbers = rust_openssl.rsa.RSAPublicNumbers - - -def generate_private_key( - public_exponent: int, - key_size: int, - backend: typing.Any = None, -) -> RSAPrivateKey: - _verify_rsa_parameters(public_exponent, key_size) - return rust_openssl.rsa.generate_private_key(public_exponent, key_size) - - -def _verify_rsa_parameters(public_exponent: int, key_size: int) -> None: - if public_exponent not in (3, 65537): - raise ValueError( - "public_exponent must be either 3 (for legacy compatibility) or " - "65537. Almost everyone should choose 65537 here!" - ) - - if key_size < 1024: - raise ValueError("key_size must be at least 1024-bits.") - - -def _modinv(e: int, m: int) -> int: - """ - Modular Multiplicative Inverse. Returns x such that: (x*e) mod m == 1 - """ - x1, x2 = 1, 0 - a, b = e, m - while b > 0: - q, r = divmod(a, b) - xn = x1 - q * x2 - a, b, x1, x2 = b, r, x2, xn - return x1 % m - - -def rsa_crt_iqmp(p: int, q: int) -> int: - """ - Compute the CRT (q ** -1) % p value from RSA primes p and q. - """ - if p <= 1 or q <= 1: - raise ValueError("Values can't be <= 1") - return _modinv(q, p) - - -def rsa_crt_dmp1(private_exponent: int, p: int) -> int: - """ - Compute the CRT private_exponent % (p - 1) value from the RSA - private_exponent (d) and p. - """ - if private_exponent <= 1 or p <= 1: - raise ValueError("Values can't be <= 1") - return private_exponent % (p - 1) - - -def rsa_crt_dmq1(private_exponent: int, q: int) -> int: - """ - Compute the CRT private_exponent % (q - 1) value from the RSA - private_exponent (d) and q. - """ - if private_exponent <= 1 or q <= 1: - raise ValueError("Values can't be <= 1") - return private_exponent % (q - 1) - - -def rsa_recover_private_exponent(e: int, p: int, q: int) -> int: - """ - Compute the RSA private_exponent (d) given the public exponent (e) - and the RSA primes p and q. - - This uses the Carmichael totient function to generate the - smallest possible working value of the private exponent. - """ - # This lambda_n is the Carmichael totient function. - # The original RSA paper uses the Euler totient function - # here: phi_n = (p - 1) * (q - 1) - # Either version of the private exponent will work, but the - # one generated by the older formulation may be larger - # than necessary. (lambda_n always divides phi_n) - if e <= 1 or p <= 1 or q <= 1: - raise ValueError("Values can't be <= 1") - return _modinv(e, lcm(p - 1, q - 1)) - - -# Controls the number of iterations rsa_recover_prime_factors will perform -# to obtain the prime factors. -_MAX_RECOVERY_ATTEMPTS = 500 - - -def rsa_recover_prime_factors(n: int, e: int, d: int) -> tuple[int, int]: - """ - Compute factors p and q from the private exponent d. We assume that n has - no more than two factors. This function is adapted from code in PyCrypto. - """ - # reject invalid values early - if d <= 1 or e <= 1: - raise ValueError("d, e can't be <= 1") - if 17 != pow(17, e * d, n): - raise ValueError("n, d, e don't match") - # See 8.2.2(i) in Handbook of Applied Cryptography. - ktot = d * e - 1 - # The quantity d*e-1 is a multiple of phi(n), even, - # and can be represented as t*2^s. - t = ktot - while t % 2 == 0: - t = t // 2 - # Cycle through all multiplicative inverses in Zn. - # The algorithm is non-deterministic, but there is a 50% chance - # any candidate a leads to successful factoring. - # See "Digitalized Signatures and Public Key Functions as Intractable - # as Factorization", M. Rabin, 1979 - spotted = False - tries = 0 - while not spotted and tries < _MAX_RECOVERY_ATTEMPTS: - a = random.randint(2, n - 1) - tries += 1 - k = t - # Cycle through all values a^{t*2^i}=a^k - while k < ktot: - cand = pow(a, k, n) - # Check if a^k is a non-trivial root of unity (mod n) - if cand != 1 and cand != (n - 1) and pow(cand, 2, n) == 1: - # We have found a number such that (cand-1)(cand+1)=0 (mod n). - # Either of the terms divides n. - p = gcd(cand + 1, n) - spotted = True - break - k *= 2 - if not spotted: - raise ValueError("Unable to compute factors p and q from exponent d.") - # Found ! - q, r = divmod(n, p) - assert r == 0 - p, q = sorted((p, q), reverse=True) - return (p, q) diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/types.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/types.py deleted file mode 100644 index dfd12ce..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/types.py +++ /dev/null @@ -1,123 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -import typing - -from cryptography import utils -from cryptography.hazmat.primitives.asymmetric import ( - dh, - dsa, - ec, - ed448, - ed25519, - mldsa, - mlkem, - rsa, - x448, - x25519, -) - -# Every asymmetric key type -PublicKeyTypes = typing.Union[ - dh.DHPublicKey, - dsa.DSAPublicKey, - rsa.RSAPublicKey, - ec.EllipticCurvePublicKey, - ed25519.Ed25519PublicKey, - ed448.Ed448PublicKey, - mldsa.MLDSA44PublicKey, - mldsa.MLDSA65PublicKey, - mldsa.MLDSA87PublicKey, - mlkem.MLKEM768PublicKey, - mlkem.MLKEM1024PublicKey, - x25519.X25519PublicKey, - x448.X448PublicKey, -] -PUBLIC_KEY_TYPES = PublicKeyTypes -utils.deprecated( - PUBLIC_KEY_TYPES, - __name__, - "Use PublicKeyTypes instead", - utils.DeprecatedIn40, - name="PUBLIC_KEY_TYPES", -) -# Every asymmetric key type -PrivateKeyTypes = typing.Union[ - dh.DHPrivateKey, - ed25519.Ed25519PrivateKey, - ed448.Ed448PrivateKey, - mldsa.MLDSA44PrivateKey, - mldsa.MLDSA65PrivateKey, - mldsa.MLDSA87PrivateKey, - mlkem.MLKEM768PrivateKey, - mlkem.MLKEM1024PrivateKey, - rsa.RSAPrivateKey, - dsa.DSAPrivateKey, - ec.EllipticCurvePrivateKey, - x25519.X25519PrivateKey, - x448.X448PrivateKey, -] -PRIVATE_KEY_TYPES = PrivateKeyTypes -utils.deprecated( - PRIVATE_KEY_TYPES, - __name__, - "Use PrivateKeyTypes instead", - utils.DeprecatedIn40, - name="PRIVATE_KEY_TYPES", -) -# Just the key types we allow to be used for x509 signing. This mirrors -# the certificate public key types -CertificateIssuerPrivateKeyTypes = typing.Union[ - ed25519.Ed25519PrivateKey, - ed448.Ed448PrivateKey, - rsa.RSAPrivateKey, - dsa.DSAPrivateKey, - ec.EllipticCurvePrivateKey, -] -CERTIFICATE_PRIVATE_KEY_TYPES = CertificateIssuerPrivateKeyTypes -utils.deprecated( - CERTIFICATE_PRIVATE_KEY_TYPES, - __name__, - "Use CertificateIssuerPrivateKeyTypes instead", - utils.DeprecatedIn40, - name="CERTIFICATE_PRIVATE_KEY_TYPES", -) -# Just the key types we allow to be used for x509 signing. This mirrors -# the certificate private key types -CertificateIssuerPublicKeyTypes = typing.Union[ - dsa.DSAPublicKey, - rsa.RSAPublicKey, - ec.EllipticCurvePublicKey, - ed25519.Ed25519PublicKey, - ed448.Ed448PublicKey, -] -CERTIFICATE_ISSUER_PUBLIC_KEY_TYPES = CertificateIssuerPublicKeyTypes -utils.deprecated( - CERTIFICATE_ISSUER_PUBLIC_KEY_TYPES, - __name__, - "Use CertificateIssuerPublicKeyTypes instead", - utils.DeprecatedIn40, - name="CERTIFICATE_ISSUER_PUBLIC_KEY_TYPES", -) -# This type removes DHPublicKey. x448/x25519 can be a public key -# but cannot be used in signing so they are allowed here. -CertificatePublicKeyTypes = typing.Union[ - dsa.DSAPublicKey, - rsa.RSAPublicKey, - ec.EllipticCurvePublicKey, - ed25519.Ed25519PublicKey, - ed448.Ed448PublicKey, - x25519.X25519PublicKey, - x448.X448PublicKey, -] -CERTIFICATE_PUBLIC_KEY_TYPES = CertificatePublicKeyTypes -utils.deprecated( - CERTIFICATE_PUBLIC_KEY_TYPES, - __name__, - "Use CertificatePublicKeyTypes instead", - utils.DeprecatedIn40, - name="CERTIFICATE_PUBLIC_KEY_TYPES", -) diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/utils.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/utils.py deleted file mode 100644 index c01c342..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/utils.py +++ /dev/null @@ -1,28 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -from cryptography.hazmat.bindings._rust import asn1 -from cryptography.hazmat.primitives import hashes - -decode_dss_signature = asn1.decode_dss_signature -encode_dss_signature = asn1.encode_dss_signature - - -class NoDigestInfo: - pass - - -class Prehashed: - def __init__(self, algorithm: hashes.HashAlgorithm): - if not isinstance(algorithm, hashes.HashAlgorithm): - raise TypeError("Expected instance of HashAlgorithm.") - - self._algorithm = algorithm - self._digest_size = algorithm.digest_size - - @property - def digest_size(self) -> int: - return self._digest_size diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/x25519.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/x25519.py deleted file mode 100644 index 7498998..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/x25519.py +++ /dev/null @@ -1,134 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -import abc - -from cryptography.exceptions import UnsupportedAlgorithm, _Reasons -from cryptography.hazmat.bindings._rust import openssl as rust_openssl -from cryptography.hazmat.primitives import _serialization -from cryptography.utils import Buffer - - -class X25519PublicKey(metaclass=abc.ABCMeta): - @classmethod - def from_public_bytes(cls, data: bytes) -> X25519PublicKey: - from cryptography.hazmat.backends.openssl.backend import backend - - if not backend.x25519_supported(): - raise UnsupportedAlgorithm( - "X25519 is not supported by this version of OpenSSL.", - _Reasons.UNSUPPORTED_EXCHANGE_ALGORITHM, - ) - - return rust_openssl.x25519.from_public_bytes(data) - - @abc.abstractmethod - def public_bytes( - self, - encoding: _serialization.Encoding, - format: _serialization.PublicFormat, - ) -> bytes: - """ - The serialized bytes of the public key. - """ - - @abc.abstractmethod - def public_bytes_raw(self) -> bytes: - """ - The raw bytes of the public key. - Equivalent to public_bytes(Raw, Raw). - """ - - @abc.abstractmethod - def __eq__(self, other: object) -> bool: - """ - Checks equality. - """ - - @abc.abstractmethod - def __copy__(self) -> X25519PublicKey: - """ - Returns a copy. - """ - - @abc.abstractmethod - def __deepcopy__(self, memo: dict) -> X25519PublicKey: - """ - Returns a deep copy. - """ - - -X25519PublicKey.register(rust_openssl.x25519.X25519PublicKey) - - -class X25519PrivateKey(metaclass=abc.ABCMeta): - @classmethod - def generate(cls) -> X25519PrivateKey: - from cryptography.hazmat.backends.openssl.backend import backend - - if not backend.x25519_supported(): - raise UnsupportedAlgorithm( - "X25519 is not supported by this version of OpenSSL.", - _Reasons.UNSUPPORTED_EXCHANGE_ALGORITHM, - ) - return rust_openssl.x25519.generate_key() - - @classmethod - def from_private_bytes(cls, data: Buffer) -> X25519PrivateKey: - from cryptography.hazmat.backends.openssl.backend import backend - - if not backend.x25519_supported(): - raise UnsupportedAlgorithm( - "X25519 is not supported by this version of OpenSSL.", - _Reasons.UNSUPPORTED_EXCHANGE_ALGORITHM, - ) - - return rust_openssl.x25519.from_private_bytes(data) - - @abc.abstractmethod - def public_key(self) -> X25519PublicKey: - """ - Returns the public key associated with this private key - """ - - @abc.abstractmethod - def private_bytes( - self, - encoding: _serialization.Encoding, - format: _serialization.PrivateFormat, - encryption_algorithm: _serialization.KeySerializationEncryption, - ) -> bytes: - """ - The serialized bytes of the private key. - """ - - @abc.abstractmethod - def private_bytes_raw(self) -> bytes: - """ - The raw bytes of the private key. - Equivalent to private_bytes(Raw, Raw, NoEncryption()). - """ - - @abc.abstractmethod - def exchange(self, peer_public_key: X25519PublicKey) -> bytes: - """ - Performs a key exchange operation using the provided peer's public key. - """ - - @abc.abstractmethod - def __copy__(self) -> X25519PrivateKey: - """ - Returns a copy. - """ - - @abc.abstractmethod - def __deepcopy__(self, memo: dict) -> X25519PrivateKey: - """ - Returns a deep copy. - """ - - -X25519PrivateKey.register(rust_openssl.x25519.X25519PrivateKey) diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/x448.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/x448.py deleted file mode 100644 index b9dc826..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/x448.py +++ /dev/null @@ -1,137 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -import abc - -from cryptography.exceptions import UnsupportedAlgorithm, _Reasons -from cryptography.hazmat.bindings._rust import openssl as rust_openssl -from cryptography.hazmat.primitives import _serialization -from cryptography.utils import Buffer - - -class X448PublicKey(metaclass=abc.ABCMeta): - @classmethod - def from_public_bytes(cls, data: bytes) -> X448PublicKey: - from cryptography.hazmat.backends.openssl.backend import backend - - if not backend.x448_supported(): - raise UnsupportedAlgorithm( - "X448 is not supported by this version of OpenSSL.", - _Reasons.UNSUPPORTED_EXCHANGE_ALGORITHM, - ) - - return rust_openssl.x448.from_public_bytes(data) - - @abc.abstractmethod - def public_bytes( - self, - encoding: _serialization.Encoding, - format: _serialization.PublicFormat, - ) -> bytes: - """ - The serialized bytes of the public key. - """ - - @abc.abstractmethod - def public_bytes_raw(self) -> bytes: - """ - The raw bytes of the public key. - Equivalent to public_bytes(Raw, Raw). - """ - - @abc.abstractmethod - def __eq__(self, other: object) -> bool: - """ - Checks equality. - """ - - @abc.abstractmethod - def __copy__(self) -> X448PublicKey: - """ - Returns a copy. - """ - - @abc.abstractmethod - def __deepcopy__(self, memo: dict) -> X448PublicKey: - """ - Returns a deep copy. - """ - - -if hasattr(rust_openssl, "x448"): - X448PublicKey.register(rust_openssl.x448.X448PublicKey) - - -class X448PrivateKey(metaclass=abc.ABCMeta): - @classmethod - def generate(cls) -> X448PrivateKey: - from cryptography.hazmat.backends.openssl.backend import backend - - if not backend.x448_supported(): - raise UnsupportedAlgorithm( - "X448 is not supported by this version of OpenSSL.", - _Reasons.UNSUPPORTED_EXCHANGE_ALGORITHM, - ) - - return rust_openssl.x448.generate_key() - - @classmethod - def from_private_bytes(cls, data: Buffer) -> X448PrivateKey: - from cryptography.hazmat.backends.openssl.backend import backend - - if not backend.x448_supported(): - raise UnsupportedAlgorithm( - "X448 is not supported by this version of OpenSSL.", - _Reasons.UNSUPPORTED_EXCHANGE_ALGORITHM, - ) - - return rust_openssl.x448.from_private_bytes(data) - - @abc.abstractmethod - def public_key(self) -> X448PublicKey: - """ - Returns the public key associated with this private key - """ - - @abc.abstractmethod - def private_bytes( - self, - encoding: _serialization.Encoding, - format: _serialization.PrivateFormat, - encryption_algorithm: _serialization.KeySerializationEncryption, - ) -> bytes: - """ - The serialized bytes of the private key. - """ - - @abc.abstractmethod - def private_bytes_raw(self) -> bytes: - """ - The raw bytes of the private key. - Equivalent to private_bytes(Raw, Raw, NoEncryption()). - """ - - @abc.abstractmethod - def exchange(self, peer_public_key: X448PublicKey) -> bytes: - """ - Performs a key exchange operation using the provided peer's public key. - """ - - @abc.abstractmethod - def __copy__(self) -> X448PrivateKey: - """ - Returns a copy. - """ - - @abc.abstractmethod - def __deepcopy__(self, memo: dict) -> X448PrivateKey: - """ - Returns a deep copy. - """ - - -if hasattr(rust_openssl, "x448"): - X448PrivateKey.register(rust_openssl.x448.X448PrivateKey) diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/ciphers/__init__.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/ciphers/__init__.py deleted file mode 100644 index 10c15d0..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/ciphers/__init__.py +++ /dev/null @@ -1,27 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -from cryptography.hazmat.primitives._cipheralgorithm import ( - BlockCipherAlgorithm, - CipherAlgorithm, -) -from cryptography.hazmat.primitives.ciphers.base import ( - AEADCipherContext, - AEADDecryptionContext, - AEADEncryptionContext, - Cipher, - CipherContext, -) - -__all__ = [ - "AEADCipherContext", - "AEADDecryptionContext", - "AEADEncryptionContext", - "BlockCipherAlgorithm", - "Cipher", - "CipherAlgorithm", - "CipherContext", -] diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/ciphers/aead.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/ciphers/aead.py deleted file mode 100644 index c8a582d..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/ciphers/aead.py +++ /dev/null @@ -1,23 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -from cryptography.hazmat.bindings._rust import openssl as rust_openssl - -__all__ = [ - "AESCCM", - "AESGCM", - "AESGCMSIV", - "AESOCB3", - "AESSIV", - "ChaCha20Poly1305", -] - -AESGCM = rust_openssl.aead.AESGCM -ChaCha20Poly1305 = rust_openssl.aead.ChaCha20Poly1305 -AESCCM = rust_openssl.aead.AESCCM -AESSIV = rust_openssl.aead.AESSIV -AESOCB3 = rust_openssl.aead.AESOCB3 -AESGCMSIV = rust_openssl.aead.AESGCMSIV diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/ciphers/algorithms.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/ciphers/algorithms.py deleted file mode 100644 index 6b20dd5..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/ciphers/algorithms.py +++ /dev/null @@ -1,138 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -from cryptography import utils -from cryptography.hazmat.decrepit.ciphers.algorithms import ( - ARC4 as ARC4, -) -from cryptography.hazmat.decrepit.ciphers.algorithms import ( - CAST5 as CAST5, -) -from cryptography.hazmat.decrepit.ciphers.algorithms import ( - IDEA as IDEA, -) -from cryptography.hazmat.decrepit.ciphers.algorithms import ( - SEED as SEED, -) -from cryptography.hazmat.decrepit.ciphers.algorithms import ( - Blowfish as Blowfish, -) -from cryptography.hazmat.decrepit.ciphers.algorithms import ( - Camellia as Camellia, -) -from cryptography.hazmat.decrepit.ciphers.algorithms import ( - TripleDES as TripleDES, -) -from cryptography.hazmat.primitives._cipheralgorithm import _verify_key_size -from cryptography.hazmat.primitives.ciphers import ( - BlockCipherAlgorithm, - CipherAlgorithm, -) - - -class AES(BlockCipherAlgorithm): - name = "AES" - block_size = 128 - # 512 added to support AES-256-XTS, which uses 512-bit keys - key_sizes = frozenset([128, 192, 256, 512]) - - def __init__(self, key: utils.Buffer): - self.key = _verify_key_size(self, key) - - @property - def key_size(self) -> int: - return len(self.key) * 8 - - -class AES128(BlockCipherAlgorithm): - name = "AES" - block_size = 128 - key_sizes = frozenset([128]) - key_size = 128 - - def __init__(self, key: utils.Buffer): - self.key = _verify_key_size(self, key) - - -class AES256(BlockCipherAlgorithm): - name = "AES" - block_size = 128 - key_sizes = frozenset([256]) - key_size = 256 - - def __init__(self, key: utils.Buffer): - self.key = _verify_key_size(self, key) - - -utils.deprecated( - Camellia, - __name__, - "Camellia has been moved to " - "cryptography.hazmat.decrepit.ciphers.algorithms.Camellia and " - "will be removed from " - "cryptography.hazmat.primitives.ciphers.algorithms in 49.0.0.", - utils.DeprecatedIn43, - name="Camellia", -) - - -utils.deprecated( - ARC4, - __name__, - "ARC4 has been moved to " - "cryptography.hazmat.decrepit.ciphers.algorithms.ARC4 and " - "will be removed from " - "cryptography.hazmat.primitives.ciphers.algorithms in 48.0.0.", - utils.DeprecatedIn43, - name="ARC4", -) - - -utils.deprecated( - TripleDES, - __name__, - "TripleDES has been moved to " - "cryptography.hazmat.decrepit.ciphers.algorithms.TripleDES and " - "will be removed from " - "cryptography.hazmat.primitives.ciphers.algorithms in 48.0.0.", - utils.DeprecatedIn43, - name="TripleDES", -) - - -class ChaCha20(CipherAlgorithm): - name = "ChaCha20" - key_sizes = frozenset([256]) - - def __init__(self, key: utils.Buffer, nonce: utils.Buffer): - self.key = _verify_key_size(self, key) - utils._check_byteslike("nonce", nonce) - - if len(nonce) != 16: - raise ValueError("nonce must be 128-bits (16 bytes)") - - self._nonce = nonce - - @property - def nonce(self) -> utils.Buffer: - return self._nonce - - @property - def key_size(self) -> int: - return len(self.key) * 8 - - -class SM4(BlockCipherAlgorithm): - name = "SM4" - block_size = 128 - key_sizes = frozenset([128]) - - def __init__(self, key: bytes): - self.key = _verify_key_size(self, key) - - @property - def key_size(self) -> int: - return len(self.key) * 8 diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/ciphers/base.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/ciphers/base.py deleted file mode 100644 index 24fceea..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/ciphers/base.py +++ /dev/null @@ -1,146 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -import abc -import typing - -from cryptography.hazmat.bindings._rust import openssl as rust_openssl -from cryptography.hazmat.primitives._cipheralgorithm import CipherAlgorithm -from cryptography.hazmat.primitives.ciphers import modes -from cryptography.utils import Buffer - - -class CipherContext(metaclass=abc.ABCMeta): - @abc.abstractmethod - def update(self, data: Buffer) -> bytes: - """ - Processes the provided bytes through the cipher and returns the results - as bytes. - """ - - @abc.abstractmethod - def update_into(self, data: Buffer, buf: Buffer) -> int: - """ - Processes the provided bytes and writes the resulting data into the - provided buffer. Returns the number of bytes written. - """ - - @abc.abstractmethod - def finalize(self) -> bytes: - """ - Returns the results of processing the final block as bytes. - """ - - @abc.abstractmethod - def reset_nonce(self, nonce: bytes) -> None: - """ - Resets the nonce for the cipher context to the provided value. - Raises an exception if it does not support reset or if the - provided nonce does not have a valid length. - """ - - -class AEADCipherContext(CipherContext, metaclass=abc.ABCMeta): - @abc.abstractmethod - def authenticate_additional_data(self, data: Buffer) -> None: - """ - Authenticates the provided bytes. - """ - - -class AEADDecryptionContext(AEADCipherContext, metaclass=abc.ABCMeta): - @abc.abstractmethod - def finalize_with_tag(self, tag: bytes) -> bytes: - """ - Returns the results of processing the final block as bytes and allows - delayed passing of the authentication tag. - """ - - -class AEADEncryptionContext(AEADCipherContext, metaclass=abc.ABCMeta): - @property - @abc.abstractmethod - def tag(self) -> bytes: - """ - Returns tag bytes. This is only available after encryption is - finalized. - """ - - -Mode = typing.TypeVar( - "Mode", bound=typing.Optional[modes.Mode], covariant=True -) - - -class Cipher(typing.Generic[Mode]): - def __init__( - self, - algorithm: CipherAlgorithm, - mode: Mode, - backend: typing.Any = None, - ) -> None: - if not isinstance(algorithm, CipherAlgorithm): - raise TypeError("Expected interface of CipherAlgorithm.") - - if mode is not None: - # mypy needs this assert to narrow the type from our generic - # type. Maybe it won't some time in the future. - assert isinstance(mode, modes.Mode) - mode.validate_for_algorithm(algorithm) - - self.algorithm = algorithm - self.mode = mode - - @typing.overload - def encryptor( - self: Cipher[modes.ModeWithAuthenticationTag], - ) -> AEADEncryptionContext: ... - - @typing.overload - def encryptor( - self: _CIPHER_TYPE, - ) -> CipherContext: ... - - def encryptor(self): - if isinstance(self.mode, modes.ModeWithAuthenticationTag): - if self.mode.tag is not None: - raise ValueError( - "Authentication tag must be None when encrypting." - ) - - return rust_openssl.ciphers.create_encryption_ctx( - self.algorithm, self.mode - ) - - @typing.overload - def decryptor( - self: Cipher[modes.ModeWithAuthenticationTag], - ) -> AEADDecryptionContext: ... - - @typing.overload - def decryptor( - self: _CIPHER_TYPE, - ) -> CipherContext: ... - - def decryptor(self): - return rust_openssl.ciphers.create_decryption_ctx( - self.algorithm, self.mode - ) - - -_CIPHER_TYPE = Cipher[ - typing.Union[ - modes.ModeWithNonce, - modes.ModeWithTweak, - modes.ECB, - modes.ModeWithInitializationVector, - None, - ] -] - -CipherContext.register(rust_openssl.ciphers.CipherContext) -AEADEncryptionContext.register(rust_openssl.ciphers.AEADEncryptionContext) -AEADDecryptionContext.register(rust_openssl.ciphers.AEADDecryptionContext) diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/ciphers/modes.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/ciphers/modes.py deleted file mode 100644 index 0f1c217..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/ciphers/modes.py +++ /dev/null @@ -1,192 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -from cryptography import utils -from cryptography.exceptions import UnsupportedAlgorithm, _Reasons -from cryptography.hazmat.decrepit.ciphers.modes import CFB as CFB -from cryptography.hazmat.decrepit.ciphers.modes import CFB8 as CFB8 -from cryptography.hazmat.decrepit.ciphers.modes import OFB as OFB -from cryptography.hazmat.primitives._cipheralgorithm import ( - BlockCipherAlgorithm, - CipherAlgorithm, -) -from cryptography.hazmat.primitives._modes import ( - Mode as Mode, -) -from cryptography.hazmat.primitives._modes import ( - ModeWithAuthenticationTag as ModeWithAuthenticationTag, -) -from cryptography.hazmat.primitives._modes import ( - ModeWithInitializationVector as ModeWithInitializationVector, -) -from cryptography.hazmat.primitives._modes import ( - ModeWithNonce as ModeWithNonce, -) -from cryptography.hazmat.primitives._modes import ( - ModeWithTweak as ModeWithTweak, -) -from cryptography.hazmat.primitives._modes import ( - _check_aes_key_length, - _check_iv_and_key_length, - _check_nonce_length, -) -from cryptography.hazmat.primitives.ciphers import algorithms - - -class CBC(ModeWithInitializationVector): - name = "CBC" - - def __init__(self, initialization_vector: utils.Buffer): - utils._check_byteslike("initialization_vector", initialization_vector) - self._initialization_vector = initialization_vector - - @property - def initialization_vector(self) -> utils.Buffer: - return self._initialization_vector - - validate_for_algorithm = _check_iv_and_key_length - - -class XTS(ModeWithTweak): - name = "XTS" - - def __init__(self, tweak: utils.Buffer): - utils._check_byteslike("tweak", tweak) - - if len(tweak) != 16: - raise ValueError("tweak must be 128-bits (16 bytes)") - - self._tweak = tweak - - @property - def tweak(self) -> utils.Buffer: - return self._tweak - - def validate_for_algorithm(self, algorithm: CipherAlgorithm) -> None: - if isinstance(algorithm, (algorithms.AES128, algorithms.AES256)): - raise TypeError( - "The AES128 and AES256 classes do not support XTS, please use " - "the standard AES class instead." - ) - - if algorithm.key_size not in (256, 512): - raise ValueError( - "The XTS specification requires a 256-bit key for AES-128-XTS" - " and 512-bit key for AES-256-XTS" - ) - - -class ECB(Mode): - name = "ECB" - - validate_for_algorithm = _check_aes_key_length - - -class CTR(ModeWithNonce): - name = "CTR" - - def __init__(self, nonce: utils.Buffer): - utils._check_byteslike("nonce", nonce) - self._nonce = nonce - - @property - def nonce(self) -> utils.Buffer: - return self._nonce - - def validate_for_algorithm(self, algorithm: CipherAlgorithm) -> None: - _check_aes_key_length(self, algorithm) - _check_nonce_length(self.nonce, self.name, algorithm) - - -class GCM(ModeWithInitializationVector, ModeWithAuthenticationTag): - name = "GCM" - _MAX_ENCRYPTED_BYTES = (2**39 - 256) // 8 - _MAX_AAD_BYTES = (2**64) // 8 - - def __init__( - self, - initialization_vector: utils.Buffer, - tag: bytes | None = None, - min_tag_length: int = 16, - ): - # OpenSSL 3.0.0 constrains GCM IVs to [64, 1024] bits inclusive - # This is a sane limit anyway so we'll enforce it here. - utils._check_byteslike("initialization_vector", initialization_vector) - if len(initialization_vector) < 8 or len(initialization_vector) > 128: - raise ValueError( - "initialization_vector must be between 8 and 128 bytes (64 " - "and 1024 bits)." - ) - self._initialization_vector = initialization_vector - if tag is not None: - utils._check_bytes("tag", tag) - if min_tag_length < 4: - raise ValueError("min_tag_length must be >= 4") - if len(tag) < min_tag_length: - raise ValueError( - f"Authentication tag must be {min_tag_length} bytes or " - "longer." - ) - self._tag = tag - self._min_tag_length = min_tag_length - - @property - def tag(self) -> bytes | None: - return self._tag - - @property - def initialization_vector(self) -> utils.Buffer: - return self._initialization_vector - - def validate_for_algorithm(self, algorithm: CipherAlgorithm) -> None: - _check_aes_key_length(self, algorithm) - if not isinstance(algorithm, BlockCipherAlgorithm): - raise UnsupportedAlgorithm( - "GCM requires a block cipher algorithm", - _Reasons.UNSUPPORTED_CIPHER, - ) - block_size_bytes = algorithm.block_size // 8 - if self._tag is not None and len(self._tag) > block_size_bytes: - raise ValueError( - f"Authentication tag cannot be more than {block_size_bytes} " - "bytes." - ) - - -utils.deprecated( - OFB, - __name__, - "OFB has been moved to " - "cryptography.hazmat.decrepit.ciphers.modes.OFB and " - "will be removed from " - "cryptography.hazmat.primitives.ciphers.modes in 49.0.0.", - utils.DeprecatedIn47, - name="OFB", -) - - -utils.deprecated( - CFB, - __name__, - "CFB has been moved to " - "cryptography.hazmat.decrepit.ciphers.modes.CFB and " - "will be removed from " - "cryptography.hazmat.primitives.ciphers.modes in 49.0.0.", - utils.DeprecatedIn47, - name="CFB", -) - - -utils.deprecated( - CFB8, - __name__, - "CFB8 has been moved to " - "cryptography.hazmat.decrepit.ciphers.modes.CFB8 and " - "will be removed from " - "cryptography.hazmat.primitives.ciphers.modes in 49.0.0.", - utils.DeprecatedIn47, - name="CFB8", -) diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/cmac.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/cmac.py deleted file mode 100644 index 2c67ce2..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/cmac.py +++ /dev/null @@ -1,10 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -from cryptography.hazmat.bindings._rust import openssl as rust_openssl - -__all__ = ["CMAC"] -CMAC = rust_openssl.cmac.CMAC diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/constant_time.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/constant_time.py deleted file mode 100644 index 3975c71..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/constant_time.py +++ /dev/null @@ -1,14 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -import hmac - - -def bytes_eq(a: bytes, b: bytes) -> bool: - if not isinstance(a, bytes) or not isinstance(b, bytes): - raise TypeError("a and b must be bytes.") - - return hmac.compare_digest(a, b) diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/hashes.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/hashes.py deleted file mode 100644 index 4b55ec3..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/hashes.py +++ /dev/null @@ -1,246 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -import abc - -from cryptography.hazmat.bindings._rust import openssl as rust_openssl -from cryptography.utils import Buffer - -__all__ = [ - "MD5", - "SHA1", - "SHA3_224", - "SHA3_256", - "SHA3_384", - "SHA3_512", - "SHA224", - "SHA256", - "SHA384", - "SHA512", - "SHA512_224", - "SHA512_256", - "SHAKE128", - "SHAKE256", - "SM3", - "BLAKE2b", - "BLAKE2s", - "ExtendableOutputFunction", - "Hash", - "HashAlgorithm", - "HashContext", - "XOFHash", -] - - -class HashAlgorithm(metaclass=abc.ABCMeta): - @property - @abc.abstractmethod - def name(self) -> str: - """ - A string naming this algorithm (e.g. "sha256", "md5"). - """ - - @property - @abc.abstractmethod - def digest_size(self) -> int: - """ - The size of the resulting digest in bytes. - """ - - @property - @abc.abstractmethod - def block_size(self) -> int | None: - """ - The internal block size of the hash function, or None if the hash - function does not use blocks internally (e.g. SHA3). - """ - - -class HashContext(metaclass=abc.ABCMeta): - @property - @abc.abstractmethod - def algorithm(self) -> HashAlgorithm: - """ - A HashAlgorithm that will be used by this context. - """ - - @abc.abstractmethod - def update(self, data: Buffer) -> None: - """ - Processes the provided bytes through the hash. - """ - - @abc.abstractmethod - def finalize(self) -> bytes: - """ - Finalizes the hash context and returns the hash digest as bytes. - """ - - @abc.abstractmethod - def copy(self) -> HashContext: - """ - Return a HashContext that is a copy of the current context. - """ - - -Hash = rust_openssl.hashes.Hash -HashContext.register(Hash) - -XOFHash = rust_openssl.hashes.XOFHash - - -class ExtendableOutputFunction(metaclass=abc.ABCMeta): - """ - An interface for extendable output functions. - """ - - -class SHA1(HashAlgorithm): - name = "sha1" - digest_size = 20 - block_size = 64 - - -class SHA512_224(HashAlgorithm): # noqa: N801 - name = "sha512-224" - digest_size = 28 - block_size = 128 - - -class SHA512_256(HashAlgorithm): # noqa: N801 - name = "sha512-256" - digest_size = 32 - block_size = 128 - - -class SHA224(HashAlgorithm): - name = "sha224" - digest_size = 28 - block_size = 64 - - -class SHA256(HashAlgorithm): - name = "sha256" - digest_size = 32 - block_size = 64 - - -class SHA384(HashAlgorithm): - name = "sha384" - digest_size = 48 - block_size = 128 - - -class SHA512(HashAlgorithm): - name = "sha512" - digest_size = 64 - block_size = 128 - - -class SHA3_224(HashAlgorithm): # noqa: N801 - name = "sha3-224" - digest_size = 28 - block_size = None - - -class SHA3_256(HashAlgorithm): # noqa: N801 - name = "sha3-256" - digest_size = 32 - block_size = None - - -class SHA3_384(HashAlgorithm): # noqa: N801 - name = "sha3-384" - digest_size = 48 - block_size = None - - -class SHA3_512(HashAlgorithm): # noqa: N801 - name = "sha3-512" - digest_size = 64 - block_size = None - - -class SHAKE128(HashAlgorithm, ExtendableOutputFunction): - name = "shake128" - block_size = None - - def __init__(self, digest_size: int): - if not isinstance(digest_size, int): - raise TypeError("digest_size must be an integer") - - if digest_size < 1: - raise ValueError("digest_size must be a positive integer") - - self._digest_size = digest_size - - @property - def digest_size(self) -> int: - return self._digest_size - - -class SHAKE256(HashAlgorithm, ExtendableOutputFunction): - name = "shake256" - block_size = None - - def __init__(self, digest_size: int): - if not isinstance(digest_size, int): - raise TypeError("digest_size must be an integer") - - if digest_size < 1: - raise ValueError("digest_size must be a positive integer") - - self._digest_size = digest_size - - @property - def digest_size(self) -> int: - return self._digest_size - - -class MD5(HashAlgorithm): - name = "md5" - digest_size = 16 - block_size = 64 - - -class BLAKE2b(HashAlgorithm): - name = "blake2b" - _max_digest_size = 64 - _min_digest_size = 1 - block_size = 128 - - def __init__(self, digest_size: int): - if digest_size != 64: - raise ValueError("Digest size must be 64") - - self._digest_size = digest_size - - @property - def digest_size(self) -> int: - return self._digest_size - - -class BLAKE2s(HashAlgorithm): - name = "blake2s" - block_size = 64 - _max_digest_size = 32 - _min_digest_size = 1 - - def __init__(self, digest_size: int): - if digest_size != 32: - raise ValueError("Digest size must be 32") - - self._digest_size = digest_size - - @property - def digest_size(self) -> int: - return self._digest_size - - -class SM3(HashAlgorithm): - name = "sm3" - digest_size = 32 - block_size = 64 diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/hmac.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/hmac.py deleted file mode 100644 index a9442d5..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/hmac.py +++ /dev/null @@ -1,13 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -from cryptography.hazmat.bindings._rust import openssl as rust_openssl -from cryptography.hazmat.primitives import hashes - -__all__ = ["HMAC"] - -HMAC = rust_openssl.hmac.HMAC -hashes.HashContext.register(HMAC) diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/hpke.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/hpke.py deleted file mode 100644 index c802808..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/hpke.py +++ /dev/null @@ -1,27 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -from cryptography.hazmat.bindings._rust import openssl as rust_openssl - -AEAD = rust_openssl.hpke.AEAD -KDF = rust_openssl.hpke.KDF -KEM = rust_openssl.hpke.KEM -MLKEM768X25519PrivateKey = rust_openssl.hpke.MLKEM768X25519PrivateKey -MLKEM768X25519PublicKey = rust_openssl.hpke.MLKEM768X25519PublicKey -MLKEM1024P384PrivateKey = rust_openssl.hpke.MLKEM1024P384PrivateKey -MLKEM1024P384PublicKey = rust_openssl.hpke.MLKEM1024P384PublicKey -Suite = rust_openssl.hpke.Suite - -__all__ = [ - "AEAD", - "KDF", - "KEM", - "MLKEM768X25519PrivateKey", - "MLKEM768X25519PublicKey", - "MLKEM1024P384PrivateKey", - "MLKEM1024P384PublicKey", - "Suite", -] diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/kdf/__init__.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/kdf/__init__.py deleted file mode 100644 index 26c45bd..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/kdf/__init__.py +++ /dev/null @@ -1,32 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -import abc - -from cryptography.utils import Buffer - - -class KeyDerivationFunction(metaclass=abc.ABCMeta): - @abc.abstractmethod - def derive(self, key_material: bytes) -> bytes: - """ - Deterministically generates and returns a new key based on the existing - key material. - """ - - @abc.abstractmethod - def derive_into(self, key_material: bytes, buffer: Buffer) -> None: - """ - Deterministically generates a new key based on the existing key - material and stores it in the provided buffer. - """ - - @abc.abstractmethod - def verify(self, key_material: bytes, expected_key: bytes) -> None: - """ - Checks whether the key generated by the key material matches the - expected derived key. Raises an exception if they do not match. - """ diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/kdf/argon2.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/kdf/argon2.py deleted file mode 100644 index 03e84d4..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/kdf/argon2.py +++ /dev/null @@ -1,17 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -from cryptography.hazmat.bindings._rust import openssl as rust_openssl -from cryptography.hazmat.primitives.kdf import KeyDerivationFunction - -Argon2d = rust_openssl.kdf.Argon2d -Argon2i = rust_openssl.kdf.Argon2i -Argon2id = rust_openssl.kdf.Argon2id -KeyDerivationFunction.register(Argon2d) -KeyDerivationFunction.register(Argon2i) -KeyDerivationFunction.register(Argon2id) - -__all__ = ["Argon2d", "Argon2i", "Argon2id"] diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/kdf/concatkdf.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/kdf/concatkdf.py deleted file mode 100644 index 398dc5d..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/kdf/concatkdf.py +++ /dev/null @@ -1,16 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -from cryptography.hazmat.bindings._rust import openssl as rust_openssl -from cryptography.hazmat.primitives.kdf import KeyDerivationFunction - -ConcatKDFHash = rust_openssl.kdf.ConcatKDFHash -ConcatKDFHMAC = rust_openssl.kdf.ConcatKDFHMAC - -KeyDerivationFunction.register(ConcatKDFHash) -KeyDerivationFunction.register(ConcatKDFHMAC) - -__all__ = ["ConcatKDFHMAC", "ConcatKDFHash"] diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/kdf/hkdf.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/kdf/hkdf.py deleted file mode 100644 index 1e162d9..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/kdf/hkdf.py +++ /dev/null @@ -1,16 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -from cryptography.hazmat.bindings._rust import openssl as rust_openssl -from cryptography.hazmat.primitives.kdf import KeyDerivationFunction - -HKDF = rust_openssl.kdf.HKDF -HKDFExpand = rust_openssl.kdf.HKDFExpand - -KeyDerivationFunction.register(HKDF) -KeyDerivationFunction.register(HKDFExpand) - -__all__ = ["HKDF", "HKDFExpand"] diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/kdf/kbkdf.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/kdf/kbkdf.py deleted file mode 100644 index e559df8..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/kdf/kbkdf.py +++ /dev/null @@ -1,26 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -from cryptography import utils -from cryptography.hazmat.bindings._rust import openssl as rust_openssl -from cryptography.hazmat.primitives.kdf import KeyDerivationFunction - - -class Mode(utils.Enum): - CounterMode = "ctr" - - -class CounterLocation(utils.Enum): - BeforeFixed = "before_fixed" - AfterFixed = "after_fixed" - MiddleFixed = "middle_fixed" - - -KBKDFHMAC = rust_openssl.kdf.KBKDFHMAC -KeyDerivationFunction.register(KBKDFHMAC) - -KBKDFCMAC = rust_openssl.kdf.KBKDFCMAC -KeyDerivationFunction.register(KBKDFCMAC) diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/kdf/pbkdf2.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/kdf/pbkdf2.py deleted file mode 100644 index 771d80d..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/kdf/pbkdf2.py +++ /dev/null @@ -1,13 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -from cryptography.hazmat.bindings._rust import openssl as rust_openssl -from cryptography.hazmat.primitives.kdf import KeyDerivationFunction - -PBKDF2HMAC = rust_openssl.kdf.PBKDF2HMAC -KeyDerivationFunction.register(PBKDF2HMAC) - -__all__ = ["PBKDF2HMAC"] diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/kdf/scrypt.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/kdf/scrypt.py deleted file mode 100644 index f791cee..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/kdf/scrypt.py +++ /dev/null @@ -1,19 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -import sys - -from cryptography.hazmat.bindings._rust import openssl as rust_openssl -from cryptography.hazmat.primitives.kdf import KeyDerivationFunction - -# This is used by the scrypt tests to skip tests that require more memory -# than the MEM_LIMIT -_MEM_LIMIT = sys.maxsize // 2 - -Scrypt = rust_openssl.kdf.Scrypt -KeyDerivationFunction.register(Scrypt) - -__all__ = ["Scrypt"] diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/kdf/x963kdf.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/kdf/x963kdf.py deleted file mode 100644 index 8c4e2d3..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/kdf/x963kdf.py +++ /dev/null @@ -1,13 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -from cryptography.hazmat.bindings._rust import openssl as rust_openssl -from cryptography.hazmat.primitives.kdf import KeyDerivationFunction - -X963KDF = rust_openssl.kdf.X963KDF -KeyDerivationFunction.register(X963KDF) - -__all__ = ["X963KDF"] diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/keywrap.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/keywrap.py deleted file mode 100644 index a3e56b9..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/keywrap.py +++ /dev/null @@ -1,180 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -import typing - -from cryptography.hazmat.primitives.ciphers import Cipher -from cryptography.hazmat.primitives.ciphers.algorithms import AES -from cryptography.hazmat.primitives.ciphers.modes import ECB -from cryptography.hazmat.primitives.constant_time import bytes_eq - - -def _wrap_core( - wrapping_key: bytes, - a: bytes, - r: list[bytes], -) -> bytes: - # RFC 3394 Key Wrap - 2.2.1 (index method) - encryptor = Cipher(AES(wrapping_key), ECB()).encryptor() - n = len(r) - for j in range(6): - for i in range(n): - # every encryption operation is a discrete 16 byte chunk (because - # AES has a 128-bit block size) and since we're using ECB it is - # safe to reuse the encryptor for the entire operation - b = encryptor.update(a + r[i]) - a = ( - int.from_bytes(b[:8], byteorder="big") ^ ((n * j) + i + 1) - ).to_bytes(length=8, byteorder="big") - r[i] = b[-8:] - - assert encryptor.finalize() == b"" - - return a + b"".join(r) - - -def aes_key_wrap( - wrapping_key: bytes, - key_to_wrap: bytes, - backend: typing.Any = None, -) -> bytes: - if len(wrapping_key) not in [16, 24, 32]: - raise ValueError("The wrapping key must be a valid AES key length") - - if len(key_to_wrap) < 16: - raise ValueError("The key to wrap must be at least 16 bytes") - - if len(key_to_wrap) % 8 != 0: - raise ValueError("The key to wrap must be a multiple of 8 bytes") - - a = b"\xa6\xa6\xa6\xa6\xa6\xa6\xa6\xa6" - r = [key_to_wrap[i : i + 8] for i in range(0, len(key_to_wrap), 8)] - return _wrap_core(wrapping_key, a, r) - - -def _unwrap_core( - wrapping_key: bytes, - a: bytes, - r: list[bytes], -) -> tuple[bytes, list[bytes]]: - # Implement RFC 3394 Key Unwrap - 2.2.2 (index method) - decryptor = Cipher(AES(wrapping_key), ECB()).decryptor() - n = len(r) - for j in reversed(range(6)): - for i in reversed(range(n)): - atr = ( - int.from_bytes(a, byteorder="big") ^ ((n * j) + i + 1) - ).to_bytes(length=8, byteorder="big") + r[i] - # every decryption operation is a discrete 16 byte chunk so - # it is safe to reuse the decryptor for the entire operation - b = decryptor.update(atr) - a = b[:8] - r[i] = b[-8:] - - assert decryptor.finalize() == b"" - return a, r - - -def aes_key_wrap_with_padding( - wrapping_key: bytes, - key_to_wrap: bytes, - backend: typing.Any = None, -) -> bytes: - if len(wrapping_key) not in [16, 24, 32]: - raise ValueError("The wrapping key must be a valid AES key length") - - if not key_to_wrap or len(key_to_wrap) > 2**32: - raise ValueError("key_to_wrap must be between 1 and 2^32 bytes") - - aiv = b"\xa6\x59\x59\xa6" + len(key_to_wrap).to_bytes( - length=4, byteorder="big" - ) - # pad the key to wrap if necessary - pad = (8 - (len(key_to_wrap) % 8)) % 8 - key_to_wrap = key_to_wrap + b"\x00" * pad - if len(key_to_wrap) == 8: - # RFC 5649 - 4.1 - exactly 8 octets after padding - encryptor = Cipher(AES(wrapping_key), ECB()).encryptor() - b = encryptor.update(aiv + key_to_wrap) - assert encryptor.finalize() == b"" - return b - else: - r = [key_to_wrap[i : i + 8] for i in range(0, len(key_to_wrap), 8)] - return _wrap_core(wrapping_key, aiv, r) - - -def aes_key_unwrap_with_padding( - wrapping_key: bytes, - wrapped_key: bytes, - backend: typing.Any = None, -) -> bytes: - if len(wrapped_key) < 16: - raise InvalidUnwrap("Must be at least 16 bytes") - - if len(wrapping_key) not in [16, 24, 32]: - raise ValueError("The wrapping key must be a valid AES key length") - - if len(wrapped_key) == 16: - # RFC 5649 - 4.2 - exactly two 64-bit blocks - decryptor = Cipher(AES(wrapping_key), ECB()).decryptor() - out = decryptor.update(wrapped_key) - assert decryptor.finalize() == b"" - a = out[:8] - data = out[8:] - n = 1 - else: - r = [wrapped_key[i : i + 8] for i in range(0, len(wrapped_key), 8)] - encrypted_aiv = r.pop(0) - n = len(r) - a, r = _unwrap_core(wrapping_key, encrypted_aiv, r) - data = b"".join(r) - - # 1) Check that MSB(32,A) = A65959A6. - # 2) Check that 8*(n-1) < LSB(32,A) <= 8*n. If so, let - # MLI = LSB(32,A). - # 3) Let b = (8*n)-MLI, and then check that the rightmost b octets of - # the output data are zero. - mli = int.from_bytes(a[4:], byteorder="big") - b = (8 * n) - mli - if ( - not bytes_eq(a[:4], b"\xa6\x59\x59\xa6") - or not 8 * (n - 1) < mli <= 8 * n - or (b != 0 and not bytes_eq(data[-b:], b"\x00" * b)) - ): - raise InvalidUnwrap() - - if b == 0: - return data - else: - return data[:-b] - - -def aes_key_unwrap( - wrapping_key: bytes, - wrapped_key: bytes, - backend: typing.Any = None, -) -> bytes: - if len(wrapped_key) < 24: - raise InvalidUnwrap("Must be at least 24 bytes") - - if len(wrapped_key) % 8 != 0: - raise InvalidUnwrap("The wrapped key must be a multiple of 8 bytes") - - if len(wrapping_key) not in [16, 24, 32]: - raise ValueError("The wrapping key must be a valid AES key length") - - aiv = b"\xa6\xa6\xa6\xa6\xa6\xa6\xa6\xa6" - r = [wrapped_key[i : i + 8] for i in range(0, len(wrapped_key), 8)] - a = r.pop(0) - a, r = _unwrap_core(wrapping_key, a, r) - if not bytes_eq(a, aiv): - raise InvalidUnwrap() - - return b"".join(r) - - -class InvalidUnwrap(Exception): - pass diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/padding.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/padding.py deleted file mode 100644 index f9cd1f1..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/padding.py +++ /dev/null @@ -1,69 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -import abc - -from cryptography import utils -from cryptography.hazmat.bindings._rust import ( - ANSIX923PaddingContext, - ANSIX923UnpaddingContext, - PKCS7PaddingContext, - PKCS7UnpaddingContext, -) - - -class PaddingContext(metaclass=abc.ABCMeta): - @abc.abstractmethod - def update(self, data: utils.Buffer) -> bytes: - """ - Pads the provided bytes and returns any available data as bytes. - """ - - @abc.abstractmethod - def finalize(self) -> bytes: - """ - Finalize the padding, returns bytes. - """ - - -def _byte_padding_check(block_size: int) -> None: - if not (0 <= block_size <= 2040): - raise ValueError("block_size must be in range(0, 2041).") - - if block_size % 8 != 0: - raise ValueError("block_size must be a multiple of 8.") - - -class PKCS7: - def __init__(self, block_size: int): - _byte_padding_check(block_size) - self.block_size = block_size - - def padder(self) -> PaddingContext: - return PKCS7PaddingContext(self.block_size) - - def unpadder(self) -> PaddingContext: - return PKCS7UnpaddingContext(self.block_size) - - -PaddingContext.register(PKCS7PaddingContext) -PaddingContext.register(PKCS7UnpaddingContext) - - -class ANSIX923: - def __init__(self, block_size: int): - _byte_padding_check(block_size) - self.block_size = block_size - - def padder(self) -> PaddingContext: - return ANSIX923PaddingContext(self.block_size) - - def unpadder(self) -> PaddingContext: - return ANSIX923UnpaddingContext(self.block_size) - - -PaddingContext.register(ANSIX923PaddingContext) -PaddingContext.register(ANSIX923UnpaddingContext) diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/poly1305.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/poly1305.py deleted file mode 100644 index 7f5a77a..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/poly1305.py +++ /dev/null @@ -1,11 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -from cryptography.hazmat.bindings._rust import openssl as rust_openssl - -__all__ = ["Poly1305"] - -Poly1305 = rust_openssl.poly1305.Poly1305 diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/serialization/__init__.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/serialization/__init__.py deleted file mode 100644 index 62283cc..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/serialization/__init__.py +++ /dev/null @@ -1,65 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -from cryptography.hazmat.primitives._serialization import ( - BestAvailableEncryption, - Encoding, - KeySerializationEncryption, - NoEncryption, - ParameterFormat, - PrivateFormat, - PublicFormat, - _KeySerializationEncryption, -) -from cryptography.hazmat.primitives.serialization.base import ( - load_der_parameters, - load_der_private_key, - load_der_public_key, - load_pem_parameters, - load_pem_private_key, - load_pem_public_key, -) -from cryptography.hazmat.primitives.serialization.ssh import ( - SSHCertificate, - SSHCertificateBuilder, - SSHCertificateType, - SSHCertPrivateKeyTypes, - SSHCertPublicKeyTypes, - SSHPrivateKeyTypes, - SSHPublicKeyTypes, - load_ssh_private_key, - load_ssh_public_identity, - load_ssh_public_key, - ssh_key_fingerprint, -) - -__all__ = [ - "BestAvailableEncryption", - "Encoding", - "KeySerializationEncryption", - "NoEncryption", - "ParameterFormat", - "PrivateFormat", - "PublicFormat", - "SSHCertPrivateKeyTypes", - "SSHCertPublicKeyTypes", - "SSHCertificate", - "SSHCertificateBuilder", - "SSHCertificateType", - "SSHPrivateKeyTypes", - "SSHPublicKeyTypes", - "_KeySerializationEncryption", - "load_der_parameters", - "load_der_private_key", - "load_der_public_key", - "load_pem_parameters", - "load_pem_private_key", - "load_pem_public_key", - "load_ssh_private_key", - "load_ssh_public_identity", - "load_ssh_public_key", - "ssh_key_fingerprint", -] diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/serialization/base.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/serialization/base.py deleted file mode 100644 index e7c998b..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/serialization/base.py +++ /dev/null @@ -1,14 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from cryptography.hazmat.bindings._rust import openssl as rust_openssl - -load_pem_private_key = rust_openssl.keys.load_pem_private_key -load_der_private_key = rust_openssl.keys.load_der_private_key - -load_pem_public_key = rust_openssl.keys.load_pem_public_key -load_der_public_key = rust_openssl.keys.load_der_public_key - -load_pem_parameters = rust_openssl.dh.from_pem_parameters -load_der_parameters = rust_openssl.dh.from_der_parameters diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/serialization/pkcs12.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/serialization/pkcs12.py deleted file mode 100644 index 58884ff..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/serialization/pkcs12.py +++ /dev/null @@ -1,176 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -import typing -from collections.abc import Iterable - -from cryptography import x509 -from cryptography.hazmat.bindings._rust import pkcs12 as rust_pkcs12 -from cryptography.hazmat.primitives import serialization -from cryptography.hazmat.primitives._serialization import PBES as PBES -from cryptography.hazmat.primitives.asymmetric import ( - dsa, - ec, - ed448, - ed25519, - rsa, -) -from cryptography.hazmat.primitives.asymmetric.types import PrivateKeyTypes - -__all__ = [ - "PBES", - "PKCS12Certificate", - "PKCS12KeyAndCertificates", - "PKCS12PrivateKeyTypes", - "load_key_and_certificates", - "load_pkcs12", - "serialize_java_truststore", - "serialize_key_and_certificates", -] - -PKCS12PrivateKeyTypes = typing.Union[ - rsa.RSAPrivateKey, - dsa.DSAPrivateKey, - ec.EllipticCurvePrivateKey, - ed25519.Ed25519PrivateKey, - ed448.Ed448PrivateKey, -] - - -PKCS12Certificate = rust_pkcs12.PKCS12Certificate - - -class PKCS12KeyAndCertificates: - def __init__( - self, - key: PrivateKeyTypes | None, - cert: PKCS12Certificate | None, - additional_certs: list[PKCS12Certificate], - ): - if key is not None and not isinstance( - key, - ( - rsa.RSAPrivateKey, - dsa.DSAPrivateKey, - ec.EllipticCurvePrivateKey, - ed25519.Ed25519PrivateKey, - ed448.Ed448PrivateKey, - ), - ): - raise TypeError( - "Key must be RSA, DSA, EllipticCurve, ED25519, or ED448" - " private key, or None." - ) - if cert is not None and not isinstance(cert, PKCS12Certificate): - raise TypeError("cert must be a PKCS12Certificate object or None") - if not all( - isinstance(add_cert, PKCS12Certificate) - for add_cert in additional_certs - ): - raise TypeError( - "all values in additional_certs must be PKCS12Certificate" - " objects" - ) - self._key = key - self._cert = cert - self._additional_certs = additional_certs - - @property - def key(self) -> PrivateKeyTypes | None: - return self._key - - @property - def cert(self) -> PKCS12Certificate | None: - return self._cert - - @property - def additional_certs(self) -> list[PKCS12Certificate]: - return self._additional_certs - - def __eq__(self, other: object) -> bool: - if not isinstance(other, PKCS12KeyAndCertificates): - return NotImplemented - - return ( - self.key == other.key - and self.cert == other.cert - and self.additional_certs == other.additional_certs - ) - - def __hash__(self) -> int: - return hash((self.key, self.cert, tuple(self.additional_certs))) - - def __repr__(self) -> str: - fmt = ( - "" - ) - return fmt.format(self.key, self.cert, self.additional_certs) - - -load_key_and_certificates = rust_pkcs12.load_key_and_certificates -load_pkcs12 = rust_pkcs12.load_pkcs12 - - -_PKCS12CATypes = typing.Union[ - x509.Certificate, - PKCS12Certificate, -] - - -def serialize_java_truststore( - certs: Iterable[PKCS12Certificate], - encryption_algorithm: serialization.KeySerializationEncryption, -) -> bytes: - if not certs: - raise ValueError("You must supply at least one cert") - - if not isinstance( - encryption_algorithm, serialization.KeySerializationEncryption - ): - raise TypeError( - "Key encryption algorithm must be a " - "KeySerializationEncryption instance" - ) - - return rust_pkcs12.serialize_java_truststore(certs, encryption_algorithm) - - -def serialize_key_and_certificates( - name: bytes | None, - key: PKCS12PrivateKeyTypes | None, - cert: x509.Certificate | None, - cas: Iterable[_PKCS12CATypes] | None, - encryption_algorithm: serialization.KeySerializationEncryption, -) -> bytes: - if key is not None and not isinstance( - key, - ( - rsa.RSAPrivateKey, - dsa.DSAPrivateKey, - ec.EllipticCurvePrivateKey, - ed25519.Ed25519PrivateKey, - ed448.Ed448PrivateKey, - ), - ): - raise TypeError( - "Key must be RSA, DSA, EllipticCurve, ED25519, or ED448" - " private key, or None." - ) - - if not isinstance( - encryption_algorithm, serialization.KeySerializationEncryption - ): - raise TypeError( - "Key encryption algorithm must be a " - "KeySerializationEncryption instance" - ) - - if key is None and cert is None and not cas: - raise ValueError("You must supply at least one of key, cert, or cas") - - return rust_pkcs12.serialize_key_and_certificates( - name, key, cert, cas, encryption_algorithm - ) diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/serialization/pkcs7.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/serialization/pkcs7.py deleted file mode 100644 index 76b667a..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/serialization/pkcs7.py +++ /dev/null @@ -1,412 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -import email.base64mime -import email.generator -import email.message -import email.policy -import io -import typing -from collections.abc import Iterable - -from cryptography import utils, x509 -from cryptography.exceptions import UnsupportedAlgorithm, _Reasons -from cryptography.hazmat.bindings._rust import pkcs7 as rust_pkcs7 -from cryptography.hazmat.primitives import hashes, serialization -from cryptography.hazmat.primitives.asymmetric import ec, padding, rsa -from cryptography.hazmat.primitives.ciphers import ( - algorithms, -) -from cryptography.utils import _check_byteslike - -load_pem_pkcs7_certificates = rust_pkcs7.load_pem_pkcs7_certificates - -load_der_pkcs7_certificates = rust_pkcs7.load_der_pkcs7_certificates - -serialize_certificates = rust_pkcs7.serialize_certificates - -PKCS7HashTypes = typing.Union[ - hashes.SHA224, - hashes.SHA256, - hashes.SHA384, - hashes.SHA512, -] - -PKCS7PrivateKeyTypes = typing.Union[ - rsa.RSAPrivateKey, ec.EllipticCurvePrivateKey -] - -ContentEncryptionAlgorithm = typing.Union[ - type[algorithms.AES128], type[algorithms.AES256] -] - - -class PKCS7Options(utils.Enum): - Text = "Add text/plain MIME type" - Binary = "Don't translate input data into canonical MIME format" - DetachedSignature = "Don't embed data in the PKCS7 structure" - NoCapabilities = "Don't embed SMIME capabilities" - NoAttributes = "Don't embed authenticatedAttributes" - NoCerts = "Don't embed signer certificate" - - -class PKCS7SignatureBuilder: - def __init__( - self, - data: utils.Buffer | None = None, - signers: list[ - tuple[ - x509.Certificate, - PKCS7PrivateKeyTypes, - PKCS7HashTypes, - padding.PSS | padding.PKCS1v15 | None, - ] - ] = [], - additional_certs: list[x509.Certificate] = [], - ): - self._data = data - self._signers = signers - self._additional_certs = additional_certs - - def set_data(self, data: utils.Buffer) -> PKCS7SignatureBuilder: - _check_byteslike("data", data) - if self._data is not None: - raise ValueError("data may only be set once") - - return PKCS7SignatureBuilder(data, self._signers) - - def add_signer( - self, - certificate: x509.Certificate, - private_key: PKCS7PrivateKeyTypes, - hash_algorithm: PKCS7HashTypes, - *, - rsa_padding: padding.PSS | padding.PKCS1v15 | None = None, - ) -> PKCS7SignatureBuilder: - if not isinstance( - hash_algorithm, - ( - hashes.SHA224, - hashes.SHA256, - hashes.SHA384, - hashes.SHA512, - ), - ): - raise TypeError( - "hash_algorithm must be one of hashes.SHA224, " - "SHA256, SHA384, or SHA512" - ) - if not isinstance(certificate, x509.Certificate): - raise TypeError("certificate must be a x509.Certificate") - - if not isinstance( - private_key, (rsa.RSAPrivateKey, ec.EllipticCurvePrivateKey) - ): - raise TypeError("Only RSA & EC keys are supported at this time.") - - if rsa_padding is not None: - if not isinstance(rsa_padding, (padding.PSS, padding.PKCS1v15)): - raise TypeError("Padding must be PSS or PKCS1v15") - if not isinstance(private_key, rsa.RSAPrivateKey): - raise TypeError("Padding is only supported for RSA keys") - - return PKCS7SignatureBuilder( - self._data, - [ - *self._signers, - (certificate, private_key, hash_algorithm, rsa_padding), - ], - ) - - def add_certificate( - self, certificate: x509.Certificate - ) -> PKCS7SignatureBuilder: - if not isinstance(certificate, x509.Certificate): - raise TypeError("certificate must be a x509.Certificate") - - return PKCS7SignatureBuilder( - self._data, self._signers, [*self._additional_certs, certificate] - ) - - def sign( - self, - encoding: serialization.Encoding, - options: Iterable[PKCS7Options], - backend: typing.Any = None, - ) -> bytes: - if len(self._signers) == 0: - raise ValueError("Must have at least one signer") - if self._data is None: - raise ValueError("You must add data to sign") - options = list(options) - if not all(isinstance(x, PKCS7Options) for x in options): - raise ValueError("options must be from the PKCS7Options enum") - if encoding not in ( - serialization.Encoding.PEM, - serialization.Encoding.DER, - serialization.Encoding.SMIME, - ): - raise ValueError( - "Must be PEM, DER, or SMIME from the Encoding enum" - ) - - # Text is a meaningless option unless it is accompanied by - # DetachedSignature - if ( - PKCS7Options.Text in options - and PKCS7Options.DetachedSignature not in options - ): - raise ValueError( - "When passing the Text option you must also pass " - "DetachedSignature" - ) - - if PKCS7Options.Text in options and encoding in ( - serialization.Encoding.DER, - serialization.Encoding.PEM, - ): - raise ValueError( - "The Text option is only available for SMIME serialization" - ) - - # No attributes implies no capabilities so we'll error if you try to - # pass both. - if ( - PKCS7Options.NoAttributes in options - and PKCS7Options.NoCapabilities in options - ): - raise ValueError( - "NoAttributes is a superset of NoCapabilities. Do not pass " - "both values." - ) - - return rust_pkcs7.sign_and_serialize(self, encoding, options) - - -class PKCS7EnvelopeBuilder: - def __init__( - self, - *, - _data: bytes | None = None, - _recipients: list[x509.Certificate] | None = None, - _content_encryption_algorithm: ContentEncryptionAlgorithm - | None = None, - ): - from cryptography.hazmat.backends.openssl.backend import ( - backend as ossl, - ) - - if not ossl.rsa_encryption_supported(padding=padding.PKCS1v15()): - raise UnsupportedAlgorithm( - "RSA with PKCS1 v1.5 padding is not supported by this version" - " of OpenSSL.", - _Reasons.UNSUPPORTED_PADDING, - ) - self._data = _data - self._recipients = _recipients if _recipients is not None else [] - self._content_encryption_algorithm = _content_encryption_algorithm - - def set_data(self, data: bytes) -> PKCS7EnvelopeBuilder: - _check_byteslike("data", data) - if self._data is not None: - raise ValueError("data may only be set once") - - return PKCS7EnvelopeBuilder( - _data=data, - _recipients=self._recipients, - _content_encryption_algorithm=self._content_encryption_algorithm, - ) - - def add_recipient( - self, - certificate: x509.Certificate, - ) -> PKCS7EnvelopeBuilder: - if not isinstance(certificate, x509.Certificate): - raise TypeError("certificate must be a x509.Certificate") - - if not isinstance(certificate.public_key(), rsa.RSAPublicKey): - raise TypeError("Only RSA keys are supported at this time.") - - return PKCS7EnvelopeBuilder( - _data=self._data, - _recipients=[ - *self._recipients, - certificate, - ], - _content_encryption_algorithm=self._content_encryption_algorithm, - ) - - def set_content_encryption_algorithm( - self, content_encryption_algorithm: ContentEncryptionAlgorithm - ) -> PKCS7EnvelopeBuilder: - if self._content_encryption_algorithm is not None: - raise ValueError("Content encryption algo may only be set once") - if content_encryption_algorithm not in { - algorithms.AES128, - algorithms.AES256, - }: - raise TypeError("Only AES128 and AES256 are supported") - - return PKCS7EnvelopeBuilder( - _data=self._data, - _recipients=self._recipients, - _content_encryption_algorithm=content_encryption_algorithm, - ) - - def encrypt( - self, - encoding: serialization.Encoding, - options: Iterable[PKCS7Options], - ) -> bytes: - if len(self._recipients) == 0: - raise ValueError("Must have at least one recipient") - if self._data is None: - raise ValueError("You must add data to encrypt") - - # The default content encryption algorithm is AES-128-CBC, which the - # S/MIME v3.2 RFC specifies as MUST support (https://datatracker.ietf.org/doc/html/rfc5751#section-2.7) - # however rest of S/MIME v3.2 is not currently supported - content_encryption_algorithm = ( - self._content_encryption_algorithm or algorithms.AES128 - ) - - options = list(options) - if not all(isinstance(x, PKCS7Options) for x in options): - raise ValueError("options must be from the PKCS7Options enum") - if encoding not in ( - serialization.Encoding.PEM, - serialization.Encoding.DER, - serialization.Encoding.SMIME, - ): - raise ValueError( - "Must be PEM, DER, or SMIME from the Encoding enum" - ) - - # Only allow options that make sense for encryption - if any( - opt not in [PKCS7Options.Text, PKCS7Options.Binary] - for opt in options - ): - raise ValueError( - "Only the following options are supported for encryption: " - "Text, Binary" - ) - elif PKCS7Options.Text in options and PKCS7Options.Binary in options: - # OpenSSL accepts both options at the same time, but ignores Text. - # We fail defensively to avoid unexpected outputs. - raise ValueError( - "Cannot use Binary and Text options at the same time" - ) - - return rust_pkcs7.encrypt_and_serialize( - self, content_encryption_algorithm, encoding, options - ) - - -pkcs7_decrypt_der = rust_pkcs7.decrypt_der -pkcs7_decrypt_pem = rust_pkcs7.decrypt_pem -pkcs7_decrypt_smime = rust_pkcs7.decrypt_smime - - -def _smime_signed_encode( - data: bytes, signature: bytes, micalg: str, text_mode: bool -) -> bytes: - # This function works pretty hard to replicate what OpenSSL does - # precisely. For good and for ill. - - m = email.message.Message() - m.add_header("MIME-Version", "1.0") - m.add_header( - "Content-Type", - "multipart/signed", - protocol="application/x-pkcs7-signature", - micalg=micalg, - ) - - m.preamble = "This is an S/MIME signed message\n" - - msg_part = OpenSSLMimePart() - msg_part.set_payload(data) - if text_mode: - msg_part.add_header("Content-Type", "text/plain") - m.attach(msg_part) - - sig_part = email.message.MIMEPart() - sig_part.add_header( - "Content-Type", "application/x-pkcs7-signature", name="smime.p7s" - ) - sig_part.add_header("Content-Transfer-Encoding", "base64") - sig_part.add_header( - "Content-Disposition", "attachment", filename="smime.p7s" - ) - sig_part.set_payload( - email.base64mime.body_encode(signature, maxlinelen=65) - ) - del sig_part["MIME-Version"] - m.attach(sig_part) - - fp = io.BytesIO() - g = email.generator.BytesGenerator( - fp, - maxheaderlen=0, - mangle_from_=False, - policy=m.policy.clone(linesep="\r\n"), - ) - g.flatten(m) - return fp.getvalue() - - -def _smime_enveloped_encode(data: bytes) -> bytes: - m = email.message.Message() - m.add_header("MIME-Version", "1.0") - m.add_header("Content-Disposition", "attachment", filename="smime.p7m") - m.add_header( - "Content-Type", - "application/pkcs7-mime", - smime_type="enveloped-data", - name="smime.p7m", - ) - m.add_header("Content-Transfer-Encoding", "base64") - - m.set_payload(email.base64mime.body_encode(data, maxlinelen=65)) - - return m.as_bytes(policy=m.policy.clone(linesep="\n", max_line_length=0)) - - -def _smime_enveloped_decode(data: bytes) -> bytes: - m = email.message_from_bytes(data) - if m.get_content_type() not in { - "application/x-pkcs7-mime", - "application/pkcs7-mime", - }: - raise ValueError("Not an S/MIME enveloped message") - return bytes(m.get_payload(decode=True)) - - -def _smime_remove_text_headers(data: bytes) -> bytes: - m = email.message_from_bytes(data) - # Using get() instead of get_content_type() since it has None as default, - # where the latter has "text/plain". Both methods are case-insensitive. - content_type = m.get("content-type") - if content_type is None: - raise ValueError( - "Decrypted MIME data has no 'Content-Type' header. " - "Please remove the 'Text' option to parse it manually." - ) - if "text/plain" not in content_type: - raise ValueError( - f"Decrypted MIME data content type is '{content_type}', not " - "'text/plain'. Remove the 'Text' option to parse it manually." - ) - return bytes(m.get_payload(decode=True)) - - -class OpenSSLMimePart(email.message.MIMEPart): - # A MIMEPart subclass that replicates OpenSSL's behavior of not including - # a newline if there are no headers. - def _write_headers(self, generator) -> None: - if list(self.raw_items()): - generator._write_headers(self) diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/serialization/ssh.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/serialization/ssh.py deleted file mode 100644 index 411113b..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/serialization/ssh.py +++ /dev/null @@ -1,1621 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -import binascii -import enum -import os -import re -import typing -import warnings -from base64 import encodebytes as _base64_encode -from dataclasses import dataclass - -from cryptography import utils -from cryptography.exceptions import UnsupportedAlgorithm -from cryptography.hazmat.primitives import hashes -from cryptography.hazmat.primitives.asymmetric import ( - dsa, - ec, - ed25519, - padding, - rsa, -) -from cryptography.hazmat.primitives.asymmetric import utils as asym_utils -from cryptography.hazmat.primitives.ciphers import ( - AEADDecryptionContext, - Cipher, - algorithms, - modes, -) -from cryptography.hazmat.primitives.serialization import ( - Encoding, - KeySerializationEncryption, - NoEncryption, - PrivateFormat, - PublicFormat, - _KeySerializationEncryption, -) - -try: - from bcrypt import kdf as _bcrypt_kdf - - _bcrypt_supported = True -except ImportError: - _bcrypt_supported = False - - def _bcrypt_kdf( - password: bytes, - salt: bytes, - desired_key_bytes: int, - rounds: int, - ignore_few_rounds: bool = False, - ) -> bytes: - raise UnsupportedAlgorithm("Need bcrypt module") - - -_SSH_ED25519 = b"ssh-ed25519" -_SSH_RSA = b"ssh-rsa" -_SSH_DSA = b"ssh-dss" -_ECDSA_NISTP256 = b"ecdsa-sha2-nistp256" -_ECDSA_NISTP384 = b"ecdsa-sha2-nistp384" -_ECDSA_NISTP521 = b"ecdsa-sha2-nistp521" -_CERT_SUFFIX = b"-cert-v01@openssh.com" - -# U2F application string suffixed pubkey -_SK_SSH_ED25519 = b"sk-ssh-ed25519@openssh.com" -_SK_SSH_ECDSA_NISTP256 = b"sk-ecdsa-sha2-nistp256@openssh.com" - -# These are not key types, only algorithms, so they cannot appear -# as a public key type -_SSH_RSA_SHA256 = b"rsa-sha2-256" -_SSH_RSA_SHA512 = b"rsa-sha2-512" - -_SSH_PUBKEY_RC = re.compile(rb"\A(\S+)[ \t]+(\S+)") -_SK_MAGIC = b"openssh-key-v1\0" -_SK_START = b"-----BEGIN OPENSSH PRIVATE KEY-----" -_SK_END = b"-----END OPENSSH PRIVATE KEY-----" -_BCRYPT = b"bcrypt" -_NONE = b"none" -_DEFAULT_CIPHER = b"aes256-ctr" -_DEFAULT_ROUNDS = 16 - -# re is only way to work on bytes-like data -_PEM_RC = re.compile(_SK_START + b"(.*?)" + _SK_END, re.DOTALL) - -# padding for max blocksize -_PADDING = memoryview(bytearray(range(1, 1 + 16))) - - -@dataclass -class _SSHCipher: - alg: type[algorithms.AES] - key_len: int - mode: type[modes.CTR] | type[modes.CBC] | type[modes.GCM] - block_len: int - iv_len: int - tag_len: int | None - is_aead: bool - - -# ciphers that are actually used in key wrapping -_SSH_CIPHERS: dict[bytes, _SSHCipher] = { - b"aes256-ctr": _SSHCipher( - alg=algorithms.AES, - key_len=32, - mode=modes.CTR, - block_len=16, - iv_len=16, - tag_len=None, - is_aead=False, - ), - b"aes256-cbc": _SSHCipher( - alg=algorithms.AES, - key_len=32, - mode=modes.CBC, - block_len=16, - iv_len=16, - tag_len=None, - is_aead=False, - ), - b"aes256-gcm@openssh.com": _SSHCipher( - alg=algorithms.AES, - key_len=32, - mode=modes.GCM, - block_len=16, - iv_len=12, - tag_len=16, - is_aead=True, - ), -} - -# map local curve name to key type -_ECDSA_KEY_TYPE = { - "secp256r1": _ECDSA_NISTP256, - "secp384r1": _ECDSA_NISTP384, - "secp521r1": _ECDSA_NISTP521, -} - - -def _get_ssh_key_type(key: SSHPrivateKeyTypes | SSHPublicKeyTypes) -> bytes: - if isinstance(key, ec.EllipticCurvePrivateKey): - key_type = _ecdsa_key_type(key.public_key()) - elif isinstance(key, ec.EllipticCurvePublicKey): - key_type = _ecdsa_key_type(key) - elif isinstance(key, (rsa.RSAPrivateKey, rsa.RSAPublicKey)): - key_type = _SSH_RSA - elif isinstance(key, (dsa.DSAPrivateKey, dsa.DSAPublicKey)): - key_type = _SSH_DSA - elif isinstance( - key, (ed25519.Ed25519PrivateKey, ed25519.Ed25519PublicKey) - ): - key_type = _SSH_ED25519 - else: - raise ValueError("Unsupported key type") - - return key_type - - -def _ecdsa_key_type(public_key: ec.EllipticCurvePublicKey) -> bytes: - """Return SSH key_type and curve_name for private key.""" - curve = public_key.curve - if curve.name not in _ECDSA_KEY_TYPE: - raise ValueError( - f"Unsupported curve for ssh private key: {curve.name!r}" - ) - return _ECDSA_KEY_TYPE[curve.name] - - -def _ssh_pem_encode( - data: utils.Buffer, - prefix: bytes = _SK_START + b"\n", - suffix: bytes = _SK_END + b"\n", -) -> bytes: - return b"".join([prefix, _base64_encode(data), suffix]) - - -def _check_block_size(data: utils.Buffer, block_len: int) -> None: - """Require data to be full blocks""" - if not data or len(data) % block_len != 0: - raise ValueError("Corrupt data: missing padding") - - -def _check_empty(data: utils.Buffer) -> None: - """All data should have been parsed.""" - if data: - raise ValueError("Corrupt data: unparsed data") - - -def _init_cipher( - ciphername: bytes, - password: bytes | None, - salt: bytes, - rounds: int, -) -> Cipher[modes.CBC | modes.CTR | modes.GCM]: - """Generate key + iv and return cipher.""" - if not password: - raise TypeError( - "Key is password-protected, but password was not provided." - ) - - ciph = _SSH_CIPHERS[ciphername] - seed = _bcrypt_kdf( - password, salt, ciph.key_len + ciph.iv_len, rounds, True - ) - return Cipher( - ciph.alg(seed[: ciph.key_len]), - ciph.mode(seed[ciph.key_len :]), - ) - - -def _get_u32(data: memoryview) -> tuple[int, memoryview]: - """Uint32""" - if len(data) < 4: - raise ValueError("Invalid data") - return int.from_bytes(data[:4], byteorder="big"), data[4:] - - -def _get_u64(data: memoryview) -> tuple[int, memoryview]: - """Uint64""" - if len(data) < 8: - raise ValueError("Invalid data") - return int.from_bytes(data[:8], byteorder="big"), data[8:] - - -def _get_sshstr(data: memoryview) -> tuple[memoryview, memoryview]: - """Bytes with u32 length prefix""" - n, data = _get_u32(data) - if n > len(data): - raise ValueError("Invalid data") - return data[:n], data[n:] - - -def _get_mpint(data: memoryview) -> tuple[int, memoryview]: - """Big integer.""" - val, data = _get_sshstr(data) - if val and val[0] > 0x7F: - raise ValueError("Invalid data") - return int.from_bytes(val, "big"), data - - -def _to_mpint(val: int) -> bytes: - """Storage format for signed bigint.""" - if val < 0: - raise ValueError("negative mpint not allowed") - if not val: - return b"" - nbytes = (val.bit_length() + 8) // 8 - return utils.int_to_bytes(val, nbytes) - - -class _FragList: - """Build recursive structure without data copy.""" - - flist: list[utils.Buffer] - - def __init__(self, init: list[utils.Buffer] | None = None) -> None: - self.flist = [] - if init: - self.flist.extend(init) - - def put_raw(self, val: utils.Buffer) -> None: - """Add plain bytes""" - self.flist.append(val) - - def put_u32(self, val: int) -> None: - """Big-endian uint32""" - self.flist.append(val.to_bytes(length=4, byteorder="big")) - - def put_u64(self, val: int) -> None: - """Big-endian uint64""" - self.flist.append(val.to_bytes(length=8, byteorder="big")) - - def put_sshstr(self, val: bytes | _FragList) -> None: - """Bytes prefixed with u32 length""" - if isinstance(val, (bytes, memoryview, bytearray)): - self.put_u32(len(val)) - self.flist.append(val) - else: - self.put_u32(val.size()) - self.flist.extend(val.flist) - - def put_mpint(self, val: int) -> None: - """Big-endian bigint prefixed with u32 length""" - self.put_sshstr(_to_mpint(val)) - - def size(self) -> int: - """Current number of bytes""" - return sum(map(len, self.flist)) - - def render(self, dstbuf: memoryview, pos: int = 0) -> int: - """Write into bytearray""" - for frag in self.flist: - flen = len(frag) - start, pos = pos, pos + flen - dstbuf[start:pos] = frag - return pos - - def tobytes(self) -> bytes: - """Return as bytes""" - buf = memoryview(bytearray(self.size())) - self.render(buf) - return buf.tobytes() - - -class _SSHFormatRSA: - """Format for RSA keys. - - Public: - mpint e, n - Private: - mpint n, e, d, iqmp, p, q - """ - - def get_public( - self, data: memoryview - ) -> tuple[tuple[int, int], memoryview]: - """RSA public fields""" - e, data = _get_mpint(data) - n, data = _get_mpint(data) - return (e, n), data - - def load_public( - self, data: memoryview - ) -> tuple[rsa.RSAPublicKey, memoryview]: - """Make RSA public key from data.""" - (e, n), data = self.get_public(data) - public_numbers = rsa.RSAPublicNumbers(e, n) - public_key = public_numbers.public_key() - return public_key, data - - def load_private( - self, data: memoryview, pubfields, unsafe_skip_rsa_key_validation: bool - ) -> tuple[rsa.RSAPrivateKey, memoryview]: - """Make RSA private key from data.""" - n, data = _get_mpint(data) - e, data = _get_mpint(data) - d, data = _get_mpint(data) - iqmp, data = _get_mpint(data) - p, data = _get_mpint(data) - q, data = _get_mpint(data) - - if (e, n) != pubfields: - raise ValueError("Corrupt data: rsa field mismatch") - dmp1 = rsa.rsa_crt_dmp1(d, p) - dmq1 = rsa.rsa_crt_dmq1(d, q) - public_numbers = rsa.RSAPublicNumbers(e, n) - private_numbers = rsa.RSAPrivateNumbers( - p, q, d, dmp1, dmq1, iqmp, public_numbers - ) - private_key = private_numbers.private_key( - unsafe_skip_rsa_key_validation=unsafe_skip_rsa_key_validation - ) - return private_key, data - - def encode_public( - self, public_key: rsa.RSAPublicKey, f_pub: _FragList - ) -> None: - """Write RSA public key""" - pubn = public_key.public_numbers() - f_pub.put_mpint(pubn.e) - f_pub.put_mpint(pubn.n) - - def encode_private( - self, private_key: rsa.RSAPrivateKey, f_priv: _FragList - ) -> None: - """Write RSA private key""" - private_numbers = private_key.private_numbers() - public_numbers = private_numbers.public_numbers - - f_priv.put_mpint(public_numbers.n) - f_priv.put_mpint(public_numbers.e) - - f_priv.put_mpint(private_numbers.d) - f_priv.put_mpint(private_numbers.iqmp) - f_priv.put_mpint(private_numbers.p) - f_priv.put_mpint(private_numbers.q) - - -class _SSHFormatDSA: - """Format for DSA keys. - - Public: - mpint p, q, g, y - Private: - mpint p, q, g, y, x - """ - - def get_public(self, data: memoryview) -> tuple[tuple, memoryview]: - """DSA public fields""" - p, data = _get_mpint(data) - q, data = _get_mpint(data) - g, data = _get_mpint(data) - y, data = _get_mpint(data) - return (p, q, g, y), data - - def load_public( - self, data: memoryview - ) -> tuple[dsa.DSAPublicKey, memoryview]: - """Make DSA public key from data.""" - (p, q, g, y), data = self.get_public(data) - parameter_numbers = dsa.DSAParameterNumbers(p, q, g) - public_numbers = dsa.DSAPublicNumbers(y, parameter_numbers) - self._validate(public_numbers) - public_key = public_numbers.public_key() - return public_key, data - - def load_private( - self, data: memoryview, pubfields, unsafe_skip_rsa_key_validation: bool - ) -> tuple[dsa.DSAPrivateKey, memoryview]: - """Make DSA private key from data.""" - (p, q, g, y), data = self.get_public(data) - x, data = _get_mpint(data) - - if (p, q, g, y) != pubfields: - raise ValueError("Corrupt data: dsa field mismatch") - parameter_numbers = dsa.DSAParameterNumbers(p, q, g) - public_numbers = dsa.DSAPublicNumbers(y, parameter_numbers) - self._validate(public_numbers) - private_numbers = dsa.DSAPrivateNumbers(x, public_numbers) - private_key = private_numbers.private_key() - return private_key, data - - def encode_public( - self, public_key: dsa.DSAPublicKey, f_pub: _FragList - ) -> None: - """Write DSA public key""" - public_numbers = public_key.public_numbers() - parameter_numbers = public_numbers.parameter_numbers - self._validate(public_numbers) - - f_pub.put_mpint(parameter_numbers.p) - f_pub.put_mpint(parameter_numbers.q) - f_pub.put_mpint(parameter_numbers.g) - f_pub.put_mpint(public_numbers.y) - - def encode_private( - self, private_key: dsa.DSAPrivateKey, f_priv: _FragList - ) -> None: - """Write DSA private key""" - self.encode_public(private_key.public_key(), f_priv) - f_priv.put_mpint(private_key.private_numbers().x) - - def _validate(self, public_numbers: dsa.DSAPublicNumbers) -> None: - parameter_numbers = public_numbers.parameter_numbers - if parameter_numbers.p.bit_length() != 1024: - raise ValueError("SSH supports only 1024 bit DSA keys") - - -class _SSHFormatECDSA: - """Format for ECDSA keys. - - Public: - str curve - bytes point - Private: - str curve - bytes point - mpint secret - """ - - def __init__(self, ssh_curve_name: bytes, curve: ec.EllipticCurve): - self.ssh_curve_name = ssh_curve_name - self.curve = curve - - def get_public( - self, data: memoryview - ) -> tuple[tuple[memoryview, memoryview], memoryview]: - """ECDSA public fields""" - curve, data = _get_sshstr(data) - point, data = _get_sshstr(data) - if curve != self.ssh_curve_name: - raise ValueError("Curve name mismatch") - if len(point) == 0: - raise ValueError("Invalid EC point: empty data") - if point[0] != 4: - raise NotImplementedError("Need uncompressed point") - return (curve, point), data - - def load_public( - self, data: memoryview - ) -> tuple[ec.EllipticCurvePublicKey, memoryview]: - """Make ECDSA public key from data.""" - (_, point), data = self.get_public(data) - public_key = ec.EllipticCurvePublicKey.from_encoded_point( - self.curve, point.tobytes() - ) - return public_key, data - - def load_private( - self, data: memoryview, pubfields, unsafe_skip_rsa_key_validation: bool - ) -> tuple[ec.EllipticCurvePrivateKey, memoryview]: - """Make ECDSA private key from data.""" - (curve_name, point), data = self.get_public(data) - secret, data = _get_mpint(data) - - if (curve_name, point) != pubfields: - raise ValueError("Corrupt data: ecdsa field mismatch") - private_key = ec.derive_private_key(secret, self.curve) - return private_key, data - - def encode_public( - self, public_key: ec.EllipticCurvePublicKey, f_pub: _FragList - ) -> None: - """Write ECDSA public key""" - point = public_key.public_bytes( - Encoding.X962, PublicFormat.UncompressedPoint - ) - f_pub.put_sshstr(self.ssh_curve_name) - f_pub.put_sshstr(point) - - def encode_private( - self, private_key: ec.EllipticCurvePrivateKey, f_priv: _FragList - ) -> None: - """Write ECDSA private key""" - public_key = private_key.public_key() - private_numbers = private_key.private_numbers() - - self.encode_public(public_key, f_priv) - f_priv.put_mpint(private_numbers.private_value) - - -class _SSHFormatEd25519: - """Format for Ed25519 keys. - - Public: - bytes point - Private: - bytes point - bytes secret_and_point - """ - - def get_public( - self, data: memoryview - ) -> tuple[tuple[memoryview], memoryview]: - """Ed25519 public fields""" - point, data = _get_sshstr(data) - return (point,), data - - def load_public( - self, data: memoryview - ) -> tuple[ed25519.Ed25519PublicKey, memoryview]: - """Make Ed25519 public key from data.""" - (point,), data = self.get_public(data) - public_key = ed25519.Ed25519PublicKey.from_public_bytes( - point.tobytes() - ) - return public_key, data - - def load_private( - self, data: memoryview, pubfields, unsafe_skip_rsa_key_validation: bool - ) -> tuple[ed25519.Ed25519PrivateKey, memoryview]: - """Make Ed25519 private key from data.""" - (point,), data = self.get_public(data) - keypair, data = _get_sshstr(data) - - secret = keypair[:32] - point2 = keypair[32:] - if point != point2 or (point,) != pubfields: - raise ValueError("Corrupt data: ed25519 field mismatch") - private_key = ed25519.Ed25519PrivateKey.from_private_bytes(secret) - return private_key, data - - def encode_public( - self, public_key: ed25519.Ed25519PublicKey, f_pub: _FragList - ) -> None: - """Write Ed25519 public key""" - raw_public_key = public_key.public_bytes( - Encoding.Raw, PublicFormat.Raw - ) - f_pub.put_sshstr(raw_public_key) - - def encode_private( - self, private_key: ed25519.Ed25519PrivateKey, f_priv: _FragList - ) -> None: - """Write Ed25519 private key""" - public_key = private_key.public_key() - raw_private_key = private_key.private_bytes( - Encoding.Raw, PrivateFormat.Raw, NoEncryption() - ) - raw_public_key = public_key.public_bytes( - Encoding.Raw, PublicFormat.Raw - ) - f_keypair = _FragList([raw_private_key, raw_public_key]) - - self.encode_public(public_key, f_priv) - f_priv.put_sshstr(f_keypair) - - -def load_application(data) -> tuple[memoryview, memoryview]: - """ - U2F application strings - """ - application, data = _get_sshstr(data) - if not application.tobytes().startswith(b"ssh:"): - raise ValueError( - "U2F application string does not start with b'ssh:' " - f"({application})" - ) - return application, data - - -class _SSHFormatSKEd25519: - """ - The format of a sk-ssh-ed25519@openssh.com public key is: - - string "sk-ssh-ed25519@openssh.com" - string public key - string application (user-specified, but typically "ssh:") - """ - - def load_public( - self, data: memoryview - ) -> tuple[ed25519.Ed25519PublicKey, memoryview]: - """Make Ed25519 public key from data.""" - public_key, data = _lookup_kformat(_SSH_ED25519).load_public(data) - _, data = load_application(data) - return public_key, data - - def get_public(self, data: memoryview) -> typing.NoReturn: - # Confusingly `get_public` is an entry point used by private key - # loading. - raise UnsupportedAlgorithm( - "sk-ssh-ed25519 private keys cannot be loaded" - ) - - -class _SSHFormatSKECDSA: - """ - The format of a sk-ecdsa-sha2-nistp256@openssh.com public key is: - - string "sk-ecdsa-sha2-nistp256@openssh.com" - string curve name - ec_point Q - string application (user-specified, but typically "ssh:") - """ - - def load_public( - self, data: memoryview - ) -> tuple[ec.EllipticCurvePublicKey, memoryview]: - """Make ECDSA public key from data.""" - public_key, data = _lookup_kformat(_ECDSA_NISTP256).load_public(data) - _, data = load_application(data) - return public_key, data - - def get_public(self, data: memoryview) -> typing.NoReturn: - # Confusingly `get_public` is an entry point used by private key - # loading. - raise UnsupportedAlgorithm( - "sk-ecdsa-sha2-nistp256 private keys cannot be loaded" - ) - - -_KEY_FORMATS = { - _SSH_RSA: _SSHFormatRSA(), - _SSH_DSA: _SSHFormatDSA(), - _SSH_ED25519: _SSHFormatEd25519(), - _ECDSA_NISTP256: _SSHFormatECDSA(b"nistp256", ec.SECP256R1()), - _ECDSA_NISTP384: _SSHFormatECDSA(b"nistp384", ec.SECP384R1()), - _ECDSA_NISTP521: _SSHFormatECDSA(b"nistp521", ec.SECP521R1()), - _SK_SSH_ED25519: _SSHFormatSKEd25519(), - _SK_SSH_ECDSA_NISTP256: _SSHFormatSKECDSA(), -} - - -def _lookup_kformat(key_type: utils.Buffer): - """Return valid format or throw error""" - if not isinstance(key_type, bytes): - key_type = memoryview(key_type).tobytes() - if key_type in _KEY_FORMATS: - return _KEY_FORMATS[key_type] - raise UnsupportedAlgorithm(f"Unsupported key type: {key_type!r}") - - -SSHPrivateKeyTypes = typing.Union[ - ec.EllipticCurvePrivateKey, - rsa.RSAPrivateKey, - dsa.DSAPrivateKey, - ed25519.Ed25519PrivateKey, -] - - -def load_ssh_private_key( - data: utils.Buffer, - password: bytes | None, - backend: typing.Any = None, - *, - unsafe_skip_rsa_key_validation: bool = False, -) -> SSHPrivateKeyTypes: - """Load private key from OpenSSH custom encoding.""" - utils._check_byteslike("data", data) - if password is not None: - utils._check_bytes("password", password) - - m = _PEM_RC.search(data) - if not m: - raise ValueError("Not OpenSSH private key format") - p1 = m.start(1) - p2 = m.end(1) - data = binascii.a2b_base64(memoryview(data)[p1:p2]) - if not data.startswith(_SK_MAGIC): - raise ValueError("Not OpenSSH private key format") - data = memoryview(data)[len(_SK_MAGIC) :] - - # parse header - ciphername, data = _get_sshstr(data) - kdfname, data = _get_sshstr(data) - kdfoptions, data = _get_sshstr(data) - nkeys, data = _get_u32(data) - if nkeys != 1: - raise ValueError("Only one key supported") - - # load public key data - pubdata, data = _get_sshstr(data) - pub_key_type, pubdata = _get_sshstr(pubdata) - kformat = _lookup_kformat(pub_key_type) - pubfields, pubdata = kformat.get_public(pubdata) - _check_empty(pubdata) - - if ciphername != _NONE or kdfname != _NONE: - ciphername_bytes = ciphername.tobytes() - if ciphername_bytes not in _SSH_CIPHERS: - raise UnsupportedAlgorithm( - f"Unsupported cipher: {ciphername_bytes!r}" - ) - if kdfname != _BCRYPT: - raise UnsupportedAlgorithm(f"Unsupported KDF: {kdfname!r}") - blklen = _SSH_CIPHERS[ciphername_bytes].block_len - tag_len = _SSH_CIPHERS[ciphername_bytes].tag_len - # load secret data - edata, data = _get_sshstr(data) - # see https://bugzilla.mindrot.org/show_bug.cgi?id=3553 for - # information about how OpenSSH handles AEAD tags - if _SSH_CIPHERS[ciphername_bytes].is_aead: - tag = bytes(data) - if len(tag) != tag_len: - raise ValueError("Corrupt data: invalid tag length for cipher") - else: - _check_empty(data) - _check_block_size(edata, blklen) - salt, kbuf = _get_sshstr(kdfoptions) - rounds, kbuf = _get_u32(kbuf) - _check_empty(kbuf) - ciph = _init_cipher(ciphername_bytes, password, salt.tobytes(), rounds) - dec = ciph.decryptor() - edata = memoryview(dec.update(edata)) - if _SSH_CIPHERS[ciphername_bytes].is_aead: - assert isinstance(dec, AEADDecryptionContext) - _check_empty(dec.finalize_with_tag(tag)) - else: - # _check_block_size requires data to be a full block so there - # should be no output from finalize - _check_empty(dec.finalize()) - else: - if password: - raise TypeError( - "Password was given but private key is not encrypted." - ) - # load secret data - edata, data = _get_sshstr(data) - _check_empty(data) - blklen = 8 - _check_block_size(edata, blklen) - ck1, edata = _get_u32(edata) - ck2, edata = _get_u32(edata) - if ck1 != ck2: - raise ValueError("Corrupt data: broken checksum") - - # load per-key struct - key_type, edata = _get_sshstr(edata) - if key_type != pub_key_type: - raise ValueError("Corrupt data: key type mismatch") - private_key, edata = kformat.load_private( - edata, - pubfields, - unsafe_skip_rsa_key_validation=unsafe_skip_rsa_key_validation, - ) - # We don't use the comment - _, edata = _get_sshstr(edata) - - # yes, SSH does padding check *after* all other parsing is done. - # need to follow as it writes zero-byte padding too. - if edata != _PADDING[: len(edata)]: - raise ValueError("Corrupt data: invalid padding") - - if isinstance(private_key, dsa.DSAPrivateKey): - warnings.warn( - "SSH DSA keys are deprecated and will be removed in a future " - "release.", - utils.DeprecatedIn40, - stacklevel=2, - ) - - return private_key - - -def _serialize_ssh_private_key( - private_key: SSHPrivateKeyTypes, - password: bytes, - encryption_algorithm: KeySerializationEncryption, -) -> bytes: - """Serialize private key with OpenSSH custom encoding.""" - utils._check_bytes("password", password) - if isinstance(private_key, dsa.DSAPrivateKey): - warnings.warn( - "SSH DSA key support is deprecated and will be " - "removed in a future release", - utils.DeprecatedIn40, - stacklevel=4, - ) - - key_type = _get_ssh_key_type(private_key) - kformat = _lookup_kformat(key_type) - - # setup parameters - f_kdfoptions = _FragList() - if password: - ciphername = _DEFAULT_CIPHER - blklen = _SSH_CIPHERS[ciphername].block_len - kdfname = _BCRYPT - rounds = _DEFAULT_ROUNDS - if ( - isinstance(encryption_algorithm, _KeySerializationEncryption) - and encryption_algorithm._kdf_rounds is not None - ): - rounds = encryption_algorithm._kdf_rounds - salt = os.urandom(16) - f_kdfoptions.put_sshstr(salt) - f_kdfoptions.put_u32(rounds) - ciph = _init_cipher(ciphername, password, salt, rounds) - else: - ciphername = kdfname = _NONE - blklen = 8 - ciph = None - nkeys = 1 - checkval = os.urandom(4) - comment = b"" - - # encode public and private parts together - f_public_key = _FragList() - f_public_key.put_sshstr(key_type) - kformat.encode_public(private_key.public_key(), f_public_key) - - f_secrets = _FragList([checkval, checkval]) - f_secrets.put_sshstr(key_type) - kformat.encode_private(private_key, f_secrets) - f_secrets.put_sshstr(comment) - f_secrets.put_raw(_PADDING[: blklen - (f_secrets.size() % blklen)]) - - # top-level structure - f_main = _FragList() - f_main.put_raw(_SK_MAGIC) - f_main.put_sshstr(ciphername) - f_main.put_sshstr(kdfname) - f_main.put_sshstr(f_kdfoptions) - f_main.put_u32(nkeys) - f_main.put_sshstr(f_public_key) - f_main.put_sshstr(f_secrets) - - # copy result info bytearray - slen = f_secrets.size() - mlen = f_main.size() - buf = memoryview(bytearray(mlen + blklen)) - f_main.render(buf) - ofs = mlen - slen - - # encrypt in-place - if ciph is not None: - ciph.encryptor().update_into(buf[ofs:mlen], buf[ofs:]) - - return _ssh_pem_encode(buf[:mlen]) - - -SSHPublicKeyTypes = typing.Union[ - ec.EllipticCurvePublicKey, - rsa.RSAPublicKey, - dsa.DSAPublicKey, - ed25519.Ed25519PublicKey, -] - -SSHCertPublicKeyTypes = typing.Union[ - ec.EllipticCurvePublicKey, - rsa.RSAPublicKey, - ed25519.Ed25519PublicKey, -] - - -class SSHCertificateType(enum.Enum): - USER = 1 - HOST = 2 - - -class SSHCertificate: - def __init__( - self, - _nonce: memoryview, - _public_key: SSHPublicKeyTypes, - _serial: int, - _cctype: int, - _key_id: memoryview, - _valid_principals: list[bytes], - _valid_after: int, - _valid_before: int, - _critical_options: dict[bytes, bytes], - _extensions: dict[bytes, bytes], - _sig_type: memoryview, - _sig_key: memoryview, - _inner_sig_type: memoryview, - _signature: memoryview, - _tbs_cert_body: memoryview, - _cert_key_type: bytes, - _cert_body: memoryview, - ): - self._nonce = _nonce - self._public_key = _public_key - self._serial = _serial - try: - self._type = SSHCertificateType(_cctype) - except ValueError: - raise ValueError("Invalid certificate type") - self._key_id = _key_id - self._valid_principals = _valid_principals - self._valid_after = _valid_after - self._valid_before = _valid_before - self._critical_options = _critical_options - self._extensions = _extensions - self._sig_type = _sig_type - self._sig_key = _sig_key - self._inner_sig_type = _inner_sig_type - self._signature = _signature - self._cert_key_type = _cert_key_type - self._cert_body = _cert_body - self._tbs_cert_body = _tbs_cert_body - - @property - def nonce(self) -> bytes: - return bytes(self._nonce) - - def public_key(self) -> SSHCertPublicKeyTypes: - # make mypy happy until we remove DSA support entirely and - # the underlying union won't have a disallowed type - return typing.cast(SSHCertPublicKeyTypes, self._public_key) - - @property - def serial(self) -> int: - return self._serial - - @property - def type(self) -> SSHCertificateType: - return self._type - - @property - def key_id(self) -> bytes: - return bytes(self._key_id) - - @property - def valid_principals(self) -> list[bytes]: - return self._valid_principals - - @property - def valid_before(self) -> int: - return self._valid_before - - @property - def valid_after(self) -> int: - return self._valid_after - - @property - def critical_options(self) -> dict[bytes, bytes]: - return self._critical_options - - @property - def extensions(self) -> dict[bytes, bytes]: - return self._extensions - - def signature_key(self) -> SSHCertPublicKeyTypes: - sigformat = _lookup_kformat(self._sig_type) - signature_key, sigkey_rest = sigformat.load_public(self._sig_key) - _check_empty(sigkey_rest) - return signature_key - - def public_bytes(self) -> bytes: - return ( - bytes(self._cert_key_type) - + b" " - + binascii.b2a_base64(bytes(self._cert_body), newline=False) - ) - - def verify_cert_signature(self) -> None: - signature_key = self.signature_key() - if isinstance(signature_key, ed25519.Ed25519PublicKey): - signature_key.verify( - bytes(self._signature), bytes(self._tbs_cert_body) - ) - elif isinstance(signature_key, ec.EllipticCurvePublicKey): - # The signature is encoded as a pair of big-endian integers - r, data = _get_mpint(self._signature) - s, data = _get_mpint(data) - _check_empty(data) - computed_sig = asym_utils.encode_dss_signature(r, s) - hash_alg = _get_ec_hash_alg(signature_key.curve) - signature_key.verify( - computed_sig, bytes(self._tbs_cert_body), ec.ECDSA(hash_alg) - ) - else: - assert isinstance(signature_key, rsa.RSAPublicKey) - if self._inner_sig_type == _SSH_RSA: - hash_alg = hashes.SHA1() - elif self._inner_sig_type == _SSH_RSA_SHA256: - hash_alg = hashes.SHA256() - else: - assert self._inner_sig_type == _SSH_RSA_SHA512 - hash_alg = hashes.SHA512() - signature_key.verify( - bytes(self._signature), - bytes(self._tbs_cert_body), - padding.PKCS1v15(), - hash_alg, - ) - - -def _get_ec_hash_alg(curve: ec.EllipticCurve) -> hashes.HashAlgorithm: - if isinstance(curve, ec.SECP256R1): - return hashes.SHA256() - elif isinstance(curve, ec.SECP384R1): - return hashes.SHA384() - else: - assert isinstance(curve, ec.SECP521R1) - return hashes.SHA512() - - -def _load_ssh_public_identity( - data: utils.Buffer, - _legacy_dsa_allowed=False, -) -> SSHCertificate | SSHPublicKeyTypes: - utils._check_byteslike("data", data) - - m = _SSH_PUBKEY_RC.match(data) - if not m: - raise ValueError("Invalid line format") - key_type = orig_key_type = m.group(1) - key_body = m.group(2) - with_cert = False - if key_type.endswith(_CERT_SUFFIX): - with_cert = True - key_type = key_type[: -len(_CERT_SUFFIX)] - if key_type == _SSH_DSA and not _legacy_dsa_allowed: - raise UnsupportedAlgorithm( - "DSA keys aren't supported in SSH certificates" - ) - kformat = _lookup_kformat(key_type) - - try: - rest = memoryview(binascii.a2b_base64(key_body)) - except (TypeError, binascii.Error): - raise ValueError("Invalid format") - - if with_cert: - cert_body = rest - inner_key_type, rest = _get_sshstr(rest) - if inner_key_type != orig_key_type: - raise ValueError("Invalid key format") - if with_cert: - nonce, rest = _get_sshstr(rest) - public_key, rest = kformat.load_public(rest) - if with_cert: - serial, rest = _get_u64(rest) - cctype, rest = _get_u32(rest) - key_id, rest = _get_sshstr(rest) - principals, rest = _get_sshstr(rest) - valid_principals = [] - while principals: - principal, principals = _get_sshstr(principals) - valid_principals.append(bytes(principal)) - valid_after, rest = _get_u64(rest) - valid_before, rest = _get_u64(rest) - crit_options, rest = _get_sshstr(rest) - critical_options = _parse_exts_opts(crit_options) - exts, rest = _get_sshstr(rest) - extensions = _parse_exts_opts(exts) - # Get the reserved field, which is unused. - _, rest = _get_sshstr(rest) - sig_key_raw, rest = _get_sshstr(rest) - sig_type, sig_key = _get_sshstr(sig_key_raw) - if sig_type == _SSH_DSA and not _legacy_dsa_allowed: - raise UnsupportedAlgorithm( - "DSA signatures aren't supported in SSH certificates" - ) - # Get the entire cert body and subtract the signature - tbs_cert_body = cert_body[: -len(rest)] - signature_raw, rest = _get_sshstr(rest) - _check_empty(rest) - inner_sig_type, sig_rest = _get_sshstr(signature_raw) - # RSA certs can have multiple algorithm types - if ( - sig_type == _SSH_RSA - and inner_sig_type - not in [_SSH_RSA_SHA256, _SSH_RSA_SHA512, _SSH_RSA] - ) or (sig_type != _SSH_RSA and inner_sig_type != sig_type): - raise ValueError("Signature key type does not match") - signature, sig_rest = _get_sshstr(sig_rest) - _check_empty(sig_rest) - return SSHCertificate( - nonce, - public_key, - serial, - cctype, - key_id, - valid_principals, - valid_after, - valid_before, - critical_options, - extensions, - sig_type, - sig_key, - inner_sig_type, - signature, - tbs_cert_body, - orig_key_type, - cert_body, - ) - else: - _check_empty(rest) - return public_key - - -def load_ssh_public_identity( - data: utils.Buffer, -) -> SSHCertificate | SSHPublicKeyTypes: - return _load_ssh_public_identity(data) - - -def _parse_exts_opts(exts_opts: memoryview) -> dict[bytes, bytes]: - result: dict[bytes, bytes] = {} - last_name = None - while exts_opts: - name, exts_opts = _get_sshstr(exts_opts) - bname: bytes = bytes(name) - if bname in result: - raise ValueError("Duplicate name") - if last_name is not None and bname < last_name: - raise ValueError("Fields not lexically sorted") - value, exts_opts = _get_sshstr(exts_opts) - if len(value) > 0: - value, extra = _get_sshstr(value) - if len(extra) > 0: - raise ValueError("Unexpected extra data after value") - result[bname] = bytes(value) - last_name = bname - return result - - -def ssh_key_fingerprint( - key: SSHPublicKeyTypes, - hash_algorithm: hashes.MD5 | hashes.SHA256, -) -> bytes: - if not isinstance(hash_algorithm, (hashes.MD5, hashes.SHA256)): - raise TypeError("hash_algorithm must be either MD5 or SHA256") - - key_type = _get_ssh_key_type(key) - kformat = _lookup_kformat(key_type) - - f_pub = _FragList() - f_pub.put_sshstr(key_type) - kformat.encode_public(key, f_pub) - - ssh_binary_data = f_pub.tobytes() - - # Hash the binary data - hash_obj = hashes.Hash(hash_algorithm) - hash_obj.update(ssh_binary_data) - return hash_obj.finalize() - - -def load_ssh_public_key( - data: utils.Buffer, backend: typing.Any = None -) -> SSHPublicKeyTypes: - cert_or_key = _load_ssh_public_identity(data, _legacy_dsa_allowed=True) - public_key: SSHPublicKeyTypes - if isinstance(cert_or_key, SSHCertificate): - public_key = cert_or_key.public_key() - else: - public_key = cert_or_key - - if isinstance(public_key, dsa.DSAPublicKey): - warnings.warn( - "SSH DSA keys are deprecated and will be removed in a future " - "release.", - utils.DeprecatedIn40, - stacklevel=2, - ) - return public_key - - -def serialize_ssh_public_key(public_key: SSHPublicKeyTypes) -> bytes: - """One-line public key format for OpenSSH""" - if isinstance(public_key, dsa.DSAPublicKey): - warnings.warn( - "SSH DSA key support is deprecated and will be " - "removed in a future release", - utils.DeprecatedIn40, - stacklevel=4, - ) - key_type = _get_ssh_key_type(public_key) - kformat = _lookup_kformat(key_type) - - f_pub = _FragList() - f_pub.put_sshstr(key_type) - kformat.encode_public(public_key, f_pub) - - pub = binascii.b2a_base64(f_pub.tobytes()).strip() - return b"".join([key_type, b" ", pub]) - - -SSHCertPrivateKeyTypes = typing.Union[ - ec.EllipticCurvePrivateKey, - rsa.RSAPrivateKey, - ed25519.Ed25519PrivateKey, -] - - -# This is an undocumented limit enforced in the openssh codebase for sshd and -# ssh-keygen, but it is undefined in the ssh certificates spec. -_SSHKEY_CERT_MAX_PRINCIPALS = 256 - - -class SSHCertificateBuilder: - def __init__( - self, - _public_key: SSHCertPublicKeyTypes | None = None, - _serial: int | None = None, - _type: SSHCertificateType | None = None, - _key_id: bytes | None = None, - _valid_principals: list[bytes] = [], - _valid_for_all_principals: bool = False, - _valid_before: int | None = None, - _valid_after: int | None = None, - _critical_options: list[tuple[bytes, bytes]] = [], - _extensions: list[tuple[bytes, bytes]] = [], - ): - self._public_key = _public_key - self._serial = _serial - self._type = _type - self._key_id = _key_id - self._valid_principals = _valid_principals - self._valid_for_all_principals = _valid_for_all_principals - self._valid_before = _valid_before - self._valid_after = _valid_after - self._critical_options = _critical_options - self._extensions = _extensions - - def public_key( - self, public_key: SSHCertPublicKeyTypes - ) -> SSHCertificateBuilder: - if not isinstance( - public_key, - ( - ec.EllipticCurvePublicKey, - rsa.RSAPublicKey, - ed25519.Ed25519PublicKey, - ), - ): - raise TypeError("Unsupported key type") - if self._public_key is not None: - raise ValueError("public_key already set") - - return SSHCertificateBuilder( - _public_key=public_key, - _serial=self._serial, - _type=self._type, - _key_id=self._key_id, - _valid_principals=self._valid_principals, - _valid_for_all_principals=self._valid_for_all_principals, - _valid_before=self._valid_before, - _valid_after=self._valid_after, - _critical_options=self._critical_options, - _extensions=self._extensions, - ) - - def serial(self, serial: int) -> SSHCertificateBuilder: - if not isinstance(serial, int): - raise TypeError("serial must be an integer") - if not 0 <= serial < 2**64: - raise ValueError("serial must be between 0 and 2**64") - if self._serial is not None: - raise ValueError("serial already set") - - return SSHCertificateBuilder( - _public_key=self._public_key, - _serial=serial, - _type=self._type, - _key_id=self._key_id, - _valid_principals=self._valid_principals, - _valid_for_all_principals=self._valid_for_all_principals, - _valid_before=self._valid_before, - _valid_after=self._valid_after, - _critical_options=self._critical_options, - _extensions=self._extensions, - ) - - def type(self, type: SSHCertificateType) -> SSHCertificateBuilder: - if not isinstance(type, SSHCertificateType): - raise TypeError("type must be an SSHCertificateType") - if self._type is not None: - raise ValueError("type already set") - - return SSHCertificateBuilder( - _public_key=self._public_key, - _serial=self._serial, - _type=type, - _key_id=self._key_id, - _valid_principals=self._valid_principals, - _valid_for_all_principals=self._valid_for_all_principals, - _valid_before=self._valid_before, - _valid_after=self._valid_after, - _critical_options=self._critical_options, - _extensions=self._extensions, - ) - - def key_id(self, key_id: bytes) -> SSHCertificateBuilder: - if not isinstance(key_id, bytes): - raise TypeError("key_id must be bytes") - if self._key_id is not None: - raise ValueError("key_id already set") - - return SSHCertificateBuilder( - _public_key=self._public_key, - _serial=self._serial, - _type=self._type, - _key_id=key_id, - _valid_principals=self._valid_principals, - _valid_for_all_principals=self._valid_for_all_principals, - _valid_before=self._valid_before, - _valid_after=self._valid_after, - _critical_options=self._critical_options, - _extensions=self._extensions, - ) - - def valid_principals( - self, valid_principals: list[bytes] - ) -> SSHCertificateBuilder: - if self._valid_for_all_principals: - raise ValueError( - "Principals can't be set because the cert is valid " - "for all principals" - ) - if ( - not all(isinstance(x, bytes) for x in valid_principals) - or not valid_principals - ): - raise TypeError( - "principals must be a list of bytes and can't be empty" - ) - if self._valid_principals: - raise ValueError("valid_principals already set") - - if len(valid_principals) > _SSHKEY_CERT_MAX_PRINCIPALS: - raise ValueError( - "Reached or exceeded the maximum number of valid_principals" - ) - - return SSHCertificateBuilder( - _public_key=self._public_key, - _serial=self._serial, - _type=self._type, - _key_id=self._key_id, - _valid_principals=valid_principals, - _valid_for_all_principals=self._valid_for_all_principals, - _valid_before=self._valid_before, - _valid_after=self._valid_after, - _critical_options=self._critical_options, - _extensions=self._extensions, - ) - - def valid_for_all_principals(self): - if self._valid_principals: - raise ValueError( - "valid_principals already set, can't set " - "valid_for_all_principals" - ) - if self._valid_for_all_principals: - raise ValueError("valid_for_all_principals already set") - - return SSHCertificateBuilder( - _public_key=self._public_key, - _serial=self._serial, - _type=self._type, - _key_id=self._key_id, - _valid_principals=self._valid_principals, - _valid_for_all_principals=True, - _valid_before=self._valid_before, - _valid_after=self._valid_after, - _critical_options=self._critical_options, - _extensions=self._extensions, - ) - - def valid_before(self, valid_before: int | float) -> SSHCertificateBuilder: - if not isinstance(valid_before, (int, float)): - raise TypeError("valid_before must be an int or float") - valid_before = int(valid_before) - if valid_before < 0 or valid_before >= 2**64: - raise ValueError("valid_before must [0, 2**64)") - if self._valid_before is not None: - raise ValueError("valid_before already set") - - return SSHCertificateBuilder( - _public_key=self._public_key, - _serial=self._serial, - _type=self._type, - _key_id=self._key_id, - _valid_principals=self._valid_principals, - _valid_for_all_principals=self._valid_for_all_principals, - _valid_before=valid_before, - _valid_after=self._valid_after, - _critical_options=self._critical_options, - _extensions=self._extensions, - ) - - def valid_after(self, valid_after: int | float) -> SSHCertificateBuilder: - if not isinstance(valid_after, (int, float)): - raise TypeError("valid_after must be an int or float") - valid_after = int(valid_after) - if valid_after < 0 or valid_after >= 2**64: - raise ValueError("valid_after must [0, 2**64)") - if self._valid_after is not None: - raise ValueError("valid_after already set") - - return SSHCertificateBuilder( - _public_key=self._public_key, - _serial=self._serial, - _type=self._type, - _key_id=self._key_id, - _valid_principals=self._valid_principals, - _valid_for_all_principals=self._valid_for_all_principals, - _valid_before=self._valid_before, - _valid_after=valid_after, - _critical_options=self._critical_options, - _extensions=self._extensions, - ) - - def add_critical_option( - self, name: bytes, value: bytes - ) -> SSHCertificateBuilder: - if not isinstance(name, bytes) or not isinstance(value, bytes): - raise TypeError("name and value must be bytes") - # This is O(n**2) - if name in [name for name, _ in self._critical_options]: - raise ValueError("Duplicate critical option name") - - return SSHCertificateBuilder( - _public_key=self._public_key, - _serial=self._serial, - _type=self._type, - _key_id=self._key_id, - _valid_principals=self._valid_principals, - _valid_for_all_principals=self._valid_for_all_principals, - _valid_before=self._valid_before, - _valid_after=self._valid_after, - _critical_options=[*self._critical_options, (name, value)], - _extensions=self._extensions, - ) - - def add_extension( - self, name: bytes, value: bytes - ) -> SSHCertificateBuilder: - if not isinstance(name, bytes) or not isinstance(value, bytes): - raise TypeError("name and value must be bytes") - # This is O(n**2) - if name in [name for name, _ in self._extensions]: - raise ValueError("Duplicate extension name") - - return SSHCertificateBuilder( - _public_key=self._public_key, - _serial=self._serial, - _type=self._type, - _key_id=self._key_id, - _valid_principals=self._valid_principals, - _valid_for_all_principals=self._valid_for_all_principals, - _valid_before=self._valid_before, - _valid_after=self._valid_after, - _critical_options=self._critical_options, - _extensions=[*self._extensions, (name, value)], - ) - - def sign(self, private_key: SSHCertPrivateKeyTypes) -> SSHCertificate: - if not isinstance( - private_key, - ( - ec.EllipticCurvePrivateKey, - rsa.RSAPrivateKey, - ed25519.Ed25519PrivateKey, - ), - ): - raise TypeError("Unsupported private key type") - - if self._public_key is None: - raise ValueError("public_key must be set") - - # Not required - serial = 0 if self._serial is None else self._serial - - if self._type is None: - raise ValueError("type must be set") - - # Not required - key_id = b"" if self._key_id is None else self._key_id - - # A zero length list is valid, but means the certificate - # is valid for any principal of the specified type. We require - # the user to explicitly set valid_for_all_principals to get - # that behavior. - if not self._valid_principals and not self._valid_for_all_principals: - raise ValueError( - "valid_principals must be set if valid_for_all_principals " - "is False" - ) - - if self._valid_before is None: - raise ValueError("valid_before must be set") - - if self._valid_after is None: - raise ValueError("valid_after must be set") - - if self._valid_after > self._valid_before: - raise ValueError("valid_after must be earlier than valid_before") - - # lexically sort our byte strings - self._critical_options.sort(key=lambda x: x[0]) - self._extensions.sort(key=lambda x: x[0]) - - key_type = _get_ssh_key_type(self._public_key) - cert_prefix = key_type + _CERT_SUFFIX - - # Marshal the bytes to be signed - nonce = os.urandom(32) - kformat = _lookup_kformat(key_type) - f = _FragList() - f.put_sshstr(cert_prefix) - f.put_sshstr(nonce) - kformat.encode_public(self._public_key, f) - f.put_u64(serial) - f.put_u32(self._type.value) - f.put_sshstr(key_id) - fprincipals = _FragList() - for p in self._valid_principals: - fprincipals.put_sshstr(p) - f.put_sshstr(fprincipals.tobytes()) - f.put_u64(self._valid_after) - f.put_u64(self._valid_before) - fcrit = _FragList() - for name, value in self._critical_options: - fcrit.put_sshstr(name) - if len(value) > 0: - foptval = _FragList() - foptval.put_sshstr(value) - fcrit.put_sshstr(foptval.tobytes()) - else: - fcrit.put_sshstr(value) - f.put_sshstr(fcrit.tobytes()) - fext = _FragList() - for name, value in self._extensions: - fext.put_sshstr(name) - if len(value) > 0: - fextval = _FragList() - fextval.put_sshstr(value) - fext.put_sshstr(fextval.tobytes()) - else: - fext.put_sshstr(value) - f.put_sshstr(fext.tobytes()) - f.put_sshstr(b"") # RESERVED FIELD - # encode CA public key - ca_type = _get_ssh_key_type(private_key) - caformat = _lookup_kformat(ca_type) - caf = _FragList() - caf.put_sshstr(ca_type) - caformat.encode_public(private_key.public_key(), caf) - f.put_sshstr(caf.tobytes()) - # Sigs according to the rules defined for the CA's public key - # (RFC4253 section 6.6 for ssh-rsa, RFC5656 for ECDSA, - # and RFC8032 for Ed25519). - if isinstance(private_key, ed25519.Ed25519PrivateKey): - signature = private_key.sign(f.tobytes()) - fsig = _FragList() - fsig.put_sshstr(ca_type) - fsig.put_sshstr(signature) - f.put_sshstr(fsig.tobytes()) - elif isinstance(private_key, ec.EllipticCurvePrivateKey): - hash_alg = _get_ec_hash_alg(private_key.curve) - signature = private_key.sign(f.tobytes(), ec.ECDSA(hash_alg)) - r, s = asym_utils.decode_dss_signature(signature) - fsig = _FragList() - fsig.put_sshstr(ca_type) - fsigblob = _FragList() - fsigblob.put_mpint(r) - fsigblob.put_mpint(s) - fsig.put_sshstr(fsigblob.tobytes()) - f.put_sshstr(fsig.tobytes()) - - else: - assert isinstance(private_key, rsa.RSAPrivateKey) - # Just like Golang, we're going to use SHA512 for RSA - # https://cs.opensource.google/go/x/crypto/+/refs/tags/ - # v0.4.0:ssh/certs.go;l=445 - # RFC 8332 defines SHA256 and 512 as options - fsig = _FragList() - fsig.put_sshstr(_SSH_RSA_SHA512) - signature = private_key.sign( - f.tobytes(), padding.PKCS1v15(), hashes.SHA512() - ) - fsig.put_sshstr(signature) - f.put_sshstr(fsig.tobytes()) - - cert_data = binascii.b2a_base64(f.tobytes()).strip() - # load_ssh_public_identity returns a union, but this is - # guaranteed to be an SSHCertificate, so we cast to make - # mypy happy. - return typing.cast( - SSHCertificate, - load_ssh_public_identity(b"".join([cert_prefix, b" ", cert_data])), - ) diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/twofactor/__init__.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/twofactor/__init__.py deleted file mode 100644 index c1af423..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/twofactor/__init__.py +++ /dev/null @@ -1,9 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - - -class InvalidToken(Exception): - pass diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/twofactor/hotp.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/twofactor/hotp.py deleted file mode 100644 index 21fb000..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/twofactor/hotp.py +++ /dev/null @@ -1,101 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -import base64 -import typing -from urllib.parse import quote, urlencode - -from cryptography.hazmat.primitives import constant_time, hmac -from cryptography.hazmat.primitives.hashes import SHA1, SHA256, SHA512 -from cryptography.hazmat.primitives.twofactor import InvalidToken -from cryptography.utils import Buffer - -HOTPHashTypes = typing.Union[SHA1, SHA256, SHA512] - - -def _generate_uri( - hotp: HOTP, - type_name: str, - account_name: str, - issuer: str | None, - extra_parameters: list[tuple[str, int]], -) -> str: - parameters = [ - ("digits", hotp._length), - ("secret", base64.b32encode(hotp._key)), - ("algorithm", hotp._algorithm.name.upper()), - ] - - if issuer is not None: - parameters.append(("issuer", issuer)) - - parameters.extend(extra_parameters) - - label = ( - f"{quote(issuer)}:{quote(account_name)}" - if issuer - else quote(account_name) - ) - return f"otpauth://{type_name}/{label}?{urlencode(parameters)}" - - -class HOTP: - def __init__( - self, - key: Buffer, - length: int, - algorithm: HOTPHashTypes, - backend: typing.Any = None, - enforce_key_length: bool = True, - ) -> None: - if len(key) < 16 and enforce_key_length is True: - raise ValueError("Key length has to be at least 128 bits.") - - if not isinstance(length, int): - raise TypeError("Length parameter must be an integer type.") - - if length < 6 or length > 8: - raise ValueError("Length of HOTP has to be between 6 and 8.") - - if not isinstance(algorithm, (SHA1, SHA256, SHA512)): - raise TypeError("Algorithm must be SHA1, SHA256 or SHA512.") - - self._key = key - self._length = length - self._algorithm = algorithm - - def generate(self, counter: int) -> bytes: - if not isinstance(counter, int): - raise TypeError("Counter parameter must be an integer type.") - - truncated_value = self._dynamic_truncate(counter) - hotp = truncated_value % (10**self._length) - return "{0:0{1}}".format(hotp, self._length).encode() - - def verify(self, hotp: bytes, counter: int) -> None: - if not constant_time.bytes_eq(self.generate(counter), hotp): - raise InvalidToken("Supplied HOTP value does not match.") - - def _dynamic_truncate(self, counter: int) -> int: - ctx = hmac.HMAC(self._key, self._algorithm) - - try: - ctx.update(counter.to_bytes(length=8, byteorder="big")) - except OverflowError: - raise ValueError(f"Counter must be between 0 and {2**64 - 1}.") - - hmac_value = ctx.finalize() - - offset = hmac_value[len(hmac_value) - 1] & 0b1111 - p = hmac_value[offset : offset + 4] - return int.from_bytes(p, byteorder="big") & 0x7FFFFFFF - - def get_provisioning_uri( - self, account_name: str, counter: int, issuer: str | None - ) -> str: - return _generate_uri( - self, "hotp", account_name, issuer, [("counter", int(counter))] - ) diff --git a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/twofactor/totp.py b/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/twofactor/totp.py deleted file mode 100644 index 10c725c..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/hazmat/primitives/twofactor/totp.py +++ /dev/null @@ -1,56 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -import typing - -from cryptography.hazmat.primitives import constant_time -from cryptography.hazmat.primitives.twofactor import InvalidToken -from cryptography.hazmat.primitives.twofactor.hotp import ( - HOTP, - HOTPHashTypes, - _generate_uri, -) -from cryptography.utils import Buffer - - -class TOTP: - def __init__( - self, - key: Buffer, - length: int, - algorithm: HOTPHashTypes, - time_step: int, - backend: typing.Any = None, - enforce_key_length: bool = True, - ): - self._time_step = time_step - self._hotp = HOTP( - key, length, algorithm, enforce_key_length=enforce_key_length - ) - - def generate(self, time: int | float) -> bytes: - if not isinstance(time, (int, float)): - raise TypeError( - "Time parameter must be an integer type or float type." - ) - - counter = int(time / self._time_step) - return self._hotp.generate(counter) - - def verify(self, totp: bytes, time: int) -> None: - if not constant_time.bytes_eq(self.generate(time), totp): - raise InvalidToken("Supplied TOTP value does not match.") - - def get_provisioning_uri( - self, account_name: str, issuer: str | None - ) -> str: - return _generate_uri( - self._hotp, - "totp", - account_name, - issuer, - [("period", int(self._time_step))], - ) diff --git a/.venv/lib/python3.12/site-packages/cryptography/py.typed b/.venv/lib/python3.12/site-packages/cryptography/py.typed deleted file mode 100644 index e69de29..0000000 diff --git a/.venv/lib/python3.12/site-packages/cryptography/utils.py b/.venv/lib/python3.12/site-packages/cryptography/utils.py deleted file mode 100644 index 9cfc992..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/utils.py +++ /dev/null @@ -1,135 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -import enum -import sys -import types -import typing -import warnings -from collections.abc import Callable, Sequence - - -# We use a UserWarning subclass, instead of DeprecationWarning, because CPython -# decided deprecation warnings should be invisible by default. -class CryptographyDeprecationWarning(UserWarning): - pass - - -# Several APIs were deprecated with no specific end-of-life date because of the -# ubiquity of their use. They should not be removed until we agree on when that -# cycle ends. -DeprecatedIn36 = CryptographyDeprecationWarning -DeprecatedIn40 = CryptographyDeprecationWarning -DeprecatedIn41 = CryptographyDeprecationWarning -DeprecatedIn42 = CryptographyDeprecationWarning -DeprecatedIn43 = CryptographyDeprecationWarning -DeprecatedIn47 = CryptographyDeprecationWarning - - -# If you're wondering why we don't use `Buffer`, it's because `Buffer` would -# be more accurately named: Bufferable. It means something which has an -# `__buffer__`. Which means you can't actually treat the result as a buffer -# (and do things like take a `len()`). -Buffer = typing.Union[bytes, bytearray, memoryview] - - -def _check_bytes(name: str, value: bytes) -> None: - if not isinstance(value, bytes): - raise TypeError(f"{name} must be bytes") - - -def _check_byteslike(name: str, value: Buffer) -> None: - try: - memoryview(value) - except TypeError: - raise TypeError(f"{name} must be bytes-like") - - -def int_to_bytes(integer: int, length: int | None = None) -> bytes: - if length == 0: - raise ValueError("length argument can't be 0") - return integer.to_bytes( - length or (integer.bit_length() + 7) // 8 or 1, "big" - ) - - -class InterfaceNotImplemented(Exception): - pass - - -class _DeprecatedValue: - def __init__(self, value: object, message: str, warning_class): - self.value = value - self.message = message - self.warning_class = warning_class - - -class _ModuleWithDeprecations(types.ModuleType): - def __init__(self, module: types.ModuleType): - super().__init__(module.__name__) - self.__dict__["_module"] = module - - def __getattr__(self, name: str) -> typing.Any: - obj = getattr(self._module, name) - if isinstance(obj, _DeprecatedValue): - warnings.warn(obj.message, obj.warning_class, stacklevel=2) - obj = obj.value - return obj - - def __setattr__(self, attr: str, value: object) -> None: - setattr(self._module, attr, value) - - def __delattr__(self, attr: str) -> None: - obj = getattr(self._module, attr) - if isinstance(obj, _DeprecatedValue): - warnings.warn(obj.message, obj.warning_class, stacklevel=2) - - delattr(self._module, attr) - - def __dir__(self) -> Sequence[str]: - return ["_module", *dir(self._module)] - - -def deprecated( - value: object, - module_name: str, - message: str, - warning_class: type[Warning], - name: str | None = None, -) -> _DeprecatedValue: - module = sys.modules[module_name] - if not isinstance(module, _ModuleWithDeprecations): - sys.modules[module_name] = module = _ModuleWithDeprecations(module) - dv = _DeprecatedValue(value, message, warning_class) - # Maintain backwards compatibility with `name is None` for pyOpenSSL. - if name is not None: - setattr(module, name, dv) - return dv - - -def cached_property(func: Callable) -> property: - cached_name = f"_cached_{func}" - sentinel = object() - - def inner(instance: object): - cache = getattr(instance, cached_name, sentinel) - if cache is not sentinel: - return cache - result = func(instance) - setattr(instance, cached_name, result) - return result - - return property(inner) - - -# Python 3.10 changed representation of enums. We use well-defined object -# representation and string representation from Python 3.9. -class Enum(enum.Enum): - def __repr__(self) -> str: - return f"<{self.__class__.__name__}.{self._name_}: {self._value_!r}>" - - def __str__(self) -> str: - return f"{self.__class__.__name__}.{self._name_}" diff --git a/.venv/lib/python3.12/site-packages/cryptography/x509/__init__.py b/.venv/lib/python3.12/site-packages/cryptography/x509/__init__.py deleted file mode 100644 index cb34833..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/x509/__init__.py +++ /dev/null @@ -1,271 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -from cryptography.x509 import certificate_transparency, oid, verification -from cryptography.x509.base import ( - Attribute, - AttributeNotFound, - Attributes, - Certificate, - CertificateBuilder, - CertificateRevocationList, - CertificateRevocationListBuilder, - CertificateSigningRequest, - CertificateSigningRequestBuilder, - InvalidVersion, - RevokedCertificate, - RevokedCertificateBuilder, - Version, - load_der_x509_certificate, - load_der_x509_crl, - load_der_x509_csr, - load_pem_x509_certificate, - load_pem_x509_certificates, - load_pem_x509_crl, - load_pem_x509_csr, - random_serial_number, -) -from cryptography.x509.extensions import ( - AccessDescription, - Admission, - Admissions, - AuthorityInformationAccess, - AuthorityKeyIdentifier, - BasicConstraints, - CertificateIssuer, - CertificatePolicies, - CRLDistributionPoints, - CRLNumber, - CRLReason, - DeltaCRLIndicator, - DistributionPoint, - DuplicateExtension, - ExtendedKeyUsage, - Extension, - ExtensionNotFound, - Extensions, - ExtensionType, - FreshestCRL, - GeneralNames, - InhibitAnyPolicy, - InvalidityDate, - IssuerAlternativeName, - IssuingDistributionPoint, - KeyUsage, - MSCertificateTemplate, - NameConstraints, - NamingAuthority, - NoticeReference, - OCSPAcceptableResponses, - OCSPNoCheck, - OCSPNonce, - PolicyConstraints, - PolicyInformation, - PrecertificateSignedCertificateTimestamps, - PrecertPoison, - PrivateKeyUsagePeriod, - ProfessionInfo, - ReasonFlags, - SignedCertificateTimestamps, - SubjectAlternativeName, - SubjectInformationAccess, - SubjectKeyIdentifier, - TLSFeature, - TLSFeatureType, - UnrecognizedExtension, - UserNotice, -) -from cryptography.x509.general_name import ( - DirectoryName, - DNSName, - GeneralName, - IPAddress, - OtherName, - RegisteredID, - RFC822Name, - UniformResourceIdentifier, - UnsupportedGeneralNameType, -) -from cryptography.x509.name import ( - Name, - NameAttribute, - RelativeDistinguishedName, -) -from cryptography.x509.oid import ( - AuthorityInformationAccessOID, - CertificatePoliciesOID, - CRLEntryExtensionOID, - ExtendedKeyUsageOID, - ExtensionOID, - NameOID, - ObjectIdentifier, - PublicKeyAlgorithmOID, - SignatureAlgorithmOID, -) - -OID_AUTHORITY_INFORMATION_ACCESS = ExtensionOID.AUTHORITY_INFORMATION_ACCESS -OID_AUTHORITY_KEY_IDENTIFIER = ExtensionOID.AUTHORITY_KEY_IDENTIFIER -OID_BASIC_CONSTRAINTS = ExtensionOID.BASIC_CONSTRAINTS -OID_CERTIFICATE_POLICIES = ExtensionOID.CERTIFICATE_POLICIES -OID_CRL_DISTRIBUTION_POINTS = ExtensionOID.CRL_DISTRIBUTION_POINTS -OID_EXTENDED_KEY_USAGE = ExtensionOID.EXTENDED_KEY_USAGE -OID_FRESHEST_CRL = ExtensionOID.FRESHEST_CRL -OID_INHIBIT_ANY_POLICY = ExtensionOID.INHIBIT_ANY_POLICY -OID_ISSUER_ALTERNATIVE_NAME = ExtensionOID.ISSUER_ALTERNATIVE_NAME -OID_KEY_USAGE = ExtensionOID.KEY_USAGE -OID_PRIVATE_KEY_USAGE_PERIOD = ExtensionOID.PRIVATE_KEY_USAGE_PERIOD -OID_NAME_CONSTRAINTS = ExtensionOID.NAME_CONSTRAINTS -OID_OCSP_NO_CHECK = ExtensionOID.OCSP_NO_CHECK -OID_POLICY_CONSTRAINTS = ExtensionOID.POLICY_CONSTRAINTS -OID_POLICY_MAPPINGS = ExtensionOID.POLICY_MAPPINGS -OID_SUBJECT_ALTERNATIVE_NAME = ExtensionOID.SUBJECT_ALTERNATIVE_NAME -OID_SUBJECT_DIRECTORY_ATTRIBUTES = ExtensionOID.SUBJECT_DIRECTORY_ATTRIBUTES -OID_SUBJECT_INFORMATION_ACCESS = ExtensionOID.SUBJECT_INFORMATION_ACCESS -OID_SUBJECT_KEY_IDENTIFIER = ExtensionOID.SUBJECT_KEY_IDENTIFIER - -OID_DSA_WITH_SHA1 = SignatureAlgorithmOID.DSA_WITH_SHA1 -OID_DSA_WITH_SHA224 = SignatureAlgorithmOID.DSA_WITH_SHA224 -OID_DSA_WITH_SHA256 = SignatureAlgorithmOID.DSA_WITH_SHA256 -OID_ECDSA_WITH_SHA1 = SignatureAlgorithmOID.ECDSA_WITH_SHA1 -OID_ECDSA_WITH_SHA224 = SignatureAlgorithmOID.ECDSA_WITH_SHA224 -OID_ECDSA_WITH_SHA256 = SignatureAlgorithmOID.ECDSA_WITH_SHA256 -OID_ECDSA_WITH_SHA384 = SignatureAlgorithmOID.ECDSA_WITH_SHA384 -OID_ECDSA_WITH_SHA512 = SignatureAlgorithmOID.ECDSA_WITH_SHA512 -OID_RSA_WITH_MD5 = SignatureAlgorithmOID.RSA_WITH_MD5 -OID_RSA_WITH_SHA1 = SignatureAlgorithmOID.RSA_WITH_SHA1 -OID_RSA_WITH_SHA224 = SignatureAlgorithmOID.RSA_WITH_SHA224 -OID_RSA_WITH_SHA256 = SignatureAlgorithmOID.RSA_WITH_SHA256 -OID_RSA_WITH_SHA384 = SignatureAlgorithmOID.RSA_WITH_SHA384 -OID_RSA_WITH_SHA512 = SignatureAlgorithmOID.RSA_WITH_SHA512 -OID_RSASSA_PSS = SignatureAlgorithmOID.RSASSA_PSS - -OID_COMMON_NAME = NameOID.COMMON_NAME -OID_COUNTRY_NAME = NameOID.COUNTRY_NAME -OID_DOMAIN_COMPONENT = NameOID.DOMAIN_COMPONENT -OID_DN_QUALIFIER = NameOID.DN_QUALIFIER -OID_EMAIL_ADDRESS = NameOID.EMAIL_ADDRESS -OID_GENERATION_QUALIFIER = NameOID.GENERATION_QUALIFIER -OID_GIVEN_NAME = NameOID.GIVEN_NAME -OID_LOCALITY_NAME = NameOID.LOCALITY_NAME -OID_ORGANIZATIONAL_UNIT_NAME = NameOID.ORGANIZATIONAL_UNIT_NAME -OID_ORGANIZATION_NAME = NameOID.ORGANIZATION_NAME -OID_PSEUDONYM = NameOID.PSEUDONYM -OID_SERIAL_NUMBER = NameOID.SERIAL_NUMBER -OID_STATE_OR_PROVINCE_NAME = NameOID.STATE_OR_PROVINCE_NAME -OID_SURNAME = NameOID.SURNAME -OID_TITLE = NameOID.TITLE - -OID_CLIENT_AUTH = ExtendedKeyUsageOID.CLIENT_AUTH -OID_CODE_SIGNING = ExtendedKeyUsageOID.CODE_SIGNING -OID_EMAIL_PROTECTION = ExtendedKeyUsageOID.EMAIL_PROTECTION -OID_OCSP_SIGNING = ExtendedKeyUsageOID.OCSP_SIGNING -OID_SERVER_AUTH = ExtendedKeyUsageOID.SERVER_AUTH -OID_TIME_STAMPING = ExtendedKeyUsageOID.TIME_STAMPING - -OID_ANY_POLICY = CertificatePoliciesOID.ANY_POLICY -OID_CPS_QUALIFIER = CertificatePoliciesOID.CPS_QUALIFIER -OID_CPS_USER_NOTICE = CertificatePoliciesOID.CPS_USER_NOTICE - -OID_CERTIFICATE_ISSUER = CRLEntryExtensionOID.CERTIFICATE_ISSUER -OID_CRL_REASON = CRLEntryExtensionOID.CRL_REASON -OID_INVALIDITY_DATE = CRLEntryExtensionOID.INVALIDITY_DATE - -OID_CA_ISSUERS = AuthorityInformationAccessOID.CA_ISSUERS -OID_OCSP = AuthorityInformationAccessOID.OCSP - -__all__ = [ - "OID_CA_ISSUERS", - "OID_OCSP", - "AccessDescription", - "Admission", - "Admissions", - "Attribute", - "AttributeNotFound", - "Attributes", - "AuthorityInformationAccess", - "AuthorityKeyIdentifier", - "BasicConstraints", - "CRLDistributionPoints", - "CRLNumber", - "CRLReason", - "Certificate", - "CertificateBuilder", - "CertificateIssuer", - "CertificatePolicies", - "CertificateRevocationList", - "CertificateRevocationListBuilder", - "CertificateSigningRequest", - "CertificateSigningRequestBuilder", - "DNSName", - "DeltaCRLIndicator", - "DirectoryName", - "DistributionPoint", - "DuplicateExtension", - "ExtendedKeyUsage", - "Extension", - "ExtensionNotFound", - "ExtensionType", - "Extensions", - "FreshestCRL", - "GeneralName", - "GeneralNames", - "IPAddress", - "InhibitAnyPolicy", - "InvalidVersion", - "InvalidityDate", - "IssuerAlternativeName", - "IssuingDistributionPoint", - "KeyUsage", - "MSCertificateTemplate", - "Name", - "NameAttribute", - "NameConstraints", - "NameOID", - "NamingAuthority", - "NoticeReference", - "OCSPAcceptableResponses", - "OCSPNoCheck", - "OCSPNonce", - "ObjectIdentifier", - "OtherName", - "PolicyConstraints", - "PolicyInformation", - "PrecertPoison", - "PrecertificateSignedCertificateTimestamps", - "PrivateKeyUsagePeriod", - "ProfessionInfo", - "PublicKeyAlgorithmOID", - "RFC822Name", - "ReasonFlags", - "RegisteredID", - "RelativeDistinguishedName", - "RevokedCertificate", - "RevokedCertificateBuilder", - "SignatureAlgorithmOID", - "SignedCertificateTimestamps", - "SubjectAlternativeName", - "SubjectInformationAccess", - "SubjectKeyIdentifier", - "TLSFeature", - "TLSFeatureType", - "UniformResourceIdentifier", - "UnrecognizedExtension", - "UnsupportedGeneralNameType", - "UserNotice", - "Version", - "certificate_transparency", - "load_der_x509_certificate", - "load_der_x509_crl", - "load_der_x509_csr", - "load_pem_x509_certificate", - "load_pem_x509_certificates", - "load_pem_x509_crl", - "load_pem_x509_csr", - "oid", - "random_serial_number", - "verification", - "verification", -] diff --git a/.venv/lib/python3.12/site-packages/cryptography/x509/base.py b/.venv/lib/python3.12/site-packages/cryptography/x509/base.py deleted file mode 100644 index a11b8fe..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/x509/base.py +++ /dev/null @@ -1,773 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -import datetime -import os -import typing -from collections.abc import Iterable - -from cryptography import utils -from cryptography.hazmat.bindings._rust import x509 as rust_x509 -from cryptography.hazmat.primitives import hashes -from cryptography.hazmat.primitives.asymmetric import ( - dsa, - ec, - ed448, - ed25519, - padding, - rsa, - x448, - x25519, -) -from cryptography.hazmat.primitives.asymmetric.types import ( - CertificateIssuerPrivateKeyTypes, - CertificatePublicKeyTypes, -) -from cryptography.x509.extensions import ( - Extension, - ExtensionType, - _make_sequence_methods, -) -from cryptography.x509.name import Name, _ASN1Type -from cryptography.x509.oid import ObjectIdentifier - -_EARLIEST_UTC_TIME = datetime.datetime(1950, 1, 1) - -# This must be kept in sync with sign.rs's list of allowable types in -# identify_hash_type -_AllowedHashTypes = typing.Union[ - hashes.SHA224, - hashes.SHA256, - hashes.SHA384, - hashes.SHA512, - hashes.SHA3_224, - hashes.SHA3_256, - hashes.SHA3_384, - hashes.SHA3_512, -] - - -class AttributeNotFound(Exception): - def __init__(self, msg: str, oid: ObjectIdentifier) -> None: - super().__init__(msg) - self.oid = oid - - -def _reject_duplicate_extension( - extension: Extension[ExtensionType], - extensions: list[Extension[ExtensionType]], -) -> None: - # This is quadratic in the number of extensions - for e in extensions: - if e.oid == extension.oid: - raise ValueError("This extension has already been set.") - - -def _reject_duplicate_attribute( - oid: ObjectIdentifier, - attributes: list[tuple[ObjectIdentifier, bytes, int | None]], -) -> None: - # This is quadratic in the number of attributes - for attr_oid, _, _ in attributes: - if attr_oid == oid: - raise ValueError("This attribute has already been set.") - - -def _convert_to_naive_utc_time(time: datetime.datetime) -> datetime.datetime: - """Normalizes a datetime to a naive datetime in UTC. - - time -- datetime to normalize. Assumed to be in UTC if not timezone - aware. - """ - if time.tzinfo is not None: - offset = time.utcoffset() - offset = offset if offset else datetime.timedelta() - return time.replace(tzinfo=None) - offset - else: - return time - - -class Attribute: - def __init__( - self, - oid: ObjectIdentifier, - value: bytes, - _type: int = _ASN1Type.UTF8String.value, - ) -> None: - self._oid = oid - self._value = value - self._type = _type - - @property - def oid(self) -> ObjectIdentifier: - return self._oid - - @property - def value(self) -> bytes: - return self._value - - def __repr__(self) -> str: - return f"" - - def __eq__(self, other: object) -> bool: - if not isinstance(other, Attribute): - return NotImplemented - - return ( - self.oid == other.oid - and self.value == other.value - and self._type == other._type - ) - - def __hash__(self) -> int: - return hash((self.oid, self.value, self._type)) - - -class Attributes: - def __init__( - self, - attributes: Iterable[Attribute], - ) -> None: - self._attributes = list(attributes) - - __len__, __iter__, __getitem__ = _make_sequence_methods("_attributes") - - def __repr__(self) -> str: - return f"" - - def get_attribute_for_oid(self, oid: ObjectIdentifier) -> Attribute: - for attr in self: - if attr.oid == oid: - return attr - - raise AttributeNotFound(f"No {oid} attribute was found", oid) - - -class Version(utils.Enum): - v1 = 0 - v3 = 2 - - -class InvalidVersion(Exception): - def __init__(self, msg: str, parsed_version: int) -> None: - super().__init__(msg) - self.parsed_version = parsed_version - - -Certificate = rust_x509.Certificate -RevokedCertificate = rust_x509.RevokedCertificate - - -CertificateRevocationList = rust_x509.CertificateRevocationList -CertificateSigningRequest = rust_x509.CertificateSigningRequest - - -load_pem_x509_certificate = rust_x509.load_pem_x509_certificate -load_der_x509_certificate = rust_x509.load_der_x509_certificate - -load_pem_x509_certificates = rust_x509.load_pem_x509_certificates - -load_pem_x509_csr = rust_x509.load_pem_x509_csr -load_der_x509_csr = rust_x509.load_der_x509_csr - -load_pem_x509_crl = rust_x509.load_pem_x509_crl -load_der_x509_crl = rust_x509.load_der_x509_crl - - -class CertificateSigningRequestBuilder: - def __init__( - self, - subject_name: Name | None = None, - extensions: list[Extension[ExtensionType]] = [], - attributes: list[tuple[ObjectIdentifier, bytes, int | None]] = [], - ): - """ - Creates an empty X.509 certificate request (v1). - """ - self._subject_name = subject_name - self._extensions = extensions - self._attributes = attributes - - def subject_name(self, name: Name) -> CertificateSigningRequestBuilder: - """ - Sets the certificate requestor's distinguished name. - """ - if not isinstance(name, Name): - raise TypeError("Expecting x509.Name object.") - if self._subject_name is not None: - raise ValueError("The subject name may only be set once.") - return CertificateSigningRequestBuilder( - name, self._extensions, self._attributes - ) - - def add_extension( - self, extval: ExtensionType, critical: bool - ) -> CertificateSigningRequestBuilder: - """ - Adds an X.509 extension to the certificate request. - """ - if not isinstance(extval, ExtensionType): - raise TypeError("extension must be an ExtensionType") - - extension = Extension(extval.oid, critical, extval) - _reject_duplicate_extension(extension, self._extensions) - - return CertificateSigningRequestBuilder( - self._subject_name, - [*self._extensions, extension], - self._attributes, - ) - - def add_attribute( - self, - oid: ObjectIdentifier, - value: bytes, - *, - _tag: _ASN1Type | None = None, - ) -> CertificateSigningRequestBuilder: - """ - Adds an X.509 attribute with an OID and associated value. - """ - if not isinstance(oid, ObjectIdentifier): - raise TypeError("oid must be an ObjectIdentifier") - - if not isinstance(value, bytes): - raise TypeError("value must be bytes") - - if _tag is not None and not isinstance(_tag, _ASN1Type): - raise TypeError("tag must be _ASN1Type") - - _reject_duplicate_attribute(oid, self._attributes) - - if _tag is not None: - tag = _tag.value - else: - tag = None - - return CertificateSigningRequestBuilder( - self._subject_name, - self._extensions, - [*self._attributes, (oid, value, tag)], - ) - - def sign( - self, - private_key: CertificateIssuerPrivateKeyTypes, - algorithm: _AllowedHashTypes | None, - backend: typing.Any = None, - *, - rsa_padding: padding.PSS | padding.PKCS1v15 | None = None, - ecdsa_deterministic: bool | None = None, - ) -> CertificateSigningRequest: - """ - Signs the request using the requestor's private key. - """ - if self._subject_name is None: - raise ValueError("A CertificateSigningRequest must have a subject") - - if rsa_padding is not None: - if not isinstance(rsa_padding, (padding.PSS, padding.PKCS1v15)): - raise TypeError("Padding must be PSS or PKCS1v15") - if not isinstance(private_key, rsa.RSAPrivateKey): - raise TypeError("Padding is only supported for RSA keys") - - if ecdsa_deterministic is not None: - if not isinstance(private_key, ec.EllipticCurvePrivateKey): - raise TypeError( - "Deterministic ECDSA is only supported for EC keys" - ) - - return rust_x509.create_x509_csr( - self, - private_key, - algorithm, - rsa_padding, - ecdsa_deterministic, - ) - - -class CertificateBuilder: - _extensions: list[Extension[ExtensionType]] - - def __init__( - self, - issuer_name: Name | None = None, - subject_name: Name | None = None, - public_key: CertificatePublicKeyTypes | None = None, - serial_number: int | None = None, - not_valid_before: datetime.datetime | None = None, - not_valid_after: datetime.datetime | None = None, - extensions: list[Extension[ExtensionType]] = [], - ) -> None: - self._version = Version.v3 - self._issuer_name = issuer_name - self._subject_name = subject_name - self._public_key = public_key - self._serial_number = serial_number - self._not_valid_before = not_valid_before - self._not_valid_after = not_valid_after - self._extensions = extensions - - def issuer_name(self, name: Name) -> CertificateBuilder: - """ - Sets the CA's distinguished name. - """ - if not isinstance(name, Name): - raise TypeError("Expecting x509.Name object.") - if self._issuer_name is not None: - raise ValueError("The issuer name may only be set once.") - return CertificateBuilder( - name, - self._subject_name, - self._public_key, - self._serial_number, - self._not_valid_before, - self._not_valid_after, - self._extensions, - ) - - def subject_name(self, name: Name) -> CertificateBuilder: - """ - Sets the requestor's distinguished name. - """ - if not isinstance(name, Name): - raise TypeError("Expecting x509.Name object.") - if self._subject_name is not None: - raise ValueError("The subject name may only be set once.") - return CertificateBuilder( - self._issuer_name, - name, - self._public_key, - self._serial_number, - self._not_valid_before, - self._not_valid_after, - self._extensions, - ) - - def public_key( - self, - key: CertificatePublicKeyTypes, - ) -> CertificateBuilder: - """ - Sets the requestor's public key (as found in the signing request). - """ - if not isinstance( - key, - ( - dsa.DSAPublicKey, - rsa.RSAPublicKey, - ec.EllipticCurvePublicKey, - ed25519.Ed25519PublicKey, - ed448.Ed448PublicKey, - x25519.X25519PublicKey, - x448.X448PublicKey, - ), - ): - raise TypeError( - "Expecting one of DSAPublicKey, RSAPublicKey," - " EllipticCurvePublicKey, Ed25519PublicKey," - " Ed448PublicKey, X25519PublicKey, or " - "X448PublicKey." - ) - if self._public_key is not None: - raise ValueError("The public key may only be set once.") - return CertificateBuilder( - self._issuer_name, - self._subject_name, - key, - self._serial_number, - self._not_valid_before, - self._not_valid_after, - self._extensions, - ) - - def serial_number(self, number: int) -> CertificateBuilder: - """ - Sets the certificate serial number. - """ - if not isinstance(number, int): - raise TypeError("Serial number must be of integral type.") - if self._serial_number is not None: - raise ValueError("The serial number may only be set once.") - if number <= 0: - raise ValueError("The serial number should be positive.") - - # ASN.1 integers are always signed, so most significant bit must be - # zero. - if number.bit_length() >= 160: # As defined in RFC 5280 - raise ValueError( - "The serial number should not be more than 159 bits." - ) - return CertificateBuilder( - self._issuer_name, - self._subject_name, - self._public_key, - number, - self._not_valid_before, - self._not_valid_after, - self._extensions, - ) - - def not_valid_before(self, time: datetime.datetime) -> CertificateBuilder: - """ - Sets the certificate activation time. - """ - if not isinstance(time, datetime.datetime): - raise TypeError("Expecting datetime object.") - if self._not_valid_before is not None: - raise ValueError("The not valid before may only be set once.") - time = _convert_to_naive_utc_time(time) - if time < _EARLIEST_UTC_TIME: - raise ValueError( - "The not valid before date must be on or after" - " 1950 January 1)." - ) - if self._not_valid_after is not None and time > self._not_valid_after: - raise ValueError( - "The not valid before date must be before the not valid after " - "date." - ) - return CertificateBuilder( - self._issuer_name, - self._subject_name, - self._public_key, - self._serial_number, - time, - self._not_valid_after, - self._extensions, - ) - - def not_valid_after(self, time: datetime.datetime) -> CertificateBuilder: - """ - Sets the certificate expiration time. - """ - if not isinstance(time, datetime.datetime): - raise TypeError("Expecting datetime object.") - if self._not_valid_after is not None: - raise ValueError("The not valid after may only be set once.") - time = _convert_to_naive_utc_time(time) - if time < _EARLIEST_UTC_TIME: - raise ValueError( - "The not valid after date must be on or after 1950 January 1." - ) - if ( - self._not_valid_before is not None - and time < self._not_valid_before - ): - raise ValueError( - "The not valid after date must be after the not valid before " - "date." - ) - return CertificateBuilder( - self._issuer_name, - self._subject_name, - self._public_key, - self._serial_number, - self._not_valid_before, - time, - self._extensions, - ) - - def add_extension( - self, extval: ExtensionType, critical: bool - ) -> CertificateBuilder: - """ - Adds an X.509 extension to the certificate. - """ - if not isinstance(extval, ExtensionType): - raise TypeError("extension must be an ExtensionType") - - extension = Extension(extval.oid, critical, extval) - _reject_duplicate_extension(extension, self._extensions) - - return CertificateBuilder( - self._issuer_name, - self._subject_name, - self._public_key, - self._serial_number, - self._not_valid_before, - self._not_valid_after, - [*self._extensions, extension], - ) - - def sign( - self, - private_key: CertificateIssuerPrivateKeyTypes, - algorithm: _AllowedHashTypes | None, - backend: typing.Any = None, - *, - rsa_padding: padding.PSS | padding.PKCS1v15 | None = None, - ecdsa_deterministic: bool | None = None, - ) -> Certificate: - """ - Signs the certificate using the CA's private key. - """ - if self._subject_name is None: - raise ValueError("A certificate must have a subject name") - - if self._issuer_name is None: - raise ValueError("A certificate must have an issuer name") - - if self._serial_number is None: - raise ValueError("A certificate must have a serial number") - - if self._not_valid_before is None: - raise ValueError("A certificate must have a not valid before time") - - if self._not_valid_after is None: - raise ValueError("A certificate must have a not valid after time") - - if self._public_key is None: - raise ValueError("A certificate must have a public key") - - if rsa_padding is not None: - if not isinstance(rsa_padding, (padding.PSS, padding.PKCS1v15)): - raise TypeError("Padding must be PSS or PKCS1v15") - if not isinstance(private_key, rsa.RSAPrivateKey): - raise TypeError("Padding is only supported for RSA keys") - - if ecdsa_deterministic is not None: - if not isinstance(private_key, ec.EllipticCurvePrivateKey): - raise TypeError( - "Deterministic ECDSA is only supported for EC keys" - ) - - return rust_x509.create_x509_certificate( - self, - private_key, - algorithm, - rsa_padding, - ecdsa_deterministic, - ) - - -class CertificateRevocationListBuilder: - _extensions: list[Extension[ExtensionType]] - _revoked_certificates: list[RevokedCertificate] - - def __init__( - self, - issuer_name: Name | None = None, - last_update: datetime.datetime | None = None, - next_update: datetime.datetime | None = None, - extensions: list[Extension[ExtensionType]] = [], - revoked_certificates: list[RevokedCertificate] = [], - ): - self._issuer_name = issuer_name - self._last_update = last_update - self._next_update = next_update - self._extensions = extensions - self._revoked_certificates = revoked_certificates - - def issuer_name( - self, issuer_name: Name - ) -> CertificateRevocationListBuilder: - if not isinstance(issuer_name, Name): - raise TypeError("Expecting x509.Name object.") - if self._issuer_name is not None: - raise ValueError("The issuer name may only be set once.") - return CertificateRevocationListBuilder( - issuer_name, - self._last_update, - self._next_update, - self._extensions, - self._revoked_certificates, - ) - - def last_update( - self, last_update: datetime.datetime - ) -> CertificateRevocationListBuilder: - if not isinstance(last_update, datetime.datetime): - raise TypeError("Expecting datetime object.") - if self._last_update is not None: - raise ValueError("Last update may only be set once.") - last_update = _convert_to_naive_utc_time(last_update) - if last_update < _EARLIEST_UTC_TIME: - raise ValueError( - "The last update date must be on or after 1950 January 1." - ) - if self._next_update is not None and last_update > self._next_update: - raise ValueError( - "The last update date must be before the next update date." - ) - return CertificateRevocationListBuilder( - self._issuer_name, - last_update, - self._next_update, - self._extensions, - self._revoked_certificates, - ) - - def next_update( - self, next_update: datetime.datetime - ) -> CertificateRevocationListBuilder: - if not isinstance(next_update, datetime.datetime): - raise TypeError("Expecting datetime object.") - if self._next_update is not None: - raise ValueError("Last update may only be set once.") - next_update = _convert_to_naive_utc_time(next_update) - if next_update < _EARLIEST_UTC_TIME: - raise ValueError( - "The last update date must be on or after 1950 January 1." - ) - if self._last_update is not None and next_update < self._last_update: - raise ValueError( - "The next update date must be after the last update date." - ) - return CertificateRevocationListBuilder( - self._issuer_name, - self._last_update, - next_update, - self._extensions, - self._revoked_certificates, - ) - - def add_extension( - self, extval: ExtensionType, critical: bool - ) -> CertificateRevocationListBuilder: - """ - Adds an X.509 extension to the certificate revocation list. - """ - if not isinstance(extval, ExtensionType): - raise TypeError("extension must be an ExtensionType") - - extension = Extension(extval.oid, critical, extval) - _reject_duplicate_extension(extension, self._extensions) - return CertificateRevocationListBuilder( - self._issuer_name, - self._last_update, - self._next_update, - [*self._extensions, extension], - self._revoked_certificates, - ) - - def add_revoked_certificate( - self, revoked_certificate: RevokedCertificate - ) -> CertificateRevocationListBuilder: - """ - Adds a revoked certificate to the CRL. - """ - if not isinstance(revoked_certificate, RevokedCertificate): - raise TypeError("Must be an instance of RevokedCertificate") - - return CertificateRevocationListBuilder( - self._issuer_name, - self._last_update, - self._next_update, - self._extensions, - [*self._revoked_certificates, revoked_certificate], - ) - - def sign( - self, - private_key: CertificateIssuerPrivateKeyTypes, - algorithm: _AllowedHashTypes | None, - backend: typing.Any = None, - *, - rsa_padding: padding.PSS | padding.PKCS1v15 | None = None, - ecdsa_deterministic: bool | None = None, - ) -> CertificateRevocationList: - if self._issuer_name is None: - raise ValueError("A CRL must have an issuer name") - - if self._last_update is None: - raise ValueError("A CRL must have a last update time") - - if self._next_update is None: - raise ValueError("A CRL must have a next update time") - - if rsa_padding is not None: - if not isinstance(rsa_padding, (padding.PSS, padding.PKCS1v15)): - raise TypeError("Padding must be PSS or PKCS1v15") - if not isinstance(private_key, rsa.RSAPrivateKey): - raise TypeError("Padding is only supported for RSA keys") - - if ecdsa_deterministic is not None: - if not isinstance(private_key, ec.EllipticCurvePrivateKey): - raise TypeError( - "Deterministic ECDSA is only supported for EC keys" - ) - - return rust_x509.create_x509_crl( - self, - private_key, - algorithm, - rsa_padding, - ecdsa_deterministic, - ) - - -class RevokedCertificateBuilder: - def __init__( - self, - serial_number: int | None = None, - revocation_date: datetime.datetime | None = None, - extensions: list[Extension[ExtensionType]] = [], - ): - self._serial_number = serial_number - self._revocation_date = revocation_date - self._extensions = extensions - - def serial_number(self, number: int) -> RevokedCertificateBuilder: - if not isinstance(number, int): - raise TypeError("Serial number must be of integral type.") - if self._serial_number is not None: - raise ValueError("The serial number may only be set once.") - if number <= 0: - raise ValueError("The serial number should be positive") - - # ASN.1 integers are always signed, so most significant bit must be - # zero. - if number.bit_length() >= 160: # As defined in RFC 5280 - raise ValueError( - "The serial number should not be more than 159 bits." - ) - return RevokedCertificateBuilder( - number, self._revocation_date, self._extensions - ) - - def revocation_date( - self, time: datetime.datetime - ) -> RevokedCertificateBuilder: - if not isinstance(time, datetime.datetime): - raise TypeError("Expecting datetime object.") - if self._revocation_date is not None: - raise ValueError("The revocation date may only be set once.") - time = _convert_to_naive_utc_time(time) - if time < _EARLIEST_UTC_TIME: - raise ValueError( - "The revocation date must be on or after 1950 January 1." - ) - return RevokedCertificateBuilder( - self._serial_number, time, self._extensions - ) - - def add_extension( - self, extval: ExtensionType, critical: bool - ) -> RevokedCertificateBuilder: - if not isinstance(extval, ExtensionType): - raise TypeError("extension must be an ExtensionType") - - extension = Extension(extval.oid, critical, extval) - _reject_duplicate_extension(extension, self._extensions) - return RevokedCertificateBuilder( - self._serial_number, - self._revocation_date, - [*self._extensions, extension], - ) - - def build(self, backend: typing.Any = None) -> RevokedCertificate: - if self._serial_number is None: - raise ValueError("A revoked certificate must have a serial number") - if self._revocation_date is None: - raise ValueError( - "A revoked certificate must have a revocation date" - ) - return rust_x509.create_revoked_certificate(self) - - -def random_serial_number() -> int: - return int.from_bytes(os.urandom(20), "big") >> 1 diff --git a/.venv/lib/python3.12/site-packages/cryptography/x509/certificate_transparency.py b/.venv/lib/python3.12/site-packages/cryptography/x509/certificate_transparency.py deleted file mode 100644 index fb66cc6..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/x509/certificate_transparency.py +++ /dev/null @@ -1,35 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -from cryptography import utils -from cryptography.hazmat.bindings._rust import x509 as rust_x509 - - -class LogEntryType(utils.Enum): - X509_CERTIFICATE = 0 - PRE_CERTIFICATE = 1 - - -class Version(utils.Enum): - v1 = 0 - - -class SignatureAlgorithm(utils.Enum): - """ - Signature algorithms that are valid for SCTs. - - These are exactly the same as SignatureAlgorithm in RFC 5246 (TLS 1.2). - - See: - """ - - ANONYMOUS = 0 - RSA = 1 - DSA = 2 - ECDSA = 3 - - -SignedCertificateTimestamp = rust_x509.Sct diff --git a/.venv/lib/python3.12/site-packages/cryptography/x509/extensions.py b/.venv/lib/python3.12/site-packages/cryptography/x509/extensions.py deleted file mode 100644 index 7b78e9e..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/x509/extensions.py +++ /dev/null @@ -1,2533 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -import abc -import datetime -import hashlib -import ipaddress -import typing -from collections.abc import Iterable, Iterator - -from cryptography import utils -from cryptography.hazmat.bindings._rust import asn1 -from cryptography.hazmat.bindings._rust import x509 as rust_x509 -from cryptography.hazmat.primitives import constant_time, serialization -from cryptography.hazmat.primitives.asymmetric.ec import EllipticCurvePublicKey -from cryptography.hazmat.primitives.asymmetric.rsa import RSAPublicKey -from cryptography.hazmat.primitives.asymmetric.types import ( - CertificateIssuerPublicKeyTypes, - CertificatePublicKeyTypes, -) -from cryptography.x509.certificate_transparency import ( - SignedCertificateTimestamp, -) -from cryptography.x509.general_name import ( - DirectoryName, - DNSName, - GeneralName, - IPAddress, - OtherName, - RegisteredID, - RFC822Name, - UniformResourceIdentifier, - _IPAddressTypes, -) -from cryptography.x509.name import Name, RelativeDistinguishedName -from cryptography.x509.oid import ( - CRLEntryExtensionOID, - ExtensionOID, - ObjectIdentifier, - OCSPExtensionOID, -) - -ExtensionTypeVar = typing.TypeVar( - "ExtensionTypeVar", bound="ExtensionType", covariant=True -) - - -def _key_identifier_from_public_key( - public_key: CertificatePublicKeyTypes, -) -> bytes: - if isinstance(public_key, RSAPublicKey): - data = public_key.public_bytes( - serialization.Encoding.DER, - serialization.PublicFormat.PKCS1, - ) - elif isinstance(public_key, EllipticCurvePublicKey): - data = public_key.public_bytes( - serialization.Encoding.X962, - serialization.PublicFormat.UncompressedPoint, - ) - else: - # This is a very slow way to do this. - serialized = public_key.public_bytes( - serialization.Encoding.DER, - serialization.PublicFormat.SubjectPublicKeyInfo, - ) - data = asn1.parse_spki_for_data(serialized) - - return hashlib.sha1(data).digest() - - -def _make_sequence_methods(field_name: str): - def len_method(self) -> int: - return len(getattr(self, field_name)) - - def iter_method(self): - return iter(getattr(self, field_name)) - - def getitem_method(self, idx): - return getattr(self, field_name)[idx] - - return len_method, iter_method, getitem_method - - -class DuplicateExtension(Exception): - def __init__(self, msg: str, oid: ObjectIdentifier) -> None: - super().__init__(msg) - self.oid = oid - - -class ExtensionNotFound(Exception): - def __init__(self, msg: str, oid: ObjectIdentifier) -> None: - super().__init__(msg) - self.oid = oid - - -class ExtensionType(metaclass=abc.ABCMeta): - oid: typing.ClassVar[ObjectIdentifier] - - def public_bytes(self) -> bytes: - """ - Serializes the extension type to DER. - """ - raise NotImplementedError( - f"public_bytes is not implemented for extension type {self!r}" - ) - - -class Extensions: - def __init__(self, extensions: Iterable[Extension[ExtensionType]]) -> None: - self._extensions = list(extensions) - - def get_extension_for_oid( - self, oid: ObjectIdentifier - ) -> Extension[ExtensionType]: - for ext in self: - if ext.oid == oid: - return ext - - raise ExtensionNotFound(f"No {oid} extension was found", oid) - - def get_extension_for_class( - self, extclass: type[ExtensionTypeVar] - ) -> Extension[ExtensionTypeVar]: - if extclass is UnrecognizedExtension: - raise TypeError( - "UnrecognizedExtension can't be used with " - "get_extension_for_class because more than one instance of the" - " class may be present." - ) - - for ext in self: - if isinstance(ext.value, extclass): - return ext - - raise ExtensionNotFound( - f"No {extclass} extension was found", extclass.oid - ) - - __len__, __iter__, __getitem__ = _make_sequence_methods("_extensions") - - def __repr__(self) -> str: - return f"" - - -class CRLNumber(ExtensionType): - oid = ExtensionOID.CRL_NUMBER - - def __init__(self, crl_number: int) -> None: - if not isinstance(crl_number, int): - raise TypeError("crl_number must be an integer") - - self._crl_number = crl_number - - def __eq__(self, other: object) -> bool: - if not isinstance(other, CRLNumber): - return NotImplemented - - return self.crl_number == other.crl_number - - def __hash__(self) -> int: - return hash(self.crl_number) - - def __repr__(self) -> str: - return f"" - - @property - def crl_number(self) -> int: - return self._crl_number - - def public_bytes(self) -> bytes: - return rust_x509.encode_extension_value(self) - - -class AuthorityKeyIdentifier(ExtensionType): - oid = ExtensionOID.AUTHORITY_KEY_IDENTIFIER - - def __init__( - self, - key_identifier: bytes | None, - authority_cert_issuer: Iterable[GeneralName] | None, - authority_cert_serial_number: int | None, - ) -> None: - if (authority_cert_issuer is None) != ( - authority_cert_serial_number is None - ): - raise ValueError( - "authority_cert_issuer and authority_cert_serial_number " - "must both be present or both None" - ) - - if authority_cert_issuer is not None: - authority_cert_issuer = list(authority_cert_issuer) - if not all( - isinstance(x, GeneralName) for x in authority_cert_issuer - ): - raise TypeError( - "authority_cert_issuer must be a list of GeneralName " - "objects" - ) - - if authority_cert_serial_number is not None and not isinstance( - authority_cert_serial_number, int - ): - raise TypeError("authority_cert_serial_number must be an integer") - - self._key_identifier = key_identifier - self._authority_cert_issuer = authority_cert_issuer - self._authority_cert_serial_number = authority_cert_serial_number - - # This takes a subset of CertificatePublicKeyTypes because an issuer - # cannot have an X25519/X448 key. This introduces some unfortunate - # asymmetry that requires typing users to explicitly - # narrow their type, but we should make this accurate and not just - # convenient. - @classmethod - def from_issuer_public_key( - cls, public_key: CertificateIssuerPublicKeyTypes - ) -> AuthorityKeyIdentifier: - digest = _key_identifier_from_public_key(public_key) - return cls( - key_identifier=digest, - authority_cert_issuer=None, - authority_cert_serial_number=None, - ) - - @classmethod - def from_issuer_subject_key_identifier( - cls, ski: SubjectKeyIdentifier - ) -> AuthorityKeyIdentifier: - return cls( - key_identifier=ski.digest, - authority_cert_issuer=None, - authority_cert_serial_number=None, - ) - - def __repr__(self) -> str: - return ( - f"" - ) - - def __eq__(self, other: object) -> bool: - if not isinstance(other, AuthorityKeyIdentifier): - return NotImplemented - - return ( - self.key_identifier == other.key_identifier - and self.authority_cert_issuer == other.authority_cert_issuer - and self.authority_cert_serial_number - == other.authority_cert_serial_number - ) - - def __hash__(self) -> int: - if self.authority_cert_issuer is None: - aci = None - else: - aci = tuple(self.authority_cert_issuer) - return hash( - (self.key_identifier, aci, self.authority_cert_serial_number) - ) - - @property - def key_identifier(self) -> bytes | None: - return self._key_identifier - - @property - def authority_cert_issuer( - self, - ) -> list[GeneralName] | None: - return self._authority_cert_issuer - - @property - def authority_cert_serial_number(self) -> int | None: - return self._authority_cert_serial_number - - def public_bytes(self) -> bytes: - return rust_x509.encode_extension_value(self) - - -class SubjectKeyIdentifier(ExtensionType): - oid = ExtensionOID.SUBJECT_KEY_IDENTIFIER - - def __init__(self, digest: bytes) -> None: - self._digest = digest - - @classmethod - def from_public_key( - cls, public_key: CertificatePublicKeyTypes - ) -> SubjectKeyIdentifier: - return cls(_key_identifier_from_public_key(public_key)) - - @property - def digest(self) -> bytes: - return self._digest - - @property - def key_identifier(self) -> bytes: - return self._digest - - def __repr__(self) -> str: - return f"" - - def __eq__(self, other: object) -> bool: - if not isinstance(other, SubjectKeyIdentifier): - return NotImplemented - - return constant_time.bytes_eq(self.digest, other.digest) - - def __hash__(self) -> int: - return hash(self.digest) - - def public_bytes(self) -> bytes: - return rust_x509.encode_extension_value(self) - - -class AuthorityInformationAccess(ExtensionType): - oid = ExtensionOID.AUTHORITY_INFORMATION_ACCESS - - def __init__(self, descriptions: Iterable[AccessDescription]) -> None: - descriptions = list(descriptions) - if not all(isinstance(x, AccessDescription) for x in descriptions): - raise TypeError( - "Every item in the descriptions list must be an " - "AccessDescription" - ) - - self._descriptions = descriptions - - __len__, __iter__, __getitem__ = _make_sequence_methods("_descriptions") - - def __repr__(self) -> str: - return f"" - - def __eq__(self, other: object) -> bool: - if not isinstance(other, AuthorityInformationAccess): - return NotImplemented - - return self._descriptions == other._descriptions - - def __hash__(self) -> int: - return hash(tuple(self._descriptions)) - - def public_bytes(self) -> bytes: - return rust_x509.encode_extension_value(self) - - -class SubjectInformationAccess(ExtensionType): - oid = ExtensionOID.SUBJECT_INFORMATION_ACCESS - - def __init__(self, descriptions: Iterable[AccessDescription]) -> None: - descriptions = list(descriptions) - if not all(isinstance(x, AccessDescription) for x in descriptions): - raise TypeError( - "Every item in the descriptions list must be an " - "AccessDescription" - ) - - self._descriptions = descriptions - - __len__, __iter__, __getitem__ = _make_sequence_methods("_descriptions") - - def __repr__(self) -> str: - return f"" - - def __eq__(self, other: object) -> bool: - if not isinstance(other, SubjectInformationAccess): - return NotImplemented - - return self._descriptions == other._descriptions - - def __hash__(self) -> int: - return hash(tuple(self._descriptions)) - - def public_bytes(self) -> bytes: - return rust_x509.encode_extension_value(self) - - -class AccessDescription: - def __init__( - self, access_method: ObjectIdentifier, access_location: GeneralName - ) -> None: - if not isinstance(access_method, ObjectIdentifier): - raise TypeError("access_method must be an ObjectIdentifier") - - if not isinstance(access_location, GeneralName): - raise TypeError("access_location must be a GeneralName") - - self._access_method = access_method - self._access_location = access_location - - def __repr__(self) -> str: - return ( - f"" - ) - - def __eq__(self, other: object) -> bool: - if not isinstance(other, AccessDescription): - return NotImplemented - - return ( - self.access_method == other.access_method - and self.access_location == other.access_location - ) - - def __hash__(self) -> int: - return hash((self.access_method, self.access_location)) - - @property - def access_method(self) -> ObjectIdentifier: - return self._access_method - - @property - def access_location(self) -> GeneralName: - return self._access_location - - -class BasicConstraints(ExtensionType): - oid = ExtensionOID.BASIC_CONSTRAINTS - - def __init__(self, ca: bool, path_length: int | None) -> None: - if not isinstance(ca, bool): - raise TypeError("ca must be a boolean value") - - if path_length is not None and not ca: - raise ValueError("path_length must be None when ca is False") - - if path_length is not None and ( - not isinstance(path_length, int) or path_length < 0 - ): - raise TypeError( - "path_length must be a non-negative integer or None" - ) - - self._ca = ca - self._path_length = path_length - - @property - def ca(self) -> bool: - return self._ca - - @property - def path_length(self) -> int | None: - return self._path_length - - def __repr__(self) -> str: - return ( - f"" - ) - - def __eq__(self, other: object) -> bool: - if not isinstance(other, BasicConstraints): - return NotImplemented - - return self.ca == other.ca and self.path_length == other.path_length - - def __hash__(self) -> int: - return hash((self.ca, self.path_length)) - - def public_bytes(self) -> bytes: - return rust_x509.encode_extension_value(self) - - -class DeltaCRLIndicator(ExtensionType): - oid = ExtensionOID.DELTA_CRL_INDICATOR - - def __init__(self, crl_number: int) -> None: - if not isinstance(crl_number, int): - raise TypeError("crl_number must be an integer") - - self._crl_number = crl_number - - @property - def crl_number(self) -> int: - return self._crl_number - - def __eq__(self, other: object) -> bool: - if not isinstance(other, DeltaCRLIndicator): - return NotImplemented - - return self.crl_number == other.crl_number - - def __hash__(self) -> int: - return hash(self.crl_number) - - def __repr__(self) -> str: - return f"" - - def public_bytes(self) -> bytes: - return rust_x509.encode_extension_value(self) - - -class CRLDistributionPoints(ExtensionType): - oid = ExtensionOID.CRL_DISTRIBUTION_POINTS - - def __init__( - self, distribution_points: Iterable[DistributionPoint] - ) -> None: - distribution_points = list(distribution_points) - if not all( - isinstance(x, DistributionPoint) for x in distribution_points - ): - raise TypeError( - "distribution_points must be a list of DistributionPoint " - "objects" - ) - - self._distribution_points = distribution_points - - __len__, __iter__, __getitem__ = _make_sequence_methods( - "_distribution_points" - ) - - def __repr__(self) -> str: - return f"" - - def __eq__(self, other: object) -> bool: - if not isinstance(other, CRLDistributionPoints): - return NotImplemented - - return self._distribution_points == other._distribution_points - - def __hash__(self) -> int: - return hash(tuple(self._distribution_points)) - - def public_bytes(self) -> bytes: - return rust_x509.encode_extension_value(self) - - -class FreshestCRL(ExtensionType): - oid = ExtensionOID.FRESHEST_CRL - - def __init__( - self, distribution_points: Iterable[DistributionPoint] - ) -> None: - distribution_points = list(distribution_points) - if not all( - isinstance(x, DistributionPoint) for x in distribution_points - ): - raise TypeError( - "distribution_points must be a list of DistributionPoint " - "objects" - ) - - self._distribution_points = distribution_points - - __len__, __iter__, __getitem__ = _make_sequence_methods( - "_distribution_points" - ) - - def __repr__(self) -> str: - return f"" - - def __eq__(self, other: object) -> bool: - if not isinstance(other, FreshestCRL): - return NotImplemented - - return self._distribution_points == other._distribution_points - - def __hash__(self) -> int: - return hash(tuple(self._distribution_points)) - - def public_bytes(self) -> bytes: - return rust_x509.encode_extension_value(self) - - -class DistributionPoint: - def __init__( - self, - full_name: Iterable[GeneralName] | None, - relative_name: RelativeDistinguishedName | None, - reasons: frozenset[ReasonFlags] | None, - crl_issuer: Iterable[GeneralName] | None, - ) -> None: - if full_name and relative_name: - raise ValueError( - "You cannot provide both full_name and relative_name, at " - "least one must be None." - ) - if not full_name and not relative_name and not crl_issuer: - raise ValueError( - "Either full_name, relative_name or crl_issuer must be " - "provided." - ) - - if full_name is not None: - full_name = list(full_name) - if not all(isinstance(x, GeneralName) for x in full_name): - raise TypeError( - "full_name must be a list of GeneralName objects" - ) - - if relative_name: - if not isinstance(relative_name, RelativeDistinguishedName): - raise TypeError( - "relative_name must be a RelativeDistinguishedName" - ) - - if crl_issuer is not None: - crl_issuer = list(crl_issuer) - if not all(isinstance(x, GeneralName) for x in crl_issuer): - raise TypeError( - "crl_issuer must be None or a list of general names" - ) - - if reasons and ( - not isinstance(reasons, frozenset) - or not all(isinstance(x, ReasonFlags) for x in reasons) - ): - raise TypeError("reasons must be None or frozenset of ReasonFlags") - - if reasons and ( - ReasonFlags.unspecified in reasons - or ReasonFlags.remove_from_crl in reasons - ): - raise ValueError( - "unspecified and remove_from_crl are not valid reasons in a " - "DistributionPoint" - ) - - self._full_name = full_name - self._relative_name = relative_name - self._reasons = reasons - self._crl_issuer = crl_issuer - - def __repr__(self) -> str: - return ( - "".format(self) - ) - - def __eq__(self, other: object) -> bool: - if not isinstance(other, DistributionPoint): - return NotImplemented - - return ( - self.full_name == other.full_name - and self.relative_name == other.relative_name - and self.reasons == other.reasons - and self.crl_issuer == other.crl_issuer - ) - - def __hash__(self) -> int: - if self.full_name is not None: - fn: tuple[GeneralName, ...] | None = tuple(self.full_name) - else: - fn = None - - if self.crl_issuer is not None: - crl_issuer: tuple[GeneralName, ...] | None = tuple(self.crl_issuer) - else: - crl_issuer = None - - return hash((fn, self.relative_name, self.reasons, crl_issuer)) - - @property - def full_name(self) -> list[GeneralName] | None: - return self._full_name - - @property - def relative_name(self) -> RelativeDistinguishedName | None: - return self._relative_name - - @property - def reasons(self) -> frozenset[ReasonFlags] | None: - return self._reasons - - @property - def crl_issuer(self) -> list[GeneralName] | None: - return self._crl_issuer - - -class ReasonFlags(utils.Enum): - unspecified = "unspecified" - key_compromise = "keyCompromise" - ca_compromise = "cACompromise" - affiliation_changed = "affiliationChanged" - superseded = "superseded" - cessation_of_operation = "cessationOfOperation" - certificate_hold = "certificateHold" - privilege_withdrawn = "privilegeWithdrawn" - aa_compromise = "aACompromise" - remove_from_crl = "removeFromCRL" - - -# These are distribution point bit string mappings. Not to be confused with -# CRLReason reason flags bit string mappings. -# ReasonFlags ::= BIT STRING { -# unused (0), -# keyCompromise (1), -# cACompromise (2), -# affiliationChanged (3), -# superseded (4), -# cessationOfOperation (5), -# certificateHold (6), -# privilegeWithdrawn (7), -# aACompromise (8) } -_REASON_BIT_MAPPING = { - 1: ReasonFlags.key_compromise, - 2: ReasonFlags.ca_compromise, - 3: ReasonFlags.affiliation_changed, - 4: ReasonFlags.superseded, - 5: ReasonFlags.cessation_of_operation, - 6: ReasonFlags.certificate_hold, - 7: ReasonFlags.privilege_withdrawn, - 8: ReasonFlags.aa_compromise, -} - -_CRLREASONFLAGS = { - ReasonFlags.key_compromise: 1, - ReasonFlags.ca_compromise: 2, - ReasonFlags.affiliation_changed: 3, - ReasonFlags.superseded: 4, - ReasonFlags.cessation_of_operation: 5, - ReasonFlags.certificate_hold: 6, - ReasonFlags.privilege_withdrawn: 7, - ReasonFlags.aa_compromise: 8, -} - -# CRLReason ::= ENUMERATED { -# unspecified (0), -# keyCompromise (1), -# cACompromise (2), -# affiliationChanged (3), -# superseded (4), -# cessationOfOperation (5), -# certificateHold (6), -# -- value 7 is not used -# removeFromCRL (8), -# privilegeWithdrawn (9), -# aACompromise (10) } -_CRL_ENTRY_REASON_ENUM_TO_CODE = { - ReasonFlags.unspecified: 0, - ReasonFlags.key_compromise: 1, - ReasonFlags.ca_compromise: 2, - ReasonFlags.affiliation_changed: 3, - ReasonFlags.superseded: 4, - ReasonFlags.cessation_of_operation: 5, - ReasonFlags.certificate_hold: 6, - ReasonFlags.remove_from_crl: 8, - ReasonFlags.privilege_withdrawn: 9, - ReasonFlags.aa_compromise: 10, -} - - -class PolicyConstraints(ExtensionType): - oid = ExtensionOID.POLICY_CONSTRAINTS - - def __init__( - self, - require_explicit_policy: int | None, - inhibit_policy_mapping: int | None, - ) -> None: - if require_explicit_policy is not None and not isinstance( - require_explicit_policy, int - ): - raise TypeError( - "require_explicit_policy must be a non-negative integer or " - "None" - ) - - if inhibit_policy_mapping is not None and not isinstance( - inhibit_policy_mapping, int - ): - raise TypeError( - "inhibit_policy_mapping must be a non-negative integer or None" - ) - - if inhibit_policy_mapping is None and require_explicit_policy is None: - raise ValueError( - "At least one of require_explicit_policy and " - "inhibit_policy_mapping must not be None" - ) - - self._require_explicit_policy = require_explicit_policy - self._inhibit_policy_mapping = inhibit_policy_mapping - - def __repr__(self) -> str: - return ( - "".format(self) - ) - - def __eq__(self, other: object) -> bool: - if not isinstance(other, PolicyConstraints): - return NotImplemented - - return ( - self.require_explicit_policy == other.require_explicit_policy - and self.inhibit_policy_mapping == other.inhibit_policy_mapping - ) - - def __hash__(self) -> int: - return hash( - (self.require_explicit_policy, self.inhibit_policy_mapping) - ) - - @property - def require_explicit_policy(self) -> int | None: - return self._require_explicit_policy - - @property - def inhibit_policy_mapping(self) -> int | None: - return self._inhibit_policy_mapping - - def public_bytes(self) -> bytes: - return rust_x509.encode_extension_value(self) - - -class CertificatePolicies(ExtensionType): - oid = ExtensionOID.CERTIFICATE_POLICIES - - def __init__(self, policies: Iterable[PolicyInformation]) -> None: - policies = list(policies) - if not all(isinstance(x, PolicyInformation) for x in policies): - raise TypeError( - "Every item in the policies list must be a PolicyInformation" - ) - - self._policies = policies - - __len__, __iter__, __getitem__ = _make_sequence_methods("_policies") - - def __repr__(self) -> str: - return f"" - - def __eq__(self, other: object) -> bool: - if not isinstance(other, CertificatePolicies): - return NotImplemented - - return self._policies == other._policies - - def __hash__(self) -> int: - return hash(tuple(self._policies)) - - def public_bytes(self) -> bytes: - return rust_x509.encode_extension_value(self) - - -class PolicyInformation: - def __init__( - self, - policy_identifier: ObjectIdentifier, - policy_qualifiers: Iterable[str | UserNotice] | None, - ) -> None: - if not isinstance(policy_identifier, ObjectIdentifier): - raise TypeError("policy_identifier must be an ObjectIdentifier") - - self._policy_identifier = policy_identifier - - if policy_qualifiers is not None: - policy_qualifiers = list(policy_qualifiers) - if not all( - isinstance(x, (str, UserNotice)) for x in policy_qualifiers - ): - raise TypeError( - "policy_qualifiers must be a list of strings and/or " - "UserNotice objects or None" - ) - - self._policy_qualifiers = policy_qualifiers - - def __repr__(self) -> str: - return ( - f"" - ) - - def __eq__(self, other: object) -> bool: - if not isinstance(other, PolicyInformation): - return NotImplemented - - return ( - self.policy_identifier == other.policy_identifier - and self.policy_qualifiers == other.policy_qualifiers - ) - - def __hash__(self) -> int: - if self.policy_qualifiers is not None: - pq = tuple(self.policy_qualifiers) - else: - pq = None - - return hash((self.policy_identifier, pq)) - - @property - def policy_identifier(self) -> ObjectIdentifier: - return self._policy_identifier - - @property - def policy_qualifiers( - self, - ) -> list[str | UserNotice] | None: - return self._policy_qualifiers - - -class UserNotice: - def __init__( - self, - notice_reference: NoticeReference | None, - explicit_text: str | None, - ) -> None: - if notice_reference and not isinstance( - notice_reference, NoticeReference - ): - raise TypeError( - "notice_reference must be None or a NoticeReference" - ) - - self._notice_reference = notice_reference - self._explicit_text = explicit_text - - def __repr__(self) -> str: - return ( - f"" - ) - - def __eq__(self, other: object) -> bool: - if not isinstance(other, UserNotice): - return NotImplemented - - return ( - self.notice_reference == other.notice_reference - and self.explicit_text == other.explicit_text - ) - - def __hash__(self) -> int: - return hash((self.notice_reference, self.explicit_text)) - - @property - def notice_reference(self) -> NoticeReference | None: - return self._notice_reference - - @property - def explicit_text(self) -> str | None: - return self._explicit_text - - -class NoticeReference: - def __init__( - self, - organization: str | None, - notice_numbers: Iterable[int], - ) -> None: - self._organization = organization - notice_numbers = list(notice_numbers) - if not all(isinstance(x, int) for x in notice_numbers): - raise TypeError("notice_numbers must be a list of integers") - - self._notice_numbers = notice_numbers - - def __repr__(self) -> str: - return ( - f"" - ) - - def __eq__(self, other: object) -> bool: - if not isinstance(other, NoticeReference): - return NotImplemented - - return ( - self.organization == other.organization - and self.notice_numbers == other.notice_numbers - ) - - def __hash__(self) -> int: - return hash((self.organization, tuple(self.notice_numbers))) - - @property - def organization(self) -> str | None: - return self._organization - - @property - def notice_numbers(self) -> list[int]: - return self._notice_numbers - - -class ExtendedKeyUsage(ExtensionType): - oid = ExtensionOID.EXTENDED_KEY_USAGE - - def __init__(self, usages: Iterable[ObjectIdentifier]) -> None: - usages = list(usages) - if not all(isinstance(x, ObjectIdentifier) for x in usages): - raise TypeError( - "Every item in the usages list must be an ObjectIdentifier" - ) - - self._usages = usages - - __len__, __iter__, __getitem__ = _make_sequence_methods("_usages") - - def __repr__(self) -> str: - return f"" - - def __eq__(self, other: object) -> bool: - if not isinstance(other, ExtendedKeyUsage): - return NotImplemented - - return self._usages == other._usages - - def __hash__(self) -> int: - return hash(tuple(self._usages)) - - def public_bytes(self) -> bytes: - return rust_x509.encode_extension_value(self) - - -class OCSPNoCheck(ExtensionType): - oid = ExtensionOID.OCSP_NO_CHECK - - def __eq__(self, other: object) -> bool: - if not isinstance(other, OCSPNoCheck): - return NotImplemented - - return True - - def __hash__(self) -> int: - return hash(OCSPNoCheck) - - def __repr__(self) -> str: - return "" - - def public_bytes(self) -> bytes: - return rust_x509.encode_extension_value(self) - - -class PrecertPoison(ExtensionType): - oid = ExtensionOID.PRECERT_POISON - - def __eq__(self, other: object) -> bool: - if not isinstance(other, PrecertPoison): - return NotImplemented - - return True - - def __hash__(self) -> int: - return hash(PrecertPoison) - - def __repr__(self) -> str: - return "" - - def public_bytes(self) -> bytes: - return rust_x509.encode_extension_value(self) - - -class TLSFeature(ExtensionType): - oid = ExtensionOID.TLS_FEATURE - - def __init__(self, features: Iterable[TLSFeatureType]) -> None: - features = list(features) - if ( - not all(isinstance(x, TLSFeatureType) for x in features) - or len(features) == 0 - ): - raise TypeError( - "features must be a list of elements from the TLSFeatureType " - "enum" - ) - - self._features = features - - __len__, __iter__, __getitem__ = _make_sequence_methods("_features") - - def __repr__(self) -> str: - return f"" - - def __eq__(self, other: object) -> bool: - if not isinstance(other, TLSFeature): - return NotImplemented - - return self._features == other._features - - def __hash__(self) -> int: - return hash(tuple(self._features)) - - def public_bytes(self) -> bytes: - return rust_x509.encode_extension_value(self) - - -class TLSFeatureType(utils.Enum): - # status_request is defined in RFC 6066 and is used for what is commonly - # called OCSP Must-Staple when present in the TLS Feature extension in an - # X.509 certificate. - status_request = 5 - # status_request_v2 is defined in RFC 6961 and allows multiple OCSP - # responses to be provided. It is not currently in use by clients or - # servers. - status_request_v2 = 17 - - -_TLS_FEATURE_TYPE_TO_ENUM = {x.value: x for x in TLSFeatureType} - - -class InhibitAnyPolicy(ExtensionType): - oid = ExtensionOID.INHIBIT_ANY_POLICY - - def __init__(self, skip_certs: int) -> None: - if not isinstance(skip_certs, int): - raise TypeError("skip_certs must be an integer") - - if skip_certs < 0: - raise ValueError("skip_certs must be a non-negative integer") - - self._skip_certs = skip_certs - - def __repr__(self) -> str: - return f"" - - def __eq__(self, other: object) -> bool: - if not isinstance(other, InhibitAnyPolicy): - return NotImplemented - - return self.skip_certs == other.skip_certs - - def __hash__(self) -> int: - return hash(self.skip_certs) - - @property - def skip_certs(self) -> int: - return self._skip_certs - - def public_bytes(self) -> bytes: - return rust_x509.encode_extension_value(self) - - -class KeyUsage(ExtensionType): - oid = ExtensionOID.KEY_USAGE - - def __init__( - self, - digital_signature: bool, - content_commitment: bool, - key_encipherment: bool, - data_encipherment: bool, - key_agreement: bool, - key_cert_sign: bool, - crl_sign: bool, - encipher_only: bool, - decipher_only: bool, - ) -> None: - if not key_agreement and (encipher_only or decipher_only): - raise ValueError( - "encipher_only and decipher_only can only be true when " - "key_agreement is true" - ) - - self._digital_signature = digital_signature - self._content_commitment = content_commitment - self._key_encipherment = key_encipherment - self._data_encipherment = data_encipherment - self._key_agreement = key_agreement - self._key_cert_sign = key_cert_sign - self._crl_sign = crl_sign - self._encipher_only = encipher_only - self._decipher_only = decipher_only - - @property - def digital_signature(self) -> bool: - return self._digital_signature - - @property - def content_commitment(self) -> bool: - return self._content_commitment - - @property - def key_encipherment(self) -> bool: - return self._key_encipherment - - @property - def data_encipherment(self) -> bool: - return self._data_encipherment - - @property - def key_agreement(self) -> bool: - return self._key_agreement - - @property - def key_cert_sign(self) -> bool: - return self._key_cert_sign - - @property - def crl_sign(self) -> bool: - return self._crl_sign - - @property - def encipher_only(self) -> bool: - if not self.key_agreement: - raise ValueError( - "encipher_only is undefined unless key_agreement is true" - ) - else: - return self._encipher_only - - @property - def decipher_only(self) -> bool: - if not self.key_agreement: - raise ValueError( - "decipher_only is undefined unless key_agreement is true" - ) - else: - return self._decipher_only - - def __repr__(self) -> str: - try: - encipher_only = self.encipher_only - decipher_only = self.decipher_only - except ValueError: - # Users found None confusing because even though encipher/decipher - # have no meaning unless key_agreement is true, to construct an - # instance of the class you still need to pass False. - encipher_only = False - decipher_only = False - - return ( - f"" - ) - - def __eq__(self, other: object) -> bool: - if not isinstance(other, KeyUsage): - return NotImplemented - - return ( - self.digital_signature == other.digital_signature - and self.content_commitment == other.content_commitment - and self.key_encipherment == other.key_encipherment - and self.data_encipherment == other.data_encipherment - and self.key_agreement == other.key_agreement - and self.key_cert_sign == other.key_cert_sign - and self.crl_sign == other.crl_sign - and self._encipher_only == other._encipher_only - and self._decipher_only == other._decipher_only - ) - - def __hash__(self) -> int: - return hash( - ( - self.digital_signature, - self.content_commitment, - self.key_encipherment, - self.data_encipherment, - self.key_agreement, - self.key_cert_sign, - self.crl_sign, - self._encipher_only, - self._decipher_only, - ) - ) - - def public_bytes(self) -> bytes: - return rust_x509.encode_extension_value(self) - - -class PrivateKeyUsagePeriod(ExtensionType): - oid = ExtensionOID.PRIVATE_KEY_USAGE_PERIOD - - def __init__( - self, - not_before: datetime.datetime | None, - not_after: datetime.datetime | None, - ) -> None: - if ( - not isinstance(not_before, datetime.datetime) - and not_before is not None - ): - raise TypeError("not_before must be a datetime.datetime or None") - - if ( - not isinstance(not_after, datetime.datetime) - and not_after is not None - ): - raise TypeError("not_after must be a datetime.datetime or None") - - if not_before is None and not_after is None: - raise ValueError( - "At least one of not_before and not_after must not be None" - ) - - if ( - not_before is not None - and not_after is not None - and not_before > not_after - ): - raise ValueError("not_before must be before not_after") - - self._not_before = not_before - self._not_after = not_after - - @property - def not_before(self) -> datetime.datetime | None: - return self._not_before - - @property - def not_after(self) -> datetime.datetime | None: - return self._not_after - - def __repr__(self) -> str: - return ( - f"" - ) - - def __eq__(self, other: object) -> bool: - if not isinstance(other, PrivateKeyUsagePeriod): - return NotImplemented - - return ( - self.not_before == other.not_before - and self.not_after == other.not_after - ) - - def __hash__(self) -> int: - return hash((self.not_before, self.not_after)) - - def public_bytes(self) -> bytes: - return rust_x509.encode_extension_value(self) - - -class NameConstraints(ExtensionType): - oid = ExtensionOID.NAME_CONSTRAINTS - - def __init__( - self, - permitted_subtrees: Iterable[GeneralName] | None, - excluded_subtrees: Iterable[GeneralName] | None, - ) -> None: - if permitted_subtrees is not None: - permitted_subtrees = list(permitted_subtrees) - if not permitted_subtrees: - raise ValueError( - "permitted_subtrees must be a non-empty list or None" - ) - if not all(isinstance(x, GeneralName) for x in permitted_subtrees): - raise TypeError( - "permitted_subtrees must be a list of GeneralName objects " - "or None" - ) - - self._validate_tree(permitted_subtrees) - - if excluded_subtrees is not None: - excluded_subtrees = list(excluded_subtrees) - if not excluded_subtrees: - raise ValueError( - "excluded_subtrees must be a non-empty list or None" - ) - if not all(isinstance(x, GeneralName) for x in excluded_subtrees): - raise TypeError( - "excluded_subtrees must be a list of GeneralName objects " - "or None" - ) - - self._validate_tree(excluded_subtrees) - - if permitted_subtrees is None and excluded_subtrees is None: - raise ValueError( - "At least one of permitted_subtrees and excluded_subtrees " - "must not be None" - ) - - self._permitted_subtrees = permitted_subtrees - self._excluded_subtrees = excluded_subtrees - - def __eq__(self, other: object) -> bool: - if not isinstance(other, NameConstraints): - return NotImplemented - - return ( - self.excluded_subtrees == other.excluded_subtrees - and self.permitted_subtrees == other.permitted_subtrees - ) - - def _validate_tree(self, tree: Iterable[GeneralName]) -> None: - self._validate_ip_name(tree) - self._validate_dns_name(tree) - - def _validate_ip_name(self, tree: Iterable[GeneralName]) -> None: - if any( - isinstance(name, IPAddress) - and not isinstance( - name.value, (ipaddress.IPv4Network, ipaddress.IPv6Network) - ) - for name in tree - ): - raise TypeError( - "IPAddress name constraints must be an IPv4Network or" - " IPv6Network object" - ) - - def _validate_dns_name(self, tree: Iterable[GeneralName]) -> None: - if any( - isinstance(name, DNSName) and "*" in name.value for name in tree - ): - raise ValueError( - "DNSName name constraints must not contain the '*' wildcard" - " character" - ) - - def __repr__(self) -> str: - return ( - f"" - ) - - def __hash__(self) -> int: - if self.permitted_subtrees is not None: - ps: tuple[GeneralName, ...] | None = tuple(self.permitted_subtrees) - else: - ps = None - - if self.excluded_subtrees is not None: - es: tuple[GeneralName, ...] | None = tuple(self.excluded_subtrees) - else: - es = None - - return hash((ps, es)) - - @property - def permitted_subtrees( - self, - ) -> list[GeneralName] | None: - return self._permitted_subtrees - - @property - def excluded_subtrees( - self, - ) -> list[GeneralName] | None: - return self._excluded_subtrees - - def public_bytes(self) -> bytes: - return rust_x509.encode_extension_value(self) - - -class Extension(typing.Generic[ExtensionTypeVar]): - def __init__( - self, oid: ObjectIdentifier, critical: bool, value: ExtensionTypeVar - ) -> None: - if not isinstance(oid, ObjectIdentifier): - raise TypeError( - "oid argument must be an ObjectIdentifier instance." - ) - - if not isinstance(critical, bool): - raise TypeError("critical must be a boolean value") - - self._oid = oid - self._critical = critical - self._value = value - - @property - def oid(self) -> ObjectIdentifier: - return self._oid - - @property - def critical(self) -> bool: - return self._critical - - @property - def value(self) -> ExtensionTypeVar: - return self._value - - def __repr__(self) -> str: - return ( - f"" - ) - - def __eq__(self, other: object) -> bool: - if not isinstance(other, Extension): - return NotImplemented - - return ( - self.oid == other.oid - and self.critical == other.critical - and self.value == other.value - ) - - def __hash__(self) -> int: - return hash((self.oid, self.critical, self.value)) - - -class GeneralNames: - def __init__(self, general_names: Iterable[GeneralName]) -> None: - general_names = list(general_names) - if not all(isinstance(x, GeneralName) for x in general_names): - raise TypeError( - "Every item in the general_names list must be an " - "object conforming to the GeneralName interface" - ) - - self._general_names = general_names - - __len__, __iter__, __getitem__ = _make_sequence_methods("_general_names") - - @typing.overload - def get_values_for_type( - self, - type: type[DNSName] - | type[UniformResourceIdentifier] - | type[RFC822Name], - ) -> list[str]: ... - - @typing.overload - def get_values_for_type( - self, - type: type[DirectoryName], - ) -> list[Name]: ... - - @typing.overload - def get_values_for_type( - self, - type: type[RegisteredID], - ) -> list[ObjectIdentifier]: ... - - @typing.overload - def get_values_for_type( - self, type: type[IPAddress] - ) -> list[_IPAddressTypes]: ... - - @typing.overload - def get_values_for_type( - self, type: type[OtherName] - ) -> list[OtherName]: ... - - def get_values_for_type( - self, - type: type[DNSName] - | type[DirectoryName] - | type[IPAddress] - | type[OtherName] - | type[RFC822Name] - | type[RegisteredID] - | type[UniformResourceIdentifier], - ) -> ( - list[_IPAddressTypes] - | list[str] - | list[OtherName] - | list[Name] - | list[ObjectIdentifier] - ): - # Return the value of each GeneralName, except for OtherName instances - # which we return directly because it has two important properties not - # just one value. - objs = (i for i in self if isinstance(i, type)) - if type != OtherName: - return [i.value for i in objs] # type: ignore[return-value,unused-ignore] - return list(objs) # type: ignore[return-value,unused-ignore] - - def __repr__(self) -> str: - return f"" - - def __eq__(self, other: object) -> bool: - if not isinstance(other, GeneralNames): - return NotImplemented - - return self._general_names == other._general_names - - def __hash__(self) -> int: - return hash(tuple(self._general_names)) - - -class SubjectAlternativeName(ExtensionType): - oid = ExtensionOID.SUBJECT_ALTERNATIVE_NAME - - def __init__(self, general_names: Iterable[GeneralName]) -> None: - self._general_names = GeneralNames(general_names) - - __len__, __iter__, __getitem__ = _make_sequence_methods("_general_names") - - @typing.overload - def get_values_for_type( - self, - type: type[DNSName] - | type[UniformResourceIdentifier] - | type[RFC822Name], - ) -> list[str]: ... - - @typing.overload - def get_values_for_type( - self, - type: type[DirectoryName], - ) -> list[Name]: ... - - @typing.overload - def get_values_for_type( - self, - type: type[RegisteredID], - ) -> list[ObjectIdentifier]: ... - - @typing.overload - def get_values_for_type( - self, type: type[IPAddress] - ) -> list[_IPAddressTypes]: ... - - @typing.overload - def get_values_for_type( - self, type: type[OtherName] - ) -> list[OtherName]: ... - - def get_values_for_type( - self, - type: type[DNSName] - | type[DirectoryName] - | type[IPAddress] - | type[OtherName] - | type[RFC822Name] - | type[RegisteredID] - | type[UniformResourceIdentifier], - ) -> ( - list[_IPAddressTypes] - | list[str] - | list[OtherName] - | list[Name] - | list[ObjectIdentifier] - ): - return self._general_names.get_values_for_type(type) - - def __repr__(self) -> str: - return f"" - - def __eq__(self, other: object) -> bool: - if not isinstance(other, SubjectAlternativeName): - return NotImplemented - - return self._general_names == other._general_names - - def __hash__(self) -> int: - return hash(self._general_names) - - def public_bytes(self) -> bytes: - return rust_x509.encode_extension_value(self) - - -class IssuerAlternativeName(ExtensionType): - oid = ExtensionOID.ISSUER_ALTERNATIVE_NAME - - def __init__(self, general_names: Iterable[GeneralName]) -> None: - self._general_names = GeneralNames(general_names) - - __len__, __iter__, __getitem__ = _make_sequence_methods("_general_names") - - @typing.overload - def get_values_for_type( - self, - type: type[DNSName] - | type[UniformResourceIdentifier] - | type[RFC822Name], - ) -> list[str]: ... - - @typing.overload - def get_values_for_type( - self, - type: type[DirectoryName], - ) -> list[Name]: ... - - @typing.overload - def get_values_for_type( - self, - type: type[RegisteredID], - ) -> list[ObjectIdentifier]: ... - - @typing.overload - def get_values_for_type( - self, type: type[IPAddress] - ) -> list[_IPAddressTypes]: ... - - @typing.overload - def get_values_for_type( - self, type: type[OtherName] - ) -> list[OtherName]: ... - - def get_values_for_type( - self, - type: type[DNSName] - | type[DirectoryName] - | type[IPAddress] - | type[OtherName] - | type[RFC822Name] - | type[RegisteredID] - | type[UniformResourceIdentifier], - ) -> ( - list[_IPAddressTypes] - | list[str] - | list[OtherName] - | list[Name] - | list[ObjectIdentifier] - ): - return self._general_names.get_values_for_type(type) - - def __repr__(self) -> str: - return f"" - - def __eq__(self, other: object) -> bool: - if not isinstance(other, IssuerAlternativeName): - return NotImplemented - - return self._general_names == other._general_names - - def __hash__(self) -> int: - return hash(self._general_names) - - def public_bytes(self) -> bytes: - return rust_x509.encode_extension_value(self) - - -class CertificateIssuer(ExtensionType): - oid = CRLEntryExtensionOID.CERTIFICATE_ISSUER - - def __init__(self, general_names: Iterable[GeneralName]) -> None: - self._general_names = GeneralNames(general_names) - - __len__, __iter__, __getitem__ = _make_sequence_methods("_general_names") - - @typing.overload - def get_values_for_type( - self, - type: type[DNSName] - | type[UniformResourceIdentifier] - | type[RFC822Name], - ) -> list[str]: ... - - @typing.overload - def get_values_for_type( - self, - type: type[DirectoryName], - ) -> list[Name]: ... - - @typing.overload - def get_values_for_type( - self, - type: type[RegisteredID], - ) -> list[ObjectIdentifier]: ... - - @typing.overload - def get_values_for_type( - self, type: type[IPAddress] - ) -> list[_IPAddressTypes]: ... - - @typing.overload - def get_values_for_type( - self, type: type[OtherName] - ) -> list[OtherName]: ... - - def get_values_for_type( - self, - type: type[DNSName] - | type[DirectoryName] - | type[IPAddress] - | type[OtherName] - | type[RFC822Name] - | type[RegisteredID] - | type[UniformResourceIdentifier], - ) -> ( - list[_IPAddressTypes] - | list[str] - | list[OtherName] - | list[Name] - | list[ObjectIdentifier] - ): - return self._general_names.get_values_for_type(type) - - def __repr__(self) -> str: - return f"" - - def __eq__(self, other: object) -> bool: - if not isinstance(other, CertificateIssuer): - return NotImplemented - - return self._general_names == other._general_names - - def __hash__(self) -> int: - return hash(self._general_names) - - def public_bytes(self) -> bytes: - return rust_x509.encode_extension_value(self) - - -class CRLReason(ExtensionType): - oid = CRLEntryExtensionOID.CRL_REASON - - def __init__(self, reason: ReasonFlags) -> None: - if not isinstance(reason, ReasonFlags): - raise TypeError("reason must be an element from ReasonFlags") - - self._reason = reason - - def __repr__(self) -> str: - return f"" - - def __eq__(self, other: object) -> bool: - if not isinstance(other, CRLReason): - return NotImplemented - - return self.reason == other.reason - - def __hash__(self) -> int: - return hash(self.reason) - - @property - def reason(self) -> ReasonFlags: - return self._reason - - def public_bytes(self) -> bytes: - return rust_x509.encode_extension_value(self) - - -class InvalidityDate(ExtensionType): - oid = CRLEntryExtensionOID.INVALIDITY_DATE - - def __init__(self, invalidity_date: datetime.datetime) -> None: - if not isinstance(invalidity_date, datetime.datetime): - raise TypeError("invalidity_date must be a datetime.datetime") - - self._invalidity_date = invalidity_date - - def __repr__(self) -> str: - return f"" - - def __eq__(self, other: object) -> bool: - if not isinstance(other, InvalidityDate): - return NotImplemented - - return self.invalidity_date == other.invalidity_date - - def __hash__(self) -> int: - return hash(self.invalidity_date) - - @property - def invalidity_date(self) -> datetime.datetime: - return self._invalidity_date - - @property - def invalidity_date_utc(self) -> datetime.datetime: - if self._invalidity_date.tzinfo is None: - return self._invalidity_date.replace(tzinfo=datetime.timezone.utc) - else: - return self._invalidity_date.astimezone(tz=datetime.timezone.utc) - - def public_bytes(self) -> bytes: - return rust_x509.encode_extension_value(self) - - -class PrecertificateSignedCertificateTimestamps(ExtensionType): - oid = ExtensionOID.PRECERT_SIGNED_CERTIFICATE_TIMESTAMPS - - def __init__( - self, - signed_certificate_timestamps: Iterable[SignedCertificateTimestamp], - ) -> None: - signed_certificate_timestamps = list(signed_certificate_timestamps) - if not all( - isinstance(sct, SignedCertificateTimestamp) - for sct in signed_certificate_timestamps - ): - raise TypeError( - "Every item in the signed_certificate_timestamps list must be " - "a SignedCertificateTimestamp" - ) - self._signed_certificate_timestamps = signed_certificate_timestamps - - __len__, __iter__, __getitem__ = _make_sequence_methods( - "_signed_certificate_timestamps" - ) - - def __repr__(self) -> str: - return f"" - - def __hash__(self) -> int: - return hash(tuple(self._signed_certificate_timestamps)) - - def __eq__(self, other: object) -> bool: - if not isinstance(other, PrecertificateSignedCertificateTimestamps): - return NotImplemented - - return ( - self._signed_certificate_timestamps - == other._signed_certificate_timestamps - ) - - def public_bytes(self) -> bytes: - return rust_x509.encode_extension_value(self) - - -class SignedCertificateTimestamps(ExtensionType): - oid = ExtensionOID.SIGNED_CERTIFICATE_TIMESTAMPS - - def __init__( - self, - signed_certificate_timestamps: Iterable[SignedCertificateTimestamp], - ) -> None: - signed_certificate_timestamps = list(signed_certificate_timestamps) - if not all( - isinstance(sct, SignedCertificateTimestamp) - for sct in signed_certificate_timestamps - ): - raise TypeError( - "Every item in the signed_certificate_timestamps list must be " - "a SignedCertificateTimestamp" - ) - self._signed_certificate_timestamps = signed_certificate_timestamps - - __len__, __iter__, __getitem__ = _make_sequence_methods( - "_signed_certificate_timestamps" - ) - - def __repr__(self) -> str: - return f"" - - def __hash__(self) -> int: - return hash(tuple(self._signed_certificate_timestamps)) - - def __eq__(self, other: object) -> bool: - if not isinstance(other, SignedCertificateTimestamps): - return NotImplemented - - return ( - self._signed_certificate_timestamps - == other._signed_certificate_timestamps - ) - - def public_bytes(self) -> bytes: - return rust_x509.encode_extension_value(self) - - -class OCSPNonce(ExtensionType): - oid = OCSPExtensionOID.NONCE - - def __init__(self, nonce: bytes) -> None: - if not isinstance(nonce, bytes): - raise TypeError("nonce must be bytes") - - self._nonce = nonce - - def __eq__(self, other: object) -> bool: - if not isinstance(other, OCSPNonce): - return NotImplemented - - return self.nonce == other.nonce - - def __hash__(self) -> int: - return hash(self.nonce) - - def __repr__(self) -> str: - return f"" - - @property - def nonce(self) -> bytes: - return self._nonce - - def public_bytes(self) -> bytes: - return rust_x509.encode_extension_value(self) - - -class OCSPAcceptableResponses(ExtensionType): - oid = OCSPExtensionOID.ACCEPTABLE_RESPONSES - - def __init__(self, responses: Iterable[ObjectIdentifier]) -> None: - responses = list(responses) - if any(not isinstance(r, ObjectIdentifier) for r in responses): - raise TypeError("All responses must be ObjectIdentifiers") - - self._responses = responses - - def __eq__(self, other: object) -> bool: - if not isinstance(other, OCSPAcceptableResponses): - return NotImplemented - - return self._responses == other._responses - - def __hash__(self) -> int: - return hash(tuple(self._responses)) - - def __repr__(self) -> str: - return f"" - - def __iter__(self) -> Iterator[ObjectIdentifier]: - return iter(self._responses) - - def public_bytes(self) -> bytes: - return rust_x509.encode_extension_value(self) - - -class IssuingDistributionPoint(ExtensionType): - oid = ExtensionOID.ISSUING_DISTRIBUTION_POINT - - def __init__( - self, - full_name: Iterable[GeneralName] | None, - relative_name: RelativeDistinguishedName | None, - only_contains_user_certs: bool, - only_contains_ca_certs: bool, - only_some_reasons: frozenset[ReasonFlags] | None, - indirect_crl: bool, - only_contains_attribute_certs: bool, - ) -> None: - if full_name is not None: - full_name = list(full_name) - - if only_some_reasons and ( - not isinstance(only_some_reasons, frozenset) - or not all(isinstance(x, ReasonFlags) for x in only_some_reasons) - ): - raise TypeError( - "only_some_reasons must be None or frozenset of ReasonFlags" - ) - - if only_some_reasons and ( - ReasonFlags.unspecified in only_some_reasons - or ReasonFlags.remove_from_crl in only_some_reasons - ): - raise ValueError( - "unspecified and remove_from_crl are not valid reasons in an " - "IssuingDistributionPoint" - ) - - if not ( - isinstance(only_contains_user_certs, bool) - and isinstance(only_contains_ca_certs, bool) - and isinstance(indirect_crl, bool) - and isinstance(only_contains_attribute_certs, bool) - ): - raise TypeError( - "only_contains_user_certs, only_contains_ca_certs, " - "indirect_crl and only_contains_attribute_certs " - "must all be boolean." - ) - - # Per RFC5280 Section 5.2.5, the Issuing Distribution Point extension - # in a CRL can have only one of onlyContainsUserCerts, - # onlyContainsCACerts, onlyContainsAttributeCerts set to TRUE. - crl_constraints = [ - only_contains_user_certs, - only_contains_ca_certs, - only_contains_attribute_certs, - ] - - if len([x for x in crl_constraints if x]) > 1: - raise ValueError( - "Only one of the following can be set to True: " - "only_contains_user_certs, only_contains_ca_certs, " - "only_contains_attribute_certs" - ) - - if not any( - [ - only_contains_user_certs, - only_contains_ca_certs, - indirect_crl, - only_contains_attribute_certs, - full_name, - relative_name, - only_some_reasons, - ] - ): - raise ValueError( - "Cannot create empty extension: " - "if only_contains_user_certs, only_contains_ca_certs, " - "indirect_crl, and only_contains_attribute_certs are all False" - ", then either full_name, relative_name, or only_some_reasons " - "must have a value." - ) - - self._only_contains_user_certs = only_contains_user_certs - self._only_contains_ca_certs = only_contains_ca_certs - self._indirect_crl = indirect_crl - self._only_contains_attribute_certs = only_contains_attribute_certs - self._only_some_reasons = only_some_reasons - self._full_name = full_name - self._relative_name = relative_name - - def __repr__(self) -> str: - return ( - f"" - ) - - def __eq__(self, other: object) -> bool: - if not isinstance(other, IssuingDistributionPoint): - return NotImplemented - - return ( - self.full_name == other.full_name - and self.relative_name == other.relative_name - and self.only_contains_user_certs == other.only_contains_user_certs - and self.only_contains_ca_certs == other.only_contains_ca_certs - and self.only_some_reasons == other.only_some_reasons - and self.indirect_crl == other.indirect_crl - and self.only_contains_attribute_certs - == other.only_contains_attribute_certs - ) - - def __hash__(self) -> int: - if self.full_name is not None: - full_name: tuple[GeneralName, ...] | None = tuple(self.full_name) - else: - full_name = None - - return hash( - ( - full_name, - self.relative_name, - self.only_contains_user_certs, - self.only_contains_ca_certs, - self.only_some_reasons, - self.indirect_crl, - self.only_contains_attribute_certs, - ) - ) - - @property - def full_name(self) -> list[GeneralName] | None: - return self._full_name - - @property - def relative_name(self) -> RelativeDistinguishedName | None: - return self._relative_name - - @property - def only_contains_user_certs(self) -> bool: - return self._only_contains_user_certs - - @property - def only_contains_ca_certs(self) -> bool: - return self._only_contains_ca_certs - - @property - def only_some_reasons( - self, - ) -> frozenset[ReasonFlags] | None: - return self._only_some_reasons - - @property - def indirect_crl(self) -> bool: - return self._indirect_crl - - @property - def only_contains_attribute_certs(self) -> bool: - return self._only_contains_attribute_certs - - def public_bytes(self) -> bytes: - return rust_x509.encode_extension_value(self) - - -class MSCertificateTemplate(ExtensionType): - oid = ExtensionOID.MS_CERTIFICATE_TEMPLATE - - def __init__( - self, - template_id: ObjectIdentifier, - major_version: int | None, - minor_version: int | None, - ) -> None: - if not isinstance(template_id, ObjectIdentifier): - raise TypeError("oid must be an ObjectIdentifier") - self._template_id = template_id - if ( - major_version is not None and not isinstance(major_version, int) - ) or ( - minor_version is not None and not isinstance(minor_version, int) - ): - raise TypeError( - "major_version and minor_version must be integers or None" - ) - self._major_version = major_version - self._minor_version = minor_version - - @property - def template_id(self) -> ObjectIdentifier: - return self._template_id - - @property - def major_version(self) -> int | None: - return self._major_version - - @property - def minor_version(self) -> int | None: - return self._minor_version - - def __repr__(self) -> str: - return ( - f"" - ) - - def __eq__(self, other: object) -> bool: - if not isinstance(other, MSCertificateTemplate): - return NotImplemented - - return ( - self.template_id == other.template_id - and self.major_version == other.major_version - and self.minor_version == other.minor_version - ) - - def __hash__(self) -> int: - return hash((self.template_id, self.major_version, self.minor_version)) - - def public_bytes(self) -> bytes: - return rust_x509.encode_extension_value(self) - - -class NamingAuthority: - def __init__( - self, - id: ObjectIdentifier | None, - url: str | None, - text: str | None, - ) -> None: - if id is not None and not isinstance(id, ObjectIdentifier): - raise TypeError("id must be an ObjectIdentifier") - - if url is not None and not isinstance(url, str): - raise TypeError("url must be a str") - - if text is not None and not isinstance(text, str): - raise TypeError("text must be a str") - - self._id = id - self._url = url - self._text = text - - @property - def id(self) -> ObjectIdentifier | None: - return self._id - - @property - def url(self) -> str | None: - return self._url - - @property - def text(self) -> str | None: - return self._text - - def __repr__(self) -> str: - return ( - f"" - ) - - def __eq__(self, other: object) -> bool: - if not isinstance(other, NamingAuthority): - return NotImplemented - - return ( - self.id == other.id - and self.url == other.url - and self.text == other.text - ) - - def __hash__(self) -> int: - return hash( - ( - self.id, - self.url, - self.text, - ) - ) - - -class ProfessionInfo: - def __init__( - self, - naming_authority: NamingAuthority | None, - profession_items: Iterable[str], - profession_oids: Iterable[ObjectIdentifier] | None, - registration_number: str | None, - add_profession_info: bytes | None, - ) -> None: - if naming_authority is not None and not isinstance( - naming_authority, NamingAuthority - ): - raise TypeError("naming_authority must be a NamingAuthority") - - profession_items = list(profession_items) - if not all(isinstance(item, str) for item in profession_items): - raise TypeError( - "Every item in the profession_items list must be a str" - ) - - if profession_oids is not None: - profession_oids = list(profession_oids) - if not all( - isinstance(oid, ObjectIdentifier) for oid in profession_oids - ): - raise TypeError( - "Every item in the profession_oids list must be an " - "ObjectIdentifier" - ) - - if registration_number is not None and not isinstance( - registration_number, str - ): - raise TypeError("registration_number must be a str") - - if add_profession_info is not None and not isinstance( - add_profession_info, bytes - ): - raise TypeError("add_profession_info must be bytes") - - self._naming_authority = naming_authority - self._profession_items = profession_items - self._profession_oids = profession_oids - self._registration_number = registration_number - self._add_profession_info = add_profession_info - - @property - def naming_authority(self) -> NamingAuthority | None: - return self._naming_authority - - @property - def profession_items(self) -> list[str]: - return self._profession_items - - @property - def profession_oids(self) -> list[ObjectIdentifier] | None: - return self._profession_oids - - @property - def registration_number(self) -> str | None: - return self._registration_number - - @property - def add_profession_info(self) -> bytes | None: - return self._add_profession_info - - def __repr__(self) -> str: - return ( - f"" - ) - - def __eq__(self, other: object) -> bool: - if not isinstance(other, ProfessionInfo): - return NotImplemented - - return ( - self.naming_authority == other.naming_authority - and self.profession_items == other.profession_items - and self.profession_oids == other.profession_oids - and self.registration_number == other.registration_number - and self.add_profession_info == other.add_profession_info - ) - - def __hash__(self) -> int: - if self.profession_oids is not None: - profession_oids = tuple(self.profession_oids) - else: - profession_oids = None - return hash( - ( - self.naming_authority, - tuple(self.profession_items), - profession_oids, - self.registration_number, - self.add_profession_info, - ) - ) - - -class Admission: - def __init__( - self, - admission_authority: GeneralName | None, - naming_authority: NamingAuthority | None, - profession_infos: Iterable[ProfessionInfo], - ) -> None: - if admission_authority is not None and not isinstance( - admission_authority, GeneralName - ): - raise TypeError("admission_authority must be a GeneralName") - - if naming_authority is not None and not isinstance( - naming_authority, NamingAuthority - ): - raise TypeError("naming_authority must be a NamingAuthority") - - profession_infos = list(profession_infos) - if not all( - isinstance(info, ProfessionInfo) for info in profession_infos - ): - raise TypeError( - "Every item in the profession_infos list must be a " - "ProfessionInfo" - ) - - self._admission_authority = admission_authority - self._naming_authority = naming_authority - self._profession_infos = profession_infos - - @property - def admission_authority(self) -> GeneralName | None: - return self._admission_authority - - @property - def naming_authority(self) -> NamingAuthority | None: - return self._naming_authority - - @property - def profession_infos(self) -> list[ProfessionInfo]: - return self._profession_infos - - def __repr__(self) -> str: - return ( - f"" - ) - - def __eq__(self, other: object) -> bool: - if not isinstance(other, Admission): - return NotImplemented - - return ( - self.admission_authority == other.admission_authority - and self.naming_authority == other.naming_authority - and self.profession_infos == other.profession_infos - ) - - def __hash__(self) -> int: - return hash( - ( - self.admission_authority, - self.naming_authority, - tuple(self.profession_infos), - ) - ) - - -class Admissions(ExtensionType): - oid = ExtensionOID.ADMISSIONS - - def __init__( - self, - authority: GeneralName | None, - admissions: Iterable[Admission], - ) -> None: - if authority is not None and not isinstance(authority, GeneralName): - raise TypeError("authority must be a GeneralName") - - admissions = list(admissions) - if not all( - isinstance(admission, Admission) for admission in admissions - ): - raise TypeError( - "Every item in the contents_of_admissions list must be an " - "Admission" - ) - - self._authority = authority - self._admissions = admissions - - __len__, __iter__, __getitem__ = _make_sequence_methods("_admissions") - - @property - def authority(self) -> GeneralName | None: - return self._authority - - def __repr__(self) -> str: - return ( - f"" - ) - - def __eq__(self, other: object) -> bool: - if not isinstance(other, Admissions): - return NotImplemented - - return ( - self.authority == other.authority - and self._admissions == other._admissions - ) - - def __hash__(self) -> int: - return hash((self.authority, tuple(self._admissions))) - - def public_bytes(self) -> bytes: - return rust_x509.encode_extension_value(self) - - -class UnrecognizedExtension(ExtensionType): - def __init__(self, oid: ObjectIdentifier, value: bytes) -> None: - if not isinstance(oid, ObjectIdentifier): - raise TypeError("oid must be an ObjectIdentifier") - self._oid = oid - self._value = value - - @property - def oid(self) -> ObjectIdentifier: # type: ignore[override] - return self._oid - - @property - def value(self) -> bytes: - return self._value - - def __repr__(self) -> str: - return f"" - - def __eq__(self, other: object) -> bool: - if not isinstance(other, UnrecognizedExtension): - return NotImplemented - - return self.oid == other.oid and self.value == other.value - - def __hash__(self) -> int: - return hash((self.oid, self.value)) - - def public_bytes(self) -> bytes: - return self.value diff --git a/.venv/lib/python3.12/site-packages/cryptography/x509/general_name.py b/.venv/lib/python3.12/site-packages/cryptography/x509/general_name.py deleted file mode 100644 index 672f287..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/x509/general_name.py +++ /dev/null @@ -1,281 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -import abc -import ipaddress -import typing -from email.utils import parseaddr - -from cryptography.x509.name import Name -from cryptography.x509.oid import ObjectIdentifier - -_IPAddressTypes = typing.Union[ - ipaddress.IPv4Address, - ipaddress.IPv6Address, - ipaddress.IPv4Network, - ipaddress.IPv6Network, -] - - -class UnsupportedGeneralNameType(Exception): - pass - - -class GeneralName(metaclass=abc.ABCMeta): - @property - @abc.abstractmethod - def value(self) -> typing.Any: - """ - Return the value of the object - """ - - -class RFC822Name(GeneralName): - def __init__(self, value: str) -> None: - if isinstance(value, str): - try: - value.encode("ascii") - except UnicodeEncodeError: - raise ValueError( - "RFC822Name values should be passed as an A-label string. " - "This means unicode characters should be encoded via " - "a library like idna." - ) - else: - raise TypeError("value must be string") - - name, address = parseaddr(value) - if name or not address: - # parseaddr has found a name (e.g. Name ) or the entire - # value is an empty string. - raise ValueError("Invalid rfc822name value") - - self._value = value - - @property - def value(self) -> str: - return self._value - - @classmethod - def _init_without_validation(cls, value: str) -> RFC822Name: - instance = cls.__new__(cls) - instance._value = value - return instance - - def __repr__(self) -> str: - return f"" - - def __eq__(self, other: object) -> bool: - if not isinstance(other, RFC822Name): - return NotImplemented - - return self.value == other.value - - def __hash__(self) -> int: - return hash(self.value) - - -class DNSName(GeneralName): - def __init__(self, value: str) -> None: - if isinstance(value, str): - try: - value.encode("ascii") - except UnicodeEncodeError: - raise ValueError( - "DNSName values should be passed as an A-label string. " - "This means unicode characters should be encoded via " - "a library like idna." - ) - else: - raise TypeError("value must be string") - - self._value = value - - @property - def value(self) -> str: - return self._value - - @classmethod - def _init_without_validation(cls, value: str) -> DNSName: - instance = cls.__new__(cls) - instance._value = value - return instance - - def __repr__(self) -> str: - return f"" - - def __eq__(self, other: object) -> bool: - if not isinstance(other, DNSName): - return NotImplemented - - return self.value == other.value - - def __hash__(self) -> int: - return hash(self.value) - - -class UniformResourceIdentifier(GeneralName): - def __init__(self, value: str) -> None: - if isinstance(value, str): - try: - value.encode("ascii") - except UnicodeEncodeError: - raise ValueError( - "URI values should be passed as an A-label string. " - "This means unicode characters should be encoded via " - "a library like idna." - ) - else: - raise TypeError("value must be string") - - self._value = value - - @property - def value(self) -> str: - return self._value - - @classmethod - def _init_without_validation(cls, value: str) -> UniformResourceIdentifier: - instance = cls.__new__(cls) - instance._value = value - return instance - - def __repr__(self) -> str: - return f"" - - def __eq__(self, other: object) -> bool: - if not isinstance(other, UniformResourceIdentifier): - return NotImplemented - - return self.value == other.value - - def __hash__(self) -> int: - return hash(self.value) - - -class DirectoryName(GeneralName): - def __init__(self, value: Name) -> None: - if not isinstance(value, Name): - raise TypeError("value must be a Name") - - self._value = value - - @property - def value(self) -> Name: - return self._value - - def __repr__(self) -> str: - return f"" - - def __eq__(self, other: object) -> bool: - if not isinstance(other, DirectoryName): - return NotImplemented - - return self.value == other.value - - def __hash__(self) -> int: - return hash(self.value) - - -class RegisteredID(GeneralName): - def __init__(self, value: ObjectIdentifier) -> None: - if not isinstance(value, ObjectIdentifier): - raise TypeError("value must be an ObjectIdentifier") - - self._value = value - - @property - def value(self) -> ObjectIdentifier: - return self._value - - def __repr__(self) -> str: - return f"" - - def __eq__(self, other: object) -> bool: - if not isinstance(other, RegisteredID): - return NotImplemented - - return self.value == other.value - - def __hash__(self) -> int: - return hash(self.value) - - -class IPAddress(GeneralName): - def __init__(self, value: _IPAddressTypes) -> None: - if not isinstance( - value, - ( - ipaddress.IPv4Address, - ipaddress.IPv6Address, - ipaddress.IPv4Network, - ipaddress.IPv6Network, - ), - ): - raise TypeError( - "value must be an instance of ipaddress.IPv4Address, " - "ipaddress.IPv6Address, ipaddress.IPv4Network, or " - "ipaddress.IPv6Network" - ) - - self._value = value - - @property - def value(self) -> _IPAddressTypes: - return self._value - - def _packed(self) -> bytes: - if isinstance( - self.value, (ipaddress.IPv4Address, ipaddress.IPv6Address) - ): - return self.value.packed - else: - return ( - self.value.network_address.packed + self.value.netmask.packed - ) - - def __repr__(self) -> str: - return f"" - - def __eq__(self, other: object) -> bool: - if not isinstance(other, IPAddress): - return NotImplemented - - return self.value == other.value - - def __hash__(self) -> int: - return hash(self.value) - - -class OtherName(GeneralName): - def __init__(self, type_id: ObjectIdentifier, value: bytes) -> None: - if not isinstance(type_id, ObjectIdentifier): - raise TypeError("type_id must be an ObjectIdentifier") - if not isinstance(value, bytes): - raise TypeError("value must be a binary string") - - self._type_id = type_id - self._value = value - - @property - def type_id(self) -> ObjectIdentifier: - return self._type_id - - @property - def value(self) -> bytes: - return self._value - - def __repr__(self) -> str: - return f"" - - def __eq__(self, other: object) -> bool: - if not isinstance(other, OtherName): - return NotImplemented - - return self.type_id == other.type_id and self.value == other.value - - def __hash__(self) -> int: - return hash((self.type_id, self.value)) diff --git a/.venv/lib/python3.12/site-packages/cryptography/x509/name.py b/.venv/lib/python3.12/site-packages/cryptography/x509/name.py deleted file mode 100644 index 57f3d56..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/x509/name.py +++ /dev/null @@ -1,482 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -import binascii -import re -import sys -import typing -import warnings -from collections.abc import Iterable, Iterator - -from cryptography import utils -from cryptography.hazmat.bindings._rust import x509 as rust_x509 -from cryptography.x509.oid import NameOID, ObjectIdentifier - - -class _ASN1Type(utils.Enum): - BitString = 3 - OctetString = 4 - UTF8String = 12 - NumericString = 18 - PrintableString = 19 - T61String = 20 - IA5String = 22 - UTCTime = 23 - GeneralizedTime = 24 - VisibleString = 26 - UniversalString = 28 - BMPString = 30 - - -_ASN1_TYPE_TO_ENUM = {i.value: i for i in _ASN1Type} -_NAMEOID_DEFAULT_TYPE: dict[ObjectIdentifier, _ASN1Type] = { - NameOID.COUNTRY_NAME: _ASN1Type.PrintableString, - NameOID.JURISDICTION_COUNTRY_NAME: _ASN1Type.PrintableString, - NameOID.SERIAL_NUMBER: _ASN1Type.PrintableString, - NameOID.DN_QUALIFIER: _ASN1Type.PrintableString, - NameOID.EMAIL_ADDRESS: _ASN1Type.IA5String, - NameOID.DOMAIN_COMPONENT: _ASN1Type.IA5String, -} - -# Type alias -_OidNameMap = typing.Mapping[ObjectIdentifier, str] -_NameOidMap = typing.Mapping[str, ObjectIdentifier] - -#: Short attribute names from RFC 4514: -#: https://tools.ietf.org/html/rfc4514#page-7 -_NAMEOID_TO_NAME: _OidNameMap = { - NameOID.COMMON_NAME: "CN", - NameOID.LOCALITY_NAME: "L", - NameOID.STATE_OR_PROVINCE_NAME: "ST", - NameOID.ORGANIZATION_NAME: "O", - NameOID.ORGANIZATIONAL_UNIT_NAME: "OU", - NameOID.COUNTRY_NAME: "C", - NameOID.STREET_ADDRESS: "STREET", - NameOID.DOMAIN_COMPONENT: "DC", - NameOID.USER_ID: "UID", -} -_NAME_TO_NAMEOID = {v: k for k, v in _NAMEOID_TO_NAME.items()} - -_NAMEOID_LENGTH_LIMIT = { - NameOID.COUNTRY_NAME: (2, 2), - NameOID.JURISDICTION_COUNTRY_NAME: (2, 2), - NameOID.COMMON_NAME: (1, 64), -} - - -def _escape_dn_value(val: str | bytes) -> str: - """Escape special characters in RFC4514 Distinguished Name value.""" - - if not val: - return "" - - # RFC 4514 Section 2.4 defines the value as being the # (U+0023) character - # followed by the hexadecimal encoding of the octets. - if isinstance(val, bytes): - return "#" + binascii.hexlify(val).decode("utf8") - - # See https://tools.ietf.org/html/rfc4514#section-2.4 - val = val.replace("\\", "\\\\") - val = val.replace('"', '\\"') - val = val.replace("+", "\\+") - val = val.replace(",", "\\,") - val = val.replace(";", "\\;") - val = val.replace("<", "\\<") - val = val.replace(">", "\\>") - val = val.replace("\0", "\\00") - - if val[0] == "#" or (val[0] == " " and len(val) > 1): - val = "\\" + val - if val[-1] == " ": - val = val[:-1] + "\\ " - - return val - - -def _unescape_dn_value(val: str) -> str: - if not val: - return "" - - # See https://tools.ietf.org/html/rfc4514#section-3 - - # special = escaped / SPACE / SHARP / EQUALS - # escaped = DQUOTE / PLUS / COMMA / SEMI / LANGLE / RANGLE - def sub(m): - val = m.group(0) - # Special character escape - if len(val) == 2: - return val[1:] - - # Unicode string of hex - return binascii.unhexlify(val.replace("\\", "")).decode() - - return _RFC4514NameParser._PAIR_MULTI_RE.sub(sub, val) - - -NameAttributeValueType = typing.TypeVar( - "NameAttributeValueType", - typing.Union[str, bytes], - str, - bytes, - covariant=True, -) - - -class NameAttribute(typing.Generic[NameAttributeValueType]): - def __init__( - self, - oid: ObjectIdentifier, - value: NameAttributeValueType, - _type: _ASN1Type | None = None, - *, - _validate: bool = True, - ) -> None: - if not isinstance(oid, ObjectIdentifier): - raise TypeError( - "oid argument must be an ObjectIdentifier instance." - ) - if _type == _ASN1Type.BitString: - if oid != NameOID.X500_UNIQUE_IDENTIFIER: - raise TypeError( - "oid must be X500_UNIQUE_IDENTIFIER for BitString type." - ) - if not isinstance(value, bytes): - raise TypeError("value must be bytes for BitString") - elif not isinstance(value, str): - raise TypeError("value argument must be a str") - - length_limits = _NAMEOID_LENGTH_LIMIT.get(oid) - if length_limits is not None: - min_length, max_length = length_limits - assert isinstance(value, str) - c_len = len(value.encode("utf8")) - if c_len < min_length or c_len > max_length: - msg = ( - f"Attribute's length must be >= {min_length} and " - f"<= {max_length}, but it was {c_len}" - ) - if _validate is True: - raise ValueError(msg) - else: - warnings.warn(msg, stacklevel=2) - - # The appropriate ASN1 string type varies by OID and is defined across - # multiple RFCs including 2459, 3280, and 5280. In general UTF8String - # is preferred (2459), but 3280 and 5280 specify several OIDs with - # alternate types. This means when we see the sentinel value we need - # to look up whether the OID has a non-UTF8 type. If it does, set it - # to that. Otherwise, UTF8! - if _type is None: - _type = _NAMEOID_DEFAULT_TYPE.get(oid, _ASN1Type.UTF8String) - - if not isinstance(_type, _ASN1Type): - raise TypeError("_type must be from the _ASN1Type enum") - - self._oid = oid - self._value: NameAttributeValueType = value - self._type: _ASN1Type = _type - - @property - def oid(self) -> ObjectIdentifier: - return self._oid - - @property - def value(self) -> NameAttributeValueType: - return self._value - - @property - def rfc4514_attribute_name(self) -> str: - """ - The short attribute name (for example "CN") if available, - otherwise the OID dotted string. - """ - return _NAMEOID_TO_NAME.get(self.oid, self.oid.dotted_string) - - def rfc4514_string( - self, attr_name_overrides: _OidNameMap | None = None - ) -> str: - """ - Format as RFC4514 Distinguished Name string. - - Use short attribute name if available, otherwise fall back to OID - dotted string. - """ - attr_name = ( - attr_name_overrides.get(self.oid) if attr_name_overrides else None - ) - if attr_name is None: - attr_name = self.rfc4514_attribute_name - - return f"{attr_name}={_escape_dn_value(self.value)}" - - def __eq__(self, other: object) -> bool: - if not isinstance(other, NameAttribute): - return NotImplemented - - return self.oid == other.oid and self.value == other.value - - def __hash__(self) -> int: - return hash((self.oid, self.value)) - - def __repr__(self) -> str: - return f"" - - -class RelativeDistinguishedName: - def __init__(self, attributes: Iterable[NameAttribute[str | bytes]]): - attributes = list(attributes) - if not attributes: - raise ValueError("a relative distinguished name cannot be empty") - if not all(isinstance(x, NameAttribute) for x in attributes): - raise TypeError("attributes must be an iterable of NameAttribute") - - # Keep list and frozenset to preserve attribute order where it matters - self._attributes = attributes - self._attribute_set = frozenset(attributes) - - if len(self._attribute_set) != len(attributes): - raise ValueError("duplicate attributes are not allowed") - - def get_attributes_for_oid( - self, - oid: ObjectIdentifier, - ) -> list[NameAttribute[str | bytes]]: - return [i for i in self if i.oid == oid] - - def rfc4514_string( - self, attr_name_overrides: _OidNameMap | None = None - ) -> str: - """ - Format as RFC4514 Distinguished Name string. - - Within each RDN, attributes are joined by '+', although that is rarely - used in certificates. - """ - return "+".join( - attr.rfc4514_string(attr_name_overrides) - for attr in self._attributes - ) - - def __eq__(self, other: object) -> bool: - if not isinstance(other, RelativeDistinguishedName): - return NotImplemented - - return self._attribute_set == other._attribute_set - - def __hash__(self) -> int: - return hash(self._attribute_set) - - def __iter__(self) -> Iterator[NameAttribute[str | bytes]]: - return iter(self._attributes) - - def __len__(self) -> int: - return len(self._attributes) - - def __repr__(self) -> str: - return f"" - - -class Name: - @typing.overload - def __init__( - self, attributes: Iterable[NameAttribute[str | bytes]] - ) -> None: ... - - @typing.overload - def __init__( - self, attributes: Iterable[RelativeDistinguishedName] - ) -> None: ... - - def __init__( - self, - attributes: Iterable[ - NameAttribute[str | bytes] | RelativeDistinguishedName - ], - ) -> None: - attributes = list(attributes) - if all(isinstance(x, NameAttribute) for x in attributes): - self._attributes = [ - RelativeDistinguishedName([typing.cast(NameAttribute, x)]) - for x in attributes - ] - elif all(isinstance(x, RelativeDistinguishedName) for x in attributes): - self._attributes = typing.cast( - list[RelativeDistinguishedName], attributes - ) - else: - raise TypeError( - "attributes must be a list of NameAttribute" - " or a list RelativeDistinguishedName" - ) - - @classmethod - def from_rfc4514_string( - cls, - data: str, - attr_name_overrides: _NameOidMap | None = None, - ) -> Name: - return _RFC4514NameParser(data, attr_name_overrides or {}).parse() - - def rfc4514_string( - self, attr_name_overrides: _OidNameMap | None = None - ) -> str: - """ - Format as RFC4514 Distinguished Name string. - For example 'CN=foobar.com,O=Foo Corp,C=US' - - An X.509 name is a two-level structure: a list of sets of attributes. - Each list element is separated by ',' and within each list element, set - elements are separated by '+'. The latter is almost never used in - real world certificates. According to RFC4514 section 2.1 the - RDNSequence must be reversed when converting to string representation. - """ - return ",".join( - attr.rfc4514_string(attr_name_overrides) - for attr in reversed(self._attributes) - ) - - def get_attributes_for_oid( - self, - oid: ObjectIdentifier, - ) -> list[NameAttribute[str | bytes]]: - return [i for i in self if i.oid == oid] - - @property - def rdns(self) -> list[RelativeDistinguishedName]: - return self._attributes - - def public_bytes(self, backend: typing.Any = None) -> bytes: - return rust_x509.encode_name_bytes(self) - - def __eq__(self, other: object) -> bool: - if not isinstance(other, Name): - return NotImplemented - - return self._attributes == other._attributes - - def __hash__(self) -> int: - # TODO: this is relatively expensive, if this looks like a bottleneck - # for you, consider optimizing! - return hash(tuple(self._attributes)) - - def __iter__(self) -> Iterator[NameAttribute[str | bytes]]: - for rdn in self._attributes: - yield from rdn - - def __len__(self) -> int: - return sum(len(rdn) for rdn in self._attributes) - - def __repr__(self) -> str: - return f"" - - -class _RFC4514NameParser: - _OID_RE = re.compile(r"(0|([1-9]\d*))(\.(0|([1-9]\d*)))+") - _DESCR_RE = re.compile(r"[a-zA-Z][a-zA-Z\d-]*") - - _ESCAPE_SPECIAL = r"[\\ #=\"\+,;<>]" - _ESCAPE_HEX = r"[\da-zA-Z]{2}" - _PAIR = rf"\\({_ESCAPE_SPECIAL}|{_ESCAPE_HEX})" - _PAIR_MULTI_RE = re.compile(rf"(\\{_ESCAPE_SPECIAL})|((\\{_ESCAPE_HEX})+)") - _LUTF1 = r"[\x01-\x1f\x21\x24-\x2A\x2D-\x3A\x3D\x3F-\x5B\x5D-\x7F]" - _SUTF1 = r"[\x01-\x21\x23-\x2A\x2D-\x3A\x3D\x3F-\x5B\x5D-\x7F]" - _TUTF1 = r"[\x01-\x1F\x21\x23-\x2A\x2D-\x3A\x3D\x3F-\x5B\x5D-\x7F]" - _UTFMB = rf"[\x80-{chr(sys.maxunicode)}]" - _LEADCHAR = rf"{_LUTF1}|{_UTFMB}" - _STRINGCHAR = rf"{_SUTF1}|{_UTFMB}" - _TRAILCHAR = rf"{_TUTF1}|{_UTFMB}" - _STRING_RE = re.compile( - rf""" - ( - ({_LEADCHAR}|{_PAIR}) - ( - ({_STRINGCHAR}|{_PAIR})* - ({_TRAILCHAR}|{_PAIR}) - )? - )? - """, - re.VERBOSE, - ) - _HEXSTRING_RE = re.compile(r"#([\da-zA-Z]{2})+") - - def __init__(self, data: str, attr_name_overrides: _NameOidMap) -> None: - self._data = data - self._idx = 0 - - self._attr_name_overrides = attr_name_overrides - - def _has_data(self) -> bool: - return self._idx < len(self._data) - - def _peek(self) -> str | None: - if self._has_data(): - return self._data[self._idx] - return None - - def _read_char(self, ch: str) -> None: - if self._peek() != ch: - raise ValueError - self._idx += 1 - - def _read_re(self, pat) -> str: - match = pat.match(self._data, pos=self._idx) - if match is None: - raise ValueError - val = match.group() - self._idx += len(val) - return val - - def parse(self) -> Name: - """ - Parses the `data` string and converts it to a Name. - - According to RFC4514 section 2.1 the RDNSequence must be - reversed when converting to string representation. So, when - we parse it, we need to reverse again to get the RDNs on the - correct order. - """ - - if not self._has_data(): - return Name([]) - - rdns = [self._parse_rdn()] - - while self._has_data(): - self._read_char(",") - rdns.append(self._parse_rdn()) - - return Name(reversed(rdns)) - - def _parse_rdn(self) -> RelativeDistinguishedName: - nas = [self._parse_na()] - while self._peek() == "+": - self._read_char("+") - nas.append(self._parse_na()) - - return RelativeDistinguishedName(nas) - - def _parse_na(self) -> NameAttribute[str]: - try: - oid_value = self._read_re(self._OID_RE) - except ValueError: - name = self._read_re(self._DESCR_RE) - oid = self._attr_name_overrides.get( - name, _NAME_TO_NAMEOID.get(name) - ) - if oid is None: - raise ValueError - else: - oid = ObjectIdentifier(oid_value) - - self._read_char("=") - if self._peek() == "#": - value = self._read_re(self._HEXSTRING_RE) - value = binascii.unhexlify(value[1:]).decode() - else: - raw_value = self._read_re(self._STRING_RE) - value = _unescape_dn_value(raw_value) - - return NameAttribute(oid, value) diff --git a/.venv/lib/python3.12/site-packages/cryptography/x509/ocsp.py b/.venv/lib/python3.12/site-packages/cryptography/x509/ocsp.py deleted file mode 100644 index f61ed80..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/x509/ocsp.py +++ /dev/null @@ -1,379 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -import datetime -from collections.abc import Iterable - -from cryptography import utils, x509 -from cryptography.hazmat.bindings._rust import ocsp -from cryptography.hazmat.primitives import hashes -from cryptography.hazmat.primitives.asymmetric.types import ( - CertificateIssuerPrivateKeyTypes, -) -from cryptography.x509.base import _reject_duplicate_extension - - -class OCSPResponderEncoding(utils.Enum): - HASH = "By Hash" - NAME = "By Name" - - -class OCSPResponseStatus(utils.Enum): - SUCCESSFUL = 0 - MALFORMED_REQUEST = 1 - INTERNAL_ERROR = 2 - TRY_LATER = 3 - SIG_REQUIRED = 5 - UNAUTHORIZED = 6 - - -_ALLOWED_HASHES = ( - hashes.SHA1, - hashes.SHA224, - hashes.SHA256, - hashes.SHA384, - hashes.SHA512, -) - - -def _verify_algorithm(algorithm: hashes.HashAlgorithm) -> None: - if not isinstance(algorithm, _ALLOWED_HASHES): - raise ValueError( - "Algorithm must be SHA1, SHA224, SHA256, SHA384, or SHA512" - ) - - -class OCSPCertStatus(utils.Enum): - GOOD = 0 - REVOKED = 1 - UNKNOWN = 2 - - -class _SingleResponse: - def __init__( - self, - resp: tuple[x509.Certificate, x509.Certificate] | None, - resp_hash: tuple[bytes, bytes, int] | None, - algorithm: hashes.HashAlgorithm, - cert_status: OCSPCertStatus, - this_update: datetime.datetime, - next_update: datetime.datetime | None, - revocation_time: datetime.datetime | None, - revocation_reason: x509.ReasonFlags | None, - ): - _verify_algorithm(algorithm) - if not isinstance(this_update, datetime.datetime): - raise TypeError("this_update must be a datetime object") - if next_update is not None and not isinstance( - next_update, datetime.datetime - ): - raise TypeError("next_update must be a datetime object or None") - - self._resp = resp - self._resp_hash = resp_hash - self._algorithm = algorithm - self._this_update = this_update - self._next_update = next_update - - if not isinstance(cert_status, OCSPCertStatus): - raise TypeError( - "cert_status must be an item from the OCSPCertStatus enum" - ) - if cert_status is not OCSPCertStatus.REVOKED: - if revocation_time is not None: - raise ValueError( - "revocation_time can only be provided if the certificate " - "is revoked" - ) - if revocation_reason is not None: - raise ValueError( - "revocation_reason can only be provided if the certificate" - " is revoked" - ) - else: - if not isinstance(revocation_time, datetime.datetime): - raise TypeError("revocation_time must be a datetime object") - - if revocation_reason is not None and not isinstance( - revocation_reason, x509.ReasonFlags - ): - raise TypeError( - "revocation_reason must be an item from the ReasonFlags " - "enum or None" - ) - - self._cert_status = cert_status - self._revocation_time = revocation_time - self._revocation_reason = revocation_reason - - -OCSPRequest = ocsp.OCSPRequest -OCSPResponse = ocsp.OCSPResponse -OCSPSingleResponse = ocsp.OCSPSingleResponse - - -class OCSPRequestBuilder: - def __init__( - self, - request: tuple[ - x509.Certificate, x509.Certificate, hashes.HashAlgorithm - ] - | None = None, - request_hash: tuple[bytes, bytes, int, hashes.HashAlgorithm] - | None = None, - extensions: list[x509.Extension[x509.ExtensionType]] = [], - ) -> None: - self._request = request - self._request_hash = request_hash - self._extensions = extensions - - def add_certificate( - self, - cert: x509.Certificate, - issuer: x509.Certificate, - algorithm: hashes.HashAlgorithm, - ) -> OCSPRequestBuilder: - if self._request is not None or self._request_hash is not None: - raise ValueError("Only one certificate can be added to a request") - - _verify_algorithm(algorithm) - if not isinstance(cert, x509.Certificate) or not isinstance( - issuer, x509.Certificate - ): - raise TypeError("cert and issuer must be a Certificate") - - return OCSPRequestBuilder( - (cert, issuer, algorithm), self._request_hash, self._extensions - ) - - def add_certificate_by_hash( - self, - issuer_name_hash: bytes, - issuer_key_hash: bytes, - serial_number: int, - algorithm: hashes.HashAlgorithm, - ) -> OCSPRequestBuilder: - if self._request is not None or self._request_hash is not None: - raise ValueError("Only one certificate can be added to a request") - - if not isinstance(serial_number, int): - raise TypeError("serial_number must be an integer") - - _verify_algorithm(algorithm) - utils._check_bytes("issuer_name_hash", issuer_name_hash) - utils._check_bytes("issuer_key_hash", issuer_key_hash) - if algorithm.digest_size != len( - issuer_name_hash - ) or algorithm.digest_size != len(issuer_key_hash): - raise ValueError( - "issuer_name_hash and issuer_key_hash must be the same length " - "as the digest size of the algorithm" - ) - - return OCSPRequestBuilder( - self._request, - (issuer_name_hash, issuer_key_hash, serial_number, algorithm), - self._extensions, - ) - - def add_extension( - self, extval: x509.ExtensionType, critical: bool - ) -> OCSPRequestBuilder: - if not isinstance(extval, x509.ExtensionType): - raise TypeError("extension must be an ExtensionType") - - extension = x509.Extension(extval.oid, critical, extval) - _reject_duplicate_extension(extension, self._extensions) - - return OCSPRequestBuilder( - self._request, self._request_hash, [*self._extensions, extension] - ) - - def build(self) -> OCSPRequest: - if self._request is None and self._request_hash is None: - raise ValueError("You must add a certificate before building") - - return ocsp.create_ocsp_request(self) - - -class OCSPResponseBuilder: - def __init__( - self, - response: _SingleResponse | None = None, - responder_id: tuple[x509.Certificate, OCSPResponderEncoding] - | None = None, - certs: list[x509.Certificate] | None = None, - extensions: list[x509.Extension[x509.ExtensionType]] = [], - ): - self._response = response - self._responder_id = responder_id - self._certs = certs - self._extensions = extensions - - def add_response( - self, - cert: x509.Certificate, - issuer: x509.Certificate, - algorithm: hashes.HashAlgorithm, - cert_status: OCSPCertStatus, - this_update: datetime.datetime, - next_update: datetime.datetime | None, - revocation_time: datetime.datetime | None, - revocation_reason: x509.ReasonFlags | None, - ) -> OCSPResponseBuilder: - if self._response is not None: - raise ValueError("Only one response per OCSPResponse.") - - if not isinstance(cert, x509.Certificate) or not isinstance( - issuer, x509.Certificate - ): - raise TypeError("cert and issuer must be a Certificate") - - singleresp = _SingleResponse( - (cert, issuer), - None, - algorithm, - cert_status, - this_update, - next_update, - revocation_time, - revocation_reason, - ) - return OCSPResponseBuilder( - singleresp, - self._responder_id, - self._certs, - self._extensions, - ) - - def add_response_by_hash( - self, - issuer_name_hash: bytes, - issuer_key_hash: bytes, - serial_number: int, - algorithm: hashes.HashAlgorithm, - cert_status: OCSPCertStatus, - this_update: datetime.datetime, - next_update: datetime.datetime | None, - revocation_time: datetime.datetime | None, - revocation_reason: x509.ReasonFlags | None, - ) -> OCSPResponseBuilder: - if self._response is not None: - raise ValueError("Only one response per OCSPResponse.") - - if not isinstance(serial_number, int): - raise TypeError("serial_number must be an integer") - - utils._check_bytes("issuer_name_hash", issuer_name_hash) - utils._check_bytes("issuer_key_hash", issuer_key_hash) - _verify_algorithm(algorithm) - if algorithm.digest_size != len( - issuer_name_hash - ) or algorithm.digest_size != len(issuer_key_hash): - raise ValueError( - "issuer_name_hash and issuer_key_hash must be the same length " - "as the digest size of the algorithm" - ) - - singleresp = _SingleResponse( - None, - (issuer_name_hash, issuer_key_hash, serial_number), - algorithm, - cert_status, - this_update, - next_update, - revocation_time, - revocation_reason, - ) - return OCSPResponseBuilder( - singleresp, - self._responder_id, - self._certs, - self._extensions, - ) - - def responder_id( - self, encoding: OCSPResponderEncoding, responder_cert: x509.Certificate - ) -> OCSPResponseBuilder: - if self._responder_id is not None: - raise ValueError("responder_id can only be set once") - if not isinstance(responder_cert, x509.Certificate): - raise TypeError("responder_cert must be a Certificate") - if not isinstance(encoding, OCSPResponderEncoding): - raise TypeError( - "encoding must be an element from OCSPResponderEncoding" - ) - - return OCSPResponseBuilder( - self._response, - (responder_cert, encoding), - self._certs, - self._extensions, - ) - - def certificates( - self, certs: Iterable[x509.Certificate] - ) -> OCSPResponseBuilder: - if self._certs is not None: - raise ValueError("certificates may only be set once") - certs = list(certs) - if len(certs) == 0: - raise ValueError("certs must not be an empty list") - if not all(isinstance(x, x509.Certificate) for x in certs): - raise TypeError("certs must be a list of Certificates") - return OCSPResponseBuilder( - self._response, - self._responder_id, - certs, - self._extensions, - ) - - def add_extension( - self, extval: x509.ExtensionType, critical: bool - ) -> OCSPResponseBuilder: - if not isinstance(extval, x509.ExtensionType): - raise TypeError("extension must be an ExtensionType") - - extension = x509.Extension(extval.oid, critical, extval) - _reject_duplicate_extension(extension, self._extensions) - - return OCSPResponseBuilder( - self._response, - self._responder_id, - self._certs, - [*self._extensions, extension], - ) - - def sign( - self, - private_key: CertificateIssuerPrivateKeyTypes, - algorithm: hashes.HashAlgorithm | None, - ) -> OCSPResponse: - if self._response is None: - raise ValueError("You must add a response before signing") - if self._responder_id is None: - raise ValueError("You must add a responder_id before signing") - - return ocsp.create_ocsp_response( - OCSPResponseStatus.SUCCESSFUL, self, private_key, algorithm - ) - - @classmethod - def build_unsuccessful( - cls, response_status: OCSPResponseStatus - ) -> OCSPResponse: - if not isinstance(response_status, OCSPResponseStatus): - raise TypeError( - "response_status must be an item from OCSPResponseStatus" - ) - if response_status is OCSPResponseStatus.SUCCESSFUL: - raise ValueError("response_status cannot be SUCCESSFUL") - - return ocsp.create_ocsp_response(response_status, None, None, None) - - -load_der_ocsp_request = ocsp.load_der_ocsp_request -load_der_ocsp_response = ocsp.load_der_ocsp_response diff --git a/.venv/lib/python3.12/site-packages/cryptography/x509/oid.py b/.venv/lib/python3.12/site-packages/cryptography/x509/oid.py deleted file mode 100644 index 520fc7a..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/x509/oid.py +++ /dev/null @@ -1,37 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -from cryptography.hazmat._oid import ( - AttributeOID, - AuthorityInformationAccessOID, - CertificatePoliciesOID, - CRLEntryExtensionOID, - ExtendedKeyUsageOID, - ExtensionOID, - NameOID, - ObjectIdentifier, - OCSPExtensionOID, - OtherNameFormOID, - PublicKeyAlgorithmOID, - SignatureAlgorithmOID, - SubjectInformationAccessOID, -) - -__all__ = [ - "AttributeOID", - "AuthorityInformationAccessOID", - "CRLEntryExtensionOID", - "CertificatePoliciesOID", - "ExtendedKeyUsageOID", - "ExtensionOID", - "NameOID", - "OCSPExtensionOID", - "ObjectIdentifier", - "OtherNameFormOID", - "PublicKeyAlgorithmOID", - "SignatureAlgorithmOID", - "SubjectInformationAccessOID", -] diff --git a/.venv/lib/python3.12/site-packages/cryptography/x509/verification.py b/.venv/lib/python3.12/site-packages/cryptography/x509/verification.py deleted file mode 100644 index 2db4324..0000000 --- a/.venv/lib/python3.12/site-packages/cryptography/x509/verification.py +++ /dev/null @@ -1,34 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import annotations - -import typing - -from cryptography.hazmat.bindings._rust import x509 as rust_x509 -from cryptography.x509.general_name import DNSName, IPAddress - -__all__ = [ - "ClientVerifier", - "Criticality", - "ExtensionPolicy", - "Policy", - "PolicyBuilder", - "ServerVerifier", - "Store", - "Subject", - "VerificationError", - "VerifiedClient", -] - -Store = rust_x509.Store -Subject = typing.Union[DNSName, IPAddress] -VerifiedClient = rust_x509.VerifiedClient -ClientVerifier = rust_x509.ClientVerifier -ServerVerifier = rust_x509.ServerVerifier -PolicyBuilder = rust_x509.PolicyBuilder -Policy = rust_x509.Policy -ExtensionPolicy = rust_x509.ExtensionPolicy -Criticality = rust_x509.Criticality -VerificationError = rust_x509.VerificationError diff --git a/.venv/lib/python3.12/site-packages/distutils-precedence.pth b/.venv/lib/python3.12/site-packages/distutils-precedence.pth deleted file mode 100644 index 7f009fe..0000000 --- a/.venv/lib/python3.12/site-packages/distutils-precedence.pth +++ /dev/null @@ -1 +0,0 @@ -import os; var = 'SETUPTOOLS_USE_DISTUTILS'; enabled = os.environ.get(var, 'local') == 'local'; enabled and __import__('_distutils_hack').add_shim(); diff --git a/.venv/lib/python3.12/site-packages/h11-0.16.0.dist-info/INSTALLER b/.venv/lib/python3.12/site-packages/h11-0.16.0.dist-info/INSTALLER deleted file mode 100644 index a1b589e..0000000 --- a/.venv/lib/python3.12/site-packages/h11-0.16.0.dist-info/INSTALLER +++ /dev/null @@ -1 +0,0 @@ -pip diff --git a/.venv/lib/python3.12/site-packages/h11-0.16.0.dist-info/METADATA b/.venv/lib/python3.12/site-packages/h11-0.16.0.dist-info/METADATA deleted file mode 100644 index 8a2f639..0000000 --- a/.venv/lib/python3.12/site-packages/h11-0.16.0.dist-info/METADATA +++ /dev/null @@ -1,202 +0,0 @@ -Metadata-Version: 2.4 -Name: h11 -Version: 0.16.0 -Summary: A pure-Python, bring-your-own-I/O implementation of HTTP/1.1 -Home-page: https://github.com/python-hyper/h11 -Author: Nathaniel J. Smith -Author-email: njs@pobox.com -License: MIT -Classifier: Development Status :: 3 - Alpha -Classifier: Intended Audience :: Developers -Classifier: License :: OSI Approved :: MIT License -Classifier: Programming Language :: Python :: Implementation :: CPython -Classifier: Programming Language :: Python :: Implementation :: PyPy -Classifier: Programming Language :: Python :: 3 -Classifier: Programming Language :: Python :: 3 :: Only -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: Topic :: Internet :: WWW/HTTP -Classifier: Topic :: System :: Networking -Requires-Python: >=3.8 -License-File: LICENSE.txt -Dynamic: author -Dynamic: author-email -Dynamic: classifier -Dynamic: description -Dynamic: home-page -Dynamic: license -Dynamic: license-file -Dynamic: requires-python -Dynamic: summary - -h11 -=== - -.. image:: https://travis-ci.org/python-hyper/h11.svg?branch=master - :target: https://travis-ci.org/python-hyper/h11 - :alt: Automated test status - -.. image:: https://codecov.io/gh/python-hyper/h11/branch/master/graph/badge.svg - :target: https://codecov.io/gh/python-hyper/h11 - :alt: Test coverage - -.. image:: https://readthedocs.org/projects/h11/badge/?version=latest - :target: http://h11.readthedocs.io/en/latest/?badge=latest - :alt: Documentation Status - -This is a little HTTP/1.1 library written from scratch in Python, -heavily inspired by `hyper-h2 `_. - -It's a "bring-your-own-I/O" library; h11 contains no IO code -whatsoever. This means you can hook h11 up to your favorite network -API, and that could be anything you want: synchronous, threaded, -asynchronous, or your own implementation of `RFC 6214 -`_ -- h11 won't judge you. -(Compare this to the current state of the art, where every time a `new -network API `_ comes along then someone -gets to start over reimplementing the entire HTTP protocol from -scratch.) Cory Benfield made an `excellent blog post describing the -benefits of this approach -`_, or if you like video -then here's his `PyCon 2016 talk on the same theme -`_. - -This also means that h11 is not immediately useful out of the box: -it's a toolkit for building programs that speak HTTP, not something -that could directly replace ``requests`` or ``twisted.web`` or -whatever. But h11 makes it much easier to implement something like -``requests`` or ``twisted.web``. - -At a high level, working with h11 goes like this: - -1) First, create an ``h11.Connection`` object to track the state of a - single HTTP/1.1 connection. - -2) When you read data off the network, pass it to - ``conn.receive_data(...)``; you'll get back a list of objects - representing high-level HTTP "events". - -3) When you want to send a high-level HTTP event, create the - corresponding "event" object and pass it to ``conn.send(...)``; - this will give you back some bytes that you can then push out - through the network. - -For example, a client might instantiate and then send a -``h11.Request`` object, then zero or more ``h11.Data`` objects for the -request body (e.g., if this is a POST), and then a -``h11.EndOfMessage`` to indicate the end of the message. Then the -server would then send back a ``h11.Response``, some ``h11.Data``, and -its own ``h11.EndOfMessage``. If either side violates the protocol, -you'll get a ``h11.ProtocolError`` exception. - -h11 is suitable for implementing both servers and clients, and has a -pleasantly symmetric API: the events you send as a client are exactly -the ones that you receive as a server and vice-versa. - -`Here's an example of a tiny HTTP client -`_ - -It also has `a fine manual `_. - -FAQ ---- - -*Whyyyyy?* - -I wanted to play with HTTP in `Curio -`__ and `Trio -`__, which at the time didn't have any -HTTP libraries. So I thought, no big deal, Python has, like, a dozen -different implementations of HTTP, surely I can find one that's -reusable. I didn't find one, but I did find Cory's call-to-arms -blog-post. So I figured, well, fine, if I have to implement HTTP from -scratch, at least I can make sure no-one *else* has to ever again. - -*Should I use it?* - -Maybe. You should be aware that it's a very young project. But, it's -feature complete and has an exhaustive test-suite and complete docs, -so the next step is for people to try using it and see how it goes -:-). If you do then please let us know -- if nothing else we'll want -to talk to you before making any incompatible changes! - -*What are the features/limitations?* - -Roughly speaking, it's trying to be a robust, complete, and non-hacky -implementation of the first "chapter" of the HTTP/1.1 spec: `RFC 7230: -HTTP/1.1 Message Syntax and Routing -`_. That is, it mostly focuses on -implementing HTTP at the level of taking bytes on and off the wire, -and the headers related to that, and tries to be anal about spec -conformance. It doesn't know about higher-level concerns like URL -routing, conditional GETs, cross-origin cookie policies, or content -negotiation. But it does know how to take care of framing, -cross-version differences in keep-alive handling, and the "obsolete -line folding" rule, so you can focus your energies on the hard / -interesting parts for your application, and it tries to support the -full specification in the sense that any useful HTTP/1.1 conformant -application should be able to use h11. - -It's pure Python, and has no dependencies outside of the standard -library. - -It has a test suite with 100.0% coverage for both statements and -branches. - -Currently it supports Python 3 (testing on 3.8-3.12) and PyPy 3. -The last Python 2-compatible version was h11 0.11.x. -(Originally it had a Cython wrapper for `http-parser -`_ and a beautiful nested state -machine implemented with ``yield from`` to postprocess the output. But -I had to take these out -- the new *parser* needs fewer lines-of-code -than the old *parser wrapper*, is written in pure Python, uses no -exotic language syntax, and has more features. It's sad, really; that -old state machine was really slick. I just need a few sentences here -to mourn that.) - -I don't know how fast it is. I haven't benchmarked or profiled it yet, -so it's probably got a few pointless hot spots, and I've been trying -to err on the side of simplicity and robustness instead of -micro-optimization. But at the architectural level I tried hard to -avoid fundamentally bad decisions, e.g., I believe that all the -parsing algorithms remain linear-time even in the face of pathological -input like slowloris, and there are no byte-by-byte loops. (I also -believe that it maintains bounded memory usage in the face of -arbitrary/pathological input.) - -The whole library is ~800 lines-of-code. You can read and understand -the whole thing in less than an hour. Most of the energy invested in -this so far has been spent on trying to keep things simple by -minimizing special-cases and ad hoc state manipulation; even though it -is now quite small and simple, I'm still annoyed that I haven't -figured out how to make it even smaller and simpler. (Unfortunately, -HTTP does not lend itself to simplicity.) - -The API is ~feature complete and I don't expect the general outlines -to change much, but you can't judge an API's ergonomics until you -actually document and use it, so I'd expect some changes in the -details. - -*How do I try it?* - -.. code-block:: sh - - $ pip install h11 - $ git clone git@github.com:python-hyper/h11 - $ cd h11/examples - $ python basic-client.py - -and go from there. - -*License?* - -MIT - -*Code of conduct?* - -Contributors are requested to follow our `code of conduct -`_ in -all project spaces. diff --git a/.venv/lib/python3.12/site-packages/h11-0.16.0.dist-info/RECORD b/.venv/lib/python3.12/site-packages/h11-0.16.0.dist-info/RECORD deleted file mode 100644 index a8f8e63..0000000 --- a/.venv/lib/python3.12/site-packages/h11-0.16.0.dist-info/RECORD +++ /dev/null @@ -1,29 +0,0 @@ -h11-0.16.0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4 -h11-0.16.0.dist-info/METADATA,sha256=KPMmCYrAn8unm48YD5YIfIQf4kViFct7hyqcfVzRnWQ,8348 -h11-0.16.0.dist-info/RECORD,, -h11-0.16.0.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91 -h11-0.16.0.dist-info/licenses/LICENSE.txt,sha256=N9tbuFkm2yikJ6JYZ_ELEjIAOuob5pzLhRE4rbjm82E,1124 -h11-0.16.0.dist-info/top_level.txt,sha256=F7dC4jl3zeh8TGHEPaWJrMbeuoWbS379Gwdi-Yvdcis,4 -h11/__init__.py,sha256=iO1KzkSO42yZ6ffg-VMgbx_ZVTWGUY00nRYEWn-s3kY,1507 -h11/__pycache__/__init__.cpython-312.pyc,, -h11/__pycache__/_abnf.cpython-312.pyc,, -h11/__pycache__/_connection.cpython-312.pyc,, -h11/__pycache__/_events.cpython-312.pyc,, -h11/__pycache__/_headers.cpython-312.pyc,, -h11/__pycache__/_readers.cpython-312.pyc,, -h11/__pycache__/_receivebuffer.cpython-312.pyc,, -h11/__pycache__/_state.cpython-312.pyc,, -h11/__pycache__/_util.cpython-312.pyc,, -h11/__pycache__/_version.cpython-312.pyc,, -h11/__pycache__/_writers.cpython-312.pyc,, -h11/_abnf.py,sha256=ybixr0xsupnkA6GFAyMubuXF6Tc1lb_hF890NgCsfNc,4815 -h11/_connection.py,sha256=k9YRVf6koZqbttBW36xSWaJpWdZwa-xQVU9AHEo9DuI,26863 -h11/_events.py,sha256=I97aXoal1Wu7dkL548BANBUCkOIbe-x5CioYA9IBY14,11792 -h11/_headers.py,sha256=P7D-lBNxHwdLZPLimmYwrPG-9ZkjElvvJZJdZAgSP-4,10412 -h11/_readers.py,sha256=a4RypORUCC3d0q_kxPuBIM7jTD8iLt5X91TH0FsduN4,8590 -h11/_receivebuffer.py,sha256=xrspsdsNgWFxRfQcTXxR8RrdjRXXTK0Io5cQYWpJ1Ws,5252 -h11/_state.py,sha256=_5LG_BGR8FCcFQeBPH-TMHgm_-B-EUcWCnQof_9XjFE,13231 -h11/_util.py,sha256=LWkkjXyJaFlAy6Lt39w73UStklFT5ovcvo0TkY7RYuk,4888 -h11/_version.py,sha256=GVSsbPSPDcOuF6ptfIiXnVJoaEm3ygXbMnqlr_Giahw,686 -h11/_writers.py,sha256=oFKm6PtjeHfbj4RLX7VB7KDc1gIY53gXG3_HR9ltmTA,5081 -h11/py.typed,sha256=sow9soTwP9T_gEAQSVh7Gb8855h04Nwmhs2We-JRgZM,7 diff --git a/.venv/lib/python3.12/site-packages/h11-0.16.0.dist-info/WHEEL b/.venv/lib/python3.12/site-packages/h11-0.16.0.dist-info/WHEEL deleted file mode 100644 index 1eb3c49..0000000 --- a/.venv/lib/python3.12/site-packages/h11-0.16.0.dist-info/WHEEL +++ /dev/null @@ -1,5 +0,0 @@ -Wheel-Version: 1.0 -Generator: setuptools (78.1.0) -Root-Is-Purelib: true -Tag: py3-none-any - diff --git a/.venv/lib/python3.12/site-packages/h11-0.16.0.dist-info/licenses/LICENSE.txt b/.venv/lib/python3.12/site-packages/h11-0.16.0.dist-info/licenses/LICENSE.txt deleted file mode 100644 index 8f080ea..0000000 --- a/.venv/lib/python3.12/site-packages/h11-0.16.0.dist-info/licenses/LICENSE.txt +++ /dev/null @@ -1,22 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2016 Nathaniel J. Smith and other contributors - -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. diff --git a/.venv/lib/python3.12/site-packages/h11-0.16.0.dist-info/top_level.txt b/.venv/lib/python3.12/site-packages/h11-0.16.0.dist-info/top_level.txt deleted file mode 100644 index 0d24def..0000000 --- a/.venv/lib/python3.12/site-packages/h11-0.16.0.dist-info/top_level.txt +++ /dev/null @@ -1 +0,0 @@ -h11 diff --git a/.venv/lib/python3.12/site-packages/h11/__init__.py b/.venv/lib/python3.12/site-packages/h11/__init__.py deleted file mode 100644 index 989e92c..0000000 --- a/.venv/lib/python3.12/site-packages/h11/__init__.py +++ /dev/null @@ -1,62 +0,0 @@ -# A highish-level implementation of the HTTP/1.1 wire protocol (RFC 7230), -# containing no networking code at all, loosely modelled on hyper-h2's generic -# implementation of HTTP/2 (and in particular the h2.connection.H2Connection -# class). There's still a bunch of subtle details you need to get right if you -# want to make this actually useful, because it doesn't implement all the -# semantics to check that what you're asking to write to the wire is sensible, -# but at least it gets you out of dealing with the wire itself. - -from h11._connection import Connection, NEED_DATA, PAUSED -from h11._events import ( - ConnectionClosed, - Data, - EndOfMessage, - Event, - InformationalResponse, - Request, - Response, -) -from h11._state import ( - CLIENT, - CLOSED, - DONE, - ERROR, - IDLE, - MIGHT_SWITCH_PROTOCOL, - MUST_CLOSE, - SEND_BODY, - SEND_RESPONSE, - SERVER, - SWITCHED_PROTOCOL, -) -from h11._util import LocalProtocolError, ProtocolError, RemoteProtocolError -from h11._version import __version__ - -PRODUCT_ID = "python-h11/" + __version__ - - -__all__ = ( - "Connection", - "NEED_DATA", - "PAUSED", - "ConnectionClosed", - "Data", - "EndOfMessage", - "Event", - "InformationalResponse", - "Request", - "Response", - "CLIENT", - "CLOSED", - "DONE", - "ERROR", - "IDLE", - "MUST_CLOSE", - "SEND_BODY", - "SEND_RESPONSE", - "SERVER", - "SWITCHED_PROTOCOL", - "ProtocolError", - "LocalProtocolError", - "RemoteProtocolError", -) diff --git a/.venv/lib/python3.12/site-packages/h11/_abnf.py b/.venv/lib/python3.12/site-packages/h11/_abnf.py deleted file mode 100644 index 933587f..0000000 --- a/.venv/lib/python3.12/site-packages/h11/_abnf.py +++ /dev/null @@ -1,132 +0,0 @@ -# We use native strings for all the re patterns, to take advantage of string -# formatting, and then convert to bytestrings when compiling the final re -# objects. - -# https://svn.tools.ietf.org/svn/wg/httpbis/specs/rfc7230.html#whitespace -# OWS = *( SP / HTAB ) -# ; optional whitespace -OWS = r"[ \t]*" - -# https://svn.tools.ietf.org/svn/wg/httpbis/specs/rfc7230.html#rule.token.separators -# token = 1*tchar -# -# tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*" -# / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~" -# / DIGIT / ALPHA -# ; any VCHAR, except delimiters -token = r"[-!#$%&'*+.^_`|~0-9a-zA-Z]+" - -# https://svn.tools.ietf.org/svn/wg/httpbis/specs/rfc7230.html#header.fields -# field-name = token -field_name = token - -# The standard says: -# -# field-value = *( field-content / obs-fold ) -# field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ] -# field-vchar = VCHAR / obs-text -# obs-fold = CRLF 1*( SP / HTAB ) -# ; obsolete line folding -# ; see Section 3.2.4 -# -# https://tools.ietf.org/html/rfc5234#appendix-B.1 -# -# VCHAR = %x21-7E -# ; visible (printing) characters -# -# https://svn.tools.ietf.org/svn/wg/httpbis/specs/rfc7230.html#rule.quoted-string -# obs-text = %x80-FF -# -# However, the standard definition of field-content is WRONG! It disallows -# fields containing a single visible character surrounded by whitespace, -# e.g. "foo a bar". -# -# See: https://www.rfc-editor.org/errata_search.php?rfc=7230&eid=4189 -# -# So our definition of field_content attempts to fix it up... -# -# Also, we allow lots of control characters, because apparently people assume -# that they're legal in practice (e.g., google analytics makes cookies with -# \x01 in them!): -# https://github.com/python-hyper/h11/issues/57 -# We still don't allow NUL or whitespace, because those are often treated as -# meta-characters and letting them through can lead to nasty issues like SSRF. -vchar = r"[\x21-\x7e]" -vchar_or_obs_text = r"[^\x00\s]" -field_vchar = vchar_or_obs_text -field_content = r"{field_vchar}+(?:[ \t]+{field_vchar}+)*".format(**globals()) - -# We handle obs-fold at a different level, and our fixed-up field_content -# already grows to swallow the whole value, so ? instead of * -field_value = r"({field_content})?".format(**globals()) - -# header-field = field-name ":" OWS field-value OWS -header_field = ( - r"(?P{field_name})" - r":" - r"{OWS}" - r"(?P{field_value})" - r"{OWS}".format(**globals()) -) - -# https://svn.tools.ietf.org/svn/wg/httpbis/specs/rfc7230.html#request.line -# -# request-line = method SP request-target SP HTTP-version CRLF -# method = token -# HTTP-version = HTTP-name "/" DIGIT "." DIGIT -# HTTP-name = %x48.54.54.50 ; "HTTP", case-sensitive -# -# request-target is complicated (see RFC 7230 sec 5.3) -- could be path, full -# URL, host+port (for connect), or even "*", but in any case we are guaranteed -# that it contists of the visible printing characters. -method = token -request_target = r"{vchar}+".format(**globals()) -http_version = r"HTTP/(?P[0-9]\.[0-9])" -request_line = ( - r"(?P{method})" - r" " - r"(?P{request_target})" - r" " - r"{http_version}".format(**globals()) -) - -# https://svn.tools.ietf.org/svn/wg/httpbis/specs/rfc7230.html#status.line -# -# status-line = HTTP-version SP status-code SP reason-phrase CRLF -# status-code = 3DIGIT -# reason-phrase = *( HTAB / SP / VCHAR / obs-text ) -status_code = r"[0-9]{3}" -reason_phrase = r"([ \t]|{vchar_or_obs_text})*".format(**globals()) -status_line = ( - r"{http_version}" - r" " - r"(?P{status_code})" - # However, there are apparently a few too many servers out there that just - # leave out the reason phrase: - # https://github.com/scrapy/scrapy/issues/345#issuecomment-281756036 - # https://github.com/seanmonstar/httparse/issues/29 - # so make it optional. ?: is a non-capturing group. - r"(?: (?P{reason_phrase}))?".format(**globals()) -) - -HEXDIG = r"[0-9A-Fa-f]" -# Actually -# -# chunk-size = 1*HEXDIG -# -# but we impose an upper-limit to avoid ridiculosity. len(str(2**64)) == 20 -chunk_size = r"({HEXDIG}){{1,20}}".format(**globals()) -# Actually -# -# chunk-ext = *( ";" chunk-ext-name [ "=" chunk-ext-val ] ) -# -# but we aren't parsing the things so we don't really care. -chunk_ext = r";.*" -chunk_header = ( - r"(?P{chunk_size})" - r"(?P{chunk_ext})?" - r"{OWS}\r\n".format( - **globals() - ) # Even though the specification does not allow for extra whitespaces, - # we are lenient with trailing whitespaces because some servers on the wild use it. -) diff --git a/.venv/lib/python3.12/site-packages/h11/_connection.py b/.venv/lib/python3.12/site-packages/h11/_connection.py deleted file mode 100644 index e37d82a..0000000 --- a/.venv/lib/python3.12/site-packages/h11/_connection.py +++ /dev/null @@ -1,659 +0,0 @@ -# This contains the main Connection class. Everything in h11 revolves around -# this. -from typing import ( - Any, - Callable, - cast, - Dict, - List, - Optional, - overload, - Tuple, - Type, - Union, -) - -from ._events import ( - ConnectionClosed, - Data, - EndOfMessage, - Event, - InformationalResponse, - Request, - Response, -) -from ._headers import get_comma_header, has_expect_100_continue, set_comma_header -from ._readers import READERS, ReadersType -from ._receivebuffer import ReceiveBuffer -from ._state import ( - _SWITCH_CONNECT, - _SWITCH_UPGRADE, - CLIENT, - ConnectionState, - DONE, - ERROR, - MIGHT_SWITCH_PROTOCOL, - SEND_BODY, - SERVER, - SWITCHED_PROTOCOL, -) -from ._util import ( # Import the internal things we need - LocalProtocolError, - RemoteProtocolError, - Sentinel, -) -from ._writers import WRITERS, WritersType - -# Everything in __all__ gets re-exported as part of the h11 public API. -__all__ = ["Connection", "NEED_DATA", "PAUSED"] - - -class NEED_DATA(Sentinel, metaclass=Sentinel): - pass - - -class PAUSED(Sentinel, metaclass=Sentinel): - pass - - -# If we ever have this much buffered without it making a complete parseable -# event, we error out. The only time we really buffer is when reading the -# request/response line + headers together, so this is effectively the limit on -# the size of that. -# -# Some precedents for defaults: -# - node.js: 80 * 1024 -# - tomcat: 8 * 1024 -# - IIS: 16 * 1024 -# - Apache: <8 KiB per line> -DEFAULT_MAX_INCOMPLETE_EVENT_SIZE = 16 * 1024 - - -# RFC 7230's rules for connection lifecycles: -# - If either side says they want to close the connection, then the connection -# must close. -# - HTTP/1.1 defaults to keep-alive unless someone says Connection: close -# - HTTP/1.0 defaults to close unless both sides say Connection: keep-alive -# (and even this is a mess -- e.g. if you're implementing a proxy then -# sending Connection: keep-alive is forbidden). -# -# We simplify life by simply not supporting keep-alive with HTTP/1.0 peers. So -# our rule is: -# - If someone says Connection: close, we will close -# - If someone uses HTTP/1.0, we will close. -def _keep_alive(event: Union[Request, Response]) -> bool: - connection = get_comma_header(event.headers, b"connection") - if b"close" in connection: - return False - if getattr(event, "http_version", b"1.1") < b"1.1": - return False - return True - - -def _body_framing( - request_method: bytes, event: Union[Request, Response] -) -> Tuple[str, Union[Tuple[()], Tuple[int]]]: - # Called when we enter SEND_BODY to figure out framing information for - # this body. - # - # These are the only two events that can trigger a SEND_BODY state: - assert type(event) in (Request, Response) - # Returns one of: - # - # ("content-length", count) - # ("chunked", ()) - # ("http/1.0", ()) - # - # which are (lookup key, *args) for constructing body reader/writer - # objects. - # - # Reference: https://tools.ietf.org/html/rfc7230#section-3.3.3 - # - # Step 1: some responses always have an empty body, regardless of what the - # headers say. - if type(event) is Response: - if ( - event.status_code in (204, 304) - or request_method == b"HEAD" - or (request_method == b"CONNECT" and 200 <= event.status_code < 300) - ): - return ("content-length", (0,)) - # Section 3.3.3 also lists another case -- responses with status_code - # < 200. For us these are InformationalResponses, not Responses, so - # they can't get into this function in the first place. - assert event.status_code >= 200 - - # Step 2: check for Transfer-Encoding (T-E beats C-L): - transfer_encodings = get_comma_header(event.headers, b"transfer-encoding") - if transfer_encodings: - assert transfer_encodings == [b"chunked"] - return ("chunked", ()) - - # Step 3: check for Content-Length - content_lengths = get_comma_header(event.headers, b"content-length") - if content_lengths: - return ("content-length", (int(content_lengths[0]),)) - - # Step 4: no applicable headers; fallback/default depends on type - if type(event) is Request: - return ("content-length", (0,)) - else: - return ("http/1.0", ()) - - -################################################################ -# -# The main Connection class -# -################################################################ - - -class Connection: - """An object encapsulating the state of an HTTP connection. - - Args: - our_role: If you're implementing a client, pass :data:`h11.CLIENT`. If - you're implementing a server, pass :data:`h11.SERVER`. - - max_incomplete_event_size (int): - The maximum number of bytes we're willing to buffer of an - incomplete event. In practice this mostly sets a limit on the - maximum size of the request/response line + headers. If this is - exceeded, then :meth:`next_event` will raise - :exc:`RemoteProtocolError`. - - """ - - def __init__( - self, - our_role: Type[Sentinel], - max_incomplete_event_size: int = DEFAULT_MAX_INCOMPLETE_EVENT_SIZE, - ) -> None: - self._max_incomplete_event_size = max_incomplete_event_size - # State and role tracking - if our_role not in (CLIENT, SERVER): - raise ValueError(f"expected CLIENT or SERVER, not {our_role!r}") - self.our_role = our_role - self.their_role: Type[Sentinel] - if our_role is CLIENT: - self.their_role = SERVER - else: - self.their_role = CLIENT - self._cstate = ConnectionState() - - # Callables for converting data->events or vice-versa given the - # current state - self._writer = self._get_io_object(self.our_role, None, WRITERS) - self._reader = self._get_io_object(self.their_role, None, READERS) - - # Holds any unprocessed received data - self._receive_buffer = ReceiveBuffer() - # If this is true, then it indicates that the incoming connection was - # closed *after* the end of whatever's in self._receive_buffer: - self._receive_buffer_closed = False - - # Extra bits of state that don't fit into the state machine. - # - # These two are only used to interpret framing headers for figuring - # out how to read/write response bodies. their_http_version is also - # made available as a convenient public API. - self.their_http_version: Optional[bytes] = None - self._request_method: Optional[bytes] = None - # This is pure flow-control and doesn't at all affect the set of legal - # transitions, so no need to bother ConnectionState with it: - self.client_is_waiting_for_100_continue = False - - @property - def states(self) -> Dict[Type[Sentinel], Type[Sentinel]]: - """A dictionary like:: - - {CLIENT: , SERVER: } - - See :ref:`state-machine` for details. - - """ - return dict(self._cstate.states) - - @property - def our_state(self) -> Type[Sentinel]: - """The current state of whichever role we are playing. See - :ref:`state-machine` for details. - """ - return self._cstate.states[self.our_role] - - @property - def their_state(self) -> Type[Sentinel]: - """The current state of whichever role we are NOT playing. See - :ref:`state-machine` for details. - """ - return self._cstate.states[self.their_role] - - @property - def they_are_waiting_for_100_continue(self) -> bool: - return self.their_role is CLIENT and self.client_is_waiting_for_100_continue - - def start_next_cycle(self) -> None: - """Attempt to reset our connection state for a new request/response - cycle. - - If both client and server are in :data:`DONE` state, then resets them - both to :data:`IDLE` state in preparation for a new request/response - cycle on this same connection. Otherwise, raises a - :exc:`LocalProtocolError`. - - See :ref:`keepalive-and-pipelining`. - - """ - old_states = dict(self._cstate.states) - self._cstate.start_next_cycle() - self._request_method = None - # self.their_http_version gets left alone, since it presumably lasts - # beyond a single request/response cycle - assert not self.client_is_waiting_for_100_continue - self._respond_to_state_changes(old_states) - - def _process_error(self, role: Type[Sentinel]) -> None: - old_states = dict(self._cstate.states) - self._cstate.process_error(role) - self._respond_to_state_changes(old_states) - - def _server_switch_event(self, event: Event) -> Optional[Type[Sentinel]]: - if type(event) is InformationalResponse and event.status_code == 101: - return _SWITCH_UPGRADE - if type(event) is Response: - if ( - _SWITCH_CONNECT in self._cstate.pending_switch_proposals - and 200 <= event.status_code < 300 - ): - return _SWITCH_CONNECT - return None - - # All events go through here - def _process_event(self, role: Type[Sentinel], event: Event) -> None: - # First, pass the event through the state machine to make sure it - # succeeds. - old_states = dict(self._cstate.states) - if role is CLIENT and type(event) is Request: - if event.method == b"CONNECT": - self._cstate.process_client_switch_proposal(_SWITCH_CONNECT) - if get_comma_header(event.headers, b"upgrade"): - self._cstate.process_client_switch_proposal(_SWITCH_UPGRADE) - server_switch_event = None - if role is SERVER: - server_switch_event = self._server_switch_event(event) - self._cstate.process_event(role, type(event), server_switch_event) - - # Then perform the updates triggered by it. - - if type(event) is Request: - self._request_method = event.method - - if role is self.their_role and type(event) in ( - Request, - Response, - InformationalResponse, - ): - event = cast(Union[Request, Response, InformationalResponse], event) - self.their_http_version = event.http_version - - # Keep alive handling - # - # RFC 7230 doesn't really say what one should do if Connection: close - # shows up on a 1xx InformationalResponse. I think the idea is that - # this is not supposed to happen. In any case, if it does happen, we - # ignore it. - if type(event) in (Request, Response) and not _keep_alive( - cast(Union[Request, Response], event) - ): - self._cstate.process_keep_alive_disabled() - - # 100-continue - if type(event) is Request and has_expect_100_continue(event): - self.client_is_waiting_for_100_continue = True - if type(event) in (InformationalResponse, Response): - self.client_is_waiting_for_100_continue = False - if role is CLIENT and type(event) in (Data, EndOfMessage): - self.client_is_waiting_for_100_continue = False - - self._respond_to_state_changes(old_states, event) - - def _get_io_object( - self, - role: Type[Sentinel], - event: Optional[Event], - io_dict: Union[ReadersType, WritersType], - ) -> Optional[Callable[..., Any]]: - # event may be None; it's only used when entering SEND_BODY - state = self._cstate.states[role] - if state is SEND_BODY: - # Special case: the io_dict has a dict of reader/writer factories - # that depend on the request/response framing. - framing_type, args = _body_framing( - cast(bytes, self._request_method), cast(Union[Request, Response], event) - ) - return io_dict[SEND_BODY][framing_type](*args) # type: ignore[index] - else: - # General case: the io_dict just has the appropriate reader/writer - # for this state - return io_dict.get((role, state)) # type: ignore[return-value] - - # This must be called after any action that might have caused - # self._cstate.states to change. - def _respond_to_state_changes( - self, - old_states: Dict[Type[Sentinel], Type[Sentinel]], - event: Optional[Event] = None, - ) -> None: - # Update reader/writer - if self.our_state != old_states[self.our_role]: - self._writer = self._get_io_object(self.our_role, event, WRITERS) - if self.their_state != old_states[self.their_role]: - self._reader = self._get_io_object(self.their_role, event, READERS) - - @property - def trailing_data(self) -> Tuple[bytes, bool]: - """Data that has been received, but not yet processed, represented as - a tuple with two elements, where the first is a byte-string containing - the unprocessed data itself, and the second is a bool that is True if - the receive connection was closed. - - See :ref:`switching-protocols` for discussion of why you'd want this. - """ - return (bytes(self._receive_buffer), self._receive_buffer_closed) - - def receive_data(self, data: bytes) -> None: - """Add data to our internal receive buffer. - - This does not actually do any processing on the data, just stores - it. To trigger processing, you have to call :meth:`next_event`. - - Args: - data (:term:`bytes-like object`): - The new data that was just received. - - Special case: If *data* is an empty byte-string like ``b""``, - then this indicates that the remote side has closed the - connection (end of file). Normally this is convenient, because - standard Python APIs like :meth:`file.read` or - :meth:`socket.recv` use ``b""`` to indicate end-of-file, while - other failures to read are indicated using other mechanisms - like raising :exc:`TimeoutError`. When using such an API you - can just blindly pass through whatever you get from ``read`` - to :meth:`receive_data`, and everything will work. - - But, if you have an API where reading an empty string is a - valid non-EOF condition, then you need to be aware of this and - make sure to check for such strings and avoid passing them to - :meth:`receive_data`. - - Returns: - Nothing, but after calling this you should call :meth:`next_event` - to parse the newly received data. - - Raises: - RuntimeError: - Raised if you pass an empty *data*, indicating EOF, and then - pass a non-empty *data*, indicating more data that somehow - arrived after the EOF. - - (Calling ``receive_data(b"")`` multiple times is fine, - and equivalent to calling it once.) - - """ - if data: - if self._receive_buffer_closed: - raise RuntimeError("received close, then received more data?") - self._receive_buffer += data - else: - self._receive_buffer_closed = True - - def _extract_next_receive_event( - self, - ) -> Union[Event, Type[NEED_DATA], Type[PAUSED]]: - state = self.their_state - # We don't pause immediately when they enter DONE, because even in - # DONE state we can still process a ConnectionClosed() event. But - # if we have data in our buffer, then we definitely aren't getting - # a ConnectionClosed() immediately and we need to pause. - if state is DONE and self._receive_buffer: - return PAUSED - if state is MIGHT_SWITCH_PROTOCOL or state is SWITCHED_PROTOCOL: - return PAUSED - assert self._reader is not None - event = self._reader(self._receive_buffer) - if event is None: - if not self._receive_buffer and self._receive_buffer_closed: - # In some unusual cases (basically just HTTP/1.0 bodies), EOF - # triggers an actual protocol event; in that case, we want to - # return that event, and then the state will change and we'll - # get called again to generate the actual ConnectionClosed(). - if hasattr(self._reader, "read_eof"): - event = self._reader.read_eof() - else: - event = ConnectionClosed() - if event is None: - event = NEED_DATA - return event # type: ignore[no-any-return] - - def next_event(self) -> Union[Event, Type[NEED_DATA], Type[PAUSED]]: - """Parse the next event out of our receive buffer, update our internal - state, and return it. - - This is a mutating operation -- think of it like calling :func:`next` - on an iterator. - - Returns: - : One of three things: - - 1) An event object -- see :ref:`events`. - - 2) The special constant :data:`NEED_DATA`, which indicates that - you need to read more data from your socket and pass it to - :meth:`receive_data` before this method will be able to return - any more events. - - 3) The special constant :data:`PAUSED`, which indicates that we - are not in a state where we can process incoming data (usually - because the peer has finished their part of the current - request/response cycle, and you have not yet called - :meth:`start_next_cycle`). See :ref:`flow-control` for details. - - Raises: - RemoteProtocolError: - The peer has misbehaved. You should close the connection - (possibly after sending some kind of 4xx response). - - Once this method returns :class:`ConnectionClosed` once, then all - subsequent calls will also return :class:`ConnectionClosed`. - - If this method raises any exception besides :exc:`RemoteProtocolError` - then that's a bug -- if it happens please file a bug report! - - If this method raises any exception then it also sets - :attr:`Connection.their_state` to :data:`ERROR` -- see - :ref:`error-handling` for discussion. - - """ - - if self.their_state is ERROR: - raise RemoteProtocolError("Can't receive data when peer state is ERROR") - try: - event = self._extract_next_receive_event() - if event not in [NEED_DATA, PAUSED]: - self._process_event(self.their_role, cast(Event, event)) - if event is NEED_DATA: - if len(self._receive_buffer) > self._max_incomplete_event_size: - # 431 is "Request header fields too large" which is pretty - # much the only situation where we can get here - raise RemoteProtocolError( - "Receive buffer too long", error_status_hint=431 - ) - if self._receive_buffer_closed: - # We're still trying to complete some event, but that's - # never going to happen because no more data is coming - raise RemoteProtocolError("peer unexpectedly closed connection") - return event - except BaseException as exc: - self._process_error(self.their_role) - if isinstance(exc, LocalProtocolError): - exc._reraise_as_remote_protocol_error() - else: - raise - - @overload - def send(self, event: ConnectionClosed) -> None: - ... - - @overload - def send( - self, event: Union[Request, InformationalResponse, Response, Data, EndOfMessage] - ) -> bytes: - ... - - @overload - def send(self, event: Event) -> Optional[bytes]: - ... - - def send(self, event: Event) -> Optional[bytes]: - """Convert a high-level event into bytes that can be sent to the peer, - while updating our internal state machine. - - Args: - event: The :ref:`event ` to send. - - Returns: - If ``type(event) is ConnectionClosed``, then returns - ``None``. Otherwise, returns a :term:`bytes-like object`. - - Raises: - LocalProtocolError: - Sending this event at this time would violate our - understanding of the HTTP/1.1 protocol. - - If this method raises any exception then it also sets - :attr:`Connection.our_state` to :data:`ERROR` -- see - :ref:`error-handling` for discussion. - - """ - data_list = self.send_with_data_passthrough(event) - if data_list is None: - return None - else: - return b"".join(data_list) - - def send_with_data_passthrough(self, event: Event) -> Optional[List[bytes]]: - """Identical to :meth:`send`, except that in situations where - :meth:`send` returns a single :term:`bytes-like object`, this instead - returns a list of them -- and when sending a :class:`Data` event, this - list is guaranteed to contain the exact object you passed in as - :attr:`Data.data`. See :ref:`sendfile` for discussion. - - """ - if self.our_state is ERROR: - raise LocalProtocolError("Can't send data when our state is ERROR") - try: - if type(event) is Response: - event = self._clean_up_response_headers_for_sending(event) - # We want to call _process_event before calling the writer, - # because if someone tries to do something invalid then this will - # give a sensible error message, while our writers all just assume - # they will only receive valid events. But, _process_event might - # change self._writer. So we have to do a little dance: - writer = self._writer - self._process_event(self.our_role, event) - if type(event) is ConnectionClosed: - return None - else: - # In any situation where writer is None, process_event should - # have raised ProtocolError - assert writer is not None - data_list: List[bytes] = [] - writer(event, data_list.append) - return data_list - except: - self._process_error(self.our_role) - raise - - def send_failed(self) -> None: - """Notify the state machine that we failed to send the data it gave - us. - - This causes :attr:`Connection.our_state` to immediately become - :data:`ERROR` -- see :ref:`error-handling` for discussion. - - """ - self._process_error(self.our_role) - - # When sending a Response, we take responsibility for a few things: - # - # - Sometimes you MUST set Connection: close. We take care of those - # times. (You can also set it yourself if you want, and if you do then - # we'll respect that and close the connection at the right time. But you - # don't have to worry about that unless you want to.) - # - # - The user has to set Content-Length if they want it. Otherwise, for - # responses that have bodies (e.g. not HEAD), then we will automatically - # select the right mechanism for streaming a body of unknown length, - # which depends on depending on the peer's HTTP version. - # - # This function's *only* responsibility is making sure headers are set up - # right -- everything downstream just looks at the headers. There are no - # side channels. - def _clean_up_response_headers_for_sending(self, response: Response) -> Response: - assert type(response) is Response - - headers = response.headers - need_close = False - - # HEAD requests need some special handling: they always act like they - # have Content-Length: 0, and that's how _body_framing treats - # them. But their headers are supposed to match what we would send if - # the request was a GET. (Technically there is one deviation allowed: - # we're allowed to leave out the framing headers -- see - # https://tools.ietf.org/html/rfc7231#section-4.3.2 . But it's just as - # easy to get them right.) - method_for_choosing_headers = cast(bytes, self._request_method) - if method_for_choosing_headers == b"HEAD": - method_for_choosing_headers = b"GET" - framing_type, _ = _body_framing(method_for_choosing_headers, response) - if framing_type in ("chunked", "http/1.0"): - # This response has a body of unknown length. - # If our peer is HTTP/1.1, we use Transfer-Encoding: chunked - # If our peer is HTTP/1.0, we use no framing headers, and close the - # connection afterwards. - # - # Make sure to clear Content-Length (in principle user could have - # set both and then we ignored Content-Length b/c - # Transfer-Encoding overwrote it -- this would be naughty of them, - # but the HTTP spec says that if our peer does this then we have - # to fix it instead of erroring out, so we'll accord the user the - # same respect). - headers = set_comma_header(headers, b"content-length", []) - if self.their_http_version is None or self.their_http_version < b"1.1": - # Either we never got a valid request and are sending back an - # error (their_http_version is None), so we assume the worst; - # or else we did get a valid HTTP/1.0 request, so we know that - # they don't understand chunked encoding. - headers = set_comma_header(headers, b"transfer-encoding", []) - # This is actually redundant ATM, since currently we - # unconditionally disable keep-alive when talking to HTTP/1.0 - # peers. But let's be defensive just in case we add - # Connection: keep-alive support later: - if self._request_method != b"HEAD": - need_close = True - else: - headers = set_comma_header(headers, b"transfer-encoding", [b"chunked"]) - - if not self._cstate.keep_alive or need_close: - # Make sure Connection: close is set - connection = set(get_comma_header(headers, b"connection")) - connection.discard(b"keep-alive") - connection.add(b"close") - headers = set_comma_header(headers, b"connection", sorted(connection)) - - return Response( - headers=headers, - status_code=response.status_code, - http_version=response.http_version, - reason=response.reason, - ) diff --git a/.venv/lib/python3.12/site-packages/h11/_events.py b/.venv/lib/python3.12/site-packages/h11/_events.py deleted file mode 100644 index ca1c3ad..0000000 --- a/.venv/lib/python3.12/site-packages/h11/_events.py +++ /dev/null @@ -1,369 +0,0 @@ -# High level events that make up HTTP/1.1 conversations. Loosely inspired by -# the corresponding events in hyper-h2: -# -# http://python-hyper.org/h2/en/stable/api.html#events -# -# Don't subclass these. Stuff will break. - -import re -from abc import ABC -from dataclasses import dataclass -from typing import List, Tuple, Union - -from ._abnf import method, request_target -from ._headers import Headers, normalize_and_validate -from ._util import bytesify, LocalProtocolError, validate - -# Everything in __all__ gets re-exported as part of the h11 public API. -__all__ = [ - "Event", - "Request", - "InformationalResponse", - "Response", - "Data", - "EndOfMessage", - "ConnectionClosed", -] - -method_re = re.compile(method.encode("ascii")) -request_target_re = re.compile(request_target.encode("ascii")) - - -class Event(ABC): - """ - Base class for h11 events. - """ - - __slots__ = () - - -@dataclass(init=False, frozen=True) -class Request(Event): - """The beginning of an HTTP request. - - Fields: - - .. attribute:: method - - An HTTP method, e.g. ``b"GET"`` or ``b"POST"``. Always a byte - string. :term:`Bytes-like objects ` and native - strings containing only ascii characters will be automatically - converted to byte strings. - - .. attribute:: target - - The target of an HTTP request, e.g. ``b"/index.html"``, or one of the - more exotic formats described in `RFC 7320, section 5.3 - `_. Always a byte - string. :term:`Bytes-like objects ` and native - strings containing only ascii characters will be automatically - converted to byte strings. - - .. attribute:: headers - - Request headers, represented as a list of (name, value) pairs. See - :ref:`the header normalization rules ` for details. - - .. attribute:: http_version - - The HTTP protocol version, represented as a byte string like - ``b"1.1"``. See :ref:`the HTTP version normalization rules - ` for details. - - """ - - __slots__ = ("method", "headers", "target", "http_version") - - method: bytes - headers: Headers - target: bytes - http_version: bytes - - def __init__( - self, - *, - method: Union[bytes, str], - headers: Union[Headers, List[Tuple[bytes, bytes]], List[Tuple[str, str]]], - target: Union[bytes, str], - http_version: Union[bytes, str] = b"1.1", - _parsed: bool = False, - ) -> None: - super().__init__() - if isinstance(headers, Headers): - object.__setattr__(self, "headers", headers) - else: - object.__setattr__( - self, "headers", normalize_and_validate(headers, _parsed=_parsed) - ) - if not _parsed: - object.__setattr__(self, "method", bytesify(method)) - object.__setattr__(self, "target", bytesify(target)) - object.__setattr__(self, "http_version", bytesify(http_version)) - else: - object.__setattr__(self, "method", method) - object.__setattr__(self, "target", target) - object.__setattr__(self, "http_version", http_version) - - # "A server MUST respond with a 400 (Bad Request) status code to any - # HTTP/1.1 request message that lacks a Host header field and to any - # request message that contains more than one Host header field or a - # Host header field with an invalid field-value." - # -- https://tools.ietf.org/html/rfc7230#section-5.4 - host_count = 0 - for name, value in self.headers: - if name == b"host": - host_count += 1 - if self.http_version == b"1.1" and host_count == 0: - raise LocalProtocolError("Missing mandatory Host: header") - if host_count > 1: - raise LocalProtocolError("Found multiple Host: headers") - - validate(method_re, self.method, "Illegal method characters") - validate(request_target_re, self.target, "Illegal target characters") - - # This is an unhashable type. - __hash__ = None # type: ignore - - -@dataclass(init=False, frozen=True) -class _ResponseBase(Event): - __slots__ = ("headers", "http_version", "reason", "status_code") - - headers: Headers - http_version: bytes - reason: bytes - status_code: int - - def __init__( - self, - *, - headers: Union[Headers, List[Tuple[bytes, bytes]], List[Tuple[str, str]]], - status_code: int, - http_version: Union[bytes, str] = b"1.1", - reason: Union[bytes, str] = b"", - _parsed: bool = False, - ) -> None: - super().__init__() - if isinstance(headers, Headers): - object.__setattr__(self, "headers", headers) - else: - object.__setattr__( - self, "headers", normalize_and_validate(headers, _parsed=_parsed) - ) - if not _parsed: - object.__setattr__(self, "reason", bytesify(reason)) - object.__setattr__(self, "http_version", bytesify(http_version)) - if not isinstance(status_code, int): - raise LocalProtocolError("status code must be integer") - # Because IntEnum objects are instances of int, but aren't - # duck-compatible (sigh), see gh-72. - object.__setattr__(self, "status_code", int(status_code)) - else: - object.__setattr__(self, "reason", reason) - object.__setattr__(self, "http_version", http_version) - object.__setattr__(self, "status_code", status_code) - - self.__post_init__() - - def __post_init__(self) -> None: - pass - - # This is an unhashable type. - __hash__ = None # type: ignore - - -@dataclass(init=False, frozen=True) -class InformationalResponse(_ResponseBase): - """An HTTP informational response. - - Fields: - - .. attribute:: status_code - - The status code of this response, as an integer. For an - :class:`InformationalResponse`, this is always in the range [100, - 200). - - .. attribute:: headers - - Request headers, represented as a list of (name, value) pairs. See - :ref:`the header normalization rules ` for - details. - - .. attribute:: http_version - - The HTTP protocol version, represented as a byte string like - ``b"1.1"``. See :ref:`the HTTP version normalization rules - ` for details. - - .. attribute:: reason - - The reason phrase of this response, as a byte string. For example: - ``b"OK"``, or ``b"Not Found"``. - - """ - - def __post_init__(self) -> None: - if not (100 <= self.status_code < 200): - raise LocalProtocolError( - "InformationalResponse status_code should be in range " - "[100, 200), not {}".format(self.status_code) - ) - - # This is an unhashable type. - __hash__ = None # type: ignore - - -@dataclass(init=False, frozen=True) -class Response(_ResponseBase): - """The beginning of an HTTP response. - - Fields: - - .. attribute:: status_code - - The status code of this response, as an integer. For an - :class:`Response`, this is always in the range [200, - 1000). - - .. attribute:: headers - - Request headers, represented as a list of (name, value) pairs. See - :ref:`the header normalization rules ` for details. - - .. attribute:: http_version - - The HTTP protocol version, represented as a byte string like - ``b"1.1"``. See :ref:`the HTTP version normalization rules - ` for details. - - .. attribute:: reason - - The reason phrase of this response, as a byte string. For example: - ``b"OK"``, or ``b"Not Found"``. - - """ - - def __post_init__(self) -> None: - if not (200 <= self.status_code < 1000): - raise LocalProtocolError( - "Response status_code should be in range [200, 1000), not {}".format( - self.status_code - ) - ) - - # This is an unhashable type. - __hash__ = None # type: ignore - - -@dataclass(init=False, frozen=True) -class Data(Event): - """Part of an HTTP message body. - - Fields: - - .. attribute:: data - - A :term:`bytes-like object` containing part of a message body. Or, if - using the ``combine=False`` argument to :meth:`Connection.send`, then - any object that your socket writing code knows what to do with, and for - which calling :func:`len` returns the number of bytes that will be - written -- see :ref:`sendfile` for details. - - .. attribute:: chunk_start - - A marker that indicates whether this data object is from the start of a - chunked transfer encoding chunk. This field is ignored when when a Data - event is provided to :meth:`Connection.send`: it is only valid on - events emitted from :meth:`Connection.next_event`. You probably - shouldn't use this attribute at all; see - :ref:`chunk-delimiters-are-bad` for details. - - .. attribute:: chunk_end - - A marker that indicates whether this data object is the last for a - given chunked transfer encoding chunk. This field is ignored when when - a Data event is provided to :meth:`Connection.send`: it is only valid - on events emitted from :meth:`Connection.next_event`. You probably - shouldn't use this attribute at all; see - :ref:`chunk-delimiters-are-bad` for details. - - """ - - __slots__ = ("data", "chunk_start", "chunk_end") - - data: bytes - chunk_start: bool - chunk_end: bool - - def __init__( - self, data: bytes, chunk_start: bool = False, chunk_end: bool = False - ) -> None: - object.__setattr__(self, "data", data) - object.__setattr__(self, "chunk_start", chunk_start) - object.__setattr__(self, "chunk_end", chunk_end) - - # This is an unhashable type. - __hash__ = None # type: ignore - - -# XX FIXME: "A recipient MUST ignore (or consider as an error) any fields that -# are forbidden to be sent in a trailer, since processing them as if they were -# present in the header section might bypass external security filters." -# https://svn.tools.ietf.org/svn/wg/httpbis/specs/rfc7230.html#chunked.trailer.part -# Unfortunately, the list of forbidden fields is long and vague :-/ -@dataclass(init=False, frozen=True) -class EndOfMessage(Event): - """The end of an HTTP message. - - Fields: - - .. attribute:: headers - - Default value: ``[]`` - - Any trailing headers attached to this message, represented as a list of - (name, value) pairs. See :ref:`the header normalization rules - ` for details. - - Must be empty unless ``Transfer-Encoding: chunked`` is in use. - - """ - - __slots__ = ("headers",) - - headers: Headers - - def __init__( - self, - *, - headers: Union[ - Headers, List[Tuple[bytes, bytes]], List[Tuple[str, str]], None - ] = None, - _parsed: bool = False, - ) -> None: - super().__init__() - if headers is None: - headers = Headers([]) - elif not isinstance(headers, Headers): - headers = normalize_and_validate(headers, _parsed=_parsed) - - object.__setattr__(self, "headers", headers) - - # This is an unhashable type. - __hash__ = None # type: ignore - - -@dataclass(frozen=True) -class ConnectionClosed(Event): - """This event indicates that the sender has closed their outgoing - connection. - - Note that this does not necessarily mean that they can't *receive* further - data, because TCP connections are composed to two one-way channels which - can be closed independently. See :ref:`closing` for details. - - No fields. - """ - - pass diff --git a/.venv/lib/python3.12/site-packages/h11/_headers.py b/.venv/lib/python3.12/site-packages/h11/_headers.py deleted file mode 100644 index 31da3e2..0000000 --- a/.venv/lib/python3.12/site-packages/h11/_headers.py +++ /dev/null @@ -1,282 +0,0 @@ -import re -from typing import AnyStr, cast, List, overload, Sequence, Tuple, TYPE_CHECKING, Union - -from ._abnf import field_name, field_value -from ._util import bytesify, LocalProtocolError, validate - -if TYPE_CHECKING: - from ._events import Request - -try: - from typing import Literal -except ImportError: - from typing_extensions import Literal # type: ignore - -CONTENT_LENGTH_MAX_DIGITS = 20 # allow up to 1 billion TB - 1 - - -# Facts -# ----- -# -# Headers are: -# keys: case-insensitive ascii -# values: mixture of ascii and raw bytes -# -# "Historically, HTTP has allowed field content with text in the ISO-8859-1 -# charset [ISO-8859-1], supporting other charsets only through use of -# [RFC2047] encoding. In practice, most HTTP header field values use only a -# subset of the US-ASCII charset [USASCII]. Newly defined header fields SHOULD -# limit their field values to US-ASCII octets. A recipient SHOULD treat other -# octets in field content (obs-text) as opaque data." -# And it deprecates all non-ascii values -# -# Leading/trailing whitespace in header names is forbidden -# -# Values get leading/trailing whitespace stripped -# -# Content-Disposition actually needs to contain unicode semantically; to -# accomplish this it has a terrifically weird way of encoding the filename -# itself as ascii (and even this still has lots of cross-browser -# incompatibilities) -# -# Order is important: -# "a proxy MUST NOT change the order of these field values when forwarding a -# message" -# (and there are several headers where the order indicates a preference) -# -# Multiple occurences of the same header: -# "A sender MUST NOT generate multiple header fields with the same field name -# in a message unless either the entire field value for that header field is -# defined as a comma-separated list [or the header is Set-Cookie which gets a -# special exception]" - RFC 7230. (cookies are in RFC 6265) -# -# So every header aside from Set-Cookie can be merged by b", ".join if it -# occurs repeatedly. But, of course, they can't necessarily be split by -# .split(b","), because quoting. -# -# Given all this mess (case insensitive, duplicates allowed, order is -# important, ...), there doesn't appear to be any standard way to handle -# headers in Python -- they're almost like dicts, but... actually just -# aren't. For now we punt and just use a super simple representation: headers -# are a list of pairs -# -# [(name1, value1), (name2, value2), ...] -# -# where all entries are bytestrings, names are lowercase and have no -# leading/trailing whitespace, and values are bytestrings with no -# leading/trailing whitespace. Searching and updating are done via naive O(n) -# methods. -# -# Maybe a dict-of-lists would be better? - -_content_length_re = re.compile(rb"[0-9]+") -_field_name_re = re.compile(field_name.encode("ascii")) -_field_value_re = re.compile(field_value.encode("ascii")) - - -class Headers(Sequence[Tuple[bytes, bytes]]): - """ - A list-like interface that allows iterating over headers as byte-pairs - of (lowercased-name, value). - - Internally we actually store the representation as three-tuples, - including both the raw original casing, in order to preserve casing - over-the-wire, and the lowercased name, for case-insensitive comparisions. - - r = Request( - method="GET", - target="/", - headers=[("Host", "example.org"), ("Connection", "keep-alive")], - http_version="1.1", - ) - assert r.headers == [ - (b"host", b"example.org"), - (b"connection", b"keep-alive") - ] - assert r.headers.raw_items() == [ - (b"Host", b"example.org"), - (b"Connection", b"keep-alive") - ] - """ - - __slots__ = "_full_items" - - def __init__(self, full_items: List[Tuple[bytes, bytes, bytes]]) -> None: - self._full_items = full_items - - def __bool__(self) -> bool: - return bool(self._full_items) - - def __eq__(self, other: object) -> bool: - return list(self) == list(other) # type: ignore - - def __len__(self) -> int: - return len(self._full_items) - - def __repr__(self) -> str: - return "" % repr(list(self)) - - def __getitem__(self, idx: int) -> Tuple[bytes, bytes]: # type: ignore[override] - _, name, value = self._full_items[idx] - return (name, value) - - def raw_items(self) -> List[Tuple[bytes, bytes]]: - return [(raw_name, value) for raw_name, _, value in self._full_items] - - -HeaderTypes = Union[ - List[Tuple[bytes, bytes]], - List[Tuple[bytes, str]], - List[Tuple[str, bytes]], - List[Tuple[str, str]], -] - - -@overload -def normalize_and_validate(headers: Headers, _parsed: Literal[True]) -> Headers: - ... - - -@overload -def normalize_and_validate(headers: HeaderTypes, _parsed: Literal[False]) -> Headers: - ... - - -@overload -def normalize_and_validate( - headers: Union[Headers, HeaderTypes], _parsed: bool = False -) -> Headers: - ... - - -def normalize_and_validate( - headers: Union[Headers, HeaderTypes], _parsed: bool = False -) -> Headers: - new_headers = [] - seen_content_length = None - saw_transfer_encoding = False - for name, value in headers: - # For headers coming out of the parser, we can safely skip some steps, - # because it always returns bytes and has already run these regexes - # over the data: - if not _parsed: - name = bytesify(name) - value = bytesify(value) - validate(_field_name_re, name, "Illegal header name {!r}", name) - validate(_field_value_re, value, "Illegal header value {!r}", value) - assert isinstance(name, bytes) - assert isinstance(value, bytes) - - raw_name = name - name = name.lower() - if name == b"content-length": - lengths = {length.strip() for length in value.split(b",")} - if len(lengths) != 1: - raise LocalProtocolError("conflicting Content-Length headers") - value = lengths.pop() - validate(_content_length_re, value, "bad Content-Length") - if len(value) > CONTENT_LENGTH_MAX_DIGITS: - raise LocalProtocolError("bad Content-Length") - if seen_content_length is None: - seen_content_length = value - new_headers.append((raw_name, name, value)) - elif seen_content_length != value: - raise LocalProtocolError("conflicting Content-Length headers") - elif name == b"transfer-encoding": - # "A server that receives a request message with a transfer coding - # it does not understand SHOULD respond with 501 (Not - # Implemented)." - # https://tools.ietf.org/html/rfc7230#section-3.3.1 - if saw_transfer_encoding: - raise LocalProtocolError( - "multiple Transfer-Encoding headers", error_status_hint=501 - ) - # "All transfer-coding names are case-insensitive" - # -- https://tools.ietf.org/html/rfc7230#section-4 - value = value.lower() - if value != b"chunked": - raise LocalProtocolError( - "Only Transfer-Encoding: chunked is supported", - error_status_hint=501, - ) - saw_transfer_encoding = True - new_headers.append((raw_name, name, value)) - else: - new_headers.append((raw_name, name, value)) - return Headers(new_headers) - - -def get_comma_header(headers: Headers, name: bytes) -> List[bytes]: - # Should only be used for headers whose value is a list of - # comma-separated, case-insensitive values. - # - # The header name `name` is expected to be lower-case bytes. - # - # Connection: meets these criteria (including cast insensitivity). - # - # Content-Length: technically is just a single value (1*DIGIT), but the - # standard makes reference to implementations that do multiple values, and - # using this doesn't hurt. Ditto, case insensitivity doesn't things either - # way. - # - # Transfer-Encoding: is more complex (allows for quoted strings), so - # splitting on , is actually wrong. For example, this is legal: - # - # Transfer-Encoding: foo; options="1,2", chunked - # - # and should be parsed as - # - # foo; options="1,2" - # chunked - # - # but this naive function will parse it as - # - # foo; options="1 - # 2" - # chunked - # - # However, this is okay because the only thing we are going to do with - # any Transfer-Encoding is reject ones that aren't just "chunked", so - # both of these will be treated the same anyway. - # - # Expect: the only legal value is the literal string - # "100-continue". Splitting on commas is harmless. Case insensitive. - # - out: List[bytes] = [] - for _, found_name, found_raw_value in headers._full_items: - if found_name == name: - found_raw_value = found_raw_value.lower() - for found_split_value in found_raw_value.split(b","): - found_split_value = found_split_value.strip() - if found_split_value: - out.append(found_split_value) - return out - - -def set_comma_header(headers: Headers, name: bytes, new_values: List[bytes]) -> Headers: - # The header name `name` is expected to be lower-case bytes. - # - # Note that when we store the header we use title casing for the header - # names, in order to match the conventional HTTP header style. - # - # Simply calling `.title()` is a blunt approach, but it's correct - # here given the cases where we're using `set_comma_header`... - # - # Connection, Content-Length, Transfer-Encoding. - new_headers: List[Tuple[bytes, bytes]] = [] - for found_raw_name, found_name, found_raw_value in headers._full_items: - if found_name != name: - new_headers.append((found_raw_name, found_raw_value)) - for new_value in new_values: - new_headers.append((name.title(), new_value)) - return normalize_and_validate(new_headers) - - -def has_expect_100_continue(request: "Request") -> bool: - # https://tools.ietf.org/html/rfc7231#section-5.1.1 - # "A server that receives a 100-continue expectation in an HTTP/1.0 request - # MUST ignore that expectation." - if request.http_version < b"1.1": - return False - expect = get_comma_header(request.headers, b"expect") - return b"100-continue" in expect diff --git a/.venv/lib/python3.12/site-packages/h11/_readers.py b/.venv/lib/python3.12/site-packages/h11/_readers.py deleted file mode 100644 index 576804c..0000000 --- a/.venv/lib/python3.12/site-packages/h11/_readers.py +++ /dev/null @@ -1,250 +0,0 @@ -# Code to read HTTP data -# -# Strategy: each reader is a callable which takes a ReceiveBuffer object, and -# either: -# 1) consumes some of it and returns an Event -# 2) raises a LocalProtocolError (for consistency -- e.g. we call validate() -# and it might raise a LocalProtocolError, so simpler just to always use -# this) -# 3) returns None, meaning "I need more data" -# -# If they have a .read_eof attribute, then this will be called if an EOF is -# received -- but this is optional. Either way, the actual ConnectionClosed -# event will be generated afterwards. -# -# READERS is a dict describing how to pick a reader. It maps states to either: -# - a reader -# - or, for body readers, a dict of per-framing reader factories - -import re -from typing import Any, Callable, Dict, Iterable, NoReturn, Optional, Tuple, Type, Union - -from ._abnf import chunk_header, header_field, request_line, status_line -from ._events import Data, EndOfMessage, InformationalResponse, Request, Response -from ._receivebuffer import ReceiveBuffer -from ._state import ( - CLIENT, - CLOSED, - DONE, - IDLE, - MUST_CLOSE, - SEND_BODY, - SEND_RESPONSE, - SERVER, -) -from ._util import LocalProtocolError, RemoteProtocolError, Sentinel, validate - -__all__ = ["READERS"] - -header_field_re = re.compile(header_field.encode("ascii")) -obs_fold_re = re.compile(rb"[ \t]+") - - -def _obsolete_line_fold(lines: Iterable[bytes]) -> Iterable[bytes]: - it = iter(lines) - last: Optional[bytes] = None - for line in it: - match = obs_fold_re.match(line) - if match: - if last is None: - raise LocalProtocolError("continuation line at start of headers") - if not isinstance(last, bytearray): - # Cast to a mutable type, avoiding copy on append to ensure O(n) time - last = bytearray(last) - last += b" " - last += line[match.end() :] - else: - if last is not None: - yield last - last = line - if last is not None: - yield last - - -def _decode_header_lines( - lines: Iterable[bytes], -) -> Iterable[Tuple[bytes, bytes]]: - for line in _obsolete_line_fold(lines): - matches = validate(header_field_re, line, "illegal header line: {!r}", line) - yield (matches["field_name"], matches["field_value"]) - - -request_line_re = re.compile(request_line.encode("ascii")) - - -def maybe_read_from_IDLE_client(buf: ReceiveBuffer) -> Optional[Request]: - lines = buf.maybe_extract_lines() - if lines is None: - if buf.is_next_line_obviously_invalid_request_line(): - raise LocalProtocolError("illegal request line") - return None - if not lines: - raise LocalProtocolError("no request line received") - matches = validate( - request_line_re, lines[0], "illegal request line: {!r}", lines[0] - ) - return Request( - headers=list(_decode_header_lines(lines[1:])), _parsed=True, **matches - ) - - -status_line_re = re.compile(status_line.encode("ascii")) - - -def maybe_read_from_SEND_RESPONSE_server( - buf: ReceiveBuffer, -) -> Union[InformationalResponse, Response, None]: - lines = buf.maybe_extract_lines() - if lines is None: - if buf.is_next_line_obviously_invalid_request_line(): - raise LocalProtocolError("illegal request line") - return None - if not lines: - raise LocalProtocolError("no response line received") - matches = validate(status_line_re, lines[0], "illegal status line: {!r}", lines[0]) - http_version = ( - b"1.1" if matches["http_version"] is None else matches["http_version"] - ) - reason = b"" if matches["reason"] is None else matches["reason"] - status_code = int(matches["status_code"]) - class_: Union[Type[InformationalResponse], Type[Response]] = ( - InformationalResponse if status_code < 200 else Response - ) - return class_( - headers=list(_decode_header_lines(lines[1:])), - _parsed=True, - status_code=status_code, - reason=reason, - http_version=http_version, - ) - - -class ContentLengthReader: - def __init__(self, length: int) -> None: - self._length = length - self._remaining = length - - def __call__(self, buf: ReceiveBuffer) -> Union[Data, EndOfMessage, None]: - if self._remaining == 0: - return EndOfMessage() - data = buf.maybe_extract_at_most(self._remaining) - if data is None: - return None - self._remaining -= len(data) - return Data(data=data) - - def read_eof(self) -> NoReturn: - raise RemoteProtocolError( - "peer closed connection without sending complete message body " - "(received {} bytes, expected {})".format( - self._length - self._remaining, self._length - ) - ) - - -chunk_header_re = re.compile(chunk_header.encode("ascii")) - - -class ChunkedReader: - def __init__(self) -> None: - self._bytes_in_chunk = 0 - # After reading a chunk, we have to throw away the trailing \r\n. - # This tracks the bytes that we need to match and throw away. - self._bytes_to_discard = b"" - self._reading_trailer = False - - def __call__(self, buf: ReceiveBuffer) -> Union[Data, EndOfMessage, None]: - if self._reading_trailer: - lines = buf.maybe_extract_lines() - if lines is None: - return None - return EndOfMessage(headers=list(_decode_header_lines(lines))) - if self._bytes_to_discard: - data = buf.maybe_extract_at_most(len(self._bytes_to_discard)) - if data is None: - return None - if data != self._bytes_to_discard[: len(data)]: - raise LocalProtocolError( - f"malformed chunk footer: {data!r} (expected {self._bytes_to_discard!r})" - ) - self._bytes_to_discard = self._bytes_to_discard[len(data) :] - if self._bytes_to_discard: - return None - # else, fall through and read some more - assert self._bytes_to_discard == b"" - if self._bytes_in_chunk == 0: - # We need to refill our chunk count - chunk_header = buf.maybe_extract_next_line() - if chunk_header is None: - return None - matches = validate( - chunk_header_re, - chunk_header, - "illegal chunk header: {!r}", - chunk_header, - ) - # XX FIXME: we discard chunk extensions. Does anyone care? - self._bytes_in_chunk = int(matches["chunk_size"], base=16) - if self._bytes_in_chunk == 0: - self._reading_trailer = True - return self(buf) - chunk_start = True - else: - chunk_start = False - assert self._bytes_in_chunk > 0 - data = buf.maybe_extract_at_most(self._bytes_in_chunk) - if data is None: - return None - self._bytes_in_chunk -= len(data) - if self._bytes_in_chunk == 0: - self._bytes_to_discard = b"\r\n" - chunk_end = True - else: - chunk_end = False - return Data(data=data, chunk_start=chunk_start, chunk_end=chunk_end) - - def read_eof(self) -> NoReturn: - raise RemoteProtocolError( - "peer closed connection without sending complete message body " - "(incomplete chunked read)" - ) - - -class Http10Reader: - def __call__(self, buf: ReceiveBuffer) -> Optional[Data]: - data = buf.maybe_extract_at_most(999999999) - if data is None: - return None - return Data(data=data) - - def read_eof(self) -> EndOfMessage: - return EndOfMessage() - - -def expect_nothing(buf: ReceiveBuffer) -> None: - if buf: - raise LocalProtocolError("Got data when expecting EOF") - return None - - -ReadersType = Dict[ - Union[Type[Sentinel], Tuple[Type[Sentinel], Type[Sentinel]]], - Union[Callable[..., Any], Dict[str, Callable[..., Any]]], -] - -READERS: ReadersType = { - (CLIENT, IDLE): maybe_read_from_IDLE_client, - (SERVER, IDLE): maybe_read_from_SEND_RESPONSE_server, - (SERVER, SEND_RESPONSE): maybe_read_from_SEND_RESPONSE_server, - (CLIENT, DONE): expect_nothing, - (CLIENT, MUST_CLOSE): expect_nothing, - (CLIENT, CLOSED): expect_nothing, - (SERVER, DONE): expect_nothing, - (SERVER, MUST_CLOSE): expect_nothing, - (SERVER, CLOSED): expect_nothing, - SEND_BODY: { - "chunked": ChunkedReader, - "content-length": ContentLengthReader, - "http/1.0": Http10Reader, - }, -} diff --git a/.venv/lib/python3.12/site-packages/h11/_receivebuffer.py b/.venv/lib/python3.12/site-packages/h11/_receivebuffer.py deleted file mode 100644 index e5c4e08..0000000 --- a/.venv/lib/python3.12/site-packages/h11/_receivebuffer.py +++ /dev/null @@ -1,153 +0,0 @@ -import re -import sys -from typing import List, Optional, Union - -__all__ = ["ReceiveBuffer"] - - -# Operations we want to support: -# - find next \r\n or \r\n\r\n (\n or \n\n are also acceptable), -# or wait until there is one -# - read at-most-N bytes -# Goals: -# - on average, do this fast -# - worst case, do this in O(n) where n is the number of bytes processed -# Plan: -# - store bytearray, offset, how far we've searched for a separator token -# - use the how-far-we've-searched data to avoid rescanning -# - while doing a stream of uninterrupted processing, advance offset instead -# of constantly copying -# WARNING: -# - I haven't benchmarked or profiled any of this yet. -# -# Note that starting in Python 3.4, deleting the initial n bytes from a -# bytearray is amortized O(n), thanks to some excellent work by Antoine -# Martin: -# -# https://bugs.python.org/issue19087 -# -# This means that if we only supported 3.4+, we could get rid of the code here -# involving self._start and self.compress, because it's doing exactly the same -# thing that bytearray now does internally. -# -# BUT unfortunately, we still support 2.7, and reading short segments out of a -# long buffer MUST be O(bytes read) to avoid DoS issues, so we can't actually -# delete this code. Yet: -# -# https://pythonclock.org/ -# -# (Two things to double-check first though: make sure PyPy also has the -# optimization, and benchmark to make sure it's a win, since we do have a -# slightly clever thing where we delay calling compress() until we've -# processed a whole event, which could in theory be slightly more efficient -# than the internal bytearray support.) -blank_line_regex = re.compile(b"\n\r?\n", re.MULTILINE) - - -class ReceiveBuffer: - def __init__(self) -> None: - self._data = bytearray() - self._next_line_search = 0 - self._multiple_lines_search = 0 - - def __iadd__(self, byteslike: Union[bytes, bytearray]) -> "ReceiveBuffer": - self._data += byteslike - return self - - def __bool__(self) -> bool: - return bool(len(self)) - - def __len__(self) -> int: - return len(self._data) - - # for @property unprocessed_data - def __bytes__(self) -> bytes: - return bytes(self._data) - - def _extract(self, count: int) -> bytearray: - # extracting an initial slice of the data buffer and return it - out = self._data[:count] - del self._data[:count] - - self._next_line_search = 0 - self._multiple_lines_search = 0 - - return out - - def maybe_extract_at_most(self, count: int) -> Optional[bytearray]: - """ - Extract a fixed number of bytes from the buffer. - """ - out = self._data[:count] - if not out: - return None - - return self._extract(count) - - def maybe_extract_next_line(self) -> Optional[bytearray]: - """ - Extract the first line, if it is completed in the buffer. - """ - # Only search in buffer space that we've not already looked at. - search_start_index = max(0, self._next_line_search - 1) - partial_idx = self._data.find(b"\r\n", search_start_index) - - if partial_idx == -1: - self._next_line_search = len(self._data) - return None - - # + 2 is to compensate len(b"\r\n") - idx = partial_idx + 2 - - return self._extract(idx) - - def maybe_extract_lines(self) -> Optional[List[bytearray]]: - """ - Extract everything up to the first blank line, and return a list of lines. - """ - # Handle the case where we have an immediate empty line. - if self._data[:1] == b"\n": - self._extract(1) - return [] - - if self._data[:2] == b"\r\n": - self._extract(2) - return [] - - # Only search in buffer space that we've not already looked at. - match = blank_line_regex.search(self._data, self._multiple_lines_search) - if match is None: - self._multiple_lines_search = max(0, len(self._data) - 2) - return None - - # Truncate the buffer and return it. - idx = match.span(0)[-1] - out = self._extract(idx) - lines = out.split(b"\n") - - for line in lines: - if line.endswith(b"\r"): - del line[-1] - - assert lines[-2] == lines[-1] == b"" - - del lines[-2:] - - return lines - - # In theory we should wait until `\r\n` before starting to validate - # incoming data. However it's interesting to detect (very) invalid data - # early given they might not even contain `\r\n` at all (hence only - # timeout will get rid of them). - # This is not a 100% effective detection but more of a cheap sanity check - # allowing for early abort in some useful cases. - # This is especially interesting when peer is messing up with HTTPS and - # sent us a TLS stream where we were expecting plain HTTP given all - # versions of TLS so far start handshake with a 0x16 message type code. - def is_next_line_obviously_invalid_request_line(self) -> bool: - try: - # HTTP header line must not contain non-printable characters - # and should not start with a space - return self._data[0] < 0x21 - except IndexError: - return False diff --git a/.venv/lib/python3.12/site-packages/h11/_state.py b/.venv/lib/python3.12/site-packages/h11/_state.py deleted file mode 100644 index 3ad444b..0000000 --- a/.venv/lib/python3.12/site-packages/h11/_state.py +++ /dev/null @@ -1,365 +0,0 @@ -################################################################ -# The core state machine -################################################################ -# -# Rule 1: everything that affects the state machine and state transitions must -# live here in this file. As much as possible goes into the table-based -# representation, but for the bits that don't quite fit, the actual code and -# state must nonetheless live here. -# -# Rule 2: this file does not know about what role we're playing; it only knows -# about HTTP request/response cycles in the abstract. This ensures that we -# don't cheat and apply different rules to local and remote parties. -# -# -# Theory of operation -# =================== -# -# Possibly the simplest way to think about this is that we actually have 5 -# different state machines here. Yes, 5. These are: -# -# 1) The client state, with its complicated automaton (see the docs) -# 2) The server state, with its complicated automaton (see the docs) -# 3) The keep-alive state, with possible states {True, False} -# 4) The SWITCH_CONNECT state, with possible states {False, True} -# 5) The SWITCH_UPGRADE state, with possible states {False, True} -# -# For (3)-(5), the first state listed is the initial state. -# -# (1)-(3) are stored explicitly in member variables. The last -# two are stored implicitly in the pending_switch_proposals set as: -# (state of 4) == (_SWITCH_CONNECT in pending_switch_proposals) -# (state of 5) == (_SWITCH_UPGRADE in pending_switch_proposals) -# -# And each of these machines has two different kinds of transitions: -# -# a) Event-triggered -# b) State-triggered -# -# Event triggered is the obvious thing that you'd think it is: some event -# happens, and if it's the right event at the right time then a transition -# happens. But there are somewhat complicated rules for which machines can -# "see" which events. (As a rule of thumb, if a machine "sees" an event, this -# means two things: the event can affect the machine, and if the machine is -# not in a state where it expects that event then it's an error.) These rules -# are: -# -# 1) The client machine sees all h11.events objects emitted by the client. -# -# 2) The server machine sees all h11.events objects emitted by the server. -# -# It also sees the client's Request event. -# -# And sometimes, server events are annotated with a _SWITCH_* event. For -# example, we can have a (Response, _SWITCH_CONNECT) event, which is -# different from a regular Response event. -# -# 3) The keep-alive machine sees the process_keep_alive_disabled() event -# (which is derived from Request/Response events), and this event -# transitions it from True -> False, or from False -> False. There's no way -# to transition back. -# -# 4&5) The _SWITCH_* machines transition from False->True when we get a -# Request that proposes the relevant type of switch (via -# process_client_switch_proposals), and they go from True->False when we -# get a Response that has no _SWITCH_* annotation. -# -# So that's event-triggered transitions. -# -# State-triggered transitions are less standard. What they do here is couple -# the machines together. The way this works is, when certain *joint* -# configurations of states are achieved, then we automatically transition to a -# new *joint* state. So, for example, if we're ever in a joint state with -# -# client: DONE -# keep-alive: False -# -# then the client state immediately transitions to: -# -# client: MUST_CLOSE -# -# This is fundamentally different from an event-based transition, because it -# doesn't matter how we arrived at the {client: DONE, keep-alive: False} state -# -- maybe the client transitioned SEND_BODY -> DONE, or keep-alive -# transitioned True -> False. Either way, once this precondition is satisfied, -# this transition is immediately triggered. -# -# What if two conflicting state-based transitions get enabled at the same -# time? In practice there's only one case where this arises (client DONE -> -# MIGHT_SWITCH_PROTOCOL versus DONE -> MUST_CLOSE), and we resolve it by -# explicitly prioritizing the DONE -> MIGHT_SWITCH_PROTOCOL transition. -# -# Implementation -# -------------- -# -# The event-triggered transitions for the server and client machines are all -# stored explicitly in a table. Ditto for the state-triggered transitions that -# involve just the server and client state. -# -# The transitions for the other machines, and the state-triggered transitions -# that involve the other machines, are written out as explicit Python code. -# -# It'd be nice if there were some cleaner way to do all this. This isn't -# *too* terrible, but I feel like it could probably be better. -# -# WARNING -# ------- -# -# The script that generates the state machine diagrams for the docs knows how -# to read out the EVENT_TRIGGERED_TRANSITIONS and STATE_TRIGGERED_TRANSITIONS -# tables. But it can't automatically read the transitions that are written -# directly in Python code. So if you touch those, you need to also update the -# script to keep it in sync! -from typing import cast, Dict, Optional, Set, Tuple, Type, Union - -from ._events import * -from ._util import LocalProtocolError, Sentinel - -# Everything in __all__ gets re-exported as part of the h11 public API. -__all__ = [ - "CLIENT", - "SERVER", - "IDLE", - "SEND_RESPONSE", - "SEND_BODY", - "DONE", - "MUST_CLOSE", - "CLOSED", - "MIGHT_SWITCH_PROTOCOL", - "SWITCHED_PROTOCOL", - "ERROR", -] - - -class CLIENT(Sentinel, metaclass=Sentinel): - pass - - -class SERVER(Sentinel, metaclass=Sentinel): - pass - - -# States -class IDLE(Sentinel, metaclass=Sentinel): - pass - - -class SEND_RESPONSE(Sentinel, metaclass=Sentinel): - pass - - -class SEND_BODY(Sentinel, metaclass=Sentinel): - pass - - -class DONE(Sentinel, metaclass=Sentinel): - pass - - -class MUST_CLOSE(Sentinel, metaclass=Sentinel): - pass - - -class CLOSED(Sentinel, metaclass=Sentinel): - pass - - -class ERROR(Sentinel, metaclass=Sentinel): - pass - - -# Switch types -class MIGHT_SWITCH_PROTOCOL(Sentinel, metaclass=Sentinel): - pass - - -class SWITCHED_PROTOCOL(Sentinel, metaclass=Sentinel): - pass - - -class _SWITCH_UPGRADE(Sentinel, metaclass=Sentinel): - pass - - -class _SWITCH_CONNECT(Sentinel, metaclass=Sentinel): - pass - - -EventTransitionType = Dict[ - Type[Sentinel], - Dict[ - Type[Sentinel], - Dict[Union[Type[Event], Tuple[Type[Event], Type[Sentinel]]], Type[Sentinel]], - ], -] - -EVENT_TRIGGERED_TRANSITIONS: EventTransitionType = { - CLIENT: { - IDLE: {Request: SEND_BODY, ConnectionClosed: CLOSED}, - SEND_BODY: {Data: SEND_BODY, EndOfMessage: DONE}, - DONE: {ConnectionClosed: CLOSED}, - MUST_CLOSE: {ConnectionClosed: CLOSED}, - CLOSED: {ConnectionClosed: CLOSED}, - MIGHT_SWITCH_PROTOCOL: {}, - SWITCHED_PROTOCOL: {}, - ERROR: {}, - }, - SERVER: { - IDLE: { - ConnectionClosed: CLOSED, - Response: SEND_BODY, - # Special case: server sees client Request events, in this form - (Request, CLIENT): SEND_RESPONSE, - }, - SEND_RESPONSE: { - InformationalResponse: SEND_RESPONSE, - Response: SEND_BODY, - (InformationalResponse, _SWITCH_UPGRADE): SWITCHED_PROTOCOL, - (Response, _SWITCH_CONNECT): SWITCHED_PROTOCOL, - }, - SEND_BODY: {Data: SEND_BODY, EndOfMessage: DONE}, - DONE: {ConnectionClosed: CLOSED}, - MUST_CLOSE: {ConnectionClosed: CLOSED}, - CLOSED: {ConnectionClosed: CLOSED}, - SWITCHED_PROTOCOL: {}, - ERROR: {}, - }, -} - -StateTransitionType = Dict[ - Tuple[Type[Sentinel], Type[Sentinel]], Dict[Type[Sentinel], Type[Sentinel]] -] - -# NB: there are also some special-case state-triggered transitions hard-coded -# into _fire_state_triggered_transitions below. -STATE_TRIGGERED_TRANSITIONS: StateTransitionType = { - # (Client state, Server state) -> new states - # Protocol negotiation - (MIGHT_SWITCH_PROTOCOL, SWITCHED_PROTOCOL): {CLIENT: SWITCHED_PROTOCOL}, - # Socket shutdown - (CLOSED, DONE): {SERVER: MUST_CLOSE}, - (CLOSED, IDLE): {SERVER: MUST_CLOSE}, - (ERROR, DONE): {SERVER: MUST_CLOSE}, - (DONE, CLOSED): {CLIENT: MUST_CLOSE}, - (IDLE, CLOSED): {CLIENT: MUST_CLOSE}, - (DONE, ERROR): {CLIENT: MUST_CLOSE}, -} - - -class ConnectionState: - def __init__(self) -> None: - # Extra bits of state that don't quite fit into the state model. - - # If this is False then it enables the automatic DONE -> MUST_CLOSE - # transition. Don't set this directly; call .keep_alive_disabled() - self.keep_alive = True - - # This is a subset of {UPGRADE, CONNECT}, containing the proposals - # made by the client for switching protocols. - self.pending_switch_proposals: Set[Type[Sentinel]] = set() - - self.states: Dict[Type[Sentinel], Type[Sentinel]] = {CLIENT: IDLE, SERVER: IDLE} - - def process_error(self, role: Type[Sentinel]) -> None: - self.states[role] = ERROR - self._fire_state_triggered_transitions() - - def process_keep_alive_disabled(self) -> None: - self.keep_alive = False - self._fire_state_triggered_transitions() - - def process_client_switch_proposal(self, switch_event: Type[Sentinel]) -> None: - self.pending_switch_proposals.add(switch_event) - self._fire_state_triggered_transitions() - - def process_event( - self, - role: Type[Sentinel], - event_type: Type[Event], - server_switch_event: Optional[Type[Sentinel]] = None, - ) -> None: - _event_type: Union[Type[Event], Tuple[Type[Event], Type[Sentinel]]] = event_type - if server_switch_event is not None: - assert role is SERVER - if server_switch_event not in self.pending_switch_proposals: - raise LocalProtocolError( - "Received server _SWITCH_UPGRADE event without a pending proposal" - ) - _event_type = (event_type, server_switch_event) - if server_switch_event is None and _event_type is Response: - self.pending_switch_proposals = set() - self._fire_event_triggered_transitions(role, _event_type) - # Special case: the server state does get to see Request - # events. - if _event_type is Request: - assert role is CLIENT - self._fire_event_triggered_transitions(SERVER, (Request, CLIENT)) - self._fire_state_triggered_transitions() - - def _fire_event_triggered_transitions( - self, - role: Type[Sentinel], - event_type: Union[Type[Event], Tuple[Type[Event], Type[Sentinel]]], - ) -> None: - state = self.states[role] - try: - new_state = EVENT_TRIGGERED_TRANSITIONS[role][state][event_type] - except KeyError: - event_type = cast(Type[Event], event_type) - raise LocalProtocolError( - "can't handle event type {} when role={} and state={}".format( - event_type.__name__, role, self.states[role] - ) - ) from None - self.states[role] = new_state - - def _fire_state_triggered_transitions(self) -> None: - # We apply these rules repeatedly until converging on a fixed point - while True: - start_states = dict(self.states) - - # It could happen that both these special-case transitions are - # enabled at the same time: - # - # DONE -> MIGHT_SWITCH_PROTOCOL - # DONE -> MUST_CLOSE - # - # For example, this will always be true of a HTTP/1.0 client - # requesting CONNECT. If this happens, the protocol switch takes - # priority. From there the client will either go to - # SWITCHED_PROTOCOL, in which case it's none of our business when - # they close the connection, or else the server will deny the - # request, in which case the client will go back to DONE and then - # from there to MUST_CLOSE. - if self.pending_switch_proposals: - if self.states[CLIENT] is DONE: - self.states[CLIENT] = MIGHT_SWITCH_PROTOCOL - - if not self.pending_switch_proposals: - if self.states[CLIENT] is MIGHT_SWITCH_PROTOCOL: - self.states[CLIENT] = DONE - - if not self.keep_alive: - for role in (CLIENT, SERVER): - if self.states[role] is DONE: - self.states[role] = MUST_CLOSE - - # Tabular state-triggered transitions - joint_state = (self.states[CLIENT], self.states[SERVER]) - changes = STATE_TRIGGERED_TRANSITIONS.get(joint_state, {}) - self.states.update(changes) - - if self.states == start_states: - # Fixed point reached - return - - def start_next_cycle(self) -> None: - if self.states != {CLIENT: DONE, SERVER: DONE}: - raise LocalProtocolError( - f"not in a reusable state. self.states={self.states}" - ) - # Can't reach DONE/DONE with any of these active, but still, let's be - # sure. - assert self.keep_alive - assert not self.pending_switch_proposals - self.states = {CLIENT: IDLE, SERVER: IDLE} diff --git a/.venv/lib/python3.12/site-packages/h11/_util.py b/.venv/lib/python3.12/site-packages/h11/_util.py deleted file mode 100644 index 6718445..0000000 --- a/.venv/lib/python3.12/site-packages/h11/_util.py +++ /dev/null @@ -1,135 +0,0 @@ -from typing import Any, Dict, NoReturn, Pattern, Tuple, Type, TypeVar, Union - -__all__ = [ - "ProtocolError", - "LocalProtocolError", - "RemoteProtocolError", - "validate", - "bytesify", -] - - -class ProtocolError(Exception): - """Exception indicating a violation of the HTTP/1.1 protocol. - - This as an abstract base class, with two concrete base classes: - :exc:`LocalProtocolError`, which indicates that you tried to do something - that HTTP/1.1 says is illegal, and :exc:`RemoteProtocolError`, which - indicates that the remote peer tried to do something that HTTP/1.1 says is - illegal. See :ref:`error-handling` for details. - - In addition to the normal :exc:`Exception` features, it has one attribute: - - .. attribute:: error_status_hint - - This gives a suggestion as to what status code a server might use if - this error occurred as part of a request. - - For a :exc:`RemoteProtocolError`, this is useful as a suggestion for - how you might want to respond to a misbehaving peer, if you're - implementing a server. - - For a :exc:`LocalProtocolError`, this can be taken as a suggestion for - how your peer might have responded to *you* if h11 had allowed you to - continue. - - The default is 400 Bad Request, a generic catch-all for protocol - violations. - - """ - - def __init__(self, msg: str, error_status_hint: int = 400) -> None: - if type(self) is ProtocolError: - raise TypeError("tried to directly instantiate ProtocolError") - Exception.__init__(self, msg) - self.error_status_hint = error_status_hint - - -# Strategy: there are a number of public APIs where a LocalProtocolError can -# be raised (send(), all the different event constructors, ...), and only one -# public API where RemoteProtocolError can be raised -# (receive_data()). Therefore we always raise LocalProtocolError internally, -# and then receive_data will translate this into a RemoteProtocolError. -# -# Internally: -# LocalProtocolError is the generic "ProtocolError". -# Externally: -# LocalProtocolError is for local errors and RemoteProtocolError is for -# remote errors. -class LocalProtocolError(ProtocolError): - def _reraise_as_remote_protocol_error(self) -> NoReturn: - # After catching a LocalProtocolError, use this method to re-raise it - # as a RemoteProtocolError. This method must be called from inside an - # except: block. - # - # An easy way to get an equivalent RemoteProtocolError is just to - # modify 'self' in place. - self.__class__ = RemoteProtocolError # type: ignore - # But the re-raising is somewhat non-trivial -- you might think that - # now that we've modified the in-flight exception object, that just - # doing 'raise' to re-raise it would be enough. But it turns out that - # this doesn't work, because Python tracks the exception type - # (exc_info[0]) separately from the exception object (exc_info[1]), - # and we only modified the latter. So we really do need to re-raise - # the new type explicitly. - # On py3, the traceback is part of the exception object, so our - # in-place modification preserved it and we can just re-raise: - raise self - - -class RemoteProtocolError(ProtocolError): - pass - - -def validate( - regex: Pattern[bytes], data: bytes, msg: str = "malformed data", *format_args: Any -) -> Dict[str, bytes]: - match = regex.fullmatch(data) - if not match: - if format_args: - msg = msg.format(*format_args) - raise LocalProtocolError(msg) - return match.groupdict() - - -# Sentinel values -# -# - Inherit identity-based comparison and hashing from object -# - Have a nice repr -# - Have a *bonus property*: type(sentinel) is sentinel -# -# The bonus property is useful if you want to take the return value from -# next_event() and do some sort of dispatch based on type(event). - -_T_Sentinel = TypeVar("_T_Sentinel", bound="Sentinel") - - -class Sentinel(type): - def __new__( - cls: Type[_T_Sentinel], - name: str, - bases: Tuple[type, ...], - namespace: Dict[str, Any], - **kwds: Any - ) -> _T_Sentinel: - assert bases == (Sentinel,) - v = super().__new__(cls, name, bases, namespace, **kwds) - v.__class__ = v # type: ignore - return v - - def __repr__(self) -> str: - return self.__name__ - - -# Used for methods, request targets, HTTP versions, header names, and header -# values. Accepts ascii-strings, or bytes/bytearray/memoryview/..., and always -# returns bytes. -def bytesify(s: Union[bytes, bytearray, memoryview, int, str]) -> bytes: - # Fast-path: - if type(s) is bytes: - return s - if isinstance(s, str): - s = s.encode("ascii") - if isinstance(s, int): - raise TypeError("expected bytes-like object, not int") - return bytes(s) diff --git a/.venv/lib/python3.12/site-packages/h11/_version.py b/.venv/lib/python3.12/site-packages/h11/_version.py deleted file mode 100644 index 76e7327..0000000 --- a/.venv/lib/python3.12/site-packages/h11/_version.py +++ /dev/null @@ -1,16 +0,0 @@ -# This file must be kept very simple, because it is consumed from several -# places -- it is imported by h11/__init__.py, execfile'd by setup.py, etc. - -# We use a simple scheme: -# 1.0.0 -> 1.0.0+dev -> 1.1.0 -> 1.1.0+dev -# where the +dev versions are never released into the wild, they're just what -# we stick into the VCS in between releases. -# -# This is compatible with PEP 440: -# http://legacy.python.org/dev/peps/pep-0440/ -# via the use of the "local suffix" "+dev", which is disallowed on index -# servers and causes 1.0.0+dev to sort after plain 1.0.0, which is what we -# want. (Contrast with the special suffix 1.0.0.dev, which sorts *before* -# 1.0.0.) - -__version__ = "0.16.0" diff --git a/.venv/lib/python3.12/site-packages/h11/_writers.py b/.venv/lib/python3.12/site-packages/h11/_writers.py deleted file mode 100644 index 939cdb9..0000000 --- a/.venv/lib/python3.12/site-packages/h11/_writers.py +++ /dev/null @@ -1,145 +0,0 @@ -# Code to read HTTP data -# -# Strategy: each writer takes an event + a write-some-bytes function, which is -# calls. -# -# WRITERS is a dict describing how to pick a reader. It maps states to either: -# - a writer -# - or, for body writers, a dict of framin-dependent writer factories - -from typing import Any, Callable, Dict, List, Tuple, Type, Union - -from ._events import Data, EndOfMessage, Event, InformationalResponse, Request, Response -from ._headers import Headers -from ._state import CLIENT, IDLE, SEND_BODY, SEND_RESPONSE, SERVER -from ._util import LocalProtocolError, Sentinel - -__all__ = ["WRITERS"] - -Writer = Callable[[bytes], Any] - - -def write_headers(headers: Headers, write: Writer) -> None: - # "Since the Host field-value is critical information for handling a - # request, a user agent SHOULD generate Host as the first header field - # following the request-line." - RFC 7230 - raw_items = headers._full_items - for raw_name, name, value in raw_items: - if name == b"host": - write(b"%s: %s\r\n" % (raw_name, value)) - for raw_name, name, value in raw_items: - if name != b"host": - write(b"%s: %s\r\n" % (raw_name, value)) - write(b"\r\n") - - -def write_request(request: Request, write: Writer) -> None: - if request.http_version != b"1.1": - raise LocalProtocolError("I only send HTTP/1.1") - write(b"%s %s HTTP/1.1\r\n" % (request.method, request.target)) - write_headers(request.headers, write) - - -# Shared between InformationalResponse and Response -def write_any_response( - response: Union[InformationalResponse, Response], write: Writer -) -> None: - if response.http_version != b"1.1": - raise LocalProtocolError("I only send HTTP/1.1") - status_bytes = str(response.status_code).encode("ascii") - # We don't bother sending ascii status messages like "OK"; they're - # optional and ignored by the protocol. (But the space after the numeric - # status code is mandatory.) - # - # XX FIXME: could at least make an effort to pull out the status message - # from stdlib's http.HTTPStatus table. Or maybe just steal their enums - # (either by import or copy/paste). We already accept them as status codes - # since they're of type IntEnum < int. - write(b"HTTP/1.1 %s %s\r\n" % (status_bytes, response.reason)) - write_headers(response.headers, write) - - -class BodyWriter: - def __call__(self, event: Event, write: Writer) -> None: - if type(event) is Data: - self.send_data(event.data, write) - elif type(event) is EndOfMessage: - self.send_eom(event.headers, write) - else: # pragma: no cover - assert False - - def send_data(self, data: bytes, write: Writer) -> None: - pass - - def send_eom(self, headers: Headers, write: Writer) -> None: - pass - - -# -# These are all careful not to do anything to 'data' except call len(data) and -# write(data). This allows us to transparently pass-through funny objects, -# like placeholder objects referring to files on disk that will be sent via -# sendfile(2). -# -class ContentLengthWriter(BodyWriter): - def __init__(self, length: int) -> None: - self._length = length - - def send_data(self, data: bytes, write: Writer) -> None: - self._length -= len(data) - if self._length < 0: - raise LocalProtocolError("Too much data for declared Content-Length") - write(data) - - def send_eom(self, headers: Headers, write: Writer) -> None: - if self._length != 0: - raise LocalProtocolError("Too little data for declared Content-Length") - if headers: - raise LocalProtocolError("Content-Length and trailers don't mix") - - -class ChunkedWriter(BodyWriter): - def send_data(self, data: bytes, write: Writer) -> None: - # if we encoded 0-length data in the naive way, it would look like an - # end-of-message. - if not data: - return - write(b"%x\r\n" % len(data)) - write(data) - write(b"\r\n") - - def send_eom(self, headers: Headers, write: Writer) -> None: - write(b"0\r\n") - write_headers(headers, write) - - -class Http10Writer(BodyWriter): - def send_data(self, data: bytes, write: Writer) -> None: - write(data) - - def send_eom(self, headers: Headers, write: Writer) -> None: - if headers: - raise LocalProtocolError("can't send trailers to HTTP/1.0 client") - # no need to close the socket ourselves, that will be taken care of by - # Connection: close machinery - - -WritersType = Dict[ - Union[Tuple[Type[Sentinel], Type[Sentinel]], Type[Sentinel]], - Union[ - Dict[str, Type[BodyWriter]], - Callable[[Union[InformationalResponse, Response], Writer], None], - Callable[[Request, Writer], None], - ], -] - -WRITERS: WritersType = { - (CLIENT, IDLE): write_request, - (SERVER, IDLE): write_any_response, - (SERVER, SEND_RESPONSE): write_any_response, - SEND_BODY: { - "chunked": ChunkedWriter, - "content-length": ContentLengthWriter, - "http/1.0": Http10Writer, - }, -} diff --git a/.venv/lib/python3.12/site-packages/h11/py.typed b/.venv/lib/python3.12/site-packages/h11/py.typed deleted file mode 100644 index f5642f7..0000000 --- a/.venv/lib/python3.12/site-packages/h11/py.typed +++ /dev/null @@ -1 +0,0 @@ -Marker diff --git a/.venv/lib/python3.12/site-packages/html5tagger-1.3.0.dist-info/INSTALLER b/.venv/lib/python3.12/site-packages/html5tagger-1.3.0.dist-info/INSTALLER deleted file mode 100644 index a1b589e..0000000 --- a/.venv/lib/python3.12/site-packages/html5tagger-1.3.0.dist-info/INSTALLER +++ /dev/null @@ -1 +0,0 @@ -pip diff --git a/.venv/lib/python3.12/site-packages/html5tagger-1.3.0.dist-info/LICENSE b/.venv/lib/python3.12/site-packages/html5tagger-1.3.0.dist-info/LICENSE deleted file mode 100644 index b3dbff0..0000000 --- a/.venv/lib/python3.12/site-packages/html5tagger-1.3.0.dist-info/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -This is free and unencumbered software released into the public domain. - -Anyone is free to copy, modify, publish, use, compile, sell, or -distribute this software, either in source code form or as a compiled -binary, for any purpose, commercial or non-commercial, and by any -means. - -In jurisdictions that recognize copyright laws, the author or authors -of this software dedicate any and all copyright interest in the -software to the public domain. We make this dedication for the benefit -of the public at large and to the detriment of our heirs and -successors. We intend this dedication to be an overt act of -relinquishment in perpetuity of all present and future rights to this -software under copyright law. - -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 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. diff --git a/.venv/lib/python3.12/site-packages/html5tagger-1.3.0.dist-info/METADATA b/.venv/lib/python3.12/site-packages/html5tagger-1.3.0.dist-info/METADATA deleted file mode 100644 index 0fa6efb..0000000 --- a/.venv/lib/python3.12/site-packages/html5tagger-1.3.0.dist-info/METADATA +++ /dev/null @@ -1,193 +0,0 @@ -Metadata-Version: 2.1 -Name: html5tagger -Version: 1.3.0 -Summary: Pythonic HTML generation/templating (no template files) -Home-page: https://github.com/sanic-org/html5tagger -Author: Sanic Community -Author-email: tronic@noreply.users.github.com -Keywords: HTML,HTML5,templating,Jinja2 -Classifier: Development Status :: 5 - Production/Stable -Classifier: Intended Audience :: Developers -Classifier: Programming Language :: Python :: 3 -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: Topic :: Text Processing :: Markup :: HTML -Classifier: License :: OSI Approved :: MIT License -Classifier: License :: Public Domain -Classifier: Operating System :: OS Independent -Requires-Python: >=3.7 -Description-Content-Type: text/markdown -License-File: LICENSE - -# HTML5 Generation with html5tagger: Fast, Pure Python, No Dependencies - -If you're looking for a more efficient and streamlined way to generate HTML5, look no further than html5tagger! This module provides a simplified HTML5 syntax, so you can create your entire document template using only Python. Say goodbye to the clunky and error-prone process of manually writing HTML tags. - -With html5tagger, you can safely and quickly generate HTML5 without any dependencies, making it the perfect solution for developers who value speed and simplicity. And with its pure Python implementation, you'll never have to worry about compatibility issues or adding extra libraries to your project. - -Ready to streamline your page rendering process? It is super fast to get started. Trust us, once you try html5tagger, you'll never go back to Jinja2 or manual HTML writing again! - -```sh -pip install html5tagger -``` - -## Intro - -html5tagger provides two starting points for HTML generation: `E` as an empty builder for creating HTML snippets, or `Document` for generating full HTML documents with a DOCTYPE declaration. Both produce a `Builder` object, in case you need that for type annotations. - -Create a snippet and add tags by dot notation: -```python -E.p("Powered by:").br.a(href="...")("html5tagger") -``` -```html -

Powered by:
html5tagger -``` - -A complete example with template variables and other features: - -```python -from html5tagger import Document, E - -# Create a document -doc = Document( - E.TitleText_, # The first argument is for , adding variable TitleText - lang="en", # Keyword arguments for <html> attributes - - # Just list the resources you need, no need to remember link/script tags - _urls=[ "style.css", "favicon.png", "manifest.json" ] -) - -# Upper case names are template variables. You can modify them later. -doc.Head_ -doc.h1.TitleText_("Demo") # Goes inside <h1> and updates <title> as well - -# This has been a hard problem for DOM other such generators: -doc.p("A paragraph with ").a("a link", href="/files")(" and ").em("formatting") - -# Use with for complex nesting (not often needed) -with doc.table(id="data"): - doc.tr.th("First").th("Second").th("Third") - doc.TableRows_ - -# Let's add something to the template variables -doc.Head._script("console.log('</script> escaping is weird')") - -table = doc.TableRows -for row in range(10): - table.tr - for col in range(3): - table.td(row * col) - -# Or remove the table data we just added -doc.TableRows = None -``` - -You can `str(doc)` to get the HTML code, and using `doc` directly usually has the desired effect as well (e.g. giving HTML responses). Jupyter Notebooks render it as HTML. For debugging, use `repr(doc)` where the templating variables are visible: - -```html ->>> doc -《Document Builder》 -<!DOCTYPE html><html lang=en><meta charset="utf-8"> -<title>《TitleText:Demo》 - - - -《Head:》 -

《TitleText:Demo》

-

A paragraph with a link and formatting - -
FirstSecondThird - 《TableRows》 -
-``` - -The actual HTML output is similar. No whitespace is added to the document, it is all on one line unless the content contains newlines. You may notice that `body` and other familiar tags are missing and that the escaping is very minimal. This is HTML5: the document is standards-compliant with a lot less cruft. - -## Templating - -Use template variables to build a document once and only update the dynamic parts at render time for faster performance. Access template variables via doc.TitleText and add content in parenthesis after the tag name. The underscore at the end of a tag name indicates the tag is added to the document and can have content in parenthesis, but any further tags on the same line go to the original document, not the template. - -## Nesting - -In HTML5 elements such as `

` do not need any closing tag, so we can keep adding content without worrying of when it should close. This module does not use closing tags for any elements where those are optional or forbidden. - -A tag is automatically closed when you add content to it or when another tag is added. Setting attributes alone does not close an element. Use `(None)` to close an empty element if any subsequent content is not meant to go inside it, e.g. `doc.script(None, src="...")`. - -For elements like `` and `
`` which has one row and two - cells: one containing the line numbers and one containing the code. - Example: - - .. sourcecode:: html - -
-
- - -
-
1
-            2
-
-
def foo(bar):
-              pass
-            
-
- - (whitespace added to improve clarity). - - A list of lines can be specified using the `hl_lines` option to make these - lines highlighted (as of Pygments 0.11). - - With the `full` option, a complete HTML 4 document is output, including - the style definitions inside a ``$)', _handle_cssblock), - - include('keywords'), - include('inline'), - ], - 'keywords': [ - (words(( - '\\define', '\\end', 'caption', 'created', 'modified', 'tags', - 'title', 'type'), prefix=r'^', suffix=r'\b'), - Keyword), - ], - 'inline': [ - # escape - (r'\\.', Text), - # created or modified date - (r'\d{17}', Number.Integer), - # italics - (r'(\s)(//[^/]+//)((?=\W|\n))', - bygroups(Text, Generic.Emph, Text)), - # superscript - (r'(\s)(\^\^[^\^]+\^\^)', bygroups(Text, Generic.Emph)), - # subscript - (r'(\s)(,,[^,]+,,)', bygroups(Text, Generic.Emph)), - # underscore - (r'(\s)(__[^_]+__)', bygroups(Text, Generic.Strong)), - # bold - (r"(\s)(''[^']+'')((?=\W|\n))", - bygroups(Text, Generic.Strong, Text)), - # strikethrough - (r'(\s)(~~[^~]+~~)((?=\W|\n))', - bygroups(Text, Generic.Deleted, Text)), - # TiddlyWiki variables - (r'<<[^>]+>>', Name.Tag), - (r'\$\$[^$]+\$\$', Name.Tag), - (r'\$\([^)]+\)\$', Name.Tag), - # TiddlyWiki style or class - (r'^@@.*$', Name.Tag), - # HTML tags - (r']+>', Name.Tag), - # inline code - (r'`[^`]+`', String.Backtick), - # HTML escaped symbols - (r'&\S*?;', String.Regex), - # Wiki links - (r'(\[{2})([^]\|]+)(\]{2})', bygroups(Text, Name.Tag, Text)), - # External links - (r'(\[{2})([^]\|]+)(\|)([^]\|]+)(\]{2})', - bygroups(Text, Name.Tag, Text, Name.Attribute, Text)), - # Transclusion - (r'(\{{2})([^}]+)(\}{2})', bygroups(Text, Name.Tag, Text)), - # URLs - (r'(\b.?.?tps?://[^\s"]+)', bygroups(Name.Attribute)), - - # general text, must come last! - (r'[\w]+', Text), - (r'.', Text) - ], - } - - def __init__(self, **options): - self.handlecodeblocks = get_bool_opt(options, 'handlecodeblocks', True) - RegexLexer.__init__(self, **options) - - -class WikitextLexer(RegexLexer): - """ - For MediaWiki Wikitext. - - Parsing Wikitext is tricky, and results vary between different MediaWiki - installations, so we only highlight common syntaxes (built-in or from - popular extensions), and also assume templates produce no unbalanced - syntaxes. - """ - name = 'Wikitext' - url = 'https://www.mediawiki.org/wiki/Wikitext' - aliases = ['wikitext', 'mediawiki'] - filenames = [] - mimetypes = ['text/x-wiki'] - version_added = '2.15' - flags = re.MULTILINE - - def nowiki_tag_rules(tag_name): - return [ - (rf'(?i)()', bygroups(Punctuation, - Name.Tag, Whitespace, Punctuation), '#pop'), - include('entity'), - include('text'), - ] - - def plaintext_tag_rules(tag_name): - return [ - (rf'(?si)(.*?)()', bygroups(Text, - Punctuation, Name.Tag, Whitespace, Punctuation), '#pop'), - ] - - def delegate_tag_rules(tag_name, lexer, **lexer_kwargs): - return [ - (rf'(?i)()', bygroups(Punctuation, - Name.Tag, Whitespace, Punctuation), '#pop'), - (rf'(?si).+?(?=)', using(lexer, **lexer_kwargs)), - ] - - def text_rules(token): - return [ - (r'\w+', token), - (r'[^\S\n]+', token), - (r'(?s).', token), - ] - - def handle_syntaxhighlight(self, match, ctx): - from pygments.lexers import get_lexer_by_name - - attr_content = match.group() - start = 0 - index = 0 - while True: - index = attr_content.find('>', start) - # Exclude comment end (-->) - if attr_content[index-2:index] != '--': - break - start = index + 1 - - if index == -1: - # No tag end - yield from self.get_tokens_unprocessed(attr_content, stack=['root', 'attr']) - return - attr = attr_content[:index] - yield from self.get_tokens_unprocessed(attr, stack=['root', 'attr']) - yield match.start(3) + index, Punctuation, '>' - - lexer = None - content = attr_content[index+1:] - lang_match = re.findall(r'\blang=("|\'|)(\w+)(\1)', attr) - - if len(lang_match) >= 1: - # Pick the last match in case of multiple matches - lang = lang_match[-1][1] - try: - lexer = get_lexer_by_name(lang) - except ClassNotFound: - pass - - if lexer is None: - yield match.start() + index + 1, Text, content - else: - yield from lexer.get_tokens_unprocessed(content) - - def handle_score(self, match, ctx): - attr_content = match.group() - start = 0 - index = 0 - while True: - index = attr_content.find('>', start) - # Exclude comment end (-->) - if attr_content[index-2:index] != '--': - break - start = index + 1 - - if index == -1: - # No tag end - yield from self.get_tokens_unprocessed(attr_content, stack=['root', 'attr']) - return - attr = attr_content[:index] - content = attr_content[index+1:] - yield from self.get_tokens_unprocessed(attr, stack=['root', 'attr']) - yield match.start(3) + index, Punctuation, '>' - - lang_match = re.findall(r'\blang=("|\'|)(\w+)(\1)', attr) - # Pick the last match in case of multiple matches - lang = lang_match[-1][1] if len(lang_match) >= 1 else 'lilypond' - - if lang == 'lilypond': # Case sensitive - yield from LilyPondLexer().get_tokens_unprocessed(content) - else: # ABC - # FIXME: Use ABC lexer in the future - yield match.start() + index + 1, Text, content - - # a-z removed to prevent linter from complaining, REMEMBER to use (?i) - title_char = r' %!"$&\'()*,\-./0-9:;=?@A-Z\\\^_`~+\u0080-\uFFFF' - nbsp_char = r'(?:\t| |&\#0*160;|&\#[Xx]0*[Aa]0;|[ \xA0\u1680\u2000-\u200A\u202F\u205F\u3000])' - link_address = r'(?:[0-9.]+|\[[0-9a-f:.]+\]|[^\x00-\x20"<>\[\]\x7F\xA0\u1680\u2000-\u200A\u202F\u205F\u3000\uFFFD])' - link_char_class = r'[^\x00-\x20"<>\[\]\x7F\xA0\u1680\u2000-\u200A\u202F\u205F\u3000\uFFFD]' - double_slashes_i = { - '__FORCETOC__', '__NOCONTENTCONVERT__', '__NOCC__', '__NOEDITSECTION__', '__NOGALLERY__', - '__NOTITLECONVERT__', '__NOTC__', '__NOTOC__', '__TOC__', - } - double_slashes = { - '__EXPECTUNUSEDCATEGORY__', '__HIDDENCAT__', '__INDEX__', '__NEWSECTIONLINK__', - '__NOINDEX__', '__NONEWSECTIONLINK__', '__STATICREDIRECT__', '__NOGLOBAL__', - '__DISAMBIG__', '__EXPECTED_UNCONNECTED_PAGE__', - } - protocols = { - 'bitcoin:', 'ftp://', 'ftps://', 'geo:', 'git://', 'gopher://', 'http://', 'https://', - 'irc://', 'ircs://', 'magnet:', 'mailto:', 'mms://', 'news:', 'nntp://', 'redis://', - 'sftp://', 'sip:', 'sips:', 'sms:', 'ssh://', 'svn://', 'tel:', 'telnet://', 'urn:', - 'worldwind://', 'xmpp:', '//', - } - non_relative_protocols = protocols - {'//'} - html_tags = { - 'abbr', 'b', 'bdi', 'bdo', 'big', 'blockquote', 'br', 'caption', 'center', 'cite', 'code', - 'data', 'dd', 'del', 'dfn', 'div', 'dl', 'dt', 'em', 'font', 'h1', 'h2', 'h3', 'h4', 'h5', - 'h6', 'hr', 'i', 'ins', 'kbd', 'li', 'link', 'mark', 'meta', 'ol', 'p', 'q', 'rb', 'rp', - 'rt', 'rtc', 'ruby', 's', 'samp', 'small', 'span', 'strike', 'strong', 'sub', 'sup', - 'table', 'td', 'th', 'time', 'tr', 'tt', 'u', 'ul', 'var', 'wbr', - } - parser_tags = { - 'graph', 'charinsert', 'rss', 'chem', 'categorytree', 'nowiki', 'inputbox', 'math', - 'hiero', 'score', 'pre', 'ref', 'translate', 'imagemap', 'templatestyles', 'languages', - 'noinclude', 'mapframe', 'section', 'poem', 'syntaxhighlight', 'includeonly', 'tvar', - 'onlyinclude', 'templatedata', 'langconvert', 'timeline', 'dynamicpagelist', 'gallery', - 'maplink', 'ce', 'references', - } - variant_langs = { - # ZhConverter.php - 'zh', 'zh-hans', 'zh-hant', 'zh-cn', 'zh-hk', 'zh-mo', 'zh-my', 'zh-sg', 'zh-tw', - # WuuConverter.php - 'wuu', 'wuu-hans', 'wuu-hant', - # UzConverter.php - 'uz', 'uz-latn', 'uz-cyrl', - # TlyConverter.php - 'tly', 'tly-cyrl', - # TgConverter.php - 'tg', 'tg-latn', - # SrConverter.php - 'sr', 'sr-ec', 'sr-el', - # ShiConverter.php - 'shi', 'shi-tfng', 'shi-latn', - # ShConverter.php - 'sh-latn', 'sh-cyrl', - # KuConverter.php - 'ku', 'ku-arab', 'ku-latn', - # IuConverter.php - 'iu', 'ike-cans', 'ike-latn', - # GanConverter.php - 'gan', 'gan-hans', 'gan-hant', - # EnConverter.php - 'en', 'en-x-piglatin', - # CrhConverter.php - 'crh', 'crh-cyrl', 'crh-latn', - # BanConverter.php - 'ban', 'ban-bali', 'ban-x-dharma', 'ban-x-palmleaf', 'ban-x-pku', - } - magic_vars_i = { - 'ARTICLEPATH', 'INT', 'PAGEID', 'SCRIPTPATH', 'SERVER', 'SERVERNAME', 'STYLEPATH', - } - magic_vars = { - '!', '=', 'BASEPAGENAME', 'BASEPAGENAMEE', 'CASCADINGSOURCES', 'CONTENTLANGUAGE', - 'CONTENTLANG', 'CURRENTDAY', 'CURRENTDAY2', 'CURRENTDAYNAME', 'CURRENTDOW', 'CURRENTHOUR', - 'CURRENTMONTH', 'CURRENTMONTH2', 'CURRENTMONTH1', 'CURRENTMONTHABBREV', 'CURRENTMONTHNAME', - 'CURRENTMONTHNAMEGEN', 'CURRENTTIME', 'CURRENTTIMESTAMP', 'CURRENTVERSION', 'CURRENTWEEK', - 'CURRENTYEAR', 'DIRECTIONMARK', 'DIRMARK', 'FULLPAGENAME', 'FULLPAGENAMEE', 'LOCALDAY', - 'LOCALDAY2', 'LOCALDAYNAME', 'LOCALDOW', 'LOCALHOUR', 'LOCALMONTH', 'LOCALMONTH2', - 'LOCALMONTH1', 'LOCALMONTHABBREV', 'LOCALMONTHNAME', 'LOCALMONTHNAMEGEN', 'LOCALTIME', - 'LOCALTIMESTAMP', 'LOCALWEEK', 'LOCALYEAR', 'NAMESPACE', 'NAMESPACEE', 'NAMESPACENUMBER', - 'NUMBEROFACTIVEUSERS', 'NUMBEROFADMINS', 'NUMBEROFARTICLES', 'NUMBEROFEDITS', - 'NUMBEROFFILES', 'NUMBEROFPAGES', 'NUMBEROFUSERS', 'PAGELANGUAGE', 'PAGENAME', 'PAGENAMEE', - 'REVISIONDAY', 'REVISIONDAY2', 'REVISIONID', 'REVISIONMONTH', 'REVISIONMONTH1', - 'REVISIONSIZE', 'REVISIONTIMESTAMP', 'REVISIONUSER', 'REVISIONYEAR', 'ROOTPAGENAME', - 'ROOTPAGENAMEE', 'SITENAME', 'SUBJECTPAGENAME', 'ARTICLEPAGENAME', 'SUBJECTPAGENAMEE', - 'ARTICLEPAGENAMEE', 'SUBJECTSPACE', 'ARTICLESPACE', 'SUBJECTSPACEE', 'ARTICLESPACEE', - 'SUBPAGENAME', 'SUBPAGENAMEE', 'TALKPAGENAME', 'TALKPAGENAMEE', 'TALKSPACE', 'TALKSPACEE', - } - parser_functions_i = { - 'ANCHORENCODE', 'BIDI', 'CANONICALURL', 'CANONICALURLE', 'FILEPATH', 'FORMATNUM', - 'FULLURL', 'FULLURLE', 'GENDER', 'GRAMMAR', 'INT', r'\#LANGUAGE', 'LC', 'LCFIRST', 'LOCALURL', - 'LOCALURLE', 'NS', 'NSE', 'PADLEFT', 'PADRIGHT', 'PAGEID', 'PLURAL', 'UC', 'UCFIRST', - 'URLENCODE', - } - parser_functions = { - 'BASEPAGENAME', 'BASEPAGENAMEE', 'CASCADINGSOURCES', 'DEFAULTSORT', 'DEFAULTSORTKEY', - 'DEFAULTCATEGORYSORT', 'FULLPAGENAME', 'FULLPAGENAMEE', 'NAMESPACE', 'NAMESPACEE', - 'NAMESPACENUMBER', 'NUMBERINGROUP', 'NUMINGROUP', 'NUMBEROFACTIVEUSERS', 'NUMBEROFADMINS', - 'NUMBEROFARTICLES', 'NUMBEROFEDITS', 'NUMBEROFFILES', 'NUMBEROFPAGES', 'NUMBEROFUSERS', - 'PAGENAME', 'PAGENAMEE', 'PAGESINCATEGORY', 'PAGESINCAT', 'PAGESIZE', 'PROTECTIONEXPIRY', - 'PROTECTIONLEVEL', 'REVISIONDAY', 'REVISIONDAY2', 'REVISIONID', 'REVISIONMONTH', - 'REVISIONMONTH1', 'REVISIONTIMESTAMP', 'REVISIONUSER', 'REVISIONYEAR', 'ROOTPAGENAME', - 'ROOTPAGENAMEE', 'SUBJECTPAGENAME', 'ARTICLEPAGENAME', 'SUBJECTPAGENAMEE', - 'ARTICLEPAGENAMEE', 'SUBJECTSPACE', 'ARTICLESPACE', 'SUBJECTSPACEE', 'ARTICLESPACEE', - 'SUBPAGENAME', 'SUBPAGENAMEE', 'TALKPAGENAME', 'TALKPAGENAMEE', 'TALKSPACE', 'TALKSPACEE', - 'INT', 'DISPLAYTITLE', 'PAGESINNAMESPACE', 'PAGESINNS', - } - - tokens = { - 'root': [ - # Redirects - (r"""(?xi) - (\A\s*?)(\#REDIRECT:?) # may contain a colon - (\s+)(\[\[) (?=[^\]\n]* \]\]$) - """, - bygroups(Whitespace, Keyword, Whitespace, Punctuation), 'redirect-inner'), - # Subheadings - (r'^(={2,6})(.+?)(\1)(\s*$\n)', - bygroups(Generic.Subheading, Generic.Subheading, Generic.Subheading, Whitespace)), - # Headings - (r'^(=.+?=)(\s*$\n)', - bygroups(Generic.Heading, Whitespace)), - # Double-slashed magic words - (words(double_slashes_i, prefix=r'(?i)'), Name.Function.Magic), - (words(double_slashes), Name.Function.Magic), - # Raw URLs - (r'(?i)\b(?:{}){}{}*'.format('|'.join(protocols), - link_address, link_char_class), Name.Label), - # Magic links - (rf'\b(?:RFC|PMID){nbsp_char}+[0-9]+\b', - Name.Function.Magic), - (r"""(?x) - \bISBN {nbsp_char} - (?: 97[89] {nbsp_dash}? )? - (?: [0-9] {nbsp_dash}? ){{9}} # escape format() - [0-9Xx]\b - """.format(nbsp_char=nbsp_char, nbsp_dash=f'(?:-|{nbsp_char})'), Name.Function.Magic), - include('list'), - include('inline'), - include('text'), - ], - 'redirect-inner': [ - (r'(\]\])(\s*?\n)', bygroups(Punctuation, Whitespace), '#pop'), - (r'(\#)([^#]*?)', bygroups(Punctuation, Name.Label)), - (rf'(?i)[{title_char}]+', Name.Tag), - ], - 'list': [ - # Description lists - (r'^;', Keyword, 'dt'), - # Ordered lists, unordered lists and indents - (r'^[#:*]+', Keyword), - # Horizontal rules - (r'^-{4,}', Keyword), - ], - 'inline': [ - # Signatures - (r'~{3,5}', Keyword), - # Entities - include('entity'), - # Bold & italic - (r"('')(''')(?!')", bygroups(Generic.Emph, - Generic.EmphStrong), 'inline-italic-bold'), - (r"'''(?!')", Generic.Strong, 'inline-bold'), - (r"''(?!')", Generic.Emph, 'inline-italic'), - # Comments & parameters & templates - include('replaceable'), - # Media links - ( - r"""(?xi) - (\[\[) - (File|Image) (:) - ((?: [{}] | \{{{{2,3}}[^{{}}]*?\}}{{2,3}} | )*) - (?: (\#) ([{}]*?) )? - """.format(title_char, f'{title_char}#'), - bygroups(Punctuation, Name.Namespace, Punctuation, - using(this, state=['wikilink-name']), Punctuation, Name.Label), - 'medialink-inner' - ), - # Wikilinks - ( - r"""(?xi) - (\[\[)(?!{}) # Should not contain URLs - (?: ([{}]*) (:))? - ((?: [{}] | \{{{{2,3}}[^{{}}]*?\}}{{2,3}} | )*?) - (?: (\#) ([{}]*?) )? - (\]\]) - """.format('|'.join(protocols), title_char.replace('/', ''), - title_char, f'{title_char}#'), - bygroups(Punctuation, Name.Namespace, Punctuation, - using(this, state=['wikilink-name']), Punctuation, Name.Label, Punctuation) - ), - ( - r"""(?xi) - (\[\[)(?!{}) - (?: ([{}]*) (:))? - ((?: [{}] | \{{{{2,3}}[^{{}}]*?\}}{{2,3}} | )*?) - (?: (\#) ([{}]*?) )? - (\|) - """.format('|'.join(protocols), title_char.replace('/', ''), - title_char, f'{title_char}#'), - bygroups(Punctuation, Name.Namespace, Punctuation, - using(this, state=['wikilink-name']), Punctuation, Name.Label, Punctuation), - 'wikilink-inner' - ), - # External links - ( - r"""(?xi) - (\[) - ((?:{}) {} {}*) - (\s*) - """.format('|'.join(protocols), link_address, link_char_class), - bygroups(Punctuation, Name.Label, Whitespace), - 'extlink-inner' - ), - # Tables - (r'^(:*)(\s*?)(\{\|)([^\n]*)$', bygroups(Keyword, - Whitespace, Punctuation, using(this, state=['root', 'attr'])), 'table'), - # HTML tags - (r'(?i)(<)({})\b'.format('|'.join(html_tags)), - bygroups(Punctuation, Name.Tag), 'tag-inner-ordinary'), - (r'(?i)()'.format('|'.join(html_tags)), - bygroups(Punctuation, Name.Tag, Whitespace, Punctuation)), - # - (r'(?i)(<)(nowiki)\b', bygroups(Punctuation, - Name.Tag), ('tag-nowiki', 'tag-inner')), - #

-            (r'(?i)(<)(pre)\b', bygroups(Punctuation,
-             Name.Tag), ('tag-pre', 'tag-inner')),
-            # 
-            (r'(?i)(<)(categorytree)\b', bygroups(
-                Punctuation, Name.Tag), ('tag-categorytree', 'tag-inner')),
-            # 
-            (r'(?i)(<)(hiero)\b', bygroups(Punctuation,
-             Name.Tag), ('tag-hiero', 'tag-inner')),
-            # 
-            (r'(?i)(<)(math)\b', bygroups(Punctuation,
-             Name.Tag), ('tag-math', 'tag-inner')),
-            # 
-            (r'(?i)(<)(chem)\b', bygroups(Punctuation,
-             Name.Tag), ('tag-chem', 'tag-inner')),
-            # 
-            (r'(?i)(<)(ce)\b', bygroups(Punctuation,
-             Name.Tag), ('tag-ce', 'tag-inner')),
-            # 
-            (r'(?i)(<)(charinsert)\b', bygroups(
-                Punctuation, Name.Tag), ('tag-charinsert', 'tag-inner')),
-            # 
-            (r'(?i)(<)(templatedata)\b', bygroups(
-                Punctuation, Name.Tag), ('tag-templatedata', 'tag-inner')),
-            # 
-            (r'(?i)(<)(gallery)\b', bygroups(
-                Punctuation, Name.Tag), ('tag-gallery', 'tag-inner')),
-            # 
-            (r'(?i)(<)(gallery)\b', bygroups(
-                Punctuation, Name.Tag), ('tag-graph', 'tag-inner')),
-            # 
-            (r'(?i)(<)(dynamicpagelist)\b', bygroups(
-                Punctuation, Name.Tag), ('tag-dynamicpagelist', 'tag-inner')),
-            # 
-            (r'(?i)(<)(inputbox)\b', bygroups(
-                Punctuation, Name.Tag), ('tag-inputbox', 'tag-inner')),
-            # 
-            (r'(?i)(<)(rss)\b', bygroups(
-                Punctuation, Name.Tag), ('tag-rss', 'tag-inner')),
-            # 
-            (r'(?i)(<)(imagemap)\b', bygroups(
-                Punctuation, Name.Tag), ('tag-imagemap', 'tag-inner')),
-            # 
-            (r'(?i)()',
-             bygroups(Punctuation, Name.Tag, Whitespace, Punctuation)),
-            (r'(?si)(<)(syntaxhighlight)\b([^>]*?(?.*?)(?=)',
-             bygroups(Punctuation, Name.Tag, handle_syntaxhighlight)),
-            # : Fallback case for self-closing tags
-            (r'(?i)(<)(syntaxhighlight)\b(\s*?)((?:[^>]|-->)*?)(/\s*?(?)*?)(/\s*?(?)*?)(/\s*?(?|\Z)', Comment.Multiline),
-            # Parameters
-            (
-                r"""(?x)
-                (\{{3})
-                    ([^|]*?)
-                    (?=\}{3}|\|)
-                """,
-                bygroups(Punctuation, Name.Variable),
-                'parameter-inner',
-            ),
-            # Magic variables
-            (r'(?i)(\{{\{{)(\s*)({})(\s*)(\}}\}})'.format('|'.join(magic_vars_i)),
-             bygroups(Punctuation, Whitespace, Name.Function, Whitespace, Punctuation)),
-            (r'(\{{\{{)(\s*)({})(\s*)(\}}\}})'.format('|'.join(magic_vars)),
-                bygroups(Punctuation, Whitespace, Name.Function, Whitespace, Punctuation)),
-            # Parser functions & templates
-            (r'\{\{', Punctuation, 'template-begin-space'),
-            #  legacy syntax
-            (r'(?i)(<)(tvar)\b(\|)([^>]*?)(>)', bygroups(Punctuation,
-             Name.Tag, Punctuation, String, Punctuation)),
-            (r'', Punctuation, '#pop'),
-            # 
-            (r'(?i)(<)(tvar)\b', bygroups(Punctuation, Name.Tag), 'tag-inner-ordinary'),
-            (r'(?i)()',
-             bygroups(Punctuation, Name.Tag, Whitespace, Punctuation)),
-        ],
-        'parameter-inner': [
-            (r'\}{3}', Punctuation, '#pop'),
-            (r'\|', Punctuation),
-            include('inline'),
-            include('text'),
-        ],
-        'template-begin-space': [
-            # Templates allow line breaks at the beginning, and due to how MediaWiki handles
-            # comments, an extra state is required to handle things like {{\n\n name}}
-            (r'|\Z)', Comment.Multiline),
-            (r'\s+', Whitespace),
-            # Parser functions
-            (
-                r'(?i)(\#[{}]*?|{})(:)'.format(title_char,
-                                           '|'.join(parser_functions_i)),
-                bygroups(Name.Function, Punctuation), ('#pop', 'template-inner')
-            ),
-            (
-                r'({})(:)'.format('|'.join(parser_functions)),
-                bygroups(Name.Function, Punctuation), ('#pop', 'template-inner')
-            ),
-            # Templates
-            (
-                rf'(?i)([{title_char}]*?)(:)',
-                bygroups(Name.Namespace, Punctuation), ('#pop', 'template-name')
-            ),
-            default(('#pop', 'template-name'),),
-        ],
-        'template-name': [
-            (r'(\s*?)(\|)', bygroups(Text, Punctuation), ('#pop', 'template-inner')),
-            (r'\}\}', Punctuation, '#pop'),
-            (r'\n', Text, '#pop'),
-            include('replaceable'),
-            *text_rules(Name.Tag),
-        ],
-        'template-inner': [
-            (r'\}\}', Punctuation, '#pop'),
-            (r'\|', Punctuation),
-            (
-                r"""(?x)
-                    (?<=\|)
-                    ( (?: (?! \{\{ | \}\} )[^=\|<])*? ) # Exclude templates and tags
-                    (=)
-                """,
-                bygroups(Name.Label, Operator)
-            ),
-            include('inline'),
-            include('text'),
-        ],
-        'table': [
-            # Use [ \t\n\r\0\x0B] instead of \s to follow PHP trim() behavior
-            # Endings
-            (r'^([ \t\n\r\0\x0B]*?)(\|\})',
-             bygroups(Whitespace, Punctuation), '#pop'),
-            # Table rows
-            (r'^([ \t\n\r\0\x0B]*?)(\|-+)(.*)$', bygroups(Whitespace, Punctuation,
-             using(this, state=['root', 'attr']))),
-            # Captions
-            (
-                r"""(?x)
-                ^([ \t\n\r\0\x0B]*?)(\|\+)
-                # Exclude links, template and tags
-                (?: ( (?: (?! \[\[ | \{\{ )[^|\n<] )*? )(\|) )?
-                (.*?)$
-                """,
-                bygroups(Whitespace, Punctuation, using(this, state=[
-                         'root', 'attr']), Punctuation, Generic.Heading),
-            ),
-            # Table data
-            (
-                r"""(?x)
-                ( ^(?:[ \t\n\r\0\x0B]*?)\| | \|\| )
-                (?: ( (?: (?! \[\[ | \{\{ )[^|\n<] )*? )(\|)(?!\|) )?
-                """,
-                bygroups(Punctuation, using(this, state=[
-                         'root', 'attr']), Punctuation),
-            ),
-            # Table headers
-            (
-                r"""(?x)
-                ( ^(?:[ \t\n\r\0\x0B]*?)!  )
-                (?: ( (?: (?! \[\[ | \{\{ )[^|\n<] )*? )(\|)(?!\|) )?
-                """,
-                bygroups(Punctuation, using(this, state=[
-                         'root', 'attr']), Punctuation),
-                'table-header',
-            ),
-            include('list'),
-            include('inline'),
-            include('text'),
-        ],
-        'table-header': [
-            # Requires another state for || handling inside headers
-            (r'\n', Text, '#pop'),
-            (
-                r"""(?x)
-                (!!|\|\|)
-                (?:
-                    ( (?: (?! \[\[ | \{\{ )[^|\n<] )*? )
-                    (\|)(?!\|)
-                )?
-                """,
-                bygroups(Punctuation, using(this, state=[
-                         'root', 'attr']), Punctuation)
-            ),
-            *text_rules(Generic.Subheading),
-        ],
-        'entity': [
-            (r'&\S*?;', Name.Entity),
-        ],
-        'dt': [
-            (r'\n', Text, '#pop'),
-            include('inline'),
-            (r':', Keyword, '#pop'),
-            include('text'),
-        ],
-        'extlink-inner': [
-            (r'\]', Punctuation, '#pop'),
-            include('inline'),
-            include('text'),
-        ],
-        'nowiki-ish': [
-            include('entity'),
-            include('text'),
-        ],
-        'attr': [
-            include('replaceable'),
-            (r'\s+', Whitespace),
-            (r'(=)(\s*)(")', bygroups(Operator, Whitespace, String.Double), 'attr-val-2'),
-            (r"(=)(\s*)(')", bygroups(Operator, Whitespace, String.Single), 'attr-val-1'),
-            (r'(=)(\s*)', bygroups(Operator, Whitespace), 'attr-val-0'),
-            (r'[\w:-]+', Name.Attribute),
-
-        ],
-        'attr-val-0': [
-            (r'\s', Whitespace, '#pop'),
-            include('replaceable'),
-            *text_rules(String),
-        ],
-        'attr-val-1': [
-            (r"'", String.Single, '#pop'),
-            include('replaceable'),
-            *text_rules(String.Single),
-        ],
-        'attr-val-2': [
-            (r'"', String.Double, '#pop'),
-            include('replaceable'),
-            *text_rules(String.Double),
-        ],
-        'tag-inner-ordinary': [
-            (r'/?\s*>', Punctuation, '#pop'),
-            include('tag-attr'),
-        ],
-        'tag-inner': [
-            # Return to root state for self-closing tags
-            (r'/\s*>', Punctuation, '#pop:2'),
-            (r'\s*>', Punctuation, '#pop'),
-            include('tag-attr'),
-        ],
-        # There states below are just like their non-tag variants, the key difference is
-        # they forcibly quit when encountering tag closing markup
-        'tag-attr': [
-            include('replaceable'),
-            (r'\s+', Whitespace),
-            (r'(=)(\s*)(")', bygroups(Operator,
-             Whitespace, String.Double), 'tag-attr-val-2'),
-            (r"(=)(\s*)(')", bygroups(Operator,
-             Whitespace, String.Single), 'tag-attr-val-1'),
-            (r'(=)(\s*)', bygroups(Operator, Whitespace), 'tag-attr-val-0'),
-            (r'[\w:-]+', Name.Attribute),
-
-        ],
-        'tag-attr-val-0': [
-            (r'\s', Whitespace, '#pop'),
-            (r'/?>', Punctuation, '#pop:2'),
-            include('replaceable'),
-            *text_rules(String),
-        ],
-        'tag-attr-val-1': [
-            (r"'", String.Single, '#pop'),
-            (r'/?>', Punctuation, '#pop:2'),
-            include('replaceable'),
-            *text_rules(String.Single),
-        ],
-        'tag-attr-val-2': [
-            (r'"', String.Double, '#pop'),
-            (r'/?>', Punctuation, '#pop:2'),
-            include('replaceable'),
-            *text_rules(String.Double),
-        ],
-        'tag-nowiki': nowiki_tag_rules('nowiki'),
-        'tag-pre': nowiki_tag_rules('pre'),
-        'tag-categorytree': plaintext_tag_rules('categorytree'),
-        'tag-dynamicpagelist': plaintext_tag_rules('dynamicpagelist'),
-        'tag-hiero': plaintext_tag_rules('hiero'),
-        'tag-inputbox': plaintext_tag_rules('inputbox'),
-        'tag-imagemap': plaintext_tag_rules('imagemap'),
-        'tag-charinsert': plaintext_tag_rules('charinsert'),
-        'tag-timeline': plaintext_tag_rules('timeline'),
-        'tag-gallery': plaintext_tag_rules('gallery'),
-        'tag-graph': plaintext_tag_rules('graph'),
-        'tag-rss': plaintext_tag_rules('rss'),
-        'tag-math': delegate_tag_rules('math', TexLexer, state='math'),
-        'tag-chem': delegate_tag_rules('chem', TexLexer, state='math'),
-        'tag-ce': delegate_tag_rules('ce', TexLexer, state='math'),
-        'tag-templatedata': delegate_tag_rules('templatedata', JsonLexer),
-        'text-italic': text_rules(Generic.Emph),
-        'text-bold': text_rules(Generic.Strong),
-        'text-bold-italic': text_rules(Generic.EmphStrong),
-        'text': text_rules(Text),
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/math.py b/.venv/lib/python3.12/site-packages/pygments/lexers/math.py
deleted file mode 100644
index b38c13e..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/math.py
+++ /dev/null
@@ -1,21 +0,0 @@
-"""
-    pygments.lexers.math
-    ~~~~~~~~~~~~~~~~~~~~
-
-    Just export lexers that were contained in this module.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-# ruff: noqa: F401
-from pygments.lexers.python import NumPyLexer
-from pygments.lexers.matlab import MatlabLexer, MatlabSessionLexer, \
-    OctaveLexer, ScilabLexer
-from pygments.lexers.julia import JuliaLexer, JuliaConsoleLexer
-from pygments.lexers.r import RConsoleLexer, SLexer, RdLexer
-from pygments.lexers.modeling import BugsLexer, JagsLexer, StanLexer
-from pygments.lexers.idl import IDLLexer
-from pygments.lexers.algebra import MuPADLexer
-
-__all__ = []
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/matlab.py b/.venv/lib/python3.12/site-packages/pygments/lexers/matlab.py
deleted file mode 100644
index b27f4db..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/matlab.py
+++ /dev/null
@@ -1,3307 +0,0 @@
-"""
-    pygments.lexers.matlab
-    ~~~~~~~~~~~~~~~~~~~~~~
-
-    Lexers for Matlab and related languages.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-import re
-
-from pygments.lexer import Lexer, RegexLexer, bygroups, default, words, \
-    do_insertions, include
-from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
-    Number, Punctuation, Generic, Whitespace
-
-from pygments.lexers import _scilab_builtins
-
-__all__ = ['MatlabLexer', 'MatlabSessionLexer', 'OctaveLexer', 'ScilabLexer']
-
-
-class MatlabLexer(RegexLexer):
-    """
-    For Matlab source code.
-    """
-    name = 'Matlab'
-    aliases = ['matlab']
-    filenames = ['*.m']
-    mimetypes = ['text/matlab']
-    url = 'https://www.mathworks.com/products/matlab.html'
-    version_added = '0.10'
-
-    _operators = r'-|==|~=|<=|>=|<|>|&&|&|~|\|\|?|\.\*|\*|\+|\.\^|\^|\.\\|\./|/|\\'
-
-    tokens = {
-        'expressions': [
-            # operators:
-            (_operators, Operator),
-
-            # numbers (must come before punctuation to handle `.5`; cannot use
-            # `\b` due to e.g. `5. + .5`).  The negative lookahead on operators
-            # avoids including the dot in `1./x` (the dot is part of `./`).
-            (rf'(? and then
-            # (equal | open-parenthesis |  | ).
-            (rf'(?:^|(?<=;))(\s*)(\w+)(\s+)(?!=|\(|{_operators}\s|\s)',
-             bygroups(Whitespace, Name, Whitespace), 'commandargs'),
-
-            include('expressions')
-        ],
-        'blockcomment': [
-            (r'^\s*%\}', Comment.Multiline, '#pop'),
-            (r'^.*\n', Comment.Multiline),
-            (r'.', Comment.Multiline),
-        ],
-        'deffunc': [
-            (r'(\s*)(?:(\S+)(\s*)(=)(\s*))?(.+)(\()(.*)(\))(\s*)',
-             bygroups(Whitespace, Text, Whitespace, Punctuation,
-                      Whitespace, Name.Function, Punctuation, Text,
-                      Punctuation, Whitespace), '#pop'),
-            # function with no args
-            (r'(\s*)([a-zA-Z_]\w*)',
-             bygroups(Whitespace, Name.Function), '#pop'),
-        ],
-        'propattrs': [
-            (r'(\w+)(\s*)(=)(\s*)(\d+)',
-             bygroups(Name.Builtin, Whitespace, Punctuation, Whitespace,
-                      Number)),
-            (r'(\w+)(\s*)(=)(\s*)([a-zA-Z]\w*)',
-             bygroups(Name.Builtin, Whitespace, Punctuation, Whitespace,
-                      Keyword)),
-            (r',', Punctuation),
-            (r'\)', Punctuation, '#pop'),
-            (r'\s+', Whitespace),
-            (r'.', Text),
-        ],
-        'defprops': [
-            (r'%\{\s*\n', Comment.Multiline, 'blockcomment'),
-            (r'%.*$', Comment),
-            (r'(?.
-    """
-    name = 'Matlab session'
-    aliases = ['matlabsession']
-    url = 'https://www.mathworks.com/products/matlab.html'
-    version_added = '0.10'
-    _example = "matlabsession/matlabsession_sample.txt"
-
-    def get_tokens_unprocessed(self, text):
-        mlexer = MatlabLexer(**self.options)
-
-        curcode = ''
-        insertions = []
-        continuation = False
-
-        for match in line_re.finditer(text):
-            line = match.group()
-
-            if line.startswith('>> '):
-                insertions.append((len(curcode),
-                                   [(0, Generic.Prompt, line[:3])]))
-                curcode += line[3:]
-
-            elif line.startswith('>>'):
-                insertions.append((len(curcode),
-                                   [(0, Generic.Prompt, line[:2])]))
-                curcode += line[2:]
-
-            elif line.startswith('???'):
-
-                idx = len(curcode)
-
-                # without is showing error on same line as before...?
-                # line = "\n" + line
-                token = (0, Generic.Traceback, line)
-                insertions.append((idx, [token]))
-            elif continuation and insertions:
-                # line_start is the length of the most recent prompt symbol
-                line_start = len(insertions[-1][-1][-1])
-                # Set leading spaces with the length of the prompt to be a generic prompt
-                # This keeps code aligned when prompts are removed, say with some Javascript
-                if line.startswith(' '*line_start):
-                    insertions.append(
-                        (len(curcode), [(0, Generic.Prompt, line[:line_start])]))
-                    curcode += line[line_start:]
-                else:
-                    curcode += line
-            else:
-                if curcode:
-                    yield from do_insertions(
-                        insertions, mlexer.get_tokens_unprocessed(curcode))
-                    curcode = ''
-                    insertions = []
-
-                yield match.start(), Generic.Output, line
-
-            # Does not allow continuation if a comment is included after the ellipses.
-            # Continues any line that ends with ..., even comments (lines that start with %)
-            if line.strip().endswith('...'):
-                continuation = True
-            else:
-                continuation = False
-
-        if curcode:  # or item:
-            yield from do_insertions(
-                insertions, mlexer.get_tokens_unprocessed(curcode))
-
-
-class OctaveLexer(RegexLexer):
-    """
-    For GNU Octave source code.
-    """
-    name = 'Octave'
-    url = 'https://www.gnu.org/software/octave/index'
-    aliases = ['octave']
-    filenames = ['*.m']
-    mimetypes = ['text/octave']
-    version_added = '1.5'
-
-    # These lists are generated automatically.
-    # Run the following in bash shell:
-    #
-    # First dump all of the Octave manual into a plain text file:
-    #
-    #   $ info octave --subnodes -o octave-manual
-    #
-    # Now grep through it:
-
-    # for i in \
-    #     "Built-in Function" "Command" "Function File" \
-    #     "Loadable Function" "Mapping Function";
-    # do
-    #     perl -e '@name = qw('"$i"');
-    #              print lc($name[0]),"_kw = [\n"';
-    #
-    #     perl -n -e 'print "\"$1\",\n" if /-- '"$i"': .* (\w*) \(/;' \
-    #         octave-manual | sort | uniq ;
-    #     echo "]" ;
-    #     echo;
-    # done
-
-    # taken from Octave Mercurial changeset 8cc154f45e37 (30-jan-2011)
-
-    builtin_kw = (
-        "addlistener", "addpath", "addproperty", "all",
-        "and", "any", "argnames", "argv", "assignin",
-        "atexit", "autoload",
-        "available_graphics_toolkits", "beep_on_error",
-        "bitand", "bitmax", "bitor", "bitshift", "bitxor",
-        "cat", "cell", "cellstr", "char", "class", "clc",
-        "columns", "command_line_path",
-        "completion_append_char", "completion_matches",
-        "complex", "confirm_recursive_rmdir", "cputime",
-        "crash_dumps_octave_core", "ctranspose", "cumprod",
-        "cumsum", "debug_on_error", "debug_on_interrupt",
-        "debug_on_warning", "default_save_options",
-        "dellistener", "diag", "diff", "disp",
-        "doc_cache_file", "do_string_escapes", "double",
-        "drawnow", "e", "echo_executing_commands", "eps",
-        "eq", "errno", "errno_list", "error", "eval",
-        "evalin", "exec", "exist", "exit", "eye", "false",
-        "fclear", "fclose", "fcntl", "fdisp", "feof",
-        "ferror", "feval", "fflush", "fgetl", "fgets",
-        "fieldnames", "file_in_loadpath", "file_in_path",
-        "filemarker", "filesep", "find_dir_in_path",
-        "fixed_point_format", "fnmatch", "fopen", "fork",
-        "formula", "fprintf", "fputs", "fread", "freport",
-        "frewind", "fscanf", "fseek", "fskipl", "ftell",
-        "functions", "fwrite", "ge", "genpath", "get",
-        "getegid", "getenv", "geteuid", "getgid",
-        "getpgrp", "getpid", "getppid", "getuid", "glob",
-        "gt", "gui_mode", "history_control",
-        "history_file", "history_size",
-        "history_timestamp_format_string", "home",
-        "horzcat", "hypot", "ifelse",
-        "ignore_function_time_stamp", "inferiorto",
-        "info_file", "info_program", "inline", "input",
-        "intmax", "intmin", "ipermute",
-        "is_absolute_filename", "isargout", "isbool",
-        "iscell", "iscellstr", "ischar", "iscomplex",
-        "isempty", "isfield", "isfloat", "isglobal",
-        "ishandle", "isieee", "isindex", "isinteger",
-        "islogical", "ismatrix", "ismethod", "isnull",
-        "isnumeric", "isobject", "isreal",
-        "is_rooted_relative_filename", "issorted",
-        "isstruct", "isvarname", "kbhit", "keyboard",
-        "kill", "lasterr", "lasterror", "lastwarn",
-        "ldivide", "le", "length", "link", "linspace",
-        "logical", "lstat", "lt", "make_absolute_filename",
-        "makeinfo_program", "max_recursion_depth", "merge",
-        "methods", "mfilename", "minus", "mislocked",
-        "mkdir", "mkfifo", "mkstemp", "mldivide", "mlock",
-        "mouse_wheel_zoom", "mpower", "mrdivide", "mtimes",
-        "munlock", "nargin", "nargout",
-        "native_float_format", "ndims", "ne", "nfields",
-        "nnz", "norm", "not", "numel", "nzmax",
-        "octave_config_info", "octave_core_file_limit",
-        "octave_core_file_name",
-        "octave_core_file_options", "ones", "or",
-        "output_max_field_width", "output_precision",
-        "page_output_immediately", "page_screen_output",
-        "path", "pathsep", "pause", "pclose", "permute",
-        "pi", "pipe", "plus", "popen", "power",
-        "print_empty_dimensions", "printf",
-        "print_struct_array_contents", "prod",
-        "program_invocation_name", "program_name",
-        "putenv", "puts", "pwd", "quit", "rats", "rdivide",
-        "readdir", "readlink", "read_readline_init_file",
-        "realmax", "realmin", "rehash", "rename",
-        "repelems", "re_read_readline_init_file", "reset",
-        "reshape", "resize", "restoredefaultpath",
-        "rethrow", "rmdir", "rmfield", "rmpath", "rows",
-        "save_header_format_string", "save_precision",
-        "saving_history", "scanf", "set", "setenv",
-        "shell_cmd", "sighup_dumps_octave_core",
-        "sigterm_dumps_octave_core", "silent_functions",
-        "single", "size", "size_equal", "sizemax",
-        "sizeof", "sleep", "source", "sparse_auto_mutate",
-        "split_long_rows", "sprintf", "squeeze", "sscanf",
-        "stat", "stderr", "stdin", "stdout", "strcmp",
-        "strcmpi", "string_fill_char", "strncmp",
-        "strncmpi", "struct", "struct_levels_to_print",
-        "strvcat", "subsasgn", "subsref", "sum", "sumsq",
-        "superiorto", "suppress_verbose_help_message",
-        "symlink", "system", "tic", "tilde_expand",
-        "times", "tmpfile", "tmpnam", "toc", "toupper",
-        "transpose", "true", "typeinfo", "umask", "uminus",
-        "uname", "undo_string_escapes", "unlink", "uplus",
-        "upper", "usage", "usleep", "vec", "vectorize",
-        "vertcat", "waitpid", "warning", "warranty",
-        "whos_line_format", "yes_or_no", "zeros",
-        "inf", "Inf", "nan", "NaN")
-
-    command_kw = ("close", "load", "who", "whos")
-
-    function_kw = (
-        "accumarray", "accumdim", "acosd", "acotd",
-        "acscd", "addtodate", "allchild", "ancestor",
-        "anova", "arch_fit", "arch_rnd", "arch_test",
-        "area", "arma_rnd", "arrayfun", "ascii", "asctime",
-        "asecd", "asind", "assert", "atand",
-        "autoreg_matrix", "autumn", "axes", "axis", "bar",
-        "barh", "bartlett", "bartlett_test", "beep",
-        "betacdf", "betainv", "betapdf", "betarnd",
-        "bicgstab", "bicubic", "binary", "binocdf",
-        "binoinv", "binopdf", "binornd", "bitcmp",
-        "bitget", "bitset", "blackman", "blanks",
-        "blkdiag", "bone", "box", "brighten", "calendar",
-        "cast", "cauchy_cdf", "cauchy_inv", "cauchy_pdf",
-        "cauchy_rnd", "caxis", "celldisp", "center", "cgs",
-        "chisquare_test_homogeneity",
-        "chisquare_test_independence", "circshift", "cla",
-        "clabel", "clf", "clock", "cloglog", "closereq",
-        "colon", "colorbar", "colormap", "colperm",
-        "comet", "common_size", "commutation_matrix",
-        "compan", "compare_versions", "compass",
-        "computer", "cond", "condest", "contour",
-        "contourc", "contourf", "contrast", "conv",
-        "convhull", "cool", "copper", "copyfile", "cor",
-        "corrcoef", "cor_test", "cosd", "cotd", "cov",
-        "cplxpair", "cross", "cscd", "cstrcat", "csvread",
-        "csvwrite", "ctime", "cumtrapz", "curl", "cut",
-        "cylinder", "date", "datenum", "datestr",
-        "datetick", "datevec", "dblquad", "deal",
-        "deblank", "deconv", "delaunay", "delaunayn",
-        "delete", "demo", "detrend", "diffpara", "diffuse",
-        "dir", "discrete_cdf", "discrete_inv",
-        "discrete_pdf", "discrete_rnd", "display",
-        "divergence", "dlmwrite", "dos", "dsearch",
-        "dsearchn", "duplication_matrix", "durbinlevinson",
-        "ellipsoid", "empirical_cdf", "empirical_inv",
-        "empirical_pdf", "empirical_rnd", "eomday",
-        "errorbar", "etime", "etreeplot", "example",
-        "expcdf", "expinv", "expm", "exppdf", "exprnd",
-        "ezcontour", "ezcontourf", "ezmesh", "ezmeshc",
-        "ezplot", "ezpolar", "ezsurf", "ezsurfc", "factor",
-        "factorial", "fail", "fcdf", "feather", "fftconv",
-        "fftfilt", "fftshift", "figure", "fileattrib",
-        "fileparts", "fill", "findall", "findobj",
-        "findstr", "finv", "flag", "flipdim", "fliplr",
-        "flipud", "fpdf", "fplot", "fractdiff", "freqz",
-        "freqz_plot", "frnd", "fsolve",
-        "f_test_regression", "ftp", "fullfile", "fzero",
-        "gamcdf", "gaminv", "gampdf", "gamrnd", "gca",
-        "gcbf", "gcbo", "gcf", "genvarname", "geocdf",
-        "geoinv", "geopdf", "geornd", "getfield", "ginput",
-        "glpk", "gls", "gplot", "gradient",
-        "graphics_toolkit", "gray", "grid", "griddata",
-        "griddatan", "gtext", "gunzip", "gzip", "hadamard",
-        "hamming", "hankel", "hanning", "hggroup",
-        "hidden", "hilb", "hist", "histc", "hold", "hot",
-        "hotelling_test", "housh", "hsv", "hurst",
-        "hygecdf", "hygeinv", "hygepdf", "hygernd",
-        "idivide", "ifftshift", "image", "imagesc",
-        "imfinfo", "imread", "imshow", "imwrite", "index",
-        "info", "inpolygon", "inputname", "interpft",
-        "interpn", "intersect", "invhilb", "iqr", "isa",
-        "isdefinite", "isdir", "is_duplicate_entry",
-        "isequal", "isequalwithequalnans", "isfigure",
-        "ishermitian", "ishghandle", "is_leap_year",
-        "isletter", "ismac", "ismember", "ispc", "isprime",
-        "isprop", "isscalar", "issquare", "isstrprop",
-        "issymmetric", "isunix", "is_valid_file_id",
-        "isvector", "jet", "kendall",
-        "kolmogorov_smirnov_cdf",
-        "kolmogorov_smirnov_test", "kruskal_wallis_test",
-        "krylov", "kurtosis", "laplace_cdf", "laplace_inv",
-        "laplace_pdf", "laplace_rnd", "legend", "legendre",
-        "license", "line", "linkprop", "list_primes",
-        "loadaudio", "loadobj", "logistic_cdf",
-        "logistic_inv", "logistic_pdf", "logistic_rnd",
-        "logit", "loglog", "loglogerr", "logm", "logncdf",
-        "logninv", "lognpdf", "lognrnd", "logspace",
-        "lookfor", "ls_command", "lsqnonneg", "magic",
-        "mahalanobis", "manova", "matlabroot",
-        "mcnemar_test", "mean", "meansq", "median", "menu",
-        "mesh", "meshc", "meshgrid", "meshz", "mexext",
-        "mget", "mkpp", "mode", "moment", "movefile",
-        "mpoles", "mput", "namelengthmax", "nargchk",
-        "nargoutchk", "nbincdf", "nbininv", "nbinpdf",
-        "nbinrnd", "nchoosek", "ndgrid", "newplot", "news",
-        "nonzeros", "normcdf", "normest", "norminv",
-        "normpdf", "normrnd", "now", "nthroot", "null",
-        "ocean", "ols", "onenormest", "optimget",
-        "optimset", "orderfields", "orient", "orth",
-        "pack", "pareto", "parseparams", "pascal", "patch",
-        "pathdef", "pcg", "pchip", "pcolor", "pcr",
-        "peaks", "periodogram", "perl", "perms", "pie",
-        "pink", "planerot", "playaudio", "plot",
-        "plotmatrix", "plotyy", "poisscdf", "poissinv",
-        "poisspdf", "poissrnd", "polar", "poly",
-        "polyaffine", "polyarea", "polyderiv", "polyfit",
-        "polygcd", "polyint", "polyout", "polyreduce",
-        "polyval", "polyvalm", "postpad", "powerset",
-        "ppder", "ppint", "ppjumps", "ppplot", "ppval",
-        "pqpnonneg", "prepad", "primes", "print",
-        "print_usage", "prism", "probit", "qp", "qqplot",
-        "quadcc", "quadgk", "quadl", "quadv", "quiver",
-        "qzhess", "rainbow", "randi", "range", "rank",
-        "ranks", "rat", "reallog", "realpow", "realsqrt",
-        "record", "rectangle_lw", "rectangle_sw",
-        "rectint", "refresh", "refreshdata",
-        "regexptranslate", "repmat", "residue", "ribbon",
-        "rindex", "roots", "rose", "rosser", "rotdim",
-        "rref", "run", "run_count", "rundemos", "run_test",
-        "runtests", "saveas", "saveaudio", "saveobj",
-        "savepath", "scatter", "secd", "semilogx",
-        "semilogxerr", "semilogy", "semilogyerr",
-        "setaudio", "setdiff", "setfield", "setxor",
-        "shading", "shift", "shiftdim", "sign_test",
-        "sinc", "sind", "sinetone", "sinewave", "skewness",
-        "slice", "sombrero", "sortrows", "spaugment",
-        "spconvert", "spdiags", "spearman", "spectral_adf",
-        "spectral_xdf", "specular", "speed", "spencer",
-        "speye", "spfun", "sphere", "spinmap", "spline",
-        "spones", "sprand", "sprandn", "sprandsym",
-        "spring", "spstats", "spy", "sqp", "stairs",
-        "statistics", "std", "stdnormal_cdf",
-        "stdnormal_inv", "stdnormal_pdf", "stdnormal_rnd",
-        "stem", "stft", "strcat", "strchr", "strjust",
-        "strmatch", "strread", "strsplit", "strtok",
-        "strtrim", "strtrunc", "structfun", "studentize",
-        "subplot", "subsindex", "subspace", "substr",
-        "substruct", "summer", "surf", "surface", "surfc",
-        "surfl", "surfnorm", "svds", "swapbytes",
-        "sylvester_matrix", "symvar", "synthesis", "table",
-        "tand", "tar", "tcdf", "tempdir", "tempname",
-        "test", "text", "textread", "textscan", "tinv",
-        "title", "toeplitz", "tpdf", "trace", "trapz",
-        "treelayout", "treeplot", "triangle_lw",
-        "triangle_sw", "tril", "trimesh", "triplequad",
-        "triplot", "trisurf", "triu", "trnd", "tsearchn",
-        "t_test", "t_test_regression", "type", "unidcdf",
-        "unidinv", "unidpdf", "unidrnd", "unifcdf",
-        "unifinv", "unifpdf", "unifrnd", "union", "unique",
-        "unix", "unmkpp", "unpack", "untabify", "untar",
-        "unwrap", "unzip", "u_test", "validatestring",
-        "vander", "var", "var_test", "vech", "ver",
-        "version", "view", "voronoi", "voronoin",
-        "waitforbuttonpress", "wavread", "wavwrite",
-        "wblcdf", "wblinv", "wblpdf", "wblrnd", "weekday",
-        "welch_test", "what", "white", "whitebg",
-        "wienrnd", "wilcoxon_test", "wilkinson", "winter",
-        "xlabel", "xlim", "ylabel", "yulewalker", "zip",
-        "zlabel", "z_test")
-
-    loadable_kw = (
-        "airy", "amd", "balance", "besselh", "besseli",
-        "besselj", "besselk", "bessely", "bitpack",
-        "bsxfun", "builtin", "ccolamd", "cellfun",
-        "cellslices", "chol", "choldelete", "cholinsert",
-        "cholinv", "cholshift", "cholupdate", "colamd",
-        "colloc", "convhulln", "convn", "csymamd",
-        "cummax", "cummin", "daspk", "daspk_options",
-        "dasrt", "dasrt_options", "dassl", "dassl_options",
-        "dbclear", "dbdown", "dbstack", "dbstatus",
-        "dbstop", "dbtype", "dbup", "dbwhere", "det",
-        "dlmread", "dmperm", "dot", "eig", "eigs",
-        "endgrent", "endpwent", "etree", "fft", "fftn",
-        "fftw", "filter", "find", "full", "gcd",
-        "getgrent", "getgrgid", "getgrnam", "getpwent",
-        "getpwnam", "getpwuid", "getrusage", "givens",
-        "gmtime", "gnuplot_binary", "hess", "ifft",
-        "ifftn", "inv", "isdebugmode", "issparse", "kron",
-        "localtime", "lookup", "lsode", "lsode_options",
-        "lu", "luinc", "luupdate", "matrix_type", "max",
-        "min", "mktime", "pinv", "qr", "qrdelete",
-        "qrinsert", "qrshift", "qrupdate", "quad",
-        "quad_options", "qz", "rand", "rande", "randg",
-        "randn", "randp", "randperm", "rcond", "regexp",
-        "regexpi", "regexprep", "schur", "setgrent",
-        "setpwent", "sort", "spalloc", "sparse", "spparms",
-        "sprank", "sqrtm", "strfind", "strftime",
-        "strptime", "strrep", "svd", "svd_driver", "syl",
-        "symamd", "symbfact", "symrcm", "time", "tsearch",
-        "typecast", "urlread", "urlwrite")
-
-    mapping_kw = (
-        "abs", "acos", "acosh", "acot", "acoth", "acsc",
-        "acsch", "angle", "arg", "asec", "asech", "asin",
-        "asinh", "atan", "atanh", "beta", "betainc",
-        "betaln", "bincoeff", "cbrt", "ceil", "conj", "cos",
-        "cosh", "cot", "coth", "csc", "csch", "erf", "erfc",
-        "erfcx", "erfinv", "exp", "finite", "fix", "floor",
-        "fmod", "gamma", "gammainc", "gammaln", "imag",
-        "isalnum", "isalpha", "isascii", "iscntrl",
-        "isdigit", "isfinite", "isgraph", "isinf",
-        "islower", "isna", "isnan", "isprint", "ispunct",
-        "isspace", "isupper", "isxdigit", "lcm", "lgamma",
-        "log", "lower", "mod", "real", "rem", "round",
-        "roundb", "sec", "sech", "sign", "sin", "sinh",
-        "sqrt", "tan", "tanh", "toascii", "tolower", "xor")
-
-    builtin_consts = (
-        "EDITOR", "EXEC_PATH", "I", "IMAGE_PATH", "NA",
-        "OCTAVE_HOME", "OCTAVE_VERSION", "PAGER",
-        "PAGER_FLAGS", "SEEK_CUR", "SEEK_END", "SEEK_SET",
-        "SIG", "S_ISBLK", "S_ISCHR", "S_ISDIR", "S_ISFIFO",
-        "S_ISLNK", "S_ISREG", "S_ISSOCK", "WCONTINUE",
-        "WCOREDUMP", "WEXITSTATUS", "WIFCONTINUED",
-        "WIFEXITED", "WIFSIGNALED", "WIFSTOPPED", "WNOHANG",
-        "WSTOPSIG", "WTERMSIG", "WUNTRACED")
-
-    tokens = {
-        'root': [
-            (r'%\{\s*\n', Comment.Multiline, 'percentblockcomment'),
-            (r'#\{\s*\n', Comment.Multiline, 'hashblockcomment'),
-            (r'[%#].*$', Comment),
-            (r'^\s*function\b', Keyword, 'deffunc'),
-
-            # from 'iskeyword' on hg changeset 8cc154f45e37
-            (words((
-                '__FILE__', '__LINE__', 'break', 'case', 'catch', 'classdef',
-                'continue', 'do', 'else', 'elseif', 'end', 'end_try_catch',
-                'end_unwind_protect', 'endclassdef', 'endevents', 'endfor',
-                'endfunction', 'endif', 'endmethods', 'endproperties', 'endswitch',
-                'endwhile', 'events', 'for', 'function', 'get', 'global', 'if',
-                'methods', 'otherwise', 'persistent', 'properties', 'return',
-                'set', 'static', 'switch', 'try', 'until', 'unwind_protect',
-                'unwind_protect_cleanup', 'while'), suffix=r'\b'),
-             Keyword),
-
-            (words(builtin_kw + command_kw + function_kw + loadable_kw + mapping_kw,
-                   suffix=r'\b'),  Name.Builtin),
-
-            (words(builtin_consts, suffix=r'\b'), Name.Constant),
-
-            # operators in Octave but not Matlab:
-            (r'-=|!=|!|/=|--', Operator),
-            # operators:
-            (r'-|==|~=|<|>|<=|>=|&&|&|~|\|\|?', Operator),
-            # operators in Octave but not Matlab requiring escape for re:
-            (r'\*=|\+=|\^=|\/=|\\=|\*\*|\+\+|\.\*\*', Operator),
-            # operators requiring escape for re:
-            (r'\.\*|\*|\+|\.\^|\^|\.\\|\.\/|\/|\\', Operator),
-
-
-            # punctuation:
-            (r'[\[\](){}:@.,]', Punctuation),
-            (r'=|:|;', Punctuation),
-
-            (r'"[^"]*"', String),
-
-            (r'(\d+\.\d*|\d*\.\d+)([eEf][+-]?[0-9]+)?', Number.Float),
-            (r'\d+[eEf][+-]?[0-9]+', Number.Float),
-            (r'\d+', Number.Integer),
-
-            # quote can be transpose, instead of string:
-            # (not great, but handles common cases...)
-            (r'(?<=[\w)\].])\'+', Operator),
-            (r'(?|<=|>=|&&|&|~|\|\|?', Operator),
-            # operators requiring escape for re:
-            (r'\.\*|\*|\+|\.\^|\^|\.\\|\.\/|\/|\\', Operator),
-
-            # punctuation:
-            (r'[\[\](){}@.,=:;]+', Punctuation),
-
-            (r'"[^"]*"', String),
-
-            # quote can be transpose, instead of string:
-            # (not great, but handles common cases...)
-            (r'(?<=[\w)\].])\'+', Operator),
-            (r'(?', r'<', r'|', r'!', r"'")
-
-    operator_words = ('and', 'or', 'not')
-
-    tokens = {
-        'root': [
-            (r'/\*', Comment.Multiline, 'comment'),
-            (r'"(?:[^"\\]|\\.)*"', String),
-            (r'\(|\)|\[|\]|\{|\}', Punctuation),
-            (r'[,;$]', Punctuation),
-            (words (constants), Name.Constant),
-            (words (keywords), Keyword),
-            (words (operators), Operator),
-            (words (operator_words), Operator.Word),
-            (r'''(?x)
-              ((?:[a-zA-Z_#][\w#]*|`[^`]*`)
-              (?:::[a-zA-Z_#][\w#]*|`[^`]*`)*)(\s*)([(])''',
-             bygroups(Name.Function, Text.Whitespace, Punctuation)),
-            (r'''(?x)
-              (?:[a-zA-Z_#%][\w#%]*|`[^`]*`)
-              (?:::[a-zA-Z_#%][\w#%]*|`[^`]*`)*''', Name.Variable),
-            (r'[-+]?(\d*\.\d+([bdefls][-+]?\d+)?|\d+(\.\d*)?[bdefls][-+]?\d+)', Number.Float),
-            (r'[-+]?\d+', Number.Integer),
-            (r'\s+', Text.Whitespace),
-            (r'.', Text)
-        ],
-        'comment': [
-            (r'[^*/]+', Comment.Multiline),
-            (r'/\*', Comment.Multiline, '#push'),
-            (r'\*/', Comment.Multiline, '#pop'),
-            (r'[*/]', Comment.Multiline)
-        ]
-    }
-
-    def analyse_text (text):
-        strength = 0.0
-        # Input expression terminator.
-        if re.search (r'\$\s*$', text, re.MULTILINE):
-            strength += 0.05
-        # Function definition operator.
-        if ':=' in text:
-            strength += 0.02
-        return strength
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/meson.py b/.venv/lib/python3.12/site-packages/pygments/lexers/meson.py
deleted file mode 100644
index 154a2de..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/meson.py
+++ /dev/null
@@ -1,139 +0,0 @@
-"""
-    pygments.lexers.meson
-    ~~~~~~~~~~~~~~~~~~~~~
-
-    Pygments lexer for the Meson build system
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-from pygments.lexer import RegexLexer, words, include
-from pygments.token import Comment, Name, Number, Punctuation, Operator, \
-    Keyword, String, Whitespace
-
-__all__ = ['MesonLexer']
-
-
-class MesonLexer(RegexLexer):
-    """Meson language lexer.
-
-    The grammar definition use to transcribe the syntax was retrieved from
-    https://mesonbuild.com/Syntax.html#grammar for version 0.58.
-    Some of those definitions are improperly transcribed, so the Meson++
-    implementation was also checked: https://github.com/dcbaker/meson-plus-plus.
-    """
-
-    # TODO String interpolation @VARNAME@ inner matches
-    # TODO keyword_arg: value inner matches
-
-    name = 'Meson'
-    url = 'https://mesonbuild.com/'
-    aliases = ['meson', 'meson.build']
-    filenames = ['meson.build', 'meson.options', 'meson_options.txt']
-    mimetypes = ['text/x-meson']
-    version_added = '2.10'
-
-    tokens = {
-        'root': [
-            (r'#.*?$', Comment),
-            (r"'''.*'''", String.Single),
-            (r'[1-9][0-9]*', Number.Integer),
-            (r'0o[0-7]+', Number.Oct),
-            (r'0x[a-fA-F0-9]+', Number.Hex),
-            include('string'),
-            include('keywords'),
-            include('expr'),
-            (r'[a-zA-Z_][a-zA-Z_0-9]*', Name),
-            (r'\s+', Whitespace),
-        ],
-        'string': [
-            (r"[']{3}([']{0,2}([^\\']|\\(.|\n)))*[']{3}", String),
-            (r"'.*?(?`_.
-    """
-
-    name = "MCFunction"
-    url = "https://minecraft.wiki/w/Commands"
-    aliases = ["mcfunction", "mcf"]
-    filenames = ["*.mcfunction"]
-    mimetypes = ["text/mcfunction"]
-    version_added = '2.12'
-
-    # Used to denotate the start of a block comment, borrowed from Github's mcfunction
-    _block_comment_prefix = "[>!]"
-
-    tokens = {
-        "root": [
-            include("names"),
-            include("comments"),
-            include("literals"),
-            include("whitespace"),
-            include("property"),
-            include("operators"),
-            include("selectors"),
-        ],
-
-        "names": [
-            # The start of a command (either beginning of line OR after the run keyword)
-            #  We don't encode a list of keywords since mods, plugins, or even pre-processors
-            #  may add new commands, so we have a 'close-enough' regex which catches them.
-            (r"^(\s*)([a-z_]+)", bygroups(Whitespace, Name.Builtin)),
-            (r"(?<=run)\s+[a-z_]+", Name.Builtin),
-
-            # UUID
-            (r"\b[0-9a-fA-F]+(?:-[0-9a-fA-F]+){4}\b", Name.Variable),
-            include("resource-name"),
-            # normal command names and scoreboards
-            #  there's no way to know the differences unfortuntely
-            (r"[A-Za-z_][\w.#%$]+", Keyword.Constant),
-            (r"[#%$][\w.#%$]+", Name.Variable.Magic),
-        ],
-
-        "resource-name": [
-            # resource names have to be lowercase
-            (r"#?[a-z_][a-z_.-]*:[a-z0-9_./-]+", Name.Function),
-            # similar to above except optional `:``
-            #  a `/` must be present "somewhere"
-            (r"#?[a-z0-9_\.\-]+\/[a-z0-9_\.\-\/]+", Name.Function),
-        ],
-
-        "whitespace": [
-            (r"\s+", Whitespace),
-        ],
-
-        "comments": [
-            (rf"^\s*(#{_block_comment_prefix})", Comment.Multiline,
-             ("comments.block", "comments.block.emphasized")),
-            (r"#.*$", Comment.Single),
-        ],
-        "comments.block": [
-            (rf"^\s*#{_block_comment_prefix}", Comment.Multiline,
-             "comments.block.emphasized"),
-            (r"^\s*#", Comment.Multiline, "comments.block.normal"),
-            default("#pop"),
-        ],
-        "comments.block.normal": [
-            include("comments.block.special"),
-            (r"\S+", Comment.Multiline),
-            (r"\n", Text, "#pop"),
-            include("whitespace"),
-        ],
-        "comments.block.emphasized": [
-            include("comments.block.special"),
-            (r"\S+", String.Doc),
-            (r"\n", Text, "#pop"),
-            include("whitespace"),
-        ],
-        "comments.block.special": [
-            # Params
-            (r"@\S+", Name.Decorator),
-
-            include("resource-name"),
-
-            # Scoreboard player names
-            (r"[#%$][\w.#%$]+", Name.Variable.Magic),
-        ],
-
-        "operators": [
-            (r"[\-~%^?!+*<>\\/|&=.]", Operator),
-        ],
-
-        "literals": [
-            (r"\.\.", Literal),
-            (r"(true|false)", Keyword.Pseudo),
-
-            # these are like unquoted strings and appear in many places
-            (r"[A-Za-z_]+", Name.Variable.Class),
-
-            (r"[0-7]b", Number.Byte),
-            (r"[+-]?\d*\.?\d+([eE]?[+-]?\d+)?[df]?\b", Number.Float),
-            (r"[+-]?\d+\b", Number.Integer),
-            (r'"', String.Double, "literals.string-double"),
-            (r"'", String.Single, "literals.string-single"),
-        ],
-        "literals.string-double": [
-            (r"\\.", String.Escape),
-            (r'[^\\"\n]+', String.Double),
-            (r'"', String.Double, "#pop"),
-        ],
-        "literals.string-single": [
-            (r"\\.", String.Escape),
-            (r"[^\\'\n]+", String.Single),
-            (r"'", String.Single, "#pop"),
-        ],
-
-        "selectors": [
-            (r"@[a-z]", Name.Variable),
-        ],
-
-
-        ## Generic Property Container
-        # There are several, differing instances where the language accepts
-        #  specific contained keys or contained key, value pairings.
-        #
-        # Property Maps:
-        # - Starts with either `[` or `{`
-        # - Key separated by `:` or `=`
-        # - Deliminated by `,`
-        #
-        # Property Lists:
-        # - Starts with `[`
-        # - Deliminated by `,`
-        #
-        # For simplicity, these patterns match a generic, nestable structure
-        #  which follow a key, value pattern. For normal lists, there's only keys.
-        # This allow some "illegal" structures, but we'll accept those for
-        #  sake of simplicity
-        #
-        # Examples:
-        # - `[facing=up, powered=true]` (blockstate)
-        # - `[name="hello world", nbt={key: 1b}]` (selector + nbt)
-        # - `[{"text": "value"}, "literal"]` (json)
-        ##
-        "property": [
-            # This state gets included in root and also several substates
-            # We do this to shortcut the starting of new properties
-            #  within other properties. Lists can have sublists and compounds
-            #  and values can start a new property (see the `difficult_1.txt`
-            #  snippet).
-            (r"\{", Punctuation, ("property.curly", "property.key")),
-            (r"\[", Punctuation, ("property.square", "property.key")),
-        ],
-        "property.curly": [
-            include("whitespace"),
-            include("property"),
-            (r"\}", Punctuation, "#pop"),
-        ],
-        "property.square": [
-            include("whitespace"),
-            include("property"),
-            (r"\]", Punctuation, "#pop"),
-
-            # lists can have sequences of items
-            (r",", Punctuation),
-        ],
-        "property.key": [
-            include("whitespace"),
-
-            # resource names (for advancements)
-            #  can omit `:` to default `minecraft:`
-            # must check if there is a future equals sign if `:` is in the name
-            (r"#?[a-z_][a-z_\.\-]*\:[a-z0-9_\.\-/]+(?=\s*\=)", Name.Attribute, "property.delimiter"),
-            (r"#?[a-z_][a-z0-9_\.\-/]+", Name.Attribute, "property.delimiter"),
-
-            # unquoted NBT key
-            (r"[A-Za-z_\-\+]+", Name.Attribute, "property.delimiter"),
-
-            # quoted JSON or NBT key
-            (r'"', Name.Attribute, "property.delimiter", "literals.string-double"),
-            (r"'", Name.Attribute, "property.delimiter", "literals.string-single"),
-
-            # index for a list
-            (r"-?\d+", Number.Integer, "property.delimiter"),
-
-            default("#pop"),
-        ],
-        "property.key.string-double": [
-            (r"\\.", String.Escape),
-            (r'[^\\"\n]+', Name.Attribute),
-            (r'"', Name.Attribute, "#pop"),
-        ],
-        "property.key.string-single": [
-            (r"\\.", String.Escape),
-            (r"[^\\'\n]+", Name.Attribute),
-            (r"'", Name.Attribute, "#pop"),
-        ],
-        "property.delimiter": [
-            include("whitespace"),
-
-            (r"[:=]!?", Punctuation, "property.value"),
-            (r",", Punctuation),
-
-            default("#pop"),
-        ],
-        "property.value": [
-            include("whitespace"),
-
-            # unquoted resource names are valid literals here
-            (r"#?[a-z_][a-z_\.\-]*\:[a-z0-9_\.\-/]+", Name.Tag),
-            (r"#?[a-z_][a-z0-9_\.\-/]+", Name.Tag),
-
-            include("literals"),
-            include("property"),
-
-            default("#pop"),
-        ],
-    }
-
-
-class MCSchemaLexer(RegexLexer):
-    """Lexer for Minecraft Add-ons data Schemas, an interface structure standard used in Minecraft
-    """
-
-    name = 'MCSchema'
-    url = 'https://learn.microsoft.com/en-us/minecraft/creator/reference/content/schemasreference/'
-    aliases = ['mcschema']
-    filenames = ['*.mcschema']
-    mimetypes = ['text/mcschema']
-    version_added = '2.14'
-
-    tokens = {
-        'commentsandwhitespace': [
-            (r'\s+', Whitespace),
-            (r'//.*?$', Comment.Single),
-            (r'/\*.*?\*/', Comment.Multiline)
-        ],
-        'slashstartsregex': [
-            include('commentsandwhitespace'),
-            (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/'
-             r'([gimuysd]+\b|\B)', String.Regex, '#pop'),
-            (r'(?=/)', Text, ('#pop', 'badregex')),
-            default('#pop')
-        ],
-        'badregex': [
-            (r'\n', Whitespace, '#pop')
-        ],
-        'singlestring': [
-            (r'\\.', String.Escape),
-            (r"'", String.Single, '#pop'),
-            (r"[^\\']+", String.Single),
-        ],
-        'doublestring': [
-            (r'\\.', String.Escape),
-            (r'"', String.Double, '#pop'),
-            (r'[^\\"]+', String.Double),
-        ],
-        'root': [
-            (r'^(?=\s|/|', Comment, '#pop'),
-            (r'[^\-]+|-', Comment),
-        ],
-    }
-
-
-class ReasonLexer(RegexLexer):
-    """
-    For the ReasonML language.
-    """
-
-    name = 'ReasonML'
-    url = 'https://reasonml.github.io/'
-    aliases = ['reasonml', 'reason']
-    filenames = ['*.re', '*.rei']
-    mimetypes = ['text/x-reasonml']
-    version_added = '2.6'
-
-    keywords = (
-        'as', 'assert', 'begin', 'class', 'constraint', 'do', 'done', 'downto',
-        'else', 'end', 'exception', 'external', 'false', 'for', 'fun', 'esfun',
-        'function', 'functor', 'if', 'in', 'include', 'inherit', 'initializer', 'lazy',
-        'let', 'switch', 'module', 'pub', 'mutable', 'new', 'nonrec', 'object', 'of',
-        'open', 'pri', 'rec', 'sig', 'struct', 'then', 'to', 'true', 'try',
-        'type', 'val', 'virtual', 'when', 'while', 'with',
-    )
-    keyopts = (
-        '!=', '#', '&', '&&', r'\(', r'\)', r'\*', r'\+', ',', '-',
-        r'-\.', '=>', r'\.', r'\.\.', r'\.\.\.', ':', '::', ':=', ':>', ';', ';;', '<',
-        '<-', '=', '>', '>]', r'>\}', r'\?', r'\?\?', r'\[', r'\[<', r'\[>',
-        r'\[\|', ']', '_', '`', r'\{', r'\{<', r'\|', r'\|\|', r'\|]', r'\}', '~'
-    )
-
-    operators = r'[!$%&*+\./:<=>?@^|~-]'
-    word_operators = ('and', 'asr', 'land', 'lor', 'lsl', 'lsr', 'lxor', 'mod', 'or')
-    prefix_syms = r'[!?~]'
-    infix_syms = r'[=<>@^|&+\*/$%-]'
-    primitives = ('unit', 'int', 'float', 'bool', 'string', 'char', 'list', 'array')
-
-    tokens = {
-        'escape-sequence': [
-            (r'\\[\\"\'ntbr]', String.Escape),
-            (r'\\[0-9]{3}', String.Escape),
-            (r'\\x[0-9a-fA-F]{2}', String.Escape),
-        ],
-        'root': [
-            (r'\s+', Text),
-            (r'false|true|\(\)|\[\]', Name.Builtin.Pseudo),
-            (r'\b([A-Z][\w\']*)(?=\s*\.)', Name.Namespace, 'dotted'),
-            (r'\b([A-Z][\w\']*)', Name.Class),
-            (r'//.*?\n', Comment.Single),
-            (r'\/\*(?!/)', Comment.Multiline, 'comment'),
-            (r'\b({})\b'.format('|'.join(keywords)), Keyword),
-            (r'({})'.format('|'.join(keyopts[::-1])), Operator.Word),
-            (rf'({infix_syms}|{prefix_syms})?{operators}', Operator),
-            (r'\b({})\b'.format('|'.join(word_operators)), Operator.Word),
-            (r'\b({})\b'.format('|'.join(primitives)), Keyword.Type),
-
-            (r"[^\W\d][\w']*", Name),
-
-            (r'-?\d[\d_]*(.[\d_]*)?([eE][+\-]?\d[\d_]*)', Number.Float),
-            (r'0[xX][\da-fA-F][\da-fA-F_]*', Number.Hex),
-            (r'0[oO][0-7][0-7_]*', Number.Oct),
-            (r'0[bB][01][01_]*', Number.Bin),
-            (r'\d[\d_]*', Number.Integer),
-
-            (r"'(?:(\\[\\\"'ntbr ])|(\\[0-9]{3})|(\\x[0-9a-fA-F]{2}))'",
-             String.Char),
-            (r"'.'", String.Char),
-            (r"'", Keyword),
-
-            (r'"', String.Double, 'string'),
-
-            (r'[~?][a-z][\w\']*:', Name.Variable),
-        ],
-        'comment': [
-            (r'[^/*]+', Comment.Multiline),
-            (r'\/\*', Comment.Multiline, '#push'),
-            (r'\*\/', Comment.Multiline, '#pop'),
-            (r'\*', Comment.Multiline),
-        ],
-        'string': [
-            (r'[^\\"]+', String.Double),
-            include('escape-sequence'),
-            (r'\\\n', String.Double),
-            (r'"', String.Double, '#pop'),
-        ],
-        'dotted': [
-            (r'\s+', Text),
-            (r'\.', Punctuation),
-            (r'[A-Z][\w\']*(?=\s*\.)', Name.Namespace),
-            (r'[A-Z][\w\']*', Name.Class, '#pop'),
-            (r'[a-z_][\w\']*', Name, '#pop'),
-            default('#pop'),
-        ],
-    }
-
-
-class FStarLexer(RegexLexer):
-    """
-    For the F* language.
-    """
-
-    name = 'FStar'
-    url = 'https://www.fstar-lang.org/'
-    aliases = ['fstar']
-    filenames = ['*.fst', '*.fsti']
-    mimetypes = ['text/x-fstar']
-    version_added = '2.7'
-
-    keywords = (
-        'abstract', 'attributes', 'noeq', 'unopteq', 'and'
-        'begin', 'by', 'default', 'effect', 'else', 'end', 'ensures',
-        'exception', 'exists', 'false', 'forall', 'fun', 'function', 'if',
-        'in', 'include', 'inline', 'inline_for_extraction', 'irreducible',
-        'logic', 'match', 'module', 'mutable', 'new', 'new_effect', 'noextract',
-        'of', 'open', 'opaque', 'private', 'range_of', 'reifiable',
-        'reify', 'reflectable', 'requires', 'set_range_of', 'sub_effect',
-        'synth', 'then', 'total', 'true', 'try', 'type', 'unfold', 'unfoldable',
-        'val', 'when', 'with', 'not'
-    )
-    decl_keywords = ('let', 'rec')
-    assume_keywords = ('assume', 'admit', 'assert', 'calc')
-    keyopts = (
-        r'~', r'-', r'/\\', r'\\/', r'<:', r'<@', r'\(\|', r'\|\)', r'#', r'u#',
-        r'&', r'\(', r'\)', r'\(\)', r',', r'~>', r'->', r'<-', r'<--', r'<==>',
-        r'==>', r'\.', r'\?', r'\?\.', r'\.\[', r'\.\(', r'\.\(\|', r'\.\[\|',
-        r'\{:pattern', r':', r'::', r':=', r';', r';;', r'=', r'%\[', r'!\{',
-        r'\[', r'\[@', r'\[\|', r'\|>', r'\]', r'\|\]', r'\{', r'\|', r'\}', r'\$'
-    )
-
-    operators = r'[!$%&*+\./:<=>?@^|~-]'
-    prefix_syms = r'[!?~]'
-    infix_syms = r'[=<>@^|&+\*/$%-]'
-    primitives = ('unit', 'int', 'float', 'bool', 'string', 'char', 'list', 'array')
-
-    tokens = {
-        'escape-sequence': [
-            (r'\\[\\"\'ntbr]', String.Escape),
-            (r'\\[0-9]{3}', String.Escape),
-            (r'\\x[0-9a-fA-F]{2}', String.Escape),
-        ],
-        'root': [
-            (r'\s+', Text),
-            (r'false|true|False|True|\(\)|\[\]', Name.Builtin.Pseudo),
-            (r'\b([A-Z][\w\']*)(?=\s*\.)', Name.Namespace, 'dotted'),
-            (r'\b([A-Z][\w\']*)', Name.Class),
-            (r'\(\*(?![)])', Comment, 'comment'),
-            (r'\/\/.+$', Comment),
-            (r'\b({})\b'.format('|'.join(keywords)), Keyword),
-            (r'\b({})\b'.format('|'.join(assume_keywords)), Name.Exception),
-            (r'\b({})\b'.format('|'.join(decl_keywords)), Keyword.Declaration),
-            (r'({})'.format('|'.join(keyopts[::-1])), Operator),
-            (rf'({infix_syms}|{prefix_syms})?{operators}', Operator),
-            (r'\b({})\b'.format('|'.join(primitives)), Keyword.Type),
-
-            (r"[^\W\d][\w']*", Name),
-
-            (r'-?\d[\d_]*(.[\d_]*)?([eE][+\-]?\d[\d_]*)', Number.Float),
-            (r'0[xX][\da-fA-F][\da-fA-F_]*', Number.Hex),
-            (r'0[oO][0-7][0-7_]*', Number.Oct),
-            (r'0[bB][01][01_]*', Number.Bin),
-            (r'\d[\d_]*', Number.Integer),
-
-            (r"'(?:(\\[\\\"'ntbr ])|(\\[0-9]{3})|(\\x[0-9a-fA-F]{2}))'",
-             String.Char),
-            (r"'.'", String.Char),
-            (r"'", Keyword),  # a stray quote is another syntax element
-            (r"\`([\w\'.]+)\`", Operator.Word),  # for infix applications
-            (r"\`", Keyword),  # for quoting
-            (r'"', String.Double, 'string'),
-
-            (r'[~?][a-z][\w\']*:', Name.Variable),
-        ],
-        'comment': [
-            (r'[^(*)]+', Comment),
-            (r'\(\*', Comment, '#push'),
-            (r'\*\)', Comment, '#pop'),
-            (r'[(*)]', Comment),
-        ],
-        'string': [
-            (r'[^\\"]+', String.Double),
-            include('escape-sequence'),
-            (r'\\\n', String.Double),
-            (r'"', String.Double, '#pop'),
-        ],
-        'dotted': [
-            (r'\s+', Text),
-            (r'\.', Punctuation),
-            (r'[A-Z][\w\']*(?=\s*\.)', Name.Namespace),
-            (r'[A-Z][\w\']*', Name.Class, '#pop'),
-            (r'[a-z_][\w\']*', Name, '#pop'),
-            default('#pop'),
-        ],
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/modeling.py b/.venv/lib/python3.12/site-packages/pygments/lexers/modeling.py
deleted file mode 100644
index 4c22aeb..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/modeling.py
+++ /dev/null
@@ -1,368 +0,0 @@
-"""
-    pygments.lexers.modeling
-    ~~~~~~~~~~~~~~~~~~~~~~~~
-
-    Lexers for modeling languages.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-import re
-
-from pygments.lexer import RegexLexer, include, bygroups, using, default
-from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
-    Number, Punctuation, Whitespace
-
-from pygments.lexers.html import HtmlLexer
-from pygments.lexers import _stan_builtins
-
-__all__ = ['ModelicaLexer', 'BugsLexer', 'JagsLexer', 'StanLexer']
-
-
-class ModelicaLexer(RegexLexer):
-    """
-    For Modelica source code.
-    """
-    name = 'Modelica'
-    url = 'http://www.modelica.org/'
-    aliases = ['modelica']
-    filenames = ['*.mo']
-    mimetypes = ['text/x-modelica']
-    version_added = '1.1'
-
-    flags = re.DOTALL | re.MULTILINE
-
-    _name = r"(?:'(?:[^\\']|\\.)+'|[a-zA-Z_]\w*)"
-
-    tokens = {
-        'whitespace': [
-            (r'[\s\ufeff]+', Text),
-            (r'//[^\n]*\n?', Comment.Single),
-            (r'/\*.*?\*/', Comment.Multiline)
-        ],
-        'root': [
-            include('whitespace'),
-            (r'"', String.Double, 'string'),
-            (r'[()\[\]{},;]+', Punctuation),
-            (r'\.?[*^/+-]|\.|<>|[<>:=]=?', Operator),
-            (r'\d+(\.?\d*[eE][-+]?\d+|\.\d*)', Number.Float),
-            (r'\d+', Number.Integer),
-            (r'(abs|acos|actualStream|array|asin|assert|AssertionLevel|atan|'
-             r'atan2|backSample|Boolean|cardinality|cat|ceil|change|Clock|'
-             r'Connections|cos|cosh|cross|delay|diagonal|div|edge|exp|'
-             r'ExternalObject|fill|floor|getInstanceName|hold|homotopy|'
-             r'identity|inStream|integer|Integer|interval|inverse|isPresent|'
-             r'linspace|log|log10|matrix|max|min|mod|ndims|noClock|noEvent|'
-             r'ones|outerProduct|pre|previous|product|Real|reinit|rem|rooted|'
-             r'sample|scalar|semiLinear|shiftSample|sign|sin|sinh|size|skew|'
-             r'smooth|spatialDistribution|sqrt|StateSelect|String|subSample|'
-             r'sum|superSample|symmetric|tan|tanh|terminal|terminate|time|'
-             r'transpose|vector|zeros)\b', Name.Builtin),
-            (r'(algorithm|annotation|break|connect|constant|constrainedby|der|'
-             r'discrete|each|else|elseif|elsewhen|encapsulated|enumeration|'
-             r'equation|exit|expandable|extends|external|firstTick|final|flow|for|if|'
-             r'import|impure|in|initial|inner|input|interval|loop|nondiscrete|outer|'
-             r'output|parameter|partial|protected|public|pure|redeclare|'
-             r'replaceable|return|stream|then|when|while)\b',
-             Keyword.Reserved),
-            (r'(and|not|or)\b', Operator.Word),
-            (r'(block|class|connector|end|function|model|operator|package|'
-             r'record|type)\b', Keyword.Reserved, 'class'),
-            (r'(false|true)\b', Keyword.Constant),
-            (r'within\b', Keyword.Reserved, 'package-prefix'),
-            (_name, Name)
-        ],
-        'class': [
-            include('whitespace'),
-            (r'(function|record)\b', Keyword.Reserved),
-            (r'(if|for|when|while)\b', Keyword.Reserved, '#pop'),
-            (_name, Name.Class, '#pop'),
-            default('#pop')
-        ],
-        'package-prefix': [
-            include('whitespace'),
-            (_name, Name.Namespace, '#pop'),
-            default('#pop')
-        ],
-        'string': [
-            (r'"', String.Double, '#pop'),
-            (r'\\[\'"?\\abfnrtv]', String.Escape),
-            (r'(?i)<\s*html\s*>([^\\"]|\\.)+?(<\s*/\s*html\s*>|(?="))',
-             using(HtmlLexer)),
-            (r'<|\\?[^"\\<]+', String.Double)
-        ]
-    }
-
-
-class BugsLexer(RegexLexer):
-    """
-    Pygments Lexer for OpenBugs and WinBugs
-    models.
-    """
-
-    name = 'BUGS'
-    aliases = ['bugs', 'winbugs', 'openbugs']
-    filenames = ['*.bug']
-    url = 'https://www.mrc-bsu.cam.ac.uk/software/bugs/openbugs'
-    version_added = '1.6'
-
-    _FUNCTIONS = (
-        # Scalar functions
-        'abs', 'arccos', 'arccosh', 'arcsin', 'arcsinh', 'arctan', 'arctanh',
-        'cloglog', 'cos', 'cosh', 'cumulative', 'cut', 'density', 'deviance',
-        'equals', 'expr', 'gammap', 'ilogit', 'icloglog', 'integral', 'log',
-        'logfact', 'loggam', 'logit', 'max', 'min', 'phi', 'post.p.value',
-        'pow', 'prior.p.value', 'probit', 'replicate.post', 'replicate.prior',
-        'round', 'sin', 'sinh', 'solution', 'sqrt', 'step', 'tan', 'tanh',
-        'trunc',
-        # Vector functions
-        'inprod', 'interp.lin', 'inverse', 'logdet', 'mean', 'eigen.vals',
-        'ode', 'prod', 'p.valueM', 'rank', 'ranked', 'replicate.postM',
-        'sd', 'sort', 'sum',
-        # Special
-        'D', 'I', 'F', 'T', 'C')
-    """ OpenBUGS built-in functions
-
-    From http://www.openbugs.info/Manuals/ModelSpecification.html#ContentsAII
-
-    This also includes
-
-    - T, C, I : Truncation and censoring.
-      ``T`` and ``C`` are in OpenBUGS. ``I`` in WinBUGS.
-    - D : ODE
-    - F : Functional http://www.openbugs.info/Examples/Functionals.html
-
-    """
-
-    _DISTRIBUTIONS = ('dbern', 'dbin', 'dcat', 'dnegbin', 'dpois',
-                      'dhyper', 'dbeta', 'dchisqr', 'ddexp', 'dexp',
-                      'dflat', 'dgamma', 'dgev', 'df', 'dggamma', 'dgpar',
-                      'dloglik', 'dlnorm', 'dlogis', 'dnorm', 'dpar',
-                      'dt', 'dunif', 'dweib', 'dmulti', 'ddirch', 'dmnorm',
-                      'dmt', 'dwish')
-    """ OpenBUGS built-in distributions
-
-    Functions from
-    http://www.openbugs.info/Manuals/ModelSpecification.html#ContentsAI
-    """
-
-    tokens = {
-        'whitespace': [
-            (r"\s+", Text),
-        ],
-        'comments': [
-            # Comments
-            (r'#.*$', Comment.Single),
-        ],
-        'root': [
-            # Comments
-            include('comments'),
-            include('whitespace'),
-            # Block start
-            (r'(model)(\s+)(\{)',
-             bygroups(Keyword.Namespace, Text, Punctuation)),
-            # Reserved Words
-            (r'(for|in)(?![\w.])', Keyword.Reserved),
-            # Built-in Functions
-            (r'({})(?=\s*\()'.format(r'|'.join(_FUNCTIONS + _DISTRIBUTIONS)),
-             Name.Builtin),
-            # Regular variable names
-            (r'[A-Za-z][\w.]*', Name),
-            # Number Literals
-            (r'[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?', Number),
-            # Punctuation
-            (r'\[|\]|\(|\)|:|,|;', Punctuation),
-            # Assignment operators
-            # SLexer makes these tokens Operators.
-            (r'<-|~', Operator),
-            # Infix and prefix operators
-            (r'\+|-|\*|/', Operator),
-            # Block
-            (r'[{}]', Punctuation),
-        ]
-    }
-
-    def analyse_text(text):
-        if re.search(r"^\s*model\s*{", text, re.M):
-            return 0.7
-        else:
-            return 0.0
-
-
-class JagsLexer(RegexLexer):
-    """
-    Pygments Lexer for JAGS.
-    """
-
-    name = 'JAGS'
-    aliases = ['jags']
-    filenames = ['*.jag', '*.bug']
-    url = 'https://mcmc-jags.sourceforge.io'
-    version_added = '1.6'
-
-    # JAGS
-    _FUNCTIONS = (
-        'abs', 'arccos', 'arccosh', 'arcsin', 'arcsinh', 'arctan', 'arctanh',
-        'cos', 'cosh', 'cloglog',
-        'equals', 'exp', 'icloglog', 'ifelse', 'ilogit', 'log', 'logfact',
-        'loggam', 'logit', 'phi', 'pow', 'probit', 'round', 'sin', 'sinh',
-        'sqrt', 'step', 'tan', 'tanh', 'trunc', 'inprod', 'interp.lin',
-        'logdet', 'max', 'mean', 'min', 'prod', 'sum', 'sd', 'inverse',
-        'rank', 'sort', 't', 'acos', 'acosh', 'asin', 'asinh', 'atan',
-        # Truncation/Censoring (should I include)
-        'T', 'I')
-    # Distributions with density, probability and quartile functions
-    _DISTRIBUTIONS = tuple(f'[dpq]{x}' for x in
-                           ('bern', 'beta', 'dchiqsqr', 'ddexp', 'dexp',
-                            'df', 'gamma', 'gen.gamma', 'logis', 'lnorm',
-                            'negbin', 'nchisqr', 'norm', 'par', 'pois', 'weib'))
-    # Other distributions without density and probability
-    _OTHER_DISTRIBUTIONS = (
-        'dt', 'dunif', 'dbetabin', 'dbern', 'dbin', 'dcat', 'dhyper',
-        'ddirch', 'dmnorm', 'dwish', 'dmt', 'dmulti', 'dbinom', 'dchisq',
-        'dnbinom', 'dweibull', 'ddirich')
-
-    tokens = {
-        'whitespace': [
-            (r"\s+", Text),
-        ],
-        'names': [
-            # Regular variable names
-            (r'[a-zA-Z][\w.]*\b', Name),
-        ],
-        'comments': [
-            # do not use stateful comments
-            (r'(?s)/\*.*?\*/', Comment.Multiline),
-            # Comments
-            (r'#.*$', Comment.Single),
-        ],
-        'root': [
-            # Comments
-            include('comments'),
-            include('whitespace'),
-            # Block start
-            (r'(model|data)(\s+)(\{)',
-             bygroups(Keyword.Namespace, Text, Punctuation)),
-            (r'var(?![\w.])', Keyword.Declaration),
-            # Reserved Words
-            (r'(for|in)(?![\w.])', Keyword.Reserved),
-            # Builtins
-            # Need to use lookahead because . is a valid char
-            (r'({})(?=\s*\()'.format(r'|'.join(_FUNCTIONS
-                                          + _DISTRIBUTIONS
-                                          + _OTHER_DISTRIBUTIONS)),
-             Name.Builtin),
-            # Names
-            include('names'),
-            # Number Literals
-            (r'[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?', Number),
-            (r'\[|\]|\(|\)|:|,|;', Punctuation),
-            # Assignment operators
-            (r'<-|~', Operator),
-            # # JAGS includes many more than OpenBUGS
-            (r'\+|-|\*|\/|\|\|[&]{2}|[<>=]=?|\^|%.*?%', Operator),
-            (r'[{}]', Punctuation),
-        ]
-    }
-
-    def analyse_text(text):
-        if re.search(r'^\s*model\s*\{', text, re.M):
-            if re.search(r'^\s*data\s*\{', text, re.M):
-                return 0.9
-            elif re.search(r'^\s*var', text, re.M):
-                return 0.9
-            else:
-                return 0.3
-        else:
-            return 0
-
-
-class StanLexer(RegexLexer):
-    """Pygments Lexer for Stan models.
-
-    The Stan modeling language is specified in the *Stan Modeling Language
-    User's Guide and Reference Manual, v2.17.0*,
-    `pdf `__.
-    """
-
-    name = 'Stan'
-    aliases = ['stan']
-    filenames = ['*.stan']
-    url = 'https://mc-stan.org'
-    version_added = '1.6'
-
-    tokens = {
-        'whitespace': [
-            (r"\s+", Text),
-        ],
-        'comments': [
-            (r'(?s)/\*.*?\*/', Comment.Multiline),
-            # Comments
-            (r'(//|#).*$', Comment.Single),
-        ],
-        'root': [
-            (r'"[^"]*"', String),
-            # Comments
-            include('comments'),
-            # block start
-            include('whitespace'),
-            # Block start
-            (r'({})(\s*)(\{{)'.format(r'|'.join(('functions', 'data', r'transformed\s+?data',
-                        'parameters', r'transformed\s+parameters',
-                        'model', r'generated\s+quantities'))),
-             bygroups(Keyword.Namespace, Text, Punctuation)),
-            # target keyword
-            (r'target\s*\+=', Keyword),
-            # jacobian += statement
-            (r'jacobian\s*\+=', Keyword),
-            # Reserved Words
-            (r'({})\b'.format(r'|'.join(_stan_builtins.KEYWORDS)), Keyword),
-            # Truncation
-            (r'T(?=\s*\[)', Keyword),
-            # Data types
-            (r'({})\b'.format(r'|'.join(_stan_builtins.TYPES)), Keyword.Type),
-             # < should be punctuation, but elsewhere I can't tell if it is in
-             # a range constraint
-            (r'(<)(\s*)(upper|lower|offset|multiplier)(\s*)(=)',
-             bygroups(Operator, Whitespace, Keyword, Whitespace, Punctuation)),
-            (r'(,)(\s*)(upper)(\s*)(=)',
-             bygroups(Punctuation, Whitespace, Keyword, Whitespace, Punctuation)),
-            # Punctuation
-            (r"[;,\[\]()]", Punctuation),
-            # Builtin
-            (r'({})(?=\s*\()'.format('|'.join(_stan_builtins.FUNCTIONS)), Name.Builtin),
-            (r'(~)(\s*)({})(?=\s*\()'.format('|'.join(_stan_builtins.DISTRIBUTIONS)),
-                bygroups(Operator, Whitespace, Name.Builtin)),
-            # Special names ending in __, like lp__
-            (r'[A-Za-z]\w*__\b', Name.Builtin.Pseudo),
-            (r'({})\b'.format(r'|'.join(_stan_builtins.RESERVED)), Keyword.Reserved),
-            # user-defined functions
-            (r'[A-Za-z]\w*(?=\s*\()]', Name.Function),
-            # Imaginary Literals
-            (r'[0-9]+(\.[0-9]*)?([eE][+-]?[0-9]+)?i', Number.Float),
-            (r'\.[0-9]+([eE][+-]?[0-9]+)?i', Number.Float),
-            (r'[0-9]+i', Number.Float),
-            # Real Literals
-            (r'[0-9]+(\.[0-9]*)?([eE][+-]?[0-9]+)?', Number.Float),
-            (r'\.[0-9]+([eE][+-]?[0-9]+)?', Number.Float),
-            # Integer Literals
-            (r'[0-9]+', Number.Integer),
-            # Regular variable names
-            (r'[A-Za-z]\w*\b', Name),
-            # Assignment operators
-            (r'<-|(?:\+|-|\.?/|\.?\*|=)?=|~', Operator),
-            # Infix, prefix and postfix operators (and = )
-            (r"\+|-|\.?\*|\.?/|\\|'|\.?\^|!=?|<=?|>=?|\|\||&&|%|\?|:|%/%|!", Operator),
-            # Block delimiters
-            (r'[{}]', Punctuation),
-            # Distribution |
-            (r'\|', Punctuation)
-        ]
-    }
-
-    def analyse_text(text):
-        if re.search(r'^\s*parameters\s*\{', text, re.M):
-            return 1.0
-        else:
-            return 0.0
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/modula2.py b/.venv/lib/python3.12/site-packages/pygments/lexers/modula2.py
deleted file mode 100644
index c0ebd5c..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/modula2.py
+++ /dev/null
@@ -1,1579 +0,0 @@
-"""
-    pygments.lexers.modula2
-    ~~~~~~~~~~~~~~~~~~~~~~~
-
-    Multi-Dialect Lexer for Modula-2.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-import re
-
-from pygments.lexer import RegexLexer, include
-from pygments.util import get_bool_opt, get_list_opt
-from pygments.token import Text, Comment, Operator, Keyword, Name, \
-    String, Number, Punctuation, Error
-
-__all__ = ['Modula2Lexer']
-
-
-# Multi-Dialect Modula-2 Lexer
-class Modula2Lexer(RegexLexer):
-    """
-    For Modula-2 source code.
-
-    The Modula-2 lexer supports several dialects.  By default, it operates in
-    fallback mode, recognising the *combined* literals, punctuation symbols
-    and operators of all supported dialects, and the *combined* reserved words
-    and builtins of PIM Modula-2, ISO Modula-2 and Modula-2 R10, while not
-    differentiating between library defined identifiers.
-
-    To select a specific dialect, a dialect option may be passed
-    or a dialect tag may be embedded into a source file.
-
-    Dialect Options:
-
-    `m2pim`
-        Select PIM Modula-2 dialect.
-    `m2iso`
-        Select ISO Modula-2 dialect.
-    `m2r10`
-        Select Modula-2 R10 dialect.
-    `objm2`
-        Select Objective Modula-2 dialect.
-
-    The PIM and ISO dialect options may be qualified with a language extension.
-
-    Language Extensions:
-
-    `+aglet`
-        Select Aglet Modula-2 extensions, available with m2iso.
-    `+gm2`
-        Select GNU Modula-2 extensions, available with m2pim.
-    `+p1`
-        Select p1 Modula-2 extensions, available with m2iso.
-    `+xds`
-        Select XDS Modula-2 extensions, available with m2iso.
-
-
-    Passing a Dialect Option via Unix Commandline Interface
-
-    Dialect options may be passed to the lexer using the `dialect` key.
-    Only one such option should be passed. If multiple dialect options are
-    passed, the first valid option is used, any subsequent options are ignored.
-
-    Examples:
-
-    `$ pygmentize -O full,dialect=m2iso -f html -o /path/to/output /path/to/input`
-        Use ISO dialect to render input to HTML output
-    `$ pygmentize -O full,dialect=m2iso+p1 -f rtf -o /path/to/output /path/to/input`
-        Use ISO dialect with p1 extensions to render input to RTF output
-
-
-    Embedding a Dialect Option within a source file
-
-    A dialect option may be embedded in a source file in form of a dialect
-    tag, a specially formatted comment that specifies a dialect option.
-
-    Dialect Tag EBNF::
-
-       dialectTag :
-           OpeningCommentDelim Prefix dialectOption ClosingCommentDelim ;
-
-       dialectOption :
-           'm2pim' | 'm2iso' | 'm2r10' | 'objm2' |
-           'm2iso+aglet' | 'm2pim+gm2' | 'm2iso+p1' | 'm2iso+xds' ;
-
-       Prefix : '!' ;
-
-       OpeningCommentDelim : '(*' ;
-
-       ClosingCommentDelim : '*)' ;
-
-    No whitespace is permitted between the tokens of a dialect tag.
-
-    In the event that a source file contains multiple dialect tags, the first
-    tag that contains a valid dialect option will be used and any subsequent
-    dialect tags will be ignored.  Ideally, a dialect tag should be placed
-    at the beginning of a source file.
-
-    An embedded dialect tag overrides a dialect option set via command line.
-
-    Examples:
-
-    ``(*!m2r10*) DEFINITION MODULE Foobar; ...``
-        Use Modula2 R10 dialect to render this source file.
-    ``(*!m2pim+gm2*) DEFINITION MODULE Bazbam; ...``
-        Use PIM dialect with GNU extensions to render this source file.
-
-
-    Algol Publication Mode:
-
-    In Algol publication mode, source text is rendered for publication of
-    algorithms in scientific papers and academic texts, following the format
-    of the Revised Algol-60 Language Report.  It is activated by passing
-    one of two corresponding styles as an option:
-
-    `algol`
-        render reserved words lowercase underline boldface
-        and builtins lowercase boldface italic
-    `algol_nu`
-        render reserved words lowercase boldface (no underlining)
-        and builtins lowercase boldface italic
-
-    The lexer automatically performs the required lowercase conversion when
-    this mode is activated.
-
-    Example:
-
-    ``$ pygmentize -O full,style=algol -f latex -o /path/to/output /path/to/input``
-        Render input file in Algol publication mode to LaTeX output.
-
-
-    Rendering Mode of First Class ADT Identifiers:
-
-    The rendering of standard library first class ADT identifiers is controlled
-    by option flag "treat_stdlib_adts_as_builtins".
-
-    When this option is turned on, standard library ADT identifiers are rendered
-    as builtins.  When it is turned off, they are rendered as ordinary library
-    identifiers.
-
-    `treat_stdlib_adts_as_builtins` (default: On)
-
-    The option is useful for dialects that support ADTs as first class objects
-    and provide ADTs in the standard library that would otherwise be built-in.
-
-    At present, only Modula-2 R10 supports library ADTs as first class objects
-    and therefore, no ADT identifiers are defined for any other dialects.
-
-    Example:
-
-    ``$ pygmentize -O full,dialect=m2r10,treat_stdlib_adts_as_builtins=Off ...``
-        Render standard library ADTs as ordinary library types.
-
-    .. versionchanged:: 2.1
-       Added multi-dialect support.
-    """
-    name = 'Modula-2'
-    url = 'http://www.modula2.org/'
-    aliases = ['modula2', 'm2']
-    filenames = ['*.def', '*.mod']
-    mimetypes = ['text/x-modula2']
-    version_added = '1.3'
-
-    flags = re.MULTILINE | re.DOTALL
-
-    tokens = {
-        'whitespace': [
-            (r'\n+', Text),  # blank lines
-            (r'\s+', Text),  # whitespace
-        ],
-        'dialecttags': [
-            # PIM Dialect Tag
-            (r'\(\*!m2pim\*\)', Comment.Special),
-            # ISO Dialect Tag
-            (r'\(\*!m2iso\*\)', Comment.Special),
-            # M2R10 Dialect Tag
-            (r'\(\*!m2r10\*\)', Comment.Special),
-            # ObjM2 Dialect Tag
-            (r'\(\*!objm2\*\)', Comment.Special),
-            # Aglet Extensions Dialect Tag
-            (r'\(\*!m2iso\+aglet\*\)', Comment.Special),
-            # GNU Extensions Dialect Tag
-            (r'\(\*!m2pim\+gm2\*\)', Comment.Special),
-            # p1 Extensions Dialect Tag
-            (r'\(\*!m2iso\+p1\*\)', Comment.Special),
-            # XDS Extensions Dialect Tag
-            (r'\(\*!m2iso\+xds\*\)', Comment.Special),
-        ],
-        'identifiers': [
-            (r'([a-zA-Z_$][\w$]*)', Name),
-        ],
-        'prefixed_number_literals': [
-            #
-            # Base-2, whole number
-            (r'0b[01]+(\'[01]+)*', Number.Bin),
-            #
-            # Base-16, whole number
-            (r'0[ux][0-9A-F]+(\'[0-9A-F]+)*', Number.Hex),
-        ],
-        'plain_number_literals': [
-            #
-            # Base-10, real number with exponent
-            (r'[0-9]+(\'[0-9]+)*'  # integral part
-             r'\.[0-9]+(\'[0-9]+)*'  # fractional part
-             r'[eE][+-]?[0-9]+(\'[0-9]+)*',  # exponent
-             Number.Float),
-            #
-            # Base-10, real number without exponent
-            (r'[0-9]+(\'[0-9]+)*'  # integral part
-             r'\.[0-9]+(\'[0-9]+)*',  # fractional part
-             Number.Float),
-            #
-            # Base-10, whole number
-            (r'[0-9]+(\'[0-9]+)*', Number.Integer),
-        ],
-        'suffixed_number_literals': [
-            #
-            # Base-8, whole number
-            (r'[0-7]+B', Number.Oct),
-            #
-            # Base-8, character code
-            (r'[0-7]+C', Number.Oct),
-            #
-            # Base-16, number
-            (r'[0-9A-F]+H', Number.Hex),
-        ],
-        'string_literals': [
-            (r'"(\\\\|\\[^\\]|[^"\\])*"', String.Double),
-            (r"'(\\\\|\\[^\\]|[^'\\])*'", String.Single),
-        ],
-        'digraph_operators': [
-            # Dot Product Operator
-            (r'\*\.', Operator),
-            # Array Concatenation Operator
-            (r'\+>', Operator),  # M2R10 + ObjM2
-            # Inequality Operator
-            (r'<>', Operator),  # ISO + PIM
-            # Less-Or-Equal, Subset
-            (r'<=', Operator),
-            # Greater-Or-Equal, Superset
-            (r'>=', Operator),
-            # Identity Operator
-            (r'==', Operator),  # M2R10 + ObjM2
-            # Type Conversion Operator
-            (r'::', Operator),  # M2R10 + ObjM2
-            # Assignment Symbol
-            (r':=', Operator),
-            # Postfix Increment Mutator
-            (r'\+\+', Operator),  # M2R10 + ObjM2
-            # Postfix Decrement Mutator
-            (r'--', Operator),  # M2R10 + ObjM2
-        ],
-        'unigraph_operators': [
-            # Arithmetic Operators
-            (r'[+-]', Operator),
-            (r'[*/]', Operator),
-            # ISO 80000-2 compliant Set Difference Operator
-            (r'\\', Operator),  # M2R10 + ObjM2
-            # Relational Operators
-            (r'[=#<>]', Operator),
-            # Dereferencing Operator
-            (r'\^', Operator),
-            # Dereferencing Operator Synonym
-            (r'@', Operator),  # ISO
-            # Logical AND Operator Synonym
-            (r'&', Operator),  # PIM + ISO
-            # Logical NOT Operator Synonym
-            (r'~', Operator),  # PIM + ISO
-            # Smalltalk Message Prefix
-            (r'`', Operator),  # ObjM2
-        ],
-        'digraph_punctuation': [
-            # Range Constructor
-            (r'\.\.', Punctuation),
-            # Opening Chevron Bracket
-            (r'<<', Punctuation),  # M2R10 + ISO
-            # Closing Chevron Bracket
-            (r'>>', Punctuation),  # M2R10 + ISO
-            # Blueprint Punctuation
-            (r'->', Punctuation),  # M2R10 + ISO
-            # Distinguish |# and # in M2 R10
-            (r'\|#', Punctuation),
-            # Distinguish ## and # in M2 R10
-            (r'##', Punctuation),
-            # Distinguish |* and * in M2 R10
-            (r'\|\*', Punctuation),
-        ],
-        'unigraph_punctuation': [
-            # Common Punctuation
-            (r'[()\[\]{},.:;|]', Punctuation),
-            # Case Label Separator Synonym
-            (r'!', Punctuation),  # ISO
-            # Blueprint Punctuation
-            (r'\?', Punctuation),  # M2R10 + ObjM2
-        ],
-        'comments': [
-            # Single Line Comment
-            (r'^//.*?\n', Comment.Single),  # M2R10 + ObjM2
-            # Block Comment
-            (r'\(\*([^$].*?)\*\)', Comment.Multiline),
-            # Template Block Comment
-            (r'/\*(.*?)\*/', Comment.Multiline),  # M2R10 + ObjM2
-        ],
-        'pragmas': [
-            # ISO Style Pragmas
-            (r'<\*.*?\*>', Comment.Preproc),  # ISO, M2R10 + ObjM2
-            # Pascal Style Pragmas
-            (r'\(\*\$.*?\*\)', Comment.Preproc),  # PIM
-        ],
-        'root': [
-            include('whitespace'),
-            include('dialecttags'),
-            include('pragmas'),
-            include('comments'),
-            include('identifiers'),
-            include('suffixed_number_literals'),  # PIM + ISO
-            include('prefixed_number_literals'),  # M2R10 + ObjM2
-            include('plain_number_literals'),
-            include('string_literals'),
-            include('digraph_punctuation'),
-            include('digraph_operators'),
-            include('unigraph_punctuation'),
-            include('unigraph_operators'),
-        ]
-    }
-
-#  C o m m o n   D a t a s e t s
-
-    # Common Reserved Words Dataset
-    common_reserved_words = (
-        # 37 common reserved words
-        'AND', 'ARRAY', 'BEGIN', 'BY', 'CASE', 'CONST', 'DEFINITION', 'DIV',
-        'DO', 'ELSE', 'ELSIF', 'END', 'EXIT', 'FOR', 'FROM', 'IF',
-        'IMPLEMENTATION', 'IMPORT', 'IN', 'LOOP', 'MOD', 'MODULE', 'NOT',
-        'OF', 'OR', 'POINTER', 'PROCEDURE', 'RECORD', 'REPEAT', 'RETURN',
-        'SET', 'THEN', 'TO', 'TYPE', 'UNTIL', 'VAR', 'WHILE',
-    )
-
-    # Common Builtins Dataset
-    common_builtins = (
-        # 16 common builtins
-        'ABS', 'BOOLEAN', 'CARDINAL', 'CHAR', 'CHR', 'FALSE', 'INTEGER',
-        'LONGINT', 'LONGREAL', 'MAX', 'MIN', 'NIL', 'ODD', 'ORD', 'REAL',
-        'TRUE',
-    )
-
-    # Common Pseudo-Module Builtins Dataset
-    common_pseudo_builtins = (
-        # 4 common pseudo builtins
-        'ADDRESS', 'BYTE', 'WORD', 'ADR'
-    )
-
-#  P I M   M o d u l a - 2   D a t a s e t s
-
-    # Lexemes to Mark as Error Tokens for PIM Modula-2
-    pim_lexemes_to_reject = (
-        '!', '`', '@', '$', '%', '?', '\\', '==', '++', '--', '::', '*.',
-        '+>', '->', '<<', '>>', '|#', '##',
-    )
-
-    # PIM Modula-2 Additional Reserved Words Dataset
-    pim_additional_reserved_words = (
-        # 3 additional reserved words
-        'EXPORT', 'QUALIFIED', 'WITH',
-    )
-
-    # PIM Modula-2 Additional Builtins Dataset
-    pim_additional_builtins = (
-        # 16 additional builtins
-        'BITSET', 'CAP', 'DEC', 'DISPOSE', 'EXCL', 'FLOAT', 'HALT', 'HIGH',
-        'INC', 'INCL', 'NEW', 'NIL', 'PROC', 'SIZE', 'TRUNC', 'VAL',
-    )
-
-    # PIM Modula-2 Additional Pseudo-Module Builtins Dataset
-    pim_additional_pseudo_builtins = (
-        # 5 additional pseudo builtins
-        'SYSTEM', 'PROCESS', 'TSIZE', 'NEWPROCESS', 'TRANSFER',
-    )
-
-#  I S O   M o d u l a - 2   D a t a s e t s
-
-    # Lexemes to Mark as Error Tokens for ISO Modula-2
-    iso_lexemes_to_reject = (
-        '`', '$', '%', '?', '\\', '==', '++', '--', '::', '*.', '+>', '->',
-        '<<', '>>', '|#', '##',
-    )
-
-    # ISO Modula-2 Additional Reserved Words Dataset
-    iso_additional_reserved_words = (
-        # 9 additional reserved words (ISO 10514-1)
-        'EXCEPT', 'EXPORT', 'FINALLY', 'FORWARD', 'PACKEDSET', 'QUALIFIED',
-        'REM', 'RETRY', 'WITH',
-        # 10 additional reserved words (ISO 10514-2 & ISO 10514-3)
-        'ABSTRACT', 'AS', 'CLASS', 'GUARD', 'INHERIT', 'OVERRIDE', 'READONLY',
-        'REVEAL', 'TRACED', 'UNSAFEGUARDED',
-    )
-
-    # ISO Modula-2 Additional Builtins Dataset
-    iso_additional_builtins = (
-        # 26 additional builtins (ISO 10514-1)
-        'BITSET', 'CAP', 'CMPLX', 'COMPLEX', 'DEC', 'DISPOSE', 'EXCL', 'FLOAT',
-        'HALT', 'HIGH', 'IM', 'INC', 'INCL', 'INT', 'INTERRUPTIBLE',  'LENGTH',
-        'LFLOAT', 'LONGCOMPLEX', 'NEW', 'PROC', 'PROTECTION', 'RE', 'SIZE',
-        'TRUNC', 'UNINTERRUBTIBLE', 'VAL',
-        # 5 additional builtins (ISO 10514-2 & ISO 10514-3)
-        'CREATE', 'DESTROY', 'EMPTY', 'ISMEMBER', 'SELF',
-    )
-
-    # ISO Modula-2 Additional Pseudo-Module Builtins Dataset
-    iso_additional_pseudo_builtins = (
-        # 14 additional builtins (SYSTEM)
-        'SYSTEM', 'BITSPERLOC', 'LOCSPERBYTE', 'LOCSPERWORD', 'LOC',
-        'ADDADR', 'SUBADR', 'DIFADR', 'MAKEADR', 'ADR',
-        'ROTATE', 'SHIFT', 'CAST', 'TSIZE',
-        # 13 additional builtins (COROUTINES)
-        'COROUTINES', 'ATTACH', 'COROUTINE', 'CURRENT', 'DETACH', 'HANDLER',
-        'INTERRUPTSOURCE', 'IOTRANSFER', 'IsATTACHED', 'LISTEN',
-        'NEWCOROUTINE', 'PROT', 'TRANSFER',
-        # 9 additional builtins (EXCEPTIONS)
-        'EXCEPTIONS', 'AllocateSource', 'CurrentNumber', 'ExceptionNumber',
-        'ExceptionSource', 'GetMessage', 'IsCurrentSource',
-        'IsExceptionalExecution', 'RAISE',
-        # 3 additional builtins (TERMINATION)
-        'TERMINATION', 'IsTerminating', 'HasHalted',
-        # 4 additional builtins (M2EXCEPTION)
-        'M2EXCEPTION', 'M2Exceptions', 'M2Exception', 'IsM2Exception',
-        'indexException', 'rangeException', 'caseSelectException',
-        'invalidLocation', 'functionException', 'wholeValueException',
-        'wholeDivException', 'realValueException', 'realDivException',
-        'complexValueException', 'complexDivException', 'protException',
-        'sysException', 'coException', 'exException',
-    )
-
-#  M o d u l a - 2   R 1 0   D a t a s e t s
-
-    # Lexemes to Mark as Error Tokens for Modula-2 R10
-    m2r10_lexemes_to_reject = (
-        '!', '`', '@', '$', '%', '&', '<>',
-    )
-
-    # Modula-2 R10 reserved words in addition to the common set
-    m2r10_additional_reserved_words = (
-        # 12 additional reserved words
-        'ALIAS', 'ARGLIST', 'BLUEPRINT', 'COPY', 'GENLIB', 'INDETERMINATE',
-        'NEW', 'NONE', 'OPAQUE', 'REFERENTIAL', 'RELEASE', 'RETAIN',
-        # 2 additional reserved words with symbolic assembly option
-        'ASM', 'REG',
-    )
-
-    # Modula-2 R10 builtins in addition to the common set
-    m2r10_additional_builtins = (
-        # 26 additional builtins
-        'CARDINAL', 'COUNT', 'EMPTY', 'EXISTS', 'INSERT', 'LENGTH', 'LONGCARD',
-        'OCTET', 'PTR', 'PRED', 'READ', 'READNEW', 'REMOVE', 'RETRIEVE', 'SORT',
-        'STORE', 'SUBSET', 'SUCC', 'TLIMIT', 'TMAX', 'TMIN', 'TRUE', 'TSIZE',
-        'UNICHAR', 'WRITE', 'WRITEF',
-    )
-
-    # Modula-2 R10 Additional Pseudo-Module Builtins Dataset
-    m2r10_additional_pseudo_builtins = (
-        # 13 additional builtins (TPROPERTIES)
-        'TPROPERTIES', 'PROPERTY', 'LITERAL', 'TPROPERTY', 'TLITERAL',
-        'TBUILTIN', 'TDYN', 'TREFC', 'TNIL', 'TBASE', 'TPRECISION',
-        'TMAXEXP', 'TMINEXP',
-        # 4 additional builtins (CONVERSION)
-        'CONVERSION', 'TSXFSIZE', 'SXF', 'VAL',
-        # 35 additional builtins (UNSAFE)
-        'UNSAFE', 'CAST', 'INTRINSIC', 'AVAIL', 'ADD', 'SUB', 'ADDC', 'SUBC',
-        'FETCHADD', 'FETCHSUB', 'SHL', 'SHR', 'ASHR', 'ROTL', 'ROTR', 'ROTLC',
-        'ROTRC', 'BWNOT', 'BWAND', 'BWOR', 'BWXOR', 'BWNAND', 'BWNOR',
-        'SETBIT', 'TESTBIT', 'LSBIT', 'MSBIT', 'CSBITS', 'BAIL', 'HALT',
-        'TODO', 'FFI', 'ADDR', 'VARGLIST', 'VARGC',
-        # 11 additional builtins (ATOMIC)
-        'ATOMIC', 'INTRINSIC', 'AVAIL', 'SWAP', 'CAS', 'INC', 'DEC', 'BWAND',
-        'BWNAND', 'BWOR', 'BWXOR',
-        # 7 additional builtins (COMPILER)
-        'COMPILER', 'DEBUG', 'MODNAME', 'PROCNAME', 'LINENUM', 'DEFAULT',
-        'HASH',
-        # 5 additional builtins (ASSEMBLER)
-        'ASSEMBLER', 'REGISTER', 'SETREG', 'GETREG', 'CODE',
-    )
-
-#  O b j e c t i v e   M o d u l a - 2   D a t a s e t s
-
-    # Lexemes to Mark as Error Tokens for Objective Modula-2
-    objm2_lexemes_to_reject = (
-        '!', '$', '%', '&', '<>',
-    )
-
-    # Objective Modula-2 Extensions
-    # reserved words in addition to Modula-2 R10
-    objm2_additional_reserved_words = (
-        # 16 additional reserved words
-        'BYCOPY', 'BYREF', 'CLASS', 'CONTINUE', 'CRITICAL', 'INOUT', 'METHOD',
-        'ON', 'OPTIONAL', 'OUT', 'PRIVATE', 'PROTECTED', 'PROTOCOL', 'PUBLIC',
-        'SUPER', 'TRY',
-    )
-
-    # Objective Modula-2 Extensions
-    # builtins in addition to Modula-2 R10
-    objm2_additional_builtins = (
-        # 3 additional builtins
-        'OBJECT', 'NO', 'YES',
-    )
-
-    # Objective Modula-2 Extensions
-    # pseudo-module builtins in addition to Modula-2 R10
-    objm2_additional_pseudo_builtins = (
-        # None
-    )
-
-#  A g l e t   M o d u l a - 2   D a t a s e t s
-
-    # Aglet Extensions
-    # reserved words in addition to ISO Modula-2
-    aglet_additional_reserved_words = (
-        # None
-    )
-
-    # Aglet Extensions
-    # builtins in addition to ISO Modula-2
-    aglet_additional_builtins = (
-        # 9 additional builtins
-        'BITSET8', 'BITSET16', 'BITSET32', 'CARDINAL8', 'CARDINAL16',
-        'CARDINAL32', 'INTEGER8', 'INTEGER16', 'INTEGER32',
-    )
-
-    # Aglet Modula-2 Extensions
-    # pseudo-module builtins in addition to ISO Modula-2
-    aglet_additional_pseudo_builtins = (
-        # None
-    )
-
-#  G N U   M o d u l a - 2   D a t a s e t s
-
-    # GNU Extensions
-    # reserved words in addition to PIM Modula-2
-    gm2_additional_reserved_words = (
-        # 10 additional reserved words
-        'ASM', '__ATTRIBUTE__', '__BUILTIN__', '__COLUMN__', '__DATE__',
-        '__FILE__', '__FUNCTION__', '__LINE__', '__MODULE__', 'VOLATILE',
-    )
-
-    # GNU Extensions
-    # builtins in addition to PIM Modula-2
-    gm2_additional_builtins = (
-        # 21 additional builtins
-        'BITSET8', 'BITSET16', 'BITSET32', 'CARDINAL8', 'CARDINAL16',
-        'CARDINAL32', 'CARDINAL64', 'COMPLEX32', 'COMPLEX64', 'COMPLEX96',
-        'COMPLEX128', 'INTEGER8', 'INTEGER16', 'INTEGER32', 'INTEGER64',
-        'REAL8', 'REAL16', 'REAL32', 'REAL96', 'REAL128', 'THROW',
-    )
-
-    # GNU Extensions
-    # pseudo-module builtins in addition to PIM Modula-2
-    gm2_additional_pseudo_builtins = (
-        # None
-    )
-
-#  p 1   M o d u l a - 2   D a t a s e t s
-
-    # p1 Extensions
-    # reserved words in addition to ISO Modula-2
-    p1_additional_reserved_words = (
-        # None
-    )
-
-    # p1 Extensions
-    # builtins in addition to ISO Modula-2
-    p1_additional_builtins = (
-        # None
-    )
-
-    # p1 Modula-2 Extensions
-    # pseudo-module builtins in addition to ISO Modula-2
-    p1_additional_pseudo_builtins = (
-        # 1 additional builtin
-        'BCD',
-    )
-
-#  X D S   M o d u l a - 2   D a t a s e t s
-
-    # XDS Extensions
-    # reserved words in addition to ISO Modula-2
-    xds_additional_reserved_words = (
-        # 1 additional reserved word
-        'SEQ',
-    )
-
-    # XDS Extensions
-    # builtins in addition to ISO Modula-2
-    xds_additional_builtins = (
-        # 9 additional builtins
-        'ASH', 'ASSERT', 'DIFFADR_TYPE', 'ENTIER', 'INDEX', 'LEN',
-        'LONGCARD', 'SHORTCARD', 'SHORTINT',
-    )
-
-    # XDS Modula-2 Extensions
-    # pseudo-module builtins in addition to ISO Modula-2
-    xds_additional_pseudo_builtins = (
-        # 22 additional builtins (SYSTEM)
-        'PROCESS', 'NEWPROCESS', 'BOOL8', 'BOOL16', 'BOOL32', 'CARD8',
-        'CARD16', 'CARD32', 'INT8', 'INT16', 'INT32', 'REF', 'MOVE',
-        'FILL', 'GET', 'PUT', 'CC', 'int', 'unsigned', 'size_t', 'void'
-        # 3 additional builtins (COMPILER)
-        'COMPILER', 'OPTION', 'EQUATION'
-    )
-
-#  P I M   S t a n d a r d   L i b r a r y   D a t a s e t s
-
-    # PIM Modula-2 Standard Library Modules Dataset
-    pim_stdlib_module_identifiers = (
-        'Terminal', 'FileSystem', 'InOut', 'RealInOut', 'MathLib0', 'Storage',
-    )
-
-    # PIM Modula-2 Standard Library Types Dataset
-    pim_stdlib_type_identifiers = (
-        'Flag', 'FlagSet', 'Response', 'Command', 'Lock', 'Permission',
-        'MediumType', 'File', 'FileProc', 'DirectoryProc', 'FileCommand',
-        'DirectoryCommand',
-    )
-
-    # PIM Modula-2 Standard Library Procedures Dataset
-    pim_stdlib_proc_identifiers = (
-        'Read', 'BusyRead', 'ReadAgain', 'Write', 'WriteString', 'WriteLn',
-        'Create', 'Lookup', 'Close', 'Delete', 'Rename', 'SetRead', 'SetWrite',
-        'SetModify', 'SetOpen', 'Doio', 'SetPos', 'GetPos', 'Length', 'Reset',
-        'Again', 'ReadWord', 'WriteWord', 'ReadChar', 'WriteChar',
-        'CreateMedium', 'DeleteMedium', 'AssignName', 'DeassignName',
-        'ReadMedium', 'LookupMedium', 'OpenInput', 'OpenOutput', 'CloseInput',
-        'CloseOutput', 'ReadString', 'ReadInt', 'ReadCard', 'ReadWrd',
-        'WriteInt', 'WriteCard', 'WriteOct', 'WriteHex', 'WriteWrd',
-        'ReadReal', 'WriteReal', 'WriteFixPt', 'WriteRealOct', 'sqrt', 'exp',
-        'ln', 'sin', 'cos', 'arctan', 'entier', 'ALLOCATE', 'DEALLOCATE',
-    )
-
-    # PIM Modula-2 Standard Library Variables Dataset
-    pim_stdlib_var_identifiers = (
-        'Done', 'termCH', 'in', 'out'
-    )
-
-    # PIM Modula-2 Standard Library Constants Dataset
-    pim_stdlib_const_identifiers = (
-        'EOL',
-    )
-
-#  I S O   S t a n d a r d   L i b r a r y   D a t a s e t s
-
-    # ISO Modula-2 Standard Library Modules Dataset
-    iso_stdlib_module_identifiers = (
-        # TO DO
-    )
-
-    # ISO Modula-2 Standard Library Types Dataset
-    iso_stdlib_type_identifiers = (
-        # TO DO
-    )
-
-    # ISO Modula-2 Standard Library Procedures Dataset
-    iso_stdlib_proc_identifiers = (
-        # TO DO
-    )
-
-    # ISO Modula-2 Standard Library Variables Dataset
-    iso_stdlib_var_identifiers = (
-        # TO DO
-    )
-
-    # ISO Modula-2 Standard Library Constants Dataset
-    iso_stdlib_const_identifiers = (
-        # TO DO
-    )
-
-#  M 2   R 1 0   S t a n d a r d   L i b r a r y   D a t a s e t s
-
-    # Modula-2 R10 Standard Library ADTs Dataset
-    m2r10_stdlib_adt_identifiers = (
-        'BCD', 'LONGBCD', 'BITSET', 'SHORTBITSET', 'LONGBITSET',
-        'LONGLONGBITSET', 'COMPLEX', 'LONGCOMPLEX', 'SHORTCARD', 'LONGLONGCARD',
-        'SHORTINT', 'LONGLONGINT', 'POSINT', 'SHORTPOSINT', 'LONGPOSINT',
-        'LONGLONGPOSINT', 'BITSET8', 'BITSET16', 'BITSET32', 'BITSET64',
-        'BITSET128', 'BS8', 'BS16', 'BS32', 'BS64', 'BS128', 'CARDINAL8',
-        'CARDINAL16', 'CARDINAL32', 'CARDINAL64', 'CARDINAL128', 'CARD8',
-        'CARD16', 'CARD32', 'CARD64', 'CARD128', 'INTEGER8', 'INTEGER16',
-        'INTEGER32', 'INTEGER64', 'INTEGER128', 'INT8', 'INT16', 'INT32',
-        'INT64', 'INT128', 'STRING', 'UNISTRING',
-    )
-
-    # Modula-2 R10 Standard Library Blueprints Dataset
-    m2r10_stdlib_blueprint_identifiers = (
-        'ProtoRoot', 'ProtoComputational', 'ProtoNumeric', 'ProtoScalar',
-        'ProtoNonScalar', 'ProtoCardinal', 'ProtoInteger', 'ProtoReal',
-        'ProtoComplex', 'ProtoVector', 'ProtoTuple', 'ProtoCompArray',
-        'ProtoCollection', 'ProtoStaticArray', 'ProtoStaticSet',
-        'ProtoStaticString', 'ProtoArray', 'ProtoString', 'ProtoSet',
-        'ProtoMultiSet', 'ProtoDictionary', 'ProtoMultiDict', 'ProtoExtension',
-        'ProtoIO', 'ProtoCardMath', 'ProtoIntMath', 'ProtoRealMath',
-    )
-
-    # Modula-2 R10 Standard Library Modules Dataset
-    m2r10_stdlib_module_identifiers = (
-        'ASCII', 'BooleanIO', 'CharIO', 'UnicharIO', 'OctetIO',
-        'CardinalIO', 'LongCardIO', 'IntegerIO', 'LongIntIO', 'RealIO',
-        'LongRealIO', 'BCDIO', 'LongBCDIO', 'CardMath', 'LongCardMath',
-        'IntMath', 'LongIntMath', 'RealMath', 'LongRealMath', 'BCDMath',
-        'LongBCDMath', 'FileIO', 'FileSystem', 'Storage', 'IOSupport',
-    )
-
-    # Modula-2 R10 Standard Library Types Dataset
-    m2r10_stdlib_type_identifiers = (
-        'File', 'Status',
-        # TO BE COMPLETED
-    )
-
-    # Modula-2 R10 Standard Library Procedures Dataset
-    m2r10_stdlib_proc_identifiers = (
-        'ALLOCATE', 'DEALLOCATE', 'SIZE',
-        # TO BE COMPLETED
-    )
-
-    # Modula-2 R10 Standard Library Variables Dataset
-    m2r10_stdlib_var_identifiers = (
-        'stdIn', 'stdOut', 'stdErr',
-    )
-
-    # Modula-2 R10 Standard Library Constants Dataset
-    m2r10_stdlib_const_identifiers = (
-        'pi', 'tau',
-    )
-
-#  D i a l e c t s
-
-    # Dialect modes
-    dialects = (
-        'unknown',
-        'm2pim', 'm2iso', 'm2r10', 'objm2',
-        'm2iso+aglet', 'm2pim+gm2', 'm2iso+p1', 'm2iso+xds',
-    )
-
-#   D a t a b a s e s
-
-    # Lexemes to Mark as Errors Database
-    lexemes_to_reject_db = {
-        # Lexemes to reject for unknown dialect
-        'unknown': (
-            # LEAVE THIS EMPTY
-        ),
-        # Lexemes to reject for PIM Modula-2
-        'm2pim': (
-            pim_lexemes_to_reject,
-        ),
-        # Lexemes to reject for ISO Modula-2
-        'm2iso': (
-            iso_lexemes_to_reject,
-        ),
-        # Lexemes to reject for Modula-2 R10
-        'm2r10': (
-            m2r10_lexemes_to_reject,
-        ),
-        # Lexemes to reject for Objective Modula-2
-        'objm2': (
-            objm2_lexemes_to_reject,
-        ),
-        # Lexemes to reject for Aglet Modula-2
-        'm2iso+aglet': (
-            iso_lexemes_to_reject,
-        ),
-        # Lexemes to reject for GNU Modula-2
-        'm2pim+gm2': (
-            pim_lexemes_to_reject,
-        ),
-        # Lexemes to reject for p1 Modula-2
-        'm2iso+p1': (
-            iso_lexemes_to_reject,
-        ),
-        # Lexemes to reject for XDS Modula-2
-        'm2iso+xds': (
-            iso_lexemes_to_reject,
-        ),
-    }
-
-    # Reserved Words Database
-    reserved_words_db = {
-        # Reserved words for unknown dialect
-        'unknown': (
-            common_reserved_words,
-            pim_additional_reserved_words,
-            iso_additional_reserved_words,
-            m2r10_additional_reserved_words,
-        ),
-
-        # Reserved words for PIM Modula-2
-        'm2pim': (
-            common_reserved_words,
-            pim_additional_reserved_words,
-        ),
-
-        # Reserved words for Modula-2 R10
-        'm2iso': (
-            common_reserved_words,
-            iso_additional_reserved_words,
-        ),
-
-        # Reserved words for ISO Modula-2
-        'm2r10': (
-            common_reserved_words,
-            m2r10_additional_reserved_words,
-        ),
-
-        # Reserved words for Objective Modula-2
-        'objm2': (
-            common_reserved_words,
-            m2r10_additional_reserved_words,
-            objm2_additional_reserved_words,
-        ),
-
-        # Reserved words for Aglet Modula-2 Extensions
-        'm2iso+aglet': (
-            common_reserved_words,
-            iso_additional_reserved_words,
-            aglet_additional_reserved_words,
-        ),
-
-        # Reserved words for GNU Modula-2 Extensions
-        'm2pim+gm2': (
-            common_reserved_words,
-            pim_additional_reserved_words,
-            gm2_additional_reserved_words,
-        ),
-
-        # Reserved words for p1 Modula-2 Extensions
-        'm2iso+p1': (
-            common_reserved_words,
-            iso_additional_reserved_words,
-            p1_additional_reserved_words,
-        ),
-
-        # Reserved words for XDS Modula-2 Extensions
-        'm2iso+xds': (
-            common_reserved_words,
-            iso_additional_reserved_words,
-            xds_additional_reserved_words,
-        ),
-    }
-
-    # Builtins Database
-    builtins_db = {
-        # Builtins for unknown dialect
-        'unknown': (
-            common_builtins,
-            pim_additional_builtins,
-            iso_additional_builtins,
-            m2r10_additional_builtins,
-        ),
-
-        # Builtins for PIM Modula-2
-        'm2pim': (
-            common_builtins,
-            pim_additional_builtins,
-        ),
-
-        # Builtins for ISO Modula-2
-        'm2iso': (
-            common_builtins,
-            iso_additional_builtins,
-        ),
-
-        # Builtins for ISO Modula-2
-        'm2r10': (
-            common_builtins,
-            m2r10_additional_builtins,
-        ),
-
-        # Builtins for Objective Modula-2
-        'objm2': (
-            common_builtins,
-            m2r10_additional_builtins,
-            objm2_additional_builtins,
-        ),
-
-        # Builtins for Aglet Modula-2 Extensions
-        'm2iso+aglet': (
-            common_builtins,
-            iso_additional_builtins,
-            aglet_additional_builtins,
-        ),
-
-        # Builtins for GNU Modula-2 Extensions
-        'm2pim+gm2': (
-            common_builtins,
-            pim_additional_builtins,
-            gm2_additional_builtins,
-        ),
-
-        # Builtins for p1 Modula-2 Extensions
-        'm2iso+p1': (
-            common_builtins,
-            iso_additional_builtins,
-            p1_additional_builtins,
-        ),
-
-        # Builtins for XDS Modula-2 Extensions
-        'm2iso+xds': (
-            common_builtins,
-            iso_additional_builtins,
-            xds_additional_builtins,
-        ),
-    }
-
-    # Pseudo-Module Builtins Database
-    pseudo_builtins_db = {
-        # Builtins for unknown dialect
-        'unknown': (
-            common_pseudo_builtins,
-            pim_additional_pseudo_builtins,
-            iso_additional_pseudo_builtins,
-            m2r10_additional_pseudo_builtins,
-        ),
-
-        # Builtins for PIM Modula-2
-        'm2pim': (
-            common_pseudo_builtins,
-            pim_additional_pseudo_builtins,
-        ),
-
-        # Builtins for ISO Modula-2
-        'm2iso': (
-            common_pseudo_builtins,
-            iso_additional_pseudo_builtins,
-        ),
-
-        # Builtins for ISO Modula-2
-        'm2r10': (
-            common_pseudo_builtins,
-            m2r10_additional_pseudo_builtins,
-        ),
-
-        # Builtins for Objective Modula-2
-        'objm2': (
-            common_pseudo_builtins,
-            m2r10_additional_pseudo_builtins,
-            objm2_additional_pseudo_builtins,
-        ),
-
-        # Builtins for Aglet Modula-2 Extensions
-        'm2iso+aglet': (
-            common_pseudo_builtins,
-            iso_additional_pseudo_builtins,
-            aglet_additional_pseudo_builtins,
-        ),
-
-        # Builtins for GNU Modula-2 Extensions
-        'm2pim+gm2': (
-            common_pseudo_builtins,
-            pim_additional_pseudo_builtins,
-            gm2_additional_pseudo_builtins,
-        ),
-
-        # Builtins for p1 Modula-2 Extensions
-        'm2iso+p1': (
-            common_pseudo_builtins,
-            iso_additional_pseudo_builtins,
-            p1_additional_pseudo_builtins,
-        ),
-
-        # Builtins for XDS Modula-2 Extensions
-        'm2iso+xds': (
-            common_pseudo_builtins,
-            iso_additional_pseudo_builtins,
-            xds_additional_pseudo_builtins,
-        ),
-    }
-
-    # Standard Library ADTs Database
-    stdlib_adts_db = {
-        # Empty entry for unknown dialect
-        'unknown': (
-            # LEAVE THIS EMPTY
-        ),
-        # Standard Library ADTs for PIM Modula-2
-        'm2pim': (
-            # No first class library types
-        ),
-
-        # Standard Library ADTs for ISO Modula-2
-        'm2iso': (
-            # No first class library types
-        ),
-
-        # Standard Library ADTs for Modula-2 R10
-        'm2r10': (
-            m2r10_stdlib_adt_identifiers,
-        ),
-
-        # Standard Library ADTs for Objective Modula-2
-        'objm2': (
-            m2r10_stdlib_adt_identifiers,
-        ),
-
-        # Standard Library ADTs for Aglet Modula-2
-        'm2iso+aglet': (
-            # No first class library types
-        ),
-
-        # Standard Library ADTs for GNU Modula-2
-        'm2pim+gm2': (
-            # No first class library types
-        ),
-
-        # Standard Library ADTs for p1 Modula-2
-        'm2iso+p1': (
-            # No first class library types
-        ),
-
-        # Standard Library ADTs for XDS Modula-2
-        'm2iso+xds': (
-            # No first class library types
-        ),
-    }
-
-    # Standard Library Modules Database
-    stdlib_modules_db = {
-        # Empty entry for unknown dialect
-        'unknown': (
-            # LEAVE THIS EMPTY
-        ),
-        # Standard Library Modules for PIM Modula-2
-        'm2pim': (
-            pim_stdlib_module_identifiers,
-        ),
-
-        # Standard Library Modules for ISO Modula-2
-        'm2iso': (
-            iso_stdlib_module_identifiers,
-        ),
-
-        # Standard Library Modules for Modula-2 R10
-        'm2r10': (
-            m2r10_stdlib_blueprint_identifiers,
-            m2r10_stdlib_module_identifiers,
-            m2r10_stdlib_adt_identifiers,
-        ),
-
-        # Standard Library Modules for Objective Modula-2
-        'objm2': (
-            m2r10_stdlib_blueprint_identifiers,
-            m2r10_stdlib_module_identifiers,
-        ),
-
-        # Standard Library Modules for Aglet Modula-2
-        'm2iso+aglet': (
-            iso_stdlib_module_identifiers,
-        ),
-
-        # Standard Library Modules for GNU Modula-2
-        'm2pim+gm2': (
-            pim_stdlib_module_identifiers,
-        ),
-
-        # Standard Library Modules for p1 Modula-2
-        'm2iso+p1': (
-            iso_stdlib_module_identifiers,
-        ),
-
-        # Standard Library Modules for XDS Modula-2
-        'm2iso+xds': (
-            iso_stdlib_module_identifiers,
-        ),
-    }
-
-    # Standard Library Types Database
-    stdlib_types_db = {
-        # Empty entry for unknown dialect
-        'unknown': (
-            # LEAVE THIS EMPTY
-        ),
-        # Standard Library Types for PIM Modula-2
-        'm2pim': (
-            pim_stdlib_type_identifiers,
-        ),
-
-        # Standard Library Types for ISO Modula-2
-        'm2iso': (
-            iso_stdlib_type_identifiers,
-        ),
-
-        # Standard Library Types for Modula-2 R10
-        'm2r10': (
-            m2r10_stdlib_type_identifiers,
-        ),
-
-        # Standard Library Types for Objective Modula-2
-        'objm2': (
-            m2r10_stdlib_type_identifiers,
-        ),
-
-        # Standard Library Types for Aglet Modula-2
-        'm2iso+aglet': (
-            iso_stdlib_type_identifiers,
-        ),
-
-        # Standard Library Types for GNU Modula-2
-        'm2pim+gm2': (
-            pim_stdlib_type_identifiers,
-        ),
-
-        # Standard Library Types for p1 Modula-2
-        'm2iso+p1': (
-            iso_stdlib_type_identifiers,
-        ),
-
-        # Standard Library Types for XDS Modula-2
-        'm2iso+xds': (
-            iso_stdlib_type_identifiers,
-        ),
-    }
-
-    # Standard Library Procedures Database
-    stdlib_procedures_db = {
-        # Empty entry for unknown dialect
-        'unknown': (
-            # LEAVE THIS EMPTY
-        ),
-        # Standard Library Procedures for PIM Modula-2
-        'm2pim': (
-            pim_stdlib_proc_identifiers,
-        ),
-
-        # Standard Library Procedures for ISO Modula-2
-        'm2iso': (
-            iso_stdlib_proc_identifiers,
-        ),
-
-        # Standard Library Procedures for Modula-2 R10
-        'm2r10': (
-            m2r10_stdlib_proc_identifiers,
-        ),
-
-        # Standard Library Procedures for Objective Modula-2
-        'objm2': (
-            m2r10_stdlib_proc_identifiers,
-        ),
-
-        # Standard Library Procedures for Aglet Modula-2
-        'm2iso+aglet': (
-            iso_stdlib_proc_identifiers,
-        ),
-
-        # Standard Library Procedures for GNU Modula-2
-        'm2pim+gm2': (
-            pim_stdlib_proc_identifiers,
-        ),
-
-        # Standard Library Procedures for p1 Modula-2
-        'm2iso+p1': (
-            iso_stdlib_proc_identifiers,
-        ),
-
-        # Standard Library Procedures for XDS Modula-2
-        'm2iso+xds': (
-            iso_stdlib_proc_identifiers,
-        ),
-    }
-
-    # Standard Library Variables Database
-    stdlib_variables_db = {
-        # Empty entry for unknown dialect
-        'unknown': (
-            # LEAVE THIS EMPTY
-        ),
-        # Standard Library Variables for PIM Modula-2
-        'm2pim': (
-            pim_stdlib_var_identifiers,
-        ),
-
-        # Standard Library Variables for ISO Modula-2
-        'm2iso': (
-            iso_stdlib_var_identifiers,
-        ),
-
-        # Standard Library Variables for Modula-2 R10
-        'm2r10': (
-            m2r10_stdlib_var_identifiers,
-        ),
-
-        # Standard Library Variables for Objective Modula-2
-        'objm2': (
-            m2r10_stdlib_var_identifiers,
-        ),
-
-        # Standard Library Variables for Aglet Modula-2
-        'm2iso+aglet': (
-            iso_stdlib_var_identifiers,
-        ),
-
-        # Standard Library Variables for GNU Modula-2
-        'm2pim+gm2': (
-            pim_stdlib_var_identifiers,
-        ),
-
-        # Standard Library Variables for p1 Modula-2
-        'm2iso+p1': (
-            iso_stdlib_var_identifiers,
-        ),
-
-        # Standard Library Variables for XDS Modula-2
-        'm2iso+xds': (
-            iso_stdlib_var_identifiers,
-        ),
-    }
-
-    # Standard Library Constants Database
-    stdlib_constants_db = {
-        # Empty entry for unknown dialect
-        'unknown': (
-            # LEAVE THIS EMPTY
-        ),
-        # Standard Library Constants for PIM Modula-2
-        'm2pim': (
-            pim_stdlib_const_identifiers,
-        ),
-
-        # Standard Library Constants for ISO Modula-2
-        'm2iso': (
-            iso_stdlib_const_identifiers,
-        ),
-
-        # Standard Library Constants for Modula-2 R10
-        'm2r10': (
-            m2r10_stdlib_const_identifiers,
-        ),
-
-        # Standard Library Constants for Objective Modula-2
-        'objm2': (
-            m2r10_stdlib_const_identifiers,
-        ),
-
-        # Standard Library Constants for Aglet Modula-2
-        'm2iso+aglet': (
-            iso_stdlib_const_identifiers,
-        ),
-
-        # Standard Library Constants for GNU Modula-2
-        'm2pim+gm2': (
-            pim_stdlib_const_identifiers,
-        ),
-
-        # Standard Library Constants for p1 Modula-2
-        'm2iso+p1': (
-            iso_stdlib_const_identifiers,
-        ),
-
-        # Standard Library Constants for XDS Modula-2
-        'm2iso+xds': (
-            iso_stdlib_const_identifiers,
-        ),
-    }
-
-#   M e t h o d s
-
-    # initialise a lexer instance
-    def __init__(self, **options):
-        #
-        # check dialect options
-        #
-        dialects = get_list_opt(options, 'dialect', [])
-        #
-        for dialect_option in dialects:
-            if dialect_option in self.dialects[1:-1]:
-                # valid dialect option found
-                self.set_dialect(dialect_option)
-                break
-        #
-        # Fallback Mode (DEFAULT)
-        else:
-            # no valid dialect option
-            self.set_dialect('unknown')
-        #
-        self.dialect_set_by_tag = False
-        #
-        # check style options
-        #
-        styles = get_list_opt(options, 'style', [])
-        #
-        # use lowercase mode for Algol style
-        if 'algol' in styles or 'algol_nu' in styles:
-            self.algol_publication_mode = True
-        else:
-            self.algol_publication_mode = False
-        #
-        # Check option flags
-        #
-        self.treat_stdlib_adts_as_builtins = get_bool_opt(
-            options, 'treat_stdlib_adts_as_builtins', True)
-        #
-        # call superclass initialiser
-        RegexLexer.__init__(self, **options)
-
-    # Set lexer to a specified dialect
-    def set_dialect(self, dialect_id):
-        #
-        # if __debug__:
-        #    print 'entered set_dialect with arg: ', dialect_id
-        #
-        # check dialect name against known dialects
-        if dialect_id not in self.dialects:
-            dialect = 'unknown'  # default
-        else:
-            dialect = dialect_id
-        #
-        # compose lexemes to reject set
-        lexemes_to_reject_set = set()
-        # add each list of reject lexemes for this dialect
-        for list in self.lexemes_to_reject_db[dialect]:
-            lexemes_to_reject_set.update(set(list))
-        #
-        # compose reserved words set
-        reswords_set = set()
-        # add each list of reserved words for this dialect
-        for list in self.reserved_words_db[dialect]:
-            reswords_set.update(set(list))
-        #
-        # compose builtins set
-        builtins_set = set()
-        # add each list of builtins for this dialect excluding reserved words
-        for list in self.builtins_db[dialect]:
-            builtins_set.update(set(list).difference(reswords_set))
-        #
-        # compose pseudo-builtins set
-        pseudo_builtins_set = set()
-        # add each list of builtins for this dialect excluding reserved words
-        for list in self.pseudo_builtins_db[dialect]:
-            pseudo_builtins_set.update(set(list).difference(reswords_set))
-        #
-        # compose ADTs set
-        adts_set = set()
-        # add each list of ADTs for this dialect excluding reserved words
-        for list in self.stdlib_adts_db[dialect]:
-            adts_set.update(set(list).difference(reswords_set))
-        #
-        # compose modules set
-        modules_set = set()
-        # add each list of builtins for this dialect excluding builtins
-        for list in self.stdlib_modules_db[dialect]:
-            modules_set.update(set(list).difference(builtins_set))
-        #
-        # compose types set
-        types_set = set()
-        # add each list of types for this dialect excluding builtins
-        for list in self.stdlib_types_db[dialect]:
-            types_set.update(set(list).difference(builtins_set))
-        #
-        # compose procedures set
-        procedures_set = set()
-        # add each list of procedures for this dialect excluding builtins
-        for list in self.stdlib_procedures_db[dialect]:
-            procedures_set.update(set(list).difference(builtins_set))
-        #
-        # compose variables set
-        variables_set = set()
-        # add each list of variables for this dialect excluding builtins
-        for list in self.stdlib_variables_db[dialect]:
-            variables_set.update(set(list).difference(builtins_set))
-        #
-        # compose constants set
-        constants_set = set()
-        # add each list of constants for this dialect excluding builtins
-        for list in self.stdlib_constants_db[dialect]:
-            constants_set.update(set(list).difference(builtins_set))
-        #
-        # update lexer state
-        self.dialect = dialect
-        self.lexemes_to_reject = lexemes_to_reject_set
-        self.reserved_words = reswords_set
-        self.builtins = builtins_set
-        self.pseudo_builtins = pseudo_builtins_set
-        self.adts = adts_set
-        self.modules = modules_set
-        self.types = types_set
-        self.procedures = procedures_set
-        self.variables = variables_set
-        self.constants = constants_set
-        #
-        # if __debug__:
-        #    print 'exiting set_dialect'
-        #    print ' self.dialect: ', self.dialect
-        #    print ' self.lexemes_to_reject: ', self.lexemes_to_reject
-        #    print ' self.reserved_words: ', self.reserved_words
-        #    print ' self.builtins: ', self.builtins
-        #    print ' self.pseudo_builtins: ', self.pseudo_builtins
-        #    print ' self.adts: ', self.adts
-        #    print ' self.modules: ', self.modules
-        #    print ' self.types: ', self.types
-        #    print ' self.procedures: ', self.procedures
-        #    print ' self.variables: ', self.variables
-        #    print ' self.types: ', self.types
-        #    print ' self.constants: ', self.constants
-
-    # Extracts a dialect name from a dialect tag comment string  and checks
-    # the extracted name against known dialects.  If a match is found,  the
-    # matching name is returned, otherwise dialect id 'unknown' is returned
-    def get_dialect_from_dialect_tag(self, dialect_tag):
-        #
-        # if __debug__:
-        #    print 'entered get_dialect_from_dialect_tag with arg: ', dialect_tag
-        #
-        # constants
-        left_tag_delim = '(*!'
-        right_tag_delim = '*)'
-        left_tag_delim_len = len(left_tag_delim)
-        right_tag_delim_len = len(right_tag_delim)
-        indicator_start = left_tag_delim_len
-        indicator_end = -(right_tag_delim_len)
-        #
-        # check comment string for dialect indicator
-        if len(dialect_tag) > (left_tag_delim_len + right_tag_delim_len) \
-           and dialect_tag.startswith(left_tag_delim) \
-           and dialect_tag.endswith(right_tag_delim):
-            #
-            # if __debug__:
-            #    print 'dialect tag found'
-            #
-            # extract dialect indicator
-            indicator = dialect_tag[indicator_start:indicator_end]
-            #
-            # if __debug__:
-            #    print 'extracted: ', indicator
-            #
-            # check against known dialects
-            for index in range(1, len(self.dialects)):
-                #
-                # if __debug__:
-                #    print 'dialects[', index, ']: ', self.dialects[index]
-                #
-                if indicator == self.dialects[index]:
-                    #
-                    # if __debug__:
-                    #    print 'matching dialect found'
-                    #
-                    # indicator matches known dialect
-                    return indicator
-            else:
-                # indicator does not match any dialect
-                return 'unknown'  # default
-        else:
-            # invalid indicator string
-            return 'unknown'  # default
-
-    # intercept the token stream, modify token attributes and return them
-    def get_tokens_unprocessed(self, text):
-        for index, token, value in RegexLexer.get_tokens_unprocessed(self, text):
-            #
-            # check for dialect tag if dialect has not been set by tag
-            if not self.dialect_set_by_tag and token == Comment.Special:
-                indicated_dialect = self.get_dialect_from_dialect_tag(value)
-                if indicated_dialect != 'unknown':
-                    # token is a dialect indicator
-                    # reset reserved words and builtins
-                    self.set_dialect(indicated_dialect)
-                    self.dialect_set_by_tag = True
-            #
-            # check for reserved words, predefined and stdlib identifiers
-            if token is Name:
-                if value in self.reserved_words:
-                    token = Keyword.Reserved
-                    if self.algol_publication_mode:
-                        value = value.lower()
-                #
-                elif value in self.builtins:
-                    token = Name.Builtin
-                    if self.algol_publication_mode:
-                        value = value.lower()
-                #
-                elif value in self.pseudo_builtins:
-                    token = Name.Builtin.Pseudo
-                    if self.algol_publication_mode:
-                        value = value.lower()
-                #
-                elif value in self.adts:
-                    if not self.treat_stdlib_adts_as_builtins:
-                        token = Name.Namespace
-                    else:
-                        token = Name.Builtin.Pseudo
-                        if self.algol_publication_mode:
-                            value = value.lower()
-                #
-                elif value in self.modules:
-                    token = Name.Namespace
-                #
-                elif value in self.types:
-                    token = Name.Class
-                #
-                elif value in self.procedures:
-                    token = Name.Function
-                #
-                elif value in self.variables:
-                    token = Name.Variable
-                #
-                elif value in self.constants:
-                    token = Name.Constant
-            #
-            elif token in Number:
-                #
-                # mark prefix number literals as error for PIM and ISO dialects
-                if self.dialect not in ('unknown', 'm2r10', 'objm2'):
-                    if "'" in value or value[0:2] in ('0b', '0x', '0u'):
-                        token = Error
-                #
-                elif self.dialect in ('m2r10', 'objm2'):
-                    # mark base-8 number literals as errors for M2 R10 and ObjM2
-                    if token is Number.Oct:
-                        token = Error
-                    # mark suffix base-16 literals as errors for M2 R10 and ObjM2
-                    elif token is Number.Hex and 'H' in value:
-                        token = Error
-                    # mark real numbers with E as errors for M2 R10 and ObjM2
-                    elif token is Number.Float and 'E' in value:
-                        token = Error
-            #
-            elif token in Comment:
-                #
-                # mark single line comment as error for PIM and ISO dialects
-                if token is Comment.Single:
-                    if self.dialect not in ('unknown', 'm2r10', 'objm2'):
-                        token = Error
-                #
-                if token is Comment.Preproc:
-                    # mark ISO pragma as error for PIM dialects
-                    if value.startswith('<*') and \
-                       self.dialect.startswith('m2pim'):
-                        token = Error
-                    # mark PIM pragma as comment for other dialects
-                    elif value.startswith('(*$') and \
-                            self.dialect != 'unknown' and \
-                            not self.dialect.startswith('m2pim'):
-                        token = Comment.Multiline
-            #
-            else:  # token is neither Name nor Comment
-                #
-                # mark lexemes matching the dialect's error token set as errors
-                if value in self.lexemes_to_reject:
-                    token = Error
-                #
-                # substitute lexemes when in Algol mode
-                if self.algol_publication_mode:
-                    if value == '#':
-                        value = '≠'
-                    elif value == '<=':
-                        value = '≤'
-                    elif value == '>=':
-                        value = '≥'
-                    elif value == '==':
-                        value = '≡'
-                    elif value == '*.':
-                        value = '•'
-
-            # return result
-            yield index, token, value
-
-    def analyse_text(text):
-        """It's Pascal-like, but does not use FUNCTION -- uses PROCEDURE
-        instead."""
-
-        # Check if this looks like Pascal, if not, bail out early
-        if not ('(*' in text and '*)' in text and ':=' in text):
-            return
-
-        result = 0
-        # Procedure is in Modula2
-        if re.search(r'\bPROCEDURE\b', text):
-            result += 0.6
-
-        # FUNCTION is only valid in Pascal, but not in Modula2
-        if re.search(r'\bFUNCTION\b', text):
-            result = 0.0
-
-        return result
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/mojo.py b/.venv/lib/python3.12/site-packages/pygments/lexers/mojo.py
deleted file mode 100644
index 84aac46..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/mojo.py
+++ /dev/null
@@ -1,707 +0,0 @@
-"""
-    pygments.lexers.mojo
-    ~~~~~~~~~~~~~~~~~~~~
-
-    Lexers for Mojo and related languages.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-import keyword
-
-from pygments import unistring as uni
-from pygments.lexer import (
-    RegexLexer,
-    bygroups,
-    combined,
-    default,
-    include,
-    this,
-    using,
-    words,
-)
-from pygments.token import (
-    Comment,
-    # Error,
-    Keyword,
-    Name,
-    Number,
-    Operator,
-    Punctuation,
-    String,
-    Text,
-    Whitespace,
-)
-from pygments.util import shebang_matches
-
-__all__ = ["MojoLexer"]
-
-
-class MojoLexer(RegexLexer):
-    """
-    For Mojo source code (version 24.2.1).
-    """
-
-    name = "Mojo"
-    url = "https://docs.modular.com/mojo/"
-    aliases = ["mojo", "🔥"]
-    filenames = [
-        "*.mojo",
-        "*.🔥",
-    ]
-    mimetypes = [
-        "text/x-mojo",
-        "application/x-mojo",
-    ]
-    version_added = "2.18"
-
-    uni_name = f"[{uni.xid_start}][{uni.xid_continue}]*"
-
-    def innerstring_rules(ttype):
-        return [
-            # the old style '%s' % (...) string formatting (still valid in Py3)
-            (
-                r"%(\(\w+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?"
-                "[hlL]?[E-GXc-giorsaux%]",
-                String.Interpol,
-            ),
-            # the new style '{}'.format(...) string formatting
-            (
-                r"\{"
-                r"((\w+)((\.\w+)|(\[[^\]]+\]))*)?"  # field name
-                r"(\![sra])?"  # conversion
-                r"(\:(.?[<>=\^])?[-+ ]?#?0?(\d+)?,?(\.\d+)?[E-GXb-gnosx%]?)?"
-                r"\}",
-                String.Interpol,
-            ),
-            # backslashes, quotes and formatting signs must be parsed one at a time
-            (r'[^\\\'"%{\n]+', ttype),
-            (r'[\'"\\]', ttype),
-            # unhandled string formatting sign
-            (r"%|(\{{1,2})", ttype),
-            # newlines are an error (use "nl" state)
-        ]
-
-    def fstring_rules(ttype):
-        return [
-            # Assuming that a '}' is the closing brace after format specifier.
-            # Sadly, this means that we won't detect syntax error. But it's
-            # more important to parse correct syntax correctly, than to
-            # highlight invalid syntax.
-            (r"\}", String.Interpol),
-            (r"\{", String.Interpol, "expr-inside-fstring"),
-            # backslashes, quotes and formatting signs must be parsed one at a time
-            (r'[^\\\'"{}\n]+', ttype),
-            (r'[\'"\\]', ttype),
-            # newlines are an error (use "nl" state)
-        ]
-
-    tokens = {
-        "root": [
-            (r"\s+", Whitespace),
-            (
-                r'^(\s*)([rRuUbB]{,2})("""(?:.|\n)*?""")',
-                bygroups(Whitespace, String.Affix, String.Doc),
-            ),
-            (
-                r"^(\s*)([rRuUbB]{,2})('''(?:.|\n)*?''')",
-                bygroups(Whitespace, String.Affix, String.Doc),
-            ),
-            (r"\A#!.+$", Comment.Hashbang),
-            (r"#.*$", Comment.Single),
-            (r"\\\n", Whitespace),
-            (r"\\", Whitespace),
-            include("keywords"),
-            include("soft-keywords"),
-            # In the original PR, all the below here used ((?:\s|\\\s)+) to
-            # designate whitespace, but I can't find any example of this being
-            # needed in the example file, so we're replacing it with `\s+`.
-            (
-                r"(alias)(\s+)",
-                bygroups(Keyword, Whitespace),
-                "varname",  # TODO varname the right fit?
-            ),
-            (r"(var)(\s+)", bygroups(Keyword, Whitespace), "varname"),
-            (r"(def)(\s+)", bygroups(Keyword, Whitespace), "funcname"),
-            (r"(fn)(\s+)", bygroups(Keyword, Whitespace), "funcname"),
-            (
-                r"(class)(\s+)",
-                bygroups(Keyword, Whitespace),
-                "classname",
-            ),  # not implemented yet
-            (r"(struct)(\s+)", bygroups(Keyword, Whitespace), "structname"),
-            (r"(trait)(\s+)", bygroups(Keyword, Whitespace), "structname"),
-            (r"(from)(\s+)", bygroups(Keyword.Namespace, Whitespace), "fromimport"),
-            (r"(import)(\s+)", bygroups(Keyword.Namespace, Whitespace), "import"),
-            include("expr"),
-        ],
-        "expr": [
-            # raw f-strings
-            (
-                '(?i)(rf|fr)(""")',
-                bygroups(String.Affix, String.Double),
-                combined("rfstringescape", "tdqf"),
-            ),
-            (
-                "(?i)(rf|fr)(''')",
-                bygroups(String.Affix, String.Single),
-                combined("rfstringescape", "tsqf"),
-            ),
-            (
-                '(?i)(rf|fr)(")',
-                bygroups(String.Affix, String.Double),
-                combined("rfstringescape", "dqf"),
-            ),
-            (
-                "(?i)(rf|fr)(')",
-                bygroups(String.Affix, String.Single),
-                combined("rfstringescape", "sqf"),
-            ),
-            # non-raw f-strings
-            (
-                '([fF])(""")',
-                bygroups(String.Affix, String.Double),
-                combined("fstringescape", "tdqf"),
-            ),
-            (
-                "([fF])(''')",
-                bygroups(String.Affix, String.Single),
-                combined("fstringescape", "tsqf"),
-            ),
-            (
-                '([fF])(")',
-                bygroups(String.Affix, String.Double),
-                combined("fstringescape", "dqf"),
-            ),
-            (
-                "([fF])(')",
-                bygroups(String.Affix, String.Single),
-                combined("fstringescape", "sqf"),
-            ),
-            # raw bytes and strings
-            ('(?i)(rb|br|r)(""")', bygroups(String.Affix, String.Double), "tdqs"),
-            ("(?i)(rb|br|r)(''')", bygroups(String.Affix, String.Single), "tsqs"),
-            ('(?i)(rb|br|r)(")', bygroups(String.Affix, String.Double), "dqs"),
-            ("(?i)(rb|br|r)(')", bygroups(String.Affix, String.Single), "sqs"),
-            # non-raw strings
-            (
-                '([uU]?)(""")',
-                bygroups(String.Affix, String.Double),
-                combined("stringescape", "tdqs"),
-            ),
-            (
-                "([uU]?)(''')",
-                bygroups(String.Affix, String.Single),
-                combined("stringescape", "tsqs"),
-            ),
-            (
-                '([uU]?)(")',
-                bygroups(String.Affix, String.Double),
-                combined("stringescape", "dqs"),
-            ),
-            (
-                "([uU]?)(')",
-                bygroups(String.Affix, String.Single),
-                combined("stringescape", "sqs"),
-            ),
-            # non-raw bytes
-            (
-                '([bB])(""")',
-                bygroups(String.Affix, String.Double),
-                combined("bytesescape", "tdqs"),
-            ),
-            (
-                "([bB])(''')",
-                bygroups(String.Affix, String.Single),
-                combined("bytesescape", "tsqs"),
-            ),
-            (
-                '([bB])(")',
-                bygroups(String.Affix, String.Double),
-                combined("bytesescape", "dqs"),
-            ),
-            (
-                "([bB])(')",
-                bygroups(String.Affix, String.Single),
-                combined("bytesescape", "sqs"),
-            ),
-            (r"[^\S\n]+", Text),
-            include("numbers"),
-            (r"!=|==|<<|>>|:=|[-~+/*%=<>&^|.]", Operator),
-            (r"([]{}:\(\),;[])+", Punctuation),
-            (r"(in|is|and|or|not)\b", Operator.Word),
-            include("expr-keywords"),
-            include("builtins"),
-            include("magicfuncs"),
-            include("magicvars"),
-            include("name"),
-        ],
-        "expr-inside-fstring": [
-            (r"[{([]", Punctuation, "expr-inside-fstring-inner"),
-            # without format specifier
-            (
-                r"(=\s*)?"  # debug (https://bugs.python.org/issue36817)
-                r"(\![sraf])?"  # conversion
-                r"\}",
-                String.Interpol,
-                "#pop",
-            ),
-            # with format specifier
-            # we'll catch the remaining '}' in the outer scope
-            (
-                r"(=\s*)?"  # debug (https://bugs.python.org/issue36817)
-                r"(\![sraf])?"  # conversion
-                r":",
-                String.Interpol,
-                "#pop",
-            ),
-            (r"\s+", Whitespace),  # allow new lines
-            include("expr"),
-        ],
-        "expr-inside-fstring-inner": [
-            (r"[{([]", Punctuation, "expr-inside-fstring-inner"),
-            (r"[])}]", Punctuation, "#pop"),
-            (r"\s+", Whitespace),  # allow new lines
-            include("expr"),
-        ],
-        "expr-keywords": [
-            # Based on https://docs.python.org/3/reference/expressions.html
-            (
-                words(
-                    (
-                        "async for",  # TODO https://docs.modular.com/mojo/roadmap#no-async-for-or-async-with
-                        "async with",  # TODO https://docs.modular.com/mojo/roadmap#no-async-for-or-async-with
-                        "await",
-                        "else",
-                        "for",
-                        "if",
-                        "lambda",
-                        "yield",
-                        "yield from",
-                    ),
-                    suffix=r"\b",
-                ),
-                Keyword,
-            ),
-            (words(("True", "False", "None"), suffix=r"\b"), Keyword.Constant),
-        ],
-        "keywords": [
-            (
-                words(
-                    (
-                        "assert",
-                        "async",
-                        "await",
-                        "borrowed",
-                        "break",
-                        "continue",
-                        "del",
-                        "elif",
-                        "else",
-                        "except",
-                        "finally",
-                        "for",
-                        "global",
-                        "if",
-                        "lambda",
-                        "pass",
-                        "raise",
-                        "nonlocal",
-                        "return",
-                        "try",
-                        "while",
-                        "yield",
-                        "yield from",
-                        "as",
-                        "with",
-                    ),
-                    suffix=r"\b",
-                ),
-                Keyword,
-            ),
-            (words(("True", "False", "None"), suffix=r"\b"), Keyword.Constant),
-        ],
-        "soft-keywords": [
-            # `match`, `case` and `_` soft keywords
-            (
-                r"(^[ \t]*)"  # at beginning of line + possible indentation
-                r"(match|case)\b"  # a possible keyword
-                r"(?![ \t]*(?:"  # not followed by...
-                r"[:,;=^&|@~)\]}]|(?:" +  # characters and keywords that mean this isn't
-                # pattern matching (but None/True/False is ok)
-                r"|".join(k for k in keyword.kwlist if k[0].islower())
-                + r")\b))",
-                bygroups(Whitespace, Keyword),
-                "soft-keywords-inner",
-            ),
-        ],
-        "soft-keywords-inner": [
-            # optional `_` keyword
-            (r"(\s+)([^\n_]*)(_\b)", bygroups(Whitespace, using(this), Keyword)),
-            default("#pop"),
-        ],
-        "builtins": [
-            (
-                words(
-                    (
-                        "__import__",
-                        "abs",
-                        "aiter",
-                        "all",
-                        "any",
-                        "bin",
-                        "bool",
-                        "bytearray",
-                        "breakpoint",
-                        "bytes",
-                        "callable",
-                        "chr",
-                        "classmethod",
-                        "compile",
-                        "complex",
-                        "delattr",
-                        "dict",
-                        "dir",
-                        "divmod",
-                        "enumerate",
-                        "eval",
-                        "filter",
-                        "float",
-                        "format",
-                        "frozenset",
-                        "getattr",
-                        "globals",
-                        "hasattr",
-                        "hash",
-                        "hex",
-                        "id",
-                        "input",
-                        "int",
-                        "isinstance",
-                        "issubclass",
-                        "iter",
-                        "len",
-                        "list",
-                        "locals",
-                        "map",
-                        "max",
-                        "memoryview",
-                        "min",
-                        "next",
-                        "object",
-                        "oct",
-                        "open",
-                        "ord",
-                        "pow",
-                        "print",
-                        "property",
-                        "range",
-                        "repr",
-                        "reversed",
-                        "round",
-                        "set",
-                        "setattr",
-                        "slice",
-                        "sorted",
-                        "staticmethod",
-                        "str",
-                        "sum",
-                        "super",
-                        "tuple",
-                        "type",
-                        "vars",
-                        "zip",
-                        # Mojo builtin types: https://docs.modular.com/mojo/stdlib/builtin/
-                        "AnyType",
-                        "Coroutine",
-                        "DType",
-                        "Error",
-                        "Int",
-                        "List",
-                        "ListLiteral",
-                        "Scalar",
-                        "Int8",
-                        "UInt8",
-                        "Int16",
-                        "UInt16",
-                        "Int32",
-                        "UInt32",
-                        "Int64",
-                        "UInt64",
-                        "BFloat16",
-                        "Float16",
-                        "Float32",
-                        "Float64",
-                        "SIMD",
-                        "String",
-                        "Tensor",
-                        "Tuple",
-                        "Movable",
-                        "Copyable",
-                        "CollectionElement",
-                    ),
-                    prefix=r"(?>',
-    # Binary augmented
-    '+=', '-=', '*=', '/=', '%=', '**=', '&=', '|=', '^=', '<<=', '>>=',
-    # Comparison
-    '==', '!=', '<', '<=', '>', '>=', '<=>',
-    # Patterns and assignment
-    ':=', '?', '=~', '!~', '=>',
-    # Calls and sends
-    '.', '<-', '->',
-]
-_escape_pattern = (
-    r'(?:\\x[0-9a-fA-F]{2}|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}|'
-    r'\\["\'\\bftnr])')
-# _char = _escape_chars + [('.', String.Char)]
-_identifier = r'[_a-zA-Z]\w*'
-
-_constants = [
-    # Void constants
-    'null',
-    # Bool constants
-    'false', 'true',
-    # Double constants
-    'Infinity', 'NaN',
-    # Special objects
-    'M', 'Ref', 'throw', 'traceln',
-]
-
-_guards = [
-    'Any', 'Binding', 'Bool', 'Bytes', 'Char', 'DeepFrozen', 'Double',
-    'Empty', 'Int', 'List', 'Map', 'Near', 'NullOk', 'Same', 'Selfless',
-    'Set', 'Str', 'SubrangeGuard', 'Transparent', 'Void',
-]
-
-_safeScope = [
-    '_accumulateList', '_accumulateMap', '_auditedBy', '_bind',
-    '_booleanFlow', '_comparer', '_equalizer', '_iterForever', '_loop',
-    '_makeBytes', '_makeDouble', '_makeFinalSlot', '_makeInt', '_makeList',
-    '_makeMap', '_makeMessageDesc', '_makeOrderedSpace', '_makeParamDesc',
-    '_makeProtocolDesc', '_makeSourceSpan', '_makeString', '_makeVarSlot',
-    '_makeVerbFacet', '_mapExtract', '_matchSame', '_quasiMatcher',
-    '_slotToBinding', '_splitList', '_suchThat', '_switchFailed',
-    '_validateFor', 'b__quasiParser', 'eval', 'import', 'm__quasiParser',
-    'makeBrandPair', 'makeLazySlot', 'safeScope', 'simple__quasiParser',
-]
-
-
-class MonteLexer(RegexLexer):
-    """
-    Lexer for the Monte programming language.
-    """
-    name = 'Monte'
-    url = 'https://monte.readthedocs.io/'
-    aliases = ['monte']
-    filenames = ['*.mt']
-    version_added = '2.2'
-
-    tokens = {
-        'root': [
-            # Comments
-            (r'#[^\n]*\n', Comment),
-
-            # Docstrings
-            # Apologies for the non-greedy matcher here.
-            (r'/\*\*.*?\*/', String.Doc),
-
-            # `var` declarations
-            (r'\bvar\b', Keyword.Declaration, 'var'),
-
-            # `interface` declarations
-            (r'\binterface\b', Keyword.Declaration, 'interface'),
-
-            # method declarations
-            (words(_methods, prefix='\\b', suffix='\\b'),
-             Keyword, 'method'),
-
-            # All other declarations
-            (words(_declarations, prefix='\\b', suffix='\\b'),
-             Keyword.Declaration),
-
-            # Keywords
-            (words(_keywords, prefix='\\b', suffix='\\b'), Keyword),
-
-            # Literals
-            ('[+-]?0x[_0-9a-fA-F]+', Number.Hex),
-            (r'[+-]?[_0-9]+\.[_0-9]*([eE][+-]?[_0-9]+)?', Number.Float),
-            ('[+-]?[_0-9]+', Number.Integer),
-            ("'", String.Double, 'char'),
-            ('"', String.Double, 'string'),
-
-            # Quasiliterals
-            ('`', String.Backtick, 'ql'),
-
-            # Operators
-            (words(_operators), Operator),
-
-            # Verb operators
-            (_identifier + '=', Operator.Word),
-
-            # Safe scope constants
-            (words(_constants, prefix='\\b', suffix='\\b'),
-             Keyword.Pseudo),
-
-            # Safe scope guards
-            (words(_guards, prefix='\\b', suffix='\\b'), Keyword.Type),
-
-            # All other safe scope names
-            (words(_safeScope, prefix='\\b', suffix='\\b'),
-             Name.Builtin),
-
-            # Identifiers
-            (_identifier, Name),
-
-            # Punctuation
-            (r'\(|\)|\{|\}|\[|\]|:|,', Punctuation),
-
-            # Whitespace
-            (' +', Whitespace),
-
-            # Definite lexer errors
-            ('=', Error),
-        ],
-        'char': [
-            # It is definitely an error to have a char of width == 0.
-            ("'", Error, 'root'),
-            (_escape_pattern, String.Escape, 'charEnd'),
-            ('.', String.Char, 'charEnd'),
-        ],
-        'charEnd': [
-            ("'", String.Char, '#pop:2'),
-            # It is definitely an error to have a char of width > 1.
-            ('.', Error),
-        ],
-        # The state of things coming into an interface.
-        'interface': [
-            (' +', Whitespace),
-            (_identifier, Name.Class, '#pop'),
-            include('root'),
-        ],
-        # The state of things coming into a method.
-        'method': [
-            (' +', Whitespace),
-            (_identifier, Name.Function, '#pop'),
-            include('root'),
-        ],
-        'string': [
-            ('"', String.Double, 'root'),
-            (_escape_pattern, String.Escape),
-            (r'\n', String.Double),
-            ('.', String.Double),
-        ],
-        'ql': [
-            ('`', String.Backtick, 'root'),
-            (r'\$' + _escape_pattern, String.Escape),
-            (r'\$\$', String.Escape),
-            (r'@@', String.Escape),
-            (r'\$\{', String.Interpol, 'qlNest'),
-            (r'@\{', String.Interpol, 'qlNest'),
-            (r'\$' + _identifier, Name),
-            ('@' + _identifier, Name),
-            ('.', String.Backtick),
-        ],
-        'qlNest': [
-            (r'\}', String.Interpol, '#pop'),
-            include('root'),
-        ],
-        # The state of things immediately following `var`.
-        'var': [
-            (' +', Whitespace),
-            (_identifier, Name.Variable, '#pop'),
-            include('root'),
-        ],
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/mosel.py b/.venv/lib/python3.12/site-packages/pygments/lexers/mosel.py
deleted file mode 100644
index 912f478..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/mosel.py
+++ /dev/null
@@ -1,447 +0,0 @@
-"""
-    pygments.lexers.mosel
-    ~~~~~~~~~~~~~~~~~~~~~
-
-    Lexers for the mosel language.
-    http://www.fico.com/en/products/fico-xpress-optimization
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-from pygments.lexer import RegexLexer, words
-from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
-    Number, Punctuation
-
-__all__ = ['MoselLexer']
-
-FUNCTIONS = (
-    # core functions
-    '_',
-    'abs',
-    'arctan',
-    'asproc',
-    'assert',
-    'bitflip',
-    'bitneg',
-    'bitset',
-    'bitshift',
-    'bittest',
-    'bitval',
-    'ceil',
-    'cos',
-    'create',
-    'currentdate',
-    'currenttime',
-    'cutelt',
-    'cutfirst',
-    'cuthead',
-    'cutlast',
-    'cuttail',
-    'datablock',
-    'delcell',
-    'exists',
-    'exit',
-    'exp',
-    'exportprob',
-    'fclose',
-    'fflush',
-    'finalize',
-    'findfirst',
-    'findlast',
-    'floor',
-    'fopen',
-    'fselect',
-    'fskipline',
-    'fwrite',
-    'fwrite_',
-    'fwriteln',
-    'fwriteln_',
-    'getact',
-    'getcoeff',
-    'getcoeffs',
-    'getdual',
-    'getelt',
-    'getfid',
-    'getfirst',
-    'getfname',
-    'gethead',
-    'getlast',
-    'getobjval',
-    'getparam',
-    'getrcost',
-    'getreadcnt',
-    'getreverse',
-    'getsize',
-    'getslack',
-    'getsol',
-    'gettail',
-    'gettype',
-    'getvars',
-    'isdynamic',
-    'iseof',
-    'isfinite',
-    'ishidden',
-    'isinf',
-    'isnan',
-    'isodd',
-    'ln',
-    'localsetparam',
-    'log',
-    'makesos1',
-    'makesos2',
-    'maxlist',
-    'memoryuse',
-    'minlist',
-    'newmuid',
-    'publish',
-    'random',
-    'read',
-    'readln',
-    'reset',
-    'restoreparam',
-    'reverse',
-    'round',
-    'setcoeff',
-    'sethidden',
-    'setioerr',
-    'setmatherr',
-    'setname',
-    'setparam',
-    'setrandseed',
-    'setrange',
-    'settype',
-    'sin',
-    'splithead',
-    'splittail',
-    'sqrt',
-    'strfmt',
-    'substr',
-    'timestamp',
-    'unpublish',
-    'versionnum',
-    'versionstr',
-    'write',
-    'write_',
-    'writeln',
-    'writeln_',
-
-    # mosel exam mmxprs | sed -n -e "s/ [pf][a-z]* \([a-zA-Z0-9_]*\).*/'\1',/p" | sort -u
-    'addcut',
-    'addcuts',
-    'addmipsol',
-    'basisstability',
-    'calcsolinfo',
-    'clearmipdir',
-    'clearmodcut',
-    'command',
-    'copysoltoinit',
-    'crossoverlpsol',
-    'defdelayedrows',
-    'defsecurevecs',
-    'delcuts',
-    'dropcuts',
-    'estimatemarginals',
-    'fixglobal',
-    'flushmsgq',
-    'getbstat',
-    'getcnlist',
-    'getcplist',
-    'getdualray',
-    'getiis',
-    'getiissense',
-    'getiistype',
-    'getinfcause',
-    'getinfeas',
-    'getlb',
-    'getlct',
-    'getleft',
-    'getloadedlinctrs',
-    'getloadedmpvars',
-    'getname',
-    'getprimalray',
-    'getprobstat',
-    'getrange',
-    'getright',
-    'getsensrng',
-    'getsize',
-    'getsol',
-    'gettype',
-    'getub',
-    'getvars',
-    'gety',
-    'hasfeature',
-    'implies',
-    'indicator',
-    'initglobal',
-    'ishidden',
-    'isiisvalid',
-    'isintegral',
-    'loadbasis',
-    'loadcuts',
-    'loadlpsol',
-    'loadmipsol',
-    'loadprob',
-    'maximise',
-    'maximize',
-    'minimise',
-    'minimize',
-    'postsolve',
-    'readbasis',
-    'readdirs',
-    'readsol',
-    'refinemipsol',
-    'rejectintsol',
-    'repairinfeas',
-    'repairinfeas_deprec',
-    'resetbasis',
-    'resetiis',
-    'resetsol',
-    'savebasis',
-    'savemipsol',
-    'savesol',
-    'savestate',
-    'selectsol',
-    'setarchconsistency',
-    'setbstat',
-    'setcallback',
-    'setcbcutoff',
-    'setgndata',
-    'sethidden',
-    'setlb',
-    'setmipdir',
-    'setmodcut',
-    'setsol',
-    'setub',
-    'setucbdata',
-    'stopoptimise',
-    'stopoptimize',
-    'storecut',
-    'storecuts',
-    'unloadprob',
-    'uselastbarsol',
-    'writebasis',
-    'writedirs',
-    'writeprob',
-    'writesol',
-    'xor',
-    'xprs_addctr',
-    'xprs_addindic',
-
-    # mosel exam mmsystem | sed -n -e "s/ [pf][a-z]* \([a-zA-Z0-9_]*\).*/'\1',/p" | sort -u
-    'addmonths',
-    'copytext',
-    'cuttext',
-    'deltext',
-    'endswith',
-    'erase',
-    'expandpath',
-    'fcopy',
-    'fdelete',
-    'findfiles',
-    'findtext',
-    'fmove',
-    'formattext',
-    'getasnumber',
-    'getchar',
-    'getcwd',
-    'getdate',
-    'getday',
-    'getdaynum',
-    'getdays',
-    'getdirsep',
-    'getdsoparam',
-    'getendparse',
-    'getenv',
-    'getfsize',
-    'getfstat',
-    'getftime',
-    'gethour',
-    'getminute',
-    'getmonth',
-    'getmsec',
-    'getoserrmsg',
-    'getoserror',
-    'getpathsep',
-    'getqtype',
-    'getsecond',
-    'getsepchar',
-    'getsize',
-    'getstart',
-    'getsucc',
-    'getsysinfo',
-    'getsysstat',
-    'gettime',
-    'gettmpdir',
-    'gettrim',
-    'getweekday',
-    'getyear',
-    'inserttext',
-    'isvalid',
-    'jointext',
-    'makedir',
-    'makepath',
-    'newtar',
-    'newzip',
-    'nextfield',
-    'openpipe',
-    'parseextn',
-    'parseint',
-    'parsereal',
-    'parsetext',
-    'pastetext',
-    'pathmatch',
-    'pathsplit',
-    'qsort',
-    'quote',
-    'readtextline',
-    'regmatch',
-    'regreplace',
-    'removedir',
-    'removefiles',
-    'setchar',
-    'setdate',
-    'setday',
-    'setdsoparam',
-    'setendparse',
-    'setenv',
-    'sethour',
-    'setminute',
-    'setmonth',
-    'setmsec',
-    'setoserror',
-    'setqtype',
-    'setsecond',
-    'setsepchar',
-    'setstart',
-    'setsucc',
-    'settime',
-    'settrim',
-    'setyear',
-    'sleep',
-    'splittext',
-    'startswith',
-    'system',
-    'tarlist',
-    'textfmt',
-    'tolower',
-    'toupper',
-    'trim',
-    'untar',
-    'unzip',
-    'ziplist',
-
-    # mosel exam mmjobs | sed -n -e "s/ [pf][a-z]* \([a-zA-Z0-9_]*\).*/'\1',/p" | sort -u
-    'canceltimer',
-    'clearaliases',
-    'compile',
-    'connect',
-    'detach',
-    'disconnect',
-    'dropnextevent',
-    'findxsrvs',
-    'getaliases',
-    'getannidents',
-    'getannotations',
-    'getbanner',
-    'getclass',
-    'getdsoprop',
-    'getdsopropnum',
-    'getexitcode',
-    'getfromgid',
-    'getfromid',
-    'getfromuid',
-    'getgid',
-    'gethostalias',
-    'getid',
-    'getmodprop',
-    'getmodpropnum',
-    'getnextevent',
-    'getnode',
-    'getrmtid',
-    'getstatus',
-    'getsysinfo',
-    'gettimer',
-    'getuid',
-    'getvalue',
-    'isqueueempty',
-    'load',
-    'nullevent',
-    'peeknextevent',
-    'resetmodpar',
-    'run',
-    'send',
-    'setcontrol',
-    'setdefstream',
-    'setgid',
-    'sethostalias',
-    'setmodpar',
-    'settimer',
-    'setuid',
-    'setworkdir',
-    'stop',
-    'unload',
-    'wait',
-    'waitexpired',
-    'waitfor',
-    'waitforend',
-)
-
-
-class MoselLexer(RegexLexer):
-    """
-    For the Mosel optimization language.
-    """
-    name = 'Mosel'
-    aliases = ['mosel']
-    filenames = ['*.mos']
-    url = 'https://www.fico.com/fico-xpress-optimization/docs/latest/mosel/mosel_lang/dhtml/moselreflang.html'
-    version_added = '2.6'
-
-    tokens = {
-        'root': [
-            (r'\n', Text),
-            (r'\s+', Text.Whitespace),
-            (r'!.*?\n', Comment.Single),
-            (r'\(!(.|\n)*?!\)', Comment.Multiline),
-            (words((
-                'and', 'as', 'break', 'case', 'count', 'declarations', 'do',
-                'dynamic', 'elif', 'else', 'end-', 'end', 'evaluation', 'false',
-                'forall', 'forward', 'from', 'function', 'hashmap', 'if',
-                'imports', 'include', 'initialisations', 'initializations', 'inter',
-                'max', 'min', 'model', 'namespace', 'next', 'not', 'nsgroup',
-                'nssearch', 'of', 'options', 'or', 'package', 'parameters',
-                'procedure', 'public', 'prod', 'record', 'repeat', 'requirements',
-                'return', 'sum', 'then', 'to', 'true', 'union', 'until', 'uses',
-                'version', 'while', 'with'), prefix=r'\b', suffix=r'\b'),
-             Keyword.Builtin),
-            (words((
-                'range', 'array', 'set', 'list', 'mpvar', 'mpproblem', 'linctr',
-                'nlctr', 'integer', 'string', 'real', 'boolean', 'text', 'time',
-                'date', 'datetime', 'returned', 'Model', 'Mosel', 'counter',
-                'xmldoc', 'is_sos1', 'is_sos2', 'is_integer', 'is_binary',
-                'is_continuous', 'is_free', 'is_semcont', 'is_semint',
-                'is_partint'), prefix=r'\b', suffix=r'\b'),
-             Keyword.Type),
-            (r'(\+|\-|\*|/|=|<=|>=|\||\^|<|>|<>|\.\.|\.|:=|::|:|in|mod|div)',
-             Operator),
-            (r'[()\[\]{},;]+', Punctuation),
-            (words(FUNCTIONS,  prefix=r'\b', suffix=r'\b'), Name.Function),
-            (r'(\d+\.(?!\.)\d*|\.(?!.)\d+)([eE][+-]?\d+)?', Number.Float),
-            (r'\d+([eE][+-]?\d+)?', Number.Integer),
-            (r'[+-]?Infinity', Number.Integer),
-            (r'0[xX][0-9a-fA-F]+', Number),
-            (r'"', String.Double, 'double_quote'),
-            (r'\'', String.Single, 'single_quote'),
-            (r'(\w+|(\.(?!\.)))', Text),
-        ],
-        'single_quote': [
-            (r'\'', String.Single, '#pop'),
-            (r'[^\']+', String.Single),
-        ],
-        'double_quote': [
-            (r'(\\"|\\[0-7]{1,3}\D|\\[abfnrtv]|\\\\)', String.Escape),
-            (r'\"', String.Double, '#pop'),
-            (r'[^"\\]+', String.Double),
-        ],
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/ncl.py b/.venv/lib/python3.12/site-packages/pygments/lexers/ncl.py
deleted file mode 100644
index a2729ef..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/ncl.py
+++ /dev/null
@@ -1,894 +0,0 @@
-"""
-    pygments.lexers.ncl
-    ~~~~~~~~~~~~~~~~~~~
-
-    Lexers for NCAR Command Language.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-import re
-
-from pygments.lexer import RegexLexer, include, words
-from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
-    Number, Punctuation
-
-__all__ = ['NCLLexer']
-
-
-class NCLLexer(RegexLexer):
-    """
-    Lexer for NCL code.
-    """
-    name = 'NCL'
-    aliases = ['ncl']
-    filenames = ['*.ncl']
-    mimetypes = ['text/ncl']
-    url = 'https://www.ncl.ucar.edu'
-    version_added = '2.2'
-
-    flags = re.MULTILINE
-
-    tokens = {
-        'root': [
-            (r';.*\n', Comment),
-            include('strings'),
-            include('core'),
-            (r'[a-zA-Z_]\w*', Name),
-            include('nums'),
-            (r'[\s]+', Text),
-        ],
-        'core': [
-            # Statements
-            (words((
-                'begin', 'break', 'continue', 'create', 'defaultapp', 'do',
-                'else', 'end', 'external', 'exit', 'True', 'False', 'file', 'function',
-                'getvalues', 'graphic', 'group', 'if', 'list', 'load', 'local',
-                'new', '_Missing', 'Missing', 'noparent', 'procedure',
-                'quit', 'QUIT', 'Quit', 'record', 'return', 'setvalues', 'stop',
-                'then', 'while'), prefix=r'\b', suffix=r'\s*\b'),
-             Keyword),
-
-            # Data Types
-            (words((
-                'ubyte', 'uint', 'uint64', 'ulong', 'string', 'byte',
-                'character', 'double', 'float', 'integer', 'int64', 'logical',
-                'long', 'short', 'ushort', 'enumeric', 'numeric', 'snumeric'),
-                prefix=r'\b', suffix=r'\s*\b'),
-             Keyword.Type),
-
-            # Operators
-            (r'[\%^*+\-/<>]', Operator),
-
-            # punctuation:
-            (r'[\[\]():@$!&|.,\\{}]', Punctuation),
-            (r'[=:]', Punctuation),
-
-            # Intrinsics
-            (words((
-                'abs', 'acos', 'addfile', 'addfiles', 'all', 'angmom_atm', 'any',
-                'area_conserve_remap', 'area_hi2lores', 'area_poly_sphere',
-                'asciiread', 'asciiwrite', 'asin', 'atan', 'atan2', 'attsetvalues',
-                'avg', 'betainc', 'bin_avg', 'bin_sum', 'bw_bandpass_filter',
-                'cancor', 'cbinread', 'cbinwrite', 'cd_calendar', 'cd_inv_calendar',
-                'cdfbin_p', 'cdfbin_pr', 'cdfbin_s', 'cdfbin_xn', 'cdfchi_p',
-                'cdfchi_x', 'cdfgam_p', 'cdfgam_x', 'cdfnor_p', 'cdfnor_x',
-                'cdft_p', 'cdft_t', 'ceil', 'center_finite_diff',
-                'center_finite_diff_n', 'cfftb', 'cfftf', 'cfftf_frq_reorder',
-                'charactertodouble', 'charactertofloat', 'charactertointeger',
-                'charactertolong', 'charactertoshort', 'charactertostring',
-                'chartodouble', 'chartofloat', 'chartoint', 'chartointeger',
-                'chartolong', 'chartoshort', 'chartostring', 'chiinv', 'clear',
-                'color_index_to_rgba', 'conform', 'conform_dims', 'cos', 'cosh',
-                'count_unique_values', 'covcorm', 'covcorm_xy', 'craybinnumrec',
-                'craybinrecread', 'create_graphic', 'csa1', 'csa1d', 'csa1s',
-                'csa1x', 'csa1xd', 'csa1xs', 'csa2', 'csa2d', 'csa2l', 'csa2ld',
-                'csa2ls', 'csa2lx', 'csa2lxd', 'csa2lxs', 'csa2s', 'csa2x',
-                'csa2xd', 'csa2xs', 'csa3', 'csa3d', 'csa3l', 'csa3ld', 'csa3ls',
-                'csa3lx', 'csa3lxd', 'csa3lxs', 'csa3s', 'csa3x', 'csa3xd',
-                'csa3xs', 'csc2s', 'csgetp', 'css2c', 'cssetp', 'cssgrid', 'csstri',
-                'csvoro', 'cumsum', 'cz2ccm', 'datatondc', 'day_of_week',
-                'day_of_year', 'days_in_month', 'default_fillvalue', 'delete',
-                'depth_to_pres', 'destroy', 'determinant', 'dewtemp_trh',
-                'dgeevx_lapack', 'dim_acumrun_n', 'dim_avg', 'dim_avg_n',
-                'dim_avg_wgt', 'dim_avg_wgt_n', 'dim_cumsum', 'dim_cumsum_n',
-                'dim_gamfit_n', 'dim_gbits', 'dim_max', 'dim_max_n', 'dim_median',
-                'dim_median_n', 'dim_min', 'dim_min_n', 'dim_num', 'dim_num_n',
-                'dim_numrun_n', 'dim_pqsort', 'dim_pqsort_n', 'dim_product',
-                'dim_product_n', 'dim_rmsd', 'dim_rmsd_n', 'dim_rmvmean',
-                'dim_rmvmean_n', 'dim_rmvmed', 'dim_rmvmed_n', 'dim_spi_n',
-                'dim_standardize', 'dim_standardize_n', 'dim_stat4', 'dim_stat4_n',
-                'dim_stddev', 'dim_stddev_n', 'dim_sum', 'dim_sum_n', 'dim_sum_wgt',
-                'dim_sum_wgt_n', 'dim_variance', 'dim_variance_n', 'dimsizes',
-                'doubletobyte', 'doubletochar', 'doubletocharacter',
-                'doubletofloat', 'doubletoint', 'doubletointeger', 'doubletolong',
-                'doubletoshort', 'dpres_hybrid_ccm', 'dpres_plevel', 'draw',
-                'draw_color_palette', 'dsgetp', 'dsgrid2', 'dsgrid2d', 'dsgrid2s',
-                'dsgrid3', 'dsgrid3d', 'dsgrid3s', 'dspnt2', 'dspnt2d', 'dspnt2s',
-                'dspnt3', 'dspnt3d', 'dspnt3s', 'dssetp', 'dtrend', 'dtrend_msg',
-                'dtrend_msg_n', 'dtrend_n', 'dtrend_quadratic',
-                'dtrend_quadratic_msg_n', 'dv2uvf', 'dv2uvg', 'dz_height',
-                'echo_off', 'echo_on', 'eof2data', 'eof_varimax', 'eofcor',
-                'eofcor_pcmsg', 'eofcor_ts', 'eofcov', 'eofcov_pcmsg', 'eofcov_ts',
-                'eofunc', 'eofunc_ts', 'eofunc_varimax', 'equiv_sample_size', 'erf',
-                'erfc', 'esacr', 'esacv', 'esccr', 'esccv', 'escorc', 'escorc_n',
-                'escovc', 'exit', 'exp', 'exp_tapersh', 'exp_tapersh_wgts',
-                'exp_tapershC', 'ezfftb', 'ezfftb_n', 'ezfftf', 'ezfftf_n',
-                'f2fosh', 'f2foshv', 'f2fsh', 'f2fshv', 'f2gsh', 'f2gshv', 'fabs',
-                'fbindirread', 'fbindirwrite', 'fbinnumrec', 'fbinread',
-                'fbinrecread', 'fbinrecwrite', 'fbinwrite', 'fft2db', 'fft2df',
-                'fftshift', 'fileattdef', 'filechunkdimdef', 'filedimdef',
-                'fileexists', 'filegrpdef', 'filevarattdef', 'filevarchunkdef',
-                'filevarcompressleveldef', 'filevardef', 'filevardimsizes',
-                'filwgts_lancos', 'filwgts_lanczos', 'filwgts_normal',
-                'floattobyte', 'floattochar', 'floattocharacter', 'floattoint',
-                'floattointeger', 'floattolong', 'floattoshort', 'floor',
-                'fluxEddy', 'fo2fsh', 'fo2fshv', 'fourier_info', 'frame', 'fspan',
-                'ftcurv', 'ftcurvd', 'ftcurvi', 'ftcurvp', 'ftcurvpi', 'ftcurvps',
-                'ftcurvs', 'ftest', 'ftgetp', 'ftkurv', 'ftkurvd', 'ftkurvp',
-                'ftkurvpd', 'ftsetp', 'ftsurf', 'g2fsh', 'g2fshv', 'g2gsh',
-                'g2gshv', 'gamma', 'gammainc', 'gaus', 'gaus_lobat',
-                'gaus_lobat_wgt', 'gc_aangle', 'gc_clkwise', 'gc_dangle',
-                'gc_inout', 'gc_latlon', 'gc_onarc', 'gc_pnt2gc', 'gc_qarea',
-                'gc_tarea', 'generate_2d_array', 'get_color_index',
-                'get_color_rgba', 'get_cpu_time', 'get_isolines', 'get_ncl_version',
-                'get_script_name', 'get_script_prefix_name', 'get_sphere_radius',
-                'get_unique_values', 'getbitsone', 'getenv', 'getfiledimsizes',
-                'getfilegrpnames', 'getfilepath', 'getfilevaratts',
-                'getfilevarchunkdimsizes', 'getfilevardims', 'getfilevardimsizes',
-                'getfilevarnames', 'getfilevartypes', 'getvaratts', 'getvardims',
-                'gradsf', 'gradsg', 'greg2jul', 'grid2triple', 'hlsrgb', 'hsvrgb',
-                'hydro', 'hyi2hyo', 'idsfft', 'igradsf', 'igradsg', 'ilapsf',
-                'ilapsg', 'ilapvf', 'ilapvg', 'ind', 'ind_resolve', 'int2p',
-                'int2p_n', 'integertobyte', 'integertochar', 'integertocharacter',
-                'integertoshort', 'inttobyte', 'inttochar', 'inttoshort',
-                'inverse_matrix', 'isatt', 'isbigendian', 'isbyte', 'ischar',
-                'iscoord', 'isdefined', 'isdim', 'isdimnamed', 'isdouble',
-                'isenumeric', 'isfile', 'isfilepresent', 'isfilevar',
-                'isfilevaratt', 'isfilevarcoord', 'isfilevardim', 'isfloat',
-                'isfunc', 'isgraphic', 'isint', 'isint64', 'isinteger',
-                'isleapyear', 'islogical', 'islong', 'ismissing', 'isnan_ieee',
-                'isnumeric', 'ispan', 'isproc', 'isshort', 'issnumeric', 'isstring',
-                'isubyte', 'isuint', 'isuint64', 'isulong', 'isunlimited',
-                'isunsigned', 'isushort', 'isvar', 'jul2greg', 'kmeans_as136',
-                'kolsm2_n', 'kron_product', 'lapsf', 'lapsg', 'lapvf', 'lapvg',
-                'latlon2utm', 'lclvl', 'lderuvf', 'lderuvg', 'linint1', 'linint1_n',
-                'linint2', 'linint2_points', 'linmsg', 'linmsg_n', 'linrood_latwgt',
-                'linrood_wgt', 'list_files', 'list_filevars', 'list_hlus',
-                'list_procfuncs', 'list_vars', 'ListAppend', 'ListCount',
-                'ListGetType', 'ListIndex', 'ListIndexFromName', 'ListPop',
-                'ListPush', 'ListSetType', 'loadscript', 'local_max', 'local_min',
-                'log', 'log10', 'longtobyte', 'longtochar', 'longtocharacter',
-                'longtoint', 'longtointeger', 'longtoshort', 'lspoly', 'lspoly_n',
-                'mask', 'max', 'maxind', 'min', 'minind', 'mixed_layer_depth',
-                'mixhum_ptd', 'mixhum_ptrh', 'mjo_cross_coh2pha',
-                'mjo_cross_segment', 'moc_globe_atl', 'monthday', 'natgrid',
-                'natgridd', 'natgrids', 'ncargpath', 'ncargversion', 'ndctodata',
-                'ndtooned', 'new', 'NewList', 'ngezlogo', 'nggcog', 'nggetp',
-                'nglogo', 'ngsetp', 'NhlAddAnnotation', 'NhlAddData',
-                'NhlAddOverlay', 'NhlAddPrimitive', 'NhlAppGetDefaultParentId',
-                'NhlChangeWorkstation', 'NhlClassName', 'NhlClearWorkstation',
-                'NhlDataPolygon', 'NhlDataPolyline', 'NhlDataPolymarker',
-                'NhlDataToNDC', 'NhlDestroy', 'NhlDraw', 'NhlFrame', 'NhlFreeColor',
-                'NhlGetBB', 'NhlGetClassResources', 'NhlGetErrorObjectId',
-                'NhlGetNamedColorIndex', 'NhlGetParentId',
-                'NhlGetParentWorkstation', 'NhlGetWorkspaceObjectId',
-                'NhlIsAllocatedColor', 'NhlIsApp', 'NhlIsDataComm', 'NhlIsDataItem',
-                'NhlIsDataSpec', 'NhlIsTransform', 'NhlIsView', 'NhlIsWorkstation',
-                'NhlName', 'NhlNDCPolygon', 'NhlNDCPolyline', 'NhlNDCPolymarker',
-                'NhlNDCToData', 'NhlNewColor', 'NhlNewDashPattern', 'NhlNewMarker',
-                'NhlPalGetDefined', 'NhlRemoveAnnotation', 'NhlRemoveData',
-                'NhlRemoveOverlay', 'NhlRemovePrimitive', 'NhlSetColor',
-                'NhlSetDashPattern', 'NhlSetMarker', 'NhlUpdateData',
-                'NhlUpdateWorkstation', 'nice_mnmxintvl', 'nngetaspectd',
-                'nngetaspects', 'nngetp', 'nngetsloped', 'nngetslopes', 'nngetwts',
-                'nngetwtsd', 'nnpnt', 'nnpntd', 'nnpntend', 'nnpntendd',
-                'nnpntinit', 'nnpntinitd', 'nnpntinits', 'nnpnts', 'nnsetp', 'num',
-                'obj_anal_ic', 'omega_ccm', 'onedtond', 'overlay', 'paleo_outline',
-                'pdfxy_bin', 'poisson_grid_fill', 'pop_remap', 'potmp_insitu_ocn',
-                'prcwater_dp', 'pres2hybrid', 'pres_hybrid_ccm', 'pres_sigma',
-                'print', 'print_table', 'printFileVarSummary', 'printVarSummary',
-                'product', 'pslec', 'pslhor', 'pslhyp', 'qsort', 'rand',
-                'random_chi', 'random_gamma', 'random_normal', 'random_setallseed',
-                'random_uniform', 'rcm2points', 'rcm2rgrid', 'rdsstoi',
-                'read_colormap_file', 'reg_multlin', 'regcoef', 'regCoef_n',
-                'regline', 'relhum', 'replace_ieeenan', 'reshape', 'reshape_ind',
-                'rgba_to_color_index', 'rgbhls', 'rgbhsv', 'rgbyiq', 'rgrid2rcm',
-                'rhomb_trunc', 'rip_cape_2d', 'rip_cape_3d', 'round', 'rtest',
-                'runave', 'runave_n', 'set_default_fillvalue', 'set_sphere_radius',
-                'setfileoption', 'sfvp2uvf', 'sfvp2uvg', 'shaec', 'shagc',
-                'shgetnp', 'shgetp', 'shgrid', 'shorttobyte', 'shorttochar',
-                'shorttocharacter', 'show_ascii', 'shsec', 'shsetp', 'shsgc',
-                'shsgc_R42', 'sigma2hybrid', 'simpeq', 'simpne', 'sin',
-                'sindex_yrmo', 'sinh', 'sizeof', 'sleep', 'smth9', 'snindex_yrmo',
-                'solve_linsys', 'span_color_indexes', 'span_color_rgba',
-                'sparse_matrix_mult', 'spcorr', 'spcorr_n', 'specx_anal',
-                'specxy_anal', 'spei', 'sprintf', 'sprinti', 'sqrt', 'sqsort',
-                'srand', 'stat2', 'stat4', 'stat_medrng', 'stat_trim',
-                'status_exit', 'stdatmus_p2tdz', 'stdatmus_z2tdp', 'stddev',
-                'str_capital', 'str_concat', 'str_fields_count', 'str_get_cols',
-                'str_get_dq', 'str_get_field', 'str_get_nl', 'str_get_sq',
-                'str_get_tab', 'str_index_of_substr', 'str_insert', 'str_is_blank',
-                'str_join', 'str_left_strip', 'str_lower', 'str_match',
-                'str_match_ic', 'str_match_ic_regex', 'str_match_ind',
-                'str_match_ind_ic', 'str_match_ind_ic_regex', 'str_match_ind_regex',
-                'str_match_regex', 'str_right_strip', 'str_split',
-                'str_split_by_length', 'str_split_csv', 'str_squeeze', 'str_strip',
-                'str_sub_str', 'str_switch', 'str_upper', 'stringtochar',
-                'stringtocharacter', 'stringtodouble', 'stringtofloat',
-                'stringtoint', 'stringtointeger', 'stringtolong', 'stringtoshort',
-                'strlen', 'student_t', 'sum', 'svd_lapack', 'svdcov', 'svdcov_sv',
-                'svdstd', 'svdstd_sv', 'system', 'systemfunc', 'tan', 'tanh',
-                'taper', 'taper_n', 'tdclrs', 'tdctri', 'tdcudp', 'tdcurv',
-                'tddtri', 'tdez2d', 'tdez3d', 'tdgetp', 'tdgrds', 'tdgrid',
-                'tdgtrs', 'tdinit', 'tditri', 'tdlbla', 'tdlblp', 'tdlbls',
-                'tdline', 'tdlndp', 'tdlnpa', 'tdlpdp', 'tdmtri', 'tdotri',
-                'tdpara', 'tdplch', 'tdprpa', 'tdprpi', 'tdprpt', 'tdsetp',
-                'tdsort', 'tdstri', 'tdstrs', 'tdttri', 'thornthwaite', 'tobyte',
-                'tochar', 'todouble', 'tofloat', 'toint', 'toint64', 'tointeger',
-                'tolong', 'toshort', 'tosigned', 'tostring', 'tostring_with_format',
-                'totype', 'toubyte', 'touint', 'touint64', 'toulong', 'tounsigned',
-                'toushort', 'trend_manken', 'tri_trunc', 'triple2grid',
-                'triple2grid2d', 'trop_wmo', 'ttest', 'typeof', 'undef',
-                'unique_string', 'update', 'ushorttoint', 'ut_calendar',
-                'ut_inv_calendar', 'utm2latlon', 'uv2dv_cfd', 'uv2dvf', 'uv2dvg',
-                'uv2sfvpf', 'uv2sfvpg', 'uv2vr_cfd', 'uv2vrdvf', 'uv2vrdvg',
-                'uv2vrf', 'uv2vrg', 'v5d_close', 'v5d_create', 'v5d_setLowLev',
-                'v5d_setUnits', 'v5d_write', 'v5d_write_var', 'variance', 'vhaec',
-                'vhagc', 'vhsec', 'vhsgc', 'vibeta', 'vinth2p', 'vinth2p_ecmwf',
-                'vinth2p_ecmwf_nodes', 'vinth2p_nodes', 'vintp2p_ecmwf', 'vr2uvf',
-                'vr2uvg', 'vrdv2uvf', 'vrdv2uvg', 'wavelet', 'wavelet_default',
-                'weibull', 'wgt_area_smooth', 'wgt_areaave', 'wgt_areaave2',
-                'wgt_arearmse', 'wgt_arearmse2', 'wgt_areasum2', 'wgt_runave',
-                'wgt_runave_n', 'wgt_vert_avg_beta', 'wgt_volave', 'wgt_volave_ccm',
-                'wgt_volrmse', 'wgt_volrmse_ccm', 'where', 'wk_smooth121', 'wmbarb',
-                'wmbarbmap', 'wmdrft', 'wmgetp', 'wmlabs', 'wmsetp', 'wmstnm',
-                'wmvect', 'wmvectmap', 'wmvlbl', 'wrf_avo', 'wrf_cape_2d',
-                'wrf_cape_3d', 'wrf_dbz', 'wrf_eth', 'wrf_helicity', 'wrf_ij_to_ll',
-                'wrf_interp_1d', 'wrf_interp_2d_xy', 'wrf_interp_3d_z',
-                'wrf_latlon_to_ij', 'wrf_ll_to_ij', 'wrf_omega', 'wrf_pvo',
-                'wrf_rh', 'wrf_slp', 'wrf_smooth_2d', 'wrf_td', 'wrf_tk',
-                'wrf_updraft_helicity', 'wrf_uvmet', 'wrf_virtual_temp',
-                'wrf_wetbulb', 'wrf_wps_close_int', 'wrf_wps_open_int',
-                'wrf_wps_rddata_int', 'wrf_wps_rdhead_int', 'wrf_wps_read_int',
-                'wrf_wps_write_int', 'write_matrix', 'write_table', 'yiqrgb',
-                'z2geouv', 'zonal_mpsi', 'addfiles_GetVar', 'advect_variable',
-                'area_conserve_remap_Wrap', 'area_hi2lores_Wrap',
-                'array_append_record', 'assignFillValue', 'byte2flt',
-                'byte2flt_hdf', 'calcDayAnomTLL', 'calcMonAnomLLLT',
-                'calcMonAnomLLT', 'calcMonAnomTLL', 'calcMonAnomTLLL',
-                'calculate_monthly_values', 'cd_convert', 'changeCase',
-                'changeCaseChar', 'clmDayTLL', 'clmDayTLLL', 'clmMon2clmDay',
-                'clmMonLLLT', 'clmMonLLT', 'clmMonTLL', 'clmMonTLLL', 'closest_val',
-                'copy_VarAtts', 'copy_VarCoords', 'copy_VarCoords_1',
-                'copy_VarCoords_2', 'copy_VarMeta', 'copyatt', 'crossp3',
-                'cshstringtolist', 'cssgrid_Wrap', 'dble2flt', 'decimalPlaces',
-                'delete_VarAtts', 'dim_avg_n_Wrap', 'dim_avg_wgt_n_Wrap',
-                'dim_avg_wgt_Wrap', 'dim_avg_Wrap', 'dim_cumsum_n_Wrap',
-                'dim_cumsum_Wrap', 'dim_max_n_Wrap', 'dim_min_n_Wrap',
-                'dim_rmsd_n_Wrap', 'dim_rmsd_Wrap', 'dim_rmvmean_n_Wrap',
-                'dim_rmvmean_Wrap', 'dim_rmvmed_n_Wrap', 'dim_rmvmed_Wrap',
-                'dim_standardize_n_Wrap', 'dim_standardize_Wrap',
-                'dim_stddev_n_Wrap', 'dim_stddev_Wrap', 'dim_sum_n_Wrap',
-                'dim_sum_wgt_n_Wrap', 'dim_sum_wgt_Wrap', 'dim_sum_Wrap',
-                'dim_variance_n_Wrap', 'dim_variance_Wrap', 'dpres_plevel_Wrap',
-                'dtrend_leftdim', 'dv2uvF_Wrap', 'dv2uvG_Wrap', 'eof_north',
-                'eofcor_Wrap', 'eofcov_Wrap', 'eofunc_north', 'eofunc_ts_Wrap',
-                'eofunc_varimax_reorder', 'eofunc_varimax_Wrap', 'eofunc_Wrap',
-                'epsZero', 'f2fosh_Wrap', 'f2foshv_Wrap', 'f2fsh_Wrap',
-                'f2fshv_Wrap', 'f2gsh_Wrap', 'f2gshv_Wrap', 'fbindirSwap',
-                'fbinseqSwap1', 'fbinseqSwap2', 'flt2dble', 'flt2string',
-                'fo2fsh_Wrap', 'fo2fshv_Wrap', 'g2fsh_Wrap', 'g2fshv_Wrap',
-                'g2gsh_Wrap', 'g2gshv_Wrap', 'generate_resample_indices',
-                'generate_sample_indices', 'generate_unique_indices',
-                'genNormalDist', 'get1Dindex', 'get1Dindex_Collapse',
-                'get1Dindex_Exclude', 'get_file_suffix', 'GetFillColor',
-                'GetFillColorIndex', 'getFillValue', 'getind_latlon2d',
-                'getVarDimNames', 'getVarFillValue', 'grib_stime2itime',
-                'hyi2hyo_Wrap', 'ilapsF_Wrap', 'ilapsG_Wrap', 'ind_nearest_coord',
-                'indStrSubset', 'int2dble', 'int2flt', 'int2p_n_Wrap', 'int2p_Wrap',
-                'isMonotonic', 'isStrSubset', 'latGau', 'latGauWgt', 'latGlobeF',
-                'latGlobeFo', 'latRegWgt', 'linint1_n_Wrap', 'linint1_Wrap',
-                'linint2_points_Wrap', 'linint2_Wrap', 'local_max_1d',
-                'local_min_1d', 'lonFlip', 'lonGlobeF', 'lonGlobeFo', 'lonPivot',
-                'merge_levels_sfc', 'mod', 'month_to_annual',
-                'month_to_annual_weighted', 'month_to_season', 'month_to_season12',
-                'month_to_seasonN', 'monthly_total_to_daily_mean', 'nameDim',
-                'natgrid_Wrap', 'NewCosWeight', 'niceLatLon2D', 'NormCosWgtGlobe',
-                'numAsciiCol', 'numAsciiRow', 'numeric2int',
-                'obj_anal_ic_deprecated', 'obj_anal_ic_Wrap', 'omega_ccm_driver',
-                'omega_to_w', 'oneDtostring', 'pack_values', 'pattern_cor', 'pdfx',
-                'pdfxy', 'pdfxy_conform', 'pot_temp', 'pot_vort_hybrid',
-                'pot_vort_isobaric', 'pres2hybrid_Wrap', 'print_clock',
-                'printMinMax', 'quadroots', 'rcm2points_Wrap', 'rcm2rgrid_Wrap',
-                'readAsciiHead', 'readAsciiTable', 'reg_multlin_stats',
-                'region_ind', 'regline_stats', 'relhum_ttd', 'replaceSingleChar',
-                'RGBtoCmap', 'rgrid2rcm_Wrap', 'rho_mwjf', 'rm_single_dims',
-                'rmAnnCycle1D', 'rmInsufData', 'rmMonAnnCycLLLT', 'rmMonAnnCycLLT',
-                'rmMonAnnCycTLL', 'runave_n_Wrap', 'runave_Wrap', 'short2flt',
-                'short2flt_hdf', 'shsgc_R42_Wrap', 'sign_f90', 'sign_matlab',
-                'smth9_Wrap', 'smthClmDayTLL', 'smthClmDayTLLL', 'SqrtCosWeight',
-                'stat_dispersion', 'static_stability', 'stdMonLLLT', 'stdMonLLT',
-                'stdMonTLL', 'stdMonTLLL', 'symMinMaxPlt', 'table_attach_columns',
-                'table_attach_rows', 'time_to_newtime', 'transpose',
-                'triple2grid_Wrap', 'ut_convert', 'uv2dvF_Wrap', 'uv2dvG_Wrap',
-                'uv2vrF_Wrap', 'uv2vrG_Wrap', 'vr2uvF_Wrap', 'vr2uvG_Wrap',
-                'w_to_omega', 'wallClockElapseTime', 'wave_number_spc',
-                'wgt_areaave_Wrap', 'wgt_runave_leftdim', 'wgt_runave_n_Wrap',
-                'wgt_runave_Wrap', 'wgt_vertical_n', 'wind_component',
-                'wind_direction', 'yyyyddd_to_yyyymmdd', 'yyyymm_time',
-                'yyyymm_to_yyyyfrac', 'yyyymmdd_time', 'yyyymmdd_to_yyyyddd',
-                'yyyymmdd_to_yyyyfrac', 'yyyymmddhh_time', 'yyyymmddhh_to_yyyyfrac',
-                'zonal_mpsi_Wrap', 'zonalAve', 'calendar_decode2', 'cd_string',
-                'kf_filter', 'run_cor', 'time_axis_labels', 'ut_string',
-                'wrf_contour', 'wrf_map', 'wrf_map_overlay', 'wrf_map_overlays',
-                'wrf_map_resources', 'wrf_map_zoom', 'wrf_overlay', 'wrf_overlays',
-                'wrf_user_getvar', 'wrf_user_ij_to_ll', 'wrf_user_intrp2d',
-                'wrf_user_intrp3d', 'wrf_user_latlon_to_ij', 'wrf_user_list_times',
-                'wrf_user_ll_to_ij', 'wrf_user_unstagger', 'wrf_user_vert_interp',
-                'wrf_vector', 'gsn_add_annotation', 'gsn_add_polygon',
-                'gsn_add_polyline', 'gsn_add_polymarker',
-                'gsn_add_shapefile_polygons', 'gsn_add_shapefile_polylines',
-                'gsn_add_shapefile_polymarkers', 'gsn_add_text', 'gsn_attach_plots',
-                'gsn_blank_plot', 'gsn_contour', 'gsn_contour_map',
-                'gsn_contour_shade', 'gsn_coordinates', 'gsn_create_labelbar',
-                'gsn_create_legend', 'gsn_create_text',
-                'gsn_csm_attach_zonal_means', 'gsn_csm_blank_plot',
-                'gsn_csm_contour', 'gsn_csm_contour_map', 'gsn_csm_contour_map_ce',
-                'gsn_csm_contour_map_overlay', 'gsn_csm_contour_map_polar',
-                'gsn_csm_hov', 'gsn_csm_lat_time', 'gsn_csm_map', 'gsn_csm_map_ce',
-                'gsn_csm_map_polar', 'gsn_csm_pres_hgt',
-                'gsn_csm_pres_hgt_streamline', 'gsn_csm_pres_hgt_vector',
-                'gsn_csm_streamline', 'gsn_csm_streamline_contour_map',
-                'gsn_csm_streamline_contour_map_ce',
-                'gsn_csm_streamline_contour_map_polar', 'gsn_csm_streamline_map',
-                'gsn_csm_streamline_map_ce', 'gsn_csm_streamline_map_polar',
-                'gsn_csm_streamline_scalar', 'gsn_csm_streamline_scalar_map',
-                'gsn_csm_streamline_scalar_map_ce',
-                'gsn_csm_streamline_scalar_map_polar', 'gsn_csm_time_lat',
-                'gsn_csm_vector', 'gsn_csm_vector_map', 'gsn_csm_vector_map_ce',
-                'gsn_csm_vector_map_polar', 'gsn_csm_vector_scalar',
-                'gsn_csm_vector_scalar_map', 'gsn_csm_vector_scalar_map_ce',
-                'gsn_csm_vector_scalar_map_polar', 'gsn_csm_x2y', 'gsn_csm_x2y2',
-                'gsn_csm_xy', 'gsn_csm_xy2', 'gsn_csm_xy3', 'gsn_csm_y',
-                'gsn_define_colormap', 'gsn_draw_colormap', 'gsn_draw_named_colors',
-                'gsn_histogram', 'gsn_labelbar_ndc', 'gsn_legend_ndc', 'gsn_map',
-                'gsn_merge_colormaps', 'gsn_open_wks', 'gsn_panel', 'gsn_polygon',
-                'gsn_polygon_ndc', 'gsn_polyline', 'gsn_polyline_ndc',
-                'gsn_polymarker', 'gsn_polymarker_ndc', 'gsn_retrieve_colormap',
-                'gsn_reverse_colormap', 'gsn_streamline', 'gsn_streamline_map',
-                'gsn_streamline_scalar', 'gsn_streamline_scalar_map', 'gsn_table',
-                'gsn_text', 'gsn_text_ndc', 'gsn_vector', 'gsn_vector_map',
-                'gsn_vector_scalar', 'gsn_vector_scalar_map', 'gsn_xy', 'gsn_y',
-                'hsv2rgb', 'maximize_output', 'namedcolor2rgb', 'namedcolor2rgba',
-                'reset_device_coordinates', 'span_named_colors'), prefix=r'\b'),
-             Name.Builtin),
-
-            # Resources
-            (words((
-                'amDataXF', 'amDataYF', 'amJust', 'amOn', 'amOrthogonalPosF',
-                'amParallelPosF', 'amResizeNotify', 'amSide', 'amTrackData',
-                'amViewId', 'amZone', 'appDefaultParent', 'appFileSuffix',
-                'appResources', 'appSysDir', 'appUsrDir', 'caCopyArrays',
-                'caXArray', 'caXCast', 'caXMaxV', 'caXMinV', 'caXMissingV',
-                'caYArray', 'caYCast', 'caYMaxV', 'caYMinV', 'caYMissingV',
-                'cnCellFillEdgeColor', 'cnCellFillMissingValEdgeColor',
-                'cnConpackParams', 'cnConstFEnableFill', 'cnConstFLabelAngleF',
-                'cnConstFLabelBackgroundColor', 'cnConstFLabelConstantSpacingF',
-                'cnConstFLabelFont', 'cnConstFLabelFontAspectF',
-                'cnConstFLabelFontColor', 'cnConstFLabelFontHeightF',
-                'cnConstFLabelFontQuality', 'cnConstFLabelFontThicknessF',
-                'cnConstFLabelFormat', 'cnConstFLabelFuncCode', 'cnConstFLabelJust',
-                'cnConstFLabelOn', 'cnConstFLabelOrthogonalPosF',
-                'cnConstFLabelParallelPosF', 'cnConstFLabelPerimColor',
-                'cnConstFLabelPerimOn', 'cnConstFLabelPerimSpaceF',
-                'cnConstFLabelPerimThicknessF', 'cnConstFLabelSide',
-                'cnConstFLabelString', 'cnConstFLabelTextDirection',
-                'cnConstFLabelZone', 'cnConstFUseInfoLabelRes',
-                'cnExplicitLabelBarLabelsOn', 'cnExplicitLegendLabelsOn',
-                'cnExplicitLineLabelsOn', 'cnFillBackgroundColor', 'cnFillColor',
-                'cnFillColors', 'cnFillDotSizeF', 'cnFillDrawOrder', 'cnFillMode',
-                'cnFillOn', 'cnFillOpacityF', 'cnFillPalette', 'cnFillPattern',
-                'cnFillPatterns', 'cnFillScaleF', 'cnFillScales', 'cnFixFillBleed',
-                'cnGridBoundFillColor', 'cnGridBoundFillPattern',
-                'cnGridBoundFillScaleF', 'cnGridBoundPerimColor',
-                'cnGridBoundPerimDashPattern', 'cnGridBoundPerimOn',
-                'cnGridBoundPerimThicknessF', 'cnHighLabelAngleF',
-                'cnHighLabelBackgroundColor', 'cnHighLabelConstantSpacingF',
-                'cnHighLabelCount', 'cnHighLabelFont', 'cnHighLabelFontAspectF',
-                'cnHighLabelFontColor', 'cnHighLabelFontHeightF',
-                'cnHighLabelFontQuality', 'cnHighLabelFontThicknessF',
-                'cnHighLabelFormat', 'cnHighLabelFuncCode', 'cnHighLabelPerimColor',
-                'cnHighLabelPerimOn', 'cnHighLabelPerimSpaceF',
-                'cnHighLabelPerimThicknessF', 'cnHighLabelString', 'cnHighLabelsOn',
-                'cnHighLowLabelOverlapMode', 'cnHighUseLineLabelRes',
-                'cnInfoLabelAngleF', 'cnInfoLabelBackgroundColor',
-                'cnInfoLabelConstantSpacingF', 'cnInfoLabelFont',
-                'cnInfoLabelFontAspectF', 'cnInfoLabelFontColor',
-                'cnInfoLabelFontHeightF', 'cnInfoLabelFontQuality',
-                'cnInfoLabelFontThicknessF', 'cnInfoLabelFormat',
-                'cnInfoLabelFuncCode', 'cnInfoLabelJust', 'cnInfoLabelOn',
-                'cnInfoLabelOrthogonalPosF', 'cnInfoLabelParallelPosF',
-                'cnInfoLabelPerimColor', 'cnInfoLabelPerimOn',
-                'cnInfoLabelPerimSpaceF', 'cnInfoLabelPerimThicknessF',
-                'cnInfoLabelSide', 'cnInfoLabelString', 'cnInfoLabelTextDirection',
-                'cnInfoLabelZone', 'cnLabelBarEndLabelsOn', 'cnLabelBarEndStyle',
-                'cnLabelDrawOrder', 'cnLabelMasking', 'cnLabelScaleFactorF',
-                'cnLabelScaleValueF', 'cnLabelScalingMode', 'cnLegendLevelFlags',
-                'cnLevelCount', 'cnLevelFlag', 'cnLevelFlags', 'cnLevelSelectionMode',
-                'cnLevelSpacingF', 'cnLevels', 'cnLineColor', 'cnLineColors',
-                'cnLineDashPattern', 'cnLineDashPatterns', 'cnLineDashSegLenF',
-                'cnLineDrawOrder', 'cnLineLabelAngleF', 'cnLineLabelBackgroundColor',
-                'cnLineLabelConstantSpacingF', 'cnLineLabelCount',
-                'cnLineLabelDensityF', 'cnLineLabelFont', 'cnLineLabelFontAspectF',
-                'cnLineLabelFontColor', 'cnLineLabelFontColors',
-                'cnLineLabelFontHeightF', 'cnLineLabelFontQuality',
-                'cnLineLabelFontThicknessF', 'cnLineLabelFormat',
-                'cnLineLabelFuncCode', 'cnLineLabelInterval', 'cnLineLabelPerimColor',
-                'cnLineLabelPerimOn', 'cnLineLabelPerimSpaceF',
-                'cnLineLabelPerimThicknessF', 'cnLineLabelPlacementMode',
-                'cnLineLabelStrings', 'cnLineLabelsOn', 'cnLinePalette',
-                'cnLineThicknessF', 'cnLineThicknesses', 'cnLinesOn',
-                'cnLowLabelAngleF', 'cnLowLabelBackgroundColor',
-                'cnLowLabelConstantSpacingF', 'cnLowLabelCount', 'cnLowLabelFont',
-                'cnLowLabelFontAspectF', 'cnLowLabelFontColor',
-                'cnLowLabelFontHeightF', 'cnLowLabelFontQuality',
-                'cnLowLabelFontThicknessF', 'cnLowLabelFormat', 'cnLowLabelFuncCode',
-                'cnLowLabelPerimColor', 'cnLowLabelPerimOn', 'cnLowLabelPerimSpaceF',
-                'cnLowLabelPerimThicknessF', 'cnLowLabelString', 'cnLowLabelsOn',
-                'cnLowUseHighLabelRes', 'cnMaxDataValueFormat', 'cnMaxLevelCount',
-                'cnMaxLevelValF', 'cnMaxPointDistanceF', 'cnMinLevelValF',
-                'cnMissingValFillColor', 'cnMissingValFillPattern',
-                'cnMissingValFillScaleF', 'cnMissingValPerimColor',
-                'cnMissingValPerimDashPattern', 'cnMissingValPerimGridBoundOn',
-                'cnMissingValPerimOn', 'cnMissingValPerimThicknessF',
-                'cnMonoFillColor', 'cnMonoFillPattern', 'cnMonoFillScale',
-                'cnMonoLevelFlag', 'cnMonoLineColor', 'cnMonoLineDashPattern',
-                'cnMonoLineLabelFontColor', 'cnMonoLineThickness', 'cnNoDataLabelOn',
-                'cnNoDataLabelString', 'cnOutOfRangeFillColor',
-                'cnOutOfRangeFillPattern', 'cnOutOfRangeFillScaleF',
-                'cnOutOfRangePerimColor', 'cnOutOfRangePerimDashPattern',
-                'cnOutOfRangePerimOn', 'cnOutOfRangePerimThicknessF',
-                'cnRasterCellSizeF', 'cnRasterMinCellSizeF', 'cnRasterModeOn',
-                'cnRasterSampleFactorF', 'cnRasterSmoothingOn', 'cnScalarFieldData',
-                'cnSmoothingDistanceF', 'cnSmoothingOn', 'cnSmoothingTensionF',
-                'cnSpanFillPalette', 'cnSpanLinePalette', 'ctCopyTables',
-                'ctXElementSize', 'ctXMaxV', 'ctXMinV', 'ctXMissingV', 'ctXTable',
-                'ctXTableLengths', 'ctXTableType', 'ctYElementSize', 'ctYMaxV',
-                'ctYMinV', 'ctYMissingV', 'ctYTable', 'ctYTableLengths',
-                'ctYTableType', 'dcDelayCompute', 'errBuffer',
-                'errFileName', 'errFilePtr', 'errLevel', 'errPrint', 'errUnitNumber',
-                'gsClipOn', 'gsColors', 'gsEdgeColor', 'gsEdgeDashPattern',
-                'gsEdgeDashSegLenF', 'gsEdgeThicknessF', 'gsEdgesOn',
-                'gsFillBackgroundColor', 'gsFillColor', 'gsFillDotSizeF',
-                'gsFillIndex', 'gsFillLineThicknessF', 'gsFillOpacityF',
-                'gsFillScaleF', 'gsFont', 'gsFontAspectF', 'gsFontColor',
-                'gsFontHeightF', 'gsFontOpacityF', 'gsFontQuality',
-                'gsFontThicknessF', 'gsLineColor', 'gsLineDashPattern',
-                'gsLineDashSegLenF', 'gsLineLabelConstantSpacingF', 'gsLineLabelFont',
-                'gsLineLabelFontAspectF', 'gsLineLabelFontColor',
-                'gsLineLabelFontHeightF', 'gsLineLabelFontQuality',
-                'gsLineLabelFontThicknessF', 'gsLineLabelFuncCode',
-                'gsLineLabelString', 'gsLineOpacityF', 'gsLineThicknessF',
-                'gsMarkerColor', 'gsMarkerIndex', 'gsMarkerOpacityF', 'gsMarkerSizeF',
-                'gsMarkerThicknessF', 'gsSegments', 'gsTextAngleF',
-                'gsTextConstantSpacingF', 'gsTextDirection', 'gsTextFuncCode',
-                'gsTextJustification', 'gsnAboveYRefLineBarColors',
-                'gsnAboveYRefLineBarFillScales', 'gsnAboveYRefLineBarPatterns',
-                'gsnAboveYRefLineColor', 'gsnAddCyclic', 'gsnAttachBorderOn',
-                'gsnAttachPlotsXAxis', 'gsnBelowYRefLineBarColors',
-                'gsnBelowYRefLineBarFillScales', 'gsnBelowYRefLineBarPatterns',
-                'gsnBelowYRefLineColor', 'gsnBoxMargin', 'gsnCenterString',
-                'gsnCenterStringFontColor', 'gsnCenterStringFontHeightF',
-                'gsnCenterStringFuncCode', 'gsnCenterStringOrthogonalPosF',
-                'gsnCenterStringParallelPosF', 'gsnContourLineThicknessesScale',
-                'gsnContourNegLineDashPattern', 'gsnContourPosLineDashPattern',
-                'gsnContourZeroLineThicknessF', 'gsnDebugWriteFileName', 'gsnDraw',
-                'gsnFrame', 'gsnHistogramBarWidthPercent', 'gsnHistogramBinIntervals',
-                'gsnHistogramBinMissing', 'gsnHistogramBinWidth',
-                'gsnHistogramClassIntervals', 'gsnHistogramCompare',
-                'gsnHistogramComputePercentages',
-                'gsnHistogramComputePercentagesNoMissing',
-                'gsnHistogramDiscreteBinValues', 'gsnHistogramDiscreteClassValues',
-                'gsnHistogramHorizontal', 'gsnHistogramMinMaxBinsOn',
-                'gsnHistogramNumberOfBins', 'gsnHistogramPercentSign',
-                'gsnHistogramSelectNiceIntervals', 'gsnLeftString',
-                'gsnLeftStringFontColor', 'gsnLeftStringFontHeightF',
-                'gsnLeftStringFuncCode', 'gsnLeftStringOrthogonalPosF',
-                'gsnLeftStringParallelPosF', 'gsnMajorLatSpacing',
-                'gsnMajorLonSpacing', 'gsnMaskLambertConformal',
-                'gsnMaskLambertConformalOutlineOn', 'gsnMaximize',
-                'gsnMinorLatSpacing', 'gsnMinorLonSpacing', 'gsnPanelBottom',
-                'gsnPanelCenter', 'gsnPanelDebug', 'gsnPanelFigureStrings',
-                'gsnPanelFigureStringsBackgroundFillColor',
-                'gsnPanelFigureStringsFontHeightF', 'gsnPanelFigureStringsJust',
-                'gsnPanelFigureStringsPerimOn', 'gsnPanelLabelBar', 'gsnPanelLeft',
-                'gsnPanelMainFont', 'gsnPanelMainFontColor',
-                'gsnPanelMainFontHeightF', 'gsnPanelMainString', 'gsnPanelRight',
-                'gsnPanelRowSpec', 'gsnPanelScalePlotIndex', 'gsnPanelTop',
-                'gsnPanelXF', 'gsnPanelXWhiteSpacePercent', 'gsnPanelYF',
-                'gsnPanelYWhiteSpacePercent', 'gsnPaperHeight', 'gsnPaperMargin',
-                'gsnPaperOrientation', 'gsnPaperWidth', 'gsnPolar',
-                'gsnPolarLabelDistance', 'gsnPolarLabelFont',
-                'gsnPolarLabelFontHeightF', 'gsnPolarLabelSpacing', 'gsnPolarTime',
-                'gsnPolarUT', 'gsnRightString', 'gsnRightStringFontColor',
-                'gsnRightStringFontHeightF', 'gsnRightStringFuncCode',
-                'gsnRightStringOrthogonalPosF', 'gsnRightStringParallelPosF',
-                'gsnScalarContour', 'gsnScale', 'gsnShape', 'gsnSpreadColorEnd',
-                'gsnSpreadColorStart', 'gsnSpreadColors', 'gsnStringFont',
-                'gsnStringFontColor', 'gsnStringFontHeightF', 'gsnStringFuncCode',
-                'gsnTickMarksOn', 'gsnXAxisIrregular2Linear', 'gsnXAxisIrregular2Log',
-                'gsnXRefLine', 'gsnXRefLineColor', 'gsnXRefLineDashPattern',
-                'gsnXRefLineThicknessF', 'gsnXYAboveFillColors', 'gsnXYBarChart',
-                'gsnXYBarChartBarWidth', 'gsnXYBarChartColors',
-                'gsnXYBarChartColors2', 'gsnXYBarChartFillDotSizeF',
-                'gsnXYBarChartFillLineThicknessF', 'gsnXYBarChartFillOpacityF',
-                'gsnXYBarChartFillScaleF', 'gsnXYBarChartOutlineOnly',
-                'gsnXYBarChartOutlineThicknessF', 'gsnXYBarChartPatterns',
-                'gsnXYBarChartPatterns2', 'gsnXYBelowFillColors', 'gsnXYFillColors',
-                'gsnXYFillOpacities', 'gsnXYLeftFillColors', 'gsnXYRightFillColors',
-                'gsnYAxisIrregular2Linear', 'gsnYAxisIrregular2Log', 'gsnYRefLine',
-                'gsnYRefLineColor', 'gsnYRefLineColors', 'gsnYRefLineDashPattern',
-                'gsnYRefLineDashPatterns', 'gsnYRefLineThicknessF',
-                'gsnYRefLineThicknesses', 'gsnZonalMean', 'gsnZonalMeanXMaxF',
-                'gsnZonalMeanXMinF', 'gsnZonalMeanYRefLine', 'lbAutoManage',
-                'lbBottomMarginF', 'lbBoxCount', 'lbBoxEndCapStyle', 'lbBoxFractions',
-                'lbBoxLineColor', 'lbBoxLineDashPattern', 'lbBoxLineDashSegLenF',
-                'lbBoxLineThicknessF', 'lbBoxLinesOn', 'lbBoxMajorExtentF',
-                'lbBoxMinorExtentF', 'lbBoxSeparatorLinesOn', 'lbBoxSizing',
-                'lbFillBackground', 'lbFillColor', 'lbFillColors', 'lbFillDotSizeF',
-                'lbFillLineThicknessF', 'lbFillPattern', 'lbFillPatterns',
-                'lbFillScaleF', 'lbFillScales', 'lbJustification', 'lbLabelAlignment',
-                'lbLabelAngleF', 'lbLabelAutoStride', 'lbLabelBarOn',
-                'lbLabelConstantSpacingF', 'lbLabelDirection', 'lbLabelFont',
-                'lbLabelFontAspectF', 'lbLabelFontColor', 'lbLabelFontHeightF',
-                'lbLabelFontQuality', 'lbLabelFontThicknessF', 'lbLabelFuncCode',
-                'lbLabelJust', 'lbLabelOffsetF', 'lbLabelPosition', 'lbLabelStride',
-                'lbLabelStrings', 'lbLabelsOn', 'lbLeftMarginF', 'lbMaxLabelLenF',
-                'lbMinLabelSpacingF', 'lbMonoFillColor', 'lbMonoFillPattern',
-                'lbMonoFillScale', 'lbOrientation', 'lbPerimColor',
-                'lbPerimDashPattern', 'lbPerimDashSegLenF', 'lbPerimFill',
-                'lbPerimFillColor', 'lbPerimOn', 'lbPerimThicknessF',
-                'lbRasterFillOn', 'lbRightMarginF', 'lbTitleAngleF',
-                'lbTitleConstantSpacingF', 'lbTitleDirection', 'lbTitleExtentF',
-                'lbTitleFont', 'lbTitleFontAspectF', 'lbTitleFontColor',
-                'lbTitleFontHeightF', 'lbTitleFontQuality', 'lbTitleFontThicknessF',
-                'lbTitleFuncCode', 'lbTitleJust', 'lbTitleOffsetF', 'lbTitleOn',
-                'lbTitlePosition', 'lbTitleString', 'lbTopMarginF', 'lgAutoManage',
-                'lgBottomMarginF', 'lgBoxBackground', 'lgBoxLineColor',
-                'lgBoxLineDashPattern', 'lgBoxLineDashSegLenF', 'lgBoxLineThicknessF',
-                'lgBoxLinesOn', 'lgBoxMajorExtentF', 'lgBoxMinorExtentF',
-                'lgDashIndex', 'lgDashIndexes', 'lgItemCount', 'lgItemOrder',
-                'lgItemPlacement', 'lgItemPositions', 'lgItemType', 'lgItemTypes',
-                'lgJustification', 'lgLabelAlignment', 'lgLabelAngleF',
-                'lgLabelAutoStride', 'lgLabelConstantSpacingF', 'lgLabelDirection',
-                'lgLabelFont', 'lgLabelFontAspectF', 'lgLabelFontColor',
-                'lgLabelFontHeightF', 'lgLabelFontQuality', 'lgLabelFontThicknessF',
-                'lgLabelFuncCode', 'lgLabelJust', 'lgLabelOffsetF', 'lgLabelPosition',
-                'lgLabelStride', 'lgLabelStrings', 'lgLabelsOn', 'lgLeftMarginF',
-                'lgLegendOn', 'lgLineColor', 'lgLineColors', 'lgLineDashSegLenF',
-                'lgLineDashSegLens', 'lgLineLabelConstantSpacingF', 'lgLineLabelFont',
-                'lgLineLabelFontAspectF', 'lgLineLabelFontColor',
-                'lgLineLabelFontColors', 'lgLineLabelFontHeightF',
-                'lgLineLabelFontHeights', 'lgLineLabelFontQuality',
-                'lgLineLabelFontThicknessF', 'lgLineLabelFuncCode',
-                'lgLineLabelStrings', 'lgLineLabelsOn', 'lgLineThicknessF',
-                'lgLineThicknesses', 'lgMarkerColor', 'lgMarkerColors',
-                'lgMarkerIndex', 'lgMarkerIndexes', 'lgMarkerSizeF', 'lgMarkerSizes',
-                'lgMarkerThicknessF', 'lgMarkerThicknesses', 'lgMonoDashIndex',
-                'lgMonoItemType', 'lgMonoLineColor', 'lgMonoLineDashSegLen',
-                'lgMonoLineLabelFontColor', 'lgMonoLineLabelFontHeight',
-                'lgMonoLineThickness', 'lgMonoMarkerColor', 'lgMonoMarkerIndex',
-                'lgMonoMarkerSize', 'lgMonoMarkerThickness', 'lgOrientation',
-                'lgPerimColor', 'lgPerimDashPattern', 'lgPerimDashSegLenF',
-                'lgPerimFill', 'lgPerimFillColor', 'lgPerimOn', 'lgPerimThicknessF',
-                'lgRightMarginF', 'lgTitleAngleF', 'lgTitleConstantSpacingF',
-                'lgTitleDirection', 'lgTitleExtentF', 'lgTitleFont',
-                'lgTitleFontAspectF', 'lgTitleFontColor', 'lgTitleFontHeightF',
-                'lgTitleFontQuality', 'lgTitleFontThicknessF', 'lgTitleFuncCode',
-                'lgTitleJust', 'lgTitleOffsetF', 'lgTitleOn', 'lgTitlePosition',
-                'lgTitleString', 'lgTopMarginF', 'mpAreaGroupCount',
-                'mpAreaMaskingOn', 'mpAreaNames', 'mpAreaTypes', 'mpBottomAngleF',
-                'mpBottomMapPosF', 'mpBottomNDCF', 'mpBottomNPCF',
-                'mpBottomPointLatF', 'mpBottomPointLonF', 'mpBottomWindowF',
-                'mpCenterLatF', 'mpCenterLonF', 'mpCenterRotF', 'mpCountyLineColor',
-                'mpCountyLineDashPattern', 'mpCountyLineDashSegLenF',
-                'mpCountyLineThicknessF', 'mpDataBaseVersion', 'mpDataResolution',
-                'mpDataSetName', 'mpDefaultFillColor', 'mpDefaultFillPattern',
-                'mpDefaultFillScaleF', 'mpDynamicAreaGroups', 'mpEllipticalBoundary',
-                'mpFillAreaSpecifiers', 'mpFillBoundarySets', 'mpFillColor',
-                'mpFillColors', 'mpFillColors-default', 'mpFillDotSizeF',
-                'mpFillDrawOrder', 'mpFillOn', 'mpFillPatternBackground',
-                'mpFillPattern', 'mpFillPatterns', 'mpFillPatterns-default',
-                'mpFillScaleF', 'mpFillScales', 'mpFillScales-default',
-                'mpFixedAreaGroups', 'mpGeophysicalLineColor',
-                'mpGeophysicalLineDashPattern', 'mpGeophysicalLineDashSegLenF',
-                'mpGeophysicalLineThicknessF', 'mpGreatCircleLinesOn',
-                'mpGridAndLimbDrawOrder', 'mpGridAndLimbOn', 'mpGridLatSpacingF',
-                'mpGridLineColor', 'mpGridLineDashPattern', 'mpGridLineDashSegLenF',
-                'mpGridLineThicknessF', 'mpGridLonSpacingF', 'mpGridMaskMode',
-                'mpGridMaxLatF', 'mpGridPolarLonSpacingF', 'mpGridSpacingF',
-                'mpInlandWaterFillColor', 'mpInlandWaterFillPattern',
-                'mpInlandWaterFillScaleF', 'mpLabelDrawOrder', 'mpLabelFontColor',
-                'mpLabelFontHeightF', 'mpLabelsOn', 'mpLambertMeridianF',
-                'mpLambertParallel1F', 'mpLambertParallel2F', 'mpLandFillColor',
-                'mpLandFillPattern', 'mpLandFillScaleF', 'mpLeftAngleF',
-                'mpLeftCornerLatF', 'mpLeftCornerLonF', 'mpLeftMapPosF',
-                'mpLeftNDCF', 'mpLeftNPCF', 'mpLeftPointLatF',
-                'mpLeftPointLonF', 'mpLeftWindowF', 'mpLimbLineColor',
-                'mpLimbLineDashPattern', 'mpLimbLineDashSegLenF',
-                'mpLimbLineThicknessF', 'mpLimitMode', 'mpMaskAreaSpecifiers',
-                'mpMaskOutlineSpecifiers', 'mpMaxLatF', 'mpMaxLonF',
-                'mpMinLatF', 'mpMinLonF', 'mpMonoFillColor', 'mpMonoFillPattern',
-                'mpMonoFillScale', 'mpNationalLineColor', 'mpNationalLineDashPattern',
-                'mpNationalLineThicknessF', 'mpOceanFillColor', 'mpOceanFillPattern',
-                'mpOceanFillScaleF', 'mpOutlineBoundarySets', 'mpOutlineDrawOrder',
-                'mpOutlineMaskingOn', 'mpOutlineOn', 'mpOutlineSpecifiers',
-                'mpPerimDrawOrder', 'mpPerimLineColor', 'mpPerimLineDashPattern',
-                'mpPerimLineDashSegLenF', 'mpPerimLineThicknessF', 'mpPerimOn',
-                'mpPolyMode', 'mpProjection', 'mpProvincialLineColor',
-                'mpProvincialLineDashPattern', 'mpProvincialLineDashSegLenF',
-                'mpProvincialLineThicknessF', 'mpRelativeCenterLat',
-                'mpRelativeCenterLon', 'mpRightAngleF', 'mpRightCornerLatF',
-                'mpRightCornerLonF', 'mpRightMapPosF', 'mpRightNDCF',
-                'mpRightNPCF', 'mpRightPointLatF', 'mpRightPointLonF',
-                'mpRightWindowF', 'mpSatelliteAngle1F', 'mpSatelliteAngle2F',
-                'mpSatelliteDistF', 'mpShapeMode', 'mpSpecifiedFillColors',
-                'mpSpecifiedFillDirectIndexing', 'mpSpecifiedFillPatterns',
-                'mpSpecifiedFillPriority', 'mpSpecifiedFillScales',
-                'mpTopAngleF', 'mpTopMapPosF', 'mpTopNDCF', 'mpTopNPCF',
-                'mpTopPointLatF', 'mpTopPointLonF', 'mpTopWindowF',
-                'mpUSStateLineColor', 'mpUSStateLineDashPattern',
-                'mpUSStateLineDashSegLenF', 'mpUSStateLineThicknessF',
-                'pmAnnoManagers', 'pmAnnoViews', 'pmLabelBarDisplayMode',
-                'pmLabelBarHeightF', 'pmLabelBarKeepAspect', 'pmLabelBarOrthogonalPosF',
-                'pmLabelBarParallelPosF', 'pmLabelBarSide', 'pmLabelBarWidthF',
-                'pmLabelBarZone', 'pmLegendDisplayMode', 'pmLegendHeightF',
-                'pmLegendKeepAspect', 'pmLegendOrthogonalPosF',
-                'pmLegendParallelPosF', 'pmLegendSide', 'pmLegendWidthF',
-                'pmLegendZone', 'pmOverlaySequenceIds', 'pmTickMarkDisplayMode',
-                'pmTickMarkZone', 'pmTitleDisplayMode', 'pmTitleZone',
-                'prGraphicStyle', 'prPolyType', 'prXArray', 'prYArray',
-                'sfCopyData', 'sfDataArray', 'sfDataMaxV', 'sfDataMinV',
-                'sfElementNodes', 'sfExchangeDimensions', 'sfFirstNodeIndex',
-                'sfMissingValueV', 'sfXArray', 'sfXCActualEndF', 'sfXCActualStartF',
-                'sfXCEndIndex', 'sfXCEndSubsetV', 'sfXCEndV', 'sfXCStartIndex',
-                'sfXCStartSubsetV', 'sfXCStartV', 'sfXCStride', 'sfXCellBounds',
-                'sfYArray', 'sfYCActualEndF', 'sfYCActualStartF', 'sfYCEndIndex',
-                'sfYCEndSubsetV', 'sfYCEndV', 'sfYCStartIndex', 'sfYCStartSubsetV',
-                'sfYCStartV', 'sfYCStride', 'sfYCellBounds', 'stArrowLengthF',
-                'stArrowStride', 'stCrossoverCheckCount',
-                'stExplicitLabelBarLabelsOn', 'stLabelBarEndLabelsOn',
-                'stLabelFormat', 'stLengthCheckCount', 'stLevelColors',
-                'stLevelCount', 'stLevelPalette', 'stLevelSelectionMode',
-                'stLevelSpacingF', 'stLevels', 'stLineColor', 'stLineOpacityF',
-                'stLineStartStride', 'stLineThicknessF', 'stMapDirection',
-                'stMaxLevelCount', 'stMaxLevelValF', 'stMinArrowSpacingF',
-                'stMinDistanceF', 'stMinLevelValF', 'stMinLineSpacingF',
-                'stMinStepFactorF', 'stMonoLineColor', 'stNoDataLabelOn',
-                'stNoDataLabelString', 'stScalarFieldData', 'stScalarMissingValColor',
-                'stSpanLevelPalette', 'stStepSizeF', 'stStreamlineDrawOrder',
-                'stUseScalarArray', 'stVectorFieldData', 'stZeroFLabelAngleF',
-                'stZeroFLabelBackgroundColor', 'stZeroFLabelConstantSpacingF',
-                'stZeroFLabelFont', 'stZeroFLabelFontAspectF',
-                'stZeroFLabelFontColor', 'stZeroFLabelFontHeightF',
-                'stZeroFLabelFontQuality', 'stZeroFLabelFontThicknessF',
-                'stZeroFLabelFuncCode', 'stZeroFLabelJust', 'stZeroFLabelOn',
-                'stZeroFLabelOrthogonalPosF', 'stZeroFLabelParallelPosF',
-                'stZeroFLabelPerimColor', 'stZeroFLabelPerimOn',
-                'stZeroFLabelPerimSpaceF', 'stZeroFLabelPerimThicknessF',
-                'stZeroFLabelSide', 'stZeroFLabelString', 'stZeroFLabelTextDirection',
-                'stZeroFLabelZone', 'tfDoNDCOverlay', 'tfPlotManagerOn',
-                'tfPolyDrawList', 'tfPolyDrawOrder', 'tiDeltaF', 'tiMainAngleF',
-                'tiMainConstantSpacingF', 'tiMainDirection', 'tiMainFont',
-                'tiMainFontAspectF', 'tiMainFontColor', 'tiMainFontHeightF',
-                'tiMainFontQuality', 'tiMainFontThicknessF', 'tiMainFuncCode',
-                'tiMainJust', 'tiMainOffsetXF', 'tiMainOffsetYF', 'tiMainOn',
-                'tiMainPosition', 'tiMainSide', 'tiMainString', 'tiUseMainAttributes',
-                'tiXAxisAngleF', 'tiXAxisConstantSpacingF', 'tiXAxisDirection',
-                'tiXAxisFont', 'tiXAxisFontAspectF', 'tiXAxisFontColor',
-                'tiXAxisFontHeightF', 'tiXAxisFontQuality', 'tiXAxisFontThicknessF',
-                'tiXAxisFuncCode', 'tiXAxisJust', 'tiXAxisOffsetXF',
-                'tiXAxisOffsetYF', 'tiXAxisOn', 'tiXAxisPosition', 'tiXAxisSide',
-                'tiXAxisString', 'tiYAxisAngleF', 'tiYAxisConstantSpacingF',
-                'tiYAxisDirection', 'tiYAxisFont', 'tiYAxisFontAspectF',
-                'tiYAxisFontColor', 'tiYAxisFontHeightF', 'tiYAxisFontQuality',
-                'tiYAxisFontThicknessF', 'tiYAxisFuncCode', 'tiYAxisJust',
-                'tiYAxisOffsetXF', 'tiYAxisOffsetYF', 'tiYAxisOn', 'tiYAxisPosition',
-                'tiYAxisSide', 'tiYAxisString', 'tmBorderLineColor',
-                'tmBorderThicknessF', 'tmEqualizeXYSizes', 'tmLabelAutoStride',
-                'tmSciNoteCutoff', 'tmXBAutoPrecision', 'tmXBBorderOn',
-                'tmXBDataLeftF', 'tmXBDataRightF', 'tmXBFormat', 'tmXBIrrTensionF',
-                'tmXBIrregularPoints', 'tmXBLabelAngleF', 'tmXBLabelConstantSpacingF',
-                'tmXBLabelDeltaF', 'tmXBLabelDirection', 'tmXBLabelFont',
-                'tmXBLabelFontAspectF', 'tmXBLabelFontColor', 'tmXBLabelFontHeightF',
-                'tmXBLabelFontQuality', 'tmXBLabelFontThicknessF',
-                'tmXBLabelFuncCode', 'tmXBLabelJust', 'tmXBLabelStride', 'tmXBLabels',
-                'tmXBLabelsOn', 'tmXBMajorLengthF', 'tmXBMajorLineColor',
-                'tmXBMajorOutwardLengthF', 'tmXBMajorThicknessF', 'tmXBMaxLabelLenF',
-                'tmXBMaxTicks', 'tmXBMinLabelSpacingF', 'tmXBMinorLengthF',
-                'tmXBMinorLineColor', 'tmXBMinorOn', 'tmXBMinorOutwardLengthF',
-                'tmXBMinorPerMajor', 'tmXBMinorThicknessF', 'tmXBMinorValues',
-                'tmXBMode', 'tmXBOn', 'tmXBPrecision', 'tmXBStyle', 'tmXBTickEndF',
-                'tmXBTickSpacingF', 'tmXBTickStartF', 'tmXBValues', 'tmXMajorGrid',
-                'tmXMajorGridLineColor', 'tmXMajorGridLineDashPattern',
-                'tmXMajorGridThicknessF', 'tmXMinorGrid', 'tmXMinorGridLineColor',
-                'tmXMinorGridLineDashPattern', 'tmXMinorGridThicknessF',
-                'tmXTAutoPrecision', 'tmXTBorderOn', 'tmXTDataLeftF',
-                'tmXTDataRightF', 'tmXTFormat', 'tmXTIrrTensionF',
-                'tmXTIrregularPoints', 'tmXTLabelAngleF', 'tmXTLabelConstantSpacingF',
-                'tmXTLabelDeltaF', 'tmXTLabelDirection', 'tmXTLabelFont',
-                'tmXTLabelFontAspectF', 'tmXTLabelFontColor', 'tmXTLabelFontHeightF',
-                'tmXTLabelFontQuality', 'tmXTLabelFontThicknessF',
-                'tmXTLabelFuncCode', 'tmXTLabelJust', 'tmXTLabelStride', 'tmXTLabels',
-                'tmXTLabelsOn', 'tmXTMajorLengthF', 'tmXTMajorLineColor',
-                'tmXTMajorOutwardLengthF', 'tmXTMajorThicknessF', 'tmXTMaxLabelLenF',
-                'tmXTMaxTicks', 'tmXTMinLabelSpacingF', 'tmXTMinorLengthF',
-                'tmXTMinorLineColor', 'tmXTMinorOn', 'tmXTMinorOutwardLengthF',
-                'tmXTMinorPerMajor', 'tmXTMinorThicknessF', 'tmXTMinorValues',
-                'tmXTMode', 'tmXTOn', 'tmXTPrecision', 'tmXTStyle', 'tmXTTickEndF',
-                'tmXTTickSpacingF', 'tmXTTickStartF', 'tmXTValues', 'tmXUseBottom',
-                'tmYLAutoPrecision', 'tmYLBorderOn', 'tmYLDataBottomF',
-                'tmYLDataTopF', 'tmYLFormat', 'tmYLIrrTensionF',
-                'tmYLIrregularPoints', 'tmYLLabelAngleF', 'tmYLLabelConstantSpacingF',
-                'tmYLLabelDeltaF', 'tmYLLabelDirection', 'tmYLLabelFont',
-                'tmYLLabelFontAspectF', 'tmYLLabelFontColor', 'tmYLLabelFontHeightF',
-                'tmYLLabelFontQuality', 'tmYLLabelFontThicknessF',
-                'tmYLLabelFuncCode', 'tmYLLabelJust', 'tmYLLabelStride', 'tmYLLabels',
-                'tmYLLabelsOn', 'tmYLMajorLengthF', 'tmYLMajorLineColor',
-                'tmYLMajorOutwardLengthF', 'tmYLMajorThicknessF', 'tmYLMaxLabelLenF',
-                'tmYLMaxTicks', 'tmYLMinLabelSpacingF', 'tmYLMinorLengthF',
-                'tmYLMinorLineColor', 'tmYLMinorOn', 'tmYLMinorOutwardLengthF',
-                'tmYLMinorPerMajor', 'tmYLMinorThicknessF', 'tmYLMinorValues',
-                'tmYLMode', 'tmYLOn', 'tmYLPrecision', 'tmYLStyle', 'tmYLTickEndF',
-                'tmYLTickSpacingF', 'tmYLTickStartF', 'tmYLValues', 'tmYMajorGrid',
-                'tmYMajorGridLineColor', 'tmYMajorGridLineDashPattern',
-                'tmYMajorGridThicknessF', 'tmYMinorGrid', 'tmYMinorGridLineColor',
-                'tmYMinorGridLineDashPattern', 'tmYMinorGridThicknessF',
-                'tmYRAutoPrecision', 'tmYRBorderOn', 'tmYRDataBottomF',
-                'tmYRDataTopF', 'tmYRFormat', 'tmYRIrrTensionF',
-                'tmYRIrregularPoints', 'tmYRLabelAngleF', 'tmYRLabelConstantSpacingF',
-                'tmYRLabelDeltaF', 'tmYRLabelDirection', 'tmYRLabelFont',
-                'tmYRLabelFontAspectF', 'tmYRLabelFontColor', 'tmYRLabelFontHeightF',
-                'tmYRLabelFontQuality', 'tmYRLabelFontThicknessF',
-                'tmYRLabelFuncCode', 'tmYRLabelJust', 'tmYRLabelStride', 'tmYRLabels',
-                'tmYRLabelsOn', 'tmYRMajorLengthF', 'tmYRMajorLineColor',
-                'tmYRMajorOutwardLengthF', 'tmYRMajorThicknessF', 'tmYRMaxLabelLenF',
-                'tmYRMaxTicks', 'tmYRMinLabelSpacingF', 'tmYRMinorLengthF',
-                'tmYRMinorLineColor', 'tmYRMinorOn', 'tmYRMinorOutwardLengthF',
-                'tmYRMinorPerMajor', 'tmYRMinorThicknessF', 'tmYRMinorValues',
-                'tmYRMode', 'tmYROn', 'tmYRPrecision', 'tmYRStyle', 'tmYRTickEndF',
-                'tmYRTickSpacingF', 'tmYRTickStartF', 'tmYRValues', 'tmYUseLeft',
-                'trGridType', 'trLineInterpolationOn',
-                'trXAxisType', 'trXCoordPoints', 'trXInterPoints', 'trXLog',
-                'trXMaxF', 'trXMinF', 'trXReverse', 'trXSamples', 'trXTensionF',
-                'trYAxisType', 'trYCoordPoints', 'trYInterPoints', 'trYLog',
-                'trYMaxF', 'trYMinF', 'trYReverse', 'trYSamples', 'trYTensionF',
-                'txAngleF', 'txBackgroundFillColor', 'txConstantSpacingF', 'txDirection',
-                'txFont', 'HLU-Fonts', 'txFontAspectF', 'txFontColor',
-                'txFontHeightF', 'txFontOpacityF', 'txFontQuality',
-                'txFontThicknessF', 'txFuncCode', 'txJust', 'txPerimColor',
-                'txPerimDashLengthF', 'txPerimDashPattern', 'txPerimOn',
-                'txPerimSpaceF', 'txPerimThicknessF', 'txPosXF', 'txPosYF',
-                'txString', 'vcExplicitLabelBarLabelsOn', 'vcFillArrowEdgeColor',
-                'vcFillArrowEdgeThicknessF', 'vcFillArrowFillColor',
-                'vcFillArrowHeadInteriorXF', 'vcFillArrowHeadMinFracXF',
-                'vcFillArrowHeadMinFracYF', 'vcFillArrowHeadXF', 'vcFillArrowHeadYF',
-                'vcFillArrowMinFracWidthF', 'vcFillArrowWidthF', 'vcFillArrowsOn',
-                'vcFillOverEdge', 'vcGlyphOpacityF', 'vcGlyphStyle',
-                'vcLabelBarEndLabelsOn', 'vcLabelFontColor', 'vcLabelFontHeightF',
-                'vcLabelsOn', 'vcLabelsUseVectorColor', 'vcLevelColors',
-                'vcLevelCount', 'vcLevelPalette', 'vcLevelSelectionMode',
-                'vcLevelSpacingF', 'vcLevels', 'vcLineArrowColor',
-                'vcLineArrowHeadMaxSizeF', 'vcLineArrowHeadMinSizeF',
-                'vcLineArrowThicknessF', 'vcMagnitudeFormat',
-                'vcMagnitudeScaleFactorF', 'vcMagnitudeScaleValueF',
-                'vcMagnitudeScalingMode', 'vcMapDirection', 'vcMaxLevelCount',
-                'vcMaxLevelValF', 'vcMaxMagnitudeF', 'vcMinAnnoAngleF',
-                'vcMinAnnoArrowAngleF', 'vcMinAnnoArrowEdgeColor',
-                'vcMinAnnoArrowFillColor', 'vcMinAnnoArrowLineColor',
-                'vcMinAnnoArrowMinOffsetF', 'vcMinAnnoArrowSpaceF',
-                'vcMinAnnoArrowUseVecColor', 'vcMinAnnoBackgroundColor',
-                'vcMinAnnoConstantSpacingF', 'vcMinAnnoExplicitMagnitudeF',
-                'vcMinAnnoFont', 'vcMinAnnoFontAspectF', 'vcMinAnnoFontColor',
-                'vcMinAnnoFontHeightF', 'vcMinAnnoFontQuality',
-                'vcMinAnnoFontThicknessF', 'vcMinAnnoFuncCode', 'vcMinAnnoJust',
-                'vcMinAnnoOn', 'vcMinAnnoOrientation', 'vcMinAnnoOrthogonalPosF',
-                'vcMinAnnoParallelPosF', 'vcMinAnnoPerimColor', 'vcMinAnnoPerimOn',
-                'vcMinAnnoPerimSpaceF', 'vcMinAnnoPerimThicknessF', 'vcMinAnnoSide',
-                'vcMinAnnoString1', 'vcMinAnnoString1On', 'vcMinAnnoString2',
-                'vcMinAnnoString2On', 'vcMinAnnoTextDirection', 'vcMinAnnoZone',
-                'vcMinDistanceF', 'vcMinFracLengthF', 'vcMinLevelValF',
-                'vcMinMagnitudeF', 'vcMonoFillArrowEdgeColor',
-                'vcMonoFillArrowFillColor', 'vcMonoLineArrowColor',
-                'vcMonoWindBarbColor', 'vcNoDataLabelOn', 'vcNoDataLabelString',
-                'vcPositionMode', 'vcRefAnnoAngleF', 'vcRefAnnoArrowAngleF',
-                'vcRefAnnoArrowEdgeColor', 'vcRefAnnoArrowFillColor',
-                'vcRefAnnoArrowLineColor', 'vcRefAnnoArrowMinOffsetF',
-                'vcRefAnnoArrowSpaceF', 'vcRefAnnoArrowUseVecColor',
-                'vcRefAnnoBackgroundColor', 'vcRefAnnoConstantSpacingF',
-                'vcRefAnnoExplicitMagnitudeF', 'vcRefAnnoFont',
-                'vcRefAnnoFontAspectF', 'vcRefAnnoFontColor', 'vcRefAnnoFontHeightF',
-                'vcRefAnnoFontQuality', 'vcRefAnnoFontThicknessF',
-                'vcRefAnnoFuncCode', 'vcRefAnnoJust', 'vcRefAnnoOn',
-                'vcRefAnnoOrientation', 'vcRefAnnoOrthogonalPosF',
-                'vcRefAnnoParallelPosF', 'vcRefAnnoPerimColor', 'vcRefAnnoPerimOn',
-                'vcRefAnnoPerimSpaceF', 'vcRefAnnoPerimThicknessF', 'vcRefAnnoSide',
-                'vcRefAnnoString1', 'vcRefAnnoString1On', 'vcRefAnnoString2',
-                'vcRefAnnoString2On', 'vcRefAnnoTextDirection', 'vcRefAnnoZone',
-                'vcRefLengthF', 'vcRefMagnitudeF', 'vcScalarFieldData',
-                'vcScalarMissingValColor', 'vcScalarValueFormat',
-                'vcScalarValueScaleFactorF', 'vcScalarValueScaleValueF',
-                'vcScalarValueScalingMode', 'vcSpanLevelPalette', 'vcUseRefAnnoRes',
-                'vcUseScalarArray', 'vcVectorDrawOrder', 'vcVectorFieldData',
-                'vcWindBarbCalmCircleSizeF', 'vcWindBarbColor',
-                'vcWindBarbLineThicknessF', 'vcWindBarbScaleFactorF',
-                'vcWindBarbTickAngleF', 'vcWindBarbTickLengthF',
-                'vcWindBarbTickSpacingF', 'vcZeroFLabelAngleF',
-                'vcZeroFLabelBackgroundColor', 'vcZeroFLabelConstantSpacingF',
-                'vcZeroFLabelFont', 'vcZeroFLabelFontAspectF',
-                'vcZeroFLabelFontColor', 'vcZeroFLabelFontHeightF',
-                'vcZeroFLabelFontQuality', 'vcZeroFLabelFontThicknessF',
-                'vcZeroFLabelFuncCode', 'vcZeroFLabelJust', 'vcZeroFLabelOn',
-                'vcZeroFLabelOrthogonalPosF', 'vcZeroFLabelParallelPosF',
-                'vcZeroFLabelPerimColor', 'vcZeroFLabelPerimOn',
-                'vcZeroFLabelPerimSpaceF', 'vcZeroFLabelPerimThicknessF',
-                'vcZeroFLabelSide', 'vcZeroFLabelString', 'vcZeroFLabelTextDirection',
-                'vcZeroFLabelZone', 'vfCopyData', 'vfDataArray',
-                'vfExchangeDimensions', 'vfExchangeUVData', 'vfMagMaxV', 'vfMagMinV',
-                'vfMissingUValueV', 'vfMissingVValueV', 'vfPolarData',
-                'vfSingleMissingValue', 'vfUDataArray', 'vfUMaxV', 'vfUMinV',
-                'vfVDataArray', 'vfVMaxV', 'vfVMinV', 'vfXArray', 'vfXCActualEndF',
-                'vfXCActualStartF', 'vfXCEndIndex', 'vfXCEndSubsetV', 'vfXCEndV',
-                'vfXCStartIndex', 'vfXCStartSubsetV', 'vfXCStartV', 'vfXCStride',
-                'vfYArray', 'vfYCActualEndF', 'vfYCActualStartF', 'vfYCEndIndex',
-                'vfYCEndSubsetV', 'vfYCEndV', 'vfYCStartIndex', 'vfYCStartSubsetV',
-                'vfYCStartV', 'vfYCStride', 'vpAnnoManagerId', 'vpClipOn',
-                'vpHeightF', 'vpKeepAspect', 'vpOn', 'vpUseSegments', 'vpWidthF',
-                'vpXF', 'vpYF', 'wkAntiAlias', 'wkBackgroundColor', 'wkBackgroundOpacityF',
-                'wkColorMapLen', 'wkColorMap', 'wkColorModel', 'wkDashTableLength',
-                'wkDefGraphicStyleId', 'wkDeviceLowerX', 'wkDeviceLowerY',
-                'wkDeviceUpperX', 'wkDeviceUpperY', 'wkFileName', 'wkFillTableLength',
-                'wkForegroundColor', 'wkFormat', 'wkFullBackground', 'wkGksWorkId',
-                'wkHeight', 'wkMarkerTableLength', 'wkMetaName', 'wkOrientation',
-                'wkPDFFileName', 'wkPDFFormat', 'wkPDFResolution', 'wkPSFileName',
-                'wkPSFormat', 'wkPSResolution', 'wkPaperHeightF', 'wkPaperSize',
-                'wkPaperWidthF', 'wkPause', 'wkTopLevelViews', 'wkViews',
-                'wkVisualType', 'wkWidth', 'wkWindowId', 'wkXColorMode', 'wsCurrentSize',
-                'wsMaximumSize', 'wsThresholdSize', 'xyComputeXMax',
-                'xyComputeXMin', 'xyComputeYMax', 'xyComputeYMin', 'xyCoordData',
-                'xyCoordDataSpec', 'xyCurveDrawOrder', 'xyDashPattern',
-                'xyDashPatterns', 'xyExplicitLabels', 'xyExplicitLegendLabels',
-                'xyLabelMode', 'xyLineColor', 'xyLineColors', 'xyLineDashSegLenF',
-                'xyLineLabelConstantSpacingF', 'xyLineLabelFont',
-                'xyLineLabelFontAspectF', 'xyLineLabelFontColor',
-                'xyLineLabelFontColors', 'xyLineLabelFontHeightF',
-                'xyLineLabelFontQuality', 'xyLineLabelFontThicknessF',
-                'xyLineLabelFuncCode', 'xyLineThicknessF', 'xyLineThicknesses',
-                'xyMarkLineMode', 'xyMarkLineModes', 'xyMarker', 'xyMarkerColor',
-                'xyMarkerColors', 'xyMarkerSizeF', 'xyMarkerSizes',
-                'xyMarkerThicknessF', 'xyMarkerThicknesses', 'xyMarkers',
-                'xyMonoDashPattern', 'xyMonoLineColor', 'xyMonoLineLabelFontColor',
-                'xyMonoLineThickness', 'xyMonoMarkLineMode', 'xyMonoMarker',
-                'xyMonoMarkerColor', 'xyMonoMarkerSize', 'xyMonoMarkerThickness',
-                'xyXIrrTensionF', 'xyXIrregularPoints', 'xyXStyle', 'xyYIrrTensionF',
-                'xyYIrregularPoints', 'xyYStyle'), prefix=r'\b'),
-             Name.Builtin),
-
-            # Booleans
-            (r'\.(True|False)\.', Name.Builtin),
-            # Comparing Operators
-            (r'\.(eq|ne|lt|le|gt|ge|not|and|or|xor)\.', Operator.Word),
-        ],
-
-        'strings': [
-            (r'(?s)"(\\\\|\\[0-7]+|\\.|[^"\\])*"', String.Double),
-        ],
-
-        'nums': [
-            (r'\d+(?![.e])(_[a-z]\w+)?', Number.Integer),
-            (r'[+-]?\d*\.\d+(e[-+]?\d+)?(_[a-z]\w+)?', Number.Float),
-            (r'[+-]?\d+\.\d*(e[-+]?\d+)?(_[a-z]\w+)?', Number.Float),
-        ],
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/nimrod.py b/.venv/lib/python3.12/site-packages/pygments/lexers/nimrod.py
deleted file mode 100644
index b99e246..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/nimrod.py
+++ /dev/null
@@ -1,199 +0,0 @@
-"""
-    pygments.lexers.nimrod
-    ~~~~~~~~~~~~~~~~~~~~~~
-
-    Lexer for the Nim language (formerly known as Nimrod).
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-import re
-
-from pygments.lexer import RegexLexer, include, default, bygroups
-from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
-    Number, Punctuation, Error
-
-__all__ = ['NimrodLexer']
-
-
-class NimrodLexer(RegexLexer):
-    """
-    For Nim source code.
-    """
-
-    name = 'Nimrod'
-    url = 'http://nim-lang.org/'
-    aliases = ['nimrod', 'nim']
-    filenames = ['*.nim', '*.nimrod']
-    mimetypes = ['text/x-nim']
-    version_added = '1.5'
-
-    flags = re.MULTILINE | re.IGNORECASE
-
-    def underscorize(words):
-        newWords = []
-        new = []
-        for word in words:
-            for ch in word:
-                new.append(ch)
-                new.append("_?")
-            newWords.append(''.join(new))
-            new = []
-        return "|".join(newWords)
-
-    keywords = [
-        'addr', 'and', 'as', 'asm', 'bind', 'block', 'break', 'case',
-        'cast', 'concept', 'const', 'continue', 'converter', 'defer', 'discard',
-        'distinct', 'div', 'do', 'elif', 'else', 'end', 'enum', 'except',
-        'export', 'finally', 'for', 'if', 'in', 'yield', 'interface',
-        'is', 'isnot', 'iterator', 'let', 'mixin', 'mod',
-        'not', 'notin', 'object', 'of', 'or', 'out', 'ptr', 'raise',
-        'ref', 'return', 'shl', 'shr', 'static', 'try',
-        'tuple', 'type', 'using', 'when', 'while', 'xor'
-    ]
-
-    keywordsPseudo = [
-        'nil', 'true', 'false'
-    ]
-
-    opWords = [
-        'and', 'or', 'not', 'xor', 'shl', 'shr', 'div', 'mod', 'in',
-        'notin', 'is', 'isnot'
-    ]
-
-    types = [
-        'int', 'int8', 'int16', 'int32', 'int64', 'float', 'float32', 'float64',
-        'bool', 'char', 'range', 'array', 'seq', 'set', 'string'
-    ]
-
-    tokens = {
-        'root': [
-            # Comments
-            (r'##\[', String.Doc, 'doccomment'),
-            (r'##.*$', String.Doc),
-            (r'#\[', Comment.Multiline, 'comment'),
-            (r'#.*$', Comment),
-
-            # Pragmas
-            (r'\{\.', String.Other, 'pragma'),
-
-            # Operators
-            (r'[*=><+\-/@$~&%!?|\\\[\]]', Operator),
-            (r'\.\.|\.|,|\[\.|\.\]|\{\.|\.\}|\(\.|\.\)|\{|\}|\(|\)|:|\^|`|;',
-             Punctuation),
-
-            # Case statement branch
-            (r'(\n\s*)(of)(\s)', bygroups(Text.Whitespace, Keyword,
-                                          Text.Whitespace), 'casebranch'),
-
-            # Strings
-            (r'(?:[\w]+)"', String, 'rdqs'),
-            (r'"""', String.Double, 'tdqs'),
-            ('"', String, 'dqs'),
-
-            # Char
-            ("'", String.Char, 'chars'),
-
-            # Keywords
-            (rf'({underscorize(opWords)})\b', Operator.Word),
-            (r'(proc|func|method|macro|template)(\s)(?![(\[\]])',
-             bygroups(Keyword, Text.Whitespace), 'funcname'),
-            (rf'({underscorize(keywords)})\b', Keyword),
-            (r'({})\b'.format(underscorize(['from', 'import', 'include', 'export'])),
-             Keyword.Namespace),
-            (r'(v_?a_?r)\b', Keyword.Declaration),
-            (rf'({underscorize(types)})\b', Name.Builtin),
-            (rf'({underscorize(keywordsPseudo)})\b', Keyword.Pseudo),
-
-            # Identifiers
-            (r'\b((?![_\d])\w)(((?!_)\w)|(_(?!_)\w))*', Name),
-
-            # Numbers
-            (r'[0-9][0-9_]*(?=([e.]|\'f(32|64)))',
-             Number.Float, ('float-suffix', 'float-number')),
-            (r'0x[a-f0-9][a-f0-9_]*', Number.Hex, 'int-suffix'),
-            (r'0b[01][01_]*', Number.Bin, 'int-suffix'),
-            (r'0o[0-7][0-7_]*', Number.Oct, 'int-suffix'),
-            (r'[0-9][0-9_]*', Number.Integer, 'int-suffix'),
-
-            # Whitespace
-            (r'\s+', Text.Whitespace),
-            (r'.+$', Error),
-        ],
-        'chars': [
-            (r'\\([\\abcefnrtvl"\']|x[a-f0-9]{2}|[0-9]{1,3})', String.Escape),
-            (r"'", String.Char, '#pop'),
-            (r".", String.Char)
-        ],
-        'strings': [
-            (r'(?|>=|>>|>|<=|<<|<|\+|-|=|/|\*|%|\+=|-=|!|@', Operator),
-            (r'\(|\)|\[|\]|,|\.\.\.|\.\.|\.|::|:', Punctuation),
-            (r'`\{[^`]*`\}', Text),  # Extern blocks won't be Lexed by Nit
-            (r'[\r\n\t ]+', Text),
-        ],
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/nix.py b/.venv/lib/python3.12/site-packages/pygments/lexers/nix.py
deleted file mode 100644
index 16572af..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/nix.py
+++ /dev/null
@@ -1,144 +0,0 @@
-"""
-    pygments.lexers.nix
-    ~~~~~~~~~~~~~~~~~~~
-
-    Lexers for the NixOS Nix language.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-import re
-
-from pygments.lexer import RegexLexer, include
-from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
-    Number, Punctuation, Literal
-
-__all__ = ['NixLexer']
-
-
-class NixLexer(RegexLexer):
-    """
-    For the Nix language.
-    """
-
-    name = 'Nix'
-    url = 'http://nixos.org/nix/'
-    aliases = ['nixos', 'nix']
-    filenames = ['*.nix']
-    mimetypes = ['text/x-nix']
-    version_added = '2.0'
-
-    keywords = ['rec', 'with', 'let', 'in', 'inherit', 'assert', 'if',
-                'else', 'then', '...']
-    builtins = ['import', 'abort', 'baseNameOf', 'dirOf', 'isNull', 'builtins',
-                'map', 'removeAttrs', 'throw', 'toString', 'derivation']
-    operators = ['++', '+', '?', '.', '!', '//', '==', '/',
-                 '!=', '&&', '||', '->', '=', '<', '>', '*', '-']
-
-    punctuations = ["(", ")", "[", "]", ";", "{", "}", ":", ",", "@"]
-
-    tokens = {
-        'root': [
-            # comments starting with #
-            (r'#.*$', Comment.Single),
-
-            # multiline comments
-            (r'/\*', Comment.Multiline, 'comment'),
-
-            # whitespace
-            (r'\s+', Text),
-
-            # keywords
-            ('({})'.format('|'.join(re.escape(entry) + '\\b' for entry in keywords)), Keyword),
-
-            # highlight the builtins
-            ('({})'.format('|'.join(re.escape(entry) + '\\b' for entry in builtins)),
-             Name.Builtin),
-
-            (r'\b(true|false|null)\b', Name.Constant),
-
-            # floats
-            (r'-?(\d+\.\d*|\.\d+)([eE][-+]?\d+)?', Number.Float),
-
-            # integers
-            (r'-?[0-9]+', Number.Integer),
-
-            # paths
-            (r'[\w.+-]*(\/[\w.+-]+)+', Literal),
-            (r'~(\/[\w.+-]+)+', Literal),
-            (r'\<[\w.+-]+(\/[\w.+-]+)*\>', Literal),
-
-            # operators
-            ('({})'.format('|'.join(re.escape(entry) for entry in operators)),
-             Operator),
-
-            # word operators
-            (r'\b(or|and)\b', Operator.Word),
-
-            (r'\{', Punctuation, 'block'),
-
-            # punctuations
-            ('({})'.format('|'.join(re.escape(entry) for entry in punctuations)), Punctuation),
-
-            # strings
-            (r'"', String.Double, 'doublequote'),
-            (r"''", String.Multiline, 'multiline'),
-
-            # urls
-            (r'[a-zA-Z][a-zA-Z0-9\+\-\.]*\:[\w%/?:@&=+$,\\.!~*\'-]+', Literal),
-
-            # names of variables
-            (r'[\w-]+(?=\s*=)', String.Symbol),
-            (r'[a-zA-Z_][\w\'-]*', Text),
-
-            (r"\$\{", String.Interpol, 'antiquote'),
-        ],
-        'comment': [
-            (r'[^/*]+', Comment.Multiline),
-            (r'/\*', Comment.Multiline, '#push'),
-            (r'\*/', Comment.Multiline, '#pop'),
-            (r'[*/]', Comment.Multiline),
-        ],
-        'multiline': [
-            (r"''(\$|'|\\n|\\r|\\t|\\)", String.Escape),
-            (r"''", String.Multiline, '#pop'),
-            (r'\$\{', String.Interpol, 'antiquote'),
-            (r"[^'\$]+", String.Multiline),
-            (r"\$[^\{']", String.Multiline),
-            (r"'[^']", String.Multiline),
-            (r"\$(?=')", String.Multiline),
-        ],
-        'doublequote': [
-            (r'\\(\\|"|\$|n)', String.Escape),
-            (r'"', String.Double, '#pop'),
-            (r'\$\{', String.Interpol, 'antiquote'),
-            (r'[^"\\\$]+', String.Double),
-            (r'\$[^\{"]', String.Double),
-            (r'\$(?=")', String.Double),
-            (r'\\', String.Double),
-        ],
-        'antiquote': [
-            (r"\}", String.Interpol, '#pop'),
-            # TODO: we should probably escape also here ''${ \${
-            (r"\$\{", String.Interpol, '#push'),
-            include('root'),
-        ],
-        'block': [
-            (r"\}", Punctuation, '#pop'),
-            include('root'),
-        ],
-    }
-
-    def analyse_text(text):
-        rv = 0.0
-        # TODO: let/in
-        if re.search(r'import.+?<[^>]+>', text):
-            rv += 0.4
-        if re.search(r'mkDerivation\s+(\(|\{|rec)', text):
-            rv += 0.4
-        if re.search(r'=\s+mkIf\s+', text):
-            rv += 0.4
-        if re.search(r'\{[a-zA-Z,\s]+\}:', text):
-            rv += 0.1
-        return rv
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/numbair.py b/.venv/lib/python3.12/site-packages/pygments/lexers/numbair.py
deleted file mode 100644
index 28395b4..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/numbair.py
+++ /dev/null
@@ -1,63 +0,0 @@
-"""
-    pygments.lexers.numbair
-    ~~~~~~~~~~~~~~~~~~~~~~~
-
-    Lexer for other Numba Intermediate Representation.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-from pygments.lexer import RegexLexer, include, bygroups, words
-from pygments.token import Whitespace, Name, String,  Punctuation, Keyword, \
-    Operator, Number
-
-__all__ = ["NumbaIRLexer"]
-
-class NumbaIRLexer(RegexLexer):
-    """
-    Lexer for Numba IR
-    """
-    name = 'Numba_IR'
-    url = "https://numba.readthedocs.io/en/stable/developer/architecture.html#stage-2-generate-the-numba-ir"
-    aliases = ['numba_ir', 'numbair']
-    filenames = ['*.numba_ir']
-    mimetypes = ['text/x-numba_ir', 'text/x-numbair']
-    version_added = '2.19'
-
-    identifier = r'\$[a-zA-Z0-9._]+'
-    fun_or_var = r'([a-zA-Z_]+[a-zA-Z0-9]*)'
-
-    tokens = {
-        'root' : [
-            (r'(label)(\ [0-9]+)(:)$',
-                bygroups(Keyword, Name.Label, Punctuation)),
-
-            (r'=', Operator),
-            include('whitespace'),
-            include('keyword'),
-
-            (identifier, Name.Variable),
-            (fun_or_var + r'(\()',
-                bygroups(Name.Function, Punctuation)),
-            (fun_or_var + r'(\=)',
-                bygroups(Name.Attribute, Punctuation)),
-            (fun_or_var, Name.Constant),
-            (r'[0-9]+', Number),
-
-            # 
-            (r'<[^>\n]*>', String),
-
-            (r'[=<>{}\[\]()*.,!\':]|x\b', Punctuation)
-        ],
-
-        'keyword':[
-            (words((
-                'del', 'jump', 'call', 'branch',
-            ), suffix=' '), Keyword),
-        ],
-
-        'whitespace': [
-            (r'(\n|\s)+', Whitespace),
-        ],
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/oberon.py b/.venv/lib/python3.12/site-packages/pygments/lexers/oberon.py
deleted file mode 100644
index 11cf571..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/oberon.py
+++ /dev/null
@@ -1,120 +0,0 @@
-"""
-    pygments.lexers.oberon
-    ~~~~~~~~~~~~~~~~~~~~~~
-
-    Lexers for Oberon family languages.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-import re
-
-from pygments.lexer import RegexLexer, include, words
-from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
-    Number, Punctuation
-
-__all__ = ['ComponentPascalLexer']
-
-
-class ComponentPascalLexer(RegexLexer):
-    """
-    For Component Pascal source code.
-    """
-    name = 'Component Pascal'
-    aliases = ['componentpascal', 'cp']
-    filenames = ['*.cp', '*.cps']
-    mimetypes = ['text/x-component-pascal']
-    url = 'https://blackboxframework.org'
-    version_added = '2.1'
-
-    flags = re.MULTILINE | re.DOTALL
-
-    tokens = {
-        'root': [
-            include('whitespace'),
-            include('comments'),
-            include('punctuation'),
-            include('numliterals'),
-            include('strings'),
-            include('operators'),
-            include('builtins'),
-            include('identifiers'),
-        ],
-        'whitespace': [
-            (r'\n+', Text),  # blank lines
-            (r'\s+', Text),  # whitespace
-        ],
-        'comments': [
-            (r'\(\*([^$].*?)\*\)', Comment.Multiline),
-            # TODO: nested comments (* (* ... *) ... (* ... *) *) not supported!
-        ],
-        'punctuation': [
-            (r'[()\[\]{},.:;|]', Punctuation),
-        ],
-        'numliterals': [
-            (r'[0-9A-F]+X\b', Number.Hex),                 # char code
-            (r'[0-9A-F]+[HL]\b', Number.Hex),              # hexadecimal number
-            (r'[0-9]+\.[0-9]+E[+-][0-9]+', Number.Float),  # real number
-            (r'[0-9]+\.[0-9]+', Number.Float),             # real number
-            (r'[0-9]+', Number.Integer),                   # decimal whole number
-        ],
-        'strings': [
-            (r"'[^\n']*'", String),  # single quoted string
-            (r'"[^\n"]*"', String),  # double quoted string
-        ],
-        'operators': [
-            # Arithmetic Operators
-            (r'[+-]', Operator),
-            (r'[*/]', Operator),
-            # Relational Operators
-            (r'[=#<>]', Operator),
-            # Dereferencing Operator
-            (r'\^', Operator),
-            # Logical AND Operator
-            (r'&', Operator),
-            # Logical NOT Operator
-            (r'~', Operator),
-            # Assignment Symbol
-            (r':=', Operator),
-            # Range Constructor
-            (r'\.\.', Operator),
-            (r'\$', Operator),
-        ],
-        'identifiers': [
-            (r'([a-zA-Z_$][\w$]*)', Name),
-        ],
-        'builtins': [
-            (words((
-                'ANYPTR', 'ANYREC', 'BOOLEAN', 'BYTE', 'CHAR', 'INTEGER', 'LONGINT',
-                'REAL', 'SET', 'SHORTCHAR', 'SHORTINT', 'SHORTREAL'
-                ), suffix=r'\b'), Keyword.Type),
-            (words((
-                'ABS', 'ABSTRACT', 'ARRAY', 'ASH', 'ASSERT', 'BEGIN', 'BITS', 'BY',
-                'CAP', 'CASE', 'CHR', 'CLOSE', 'CONST', 'DEC', 'DIV', 'DO', 'ELSE',
-                'ELSIF', 'EMPTY', 'END', 'ENTIER', 'EXCL', 'EXIT', 'EXTENSIBLE', 'FOR',
-                'HALT', 'IF', 'IMPORT', 'IN', 'INC', 'INCL', 'IS', 'LEN', 'LIMITED',
-                'LONG', 'LOOP', 'MAX', 'MIN', 'MOD', 'MODULE', 'NEW', 'ODD', 'OF',
-                'OR', 'ORD', 'OUT', 'POINTER', 'PROCEDURE', 'RECORD', 'REPEAT', 'RETURN',
-                'SHORT', 'SHORTCHAR', 'SHORTINT', 'SIZE', 'THEN', 'TYPE', 'TO', 'UNTIL',
-                'VAR', 'WHILE', 'WITH'
-                ), suffix=r'\b'), Keyword.Reserved),
-            (r'(TRUE|FALSE|NIL|INF)\b', Keyword.Constant),
-        ]
-    }
-
-    def analyse_text(text):
-        """The only other lexer using .cp is the C++ one, so we check if for
-        a few common Pascal keywords here. Those are unfortunately quite
-        common across various business languages as well."""
-        result = 0
-        if 'BEGIN' in text:
-            result += 0.01
-        if 'END' in text:
-            result += 0.01
-        if 'PROCEDURE' in text:
-            result += 0.01
-        if 'MODULE' in text:
-            result += 0.01
-
-        return result
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/objective.py b/.venv/lib/python3.12/site-packages/pygments/lexers/objective.py
deleted file mode 100644
index ce281fb..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/objective.py
+++ /dev/null
@@ -1,513 +0,0 @@
-"""
-    pygments.lexers.objective
-    ~~~~~~~~~~~~~~~~~~~~~~~~~
-
-    Lexers for Objective-C family languages.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-import re
-
-from pygments.lexer import RegexLexer, include, bygroups, using, this, words, \
-    inherit, default
-from pygments.token import Text, Keyword, Name, String, Operator, \
-    Number, Punctuation, Literal, Comment, Whitespace
-
-from pygments.lexers.c_cpp import CLexer, CppLexer
-
-__all__ = ['ObjectiveCLexer', 'ObjectiveCppLexer', 'LogosLexer', 'SwiftLexer']
-
-
-def objective(baselexer):
-    """
-    Generate a subclass of baselexer that accepts the Objective-C syntax
-    extensions.
-    """
-
-    # Have to be careful not to accidentally match JavaDoc/Doxygen syntax here,
-    # since that's quite common in ordinary C/C++ files.  It's OK to match
-    # JavaDoc/Doxygen keywords that only apply to Objective-C, mind.
-    #
-    # The upshot of this is that we CANNOT match @class or @interface
-    _oc_keywords = re.compile(r'@(?:end|implementation|protocol)')
-
-    # Matches [ ? identifier  ( identifier ? ] |  identifier? : )
-    # (note the identifier is *optional* when there is a ':'!)
-    _oc_message = re.compile(r'\[\s*[a-zA-Z_]\w*\s+'
-                             r'(?:[a-zA-Z_]\w*\s*\]|'
-                             r'(?:[a-zA-Z_]\w*)?:)')
-
-    class GeneratedObjectiveCVariant(baselexer):
-        """
-        Implements Objective-C syntax on top of an existing C family lexer.
-        """
-
-        tokens = {
-            'statements': [
-                (r'@"', String, 'string'),
-                (r'@(YES|NO)', Number),
-                (r"@'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'", String.Char),
-                (r'@(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[lL]?', Number.Float),
-                (r'@(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float),
-                (r'@0x[0-9a-fA-F]+[Ll]?', Number.Hex),
-                (r'@0[0-7]+[Ll]?', Number.Oct),
-                (r'@\d+[Ll]?', Number.Integer),
-                (r'@\(', Literal, 'literal_number'),
-                (r'@\[', Literal, 'literal_array'),
-                (r'@\{', Literal, 'literal_dictionary'),
-                (words((
-                    '@selector', '@private', '@protected', '@public', '@encode',
-                    '@synchronized', '@try', '@throw', '@catch', '@finally',
-                    '@end', '@property', '@synthesize', '__bridge', '__bridge_transfer',
-                    '__autoreleasing', '__block', '__weak', '__strong', 'weak', 'strong',
-                    'copy', 'retain', 'assign', 'unsafe_unretained', 'atomic', 'nonatomic',
-                    'readonly', 'readwrite', 'setter', 'getter', 'typeof', 'in',
-                    'out', 'inout', 'release', 'class', '@dynamic', '@optional',
-                    '@required', '@autoreleasepool', '@import'), suffix=r'\b'),
-                 Keyword),
-                (words(('id', 'instancetype', 'Class', 'IMP', 'SEL', 'BOOL',
-                        'IBOutlet', 'IBAction', 'unichar'), suffix=r'\b'),
-                 Keyword.Type),
-                (r'@(true|false|YES|NO)\n', Name.Builtin),
-                (r'(YES|NO|nil|self|super)\b', Name.Builtin),
-                # Carbon types
-                (r'(Boolean|UInt8|SInt8|UInt16|SInt16|UInt32|SInt32)\b', Keyword.Type),
-                # Carbon built-ins
-                (r'(TRUE|FALSE)\b', Name.Builtin),
-                (r'(@interface|@implementation)(\s+)', bygroups(Keyword, Text),
-                 ('#pop', 'oc_classname')),
-                (r'(@class|@protocol)(\s+)', bygroups(Keyword, Text),
-                 ('#pop', 'oc_forward_classname')),
-                # @ can also prefix other expressions like @{...} or @(...)
-                (r'@', Punctuation),
-                inherit,
-            ],
-            'oc_classname': [
-                # interface definition that inherits
-                (r'([a-zA-Z$_][\w$]*)(\s*:\s*)([a-zA-Z$_][\w$]*)?(\s*)(\{)',
-                 bygroups(Name.Class, Text, Name.Class, Text, Punctuation),
-                 ('#pop', 'oc_ivars')),
-                (r'([a-zA-Z$_][\w$]*)(\s*:\s*)([a-zA-Z$_][\w$]*)?',
-                 bygroups(Name.Class, Text, Name.Class), '#pop'),
-                # interface definition for a category
-                (r'([a-zA-Z$_][\w$]*)(\s*)(\([a-zA-Z$_][\w$]*\))(\s*)(\{)',
-                 bygroups(Name.Class, Text, Name.Label, Text, Punctuation),
-                 ('#pop', 'oc_ivars')),
-                (r'([a-zA-Z$_][\w$]*)(\s*)(\([a-zA-Z$_][\w$]*\))',
-                 bygroups(Name.Class, Text, Name.Label), '#pop'),
-                # simple interface / implementation
-                (r'([a-zA-Z$_][\w$]*)(\s*)(\{)',
-                 bygroups(Name.Class, Text, Punctuation), ('#pop', 'oc_ivars')),
-                (r'([a-zA-Z$_][\w$]*)', Name.Class, '#pop')
-            ],
-            'oc_forward_classname': [
-                (r'([a-zA-Z$_][\w$]*)(\s*,\s*)',
-                 bygroups(Name.Class, Text), 'oc_forward_classname'),
-                (r'([a-zA-Z$_][\w$]*)(\s*;?)',
-                 bygroups(Name.Class, Text), '#pop')
-            ],
-            'oc_ivars': [
-                include('whitespace'),
-                include('statements'),
-                (';', Punctuation),
-                (r'\{', Punctuation, '#push'),
-                (r'\}', Punctuation, '#pop'),
-            ],
-            'root': [
-                # methods
-                (r'^([-+])(\s*)'                         # method marker
-                 r'(\(.*?\))?(\s*)'                      # return type
-                 r'([a-zA-Z$_][\w$]*:?)',        # begin of method name
-                 bygroups(Punctuation, Text, using(this),
-                          Text, Name.Function),
-                 'method'),
-                inherit,
-            ],
-            'method': [
-                include('whitespace'),
-                # TODO unsure if ellipses are allowed elsewhere, see
-                # discussion in Issue 789
-                (r',', Punctuation),
-                (r'\.\.\.', Punctuation),
-                (r'(\(.*?\))(\s*)([a-zA-Z$_][\w$]*)',
-                 bygroups(using(this), Text, Name.Variable)),
-                (r'[a-zA-Z$_][\w$]*:', Name.Function),
-                (';', Punctuation, '#pop'),
-                (r'\{', Punctuation, 'function'),
-                default('#pop'),
-            ],
-            'literal_number': [
-                (r'\(', Punctuation, 'literal_number_inner'),
-                (r'\)', Literal, '#pop'),
-                include('statement'),
-            ],
-            'literal_number_inner': [
-                (r'\(', Punctuation, '#push'),
-                (r'\)', Punctuation, '#pop'),
-                include('statement'),
-            ],
-            'literal_array': [
-                (r'\[', Punctuation, 'literal_array_inner'),
-                (r'\]', Literal, '#pop'),
-                include('statement'),
-            ],
-            'literal_array_inner': [
-                (r'\[', Punctuation, '#push'),
-                (r'\]', Punctuation, '#pop'),
-                include('statement'),
-            ],
-            'literal_dictionary': [
-                (r'\}', Literal, '#pop'),
-                include('statement'),
-            ],
-        }
-
-        def analyse_text(text):
-            if _oc_keywords.search(text):
-                return 1.0
-            elif '@"' in text:  # strings
-                return 0.8
-            elif re.search('@[0-9]+', text):
-                return 0.7
-            elif _oc_message.search(text):
-                return 0.8
-            return 0
-
-        def get_tokens_unprocessed(self, text, stack=('root',)):
-            from pygments.lexers._cocoa_builtins import COCOA_INTERFACES, \
-                COCOA_PROTOCOLS, COCOA_PRIMITIVES
-
-            for index, token, value in \
-                    baselexer.get_tokens_unprocessed(self, text, stack):
-                if token is Name or token is Name.Class:
-                    if value in COCOA_INTERFACES or value in COCOA_PROTOCOLS \
-                       or value in COCOA_PRIMITIVES:
-                        token = Name.Builtin.Pseudo
-
-                yield index, token, value
-
-    return GeneratedObjectiveCVariant
-
-
-class ObjectiveCLexer(objective(CLexer)):
-    """
-    For Objective-C source code with preprocessor directives.
-    """
-
-    name = 'Objective-C'
-    url = 'https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/Introduction/Introduction.html'
-    aliases = ['objective-c', 'objectivec', 'obj-c', 'objc']
-    filenames = ['*.m', '*.h']
-    mimetypes = ['text/x-objective-c']
-    version_added = ''
-    priority = 0.05    # Lower than C
-
-
-class ObjectiveCppLexer(objective(CppLexer)):
-    """
-    For Objective-C++ source code with preprocessor directives.
-    """
-
-    name = 'Objective-C++'
-    aliases = ['objective-c++', 'objectivec++', 'obj-c++', 'objc++']
-    filenames = ['*.mm', '*.hh']
-    mimetypes = ['text/x-objective-c++']
-    version_added = ''
-    priority = 0.05    # Lower than C++
-
-
-class LogosLexer(ObjectiveCppLexer):
-    """
-    For Logos + Objective-C source code with preprocessor directives.
-    """
-
-    name = 'Logos'
-    aliases = ['logos']
-    filenames = ['*.x', '*.xi', '*.xm', '*.xmi']
-    mimetypes = ['text/x-logos']
-    version_added = '1.6'
-    priority = 0.25
-
-    tokens = {
-        'statements': [
-            (r'(%orig|%log)\b', Keyword),
-            (r'(%c)\b(\()(\s*)([a-zA-Z$_][\w$]*)(\s*)(\))',
-             bygroups(Keyword, Punctuation, Text, Name.Class, Text, Punctuation)),
-            (r'(%init)\b(\()',
-             bygroups(Keyword, Punctuation), 'logos_init_directive'),
-            (r'(%init)(?=\s*;)', bygroups(Keyword)),
-            (r'(%hook|%group)(\s+)([a-zA-Z$_][\w$]+)',
-             bygroups(Keyword, Text, Name.Class), '#pop'),
-            (r'(%subclass)(\s+)', bygroups(Keyword, Text),
-             ('#pop', 'logos_classname')),
-            inherit,
-        ],
-        'logos_init_directive': [
-            (r'\s+', Text),
-            (',', Punctuation, ('logos_init_directive', '#pop')),
-            (r'([a-zA-Z$_][\w$]*)(\s*)(=)(\s*)([^);]*)',
-             bygroups(Name.Class, Text, Punctuation, Text, Text)),
-            (r'([a-zA-Z$_][\w$]*)', Name.Class),
-            (r'\)', Punctuation, '#pop'),
-        ],
-        'logos_classname': [
-            (r'([a-zA-Z$_][\w$]*)(\s*:\s*)([a-zA-Z$_][\w$]*)?',
-             bygroups(Name.Class, Text, Name.Class), '#pop'),
-            (r'([a-zA-Z$_][\w$]*)', Name.Class, '#pop')
-        ],
-        'root': [
-            (r'(%subclass)(\s+)', bygroups(Keyword, Text),
-             'logos_classname'),
-            (r'(%hook|%group)(\s+)([a-zA-Z$_][\w$]+)',
-             bygroups(Keyword, Text, Name.Class)),
-            (r'(%config)(\s*\(\s*)(\w+)(\s*=)(.*?)(\)\s*)',
-             bygroups(Keyword, Text, Name.Variable, Text, String, Text)),
-            (r'(%ctor)(\s*)(\{)', bygroups(Keyword, Text, Punctuation),
-             'function'),
-            (r'(%new)(\s*)(\()(.*?)(\))',
-             bygroups(Keyword, Text, Keyword, String, Keyword)),
-            (r'(\s*)(%end)(\s*)', bygroups(Text, Keyword, Text)),
-            inherit,
-        ],
-    }
-
-    _logos_keywords = re.compile(r'%(?:hook|ctor|init|c\()')
-
-    def analyse_text(text):
-        if LogosLexer._logos_keywords.search(text):
-            return 1.0
-        return 0
-
-
-class SwiftLexer(RegexLexer):
-    """
-    For Swift source.
-    """
-    name = 'Swift'
-    url = 'https://www.swift.org/'
-    filenames = ['*.swift']
-    aliases = ['swift']
-    mimetypes = ['text/x-swift']
-    version_added = '2.0'
-
-    tokens = {
-        'root': [
-            # Whitespace and Comments
-            (r'\n', Text),
-            (r'\s+', Whitespace),
-            (r'//', Comment.Single, 'comment-single'),
-            (r'/\*', Comment.Multiline, 'comment-multi'),
-            (r'#(if|elseif|else|endif|available)\b', Comment.Preproc, 'preproc'),
-
-            # Keywords
-            include('keywords'),
-
-            # Global Types
-            (words((
-                'Array', 'AutoreleasingUnsafeMutablePointer', 'BidirectionalReverseView',
-                'Bit', 'Bool', 'CFunctionPointer', 'COpaquePointer', 'CVaListPointer',
-                'Character', 'ClosedInterval', 'CollectionOfOne', 'ContiguousArray',
-                'Dictionary', 'DictionaryGenerator', 'DictionaryIndex', 'Double',
-                'EmptyCollection', 'EmptyGenerator', 'EnumerateGenerator',
-                'EnumerateSequence', 'FilterCollectionView',
-                'FilterCollectionViewIndex', 'FilterGenerator', 'FilterSequenceView',
-                'Float', 'Float80', 'FloatingPointClassification', 'GeneratorOf',
-                'GeneratorOfOne', 'GeneratorSequence', 'HalfOpenInterval', 'HeapBuffer',
-                'HeapBufferStorage', 'ImplicitlyUnwrappedOptional', 'IndexingGenerator',
-                'Int', 'Int16', 'Int32', 'Int64', 'Int8', 'LazyBidirectionalCollection',
-                'LazyForwardCollection', 'LazyRandomAccessCollection',
-                'LazySequence', 'MapCollectionView', 'MapSequenceGenerator',
-                'MapSequenceView', 'MirrorDisposition', 'ObjectIdentifier', 'OnHeap',
-                'Optional', 'PermutationGenerator', 'QuickLookObject',
-                'RandomAccessReverseView', 'Range', 'RangeGenerator', 'RawByte', 'Repeat',
-                'ReverseBidirectionalIndex', 'ReverseRandomAccessIndex', 'SequenceOf',
-                'SinkOf', 'Slice', 'StaticString', 'StrideThrough', 'StrideThroughGenerator',
-                'StrideTo', 'StrideToGenerator', 'String', 'UInt', 'UInt16', 'UInt32',
-                'UInt64', 'UInt8', 'UTF16', 'UTF32', 'UTF8', 'UnicodeDecodingResult',
-                'UnicodeScalar', 'Unmanaged', 'UnsafeBufferPointer',
-                'UnsafeBufferPointerGenerator', 'UnsafeMutableBufferPointer',
-                'UnsafeMutablePointer', 'UnsafePointer', 'Zip2', 'ZipGenerator2',
-                # Protocols
-                'AbsoluteValuable', 'AnyObject', 'ArrayLiteralConvertible',
-                'BidirectionalIndexType', 'BitwiseOperationsType',
-                'BooleanLiteralConvertible', 'BooleanType', 'CVarArgType',
-                'CollectionType', 'Comparable', 'DebugPrintable',
-                'DictionaryLiteralConvertible', 'Equatable',
-                'ExtendedGraphemeClusterLiteralConvertible',
-                'ExtensibleCollectionType', 'FloatLiteralConvertible',
-                'FloatingPointType', 'ForwardIndexType', 'GeneratorType', 'Hashable',
-                'IntegerArithmeticType', 'IntegerLiteralConvertible', 'IntegerType',
-                'IntervalType', 'MirrorType', 'MutableCollectionType', 'MutableSliceable',
-                'NilLiteralConvertible', 'OutputStreamType', 'Printable',
-                'RandomAccessIndexType', 'RangeReplaceableCollectionType',
-                'RawOptionSetType', 'RawRepresentable', 'Reflectable', 'SequenceType',
-                'SignedIntegerType', 'SignedNumberType', 'SinkType', 'Sliceable',
-                'Streamable', 'Strideable', 'StringInterpolationConvertible',
-                'StringLiteralConvertible', 'UnicodeCodecType',
-                'UnicodeScalarLiteralConvertible', 'UnsignedIntegerType',
-                '_ArrayBufferType', '_BidirectionalIndexType', '_CocoaStringType',
-                '_CollectionType', '_Comparable', '_ExtensibleCollectionType',
-                '_ForwardIndexType', '_Incrementable', '_IntegerArithmeticType',
-                '_IntegerType', '_ObjectiveCBridgeable', '_RandomAccessIndexType',
-                '_RawOptionSetType', '_SequenceType', '_Sequence_Type',
-                '_SignedIntegerType', '_SignedNumberType', '_Sliceable', '_Strideable',
-                '_SwiftNSArrayRequiredOverridesType', '_SwiftNSArrayType',
-                '_SwiftNSCopyingType', '_SwiftNSDictionaryRequiredOverridesType',
-                '_SwiftNSDictionaryType', '_SwiftNSEnumeratorType',
-                '_SwiftNSFastEnumerationType', '_SwiftNSStringRequiredOverridesType',
-                '_SwiftNSStringType', '_UnsignedIntegerType',
-                # Variables
-                'C_ARGC', 'C_ARGV', 'Process',
-                # Typealiases
-                'Any', 'AnyClass', 'BooleanLiteralType', 'CBool', 'CChar', 'CChar16',
-                'CChar32', 'CDouble', 'CFloat', 'CInt', 'CLong', 'CLongLong', 'CShort',
-                'CSignedChar', 'CUnsignedInt', 'CUnsignedLong', 'CUnsignedShort',
-                'CWideChar', 'ExtendedGraphemeClusterType', 'Float32', 'Float64',
-                'FloatLiteralType', 'IntMax', 'IntegerLiteralType', 'StringLiteralType',
-                'UIntMax', 'UWord', 'UnicodeScalarType', 'Void', 'Word',
-                # Foundation/Cocoa
-                'NSErrorPointer', 'NSObjectProtocol', 'Selector'), suffix=r'\b'),
-             Name.Builtin),
-            # Functions
-            (words((
-                'abs', 'advance', 'alignof', 'alignofValue', 'assert', 'assertionFailure',
-                'contains', 'count', 'countElements', 'debugPrint', 'debugPrintln',
-                'distance', 'dropFirst', 'dropLast', 'dump', 'enumerate', 'equal',
-                'extend', 'fatalError', 'filter', 'find', 'first', 'getVaList', 'indices',
-                'insert', 'isEmpty', 'join', 'last', 'lazy', 'lexicographicalCompare',
-                'map', 'max', 'maxElement', 'min', 'minElement', 'numericCast', 'overlaps',
-                'partition', 'precondition', 'preconditionFailure', 'prefix', 'print',
-                'println', 'reduce', 'reflect', 'removeAll', 'removeAtIndex', 'removeLast',
-                'removeRange', 'reverse', 'sizeof', 'sizeofValue', 'sort', 'sorted',
-                'splice', 'split', 'startsWith', 'stride', 'strideof', 'strideofValue',
-                'suffix', 'swap', 'toDebugString', 'toString', 'transcode',
-                'underestimateCount', 'unsafeAddressOf', 'unsafeBitCast', 'unsafeDowncast',
-                'withExtendedLifetime', 'withUnsafeMutablePointer',
-                'withUnsafeMutablePointers', 'withUnsafePointer', 'withUnsafePointers',
-                'withVaList'), suffix=r'\b'),
-             Name.Builtin.Pseudo),
-
-            # Implicit Block Variables
-            (r'\$\d+', Name.Variable),
-
-            # Binary Literal
-            (r'0b[01_]+', Number.Bin),
-            # Octal Literal
-            (r'0o[0-7_]+', Number.Oct),
-            # Hexadecimal Literal
-            (r'0x[0-9a-fA-F_]+', Number.Hex),
-            # Decimal Literal
-            (r'[0-9][0-9_]*(\.[0-9_]+[eE][+\-]?[0-9_]+|'
-             r'\.[0-9_]*|[eE][+\-]?[0-9_]+)', Number.Float),
-            (r'[0-9][0-9_]*', Number.Integer),
-            # String Literal
-            (r'"""', String, 'string-multi'),
-            (r'"', String, 'string'),
-
-            # Operators and Punctuation
-            (r'[(){}\[\].,:;=@#`?]|->|[<&?](?=\w)|(?<=\w)[>!?]', Punctuation),
-            (r'[/=\-+!*%<>&|^?~]+', Operator),
-
-            # Identifier
-            (r'[a-zA-Z_]\w*', Name)
-        ],
-        'keywords': [
-            (words((
-                'as', 'async', 'await', 'break', 'case', 'catch', 'continue', 'default', 'defer',
-                'do', 'else', 'fallthrough', 'for', 'guard', 'if', 'in', 'is',
-                'repeat', 'return', '#selector', 'switch', 'throw', 'try',
-                'where', 'while'), suffix=r'\b'),
-             Keyword),
-            (r'@availability\([^)]+\)', Keyword.Reserved),
-            (words((
-                'associativity', 'convenience', 'dynamic', 'didSet', 'final',
-                'get', 'indirect', 'infix', 'inout', 'lazy', 'left', 'mutating',
-                'none', 'nonmutating', 'optional', 'override', 'postfix',
-                'precedence', 'prefix', 'Protocol', 'required', 'rethrows',
-                'right', 'set', 'throws', 'Type', 'unowned', 'weak', 'willSet',
-                '@availability', '@autoclosure', '@noreturn',
-                '@NSApplicationMain', '@NSCopying', '@NSManaged', '@objc',
-                '@UIApplicationMain', '@IBAction', '@IBDesignable',
-                '@IBInspectable', '@IBOutlet'), suffix=r'\b'),
-             Keyword.Reserved),
-            (r'(as|dynamicType|false|is|nil|self|Self|super|true|__COLUMN__'
-             r'|__FILE__|__FUNCTION__|__LINE__|_'
-             r'|#(?:file|line|column|function))\b', Keyword.Constant),
-            (r'import\b', Keyword.Declaration, 'module'),
-            (r'(class|enum|extension|struct|protocol)(\s+)([a-zA-Z_]\w*)',
-             bygroups(Keyword.Declaration, Whitespace, Name.Class)),
-            (r'(func)(\s+)([a-zA-Z_]\w*)',
-             bygroups(Keyword.Declaration, Whitespace, Name.Function)),
-            (r'(var|let)(\s+)([a-zA-Z_]\w*)', bygroups(Keyword.Declaration,
-             Whitespace, Name.Variable)),
-            (words((
-                'actor', 'associatedtype', 'class', 'deinit', 'enum', 'extension', 'func', 'import',
-                'init', 'internal', 'let', 'operator', 'private', 'protocol', 'public',
-                'static', 'struct', 'subscript', 'typealias', 'var'), suffix=r'\b'),
-             Keyword.Declaration)
-        ],
-        'comment': [
-            (r':param: [a-zA-Z_]\w*|:returns?:|(FIXME|MARK|TODO):',
-             Comment.Special)
-        ],
-
-        # Nested
-        'comment-single': [
-            (r'\n', Whitespace, '#pop'),
-            include('comment'),
-            (r'[^\n]+', Comment.Single)
-        ],
-        'comment-multi': [
-            include('comment'),
-            (r'[^*/]+', Comment.Multiline),
-            (r'/\*', Comment.Multiline, '#push'),
-            (r'\*/', Comment.Multiline, '#pop'),
-            (r'[*/]+', Comment.Multiline)
-        ],
-        'module': [
-            (r'\n', Whitespace, '#pop'),
-            (r'[a-zA-Z_]\w*', Name.Class),
-            include('root')
-        ],
-        'preproc': [
-            (r'\n', Whitespace, '#pop'),
-            include('keywords'),
-            (r'[A-Za-z]\w*', Comment.Preproc),
-            include('root')
-        ],
-        'string': [
-            (r'"', String, '#pop'),
-            include("string-common"),
-        ],
-        'string-multi': [
-            (r'"""', String, '#pop'),
-            include("string-common"),
-        ],
-        'string-common': [
-            (r'\\\(', String.Interpol, 'string-intp'),
-            (r"""\\['"\\nrt]|\\x[0-9a-fA-F]{2}|\\[0-7]{1,3}"""
-             r"""|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}""", String.Escape),
-            (r'[^\\"]+', String),
-            (r'\\', String)
-        ],
-        'string-intp': [
-            (r'\(', String.Interpol, '#push'),
-            (r'\)', String.Interpol, '#pop'),
-            include('root')
-        ]
-    }
-
-    def get_tokens_unprocessed(self, text):
-        from pygments.lexers._cocoa_builtins import COCOA_INTERFACES, \
-            COCOA_PROTOCOLS, COCOA_PRIMITIVES
-
-        for index, token, value in \
-                RegexLexer.get_tokens_unprocessed(self, text):
-            if token is Name or token is Name.Class:
-                if value in COCOA_INTERFACES or value in COCOA_PROTOCOLS \
-                   or value in COCOA_PRIMITIVES:
-                    token = Name.Builtin.Pseudo
-
-            yield index, token, value
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/ooc.py b/.venv/lib/python3.12/site-packages/pygments/lexers/ooc.py
deleted file mode 100644
index f6aea8c..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/ooc.py
+++ /dev/null
@@ -1,84 +0,0 @@
-"""
-    pygments.lexers.ooc
-    ~~~~~~~~~~~~~~~~~~~
-
-    Lexers for the Ooc language.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-from pygments.lexer import RegexLexer, bygroups, words
-from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
-    Number, Punctuation
-
-__all__ = ['OocLexer']
-
-
-class OocLexer(RegexLexer):
-    """
-    For Ooc source code
-    """
-    name = 'Ooc'
-    url = 'https://ooc-lang.github.io/'
-    aliases = ['ooc']
-    filenames = ['*.ooc']
-    mimetypes = ['text/x-ooc']
-    version_added = '1.2'
-
-    tokens = {
-        'root': [
-            (words((
-                'class', 'interface', 'implement', 'abstract', 'extends', 'from',
-                'this', 'super', 'new', 'const', 'final', 'static', 'import',
-                'use', 'extern', 'inline', 'proto', 'break', 'continue',
-                'fallthrough', 'operator', 'if', 'else', 'for', 'while', 'do',
-                'switch', 'case', 'as', 'in', 'version', 'return', 'true',
-                'false', 'null'), prefix=r'\b', suffix=r'\b'),
-             Keyword),
-            (r'include\b', Keyword, 'include'),
-            (r'(cover)([ \t]+)(from)([ \t]+)(\w+[*@]?)',
-             bygroups(Keyword, Text, Keyword, Text, Name.Class)),
-            (r'(func)((?:[ \t]|\\\n)+)(~[a-z_]\w*)',
-             bygroups(Keyword, Text, Name.Function)),
-            (r'\bfunc\b', Keyword),
-            # Note: %= not listed on https://ooc-lang.github.io/docs/lang/operators/
-            (r'//.*', Comment),
-            (r'(?s)/\*.*?\*/', Comment.Multiline),
-            (r'(==?|\+=?|-[=>]?|\*=?|/=?|:=|!=?|%=?|\?|>{1,3}=?|<{1,3}=?|\.\.|'
-             r'&&?|\|\|?|\^=?)', Operator),
-            (r'(\.)([ \t]*)([a-z]\w*)', bygroups(Operator, Text,
-                                                 Name.Function)),
-            (r'[A-Z][A-Z0-9_]+', Name.Constant),
-            (r'[A-Z]\w*([@*]|\[[ \t]*\])?', Name.Class),
-
-            (r'([a-z]\w*(?:~[a-z]\w*)?)((?:[ \t]|\\\n)*)(?=\()',
-             bygroups(Name.Function, Text)),
-            (r'[a-z]\w*', Name.Variable),
-
-            # : introduces types
-            (r'[:(){}\[\];,]', Punctuation),
-
-            (r'0x[0-9a-fA-F]+', Number.Hex),
-            (r'0c[0-9]+', Number.Oct),
-            (r'0b[01]+', Number.Bin),
-            (r'[0-9_]\.[0-9_]*(?!\.)', Number.Float),
-            (r'[0-9_]+', Number.Decimal),
-
-            (r'"(?:\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\"])*"',
-             String.Double),
-            (r"'(?:\\.|\\[0-9]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'",
-             String.Char),
-            (r'@', Punctuation),  # pointer dereference
-            (r'\.', Punctuation),  # imports or chain operator
-
-            (r'\\[ \t\n]', Text),
-            (r'[ \t]+', Text),
-        ],
-        'include': [
-            (r'[\w/]+', Name),
-            (r',', Punctuation),
-            (r'[ \t]', Text),
-            (r'[;\n]', Text, '#pop'),
-        ],
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/openscad.py b/.venv/lib/python3.12/site-packages/pygments/lexers/openscad.py
deleted file mode 100644
index 1ec8fea..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/openscad.py
+++ /dev/null
@@ -1,96 +0,0 @@
-"""
-    pygments.lexers.openscad
-    ~~~~~~~~~~~~~~~~~~~~~~~~
-
-    Lexers for the OpenSCAD languages.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-from pygments.lexer import RegexLexer, bygroups, words, include
-from pygments.token import Text, Comment, Punctuation, Operator, Keyword, Name, Number, Whitespace, Literal, String
-
-__all__ = ['OpenScadLexer']
-
-
-class OpenScadLexer(RegexLexer):
-    """For openSCAD code.
-    """
-    name = "OpenSCAD"
-    url = "https://openscad.org/"
-    aliases = ["openscad"]
-    filenames = ["*.scad"]
-    mimetypes = ["application/x-openscad"]
-    version_added = '2.16'
-
-    tokens = {
-        "root": [
-            (r"[^\S\n]+", Whitespace),
-            (r'//', Comment.Single, 'comment-single'),
-            (r'/\*', Comment.Multiline, 'comment-multi'),
-            (r"[{}\[\]\(\),;:]", Punctuation),
-            (r"[*!#%\-+=?/]", Operator),
-            (r"<=|<|==|!=|>=|>|&&|\|\|", Operator),
-            (r"\$(f[asn]|t|vp[rtd]|children)", Operator),
-            (r"(undef|PI)\b", Keyword.Constant),
-            (
-                r"(use|include)((?:\s|\\\\s)+)",
-                bygroups(Keyword.Namespace, Text),
-                "includes",
-            ),
-            (r"(module)(\s*)([^\s\(]+)",
-             bygroups(Keyword.Namespace, Whitespace, Name.Namespace)),
-            (r"(function)(\s*)([^\s\(]+)",
-             bygroups(Keyword.Declaration, Whitespace, Name.Function)),
-            (words(("true", "false"), prefix=r"\b", suffix=r"\b"), Literal),
-            (words((
-                "function", "module", "include", "use", "for",
-                "intersection_for", "if", "else", "return"
-                ), prefix=r"\b", suffix=r"\b"), Keyword
-            ),
-            (words((
-                "circle", "square", "polygon", "text", "sphere", "cube",
-                "cylinder", "polyhedron", "translate", "rotate", "scale",
-                "resize", "mirror", "multmatrix", "color", "offset", "hull",
-                "minkowski", "union", "difference", "intersection", "abs",
-                "sign", "sin", "cos", "tan", "acos", "asin", "atan", "atan2",
-                "floor", "round", "ceil", "ln", "log", "pow", "sqrt", "exp",
-                "rands", "min", "max", "concat", "lookup", "str", "chr",
-                "search", "version", "version_num", "norm", "cross",
-                "parent_module", "echo", "import", "import_dxf",
-                "dxf_linear_extrude", "linear_extrude", "rotate_extrude",
-                "surface", "projection", "render", "dxf_cross",
-                "dxf_dim", "let", "assign", "len"
-                ), prefix=r"\b", suffix=r"\b"),
-                Name.Builtin
-            ),
-            (r"\bchildren\b", Name.Builtin.Pseudo),
-            (r'""".*?"""', String.Double),
-            (r'"(\\\\|\\[^\\]|[^"\\])*"', String.Double),
-            (r"-?\d+(\.\d+)?(e[+-]?\d+)?", Number),
-            (r"\w+", Name),
-        ],
-        "includes": [
-            (
-                r"(<)([^>]*)(>)",
-                bygroups(Punctuation, Comment.PreprocFile, Punctuation),
-            ),
-        ],
-        'comment': [
-            (r':param: [a-zA-Z_]\w*|:returns?:|(FIXME|MARK|TODO):',
-             Comment.Special)
-        ],
-        'comment-single': [
-            (r'\n', Text, '#pop'),
-            include('comment'),
-            (r'[^\n]+', Comment.Single)
-        ],
-        'comment-multi': [
-            include('comment'),
-            (r'[^*/]+', Comment.Multiline),
-            (r'/\*', Comment.Multiline, '#push'),
-            (r'\*/', Comment.Multiline, '#pop'),
-            (r'[*/]', Comment.Multiline)
-        ],
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/other.py b/.venv/lib/python3.12/site-packages/pygments/lexers/other.py
deleted file mode 100644
index 8767d73..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/other.py
+++ /dev/null
@@ -1,41 +0,0 @@
-"""
-    pygments.lexers.other
-    ~~~~~~~~~~~~~~~~~~~~~
-
-    Just export lexer classes previously contained in this module.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-# ruff: noqa: F401
-from pygments.lexers.sql import SqlLexer, MySqlLexer, SqliteConsoleLexer
-from pygments.lexers.shell import BashLexer, BashSessionLexer, BatchLexer, \
-    TcshLexer
-from pygments.lexers.robotframework import RobotFrameworkLexer
-from pygments.lexers.testing import GherkinLexer
-from pygments.lexers.esoteric import BrainfuckLexer, BefungeLexer, RedcodeLexer
-from pygments.lexers.prolog import LogtalkLexer
-from pygments.lexers.snobol import SnobolLexer
-from pygments.lexers.rebol import RebolLexer
-from pygments.lexers.configs import KconfigLexer, Cfengine3Lexer
-from pygments.lexers.modeling import ModelicaLexer
-from pygments.lexers.scripting import AppleScriptLexer, MOOCodeLexer, \
-    HybrisLexer
-from pygments.lexers.graphics import PostScriptLexer, GnuplotLexer, \
-    AsymptoteLexer, PovrayLexer
-from pygments.lexers.business import ABAPLexer, OpenEdgeLexer, \
-    GoodDataCLLexer, MaqlLexer
-from pygments.lexers.automation import AutoItLexer, AutohotkeyLexer
-from pygments.lexers.dsls import ProtoBufLexer, BroLexer, PuppetLexer, \
-    MscgenLexer, VGLLexer
-from pygments.lexers.basic import CbmBasicV2Lexer
-from pygments.lexers.pawn import SourcePawnLexer, PawnLexer
-from pygments.lexers.ecl import ECLLexer
-from pygments.lexers.urbi import UrbiscriptLexer
-from pygments.lexers.smalltalk import SmalltalkLexer, NewspeakLexer
-from pygments.lexers.installers import NSISLexer, RPMSpecLexer
-from pygments.lexers.textedit import AwkLexer
-from pygments.lexers.smv import NuSMVLexer
-
-__all__ = []
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/parasail.py b/.venv/lib/python3.12/site-packages/pygments/lexers/parasail.py
deleted file mode 100644
index 9b40960..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/parasail.py
+++ /dev/null
@@ -1,78 +0,0 @@
-"""
-    pygments.lexers.parasail
-    ~~~~~~~~~~~~~~~~~~~~~~~~
-
-    Lexer for ParaSail.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-import re
-
-from pygments.lexer import RegexLexer, include
-from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
-    Number, Punctuation, Literal
-
-__all__ = ['ParaSailLexer']
-
-
-class ParaSailLexer(RegexLexer):
-    """
-    For ParaSail source code.
-    """
-
-    name = 'ParaSail'
-    url = 'http://www.parasail-lang.org'
-    aliases = ['parasail']
-    filenames = ['*.psi', '*.psl']
-    mimetypes = ['text/x-parasail']
-    version_added = '2.1'
-
-    flags = re.MULTILINE
-
-    tokens = {
-        'root': [
-            (r'[^\S\n]+', Text),
-            (r'//.*?\n', Comment.Single),
-            (r'\b(and|or|xor)=', Operator.Word),
-            (r'\b(and(\s+then)?|or(\s+else)?|xor|rem|mod|'
-             r'(is|not)\s+null)\b',
-             Operator.Word),
-            # Keywords
-            (r'\b(abs|abstract|all|block|class|concurrent|const|continue|'
-             r'each|end|exit|extends|exports|forward|func|global|implements|'
-             r'import|in|interface|is|lambda|locked|new|not|null|of|op|'
-             r'optional|private|queued|ref|return|reverse|separate|some|'
-             r'type|until|var|with|'
-             # Control flow
-             r'if|then|else|elsif|case|for|while|loop)\b',
-             Keyword.Reserved),
-            (r'(abstract\s+)?(interface|class|op|func|type)',
-             Keyword.Declaration),
-            # Literals
-            (r'"[^"]*"', String),
-            (r'\\[\'ntrf"0]', String.Escape),
-            (r'#[a-zA-Z]\w*', Literal),       # Enumeration
-            include('numbers'),
-            (r"'[^']'", String.Char),
-            (r'[a-zA-Z]\w*', Name),
-            # Operators and Punctuation
-            (r'(<==|==>|<=>|\*\*=|<\|=|<<=|>>=|==|!=|=\?|<=|>=|'
-             r'\*\*|<<|>>|=>|:=|\+=|-=|\*=|\|=|\||/=|\+|-|\*|/|'
-             r'\.\.|<\.\.|\.\.<|<\.\.<)',
-             Operator),
-            (r'(<|>|\[|\]|\(|\)|\||:|;|,|.|\{|\}|->)',
-             Punctuation),
-            (r'\n+', Text),
-        ],
-        'numbers': [
-            (r'\d[0-9_]*#[0-9a-fA-F][0-9a-fA-F_]*#', Number.Hex),  # any base
-            (r'0[xX][0-9a-fA-F][0-9a-fA-F_]*', Number.Hex),        # C-like hex
-            (r'0[bB][01][01_]*', Number.Bin),                      # C-like bin
-            (r'\d[0-9_]*\.\d[0-9_]*[eE][+-]\d[0-9_]*',             # float exp
-             Number.Float),
-            (r'\d[0-9_]*\.\d[0-9_]*', Number.Float),               # float
-            (r'\d[0-9_]*', Number.Integer),                        # integer
-        ],
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/parsers.py b/.venv/lib/python3.12/site-packages/pygments/lexers/parsers.py
deleted file mode 100644
index baa49b0..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/parsers.py
+++ /dev/null
@@ -1,798 +0,0 @@
-"""
-    pygments.lexers.parsers
-    ~~~~~~~~~~~~~~~~~~~~~~~
-
-    Lexers for parser generators.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-import re
-
-from pygments.lexer import RegexLexer, DelegatingLexer, \
-    include, bygroups, using
-from pygments.token import Punctuation, Other, Text, Comment, Operator, \
-    Keyword, Name, String, Number, Whitespace
-from pygments.lexers.jvm import JavaLexer
-from pygments.lexers.c_cpp import CLexer, CppLexer
-from pygments.lexers.objective import ObjectiveCLexer
-from pygments.lexers.d import DLexer
-from pygments.lexers.dotnet import CSharpLexer
-from pygments.lexers.ruby import RubyLexer
-from pygments.lexers.python import PythonLexer
-from pygments.lexers.perl import PerlLexer
-
-__all__ = ['RagelLexer', 'RagelEmbeddedLexer', 'RagelCLexer', 'RagelDLexer',
-           'RagelCppLexer', 'RagelObjectiveCLexer', 'RagelRubyLexer',
-           'RagelJavaLexer', 'AntlrLexer', 'AntlrPythonLexer',
-           'AntlrPerlLexer', 'AntlrRubyLexer', 'AntlrCppLexer',
-           'AntlrCSharpLexer', 'AntlrObjectiveCLexer',
-           'AntlrJavaLexer', 'AntlrActionScriptLexer',
-           'TreetopLexer', 'EbnfLexer']
-
-
-class RagelLexer(RegexLexer):
-    """A pure `Ragel `_ lexer.
-
-    Use this for fragments of Ragel.  For ``.rl`` files, use
-    :class:`RagelEmbeddedLexer` instead (or one of the language-specific
-    subclasses).
-    """
-
-    name = 'Ragel'
-    url = 'http://www.colm.net/open-source/ragel/'
-    aliases = ['ragel']
-    filenames = []
-    version_added = '1.1'
-
-    tokens = {
-        'whitespace': [
-            (r'\s+', Whitespace)
-        ],
-        'comments': [
-            (r'\#.*$', Comment),
-        ],
-        'keywords': [
-            (r'(access|action|alphtype)\b', Keyword),
-            (r'(getkey|write|machine|include)\b', Keyword),
-            (r'(any|ascii|extend|alpha|digit|alnum|lower|upper)\b', Keyword),
-            (r'(xdigit|cntrl|graph|print|punct|space|zlen|empty)\b', Keyword)
-        ],
-        'numbers': [
-            (r'0x[0-9A-Fa-f]+', Number.Hex),
-            (r'[+-]?[0-9]+', Number.Integer),
-        ],
-        'literals': [
-            (r'"(\\\\|\\[^\\]|[^"\\])*"', String.Double),
-            (r"'(\\\\|\\[^\\]|[^'\\])*'", String.Single),
-            (r'\[(\\\\|\\[^\\]|[^\\\]])*\]', String),          # square bracket literals
-            (r'/(?!\*)(\\\\|\\[^\\]|[^/\\])*/', String.Regex),  # regular expressions
-        ],
-        'identifiers': [
-            (r'[a-zA-Z_]\w*', Name.Variable),
-        ],
-        'operators': [
-            (r',', Operator),                           # Join
-            (r'\||&|--?', Operator),                    # Union, Intersection and Subtraction
-            (r'\.|<:|:>>?', Operator),                  # Concatention
-            (r':', Operator),                           # Label
-            (r'->', Operator),                          # Epsilon Transition
-            (r'(>|\$|%|<|@|<>)(/|eof\b)', Operator),    # EOF Actions
-            (r'(>|\$|%|<|@|<>)(!|err\b)', Operator),    # Global Error Actions
-            (r'(>|\$|%|<|@|<>)(\^|lerr\b)', Operator),  # Local Error Actions
-            (r'(>|\$|%|<|@|<>)(~|to\b)', Operator),     # To-State Actions
-            (r'(>|\$|%|<|@|<>)(\*|from\b)', Operator),  # From-State Actions
-            (r'>|@|\$|%', Operator),                    # Transition Actions and Priorities
-            (r'\*|\?|\+|\{[0-9]*,[0-9]*\}', Operator),  # Repetition
-            (r'!|\^', Operator),                        # Negation
-            (r'\(|\)', Operator),                       # Grouping
-        ],
-        'root': [
-            include('literals'),
-            include('whitespace'),
-            include('comments'),
-            include('keywords'),
-            include('numbers'),
-            include('identifiers'),
-            include('operators'),
-            (r'\{', Punctuation, 'host'),
-            (r'=', Operator),
-            (r';', Punctuation),
-        ],
-        'host': [
-            (r'(' + r'|'.join((  # keep host code in largest possible chunks
-                r'[^{}\'"/#]+',  # exclude unsafe characters
-                r'[^\\]\\[{}]',  # allow escaped { or }
-
-                # strings and comments may safely contain unsafe characters
-                r'"(\\\\|\\[^\\]|[^"\\])*"',
-                r"'(\\\\|\\[^\\]|[^'\\])*'",
-                r'//.*$\n?',            # single line comment
-                r'/\*(.|\n)*?\*/',      # multi-line javadoc-style comment
-                r'\#.*$\n?',            # ruby comment
-
-                # regular expression: There's no reason for it to start
-                # with a * and this stops confusion with comments.
-                r'/(?!\*)(\\\\|\\[^\\]|[^/\\])*/',
-
-                # / is safe now that we've handled regex and javadoc comments
-                r'/',
-            )) + r')+', Other),
-
-            (r'\{', Punctuation, '#push'),
-            (r'\}', Punctuation, '#pop'),
-        ],
-    }
-
-
-class RagelEmbeddedLexer(RegexLexer):
-    """
-    A lexer for Ragel embedded in a host language file.
-
-    This will only highlight Ragel statements. If you want host language
-    highlighting then call the language-specific Ragel lexer.
-    """
-
-    name = 'Embedded Ragel'
-    aliases = ['ragel-em']
-    filenames = ['*.rl']
-    url = 'http://www.colm.net/open-source/ragel/'
-    version_added = '1.1'
-
-    tokens = {
-        'root': [
-            (r'(' + r'|'.join((   # keep host code in largest possible chunks
-                r'[^%\'"/#]+',    # exclude unsafe characters
-                r'%(?=[^%]|$)',   # a single % sign is okay, just not 2 of them
-
-                # strings and comments may safely contain unsafe characters
-                r'"(\\\\|\\[^\\]|[^"\\])*"',
-                r"'(\\\\|\\[^\\]|[^'\\])*'",
-                r'/\*(.|\n)*?\*/',      # multi-line javadoc-style comment
-                r'//.*$\n?',  # single line comment
-                r'\#.*$\n?',  # ruby/ragel comment
-                r'/(?!\*)(\\\\|\\[^\\]|[^/\\])*/',  # regular expression
-
-                # / is safe now that we've handled regex and javadoc comments
-                r'/',
-            )) + r')+', Other),
-
-            # Single Line FSM.
-            # Please don't put a quoted newline in a single line FSM.
-            # That's just mean. It will break this.
-            (r'(%%)(?![{%])(.*)($|;)(\n?)', bygroups(Punctuation,
-                                                     using(RagelLexer),
-                                                     Punctuation, Text)),
-
-            # Multi Line FSM.
-            (r'(%%%%|%%)\{', Punctuation, 'multi-line-fsm'),
-        ],
-        'multi-line-fsm': [
-            (r'(' + r'|'.join((  # keep ragel code in largest possible chunks.
-                r'(' + r'|'.join((
-                    r'[^}\'"\[/#]',   # exclude unsafe characters
-                    r'\}(?=[^%]|$)',   # } is okay as long as it's not followed by %
-                    r'\}%(?=[^%]|$)',  # ...well, one %'s okay, just not two...
-                    r'[^\\]\\[{}]',   # ...and } is okay if it's escaped
-
-                    # allow / if it's preceded with one of these symbols
-                    # (ragel EOF actions)
-                    r'(>|\$|%|<|@|<>)/',
-
-                    # specifically allow regex followed immediately by *
-                    # so it doesn't get mistaken for a comment
-                    r'/(?!\*)(\\\\|\\[^\\]|[^/\\])*/\*',
-
-                    # allow / as long as it's not followed by another / or by a *
-                    r'/(?=[^/*]|$)',
-
-                    # We want to match as many of these as we can in one block.
-                    # Not sure if we need the + sign here,
-                    # does it help performance?
-                )) + r')+',
-
-                # strings and comments may safely contain unsafe characters
-                r'"(\\\\|\\[^\\]|[^"\\])*"',
-                r"'(\\\\|\\[^\\]|[^'\\])*'",
-                r"\[(\\\\|\\[^\\]|[^\]\\])*\]",  # square bracket literal
-                r'/\*(.|\n)*?\*/',          # multi-line javadoc-style comment
-                r'//.*$\n?',                # single line comment
-                r'\#.*$\n?',                # ruby/ragel comment
-            )) + r')+', using(RagelLexer)),
-
-            (r'\}%%', Punctuation, '#pop'),
-        ]
-    }
-
-    def analyse_text(text):
-        return '@LANG: indep' in text
-
-
-class RagelRubyLexer(DelegatingLexer):
-    """
-    A lexer for Ragel in a Ruby host file.
-    """
-
-    name = 'Ragel in Ruby Host'
-    aliases = ['ragel-ruby', 'ragel-rb']
-    filenames = ['*.rl']
-    url = 'http://www.colm.net/open-source/ragel/'
-    version_added = '1.1'
-
-    def __init__(self, **options):
-        super().__init__(RubyLexer, RagelEmbeddedLexer, **options)
-
-    def analyse_text(text):
-        return '@LANG: ruby' in text
-
-
-class RagelCLexer(DelegatingLexer):
-    """
-    A lexer for Ragel in a C host file.
-    """
-
-    name = 'Ragel in C Host'
-    aliases = ['ragel-c']
-    filenames = ['*.rl']
-    url = 'http://www.colm.net/open-source/ragel/'
-    version_added = '1.1'
-
-    def __init__(self, **options):
-        super().__init__(CLexer, RagelEmbeddedLexer, **options)
-
-    def analyse_text(text):
-        return '@LANG: c' in text
-
-
-class RagelDLexer(DelegatingLexer):
-    """
-    A lexer for Ragel in a D host file.
-    """
-
-    name = 'Ragel in D Host'
-    aliases = ['ragel-d']
-    filenames = ['*.rl']
-    url = 'http://www.colm.net/open-source/ragel/'
-    version_added = '1.1'
-
-    def __init__(self, **options):
-        super().__init__(DLexer, RagelEmbeddedLexer, **options)
-
-    def analyse_text(text):
-        return '@LANG: d' in text
-
-
-class RagelCppLexer(DelegatingLexer):
-    """
-    A lexer for Ragel in a C++ host file.
-    """
-
-    name = 'Ragel in CPP Host'
-    aliases = ['ragel-cpp']
-    filenames = ['*.rl']
-    url = 'http://www.colm.net/open-source/ragel/'
-    version_added = '1.1'
-
-    def __init__(self, **options):
-        super().__init__(CppLexer, RagelEmbeddedLexer, **options)
-
-    def analyse_text(text):
-        return '@LANG: c++' in text
-
-
-class RagelObjectiveCLexer(DelegatingLexer):
-    """
-    A lexer for Ragel in an Objective C host file.
-    """
-
-    name = 'Ragel in Objective C Host'
-    aliases = ['ragel-objc']
-    filenames = ['*.rl']
-    url = 'http://www.colm.net/open-source/ragel/'
-    version_added = '1.1'
-
-    def __init__(self, **options):
-        super().__init__(ObjectiveCLexer, RagelEmbeddedLexer, **options)
-
-    def analyse_text(text):
-        return '@LANG: objc' in text
-
-
-class RagelJavaLexer(DelegatingLexer):
-    """
-    A lexer for Ragel in a Java host file.
-    """
-
-    name = 'Ragel in Java Host'
-    aliases = ['ragel-java']
-    filenames = ['*.rl']
-    url = 'http://www.colm.net/open-source/ragel/'
-    version_added = '1.1'
-
-    def __init__(self, **options):
-        super().__init__(JavaLexer, RagelEmbeddedLexer, **options)
-
-    def analyse_text(text):
-        return '@LANG: java' in text
-
-
-class AntlrLexer(RegexLexer):
-    """
-    Generic ANTLR Lexer.
-    Should not be called directly, instead
-    use DelegatingLexer for your target language.
-    """
-
-    name = 'ANTLR'
-    aliases = ['antlr']
-    filenames = []
-    url = 'https://www.antlr.org'
-    version_added = '1.1'
-
-    _id = r'[A-Za-z]\w*'
-    _TOKEN_REF = r'[A-Z]\w*'
-    _RULE_REF = r'[a-z]\w*'
-    _STRING_LITERAL = r'\'(?:\\\\|\\\'|[^\']*)\''
-    _INT = r'[0-9]+'
-
-    tokens = {
-        'whitespace': [
-            (r'\s+', Whitespace),
-        ],
-        'comments': [
-            (r'//.*$', Comment),
-            (r'/\*(.|\n)*?\*/', Comment),
-        ],
-        'root': [
-            include('whitespace'),
-            include('comments'),
-
-            (r'(lexer|parser|tree)?(\s*)(grammar\b)(\s*)(' + _id + ')(;)',
-             bygroups(Keyword, Whitespace, Keyword, Whitespace, Name.Class,
-                      Punctuation)),
-            # optionsSpec
-            (r'options\b', Keyword, 'options'),
-            # tokensSpec
-            (r'tokens\b', Keyword, 'tokens'),
-            # attrScope
-            (r'(scope)(\s*)(' + _id + r')(\s*)(\{)',
-             bygroups(Keyword, Whitespace, Name.Variable, Whitespace,
-                      Punctuation), 'action'),
-            # exception
-            (r'(catch|finally)\b', Keyword, 'exception'),
-            # action
-            (r'(@' + _id + r')(\s*)(::)?(\s*)(' + _id + r')(\s*)(\{)',
-             bygroups(Name.Label, Whitespace, Punctuation, Whitespace,
-                      Name.Label, Whitespace, Punctuation), 'action'),
-            # rule
-            (r'((?:protected|private|public|fragment)\b)?(\s*)(' + _id + ')(!)?',
-             bygroups(Keyword, Whitespace, Name.Label, Punctuation),
-             ('rule-alts', 'rule-prelims')),
-        ],
-        'exception': [
-            (r'\n', Whitespace, '#pop'),
-            (r'\s', Whitespace),
-            include('comments'),
-
-            (r'\[', Punctuation, 'nested-arg-action'),
-            (r'\{', Punctuation, 'action'),
-        ],
-        'rule-prelims': [
-            include('whitespace'),
-            include('comments'),
-
-            (r'returns\b', Keyword),
-            (r'\[', Punctuation, 'nested-arg-action'),
-            (r'\{', Punctuation, 'action'),
-            # throwsSpec
-            (r'(throws)(\s+)(' + _id + ')',
-             bygroups(Keyword, Whitespace, Name.Label)),
-            (r'(,)(\s*)(' + _id + ')',
-             bygroups(Punctuation, Whitespace, Name.Label)),  # Additional throws
-            # optionsSpec
-            (r'options\b', Keyword, 'options'),
-            # ruleScopeSpec - scope followed by target language code or name of action
-            # TODO finish implementing other possibilities for scope
-            # L173 ANTLRv3.g from ANTLR book
-            (r'(scope)(\s+)(\{)', bygroups(Keyword, Whitespace, Punctuation),
-             'action'),
-            (r'(scope)(\s+)(' + _id + r')(\s*)(;)',
-             bygroups(Keyword, Whitespace, Name.Label, Whitespace, Punctuation)),
-            # ruleAction
-            (r'(@' + _id + r')(\s*)(\{)',
-             bygroups(Name.Label, Whitespace, Punctuation), 'action'),
-            # finished prelims, go to rule alts!
-            (r':', Punctuation, '#pop')
-        ],
-        'rule-alts': [
-            include('whitespace'),
-            include('comments'),
-
-            # These might need to go in a separate 'block' state triggered by (
-            (r'options\b', Keyword, 'options'),
-            (r':', Punctuation),
-
-            # literals
-            (r'"(\\\\|\\[^\\]|[^"\\])*"', String.Double),
-            (r"'(\\\\|\\[^\\]|[^'\\])*'", String.Single),
-            (r'<<([^>]|>[^>])>>', String),
-            # identifiers
-            # Tokens start with capital letter.
-            (r'\$?[A-Z_]\w*', Name.Constant),
-            # Rules start with small letter.
-            (r'\$?[a-z_]\w*', Name.Variable),
-            # operators
-            (r'(\+|\||->|=>|=|\(|\)|\.\.|\.|\?|\*|\^|!|\#|~)', Operator),
-            (r',', Punctuation),
-            (r'\[', Punctuation, 'nested-arg-action'),
-            (r'\{', Punctuation, 'action'),
-            (r';', Punctuation, '#pop')
-        ],
-        'tokens': [
-            include('whitespace'),
-            include('comments'),
-            (r'\{', Punctuation),
-            (r'(' + _TOKEN_REF + r')(\s*)(=)?(\s*)(' + _STRING_LITERAL
-             + r')?(\s*)(;)',
-             bygroups(Name.Label, Whitespace, Punctuation, Whitespace,
-                      String, Whitespace, Punctuation)),
-            (r'\}', Punctuation, '#pop'),
-        ],
-        'options': [
-            include('whitespace'),
-            include('comments'),
-            (r'\{', Punctuation),
-            (r'(' + _id + r')(\s*)(=)(\s*)(' +
-             '|'.join((_id, _STRING_LITERAL, _INT, r'\*')) + r')(\s*)(;)',
-             bygroups(Name.Variable, Whitespace, Punctuation, Whitespace,
-                      Text, Whitespace, Punctuation)),
-            (r'\}', Punctuation, '#pop'),
-        ],
-        'action': [
-            (r'(' + r'|'.join((    # keep host code in largest possible chunks
-                r'[^${}\'"/\\]+',  # exclude unsafe characters
-
-                # strings and comments may safely contain unsafe characters
-                r'"(\\\\|\\[^\\]|[^"\\])*"',
-                r"'(\\\\|\\[^\\]|[^'\\])*'",
-                r'//.*$\n?',            # single line comment
-                r'/\*(.|\n)*?\*/',      # multi-line javadoc-style comment
-
-                # regular expression: There's no reason for it to start
-                # with a * and this stops confusion with comments.
-                r'/(?!\*)(\\\\|\\[^\\]|[^/\\])*/',
-
-                # backslashes are okay, as long as we are not backslashing a %
-                r'\\(?!%)',
-
-                # Now that we've handled regex and javadoc comments
-                # it's safe to let / through.
-                r'/',
-            )) + r')+', Other),
-            (r'(\\)(%)', bygroups(Punctuation, Other)),
-            (r'(\$[a-zA-Z]+)(\.?)(text|value)?',
-             bygroups(Name.Variable, Punctuation, Name.Property)),
-            (r'\{', Punctuation, '#push'),
-            (r'\}', Punctuation, '#pop'),
-        ],
-        'nested-arg-action': [
-            (r'(' + r'|'.join((    # keep host code in largest possible chunks.
-                r'[^$\[\]\'"/]+',  # exclude unsafe characters
-
-                # strings and comments may safely contain unsafe characters
-                r'"(\\\\|\\[^\\]|[^"\\])*"',
-                r"'(\\\\|\\[^\\]|[^'\\])*'",
-                r'//.*$\n?',            # single line comment
-                r'/\*(.|\n)*?\*/',      # multi-line javadoc-style comment
-
-                # regular expression: There's no reason for it to start
-                # with a * and this stops confusion with comments.
-                r'/(?!\*)(\\\\|\\[^\\]|[^/\\])*/',
-
-                # Now that we've handled regex and javadoc comments
-                # it's safe to let / through.
-                r'/',
-            )) + r')+', Other),
-
-
-            (r'\[', Punctuation, '#push'),
-            (r'\]', Punctuation, '#pop'),
-            (r'(\$[a-zA-Z]+)(\.?)(text|value)?',
-             bygroups(Name.Variable, Punctuation, Name.Property)),
-            (r'(\\\\|\\\]|\\\[|[^\[\]])+', Other),
-        ]
-    }
-
-    def analyse_text(text):
-        return re.search(r'^\s*grammar\s+[a-zA-Z0-9]+\s*;', text, re.M)
-
-
-# http://www.antlr.org/wiki/display/ANTLR3/Code+Generation+Targets
-
-class AntlrCppLexer(DelegatingLexer):
-    """
-    ANTLR with C++ Target
-    """
-
-    name = 'ANTLR With CPP Target'
-    aliases = ['antlr-cpp']
-    filenames = ['*.G', '*.g']
-    url = 'https://www.antlr.org'
-    version_added = '1.1'
-
-    def __init__(self, **options):
-        super().__init__(CppLexer, AntlrLexer, **options)
-
-    def analyse_text(text):
-        return AntlrLexer.analyse_text(text) and \
-            re.search(r'^\s*language\s*=\s*C\s*;', text, re.M)
-
-
-class AntlrObjectiveCLexer(DelegatingLexer):
-    """
-    ANTLR with Objective-C Target
-    """
-
-    name = 'ANTLR With ObjectiveC Target'
-    aliases = ['antlr-objc']
-    filenames = ['*.G', '*.g']
-    url = 'https://www.antlr.org'
-    version_added = '1.1'
-
-    def __init__(self, **options):
-        super().__init__(ObjectiveCLexer, AntlrLexer, **options)
-
-    def analyse_text(text):
-        return AntlrLexer.analyse_text(text) and \
-            re.search(r'^\s*language\s*=\s*ObjC\s*;', text)
-
-
-class AntlrCSharpLexer(DelegatingLexer):
-    """
-    ANTLR with C# Target
-    """
-
-    name = 'ANTLR With C# Target'
-    aliases = ['antlr-csharp', 'antlr-c#']
-    filenames = ['*.G', '*.g']
-    url = 'https://www.antlr.org'
-    version_added = '1.1'
-
-    def __init__(self, **options):
-        super().__init__(CSharpLexer, AntlrLexer, **options)
-
-    def analyse_text(text):
-        return AntlrLexer.analyse_text(text) and \
-            re.search(r'^\s*language\s*=\s*CSharp2\s*;', text, re.M)
-
-
-class AntlrPythonLexer(DelegatingLexer):
-    """
-    ANTLR with Python Target
-    """
-
-    name = 'ANTLR With Python Target'
-    aliases = ['antlr-python']
-    filenames = ['*.G', '*.g']
-    url = 'https://www.antlr.org'
-    version_added = '1.1'
-
-    def __init__(self, **options):
-        super().__init__(PythonLexer, AntlrLexer, **options)
-
-    def analyse_text(text):
-        return AntlrLexer.analyse_text(text) and \
-            re.search(r'^\s*language\s*=\s*Python\s*;', text, re.M)
-
-
-class AntlrJavaLexer(DelegatingLexer):
-    """
-    ANTLR with Java Target
-    """
-
-    name = 'ANTLR With Java Target'
-    aliases = ['antlr-java']
-    filenames = ['*.G', '*.g']
-    url = 'https://www.antlr.org'
-    version_added = '1.1'
-
-    def __init__(self, **options):
-        super().__init__(JavaLexer, AntlrLexer, **options)
-
-    def analyse_text(text):
-        # Antlr language is Java by default
-        return AntlrLexer.analyse_text(text) and 0.9
-
-
-class AntlrRubyLexer(DelegatingLexer):
-    """
-    ANTLR with Ruby Target
-    """
-
-    name = 'ANTLR With Ruby Target'
-    aliases = ['antlr-ruby', 'antlr-rb']
-    filenames = ['*.G', '*.g']
-    url = 'https://www.antlr.org'
-    version_added = '1.1'
-
-    def __init__(self, **options):
-        super().__init__(RubyLexer, AntlrLexer, **options)
-
-    def analyse_text(text):
-        return AntlrLexer.analyse_text(text) and \
-            re.search(r'^\s*language\s*=\s*Ruby\s*;', text, re.M)
-
-
-class AntlrPerlLexer(DelegatingLexer):
-    """
-    ANTLR with Perl Target
-    """
-
-    name = 'ANTLR With Perl Target'
-    aliases = ['antlr-perl']
-    filenames = ['*.G', '*.g']
-    url = 'https://www.antlr.org'
-    version_added = '1.1'
-
-    def __init__(self, **options):
-        super().__init__(PerlLexer, AntlrLexer, **options)
-
-    def analyse_text(text):
-        return AntlrLexer.analyse_text(text) and \
-            re.search(r'^\s*language\s*=\s*Perl5\s*;', text, re.M)
-
-
-class AntlrActionScriptLexer(DelegatingLexer):
-    """
-    ANTLR with ActionScript Target
-    """
-
-    name = 'ANTLR With ActionScript Target'
-    aliases = ['antlr-actionscript', 'antlr-as']
-    filenames = ['*.G', '*.g']
-    url = 'https://www.antlr.org'
-    version_added = '1.1'
-
-    def __init__(self, **options):
-        from pygments.lexers.actionscript import ActionScriptLexer
-        super().__init__(ActionScriptLexer, AntlrLexer, **options)
-
-    def analyse_text(text):
-        return AntlrLexer.analyse_text(text) and \
-            re.search(r'^\s*language\s*=\s*ActionScript\s*;', text, re.M)
-
-
-class TreetopBaseLexer(RegexLexer):
-    """
-    A base lexer for `Treetop `_ grammars.
-    Not for direct use; use :class:`TreetopLexer` instead.
-
-    .. versionadded:: 1.6
-    """
-
-    tokens = {
-        'root': [
-            include('space'),
-            (r'require[ \t]+[^\n\r]+[\n\r]', Other),
-            (r'module\b', Keyword.Namespace, 'module'),
-            (r'grammar\b', Keyword, 'grammar'),
-        ],
-        'module': [
-            include('space'),
-            include('end'),
-            (r'module\b', Keyword, '#push'),
-            (r'grammar\b', Keyword, 'grammar'),
-            (r'[A-Z]\w*(?:::[A-Z]\w*)*', Name.Namespace),
-        ],
-        'grammar': [
-            include('space'),
-            include('end'),
-            (r'rule\b', Keyword, 'rule'),
-            (r'include\b', Keyword, 'include'),
-            (r'[A-Z]\w*', Name),
-        ],
-        'include': [
-            include('space'),
-            (r'[A-Z]\w*(?:::[A-Z]\w*)*', Name.Class, '#pop'),
-        ],
-        'rule': [
-            include('space'),
-            include('end'),
-            (r'"(\\\\|\\[^\\]|[^"\\])*"', String.Double),
-            (r"'(\\\\|\\[^\\]|[^'\\])*'", String.Single),
-            (r'([A-Za-z_]\w*)(:)', bygroups(Name.Label, Punctuation)),
-            (r'[A-Za-z_]\w*', Name),
-            (r'[()]', Punctuation),
-            (r'[?+*/&!~]', Operator),
-            (r'\[(?:\\.|\[:\^?[a-z]+:\]|[^\\\]])+\]', String.Regex),
-            (r'([0-9]*)(\.\.)([0-9]*)',
-             bygroups(Number.Integer, Operator, Number.Integer)),
-            (r'(<)([^>]+)(>)', bygroups(Punctuation, Name.Class, Punctuation)),
-            (r'\{', Punctuation, 'inline_module'),
-            (r'\.', String.Regex),
-        ],
-        'inline_module': [
-            (r'\{', Other, 'ruby'),
-            (r'\}', Punctuation, '#pop'),
-            (r'[^{}]+', Other),
-        ],
-        'ruby': [
-            (r'\{', Other, '#push'),
-            (r'\}', Other, '#pop'),
-            (r'[^{}]+', Other),
-        ],
-        'space': [
-            (r'[ \t\n\r]+', Whitespace),
-            (r'#[^\n]*', Comment.Single),
-        ],
-        'end': [
-            (r'end\b', Keyword, '#pop'),
-        ],
-    }
-
-
-class TreetopLexer(DelegatingLexer):
-    """
-    A lexer for Treetop grammars.
-    """
-
-    name = 'Treetop'
-    aliases = ['treetop']
-    filenames = ['*.treetop', '*.tt']
-    url = 'https://cjheath.github.io/treetop'
-    version_added = '1.6'
-
-    def __init__(self, **options):
-        super().__init__(RubyLexer, TreetopBaseLexer, **options)
-
-
-class EbnfLexer(RegexLexer):
-    """
-    Lexer for `ISO/IEC 14977 EBNF
-    `_
-    grammars.
-    """
-
-    name = 'EBNF'
-    aliases = ['ebnf']
-    filenames = ['*.ebnf']
-    mimetypes = ['text/x-ebnf']
-    url = 'https://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_Form'
-    version_added = '2.0'
-
-    tokens = {
-        'root': [
-            include('whitespace'),
-            include('comment_start'),
-            include('identifier'),
-            (r'=', Operator, 'production'),
-        ],
-        'production': [
-            include('whitespace'),
-            include('comment_start'),
-            include('identifier'),
-            (r'"[^"]*"', String.Double),
-            (r"'[^']*'", String.Single),
-            (r'(\?[^?]*\?)', Name.Entity),
-            (r'[\[\]{}(),|]', Punctuation),
-            (r'-', Operator),
-            (r';', Punctuation, '#pop'),
-            (r'\.', Punctuation, '#pop'),
-        ],
-        'whitespace': [
-            (r'\s+', Text),
-        ],
-        'comment_start': [
-            (r'\(\*', Comment.Multiline, 'comment'),
-        ],
-        'comment': [
-            (r'[^*)]', Comment.Multiline),
-            include('comment_start'),
-            (r'\*\)', Comment.Multiline, '#pop'),
-            (r'[*)]', Comment.Multiline),
-        ],
-        'identifier': [
-            (r'([a-zA-Z][\w \-]*)', Keyword),
-        ],
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/pascal.py b/.venv/lib/python3.12/site-packages/pygments/lexers/pascal.py
deleted file mode 100644
index ad8a0ae..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/pascal.py
+++ /dev/null
@@ -1,644 +0,0 @@
-"""
-    pygments.lexers.pascal
-    ~~~~~~~~~~~~~~~~~~~~~~
-
-    Lexers for Pascal family languages.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-import re
-
-from pygments.lexer import Lexer
-from pygments.util import get_bool_opt, get_list_opt
-from pygments.token import Comment, Operator, Keyword, Name, String, \
-    Number, Punctuation, Error, Whitespace
-from pygments.scanner import Scanner
-
-# compatibility import
-from pygments.lexers.modula2 import Modula2Lexer # noqa: F401
-
-__all__ = ['DelphiLexer', 'PortugolLexer']
-
-
-class PortugolLexer(Lexer):
-    """For Portugol, a Pascal dialect with keywords in Portuguese."""
-    name = 'Portugol'
-    aliases = ['portugol']
-    filenames = ['*.alg', '*.portugol']
-    mimetypes = []
-    url = "https://www.apoioinformatica.inf.br/produtos/visualg/linguagem"
-    version_added = ''
-
-    def __init__(self, **options):
-        Lexer.__init__(self, **options)
-        self.lexer = DelphiLexer(**options, portugol=True)
-
-    def get_tokens_unprocessed(self, text):
-        return self.lexer.get_tokens_unprocessed(text)
-
-
-class DelphiLexer(Lexer):
-    """
-    For Delphi (Borland Object Pascal),
-    Turbo Pascal and Free Pascal source code.
-
-    Additional options accepted:
-
-    `turbopascal`
-        Highlight Turbo Pascal specific keywords (default: ``True``).
-    `delphi`
-        Highlight Borland Delphi specific keywords (default: ``True``).
-    `freepascal`
-        Highlight Free Pascal specific keywords (default: ``True``).
-    `units`
-        A list of units that should be considered builtin, supported are
-        ``System``, ``SysUtils``, ``Classes`` and ``Math``.
-        Default is to consider all of them builtin.
-    """
-    name = 'Delphi'
-    aliases = ['delphi', 'pas', 'pascal', 'objectpascal']
-    filenames = ['*.pas', '*.dpr']
-    mimetypes = ['text/x-pascal']
-    url = 'https://www.embarcadero.com/products/delphi'
-    version_added = ''
-
-    TURBO_PASCAL_KEYWORDS = (
-        'absolute', 'and', 'array', 'asm', 'begin', 'break', 'case',
-        'const', 'constructor', 'continue', 'destructor', 'div', 'do',
-        'downto', 'else', 'end', 'file', 'for', 'function', 'goto',
-        'if', 'implementation', 'in', 'inherited', 'inline', 'interface',
-        'label', 'mod', 'nil', 'not', 'object', 'of', 'on', 'operator',
-        'or', 'packed', 'procedure', 'program', 'record', 'reintroduce',
-        'repeat', 'self', 'set', 'shl', 'shr', 'string', 'then', 'to',
-        'type', 'unit', 'until', 'uses', 'var', 'while', 'with', 'xor'
-    )
-
-    DELPHI_KEYWORDS = (
-        'as', 'class', 'except', 'exports', 'finalization', 'finally',
-        'initialization', 'is', 'library', 'on', 'property', 'raise',
-        'threadvar', 'try'
-    )
-
-    FREE_PASCAL_KEYWORDS = (
-        'dispose', 'exit', 'false', 'new', 'true'
-    )
-
-    BLOCK_KEYWORDS = {
-        'begin', 'class', 'const', 'constructor', 'destructor', 'end',
-        'finalization', 'function', 'implementation', 'initialization',
-        'label', 'library', 'operator', 'procedure', 'program', 'property',
-        'record', 'threadvar', 'type', 'unit', 'uses', 'var'
-    }
-
-    FUNCTION_MODIFIERS = {
-        'alias', 'cdecl', 'export', 'inline', 'interrupt', 'nostackframe',
-        'pascal', 'register', 'safecall', 'softfloat', 'stdcall',
-        'varargs', 'name', 'dynamic', 'near', 'virtual', 'external',
-        'override', 'assembler'
-    }
-
-    # XXX: those aren't global. but currently we know no way for defining
-    #      them just for the type context.
-    DIRECTIVES = {
-        'absolute', 'abstract', 'assembler', 'cppdecl', 'default', 'far',
-        'far16', 'forward', 'index', 'oldfpccall', 'private', 'protected',
-        'published', 'public'
-    }
-
-    BUILTIN_TYPES = {
-        'ansichar', 'ansistring', 'bool', 'boolean', 'byte', 'bytebool',
-        'cardinal', 'char', 'comp', 'currency', 'double', 'dword',
-        'extended', 'int64', 'integer', 'iunknown', 'longbool', 'longint',
-        'longword', 'pansichar', 'pansistring', 'pbool', 'pboolean',
-        'pbyte', 'pbytearray', 'pcardinal', 'pchar', 'pcomp', 'pcurrency',
-        'pdate', 'pdatetime', 'pdouble', 'pdword', 'pextended', 'phandle',
-        'pint64', 'pinteger', 'plongint', 'plongword', 'pointer',
-        'ppointer', 'pshortint', 'pshortstring', 'psingle', 'psmallint',
-        'pstring', 'pvariant', 'pwidechar', 'pwidestring', 'pword',
-        'pwordarray', 'pwordbool', 'real', 'real48', 'shortint',
-        'shortstring', 'single', 'smallint', 'string', 'tclass', 'tdate',
-        'tdatetime', 'textfile', 'thandle', 'tobject', 'ttime', 'variant',
-        'widechar', 'widestring', 'word', 'wordbool'
-    }
-
-    BUILTIN_UNITS = {
-        'System': (
-            'abs', 'acquireexceptionobject', 'addr', 'ansitoutf8',
-            'append', 'arctan', 'assert', 'assigned', 'assignfile',
-            'beginthread', 'blockread', 'blockwrite', 'break', 'chdir',
-            'chr', 'close', 'closefile', 'comptocurrency', 'comptodouble',
-            'concat', 'continue', 'copy', 'cos', 'dec', 'delete',
-            'dispose', 'doubletocomp', 'endthread', 'enummodules',
-            'enumresourcemodules', 'eof', 'eoln', 'erase', 'exceptaddr',
-            'exceptobject', 'exclude', 'exit', 'exp', 'filepos', 'filesize',
-            'fillchar', 'finalize', 'findclasshinstance', 'findhinstance',
-            'findresourcehinstance', 'flush', 'frac', 'freemem',
-            'get8087cw', 'getdir', 'getlasterror', 'getmem',
-            'getmemorymanager', 'getmodulefilename', 'getvariantmanager',
-            'halt', 'hi', 'high', 'inc', 'include', 'initialize', 'insert',
-            'int', 'ioresult', 'ismemorymanagerset', 'isvariantmanagerset',
-            'length', 'ln', 'lo', 'low', 'mkdir', 'move', 'new', 'odd',
-            'olestrtostring', 'olestrtostrvar', 'ord', 'paramcount',
-            'paramstr', 'pi', 'pos', 'pred', 'ptr', 'pucs4chars', 'random',
-            'randomize', 'read', 'readln', 'reallocmem',
-            'releaseexceptionobject', 'rename', 'reset', 'rewrite', 'rmdir',
-            'round', 'runerror', 'seek', 'seekeof', 'seekeoln',
-            'set8087cw', 'setlength', 'setlinebreakstyle',
-            'setmemorymanager', 'setstring', 'settextbuf',
-            'setvariantmanager', 'sin', 'sizeof', 'slice', 'sqr', 'sqrt',
-            'str', 'stringofchar', 'stringtoolestr', 'stringtowidechar',
-            'succ', 'swap', 'trunc', 'truncate', 'typeinfo',
-            'ucs4stringtowidestring', 'unicodetoutf8', 'uniquestring',
-            'upcase', 'utf8decode', 'utf8encode', 'utf8toansi',
-            'utf8tounicode', 'val', 'vararrayredim', 'varclear',
-            'widecharlentostring', 'widecharlentostrvar',
-            'widechartostring', 'widechartostrvar',
-            'widestringtoucs4string', 'write', 'writeln'
-        ),
-        'SysUtils': (
-            'abort', 'addexitproc', 'addterminateproc', 'adjustlinebreaks',
-            'allocmem', 'ansicomparefilename', 'ansicomparestr',
-            'ansicomparetext', 'ansidequotedstr', 'ansiextractquotedstr',
-            'ansilastchar', 'ansilowercase', 'ansilowercasefilename',
-            'ansipos', 'ansiquotedstr', 'ansisamestr', 'ansisametext',
-            'ansistrcomp', 'ansistricomp', 'ansistrlastchar', 'ansistrlcomp',
-            'ansistrlicomp', 'ansistrlower', 'ansistrpos', 'ansistrrscan',
-            'ansistrscan', 'ansistrupper', 'ansiuppercase',
-            'ansiuppercasefilename', 'appendstr', 'assignstr', 'beep',
-            'booltostr', 'bytetocharindex', 'bytetocharlen', 'bytetype',
-            'callterminateprocs', 'changefileext', 'charlength',
-            'chartobyteindex', 'chartobytelen', 'comparemem', 'comparestr',
-            'comparetext', 'createdir', 'createguid', 'currentyear',
-            'currtostr', 'currtostrf', 'date', 'datetimetofiledate',
-            'datetimetostr', 'datetimetostring', 'datetimetosystemtime',
-            'datetimetotimestamp', 'datetostr', 'dayofweek', 'decodedate',
-            'decodedatefully', 'decodetime', 'deletefile', 'directoryexists',
-            'diskfree', 'disksize', 'disposestr', 'encodedate', 'encodetime',
-            'exceptionerrormessage', 'excludetrailingbackslash',
-            'excludetrailingpathdelimiter', 'expandfilename',
-            'expandfilenamecase', 'expanduncfilename', 'extractfiledir',
-            'extractfiledrive', 'extractfileext', 'extractfilename',
-            'extractfilepath', 'extractrelativepath', 'extractshortpathname',
-            'fileage', 'fileclose', 'filecreate', 'filedatetodatetime',
-            'fileexists', 'filegetattr', 'filegetdate', 'fileisreadonly',
-            'fileopen', 'fileread', 'filesearch', 'fileseek', 'filesetattr',
-            'filesetdate', 'filesetreadonly', 'filewrite', 'finalizepackage',
-            'findclose', 'findcmdlineswitch', 'findfirst', 'findnext',
-            'floattocurr', 'floattodatetime', 'floattodecimal', 'floattostr',
-            'floattostrf', 'floattotext', 'floattotextfmt', 'fmtloadstr',
-            'fmtstr', 'forcedirectories', 'format', 'formatbuf', 'formatcurr',
-            'formatdatetime', 'formatfloat', 'freeandnil', 'getcurrentdir',
-            'getenvironmentvariable', 'getfileversion', 'getformatsettings',
-            'getlocaleformatsettings', 'getmodulename', 'getpackagedescription',
-            'getpackageinfo', 'gettime', 'guidtostring', 'incamonth',
-            'includetrailingbackslash', 'includetrailingpathdelimiter',
-            'incmonth', 'initializepackage', 'interlockeddecrement',
-            'interlockedexchange', 'interlockedexchangeadd',
-            'interlockedincrement', 'inttohex', 'inttostr', 'isdelimiter',
-            'isequalguid', 'isleapyear', 'ispathdelimiter', 'isvalidident',
-            'languages', 'lastdelimiter', 'loadpackage', 'loadstr',
-            'lowercase', 'msecstotimestamp', 'newstr', 'nextcharindex', 'now',
-            'outofmemoryerror', 'quotedstr', 'raiselastoserror',
-            'raiselastwin32error', 'removedir', 'renamefile', 'replacedate',
-            'replacetime', 'safeloadlibrary', 'samefilename', 'sametext',
-            'setcurrentdir', 'showexception', 'sleep', 'stralloc', 'strbufsize',
-            'strbytetype', 'strcat', 'strcharlength', 'strcomp', 'strcopy',
-            'strdispose', 'strecopy', 'strend', 'strfmt', 'stricomp',
-            'stringreplace', 'stringtoguid', 'strlcat', 'strlcomp', 'strlcopy',
-            'strlen', 'strlfmt', 'strlicomp', 'strlower', 'strmove', 'strnew',
-            'strnextchar', 'strpas', 'strpcopy', 'strplcopy', 'strpos',
-            'strrscan', 'strscan', 'strtobool', 'strtobooldef', 'strtocurr',
-            'strtocurrdef', 'strtodate', 'strtodatedef', 'strtodatetime',
-            'strtodatetimedef', 'strtofloat', 'strtofloatdef', 'strtoint',
-            'strtoint64', 'strtoint64def', 'strtointdef', 'strtotime',
-            'strtotimedef', 'strupper', 'supports', 'syserrormessage',
-            'systemtimetodatetime', 'texttofloat', 'time', 'timestamptodatetime',
-            'timestamptomsecs', 'timetostr', 'trim', 'trimleft', 'trimright',
-            'tryencodedate', 'tryencodetime', 'tryfloattocurr', 'tryfloattodatetime',
-            'trystrtobool', 'trystrtocurr', 'trystrtodate', 'trystrtodatetime',
-            'trystrtofloat', 'trystrtoint', 'trystrtoint64', 'trystrtotime',
-            'unloadpackage', 'uppercase', 'widecomparestr', 'widecomparetext',
-            'widefmtstr', 'wideformat', 'wideformatbuf', 'widelowercase',
-            'widesamestr', 'widesametext', 'wideuppercase', 'win32check',
-            'wraptext'
-        ),
-        'Classes': (
-            'activateclassgroup', 'allocatehwnd', 'bintohex', 'checksynchronize',
-            'collectionsequal', 'countgenerations', 'deallocatehwnd', 'equalrect',
-            'extractstrings', 'findclass', 'findglobalcomponent', 'getclass',
-            'groupdescendantswith', 'hextobin', 'identtoint',
-            'initinheritedcomponent', 'inttoident', 'invalidpoint',
-            'isuniqueglobalcomponentname', 'linestart', 'objectbinarytotext',
-            'objectresourcetotext', 'objecttexttobinary', 'objecttexttoresource',
-            'pointsequal', 'readcomponentres', 'readcomponentresex',
-            'readcomponentresfile', 'rect', 'registerclass', 'registerclassalias',
-            'registerclasses', 'registercomponents', 'registerintegerconsts',
-            'registernoicon', 'registernonactivex', 'smallpoint', 'startclassgroup',
-            'teststreamformat', 'unregisterclass', 'unregisterclasses',
-            'unregisterintegerconsts', 'unregistermoduleclasses',
-            'writecomponentresfile'
-        ),
-        'Math': (
-            'arccos', 'arccosh', 'arccot', 'arccoth', 'arccsc', 'arccsch', 'arcsec',
-            'arcsech', 'arcsin', 'arcsinh', 'arctan2', 'arctanh', 'ceil',
-            'comparevalue', 'cosecant', 'cosh', 'cot', 'cotan', 'coth', 'csc',
-            'csch', 'cycletodeg', 'cycletograd', 'cycletorad', 'degtocycle',
-            'degtograd', 'degtorad', 'divmod', 'doubledecliningbalance',
-            'ensurerange', 'floor', 'frexp', 'futurevalue', 'getexceptionmask',
-            'getprecisionmode', 'getroundmode', 'gradtocycle', 'gradtodeg',
-            'gradtorad', 'hypot', 'inrange', 'interestpayment', 'interestrate',
-            'internalrateofreturn', 'intpower', 'isinfinite', 'isnan', 'iszero',
-            'ldexp', 'lnxp1', 'log10', 'log2', 'logn', 'max', 'maxintvalue',
-            'maxvalue', 'mean', 'meanandstddev', 'min', 'minintvalue', 'minvalue',
-            'momentskewkurtosis', 'netpresentvalue', 'norm', 'numberofperiods',
-            'payment', 'periodpayment', 'poly', 'popnstddev', 'popnvariance',
-            'power', 'presentvalue', 'radtocycle', 'radtodeg', 'radtograd',
-            'randg', 'randomrange', 'roundto', 'samevalue', 'sec', 'secant',
-            'sech', 'setexceptionmask', 'setprecisionmode', 'setroundmode',
-            'sign', 'simpleroundto', 'sincos', 'sinh', 'slndepreciation', 'stddev',
-            'sum', 'sumint', 'sumofsquares', 'sumsandsquares', 'syddepreciation',
-            'tan', 'tanh', 'totalvariance', 'variance'
-        )
-    }
-
-    ASM_REGISTERS = {
-        'ah', 'al', 'ax', 'bh', 'bl', 'bp', 'bx', 'ch', 'cl', 'cr0',
-        'cr1', 'cr2', 'cr3', 'cr4', 'cs', 'cx', 'dh', 'di', 'dl', 'dr0',
-        'dr1', 'dr2', 'dr3', 'dr4', 'dr5', 'dr6', 'dr7', 'ds', 'dx',
-        'eax', 'ebp', 'ebx', 'ecx', 'edi', 'edx', 'es', 'esi', 'esp',
-        'fs', 'gs', 'mm0', 'mm1', 'mm2', 'mm3', 'mm4', 'mm5', 'mm6',
-        'mm7', 'si', 'sp', 'ss', 'st0', 'st1', 'st2', 'st3', 'st4', 'st5',
-        'st6', 'st7', 'xmm0', 'xmm1', 'xmm2', 'xmm3', 'xmm4', 'xmm5',
-        'xmm6', 'xmm7'
-    }
-
-    ASM_INSTRUCTIONS = {
-        'aaa', 'aad', 'aam', 'aas', 'adc', 'add', 'and', 'arpl', 'bound',
-        'bsf', 'bsr', 'bswap', 'bt', 'btc', 'btr', 'bts', 'call', 'cbw',
-        'cdq', 'clc', 'cld', 'cli', 'clts', 'cmc', 'cmova', 'cmovae',
-        'cmovb', 'cmovbe', 'cmovc', 'cmovcxz', 'cmove', 'cmovg',
-        'cmovge', 'cmovl', 'cmovle', 'cmovna', 'cmovnae', 'cmovnb',
-        'cmovnbe', 'cmovnc', 'cmovne', 'cmovng', 'cmovnge', 'cmovnl',
-        'cmovnle', 'cmovno', 'cmovnp', 'cmovns', 'cmovnz', 'cmovo',
-        'cmovp', 'cmovpe', 'cmovpo', 'cmovs', 'cmovz', 'cmp', 'cmpsb',
-        'cmpsd', 'cmpsw', 'cmpxchg', 'cmpxchg486', 'cmpxchg8b', 'cpuid',
-        'cwd', 'cwde', 'daa', 'das', 'dec', 'div', 'emms', 'enter', 'hlt',
-        'ibts', 'icebp', 'idiv', 'imul', 'in', 'inc', 'insb', 'insd',
-        'insw', 'int', 'int01', 'int03', 'int1', 'int3', 'into', 'invd',
-        'invlpg', 'iret', 'iretd', 'iretw', 'ja', 'jae', 'jb', 'jbe',
-        'jc', 'jcxz', 'jcxz', 'je', 'jecxz', 'jg', 'jge', 'jl', 'jle',
-        'jmp', 'jna', 'jnae', 'jnb', 'jnbe', 'jnc', 'jne', 'jng', 'jnge',
-        'jnl', 'jnle', 'jno', 'jnp', 'jns', 'jnz', 'jo', 'jp', 'jpe',
-        'jpo', 'js', 'jz', 'lahf', 'lar', 'lcall', 'lds', 'lea', 'leave',
-        'les', 'lfs', 'lgdt', 'lgs', 'lidt', 'ljmp', 'lldt', 'lmsw',
-        'loadall', 'loadall286', 'lock', 'lodsb', 'lodsd', 'lodsw',
-        'loop', 'loope', 'loopne', 'loopnz', 'loopz', 'lsl', 'lss', 'ltr',
-        'mov', 'movd', 'movq', 'movsb', 'movsd', 'movsw', 'movsx',
-        'movzx', 'mul', 'neg', 'nop', 'not', 'or', 'out', 'outsb', 'outsd',
-        'outsw', 'pop', 'popa', 'popad', 'popaw', 'popf', 'popfd', 'popfw',
-        'push', 'pusha', 'pushad', 'pushaw', 'pushf', 'pushfd', 'pushfw',
-        'rcl', 'rcr', 'rdmsr', 'rdpmc', 'rdshr', 'rdtsc', 'rep', 'repe',
-        'repne', 'repnz', 'repz', 'ret', 'retf', 'retn', 'rol', 'ror',
-        'rsdc', 'rsldt', 'rsm', 'sahf', 'sal', 'salc', 'sar', 'sbb',
-        'scasb', 'scasd', 'scasw', 'seta', 'setae', 'setb', 'setbe',
-        'setc', 'setcxz', 'sete', 'setg', 'setge', 'setl', 'setle',
-        'setna', 'setnae', 'setnb', 'setnbe', 'setnc', 'setne', 'setng',
-        'setnge', 'setnl', 'setnle', 'setno', 'setnp', 'setns', 'setnz',
-        'seto', 'setp', 'setpe', 'setpo', 'sets', 'setz', 'sgdt', 'shl',
-        'shld', 'shr', 'shrd', 'sidt', 'sldt', 'smi', 'smint', 'smintold',
-        'smsw', 'stc', 'std', 'sti', 'stosb', 'stosd', 'stosw', 'str',
-        'sub', 'svdc', 'svldt', 'svts', 'syscall', 'sysenter', 'sysexit',
-        'sysret', 'test', 'ud1', 'ud2', 'umov', 'verr', 'verw', 'wait',
-        'wbinvd', 'wrmsr', 'wrshr', 'xadd', 'xbts', 'xchg', 'xlat',
-        'xlatb', 'xor'
-    }
-
-    PORTUGOL_KEYWORDS = (
-        'aleatorio',
-        'algoritmo',
-        'arquivo',
-        'ate',
-        'caso',
-        'cronometro',
-        'debug',
-        'e',
-        'eco',
-        'enquanto',
-        'entao',
-        'escolha',
-        'escreva',
-        'escreval',
-        'faca',
-        'falso',
-        'fimalgoritmo',
-        'fimenquanto',
-        'fimescolha',
-        'fimfuncao',
-        'fimpara',
-        'fimprocedimento',
-        'fimrepita',
-        'fimse',
-        'funcao',
-        'inicio',
-        'int',
-        'interrompa',
-        'leia',
-        'limpatela',
-        'mod',
-        'nao',
-        'ou',
-        'outrocaso',
-        'para',
-        'passo',
-        'pausa',
-        'procedimento',
-        'repita',
-        'retorne',
-        'se',
-        'senao',
-        'timer',
-        'var',
-        'vetor',
-        'verdadeiro',
-        'xou',
-        'div',
-        'mod',
-        'abs',
-        'arccos',
-        'arcsen',
-        'arctan',
-        'cos',
-        'cotan',
-        'Exp',
-        'grauprad',
-        'int',
-        'log',
-        'logn',
-        'pi',
-        'quad',
-        'radpgrau',
-        'raizq',
-        'rand',
-        'randi',
-        'sen',
-        'Tan',
-        'asc',
-        'carac',
-        'caracpnum',
-        'compr',
-        'copia',
-        'maiusc',
-        'minusc',
-        'numpcarac',
-        'pos',
-    )
-
-    PORTUGOL_BUILTIN_TYPES = {
-        'inteiro', 'real', 'caractere', 'logico'
-    }
-
-    def __init__(self, **options):
-        Lexer.__init__(self, **options)
-        self.keywords = set()
-        self.builtins = set()
-        if get_bool_opt(options, 'portugol', False):
-            self.keywords.update(self.PORTUGOL_KEYWORDS)
-            self.builtins.update(self.PORTUGOL_BUILTIN_TYPES)
-            self.is_portugol = True
-        else:
-            self.is_portugol = False
-
-            if get_bool_opt(options, 'turbopascal', True):
-                self.keywords.update(self.TURBO_PASCAL_KEYWORDS)
-            if get_bool_opt(options, 'delphi', True):
-                self.keywords.update(self.DELPHI_KEYWORDS)
-            if get_bool_opt(options, 'freepascal', True):
-                self.keywords.update(self.FREE_PASCAL_KEYWORDS)
-            for unit in get_list_opt(options, 'units', list(self.BUILTIN_UNITS)):
-                self.builtins.update(self.BUILTIN_UNITS[unit])
-
-    def get_tokens_unprocessed(self, text):
-        scanner = Scanner(text, re.DOTALL | re.MULTILINE | re.IGNORECASE)
-        stack = ['initial']
-        in_function_block = False
-        in_property_block = False
-        was_dot = False
-        next_token_is_function = False
-        next_token_is_property = False
-        collect_labels = False
-        block_labels = set()
-        brace_balance = [0, 0]
-
-        while not scanner.eos:
-            token = Error
-
-            if stack[-1] == 'initial':
-                if scanner.scan(r'\s+'):
-                    token = Whitespace
-                elif not self.is_portugol and scanner.scan(r'\{.*?\}|\(\*.*?\*\)'):
-                    if scanner.match.startswith('$'):
-                        token = Comment.Preproc
-                    else:
-                        token = Comment.Multiline
-                elif scanner.scan(r'//.*?$'):
-                    token = Comment.Single
-                elif self.is_portugol and scanner.scan(r'(<\-)|(>=)|(<=)|%|<|>|-|\+|\*|\=|(<>)|\/|\.|:|,'):
-                    token = Operator
-                elif not self.is_portugol and scanner.scan(r'[-+*\/=<>:;,.@\^]'):
-                    token = Operator
-                    # stop label highlighting on next ";"
-                    if collect_labels and scanner.match == ';':
-                        collect_labels = False
-                elif scanner.scan(r'[\(\)\[\]]+'):
-                    token = Punctuation
-                    # abort function naming ``foo = Function(...)``
-                    next_token_is_function = False
-                    # if we are in a function block we count the open
-                    # braces because ootherwise it's impossible to
-                    # determine the end of the modifier context
-                    if in_function_block or in_property_block:
-                        if scanner.match == '(':
-                            brace_balance[0] += 1
-                        elif scanner.match == ')':
-                            brace_balance[0] -= 1
-                        elif scanner.match == '[':
-                            brace_balance[1] += 1
-                        elif scanner.match == ']':
-                            brace_balance[1] -= 1
-                elif scanner.scan(r'[A-Za-z_][A-Za-z_0-9]*'):
-                    lowercase_name = scanner.match.lower()
-                    if lowercase_name == 'result':
-                        token = Name.Builtin.Pseudo
-                    elif lowercase_name in self.keywords:
-                        token = Keyword
-                        # if we are in a special block and a
-                        # block ending keyword occurs (and the parenthesis
-                        # is balanced) we end the current block context
-                        if self.is_portugol:
-                            if lowercase_name in ('funcao', 'procedimento'):
-                                in_function_block = True
-                                next_token_is_function = True
-                        else:
-                            if (in_function_block or in_property_block) and \
-                                    lowercase_name in self.BLOCK_KEYWORDS and \
-                                    brace_balance[0] <= 0 and \
-                                    brace_balance[1] <= 0:
-                                in_function_block = False
-                                in_property_block = False
-                                brace_balance = [0, 0]
-                                block_labels = set()
-                            if lowercase_name in ('label', 'goto'):
-                                collect_labels = True
-                            elif lowercase_name == 'asm':
-                                stack.append('asm')
-                            elif lowercase_name == 'property':
-                                in_property_block = True
-                                next_token_is_property = True
-                            elif lowercase_name in ('procedure', 'operator',
-                                                    'function', 'constructor',
-                                                    'destructor'):
-                                in_function_block = True
-                                next_token_is_function = True
-                    # we are in a function block and the current name
-                    # is in the set of registered modifiers. highlight
-                    # it as pseudo keyword
-                    elif not self.is_portugol and in_function_block and \
-                            lowercase_name in self.FUNCTION_MODIFIERS:
-                        token = Keyword.Pseudo
-                    # if we are in a property highlight some more
-                    # modifiers
-                    elif not self.is_portugol and in_property_block and \
-                            lowercase_name in ('read', 'write'):
-                        token = Keyword.Pseudo
-                        next_token_is_function = True
-                    # if the last iteration set next_token_is_function
-                    # to true we now want this name highlighted as
-                    # function. so do that and reset the state
-                    elif next_token_is_function:
-                        # Look if the next token is a dot. If yes it's
-                        # not a function, but a class name and the
-                        # part after the dot a function name
-                        if not self.is_portugol and scanner.test(r'\s*\.\s*'):
-                            token = Name.Class
-                        # it's not a dot, our job is done
-                        else:
-                            token = Name.Function
-                            next_token_is_function = False
-
-                            if self.is_portugol:
-                                block_labels.add(scanner.match.lower())
-
-                    # same for properties
-                    elif not self.is_portugol and next_token_is_property:
-                        token = Name.Property
-                        next_token_is_property = False
-                    # Highlight this token as label and add it
-                    # to the list of known labels
-                    elif not self.is_portugol and collect_labels:
-                        token = Name.Label
-                        block_labels.add(scanner.match.lower())
-                    # name is in list of known labels
-                    elif lowercase_name in block_labels:
-                        token = Name.Label
-                    elif self.is_portugol and lowercase_name in self.PORTUGOL_BUILTIN_TYPES:
-                        token = Keyword.Type
-                    elif not self.is_portugol and lowercase_name in self.BUILTIN_TYPES:
-                        token = Keyword.Type
-                    elif not self.is_portugol and lowercase_name in self.DIRECTIVES:
-                        token = Keyword.Pseudo
-                    # builtins are just builtins if the token
-                    # before isn't a dot
-                    elif not self.is_portugol and not was_dot and lowercase_name in self.builtins:
-                        token = Name.Builtin
-                    else:
-                        token = Name
-                elif self.is_portugol and scanner.scan(r"\""):
-                    token = String
-                    stack.append('string')
-                elif not self.is_portugol and scanner.scan(r"'"):
-                    token = String
-                    stack.append('string')
-                elif not self.is_portugol and scanner.scan(r'\#(\d+|\$[0-9A-Fa-f]+)'):
-                    token = String.Char
-                elif not self.is_portugol and scanner.scan(r'\$[0-9A-Fa-f]+'):
-                    token = Number.Hex
-                elif scanner.scan(r'\d+(?![eE]|\.[^.])'):
-                    token = Number.Integer
-                elif scanner.scan(r'\d+(\.\d+([eE][+-]?\d+)?|[eE][+-]?\d+)'):
-                    token = Number.Float
-                else:
-                    # if the stack depth is deeper than once, pop
-                    if len(stack) > 1:
-                        stack.pop()
-                    scanner.get_char()
-
-            elif stack[-1] == 'string':
-                if self.is_portugol:
-                    if scanner.scan(r"''"):
-                        token = String.Escape
-                    elif scanner.scan(r"\""):
-                        token = String
-                        stack.pop()
-                    elif scanner.scan(r"[^\"]*"):
-                        token = String
-                    else:
-                        scanner.get_char()
-                        stack.pop()
-                else:
-                    if scanner.scan(r"''"):
-                        token = String.Escape
-                    elif scanner.scan(r"'"):
-                        token = String
-                        stack.pop()
-                    elif scanner.scan(r"[^']*"):
-                        token = String
-                    else:
-                        scanner.get_char()
-                        stack.pop()
-            elif not self.is_portugol and stack[-1] == 'asm':
-                if scanner.scan(r'\s+'):
-                    token = Whitespace
-                elif scanner.scan(r'end'):
-                    token = Keyword
-                    stack.pop()
-                elif scanner.scan(r'\{.*?\}|\(\*.*?\*\)'):
-                    if scanner.match.startswith('$'):
-                        token = Comment.Preproc
-                    else:
-                        token = Comment.Multiline
-                elif scanner.scan(r'//.*?$'):
-                    token = Comment.Single
-                elif scanner.scan(r"'"):
-                    token = String
-                    stack.append('string')
-                elif scanner.scan(r'@@[A-Za-z_][A-Za-z_0-9]*'):
-                    token = Name.Label
-                elif scanner.scan(r'[A-Za-z_][A-Za-z_0-9]*'):
-                    lowercase_name = scanner.match.lower()
-                    if lowercase_name in self.ASM_INSTRUCTIONS:
-                        token = Keyword
-                    elif lowercase_name in self.ASM_REGISTERS:
-                        token = Name.Builtin
-                    else:
-                        token = Name
-                elif scanner.scan(r'[-+*\/=<>:;,.@\^]+'):
-                    token = Operator
-                elif scanner.scan(r'[\(\)\[\]]+'):
-                    token = Punctuation
-                elif scanner.scan(r'\$[0-9A-Fa-f]+'):
-                    token = Number.Hex
-                elif scanner.scan(r'\d+(?![eE]|\.[^.])'):
-                    token = Number.Integer
-                elif scanner.scan(r'\d+(\.\d+([eE][+-]?\d+)?|[eE][+-]?\d+)'):
-                    token = Number.Float
-                else:
-                    scanner.get_char()
-                    stack.pop()
-
-            # save the dot!!!11
-            if not self.is_portugol and scanner.match.strip():
-                was_dot = scanner.match == '.'
-
-            yield scanner.start_pos, token, scanner.match or ''
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/pawn.py b/.venv/lib/python3.12/site-packages/pygments/lexers/pawn.py
deleted file mode 100644
index 9b4234c..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/pawn.py
+++ /dev/null
@@ -1,202 +0,0 @@
-"""
-    pygments.lexers.pawn
-    ~~~~~~~~~~~~~~~~~~~~
-
-    Lexers for the Pawn languages.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-from pygments.lexer import RegexLexer
-from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
-    Number, Punctuation
-from pygments.util import get_bool_opt
-
-__all__ = ['SourcePawnLexer', 'PawnLexer']
-
-
-class SourcePawnLexer(RegexLexer):
-    """
-    For SourcePawn source code with preprocessor directives.
-    """
-    name = 'SourcePawn'
-    aliases = ['sp']
-    filenames = ['*.sp']
-    mimetypes = ['text/x-sourcepawn']
-    url = 'https://github.com/alliedmodders/sourcepawn'
-    version_added = '1.6'
-
-    #: optional Comment or Whitespace
-    _ws = r'(?:\s|//.*?\n|/\*.*?\*/)+'
-    #: only one /* */ style comment
-    _ws1 = r'\s*(?:/[*].*?[*]/\s*)*'
-
-    tokens = {
-        'root': [
-            # preprocessor directives: without whitespace
-            (r'^#if\s+0', Comment.Preproc, 'if0'),
-            ('^#', Comment.Preproc, 'macro'),
-            # or with whitespace
-            ('^' + _ws1 + r'#if\s+0', Comment.Preproc, 'if0'),
-            ('^' + _ws1 + '#', Comment.Preproc, 'macro'),
-            (r'\n', Text),
-            (r'\s+', Text),
-            (r'\\\n', Text),  # line continuation
-            (r'/(\\\n)?/(\n|(.|\n)*?[^\\]\n)', Comment.Single),
-            (r'/(\\\n)?\*(.|\n)*?\*(\\\n)?/', Comment.Multiline),
-            (r'[{}]', Punctuation),
-            (r'L?"', String, 'string'),
-            (r"L?'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'", String.Char),
-            (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[LlUu]*', Number.Float),
-            (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float),
-            (r'0x[0-9a-fA-F]+[LlUu]*', Number.Hex),
-            (r'0[0-7]+[LlUu]*', Number.Oct),
-            (r'\d+[LlUu]*', Number.Integer),
-            (r'[~!%^&*+=|?:<>/-]', Operator),
-            (r'[()\[\],.;]', Punctuation),
-            (r'(case|const|continue|native|'
-             r'default|else|enum|for|if|new|operator|'
-             r'public|return|sizeof|static|decl|struct|switch)\b', Keyword),
-            (r'(bool|Float)\b', Keyword.Type),
-            (r'(true|false)\b', Keyword.Constant),
-            (r'[a-zA-Z_]\w*', Name),
-        ],
-        'string': [
-            (r'"', String, '#pop'),
-            (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
-            (r'[^\\"\n]+', String),  # all other characters
-            (r'\\\n', String),       # line continuation
-            (r'\\', String),         # stray backslash
-        ],
-        'macro': [
-            (r'[^/\n]+', Comment.Preproc),
-            (r'/\*(.|\n)*?\*/', Comment.Multiline),
-            (r'//.*?\n', Comment.Single, '#pop'),
-            (r'/', Comment.Preproc),
-            (r'(?<=\\)\n', Comment.Preproc),
-            (r'\n', Comment.Preproc, '#pop'),
-        ],
-        'if0': [
-            (r'^\s*#if.*?(?/-]', Operator),
-            (r'[()\[\],.;]', Punctuation),
-            (r'(switch|case|default|const|new|static|char|continue|break|'
-             r'if|else|for|while|do|operator|enum|'
-             r'public|return|sizeof|tagof|state|goto)\b', Keyword),
-            (r'(bool|Float)\b', Keyword.Type),
-            (r'(true|false)\b', Keyword.Constant),
-            (r'[a-zA-Z_]\w*', Name),
-        ],
-        'string': [
-            (r'"', String, '#pop'),
-            (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
-            (r'[^\\"\n]+', String),  # all other characters
-            (r'\\\n', String),       # line continuation
-            (r'\\', String),         # stray backslash
-        ],
-        'macro': [
-            (r'[^/\n]+', Comment.Preproc),
-            (r'/\*(.|\n)*?\*/', Comment.Multiline),
-            (r'//.*?\n', Comment.Single, '#pop'),
-            (r'/', Comment.Preproc),
-            (r'(?<=\\)\n', Comment.Preproc),
-            (r'\n', Comment.Preproc, '#pop'),
-        ],
-        'if0': [
-            (r'^\s*#if.*?(?<-]', Operator),
-            (r'[a-zA-Z][a-zA-Z0-9_-]*', Name),
-            (r'\?[a-zA-Z][a-zA-Z0-9_-]*', Name.Variable),
-            (r'[0-9]+\.[0-9]+', Number.Float),
-            (r'[0-9]+', Number.Integer),
-        ],
-        'keywords': [
-            (words((
-                ':requirements', ':types', ':constants',
-                ':predicates', ':functions', ':action', ':agent',
-                ':parameters', ':precondition', ':effect',
-                ':durative-action', ':duration', ':condition',
-                ':derived', ':domain', ':objects', ':init',
-                ':goal', ':metric', ':length', ':serial', ':parallel',
-                # the following are requirements
-                ':strips', ':typing', ':negative-preconditions',
-                ':disjunctive-preconditions', ':equality',
-                ':existential-preconditions', ':universal-preconditions',
-                ':conditional-effects', ':fluents', ':numeric-fluents',
-                ':object-fluents', ':adl', ':durative-actions',
-                ':continuous-effects', ':derived-predicates',
-                ':time-intial-literals', ':preferences',
-                ':constraints', ':action-costs', ':multi-agent',
-                ':unfactored-privacy', ':factored-privacy',
-                ':non-deterministic'
-                ), suffix=r'\b'), Keyword)
-        ],
-        'builtins': [
-            (words((
-                'define', 'domain', 'object', 'either', 'and',
-                'forall', 'preference', 'imply', 'or', 'exists',
-                'not', 'when', 'assign', 'scale-up', 'scale-down',
-                'increase', 'decrease', 'at', 'over', 'start',
-                'end', 'all', 'problem', 'always', 'sometime',
-                'within', 'at-most-once', 'sometime-after',
-                'sometime-before', 'always-within', 'hold-during',
-                'hold-after', 'minimize', 'maximize',
-                'total-time', 'is-violated'), suffix=r'\b'),
-                Name.Builtin)
-        ]
-    }
-
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/perl.py b/.venv/lib/python3.12/site-packages/pygments/lexers/perl.py
deleted file mode 100644
index 7448d2a..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/perl.py
+++ /dev/null
@@ -1,733 +0,0 @@
-"""
-    pygments.lexers.perl
-    ~~~~~~~~~~~~~~~~~~~~
-
-    Lexers for Perl, Raku and related languages.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-import re
-
-from pygments.lexer import RegexLexer, ExtendedRegexLexer, include, bygroups, \
-    using, this, default, words
-from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
-    Number, Punctuation, Whitespace
-from pygments.util import shebang_matches
-
-__all__ = ['PerlLexer', 'Perl6Lexer']
-
-
-class PerlLexer(RegexLexer):
-    """
-    For Perl source code.
-    """
-
-    name = 'Perl'
-    url = 'https://www.perl.org'
-    aliases = ['perl', 'pl']
-    filenames = ['*.pl', '*.pm', '*.t', '*.perl']
-    mimetypes = ['text/x-perl', 'application/x-perl']
-    version_added = ''
-
-    flags = re.DOTALL | re.MULTILINE
-    # TODO: give this to a perl guy who knows how to parse perl...
-    tokens = {
-        'balanced-regex': [
-            (r'/(\\\\|\\[^\\]|[^\\/])*/[egimosx]*', String.Regex, '#pop'),
-            (r'!(\\\\|\\[^\\]|[^\\!])*![egimosx]*', String.Regex, '#pop'),
-            (r'\\(\\\\|[^\\])*\\[egimosx]*', String.Regex, '#pop'),
-            (r'\{(\\\\|\\[^\\]|[^\\}])*\}[egimosx]*', String.Regex, '#pop'),
-            (r'<(\\\\|\\[^\\]|[^\\>])*>[egimosx]*', String.Regex, '#pop'),
-            (r'\[(\\\\|\\[^\\]|[^\\\]])*\][egimosx]*', String.Regex, '#pop'),
-            (r'\((\\\\|\\[^\\]|[^\\)])*\)[egimosx]*', String.Regex, '#pop'),
-            (r'@(\\\\|\\[^\\]|[^\\@])*@[egimosx]*', String.Regex, '#pop'),
-            (r'%(\\\\|\\[^\\]|[^\\%])*%[egimosx]*', String.Regex, '#pop'),
-            (r'\$(\\\\|\\[^\\]|[^\\$])*\$[egimosx]*', String.Regex, '#pop'),
-        ],
-        'root': [
-            (r'\A\#!.+?$', Comment.Hashbang),
-            (r'\#.*?$', Comment.Single),
-            (r'^=[a-zA-Z0-9]+\s+.*?\n=cut', Comment.Multiline),
-            (words((
-                'case', 'continue', 'do', 'else', 'elsif', 'for', 'foreach',
-                'if', 'last', 'my', 'next', 'our', 'redo', 'reset', 'then',
-                'unless', 'until', 'while', 'print', 'new', 'BEGIN',
-                'CHECK', 'INIT', 'END', 'return'), suffix=r'\b'),
-             Keyword),
-            (r'(format)(\s+)(\w+)(\s*)(=)(\s*\n)',
-             bygroups(Keyword, Whitespace, Name, Whitespace, Punctuation, Whitespace), 'format'),
-            (r'(eq|lt|gt|le|ge|ne|not|and|or|cmp)\b', Operator.Word),
-            # common delimiters
-            (r's/(\\\\|\\[^\\]|[^\\/])*/(\\\\|\\[^\\]|[^\\/])*/[egimosx]*',
-                String.Regex),
-            (r's!(\\\\|\\!|[^!])*!(\\\\|\\!|[^!])*![egimosx]*', String.Regex),
-            (r's\\(\\\\|[^\\])*\\(\\\\|[^\\])*\\[egimosx]*', String.Regex),
-            (r's@(\\\\|\\[^\\]|[^\\@])*@(\\\\|\\[^\\]|[^\\@])*@[egimosx]*',
-                String.Regex),
-            (r's%(\\\\|\\[^\\]|[^\\%])*%(\\\\|\\[^\\]|[^\\%])*%[egimosx]*',
-                String.Regex),
-            # balanced delimiters
-            (r's\{(\\\\|\\[^\\]|[^\\}])*\}\s*', String.Regex, 'balanced-regex'),
-            (r's<(\\\\|\\[^\\]|[^\\>])*>\s*', String.Regex, 'balanced-regex'),
-            (r's\[(\\\\|\\[^\\]|[^\\\]])*\]\s*', String.Regex,
-                'balanced-regex'),
-            (r's\((\\\\|\\[^\\]|[^\\)])*\)\s*', String.Regex,
-                'balanced-regex'),
-
-            (r'm?/(\\\\|\\[^\\]|[^\\/\n])*/[gcimosx]*', String.Regex),
-            (r'm(?=[/!\\{<\[(@%$])', String.Regex, 'balanced-regex'),
-            (r'((?<==~)|(?<=\())\s*/(\\\\|\\[^\\]|[^\\/])*/[gcimosx]*',
-                String.Regex),
-            (r'\s+', Whitespace),
-            (words((
-                'abs', 'accept', 'alarm', 'atan2', 'bind', 'binmode', 'bless', 'caller', 'chdir',
-                'chmod', 'chomp', 'chop', 'chown', 'chr', 'chroot', 'close', 'closedir', 'connect',
-                'continue', 'cos', 'crypt', 'dbmclose', 'dbmopen', 'defined', 'delete', 'die',
-                'dump', 'each', 'endgrent', 'endhostent', 'endnetent', 'endprotoent',
-                'endpwent', 'endservent', 'eof', 'eval', 'exec', 'exists', 'exit', 'exp', 'fcntl',
-                'fileno', 'flock', 'fork', 'format', 'formline', 'getc', 'getgrent', 'getgrgid',
-                'getgrnam', 'gethostbyaddr', 'gethostbyname', 'gethostent', 'getlogin',
-                'getnetbyaddr', 'getnetbyname', 'getnetent', 'getpeername', 'getpgrp',
-                'getppid', 'getpriority', 'getprotobyname', 'getprotobynumber',
-                'getprotoent', 'getpwent', 'getpwnam', 'getpwuid', 'getservbyname',
-                'getservbyport', 'getservent', 'getsockname', 'getsockopt', 'glob', 'gmtime',
-                'goto', 'grep', 'hex', 'import', 'index', 'int', 'ioctl', 'join', 'keys', 'kill', 'last',
-                'lc', 'lcfirst', 'length', 'link', 'listen', 'local', 'localtime', 'log', 'lstat',
-                'map', 'mkdir', 'msgctl', 'msgget', 'msgrcv', 'msgsnd', 'my', 'next', 'oct', 'open',
-                'opendir', 'ord', 'our', 'pack', 'pipe', 'pop', 'pos', 'printf',
-                'prototype', 'push', 'quotemeta', 'rand', 'read', 'readdir',
-                'readline', 'readlink', 'readpipe', 'recv', 'redo', 'ref', 'rename',
-                'reverse', 'rewinddir', 'rindex', 'rmdir', 'scalar', 'seek', 'seekdir',
-                'select', 'semctl', 'semget', 'semop', 'send', 'setgrent', 'sethostent', 'setnetent',
-                'setpgrp', 'setpriority', 'setprotoent', 'setpwent', 'setservent',
-                'setsockopt', 'shift', 'shmctl', 'shmget', 'shmread', 'shmwrite', 'shutdown',
-                'sin', 'sleep', 'socket', 'socketpair', 'sort', 'splice', 'split', 'sprintf', 'sqrt',
-                'srand', 'stat', 'study', 'substr', 'symlink', 'syscall', 'sysopen', 'sysread',
-                'sysseek', 'system', 'syswrite', 'tell', 'telldir', 'tie', 'tied', 'time', 'times', 'tr',
-                'truncate', 'uc', 'ucfirst', 'umask', 'undef', 'unlink', 'unpack', 'unshift', 'untie',
-                'utime', 'values', 'vec', 'wait', 'waitpid', 'wantarray', 'warn', 'write'), suffix=r'\b'),
-             Name.Builtin),
-            (r'((__(DATA|DIE|WARN)__)|(STD(IN|OUT|ERR)))\b', Name.Builtin.Pseudo),
-            (r'(<<)([\'"]?)([a-zA-Z_]\w*)(\2;?\n.*?\n)(\3)(\n)',
-             bygroups(String, String, String.Delimiter, String, String.Delimiter, Whitespace)),
-            (r'__END__', Comment.Preproc, 'end-part'),
-            (r'\$\^[ADEFHILMOPSTWX]', Name.Variable.Global),
-            (r"\$[\\\"\[\]'&`+*.,;=%~?@$!<>(^|/-](?!\w)", Name.Variable.Global),
-            (r'[$@%#]+', Name.Variable, 'varname'),
-            (r'0_?[0-7]+(_[0-7]+)*', Number.Oct),
-            (r'0x[0-9A-Fa-f]+(_[0-9A-Fa-f]+)*', Number.Hex),
-            (r'0b[01]+(_[01]+)*', Number.Bin),
-            (r'(?i)(\d*(_\d*)*\.\d+(_\d*)*|\d+(_\d*)*\.\d+(_\d*)*)(e[+-]?\d+)?',
-             Number.Float),
-            (r'(?i)\d+(_\d*)*e[+-]?\d+(_\d*)*', Number.Float),
-            (r'\d+(_\d+)*', Number.Integer),
-            (r"'(\\\\|\\[^\\]|[^'\\])*'", String),
-            (r'"(\\\\|\\[^\\]|[^"\\])*"', String),
-            (r'`(\\\\|\\[^\\]|[^`\\])*`', String.Backtick),
-            (r'<([^\s>]+)>', String.Regex),
-            (r'(q|qq|qw|qr|qx)\{', String.Other, 'cb-string'),
-            (r'(q|qq|qw|qr|qx)\(', String.Other, 'rb-string'),
-            (r'(q|qq|qw|qr|qx)\[', String.Other, 'sb-string'),
-            (r'(q|qq|qw|qr|qx)\<', String.Other, 'lt-string'),
-            (r'(q|qq|qw|qr|qx)([\W_])(.|\n)*?\2', String.Other),
-            (r'(package)(\s+)([a-zA-Z_]\w*(?:::[a-zA-Z_]\w*)*)',
-             bygroups(Keyword, Whitespace, Name.Namespace)),
-            (r'(use|require|no)(\s+)([a-zA-Z_]\w*(?:::[a-zA-Z_]\w*)*)',
-             bygroups(Keyword, Whitespace, Name.Namespace)),
-            (r'(sub)(\s+)', bygroups(Keyword, Whitespace), 'funcname'),
-            (words((
-                'no', 'package', 'require', 'use'), suffix=r'\b'),
-             Keyword),
-            (r'(\[\]|\*\*|::|<<|>>|>=|<=>|<=|={3}|!=|=~|'
-             r'!~|&&?|\|\||\.{1,3})', Operator),
-            (r'[-+/*%=<>&^|!\\~]=?', Operator),
-            (r'[()\[\]:;,<>/?{}]', Punctuation),  # yes, there's no shortage
-                                                  # of punctuation in Perl!
-            (r'(?=\w)', Name, 'name'),
-        ],
-        'format': [
-            (r'\.\n', String.Interpol, '#pop'),
-            (r'[^\n]*\n', String.Interpol),
-        ],
-        'varname': [
-            (r'\s+', Whitespace),
-            (r'\{', Punctuation, '#pop'),    # hash syntax?
-            (r'\)|,', Punctuation, '#pop'),  # argument specifier
-            (r'\w+::', Name.Namespace),
-            (r'[\w:]+', Name.Variable, '#pop'),
-        ],
-        'name': [
-            (r'[a-zA-Z_]\w*(::[a-zA-Z_]\w*)*(::)?(?=\s*->)', Name.Namespace, '#pop'),
-            (r'[a-zA-Z_]\w*(::[a-zA-Z_]\w*)*::', Name.Namespace, '#pop'),
-            (r'[\w:]+', Name, '#pop'),
-            (r'[A-Z_]+(?=\W)', Name.Constant, '#pop'),
-            (r'(?=\W)', Text, '#pop'),
-        ],
-        'funcname': [
-            (r'[a-zA-Z_]\w*[!?]?', Name.Function),
-            (r'\s+', Whitespace),
-            # argument declaration
-            (r'(\([$@%]*\))(\s*)', bygroups(Punctuation, Whitespace)),
-            (r';', Punctuation, '#pop'),
-            (r'.*?\{', Punctuation, '#pop'),
-        ],
-        'cb-string': [
-            (r'\\[{}\\]', String.Other),
-            (r'\\', String.Other),
-            (r'\{', String.Other, 'cb-string'),
-            (r'\}', String.Other, '#pop'),
-            (r'[^{}\\]+', String.Other)
-        ],
-        'rb-string': [
-            (r'\\[()\\]', String.Other),
-            (r'\\', String.Other),
-            (r'\(', String.Other, 'rb-string'),
-            (r'\)', String.Other, '#pop'),
-            (r'[^()]+', String.Other)
-        ],
-        'sb-string': [
-            (r'\\[\[\]\\]', String.Other),
-            (r'\\', String.Other),
-            (r'\[', String.Other, 'sb-string'),
-            (r'\]', String.Other, '#pop'),
-            (r'[^\[\]]+', String.Other)
-        ],
-        'lt-string': [
-            (r'\\[<>\\]', String.Other),
-            (r'\\', String.Other),
-            (r'\<', String.Other, 'lt-string'),
-            (r'\>', String.Other, '#pop'),
-            (r'[^<>]+', String.Other)
-        ],
-        'end-part': [
-            (r'.+', Comment.Preproc, '#pop')
-        ]
-    }
-
-    def analyse_text(text):
-        if shebang_matches(text, r'perl'):
-            return True
-
-        result = 0
-
-        if re.search(r'(?:my|our)\s+[$@%(]', text):
-            result += 0.9
-
-        if ':=' in text:
-            # := is not valid Perl, but it appears in unicon, so we should
-            # become less confident if we think we found Perl with :=
-            result /= 2
-
-        return result
-
-
-class Perl6Lexer(ExtendedRegexLexer):
-    """
-    For Raku (a.k.a. Perl 6) source code.
-    """
-
-    name = 'Perl6'
-    url = 'https://www.raku.org'
-    aliases = ['perl6', 'pl6', 'raku']
-    filenames = ['*.pl', '*.pm', '*.nqp', '*.p6', '*.6pl', '*.p6l', '*.pl6',
-                 '*.6pm', '*.p6m', '*.pm6', '*.t', '*.raku', '*.rakumod',
-                 '*.rakutest', '*.rakudoc']
-    mimetypes = ['text/x-perl6', 'application/x-perl6']
-    version_added = '2.0'
-    flags = re.MULTILINE | re.DOTALL
-
-    PERL6_IDENTIFIER_RANGE = r"['\w:-]"
-
-    PERL6_KEYWORDS = (
-        #Phasers
-        'BEGIN','CATCH','CHECK','CLOSE','CONTROL','DOC','END','ENTER','FIRST',
-        'INIT','KEEP','LAST','LEAVE','NEXT','POST','PRE','QUIT','UNDO',
-        #Keywords
-        'anon','augment','but','class','constant','default','does','else',
-        'elsif','enum','for','gather','given','grammar','has','if','import',
-        'is','let','loop','made','make','method','module','multi','my','need',
-        'orwith','our','proceed','proto','repeat','require','return',
-        'return-rw','returns','role','rule','state','sub','submethod','subset',
-        'succeed','supersede','token','try','unit','unless','until','use',
-        'when','while','with','without',
-        #Traits
-        'export','native','repr','required','rw','symbol',
-    )
-
-    PERL6_BUILTINS = (
-        'ACCEPTS','abs','abs2rel','absolute','accept','accessed','acos',
-        'acosec','acosech','acosh','acotan','acotanh','acquire','act','action',
-        'actions','add','add_attribute','add_enum_value','add_fallback',
-        'add_method','add_parent','add_private_method','add_role','add_trustee',
-        'adverb','after','all','allocate','allof','allowed','alternative-names',
-        'annotations','antipair','antipairs','any','anyof','app_lifetime',
-        'append','arch','archname','args','arity','Array','asec','asech','asin',
-        'asinh','ASSIGN-KEY','ASSIGN-POS','assuming','ast','at','atan','atan2',
-        'atanh','AT-KEY','atomic-assign','atomic-dec-fetch','atomic-fetch',
-        'atomic-fetch-add','atomic-fetch-dec','atomic-fetch-inc',
-        'atomic-fetch-sub','atomic-inc-fetch','AT-POS','attributes','auth',
-        'await','backtrace','Bag','BagHash','bail-out','base','basename',
-        'base-repeating','batch','BIND-KEY','BIND-POS','bind-stderr',
-        'bind-stdin','bind-stdout','bind-udp','bits','bless','block','Bool',
-        'bool-only','bounds','break','Bridge','broken','BUILD','build-date',
-        'bytes','cache','callframe','calling-package','CALL-ME','callsame',
-        'callwith','can','cancel','candidates','cando','can-ok','canonpath',
-        'caps','caption','Capture','cas','catdir','categorize','categorize-list',
-        'catfile','catpath','cause','ceiling','cglobal','changed','Channel',
-        'chars','chdir','child','child-name','child-typename','chmod','chomp',
-        'chop','chr','chrs','chunks','cis','classify','classify-list','cleanup',
-        'clone','close','closed','close-stdin','cmp-ok','code','codes','collate',
-        'column','comb','combinations','command','comment','compiler','Complex',
-        'compose','compose_type','composer','condition','config',
-        'configure_destroy','configure_type_checking','conj','connect',
-        'constraints','construct','contains','contents','copy','cos','cosec',
-        'cosech','cosh','cotan','cotanh','count','count-only','cpu-cores',
-        'cpu-usage','CREATE','create_type','cross','cue','curdir','curupdir','d',
-        'Date','DateTime','day','daycount','day-of-month','day-of-week',
-        'day-of-year','days-in-month','declaration','decode','decoder','deepmap',
-        'default','defined','DEFINITE','delayed','DELETE-KEY','DELETE-POS',
-        'denominator','desc','DESTROY','destroyers','devnull','diag',
-        'did-you-mean','die','dies-ok','dir','dirname','dir-sep','DISTROnames',
-        'do','does','does-ok','done','done-testing','duckmap','dynamic','e',
-        'eager','earlier','elems','emit','enclosing','encode','encoder',
-        'encoding','end','ends-with','enum_from_value','enum_value_list',
-        'enum_values','enums','eof','EVAL','eval-dies-ok','EVALFILE',
-        'eval-lives-ok','exception','excludes-max','excludes-min','EXISTS-KEY',
-        'EXISTS-POS','exit','exitcode','exp','expected','explicitly-manage',
-        'expmod','extension','f','fail','fails-like','fc','feature','file',
-        'filename','find_method','find_method_qualified','finish','first','flat',
-        'flatmap','flip','floor','flunk','flush','fmt','format','formatter',
-        'freeze','from','from-list','from-loop','from-posix','full',
-        'full-barrier','get','get_value','getc','gist','got','grab','grabpairs',
-        'grep','handle','handled','handles','hardware','has_accessor','Hash',
-        'head','headers','hh-mm-ss','hidden','hides','hour','how','hyper','id',
-        'illegal','im','in','indent','index','indices','indir','infinite',
-        'infix','infix:<+>','infix:<->','install_method_cache','Instant',
-        'instead','Int','int-bounds','interval','in-timezone','invalid-str',
-        'invert','invocant','IO','IO::Notification.watch-path','is_trusted',
-        'is_type','isa','is-absolute','isa-ok','is-approx','is-deeply',
-        'is-hidden','is-initial-thread','is-int','is-lazy','is-leap-year',
-        'isNaN','isnt','is-prime','is-relative','is-routine','is-setting',
-        'is-win','item','iterator','join','keep','kept','KERNELnames','key',
-        'keyof','keys','kill','kv','kxxv','l','lang','last','lastcall','later',
-        'lazy','lc','leading','level','like','line','lines','link','List',
-        'listen','live','lives-ok','local','lock','log','log10','lookup','lsb',
-        'made','MAIN','make','Map','match','max','maxpairs','merge','message',
-        'method','method_table','methods','migrate','min','minmax','minpairs',
-        'minute','misplaced','Mix','MixHash','mkdir','mode','modified','month',
-        'move','mro','msb','multi','multiness','my','name','named','named_names',
-        'narrow','nativecast','native-descriptor','nativesizeof','new','new_type',
-        'new-from-daycount','new-from-pairs','next','nextcallee','next-handle',
-        'nextsame','nextwith','NFC','NFD','NFKC','NFKD','nl-in','nl-out',
-        'nodemap','nok','none','norm','not','note','now','nude','Num',
-        'numerator','Numeric','of','offset','offset-in-hours','offset-in-minutes',
-        'ok','old','on-close','one','on-switch','open','opened','operation',
-        'optional','ord','ords','orig','os-error','osname','out-buffer','pack',
-        'package','package-kind','package-name','packages','pair','pairs',
-        'pairup','parameter','params','parent','parent-name','parents','parse',
-        'parse-base','parsefile','parse-names','parts','pass','path','path-sep',
-        'payload','peer-host','peer-port','periods','perl','permutations','phaser',
-        'pick','pickpairs','pid','placeholder','plan','plus','polar','poll',
-        'polymod','pop','pos','positional','posix','postfix','postmatch',
-        'precomp-ext','precomp-target','pred','prefix','prematch','prepend',
-        'print','printf','print-nl','print-to','private','private_method_table',
-        'proc','produce','Promise','prompt','protect','pull-one','push',
-        'push-all','push-at-least','push-exactly','push-until-lazy','put',
-        'qualifier-type','quit','r','race','radix','rand','range','Rat','raw',
-        're','read','readchars','readonly','ready','Real','reallocate','reals',
-        'reason','rebless','receive','recv','redispatcher','redo','reduce',
-        'rel2abs','relative','release','rename','repeated','replacement',
-        'report','reserved','resolve','restore','result','resume','rethrow',
-        'reverse','right','rindex','rmdir','role','roles_to_compose','rolish',
-        'roll','rootdir','roots','rotate','rotor','round','roundrobin',
-        'routine-type','run','rwx','s','samecase','samemark','samewith','say',
-        'schedule-on','scheduler','scope','sec','sech','second','seek','self',
-        'send','Set','set_hidden','set_name','set_package','set_rw','set_value',
-        'SetHash','set-instruments','setup_finalization','shape','share','shell',
-        'shift','sibling','sigil','sign','signal','signals','signature','sin',
-        'sinh','sink','sink-all','skip','skip-at-least','skip-at-least-pull-one',
-        'skip-one','skip-rest','sleep','sleep-timer','sleep-until','Slip','slurp',
-        'slurp-rest','slurpy','snap','snapper','so','socket-host','socket-port',
-        'sort','source','source-package','spawn','SPEC','splice','split',
-        'splitdir','splitpath','sprintf','spurt','sqrt','squish','srand','stable',
-        'start','started','starts-with','status','stderr','stdout','Str',
-        'sub_signature','subbuf','subbuf-rw','subname','subparse','subst',
-        'subst-mutate','substr','substr-eq','substr-rw','subtest','succ','sum',
-        'Supply','symlink','t','tail','take','take-rw','tan','tanh','tap',
-        'target','target-name','tc','tclc','tell','then','throttle','throw',
-        'throws-like','timezone','tmpdir','to','today','todo','toggle','to-posix',
-        'total','trailing','trans','tree','trim','trim-leading','trim-trailing',
-        'truncate','truncated-to','trusts','try_acquire','trying','twigil','type',
-        'type_captures','typename','uc','udp','uncaught_handler','unimatch',
-        'uniname','uninames','uniparse','uniprop','uniprops','unique','unival',
-        'univals','unlike','unlink','unlock','unpack','unpolar','unshift',
-        'unwrap','updir','USAGE','use-ok','utc','val','value','values','VAR',
-        'variable','verbose-config','version','VMnames','volume','vow','w','wait',
-        'warn','watch','watch-path','week','weekday-of-month','week-number',
-        'week-year','WHAT','when','WHERE','WHEREFORE','WHICH','WHO',
-        'whole-second','WHY','wordcase','words','workaround','wrap','write',
-        'write-to','x','yada','year','yield','yyyy-mm-dd','z','zip','zip-latest',
-
-    )
-
-    PERL6_BUILTIN_CLASSES = (
-        #Booleans
-        'False','True',
-        #Classes
-        'Any','Array','Associative','AST','atomicint','Attribute','Backtrace',
-        'Backtrace::Frame','Bag','Baggy','BagHash','Blob','Block','Bool','Buf',
-        'Callable','CallFrame','Cancellation','Capture','CArray','Channel','Code',
-        'compiler','Complex','ComplexStr','Cool','CurrentThreadScheduler',
-        'Cursor','Date','Dateish','DateTime','Distro','Duration','Encoding',
-        'Exception','Failure','FatRat','Grammar','Hash','HyperWhatever','Instant',
-        'Int','int16','int32','int64','int8','IntStr','IO','IO::ArgFiles',
-        'IO::CatHandle','IO::Handle','IO::Notification','IO::Path',
-        'IO::Path::Cygwin','IO::Path::QNX','IO::Path::Unix','IO::Path::Win32',
-        'IO::Pipe','IO::Socket','IO::Socket::Async','IO::Socket::INET','IO::Spec',
-        'IO::Spec::Cygwin','IO::Spec::QNX','IO::Spec::Unix','IO::Spec::Win32',
-        'IO::Special','Iterable','Iterator','Junction','Kernel','Label','List',
-        'Lock','Lock::Async','long','longlong','Macro','Map','Match',
-        'Metamodel::AttributeContainer','Metamodel::C3MRO','Metamodel::ClassHOW',
-        'Metamodel::EnumHOW','Metamodel::Finalization','Metamodel::MethodContainer',
-        'Metamodel::MROBasedMethodDispatch','Metamodel::MultipleInheritance',
-        'Metamodel::Naming','Metamodel::Primitives','Metamodel::PrivateMethodContainer',
-        'Metamodel::RoleContainer','Metamodel::Trusting','Method','Mix','MixHash',
-        'Mixy','Mu','NFC','NFD','NFKC','NFKD','Nil','Num','num32','num64',
-        'Numeric','NumStr','ObjAt','Order','Pair','Parameter','Perl','Pod::Block',
-        'Pod::Block::Code','Pod::Block::Comment','Pod::Block::Declarator',
-        'Pod::Block::Named','Pod::Block::Para','Pod::Block::Table','Pod::Heading',
-        'Pod::Item','Pointer','Positional','PositionalBindFailover','Proc',
-        'Proc::Async','Promise','Proxy','PseudoStash','QuantHash','Range','Rat',
-        'Rational','RatStr','Real','Regex','Routine','Scalar','Scheduler',
-        'Semaphore','Seq','Set','SetHash','Setty','Signature','size_t','Slip',
-        'Stash','Str','StrDistance','Stringy','Sub','Submethod','Supplier',
-        'Supplier::Preserving','Supply','Systemic','Tap','Telemetry',
-        'Telemetry::Instrument::Thread','Telemetry::Instrument::Usage',
-        'Telemetry::Period','Telemetry::Sampler','Thread','ThreadPoolScheduler',
-        'UInt','uint16','uint32','uint64','uint8','Uni','utf8','Variable',
-        'Version','VM','Whatever','WhateverCode','WrapHandle'
-    )
-
-    PERL6_OPERATORS = (
-        'X', 'Z', 'after', 'also', 'and', 'andthen', 'before', 'cmp', 'div',
-        'eq', 'eqv', 'extra', 'ff', 'fff', 'ge', 'gt', 'le', 'leg', 'lt', 'm',
-        'mm', 'mod', 'ne', 'or', 'orelse', 'rx', 's', 'tr', 'x', 'xor', 'xx',
-        '++', '--', '**', '!', '+', '-', '~', '?', '|', '||', '+^', '~^', '?^',
-        '^', '*', '/', '%', '%%', '+&', '+<', '+>', '~&', '~<', '~>', '?&',
-        'gcd', 'lcm', '+', '-', '+|', '+^', '~|', '~^', '?|', '?^',
-        '~', '&', '^', 'but', 'does', '<=>', '..', '..^', '^..', '^..^',
-        '!=', '==', '<', '<=', '>', '>=', '~~', '===', '!eqv',
-        '&&', '||', '^^', '//', 'min', 'max', '??', '!!', 'ff', 'fff', 'so',
-        'not', '<==', '==>', '<<==', '==>>','unicmp',
-    )
-
-    # Perl 6 has a *lot* of possible bracketing characters
-    # this list was lifted from STD.pm6 (https://github.com/perl6/std)
-    PERL6_BRACKETS = {
-        '\u0028': '\u0029', '\u003c': '\u003e', '\u005b': '\u005d',
-        '\u007b': '\u007d', '\u00ab': '\u00bb', '\u0f3a': '\u0f3b',
-        '\u0f3c': '\u0f3d', '\u169b': '\u169c', '\u2018': '\u2019',
-        '\u201a': '\u2019', '\u201b': '\u2019', '\u201c': '\u201d',
-        '\u201e': '\u201d', '\u201f': '\u201d', '\u2039': '\u203a',
-        '\u2045': '\u2046', '\u207d': '\u207e', '\u208d': '\u208e',
-        '\u2208': '\u220b', '\u2209': '\u220c', '\u220a': '\u220d',
-        '\u2215': '\u29f5', '\u223c': '\u223d', '\u2243': '\u22cd',
-        '\u2252': '\u2253', '\u2254': '\u2255', '\u2264': '\u2265',
-        '\u2266': '\u2267', '\u2268': '\u2269', '\u226a': '\u226b',
-        '\u226e': '\u226f', '\u2270': '\u2271', '\u2272': '\u2273',
-        '\u2274': '\u2275', '\u2276': '\u2277', '\u2278': '\u2279',
-        '\u227a': '\u227b', '\u227c': '\u227d', '\u227e': '\u227f',
-        '\u2280': '\u2281', '\u2282': '\u2283', '\u2284': '\u2285',
-        '\u2286': '\u2287', '\u2288': '\u2289', '\u228a': '\u228b',
-        '\u228f': '\u2290', '\u2291': '\u2292', '\u2298': '\u29b8',
-        '\u22a2': '\u22a3', '\u22a6': '\u2ade', '\u22a8': '\u2ae4',
-        '\u22a9': '\u2ae3', '\u22ab': '\u2ae5', '\u22b0': '\u22b1',
-        '\u22b2': '\u22b3', '\u22b4': '\u22b5', '\u22b6': '\u22b7',
-        '\u22c9': '\u22ca', '\u22cb': '\u22cc', '\u22d0': '\u22d1',
-        '\u22d6': '\u22d7', '\u22d8': '\u22d9', '\u22da': '\u22db',
-        '\u22dc': '\u22dd', '\u22de': '\u22df', '\u22e0': '\u22e1',
-        '\u22e2': '\u22e3', '\u22e4': '\u22e5', '\u22e6': '\u22e7',
-        '\u22e8': '\u22e9', '\u22ea': '\u22eb', '\u22ec': '\u22ed',
-        '\u22f0': '\u22f1', '\u22f2': '\u22fa', '\u22f3': '\u22fb',
-        '\u22f4': '\u22fc', '\u22f6': '\u22fd', '\u22f7': '\u22fe',
-        '\u2308': '\u2309', '\u230a': '\u230b', '\u2329': '\u232a',
-        '\u23b4': '\u23b5', '\u2768': '\u2769', '\u276a': '\u276b',
-        '\u276c': '\u276d', '\u276e': '\u276f', '\u2770': '\u2771',
-        '\u2772': '\u2773', '\u2774': '\u2775', '\u27c3': '\u27c4',
-        '\u27c5': '\u27c6', '\u27d5': '\u27d6', '\u27dd': '\u27de',
-        '\u27e2': '\u27e3', '\u27e4': '\u27e5', '\u27e6': '\u27e7',
-        '\u27e8': '\u27e9', '\u27ea': '\u27eb', '\u2983': '\u2984',
-        '\u2985': '\u2986', '\u2987': '\u2988', '\u2989': '\u298a',
-        '\u298b': '\u298c', '\u298d': '\u298e', '\u298f': '\u2990',
-        '\u2991': '\u2992', '\u2993': '\u2994', '\u2995': '\u2996',
-        '\u2997': '\u2998', '\u29c0': '\u29c1', '\u29c4': '\u29c5',
-        '\u29cf': '\u29d0', '\u29d1': '\u29d2', '\u29d4': '\u29d5',
-        '\u29d8': '\u29d9', '\u29da': '\u29db', '\u29f8': '\u29f9',
-        '\u29fc': '\u29fd', '\u2a2b': '\u2a2c', '\u2a2d': '\u2a2e',
-        '\u2a34': '\u2a35', '\u2a3c': '\u2a3d', '\u2a64': '\u2a65',
-        '\u2a79': '\u2a7a', '\u2a7d': '\u2a7e', '\u2a7f': '\u2a80',
-        '\u2a81': '\u2a82', '\u2a83': '\u2a84', '\u2a8b': '\u2a8c',
-        '\u2a91': '\u2a92', '\u2a93': '\u2a94', '\u2a95': '\u2a96',
-        '\u2a97': '\u2a98', '\u2a99': '\u2a9a', '\u2a9b': '\u2a9c',
-        '\u2aa1': '\u2aa2', '\u2aa6': '\u2aa7', '\u2aa8': '\u2aa9',
-        '\u2aaa': '\u2aab', '\u2aac': '\u2aad', '\u2aaf': '\u2ab0',
-        '\u2ab3': '\u2ab4', '\u2abb': '\u2abc', '\u2abd': '\u2abe',
-        '\u2abf': '\u2ac0', '\u2ac1': '\u2ac2', '\u2ac3': '\u2ac4',
-        '\u2ac5': '\u2ac6', '\u2acd': '\u2ace', '\u2acf': '\u2ad0',
-        '\u2ad1': '\u2ad2', '\u2ad3': '\u2ad4', '\u2ad5': '\u2ad6',
-        '\u2aec': '\u2aed', '\u2af7': '\u2af8', '\u2af9': '\u2afa',
-        '\u2e02': '\u2e03', '\u2e04': '\u2e05', '\u2e09': '\u2e0a',
-        '\u2e0c': '\u2e0d', '\u2e1c': '\u2e1d', '\u2e20': '\u2e21',
-        '\u3008': '\u3009', '\u300a': '\u300b', '\u300c': '\u300d',
-        '\u300e': '\u300f', '\u3010': '\u3011', '\u3014': '\u3015',
-        '\u3016': '\u3017', '\u3018': '\u3019', '\u301a': '\u301b',
-        '\u301d': '\u301e', '\ufd3e': '\ufd3f', '\ufe17': '\ufe18',
-        '\ufe35': '\ufe36', '\ufe37': '\ufe38', '\ufe39': '\ufe3a',
-        '\ufe3b': '\ufe3c', '\ufe3d': '\ufe3e', '\ufe3f': '\ufe40',
-        '\ufe41': '\ufe42', '\ufe43': '\ufe44', '\ufe47': '\ufe48',
-        '\ufe59': '\ufe5a', '\ufe5b': '\ufe5c', '\ufe5d': '\ufe5e',
-        '\uff08': '\uff09', '\uff1c': '\uff1e', '\uff3b': '\uff3d',
-        '\uff5b': '\uff5d', '\uff5f': '\uff60', '\uff62': '\uff63',
-    }
-
-    def _build_word_match(words, boundary_regex_fragment=None, prefix='', suffix=''):
-        if boundary_regex_fragment is None:
-            return r'\b(' + prefix + r'|'.join(re.escape(x) for x in words) + \
-                suffix + r')\b'
-        else:
-            return r'(? 0:
-                    next_open_pos = text.find(opening_chars, search_pos + n_chars)
-                    next_close_pos = text.find(closing_chars, search_pos + n_chars)
-
-                    if next_close_pos == -1:
-                        next_close_pos = len(text)
-                        nesting_level = 0
-                    elif next_open_pos != -1 and next_open_pos < next_close_pos:
-                        nesting_level += 1
-                        search_pos = next_open_pos
-                    else:  # next_close_pos < next_open_pos
-                        nesting_level -= 1
-                        search_pos = next_close_pos
-
-                end_pos = next_close_pos
-
-            if end_pos < 0:     # if we didn't find a closer, just highlight the
-                                # rest of the text in this class
-                end_pos = len(text)
-
-            if adverbs is not None and re.search(r':to\b', adverbs):
-                heredoc_terminator = text[match.start('delimiter') + n_chars:end_pos]
-                end_heredoc = re.search(r'^\s*' + re.escape(heredoc_terminator) +
-                                        r'\s*$', text[end_pos:], re.MULTILINE)
-
-                if end_heredoc:
-                    end_pos += end_heredoc.end()
-                else:
-                    end_pos = len(text)
-
-            yield match.start(), token_class, text[match.start():end_pos + n_chars]
-            context.pos = end_pos + n_chars
-
-        return callback
-
-    def opening_brace_callback(lexer, match, context):
-        stack = context.stack
-
-        yield match.start(), Text, context.text[match.start():match.end()]
-        context.pos = match.end()
-
-        # if we encounter an opening brace and we're one level
-        # below a token state, it means we need to increment
-        # the nesting level for braces so we know later when
-        # we should return to the token rules.
-        if len(stack) > 2 and stack[-2] == 'token':
-            context.perl6_token_nesting_level += 1
-
-    def closing_brace_callback(lexer, match, context):
-        stack = context.stack
-
-        yield match.start(), Text, context.text[match.start():match.end()]
-        context.pos = match.end()
-
-        # if we encounter a free closing brace and we're one level
-        # below a token state, it means we need to check the nesting
-        # level to see if we need to return to the token state.
-        if len(stack) > 2 and stack[-2] == 'token':
-            context.perl6_token_nesting_level -= 1
-            if context.perl6_token_nesting_level == 0:
-                stack.pop()
-
-    def embedded_perl6_callback(lexer, match, context):
-        context.perl6_token_nesting_level = 1
-        yield match.start(), Text, context.text[match.start():match.end()]
-        context.pos = match.end()
-        context.stack.append('root')
-
-    # If you're modifying these rules, be careful if you need to process '{' or '}'
-    # characters. We have special logic for processing these characters (due to the fact
-    # that you can nest Perl 6 code in regex blocks), so if you need to process one of
-    # them, make sure you also process the corresponding one!
-    tokens = {
-        'common': [
-            (r'#[`|=](?P(?P[' + ''.join(PERL6_BRACKETS) + r'])(?P=first_char)*)',
-             brackets_callback(Comment.Multiline)),
-            (r'#[^\n]*$', Comment.Single),
-            (r'^(\s*)=begin\s+(\w+)\b.*?^\1=end\s+\2', Comment.Multiline),
-            (r'^(\s*)=for.*?\n\s*?\n', Comment.Multiline),
-            (r'^=.*?\n\s*?\n', Comment.Multiline),
-            (r'(regex|token|rule)(\s*' + PERL6_IDENTIFIER_RANGE + '+:sym)',
-             bygroups(Keyword, Name), 'token-sym-brackets'),
-            (r'(regex|token|rule)(?!' + PERL6_IDENTIFIER_RANGE + r')(\s*' + PERL6_IDENTIFIER_RANGE + '+)?',
-             bygroups(Keyword, Name), 'pre-token'),
-            # deal with a special case in the Perl 6 grammar (role q { ... })
-            (r'(role)(\s+)(q)(\s*)', bygroups(Keyword, Whitespace, Name, Whitespace)),
-            (_build_word_match(PERL6_KEYWORDS, PERL6_IDENTIFIER_RANGE), Keyword),
-            (_build_word_match(PERL6_BUILTIN_CLASSES, PERL6_IDENTIFIER_RANGE, suffix='(?::[UD])?'),
-             Name.Builtin),
-            (_build_word_match(PERL6_BUILTINS, PERL6_IDENTIFIER_RANGE), Name.Builtin),
-            # copied from PerlLexer
-            (r'[$@%&][.^:?=!~]?' + PERL6_IDENTIFIER_RANGE + '+(?:<<.*?>>|<.*?>|«.*?»)*',
-             Name.Variable),
-            (r'\$[!/](?:<<.*?>>|<.*?>|«.*?»)*', Name.Variable.Global),
-            (r'::\?\w+', Name.Variable.Global),
-            (r'[$@%&]\*' + PERL6_IDENTIFIER_RANGE + '+(?:<<.*?>>|<.*?>|«.*?»)*',
-             Name.Variable.Global),
-            (r'\$(?:<.*?>)+', Name.Variable),
-            (r'(?:q|qq|Q)[a-zA-Z]?\s*(?P:[\w\s:]+)?\s*(?P(?P[^0-9a-zA-Z:\s])'
-             r'(?P=first_char)*)', brackets_callback(String)),
-            # copied from PerlLexer
-            (r'0_?[0-7]+(_[0-7]+)*', Number.Oct),
-            (r'0x[0-9A-Fa-f]+(_[0-9A-Fa-f]+)*', Number.Hex),
-            (r'0b[01]+(_[01]+)*', Number.Bin),
-            (r'(?i)(\d*(_\d*)*\.\d+(_\d*)*|\d+(_\d*)*\.\d+(_\d*)*)(e[+-]?\d+)?',
-             Number.Float),
-            (r'(?i)\d+(_\d*)*e[+-]?\d+(_\d*)*', Number.Float),
-            (r'\d+(_\d+)*', Number.Integer),
-            (r'(?<=~~)\s*/(?:\\\\|\\/|.)*?/', String.Regex),
-            (r'(?<=[=(,])\s*/(?:\\\\|\\/|.)*?/', String.Regex),
-            (r'm\w+(?=\()', Name),
-            (r'(?:m|ms|rx)\s*(?P:[\w\s:]+)?\s*(?P(?P[^\w:\s])'
-             r'(?P=first_char)*)', brackets_callback(String.Regex)),
-            (r'(?:s|ss|tr)\s*(?::[\w\s:]+)?\s*/(?:\\\\|\\/|.)*?/(?:\\\\|\\/|.)*?/',
-             String.Regex),
-            (r'<[^\s=].*?\S>', String),
-            (_build_word_match(PERL6_OPERATORS), Operator),
-            (r'\w' + PERL6_IDENTIFIER_RANGE + '*', Name),
-            (r"'(\\\\|\\[^\\]|[^'\\])*'", String),
-            (r'"(\\\\|\\[^\\]|[^"\\])*"', String),
-        ],
-        'root': [
-            include('common'),
-            (r'\{', opening_brace_callback),
-            (r'\}', closing_brace_callback),
-            (r'.+?', Text),
-        ],
-        'pre-token': [
-            include('common'),
-            (r'\{', Text, ('#pop', 'token')),
-            (r'.+?', Text),
-        ],
-        'token-sym-brackets': [
-            (r'(?P(?P[' + ''.join(PERL6_BRACKETS) + '])(?P=first_char)*)',
-             brackets_callback(Name), ('#pop', 'pre-token')),
-            default(('#pop', 'pre-token')),
-        ],
-        'token': [
-            (r'\}', Text, '#pop'),
-            (r'(?<=:)(?:my|our|state|constant|temp|let).*?;', using(this)),
-            # make sure that quotes in character classes aren't treated as strings
-            (r'<(?:[-!?+.]\s*)?\[.*?\]>', String.Regex),
-            # make sure that '#' characters in quotes aren't treated as comments
-            (r"(?my|our)\s+)?(?:module|class|role|enum|grammar)', line)
-            if class_decl:
-                if saw_perl_decl or class_decl.group('scope') is not None:
-                    return True
-                rating = 0.05
-                continue
-            break
-
-        if ':=' in text:
-            # Same logic as above for PerlLexer
-            rating /= 2
-
-        return rating
-
-    def __init__(self, **options):
-        super().__init__(**options)
-        self.encoding = options.get('encoding', 'utf-8')
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/phix.py b/.venv/lib/python3.12/site-packages/pygments/lexers/phix.py
deleted file mode 100644
index c4cb35d..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/phix.py
+++ /dev/null
@@ -1,363 +0,0 @@
-"""
-    pygments.lexers.phix
-    ~~~~~~~~~~~~~~~~~~~~
-
-    Lexers for Phix.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-import re
-
-from pygments.lexer import RegexLexer, words
-from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
-    Whitespace
-
-__all__ = ['PhixLexer']
-
-
-class PhixLexer(RegexLexer):
-    """
-    Pygments Lexer for Phix files (.exw).
-    See http://phix.x10.mx
-    """
-
-    name = 'Phix'
-    url = 'http://phix.x10.mx'
-    aliases = ['phix']
-    filenames = ['*.exw']
-    mimetypes = ['text/x-phix']
-    version_added = '2.14'
-
-    flags = re.MULTILINE    # nb: **NOT** re.DOTALL! (totally spanners comment handling)
-
-    preproc = (
-        'ifdef', 'elsifdef', 'elsedef'
-    )
-    # Note these lists are auto-generated by pwa/p2js.exw, when pwa\src\p2js_keywords.e (etc)
-    #     change, though of course subsequent copy/commit/pull requests are all manual steps.
-    types = (
-        'string', 'nullable_string', 'atom_string', 'atom', 'bool', 'boolean',
-        'cdCanvan', 'cdCanvas', 'complex', 'CURLcode', 'dictionary', 'int',
-        'integer', 'Ihandle', 'Ihandles', 'Ihandln', 'mpfr', 'mpq', 'mpz',
-        'mpz_or_string', 'number', 'rid_string', 'seq', 'sequence', 'timedate',
-        'object'
-    )
-    keywords = (
-        'abstract', 'class', 'continue', 'export', 'extends', 'nullable',
-        'private', 'public', 'static', 'struct', 'trace',
-        'and', 'break', 'by', 'case', 'catch', 'const', 'constant', 'debug',
-        'default', 'do', 'else', 'elsif', 'end', 'enum', 'exit', 'fallthru',
-        'fallthrough', 'for', 'forward', 'function', 'global', 'if', 'in',
-        'include', 'js', 'javascript', 'javascript_semantics', 'let', 'not',
-        'or', 'procedure', 'profile', 'profile_time', 'return', 'safe_mode',
-        'switch', 'then', 'to', 'try', 'type', 'type_check', 'until', 'warning',
-        'while', 'with', 'without', 'xor'
-    )
-    routines = (
-        'abort', 'abs', 'adjust_timedate', 'and_bits', 'and_bitsu', 'apply',
-        'append', 'arccos', 'arcsin', 'arctan', 'assert', 'atan2',
-        'atom_to_float32', 'atom_to_float64', 'bankers_rounding', 'beep',
-        'begins', 'binary_search', 'bits_to_int', 'bk_color', 'bytes_to_int',
-        'call_func', 'call_proc', 'cdCanvasActivate', 'cdCanvasArc',
-        'cdCanvasBegin', 'cdCanvasBox', 'cdCanvasChord', 'cdCanvasCircle',
-        'cdCanvasClear', 'cdCanvasEnd', 'cdCanvasFlush', 'cdCanvasFont',
-        'cdCanvasGetImageRGB', 'cdCanvasGetSize', 'cdCanvasGetTextAlignment',
-        'cdCanvasGetTextSize', 'cdCanvasLine', 'cdCanvasMark',
-        'cdCanvasMarkSize', 'cdCanvasMultiLineVectorText', 'cdCanvasPixel',
-        'cdCanvasRect', 'cdCanvasRoundedBox', 'cdCanvasRoundedRect',
-        'cdCanvasSector', 'cdCanvasSetAttribute', 'cdCanvasSetBackground',
-        'cdCanvasSetFillMode', 'cdCanvasSetForeground',
-        'cdCanvasSetInteriorStyle', 'cdCanvasSetLineStyle',
-        'cdCanvasSetLineWidth', 'cdCanvasSetTextAlignment', 'cdCanvasText',
-        'cdCanvasSetTextOrientation', 'cdCanvasGetTextOrientation',
-        'cdCanvasVectorText', 'cdCanvasVectorTextDirection',
-        'cdCanvasVectorTextSize', 'cdCanvasVertex', 'cdCreateCanvas',
-        'cdDecodeAlpha', 'cdDecodeColor', 'cdDecodeColorAlpha', 'cdEncodeAlpha',
-        'cdEncodeColor', 'cdEncodeColorAlpha', 'cdKillCanvas', 'cdVersion',
-        'cdVersionDate', 'ceil', 'change_timezone', 'choose', 'clear_screen',
-        'columnize', 'command_line', 'compare', 'complex_abs', 'complex_add',
-        'complex_arg', 'complex_conjugate', 'complex_cos', 'complex_cosh',
-        'complex_div', 'complex_exp', 'complex_imag', 'complex_inv',
-        'complex_log', 'complex_mul', 'complex_neg', 'complex_new',
-        'complex_norm', 'complex_power', 'complex_rho', 'complex_real',
-        'complex_round', 'complex_sin', 'complex_sinh', 'complex_sprint',
-        'complex_sqrt', 'complex_sub', 'complex_theta', 'concat', 'cos',
-        'crash', 'custom_sort', 'date', 'day_of_week', 'day_of_year',
-        'days_in_month', 'decode_base64', 'decode_flags', 'deep_copy', 'deld',
-        'deserialize', 'destroy_dict', 'destroy_queue', 'destroy_stack',
-        'dict_name', 'dict_size', 'elapsed', 'elapsed_short', 'encode_base64',
-        'equal', 'even', 'exp', 'extract', 'factorial', 'factors',
-        'file_size_k', 'find', 'find_all', 'find_any', 'find_replace', 'filter',
-        'flatten', 'float32_to_atom', 'float64_to_atom', 'floor',
-        'format_timedate', 'free_console', 'from_polar', 'gcd', 'get_file_base',
-        'get_file_extension', 'get_file_name', 'get_file_name_and_path',
-        'get_file_path', 'get_file_path_and_name', 'get_maxprime', 'get_prime',
-        'get_primes', 'get_primes_le', 'get_proper_dir', 'get_proper_path',
-        'get_rand', 'get_routine_info', 'get_test_abort', 'get_test_logfile',
-        'get_test_pause', 'get_test_verbosity', 'get_tzid', 'getd', 'getdd',
-        'getd_all_keys', 'getd_by_index', 'getd_index', 'getd_partial_key',
-        'glAttachShader', 'glBindBuffer', 'glBindTexture', 'glBufferData',
-        'glCanvasSpecialText', 'glClear', 'glClearColor', 'glColor',
-        'glCompileShader', 'glCreateBuffer', 'glCreateProgram',
-        'glCreateShader', 'glCreateTexture', 'glDeleteProgram',
-        'glDeleteShader', 'glDrawArrays', 'glEnable',
-        'glEnableVertexAttribArray', 'glFloat32Array', 'glInt32Array',
-        'glFlush', 'glGetAttribLocation', 'glGetError', 'glGetProgramInfoLog',
-        'glGetProgramParameter', 'glGetShaderInfoLog', 'glGetShaderParameter',
-        'glGetUniformLocation', 'glLinkProgram', 'glLoadIdentity',
-        'glMatrixMode', 'glOrtho', 'glRotatef', 'glShadeModel',
-        'glShaderSource', 'glSimpleA7texcoords', 'glTexImage2Dc',
-        'glTexParameteri', 'glTranslate', 'glUniform1f', 'glUniform1i',
-        'glUniformMatrix4fv', 'glUseProgram', 'glVertex',
-        'glVertexAttribPointer', 'glViewport', 'head', 'hsv_to_rgb', 'iff',
-        'iif', 'include_file', 'incl0de_file', 'insert', 'instance',
-        'int_to_bits', 'int_to_bytes', 'is_dict', 'is_integer', 's_leap_year',
-        'is_prime', 'is_prime2', 'islower', 'isupper', 'Icallback',
-        'iup_isdouble', 'iup_isprint', 'iup_XkeyBase', 'IupAppend', 'IupAlarm',
-        'IupBackgroundBox', 'IupButton', 'IupCalendar', 'IupCanvas',
-        'IupClipboard', 'IupClose', 'IupCloseOnEscape', 'IupControlsOpen',
-        'IupDatePick', 'IupDestroy', 'IupDialog', 'IupDrawArc', 'IupDrawBegin',
-        'IupDrawEnd', 'IupDrawGetSize', 'IupDrawGetTextSize', 'IupDrawLine',
-        'IupDrawRectangle', 'IupDrawText', 'IupExpander', 'IupFill',
-        'IupFlatLabel', 'IupFlatList', 'IupFlatTree', 'IupFlush', 'IupFrame',
-        'IupGetAttribute', 'IupGetAttributeId', 'IupGetAttributePtr',
-        'IupGetBrother', 'IupGetChild', 'IupGetChildCount', 'IupGetClassName',
-        'IupGetDialog', 'IupGetDialogChild', 'IupGetDouble', 'IupGetFocus',
-        'IupGetGlobal', 'IupGetGlobalInt', 'IupGetGlobalIntInt', 'IupGetInt',
-        'IupGetInt2', 'IupGetIntId', 'IupGetIntInt', 'IupGetParent',
-        'IupGLCanvas', 'IupGLCanvasOpen', 'IupGLMakeCurrent', 'IupGraph',
-        'IupHbox', 'IupHide', 'IupImage', 'IupImageRGBA', 'IupItem',
-        'iupKeyCodeToName', 'IupLabel', 'IupLink', 'IupList', 'IupMap',
-        'IupMenu', 'IupMenuItem', 'IupMessage', 'IupMessageDlg', 'IupMultiBox',
-        'IupMultiLine', 'IupNextField', 'IupNormaliser', 'IupOpen',
-        'IupPlayInput', 'IupPopup', 'IupPreviousField', 'IupProgressBar',
-        'IupRadio', 'IupRecordInput', 'IupRedraw', 'IupRefresh',
-        'IupRefreshChildren', 'IupSeparator', 'IupSetAttribute',
-        'IupSetAttributes', 'IupSetAttributeHandle', 'IupSetAttributeId',
-        'IupSetAttributePtr', 'IupSetCallback', 'IupSetCallbacks',
-        'IupSetDouble', 'IupSetFocus', 'IupSetGlobal', 'IupSetGlobalInt',
-        'IupSetGlobalFunction', 'IupSetHandle', 'IupSetInt',
-        'IupSetStrAttribute', 'IupSetStrGlobal', 'IupShow', 'IupShowXY',
-        'IupSplit', 'IupStoreAttribute', 'IupSubmenu', 'IupTable',
-        'IupTableClearSelected', 'IupTableClick_cb', 'IupTableGetSelected',
-        'IupTableResize_cb', 'IupTableSetData', 'IupTabs', 'IupText',
-        'IupTimer', 'IupToggle', 'IupTreeAddNodes', 'IupTreeView', 'IupUpdate',
-        'IupValuator', 'IupVbox', 'join', 'join_by', 'join_path', 'k_perm',
-        'largest', 'lcm', 'length', 'log', 'log10', 'log2', 'lower',
-        'm4_crossProduct', 'm4_inverse', 'm4_lookAt', 'm4_multiply',
-        'm4_normalize', 'm4_perspective', 'm4_subtractVectors', 'm4_xRotate',
-        'm4_yRotate', 'machine_bits', 'machine_word', 'match', 'match_all',
-        'match_replace', 'max', 'maxsq', 'min', 'minsq', 'mod', 'mpfr_add',
-        'mpfr_ceil', 'mpfr_cmp', 'mpfr_cmp_si', 'mpfr_const_pi', 'mpfr_div',
-        'mpfr_div_si', 'mpfr_div_z', 'mpfr_floor', 'mpfr_free', 'mpfr_get_d',
-        'mpfr_get_default_precision', 'mpfr_get_default_rounding_mode',
-        'mpfr_get_fixed', 'mpfr_get_precision', 'mpfr_get_si', 'mpfr_init',
-        'mpfr_inits', 'mpfr_init_set', 'mpfr_init_set_q', 'mpfr_init_set_z',
-        'mpfr_mul', 'mpfr_mul_si', 'mpfr_pow_si', 'mpfr_set', 'mpfr_set_d',
-        'mpfr_set_default_precision', 'mpfr_set_default_rounding_mode',
-        'mpfr_set_precision', 'mpfr_set_q', 'mpfr_set_si', 'mpfr_set_str',
-        'mpfr_set_z', 'mpfr_si_div', 'mpfr_si_sub', 'mpfr_sqrt', 'mpfr_sub',
-        'mpfr_sub_si', 'mpq_abs', 'mpq_add', 'mpq_add_si', 'mpq_canonicalize',
-        'mpq_cmp', 'mpq_cmp_si', 'mpq_div', 'mpq_div_2exp', 'mpq_free',
-        'mpq_get_den', 'mpq_get_num', 'mpq_get_str', 'mpq_init', 'mpq_init_set',
-        'mpq_init_set_si', 'mpq_init_set_str', 'mpq_init_set_z', 'mpq_inits',
-        'mpq_inv', 'mpq_mul', 'mpq_neg', 'mpq_set', 'mpq_set_si', 'mpq_set_str',
-        'mpq_set_z', 'mpq_sub', 'mpz_abs', 'mpz_add', 'mpz_addmul',
-        'mpz_addmul_ui', 'mpz_addmul_si', 'mpz_add_si', 'mpz_add_ui', 'mpz_and',
-        'mpz_bin_uiui', 'mpz_cdiv_q', 'mpz_cmp', 'mpz_cmp_si', 'mpz_divexact',
-        'mpz_divexact_ui', 'mpz_divisible_p', 'mpz_divisible_ui_p', 'mpz_even',
-        'mpz_fac_ui', 'mpz_factorstring', 'mpz_fdiv_q', 'mpz_fdiv_q_2exp',
-        'mpz_fdiv_q_ui', 'mpz_fdiv_qr', 'mpz_fdiv_r', 'mpz_fdiv_ui',
-        'mpz_fib_ui', 'mpz_fib2_ui', 'mpz_fits_atom', 'mpz_fits_integer',
-        'mpz_free', 'mpz_gcd', 'mpz_gcd_ui', 'mpz_get_atom', 'mpz_get_integer',
-        'mpz_get_short_str', 'mpz_get_str', 'mpz_init', 'mpz_init_set',
-        'mpz_inits', 'mpz_invert', 'mpz_lcm', 'mpz_lcm_ui', 'mpz_max',
-        'mpz_min', 'mpz_mod', 'mpz_mod_ui', 'mpz_mul', 'mpz_mul_2exp',
-        'mpz_mul_d', 'mpz_mul_si', 'mpz_neg', 'mpz_nthroot', 'mpz_odd',
-        'mpz_pollard_rho', 'mpz_pow_ui', 'mpz_powm', 'mpz_powm_ui', 'mpz_prime',
-        'mpz_prime_factors', 'mpz_prime_mr', 'mpz_rand', 'mpz_rand_ui',
-        'mpz_re_compose', 'mpz_remove', 'mpz_scan0', 'mpz_scan1', 'mpz_set',
-        'mpz_set_d', 'mpz_set_si', 'mpz_set_str', 'mpz_set_v', 'mpz_sign',
-        'mpz_sizeinbase', 'mpz_sqrt', 'mpz_sub', 'mpz_sub_si', 'mpz_sub_ui',
-        'mpz_si_sub', 'mpz_tdiv_q_2exp', 'mpz_tdiv_r_2exp', 'mpz_tstbit',
-        'mpz_ui_pow_ui', 'mpz_xor', 'named_dict', 'new_dict', 'new_queue',
-        'new_stack', 'not_bits', 'not_bitsu', 'odd', 'or_all', 'or_allu',
-        'or_bits', 'or_bitsu', 'ord', 'ordinal', 'ordinant',
-        'override_timezone', 'pad', 'pad_head', 'pad_tail', 'parse_date_string',
-        'papply', 'peep', 'peepn', 'peep_dict', 'permute', 'permutes',
-        'platform', 'pop', 'popn', 'pop_dict', 'power', 'pp', 'ppEx', 'ppExf',
-        'ppf', 'ppOpt', 'pq_add', 'pq_destroy', 'pq_empty', 'pq_new', 'pq_peek',
-        'pq_pop', 'pq_pop_data', 'pq_size', 'prepend', 'prime_factors',
-        'printf', 'product', 'proper', 'push', 'pushn', 'putd', 'puts',
-        'queue_empty', 'queue_size', 'rand', 'rand_range', 'reinstate',
-        'remainder', 'remove', 'remove_all', 'repeat', 'repeatch', 'replace',
-        'requires', 'reverse', 'rfind', 'rgb', 'rmatch', 'rmdr', 'rnd', 'round',
-        'routine_id', 'scanf', 'serialize', 'series', 'set_rand',
-        'set_test_abort', 'set_test_logfile', 'set_test_module',
-        'set_test_pause', 'set_test_verbosity', 'set_timedate_formats',
-        'set_timezone', 'setd', 'setd_default', 'shorten', 'sha256',
-        'shift_bits', 'shuffle', 'sign', 'sin', 'smallest', 'sort',
-        'sort_columns', 'speak', 'splice', 'split', 'split_any', 'split_by',
-        'sprint', 'sprintf', 'sq_abs', 'sq_add', 'sq_and', 'sq_and_bits',
-        'sq_arccos', 'sq_arcsin', 'sq_arctan', 'sq_atom', 'sq_ceil', 'sq_cmp',
-        'sq_cos', 'sq_div', 'sq_even', 'sq_eq', 'sq_floor', 'sq_floor_div',
-        'sq_ge', 'sq_gt', 'sq_int', 'sq_le', 'sq_log', 'sq_log10', 'sq_log2',
-        'sq_lt', 'sq_max', 'sq_min', 'sq_mod', 'sq_mul', 'sq_ne', 'sq_not',
-        'sq_not_bits', 'sq_odd', 'sq_or', 'sq_or_bits', 'sq_power', 'sq_rand',
-        'sq_remainder', 'sq_rmdr', 'sq_rnd', 'sq_round', 'sq_seq', 'sq_sign',
-        'sq_sin', 'sq_sqrt', 'sq_str', 'sq_sub', 'sq_tan', 'sq_trunc',
-        'sq_uminus', 'sq_xor', 'sq_xor_bits', 'sqrt', 'square_free',
-        'stack_empty', 'stack_size', 'substitute', 'substitute_all', 'sum',
-        'tail', 'tan', 'test_equal', 'test_fail', 'test_false',
-        'test_not_equal', 'test_pass', 'test_summary', 'test_true',
-        'text_color', 'throw', 'time', 'timedate_diff', 'timedelta',
-        'to_integer', 'to_number', 'to_rgb', 'to_string', 'traverse_dict',
-        'traverse_dict_partial_key', 'trim', 'trim_head', 'trim_tail', 'trunc',
-        'tagset', 'tagstart', 'typeof', 'unique', 'unix_dict', 'upper',
-        'utf8_to_utf32', 'utf32_to_utf8', 'version', 'vlookup', 'vslice',
-        'wglGetProcAddress', 'wildcard_file', 'wildcard_match', 'with_rho',
-        'with_theta', 'xml_new_doc', 'xml_new_element', 'xml_set_attribute',
-        'xml_sprint', 'xor_bits', 'xor_bitsu',
-        'accept', 'allocate', 'allocate_string', 'allow_break', 'ARM',
-        'atom_to_float80', 'c_func', 'c_proc', 'call_back', 'chdir',
-        'check_break', 'clearDib', 'close', 'closesocket', 'console',
-        'copy_file', 'create', 'create_directory', 'create_thread',
-        'curl_easy_cleanup', 'curl_easy_get_file', 'curl_easy_init',
-        'curl_easy_perform', 'curl_easy_perform_ex', 'curl_easy_setopt',
-        'curl_easy_strerror', 'curl_global_cleanup', 'curl_global_init',
-        'curl_slist_append', 'curl_slist_free_all', 'current_dir', 'cursor',
-        'define_c_func', 'define_c_proc', 'delete', 'delete_cs', 'delete_file',
-        'dir', 'DLL', 'drawDib', 'drawShadedPolygonToDib', 'ELF32', 'ELF64',
-        'enter_cs', 'eval', 'exit_thread', 'free', 'file_exists', 'final',
-        'float80_to_atom', 'format', 'get_bytes', 'get_file_date',
-        'get_file_size', 'get_file_type', 'get_interpreter', 'get_key',
-        'get_socket_error', 'get_text', 'get_thread_exitcode', 'get_thread_id',
-        'getc', 'getenv', 'gets', 'getsockaddr', 'glBegin', 'glCallList',
-        'glFrustum', 'glGenLists', 'glGetString', 'glLight', 'glMaterial',
-        'glNewList', 'glNormal', 'glPopMatrix', 'glPushMatrix', 'glRotate',
-        'glEnd', 'glEndList', 'glTexImage2D', 'goto', 'GUI', 'icons', 'ilASM',
-        'include_files', 'include_paths', 'init_cs', 'ip_to_string',
-        'IupConfig', 'IupConfigDialogClosed', 'IupConfigDialogShow',
-        'IupConfigGetVariableInt', 'IupConfigLoad', 'IupConfigSave',
-        'IupConfigSetVariableInt', 'IupExitLoop', 'IupFileDlg', 'IupFileList',
-        'IupGLSwapBuffers', 'IupHelp', 'IupLoopStep', 'IupMainLoop',
-        'IupNormalizer', 'IupPlot', 'IupPlotAdd', 'IupPlotBegin', 'IupPlotEnd',
-        'IupPlotInsert', 'IupSaveImage', 'IupTreeGetUserId', 'IupUser',
-        'IupVersion', 'IupVersionDate', 'IupVersionNumber', 'IupVersionShow',
-        'killDib', 'leave_cs', 'listen', 'manifest', 'mem_copy', 'mem_set',
-        'mpfr_gamma', 'mpfr_printf', 'mpfr_sprintf', 'mpz_export', 'mpz_import',
-        'namespace', 'new', 'newDib', 'open', 'open_dll', 'PE32', 'PE64',
-        'peek', 'peek_string', 'peek1s', 'peek1u', 'peek2s', 'peek2u', 'peek4s',
-        'peek4u', 'peek8s', 'peek8u', 'peekNS', 'peekns', 'peeknu', 'poke',
-        'poke2', 'poke4', 'poke8', 'pokeN', 'poke_string', 'poke_wstring',
-        'position', 'progress', 'prompt_number', 'prompt_string', 'read_file',
-        'read_lines', 'recv', 'resume_thread', 'seek', 'select', 'send',
-        'setHandler', 'shutdown', 'sleep', 'SO', 'sockaddr_in', 'socket',
-        'split_path', 'suspend_thread', 'system', 'system_exec', 'system_open',
-        'system_wait', 'task_clock_start', 'task_clock_stop', 'task_create',
-        'task_delay', 'task_list', 'task_schedule', 'task_self', 'task_status',
-        'task_suspend', 'task_yield', 'thread_safe_string', 'try_cs',
-        'utf8_to_utf16', 'utf16_to_utf8', 'utf16_to_utf32', 'utf32_to_utf16',
-        'video_config', 'WSACleanup', 'wait_thread', 'walk_dir', 'where',
-        'write_lines', 'wait_key'
-    )
-    constants = (
-        'ANY_QUEUE', 'ASCENDING', 'BLACK', 'BLOCK_CURSOR', 'BLUE',
-        'BRIGHT_CYAN', 'BRIGHT_BLUE', 'BRIGHT_GREEN', 'BRIGHT_MAGENTA',
-        'BRIGHT_RED', 'BRIGHT_WHITE', 'BROWN', 'C_DWORD', 'C_INT', 'C_POINTER',
-        'C_USHORT', 'C_WORD', 'CD_AMBER', 'CD_BLACK', 'CD_BLUE', 'CD_BOLD',
-        'CD_BOLD_ITALIC', 'CD_BOX', 'CD_CENTER', 'CD_CIRCLE', 'CD_CLOSED_LINES',
-        'CD_CONTINUOUS', 'CD_CUSTOM', 'CD_CYAN', 'CD_DARK_BLUE', 'CD_DARK_CYAN',
-        'CD_DARK_GRAY', 'CD_DARK_GREY', 'CD_DARK_GREEN', 'CD_DARK_MAGENTA',
-        'CD_DARK_RED', 'CD_DARK_YELLOW', 'CD_DASH_DOT', 'CD_DASH_DOT_DOT',
-        'CD_DASHED', 'CD_DBUFFER', 'CD_DEG2RAD', 'CD_DIAMOND', 'CD_DOTTED',
-        'CD_EAST', 'CD_EVENODD', 'CD_FILL', 'CD_GL', 'CD_GRAY', 'CD_GREY',
-        'CD_GREEN', 'CD_HATCH', 'CD_HOLLOW', 'CD_HOLLOW_BOX',
-        'CD_HOLLOW_CIRCLE', 'CD_HOLLOW_DIAMOND', 'CD_INDIGO', 'CD_ITALIC',
-        'CD_IUP', 'CD_IUPDBUFFER', 'CD_LIGHT_BLUE', 'CD_LIGHT_GRAY',
-        'CD_LIGHT_GREY', 'CD_LIGHT_GREEN', 'CD_LIGHT_PARCHMENT', 'CD_MAGENTA',
-        'CD_NAVY', 'CD_NORTH', 'CD_NORTH_EAST', 'CD_NORTH_WEST', 'CD_OLIVE',
-        'CD_OPEN_LINES', 'CD_ORANGE', 'CD_PARCHMENT', 'CD_PATTERN',
-        'CD_PRINTER', 'CD_PURPLE', 'CD_PLAIN', 'CD_PLUS', 'CD_QUERY',
-        'CD_RAD2DEG', 'CD_RED', 'CD_SILVER', 'CD_SOLID', 'CD_SOUTH_EAST',
-        'CD_SOUTH_WEST', 'CD_STAR', 'CD_STIPPLE', 'CD_STRIKEOUT',
-        'CD_UNDERLINE', 'CD_WEST', 'CD_WHITE', 'CD_WINDING', 'CD_VIOLET',
-        'CD_X', 'CD_YELLOW', 'CURLE_OK', 'CURLOPT_MAIL_FROM',
-        'CURLOPT_MAIL_RCPT', 'CURLOPT_PASSWORD', 'CURLOPT_READDATA',
-        'CURLOPT_READFUNCTION', 'CURLOPT_SSL_VERIFYPEER',
-        'CURLOPT_SSL_VERIFYHOST', 'CURLOPT_UPLOAD', 'CURLOPT_URL',
-        'CURLOPT_USE_SSL', 'CURLOPT_USERNAME', 'CURLOPT_VERBOSE',
-        'CURLOPT_WRITEFUNCTION', 'CURLUSESSL_ALL', 'CYAN', 'D_NAME',
-        'D_ATTRIBUTES', 'D_SIZE', 'D_YEAR', 'D_MONTH', 'D_DAY', 'D_HOUR',
-        'D_MINUTE', 'D_SECOND', 'D_CREATION', 'D_LASTACCESS', 'D_MODIFICATION',
-        'DT_YEAR', 'DT_MONTH', 'DT_DAY', 'DT_HOUR', 'DT_MINUTE', 'DT_SECOND',
-        'DT_DOW', 'DT_MSEC', 'DT_DOY', 'DT_GMT', 'EULER', 'E_CODE', 'E_ADDR',
-        'E_LINE', 'E_RTN', 'E_NAME', 'E_FILE', 'E_PATH', 'E_USER', 'false',
-        'False', 'FALSE', 'FIFO_QUEUE', 'FILETYPE_DIRECTORY', 'FILETYPE_FILE',
-        'GET_EOF', 'GET_FAIL', 'GET_IGNORE', 'GET_SUCCESS',
-        'GL_AMBIENT_AND_DIFFUSE', 'GL_ARRAY_BUFFER', 'GL_CLAMP',
-        'GL_CLAMP_TO_BORDER', 'GL_CLAMP_TO_EDGE', 'GL_COLOR_BUFFER_BIT',
-        'GL_COMPILE', 'GL_COMPILE_STATUS', 'GL_CULL_FACE',
-        'GL_DEPTH_BUFFER_BIT', 'GL_DEPTH_TEST', 'GL_EXTENSIONS', 'GL_FLAT',
-        'GL_FLOAT', 'GL_FRAGMENT_SHADER', 'GL_FRONT', 'GL_LIGHT0',
-        'GL_LIGHTING', 'GL_LINEAR', 'GL_LINK_STATUS', 'GL_MODELVIEW',
-        'GL_NEAREST', 'GL_NO_ERROR', 'GL_NORMALIZE', 'GL_POSITION',
-        'GL_PROJECTION', 'GL_QUAD_STRIP', 'GL_QUADS', 'GL_RENDERER',
-        'GL_REPEAT', 'GL_RGB', 'GL_RGBA', 'GL_SMOOTH', 'GL_STATIC_DRAW',
-        'GL_TEXTURE_2D', 'GL_TEXTURE_MAG_FILTER', 'GL_TEXTURE_MIN_FILTER',
-        'GL_TEXTURE_WRAP_S', 'GL_TEXTURE_WRAP_T', 'GL_TRIANGLES',
-        'GL_UNSIGNED_BYTE', 'GL_VENDOR', 'GL_VERSION', 'GL_VERTEX_SHADER',
-        'GRAY', 'GREEN', 'GT_LF_STRIPPED', 'GT_WHOLE_FILE', 'INVLN10',
-        'IUP_CLOSE', 'IUP_CONTINUE', 'IUP_DEFAULT', 'IUP_BLACK', 'IUP_BLUE',
-        'IUP_BUTTON1', 'IUP_BUTTON3', 'IUP_CENTER', 'IUP_CYAN', 'IUP_DARK_BLUE',
-        'IUP_DARK_CYAN', 'IUP_DARK_GRAY', 'IUP_DARK_GREY', 'IUP_DARK_GREEN',
-        'IUP_DARK_MAGENTA', 'IUP_DARK_RED', 'IUP_GRAY', 'IUP_GREY', 'IUP_GREEN',
-        'IUP_IGNORE', 'IUP_INDIGO', 'IUP_MAGENTA', 'IUP_MASK_INT',
-        'IUP_MASK_UINT', 'IUP_MOUSEPOS', 'IUP_NAVY', 'IUP_OLIVE', 'IUP_RECTEXT',
-        'IUP_RED', 'IUP_LIGHT_BLUE', 'IUP_LIGHT_GRAY', 'IUP_LIGHT_GREY',
-        'IUP_LIGHT_GREEN', 'IUP_ORANGE', 'IUP_PARCHMENT', 'IUP_PURPLE',
-        'IUP_SILVER', 'IUP_TEAL', 'IUP_VIOLET', 'IUP_WHITE', 'IUP_YELLOW',
-        'K_BS', 'K_cA', 'K_cC', 'K_cD', 'K_cF5', 'K_cK', 'K_cM', 'K_cN', 'K_cO',
-        'K_cP', 'K_cR', 'K_cS', 'K_cT', 'K_cW', 'K_CR', 'K_DEL', 'K_DOWN',
-        'K_END', 'K_ESC', 'K_F1', 'K_F2', 'K_F3', 'K_F4', 'K_F5', 'K_F6',
-        'K_F7', 'K_F8', 'K_F9', 'K_F10', 'K_F11', 'K_F12', 'K_HOME', 'K_INS',
-        'K_LEFT', 'K_MIDDLE', 'K_PGDN', 'K_PGUP', 'K_RIGHT', 'K_SP', 'K_TAB',
-        'K_UP', 'K_h', 'K_i', 'K_j', 'K_p', 'K_r', 'K_s', 'JS', 'LIFO_QUEUE',
-        'LINUX', 'MAX_HEAP', 'MAGENTA', 'MIN_HEAP', 'Nan', 'NO_CURSOR', 'null',
-        'NULL', 'PI', 'pp_Ascii', 'pp_Brkt', 'pp_Date', 'pp_File', 'pp_FltFmt',
-        'pp_Indent', 'pp_IntCh', 'pp_IntFmt', 'pp_Maxlen', 'pp_Nest',
-        'pp_Pause', 'pp_Q22', 'pp_StrFmt', 'RED', 'SEEK_OK', 'SLASH',
-        'TEST_ABORT', 'TEST_CRASH', 'TEST_PAUSE', 'TEST_PAUSE_FAIL',
-        'TEST_QUIET', 'TEST_SHOW_ALL', 'TEST_SHOW_FAILED', 'TEST_SUMMARY',
-        'true', 'True', 'TRUE', 'VC_SCRNLINES', 'WHITE', 'WINDOWS', 'YELLOW'
-    )
-
-    tokens = {
-        'root': [
-            (r"\s+", Whitespace),
-            (r'/\*|--/\*|#\[', Comment.Multiline, 'comment'),
-            (r'(?://|--|#!).*$', Comment.Single),
-#Alt:
-#           (r'//.*$|--.*$|#!.*$', Comment.Single),
-            (r'"([^"\\]|\\.)*"', String.Other),
-            (r'\'[^\']*\'', String.Other),
-            (r'`[^`]*`', String.Other),
-
-            (words(types, prefix=r'\b', suffix=r'\b'), Name.Function),
-            (words(routines, prefix=r'\b', suffix=r'\b'), Name.Function),
-            (words(preproc, prefix=r'\b', suffix=r'\b'), Keyword.Declaration),
-            (words(keywords, prefix=r'\b', suffix=r'\b'), Keyword.Declaration),
-            (words(constants, prefix=r'\b', suffix=r'\b'), Name.Constant),
-            # Aside: Phix only supports/uses the ascii/non-unicode tilde
-            (r'!=|==|<<|>>|:=|[-~+/*%=<>&^|\.(){},?:\[\]$\\;#]', Operator),
-            (r'[\w-]+', Text)
-        ],
-        'comment': [
-            (r'[^*/#]+', Comment.Multiline),
-            (r'/\*|#\[', Comment.Multiline, '#push'),
-            (r'\*/|#\]', Comment.Multiline, '#pop'),
-            (r'[*/#]', Comment.Multiline)
-        ]
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/php.py b/.venv/lib/python3.12/site-packages/pygments/lexers/php.py
deleted file mode 100644
index ac935c4..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/php.py
+++ /dev/null
@@ -1,335 +0,0 @@
-"""
-    pygments.lexers.php
-    ~~~~~~~~~~~~~~~~~~~
-
-    Lexers for PHP and related languages.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-import re
-
-from pygments.lexer import Lexer, RegexLexer, include, bygroups, default, \
-    using, this, words, do_insertions, line_re
-from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
-    Number, Punctuation, Other, Generic
-from pygments.util import get_bool_opt, get_list_opt, shebang_matches
-
-__all__ = ['ZephirLexer', 'PsyshConsoleLexer', 'PhpLexer']
-
-
-class ZephirLexer(RegexLexer):
-    """
-    For Zephir language source code.
-
-    Zephir is a compiled high level language aimed
-    to the creation of C-extensions for PHP.
-    """
-
-    name = 'Zephir'
-    url = 'http://zephir-lang.com/'
-    aliases = ['zephir']
-    filenames = ['*.zep']
-    version_added = '2.0'
-
-    zephir_keywords = ['fetch', 'echo', 'isset', 'empty']
-    zephir_type = ['bit', 'bits', 'string']
-
-    flags = re.DOTALL | re.MULTILINE
-
-    tokens = {
-        'commentsandwhitespace': [
-            (r'\s+', Text),
-            (r'//.*?\n', Comment.Single),
-            (r'/\*.*?\*/', Comment.Multiline)
-        ],
-        'slashstartsregex': [
-            include('commentsandwhitespace'),
-            (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/'
-             r'([gim]+\b|\B)', String.Regex, '#pop'),
-            (r'/', Operator, '#pop'),
-            default('#pop')
-        ],
-        'badregex': [
-            (r'\n', Text, '#pop')
-        ],
-        'root': [
-            (r'^(?=\s|/)', Text, 'slashstartsregex'),
-            include('commentsandwhitespace'),
-            (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|'
-             r'(<<|>>>?|==?|!=?|->|[-<>+*%&|^/])=?', Operator, 'slashstartsregex'),
-            (r'[{(\[;,]', Punctuation, 'slashstartsregex'),
-            (r'[})\].]', Punctuation),
-            (r'(for|in|while|do|break|return|continue|switch|case|default|if|else|loop|'
-             r'require|inline|throw|try|catch|finally|new|delete|typeof|instanceof|void|'
-             r'namespace|use|extends|this|fetch|isset|unset|echo|fetch|likely|unlikely|'
-             r'empty)\b', Keyword, 'slashstartsregex'),
-            (r'(var|let|with|function)\b', Keyword.Declaration, 'slashstartsregex'),
-            (r'(abstract|boolean|bool|char|class|const|double|enum|export|extends|final|'
-             r'native|goto|implements|import|int|string|interface|long|ulong|char|uchar|'
-             r'float|unsigned|private|protected|public|short|static|self|throws|reverse|'
-             r'transient|volatile|readonly)\b', Keyword.Reserved),
-            (r'(true|false|null|undefined)\b', Keyword.Constant),
-            (r'(Array|Boolean|Date|_REQUEST|_COOKIE|_SESSION|'
-             r'_GET|_POST|_SERVER|this|stdClass|range|count|iterator|'
-             r'window)\b', Name.Builtin),
-            (r'[$a-zA-Z_][\w\\]*', Name.Other),
-            (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
-            (r'0x[0-9a-fA-F]+', Number.Hex),
-            (r'[0-9]+', Number.Integer),
-            (r'"(\\\\|\\[^\\]|[^"\\])*"', String.Double),
-            (r"'(\\\\|\\[^\\]|[^'\\])*'", String.Single),
-        ]
-    }
-
-
-class PsyshConsoleLexer(Lexer):
-    """
-    For PsySH console output, such as:
-
-    .. sourcecode:: psysh
-
-        >>> $greeting = function($name): string {
-        ...     return "Hello, {$name}";
-        ... };
-        => Closure($name): string {#2371 …3}
-        >>> $greeting('World')
-        => "Hello, World"
-    """
-    name = 'PsySH console session for PHP'
-    url = 'https://psysh.org/'
-    aliases = ['psysh']
-    version_added = '2.7'
-
-    def __init__(self, **options):
-        options['startinline'] = True
-        Lexer.__init__(self, **options)
-
-    def get_tokens_unprocessed(self, text):
-        phplexer = PhpLexer(**self.options)
-        curcode = ''
-        insertions = []
-        for match in line_re.finditer(text):
-            line = match.group()
-            if line.startswith('>>> ') or line.startswith('... '):
-                insertions.append((len(curcode),
-                                   [(0, Generic.Prompt, line[:4])]))
-                curcode += line[4:]
-            elif line.rstrip() == '...':
-                insertions.append((len(curcode),
-                                   [(0, Generic.Prompt, '...')]))
-                curcode += line[3:]
-            else:
-                if curcode:
-                    yield from do_insertions(
-                        insertions, phplexer.get_tokens_unprocessed(curcode))
-                    curcode = ''
-                    insertions = []
-                yield match.start(), Generic.Output, line
-        if curcode:
-            yield from do_insertions(insertions,
-                                     phplexer.get_tokens_unprocessed(curcode))
-
-
-class PhpLexer(RegexLexer):
-    """
-    For PHP source code.
-    For PHP embedded in HTML, use the `HtmlPhpLexer`.
-
-    Additional options accepted:
-
-    `startinline`
-        If given and ``True`` the lexer starts highlighting with
-        php code (i.e.: no starting ``>> from pygments.lexers._php_builtins import MODULES
-            >>> MODULES.keys()
-            ['PHP Options/Info', 'Zip', 'dba', ...]
-
-        In fact the names of those modules match the module names from
-        the php documentation.
-    """
-
-    name = 'PHP'
-    url = 'https://www.php.net/'
-    aliases = ['php', 'php3', 'php4', 'php5']
-    filenames = ['*.php', '*.php[345]', '*.inc']
-    mimetypes = ['text/x-php']
-    version_added = ''
-
-    # Note that a backslash is included, PHP uses a backslash as a namespace
-    # separator.
-    _ident_inner = r'(?:[\\_a-z]|[^\x00-\x7f])(?:[\\\w]|[^\x00-\x7f])*'
-    # But not inside strings.
-    _ident_nons = r'(?:[_a-z]|[^\x00-\x7f])(?:\w|[^\x00-\x7f])*'
-
-    flags = re.IGNORECASE | re.DOTALL | re.MULTILINE
-    tokens = {
-        'root': [
-            (r'<\?(php)?', Comment.Preproc, 'php'),
-            (r'[^<]+', Other),
-            (r'<', Other)
-        ],
-        'php': [
-            (r'\?>', Comment.Preproc, '#pop'),
-            (r'(<<<)([\'"]?)(' + _ident_nons + r')(\2\n.*?\n\s*)(\3)(;?)(\n)',
-             bygroups(String, String, String.Delimiter, String, String.Delimiter,
-                      Punctuation, Text)),
-            (r'\s+', Text),
-            (r'#\[', Punctuation, 'attribute'),
-            (r'#.*?\n', Comment.Single),
-            (r'//.*?\n', Comment.Single),
-            # put the empty comment here, it is otherwise seen as
-            # the start of a docstring
-            (r'/\*\*/', Comment.Multiline),
-            (r'/\*\*.*?\*/', String.Doc),
-            (r'/\*.*?\*/', Comment.Multiline),
-            (r'(->|::)(\s*)(' + _ident_nons + ')',
-             bygroups(Operator, Text, Name.Attribute)),
-            (r'[~!%^&*+=|:.<>/@-]+', Operator),
-            (r'\?', Operator),  # don't add to the charclass above!
-            (r'[\[\]{}();,]+', Punctuation),
-            (r'(new)(\s+)(class)\b', bygroups(Keyword, Text, Keyword)),
-            (r'(class)(\s+)', bygroups(Keyword, Text), 'classname'),
-            (r'(function)(\s*)(?=\()', bygroups(Keyword, Text)),
-            (r'(function)(\s+)(&?)(\s*)',
-             bygroups(Keyword, Text, Operator, Text), 'functionname'),
-            (r'(const)(\s+)(' + _ident_inner + ')',
-             bygroups(Keyword, Text, Name.Constant)),
-            # source: https://www.php.net/manual/en/reserved.keywords.php
-            (r'(and|E_PARSE|old_function|E_ERROR|or|as|E_WARNING|parent|'
-             r'eval|PHP_OS|break|exit|case|extends|PHP_VERSION|cfunction|'
-             r'FALSE|print|for|require|continue|foreach|require_once|'
-             r'declare|return|default|static|do|switch|die|stdClass|'
-             r'echo|else|TRUE|elseif|var|empty|if|xor|enddeclare|include|'
-             r'virtual|endfor|include_once|while|endforeach|global|'
-             r'endif|list|endswitch|new|endwhile|not|'
-             r'array|E_ALL|NULL|final|php_user_filter|interface|'
-             r'implements|public|private|protected|abstract|clone|try|'
-             r'catch|throw|this|use|namespace|trait|yield( from)?|'
-             r'finally|match|readonly)\b', Keyword),
-            (r'(true|false|null)\b', Keyword.Constant),
-            include('magicconstants'),
-            (r'\$\{', Name.Variable, 'variablevariable'),
-            (r'\$+' + _ident_inner, Name.Variable),
-            (_ident_inner, Name.Other),
-            (r'(\d+\.\d*|\d*\.\d+)(e[+-]?[0-9]+)?', Number.Float),
-            (r'\d+e[+-]?[0-9]+', Number.Float),
-            (r'0[0-7]+', Number.Oct),
-            (r'0x[a-f0-9]+', Number.Hex),
-            (r'\d+', Number.Integer),
-            (r'0b[01]+', Number.Bin),
-            (r"'([^'\\]*(?:\\.[^'\\]*)*)'", String.Single),
-            (r'`([^`\\]*(?:\\.[^`\\]*)*)`', String.Backtick),
-            (r'"', String.Double, 'string'),
-        ],
-        'variablevariable': [
-            (r'\}', Name.Variable, '#pop'),
-            include('php')
-        ],
-        'magicfuncs': [
-            # source: http://php.net/manual/en/language.oop5.magic.php
-            (words((
-                '__construct', '__destruct', '__call', '__callStatic', '__get', '__set',
-                '__isset', '__unset', '__sleep', '__wakeup', '__toString', '__invoke',
-                '__set_state', '__clone', '__debugInfo',), suffix=r'\b'),
-             Name.Function.Magic),
-        ],
-        'magicconstants': [
-            # source: https://www.php.net/manual/en/language.constants.magic.php
-            (words((
-                '__LINE__', '__FILE__', '__DIR__', '__FUNCTION__', '__CLASS__',
-                '__TRAIT__', '__METHOD__', '__NAMESPACE__', '__PROPERTY__',),
-                suffix=r'\b'),
-             Name.Constant),
-        ],
-        'classname': [
-            (_ident_inner, Name.Class, '#pop')
-        ],
-        'functionname': [
-            include('magicfuncs'),
-            (_ident_inner, Name.Function, '#pop'),
-            default('#pop')
-        ],
-        'string': [
-            (r'"', String.Double, '#pop'),
-            (r'[^{$"\\]+', String.Double),
-            (r'\\([nrt"$\\]|[0-7]{1,3}|x[0-9a-f]{1,2})', String.Escape),
-            (r'\$' + _ident_nons + r'(\[\S+?\]|->' + _ident_nons + ')?',
-             String.Interpol),
-            (r'(\{\$\{)(.*?)(\}\})',
-             bygroups(String.Interpol, using(this, _startinline=True),
-                      String.Interpol)),
-            (r'(\{)(\$.*?)(\})',
-             bygroups(String.Interpol, using(this, _startinline=True),
-                      String.Interpol)),
-            (r'(\$\{)(\S+)(\})',
-             bygroups(String.Interpol, Name.Variable, String.Interpol)),
-            (r'[${\\]', String.Double)
-        ],
-        'attribute': [
-            (r'\]', Punctuation, '#pop'),
-            (r'\(', Punctuation, 'attributeparams'),
-            (_ident_inner, Name.Decorator),
-            include('php')
-        ],
-        'attributeparams': [
-            (r'\)', Punctuation, '#pop'),
-            include('php')
-        ],
-    }
-
-    def __init__(self, **options):
-        self.funcnamehighlighting = get_bool_opt(
-            options, 'funcnamehighlighting', True)
-        self.disabledmodules = get_list_opt(
-            options, 'disabledmodules', ['unknown'])
-        self.startinline = get_bool_opt(options, 'startinline', False)
-
-        # private option argument for the lexer itself
-        if '_startinline' in options:
-            self.startinline = options.pop('_startinline')
-
-        # collect activated functions in a set
-        self._functions = set()
-        if self.funcnamehighlighting:
-            from pygments.lexers._php_builtins import MODULES
-            for key, value in MODULES.items():
-                if key not in self.disabledmodules:
-                    self._functions.update(value)
-        RegexLexer.__init__(self, **options)
-
-    def get_tokens_unprocessed(self, text):
-        stack = ['root']
-        if self.startinline:
-            stack.append('php')
-        for index, token, value in \
-                RegexLexer.get_tokens_unprocessed(self, text, stack):
-            if token is Name.Other:
-                if value in self._functions:
-                    yield index, Name.Builtin, value
-                    continue
-            yield index, token, value
-
-    def analyse_text(text):
-        if shebang_matches(text, r'php'):
-            return True
-        rv = 0.0
-        if re.search(r'<\?(?!xml)', text):
-            rv += 0.3
-        return rv
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/pointless.py b/.venv/lib/python3.12/site-packages/pygments/lexers/pointless.py
deleted file mode 100644
index aab0a56..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/pointless.py
+++ /dev/null
@@ -1,70 +0,0 @@
-"""
-    pygments.lexers.pointless
-    ~~~~~~~~~~~~~~~~~~~~~~~~~
-
-    Lexers for Pointless.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-from pygments.lexer import RegexLexer, words
-from pygments.token import Comment, Error, Keyword, Name, Number, Operator, \
-    Punctuation, String, Text
-
-__all__ = ['PointlessLexer']
-
-
-class PointlessLexer(RegexLexer):
-    """
-    For Pointless source code.
-    """
-
-    name = 'Pointless'
-    url = 'https://ptls.dev'
-    aliases = ['pointless']
-    filenames = ['*.ptls']
-    version_added = '2.7'
-
-    ops = words([
-        "+", "-", "*", "/", "**", "%", "+=", "-=", "*=",
-        "/=", "**=", "%=", "|>", "=", "==", "!=", "<", ">",
-        "<=", ">=", "=>", "$", "++",
-    ])
-
-    keywords = words([
-        "if", "then", "else", "where", "with", "cond",
-        "case", "and", "or", "not", "in", "as", "for",
-        "requires", "throw", "try", "catch", "when",
-        "yield", "upval",
-    ], suffix=r'\b')
-
-    tokens = {
-        'root': [
-            (r'[ \n\r]+', Text),
-            (r'--.*$', Comment.Single),
-            (r'"""', String, 'multiString'),
-            (r'"', String, 'string'),
-            (r'[\[\](){}:;,.]', Punctuation),
-            (ops, Operator),
-            (keywords, Keyword),
-            (r'\d+|\d*\.\d+', Number),
-            (r'(true|false)\b', Name.Builtin),
-            (r'[A-Z][a-zA-Z0-9]*\b', String.Symbol),
-            (r'output\b', Name.Variable.Magic),
-            (r'(export|import)\b', Keyword.Namespace),
-            (r'[a-z][a-zA-Z0-9]*\b', Name.Variable)
-        ],
-        'multiString': [
-            (r'\\.', String.Escape),
-            (r'"""', String, '#pop'),
-            (r'"', String),
-            (r'[^\\"]+', String),
-        ],
-        'string': [
-            (r'\\.', String.Escape),
-            (r'"', String, '#pop'),
-            (r'\n', Error),
-            (r'[^\\"]+', String),
-        ],
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/pony.py b/.venv/lib/python3.12/site-packages/pygments/lexers/pony.py
deleted file mode 100644
index 62d16d7..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/pony.py
+++ /dev/null
@@ -1,93 +0,0 @@
-"""
-    pygments.lexers.pony
-    ~~~~~~~~~~~~~~~~~~~~
-
-    Lexers for Pony and related languages.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-from pygments.lexer import RegexLexer, bygroups, words
-from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
-    Number, Punctuation
-
-__all__ = ['PonyLexer']
-
-
-class PonyLexer(RegexLexer):
-    """
-    For Pony source code.
-    """
-
-    name = 'Pony'
-    aliases = ['pony']
-    filenames = ['*.pony']
-    url = 'https://www.ponylang.io'
-    version_added = '2.4'
-
-    _caps = r'(iso|trn|ref|val|box|tag)'
-
-    tokens = {
-        'root': [
-            (r'\n', Text),
-            (r'[^\S\n]+', Text),
-            (r'//.*\n', Comment.Single),
-            (r'/\*', Comment.Multiline, 'nested_comment'),
-            (r'"""(?:.|\n)*?"""', String.Doc),
-            (r'"', String, 'string'),
-            (r'\'.*\'', String.Char),
-            (r'=>|[]{}:().~;,|&!^?[]', Punctuation),
-            (words((
-                'addressof', 'and', 'as', 'consume', 'digestof', 'is', 'isnt',
-                'not', 'or'),
-                suffix=r'\b'),
-             Operator.Word),
-            (r'!=|==|<<|>>|[-+/*%=<>]', Operator),
-            (words((
-                'box', 'break', 'compile_error', 'compile_intrinsic',
-                'continue', 'do', 'else', 'elseif', 'embed', 'end', 'error',
-                'for', 'if', 'ifdef', 'in', 'iso', 'lambda', 'let', 'match',
-                'object', 'recover', 'ref', 'repeat', 'return', 'tag', 'then',
-                'this', 'trn', 'try', 'until', 'use', 'var', 'val', 'where',
-                'while', 'with', '#any', '#read', '#send', '#share'),
-                suffix=r'\b'),
-             Keyword),
-            (r'(actor|class|struct|primitive|interface|trait|type)((?:\s)+)',
-             bygroups(Keyword, Text), 'typename'),
-            (r'(new|fun|be)((?:\s)+)', bygroups(Keyword, Text), 'methodname'),
-            (words((
-                'I8', 'U8', 'I16', 'U16', 'I32', 'U32', 'I64', 'U64', 'I128',
-                'U128', 'ILong', 'ULong', 'ISize', 'USize', 'F32', 'F64',
-                'Bool', 'Pointer', 'None', 'Any', 'Array', 'String',
-                'Iterator'),
-                suffix=r'\b'),
-             Name.Builtin.Type),
-            (r'_?[A-Z]\w*', Name.Type),
-            (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+', Number.Float),
-            (r'0x[0-9a-fA-F]+', Number.Hex),
-            (r'\d+', Number.Integer),
-            (r'(true|false)\b', Name.Builtin),
-            (r'_\d*', Name),
-            (r'_?[a-z][\w\']*', Name)
-        ],
-        'typename': [
-            (_caps + r'?((?:\s)*)(_?[A-Z]\w*)',
-             bygroups(Keyword, Text, Name.Class), '#pop')
-        ],
-        'methodname': [
-            (_caps + r'?((?:\s)*)(_?[a-z]\w*)',
-             bygroups(Keyword, Text, Name.Function), '#pop')
-        ],
-        'nested_comment': [
-            (r'[^*/]+', Comment.Multiline),
-            (r'/\*', Comment.Multiline, '#push'),
-            (r'\*/', Comment.Multiline, '#pop'),
-            (r'[*/]', Comment.Multiline)
-        ],
-        'string': [
-            (r'"', String, '#pop'),
-            (r'\\"', String),
-            (r'[^\\"]+', String)
-        ]
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/praat.py b/.venv/lib/python3.12/site-packages/pygments/lexers/praat.py
deleted file mode 100644
index c50e927..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/praat.py
+++ /dev/null
@@ -1,303 +0,0 @@
-"""
-    pygments.lexers.praat
-    ~~~~~~~~~~~~~~~~~~~~~
-
-    Lexer for Praat
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-from pygments.lexer import RegexLexer, words, bygroups, include
-from pygments.token import Name, Text, Comment, Keyword, String, Punctuation, \
-    Number, Operator, Whitespace
-
-__all__ = ['PraatLexer']
-
-
-class PraatLexer(RegexLexer):
-    """
-    For Praat scripts.
-    """
-
-    name = 'Praat'
-    url = 'http://www.praat.org'
-    aliases = ['praat']
-    filenames = ['*.praat', '*.proc', '*.psc']
-    version_added = '2.1'
-
-    keywords = (
-        'if', 'then', 'else', 'elsif', 'elif', 'endif', 'fi', 'for', 'from', 'to',
-        'endfor', 'endproc', 'while', 'endwhile', 'repeat', 'until', 'select', 'plus',
-        'minus', 'demo', 'assert', 'stopwatch', 'nocheck', 'nowarn', 'noprogress',
-        'editor', 'endeditor', 'clearinfo',
-    )
-
-    functions_string = (
-        'backslashTrigraphsToUnicode', 'chooseDirectory', 'chooseReadFile',
-        'chooseWriteFile', 'date', 'demoKey', 'do', 'environment', 'extractLine',
-        'extractWord', 'fixed', 'info', 'left', 'mid', 'percent', 'readFile', 'replace',
-        'replace_regex', 'right', 'selected', 'string', 'unicodeToBackslashTrigraphs',
-    )
-
-    functions_numeric = (
-        'abs', 'appendFile', 'appendFileLine', 'appendInfo', 'appendInfoLine', 'arccos',
-        'arccosh', 'arcsin', 'arcsinh', 'arctan', 'arctan2', 'arctanh', 'barkToHertz',
-        'beginPause', 'beginSendPraat', 'besselI', 'besselK', 'beta', 'beta2',
-        'binomialP', 'binomialQ', 'boolean', 'ceiling', 'chiSquareP', 'chiSquareQ',
-        'choice', 'comment', 'cos', 'cosh', 'createDirectory', 'deleteFile',
-        'demoClicked', 'demoClickedIn', 'demoCommandKeyPressed',
-        'demoExtraControlKeyPressed', 'demoInput', 'demoKeyPressed',
-        'demoOptionKeyPressed', 'demoShiftKeyPressed', 'demoShow', 'demoWaitForInput',
-        'demoWindowTitle', 'demoX', 'demoY', 'differenceLimensToPhon', 'do', 'editor',
-        'endPause', 'endSendPraat', 'endsWith', 'erb', 'erbToHertz', 'erf', 'erfc',
-        'exitScript', 'exp', 'extractNumber', 'fileReadable', 'fisherP', 'fisherQ',
-        'floor', 'gaussP', 'gaussQ', 'hertzToBark', 'hertzToErb', 'hertzToMel',
-        'hertzToSemitones', 'imax', 'imin', 'incompleteBeta', 'incompleteGammaP', 'index',
-        'index_regex', 'integer', 'invBinomialP', 'invBinomialQ', 'invChiSquareQ', 'invFisherQ',
-        'invGaussQ', 'invSigmoid', 'invStudentQ', 'length', 'ln', 'lnBeta', 'lnGamma',
-        'log10', 'log2', 'max', 'melToHertz', 'min', 'minusObject', 'natural', 'number',
-        'numberOfColumns', 'numberOfRows', 'numberOfSelected', 'objectsAreIdentical',
-        'option', 'optionMenu', 'pauseScript', 'phonToDifferenceLimens', 'plusObject',
-        'positive', 'randomBinomial', 'randomGauss', 'randomInteger', 'randomPoisson',
-        'randomUniform', 'real', 'readFile', 'removeObject', 'rindex', 'rindex_regex',
-        'round', 'runScript', 'runSystem', 'runSystem_nocheck', 'selectObject',
-        'selected', 'semitonesToHertz', 'sentence', 'sentencetext', 'sigmoid', 'sin', 'sinc',
-        'sincpi', 'sinh', 'soundPressureToPhon', 'sqrt', 'startsWith', 'studentP',
-        'studentQ', 'tan', 'tanh', 'text', 'variableExists', 'word', 'writeFile', 'writeFileLine',
-        'writeInfo', 'writeInfoLine',
-    )
-
-    functions_array = (
-        'linear', 'randomGauss', 'randomInteger', 'randomUniform', 'zero',
-    )
-
-    objects = (
-        'Activation', 'AffineTransform', 'AmplitudeTier', 'Art', 'Artword',
-        'Autosegment', 'BarkFilter', 'BarkSpectrogram', 'CCA', 'Categories',
-        'Cepstrogram', 'Cepstrum', 'Cepstrumc', 'ChebyshevSeries', 'ClassificationTable',
-        'Cochleagram', 'Collection', 'ComplexSpectrogram', 'Configuration', 'Confusion',
-        'ContingencyTable', 'Corpus', 'Correlation', 'Covariance',
-        'CrossCorrelationTable', 'CrossCorrelationTables', 'DTW', 'DataModeler',
-        'Diagonalizer', 'Discriminant', 'Dissimilarity', 'Distance', 'Distributions',
-        'DurationTier', 'EEG', 'ERP', 'ERPTier', 'EditCostsTable', 'EditDistanceTable',
-        'Eigen', 'Excitation', 'Excitations', 'ExperimentMFC', 'FFNet', 'FeatureWeights',
-        'FileInMemory', 'FilesInMemory', 'Formant', 'FormantFilter', 'FormantGrid',
-        'FormantModeler', 'FormantPoint', 'FormantTier', 'GaussianMixture', 'HMM',
-        'HMM_Observation', 'HMM_ObservationSequence', 'HMM_State', 'HMM_StateSequence',
-        'Harmonicity', 'ISpline', 'Index', 'Intensity', 'IntensityTier', 'IntervalTier',
-        'KNN', 'KlattGrid', 'KlattTable', 'LFCC', 'LPC', 'Label', 'LegendreSeries',
-        'LinearRegression', 'LogisticRegression', 'LongSound', 'Ltas', 'MFCC', 'MSpline',
-        'ManPages', 'Manipulation', 'Matrix', 'MelFilter', 'MelSpectrogram',
-        'MixingMatrix', 'Movie', 'Network', 'Object', 'OTGrammar', 'OTHistory', 'OTMulti',
-        'PCA', 'PairDistribution', 'ParamCurve', 'Pattern', 'Permutation', 'Photo',
-        'Pitch', 'PitchModeler', 'PitchTier', 'PointProcess', 'Polygon', 'Polynomial',
-        'PowerCepstrogram', 'PowerCepstrum', 'Procrustes', 'RealPoint', 'RealTier',
-        'ResultsMFC', 'Roots', 'SPINET', 'SSCP', 'SVD', 'Salience', 'ScalarProduct',
-        'Similarity', 'SimpleString', 'SortedSetOfString', 'Sound', 'Speaker',
-        'Spectrogram', 'Spectrum', 'SpectrumTier', 'SpeechSynthesizer', 'SpellingChecker',
-        'Strings', 'StringsIndex', 'Table', 'TableOfReal', 'TextGrid', 'TextInterval',
-        'TextPoint', 'TextTier', 'Tier', 'Transition', 'VocalTract', 'VocalTractTier',
-        'Weight', 'WordList',
-    )
-
-    variables_numeric = (
-        'macintosh', 'windows', 'unix', 'praatVersion', 'pi', 'e', 'undefined',
-    )
-
-    variables_string = (
-        'praatVersion', 'tab', 'shellDirectory', 'homeDirectory',
-        'preferencesDirectory', 'newline', 'temporaryDirectory',
-        'defaultDirectory',
-    )
-
-    object_attributes = (
-        'ncol', 'nrow', 'xmin', 'ymin', 'xmax', 'ymax', 'nx', 'ny', 'dx', 'dy',
-    )
-
-    tokens = {
-        'root': [
-            (r'(\s+)(#.*?$)',  bygroups(Whitespace, Comment.Single)),
-            (r'^#.*?$',        Comment.Single),
-            (r';[^\n]*',       Comment.Single),
-            (r'\s+',           Whitespace),
-
-            (r'\bprocedure\b', Keyword,       'procedure_definition'),
-            (r'\bcall\b',      Keyword,       'procedure_call'),
-            (r'@',             Name.Function, 'procedure_call'),
-
-            include('function_call'),
-
-            (words(keywords, suffix=r'\b'), Keyword),
-
-            (r'(\bform\b)(\s+)([^\n]+)',
-             bygroups(Keyword, Whitespace, String), 'old_form'),
-
-            (r'(print(?:line|tab)?|echo|exit|asserterror|pause|send(?:praat|socket)|'
-             r'include|execute|system(?:_nocheck)?)(\s+)',
-             bygroups(Keyword, Whitespace), 'string_unquoted'),
-
-            (r'(goto|label)(\s+)(\w+)', bygroups(Keyword, Whitespace, Name.Label)),
-
-            include('variable_name'),
-            include('number'),
-
-            (r'"', String, 'string'),
-
-            (words((objects), suffix=r'(?=\s+\S+\n)'), Name.Class, 'string_unquoted'),
-
-            (r'\b[A-Z]', Keyword, 'command'),
-            (r'(\.{3}|[)(,])', Punctuation),
-        ],
-        'command': [
-            (r'( ?[\w()-]+ ?)', Keyword),
-
-            include('string_interpolated'),
-
-            (r'\.{3}', Keyword, ('#pop', 'old_arguments')),
-            (r':', Keyword, ('#pop', 'comma_list')),
-            (r'\s', Whitespace, '#pop'),
-        ],
-        'procedure_call': [
-            (r'\s+', Whitespace),
-            (r'([\w.]+)(?:(:)|(?:(\s*)(\()))',
-             bygroups(Name.Function, Punctuation,
-                      Text.Whitespace, Punctuation), '#pop'),
-            (r'([\w.]+)', Name.Function, ('#pop', 'old_arguments')),
-        ],
-        'procedure_definition': [
-            (r'\s', Whitespace),
-            (r'([\w.]+)(\s*?[(:])',
-             bygroups(Name.Function, Whitespace), '#pop'),
-            (r'([\w.]+)([^\n]*)',
-             bygroups(Name.Function, Text), '#pop'),
-        ],
-        'function_call': [
-            (words(functions_string, suffix=r'\$(?=\s*[:(])'), Name.Function, 'function'),
-            (words(functions_array, suffix=r'#(?=\s*[:(])'),   Name.Function, 'function'),
-            (words(functions_numeric, suffix=r'(?=\s*[:(])'),  Name.Function, 'function'),
-        ],
-        'function': [
-            (r'\s+',   Whitespace),
-            (r':',     Punctuation, ('#pop', 'comma_list')),
-            (r'\s*\(', Punctuation, ('#pop', 'comma_list')),
-        ],
-        'comma_list': [
-            (r'(\s*\n\s*)(\.{3})', bygroups(Whitespace, Punctuation)),
-
-            (r'(\s*)(?:([)\]])|(\n))', bygroups(
-                Whitespace, Punctuation, Whitespace), '#pop'),
-
-            (r'\s+', Whitespace),
-            (r'"',   String, 'string'),
-            (r'\b(if|then|else|fi|endif)\b', Keyword),
-
-            include('function_call'),
-            include('variable_name'),
-            include('operator'),
-            include('number'),
-
-            (r'[()]', Text),
-            (r',', Punctuation),
-        ],
-        'old_arguments': [
-            (r'\n', Whitespace, '#pop'),
-
-            include('variable_name'),
-            include('operator'),
-            include('number'),
-
-            (r'"', String, 'string'),
-            (r'[^\n]', Text),
-        ],
-        'number': [
-            (r'\n', Whitespace, '#pop'),
-            (r'\b\d+(\.\d*)?([eE][-+]?\d+)?%?', Number),
-        ],
-        'object_reference': [
-            include('string_interpolated'),
-            (r'([a-z][a-zA-Z0-9_]*|\d+)', Name.Builtin),
-
-            (words(object_attributes, prefix=r'\.'), Name.Builtin, '#pop'),
-
-            (r'\$', Name.Builtin),
-            (r'\[', Text, '#pop'),
-        ],
-        'variable_name': [
-            include('operator'),
-            include('number'),
-
-            (words(variables_string,  suffix=r'\$'), Name.Variable.Global),
-            (words(variables_numeric,
-             suffix=r'(?=[^a-zA-Z0-9_."\'$#\[:(]|\s|^|$)'),
-             Name.Variable.Global),
-
-            (words(objects, prefix=r'\b', suffix=r"(_)"),
-             bygroups(Name.Builtin, Name.Builtin),
-             'object_reference'),
-
-            (r'\.?_?[a-z][\w.]*(\$|#)?', Text),
-            (r'[\[\]]', Punctuation, 'comma_list'),
-
-            include('string_interpolated'),
-        ],
-        'operator': [
-            (r'([+\/*<>=!-]=?|[&*|][&*|]?|\^|<>)',       Operator),
-            (r'(?', Punctuation),
-            (r'"(?:\\x[0-9a-fA-F]+\\|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}|'
-             r'\\[0-7]+\\|\\["\\abcefnrstv]|[^\\"])*"', String.Double),
-            (r"'(?:''|[^'])*'", String.Atom),  # quoted atom
-            # Needs to not be followed by an atom.
-            # (r'=(?=\s|[a-zA-Z\[])', Operator),
-            (r'is\b', Operator),
-            (r'(<|>|=<|>=|==|=:=|=|/|//|\*|\+|-)(?=\s|[a-zA-Z0-9\[])',
-             Operator),
-            (r'(mod|div|not)\b', Operator),
-            (r'_', Keyword),  # The don't-care variable
-            (r'([a-z]+)(:)', bygroups(Name.Namespace, Punctuation)),
-            (r'([a-z\u00c0-\u1fff\u3040-\ud7ff\ue000-\uffef]'
-             r'[\w$\u00c0-\u1fff\u3040-\ud7ff\ue000-\uffef]*)'
-             r'(\s*)(:-|-->)',
-             bygroups(Name.Function, Text, Operator)),  # function defn
-            (r'([a-z\u00c0-\u1fff\u3040-\ud7ff\ue000-\uffef]'
-             r'[\w$\u00c0-\u1fff\u3040-\ud7ff\ue000-\uffef]*)'
-             r'(\s*)(\()',
-             bygroups(Name.Function, Text, Punctuation)),
-            (r'[a-z\u00c0-\u1fff\u3040-\ud7ff\ue000-\uffef]'
-             r'[\w$\u00c0-\u1fff\u3040-\ud7ff\ue000-\uffef]*',
-             String.Atom),  # atom, characters
-            # This one includes !
-            (r'[#&*+\-./:<=>?@\\^~\u00a1-\u00bf\u2010-\u303f]+',
-             String.Atom),  # atom, graphics
-            (r'[A-Z_]\w*', Name.Variable),
-            (r'\s+|[\u2000-\u200f\ufff0-\ufffe\uffef]', Text),
-        ],
-        'nested-comment': [
-            (r'\*/', Comment.Multiline, '#pop'),
-            (r'/\*', Comment.Multiline, '#push'),
-            (r'[^*/]+', Comment.Multiline),
-            (r'[*/]', Comment.Multiline),
-        ],
-    }
-
-    def analyse_text(text):
-        """Competes with IDL and Visual Prolog on *.pro"""
-        if ':-' in text:
-            # Visual Prolog also uses :-
-            return 0.5
-        else:
-            return 0
-
-
-class LogtalkLexer(RegexLexer):
-    """
-    For Logtalk source code.
-    """
-
-    name = 'Logtalk'
-    url = 'http://logtalk.org/'
-    aliases = ['logtalk']
-    filenames = ['*.lgt', '*.logtalk']
-    mimetypes = ['text/x-logtalk']
-    version_added = '0.10'
-
-    tokens = {
-        'root': [
-            # Directives
-            (r'^\s*:-\s', Punctuation, 'directive'),
-            # Comments
-            (r'%.*?\n', Comment),
-            (r'/\*(.|\n)*?\*/', Comment),
-            # Whitespace
-            (r'\n', Text),
-            (r'\s+', Text),
-            # Numbers
-            (r"0'[\\]?.", Number),
-            (r'0b[01]+', Number.Bin),
-            (r'0o[0-7]+', Number.Oct),
-            (r'0x[0-9a-fA-F]+', Number.Hex),
-            (r'\d+\.?\d*((e|E)(\+|-)?\d+)?', Number),
-            # Variables
-            (r'([A-Z_][a-zA-Z0-9_]*)', Name.Variable),
-            # Event handlers
-            (r'(after|before)(?=[(])', Keyword),
-            # Message forwarding handler
-            (r'forward(?=[(])', Keyword),
-            # Execution-context methods
-            (r'(context|parameter|this|se(lf|nder))(?=[(])', Keyword),
-            # Reflection
-            (r'(current_predicate|predicate_property)(?=[(])', Keyword),
-            # DCGs and term expansion
-            (r'(expand_(goal|term)|(goal|term)_expansion|phrase)(?=[(])', Keyword),
-            # Entity
-            (r'(abolish|c(reate|urrent))_(object|protocol|category)(?=[(])', Keyword),
-            (r'(object|protocol|category)_property(?=[(])', Keyword),
-            # Entity relations
-            (r'co(mplements_object|nforms_to_protocol)(?=[(])', Keyword),
-            (r'extends_(object|protocol|category)(?=[(])', Keyword),
-            (r'imp(lements_protocol|orts_category)(?=[(])', Keyword),
-            (r'(instantiat|specializ)es_class(?=[(])', Keyword),
-            # Events
-            (r'(current_event|(abolish|define)_events)(?=[(])', Keyword),
-            # Flags
-            (r'(create|current|set)_logtalk_flag(?=[(])', Keyword),
-            # Compiling, loading, and library paths
-            (r'logtalk_(compile|l(ibrary_path|oad|oad_context)|make(_target_action)?)(?=[(])', Keyword),
-            (r'\blogtalk_make\b', Keyword),
-            # Database
-            (r'(clause|retract(all)?)(?=[(])', Keyword),
-            (r'a(bolish|ssert(a|z))(?=[(])', Keyword),
-            # Control constructs
-            (r'(ca(ll|tch)|throw)(?=[(])', Keyword),
-            (r'(fa(il|lse)|true|(instantiation|system)_error)\b', Keyword),
-            (r'(uninstantiation|type|domain|existence|permission|representation|evaluation|resource|syntax)_error(?=[(])', Keyword),
-            # All solutions
-            (r'((bag|set)of|f(ind|or)all)(?=[(])', Keyword),
-            # Multi-threading predicates
-            (r'threaded(_(ca(ll|ncel)|once|ignore|exit|peek|wait|notify))?(?=[(])', Keyword),
-            # Engine predicates
-            (r'threaded_engine(_(create|destroy|self|next|next_reified|yield|post|fetch))?(?=[(])', Keyword),
-            # Term unification
-            (r'(subsumes_term|unify_with_occurs_check)(?=[(])', Keyword),
-            # Term creation and decomposition
-            (r'(functor|arg|copy_term|numbervars|term_variables)(?=[(])', Keyword),
-            # Evaluable functors
-            (r'(div|rem|m(ax|in|od)|abs|sign)(?=[(])', Keyword),
-            (r'float(_(integer|fractional)_part)?(?=[(])', Keyword),
-            (r'(floor|t(an|runcate)|round|ceiling)(?=[(])', Keyword),
-            # Other arithmetic functors
-            (r'(cos|a(cos|sin|tan|tan2)|exp|log|s(in|qrt)|xor)(?=[(])', Keyword),
-            # Term testing
-            (r'(var|atom(ic)?|integer|float|c(allable|ompound)|n(onvar|umber)|ground|acyclic_term)(?=[(])', Keyword),
-            # Term comparison
-            (r'compare(?=[(])', Keyword),
-            # Stream selection and control
-            (r'(curren|se)t_(in|out)put(?=[(])', Keyword),
-            (r'(open|close)(?=[(])', Keyword),
-            (r'flush_output(?=[(])', Keyword),
-            (r'(at_end_of_stream|flush_output)\b', Keyword),
-            (r'(stream_property|at_end_of_stream|set_stream_position)(?=[(])', Keyword),
-            # Character and byte input/output
-            (r'(nl|(get|peek|put)_(byte|c(har|ode)))(?=[(])', Keyword),
-            (r'\bnl\b', Keyword),
-            # Term input/output
-            (r'read(_term)?(?=[(])', Keyword),
-            (r'write(q|_(canonical|term))?(?=[(])', Keyword),
-            (r'(current_)?op(?=[(])', Keyword),
-            (r'(current_)?char_conversion(?=[(])', Keyword),
-            # Atomic term processing
-            (r'atom_(length|c(hars|o(ncat|des)))(?=[(])', Keyword),
-            (r'(char_code|sub_atom)(?=[(])', Keyword),
-            (r'number_c(har|ode)s(?=[(])', Keyword),
-            # Implementation defined hooks functions
-            (r'(se|curren)t_prolog_flag(?=[(])', Keyword),
-            (r'\bhalt\b', Keyword),
-            (r'halt(?=[(])', Keyword),
-            # Message sending operators
-            (r'(::|:|\^\^)', Operator),
-            # External call
-            (r'[{}]', Keyword),
-            # Logic and control
-            (r'(ignore|once)(?=[(])', Keyword),
-            (r'\brepeat\b', Keyword),
-            # Sorting
-            (r'(key)?sort(?=[(])', Keyword),
-            # Bitwise functors
-            (r'(>>|<<|/\\|\\\\|\\)', Operator),
-            # Predicate aliases
-            (r'\bas\b', Operator),
-            # Arithmetic evaluation
-            (r'\bis\b', Keyword),
-            # Arithmetic comparison
-            (r'(=:=|=\\=|<|=<|>=|>)', Operator),
-            # Term creation and decomposition
-            (r'=\.\.', Operator),
-            # Term unification
-            (r'(=|\\=)', Operator),
-            # Term comparison
-            (r'(==|\\==|@=<|@<|@>=|@>)', Operator),
-            # Evaluable functors
-            (r'(//|[-+*/])', Operator),
-            (r'\b(e|pi|div|mod|rem)\b', Operator),
-            # Other arithmetic functors
-            (r'\b\*\*\b', Operator),
-            # DCG rules
-            (r'-->', Operator),
-            # Control constructs
-            (r'([!;]|->)', Operator),
-            # Logic and control
-            (r'\\+', Operator),
-            # Mode operators
-            (r'[?@]', Operator),
-            # Existential quantifier
-            (r'\^', Operator),
-            # Punctuation
-            (r'[()\[\],.|]', Text),
-            # Atoms
-            (r"[a-z][a-zA-Z0-9_]*", Text),
-            (r"'", String, 'quoted_atom'),
-            # Double-quoted terms
-            (r'"', String, 'double_quoted_term'),
-        ],
-
-        'quoted_atom': [
-            (r"''", String),
-            (r"'", String, '#pop'),
-            (r'\\([\\abfnrtv"\']|(x[a-fA-F0-9]+|[0-7]+)\\)', String.Escape),
-            (r"[^\\'\n]+", String),
-            (r'\\', String),
-        ],
-
-        'double_quoted_term': [
-            (r'""', String),
-            (r'"', String, '#pop'),
-            (r'\\([\\abfnrtv"\']|(x[a-fA-F0-9]+|[0-7]+)\\)', String.Escape),
-            (r'[^\\"\n]+', String),
-            (r'\\', String),
-        ],
-
-        'directive': [
-            # Conditional compilation directives
-            (r'(el)?if(?=[(])', Keyword, 'root'),
-            (r'(e(lse|ndif))(?=[.])', Keyword, 'root'),
-            # Entity directives
-            (r'(category|object|protocol)(?=[(])', Keyword, 'entityrelations'),
-            (r'(end_(category|object|protocol))(?=[.])', Keyword, 'root'),
-            # Predicate scope directives
-            (r'(public|protected|private)(?=[(])', Keyword, 'root'),
-            # Other directives
-            (r'e(n(coding|sure_loaded)|xport)(?=[(])', Keyword, 'root'),
-            (r'in(clude|itialization|fo)(?=[(])', Keyword, 'root'),
-            (r'(built_in|dynamic|synchronized|threaded)(?=[.])', Keyword, 'root'),
-            (r'(alias|d(ynamic|iscontiguous)|m(eta_(non_terminal|predicate)|ode|ultifile)|s(et_(logtalk|prolog)_flag|ynchronized))(?=[(])', Keyword, 'root'),
-            (r'op(?=[(])', Keyword, 'root'),
-            (r'(c(alls|oinductive)|module|reexport|use(s|_module))(?=[(])', Keyword, 'root'),
-            (r'[a-z][a-zA-Z0-9_]*(?=[(])', Text, 'root'),
-            (r'[a-z][a-zA-Z0-9_]*(?=[.])', Text, 'root'),
-        ],
-
-        'entityrelations': [
-            (r'(complements|extends|i(nstantiates|mp(lements|orts))|specializes)(?=[(])', Keyword),
-            # Numbers
-            (r"0'[\\]?.", Number),
-            (r'0b[01]+', Number.Bin),
-            (r'0o[0-7]+', Number.Oct),
-            (r'0x[0-9a-fA-F]+', Number.Hex),
-            (r'\d+\.?\d*((e|E)(\+|-)?\d+)?', Number),
-            # Variables
-            (r'([A-Z_][a-zA-Z0-9_]*)', Name.Variable),
-            # Atoms
-            (r"[a-z][a-zA-Z0-9_]*", Text),
-            (r"'", String, 'quoted_atom'),
-            # Double-quoted terms
-            (r'"', String, 'double_quoted_term'),
-            # End of entity-opening directive
-            (r'([)]\.)', Text, 'root'),
-            # Scope operator
-            (r'(::)', Operator),
-            # Punctuation
-            (r'[()\[\],.|]', Text),
-            # Comments
-            (r'%.*?\n', Comment),
-            (r'/\*(.|\n)*?\*/', Comment),
-            # Whitespace
-            (r'\n', Text),
-            (r'\s+', Text),
-        ]
-    }
-
-    def analyse_text(text):
-        if ':- object(' in text:
-            return 1.0
-        elif ':- protocol(' in text:
-            return 1.0
-        elif ':- category(' in text:
-            return 1.0
-        elif re.search(r'^:-\s[a-z]', text, re.M):
-            return 0.9
-        else:
-            return 0.0
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/promql.py b/.venv/lib/python3.12/site-packages/pygments/lexers/promql.py
deleted file mode 100644
index 5cfa73f..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/promql.py
+++ /dev/null
@@ -1,176 +0,0 @@
-"""
-    pygments.lexers.promql
-    ~~~~~~~~~~~~~~~~~~~~~~
-
-    Lexer for Prometheus Query Language.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-from pygments.lexer import RegexLexer, bygroups, default, words
-from pygments.token import Comment, Keyword, Name, Number, Operator, \
-    Punctuation, String, Whitespace
-
-__all__ = ["PromQLLexer"]
-
-
-class PromQLLexer(RegexLexer):
-    """
-    For PromQL queries.
-
-    For details about the grammar see:
-    https://github.com/prometheus/prometheus/tree/master/promql/parser
-
-    .. versionadded: 2.7
-    """
-
-    name = "PromQL"
-    url = 'https://prometheus.io/docs/prometheus/latest/querying/basics/'
-    aliases = ["promql"]
-    filenames = ["*.promql"]
-    version_added = ''
-
-    base_keywords = (
-        words(
-            (
-                "bool",
-                "by",
-                "group_left",
-                "group_right",
-                "ignoring",
-                "offset",
-                "on",
-                "without",
-            ),
-            suffix=r"\b",
-        ),
-        Keyword,
-    )
-
-    aggregator_keywords = (
-        words(
-            (
-                "sum",
-                "min",
-                "max",
-                "avg",
-                "group",
-                "stddev",
-                "stdvar",
-                "count",
-                "count_values",
-                "bottomk",
-                "topk",
-                "quantile",
-            ),
-            suffix=r"\b",
-        ),
-        Keyword,
-    )
-
-    function_keywords = (
-        words(
-            (
-                "abs",
-                "absent",
-                "absent_over_time",
-                "avg_over_time",
-                "ceil",
-                "changes",
-                "clamp_max",
-                "clamp_min",
-                "count_over_time",
-                "day_of_month",
-                "day_of_week",
-                "days_in_month",
-                "delta",
-                "deriv",
-                "exp",
-                "floor",
-                "histogram_quantile",
-                "holt_winters",
-                "hour",
-                "idelta",
-                "increase",
-                "irate",
-                "label_join",
-                "label_replace",
-                "ln",
-                "log10",
-                "log2",
-                "max_over_time",
-                "min_over_time",
-                "minute",
-                "month",
-                "predict_linear",
-                "quantile_over_time",
-                "rate",
-                "resets",
-                "round",
-                "scalar",
-                "sort",
-                "sort_desc",
-                "sqrt",
-                "stddev_over_time",
-                "stdvar_over_time",
-                "sum_over_time",
-                "time",
-                "timestamp",
-                "vector",
-                "year",
-            ),
-            suffix=r"\b",
-        ),
-        Keyword.Reserved,
-    )
-
-    tokens = {
-        "root": [
-            (r"\n", Whitespace),
-            (r"\s+", Whitespace),
-            (r",", Punctuation),
-            # Keywords
-            base_keywords,
-            aggregator_keywords,
-            function_keywords,
-            # Offsets
-            (r"[1-9][0-9]*[smhdwy]", String),
-            # Numbers
-            (r"-?[0-9]+\.[0-9]+", Number.Float),
-            (r"-?[0-9]+", Number.Integer),
-            # Comments
-            (r"#.*?$", Comment.Single),
-            # Operators
-            (r"(\+|\-|\*|\/|\%|\^)", Operator),
-            (r"==|!=|>=|<=|<|>", Operator),
-            (r"and|or|unless", Operator.Word),
-            # Metrics
-            (r"[_a-zA-Z][a-zA-Z0-9_]+", Name.Variable),
-            # Params
-            (r'(["\'])(.*?)(["\'])', bygroups(Punctuation, String, Punctuation)),
-            # Other states
-            (r"\(", Operator, "function"),
-            (r"\)", Operator),
-            (r"\{", Punctuation, "labels"),
-            (r"\[", Punctuation, "range"),
-        ],
-        "labels": [
-            (r"\}", Punctuation, "#pop"),
-            (r"\n", Whitespace),
-            (r"\s+", Whitespace),
-            (r",", Punctuation),
-            (r'([_a-zA-Z][a-zA-Z0-9_]*?)(\s*?)(=~|!=|=|!~)(\s*?)("|\')(.*?)("|\')',
-             bygroups(Name.Label, Whitespace, Operator, Whitespace,
-                      Punctuation, String, Punctuation)),
-        ],
-        "range": [
-            (r"\]", Punctuation, "#pop"),
-            (r"[1-9][0-9]*[smhdwy]", String),
-        ],
-        "function": [
-            (r"\)", Operator, "#pop"),
-            (r"\(", Operator, "#push"),
-            default("#pop"),
-        ],
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/prql.py b/.venv/lib/python3.12/site-packages/pygments/lexers/prql.py
deleted file mode 100644
index a62cb6b..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/prql.py
+++ /dev/null
@@ -1,251 +0,0 @@
-"""
-    pygments.lexers.prql
-    ~~~~~~~~~~~~~~~~~~~~
-
-    Lexer for the PRQL query language.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-from pygments.lexer import RegexLexer, combined, words, include, bygroups
-from pygments.token import Comment, Literal, Keyword, Name, Number, Operator, \
-    Punctuation, String, Text, Whitespace
-
-__all__ = ['PrqlLexer']
-
-
-class PrqlLexer(RegexLexer):
-    """
-    For PRQL source code.
-
-    grammar: https://github.com/PRQL/prql/tree/main/grammars
-    """
-
-    name = 'PRQL'
-    url = 'https://prql-lang.org/'
-    aliases = ['prql']
-    filenames = ['*.prql']
-    mimetypes = ['application/prql', 'application/x-prql']
-    version_added = '2.17'
-
-    builtinTypes = words((
-        "bool",
-        "int",
-        "int8", "int16", "int32", "int64", "int128",
-        "float",
-        "text",
-        "set"), suffix=r'\b')
-
-    def innerstring_rules(ttype):
-        return [
-            # the new style '{}'.format(...) string formatting
-            (r'\{'
-             r'((\w+)((\.\w+)|(\[[^\]]+\]))*)?'  # field name
-             r'(\:(.?[<>=\^])?[-+ ]?#?0?(\d+)?,?(\.\d+)?[E-GXb-gnosx%]?)?'
-             r'\}', String.Interpol),
-
-            (r'[^\\\'"%{\n]+', ttype),
-            (r'[\'"\\]', ttype),
-            (r'%|(\{{1,2})', ttype)
-        ]
-
-    def fstring_rules(ttype):
-        return [
-            (r'\}', String.Interpol),
-            (r'\{', String.Interpol, 'expr-inside-fstring'),
-            (r'[^\\\'"{}\n]+', ttype),
-            (r'[\'"\\]', ttype),
-        ]
-
-    tokens = {
-        'root': [
-
-            # Comments
-            (r'#!.*', String.Doc),
-            (r'#.*', Comment.Single),
-
-            # Whitespace
-            (r'\s+', Whitespace),
-
-            # Modules
-            (r'^(\s*)(module)(\s*)',
-             bygroups(Whitespace, Keyword.Namespace, Whitespace),
-             'imports'),
-
-            (builtinTypes, Keyword.Type),
-
-            # Main
-            (r'^prql ', Keyword.Reserved),
-
-            ('let', Keyword.Declaration),
-
-            include('keywords'),
-            include('expr'),
-
-            # Transforms
-            (r'^[A-Za-z_][a-zA-Z0-9_]*', Keyword),
-        ],
-        'expr': [
-            # non-raw f-strings
-            ('(f)(""")', bygroups(String.Affix, String.Double),
-             combined('fstringescape', 'tdqf')),
-            ("(f)(''')", bygroups(String.Affix, String.Single),
-             combined('fstringescape', 'tsqf')),
-            ('(f)(")', bygroups(String.Affix, String.Double),
-             combined('fstringescape', 'dqf')),
-            ("(f)(')", bygroups(String.Affix, String.Single),
-             combined('fstringescape', 'sqf')),
-
-            # non-raw s-strings
-            ('(s)(""")', bygroups(String.Affix, String.Double),
-             combined('stringescape', 'tdqf')),
-            ("(s)(''')", bygroups(String.Affix, String.Single),
-             combined('stringescape', 'tsqf')),
-            ('(s)(")', bygroups(String.Affix, String.Double),
-             combined('stringescape', 'dqf')),
-            ("(s)(')", bygroups(String.Affix, String.Single),
-             combined('stringescape', 'sqf')),
-
-            # raw strings
-            ('(?i)(r)(""")',
-             bygroups(String.Affix, String.Double), 'tdqs'),
-            ("(?i)(r)(''')",
-             bygroups(String.Affix, String.Single), 'tsqs'),
-            ('(?i)(r)(")',
-             bygroups(String.Affix, String.Double), 'dqs'),
-            ("(?i)(r)(')",
-             bygroups(String.Affix, String.Single), 'sqs'),
-
-            # non-raw strings
-            ('"""', String.Double, combined('stringescape', 'tdqs')),
-            ("'''", String.Single, combined('stringescape', 'tsqs')),
-            ('"', String.Double, combined('stringescape', 'dqs')),
-            ("'", String.Single, combined('stringescape', 'sqs')),
-
-            # Time and dates
-            (r'@\d{4}-\d{2}-\d{2}T\d{2}(:\d{2})?(:\d{2})?(\.\d{1,6})?(Z|[+-]\d{1,2}(:\d{1,2})?)?', Literal.Date),
-            (r'@\d{4}-\d{2}-\d{2}', Literal.Date),
-            (r'@\d{2}(:\d{2})?(:\d{2})?(\.\d{1,6})?(Z|[+-]\d{1,2}(:\d{1,2})?)?', Literal.Date),
-
-            (r'[^\S\n]+', Text),
-            include('numbers'),
-            (r'->|=>|==|!=|>=|<=|~=|&&|\|\||\?\?|\/\/', Operator),
-            (r'[-~+/*%=<>&^|.@]', Operator),
-            (r'[]{}:(),;[]', Punctuation),
-            include('functions'),
-
-            # Variable Names
-            (r'[A-Za-z_][a-zA-Z0-9_]*', Name.Variable),
-        ],
-        'numbers': [
-            (r'(\d(?:_?\d)*\.(?:\d(?:_?\d)*)?|(?:\d(?:_?\d)*)?\.\d(?:_?\d)*)'
-             r'([eE][+-]?\d(?:_?\d)*)?', Number.Float),
-            (r'\d(?:_?\d)*[eE][+-]?\d(?:_?\d)*j?', Number.Float),
-            (r'0[oO](?:_?[0-7])+', Number.Oct),
-            (r'0[bB](?:_?[01])+', Number.Bin),
-            (r'0[xX](?:_?[a-fA-F0-9])+', Number.Hex),
-            (r'\d(?:_?\d)*', Number.Integer),
-        ],
-        'fstringescape': [
-            include('stringescape'),
-        ],
-        'bytesescape': [
-            (r'\\([\\bfnrt"\']|\n|x[a-fA-F0-9]{2}|[0-7]{1,3})', String.Escape)
-        ],
-        'stringescape': [
-            (r'\\(N\{.*?\}|u\{[a-fA-F0-9]{1,6}\})', String.Escape),
-            include('bytesescape')
-        ],
-        'fstrings-single': fstring_rules(String.Single),
-        'fstrings-double': fstring_rules(String.Double),
-        'strings-single': innerstring_rules(String.Single),
-        'strings-double': innerstring_rules(String.Double),
-        'dqf': [
-            (r'"', String.Double, '#pop'),
-            (r'\\\\|\\"|\\\n', String.Escape),  # included here for raw strings
-            include('fstrings-double')
-        ],
-        'sqf': [
-            (r"'", String.Single, '#pop'),
-            (r"\\\\|\\'|\\\n", String.Escape),  # included here for raw strings
-            include('fstrings-single')
-        ],
-        'dqs': [
-            (r'"', String.Double, '#pop'),
-            (r'\\\\|\\"|\\\n', String.Escape),  # included here for raw strings
-            include('strings-double')
-        ],
-        'sqs': [
-            (r"'", String.Single, '#pop'),
-            (r"\\\\|\\'|\\\n", String.Escape),  # included here for raw strings
-            include('strings-single')
-        ],
-        'tdqf': [
-            (r'"""', String.Double, '#pop'),
-            include('fstrings-double'),
-            (r'\n', String.Double)
-        ],
-        'tsqf': [
-            (r"'''", String.Single, '#pop'),
-            include('fstrings-single'),
-            (r'\n', String.Single)
-        ],
-        'tdqs': [
-            (r'"""', String.Double, '#pop'),
-            include('strings-double'),
-            (r'\n', String.Double)
-        ],
-        'tsqs': [
-            (r"'''", String.Single, '#pop'),
-            include('strings-single'),
-            (r'\n', String.Single)
-        ],
-
-        'expr-inside-fstring': [
-            (r'[{([]', Punctuation, 'expr-inside-fstring-inner'),
-            # without format specifier
-            (r'(=\s*)?'         # debug (https://bugs.python.org/issue36817)
-             r'\}', String.Interpol, '#pop'),
-            # with format specifier
-            # we'll catch the remaining '}' in the outer scope
-            (r'(=\s*)?'         # debug (https://bugs.python.org/issue36817)
-             r':', String.Interpol, '#pop'),
-            (r'\s+', Whitespace),  # allow new lines
-            include('expr'),
-        ],
-        'expr-inside-fstring-inner': [
-            (r'[{([]', Punctuation, 'expr-inside-fstring-inner'),
-            (r'[])}]', Punctuation, '#pop'),
-            (r'\s+', Whitespace),  # allow new lines
-            include('expr'),
-        ],
-        'keywords': [
-            (words((
-                'into', 'case', 'type', 'module', 'internal',
-            ), suffix=r'\b'),
-                Keyword),
-            (words(('true', 'false', 'null'), suffix=r'\b'), Keyword.Constant),
-        ],
-        'functions': [
-            (words((
-                "min", "max", "sum", "average", "stddev", "every", "any",
-                "concat_array", "count", "lag", "lead", "first", "last",
-                "rank", "rank_dense", "row_number", "round", "as", "in",
-                "tuple_every", "tuple_map", "tuple_zip", "_eq", "_is_null",
-                "from_text", "lower", "upper", "read_parquet", "read_csv"),
-                suffix=r'\b'),
-             Name.Function),
-        ],
-
-        'comment': [
-            (r'-(?!\})', Comment.Multiline),
-            (r'\{-', Comment.Multiline, 'comment'),
-            (r'[^-}]', Comment.Multiline),
-            (r'-\}', Comment.Multiline, '#pop'),
-        ],
-
-        'imports': [
-            (r'\w+(\.\w+)*', Name.Class, '#pop'),
-        ],
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/ptx.py b/.venv/lib/python3.12/site-packages/pygments/lexers/ptx.py
deleted file mode 100644
index 685c735..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/ptx.py
+++ /dev/null
@@ -1,119 +0,0 @@
-"""
-    pygments.lexers.ptx
-    ~~~~~~~~~~~~~~~~~~~
-
-    Lexer for other PTX language.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-from pygments.lexer import RegexLexer, include, words
-from pygments.token import Comment, Keyword, Name, String, Number, \
-    Punctuation, Whitespace, Operator
-
-__all__ = ["PtxLexer"]
-
-
-class PtxLexer(RegexLexer):
-    """
-    For NVIDIA `PTX `_
-    source.
-    """
-    name = 'PTX'
-    url = "https://docs.nvidia.com/cuda/parallel-thread-execution/"
-    filenames = ['*.ptx']
-    aliases = ['ptx']
-    mimetypes = ['text/x-ptx']
-    version_added = '2.16'
-
-    #: optional Comment or Whitespace
-    string = r'"[^"]*?"'
-    followsym = r'[a-zA-Z0-9_$]'
-    identifier = r'([-a-zA-Z$._][\w\-$.]*|' + string + ')'
-    block_label = r'(' + identifier + r'|(\d+))'
-
-    tokens = {
-        'root': [
-            include('whitespace'),
-
-            (block_label + r'\s*:', Name.Label),
-
-            include('keyword'),
-
-            (r'%' + identifier, Name.Variable),
-            (r'%\d+', Name.Variable.Anonymous),
-            (r'c?' + string, String),
-            (identifier, Name.Variable),
-            (r';', Punctuation),
-            (r'[*+-/]', Operator),
-
-            (r'0[xX][a-fA-F0-9]+', Number),
-            (r'-?\d+(?:[.]\d+)?(?:[eE][-+]?\d+(?:[.]\d+)?)?', Number),
-
-            (r'[=<>{}\[\]()*.,!]|x\b', Punctuation)
-
-        ],
-        'whitespace': [
-            (r'(\n|\s+)+', Whitespace),
-            (r'//.*?\n', Comment)
-        ],
-
-        'keyword': [
-            # Instruction keywords
-            (words((
-                'abs', 'discard', 'min', 'shf', 'vadd',
-                'activemask', 'div', 'mma', 'shfl', 'vadd2',
-                'add', 'dp2a', 'mov', 'shl', 'vadd4',
-                'addc', 'dp4a', 'movmatrix', 'shr', 'vavrg2',
-                'alloca', 'elect', 'mul', 'sin', 'vavrg4',
-                'and', 'ex2', 'mul24', 'slct', 'vmad',
-                'applypriority', 'exit', 'multimem', 'sqrt', 'vmax',
-                'atom', 'fence', 'nanosleep', 'st', 'vmax2',
-                'bar', 'fma', 'neg', 'stackrestore', 'vmax4',
-                'barrier', 'fns', 'not', 'stacksave', 'vmin',
-                'bfe', 'getctarank', 'or', 'stmatrix', 'vmin2',
-                'bfi', 'griddepcontrol', 'pmevent', 'sub', 'vmin4',
-                'bfind', 'isspacep', 'popc', 'subc', 'vote',
-                'bmsk', 'istypep', 'prefetch', 'suld', 'vset',
-                'bra', 'ld', 'prefetchu', 'suq', 'vset2',
-                'brev', 'ldmatrix', 'prmt', 'sured', 'vset4',
-                'brkpt', 'ldu', 'rcp', 'sust', 'vshl',
-                'brx', 'lg2', 'red', 'szext', 'vshr',
-                'call', 'lop3', 'redux', 'tanh', 'vsub',
-                'clz', 'mad', 'rem', 'testp', 'vsub2',
-                'cnot', 'mad24', 'ret', 'tex', 'vsub4',
-                'copysign', 'madc', 'rsqrt', 'tld4', 'wgmma',
-                'cos', 'mapa', 'sad', 'trap', 'wmma',
-                'cp', 'match', 'selp', 'txq', 'xor',
-                'createpolicy', 'max', 'set', 'vabsdiff', 'cvt',
-                'mbarrier', 'setmaxnreg', 'vabsdiff2', 'cvta',
-                'membar', 'setp', 'vabsdiff4')), Keyword),
-            # State Spaces and Suffixes
-            (words((
-                'reg', '.sreg', '.const', '.global',
-                '.local', '.param', '.shared', '.tex',
-                '.wide', '.loc'
-            )), Keyword.Pseudo),
-            # PTX Directives
-            (words((
-                '.address_size', '.explicitcluster', '.maxnreg', '.section',
-                '.alias', '.extern', '.maxntid', '.shared',
-                '.align', '.file', '.minnctapersm', '.sreg',
-                '.branchtargets', '.func', '.noreturn', '.target',
-                '.callprototype', '.global', '.param', '.tex',
-                '.calltargets', '.loc', '.pragma', '.version',
-                '.common', '.local', '.reg', '.visible',
-                '.const', '.maxclusterrank', '.reqnctapercluster', '.weak',
-                '.entry', '.maxnctapersm', '.reqntid')), Keyword.Reserved),
-            # Fundamental Types
-            (words((
-                '.s8', '.s16', '.s32', '.s64',
-                '.u8', '.u16', '.u32', '.u64',
-                '.f16', '.f16x2', '.f32', '.f64',
-                '.b8', '.b16', '.b32', '.b64',
-                '.pred'
-            )), Keyword.Type)
-        ],
-
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/python.py b/.venv/lib/python3.12/site-packages/pygments/lexers/python.py
deleted file mode 100644
index b296c8d..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/python.py
+++ /dev/null
@@ -1,1204 +0,0 @@
-"""
-    pygments.lexers.python
-    ~~~~~~~~~~~~~~~~~~~~~~
-
-    Lexers for Python and related languages.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-import keyword
-
-from pygments.lexer import DelegatingLexer, RegexLexer, include, \
-    bygroups, using, default, words, combined, this
-from pygments.util import get_bool_opt, shebang_matches
-from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
-    Number, Punctuation, Generic, Other, Error, Whitespace
-from pygments import unistring as uni
-
-__all__ = ['PythonLexer', 'PythonConsoleLexer', 'PythonTracebackLexer',
-           'Python2Lexer', 'Python2TracebackLexer',
-           'CythonLexer', 'DgLexer', 'NumPyLexer']
-
-
-class PythonLexer(RegexLexer):
-    """
-    For Python source code (version 3.x).
-
-    .. versionchanged:: 2.5
-       This is now the default ``PythonLexer``.  It is still available as the
-       alias ``Python3Lexer``.
-    """
-
-    name = 'Python'
-    url = 'https://www.python.org'
-    aliases = ['python', 'py', 'sage', 'python3', 'py3', 'bazel', 'starlark', 'pyi']
-    filenames = [
-        '*.py',
-        '*.pyw',
-        # Type stubs
-        '*.pyi',
-        # Jython
-        '*.jy',
-        # Sage
-        '*.sage',
-        # SCons
-        '*.sc',
-        'SConstruct',
-        'SConscript',
-        # Skylark/Starlark (used by Bazel, Buck, and Pants)
-        '*.bzl',
-        'BUCK',
-        'BUILD',
-        'BUILD.bazel',
-        'WORKSPACE',
-        # Twisted Application infrastructure
-        '*.tac',
-        # Execubot level format
-        '*.pye',
-    ]
-    mimetypes = ['text/x-python', 'application/x-python',
-                 'text/x-python3', 'application/x-python3']
-    version_added = '0.10'
-
-    uni_name = f"[{uni.xid_start}][{uni.xid_continue}]*"
-
-    def innerstring_rules(ttype):
-        return [
-            # the old style '%s' % (...) string formatting (still valid in Py3)
-            (r'%(\(\w+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?'
-             '[hlL]?[E-GXc-giorsaux%]', String.Interpol),
-            # the new style '{}'.format(...) string formatting
-            (r'\{'
-             r'((\w+)((\.\w+)|(\[[^\]]+\]))*)?'  # field name
-             r'(\![sra])?'                       # conversion
-             r'(\:(.?[<>=\^])?[-+ ]?#?0?(\d+)?,?(\.\d+)?[E-GXb-gnosx%]?)?'
-             r'\}', String.Interpol),
-
-            # backslashes, quotes and formatting signs must be parsed one at a time
-            (r'[^\\\'"%{\n]+', ttype),
-            (r'[\'"\\]', ttype),
-            # unhandled string formatting sign
-            (r'%|(\{{1,2})', ttype)
-            # newlines are an error (use "nl" state)
-        ]
-
-    def fstring_rules(ttype):
-        return [
-            # Assuming that a '}' is the closing brace after format specifier.
-            # Sadly, this means that we won't detect syntax error. But it's
-            # more important to parse correct syntax correctly, than to
-            # highlight invalid syntax.
-            (r'\}', String.Interpol),
-            (r'\{', String.Interpol, 'expr-inside-fstring'),
-            # backslashes, quotes and formatting signs must be parsed one at a time
-            (r'[^\\\'"{}\n]+', ttype),
-            (r'[\'"\\]', ttype),
-            # newlines are an error (use "nl" state)
-        ]
-
-    tokens = {
-        'root': [
-            (r'\n', Whitespace),
-            (r'^(\s*)([rRuUbB]{,2})("""(?:.|\n)*?""")',
-             bygroups(Whitespace, String.Affix, String.Doc)),
-            (r"^(\s*)([rRuUbB]{,2})('''(?:.|\n)*?''')",
-             bygroups(Whitespace, String.Affix, String.Doc)),
-            (r'\A#!.+$', Comment.Hashbang),
-            (r'#.*$', Comment.Single),
-            (r'\\\n', Text),
-            (r'\\', Text),
-            include('keywords'),
-            include('soft-keywords'),
-            (r'(def)((?:\s|\\\s)+)', bygroups(Keyword, Whitespace), 'funcname'),
-            (r'(class)((?:\s|\\\s)+)', bygroups(Keyword, Whitespace), 'classname'),
-            (r'(from)((?:\s|\\\s)+)', bygroups(Keyword.Namespace, Whitespace),
-             'fromimport'),
-            (r'(import)((?:\s|\\\s)+)', bygroups(Keyword.Namespace, Whitespace),
-             'import'),
-            include('expr'),
-        ],
-        'expr': [
-            # raw f-strings and t-strings
-            ('(?i)(r[ft]|[ft]r)(""")',
-             bygroups(String.Affix, String.Double),
-             combined('rfstringescape', 'tdqf')),
-            ("(?i)(r[ft]|[ft]r)(''')",
-             bygroups(String.Affix, String.Single),
-             combined('rfstringescape', 'tsqf')),
-            ('(?i)(r[ft]|[ft]r)(")',
-             bygroups(String.Affix, String.Double),
-             combined('rfstringescape', 'dqf')),
-            ("(?i)(r[ft]|[ft]r)(')",
-             bygroups(String.Affix, String.Single),
-             combined('rfstringescape', 'sqf')),
-            # non-raw f-strings and t-strings
-            ('([fFtT])(""")', bygroups(String.Affix, String.Double),
-             combined('fstringescape', 'tdqf')),
-            ("([fFtT])(''')", bygroups(String.Affix, String.Single),
-             combined('fstringescape', 'tsqf')),
-            ('([fFtT])(")', bygroups(String.Affix, String.Double),
-             combined('fstringescape', 'dqf')),
-            ("([fFtT])(')", bygroups(String.Affix, String.Single),
-             combined('fstringescape', 'sqf')),
-            # raw bytes and strings
-            ('(?i)(rb|br|r)(""")',
-             bygroups(String.Affix, String.Double), 'tdqs'),
-            ("(?i)(rb|br|r)(''')",
-             bygroups(String.Affix, String.Single), 'tsqs'),
-            ('(?i)(rb|br|r)(")',
-             bygroups(String.Affix, String.Double), 'dqs'),
-            ("(?i)(rb|br|r)(')",
-             bygroups(String.Affix, String.Single), 'sqs'),
-            # non-raw strings
-            ('([uU]?)(""")', bygroups(String.Affix, String.Double),
-             combined('stringescape', 'tdqs')),
-            ("([uU]?)(''')", bygroups(String.Affix, String.Single),
-             combined('stringescape', 'tsqs')),
-            ('([uU]?)(")', bygroups(String.Affix, String.Double),
-             combined('stringescape', 'dqs')),
-            ("([uU]?)(')", bygroups(String.Affix, String.Single),
-             combined('stringescape', 'sqs')),
-            # non-raw bytes
-            ('([bB])(""")', bygroups(String.Affix, String.Double),
-             combined('bytesescape', 'tdqs')),
-            ("([bB])(''')", bygroups(String.Affix, String.Single),
-             combined('bytesescape', 'tsqs')),
-            ('([bB])(")', bygroups(String.Affix, String.Double),
-             combined('bytesescape', 'dqs')),
-            ("([bB])(')", bygroups(String.Affix, String.Single),
-             combined('bytesescape', 'sqs')),
-
-            (r'[^\S\n]+', Text),
-            include('numbers'),
-            (r'!=|==|<<|>>|:=|[-~+/*%=<>&^|.]', Operator),
-            (r'[]{}:(),;[]', Punctuation),
-            (r'(in|is|and|or|not)\b', Operator.Word),
-            include('expr-keywords'),
-            include('builtins'),
-            include('magicfuncs'),
-            include('magicvars'),
-            include('name'),
-        ],
-        'expr-inside-fstring': [
-            (r'[{([]', Punctuation, 'expr-inside-fstring-inner'),
-            # without format specifier
-            (r'(=\s*)?'         # debug (https://bugs.python.org/issue36817)
-             r'(\![sraf])?'     # conversion
-             r'\}', String.Interpol, '#pop'),
-            # with format specifier
-            # we'll catch the remaining '}' in the outer scope
-            (r'(=\s*)?'         # debug (https://bugs.python.org/issue36817)
-             r'(\![sraf])?'     # conversion
-             r':', String.Interpol, '#pop'),
-            (r'\s+', Whitespace),  # allow new lines
-            include('expr'),
-        ],
-        'expr-inside-fstring-inner': [
-            (r'[{([]', Punctuation, 'expr-inside-fstring-inner'),
-            (r'[])}]', Punctuation, '#pop'),
-            (r'\s+', Whitespace),  # allow new lines
-            include('expr'),
-        ],
-        'expr-keywords': [
-            # Based on https://docs.python.org/3/reference/expressions.html
-            (words((
-                'async for', 'await', 'else', 'for', 'if', 'lambda',
-                'yield', 'yield from'), suffix=r'\b'),
-             Keyword),
-            (words(('True', 'False', 'None'), suffix=r'\b'), Keyword.Constant),
-        ],
-        'keywords': [
-            (words((
-                'assert', 'async', 'await', 'break', 'continue', 'del', 'elif',
-                'else', 'except', 'finally', 'for', 'global', 'if', 'lambda',
-                'pass', 'raise', 'nonlocal', 'return', 'try', 'while', 'yield',
-                'yield from', 'as', 'with'), suffix=r'\b'),
-             Keyword),
-            (words(('True', 'False', 'None'), suffix=r'\b'), Keyword.Constant),
-        ],
-        'soft-keywords': [
-            # `match`, `case` and `_` soft keywords
-            (r'(^[ \t]*)'              # at beginning of line + possible indentation
-             r'(match|case)\b'         # a possible keyword
-             r'(?![ \t]*(?:'           # not followed by...
-             r'[:,;=^&|@~)\]}]|(?:' +  # characters and keywords that mean this isn't
-                                       # pattern matching (but None/True/False is ok)
-             r'|'.join(k for k in keyword.kwlist if k[0].islower()) + r')\b))',
-             bygroups(Text, Keyword), 'soft-keywords-inner'),
-        ],
-        'soft-keywords-inner': [
-            # optional `_` keyword
-            (r'(\s+)([^\n_]*)(_\b)', bygroups(Whitespace, using(this), Keyword)),
-            default('#pop')
-        ],
-        'builtins': [
-            (words((
-                '__import__', 'abs', 'aiter', 'all', 'any', 'bin', 'bool', 'bytearray',
-                'breakpoint', 'bytes', 'callable', 'chr', 'classmethod', 'compile',
-                'complex', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval',
-                'filter', 'float', 'format', 'frozenset', 'getattr', 'globals',
-                'hasattr', 'hash', 'hex', 'id', 'input', 'int', 'isinstance',
-                'issubclass', 'iter', 'len', 'list', 'locals', 'map', 'max',
-                'memoryview', 'min', 'next', 'object', 'oct', 'open', 'ord', 'pow',
-                'print', 'property', 'range', 'repr', 'reversed', 'round', 'set',
-                'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super',
-                'tuple', 'type', 'vars', 'zip'), prefix=r'(?>|[-~+/*%=<>&^|.]', Operator),
-            include('keywords'),
-            (r'(def)((?:\s|\\\s)+)', bygroups(Keyword, Whitespace), 'funcname'),
-            (r'(class)((?:\s|\\\s)+)', bygroups(Keyword, Whitespace), 'classname'),
-            (r'(from)((?:\s|\\\s)+)', bygroups(Keyword.Namespace, Whitespace),
-             'fromimport'),
-            (r'(import)((?:\s|\\\s)+)', bygroups(Keyword.Namespace, Whitespace),
-             'import'),
-            include('builtins'),
-            include('magicfuncs'),
-            include('magicvars'),
-            include('backtick'),
-            ('([rR]|[uUbB][rR]|[rR][uUbB])(""")',
-             bygroups(String.Affix, String.Double), 'tdqs'),
-            ("([rR]|[uUbB][rR]|[rR][uUbB])(''')",
-             bygroups(String.Affix, String.Single), 'tsqs'),
-            ('([rR]|[uUbB][rR]|[rR][uUbB])(")',
-             bygroups(String.Affix, String.Double), 'dqs'),
-            ("([rR]|[uUbB][rR]|[rR][uUbB])(')",
-             bygroups(String.Affix, String.Single), 'sqs'),
-            ('([uUbB]?)(""")', bygroups(String.Affix, String.Double),
-             combined('stringescape', 'tdqs')),
-            ("([uUbB]?)(''')", bygroups(String.Affix, String.Single),
-             combined('stringescape', 'tsqs')),
-            ('([uUbB]?)(")', bygroups(String.Affix, String.Double),
-             combined('stringescape', 'dqs')),
-            ("([uUbB]?)(')", bygroups(String.Affix, String.Single),
-             combined('stringescape', 'sqs')),
-            include('name'),
-            include('numbers'),
-        ],
-        'keywords': [
-            (words((
-                'assert', 'break', 'continue', 'del', 'elif', 'else', 'except',
-                'exec', 'finally', 'for', 'global', 'if', 'lambda', 'pass',
-                'print', 'raise', 'return', 'try', 'while', 'yield',
-                'yield from', 'as', 'with'), suffix=r'\b'),
-             Keyword),
-        ],
-        'builtins': [
-            (words((
-                '__import__', 'abs', 'all', 'any', 'apply', 'basestring', 'bin',
-                'bool', 'buffer', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod',
-                'cmp', 'coerce', 'compile', 'complex', 'delattr', 'dict', 'dir', 'divmod',
-                'enumerate', 'eval', 'execfile', 'exit', 'file', 'filter', 'float',
-                'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'hex', 'id',
-                'input', 'int', 'intern', 'isinstance', 'issubclass', 'iter', 'len',
-                'list', 'locals', 'long', 'map', 'max', 'min', 'next', 'object',
-                'oct', 'open', 'ord', 'pow', 'property', 'range', 'raw_input', 'reduce',
-                'reload', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice',
-                'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type',
-                'unichr', 'unicode', 'vars', 'xrange', 'zip'),
-                prefix=r'(?>> )(.*\n)', bygroups(Generic.Prompt, Other.Code), 'continuations'),
-            # This happens, e.g., when tracebacks are embedded in documentation;
-            # trailing whitespaces are often stripped in such contexts.
-            (r'(>>>)(\n)', bygroups(Generic.Prompt, Whitespace)),
-            (r'(\^C)?Traceback \(most recent call last\):\n', Other.Traceback, 'traceback'),
-            # SyntaxError starts with this
-            (r'  File "[^"]+", line \d+', Other.Traceback, 'traceback'),
-            (r'.*\n', Generic.Output),
-        ],
-        'continuations': [
-            (r'(\.\.\. )(.*\n)', bygroups(Generic.Prompt, Other.Code)),
-            # See above.
-            (r'(\.\.\.)(\n)', bygroups(Generic.Prompt, Whitespace)),
-            default('#pop'),
-        ],
-        'traceback': [
-            # As soon as we see a traceback, consume everything until the next
-            # >>> prompt.
-            (r'(?=>>>( |$))', Text, '#pop'),
-            (r'(KeyboardInterrupt)(\n)', bygroups(Name.Class, Whitespace)),
-            (r'.*\n', Other.Traceback),
-        ],
-    }
-
-
-class PythonConsoleLexer(DelegatingLexer):
-    """
-    For Python console output or doctests, such as:
-
-    .. sourcecode:: pycon
-
-        >>> a = 'foo'
-        >>> print(a)
-        foo
-        >>> 1 / 0
-        Traceback (most recent call last):
-          File "", line 1, in 
-        ZeroDivisionError: integer division or modulo by zero
-
-    Additional options:
-
-    `python3`
-        Use Python 3 lexer for code.  Default is ``True``.
-
-        .. versionadded:: 1.0
-        .. versionchanged:: 2.5
-           Now defaults to ``True``.
-    """
-
-    name = 'Python console session'
-    aliases = ['pycon', 'python-console']
-    mimetypes = ['text/x-python-doctest']
-    url = 'https://python.org'
-    version_added = ''
-
-    def __init__(self, **options):
-        python3 = get_bool_opt(options, 'python3', True)
-        if python3:
-            pylexer = PythonLexer
-            tblexer = PythonTracebackLexer
-        else:
-            pylexer = Python2Lexer
-            tblexer = Python2TracebackLexer
-        # We have two auxiliary lexers. Use DelegatingLexer twice with
-        # different tokens.  TODO: DelegatingLexer should support this
-        # directly, by accepting a tuplet of auxiliary lexers and a tuple of
-        # distinguishing tokens. Then we wouldn't need this intermediary
-        # class.
-        class _ReplaceInnerCode(DelegatingLexer):
-            def __init__(self, **options):
-                super().__init__(pylexer, _PythonConsoleLexerBase, Other.Code, **options)
-        super().__init__(tblexer, _ReplaceInnerCode, Other.Traceback, **options)
-
-
-class PythonTracebackLexer(RegexLexer):
-    """
-    For Python 3.x tracebacks, with support for chained exceptions.
-
-    .. versionchanged:: 2.5
-       This is now the default ``PythonTracebackLexer``.  It is still available
-       as the alias ``Python3TracebackLexer``.
-    """
-
-    name = 'Python Traceback'
-    aliases = ['pytb', 'py3tb']
-    filenames = ['*.pytb', '*.py3tb']
-    mimetypes = ['text/x-python-traceback', 'text/x-python3-traceback']
-    url = 'https://python.org'
-    version_added = '1.0'
-
-    tokens = {
-        'root': [
-            (r'\n', Whitespace),
-            (r'^(\^C)?Traceback \(most recent call last\):\n', Generic.Traceback, 'intb'),
-            (r'^During handling of the above exception, another '
-             r'exception occurred:\n\n', Generic.Traceback),
-            (r'^The above exception was the direct cause of the '
-             r'following exception:\n\n', Generic.Traceback),
-            (r'^(?=  File "[^"]+", line \d+)', Generic.Traceback, 'intb'),
-            (r'^.*\n', Other),
-        ],
-        'intb': [
-            (r'^(  File )("[^"]+")(, line )(\d+)(, in )(.+)(\n)',
-             bygroups(Text, Name.Builtin, Text, Number, Text, Name, Whitespace)),
-            (r'^(  File )("[^"]+")(, line )(\d+)(\n)',
-             bygroups(Text, Name.Builtin, Text, Number, Whitespace)),
-            (r'^(    )(.+)(\n)',
-             bygroups(Whitespace, using(PythonLexer), Whitespace), 'markers'),
-            (r'^([ \t]*)(\.\.\.)(\n)',
-             bygroups(Whitespace, Comment, Whitespace)),  # for doctests...
-            (r'^([^:]+)(: )(.+)(\n)',
-             bygroups(Generic.Error, Text, Name, Whitespace), '#pop'),
-            (r'^([a-zA-Z_][\w.]*)(:?\n)',
-             bygroups(Generic.Error, Whitespace), '#pop'),
-            default('#pop'),
-        ],
-        'markers': [
-            # Either `PEP 657 `
-            # error locations in Python 3.11+, or single-caret markers
-            # for syntax errors before that.
-            (r'^( {4,})([~^]+)(\n)',
-             bygroups(Whitespace, Punctuation.Marker, Whitespace),
-             '#pop'),
-            default('#pop'),
-        ],
-    }
-
-
-Python3TracebackLexer = PythonTracebackLexer
-
-
-class Python2TracebackLexer(RegexLexer):
-    """
-    For Python tracebacks.
-
-    .. versionchanged:: 2.5
-       This class has been renamed from ``PythonTracebackLexer``.
-       ``PythonTracebackLexer`` now refers to the Python 3 variant.
-    """
-
-    name = 'Python 2.x Traceback'
-    aliases = ['py2tb']
-    filenames = ['*.py2tb']
-    mimetypes = ['text/x-python2-traceback']
-    url = 'https://python.org'
-    version_added = '0.7'
-
-    tokens = {
-        'root': [
-            # Cover both (most recent call last) and (innermost last)
-            # The optional ^C allows us to catch keyboard interrupt signals.
-            (r'^(\^C)?(Traceback.*\n)',
-             bygroups(Text, Generic.Traceback), 'intb'),
-            # SyntaxError starts with this.
-            (r'^(?=  File "[^"]+", line \d+)', Generic.Traceback, 'intb'),
-            (r'^.*\n', Other),
-        ],
-        'intb': [
-            (r'^(  File )("[^"]+")(, line )(\d+)(, in )(.+)(\n)',
-             bygroups(Text, Name.Builtin, Text, Number, Text, Name, Whitespace)),
-            (r'^(  File )("[^"]+")(, line )(\d+)(\n)',
-             bygroups(Text, Name.Builtin, Text, Number, Whitespace)),
-            (r'^(    )(.+)(\n)',
-             bygroups(Text, using(Python2Lexer), Whitespace), 'marker'),
-            (r'^([ \t]*)(\.\.\.)(\n)',
-             bygroups(Text, Comment, Whitespace)),  # for doctests...
-            (r'^([^:]+)(: )(.+)(\n)',
-             bygroups(Generic.Error, Text, Name, Whitespace), '#pop'),
-            (r'^([a-zA-Z_]\w*)(:?\n)',
-             bygroups(Generic.Error, Whitespace), '#pop')
-        ],
-        'marker': [
-            # For syntax errors.
-            (r'( {4,})(\^)', bygroups(Text, Punctuation.Marker), '#pop'),
-            default('#pop'),
-        ],
-    }
-
-
-class CythonLexer(RegexLexer):
-    """
-    For Pyrex and Cython source code.
-    """
-
-    name = 'Cython'
-    url = 'https://cython.org'
-    aliases = ['cython', 'pyx', 'pyrex']
-    filenames = ['*.pyx', '*.pxd', '*.pxi']
-    mimetypes = ['text/x-cython', 'application/x-cython']
-    version_added = '1.1'
-
-    tokens = {
-        'root': [
-            (r'\n', Whitespace),
-            (r'^(\s*)("""(?:.|\n)*?""")', bygroups(Whitespace, String.Doc)),
-            (r"^(\s*)('''(?:.|\n)*?''')", bygroups(Whitespace, String.Doc)),
-            (r'[^\S\n]+', Text),
-            (r'#.*$', Comment),
-            (r'[]{}:(),;[]', Punctuation),
-            (r'\\\n', Whitespace),
-            (r'\\', Text),
-            (r'(in|is|and|or|not)\b', Operator.Word),
-            (r'(<)([a-zA-Z0-9.?]+)(>)',
-             bygroups(Punctuation, Keyword.Type, Punctuation)),
-            (r'!=|==|<<|>>|[-~+/*%=<>&^|.?]', Operator),
-            (r'(from)(\d+)(<=)(\s+)(<)(\d+)(:)',
-             bygroups(Keyword, Number.Integer, Operator, Whitespace, Operator,
-                      Name, Punctuation)),
-            include('keywords'),
-            (r'(def|property)(\s+)', bygroups(Keyword, Whitespace), 'funcname'),
-            (r'(cp?def)(\s+)', bygroups(Keyword, Whitespace), 'cdef'),
-            # (should actually start a block with only cdefs)
-            (r'(cdef)(:)', bygroups(Keyword, Punctuation)),
-            (r'(class|cppclass|struct)(\s+)', bygroups(Keyword, Whitespace), 'classname'),
-            (r'(from)(\s+)', bygroups(Keyword, Whitespace), 'fromimport'),
-            (r'(c?import)(\s+)', bygroups(Keyword, Whitespace), 'import'),
-            include('builtins'),
-            include('backtick'),
-            ('(?:[rR]|[uU][rR]|[rR][uU])"""', String, 'tdqs'),
-            ("(?:[rR]|[uU][rR]|[rR][uU])'''", String, 'tsqs'),
-            ('(?:[rR]|[uU][rR]|[rR][uU])"', String, 'dqs'),
-            ("(?:[rR]|[uU][rR]|[rR][uU])'", String, 'sqs'),
-            ('[uU]?"""', String, combined('stringescape', 'tdqs')),
-            ("[uU]?'''", String, combined('stringescape', 'tsqs')),
-            ('[uU]?"', String, combined('stringescape', 'dqs')),
-            ("[uU]?'", String, combined('stringescape', 'sqs')),
-            include('name'),
-            include('numbers'),
-        ],
-        'keywords': [
-            (words((
-                'assert', 'async', 'await', 'break', 'by', 'continue', 'ctypedef', 'del',
-                'elif', 'else', 'except', 'except?', 'exec', 'finally', 'for', 'fused', 'gil',
-                'global', 'if', 'include', 'lambda', 'namespace', 'new', 'noexcept','nogil',
-                'pass', 'print', 'raise', 'return', 'try', 'while', 'yield', 'as', 'with'),
-             suffix=r'\b'),
-             Keyword),
-             (words(('True', 'False', 'None', 'NULL'), suffix=r'\b'), Keyword.Constant),
-            (r'(DEF|IF|ELIF|ELSE)\b', Comment.Preproc),
-        ],
-        'builtins': [
-            (words((
-                '__import__', 'abs', 'all', 'any', 'apply', 'basestring', 'bin', 'bint',
-                'bool', 'buffer', 'bytearray', 'bytes', 'callable', 'char', 'chr',
-                'classmethod', 'cmp', 'coerce', 'compile', 'complex', 'delattr',
-                'dict', 'dir', 'divmod', 'double', 'enumerate', 'eval', 'execfile', 'exit',
-                'file', 'filter', 'float', 'frozenset', 'getattr', 'globals',
-                'hasattr', 'hash', 'hex', 'id', 'input', 'int', 'intern', 'isinstance',
-                'issubclass', 'iter', 'len', 'list', 'locals', 'long', 'map', 'max',
-                'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'property',
-                'Py_ssize_t', 'range', 'raw_input', 'reduce', 'reload', 'repr', 'reversed',
-                'round', 'set', 'setattr', 'size_t', 'slice', 'sorted', 'staticmethod',
-                'ssize_t', 'str', 'sum', 'super', 'tuple', 'type', 'unichr', 'unicode',
-                'unsigned', 'vars', 'xrange', 'zip'), prefix=r'(??/\\:']?:)(\s*)(\{)",
-             bygroups(Name.Function, Whitespace, Operator, Whitespace, Punctuation),
-             "functions"),
-            # Variable Names
-            (r"([.]?[a-zA-Z][\w.]*)(\s*)([-.~=!@#$%^&*_+|,<>?/\\:']?:)",
-             bygroups(Name.Variable, Whitespace, Operator)),
-            # Functions
-            (r"\{", Punctuation, "functions"),
-            # Parentheses
-            (r"\(", Punctuation, "parentheses"),
-            # Brackets
-            (r"\[", Punctuation, "brackets"),
-            # Errors
-            (r"'`([a-zA-Z][\w.]*)?", Name.Exception),
-            # File Symbols
-            (r"`:([a-zA-Z/][\w./]*)?", String.Symbol),
-            # Symbols
-            (r"`([a-zA-Z][\w.]*)?", String.Symbol),
-            # Numbers
-            include("numbers"),
-            # Variable Names
-            (r"[a-zA-Z][\w.]*", Name),
-            # Operators
-            (r"[-=+*#$%@!~^&:.,<>'\\|/?_]", Operator),
-            # Punctuation
-            (r";", Punctuation),
-        ],
-        "functions": [
-            include("root"),
-            (r"\}", Punctuation, "#pop"),
-        ],
-        "parentheses": [
-            include("root"),
-            (r"\)", Punctuation, "#pop"),
-        ],
-        "brackets": [
-            include("root"),
-            (r"\]", Punctuation, "#pop"),
-        ],
-        "numbers": [
-            # Binary Values
-            (r"[01]+b", Number.Bin),
-            # Nulls/Infinities
-            (r"0[nNwW][cefghijmndzuvtp]?", Number),
-            # Timestamps
-            ((r"(?:[0-9]{4}[.][0-9]{2}[.][0-9]{2}|[0-9]+)"
-              "D(?:[0-9](?:[0-9](?::[0-9]{2}"
-              "(?::[0-9]{2}(?:[.][0-9]*)?)?)?)?)?"), Literal.Date),
-            # Datetimes
-            ((r"[0-9]{4}[.][0-9]{2}"
-              "(?:m|[.][0-9]{2}(?:T(?:[0-9]{2}:[0-9]{2}"
-              "(?::[0-9]{2}(?:[.][0-9]*)?)?)?)?)"), Literal.Date),
-            # Times
-            (r"[0-9]{2}:[0-9]{2}(?::[0-9]{2}(?:[.][0-9]{1,3})?)?",
-             Literal.Date),
-            # GUIDs
-            (r"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}",
-             Number.Hex),
-            # Byte Vectors
-            (r"0x[0-9a-fA-F]+", Number.Hex),
-            # Floats
-            (r"([0-9]*[.]?[0-9]+|[0-9]+[.]?[0-9]*)[eE][+-]?[0-9]+[ef]?",
-             Number.Float),
-            (r"([0-9]*[.][0-9]+|[0-9]+[.][0-9]*)[ef]?", Number.Float),
-            (r"[0-9]+[ef]", Number.Float),
-            # Characters
-            (r"[0-9]+c", Number),
-            # Integers
-            (r"[0-9]+[ihtuv]", Number.Integer),
-            # Long Integers
-            (r"[0-9]+[jnp]?", Number.Integer.Long),
-        ],
-        "comments": [
-            (r"[^\\]+", Comment.Multiline),
-            (r"^\\", Comment.Multiline, "#pop"),
-            (r"\\", Comment.Multiline),
-        ],
-        "strings": [
-            (r'[^"\\]+', String.Double),
-            (r"\\.", String.Escape),
-            (r'"', String.Double, "#pop"),
-        ],
-    }
-
-
-class QLexer(KLexer):
-    """
-    For `Q `_ source code.
-    """
-
-    name = "Q"
-    aliases = ["q"]
-    filenames = ["*.q"]
-    version_added = '2.12'
-
-    tokens = {
-        "root": [
-            (words(("aj", "aj0", "ajf", "ajf0", "all", "and", "any", "asc",
-                    "asof", "attr", "avgs", "ceiling", "cols", "count", "cross",
-                    "csv", "cut", "deltas", "desc", "differ", "distinct", "dsave",
-                    "each", "ej", "ema", "eval", "except", "fby", "fills", "first",
-                    "fkeys", "flip", "floor", "get", "group", "gtime", "hclose",
-                    "hcount", "hdel", "hsym", "iasc", "idesc", "ij", "ijf",
-                    "inter", "inv", "key", "keys", "lj", "ljf", "load", "lower",
-                    "lsq", "ltime", "ltrim", "mavg", "maxs", "mcount", "md5",
-                    "mdev", "med", "meta", "mins", "mmax", "mmin", "mmu", "mod",
-                    "msum", "neg", "next", "not", "null", "or", "over", "parse",
-                    "peach", "pj", "prds", "prior", "prev", "rand", "rank", "ratios",
-                    "raze", "read0", "read1", "reciprocal", "reval", "reverse",
-                    "rload", "rotate", "rsave", "rtrim", "save", "scan", "scov",
-                    "sdev", "set", "show", "signum", "ssr", "string", "sublist",
-                    "sums", "sv", "svar", "system", "tables", "til", "trim", "txf",
-                    "type", "uj", "ujf", "ungroup", "union", "upper", "upsert",
-                    "value", "view", "views", "vs", "where", "wj", "wj1", "ww",
-                    "xasc", "xbar", "xcol", "xcols", "xdesc", "xgroup", "xkey",
-                    "xlog", "xprev", "xrank"),
-                    suffix=r"\b"), Name.Builtin,
-            ),
-            inherit,
-        ],
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/qlik.py b/.venv/lib/python3.12/site-packages/pygments/lexers/qlik.py
deleted file mode 100644
index 6972ed9..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/qlik.py
+++ /dev/null
@@ -1,117 +0,0 @@
-"""
-    pygments.lexers.qlik
-    ~~~~~~~~~~~~~~~~~~~~
-
-    Lexer for the qlik scripting language
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-import re
-
-from pygments.lexer import RegexLexer, include, bygroups, words
-from pygments.token import Comment, Keyword, Name, Number, Operator, \
-    Punctuation, String, Text
-from pygments.lexers._qlik_builtins import OPERATORS_LIST, STATEMENT_LIST, \
-    SCRIPT_FUNCTIONS, CONSTANT_LIST
-
-__all__ = ["QlikLexer"]
-
-
-class QlikLexer(RegexLexer):
-    """
-    Lexer for qlik code, including .qvs files
-    """
-
-    name = "Qlik"
-    aliases = ["qlik", "qlikview", "qliksense", "qlikscript"]
-    filenames = ["*.qvs", "*.qvw"]
-    url = "https://qlik.com"
-    version_added = '2.12'
-
-    flags = re.IGNORECASE
-
-    tokens = {
-        # Handle multi-line comments
-        "comment": [
-            (r"\*/", Comment.Multiline, "#pop"),
-            (r"[^*]+", Comment.Multiline),
-        ],
-        # Handle numbers
-        "numerics": [
-            (r"\b\d+\.\d+(e\d+)?[fd]?\b", Number.Float),
-            (r"\b\d+\b", Number.Integer),
-        ],
-        # Handle variable names in things
-        "interp": [
-            (
-                r"(\$\()(\w+)(\))",
-                bygroups(String.Interpol, Name.Variable, String.Interpol),
-            ),
-        ],
-        # Handle strings
-        "string": [
-            (r"'", String, "#pop"),
-            include("interp"),
-            (r"[^'$]+", String),
-            (r"\$", String),
-        ],
-        #
-        "assignment": [
-            (r";", Punctuation, "#pop"),
-            include("root"),
-        ],
-        "field_name_quote": [
-            (r'"', String.Symbol, "#pop"),
-            include("interp"),
-            (r"[^\"$]+", String.Symbol),
-            (r"\$", String.Symbol),
-        ],
-        "field_name_bracket": [
-            (r"\]", String.Symbol, "#pop"),
-            include("interp"),
-            (r"[^\]$]+", String.Symbol),
-            (r"\$", String.Symbol),
-        ],
-        "function": [(r"\)", Punctuation, "#pop"), include("root")],
-        "root": [
-            # Whitespace and comments
-            (r"\s+", Text.Whitespace),
-            (r"/\*", Comment.Multiline, "comment"),
-            (r"//.*\n", Comment.Single),
-            # variable assignment
-            (r"(let|set)(\s+)", bygroups(Keyword.Declaration, Text.Whitespace),
-             "assignment"),
-            # Word operators
-            (words(OPERATORS_LIST["words"], prefix=r"\b", suffix=r"\b"),
-             Operator.Word),
-            # Statements
-            (words(STATEMENT_LIST, suffix=r"\b"), Keyword),
-            # Table names
-            (r"[a-z]\w*:", Keyword.Declaration),
-            # Constants
-            (words(CONSTANT_LIST, suffix=r"\b"), Keyword.Constant),
-            # Functions
-            (words(SCRIPT_FUNCTIONS, suffix=r"(?=\s*\()"), Name.Builtin,
-             "function"),
-            # interpolation - e.g. $(variableName)
-            include("interp"),
-            # Quotes denote a field/file name
-            (r'"', String.Symbol, "field_name_quote"),
-            # Square brackets denote a field/file name
-            (r"\[", String.Symbol, "field_name_bracket"),
-            # Strings
-            (r"'", String, "string"),
-            # Numbers
-            include("numerics"),
-            # Operator symbols
-            (words(OPERATORS_LIST["symbols"]), Operator),
-            # Strings denoted by single quotes
-            (r"'.+?'", String),
-            # Words as text
-            (r"\b\w+\b", Text),
-            # Basic punctuation
-            (r"[,;.()\\/]", Punctuation),
-        ],
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/qvt.py b/.venv/lib/python3.12/site-packages/pygments/lexers/qvt.py
deleted file mode 100644
index 02d6fcf..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/qvt.py
+++ /dev/null
@@ -1,153 +0,0 @@
-"""
-    pygments.lexers.qvt
-    ~~~~~~~~~~~~~~~~~~~
-
-    Lexer for QVT Operational language.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-from pygments.lexer import RegexLexer, bygroups, include, combined, default, \
-    words
-from pygments.token import Text, Comment, Operator, Keyword, Punctuation, \
-    Name, String, Number
-
-__all__ = ['QVToLexer']
-
-
-class QVToLexer(RegexLexer):
-    """
-    For the QVT Operational Mapping language.
-
-    Reference for implementing this: «Meta Object Facility (MOF) 2.0
-    Query/View/Transformation Specification», Version 1.1 - January 2011
-    (https://www.omg.org/spec/QVT/1.1/), see §8.4, «Concrete Syntax» in
-    particular.
-
-    Notable tokens assignments:
-
-    - Name.Class is assigned to the identifier following any of the following
-      keywords: metamodel, class, exception, primitive, enum, transformation
-      or library
-
-    - Name.Function is assigned to the names of mappings and queries
-
-    - Name.Builtin.Pseudo is assigned to the pre-defined variables 'this',
-      'self' and 'result'.
-    """
-    # With obvious borrowings & inspiration from the Java, Python and C lexers
-
-    name = 'QVTO'
-    aliases = ['qvto', 'qvt']
-    filenames = ['*.qvto']
-    url = 'https://www.omg.org/spec/QVT/1.1'
-    version_added = ''
-
-    tokens = {
-        'root': [
-            (r'\n', Text),
-            (r'[^\S\n]+', Text),
-            (r'(--|//)(\s*)(directive:)?(.*)$',
-             bygroups(Comment, Comment, Comment.Preproc, Comment)),
-            # Uncomment the following if you want to distinguish between
-            # '/*' and '/**', à la javadoc
-            # (r'/[*]{2}(.|\n)*?[*]/', Comment.Multiline),
-            (r'/[*](.|\n)*?[*]/', Comment.Multiline),
-            (r'\\\n', Text),
-            (r'(and|not|or|xor|##?)\b', Operator.Word),
-            (r'(:{1,2}=|[-+]=)\b', Operator.Word),
-            (r'(@|<<|>>)\b', Keyword),  # stereotypes
-            (r'!=|<>|==|=|!->|->|>=|<=|[.]{3}|[+/*%=<>&|.~]', Operator),
-            (r'[]{}:(),;[]', Punctuation),
-            (r'(true|false|unlimited|null)\b', Keyword.Constant),
-            (r'(this|self|result)\b', Name.Builtin.Pseudo),
-            (r'(var)\b', Keyword.Declaration),
-            (r'(from|import)\b', Keyword.Namespace, 'fromimport'),
-            (r'(metamodel|class|exception|primitive|enum|transformation|'
-             r'library)(\s+)(\w+)',
-             bygroups(Keyword.Word, Text, Name.Class)),
-            (r'(exception)(\s+)(\w+)',
-             bygroups(Keyword.Word, Text, Name.Exception)),
-            (r'(main)\b', Name.Function),
-            (r'(mapping|helper|query)(\s+)',
-             bygroups(Keyword.Declaration, Text), 'operation'),
-            (r'(assert)(\s+)\b', bygroups(Keyword, Text), 'assert'),
-            (r'(Bag|Collection|Dict|OrderedSet|Sequence|Set|Tuple|List)\b',
-             Keyword.Type),
-            include('keywords'),
-            ('"', String, combined('stringescape', 'dqs')),
-            ("'", String, combined('stringescape', 'sqs')),
-            include('name'),
-            include('numbers'),
-            # (r'([a-zA-Z_]\w*)(::)([a-zA-Z_]\w*)',
-            # bygroups(Text, Text, Text)),
-        ],
-
-        'fromimport': [
-            (r'(?:[ \t]|\\\n)+', Text),
-            (r'[a-zA-Z_][\w.]*', Name.Namespace),
-            default('#pop'),
-        ],
-
-        'operation': [
-            (r'::', Text),
-            (r'(.*::)([a-zA-Z_]\w*)([ \t]*)(\()',
-             bygroups(Text, Name.Function, Text, Punctuation), '#pop')
-        ],
-
-        'assert': [
-            (r'(warning|error|fatal)\b', Keyword, '#pop'),
-            default('#pop'),  # all else: go back
-        ],
-
-        'keywords': [
-            (words((
-                'abstract', 'access', 'any', 'assert', 'blackbox', 'break',
-                'case', 'collect', 'collectNested', 'collectOne', 'collectselect',
-                'collectselectOne', 'composes', 'compute', 'configuration',
-                'constructor', 'continue', 'datatype', 'default', 'derived',
-                'disjuncts', 'do', 'elif', 'else', 'end', 'endif', 'except',
-                'exists', 'extends', 'forAll', 'forEach', 'forOne', 'from', 'if',
-                'implies', 'in', 'inherits', 'init', 'inout', 'intermediate',
-                'invresolve', 'invresolveIn', 'invresolveone', 'invresolveoneIn',
-                'isUnique', 'iterate', 'late', 'let', 'literal', 'log', 'map',
-                'merges', 'modeltype', 'new', 'object', 'one', 'ordered', 'out',
-                'package', 'population', 'property', 'raise', 'readonly',
-                'references', 'refines', 'reject', 'resolve', 'resolveIn',
-                'resolveone', 'resolveoneIn', 'return', 'select', 'selectOne',
-                'sortedBy', 'static', 'switch', 'tag', 'then', 'try', 'typedef',
-                'unlimited', 'uses', 'when', 'where', 'while', 'with', 'xcollect',
-                'xmap', 'xselect'), suffix=r'\b'), Keyword),
-        ],
-
-        # There is no need to distinguish between String.Single and
-        # String.Double: 'strings' is factorised for 'dqs' and 'sqs'
-        'strings': [
-            (r'[^\\\'"\n]+', String),
-            # quotes, percents and backslashes must be parsed one at a time
-            (r'[\'"\\]', String),
-        ],
-        'stringescape': [
-            (r'\\([\\btnfr"\']|u[0-3][0-7]{2}|u[0-7]{1,2})', String.Escape)
-        ],
-        'dqs': [  # double-quoted string
-            (r'"', String, '#pop'),
-            (r'\\\\|\\"', String.Escape),
-            include('strings')
-        ],
-        'sqs': [  # single-quoted string
-            (r"'", String, '#pop'),
-            (r"\\\\|\\'", String.Escape),
-            include('strings')
-        ],
-        'name': [
-            (r'[a-zA-Z_]\w*', Name),
-        ],
-        # numbers: excerpt taken from the python lexer
-        'numbers': [
-            (r'(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number.Float),
-            (r'\d+[eE][+-]?[0-9]+', Number.Float),
-            (r'\d+', Number.Integer)
-        ],
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/r.py b/.venv/lib/python3.12/site-packages/pygments/lexers/r.py
deleted file mode 100644
index 7dcc148..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/r.py
+++ /dev/null
@@ -1,196 +0,0 @@
-"""
-    pygments.lexers.r
-    ~~~~~~~~~~~~~~~~~
-
-    Lexers for the R/S languages.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-import re
-
-from pygments.lexer import Lexer, RegexLexer, include, do_insertions
-from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
-    Number, Punctuation, Generic, Whitespace
-
-__all__ = ['RConsoleLexer', 'SLexer', 'RdLexer']
-
-
-line_re  = re.compile('.*?\n')
-
-
-class RConsoleLexer(Lexer):
-    """
-    For R console transcripts or R CMD BATCH output files.
-    """
-
-    name = 'RConsole'
-    aliases = ['rconsole', 'rout']
-    filenames = ['*.Rout']
-    url = 'https://www.r-project.org'
-    version_added = ''
-    _example = "rconsole/r-console-transcript.Rout"
-
-    def get_tokens_unprocessed(self, text):
-        slexer = SLexer(**self.options)
-
-        current_code_block = ''
-        insertions = []
-
-        for match in line_re.finditer(text):
-            line = match.group()
-            if line.startswith('>') or line.startswith('+'):
-                # Colorize the prompt as such,
-                # then put rest of line into current_code_block
-                insertions.append((len(current_code_block),
-                                   [(0, Generic.Prompt, line[:2])]))
-                current_code_block += line[2:]
-            else:
-                # We have reached a non-prompt line!
-                # If we have stored prompt lines, need to process them first.
-                if current_code_block:
-                    # Weave together the prompts and highlight code.
-                    yield from do_insertions(
-                        insertions, slexer.get_tokens_unprocessed(current_code_block))
-                    # Reset vars for next code block.
-                    current_code_block = ''
-                    insertions = []
-                # Now process the actual line itself, this is output from R.
-                yield match.start(), Generic.Output, line
-
-        # If we happen to end on a code block with nothing after it, need to
-        # process the last code block. This is neither elegant nor DRY so
-        # should be changed.
-        if current_code_block:
-            yield from do_insertions(
-                insertions, slexer.get_tokens_unprocessed(current_code_block))
-
-
-class SLexer(RegexLexer):
-    """
-    For S, S-plus, and R source code.
-    """
-
-    name = 'S'
-    aliases = ['splus', 's', 'r']
-    filenames = ['*.S', '*.R', '.Rhistory', '.Rprofile', '.Renviron']
-    mimetypes = ['text/S-plus', 'text/S', 'text/x-r-source', 'text/x-r',
-                 'text/x-R', 'text/x-r-history', 'text/x-r-profile']
-    url = 'https://www.r-project.org'
-    version_added = '0.10'
-
-    valid_name = r'`[^`\\]*(?:\\.[^`\\]*)*`|(?:[a-zA-Z]|\.[A-Za-z_.])[\w.]*|\.'
-    tokens = {
-        'comments': [
-            (r'#.*$', Comment.Single),
-        ],
-        'valid_name': [
-            (valid_name, Name),
-        ],
-        'function_name': [
-            (rf'({valid_name})\s*(?=\()', Name.Function),
-        ],
-        'punctuation': [
-            (r'\[{1,2}|\]{1,2}|\(|\)|;|,', Punctuation),
-        ],
-        'keywords': [
-            (r'(if|else|for|while|repeat|in|next|break|return|switch|function)'
-             r'(?![\w.])',
-             Keyword.Reserved),
-        ],
-        'operators': [
-            (r'<>?|-|==|<=|>=|\|>|<|>|&&?|!=|\|\|?|\?', Operator),
-            (r'\*|\+|\^|/|!|%[^%]*%|=|~|\$|@|:{1,3}', Operator),
-        ],
-        'builtin_symbols': [
-            (r'(NULL|NA(_(integer|real|complex|character)_)?|'
-             r'letters|LETTERS|Inf|TRUE|FALSE|NaN|pi|\.\.(\.|[0-9]+))'
-             r'(?![\w.])',
-             Keyword.Constant),
-            (r'(T|F)\b', Name.Builtin.Pseudo),
-        ],
-        'numbers': [
-            # hex number
-            (r'0[xX][a-fA-F0-9]+([pP][0-9]+)?[Li]?', Number.Hex),
-            # decimal number
-            (r'[+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+|\.)([eE][+-]?[0-9]+)?[Li]?',
-             Number),
-        ],
-        'statements': [
-            include('comments'),
-            # whitespaces
-            (r'\s+', Whitespace),
-            (r'\'', String, 'string_squote'),
-            (r'\"', String, 'string_dquote'),
-            include('builtin_symbols'),
-            include('keywords'),
-            include('function_name'),
-            include('valid_name'),
-            include('numbers'),
-            include('punctuation'),
-            include('operators'),
-        ],
-        'root': [
-            # calls:
-            include('statements'),
-            # blocks:
-            (r'\{|\}', Punctuation),
-            # (r'\{', Punctuation, 'block'),
-            (r'.', Text),
-        ],
-        # 'block': [
-        #    include('statements'),
-        #    ('\{', Punctuation, '#push'),
-        #    ('\}', Punctuation, '#pop')
-        # ],
-        'string_squote': [
-            (r'([^\'\\]|\\.)*\'', String, '#pop'),
-        ],
-        'string_dquote': [
-            (r'([^"\\]|\\.)*"', String, '#pop'),
-        ],
-    }
-
-    def analyse_text(text):
-        if re.search(r'[a-z0-9_\])\s]<-(?!-)', text):
-            return 0.11
-
-
-class RdLexer(RegexLexer):
-    """
-    Pygments Lexer for R documentation (Rd) files
-
-    This is a very minimal implementation, highlighting little more
-    than the macros. A description of Rd syntax is found in `Writing R
-    Extensions `_
-    and `Parsing Rd files `_.
-    """
-    name = 'Rd'
-    aliases = ['rd']
-    filenames = ['*.Rd']
-    mimetypes = ['text/x-r-doc']
-    url = 'http://cran.r-project.org/doc/manuals/R-exts.html'
-    version_added = '1.6'
-
-    # To account for verbatim / LaTeX-like / and R-like areas
-    # would require parsing.
-    tokens = {
-        'root': [
-            # catch escaped brackets and percent sign
-            (r'\\[\\{}%]', String.Escape),
-            # comments
-            (r'%.*$', Comment),
-            # special macros with no arguments
-            (r'\\(?:cr|l?dots|R|tab)\b', Keyword.Constant),
-            # macros
-            (r'\\[a-zA-Z]+\b', Keyword),
-            # special preprocessor macros
-            (r'^\s*#(?:ifn?def|endif).*\b', Comment.Preproc),
-            # non-escaped brackets
-            (r'[{}]', Name.Builtin),
-            # everything else
-            (r'[^\\%\n{}]+', Text),
-            (r'.', Text),
-        ]
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/rdf.py b/.venv/lib/python3.12/site-packages/pygments/lexers/rdf.py
deleted file mode 100644
index f2ecf7a..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/rdf.py
+++ /dev/null
@@ -1,468 +0,0 @@
-"""
-    pygments.lexers.rdf
-    ~~~~~~~~~~~~~~~~~~~
-
-    Lexers for semantic web and RDF query languages and markup.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-import re
-
-from pygments.lexer import RegexLexer, bygroups, default
-from pygments.token import Keyword, Punctuation, String, Number, Operator, \
-    Generic, Whitespace, Name, Literal, Comment, Text
-
-__all__ = ['SparqlLexer', 'TurtleLexer', 'ShExCLexer']
-
-
-class SparqlLexer(RegexLexer):
-    """
-    Lexer for SPARQL query language.
-    """
-    name = 'SPARQL'
-    aliases = ['sparql']
-    filenames = ['*.rq', '*.sparql']
-    mimetypes = ['application/sparql-query']
-    url = 'https://www.w3.org/TR/sparql11-query'
-    version_added = '2.0'
-
-    # character group definitions ::
-
-    PN_CHARS_BASE_GRP = ('a-zA-Z'
-                         '\u00c0-\u00d6'
-                         '\u00d8-\u00f6'
-                         '\u00f8-\u02ff'
-                         '\u0370-\u037d'
-                         '\u037f-\u1fff'
-                         '\u200c-\u200d'
-                         '\u2070-\u218f'
-                         '\u2c00-\u2fef'
-                         '\u3001-\ud7ff'
-                         '\uf900-\ufdcf'
-                         '\ufdf0-\ufffd')
-
-    PN_CHARS_U_GRP = (PN_CHARS_BASE_GRP + '_')
-
-    PN_CHARS_GRP = (PN_CHARS_U_GRP +
-                    r'\-' +
-                    r'0-9' +
-                    '\u00b7' +
-                    '\u0300-\u036f' +
-                    '\u203f-\u2040')
-
-    HEX_GRP = '0-9A-Fa-f'
-
-    PN_LOCAL_ESC_CHARS_GRP = r' _~.\-!$&"()*+,;=/?#@%'
-
-    # terminal productions ::
-
-    PN_CHARS_BASE = '[' + PN_CHARS_BASE_GRP + ']'
-
-    PN_CHARS_U = '[' + PN_CHARS_U_GRP + ']'
-
-    PN_CHARS = '[' + PN_CHARS_GRP + ']'
-
-    HEX = '[' + HEX_GRP + ']'
-
-    PN_LOCAL_ESC_CHARS = '[' + PN_LOCAL_ESC_CHARS_GRP + ']'
-
-    IRIREF = r'<(?:[^<>"{}|^`\\\x00-\x20])*>'
-
-    BLANK_NODE_LABEL = '_:[0-9' + PN_CHARS_U_GRP + '](?:[' + PN_CHARS_GRP + \
-                       '.]*' + PN_CHARS + ')?'
-
-    PN_PREFIX = PN_CHARS_BASE + '(?:[' + PN_CHARS_GRP + '.]*' + PN_CHARS + ')?'
-
-    VARNAME = '[0-9' + PN_CHARS_U_GRP + '][' + PN_CHARS_U_GRP + \
-              '0-9\u00b7\u0300-\u036f\u203f-\u2040]*'
-
-    PERCENT = '%' + HEX + HEX
-
-    PN_LOCAL_ESC = r'\\' + PN_LOCAL_ESC_CHARS
-
-    PLX = '(?:' + PERCENT + ')|(?:' + PN_LOCAL_ESC + ')'
-
-    PN_LOCAL = ('(?:[' + PN_CHARS_U_GRP + ':0-9' + ']|' + PLX + ')' +
-                '(?:(?:[' + PN_CHARS_GRP + '.:]|' + PLX + ')*(?:[' +
-                PN_CHARS_GRP + ':]|' + PLX + '))?')
-
-    EXPONENT = r'[eE][+-]?\d+'
-
-    # Lexer token definitions ::
-
-    tokens = {
-        'root': [
-            (r'\s+', Text),
-            # keywords ::
-            (r'(?i)(select|construct|describe|ask|where|filter|group\s+by|minus|'
-             r'distinct|reduced|from\s+named|from|order\s+by|desc|asc|limit|'
-             r'offset|values|bindings|load|into|clear|drop|create|add|move|copy|'
-             r'insert\s+data|delete\s+data|delete\s+where|with|delete|insert|'
-             r'using\s+named|using|graph|default|named|all|optional|service|'
-             r'silent|bind|undef|union|not\s+in|in|as|having|to|prefix|base)\b', Keyword),
-            (r'(a)\b', Keyword),
-            # IRIs ::
-            ('(' + IRIREF + ')', Name.Label),
-            # blank nodes ::
-            ('(' + BLANK_NODE_LABEL + ')', Name.Label),
-            #  # variables ::
-            ('[?$]' + VARNAME, Name.Variable),
-            # prefixed names ::
-            (r'(' + PN_PREFIX + r')?(\:)(' + PN_LOCAL + r')?',
-             bygroups(Name.Namespace, Punctuation, Name.Tag)),
-            # function names ::
-            (r'(?i)(str|lang|langmatches|datatype|bound|iri|uri|bnode|rand|abs|'
-             r'ceil|floor|round|concat|strlen|ucase|lcase|encode_for_uri|'
-             r'contains|strstarts|strends|strbefore|strafter|year|month|day|'
-             r'hours|minutes|seconds|timezone|tz|now|uuid|struuid|md5|sha1|sha256|sha384|'
-             r'sha512|coalesce|if|strlang|strdt|sameterm|isiri|isuri|isblank|'
-             r'isliteral|isnumeric|regex|substr|replace|exists|not\s+exists|'
-             r'count|sum|min|max|avg|sample|group_concat|separator)\b',
-             Name.Function),
-            # boolean literals ::
-            (r'(true|false)', Keyword.Constant),
-            # double literals ::
-            (r'[+\-]?(\d+\.\d*' + EXPONENT + r'|\.?\d+' + EXPONENT + ')', Number.Float),
-            # decimal literals ::
-            (r'[+\-]?(\d+\.\d*|\.\d+)', Number.Float),
-            # integer literals ::
-            (r'[+\-]?\d+', Number.Integer),
-            # operators ::
-            (r'(\|\||&&|=|\*|\-|\+|/|!=|<=|>=|!|<|>)', Operator),
-            # punctuation characters ::
-            (r'[(){}.;,:^\[\]]', Punctuation),
-            # line comments ::
-            (r'#[^\n]*', Comment),
-            # strings ::
-            (r'"""', String, 'triple-double-quoted-string'),
-            (r'"', String, 'single-double-quoted-string'),
-            (r"'''", String, 'triple-single-quoted-string'),
-            (r"'", String, 'single-single-quoted-string'),
-        ],
-        'triple-double-quoted-string': [
-            (r'"""', String, 'end-of-string'),
-            (r'[^\\]+', String),
-            (r'\\', String, 'string-escape'),
-        ],
-        'single-double-quoted-string': [
-            (r'"', String, 'end-of-string'),
-            (r'[^"\\\n]+', String),
-            (r'\\', String, 'string-escape'),
-        ],
-        'triple-single-quoted-string': [
-            (r"'''", String, 'end-of-string'),
-            (r'[^\\]+', String),
-            (r'\\', String.Escape, 'string-escape'),
-        ],
-        'single-single-quoted-string': [
-            (r"'", String, 'end-of-string'),
-            (r"[^'\\\n]+", String),
-            (r'\\', String, 'string-escape'),
-        ],
-        'string-escape': [
-            (r'u' + HEX + '{4}', String.Escape, '#pop'),
-            (r'U' + HEX + '{8}', String.Escape, '#pop'),
-            (r'.', String.Escape, '#pop'),
-        ],
-        'end-of-string': [
-            (r'(@)([a-zA-Z]+(?:-[a-zA-Z0-9]+)*)',
-             bygroups(Operator, Name.Function), '#pop:2'),
-            (r'\^\^', Operator, '#pop:2'),
-            default('#pop:2'),
-        ],
-    }
-
-
-class TurtleLexer(RegexLexer):
-    """
-    Lexer for Turtle data language.
-    """
-    name = 'Turtle'
-    aliases = ['turtle']
-    filenames = ['*.ttl']
-    mimetypes = ['text/turtle', 'application/x-turtle']
-    url = 'https://www.w3.org/TR/turtle'
-    version_added = '2.1'
-
-    # character group definitions ::
-    PN_CHARS_BASE_GRP = ('a-zA-Z'
-                         '\u00c0-\u00d6'
-                         '\u00d8-\u00f6'
-                         '\u00f8-\u02ff'
-                         '\u0370-\u037d'
-                         '\u037f-\u1fff'
-                         '\u200c-\u200d'
-                         '\u2070-\u218f'
-                         '\u2c00-\u2fef'
-                         '\u3001-\ud7ff'
-                         '\uf900-\ufdcf'
-                         '\ufdf0-\ufffd')
-
-    PN_CHARS_U_GRP = (PN_CHARS_BASE_GRP + '_')
-
-    PN_CHARS_GRP = (PN_CHARS_U_GRP +
-                    r'\-' +
-                    r'0-9' +
-                    '\u00b7' +
-                    '\u0300-\u036f' +
-                    '\u203f-\u2040')
-
-    PN_CHARS = '[' + PN_CHARS_GRP + ']'
-
-    PN_CHARS_BASE = '[' + PN_CHARS_BASE_GRP + ']'
-
-    PN_PREFIX = PN_CHARS_BASE + '(?:[' + PN_CHARS_GRP + '.]*' + PN_CHARS + ')?'
-
-    HEX_GRP = '0-9A-Fa-f'
-
-    HEX = '[' + HEX_GRP + ']'
-
-    PERCENT = '%' + HEX + HEX
-
-    PN_LOCAL_ESC_CHARS_GRP = r' _~.\-!$&"()*+,;=/?#@%'
-
-    PN_LOCAL_ESC_CHARS = '[' + PN_LOCAL_ESC_CHARS_GRP + ']'
-
-    PN_LOCAL_ESC = r'\\' + PN_LOCAL_ESC_CHARS
-
-    PLX = '(?:' + PERCENT + ')|(?:' + PN_LOCAL_ESC + ')'
-
-    PN_LOCAL = ('(?:[' + PN_CHARS_U_GRP + ':0-9' + ']|' + PLX + ')' +
-                '(?:(?:[' + PN_CHARS_GRP + '.:]|' + PLX + ')*(?:[' +
-                PN_CHARS_GRP + ':]|' + PLX + '))?')
-
-    patterns = {
-        'PNAME_NS': r'((?:[a-zA-Z][\w-]*)?\:)',  # Simplified character range
-        'IRIREF': r'(<[^<>"{}|^`\\\x00-\x20]*>)'
-    }
-
-    tokens = {
-        'root': [
-            (r'\s+', Text),
-
-            # Base / prefix
-            (r'(@base|BASE)(\s+){IRIREF}(\s*)(\.?)'.format(**patterns),
-             bygroups(Keyword, Whitespace, Name.Variable, Whitespace,
-                      Punctuation)),
-            (r'(@prefix|PREFIX)(\s+){PNAME_NS}(\s+){IRIREF}(\s*)(\.?)'.format(**patterns),
-             bygroups(Keyword, Whitespace, Name.Namespace, Whitespace,
-                      Name.Variable, Whitespace, Punctuation)),
-
-            # The shorthand predicate 'a'
-            (r'(?<=\s)a(?=\s)', Keyword.Type),
-
-            # IRIREF
-            (r'{IRIREF}'.format(**patterns), Name.Variable),
-
-            # PrefixedName
-            (r'(' + PN_PREFIX + r')?(\:)(' + PN_LOCAL + r')?',
-             bygroups(Name.Namespace, Punctuation, Name.Tag)),
-
-            # BlankNodeLabel
-            (r'(_)(:)([' + PN_CHARS_U_GRP + r'0-9]([' + PN_CHARS_GRP + r'.]*' + PN_CHARS + ')?)',
-             bygroups(Name.Namespace, Punctuation, Name.Tag)),
-
-            # Comment
-            (r'#([^\n]+|$)', Comment),
-
-            (r'\b(true|false)\b', Literal),
-            (r'[+\-]?\d*\.\d+', Number.Float),
-            (r'[+\-]?\d*(:?\.\d+)?E[+\-]?\d+', Number.Float),
-            (r'[+\-]?\d+', Number.Integer),
-            (r'[\[\](){}.;,:^]', Punctuation),
-
-            (r'"""', String, 'triple-double-quoted-string'),
-            (r'"', String, 'single-double-quoted-string'),
-            (r"'''", String, 'triple-single-quoted-string'),
-            (r"'", String, 'single-single-quoted-string'),
-        ],
-        'triple-double-quoted-string': [
-            (r'"""', String, 'end-of-string'),
-            (r'[^\\]+(?=""")', String),
-            (r'\\', String, 'string-escape'),
-        ],
-        'single-double-quoted-string': [
-            (r'"', String, 'end-of-string'),
-            (r'[^"\\\n]+', String),
-            (r'\\', String, 'string-escape'),
-        ],
-        'triple-single-quoted-string': [
-            (r"'''", String, 'end-of-string'),
-            (r"[^\\]+(?=''')", String),
-            (r'\\', String, 'string-escape'),
-        ],
-        'single-single-quoted-string': [
-            (r"'", String, 'end-of-string'),
-            (r"[^'\\\n]+", String),
-            (r'\\', String, 'string-escape'),
-        ],
-        'string-escape': [
-            (r'.', String, '#pop'),
-        ],
-        'end-of-string': [
-            (r'(@)([a-zA-Z]+(?:-[a-zA-Z0-9]+)*)',
-             bygroups(Operator, Generic.Emph), '#pop:2'),
-
-            (r'(\^\^){IRIREF}'.format(**patterns), bygroups(Operator, Generic.Emph), '#pop:2'),
-
-            default('#pop:2'),
-
-        ],
-    }
-
-    # Turtle and Tera Term macro files share the same file extension
-    # but each has a recognizable and distinct syntax.
-    def analyse_text(text):
-        for t in ('@base ', 'BASE ', '@prefix ', 'PREFIX '):
-            if re.search(rf'^\s*{t}', text):
-                return 0.80
-
-
-class ShExCLexer(RegexLexer):
-    """
-    Lexer for ShExC shape expressions language syntax.
-    """
-    name = 'ShExC'
-    aliases = ['shexc', 'shex']
-    filenames = ['*.shex']
-    mimetypes = ['text/shex']
-    url = 'https://shex.io/shex-semantics/#shexc'
-    version_added = ''
-
-    # character group definitions ::
-
-    PN_CHARS_BASE_GRP = ('a-zA-Z'
-                         '\u00c0-\u00d6'
-                         '\u00d8-\u00f6'
-                         '\u00f8-\u02ff'
-                         '\u0370-\u037d'
-                         '\u037f-\u1fff'
-                         '\u200c-\u200d'
-                         '\u2070-\u218f'
-                         '\u2c00-\u2fef'
-                         '\u3001-\ud7ff'
-                         '\uf900-\ufdcf'
-                         '\ufdf0-\ufffd')
-
-    PN_CHARS_U_GRP = (PN_CHARS_BASE_GRP + '_')
-
-    PN_CHARS_GRP = (PN_CHARS_U_GRP +
-                    r'\-' +
-                    r'0-9' +
-                    '\u00b7' +
-                    '\u0300-\u036f' +
-                    '\u203f-\u2040')
-
-    HEX_GRP = '0-9A-Fa-f'
-
-    PN_LOCAL_ESC_CHARS_GRP = r"_~.\-!$&'()*+,;=/?#@%"
-
-    # terminal productions ::
-
-    PN_CHARS_BASE = '[' + PN_CHARS_BASE_GRP + ']'
-
-    PN_CHARS_U = '[' + PN_CHARS_U_GRP + ']'
-
-    PN_CHARS = '[' + PN_CHARS_GRP + ']'
-
-    HEX = '[' + HEX_GRP + ']'
-
-    PN_LOCAL_ESC_CHARS = '[' + PN_LOCAL_ESC_CHARS_GRP + ']'
-
-    UCHAR_NO_BACKSLASH = '(?:u' + HEX + '{4}|U' + HEX + '{8})'
-
-    UCHAR = r'\\' + UCHAR_NO_BACKSLASH
-
-    IRIREF = r'<(?:[^\x00-\x20<>"{}|^`\\]|' + UCHAR + ')*>'
-
-    BLANK_NODE_LABEL = '_:[0-9' + PN_CHARS_U_GRP + '](?:[' + PN_CHARS_GRP + \
-                       '.]*' + PN_CHARS + ')?'
-
-    PN_PREFIX = PN_CHARS_BASE + '(?:[' + PN_CHARS_GRP + '.]*' + PN_CHARS + ')?'
-
-    PERCENT = '%' + HEX + HEX
-
-    PN_LOCAL_ESC = r'\\' + PN_LOCAL_ESC_CHARS
-
-    PLX = '(?:' + PERCENT + ')|(?:' + PN_LOCAL_ESC + ')'
-
-    PN_LOCAL = ('(?:[' + PN_CHARS_U_GRP + ':0-9' + ']|' + PLX + ')' +
-                '(?:(?:[' + PN_CHARS_GRP + '.:]|' + PLX + ')*(?:[' +
-                PN_CHARS_GRP + ':]|' + PLX + '))?')
-
-    EXPONENT = r'[eE][+-]?\d+'
-
-    # Lexer token definitions ::
-
-    tokens = {
-        'root': [
-            (r'\s+', Text),
-            # keywords ::
-            (r'(?i)(base|prefix|start|external|'
-             r'literal|iri|bnode|nonliteral|length|minlength|maxlength|'
-             r'mininclusive|minexclusive|maxinclusive|maxexclusive|'
-             r'totaldigits|fractiondigits|'
-             r'closed|extra)\b', Keyword),
-            (r'(a)\b', Keyword),
-            # IRIs ::
-            ('(' + IRIREF + ')', Name.Label),
-            # blank nodes ::
-            ('(' + BLANK_NODE_LABEL + ')', Name.Label),
-            # prefixed names ::
-            (r'(' + PN_PREFIX + r')?(\:)(' + PN_LOCAL + ')?',
-             bygroups(Name.Namespace, Punctuation, Name.Tag)),
-            # boolean literals ::
-            (r'(true|false)', Keyword.Constant),
-            # double literals ::
-            (r'[+\-]?(\d+\.\d*' + EXPONENT + r'|\.?\d+' + EXPONENT + ')', Number.Float),
-            # decimal literals ::
-            (r'[+\-]?(\d+\.\d*|\.\d+)', Number.Float),
-            # integer literals ::
-            (r'[+\-]?\d+', Number.Integer),
-            # operators ::
-            (r'[@|$&=*+?^\-~]', Operator),
-            # operator keywords ::
-            (r'(?i)(and|or|not)\b', Operator.Word),
-            # punctuation characters ::
-            (r'[(){}.;,:^\[\]]', Punctuation),
-            # line comments ::
-            (r'#[^\n]*', Comment),
-            # strings ::
-            (r'"""', String, 'triple-double-quoted-string'),
-            (r'"', String, 'single-double-quoted-string'),
-            (r"'''", String, 'triple-single-quoted-string'),
-            (r"'", String, 'single-single-quoted-string'),
-        ],
-        'triple-double-quoted-string': [
-            (r'"""', String, 'end-of-string'),
-            (r'[^\\]+', String),
-            (r'\\', String, 'string-escape'),
-        ],
-        'single-double-quoted-string': [
-            (r'"', String, 'end-of-string'),
-            (r'[^"\\\n]+', String),
-            (r'\\', String, 'string-escape'),
-        ],
-        'triple-single-quoted-string': [
-            (r"'''", String, 'end-of-string'),
-            (r'[^\\]+', String),
-            (r'\\', String.Escape, 'string-escape'),
-        ],
-        'single-single-quoted-string': [
-            (r"'", String, 'end-of-string'),
-            (r"[^'\\\n]+", String),
-            (r'\\', String, 'string-escape'),
-        ],
-        'string-escape': [
-            (UCHAR_NO_BACKSLASH, String.Escape, '#pop'),
-            (r'.', String.Escape, '#pop'),
-        ],
-        'end-of-string': [
-            (r'(@)([a-zA-Z]+(?:-[a-zA-Z0-9]+)*)',
-             bygroups(Operator, Name.Function), '#pop:2'),
-            (r'\^\^', Operator, '#pop:2'),
-            default('#pop:2'),
-        ],
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/rebol.py b/.venv/lib/python3.12/site-packages/pygments/lexers/rebol.py
deleted file mode 100644
index fcff62b..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/rebol.py
+++ /dev/null
@@ -1,419 +0,0 @@
-"""
-    pygments.lexers.rebol
-    ~~~~~~~~~~~~~~~~~~~~~
-
-    Lexers for the REBOL and related languages.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-import re
-
-from pygments.lexer import RegexLexer, bygroups
-from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
-    Number, Generic, Whitespace
-
-__all__ = ['RebolLexer', 'RedLexer']
-
-
-class RebolLexer(RegexLexer):
-    """
-    A REBOL lexer.
-    """
-    name = 'REBOL'
-    aliases = ['rebol']
-    filenames = ['*.r', '*.r3', '*.reb']
-    mimetypes = ['text/x-rebol']
-    url = 'http://www.rebol.com'
-    version_added = '1.1'
-
-    flags = re.IGNORECASE | re.MULTILINE
-
-    escape_re = r'(?:\^\([0-9a-f]{1,4}\)*)'
-
-    def word_callback(lexer, match):
-        word = match.group()
-
-        if re.match(".*:$", word):
-            yield match.start(), Generic.Subheading, word
-        elif re.match(
-            r'(native|alias|all|any|as-string|as-binary|bind|bound\?|case|'
-            r'catch|checksum|comment|debase|dehex|exclude|difference|disarm|'
-            r'either|else|enbase|foreach|remove-each|form|free|get|get-env|if|'
-            r'in|intersect|loop|minimum-of|maximum-of|mold|new-line|'
-            r'new-line\?|not|now|prin|print|reduce|compose|construct|repeat|'
-            r'reverse|save|script\?|set|shift|switch|throw|to-hex|trace|try|'
-            r'type\?|union|unique|unless|unprotect|unset|until|use|value\?|'
-            r'while|compress|decompress|secure|open|close|read|read-io|'
-            r'write-io|write|update|query|wait|input\?|exp|log-10|log-2|'
-            r'log-e|square-root|cosine|sine|tangent|arccosine|arcsine|'
-            r'arctangent|protect|lowercase|uppercase|entab|detab|connected\?|'
-            r'browse|launch|stats|get-modes|set-modes|to-local-file|'
-            r'to-rebol-file|encloak|decloak|create-link|do-browser|bind\?|'
-            r'hide|draw|show|size-text|textinfo|offset-to-caret|'
-            r'caret-to-offset|local-request-file|rgb-to-hsv|hsv-to-rgb|'
-            r'crypt-strength\?|dh-make-key|dh-generate-key|dh-compute-key|'
-            r'dsa-make-key|dsa-generate-key|dsa-make-signature|'
-            r'dsa-verify-signature|rsa-make-key|rsa-generate-key|'
-            r'rsa-encrypt)$', word):
-            yield match.start(), Name.Builtin, word
-        elif re.match(
-            r'(add|subtract|multiply|divide|remainder|power|and~|or~|xor~|'
-            r'minimum|maximum|negate|complement|absolute|random|head|tail|'
-            r'next|back|skip|at|pick|first|second|third|fourth|fifth|sixth|'
-            r'seventh|eighth|ninth|tenth|last|path|find|select|make|to|copy\*|'
-            r'insert|remove|change|poke|clear|trim|sort|min|max|abs|cp|'
-            r'copy)$', word):
-            yield match.start(), Name.Function, word
-        elif re.match(
-            r'(error|source|input|license|help|install|echo|Usage|with|func|'
-            r'throw-on-error|function|does|has|context|probe|\?\?|as-pair|'
-            r'mod|modulo|round|repend|about|set-net|append|join|rejoin|reform|'
-            r'remold|charset|array|replace|move|extract|forskip|forall|alter|'
-            r'first+|also|take|for|forever|dispatch|attempt|what-dir|'
-            r'change-dir|clean-path|list-dir|dirize|rename|split-path|delete|'
-            r'make-dir|delete-dir|in-dir|confirm|dump-obj|upgrade|what|'
-            r'build-tag|process-source|build-markup|decode-cgi|read-cgi|'
-            r'write-user|save-user|set-user-name|protect-system|parse-xml|'
-            r'cvs-date|cvs-version|do-boot|get-net-info|desktop|layout|'
-            r'scroll-para|get-face|alert|set-face|uninstall|unfocus|'
-            r'request-dir|center-face|do-events|net-error|decode-url|'
-            r'parse-header|parse-header-date|parse-email-addrs|import-email|'
-            r'send|build-attach-body|resend|show-popup|hide-popup|open-events|'
-            r'find-key-face|do-face|viewtop|confine|find-window|'
-            r'insert-event-func|remove-event-func|inform|dump-pane|dump-face|'
-            r'flag-face|deflag-face|clear-fields|read-net|vbug|path-thru|'
-            r'read-thru|load-thru|do-thru|launch-thru|load-image|'
-            r'request-download|do-face-alt|set-font|set-para|get-style|'
-            r'set-style|make-face|stylize|choose|hilight-text|hilight-all|'
-            r'unlight-text|focus|scroll-drag|clear-face|reset-face|scroll-face|'
-            r'resize-face|load-stock|load-stock-block|notify|request|flash|'
-            r'request-color|request-pass|request-text|request-list|'
-            r'request-date|request-file|dbug|editor|link-relative-path|'
-            r'emailer|parse-error)$', word):
-            yield match.start(), Keyword.Namespace, word
-        elif re.match(
-            r'(halt|quit|do|load|q|recycle|call|run|ask|parse|view|unview|'
-            r'return|exit|break)$', word):
-            yield match.start(), Name.Exception, word
-        elif re.match('REBOL$', word):
-            yield match.start(), Generic.Heading, word
-        elif re.match("to-.*", word):
-            yield match.start(), Keyword, word
-        elif re.match(r'(\+|-|\*|/|//|\*\*|and|or|xor|=\?|=|==|<>|<|>|<=|>=)$',
-                      word):
-            yield match.start(), Operator, word
-        elif re.match(r".*\?$", word):
-            yield match.start(), Keyword, word
-        elif re.match(r".*\!$", word):
-            yield match.start(), Keyword.Type, word
-        elif re.match("'.*", word):
-            yield match.start(), Name.Variable.Instance, word  # lit-word
-        elif re.match("#.*", word):
-            yield match.start(), Name.Label, word  # issue
-        elif re.match("%.*", word):
-            yield match.start(), Name.Decorator, word  # file
-        else:
-            yield match.start(), Name.Variable, word
-
-    tokens = {
-        'root': [
-            (r'\s+', Text),
-            (r'#"', String.Char, 'char'),
-            (r'#\{[0-9a-f]*\}', Number.Hex),
-            (r'2#\{', Number.Hex, 'bin2'),
-            (r'64#\{[0-9a-z+/=\s]*\}', Number.Hex),
-            (r'"', String, 'string'),
-            (r'\{', String, 'string2'),
-            (r';#+.*\n', Comment.Special),
-            (r';\*+.*\n', Comment.Preproc),
-            (r';.*\n', Comment),
-            (r'%"', Name.Decorator, 'stringFile'),
-            (r'%[^(^{")\s\[\]]+', Name.Decorator),
-            (r'[+-]?([a-z]{1,3})?\$\d+(\.\d+)?', Number.Float),  # money
-            (r'[+-]?\d+\:\d+(\:\d+)?(\.\d+)?', String.Other),    # time
-            (r'\d+[\-/][0-9a-z]+[\-/]\d+(\/\d+\:\d+((\:\d+)?'
-             r'([.\d+]?([+-]?\d+:\d+)?)?)?)?', String.Other),   # date
-            (r'\d+(\.\d+)+\.\d+', Keyword.Constant),             # tuple
-            (r'\d+X\d+', Keyword.Constant),                   # pair
-            (r'[+-]?\d+(\'\d+)?([.,]\d*)?E[+-]?\d+', Number.Float),
-            (r'[+-]?\d+(\'\d+)?[.,]\d*', Number.Float),
-            (r'[+-]?\d+(\'\d+)?', Number),
-            (r'[\[\]()]', Generic.Strong),
-            (r'[a-z]+[^(^{"\s:)]*://[^(^{"\s)]*', Name.Decorator),  # url
-            (r'mailto:[^(^{"@\s)]+@[^(^{"@\s)]+', Name.Decorator),  # url
-            (r'[^(^{"@\s)]+@[^(^{"@\s)]+', Name.Decorator),         # email
-            (r'comment\s"', Comment, 'commentString1'),
-            (r'comment\s\{', Comment, 'commentString2'),
-            (r'comment\s\[', Comment, 'commentBlock'),
-            (r'comment\s[^(\s{"\[]+', Comment),
-            (r'/[^(^{")\s/[\]]*', Name.Attribute),
-            (r'([^(^{")\s/[\]]+)(?=[:({"\s/\[\]])', word_callback),
-            (r'<[\w:.-]*>', Name.Tag),
-            (r'<[^(<>\s")]+', Name.Tag, 'tag'),
-            (r'([^(^{")\s]+)', Text),
-        ],
-        'string': [
-            (r'[^(^")]+', String),
-            (escape_re, String.Escape),
-            (r'[(|)]+', String),
-            (r'\^.', String.Escape),
-            (r'"', String, '#pop'),
-        ],
-        'string2': [
-            (r'[^(^{})]+', String),
-            (escape_re, String.Escape),
-            (r'[(|)]+', String),
-            (r'\^.', String.Escape),
-            (r'\{', String, '#push'),
-            (r'\}', String, '#pop'),
-        ],
-        'stringFile': [
-            (r'[^(^")]+', Name.Decorator),
-            (escape_re, Name.Decorator),
-            (r'\^.', Name.Decorator),
-            (r'"', Name.Decorator, '#pop'),
-        ],
-        'char': [
-            (escape_re + '"', String.Char, '#pop'),
-            (r'\^."', String.Char, '#pop'),
-            (r'."', String.Char, '#pop'),
-        ],
-        'tag': [
-            (escape_re, Name.Tag),
-            (r'"', Name.Tag, 'tagString'),
-            (r'[^(<>\r\n")]+', Name.Tag),
-            (r'>', Name.Tag, '#pop'),
-        ],
-        'tagString': [
-            (r'[^(^")]+', Name.Tag),
-            (escape_re, Name.Tag),
-            (r'[(|)]+', Name.Tag),
-            (r'\^.', Name.Tag),
-            (r'"', Name.Tag, '#pop'),
-        ],
-        'tuple': [
-            (r'(\d+\.)+', Keyword.Constant),
-            (r'\d+', Keyword.Constant, '#pop'),
-        ],
-        'bin2': [
-            (r'\s+', Number.Hex),
-            (r'([01]\s*){8}', Number.Hex),
-            (r'\}', Number.Hex, '#pop'),
-        ],
-        'commentString1': [
-            (r'[^(^")]+', Comment),
-            (escape_re, Comment),
-            (r'[(|)]+', Comment),
-            (r'\^.', Comment),
-            (r'"', Comment, '#pop'),
-        ],
-        'commentString2': [
-            (r'[^(^{})]+', Comment),
-            (escape_re, Comment),
-            (r'[(|)]+', Comment),
-            (r'\^.', Comment),
-            (r'\{', Comment, '#push'),
-            (r'\}', Comment, '#pop'),
-        ],
-        'commentBlock': [
-            (r'\[', Comment, '#push'),
-            (r'\]', Comment, '#pop'),
-            (r'"', Comment, "commentString1"),
-            (r'\{', Comment, "commentString2"),
-            (r'[^(\[\]"{)]+', Comment),
-        ],
-    }
-
-    def analyse_text(text):
-        """
-        Check if code contains REBOL header and so it probably not R code
-        """
-        if re.match(r'^\s*REBOL\s*\[', text, re.IGNORECASE):
-            # The code starts with REBOL header
-            return 1.0
-        elif re.search(r'\s*REBOL\s*\[', text, re.IGNORECASE):
-            # The code contains REBOL header but also some text before it
-            return 0.5
-
-
-class RedLexer(RegexLexer):
-    """
-    A Red-language lexer.
-    """
-    name = 'Red'
-    aliases = ['red', 'red/system']
-    filenames = ['*.red', '*.reds']
-    mimetypes = ['text/x-red', 'text/x-red-system']
-    url = 'https://www.red-lang.org'
-    version_added = '2.0'
-
-    flags = re.IGNORECASE | re.MULTILINE
-
-    escape_re = r'(?:\^\([0-9a-f]{1,4}\)*)'
-
-    def word_callback(lexer, match):
-        word = match.group()
-
-        if re.match(".*:$", word):
-            yield match.start(), Generic.Subheading, word
-        elif re.match(r'(if|unless|either|any|all|while|until|loop|repeat|'
-                      r'foreach|forall|func|function|does|has|switch|'
-                      r'case|reduce|compose|get|set|print|prin|equal\?|'
-                      r'not-equal\?|strict-equal\?|lesser\?|greater\?|lesser-or-equal\?|'
-                      r'greater-or-equal\?|same\?|not|type\?|stats|'
-                      r'bind|union|replace|charset|routine)$', word):
-            yield match.start(), Name.Builtin, word
-        elif re.match(r'(make|random|reflect|to|form|mold|absolute|add|divide|multiply|negate|'
-                      r'power|remainder|round|subtract|even\?|odd\?|and~|complement|or~|xor~|'
-                      r'append|at|back|change|clear|copy|find|head|head\?|index\?|insert|'
-                      r'length\?|next|pick|poke|remove|reverse|select|sort|skip|swap|tail|tail\?|'
-                      r'take|trim|create|close|delete|modify|open|open\?|query|read|rename|'
-                      r'update|write)$', word):
-            yield match.start(), Name.Function, word
-        elif re.match(r'(yes|on|no|off|true|false|tab|cr|lf|newline|escape|slash|sp|space|null|'
-                      r'none|crlf|dot|null-byte)$', word):
-            yield match.start(), Name.Builtin.Pseudo, word
-        elif re.match(r'(#system-global|#include|#enum|#define|#either|#if|#import|#export|'
-                      r'#switch|#default|#get-definition)$', word):
-            yield match.start(), Keyword.Namespace, word
-        elif re.match(r'(system|halt|quit|quit-return|do|load|q|recycle|call|run|ask|parse|'
-                      r'raise-error|return|exit|break|alias|push|pop|probe|\?\?|spec-of|body-of|'
-                      r'quote|forever)$', word):
-            yield match.start(), Name.Exception, word
-        elif re.match(r'(action\?|block\?|char\?|datatype\?|file\?|function\?|get-path\?|zero\?|'
-                      r'get-word\?|integer\?|issue\?|lit-path\?|lit-word\?|logic\?|native\?|'
-                      r'op\?|paren\?|path\?|refinement\?|set-path\?|set-word\?|string\?|unset\?|'
-                      r'any-struct\?|none\?|word\?|any-series\?)$', word):
-            yield match.start(), Keyword, word
-        elif re.match(r'(JNICALL|stdcall|cdecl|infix)$', word):
-            yield match.start(), Keyword.Namespace, word
-        elif re.match("to-.*", word):
-            yield match.start(), Keyword, word
-        elif re.match(r'(\+|-\*\*|-|\*\*|//|/|\*|and|or|xor|=\?|===|==|=|<>|<=|>=|'
-                      r'<<<|>>>|<<|>>|<|>%)$', word):
-            yield match.start(), Operator, word
-        elif re.match(r".*\!$", word):
-            yield match.start(), Keyword.Type, word
-        elif re.match("'.*", word):
-            yield match.start(), Name.Variable.Instance, word  # lit-word
-        elif re.match("#.*", word):
-            yield match.start(), Name.Label, word  # issue
-        elif re.match("%.*", word):
-            yield match.start(), Name.Decorator, word  # file
-        elif re.match(":.*", word):
-            yield match.start(), Generic.Subheading, word  # get-word
-        else:
-            yield match.start(), Name.Variable, word
-
-    tokens = {
-        'root': [
-            (r'\s+', Text),
-            (r'#"', String.Char, 'char'),
-            (r'#\{[0-9a-f\s]*\}', Number.Hex),
-            (r'2#\{', Number.Hex, 'bin2'),
-            (r'64#\{[0-9a-z+/=\s]*\}', Number.Hex),
-            (r'([0-9a-f]+)(h)((\s)|(?=[\[\]{}"()]))',
-             bygroups(Number.Hex, Name.Variable, Whitespace)),
-            (r'"', String, 'string'),
-            (r'\{', String, 'string2'),
-            (r';#+.*\n', Comment.Special),
-            (r';\*+.*\n', Comment.Preproc),
-            (r';.*\n', Comment),
-            (r'%"', Name.Decorator, 'stringFile'),
-            (r'%[^(^{")\s\[\]]+', Name.Decorator),
-            (r'[+-]?([a-z]{1,3})?\$\d+(\.\d+)?', Number.Float),  # money
-            (r'[+-]?\d+\:\d+(\:\d+)?(\.\d+)?', String.Other),    # time
-            (r'\d+[\-/][0-9a-z]+[\-/]\d+(/\d+:\d+((:\d+)?'
-             r'([\.\d+]?([+-]?\d+:\d+)?)?)?)?', String.Other),   # date
-            (r'\d+(\.\d+)+\.\d+', Keyword.Constant),             # tuple
-            (r'\d+X\d+', Keyword.Constant),                   # pair
-            (r'[+-]?\d+(\'\d+)?([.,]\d*)?E[+-]?\d+', Number.Float),
-            (r'[+-]?\d+(\'\d+)?[.,]\d*', Number.Float),
-            (r'[+-]?\d+(\'\d+)?', Number),
-            (r'[\[\]()]', Generic.Strong),
-            (r'[a-z]+[^(^{"\s:)]*://[^(^{"\s)]*', Name.Decorator),  # url
-            (r'mailto:[^(^{"@\s)]+@[^(^{"@\s)]+', Name.Decorator),  # url
-            (r'[^(^{"@\s)]+@[^(^{"@\s)]+', Name.Decorator),         # email
-            (r'comment\s"', Comment, 'commentString1'),
-            (r'comment\s\{', Comment, 'commentString2'),
-            (r'comment\s\[', Comment, 'commentBlock'),
-            (r'comment\s[^(\s{"\[]+', Comment),
-            (r'/[^(^{^")\s/[\]]*', Name.Attribute),
-            (r'([^(^{^")\s/[\]]+)(?=[:({"\s/\[\]])', word_callback),
-            (r'<[\w:.-]*>', Name.Tag),
-            (r'<[^(<>\s")]+', Name.Tag, 'tag'),
-            (r'([^(^{")\s]+)', Text),
-        ],
-        'string': [
-            (r'[^(^")]+', String),
-            (escape_re, String.Escape),
-            (r'[(|)]+', String),
-            (r'\^.', String.Escape),
-            (r'"', String, '#pop'),
-        ],
-        'string2': [
-            (r'[^(^{})]+', String),
-            (escape_re, String.Escape),
-            (r'[(|)]+', String),
-            (r'\^.', String.Escape),
-            (r'\{', String, '#push'),
-            (r'\}', String, '#pop'),
-        ],
-        'stringFile': [
-            (r'[^(^")]+', Name.Decorator),
-            (escape_re, Name.Decorator),
-            (r'\^.', Name.Decorator),
-            (r'"', Name.Decorator, '#pop'),
-        ],
-        'char': [
-            (escape_re + '"', String.Char, '#pop'),
-            (r'\^."', String.Char, '#pop'),
-            (r'."', String.Char, '#pop'),
-        ],
-        'tag': [
-            (escape_re, Name.Tag),
-            (r'"', Name.Tag, 'tagString'),
-            (r'[^(<>\r\n")]+', Name.Tag),
-            (r'>', Name.Tag, '#pop'),
-        ],
-        'tagString': [
-            (r'[^(^")]+', Name.Tag),
-            (escape_re, Name.Tag),
-            (r'[(|)]+', Name.Tag),
-            (r'\^.', Name.Tag),
-            (r'"', Name.Tag, '#pop'),
-        ],
-        'tuple': [
-            (r'(\d+\.)+', Keyword.Constant),
-            (r'\d+', Keyword.Constant, '#pop'),
-        ],
-        'bin2': [
-            (r'\s+', Number.Hex),
-            (r'([01]\s*){8}', Number.Hex),
-            (r'\}', Number.Hex, '#pop'),
-        ],
-        'commentString1': [
-            (r'[^(^")]+', Comment),
-            (escape_re, Comment),
-            (r'[(|)]+', Comment),
-            (r'\^.', Comment),
-            (r'"', Comment, '#pop'),
-        ],
-        'commentString2': [
-            (r'[^(^{})]+', Comment),
-            (escape_re, Comment),
-            (r'[(|)]+', Comment),
-            (r'\^.', Comment),
-            (r'\{', Comment, '#push'),
-            (r'\}', Comment, '#pop'),
-        ],
-        'commentBlock': [
-            (r'\[', Comment, '#push'),
-            (r'\]', Comment, '#pop'),
-            (r'"', Comment, "commentString1"),
-            (r'\{', Comment, "commentString2"),
-            (r'[^(\[\]"{)]+', Comment),
-        ],
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/rego.py b/.venv/lib/python3.12/site-packages/pygments/lexers/rego.py
deleted file mode 100644
index b2e8b75..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/rego.py
+++ /dev/null
@@ -1,57 +0,0 @@
-"""
-    pygments.lexers.rego
-    ~~~~~~~~~~~~~~~~~~~~
-
-    Lexers for the Rego policy languages.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-from pygments.lexer import RegexLexer, words
-from pygments.token import Comment, Operator, Keyword, Name, String, Number, Punctuation, Whitespace
-
-class RegoLexer(RegexLexer):
-    """
-    For Rego source.
-    """
-    name = 'Rego'
-    url = 'https://www.openpolicyagent.org/docs/latest/policy-language/'
-    filenames = ['*.rego']
-    aliases = ['rego']
-    mimetypes = ['text/x-rego']
-    version_added = '2.19'
-
-    reserved_words = (
-        'as', 'contains', 'data', 'default', 'else', 'every', 'false',
-        'if', 'in', 'import', 'package', 'not', 'null',
-        'some', 'true', 'with'
-    )
-
-    builtins = (
-        # https://www.openpolicyagent.org/docs/latest/philosophy/#the-opa-document-model
-        'data',  # Global variable for accessing base and virtual documents
-        'input', # Represents synchronously pushed base documents
-    )
-
-    tokens = {
-        'root': [
-            (r'\n', Whitespace),
-            (r'\s+', Whitespace),
-            (r'#.*?$', Comment.Single),
-            (words(reserved_words, suffix=r'\b'), Keyword),
-            (words(builtins, suffix=r'\b'), Name.Builtin),
-            (r'[a-zA-Z_][a-zA-Z0-9_]*', Name),
-            (r'"(\\\\|\\"|[^"])*"', String.Double),
-            (r'`[^`]*`', String.Backtick),
-            (r'-?\d+(\.\d+)?', Number),
-            (r'(==|!=|<=|>=|:=)', Operator),  # Compound operators
-            (r'[=<>+\-*/%&|]', Operator),     # Single-character operators
-            (r'[\[\]{}(),.:;]', Punctuation),
-        ]
-    }
-
-__all__ = ['RegoLexer']
-
-
-
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/rell.py b/.venv/lib/python3.12/site-packages/pygments/lexers/rell.py
deleted file mode 100644
index 8d54ed2..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/rell.py
+++ /dev/null
@@ -1,68 +0,0 @@
-"""
-    pygments.lexers.rell
-    ~~~~~~~~~~~~~~~~~~~~
-
-    Lexers for the Rell language.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-from pygments.lexer import RegexLexer, bygroups, default, words
-from pygments.token import Comment, Keyword, Name, String, Number, \
-        Punctuation, Whitespace
-
-__all__ = ['RellLexer']
-
-
-class RellLexer(RegexLexer):
-    """
-    A Lexer for Rell.
-    """
-    name = 'Rell'
-    url = 'https://docs.chromia.com/rell/rell-intro'
-    aliases = ['rell']
-    filenames = ['*.rell']
-    mimetypes = ['text/x-rell']
-    version_added = '2.20'
-
-    ident = r'[a-zA-Z_][a-zA-Z0-9_]*'
-
-    tokens = {
-        'root': [
-            (words((
-                'big_integer', 'boolean', 'byte_array', 'decimal', 'gtv',
-                'integer', 'json', 'list', 'map', 'mutable', 'set', 'text',
-                'virtual'), suffix=r'\b'),
-             Keyword.Type),
-            (r'(false|true|null)\b', Keyword.Constant),
-            (r'(entity|enum|namespace|object|struct)\b', Keyword.Declaration),
-            (r'(function|operation|query)\b', Keyword.Declaration, 'function'),
-            (words((
-                'abstract', 'and', 'break', 'continue', 'create', 'delete',
-                'else', 'for', 'if', 'import', 'in', 'index', 'key', 'limit',
-                'module', 'not', 'offset', 'or', 'override', 'return', 'update',
-                'val', 'var', 'when', 'while'), suffix=r'\b'),
-             Keyword.Reserved),
-            (r'//.*?$', Comment.Single),
-            (r'/\*(.|\n|\r)*?\*/', Comment.Multiline),
-            (r'"(\\\\|\\"|[^"])*"', String.Double),
-            (r'\'(\\\\|\\\'|[^\\\'])*\'', String.Single),
-            (r'-?[0-9]*\.[0-9]+([eE][+-][0-9]+)?', Number.Float),
-            (r'-?[0-9]+([eE][+-][0-9]+|[lL])?', Number.Integer),
-            (r'x(\'[a-fA-F0-9]*\'|"[a-fA-F0-9]*")', String.Binary),
-            (r'(\.)([ \n\t\r]*)(' + ident + ')',
-                bygroups(Punctuation, Whitespace, Name.Attribute)),
-            (r'[{}():;,]+', Punctuation),
-            (r'[ \n\t\r]+', Whitespace),
-            (r'@[a-zA-Z_][a-zA-Z0-9_]*', Name.Decorator),
-            (r'[~^*!%&\[\]<>|+=/?\-@\$]', Punctuation.Marker),
-            (ident, Name),
-            (r'(\.)+', Punctuation),
-        ],
-        'function': [
-            (r'[ \n\t\r]+', Whitespace),
-            (ident, Name.Function, '#pop'),
-            default('#pop'),
-        ],
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/resource.py b/.venv/lib/python3.12/site-packages/pygments/lexers/resource.py
deleted file mode 100644
index eb6cb4a..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/resource.py
+++ /dev/null
@@ -1,83 +0,0 @@
-"""
-    pygments.lexers.resource
-    ~~~~~~~~~~~~~~~~~~~~~~~~
-
-    Lexer for resource definition files.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-import re
-
-from pygments.lexer import RegexLexer, bygroups, words
-from pygments.token import Comment, String, Number, Operator, Text, \
-    Keyword, Name
-
-__all__ = ['ResourceLexer']
-
-
-class ResourceLexer(RegexLexer):
-    """Lexer for ICU Resource bundles.
-    """
-    name = 'ResourceBundle'
-    aliases = ['resourcebundle', 'resource']
-    filenames = []
-    url = 'https://unicode-org.github.io/icu/userguide/locale/resources.html'
-    version_added = '2.0'
-
-    _types = (':table', ':array', ':string', ':bin', ':import', ':intvector',
-              ':int', ':alias')
-
-    flags = re.MULTILINE | re.IGNORECASE
-    tokens = {
-        'root': [
-            (r'//.*?$', Comment),
-            (r'"', String, 'string'),
-            (r'-?\d+', Number.Integer),
-            (r'[,{}]', Operator),
-            (r'([^\s{{:]+)(\s*)({}?)'.format('|'.join(_types)),
-             bygroups(Name, Text, Keyword)),
-            (r'\s+', Text),
-            (words(_types), Keyword),
-        ],
-        'string': [
-            (r'(\\x[0-9a-f]{2}|\\u[0-9a-f]{4}|\\U00[0-9a-f]{6}|'
-             r'\\[0-7]{1,3}|\\c.|\\[abtnvfre\'"?\\]|\\\{|[^"{\\])+', String),
-            (r'\{', String.Escape, 'msgname'),
-            (r'"', String, '#pop')
-        ],
-        'msgname': [
-            (r'([^{},]+)(\s*)', bygroups(Name, String.Escape), ('#pop', 'message'))
-        ],
-        'message': [
-            (r'\{', String.Escape, 'msgname'),
-            (r'\}', String.Escape, '#pop'),
-            (r'(,)(\s*)([a-z]+)(\s*\})',
-             bygroups(Operator, String.Escape, Keyword, String.Escape), '#pop'),
-            (r'(,)(\s*)([a-z]+)(\s*)(,)(\s*)(offset)(\s*)(:)(\s*)(-?\d+)(\s*)',
-             bygroups(Operator, String.Escape, Keyword, String.Escape, Operator,
-                      String.Escape, Operator.Word, String.Escape, Operator,
-                      String.Escape, Number.Integer, String.Escape), 'choice'),
-            (r'(,)(\s*)([a-z]+)(\s*)(,)(\s*)',
-             bygroups(Operator, String.Escape, Keyword, String.Escape, Operator,
-                      String.Escape), 'choice'),
-            (r'\s+', String.Escape)
-        ],
-        'choice': [
-            (r'(=|<|>|<=|>=|!=)(-?\d+)(\s*\{)',
-             bygroups(Operator, Number.Integer, String.Escape), 'message'),
-            (r'([a-z]+)(\s*\{)', bygroups(Keyword.Type, String.Escape), 'str'),
-            (r'\}', String.Escape, ('#pop', '#pop')),
-            (r'\s+', String.Escape)
-        ],
-        'str': [
-            (r'\}', String.Escape, '#pop'),
-            (r'\{', String.Escape, 'msgname'),
-            (r'[^{}]+', String)
-        ]
-    }
-
-    def analyse_text(text):
-        if text.startswith('root:table'):
-            return 1.0
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/ride.py b/.venv/lib/python3.12/site-packages/pygments/lexers/ride.py
deleted file mode 100644
index 1ed8f38..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/ride.py
+++ /dev/null
@@ -1,138 +0,0 @@
-"""
-    pygments.lexers.ride
-    ~~~~~~~~~~~~~~~~~~~~
-
-    Lexer for the Ride programming language.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-from pygments.lexer import RegexLexer, words, include
-from pygments.token import Comment, Keyword, Name, Number, Punctuation, \
-    String, Text
-
-__all__ = ['RideLexer']
-
-
-class RideLexer(RegexLexer):
-    """
-    For Ride source code.
-    """
-
-    name = 'Ride'
-    aliases = ['ride']
-    filenames = ['*.ride']
-    mimetypes = ['text/x-ride']
-    url = 'https://docs.waves.tech/en/ride'
-    version_added = '2.6'
-
-    validName = r'[a-zA-Z_][a-zA-Z0-9_\']*'
-
-    builtinOps = (
-        '||', '|', '>=', '>', '==', '!',
-        '=', '<=', '<', '::', ':+', ':', '!=', '/',
-        '.', '=>', '-', '+', '*', '&&', '%', '++',
-    )
-
-    globalVariablesName = (
-        'NOALG', 'MD5', 'SHA1', 'SHA224', 'SHA256', 'SHA384', 'SHA512',
-        'SHA3224', 'SHA3256', 'SHA3384', 'SHA3512', 'nil', 'this', 'unit',
-        'height', 'lastBlock', 'Buy', 'Sell', 'CEILING', 'FLOOR', 'DOWN',
-        'HALFDOWN', 'HALFEVEN', 'HALFUP', 'UP',
-    )
-
-    typesName = (
-        'Unit', 'Int', 'Boolean', 'ByteVector', 'String', 'Address', 'Alias',
-        'Transfer', 'AssetPair', 'DataEntry', 'Order', 'Transaction',
-        'GenesisTransaction', 'PaymentTransaction', 'ReissueTransaction',
-        'BurnTransaction', 'MassTransferTransaction', 'ExchangeTransaction',
-        'TransferTransaction', 'SetAssetScriptTransaction',
-        'InvokeScriptTransaction', 'IssueTransaction', 'LeaseTransaction',
-        'LeaseCancelTransaction', 'CreateAliasTransaction',
-        'SetScriptTransaction', 'SponsorFeeTransaction', 'DataTransaction',
-        'WriteSet', 'AttachedPayment', 'ScriptTransfer', 'TransferSet',
-        'ScriptResult', 'Invocation', 'Asset', 'BlockInfo', 'Issue', 'Reissue',
-        'Burn', 'NoAlg', 'Md5', 'Sha1', 'Sha224', 'Sha256', 'Sha384', 'Sha512',
-        'Sha3224', 'Sha3256', 'Sha3384', 'Sha3512', 'BinaryEntry',
-        'BooleanEntry', 'IntegerEntry', 'StringEntry', 'List', 'Ceiling',
-        'Down', 'Floor', 'HalfDown', 'HalfEven', 'HalfUp', 'Up',
-    )
-
-    functionsName = (
-        'fraction', 'size', 'toBytes', 'take', 'drop', 'takeRight', 'dropRight',
-        'toString', 'isDefined', 'extract', 'throw', 'getElement', 'value',
-        'cons', 'toUtf8String', 'toInt', 'indexOf', 'lastIndexOf', 'split',
-        'parseInt', 'parseIntValue', 'keccak256', 'blake2b256', 'sha256',
-        'sigVerify', 'toBase58String', 'fromBase58String', 'toBase64String',
-        'fromBase64String', 'transactionById', 'transactionHeightById',
-        'getInteger', 'getBoolean', 'getBinary', 'getString',
-        'addressFromPublicKey', 'addressFromString', 'addressFromRecipient',
-        'assetBalance', 'wavesBalance', 'getIntegerValue', 'getBooleanValue',
-        'getBinaryValue', 'getStringValue', 'addressFromStringValue',
-        'assetInfo', 'rsaVerify', 'checkMerkleProof', 'median',
-        'valueOrElse', 'valueOrErrorMessage', 'contains', 'log', 'pow',
-        'toBase16String', 'fromBase16String', 'blockInfoByHeight',
-        'transferTransactionById',
-    )
-
-    reservedWords = words((
-        'match', 'case', 'else', 'func', 'if',
-        'let', 'then', '@Callable', '@Verifier',
-    ), suffix=r'\b')
-
-    tokens = {
-        'root': [
-            # Comments
-            (r'#.*', Comment.Single),
-            # Whitespace
-            (r'\s+', Text),
-            # Strings
-            (r'"', String, 'doublequote'),
-            (r'utf8\'', String, 'utf8quote'),
-            (r'base(58|64|16)\'', String, 'singlequote'),
-            # Keywords
-            (reservedWords, Keyword.Reserved),
-            (r'\{-#.*?#-\}', Keyword.Reserved),
-            (r'FOLD<\d+>', Keyword.Reserved),
-            # Types
-            (words(typesName), Keyword.Type),
-            # Main
-            # (specialName, Keyword.Reserved),
-            # Prefix Operators
-            (words(builtinOps, prefix=r'\(', suffix=r'\)'), Name.Function),
-            # Infix Operators
-            (words(builtinOps), Name.Function),
-            (words(globalVariablesName), Name.Function),
-            (words(functionsName), Name.Function),
-            # Numbers
-            include('numbers'),
-            # Variable Names
-            (validName, Name.Variable),
-            # Parens
-            (r'[,()\[\]{}]', Punctuation),
-        ],
-
-        'doublequote': [
-            (r'\\u[0-9a-fA-F]{4}', String.Escape),
-            (r'\\[nrfvb\\"]', String.Escape),
-            (r'[^"]', String),
-            (r'"', String, '#pop'),
-        ],
-
-        'utf8quote': [
-            (r'\\u[0-9a-fA-F]{4}', String.Escape),
-            (r'\\[nrfvb\\\']', String.Escape),
-            (r'[^\']', String),
-            (r'\'', String, '#pop'),
-        ],
-
-        'singlequote': [
-            (r'[^\']', String),
-            (r'\'', String, '#pop'),
-        ],
-
-        'numbers': [
-            (r'_?\d+', Number.Integer),
-        ],
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/rita.py b/.venv/lib/python3.12/site-packages/pygments/lexers/rita.py
deleted file mode 100644
index 99a574c..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/rita.py
+++ /dev/null
@@ -1,42 +0,0 @@
-"""
-    pygments.lexers.rita
-    ~~~~~~~~~~~~~~~~~~~~
-
-    Lexers for RITA language
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-from pygments.lexer import RegexLexer
-from pygments.token import Comment, Operator, Keyword, Name, Literal, \
-    Punctuation, Whitespace
-
-__all__ = ['RitaLexer']
-
-
-class RitaLexer(RegexLexer):
-    """
-    Lexer for RITA.
-    """
-    name = 'Rita'
-    url = 'https://github.com/zaibacu/rita-dsl'
-    filenames = ['*.rita']
-    aliases = ['rita']
-    mimetypes = ['text/rita']
-    version_added = '2.11'
-
-    tokens = {
-        'root': [
-            (r'\n', Whitespace),
-            (r'\s+', Whitespace),
-            (r'#(.*?)\n', Comment.Single),
-            (r'@(.*?)\n', Operator),  # Yes, whole line as an operator
-            (r'"(\w|\d|\s|(\\")|[\'_\-./,\?\!])+?"', Literal),
-            (r'\'(\w|\d|\s|(\\\')|["_\-./,\?\!])+?\'', Literal),
-            (r'([A-Z_]+)', Keyword),
-            (r'([a-z0-9_]+)', Name),
-            (r'((->)|[!?+*|=])', Operator),
-            (r'[\(\),\{\}]', Punctuation)
-        ]
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/rnc.py b/.venv/lib/python3.12/site-packages/pygments/lexers/rnc.py
deleted file mode 100644
index 7ddd33e..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/rnc.py
+++ /dev/null
@@ -1,66 +0,0 @@
-"""
-    pygments.lexers.rnc
-    ~~~~~~~~~~~~~~~~~~~
-
-    Lexer for Relax-NG Compact syntax
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-from pygments.lexer import RegexLexer
-from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
-    Punctuation
-
-__all__ = ['RNCCompactLexer']
-
-
-class RNCCompactLexer(RegexLexer):
-    """
-    For RelaxNG-compact syntax.
-    """
-
-    name = 'Relax-NG Compact'
-    url = 'http://relaxng.org'
-    aliases = ['rng-compact', 'rnc']
-    filenames = ['*.rnc']
-    version_added = '2.2'
-
-    tokens = {
-        'root': [
-            (r'namespace\b', Keyword.Namespace),
-            (r'(?:default|datatypes)\b', Keyword.Declaration),
-            (r'##.*$', Comment.Preproc),
-            (r'#.*$', Comment.Single),
-            (r'"[^"]*"', String.Double),
-            # TODO single quoted strings and escape sequences outside of
-            # double-quoted strings
-            (r'(?:element|attribute|mixed)\b', Keyword.Declaration, 'variable'),
-            (r'(text\b|xsd:[^ ]+)', Keyword.Type, 'maybe_xsdattributes'),
-            (r'[,?&*=|~]|>>', Operator),
-            (r'[(){}]', Punctuation),
-            (r'.', Text),
-        ],
-
-        # a variable has been declared using `element` or `attribute`
-        'variable': [
-            (r'[^{]+', Name.Variable),
-            (r'\{', Punctuation, '#pop'),
-        ],
-
-        # after an xsd: declaration there may be attributes
-        'maybe_xsdattributes': [
-            (r'\{', Punctuation, 'xsdattributes'),
-            (r'\}', Punctuation, '#pop'),
-            (r'.', Text),
-        ],
-
-        # attributes take the form { key1 = value1 key2 = value2 ... }
-        'xsdattributes': [
-            (r'[^ =}]', Name.Attribute),
-            (r'=', Operator),
-            (r'"[^"]*"', String.Double),
-            (r'\}', Punctuation, '#pop'),
-            (r'.', Text),
-        ],
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/roboconf.py b/.venv/lib/python3.12/site-packages/pygments/lexers/roboconf.py
deleted file mode 100644
index bf0570c..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/roboconf.py
+++ /dev/null
@@ -1,81 +0,0 @@
-"""
-    pygments.lexers.roboconf
-    ~~~~~~~~~~~~~~~~~~~~~~~~
-
-    Lexers for Roboconf DSL.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-from pygments.lexer import RegexLexer, words, re
-from pygments.token import Text, Operator, Keyword, Name, Comment
-
-__all__ = ['RoboconfGraphLexer', 'RoboconfInstancesLexer']
-
-
-class RoboconfGraphLexer(RegexLexer):
-    """
-    Lexer for Roboconf graph files.
-    """
-    name = 'Roboconf Graph'
-    aliases = ['roboconf-graph']
-    filenames = ['*.graph']
-    url = 'https://roboconf.github.io/en/user-guide/graph-definition.html'
-    version_added = '2.1'
-
-    flags = re.IGNORECASE | re.MULTILINE
-    tokens = {
-        'root': [
-            # Skip white spaces
-            (r'\s+', Text),
-
-            # There is one operator
-            (r'=', Operator),
-
-            # Keywords
-            (words(('facet', 'import'), suffix=r'\s*\b', prefix=r'\b'), Keyword),
-            (words((
-                'installer', 'extends', 'exports', 'imports', 'facets',
-                'children'), suffix=r'\s*:?', prefix=r'\b'), Name),
-
-            # Comments
-            (r'#.*\n', Comment),
-
-            # Default
-            (r'[^#]', Text),
-            (r'.*\n', Text)
-        ]
-    }
-
-
-class RoboconfInstancesLexer(RegexLexer):
-    """
-    Lexer for Roboconf instances files.
-    """
-    name = 'Roboconf Instances'
-    aliases = ['roboconf-instances']
-    filenames = ['*.instances']
-    url = 'https://roboconf.github.io'
-    version_added = '2.1'
-
-    flags = re.IGNORECASE | re.MULTILINE
-    tokens = {
-        'root': [
-
-            # Skip white spaces
-            (r'\s+', Text),
-
-            # Keywords
-            (words(('instance of', 'import'), suffix=r'\s*\b', prefix=r'\b'), Keyword),
-            (words(('name', 'count'), suffix=r's*:?', prefix=r'\b'), Name),
-            (r'\s*[\w.-]+\s*:', Name),
-
-            # Comments
-            (r'#.*\n', Comment),
-
-            # Default
-            (r'[^#]', Text),
-            (r'.*\n', Text)
-        ]
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/robotframework.py b/.venv/lib/python3.12/site-packages/pygments/lexers/robotframework.py
deleted file mode 100644
index a481136..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/robotframework.py
+++ /dev/null
@@ -1,551 +0,0 @@
-"""
-    pygments.lexers.robotframework
-    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-    Lexer for Robot Framework.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-#  Copyright 2012 Nokia Siemens Networks Oyj
-#
-#  Licensed under the Apache License, Version 2.0 (the "License");
-#  you may not use this file except in compliance with the License.
-#  You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-#  Unless required by applicable law or agreed to in writing, software
-#  distributed under the License is distributed on an "AS IS" BASIS,
-#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-#  See the License for the specific language governing permissions and
-#  limitations under the License.
-
-import re
-
-from pygments.lexer import Lexer
-from pygments.token import Token
-
-__all__ = ['RobotFrameworkLexer']
-
-
-HEADING = Token.Generic.Heading
-SETTING = Token.Keyword.Namespace
-IMPORT = Token.Name.Namespace
-TC_KW_NAME = Token.Generic.Subheading
-KEYWORD = Token.Name.Function
-ARGUMENT = Token.String
-VARIABLE = Token.Name.Variable
-COMMENT = Token.Comment
-SEPARATOR = Token.Punctuation
-SYNTAX = Token.Punctuation
-GHERKIN = Token.Generic.Emph
-ERROR = Token.Error
-
-
-def normalize(string, remove=''):
-    string = string.lower()
-    for char in remove + ' ':
-        if char in string:
-            string = string.replace(char, '')
-    return string
-
-
-class RobotFrameworkLexer(Lexer):
-    """
-    For Robot Framework test data.
-
-    Supports both space and pipe separated plain text formats.
-    """
-    name = 'RobotFramework'
-    url = 'http://robotframework.org'
-    aliases = ['robotframework']
-    filenames = ['*.robot', '*.resource']
-    mimetypes = ['text/x-robotframework']
-    version_added = '1.6'
-
-    def __init__(self, **options):
-        options['tabsize'] = 2
-        options['encoding'] = 'UTF-8'
-        Lexer.__init__(self, **options)
-
-    def get_tokens_unprocessed(self, text):
-        row_tokenizer = RowTokenizer()
-        var_tokenizer = VariableTokenizer()
-        index = 0
-        for row in text.splitlines():
-            for value, token in row_tokenizer.tokenize(row):
-                for value, token in var_tokenizer.tokenize(value, token):
-                    if value:
-                        yield index, token, str(value)
-                        index += len(value)
-
-
-class VariableTokenizer:
-
-    def tokenize(self, string, token):
-        var = VariableSplitter(string, identifiers='$@%&')
-        if var.start < 0 or token in (COMMENT, ERROR):
-            yield string, token
-            return
-        for value, token in self._tokenize(var, string, token):
-            if value:
-                yield value, token
-
-    def _tokenize(self, var, string, orig_token):
-        before = string[:var.start]
-        yield before, orig_token
-        yield var.identifier + '{', SYNTAX
-        yield from self.tokenize(var.base, VARIABLE)
-        yield '}', SYNTAX
-        if var.index is not None:
-            yield '[', SYNTAX
-            yield from self.tokenize(var.index, VARIABLE)
-            yield ']', SYNTAX
-        yield from self.tokenize(string[var.end:], orig_token)
-
-
-class RowTokenizer:
-
-    def __init__(self):
-        self._table = UnknownTable()
-        self._splitter = RowSplitter()
-        testcases = TestCaseTable()
-        settings = SettingTable(testcases.set_default_template)
-        variables = VariableTable()
-        keywords = KeywordTable()
-        self._tables = {'settings': settings, 'setting': settings,
-                        'metadata': settings,
-                        'variables': variables, 'variable': variables,
-                        'testcases': testcases, 'testcase': testcases,
-                        'tasks': testcases, 'task': testcases,
-                        'keywords': keywords, 'keyword': keywords,
-                        'userkeywords': keywords, 'userkeyword': keywords}
-
-    def tokenize(self, row):
-        commented = False
-        heading = False
-        for index, value in enumerate(self._splitter.split(row)):
-            # First value, and every second after that, is a separator.
-            index, separator = divmod(index-1, 2)
-            if value.startswith('#'):
-                commented = True
-            elif index == 0 and value.startswith('*'):
-                self._table = self._start_table(value)
-                heading = True
-            yield from self._tokenize(value, index, commented,
-                                      separator, heading)
-        self._table.end_row()
-
-    def _start_table(self, header):
-        name = normalize(header, remove='*')
-        return self._tables.get(name, UnknownTable())
-
-    def _tokenize(self, value, index, commented, separator, heading):
-        if commented:
-            yield value, COMMENT
-        elif separator:
-            yield value, SEPARATOR
-        elif heading:
-            yield value, HEADING
-        else:
-            yield from self._table.tokenize(value, index)
-
-
-class RowSplitter:
-    _space_splitter = re.compile('( {2,})')
-    _pipe_splitter = re.compile(r'((?:^| +)\|(?: +|$))')
-
-    def split(self, row):
-        splitter = (row.startswith('| ') and self._split_from_pipes
-                    or self._split_from_spaces)
-        yield from splitter(row)
-        yield '\n'
-
-    def _split_from_spaces(self, row):
-        yield ''  # Start with (pseudo)separator similarly as with pipes
-        yield from self._space_splitter.split(row)
-
-    def _split_from_pipes(self, row):
-        _, separator, rest = self._pipe_splitter.split(row, 1)
-        yield separator
-        while self._pipe_splitter.search(rest):
-            cell, separator, rest = self._pipe_splitter.split(rest, 1)
-            yield cell
-            yield separator
-        yield rest
-
-
-class Tokenizer:
-    _tokens = None
-
-    def __init__(self):
-        self._index = 0
-
-    def tokenize(self, value):
-        values_and_tokens = self._tokenize(value, self._index)
-        self._index += 1
-        if isinstance(values_and_tokens, type(Token)):
-            values_and_tokens = [(value, values_and_tokens)]
-        return values_and_tokens
-
-    def _tokenize(self, value, index):
-        index = min(index, len(self._tokens) - 1)
-        return self._tokens[index]
-
-    def _is_assign(self, value):
-        if value.endswith('='):
-            value = value[:-1].strip()
-        var = VariableSplitter(value, identifiers='$@&')
-        return var.start == 0 and var.end == len(value)
-
-
-class Comment(Tokenizer):
-    _tokens = (COMMENT,)
-
-
-class Setting(Tokenizer):
-    _tokens = (SETTING, ARGUMENT)
-    _keyword_settings = ('suitesetup', 'suiteprecondition', 'suiteteardown',
-                         'suitepostcondition', 'testsetup', 'tasksetup', 'testprecondition',
-                         'testteardown','taskteardown', 'testpostcondition', 'testtemplate', 'tasktemplate')
-    _import_settings = ('library', 'resource', 'variables')
-    _other_settings = ('documentation', 'metadata', 'forcetags', 'defaulttags',
-                       'testtimeout','tasktimeout')
-    _custom_tokenizer = None
-
-    def __init__(self, template_setter=None):
-        Tokenizer.__init__(self)
-        self._template_setter = template_setter
-
-    def _tokenize(self, value, index):
-        if index == 1 and self._template_setter:
-            self._template_setter(value)
-        if index == 0:
-            normalized = normalize(value)
-            if normalized in self._keyword_settings:
-                self._custom_tokenizer = KeywordCall(support_assign=False)
-            elif normalized in self._import_settings:
-                self._custom_tokenizer = ImportSetting()
-            elif normalized not in self._other_settings:
-                return ERROR
-        elif self._custom_tokenizer:
-            return self._custom_tokenizer.tokenize(value)
-        return Tokenizer._tokenize(self, value, index)
-
-
-class ImportSetting(Tokenizer):
-    _tokens = (IMPORT, ARGUMENT)
-
-
-class TestCaseSetting(Setting):
-    _keyword_settings = ('setup', 'precondition', 'teardown', 'postcondition',
-                         'template')
-    _import_settings = ()
-    _other_settings = ('documentation', 'tags', 'timeout')
-
-    def _tokenize(self, value, index):
-        if index == 0:
-            type = Setting._tokenize(self, value[1:-1], index)
-            return [('[', SYNTAX), (value[1:-1], type), (']', SYNTAX)]
-        return Setting._tokenize(self, value, index)
-
-
-class KeywordSetting(TestCaseSetting):
-    _keyword_settings = ('teardown',)
-    _other_settings = ('documentation', 'arguments', 'return', 'timeout', 'tags')
-
-
-class Variable(Tokenizer):
-    _tokens = (SYNTAX, ARGUMENT)
-
-    def _tokenize(self, value, index):
-        if index == 0 and not self._is_assign(value):
-            return ERROR
-        return Tokenizer._tokenize(self, value, index)
-
-
-class KeywordCall(Tokenizer):
-    _tokens = (KEYWORD, ARGUMENT)
-
-    def __init__(self, support_assign=True):
-        Tokenizer.__init__(self)
-        self._keyword_found = not support_assign
-        self._assigns = 0
-
-    def _tokenize(self, value, index):
-        if not self._keyword_found and self._is_assign(value):
-            self._assigns += 1
-            return SYNTAX  # VariableTokenizer tokenizes this later.
-        if self._keyword_found:
-            return Tokenizer._tokenize(self, value, index - self._assigns)
-        self._keyword_found = True
-        return GherkinTokenizer().tokenize(value, KEYWORD)
-
-
-class GherkinTokenizer:
-    _gherkin_prefix = re.compile('^(Given|When|Then|And|But) ', re.IGNORECASE)
-
-    def tokenize(self, value, token):
-        match = self._gherkin_prefix.match(value)
-        if not match:
-            return [(value, token)]
-        end = match.end()
-        return [(value[:end], GHERKIN), (value[end:], token)]
-
-
-class TemplatedKeywordCall(Tokenizer):
-    _tokens = (ARGUMENT,)
-
-
-class ForLoop(Tokenizer):
-
-    def __init__(self):
-        Tokenizer.__init__(self)
-        self._in_arguments = False
-
-    def _tokenize(self, value, index):
-        token = self._in_arguments and ARGUMENT or SYNTAX
-        if value.upper() in ('IN', 'IN RANGE'):
-            self._in_arguments = True
-        return token
-
-
-class _Table:
-    _tokenizer_class = None
-
-    def __init__(self, prev_tokenizer=None):
-        self._tokenizer = self._tokenizer_class()
-        self._prev_tokenizer = prev_tokenizer
-        self._prev_values_on_row = []
-
-    def tokenize(self, value, index):
-        if self._continues(value, index):
-            self._tokenizer = self._prev_tokenizer
-            yield value, SYNTAX
-        else:
-            yield from self._tokenize(value, index)
-        self._prev_values_on_row.append(value)
-
-    def _continues(self, value, index):
-        return value == '...' and all(self._is_empty(t)
-                                      for t in self._prev_values_on_row)
-
-    def _is_empty(self, value):
-        return value in ('', '\\')
-
-    def _tokenize(self, value, index):
-        return self._tokenizer.tokenize(value)
-
-    def end_row(self):
-        self.__init__(prev_tokenizer=self._tokenizer)
-
-
-class UnknownTable(_Table):
-    _tokenizer_class = Comment
-
-    def _continues(self, value, index):
-        return False
-
-
-class VariableTable(_Table):
-    _tokenizer_class = Variable
-
-
-class SettingTable(_Table):
-    _tokenizer_class = Setting
-
-    def __init__(self, template_setter, prev_tokenizer=None):
-        _Table.__init__(self, prev_tokenizer)
-        self._template_setter = template_setter
-
-    def _tokenize(self, value, index):
-        if index == 0 and normalize(value) == 'testtemplate':
-            self._tokenizer = Setting(self._template_setter)
-        return _Table._tokenize(self, value, index)
-
-    def end_row(self):
-        self.__init__(self._template_setter, prev_tokenizer=self._tokenizer)
-
-
-class TestCaseTable(_Table):
-    _setting_class = TestCaseSetting
-    _test_template = None
-    _default_template = None
-
-    @property
-    def _tokenizer_class(self):
-        if self._test_template or (self._default_template and
-                                   self._test_template is not False):
-            return TemplatedKeywordCall
-        return KeywordCall
-
-    def _continues(self, value, index):
-        return index > 0 and _Table._continues(self, value, index)
-
-    def _tokenize(self, value, index):
-        if index == 0:
-            if value:
-                self._test_template = None
-            return GherkinTokenizer().tokenize(value, TC_KW_NAME)
-        if index == 1 and self._is_setting(value):
-            if self._is_template(value):
-                self._test_template = False
-                self._tokenizer = self._setting_class(self.set_test_template)
-            else:
-                self._tokenizer = self._setting_class()
-        if index == 1 and self._is_for_loop(value):
-            self._tokenizer = ForLoop()
-        if index == 1 and self._is_empty(value):
-            return [(value, SYNTAX)]
-        return _Table._tokenize(self, value, index)
-
-    def _is_setting(self, value):
-        return value.startswith('[') and value.endswith(']')
-
-    def _is_template(self, value):
-        return normalize(value) == '[template]'
-
-    def _is_for_loop(self, value):
-        return value.startswith(':') and normalize(value, remove=':') == 'for'
-
-    def set_test_template(self, template):
-        self._test_template = self._is_template_set(template)
-
-    def set_default_template(self, template):
-        self._default_template = self._is_template_set(template)
-
-    def _is_template_set(self, template):
-        return normalize(template) not in ('', '\\', 'none', '${empty}')
-
-
-class KeywordTable(TestCaseTable):
-    _tokenizer_class = KeywordCall
-    _setting_class = KeywordSetting
-
-    def _is_template(self, value):
-        return False
-
-
-# Following code copied directly from Robot Framework 2.7.5.
-
-class VariableSplitter:
-
-    def __init__(self, string, identifiers):
-        self.identifier = None
-        self.base = None
-        self.index = None
-        self.start = -1
-        self.end = -1
-        self._identifiers = identifiers
-        self._may_have_internal_variables = False
-        try:
-            self._split(string)
-        except ValueError:
-            pass
-        else:
-            self._finalize()
-
-    def get_replaced_base(self, variables):
-        if self._may_have_internal_variables:
-            return variables.replace_string(self.base)
-        return self.base
-
-    def _finalize(self):
-        self.identifier = self._variable_chars[0]
-        self.base = ''.join(self._variable_chars[2:-1])
-        self.end = self.start + len(self._variable_chars)
-        if self._has_list_or_dict_variable_index():
-            self.index = ''.join(self._list_and_dict_variable_index_chars[1:-1])
-            self.end += len(self._list_and_dict_variable_index_chars)
-
-    def _has_list_or_dict_variable_index(self):
-        return self._list_and_dict_variable_index_chars\
-        and self._list_and_dict_variable_index_chars[-1] == ']'
-
-    def _split(self, string):
-        start_index, max_index = self._find_variable(string)
-        self.start = start_index
-        self._open_curly = 1
-        self._state = self._variable_state
-        self._variable_chars = [string[start_index], '{']
-        self._list_and_dict_variable_index_chars = []
-        self._string = string
-        start_index += 2
-        for index, char in enumerate(string[start_index:]):
-            index += start_index  # Giving start to enumerate only in Py 2.6+
-            try:
-                self._state(char, index)
-            except StopIteration:
-                return
-            if index  == max_index and not self._scanning_list_variable_index():
-                return
-
-    def _scanning_list_variable_index(self):
-        return self._state in [self._waiting_list_variable_index_state,
-                               self._list_variable_index_state]
-
-    def _find_variable(self, string):
-        max_end_index = string.rfind('}')
-        if max_end_index == -1:
-            raise ValueError('No variable end found')
-        if self._is_escaped(string, max_end_index):
-            return self._find_variable(string[:max_end_index])
-        start_index = self._find_start_index(string, 1, max_end_index)
-        if start_index == -1:
-            raise ValueError('No variable start found')
-        return start_index, max_end_index
-
-    def _find_start_index(self, string, start, end):
-        index = string.find('{', start, end) - 1
-        if index < 0:
-            return -1
-        if self._start_index_is_ok(string, index):
-            return index
-        return self._find_start_index(string, index+2, end)
-
-    def _start_index_is_ok(self, string, index):
-        return string[index] in self._identifiers\
-        and not self._is_escaped(string, index)
-
-    def _is_escaped(self, string, index):
-        escaped = False
-        while index > 0 and string[index-1] == '\\':
-            index -= 1
-            escaped = not escaped
-        return escaped
-
-    def _variable_state(self, char, index):
-        self._variable_chars.append(char)
-        if char == '}' and not self._is_escaped(self._string, index):
-            self._open_curly -= 1
-            if self._open_curly == 0:
-                if not self._is_list_or_dict_variable():
-                    raise StopIteration
-                self._state = self._waiting_list_variable_index_state
-        elif char in self._identifiers:
-            self._state = self._internal_variable_start_state
-
-    def _is_list_or_dict_variable(self):
-        return self._variable_chars[0] in ('@','&')
-
-    def _internal_variable_start_state(self, char, index):
-        self._state = self._variable_state
-        if char == '{':
-            self._variable_chars.append(char)
-            self._open_curly += 1
-            self._may_have_internal_variables = True
-        else:
-            self._variable_state(char, index)
-
-    def _waiting_list_variable_index_state(self, char, index):
-        if char != '[':
-            raise StopIteration
-        self._list_and_dict_variable_index_chars.append(char)
-        self._state = self._list_variable_index_state
-
-    def _list_variable_index_state(self, char, index):
-        self._list_and_dict_variable_index_chars.append(char)
-        if char == ']':
-            raise StopIteration
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/ruby.py b/.venv/lib/python3.12/site-packages/pygments/lexers/ruby.py
deleted file mode 100644
index 6832652..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/ruby.py
+++ /dev/null
@@ -1,518 +0,0 @@
-"""
-    pygments.lexers.ruby
-    ~~~~~~~~~~~~~~~~~~~~
-
-    Lexers for Ruby and related languages.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-import re
-
-from pygments.lexer import Lexer, RegexLexer, ExtendedRegexLexer, include, \
-    bygroups, default, LexerContext, do_insertions, words, line_re
-from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
-    Number, Punctuation, Error, Generic, Whitespace
-from pygments.util import shebang_matches
-
-__all__ = ['RubyLexer', 'RubyConsoleLexer', 'FancyLexer']
-
-
-RUBY_OPERATORS = (
-    '*', '**', '-', '+', '-@', '+@', '/', '%', '&', '|', '^', '`', '~',
-    '[]', '[]=', '<<', '>>', '<', '<>', '<=>', '>', '>=', '==', '==='
-)
-
-
-class RubyLexer(ExtendedRegexLexer):
-    """
-    For Ruby source code.
-    """
-
-    name = 'Ruby'
-    url = 'http://www.ruby-lang.org'
-    aliases = ['ruby', 'rb', 'duby']
-    filenames = ['*.rb', '*.rbw', 'Rakefile', '*.rake', '*.gemspec',
-                 '*.rbx', '*.duby', 'Gemfile', 'Vagrantfile']
-    mimetypes = ['text/x-ruby', 'application/x-ruby']
-    version_added = ''
-
-    flags = re.DOTALL | re.MULTILINE
-
-    def heredoc_callback(self, match, ctx):
-        # okay, this is the hardest part of parsing Ruby...
-        # match: 1 = <<[-~]?, 2 = quote? 3 = name 4 = quote? 5 = rest of line
-
-        start = match.start(1)
-        yield start, Operator, match.group(1)        # <<[-~]?
-        yield match.start(2), String.Heredoc, match.group(2)   # quote ", ', `
-        yield match.start(3), String.Delimiter, match.group(3) # heredoc name
-        yield match.start(4), String.Heredoc, match.group(4)   # quote again
-
-        heredocstack = ctx.__dict__.setdefault('heredocstack', [])
-        outermost = not bool(heredocstack)
-        heredocstack.append((match.group(1) in ('<<-', '<<~'), match.group(3)))
-
-        ctx.pos = match.start(5)
-        ctx.end = match.end(5)
-        # this may find other heredocs, so limit the recursion depth
-        if len(heredocstack) < 100:
-            yield from self.get_tokens_unprocessed(context=ctx)
-        else:
-            yield ctx.pos, String.Heredoc, match.group(5)
-        ctx.pos = match.end()
-
-        if outermost:
-            # this is the outer heredoc again, now we can process them all
-            for tolerant, hdname in heredocstack:
-                lines = []
-                for match in line_re.finditer(ctx.text, ctx.pos):
-                    if tolerant:
-                        check = match.group().strip()
-                    else:
-                        check = match.group().rstrip()
-                    if check == hdname:
-                        for amatch in lines:
-                            yield amatch.start(), String.Heredoc, amatch.group()
-                        yield match.start(), String.Delimiter, match.group()
-                        ctx.pos = match.end()
-                        break
-                    else:
-                        lines.append(match)
-                else:
-                    # end of heredoc not found -- error!
-                    for amatch in lines:
-                        yield amatch.start(), Error, amatch.group()
-            ctx.end = len(ctx.text)
-            del heredocstack[:]
-
-    def gen_rubystrings_rules():
-        def intp_regex_callback(self, match, ctx):
-            yield match.start(1), String.Regex, match.group(1)  # begin
-            nctx = LexerContext(match.group(3), 0, ['interpolated-regex'])
-            for i, t, v in self.get_tokens_unprocessed(context=nctx):
-                yield match.start(3)+i, t, v
-            yield match.start(4), String.Regex, match.group(4)  # end[mixounse]*
-            ctx.pos = match.end()
-
-        def intp_string_callback(self, match, ctx):
-            yield match.start(1), String.Other, match.group(1)
-            nctx = LexerContext(match.group(3), 0, ['interpolated-string'])
-            for i, t, v in self.get_tokens_unprocessed(context=nctx):
-                yield match.start(3)+i, t, v
-            yield match.start(4), String.Other, match.group(4)  # end
-            ctx.pos = match.end()
-
-        states = {}
-        states['strings'] = [
-            # easy ones
-            (r'\:@{0,2}[a-zA-Z_]\w*[!?]?', String.Symbol),
-            (words(RUBY_OPERATORS, prefix=r'\:@{0,2}'), String.Symbol),
-            (r":'(\\\\|\\[^\\]|[^'\\])*'", String.Symbol),
-            (r':"', String.Symbol, 'simple-sym'),
-            (r'([a-zA-Z_]\w*)(:)(?!:)',
-             bygroups(String.Symbol, Punctuation)),  # Since Ruby 1.9
-            (r'"', String.Double, 'simple-string-double'),
-            (r"'", String.Single, 'simple-string-single'),
-            (r'(?', '<>', 'ab'):
-            states[name+'-intp-string'] = [
-                (r'\\[\\' + bracecc + ']', String.Other),
-                (lbrace, String.Other, '#push'),
-                (rbrace, String.Other, '#pop'),
-                include('string-intp-escaped'),
-                (r'[\\#' + bracecc + ']', String.Other),
-                (r'[^\\#' + bracecc + ']+', String.Other),
-            ]
-            states['strings'].append((r'%[QWx]?' + lbrace, String.Other,
-                                      name+'-intp-string'))
-            states[name+'-string'] = [
-                (r'\\[\\' + bracecc + ']', String.Other),
-                (lbrace, String.Other, '#push'),
-                (rbrace, String.Other, '#pop'),
-                (r'[\\#' + bracecc + ']', String.Other),
-                (r'[^\\#' + bracecc + ']+', String.Other),
-            ]
-            states['strings'].append((r'%[qsw]' + lbrace, String.Other,
-                                      name+'-string'))
-            states[name+'-regex'] = [
-                (r'\\[\\' + bracecc + ']', String.Regex),
-                (lbrace, String.Regex, '#push'),
-                (rbrace + '[mixounse]*', String.Regex, '#pop'),
-                include('string-intp'),
-                (r'[\\#' + bracecc + ']', String.Regex),
-                (r'[^\\#' + bracecc + ']+', String.Regex),
-            ]
-            states['strings'].append((r'%r' + lbrace, String.Regex,
-                                      name+'-regex'))
-
-        # these must come after %!
-        states['strings'] += [
-            # %r regex
-            (r'(%r([\W_]))((?:\\\2|(?!\2).)*)(\2[mixounse]*)',
-             intp_regex_callback),
-            # regular fancy strings with qsw
-            (r'%[qsw]([\W_])((?:\\\1|(?!\1).)*)\1', String.Other),
-            (r'(%[QWx]([\W_]))((?:\\\2|(?!\2).)*)(\2)',
-             intp_string_callback),
-            # special forms of fancy strings after operators or
-            # in method calls with braces
-            (r'(?<=[-+/*%=<>&!^|~,(])(\s*)(%([\t ])(?:(?:\\\3|(?!\3).)*)\3)',
-             bygroups(Whitespace, String.Other, None)),
-            # and because of fixed width lookbehinds the whole thing a
-            # second time for line startings...
-            (r'^(\s*)(%([\t ])(?:(?:\\\3|(?!\3).)*)\3)',
-             bygroups(Whitespace, String.Other, None)),
-            # all regular fancy strings without qsw
-            (r'(%([^a-zA-Z0-9\s]))((?:\\\2|(?!\2).)*)(\2)',
-             intp_string_callback),
-        ]
-
-        return states
-
-    tokens = {
-        'root': [
-            (r'\A#!.+?$', Comment.Hashbang),
-            (r'#.*?$', Comment.Single),
-            (r'=begin\s.*?\n=end.*?$', Comment.Multiline),
-            # keywords
-            (words((
-                'BEGIN', 'END', 'alias', 'begin', 'break', 'case', 'defined?',
-                'do', 'else', 'elsif', 'end', 'ensure', 'for', 'if', 'in', 'next', 'redo',
-                'rescue', 'raise', 'retry', 'return', 'super', 'then', 'undef',
-                'unless', 'until', 'when', 'while', 'yield'), suffix=r'\b'),
-             Keyword),
-            # start of function, class and module names
-            (r'(module)(\s+)([a-zA-Z_]\w*'
-             r'(?:::[a-zA-Z_]\w*)*)',
-             bygroups(Keyword, Whitespace, Name.Namespace)),
-            (r'(def)(\s+)', bygroups(Keyword, Whitespace), 'funcname'),
-            (r'def(?=[*%&^`~+-/\[<>=])', Keyword, 'funcname'),
-            (r'(class)(\s+)', bygroups(Keyword, Whitespace), 'classname'),
-            # special methods
-            (words((
-                'initialize', 'new', 'loop', 'include', 'extend', 'raise', 'attr_reader',
-                'attr_writer', 'attr_accessor', 'attr', 'catch', 'throw', 'private',
-                'module_function', 'public', 'protected', 'true', 'false', 'nil'),
-                suffix=r'\b'),
-             Keyword.Pseudo),
-            (r'(not|and|or)\b', Operator.Word),
-            (words((
-                'autoload', 'block_given', 'const_defined', 'eql', 'equal', 'frozen', 'include',
-                'instance_of', 'is_a', 'iterator', 'kind_of', 'method_defined', 'nil',
-                'private_method_defined', 'protected_method_defined',
-                'public_method_defined', 'respond_to', 'tainted'), suffix=r'\?'),
-             Name.Builtin),
-            (r'(chomp|chop|exit|gsub|sub)!', Name.Builtin),
-            (words((
-                'Array', 'Float', 'Integer', 'String', '__id__', '__send__', 'abort',
-                'ancestors', 'at_exit', 'autoload', 'binding', 'callcc', 'caller',
-                'catch', 'chomp', 'chop', 'class_eval', 'class_variables',
-                'clone', 'const_defined?', 'const_get', 'const_missing', 'const_set',
-                'constants', 'display', 'dup', 'eval', 'exec', 'exit', 'extend', 'fail', 'fork',
-                'format', 'freeze', 'getc', 'gets', 'global_variables', 'gsub',
-                'hash', 'id', 'included_modules', 'inspect', 'instance_eval',
-                'instance_method', 'instance_methods',
-                'instance_variable_get', 'instance_variable_set', 'instance_variables',
-                'lambda', 'load', 'local_variables', 'loop',
-                'method', 'method_missing', 'methods', 'module_eval', 'name',
-                'object_id', 'open', 'p', 'print', 'printf', 'private_class_method',
-                'private_instance_methods',
-                'private_methods', 'proc', 'protected_instance_methods',
-                'protected_methods', 'public_class_method',
-                'public_instance_methods', 'public_methods',
-                'putc', 'puts', 'raise', 'rand', 'readline', 'readlines', 'require',
-                'scan', 'select', 'self', 'send', 'set_trace_func', 'singleton_methods', 'sleep',
-                'split', 'sprintf', 'srand', 'sub', 'syscall', 'system', 'taint',
-                'test', 'throw', 'to_a', 'to_s', 'trace_var', 'trap', 'untaint',
-                'untrace_var', 'warn'), prefix=r'(?~!:])|'
-             r'(?<=(?:\s|;)when\s)|'
-             r'(?<=(?:\s|;)or\s)|'
-             r'(?<=(?:\s|;)and\s)|'
-             r'(?<=\.index\s)|'
-             r'(?<=\.scan\s)|'
-             r'(?<=\.sub\s)|'
-             r'(?<=\.sub!\s)|'
-             r'(?<=\.gsub\s)|'
-             r'(?<=\.gsub!\s)|'
-             r'(?<=\.match\s)|'
-             r'(?<=(?:\s|;)if\s)|'
-             r'(?<=(?:\s|;)elsif\s)|'
-             r'(?<=^when\s)|'
-             r'(?<=^index\s)|'
-             r'(?<=^scan\s)|'
-             r'(?<=^sub\s)|'
-             r'(?<=^gsub\s)|'
-             r'(?<=^sub!\s)|'
-             r'(?<=^gsub!\s)|'
-             r'(?<=^match\s)|'
-             r'(?<=^if\s)|'
-             r'(?<=^elsif\s)'
-             r')(\s*)(/)', bygroups(Text, String.Regex), 'multiline-regex'),
-            # multiline regex (in method calls or subscripts)
-            (r'(?<=\(|,|\[)/', String.Regex, 'multiline-regex'),
-            # multiline regex (this time the funny no whitespace rule)
-            (r'(\s+)(/)(?![\s=])', bygroups(Whitespace, String.Regex),
-             'multiline-regex'),
-            # lex numbers and ignore following regular expressions which
-            # are division operators in fact (grrrr. i hate that. any
-            # better ideas?)
-            # since pygments 0.7 we also eat a "?" operator after numbers
-            # so that the char operator does not work. Chars are not allowed
-            # there so that you can use the ternary operator.
-            # stupid example:
-            #   x>=0?n[x]:""
-            (r'(0_?[0-7]+(?:_[0-7]+)*)(\s*)([/?])?',
-             bygroups(Number.Oct, Whitespace, Operator)),
-            (r'(0x[0-9A-Fa-f]+(?:_[0-9A-Fa-f]+)*)(\s*)([/?])?',
-             bygroups(Number.Hex, Whitespace, Operator)),
-            (r'(0b[01]+(?:_[01]+)*)(\s*)([/?])?',
-             bygroups(Number.Bin, Whitespace, Operator)),
-            (r'([\d]+(?:_\d+)*)(\s*)([/?])?',
-             bygroups(Number.Integer, Whitespace, Operator)),
-            # Names
-            (r'@@[a-zA-Z_]\w*', Name.Variable.Class),
-            (r'@[a-zA-Z_]\w*', Name.Variable.Instance),
-            (r'\$\w+', Name.Variable.Global),
-            (r'\$[!@&`\'+~=/\\,;.<>_*$?:"^-]', Name.Variable.Global),
-            (r'\$-[0adFiIlpvw]', Name.Variable.Global),
-            (r'::', Operator),
-            include('strings'),
-            # chars
-            (r'\?(\\[MC]-)*'  # modifiers
-             r'(\\([\\abefnrstv#"\']|x[a-fA-F0-9]{1,2}|[0-7]{1,3})|\S)'
-             r'(?!\w)',
-             String.Char),
-            (r'[A-Z]\w+', Name.Constant),
-            # this is needed because ruby attributes can look
-            # like keywords (class) or like this: ` ?!?
-            (words(RUBY_OPERATORS, prefix=r'(\.|::)'),
-             bygroups(Operator, Name.Operator)),
-            (r'(\.|::)([a-zA-Z_]\w*[!?]?|[*%&^`~+\-/\[<>=])',
-             bygroups(Operator, Name)),
-            (r'[a-zA-Z_]\w*[!?]?', Name),
-            (r'(\[|\]|\*\*|<>?|>=|<=|<=>|=~|={3}|'
-             r'!~|&&?|\|\||\.{1,3})', Operator),
-            (r'[-+/*%=<>&!^|~]=?', Operator),
-            (r'[(){};,/?:\\]', Punctuation),
-            (r'\s+', Whitespace)
-        ],
-        'funcname': [
-            (r'\(', Punctuation, 'defexpr'),
-            (r'(?:([a-zA-Z_]\w*)(\.))?'  # optional scope name, like "self."
-             r'('
-                r'[a-zA-Z\u0080-\uffff][a-zA-Z0-9_\u0080-\uffff]*[!?=]?'  # method name
-                r'|!=|!~|=~|\*\*?|[-+!~]@?|[/%&|^]|<=>|<[<=]?|>[>=]?|===?'  # or operator override
-                r'|\[\]=?'  # or element reference/assignment override
-                r'|`'  # or the undocumented backtick override
-             r')',
-             bygroups(Name.Class, Operator, Name.Function), '#pop'),
-            default('#pop')
-        ],
-        'classname': [
-            (r'\(', Punctuation, 'defexpr'),
-            (r'<<', Operator, '#pop'),
-            (r'[A-Z_]\w*', Name.Class, '#pop'),
-            default('#pop')
-        ],
-        'defexpr': [
-            (r'(\))(\.|::)?', bygroups(Punctuation, Operator), '#pop'),
-            (r'\(', Operator, '#push'),
-            include('root')
-        ],
-        'in-intp': [
-            (r'\{', String.Interpol, '#push'),
-            (r'\}', String.Interpol, '#pop'),
-            include('root'),
-        ],
-        'string-intp': [
-            (r'#\{', String.Interpol, 'in-intp'),
-            (r'#@@?[a-zA-Z_]\w*', String.Interpol),
-            (r'#\$[a-zA-Z_]\w*', String.Interpol)
-        ],
-        'string-intp-escaped': [
-            include('string-intp'),
-            (r'\\([\\abefnrstv#"\']|x[a-fA-F0-9]{1,2}|[0-7]{1,3})',
-             String.Escape)
-        ],
-        'interpolated-regex': [
-            include('string-intp'),
-            (r'[\\#]', String.Regex),
-            (r'[^\\#]+', String.Regex),
-        ],
-        'interpolated-string': [
-            include('string-intp'),
-            (r'[\\#]', String.Other),
-            (r'[^\\#]+', String.Other),
-        ],
-        'multiline-regex': [
-            include('string-intp'),
-            (r'\\\\', String.Regex),
-            (r'\\/', String.Regex),
-            (r'[\\#]', String.Regex),
-            (r'[^\\/#]+', String.Regex),
-            (r'/[mixounse]*', String.Regex, '#pop'),
-        ],
-        'end-part': [
-            (r'.+', Comment.Preproc, '#pop')
-        ]
-    }
-    tokens.update(gen_rubystrings_rules())
-
-    def analyse_text(text):
-        return shebang_matches(text, r'ruby(1\.\d)?')
-
-
-class RubyConsoleLexer(Lexer):
-    """
-    For Ruby interactive console (**irb**) output.
-    """
-    name = 'Ruby irb session'
-    aliases = ['rbcon', 'irb']
-    mimetypes = ['text/x-ruby-shellsession']
-    url = 'https://www.ruby-lang.org'
-    version_added = ''
-    _example = 'rbcon/console'
-
-    _prompt_re = re.compile(r'irb\([a-zA-Z_]\w*\):\d{3}:\d+[>*"\'] '
-                            r'|>> |\?> ')
-
-    def get_tokens_unprocessed(self, text):
-        rblexer = RubyLexer(**self.options)
-
-        curcode = ''
-        insertions = []
-        for match in line_re.finditer(text):
-            line = match.group()
-            m = self._prompt_re.match(line)
-            if m is not None:
-                end = m.end()
-                insertions.append((len(curcode),
-                                   [(0, Generic.Prompt, line[:end])]))
-                curcode += line[end:]
-            else:
-                if curcode:
-                    yield from do_insertions(
-                        insertions, rblexer.get_tokens_unprocessed(curcode))
-                    curcode = ''
-                    insertions = []
-                yield match.start(), Generic.Output, line
-        if curcode:
-            yield from do_insertions(
-                insertions, rblexer.get_tokens_unprocessed(curcode))
-
-
-class FancyLexer(RegexLexer):
-    """
-    Pygments Lexer For Fancy.
-
-    Fancy is a self-hosted, pure object-oriented, dynamic,
-    class-based, concurrent general-purpose programming language
-    running on Rubinius, the Ruby VM.
-    """
-    name = 'Fancy'
-    url = 'https://github.com/bakkdoor/fancy'
-    filenames = ['*.fy', '*.fancypack']
-    aliases = ['fancy', 'fy']
-    mimetypes = ['text/x-fancysrc']
-    version_added = '1.5'
-
-    tokens = {
-        # copied from PerlLexer:
-        'balanced-regex': [
-            (r'/(\\\\|\\[^\\]|[^/\\])*/[egimosx]*', String.Regex, '#pop'),
-            (r'!(\\\\|\\[^\\]|[^!\\])*![egimosx]*', String.Regex, '#pop'),
-            (r'\\(\\\\|[^\\])*\\[egimosx]*', String.Regex, '#pop'),
-            (r'\{(\\\\|\\[^\\]|[^}\\])*\}[egimosx]*', String.Regex, '#pop'),
-            (r'<(\\\\|\\[^\\]|[^>\\])*>[egimosx]*', String.Regex, '#pop'),
-            (r'\[(\\\\|\\[^\\]|[^\]\\])*\][egimosx]*', String.Regex, '#pop'),
-            (r'\((\\\\|\\[^\\]|[^)\\])*\)[egimosx]*', String.Regex, '#pop'),
-            (r'@(\\\\|\\[^\\]|[^@\\])*@[egimosx]*', String.Regex, '#pop'),
-            (r'%(\\\\|\\[^\\]|[^%\\])*%[egimosx]*', String.Regex, '#pop'),
-            (r'\$(\\\\|\\[^\\]|[^$\\])*\$[egimosx]*', String.Regex, '#pop'),
-        ],
-        'root': [
-            (r'\s+', Whitespace),
-
-            # balanced delimiters (copied from PerlLexer):
-            (r's\{(\\\\|\\[^\\]|[^}\\])*\}\s*', String.Regex, 'balanced-regex'),
-            (r's<(\\\\|\\[^\\]|[^>\\])*>\s*', String.Regex, 'balanced-regex'),
-            (r's\[(\\\\|\\[^\\]|[^\]\\])*\]\s*', String.Regex, 'balanced-regex'),
-            (r's\((\\\\|\\[^\\]|[^)\\])*\)\s*', String.Regex, 'balanced-regex'),
-            (r'm?/(\\\\|\\[^\\]|[^///\n])*/[gcimosx]*', String.Regex),
-            (r'm(?=[/!\\{<\[(@%$])', String.Regex, 'balanced-regex'),
-
-            # Comments
-            (r'#(.*?)\n', Comment.Single),
-            # Symbols
-            (r'\'([^\'\s\[\](){}]+|\[\])', String.Symbol),
-            # Multi-line DoubleQuotedString
-            (r'"""(\\\\|\\[^\\]|[^\\])*?"""', String),
-            # DoubleQuotedString
-            (r'"(\\\\|\\[^\\]|[^"\\])*"', String),
-            # keywords
-            (r'(def|class|try|catch|finally|retry|return|return_local|match|'
-             r'case|->|=>)\b', Keyword),
-            # constants
-            (r'(self|super|nil|false|true)\b', Name.Constant),
-            (r'[(){};,/?|:\\]', Punctuation),
-            # names
-            (words((
-                'Object', 'Array', 'Hash', 'Directory', 'File', 'Class', 'String',
-                'Number', 'Enumerable', 'FancyEnumerable', 'Block', 'TrueClass',
-                'NilClass', 'FalseClass', 'Tuple', 'Symbol', 'Stack', 'Set',
-                'FancySpec', 'Method', 'Package', 'Range'), suffix=r'\b'),
-             Name.Builtin),
-            # functions
-            (r'[a-zA-Z](\w|[-+?!=*/^><%])*:', Name.Function),
-            # operators, must be below functions
-            (r'[-+*/~,<>=&!?%^\[\].$]+', Operator),
-            (r'[A-Z]\w*', Name.Constant),
-            (r'@[a-zA-Z_]\w*', Name.Variable.Instance),
-            (r'@@[a-zA-Z_]\w*', Name.Variable.Class),
-            ('@@?', Operator),
-            (r'[a-zA-Z_]\w*', Name),
-            # numbers - / checks are necessary to avoid mismarking regexes,
-            # see comment in RubyLexer
-            (r'(0[oO]?[0-7]+(?:_[0-7]+)*)(\s*)([/?])?',
-             bygroups(Number.Oct, Whitespace, Operator)),
-            (r'(0[xX][0-9A-Fa-f]+(?:_[0-9A-Fa-f]+)*)(\s*)([/?])?',
-             bygroups(Number.Hex, Whitespace, Operator)),
-            (r'(0[bB][01]+(?:_[01]+)*)(\s*)([/?])?',
-             bygroups(Number.Bin, Whitespace, Operator)),
-            (r'([\d]+(?:_\d+)*)(\s*)([/?])?',
-             bygroups(Number.Integer, Whitespace, Operator)),
-            (r'\d+([eE][+-]?[0-9]+)|\d+\.\d+([eE][+-]?[0-9]+)?', Number.Float),
-            (r'\d+', Number.Integer)
-        ]
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/rust.py b/.venv/lib/python3.12/site-packages/pygments/lexers/rust.py
deleted file mode 100644
index 6c9e621..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/rust.py
+++ /dev/null
@@ -1,222 +0,0 @@
-"""
-    pygments.lexers.rust
-    ~~~~~~~~~~~~~~~~~~~~
-
-    Lexers for the Rust language.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-from pygments.lexer import RegexLexer, include, bygroups, words, default
-from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
-    Number, Punctuation, Whitespace
-
-__all__ = ['RustLexer']
-
-
-class RustLexer(RegexLexer):
-    """
-    Lexer for the Rust programming language (version 1.47).
-    """
-    name = 'Rust'
-    url = 'https://www.rust-lang.org/'
-    filenames = ['*.rs', '*.rs.in']
-    aliases = ['rust', 'rs']
-    mimetypes = ['text/rust', 'text/x-rust']
-    version_added = '1.6'
-
-    keyword_types = (words((
-        'u8', 'u16', 'u32', 'u64', 'u128', 'i8', 'i16', 'i32', 'i64', 'i128',
-        'usize', 'isize', 'f32', 'f64', 'char', 'str', 'bool',
-    ), suffix=r'\b'), Keyword.Type)
-
-    builtin_funcs_types = (words((
-        'Copy', 'Send', 'Sized', 'Sync', 'Unpin',
-        'Drop', 'Fn', 'FnMut', 'FnOnce', 'drop',
-        'Box', 'ToOwned', 'Clone',
-        'PartialEq', 'PartialOrd', 'Eq', 'Ord',
-        'AsRef', 'AsMut', 'Into', 'From', 'Default',
-        'Iterator', 'Extend', 'IntoIterator', 'DoubleEndedIterator',
-        'ExactSizeIterator',
-        'Option', 'Some', 'None',
-        'Result', 'Ok', 'Err',
-        'String', 'ToString', 'Vec',
-    ), suffix=r'\b'), Name.Builtin)
-
-    builtin_macros = (words((
-        'asm', 'assert', 'assert_eq', 'assert_ne', 'cfg', 'column',
-        'compile_error', 'concat', 'concat_idents', 'dbg', 'debug_assert',
-        'debug_assert_eq', 'debug_assert_ne', 'env', 'eprint', 'eprintln',
-        'file', 'format', 'format_args', 'format_args_nl', 'global_asm',
-        'include', 'include_bytes', 'include_str',
-        'is_aarch64_feature_detected',
-        'is_arm_feature_detected',
-        'is_mips64_feature_detected',
-        'is_mips_feature_detected',
-        'is_powerpc64_feature_detected',
-        'is_powerpc_feature_detected',
-        'is_x86_feature_detected',
-        'line', 'llvm_asm', 'log_syntax', 'macro_rules', 'matches',
-        'module_path', 'option_env', 'panic', 'print', 'println', 'stringify',
-        'thread_local', 'todo', 'trace_macros', 'unimplemented', 'unreachable',
-        'vec', 'write', 'writeln',
-    ), suffix=r'!'), Name.Function.Magic)
-
-    tokens = {
-        'root': [
-            # rust allows a file to start with a shebang, but if the first line
-            # starts with #![ then it's not a shebang but a crate attribute.
-            (r'#![^[\r\n].*$', Comment.Preproc),
-            default('base'),
-        ],
-        'base': [
-            # Whitespace and Comments
-            (r'\n', Whitespace),
-            (r'\s+', Whitespace),
-            (r'//!.*?\n', String.Doc),
-            (r'///(\n|[^/].*?\n)', String.Doc),
-            (r'//(.*?)\n', Comment.Single),
-            (r'/\*\*(\n|[^/*])', String.Doc, 'doccomment'),
-            (r'/\*!', String.Doc, 'doccomment'),
-            (r'/\*', Comment.Multiline, 'comment'),
-
-            # Macro parameters
-            (r"""\$([a-zA-Z_]\w*|\(,?|\),?|,?)""", Comment.Preproc),
-            # Keywords
-            (words(('as', 'async', 'await', 'box', 'const', 'crate', 'dyn',
-                    'else', 'extern', 'for', 'if', 'impl', 'in', 'loop',
-                    'match', 'move', 'mut', 'pub', 'ref', 'return', 'static',
-                    'super', 'trait', 'unsafe', 'use', 'where', 'while'),
-                   suffix=r'\b'), Keyword),
-            (words(('abstract', 'become', 'do', 'final', 'macro', 'override',
-                    'priv', 'typeof', 'try', 'unsized', 'virtual', 'yield'),
-                   suffix=r'\b'), Keyword.Reserved),
-            (r'(true|false)\b', Keyword.Constant),
-            (r'self\b', Name.Builtin.Pseudo),
-            (r'mod\b', Keyword, 'modname'),
-            (r'let\b', Keyword.Declaration),
-            (r'fn\b', Keyword, 'funcname'),
-            (r'(struct|enum|type|union)\b', Keyword, 'typename'),
-            (r'(default)(\s+)(type|fn)\b', bygroups(Keyword, Whitespace, Keyword)),
-            keyword_types,
-            (r'[sS]elf\b', Name.Builtin.Pseudo),
-            # Prelude (taken from Rust's src/libstd/prelude.rs)
-            builtin_funcs_types,
-            builtin_macros,
-            # Path separators, so types don't catch them.
-            (r'::\b', Punctuation),
-            # Types in positions.
-            (r'(?::|->)', Punctuation, 'typename'),
-            # Labels
-            (r'(break|continue)(\b\s*)(\'[A-Za-z_]\w*)?',
-             bygroups(Keyword, Text.Whitespace, Name.Label)),
-
-            # Character literals
-            (r"""'(\\['"\\nrt]|\\x[0-7][0-9a-fA-F]|\\0"""
-             r"""|\\u\{[0-9a-fA-F]{1,6}\}|.)'""",
-             String.Char),
-            (r"""b'(\\['"\\nrt]|\\x[0-9a-fA-F]{2}|\\0"""
-             r"""|\\u\{[0-9a-fA-F]{1,6}\}|.)'""",
-             String.Char),
-
-            # Binary literals
-            (r'0b[01_]+', Number.Bin, 'number_lit'),
-            # Octal literals
-            (r'0o[0-7_]+', Number.Oct, 'number_lit'),
-            # Hexadecimal literals
-            (r'0[xX][0-9a-fA-F_]+', Number.Hex, 'number_lit'),
-            # Decimal literals
-            (r'[0-9][0-9_]*(\.[0-9_]+[eE][+\-]?[0-9_]+|'
-             r'\.[0-9_]*(?!\.)|[eE][+\-]?[0-9_]+)', Number.Float,
-             'number_lit'),
-            (r'[0-9][0-9_]*', Number.Integer, 'number_lit'),
-
-            # String literals
-            (r'b"', String, 'bytestring'),
-            (r'"', String, 'string'),
-            (r'(?s)b?r(#*)".*?"\1', String),
-
-            # Lifetime names
-            (r"'", Operator, 'lifetime'),
-
-            # Operators and Punctuation
-            (r'\.\.=?', Operator),
-            (r'[{}()\[\],.;]', Punctuation),
-            (r'[+\-*/%&|<>^!~@=:?]', Operator),
-
-            # Identifiers
-            (r'[a-zA-Z_]\w*', Name),
-            # Raw identifiers
-            (r'r#[a-zA-Z_]\w*', Name),
-
-            # Attributes
-            (r'#!?\[', Comment.Preproc, 'attribute['),
-
-            # Misc
-            # Lone hashes: not used in Rust syntax, but allowed in macro
-            # arguments, most famously for quote::quote!()
-            (r'#', Punctuation),
-        ],
-        'comment': [
-            (r'[^*/]+', Comment.Multiline),
-            (r'/\*', Comment.Multiline, '#push'),
-            (r'\*/', Comment.Multiline, '#pop'),
-            (r'[*/]', Comment.Multiline),
-        ],
-        'doccomment': [
-            (r'[^*/]+', String.Doc),
-            (r'/\*', String.Doc, '#push'),
-            (r'\*/', String.Doc, '#pop'),
-            (r'[*/]', String.Doc),
-        ],
-        'modname': [
-            (r'\s+', Whitespace),
-            (r'[a-zA-Z_]\w*', Name.Namespace, '#pop'),
-            default('#pop'),
-        ],
-        'funcname': [
-            (r'\s+', Whitespace),
-            (r'[a-zA-Z_]\w*', Name.Function, '#pop'),
-            default('#pop'),
-        ],
-        'typename': [
-            (r'\s+', Whitespace),
-            (r'&', Keyword.Pseudo),
-            (r"'", Operator, 'lifetime'),
-            builtin_funcs_types,
-            keyword_types,
-            (r'[a-zA-Z_]\w*', Name.Class, '#pop'),
-            default('#pop'),
-        ],
-        'lifetime': [
-            (r"(static|_)", Name.Builtin),
-            (r"[a-zA-Z_]+\w*", Name.Attribute),
-            default('#pop'),
-        ],
-        'number_lit': [
-            (r'[ui](8|16|32|64|size)', Keyword, '#pop'),
-            (r'f(32|64)', Keyword, '#pop'),
-            default('#pop'),
-        ],
-        'string': [
-            (r'"', String, '#pop'),
-            (r"""\\['"\\nrt]|\\x[0-7][0-9a-fA-F]|\\0"""
-             r"""|\\u\{[0-9a-fA-F]{1,6}\}""", String.Escape),
-            (r'[^\\"]+', String),
-            (r'\\', String),
-        ],
-        'bytestring': [
-            (r"""\\x[89a-fA-F][0-9a-fA-F]""", String.Escape),
-            include('string'),
-        ],
-        'attribute_common': [
-            (r'"', String, 'string'),
-            (r'\[', Comment.Preproc, 'attribute['),
-        ],
-        'attribute[': [
-            include('attribute_common'),
-            (r'\]', Comment.Preproc, '#pop'),
-            (r'[^"\]\[]+', Comment.Preproc),
-        ],
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/sas.py b/.venv/lib/python3.12/site-packages/pygments/lexers/sas.py
deleted file mode 100644
index 35ee854..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/sas.py
+++ /dev/null
@@ -1,227 +0,0 @@
-"""
-    pygments.lexers.sas
-    ~~~~~~~~~~~~~~~~~~~
-
-    Lexer for SAS.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-import re
-from pygments.lexer import RegexLexer, include, words
-from pygments.token import Comment, Keyword, Name, Number, String, Text, \
-    Other, Generic
-
-__all__ = ['SASLexer']
-
-
-class SASLexer(RegexLexer):
-    """
-    For SAS files.
-    """
-    # Syntax from syntax/sas.vim by James Kidd 
-
-    name      = 'SAS'
-    aliases   = ['sas']
-    filenames = ['*.SAS', '*.sas']
-    mimetypes = ['text/x-sas', 'text/sas', 'application/x-sas']
-    url = 'https://en.wikipedia.org/wiki/SAS_(software)'
-    version_added = '2.2'
-    flags     = re.IGNORECASE | re.MULTILINE
-
-    builtins_macros = (
-        "bquote", "nrbquote", "cmpres", "qcmpres", "compstor", "datatyp",
-        "display", "do", "else", "end", "eval", "global", "goto", "if",
-        "index", "input", "keydef", "label", "left", "length", "let",
-        "local", "lowcase", "macro", "mend", "nrquote",
-        "nrstr", "put", "qleft", "qlowcase", "qscan",
-        "qsubstr", "qsysfunc", "qtrim", "quote", "qupcase", "scan",
-        "str", "substr", "superq", "syscall", "sysevalf", "sysexec",
-        "sysfunc", "sysget", "syslput", "sysprod", "sysrc", "sysrput",
-        "then", "to", "trim", "unquote", "until", "upcase", "verify",
-        "while", "window"
-    )
-
-    builtins_conditionals = (
-        "do", "if", "then", "else", "end", "until", "while"
-    )
-
-    builtins_statements = (
-        "abort", "array", "attrib", "by", "call", "cards", "cards4",
-        "catname", "continue", "datalines", "datalines4", "delete", "delim",
-        "delimiter", "display", "dm", "drop", "endsas", "error", "file",
-        "filename", "footnote", "format", "goto", "in", "infile", "informat",
-        "input", "keep", "label", "leave", "length", "libname", "link",
-        "list", "lostcard", "merge", "missing", "modify", "options", "output",
-        "out", "page", "put", "redirect", "remove", "rename", "replace",
-        "retain", "return", "select", "set", "skip", "startsas", "stop",
-        "title", "update", "waitsas", "where", "window", "x", "systask"
-    )
-
-    builtins_sql = (
-        "add", "and", "alter", "as", "cascade", "check", "create",
-        "delete", "describe", "distinct", "drop", "foreign", "from",
-        "group", "having", "index", "insert", "into", "in", "key", "like",
-        "message", "modify", "msgtype", "not", "null", "on", "or",
-        "order", "primary", "references", "reset", "restrict", "select",
-        "set", "table", "unique", "update", "validate", "view", "where"
-    )
-
-    builtins_functions = (
-        "abs", "addr", "airy", "arcos", "arsin", "atan", "attrc",
-        "attrn", "band", "betainv", "blshift", "bnot", "bor",
-        "brshift", "bxor", "byte", "cdf", "ceil", "cexist", "cinv",
-        "close", "cnonct", "collate", "compbl", "compound",
-        "compress", "cos", "cosh", "css", "curobs", "cv", "daccdb",
-        "daccdbsl", "daccsl", "daccsyd", "dacctab", "dairy", "date",
-        "datejul", "datepart", "datetime", "day", "dclose", "depdb",
-        "depdbsl", "depsl", "depsyd",
-        "deptab", "dequote", "dhms", "dif", "digamma",
-        "dim", "dinfo", "dnum", "dopen", "doptname", "doptnum",
-        "dread", "dropnote", "dsname", "erf", "erfc", "exist", "exp",
-        "fappend", "fclose", "fcol", "fdelete", "fetch", "fetchobs",
-        "fexist", "fget", "fileexist", "filename", "fileref",
-        "finfo", "finv", "fipname", "fipnamel", "fipstate", "floor",
-        "fnonct", "fnote", "fopen", "foptname", "foptnum", "fpoint",
-        "fpos", "fput", "fread", "frewind", "frlen", "fsep", "fuzz",
-        "fwrite", "gaminv", "gamma", "getoption", "getvarc", "getvarn",
-        "hbound", "hms", "hosthelp", "hour", "ibessel", "index",
-        "indexc", "indexw", "input", "inputc", "inputn", "int",
-        "intck", "intnx", "intrr", "irr", "jbessel", "juldate",
-        "kurtosis", "lag", "lbound", "left", "length", "lgamma",
-        "libname", "libref", "log", "log10", "log2", "logpdf", "logpmf",
-        "logsdf", "lowcase", "max", "mdy", "mean", "min", "minute",
-        "mod", "month", "mopen", "mort", "n", "netpv", "nmiss",
-        "normal", "note", "npv", "open", "ordinal", "pathname",
-        "pdf", "peek", "peekc", "pmf", "point", "poisson", "poke",
-        "probbeta", "probbnml", "probchi", "probf", "probgam",
-        "probhypr", "probit", "probnegb", "probnorm", "probt",
-        "put", "putc", "putn", "qtr", "quote", "ranbin", "rancau",
-        "ranexp", "rangam", "range", "rank", "rannor", "ranpoi",
-        "rantbl", "rantri", "ranuni", "repeat", "resolve", "reverse",
-        "rewind", "right", "round", "saving", "scan", "sdf", "second",
-        "sign", "sin", "sinh", "skewness", "soundex", "spedis",
-        "sqrt", "std", "stderr", "stfips", "stname", "stnamel",
-        "substr", "sum", "symget", "sysget", "sysmsg", "sysprod",
-        "sysrc", "system", "tan", "tanh", "time", "timepart", "tinv",
-        "tnonct", "today", "translate", "tranwrd", "trigamma",
-        "trim", "trimn", "trunc", "uniform", "upcase", "uss", "var",
-        "varfmt", "varinfmt", "varlabel", "varlen", "varname",
-        "varnum", "varray", "varrayx", "vartype", "verify", "vformat",
-        "vformatd", "vformatdx", "vformatn", "vformatnx", "vformatw",
-        "vformatwx", "vformatx", "vinarray", "vinarrayx", "vinformat",
-        "vinformatd", "vinformatdx", "vinformatn", "vinformatnx",
-        "vinformatw", "vinformatwx", "vinformatx", "vlabel",
-        "vlabelx", "vlength", "vlengthx", "vname", "vnamex", "vtype",
-        "vtypex", "weekday", "year", "yyq", "zipfips", "zipname",
-        "zipnamel", "zipstate"
-    )
-
-    tokens = {
-        'root': [
-            include('comments'),
-            include('proc-data'),
-            include('cards-datalines'),
-            include('logs'),
-            include('general'),
-            (r'.', Text),
-        ],
-        # SAS is multi-line regardless, but * is ended by ;
-        'comments': [
-            (r'^\s*\*.*?;', Comment),
-            (r'/\*.*?\*/', Comment),
-            (r'^\s*\*(.|\n)*?;', Comment.Multiline),
-            (r'/[*](.|\n)*?[*]/', Comment.Multiline),
-        ],
-        # Special highlight for proc, data, quit, run
-        'proc-data': [
-            (r'(^|;)\s*(proc \w+|data|run|quit)[\s;]',
-             Keyword.Reserved),
-        ],
-        # Special highlight cards and datalines
-        'cards-datalines': [
-            (r'^\s*(datalines|cards)\s*;\s*$', Keyword, 'data'),
-        ],
-        'data': [
-            (r'(.|\n)*^\s*;\s*$', Other, '#pop'),
-        ],
-        # Special highlight for put NOTE|ERROR|WARNING (order matters)
-        'logs': [
-            (r'\n?^\s*%?put ', Keyword, 'log-messages'),
-        ],
-        'log-messages': [
-            (r'NOTE(:|-).*', Generic, '#pop'),
-            (r'WARNING(:|-).*', Generic.Emph, '#pop'),
-            (r'ERROR(:|-).*', Generic.Error, '#pop'),
-            include('general'),
-        ],
-        'general': [
-            include('keywords'),
-            include('vars-strings'),
-            include('special'),
-            include('numbers'),
-        ],
-        # Keywords, statements, functions, macros
-        'keywords': [
-            (words(builtins_statements,
-                   prefix = r'\b',
-                   suffix = r'\b'),
-             Keyword),
-            (words(builtins_sql,
-                   prefix = r'\b',
-                   suffix = r'\b'),
-             Keyword),
-            (words(builtins_conditionals,
-                   prefix = r'\b',
-                   suffix = r'\b'),
-             Keyword),
-            (words(builtins_macros,
-                   prefix = r'%',
-                   suffix = r'\b'),
-             Name.Builtin),
-            (words(builtins_functions,
-                   prefix = r'\b',
-                   suffix = r'\('),
-             Name.Builtin),
-        ],
-        # Strings and user-defined variables and macros (order matters)
-        'vars-strings': [
-            (r'&[a-z_]\w{0,31}\.?', Name.Variable),
-            (r'%[a-z_]\w{0,31}', Name.Function),
-            (r'\'', String, 'string_squote'),
-            (r'"', String, 'string_dquote'),
-        ],
-        'string_squote': [
-            ('\'', String, '#pop'),
-            (r'\\\\|\\"|\\\n', String.Escape),
-            # AFAIK, macro variables are not evaluated in single quotes
-            # (r'&', Name.Variable, 'validvar'),
-            (r'[^$\'\\]+', String),
-            (r'[$\'\\]', String),
-        ],
-        'string_dquote': [
-            (r'"', String, '#pop'),
-            (r'\\\\|\\"|\\\n', String.Escape),
-            (r'&', Name.Variable, 'validvar'),
-            (r'[^$&"\\]+', String),
-            (r'[$"\\]', String),
-        ],
-        'validvar': [
-            (r'[a-z_]\w{0,31}\.?', Name.Variable, '#pop'),
-        ],
-        # SAS numbers and special variables
-        'numbers': [
-            (r'\b[+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+|\.)(E[+-]?[0-9]+)?i?\b',
-             Number),
-        ],
-        'special': [
-            (r'(null|missing|_all_|_automatic_|_character_|_n_|'
-             r'_infile_|_name_|_null_|_numeric_|_user_|_webout_)',
-             Keyword.Constant),
-        ],
-        # 'operators': [
-        #     (r'(-|=|<=|>=|<|>|<>|&|!=|'
-        #      r'\||\*|\+|\^|/|!|~|~=)', Operator)
-        # ],
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/savi.py b/.venv/lib/python3.12/site-packages/pygments/lexers/savi.py
deleted file mode 100644
index 548a056..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/savi.py
+++ /dev/null
@@ -1,171 +0,0 @@
-"""
-    pygments.lexers.savi
-    ~~~~~~~~~~~~~~~~~~~~
-
-    Lexer for Savi.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-from pygments.lexer import RegexLexer, bygroups, include
-from pygments.token import Whitespace, Keyword, Name, String, Number, \
-  Operator, Punctuation, Comment, Generic, Error
-
-__all__ = ['SaviLexer']
-
-
-# The canonical version of this file can be found in the following repository,
-# where it is kept in sync with any language changes, as well as the other
-# pygments-like lexers that are maintained for use with other tools:
-# - https://github.com/savi-lang/savi/blob/main/tooling/pygments/lexers/savi.py
-#
-# If you're changing this file in the pygments repository, please ensure that
-# any changes you make are also propagated to the official Savi repository,
-# in order to avoid accidental clobbering of your changes later when an update
-# from the Savi repository flows forward into the pygments repository.
-#
-# If you're changing this file in the Savi repository, please ensure that
-# any changes you make are also reflected in the other pygments-like lexers
-# (rouge, vscode, etc) so that all of the lexers can be kept cleanly in sync.
-
-class SaviLexer(RegexLexer):
-    """
-    For Savi source code.
-
-    .. versionadded: 2.10
-    """
-
-    name = 'Savi'
-    url = 'https://github.com/savi-lang/savi'
-    aliases = ['savi']
-    filenames = ['*.savi']
-    version_added = ''
-
-    tokens = {
-      "root": [
-        # Line Comment
-        (r'//.*?$', Comment.Single),
-
-        # Doc Comment
-        (r'::.*?$', Comment.Single),
-
-        # Capability Operator
-        (r'(\')(\w+)(?=[^\'])', bygroups(Operator, Name)),
-
-        # Double-Quote String
-        (r'\w?"', String.Double, "string.double"),
-
-        # Single-Char String
-        (r"'", String.Char, "string.char"),
-
-        # Type Name
-        (r'(_?[A-Z]\w*)', Name.Class),
-
-        # Nested Type Name
-        (r'(\.)(\s*)(_?[A-Z]\w*)', bygroups(Punctuation, Whitespace, Name.Class)),
-
-        # Declare
-        (r'^([ \t]*)(:\w+)',
-          bygroups(Whitespace, Name.Tag),
-          "decl"),
-
-        # Error-Raising Calls/Names
-        (r'((\w+|\+|\-|\*)\!)', Generic.Deleted),
-
-        # Numeric Values
-        (r'\b\d([\d_]*(\.[\d_]+)?)\b', Number),
-
-        # Hex Numeric Values
-        (r'\b0x([0-9a-fA-F_]+)\b', Number.Hex),
-
-        # Binary Numeric Values
-        (r'\b0b([01_]+)\b', Number.Bin),
-
-        # Function Call (with braces)
-        (r'\w+(?=\()', Name.Function),
-
-        # Function Call (with receiver)
-        (r'(\.)(\s*)(\w+)', bygroups(Punctuation, Whitespace, Name.Function)),
-
-        # Function Call (with self receiver)
-        (r'(@)(\w+)', bygroups(Punctuation, Name.Function)),
-
-        # Parenthesis
-        (r'\(', Punctuation, "root"),
-        (r'\)', Punctuation, "#pop"),
-
-        # Brace
-        (r'\{', Punctuation, "root"),
-        (r'\}', Punctuation, "#pop"),
-
-        # Bracket
-        (r'\[', Punctuation, "root"),
-        (r'(\])(\!)', bygroups(Punctuation, Generic.Deleted), "#pop"),
-        (r'\]', Punctuation, "#pop"),
-
-        # Punctuation
-        (r'[,;:\.@]', Punctuation),
-
-        # Piping Operators
-        (r'(\|\>)', Operator),
-
-        # Branching Operators
-        (r'(\&\&|\|\||\?\?|\&\?|\|\?|\.\?)', Operator),
-
-        # Comparison Operators
-        (r'(\<\=\>|\=\~|\=\=|\<\=|\>\=|\<|\>)', Operator),
-
-        # Arithmetic Operators
-        (r'(\+|\-|\/|\*|\%)', Operator),
-
-        # Assignment Operators
-        (r'(\=)', Operator),
-
-        # Other Operators
-        (r'(\!|\<\<|\<|\&|\|)', Operator),
-
-        # Identifiers
-        (r'\b\w+\b', Name),
-
-        # Whitespace
-        (r'[ \t\r]+\n*|\n+', Whitespace),
-      ],
-
-      # Declare (nested rules)
-      "decl": [
-        (r'\b[a-z_]\w*\b(?!\!)', Keyword.Declaration),
-        (r':', Punctuation, "#pop"),
-        (r'\n', Whitespace, "#pop"),
-        include("root"),
-      ],
-
-      # Double-Quote String (nested rules)
-      "string.double": [
-        (r'\\\(', String.Interpol, "string.interpolation"),
-        (r'\\u[0-9a-fA-F]{4}', String.Escape),
-        (r'\\x[0-9a-fA-F]{2}', String.Escape),
-        (r'\\[bfnrt\\\']', String.Escape),
-        (r'\\"', String.Escape),
-        (r'"', String.Double, "#pop"),
-        (r'[^\\"]+', String.Double),
-        (r'.', Error),
-      ],
-
-      # Single-Char String (nested rules)
-      "string.char": [
-        (r'\\u[0-9a-fA-F]{4}', String.Escape),
-        (r'\\x[0-9a-fA-F]{2}', String.Escape),
-        (r'\\[bfnrt\\\']', String.Escape),
-        (r"\\'", String.Escape),
-        (r"'", String.Char, "#pop"),
-        (r"[^\\']+", String.Char),
-        (r'.', Error),
-      ],
-
-      # Interpolation inside String (nested rules)
-      "string.interpolation": [
-        (r"\)", String.Interpol, "#pop"),
-        include("root"),
-      ]
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/scdoc.py b/.venv/lib/python3.12/site-packages/pygments/lexers/scdoc.py
deleted file mode 100644
index 9b2e01d..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/scdoc.py
+++ /dev/null
@@ -1,85 +0,0 @@
-"""
-    pygments.lexers.scdoc
-    ~~~~~~~~~~~~~~~~~~~~~
-
-    Lexer for scdoc, a simple man page generator.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-import re
-
-from pygments.lexer import RegexLexer, include, bygroups, using, this
-from pygments.token import Text, Comment, Keyword, String, Generic
-
-__all__ = ['ScdocLexer']
-
-
-class ScdocLexer(RegexLexer):
-    """
-    `scdoc` is a simple man page generator for POSIX systems written in C99.
-    """
-    name = 'scdoc'
-    url = 'https://git.sr.ht/~sircmpwn/scdoc'
-    aliases = ['scdoc', 'scd']
-    filenames = ['*.scd', '*.scdoc']
-    version_added = '2.5'
-    flags = re.MULTILINE
-
-    tokens = {
-        'root': [
-            # comment
-            (r'^(;.+\n)', bygroups(Comment)),
-
-            # heading with pound prefix
-            (r'^(#)([^#].+\n)', bygroups(Generic.Heading, Text)),
-            (r'^(#{2})(.+\n)', bygroups(Generic.Subheading, Text)),
-            # bulleted lists
-            (r'^(\s*)([*-])(\s)(.+\n)',
-            bygroups(Text, Keyword, Text, using(this, state='inline'))),
-            # numbered lists
-            (r'^(\s*)(\.+\.)( .+\n)',
-            bygroups(Text, Keyword, using(this, state='inline'))),
-            # quote
-            (r'^(\s*>\s)(.+\n)', bygroups(Keyword, Generic.Emph)),
-            # text block
-            (r'^(```\n)([\w\W]*?)(^```$)', bygroups(String, Text, String)),
-
-            include('inline'),
-        ],
-        'inline': [
-            # escape
-            (r'\\.', Text),
-            # underlines
-            (r'(\s)(_[^_]+_)(\W|\n)', bygroups(Text, Generic.Emph, Text)),
-            # bold
-            (r'(\s)(\*[^*]+\*)(\W|\n)', bygroups(Text, Generic.Strong, Text)),
-            # inline code
-            (r'`[^`]+`', String.Backtick),
-
-            # general text, must come last!
-            (r'[^\\\s]+', Text),
-            (r'.', Text),
-        ],
-    }
-
-    def analyse_text(text):
-        """We checks for bold and underline text with * and _. Also
-        every scdoc file must start with a strictly defined first line."""
-        result = 0
-
-        if '*' in text:
-            result += 0.01
-
-        if '_' in text:
-            result += 0.01
-
-        # name(section) ["left_footer" ["center_header"]]
-        first_line = text.partition('\n')[0]
-        scdoc_preamble_pattern = r'^.*\([1-7]\)( "[^"]+"){0,2}$'
-
-        if re.search(scdoc_preamble_pattern, first_line):
-            result += 0.5
-
-        return result
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/scripting.py b/.venv/lib/python3.12/site-packages/pygments/lexers/scripting.py
deleted file mode 100644
index 2adb7bb..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/scripting.py
+++ /dev/null
@@ -1,1638 +0,0 @@
-"""
-    pygments.lexers.scripting
-    ~~~~~~~~~~~~~~~~~~~~~~~~~
-
-    Lexer for scripting and embedded languages.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-import re
-
-from pygments.lexer import RegexLexer, include, bygroups, default, combined, \
-    words
-from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
-    Number, Punctuation, Error, Whitespace, Other
-from pygments.util import get_bool_opt, get_list_opt
-
-__all__ = ['LuaLexer', 'LuauLexer', 'MoonScriptLexer', 'ChaiscriptLexer', 'LSLLexer',
-           'AppleScriptLexer', 'RexxLexer', 'MOOCodeLexer', 'HybrisLexer',
-           'EasytrieveLexer', 'JclLexer', 'MiniScriptLexer']
-
-
-def all_lua_builtins():
-    from pygments.lexers._lua_builtins import MODULES
-    return [w for values in MODULES.values() for w in values]
-
-class LuaLexer(RegexLexer):
-    """
-    For Lua source code.
-
-    Additional options accepted:
-
-    `func_name_highlighting`
-        If given and ``True``, highlight builtin function names
-        (default: ``True``).
-    `disabled_modules`
-        If given, must be a list of module names whose function names
-        should not be highlighted. By default all modules are highlighted.
-
-        To get a list of allowed modules have a look into the
-        `_lua_builtins` module:
-
-        .. sourcecode:: pycon
-
-            >>> from pygments.lexers._lua_builtins import MODULES
-            >>> MODULES.keys()
-            ['string', 'coroutine', 'modules', 'io', 'basic', ...]
-    """
-
-    name = 'Lua'
-    url = 'https://www.lua.org/'
-    aliases = ['lua']
-    filenames = ['*.lua', '*.wlua']
-    mimetypes = ['text/x-lua', 'application/x-lua']
-    version_added = ''
-
-    _comment_multiline = r'(?:--\[(?P=*)\[[\w\W]*?\](?P=level)\])'
-    _comment_single = r'(?:--.*$)'
-    _space = r'(?:\s+(?!\s))'
-    _s = rf'(?:{_comment_multiline}|{_comment_single}|{_space})'
-    # A lookahead-safe version of _s that avoids catastrophic backtracking.
-    # The _comment_multiline pattern contains [\w\W]*? which, when used
-    # inside a lookahead with a * quantifier, causes exponential blowup.
-    # This version skips only whitespace; comments between an identifier
-    # and a following [.:] or ( are rare enough to sacrifice.
-    _s_la = r'\s'
-    _name = r'(?:[^\W\d]\w*)'
-
-    tokens = {
-        'root': [
-            # Lua allows a file to start with a shebang.
-            (r'#!.*', Comment.Preproc),
-            default('base'),
-        ],
-        'ws': [
-            (_comment_multiline, Comment.Multiline),
-            (_comment_single, Comment.Single),
-            (_space, Whitespace),
-        ],
-        'base': [
-            include('ws'),
-
-            (r'(?i)0x[\da-f]*(\.[\da-f]*)?(p[+-]?\d+)?', Number.Hex),
-            (r'(?i)(\d*\.\d+|\d+\.\d*)(e[+-]?\d+)?', Number.Float),
-            (r'(?i)\d+e[+-]?\d+', Number.Float),
-            (r'\d+', Number.Integer),
-
-            # multiline strings
-            (r'(?s)\[(=*)\[.*?\]\1\]', String),
-
-            (r'::', Punctuation, 'label'),
-            (r'\.{3}', Punctuation),
-            (r'[=<>|~&+\-*/%#^]+|\.\.', Operator),
-            (r'[\[\]{}().,:;]+', Punctuation),
-            (r'(and|or|not)\b', Operator.Word),
-
-            (words([
-                'break', 'do', 'else', 'elseif', 'end', 'for', 'if', 'in',
-                'repeat', 'return', 'then', 'until', 'while'
-            ], suffix=r'\b'), Keyword.Reserved),
-            (r'goto\b', Keyword.Reserved, 'goto'),
-            (r'(local)\b', Keyword.Declaration),
-            (r'(true|false|nil)\b', Keyword.Constant),
-
-            (r'(function)\b', Keyword.Reserved, 'funcname'),
-
-            (words(all_lua_builtins(), suffix=r"\b"), Name.Builtin),
-            (fr'[A-Za-z_]\w*(?={_s_la}*[.:])', Name.Variable, 'varname'),
-            (fr'[A-Za-z_]\w*(?={_s_la}*\()', Name.Function),
-            (r'[A-Za-z_]\w*', Name.Variable),
-
-            ("'", String.Single, combined('stringescape', 'sqs')),
-            ('"', String.Double, combined('stringescape', 'dqs'))
-        ],
-
-        'varname': [
-            include('ws'),
-            (r'\.\.', Operator, '#pop'),
-            (r'[.:]', Punctuation),
-            (rf'{_name}(?={_s_la}*[.:])', Name.Property),
-            (rf'{_name}(?={_s_la}*\()', Name.Function, '#pop'),
-            (_name, Name.Property, '#pop'),
-        ],
-
-        'funcname': [
-            include('ws'),
-            (r'[.:]', Punctuation),
-            (rf'{_name}(?={_s_la}*[.:])', Name.Class),
-            (_name, Name.Function, '#pop'),
-            # inline function
-            (r'\(', Punctuation, '#pop'),
-        ],
-
-        'goto': [
-            include('ws'),
-            (_name, Name.Label, '#pop'),
-        ],
-
-        'label': [
-            include('ws'),
-            (r'::', Punctuation, '#pop'),
-            (_name, Name.Label),
-        ],
-
-        'stringescape': [
-            (r'\\([abfnrtv\\"\']|[\r\n]{1,2}|z\s*|x[0-9a-fA-F]{2}|\d{1,3}|'
-             r'u\{[0-9a-fA-F]+\})', String.Escape),
-        ],
-
-        'sqs': [
-            (r"'", String.Single, '#pop'),
-            (r"[^\\']+", String.Single),
-        ],
-
-        'dqs': [
-            (r'"', String.Double, '#pop'),
-            (r'[^\\"]+', String.Double),
-        ]
-    }
-
-    def __init__(self, **options):
-        self.func_name_highlighting = get_bool_opt(
-            options, 'func_name_highlighting', True)
-        self.disabled_modules = get_list_opt(options, 'disabled_modules', [])
-
-        self._functions = set()
-        if self.func_name_highlighting:
-            from pygments.lexers._lua_builtins import MODULES
-            for mod, func in MODULES.items():
-                if mod not in self.disabled_modules:
-                    self._functions.update(func)
-        RegexLexer.__init__(self, **options)
-
-    def get_tokens_unprocessed(self, text):
-        for index, token, value in \
-                RegexLexer.get_tokens_unprocessed(self, text):
-            if token is Name.Builtin and value not in self._functions:
-                if '.' in value:
-                    a, b = value.split('.')
-                    yield index, Name, a
-                    yield index + len(a), Punctuation, '.'
-                    yield index + len(a) + 1, Name, b
-                else:
-                    yield index, Name, value
-                continue
-            yield index, token, value
-
-def _luau_make_expression(should_pop, _s, _s_la):
-    temp_list = [
-        (r'0[xX][\da-fA-F_]*', Number.Hex, '#pop'),
-        (r'0[bB][\d_]*', Number.Bin, '#pop'),
-        (r'\.?\d[\d_]*(?:\.[\d_]*)?(?:[eE][+-]?[\d_]+)?', Number.Float, '#pop'),
-
-        (words((
-            'true', 'false', 'nil'
-        ), suffix=r'\b'), Keyword.Constant, '#pop'),
-
-        (r'\[(=*)\[[.\n]*?\]\1\]', String, '#pop'),
-
-        (r'(\.)([a-zA-Z_]\w*)(?=%s*[({"\'])', bygroups(Punctuation, Name.Function), '#pop'),
-        (r'(\.)([a-zA-Z_]\w*)', bygroups(Punctuation, Name.Variable), '#pop'),
-
-        (rf'[a-zA-Z_]\w*(?:\.[a-zA-Z_]\w*)*(?={_s_la}*[({{"\'])', Name.Other, '#pop'),
-        (r'[a-zA-Z_]\w*(?:\.[a-zA-Z_]\w*)*', Name, '#pop'),
-    ]
-    if should_pop:
-        return temp_list
-    return [entry[:2] for entry in temp_list]
-
-def _luau_make_expression_special(should_pop):
-    temp_list = [
-        (r'\{', Punctuation, ('#pop', 'closing_brace_base', 'expression')),
-        (r'\(', Punctuation, ('#pop', 'closing_parenthesis_base', 'expression')),
-
-        (r'::?', Punctuation, ('#pop', 'type_end', 'type_start')),
-
-        (r"'", String.Single, ('#pop', 'string_single')),
-        (r'"', String.Double, ('#pop', 'string_double')),
-        (r'`', String.Backtick, ('#pop', 'string_interpolated')),
-    ]
-    if should_pop:
-        return temp_list
-    return [(entry[0], entry[1], entry[2][1:]) for entry in temp_list]
-
-class LuauLexer(RegexLexer):
-    """
-    For Luau source code.
-
-    Additional options accepted:
-
-    `include_luau_builtins`
-        If given and ``True``, automatically highlight Luau builtins
-        (default: ``True``).
-    `include_roblox_builtins`
-        If given and ``True``, automatically highlight Roblox-specific builtins
-        (default: ``False``).
-    `additional_builtins`
-        If given, must be a list of additional builtins to highlight.
-    `disabled_builtins`
-        If given, must be a list of builtins that will not be highlighted.
-    """
-
-    name = 'Luau'
-    url = 'https://luau-lang.org/'
-    aliases = ['luau']
-    filenames = ['*.luau']
-    version_added = '2.18'
-
-    _comment_multiline = r'(?:--\[(?P=*)\[[\w\W]*?\](?P=level)\])'
-    _comment_single = r'(?:--.*$)'
-    _s = r'(?:{}|{}|{})'.format(_comment_multiline, _comment_single, r'\s+')
-    # Lookahead-safe version — avoids catastrophic backtracking from
-    # [\w\W]*? inside _comment_multiline when combined with * quantifier.
-    _s_la = r'\s'
-
-    tokens = {
-        'root': [
-            (r'#!.*', Comment.Hashbang, 'base'),
-            default('base'),
-        ],
-
-        'ws': [
-            (_comment_multiline, Comment.Multiline),
-            (_comment_single, Comment.Single),
-            (r'\s+', Whitespace),
-        ],
-
-        'base': [
-            include('ws'),
-
-            *_luau_make_expression_special(False),
-            (r'\.\.\.', Punctuation),
-
-            (rf'type\b(?={_s}+[a-zA-Z_])', Keyword.Reserved, 'type_declaration'),
-            (rf'export\b(?={_s}+[a-zA-Z_])', Keyword.Reserved),
-
-            (r'(?:\.\.|//|[+\-*\/%^<>=])=?', Operator, 'expression'),
-            (r'~=', Operator, 'expression'),
-
-            (words((
-                'and', 'or', 'not'
-            ), suffix=r'\b'), Operator.Word, 'expression'),
-
-            (words((
-                'elseif', 'for', 'if', 'in', 'repeat', 'return', 'until',
-                'while'), suffix=r'\b'), Keyword.Reserved, 'expression'),
-            (r'local\b', Keyword.Declaration, 'expression'),
-
-            (r'function\b', Keyword.Reserved, ('expression', 'func_name')),
-
-            (r'[\])};]+', Punctuation),
-
-            include('expression_static'),
-            *_luau_make_expression(False, _s, _s_la),
-
-            (r'[\[.,]', Punctuation, 'expression'),
-        ],
-        'expression_static': [
-            (words((
-                'break', 'continue', 'do', 'else', 'elseif', 'end', 'for',
-                'if', 'in', 'repeat', 'return', 'then', 'until', 'while'),
-                suffix=r'\b'), Keyword.Reserved),
-        ],
-        'expression': [
-            include('ws'),
-
-            (r'if\b', Keyword.Reserved, ('ternary', 'expression')),
-
-            (r'local\b', Keyword.Declaration),
-            *_luau_make_expression_special(True),
-            (r'\.\.\.', Punctuation, '#pop'),
-
-            (r'function\b', Keyword.Reserved, 'func_name'),
-
-            include('expression_static'),
-            *_luau_make_expression(True, _s, _s_la),
-
-            default('#pop'),
-        ],
-        'ternary': [
-            include('ws'),
-
-            (r'else\b', Keyword.Reserved, '#pop'),
-            (words((
-                'then', 'elseif',
-            ), suffix=r'\b'), Operator.Reserved, 'expression'),
-
-            default('#pop'),
-        ],
-
-        'closing_brace_pop': [
-            (r'\}', Punctuation, '#pop'),
-        ],
-        'closing_parenthesis_pop': [
-            (r'\)', Punctuation, '#pop'),
-        ],
-        'closing_gt_pop': [
-            (r'>', Punctuation, '#pop'),
-        ],
-
-        'closing_parenthesis_base': [
-            include('closing_parenthesis_pop'),
-            include('base'),
-        ],
-        'closing_parenthesis_type': [
-            include('closing_parenthesis_pop'),
-            include('type'),
-        ],
-        'closing_brace_base': [
-            include('closing_brace_pop'),
-            include('base'),
-        ],
-        'closing_brace_type': [
-            include('closing_brace_pop'),
-            include('type'),
-        ],
-        'closing_gt_type': [
-            include('closing_gt_pop'),
-            include('type'),
-        ],
-
-        'string_escape': [
-            (r'\\z\s*', String.Escape),
-            (r'\\(?:[abfnrtvz\\"\'`\{\n])|[\r\n]{1,2}|x[\da-fA-F]{2}|\d{1,3}|'
-             r'u\{\}[\da-fA-F]*\}', String.Escape),
-        ],
-        'string_single': [
-            include('string_escape'),
-
-            (r"'", String.Single, "#pop"),
-            (r"[^\\']+", String.Single),
-        ],
-        'string_double': [
-            include('string_escape'),
-
-            (r'"', String.Double, "#pop"),
-            (r'[^\\"]+', String.Double),
-        ],
-        'string_interpolated': [
-            include('string_escape'),
-
-            (r'\{', Punctuation, ('closing_brace_base', 'expression')),
-
-            (r'`', String.Backtick, "#pop"),
-            (r'[^\\`\{]+', String.Backtick),
-        ],
-
-        'func_name': [
-            include('ws'),
-
-            (r'[.:]', Punctuation),
-            (rf'[a-zA-Z_]\w*(?={_s_la}*[.:])', Name.Class),
-            (r'[a-zA-Z_]\w*', Name.Function),
-
-            (r'<', Punctuation, 'closing_gt_type'),
-
-            (r'\(', Punctuation, '#pop'),
-        ],
-
-        'type': [
-            include('ws'),
-
-            (r'\(', Punctuation, 'closing_parenthesis_type'),
-            (r'\{', Punctuation, 'closing_brace_type'),
-            (r'<', Punctuation, 'closing_gt_type'),
-
-            (r"'", String.Single, 'string_single'),
-            (r'"', String.Double, 'string_double'),
-
-            (r'[|&\.,\[\]:=]+', Punctuation),
-            (r'->', Punctuation),
-
-            (r'typeof\(', Name.Builtin, ('closing_parenthesis_base',
-                                         'expression')),
-            (r'[a-zA-Z_]\w*', Name.Class),
-        ],
-        'type_start': [
-            include('ws'),
-
-            (r'\(', Punctuation, ('#pop', 'closing_parenthesis_type')),
-            (r'\{', Punctuation, ('#pop', 'closing_brace_type')),
-            (r'<', Punctuation, ('#pop', 'closing_gt_type')),
-
-            (r"'", String.Single, ('#pop', 'string_single')),
-            (r'"', String.Double, ('#pop', 'string_double')),
-
-            (r'typeof\(', Name.Builtin, ('#pop', 'closing_parenthesis_base',
-                                         'expression')),
-            (r'[a-zA-Z_]\w*', Name.Class, '#pop'),
-        ],
-        'type_end': [
-            include('ws'),
-
-            (r'[|&\.]', Punctuation, 'type_start'),
-            (r'->', Punctuation, 'type_start'),
-
-            (r'<', Punctuation, 'closing_gt_type'),
-
-            default('#pop'),
-        ],
-        'type_declaration': [
-            include('ws'),
-
-            (r'[a-zA-Z_]\w*', Name.Class),
-            (r'<', Punctuation, 'closing_gt_type'),
-
-            (r'=', Punctuation, ('#pop', 'type_end', 'type_start')),
-        ],
-    }
-
-    def __init__(self, **options):
-        self.include_luau_builtins = get_bool_opt(
-            options, 'include_luau_builtins', True)
-        self.include_roblox_builtins = get_bool_opt(
-            options, 'include_roblox_builtins', False)
-        self.additional_builtins = get_list_opt(options, 'additional_builtins', [])
-        self.disabled_builtins = get_list_opt(options, 'disabled_builtins', [])
-
-        self._builtins = set(self.additional_builtins)
-        if self.include_luau_builtins:
-            from pygments.lexers._luau_builtins import LUAU_BUILTINS
-            self._builtins.update(LUAU_BUILTINS)
-        if self.include_roblox_builtins:
-            from pygments.lexers._luau_builtins import ROBLOX_BUILTINS
-            self._builtins.update(ROBLOX_BUILTINS)
-        if self.additional_builtins:
-            self._builtins.update(self.additional_builtins)
-        self._builtins.difference_update(self.disabled_builtins)
-
-        RegexLexer.__init__(self, **options)
-
-    def get_tokens_unprocessed(self, text):
-        for index, token, value in \
-                RegexLexer.get_tokens_unprocessed(self, text):
-            if token is Name or token is Name.Other:
-                split_value = value.split('.')
-                complete_value = []
-                new_index = index
-                for position in range(len(split_value), 0, -1):
-                    potential_string = '.'.join(split_value[:position])
-                    if potential_string in self._builtins:
-                        yield index, Name.Builtin, potential_string
-                        new_index += len(potential_string)
-
-                        if complete_value:
-                            yield new_index, Punctuation, '.'
-                            new_index += 1
-                        break
-                    complete_value.insert(0, split_value[position - 1])
-
-                for position, substring in enumerate(complete_value):
-                    if position + 1 == len(complete_value):
-                        if token is Name:
-                            yield new_index, Name.Variable, substring
-                            continue
-                        yield new_index, Name.Function, substring
-                        continue
-                    yield new_index, Name.Variable, substring
-                    new_index += len(substring)
-                    yield new_index, Punctuation, '.'
-                    new_index += 1
-
-                continue
-            yield index, token, value
-
-class MoonScriptLexer(LuaLexer):
-    """
-    For MoonScript source code.
-    """
-
-    name = 'MoonScript'
-    url = 'http://moonscript.org'
-    aliases = ['moonscript', 'moon']
-    filenames = ['*.moon']
-    mimetypes = ['text/x-moonscript', 'application/x-moonscript']
-    version_added = '1.5'
-
-    tokens = {
-        'root': [
-            (r'#!(.*?)$', Comment.Preproc),
-            default('base'),
-        ],
-        'base': [
-            ('--.*$', Comment.Single),
-            (r'(?i)(\d*\.\d+|\d+\.\d*)(e[+-]?\d+)?', Number.Float),
-            (r'(?i)\d+e[+-]?\d+', Number.Float),
-            (r'(?i)0x[0-9a-f]*', Number.Hex),
-            (r'\d+', Number.Integer),
-            (r'\n', Whitespace),
-            (r'[^\S\n]+', Text),
-            (r'(?s)\[(=*)\[.*?\]\1\]', String),
-            (r'(->|=>)', Name.Function),
-            (r':[a-zA-Z_]\w*', Name.Variable),
-            (r'(==|!=|~=|<=|>=|\.\.\.|\.\.|[=+\-*/%^<>#!.\\:])', Operator),
-            (r'[;,]', Punctuation),
-            (r'[\[\]{}()]', Keyword.Type),
-            (r'[a-zA-Z_]\w*:', Name.Variable),
-            (words((
-                'class', 'extends', 'if', 'then', 'super', 'do', 'with',
-                'import', 'export', 'while', 'elseif', 'return', 'for', 'in',
-                'from', 'when', 'using', 'else', 'and', 'or', 'not', 'switch',
-                'break'), suffix=r'\b'),
-             Keyword),
-            (r'(true|false|nil)\b', Keyword.Constant),
-            (r'(and|or|not)\b', Operator.Word),
-            (r'(self)\b', Name.Builtin.Pseudo),
-            (r'@@?([a-zA-Z_]\w*)?', Name.Variable.Class),
-            (r'[A-Z]\w*', Name.Class),  # proper name
-            (words(all_lua_builtins(), suffix=r"\b"), Name.Builtin),
-            (r'[A-Za-z_]\w*', Name),
-            ("'", String.Single, combined('stringescape', 'sqs')),
-            ('"', String.Double, combined('stringescape', 'dqs'))
-        ],
-        'stringescape': [
-            (r'''\\([abfnrtv\\"']|\d{1,3})''', String.Escape)
-        ],
-        'strings': [
-            (r'[^#\\\'"]+', String),
-            # note that strings are multi-line.
-            # hashmarks, quotes and backslashes must be parsed one at a time
-        ],
-        'interpoling_string': [
-            (r'\}', String.Interpol, "#pop"),
-            include('base')
-        ],
-        'dqs': [
-            (r'"', String.Double, '#pop'),
-            (r'\\.|\'', String),  # double-quoted string don't need ' escapes
-            (r'#\{', String.Interpol, "interpoling_string"),
-            (r'#', String),
-            include('strings')
-        ],
-        'sqs': [
-            (r"'", String.Single, '#pop'),
-            (r'#|\\.|"', String),  # single quoted strings don't need " escapses
-            include('strings')
-        ]
-    }
-
-    def get_tokens_unprocessed(self, text):
-        # set . as Operator instead of Punctuation
-        for index, token, value in LuaLexer.get_tokens_unprocessed(self, text):
-            if token == Punctuation and value == ".":
-                token = Operator
-            yield index, token, value
-
-
-class ChaiscriptLexer(RegexLexer):
-    """
-    For ChaiScript source code.
-    """
-
-    name = 'ChaiScript'
-    url = 'http://chaiscript.com/'
-    aliases = ['chaiscript', 'chai']
-    filenames = ['*.chai']
-    mimetypes = ['text/x-chaiscript', 'application/x-chaiscript']
-    version_added = '2.0'
-
-    flags = re.DOTALL | re.MULTILINE
-
-    tokens = {
-        'commentsandwhitespace': [
-            (r'\s+', Text),
-            (r'//.*?\n', Comment.Single),
-            (r'/\*.*?\*/', Comment.Multiline),
-            (r'^\#.*?\n', Comment.Single)
-        ],
-        'slashstartsregex': [
-            include('commentsandwhitespace'),
-            (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/'
-             r'([gim]+\b|\B)', String.Regex, '#pop'),
-            (r'(?=/)', Text, ('#pop', 'badregex')),
-            default('#pop')
-        ],
-        'badregex': [
-            (r'\n', Text, '#pop')
-        ],
-        'root': [
-            include('commentsandwhitespace'),
-            (r'\n', Text),
-            (r'[^\S\n]+', Text),
-            (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|\.\.'
-             r'(<<|>>>?|==?|!=?|[-<>+*%&|^/])=?', Operator, 'slashstartsregex'),
-            (r'[{(\[;,]', Punctuation, 'slashstartsregex'),
-            (r'[})\].]', Punctuation),
-            (r'[=+\-*/]', Operator),
-            (r'(for|in|while|do|break|return|continue|if|else|'
-             r'throw|try|catch'
-             r')\b', Keyword, 'slashstartsregex'),
-            (r'(var)\b', Keyword.Declaration, 'slashstartsregex'),
-            (r'(attr|def|fun)\b', Keyword.Reserved),
-            (r'(true|false)\b', Keyword.Constant),
-            (r'(eval|throw)\b', Name.Builtin),
-            (r'`\S+`', Name.Builtin),
-            (r'[$a-zA-Z_]\w*', Name.Other),
-            (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
-            (r'0x[0-9a-fA-F]+', Number.Hex),
-            (r'[0-9]+', Number.Integer),
-            (r'"', String.Double, 'dqstring'),
-            (r"'(\\\\|\\[^\\]|[^'\\])*'", String.Single),
-        ],
-        'dqstring': [
-            (r'\$\{[^"}]+?\}', String.Interpol),
-            (r'\$', String.Double),
-            (r'\\\\', String.Double),
-            (r'\\"', String.Double),
-            (r'[^\\"$]+', String.Double),
-            (r'"', String.Double, '#pop'),
-        ],
-    }
-
-
-class LSLLexer(RegexLexer):
-    """
-    For Second Life's Linden Scripting Language source code.
-    """
-
-    name = 'LSL'
-    aliases = ['lsl']
-    filenames = ['*.lsl']
-    mimetypes = ['text/x-lsl']
-    url = 'https://wiki.secondlife.com/wiki/Linden_Scripting_Language'
-    version_added = '2.0'
-
-    flags = re.MULTILINE
-
-    lsl_keywords = r'\b(?:do|else|for|if|jump|return|while)\b'
-    lsl_types = r'\b(?:float|integer|key|list|quaternion|rotation|string|vector)\b'
-    lsl_states = r'\b(?:(?:state)\s+\w+|default)\b'
-    lsl_events = r'\b(?:state_(?:entry|exit)|touch(?:_(?:start|end))?|(?:land_)?collision(?:_(?:start|end))?|timer|listen|(?:no_)?sensor|control|(?:not_)?at_(?:rot_)?target|money|email|run_time_permissions|changed|attach|dataserver|moving_(?:start|end)|link_message|(?:on|object)_rez|remote_data|http_re(?:sponse|quest)|path_update|transaction_result)\b'
-    lsl_functions_builtin = r'\b(?:ll(?:ReturnObjectsBy(?:ID|Owner)|Json(?:2List|[GS]etValue|ValueType)|Sin|Cos|Tan|Atan2|Sqrt|Pow|Abs|Fabs|Frand|Floor|Ceil|Round|Vec(?:Mag|Norm|Dist)|Rot(?:Between|2(?:Euler|Fwd|Left|Up))|(?:Euler|Axes)2Rot|Whisper|(?:Region|Owner)?Say|Shout|Listen(?:Control|Remove)?|Sensor(?:Repeat|Remove)?|Detected(?:Name|Key|Owner|Type|Pos|Vel|Grab|Rot|Group|LinkNumber)|Die|Ground|Wind|(?:[GS]et)(?:AnimationOverride|MemoryLimit|PrimMediaParams|ParcelMusicURL|Object(?:Desc|Name)|PhysicsMaterial|Status|Scale|Color|Alpha|Texture|Pos|Rot|Force|Torque)|ResetAnimationOverride|(?:Scale|Offset|Rotate)Texture|(?:Rot)?Target(?:Remove)?|(?:Stop)?MoveToTarget|Apply(?:Rotational)?Impulse|Set(?:KeyframedMotion|ContentType|RegionPos|(?:Angular)?Velocity|Buoyancy|HoverHeight|ForceAndTorque|TimerEvent|ScriptState|Damage|TextureAnim|Sound(?:Queueing|Radius)|Vehicle(?:Type|(?:Float|Vector|Rotation)Param)|(?:Touch|Sit)?Text|Camera(?:Eye|At)Offset|PrimitiveParams|ClickAction|Link(?:Alpha|Color|PrimitiveParams(?:Fast)?|Texture(?:Anim)?|Camera|Media)|RemoteScriptAccessPin|PayPrice|LocalRot)|ScaleByFactor|Get(?:(?:Max|Min)ScaleFactor|ClosestNavPoint|StaticPath|SimStats|Env|PrimitiveParams|Link(?:PrimitiveParams|Number(?:OfSides)?|Key|Name|Media)|HTTPHeader|FreeURLs|Object(?:Details|PermMask|PrimCount)|Parcel(?:MaxPrims|Details|Prim(?:Count|Owners))|Attached|(?:SPMax|Free|Used)Memory|Region(?:Name|TimeDilation|FPS|Corner|AgentCount)|Root(?:Position|Rotation)|UnixTime|(?:Parcel|Region)Flags|(?:Wall|GMT)clock|SimulatorHostname|BoundingBox|GeometricCenter|Creator|NumberOf(?:Prims|NotecardLines|Sides)|Animation(?:List)?|(?:Camera|Local)(?:Pos|Rot)|Vel|Accel|Omega|Time(?:stamp|OfDay)|(?:Object|CenterOf)?Mass|MassMKS|Energy|Owner|(?:Owner)?Key|SunDirection|Texture(?:Offset|Scale|Rot)|Inventory(?:Number|Name|Key|Type|Creator|PermMask)|Permissions(?:Key)?|StartParameter|List(?:Length|EntryType)|Date|Agent(?:Size|Info|Language|List)|LandOwnerAt|NotecardLine|Script(?:Name|State))|(?:Get|Reset|GetAndReset)Time|PlaySound(?:Slave)?|LoopSound(?:Master|Slave)?|(?:Trigger|Stop|Preload)Sound|(?:(?:Get|Delete)Sub|Insert)String|To(?:Upper|Lower)|Give(?:InventoryList|Money)|RezObject|(?:Stop)?LookAt|Sleep|CollisionFilter|(?:Take|Release)Controls|DetachFromAvatar|AttachToAvatar(?:Temp)?|InstantMessage|(?:GetNext)?Email|StopHover|MinEventDelay|RotLookAt|String(?:Length|Trim)|(?:Start|Stop)Animation|TargetOmega|RequestPermissions|(?:Create|Break)Link|BreakAllLinks|(?:Give|Remove)Inventory|Water|PassTouches|Request(?:Agent|Inventory)Data|TeleportAgent(?:Home|GlobalCoords)?|ModifyLand|CollisionSound|ResetScript|MessageLinked|PushObject|PassCollisions|AxisAngle2Rot|Rot2(?:Axis|Angle)|A(?:cos|sin)|AngleBetween|AllowInventoryDrop|SubStringIndex|List2(?:CSV|Integer|Json|Float|String|Key|Vector|Rot|List(?:Strided)?)|DeleteSubList|List(?:Statistics|Sort|Randomize|(?:Insert|Find|Replace)List)|EdgeOfWorld|AdjustSoundVolume|Key2Name|TriggerSoundLimited|EjectFromLand|(?:CSV|ParseString)2List|OverMyLand|SameGroup|UnSit|Ground(?:Slope|Normal|Contour)|GroundRepel|(?:Set|Remove)VehicleFlags|(?:AvatarOn)?(?:Link)?SitTarget|Script(?:Danger|Profiler)|Dialog|VolumeDetect|ResetOtherScript|RemoteLoadScriptPin|(?:Open|Close)RemoteDataChannel|SendRemoteData|RemoteDataReply|(?:Integer|String)ToBase64|XorBase64|Log(?:10)?|Base64To(?:String|Integer)|ParseStringKeepNulls|RezAtRoot|RequestSimulatorData|ForceMouselook|(?:Load|Release|(?:E|Une)scape)URL|ParcelMedia(?:CommandList|Query)|ModPow|MapDestination|(?:RemoveFrom|AddTo|Reset)Land(?:Pass|Ban)List|(?:Set|Clear)CameraParams|HTTP(?:Request|Response)|TextBox|DetectedTouch(?:UV|Face|Pos|(?:N|Bin)ormal|ST)|(?:MD5|SHA1|DumpList2)String|Request(?:Secure)?URL|Clear(?:Prim|Link)Media|(?:Link)?ParticleSystem|(?:Get|Request)(?:Username|DisplayName)|RegionSayTo|CastRay|GenerateKey|TransferLindenDollars|ManageEstateAccess|(?:Create|Delete)Character|ExecCharacterCmd|Evade|FleeFrom|NavigateTo|PatrolPoints|Pursue|UpdateCharacter|WanderWithin))\b'
-    lsl_constants_float = r'\b(?:DEG_TO_RAD|PI(?:_BY_TWO)?|RAD_TO_DEG|SQRT2|TWO_PI)\b'
-    lsl_constants_integer = r'\b(?:JSON_APPEND|STATUS_(?:PHYSICS|ROTATE_[XYZ]|PHANTOM|SANDBOX|BLOCK_GRAB(?:_OBJECT)?|(?:DIE|RETURN)_AT_EDGE|CAST_SHADOWS|OK|MALFORMED_PARAMS|TYPE_MISMATCH|BOUNDS_ERROR|NOT_(?:FOUND|SUPPORTED)|INTERNAL_ERROR|WHITELIST_FAILED)|AGENT(?:_(?:BY_(?:LEGACY_|USER)NAME|FLYING|ATTACHMENTS|SCRIPTED|MOUSELOOK|SITTING|ON_OBJECT|AWAY|WALKING|IN_AIR|TYPING|CROUCHING|BUSY|ALWAYS_RUN|AUTOPILOT|LIST_(?:PARCEL(?:_OWNER)?|REGION)))?|CAMERA_(?:PITCH|DISTANCE|BEHINDNESS_(?:ANGLE|LAG)|(?:FOCUS|POSITION)(?:_(?:THRESHOLD|LOCKED|LAG))?|FOCUS_OFFSET|ACTIVE)|ANIM_ON|LOOP|REVERSE|PING_PONG|SMOOTH|ROTATE|SCALE|ALL_SIDES|LINK_(?:ROOT|SET|ALL_(?:OTHERS|CHILDREN)|THIS)|ACTIVE|PASSIVE|SCRIPTED|CONTROL_(?:FWD|BACK|(?:ROT_)?(?:LEFT|RIGHT)|UP|DOWN|(?:ML_)?LBUTTON)|PERMISSION_(?:RETURN_OBJECTS|DEBIT|OVERRIDE_ANIMATIONS|SILENT_ESTATE_MANAGEMENT|TAKE_CONTROLS|TRIGGER_ANIMATION|ATTACH|CHANGE_LINKS|(?:CONTROL|TRACK)_CAMERA|TELEPORT)|INVENTORY_(?:TEXTURE|SOUND|OBJECT|SCRIPT|LANDMARK|CLOTHING|NOTECARD|BODYPART|ANIMATION|GESTURE|ALL|NONE)|CHANGED_(?:INVENTORY|COLOR|SHAPE|SCALE|TEXTURE|LINK|ALLOWED_DROP|OWNER|REGION(?:_START)?|TELEPORT|MEDIA)|OBJECT_(?:(?:PHYSICS|SERVER|STREAMING)_COST|UNKNOWN_DETAIL|CHARACTER_TIME|PHANTOM|PHYSICS|TEMP_ON_REZ|NAME|DESC|POS|PRIM_EQUIVALENCE|RETURN_(?:PARCEL(?:_OWNER)?|REGION)|ROO?T|VELOCITY|OWNER|GROUP|CREATOR|ATTACHED_POINT|RENDER_WEIGHT|PATHFINDING_TYPE|(?:RUNNING|TOTAL)_SCRIPT_COUNT|SCRIPT_(?:MEMORY|TIME))|TYPE_(?:INTEGER|FLOAT|STRING|KEY|VECTOR|ROTATION|INVALID)|(?:DEBUG|PUBLIC)_CHANNEL|ATTACH_(?:AVATAR_CENTER|CHEST|HEAD|BACK|PELVIS|MOUTH|CHIN|NECK|NOSE|BELLY|[LR](?:SHOULDER|HAND|FOOT|EAR|EYE|[UL](?:ARM|LEG)|HIP)|(?:LEFT|RIGHT)_PEC|HUD_(?:CENTER_[12]|TOP_(?:RIGHT|CENTER|LEFT)|BOTTOM(?:_(?:RIGHT|LEFT))?))|LAND_(?:LEVEL|RAISE|LOWER|SMOOTH|NOISE|REVERT)|DATA_(?:ONLINE|NAME|BORN|SIM_(?:POS|STATUS|RATING)|PAYINFO)|PAYMENT_INFO_(?:ON_FILE|USED)|REMOTE_DATA_(?:CHANNEL|REQUEST|REPLY)|PSYS_(?:PART_(?:BF_(?:ZERO|ONE(?:_MINUS_(?:DEST_COLOR|SOURCE_(ALPHA|COLOR)))?|DEST_COLOR|SOURCE_(ALPHA|COLOR))|BLEND_FUNC_(DEST|SOURCE)|FLAGS|(?:START|END)_(?:COLOR|ALPHA|SCALE|GLOW)|MAX_AGE|(?:RIBBON|WIND|INTERP_(?:COLOR|SCALE)|BOUNCE|FOLLOW_(?:SRC|VELOCITY)|TARGET_(?:POS|LINEAR)|EMISSIVE)_MASK)|SRC_(?:MAX_AGE|PATTERN|ANGLE_(?:BEGIN|END)|BURST_(?:RATE|PART_COUNT|RADIUS|SPEED_(?:MIN|MAX))|ACCEL|TEXTURE|TARGET_KEY|OMEGA|PATTERN_(?:DROP|EXPLODE|ANGLE(?:_CONE(?:_EMPTY)?)?)))|VEHICLE_(?:REFERENCE_FRAME|TYPE_(?:NONE|SLED|CAR|BOAT|AIRPLANE|BALLOON)|(?:LINEAR|ANGULAR)_(?:FRICTION_TIMESCALE|MOTOR_DIRECTION)|LINEAR_MOTOR_OFFSET|HOVER_(?:HEIGHT|EFFICIENCY|TIMESCALE)|BUOYANCY|(?:LINEAR|ANGULAR)_(?:DEFLECTION_(?:EFFICIENCY|TIMESCALE)|MOTOR_(?:DECAY_)?TIMESCALE)|VERTICAL_ATTRACTION_(?:EFFICIENCY|TIMESCALE)|BANKING_(?:EFFICIENCY|MIX|TIMESCALE)|FLAG_(?:NO_DEFLECTION_UP|LIMIT_(?:ROLL_ONLY|MOTOR_UP)|HOVER_(?:(?:WATER|TERRAIN|UP)_ONLY|GLOBAL_HEIGHT)|MOUSELOOK_(?:STEER|BANK)|CAMERA_DECOUPLED))|PRIM_(?:TYPE(?:_(?:BOX|CYLINDER|PRISM|SPHERE|TORUS|TUBE|RING|SCULPT))?|HOLE_(?:DEFAULT|CIRCLE|SQUARE|TRIANGLE)|MATERIAL(?:_(?:STONE|METAL|GLASS|WOOD|FLESH|PLASTIC|RUBBER))?|SHINY_(?:NONE|LOW|MEDIUM|HIGH)|BUMP_(?:NONE|BRIGHT|DARK|WOOD|BARK|BRICKS|CHECKER|CONCRETE|TILE|STONE|DISKS|GRAVEL|BLOBS|SIDING|LARGETILE|STUCCO|SUCTION|WEAVE)|TEXGEN_(?:DEFAULT|PLANAR)|SCULPT_(?:TYPE_(?:SPHERE|TORUS|PLANE|CYLINDER|MASK)|FLAG_(?:MIRROR|INVERT))|PHYSICS(?:_(?:SHAPE_(?:CONVEX|NONE|PRIM|TYPE)))?|(?:POS|ROT)_LOCAL|SLICE|TEXT|FLEXIBLE|POINT_LIGHT|TEMP_ON_REZ|PHANTOM|POSITION|SIZE|ROTATION|TEXTURE|NAME|OMEGA|DESC|LINK_TARGET|COLOR|BUMP_SHINY|FULLBRIGHT|TEXGEN|GLOW|MEDIA_(?:ALT_IMAGE_ENABLE|CONTROLS|(?:CURRENT|HOME)_URL|AUTO_(?:LOOP|PLAY|SCALE|ZOOM)|FIRST_CLICK_INTERACT|(?:WIDTH|HEIGHT)_PIXELS|WHITELIST(?:_ENABLE)?|PERMS_(?:INTERACT|CONTROL)|PARAM_MAX|CONTROLS_(?:STANDARD|MINI)|PERM_(?:NONE|OWNER|GROUP|ANYONE)|MAX_(?:URL_LENGTH|WHITELIST_(?:SIZE|COUNT)|(?:WIDTH|HEIGHT)_PIXELS)))|MASK_(?:BASE|OWNER|GROUP|EVERYONE|NEXT)|PERM_(?:TRANSFER|MODIFY|COPY|MOVE|ALL)|PARCEL_(?:MEDIA_COMMAND_(?:STOP|PAUSE|PLAY|LOOP|TEXTURE|URL|TIME|AGENT|UNLOAD|AUTO_ALIGN|TYPE|SIZE|DESC|LOOP_SET)|FLAG_(?:ALLOW_(?:FLY|(?:GROUP_)?SCRIPTS|LANDMARK|TERRAFORM|DAMAGE|CREATE_(?:GROUP_)?OBJECTS)|USE_(?:ACCESS_(?:GROUP|LIST)|BAN_LIST|LAND_PASS_LIST)|LOCAL_SOUND_ONLY|RESTRICT_PUSHOBJECT|ALLOW_(?:GROUP|ALL)_OBJECT_ENTRY)|COUNT_(?:TOTAL|OWNER|GROUP|OTHER|SELECTED|TEMP)|DETAILS_(?:NAME|DESC|OWNER|GROUP|AREA|ID|SEE_AVATARS))|LIST_STAT_(?:MAX|MIN|MEAN|MEDIAN|STD_DEV|SUM(?:_SQUARES)?|NUM_COUNT|GEOMETRIC_MEAN|RANGE)|PAY_(?:HIDE|DEFAULT)|REGION_FLAG_(?:ALLOW_DAMAGE|FIXED_SUN|BLOCK_TERRAFORM|SANDBOX|DISABLE_(?:COLLISIONS|PHYSICS)|BLOCK_FLY|ALLOW_DIRECT_TELEPORT|RESTRICT_PUSHOBJECT)|HTTP_(?:METHOD|MIMETYPE|BODY_(?:MAXLENGTH|TRUNCATED)|CUSTOM_HEADER|PRAGMA_NO_CACHE|VERBOSE_THROTTLE|VERIFY_CERT)|STRING_(?:TRIM(?:_(?:HEAD|TAIL))?)|CLICK_ACTION_(?:NONE|TOUCH|SIT|BUY|PAY|OPEN(?:_MEDIA)?|PLAY|ZOOM)|TOUCH_INVALID_FACE|PROFILE_(?:NONE|SCRIPT_MEMORY)|RC_(?:DATA_FLAGS|DETECT_PHANTOM|GET_(?:LINK_NUM|NORMAL|ROOT_KEY)|MAX_HITS|REJECT_(?:TYPES|AGENTS|(?:NON)?PHYSICAL|LAND))|RCERR_(?:CAST_TIME_EXCEEDED|SIM_PERF_LOW|UNKNOWN)|ESTATE_ACCESS_(?:ALLOWED_(?:AGENT|GROUP)_(?:ADD|REMOVE)|BANNED_AGENT_(?:ADD|REMOVE))|DENSITY|FRICTION|RESTITUTION|GRAVITY_MULTIPLIER|KFM_(?:COMMAND|CMD_(?:PLAY|STOP|PAUSE|SET_MODE)|MODE|FORWARD|LOOP|PING_PONG|REVERSE|DATA|ROTATION|TRANSLATION)|ERR_(?:GENERIC|PARCEL_PERMISSIONS|MALFORMED_PARAMS|RUNTIME_PERMISSIONS|THROTTLED)|CHARACTER_(?:CMD_(?:(?:SMOOTH_)?STOP|JUMP)|DESIRED_(?:TURN_)?SPEED|RADIUS|STAY_WITHIN_PARCEL|LENGTH|ORIENTATION|ACCOUNT_FOR_SKIPPED_FRAMES|AVOIDANCE_MODE|TYPE(?:_(?:[A-D]|NONE))?|MAX_(?:DECEL|TURN_RADIUS|(?:ACCEL|SPEED)))|PURSUIT_(?:OFFSET|FUZZ_FACTOR|GOAL_TOLERANCE|INTERCEPT)|REQUIRE_LINE_OF_SIGHT|FORCE_DIRECT_PATH|VERTICAL|HORIZONTAL|AVOID_(?:CHARACTERS|DYNAMIC_OBSTACLES|NONE)|PU_(?:EVADE_(?:HIDDEN|SPOTTED)|FAILURE_(?:DYNAMIC_PATHFINDING_DISABLED|INVALID_(?:GOAL|START)|NO_(?:NAVMESH|VALID_DESTINATION)|OTHER|TARGET_GONE|(?:PARCEL_)?UNREACHABLE)|(?:GOAL|SLOWDOWN_DISTANCE)_REACHED)|TRAVERSAL_TYPE(?:_(?:FAST|NONE|SLOW))?|CONTENT_TYPE_(?:ATOM|FORM|HTML|JSON|LLSD|RSS|TEXT|XHTML|XML)|GCNP_(?:RADIUS|STATIC)|(?:PATROL|WANDER)_PAUSE_AT_WAYPOINTS|OPT_(?:AVATAR|CHARACTER|EXCLUSION_VOLUME|LEGACY_LINKSET|MATERIAL_VOLUME|OTHER|STATIC_OBSTACLE|WALKABLE)|SIM_STAT_PCT_CHARS_STEPPED)\b'
-    lsl_constants_integer_boolean = r'\b(?:FALSE|TRUE)\b'
-    lsl_constants_rotation = r'\b(?:ZERO_ROTATION)\b'
-    lsl_constants_string = r'\b(?:EOF|JSON_(?:ARRAY|DELETE|FALSE|INVALID|NULL|NUMBER|OBJECT|STRING|TRUE)|NULL_KEY|TEXTURE_(?:BLANK|DEFAULT|MEDIA|PLYWOOD|TRANSPARENT)|URL_REQUEST_(?:GRANTED|DENIED))\b'
-    lsl_constants_vector = r'\b(?:TOUCH_INVALID_(?:TEXCOORD|VECTOR)|ZERO_VECTOR)\b'
-    lsl_invalid_broken = r'\b(?:LAND_(?:LARGE|MEDIUM|SMALL)_BRUSH)\b'
-    lsl_invalid_deprecated = r'\b(?:ATTACH_[LR]PEC|DATA_RATING|OBJECT_ATTACHMENT_(?:GEOMETRY_BYTES|SURFACE_AREA)|PRIM_(?:CAST_SHADOWS|MATERIAL_LIGHT|TYPE_LEGACY)|PSYS_SRC_(?:INNER|OUTER)ANGLE|VEHICLE_FLAG_NO_FLY_UP|ll(?:Cloud|Make(?:Explosion|Fountain|Smoke|Fire)|RemoteDataSetRegion|Sound(?:Preload)?|XorBase64Strings(?:Correct)?))\b'
-    lsl_invalid_illegal = r'\b(?:event)\b'
-    lsl_invalid_unimplemented = r'\b(?:CHARACTER_(?:MAX_ANGULAR_(?:ACCEL|SPEED)|TURN_SPEED_MULTIPLIER)|PERMISSION_(?:CHANGE_(?:JOINTS|PERMISSIONS)|RELEASE_OWNERSHIP|REMAP_CONTROLS)|PRIM_PHYSICS_MATERIAL|PSYS_SRC_OBJ_REL_MASK|ll(?:CollisionSprite|(?:Stop)?PointAt|(?:(?:Refresh|Set)Prim)URL|(?:Take|Release)Camera|RemoteLoadScript))\b'
-    lsl_reserved_godmode = r'\b(?:ll(?:GodLikeRezObject|Set(?:Inventory|Object)PermMask))\b'
-    lsl_reserved_log = r'\b(?:print)\b'
-    lsl_operators = r'\+\+|\-\-|<<|>>|&&?|\|\|?|\^|~|[!%<>=*+\-/]=?'
-
-    tokens = {
-        'root':
-        [
-            (r'//.*?\n',                          Comment.Single),
-            (r'/\*',                              Comment.Multiline, 'comment'),
-            (r'"',                                String.Double, 'string'),
-            (lsl_keywords,                        Keyword),
-            (lsl_types,                           Keyword.Type),
-            (lsl_states,                          Name.Class),
-            (lsl_events,                          Name.Builtin),
-            (lsl_functions_builtin,               Name.Function),
-            (lsl_constants_float,                 Keyword.Constant),
-            (lsl_constants_integer,               Keyword.Constant),
-            (lsl_constants_integer_boolean,       Keyword.Constant),
-            (lsl_constants_rotation,              Keyword.Constant),
-            (lsl_constants_string,                Keyword.Constant),
-            (lsl_constants_vector,                Keyword.Constant),
-            (lsl_invalid_broken,                  Error),
-            (lsl_invalid_deprecated,              Error),
-            (lsl_invalid_illegal,                 Error),
-            (lsl_invalid_unimplemented,           Error),
-            (lsl_reserved_godmode,                Keyword.Reserved),
-            (lsl_reserved_log,                    Keyword.Reserved),
-            (r'\b([a-zA-Z_]\w*)\b',     Name.Variable),
-            (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d*', Number.Float),
-            (r'(\d+\.\d*|\.\d+)',                 Number.Float),
-            (r'0[xX][0-9a-fA-F]+',                Number.Hex),
-            (r'\d+',                              Number.Integer),
-            (lsl_operators,                       Operator),
-            (r':=?',                              Error),
-            (r'[,;{}()\[\]]',                     Punctuation),
-            (r'\n+',                              Whitespace),
-            (r'\s+',                              Whitespace)
-        ],
-        'comment':
-        [
-            (r'[^*/]+',                           Comment.Multiline),
-            (r'/\*',                              Comment.Multiline, '#push'),
-            (r'\*/',                              Comment.Multiline, '#pop'),
-            (r'[*/]',                             Comment.Multiline)
-        ],
-        'string':
-        [
-            (r'\\([nt"\\])',                      String.Escape),
-            (r'"',                                String.Double, '#pop'),
-            (r'\\.',                              Error),
-            (r'[^"\\]+',                          String.Double),
-        ]
-    }
-
-
-class AppleScriptLexer(RegexLexer):
-    """
-    For AppleScript source code,
-    including `AppleScript Studio
-    `_.
-    Contributed by Andreas Amann .
-    """
-
-    name = 'AppleScript'
-    url = 'https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/introduction/ASLR_intro.html'
-    aliases = ['applescript']
-    filenames = ['*.applescript']
-    version_added = '1.0'
-
-    flags = re.MULTILINE | re.DOTALL
-
-    Identifiers = r'[a-zA-Z]\w*'
-
-    # XXX: use words() for all of these
-    Literals = ('AppleScript', 'current application', 'false', 'linefeed',
-                'missing value', 'pi', 'quote', 'result', 'return', 'space',
-                'tab', 'text item delimiters', 'true', 'version')
-    Classes = ('alias ', 'application ', 'boolean ', 'class ', 'constant ',
-               'date ', 'file ', 'integer ', 'list ', 'number ', 'POSIX file ',
-               'real ', 'record ', 'reference ', 'RGB color ', 'script ',
-               'text ', 'unit types', '(?:Unicode )?text', 'string')
-    BuiltIn = ('attachment', 'attribute run', 'character', 'day', 'month',
-               'paragraph', 'word', 'year')
-    HandlerParams = ('about', 'above', 'against', 'apart from', 'around',
-                     'aside from', 'at', 'below', 'beneath', 'beside',
-                     'between', 'for', 'given', 'instead of', 'on', 'onto',
-                     'out of', 'over', 'since')
-    Commands = ('ASCII (character|number)', 'activate', 'beep', 'choose URL',
-                'choose application', 'choose color', 'choose file( name)?',
-                'choose folder', 'choose from list',
-                'choose remote application', 'clipboard info',
-                'close( access)?', 'copy', 'count', 'current date', 'delay',
-                'delete', 'display (alert|dialog)', 'do shell script',
-                'duplicate', 'exists', 'get eof', 'get volume settings',
-                'info for', 'launch', 'list (disks|folder)', 'load script',
-                'log', 'make', 'mount volume', 'new', 'offset',
-                'open( (for access|location))?', 'path to', 'print', 'quit',
-                'random number', 'read', 'round', 'run( script)?',
-                'say', 'scripting components',
-                'set (eof|the clipboard to|volume)', 'store script',
-                'summarize', 'system attribute', 'system info',
-                'the clipboard', 'time to GMT', 'write', 'quoted form')
-    References = ('(in )?back of', '(in )?front of', '[0-9]+(st|nd|rd|th)',
-                  'first', 'second', 'third', 'fourth', 'fifth', 'sixth',
-                  'seventh', 'eighth', 'ninth', 'tenth', 'after', 'back',
-                  'before', 'behind', 'every', 'front', 'index', 'last',
-                  'middle', 'some', 'that', 'through', 'thru', 'where', 'whose')
-    Operators = ("and", "or", "is equal", "equals", "(is )?equal to", "is not",
-                 "isn't", "isn't equal( to)?", "is not equal( to)?",
-                 "doesn't equal", "does not equal", "(is )?greater than",
-                 "comes after", "is not less than or equal( to)?",
-                 "isn't less than or equal( to)?", "(is )?less than",
-                 "comes before", "is not greater than or equal( to)?",
-                 "isn't greater than or equal( to)?",
-                 "(is  )?greater than or equal( to)?", "is not less than",
-                 "isn't less than", "does not come before",
-                 "doesn't come before", "(is )?less than or equal( to)?",
-                 "is not greater than", "isn't greater than",
-                 "does not come after", "doesn't come after", "starts? with",
-                 "begins? with", "ends? with", "contains?", "does not contain",
-                 "doesn't contain", "is in", "is contained by", "is not in",
-                 "is not contained by", "isn't contained by", "div", "mod",
-                 "not", "(a  )?(ref( to)?|reference to)", "is", "does")
-    Control = ('considering', 'else', 'error', 'exit', 'from', 'if',
-               'ignoring', 'in', 'repeat', 'tell', 'then', 'times', 'to',
-               'try', 'until', 'using terms from', 'while', 'whith',
-               'with timeout( of)?', 'with transaction', 'by', 'continue',
-               'end', 'its?', 'me', 'my', 'return', 'of', 'as')
-    Declarations = ('global', 'local', 'prop(erty)?', 'set', 'get')
-    Reserved = ('but', 'put', 'returning', 'the')
-    StudioClasses = ('action cell', 'alert reply', 'application', 'box',
-                     'browser( cell)?', 'bundle', 'button( cell)?', 'cell',
-                     'clip view', 'color well', 'color-panel',
-                     'combo box( item)?', 'control',
-                     'data( (cell|column|item|row|source))?', 'default entry',
-                     'dialog reply', 'document', 'drag info', 'drawer',
-                     'event', 'font(-panel)?', 'formatter',
-                     'image( (cell|view))?', 'matrix', 'menu( item)?', 'item',
-                     'movie( view)?', 'open-panel', 'outline view', 'panel',
-                     'pasteboard', 'plugin', 'popup button',
-                     'progress indicator', 'responder', 'save-panel',
-                     'scroll view', 'secure text field( cell)?', 'slider',
-                     'sound', 'split view', 'stepper', 'tab view( item)?',
-                     'table( (column|header cell|header view|view))',
-                     'text( (field( cell)?|view))?', 'toolbar( item)?',
-                     'user-defaults', 'view', 'window')
-    StudioEvents = ('accept outline drop', 'accept table drop', 'action',
-                    'activated', 'alert ended', 'awake from nib', 'became key',
-                    'became main', 'begin editing', 'bounds changed',
-                    'cell value', 'cell value changed', 'change cell value',
-                    'change item value', 'changed', 'child of item',
-                    'choose menu item', 'clicked', 'clicked toolbar item',
-                    'closed', 'column clicked', 'column moved',
-                    'column resized', 'conclude drop', 'data representation',
-                    'deminiaturized', 'dialog ended', 'document nib name',
-                    'double clicked', 'drag( (entered|exited|updated))?',
-                    'drop', 'end editing', 'exposed', 'idle', 'item expandable',
-                    'item value', 'item value changed', 'items changed',
-                    'keyboard down', 'keyboard up', 'launched',
-                    'load data representation', 'miniaturized', 'mouse down',
-                    'mouse dragged', 'mouse entered', 'mouse exited',
-                    'mouse moved', 'mouse up', 'moved',
-                    'number of browser rows', 'number of items',
-                    'number of rows', 'open untitled', 'opened', 'panel ended',
-                    'parameters updated', 'plugin loaded', 'prepare drop',
-                    'prepare outline drag', 'prepare outline drop',
-                    'prepare table drag', 'prepare table drop',
-                    'read from file', 'resigned active', 'resigned key',
-                    'resigned main', 'resized( sub views)?',
-                    'right mouse down', 'right mouse dragged',
-                    'right mouse up', 'rows changed', 'scroll wheel',
-                    'selected tab view item', 'selection changed',
-                    'selection changing', 'should begin editing',
-                    'should close', 'should collapse item',
-                    'should end editing', 'should expand item',
-                    'should open( untitled)?',
-                    'should quit( after last window closed)?',
-                    'should select column', 'should select item',
-                    'should select row', 'should select tab view item',
-                    'should selection change', 'should zoom', 'shown',
-                    'update menu item', 'update parameters',
-                    'update toolbar item', 'was hidden', 'was miniaturized',
-                    'will become active', 'will close', 'will dismiss',
-                    'will display browser cell', 'will display cell',
-                    'will display item cell', 'will display outline cell',
-                    'will finish launching', 'will hide', 'will miniaturize',
-                    'will move', 'will open', 'will pop up', 'will quit',
-                    'will resign active', 'will resize( sub views)?',
-                    'will select tab view item', 'will show', 'will zoom',
-                    'write to file', 'zoomed')
-    StudioCommands = ('animate', 'append', 'call method', 'center',
-                      'close drawer', 'close panel', 'display',
-                      'display alert', 'display dialog', 'display panel', 'go',
-                      'hide', 'highlight', 'increment', 'item for',
-                      'load image', 'load movie', 'load nib', 'load panel',
-                      'load sound', 'localized string', 'lock focus', 'log',
-                      'open drawer', 'path for', 'pause', 'perform action',
-                      'play', 'register', 'resume', 'scroll', 'select( all)?',
-                      'show', 'size to fit', 'start', 'step back',
-                      'step forward', 'stop', 'synchronize', 'unlock focus',
-                      'update')
-    StudioProperties = ('accepts arrow key', 'action method', 'active',
-                        'alignment', 'allowed identifiers',
-                        'allows branch selection', 'allows column reordering',
-                        'allows column resizing', 'allows column selection',
-                        'allows customization',
-                        'allows editing text attributes',
-                        'allows empty selection', 'allows mixed state',
-                        'allows multiple selection', 'allows reordering',
-                        'allows undo', 'alpha( value)?', 'alternate image',
-                        'alternate increment value', 'alternate title',
-                        'animation delay', 'associated file name',
-                        'associated object', 'auto completes', 'auto display',
-                        'auto enables items', 'auto repeat',
-                        'auto resizes( outline column)?',
-                        'auto save expanded items', 'auto save name',
-                        'auto save table columns', 'auto saves configuration',
-                        'auto scroll', 'auto sizes all columns to fit',
-                        'auto sizes cells', 'background color', 'bezel state',
-                        'bezel style', 'bezeled', 'border rect', 'border type',
-                        'bordered', 'bounds( rotation)?', 'box type',
-                        'button returned', 'button type',
-                        'can choose directories', 'can choose files',
-                        'can draw', 'can hide',
-                        'cell( (background color|size|type))?', 'characters',
-                        'class', 'click count', 'clicked( data)? column',
-                        'clicked data item', 'clicked( data)? row',
-                        'closeable', 'collating', 'color( (mode|panel))',
-                        'command key down', 'configuration',
-                        'content(s| (size|view( margins)?))?', 'context',
-                        'continuous', 'control key down', 'control size',
-                        'control tint', 'control view',
-                        'controller visible', 'coordinate system',
-                        'copies( on scroll)?', 'corner view', 'current cell',
-                        'current column', 'current( field)?  editor',
-                        'current( menu)? item', 'current row',
-                        'current tab view item', 'data source',
-                        'default identifiers', 'delta (x|y|z)',
-                        'destination window', 'directory', 'display mode',
-                        'displayed cell', 'document( (edited|rect|view))?',
-                        'double value', 'dragged column', 'dragged distance',
-                        'dragged items', 'draws( cell)? background',
-                        'draws grid', 'dynamically scrolls', 'echos bullets',
-                        'edge', 'editable', 'edited( data)? column',
-                        'edited data item', 'edited( data)? row', 'enabled',
-                        'enclosing scroll view', 'ending page',
-                        'error handling', 'event number', 'event type',
-                        'excluded from windows menu', 'executable path',
-                        'expanded', 'fax number', 'field editor', 'file kind',
-                        'file name', 'file type', 'first responder',
-                        'first visible column', 'flipped', 'floating',
-                        'font( panel)?', 'formatter', 'frameworks path',
-                        'frontmost', 'gave up', 'grid color', 'has data items',
-                        'has horizontal ruler', 'has horizontal scroller',
-                        'has parent data item', 'has resize indicator',
-                        'has shadow', 'has sub menu', 'has vertical ruler',
-                        'has vertical scroller', 'header cell', 'header view',
-                        'hidden', 'hides when deactivated', 'highlights by',
-                        'horizontal line scroll', 'horizontal page scroll',
-                        'horizontal ruler view', 'horizontally resizable',
-                        'icon image', 'id', 'identifier',
-                        'ignores multiple clicks',
-                        'image( (alignment|dims when disabled|frame style|scaling))?',
-                        'imports graphics', 'increment value',
-                        'indentation per level', 'indeterminate', 'index',
-                        'integer value', 'intercell spacing', 'item height',
-                        'key( (code|equivalent( modifier)?|window))?',
-                        'knob thickness', 'label', 'last( visible)? column',
-                        'leading offset', 'leaf', 'level', 'line scroll',
-                        'loaded', 'localized sort', 'location', 'loop mode',
-                        'main( (bunde|menu|window))?', 'marker follows cell',
-                        'matrix mode', 'maximum( content)? size',
-                        'maximum visible columns',
-                        'menu( form representation)?', 'miniaturizable',
-                        'miniaturized', 'minimized image', 'minimized title',
-                        'minimum column width', 'minimum( content)? size',
-                        'modal', 'modified', 'mouse down state',
-                        'movie( (controller|file|rect))?', 'muted', 'name',
-                        'needs display', 'next state', 'next text',
-                        'number of tick marks', 'only tick mark values',
-                        'opaque', 'open panel', 'option key down',
-                        'outline table column', 'page scroll', 'pages across',
-                        'pages down', 'palette label', 'pane splitter',
-                        'parent data item', 'parent window', 'pasteboard',
-                        'path( (names|separator))?', 'playing',
-                        'plays every frame', 'plays selection only', 'position',
-                        'preferred edge', 'preferred type', 'pressure',
-                        'previous text', 'prompt', 'properties',
-                        'prototype cell', 'pulls down', 'rate',
-                        'released when closed', 'repeated',
-                        'requested print time', 'required file type',
-                        'resizable', 'resized column', 'resource path',
-                        'returns records', 'reuses columns', 'rich text',
-                        'roll over', 'row height', 'rulers visible',
-                        'save panel', 'scripts path', 'scrollable',
-                        'selectable( identifiers)?', 'selected cell',
-                        'selected( data)? columns?', 'selected data items?',
-                        'selected( data)? rows?', 'selected item identifier',
-                        'selection by rect', 'send action on arrow key',
-                        'sends action when done editing', 'separates columns',
-                        'separator item', 'sequence number', 'services menu',
-                        'shared frameworks path', 'shared support path',
-                        'sheet', 'shift key down', 'shows alpha',
-                        'shows state by', 'size( mode)?',
-                        'smart insert delete enabled', 'sort case sensitivity',
-                        'sort column', 'sort order', 'sort type',
-                        'sorted( data rows)?', 'sound', 'source( mask)?',
-                        'spell checking enabled', 'starting page', 'state',
-                        'string value', 'sub menu', 'super menu', 'super view',
-                        'tab key traverses cells', 'tab state', 'tab type',
-                        'tab view', 'table view', 'tag', 'target( printer)?',
-                        'text color', 'text container insert',
-                        'text container origin', 'text returned',
-                        'tick mark position', 'time stamp',
-                        'title(d| (cell|font|height|position|rect))?',
-                        'tool tip', 'toolbar', 'trailing offset', 'transparent',
-                        'treat packages as directories', 'truncated labels',
-                        'types', 'unmodified characters', 'update views',
-                        'use sort indicator', 'user defaults',
-                        'uses data source', 'uses ruler',
-                        'uses threaded animation',
-                        'uses title from previous column', 'value wraps',
-                        'version',
-                        'vertical( (line scroll|page scroll|ruler view))?',
-                        'vertically resizable', 'view',
-                        'visible( document rect)?', 'volume', 'width', 'window',
-                        'windows menu', 'wraps', 'zoomable', 'zoomed')
-
-    tokens = {
-        'root': [
-            (r'\s+', Text),
-            (r'¬\n', String.Escape),
-            (r"'s\s+", Text),  # This is a possessive, consider moving
-            (r'(--|#).*?$', Comment),
-            (r'\(\*', Comment.Multiline, 'comment'),
-            (r'[(){}!,.:]', Punctuation),
-            (r'(«)([^»]+)(»)',
-             bygroups(Text, Name.Builtin, Text)),
-            (r'\b((?:considering|ignoring)\s*)'
-             r'(application responses|case|diacriticals|hyphens|'
-             r'numeric strings|punctuation|white space)',
-             bygroups(Keyword, Name.Builtin)),
-            (r'(-|\*|\+|&|≠|>=?|<=?|=|≥|≤|/|÷|\^)', Operator),
-            (r"\b({})\b".format('|'.join(Operators)), Operator.Word),
-            (r'^(\s*(?:on|end)\s+)'
-             r'({})'.format('|'.join(StudioEvents[::-1])),
-             bygroups(Keyword, Name.Function)),
-            (r'^(\s*)(in|on|script|to)(\s+)', bygroups(Text, Keyword, Text)),
-            (r'\b(as )({})\b'.format('|'.join(Classes)),
-             bygroups(Keyword, Name.Class)),
-            (r'\b({})\b'.format('|'.join(Literals)), Name.Constant),
-            (r'\b({})\b'.format('|'.join(Commands)), Name.Builtin),
-            (r'\b({})\b'.format('|'.join(Control)), Keyword),
-            (r'\b({})\b'.format('|'.join(Declarations)), Keyword),
-            (r'\b({})\b'.format('|'.join(Reserved)), Name.Builtin),
-            (r'\b({})s?\b'.format('|'.join(BuiltIn)), Name.Builtin),
-            (r'\b({})\b'.format('|'.join(HandlerParams)), Name.Builtin),
-            (r'\b({})\b'.format('|'.join(StudioProperties)), Name.Attribute),
-            (r'\b({})s?\b'.format('|'.join(StudioClasses)), Name.Builtin),
-            (r'\b({})\b'.format('|'.join(StudioCommands)), Name.Builtin),
-            (r'\b({})\b'.format('|'.join(References)), Name.Builtin),
-            (r'"(\\\\|\\[^\\]|[^"\\])*"', String.Double),
-            (rf'\b({Identifiers})\b', Name.Variable),
-            (r'[-+]?(\d+\.\d*|\d*\.\d+)(E[-+][0-9]+)?', Number.Float),
-            (r'[-+]?\d+', Number.Integer),
-        ],
-        'comment': [
-            (r'\(\*', Comment.Multiline, '#push'),
-            (r'\*\)', Comment.Multiline, '#pop'),
-            ('[^*(]+', Comment.Multiline),
-            ('[*(]', Comment.Multiline),
-        ],
-    }
-
-
-class RexxLexer(RegexLexer):
-    """
-    Rexx is a scripting language available for
-    a wide range of different platforms with its roots found on mainframe
-    systems. It is popular for I/O- and data based tasks and can act as glue
-    language to bind different applications together.
-    """
-    name = 'Rexx'
-    url = 'http://www.rexxinfo.org/'
-    aliases = ['rexx', 'arexx']
-    filenames = ['*.rexx', '*.rex', '*.rx', '*.arexx']
-    mimetypes = ['text/x-rexx']
-    version_added = '2.0'
-    flags = re.IGNORECASE
-
-    tokens = {
-        'root': [
-            (r'\s+', Whitespace),
-            (r'/\*', Comment.Multiline, 'comment'),
-            (r'"', String, 'string_double'),
-            (r"'", String, 'string_single'),
-            (r'[0-9]+(\.[0-9]+)?(e[+-]?[0-9])?', Number),
-            (r'([a-z_]\w*)(\s*)(:)(\s*)(procedure)\b',
-             bygroups(Name.Function, Whitespace, Operator, Whitespace,
-                      Keyword.Declaration)),
-            (r'([a-z_]\w*)(\s*)(:)',
-             bygroups(Name.Label, Whitespace, Operator)),
-            include('function'),
-            include('keyword'),
-            include('operator'),
-            (r'[a-z_]\w*', Text),
-        ],
-        'function': [
-            (words((
-                'abbrev', 'abs', 'address', 'arg', 'b2x', 'bitand', 'bitor', 'bitxor',
-                'c2d', 'c2x', 'center', 'charin', 'charout', 'chars', 'compare',
-                'condition', 'copies', 'd2c', 'd2x', 'datatype', 'date', 'delstr',
-                'delword', 'digits', 'errortext', 'form', 'format', 'fuzz', 'insert',
-                'lastpos', 'left', 'length', 'linein', 'lineout', 'lines', 'max',
-                'min', 'overlay', 'pos', 'queued', 'random', 'reverse', 'right', 'sign',
-                'sourceline', 'space', 'stream', 'strip', 'substr', 'subword', 'symbol',
-                'time', 'trace', 'translate', 'trunc', 'value', 'verify', 'word',
-                'wordindex', 'wordlength', 'wordpos', 'words', 'x2b', 'x2c', 'x2d',
-                'xrange'), suffix=r'(\s*)(\()'),
-             bygroups(Name.Builtin, Whitespace, Operator)),
-        ],
-        'keyword': [
-            (r'(address|arg|by|call|do|drop|else|end|exit|for|forever|if|'
-             r'interpret|iterate|leave|nop|numeric|off|on|options|parse|'
-             r'pull|push|queue|return|say|select|signal|to|then|trace|until|'
-             r'while)\b', Keyword.Reserved),
-        ],
-        'operator': [
-            (r'(-|//|/|\(|\)|\*\*|\*|\\<<|\\<|\\==|\\=|\\>>|\\>|\\|\|\||\||'
-             r'&&|&|%|\+|<<=|<<|<=|<>|<|==|=|><|>=|>>=|>>|>|¬<<|¬<|¬==|¬=|'
-             r'¬>>|¬>|¬|\.|,)', Operator),
-        ],
-        'string_double': [
-            (r'[^"\n]+', String),
-            (r'""', String),
-            (r'"', String, '#pop'),
-            (r'\n', Text, '#pop'),  # Stray linefeed also terminates strings.
-        ],
-        'string_single': [
-            (r'[^\'\n]+', String),
-            (r'\'\'', String),
-            (r'\'', String, '#pop'),
-            (r'\n', Text, '#pop'),  # Stray linefeed also terminates strings.
-        ],
-        'comment': [
-            (r'[^*]+', Comment.Multiline),
-            (r'\*/', Comment.Multiline, '#pop'),
-            (r'\*', Comment.Multiline),
-        ]
-    }
-
-    def _c(s):
-        return re.compile(s, re.MULTILINE)
-    _ADDRESS_COMMAND_PATTERN = _c(r'^\s*address\s+command\b')
-    _ADDRESS_PATTERN = _c(r'^\s*address\s+')
-    _DO_WHILE_PATTERN = _c(r'^\s*do\s+while\b')
-    _IF_THEN_DO_PATTERN = _c(r'^\s*if\b.+\bthen\s+do\s*$')
-    _PROCEDURE_PATTERN = _c(r'^\s*([a-z_]\w*)(\s*)(:)(\s*)(procedure)\b')
-    _ELSE_DO_PATTERN = _c(r'\belse\s+do\s*$')
-    _PARSE_ARG_PATTERN = _c(r'^\s*parse\s+(upper\s+)?(arg|value)\b')
-    PATTERNS_AND_WEIGHTS = (
-        (_ADDRESS_COMMAND_PATTERN, 0.2),
-        (_ADDRESS_PATTERN, 0.05),
-        (_DO_WHILE_PATTERN, 0.1),
-        (_ELSE_DO_PATTERN, 0.1),
-        (_IF_THEN_DO_PATTERN, 0.1),
-        (_PROCEDURE_PATTERN, 0.5),
-        (_PARSE_ARG_PATTERN, 0.2),
-    )
-
-    def analyse_text(text):
-        """
-        Check for initial comment and patterns that distinguish Rexx from other
-        C-like languages.
-        """
-        if re.search(r'/\*\**\s*rexx', text, re.IGNORECASE):
-            # Header matches MVS Rexx requirements, this is certainly a Rexx
-            # script.
-            return 1.0
-        elif text.startswith('/*'):
-            # Header matches general Rexx requirements; the source code might
-            # still be any language using C comments such as C++, C# or Java.
-            lowerText = text.lower()
-            result = sum(weight
-                         for (pattern, weight) in RexxLexer.PATTERNS_AND_WEIGHTS
-                         if pattern.search(lowerText)) + 0.01
-            return min(result, 1.0)
-
-
-class MOOCodeLexer(RegexLexer):
-    """
-    For MOOCode (the MOO scripting language).
-    """
-    name = 'MOOCode'
-    url = 'http://www.moo.mud.org/'
-    filenames = ['*.moo']
-    aliases = ['moocode', 'moo']
-    mimetypes = ['text/x-moocode']
-    version_added = '0.9'
-
-    tokens = {
-        'root': [
-            # Numbers
-            (r'(0|[1-9][0-9_]*)', Number.Integer),
-            # Strings
-            (r'"(\\\\|\\[^\\]|[^"\\])*"', String),
-            # exceptions
-            (r'(E_PERM|E_DIV)', Name.Exception),
-            # db-refs
-            (r'((#[-0-9]+)|(\$\w+))', Name.Entity),
-            # Keywords
-            (r'\b(if|else|elseif|endif|for|endfor|fork|endfork|while'
-             r'|endwhile|break|continue|return|try'
-             r'|except|endtry|finally|in)\b', Keyword),
-            # builtins
-            (r'(random|length)', Name.Builtin),
-            # special variables
-            (r'(player|caller|this|args)', Name.Variable.Instance),
-            # skip whitespace
-            (r'\s+', Text),
-            (r'\n', Text),
-            # other operators
-            (r'([!;=,{}&|:.\[\]@()<>?]+)', Operator),
-            # function call
-            (r'(\w+)(\()', bygroups(Name.Function, Operator)),
-            # variables
-            (r'(\w+)', Text),
-        ]
-    }
-
-
-class HybrisLexer(RegexLexer):
-    """
-    For Hybris source code.
-    """
-
-    name = 'Hybris'
-    aliases = ['hybris']
-    filenames = ['*.hyb']
-    mimetypes = ['text/x-hybris', 'application/x-hybris']
-    url = 'https://github.com/evilsocket/hybris'
-    version_added = '1.4'
-
-    flags = re.MULTILINE | re.DOTALL
-
-    tokens = {
-        'root': [
-            # method names
-            (r'^(\s*(?:function|method|operator\s+)+?)'
-             r'([a-zA-Z_]\w*)'
-             r'(\s*)(\()', bygroups(Keyword, Name.Function, Text, Operator)),
-            (r'[^\S\n]+', Text),
-            (r'//.*?\n', Comment.Single),
-            (r'/\*.*?\*/', Comment.Multiline),
-            (r'@[a-zA-Z_][\w.]*', Name.Decorator),
-            (r'(break|case|catch|next|default|do|else|finally|for|foreach|of|'
-             r'unless|if|new|return|switch|me|throw|try|while)\b', Keyword),
-            (r'(extends|private|protected|public|static|throws|function|method|'
-             r'operator)\b', Keyword.Declaration),
-            (r'(true|false|null|__FILE__|__LINE__|__VERSION__|__LIB_PATH__|'
-             r'__INC_PATH__)\b', Keyword.Constant),
-            (r'(class|struct)(\s+)',
-             bygroups(Keyword.Declaration, Text), 'class'),
-            (r'(import|include)(\s+)',
-             bygroups(Keyword.Namespace, Text), 'import'),
-            (words((
-                'gc_collect', 'gc_mm_items', 'gc_mm_usage', 'gc_collect_threshold',
-                'urlencode', 'urldecode', 'base64encode', 'base64decode', 'sha1', 'crc32',
-                'sha2', 'md5', 'md5_file', 'acos', 'asin', 'atan', 'atan2', 'ceil', 'cos',
-                'cosh', 'exp', 'fabs', 'floor', 'fmod', 'log', 'log10', 'pow', 'sin',
-                'sinh', 'sqrt', 'tan', 'tanh', 'isint', 'isfloat', 'ischar', 'isstring',
-                'isarray', 'ismap', 'isalias', 'typeof', 'sizeof', 'toint', 'tostring',
-                'fromxml', 'toxml', 'binary', 'pack', 'load', 'eval', 'var_names',
-                'var_values', 'user_functions', 'dyn_functions', 'methods', 'call',
-                'call_method', 'mknod', 'mkfifo', 'mount', 'umount2', 'umount', 'ticks',
-                'usleep', 'sleep', 'time', 'strtime', 'strdate', 'dllopen', 'dlllink',
-                'dllcall', 'dllcall_argv', 'dllclose', 'env', 'exec', 'fork', 'getpid',
-                'wait', 'popen', 'pclose', 'exit', 'kill', 'pthread_create',
-                'pthread_create_argv', 'pthread_exit', 'pthread_join', 'pthread_kill',
-                'smtp_send', 'http_get', 'http_post', 'http_download', 'socket', 'bind',
-                'listen', 'accept', 'getsockname', 'getpeername', 'settimeout', 'connect',
-                'server', 'recv', 'send', 'close', 'print', 'println', 'printf', 'input',
-                'readline', 'serial_open', 'serial_fcntl', 'serial_get_attr',
-                'serial_get_ispeed', 'serial_get_ospeed', 'serial_set_attr',
-                'serial_set_ispeed', 'serial_set_ospeed', 'serial_write', 'serial_read',
-                'serial_close', 'xml_load', 'xml_parse', 'fopen', 'fseek', 'ftell',
-                'fsize', 'fread', 'fwrite', 'fgets', 'fclose', 'file', 'readdir',
-                'pcre_replace', 'size', 'pop', 'unmap', 'has', 'keys', 'values',
-                'length', 'find', 'substr', 'replace', 'split', 'trim', 'remove',
-                'contains', 'join'), suffix=r'\b'),
-             Name.Builtin),
-            (words((
-                'MethodReference', 'Runner', 'Dll', 'Thread', 'Pipe', 'Process',
-                'Runnable', 'CGI', 'ClientSocket', 'Socket', 'ServerSocket',
-                'File', 'Console', 'Directory', 'Exception'), suffix=r'\b'),
-             Keyword.Type),
-            (r'"(\\\\|\\[^\\]|[^"\\])*"', String),
-            (r"'\\.'|'[^\\]'|'\\u[0-9a-f]{4}'", String.Char),
-            (r'(\.)([a-zA-Z_]\w*)',
-             bygroups(Operator, Name.Attribute)),
-            (r'[a-zA-Z_]\w*:', Name.Label),
-            (r'[a-zA-Z_$]\w*', Name),
-            (r'[~^*!%&\[\](){}<>|+=:;,./?\-@]+', Operator),
-            (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
-            (r'0x[0-9a-f]+', Number.Hex),
-            (r'[0-9]+L?', Number.Integer),
-            (r'\n', Text),
-        ],
-        'class': [
-            (r'[a-zA-Z_]\w*', Name.Class, '#pop')
-        ],
-        'import': [
-            (r'[\w.]+\*?', Name.Namespace, '#pop')
-        ],
-    }
-
-    def analyse_text(text):
-        """public method and private method don't seem to be quite common
-        elsewhere."""
-        result = 0
-        if re.search(r'\b(?:public|private)\s+method\b', text):
-            result += 0.01
-        return result
-
-
-
-class EasytrieveLexer(RegexLexer):
-    """
-    Easytrieve Plus is a programming language for extracting, filtering and
-    converting sequential data. Furthermore it can layout data for reports.
-    It is mainly used on mainframe platforms and can access several of the
-    mainframe's native file formats. It is somewhat comparable to awk.
-    """
-    name = 'Easytrieve'
-    aliases = ['easytrieve']
-    filenames = ['*.ezt', '*.mac']
-    mimetypes = ['text/x-easytrieve']
-    url = 'https://www.broadcom.com/products/mainframe/application-development/easytrieve-report-generator'
-    version_added = '2.1'
-    flags = 0
-
-    # Note: We cannot use r'\b' at the start and end of keywords because
-    # Easytrieve Plus delimiter characters are:
-    #
-    #   * space ( )
-    #   * apostrophe (')
-    #   * period (.)
-    #   * comma (,)
-    #   * parenthesis ( and )
-    #   * colon (:)
-    #
-    # Additionally words end once a '*' appears, indicatins a comment.
-    _DELIMITERS = r' \'.,():\n'
-    _DELIMITERS_OR_COMENT = _DELIMITERS + '*'
-    _DELIMITER_PATTERN = '[' + _DELIMITERS + ']'
-    _DELIMITER_PATTERN_CAPTURE = '(' + _DELIMITER_PATTERN + ')'
-    _NON_DELIMITER_OR_COMMENT_PATTERN = '[^' + _DELIMITERS_OR_COMENT + ']'
-    _OPERATORS_PATTERN = '[.+\\-/=\\[\\](){}<>;,&%¬]'
-    _KEYWORDS = [
-        'AFTER-BREAK', 'AFTER-LINE', 'AFTER-SCREEN', 'AIM', 'AND', 'ATTR',
-        'BEFORE', 'BEFORE-BREAK', 'BEFORE-LINE', 'BEFORE-SCREEN', 'BUSHU',
-        'BY', 'CALL', 'CASE', 'CHECKPOINT', 'CHKP', 'CHKP-STATUS', 'CLEAR',
-        'CLOSE', 'COL', 'COLOR', 'COMMIT', 'CONTROL', 'COPY', 'CURSOR', 'D',
-        'DECLARE', 'DEFAULT', 'DEFINE', 'DELETE', 'DENWA', 'DISPLAY', 'DLI',
-        'DO', 'DUPLICATE', 'E', 'ELSE', 'ELSE-IF', 'END', 'END-CASE',
-        'END-DO', 'END-IF', 'END-PROC', 'ENDPAGE', 'ENDTABLE', 'ENTER', 'EOF',
-        'EQ', 'ERROR', 'EXIT', 'EXTERNAL', 'EZLIB', 'F1', 'F10', 'F11', 'F12',
-        'F13', 'F14', 'F15', 'F16', 'F17', 'F18', 'F19', 'F2', 'F20', 'F21',
-        'F22', 'F23', 'F24', 'F25', 'F26', 'F27', 'F28', 'F29', 'F3', 'F30',
-        'F31', 'F32', 'F33', 'F34', 'F35', 'F36', 'F4', 'F5', 'F6', 'F7',
-        'F8', 'F9', 'FETCH', 'FILE-STATUS', 'FILL', 'FINAL', 'FIRST',
-        'FIRST-DUP', 'FOR', 'GE', 'GET', 'GO', 'GOTO', 'GQ', 'GR', 'GT',
-        'HEADING', 'HEX', 'HIGH-VALUES', 'IDD', 'IDMS', 'IF', 'IN', 'INSERT',
-        'JUSTIFY', 'KANJI-DATE', 'KANJI-DATE-LONG', 'KANJI-TIME', 'KEY',
-        'KEY-PRESSED', 'KOKUGO', 'KUN', 'LAST-DUP', 'LE', 'LEVEL', 'LIKE',
-        'LINE', 'LINE-COUNT', 'LINE-NUMBER', 'LINK', 'LIST', 'LOW-VALUES',
-        'LQ', 'LS', 'LT', 'MACRO', 'MASK', 'MATCHED', 'MEND', 'MESSAGE',
-        'MOVE', 'MSTART', 'NE', 'NEWPAGE', 'NOMASK', 'NOPRINT', 'NOT',
-        'NOTE', 'NOVERIFY', 'NQ', 'NULL', 'OF', 'OR', 'OTHERWISE', 'PA1',
-        'PA2', 'PA3', 'PAGE-COUNT', 'PAGE-NUMBER', 'PARM-REGISTER',
-        'PATH-ID', 'PATTERN', 'PERFORM', 'POINT', 'POS', 'PRIMARY', 'PRINT',
-        'PROCEDURE', 'PROGRAM', 'PUT', 'READ', 'RECORD', 'RECORD-COUNT',
-        'RECORD-LENGTH', 'REFRESH', 'RELEASE', 'RENUM', 'REPEAT', 'REPORT',
-        'REPORT-INPUT', 'RESHOW', 'RESTART', 'RETRIEVE', 'RETURN-CODE',
-        'ROLLBACK', 'ROW', 'S', 'SCREEN', 'SEARCH', 'SECONDARY', 'SELECT',
-        'SEQUENCE', 'SIZE', 'SKIP', 'SOKAKU', 'SORT', 'SQL', 'STOP', 'SUM',
-        'SYSDATE', 'SYSDATE-LONG', 'SYSIN', 'SYSIPT', 'SYSLST', 'SYSPRINT',
-        'SYSSNAP', 'SYSTIME', 'TALLY', 'TERM-COLUMNS', 'TERM-NAME',
-        'TERM-ROWS', 'TERMINATION', 'TITLE', 'TO', 'TRANSFER', 'TRC',
-        'UNIQUE', 'UNTIL', 'UPDATE', 'UPPERCASE', 'USER', 'USERID', 'VALUE',
-        'VERIFY', 'W', 'WHEN', 'WHILE', 'WORK', 'WRITE', 'X', 'XDM', 'XRST'
-    ]
-
-    tokens = {
-        'root': [
-            (r'\*.*\n', Comment.Single),
-            (r'\n+', Whitespace),
-            # Macro argument
-            (r'&' + _NON_DELIMITER_OR_COMMENT_PATTERN + r'+\.', Name.Variable,
-             'after_macro_argument'),
-            # Macro call
-            (r'%' + _NON_DELIMITER_OR_COMMENT_PATTERN + r'+', Name.Variable),
-            (r'(FILE|MACRO|REPORT)(\s+)',
-             bygroups(Keyword.Declaration, Whitespace), 'after_declaration'),
-            (r'(JOB|PARM)' + r'(' + _DELIMITER_PATTERN + r')',
-             bygroups(Keyword.Declaration, Operator)),
-            (words(_KEYWORDS, suffix=_DELIMITER_PATTERN_CAPTURE),
-             bygroups(Keyword.Reserved, Operator)),
-            (_OPERATORS_PATTERN, Operator),
-            # Procedure declaration
-            (r'(' + _NON_DELIMITER_OR_COMMENT_PATTERN + r'+)(\s*)(\.?)(\s*)(PROC)(\s*\n)',
-             bygroups(Name.Function, Whitespace, Operator, Whitespace,
-                      Keyword.Declaration, Whitespace)),
-            (r'[0-9]+\.[0-9]*', Number.Float),
-            (r'[0-9]+', Number.Integer),
-            (r"'(''|[^'])*'", String),
-            (r'\s+', Whitespace),
-            # Everything else just belongs to a name
-            (_NON_DELIMITER_OR_COMMENT_PATTERN + r'+', Name),
-         ],
-        'after_declaration': [
-            (_NON_DELIMITER_OR_COMMENT_PATTERN + r'+', Name.Function),
-            default('#pop'),
-        ],
-        'after_macro_argument': [
-            (r'\*.*\n', Comment.Single, '#pop'),
-            (r'\s+', Whitespace, '#pop'),
-            (_OPERATORS_PATTERN, Operator, '#pop'),
-            (r"'(''|[^'])*'", String, '#pop'),
-            # Everything else just belongs to a name
-            (_NON_DELIMITER_OR_COMMENT_PATTERN + r'+', Name),
-        ],
-    }
-    _COMMENT_LINE_REGEX = re.compile(r'^\s*\*')
-    _MACRO_HEADER_REGEX = re.compile(r'^\s*MACRO')
-
-    def analyse_text(text):
-        """
-        Perform a structural analysis for basic Easytrieve constructs.
-        """
-        result = 0.0
-        lines = text.split('\n')
-        hasEndProc = False
-        hasHeaderComment = False
-        hasFile = False
-        hasJob = False
-        hasProc = False
-        hasParm = False
-        hasReport = False
-
-        def isCommentLine(line):
-            return EasytrieveLexer._COMMENT_LINE_REGEX.match(lines[0]) is not None
-
-        def isEmptyLine(line):
-            return not bool(line.strip())
-
-        # Remove possible empty lines and header comments.
-        while lines and (isEmptyLine(lines[0]) or isCommentLine(lines[0])):
-            if not isEmptyLine(lines[0]):
-                hasHeaderComment = True
-            del lines[0]
-
-        if EasytrieveLexer._MACRO_HEADER_REGEX.match(lines[0]):
-            # Looks like an Easytrieve macro.
-            result = 0.4
-            if hasHeaderComment:
-                result += 0.4
-        else:
-            # Scan the source for lines starting with indicators.
-            for line in lines:
-                words = line.split()
-                if (len(words) >= 2):
-                    firstWord = words[0]
-                    if not hasReport:
-                        if not hasJob:
-                            if not hasFile:
-                                if not hasParm:
-                                    if firstWord == 'PARM':
-                                        hasParm = True
-                                if firstWord == 'FILE':
-                                    hasFile = True
-                            if firstWord == 'JOB':
-                                hasJob = True
-                        elif firstWord == 'PROC':
-                            hasProc = True
-                        elif firstWord == 'END-PROC':
-                            hasEndProc = True
-                        elif firstWord == 'REPORT':
-                            hasReport = True
-
-            # Weight the findings.
-            if hasJob and (hasProc == hasEndProc):
-                if hasHeaderComment:
-                    result += 0.1
-                if hasParm:
-                    if hasProc:
-                        # Found PARM, JOB and PROC/END-PROC:
-                        # pretty sure this is Easytrieve.
-                        result += 0.8
-                    else:
-                        # Found PARAM and  JOB: probably this is Easytrieve
-                        result += 0.5
-                else:
-                    # Found JOB and possibly other keywords: might be Easytrieve
-                    result += 0.11
-                    if hasParm:
-                        # Note: PARAM is not a proper English word, so this is
-                        # regarded a much better indicator for Easytrieve than
-                        # the other words.
-                        result += 0.2
-                    if hasFile:
-                        result += 0.01
-                    if hasReport:
-                        result += 0.01
-        assert 0.0 <= result <= 1.0
-        return result
-
-
-class JclLexer(RegexLexer):
-    """
-    Job Control Language (JCL)
-    is a scripting language used on mainframe platforms to instruct the system
-    on how to run a batch job or start a subsystem. It is somewhat
-    comparable to MS DOS batch and Unix shell scripts.
-    """
-    name = 'JCL'
-    aliases = ['jcl']
-    filenames = ['*.jcl']
-    mimetypes = ['text/x-jcl']
-    url = 'https://en.wikipedia.org/wiki/Job_Control_Language'
-    version_added = '2.1'
-
-    flags = re.IGNORECASE
-
-    tokens = {
-        'root': [
-            (r'//\*.*\n', Comment.Single),
-            (r'//', Keyword.Pseudo, 'statement'),
-            (r'/\*', Keyword.Pseudo, 'jes2_statement'),
-            # TODO: JES3 statement
-            (r'.*\n', Other)  # Input text or inline code in any language.
-        ],
-        'statement': [
-            (r'\s*\n', Whitespace, '#pop'),
-            (r'([a-z]\w*)(\s+)(exec|job)(\s*)',
-             bygroups(Name.Label, Whitespace, Keyword.Reserved, Whitespace),
-             'option'),
-            (r'[a-z]\w*', Name.Variable, 'statement_command'),
-            (r'\s+', Whitespace, 'statement_command'),
-        ],
-        'statement_command': [
-            (r'\s+(command|cntl|dd|endctl|endif|else|include|jcllib|'
-             r'output|pend|proc|set|then|xmit)\s+', Keyword.Reserved, 'option'),
-            include('option')
-        ],
-        'jes2_statement': [
-            (r'\s*\n', Whitespace, '#pop'),
-            (r'\$', Keyword, 'option'),
-            (r'\b(jobparam|message|netacct|notify|output|priority|route|'
-             r'setup|signoff|xeq|xmit)\b', Keyword, 'option'),
-        ],
-        'option': [
-            # (r'\n', Text, 'root'),
-            (r'\*', Name.Builtin),
-            (r'[\[\](){}<>;,]', Punctuation),
-            (r'[-+*/=&%]', Operator),
-            (r'[a-z_]\w*', Name),
-            (r'\d+\.\d*', Number.Float),
-            (r'\.\d+', Number.Float),
-            (r'\d+', Number.Integer),
-            (r"'", String, 'option_string'),
-            (r'[ \t]+', Whitespace, 'option_comment'),
-            (r'\.', Punctuation),
-        ],
-        'option_string': [
-            (r"(\n)(//)", bygroups(Text, Keyword.Pseudo)),
-            (r"''", String),
-            (r"[^']", String),
-            (r"'", String, '#pop'),
-        ],
-        'option_comment': [
-            # (r'\n', Text, 'root'),
-            (r'.+', Comment.Single),
-        ]
-    }
-
-    _JOB_HEADER_PATTERN = re.compile(r'^//[a-z#$@][a-z0-9#$@]{0,7}\s+job(\s+.*)?$',
-                                     re.IGNORECASE)
-
-    def analyse_text(text):
-        """
-        Recognize JCL job by header.
-        """
-        result = 0.0
-        lines = text.split('\n')
-        if len(lines) > 0:
-            if JclLexer._JOB_HEADER_PATTERN.match(lines[0]):
-                result = 1.0
-        assert 0.0 <= result <= 1.0
-        return result
-
-
-class MiniScriptLexer(RegexLexer):
-    """
-    For MiniScript source code.
-    """
-
-    name = 'MiniScript'
-    url = 'https://miniscript.org'
-    aliases = ['miniscript', 'ms']
-    filenames = ['*.ms']
-    mimetypes = ['text/x-minicript', 'application/x-miniscript']
-    version_added = '2.6'
-
-    tokens = {
-        'root': [
-            (r'#!(.*?)$', Comment.Preproc),
-            default('base'),
-        ],
-        'base': [
-            ('//.*$', Comment.Single),
-            (r'(?i)(\d*\.\d+|\d+\.\d*)(e[+-]?\d+)?', Number),
-            (r'(?i)\d+e[+-]?\d+', Number),
-            (r'\d+', Number),
-            (r'\n', Text),
-            (r'[^\S\n]+', Text),
-            (r'"', String, 'string_double'),
-            (r'(==|!=|<=|>=|[=+\-*/%^<>.:])', Operator),
-            (r'[;,\[\]{}()]', Punctuation),
-            (words((
-                'break', 'continue', 'else', 'end', 'for', 'function', 'if',
-                'in', 'isa', 'then', 'repeat', 'return', 'while'), suffix=r'\b'),
-             Keyword),
-            (words((
-                'abs', 'acos', 'asin', 'atan', 'ceil', 'char', 'cos', 'floor',
-                'log', 'round', 'rnd', 'pi', 'sign', 'sin', 'sqrt', 'str', 'tan',
-                'hasIndex', 'indexOf', 'len', 'val', 'code', 'remove', 'lower',
-                'upper', 'replace', 'split', 'indexes', 'values', 'join', 'sum',
-                'sort', 'shuffle', 'push', 'pop', 'pull', 'range',
-                'print', 'input', 'time', 'wait', 'locals', 'globals', 'outer',
-                'yield'), suffix=r'\b'),
-             Name.Builtin),
-            (r'(true|false|null)\b', Keyword.Constant),
-            (r'(and|or|not|new)\b', Operator.Word),
-            (r'(self|super|__isa)\b', Name.Builtin.Pseudo),
-            (r'[a-zA-Z_]\w*', Name.Variable)
-        ],
-        'string_double': [
-            (r'[^"\n]+', String),
-            (r'""', String),
-            (r'"', String, '#pop'),
-            (r'\n', Text, '#pop'),  # Stray linefeed also terminates strings.
-        ]
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/sgf.py b/.venv/lib/python3.12/site-packages/pygments/lexers/sgf.py
deleted file mode 100644
index 6d7c304..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/sgf.py
+++ /dev/null
@@ -1,59 +0,0 @@
-"""
-    pygments.lexers.sgf
-    ~~~~~~~~~~~~~~~~~~~
-
-    Lexer for Smart Game Format (sgf) file format.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-from pygments.lexer import RegexLexer, bygroups
-from pygments.token import Name, Literal, String, Punctuation, Whitespace
-
-__all__ = ["SmartGameFormatLexer"]
-
-
-class SmartGameFormatLexer(RegexLexer):
-    """
-    Lexer for Smart Game Format (sgf) file format.
-
-    The format is used to store game records of board games for two players
-    (mainly Go game).
-    """
-    name = 'SmartGameFormat'
-    url = 'https://www.red-bean.com/sgf/'
-    aliases = ['sgf']
-    filenames = ['*.sgf']
-    version_added = '2.4'
-
-    tokens = {
-        'root': [
-            (r'[():;]+', Punctuation),
-            # tokens:
-            (r'(A[BW]|AE|AN|AP|AR|AS|[BW]L|BM|[BW]R|[BW]S|[BW]T|CA|CH|CP|CR|'
-             r'DD|DM|DO|DT|EL|EV|EX|FF|FG|G[BW]|GC|GM|GN|HA|HO|ID|IP|IT|IY|KM|'
-             r'KO|LB|LN|LT|L|MA|MN|M|N|OB|OM|ON|OP|OT|OV|P[BW]|PC|PL|PM|RE|RG|'
-             r'RO|RU|SO|SC|SE|SI|SL|SO|SQ|ST|SU|SZ|T[BW]|TC|TE|TM|TR|UC|US|VW|'
-             r'V|[BW]|C)',
-             Name.Builtin),
-            # number:
-            (r'(\[)([0-9.]+)(\])',
-             bygroups(Punctuation, Literal.Number, Punctuation)),
-            # date:
-            (r'(\[)([0-9]{4}-[0-9]{2}-[0-9]{2})(\])',
-             bygroups(Punctuation, Literal.Date, Punctuation)),
-            # point:
-            (r'(\[)([a-z]{2})(\])',
-             bygroups(Punctuation, String, Punctuation)),
-            # double points:
-            (r'(\[)([a-z]{2})(:)([a-z]{2})(\])',
-             bygroups(Punctuation, String, Punctuation, String, Punctuation)),
-
-            (r'(\[)([\w\s#()+,\-.:?]+)(\])',
-             bygroups(Punctuation, String, Punctuation)),
-            (r'(\[)(\s.*)(\])',
-             bygroups(Punctuation, Whitespace, Punctuation)),
-            (r'\s+', Whitespace)
-        ],
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/shell.py b/.venv/lib/python3.12/site-packages/pygments/lexers/shell.py
deleted file mode 100644
index c1ce07f..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/shell.py
+++ /dev/null
@@ -1,902 +0,0 @@
-"""
-    pygments.lexers.shell
-    ~~~~~~~~~~~~~~~~~~~~~
-
-    Lexers for various shells.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-import re
-
-from pygments.lexer import Lexer, RegexLexer, do_insertions, bygroups, \
-    include, default, this, using, words, line_re
-from pygments.token import Punctuation, Whitespace, \
-    Text, Comment, Operator, Keyword, Name, String, Number, Generic
-from pygments.util import shebang_matches
-
-__all__ = ['BashLexer', 'BashSessionLexer', 'TcshLexer', 'BatchLexer',
-           'SlurmBashLexer', 'MSDOSSessionLexer', 'PowerShellLexer',
-           'PowerShellSessionLexer', 'TcshSessionLexer', 'FishShellLexer',
-           'ExeclineLexer']
-
-
-class BashLexer(RegexLexer):
-    """
-    Lexer for (ba|k|z|)sh shell scripts.
-    """
-
-    name = 'Bash'
-    aliases = ['bash', 'sh', 'ksh', 'zsh', 'shell', 'openrc']
-    filenames = ['*.sh', '*.ksh', '*.bash', '*.ebuild', '*.eclass',
-                 '*.exheres-0', '*.exlib', '*.zsh',
-                 '.bashrc', 'bashrc', '.bash_*', 'bash_*', 'zshrc', '.zshrc',
-                 '.kshrc', 'kshrc',
-                 'PKGBUILD']
-    mimetypes = ['application/x-sh', 'application/x-shellscript', 'text/x-shellscript']
-    url = 'https://en.wikipedia.org/wiki/Unix_shell'
-    version_added = '0.6'
-
-    tokens = {
-        'root': [
-            include('basic'),
-            (r'`', String.Backtick, 'backticks'),
-            include('data'),
-            include('interp'),
-        ],
-        'interp': [
-            (r'\$\(\(', Keyword, 'math'),
-            (r'\$\(', Keyword, 'paren'),
-            (r'\$\{#?', String.Interpol, 'curly'),
-            (r'\$[a-zA-Z_]\w*', Name.Variable),  # user variable
-            (r'\$(?:\d+|[#$?!_*@-])', Name.Variable),      # builtin
-            (r'\$', Text),
-        ],
-        'basic': [
-            (r'\b(if|fi|else|while|in|do|done|for|then|return|function|case|'
-             r'select|break|continue|until|esac|elif)(\s*)\b',
-             bygroups(Keyword, Whitespace)),
-            (r'\b(alias|bg|bind|builtin|caller|cd|command|compgen|'
-             r'complete|declare|dirs|disown|echo|enable|eval|exec|exit|'
-             r'export|false|fc|fg|getopts|hash|help|history|jobs|kill|let|'
-             r'local|logout|popd|printf|pushd|pwd|read|readonly|set|shift|'
-             r'shopt|source|suspend|test|time|times|trap|true|type|typeset|'
-             r'ulimit|umask|unalias|unset|wait)(?=[\s)`])',
-             Name.Builtin),
-            (r'\A#!.+\n', Comment.Hashbang),
-            (r'#.*\n', Comment.Single),
-            (r'\\[\w\W]', String.Escape),
-            (r'(\b\w+)(\s*)(\+?=)', bygroups(Name.Variable, Whitespace, Operator)),
-            (r'[\[\]{}()=]', Operator),
-            (r'<<<', Operator),  # here-string
-            (r'<<-?\s*(\'?)\\?(\w+)[\w\W]+?\2', String),
-            (r'&&|\|\|', Operator),
-        ],
-        'data': [
-            (r'(?s)\$?"(\\.|[^"\\$])*"', String.Double),
-            (r'"', String.Double, 'string'),
-            (r"(?s)\$'(\\\\|\\[0-7]+|\\.|[^'\\])*'", String.Single),
-            (r"(?s)'.*?'", String.Single),
-            (r';', Punctuation),
-            (r'&', Punctuation),
-            (r'\|', Punctuation),
-            (r'\s+', Whitespace),
-            (r'\d+\b', Number),
-            (r'[^=\s\[\]{}()$"\'`\\<&|;]+', Text),
-            (r'<', Text),
-        ],
-        'string': [
-            (r'"', String.Double, '#pop'),
-            (r'(?s)(\\\\|\\[0-7]+|\\.|[^"\\$])+', String.Double),
-            include('interp'),
-        ],
-        'curly': [
-            (r'\}', String.Interpol, '#pop'),
-            (r':-', Keyword),
-            (r'\w+', Name.Variable),
-            (r'[^}:"\'`$\\]+', Punctuation),
-            (r':', Punctuation),
-            include('root'),
-        ],
-        'paren': [
-            (r'\)', Keyword, '#pop'),
-            include('root'),
-        ],
-        'math': [
-            (r'\)\)', Keyword, '#pop'),
-            (r'\*\*|\|\||<<|>>|[-+*/%^|&<>]', Operator),
-            (r'\d+#[\da-zA-Z]+', Number),
-            (r'\d+#(?! )', Number),
-            (r'0[xX][\da-fA-F]+', Number),
-            (r'\d+', Number),
-            (r'[a-zA-Z_]\w*', Name.Variable),  # user variable
-            include('root'),
-        ],
-        'backticks': [
-            (r'`', String.Backtick, '#pop'),
-            include('root'),
-        ],
-    }
-
-    def analyse_text(text):
-        if shebang_matches(text, r'(ba|z|)sh'):
-            return 1
-        if text.startswith('$ '):
-            return 0.2
-
-
-class SlurmBashLexer(BashLexer):
-    """
-    Lexer for (ba|k|z|)sh Slurm scripts.
-    """
-
-    name = 'Slurm'
-    aliases = ['slurm', 'sbatch']
-    filenames = ['*.sl']
-    mimetypes = []
-    version_added = '2.4'
-    EXTRA_KEYWORDS = {'srun'}
-
-    def get_tokens_unprocessed(self, text):
-        for index, token, value in BashLexer.get_tokens_unprocessed(self, text):
-            if token is Text and value in self.EXTRA_KEYWORDS:
-                yield index, Name.Builtin, value
-            elif token is Comment.Single and 'SBATCH' in value:
-                yield index, Keyword.Pseudo, value
-            else:
-                yield index, token, value
-
-
-class ShellSessionBaseLexer(Lexer):
-    """
-    Base lexer for shell sessions.
-
-    .. versionadded:: 2.1
-    """
-
-    _bare_continuation = False
-    _venv = re.compile(r'^(\([^)]*\))(\s*)')
-
-    def get_tokens_unprocessed(self, text):
-        innerlexer = self._innerLexerCls(**self.options)
-
-        pos = 0
-        curcode = ''
-        insertions = []
-        backslash_continuation = False
-
-        for match in line_re.finditer(text):
-            line = match.group()
-
-            venv_match = self._venv.match(line)
-            if venv_match:
-                venv = venv_match.group(1)
-                venv_whitespace = venv_match.group(2)
-                insertions.append((len(curcode),
-                                   [(0, Generic.Prompt.VirtualEnv, venv)]))
-                if venv_whitespace:
-                    insertions.append((len(curcode),
-                                       [(0, Text, venv_whitespace)]))
-                line = line[venv_match.end():]
-
-            m = self._ps1rgx.match(line)
-            if m:
-                # To support output lexers (say diff output), the output
-                # needs to be broken by prompts whenever the output lexer
-                # changes.
-                if not insertions:
-                    pos = match.start()
-
-                insertions.append((len(curcode),
-                                   [(0, Generic.Prompt, m.group(1))]))
-                curcode += m.group(2)
-                backslash_continuation = curcode.endswith('\\\n')
-            elif backslash_continuation:
-                if line.startswith(self._ps2):
-                    insertions.append((len(curcode),
-                                       [(0, Generic.Prompt,
-                                         line[:len(self._ps2)])]))
-                    curcode += line[len(self._ps2):]
-                else:
-                    curcode += line
-                backslash_continuation = curcode.endswith('\\\n')
-            elif self._bare_continuation and line.startswith(self._ps2):
-                insertions.append((len(curcode),
-                                   [(0, Generic.Prompt,
-                                     line[:len(self._ps2)])]))
-                curcode += line[len(self._ps2):]
-            else:
-                if insertions:
-                    toks = innerlexer.get_tokens_unprocessed(curcode)
-                    for i, t, v in do_insertions(insertions, toks):
-                        yield pos+i, t, v
-                yield match.start(), Generic.Output, line
-                insertions = []
-                curcode = ''
-        if insertions:
-            for i, t, v in do_insertions(insertions,
-                                         innerlexer.get_tokens_unprocessed(curcode)):
-                yield pos+i, t, v
-
-
-class BashSessionLexer(ShellSessionBaseLexer):
-    """
-    Lexer for Bash shell sessions, i.e. command lines, including a
-    prompt, interspersed with output.
-    """
-
-    name = 'Bash Session'
-    aliases = ['console', 'shell-session']
-    filenames = ['*.sh-session', '*.shell-session']
-    mimetypes = ['application/x-shell-session', 'application/x-sh-session']
-    url = 'https://en.wikipedia.org/wiki/Unix_shell'
-    version_added = '1.1'
-    _example = "console/example.sh-session"
-
-    _innerLexerCls = BashLexer
-    _ps1rgx = re.compile(
-        r'^((?:(?:\[.*?\])|(?:\(\S+\))?(?:| |sh\S*?|\w+\S+[@:]\S+(?:\s+\S+)' \
-        r'?|\[\S+[@:][^\n]+\].+))\s*[$#%]\s*)(.*\n?)')
-    _ps2 = '> '
-
-
-class BatchLexer(RegexLexer):
-    """
-    Lexer for the DOS/Windows Batch file format.
-    """
-    name = 'Batchfile'
-    aliases = ['batch', 'bat', 'dosbatch', 'winbatch']
-    filenames = ['*.bat', '*.cmd']
-    mimetypes = ['application/x-dos-batch']
-    url = 'https://en.wikipedia.org/wiki/Batch_file'
-    version_added = '0.7'
-
-    flags = re.MULTILINE | re.IGNORECASE
-
-    _nl = r'\n\x1a'
-    _punct = r'&<>|'
-    _ws = r'\t\v\f\r ,;=\xa0'
-    _nlws = r'\s\x1a\xa0,;='
-    _space = rf'(?:(?:(?:\^[{_nl}])?[{_ws}])+)'
-    _keyword_terminator = (rf'(?=(?:\^[{_nl}]?)?[{_ws}+./:[\\\]]|[{_nl}{_punct}(])')
-    _token_terminator = rf'(?=\^?[{_ws}]|[{_punct}{_nl}])'
-    _start_label = rf'((?:(?<=^[^:])|^[^:]?)[{_ws}]*)(:)'
-    _label = rf'(?:(?:[^{_nlws}{_punct}+:^]|\^[{_nl}]?[\w\W])*)'
-    _label_compound = rf'(?:(?:[^{_nlws}{_punct}+:^)]|\^[{_nl}]?[^)])*)'
-    _number = rf'(?:-?(?:0[0-7]+|0x[\da-f]+|\d+){_token_terminator})'
-    _opword = r'(?:equ|geq|gtr|leq|lss|neq)'
-    _string = rf'(?:"[^{_nl}"]*(?:"|(?=[{_nl}])))'
-    _variable = (r'(?:(?:%(?:\*|(?:~[a-z]*(?:\$[^:]+:)?)?\d|'
-                 rf'[^%:{_nl}]+(?::(?:~(?:-?\d+)?(?:,(?:-?\d+)?)?|(?:[^%{_nl}^]|'
-                 rf'\^[^%{_nl}])[^={_nl}]*=(?:[^%{_nl}^]|\^[^%{_nl}])*)?)?%))|'
-                 rf'(?:\^?![^!:{_nl}]+(?::(?:~(?:-?\d+)?(?:,(?:-?\d+)?)?|(?:'
-                 rf'[^!{_nl}^]|\^[^!{_nl}])[^={_nl}]*=(?:[^!{_nl}^]|\^[^!{_nl}])*)?)?\^?!))')
-    _core_token = rf'(?:(?:(?:\^[{_nl}]?)?[^"{_nlws}{_punct}])+)'
-    _core_token_compound = rf'(?:(?:(?:\^[{_nl}]?)?[^"{_nlws}{_punct})])+)'
-    _token = rf'(?:[{_punct}]+|{_core_token})'
-    _token_compound = rf'(?:[{_punct}]+|{_core_token_compound})'
-    _stoken = (rf'(?:[{_punct}]+|(?:{_string}|{_variable}|{_core_token})+)')
-
-    def _make_begin_state(compound, _core_token=_core_token,
-                          _core_token_compound=_core_token_compound,
-                          _keyword_terminator=_keyword_terminator,
-                          _nl=_nl, _punct=_punct, _string=_string,
-                          _space=_space, _start_label=_start_label,
-                          _stoken=_stoken, _token_terminator=_token_terminator,
-                          _variable=_variable, _ws=_ws):
-        rest = '(?:{}|{}|[^"%{}{}{}])*'.format(_string, _variable, _nl, _punct,
-                                            ')' if compound else '')
-        rest_of_line = rf'(?:(?:[^{_nl}^]|\^[{_nl}]?[\w\W])*)'
-        rest_of_line_compound = rf'(?:(?:[^{_nl}^)]|\^[{_nl}]?[^)])*)'
-        set_space = rf'((?:(?:\^[{_nl}]?)?[^\S\n])*)'
-        suffix = ''
-        if compound:
-            _keyword_terminator = rf'(?:(?=\))|{_keyword_terminator})'
-            _token_terminator = rf'(?:(?=\))|{_token_terminator})'
-            suffix = '/compound'
-        return [
-            ((r'\)', Punctuation, '#pop') if compound else
-             (rf'\)((?=\()|{_token_terminator}){rest_of_line}',
-              Comment.Single)),
-            (rf'(?={_start_label})', Text, f'follow{suffix}'),
-            (_space, using(this, state='text')),
-            include(f'redirect{suffix}'),
-            (rf'[{_nl}]+', Text),
-            (r'\(', Punctuation, 'root/compound'),
-            (r'@+', Punctuation),
-            (rf'((?:for|if|rem)(?:(?=(?:\^[{_nl}]?)?/)|(?:(?!\^)|'
-             rf'(?<=m))(?:(?=\()|{_token_terminator})))({_space}?{_core_token_compound if compound else _core_token}?(?:\^[{_nl}]?)?/(?:\^[{_nl}]?)?\?)',
-             bygroups(Keyword, using(this, state='text')),
-             f'follow{suffix}'),
-            (rf'(goto{_keyword_terminator})({rest}(?:\^[{_nl}]?)?/(?:\^[{_nl}]?)?\?{rest})',
-             bygroups(Keyword, using(this, state='text')),
-             f'follow{suffix}'),
-            (words(('assoc', 'break', 'cd', 'chdir', 'cls', 'color', 'copy',
-                    'date', 'del', 'dir', 'dpath', 'echo', 'endlocal', 'erase',
-                    'exit', 'ftype', 'keys', 'md', 'mkdir', 'mklink', 'move',
-                    'path', 'pause', 'popd', 'prompt', 'pushd', 'rd', 'ren',
-                    'rename', 'rmdir', 'setlocal', 'shift', 'start', 'time',
-                    'title', 'type', 'ver', 'verify', 'vol'),
-                   suffix=_keyword_terminator), Keyword, f'follow{suffix}'),
-            (rf'(call)({_space}?)(:)',
-             bygroups(Keyword, using(this, state='text'), Punctuation),
-             f'call{suffix}'),
-            (rf'call{_keyword_terminator}', Keyword),
-            (rf'(for{_token_terminator}(?!\^))({_space})(/f{_token_terminator})',
-             bygroups(Keyword, using(this, state='text'), Keyword),
-             ('for/f', 'for')),
-            (rf'(for{_token_terminator}(?!\^))({_space})(/l{_token_terminator})',
-             bygroups(Keyword, using(this, state='text'), Keyword),
-             ('for/l', 'for')),
-            (rf'for{_token_terminator}(?!\^)', Keyword, ('for2', 'for')),
-            (rf'(goto{_keyword_terminator})({_space}?)(:?)',
-             bygroups(Keyword, using(this, state='text'), Punctuation),
-             f'label{suffix}'),
-            (rf'(if(?:(?=\()|{_token_terminator})(?!\^))({_space}?)((?:/i{_token_terminator})?)({_space}?)((?:not{_token_terminator})?)({_space}?)',
-             bygroups(Keyword, using(this, state='text'), Keyword,
-                      using(this, state='text'), Keyword,
-                      using(this, state='text')), ('(?', 'if')),
-            (rf'rem(((?=\()|{_token_terminator}){_space}?{_stoken}?.*|{_keyword_terminator}{rest_of_line_compound if compound else rest_of_line})',
-             Comment.Single, f'follow{suffix}'),
-            (rf'(set{_keyword_terminator}){set_space}(/a)',
-             bygroups(Keyword, using(this, state='text'), Keyword),
-             f'arithmetic{suffix}'),
-            (r'(set{}){}((?:/p)?){}((?:(?:(?:\^[{}]?)?[^"{}{}^={}]|'
-             r'\^[{}]?[^"=])+)?)((?:(?:\^[{}]?)?=)?)'.format(_keyword_terminator, set_space, set_space, _nl, _nl, _punct,
-              ')' if compound else '', _nl, _nl),
-             bygroups(Keyword, using(this, state='text'), Keyword,
-                      using(this, state='text'), using(this, state='variable'),
-                      Punctuation),
-             f'follow{suffix}'),
-            default(f'follow{suffix}')
-        ]
-
-    def _make_follow_state(compound, _label=_label,
-                           _label_compound=_label_compound, _nl=_nl,
-                           _space=_space, _start_label=_start_label,
-                           _token=_token, _token_compound=_token_compound,
-                           _ws=_ws):
-        suffix = '/compound' if compound else ''
-        state = []
-        if compound:
-            state.append((r'(?=\))', Text, '#pop'))
-        state += [
-            (rf'{_start_label}([{_ws}]*)({_label_compound if compound else _label})(.*)',
-             bygroups(Text, Punctuation, Text, Name.Label, Comment.Single)),
-            include(f'redirect{suffix}'),
-            (rf'(?=[{_nl}])', Text, '#pop'),
-            (r'\|\|?|&&?', Punctuation, '#pop'),
-            include('text')
-        ]
-        return state
-
-    def _make_arithmetic_state(compound, _nl=_nl, _punct=_punct,
-                               _string=_string, _variable=_variable,
-                               _ws=_ws, _nlws=_nlws):
-        op = r'=+\-*/!~'
-        state = []
-        if compound:
-            state.append((r'(?=\))', Text, '#pop'))
-        state += [
-            (r'0[0-7]+', Number.Oct),
-            (r'0x[\da-f]+', Number.Hex),
-            (r'\d+', Number.Integer),
-            (r'[(),]+', Punctuation),
-            (rf'([{op}]|%|\^\^)+', Operator),
-            (r'({}|{}|(\^[{}]?)?[^(){}%\^"{}{}]|\^[{}]?{})+'.format(_string, _variable, _nl, op, _nlws, _punct, _nlws,
-              r'[^)]' if compound else r'[\w\W]'),
-             using(this, state='variable')),
-            (r'(?=[\x00|&])', Text, '#pop'),
-            include('follow')
-        ]
-        return state
-
-    def _make_call_state(compound, _label=_label,
-                         _label_compound=_label_compound):
-        state = []
-        if compound:
-            state.append((r'(?=\))', Text, '#pop'))
-        state.append((r'(:?)(%s)' % (_label_compound if compound else _label),
-                      bygroups(Punctuation, Name.Label), '#pop'))
-        return state
-
-    def _make_label_state(compound, _label=_label,
-                          _label_compound=_label_compound, _nl=_nl,
-                          _punct=_punct, _string=_string, _variable=_variable):
-        state = []
-        if compound:
-            state.append((r'(?=\))', Text, '#pop'))
-        state.append((r'({}?)((?:{}|{}|\^[{}]?{}|[^"%^{}{}{}])*)'.format(_label_compound if compound else _label, _string,
-                       _variable, _nl, r'[^)]' if compound else r'[\w\W]', _nl,
-                       _punct, r')' if compound else ''),
-                      bygroups(Name.Label, Comment.Single), '#pop'))
-        return state
-
-    def _make_redirect_state(compound,
-                             _core_token_compound=_core_token_compound,
-                             _nl=_nl, _punct=_punct, _stoken=_stoken,
-                             _string=_string, _space=_space,
-                             _variable=_variable, _nlws=_nlws):
-        stoken_compound = (rf'(?:[{_punct}]+|(?:{_string}|{_variable}|{_core_token_compound})+)')
-        return [
-            (rf'((?:(?<=[{_nlws}])\d)?)(>>?&|<&)([{_nlws}]*)(\d)',
-             bygroups(Number.Integer, Punctuation, Text, Number.Integer)),
-            (rf'((?:(?<=[{_nlws}])(?>?|<)({_space}?{stoken_compound if compound else _stoken})',
-             bygroups(Number.Integer, Punctuation, using(this, state='text')))
-        ]
-
-    tokens = {
-        'root': _make_begin_state(False),
-        'follow': _make_follow_state(False),
-        'arithmetic': _make_arithmetic_state(False),
-        'call': _make_call_state(False),
-        'label': _make_label_state(False),
-        'redirect': _make_redirect_state(False),
-        'root/compound': _make_begin_state(True),
-        'follow/compound': _make_follow_state(True),
-        'arithmetic/compound': _make_arithmetic_state(True),
-        'call/compound': _make_call_state(True),
-        'label/compound': _make_label_state(True),
-        'redirect/compound': _make_redirect_state(True),
-        'variable-or-escape': [
-            (_variable, Name.Variable),
-            (rf'%%|\^[{_nl}]?(\^!|[\w\W])', String.Escape)
-        ],
-        'string': [
-            (r'"', String.Double, '#pop'),
-            (_variable, Name.Variable),
-            (r'\^!|%%', String.Escape),
-            (rf'[^"%^{_nl}]+|[%^]', String.Double),
-            default('#pop')
-        ],
-        'sqstring': [
-            include('variable-or-escape'),
-            (r'[^%]+|%', String.Single)
-        ],
-        'bqstring': [
-            include('variable-or-escape'),
-            (r'[^%]+|%', String.Backtick)
-        ],
-        'text': [
-            (r'"', String.Double, 'string'),
-            include('variable-or-escape'),
-            (rf'[^"%^{_nlws}{_punct}\d)]+|.', Text)
-        ],
-        'variable': [
-            (r'"', String.Double, 'string'),
-            include('variable-or-escape'),
-            (rf'[^"%^{_nl}]+|.', Name.Variable)
-        ],
-        'for': [
-            (rf'({_space})(in)({_space})(\()',
-             bygroups(using(this, state='text'), Keyword,
-                      using(this, state='text'), Punctuation), '#pop'),
-            include('follow')
-        ],
-        'for2': [
-            (r'\)', Punctuation),
-            (rf'({_space})(do{_token_terminator})',
-             bygroups(using(this, state='text'), Keyword), '#pop'),
-            (rf'[{_nl}]+', Text),
-            include('follow')
-        ],
-        'for/f': [
-            (rf'(")((?:{_variable}|[^"])*?")([{_nlws}]*)(\))',
-             bygroups(String.Double, using(this, state='string'), Text,
-                      Punctuation)),
-            (r'"', String.Double, ('#pop', 'for2', 'string')),
-            (rf"('(?:%%|{_variable}|[\w\W])*?')([{_nlws}]*)(\))",
-             bygroups(using(this, state='sqstring'), Text, Punctuation)),
-            (rf'(`(?:%%|{_variable}|[\w\W])*?`)([{_nlws}]*)(\))',
-             bygroups(using(this, state='bqstring'), Text, Punctuation)),
-            include('for2')
-        ],
-        'for/l': [
-            (r'-?\d+', Number.Integer),
-            include('for2')
-        ],
-        'if': [
-            (rf'((?:cmdextversion|errorlevel){_token_terminator})({_space})(\d+)',
-             bygroups(Keyword, using(this, state='text'),
-                      Number.Integer), '#pop'),
-            (rf'(defined{_token_terminator})({_space})({_stoken})',
-             bygroups(Keyword, using(this, state='text'),
-                      using(this, state='variable')), '#pop'),
-            (rf'(exist{_token_terminator})({_space}{_stoken})',
-             bygroups(Keyword, using(this, state='text')), '#pop'),
-            (rf'({_number}{_space})({_opword})({_space}{_number})',
-             bygroups(using(this, state='arithmetic'), Operator.Word,
-                      using(this, state='arithmetic')), '#pop'),
-            (_stoken, using(this, state='text'), ('#pop', 'if2')),
-        ],
-        'if2': [
-            (rf'({_space}?)(==)({_space}?{_stoken})',
-             bygroups(using(this, state='text'), Operator,
-                      using(this, state='text')), '#pop'),
-            (rf'({_space})({_opword})({_space}{_stoken})',
-             bygroups(using(this, state='text'), Operator.Word,
-                      using(this, state='text')), '#pop')
-        ],
-        '(?': [
-            (_space, using(this, state='text')),
-            (r'\(', Punctuation, ('#pop', 'else?', 'root/compound')),
-            default('#pop')
-        ],
-        'else?': [
-            (_space, using(this, state='text')),
-            (rf'else{_token_terminator}', Keyword, '#pop'),
-            default('#pop')
-        ]
-    }
-
-
-class MSDOSSessionLexer(ShellSessionBaseLexer):
-    """
-    Lexer for MS DOS shell sessions, i.e. command lines, including a
-    prompt, interspersed with output.
-    """
-
-    name = 'MSDOS Session'
-    aliases = ['doscon']
-    filenames = []
-    mimetypes = []
-    url = 'https://en.wikipedia.org/wiki/MS-DOS'
-    version_added = '2.1'
-    _example = "doscon/session"
-
-    _innerLexerCls = BatchLexer
-    _ps1rgx = re.compile(r'^([^>]*>)(.*\n?)')
-    _ps2 = 'More? '
-
-
-class TcshLexer(RegexLexer):
-    """
-    Lexer for tcsh scripts.
-    """
-
-    name = 'Tcsh'
-    aliases = ['tcsh', 'csh']
-    filenames = ['*.tcsh', '*.csh']
-    mimetypes = ['application/x-csh']
-    url = 'https://www.tcsh.org'
-    version_added = '0.10'
-
-    tokens = {
-        'root': [
-            include('basic'),
-            (r'\$\(', Keyword, 'paren'),
-            (r'\$\{#?', Keyword, 'curly'),
-            (r'`', String.Backtick, 'backticks'),
-            include('data'),
-        ],
-        'basic': [
-            (r'\b(if|endif|else|while|then|foreach|case|default|'
-             r'break|continue|goto|breaksw|end|switch|endsw)\s*\b',
-             Keyword),
-            (r'\b(alias|alloc|bg|bindkey|builtins|bye|caller|cd|chdir|'
-             r'complete|dirs|echo|echotc|eval|exec|exit|fg|filetest|getxvers|'
-             r'glob|getspath|hashstat|history|hup|inlib|jobs|kill|'
-             r'limit|log|login|logout|ls-F|migrate|newgrp|nice|nohup|notify|'
-             r'onintr|popd|printenv|pushd|rehash|repeat|rootnode|popd|pushd|'
-             r'set|shift|sched|setenv|setpath|settc|setty|setxvers|shift|'
-             r'source|stop|suspend|source|suspend|telltc|time|'
-             r'umask|unalias|uncomplete|unhash|universe|unlimit|unset|unsetenv|'
-             r'ver|wait|warp|watchlog|where|which)\s*\b',
-             Name.Builtin),
-            (r'#.*', Comment),
-            (r'\\[\w\W]', String.Escape),
-            (r'(\b\w+)(\s*)(=)', bygroups(Name.Variable, Text, Operator)),
-            (r'[\[\]{}()=]+', Operator),
-            (r'<<\s*(\'?)\\?(\w+)[\w\W]+?\2', String),
-            (r';', Punctuation),
-        ],
-        'data': [
-            (r'(?s)"(\\\\|\\[0-7]+|\\.|[^"\\])*"', String.Double),
-            (r"(?s)'(\\\\|\\[0-7]+|\\.|[^'\\])*'", String.Single),
-            (r'\s+', Text),
-            (r'[^=\s\[\]{}()$"\'`\\;#]+', Text),
-            (r'\d+(?= |\Z)', Number),
-            (r'\$#?(\w+|.)', Name.Variable),
-        ],
-        'curly': [
-            (r'\}', Keyword, '#pop'),
-            (r':-', Keyword),
-            (r'\w+', Name.Variable),
-            (r'[^}:"\'`$]+', Punctuation),
-            (r':', Punctuation),
-            include('root'),
-        ],
-        'paren': [
-            (r'\)', Keyword, '#pop'),
-            include('root'),
-        ],
-        'backticks': [
-            (r'`', String.Backtick, '#pop'),
-            include('root'),
-        ],
-    }
-
-
-class TcshSessionLexer(ShellSessionBaseLexer):
-    """
-    Lexer for Tcsh sessions, i.e. command lines, including a
-    prompt, interspersed with output.
-    """
-
-    name = 'Tcsh Session'
-    aliases = ['tcshcon']
-    filenames = []
-    mimetypes = []
-    url = 'https://www.tcsh.org'
-    version_added = '2.1'
-    _example = "tcshcon/session"
-
-    _innerLexerCls = TcshLexer
-    _ps1rgx = re.compile(r'^([^>]+>)(.*\n?)')
-    _ps2 = '? '
-
-
-class PowerShellLexer(RegexLexer):
-    """
-    For Windows PowerShell code.
-    """
-    name = 'PowerShell'
-    aliases = ['powershell', 'pwsh', 'posh', 'ps1', 'psm1']
-    filenames = ['*.ps1', '*.psm1']
-    mimetypes = ['text/x-powershell']
-    url = 'https://learn.microsoft.com/en-us/powershell'
-    version_added = '1.5'
-
-    flags = re.DOTALL | re.IGNORECASE | re.MULTILINE
-
-    keywords = (
-        'while validateset validaterange validatepattern validatelength '
-        'validatecount until trap switch return ref process param parameter in '
-        'if global: local: function foreach for finally filter end elseif else '
-        'dynamicparam do default continue cmdletbinding break begin alias \\? '
-        '% #script #private #local #global mandatory parametersetname position '
-        'valuefrompipeline valuefrompipelinebypropertyname '
-        'valuefromremainingarguments helpmessage try catch throw').split()
-
-    operators = (
-        'and as band bnot bor bxor casesensitive ccontains ceq cge cgt cle '
-        'clike clt cmatch cne cnotcontains cnotlike cnotmatch contains '
-        'creplace eq exact f file ge gt icontains ieq ige igt ile ilike ilt '
-        'imatch ine inotcontains inotlike inotmatch ireplace is isnot le like '
-        'lt match ne not notcontains notlike notmatch or regex replace '
-        'wildcard').split()
-
-    verbs = (
-        'write where watch wait use update unregister unpublish unprotect '
-        'unlock uninstall undo unblock trace test tee take sync switch '
-        'suspend submit stop step start split sort skip show set send select '
-        'search scroll save revoke resume restore restart resolve resize '
-        'reset request repair rename remove register redo receive read push '
-        'publish protect pop ping out optimize open new move mount merge '
-        'measure lock limit join invoke install initialize import hide group '
-        'grant get format foreach find export expand exit enter enable edit '
-        'dismount disconnect disable deny debug cxnew copy convertto '
-        'convertfrom convert connect confirm compress complete compare close '
-        'clear checkpoint block backup assert approve aggregate add').split()
-
-    aliases_ = (
-        'ac asnp cat cd cfs chdir clc clear clhy cli clp cls clv cnsn '
-        'compare copy cp cpi cpp curl cvpa dbp del diff dir dnsn ebp echo epal '
-        'epcsv epsn erase etsn exsn fc fhx fl foreach ft fw gal gbp gc gci gcm '
-        'gcs gdr ghy gi gjb gl gm gmo gp gps gpv group gsn gsnp gsv gu gv gwmi '
-        'h history icm iex ihy ii ipal ipcsv ipmo ipsn irm ise iwmi iwr kill lp '
-        'ls man md measure mi mount move mp mv nal ndr ni nmo npssc nsn nv ogv '
-        'oh popd ps pushd pwd r rbp rcjb rcsn rd rdr ren ri rjb rm rmdir rmo '
-        'rni rnp rp rsn rsnp rujb rv rvpa rwmi sajb sal saps sasv sbp sc select '
-        'set shcm si sl sleep sls sort sp spjb spps spsv start sujb sv swmi tee '
-        'trcm type wget where wjb write').split()
-
-    commenthelp = (
-        'component description example externalhelp forwardhelpcategory '
-        'forwardhelptargetname functionality inputs link '
-        'notes outputs parameter remotehelprunspace role synopsis').split()
-
-    tokens = {
-        'root': [
-            # we need to count pairs of parentheses for correct highlight
-            # of '$(...)' blocks in strings
-            (r'\(', Punctuation, 'child'),
-            (r'\s+', Text),
-            (r'^(\s*#[#\s]*)(\.(?:{}))([^\n]*$)'.format('|'.join(commenthelp)),
-             bygroups(Comment, String.Doc, Comment)),
-            (r'#[^\n]*?$', Comment),
-            (r'(<|<)#', Comment.Multiline, 'multline'),
-            (r'@"\n', String.Heredoc, 'heredoc-double'),
-            (r"@'\n.*?\n'@", String.Heredoc),
-            # escaped syntax
-            (r'`[\'"$@-]', Punctuation),
-            (r'"', String.Double, 'string'),
-            (r"'([^']|'')*'", String.Single),
-            (r'(\$|@@|@)((global|script|private|env):)?\w+',
-             Name.Variable),
-            (r'({})\b'.format('|'.join(keywords)), Keyword),
-            (r'-({})\b'.format('|'.join(operators)), Operator),
-            (r'({})-[a-z_]\w*\b'.format('|'.join(verbs)), Name.Builtin),
-            (r'({})\s'.format('|'.join(aliases_)), Name.Builtin),
-            (r'\[[a-z_\[][\w. `,\[\]]*\]', Name.Constant),  # .net [type]s
-            (r'-[a-z_]\w*', Name),
-            (r'\w+', Name),
-            (r'[.,;:@{}\[\]$()=+*/\\&%!~?^`|<>-]', Punctuation),
-        ],
-        'child': [
-            (r'\)', Punctuation, '#pop'),
-            include('root'),
-        ],
-        'multline': [
-            (r'[^#&.]+', Comment.Multiline),
-            (r'#(>|>)', Comment.Multiline, '#pop'),
-            (r'\.({})'.format('|'.join(commenthelp)), String.Doc),
-            (r'[#&.]', Comment.Multiline),
-        ],
-        'string': [
-            (r"`[0abfnrtv'\"$`]", String.Escape),
-            (r'[^$`"]+', String.Double),
-            (r'\$\(', Punctuation, 'child'),
-            (r'""', String.Double),
-            (r'[`$]', String.Double),
-            (r'"', String.Double, '#pop'),
-        ],
-        'heredoc-double': [
-            (r'\n"@', String.Heredoc, '#pop'),
-            (r'\$\(', Punctuation, 'child'),
-            (r'[^@\n]+"]', String.Heredoc),
-            (r".", String.Heredoc),
-        ]
-    }
-
-
-class PowerShellSessionLexer(ShellSessionBaseLexer):
-    """
-    Lexer for PowerShell sessions, i.e. command lines, including a
-    prompt, interspersed with output.
-    """
-
-    name = 'PowerShell Session'
-    aliases = ['pwsh-session', 'ps1con']
-    filenames = []
-    mimetypes = []
-    url = 'https://learn.microsoft.com/en-us/powershell'
-    version_added = '2.1'
-    _example = "pwsh-session/session"
-
-    _innerLexerCls = PowerShellLexer
-    _bare_continuation = True
-    _ps1rgx = re.compile(r'^((?:\[[^]]+\]: )?PS[^>]*> ?)(.*\n?)')
-    _ps2 = '> '
-
-
-class FishShellLexer(RegexLexer):
-    """
-    Lexer for Fish shell scripts.
-    """
-
-    name = 'Fish'
-    aliases = ['fish', 'fishshell']
-    filenames = ['*.fish', '*.load']
-    mimetypes = ['application/x-fish']
-    url = 'https://fishshell.com'
-    version_added = '2.1'
-
-    tokens = {
-        'root': [
-            include('basic'),
-            include('data'),
-            include('interp'),
-        ],
-        'interp': [
-            (r'\$\(\(', Keyword, 'math'),
-            (r'\(', Keyword, 'paren'),
-            (r'\$#?(\w+|.)', Name.Variable),
-        ],
-        'basic': [
-            (r'\b(begin|end|if|else|while|break|for|in|return|function|block|'
-             r'case|continue|switch|not|and|or|set|echo|exit|pwd|true|false|'
-             r'cd|count|test)(\s*)\b',
-             bygroups(Keyword, Text)),
-            (r'\b(alias|bg|bind|breakpoint|builtin|command|commandline|'
-             r'complete|contains|dirh|dirs|emit|eval|exec|fg|fish|fish_config|'
-             r'fish_indent|fish_pager|fish_prompt|fish_right_prompt|'
-             r'fish_update_completions|fishd|funced|funcsave|functions|help|'
-             r'history|isatty|jobs|math|mimedb|nextd|open|popd|prevd|psub|'
-             r'pushd|random|read|set_color|source|status|trap|type|ulimit|'
-             r'umask|vared|fc|getopts|hash|kill|printf|time|wait)\s*\b(?!\.)',
-             Name.Builtin),
-            (r'#.*\n', Comment),
-            (r'\\[\w\W]', String.Escape),
-            (r'(\b\w+)(\s*)(=)', bygroups(Name.Variable, Whitespace, Operator)),
-            (r'[\[\]()=]', Operator),
-            (r'<<-?\s*(\'?)\\?(\w+)[\w\W]+?\2', String),
-        ],
-        'data': [
-            (r'(?s)\$?"(\\\\|\\[0-7]+|\\.|[^"\\$])*"', String.Double),
-            (r'"', String.Double, 'string'),
-            (r"(?s)\$'(\\\\|\\[0-7]+|\\.|[^'\\])*'", String.Single),
-            (r"(?s)'.*?'", String.Single),
-            (r';', Punctuation),
-            (r'&|\||\^|<|>', Operator),
-            (r'\s+', Text),
-            (r'\d+(?= |\Z)', Number),
-            (r'[^=\s\[\]{}()$"\'`\\<&|;]+', Text),
-        ],
-        'string': [
-            (r'"', String.Double, '#pop'),
-            (r'(?s)(\\\\|\\[0-7]+|\\.|[^"\\$])+', String.Double),
-            include('interp'),
-        ],
-        'paren': [
-            (r'\)', Keyword, '#pop'),
-            include('root'),
-        ],
-        'math': [
-            (r'\)\)', Keyword, '#pop'),
-            (r'[-+*/%^|&]|\*\*|\|\|', Operator),
-            (r'\d+#\d+', Number),
-            (r'\d+#(?! )', Number),
-            (r'\d+', Number),
-            include('root'),
-        ],
-    }
-
-class ExeclineLexer(RegexLexer):
-    """
-    Lexer for Laurent Bercot's execline language.
-    """
-
-    name = 'execline'
-    aliases = ['execline']
-    filenames = ['*.exec']
-    url = 'https://skarnet.org/software/execline'
-    version_added = '2.7'
-
-    tokens = {
-        'root': [
-            include('basic'),
-            include('data'),
-            include('interp')
-        ],
-        'interp': [
-            (r'\$\{', String.Interpol, 'curly'),
-            (r'\$[\w@#]+', Name.Variable),  # user variable
-            (r'\$', Text),
-        ],
-        'basic': [
-            (r'\b(background|backtick|cd|define|dollarat|elgetopt|'
-             r'elgetpositionals|elglob|emptyenv|envfile|exec|execlineb|'
-             r'exit|export|fdblock|fdclose|fdmove|fdreserve|fdswap|'
-             r'forbacktickx|foreground|forstdin|forx|getcwd|getpid|heredoc|'
-             r'homeof|if|ifelse|ifte|ifthenelse|importas|loopwhilex|'
-             r'multidefine|multisubstitute|pipeline|piperw|posix-cd|'
-             r'redirfd|runblock|shift|trap|tryexec|umask|unexport|wait|'
-             r'withstdinas)\b', Name.Builtin),
-            (r'\A#!.+\n', Comment.Hashbang),
-            (r'#.*\n', Comment.Single),
-            (r'[{}]', Operator)
-        ],
-        'data': [
-            (r'(?s)"(\\.|[^"\\$])*"', String.Double),
-            (r'"', String.Double, 'string'),
-            (r'\s+', Text),
-            (r'[^\s{}$"\\]+', Text)
-        ],
-        'string': [
-            (r'"', String.Double, '#pop'),
-            (r'(?s)(\\\\|\\.|[^"\\$])+', String.Double),
-            include('interp'),
-        ],
-        'curly': [
-            (r'\}', String.Interpol, '#pop'),
-            (r'[\w#@]+', Name.Variable),
-            include('root')
-        ]
-
-    }
-
-    def analyse_text(text):
-        if shebang_matches(text, r'execlineb'):
-            return 1
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/sieve.py b/.venv/lib/python3.12/site-packages/pygments/lexers/sieve.py
deleted file mode 100644
index 4bda351..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/sieve.py
+++ /dev/null
@@ -1,78 +0,0 @@
-"""
-    pygments.lexers.sieve
-    ~~~~~~~~~~~~~~~~~~~~~
-
-    Lexer for Sieve file format.
-
-    https://tools.ietf.org/html/rfc5228
-    https://tools.ietf.org/html/rfc5173
-    https://tools.ietf.org/html/rfc5229
-    https://tools.ietf.org/html/rfc5230
-    https://tools.ietf.org/html/rfc5232
-    https://tools.ietf.org/html/rfc5235
-    https://tools.ietf.org/html/rfc5429
-    https://tools.ietf.org/html/rfc8580
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-from pygments.lexer import RegexLexer, bygroups
-from pygments.token import Comment, Name, Literal, String, Text, Punctuation, \
-    Keyword
-
-__all__ = ["SieveLexer"]
-
-
-class SieveLexer(RegexLexer):
-    """
-    Lexer for sieve format.
-    """
-    name = 'Sieve'
-    filenames = ['*.siv', '*.sieve']
-    aliases = ['sieve']
-    url = 'https://en.wikipedia.org/wiki/Sieve_(mail_filtering_language)'
-    version_added = '2.6'
-
-    tokens = {
-        'root': [
-            (r'\s+', Text),
-            (r'[();,{}\[\]]', Punctuation),
-            # import:
-            (r'(?i)require',
-             Keyword.Namespace),
-            # tags:
-            (r'(?i)(:)(addresses|all|contains|content|create|copy|comparator|'
-             r'count|days|detail|domain|fcc|flags|from|handle|importance|is|'
-             r'localpart|length|lowerfirst|lower|matches|message|mime|options|'
-             r'over|percent|quotewildcard|raw|regex|specialuse|subject|text|'
-             r'under|upperfirst|upper|value)',
-             bygroups(Name.Tag, Name.Tag)),
-            # tokens:
-            (r'(?i)(address|addflag|allof|anyof|body|discard|elsif|else|envelope|'
-             r'ereject|exists|false|fileinto|if|hasflag|header|keep|'
-             r'notify_method_capability|notify|not|redirect|reject|removeflag|'
-             r'setflag|size|spamtest|stop|string|true|vacation|virustest)',
-             Name.Builtin),
-            (r'(?i)set',
-             Keyword.Declaration),
-            # number:
-            (r'([0-9.]+)([kmgKMG])?',
-             bygroups(Literal.Number, Literal.Number)),
-            # comment:
-            (r'#.*$',
-             Comment.Single),
-            (r'/\*.*\*/',
-             Comment.Multiline),
-            # string:
-            (r'"[^"]*?"',
-             String),
-            # text block:
-            (r'text:',
-             Name.Tag, 'text'),
-        ],
-        'text': [
-            (r'[^.].*?\n', String),
-            (r'^\.', Punctuation, "#pop"),
-        ]
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/slash.py b/.venv/lib/python3.12/site-packages/pygments/lexers/slash.py
deleted file mode 100644
index 2bcbdf8..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/slash.py
+++ /dev/null
@@ -1,183 +0,0 @@
-"""
-    pygments.lexers.slash
-    ~~~~~~~~~~~~~~~~~~~~~
-
-    Lexer for the Slash programming language.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-from pygments.lexer import ExtendedRegexLexer, bygroups, DelegatingLexer
-from pygments.token import Name, Number, String, Comment, Punctuation, \
-    Other, Keyword, Operator, Whitespace
-
-__all__ = ['SlashLexer']
-
-
-class SlashLanguageLexer(ExtendedRegexLexer):
-    _nkw = r'(?=[^a-zA-Z_0-9])'
-
-    def move_state(new_state):
-        return ("#pop", new_state)
-
-    def right_angle_bracket(lexer, match, ctx):
-        if len(ctx.stack) > 1 and ctx.stack[-2] == "string":
-            ctx.stack.pop()
-        yield match.start(), String.Interpol, '}'
-        ctx.pos = match.end()
-        pass
-
-    tokens = {
-        "root": [
-            (r"<%=",        Comment.Preproc,    move_state("slash")),
-            (r"<%!!",       Comment.Preproc,    move_state("slash")),
-            (r"<%#.*?%>",   Comment.Multiline),
-            (r"<%",         Comment.Preproc,    move_state("slash")),
-            (r".|\n",       Other),
-        ],
-        "string": [
-            (r"\\",         String.Escape,      move_state("string_e")),
-            (r"\"",         String,             move_state("slash")),
-            (r"#\{",        String.Interpol,    "slash"),
-            (r'.|\n',       String),
-        ],
-        "string_e": [
-            (r'n',                  String.Escape,      move_state("string")),
-            (r't',                  String.Escape,      move_state("string")),
-            (r'r',                  String.Escape,      move_state("string")),
-            (r'e',                  String.Escape,      move_state("string")),
-            (r'x[a-fA-F0-9]{2}',    String.Escape,      move_state("string")),
-            (r'.',                  String.Escape,      move_state("string")),
-        ],
-        "regexp": [
-            (r'}[a-z]*',            String.Regex,       move_state("slash")),
-            (r'\\(.|\n)',           String.Regex),
-            (r'{',                  String.Regex,       "regexp_r"),
-            (r'.|\n',               String.Regex),
-        ],
-        "regexp_r": [
-            (r'}[a-z]*',            String.Regex,       "#pop"),
-            (r'\\(.|\n)',           String.Regex),
-            (r'{',                  String.Regex,       "regexp_r"),
-        ],
-        "slash": [
-            (r"%>",                     Comment.Preproc,    move_state("root")),
-            (r"\"",                     String,             move_state("string")),
-            (r"'[a-zA-Z0-9_]+",         String),
-            (r'%r{',                    String.Regex,       move_state("regexp")),
-            (r'/\*.*?\*/',              Comment.Multiline),
-            (r"(#|//).*?\n",            Comment.Single),
-            (r'-?[0-9]+e[+-]?[0-9]+',   Number.Float),
-            (r'-?[0-9]+\.[0-9]+(e[+-]?[0-9]+)?', Number.Float),
-            (r'-?[0-9]+',               Number.Integer),
-            (r'nil'+_nkw,               Name.Builtin),
-            (r'true'+_nkw,              Name.Builtin),
-            (r'false'+_nkw,             Name.Builtin),
-            (r'self'+_nkw,              Name.Builtin),
-            (r'(class)(\s+)([A-Z][a-zA-Z0-9_\']*)',
-                bygroups(Keyword, Whitespace, Name.Class)),
-            (r'class'+_nkw,             Keyword),
-            (r'extends'+_nkw,           Keyword),
-            (r'(def)(\s+)(self)(\s*)(\.)(\s*)([a-z_][a-zA-Z0-9_\']*=?|<<|>>|==|<=>|<=|<|>=|>|\+|-(self)?|~(self)?|\*|/|%|^|&&|&|\||\[\]=?)',
-                bygroups(Keyword, Whitespace, Name.Builtin, Whitespace, Punctuation, Whitespace, Name.Function)),
-            (r'(def)(\s+)([a-z_][a-zA-Z0-9_\']*=?|<<|>>|==|<=>|<=|<|>=|>|\+|-(self)?|~(self)?|\*|/|%|^|&&|&|\||\[\]=?)',
-                bygroups(Keyword, Whitespace, Name.Function)),
-            (r'def'+_nkw,               Keyword),
-            (r'if'+_nkw,                Keyword),
-            (r'elsif'+_nkw,             Keyword),
-            (r'else'+_nkw,              Keyword),
-            (r'unless'+_nkw,            Keyword),
-            (r'for'+_nkw,               Keyword),
-            (r'in'+_nkw,                Keyword),
-            (r'while'+_nkw,             Keyword),
-            (r'until'+_nkw,             Keyword),
-            (r'and'+_nkw,               Keyword),
-            (r'or'+_nkw,                Keyword),
-            (r'not'+_nkw,               Keyword),
-            (r'lambda'+_nkw,            Keyword),
-            (r'try'+_nkw,               Keyword),
-            (r'catch'+_nkw,             Keyword),
-            (r'return'+_nkw,            Keyword),
-            (r'next'+_nkw,              Keyword),
-            (r'last'+_nkw,              Keyword),
-            (r'throw'+_nkw,             Keyword),
-            (r'use'+_nkw,               Keyword),
-            (r'switch'+_nkw,            Keyword),
-            (r'\\',                     Keyword),
-            (r'λ',                      Keyword),
-            (r'__FILE__'+_nkw,          Name.Builtin.Pseudo),
-            (r'__LINE__'+_nkw,          Name.Builtin.Pseudo),
-            (r'[A-Z][a-zA-Z0-9_\']*'+_nkw, Name.Constant),
-            (r'[a-z_][a-zA-Z0-9_\']*'+_nkw, Name),
-            (r'@[a-z_][a-zA-Z0-9_\']*'+_nkw, Name.Variable.Instance),
-            (r'@@[a-z_][a-zA-Z0-9_\']*'+_nkw, Name.Variable.Class),
-            (r'\(',                     Punctuation),
-            (r'\)',                     Punctuation),
-            (r'\[',                     Punctuation),
-            (r'\]',                     Punctuation),
-            (r'\{',                     Punctuation),
-            (r'\}',                     right_angle_bracket),
-            (r';',                      Punctuation),
-            (r',',                      Punctuation),
-            (r'<<=',                    Operator),
-            (r'>>=',                    Operator),
-            (r'<<',                     Operator),
-            (r'>>',                     Operator),
-            (r'==',                     Operator),
-            (r'!=',                     Operator),
-            (r'=>',                     Operator),
-            (r'=',                      Operator),
-            (r'<=>',                    Operator),
-            (r'<=',                     Operator),
-            (r'>=',                     Operator),
-            (r'<',                      Operator),
-            (r'>',                      Operator),
-            (r'\+\+',                   Operator),
-            (r'\+=',                    Operator),
-            (r'-=',                     Operator),
-            (r'\*\*=',                  Operator),
-            (r'\*=',                    Operator),
-            (r'\*\*',                   Operator),
-            (r'\*',                     Operator),
-            (r'/=',                     Operator),
-            (r'\+',                     Operator),
-            (r'-',                      Operator),
-            (r'/',                      Operator),
-            (r'%=',                     Operator),
-            (r'%',                      Operator),
-            (r'^=',                     Operator),
-            (r'&&=',                    Operator),
-            (r'&=',                     Operator),
-            (r'&&',                     Operator),
-            (r'&',                      Operator),
-            (r'\|\|=',                  Operator),
-            (r'\|=',                    Operator),
-            (r'\|\|',                   Operator),
-            (r'\|',                     Operator),
-            (r'!',                      Operator),
-            (r'\.\.\.',                 Operator),
-            (r'\.\.',                   Operator),
-            (r'\.',                     Operator),
-            (r'::',                     Operator),
-            (r':',                      Operator),
-            (r'(\s|\n)+',               Whitespace),
-            (r'[a-z_][a-zA-Z0-9_\']*',  Name.Variable),
-        ],
-    }
-
-
-class SlashLexer(DelegatingLexer):
-    """
-    Lexer for the Slash programming language.
-    """
-
-    name = 'Slash'
-    aliases = ['slash']
-    filenames = ['*.sla']
-    url = 'https://github.com/arturadib/Slash-A'
-    version_added = '2.4'
-
-    def __init__(self, **options):
-        from pygments.lexers.web import HtmlLexer
-        super().__init__(HtmlLexer, SlashLanguageLexer, **options)
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/smalltalk.py b/.venv/lib/python3.12/site-packages/pygments/lexers/smalltalk.py
deleted file mode 100644
index 69e0519..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/smalltalk.py
+++ /dev/null
@@ -1,194 +0,0 @@
-"""
-    pygments.lexers.smalltalk
-    ~~~~~~~~~~~~~~~~~~~~~~~~~
-
-    Lexers for Smalltalk and related languages.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-from pygments.lexer import RegexLexer, include, bygroups, default
-from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
-    Number, Punctuation
-
-__all__ = ['SmalltalkLexer', 'NewspeakLexer']
-
-
-class SmalltalkLexer(RegexLexer):
-    """
-    For Smalltalk syntax.
-    Contributed by Stefan Matthias Aust.
-    Rewritten by Nils Winter.
-    """
-    name = 'Smalltalk'
-    url = 'http://www.smalltalk.org/'
-    filenames = ['*.st']
-    aliases = ['smalltalk', 'squeak', 'st']
-    mimetypes = ['text/x-smalltalk']
-    version_added = '0.10'
-
-    tokens = {
-        'root': [
-            (r'(<)(\w+:)(.*?)(>)', bygroups(Text, Keyword, Text, Text)),
-            include('squeak fileout'),
-            include('whitespaces'),
-            include('method definition'),
-            (r'(\|)([\w\s]*)(\|)', bygroups(Operator, Name.Variable, Operator)),
-            include('objects'),
-            (r'\^|\:=|\_', Operator),
-            # temporaries
-            (r'[\]({}.;!]', Text),
-        ],
-        'method definition': [
-            # Not perfect can't allow whitespaces at the beginning and the
-            # without breaking everything
-            (r'([a-zA-Z]+\w*:)(\s*)(\w+)',
-             bygroups(Name.Function, Text, Name.Variable)),
-            (r'^(\b[a-zA-Z]+\w*\b)(\s*)$', bygroups(Name.Function, Text)),
-            (r'^([-+*/\\~<>=|&!?,@%]+)(\s*)(\w+)(\s*)$',
-             bygroups(Name.Function, Text, Name.Variable, Text)),
-        ],
-        'blockvariables': [
-            include('whitespaces'),
-            (r'(:)(\s*)(\w+)',
-             bygroups(Operator, Text, Name.Variable)),
-            (r'\|', Operator, '#pop'),
-            default('#pop'),  # else pop
-        ],
-        'literals': [
-            (r"'(''|[^'])*'", String, 'afterobject'),
-            (r'\$.', String.Char, 'afterobject'),
-            (r'#\(', String.Symbol, 'parenth'),
-            (r'\)', Text, 'afterobject'),
-            (r'(\d+r)?-?\d+(\.\d+)?(e-?\d+)?', Number, 'afterobject'),
-        ],
-        '_parenth_helper': [
-            include('whitespaces'),
-            (r'(\d+r)?-?\d+(\.\d+)?(e-?\d+)?', Number),
-            (r'[-+*/\\~<>=|&#!?,@%\w:]+', String.Symbol),
-            # literals
-            (r"'(''|[^'])*'", String),
-            (r'\$.', String.Char),
-            (r'#*\(', String.Symbol, 'inner_parenth'),
-        ],
-        'parenth': [
-            # This state is a bit tricky since
-            # we can't just pop this state
-            (r'\)', String.Symbol, ('root', 'afterobject')),
-            include('_parenth_helper'),
-        ],
-        'inner_parenth': [
-            (r'\)', String.Symbol, '#pop'),
-            include('_parenth_helper'),
-        ],
-        'whitespaces': [
-            # skip whitespace and comments
-            (r'\s+', Text),
-            (r'"(""|[^"])*"', Comment),
-        ],
-        'objects': [
-            (r'\[', Text, 'blockvariables'),
-            (r'\]', Text, 'afterobject'),
-            (r'\b(self|super|true|false|nil|thisContext)\b',
-             Name.Builtin.Pseudo, 'afterobject'),
-            (r'\b[A-Z]\w*(?!:)\b', Name.Class, 'afterobject'),
-            (r'\b[a-z]\w*(?!:)\b', Name.Variable, 'afterobject'),
-            (r'#("(""|[^"])*"|[-+*/\\~<>=|&!?,@%]+|[\w:]+)',
-             String.Symbol, 'afterobject'),
-            include('literals'),
-        ],
-        'afterobject': [
-            (r'! !$', Keyword, '#pop'),  # squeak chunk delimiter
-            include('whitespaces'),
-            (r'\b(ifTrue:|ifFalse:|whileTrue:|whileFalse:|timesRepeat:)',
-             Name.Builtin, '#pop'),
-            (r'\b(new\b(?!:))', Name.Builtin),
-            (r'\:=|\_', Operator, '#pop'),
-            (r'\b[a-zA-Z]+\w*:', Name.Function, '#pop'),
-            (r'\b[a-zA-Z]+\w*', Name.Function),
-            (r'\w+:?|[-+*/\\~<>=|&!?,@%]+', Name.Function, '#pop'),
-            (r'\.', Punctuation, '#pop'),
-            (r';', Punctuation),
-            (r'[\])}]', Text),
-            (r'[\[({]', Text, '#pop'),
-        ],
-        'squeak fileout': [
-            # Squeak fileout format (optional)
-            (r'^"(""|[^"])*"!', Keyword),
-            (r"^'(''|[^'])*'!", Keyword),
-            (r'^(!)(\w+)( commentStamp: )(.*?)( prior: .*?!\n)(.*?)(!)',
-                bygroups(Keyword, Name.Class, Keyword, String, Keyword, Text, Keyword)),
-            (r"^(!)(\w+(?: class)?)( methodsFor: )('(?:''|[^'])*')(.*?!)",
-                bygroups(Keyword, Name.Class, Keyword, String, Keyword)),
-            (r'^(\w+)( subclass: )(#\w+)'
-             r'(\s+instanceVariableNames: )(.*?)'
-             r'(\s+classVariableNames: )(.*?)'
-             r'(\s+poolDictionaries: )(.*?)'
-             r'(\s+category: )(.*?)(!)',
-                bygroups(Name.Class, Keyword, String.Symbol, Keyword, String, Keyword,
-                         String, Keyword, String, Keyword, String, Keyword)),
-            (r'^(\w+(?: class)?)(\s+instanceVariableNames: )(.*?)(!)',
-                bygroups(Name.Class, Keyword, String, Keyword)),
-            (r'(!\n)(\].*)(! !)$', bygroups(Keyword, Text, Keyword)),
-            (r'! !$', Keyword),
-        ],
-    }
-
-
-class NewspeakLexer(RegexLexer):
-    """
-    For Newspeak syntax.
-    """
-    name = 'Newspeak'
-    url = 'http://newspeaklanguage.org/'
-    filenames = ['*.ns2']
-    aliases = ['newspeak', ]
-    mimetypes = ['text/x-newspeak']
-    version_added = '1.1'
-
-    tokens = {
-        'root': [
-            (r'\b(Newsqueak2)\b', Keyword.Declaration),
-            (r"'[^']*'", String),
-            (r'\b(class)(\s+)(\w+)(\s*)',
-             bygroups(Keyword.Declaration, Text, Name.Class, Text)),
-            (r'\b(mixin|self|super|private|public|protected|nil|true|false)\b',
-             Keyword),
-            (r'(\w+\:)(\s*)([a-zA-Z_]\w+)',
-             bygroups(Name.Function, Text, Name.Variable)),
-            (r'(\w+)(\s*)(=)',
-             bygroups(Name.Attribute, Text, Operator)),
-            (r'<\w+>', Comment.Special),
-            include('expressionstat'),
-            include('whitespace')
-        ],
-
-        'expressionstat': [
-            (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float),
-            (r'\d+', Number.Integer),
-            (r':\w+', Name.Variable),
-            (r'(\w+)(::)', bygroups(Name.Variable, Operator)),
-            (r'\w+:', Name.Function),
-            (r'\w+', Name.Variable),
-            (r'\(|\)', Punctuation),
-            (r'\[|\]', Punctuation),
-            (r'\{|\}', Punctuation),
-
-            (r'(\^|\+|\/|~|\*|<|>|=|@|%|\||&|\?|!|,|-|:)', Operator),
-            (r'\.|;', Punctuation),
-            include('whitespace'),
-            include('literals'),
-        ],
-        'literals': [
-            (r'\$.', String),
-            (r"'[^']*'", String),
-            (r"#'[^']*'", String.Symbol),
-            (r"#\w+:?", String.Symbol),
-            (r"#(\+|\/|~|\*|<|>|=|@|%|\||&|\?|!|,|-)+", String.Symbol)
-        ],
-        'whitespace': [
-            (r'\s+', Text),
-            (r'"[^"]*"', Comment)
-        ],
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/smithy.py b/.venv/lib/python3.12/site-packages/pygments/lexers/smithy.py
deleted file mode 100644
index 2642bb8..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/smithy.py
+++ /dev/null
@@ -1,77 +0,0 @@
-"""
-    pygments.lexers.smithy
-    ~~~~~~~~~~~~~~~~~~~~~~
-
-    Lexers for the Smithy IDL.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-from pygments.lexer import RegexLexer, bygroups, words
-from pygments.token import Text, Comment, Keyword, Name, String, \
-    Number, Whitespace, Punctuation
-
-__all__ = ['SmithyLexer']
-
-
-class SmithyLexer(RegexLexer):
-    """
-    For Smithy IDL
-    """
-    name = 'Smithy'
-    url = 'https://awslabs.github.io/smithy/'
-    filenames = ['*.smithy']
-    aliases = ['smithy']
-    version_added = '2.10'
-
-    unquoted = r'[A-Za-z0-9_\.#$-]+'
-    identifier = r"[A-Za-z0-9_\.#$-]+"
-
-    simple_shapes = (
-        'use', 'byte', 'short', 'integer', 'long', 'float', 'document',
-        'double', 'bigInteger', 'bigDecimal', 'boolean', 'blob', 'string',
-        'timestamp',
-    )
-
-    aggregate_shapes = (
-       'apply', 'list', 'map', 'set', 'structure', 'union', 'resource',
-       'operation', 'service', 'trait'
-    )
-
-    tokens = {
-        'root': [
-            (r'///.*$', Comment.Multiline),
-            (r'//.*$', Comment),
-            (r'@[0-9a-zA-Z\.#-]*', Name.Decorator),
-            (r'(=)', Name.Decorator),
-            (r'^(\$version)(:)(.+)',
-                bygroups(Keyword.Declaration, Name.Decorator, Name.Class)),
-            (r'^(namespace)(\s+' + identifier + r')\b',
-                bygroups(Keyword.Declaration, Name.Class)),
-            (words(simple_shapes,
-                   prefix=r'^', suffix=r'(\s+' + identifier + r')\b'),
-                bygroups(Keyword.Declaration, Name.Class)),
-            (words(aggregate_shapes,
-                   prefix=r'^', suffix=r'(\s+' + identifier + r')'),
-                bygroups(Keyword.Declaration, Name.Class)),
-            (r'^(metadata)(\s+)((?:\S+)|(?:\"[^"]+\"))(\s*)(=)',
-                bygroups(Keyword.Declaration, Whitespace, Name.Class,
-                         Whitespace, Name.Decorator)),
-            (r"(true|false|null)", Keyword.Constant),
-            (r"(-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?)", Number),
-            (identifier + ":", Name.Label),
-            (identifier, Name.Variable.Class),
-            (r'\[', Text, "#push"),
-            (r'\]', Text, "#pop"),
-            (r'\(', Text, "#push"),
-            (r'\)', Text, "#pop"),
-            (r'\{', Text, "#push"),
-            (r'\}', Text, "#pop"),
-            (r'"{3}(\\\\|\n|\\")*"{3}', String.Doc),
-            (r'"(\\\\|\n|\\"|[^"])*"', String.Double),
-            (r"'(\\\\|\n|\\'|[^'])*'", String.Single),
-            (r'[:,]+', Punctuation),
-            (r'\s+', Whitespace),
-        ]
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/smv.py b/.venv/lib/python3.12/site-packages/pygments/lexers/smv.py
deleted file mode 100644
index 3d06f99..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/smv.py
+++ /dev/null
@@ -1,78 +0,0 @@
-"""
-    pygments.lexers.smv
-    ~~~~~~~~~~~~~~~~~~~
-
-    Lexers for the SMV languages.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-from pygments.lexer import RegexLexer, words
-from pygments.token import Comment, Keyword, Name, Number, Operator, \
-    Punctuation, Text
-
-__all__ = ['NuSMVLexer']
-
-
-class NuSMVLexer(RegexLexer):
-    """
-    Lexer for the NuSMV language.
-    """
-
-    name = 'NuSMV'
-    aliases = ['nusmv']
-    filenames = ['*.smv']
-    mimetypes = []
-    url = 'https://nusmv.fbk.eu'
-    version_added = '2.2'
-
-    tokens = {
-        'root': [
-            # Comments
-            (r'(?s)\/\-\-.*?\-\-/', Comment),
-            (r'--.*\n', Comment),
-
-            # Reserved
-            (words(('MODULE', 'DEFINE', 'MDEFINE', 'CONSTANTS', 'VAR', 'IVAR',
-                    'FROZENVAR', 'INIT', 'TRANS', 'INVAR', 'SPEC', 'CTLSPEC',
-                    'LTLSPEC', 'PSLSPEC', 'COMPUTE', 'NAME', 'INVARSPEC',
-                    'FAIRNESS', 'JUSTICE', 'COMPASSION', 'ISA', 'ASSIGN',
-                    'CONSTRAINT', 'SIMPWFF', 'CTLWFF', 'LTLWFF', 'PSLWFF',
-                    'COMPWFF', 'IN', 'MIN', 'MAX', 'MIRROR', 'PRED',
-                    'PREDICATES'), suffix=r'(?![\w$#-])'),
-             Keyword.Declaration),
-            (r'process(?![\w$#-])', Keyword),
-            (words(('array', 'of', 'boolean', 'integer', 'real', 'word'),
-                   suffix=r'(?![\w$#-])'), Keyword.Type),
-            (words(('case', 'esac'), suffix=r'(?![\w$#-])'), Keyword),
-            (words(('word1', 'bool', 'signed', 'unsigned', 'extend', 'resize',
-                    'sizeof', 'uwconst', 'swconst', 'init', 'self', 'count',
-                    'abs', 'max', 'min'), suffix=r'(?![\w$#-])'),
-             Name.Builtin),
-            (words(('EX', 'AX', 'EF', 'AF', 'EG', 'AG', 'E', 'F', 'O', 'G',
-                    'H', 'X', 'Y', 'Z', 'A', 'U', 'S', 'V', 'T', 'BU', 'EBF',
-                    'ABF', 'EBG', 'ABG', 'next', 'mod', 'union', 'in', 'xor',
-                    'xnor'), suffix=r'(?![\w$#-])'),
-                Operator.Word),
-            (words(('TRUE', 'FALSE'), suffix=r'(?![\w$#-])'), Keyword.Constant),
-
-            # Names
-            (r'[a-zA-Z_][\w$#-]*', Name.Variable),
-
-            # Operators
-            (r':=', Operator),
-            (r'[-&|+*/<>!=]', Operator),
-
-            # Literals
-            (r'\-?\d+\b', Number.Integer),
-            (r'0[su][bB]\d*_[01_]+', Number.Bin),
-            (r'0[su][oO]\d*_[0-7_]+', Number.Oct),
-            (r'0[su][dD]\d*_[\d_]+', Number.Decimal),
-            (r'0[su][hH]\d*_[\da-fA-F_]+', Number.Hex),
-
-            # Whitespace, punctuation and the rest
-            (r'\s+', Text.Whitespace),
-            (r'[()\[\]{};?:.,]', Punctuation),
-        ],
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/snobol.py b/.venv/lib/python3.12/site-packages/pygments/lexers/snobol.py
deleted file mode 100644
index 7016c96..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/snobol.py
+++ /dev/null
@@ -1,82 +0,0 @@
-"""
-    pygments.lexers.snobol
-    ~~~~~~~~~~~~~~~~~~~~~~
-
-    Lexers for the SNOBOL language.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-from pygments.lexer import RegexLexer, bygroups
-from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
-    Number, Punctuation
-
-__all__ = ['SnobolLexer']
-
-
-class SnobolLexer(RegexLexer):
-    """
-    Lexer for the SNOBOL4 programming language.
-
-    Recognizes the common ASCII equivalents of the original SNOBOL4 operators.
-    Does not require spaces around binary operators.
-    """
-
-    name = "Snobol"
-    aliases = ["snobol"]
-    filenames = ['*.snobol']
-    mimetypes = ['text/x-snobol']
-    url = 'https://www.regressive.org/snobol4'
-    version_added = '1.5'
-
-    tokens = {
-        # root state, start of line
-        # comments, continuation lines, and directives start in column 1
-        # as do labels
-        'root': [
-            (r'\*.*\n', Comment),
-            (r'[+.] ', Punctuation, 'statement'),
-            (r'-.*\n', Comment),
-            (r'END\s*\n', Name.Label, 'heredoc'),
-            (r'[A-Za-z$][\w$]*', Name.Label, 'statement'),
-            (r'\s+', Text, 'statement'),
-        ],
-        # statement state, line after continuation or label
-        'statement': [
-            (r'\s*\n', Text, '#pop'),
-            (r'\s+', Text),
-            (r'(?<=[^\w.])(LT|LE|EQ|NE|GE|GT|INTEGER|IDENT|DIFFER|LGT|SIZE|'
-             r'REPLACE|TRIM|DUPL|REMDR|DATE|TIME|EVAL|APPLY|OPSYN|LOAD|UNLOAD|'
-             r'LEN|SPAN|BREAK|ANY|NOTANY|TAB|RTAB|REM|POS|RPOS|FAIL|FENCE|'
-             r'ABORT|ARB|ARBNO|BAL|SUCCEED|INPUT|OUTPUT|TERMINAL)(?=[^\w.])',
-             Name.Builtin),
-            (r'[A-Za-z][\w.]*', Name),
-            # ASCII equivalents of original operators
-            # | for the EBCDIC equivalent, ! likewise
-            # \ for EBCDIC negation
-            (r'\*\*|[?$.!%*/#+\-@|&\\=]', Operator),
-            (r'"[^"]*"', String),
-            (r"'[^']*'", String),
-            # Accept SPITBOL syntax for real numbers
-            # as well as Macro SNOBOL4
-            (r'[0-9]+(?=[^.EeDd])', Number.Integer),
-            (r'[0-9]+(\.[0-9]*)?([EDed][-+]?[0-9]+)?', Number.Float),
-            # Goto
-            (r':', Punctuation, 'goto'),
-            (r'[()<>,;]', Punctuation),
-        ],
-        # Goto block
-        'goto': [
-            (r'\s*\n', Text, "#pop:2"),
-            (r'\s+', Text),
-            (r'F|S', Keyword),
-            (r'(\()([A-Za-z][\w.]*)(\))',
-             bygroups(Punctuation, Name.Label, Punctuation))
-        ],
-        # everything after the END statement is basically one
-        # big heredoc.
-        'heredoc': [
-            (r'.*\n', String.Heredoc)
-        ]
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/solidity.py b/.venv/lib/python3.12/site-packages/pygments/lexers/solidity.py
deleted file mode 100644
index 3f2d1dd..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/solidity.py
+++ /dev/null
@@ -1,87 +0,0 @@
-"""
-    pygments.lexers.solidity
-    ~~~~~~~~~~~~~~~~~~~~~~~~
-
-    Lexers for Solidity.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-from pygments.lexer import RegexLexer, bygroups, include, words
-from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
-    Number, Punctuation, Whitespace
-
-__all__ = ['SolidityLexer']
-
-
-class SolidityLexer(RegexLexer):
-    """
-    For Solidity source code.
-    """
-
-    name = 'Solidity'
-    aliases = ['solidity']
-    filenames = ['*.sol']
-    mimetypes = []
-    url = 'https://soliditylang.org'
-    version_added = '2.5'
-
-    datatype = (
-        r'\b(address|bool|(?:(?:bytes|hash|int|string|uint)(?:8|16|24|32|40|48|56|64'
-        r'|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208'
-        r'|216|224|232|240|248|256)?))\b'
-    )
-
-    tokens = {
-        'root': [
-            include('whitespace'),
-            include('comments'),
-            (r'\bpragma\s+solidity\b', Keyword, 'pragma'),
-            (r'\b(contract)(\s+)([a-zA-Z_]\w*)',
-             bygroups(Keyword, Whitespace, Name.Entity)),
-            (datatype + r'(\s+)((?:external|public|internal|private)\s+)?' +
-             r'([a-zA-Z_]\w*)',
-             bygroups(Keyword.Type, Whitespace, Keyword, Name.Variable)),
-            (r'\b(enum|event|function|struct)(\s+)([a-zA-Z_]\w*)',
-             bygroups(Keyword.Type, Whitespace, Name.Variable)),
-            (r'\b(msg|block|tx)\.([A-Za-z_][a-zA-Z0-9_]*)\b', Keyword),
-            (words((
-                'block', 'break', 'constant', 'constructor', 'continue',
-                'contract', 'do', 'else', 'external', 'false', 'for',
-                'function', 'if', 'import', 'inherited', 'internal', 'is',
-                'library', 'mapping', 'memory', 'modifier', 'msg', 'new',
-                'payable', 'private', 'public', 'require', 'return',
-                'returns', 'struct', 'suicide', 'throw', 'this', 'true',
-                'tx', 'var', 'while'), prefix=r'\b', suffix=r'\b'),
-             Keyword.Type),
-            (words(('keccak256',), prefix=r'\b', suffix=r'\b'), Name.Builtin),
-            (datatype, Keyword.Type),
-            include('constants'),
-            (r'[a-zA-Z_]\w*', Text),
-            (r'[~!%^&*+=|?:<>/-]', Operator),
-            (r'[.;{}(),\[\]]', Punctuation)
-        ],
-        'comments': [
-            (r'//(\n|[\w\W]*?[^\\]\n)', Comment.Single),
-            (r'/(\\\n)?[*][\w\W]*?[*](\\\n)?/', Comment.Multiline),
-            (r'/(\\\n)?[*][\w\W]*', Comment.Multiline)
-        ],
-        'constants': [
-            (r'("(\\"|.)*?")', String.Double),
-            (r"('(\\'|.)*?')", String.Single),
-            (r'\b0[xX][0-9a-fA-F]+\b', Number.Hex),
-            (r'\b\d+\b', Number.Decimal),
-        ],
-        'pragma': [
-            include('whitespace'),
-            include('comments'),
-            (r'(\^|>=|<)(\s*)(\d+\.\d+\.\d+)',
-             bygroups(Operator, Whitespace, Keyword)),
-            (r';', Punctuation, '#pop')
-        ],
-        'whitespace': [
-            (r'\s+', Whitespace),
-            (r'\n', Whitespace)
-        ]
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/soong.py b/.venv/lib/python3.12/site-packages/pygments/lexers/soong.py
deleted file mode 100644
index 0d7f12c..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/soong.py
+++ /dev/null
@@ -1,78 +0,0 @@
-"""
-    pygments.lexers.soong
-    ~~~~~~~~~~~~~~~~~~~~~
-
-    Lexers for Soong (Android.bp Blueprint) files.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-from pygments.lexer import RegexLexer, bygroups, include
-from pygments.token import Comment, Name, Number, Operator, Punctuation, \
-        String, Whitespace
-
-__all__ = ['SoongLexer']
-
-class SoongLexer(RegexLexer):
-    name = 'Soong'
-    version_added = '2.18'
-    url = 'https://source.android.com/docs/setup/reference/androidbp'
-    aliases = ['androidbp', 'bp', 'soong']
-    filenames = ['Android.bp']
-
-    tokens = {
-        'root': [
-            # A variable assignment
-            (r'(\w*)(\s*)(\+?=)(\s*)',
-             bygroups(Name.Variable, Whitespace, Operator, Whitespace),
-             'assign-rhs'),
-
-            # A top-level module
-            (r'(\w*)(\s*)(\{)',
-             bygroups(Name.Function, Whitespace, Punctuation),
-             'in-rule'),
-
-            # Everything else
-            include('comments'),
-            (r'\s+', Whitespace),  # newlines okay
-        ],
-        'assign-rhs': [
-            include('expr'),
-            (r'\n', Whitespace, '#pop'),
-        ],
-        'in-list': [
-            include('expr'),
-            include('comments'),
-            (r'\s+', Whitespace),  # newlines okay in a list
-            (r',', Punctuation),
-            (r'\]', Punctuation, '#pop'),
-        ],
-        'in-map': [
-            # A map key
-            (r'(\w+)(:)(\s*)', bygroups(Name, Punctuation, Whitespace)),
-
-            include('expr'),
-            include('comments'),
-            (r'\s+', Whitespace),  # newlines okay in a map
-            (r',', Punctuation),
-            (r'\}', Punctuation, '#pop'),
-        ],
-        'in-rule': [
-            # Just re-use map syntax
-            include('in-map'),
-        ],
-        'comments': [
-            (r'//.*', Comment.Single),
-            (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
-        ],
-        'expr': [
-            (r'(true|false)\b', Name.Builtin),
-            (r'0x[0-9a-fA-F]+', Number.Hex),
-            (r'\d+', Number.Integer),
-            (r'".*?"', String),
-            (r'\{', Punctuation, 'in-map'),
-            (r'\[', Punctuation, 'in-list'),
-            (r'\w+', Name),
-        ],
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/sophia.py b/.venv/lib/python3.12/site-packages/pygments/lexers/sophia.py
deleted file mode 100644
index 86435f3..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/sophia.py
+++ /dev/null
@@ -1,102 +0,0 @@
-"""
-    pygments.lexers.sophia
-    ~~~~~~~~~~~~~~~~~~~~~~
-
-    Lexer for Sophia.
-
-    Derived from pygments/lexers/reason.py.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-from pygments.lexer import RegexLexer, include, default, words
-from pygments.token import Comment, Keyword, Name, Number, Operator, \
-    Punctuation, String, Text
-
-__all__ = ['SophiaLexer']
-
-class SophiaLexer(RegexLexer):
-    """
-    A Sophia lexer.
-    """
-
-    name = 'Sophia'
-    aliases = ['sophia']
-    filenames = ['*.aes']
-    mimetypes = []
-    url = 'https://docs.aeternity.com/aesophia'
-    version_added = '2.11'
-
-    keywords = (
-        'contract', 'include', 'let', 'switch', 'type', 'record', 'datatype',
-        'if', 'elif', 'else', 'function', 'stateful', 'payable', 'public',
-        'entrypoint', 'private', 'indexed', 'namespace', 'interface', 'main',
-        'using', 'as', 'for', 'hiding',
-    )
-
-    builtins = ('state', 'put', 'abort', 'require')
-
-    word_operators = ('mod', 'band', 'bor', 'bxor', 'bnot')
-
-    primitive_types = ('int', 'address', 'bool', 'bits', 'bytes', 'string',
-                       'list', 'option', 'char', 'unit', 'map', 'event',
-                       'hash', 'signature', 'oracle', 'oracle_query')
-
-    tokens = {
-        'escape-sequence': [
-            (r'\\[\\"\'ntbr]', String.Escape),
-            (r'\\[0-9]{3}', String.Escape),
-            (r'\\x[0-9a-fA-F]{2}', String.Escape),
-        ],
-        'root': [
-            (r'\s+', Text.Whitespace),
-            (r'(true|false)\b', Keyword.Constant),
-            (r'\b([A-Z][\w\']*)(?=\s*\.)', Name.Class, 'dotted'),
-            (r'\b([A-Z][\w\']*)', Name.Function),
-            (r'//.*?\n', Comment.Single),
-            (r'\/\*(?!/)', Comment.Multiline, 'comment'),
-
-            (r'0[xX][\da-fA-F][\da-fA-F_]*', Number.Hex),
-            (r'#[\da-fA-F][\da-fA-F_]*', Name.Label),
-            (r'\d[\d_]*', Number.Integer),
-
-            (words(keywords, suffix=r'\b'), Keyword),
-            (words(builtins, suffix=r'\b'), Name.Builtin),
-            (words(word_operators, prefix=r'\b', suffix=r'\b'), Operator.Word),
-            (words(primitive_types, prefix=r'\b', suffix=r'\b'), Keyword.Type),
-
-            (r'[=!<>+\\*/:&|?~@^-]', Operator.Word),
-            (r'[.;:{}(),\[\]]', Punctuation),
-
-            (r"(ak_|ok_|oq_|ct_)[\w']*", Name.Label),
-            (r"[^\W\d][\w']*", Name),
-
-            (r"'(?:(\\[\\\"'ntbr ])|(\\[0-9]{3})|(\\x[0-9a-fA-F]{2}))'",
-             String.Char),
-            (r"'.'", String.Char),
-            (r"'[a-z][\w]*", Name.Variable),
-
-            (r'"', String.Double, 'string')
-        ],
-        'comment': [
-            (r'[^/*]+', Comment.Multiline),
-            (r'\/\*', Comment.Multiline, '#push'),
-            (r'\*\/', Comment.Multiline, '#pop'),
-            (r'\*', Comment.Multiline),
-        ],
-        'string': [
-            (r'[^\\"]+', String.Double),
-            include('escape-sequence'),
-            (r'\\\n', String.Double),
-            (r'"', String.Double, '#pop'),
-        ],
-        'dotted': [
-            (r'\s+', Text),
-            (r'\.', Punctuation),
-            (r'[A-Z][\w\']*(?=\s*\.)', Name.Function),
-            (r'[A-Z][\w\']*', Name.Function, '#pop'),
-            (r'[a-z_][\w\']*', Name, '#pop'),
-            default('#pop'),
-        ],
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/special.py b/.venv/lib/python3.12/site-packages/pygments/lexers/special.py
deleted file mode 100644
index ea34522..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/special.py
+++ /dev/null
@@ -1,122 +0,0 @@
-"""
-    pygments.lexers.special
-    ~~~~~~~~~~~~~~~~~~~~~~~
-
-    Special lexers.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-import ast
-
-from pygments.lexer import Lexer, line_re
-from pygments.token import Token, Error, Text, Generic
-from pygments.util import get_choice_opt
-
-
-__all__ = ['TextLexer', 'OutputLexer', 'RawTokenLexer']
-
-
-class TextLexer(Lexer):
-    """
-    "Null" lexer, doesn't highlight anything.
-    """
-    name = 'Text only'
-    aliases = ['text']
-    filenames = ['*.txt']
-    mimetypes = ['text/plain']
-    url = ""
-    version_added = ''
-
-    priority = 0.01
-
-    def get_tokens_unprocessed(self, text):
-        yield 0, Text, text
-
-    def analyse_text(text):
-        return TextLexer.priority
-
-
-class OutputLexer(Lexer):
-    """
-    Simple lexer that highlights everything as ``Token.Generic.Output``.
-    """
-    name = 'Text output'
-    aliases = ['output']
-    url = ""
-    version_added = '2.10'
-    _example = "output/output"
-
-    def get_tokens_unprocessed(self, text):
-        yield 0, Generic.Output, text
-
-
-_ttype_cache = {}
-
-
-class RawTokenLexer(Lexer):
-    """
-    Recreate a token stream formatted with the `RawTokenFormatter`.
-
-    Additional options accepted:
-
-    `compress`
-        If set to ``"gz"`` or ``"bz2"``, decompress the token stream with
-        the given compression algorithm before lexing (default: ``""``).
-    """
-    name = 'Raw token data'
-    aliases = []
-    filenames = []
-    mimetypes = ['application/x-pygments-tokens']
-    url = 'https://pygments.org/docs/formatters/#RawTokenFormatter'
-    version_added = ''
-
-    def __init__(self, **options):
-        self.compress = get_choice_opt(options, 'compress',
-                                       ['', 'none', 'gz', 'bz2'], '')
-        Lexer.__init__(self, **options)
-
-    def get_tokens(self, text):
-        if self.compress:
-            if isinstance(text, str):
-                text = text.encode('latin1')
-            try:
-                if self.compress == 'gz':
-                    import gzip
-                    text = gzip.decompress(text)
-                elif self.compress == 'bz2':
-                    import bz2
-                    text = bz2.decompress(text)
-            except OSError:
-                yield Error, text.decode('latin1')
-        if isinstance(text, bytes):
-            text = text.decode('latin1')
-
-        # do not call Lexer.get_tokens() because stripping is not optional.
-        text = text.strip('\n') + '\n'
-        for i, t, v in self.get_tokens_unprocessed(text):
-            yield t, v
-
-    def get_tokens_unprocessed(self, text):
-        length = 0
-        for match in line_re.finditer(text):
-            try:
-                ttypestr, val = match.group().rstrip().split('\t', 1)
-                ttype = _ttype_cache.get(ttypestr)
-                if not ttype:
-                    ttype = Token
-                    ttypes = ttypestr.split('.')[1:]
-                    for ttype_ in ttypes:
-                        if not ttype_ or not ttype_[0].isupper():
-                            raise ValueError('malformed token name')
-                        ttype = getattr(ttype, ttype_)
-                    _ttype_cache[ttypestr] = ttype
-                val = ast.literal_eval(val)
-                if not isinstance(val, str):
-                    raise ValueError('expected str')
-            except (SyntaxError, ValueError):
-                val = match.group()
-                ttype = Error
-            yield length, ttype, val
-            length += len(val)
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/spice.py b/.venv/lib/python3.12/site-packages/pygments/lexers/spice.py
deleted file mode 100644
index 978f0a7..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/spice.py
+++ /dev/null
@@ -1,70 +0,0 @@
-"""
-    pygments.lexers.spice
-    ~~~~~~~~~~~~~~~~~~~~~
-
-    Lexers for the Spice programming language.
-
-    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-
-from pygments.lexer import RegexLexer, bygroups, words
-from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
-    Number, Punctuation, Whitespace
-
-__all__ = ['SpiceLexer']
-
-
-class SpiceLexer(RegexLexer):
-    """
-    For Spice source.
-    """
-    name = 'Spice'
-    url = 'https://www.spicelang.com'
-    filenames = ['*.spice']
-    aliases = ['spice', 'spicelang']
-    mimetypes = ['text/x-spice']
-    version_added = '2.11'
-
-    tokens = {
-        'root': [
-            (r'\n', Whitespace),
-            (r'\s+', Whitespace),
-            (r'\\\n', Text),
-            # comments
-            (r'//(.*?)\n', Comment.Single),
-            (r'/(\\\n)?[*]{2}(.|\n)*?[*](\\\n)?/', String.Doc),
-            (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
-            # keywords
-            (r'(import|as)\b', Keyword.Namespace),
-            (r'(f|p|type|struct|interface|enum|alias|operator)\b', Keyword.Declaration),
-            (words(('if', 'else', 'switch', 'case', 'default', 'for', 'foreach', 'do',
-                    'while', 'break', 'continue', 'fallthrough', 'return', 'assert',
-                    'unsafe', 'ext', 'cast'), suffix=r'\b'), Keyword),
-            (words(('const', 'signed', 'unsigned', 'inline', 'public', 'heap', 'compose'),
-                   suffix=r'\b'), Keyword.Pseudo),
-            (words(('new', 'yield', 'stash', 'pick', 'sync', 'class'), suffix=r'\b'),
-                   Keyword.Reserved),
-            (r'(true|false|nil)\b', Keyword.Constant),
-            (words(('double', 'int', 'short', 'long', 'byte', 'char', 'string',
-                    'bool', 'dyn'), suffix=r'\b'), Keyword.Type),
-            (words(('printf', 'sizeof', 'alignof', 'len', 'panic'), suffix=r'\b(\()'),
-             bygroups(Name.Builtin, Punctuation)),
-            # numeric literals
-            (r'[-]?[0-9]*[.][0-9]+([eE][+-]?[0-9]+)?', Number.Double),
-            (r'0[bB][01]+[slu]?', Number.Bin),
-            (r'0[oO][0-7]+[slu]?', Number.Oct),
-            (r'0[xXhH][0-9a-fA-F]+[slu]?', Number.Hex),
-            (r'(0[dD])?[0-9]+[slu]?', Number.Integer),
-            # string literal
-            (r'"(\\\\|\\[^\\]|[^"\\])*"', String),
-            # char literal
-            (r'\'(\\\\|\\[^\\]|[^\'\\])\'', String.Char),
-            # tokens
-            (r'<<=|>>=|<<|>>|<=|>=|\+=|-=|\*=|/=|\%=|\|=|&=|\^=|&&|\|\||&|\||'
-             r'\+\+|--|\%|\^|\~|==|!=|->|::|[.]{3}|#!|#|[+\-*/&]', Operator),
-            (r'[|<>=!()\[\]{}.,;:\?]', Punctuation),
-            # identifiers
-            (r'[^\W\d]\w*', Name.Other),
-        ]
-    }
diff --git a/.venv/lib/python3.12/site-packages/pygments/lexers/sql.py b/.venv/lib/python3.12/site-packages/pygments/lexers/sql.py
deleted file mode 100644
index 1d3458e..0000000
--- a/.venv/lib/python3.12/site-packages/pygments/lexers/sql.py
+++ /dev/null
@@ -1,1111 +0,0 @@
-"""
-    pygments.lexers.sql
-    ~~~~~~~~~~~~~~~~~~~
-
-    Lexers for various SQL dialects and related interactive sessions.
-
-    Postgres specific lexers:
-
-    `PostgresLexer`
-        A SQL lexer for the PostgreSQL dialect. Differences w.r.t. the SQL
-        lexer are:
-
-        - keywords and data types list parsed from the PG docs (run the
-          `_postgres_builtins` module to update them);
-        - Content of $-strings parsed using a specific lexer, e.g. the content
-          of a PL/Python function is parsed using the Python lexer;
-        - parse PG specific constructs: E-strings, $-strings, U&-strings,
-          different operators and punctuation.
-
-    `PlPgsqlLexer`
-        A lexer for the PL/pgSQL language. Adds a few specific construct on
-        top of the PG SQL lexer (such as <{text}' if rule else text
-                    append(text)
-            else:
-                styles: Dict[str, int] = {}
-                for text, style, _ in Segment.filter_control(
-                    Segment.simplify(self._record_buffer)
-                ):
-                    text = escape(text)
-                    if style:
-                        rule = style.get_html_style(_theme)
-                        style_number = styles.setdefault(rule, len(styles) + 1)
-                        if style.link:
-                            text = f'{text}'
-                        else:
-                            text = f'{text}'
-                    append(text)
-                stylesheet_rules: List[str] = []
-                stylesheet_append = stylesheet_rules.append
-                for style_rule, style_number in styles.items():
-                    if style_rule:
-                        stylesheet_append(f".r{style_number} {{{style_rule}}}")
-                stylesheet = "\n".join(stylesheet_rules)
-
-            rendered_code = render_code_format.format(
-                code="".join(fragments),
-                stylesheet=stylesheet,
-                foreground=_theme.foreground_color.hex,
-                background=_theme.background_color.hex,
-            )
-            if clear:
-                del self._record_buffer[:]
-        return rendered_code
-
-    def save_html(
-        self,
-        path: Union[str, PathLike[str]],
-        *,
-        theme: Optional[TerminalTheme] = None,
-        clear: bool = True,
-        code_format: str = CONSOLE_HTML_FORMAT,
-        inline_styles: bool = False,
-    ) -> None:
-        """Generate HTML from console contents and write to a file (requires record=True argument in constructor).
-
-        Args:
-            path (Union[str, PathLike[str]]): Path to write html file.
-            theme (TerminalTheme, optional): TerminalTheme object containing console colors.
-            clear (bool, optional): Clear record buffer after exporting. Defaults to ``True``.
-            code_format (str, optional): Format string to render HTML. In addition to '{foreground}',
-                '{background}', and '{code}', should contain '{stylesheet}' if inline_styles is ``False``.
-            inline_styles (bool, optional): If ``True`` styles will be inlined in to spans, which makes files
-                larger but easier to cut and paste markup. If ``False``, styles will be embedded in a style tag.
-                Defaults to False.
-
-        """
-        html = self.export_html(
-            theme=theme,
-            clear=clear,
-            code_format=code_format,
-            inline_styles=inline_styles,
-        )
-        with open(path, "w", encoding="utf-8") as write_file:
-            write_file.write(html)
-
-    def export_svg(
-        self,
-        *,
-        title: str = "Rich",
-        theme: Optional[TerminalTheme] = None,
-        clear: bool = True,
-        code_format: str = CONSOLE_SVG_FORMAT,
-        font_aspect_ratio: float = 0.61,
-        unique_id: Optional[str] = None,
-    ) -> str:
-        """
-        Generate an SVG from the console contents (requires record=True in Console constructor).
-
-        Args:
-            title (str, optional): The title of the tab in the output image
-            theme (TerminalTheme, optional): The ``TerminalTheme`` object to use to style the terminal
-            clear (bool, optional): Clear record buffer after exporting. Defaults to ``True``
-            code_format (str, optional): Format string used to generate the SVG. Rich will inject a number of variables
-                into the string in order to form the final SVG output. The default template used and the variables
-                injected by Rich can be found by inspecting the ``console.CONSOLE_SVG_FORMAT`` variable.
-            font_aspect_ratio (float, optional): The width to height ratio of the font used in the ``code_format``
-                string. Defaults to 0.61, which is the width to height ratio of Fira Code (the default font).
-                If you aren't specifying a different font inside ``code_format``, you probably don't need this.
-            unique_id (str, optional): unique id that is used as the prefix for various elements (CSS styles, node
-                ids). If not set, this defaults to a computed value based on the recorded content.
-        """
-
-        import zlib
-        from html import escape
-
-        from rich.cells import cell_len
-
-        style_cache: Dict[Style, str] = {}
-
-        def get_svg_style(style: Style) -> str:
-            """Convert a Style to CSS rules for SVG."""
-            if style in style_cache:
-                return style_cache[style]
-            css_rules = []
-            color = (
-                _theme.foreground_color
-                if (style.color is None or style.color.is_default)
-                else style.color.get_truecolor(_theme)
-            )
-            bgcolor = (
-                _theme.background_color
-                if (style.bgcolor is None or style.bgcolor.is_default)
-                else style.bgcolor.get_truecolor(_theme)
-            )
-            if style.reverse:
-                color, bgcolor = bgcolor, color
-            if style.dim:
-                color = blend_rgb(color, bgcolor, 0.4)
-            css_rules.append(f"fill: {color.hex}")
-            if style.bold:
-                css_rules.append("font-weight: bold")
-            if style.italic:
-                css_rules.append("font-style: italic;")
-            if style.underline:
-                css_rules.append("text-decoration: underline;")
-            if style.strike:
-                css_rules.append("text-decoration: line-through;")
-
-            css = ";".join(css_rules)
-            style_cache[style] = css
-            return css
-
-        _theme = theme or SVG_EXPORT_THEME
-
-        width = self.width
-        char_height = 20
-        char_width = char_height * font_aspect_ratio
-        line_height = char_height * 1.22
-
-        margin_top = 1
-        margin_right = 1
-        margin_bottom = 1
-        margin_left = 1
-
-        padding_top = 40
-        padding_right = 8
-        padding_bottom = 8
-        padding_left = 8
-
-        padding_width = padding_left + padding_right
-        padding_height = padding_top + padding_bottom
-        margin_width = margin_left + margin_right
-        margin_height = margin_top + margin_bottom
-
-        text_backgrounds: List[str] = []
-        text_group: List[str] = []
-        classes: Dict[str, int] = {}
-        style_no = 1
-
-        def escape_text(text: str) -> str:
-            """HTML escape text and replace spaces with nbsp."""
-            return escape(text).replace(" ", " ")
-
-        def make_tag(
-            name: str, content: Optional[str] = None, **attribs: object
-        ) -> str:
-            """Make a tag from name, content, and attributes."""
-
-            def stringify(value: object) -> str:
-                if isinstance(value, (float)):
-                    return format(value, "g")
-                return str(value)
-
-            tag_attribs = " ".join(
-                f'{k.lstrip("_").replace("_", "-")}="{stringify(v)}"'
-                for k, v in attribs.items()
-            )
-            return (
-                f"<{name} {tag_attribs}>{content}"
-                if content
-                else f"<{name} {tag_attribs}/>"
-            )
-
-        with self._record_buffer_lock:
-            segments = list(Segment.filter_control(self._record_buffer))
-            if clear:
-                self._record_buffer.clear()
-
-        if unique_id is None:
-            unique_id = "terminal-" + str(
-                zlib.adler32(
-                    ("".join(repr(segment) for segment in segments)).encode(
-                        "utf-8",
-                        "ignore",
-                    )
-                    + title.encode("utf-8", "ignore")
-                )
-            )
-        y = 0
-        for y, line in enumerate(Segment.split_and_crop_lines(segments, length=width)):
-            x = 0
-            for text, style, _control in line:
-                style = style or Style()
-                rules = get_svg_style(style)
-                if rules not in classes:
-                    classes[rules] = style_no
-                    style_no += 1
-                class_name = f"r{classes[rules]}"
-
-                if style.reverse:
-                    has_background = True
-                    background = (
-                        _theme.foreground_color.hex
-                        if style.color is None
-                        else style.color.get_truecolor(_theme).hex
-                    )
-                else:
-                    bgcolor = style.bgcolor
-                    has_background = bgcolor is not None and not bgcolor.is_default
-                    background = (
-                        _theme.background_color.hex
-                        if style.bgcolor is None
-                        else style.bgcolor.get_truecolor(_theme).hex
-                    )
-
-                text_length = cell_len(text)
-                if has_background:
-                    text_backgrounds.append(
-                        make_tag(
-                            "rect",
-                            fill=background,
-                            x=x * char_width,
-                            y=y * line_height + 1.5,
-                            width=char_width * text_length,
-                            height=line_height + 0.25,
-                            shape_rendering="crispEdges",
-                        )
-                    )
-
-                if text != " " * len(text):
-                    text_group.append(
-                        make_tag(
-                            "text",
-                            escape_text(text),
-                            _class=f"{unique_id}-{class_name}",
-                            x=x * char_width,
-                            y=y * line_height + char_height,
-                            textLength=char_width * len(text),
-                            clip_path=f"url(#{unique_id}-line-{y})",
-                        )
-                    )
-                x += cell_len(text)
-
-        line_offsets = [line_no * line_height + 1.5 for line_no in range(y)]
-        lines = "\n".join(
-            f"""
-    {make_tag("rect", x=0, y=offset, width=char_width * width, height=line_height + 0.25)}
-            """
-            for line_no, offset in enumerate(line_offsets)
-        )
-
-        styles = "\n".join(
-            f".{unique_id}-r{rule_no} {{ {css} }}" for css, rule_no in classes.items()
-        )
-        backgrounds = "".join(text_backgrounds)
-        matrix = "".join(text_group)
-
-        terminal_width = ceil(width * char_width + padding_width)
-        terminal_height = (y + 1) * line_height + padding_height
-        chrome = make_tag(
-            "rect",
-            fill=_theme.background_color.hex,
-            stroke="rgba(255,255,255,0.35)",
-            stroke_width="1",
-            x=margin_left,
-            y=margin_top,
-            width=terminal_width,
-            height=terminal_height,
-            rx=8,
-        )
-
-        title_color = _theme.foreground_color.hex
-        if title:
-            chrome += make_tag(
-                "text",
-                escape_text(title),
-                _class=f"{unique_id}-title",
-                fill=title_color,
-                text_anchor="middle",
-                x=terminal_width // 2,
-                y=margin_top + char_height + 6,
-            )
-        chrome += f"""
-            
-            
-            
-            
-            
-        """
-
-        svg = code_format.format(
-            unique_id=unique_id,
-            char_width=char_width,
-            char_height=char_height,
-            line_height=line_height,
-            terminal_width=char_width * width - 1,
-            terminal_height=(y + 1) * line_height - 1,
-            width=terminal_width + margin_width,
-            height=terminal_height + margin_height,
-            terminal_x=margin_left + padding_left,
-            terminal_y=margin_top + padding_top,
-            styles=styles,
-            chrome=chrome,
-            backgrounds=backgrounds,
-            matrix=matrix,
-            lines=lines,
-        )
-        return svg
-
-    def save_svg(
-        self,
-        path: Union[str, PathLike[str]],
-        *,
-        title: str = "Rich",
-        theme: Optional[TerminalTheme] = None,
-        clear: bool = True,
-        code_format: str = CONSOLE_SVG_FORMAT,
-        font_aspect_ratio: float = 0.61,
-        unique_id: Optional[str] = None,
-    ) -> None:
-        """Generate an SVG file from the console contents (requires record=True in Console constructor).
-
-        Args:
-            path (Union[str, PathLike[str]]): The path to write the SVG to.
-            title (str, optional): The title of the tab in the output image
-            theme (TerminalTheme, optional): The ``TerminalTheme`` object to use to style the terminal
-            clear (bool, optional): Clear record buffer after exporting. Defaults to ``True``
-            code_format (str, optional): Format string used to generate the SVG. Rich will inject a number of variables
-                into the string in order to form the final SVG output. The default template used and the variables
-                injected by Rich can be found by inspecting the ``console.CONSOLE_SVG_FORMAT`` variable.
-            font_aspect_ratio (float, optional): The width to height ratio of the font used in the ``code_format``
-                string. Defaults to 0.61, which is the width to height ratio of Fira Code (the default font).
-                If you aren't specifying a different font inside ``code_format``, you probably don't need this.
-            unique_id (str, optional): unique id that is used as the prefix for various elements (CSS styles, node
-                ids). If not set, this defaults to a computed value based on the recorded content.
-        """
-        svg = self.export_svg(
-            title=title,
-            theme=theme,
-            clear=clear,
-            code_format=code_format,
-            font_aspect_ratio=font_aspect_ratio,
-            unique_id=unique_id,
-        )
-        with open(path, "w", encoding="utf-8") as write_file:
-            write_file.write(svg)
-
-
-if __name__ == "__main__":  # pragma: no cover
-    console = Console(record=True)
-
-    console.log(
-        "JSONRPC [i]request[/i]",
-        5,
-        1.3,
-        True,
-        False,
-        None,
-        {
-            "jsonrpc": "2.0",
-            "method": "subtract",
-            "params": {"minuend": 42, "subtrahend": 23},
-            "id": 3,
-        },
-    )
-
-    console.log("Hello, World!", "{'a': 1}", repr(console))
-
-    console.print(
-        {
-            "name": None,
-            "empty": [],
-            "quiz": {
-                "sport": {
-                    "answered": True,
-                    "q1": {
-                        "question": "Which one is correct team name in NBA?",
-                        "options": [
-                            "New York Bulls",
-                            "Los Angeles Kings",
-                            "Golden State Warriors",
-                            "Huston Rocket",
-                        ],
-                        "answer": "Huston Rocket",
-                    },
-                },
-                "maths": {
-                    "answered": False,
-                    "q1": {
-                        "question": "5 + 7 = ?",
-                        "options": [10, 11, 12, 13],
-                        "answer": 12,
-                    },
-                    "q2": {
-                        "question": "12 - 8 = ?",
-                        "options": [1, 2, 3, 4],
-                        "answer": 4,
-                    },
-                },
-            },
-        }
-    )
diff --git a/.venv/lib/python3.12/site-packages/rich/constrain.py b/.venv/lib/python3.12/site-packages/rich/constrain.py
deleted file mode 100644
index 65fdf56..0000000
--- a/.venv/lib/python3.12/site-packages/rich/constrain.py
+++ /dev/null
@@ -1,37 +0,0 @@
-from typing import Optional, TYPE_CHECKING
-
-from .jupyter import JupyterMixin
-from .measure import Measurement
-
-if TYPE_CHECKING:
-    from .console import Console, ConsoleOptions, RenderableType, RenderResult
-
-
-class Constrain(JupyterMixin):
-    """Constrain the width of a renderable to a given number of characters.
-
-    Args:
-        renderable (RenderableType): A renderable object.
-        width (int, optional): The maximum width (in characters) to render. Defaults to 80.
-    """
-
-    def __init__(self, renderable: "RenderableType", width: Optional[int] = 80) -> None:
-        self.renderable = renderable
-        self.width = width
-
-    def __rich_console__(
-        self, console: "Console", options: "ConsoleOptions"
-    ) -> "RenderResult":
-        if self.width is None:
-            yield self.renderable
-        else:
-            child_options = options.update_width(min(self.width, options.max_width))
-            yield from console.render(self.renderable, child_options)
-
-    def __rich_measure__(
-        self, console: "Console", options: "ConsoleOptions"
-    ) -> "Measurement":
-        if self.width is not None:
-            options = options.update_width(self.width)
-        measurement = Measurement.get(console, options, self.renderable)
-        return measurement
diff --git a/.venv/lib/python3.12/site-packages/rich/containers.py b/.venv/lib/python3.12/site-packages/rich/containers.py
deleted file mode 100644
index 901ff8b..0000000
--- a/.venv/lib/python3.12/site-packages/rich/containers.py
+++ /dev/null
@@ -1,167 +0,0 @@
-from itertools import zip_longest
-from typing import (
-    TYPE_CHECKING,
-    Iterable,
-    Iterator,
-    List,
-    Optional,
-    TypeVar,
-    Union,
-    overload,
-)
-
-if TYPE_CHECKING:
-    from .console import (
-        Console,
-        ConsoleOptions,
-        JustifyMethod,
-        OverflowMethod,
-        RenderResult,
-        RenderableType,
-    )
-    from .text import Text
-
-from .cells import cell_len
-from .measure import Measurement
-
-T = TypeVar("T")
-
-
-class Renderables:
-    """A list subclass which renders its contents to the console."""
-
-    def __init__(
-        self, renderables: Optional[Iterable["RenderableType"]] = None
-    ) -> None:
-        self._renderables: List["RenderableType"] = (
-            list(renderables) if renderables is not None else []
-        )
-
-    def __rich_console__(
-        self, console: "Console", options: "ConsoleOptions"
-    ) -> "RenderResult":
-        """Console render method to insert line-breaks."""
-        yield from self._renderables
-
-    def __rich_measure__(
-        self, console: "Console", options: "ConsoleOptions"
-    ) -> "Measurement":
-        dimensions = [
-            Measurement.get(console, options, renderable)
-            for renderable in self._renderables
-        ]
-        if not dimensions:
-            return Measurement(1, 1)
-        _min = max(dimension.minimum for dimension in dimensions)
-        _max = max(dimension.maximum for dimension in dimensions)
-        return Measurement(_min, _max)
-
-    def append(self, renderable: "RenderableType") -> None:
-        self._renderables.append(renderable)
-
-    def __iter__(self) -> Iterable["RenderableType"]:
-        return iter(self._renderables)
-
-
-class Lines:
-    """A list subclass which can render to the console."""
-
-    def __init__(self, lines: Iterable["Text"] = ()) -> None:
-        self._lines: List["Text"] = list(lines)
-
-    def __repr__(self) -> str:
-        return f"Lines({self._lines!r})"
-
-    def __iter__(self) -> Iterator["Text"]:
-        return iter(self._lines)
-
-    @overload
-    def __getitem__(self, index: int) -> "Text":
-        ...
-
-    @overload
-    def __getitem__(self, index: slice) -> List["Text"]:
-        ...
-
-    def __getitem__(self, index: Union[slice, int]) -> Union["Text", List["Text"]]:
-        return self._lines[index]
-
-    def __setitem__(self, index: int, value: "Text") -> "Lines":
-        self._lines[index] = value
-        return self
-
-    def __len__(self) -> int:
-        return self._lines.__len__()
-
-    def __rich_console__(
-        self, console: "Console", options: "ConsoleOptions"
-    ) -> "RenderResult":
-        """Console render method to insert line-breaks."""
-        yield from self._lines
-
-    def append(self, line: "Text") -> None:
-        self._lines.append(line)
-
-    def extend(self, lines: Iterable["Text"]) -> None:
-        self._lines.extend(lines)
-
-    def pop(self, index: int = -1) -> "Text":
-        return self._lines.pop(index)
-
-    def justify(
-        self,
-        console: "Console",
-        width: int,
-        justify: "JustifyMethod" = "left",
-        overflow: "OverflowMethod" = "fold",
-    ) -> None:
-        """Justify and overflow text to a given width.
-
-        Args:
-            console (Console): Console instance.
-            width (int): Number of cells available per line.
-            justify (str, optional): Default justify method for text: "left", "center", "full" or "right". Defaults to "left".
-            overflow (str, optional): Default overflow for text: "crop", "fold", or "ellipsis". Defaults to "fold".
-
-        """
-        from .text import Text
-
-        if justify == "left":
-            for line in self._lines:
-                line.truncate(width, overflow=overflow, pad=True)
-        elif justify == "center":
-            for line in self._lines:
-                line.rstrip()
-                line.truncate(width, overflow=overflow)
-                line.pad_left((width - cell_len(line.plain)) // 2)
-                line.pad_right(width - cell_len(line.plain))
-        elif justify == "right":
-            for line in self._lines:
-                line.rstrip()
-                line.truncate(width, overflow=overflow)
-                line.pad_left(width - cell_len(line.plain))
-        elif justify == "full":
-            for line_index, line in enumerate(self._lines):
-                if line_index == len(self._lines) - 1:
-                    break
-                words = line.split(" ")
-                words_size = sum(cell_len(word.plain) for word in words)
-                num_spaces = len(words) - 1
-                spaces = [1 for _ in range(num_spaces)]
-                index = 0
-                if spaces:
-                    while words_size + num_spaces < width:
-                        spaces[len(spaces) - index - 1] += 1
-                        num_spaces += 1
-                        index = (index + 1) % len(spaces)
-                tokens: List[Text] = []
-                for index, (word, next_word) in enumerate(
-                    zip_longest(words, words[1:])
-                ):
-                    tokens.append(word)
-                    if index < len(spaces):
-                        style = word.get_style_at_offset(console, -1)
-                        next_style = next_word.get_style_at_offset(console, 0)
-                        space_style = style if style == next_style else line.style
-                        tokens.append(Text(" " * spaces[index], style=space_style))
-                self[line_index] = Text("").join(tokens)
diff --git a/.venv/lib/python3.12/site-packages/rich/control.py b/.venv/lib/python3.12/site-packages/rich/control.py
deleted file mode 100644
index 248b0f5..0000000
--- a/.venv/lib/python3.12/site-packages/rich/control.py
+++ /dev/null
@@ -1,219 +0,0 @@
-import time
-from typing import TYPE_CHECKING, Callable, Dict, Iterable, List, Union, Final
-
-from .segment import ControlCode, ControlType, Segment
-
-if TYPE_CHECKING:
-    from .console import Console, ConsoleOptions, RenderResult
-
-STRIP_CONTROL_CODES: Final = [
-    7,  # Bell
-    8,  # Backspace
-    11,  # Vertical tab
-    12,  # Form feed
-    13,  # Carriage return
-]
-_CONTROL_STRIP_TRANSLATE: Final = {
-    _codepoint: None for _codepoint in STRIP_CONTROL_CODES
-}
-
-CONTROL_ESCAPE: Final = {
-    7: "\\a",
-    8: "\\b",
-    11: "\\v",
-    12: "\\f",
-    13: "\\r",
-}
-
-CONTROL_CODES_FORMAT: Dict[int, Callable[..., str]] = {
-    ControlType.BELL: lambda: "\x07",
-    ControlType.CARRIAGE_RETURN: lambda: "\r",
-    ControlType.HOME: lambda: "\x1b[H",
-    ControlType.CLEAR: lambda: "\x1b[2J",
-    ControlType.ENABLE_ALT_SCREEN: lambda: "\x1b[?1049h",
-    ControlType.DISABLE_ALT_SCREEN: lambda: "\x1b[?1049l",
-    ControlType.SHOW_CURSOR: lambda: "\x1b[?25h",
-    ControlType.HIDE_CURSOR: lambda: "\x1b[?25l",
-    ControlType.CURSOR_UP: lambda param: f"\x1b[{param}A",
-    ControlType.CURSOR_DOWN: lambda param: f"\x1b[{param}B",
-    ControlType.CURSOR_FORWARD: lambda param: f"\x1b[{param}C",
-    ControlType.CURSOR_BACKWARD: lambda param: f"\x1b[{param}D",
-    ControlType.CURSOR_MOVE_TO_COLUMN: lambda param: f"\x1b[{param+1}G",
-    ControlType.ERASE_IN_LINE: lambda param: f"\x1b[{param}K",
-    ControlType.CURSOR_MOVE_TO: lambda x, y: f"\x1b[{y+1};{x+1}H",
-    ControlType.SET_WINDOW_TITLE: lambda title: f"\x1b]0;{title}\x07",
-}
-
-
-class Control:
-    """A renderable that inserts a control code (non printable but may move cursor).
-
-    Args:
-        *codes (str): Positional arguments are either a :class:`~rich.segment.ControlType` enum or a
-            tuple of ControlType and an integer parameter
-    """
-
-    __slots__ = ["segment"]
-
-    def __init__(self, *codes: Union[ControlType, ControlCode]) -> None:
-        control_codes: List[ControlCode] = [
-            (code,) if isinstance(code, ControlType) else code for code in codes
-        ]
-        _format_map = CONTROL_CODES_FORMAT
-        rendered_codes = "".join(
-            _format_map[code](*parameters) for code, *parameters in control_codes
-        )
-        self.segment = Segment(rendered_codes, None, control_codes)
-
-    @classmethod
-    def bell(cls) -> "Control":
-        """Ring the 'bell'."""
-        return cls(ControlType.BELL)
-
-    @classmethod
-    def home(cls) -> "Control":
-        """Move cursor to 'home' position."""
-        return cls(ControlType.HOME)
-
-    @classmethod
-    def move(cls, x: int = 0, y: int = 0) -> "Control":
-        """Move cursor relative to current position.
-
-        Args:
-            x (int): X offset.
-            y (int): Y offset.
-
-        Returns:
-            ~Control: Control object.
-
-        """
-
-        def get_codes() -> Iterable[ControlCode]:
-            control = ControlType
-            if x:
-                yield (
-                    control.CURSOR_FORWARD if x > 0 else control.CURSOR_BACKWARD,
-                    abs(x),
-                )
-            if y:
-                yield (
-                    control.CURSOR_DOWN if y > 0 else control.CURSOR_UP,
-                    abs(y),
-                )
-
-        control = cls(*get_codes())
-        return control
-
-    @classmethod
-    def move_to_column(cls, x: int, y: int = 0) -> "Control":
-        """Move to the given column, optionally add offset to row.
-
-        Returns:
-            x (int): absolute x (column)
-            y (int): optional y offset (row)
-
-        Returns:
-            ~Control: Control object.
-        """
-
-        return (
-            cls(
-                (ControlType.CURSOR_MOVE_TO_COLUMN, x),
-                (
-                    ControlType.CURSOR_DOWN if y > 0 else ControlType.CURSOR_UP,
-                    abs(y),
-                ),
-            )
-            if y
-            else cls((ControlType.CURSOR_MOVE_TO_COLUMN, x))
-        )
-
-    @classmethod
-    def move_to(cls, x: int, y: int) -> "Control":
-        """Move cursor to absolute position.
-
-        Args:
-            x (int): x offset (column)
-            y (int): y offset (row)
-
-        Returns:
-            ~Control: Control object.
-        """
-        return cls((ControlType.CURSOR_MOVE_TO, x, y))
-
-    @classmethod
-    def clear(cls) -> "Control":
-        """Clear the screen."""
-        return cls(ControlType.CLEAR)
-
-    @classmethod
-    def show_cursor(cls, show: bool) -> "Control":
-        """Show or hide the cursor."""
-        return cls(ControlType.SHOW_CURSOR if show else ControlType.HIDE_CURSOR)
-
-    @classmethod
-    def alt_screen(cls, enable: bool) -> "Control":
-        """Enable or disable alt screen."""
-        if enable:
-            return cls(ControlType.ENABLE_ALT_SCREEN, ControlType.HOME)
-        else:
-            return cls(ControlType.DISABLE_ALT_SCREEN)
-
-    @classmethod
-    def title(cls, title: str) -> "Control":
-        """Set the terminal window title
-
-        Args:
-            title (str): The new terminal window title
-        """
-        return cls((ControlType.SET_WINDOW_TITLE, title))
-
-    def __str__(self) -> str:
-        return self.segment.text
-
-    def __rich_console__(
-        self, console: "Console", options: "ConsoleOptions"
-    ) -> "RenderResult":
-        if self.segment.text:
-            yield self.segment
-
-
-def strip_control_codes(
-    text: str, _translate_table: Dict[int, None] = _CONTROL_STRIP_TRANSLATE
-) -> str:
-    """Remove control codes from text.
-
-    Args:
-        text (str): A string possibly contain control codes.
-
-    Returns:
-        str: String with control codes removed.
-    """
-    return text.translate(_translate_table)
-
-
-def escape_control_codes(
-    text: str,
-    _translate_table: Dict[int, str] = CONTROL_ESCAPE,
-) -> str:
-    """Replace control codes with their "escaped" equivalent in the given text.
-    (e.g. "\b" becomes "\\b")
-
-    Args:
-        text (str): A string possibly containing control codes.
-
-    Returns:
-        str: String with control codes replaced with their escaped version.
-    """
-    return text.translate(_translate_table)
-
-
-if __name__ == "__main__":  # pragma: no cover
-    from rich.console import Console
-
-    console = Console()
-    console.print("Look at the title of your terminal window ^")
-    # console.print(Control((ControlType.SET_WINDOW_TITLE, "Hello, world!")))
-    for i in range(10):
-        console.set_window_title("🚀 Loading" + "." * i)
-        time.sleep(0.5)
diff --git a/.venv/lib/python3.12/site-packages/rich/default_styles.py b/.venv/lib/python3.12/site-packages/rich/default_styles.py
deleted file mode 100644
index f2e4cd1..0000000
--- a/.venv/lib/python3.12/site-packages/rich/default_styles.py
+++ /dev/null
@@ -1,196 +0,0 @@
-from typing import Dict
-
-from .style import Style
-
-DEFAULT_STYLES: Dict[str, Style] = {
-    "none": Style.null(),
-    "reset": Style(
-        color="default",
-        bgcolor="default",
-        dim=False,
-        bold=False,
-        italic=False,
-        underline=False,
-        blink=False,
-        blink2=False,
-        reverse=False,
-        conceal=False,
-        strike=False,
-    ),
-    "dim": Style(dim=True),
-    "bright": Style(dim=False),
-    "bold": Style(bold=True),
-    "strong": Style(bold=True),
-    "code": Style(reverse=True, bold=True),
-    "italic": Style(italic=True),
-    "emphasize": Style(italic=True),
-    "underline": Style(underline=True),
-    "blink": Style(blink=True),
-    "blink2": Style(blink2=True),
-    "reverse": Style(reverse=True),
-    "strike": Style(strike=True),
-    "black": Style(color="black"),
-    "red": Style(color="red"),
-    "green": Style(color="green"),
-    "yellow": Style(color="yellow"),
-    "magenta": Style(color="magenta"),
-    "cyan": Style(color="cyan"),
-    "white": Style(color="white"),
-    "inspect.attr": Style(color="yellow", italic=True),
-    "inspect.attr.dunder": Style(color="yellow", italic=True, dim=True),
-    "inspect.callable": Style(bold=True, color="red"),
-    "inspect.async_def": Style(italic=True, color="bright_cyan"),
-    "inspect.def": Style(italic=True, color="bright_cyan"),
-    "inspect.class": Style(italic=True, color="bright_cyan"),
-    "inspect.error": Style(bold=True, color="red"),
-    "inspect.equals": Style(),
-    "inspect.help": Style(color="cyan"),
-    "inspect.doc": Style(dim=True),
-    "inspect.value.border": Style(color="green"),
-    "live.ellipsis": Style(bold=True, color="red"),
-    "layout.tree.row": Style(dim=False, color="red"),
-    "layout.tree.column": Style(dim=False, color="blue"),
-    "logging.keyword": Style(bold=True, color="yellow"),
-    "logging.level.notset": Style(dim=True),
-    "logging.level.debug": Style(color="green"),
-    "logging.level.info": Style(color="blue"),
-    "logging.level.warning": Style(color="yellow"),
-    "logging.level.error": Style(color="red", bold=True),
-    "logging.level.critical": Style(color="red", bold=True, reverse=True),
-    "log.level": Style.null(),
-    "log.time": Style(color="cyan", dim=True),
-    "log.message": Style.null(),
-    "log.path": Style(dim=True),
-    "repr.ellipsis": Style(color="yellow"),
-    "repr.indent": Style(color="green", dim=True),
-    "repr.error": Style(color="red", bold=True),
-    "repr.str": Style(color="green", italic=False, bold=False),
-    "repr.brace": Style(bold=True),
-    "repr.comma": Style(bold=True),
-    "repr.ipv4": Style(bold=True, color="bright_green"),
-    "repr.ipv6": Style(bold=True, color="bright_green"),
-    "repr.eui48": Style(bold=True, color="bright_green"),
-    "repr.eui64": Style(bold=True, color="bright_green"),
-    "repr.tag_start": Style(bold=True),
-    "repr.tag_name": Style(color="bright_magenta", bold=True),
-    "repr.tag_contents": Style(color="default"),
-    "repr.tag_end": Style(bold=True),
-    "repr.attrib_name": Style(color="yellow", italic=False),
-    "repr.attrib_equal": Style(bold=True),
-    "repr.attrib_value": Style(color="magenta", italic=False),
-    "repr.number": Style(color="cyan", bold=True, italic=False),
-    "repr.number_complex": Style(color="cyan", bold=True, italic=False),  # same
-    "repr.bool_true": Style(color="bright_green", italic=True),
-    "repr.bool_false": Style(color="bright_red", italic=True),
-    "repr.none": Style(color="magenta", italic=True),
-    "repr.url": Style(underline=True, color="bright_blue", italic=False, bold=False),
-    "repr.uuid": Style(color="bright_yellow", bold=False),
-    "repr.call": Style(color="magenta", bold=True),
-    "repr.path": Style(color="magenta"),
-    "repr.filename": Style(color="bright_magenta"),
-    "rule.line": Style(color="bright_green"),
-    "rule.text": Style.null(),
-    "json.brace": Style(bold=True),
-    "json.bool_true": Style(color="bright_green", italic=True),
-    "json.bool_false": Style(color="bright_red", italic=True),
-    "json.null": Style(color="magenta", italic=True),
-    "json.number": Style(color="cyan", bold=True, italic=False),
-    "json.str": Style(color="green", italic=False, bold=False),
-    "json.key": Style(color="blue", bold=True),
-    "prompt": Style.null(),
-    "prompt.choices": Style(color="magenta", bold=True),
-    "prompt.default": Style(color="cyan", bold=True),
-    "prompt.invalid": Style(color="red"),
-    "prompt.invalid.choice": Style(color="red"),
-    "pretty": Style.null(),
-    "scope.border": Style(color="blue"),
-    "scope.key": Style(color="yellow", italic=True),
-    "scope.key.special": Style(color="yellow", italic=True, dim=True),
-    "scope.equals": Style(color="red"),
-    "table.header": Style(bold=True),
-    "table.footer": Style(bold=True),
-    "table.cell": Style.null(),
-    "table.title": Style(italic=True),
-    "table.caption": Style(italic=True, dim=True),
-    "traceback.error": Style(color="red", italic=True),
-    "traceback.border.syntax_error": Style(color="bright_red"),
-    "traceback.border": Style(color="red"),
-    "traceback.text": Style.null(),
-    "traceback.title": Style(color="red", bold=True),
-    "traceback.exc_type": Style(color="bright_red", bold=True),
-    "traceback.exc_value": Style.null(),
-    "traceback.offset": Style(color="bright_red", bold=True),
-    "traceback.error_range": Style(underline=True, bold=True),
-    "traceback.note": Style(color="green", bold=True),
-    "traceback.group.border": Style(color="magenta"),
-    "bar.back": Style(color="grey23"),
-    "bar.complete": Style(color="rgb(249,38,114)"),
-    "bar.finished": Style(color="rgb(114,156,31)"),
-    "bar.pulse": Style(color="rgb(249,38,114)"),
-    "progress.description": Style.null(),
-    "progress.filesize": Style(color="green"),
-    "progress.filesize.total": Style(color="green"),
-    "progress.download": Style(color="green"),
-    "progress.elapsed": Style(color="yellow"),
-    "progress.percentage": Style(color="magenta"),
-    "progress.remaining": Style(color="cyan"),
-    "progress.data.speed": Style(color="red"),
-    "progress.spinner": Style(color="green"),
-    "status.spinner": Style(color="green"),
-    "tree": Style(),
-    "tree.line": Style(),
-    "markdown.paragraph": Style(),
-    "markdown.text": Style(),
-    "markdown.em": Style(italic=True),
-    "markdown.emph": Style(italic=True),  # For commonmark backwards compatibility
-    "markdown.strong": Style(bold=True),
-    "markdown.code": Style(bold=True, color="cyan", bgcolor="black"),
-    "markdown.code_block": Style(color="cyan", bgcolor="black"),
-    "markdown.block_quote": Style(color="magenta"),
-    "markdown.list": Style(color="cyan"),
-    "markdown.item": Style(),
-    "markdown.item.bullet": Style(bold=True),
-    "markdown.item.number": Style(color="cyan"),
-    "markdown.hr": Style(dim=True),
-    "markdown.h1.border": Style(),
-    "markdown.h1": Style(bold=True, underline=True),
-    "markdown.h2": Style(color="magenta", underline=True),
-    "markdown.h3": Style(color="magenta", bold=True),
-    "markdown.h4": Style(color="magenta", italic=True),
-    "markdown.h5": Style(italic=True),
-    "markdown.h6": Style(dim=True),
-    "markdown.h7": Style(italic=True, dim=True),
-    "markdown.link": Style(color="bright_blue"),
-    "markdown.link_url": Style(color="blue", underline=True),
-    "markdown.s": Style(strike=True),
-    "markdown.table.border": Style(color="cyan"),
-    "markdown.table.header": Style(color="cyan", bold=False),
-    "markdown.kbd": Style(bold=True, color="bright_yellow"),
-    "iso8601.date": Style(color="blue"),
-    "iso8601.time": Style(color="magenta"),
-    "iso8601.timezone": Style(color="yellow"),
-}
-
-
-if __name__ == "__main__":  # pragma: no cover
-    import argparse
-    import io
-
-    from rich.console import Console
-    from rich.table import Table
-    from rich.text import Text
-
-    parser = argparse.ArgumentParser()
-    parser.add_argument("--html", action="store_true", help="Export as HTML table")
-    args = parser.parse_args()
-    html: bool = args.html
-    console = Console(record=True, width=70, file=io.StringIO()) if html else Console()
-
-    table = Table("Name", "Styling")
-
-    for style_name, style in DEFAULT_STYLES.items():
-        table.add_row(Text(style_name, style=style), str(style))
-
-    console.print(table)
-    if html:
-        print(console.export_html(inline_styles=True))
diff --git a/.venv/lib/python3.12/site-packages/rich/diagnose.py b/.venv/lib/python3.12/site-packages/rich/diagnose.py
deleted file mode 100644
index 9d5ff3e..0000000
--- a/.venv/lib/python3.12/site-packages/rich/diagnose.py
+++ /dev/null
@@ -1,39 +0,0 @@
-import os
-import platform
-
-from rich import inspect
-from rich.console import Console, get_windows_console_features
-from rich.panel import Panel
-from rich.pretty import Pretty
-
-
-def report() -> None:  # pragma: no cover
-    """Print a report to the terminal with debugging information"""
-    console = Console()
-    inspect(console)
-    features = get_windows_console_features()
-    inspect(features)
-
-    env_names = (
-        "CLICOLOR",
-        "COLORTERM",
-        "COLUMNS",
-        "JPY_PARENT_PID",
-        "JUPYTER_COLUMNS",
-        "JUPYTER_LINES",
-        "LINES",
-        "NO_COLOR",
-        "TERM_PROGRAM",
-        "TERM",
-        "TTY_COMPATIBLE",
-        "TTY_INTERACTIVE",
-        "VSCODE_VERBOSE_LOGGING",
-    )
-    env = {name: os.getenv(name) for name in env_names}
-    console.print(Panel.fit((Pretty(env)), title="[b]Environment Variables"))
-
-    console.print(f'platform="{platform.system()}"')
-
-
-if __name__ == "__main__":  # pragma: no cover
-    report()
diff --git a/.venv/lib/python3.12/site-packages/rich/emoji.py b/.venv/lib/python3.12/site-packages/rich/emoji.py
deleted file mode 100644
index 067f93c..0000000
--- a/.venv/lib/python3.12/site-packages/rich/emoji.py
+++ /dev/null
@@ -1,93 +0,0 @@
-import sys
-from typing import TYPE_CHECKING, Literal, Optional, Union
-
-from ._emoji_replace import _emoji_replace
-from .jupyter import JupyterMixin
-from .segment import Segment
-from .style import Style
-
-if TYPE_CHECKING:
-    from .console import Console, ConsoleOptions, RenderResult
-
-
-EmojiVariant = Literal["emoji", "text"]
-
-
-class NoEmoji(Exception):
-    """No emoji by that name."""
-
-
-class Emoji(JupyterMixin):
-    __slots__ = ["name", "style", "_char", "variant"]
-
-    VARIANTS = {"text": "\ufe0e", "emoji": "\ufe0f"}
-
-    def __init__(
-        self,
-        name: str,
-        style: Union[str, Style] = "none",
-        variant: Optional[EmojiVariant] = None,
-    ) -> None:
-        """A single emoji character.
-
-        Args:
-            name (str): Name of emoji.
-            style (Union[str, Style], optional): Optional style. Defaults to None.
-
-        Raises:
-            NoEmoji: If the emoji doesn't exist.
-        """
-        from ._emoji_codes import EMOJI
-
-        self.name = name
-        self.style = style
-        self.variant = variant
-        try:
-            self._char = EMOJI[name]
-        except KeyError:
-            raise NoEmoji(f"No emoji called {name!r}")
-        if variant is not None:
-            self._char += self.VARIANTS.get(variant, "")
-
-    @classmethod
-    def replace(cls, text: str) -> str:
-        """Replace emoji markup with corresponding unicode characters.
-
-        Args:
-            text (str): A string with emojis codes, e.g. "Hello :smiley:!"
-
-        Returns:
-            str: A string with emoji codes replaces with actual emoji.
-        """
-        return _emoji_replace(text)
-
-    def __repr__(self) -> str:
-        return f""
-
-    def __str__(self) -> str:
-        return self._char
-
-    def __rich_console__(
-        self, console: "Console", options: "ConsoleOptions"
-    ) -> "RenderResult":
-        yield Segment(self._char, console.get_style(self.style))
-
-
-if __name__ == "__main__":  # pragma: no cover
-    import sys
-
-    from rich.columns import Columns
-    from rich.console import Console
-
-    console = Console(record=True)
-
-    from ._emoji_codes import EMOJI
-
-    columns = Columns(
-        (f":{name}: {name}" for name in sorted(EMOJI.keys()) if "\u200d" not in name),
-        column_first=True,
-    )
-
-    console.print(columns)
-    if len(sys.argv) > 1:
-        console.save_html(sys.argv[1])
diff --git a/.venv/lib/python3.12/site-packages/rich/errors.py b/.venv/lib/python3.12/site-packages/rich/errors.py
deleted file mode 100644
index 0bcbe53..0000000
--- a/.venv/lib/python3.12/site-packages/rich/errors.py
+++ /dev/null
@@ -1,34 +0,0 @@
-class ConsoleError(Exception):
-    """An error in console operation."""
-
-
-class StyleError(Exception):
-    """An error in styles."""
-
-
-class StyleSyntaxError(ConsoleError):
-    """Style was badly formatted."""
-
-
-class MissingStyle(StyleError):
-    """No such style."""
-
-
-class StyleStackError(ConsoleError):
-    """Style stack is invalid."""
-
-
-class NotRenderableError(ConsoleError):
-    """Object is not renderable."""
-
-
-class MarkupError(ConsoleError):
-    """Markup was badly formatted."""
-
-
-class LiveError(ConsoleError):
-    """Error related to Live display."""
-
-
-class NoAltScreen(ConsoleError):
-    """Alt screen mode was required."""
diff --git a/.venv/lib/python3.12/site-packages/rich/file_proxy.py b/.venv/lib/python3.12/site-packages/rich/file_proxy.py
deleted file mode 100644
index e32523b..0000000
--- a/.venv/lib/python3.12/site-packages/rich/file_proxy.py
+++ /dev/null
@@ -1,60 +0,0 @@
-import io
-from typing import IO, TYPE_CHECKING, Any, List
-
-from .ansi import AnsiDecoder
-from .text import Text
-
-if TYPE_CHECKING:
-    from .console import Console
-
-
-class FileProxy(io.TextIOBase):
-    """Wraps a file (e.g. sys.stdout) and redirects writes to a console."""
-
-    def __init__(self, console: "Console", file: IO[str]) -> None:
-        self.__console = console
-        self.__file = file
-        self.__buffer: List[str] = []
-        self.__ansi_decoder = AnsiDecoder()
-
-    @property
-    def rich_proxied_file(self) -> IO[str]:
-        """Get proxied file."""
-        return self.__file
-
-    def __getattr__(self, name: str) -> Any:
-        return getattr(self.__file, name)
-
-    def write(self, text: str) -> int:
-        if not isinstance(text, str):
-            raise TypeError(f"write() argument must be str, not {type(text).__name__}")
-        buffer = self.__buffer
-        lines: List[str] = []
-        while text:
-            line, new_line, text = text.partition("\n")
-            if new_line:
-                lines.append("".join(buffer) + line)
-                buffer.clear()
-            else:
-                buffer.append(line)
-                break
-        if lines:
-            console = self.__console
-            with console:
-                output = Text("\n").join(
-                    self.__ansi_decoder.decode_line(line) for line in lines
-                )
-                console.print(output)
-        return len(text)
-
-    def flush(self) -> None:
-        output = "".join(self.__buffer)
-        if output:
-            self.__console.print(output)
-        del self.__buffer[:]
-
-    def fileno(self) -> int:
-        return self.__file.fileno()
-
-    def isatty(self) -> bool:
-        return self.__file.isatty()
diff --git a/.venv/lib/python3.12/site-packages/rich/filesize.py b/.venv/lib/python3.12/site-packages/rich/filesize.py
deleted file mode 100644
index 83bc911..0000000
--- a/.venv/lib/python3.12/site-packages/rich/filesize.py
+++ /dev/null
@@ -1,88 +0,0 @@
-"""Functions for reporting filesizes. Borrowed from https://github.com/PyFilesystem/pyfilesystem2
-
-The functions declared in this module should cover the different
-use cases needed to generate a string representation of a file size
-using several different units. Since there are many standards regarding
-file size units, three different functions have been implemented.
-
-See Also:
-    * `Wikipedia: Binary prefix `_
-
-"""
-
-__all__ = ["decimal"]
-
-from typing import Iterable, List, Optional, Tuple
-
-
-def _to_str(
-    size: int,
-    suffixes: Iterable[str],
-    base: int,
-    *,
-    precision: Optional[int] = 1,
-    separator: Optional[str] = " ",
-) -> str:
-    if size == 1:
-        return "1 byte"
-    elif size < base:
-        return f"{size:,} bytes"
-
-    for i, suffix in enumerate(suffixes, 2):  # noqa: B007
-        unit = base**i
-        if size < unit:
-            break
-    return "{:,.{precision}f}{separator}{}".format(
-        (base * size / unit),
-        suffix,
-        precision=precision,
-        separator=separator,
-    )
-
-
-def pick_unit_and_suffix(size: int, suffixes: List[str], base: int) -> Tuple[int, str]:
-    """Pick a suffix and base for the given size."""
-    for i, suffix in enumerate(suffixes):
-        unit = base**i
-        if size < unit * base:
-            break
-    return unit, suffix
-
-
-def decimal(
-    size: int,
-    *,
-    precision: Optional[int] = 1,
-    separator: Optional[str] = " ",
-) -> str:
-    """Convert a filesize in to a string (powers of 1000, SI prefixes).
-
-    In this convention, ``1000 B = 1 kB``.
-
-    This is typically the format used to advertise the storage
-    capacity of USB flash drives and the like (*256 MB* meaning
-    actually a storage capacity of more than *256 000 000 B*),
-    or used by **Mac OS X** since v10.6 to report file sizes.
-
-    Arguments:
-        int (size): A file size.
-        int (precision): The number of decimal places to include (default = 1).
-        str (separator): The string to separate the value from the units (default = " ").
-
-    Returns:
-        `str`: A string containing a abbreviated file size and units.
-
-    Example:
-        >>> filesize.decimal(30000)
-        '30.0 kB'
-        >>> filesize.decimal(30000, precision=2, separator="")
-        '30.00kB'
-
-    """
-    return _to_str(
-        size,
-        ("kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"),
-        1000,
-        precision=precision,
-        separator=separator,
-    )
diff --git a/.venv/lib/python3.12/site-packages/rich/highlighter.py b/.venv/lib/python3.12/site-packages/rich/highlighter.py
deleted file mode 100644
index df28048..0000000
--- a/.venv/lib/python3.12/site-packages/rich/highlighter.py
+++ /dev/null
@@ -1,232 +0,0 @@
-import re
-from abc import ABC, abstractmethod
-from typing import ClassVar, Sequence, Union
-
-from .text import Span, Text
-
-
-def _combine_regex(*regexes: str) -> str:
-    """Combine a number of regexes in to a single regex.
-
-    Returns:
-        str: New regex with all regexes ORed together.
-    """
-    return "|".join(regexes)
-
-
-class Highlighter(ABC):
-    """Abstract base class for highlighters."""
-
-    def __call__(self, text: Union[str, Text]) -> Text:
-        """Highlight a str or Text instance.
-
-        Args:
-            text (Union[str, ~Text]): Text to highlight.
-
-        Raises:
-            TypeError: If not called with text or str.
-
-        Returns:
-            Text: A test instance with highlighting applied.
-        """
-        if isinstance(text, str):
-            highlight_text = Text(text)
-        elif isinstance(text, Text):
-            highlight_text = text.copy()
-        else:
-            raise TypeError(f"str or Text instance required, not {text!r}")
-        self.highlight(highlight_text)
-        return highlight_text
-
-    @abstractmethod
-    def highlight(self, text: Text) -> None:
-        """Apply highlighting in place to text.
-
-        Args:
-            text (~Text): A text object highlight.
-        """
-
-
-class NullHighlighter(Highlighter):
-    """A highlighter object that doesn't highlight.
-
-    May be used to disable highlighting entirely.
-
-    """
-
-    def highlight(self, text: Text) -> None:
-        """Nothing to do"""
-
-
-class RegexHighlighter(Highlighter):
-    """Applies highlighting from a list of regular expressions."""
-
-    highlights: ClassVar[Sequence[str]] = []
-    base_style: ClassVar[str] = ""
-
-    def highlight(self, text: Text) -> None:
-        """Highlight :class:`rich.text.Text` using regular expressions.
-
-        Args:
-            text (~Text): Text to highlighted.
-
-        """
-
-        highlight_regex = text.highlight_regex
-        for re_highlight in self.highlights:
-            highlight_regex(re_highlight, style_prefix=self.base_style)
-
-
-class ReprHighlighter(RegexHighlighter):
-    """Highlights the text typically produced from ``__repr__`` methods."""
-
-    base_style = "repr."
-    highlights: ClassVar[Sequence[str]] = [
-        r"(?P<)(?P[-\w.:|]*)(?P[\w\W]*)(?P>)",
-        r'(?P[\w_]{1,50})=(?P"?[\w_]+"?)?',
-        r"(?P[][{}()])",
-        _combine_regex(
-            r"(?P[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})",
-            r"(?P([A-Fa-f0-9]{1,4}::?){1,7}[A-Fa-f0-9]{1,4})",
-            r"(?P(?:[0-9A-Fa-f]{1,2}-){7}[0-9A-Fa-f]{1,2}|(?:[0-9A-Fa-f]{1,2}:){7}[0-9A-Fa-f]{1,2}|(?:[0-9A-Fa-f]{4}\.){3}[0-9A-Fa-f]{4})",
-            r"(?P(?:[0-9A-Fa-f]{1,2}-){5}[0-9A-Fa-f]{1,2}|(?:[0-9A-Fa-f]{1,2}:){5}[0-9A-Fa-f]{1,2}|(?:[0-9A-Fa-f]{4}\.){2}[0-9A-Fa-f]{4})",
-            r"(?P[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12})",
-            r"(?P[\w.]*?)\(",
-            r"\b(?PTrue)\b|\b(?PFalse)\b|\b(?PNone)\b",
-            r"(?P\.\.\.)",
-            r"(?P(?(?\B(/[-\w._+]+)*\/)(?P[-\w._+]*)?",
-            r"(?b?'''.*?(?(file|https|http|ws|wss)://[-0-9a-zA-Z$_+!`(),.?/;:&=%#~@]*)",
-        ),
-    ]
-
-
-class JSONHighlighter(RegexHighlighter):
-    """Highlights JSON"""
-
-    # Captures the start and end of JSON strings, handling escaped quotes
-    JSON_STR = r"(?b?\".*?(?[\{\[\(\)\]\}])",
-            r"\b(?Ptrue)\b|\b(?Pfalse)\b|\b(?Pnull)\b",
-            r"(?P(? None:
-        super().highlight(text)
-
-        # Additional work to handle highlighting JSON keys
-        plain = text.plain
-        append = text.spans.append
-        whitespace = self.JSON_WHITESPACE
-        for match in re.finditer(self.JSON_STR, plain):
-            start, end = match.span()
-            cursor = end
-            while cursor < len(plain):
-                char = plain[cursor]
-                cursor += 1
-                if char == ":":
-                    append(Span(start, end, "json.key"))
-                elif char in whitespace:
-                    continue
-                break
-
-
-class ISO8601Highlighter(RegexHighlighter):
-    """Highlights the ISO8601 date time strings.
-    Regex reference: https://www.oreilly.com/library/view/regular-expressions-cookbook/9781449327453/ch04s07.html
-    """
-
-    base_style: ClassVar[str] = "iso8601."
-    highlights: ClassVar[Sequence[str]] = [
-        #
-        # Dates
-        #
-        # Calendar month (e.g. 2008-08). The hyphen is required
-        r"^(?P[0-9]{4})-(?P1[0-2]|0[1-9])$",
-        # Calendar date w/o hyphens (e.g. 20080830)
-        r"^(?P(?P[0-9]{4})(?P1[0-2]|0[1-9])(?P3[01]|0[1-9]|[12][0-9]))$",
-        # Ordinal date (e.g. 2008-243). The hyphen is optional
-        r"^(?P(?P[0-9]{4})-?(?P36[0-6]|3[0-5][0-9]|[12][0-9]{2}|0[1-9][0-9]|00[1-9]))$",
-        #
-        # Weeks
-        #
-        # Week of the year (e.g., 2008-W35). The hyphen is optional
-        r"^(?P(?P[0-9]{4})-?W(?P5[0-3]|[1-4][0-9]|0[1-9]))$",
-        # Week date (e.g., 2008-W35-6). The hyphens are optional
-        r"^(?P(?P[0-9]{4})-?W(?P5[0-3]|[1-4][0-9]|0[1-9])-?(?P[1-7]))$",
-        #
-        # Times
-        #
-        # Hours and minutes (e.g., 17:21). The colon is optional
-        r"^(?P