Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +1 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/distutils/checks/extra_vsx4_mma.c +21 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/__init__.cpython-310.pyc +0 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/absoft.cpython-310.pyc +0 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/arm.cpython-310.pyc +0 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/compaq.cpython-310.pyc +0 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/environment.cpython-310.pyc +0 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/g95.cpython-310.pyc +0 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/gnu.cpython-310.pyc +0 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/hpux.cpython-310.pyc +0 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/ibm.cpython-310.pyc +0 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/intel.cpython-310.pyc +0 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/lahey.cpython-310.pyc +0 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/mips.cpython-310.pyc +0 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/nag.cpython-310.pyc +0 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/none.cpython-310.pyc +0 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/nv.cpython-310.pyc +0 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/pathf95.cpython-310.pyc +0 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/pg.cpython-310.pyc +0 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/sun.cpython-310.pyc +0 -0
- deepseekvl2/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/vast.cpython-310.pyc +0 -0
- deepseekvl2/lib/python3.10/site-packages/psutil/__pycache__/__init__.cpython-310.pyc +0 -0
- deepseekvl2/lib/python3.10/site-packages/psutil/__pycache__/_pssunos.cpython-310.pyc +0 -0
- deepseekvl2/lib/python3.10/site-packages/psutil/__pycache__/_pswindows.cpython-310.pyc +0 -0
- deepseekvl2/lib/python3.10/site-packages/torchvision-0.15.2+cu118.dist-info/INSTALLER +1 -0
- deepseekvl2/lib/python3.10/site-packages/torchvision-0.15.2+cu118.dist-info/LICENSE +29 -0
- deepseekvl2/lib/python3.10/site-packages/torchvision-0.15.2+cu118.dist-info/METADATA +233 -0
- deepseekvl2/lib/python3.10/site-packages/torchvision-0.15.2+cu118.dist-info/WHEEL +5 -0
- infer_4_33_0/lib/python3.10/site-packages/aiohttp/__pycache__/http_websocket.cpython-310.pyc +0 -0
- infer_4_33_0/lib/python3.10/site-packages/aiohttp/_websocket/.hash/mask.pxd.hash +1 -0
- infer_4_33_0/lib/python3.10/site-packages/aiohttp/_websocket/__init__.py +1 -0
- infer_4_33_0/lib/python3.10/site-packages/aiohttp/_websocket/helpers.py +147 -0
- infer_4_33_0/lib/python3.10/site-packages/aiohttp/_websocket/mask.pyx +48 -0
- infer_4_33_0/lib/python3.10/site-packages/aiohttp/_websocket/models.py +84 -0
- infer_4_33_0/lib/python3.10/site-packages/aiohttp/_websocket/reader.py +31 -0
- infer_4_33_0/lib/python3.10/site-packages/aiohttp/_websocket/reader_c.cpython-310-x86_64-linux-gnu.so +3 -0
- infer_4_33_0/lib/python3.10/site-packages/aiohttp/_websocket/reader_c.pxd +102 -0
- infer_4_33_0/lib/python3.10/site-packages/aiohttp/_websocket/reader_c.py +468 -0
- infer_4_33_0/lib/python3.10/site-packages/aiohttp/_websocket/writer.py +177 -0
- infer_4_33_0/lib/python3.10/site-packages/h5py/tests/data_files/vlen_string_dset.h5 +3 -0
- infer_4_33_0/lib/python3.10/site-packages/h5py/tests/data_files/vlen_string_s390x.h5 +3 -0
- infer_4_33_0/lib/python3.10/site-packages/mdit_py_plugins/myst_blocks/__init__.py +1 -0
- infer_4_33_0/lib/python3.10/site-packages/mdit_py_plugins/myst_blocks/__pycache__/__init__.cpython-310.pyc +0 -0
- infer_4_33_0/lib/python3.10/site-packages/mdit_py_plugins/myst_blocks/__pycache__/index.cpython-310.pyc +0 -0
- infer_4_33_0/lib/python3.10/site-packages/mdit_py_plugins/myst_blocks/index.py +153 -0
- infer_4_33_0/lib/python3.10/site-packages/mdit_py_plugins/myst_role/__init__.py +1 -0
- infer_4_33_0/lib/python3.10/site-packages/mdit_py_plugins/tasklists/__pycache__/__init__.cpython-310.pyc +0 -0
- infer_4_33_0/lib/python3.10/site-packages/mdit_py_plugins/texmath/LICENSE +21 -0
- infer_4_33_0/lib/python3.10/site-packages/mdit_py_plugins/texmath/__init__.py +1 -0
- infer_4_33_0/lib/python3.10/site-packages/mdit_py_plugins/texmath/index.py +307 -0
.gitattributes
CHANGED
|
@@ -702,3 +702,4 @@ deepseek/lib/python3.10/site-packages/numpy/lib/tests/__pycache__/test_function_
|
|
| 702 |
deepseek/lib/python3.10/site-packages/numpy/core/tests/__pycache__/test_numeric.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
| 703 |
deepseek/lib/python3.10/site-packages/numpy/core/__pycache__/_add_newdocs.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
| 704 |
deepseekvl2/lib/python3.10/site-packages/torch/_inductor/__pycache__/ir.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 702 |
deepseek/lib/python3.10/site-packages/numpy/core/tests/__pycache__/test_numeric.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
| 703 |
deepseek/lib/python3.10/site-packages/numpy/core/__pycache__/_add_newdocs.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
| 704 |
deepseekvl2/lib/python3.10/site-packages/torch/_inductor/__pycache__/ir.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
| 705 |
+
infer_4_33_0/lib/python3.10/site-packages/aiohttp/_websocket/reader_c.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
deepseekvl2/lib/python3.10/site-packages/numpy/distutils/checks/extra_vsx4_mma.c
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#ifndef __VSX__
|
| 2 |
+
#error "VSX is not supported"
|
| 3 |
+
#endif
|
| 4 |
+
#include <altivec.h>
|
| 5 |
+
|
| 6 |
+
typedef __vector float fv4sf_t;
|
| 7 |
+
typedef __vector unsigned char vec_t;
|
| 8 |
+
|
| 9 |
+
int main(void)
|
| 10 |
+
{
|
| 11 |
+
__vector_quad acc0;
|
| 12 |
+
float a[4] = {0,1,2,3};
|
| 13 |
+
float b[4] = {0,1,2,3};
|
| 14 |
+
vec_t *va = (vec_t *) a;
|
| 15 |
+
vec_t *vb = (vec_t *) b;
|
| 16 |
+
__builtin_mma_xvf32ger(&acc0, va[0], vb[0]);
|
| 17 |
+
fv4sf_t result[4];
|
| 18 |
+
__builtin_mma_disassemble_acc((void *)result, &acc0);
|
| 19 |
+
fv4sf_t c0 = result[0];
|
| 20 |
+
return (int)((float*)&c0)[0];
|
| 21 |
+
}
|
deepseekvl2/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (28.6 kB). View file
|
|
|
deepseekvl2/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/absoft.cpython-310.pyc
ADDED
|
Binary file (4.41 kB). View file
|
|
|
deepseekvl2/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/arm.cpython-310.pyc
ADDED
|
Binary file (2.74 kB). View file
|
|
|
deepseekvl2/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/compaq.cpython-310.pyc
ADDED
|
Binary file (4.15 kB). View file
|
|
|
deepseekvl2/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/environment.cpython-310.pyc
ADDED
|
Binary file (3.09 kB). View file
|
|
|
deepseekvl2/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/g95.cpython-310.pyc
ADDED
|
Binary file (1.51 kB). View file
|
|
|
deepseekvl2/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/gnu.cpython-310.pyc
ADDED
|
Binary file (13 kB). View file
|
|
|
deepseekvl2/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/hpux.cpython-310.pyc
ADDED
|
Binary file (1.81 kB). View file
|
|
|
deepseekvl2/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/ibm.cpython-310.pyc
ADDED
|
Binary file (3.43 kB). View file
|
|
|
deepseekvl2/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/intel.cpython-310.pyc
ADDED
|
Binary file (6.42 kB). View file
|
|
|
deepseekvl2/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/lahey.cpython-310.pyc
ADDED
|
Binary file (1.84 kB). View file
|
|
|
deepseekvl2/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/mips.cpython-310.pyc
ADDED
|
Binary file (2.19 kB). View file
|
|
|
deepseekvl2/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/nag.cpython-310.pyc
ADDED
|
Binary file (3.17 kB). View file
|
|
|
deepseekvl2/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/none.cpython-310.pyc
ADDED
|
Binary file (996 Bytes). View file
|
|
|
deepseekvl2/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/nv.cpython-310.pyc
ADDED
|
Binary file (2.23 kB). View file
|
|
|
deepseekvl2/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/pathf95.cpython-310.pyc
ADDED
|
Binary file (1.39 kB). View file
|
|
|
deepseekvl2/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/pg.cpython-310.pyc
ADDED
|
Binary file (4.2 kB). View file
|
|
|
deepseekvl2/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/sun.cpython-310.pyc
ADDED
|
Binary file (2.06 kB). View file
|
|
|
deepseekvl2/lib/python3.10/site-packages/numpy/distutils/fcompiler/__pycache__/vast.cpython-310.pyc
ADDED
|
Binary file (1.86 kB). View file
|
|
|
deepseekvl2/lib/python3.10/site-packages/psutil/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (63.5 kB). View file
|
|
|
deepseekvl2/lib/python3.10/site-packages/psutil/__pycache__/_pssunos.cpython-310.pyc
ADDED
|
Binary file (17.8 kB). View file
|
|
|
deepseekvl2/lib/python3.10/site-packages/psutil/__pycache__/_pswindows.cpython-310.pyc
ADDED
|
Binary file (27.7 kB). View file
|
|
|
deepseekvl2/lib/python3.10/site-packages/torchvision-0.15.2+cu118.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pip
|
deepseekvl2/lib/python3.10/site-packages/torchvision-0.15.2+cu118.dist-info/LICENSE
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
BSD 3-Clause License
|
| 2 |
+
|
| 3 |
+
Copyright (c) Soumith Chintala 2016,
|
| 4 |
+
All rights reserved.
|
| 5 |
+
|
| 6 |
+
Redistribution and use in source and binary forms, with or without
|
| 7 |
+
modification, are permitted provided that the following conditions are met:
|
| 8 |
+
|
| 9 |
+
* Redistributions of source code must retain the above copyright notice, this
|
| 10 |
+
list of conditions and the following disclaimer.
|
| 11 |
+
|
| 12 |
+
* Redistributions in binary form must reproduce the above copyright notice,
|
| 13 |
+
this list of conditions and the following disclaimer in the documentation
|
| 14 |
+
and/or other materials provided with the distribution.
|
| 15 |
+
|
| 16 |
+
* Neither the name of the copyright holder nor the names of its
|
| 17 |
+
contributors may be used to endorse or promote products derived from
|
| 18 |
+
this software without specific prior written permission.
|
| 19 |
+
|
| 20 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 21 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 22 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 23 |
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
| 24 |
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 25 |
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
| 26 |
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
| 27 |
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
| 28 |
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 29 |
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
deepseekvl2/lib/python3.10/site-packages/torchvision-0.15.2+cu118.dist-info/METADATA
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.1
|
| 2 |
+
Name: torchvision
|
| 3 |
+
Version: 0.15.2+cu118
|
| 4 |
+
Summary: image and video datasets and models for torch deep learning
|
| 5 |
+
Home-page: https://github.com/pytorch/vision
|
| 6 |
+
Author: PyTorch Core Team
|
| 7 |
+
Author-email: soumith@pytorch.org
|
| 8 |
+
License: BSD
|
| 9 |
+
Requires-Python: >=3.8
|
| 10 |
+
License-File: LICENSE
|
| 11 |
+
Requires-Dist: numpy
|
| 12 |
+
Requires-Dist: requests
|
| 13 |
+
Requires-Dist: torch (==2.0.1)
|
| 14 |
+
Requires-Dist: pillow (!=8.3.*,>=5.3.0)
|
| 15 |
+
Provides-Extra: scipy
|
| 16 |
+
Requires-Dist: scipy ; extra == 'scipy'
|
| 17 |
+
|
| 18 |
+
torchvision
|
| 19 |
+
===========
|
| 20 |
+
|
| 21 |
+
.. image:: https://pepy.tech/badge/torchvision
|
| 22 |
+
:target: https://pepy.tech/project/torchvision
|
| 23 |
+
|
| 24 |
+
.. image:: https://img.shields.io/badge/dynamic/json.svg?label=docs&url=https%3A%2F%2Fpypi.org%2Fpypi%2Ftorchvision%2Fjson&query=%24.info.version&colorB=brightgreen&prefix=v
|
| 25 |
+
:target: https://pytorch.org/vision/stable/index.html
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
The torchvision package consists of popular datasets, model architectures, and common image transformations for computer vision.
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
Installation
|
| 32 |
+
============
|
| 33 |
+
|
| 34 |
+
We recommend Anaconda as Python package management system. Please refer to `pytorch.org <https://pytorch.org/>`_
|
| 35 |
+
for the detail of PyTorch (``torch``) installation. The following is the corresponding ``torchvision`` versions and
|
| 36 |
+
supported Python versions.
|
| 37 |
+
|
| 38 |
+
+--------------------------+--------------------------+---------------------------------+
|
| 39 |
+
| ``torch`` | ``torchvision`` | ``python`` |
|
| 40 |
+
+==========================+==========================+=================================+
|
| 41 |
+
| ``main`` / ``nightly`` | ``main`` / ``nightly`` | ``>=3.8``, ``<=3.10`` |
|
| 42 |
+
+--------------------------+--------------------------+---------------------------------+
|
| 43 |
+
| ``1.13.0`` | ``0.14.0`` | ``>=3.7.2``, ``<=3.10`` |
|
| 44 |
+
+--------------------------+--------------------------+---------------------------------+
|
| 45 |
+
| ``1.12.0`` | ``0.13.0`` | ``>=3.7``, ``<=3.10`` |
|
| 46 |
+
+--------------------------+--------------------------+---------------------------------+
|
| 47 |
+
| ``1.11.0`` | ``0.12.0`` | ``>=3.7``, ``<=3.10`` |
|
| 48 |
+
+--------------------------+--------------------------+---------------------------------+
|
| 49 |
+
| ``1.10.2`` | ``0.11.3`` | ``>=3.6``, ``<=3.9`` |
|
| 50 |
+
+--------------------------+--------------------------+---------------------------------+
|
| 51 |
+
| ``1.10.1`` | ``0.11.2`` | ``>=3.6``, ``<=3.9`` |
|
| 52 |
+
+--------------------------+--------------------------+---------------------------------+
|
| 53 |
+
| ``1.10.0`` | ``0.11.1`` | ``>=3.6``, ``<=3.9`` |
|
| 54 |
+
+--------------------------+--------------------------+---------------------------------+
|
| 55 |
+
| ``1.9.1`` | ``0.10.1`` | ``>=3.6``, ``<=3.9`` |
|
| 56 |
+
+--------------------------+--------------------------+---------------------------------+
|
| 57 |
+
| ``1.9.0`` | ``0.10.0`` | ``>=3.6``, ``<=3.9`` |
|
| 58 |
+
+--------------------------+--------------------------+---------------------------------+
|
| 59 |
+
| ``1.8.2`` | ``0.9.2`` | ``>=3.6``, ``<=3.9`` |
|
| 60 |
+
+--------------------------+--------------------------+---------------------------------+
|
| 61 |
+
| ``1.8.1`` | ``0.9.1`` | ``>=3.6``, ``<=3.9`` |
|
| 62 |
+
+--------------------------+--------------------------+---------------------------------+
|
| 63 |
+
| ``1.8.0`` | ``0.9.0`` | ``>=3.6``, ``<=3.9`` |
|
| 64 |
+
+--------------------------+--------------------------+---------------------------------+
|
| 65 |
+
| ``1.7.1`` | ``0.8.2`` | ``>=3.6``, ``<=3.9`` |
|
| 66 |
+
+--------------------------+--------------------------+---------------------------------+
|
| 67 |
+
| ``1.7.0`` | ``0.8.1`` | ``>=3.6``, ``<=3.8`` |
|
| 68 |
+
+--------------------------+--------------------------+---------------------------------+
|
| 69 |
+
| ``1.7.0`` | ``0.8.0`` | ``>=3.6``, ``<=3.8`` |
|
| 70 |
+
+--------------------------+--------------------------+---------------------------------+
|
| 71 |
+
| ``1.6.0`` | ``0.7.0`` | ``>=3.6``, ``<=3.8`` |
|
| 72 |
+
+--------------------------+--------------------------+---------------------------------+
|
| 73 |
+
| ``1.5.1`` | ``0.6.1`` | ``>=3.5``, ``<=3.8`` |
|
| 74 |
+
+--------------------------+--------------------------+---------------------------------+
|
| 75 |
+
| ``1.5.0`` | ``0.6.0`` | ``>=3.5``, ``<=3.8`` |
|
| 76 |
+
+--------------------------+--------------------------+---------------------------------+
|
| 77 |
+
| ``1.4.0`` | ``0.5.0`` | ``==2.7``, ``>=3.5``, ``<=3.8`` |
|
| 78 |
+
+--------------------------+--------------------------+---------------------------------+
|
| 79 |
+
| ``1.3.1`` | ``0.4.2`` | ``==2.7``, ``>=3.5``, ``<=3.7`` |
|
| 80 |
+
+--------------------------+--------------------------+---------------------------------+
|
| 81 |
+
| ``1.3.0`` | ``0.4.1`` | ``==2.7``, ``>=3.5``, ``<=3.7`` |
|
| 82 |
+
+--------------------------+--------------------------+---------------------------------+
|
| 83 |
+
| ``1.2.0`` | ``0.4.0`` | ``==2.7``, ``>=3.5``, ``<=3.7`` |
|
| 84 |
+
+--------------------------+--------------------------+---------------------------------+
|
| 85 |
+
| ``1.1.0`` | ``0.3.0`` | ``==2.7``, ``>=3.5``, ``<=3.7`` |
|
| 86 |
+
+--------------------------+--------------------------+---------------------------------+
|
| 87 |
+
| ``<=1.0.1`` | ``0.2.2`` | ``==2.7``, ``>=3.5``, ``<=3.7`` |
|
| 88 |
+
+--------------------------+--------------------------+---------------------------------+
|
| 89 |
+
|
| 90 |
+
Anaconda:
|
| 91 |
+
|
| 92 |
+
.. code:: bash
|
| 93 |
+
|
| 94 |
+
conda install torchvision -c pytorch
|
| 95 |
+
|
| 96 |
+
pip:
|
| 97 |
+
|
| 98 |
+
.. code:: bash
|
| 99 |
+
|
| 100 |
+
pip install torchvision
|
| 101 |
+
|
| 102 |
+
From source:
|
| 103 |
+
|
| 104 |
+
.. code:: bash
|
| 105 |
+
|
| 106 |
+
python setup.py install
|
| 107 |
+
# or, for OSX
|
| 108 |
+
# MACOSX_DEPLOYMENT_TARGET=10.9 CC=clang CXX=clang++ python setup.py install
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
We don't officially support building from source using ``pip``, but *if* you do,
|
| 112 |
+
you'll need to use the ``--no-build-isolation`` flag.
|
| 113 |
+
In case building TorchVision from source fails, install the nightly version of PyTorch following
|
| 114 |
+
the linked guide on the `contributing page <https://github.com/pytorch/vision/blob/main/CONTRIBUTING.md#development-installation>`_ and retry the install.
|
| 115 |
+
|
| 116 |
+
By default, GPU support is built if CUDA is found and ``torch.cuda.is_available()`` is true.
|
| 117 |
+
It's possible to force building GPU support by setting ``FORCE_CUDA=1`` environment variable,
|
| 118 |
+
which is useful when building a docker image.
|
| 119 |
+
|
| 120 |
+
Image Backend
|
| 121 |
+
=============
|
| 122 |
+
Torchvision currently supports the following image backends:
|
| 123 |
+
|
| 124 |
+
* `Pillow`_ (default)
|
| 125 |
+
|
| 126 |
+
* `Pillow-SIMD`_ - a **much faster** drop-in replacement for Pillow with SIMD. If installed will be used as the default.
|
| 127 |
+
|
| 128 |
+
* `accimage`_ - if installed can be activated by calling :code:`torchvision.set_image_backend('accimage')`
|
| 129 |
+
|
| 130 |
+
* `libpng`_ - can be installed via conda :code:`conda install libpng` or any of the package managers for debian-based and RHEL-based Linux distributions.
|
| 131 |
+
|
| 132 |
+
* `libjpeg`_ - can be installed via conda :code:`conda install jpeg` or any of the package managers for debian-based and RHEL-based Linux distributions. `libjpeg-turbo`_ can be used as well.
|
| 133 |
+
|
| 134 |
+
**Notes:** ``libpng`` and ``libjpeg`` must be available at compilation time in order to be available. Make sure that it is available on the standard library locations,
|
| 135 |
+
otherwise, add the include and library paths in the environment variables ``TORCHVISION_INCLUDE`` and ``TORCHVISION_LIBRARY``, respectively.
|
| 136 |
+
|
| 137 |
+
.. _libpng : http://www.libpng.org/pub/png/libpng.html
|
| 138 |
+
.. _Pillow : https://python-pillow.org/
|
| 139 |
+
.. _Pillow-SIMD : https://github.com/uploadcare/pillow-simd
|
| 140 |
+
.. _accimage: https://github.com/pytorch/accimage
|
| 141 |
+
.. _libjpeg: http://ijg.org/
|
| 142 |
+
.. _libjpeg-turbo: https://libjpeg-turbo.org/
|
| 143 |
+
|
| 144 |
+
Video Backend
|
| 145 |
+
=============
|
| 146 |
+
Torchvision currently supports the following video backends:
|
| 147 |
+
|
| 148 |
+
* `pyav`_ (default) - Pythonic binding for ffmpeg libraries.
|
| 149 |
+
|
| 150 |
+
.. _pyav : https://github.com/PyAV-Org/PyAV
|
| 151 |
+
|
| 152 |
+
* video_reader - This needs ffmpeg to be installed and torchvision to be built from source. There shouldn't be any conflicting version of ffmpeg installed. Currently, this is only supported on Linux.
|
| 153 |
+
|
| 154 |
+
.. code:: bash
|
| 155 |
+
|
| 156 |
+
conda install -c conda-forge ffmpeg
|
| 157 |
+
python setup.py install
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
Using the models on C++
|
| 161 |
+
=======================
|
| 162 |
+
TorchVision provides an example project for how to use the models on C++ using JIT Script.
|
| 163 |
+
|
| 164 |
+
Installation From source:
|
| 165 |
+
|
| 166 |
+
.. code:: bash
|
| 167 |
+
|
| 168 |
+
mkdir build
|
| 169 |
+
cd build
|
| 170 |
+
# Add -DWITH_CUDA=on support for the CUDA if needed
|
| 171 |
+
cmake ..
|
| 172 |
+
make
|
| 173 |
+
make install
|
| 174 |
+
|
| 175 |
+
Once installed, the library can be accessed in cmake (after properly configuring ``CMAKE_PREFIX_PATH``) via the :code:`TorchVision::TorchVision` target:
|
| 176 |
+
|
| 177 |
+
.. code:: rest
|
| 178 |
+
|
| 179 |
+
find_package(TorchVision REQUIRED)
|
| 180 |
+
target_link_libraries(my-target PUBLIC TorchVision::TorchVision)
|
| 181 |
+
|
| 182 |
+
The ``TorchVision`` package will also automatically look for the ``Torch`` package and add it as a dependency to ``my-target``,
|
| 183 |
+
so make sure that it is also available to cmake via the ``CMAKE_PREFIX_PATH``.
|
| 184 |
+
|
| 185 |
+
For an example setup, take a look at ``examples/cpp/hello_world``.
|
| 186 |
+
|
| 187 |
+
Python linking is disabled by default when compiling TorchVision with CMake, this allows you to run models without any Python
|
| 188 |
+
dependency. In some special cases where TorchVision's operators are used from Python code, you may need to link to Python. This
|
| 189 |
+
can be done by passing ``-DUSE_PYTHON=on`` to CMake.
|
| 190 |
+
|
| 191 |
+
TorchVision Operators
|
| 192 |
+
---------------------
|
| 193 |
+
In order to get the torchvision operators registered with torch (eg. for the JIT), all you need to do is to ensure that you
|
| 194 |
+
:code:`#include <torchvision/vision.h>` in your project.
|
| 195 |
+
|
| 196 |
+
Documentation
|
| 197 |
+
=============
|
| 198 |
+
You can find the API documentation on the pytorch website: https://pytorch.org/vision/stable/index.html
|
| 199 |
+
|
| 200 |
+
Contributing
|
| 201 |
+
============
|
| 202 |
+
|
| 203 |
+
See the `CONTRIBUTING <CONTRIBUTING.md>`_ file for how to help out.
|
| 204 |
+
|
| 205 |
+
Disclaimer on Datasets
|
| 206 |
+
======================
|
| 207 |
+
|
| 208 |
+
This is a utility library that downloads and prepares public datasets. We do not host or distribute these datasets, vouch for their quality or fairness, or claim that you have license to use the dataset. It is your responsibility to determine whether you have permission to use the dataset under the dataset's license.
|
| 209 |
+
|
| 210 |
+
If you're a dataset owner and wish to update any part of it (description, citation, etc.), or do not want your dataset to be included in this library, please get in touch through a GitHub issue. Thanks for your contribution to the ML community!
|
| 211 |
+
|
| 212 |
+
Pre-trained Model License
|
| 213 |
+
=========================
|
| 214 |
+
|
| 215 |
+
The pre-trained models provided in this library may have their own licenses or terms and conditions derived from the dataset used for training. It is your responsibility to determine whether you have permission to use the models for your use case.
|
| 216 |
+
|
| 217 |
+
More specifically, SWAG models are released under the CC-BY-NC 4.0 license. See `SWAG LICENSE <https://github.com/facebookresearch/SWAG/blob/main/LICENSE>`_ for additional details.
|
| 218 |
+
|
| 219 |
+
Citing TorchVision
|
| 220 |
+
==================
|
| 221 |
+
|
| 222 |
+
If you find TorchVision useful in your work, please consider citing the following BibTeX entry:
|
| 223 |
+
|
| 224 |
+
.. code:: bibtex
|
| 225 |
+
|
| 226 |
+
@software{torchvision2016,
|
| 227 |
+
title = {TorchVision: PyTorch's Computer Vision library},
|
| 228 |
+
author = {TorchVision maintainers and contributors},
|
| 229 |
+
year = 2016,
|
| 230 |
+
journal = {GitHub repository},
|
| 231 |
+
publisher = {GitHub},
|
| 232 |
+
howpublished = {\url{https://github.com/pytorch/vision}}
|
| 233 |
+
}
|
deepseekvl2/lib/python3.10/site-packages/torchvision-0.15.2+cu118.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: bdist_wheel (0.37.1)
|
| 3 |
+
Root-Is-Purelib: false
|
| 4 |
+
Tag: cp310-cp310-linux_x86_64
|
| 5 |
+
|
infer_4_33_0/lib/python3.10/site-packages/aiohttp/__pycache__/http_websocket.cpython-310.pyc
ADDED
|
Binary file (810 Bytes). View file
|
|
|
infer_4_33_0/lib/python3.10/site-packages/aiohttp/_websocket/.hash/mask.pxd.hash
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
b01999d409b29bd916e067bc963d5f2d9ee63cfc9ae0bccb769910131417bf93 /home/runner/work/aiohttp/aiohttp/aiohttp/_websocket/mask.pxd
|
infer_4_33_0/lib/python3.10/site-packages/aiohttp/_websocket/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
"""WebSocket protocol versions 13 and 8."""
|
infer_4_33_0/lib/python3.10/site-packages/aiohttp/_websocket/helpers.py
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Helpers for WebSocket protocol versions 13 and 8."""
|
| 2 |
+
|
| 3 |
+
import functools
|
| 4 |
+
import re
|
| 5 |
+
from struct import Struct
|
| 6 |
+
from typing import TYPE_CHECKING, Final, List, Optional, Pattern, Tuple
|
| 7 |
+
|
| 8 |
+
from ..helpers import NO_EXTENSIONS
|
| 9 |
+
from .models import WSHandshakeError
|
| 10 |
+
|
| 11 |
+
UNPACK_LEN3 = Struct("!Q").unpack_from
|
| 12 |
+
UNPACK_CLOSE_CODE = Struct("!H").unpack
|
| 13 |
+
PACK_LEN1 = Struct("!BB").pack
|
| 14 |
+
PACK_LEN2 = Struct("!BBH").pack
|
| 15 |
+
PACK_LEN3 = Struct("!BBQ").pack
|
| 16 |
+
PACK_CLOSE_CODE = Struct("!H").pack
|
| 17 |
+
PACK_RANDBITS = Struct("!L").pack
|
| 18 |
+
MSG_SIZE: Final[int] = 2**14
|
| 19 |
+
MASK_LEN: Final[int] = 4
|
| 20 |
+
|
| 21 |
+
WS_KEY: Final[bytes] = b"258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
# Used by _websocket_mask_python
|
| 25 |
+
@functools.lru_cache
|
| 26 |
+
def _xor_table() -> List[bytes]:
|
| 27 |
+
return [bytes(a ^ b for a in range(256)) for b in range(256)]
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def _websocket_mask_python(mask: bytes, data: bytearray) -> None:
|
| 31 |
+
"""Websocket masking function.
|
| 32 |
+
|
| 33 |
+
`mask` is a `bytes` object of length 4; `data` is a `bytearray`
|
| 34 |
+
object of any length. The contents of `data` are masked with `mask`,
|
| 35 |
+
as specified in section 5.3 of RFC 6455.
|
| 36 |
+
|
| 37 |
+
Note that this function mutates the `data` argument.
|
| 38 |
+
|
| 39 |
+
This pure-python implementation may be replaced by an optimized
|
| 40 |
+
version when available.
|
| 41 |
+
|
| 42 |
+
"""
|
| 43 |
+
assert isinstance(data, bytearray), data
|
| 44 |
+
assert len(mask) == 4, mask
|
| 45 |
+
|
| 46 |
+
if data:
|
| 47 |
+
_XOR_TABLE = _xor_table()
|
| 48 |
+
a, b, c, d = (_XOR_TABLE[n] for n in mask)
|
| 49 |
+
data[::4] = data[::4].translate(a)
|
| 50 |
+
data[1::4] = data[1::4].translate(b)
|
| 51 |
+
data[2::4] = data[2::4].translate(c)
|
| 52 |
+
data[3::4] = data[3::4].translate(d)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
if TYPE_CHECKING or NO_EXTENSIONS: # pragma: no cover
|
| 56 |
+
websocket_mask = _websocket_mask_python
|
| 57 |
+
else:
|
| 58 |
+
try:
|
| 59 |
+
from .mask import _websocket_mask_cython # type: ignore[import-not-found]
|
| 60 |
+
|
| 61 |
+
websocket_mask = _websocket_mask_cython
|
| 62 |
+
except ImportError: # pragma: no cover
|
| 63 |
+
websocket_mask = _websocket_mask_python
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
_WS_EXT_RE: Final[Pattern[str]] = re.compile(
|
| 67 |
+
r"^(?:;\s*(?:"
|
| 68 |
+
r"(server_no_context_takeover)|"
|
| 69 |
+
r"(client_no_context_takeover)|"
|
| 70 |
+
r"(server_max_window_bits(?:=(\d+))?)|"
|
| 71 |
+
r"(client_max_window_bits(?:=(\d+))?)))*$"
|
| 72 |
+
)
|
| 73 |
+
|
| 74 |
+
_WS_EXT_RE_SPLIT: Final[Pattern[str]] = re.compile(r"permessage-deflate([^,]+)?")
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def ws_ext_parse(extstr: Optional[str], isserver: bool = False) -> Tuple[int, bool]:
|
| 78 |
+
if not extstr:
|
| 79 |
+
return 0, False
|
| 80 |
+
|
| 81 |
+
compress = 0
|
| 82 |
+
notakeover = False
|
| 83 |
+
for ext in _WS_EXT_RE_SPLIT.finditer(extstr):
|
| 84 |
+
defext = ext.group(1)
|
| 85 |
+
# Return compress = 15 when get `permessage-deflate`
|
| 86 |
+
if not defext:
|
| 87 |
+
compress = 15
|
| 88 |
+
break
|
| 89 |
+
match = _WS_EXT_RE.match(defext)
|
| 90 |
+
if match:
|
| 91 |
+
compress = 15
|
| 92 |
+
if isserver:
|
| 93 |
+
# Server never fail to detect compress handshake.
|
| 94 |
+
# Server does not need to send max wbit to client
|
| 95 |
+
if match.group(4):
|
| 96 |
+
compress = int(match.group(4))
|
| 97 |
+
# Group3 must match if group4 matches
|
| 98 |
+
# Compress wbit 8 does not support in zlib
|
| 99 |
+
# If compress level not support,
|
| 100 |
+
# CONTINUE to next extension
|
| 101 |
+
if compress > 15 or compress < 9:
|
| 102 |
+
compress = 0
|
| 103 |
+
continue
|
| 104 |
+
if match.group(1):
|
| 105 |
+
notakeover = True
|
| 106 |
+
# Ignore regex group 5 & 6 for client_max_window_bits
|
| 107 |
+
break
|
| 108 |
+
else:
|
| 109 |
+
if match.group(6):
|
| 110 |
+
compress = int(match.group(6))
|
| 111 |
+
# Group5 must match if group6 matches
|
| 112 |
+
# Compress wbit 8 does not support in zlib
|
| 113 |
+
# If compress level not support,
|
| 114 |
+
# FAIL the parse progress
|
| 115 |
+
if compress > 15 or compress < 9:
|
| 116 |
+
raise WSHandshakeError("Invalid window size")
|
| 117 |
+
if match.group(2):
|
| 118 |
+
notakeover = True
|
| 119 |
+
# Ignore regex group 5 & 6 for client_max_window_bits
|
| 120 |
+
break
|
| 121 |
+
# Return Fail if client side and not match
|
| 122 |
+
elif not isserver:
|
| 123 |
+
raise WSHandshakeError("Extension for deflate not supported" + ext.group(1))
|
| 124 |
+
|
| 125 |
+
return compress, notakeover
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
def ws_ext_gen(
|
| 129 |
+
compress: int = 15, isserver: bool = False, server_notakeover: bool = False
|
| 130 |
+
) -> str:
|
| 131 |
+
# client_notakeover=False not used for server
|
| 132 |
+
# compress wbit 8 does not support in zlib
|
| 133 |
+
if compress < 9 or compress > 15:
|
| 134 |
+
raise ValueError(
|
| 135 |
+
"Compress wbits must between 9 and 15, zlib does not support wbits=8"
|
| 136 |
+
)
|
| 137 |
+
enabledext = ["permessage-deflate"]
|
| 138 |
+
if not isserver:
|
| 139 |
+
enabledext.append("client_max_window_bits")
|
| 140 |
+
|
| 141 |
+
if compress < 15:
|
| 142 |
+
enabledext.append("server_max_window_bits=" + str(compress))
|
| 143 |
+
if server_notakeover:
|
| 144 |
+
enabledext.append("server_no_context_takeover")
|
| 145 |
+
# if client_notakeover:
|
| 146 |
+
# enabledext.append('client_no_context_takeover')
|
| 147 |
+
return "; ".join(enabledext)
|
infer_4_33_0/lib/python3.10/site-packages/aiohttp/_websocket/mask.pyx
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from cpython cimport PyBytes_AsString
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
#from cpython cimport PyByteArray_AsString # cython still not exports that
|
| 5 |
+
cdef extern from "Python.h":
|
| 6 |
+
char* PyByteArray_AsString(bytearray ba) except NULL
|
| 7 |
+
|
| 8 |
+
from libc.stdint cimport uint32_t, uint64_t, uintmax_t
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
cpdef void _websocket_mask_cython(bytes mask, bytearray data):
|
| 12 |
+
"""Note, this function mutates its `data` argument
|
| 13 |
+
"""
|
| 14 |
+
cdef:
|
| 15 |
+
Py_ssize_t data_len, i
|
| 16 |
+
# bit operations on signed integers are implementation-specific
|
| 17 |
+
unsigned char * in_buf
|
| 18 |
+
const unsigned char * mask_buf
|
| 19 |
+
uint32_t uint32_msk
|
| 20 |
+
uint64_t uint64_msk
|
| 21 |
+
|
| 22 |
+
assert len(mask) == 4
|
| 23 |
+
|
| 24 |
+
data_len = len(data)
|
| 25 |
+
in_buf = <unsigned char*>PyByteArray_AsString(data)
|
| 26 |
+
mask_buf = <const unsigned char*>PyBytes_AsString(mask)
|
| 27 |
+
uint32_msk = (<uint32_t*>mask_buf)[0]
|
| 28 |
+
|
| 29 |
+
# TODO: align in_data ptr to achieve even faster speeds
|
| 30 |
+
# does it need in python ?! malloc() always aligns to sizeof(long) bytes
|
| 31 |
+
|
| 32 |
+
if sizeof(size_t) >= 8:
|
| 33 |
+
uint64_msk = uint32_msk
|
| 34 |
+
uint64_msk = (uint64_msk << 32) | uint32_msk
|
| 35 |
+
|
| 36 |
+
while data_len >= 8:
|
| 37 |
+
(<uint64_t*>in_buf)[0] ^= uint64_msk
|
| 38 |
+
in_buf += 8
|
| 39 |
+
data_len -= 8
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
while data_len >= 4:
|
| 43 |
+
(<uint32_t*>in_buf)[0] ^= uint32_msk
|
| 44 |
+
in_buf += 4
|
| 45 |
+
data_len -= 4
|
| 46 |
+
|
| 47 |
+
for i in range(0, data_len):
|
| 48 |
+
in_buf[i] ^= mask_buf[i]
|
infer_4_33_0/lib/python3.10/site-packages/aiohttp/_websocket/models.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Models for WebSocket protocol versions 13 and 8."""
|
| 2 |
+
|
| 3 |
+
import json
|
| 4 |
+
from enum import IntEnum
|
| 5 |
+
from typing import Any, Callable, Final, NamedTuple, Optional, cast
|
| 6 |
+
|
| 7 |
+
WS_DEFLATE_TRAILING: Final[bytes] = bytes([0x00, 0x00, 0xFF, 0xFF])
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class WSCloseCode(IntEnum):
|
| 11 |
+
OK = 1000
|
| 12 |
+
GOING_AWAY = 1001
|
| 13 |
+
PROTOCOL_ERROR = 1002
|
| 14 |
+
UNSUPPORTED_DATA = 1003
|
| 15 |
+
ABNORMAL_CLOSURE = 1006
|
| 16 |
+
INVALID_TEXT = 1007
|
| 17 |
+
POLICY_VIOLATION = 1008
|
| 18 |
+
MESSAGE_TOO_BIG = 1009
|
| 19 |
+
MANDATORY_EXTENSION = 1010
|
| 20 |
+
INTERNAL_ERROR = 1011
|
| 21 |
+
SERVICE_RESTART = 1012
|
| 22 |
+
TRY_AGAIN_LATER = 1013
|
| 23 |
+
BAD_GATEWAY = 1014
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
class WSMsgType(IntEnum):
|
| 27 |
+
# websocket spec types
|
| 28 |
+
CONTINUATION = 0x0
|
| 29 |
+
TEXT = 0x1
|
| 30 |
+
BINARY = 0x2
|
| 31 |
+
PING = 0x9
|
| 32 |
+
PONG = 0xA
|
| 33 |
+
CLOSE = 0x8
|
| 34 |
+
|
| 35 |
+
# aiohttp specific types
|
| 36 |
+
CLOSING = 0x100
|
| 37 |
+
CLOSED = 0x101
|
| 38 |
+
ERROR = 0x102
|
| 39 |
+
|
| 40 |
+
text = TEXT
|
| 41 |
+
binary = BINARY
|
| 42 |
+
ping = PING
|
| 43 |
+
pong = PONG
|
| 44 |
+
close = CLOSE
|
| 45 |
+
closing = CLOSING
|
| 46 |
+
closed = CLOSED
|
| 47 |
+
error = ERROR
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
class WSMessage(NamedTuple):
|
| 51 |
+
type: WSMsgType
|
| 52 |
+
# To type correctly, this would need some kind of tagged union for each type.
|
| 53 |
+
data: Any
|
| 54 |
+
extra: Optional[str]
|
| 55 |
+
|
| 56 |
+
def json(self, *, loads: Callable[[Any], Any] = json.loads) -> Any:
|
| 57 |
+
"""Return parsed JSON data.
|
| 58 |
+
|
| 59 |
+
.. versionadded:: 0.22
|
| 60 |
+
"""
|
| 61 |
+
return loads(self.data)
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
# Constructing the tuple directly to avoid the overhead of
|
| 65 |
+
# the lambda and arg processing since NamedTuples are constructed
|
| 66 |
+
# with a run time built lambda
|
| 67 |
+
# https://github.com/python/cpython/blob/d83fcf8371f2f33c7797bc8f5423a8bca8c46e5c/Lib/collections/__init__.py#L441
|
| 68 |
+
WS_CLOSED_MESSAGE = tuple.__new__(WSMessage, (WSMsgType.CLOSED, None, None))
|
| 69 |
+
WS_CLOSING_MESSAGE = tuple.__new__(WSMessage, (WSMsgType.CLOSING, None, None))
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
class WebSocketError(Exception):
|
| 73 |
+
"""WebSocket protocol parser error."""
|
| 74 |
+
|
| 75 |
+
def __init__(self, code: int, message: str) -> None:
|
| 76 |
+
self.code = code
|
| 77 |
+
super().__init__(code, message)
|
| 78 |
+
|
| 79 |
+
def __str__(self) -> str:
|
| 80 |
+
return cast(str, self.args[1])
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
class WSHandshakeError(Exception):
|
| 84 |
+
"""WebSocket protocol handshake error."""
|
infer_4_33_0/lib/python3.10/site-packages/aiohttp/_websocket/reader.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Reader for WebSocket protocol versions 13 and 8."""
|
| 2 |
+
|
| 3 |
+
from typing import TYPE_CHECKING
|
| 4 |
+
|
| 5 |
+
from ..helpers import NO_EXTENSIONS
|
| 6 |
+
|
| 7 |
+
if TYPE_CHECKING or NO_EXTENSIONS: # pragma: no cover
|
| 8 |
+
from .reader_py import (
|
| 9 |
+
WebSocketDataQueue as WebSocketDataQueuePython,
|
| 10 |
+
WebSocketReader as WebSocketReaderPython,
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
WebSocketReader = WebSocketReaderPython
|
| 14 |
+
WebSocketDataQueue = WebSocketDataQueuePython
|
| 15 |
+
else:
|
| 16 |
+
try:
|
| 17 |
+
from .reader_c import ( # type: ignore[import-not-found]
|
| 18 |
+
WebSocketDataQueue as WebSocketDataQueueCython,
|
| 19 |
+
WebSocketReader as WebSocketReaderCython,
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
WebSocketReader = WebSocketReaderCython
|
| 23 |
+
WebSocketDataQueue = WebSocketDataQueueCython
|
| 24 |
+
except ImportError: # pragma: no cover
|
| 25 |
+
from .reader_py import (
|
| 26 |
+
WebSocketDataQueue as WebSocketDataQueuePython,
|
| 27 |
+
WebSocketReader as WebSocketReaderPython,
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
WebSocketReader = WebSocketReaderPython
|
| 31 |
+
WebSocketDataQueue = WebSocketDataQueuePython
|
infer_4_33_0/lib/python3.10/site-packages/aiohttp/_websocket/reader_c.cpython-310-x86_64-linux-gnu.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1c5ee8930e058192e5010d0bf82618fce110b123c08a7ca5db16bbb7fe1af988
|
| 3 |
+
size 1666456
|
infer_4_33_0/lib/python3.10/site-packages/aiohttp/_websocket/reader_c.pxd
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import cython
|
| 2 |
+
|
| 3 |
+
from .mask cimport _websocket_mask_cython as websocket_mask
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
cdef unsigned int READ_HEADER
|
| 7 |
+
cdef unsigned int READ_PAYLOAD_LENGTH
|
| 8 |
+
cdef unsigned int READ_PAYLOAD_MASK
|
| 9 |
+
cdef unsigned int READ_PAYLOAD
|
| 10 |
+
|
| 11 |
+
cdef unsigned int OP_CODE_CONTINUATION
|
| 12 |
+
cdef unsigned int OP_CODE_TEXT
|
| 13 |
+
cdef unsigned int OP_CODE_BINARY
|
| 14 |
+
cdef unsigned int OP_CODE_CLOSE
|
| 15 |
+
cdef unsigned int OP_CODE_PING
|
| 16 |
+
cdef unsigned int OP_CODE_PONG
|
| 17 |
+
|
| 18 |
+
cdef object UNPACK_LEN3
|
| 19 |
+
cdef object UNPACK_CLOSE_CODE
|
| 20 |
+
cdef object TUPLE_NEW
|
| 21 |
+
|
| 22 |
+
cdef object WSMsgType
|
| 23 |
+
cdef object WSMessage
|
| 24 |
+
|
| 25 |
+
cdef object WS_MSG_TYPE_TEXT
|
| 26 |
+
cdef object WS_MSG_TYPE_BINARY
|
| 27 |
+
|
| 28 |
+
cdef set ALLOWED_CLOSE_CODES
|
| 29 |
+
cdef set MESSAGE_TYPES_WITH_CONTENT
|
| 30 |
+
|
| 31 |
+
cdef tuple EMPTY_FRAME
|
| 32 |
+
cdef tuple EMPTY_FRAME_ERROR
|
| 33 |
+
|
| 34 |
+
cdef class WebSocketDataQueue:
|
| 35 |
+
|
| 36 |
+
cdef unsigned int _size
|
| 37 |
+
cdef public object _protocol
|
| 38 |
+
cdef unsigned int _limit
|
| 39 |
+
cdef object _loop
|
| 40 |
+
cdef bint _eof
|
| 41 |
+
cdef object _waiter
|
| 42 |
+
cdef object _exception
|
| 43 |
+
cdef public object _buffer
|
| 44 |
+
cdef object _get_buffer
|
| 45 |
+
cdef object _put_buffer
|
| 46 |
+
|
| 47 |
+
cdef void _release_waiter(self)
|
| 48 |
+
|
| 49 |
+
cpdef void feed_data(self, object data, unsigned int size)
|
| 50 |
+
|
| 51 |
+
@cython.locals(size="unsigned int")
|
| 52 |
+
cdef _read_from_buffer(self)
|
| 53 |
+
|
| 54 |
+
cdef class WebSocketReader:
|
| 55 |
+
|
| 56 |
+
cdef WebSocketDataQueue queue
|
| 57 |
+
cdef unsigned int _max_msg_size
|
| 58 |
+
|
| 59 |
+
cdef Exception _exc
|
| 60 |
+
cdef bytearray _partial
|
| 61 |
+
cdef unsigned int _state
|
| 62 |
+
|
| 63 |
+
cdef object _opcode
|
| 64 |
+
cdef object _frame_fin
|
| 65 |
+
cdef object _frame_opcode
|
| 66 |
+
cdef object _frame_payload
|
| 67 |
+
cdef unsigned long long _frame_payload_len
|
| 68 |
+
|
| 69 |
+
cdef bytes _tail
|
| 70 |
+
cdef bint _has_mask
|
| 71 |
+
cdef bytes _frame_mask
|
| 72 |
+
cdef unsigned long long _payload_length
|
| 73 |
+
cdef unsigned int _payload_length_flag
|
| 74 |
+
cdef object _compressed
|
| 75 |
+
cdef object _decompressobj
|
| 76 |
+
cdef bint _compress
|
| 77 |
+
|
| 78 |
+
cpdef tuple feed_data(self, object data)
|
| 79 |
+
|
| 80 |
+
@cython.locals(
|
| 81 |
+
is_continuation=bint,
|
| 82 |
+
fin=bint,
|
| 83 |
+
has_partial=bint,
|
| 84 |
+
payload_merged=bytes,
|
| 85 |
+
opcode="unsigned int",
|
| 86 |
+
)
|
| 87 |
+
cpdef void _feed_data(self, bytes data)
|
| 88 |
+
|
| 89 |
+
@cython.locals(
|
| 90 |
+
start_pos="unsigned int",
|
| 91 |
+
buf_len="unsigned int",
|
| 92 |
+
length="unsigned int",
|
| 93 |
+
chunk_size="unsigned int",
|
| 94 |
+
chunk_len="unsigned int",
|
| 95 |
+
buf_length="unsigned int",
|
| 96 |
+
first_byte="unsigned char",
|
| 97 |
+
second_byte="unsigned char",
|
| 98 |
+
end_pos="unsigned int",
|
| 99 |
+
has_mask=bint,
|
| 100 |
+
fin=bint,
|
| 101 |
+
)
|
| 102 |
+
cpdef list parse_frame(self, bytes buf)
|
infer_4_33_0/lib/python3.10/site-packages/aiohttp/_websocket/reader_c.py
ADDED
|
@@ -0,0 +1,468 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Reader for WebSocket protocol versions 13 and 8."""
|
| 2 |
+
|
| 3 |
+
import asyncio
|
| 4 |
+
import builtins
|
| 5 |
+
from collections import deque
|
| 6 |
+
from typing import Deque, Final, List, Optional, Set, Tuple, Union
|
| 7 |
+
|
| 8 |
+
from ..base_protocol import BaseProtocol
|
| 9 |
+
from ..compression_utils import ZLibDecompressor
|
| 10 |
+
from ..helpers import _EXC_SENTINEL, set_exception
|
| 11 |
+
from ..streams import EofStream
|
| 12 |
+
from .helpers import UNPACK_CLOSE_CODE, UNPACK_LEN3, websocket_mask
|
| 13 |
+
from .models import (
|
| 14 |
+
WS_DEFLATE_TRAILING,
|
| 15 |
+
WebSocketError,
|
| 16 |
+
WSCloseCode,
|
| 17 |
+
WSMessage,
|
| 18 |
+
WSMsgType,
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
ALLOWED_CLOSE_CODES: Final[Set[int]] = {int(i) for i in WSCloseCode}
|
| 22 |
+
|
| 23 |
+
# States for the reader, used to parse the WebSocket frame
|
| 24 |
+
# integer values are used so they can be cythonized
|
| 25 |
+
READ_HEADER = 1
|
| 26 |
+
READ_PAYLOAD_LENGTH = 2
|
| 27 |
+
READ_PAYLOAD_MASK = 3
|
| 28 |
+
READ_PAYLOAD = 4
|
| 29 |
+
|
| 30 |
+
WS_MSG_TYPE_BINARY = WSMsgType.BINARY
|
| 31 |
+
WS_MSG_TYPE_TEXT = WSMsgType.TEXT
|
| 32 |
+
|
| 33 |
+
# WSMsgType values unpacked so they can by cythonized to ints
|
| 34 |
+
OP_CODE_CONTINUATION = WSMsgType.CONTINUATION.value
|
| 35 |
+
OP_CODE_TEXT = WSMsgType.TEXT.value
|
| 36 |
+
OP_CODE_BINARY = WSMsgType.BINARY.value
|
| 37 |
+
OP_CODE_CLOSE = WSMsgType.CLOSE.value
|
| 38 |
+
OP_CODE_PING = WSMsgType.PING.value
|
| 39 |
+
OP_CODE_PONG = WSMsgType.PONG.value
|
| 40 |
+
|
| 41 |
+
EMPTY_FRAME_ERROR = (True, b"")
|
| 42 |
+
EMPTY_FRAME = (False, b"")
|
| 43 |
+
|
| 44 |
+
TUPLE_NEW = tuple.__new__
|
| 45 |
+
|
| 46 |
+
int_ = int # Prevent Cython from converting to PyInt
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
class WebSocketDataQueue:
|
| 50 |
+
"""WebSocketDataQueue resumes and pauses an underlying stream.
|
| 51 |
+
|
| 52 |
+
It is a destination for WebSocket data.
|
| 53 |
+
"""
|
| 54 |
+
|
| 55 |
+
def __init__(
|
| 56 |
+
self, protocol: BaseProtocol, limit: int, *, loop: asyncio.AbstractEventLoop
|
| 57 |
+
) -> None:
|
| 58 |
+
self._size = 0
|
| 59 |
+
self._protocol = protocol
|
| 60 |
+
self._limit = limit * 2
|
| 61 |
+
self._loop = loop
|
| 62 |
+
self._eof = False
|
| 63 |
+
self._waiter: Optional[asyncio.Future[None]] = None
|
| 64 |
+
self._exception: Union[BaseException, None] = None
|
| 65 |
+
self._buffer: Deque[Tuple[WSMessage, int]] = deque()
|
| 66 |
+
self._get_buffer = self._buffer.popleft
|
| 67 |
+
self._put_buffer = self._buffer.append
|
| 68 |
+
|
| 69 |
+
def is_eof(self) -> bool:
|
| 70 |
+
return self._eof
|
| 71 |
+
|
| 72 |
+
def exception(self) -> Optional[BaseException]:
|
| 73 |
+
return self._exception
|
| 74 |
+
|
| 75 |
+
def set_exception(
|
| 76 |
+
self,
|
| 77 |
+
exc: "BaseException",
|
| 78 |
+
exc_cause: builtins.BaseException = _EXC_SENTINEL,
|
| 79 |
+
) -> None:
|
| 80 |
+
self._eof = True
|
| 81 |
+
self._exception = exc
|
| 82 |
+
if (waiter := self._waiter) is not None:
|
| 83 |
+
self._waiter = None
|
| 84 |
+
set_exception(waiter, exc, exc_cause)
|
| 85 |
+
|
| 86 |
+
def _release_waiter(self) -> None:
|
| 87 |
+
if (waiter := self._waiter) is None:
|
| 88 |
+
return
|
| 89 |
+
self._waiter = None
|
| 90 |
+
if not waiter.done():
|
| 91 |
+
waiter.set_result(None)
|
| 92 |
+
|
| 93 |
+
def feed_eof(self) -> None:
|
| 94 |
+
self._eof = True
|
| 95 |
+
self._release_waiter()
|
| 96 |
+
|
| 97 |
+
def feed_data(self, data: "WSMessage", size: "int_") -> None:
|
| 98 |
+
self._size += size
|
| 99 |
+
self._put_buffer((data, size))
|
| 100 |
+
self._release_waiter()
|
| 101 |
+
if self._size > self._limit and not self._protocol._reading_paused:
|
| 102 |
+
self._protocol.pause_reading()
|
| 103 |
+
|
| 104 |
+
async def read(self) -> WSMessage:
|
| 105 |
+
if not self._buffer and not self._eof:
|
| 106 |
+
assert not self._waiter
|
| 107 |
+
self._waiter = self._loop.create_future()
|
| 108 |
+
try:
|
| 109 |
+
await self._waiter
|
| 110 |
+
except (asyncio.CancelledError, asyncio.TimeoutError):
|
| 111 |
+
self._waiter = None
|
| 112 |
+
raise
|
| 113 |
+
return self._read_from_buffer()
|
| 114 |
+
|
| 115 |
+
def _read_from_buffer(self) -> WSMessage:
|
| 116 |
+
if self._buffer:
|
| 117 |
+
data, size = self._get_buffer()
|
| 118 |
+
self._size -= size
|
| 119 |
+
if self._size < self._limit and self._protocol._reading_paused:
|
| 120 |
+
self._protocol.resume_reading()
|
| 121 |
+
return data
|
| 122 |
+
if self._exception is not None:
|
| 123 |
+
raise self._exception
|
| 124 |
+
raise EofStream
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
class WebSocketReader:
|
| 128 |
+
def __init__(
|
| 129 |
+
self, queue: WebSocketDataQueue, max_msg_size: int, compress: bool = True
|
| 130 |
+
) -> None:
|
| 131 |
+
self.queue = queue
|
| 132 |
+
self._max_msg_size = max_msg_size
|
| 133 |
+
|
| 134 |
+
self._exc: Optional[Exception] = None
|
| 135 |
+
self._partial = bytearray()
|
| 136 |
+
self._state = READ_HEADER
|
| 137 |
+
|
| 138 |
+
self._opcode: Optional[int] = None
|
| 139 |
+
self._frame_fin = False
|
| 140 |
+
self._frame_opcode: Optional[int] = None
|
| 141 |
+
self._frame_payload: Union[bytes, bytearray] = b""
|
| 142 |
+
self._frame_payload_len = 0
|
| 143 |
+
|
| 144 |
+
self._tail: bytes = b""
|
| 145 |
+
self._has_mask = False
|
| 146 |
+
self._frame_mask: Optional[bytes] = None
|
| 147 |
+
self._payload_length = 0
|
| 148 |
+
self._payload_length_flag = 0
|
| 149 |
+
self._compressed: Optional[bool] = None
|
| 150 |
+
self._decompressobj: Optional[ZLibDecompressor] = None
|
| 151 |
+
self._compress = compress
|
| 152 |
+
|
| 153 |
+
def feed_eof(self) -> None:
|
| 154 |
+
self.queue.feed_eof()
|
| 155 |
+
|
| 156 |
+
# data can be bytearray on Windows because proactor event loop uses bytearray
|
| 157 |
+
# and asyncio types this to Union[bytes, bytearray, memoryview] so we need
|
| 158 |
+
# coerce data to bytes if it is not
|
| 159 |
+
def feed_data(
|
| 160 |
+
self, data: Union[bytes, bytearray, memoryview]
|
| 161 |
+
) -> Tuple[bool, bytes]:
|
| 162 |
+
if type(data) is not bytes:
|
| 163 |
+
data = bytes(data)
|
| 164 |
+
|
| 165 |
+
if self._exc is not None:
|
| 166 |
+
return True, data
|
| 167 |
+
|
| 168 |
+
try:
|
| 169 |
+
self._feed_data(data)
|
| 170 |
+
except Exception as exc:
|
| 171 |
+
self._exc = exc
|
| 172 |
+
set_exception(self.queue, exc)
|
| 173 |
+
return EMPTY_FRAME_ERROR
|
| 174 |
+
|
| 175 |
+
return EMPTY_FRAME
|
| 176 |
+
|
| 177 |
+
def _feed_data(self, data: bytes) -> None:
|
| 178 |
+
msg: WSMessage
|
| 179 |
+
for frame in self.parse_frame(data):
|
| 180 |
+
fin = frame[0]
|
| 181 |
+
opcode = frame[1]
|
| 182 |
+
payload = frame[2]
|
| 183 |
+
compressed = frame[3]
|
| 184 |
+
|
| 185 |
+
is_continuation = opcode == OP_CODE_CONTINUATION
|
| 186 |
+
if opcode == OP_CODE_TEXT or opcode == OP_CODE_BINARY or is_continuation:
|
| 187 |
+
# load text/binary
|
| 188 |
+
if not fin:
|
| 189 |
+
# got partial frame payload
|
| 190 |
+
if not is_continuation:
|
| 191 |
+
self._opcode = opcode
|
| 192 |
+
self._partial += payload
|
| 193 |
+
if self._max_msg_size and len(self._partial) >= self._max_msg_size:
|
| 194 |
+
raise WebSocketError(
|
| 195 |
+
WSCloseCode.MESSAGE_TOO_BIG,
|
| 196 |
+
"Message size {} exceeds limit {}".format(
|
| 197 |
+
len(self._partial), self._max_msg_size
|
| 198 |
+
),
|
| 199 |
+
)
|
| 200 |
+
continue
|
| 201 |
+
|
| 202 |
+
has_partial = bool(self._partial)
|
| 203 |
+
if is_continuation:
|
| 204 |
+
if self._opcode is None:
|
| 205 |
+
raise WebSocketError(
|
| 206 |
+
WSCloseCode.PROTOCOL_ERROR,
|
| 207 |
+
"Continuation frame for non started message",
|
| 208 |
+
)
|
| 209 |
+
opcode = self._opcode
|
| 210 |
+
self._opcode = None
|
| 211 |
+
# previous frame was non finished
|
| 212 |
+
# we should get continuation opcode
|
| 213 |
+
elif has_partial:
|
| 214 |
+
raise WebSocketError(
|
| 215 |
+
WSCloseCode.PROTOCOL_ERROR,
|
| 216 |
+
"The opcode in non-fin frame is expected "
|
| 217 |
+
"to be zero, got {!r}".format(opcode),
|
| 218 |
+
)
|
| 219 |
+
|
| 220 |
+
assembled_payload: Union[bytes, bytearray]
|
| 221 |
+
if has_partial:
|
| 222 |
+
assembled_payload = self._partial + payload
|
| 223 |
+
self._partial.clear()
|
| 224 |
+
else:
|
| 225 |
+
assembled_payload = payload
|
| 226 |
+
|
| 227 |
+
if self._max_msg_size and len(assembled_payload) >= self._max_msg_size:
|
| 228 |
+
raise WebSocketError(
|
| 229 |
+
WSCloseCode.MESSAGE_TOO_BIG,
|
| 230 |
+
"Message size {} exceeds limit {}".format(
|
| 231 |
+
len(assembled_payload), self._max_msg_size
|
| 232 |
+
),
|
| 233 |
+
)
|
| 234 |
+
|
| 235 |
+
# Decompress process must to be done after all packets
|
| 236 |
+
# received.
|
| 237 |
+
if compressed:
|
| 238 |
+
if not self._decompressobj:
|
| 239 |
+
self._decompressobj = ZLibDecompressor(
|
| 240 |
+
suppress_deflate_header=True
|
| 241 |
+
)
|
| 242 |
+
payload_merged = self._decompressobj.decompress_sync(
|
| 243 |
+
assembled_payload + WS_DEFLATE_TRAILING, self._max_msg_size
|
| 244 |
+
)
|
| 245 |
+
if self._decompressobj.unconsumed_tail:
|
| 246 |
+
left = len(self._decompressobj.unconsumed_tail)
|
| 247 |
+
raise WebSocketError(
|
| 248 |
+
WSCloseCode.MESSAGE_TOO_BIG,
|
| 249 |
+
"Decompressed message size {} exceeds limit {}".format(
|
| 250 |
+
self._max_msg_size + left, self._max_msg_size
|
| 251 |
+
),
|
| 252 |
+
)
|
| 253 |
+
elif type(assembled_payload) is bytes:
|
| 254 |
+
payload_merged = assembled_payload
|
| 255 |
+
else:
|
| 256 |
+
payload_merged = bytes(assembled_payload)
|
| 257 |
+
|
| 258 |
+
if opcode == OP_CODE_TEXT:
|
| 259 |
+
try:
|
| 260 |
+
text = payload_merged.decode("utf-8")
|
| 261 |
+
except UnicodeDecodeError as exc:
|
| 262 |
+
raise WebSocketError(
|
| 263 |
+
WSCloseCode.INVALID_TEXT, "Invalid UTF-8 text message"
|
| 264 |
+
) from exc
|
| 265 |
+
|
| 266 |
+
# XXX: The Text and Binary messages here can be a performance
|
| 267 |
+
# bottleneck, so we use tuple.__new__ to improve performance.
|
| 268 |
+
# This is not type safe, but many tests should fail in
|
| 269 |
+
# test_client_ws_functional.py if this is wrong.
|
| 270 |
+
self.queue.feed_data(
|
| 271 |
+
TUPLE_NEW(WSMessage, (WS_MSG_TYPE_TEXT, text, "")),
|
| 272 |
+
len(payload_merged),
|
| 273 |
+
)
|
| 274 |
+
else:
|
| 275 |
+
self.queue.feed_data(
|
| 276 |
+
TUPLE_NEW(WSMessage, (WS_MSG_TYPE_BINARY, payload_merged, "")),
|
| 277 |
+
len(payload_merged),
|
| 278 |
+
)
|
| 279 |
+
elif opcode == OP_CODE_CLOSE:
|
| 280 |
+
if len(payload) >= 2:
|
| 281 |
+
close_code = UNPACK_CLOSE_CODE(payload[:2])[0]
|
| 282 |
+
if close_code < 3000 and close_code not in ALLOWED_CLOSE_CODES:
|
| 283 |
+
raise WebSocketError(
|
| 284 |
+
WSCloseCode.PROTOCOL_ERROR,
|
| 285 |
+
f"Invalid close code: {close_code}",
|
| 286 |
+
)
|
| 287 |
+
try:
|
| 288 |
+
close_message = payload[2:].decode("utf-8")
|
| 289 |
+
except UnicodeDecodeError as exc:
|
| 290 |
+
raise WebSocketError(
|
| 291 |
+
WSCloseCode.INVALID_TEXT, "Invalid UTF-8 text message"
|
| 292 |
+
) from exc
|
| 293 |
+
msg = TUPLE_NEW(
|
| 294 |
+
WSMessage, (WSMsgType.CLOSE, close_code, close_message)
|
| 295 |
+
)
|
| 296 |
+
elif payload:
|
| 297 |
+
raise WebSocketError(
|
| 298 |
+
WSCloseCode.PROTOCOL_ERROR,
|
| 299 |
+
f"Invalid close frame: {fin} {opcode} {payload!r}",
|
| 300 |
+
)
|
| 301 |
+
else:
|
| 302 |
+
msg = TUPLE_NEW(WSMessage, (WSMsgType.CLOSE, 0, ""))
|
| 303 |
+
|
| 304 |
+
self.queue.feed_data(msg, 0)
|
| 305 |
+
elif opcode == OP_CODE_PING:
|
| 306 |
+
msg = TUPLE_NEW(WSMessage, (WSMsgType.PING, payload, ""))
|
| 307 |
+
self.queue.feed_data(msg, len(payload))
|
| 308 |
+
|
| 309 |
+
elif opcode == OP_CODE_PONG:
|
| 310 |
+
msg = TUPLE_NEW(WSMessage, (WSMsgType.PONG, payload, ""))
|
| 311 |
+
self.queue.feed_data(msg, len(payload))
|
| 312 |
+
|
| 313 |
+
else:
|
| 314 |
+
raise WebSocketError(
|
| 315 |
+
WSCloseCode.PROTOCOL_ERROR, f"Unexpected opcode={opcode!r}"
|
| 316 |
+
)
|
| 317 |
+
|
| 318 |
+
def parse_frame(
|
| 319 |
+
self, buf: bytes
|
| 320 |
+
) -> List[Tuple[bool, Optional[int], Union[bytes, bytearray], Optional[bool]]]:
|
| 321 |
+
"""Return the next frame from the socket."""
|
| 322 |
+
frames: List[
|
| 323 |
+
Tuple[bool, Optional[int], Union[bytes, bytearray], Optional[bool]]
|
| 324 |
+
] = []
|
| 325 |
+
if self._tail:
|
| 326 |
+
buf, self._tail = self._tail + buf, b""
|
| 327 |
+
|
| 328 |
+
start_pos: int = 0
|
| 329 |
+
buf_length = len(buf)
|
| 330 |
+
|
| 331 |
+
while True:
|
| 332 |
+
# read header
|
| 333 |
+
if self._state == READ_HEADER:
|
| 334 |
+
if buf_length - start_pos < 2:
|
| 335 |
+
break
|
| 336 |
+
first_byte = buf[start_pos]
|
| 337 |
+
second_byte = buf[start_pos + 1]
|
| 338 |
+
start_pos += 2
|
| 339 |
+
|
| 340 |
+
fin = (first_byte >> 7) & 1
|
| 341 |
+
rsv1 = (first_byte >> 6) & 1
|
| 342 |
+
rsv2 = (first_byte >> 5) & 1
|
| 343 |
+
rsv3 = (first_byte >> 4) & 1
|
| 344 |
+
opcode = first_byte & 0xF
|
| 345 |
+
|
| 346 |
+
# frame-fin = %x0 ; more frames of this message follow
|
| 347 |
+
# / %x1 ; final frame of this message
|
| 348 |
+
# frame-rsv1 = %x0 ;
|
| 349 |
+
# 1 bit, MUST be 0 unless negotiated otherwise
|
| 350 |
+
# frame-rsv2 = %x0 ;
|
| 351 |
+
# 1 bit, MUST be 0 unless negotiated otherwise
|
| 352 |
+
# frame-rsv3 = %x0 ;
|
| 353 |
+
# 1 bit, MUST be 0 unless negotiated otherwise
|
| 354 |
+
#
|
| 355 |
+
# Remove rsv1 from this test for deflate development
|
| 356 |
+
if rsv2 or rsv3 or (rsv1 and not self._compress):
|
| 357 |
+
raise WebSocketError(
|
| 358 |
+
WSCloseCode.PROTOCOL_ERROR,
|
| 359 |
+
"Received frame with non-zero reserved bits",
|
| 360 |
+
)
|
| 361 |
+
|
| 362 |
+
if opcode > 0x7 and fin == 0:
|
| 363 |
+
raise WebSocketError(
|
| 364 |
+
WSCloseCode.PROTOCOL_ERROR,
|
| 365 |
+
"Received fragmented control frame",
|
| 366 |
+
)
|
| 367 |
+
|
| 368 |
+
has_mask = (second_byte >> 7) & 1
|
| 369 |
+
length = second_byte & 0x7F
|
| 370 |
+
|
| 371 |
+
# Control frames MUST have a payload
|
| 372 |
+
# length of 125 bytes or less
|
| 373 |
+
if opcode > 0x7 and length > 125:
|
| 374 |
+
raise WebSocketError(
|
| 375 |
+
WSCloseCode.PROTOCOL_ERROR,
|
| 376 |
+
"Control frame payload cannot be larger than 125 bytes",
|
| 377 |
+
)
|
| 378 |
+
|
| 379 |
+
# Set compress status if last package is FIN
|
| 380 |
+
# OR set compress status if this is first fragment
|
| 381 |
+
# Raise error if not first fragment with rsv1 = 0x1
|
| 382 |
+
if self._frame_fin or self._compressed is None:
|
| 383 |
+
self._compressed = True if rsv1 else False
|
| 384 |
+
elif rsv1:
|
| 385 |
+
raise WebSocketError(
|
| 386 |
+
WSCloseCode.PROTOCOL_ERROR,
|
| 387 |
+
"Received frame with non-zero reserved bits",
|
| 388 |
+
)
|
| 389 |
+
|
| 390 |
+
self._frame_fin = bool(fin)
|
| 391 |
+
self._frame_opcode = opcode
|
| 392 |
+
self._has_mask = bool(has_mask)
|
| 393 |
+
self._payload_length_flag = length
|
| 394 |
+
self._state = READ_PAYLOAD_LENGTH
|
| 395 |
+
|
| 396 |
+
# read payload length
|
| 397 |
+
if self._state == READ_PAYLOAD_LENGTH:
|
| 398 |
+
length_flag = self._payload_length_flag
|
| 399 |
+
if length_flag == 126:
|
| 400 |
+
if buf_length - start_pos < 2:
|
| 401 |
+
break
|
| 402 |
+
first_byte = buf[start_pos]
|
| 403 |
+
second_byte = buf[start_pos + 1]
|
| 404 |
+
start_pos += 2
|
| 405 |
+
self._payload_length = first_byte << 8 | second_byte
|
| 406 |
+
elif length_flag > 126:
|
| 407 |
+
if buf_length - start_pos < 8:
|
| 408 |
+
break
|
| 409 |
+
data = buf[start_pos : start_pos + 8]
|
| 410 |
+
start_pos += 8
|
| 411 |
+
self._payload_length = UNPACK_LEN3(data)[0]
|
| 412 |
+
else:
|
| 413 |
+
self._payload_length = length_flag
|
| 414 |
+
|
| 415 |
+
self._state = READ_PAYLOAD_MASK if self._has_mask else READ_PAYLOAD
|
| 416 |
+
|
| 417 |
+
# read payload mask
|
| 418 |
+
if self._state == READ_PAYLOAD_MASK:
|
| 419 |
+
if buf_length - start_pos < 4:
|
| 420 |
+
break
|
| 421 |
+
self._frame_mask = buf[start_pos : start_pos + 4]
|
| 422 |
+
start_pos += 4
|
| 423 |
+
self._state = READ_PAYLOAD
|
| 424 |
+
|
| 425 |
+
if self._state == READ_PAYLOAD:
|
| 426 |
+
chunk_len = buf_length - start_pos
|
| 427 |
+
if self._payload_length >= chunk_len:
|
| 428 |
+
end_pos = buf_length
|
| 429 |
+
self._payload_length -= chunk_len
|
| 430 |
+
else:
|
| 431 |
+
end_pos = start_pos + self._payload_length
|
| 432 |
+
self._payload_length = 0
|
| 433 |
+
|
| 434 |
+
if self._frame_payload_len:
|
| 435 |
+
if type(self._frame_payload) is not bytearray:
|
| 436 |
+
self._frame_payload = bytearray(self._frame_payload)
|
| 437 |
+
self._frame_payload += buf[start_pos:end_pos]
|
| 438 |
+
else:
|
| 439 |
+
# Fast path for the first frame
|
| 440 |
+
self._frame_payload = buf[start_pos:end_pos]
|
| 441 |
+
|
| 442 |
+
self._frame_payload_len += end_pos - start_pos
|
| 443 |
+
start_pos = end_pos
|
| 444 |
+
|
| 445 |
+
if self._payload_length != 0:
|
| 446 |
+
break
|
| 447 |
+
|
| 448 |
+
if self._has_mask:
|
| 449 |
+
assert self._frame_mask is not None
|
| 450 |
+
if type(self._frame_payload) is not bytearray:
|
| 451 |
+
self._frame_payload = bytearray(self._frame_payload)
|
| 452 |
+
websocket_mask(self._frame_mask, self._frame_payload)
|
| 453 |
+
|
| 454 |
+
frames.append(
|
| 455 |
+
(
|
| 456 |
+
self._frame_fin,
|
| 457 |
+
self._frame_opcode,
|
| 458 |
+
self._frame_payload,
|
| 459 |
+
self._compressed,
|
| 460 |
+
)
|
| 461 |
+
)
|
| 462 |
+
self._frame_payload = b""
|
| 463 |
+
self._frame_payload_len = 0
|
| 464 |
+
self._state = READ_HEADER
|
| 465 |
+
|
| 466 |
+
self._tail = buf[start_pos:] if start_pos < buf_length else b""
|
| 467 |
+
|
| 468 |
+
return frames
|
infer_4_33_0/lib/python3.10/site-packages/aiohttp/_websocket/writer.py
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""WebSocket protocol versions 13 and 8."""
|
| 2 |
+
|
| 3 |
+
import asyncio
|
| 4 |
+
import random
|
| 5 |
+
import zlib
|
| 6 |
+
from functools import partial
|
| 7 |
+
from typing import Any, Final, Optional, Union
|
| 8 |
+
|
| 9 |
+
from ..base_protocol import BaseProtocol
|
| 10 |
+
from ..client_exceptions import ClientConnectionResetError
|
| 11 |
+
from ..compression_utils import ZLibCompressor
|
| 12 |
+
from .helpers import (
|
| 13 |
+
MASK_LEN,
|
| 14 |
+
MSG_SIZE,
|
| 15 |
+
PACK_CLOSE_CODE,
|
| 16 |
+
PACK_LEN1,
|
| 17 |
+
PACK_LEN2,
|
| 18 |
+
PACK_LEN3,
|
| 19 |
+
PACK_RANDBITS,
|
| 20 |
+
websocket_mask,
|
| 21 |
+
)
|
| 22 |
+
from .models import WS_DEFLATE_TRAILING, WSMsgType
|
| 23 |
+
|
| 24 |
+
DEFAULT_LIMIT: Final[int] = 2**16
|
| 25 |
+
|
| 26 |
+
# For websockets, keeping latency low is extremely important as implementations
|
| 27 |
+
# generally expect to be able to send and receive messages quickly. We use a
|
| 28 |
+
# larger chunk size than the default to reduce the number of executor calls
|
| 29 |
+
# since the executor is a significant source of latency and overhead when
|
| 30 |
+
# the chunks are small. A size of 5KiB was chosen because it is also the
|
| 31 |
+
# same value python-zlib-ng choose to use as the threshold to release the GIL.
|
| 32 |
+
|
| 33 |
+
WEBSOCKET_MAX_SYNC_CHUNK_SIZE = 5 * 1024
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
class WebSocketWriter:
|
| 37 |
+
"""WebSocket writer.
|
| 38 |
+
|
| 39 |
+
The writer is responsible for sending messages to the client. It is
|
| 40 |
+
created by the protocol when a connection is established. The writer
|
| 41 |
+
should avoid implementing any application logic and should only be
|
| 42 |
+
concerned with the low-level details of the WebSocket protocol.
|
| 43 |
+
"""
|
| 44 |
+
|
| 45 |
+
def __init__(
|
| 46 |
+
self,
|
| 47 |
+
protocol: BaseProtocol,
|
| 48 |
+
transport: asyncio.Transport,
|
| 49 |
+
*,
|
| 50 |
+
use_mask: bool = False,
|
| 51 |
+
limit: int = DEFAULT_LIMIT,
|
| 52 |
+
random: random.Random = random.Random(),
|
| 53 |
+
compress: int = 0,
|
| 54 |
+
notakeover: bool = False,
|
| 55 |
+
) -> None:
|
| 56 |
+
"""Initialize a WebSocket writer."""
|
| 57 |
+
self.protocol = protocol
|
| 58 |
+
self.transport = transport
|
| 59 |
+
self.use_mask = use_mask
|
| 60 |
+
self.get_random_bits = partial(random.getrandbits, 32)
|
| 61 |
+
self.compress = compress
|
| 62 |
+
self.notakeover = notakeover
|
| 63 |
+
self._closing = False
|
| 64 |
+
self._limit = limit
|
| 65 |
+
self._output_size = 0
|
| 66 |
+
self._compressobj: Any = None # actually compressobj
|
| 67 |
+
|
| 68 |
+
async def send_frame(
|
| 69 |
+
self, message: bytes, opcode: int, compress: Optional[int] = None
|
| 70 |
+
) -> None:
|
| 71 |
+
"""Send a frame over the websocket with message as its payload."""
|
| 72 |
+
if self._closing and not (opcode & WSMsgType.CLOSE):
|
| 73 |
+
raise ClientConnectionResetError("Cannot write to closing transport")
|
| 74 |
+
|
| 75 |
+
# RSV are the reserved bits in the frame header. They are used to
|
| 76 |
+
# indicate that the frame is using an extension.
|
| 77 |
+
# https://datatracker.ietf.org/doc/html/rfc6455#section-5.2
|
| 78 |
+
rsv = 0
|
| 79 |
+
# Only compress larger packets (disabled)
|
| 80 |
+
# Does small packet needs to be compressed?
|
| 81 |
+
# if self.compress and opcode < 8 and len(message) > 124:
|
| 82 |
+
if (compress or self.compress) and opcode < 8:
|
| 83 |
+
# RSV1 (rsv = 0x40) is set for compressed frames
|
| 84 |
+
# https://datatracker.ietf.org/doc/html/rfc7692#section-7.2.3.1
|
| 85 |
+
rsv = 0x40
|
| 86 |
+
|
| 87 |
+
if compress:
|
| 88 |
+
# Do not set self._compress if compressing is for this frame
|
| 89 |
+
compressobj = self._make_compress_obj(compress)
|
| 90 |
+
else: # self.compress
|
| 91 |
+
if not self._compressobj:
|
| 92 |
+
self._compressobj = self._make_compress_obj(self.compress)
|
| 93 |
+
compressobj = self._compressobj
|
| 94 |
+
|
| 95 |
+
message = (
|
| 96 |
+
await compressobj.compress(message)
|
| 97 |
+
+ compressobj.flush(
|
| 98 |
+
zlib.Z_FULL_FLUSH if self.notakeover else zlib.Z_SYNC_FLUSH
|
| 99 |
+
)
|
| 100 |
+
).removesuffix(WS_DEFLATE_TRAILING)
|
| 101 |
+
# Its critical that we do not return control to the event
|
| 102 |
+
# loop until we have finished sending all the compressed
|
| 103 |
+
# data. Otherwise we could end up mixing compressed frames
|
| 104 |
+
# if there are multiple coroutines compressing data.
|
| 105 |
+
|
| 106 |
+
msg_length = len(message)
|
| 107 |
+
|
| 108 |
+
use_mask = self.use_mask
|
| 109 |
+
mask_bit = 0x80 if use_mask else 0
|
| 110 |
+
|
| 111 |
+
# Depending on the message length, the header is assembled differently.
|
| 112 |
+
# The first byte is reserved for the opcode and the RSV bits.
|
| 113 |
+
first_byte = 0x80 | rsv | opcode
|
| 114 |
+
if msg_length < 126:
|
| 115 |
+
header = PACK_LEN1(first_byte, msg_length | mask_bit)
|
| 116 |
+
header_len = 2
|
| 117 |
+
elif msg_length < 65536:
|
| 118 |
+
header = PACK_LEN2(first_byte, 126 | mask_bit, msg_length)
|
| 119 |
+
header_len = 4
|
| 120 |
+
else:
|
| 121 |
+
header = PACK_LEN3(first_byte, 127 | mask_bit, msg_length)
|
| 122 |
+
header_len = 10
|
| 123 |
+
|
| 124 |
+
if self.transport.is_closing():
|
| 125 |
+
raise ClientConnectionResetError("Cannot write to closing transport")
|
| 126 |
+
|
| 127 |
+
# https://datatracker.ietf.org/doc/html/rfc6455#section-5.3
|
| 128 |
+
# If we are using a mask, we need to generate it randomly
|
| 129 |
+
# and apply it to the message before sending it. A mask is
|
| 130 |
+
# a 32-bit value that is applied to the message using a
|
| 131 |
+
# bitwise XOR operation. It is used to prevent certain types
|
| 132 |
+
# of attacks on the websocket protocol. The mask is only used
|
| 133 |
+
# when aiohttp is acting as a client. Servers do not use a mask.
|
| 134 |
+
if use_mask:
|
| 135 |
+
mask = PACK_RANDBITS(self.get_random_bits())
|
| 136 |
+
message = bytearray(message)
|
| 137 |
+
websocket_mask(mask, message)
|
| 138 |
+
self.transport.write(header + mask + message)
|
| 139 |
+
self._output_size += MASK_LEN
|
| 140 |
+
elif msg_length > MSG_SIZE:
|
| 141 |
+
self.transport.write(header)
|
| 142 |
+
self.transport.write(message)
|
| 143 |
+
else:
|
| 144 |
+
self.transport.write(header + message)
|
| 145 |
+
|
| 146 |
+
self._output_size += header_len + msg_length
|
| 147 |
+
|
| 148 |
+
# It is safe to return control to the event loop when using compression
|
| 149 |
+
# after this point as we have already sent or buffered all the data.
|
| 150 |
+
|
| 151 |
+
# Once we have written output_size up to the limit, we call the
|
| 152 |
+
# drain helper which waits for the transport to be ready to accept
|
| 153 |
+
# more data. This is a flow control mechanism to prevent the buffer
|
| 154 |
+
# from growing too large. The drain helper will return right away
|
| 155 |
+
# if the writer is not paused.
|
| 156 |
+
if self._output_size > self._limit:
|
| 157 |
+
self._output_size = 0
|
| 158 |
+
if self.protocol._paused:
|
| 159 |
+
await self.protocol._drain_helper()
|
| 160 |
+
|
| 161 |
+
def _make_compress_obj(self, compress: int) -> ZLibCompressor:
|
| 162 |
+
return ZLibCompressor(
|
| 163 |
+
level=zlib.Z_BEST_SPEED,
|
| 164 |
+
wbits=-compress,
|
| 165 |
+
max_sync_chunk_size=WEBSOCKET_MAX_SYNC_CHUNK_SIZE,
|
| 166 |
+
)
|
| 167 |
+
|
| 168 |
+
async def close(self, code: int = 1000, message: Union[bytes, str] = b"") -> None:
|
| 169 |
+
"""Close the websocket, sending the specified code and message."""
|
| 170 |
+
if isinstance(message, str):
|
| 171 |
+
message = message.encode("utf-8")
|
| 172 |
+
try:
|
| 173 |
+
await self.send_frame(
|
| 174 |
+
PACK_CLOSE_CODE(code) + message, opcode=WSMsgType.CLOSE
|
| 175 |
+
)
|
| 176 |
+
finally:
|
| 177 |
+
self._closing = True
|
infer_4_33_0/lib/python3.10/site-packages/h5py/tests/data_files/vlen_string_dset.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:900f8baf19d3d8c4d1193ac1ac6019ee7774005e85c030af44e6757b38d29793
|
| 3 |
+
size 6304
|
infer_4_33_0/lib/python3.10/site-packages/h5py/tests/data_files/vlen_string_s390x.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ea990c68e0371bafab4966f752fa1355b3b9f64360066f6d9daff8f1b7e74ca5
|
| 3 |
+
size 9008
|
infer_4_33_0/lib/python3.10/site-packages/mdit_py_plugins/myst_blocks/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
from .index import myst_block_plugin # noqa: F401
|
infer_4_33_0/lib/python3.10/site-packages/mdit_py_plugins/myst_blocks/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (232 Bytes). View file
|
|
|
infer_4_33_0/lib/python3.10/site-packages/mdit_py_plugins/myst_blocks/__pycache__/index.cpython-310.pyc
ADDED
|
Binary file (3.43 kB). View file
|
|
|
infer_4_33_0/lib/python3.10/site-packages/mdit_py_plugins/myst_blocks/index.py
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import itertools
|
| 2 |
+
|
| 3 |
+
from markdown_it import MarkdownIt
|
| 4 |
+
from markdown_it.common.utils import escapeHtml, isSpace
|
| 5 |
+
from markdown_it.rules_block import StateBlock
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def myst_block_plugin(md: MarkdownIt):
|
| 9 |
+
"""Parse MyST targets (``(name)=``), blockquotes (``% comment``) and block breaks (``+++``)."""
|
| 10 |
+
md.block.ruler.before(
|
| 11 |
+
"blockquote",
|
| 12 |
+
"myst_line_comment",
|
| 13 |
+
line_comment,
|
| 14 |
+
{"alt": ["paragraph", "reference", "blockquote", "list", "footnote_def"]},
|
| 15 |
+
)
|
| 16 |
+
md.block.ruler.before(
|
| 17 |
+
"hr",
|
| 18 |
+
"myst_block_break",
|
| 19 |
+
block_break,
|
| 20 |
+
{"alt": ["paragraph", "reference", "blockquote", "list", "footnote_def"]},
|
| 21 |
+
)
|
| 22 |
+
md.block.ruler.before(
|
| 23 |
+
"hr",
|
| 24 |
+
"myst_target",
|
| 25 |
+
target,
|
| 26 |
+
{"alt": ["paragraph", "reference", "blockquote", "list", "footnote_def"]},
|
| 27 |
+
)
|
| 28 |
+
md.add_render_rule("myst_target", render_myst_target)
|
| 29 |
+
md.add_render_rule("myst_line_comment", render_myst_line_comment)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def line_comment(state: StateBlock, startLine: int, endLine: int, silent: bool):
|
| 33 |
+
|
| 34 |
+
pos = state.bMarks[startLine] + state.tShift[startLine]
|
| 35 |
+
maximum = state.eMarks[startLine]
|
| 36 |
+
|
| 37 |
+
# if it's indented more than 3 spaces, it should be a code block
|
| 38 |
+
if state.sCount[startLine] - state.blkIndent >= 4:
|
| 39 |
+
return False
|
| 40 |
+
|
| 41 |
+
if state.src[pos] != "%":
|
| 42 |
+
return False
|
| 43 |
+
|
| 44 |
+
if silent:
|
| 45 |
+
return True
|
| 46 |
+
|
| 47 |
+
token = state.push("myst_line_comment", "", 0)
|
| 48 |
+
token.attrSet("class", "myst-line-comment")
|
| 49 |
+
token.content = state.src[pos + 1 : maximum].rstrip()
|
| 50 |
+
token.markup = "%"
|
| 51 |
+
|
| 52 |
+
# search end of block while appending lines to `token.content`
|
| 53 |
+
for nextLine in itertools.count(startLine + 1):
|
| 54 |
+
if nextLine >= endLine:
|
| 55 |
+
break
|
| 56 |
+
pos = state.bMarks[nextLine] + state.tShift[nextLine]
|
| 57 |
+
maximum = state.eMarks[nextLine]
|
| 58 |
+
|
| 59 |
+
if state.src[pos] != "%":
|
| 60 |
+
break
|
| 61 |
+
token.content += "\n" + state.src[pos + 1 : maximum].rstrip()
|
| 62 |
+
|
| 63 |
+
state.line = nextLine
|
| 64 |
+
token.map = [startLine, nextLine]
|
| 65 |
+
|
| 66 |
+
return True
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def block_break(state: StateBlock, startLine: int, endLine: int, silent: bool):
|
| 70 |
+
|
| 71 |
+
pos = state.bMarks[startLine] + state.tShift[startLine]
|
| 72 |
+
maximum = state.eMarks[startLine]
|
| 73 |
+
|
| 74 |
+
# if it's indented more than 3 spaces, it should be a code block
|
| 75 |
+
if state.sCount[startLine] - state.blkIndent >= 4:
|
| 76 |
+
return False
|
| 77 |
+
|
| 78 |
+
marker = state.srcCharCode[pos]
|
| 79 |
+
pos += 1
|
| 80 |
+
|
| 81 |
+
# Check block marker /* + */
|
| 82 |
+
if marker != 0x2B:
|
| 83 |
+
return False
|
| 84 |
+
|
| 85 |
+
# markers can be mixed with spaces, but there should be at least 3 of them
|
| 86 |
+
|
| 87 |
+
cnt = 1
|
| 88 |
+
while pos < maximum:
|
| 89 |
+
ch = state.srcCharCode[pos]
|
| 90 |
+
if ch != marker and not isSpace(ch):
|
| 91 |
+
break
|
| 92 |
+
if ch == marker:
|
| 93 |
+
cnt += 1
|
| 94 |
+
pos += 1
|
| 95 |
+
|
| 96 |
+
if cnt < 3:
|
| 97 |
+
return False
|
| 98 |
+
|
| 99 |
+
if silent:
|
| 100 |
+
return True
|
| 101 |
+
|
| 102 |
+
state.line = startLine + 1
|
| 103 |
+
|
| 104 |
+
token = state.push("myst_block_break", "hr", 0)
|
| 105 |
+
token.attrSet("class", "myst-block")
|
| 106 |
+
token.content = state.src[pos:maximum].strip()
|
| 107 |
+
token.map = [startLine, state.line]
|
| 108 |
+
token.markup = chr(marker) * cnt
|
| 109 |
+
|
| 110 |
+
return True
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
def target(state: StateBlock, startLine: int, endLine: int, silent: bool):
|
| 114 |
+
|
| 115 |
+
pos = state.bMarks[startLine] + state.tShift[startLine]
|
| 116 |
+
maximum = state.eMarks[startLine]
|
| 117 |
+
|
| 118 |
+
# if it's indented more than 3 spaces, it should be a code block
|
| 119 |
+
if state.sCount[startLine] - state.blkIndent >= 4:
|
| 120 |
+
return False
|
| 121 |
+
|
| 122 |
+
text = state.src[pos:maximum].strip()
|
| 123 |
+
if not text.startswith("("):
|
| 124 |
+
return False
|
| 125 |
+
if not text.endswith(")="):
|
| 126 |
+
return False
|
| 127 |
+
if not text[1:-2]:
|
| 128 |
+
return False
|
| 129 |
+
|
| 130 |
+
if silent:
|
| 131 |
+
return True
|
| 132 |
+
|
| 133 |
+
state.line = startLine + 1
|
| 134 |
+
|
| 135 |
+
token = state.push("myst_target", "", 0)
|
| 136 |
+
token.attrSet("class", "myst-target")
|
| 137 |
+
token.content = text[1:-2]
|
| 138 |
+
token.map = [startLine, state.line]
|
| 139 |
+
|
| 140 |
+
return True
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
def render_myst_target(self, tokens, idx, options, env):
|
| 144 |
+
label = tokens[idx].content
|
| 145 |
+
class_name = "myst-target"
|
| 146 |
+
target = f'<a href="#{label}">({label})=</a>'
|
| 147 |
+
return f'<div class="{class_name}">{target}</div>'
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
def render_myst_line_comment(self, tokens, idx, options, env):
|
| 151 |
+
# Strip leading whitespace from all lines
|
| 152 |
+
content = "\n".join(line.lstrip() for line in tokens[idx].content.split("\n"))
|
| 153 |
+
return f"<!-- {escapeHtml(content)} -->"
|
infer_4_33_0/lib/python3.10/site-packages/mdit_py_plugins/myst_role/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
from .index import myst_role_plugin # noqa: F401
|
infer_4_33_0/lib/python3.10/site-packages/mdit_py_plugins/tasklists/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (4.73 kB). View file
|
|
|
infer_4_33_0/lib/python3.10/site-packages/mdit_py_plugins/texmath/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2013-17 Stefan Goessner
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
infer_4_33_0/lib/python3.10/site-packages/mdit_py_plugins/texmath/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
from .index import texmath_plugin # noqa F401
|
infer_4_33_0/lib/python3.10/site-packages/mdit_py_plugins/texmath/index.py
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re
|
| 2 |
+
from typing import Optional
|
| 3 |
+
|
| 4 |
+
from markdown_it import MarkdownIt
|
| 5 |
+
from markdown_it.common.utils import charCodeAt
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def texmath_plugin(md: MarkdownIt, delimiters="dollars", macros: Optional[dict] = None):
|
| 9 |
+
"""Plugin ported from
|
| 10 |
+
`markdown-it-texmath <https://github.com/goessner/markdown-it-texmath>`__.
|
| 11 |
+
|
| 12 |
+
It parses TeX math equations set inside opening and closing delimiters:
|
| 13 |
+
|
| 14 |
+
.. code-block:: md
|
| 15 |
+
|
| 16 |
+
$\\alpha = \\frac{1}{2}$
|
| 17 |
+
|
| 18 |
+
:param delimiters: one of: brackets, dollars, gitlab, julia, kramdown
|
| 19 |
+
|
| 20 |
+
"""
|
| 21 |
+
macros = macros or {}
|
| 22 |
+
|
| 23 |
+
if delimiters in rules:
|
| 24 |
+
for rule_inline in rules[delimiters]["inline"]:
|
| 25 |
+
md.inline.ruler.before(
|
| 26 |
+
"escape", rule_inline["name"], make_inline_func(rule_inline)
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
def render_math_inline(self, tokens, idx, options, env):
|
| 30 |
+
return rule_inline["tmpl"].format(
|
| 31 |
+
render(tokens[idx].content, False, macros)
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
md.add_render_rule(rule_inline["name"], render_math_inline)
|
| 35 |
+
|
| 36 |
+
for rule_block in rules[delimiters]["block"]:
|
| 37 |
+
md.block.ruler.before(
|
| 38 |
+
"fence", rule_block["name"], make_block_func(rule_block)
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
def render_math_block(self, tokens, idx, options, env):
|
| 42 |
+
return rule_block["tmpl"].format(
|
| 43 |
+
render(tokens[idx].content, True, macros), tokens[idx].info
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
md.add_render_rule(rule_block["name"], render_math_block)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def applyRule(rule, string: str, begin, inBlockquote):
|
| 50 |
+
|
| 51 |
+
if not (
|
| 52 |
+
string.startswith(rule["tag"], begin)
|
| 53 |
+
and (rule["pre"](string, begin) if "pre" in rule else True)
|
| 54 |
+
):
|
| 55 |
+
return False
|
| 56 |
+
|
| 57 |
+
match = rule["rex"].match(string[begin:]) # type: re.Match
|
| 58 |
+
|
| 59 |
+
if not match or match.start() != 0:
|
| 60 |
+
return False
|
| 61 |
+
|
| 62 |
+
lastIndex = match.end() + begin - 1
|
| 63 |
+
if "post" in rule:
|
| 64 |
+
if not (
|
| 65 |
+
rule["post"](string, lastIndex) # valid post-condition
|
| 66 |
+
# remove evil blockquote bug (https:#github.com/goessner/mdmath/issues/50)
|
| 67 |
+
and (not inBlockquote or "\n" not in match.group(1))
|
| 68 |
+
):
|
| 69 |
+
return False
|
| 70 |
+
return match
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def make_inline_func(rule):
|
| 74 |
+
def _func(state, silent):
|
| 75 |
+
res = applyRule(rule, state.src, state.pos, False)
|
| 76 |
+
if res:
|
| 77 |
+
if not silent:
|
| 78 |
+
token = state.push(rule["name"], "math", 0)
|
| 79 |
+
token.content = res[1] # group 1 from regex ..
|
| 80 |
+
token.markup = rule["tag"]
|
| 81 |
+
|
| 82 |
+
state.pos += res.end()
|
| 83 |
+
|
| 84 |
+
return bool(res)
|
| 85 |
+
|
| 86 |
+
return _func
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
def make_block_func(rule):
|
| 90 |
+
def _func(state, begLine, endLine, silent):
|
| 91 |
+
begin = state.bMarks[begLine] + state.tShift[begLine]
|
| 92 |
+
res = applyRule(rule, state.src, begin, state.parentType == "blockquote")
|
| 93 |
+
if res:
|
| 94 |
+
if not silent:
|
| 95 |
+
token = state.push(rule["name"], "math", 0)
|
| 96 |
+
token.block = True
|
| 97 |
+
token.content = res[1]
|
| 98 |
+
token.info = res[len(res.groups())]
|
| 99 |
+
token.markup = rule["tag"]
|
| 100 |
+
|
| 101 |
+
line = begLine
|
| 102 |
+
endpos = begin + res.end() - 1
|
| 103 |
+
|
| 104 |
+
while line < endLine:
|
| 105 |
+
if endpos >= state.bMarks[line] and endpos <= state.eMarks[line]:
|
| 106 |
+
# line for end of block math found ...
|
| 107 |
+
state.line = line + 1
|
| 108 |
+
break
|
| 109 |
+
line += 1
|
| 110 |
+
|
| 111 |
+
state.pos = begin + res.end()
|
| 112 |
+
|
| 113 |
+
return bool(res)
|
| 114 |
+
|
| 115 |
+
return _func
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
def dollar_pre(str, beg):
|
| 119 |
+
prv = charCodeAt(str[beg - 1], 0) if beg > 0 else False
|
| 120 |
+
return (
|
| 121 |
+
(not prv) or prv != 0x5C and (prv < 0x30 or prv > 0x39) # no backslash,
|
| 122 |
+
) # no decimal digit .. before opening '$'
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
def dollar_post(string, end):
|
| 126 |
+
try:
|
| 127 |
+
nxt = string[end + 1] and charCodeAt(string[end + 1], 0)
|
| 128 |
+
except IndexError:
|
| 129 |
+
return True
|
| 130 |
+
return (
|
| 131 |
+
(not nxt) or (nxt < 0x30) or (nxt > 0x39)
|
| 132 |
+
) # no decimal digit .. after closing '$'
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def render(tex, displayMode, macros):
|
| 136 |
+
return tex
|
| 137 |
+
# TODO better HTML renderer port for math
|
| 138 |
+
# try:
|
| 139 |
+
# res = katex.renderToString(tex,{throwOnError:False,displayMode,macros})
|
| 140 |
+
# except:
|
| 141 |
+
# res = tex+": "+err.message.replace("<","<")
|
| 142 |
+
# return res
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
# def use(katex): # math renderer used ...
|
| 146 |
+
# texmath.katex = katex; # ... katex solely at current ...
|
| 147 |
+
# return texmath;
|
| 148 |
+
# }
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
# All regexes areg global (g) and sticky (y), see:
|
| 152 |
+
# https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/sticky
|
| 153 |
+
|
| 154 |
+
rules: dict = {
|
| 155 |
+
"brackets": {
|
| 156 |
+
"inline": [
|
| 157 |
+
{
|
| 158 |
+
"name": "math_inline",
|
| 159 |
+
"rex": re.compile(r"^\\\((.+?)\\\)", re.DOTALL),
|
| 160 |
+
"tmpl": "<eq>{0}</eq>",
|
| 161 |
+
"tag": "\\(",
|
| 162 |
+
}
|
| 163 |
+
],
|
| 164 |
+
"block": [
|
| 165 |
+
{
|
| 166 |
+
"name": "math_block_eqno",
|
| 167 |
+
"rex": re.compile(
|
| 168 |
+
r"^\\\[(((?!\\\]|\\\[)[\s\S])+?)\\\]\s*?\(([^)$\r\n]+?)\)", re.M
|
| 169 |
+
),
|
| 170 |
+
"tmpl": '<section class="eqno"><eqn>{0}</eqn><span>({1})</span></section>',
|
| 171 |
+
"tag": "\\[",
|
| 172 |
+
},
|
| 173 |
+
{
|
| 174 |
+
"name": "math_block",
|
| 175 |
+
"rex": re.compile(r"^\\\[([\s\S]+?)\\\]", re.M),
|
| 176 |
+
"tmpl": "<section>\n<eqn>{0}</eqn>\n</section>\n",
|
| 177 |
+
"tag": "\\[",
|
| 178 |
+
},
|
| 179 |
+
],
|
| 180 |
+
},
|
| 181 |
+
"gitlab": {
|
| 182 |
+
"inline": [
|
| 183 |
+
{
|
| 184 |
+
"name": "math_inline",
|
| 185 |
+
"rex": re.compile(r"^\$`(.+?)`\$"),
|
| 186 |
+
"tmpl": "<eq>{0}</eq>",
|
| 187 |
+
"tag": "$`",
|
| 188 |
+
}
|
| 189 |
+
],
|
| 190 |
+
"block": [
|
| 191 |
+
{
|
| 192 |
+
"name": "math_block_eqno",
|
| 193 |
+
"rex": re.compile(
|
| 194 |
+
r"^`{3}math\s+?([^`]+?)\s+?`{3}\s*?\(([^)$\r\n]+?)\)", re.M
|
| 195 |
+
),
|
| 196 |
+
"tmpl": '<section class="eqno">\n<eqn>{0}</eqn><span>({1})</span>\n</section>\n', # noqa: E501
|
| 197 |
+
"tag": "```math",
|
| 198 |
+
},
|
| 199 |
+
{
|
| 200 |
+
"name": "math_block",
|
| 201 |
+
"rex": re.compile(r"^`{3}math\s+?([^`]+?)\s+?`{3}", re.M),
|
| 202 |
+
"tmpl": "<section>\n<eqn>{0}</eqn>\n</section>\n",
|
| 203 |
+
"tag": "```math",
|
| 204 |
+
},
|
| 205 |
+
],
|
| 206 |
+
},
|
| 207 |
+
"julia": {
|
| 208 |
+
"inline": [
|
| 209 |
+
{
|
| 210 |
+
"name": "math_inline",
|
| 211 |
+
"rex": re.compile(r"^`{2}([^`]+?)`{2}"),
|
| 212 |
+
"tmpl": "<eq>{0}</eq>",
|
| 213 |
+
"tag": "``",
|
| 214 |
+
},
|
| 215 |
+
{
|
| 216 |
+
"name": "math_inline",
|
| 217 |
+
"rex": re.compile(r"^\$(\S[^$\r\n]*?[^\s\\]{1}?)\$"),
|
| 218 |
+
"tmpl": "<eq>{0}</eq>",
|
| 219 |
+
"tag": "$",
|
| 220 |
+
"pre": dollar_pre,
|
| 221 |
+
"post": dollar_post,
|
| 222 |
+
},
|
| 223 |
+
{
|
| 224 |
+
"name": "math_single",
|
| 225 |
+
"rex": re.compile(r"^\$([^$\s\\]{1}?)\$"),
|
| 226 |
+
"tmpl": "<eq>{0}</eq>",
|
| 227 |
+
"tag": "$",
|
| 228 |
+
"pre": dollar_pre,
|
| 229 |
+
"post": dollar_post,
|
| 230 |
+
},
|
| 231 |
+
],
|
| 232 |
+
"block": [
|
| 233 |
+
{
|
| 234 |
+
"name": "math_block_eqno",
|
| 235 |
+
"rex": re.compile(
|
| 236 |
+
r"^`{3}math\s+?([^`]+?)\s+?`{3}\s*?\(([^)$\r\n]+?)\)", re.M
|
| 237 |
+
),
|
| 238 |
+
"tmpl": '<section class="eqno"><eqn>{0}</eqn><span>({1})</span></section>',
|
| 239 |
+
"tag": "```math",
|
| 240 |
+
},
|
| 241 |
+
{
|
| 242 |
+
"name": "math_block",
|
| 243 |
+
"rex": re.compile(r"^`{3}math\s+?([^`]+?)\s+?`{3}", re.M),
|
| 244 |
+
"tmpl": "<section><eqn>{0}</eqn></section>",
|
| 245 |
+
"tag": "```math",
|
| 246 |
+
},
|
| 247 |
+
],
|
| 248 |
+
},
|
| 249 |
+
"kramdown": {
|
| 250 |
+
"inline": [
|
| 251 |
+
{
|
| 252 |
+
"name": "math_inline",
|
| 253 |
+
"rex": re.compile(r"^\${2}([^$\r\n]*?)\${2}"),
|
| 254 |
+
"tmpl": "<eq>{0}</eq>",
|
| 255 |
+
"tag": "$$",
|
| 256 |
+
}
|
| 257 |
+
],
|
| 258 |
+
"block": [
|
| 259 |
+
{
|
| 260 |
+
"name": "math_block_eqno",
|
| 261 |
+
"rex": re.compile(r"^\${2}([^$]*?)\${2}\s*?\(([^)$\r\n]+?)\)", re.M),
|
| 262 |
+
"tmpl": '<section class="eqno"><eqn>{0}</eqn><span>({1})</span></section>',
|
| 263 |
+
"tag": "$$",
|
| 264 |
+
},
|
| 265 |
+
{
|
| 266 |
+
"name": "math_block",
|
| 267 |
+
"rex": re.compile(r"^\${2}([^$]*?)\${2}", re.M),
|
| 268 |
+
"tmpl": "<section><eqn>{0}</eqn></section>",
|
| 269 |
+
"tag": "$$",
|
| 270 |
+
},
|
| 271 |
+
],
|
| 272 |
+
},
|
| 273 |
+
"dollars": {
|
| 274 |
+
"inline": [
|
| 275 |
+
{
|
| 276 |
+
"name": "math_inline",
|
| 277 |
+
"rex": re.compile(r"^\$(\S[^$]*?[^\s\\]{1}?)\$"),
|
| 278 |
+
"tmpl": "<eq>{0}</eq>",
|
| 279 |
+
"tag": "$",
|
| 280 |
+
"pre": dollar_pre,
|
| 281 |
+
"post": dollar_post,
|
| 282 |
+
},
|
| 283 |
+
{
|
| 284 |
+
"name": "math_single",
|
| 285 |
+
"rex": re.compile(r"^\$([^$\s\\]{1}?)\$"),
|
| 286 |
+
"tmpl": "<eq>{0}</eq>",
|
| 287 |
+
"tag": "$",
|
| 288 |
+
"pre": dollar_pre,
|
| 289 |
+
"post": dollar_post,
|
| 290 |
+
},
|
| 291 |
+
],
|
| 292 |
+
"block": [
|
| 293 |
+
{
|
| 294 |
+
"name": "math_block_eqno",
|
| 295 |
+
"rex": re.compile(r"^\${2}([^$]*?)\${2}\s*?\(([^)$\r\n]+?)\)", re.M),
|
| 296 |
+
"tmpl": '<section class="eqno">\n<eqn>{0}</eqn><span>({1})</span>\n</section>\n', # noqa: E501
|
| 297 |
+
"tag": "$$",
|
| 298 |
+
},
|
| 299 |
+
{
|
| 300 |
+
"name": "math_block",
|
| 301 |
+
"rex": re.compile(r"^\${2}([^$]*?)\${2}", re.M),
|
| 302 |
+
"tmpl": "<section>\n<eqn>{0}</eqn>\n</section>\n",
|
| 303 |
+
"tag": "$$",
|
| 304 |
+
},
|
| 305 |
+
],
|
| 306 |
+
},
|
| 307 |
+
}
|