Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- evalkit_tf446/lib/python3.10/site-packages/imageio-2.36.0.dist-info/INSTALLER +1 -0
- evalkit_tf446/lib/python3.10/site-packages/imageio-2.36.0.dist-info/LICENSE +24 -0
- evalkit_tf446/lib/python3.10/site-packages/imageio-2.36.0.dist-info/METADATA +142 -0
- evalkit_tf446/lib/python3.10/site-packages/imageio/core/__pycache__/fetching.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/imageio/core/__pycache__/findlib.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/imageio/core/__pycache__/imopen.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/imageio/core/__pycache__/legacy_plugin_wrapper.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/imageio/core/__pycache__/request.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/imageio/core/__pycache__/v3_plugin_api.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/imageio/core/findlib.py +161 -0
- evalkit_tf446/lib/python3.10/site-packages/imageio/core/legacy_plugin_wrapper.py +363 -0
- evalkit_tf446/lib/python3.10/site-packages/imageio/core/request.pyi +90 -0
- evalkit_tf446/lib/python3.10/site-packages/imageio/core/util.py +561 -0
- evalkit_tf446/lib/python3.10/site-packages/markdown_it/__pycache__/__init__.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/markdown_it/__pycache__/_compat.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/markdown_it/__pycache__/_punycode.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/markdown_it/__pycache__/main.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/markdown_it/__pycache__/parser_block.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/markdown_it/__pycache__/parser_core.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/markdown_it/__pycache__/parser_inline.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/markdown_it/__pycache__/renderer.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/markdown_it/__pycache__/ruler.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/markdown_it/__pycache__/token.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/markdown_it/__pycache__/tree.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/markdown_it/__pycache__/utils.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/markdown_it/common/__init__.py +0 -0
- evalkit_tf446/lib/python3.10/site-packages/markdown_it/common/__pycache__/__init__.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/markdown_it/common/__pycache__/entities.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/markdown_it/common/__pycache__/html_blocks.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/markdown_it/common/__pycache__/html_re.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/markdown_it/common/__pycache__/normalize_url.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/markdown_it/common/__pycache__/utils.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/markdown_it/common/entities.py +4 -0
- evalkit_tf446/lib/python3.10/site-packages/markdown_it/common/html_blocks.py +68 -0
- evalkit_tf446/lib/python3.10/site-packages/markdown_it/common/html_re.py +40 -0
- evalkit_tf446/lib/python3.10/site-packages/markdown_it/common/normalize_url.py +81 -0
- evalkit_tf446/lib/python3.10/site-packages/markdown_it/common/utils.py +318 -0
- evalkit_tf446/lib/python3.10/site-packages/markdown_it/helpers/__init__.py +6 -0
- evalkit_tf446/lib/python3.10/site-packages/markdown_it/helpers/__pycache__/__init__.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/markdown_it/helpers/__pycache__/parse_link_destination.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/markdown_it/helpers/__pycache__/parse_link_label.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/markdown_it/helpers/__pycache__/parse_link_title.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/markdown_it/helpers/parse_link_destination.py +86 -0
- evalkit_tf446/lib/python3.10/site-packages/markdown_it/helpers/parse_link_label.py +43 -0
- evalkit_tf446/lib/python3.10/site-packages/markdown_it/helpers/parse_link_title.py +60 -0
- evalkit_tf446/lib/python3.10/site-packages/markdown_it/presets/__pycache__/__init__.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/markdown_it/presets/__pycache__/default.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/markdown_it/presets/__pycache__/zero.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/markdown_it/presets/default.py +35 -0
- evalkit_tf446/lib/python3.10/site-packages/markdown_it/rules_block/__pycache__/__init__.cpython-310.pyc +0 -0
evalkit_tf446/lib/python3.10/site-packages/imageio-2.36.0.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pip
|
evalkit_tf446/lib/python3.10/site-packages/imageio-2.36.0.dist-info/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright (c) 2014-2022, imageio developers
|
| 2 |
+
All rights reserved.
|
| 3 |
+
|
| 4 |
+
Redistribution and use in source and binary forms, with or without
|
| 5 |
+
modification, are permitted provided that the following conditions are met:
|
| 6 |
+
|
| 7 |
+
* Redistributions of source code must retain the above copyright notice, this
|
| 8 |
+
list of conditions and the following disclaimer.
|
| 9 |
+
|
| 10 |
+
* Redistributions in binary form must reproduce the above copyright notice,
|
| 11 |
+
this list of conditions and the following disclaimer in the documentation
|
| 12 |
+
and/or other materials provided with the distribution.
|
| 13 |
+
|
| 14 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 15 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 16 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 17 |
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
| 18 |
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 19 |
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
| 20 |
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
| 21 |
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
| 22 |
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 23 |
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 24 |
+
|
evalkit_tf446/lib/python3.10/site-packages/imageio-2.36.0.dist-info/METADATA
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.1
|
| 2 |
+
Name: imageio
|
| 3 |
+
Version: 2.36.0
|
| 4 |
+
Summary: Library for reading and writing a wide range of image, video, scientific, and volumetric data formats.
|
| 5 |
+
Home-page: https://github.com/imageio/imageio
|
| 6 |
+
Download-URL: http://pypi.python.org/pypi/imageio
|
| 7 |
+
Author: imageio contributors
|
| 8 |
+
Author-email: almar.klein@gmail.com
|
| 9 |
+
License: BSD-2-Clause
|
| 10 |
+
Keywords: image video volume imread imwrite io animation ffmpeg
|
| 11 |
+
Platform: any
|
| 12 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 13 |
+
Classifier: Intended Audience :: Science/Research
|
| 14 |
+
Classifier: Intended Audience :: Education
|
| 15 |
+
Classifier: Intended Audience :: Developers
|
| 16 |
+
Classifier: License :: OSI Approved :: BSD License
|
| 17 |
+
Classifier: Operating System :: MacOS :: MacOS X
|
| 18 |
+
Classifier: Operating System :: Microsoft :: Windows
|
| 19 |
+
Classifier: Operating System :: POSIX
|
| 20 |
+
Classifier: Programming Language :: Python :: 3
|
| 21 |
+
Classifier: Programming Language :: Python :: 3.9
|
| 22 |
+
Classifier: Programming Language :: Python :: 3.10
|
| 23 |
+
Classifier: Programming Language :: Python :: 3.11
|
| 24 |
+
Classifier: Programming Language :: Python :: 3.12
|
| 25 |
+
Classifier: Programming Language :: Python :: 3.13
|
| 26 |
+
Classifier: Programming Language :: Python :: 3.14
|
| 27 |
+
Provides: imageio
|
| 28 |
+
Requires-Python: >=3.9
|
| 29 |
+
License-File: LICENSE
|
| 30 |
+
Requires-Dist: numpy
|
| 31 |
+
Requires-Dist: pillow>=8.3.2
|
| 32 |
+
Provides-Extra: all-plugins
|
| 33 |
+
Requires-Dist: astropy; extra == "all-plugins"
|
| 34 |
+
Requires-Dist: av; extra == "all-plugins"
|
| 35 |
+
Requires-Dist: imageio-ffmpeg; extra == "all-plugins"
|
| 36 |
+
Requires-Dist: numpy>2; extra == "all-plugins"
|
| 37 |
+
Requires-Dist: pillow-heif; extra == "all-plugins"
|
| 38 |
+
Requires-Dist: psutil; extra == "all-plugins"
|
| 39 |
+
Requires-Dist: rawpy; extra == "all-plugins"
|
| 40 |
+
Requires-Dist: tifffile; extra == "all-plugins"
|
| 41 |
+
Provides-Extra: all-plugins-pypy
|
| 42 |
+
Requires-Dist: av; extra == "all-plugins-pypy"
|
| 43 |
+
Requires-Dist: imageio-ffmpeg; extra == "all-plugins-pypy"
|
| 44 |
+
Requires-Dist: pillow-heif; extra == "all-plugins-pypy"
|
| 45 |
+
Requires-Dist: psutil; extra == "all-plugins-pypy"
|
| 46 |
+
Requires-Dist: tifffile; extra == "all-plugins-pypy"
|
| 47 |
+
Provides-Extra: bsdf
|
| 48 |
+
Provides-Extra: build
|
| 49 |
+
Requires-Dist: wheel; extra == "build"
|
| 50 |
+
Provides-Extra: dev
|
| 51 |
+
Requires-Dist: pytest; extra == "dev"
|
| 52 |
+
Requires-Dist: pytest-cov; extra == "dev"
|
| 53 |
+
Requires-Dist: fsspec[github]; extra == "dev"
|
| 54 |
+
Requires-Dist: black; extra == "dev"
|
| 55 |
+
Requires-Dist: flake8; extra == "dev"
|
| 56 |
+
Provides-Extra: dicom
|
| 57 |
+
Provides-Extra: docs
|
| 58 |
+
Requires-Dist: sphinx<6; extra == "docs"
|
| 59 |
+
Requires-Dist: numpydoc; extra == "docs"
|
| 60 |
+
Requires-Dist: pydata-sphinx-theme; extra == "docs"
|
| 61 |
+
Provides-Extra: feisem
|
| 62 |
+
Provides-Extra: ffmpeg
|
| 63 |
+
Requires-Dist: imageio-ffmpeg; extra == "ffmpeg"
|
| 64 |
+
Requires-Dist: psutil; extra == "ffmpeg"
|
| 65 |
+
Provides-Extra: fits
|
| 66 |
+
Requires-Dist: astropy; extra == "fits"
|
| 67 |
+
Provides-Extra: freeimage
|
| 68 |
+
Provides-Extra: full
|
| 69 |
+
Requires-Dist: astropy; extra == "full"
|
| 70 |
+
Requires-Dist: av; extra == "full"
|
| 71 |
+
Requires-Dist: black; extra == "full"
|
| 72 |
+
Requires-Dist: flake8; extra == "full"
|
| 73 |
+
Requires-Dist: fsspec[github]; extra == "full"
|
| 74 |
+
Requires-Dist: gdal; extra == "full"
|
| 75 |
+
Requires-Dist: imageio-ffmpeg; extra == "full"
|
| 76 |
+
Requires-Dist: itk; extra == "full"
|
| 77 |
+
Requires-Dist: numpy>2; extra == "full"
|
| 78 |
+
Requires-Dist: numpydoc; extra == "full"
|
| 79 |
+
Requires-Dist: pillow-heif; extra == "full"
|
| 80 |
+
Requires-Dist: psutil; extra == "full"
|
| 81 |
+
Requires-Dist: pydata-sphinx-theme; extra == "full"
|
| 82 |
+
Requires-Dist: pytest; extra == "full"
|
| 83 |
+
Requires-Dist: pytest-cov; extra == "full"
|
| 84 |
+
Requires-Dist: rawpy; extra == "full"
|
| 85 |
+
Requires-Dist: sphinx<6; extra == "full"
|
| 86 |
+
Requires-Dist: tifffile; extra == "full"
|
| 87 |
+
Requires-Dist: wheel; extra == "full"
|
| 88 |
+
Provides-Extra: gdal
|
| 89 |
+
Requires-Dist: gdal; extra == "gdal"
|
| 90 |
+
Provides-Extra: itk
|
| 91 |
+
Requires-Dist: itk; extra == "itk"
|
| 92 |
+
Provides-Extra: linting
|
| 93 |
+
Requires-Dist: black; extra == "linting"
|
| 94 |
+
Requires-Dist: flake8; extra == "linting"
|
| 95 |
+
Provides-Extra: lytro
|
| 96 |
+
Provides-Extra: numpy
|
| 97 |
+
Provides-Extra: pillow
|
| 98 |
+
Provides-Extra: pillow-heif
|
| 99 |
+
Requires-Dist: pillow-heif; extra == "pillow-heif"
|
| 100 |
+
Provides-Extra: pyav
|
| 101 |
+
Requires-Dist: av; extra == "pyav"
|
| 102 |
+
Provides-Extra: rawpy
|
| 103 |
+
Requires-Dist: rawpy; extra == "rawpy"
|
| 104 |
+
Requires-Dist: numpy>2; extra == "rawpy"
|
| 105 |
+
Provides-Extra: simpleitk
|
| 106 |
+
Provides-Extra: spe
|
| 107 |
+
Provides-Extra: swf
|
| 108 |
+
Provides-Extra: test
|
| 109 |
+
Requires-Dist: pytest; extra == "test"
|
| 110 |
+
Requires-Dist: pytest-cov; extra == "test"
|
| 111 |
+
Requires-Dist: fsspec[github]; extra == "test"
|
| 112 |
+
Provides-Extra: tifffile
|
| 113 |
+
Requires-Dist: tifffile; extra == "tifffile"
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
.. image:: https://github.com/imageio/imageio/workflows/CI/badge.svg
|
| 117 |
+
:target: https://github.com/imageio/imageio/actions
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
Imageio is a Python library that provides an easy interface to read and
|
| 121 |
+
write a wide range of image data, including animated images, volumetric
|
| 122 |
+
data, and scientific formats. It is cross-platform, runs on Python 3.5+,
|
| 123 |
+
and is easy to install.
|
| 124 |
+
|
| 125 |
+
Main website: https://imageio.readthedocs.io/
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
Release notes: https://github.com/imageio/imageio/blob/master/CHANGELOG.md
|
| 129 |
+
|
| 130 |
+
Example:
|
| 131 |
+
|
| 132 |
+
.. code-block:: python
|
| 133 |
+
|
| 134 |
+
>>> import imageio
|
| 135 |
+
>>> im = imageio.imread('imageio:astronaut.png')
|
| 136 |
+
>>> im.shape # im is a numpy array
|
| 137 |
+
(512, 512, 3)
|
| 138 |
+
>>> imageio.imwrite('astronaut-gray.jpg', im[:, :, 0])
|
| 139 |
+
|
| 140 |
+
See the `API Reference <https://imageio.readthedocs.io/en/stable/reference/index.html>`_
|
| 141 |
+
or `examples <https://imageio.readthedocs.io/en/stable/examples.html>`_
|
| 142 |
+
for more information.
|
evalkit_tf446/lib/python3.10/site-packages/imageio/core/__pycache__/fetching.cpython-310.pyc
ADDED
|
Binary file (6.92 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/imageio/core/__pycache__/findlib.cpython-310.pyc
ADDED
|
Binary file (4.07 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/imageio/core/__pycache__/imopen.cpython-310.pyc
ADDED
|
Binary file (6.72 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/imageio/core/__pycache__/legacy_plugin_wrapper.cpython-310.pyc
ADDED
|
Binary file (10.9 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/imageio/core/__pycache__/request.cpython-310.pyc
ADDED
|
Binary file (20.1 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/imageio/core/__pycache__/v3_plugin_api.cpython-310.pyc
ADDED
|
Binary file (16.8 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/imageio/core/findlib.py
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
# Copyright (c) 2015-1018, imageio contributors
|
| 3 |
+
# Copyright (C) 2013, Zach Pincus, Almar Klein and others
|
| 4 |
+
|
| 5 |
+
""" This module contains generic code to find and load a dynamic library.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
import os
|
| 9 |
+
import sys
|
| 10 |
+
import ctypes
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
LOCALDIR = os.path.abspath(os.path.dirname(__file__))
|
| 14 |
+
|
| 15 |
+
# Flag that can be patched / set to True to disable loading non-system libs
|
| 16 |
+
SYSTEM_LIBS_ONLY = False
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def looks_lib(fname):
|
| 20 |
+
"""Returns True if the given filename looks like a dynamic library.
|
| 21 |
+
Based on extension, but cross-platform and more flexible.
|
| 22 |
+
"""
|
| 23 |
+
fname = fname.lower()
|
| 24 |
+
if sys.platform.startswith("win"):
|
| 25 |
+
return fname.endswith(".dll")
|
| 26 |
+
elif sys.platform.startswith("darwin"):
|
| 27 |
+
return fname.endswith(".dylib")
|
| 28 |
+
else:
|
| 29 |
+
return fname.endswith(".so") or ".so." in fname
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def generate_candidate_libs(lib_names, lib_dirs=None):
|
| 33 |
+
"""Generate a list of candidate filenames of what might be the dynamic
|
| 34 |
+
library corresponding with the given list of names.
|
| 35 |
+
Returns (lib_dirs, lib_paths)
|
| 36 |
+
"""
|
| 37 |
+
lib_dirs = lib_dirs or []
|
| 38 |
+
|
| 39 |
+
# Get system dirs to search
|
| 40 |
+
sys_lib_dirs = [
|
| 41 |
+
"/lib",
|
| 42 |
+
"/usr/lib",
|
| 43 |
+
"/usr/lib/x86_64-linux-gnu",
|
| 44 |
+
"/usr/lib/aarch64-linux-gnu",
|
| 45 |
+
"/usr/local/lib",
|
| 46 |
+
"/opt/local/lib",
|
| 47 |
+
]
|
| 48 |
+
|
| 49 |
+
# Get Python dirs to search (shared if for Pyzo)
|
| 50 |
+
py_sub_dirs = ["bin", "lib", "DLLs", "Library/bin", "shared"]
|
| 51 |
+
py_lib_dirs = [os.path.join(sys.prefix, d) for d in py_sub_dirs]
|
| 52 |
+
if hasattr(sys, "base_prefix"):
|
| 53 |
+
py_lib_dirs += [os.path.join(sys.base_prefix, d) for d in py_sub_dirs]
|
| 54 |
+
|
| 55 |
+
# Get user dirs to search (i.e. HOME)
|
| 56 |
+
home_dir = os.path.expanduser("~")
|
| 57 |
+
user_lib_dirs = [os.path.join(home_dir, d) for d in ["lib"]]
|
| 58 |
+
|
| 59 |
+
# Select only the dirs for which a directory exists, and remove duplicates
|
| 60 |
+
potential_lib_dirs = lib_dirs + sys_lib_dirs + py_lib_dirs + user_lib_dirs
|
| 61 |
+
lib_dirs = []
|
| 62 |
+
for ld in potential_lib_dirs:
|
| 63 |
+
if os.path.isdir(ld) and ld not in lib_dirs:
|
| 64 |
+
lib_dirs.append(ld)
|
| 65 |
+
|
| 66 |
+
# Now attempt to find libraries of that name in the given directory
|
| 67 |
+
# (case-insensitive)
|
| 68 |
+
lib_paths = []
|
| 69 |
+
for lib_dir in lib_dirs:
|
| 70 |
+
# Get files, prefer short names, last version
|
| 71 |
+
files = os.listdir(lib_dir)
|
| 72 |
+
files = reversed(sorted(files))
|
| 73 |
+
files = sorted(files, key=len)
|
| 74 |
+
for lib_name in lib_names:
|
| 75 |
+
# Test all filenames for name and ext
|
| 76 |
+
for fname in files:
|
| 77 |
+
if fname.lower().startswith(lib_name) and looks_lib(fname):
|
| 78 |
+
lib_paths.append(os.path.join(lib_dir, fname))
|
| 79 |
+
|
| 80 |
+
# Return (only the items which are files)
|
| 81 |
+
lib_paths = [lp for lp in lib_paths if os.path.isfile(lp)]
|
| 82 |
+
return lib_dirs, lib_paths
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def load_lib(exact_lib_names, lib_names, lib_dirs=None):
|
| 86 |
+
"""load_lib(exact_lib_names, lib_names, lib_dirs=None)
|
| 87 |
+
|
| 88 |
+
Load a dynamic library.
|
| 89 |
+
|
| 90 |
+
This function first tries to load the library from the given exact
|
| 91 |
+
names. When that fails, it tries to find the library in common
|
| 92 |
+
locations. It searches for files that start with one of the names
|
| 93 |
+
given in lib_names (case insensitive). The search is performed in
|
| 94 |
+
the given lib_dirs and a set of common library dirs.
|
| 95 |
+
|
| 96 |
+
Returns ``(ctypes_library, library_path)``
|
| 97 |
+
"""
|
| 98 |
+
|
| 99 |
+
# Checks
|
| 100 |
+
assert isinstance(exact_lib_names, list)
|
| 101 |
+
assert isinstance(lib_names, list)
|
| 102 |
+
if lib_dirs is not None:
|
| 103 |
+
assert isinstance(lib_dirs, list)
|
| 104 |
+
exact_lib_names = [n for n in exact_lib_names if n]
|
| 105 |
+
lib_names = [n for n in lib_names if n]
|
| 106 |
+
|
| 107 |
+
# Get reference name (for better messages)
|
| 108 |
+
if lib_names:
|
| 109 |
+
the_lib_name = lib_names[0]
|
| 110 |
+
elif exact_lib_names:
|
| 111 |
+
the_lib_name = exact_lib_names[0]
|
| 112 |
+
else:
|
| 113 |
+
raise ValueError("No library name given.")
|
| 114 |
+
|
| 115 |
+
# Collect filenames of potential libraries
|
| 116 |
+
# First try a few bare library names that ctypes might be able to find
|
| 117 |
+
# in the default locations for each platform.
|
| 118 |
+
if SYSTEM_LIBS_ONLY:
|
| 119 |
+
lib_dirs, lib_paths = [], []
|
| 120 |
+
else:
|
| 121 |
+
lib_dirs, lib_paths = generate_candidate_libs(lib_names, lib_dirs)
|
| 122 |
+
lib_paths = exact_lib_names + lib_paths
|
| 123 |
+
|
| 124 |
+
# Select loader
|
| 125 |
+
if sys.platform.startswith("win"):
|
| 126 |
+
loader = ctypes.windll
|
| 127 |
+
else:
|
| 128 |
+
loader = ctypes.cdll
|
| 129 |
+
|
| 130 |
+
# Try to load until success
|
| 131 |
+
the_lib = None
|
| 132 |
+
errors = []
|
| 133 |
+
for fname in lib_paths:
|
| 134 |
+
try:
|
| 135 |
+
the_lib = loader.LoadLibrary(fname)
|
| 136 |
+
break
|
| 137 |
+
except Exception as err:
|
| 138 |
+
# Don't record errors when it couldn't load the library from an
|
| 139 |
+
# exact name -- this fails often, and doesn't provide any useful
|
| 140 |
+
# debugging information anyway, beyond "couldn't find library..."
|
| 141 |
+
if fname not in exact_lib_names:
|
| 142 |
+
errors.append((fname, err))
|
| 143 |
+
|
| 144 |
+
# No success ...
|
| 145 |
+
if the_lib is None:
|
| 146 |
+
if errors:
|
| 147 |
+
# No library loaded, and load-errors reported for some
|
| 148 |
+
# candidate libs
|
| 149 |
+
err_txt = ["%s:\n%s" % (lib, str(e)) for lib, e in errors]
|
| 150 |
+
msg = (
|
| 151 |
+
"One or more %s libraries were found, but "
|
| 152 |
+
+ "could not be loaded due to the following errors:\n%s"
|
| 153 |
+
)
|
| 154 |
+
raise OSError(msg % (the_lib_name, "\n\n".join(err_txt)))
|
| 155 |
+
else:
|
| 156 |
+
# No errors, because no potential libraries found at all!
|
| 157 |
+
msg = "Could not find a %s library in any of:\n%s"
|
| 158 |
+
raise OSError(msg % (the_lib_name, "\n".join(lib_dirs)))
|
| 159 |
+
|
| 160 |
+
# Done
|
| 161 |
+
return the_lib, fname
|
evalkit_tf446/lib/python3.10/site-packages/imageio/core/legacy_plugin_wrapper.py
ADDED
|
@@ -0,0 +1,363 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pathlib import Path
|
| 2 |
+
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
from ..config import known_extensions
|
| 6 |
+
from .request import InitializationError, IOMode
|
| 7 |
+
from .v3_plugin_api import ImageProperties, PluginV3
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def _legacy_default_index(format):
|
| 11 |
+
if format._name == "FFMPEG":
|
| 12 |
+
index = Ellipsis
|
| 13 |
+
elif format._name == "GIF-PIL":
|
| 14 |
+
index = Ellipsis
|
| 15 |
+
else:
|
| 16 |
+
index = 0
|
| 17 |
+
|
| 18 |
+
return index
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
class LegacyPlugin(PluginV3):
|
| 22 |
+
"""A plugin to make old (v2.9) plugins compatible with v3.0
|
| 23 |
+
|
| 24 |
+
.. depreciated:: 2.9
|
| 25 |
+
`legacy_get_reader` will be removed in a future version of imageio.
|
| 26 |
+
`legacy_get_writer` will be removed in a future version of imageio.
|
| 27 |
+
|
| 28 |
+
This plugin is a wrapper around the old FormatManager class and exposes
|
| 29 |
+
all the old plugins via the new API. On top of this it has
|
| 30 |
+
``legacy_get_reader`` and ``legacy_get_writer`` methods to allow using
|
| 31 |
+
it with the v2.9 API.
|
| 32 |
+
|
| 33 |
+
Methods
|
| 34 |
+
-------
|
| 35 |
+
read(index=None, **kwargs)
|
| 36 |
+
Read the image at position ``index``.
|
| 37 |
+
write(image, **kwargs)
|
| 38 |
+
Write image to the URI.
|
| 39 |
+
iter(**kwargs)
|
| 40 |
+
Iteratively yield images from the given URI.
|
| 41 |
+
get_meta(index=None)
|
| 42 |
+
Return the metadata for the image at position ``index``.
|
| 43 |
+
legacy_get_reader(**kwargs)
|
| 44 |
+
Returns the v2.9 image reader. (depreciated)
|
| 45 |
+
legacy_get_writer(**kwargs)
|
| 46 |
+
Returns the v2.9 image writer. (depreciated)
|
| 47 |
+
|
| 48 |
+
Examples
|
| 49 |
+
--------
|
| 50 |
+
|
| 51 |
+
>>> import imageio.v3 as iio
|
| 52 |
+
>>> with iio.imopen("/path/to/image.tiff", "r", legacy_mode=True) as file:
|
| 53 |
+
>>> reader = file.legacy_get_reader() # depreciated
|
| 54 |
+
>>> for im in file.iter():
|
| 55 |
+
>>> print(im.shape)
|
| 56 |
+
|
| 57 |
+
"""
|
| 58 |
+
|
| 59 |
+
def __init__(self, request, legacy_plugin):
|
| 60 |
+
"""Instantiate a new Legacy Plugin
|
| 61 |
+
|
| 62 |
+
Parameters
|
| 63 |
+
----------
|
| 64 |
+
uri : {str, pathlib.Path, bytes, file}
|
| 65 |
+
The resource to load the image from, e.g. a filename, pathlib.Path,
|
| 66 |
+
http address or file object, see the docs for more info.
|
| 67 |
+
legacy_plugin : Format
|
| 68 |
+
The (legacy) format to use to interface with the URI.
|
| 69 |
+
|
| 70 |
+
"""
|
| 71 |
+
self._request = request
|
| 72 |
+
self._format = legacy_plugin
|
| 73 |
+
|
| 74 |
+
source = (
|
| 75 |
+
"<bytes>"
|
| 76 |
+
if isinstance(self._request.raw_uri, bytes)
|
| 77 |
+
else self._request.raw_uri
|
| 78 |
+
)
|
| 79 |
+
if self._request.mode.io_mode == IOMode.read:
|
| 80 |
+
if not self._format.can_read(request):
|
| 81 |
+
raise InitializationError(
|
| 82 |
+
f"`{self._format.name}`" f" can not read `{source}`."
|
| 83 |
+
)
|
| 84 |
+
else:
|
| 85 |
+
if not self._format.can_write(request):
|
| 86 |
+
raise InitializationError(
|
| 87 |
+
f"`{self._format.name}`" f" can not write to `{source}`."
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
def legacy_get_reader(self, **kwargs):
|
| 91 |
+
"""legacy_get_reader(**kwargs)
|
| 92 |
+
|
| 93 |
+
a utility method to provide support vor the V2.9 API
|
| 94 |
+
|
| 95 |
+
Parameters
|
| 96 |
+
----------
|
| 97 |
+
kwargs : ...
|
| 98 |
+
Further keyword arguments are passed to the reader. See :func:`.help`
|
| 99 |
+
to see what arguments are available for a particular format.
|
| 100 |
+
"""
|
| 101 |
+
|
| 102 |
+
# Note: this will break thread-safety
|
| 103 |
+
self._request._kwargs = kwargs
|
| 104 |
+
|
| 105 |
+
# safeguard for DICOM plugin reading from folders
|
| 106 |
+
try:
|
| 107 |
+
assert Path(self._request.filename).is_dir()
|
| 108 |
+
except OSError:
|
| 109 |
+
pass # not a valid path on this OS
|
| 110 |
+
except AssertionError:
|
| 111 |
+
pass # not a folder
|
| 112 |
+
else:
|
| 113 |
+
return self._format.get_reader(self._request)
|
| 114 |
+
|
| 115 |
+
self._request.get_file().seek(0)
|
| 116 |
+
return self._format.get_reader(self._request)
|
| 117 |
+
|
| 118 |
+
def read(self, *, index=None, **kwargs):
|
| 119 |
+
"""
|
| 120 |
+
Parses the given URI and creates a ndarray from it.
|
| 121 |
+
|
| 122 |
+
Parameters
|
| 123 |
+
----------
|
| 124 |
+
index : {integer, None}
|
| 125 |
+
If the URI contains a list of ndimages return the index-th
|
| 126 |
+
image. If None, stack all images into an ndimage along the
|
| 127 |
+
0-th dimension (equivalent to np.stack(imgs, axis=0)).
|
| 128 |
+
kwargs : ...
|
| 129 |
+
Further keyword arguments are passed to the reader. See
|
| 130 |
+
:func:`.help` to see what arguments are available for a particular
|
| 131 |
+
format.
|
| 132 |
+
|
| 133 |
+
Returns
|
| 134 |
+
-------
|
| 135 |
+
ndimage : np.ndarray
|
| 136 |
+
A numpy array containing the decoded image data.
|
| 137 |
+
|
| 138 |
+
"""
|
| 139 |
+
|
| 140 |
+
if index is None:
|
| 141 |
+
index = _legacy_default_index(self._format)
|
| 142 |
+
|
| 143 |
+
if index is Ellipsis:
|
| 144 |
+
img = np.stack([im for im in self.iter(**kwargs)])
|
| 145 |
+
return img
|
| 146 |
+
|
| 147 |
+
reader = self.legacy_get_reader(**kwargs)
|
| 148 |
+
return reader.get_data(index)
|
| 149 |
+
|
| 150 |
+
def legacy_get_writer(self, **kwargs):
|
| 151 |
+
"""legacy_get_writer(**kwargs)
|
| 152 |
+
|
| 153 |
+
Returns a :class:`.Writer` object which can be used to write data
|
| 154 |
+
and meta data to the specified file.
|
| 155 |
+
|
| 156 |
+
Parameters
|
| 157 |
+
----------
|
| 158 |
+
kwargs : ...
|
| 159 |
+
Further keyword arguments are passed to the writer. See :func:`.help`
|
| 160 |
+
to see what arguments are available for a particular format.
|
| 161 |
+
"""
|
| 162 |
+
|
| 163 |
+
# Note: this will break thread-safety
|
| 164 |
+
self._request._kwargs = kwargs
|
| 165 |
+
return self._format.get_writer(self._request)
|
| 166 |
+
|
| 167 |
+
def write(self, ndimage, *, is_batch=None, metadata=None, **kwargs):
|
| 168 |
+
"""
|
| 169 |
+
Write an ndimage to the URI specified in path.
|
| 170 |
+
|
| 171 |
+
If the URI points to a file on the current host and the file does not
|
| 172 |
+
yet exist it will be created. If the file exists already, it will be
|
| 173 |
+
appended if possible; otherwise, it will be replaced.
|
| 174 |
+
|
| 175 |
+
Parameters
|
| 176 |
+
----------
|
| 177 |
+
ndimage : numpy.ndarray
|
| 178 |
+
The ndimage or list of ndimages to write.
|
| 179 |
+
is_batch : bool
|
| 180 |
+
If True, treat the supplied ndimage as a batch of images. If False,
|
| 181 |
+
treat the supplied ndimage as a single image. If None, try to
|
| 182 |
+
determine ``is_batch`` from the ndimage's shape and ndim.
|
| 183 |
+
metadata : dict
|
| 184 |
+
The metadata passed to write alongside the image.
|
| 185 |
+
kwargs : ...
|
| 186 |
+
Further keyword arguments are passed to the writer. See
|
| 187 |
+
:func:`.help` to see what arguments are available for a
|
| 188 |
+
particular format.
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
Returns
|
| 192 |
+
-------
|
| 193 |
+
buffer : bytes
|
| 194 |
+
When writing to the special target "<bytes>", this function will
|
| 195 |
+
return the encoded image data as a bytes string. Otherwise it
|
| 196 |
+
returns None.
|
| 197 |
+
|
| 198 |
+
Notes
|
| 199 |
+
-----
|
| 200 |
+
Automatically determining ``is_batch`` may fail for some images due to
|
| 201 |
+
shape aliasing. For example, it may classify a channel-first color image
|
| 202 |
+
as a batch of gray images. In most cases this automatic deduction works
|
| 203 |
+
fine (it has for almost a decade), but if you do have one of those edge
|
| 204 |
+
cases (or are worried that you might) consider explicitly setting
|
| 205 |
+
``is_batch``.
|
| 206 |
+
|
| 207 |
+
"""
|
| 208 |
+
|
| 209 |
+
if is_batch or isinstance(ndimage, (list, tuple)):
|
| 210 |
+
pass # ndimage is list of images
|
| 211 |
+
elif is_batch is False:
|
| 212 |
+
ndimage = [ndimage]
|
| 213 |
+
else:
|
| 214 |
+
# Write the largest possible block by guessing the meaning of each
|
| 215 |
+
# dimension from the shape/ndim and then checking if any batch
|
| 216 |
+
# dimensions are left.
|
| 217 |
+
ndimage = np.asanyarray(ndimage)
|
| 218 |
+
batch_dims = ndimage.ndim
|
| 219 |
+
|
| 220 |
+
# two spatial dimensions
|
| 221 |
+
batch_dims = max(batch_dims - 2, 0)
|
| 222 |
+
|
| 223 |
+
# packed (channel-last) image
|
| 224 |
+
if ndimage.ndim >= 3 and ndimage.shape[-1] < 5:
|
| 225 |
+
batch_dims = max(batch_dims - 1, 0)
|
| 226 |
+
|
| 227 |
+
# format supports volumetric images
|
| 228 |
+
ext_infos = known_extensions.get(self._request.extension, list())
|
| 229 |
+
for ext_info in ext_infos:
|
| 230 |
+
if self._format.name in ext_info.priority and ext_info.volume_support:
|
| 231 |
+
batch_dims = max(batch_dims - 1, 0)
|
| 232 |
+
break
|
| 233 |
+
|
| 234 |
+
if batch_dims == 0:
|
| 235 |
+
ndimage = [ndimage]
|
| 236 |
+
|
| 237 |
+
with self.legacy_get_writer(**kwargs) as writer:
|
| 238 |
+
for image in ndimage:
|
| 239 |
+
image = np.asanyarray(image)
|
| 240 |
+
|
| 241 |
+
if image.ndim < 2:
|
| 242 |
+
raise ValueError(
|
| 243 |
+
"The image must have at least two spatial dimensions."
|
| 244 |
+
)
|
| 245 |
+
|
| 246 |
+
if not np.issubdtype(image.dtype, np.number) and not np.issubdtype(
|
| 247 |
+
image.dtype, bool
|
| 248 |
+
):
|
| 249 |
+
raise ValueError(
|
| 250 |
+
f"All images have to be numeric, and not `{image.dtype}`."
|
| 251 |
+
)
|
| 252 |
+
|
| 253 |
+
writer.append_data(image, metadata)
|
| 254 |
+
|
| 255 |
+
return writer.request.get_result()
|
| 256 |
+
|
| 257 |
+
def iter(self, **kwargs):
|
| 258 |
+
"""Iterate over a list of ndimages given by the URI
|
| 259 |
+
|
| 260 |
+
Parameters
|
| 261 |
+
----------
|
| 262 |
+
kwargs : ...
|
| 263 |
+
Further keyword arguments are passed to the reader. See
|
| 264 |
+
:func:`.help` to see what arguments are available for a particular
|
| 265 |
+
format.
|
| 266 |
+
"""
|
| 267 |
+
|
| 268 |
+
reader = self.legacy_get_reader(**kwargs)
|
| 269 |
+
for image in reader:
|
| 270 |
+
yield image
|
| 271 |
+
|
| 272 |
+
def properties(self, index=None):
|
| 273 |
+
"""Standardized ndimage metadata.
|
| 274 |
+
|
| 275 |
+
Parameters
|
| 276 |
+
----------
|
| 277 |
+
index : int
|
| 278 |
+
The index of the ndimage for which to return properties. If the
|
| 279 |
+
index is out of bounds a ``ValueError`` is raised. If ``None``,
|
| 280 |
+
return the properties for the ndimage stack. If this is impossible,
|
| 281 |
+
e.g., due to shape mismatch, an exception will be raised.
|
| 282 |
+
|
| 283 |
+
Returns
|
| 284 |
+
-------
|
| 285 |
+
properties : ImageProperties
|
| 286 |
+
A dataclass filled with standardized image metadata.
|
| 287 |
+
|
| 288 |
+
"""
|
| 289 |
+
|
| 290 |
+
if index is None:
|
| 291 |
+
index = _legacy_default_index(self._format)
|
| 292 |
+
|
| 293 |
+
# for backwards compatibility ... actually reads pixel data :(
|
| 294 |
+
if index is Ellipsis:
|
| 295 |
+
image = self.read(index=0)
|
| 296 |
+
n_images = self.legacy_get_reader().get_length()
|
| 297 |
+
return ImageProperties(
|
| 298 |
+
shape=(n_images, *image.shape),
|
| 299 |
+
dtype=image.dtype,
|
| 300 |
+
n_images=n_images,
|
| 301 |
+
is_batch=True,
|
| 302 |
+
)
|
| 303 |
+
|
| 304 |
+
image = self.read(index=index)
|
| 305 |
+
return ImageProperties(
|
| 306 |
+
shape=image.shape,
|
| 307 |
+
dtype=image.dtype,
|
| 308 |
+
is_batch=False,
|
| 309 |
+
)
|
| 310 |
+
|
| 311 |
+
def get_meta(self, *, index=None):
|
| 312 |
+
"""Read ndimage metadata from the URI
|
| 313 |
+
|
| 314 |
+
Parameters
|
| 315 |
+
----------
|
| 316 |
+
index : {integer, None}
|
| 317 |
+
If the URI contains a list of ndimages return the metadata
|
| 318 |
+
corresponding to the index-th image. If None, behavior depends on
|
| 319 |
+
the used api
|
| 320 |
+
|
| 321 |
+
Legacy-style API: return metadata of the first element (index=0)
|
| 322 |
+
New-style API: Behavior depends on the used Plugin.
|
| 323 |
+
|
| 324 |
+
Returns
|
| 325 |
+
-------
|
| 326 |
+
metadata : dict
|
| 327 |
+
A dictionary of metadata.
|
| 328 |
+
|
| 329 |
+
"""
|
| 330 |
+
|
| 331 |
+
return self.metadata(index=index, exclude_applied=False)
|
| 332 |
+
|
| 333 |
+
def metadata(self, index=None, exclude_applied: bool = True):
|
| 334 |
+
"""Format-Specific ndimage metadata.
|
| 335 |
+
|
| 336 |
+
Parameters
|
| 337 |
+
----------
|
| 338 |
+
index : int
|
| 339 |
+
The index of the ndimage to read. If the index is out of bounds a
|
| 340 |
+
``ValueError`` is raised. If ``None``, global metadata is returned.
|
| 341 |
+
exclude_applied : bool
|
| 342 |
+
This parameter exists for compatibility and has no effect. Legacy
|
| 343 |
+
plugins always report all metadata they find.
|
| 344 |
+
|
| 345 |
+
Returns
|
| 346 |
+
-------
|
| 347 |
+
metadata : dict
|
| 348 |
+
A dictionary filled with format-specific metadata fields and their
|
| 349 |
+
values.
|
| 350 |
+
|
| 351 |
+
"""
|
| 352 |
+
|
| 353 |
+
if index is None:
|
| 354 |
+
index = _legacy_default_index(self._format)
|
| 355 |
+
|
| 356 |
+
return self.legacy_get_reader().get_meta_data(index=index)
|
| 357 |
+
|
| 358 |
+
def __del__(self) -> None:
|
| 359 |
+
pass
|
| 360 |
+
# turns out we can't close the file here for LegacyPlugin
|
| 361 |
+
# because it would break backwards compatibility
|
| 362 |
+
# with legacy_get_writer and legacy_get_reader
|
| 363 |
+
# self._request.finish()
|
evalkit_tf446/lib/python3.10/site-packages/imageio/core/request.pyi
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import BinaryIO, Optional, Dict, Any, Sequence, overload, Literal
|
| 2 |
+
from ..typing import ImageResource
|
| 3 |
+
import enum
|
| 4 |
+
|
| 5 |
+
EXAMPLE_IMAGES: Dict[str, str]
|
| 6 |
+
RETURN_BYTES = "<bytes>"
|
| 7 |
+
URI_BYTES = 1
|
| 8 |
+
URI_FILE = 2
|
| 9 |
+
URI_FILENAME = 3
|
| 10 |
+
URI_ZIPPED = 4
|
| 11 |
+
URI_HTTP = 5
|
| 12 |
+
URI_FTP = 6
|
| 13 |
+
|
| 14 |
+
class IOMode(str, enum.Enum):
|
| 15 |
+
read = "r"
|
| 16 |
+
write = "w"
|
| 17 |
+
|
| 18 |
+
class ImageMode(str, enum.Enum):
|
| 19 |
+
single_image = "i"
|
| 20 |
+
multi_image = "I"
|
| 21 |
+
single_volume = "v"
|
| 22 |
+
multi_volume = "V"
|
| 23 |
+
any_mode = "?"
|
| 24 |
+
|
| 25 |
+
@enum.unique
|
| 26 |
+
class Mode(str, enum.Enum):
|
| 27 |
+
read_single_image = "ri"
|
| 28 |
+
read_multi_image = "rI"
|
| 29 |
+
read_single_volume = "rv"
|
| 30 |
+
read_multi_volume = "rV"
|
| 31 |
+
read_any = "r?"
|
| 32 |
+
write_single_image = "wi"
|
| 33 |
+
write_multi_image = "wI"
|
| 34 |
+
write_single_volume = "wv"
|
| 35 |
+
write_multi_volume = "wV"
|
| 36 |
+
write_any = "w?"
|
| 37 |
+
|
| 38 |
+
@classmethod
|
| 39 |
+
def _missing_(cls, value: Any) -> Mode: ...
|
| 40 |
+
@property
|
| 41 |
+
def io_mode(self) -> IOMode: ...
|
| 42 |
+
@property
|
| 43 |
+
def image_mode(self) -> ImageMode: ...
|
| 44 |
+
|
| 45 |
+
class InitializationError(Exception): ...
|
| 46 |
+
|
| 47 |
+
class Request(object):
|
| 48 |
+
_uri_type: int
|
| 49 |
+
raw_uri: ImageResource
|
| 50 |
+
|
| 51 |
+
@property
|
| 52 |
+
def filename(self) -> str: ...
|
| 53 |
+
@property
|
| 54 |
+
def extension(self) -> str: ...
|
| 55 |
+
@property
|
| 56 |
+
def format_hint(self) -> Optional[str]: ...
|
| 57 |
+
@format_hint.setter
|
| 58 |
+
def format_hint(self, format: str) -> None: ...
|
| 59 |
+
@property
|
| 60 |
+
def mode(self) -> Mode: ...
|
| 61 |
+
@property
|
| 62 |
+
def kwargs(self) -> Dict[str, Any]: ...
|
| 63 |
+
@property
|
| 64 |
+
def firstbytes(self) -> bytes: ...
|
| 65 |
+
def __init__(
|
| 66 |
+
self,
|
| 67 |
+
uri: ImageResource,
|
| 68 |
+
mode: str,
|
| 69 |
+
*,
|
| 70 |
+
extension: str = None,
|
| 71 |
+
format_hint: str = None,
|
| 72 |
+
**kwargs
|
| 73 |
+
) -> None: ...
|
| 74 |
+
def _parse_uri(self, uri: ImageResource) -> None: ...
|
| 75 |
+
def get_file(self) -> BinaryIO: ...
|
| 76 |
+
def get_local_filename(self) -> str: ...
|
| 77 |
+
def finish(self) -> None: ...
|
| 78 |
+
def get_result(self) -> Optional[bytes]: ...
|
| 79 |
+
def _read_first_bytes(self, N: int = 256) -> bytes: ...
|
| 80 |
+
|
| 81 |
+
def read_n_bytes(f: BinaryIO, N: int) -> bytes: ...
|
| 82 |
+
|
| 83 |
+
class SeekableFileObject:
|
| 84 |
+
def __init__(self, f: BinaryIO) -> None: ...
|
| 85 |
+
def read(self, n: int = None) -> bytes: ...
|
| 86 |
+
def tell(self) -> int: ...
|
| 87 |
+
def seek(self, i: int, mode: int = 0) -> int: ...
|
| 88 |
+
def close(self) -> None: ...
|
| 89 |
+
def isatty(self) -> bool: ...
|
| 90 |
+
def seekable(self) -> bool: ...
|
evalkit_tf446/lib/python3.10/site-packages/imageio/core/util.py
ADDED
|
@@ -0,0 +1,561 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
# imageio is distributed under the terms of the (new) BSD License.
|
| 3 |
+
|
| 4 |
+
"""
|
| 5 |
+
Various utilities for imageio
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
from collections import OrderedDict
|
| 10 |
+
import numpy as np
|
| 11 |
+
import os
|
| 12 |
+
import re
|
| 13 |
+
import struct
|
| 14 |
+
import sys
|
| 15 |
+
import time
|
| 16 |
+
import logging
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
logger = logging.getLogger("imageio")
|
| 20 |
+
|
| 21 |
+
IS_PYPY = "__pypy__" in sys.builtin_module_names
|
| 22 |
+
THIS_DIR = os.path.abspath(os.path.dirname(__file__))
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def urlopen(*args, **kwargs):
|
| 26 |
+
"""Compatibility function for the urlopen function. Raises an
|
| 27 |
+
RuntimeError if urlopen could not be imported (which can occur in
|
| 28 |
+
frozen applications.
|
| 29 |
+
"""
|
| 30 |
+
try:
|
| 31 |
+
from urllib.request import urlopen
|
| 32 |
+
except ImportError:
|
| 33 |
+
raise RuntimeError("Could not import urlopen.")
|
| 34 |
+
return urlopen(*args, **kwargs)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def _precision_warn(p1, p2, extra=""):
|
| 38 |
+
t = (
|
| 39 |
+
"Lossy conversion from {} to {}. {} Convert image to {} prior to "
|
| 40 |
+
"saving to suppress this warning."
|
| 41 |
+
)
|
| 42 |
+
logger.warning(t.format(p1, p2, extra, p2))
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def image_as_uint(im, bitdepth=None):
|
| 46 |
+
"""Convert the given image to uint (default: uint8)
|
| 47 |
+
|
| 48 |
+
If the dtype already matches the desired format, it is returned
|
| 49 |
+
as-is. If the image is float, and all values are between 0 and 1,
|
| 50 |
+
the values are multiplied by np.power(2.0, bitdepth). In all other
|
| 51 |
+
situations, the values are scaled such that the minimum value
|
| 52 |
+
becomes 0 and the maximum value becomes np.power(2.0, bitdepth)-1
|
| 53 |
+
(255 for 8-bit and 65535 for 16-bit).
|
| 54 |
+
"""
|
| 55 |
+
if not bitdepth:
|
| 56 |
+
bitdepth = 8
|
| 57 |
+
if not isinstance(im, np.ndarray):
|
| 58 |
+
raise ValueError("Image must be a numpy array")
|
| 59 |
+
if bitdepth == 8:
|
| 60 |
+
out_type = np.uint8
|
| 61 |
+
elif bitdepth == 16:
|
| 62 |
+
out_type = np.uint16
|
| 63 |
+
else:
|
| 64 |
+
raise ValueError("Bitdepth must be either 8 or 16")
|
| 65 |
+
dtype_str1 = str(im.dtype)
|
| 66 |
+
dtype_str2 = out_type.__name__
|
| 67 |
+
if (im.dtype == np.uint8 and bitdepth == 8) or (
|
| 68 |
+
im.dtype == np.uint16 and bitdepth == 16
|
| 69 |
+
):
|
| 70 |
+
# Already the correct format? Return as-is
|
| 71 |
+
return im
|
| 72 |
+
if dtype_str1.startswith("float") and np.nanmin(im) >= 0 and np.nanmax(im) <= 1:
|
| 73 |
+
_precision_warn(dtype_str1, dtype_str2, "Range [0, 1].")
|
| 74 |
+
im = im.astype(np.float64) * (np.power(2.0, bitdepth) - 1) + 0.499999999
|
| 75 |
+
elif im.dtype == np.uint16 and bitdepth == 8:
|
| 76 |
+
_precision_warn(dtype_str1, dtype_str2, "Losing 8 bits of resolution.")
|
| 77 |
+
im = np.right_shift(im, 8)
|
| 78 |
+
elif im.dtype == np.uint32:
|
| 79 |
+
_precision_warn(
|
| 80 |
+
dtype_str1,
|
| 81 |
+
dtype_str2,
|
| 82 |
+
"Losing {} bits of resolution.".format(32 - bitdepth),
|
| 83 |
+
)
|
| 84 |
+
im = np.right_shift(im, 32 - bitdepth)
|
| 85 |
+
elif im.dtype == np.uint64:
|
| 86 |
+
_precision_warn(
|
| 87 |
+
dtype_str1,
|
| 88 |
+
dtype_str2,
|
| 89 |
+
"Losing {} bits of resolution.".format(64 - bitdepth),
|
| 90 |
+
)
|
| 91 |
+
im = np.right_shift(im, 64 - bitdepth)
|
| 92 |
+
else:
|
| 93 |
+
mi = np.nanmin(im)
|
| 94 |
+
ma = np.nanmax(im)
|
| 95 |
+
if not np.isfinite(mi):
|
| 96 |
+
raise ValueError("Minimum image value is not finite")
|
| 97 |
+
if not np.isfinite(ma):
|
| 98 |
+
raise ValueError("Maximum image value is not finite")
|
| 99 |
+
if ma == mi:
|
| 100 |
+
return im.astype(out_type)
|
| 101 |
+
_precision_warn(dtype_str1, dtype_str2, "Range [{}, {}].".format(mi, ma))
|
| 102 |
+
# Now make float copy before we scale
|
| 103 |
+
im = im.astype("float64")
|
| 104 |
+
# Scale the values between 0 and 1 then multiply by the max value
|
| 105 |
+
im = (im - mi) / (ma - mi) * (np.power(2.0, bitdepth) - 1) + 0.499999999
|
| 106 |
+
assert np.nanmin(im) >= 0
|
| 107 |
+
assert np.nanmax(im) < np.power(2.0, bitdepth)
|
| 108 |
+
return im.astype(out_type)
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
class Array(np.ndarray):
|
| 112 |
+
"""Array(array, meta=None)
|
| 113 |
+
|
| 114 |
+
A subclass of np.ndarray that has a meta attribute. Get the dictionary
|
| 115 |
+
that contains the meta data using ``im.meta``. Convert to a plain numpy
|
| 116 |
+
array using ``np.asarray(im)``.
|
| 117 |
+
|
| 118 |
+
"""
|
| 119 |
+
|
| 120 |
+
def __new__(cls, array, meta=None):
|
| 121 |
+
# Check
|
| 122 |
+
if not isinstance(array, np.ndarray):
|
| 123 |
+
raise ValueError("Array expects a numpy array.")
|
| 124 |
+
if not (meta is None or isinstance(meta, dict)):
|
| 125 |
+
raise ValueError("Array expects meta data to be a dict.")
|
| 126 |
+
# Convert and return
|
| 127 |
+
meta = meta if meta is not None else getattr(array, "meta", {})
|
| 128 |
+
try:
|
| 129 |
+
ob = array.view(cls)
|
| 130 |
+
except AttributeError: # pragma: no cover
|
| 131 |
+
# Just return the original; no metadata on the array in Pypy!
|
| 132 |
+
return array
|
| 133 |
+
ob._copy_meta(meta)
|
| 134 |
+
return ob
|
| 135 |
+
|
| 136 |
+
def _copy_meta(self, meta):
|
| 137 |
+
"""Make a 2-level deep copy of the meta dictionary."""
|
| 138 |
+
self._meta = Dict()
|
| 139 |
+
for key, val in meta.items():
|
| 140 |
+
if isinstance(val, dict):
|
| 141 |
+
val = Dict(val) # Copy this level
|
| 142 |
+
self._meta[key] = val
|
| 143 |
+
|
| 144 |
+
@property
|
| 145 |
+
def meta(self):
|
| 146 |
+
"""The dict with the meta data of this image."""
|
| 147 |
+
return self._meta
|
| 148 |
+
|
| 149 |
+
def __array_finalize__(self, ob):
|
| 150 |
+
"""So the meta info is maintained when doing calculations with
|
| 151 |
+
the array.
|
| 152 |
+
"""
|
| 153 |
+
if isinstance(ob, Array):
|
| 154 |
+
self._copy_meta(ob.meta)
|
| 155 |
+
else:
|
| 156 |
+
self._copy_meta({})
|
| 157 |
+
|
| 158 |
+
def __array_wrap__(self, out, context=None):
|
| 159 |
+
"""So that we return a native numpy array (or scalar) when a
|
| 160 |
+
reducting ufunc is applied (such as sum(), std(), etc.)
|
| 161 |
+
"""
|
| 162 |
+
if not out.shape:
|
| 163 |
+
return out.dtype.type(out) # Scalar
|
| 164 |
+
elif out.shape != self.shape:
|
| 165 |
+
return out.view(type=np.ndarray)
|
| 166 |
+
elif not isinstance(out, Array):
|
| 167 |
+
return Array(out, self.meta)
|
| 168 |
+
else:
|
| 169 |
+
return out # Type Array
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
Image = Array # Alias for backwards compatibility
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
def asarray(a):
|
| 176 |
+
"""Pypy-safe version of np.asarray. Pypy's np.asarray consumes a
|
| 177 |
+
*lot* of memory if the given array is an ndarray subclass. This
|
| 178 |
+
function does not.
|
| 179 |
+
"""
|
| 180 |
+
if isinstance(a, np.ndarray):
|
| 181 |
+
if IS_PYPY: # pragma: no cover
|
| 182 |
+
a = a.copy() # pypy has issues with base views
|
| 183 |
+
plain = a.view(type=np.ndarray)
|
| 184 |
+
return plain
|
| 185 |
+
return np.asarray(a)
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
class Dict(OrderedDict):
|
| 189 |
+
"""A dict in which the keys can be get and set as if they were
|
| 190 |
+
attributes. Very convenient in combination with autocompletion.
|
| 191 |
+
|
| 192 |
+
This Dict still behaves as much as possible as a normal dict, and
|
| 193 |
+
keys can be anything that are otherwise valid keys. However,
|
| 194 |
+
keys that are not valid identifiers or that are names of the dict
|
| 195 |
+
class (such as 'items' and 'copy') cannot be get/set as attributes.
|
| 196 |
+
"""
|
| 197 |
+
|
| 198 |
+
__reserved_names__ = dir(OrderedDict()) # Also from OrderedDict
|
| 199 |
+
__pure_names__ = dir(dict())
|
| 200 |
+
|
| 201 |
+
def __getattribute__(self, key):
|
| 202 |
+
try:
|
| 203 |
+
return object.__getattribute__(self, key)
|
| 204 |
+
except AttributeError:
|
| 205 |
+
if key in self:
|
| 206 |
+
return self[key]
|
| 207 |
+
else:
|
| 208 |
+
raise
|
| 209 |
+
|
| 210 |
+
def __setattr__(self, key, val):
|
| 211 |
+
if key in Dict.__reserved_names__:
|
| 212 |
+
# Either let OrderedDict do its work, or disallow
|
| 213 |
+
if key not in Dict.__pure_names__:
|
| 214 |
+
return OrderedDict.__setattr__(self, key, val)
|
| 215 |
+
else:
|
| 216 |
+
raise AttributeError(
|
| 217 |
+
"Reserved name, this key can only "
|
| 218 |
+
+ "be set via ``d[%r] = X``" % key
|
| 219 |
+
)
|
| 220 |
+
else:
|
| 221 |
+
# if isinstance(val, dict): val = Dict(val) -> no, makes a copy!
|
| 222 |
+
self[key] = val
|
| 223 |
+
|
| 224 |
+
def __dir__(self):
|
| 225 |
+
def isidentifier(x):
|
| 226 |
+
return bool(re.match(r"[a-z_]\w*$", x, re.I))
|
| 227 |
+
|
| 228 |
+
names = [k for k in self.keys() if (isinstance(k, str) and isidentifier(k))]
|
| 229 |
+
return Dict.__reserved_names__ + names
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
class BaseProgressIndicator(object):
|
| 233 |
+
"""BaseProgressIndicator(name)
|
| 234 |
+
|
| 235 |
+
A progress indicator helps display the progress of a task to the
|
| 236 |
+
user. Progress can be pending, running, finished or failed.
|
| 237 |
+
|
| 238 |
+
Each task has:
|
| 239 |
+
* a name - a short description of what needs to be done.
|
| 240 |
+
* an action - the current action in performing the task (e.g. a subtask)
|
| 241 |
+
* progress - how far the task is completed
|
| 242 |
+
* max - max number of progress units. If 0, the progress is indefinite
|
| 243 |
+
* unit - the units in which the progress is counted
|
| 244 |
+
* status - 0: pending, 1: in progress, 2: finished, 3: failed
|
| 245 |
+
|
| 246 |
+
This class defines an abstract interface. Subclasses should implement
|
| 247 |
+
_start, _stop, _update_progress(progressText), _write(message).
|
| 248 |
+
"""
|
| 249 |
+
|
| 250 |
+
def __init__(self, name):
|
| 251 |
+
self._name = name
|
| 252 |
+
self._action = ""
|
| 253 |
+
self._unit = ""
|
| 254 |
+
self._max = 0
|
| 255 |
+
self._status = 0
|
| 256 |
+
self._last_progress_update = 0
|
| 257 |
+
|
| 258 |
+
def start(self, action="", unit="", max=0):
|
| 259 |
+
"""start(action='', unit='', max=0)
|
| 260 |
+
|
| 261 |
+
Start the progress. Optionally specify an action, a unit,
|
| 262 |
+
and a maximum progress value.
|
| 263 |
+
"""
|
| 264 |
+
if self._status == 1:
|
| 265 |
+
self.finish()
|
| 266 |
+
self._action = action
|
| 267 |
+
self._unit = unit
|
| 268 |
+
self._max = max
|
| 269 |
+
#
|
| 270 |
+
self._progress = 0
|
| 271 |
+
self._status = 1
|
| 272 |
+
self._start()
|
| 273 |
+
|
| 274 |
+
def status(self):
|
| 275 |
+
"""status()
|
| 276 |
+
|
| 277 |
+
Get the status of the progress - 0: pending, 1: in progress,
|
| 278 |
+
2: finished, 3: failed
|
| 279 |
+
"""
|
| 280 |
+
return self._status
|
| 281 |
+
|
| 282 |
+
def set_progress(self, progress=0, force=False):
|
| 283 |
+
"""set_progress(progress=0, force=False)
|
| 284 |
+
|
| 285 |
+
Set the current progress. To avoid unnecessary progress updates
|
| 286 |
+
this will only have a visual effect if the time since the last
|
| 287 |
+
update is > 0.1 seconds, or if force is True.
|
| 288 |
+
"""
|
| 289 |
+
self._progress = progress
|
| 290 |
+
# Update or not?
|
| 291 |
+
if not (force or (time.time() - self._last_progress_update > 0.1)):
|
| 292 |
+
return
|
| 293 |
+
self._last_progress_update = time.time()
|
| 294 |
+
# Compose new string
|
| 295 |
+
unit = self._unit or ""
|
| 296 |
+
progressText = ""
|
| 297 |
+
if unit == "%":
|
| 298 |
+
progressText = "%2.1f%%" % progress
|
| 299 |
+
elif self._max > 0:
|
| 300 |
+
percent = 100 * float(progress) / self._max
|
| 301 |
+
progressText = "%i/%i %s (%2.1f%%)" % (progress, self._max, unit, percent)
|
| 302 |
+
elif progress > 0:
|
| 303 |
+
if isinstance(progress, float):
|
| 304 |
+
progressText = "%0.4g %s" % (progress, unit)
|
| 305 |
+
else:
|
| 306 |
+
progressText = "%i %s" % (progress, unit)
|
| 307 |
+
# Update
|
| 308 |
+
self._update_progress(progressText)
|
| 309 |
+
|
| 310 |
+
def increase_progress(self, extra_progress):
|
| 311 |
+
"""increase_progress(extra_progress)
|
| 312 |
+
|
| 313 |
+
Increase the progress by a certain amount.
|
| 314 |
+
"""
|
| 315 |
+
self.set_progress(self._progress + extra_progress)
|
| 316 |
+
|
| 317 |
+
def finish(self, message=None):
|
| 318 |
+
"""finish(message=None)
|
| 319 |
+
|
| 320 |
+
Finish the progress, optionally specifying a message. This will
|
| 321 |
+
not set the progress to the maximum.
|
| 322 |
+
"""
|
| 323 |
+
self.set_progress(self._progress, True) # fore update
|
| 324 |
+
self._status = 2
|
| 325 |
+
self._stop()
|
| 326 |
+
if message is not None:
|
| 327 |
+
self._write(message)
|
| 328 |
+
|
| 329 |
+
def fail(self, message=None):
|
| 330 |
+
"""fail(message=None)
|
| 331 |
+
|
| 332 |
+
Stop the progress with a failure, optionally specifying a message.
|
| 333 |
+
"""
|
| 334 |
+
self.set_progress(self._progress, True) # fore update
|
| 335 |
+
self._status = 3
|
| 336 |
+
self._stop()
|
| 337 |
+
message = "FAIL " + (message or "")
|
| 338 |
+
self._write(message)
|
| 339 |
+
|
| 340 |
+
def write(self, message):
|
| 341 |
+
"""write(message)
|
| 342 |
+
|
| 343 |
+
Write a message during progress (such as a warning).
|
| 344 |
+
"""
|
| 345 |
+
if self.__class__ == BaseProgressIndicator:
|
| 346 |
+
# When this class is used as a dummy, print explicit message
|
| 347 |
+
print(message)
|
| 348 |
+
else:
|
| 349 |
+
return self._write(message)
|
| 350 |
+
|
| 351 |
+
# Implementing classes should implement these
|
| 352 |
+
|
| 353 |
+
def _start(self):
|
| 354 |
+
pass
|
| 355 |
+
|
| 356 |
+
def _stop(self):
|
| 357 |
+
pass
|
| 358 |
+
|
| 359 |
+
def _update_progress(self, progressText):
|
| 360 |
+
pass
|
| 361 |
+
|
| 362 |
+
def _write(self, message):
|
| 363 |
+
pass
|
| 364 |
+
|
| 365 |
+
|
| 366 |
+
class StdoutProgressIndicator(BaseProgressIndicator):
|
| 367 |
+
"""StdoutProgressIndicator(name)
|
| 368 |
+
|
| 369 |
+
A progress indicator that shows the progress in stdout. It
|
| 370 |
+
assumes that the tty can appropriately deal with backspace
|
| 371 |
+
characters.
|
| 372 |
+
"""
|
| 373 |
+
|
| 374 |
+
def _start(self):
|
| 375 |
+
self._chars_prefix, self._chars = "", ""
|
| 376 |
+
# Write message
|
| 377 |
+
if self._action:
|
| 378 |
+
self._chars_prefix = "%s (%s): " % (self._name, self._action)
|
| 379 |
+
else:
|
| 380 |
+
self._chars_prefix = "%s: " % self._name
|
| 381 |
+
sys.stdout.write(self._chars_prefix)
|
| 382 |
+
sys.stdout.flush()
|
| 383 |
+
|
| 384 |
+
def _update_progress(self, progressText):
|
| 385 |
+
# If progress is unknown, at least make something move
|
| 386 |
+
if not progressText:
|
| 387 |
+
i1, i2, i3, i4 = "-\\|/"
|
| 388 |
+
M = {i1: i2, i2: i3, i3: i4, i4: i1}
|
| 389 |
+
progressText = M.get(self._chars, i1)
|
| 390 |
+
# Store new string and write
|
| 391 |
+
delChars = "\b" * len(self._chars)
|
| 392 |
+
self._chars = progressText
|
| 393 |
+
sys.stdout.write(delChars + self._chars)
|
| 394 |
+
sys.stdout.flush()
|
| 395 |
+
|
| 396 |
+
def _stop(self):
|
| 397 |
+
self._chars = self._chars_prefix = ""
|
| 398 |
+
sys.stdout.write("\n")
|
| 399 |
+
sys.stdout.flush()
|
| 400 |
+
|
| 401 |
+
def _write(self, message):
|
| 402 |
+
# Write message
|
| 403 |
+
delChars = "\b" * len(self._chars_prefix + self._chars)
|
| 404 |
+
sys.stdout.write(delChars + " " + message + "\n")
|
| 405 |
+
# Reprint progress text
|
| 406 |
+
sys.stdout.write(self._chars_prefix + self._chars)
|
| 407 |
+
sys.stdout.flush()
|
| 408 |
+
|
| 409 |
+
|
| 410 |
+
# From pyzolib/paths.py (https://bitbucket.org/pyzo/pyzolib/src/tip/paths.py)
|
| 411 |
+
def appdata_dir(appname=None, roaming=False):
|
| 412 |
+
"""appdata_dir(appname=None, roaming=False)
|
| 413 |
+
|
| 414 |
+
Get the path to the application directory, where applications are allowed
|
| 415 |
+
to write user specific files (e.g. configurations). For non-user specific
|
| 416 |
+
data, consider using common_appdata_dir().
|
| 417 |
+
If appname is given, a subdir is appended (and created if necessary).
|
| 418 |
+
If roaming is True, will prefer a roaming directory (Windows Vista/7).
|
| 419 |
+
"""
|
| 420 |
+
|
| 421 |
+
# Define default user directory
|
| 422 |
+
userDir = os.getenv("IMAGEIO_USERDIR", None)
|
| 423 |
+
if userDir is None:
|
| 424 |
+
userDir = os.path.expanduser("~")
|
| 425 |
+
if not os.path.isdir(userDir): # pragma: no cover
|
| 426 |
+
userDir = "/var/tmp" # issue #54
|
| 427 |
+
|
| 428 |
+
# Get system app data dir
|
| 429 |
+
path = None
|
| 430 |
+
if sys.platform.startswith("win"):
|
| 431 |
+
path1, path2 = os.getenv("LOCALAPPDATA"), os.getenv("APPDATA")
|
| 432 |
+
path = (path2 or path1) if roaming else (path1 or path2)
|
| 433 |
+
elif sys.platform.startswith("darwin"):
|
| 434 |
+
path = os.path.join(userDir, "Library", "Application Support")
|
| 435 |
+
# On Linux and as fallback
|
| 436 |
+
if not (path and os.path.isdir(path)):
|
| 437 |
+
path = userDir
|
| 438 |
+
|
| 439 |
+
# Maybe we should store things local to the executable (in case of a
|
| 440 |
+
# portable distro or a frozen application that wants to be portable)
|
| 441 |
+
prefix = sys.prefix
|
| 442 |
+
if getattr(sys, "frozen", None):
|
| 443 |
+
prefix = os.path.abspath(os.path.dirname(sys.executable))
|
| 444 |
+
for reldir in ("settings", "../settings"):
|
| 445 |
+
localpath = os.path.abspath(os.path.join(prefix, reldir))
|
| 446 |
+
if os.path.isdir(localpath): # pragma: no cover
|
| 447 |
+
try:
|
| 448 |
+
open(os.path.join(localpath, "test.write"), "wb").close()
|
| 449 |
+
os.remove(os.path.join(localpath, "test.write"))
|
| 450 |
+
except IOError:
|
| 451 |
+
pass # We cannot write in this directory
|
| 452 |
+
else:
|
| 453 |
+
path = localpath
|
| 454 |
+
break
|
| 455 |
+
|
| 456 |
+
# Get path specific for this app
|
| 457 |
+
if appname:
|
| 458 |
+
if path == userDir:
|
| 459 |
+
appname = "." + appname.lstrip(".") # Make it a hidden directory
|
| 460 |
+
path = os.path.join(path, appname)
|
| 461 |
+
if not os.path.isdir(path): # pragma: no cover
|
| 462 |
+
os.makedirs(path, exist_ok=True)
|
| 463 |
+
|
| 464 |
+
# Done
|
| 465 |
+
return path
|
| 466 |
+
|
| 467 |
+
|
| 468 |
+
def resource_dirs():
|
| 469 |
+
"""resource_dirs()
|
| 470 |
+
|
| 471 |
+
Get a list of directories where imageio resources may be located.
|
| 472 |
+
The first directory in this list is the "resources" directory in
|
| 473 |
+
the package itself. The second directory is the appdata directory
|
| 474 |
+
(~/.imageio on Linux). The list further contains the application
|
| 475 |
+
directory (for frozen apps), and may include additional directories
|
| 476 |
+
in the future.
|
| 477 |
+
"""
|
| 478 |
+
dirs = [resource_package_dir()]
|
| 479 |
+
# Resource dir baked in the package.
|
| 480 |
+
# Appdata directory
|
| 481 |
+
try:
|
| 482 |
+
dirs.append(appdata_dir("imageio"))
|
| 483 |
+
except Exception: # pragma: no cover
|
| 484 |
+
pass # The home dir may not be writable
|
| 485 |
+
# Directory where the app is located (mainly for frozen apps)
|
| 486 |
+
if getattr(sys, "frozen", None):
|
| 487 |
+
dirs.append(os.path.abspath(os.path.dirname(sys.executable)))
|
| 488 |
+
elif sys.path and sys.path[0]:
|
| 489 |
+
dirs.append(os.path.abspath(sys.path[0]))
|
| 490 |
+
return dirs
|
| 491 |
+
|
| 492 |
+
|
| 493 |
+
def resource_package_dir():
|
| 494 |
+
"""package_dir
|
| 495 |
+
|
| 496 |
+
Get the resources directory in the imageio package installation
|
| 497 |
+
directory.
|
| 498 |
+
|
| 499 |
+
Notes
|
| 500 |
+
-----
|
| 501 |
+
This is a convenience method that is used by `resource_dirs` and
|
| 502 |
+
imageio entry point scripts.
|
| 503 |
+
"""
|
| 504 |
+
# Make pkg_resources optional if setuptools is not available
|
| 505 |
+
try:
|
| 506 |
+
# Avoid importing pkg_resources in the top level due to how slow it is
|
| 507 |
+
# https://github.com/pypa/setuptools/issues/510
|
| 508 |
+
import pkg_resources
|
| 509 |
+
except ImportError:
|
| 510 |
+
pkg_resources = None
|
| 511 |
+
|
| 512 |
+
if pkg_resources:
|
| 513 |
+
# The directory returned by `pkg_resources.resource_filename`
|
| 514 |
+
# also works with eggs.
|
| 515 |
+
pdir = pkg_resources.resource_filename("imageio", "resources")
|
| 516 |
+
else:
|
| 517 |
+
# If setuptools is not available, use fallback
|
| 518 |
+
pdir = os.path.abspath(os.path.join(THIS_DIR, "..", "resources"))
|
| 519 |
+
return pdir
|
| 520 |
+
|
| 521 |
+
|
| 522 |
+
def get_platform():
|
| 523 |
+
"""get_platform()
|
| 524 |
+
|
| 525 |
+
Get a string that specifies the platform more specific than
|
| 526 |
+
sys.platform does. The result can be: linux32, linux64, win32,
|
| 527 |
+
win64, osx32, osx64. Other platforms may be added in the future.
|
| 528 |
+
"""
|
| 529 |
+
# Get platform
|
| 530 |
+
if sys.platform.startswith("linux"):
|
| 531 |
+
plat = "linux%i"
|
| 532 |
+
elif sys.platform.startswith("win"):
|
| 533 |
+
plat = "win%i"
|
| 534 |
+
elif sys.platform.startswith("darwin"):
|
| 535 |
+
plat = "osx%i"
|
| 536 |
+
elif sys.platform.startswith("freebsd"):
|
| 537 |
+
plat = "freebsd%i"
|
| 538 |
+
else: # pragma: no cover
|
| 539 |
+
return None
|
| 540 |
+
|
| 541 |
+
return plat % (struct.calcsize("P") * 8) # 32 or 64 bits
|
| 542 |
+
|
| 543 |
+
|
| 544 |
+
def has_module(module_name):
|
| 545 |
+
"""Check to see if a python module is available."""
|
| 546 |
+
if sys.version_info > (3, 4):
|
| 547 |
+
import importlib
|
| 548 |
+
|
| 549 |
+
name_parts = module_name.split(".")
|
| 550 |
+
for i in range(len(name_parts)):
|
| 551 |
+
if importlib.util.find_spec(".".join(name_parts[: i + 1])) is None:
|
| 552 |
+
return False
|
| 553 |
+
return True
|
| 554 |
+
else: # pragma: no cover
|
| 555 |
+
import imp
|
| 556 |
+
|
| 557 |
+
try:
|
| 558 |
+
imp.find_module(module_name)
|
| 559 |
+
except ImportError:
|
| 560 |
+
return False
|
| 561 |
+
return True
|
evalkit_tf446/lib/python3.10/site-packages/markdown_it/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (295 Bytes). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/markdown_it/__pycache__/_compat.cpython-310.pyc
ADDED
|
Binary file (448 Bytes). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/markdown_it/__pycache__/_punycode.cpython-310.pyc
ADDED
|
Binary file (1.75 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/markdown_it/__pycache__/main.cpython-310.pyc
ADDED
|
Binary file (12.8 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/markdown_it/__pycache__/parser_block.cpython-310.pyc
ADDED
|
Binary file (2.75 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/markdown_it/__pycache__/parser_core.cpython-310.pyc
ADDED
|
Binary file (1.48 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/markdown_it/__pycache__/parser_inline.cpython-310.pyc
ADDED
|
Binary file (3.18 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/markdown_it/__pycache__/renderer.cpython-310.pyc
ADDED
|
Binary file (7.73 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/markdown_it/__pycache__/ruler.cpython-310.pyc
ADDED
|
Binary file (9.11 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/markdown_it/__pycache__/token.cpython-310.pyc
ADDED
|
Binary file (6.25 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/markdown_it/__pycache__/tree.cpython-310.pyc
ADDED
|
Binary file (11.2 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/markdown_it/__pycache__/utils.cpython-310.pyc
ADDED
|
Binary file (5.87 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/markdown_it/common/__init__.py
ADDED
|
File without changes
|
evalkit_tf446/lib/python3.10/site-packages/markdown_it/common/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (177 Bytes). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/markdown_it/common/__pycache__/entities.cpython-310.pyc
ADDED
|
Binary file (451 Bytes). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/markdown_it/common/__pycache__/html_blocks.cpython-310.pyc
ADDED
|
Binary file (751 Bytes). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/markdown_it/common/__pycache__/html_re.cpython-310.pyc
ADDED
|
Binary file (988 Bytes). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/markdown_it/common/__pycache__/normalize_url.cpython-310.pyc
ADDED
|
Binary file (2.2 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/markdown_it/common/__pycache__/utils.cpython-310.pyc
ADDED
|
Binary file (8.12 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/markdown_it/common/entities.py
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""HTML5 entities map: { name -> characters }."""
|
| 2 |
+
import html.entities
|
| 3 |
+
|
| 4 |
+
entities = {name.rstrip(";"): chars for name, chars in html.entities.html5.items()}
|
evalkit_tf446/lib/python3.10/site-packages/markdown_it/common/html_blocks.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""List of valid html blocks names, according to commonmark spec
|
| 2 |
+
http://jgm.github.io/CommonMark/spec.html#html-blocks
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
block_names = [
|
| 6 |
+
"address",
|
| 7 |
+
"article",
|
| 8 |
+
"aside",
|
| 9 |
+
"base",
|
| 10 |
+
"basefont",
|
| 11 |
+
"blockquote",
|
| 12 |
+
"body",
|
| 13 |
+
"caption",
|
| 14 |
+
"center",
|
| 15 |
+
"col",
|
| 16 |
+
"colgroup",
|
| 17 |
+
"dd",
|
| 18 |
+
"details",
|
| 19 |
+
"dialog",
|
| 20 |
+
"dir",
|
| 21 |
+
"div",
|
| 22 |
+
"dl",
|
| 23 |
+
"dt",
|
| 24 |
+
"fieldset",
|
| 25 |
+
"figcaption",
|
| 26 |
+
"figure",
|
| 27 |
+
"footer",
|
| 28 |
+
"form",
|
| 29 |
+
"frame",
|
| 30 |
+
"frameset",
|
| 31 |
+
"h1",
|
| 32 |
+
"h2",
|
| 33 |
+
"h3",
|
| 34 |
+
"h4",
|
| 35 |
+
"h5",
|
| 36 |
+
"h6",
|
| 37 |
+
"head",
|
| 38 |
+
"header",
|
| 39 |
+
"hr",
|
| 40 |
+
"html",
|
| 41 |
+
"iframe",
|
| 42 |
+
"legend",
|
| 43 |
+
"li",
|
| 44 |
+
"link",
|
| 45 |
+
"main",
|
| 46 |
+
"menu",
|
| 47 |
+
"menuitem",
|
| 48 |
+
"nav",
|
| 49 |
+
"noframes",
|
| 50 |
+
"ol",
|
| 51 |
+
"optgroup",
|
| 52 |
+
"option",
|
| 53 |
+
"p",
|
| 54 |
+
"param",
|
| 55 |
+
"section",
|
| 56 |
+
"source",
|
| 57 |
+
"summary",
|
| 58 |
+
"table",
|
| 59 |
+
"tbody",
|
| 60 |
+
"td",
|
| 61 |
+
"tfoot",
|
| 62 |
+
"th",
|
| 63 |
+
"thead",
|
| 64 |
+
"title",
|
| 65 |
+
"tr",
|
| 66 |
+
"track",
|
| 67 |
+
"ul",
|
| 68 |
+
]
|
evalkit_tf446/lib/python3.10/site-packages/markdown_it/common/html_re.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Regexps to match html elements
|
| 2 |
+
"""
|
| 3 |
+
|
| 4 |
+
import re
|
| 5 |
+
|
| 6 |
+
attr_name = "[a-zA-Z_:][a-zA-Z0-9:._-]*"
|
| 7 |
+
|
| 8 |
+
unquoted = "[^\"'=<>`\\x00-\\x20]+"
|
| 9 |
+
single_quoted = "'[^']*'"
|
| 10 |
+
double_quoted = '"[^"]*"'
|
| 11 |
+
|
| 12 |
+
attr_value = "(?:" + unquoted + "|" + single_quoted + "|" + double_quoted + ")"
|
| 13 |
+
|
| 14 |
+
attribute = "(?:\\s+" + attr_name + "(?:\\s*=\\s*" + attr_value + ")?)"
|
| 15 |
+
|
| 16 |
+
open_tag = "<[A-Za-z][A-Za-z0-9\\-]*" + attribute + "*\\s*\\/?>"
|
| 17 |
+
|
| 18 |
+
close_tag = "<\\/[A-Za-z][A-Za-z0-9\\-]*\\s*>"
|
| 19 |
+
comment = "<!---->|<!--(?:-?[^>-])(?:-?[^-])*-->"
|
| 20 |
+
processing = "<[?][\\s\\S]*?[?]>"
|
| 21 |
+
declaration = "<![A-Z]+\\s+[^>]*>"
|
| 22 |
+
cdata = "<!\\[CDATA\\[[\\s\\S]*?\\]\\]>"
|
| 23 |
+
|
| 24 |
+
HTML_TAG_RE = re.compile(
|
| 25 |
+
"^(?:"
|
| 26 |
+
+ open_tag
|
| 27 |
+
+ "|"
|
| 28 |
+
+ close_tag
|
| 29 |
+
+ "|"
|
| 30 |
+
+ comment
|
| 31 |
+
+ "|"
|
| 32 |
+
+ processing
|
| 33 |
+
+ "|"
|
| 34 |
+
+ declaration
|
| 35 |
+
+ "|"
|
| 36 |
+
+ cdata
|
| 37 |
+
+ ")"
|
| 38 |
+
)
|
| 39 |
+
HTML_OPEN_CLOSE_TAG_STR = "^(?:" + open_tag + "|" + close_tag + ")"
|
| 40 |
+
HTML_OPEN_CLOSE_TAG_RE = re.compile(HTML_OPEN_CLOSE_TAG_STR)
|
evalkit_tf446/lib/python3.10/site-packages/markdown_it/common/normalize_url.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from collections.abc import Callable
|
| 4 |
+
from contextlib import suppress
|
| 5 |
+
import re
|
| 6 |
+
from urllib.parse import quote, unquote, urlparse, urlunparse # noqa: F401
|
| 7 |
+
|
| 8 |
+
import mdurl
|
| 9 |
+
|
| 10 |
+
from .. import _punycode
|
| 11 |
+
|
| 12 |
+
RECODE_HOSTNAME_FOR = ("http:", "https:", "mailto:")
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def normalizeLink(url: str) -> str:
|
| 16 |
+
"""Normalize destination URLs in links
|
| 17 |
+
|
| 18 |
+
::
|
| 19 |
+
|
| 20 |
+
[label]: destination 'title'
|
| 21 |
+
^^^^^^^^^^^
|
| 22 |
+
"""
|
| 23 |
+
parsed = mdurl.parse(url, slashes_denote_host=True)
|
| 24 |
+
|
| 25 |
+
# Encode hostnames in urls like:
|
| 26 |
+
# `http://host/`, `https://host/`, `mailto:user@host`, `//host/`
|
| 27 |
+
#
|
| 28 |
+
# We don't encode unknown schemas, because it's likely that we encode
|
| 29 |
+
# something we shouldn't (e.g. `skype:name` treated as `skype:host`)
|
| 30 |
+
#
|
| 31 |
+
if parsed.hostname and (
|
| 32 |
+
not parsed.protocol or parsed.protocol in RECODE_HOSTNAME_FOR
|
| 33 |
+
):
|
| 34 |
+
with suppress(Exception):
|
| 35 |
+
parsed = parsed._replace(hostname=_punycode.to_ascii(parsed.hostname))
|
| 36 |
+
|
| 37 |
+
return mdurl.encode(mdurl.format(parsed))
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def normalizeLinkText(url: str) -> str:
|
| 41 |
+
"""Normalize autolink content
|
| 42 |
+
|
| 43 |
+
::
|
| 44 |
+
|
| 45 |
+
<destination>
|
| 46 |
+
~~~~~~~~~~~
|
| 47 |
+
"""
|
| 48 |
+
parsed = mdurl.parse(url, slashes_denote_host=True)
|
| 49 |
+
|
| 50 |
+
# Encode hostnames in urls like:
|
| 51 |
+
# `http://host/`, `https://host/`, `mailto:user@host`, `//host/`
|
| 52 |
+
#
|
| 53 |
+
# We don't encode unknown schemas, because it's likely that we encode
|
| 54 |
+
# something we shouldn't (e.g. `skype:name` treated as `skype:host`)
|
| 55 |
+
#
|
| 56 |
+
if parsed.hostname and (
|
| 57 |
+
not parsed.protocol or parsed.protocol in RECODE_HOSTNAME_FOR
|
| 58 |
+
):
|
| 59 |
+
with suppress(Exception):
|
| 60 |
+
parsed = parsed._replace(hostname=_punycode.to_unicode(parsed.hostname))
|
| 61 |
+
|
| 62 |
+
# add '%' to exclude list because of https://github.com/markdown-it/markdown-it/issues/720
|
| 63 |
+
return mdurl.decode(mdurl.format(parsed), mdurl.DECODE_DEFAULT_CHARS + "%")
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
BAD_PROTO_RE = re.compile(r"^(vbscript|javascript|file|data):")
|
| 67 |
+
GOOD_DATA_RE = re.compile(r"^data:image\/(gif|png|jpeg|webp);")
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def validateLink(url: str, validator: Callable[[str], bool] | None = None) -> bool:
|
| 71 |
+
"""Validate URL link is allowed in output.
|
| 72 |
+
|
| 73 |
+
This validator can prohibit more than really needed to prevent XSS.
|
| 74 |
+
It's a tradeoff to keep code simple and to be secure by default.
|
| 75 |
+
|
| 76 |
+
Note: url should be normalized at this point, and existing entities decoded.
|
| 77 |
+
"""
|
| 78 |
+
if validator is not None:
|
| 79 |
+
return validator(url)
|
| 80 |
+
url = url.strip().lower()
|
| 81 |
+
return bool(GOOD_DATA_RE.search(url)) if BAD_PROTO_RE.search(url) else True
|
evalkit_tf446/lib/python3.10/site-packages/markdown_it/common/utils.py
ADDED
|
@@ -0,0 +1,318 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Utilities for parsing source text
|
| 2 |
+
"""
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import re
|
| 6 |
+
from typing import Match, TypeVar
|
| 7 |
+
|
| 8 |
+
from .entities import entities
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def charCodeAt(src: str, pos: int) -> int | None:
|
| 12 |
+
"""
|
| 13 |
+
Returns the Unicode value of the character at the specified location.
|
| 14 |
+
|
| 15 |
+
@param - index The zero-based index of the desired character.
|
| 16 |
+
If there is no character at the specified index, NaN is returned.
|
| 17 |
+
|
| 18 |
+
This was added for compatibility with python
|
| 19 |
+
"""
|
| 20 |
+
try:
|
| 21 |
+
return ord(src[pos])
|
| 22 |
+
except IndexError:
|
| 23 |
+
return None
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def charStrAt(src: str, pos: int) -> str | None:
|
| 27 |
+
"""
|
| 28 |
+
Returns the Unicode value of the character at the specified location.
|
| 29 |
+
|
| 30 |
+
@param - index The zero-based index of the desired character.
|
| 31 |
+
If there is no character at the specified index, NaN is returned.
|
| 32 |
+
|
| 33 |
+
This was added for compatibility with python
|
| 34 |
+
"""
|
| 35 |
+
try:
|
| 36 |
+
return src[pos]
|
| 37 |
+
except IndexError:
|
| 38 |
+
return None
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
_ItemTV = TypeVar("_ItemTV")
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def arrayReplaceAt(
|
| 45 |
+
src: list[_ItemTV], pos: int, newElements: list[_ItemTV]
|
| 46 |
+
) -> list[_ItemTV]:
|
| 47 |
+
"""
|
| 48 |
+
Remove element from array and put another array at those position.
|
| 49 |
+
Useful for some operations with tokens
|
| 50 |
+
"""
|
| 51 |
+
return src[:pos] + newElements + src[pos + 1 :]
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def isValidEntityCode(c: int) -> bool:
|
| 55 |
+
# broken sequence
|
| 56 |
+
if c >= 0xD800 and c <= 0xDFFF:
|
| 57 |
+
return False
|
| 58 |
+
# never used
|
| 59 |
+
if c >= 0xFDD0 and c <= 0xFDEF:
|
| 60 |
+
return False
|
| 61 |
+
if ((c & 0xFFFF) == 0xFFFF) or ((c & 0xFFFF) == 0xFFFE):
|
| 62 |
+
return False
|
| 63 |
+
# control codes
|
| 64 |
+
if c >= 0x00 and c <= 0x08:
|
| 65 |
+
return False
|
| 66 |
+
if c == 0x0B:
|
| 67 |
+
return False
|
| 68 |
+
if c >= 0x0E and c <= 0x1F:
|
| 69 |
+
return False
|
| 70 |
+
if c >= 0x7F and c <= 0x9F:
|
| 71 |
+
return False
|
| 72 |
+
# out of range
|
| 73 |
+
if c > 0x10FFFF:
|
| 74 |
+
return False
|
| 75 |
+
return True
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def fromCodePoint(c: int) -> str:
|
| 79 |
+
"""Convert ordinal to unicode.
|
| 80 |
+
|
| 81 |
+
Note, in the original Javascript two string characters were required,
|
| 82 |
+
for codepoints larger than `0xFFFF`.
|
| 83 |
+
But Python 3 can represent any unicode codepoint in one character.
|
| 84 |
+
"""
|
| 85 |
+
return chr(c)
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
# UNESCAPE_MD_RE = re.compile(r'\\([!"#$%&\'()*+,\-.\/:;<=>?@[\\\]^_`{|}~])')
|
| 89 |
+
# ENTITY_RE_g = re.compile(r'&([a-z#][a-z0-9]{1,31})', re.IGNORECASE)
|
| 90 |
+
UNESCAPE_ALL_RE = re.compile(
|
| 91 |
+
r'\\([!"#$%&\'()*+,\-.\/:;<=>?@[\\\]^_`{|}~])' + "|" + r"&([a-z#][a-z0-9]{1,31});",
|
| 92 |
+
re.IGNORECASE,
|
| 93 |
+
)
|
| 94 |
+
DIGITAL_ENTITY_BASE10_RE = re.compile(r"#([0-9]{1,8})")
|
| 95 |
+
DIGITAL_ENTITY_BASE16_RE = re.compile(r"#x([a-f0-9]{1,8})", re.IGNORECASE)
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
def replaceEntityPattern(match: str, name: str) -> str:
|
| 99 |
+
"""Convert HTML entity patterns,
|
| 100 |
+
see https://spec.commonmark.org/0.30/#entity-references
|
| 101 |
+
"""
|
| 102 |
+
if name in entities:
|
| 103 |
+
return entities[name]
|
| 104 |
+
|
| 105 |
+
code: None | int = None
|
| 106 |
+
if pat := DIGITAL_ENTITY_BASE10_RE.fullmatch(name):
|
| 107 |
+
code = int(pat.group(1), 10)
|
| 108 |
+
elif pat := DIGITAL_ENTITY_BASE16_RE.fullmatch(name):
|
| 109 |
+
code = int(pat.group(1), 16)
|
| 110 |
+
|
| 111 |
+
if code is not None and isValidEntityCode(code):
|
| 112 |
+
return fromCodePoint(code)
|
| 113 |
+
|
| 114 |
+
return match
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
def unescapeAll(string: str) -> str:
|
| 118 |
+
def replacer_func(match: Match[str]) -> str:
|
| 119 |
+
escaped = match.group(1)
|
| 120 |
+
if escaped:
|
| 121 |
+
return escaped
|
| 122 |
+
entity = match.group(2)
|
| 123 |
+
return replaceEntityPattern(match.group(), entity)
|
| 124 |
+
|
| 125 |
+
if "\\" not in string and "&" not in string:
|
| 126 |
+
return string
|
| 127 |
+
return UNESCAPE_ALL_RE.sub(replacer_func, string)
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
ESCAPABLE = r"""\\!"#$%&'()*+,./:;<=>?@\[\]^`{}|_~-"""
|
| 131 |
+
ESCAPE_CHAR = re.compile(r"\\([" + ESCAPABLE + r"])")
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def stripEscape(string: str) -> str:
|
| 135 |
+
"""Strip escape \\ characters"""
|
| 136 |
+
return ESCAPE_CHAR.sub(r"\1", string)
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def escapeHtml(raw: str) -> str:
|
| 140 |
+
"""Replace special characters "&", "<", ">" and '"' to HTML-safe sequences."""
|
| 141 |
+
# like html.escape, but without escaping single quotes
|
| 142 |
+
raw = raw.replace("&", "&") # Must be done first!
|
| 143 |
+
raw = raw.replace("<", "<")
|
| 144 |
+
raw = raw.replace(">", ">")
|
| 145 |
+
raw = raw.replace('"', """)
|
| 146 |
+
return raw
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
# //////////////////////////////////////////////////////////////////////////////
|
| 150 |
+
|
| 151 |
+
REGEXP_ESCAPE_RE = re.compile(r"[.?*+^$[\]\\(){}|-]")
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
def escapeRE(string: str) -> str:
|
| 155 |
+
string = REGEXP_ESCAPE_RE.sub("\\$&", string)
|
| 156 |
+
return string
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
# //////////////////////////////////////////////////////////////////////////////
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
def isSpace(code: int | None) -> bool:
|
| 163 |
+
"""Check if character code is a whitespace."""
|
| 164 |
+
return code in (0x09, 0x20)
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
def isStrSpace(ch: str | None) -> bool:
|
| 168 |
+
"""Check if character is a whitespace."""
|
| 169 |
+
return ch in ("\t", " ")
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
MD_WHITESPACE = {
|
| 173 |
+
0x09, # \t
|
| 174 |
+
0x0A, # \n
|
| 175 |
+
0x0B, # \v
|
| 176 |
+
0x0C, # \f
|
| 177 |
+
0x0D, # \r
|
| 178 |
+
0x20, # space
|
| 179 |
+
0xA0,
|
| 180 |
+
0x1680,
|
| 181 |
+
0x202F,
|
| 182 |
+
0x205F,
|
| 183 |
+
0x3000,
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
def isWhiteSpace(code: int) -> bool:
|
| 188 |
+
r"""Zs (unicode class) || [\t\f\v\r\n]"""
|
| 189 |
+
if code >= 0x2000 and code <= 0x200A:
|
| 190 |
+
return True
|
| 191 |
+
return code in MD_WHITESPACE
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
# //////////////////////////////////////////////////////////////////////////////
|
| 195 |
+
|
| 196 |
+
UNICODE_PUNCT_RE = re.compile(
|
| 197 |
+
r"[!-#%-\*,-\/:;\?@\[-\]_\{\}\xA1\xA7\xAB\xB6\xB7\xBB\xBF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061E\u061F\u066A-\u066D\u06D4\u0700-\u070D\u07F7-\u07F9\u0830-\u083E\u085E\u0964\u0965\u0970\u09FD\u0A76\u0AF0\u0C84\u0DF4\u0E4F\u0E5A\u0E5B\u0F04-\u0F12\u0F14\u0F3A-\u0F3D\u0F85\u0FD0-\u0FD4\u0FD9\u0FDA\u104A-\u104F\u10FB\u1360-\u1368\u1400\u166D\u166E\u169B\u169C\u16EB-\u16ED\u1735\u1736\u17D4-\u17D6\u17D8-\u17DA\u1800-\u180A\u1944\u1945\u1A1E\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B60\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E\u1C7F\u1CC0-\u1CC7\u1CD3\u2010-\u2027\u2030-\u2043\u2045-\u2051\u2053-\u205E\u207D\u207E\u208D\u208E\u2308-\u230B\u2329\u232A\u2768-\u2775\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E4E\u3001-\u3003\u3008-\u3011\u3014-\u301F\u3030\u303D\u30A0\u30FB\uA4FE\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA874-\uA877\uA8CE\uA8CF\uA8F8-\uA8FA\uA8FC\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF\uAA5C-\uAA5F\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE61\uFE63\uFE68\uFE6A\uFE6B\uFF01-\uFF03\uFF05-\uFF0A\uFF0C-\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B-\uFF3D\uFF3F\uFF5B\uFF5D\uFF5F-\uFF65]|\uD800[\uDD00-\uDD02\uDF9F\uDFD0]|\uD801\uDD6F|\uD802[\uDC57\uDD1F\uDD3F\uDE50-\uDE58\uDE7F\uDEF0-\uDEF6\uDF39-\uDF3F\uDF99-\uDF9C]|\uD803[\uDF55-\uDF59]|\uD804[\uDC47-\uDC4D\uDCBB\uDCBC\uDCBE-\uDCC1\uDD40-\uDD43\uDD74\uDD75\uDDC5-\uDDC8\uDDCD\uDDDB\uDDDD-\uDDDF\uDE38-\uDE3D\uDEA9]|\uD805[\uDC4B-\uDC4F\uDC5B\uDC5D\uDCC6\uDDC1-\uDDD7\uDE41-\uDE43\uDE60-\uDE6C\uDF3C-\uDF3E]|\uD806[\uDC3B\uDE3F-\uDE46\uDE9A-\uDE9C\uDE9E-\uDEA2]|\uD807[\uDC41-\uDC45\uDC70\uDC71\uDEF7\uDEF8]|\uD809[\uDC70-\uDC74]|\uD81A[\uDE6E\uDE6F\uDEF5\uDF37-\uDF3B\uDF44]|\uD81B[\uDE97-\uDE9A]|\uD82F\uDC9F|\uD836[\uDE87-\uDE8B]|\uD83A[\uDD5E\uDD5F]" # noqa: E501
|
| 198 |
+
)
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
# Currently without astral characters support.
|
| 202 |
+
def isPunctChar(ch: str) -> bool:
|
| 203 |
+
"""Check if character is a punctuation character."""
|
| 204 |
+
return UNICODE_PUNCT_RE.search(ch) is not None
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
MD_ASCII_PUNCT = {
|
| 208 |
+
0x21, # /* ! */
|
| 209 |
+
0x22, # /* " */
|
| 210 |
+
0x23, # /* # */
|
| 211 |
+
0x24, # /* $ */
|
| 212 |
+
0x25, # /* % */
|
| 213 |
+
0x26, # /* & */
|
| 214 |
+
0x27, # /* ' */
|
| 215 |
+
0x28, # /* ( */
|
| 216 |
+
0x29, # /* ) */
|
| 217 |
+
0x2A, # /* * */
|
| 218 |
+
0x2B, # /* + */
|
| 219 |
+
0x2C, # /* , */
|
| 220 |
+
0x2D, # /* - */
|
| 221 |
+
0x2E, # /* . */
|
| 222 |
+
0x2F, # /* / */
|
| 223 |
+
0x3A, # /* : */
|
| 224 |
+
0x3B, # /* ; */
|
| 225 |
+
0x3C, # /* < */
|
| 226 |
+
0x3D, # /* = */
|
| 227 |
+
0x3E, # /* > */
|
| 228 |
+
0x3F, # /* ? */
|
| 229 |
+
0x40, # /* @ */
|
| 230 |
+
0x5B, # /* [ */
|
| 231 |
+
0x5C, # /* \ */
|
| 232 |
+
0x5D, # /* ] */
|
| 233 |
+
0x5E, # /* ^ */
|
| 234 |
+
0x5F, # /* _ */
|
| 235 |
+
0x60, # /* ` */
|
| 236 |
+
0x7B, # /* { */
|
| 237 |
+
0x7C, # /* | */
|
| 238 |
+
0x7D, # /* } */
|
| 239 |
+
0x7E, # /* ~ */
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
def isMdAsciiPunct(ch: int) -> bool:
|
| 244 |
+
"""Markdown ASCII punctuation characters.
|
| 245 |
+
|
| 246 |
+
::
|
| 247 |
+
|
| 248 |
+
!, ", #, $, %, &, ', (, ), *, +, ,, -, ., /, :, ;, <, =, >, ?, @, [, \\, ], ^, _, `, {, |, }, or ~
|
| 249 |
+
|
| 250 |
+
See http://spec.commonmark.org/0.15/#ascii-punctuation-character
|
| 251 |
+
|
| 252 |
+
Don't confuse with unicode punctuation !!! It lacks some chars in ascii range.
|
| 253 |
+
|
| 254 |
+
""" # noqa: E501
|
| 255 |
+
return ch in MD_ASCII_PUNCT
|
| 256 |
+
|
| 257 |
+
|
| 258 |
+
def normalizeReference(string: str) -> str:
|
| 259 |
+
"""Helper to unify [reference labels]."""
|
| 260 |
+
# Trim and collapse whitespace
|
| 261 |
+
#
|
| 262 |
+
string = re.sub(r"\s+", " ", string.strip())
|
| 263 |
+
|
| 264 |
+
# In node v10 'ẞ'.toLowerCase() === 'Ṿ', which is presumed to be a bug
|
| 265 |
+
# fixed in v12 (couldn't find any details).
|
| 266 |
+
#
|
| 267 |
+
# So treat this one as a special case
|
| 268 |
+
# (remove this when node v10 is no longer supported).
|
| 269 |
+
#
|
| 270 |
+
# if ('ẞ'.toLowerCase() === 'Ṿ') {
|
| 271 |
+
# str = str.replace(/ẞ/g, 'ß')
|
| 272 |
+
# }
|
| 273 |
+
|
| 274 |
+
# .toLowerCase().toUpperCase() should get rid of all differences
|
| 275 |
+
# between letter variants.
|
| 276 |
+
#
|
| 277 |
+
# Simple .toLowerCase() doesn't normalize 125 code points correctly,
|
| 278 |
+
# and .toUpperCase doesn't normalize 6 of them (list of exceptions:
|
| 279 |
+
# İ, ϴ, ẞ, Ω, K, Å - those are already uppercased, but have differently
|
| 280 |
+
# uppercased versions).
|
| 281 |
+
#
|
| 282 |
+
# Here's an example showing how it happens. Lets take greek letter omega:
|
| 283 |
+
# uppercase U+0398 (Θ), U+03f4 (ϴ) and lowercase U+03b8 (θ), U+03d1 (ϑ)
|
| 284 |
+
#
|
| 285 |
+
# Unicode entries:
|
| 286 |
+
# 0398;GREEK CAPITAL LETTER THETA;Lu;0;L;;;;;N;;;;03B8
|
| 287 |
+
# 03B8;GREEK SMALL LETTER THETA;Ll;0;L;;;;;N;;;0398;;0398
|
| 288 |
+
# 03D1;GREEK THETA SYMBOL;Ll;0;L;<compat> 03B8;;;;N;GREEK SMALL LETTER SCRIPT THETA;;0398;;0398
|
| 289 |
+
# 03F4;GREEK CAPITAL THETA SYMBOL;Lu;0;L;<compat> 0398;;;;N;;;;03B8
|
| 290 |
+
#
|
| 291 |
+
# Case-insensitive comparison should treat all of them as equivalent.
|
| 292 |
+
#
|
| 293 |
+
# But .toLowerCase() doesn't change ϑ (it's already lowercase),
|
| 294 |
+
# and .toUpperCase() doesn't change ϴ (already uppercase).
|
| 295 |
+
#
|
| 296 |
+
# Applying first lower then upper case normalizes any character:
|
| 297 |
+
# '\u0398\u03f4\u03b8\u03d1'.toLowerCase().toUpperCase() === '\u0398\u0398\u0398\u0398'
|
| 298 |
+
#
|
| 299 |
+
# Note: this is equivalent to unicode case folding; unicode normalization
|
| 300 |
+
# is a different step that is not required here.
|
| 301 |
+
#
|
| 302 |
+
# Final result should be uppercased, because it's later stored in an object
|
| 303 |
+
# (this avoid a conflict with Object.prototype members,
|
| 304 |
+
# most notably, `__proto__`)
|
| 305 |
+
#
|
| 306 |
+
return string.lower().upper()
|
| 307 |
+
|
| 308 |
+
|
| 309 |
+
LINK_OPEN_RE = re.compile(r"^<a[>\s]", flags=re.IGNORECASE)
|
| 310 |
+
LINK_CLOSE_RE = re.compile(r"^</a\s*>", flags=re.IGNORECASE)
|
| 311 |
+
|
| 312 |
+
|
| 313 |
+
def isLinkOpen(string: str) -> bool:
|
| 314 |
+
return bool(LINK_OPEN_RE.search(string))
|
| 315 |
+
|
| 316 |
+
|
| 317 |
+
def isLinkClose(string: str) -> bool:
|
| 318 |
+
return bool(LINK_CLOSE_RE.search(string))
|
evalkit_tf446/lib/python3.10/site-packages/markdown_it/helpers/__init__.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Functions for parsing Links
|
| 2 |
+
"""
|
| 3 |
+
__all__ = ("parseLinkLabel", "parseLinkDestination", "parseLinkTitle")
|
| 4 |
+
from .parse_link_destination import parseLinkDestination
|
| 5 |
+
from .parse_link_label import parseLinkLabel
|
| 6 |
+
from .parse_link_title import parseLinkTitle
|
evalkit_tf446/lib/python3.10/site-packages/markdown_it/helpers/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (432 Bytes). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/markdown_it/helpers/__pycache__/parse_link_destination.cpython-310.pyc
ADDED
|
Binary file (1.49 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/markdown_it/helpers/__pycache__/parse_link_label.cpython-310.pyc
ADDED
|
Binary file (904 Bytes). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/markdown_it/helpers/__pycache__/parse_link_title.cpython-310.pyc
ADDED
|
Binary file (1.41 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/markdown_it/helpers/parse_link_destination.py
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Parse link destination
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
from ..common.utils import charCodeAt, unescapeAll
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class _Result:
|
| 9 |
+
__slots__ = ("ok", "pos", "lines", "str")
|
| 10 |
+
|
| 11 |
+
def __init__(self) -> None:
|
| 12 |
+
self.ok = False
|
| 13 |
+
self.pos = 0
|
| 14 |
+
self.lines = 0
|
| 15 |
+
self.str = ""
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def parseLinkDestination(string: str, pos: int, maximum: int) -> _Result:
|
| 19 |
+
lines = 0
|
| 20 |
+
start = pos
|
| 21 |
+
result = _Result()
|
| 22 |
+
|
| 23 |
+
if charCodeAt(string, pos) == 0x3C: # /* < */
|
| 24 |
+
pos += 1
|
| 25 |
+
while pos < maximum:
|
| 26 |
+
code = charCodeAt(string, pos)
|
| 27 |
+
if code == 0x0A: # /* \n */)
|
| 28 |
+
return result
|
| 29 |
+
if code == 0x3C: # / * < * /
|
| 30 |
+
return result
|
| 31 |
+
if code == 0x3E: # /* > */) {
|
| 32 |
+
result.pos = pos + 1
|
| 33 |
+
result.str = unescapeAll(string[start + 1 : pos])
|
| 34 |
+
result.ok = True
|
| 35 |
+
return result
|
| 36 |
+
|
| 37 |
+
if code == 0x5C and pos + 1 < maximum: # \
|
| 38 |
+
pos += 2
|
| 39 |
+
continue
|
| 40 |
+
|
| 41 |
+
pos += 1
|
| 42 |
+
|
| 43 |
+
# no closing '>'
|
| 44 |
+
return result
|
| 45 |
+
|
| 46 |
+
# this should be ... } else { ... branch
|
| 47 |
+
|
| 48 |
+
level = 0
|
| 49 |
+
while pos < maximum:
|
| 50 |
+
code = charCodeAt(string, pos)
|
| 51 |
+
|
| 52 |
+
if code is None or code == 0x20:
|
| 53 |
+
break
|
| 54 |
+
|
| 55 |
+
# ascii control characters
|
| 56 |
+
if code < 0x20 or code == 0x7F:
|
| 57 |
+
break
|
| 58 |
+
|
| 59 |
+
if code == 0x5C and pos + 1 < maximum:
|
| 60 |
+
if charCodeAt(string, pos + 1) == 0x20:
|
| 61 |
+
break
|
| 62 |
+
pos += 2
|
| 63 |
+
continue
|
| 64 |
+
|
| 65 |
+
if code == 0x28: # /* ( */)
|
| 66 |
+
level += 1
|
| 67 |
+
if level > 32:
|
| 68 |
+
return result
|
| 69 |
+
|
| 70 |
+
if code == 0x29: # /* ) */)
|
| 71 |
+
if level == 0:
|
| 72 |
+
break
|
| 73 |
+
level -= 1
|
| 74 |
+
|
| 75 |
+
pos += 1
|
| 76 |
+
|
| 77 |
+
if start == pos:
|
| 78 |
+
return result
|
| 79 |
+
if level != 0:
|
| 80 |
+
return result
|
| 81 |
+
|
| 82 |
+
result.str = unescapeAll(string[start:pos])
|
| 83 |
+
result.lines = lines
|
| 84 |
+
result.pos = pos
|
| 85 |
+
result.ok = True
|
| 86 |
+
return result
|
evalkit_tf446/lib/python3.10/site-packages/markdown_it/helpers/parse_link_label.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Parse link label
|
| 3 |
+
|
| 4 |
+
this function assumes that first character ("[") already matches
|
| 5 |
+
returns the end of the label
|
| 6 |
+
|
| 7 |
+
"""
|
| 8 |
+
from markdown_it.rules_inline import StateInline
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def parseLinkLabel(state: StateInline, start: int, disableNested: bool = False) -> int:
|
| 12 |
+
labelEnd = -1
|
| 13 |
+
oldPos = state.pos
|
| 14 |
+
found = False
|
| 15 |
+
|
| 16 |
+
state.pos = start + 1
|
| 17 |
+
level = 1
|
| 18 |
+
|
| 19 |
+
while state.pos < state.posMax:
|
| 20 |
+
marker = state.src[state.pos]
|
| 21 |
+
if marker == "]":
|
| 22 |
+
level -= 1
|
| 23 |
+
if level == 0:
|
| 24 |
+
found = True
|
| 25 |
+
break
|
| 26 |
+
|
| 27 |
+
prevPos = state.pos
|
| 28 |
+
state.md.inline.skipToken(state)
|
| 29 |
+
if marker == "[":
|
| 30 |
+
if prevPos == state.pos - 1:
|
| 31 |
+
# increase level if we find text `[`,
|
| 32 |
+
# which is not a part of any token
|
| 33 |
+
level += 1
|
| 34 |
+
elif disableNested:
|
| 35 |
+
state.pos = oldPos
|
| 36 |
+
return -1
|
| 37 |
+
if found:
|
| 38 |
+
labelEnd = state.pos
|
| 39 |
+
|
| 40 |
+
# restore old state
|
| 41 |
+
state.pos = oldPos
|
| 42 |
+
|
| 43 |
+
return labelEnd
|
evalkit_tf446/lib/python3.10/site-packages/markdown_it/helpers/parse_link_title.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Parse link title
|
| 2 |
+
"""
|
| 3 |
+
from ..common.utils import charCodeAt, unescapeAll
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class _Result:
|
| 7 |
+
__slots__ = ("ok", "pos", "lines", "str")
|
| 8 |
+
|
| 9 |
+
def __init__(self) -> None:
|
| 10 |
+
self.ok = False
|
| 11 |
+
self.pos = 0
|
| 12 |
+
self.lines = 0
|
| 13 |
+
self.str = ""
|
| 14 |
+
|
| 15 |
+
def __str__(self) -> str:
|
| 16 |
+
return self.str
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def parseLinkTitle(string: str, pos: int, maximum: int) -> _Result:
|
| 20 |
+
lines = 0
|
| 21 |
+
start = pos
|
| 22 |
+
result = _Result()
|
| 23 |
+
|
| 24 |
+
if pos >= maximum:
|
| 25 |
+
return result
|
| 26 |
+
|
| 27 |
+
marker = charCodeAt(string, pos)
|
| 28 |
+
|
| 29 |
+
# /* " */ /* ' */ /* ( */
|
| 30 |
+
if marker != 0x22 and marker != 0x27 and marker != 0x28:
|
| 31 |
+
return result
|
| 32 |
+
|
| 33 |
+
pos += 1
|
| 34 |
+
|
| 35 |
+
# if opening marker is "(", switch it to closing marker ")"
|
| 36 |
+
if marker == 0x28:
|
| 37 |
+
marker = 0x29
|
| 38 |
+
|
| 39 |
+
while pos < maximum:
|
| 40 |
+
code = charCodeAt(string, pos)
|
| 41 |
+
if code == marker:
|
| 42 |
+
title = string[start + 1 : pos]
|
| 43 |
+
title = unescapeAll(title)
|
| 44 |
+
result.pos = pos + 1
|
| 45 |
+
result.lines = lines
|
| 46 |
+
result.str = title
|
| 47 |
+
result.ok = True
|
| 48 |
+
return result
|
| 49 |
+
elif code == 0x28 and marker == 0x29: # /* ( */ /* ) */
|
| 50 |
+
return result
|
| 51 |
+
elif code == 0x0A:
|
| 52 |
+
lines += 1
|
| 53 |
+
elif code == 0x5C and pos + 1 < maximum: # /* \ */
|
| 54 |
+
pos += 1
|
| 55 |
+
if charCodeAt(string, pos) == 0x0A:
|
| 56 |
+
lines += 1
|
| 57 |
+
|
| 58 |
+
pos += 1
|
| 59 |
+
|
| 60 |
+
return result
|
evalkit_tf446/lib/python3.10/site-packages/markdown_it/presets/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (1.22 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/markdown_it/presets/__pycache__/default.cpython-310.pyc
ADDED
|
Binary file (602 Bytes). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/markdown_it/presets/__pycache__/zero.cpython-310.pyc
ADDED
|
Binary file (836 Bytes). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/markdown_it/presets/default.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""markdown-it default options."""
|
| 2 |
+
from ..utils import PresetType
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def make() -> PresetType:
|
| 6 |
+
return {
|
| 7 |
+
"options": {
|
| 8 |
+
"maxNesting": 100, # Internal protection, recursion limit
|
| 9 |
+
"html": False, # Enable HTML tags in source
|
| 10 |
+
# this is just a shorthand for .disable(["html_inline", "html_block"])
|
| 11 |
+
# used by the linkify rule:
|
| 12 |
+
"linkify": False, # autoconvert URL-like texts to links
|
| 13 |
+
# used by the replacements and smartquotes rules:
|
| 14 |
+
# Enable some language-neutral replacements + quotes beautification
|
| 15 |
+
"typographer": False,
|
| 16 |
+
# used by the smartquotes rule:
|
| 17 |
+
# Double + single quotes replacement pairs, when typographer enabled,
|
| 18 |
+
# and smartquotes on. Could be either a String or an Array.
|
| 19 |
+
# For example, you can use '«»„“' for Russian, '„“‚‘' for German,
|
| 20 |
+
# and ['«\xA0', '\xA0»', '‹\xA0', '\xA0›'] for French (including nbsp).
|
| 21 |
+
"quotes": "\u201c\u201d\u2018\u2019", # /* “”‘’ */
|
| 22 |
+
# Renderer specific; these options are used directly in the HTML renderer
|
| 23 |
+
"xhtmlOut": False, # Use '/' to close single tags (<br />)
|
| 24 |
+
"breaks": False, # Convert '\n' in paragraphs into <br>
|
| 25 |
+
"langPrefix": "language-", # CSS language prefix for fenced blocks
|
| 26 |
+
# Highlighter function. Should return escaped HTML,
|
| 27 |
+
# or '' if the source string is not changed and should be escaped externally.
|
| 28 |
+
# If result starts with <pre... internal wrapper is skipped.
|
| 29 |
+
#
|
| 30 |
+
# function (/*str, lang, attrs*/) { return ''; }
|
| 31 |
+
#
|
| 32 |
+
"highlight": None,
|
| 33 |
+
},
|
| 34 |
+
"components": {"core": {}, "block": {}, "inline": {}},
|
| 35 |
+
}
|
evalkit_tf446/lib/python3.10/site-packages/markdown_it/rules_block/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (643 Bytes). View file
|
|
|