Upload folder using huggingface_hub
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +886 -0
- README.md +2 -8
- app.py +40 -0
- env-my/Lib/site-packages/MarkupSafe-2.1.5.dist-info/INSTALLER +1 -0
- env-my/Lib/site-packages/MarkupSafe-2.1.5.dist-info/LICENSE.rst +28 -0
- env-my/Lib/site-packages/MarkupSafe-2.1.5.dist-info/METADATA +93 -0
- env-my/Lib/site-packages/MarkupSafe-2.1.5.dist-info/RECORD +14 -0
- env-my/Lib/site-packages/MarkupSafe-2.1.5.dist-info/WHEEL +5 -0
- env-my/Lib/site-packages/MarkupSafe-2.1.5.dist-info/top_level.txt +1 -0
- env-my/Lib/site-packages/OpenSSL/SSL.py +0 -0
- env-my/Lib/site-packages/OpenSSL/__init__.py +31 -0
- env-my/Lib/site-packages/OpenSSL/__pycache__/SSL.cpython-311.pyc +3 -0
- env-my/Lib/site-packages/OpenSSL/__pycache__/__init__.cpython-311.pyc +0 -0
- env-my/Lib/site-packages/OpenSSL/__pycache__/_util.cpython-311.pyc +0 -0
- env-my/Lib/site-packages/OpenSSL/__pycache__/crypto.cpython-311.pyc +3 -0
- env-my/Lib/site-packages/OpenSSL/__pycache__/debug.cpython-311.pyc +0 -0
- env-my/Lib/site-packages/OpenSSL/__pycache__/rand.cpython-311.pyc +0 -0
- env-my/Lib/site-packages/OpenSSL/__pycache__/version.cpython-311.pyc +0 -0
- env-my/Lib/site-packages/OpenSSL/_util.py +129 -0
- env-my/Lib/site-packages/OpenSSL/crypto.py +2450 -0
- env-my/Lib/site-packages/OpenSSL/debug.py +40 -0
- env-my/Lib/site-packages/OpenSSL/py.typed +0 -0
- env-my/Lib/site-packages/OpenSSL/rand.py +50 -0
- env-my/Lib/site-packages/OpenSSL/version.py +28 -0
- env-my/Lib/site-packages/PIL/BdfFontFile.py +133 -0
- env-my/Lib/site-packages/PIL/BlpImagePlugin.py +501 -0
- env-my/Lib/site-packages/PIL/BmpImagePlugin.py +511 -0
- env-my/Lib/site-packages/PIL/BufrStubImagePlugin.py +76 -0
- env-my/Lib/site-packages/PIL/ContainerIO.py +173 -0
- env-my/Lib/site-packages/PIL/CurImagePlugin.py +75 -0
- env-my/Lib/site-packages/PIL/DcxImagePlugin.py +80 -0
- env-my/Lib/site-packages/PIL/DdsImagePlugin.py +573 -0
- env-my/Lib/site-packages/PIL/EpsImagePlugin.py +474 -0
- env-my/Lib/site-packages/PIL/ExifTags.py +382 -0
- env-my/Lib/site-packages/PIL/FitsImagePlugin.py +152 -0
- env-my/Lib/site-packages/PIL/FliImagePlugin.py +175 -0
- env-my/Lib/site-packages/PIL/FontFile.py +134 -0
- env-my/Lib/site-packages/PIL/FpxImagePlugin.py +257 -0
- env-my/Lib/site-packages/PIL/FtexImagePlugin.py +115 -0
- env-my/Lib/site-packages/PIL/GbrImagePlugin.py +103 -0
- env-my/Lib/site-packages/PIL/GdImageFile.py +102 -0
- env-my/Lib/site-packages/PIL/GifImagePlugin.py +1197 -0
- env-my/Lib/site-packages/PIL/GimpGradientFile.py +149 -0
- env-my/Lib/site-packages/PIL/GimpPaletteFile.py +58 -0
- env-my/Lib/site-packages/PIL/GribStubImagePlugin.py +76 -0
- env-my/Lib/site-packages/PIL/Hdf5StubImagePlugin.py +76 -0
- env-my/Lib/site-packages/PIL/IcnsImagePlugin.py +412 -0
- env-my/Lib/site-packages/PIL/IcoImagePlugin.py +381 -0
- env-my/Lib/site-packages/PIL/ImImagePlugin.py +386 -0
- env-my/Lib/site-packages/PIL/Image.py +0 -0
.gitattributes
CHANGED
@@ -33,3 +33,889 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
env-my/Lib/site-packages/__pycache__/typing_extensions.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
37 |
+
env-my/Lib/site-packages/_cffi_backend.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
38 |
+
env-my/Lib/site-packages/_soundfile_data/libsndfile_x64.dll filter=lfs diff=lfs merge=lfs -text
|
39 |
+
env-my/Lib/site-packages/aiortc/codecs/_opus.pyd filter=lfs diff=lfs merge=lfs -text
|
40 |
+
env-my/Lib/site-packages/aiortc/codecs/_vpx.pyd filter=lfs diff=lfs merge=lfs -text
|
41 |
+
env-my/Lib/site-packages/anyio/_backends/__pycache__/_asyncio.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
42 |
+
env-my/Lib/site-packages/attr/__pycache__/_make.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
43 |
+
env-my/Lib/site-packages/av/codec/codec.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
44 |
+
env-my/Lib/site-packages/av/codec/context.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
45 |
+
env-my/Lib/site-packages/av/container/core.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
46 |
+
env-my/Lib/site-packages/av/enum.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
47 |
+
env-my/Lib/site-packages/av/error.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
48 |
+
env-my/Lib/site-packages/av/filter/graph.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
49 |
+
env-my/Lib/site-packages/av/subtitles/subtitle.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
50 |
+
env-my/Lib/site-packages/av/video/frame.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
51 |
+
env-my/Lib/site-packages/av.libs/avcodec-61-3c926997ef7b838d6658f944d666f0a0.dll filter=lfs diff=lfs merge=lfs -text
|
52 |
+
env-my/Lib/site-packages/av.libs/avdevice-61-5a09be817d4d3e931a6c9070d0e66fcd.dll filter=lfs diff=lfs merge=lfs -text
|
53 |
+
env-my/Lib/site-packages/av.libs/avfilter-10-d347a935f6fe047deb200dbacd35fcfe.dll filter=lfs diff=lfs merge=lfs -text
|
54 |
+
env-my/Lib/site-packages/av.libs/avformat-61-7e3d9d0431fa1baee7a991ff2109203d.dll filter=lfs diff=lfs merge=lfs -text
|
55 |
+
env-my/Lib/site-packages/av.libs/avutil-59-70f8ffe8ac277b6087d85b984bc51e11.dll filter=lfs diff=lfs merge=lfs -text
|
56 |
+
env-my/Lib/site-packages/av.libs/libaom-5e90065908eb6d2f6a8c40798bc514d6.dll filter=lfs diff=lfs merge=lfs -text
|
57 |
+
env-my/Lib/site-packages/av.libs/libdav1d-c7c57292adbefe0b58c7267e96d6d922.dll filter=lfs diff=lfs merge=lfs -text
|
58 |
+
env-my/Lib/site-packages/av.libs/libgcc_s_seh-1-9fb94ff927a66e93b622bf66da1e2ece.dll filter=lfs diff=lfs merge=lfs -text
|
59 |
+
env-my/Lib/site-packages/av.libs/libgmp-10-1bd605d4a46f0380bd6ece50ba97a1e5.dll filter=lfs diff=lfs merge=lfs -text
|
60 |
+
env-my/Lib/site-packages/av.libs/libiconv-2-d03044ea6afd647513bf2998aa39653e.dll filter=lfs diff=lfs merge=lfs -text
|
61 |
+
env-my/Lib/site-packages/av.libs/liblzma-5-40d1fda73b3fae2659aa4bf4a24dc0b8.dll filter=lfs diff=lfs merge=lfs -text
|
62 |
+
env-my/Lib/site-packages/av.libs/libmp3lame-0-48443ec6fda1d4133a2ac5f8b8505339.dll filter=lfs diff=lfs merge=lfs -text
|
63 |
+
env-my/Lib/site-packages/av.libs/libopencore-amrnb-0-d960f0e8070798ab280cfbfc2161cd4c.dll filter=lfs diff=lfs merge=lfs -text
|
64 |
+
env-my/Lib/site-packages/av.libs/libopus-0-eb4d5bd001a8df9a515d8a3838e38ee5.dll filter=lfs diff=lfs merge=lfs -text
|
65 |
+
env-my/Lib/site-packages/av.libs/libspeex-1-8d636ed2142824dc6f110722692317d7.dll filter=lfs diff=lfs merge=lfs -text
|
66 |
+
env-my/Lib/site-packages/av.libs/libstdc++-6-056095c89789a85456c32a6a309789e0.dll filter=lfs diff=lfs merge=lfs -text
|
67 |
+
env-my/Lib/site-packages/av.libs/libtwolame-0-e913c957c84e7e2a8dd203857998be88.dll filter=lfs diff=lfs merge=lfs -text
|
68 |
+
env-my/Lib/site-packages/av.libs/libvorbis-0-097cc4e549a524929f0100069d5825b8.dll filter=lfs diff=lfs merge=lfs -text
|
69 |
+
env-my/Lib/site-packages/av.libs/libvorbisenc-2-22e86a86dac0f7037b6102e7751faa06.dll filter=lfs diff=lfs merge=lfs -text
|
70 |
+
env-my/Lib/site-packages/av.libs/libvpx-1-61f5f374c0e239aedc48618080a7d66f.dll filter=lfs diff=lfs merge=lfs -text
|
71 |
+
env-my/Lib/site-packages/av.libs/libwebp-a60709b1fe906689092029d8cebeddeb.dll filter=lfs diff=lfs merge=lfs -text
|
72 |
+
env-my/Lib/site-packages/av.libs/libx264-164-64ce4e560d0a7e0738ca6e6278a50586.dll filter=lfs diff=lfs merge=lfs -text
|
73 |
+
env-my/Lib/site-packages/av.libs/libx265-344def47becc7fea5a64ae3f6a986ffc.dll filter=lfs diff=lfs merge=lfs -text
|
74 |
+
env-my/Lib/site-packages/av.libs/libxml2-2-70f0fd657b05868f7159ec41834ff479.dll filter=lfs diff=lfs merge=lfs -text
|
75 |
+
env-my/Lib/site-packages/av.libs/swresample-5-0abf3649d3c0372ebed358a22305ca62.dll filter=lfs diff=lfs merge=lfs -text
|
76 |
+
env-my/Lib/site-packages/av.libs/swscale-8-da6efb72d73a9b29a33254aabc508534.dll filter=lfs diff=lfs merge=lfs -text
|
77 |
+
env-my/Lib/site-packages/av.libs/zlib1-3ddaf78385a6fc37326ef2bc962736db.dll filter=lfs diff=lfs merge=lfs -text
|
78 |
+
env-my/Lib/site-packages/babel/global.dat filter=lfs diff=lfs merge=lfs -text
|
79 |
+
env-my/Lib/site-packages/babel/locale-data/af.dat filter=lfs diff=lfs merge=lfs -text
|
80 |
+
env-my/Lib/site-packages/babel/locale-data/ak.dat filter=lfs diff=lfs merge=lfs -text
|
81 |
+
env-my/Lib/site-packages/babel/locale-data/am.dat filter=lfs diff=lfs merge=lfs -text
|
82 |
+
env-my/Lib/site-packages/babel/locale-data/ar.dat filter=lfs diff=lfs merge=lfs -text
|
83 |
+
env-my/Lib/site-packages/babel/locale-data/as.dat filter=lfs diff=lfs merge=lfs -text
|
84 |
+
env-my/Lib/site-packages/babel/locale-data/ast.dat filter=lfs diff=lfs merge=lfs -text
|
85 |
+
env-my/Lib/site-packages/babel/locale-data/az.dat filter=lfs diff=lfs merge=lfs -text
|
86 |
+
env-my/Lib/site-packages/babel/locale-data/bal_Latn.dat filter=lfs diff=lfs merge=lfs -text
|
87 |
+
env-my/Lib/site-packages/babel/locale-data/be.dat filter=lfs diff=lfs merge=lfs -text
|
88 |
+
env-my/Lib/site-packages/babel/locale-data/be_TARASK.dat filter=lfs diff=lfs merge=lfs -text
|
89 |
+
env-my/Lib/site-packages/babel/locale-data/bew.dat filter=lfs diff=lfs merge=lfs -text
|
90 |
+
env-my/Lib/site-packages/babel/locale-data/bg.dat filter=lfs diff=lfs merge=lfs -text
|
91 |
+
env-my/Lib/site-packages/babel/locale-data/blo.dat filter=lfs diff=lfs merge=lfs -text
|
92 |
+
env-my/Lib/site-packages/babel/locale-data/bn.dat filter=lfs diff=lfs merge=lfs -text
|
93 |
+
env-my/Lib/site-packages/babel/locale-data/br.dat filter=lfs diff=lfs merge=lfs -text
|
94 |
+
env-my/Lib/site-packages/babel/locale-data/brx.dat filter=lfs diff=lfs merge=lfs -text
|
95 |
+
env-my/Lib/site-packages/babel/locale-data/bs.dat filter=lfs diff=lfs merge=lfs -text
|
96 |
+
env-my/Lib/site-packages/babel/locale-data/bs_Cyrl.dat filter=lfs diff=lfs merge=lfs -text
|
97 |
+
env-my/Lib/site-packages/babel/locale-data/ca.dat filter=lfs diff=lfs merge=lfs -text
|
98 |
+
env-my/Lib/site-packages/babel/locale-data/ccp.dat filter=lfs diff=lfs merge=lfs -text
|
99 |
+
env-my/Lib/site-packages/babel/locale-data/ce.dat filter=lfs diff=lfs merge=lfs -text
|
100 |
+
env-my/Lib/site-packages/babel/locale-data/ceb.dat filter=lfs diff=lfs merge=lfs -text
|
101 |
+
env-my/Lib/site-packages/babel/locale-data/chr.dat filter=lfs diff=lfs merge=lfs -text
|
102 |
+
env-my/Lib/site-packages/babel/locale-data/cs.dat filter=lfs diff=lfs merge=lfs -text
|
103 |
+
env-my/Lib/site-packages/babel/locale-data/cv.dat filter=lfs diff=lfs merge=lfs -text
|
104 |
+
env-my/Lib/site-packages/babel/locale-data/cy.dat filter=lfs diff=lfs merge=lfs -text
|
105 |
+
env-my/Lib/site-packages/babel/locale-data/da.dat filter=lfs diff=lfs merge=lfs -text
|
106 |
+
env-my/Lib/site-packages/babel/locale-data/de.dat filter=lfs diff=lfs merge=lfs -text
|
107 |
+
env-my/Lib/site-packages/babel/locale-data/dsb.dat filter=lfs diff=lfs merge=lfs -text
|
108 |
+
env-my/Lib/site-packages/babel/locale-data/el.dat filter=lfs diff=lfs merge=lfs -text
|
109 |
+
env-my/Lib/site-packages/babel/locale-data/en.dat filter=lfs diff=lfs merge=lfs -text
|
110 |
+
env-my/Lib/site-packages/babel/locale-data/eo.dat filter=lfs diff=lfs merge=lfs -text
|
111 |
+
env-my/Lib/site-packages/babel/locale-data/es.dat filter=lfs diff=lfs merge=lfs -text
|
112 |
+
env-my/Lib/site-packages/babel/locale-data/et.dat filter=lfs diff=lfs merge=lfs -text
|
113 |
+
env-my/Lib/site-packages/babel/locale-data/eu.dat filter=lfs diff=lfs merge=lfs -text
|
114 |
+
env-my/Lib/site-packages/babel/locale-data/fa.dat filter=lfs diff=lfs merge=lfs -text
|
115 |
+
env-my/Lib/site-packages/babel/locale-data/ff_Adlm.dat filter=lfs diff=lfs merge=lfs -text
|
116 |
+
env-my/Lib/site-packages/babel/locale-data/fi.dat filter=lfs diff=lfs merge=lfs -text
|
117 |
+
env-my/Lib/site-packages/babel/locale-data/fil.dat filter=lfs diff=lfs merge=lfs -text
|
118 |
+
env-my/Lib/site-packages/babel/locale-data/fo.dat filter=lfs diff=lfs merge=lfs -text
|
119 |
+
env-my/Lib/site-packages/babel/locale-data/fr.dat filter=lfs diff=lfs merge=lfs -text
|
120 |
+
env-my/Lib/site-packages/babel/locale-data/frr.dat filter=lfs diff=lfs merge=lfs -text
|
121 |
+
env-my/Lib/site-packages/babel/locale-data/fy.dat filter=lfs diff=lfs merge=lfs -text
|
122 |
+
env-my/Lib/site-packages/babel/locale-data/ga.dat filter=lfs diff=lfs merge=lfs -text
|
123 |
+
env-my/Lib/site-packages/babel/locale-data/gd.dat filter=lfs diff=lfs merge=lfs -text
|
124 |
+
env-my/Lib/site-packages/babel/locale-data/gl.dat filter=lfs diff=lfs merge=lfs -text
|
125 |
+
env-my/Lib/site-packages/babel/locale-data/gu.dat filter=lfs diff=lfs merge=lfs -text
|
126 |
+
env-my/Lib/site-packages/babel/locale-data/ha.dat filter=lfs diff=lfs merge=lfs -text
|
127 |
+
env-my/Lib/site-packages/babel/locale-data/he.dat filter=lfs diff=lfs merge=lfs -text
|
128 |
+
env-my/Lib/site-packages/babel/locale-data/hi.dat filter=lfs diff=lfs merge=lfs -text
|
129 |
+
env-my/Lib/site-packages/babel/locale-data/hr.dat filter=lfs diff=lfs merge=lfs -text
|
130 |
+
env-my/Lib/site-packages/babel/locale-data/hsb.dat filter=lfs diff=lfs merge=lfs -text
|
131 |
+
env-my/Lib/site-packages/babel/locale-data/hu.dat filter=lfs diff=lfs merge=lfs -text
|
132 |
+
env-my/Lib/site-packages/babel/locale-data/hy.dat filter=lfs diff=lfs merge=lfs -text
|
133 |
+
env-my/Lib/site-packages/babel/locale-data/ia.dat filter=lfs diff=lfs merge=lfs -text
|
134 |
+
env-my/Lib/site-packages/babel/locale-data/id.dat filter=lfs diff=lfs merge=lfs -text
|
135 |
+
env-my/Lib/site-packages/babel/locale-data/is.dat filter=lfs diff=lfs merge=lfs -text
|
136 |
+
env-my/Lib/site-packages/babel/locale-data/it.dat filter=lfs diff=lfs merge=lfs -text
|
137 |
+
env-my/Lib/site-packages/babel/locale-data/ja.dat filter=lfs diff=lfs merge=lfs -text
|
138 |
+
env-my/Lib/site-packages/babel/locale-data/jv.dat filter=lfs diff=lfs merge=lfs -text
|
139 |
+
env-my/Lib/site-packages/babel/locale-data/ka.dat filter=lfs diff=lfs merge=lfs -text
|
140 |
+
env-my/Lib/site-packages/babel/locale-data/kab.dat filter=lfs diff=lfs merge=lfs -text
|
141 |
+
env-my/Lib/site-packages/babel/locale-data/kgp.dat filter=lfs diff=lfs merge=lfs -text
|
142 |
+
env-my/Lib/site-packages/babel/locale-data/kk.dat filter=lfs diff=lfs merge=lfs -text
|
143 |
+
env-my/Lib/site-packages/babel/locale-data/kk_Arab.dat filter=lfs diff=lfs merge=lfs -text
|
144 |
+
env-my/Lib/site-packages/babel/locale-data/km.dat filter=lfs diff=lfs merge=lfs -text
|
145 |
+
env-my/Lib/site-packages/babel/locale-data/kn.dat filter=lfs diff=lfs merge=lfs -text
|
146 |
+
env-my/Lib/site-packages/babel/locale-data/ko.dat filter=lfs diff=lfs merge=lfs -text
|
147 |
+
env-my/Lib/site-packages/babel/locale-data/kok.dat filter=lfs diff=lfs merge=lfs -text
|
148 |
+
env-my/Lib/site-packages/babel/locale-data/ks.dat filter=lfs diff=lfs merge=lfs -text
|
149 |
+
env-my/Lib/site-packages/babel/locale-data/ku.dat filter=lfs diff=lfs merge=lfs -text
|
150 |
+
env-my/Lib/site-packages/babel/locale-data/ky.dat filter=lfs diff=lfs merge=lfs -text
|
151 |
+
env-my/Lib/site-packages/babel/locale-data/lb.dat filter=lfs diff=lfs merge=lfs -text
|
152 |
+
env-my/Lib/site-packages/babel/locale-data/lij.dat filter=lfs diff=lfs merge=lfs -text
|
153 |
+
env-my/Lib/site-packages/babel/locale-data/lo.dat filter=lfs diff=lfs merge=lfs -text
|
154 |
+
env-my/Lib/site-packages/babel/locale-data/lt.dat filter=lfs diff=lfs merge=lfs -text
|
155 |
+
env-my/Lib/site-packages/babel/locale-data/lv.dat filter=lfs diff=lfs merge=lfs -text
|
156 |
+
env-my/Lib/site-packages/babel/locale-data/mk.dat filter=lfs diff=lfs merge=lfs -text
|
157 |
+
env-my/Lib/site-packages/babel/locale-data/ml.dat filter=lfs diff=lfs merge=lfs -text
|
158 |
+
env-my/Lib/site-packages/babel/locale-data/mn.dat filter=lfs diff=lfs merge=lfs -text
|
159 |
+
env-my/Lib/site-packages/babel/locale-data/mr.dat filter=lfs diff=lfs merge=lfs -text
|
160 |
+
env-my/Lib/site-packages/babel/locale-data/ms.dat filter=lfs diff=lfs merge=lfs -text
|
161 |
+
env-my/Lib/site-packages/babel/locale-data/my.dat filter=lfs diff=lfs merge=lfs -text
|
162 |
+
env-my/Lib/site-packages/babel/locale-data/ne.dat filter=lfs diff=lfs merge=lfs -text
|
163 |
+
env-my/Lib/site-packages/babel/locale-data/nl.dat filter=lfs diff=lfs merge=lfs -text
|
164 |
+
env-my/Lib/site-packages/babel/locale-data/no.dat filter=lfs diff=lfs merge=lfs -text
|
165 |
+
env-my/Lib/site-packages/babel/locale-data/nqo.dat filter=lfs diff=lfs merge=lfs -text
|
166 |
+
env-my/Lib/site-packages/babel/locale-data/or.dat filter=lfs diff=lfs merge=lfs -text
|
167 |
+
env-my/Lib/site-packages/babel/locale-data/pa.dat filter=lfs diff=lfs merge=lfs -text
|
168 |
+
env-my/Lib/site-packages/babel/locale-data/pcm.dat filter=lfs diff=lfs merge=lfs -text
|
169 |
+
env-my/Lib/site-packages/babel/locale-data/pl.dat filter=lfs diff=lfs merge=lfs -text
|
170 |
+
env-my/Lib/site-packages/babel/locale-data/ps.dat filter=lfs diff=lfs merge=lfs -text
|
171 |
+
env-my/Lib/site-packages/babel/locale-data/pt.dat filter=lfs diff=lfs merge=lfs -text
|
172 |
+
env-my/Lib/site-packages/babel/locale-data/ro.dat filter=lfs diff=lfs merge=lfs -text
|
173 |
+
env-my/Lib/site-packages/babel/locale-data/ru.dat filter=lfs diff=lfs merge=lfs -text
|
174 |
+
env-my/Lib/site-packages/babel/locale-data/sc.dat filter=lfs diff=lfs merge=lfs -text
|
175 |
+
env-my/Lib/site-packages/babel/locale-data/sd.dat filter=lfs diff=lfs merge=lfs -text
|
176 |
+
env-my/Lib/site-packages/babel/locale-data/si.dat filter=lfs diff=lfs merge=lfs -text
|
177 |
+
env-my/Lib/site-packages/babel/locale-data/sk.dat filter=lfs diff=lfs merge=lfs -text
|
178 |
+
env-my/Lib/site-packages/babel/locale-data/sl.dat filter=lfs diff=lfs merge=lfs -text
|
179 |
+
env-my/Lib/site-packages/babel/locale-data/so.dat filter=lfs diff=lfs merge=lfs -text
|
180 |
+
env-my/Lib/site-packages/babel/locale-data/sq.dat filter=lfs diff=lfs merge=lfs -text
|
181 |
+
env-my/Lib/site-packages/babel/locale-data/sr.dat filter=lfs diff=lfs merge=lfs -text
|
182 |
+
env-my/Lib/site-packages/babel/locale-data/sr_Latn.dat filter=lfs diff=lfs merge=lfs -text
|
183 |
+
env-my/Lib/site-packages/babel/locale-data/sv.dat filter=lfs diff=lfs merge=lfs -text
|
184 |
+
env-my/Lib/site-packages/babel/locale-data/sw.dat filter=lfs diff=lfs merge=lfs -text
|
185 |
+
env-my/Lib/site-packages/babel/locale-data/syr.dat filter=lfs diff=lfs merge=lfs -text
|
186 |
+
env-my/Lib/site-packages/babel/locale-data/ta.dat filter=lfs diff=lfs merge=lfs -text
|
187 |
+
env-my/Lib/site-packages/babel/locale-data/te.dat filter=lfs diff=lfs merge=lfs -text
|
188 |
+
env-my/Lib/site-packages/babel/locale-data/tg.dat filter=lfs diff=lfs merge=lfs -text
|
189 |
+
env-my/Lib/site-packages/babel/locale-data/th.dat filter=lfs diff=lfs merge=lfs -text
|
190 |
+
env-my/Lib/site-packages/babel/locale-data/ti.dat filter=lfs diff=lfs merge=lfs -text
|
191 |
+
env-my/Lib/site-packages/babel/locale-data/tk.dat filter=lfs diff=lfs merge=lfs -text
|
192 |
+
env-my/Lib/site-packages/babel/locale-data/to.dat filter=lfs diff=lfs merge=lfs -text
|
193 |
+
env-my/Lib/site-packages/babel/locale-data/tr.dat filter=lfs diff=lfs merge=lfs -text
|
194 |
+
env-my/Lib/site-packages/babel/locale-data/trw.dat filter=lfs diff=lfs merge=lfs -text
|
195 |
+
env-my/Lib/site-packages/babel/locale-data/tt.dat filter=lfs diff=lfs merge=lfs -text
|
196 |
+
env-my/Lib/site-packages/babel/locale-data/ug.dat filter=lfs diff=lfs merge=lfs -text
|
197 |
+
env-my/Lib/site-packages/babel/locale-data/uk.dat filter=lfs diff=lfs merge=lfs -text
|
198 |
+
env-my/Lib/site-packages/babel/locale-data/ur.dat filter=lfs diff=lfs merge=lfs -text
|
199 |
+
env-my/Lib/site-packages/babel/locale-data/uz.dat filter=lfs diff=lfs merge=lfs -text
|
200 |
+
env-my/Lib/site-packages/babel/locale-data/vec.dat filter=lfs diff=lfs merge=lfs -text
|
201 |
+
env-my/Lib/site-packages/babel/locale-data/vi.dat filter=lfs diff=lfs merge=lfs -text
|
202 |
+
env-my/Lib/site-packages/babel/locale-data/xnr.dat filter=lfs diff=lfs merge=lfs -text
|
203 |
+
env-my/Lib/site-packages/babel/locale-data/yo.dat filter=lfs diff=lfs merge=lfs -text
|
204 |
+
env-my/Lib/site-packages/babel/locale-data/yrl.dat filter=lfs diff=lfs merge=lfs -text
|
205 |
+
env-my/Lib/site-packages/babel/locale-data/yue.dat filter=lfs diff=lfs merge=lfs -text
|
206 |
+
env-my/Lib/site-packages/babel/locale-data/yue_Hans.dat filter=lfs diff=lfs merge=lfs -text
|
207 |
+
env-my/Lib/site-packages/babel/locale-data/zh.dat filter=lfs diff=lfs merge=lfs -text
|
208 |
+
env-my/Lib/site-packages/babel/locale-data/zh_Hant.dat filter=lfs diff=lfs merge=lfs -text
|
209 |
+
env-my/Lib/site-packages/babel/locale-data/zu.dat filter=lfs diff=lfs merge=lfs -text
|
210 |
+
env-my/Lib/site-packages/charset_normalizer/md__mypyc.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
211 |
+
env-my/Lib/site-packages/click/__pycache__/core.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
212 |
+
env-my/Lib/site-packages/cryptography/hazmat/bindings/_rust.pyd filter=lfs diff=lfs merge=lfs -text
|
213 |
+
env-my/Lib/site-packages/cryptography/x509/__pycache__/extensions.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
214 |
+
env-my/Lib/site-packages/csvw/__pycache__/metadata.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
215 |
+
env-my/Lib/site-packages/espeakng_loader/espeak-ng-data/af_dict filter=lfs diff=lfs merge=lfs -text
|
216 |
+
env-my/Lib/site-packages/espeakng_loader/espeak-ng-data/ar_dict filter=lfs diff=lfs merge=lfs -text
|
217 |
+
env-my/Lib/site-packages/espeakng_loader/espeak-ng-data/ca_dict filter=lfs diff=lfs merge=lfs -text
|
218 |
+
env-my/Lib/site-packages/espeakng_loader/espeak-ng-data/cmn_dict filter=lfs diff=lfs merge=lfs -text
|
219 |
+
env-my/Lib/site-packages/espeakng_loader/espeak-ng-data/da_dict filter=lfs diff=lfs merge=lfs -text
|
220 |
+
env-my/Lib/site-packages/espeakng_loader/espeak-ng-data/en_dict filter=lfs diff=lfs merge=lfs -text
|
221 |
+
env-my/Lib/site-packages/espeakng_loader/espeak-ng-data/fa_dict filter=lfs diff=lfs merge=lfs -text
|
222 |
+
env-my/Lib/site-packages/espeakng_loader/espeak-ng-data/hu_dict filter=lfs diff=lfs merge=lfs -text
|
223 |
+
env-my/Lib/site-packages/espeakng_loader/espeak-ng-data/ia_dict filter=lfs diff=lfs merge=lfs -text
|
224 |
+
env-my/Lib/site-packages/espeakng_loader/espeak-ng-data/it_dict filter=lfs diff=lfs merge=lfs -text
|
225 |
+
env-my/Lib/site-packages/espeakng_loader/espeak-ng-data/lb_dict filter=lfs diff=lfs merge=lfs -text
|
226 |
+
env-my/Lib/site-packages/espeakng_loader/espeak-ng-data/phondata filter=lfs diff=lfs merge=lfs -text
|
227 |
+
env-my/Lib/site-packages/espeakng_loader/espeak-ng-data/ru_dict filter=lfs diff=lfs merge=lfs -text
|
228 |
+
env-my/Lib/site-packages/espeakng_loader/espeak-ng-data/ta_dict filter=lfs diff=lfs merge=lfs -text
|
229 |
+
env-my/Lib/site-packages/espeakng_loader/espeak-ng-data/ur_dict filter=lfs diff=lfs merge=lfs -text
|
230 |
+
env-my/Lib/site-packages/espeakng_loader/espeak-ng-data/yue_dict filter=lfs diff=lfs merge=lfs -text
|
231 |
+
env-my/Lib/site-packages/espeakng_loader/espeak-ng.dll filter=lfs diff=lfs merge=lfs -text
|
232 |
+
env-my/Lib/site-packages/fastrtc/speech_to_text/test_file.wav filter=lfs diff=lfs merge=lfs -text
|
233 |
+
env-my/Lib/site-packages/fsspec/__pycache__/spec.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
234 |
+
env-my/Lib/site-packages/future/backports/email/__pycache__/_header_value_parser.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
235 |
+
env-my/Lib/site-packages/future/backports/urllib/__pycache__/request.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
236 |
+
env-my/Lib/site-packages/google/_upb/_message.pyd filter=lfs diff=lfs merge=lfs -text
|
237 |
+
env-my/Lib/site-packages/google/protobuf/__pycache__/descriptor_pb2.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
238 |
+
env-my/Lib/site-packages/gradio/__pycache__/blocks.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
239 |
+
env-my/Lib/site-packages/gradio/_frontend_code/lite/dist/assets/Canvas3D-BNUzHJMJ.js.map filter=lfs diff=lfs merge=lfs -text
|
240 |
+
env-my/Lib/site-packages/gradio/_frontend_code/lite/dist/assets/gradio-5.20.0-py3-none-any.whl filter=lfs diff=lfs merge=lfs -text
|
241 |
+
env-my/Lib/site-packages/gradio/_frontend_code/lite/dist/assets/gradio_client-1.7.2-py3-none-any.whl filter=lfs diff=lfs merge=lfs -text
|
242 |
+
env-my/Lib/site-packages/gradio/_frontend_code/lite/dist/assets/PlotlyPlot-CQtop1ne.js.map filter=lfs diff=lfs merge=lfs -text
|
243 |
+
env-my/Lib/site-packages/gradio/templates/frontend/assets/Canvas3D-CqTCFfIE.js.map filter=lfs diff=lfs merge=lfs -text
|
244 |
+
env-my/Lib/site-packages/gradio/templates/frontend/assets/PlotlyPlot-CkFocwz_.js.map filter=lfs diff=lfs merge=lfs -text
|
245 |
+
env-my/Lib/site-packages/gradio/templates/frontend/static/fonts/Source[[:space:]]Sans[[:space:]]Pro/SourceSansPro-Bold.woff2 filter=lfs diff=lfs merge=lfs -text
|
246 |
+
env-my/Lib/site-packages/gradio/templates/frontend/static/fonts/Source[[:space:]]Sans[[:space:]]Pro/SourceSansPro-Regular.woff2 filter=lfs diff=lfs merge=lfs -text
|
247 |
+
env-my/Lib/site-packages/gradio/templates/frontend/static/img/Duck.glb filter=lfs diff=lfs merge=lfs -text
|
248 |
+
env-my/Lib/site-packages/gradio/templates/node/build/client/_app/immutable/chunks/2.DuStuoiw.js.br filter=lfs diff=lfs merge=lfs -text
|
249 |
+
env-my/Lib/site-packages/gradio/templates/node/build/client/_app/immutable/chunks/AltairPlot.CX_5tlTi.js.br filter=lfs diff=lfs merge=lfs -text
|
250 |
+
env-my/Lib/site-packages/gradio/templates/node/build/client/_app/immutable/chunks/Canvas3D.FxhYMTVq.js.br filter=lfs diff=lfs merge=lfs -text
|
251 |
+
env-my/Lib/site-packages/gradio/templates/node/build/client/_app/immutable/chunks/hls.CFPBCiRi.js.br filter=lfs diff=lfs merge=lfs -text
|
252 |
+
env-my/Lib/site-packages/gradio/templates/node/build/client/_app/immutable/chunks/Index.BT4Fv832.js.br filter=lfs diff=lfs merge=lfs -text
|
253 |
+
env-my/Lib/site-packages/gradio/templates/node/build/client/_app/immutable/chunks/Index.C2l9MfZ5.js.br filter=lfs diff=lfs merge=lfs -text
|
254 |
+
env-my/Lib/site-packages/gradio/templates/node/build/client/_app/immutable/chunks/PlotlyPlot.dANaICVF.js.br filter=lfs diff=lfs merge=lfs -text
|
255 |
+
env-my/Lib/site-packages/gradio/templates/node/build/client/_app/immutable/chunks/vega-embed.module.CVnlDOx4.js.br filter=lfs diff=lfs merge=lfs -text
|
256 |
+
env-my/Lib/site-packages/gradio/templates/node/build/client/_app/immutable/chunks/vega-tooltip.module.TMyZC--t.js.br filter=lfs diff=lfs merge=lfs -text
|
257 |
+
env-my/Lib/site-packages/gradio/templates/node/build/server/chunks/Canvas3D-BIHptgsp.js.map filter=lfs diff=lfs merge=lfs -text
|
258 |
+
env-my/Lib/site-packages/gradio/templates/node/build/server/chunks/PlotlyPlot-CCSoSx2P.js.map filter=lfs diff=lfs merge=lfs -text
|
259 |
+
env-my/Lib/site-packages/gradio_client/__pycache__/media_data.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
260 |
+
env-my/Lib/site-packages/huggingface_hub/__pycache__/hf_api.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
261 |
+
env-my/Lib/site-packages/huggingface_hub/inference/__pycache__/_client.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
262 |
+
env-my/Lib/site-packages/huggingface_hub/inference/_generated/__pycache__/_async_client.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
263 |
+
env-my/Lib/site-packages/humanfriendly/__pycache__/tests.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
264 |
+
env-my/Lib/site-packages/idna/__pycache__/idnadata.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
265 |
+
env-my/Lib/site-packages/idna/__pycache__/uts46data.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
266 |
+
env-my/Lib/site-packages/jinja2/__pycache__/compiler.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
267 |
+
env-my/Lib/site-packages/jiter/jiter.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
268 |
+
env-my/Lib/site-packages/joblib/test/__pycache__/test_parallel.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
269 |
+
env-my/Lib/site-packages/jsonschema/tests/__pycache__/test_validators.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
270 |
+
env-my/Lib/site-packages/librosa/core/__pycache__/audio._zc_wrapper-1158.py311.1.nbc filter=lfs diff=lfs merge=lfs -text
|
271 |
+
env-my/Lib/site-packages/librosa/core/__pycache__/audio._zc_wrapper-1158.py311.2.nbc filter=lfs diff=lfs merge=lfs -text
|
272 |
+
env-my/Lib/site-packages/librosa/core/__pycache__/guf-audio._zc_wrapper-1158.py311.1.nbc filter=lfs diff=lfs merge=lfs -text
|
273 |
+
env-my/Lib/site-packages/librosa/core/__pycache__/guf-audio._zc_wrapper-1158.py311.2.nbc filter=lfs diff=lfs merge=lfs -text
|
274 |
+
env-my/Lib/site-packages/librosa/core/__pycache__/spectrum.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
275 |
+
env-my/Lib/site-packages/librosa/util/__pycache__/guf-utils._localmax-1051.py311.1.nbc filter=lfs diff=lfs merge=lfs -text
|
276 |
+
env-my/Lib/site-packages/librosa/util/__pycache__/guf-utils._localmax-1051.py311.2.nbc filter=lfs diff=lfs merge=lfs -text
|
277 |
+
env-my/Lib/site-packages/librosa/util/__pycache__/guf-utils._localmax-1051.py311.3.nbc filter=lfs diff=lfs merge=lfs -text
|
278 |
+
env-my/Lib/site-packages/librosa/util/__pycache__/guf-utils._localmax-1051.py311.4.nbc filter=lfs diff=lfs merge=lfs -text
|
279 |
+
env-my/Lib/site-packages/librosa/util/__pycache__/guf-utils._localmax-1051.py311.5.nbc filter=lfs diff=lfs merge=lfs -text
|
280 |
+
env-my/Lib/site-packages/librosa/util/__pycache__/guf-utils._localmin-1068.py311.1.nbc filter=lfs diff=lfs merge=lfs -text
|
281 |
+
env-my/Lib/site-packages/librosa/util/__pycache__/guf-utils._localmin-1068.py311.2.nbc filter=lfs diff=lfs merge=lfs -text
|
282 |
+
env-my/Lib/site-packages/librosa/util/__pycache__/guf-utils._localmin-1068.py311.3.nbc filter=lfs diff=lfs merge=lfs -text
|
283 |
+
env-my/Lib/site-packages/librosa/util/__pycache__/guf-utils._localmin-1068.py311.4.nbc filter=lfs diff=lfs merge=lfs -text
|
284 |
+
env-my/Lib/site-packages/librosa/util/__pycache__/guf-utils._localmin-1068.py311.5.nbc filter=lfs diff=lfs merge=lfs -text
|
285 |
+
env-my/Lib/site-packages/librosa/util/__pycache__/utils._localmax-1051.py311.1.nbc filter=lfs diff=lfs merge=lfs -text
|
286 |
+
env-my/Lib/site-packages/librosa/util/__pycache__/utils._localmax-1051.py311.2.nbc filter=lfs diff=lfs merge=lfs -text
|
287 |
+
env-my/Lib/site-packages/librosa/util/__pycache__/utils._localmax-1051.py311.3.nbc filter=lfs diff=lfs merge=lfs -text
|
288 |
+
env-my/Lib/site-packages/librosa/util/__pycache__/utils._localmax-1051.py311.4.nbc filter=lfs diff=lfs merge=lfs -text
|
289 |
+
env-my/Lib/site-packages/librosa/util/__pycache__/utils._localmax-1051.py311.5.nbc filter=lfs diff=lfs merge=lfs -text
|
290 |
+
env-my/Lib/site-packages/librosa/util/__pycache__/utils._localmin-1068.py311.1.nbc filter=lfs diff=lfs merge=lfs -text
|
291 |
+
env-my/Lib/site-packages/librosa/util/__pycache__/utils._localmin-1068.py311.2.nbc filter=lfs diff=lfs merge=lfs -text
|
292 |
+
env-my/Lib/site-packages/librosa/util/__pycache__/utils._localmin-1068.py311.3.nbc filter=lfs diff=lfs merge=lfs -text
|
293 |
+
env-my/Lib/site-packages/librosa/util/__pycache__/utils._localmin-1068.py311.4.nbc filter=lfs diff=lfs merge=lfs -text
|
294 |
+
env-my/Lib/site-packages/librosa/util/__pycache__/utils._localmin-1068.py311.5.nbc filter=lfs diff=lfs merge=lfs -text
|
295 |
+
env-my/Lib/site-packages/llvmlite/binding/llvmlite.dll filter=lfs diff=lfs merge=lfs -text
|
296 |
+
env-my/Lib/site-packages/llvmlite/tests/__pycache__/test_binding.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
297 |
+
env-my/Lib/site-packages/llvmlite/tests/__pycache__/test_ir.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
298 |
+
env-my/Lib/site-packages/moonshine_onnx/assets/beckett.wav filter=lfs diff=lfs merge=lfs -text
|
299 |
+
env-my/Lib/site-packages/mpmath/__pycache__/function_docs.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
300 |
+
env-my/Lib/site-packages/mpmath/tests/__pycache__/test_fp.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
301 |
+
env-my/Lib/site-packages/mpmath/tests/__pycache__/test_functions2.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
302 |
+
env-my/Lib/site-packages/msgpack/_cmsgpack.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
303 |
+
env-my/Lib/site-packages/numba/_helperlib.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
304 |
+
env-my/Lib/site-packages/numba/core/__pycache__/byteflow.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
305 |
+
env-my/Lib/site-packages/numba/core/__pycache__/interpreter.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
306 |
+
env-my/Lib/site-packages/numba/core/__pycache__/ir_utils.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
307 |
+
env-my/Lib/site-packages/numba/core/__pycache__/pythonapi.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
308 |
+
env-my/Lib/site-packages/numba/core/__pycache__/typeinfer.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
309 |
+
env-my/Lib/site-packages/numba/cpython/__pycache__/randomimpl.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
310 |
+
env-my/Lib/site-packages/numba/cpython/__pycache__/unicode.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
311 |
+
env-my/Lib/site-packages/numba/cuda/cudadrv/__pycache__/driver.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
312 |
+
env-my/Lib/site-packages/numba/cuda/tests/cudapy/__pycache__/test_atomics.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
313 |
+
env-my/Lib/site-packages/numba/np/__pycache__/arrayobj.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
314 |
+
env-my/Lib/site-packages/numba/np/__pycache__/linalg.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
315 |
+
env-my/Lib/site-packages/numba/np/__pycache__/new_arraymath.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
316 |
+
env-my/Lib/site-packages/numba/np/__pycache__/old_arraymath.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
317 |
+
env-my/Lib/site-packages/numba/parfors/__pycache__/array_analysis.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
318 |
+
env-my/Lib/site-packages/numba/parfors/__pycache__/parfor.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
319 |
+
env-my/Lib/site-packages/numba/tests/__pycache__/test_array_manipulation.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
320 |
+
env-my/Lib/site-packages/numba/tests/__pycache__/test_array_methods.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
321 |
+
env-my/Lib/site-packages/numba/tests/__pycache__/test_builtins.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
322 |
+
env-my/Lib/site-packages/numba/tests/__pycache__/test_dictobject.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
323 |
+
env-my/Lib/site-packages/numba/tests/__pycache__/test_dyn_array.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
324 |
+
env-my/Lib/site-packages/numba/tests/__pycache__/test_extending.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
325 |
+
env-my/Lib/site-packages/numba/tests/__pycache__/test_jitclasses.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
326 |
+
env-my/Lib/site-packages/numba/tests/__pycache__/test_linalg.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
327 |
+
env-my/Lib/site-packages/numba/tests/__pycache__/test_listobject.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
328 |
+
env-my/Lib/site-packages/numba/tests/__pycache__/test_lists.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
329 |
+
env-my/Lib/site-packages/numba/tests/__pycache__/test_mixed_tuple_unroller.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
330 |
+
env-my/Lib/site-packages/numba/tests/__pycache__/test_np_functions.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
331 |
+
env-my/Lib/site-packages/numba/tests/__pycache__/test_parfors.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
332 |
+
env-my/Lib/site-packages/numba/tests/__pycache__/test_random.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
333 |
+
env-my/Lib/site-packages/numba/tests/__pycache__/test_record_dtype.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
334 |
+
env-my/Lib/site-packages/numba/tests/__pycache__/test_stencils.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
335 |
+
env-my/Lib/site-packages/numba/tests/__pycache__/test_typedlist.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
336 |
+
env-my/Lib/site-packages/numba/tests/__pycache__/test_ufuncs.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
337 |
+
env-my/Lib/site-packages/numba/tests/__pycache__/test_unicode.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
338 |
+
env-my/Lib/site-packages/numpy/_core/__pycache__/_add_newdocs.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
339 |
+
env-my/Lib/site-packages/numpy/_core/__pycache__/fromnumeric.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
340 |
+
env-my/Lib/site-packages/numpy/_core/_multiarray_umath.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
341 |
+
env-my/Lib/site-packages/numpy/_core/_simd.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
342 |
+
env-my/Lib/site-packages/numpy/_core/lib/npymath.lib filter=lfs diff=lfs merge=lfs -text
|
343 |
+
env-my/Lib/site-packages/numpy/_core/tests/__pycache__/test_datetime.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
344 |
+
env-my/Lib/site-packages/numpy/_core/tests/__pycache__/test_dtype.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
345 |
+
env-my/Lib/site-packages/numpy/_core/tests/__pycache__/test_multiarray.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
346 |
+
env-my/Lib/site-packages/numpy/_core/tests/__pycache__/test_nditer.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
347 |
+
env-my/Lib/site-packages/numpy/_core/tests/__pycache__/test_numeric.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
348 |
+
env-my/Lib/site-packages/numpy/_core/tests/__pycache__/test_regression.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
349 |
+
env-my/Lib/site-packages/numpy/_core/tests/__pycache__/test_stringdtype.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
350 |
+
env-my/Lib/site-packages/numpy/_core/tests/__pycache__/test_ufunc.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
351 |
+
env-my/Lib/site-packages/numpy/_core/tests/__pycache__/test_umath.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
352 |
+
env-my/Lib/site-packages/numpy/distutils/__pycache__/ccompiler_opt.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
353 |
+
env-my/Lib/site-packages/numpy/distutils/__pycache__/misc_util.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
354 |
+
env-my/Lib/site-packages/numpy/distutils/__pycache__/system_info.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
355 |
+
env-my/Lib/site-packages/numpy/f2py/__pycache__/crackfortran.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
356 |
+
env-my/Lib/site-packages/numpy/fft/_pocketfft_umath.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
357 |
+
env-my/Lib/site-packages/numpy/lib/__pycache__/_function_base_impl.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
358 |
+
env-my/Lib/site-packages/numpy/lib/__pycache__/_npyio_impl.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
359 |
+
env-my/Lib/site-packages/numpy/lib/tests/__pycache__/test_function_base.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
360 |
+
env-my/Lib/site-packages/numpy/lib/tests/__pycache__/test_io.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
361 |
+
env-my/Lib/site-packages/numpy/lib/tests/__pycache__/test_nanfunctions.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
362 |
+
env-my/Lib/site-packages/numpy/linalg/__pycache__/_linalg.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
363 |
+
env-my/Lib/site-packages/numpy/linalg/_umath_linalg.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
364 |
+
env-my/Lib/site-packages/numpy/linalg/tests/__pycache__/test_linalg.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
365 |
+
env-my/Lib/site-packages/numpy/ma/__pycache__/core.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
366 |
+
env-my/Lib/site-packages/numpy/ma/tests/__pycache__/test_core.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
367 |
+
env-my/Lib/site-packages/numpy/ma/tests/__pycache__/test_extras.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
368 |
+
env-my/Lib/site-packages/numpy/random/_bounded_integers.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
369 |
+
env-my/Lib/site-packages/numpy/random/_common.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
370 |
+
env-my/Lib/site-packages/numpy/random/_generator.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
371 |
+
env-my/Lib/site-packages/numpy/random/bit_generator.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
372 |
+
env-my/Lib/site-packages/numpy/random/lib/npyrandom.lib filter=lfs diff=lfs merge=lfs -text
|
373 |
+
env-my/Lib/site-packages/numpy/random/mtrand.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
374 |
+
env-my/Lib/site-packages/numpy/random/tests/__pycache__/test_generator_mt19937.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
375 |
+
env-my/Lib/site-packages/numpy/random/tests/__pycache__/test_random.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
376 |
+
env-my/Lib/site-packages/numpy/random/tests/__pycache__/test_randomstate.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
377 |
+
env-my/Lib/site-packages/numpy/testing/_private/__pycache__/utils.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
378 |
+
env-my/Lib/site-packages/numpy/testing/tests/__pycache__/test_utils.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
379 |
+
env-my/Lib/site-packages/numpy/typing/tests/data/pass/__pycache__/random.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
380 |
+
env-my/Lib/site-packages/numpy.libs/libscipy_openblas64_-c16e4918366c6bc1f1cd71e28ca36fc0.dll filter=lfs diff=lfs merge=lfs -text
|
381 |
+
env-my/Lib/site-packages/numpy.libs/msvcp140-d64049c6e3865410a7dda6a7e9f0c575.dll filter=lfs diff=lfs merge=lfs -text
|
382 |
+
env-my/Lib/site-packages/onnxruntime/capi/onnxruntime.dll filter=lfs diff=lfs merge=lfs -text
|
383 |
+
env-my/Lib/site-packages/onnxruntime/capi/onnxruntime_pybind11_state.pyd filter=lfs diff=lfs merge=lfs -text
|
384 |
+
env-my/Lib/site-packages/onnxruntime/tools/__pycache__/symbolic_shape_infer.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
385 |
+
env-my/Lib/site-packages/onnxruntime/transformers/__pycache__/convert_generation.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
386 |
+
env-my/Lib/site-packages/OpenSSL/__pycache__/crypto.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
387 |
+
env-my/Lib/site-packages/OpenSSL/__pycache__/SSL.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
388 |
+
env-my/Lib/site-packages/orjson/orjson.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
389 |
+
env-my/Lib/site-packages/pandas/_libs/algos.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
390 |
+
env-my/Lib/site-packages/pandas/_libs/groupby.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
391 |
+
env-my/Lib/site-packages/pandas/_libs/hashing.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
392 |
+
env-my/Lib/site-packages/pandas/_libs/hashtable.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
393 |
+
env-my/Lib/site-packages/pandas/_libs/index.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
394 |
+
env-my/Lib/site-packages/pandas/_libs/internals.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
395 |
+
env-my/Lib/site-packages/pandas/_libs/interval.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
396 |
+
env-my/Lib/site-packages/pandas/_libs/join.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
397 |
+
env-my/Lib/site-packages/pandas/_libs/lib.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
398 |
+
env-my/Lib/site-packages/pandas/_libs/missing.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
399 |
+
env-my/Lib/site-packages/pandas/_libs/ops.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
400 |
+
env-my/Lib/site-packages/pandas/_libs/parsers.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
401 |
+
env-my/Lib/site-packages/pandas/_libs/reshape.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
402 |
+
env-my/Lib/site-packages/pandas/_libs/sas.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
403 |
+
env-my/Lib/site-packages/pandas/_libs/sparse.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
404 |
+
env-my/Lib/site-packages/pandas/_libs/tslib.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
405 |
+
env-my/Lib/site-packages/pandas/_libs/tslibs/conversion.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
406 |
+
env-my/Lib/site-packages/pandas/_libs/tslibs/dtypes.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
407 |
+
env-my/Lib/site-packages/pandas/_libs/tslibs/fields.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
408 |
+
env-my/Lib/site-packages/pandas/_libs/tslibs/nattype.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
409 |
+
env-my/Lib/site-packages/pandas/_libs/tslibs/np_datetime.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
410 |
+
env-my/Lib/site-packages/pandas/_libs/tslibs/offsets.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
411 |
+
env-my/Lib/site-packages/pandas/_libs/tslibs/parsing.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
412 |
+
env-my/Lib/site-packages/pandas/_libs/tslibs/period.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
413 |
+
env-my/Lib/site-packages/pandas/_libs/tslibs/strptime.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
414 |
+
env-my/Lib/site-packages/pandas/_libs/tslibs/timedeltas.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
415 |
+
env-my/Lib/site-packages/pandas/_libs/tslibs/timestamps.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
416 |
+
env-my/Lib/site-packages/pandas/_libs/tslibs/timezones.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
417 |
+
env-my/Lib/site-packages/pandas/_libs/tslibs/tzconversion.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
418 |
+
env-my/Lib/site-packages/pandas/_libs/tslibs/vectorized.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
419 |
+
env-my/Lib/site-packages/pandas/_libs/window/aggregations.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
420 |
+
env-my/Lib/site-packages/pandas/_libs/window/indexers.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
421 |
+
env-my/Lib/site-packages/pandas/_libs/writers.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
422 |
+
env-my/Lib/site-packages/pandas/core/__pycache__/frame.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
423 |
+
env-my/Lib/site-packages/pandas/core/__pycache__/generic.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
424 |
+
env-my/Lib/site-packages/pandas/core/__pycache__/indexing.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
425 |
+
env-my/Lib/site-packages/pandas/core/__pycache__/resample.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
426 |
+
env-my/Lib/site-packages/pandas/core/__pycache__/series.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
427 |
+
env-my/Lib/site-packages/pandas/core/arrays/__pycache__/categorical.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
428 |
+
env-my/Lib/site-packages/pandas/core/arrays/__pycache__/datetimelike.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
429 |
+
env-my/Lib/site-packages/pandas/core/arrays/arrow/__pycache__/array.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
430 |
+
env-my/Lib/site-packages/pandas/core/groupby/__pycache__/generic.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
431 |
+
env-my/Lib/site-packages/pandas/core/groupby/__pycache__/groupby.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
432 |
+
env-my/Lib/site-packages/pandas/core/indexes/__pycache__/base.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
433 |
+
env-my/Lib/site-packages/pandas/core/indexes/__pycache__/multi.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
434 |
+
env-my/Lib/site-packages/pandas/core/internals/__pycache__/blocks.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
435 |
+
env-my/Lib/site-packages/pandas/core/internals/__pycache__/managers.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
436 |
+
env-my/Lib/site-packages/pandas/core/reshape/__pycache__/merge.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
437 |
+
env-my/Lib/site-packages/pandas/core/strings/__pycache__/accessor.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
438 |
+
env-my/Lib/site-packages/pandas/core/window/__pycache__/rolling.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
439 |
+
env-my/Lib/site-packages/pandas/io/__pycache__/pytables.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
440 |
+
env-my/Lib/site-packages/pandas/io/__pycache__/sql.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
441 |
+
env-my/Lib/site-packages/pandas/io/__pycache__/stata.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
442 |
+
env-my/Lib/site-packages/pandas/io/formats/__pycache__/style.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
443 |
+
env-my/Lib/site-packages/pandas/io/formats/__pycache__/style_render.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
444 |
+
env-my/Lib/site-packages/pandas/tests/__pycache__/test_algos.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
445 |
+
env-my/Lib/site-packages/pandas/tests/apply/__pycache__/test_frame_apply.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
446 |
+
env-my/Lib/site-packages/pandas/tests/arithmetic/__pycache__/test_datetime64.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
447 |
+
env-my/Lib/site-packages/pandas/tests/arithmetic/__pycache__/test_period.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
448 |
+
env-my/Lib/site-packages/pandas/tests/arithmetic/__pycache__/test_timedelta64.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
449 |
+
env-my/Lib/site-packages/pandas/tests/computation/__pycache__/test_eval.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
450 |
+
env-my/Lib/site-packages/pandas/tests/copy_view/__pycache__/test_methods.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
451 |
+
env-my/Lib/site-packages/pandas/tests/dtypes/__pycache__/test_inference.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
452 |
+
env-my/Lib/site-packages/pandas/tests/extension/__pycache__/test_arrow.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
453 |
+
env-my/Lib/site-packages/pandas/tests/frame/__pycache__/test_arithmetic.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
454 |
+
env-my/Lib/site-packages/pandas/tests/frame/__pycache__/test_constructors.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
455 |
+
env-my/Lib/site-packages/pandas/tests/frame/__pycache__/test_query_eval.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
456 |
+
env-my/Lib/site-packages/pandas/tests/frame/__pycache__/test_reductions.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
457 |
+
env-my/Lib/site-packages/pandas/tests/frame/__pycache__/test_stack_unstack.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
458 |
+
env-my/Lib/site-packages/pandas/tests/frame/indexing/__pycache__/test_indexing.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
459 |
+
env-my/Lib/site-packages/pandas/tests/groupby/__pycache__/test_apply.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
460 |
+
env-my/Lib/site-packages/pandas/tests/groupby/__pycache__/test_categorical.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
461 |
+
env-my/Lib/site-packages/pandas/tests/groupby/__pycache__/test_groupby.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
462 |
+
env-my/Lib/site-packages/pandas/tests/groupby/aggregate/__pycache__/test_aggregate.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
463 |
+
env-my/Lib/site-packages/pandas/tests/groupby/transform/__pycache__/test_transform.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
464 |
+
env-my/Lib/site-packages/pandas/tests/indexes/__pycache__/test_base.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
465 |
+
env-my/Lib/site-packages/pandas/tests/indexing/__pycache__/test_loc.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
466 |
+
env-my/Lib/site-packages/pandas/tests/io/__pycache__/test_sql.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
467 |
+
env-my/Lib/site-packages/pandas/tests/io/__pycache__/test_stata.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
468 |
+
env-my/Lib/site-packages/pandas/tests/io/formats/__pycache__/test_format.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
469 |
+
env-my/Lib/site-packages/pandas/tests/io/formats/style/__pycache__/test_style.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
470 |
+
env-my/Lib/site-packages/pandas/tests/io/json/__pycache__/test_pandas.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
471 |
+
env-my/Lib/site-packages/pandas/tests/plotting/__pycache__/test_datetimelike.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
472 |
+
env-my/Lib/site-packages/pandas/tests/plotting/frame/__pycache__/test_frame.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
473 |
+
env-my/Lib/site-packages/pandas/tests/reductions/__pycache__/test_reductions.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
474 |
+
env-my/Lib/site-packages/pandas/tests/resample/__pycache__/test_datetime_index.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
475 |
+
env-my/Lib/site-packages/pandas/tests/reshape/__pycache__/test_pivot.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
476 |
+
env-my/Lib/site-packages/pandas/tests/reshape/merge/__pycache__/test_merge.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
477 |
+
env-my/Lib/site-packages/pandas/tests/series/__pycache__/test_constructors.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
478 |
+
env-my/Lib/site-packages/pandas/tests/series/indexing/__pycache__/test_setitem.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
479 |
+
env-my/Lib/site-packages/pandas/tests/tools/__pycache__/test_to_datetime.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
480 |
+
env-my/Lib/site-packages/pandas/tests/window/__pycache__/test_rolling.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
481 |
+
env-my/Lib/site-packages/pandas.libs/msvcp140-0f2ea95580b32bcfc81c235d5751ce78.dll filter=lfs diff=lfs merge=lfs -text
|
482 |
+
env-my/Lib/site-packages/PIL/__pycache__/Image.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
483 |
+
env-my/Lib/site-packages/PIL/__pycache__/TiffImagePlugin.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
484 |
+
env-my/Lib/site-packages/PIL/_imaging.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
485 |
+
env-my/Lib/site-packages/PIL/_imagingcms.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
486 |
+
env-my/Lib/site-packages/PIL/_imagingft.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
487 |
+
env-my/Lib/site-packages/PIL/_webp.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
488 |
+
env-my/Lib/site-packages/pip/_vendor/__pycache__/typing_extensions.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
489 |
+
env-my/Lib/site-packages/pip/_vendor/distlib/t64-arm.exe filter=lfs diff=lfs merge=lfs -text
|
490 |
+
env-my/Lib/site-packages/pip/_vendor/distlib/t64.exe filter=lfs diff=lfs merge=lfs -text
|
491 |
+
env-my/Lib/site-packages/pip/_vendor/distlib/w64-arm.exe filter=lfs diff=lfs merge=lfs -text
|
492 |
+
env-my/Lib/site-packages/pip/_vendor/distlib/w64.exe filter=lfs diff=lfs merge=lfs -text
|
493 |
+
env-my/Lib/site-packages/pip/_vendor/idna/__pycache__/idnadata.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
494 |
+
env-my/Lib/site-packages/pip/_vendor/idna/__pycache__/uts46data.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
495 |
+
env-my/Lib/site-packages/pip/_vendor/pkg_resources/__pycache__/__init__.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
496 |
+
env-my/Lib/site-packages/pip/_vendor/rich/__pycache__/_emoji_codes.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
497 |
+
env-my/Lib/site-packages/pip/_vendor/rich/__pycache__/console.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
498 |
+
env-my/Lib/site-packages/pkg_resources/__pycache__/__init__.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
499 |
+
env-my/Lib/site-packages/pkg_resources/_vendor/more_itertools/__pycache__/more.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
500 |
+
env-my/Lib/site-packages/pkg_resources/_vendor/pyparsing/__pycache__/core.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
501 |
+
env-my/Lib/site-packages/pycparser/__pycache__/yacctab.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
502 |
+
env-my/Lib/site-packages/pycparser/ply/__pycache__/yacc.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
503 |
+
env-my/Lib/site-packages/pydantic/__pycache__/json_schema.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
504 |
+
env-my/Lib/site-packages/pydantic/__pycache__/types.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
505 |
+
env-my/Lib/site-packages/pydantic/_internal/__pycache__/_generate_schema.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
506 |
+
env-my/Lib/site-packages/pydantic_core/__pycache__/core_schema.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
507 |
+
env-my/Lib/site-packages/pydantic_core/_pydantic_core.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
508 |
+
env-my/Lib/site-packages/pygments/lexers/__pycache__/lisp.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
509 |
+
env-my/Lib/site-packages/pylibsrtp/_binding.pyd filter=lfs diff=lfs merge=lfs -text
|
510 |
+
env-my/Lib/site-packages/pyparsing/__pycache__/core.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
511 |
+
env-my/Lib/site-packages/rdflib/__pycache__/graph.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
512 |
+
env-my/Lib/site-packages/rdflib/extras/__pycache__/infixowl.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
513 |
+
env-my/Lib/site-packages/rdflib/namespace/__pycache__/_SDO.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
514 |
+
env-my/Lib/site-packages/regex/__pycache__/_regex_core.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
515 |
+
env-my/Lib/site-packages/regex/__pycache__/test_regex.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
516 |
+
env-my/Lib/site-packages/regex/_regex.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
517 |
+
env-my/Lib/site-packages/rich/__pycache__/_emoji_codes.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
518 |
+
env-my/Lib/site-packages/rich/__pycache__/console.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
519 |
+
env-my/Lib/site-packages/rpds/rpds.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
520 |
+
env-my/Lib/site-packages/scipy/_lib/_uarray/_uarray.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
521 |
+
env-my/Lib/site-packages/scipy/cluster/__pycache__/hierarchy.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
522 |
+
env-my/Lib/site-packages/scipy/cluster/_hierarchy.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
523 |
+
env-my/Lib/site-packages/scipy/cluster/_optimal_leaf_ordering.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
524 |
+
env-my/Lib/site-packages/scipy/cluster/_vq.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
525 |
+
env-my/Lib/site-packages/scipy/constants/__pycache__/_codata.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
526 |
+
env-my/Lib/site-packages/scipy/fft/_pocketfft/pypocketfft.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
527 |
+
env-my/Lib/site-packages/scipy/fftpack/convolve.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
528 |
+
env-my/Lib/site-packages/scipy/integrate/__pycache__/_lebedev.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
529 |
+
env-my/Lib/site-packages/scipy/integrate/_dop.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
530 |
+
env-my/Lib/site-packages/scipy/integrate/_lsoda.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
531 |
+
env-my/Lib/site-packages/scipy/integrate/_odepack.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
532 |
+
env-my/Lib/site-packages/scipy/integrate/_quadpack.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
533 |
+
env-my/Lib/site-packages/scipy/integrate/_test_odeint_banded.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
534 |
+
env-my/Lib/site-packages/scipy/integrate/_vode.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
535 |
+
env-my/Lib/site-packages/scipy/interpolate/__pycache__/_bsplines.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
536 |
+
env-my/Lib/site-packages/scipy/interpolate/__pycache__/_fitpack2.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
537 |
+
env-my/Lib/site-packages/scipy/interpolate/_bspl.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
538 |
+
env-my/Lib/site-packages/scipy/interpolate/_dfitpack.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
539 |
+
env-my/Lib/site-packages/scipy/interpolate/_dierckx.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
540 |
+
env-my/Lib/site-packages/scipy/interpolate/_fitpack.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
541 |
+
env-my/Lib/site-packages/scipy/interpolate/_interpnd.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
542 |
+
env-my/Lib/site-packages/scipy/interpolate/_ppoly.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
543 |
+
env-my/Lib/site-packages/scipy/interpolate/_rbfinterp_pythran.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
544 |
+
env-my/Lib/site-packages/scipy/interpolate/_rgi_cython.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
545 |
+
env-my/Lib/site-packages/scipy/interpolate/tests/__pycache__/test_bsplines.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
546 |
+
env-my/Lib/site-packages/scipy/interpolate/tests/__pycache__/test_fitpack2.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
547 |
+
env-my/Lib/site-packages/scipy/interpolate/tests/__pycache__/test_interpolate.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
548 |
+
env-my/Lib/site-packages/scipy/io/_fast_matrix_market/_fmm_core.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
549 |
+
env-my/Lib/site-packages/scipy/io/_test_fortran.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
550 |
+
env-my/Lib/site-packages/scipy/io/matlab/_mio5_utils.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
551 |
+
env-my/Lib/site-packages/scipy/io/matlab/_streams.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
552 |
+
env-my/Lib/site-packages/scipy/linalg/_cythonized_array_utils.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
553 |
+
env-my/Lib/site-packages/scipy/linalg/_decomp_interpolative.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
554 |
+
env-my/Lib/site-packages/scipy/linalg/_decomp_lu_cython.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
555 |
+
env-my/Lib/site-packages/scipy/linalg/_decomp_update.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
556 |
+
env-my/Lib/site-packages/scipy/linalg/_fblas.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
557 |
+
env-my/Lib/site-packages/scipy/linalg/_flapack.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
558 |
+
env-my/Lib/site-packages/scipy/linalg/_linalg_pythran.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
559 |
+
env-my/Lib/site-packages/scipy/linalg/_matfuncs_expm.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
560 |
+
env-my/Lib/site-packages/scipy/linalg/_matfuncs_sqrtm_triu.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
561 |
+
env-my/Lib/site-packages/scipy/linalg/_solve_toeplitz.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
562 |
+
env-my/Lib/site-packages/scipy/linalg/cython_blas.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
563 |
+
env-my/Lib/site-packages/scipy/linalg/cython_lapack.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
564 |
+
env-my/Lib/site-packages/scipy/linalg/tests/__pycache__/test_basic.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
565 |
+
env-my/Lib/site-packages/scipy/linalg/tests/__pycache__/test_decomp.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
566 |
+
env-my/Lib/site-packages/scipy/linalg/tests/__pycache__/test_decomp_update.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
567 |
+
env-my/Lib/site-packages/scipy/linalg/tests/__pycache__/test_lapack.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
568 |
+
env-my/Lib/site-packages/scipy/ndimage/__pycache__/_morphology.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
569 |
+
env-my/Lib/site-packages/scipy/ndimage/_nd_image.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
570 |
+
env-my/Lib/site-packages/scipy/ndimage/_ni_label.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
571 |
+
env-my/Lib/site-packages/scipy/ndimage/_rank_filter_1d.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
572 |
+
env-my/Lib/site-packages/scipy/ndimage/tests/__pycache__/test_filters.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
573 |
+
env-my/Lib/site-packages/scipy/ndimage/tests/__pycache__/test_interpolation.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
574 |
+
env-my/Lib/site-packages/scipy/ndimage/tests/__pycache__/test_morphology.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
575 |
+
env-my/Lib/site-packages/scipy/odr/__odrpack.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
576 |
+
env-my/Lib/site-packages/scipy/optimize/__pycache__/_optimize.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
577 |
+
env-my/Lib/site-packages/scipy/optimize/_bglu_dense.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
578 |
+
env-my/Lib/site-packages/scipy/optimize/_cobyla.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
579 |
+
env-my/Lib/site-packages/scipy/optimize/_cython_nnls.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
580 |
+
env-my/Lib/site-packages/scipy/optimize/_group_columns.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
581 |
+
env-my/Lib/site-packages/scipy/optimize/_highspy/_core.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
582 |
+
env-my/Lib/site-packages/scipy/optimize/_highspy/_highs_options.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
583 |
+
env-my/Lib/site-packages/scipy/optimize/_lbfgsb.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
584 |
+
env-my/Lib/site-packages/scipy/optimize/_lsap.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
585 |
+
env-my/Lib/site-packages/scipy/optimize/_lsq/givens_elimination.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
586 |
+
env-my/Lib/site-packages/scipy/optimize/_minpack.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
587 |
+
env-my/Lib/site-packages/scipy/optimize/_moduleTNC.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
588 |
+
env-my/Lib/site-packages/scipy/optimize/_pava_pybind.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
589 |
+
env-my/Lib/site-packages/scipy/optimize/_slsqp.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
590 |
+
env-my/Lib/site-packages/scipy/optimize/_trlib/_trlib.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
591 |
+
env-my/Lib/site-packages/scipy/optimize/tests/__pycache__/test__differential_evolution.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
592 |
+
env-my/Lib/site-packages/scipy/optimize/tests/__pycache__/test_linprog.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
593 |
+
env-my/Lib/site-packages/scipy/optimize/tests/__pycache__/test_optimize.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
594 |
+
env-my/Lib/site-packages/scipy/signal/__pycache__/_filter_design.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
595 |
+
env-my/Lib/site-packages/scipy/signal/__pycache__/_ltisys.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
596 |
+
env-my/Lib/site-packages/scipy/signal/__pycache__/_signaltools.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
597 |
+
env-my/Lib/site-packages/scipy/signal/_max_len_seq_inner.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
598 |
+
env-my/Lib/site-packages/scipy/signal/_peak_finding_utils.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
599 |
+
env-my/Lib/site-packages/scipy/signal/_sigtools.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
600 |
+
env-my/Lib/site-packages/scipy/signal/_sosfilt.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
601 |
+
env-my/Lib/site-packages/scipy/signal/_upfirdn_apply.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
602 |
+
env-my/Lib/site-packages/scipy/signal/tests/__pycache__/test_filter_design.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
603 |
+
env-my/Lib/site-packages/scipy/signal/tests/__pycache__/test_signaltools.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
604 |
+
env-my/Lib/site-packages/scipy/signal/tests/__pycache__/test_spectral.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
605 |
+
env-my/Lib/site-packages/scipy/sparse/_csparsetools.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
606 |
+
env-my/Lib/site-packages/scipy/sparse/_sparsetools.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
607 |
+
env-my/Lib/site-packages/scipy/sparse/csgraph/_flow.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
608 |
+
env-my/Lib/site-packages/scipy/sparse/csgraph/_matching.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
609 |
+
env-my/Lib/site-packages/scipy/sparse/csgraph/_min_spanning_tree.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
610 |
+
env-my/Lib/site-packages/scipy/sparse/csgraph/_reordering.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
611 |
+
env-my/Lib/site-packages/scipy/sparse/csgraph/_shortest_path.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
612 |
+
env-my/Lib/site-packages/scipy/sparse/csgraph/_tools.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
613 |
+
env-my/Lib/site-packages/scipy/sparse/csgraph/_traversal.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
614 |
+
env-my/Lib/site-packages/scipy/sparse/linalg/_dsolve/_superlu.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
615 |
+
env-my/Lib/site-packages/scipy/sparse/linalg/_eigen/arpack/_arpack.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
616 |
+
env-my/Lib/site-packages/scipy/sparse/linalg/_propack/_cpropack.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
617 |
+
env-my/Lib/site-packages/scipy/sparse/linalg/_propack/_dpropack.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
618 |
+
env-my/Lib/site-packages/scipy/sparse/linalg/_propack/_spropack.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
619 |
+
env-my/Lib/site-packages/scipy/sparse/linalg/_propack/_zpropack.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
620 |
+
env-my/Lib/site-packages/scipy/sparse/tests/__pycache__/test_base.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
621 |
+
env-my/Lib/site-packages/scipy/spatial/__pycache__/distance.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
622 |
+
env-my/Lib/site-packages/scipy/spatial/_ckdtree.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
623 |
+
env-my/Lib/site-packages/scipy/spatial/_distance_pybind.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
624 |
+
env-my/Lib/site-packages/scipy/spatial/_distance_wrap.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
625 |
+
env-my/Lib/site-packages/scipy/spatial/_hausdorff.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
626 |
+
env-my/Lib/site-packages/scipy/spatial/_qhull.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
627 |
+
env-my/Lib/site-packages/scipy/spatial/_voronoi.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
628 |
+
env-my/Lib/site-packages/scipy/spatial/tests/__pycache__/test_distance.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
629 |
+
env-my/Lib/site-packages/scipy/spatial/tests/__pycache__/test_kdtree.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
630 |
+
env-my/Lib/site-packages/scipy/spatial/transform/_rotation.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
631 |
+
env-my/Lib/site-packages/scipy/spatial/transform/tests/__pycache__/test_rotation.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
632 |
+
env-my/Lib/site-packages/scipy/special/__pycache__/_add_newdocs.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
633 |
+
env-my/Lib/site-packages/scipy/special/__pycache__/_basic.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
634 |
+
env-my/Lib/site-packages/scipy/special/_ellip_harm_2.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
635 |
+
env-my/Lib/site-packages/scipy/special/_gufuncs.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
636 |
+
env-my/Lib/site-packages/scipy/special/_specfun.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
637 |
+
env-my/Lib/site-packages/scipy/special/_special_ufuncs.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
638 |
+
env-my/Lib/site-packages/scipy/special/_test_internal.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
639 |
+
env-my/Lib/site-packages/scipy/special/_ufuncs.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
640 |
+
env-my/Lib/site-packages/scipy/special/_ufuncs_cxx.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
641 |
+
env-my/Lib/site-packages/scipy/special/cython_special.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
642 |
+
env-my/Lib/site-packages/scipy/special/libsf_error_state.dll filter=lfs diff=lfs merge=lfs -text
|
643 |
+
env-my/Lib/site-packages/scipy/special/tests/__pycache__/test_basic.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
644 |
+
env-my/Lib/site-packages/scipy/special/tests/__pycache__/test_legendre.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
645 |
+
env-my/Lib/site-packages/scipy/special/tests/__pycache__/test_mpmath.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
646 |
+
env-my/Lib/site-packages/scipy/stats/__pycache__/_continuous_distns.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
647 |
+
env-my/Lib/site-packages/scipy/stats/__pycache__/_discrete_distns.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
648 |
+
env-my/Lib/site-packages/scipy/stats/__pycache__/_distn_infrastructure.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
649 |
+
env-my/Lib/site-packages/scipy/stats/__pycache__/_distribution_infrastructure.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
650 |
+
env-my/Lib/site-packages/scipy/stats/__pycache__/_morestats.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
651 |
+
env-my/Lib/site-packages/scipy/stats/__pycache__/_mstats_basic.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
652 |
+
env-my/Lib/site-packages/scipy/stats/__pycache__/_multivariate.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
653 |
+
env-my/Lib/site-packages/scipy/stats/__pycache__/_qmc.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
654 |
+
env-my/Lib/site-packages/scipy/stats/__pycache__/_resampling.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
655 |
+
env-my/Lib/site-packages/scipy/stats/__pycache__/_stats_py.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
656 |
+
env-my/Lib/site-packages/scipy/stats/_ansari_swilk_statistics.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
657 |
+
env-my/Lib/site-packages/scipy/stats/_biasedurn.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
658 |
+
env-my/Lib/site-packages/scipy/stats/_mvn.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
659 |
+
env-my/Lib/site-packages/scipy/stats/_qmc_cy.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
660 |
+
env-my/Lib/site-packages/scipy/stats/_rcont/rcont.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
661 |
+
env-my/Lib/site-packages/scipy/stats/_sobol.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
662 |
+
env-my/Lib/site-packages/scipy/stats/_stats.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
663 |
+
env-my/Lib/site-packages/scipy/stats/_stats_pythran.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
664 |
+
env-my/Lib/site-packages/scipy/stats/_unuran/unuran_wrapper.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
665 |
+
env-my/Lib/site-packages/scipy/stats/tests/__pycache__/test_continuous.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
666 |
+
env-my/Lib/site-packages/scipy/stats/tests/__pycache__/test_distributions.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
667 |
+
env-my/Lib/site-packages/scipy/stats/tests/__pycache__/test_hypotests.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
668 |
+
env-my/Lib/site-packages/scipy/stats/tests/__pycache__/test_morestats.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
669 |
+
env-my/Lib/site-packages/scipy/stats/tests/__pycache__/test_mstats_basic.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
670 |
+
env-my/Lib/site-packages/scipy/stats/tests/__pycache__/test_multivariate.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
671 |
+
env-my/Lib/site-packages/scipy/stats/tests/__pycache__/test_qmc.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
672 |
+
env-my/Lib/site-packages/scipy/stats/tests/__pycache__/test_resampling.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
673 |
+
env-my/Lib/site-packages/scipy/stats/tests/__pycache__/test_stats.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
674 |
+
env-my/Lib/site-packages/scipy.libs/libscipy_openblas-f07f5a5d207a3a47104dca54d6d0c86a.dll filter=lfs diff=lfs merge=lfs -text
|
675 |
+
env-my/Lib/site-packages/setuptools/_vendor/__pycache__/typing_extensions.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
676 |
+
env-my/Lib/site-packages/setuptools/_vendor/more_itertools/__pycache__/more.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
677 |
+
env-my/Lib/site-packages/setuptools/_vendor/pyparsing/__pycache__/core.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
678 |
+
env-my/Lib/site-packages/setuptools/cli-arm64.exe filter=lfs diff=lfs merge=lfs -text
|
679 |
+
env-my/Lib/site-packages/setuptools/command/__pycache__/easy_install.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
680 |
+
env-my/Lib/site-packages/setuptools/config/_validate_pyproject/__pycache__/fastjsonschema_validations.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
681 |
+
env-my/Lib/site-packages/setuptools/gui-arm64.exe filter=lfs diff=lfs merge=lfs -text
|
682 |
+
env-my/Lib/site-packages/sklearn/.libs/msvcp140.dll filter=lfs diff=lfs merge=lfs -text
|
683 |
+
env-my/Lib/site-packages/sklearn/.libs/vcomp140.dll filter=lfs diff=lfs merge=lfs -text
|
684 |
+
env-my/Lib/site-packages/sklearn/_isotonic.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
685 |
+
env-my/Lib/site-packages/sklearn/_loss/_loss.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
686 |
+
env-my/Lib/site-packages/sklearn/cluster/_dbscan_inner.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
687 |
+
env-my/Lib/site-packages/sklearn/cluster/_hdbscan/_linkage.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
688 |
+
env-my/Lib/site-packages/sklearn/cluster/_hdbscan/_reachability.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
689 |
+
env-my/Lib/site-packages/sklearn/cluster/_hdbscan/_tree.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
690 |
+
env-my/Lib/site-packages/sklearn/cluster/_hierarchical_fast.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
691 |
+
env-my/Lib/site-packages/sklearn/cluster/_k_means_common.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
692 |
+
env-my/Lib/site-packages/sklearn/cluster/_k_means_elkan.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
693 |
+
env-my/Lib/site-packages/sklearn/cluster/_k_means_lloyd.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
694 |
+
env-my/Lib/site-packages/sklearn/cluster/_k_means_minibatch.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
695 |
+
env-my/Lib/site-packages/sklearn/compose/tests/__pycache__/test_column_transformer.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
696 |
+
env-my/Lib/site-packages/sklearn/datasets/_svmlight_format_fast.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
697 |
+
env-my/Lib/site-packages/sklearn/datasets/images/china.jpg filter=lfs diff=lfs merge=lfs -text
|
698 |
+
env-my/Lib/site-packages/sklearn/datasets/images/flower.jpg filter=lfs diff=lfs merge=lfs -text
|
699 |
+
env-my/Lib/site-packages/sklearn/decomposition/_cdnmf_fast.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
700 |
+
env-my/Lib/site-packages/sklearn/decomposition/_online_lda_fast.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
701 |
+
env-my/Lib/site-packages/sklearn/ensemble/__pycache__/_forest.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
702 |
+
env-my/Lib/site-packages/sklearn/ensemble/_gradient_boosting.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
703 |
+
env-my/Lib/site-packages/sklearn/ensemble/_hist_gradient_boosting/_binning.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
704 |
+
env-my/Lib/site-packages/sklearn/ensemble/_hist_gradient_boosting/_bitset.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
705 |
+
env-my/Lib/site-packages/sklearn/ensemble/_hist_gradient_boosting/_gradient_boosting.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
706 |
+
env-my/Lib/site-packages/sklearn/ensemble/_hist_gradient_boosting/_predictor.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
707 |
+
env-my/Lib/site-packages/sklearn/ensemble/_hist_gradient_boosting/histogram.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
708 |
+
env-my/Lib/site-packages/sklearn/ensemble/_hist_gradient_boosting/splitting.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
709 |
+
env-my/Lib/site-packages/sklearn/impute/tests/__pycache__/test_impute.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
710 |
+
env-my/Lib/site-packages/sklearn/linear_model/__pycache__/_coordinate_descent.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
711 |
+
env-my/Lib/site-packages/sklearn/linear_model/__pycache__/_ridge.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
712 |
+
env-my/Lib/site-packages/sklearn/linear_model/_cd_fast.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
713 |
+
env-my/Lib/site-packages/sklearn/linear_model/_sag_fast.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
714 |
+
env-my/Lib/site-packages/sklearn/linear_model/_sgd_fast.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
715 |
+
env-my/Lib/site-packages/sklearn/linear_model/tests/__pycache__/test_logistic.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
716 |
+
env-my/Lib/site-packages/sklearn/linear_model/tests/__pycache__/test_ridge.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
717 |
+
env-my/Lib/site-packages/sklearn/linear_model/tests/__pycache__/test_sgd.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
718 |
+
env-my/Lib/site-packages/sklearn/manifold/_barnes_hut_tsne.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
719 |
+
env-my/Lib/site-packages/sklearn/manifold/_utils.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
720 |
+
env-my/Lib/site-packages/sklearn/metrics/__pycache__/_classification.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
721 |
+
env-my/Lib/site-packages/sklearn/metrics/_dist_metrics.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
722 |
+
env-my/Lib/site-packages/sklearn/metrics/_pairwise_distances_reduction/_argkmin.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
723 |
+
env-my/Lib/site-packages/sklearn/metrics/_pairwise_distances_reduction/_argkmin_classmode.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
724 |
+
env-my/Lib/site-packages/sklearn/metrics/_pairwise_distances_reduction/_base.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
725 |
+
env-my/Lib/site-packages/sklearn/metrics/_pairwise_distances_reduction/_datasets_pair.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
726 |
+
env-my/Lib/site-packages/sklearn/metrics/_pairwise_distances_reduction/_middle_term_computer.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
727 |
+
env-my/Lib/site-packages/sklearn/metrics/_pairwise_distances_reduction/_radius_neighbors.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
728 |
+
env-my/Lib/site-packages/sklearn/metrics/_pairwise_distances_reduction/_radius_neighbors_classmode.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
729 |
+
env-my/Lib/site-packages/sklearn/metrics/_pairwise_fast.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
730 |
+
env-my/Lib/site-packages/sklearn/metrics/cluster/_expected_mutual_info_fast.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
731 |
+
env-my/Lib/site-packages/sklearn/metrics/tests/__pycache__/test_classification.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
732 |
+
env-my/Lib/site-packages/sklearn/metrics/tests/__pycache__/test_ranking.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
733 |
+
env-my/Lib/site-packages/sklearn/model_selection/__pycache__/_split.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
734 |
+
env-my/Lib/site-packages/sklearn/model_selection/tests/__pycache__/test_search.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
735 |
+
env-my/Lib/site-packages/sklearn/model_selection/tests/__pycache__/test_split.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
736 |
+
env-my/Lib/site-packages/sklearn/model_selection/tests/__pycache__/test_validation.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
737 |
+
env-my/Lib/site-packages/sklearn/neighbors/_ball_tree.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
738 |
+
env-my/Lib/site-packages/sklearn/neighbors/_kd_tree.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
739 |
+
env-my/Lib/site-packages/sklearn/neighbors/_quad_tree.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
740 |
+
env-my/Lib/site-packages/sklearn/neighbors/tests/__pycache__/test_neighbors.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
741 |
+
env-my/Lib/site-packages/sklearn/preprocessing/__pycache__/_data.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
742 |
+
env-my/Lib/site-packages/sklearn/preprocessing/_csr_polynomial_expansion.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
743 |
+
env-my/Lib/site-packages/sklearn/preprocessing/_target_encoder_fast.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
744 |
+
env-my/Lib/site-packages/sklearn/preprocessing/tests/__pycache__/test_data.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
745 |
+
env-my/Lib/site-packages/sklearn/preprocessing/tests/__pycache__/test_encoders.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
746 |
+
env-my/Lib/site-packages/sklearn/svm/_liblinear.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
747 |
+
env-my/Lib/site-packages/sklearn/svm/_libsvm.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
748 |
+
env-my/Lib/site-packages/sklearn/svm/_libsvm_sparse.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
749 |
+
env-my/Lib/site-packages/sklearn/tests/__pycache__/test_pipeline.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
750 |
+
env-my/Lib/site-packages/sklearn/tree/_criterion.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
751 |
+
env-my/Lib/site-packages/sklearn/tree/_partitioner.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
752 |
+
env-my/Lib/site-packages/sklearn/tree/_splitter.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
753 |
+
env-my/Lib/site-packages/sklearn/tree/_tree.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
754 |
+
env-my/Lib/site-packages/sklearn/tree/_utils.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
755 |
+
env-my/Lib/site-packages/sklearn/tree/tests/__pycache__/test_tree.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
756 |
+
env-my/Lib/site-packages/sklearn/utils/__pycache__/estimator_checks.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
757 |
+
env-my/Lib/site-packages/sklearn/utils/__pycache__/validation.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
758 |
+
env-my/Lib/site-packages/sklearn/utils/_cython_blas.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
759 |
+
env-my/Lib/site-packages/sklearn/utils/_fast_dict.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
760 |
+
env-my/Lib/site-packages/sklearn/utils/_isfinite.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
761 |
+
env-my/Lib/site-packages/sklearn/utils/_random.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
762 |
+
env-my/Lib/site-packages/sklearn/utils/_seq_dataset.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
763 |
+
env-my/Lib/site-packages/sklearn/utils/_typedefs.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
764 |
+
env-my/Lib/site-packages/sklearn/utils/_vector_sentinel.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
765 |
+
env-my/Lib/site-packages/sklearn/utils/_weight_vector.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
766 |
+
env-my/Lib/site-packages/sklearn/utils/arrayfuncs.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
767 |
+
env-my/Lib/site-packages/sklearn/utils/murmurhash.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
768 |
+
env-my/Lib/site-packages/sklearn/utils/sparsefuncs_fast.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
769 |
+
env-my/Lib/site-packages/sklearn/utils/tests/__pycache__/test_estimator_checks.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
770 |
+
env-my/Lib/site-packages/sklearn/utils/tests/__pycache__/test_validation.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
771 |
+
env-my/Lib/site-packages/soxr/soxr_ext.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
772 |
+
env-my/Lib/site-packages/sympy/assumptions/tests/__pycache__/test_query.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
773 |
+
env-my/Lib/site-packages/sympy/combinatorics/__pycache__/perm_groups.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
774 |
+
env-my/Lib/site-packages/sympy/combinatorics/__pycache__/permutations.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
775 |
+
env-my/Lib/site-packages/sympy/concrete/tests/__pycache__/test_sums_products.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
776 |
+
env-my/Lib/site-packages/sympy/core/__pycache__/expr.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
777 |
+
env-my/Lib/site-packages/sympy/core/__pycache__/function.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
778 |
+
env-my/Lib/site-packages/sympy/core/__pycache__/numbers.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
779 |
+
env-my/Lib/site-packages/sympy/core/tests/__pycache__/test_args.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
780 |
+
env-my/Lib/site-packages/sympy/core/tests/__pycache__/test_arit.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
781 |
+
env-my/Lib/site-packages/sympy/core/tests/__pycache__/test_expr.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
782 |
+
env-my/Lib/site-packages/sympy/core/tests/__pycache__/test_function.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
783 |
+
env-my/Lib/site-packages/sympy/core/tests/__pycache__/test_numbers.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
784 |
+
env-my/Lib/site-packages/sympy/core/tests/__pycache__/test_relational.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
785 |
+
env-my/Lib/site-packages/sympy/crypto/__pycache__/crypto.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
786 |
+
env-my/Lib/site-packages/sympy/diffgeom/__pycache__/diffgeom.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
787 |
+
env-my/Lib/site-packages/sympy/functions/combinatorial/__pycache__/numbers.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
788 |
+
env-my/Lib/site-packages/sympy/functions/combinatorial/tests/__pycache__/test_comb_numbers.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
789 |
+
env-my/Lib/site-packages/sympy/functions/elementary/__pycache__/hyperbolic.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
790 |
+
env-my/Lib/site-packages/sympy/functions/elementary/__pycache__/trigonometric.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
791 |
+
env-my/Lib/site-packages/sympy/functions/elementary/tests/__pycache__/test_hyperbolic.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
792 |
+
env-my/Lib/site-packages/sympy/functions/elementary/tests/__pycache__/test_piecewise.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
793 |
+
env-my/Lib/site-packages/sympy/functions/elementary/tests/__pycache__/test_trigonometric.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
794 |
+
env-my/Lib/site-packages/sympy/functions/special/__pycache__/bessel.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
795 |
+
env-my/Lib/site-packages/sympy/functions/special/__pycache__/error_functions.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
796 |
+
env-my/Lib/site-packages/sympy/functions/special/tests/__pycache__/test_bessel.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
797 |
+
env-my/Lib/site-packages/sympy/functions/special/tests/__pycache__/test_error_functions.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
798 |
+
env-my/Lib/site-packages/sympy/geometry/__pycache__/polygon.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
799 |
+
env-my/Lib/site-packages/sympy/holonomic/__pycache__/holonomic.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
800 |
+
env-my/Lib/site-packages/sympy/integrals/__pycache__/laplace.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
801 |
+
env-my/Lib/site-packages/sympy/integrals/__pycache__/manualintegrate.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
802 |
+
env-my/Lib/site-packages/sympy/integrals/__pycache__/meijerint.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
803 |
+
env-my/Lib/site-packages/sympy/integrals/tests/__pycache__/test_integrals.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
804 |
+
env-my/Lib/site-packages/sympy/integrals/tests/__pycache__/test_laplace.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
805 |
+
env-my/Lib/site-packages/sympy/integrals/tests/__pycache__/test_manual.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
806 |
+
env-my/Lib/site-packages/sympy/integrals/tests/__pycache__/test_risch.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
807 |
+
env-my/Lib/site-packages/sympy/logic/__pycache__/boolalg.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
808 |
+
env-my/Lib/site-packages/sympy/logic/tests/__pycache__/test_boolalg.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
809 |
+
env-my/Lib/site-packages/sympy/matrices/__pycache__/common.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
810 |
+
env-my/Lib/site-packages/sympy/matrices/__pycache__/matrixbase.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
811 |
+
env-my/Lib/site-packages/sympy/matrices/tests/__pycache__/test_matrices.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
812 |
+
env-my/Lib/site-packages/sympy/matrices/tests/__pycache__/test_matrixbase.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
813 |
+
env-my/Lib/site-packages/sympy/parsing/autolev/__pycache__/_listener_autolev_antlr.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
814 |
+
env-my/Lib/site-packages/sympy/parsing/autolev/_antlr/__pycache__/autolevparser.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
815 |
+
env-my/Lib/site-packages/sympy/parsing/latex/_antlr/__pycache__/latexparser.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
816 |
+
env-my/Lib/site-packages/sympy/parsing/tests/__pycache__/test_c_parser.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
817 |
+
env-my/Lib/site-packages/sympy/physics/__pycache__/secondquant.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
818 |
+
env-my/Lib/site-packages/sympy/physics/biomechanics/tests/__pycache__/test_curve.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
819 |
+
env-my/Lib/site-packages/sympy/physics/continuum_mechanics/__pycache__/beam.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
820 |
+
env-my/Lib/site-packages/sympy/physics/control/__pycache__/lti.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
821 |
+
env-my/Lib/site-packages/sympy/physics/control/tests/__pycache__/test_lti.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
822 |
+
env-my/Lib/site-packages/sympy/physics/mechanics/tests/__pycache__/test_joint.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
823 |
+
env-my/Lib/site-packages/sympy/physics/quantum/__pycache__/spin.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
824 |
+
env-my/Lib/site-packages/sympy/physics/quantum/tests/__pycache__/test_spin.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
825 |
+
env-my/Lib/site-packages/sympy/physics/tests/__pycache__/test_secondquant.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
826 |
+
env-my/Lib/site-packages/sympy/plotting/__pycache__/series.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
827 |
+
env-my/Lib/site-packages/sympy/plotting/tests/__pycache__/test_series.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
828 |
+
env-my/Lib/site-packages/sympy/polys/__pycache__/compatibility.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
829 |
+
env-my/Lib/site-packages/sympy/polys/__pycache__/polyclasses.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
830 |
+
env-my/Lib/site-packages/sympy/polys/__pycache__/polyquinticconst.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
831 |
+
env-my/Lib/site-packages/sympy/polys/__pycache__/polytools.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
832 |
+
env-my/Lib/site-packages/sympy/polys/__pycache__/rings.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
833 |
+
env-my/Lib/site-packages/sympy/polys/benchmarks/__pycache__/bench_solvers.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
834 |
+
env-my/Lib/site-packages/sympy/polys/domains/tests/__pycache__/test_domains.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
835 |
+
env-my/Lib/site-packages/sympy/polys/matrices/__pycache__/domainmatrix.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
836 |
+
env-my/Lib/site-packages/sympy/polys/matrices/tests/__pycache__/test_domainmatrix.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
837 |
+
env-my/Lib/site-packages/sympy/polys/numberfields/__pycache__/resolvent_lookup.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
838 |
+
env-my/Lib/site-packages/sympy/polys/tests/__pycache__/test_polytools.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
839 |
+
env-my/Lib/site-packages/sympy/polys/tests/__pycache__/test_rings.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
840 |
+
env-my/Lib/site-packages/sympy/printing/__pycache__/latex.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
841 |
+
env-my/Lib/site-packages/sympy/printing/__pycache__/mathml.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
842 |
+
env-my/Lib/site-packages/sympy/printing/pretty/__pycache__/pretty.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
843 |
+
env-my/Lib/site-packages/sympy/printing/pretty/tests/__pycache__/test_pretty.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
844 |
+
env-my/Lib/site-packages/sympy/printing/tests/__pycache__/test_latex.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
845 |
+
env-my/Lib/site-packages/sympy/printing/tests/__pycache__/test_mathml.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
846 |
+
env-my/Lib/site-packages/sympy/printing/tests/__pycache__/test_str.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
847 |
+
env-my/Lib/site-packages/sympy/series/tests/__pycache__/test_limits.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
848 |
+
env-my/Lib/site-packages/sympy/sets/__pycache__/sets.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
849 |
+
env-my/Lib/site-packages/sympy/sets/tests/__pycache__/test_fancysets.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
850 |
+
env-my/Lib/site-packages/sympy/sets/tests/__pycache__/test_sets.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
851 |
+
env-my/Lib/site-packages/sympy/simplify/__pycache__/hyperexpand.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
852 |
+
env-my/Lib/site-packages/sympy/simplify/tests/__pycache__/test_simplify.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
853 |
+
env-my/Lib/site-packages/sympy/solvers/__pycache__/solvers.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
854 |
+
env-my/Lib/site-packages/sympy/solvers/__pycache__/solveset.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
855 |
+
env-my/Lib/site-packages/sympy/solvers/diophantine/__pycache__/diophantine.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
856 |
+
env-my/Lib/site-packages/sympy/solvers/diophantine/tests/__pycache__/test_diophantine.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
857 |
+
env-my/Lib/site-packages/sympy/solvers/ode/__pycache__/ode.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
858 |
+
env-my/Lib/site-packages/sympy/solvers/ode/__pycache__/single.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
859 |
+
env-my/Lib/site-packages/sympy/solvers/ode/__pycache__/systems.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
860 |
+
env-my/Lib/site-packages/sympy/solvers/ode/tests/__pycache__/test_ode.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
861 |
+
env-my/Lib/site-packages/sympy/solvers/ode/tests/__pycache__/test_single.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
862 |
+
env-my/Lib/site-packages/sympy/solvers/ode/tests/__pycache__/test_systems.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
863 |
+
env-my/Lib/site-packages/sympy/solvers/tests/__pycache__/test_solvers.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
864 |
+
env-my/Lib/site-packages/sympy/solvers/tests/__pycache__/test_solveset.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
865 |
+
env-my/Lib/site-packages/sympy/stats/__pycache__/crv_types.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
866 |
+
env-my/Lib/site-packages/sympy/stats/__pycache__/stochastic_process_types.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
867 |
+
env-my/Lib/site-packages/sympy/stats/tests/__pycache__/test_continuous_rv.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
868 |
+
env-my/Lib/site-packages/sympy/stats/tests/__pycache__/test_stochastic_process.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
869 |
+
env-my/Lib/site-packages/sympy/tensor/__pycache__/tensor.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
870 |
+
env-my/Lib/site-packages/sympy/tensor/array/expressions/__pycache__/array_expressions.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
871 |
+
env-my/Lib/site-packages/sympy/tensor/tests/__pycache__/test_tensor.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
872 |
+
env-my/Lib/site-packages/sympy/testing/__pycache__/runtests.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
873 |
+
env-my/Lib/site-packages/sympy/utilities/__pycache__/codegen.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
874 |
+
env-my/Lib/site-packages/sympy/utilities/__pycache__/iterables.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
875 |
+
env-my/Lib/site-packages/sympy/utilities/tests/__pycache__/test_lambdify.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
876 |
+
env-my/Lib/site-packages/sympy/utilities/tests/__pycache__/test_wester.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
|
877 |
+
env-my/Lib/site-packages/tokenizers/tokenizers.pyd filter=lfs diff=lfs merge=lfs -text
|
878 |
+
env-my/Lib/site-packages/yaml/_yaml.cp311-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
879 |
+
env-my/Scripts/coloredlogs.exe filter=lfs diff=lfs merge=lfs -text
|
880 |
+
env-my/Scripts/csv2rdf.exe filter=lfs diff=lfs merge=lfs -text
|
881 |
+
env-my/Scripts/csvw2datasette.exe filter=lfs diff=lfs merge=lfs -text
|
882 |
+
env-my/Scripts/csvw2json.exe filter=lfs diff=lfs merge=lfs -text
|
883 |
+
env-my/Scripts/csvw2markdown.exe filter=lfs diff=lfs merge=lfs -text
|
884 |
+
env-my/Scripts/csvw2sqlite.exe filter=lfs diff=lfs merge=lfs -text
|
885 |
+
env-my/Scripts/csvwdescribe.exe filter=lfs diff=lfs merge=lfs -text
|
886 |
+
env-my/Scripts/csvwvalidate.exe filter=lfs diff=lfs merge=lfs -text
|
887 |
+
env-my/Scripts/distro.exe filter=lfs diff=lfs merge=lfs -text
|
888 |
+
env-my/Scripts/f2py.exe filter=lfs diff=lfs merge=lfs -text
|
889 |
+
env-my/Scripts/fastapi.exe filter=lfs diff=lfs merge=lfs -text
|
890 |
+
env-my/Scripts/futurize.exe filter=lfs diff=lfs merge=lfs -text
|
891 |
+
env-my/Scripts/gradio.exe filter=lfs diff=lfs merge=lfs -text
|
892 |
+
env-my/Scripts/httpx.exe filter=lfs diff=lfs merge=lfs -text
|
893 |
+
env-my/Scripts/huggingface-cli.exe filter=lfs diff=lfs merge=lfs -text
|
894 |
+
env-my/Scripts/humanfriendly.exe filter=lfs diff=lfs merge=lfs -text
|
895 |
+
env-my/Scripts/isympy.exe filter=lfs diff=lfs merge=lfs -text
|
896 |
+
env-my/Scripts/jsonschema.exe filter=lfs diff=lfs merge=lfs -text
|
897 |
+
env-my/Scripts/markdown-it.exe filter=lfs diff=lfs merge=lfs -text
|
898 |
+
env-my/Scripts/normalizer.exe filter=lfs diff=lfs merge=lfs -text
|
899 |
+
env-my/Scripts/numpy-config.exe filter=lfs diff=lfs merge=lfs -text
|
900 |
+
env-my/Scripts/onnxruntime_test.exe filter=lfs diff=lfs merge=lfs -text
|
901 |
+
env-my/Scripts/openai.exe filter=lfs diff=lfs merge=lfs -text
|
902 |
+
env-my/Scripts/pasteurize.exe filter=lfs diff=lfs merge=lfs -text
|
903 |
+
env-my/Scripts/phonemize.exe filter=lfs diff=lfs merge=lfs -text
|
904 |
+
env-my/Scripts/pip.exe filter=lfs diff=lfs merge=lfs -text
|
905 |
+
env-my/Scripts/pip3.11.exe filter=lfs diff=lfs merge=lfs -text
|
906 |
+
env-my/Scripts/pip3.exe filter=lfs diff=lfs merge=lfs -text
|
907 |
+
env-my/Scripts/pyav.exe filter=lfs diff=lfs merge=lfs -text
|
908 |
+
env-my/Scripts/pybabel.exe filter=lfs diff=lfs merge=lfs -text
|
909 |
+
env-my/Scripts/pygmentize.exe filter=lfs diff=lfs merge=lfs -text
|
910 |
+
env-my/Scripts/python.exe filter=lfs diff=lfs merge=lfs -text
|
911 |
+
env-my/Scripts/pythonw.exe filter=lfs diff=lfs merge=lfs -text
|
912 |
+
env-my/Scripts/rdf2dot.exe filter=lfs diff=lfs merge=lfs -text
|
913 |
+
env-my/Scripts/rdfgraphisomorphism.exe filter=lfs diff=lfs merge=lfs -text
|
914 |
+
env-my/Scripts/rdfpipe.exe filter=lfs diff=lfs merge=lfs -text
|
915 |
+
env-my/Scripts/rdfs2dot.exe filter=lfs diff=lfs merge=lfs -text
|
916 |
+
env-my/Scripts/ruff.exe filter=lfs diff=lfs merge=lfs -text
|
917 |
+
env-my/Scripts/segments.exe filter=lfs diff=lfs merge=lfs -text
|
918 |
+
env-my/Scripts/tqdm.exe filter=lfs diff=lfs merge=lfs -text
|
919 |
+
env-my/Scripts/typer.exe filter=lfs diff=lfs merge=lfs -text
|
920 |
+
env-my/Scripts/upload_theme.exe filter=lfs diff=lfs merge=lfs -text
|
921 |
+
env-my/Scripts/uvicorn.exe filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
@@ -1,12 +1,6 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
|
4 |
-
colorFrom: red
|
5 |
-
colorTo: green
|
6 |
sdk: gradio
|
7 |
sdk_version: 5.20.0
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
---
|
11 |
-
|
12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: fast-rtc
|
3 |
+
app_file: app.py
|
|
|
|
|
4 |
sdk: gradio
|
5 |
sdk_version: 5.20.0
|
|
|
|
|
6 |
---
|
|
|
|
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# import os
|
2 |
+
|
3 |
+
# from fastrtc import (ReplyOnPause, Stream, get_stt_model, get_tts_model)
|
4 |
+
# from openai import OpenAI
|
5 |
+
|
6 |
+
# OpenAI.api_key = '5dd0312c-a759-42e8-a21d-6bbe275e7aa2'
|
7 |
+
|
8 |
+
# sambanova_client = OpenAI(
|
9 |
+
# api_key="5dd0312c-a759-42e8-a21d-6bbe275e7aa2", base_url="https://api.sambanova.ai/v1"
|
10 |
+
# )
|
11 |
+
# stt_model = get_stt_model()
|
12 |
+
# tts_model = get_tts_model()
|
13 |
+
|
14 |
+
# def echo(audio):
|
15 |
+
# prompt = stt_model.stt(audio)
|
16 |
+
# response = sambanova_client.chat.completions.create(
|
17 |
+
# model="Meta-Llama-3.2-3B-Instruct",
|
18 |
+
# messages=[{"role": "user", "content": prompt}],
|
19 |
+
# max_tokens=200,
|
20 |
+
# )
|
21 |
+
# prompt = response.choices[0].message.content
|
22 |
+
# for audio_chunk in tts_model.stream_tts_sync(prompt):
|
23 |
+
# yield audio_chunk
|
24 |
+
|
25 |
+
# stream = Stream(ReplyOnPause(echo), modality="audio", mode="send-receive")
|
26 |
+
# stream.ui.launch()
|
27 |
+
|
28 |
+
from fastrtc import Stream, ReplyOnPause
|
29 |
+
import numpy as np
|
30 |
+
from pydub import AudioSegment
|
31 |
+
from pydub.utils import which
|
32 |
+
|
33 |
+
AudioSegment.ffmpeg = which("ffmpeg")
|
34 |
+
|
35 |
+
def echo(audio: tuple[int, np.ndarray]) -> tuple[int, np.ndarray]:
|
36 |
+
yield audio
|
37 |
+
|
38 |
+
stream = Stream(ReplyOnPause(echo), modality="audio", mode="send-receive")
|
39 |
+
|
40 |
+
stream.ui.launch(share=True)
|
env-my/Lib/site-packages/MarkupSafe-2.1.5.dist-info/INSTALLER
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
pip
|
env-my/Lib/site-packages/MarkupSafe-2.1.5.dist-info/LICENSE.rst
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Copyright 2010 Pallets
|
2 |
+
|
3 |
+
Redistribution and use in source and binary forms, with or without
|
4 |
+
modification, are permitted provided that the following conditions are
|
5 |
+
met:
|
6 |
+
|
7 |
+
1. Redistributions of source code must retain the above copyright
|
8 |
+
notice, this list of conditions and the following disclaimer.
|
9 |
+
|
10 |
+
2. Redistributions in binary form must reproduce the above copyright
|
11 |
+
notice, this list of conditions and the following disclaimer in the
|
12 |
+
documentation and/or other materials provided with the distribution.
|
13 |
+
|
14 |
+
3. Neither the name of the copyright holder nor the names of its
|
15 |
+
contributors may be used to endorse or promote products derived from
|
16 |
+
this software without specific prior written permission.
|
17 |
+
|
18 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
19 |
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
20 |
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
21 |
+
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
22 |
+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
23 |
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
24 |
+
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
25 |
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
26 |
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
27 |
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
28 |
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
env-my/Lib/site-packages/MarkupSafe-2.1.5.dist-info/METADATA
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Metadata-Version: 2.1
|
2 |
+
Name: MarkupSafe
|
3 |
+
Version: 2.1.5
|
4 |
+
Summary: Safely add untrusted strings to HTML/XML markup.
|
5 |
+
Home-page: https://palletsprojects.com/p/markupsafe/
|
6 |
+
Maintainer: Pallets
|
7 |
+
Maintainer-email: [email protected]
|
8 |
+
License: BSD-3-Clause
|
9 |
+
Project-URL: Donate, https://palletsprojects.com/donate
|
10 |
+
Project-URL: Documentation, https://markupsafe.palletsprojects.com/
|
11 |
+
Project-URL: Changes, https://markupsafe.palletsprojects.com/changes/
|
12 |
+
Project-URL: Source Code, https://github.com/pallets/markupsafe/
|
13 |
+
Project-URL: Issue Tracker, https://github.com/pallets/markupsafe/issues/
|
14 |
+
Project-URL: Chat, https://discord.gg/pallets
|
15 |
+
Classifier: Development Status :: 5 - Production/Stable
|
16 |
+
Classifier: Environment :: Web Environment
|
17 |
+
Classifier: Intended Audience :: Developers
|
18 |
+
Classifier: License :: OSI Approved :: BSD License
|
19 |
+
Classifier: Operating System :: OS Independent
|
20 |
+
Classifier: Programming Language :: Python
|
21 |
+
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
|
22 |
+
Classifier: Topic :: Text Processing :: Markup :: HTML
|
23 |
+
Requires-Python: >=3.7
|
24 |
+
Description-Content-Type: text/x-rst
|
25 |
+
License-File: LICENSE.rst
|
26 |
+
|
27 |
+
MarkupSafe
|
28 |
+
==========
|
29 |
+
|
30 |
+
MarkupSafe implements a text object that escapes characters so it is
|
31 |
+
safe to use in HTML and XML. Characters that have special meanings are
|
32 |
+
replaced so that they display as the actual characters. This mitigates
|
33 |
+
injection attacks, meaning untrusted user input can safely be displayed
|
34 |
+
on a page.
|
35 |
+
|
36 |
+
|
37 |
+
Installing
|
38 |
+
----------
|
39 |
+
|
40 |
+
Install and update using `pip`_:
|
41 |
+
|
42 |
+
.. code-block:: text
|
43 |
+
|
44 |
+
pip install -U MarkupSafe
|
45 |
+
|
46 |
+
.. _pip: https://pip.pypa.io/en/stable/getting-started/
|
47 |
+
|
48 |
+
|
49 |
+
Examples
|
50 |
+
--------
|
51 |
+
|
52 |
+
.. code-block:: pycon
|
53 |
+
|
54 |
+
>>> from markupsafe import Markup, escape
|
55 |
+
|
56 |
+
>>> # escape replaces special characters and wraps in Markup
|
57 |
+
>>> escape("<script>alert(document.cookie);</script>")
|
58 |
+
Markup('<script>alert(document.cookie);</script>')
|
59 |
+
|
60 |
+
>>> # wrap in Markup to mark text "safe" and prevent escaping
|
61 |
+
>>> Markup("<strong>Hello</strong>")
|
62 |
+
Markup('<strong>hello</strong>')
|
63 |
+
|
64 |
+
>>> escape(Markup("<strong>Hello</strong>"))
|
65 |
+
Markup('<strong>hello</strong>')
|
66 |
+
|
67 |
+
>>> # Markup is a str subclass
|
68 |
+
>>> # methods and operators escape their arguments
|
69 |
+
>>> template = Markup("Hello <em>{name}</em>")
|
70 |
+
>>> template.format(name='"World"')
|
71 |
+
Markup('Hello <em>"World"</em>')
|
72 |
+
|
73 |
+
|
74 |
+
Donate
|
75 |
+
------
|
76 |
+
|
77 |
+
The Pallets organization develops and supports MarkupSafe and other
|
78 |
+
popular packages. In order to grow the community of contributors and
|
79 |
+
users, and allow the maintainers to devote more time to the projects,
|
80 |
+
`please donate today`_.
|
81 |
+
|
82 |
+
.. _please donate today: https://palletsprojects.com/donate
|
83 |
+
|
84 |
+
|
85 |
+
Links
|
86 |
+
-----
|
87 |
+
|
88 |
+
- Documentation: https://markupsafe.palletsprojects.com/
|
89 |
+
- Changes: https://markupsafe.palletsprojects.com/changes/
|
90 |
+
- PyPI Releases: https://pypi.org/project/MarkupSafe/
|
91 |
+
- Source Code: https://github.com/pallets/markupsafe/
|
92 |
+
- Issue Tracker: https://github.com/pallets/markupsafe/issues/
|
93 |
+
- Chat: https://discord.gg/pallets
|
env-my/Lib/site-packages/MarkupSafe-2.1.5.dist-info/RECORD
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
MarkupSafe-2.1.5.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
2 |
+
MarkupSafe-2.1.5.dist-info/LICENSE.rst,sha256=RjHsDbX9kKVH4zaBcmTGeYIUM4FG-KyUtKV_lu6MnsQ,1503
|
3 |
+
MarkupSafe-2.1.5.dist-info/METADATA,sha256=icNlaniV7YIQZ1BScCVqNaRtm7MAgfw8d3OBmoSVyAY,3096
|
4 |
+
MarkupSafe-2.1.5.dist-info/RECORD,,
|
5 |
+
MarkupSafe-2.1.5.dist-info/WHEEL,sha256=ircjsfhzblqgSzO8ow7-0pXK-RVqDqNRGQ8F650AUNM,102
|
6 |
+
MarkupSafe-2.1.5.dist-info/top_level.txt,sha256=qy0Plje5IJuvsCBjejJyhDCjEAdcDLK_2agVcex8Z6U,11
|
7 |
+
markupsafe/__init__.py,sha256=m1ysNeqf55zbEoJtaovca40ivrkEFolPlw5bGoC5Gi4,11290
|
8 |
+
markupsafe/__pycache__/__init__.cpython-311.pyc,,
|
9 |
+
markupsafe/__pycache__/_native.cpython-311.pyc,,
|
10 |
+
markupsafe/_native.py,sha256=_Q7UsXCOvgdonCgqG3l5asANI6eo50EKnDM-mlwEC5M,1776
|
11 |
+
markupsafe/_speedups.c,sha256=n3jzzaJwXcoN8nTFyA53f3vSqsWK2vujI-v6QYifjhQ,7403
|
12 |
+
markupsafe/_speedups.cp311-win_amd64.pyd,sha256=MEqnkyBOHmstwQr50hKitovHjrHhMJ0gYmya4Fu1DK0,15872
|
13 |
+
markupsafe/_speedups.pyi,sha256=f5QtwIOP0eLrxh2v5p6SmaYmlcHIGIfmz0DovaqL0OU,238
|
14 |
+
markupsafe/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
env-my/Lib/site-packages/MarkupSafe-2.1.5.dist-info/WHEEL
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Wheel-Version: 1.0
|
2 |
+
Generator: bdist_wheel (0.42.0)
|
3 |
+
Root-Is-Purelib: false
|
4 |
+
Tag: cp311-cp311-win_amd64
|
5 |
+
|
env-my/Lib/site-packages/MarkupSafe-2.1.5.dist-info/top_level.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
markupsafe
|
env-my/Lib/site-packages/OpenSSL/SSL.py
ADDED
The diff for this file is too large to render.
See raw diff
|
|
env-my/Lib/site-packages/OpenSSL/__init__.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright (C) AB Strakt
|
2 |
+
# See LICENSE for details.
|
3 |
+
|
4 |
+
"""
|
5 |
+
pyOpenSSL - A simple wrapper around the OpenSSL library
|
6 |
+
"""
|
7 |
+
|
8 |
+
from OpenSSL import SSL, crypto
|
9 |
+
from OpenSSL.version import (
|
10 |
+
__author__,
|
11 |
+
__copyright__,
|
12 |
+
__email__,
|
13 |
+
__license__,
|
14 |
+
__summary__,
|
15 |
+
__title__,
|
16 |
+
__uri__,
|
17 |
+
__version__,
|
18 |
+
)
|
19 |
+
|
20 |
+
__all__ = [
|
21 |
+
"SSL",
|
22 |
+
"__author__",
|
23 |
+
"__copyright__",
|
24 |
+
"__email__",
|
25 |
+
"__license__",
|
26 |
+
"__summary__",
|
27 |
+
"__title__",
|
28 |
+
"__uri__",
|
29 |
+
"__version__",
|
30 |
+
"crypto",
|
31 |
+
]
|
env-my/Lib/site-packages/OpenSSL/__pycache__/SSL.cpython-311.pyc
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8a5faa795e13297d79679a533f2723aa00998ccc65681240fe6afc2805f23a05
|
3 |
+
size 138984
|
env-my/Lib/site-packages/OpenSSL/__pycache__/__init__.cpython-311.pyc
ADDED
Binary file (717 Bytes). View file
|
|
env-my/Lib/site-packages/OpenSSL/__pycache__/_util.cpython-311.pyc
ADDED
Binary file (5.47 kB). View file
|
|
env-my/Lib/site-packages/OpenSSL/__pycache__/crypto.cpython-311.pyc
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d89942253816276f767384a27e5506db1cf2191214a10e77257617f214eddb14
|
3 |
+
size 110305
|
env-my/Lib/site-packages/OpenSSL/__pycache__/debug.cpython-311.pyc
ADDED
Binary file (1.67 kB). View file
|
|
env-my/Lib/site-packages/OpenSSL/__pycache__/rand.cpython-311.pyc
ADDED
Binary file (2.03 kB). View file
|
|
env-my/Lib/site-packages/OpenSSL/__pycache__/version.cpython-311.pyc
ADDED
Binary file (713 Bytes). View file
|
|
env-my/Lib/site-packages/OpenSSL/_util.py
ADDED
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from __future__ import annotations
|
2 |
+
|
3 |
+
import os
|
4 |
+
import sys
|
5 |
+
import warnings
|
6 |
+
from typing import Any, Callable, NoReturn, Union
|
7 |
+
|
8 |
+
from cryptography.hazmat.bindings.openssl.binding import Binding
|
9 |
+
|
10 |
+
if sys.version_info >= (3, 9):
|
11 |
+
StrOrBytesPath = Union[str, bytes, os.PathLike[str], os.PathLike[bytes]]
|
12 |
+
else:
|
13 |
+
StrOrBytesPath = Union[str, bytes, os.PathLike]
|
14 |
+
|
15 |
+
binding = Binding()
|
16 |
+
ffi = binding.ffi
|
17 |
+
lib = binding.lib
|
18 |
+
|
19 |
+
|
20 |
+
# This is a special CFFI allocator that does not bother to zero its memory
|
21 |
+
# after allocation. This has vastly better performance on large allocations and
|
22 |
+
# so should be used whenever we don't need the memory zeroed out.
|
23 |
+
no_zero_allocator = ffi.new_allocator(should_clear_after_alloc=False)
|
24 |
+
|
25 |
+
|
26 |
+
def text(charp: Any) -> str:
|
27 |
+
"""
|
28 |
+
Get a native string type representing of the given CFFI ``char*`` object.
|
29 |
+
|
30 |
+
:param charp: A C-style string represented using CFFI.
|
31 |
+
|
32 |
+
:return: :class:`str`
|
33 |
+
"""
|
34 |
+
if not charp:
|
35 |
+
return ""
|
36 |
+
return ffi.string(charp).decode("utf-8")
|
37 |
+
|
38 |
+
|
39 |
+
def exception_from_error_queue(exception_type: type[Exception]) -> NoReturn:
|
40 |
+
"""
|
41 |
+
Convert an OpenSSL library failure into a Python exception.
|
42 |
+
|
43 |
+
When a call to the native OpenSSL library fails, this is usually signalled
|
44 |
+
by the return value, and an error code is stored in an error queue
|
45 |
+
associated with the current thread. The err library provides functions to
|
46 |
+
obtain these error codes and textual error messages.
|
47 |
+
"""
|
48 |
+
errors = []
|
49 |
+
|
50 |
+
while True:
|
51 |
+
error = lib.ERR_get_error()
|
52 |
+
if error == 0:
|
53 |
+
break
|
54 |
+
errors.append(
|
55 |
+
(
|
56 |
+
text(lib.ERR_lib_error_string(error)),
|
57 |
+
text(lib.ERR_func_error_string(error)),
|
58 |
+
text(lib.ERR_reason_error_string(error)),
|
59 |
+
)
|
60 |
+
)
|
61 |
+
|
62 |
+
raise exception_type(errors)
|
63 |
+
|
64 |
+
|
65 |
+
def make_assert(error: type[Exception]) -> Callable[[bool], Any]:
|
66 |
+
"""
|
67 |
+
Create an assert function that uses :func:`exception_from_error_queue` to
|
68 |
+
raise an exception wrapped by *error*.
|
69 |
+
"""
|
70 |
+
|
71 |
+
def openssl_assert(ok: bool) -> None:
|
72 |
+
"""
|
73 |
+
If *ok* is not True, retrieve the error from OpenSSL and raise it.
|
74 |
+
"""
|
75 |
+
if ok is not True:
|
76 |
+
exception_from_error_queue(error)
|
77 |
+
|
78 |
+
return openssl_assert
|
79 |
+
|
80 |
+
|
81 |
+
def path_bytes(s: StrOrBytesPath) -> bytes:
|
82 |
+
"""
|
83 |
+
Convert a Python path to a :py:class:`bytes` for the path which can be
|
84 |
+
passed into an OpenSSL API accepting a filename.
|
85 |
+
|
86 |
+
:param s: A path (valid for os.fspath).
|
87 |
+
|
88 |
+
:return: An instance of :py:class:`bytes`.
|
89 |
+
"""
|
90 |
+
b = os.fspath(s)
|
91 |
+
|
92 |
+
if isinstance(b, str):
|
93 |
+
return b.encode(sys.getfilesystemencoding())
|
94 |
+
else:
|
95 |
+
return b
|
96 |
+
|
97 |
+
|
98 |
+
def byte_string(s: str) -> bytes:
|
99 |
+
return s.encode("charmap")
|
100 |
+
|
101 |
+
|
102 |
+
# A marker object to observe whether some optional arguments are passed any
|
103 |
+
# value or not.
|
104 |
+
UNSPECIFIED = object()
|
105 |
+
|
106 |
+
_TEXT_WARNING = "str for {0} is no longer accepted, use bytes"
|
107 |
+
|
108 |
+
|
109 |
+
def text_to_bytes_and_warn(label: str, obj: Any) -> Any:
|
110 |
+
"""
|
111 |
+
If ``obj`` is text, emit a warning that it should be bytes instead and try
|
112 |
+
to convert it to bytes automatically.
|
113 |
+
|
114 |
+
:param str label: The name of the parameter from which ``obj`` was taken
|
115 |
+
(so a developer can easily find the source of the problem and correct
|
116 |
+
it).
|
117 |
+
|
118 |
+
:return: If ``obj`` is the text string type, a ``bytes`` object giving the
|
119 |
+
UTF-8 encoding of that text is returned. Otherwise, ``obj`` itself is
|
120 |
+
returned.
|
121 |
+
"""
|
122 |
+
if isinstance(obj, str):
|
123 |
+
warnings.warn(
|
124 |
+
_TEXT_WARNING.format(label),
|
125 |
+
category=DeprecationWarning,
|
126 |
+
stacklevel=3,
|
127 |
+
)
|
128 |
+
return obj.encode("utf-8")
|
129 |
+
return obj
|
env-my/Lib/site-packages/OpenSSL/crypto.py
ADDED
@@ -0,0 +1,2450 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from __future__ import annotations
|
2 |
+
|
3 |
+
import calendar
|
4 |
+
import datetime
|
5 |
+
import functools
|
6 |
+
import sys
|
7 |
+
import typing
|
8 |
+
import warnings
|
9 |
+
from base64 import b16encode
|
10 |
+
from collections.abc import Iterable, Sequence
|
11 |
+
from functools import partial
|
12 |
+
from typing import (
|
13 |
+
Any,
|
14 |
+
Callable,
|
15 |
+
Union,
|
16 |
+
)
|
17 |
+
|
18 |
+
if sys.version_info >= (3, 13):
|
19 |
+
from warnings import deprecated
|
20 |
+
elif sys.version_info < (3, 8):
|
21 |
+
_T = typing.TypeVar("T")
|
22 |
+
|
23 |
+
def deprecated(msg: str, **kwargs: object) -> Callable[[_T], _T]:
|
24 |
+
return lambda f: f
|
25 |
+
else:
|
26 |
+
from typing_extensions import deprecated
|
27 |
+
|
28 |
+
from cryptography import utils, x509
|
29 |
+
from cryptography.hazmat.primitives.asymmetric import (
|
30 |
+
dsa,
|
31 |
+
ec,
|
32 |
+
ed448,
|
33 |
+
ed25519,
|
34 |
+
rsa,
|
35 |
+
)
|
36 |
+
|
37 |
+
from OpenSSL._util import StrOrBytesPath
|
38 |
+
from OpenSSL._util import (
|
39 |
+
byte_string as _byte_string,
|
40 |
+
)
|
41 |
+
from OpenSSL._util import (
|
42 |
+
exception_from_error_queue as _exception_from_error_queue,
|
43 |
+
)
|
44 |
+
from OpenSSL._util import (
|
45 |
+
ffi as _ffi,
|
46 |
+
)
|
47 |
+
from OpenSSL._util import (
|
48 |
+
lib as _lib,
|
49 |
+
)
|
50 |
+
from OpenSSL._util import (
|
51 |
+
make_assert as _make_assert,
|
52 |
+
)
|
53 |
+
from OpenSSL._util import (
|
54 |
+
path_bytes as _path_bytes,
|
55 |
+
)
|
56 |
+
|
57 |
+
__all__ = [
|
58 |
+
"FILETYPE_ASN1",
|
59 |
+
"FILETYPE_PEM",
|
60 |
+
"FILETYPE_TEXT",
|
61 |
+
"TYPE_DSA",
|
62 |
+
"TYPE_RSA",
|
63 |
+
"X509",
|
64 |
+
"Error",
|
65 |
+
"PKey",
|
66 |
+
"X509Extension",
|
67 |
+
"X509Name",
|
68 |
+
"X509Req",
|
69 |
+
"X509Store",
|
70 |
+
"X509StoreContext",
|
71 |
+
"X509StoreContextError",
|
72 |
+
"X509StoreFlags",
|
73 |
+
"dump_certificate",
|
74 |
+
"dump_certificate_request",
|
75 |
+
"dump_privatekey",
|
76 |
+
"dump_publickey",
|
77 |
+
"get_elliptic_curve",
|
78 |
+
"get_elliptic_curves",
|
79 |
+
"load_certificate",
|
80 |
+
"load_certificate_request",
|
81 |
+
"load_privatekey",
|
82 |
+
"load_publickey",
|
83 |
+
]
|
84 |
+
|
85 |
+
|
86 |
+
_PrivateKey = Union[
|
87 |
+
dsa.DSAPrivateKey,
|
88 |
+
ec.EllipticCurvePrivateKey,
|
89 |
+
ed25519.Ed25519PrivateKey,
|
90 |
+
ed448.Ed448PrivateKey,
|
91 |
+
rsa.RSAPrivateKey,
|
92 |
+
]
|
93 |
+
_PublicKey = Union[
|
94 |
+
dsa.DSAPublicKey,
|
95 |
+
ec.EllipticCurvePublicKey,
|
96 |
+
ed25519.Ed25519PublicKey,
|
97 |
+
ed448.Ed448PublicKey,
|
98 |
+
rsa.RSAPublicKey,
|
99 |
+
]
|
100 |
+
_Key = Union[_PrivateKey, _PublicKey]
|
101 |
+
PassphraseCallableT = Union[bytes, Callable[..., bytes]]
|
102 |
+
|
103 |
+
|
104 |
+
FILETYPE_PEM: int = _lib.SSL_FILETYPE_PEM
|
105 |
+
FILETYPE_ASN1: int = _lib.SSL_FILETYPE_ASN1
|
106 |
+
|
107 |
+
# TODO This was an API mistake. OpenSSL has no such constant.
|
108 |
+
FILETYPE_TEXT = 2**16 - 1
|
109 |
+
|
110 |
+
TYPE_RSA: int = _lib.EVP_PKEY_RSA
|
111 |
+
TYPE_DSA: int = _lib.EVP_PKEY_DSA
|
112 |
+
TYPE_DH: int = _lib.EVP_PKEY_DH
|
113 |
+
TYPE_EC: int = _lib.EVP_PKEY_EC
|
114 |
+
|
115 |
+
|
116 |
+
class Error(Exception):
|
117 |
+
"""
|
118 |
+
An error occurred in an `OpenSSL.crypto` API.
|
119 |
+
"""
|
120 |
+
|
121 |
+
|
122 |
+
_raise_current_error = partial(_exception_from_error_queue, Error)
|
123 |
+
_openssl_assert = _make_assert(Error)
|
124 |
+
|
125 |
+
|
126 |
+
def _new_mem_buf(buffer: bytes | None = None) -> Any:
|
127 |
+
"""
|
128 |
+
Allocate a new OpenSSL memory BIO.
|
129 |
+
|
130 |
+
Arrange for the garbage collector to clean it up automatically.
|
131 |
+
|
132 |
+
:param buffer: None or some bytes to use to put into the BIO so that they
|
133 |
+
can be read out.
|
134 |
+
"""
|
135 |
+
if buffer is None:
|
136 |
+
bio = _lib.BIO_new(_lib.BIO_s_mem())
|
137 |
+
free = _lib.BIO_free
|
138 |
+
else:
|
139 |
+
data = _ffi.new("char[]", buffer)
|
140 |
+
bio = _lib.BIO_new_mem_buf(data, len(buffer))
|
141 |
+
|
142 |
+
# Keep the memory alive as long as the bio is alive!
|
143 |
+
def free(bio: Any, ref: Any = data) -> Any:
|
144 |
+
return _lib.BIO_free(bio)
|
145 |
+
|
146 |
+
_openssl_assert(bio != _ffi.NULL)
|
147 |
+
|
148 |
+
bio = _ffi.gc(bio, free)
|
149 |
+
return bio
|
150 |
+
|
151 |
+
|
152 |
+
def _bio_to_string(bio: Any) -> bytes:
|
153 |
+
"""
|
154 |
+
Copy the contents of an OpenSSL BIO object into a Python byte string.
|
155 |
+
"""
|
156 |
+
result_buffer = _ffi.new("char**")
|
157 |
+
buffer_length = _lib.BIO_get_mem_data(bio, result_buffer)
|
158 |
+
return _ffi.buffer(result_buffer[0], buffer_length)[:]
|
159 |
+
|
160 |
+
|
161 |
+
def _set_asn1_time(boundary: Any, when: bytes) -> None:
|
162 |
+
"""
|
163 |
+
The the time value of an ASN1 time object.
|
164 |
+
|
165 |
+
@param boundary: An ASN1_TIME pointer (or an object safely
|
166 |
+
castable to that type) which will have its value set.
|
167 |
+
@param when: A string representation of the desired time value.
|
168 |
+
|
169 |
+
@raise TypeError: If C{when} is not a L{bytes} string.
|
170 |
+
@raise ValueError: If C{when} does not represent a time in the required
|
171 |
+
format.
|
172 |
+
@raise RuntimeError: If the time value cannot be set for some other
|
173 |
+
(unspecified) reason.
|
174 |
+
"""
|
175 |
+
if not isinstance(when, bytes):
|
176 |
+
raise TypeError("when must be a byte string")
|
177 |
+
# ASN1_TIME_set_string validates the string without writing anything
|
178 |
+
# when the destination is NULL.
|
179 |
+
_openssl_assert(boundary != _ffi.NULL)
|
180 |
+
|
181 |
+
set_result = _lib.ASN1_TIME_set_string(boundary, when)
|
182 |
+
if set_result == 0:
|
183 |
+
raise ValueError("Invalid string")
|
184 |
+
|
185 |
+
|
186 |
+
def _new_asn1_time(when: bytes) -> Any:
|
187 |
+
"""
|
188 |
+
Behaves like _set_asn1_time but returns a new ASN1_TIME object.
|
189 |
+
|
190 |
+
@param when: A string representation of the desired time value.
|
191 |
+
|
192 |
+
@raise TypeError: If C{when} is not a L{bytes} string.
|
193 |
+
@raise ValueError: If C{when} does not represent a time in the required
|
194 |
+
format.
|
195 |
+
@raise RuntimeError: If the time value cannot be set for some other
|
196 |
+
(unspecified) reason.
|
197 |
+
"""
|
198 |
+
ret = _lib.ASN1_TIME_new()
|
199 |
+
_openssl_assert(ret != _ffi.NULL)
|
200 |
+
ret = _ffi.gc(ret, _lib.ASN1_TIME_free)
|
201 |
+
_set_asn1_time(ret, when)
|
202 |
+
return ret
|
203 |
+
|
204 |
+
|
205 |
+
def _get_asn1_time(timestamp: Any) -> bytes | None:
|
206 |
+
"""
|
207 |
+
Retrieve the time value of an ASN1 time object.
|
208 |
+
|
209 |
+
@param timestamp: An ASN1_GENERALIZEDTIME* (or an object safely castable to
|
210 |
+
that type) from which the time value will be retrieved.
|
211 |
+
|
212 |
+
@return: The time value from C{timestamp} as a L{bytes} string in a certain
|
213 |
+
format. Or C{None} if the object contains no time value.
|
214 |
+
"""
|
215 |
+
string_timestamp = _ffi.cast("ASN1_STRING*", timestamp)
|
216 |
+
if _lib.ASN1_STRING_length(string_timestamp) == 0:
|
217 |
+
return None
|
218 |
+
elif (
|
219 |
+
_lib.ASN1_STRING_type(string_timestamp) == _lib.V_ASN1_GENERALIZEDTIME
|
220 |
+
):
|
221 |
+
return _ffi.string(_lib.ASN1_STRING_get0_data(string_timestamp))
|
222 |
+
else:
|
223 |
+
generalized_timestamp = _ffi.new("ASN1_GENERALIZEDTIME**")
|
224 |
+
_lib.ASN1_TIME_to_generalizedtime(timestamp, generalized_timestamp)
|
225 |
+
_openssl_assert(generalized_timestamp[0] != _ffi.NULL)
|
226 |
+
|
227 |
+
string_timestamp = _ffi.cast("ASN1_STRING*", generalized_timestamp[0])
|
228 |
+
string_data = _lib.ASN1_STRING_get0_data(string_timestamp)
|
229 |
+
string_result = _ffi.string(string_data)
|
230 |
+
_lib.ASN1_GENERALIZEDTIME_free(generalized_timestamp[0])
|
231 |
+
return string_result
|
232 |
+
|
233 |
+
|
234 |
+
class _X509NameInvalidator:
|
235 |
+
def __init__(self) -> None:
|
236 |
+
self._names: list[X509Name] = []
|
237 |
+
|
238 |
+
def add(self, name: X509Name) -> None:
|
239 |
+
self._names.append(name)
|
240 |
+
|
241 |
+
def clear(self) -> None:
|
242 |
+
for name in self._names:
|
243 |
+
# Breaks the object, but also prevents UAF!
|
244 |
+
del name._name
|
245 |
+
|
246 |
+
|
247 |
+
class PKey:
|
248 |
+
"""
|
249 |
+
A class representing an DSA or RSA public key or key pair.
|
250 |
+
"""
|
251 |
+
|
252 |
+
_only_public = False
|
253 |
+
_initialized = True
|
254 |
+
|
255 |
+
def __init__(self) -> None:
|
256 |
+
pkey = _lib.EVP_PKEY_new()
|
257 |
+
self._pkey = _ffi.gc(pkey, _lib.EVP_PKEY_free)
|
258 |
+
self._initialized = False
|
259 |
+
|
260 |
+
def to_cryptography_key(self) -> _Key:
|
261 |
+
"""
|
262 |
+
Export as a ``cryptography`` key.
|
263 |
+
|
264 |
+
:rtype: One of ``cryptography``'s `key interfaces`_.
|
265 |
+
|
266 |
+
.. _key interfaces: https://cryptography.io/en/latest/hazmat/\
|
267 |
+
primitives/asymmetric/rsa/#key-interfaces
|
268 |
+
|
269 |
+
.. versionadded:: 16.1.0
|
270 |
+
"""
|
271 |
+
from cryptography.hazmat.primitives.serialization import (
|
272 |
+
load_der_private_key,
|
273 |
+
load_der_public_key,
|
274 |
+
)
|
275 |
+
|
276 |
+
if self._only_public:
|
277 |
+
der = dump_publickey(FILETYPE_ASN1, self)
|
278 |
+
return typing.cast(_Key, load_der_public_key(der))
|
279 |
+
else:
|
280 |
+
der = dump_privatekey(FILETYPE_ASN1, self)
|
281 |
+
return typing.cast(_Key, load_der_private_key(der, password=None))
|
282 |
+
|
283 |
+
@classmethod
|
284 |
+
def from_cryptography_key(cls, crypto_key: _Key) -> PKey:
|
285 |
+
"""
|
286 |
+
Construct based on a ``cryptography`` *crypto_key*.
|
287 |
+
|
288 |
+
:param crypto_key: A ``cryptography`` key.
|
289 |
+
:type crypto_key: One of ``cryptography``'s `key interfaces`_.
|
290 |
+
|
291 |
+
:rtype: PKey
|
292 |
+
|
293 |
+
.. versionadded:: 16.1.0
|
294 |
+
"""
|
295 |
+
if not isinstance(
|
296 |
+
crypto_key,
|
297 |
+
(
|
298 |
+
dsa.DSAPrivateKey,
|
299 |
+
dsa.DSAPublicKey,
|
300 |
+
ec.EllipticCurvePrivateKey,
|
301 |
+
ec.EllipticCurvePublicKey,
|
302 |
+
ed25519.Ed25519PrivateKey,
|
303 |
+
ed25519.Ed25519PublicKey,
|
304 |
+
ed448.Ed448PrivateKey,
|
305 |
+
ed448.Ed448PublicKey,
|
306 |
+
rsa.RSAPrivateKey,
|
307 |
+
rsa.RSAPublicKey,
|
308 |
+
),
|
309 |
+
):
|
310 |
+
raise TypeError("Unsupported key type")
|
311 |
+
|
312 |
+
from cryptography.hazmat.primitives.serialization import (
|
313 |
+
Encoding,
|
314 |
+
NoEncryption,
|
315 |
+
PrivateFormat,
|
316 |
+
PublicFormat,
|
317 |
+
)
|
318 |
+
|
319 |
+
if isinstance(
|
320 |
+
crypto_key,
|
321 |
+
(
|
322 |
+
dsa.DSAPublicKey,
|
323 |
+
ec.EllipticCurvePublicKey,
|
324 |
+
ed25519.Ed25519PublicKey,
|
325 |
+
ed448.Ed448PublicKey,
|
326 |
+
rsa.RSAPublicKey,
|
327 |
+
),
|
328 |
+
):
|
329 |
+
return load_publickey(
|
330 |
+
FILETYPE_ASN1,
|
331 |
+
crypto_key.public_bytes(
|
332 |
+
Encoding.DER, PublicFormat.SubjectPublicKeyInfo
|
333 |
+
),
|
334 |
+
)
|
335 |
+
else:
|
336 |
+
der = crypto_key.private_bytes(
|
337 |
+
Encoding.DER, PrivateFormat.PKCS8, NoEncryption()
|
338 |
+
)
|
339 |
+
return load_privatekey(FILETYPE_ASN1, der)
|
340 |
+
|
341 |
+
def generate_key(self, type: int, bits: int) -> None:
|
342 |
+
"""
|
343 |
+
Generate a key pair of the given type, with the given number of bits.
|
344 |
+
|
345 |
+
This generates a key "into" the this object.
|
346 |
+
|
347 |
+
:param type: The key type.
|
348 |
+
:type type: :py:data:`TYPE_RSA` or :py:data:`TYPE_DSA`
|
349 |
+
:param bits: The number of bits.
|
350 |
+
:type bits: :py:data:`int` ``>= 0``
|
351 |
+
:raises TypeError: If :py:data:`type` or :py:data:`bits` isn't
|
352 |
+
of the appropriate type.
|
353 |
+
:raises ValueError: If the number of bits isn't an integer of
|
354 |
+
the appropriate size.
|
355 |
+
:return: ``None``
|
356 |
+
"""
|
357 |
+
if not isinstance(type, int):
|
358 |
+
raise TypeError("type must be an integer")
|
359 |
+
|
360 |
+
if not isinstance(bits, int):
|
361 |
+
raise TypeError("bits must be an integer")
|
362 |
+
|
363 |
+
if type == TYPE_RSA:
|
364 |
+
if bits <= 0:
|
365 |
+
raise ValueError("Invalid number of bits")
|
366 |
+
|
367 |
+
# TODO Check error return
|
368 |
+
exponent = _lib.BN_new()
|
369 |
+
exponent = _ffi.gc(exponent, _lib.BN_free)
|
370 |
+
_lib.BN_set_word(exponent, _lib.RSA_F4)
|
371 |
+
|
372 |
+
rsa = _lib.RSA_new()
|
373 |
+
|
374 |
+
result = _lib.RSA_generate_key_ex(rsa, bits, exponent, _ffi.NULL)
|
375 |
+
_openssl_assert(result == 1)
|
376 |
+
|
377 |
+
result = _lib.EVP_PKEY_assign_RSA(self._pkey, rsa)
|
378 |
+
_openssl_assert(result == 1)
|
379 |
+
|
380 |
+
elif type == TYPE_DSA:
|
381 |
+
dsa = _lib.DSA_new()
|
382 |
+
_openssl_assert(dsa != _ffi.NULL)
|
383 |
+
|
384 |
+
dsa = _ffi.gc(dsa, _lib.DSA_free)
|
385 |
+
res = _lib.DSA_generate_parameters_ex(
|
386 |
+
dsa, bits, _ffi.NULL, 0, _ffi.NULL, _ffi.NULL, _ffi.NULL
|
387 |
+
)
|
388 |
+
_openssl_assert(res == 1)
|
389 |
+
|
390 |
+
_openssl_assert(_lib.DSA_generate_key(dsa) == 1)
|
391 |
+
_openssl_assert(_lib.EVP_PKEY_set1_DSA(self._pkey, dsa) == 1)
|
392 |
+
else:
|
393 |
+
raise Error("No such key type")
|
394 |
+
|
395 |
+
self._initialized = True
|
396 |
+
|
397 |
+
def check(self) -> bool:
|
398 |
+
"""
|
399 |
+
Check the consistency of an RSA private key.
|
400 |
+
|
401 |
+
This is the Python equivalent of OpenSSL's ``RSA_check_key``.
|
402 |
+
|
403 |
+
:return: ``True`` if key is consistent.
|
404 |
+
|
405 |
+
:raise OpenSSL.crypto.Error: if the key is inconsistent.
|
406 |
+
|
407 |
+
:raise TypeError: if the key is of a type which cannot be checked.
|
408 |
+
Only RSA keys can currently be checked.
|
409 |
+
"""
|
410 |
+
if self._only_public:
|
411 |
+
raise TypeError("public key only")
|
412 |
+
|
413 |
+
if _lib.EVP_PKEY_type(self.type()) != _lib.EVP_PKEY_RSA:
|
414 |
+
raise TypeError("Only RSA keys can currently be checked.")
|
415 |
+
|
416 |
+
rsa = _lib.EVP_PKEY_get1_RSA(self._pkey)
|
417 |
+
rsa = _ffi.gc(rsa, _lib.RSA_free)
|
418 |
+
result = _lib.RSA_check_key(rsa)
|
419 |
+
if result == 1:
|
420 |
+
return True
|
421 |
+
_raise_current_error()
|
422 |
+
|
423 |
+
def type(self) -> int:
|
424 |
+
"""
|
425 |
+
Returns the type of the key
|
426 |
+
|
427 |
+
:return: The type of the key.
|
428 |
+
"""
|
429 |
+
return _lib.EVP_PKEY_id(self._pkey)
|
430 |
+
|
431 |
+
def bits(self) -> int:
|
432 |
+
"""
|
433 |
+
Returns the number of bits of the key
|
434 |
+
|
435 |
+
:return: The number of bits of the key.
|
436 |
+
"""
|
437 |
+
return _lib.EVP_PKEY_bits(self._pkey)
|
438 |
+
|
439 |
+
|
440 |
+
class _EllipticCurve:
|
441 |
+
"""
|
442 |
+
A representation of a supported elliptic curve.
|
443 |
+
|
444 |
+
@cvar _curves: :py:obj:`None` until an attempt is made to load the curves.
|
445 |
+
Thereafter, a :py:type:`set` containing :py:type:`_EllipticCurve`
|
446 |
+
instances each of which represents one curve supported by the system.
|
447 |
+
@type _curves: :py:type:`NoneType` or :py:type:`set`
|
448 |
+
"""
|
449 |
+
|
450 |
+
_curves = None
|
451 |
+
|
452 |
+
def __ne__(self, other: Any) -> bool:
|
453 |
+
"""
|
454 |
+
Implement cooperation with the right-hand side argument of ``!=``.
|
455 |
+
|
456 |
+
Python 3 seems to have dropped this cooperation in this very narrow
|
457 |
+
circumstance.
|
458 |
+
"""
|
459 |
+
if isinstance(other, _EllipticCurve):
|
460 |
+
return super().__ne__(other)
|
461 |
+
return NotImplemented
|
462 |
+
|
463 |
+
@classmethod
|
464 |
+
def _load_elliptic_curves(cls, lib: Any) -> set[_EllipticCurve]:
|
465 |
+
"""
|
466 |
+
Get the curves supported by OpenSSL.
|
467 |
+
|
468 |
+
:param lib: The OpenSSL library binding object.
|
469 |
+
|
470 |
+
:return: A :py:type:`set` of ``cls`` instances giving the names of the
|
471 |
+
elliptic curves the underlying library supports.
|
472 |
+
"""
|
473 |
+
num_curves = lib.EC_get_builtin_curves(_ffi.NULL, 0)
|
474 |
+
builtin_curves = _ffi.new("EC_builtin_curve[]", num_curves)
|
475 |
+
# The return value on this call should be num_curves again. We
|
476 |
+
# could check it to make sure but if it *isn't* then.. what could
|
477 |
+
# we do? Abort the whole process, I suppose...? -exarkun
|
478 |
+
lib.EC_get_builtin_curves(builtin_curves, num_curves)
|
479 |
+
return set(cls.from_nid(lib, c.nid) for c in builtin_curves)
|
480 |
+
|
481 |
+
@classmethod
|
482 |
+
def _get_elliptic_curves(cls, lib: Any) -> set[_EllipticCurve]:
|
483 |
+
"""
|
484 |
+
Get, cache, and return the curves supported by OpenSSL.
|
485 |
+
|
486 |
+
:param lib: The OpenSSL library binding object.
|
487 |
+
|
488 |
+
:return: A :py:type:`set` of ``cls`` instances giving the names of the
|
489 |
+
elliptic curves the underlying library supports.
|
490 |
+
"""
|
491 |
+
if cls._curves is None:
|
492 |
+
cls._curves = cls._load_elliptic_curves(lib)
|
493 |
+
return cls._curves
|
494 |
+
|
495 |
+
@classmethod
|
496 |
+
def from_nid(cls, lib: Any, nid: int) -> _EllipticCurve:
|
497 |
+
"""
|
498 |
+
Instantiate a new :py:class:`_EllipticCurve` associated with the given
|
499 |
+
OpenSSL NID.
|
500 |
+
|
501 |
+
:param lib: The OpenSSL library binding object.
|
502 |
+
|
503 |
+
:param nid: The OpenSSL NID the resulting curve object will represent.
|
504 |
+
This must be a curve NID (and not, for example, a hash NID) or
|
505 |
+
subsequent operations will fail in unpredictable ways.
|
506 |
+
:type nid: :py:class:`int`
|
507 |
+
|
508 |
+
:return: The curve object.
|
509 |
+
"""
|
510 |
+
return cls(lib, nid, _ffi.string(lib.OBJ_nid2sn(nid)).decode("ascii"))
|
511 |
+
|
512 |
+
def __init__(self, lib: Any, nid: int, name: str) -> None:
|
513 |
+
"""
|
514 |
+
:param _lib: The :py:mod:`cryptography` binding instance used to
|
515 |
+
interface with OpenSSL.
|
516 |
+
|
517 |
+
:param _nid: The OpenSSL NID identifying the curve this object
|
518 |
+
represents.
|
519 |
+
:type _nid: :py:class:`int`
|
520 |
+
|
521 |
+
:param name: The OpenSSL short name identifying the curve this object
|
522 |
+
represents.
|
523 |
+
:type name: :py:class:`unicode`
|
524 |
+
"""
|
525 |
+
self._lib = lib
|
526 |
+
self._nid = nid
|
527 |
+
self.name = name
|
528 |
+
|
529 |
+
def __repr__(self) -> str:
|
530 |
+
return f"<Curve {self.name!r}>"
|
531 |
+
|
532 |
+
def _to_EC_KEY(self) -> Any:
|
533 |
+
"""
|
534 |
+
Create a new OpenSSL EC_KEY structure initialized to use this curve.
|
535 |
+
|
536 |
+
The structure is automatically garbage collected when the Python object
|
537 |
+
is garbage collected.
|
538 |
+
"""
|
539 |
+
key = self._lib.EC_KEY_new_by_curve_name(self._nid)
|
540 |
+
return _ffi.gc(key, _lib.EC_KEY_free)
|
541 |
+
|
542 |
+
|
543 |
+
@deprecated(
|
544 |
+
"get_elliptic_curves is deprecated. You should use the APIs in "
|
545 |
+
"cryptography instead."
|
546 |
+
)
|
547 |
+
def get_elliptic_curves() -> set[_EllipticCurve]:
|
548 |
+
"""
|
549 |
+
Return a set of objects representing the elliptic curves supported in the
|
550 |
+
OpenSSL build in use.
|
551 |
+
|
552 |
+
The curve objects have a :py:class:`unicode` ``name`` attribute by which
|
553 |
+
they identify themselves.
|
554 |
+
|
555 |
+
The curve objects are useful as values for the argument accepted by
|
556 |
+
:py:meth:`Context.set_tmp_ecdh` to specify which elliptical curve should be
|
557 |
+
used for ECDHE key exchange.
|
558 |
+
"""
|
559 |
+
return _EllipticCurve._get_elliptic_curves(_lib)
|
560 |
+
|
561 |
+
|
562 |
+
@deprecated(
|
563 |
+
"get_elliptic_curve is deprecated. You should use the APIs in "
|
564 |
+
"cryptography instead."
|
565 |
+
)
|
566 |
+
def get_elliptic_curve(name: str) -> _EllipticCurve:
|
567 |
+
"""
|
568 |
+
Return a single curve object selected by name.
|
569 |
+
|
570 |
+
See :py:func:`get_elliptic_curves` for information about curve objects.
|
571 |
+
|
572 |
+
:param name: The OpenSSL short name identifying the curve object to
|
573 |
+
retrieve.
|
574 |
+
:type name: :py:class:`unicode`
|
575 |
+
|
576 |
+
If the named curve is not supported then :py:class:`ValueError` is raised.
|
577 |
+
"""
|
578 |
+
for curve in get_elliptic_curves():
|
579 |
+
if curve.name == name:
|
580 |
+
return curve
|
581 |
+
raise ValueError("unknown curve name", name)
|
582 |
+
|
583 |
+
|
584 |
+
@functools.total_ordering
|
585 |
+
class X509Name:
|
586 |
+
"""
|
587 |
+
An X.509 Distinguished Name.
|
588 |
+
|
589 |
+
:ivar countryName: The country of the entity.
|
590 |
+
:ivar C: Alias for :py:attr:`countryName`.
|
591 |
+
|
592 |
+
:ivar stateOrProvinceName: The state or province of the entity.
|
593 |
+
:ivar ST: Alias for :py:attr:`stateOrProvinceName`.
|
594 |
+
|
595 |
+
:ivar localityName: The locality of the entity.
|
596 |
+
:ivar L: Alias for :py:attr:`localityName`.
|
597 |
+
|
598 |
+
:ivar organizationName: The organization name of the entity.
|
599 |
+
:ivar O: Alias for :py:attr:`organizationName`.
|
600 |
+
|
601 |
+
:ivar organizationalUnitName: The organizational unit of the entity.
|
602 |
+
:ivar OU: Alias for :py:attr:`organizationalUnitName`
|
603 |
+
|
604 |
+
:ivar commonName: The common name of the entity.
|
605 |
+
:ivar CN: Alias for :py:attr:`commonName`.
|
606 |
+
|
607 |
+
:ivar emailAddress: The e-mail address of the entity.
|
608 |
+
"""
|
609 |
+
|
610 |
+
def __init__(self, name: X509Name) -> None:
|
611 |
+
"""
|
612 |
+
Create a new X509Name, copying the given X509Name instance.
|
613 |
+
|
614 |
+
:param name: The name to copy.
|
615 |
+
:type name: :py:class:`X509Name`
|
616 |
+
"""
|
617 |
+
name = _lib.X509_NAME_dup(name._name)
|
618 |
+
self._name: Any = _ffi.gc(name, _lib.X509_NAME_free)
|
619 |
+
|
620 |
+
def __setattr__(self, name: str, value: Any) -> None:
|
621 |
+
if name.startswith("_"):
|
622 |
+
return super().__setattr__(name, value)
|
623 |
+
|
624 |
+
# Note: we really do not want str subclasses here, so we do not use
|
625 |
+
# isinstance.
|
626 |
+
if type(name) is not str:
|
627 |
+
raise TypeError(
|
628 |
+
f"attribute name must be string, not "
|
629 |
+
f"'{type(value).__name__:.200}'"
|
630 |
+
)
|
631 |
+
|
632 |
+
nid = _lib.OBJ_txt2nid(_byte_string(name))
|
633 |
+
if nid == _lib.NID_undef:
|
634 |
+
try:
|
635 |
+
_raise_current_error()
|
636 |
+
except Error:
|
637 |
+
pass
|
638 |
+
raise AttributeError("No such attribute")
|
639 |
+
|
640 |
+
# If there's an old entry for this NID, remove it
|
641 |
+
for i in range(_lib.X509_NAME_entry_count(self._name)):
|
642 |
+
ent = _lib.X509_NAME_get_entry(self._name, i)
|
643 |
+
ent_obj = _lib.X509_NAME_ENTRY_get_object(ent)
|
644 |
+
ent_nid = _lib.OBJ_obj2nid(ent_obj)
|
645 |
+
if nid == ent_nid:
|
646 |
+
ent = _lib.X509_NAME_delete_entry(self._name, i)
|
647 |
+
_lib.X509_NAME_ENTRY_free(ent)
|
648 |
+
break
|
649 |
+
|
650 |
+
if isinstance(value, str):
|
651 |
+
value = value.encode("utf-8")
|
652 |
+
|
653 |
+
add_result = _lib.X509_NAME_add_entry_by_NID(
|
654 |
+
self._name, nid, _lib.MBSTRING_UTF8, value, -1, -1, 0
|
655 |
+
)
|
656 |
+
if not add_result:
|
657 |
+
_raise_current_error()
|
658 |
+
|
659 |
+
def __getattr__(self, name: str) -> str | None:
|
660 |
+
"""
|
661 |
+
Find attribute. An X509Name object has the following attributes:
|
662 |
+
countryName (alias C), stateOrProvince (alias ST), locality (alias L),
|
663 |
+
organization (alias O), organizationalUnit (alias OU), commonName
|
664 |
+
(alias CN) and more...
|
665 |
+
"""
|
666 |
+
nid = _lib.OBJ_txt2nid(_byte_string(name))
|
667 |
+
if nid == _lib.NID_undef:
|
668 |
+
# This is a bit weird. OBJ_txt2nid indicated failure, but it seems
|
669 |
+
# a lower level function, a2d_ASN1_OBJECT, also feels the need to
|
670 |
+
# push something onto the error queue. If we don't clean that up
|
671 |
+
# now, someone else will bump into it later and be quite confused.
|
672 |
+
# See lp#314814.
|
673 |
+
try:
|
674 |
+
_raise_current_error()
|
675 |
+
except Error:
|
676 |
+
pass
|
677 |
+
raise AttributeError("No such attribute")
|
678 |
+
|
679 |
+
entry_index = _lib.X509_NAME_get_index_by_NID(self._name, nid, -1)
|
680 |
+
if entry_index == -1:
|
681 |
+
return None
|
682 |
+
|
683 |
+
entry = _lib.X509_NAME_get_entry(self._name, entry_index)
|
684 |
+
data = _lib.X509_NAME_ENTRY_get_data(entry)
|
685 |
+
|
686 |
+
result_buffer = _ffi.new("unsigned char**")
|
687 |
+
data_length = _lib.ASN1_STRING_to_UTF8(result_buffer, data)
|
688 |
+
_openssl_assert(data_length >= 0)
|
689 |
+
|
690 |
+
try:
|
691 |
+
result = _ffi.buffer(result_buffer[0], data_length)[:].decode(
|
692 |
+
"utf-8"
|
693 |
+
)
|
694 |
+
finally:
|
695 |
+
# XXX untested
|
696 |
+
_lib.OPENSSL_free(result_buffer[0])
|
697 |
+
return result
|
698 |
+
|
699 |
+
def __eq__(self, other: Any) -> bool:
|
700 |
+
if not isinstance(other, X509Name):
|
701 |
+
return NotImplemented
|
702 |
+
|
703 |
+
return _lib.X509_NAME_cmp(self._name, other._name) == 0
|
704 |
+
|
705 |
+
def __lt__(self, other: Any) -> bool:
|
706 |
+
if not isinstance(other, X509Name):
|
707 |
+
return NotImplemented
|
708 |
+
|
709 |
+
return _lib.X509_NAME_cmp(self._name, other._name) < 0
|
710 |
+
|
711 |
+
def __repr__(self) -> str:
|
712 |
+
"""
|
713 |
+
String representation of an X509Name
|
714 |
+
"""
|
715 |
+
result_buffer = _ffi.new("char[]", 512)
|
716 |
+
format_result = _lib.X509_NAME_oneline(
|
717 |
+
self._name, result_buffer, len(result_buffer)
|
718 |
+
)
|
719 |
+
_openssl_assert(format_result != _ffi.NULL)
|
720 |
+
|
721 |
+
return "<X509Name object '{}'>".format(
|
722 |
+
_ffi.string(result_buffer).decode("utf-8"),
|
723 |
+
)
|
724 |
+
|
725 |
+
def hash(self) -> int:
|
726 |
+
"""
|
727 |
+
Return an integer representation of the first four bytes of the
|
728 |
+
MD5 digest of the DER representation of the name.
|
729 |
+
|
730 |
+
This is the Python equivalent of OpenSSL's ``X509_NAME_hash``.
|
731 |
+
|
732 |
+
:return: The (integer) hash of this name.
|
733 |
+
:rtype: :py:class:`int`
|
734 |
+
"""
|
735 |
+
return _lib.X509_NAME_hash(self._name)
|
736 |
+
|
737 |
+
def der(self) -> bytes:
|
738 |
+
"""
|
739 |
+
Return the DER encoding of this name.
|
740 |
+
|
741 |
+
:return: The DER encoded form of this name.
|
742 |
+
:rtype: :py:class:`bytes`
|
743 |
+
"""
|
744 |
+
result_buffer = _ffi.new("unsigned char**")
|
745 |
+
encode_result = _lib.i2d_X509_NAME(self._name, result_buffer)
|
746 |
+
_openssl_assert(encode_result >= 0)
|
747 |
+
|
748 |
+
string_result = _ffi.buffer(result_buffer[0], encode_result)[:]
|
749 |
+
_lib.OPENSSL_free(result_buffer[0])
|
750 |
+
return string_result
|
751 |
+
|
752 |
+
def get_components(self) -> list[tuple[bytes, bytes]]:
|
753 |
+
"""
|
754 |
+
Returns the components of this name, as a sequence of 2-tuples.
|
755 |
+
|
756 |
+
:return: The components of this name.
|
757 |
+
:rtype: :py:class:`list` of ``name, value`` tuples.
|
758 |
+
"""
|
759 |
+
result = []
|
760 |
+
for i in range(_lib.X509_NAME_entry_count(self._name)):
|
761 |
+
ent = _lib.X509_NAME_get_entry(self._name, i)
|
762 |
+
|
763 |
+
fname = _lib.X509_NAME_ENTRY_get_object(ent)
|
764 |
+
fval = _lib.X509_NAME_ENTRY_get_data(ent)
|
765 |
+
|
766 |
+
nid = _lib.OBJ_obj2nid(fname)
|
767 |
+
name = _lib.OBJ_nid2sn(nid)
|
768 |
+
|
769 |
+
# ffi.string does not handle strings containing NULL bytes
|
770 |
+
# (which may have been generated by old, broken software)
|
771 |
+
value = _ffi.buffer(
|
772 |
+
_lib.ASN1_STRING_get0_data(fval), _lib.ASN1_STRING_length(fval)
|
773 |
+
)[:]
|
774 |
+
result.append((_ffi.string(name), value))
|
775 |
+
|
776 |
+
return result
|
777 |
+
|
778 |
+
|
779 |
+
@deprecated(
|
780 |
+
"X509Extension support in pyOpenSSL is deprecated. You should use the "
|
781 |
+
"APIs in cryptography."
|
782 |
+
)
|
783 |
+
class X509Extension:
|
784 |
+
"""
|
785 |
+
An X.509 v3 certificate extension.
|
786 |
+
|
787 |
+
.. deprecated:: 23.3.0
|
788 |
+
Use cryptography's X509 APIs instead.
|
789 |
+
"""
|
790 |
+
|
791 |
+
def __init__(
|
792 |
+
self,
|
793 |
+
type_name: bytes,
|
794 |
+
critical: bool,
|
795 |
+
value: bytes,
|
796 |
+
subject: X509 | None = None,
|
797 |
+
issuer: X509 | None = None,
|
798 |
+
) -> None:
|
799 |
+
"""
|
800 |
+
Initializes an X509 extension.
|
801 |
+
|
802 |
+
:param type_name: The name of the type of extension_ to create.
|
803 |
+
:type type_name: :py:data:`bytes`
|
804 |
+
|
805 |
+
:param bool critical: A flag indicating whether this is a critical
|
806 |
+
extension.
|
807 |
+
|
808 |
+
:param value: The OpenSSL textual representation of the extension's
|
809 |
+
value.
|
810 |
+
:type value: :py:data:`bytes`
|
811 |
+
|
812 |
+
:param subject: Optional X509 certificate to use as subject.
|
813 |
+
:type subject: :py:class:`X509`
|
814 |
+
|
815 |
+
:param issuer: Optional X509 certificate to use as issuer.
|
816 |
+
:type issuer: :py:class:`X509`
|
817 |
+
|
818 |
+
.. _extension: https://www.openssl.org/docs/manmaster/man5/
|
819 |
+
x509v3_config.html#STANDARD-EXTENSIONS
|
820 |
+
"""
|
821 |
+
ctx = _ffi.new("X509V3_CTX*")
|
822 |
+
|
823 |
+
# A context is necessary for any extension which uses the r2i
|
824 |
+
# conversion method. That is, X509V3_EXT_nconf may segfault if passed
|
825 |
+
# a NULL ctx. Start off by initializing most of the fields to NULL.
|
826 |
+
_lib.X509V3_set_ctx(ctx, _ffi.NULL, _ffi.NULL, _ffi.NULL, _ffi.NULL, 0)
|
827 |
+
|
828 |
+
# We have no configuration database - but perhaps we should (some
|
829 |
+
# extensions may require it).
|
830 |
+
_lib.X509V3_set_ctx_nodb(ctx)
|
831 |
+
|
832 |
+
# Initialize the subject and issuer, if appropriate. ctx is a local,
|
833 |
+
# and as far as I can tell none of the X509V3_* APIs invoked here steal
|
834 |
+
# any references, so no need to mess with reference counts or
|
835 |
+
# duplicates.
|
836 |
+
if issuer is not None:
|
837 |
+
if not isinstance(issuer, X509):
|
838 |
+
raise TypeError("issuer must be an X509 instance")
|
839 |
+
ctx.issuer_cert = issuer._x509
|
840 |
+
if subject is not None:
|
841 |
+
if not isinstance(subject, X509):
|
842 |
+
raise TypeError("subject must be an X509 instance")
|
843 |
+
ctx.subject_cert = subject._x509
|
844 |
+
|
845 |
+
if critical:
|
846 |
+
# There are other OpenSSL APIs which would let us pass in critical
|
847 |
+
# separately, but they're harder to use, and since value is already
|
848 |
+
# a pile of crappy junk smuggling a ton of utterly important
|
849 |
+
# structured data, what's the point of trying to avoid nasty stuff
|
850 |
+
# with strings? (However, X509V3_EXT_i2d in particular seems like
|
851 |
+
# it would be a better API to invoke. I do not know where to get
|
852 |
+
# the ext_struc it desires for its last parameter, though.)
|
853 |
+
value = b"critical," + value
|
854 |
+
|
855 |
+
extension = _lib.X509V3_EXT_nconf(_ffi.NULL, ctx, type_name, value)
|
856 |
+
if extension == _ffi.NULL:
|
857 |
+
_raise_current_error()
|
858 |
+
self._extension = _ffi.gc(extension, _lib.X509_EXTENSION_free)
|
859 |
+
|
860 |
+
@property
|
861 |
+
def _nid(self) -> Any:
|
862 |
+
return _lib.OBJ_obj2nid(
|
863 |
+
_lib.X509_EXTENSION_get_object(self._extension)
|
864 |
+
)
|
865 |
+
|
866 |
+
_prefixes: typing.ClassVar[dict[int, str]] = {
|
867 |
+
_lib.GEN_EMAIL: "email",
|
868 |
+
_lib.GEN_DNS: "DNS",
|
869 |
+
_lib.GEN_URI: "URI",
|
870 |
+
}
|
871 |
+
|
872 |
+
def _subjectAltNameString(self) -> str:
|
873 |
+
names = _ffi.cast(
|
874 |
+
"GENERAL_NAMES*", _lib.X509V3_EXT_d2i(self._extension)
|
875 |
+
)
|
876 |
+
|
877 |
+
names = _ffi.gc(names, _lib.GENERAL_NAMES_free)
|
878 |
+
parts = []
|
879 |
+
for i in range(_lib.sk_GENERAL_NAME_num(names)):
|
880 |
+
name = _lib.sk_GENERAL_NAME_value(names, i)
|
881 |
+
try:
|
882 |
+
label = self._prefixes[name.type]
|
883 |
+
except KeyError:
|
884 |
+
bio = _new_mem_buf()
|
885 |
+
_lib.GENERAL_NAME_print(bio, name)
|
886 |
+
parts.append(_bio_to_string(bio).decode("utf-8"))
|
887 |
+
else:
|
888 |
+
value = _ffi.buffer(name.d.ia5.data, name.d.ia5.length)[
|
889 |
+
:
|
890 |
+
].decode("utf-8")
|
891 |
+
parts.append(label + ":" + value)
|
892 |
+
return ", ".join(parts)
|
893 |
+
|
894 |
+
def __str__(self) -> str:
|
895 |
+
"""
|
896 |
+
:return: a nice text representation of the extension
|
897 |
+
"""
|
898 |
+
if _lib.NID_subject_alt_name == self._nid:
|
899 |
+
return self._subjectAltNameString()
|
900 |
+
|
901 |
+
bio = _new_mem_buf()
|
902 |
+
print_result = _lib.X509V3_EXT_print(bio, self._extension, 0, 0)
|
903 |
+
_openssl_assert(print_result != 0)
|
904 |
+
|
905 |
+
return _bio_to_string(bio).decode("utf-8")
|
906 |
+
|
907 |
+
def get_critical(self) -> bool:
|
908 |
+
"""
|
909 |
+
Returns the critical field of this X.509 extension.
|
910 |
+
|
911 |
+
:return: The critical field.
|
912 |
+
"""
|
913 |
+
return _lib.X509_EXTENSION_get_critical(self._extension)
|
914 |
+
|
915 |
+
def get_short_name(self) -> bytes:
|
916 |
+
"""
|
917 |
+
Returns the short type name of this X.509 extension.
|
918 |
+
|
919 |
+
The result is a byte string such as :py:const:`b"basicConstraints"`.
|
920 |
+
|
921 |
+
:return: The short type name.
|
922 |
+
:rtype: :py:data:`bytes`
|
923 |
+
|
924 |
+
.. versionadded:: 0.12
|
925 |
+
"""
|
926 |
+
obj = _lib.X509_EXTENSION_get_object(self._extension)
|
927 |
+
nid = _lib.OBJ_obj2nid(obj)
|
928 |
+
# OpenSSL 3.1.0 has a bug where nid2sn returns NULL for NIDs that
|
929 |
+
# previously returned UNDEF. This is a workaround for that issue.
|
930 |
+
# https://github.com/openssl/openssl/commit/908ba3ed9adbb3df90f76
|
931 |
+
buf = _lib.OBJ_nid2sn(nid)
|
932 |
+
if buf != _ffi.NULL:
|
933 |
+
return _ffi.string(buf)
|
934 |
+
else:
|
935 |
+
return b"UNDEF"
|
936 |
+
|
937 |
+
def get_data(self) -> bytes:
|
938 |
+
"""
|
939 |
+
Returns the data of the X509 extension, encoded as ASN.1.
|
940 |
+
|
941 |
+
:return: The ASN.1 encoded data of this X509 extension.
|
942 |
+
:rtype: :py:data:`bytes`
|
943 |
+
|
944 |
+
.. versionadded:: 0.12
|
945 |
+
"""
|
946 |
+
octet_result = _lib.X509_EXTENSION_get_data(self._extension)
|
947 |
+
string_result = _ffi.cast("ASN1_STRING*", octet_result)
|
948 |
+
char_result = _lib.ASN1_STRING_get0_data(string_result)
|
949 |
+
result_length = _lib.ASN1_STRING_length(string_result)
|
950 |
+
return _ffi.buffer(char_result, result_length)[:]
|
951 |
+
|
952 |
+
|
953 |
+
@deprecated(
|
954 |
+
"CSR support in pyOpenSSL is deprecated. You should use the APIs "
|
955 |
+
"in cryptography."
|
956 |
+
)
|
957 |
+
class X509Req:
|
958 |
+
"""
|
959 |
+
An X.509 certificate signing requests.
|
960 |
+
|
961 |
+
.. deprecated:: 24.2.0
|
962 |
+
Use `cryptography.x509.CertificateSigningRequest` instead.
|
963 |
+
"""
|
964 |
+
|
965 |
+
def __init__(self) -> None:
|
966 |
+
req = _lib.X509_REQ_new()
|
967 |
+
self._req = _ffi.gc(req, _lib.X509_REQ_free)
|
968 |
+
# Default to version 0.
|
969 |
+
self.set_version(0)
|
970 |
+
|
971 |
+
def to_cryptography(self) -> x509.CertificateSigningRequest:
|
972 |
+
"""
|
973 |
+
Export as a ``cryptography`` certificate signing request.
|
974 |
+
|
975 |
+
:rtype: ``cryptography.x509.CertificateSigningRequest``
|
976 |
+
|
977 |
+
.. versionadded:: 17.1.0
|
978 |
+
"""
|
979 |
+
from cryptography.x509 import load_der_x509_csr
|
980 |
+
|
981 |
+
der = _dump_certificate_request_internal(FILETYPE_ASN1, self)
|
982 |
+
|
983 |
+
return load_der_x509_csr(der)
|
984 |
+
|
985 |
+
@classmethod
|
986 |
+
def from_cryptography(
|
987 |
+
cls, crypto_req: x509.CertificateSigningRequest
|
988 |
+
) -> X509Req:
|
989 |
+
"""
|
990 |
+
Construct based on a ``cryptography`` *crypto_req*.
|
991 |
+
|
992 |
+
:param crypto_req: A ``cryptography`` X.509 certificate signing request
|
993 |
+
:type crypto_req: ``cryptography.x509.CertificateSigningRequest``
|
994 |
+
|
995 |
+
:rtype: X509Req
|
996 |
+
|
997 |
+
.. versionadded:: 17.1.0
|
998 |
+
"""
|
999 |
+
if not isinstance(crypto_req, x509.CertificateSigningRequest):
|
1000 |
+
raise TypeError("Must be a certificate signing request")
|
1001 |
+
|
1002 |
+
from cryptography.hazmat.primitives.serialization import Encoding
|
1003 |
+
|
1004 |
+
der = crypto_req.public_bytes(Encoding.DER)
|
1005 |
+
return _load_certificate_request_internal(FILETYPE_ASN1, der)
|
1006 |
+
|
1007 |
+
def set_pubkey(self, pkey: PKey) -> None:
|
1008 |
+
"""
|
1009 |
+
Set the public key of the certificate signing request.
|
1010 |
+
|
1011 |
+
:param pkey: The public key to use.
|
1012 |
+
:type pkey: :py:class:`PKey`
|
1013 |
+
|
1014 |
+
:return: ``None``
|
1015 |
+
"""
|
1016 |
+
set_result = _lib.X509_REQ_set_pubkey(self._req, pkey._pkey)
|
1017 |
+
_openssl_assert(set_result == 1)
|
1018 |
+
|
1019 |
+
def get_pubkey(self) -> PKey:
|
1020 |
+
"""
|
1021 |
+
Get the public key of the certificate signing request.
|
1022 |
+
|
1023 |
+
:return: The public key.
|
1024 |
+
:rtype: :py:class:`PKey`
|
1025 |
+
"""
|
1026 |
+
pkey = PKey.__new__(PKey)
|
1027 |
+
pkey._pkey = _lib.X509_REQ_get_pubkey(self._req)
|
1028 |
+
_openssl_assert(pkey._pkey != _ffi.NULL)
|
1029 |
+
pkey._pkey = _ffi.gc(pkey._pkey, _lib.EVP_PKEY_free)
|
1030 |
+
pkey._only_public = True
|
1031 |
+
return pkey
|
1032 |
+
|
1033 |
+
def set_version(self, version: int) -> None:
|
1034 |
+
"""
|
1035 |
+
Set the version subfield (RFC 2986, section 4.1) of the certificate
|
1036 |
+
request.
|
1037 |
+
|
1038 |
+
:param int version: The version number.
|
1039 |
+
:return: ``None``
|
1040 |
+
"""
|
1041 |
+
if not isinstance(version, int):
|
1042 |
+
raise TypeError("version must be an int")
|
1043 |
+
if version != 0:
|
1044 |
+
raise ValueError(
|
1045 |
+
"Invalid version. The only valid version for X509Req is 0."
|
1046 |
+
)
|
1047 |
+
set_result = _lib.X509_REQ_set_version(self._req, version)
|
1048 |
+
_openssl_assert(set_result == 1)
|
1049 |
+
|
1050 |
+
def get_version(self) -> int:
|
1051 |
+
"""
|
1052 |
+
Get the version subfield (RFC 2459, section 4.1.2.1) of the certificate
|
1053 |
+
request.
|
1054 |
+
|
1055 |
+
:return: The value of the version subfield.
|
1056 |
+
:rtype: :py:class:`int`
|
1057 |
+
"""
|
1058 |
+
return _lib.X509_REQ_get_version(self._req)
|
1059 |
+
|
1060 |
+
def get_subject(self) -> X509Name:
|
1061 |
+
"""
|
1062 |
+
Return the subject of this certificate signing request.
|
1063 |
+
|
1064 |
+
This creates a new :class:`X509Name` that wraps the underlying subject
|
1065 |
+
name field on the certificate signing request. Modifying it will modify
|
1066 |
+
the underlying signing request, and will have the effect of modifying
|
1067 |
+
any other :class:`X509Name` that refers to this subject.
|
1068 |
+
|
1069 |
+
:return: The subject of this certificate signing request.
|
1070 |
+
:rtype: :class:`X509Name`
|
1071 |
+
"""
|
1072 |
+
name = X509Name.__new__(X509Name)
|
1073 |
+
name._name = _lib.X509_REQ_get_subject_name(self._req)
|
1074 |
+
_openssl_assert(name._name != _ffi.NULL)
|
1075 |
+
|
1076 |
+
# The name is owned by the X509Req structure. As long as the X509Name
|
1077 |
+
# Python object is alive, keep the X509Req Python object alive.
|
1078 |
+
name._owner = self
|
1079 |
+
|
1080 |
+
return name
|
1081 |
+
|
1082 |
+
def add_extensions(self, extensions: Iterable[X509Extension]) -> None:
|
1083 |
+
"""
|
1084 |
+
Add extensions to the certificate signing request.
|
1085 |
+
|
1086 |
+
:param extensions: The X.509 extensions to add.
|
1087 |
+
:type extensions: iterable of :py:class:`X509Extension`
|
1088 |
+
:return: ``None``
|
1089 |
+
"""
|
1090 |
+
warnings.warn(
|
1091 |
+
(
|
1092 |
+
"This API is deprecated and will be removed in a future "
|
1093 |
+
"version of pyOpenSSL. You should use pyca/cryptography's "
|
1094 |
+
"X.509 APIs instead."
|
1095 |
+
),
|
1096 |
+
DeprecationWarning,
|
1097 |
+
stacklevel=2,
|
1098 |
+
)
|
1099 |
+
|
1100 |
+
stack = _lib.sk_X509_EXTENSION_new_null()
|
1101 |
+
_openssl_assert(stack != _ffi.NULL)
|
1102 |
+
|
1103 |
+
stack = _ffi.gc(stack, _lib.sk_X509_EXTENSION_free)
|
1104 |
+
|
1105 |
+
for ext in extensions:
|
1106 |
+
if not isinstance(ext, X509Extension):
|
1107 |
+
raise ValueError("One of the elements is not an X509Extension")
|
1108 |
+
|
1109 |
+
# TODO push can fail (here and elsewhere)
|
1110 |
+
_lib.sk_X509_EXTENSION_push(stack, ext._extension)
|
1111 |
+
|
1112 |
+
add_result = _lib.X509_REQ_add_extensions(self._req, stack)
|
1113 |
+
_openssl_assert(add_result == 1)
|
1114 |
+
|
1115 |
+
def get_extensions(self) -> list[X509Extension]:
|
1116 |
+
"""
|
1117 |
+
Get X.509 extensions in the certificate signing request.
|
1118 |
+
|
1119 |
+
:return: The X.509 extensions in this request.
|
1120 |
+
:rtype: :py:class:`list` of :py:class:`X509Extension` objects.
|
1121 |
+
|
1122 |
+
.. versionadded:: 0.15
|
1123 |
+
"""
|
1124 |
+
warnings.warn(
|
1125 |
+
(
|
1126 |
+
"This API is deprecated and will be removed in a future "
|
1127 |
+
"version of pyOpenSSL. You should use pyca/cryptography's "
|
1128 |
+
"X.509 APIs instead."
|
1129 |
+
),
|
1130 |
+
DeprecationWarning,
|
1131 |
+
stacklevel=2,
|
1132 |
+
)
|
1133 |
+
|
1134 |
+
exts = []
|
1135 |
+
native_exts_obj = _lib.X509_REQ_get_extensions(self._req)
|
1136 |
+
native_exts_obj = _ffi.gc(
|
1137 |
+
native_exts_obj,
|
1138 |
+
lambda x: _lib.sk_X509_EXTENSION_pop_free(
|
1139 |
+
x,
|
1140 |
+
_ffi.addressof(_lib._original_lib, "X509_EXTENSION_free"),
|
1141 |
+
),
|
1142 |
+
)
|
1143 |
+
|
1144 |
+
for i in range(_lib.sk_X509_EXTENSION_num(native_exts_obj)):
|
1145 |
+
ext = X509Extension.__new__(X509Extension)
|
1146 |
+
extension = _lib.X509_EXTENSION_dup(
|
1147 |
+
_lib.sk_X509_EXTENSION_value(native_exts_obj, i)
|
1148 |
+
)
|
1149 |
+
ext._extension = _ffi.gc(extension, _lib.X509_EXTENSION_free)
|
1150 |
+
exts.append(ext)
|
1151 |
+
return exts
|
1152 |
+
|
1153 |
+
def sign(self, pkey: PKey, digest: str) -> None:
|
1154 |
+
"""
|
1155 |
+
Sign the certificate signing request with this key and digest type.
|
1156 |
+
|
1157 |
+
:param pkey: The key pair to sign with.
|
1158 |
+
:type pkey: :py:class:`PKey`
|
1159 |
+
:param digest: The name of the message digest to use for the signature,
|
1160 |
+
e.g. :py:data:`"sha256"`.
|
1161 |
+
:type digest: :py:class:`str`
|
1162 |
+
:return: ``None``
|
1163 |
+
"""
|
1164 |
+
if pkey._only_public:
|
1165 |
+
raise ValueError("Key has only public part")
|
1166 |
+
|
1167 |
+
if not pkey._initialized:
|
1168 |
+
raise ValueError("Key is uninitialized")
|
1169 |
+
|
1170 |
+
digest_obj = _lib.EVP_get_digestbyname(_byte_string(digest))
|
1171 |
+
if digest_obj == _ffi.NULL:
|
1172 |
+
raise ValueError("No such digest method")
|
1173 |
+
|
1174 |
+
sign_result = _lib.X509_REQ_sign(self._req, pkey._pkey, digest_obj)
|
1175 |
+
_openssl_assert(sign_result > 0)
|
1176 |
+
|
1177 |
+
def verify(self, pkey: PKey) -> bool:
|
1178 |
+
"""
|
1179 |
+
Verifies the signature on this certificate signing request.
|
1180 |
+
|
1181 |
+
:param PKey key: A public key.
|
1182 |
+
|
1183 |
+
:return: ``True`` if the signature is correct.
|
1184 |
+
:rtype: bool
|
1185 |
+
|
1186 |
+
:raises OpenSSL.crypto.Error: If the signature is invalid or there is a
|
1187 |
+
problem verifying the signature.
|
1188 |
+
"""
|
1189 |
+
if not isinstance(pkey, PKey):
|
1190 |
+
raise TypeError("pkey must be a PKey instance")
|
1191 |
+
|
1192 |
+
result = _lib.X509_REQ_verify(self._req, pkey._pkey)
|
1193 |
+
if result <= 0:
|
1194 |
+
_raise_current_error()
|
1195 |
+
|
1196 |
+
return result
|
1197 |
+
|
1198 |
+
|
1199 |
+
class X509:
|
1200 |
+
"""
|
1201 |
+
An X.509 certificate.
|
1202 |
+
"""
|
1203 |
+
|
1204 |
+
def __init__(self) -> None:
|
1205 |
+
x509 = _lib.X509_new()
|
1206 |
+
_openssl_assert(x509 != _ffi.NULL)
|
1207 |
+
self._x509 = _ffi.gc(x509, _lib.X509_free)
|
1208 |
+
|
1209 |
+
self._issuer_invalidator = _X509NameInvalidator()
|
1210 |
+
self._subject_invalidator = _X509NameInvalidator()
|
1211 |
+
|
1212 |
+
@classmethod
|
1213 |
+
def _from_raw_x509_ptr(cls, x509: Any) -> X509:
|
1214 |
+
cert = cls.__new__(cls)
|
1215 |
+
cert._x509 = _ffi.gc(x509, _lib.X509_free)
|
1216 |
+
cert._issuer_invalidator = _X509NameInvalidator()
|
1217 |
+
cert._subject_invalidator = _X509NameInvalidator()
|
1218 |
+
return cert
|
1219 |
+
|
1220 |
+
def to_cryptography(self) -> x509.Certificate:
|
1221 |
+
"""
|
1222 |
+
Export as a ``cryptography`` certificate.
|
1223 |
+
|
1224 |
+
:rtype: ``cryptography.x509.Certificate``
|
1225 |
+
|
1226 |
+
.. versionadded:: 17.1.0
|
1227 |
+
"""
|
1228 |
+
from cryptography.x509 import load_der_x509_certificate
|
1229 |
+
|
1230 |
+
der = dump_certificate(FILETYPE_ASN1, self)
|
1231 |
+
return load_der_x509_certificate(der)
|
1232 |
+
|
1233 |
+
@classmethod
|
1234 |
+
def from_cryptography(cls, crypto_cert: x509.Certificate) -> X509:
|
1235 |
+
"""
|
1236 |
+
Construct based on a ``cryptography`` *crypto_cert*.
|
1237 |
+
|
1238 |
+
:param crypto_key: A ``cryptography`` X.509 certificate.
|
1239 |
+
:type crypto_key: ``cryptography.x509.Certificate``
|
1240 |
+
|
1241 |
+
:rtype: X509
|
1242 |
+
|
1243 |
+
.. versionadded:: 17.1.0
|
1244 |
+
"""
|
1245 |
+
if not isinstance(crypto_cert, x509.Certificate):
|
1246 |
+
raise TypeError("Must be a certificate")
|
1247 |
+
|
1248 |
+
from cryptography.hazmat.primitives.serialization import Encoding
|
1249 |
+
|
1250 |
+
der = crypto_cert.public_bytes(Encoding.DER)
|
1251 |
+
return load_certificate(FILETYPE_ASN1, der)
|
1252 |
+
|
1253 |
+
def set_version(self, version: int) -> None:
|
1254 |
+
"""
|
1255 |
+
Set the version number of the certificate. Note that the
|
1256 |
+
version value is zero-based, eg. a value of 0 is V1.
|
1257 |
+
|
1258 |
+
:param version: The version number of the certificate.
|
1259 |
+
:type version: :py:class:`int`
|
1260 |
+
|
1261 |
+
:return: ``None``
|
1262 |
+
"""
|
1263 |
+
if not isinstance(version, int):
|
1264 |
+
raise TypeError("version must be an integer")
|
1265 |
+
|
1266 |
+
_openssl_assert(_lib.X509_set_version(self._x509, version) == 1)
|
1267 |
+
|
1268 |
+
def get_version(self) -> int:
|
1269 |
+
"""
|
1270 |
+
Return the version number of the certificate.
|
1271 |
+
|
1272 |
+
:return: The version number of the certificate.
|
1273 |
+
:rtype: :py:class:`int`
|
1274 |
+
"""
|
1275 |
+
return _lib.X509_get_version(self._x509)
|
1276 |
+
|
1277 |
+
def get_pubkey(self) -> PKey:
|
1278 |
+
"""
|
1279 |
+
Get the public key of the certificate.
|
1280 |
+
|
1281 |
+
:return: The public key.
|
1282 |
+
:rtype: :py:class:`PKey`
|
1283 |
+
"""
|
1284 |
+
pkey = PKey.__new__(PKey)
|
1285 |
+
pkey._pkey = _lib.X509_get_pubkey(self._x509)
|
1286 |
+
if pkey._pkey == _ffi.NULL:
|
1287 |
+
_raise_current_error()
|
1288 |
+
pkey._pkey = _ffi.gc(pkey._pkey, _lib.EVP_PKEY_free)
|
1289 |
+
pkey._only_public = True
|
1290 |
+
return pkey
|
1291 |
+
|
1292 |
+
def set_pubkey(self, pkey: PKey) -> None:
|
1293 |
+
"""
|
1294 |
+
Set the public key of the certificate.
|
1295 |
+
|
1296 |
+
:param pkey: The public key.
|
1297 |
+
:type pkey: :py:class:`PKey`
|
1298 |
+
|
1299 |
+
:return: :py:data:`None`
|
1300 |
+
"""
|
1301 |
+
if not isinstance(pkey, PKey):
|
1302 |
+
raise TypeError("pkey must be a PKey instance")
|
1303 |
+
|
1304 |
+
set_result = _lib.X509_set_pubkey(self._x509, pkey._pkey)
|
1305 |
+
_openssl_assert(set_result == 1)
|
1306 |
+
|
1307 |
+
def sign(self, pkey: PKey, digest: str) -> None:
|
1308 |
+
"""
|
1309 |
+
Sign the certificate with this key and digest type.
|
1310 |
+
|
1311 |
+
:param pkey: The key to sign with.
|
1312 |
+
:type pkey: :py:class:`PKey`
|
1313 |
+
|
1314 |
+
:param digest: The name of the message digest to use.
|
1315 |
+
:type digest: :py:class:`str`
|
1316 |
+
|
1317 |
+
:return: :py:data:`None`
|
1318 |
+
"""
|
1319 |
+
if not isinstance(pkey, PKey):
|
1320 |
+
raise TypeError("pkey must be a PKey instance")
|
1321 |
+
|
1322 |
+
if pkey._only_public:
|
1323 |
+
raise ValueError("Key only has public part")
|
1324 |
+
|
1325 |
+
if not pkey._initialized:
|
1326 |
+
raise ValueError("Key is uninitialized")
|
1327 |
+
|
1328 |
+
evp_md = _lib.EVP_get_digestbyname(_byte_string(digest))
|
1329 |
+
if evp_md == _ffi.NULL:
|
1330 |
+
raise ValueError("No such digest method")
|
1331 |
+
|
1332 |
+
sign_result = _lib.X509_sign(self._x509, pkey._pkey, evp_md)
|
1333 |
+
_openssl_assert(sign_result > 0)
|
1334 |
+
|
1335 |
+
def get_signature_algorithm(self) -> bytes:
|
1336 |
+
"""
|
1337 |
+
Return the signature algorithm used in the certificate.
|
1338 |
+
|
1339 |
+
:return: The name of the algorithm.
|
1340 |
+
:rtype: :py:class:`bytes`
|
1341 |
+
|
1342 |
+
:raises ValueError: If the signature algorithm is undefined.
|
1343 |
+
|
1344 |
+
.. versionadded:: 0.13
|
1345 |
+
"""
|
1346 |
+
sig_alg = _lib.X509_get0_tbs_sigalg(self._x509)
|
1347 |
+
alg = _ffi.new("ASN1_OBJECT **")
|
1348 |
+
_lib.X509_ALGOR_get0(alg, _ffi.NULL, _ffi.NULL, sig_alg)
|
1349 |
+
nid = _lib.OBJ_obj2nid(alg[0])
|
1350 |
+
if nid == _lib.NID_undef:
|
1351 |
+
raise ValueError("Undefined signature algorithm")
|
1352 |
+
return _ffi.string(_lib.OBJ_nid2ln(nid))
|
1353 |
+
|
1354 |
+
def digest(self, digest_name: str) -> bytes:
|
1355 |
+
"""
|
1356 |
+
Return the digest of the X509 object.
|
1357 |
+
|
1358 |
+
:param digest_name: The name of the digest algorithm to use.
|
1359 |
+
:type digest_name: :py:class:`str`
|
1360 |
+
|
1361 |
+
:return: The digest of the object, formatted as
|
1362 |
+
:py:const:`b":"`-delimited hex pairs.
|
1363 |
+
:rtype: :py:class:`bytes`
|
1364 |
+
"""
|
1365 |
+
digest = _lib.EVP_get_digestbyname(_byte_string(digest_name))
|
1366 |
+
if digest == _ffi.NULL:
|
1367 |
+
raise ValueError("No such digest method")
|
1368 |
+
|
1369 |
+
result_buffer = _ffi.new("unsigned char[]", _lib.EVP_MAX_MD_SIZE)
|
1370 |
+
result_length = _ffi.new("unsigned int[]", 1)
|
1371 |
+
result_length[0] = len(result_buffer)
|
1372 |
+
|
1373 |
+
digest_result = _lib.X509_digest(
|
1374 |
+
self._x509, digest, result_buffer, result_length
|
1375 |
+
)
|
1376 |
+
_openssl_assert(digest_result == 1)
|
1377 |
+
|
1378 |
+
return b":".join(
|
1379 |
+
[
|
1380 |
+
b16encode(ch).upper()
|
1381 |
+
for ch in _ffi.buffer(result_buffer, result_length[0])
|
1382 |
+
]
|
1383 |
+
)
|
1384 |
+
|
1385 |
+
def subject_name_hash(self) -> int:
|
1386 |
+
"""
|
1387 |
+
Return the hash of the X509 subject.
|
1388 |
+
|
1389 |
+
:return: The hash of the subject.
|
1390 |
+
:rtype: :py:class:`int`
|
1391 |
+
"""
|
1392 |
+
return _lib.X509_subject_name_hash(self._x509)
|
1393 |
+
|
1394 |
+
def set_serial_number(self, serial: int) -> None:
|
1395 |
+
"""
|
1396 |
+
Set the serial number of the certificate.
|
1397 |
+
|
1398 |
+
:param serial: The new serial number.
|
1399 |
+
:type serial: :py:class:`int`
|
1400 |
+
|
1401 |
+
:return: :py:data`None`
|
1402 |
+
"""
|
1403 |
+
if not isinstance(serial, int):
|
1404 |
+
raise TypeError("serial must be an integer")
|
1405 |
+
|
1406 |
+
hex_serial = hex(serial)[2:]
|
1407 |
+
hex_serial_bytes = hex_serial.encode("ascii")
|
1408 |
+
|
1409 |
+
bignum_serial = _ffi.new("BIGNUM**")
|
1410 |
+
|
1411 |
+
# BN_hex2bn stores the result in &bignum.
|
1412 |
+
result = _lib.BN_hex2bn(bignum_serial, hex_serial_bytes)
|
1413 |
+
_openssl_assert(result != _ffi.NULL)
|
1414 |
+
|
1415 |
+
asn1_serial = _lib.BN_to_ASN1_INTEGER(bignum_serial[0], _ffi.NULL)
|
1416 |
+
_lib.BN_free(bignum_serial[0])
|
1417 |
+
_openssl_assert(asn1_serial != _ffi.NULL)
|
1418 |
+
asn1_serial = _ffi.gc(asn1_serial, _lib.ASN1_INTEGER_free)
|
1419 |
+
set_result = _lib.X509_set_serialNumber(self._x509, asn1_serial)
|
1420 |
+
_openssl_assert(set_result == 1)
|
1421 |
+
|
1422 |
+
def get_serial_number(self) -> int:
|
1423 |
+
"""
|
1424 |
+
Return the serial number of this certificate.
|
1425 |
+
|
1426 |
+
:return: The serial number.
|
1427 |
+
:rtype: int
|
1428 |
+
"""
|
1429 |
+
asn1_serial = _lib.X509_get_serialNumber(self._x509)
|
1430 |
+
bignum_serial = _lib.ASN1_INTEGER_to_BN(asn1_serial, _ffi.NULL)
|
1431 |
+
try:
|
1432 |
+
hex_serial = _lib.BN_bn2hex(bignum_serial)
|
1433 |
+
try:
|
1434 |
+
hexstring_serial = _ffi.string(hex_serial)
|
1435 |
+
serial = int(hexstring_serial, 16)
|
1436 |
+
return serial
|
1437 |
+
finally:
|
1438 |
+
_lib.OPENSSL_free(hex_serial)
|
1439 |
+
finally:
|
1440 |
+
_lib.BN_free(bignum_serial)
|
1441 |
+
|
1442 |
+
def gmtime_adj_notAfter(self, amount: int) -> None:
|
1443 |
+
"""
|
1444 |
+
Adjust the time stamp on which the certificate stops being valid.
|
1445 |
+
|
1446 |
+
:param int amount: The number of seconds by which to adjust the
|
1447 |
+
timestamp.
|
1448 |
+
:return: ``None``
|
1449 |
+
"""
|
1450 |
+
if not isinstance(amount, int):
|
1451 |
+
raise TypeError("amount must be an integer")
|
1452 |
+
|
1453 |
+
notAfter = _lib.X509_getm_notAfter(self._x509)
|
1454 |
+
_lib.X509_gmtime_adj(notAfter, amount)
|
1455 |
+
|
1456 |
+
def gmtime_adj_notBefore(self, amount: int) -> None:
|
1457 |
+
"""
|
1458 |
+
Adjust the timestamp on which the certificate starts being valid.
|
1459 |
+
|
1460 |
+
:param amount: The number of seconds by which to adjust the timestamp.
|
1461 |
+
:return: ``None``
|
1462 |
+
"""
|
1463 |
+
if not isinstance(amount, int):
|
1464 |
+
raise TypeError("amount must be an integer")
|
1465 |
+
|
1466 |
+
notBefore = _lib.X509_getm_notBefore(self._x509)
|
1467 |
+
_lib.X509_gmtime_adj(notBefore, amount)
|
1468 |
+
|
1469 |
+
def has_expired(self) -> bool:
|
1470 |
+
"""
|
1471 |
+
Check whether the certificate has expired.
|
1472 |
+
|
1473 |
+
:return: ``True`` if the certificate has expired, ``False`` otherwise.
|
1474 |
+
:rtype: bool
|
1475 |
+
"""
|
1476 |
+
time_bytes = self.get_notAfter()
|
1477 |
+
if time_bytes is None:
|
1478 |
+
raise ValueError("Unable to determine notAfter")
|
1479 |
+
time_string = time_bytes.decode("utf-8")
|
1480 |
+
not_after = datetime.datetime.strptime(time_string, "%Y%m%d%H%M%SZ")
|
1481 |
+
|
1482 |
+
UTC = datetime.timezone.utc
|
1483 |
+
utcnow = datetime.datetime.now(UTC).replace(tzinfo=None)
|
1484 |
+
return not_after < utcnow
|
1485 |
+
|
1486 |
+
def _get_boundary_time(self, which: Any) -> bytes | None:
|
1487 |
+
return _get_asn1_time(which(self._x509))
|
1488 |
+
|
1489 |
+
def get_notBefore(self) -> bytes | None:
|
1490 |
+
"""
|
1491 |
+
Get the timestamp at which the certificate starts being valid.
|
1492 |
+
|
1493 |
+
The timestamp is formatted as an ASN.1 TIME::
|
1494 |
+
|
1495 |
+
YYYYMMDDhhmmssZ
|
1496 |
+
|
1497 |
+
:return: A timestamp string, or ``None`` if there is none.
|
1498 |
+
:rtype: bytes or NoneType
|
1499 |
+
"""
|
1500 |
+
return self._get_boundary_time(_lib.X509_getm_notBefore)
|
1501 |
+
|
1502 |
+
def _set_boundary_time(
|
1503 |
+
self, which: Callable[..., Any], when: bytes
|
1504 |
+
) -> None:
|
1505 |
+
return _set_asn1_time(which(self._x509), when)
|
1506 |
+
|
1507 |
+
def set_notBefore(self, when: bytes) -> None:
|
1508 |
+
"""
|
1509 |
+
Set the timestamp at which the certificate starts being valid.
|
1510 |
+
|
1511 |
+
The timestamp is formatted as an ASN.1 TIME::
|
1512 |
+
|
1513 |
+
YYYYMMDDhhmmssZ
|
1514 |
+
|
1515 |
+
:param bytes when: A timestamp string.
|
1516 |
+
:return: ``None``
|
1517 |
+
"""
|
1518 |
+
return self._set_boundary_time(_lib.X509_getm_notBefore, when)
|
1519 |
+
|
1520 |
+
def get_notAfter(self) -> bytes | None:
|
1521 |
+
"""
|
1522 |
+
Get the timestamp at which the certificate stops being valid.
|
1523 |
+
|
1524 |
+
The timestamp is formatted as an ASN.1 TIME::
|
1525 |
+
|
1526 |
+
YYYYMMDDhhmmssZ
|
1527 |
+
|
1528 |
+
:return: A timestamp string, or ``None`` if there is none.
|
1529 |
+
:rtype: bytes or NoneType
|
1530 |
+
"""
|
1531 |
+
return self._get_boundary_time(_lib.X509_getm_notAfter)
|
1532 |
+
|
1533 |
+
def set_notAfter(self, when: bytes) -> None:
|
1534 |
+
"""
|
1535 |
+
Set the timestamp at which the certificate stops being valid.
|
1536 |
+
|
1537 |
+
The timestamp is formatted as an ASN.1 TIME::
|
1538 |
+
|
1539 |
+
YYYYMMDDhhmmssZ
|
1540 |
+
|
1541 |
+
:param bytes when: A timestamp string.
|
1542 |
+
:return: ``None``
|
1543 |
+
"""
|
1544 |
+
return self._set_boundary_time(_lib.X509_getm_notAfter, when)
|
1545 |
+
|
1546 |
+
def _get_name(self, which: Any) -> X509Name:
|
1547 |
+
name = X509Name.__new__(X509Name)
|
1548 |
+
name._name = which(self._x509)
|
1549 |
+
_openssl_assert(name._name != _ffi.NULL)
|
1550 |
+
|
1551 |
+
# The name is owned by the X509 structure. As long as the X509Name
|
1552 |
+
# Python object is alive, keep the X509 Python object alive.
|
1553 |
+
name._owner = self
|
1554 |
+
|
1555 |
+
return name
|
1556 |
+
|
1557 |
+
def _set_name(self, which: Any, name: X509Name) -> None:
|
1558 |
+
if not isinstance(name, X509Name):
|
1559 |
+
raise TypeError("name must be an X509Name")
|
1560 |
+
set_result = which(self._x509, name._name)
|
1561 |
+
_openssl_assert(set_result == 1)
|
1562 |
+
|
1563 |
+
def get_issuer(self) -> X509Name:
|
1564 |
+
"""
|
1565 |
+
Return the issuer of this certificate.
|
1566 |
+
|
1567 |
+
This creates a new :class:`X509Name` that wraps the underlying issuer
|
1568 |
+
name field on the certificate. Modifying it will modify the underlying
|
1569 |
+
certificate, and will have the effect of modifying any other
|
1570 |
+
:class:`X509Name` that refers to this issuer.
|
1571 |
+
|
1572 |
+
:return: The issuer of this certificate.
|
1573 |
+
:rtype: :class:`X509Name`
|
1574 |
+
"""
|
1575 |
+
name = self._get_name(_lib.X509_get_issuer_name)
|
1576 |
+
self._issuer_invalidator.add(name)
|
1577 |
+
return name
|
1578 |
+
|
1579 |
+
def set_issuer(self, issuer: X509Name) -> None:
|
1580 |
+
"""
|
1581 |
+
Set the issuer of this certificate.
|
1582 |
+
|
1583 |
+
:param issuer: The issuer.
|
1584 |
+
:type issuer: :py:class:`X509Name`
|
1585 |
+
|
1586 |
+
:return: ``None``
|
1587 |
+
"""
|
1588 |
+
self._set_name(_lib.X509_set_issuer_name, issuer)
|
1589 |
+
self._issuer_invalidator.clear()
|
1590 |
+
|
1591 |
+
def get_subject(self) -> X509Name:
|
1592 |
+
"""
|
1593 |
+
Return the subject of this certificate.
|
1594 |
+
|
1595 |
+
This creates a new :class:`X509Name` that wraps the underlying subject
|
1596 |
+
name field on the certificate. Modifying it will modify the underlying
|
1597 |
+
certificate, and will have the effect of modifying any other
|
1598 |
+
:class:`X509Name` that refers to this subject.
|
1599 |
+
|
1600 |
+
:return: The subject of this certificate.
|
1601 |
+
:rtype: :class:`X509Name`
|
1602 |
+
"""
|
1603 |
+
name = self._get_name(_lib.X509_get_subject_name)
|
1604 |
+
self._subject_invalidator.add(name)
|
1605 |
+
return name
|
1606 |
+
|
1607 |
+
def set_subject(self, subject: X509Name) -> None:
|
1608 |
+
"""
|
1609 |
+
Set the subject of this certificate.
|
1610 |
+
|
1611 |
+
:param subject: The subject.
|
1612 |
+
:type subject: :py:class:`X509Name`
|
1613 |
+
|
1614 |
+
:return: ``None``
|
1615 |
+
"""
|
1616 |
+
self._set_name(_lib.X509_set_subject_name, subject)
|
1617 |
+
self._subject_invalidator.clear()
|
1618 |
+
|
1619 |
+
def get_extension_count(self) -> int:
|
1620 |
+
"""
|
1621 |
+
Get the number of extensions on this certificate.
|
1622 |
+
|
1623 |
+
:return: The number of extensions.
|
1624 |
+
:rtype: :py:class:`int`
|
1625 |
+
|
1626 |
+
.. versionadded:: 0.12
|
1627 |
+
"""
|
1628 |
+
return _lib.X509_get_ext_count(self._x509)
|
1629 |
+
|
1630 |
+
def add_extensions(self, extensions: Iterable[X509Extension]) -> None:
|
1631 |
+
"""
|
1632 |
+
Add extensions to the certificate.
|
1633 |
+
|
1634 |
+
:param extensions: The extensions to add.
|
1635 |
+
:type extensions: An iterable of :py:class:`X509Extension` objects.
|
1636 |
+
:return: ``None``
|
1637 |
+
"""
|
1638 |
+
warnings.warn(
|
1639 |
+
(
|
1640 |
+
"This API is deprecated and will be removed in a future "
|
1641 |
+
"version of pyOpenSSL. You should use pyca/cryptography's "
|
1642 |
+
"X.509 APIs instead."
|
1643 |
+
),
|
1644 |
+
DeprecationWarning,
|
1645 |
+
stacklevel=2,
|
1646 |
+
)
|
1647 |
+
|
1648 |
+
for ext in extensions:
|
1649 |
+
if not isinstance(ext, X509Extension):
|
1650 |
+
raise ValueError("One of the elements is not an X509Extension")
|
1651 |
+
|
1652 |
+
add_result = _lib.X509_add_ext(self._x509, ext._extension, -1)
|
1653 |
+
_openssl_assert(add_result == 1)
|
1654 |
+
|
1655 |
+
def get_extension(self, index: int) -> X509Extension:
|
1656 |
+
"""
|
1657 |
+
Get a specific extension of the certificate by index.
|
1658 |
+
|
1659 |
+
Extensions on a certificate are kept in order. The index
|
1660 |
+
parameter selects which extension will be returned.
|
1661 |
+
|
1662 |
+
:param int index: The index of the extension to retrieve.
|
1663 |
+
:return: The extension at the specified index.
|
1664 |
+
:rtype: :py:class:`X509Extension`
|
1665 |
+
:raises IndexError: If the extension index was out of bounds.
|
1666 |
+
|
1667 |
+
.. versionadded:: 0.12
|
1668 |
+
"""
|
1669 |
+
warnings.warn(
|
1670 |
+
(
|
1671 |
+
"This API is deprecated and will be removed in a future "
|
1672 |
+
"version of pyOpenSSL. You should use pyca/cryptography's "
|
1673 |
+
"X.509 APIs instead."
|
1674 |
+
),
|
1675 |
+
DeprecationWarning,
|
1676 |
+
stacklevel=2,
|
1677 |
+
)
|
1678 |
+
|
1679 |
+
ext = X509Extension.__new__(X509Extension)
|
1680 |
+
ext._extension = _lib.X509_get_ext(self._x509, index)
|
1681 |
+
if ext._extension == _ffi.NULL:
|
1682 |
+
raise IndexError("extension index out of bounds")
|
1683 |
+
|
1684 |
+
extension = _lib.X509_EXTENSION_dup(ext._extension)
|
1685 |
+
ext._extension = _ffi.gc(extension, _lib.X509_EXTENSION_free)
|
1686 |
+
return ext
|
1687 |
+
|
1688 |
+
|
1689 |
+
class X509StoreFlags:
|
1690 |
+
"""
|
1691 |
+
Flags for X509 verification, used to change the behavior of
|
1692 |
+
:class:`X509Store`.
|
1693 |
+
|
1694 |
+
See `OpenSSL Verification Flags`_ for details.
|
1695 |
+
|
1696 |
+
.. _OpenSSL Verification Flags:
|
1697 |
+
https://www.openssl.org/docs/manmaster/man3/X509_VERIFY_PARAM_set_flags.html
|
1698 |
+
"""
|
1699 |
+
|
1700 |
+
CRL_CHECK: int = _lib.X509_V_FLAG_CRL_CHECK
|
1701 |
+
CRL_CHECK_ALL: int = _lib.X509_V_FLAG_CRL_CHECK_ALL
|
1702 |
+
IGNORE_CRITICAL: int = _lib.X509_V_FLAG_IGNORE_CRITICAL
|
1703 |
+
X509_STRICT: int = _lib.X509_V_FLAG_X509_STRICT
|
1704 |
+
ALLOW_PROXY_CERTS: int = _lib.X509_V_FLAG_ALLOW_PROXY_CERTS
|
1705 |
+
POLICY_CHECK: int = _lib.X509_V_FLAG_POLICY_CHECK
|
1706 |
+
EXPLICIT_POLICY: int = _lib.X509_V_FLAG_EXPLICIT_POLICY
|
1707 |
+
INHIBIT_MAP: int = _lib.X509_V_FLAG_INHIBIT_MAP
|
1708 |
+
CHECK_SS_SIGNATURE: int = _lib.X509_V_FLAG_CHECK_SS_SIGNATURE
|
1709 |
+
PARTIAL_CHAIN: int = _lib.X509_V_FLAG_PARTIAL_CHAIN
|
1710 |
+
|
1711 |
+
|
1712 |
+
class X509Store:
|
1713 |
+
"""
|
1714 |
+
An X.509 store.
|
1715 |
+
|
1716 |
+
An X.509 store is used to describe a context in which to verify a
|
1717 |
+
certificate. A description of a context may include a set of certificates
|
1718 |
+
to trust, a set of certificate revocation lists, verification flags and
|
1719 |
+
more.
|
1720 |
+
|
1721 |
+
An X.509 store, being only a description, cannot be used by itself to
|
1722 |
+
verify a certificate. To carry out the actual verification process, see
|
1723 |
+
:class:`X509StoreContext`.
|
1724 |
+
"""
|
1725 |
+
|
1726 |
+
def __init__(self) -> None:
|
1727 |
+
store = _lib.X509_STORE_new()
|
1728 |
+
self._store = _ffi.gc(store, _lib.X509_STORE_free)
|
1729 |
+
|
1730 |
+
def add_cert(self, cert: X509) -> None:
|
1731 |
+
"""
|
1732 |
+
Adds a trusted certificate to this store.
|
1733 |
+
|
1734 |
+
Adding a certificate with this method adds this certificate as a
|
1735 |
+
*trusted* certificate.
|
1736 |
+
|
1737 |
+
:param X509 cert: The certificate to add to this store.
|
1738 |
+
|
1739 |
+
:raises TypeError: If the certificate is not an :class:`X509`.
|
1740 |
+
|
1741 |
+
:raises OpenSSL.crypto.Error: If OpenSSL was unhappy with your
|
1742 |
+
certificate.
|
1743 |
+
|
1744 |
+
:return: ``None`` if the certificate was added successfully.
|
1745 |
+
"""
|
1746 |
+
if not isinstance(cert, X509):
|
1747 |
+
raise TypeError()
|
1748 |
+
|
1749 |
+
res = _lib.X509_STORE_add_cert(self._store, cert._x509)
|
1750 |
+
_openssl_assert(res == 1)
|
1751 |
+
|
1752 |
+
def add_crl(self, crl: x509.CertificateRevocationList) -> None:
|
1753 |
+
"""
|
1754 |
+
Add a certificate revocation list to this store.
|
1755 |
+
|
1756 |
+
The certificate revocation lists added to a store will only be used if
|
1757 |
+
the associated flags are configured to check certificate revocation
|
1758 |
+
lists.
|
1759 |
+
|
1760 |
+
.. versionadded:: 16.1.0
|
1761 |
+
|
1762 |
+
:param crl: The certificate revocation list to add to this store.
|
1763 |
+
:type crl: ``cryptography.x509.CertificateRevocationList``
|
1764 |
+
:return: ``None`` if the certificate revocation list was added
|
1765 |
+
successfully.
|
1766 |
+
"""
|
1767 |
+
if isinstance(crl, x509.CertificateRevocationList):
|
1768 |
+
from cryptography.hazmat.primitives.serialization import Encoding
|
1769 |
+
|
1770 |
+
bio = _new_mem_buf(crl.public_bytes(Encoding.DER))
|
1771 |
+
openssl_crl = _lib.d2i_X509_CRL_bio(bio, _ffi.NULL)
|
1772 |
+
_openssl_assert(openssl_crl != _ffi.NULL)
|
1773 |
+
crl = _ffi.gc(openssl_crl, _lib.X509_CRL_free)
|
1774 |
+
else:
|
1775 |
+
raise TypeError(
|
1776 |
+
"CRL must be of type "
|
1777 |
+
"cryptography.x509.CertificateRevocationList"
|
1778 |
+
)
|
1779 |
+
|
1780 |
+
_openssl_assert(_lib.X509_STORE_add_crl(self._store, crl) != 0)
|
1781 |
+
|
1782 |
+
def set_flags(self, flags: int) -> None:
|
1783 |
+
"""
|
1784 |
+
Set verification flags to this store.
|
1785 |
+
|
1786 |
+
Verification flags can be combined by oring them together.
|
1787 |
+
|
1788 |
+
.. note::
|
1789 |
+
|
1790 |
+
Setting a verification flag sometimes requires clients to add
|
1791 |
+
additional information to the store, otherwise a suitable error will
|
1792 |
+
be raised.
|
1793 |
+
|
1794 |
+
For example, in setting flags to enable CRL checking a
|
1795 |
+
suitable CRL must be added to the store otherwise an error will be
|
1796 |
+
raised.
|
1797 |
+
|
1798 |
+
.. versionadded:: 16.1.0
|
1799 |
+
|
1800 |
+
:param int flags: The verification flags to set on this store.
|
1801 |
+
See :class:`X509StoreFlags` for available constants.
|
1802 |
+
:return: ``None`` if the verification flags were successfully set.
|
1803 |
+
"""
|
1804 |
+
_openssl_assert(_lib.X509_STORE_set_flags(self._store, flags) != 0)
|
1805 |
+
|
1806 |
+
def set_time(self, vfy_time: datetime.datetime) -> None:
|
1807 |
+
"""
|
1808 |
+
Set the time against which the certificates are verified.
|
1809 |
+
|
1810 |
+
Normally the current time is used.
|
1811 |
+
|
1812 |
+
.. note::
|
1813 |
+
|
1814 |
+
For example, you can determine if a certificate was valid at a given
|
1815 |
+
time.
|
1816 |
+
|
1817 |
+
.. versionadded:: 17.0.0
|
1818 |
+
|
1819 |
+
:param datetime vfy_time: The verification time to set on this store.
|
1820 |
+
:return: ``None`` if the verification time was successfully set.
|
1821 |
+
"""
|
1822 |
+
param = _lib.X509_VERIFY_PARAM_new()
|
1823 |
+
param = _ffi.gc(param, _lib.X509_VERIFY_PARAM_free)
|
1824 |
+
|
1825 |
+
_lib.X509_VERIFY_PARAM_set_time(
|
1826 |
+
param, calendar.timegm(vfy_time.timetuple())
|
1827 |
+
)
|
1828 |
+
_openssl_assert(_lib.X509_STORE_set1_param(self._store, param) != 0)
|
1829 |
+
|
1830 |
+
def load_locations(
|
1831 |
+
self,
|
1832 |
+
cafile: StrOrBytesPath | None,
|
1833 |
+
capath: StrOrBytesPath | None = None,
|
1834 |
+
) -> None:
|
1835 |
+
"""
|
1836 |
+
Let X509Store know where we can find trusted certificates for the
|
1837 |
+
certificate chain. Note that the certificates have to be in PEM
|
1838 |
+
format.
|
1839 |
+
|
1840 |
+
If *capath* is passed, it must be a directory prepared using the
|
1841 |
+
``c_rehash`` tool included with OpenSSL. Either, but not both, of
|
1842 |
+
*cafile* or *capath* may be ``None``.
|
1843 |
+
|
1844 |
+
.. note::
|
1845 |
+
|
1846 |
+
Both *cafile* and *capath* may be set simultaneously.
|
1847 |
+
|
1848 |
+
Call this method multiple times to add more than one location.
|
1849 |
+
For example, CA certificates, and certificate revocation list bundles
|
1850 |
+
may be passed in *cafile* in subsequent calls to this method.
|
1851 |
+
|
1852 |
+
.. versionadded:: 20.0
|
1853 |
+
|
1854 |
+
:param cafile: In which file we can find the certificates (``bytes`` or
|
1855 |
+
``unicode``).
|
1856 |
+
:param capath: In which directory we can find the certificates
|
1857 |
+
(``bytes`` or ``unicode``).
|
1858 |
+
|
1859 |
+
:return: ``None`` if the locations were set successfully.
|
1860 |
+
|
1861 |
+
:raises OpenSSL.crypto.Error: If both *cafile* and *capath* is ``None``
|
1862 |
+
or the locations could not be set for any reason.
|
1863 |
+
|
1864 |
+
"""
|
1865 |
+
if cafile is None:
|
1866 |
+
cafile = _ffi.NULL
|
1867 |
+
else:
|
1868 |
+
cafile = _path_bytes(cafile)
|
1869 |
+
|
1870 |
+
if capath is None:
|
1871 |
+
capath = _ffi.NULL
|
1872 |
+
else:
|
1873 |
+
capath = _path_bytes(capath)
|
1874 |
+
|
1875 |
+
load_result = _lib.X509_STORE_load_locations(
|
1876 |
+
self._store, cafile, capath
|
1877 |
+
)
|
1878 |
+
if not load_result:
|
1879 |
+
_raise_current_error()
|
1880 |
+
|
1881 |
+
|
1882 |
+
class X509StoreContextError(Exception):
|
1883 |
+
"""
|
1884 |
+
An exception raised when an error occurred while verifying a certificate
|
1885 |
+
using `OpenSSL.X509StoreContext.verify_certificate`.
|
1886 |
+
|
1887 |
+
:ivar certificate: The certificate which caused verificate failure.
|
1888 |
+
:type certificate: :class:`X509`
|
1889 |
+
"""
|
1890 |
+
|
1891 |
+
def __init__(
|
1892 |
+
self, message: str, errors: list[Any], certificate: X509
|
1893 |
+
) -> None:
|
1894 |
+
super().__init__(message)
|
1895 |
+
self.errors = errors
|
1896 |
+
self.certificate = certificate
|
1897 |
+
|
1898 |
+
|
1899 |
+
class X509StoreContext:
|
1900 |
+
"""
|
1901 |
+
An X.509 store context.
|
1902 |
+
|
1903 |
+
An X.509 store context is used to carry out the actual verification process
|
1904 |
+
of a certificate in a described context. For describing such a context, see
|
1905 |
+
:class:`X509Store`.
|
1906 |
+
|
1907 |
+
:param X509Store store: The certificates which will be trusted for the
|
1908 |
+
purposes of any verifications.
|
1909 |
+
:param X509 certificate: The certificate to be verified.
|
1910 |
+
:param chain: List of untrusted certificates that may be used for building
|
1911 |
+
the certificate chain. May be ``None``.
|
1912 |
+
:type chain: :class:`list` of :class:`X509`
|
1913 |
+
"""
|
1914 |
+
|
1915 |
+
def __init__(
|
1916 |
+
self,
|
1917 |
+
store: X509Store,
|
1918 |
+
certificate: X509,
|
1919 |
+
chain: Sequence[X509] | None = None,
|
1920 |
+
) -> None:
|
1921 |
+
self._store = store
|
1922 |
+
self._cert = certificate
|
1923 |
+
self._chain = self._build_certificate_stack(chain)
|
1924 |
+
|
1925 |
+
@staticmethod
|
1926 |
+
def _build_certificate_stack(
|
1927 |
+
certificates: Sequence[X509] | None,
|
1928 |
+
) -> None:
|
1929 |
+
def cleanup(s: Any) -> None:
|
1930 |
+
# Equivalent to sk_X509_pop_free, but we don't
|
1931 |
+
# currently have a CFFI binding for that available
|
1932 |
+
for i in range(_lib.sk_X509_num(s)):
|
1933 |
+
x = _lib.sk_X509_value(s, i)
|
1934 |
+
_lib.X509_free(x)
|
1935 |
+
_lib.sk_X509_free(s)
|
1936 |
+
|
1937 |
+
if certificates is None or len(certificates) == 0:
|
1938 |
+
return _ffi.NULL
|
1939 |
+
|
1940 |
+
stack = _lib.sk_X509_new_null()
|
1941 |
+
_openssl_assert(stack != _ffi.NULL)
|
1942 |
+
stack = _ffi.gc(stack, cleanup)
|
1943 |
+
|
1944 |
+
for cert in certificates:
|
1945 |
+
if not isinstance(cert, X509):
|
1946 |
+
raise TypeError("One of the elements is not an X509 instance")
|
1947 |
+
|
1948 |
+
_openssl_assert(_lib.X509_up_ref(cert._x509) > 0)
|
1949 |
+
if _lib.sk_X509_push(stack, cert._x509) <= 0:
|
1950 |
+
_lib.X509_free(cert._x509)
|
1951 |
+
_raise_current_error()
|
1952 |
+
|
1953 |
+
return stack
|
1954 |
+
|
1955 |
+
@staticmethod
|
1956 |
+
def _exception_from_context(store_ctx: Any) -> X509StoreContextError:
|
1957 |
+
"""
|
1958 |
+
Convert an OpenSSL native context error failure into a Python
|
1959 |
+
exception.
|
1960 |
+
|
1961 |
+
When a call to native OpenSSL X509_verify_cert fails, additional
|
1962 |
+
information about the failure can be obtained from the store context.
|
1963 |
+
"""
|
1964 |
+
message = _ffi.string(
|
1965 |
+
_lib.X509_verify_cert_error_string(
|
1966 |
+
_lib.X509_STORE_CTX_get_error(store_ctx)
|
1967 |
+
)
|
1968 |
+
).decode("utf-8")
|
1969 |
+
errors = [
|
1970 |
+
_lib.X509_STORE_CTX_get_error(store_ctx),
|
1971 |
+
_lib.X509_STORE_CTX_get_error_depth(store_ctx),
|
1972 |
+
message,
|
1973 |
+
]
|
1974 |
+
# A context error should always be associated with a certificate, so we
|
1975 |
+
# expect this call to never return :class:`None`.
|
1976 |
+
_x509 = _lib.X509_STORE_CTX_get_current_cert(store_ctx)
|
1977 |
+
_cert = _lib.X509_dup(_x509)
|
1978 |
+
pycert = X509._from_raw_x509_ptr(_cert)
|
1979 |
+
return X509StoreContextError(message, errors, pycert)
|
1980 |
+
|
1981 |
+
def _verify_certificate(self) -> Any:
|
1982 |
+
"""
|
1983 |
+
Verifies the certificate and runs an X509_STORE_CTX containing the
|
1984 |
+
results.
|
1985 |
+
|
1986 |
+
:raises X509StoreContextError: If an error occurred when validating a
|
1987 |
+
certificate in the context. Sets ``certificate`` attribute to
|
1988 |
+
indicate which certificate caused the error.
|
1989 |
+
"""
|
1990 |
+
store_ctx = _lib.X509_STORE_CTX_new()
|
1991 |
+
_openssl_assert(store_ctx != _ffi.NULL)
|
1992 |
+
store_ctx = _ffi.gc(store_ctx, _lib.X509_STORE_CTX_free)
|
1993 |
+
|
1994 |
+
ret = _lib.X509_STORE_CTX_init(
|
1995 |
+
store_ctx, self._store._store, self._cert._x509, self._chain
|
1996 |
+
)
|
1997 |
+
_openssl_assert(ret == 1)
|
1998 |
+
|
1999 |
+
ret = _lib.X509_verify_cert(store_ctx)
|
2000 |
+
if ret <= 0:
|
2001 |
+
raise self._exception_from_context(store_ctx)
|
2002 |
+
|
2003 |
+
return store_ctx
|
2004 |
+
|
2005 |
+
def set_store(self, store: X509Store) -> None:
|
2006 |
+
"""
|
2007 |
+
Set the context's X.509 store.
|
2008 |
+
|
2009 |
+
.. versionadded:: 0.15
|
2010 |
+
|
2011 |
+
:param X509Store store: The store description which will be used for
|
2012 |
+
the purposes of any *future* verifications.
|
2013 |
+
"""
|
2014 |
+
self._store = store
|
2015 |
+
|
2016 |
+
def verify_certificate(self) -> None:
|
2017 |
+
"""
|
2018 |
+
Verify a certificate in a context.
|
2019 |
+
|
2020 |
+
.. versionadded:: 0.15
|
2021 |
+
|
2022 |
+
:raises X509StoreContextError: If an error occurred when validating a
|
2023 |
+
certificate in the context. Sets ``certificate`` attribute to
|
2024 |
+
indicate which certificate caused the error.
|
2025 |
+
"""
|
2026 |
+
self._verify_certificate()
|
2027 |
+
|
2028 |
+
def get_verified_chain(self) -> list[X509]:
|
2029 |
+
"""
|
2030 |
+
Verify a certificate in a context and return the complete validated
|
2031 |
+
chain.
|
2032 |
+
|
2033 |
+
:raises X509StoreContextError: If an error occurred when validating a
|
2034 |
+
certificate in the context. Sets ``certificate`` attribute to
|
2035 |
+
indicate which certificate caused the error.
|
2036 |
+
|
2037 |
+
.. versionadded:: 20.0
|
2038 |
+
"""
|
2039 |
+
store_ctx = self._verify_certificate()
|
2040 |
+
|
2041 |
+
# Note: X509_STORE_CTX_get1_chain returns a deep copy of the chain.
|
2042 |
+
cert_stack = _lib.X509_STORE_CTX_get1_chain(store_ctx)
|
2043 |
+
_openssl_assert(cert_stack != _ffi.NULL)
|
2044 |
+
|
2045 |
+
result = []
|
2046 |
+
for i in range(_lib.sk_X509_num(cert_stack)):
|
2047 |
+
cert = _lib.sk_X509_value(cert_stack, i)
|
2048 |
+
_openssl_assert(cert != _ffi.NULL)
|
2049 |
+
pycert = X509._from_raw_x509_ptr(cert)
|
2050 |
+
result.append(pycert)
|
2051 |
+
|
2052 |
+
# Free the stack but not the members which are freed by the X509 class.
|
2053 |
+
_lib.sk_X509_free(cert_stack)
|
2054 |
+
return result
|
2055 |
+
|
2056 |
+
|
2057 |
+
def load_certificate(type: int, buffer: bytes) -> X509:
|
2058 |
+
"""
|
2059 |
+
Load a certificate (X509) from the string *buffer* encoded with the
|
2060 |
+
type *type*.
|
2061 |
+
|
2062 |
+
:param type: The file type (one of FILETYPE_PEM, FILETYPE_ASN1)
|
2063 |
+
|
2064 |
+
:param bytes buffer: The buffer the certificate is stored in
|
2065 |
+
|
2066 |
+
:return: The X509 object
|
2067 |
+
"""
|
2068 |
+
if isinstance(buffer, str):
|
2069 |
+
buffer = buffer.encode("ascii")
|
2070 |
+
|
2071 |
+
bio = _new_mem_buf(buffer)
|
2072 |
+
|
2073 |
+
if type == FILETYPE_PEM:
|
2074 |
+
x509 = _lib.PEM_read_bio_X509(bio, _ffi.NULL, _ffi.NULL, _ffi.NULL)
|
2075 |
+
elif type == FILETYPE_ASN1:
|
2076 |
+
x509 = _lib.d2i_X509_bio(bio, _ffi.NULL)
|
2077 |
+
else:
|
2078 |
+
raise ValueError("type argument must be FILETYPE_PEM or FILETYPE_ASN1")
|
2079 |
+
|
2080 |
+
if x509 == _ffi.NULL:
|
2081 |
+
_raise_current_error()
|
2082 |
+
|
2083 |
+
return X509._from_raw_x509_ptr(x509)
|
2084 |
+
|
2085 |
+
|
2086 |
+
def dump_certificate(type: int, cert: X509) -> bytes:
|
2087 |
+
"""
|
2088 |
+
Dump the certificate *cert* into a buffer string encoded with the type
|
2089 |
+
*type*.
|
2090 |
+
|
2091 |
+
:param type: The file type (one of FILETYPE_PEM, FILETYPE_ASN1, or
|
2092 |
+
FILETYPE_TEXT)
|
2093 |
+
:param cert: The certificate to dump
|
2094 |
+
:return: The buffer with the dumped certificate in
|
2095 |
+
"""
|
2096 |
+
bio = _new_mem_buf()
|
2097 |
+
|
2098 |
+
if type == FILETYPE_PEM:
|
2099 |
+
result_code = _lib.PEM_write_bio_X509(bio, cert._x509)
|
2100 |
+
elif type == FILETYPE_ASN1:
|
2101 |
+
result_code = _lib.i2d_X509_bio(bio, cert._x509)
|
2102 |
+
elif type == FILETYPE_TEXT:
|
2103 |
+
result_code = _lib.X509_print_ex(bio, cert._x509, 0, 0)
|
2104 |
+
else:
|
2105 |
+
raise ValueError(
|
2106 |
+
"type argument must be FILETYPE_PEM, FILETYPE_ASN1, or "
|
2107 |
+
"FILETYPE_TEXT"
|
2108 |
+
)
|
2109 |
+
|
2110 |
+
_openssl_assert(result_code == 1)
|
2111 |
+
return _bio_to_string(bio)
|
2112 |
+
|
2113 |
+
|
2114 |
+
def dump_publickey(type: int, pkey: PKey) -> bytes:
|
2115 |
+
"""
|
2116 |
+
Dump a public key to a buffer.
|
2117 |
+
|
2118 |
+
:param type: The file type (one of :data:`FILETYPE_PEM` or
|
2119 |
+
:data:`FILETYPE_ASN1`).
|
2120 |
+
:param PKey pkey: The public key to dump
|
2121 |
+
:return: The buffer with the dumped key in it.
|
2122 |
+
:rtype: bytes
|
2123 |
+
"""
|
2124 |
+
bio = _new_mem_buf()
|
2125 |
+
if type == FILETYPE_PEM:
|
2126 |
+
write_bio = _lib.PEM_write_bio_PUBKEY
|
2127 |
+
elif type == FILETYPE_ASN1:
|
2128 |
+
write_bio = _lib.i2d_PUBKEY_bio
|
2129 |
+
else:
|
2130 |
+
raise ValueError("type argument must be FILETYPE_PEM or FILETYPE_ASN1")
|
2131 |
+
|
2132 |
+
result_code = write_bio(bio, pkey._pkey)
|
2133 |
+
if result_code != 1: # pragma: no cover
|
2134 |
+
_raise_current_error()
|
2135 |
+
|
2136 |
+
return _bio_to_string(bio)
|
2137 |
+
|
2138 |
+
|
2139 |
+
def dump_privatekey(
|
2140 |
+
type: int,
|
2141 |
+
pkey: PKey,
|
2142 |
+
cipher: str | None = None,
|
2143 |
+
passphrase: PassphraseCallableT | None = None,
|
2144 |
+
) -> bytes:
|
2145 |
+
"""
|
2146 |
+
Dump the private key *pkey* into a buffer string encoded with the type
|
2147 |
+
*type*. Optionally (if *type* is :const:`FILETYPE_PEM`) encrypting it
|
2148 |
+
using *cipher* and *passphrase*.
|
2149 |
+
|
2150 |
+
:param type: The file type (one of :const:`FILETYPE_PEM`,
|
2151 |
+
:const:`FILETYPE_ASN1`, or :const:`FILETYPE_TEXT`)
|
2152 |
+
:param PKey pkey: The PKey to dump
|
2153 |
+
:param cipher: (optional) if encrypted PEM format, the cipher to use
|
2154 |
+
:param passphrase: (optional) if encrypted PEM format, this can be either
|
2155 |
+
the passphrase to use, or a callback for providing the passphrase.
|
2156 |
+
|
2157 |
+
:return: The buffer with the dumped key in
|
2158 |
+
:rtype: bytes
|
2159 |
+
"""
|
2160 |
+
bio = _new_mem_buf()
|
2161 |
+
|
2162 |
+
if not isinstance(pkey, PKey):
|
2163 |
+
raise TypeError("pkey must be a PKey")
|
2164 |
+
|
2165 |
+
if cipher is not None:
|
2166 |
+
if passphrase is None:
|
2167 |
+
raise TypeError(
|
2168 |
+
"if a value is given for cipher "
|
2169 |
+
"one must also be given for passphrase"
|
2170 |
+
)
|
2171 |
+
cipher_obj = _lib.EVP_get_cipherbyname(_byte_string(cipher))
|
2172 |
+
if cipher_obj == _ffi.NULL:
|
2173 |
+
raise ValueError("Invalid cipher name")
|
2174 |
+
else:
|
2175 |
+
cipher_obj = _ffi.NULL
|
2176 |
+
|
2177 |
+
helper = _PassphraseHelper(type, passphrase)
|
2178 |
+
if type == FILETYPE_PEM:
|
2179 |
+
result_code = _lib.PEM_write_bio_PrivateKey(
|
2180 |
+
bio,
|
2181 |
+
pkey._pkey,
|
2182 |
+
cipher_obj,
|
2183 |
+
_ffi.NULL,
|
2184 |
+
0,
|
2185 |
+
helper.callback,
|
2186 |
+
helper.callback_args,
|
2187 |
+
)
|
2188 |
+
helper.raise_if_problem()
|
2189 |
+
elif type == FILETYPE_ASN1:
|
2190 |
+
result_code = _lib.i2d_PrivateKey_bio(bio, pkey._pkey)
|
2191 |
+
elif type == FILETYPE_TEXT:
|
2192 |
+
if _lib.EVP_PKEY_id(pkey._pkey) != _lib.EVP_PKEY_RSA:
|
2193 |
+
raise TypeError("Only RSA keys are supported for FILETYPE_TEXT")
|
2194 |
+
|
2195 |
+
rsa = _ffi.gc(_lib.EVP_PKEY_get1_RSA(pkey._pkey), _lib.RSA_free)
|
2196 |
+
result_code = _lib.RSA_print(bio, rsa, 0)
|
2197 |
+
else:
|
2198 |
+
raise ValueError(
|
2199 |
+
"type argument must be FILETYPE_PEM, FILETYPE_ASN1, or "
|
2200 |
+
"FILETYPE_TEXT"
|
2201 |
+
)
|
2202 |
+
|
2203 |
+
_openssl_assert(result_code != 0)
|
2204 |
+
|
2205 |
+
return _bio_to_string(bio)
|
2206 |
+
|
2207 |
+
|
2208 |
+
class _PassphraseHelper:
|
2209 |
+
def __init__(
|
2210 |
+
self,
|
2211 |
+
type: int,
|
2212 |
+
passphrase: PassphraseCallableT | None,
|
2213 |
+
more_args: bool = False,
|
2214 |
+
truncate: bool = False,
|
2215 |
+
) -> None:
|
2216 |
+
if type != FILETYPE_PEM and passphrase is not None:
|
2217 |
+
raise ValueError(
|
2218 |
+
"only FILETYPE_PEM key format supports encryption"
|
2219 |
+
)
|
2220 |
+
self._passphrase = passphrase
|
2221 |
+
self._more_args = more_args
|
2222 |
+
self._truncate = truncate
|
2223 |
+
self._problems: list[Exception] = []
|
2224 |
+
|
2225 |
+
@property
|
2226 |
+
def callback(self) -> Any:
|
2227 |
+
if self._passphrase is None:
|
2228 |
+
return _ffi.NULL
|
2229 |
+
elif isinstance(self._passphrase, bytes) or callable(self._passphrase):
|
2230 |
+
return _ffi.callback("pem_password_cb", self._read_passphrase)
|
2231 |
+
else:
|
2232 |
+
raise TypeError(
|
2233 |
+
"Last argument must be a byte string or a callable."
|
2234 |
+
)
|
2235 |
+
|
2236 |
+
@property
|
2237 |
+
def callback_args(self) -> Any:
|
2238 |
+
if self._passphrase is None:
|
2239 |
+
return _ffi.NULL
|
2240 |
+
elif isinstance(self._passphrase, bytes) or callable(self._passphrase):
|
2241 |
+
return _ffi.NULL
|
2242 |
+
else:
|
2243 |
+
raise TypeError(
|
2244 |
+
"Last argument must be a byte string or a callable."
|
2245 |
+
)
|
2246 |
+
|
2247 |
+
def raise_if_problem(self, exceptionType: type[Exception] = Error) -> None:
|
2248 |
+
if self._problems:
|
2249 |
+
# Flush the OpenSSL error queue
|
2250 |
+
try:
|
2251 |
+
_exception_from_error_queue(exceptionType)
|
2252 |
+
except exceptionType:
|
2253 |
+
pass
|
2254 |
+
|
2255 |
+
raise self._problems.pop(0)
|
2256 |
+
|
2257 |
+
def _read_passphrase(
|
2258 |
+
self, buf: Any, size: int, rwflag: Any, userdata: Any
|
2259 |
+
) -> int:
|
2260 |
+
try:
|
2261 |
+
if callable(self._passphrase):
|
2262 |
+
if self._more_args:
|
2263 |
+
result = self._passphrase(size, rwflag, userdata)
|
2264 |
+
else:
|
2265 |
+
result = self._passphrase(rwflag)
|
2266 |
+
else:
|
2267 |
+
assert self._passphrase is not None
|
2268 |
+
result = self._passphrase
|
2269 |
+
if not isinstance(result, bytes):
|
2270 |
+
raise ValueError("Bytes expected")
|
2271 |
+
if len(result) > size:
|
2272 |
+
if self._truncate:
|
2273 |
+
result = result[:size]
|
2274 |
+
else:
|
2275 |
+
raise ValueError(
|
2276 |
+
"passphrase returned by callback is too long"
|
2277 |
+
)
|
2278 |
+
for i in range(len(result)):
|
2279 |
+
buf[i] = result[i : i + 1]
|
2280 |
+
return len(result)
|
2281 |
+
except Exception as e:
|
2282 |
+
self._problems.append(e)
|
2283 |
+
return 0
|
2284 |
+
|
2285 |
+
|
2286 |
+
def load_publickey(type: int, buffer: str | bytes) -> PKey:
|
2287 |
+
"""
|
2288 |
+
Load a public key from a buffer.
|
2289 |
+
|
2290 |
+
:param type: The file type (one of :data:`FILETYPE_PEM`,
|
2291 |
+
:data:`FILETYPE_ASN1`).
|
2292 |
+
:param buffer: The buffer the key is stored in.
|
2293 |
+
:type buffer: A Python string object, either unicode or bytestring.
|
2294 |
+
:return: The PKey object.
|
2295 |
+
:rtype: :class:`PKey`
|
2296 |
+
"""
|
2297 |
+
if isinstance(buffer, str):
|
2298 |
+
buffer = buffer.encode("ascii")
|
2299 |
+
|
2300 |
+
bio = _new_mem_buf(buffer)
|
2301 |
+
|
2302 |
+
if type == FILETYPE_PEM:
|
2303 |
+
evp_pkey = _lib.PEM_read_bio_PUBKEY(
|
2304 |
+
bio, _ffi.NULL, _ffi.NULL, _ffi.NULL
|
2305 |
+
)
|
2306 |
+
elif type == FILETYPE_ASN1:
|
2307 |
+
evp_pkey = _lib.d2i_PUBKEY_bio(bio, _ffi.NULL)
|
2308 |
+
else:
|
2309 |
+
raise ValueError("type argument must be FILETYPE_PEM or FILETYPE_ASN1")
|
2310 |
+
|
2311 |
+
if evp_pkey == _ffi.NULL:
|
2312 |
+
_raise_current_error()
|
2313 |
+
|
2314 |
+
pkey = PKey.__new__(PKey)
|
2315 |
+
pkey._pkey = _ffi.gc(evp_pkey, _lib.EVP_PKEY_free)
|
2316 |
+
pkey._only_public = True
|
2317 |
+
return pkey
|
2318 |
+
|
2319 |
+
|
2320 |
+
def load_privatekey(
|
2321 |
+
type: int,
|
2322 |
+
buffer: str | bytes,
|
2323 |
+
passphrase: PassphraseCallableT | None = None,
|
2324 |
+
) -> PKey:
|
2325 |
+
"""
|
2326 |
+
Load a private key (PKey) from the string *buffer* encoded with the type
|
2327 |
+
*type*.
|
2328 |
+
|
2329 |
+
:param type: The file type (one of FILETYPE_PEM, FILETYPE_ASN1)
|
2330 |
+
:param buffer: The buffer the key is stored in
|
2331 |
+
:param passphrase: (optional) if encrypted PEM format, this can be
|
2332 |
+
either the passphrase to use, or a callback for
|
2333 |
+
providing the passphrase.
|
2334 |
+
|
2335 |
+
:return: The PKey object
|
2336 |
+
"""
|
2337 |
+
if isinstance(buffer, str):
|
2338 |
+
buffer = buffer.encode("ascii")
|
2339 |
+
|
2340 |
+
bio = _new_mem_buf(buffer)
|
2341 |
+
|
2342 |
+
helper = _PassphraseHelper(type, passphrase)
|
2343 |
+
if type == FILETYPE_PEM:
|
2344 |
+
evp_pkey = _lib.PEM_read_bio_PrivateKey(
|
2345 |
+
bio, _ffi.NULL, helper.callback, helper.callback_args
|
2346 |
+
)
|
2347 |
+
helper.raise_if_problem()
|
2348 |
+
elif type == FILETYPE_ASN1:
|
2349 |
+
evp_pkey = _lib.d2i_PrivateKey_bio(bio, _ffi.NULL)
|
2350 |
+
else:
|
2351 |
+
raise ValueError("type argument must be FILETYPE_PEM or FILETYPE_ASN1")
|
2352 |
+
|
2353 |
+
if evp_pkey == _ffi.NULL:
|
2354 |
+
_raise_current_error()
|
2355 |
+
|
2356 |
+
pkey = PKey.__new__(PKey)
|
2357 |
+
pkey._pkey = _ffi.gc(evp_pkey, _lib.EVP_PKEY_free)
|
2358 |
+
return pkey
|
2359 |
+
|
2360 |
+
|
2361 |
+
def dump_certificate_request(type: int, req: X509Req) -> bytes:
|
2362 |
+
"""
|
2363 |
+
Dump the certificate request *req* into a buffer string encoded with the
|
2364 |
+
type *type*.
|
2365 |
+
|
2366 |
+
:param type: The file type (one of FILETYPE_PEM, FILETYPE_ASN1)
|
2367 |
+
:param req: The certificate request to dump
|
2368 |
+
:return: The buffer with the dumped certificate request in
|
2369 |
+
|
2370 |
+
|
2371 |
+
.. deprecated:: 24.2.0
|
2372 |
+
Use `cryptography.x509.CertificateSigningRequest` instead.
|
2373 |
+
"""
|
2374 |
+
bio = _new_mem_buf()
|
2375 |
+
|
2376 |
+
if type == FILETYPE_PEM:
|
2377 |
+
result_code = _lib.PEM_write_bio_X509_REQ(bio, req._req)
|
2378 |
+
elif type == FILETYPE_ASN1:
|
2379 |
+
result_code = _lib.i2d_X509_REQ_bio(bio, req._req)
|
2380 |
+
elif type == FILETYPE_TEXT:
|
2381 |
+
result_code = _lib.X509_REQ_print_ex(bio, req._req, 0, 0)
|
2382 |
+
else:
|
2383 |
+
raise ValueError(
|
2384 |
+
"type argument must be FILETYPE_PEM, FILETYPE_ASN1, or "
|
2385 |
+
"FILETYPE_TEXT"
|
2386 |
+
)
|
2387 |
+
|
2388 |
+
_openssl_assert(result_code != 0)
|
2389 |
+
|
2390 |
+
return _bio_to_string(bio)
|
2391 |
+
|
2392 |
+
|
2393 |
+
_dump_certificate_request_internal = dump_certificate_request
|
2394 |
+
|
2395 |
+
utils.deprecated(
|
2396 |
+
dump_certificate_request,
|
2397 |
+
__name__,
|
2398 |
+
(
|
2399 |
+
"CSR support in pyOpenSSL is deprecated. You should use the APIs "
|
2400 |
+
"in cryptography."
|
2401 |
+
),
|
2402 |
+
DeprecationWarning,
|
2403 |
+
name="dump_certificate_request",
|
2404 |
+
)
|
2405 |
+
|
2406 |
+
|
2407 |
+
def load_certificate_request(type: int, buffer: bytes) -> X509Req:
|
2408 |
+
"""
|
2409 |
+
Load a certificate request (X509Req) from the string *buffer* encoded with
|
2410 |
+
the type *type*.
|
2411 |
+
|
2412 |
+
:param type: The file type (one of FILETYPE_PEM, FILETYPE_ASN1)
|
2413 |
+
:param buffer: The buffer the certificate request is stored in
|
2414 |
+
:return: The X509Req object
|
2415 |
+
|
2416 |
+
.. deprecated:: 24.2.0
|
2417 |
+
Use `cryptography.x509.load_der_x509_csr` or
|
2418 |
+
`cryptography.x509.load_pem_x509_csr` instead.
|
2419 |
+
"""
|
2420 |
+
if isinstance(buffer, str):
|
2421 |
+
buffer = buffer.encode("ascii")
|
2422 |
+
|
2423 |
+
bio = _new_mem_buf(buffer)
|
2424 |
+
|
2425 |
+
if type == FILETYPE_PEM:
|
2426 |
+
req = _lib.PEM_read_bio_X509_REQ(bio, _ffi.NULL, _ffi.NULL, _ffi.NULL)
|
2427 |
+
elif type == FILETYPE_ASN1:
|
2428 |
+
req = _lib.d2i_X509_REQ_bio(bio, _ffi.NULL)
|
2429 |
+
else:
|
2430 |
+
raise ValueError("type argument must be FILETYPE_PEM or FILETYPE_ASN1")
|
2431 |
+
|
2432 |
+
_openssl_assert(req != _ffi.NULL)
|
2433 |
+
|
2434 |
+
x509req = X509Req.__new__(X509Req)
|
2435 |
+
x509req._req = _ffi.gc(req, _lib.X509_REQ_free)
|
2436 |
+
return x509req
|
2437 |
+
|
2438 |
+
|
2439 |
+
_load_certificate_request_internal = load_certificate_request
|
2440 |
+
|
2441 |
+
utils.deprecated(
|
2442 |
+
load_certificate_request,
|
2443 |
+
__name__,
|
2444 |
+
(
|
2445 |
+
"CSR support in pyOpenSSL is deprecated. You should use the APIs "
|
2446 |
+
"in cryptography."
|
2447 |
+
),
|
2448 |
+
DeprecationWarning,
|
2449 |
+
name="load_certificate_request",
|
2450 |
+
)
|
env-my/Lib/site-packages/OpenSSL/debug.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import ssl
|
2 |
+
import sys
|
3 |
+
|
4 |
+
import cffi
|
5 |
+
import cryptography
|
6 |
+
|
7 |
+
import OpenSSL.SSL
|
8 |
+
|
9 |
+
from . import version
|
10 |
+
|
11 |
+
_env_info = """\
|
12 |
+
pyOpenSSL: {pyopenssl}
|
13 |
+
cryptography: {cryptography}
|
14 |
+
cffi: {cffi}
|
15 |
+
cryptography's compiled against OpenSSL: {crypto_openssl_compile}
|
16 |
+
cryptography's linked OpenSSL: {crypto_openssl_link}
|
17 |
+
Python's OpenSSL: {python_openssl}
|
18 |
+
Python executable: {python}
|
19 |
+
Python version: {python_version}
|
20 |
+
Platform: {platform}
|
21 |
+
sys.path: {sys_path}""".format(
|
22 |
+
pyopenssl=version.__version__,
|
23 |
+
crypto_openssl_compile=OpenSSL._util.ffi.string(
|
24 |
+
OpenSSL._util.lib.OPENSSL_VERSION_TEXT,
|
25 |
+
).decode("ascii"),
|
26 |
+
crypto_openssl_link=OpenSSL.SSL.SSLeay_version(
|
27 |
+
OpenSSL.SSL.SSLEAY_VERSION
|
28 |
+
).decode("ascii"),
|
29 |
+
python_openssl=getattr(ssl, "OPENSSL_VERSION", "n/a"),
|
30 |
+
cryptography=cryptography.__version__,
|
31 |
+
cffi=cffi.__version__,
|
32 |
+
python=sys.executable,
|
33 |
+
python_version=sys.version,
|
34 |
+
platform=sys.platform,
|
35 |
+
sys_path=sys.path,
|
36 |
+
)
|
37 |
+
|
38 |
+
|
39 |
+
if __name__ == "__main__":
|
40 |
+
print(_env_info)
|
env-my/Lib/site-packages/OpenSSL/py.typed
ADDED
File without changes
|
env-my/Lib/site-packages/OpenSSL/rand.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
PRNG management routines, thin wrappers.
|
3 |
+
"""
|
4 |
+
|
5 |
+
from __future__ import annotations
|
6 |
+
|
7 |
+
import warnings
|
8 |
+
|
9 |
+
from OpenSSL._util import lib as _lib
|
10 |
+
|
11 |
+
warnings.warn(
|
12 |
+
"OpenSSL.rand is deprecated - you should use os.urandom instead",
|
13 |
+
DeprecationWarning,
|
14 |
+
stacklevel=3,
|
15 |
+
)
|
16 |
+
|
17 |
+
|
18 |
+
def add(buffer: bytes, entropy: int) -> None:
|
19 |
+
"""
|
20 |
+
Mix bytes from *string* into the PRNG state.
|
21 |
+
|
22 |
+
The *entropy* argument is (the lower bound of) an estimate of how much
|
23 |
+
randomness is contained in *string*, measured in bytes.
|
24 |
+
|
25 |
+
For more information, see e.g. :rfc:`1750`.
|
26 |
+
|
27 |
+
This function is only relevant if you are forking Python processes and
|
28 |
+
need to reseed the CSPRNG after fork.
|
29 |
+
|
30 |
+
:param buffer: Buffer with random data.
|
31 |
+
:param entropy: The entropy (in bytes) measurement of the buffer.
|
32 |
+
|
33 |
+
:return: :obj:`None`
|
34 |
+
"""
|
35 |
+
if not isinstance(buffer, bytes):
|
36 |
+
raise TypeError("buffer must be a byte string")
|
37 |
+
|
38 |
+
if not isinstance(entropy, int):
|
39 |
+
raise TypeError("entropy must be an integer")
|
40 |
+
|
41 |
+
_lib.RAND_add(buffer, len(buffer), entropy)
|
42 |
+
|
43 |
+
|
44 |
+
def status() -> int:
|
45 |
+
"""
|
46 |
+
Check whether the PRNG has been seeded with enough data.
|
47 |
+
|
48 |
+
:return: 1 if the PRNG is seeded enough, 0 otherwise.
|
49 |
+
"""
|
50 |
+
return _lib.RAND_status()
|
env-my/Lib/site-packages/OpenSSL/version.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright (C) AB Strakt
|
2 |
+
# Copyright (C) Jean-Paul Calderone
|
3 |
+
# See LICENSE for details.
|
4 |
+
|
5 |
+
"""
|
6 |
+
pyOpenSSL - A simple wrapper around the OpenSSL library
|
7 |
+
"""
|
8 |
+
|
9 |
+
__all__ = [
|
10 |
+
"__author__",
|
11 |
+
"__copyright__",
|
12 |
+
"__email__",
|
13 |
+
"__license__",
|
14 |
+
"__summary__",
|
15 |
+
"__title__",
|
16 |
+
"__uri__",
|
17 |
+
"__version__",
|
18 |
+
]
|
19 |
+
|
20 |
+
__version__ = "25.0.0"
|
21 |
+
|
22 |
+
__title__ = "pyOpenSSL"
|
23 |
+
__uri__ = "https://pyopenssl.org/"
|
24 |
+
__summary__ = "Python wrapper module around the OpenSSL library"
|
25 |
+
__author__ = "The pyOpenSSL developers"
|
26 |
+
__email__ = "[email protected]"
|
27 |
+
__license__ = "Apache License, Version 2.0"
|
28 |
+
__copyright__ = f"Copyright 2001-2025 {__author__}"
|
env-my/Lib/site-packages/PIL/BdfFontFile.py
ADDED
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#
|
2 |
+
# The Python Imaging Library
|
3 |
+
# $Id$
|
4 |
+
#
|
5 |
+
# bitmap distribution font (bdf) file parser
|
6 |
+
#
|
7 |
+
# history:
|
8 |
+
# 1996-05-16 fl created (as bdf2pil)
|
9 |
+
# 1997-08-25 fl converted to FontFile driver
|
10 |
+
# 2001-05-25 fl removed bogus __init__ call
|
11 |
+
# 2002-11-20 fl robustification (from Kevin Cazabon, Dmitry Vasiliev)
|
12 |
+
# 2003-04-22 fl more robustification (from Graham Dumpleton)
|
13 |
+
#
|
14 |
+
# Copyright (c) 1997-2003 by Secret Labs AB.
|
15 |
+
# Copyright (c) 1997-2003 by Fredrik Lundh.
|
16 |
+
#
|
17 |
+
# See the README file for information on usage and redistribution.
|
18 |
+
#
|
19 |
+
|
20 |
+
"""
|
21 |
+
Parse X Bitmap Distribution Format (BDF)
|
22 |
+
"""
|
23 |
+
from __future__ import annotations
|
24 |
+
|
25 |
+
from typing import BinaryIO
|
26 |
+
|
27 |
+
from . import FontFile, Image
|
28 |
+
|
29 |
+
bdf_slant = {
|
30 |
+
"R": "Roman",
|
31 |
+
"I": "Italic",
|
32 |
+
"O": "Oblique",
|
33 |
+
"RI": "Reverse Italic",
|
34 |
+
"RO": "Reverse Oblique",
|
35 |
+
"OT": "Other",
|
36 |
+
}
|
37 |
+
|
38 |
+
bdf_spacing = {"P": "Proportional", "M": "Monospaced", "C": "Cell"}
|
39 |
+
|
40 |
+
|
41 |
+
def bdf_char(
|
42 |
+
f: BinaryIO,
|
43 |
+
) -> (
|
44 |
+
tuple[
|
45 |
+
str,
|
46 |
+
int,
|
47 |
+
tuple[tuple[int, int], tuple[int, int, int, int], tuple[int, int, int, int]],
|
48 |
+
Image.Image,
|
49 |
+
]
|
50 |
+
| None
|
51 |
+
):
|
52 |
+
# skip to STARTCHAR
|
53 |
+
while True:
|
54 |
+
s = f.readline()
|
55 |
+
if not s:
|
56 |
+
return None
|
57 |
+
if s[:9] == b"STARTCHAR":
|
58 |
+
break
|
59 |
+
id = s[9:].strip().decode("ascii")
|
60 |
+
|
61 |
+
# load symbol properties
|
62 |
+
props = {}
|
63 |
+
while True:
|
64 |
+
s = f.readline()
|
65 |
+
if not s or s[:6] == b"BITMAP":
|
66 |
+
break
|
67 |
+
i = s.find(b" ")
|
68 |
+
props[s[:i].decode("ascii")] = s[i + 1 : -1].decode("ascii")
|
69 |
+
|
70 |
+
# load bitmap
|
71 |
+
bitmap = bytearray()
|
72 |
+
while True:
|
73 |
+
s = f.readline()
|
74 |
+
if not s or s[:7] == b"ENDCHAR":
|
75 |
+
break
|
76 |
+
bitmap += s[:-1]
|
77 |
+
|
78 |
+
# The word BBX
|
79 |
+
# followed by the width in x (BBw), height in y (BBh),
|
80 |
+
# and x and y displacement (BBxoff0, BByoff0)
|
81 |
+
# of the lower left corner from the origin of the character.
|
82 |
+
width, height, x_disp, y_disp = (int(p) for p in props["BBX"].split())
|
83 |
+
|
84 |
+
# The word DWIDTH
|
85 |
+
# followed by the width in x and y of the character in device pixels.
|
86 |
+
dwx, dwy = (int(p) for p in props["DWIDTH"].split())
|
87 |
+
|
88 |
+
bbox = (
|
89 |
+
(dwx, dwy),
|
90 |
+
(x_disp, -y_disp - height, width + x_disp, -y_disp),
|
91 |
+
(0, 0, width, height),
|
92 |
+
)
|
93 |
+
|
94 |
+
try:
|
95 |
+
im = Image.frombytes("1", (width, height), bitmap, "hex", "1")
|
96 |
+
except ValueError:
|
97 |
+
# deal with zero-width characters
|
98 |
+
im = Image.new("1", (width, height))
|
99 |
+
|
100 |
+
return id, int(props["ENCODING"]), bbox, im
|
101 |
+
|
102 |
+
|
103 |
+
class BdfFontFile(FontFile.FontFile):
|
104 |
+
"""Font file plugin for the X11 BDF format."""
|
105 |
+
|
106 |
+
def __init__(self, fp: BinaryIO) -> None:
|
107 |
+
super().__init__()
|
108 |
+
|
109 |
+
s = fp.readline()
|
110 |
+
if s[:13] != b"STARTFONT 2.1":
|
111 |
+
msg = "not a valid BDF file"
|
112 |
+
raise SyntaxError(msg)
|
113 |
+
|
114 |
+
props = {}
|
115 |
+
comments = []
|
116 |
+
|
117 |
+
while True:
|
118 |
+
s = fp.readline()
|
119 |
+
if not s or s[:13] == b"ENDPROPERTIES":
|
120 |
+
break
|
121 |
+
i = s.find(b" ")
|
122 |
+
props[s[:i].decode("ascii")] = s[i + 1 : -1].decode("ascii")
|
123 |
+
if s[:i] in [b"COMMENT", b"COPYRIGHT"]:
|
124 |
+
if s.find(b"LogicalFontDescription") < 0:
|
125 |
+
comments.append(s[i + 1 : -1].decode("ascii"))
|
126 |
+
|
127 |
+
while True:
|
128 |
+
c = bdf_char(fp)
|
129 |
+
if not c:
|
130 |
+
break
|
131 |
+
id, ch, (xy, dst, src), im = c
|
132 |
+
if 0 <= ch < len(self.glyph):
|
133 |
+
self.glyph[ch] = xy, dst, src, im
|
env-my/Lib/site-packages/PIL/BlpImagePlugin.py
ADDED
@@ -0,0 +1,501 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
Blizzard Mipmap Format (.blp)
|
3 |
+
Jerome Leclanche <[email protected]>
|
4 |
+
|
5 |
+
The contents of this file are hereby released in the public domain (CC0)
|
6 |
+
Full text of the CC0 license:
|
7 |
+
https://creativecommons.org/publicdomain/zero/1.0/
|
8 |
+
|
9 |
+
BLP1 files, used mostly in Warcraft III, are not fully supported.
|
10 |
+
All types of BLP2 files used in World of Warcraft are supported.
|
11 |
+
|
12 |
+
The BLP file structure consists of a header, up to 16 mipmaps of the
|
13 |
+
texture
|
14 |
+
|
15 |
+
Texture sizes must be powers of two, though the two dimensions do
|
16 |
+
not have to be equal; 512x256 is valid, but 512x200 is not.
|
17 |
+
The first mipmap (mipmap #0) is the full size image; each subsequent
|
18 |
+
mipmap halves both dimensions. The final mipmap should be 1x1.
|
19 |
+
|
20 |
+
BLP files come in many different flavours:
|
21 |
+
* JPEG-compressed (type == 0) - only supported for BLP1.
|
22 |
+
* RAW images (type == 1, encoding == 1). Each mipmap is stored as an
|
23 |
+
array of 8-bit values, one per pixel, left to right, top to bottom.
|
24 |
+
Each value is an index to the palette.
|
25 |
+
* DXT-compressed (type == 1, encoding == 2):
|
26 |
+
- DXT1 compression is used if alpha_encoding == 0.
|
27 |
+
- An additional alpha bit is used if alpha_depth == 1.
|
28 |
+
- DXT3 compression is used if alpha_encoding == 1.
|
29 |
+
- DXT5 compression is used if alpha_encoding == 7.
|
30 |
+
"""
|
31 |
+
|
32 |
+
from __future__ import annotations
|
33 |
+
|
34 |
+
import abc
|
35 |
+
import os
|
36 |
+
import struct
|
37 |
+
from enum import IntEnum
|
38 |
+
from io import BytesIO
|
39 |
+
from typing import IO
|
40 |
+
|
41 |
+
from . import Image, ImageFile
|
42 |
+
|
43 |
+
|
44 |
+
class Format(IntEnum):
|
45 |
+
JPEG = 0
|
46 |
+
|
47 |
+
|
48 |
+
class Encoding(IntEnum):
|
49 |
+
UNCOMPRESSED = 1
|
50 |
+
DXT = 2
|
51 |
+
UNCOMPRESSED_RAW_BGRA = 3
|
52 |
+
|
53 |
+
|
54 |
+
class AlphaEncoding(IntEnum):
|
55 |
+
DXT1 = 0
|
56 |
+
DXT3 = 1
|
57 |
+
DXT5 = 7
|
58 |
+
|
59 |
+
|
60 |
+
def unpack_565(i: int) -> tuple[int, int, int]:
|
61 |
+
return ((i >> 11) & 0x1F) << 3, ((i >> 5) & 0x3F) << 2, (i & 0x1F) << 3
|
62 |
+
|
63 |
+
|
64 |
+
def decode_dxt1(
|
65 |
+
data: bytes, alpha: bool = False
|
66 |
+
) -> tuple[bytearray, bytearray, bytearray, bytearray]:
|
67 |
+
"""
|
68 |
+
input: one "row" of data (i.e. will produce 4*width pixels)
|
69 |
+
"""
|
70 |
+
|
71 |
+
blocks = len(data) // 8 # number of blocks in row
|
72 |
+
ret = (bytearray(), bytearray(), bytearray(), bytearray())
|
73 |
+
|
74 |
+
for block_index in range(blocks):
|
75 |
+
# Decode next 8-byte block.
|
76 |
+
idx = block_index * 8
|
77 |
+
color0, color1, bits = struct.unpack_from("<HHI", data, idx)
|
78 |
+
|
79 |
+
r0, g0, b0 = unpack_565(color0)
|
80 |
+
r1, g1, b1 = unpack_565(color1)
|
81 |
+
|
82 |
+
# Decode this block into 4x4 pixels
|
83 |
+
# Accumulate the results onto our 4 row accumulators
|
84 |
+
for j in range(4):
|
85 |
+
for i in range(4):
|
86 |
+
# get next control op and generate a pixel
|
87 |
+
|
88 |
+
control = bits & 3
|
89 |
+
bits = bits >> 2
|
90 |
+
|
91 |
+
a = 0xFF
|
92 |
+
if control == 0:
|
93 |
+
r, g, b = r0, g0, b0
|
94 |
+
elif control == 1:
|
95 |
+
r, g, b = r1, g1, b1
|
96 |
+
elif control == 2:
|
97 |
+
if color0 > color1:
|
98 |
+
r = (2 * r0 + r1) // 3
|
99 |
+
g = (2 * g0 + g1) // 3
|
100 |
+
b = (2 * b0 + b1) // 3
|
101 |
+
else:
|
102 |
+
r = (r0 + r1) // 2
|
103 |
+
g = (g0 + g1) // 2
|
104 |
+
b = (b0 + b1) // 2
|
105 |
+
elif control == 3:
|
106 |
+
if color0 > color1:
|
107 |
+
r = (2 * r1 + r0) // 3
|
108 |
+
g = (2 * g1 + g0) // 3
|
109 |
+
b = (2 * b1 + b0) // 3
|
110 |
+
else:
|
111 |
+
r, g, b, a = 0, 0, 0, 0
|
112 |
+
|
113 |
+
if alpha:
|
114 |
+
ret[j].extend([r, g, b, a])
|
115 |
+
else:
|
116 |
+
ret[j].extend([r, g, b])
|
117 |
+
|
118 |
+
return ret
|
119 |
+
|
120 |
+
|
121 |
+
def decode_dxt3(data: bytes) -> tuple[bytearray, bytearray, bytearray, bytearray]:
|
122 |
+
"""
|
123 |
+
input: one "row" of data (i.e. will produce 4*width pixels)
|
124 |
+
"""
|
125 |
+
|
126 |
+
blocks = len(data) // 16 # number of blocks in row
|
127 |
+
ret = (bytearray(), bytearray(), bytearray(), bytearray())
|
128 |
+
|
129 |
+
for block_index in range(blocks):
|
130 |
+
idx = block_index * 16
|
131 |
+
block = data[idx : idx + 16]
|
132 |
+
# Decode next 16-byte block.
|
133 |
+
bits = struct.unpack_from("<8B", block)
|
134 |
+
color0, color1 = struct.unpack_from("<HH", block, 8)
|
135 |
+
|
136 |
+
(code,) = struct.unpack_from("<I", block, 12)
|
137 |
+
|
138 |
+
r0, g0, b0 = unpack_565(color0)
|
139 |
+
r1, g1, b1 = unpack_565(color1)
|
140 |
+
|
141 |
+
for j in range(4):
|
142 |
+
high = False # Do we want the higher bits?
|
143 |
+
for i in range(4):
|
144 |
+
alphacode_index = (4 * j + i) // 2
|
145 |
+
a = bits[alphacode_index]
|
146 |
+
if high:
|
147 |
+
high = False
|
148 |
+
a >>= 4
|
149 |
+
else:
|
150 |
+
high = True
|
151 |
+
a &= 0xF
|
152 |
+
a *= 17 # We get a value between 0 and 15
|
153 |
+
|
154 |
+
color_code = (code >> 2 * (4 * j + i)) & 0x03
|
155 |
+
|
156 |
+
if color_code == 0:
|
157 |
+
r, g, b = r0, g0, b0
|
158 |
+
elif color_code == 1:
|
159 |
+
r, g, b = r1, g1, b1
|
160 |
+
elif color_code == 2:
|
161 |
+
r = (2 * r0 + r1) // 3
|
162 |
+
g = (2 * g0 + g1) // 3
|
163 |
+
b = (2 * b0 + b1) // 3
|
164 |
+
elif color_code == 3:
|
165 |
+
r = (2 * r1 + r0) // 3
|
166 |
+
g = (2 * g1 + g0) // 3
|
167 |
+
b = (2 * b1 + b0) // 3
|
168 |
+
|
169 |
+
ret[j].extend([r, g, b, a])
|
170 |
+
|
171 |
+
return ret
|
172 |
+
|
173 |
+
|
174 |
+
def decode_dxt5(data: bytes) -> tuple[bytearray, bytearray, bytearray, bytearray]:
|
175 |
+
"""
|
176 |
+
input: one "row" of data (i.e. will produce 4 * width pixels)
|
177 |
+
"""
|
178 |
+
|
179 |
+
blocks = len(data) // 16 # number of blocks in row
|
180 |
+
ret = (bytearray(), bytearray(), bytearray(), bytearray())
|
181 |
+
|
182 |
+
for block_index in range(blocks):
|
183 |
+
idx = block_index * 16
|
184 |
+
block = data[idx : idx + 16]
|
185 |
+
# Decode next 16-byte block.
|
186 |
+
a0, a1 = struct.unpack_from("<BB", block)
|
187 |
+
|
188 |
+
bits = struct.unpack_from("<6B", block, 2)
|
189 |
+
alphacode1 = bits[2] | (bits[3] << 8) | (bits[4] << 16) | (bits[5] << 24)
|
190 |
+
alphacode2 = bits[0] | (bits[1] << 8)
|
191 |
+
|
192 |
+
color0, color1 = struct.unpack_from("<HH", block, 8)
|
193 |
+
|
194 |
+
(code,) = struct.unpack_from("<I", block, 12)
|
195 |
+
|
196 |
+
r0, g0, b0 = unpack_565(color0)
|
197 |
+
r1, g1, b1 = unpack_565(color1)
|
198 |
+
|
199 |
+
for j in range(4):
|
200 |
+
for i in range(4):
|
201 |
+
# get next control op and generate a pixel
|
202 |
+
alphacode_index = 3 * (4 * j + i)
|
203 |
+
|
204 |
+
if alphacode_index <= 12:
|
205 |
+
alphacode = (alphacode2 >> alphacode_index) & 0x07
|
206 |
+
elif alphacode_index == 15:
|
207 |
+
alphacode = (alphacode2 >> 15) | ((alphacode1 << 1) & 0x06)
|
208 |
+
else: # alphacode_index >= 18 and alphacode_index <= 45
|
209 |
+
alphacode = (alphacode1 >> (alphacode_index - 16)) & 0x07
|
210 |
+
|
211 |
+
if alphacode == 0:
|
212 |
+
a = a0
|
213 |
+
elif alphacode == 1:
|
214 |
+
a = a1
|
215 |
+
elif a0 > a1:
|
216 |
+
a = ((8 - alphacode) * a0 + (alphacode - 1) * a1) // 7
|
217 |
+
elif alphacode == 6:
|
218 |
+
a = 0
|
219 |
+
elif alphacode == 7:
|
220 |
+
a = 255
|
221 |
+
else:
|
222 |
+
a = ((6 - alphacode) * a0 + (alphacode - 1) * a1) // 5
|
223 |
+
|
224 |
+
color_code = (code >> 2 * (4 * j + i)) & 0x03
|
225 |
+
|
226 |
+
if color_code == 0:
|
227 |
+
r, g, b = r0, g0, b0
|
228 |
+
elif color_code == 1:
|
229 |
+
r, g, b = r1, g1, b1
|
230 |
+
elif color_code == 2:
|
231 |
+
r = (2 * r0 + r1) // 3
|
232 |
+
g = (2 * g0 + g1) // 3
|
233 |
+
b = (2 * b0 + b1) // 3
|
234 |
+
elif color_code == 3:
|
235 |
+
r = (2 * r1 + r0) // 3
|
236 |
+
g = (2 * g1 + g0) // 3
|
237 |
+
b = (2 * b1 + b0) // 3
|
238 |
+
|
239 |
+
ret[j].extend([r, g, b, a])
|
240 |
+
|
241 |
+
return ret
|
242 |
+
|
243 |
+
|
244 |
+
class BLPFormatError(NotImplementedError):
|
245 |
+
pass
|
246 |
+
|
247 |
+
|
248 |
+
def _accept(prefix: bytes) -> bool:
|
249 |
+
return prefix[:4] in (b"BLP1", b"BLP2")
|
250 |
+
|
251 |
+
|
252 |
+
class BlpImageFile(ImageFile.ImageFile):
|
253 |
+
"""
|
254 |
+
Blizzard Mipmap Format
|
255 |
+
"""
|
256 |
+
|
257 |
+
format = "BLP"
|
258 |
+
format_description = "Blizzard Mipmap Format"
|
259 |
+
|
260 |
+
def _open(self) -> None:
|
261 |
+
self.magic = self.fp.read(4)
|
262 |
+
if not _accept(self.magic):
|
263 |
+
msg = f"Bad BLP magic {repr(self.magic)}"
|
264 |
+
raise BLPFormatError(msg)
|
265 |
+
|
266 |
+
compression = struct.unpack("<i", self.fp.read(4))[0]
|
267 |
+
if self.magic == b"BLP1":
|
268 |
+
alpha = struct.unpack("<I", self.fp.read(4))[0] != 0
|
269 |
+
else:
|
270 |
+
encoding = struct.unpack("<b", self.fp.read(1))[0]
|
271 |
+
alpha = struct.unpack("<b", self.fp.read(1))[0] != 0
|
272 |
+
alpha_encoding = struct.unpack("<b", self.fp.read(1))[0]
|
273 |
+
self.fp.seek(1, os.SEEK_CUR) # mips
|
274 |
+
|
275 |
+
self._size = struct.unpack("<II", self.fp.read(8))
|
276 |
+
|
277 |
+
args: tuple[int, int, bool] | tuple[int, int, bool, int]
|
278 |
+
if self.magic == b"BLP1":
|
279 |
+
encoding = struct.unpack("<i", self.fp.read(4))[0]
|
280 |
+
self.fp.seek(4, os.SEEK_CUR) # subtype
|
281 |
+
|
282 |
+
args = (compression, encoding, alpha)
|
283 |
+
offset = 28
|
284 |
+
else:
|
285 |
+
args = (compression, encoding, alpha, alpha_encoding)
|
286 |
+
offset = 20
|
287 |
+
|
288 |
+
decoder = self.magic.decode()
|
289 |
+
|
290 |
+
self._mode = "RGBA" if alpha else "RGB"
|
291 |
+
self.tile = [ImageFile._Tile(decoder, (0, 0) + self.size, offset, args)]
|
292 |
+
|
293 |
+
|
294 |
+
class _BLPBaseDecoder(ImageFile.PyDecoder):
|
295 |
+
_pulls_fd = True
|
296 |
+
|
297 |
+
def decode(self, buffer: bytes | Image.SupportsArrayInterface) -> tuple[int, int]:
|
298 |
+
try:
|
299 |
+
self._read_header()
|
300 |
+
self._load()
|
301 |
+
except struct.error as e:
|
302 |
+
msg = "Truncated BLP file"
|
303 |
+
raise OSError(msg) from e
|
304 |
+
return -1, 0
|
305 |
+
|
306 |
+
@abc.abstractmethod
|
307 |
+
def _load(self) -> None:
|
308 |
+
pass
|
309 |
+
|
310 |
+
def _read_header(self) -> None:
|
311 |
+
self._offsets = struct.unpack("<16I", self._safe_read(16 * 4))
|
312 |
+
self._lengths = struct.unpack("<16I", self._safe_read(16 * 4))
|
313 |
+
|
314 |
+
def _safe_read(self, length: int) -> bytes:
|
315 |
+
assert self.fd is not None
|
316 |
+
return ImageFile._safe_read(self.fd, length)
|
317 |
+
|
318 |
+
def _read_palette(self) -> list[tuple[int, int, int, int]]:
|
319 |
+
ret = []
|
320 |
+
for i in range(256):
|
321 |
+
try:
|
322 |
+
b, g, r, a = struct.unpack("<4B", self._safe_read(4))
|
323 |
+
except struct.error:
|
324 |
+
break
|
325 |
+
ret.append((b, g, r, a))
|
326 |
+
return ret
|
327 |
+
|
328 |
+
def _read_bgra(
|
329 |
+
self, palette: list[tuple[int, int, int, int]], alpha: bool
|
330 |
+
) -> bytearray:
|
331 |
+
data = bytearray()
|
332 |
+
_data = BytesIO(self._safe_read(self._lengths[0]))
|
333 |
+
while True:
|
334 |
+
try:
|
335 |
+
(offset,) = struct.unpack("<B", _data.read(1))
|
336 |
+
except struct.error:
|
337 |
+
break
|
338 |
+
b, g, r, a = palette[offset]
|
339 |
+
d: tuple[int, ...] = (r, g, b)
|
340 |
+
if alpha:
|
341 |
+
d += (a,)
|
342 |
+
data.extend(d)
|
343 |
+
return data
|
344 |
+
|
345 |
+
|
346 |
+
class BLP1Decoder(_BLPBaseDecoder):
|
347 |
+
def _load(self) -> None:
|
348 |
+
self._compression, self._encoding, alpha = self.args
|
349 |
+
|
350 |
+
if self._compression == Format.JPEG:
|
351 |
+
self._decode_jpeg_stream()
|
352 |
+
|
353 |
+
elif self._compression == 1:
|
354 |
+
if self._encoding in (4, 5):
|
355 |
+
palette = self._read_palette()
|
356 |
+
data = self._read_bgra(palette, alpha)
|
357 |
+
self.set_as_raw(data)
|
358 |
+
else:
|
359 |
+
msg = f"Unsupported BLP encoding {repr(self._encoding)}"
|
360 |
+
raise BLPFormatError(msg)
|
361 |
+
else:
|
362 |
+
msg = f"Unsupported BLP compression {repr(self._encoding)}"
|
363 |
+
raise BLPFormatError(msg)
|
364 |
+
|
365 |
+
def _decode_jpeg_stream(self) -> None:
|
366 |
+
from .JpegImagePlugin import JpegImageFile
|
367 |
+
|
368 |
+
(jpeg_header_size,) = struct.unpack("<I", self._safe_read(4))
|
369 |
+
jpeg_header = self._safe_read(jpeg_header_size)
|
370 |
+
assert self.fd is not None
|
371 |
+
self._safe_read(self._offsets[0] - self.fd.tell()) # What IS this?
|
372 |
+
data = self._safe_read(self._lengths[0])
|
373 |
+
data = jpeg_header + data
|
374 |
+
image = JpegImageFile(BytesIO(data))
|
375 |
+
Image._decompression_bomb_check(image.size)
|
376 |
+
if image.mode == "CMYK":
|
377 |
+
decoder_name, extents, offset, args = image.tile[0]
|
378 |
+
assert isinstance(args, tuple)
|
379 |
+
image.tile = [
|
380 |
+
ImageFile._Tile(decoder_name, extents, offset, (args[0], "CMYK"))
|
381 |
+
]
|
382 |
+
r, g, b = image.convert("RGB").split()
|
383 |
+
reversed_image = Image.merge("RGB", (b, g, r))
|
384 |
+
self.set_as_raw(reversed_image.tobytes())
|
385 |
+
|
386 |
+
|
387 |
+
class BLP2Decoder(_BLPBaseDecoder):
|
388 |
+
def _load(self) -> None:
|
389 |
+
self._compression, self._encoding, alpha, self._alpha_encoding = self.args
|
390 |
+
|
391 |
+
palette = self._read_palette()
|
392 |
+
|
393 |
+
assert self.fd is not None
|
394 |
+
self.fd.seek(self._offsets[0])
|
395 |
+
|
396 |
+
if self._compression == 1:
|
397 |
+
# Uncompressed or DirectX compression
|
398 |
+
|
399 |
+
if self._encoding == Encoding.UNCOMPRESSED:
|
400 |
+
data = self._read_bgra(palette, alpha)
|
401 |
+
|
402 |
+
elif self._encoding == Encoding.DXT:
|
403 |
+
data = bytearray()
|
404 |
+
if self._alpha_encoding == AlphaEncoding.DXT1:
|
405 |
+
linesize = (self.state.xsize + 3) // 4 * 8
|
406 |
+
for yb in range((self.state.ysize + 3) // 4):
|
407 |
+
for d in decode_dxt1(self._safe_read(linesize), alpha):
|
408 |
+
data += d
|
409 |
+
|
410 |
+
elif self._alpha_encoding == AlphaEncoding.DXT3:
|
411 |
+
linesize = (self.state.xsize + 3) // 4 * 16
|
412 |
+
for yb in range((self.state.ysize + 3) // 4):
|
413 |
+
for d in decode_dxt3(self._safe_read(linesize)):
|
414 |
+
data += d
|
415 |
+
|
416 |
+
elif self._alpha_encoding == AlphaEncoding.DXT5:
|
417 |
+
linesize = (self.state.xsize + 3) // 4 * 16
|
418 |
+
for yb in range((self.state.ysize + 3) // 4):
|
419 |
+
for d in decode_dxt5(self._safe_read(linesize)):
|
420 |
+
data += d
|
421 |
+
else:
|
422 |
+
msg = f"Unsupported alpha encoding {repr(self._alpha_encoding)}"
|
423 |
+
raise BLPFormatError(msg)
|
424 |
+
else:
|
425 |
+
msg = f"Unknown BLP encoding {repr(self._encoding)}"
|
426 |
+
raise BLPFormatError(msg)
|
427 |
+
|
428 |
+
else:
|
429 |
+
msg = f"Unknown BLP compression {repr(self._compression)}"
|
430 |
+
raise BLPFormatError(msg)
|
431 |
+
|
432 |
+
self.set_as_raw(data)
|
433 |
+
|
434 |
+
|
435 |
+
class BLPEncoder(ImageFile.PyEncoder):
|
436 |
+
_pushes_fd = True
|
437 |
+
|
438 |
+
def _write_palette(self) -> bytes:
|
439 |
+
data = b""
|
440 |
+
assert self.im is not None
|
441 |
+
palette = self.im.getpalette("RGBA", "RGBA")
|
442 |
+
for i in range(len(palette) // 4):
|
443 |
+
r, g, b, a = palette[i * 4 : (i + 1) * 4]
|
444 |
+
data += struct.pack("<4B", b, g, r, a)
|
445 |
+
while len(data) < 256 * 4:
|
446 |
+
data += b"\x00" * 4
|
447 |
+
return data
|
448 |
+
|
449 |
+
def encode(self, bufsize: int) -> tuple[int, int, bytes]:
|
450 |
+
palette_data = self._write_palette()
|
451 |
+
|
452 |
+
offset = 20 + 16 * 4 * 2 + len(palette_data)
|
453 |
+
data = struct.pack("<16I", offset, *((0,) * 15))
|
454 |
+
|
455 |
+
assert self.im is not None
|
456 |
+
w, h = self.im.size
|
457 |
+
data += struct.pack("<16I", w * h, *((0,) * 15))
|
458 |
+
|
459 |
+
data += palette_data
|
460 |
+
|
461 |
+
for y in range(h):
|
462 |
+
for x in range(w):
|
463 |
+
data += struct.pack("<B", self.im.getpixel((x, y)))
|
464 |
+
|
465 |
+
return len(data), 0, data
|
466 |
+
|
467 |
+
|
468 |
+
def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
|
469 |
+
if im.mode != "P":
|
470 |
+
msg = "Unsupported BLP image mode"
|
471 |
+
raise ValueError(msg)
|
472 |
+
|
473 |
+
magic = b"BLP1" if im.encoderinfo.get("blp_version") == "BLP1" else b"BLP2"
|
474 |
+
fp.write(magic)
|
475 |
+
|
476 |
+
assert im.palette is not None
|
477 |
+
fp.write(struct.pack("<i", 1)) # Uncompressed or DirectX compression
|
478 |
+
|
479 |
+
alpha_depth = 1 if im.palette.mode == "RGBA" else 0
|
480 |
+
if magic == b"BLP1":
|
481 |
+
fp.write(struct.pack("<L", alpha_depth))
|
482 |
+
else:
|
483 |
+
fp.write(struct.pack("<b", Encoding.UNCOMPRESSED))
|
484 |
+
fp.write(struct.pack("<b", alpha_depth))
|
485 |
+
fp.write(struct.pack("<b", 0)) # alpha encoding
|
486 |
+
fp.write(struct.pack("<b", 0)) # mips
|
487 |
+
fp.write(struct.pack("<II", *im.size))
|
488 |
+
if magic == b"BLP1":
|
489 |
+
fp.write(struct.pack("<i", 5))
|
490 |
+
fp.write(struct.pack("<i", 0))
|
491 |
+
|
492 |
+
ImageFile._save(im, fp, [ImageFile._Tile("BLP", (0, 0) + im.size, 0, im.mode)])
|
493 |
+
|
494 |
+
|
495 |
+
Image.register_open(BlpImageFile.format, BlpImageFile, _accept)
|
496 |
+
Image.register_extension(BlpImageFile.format, ".blp")
|
497 |
+
Image.register_decoder("BLP1", BLP1Decoder)
|
498 |
+
Image.register_decoder("BLP2", BLP2Decoder)
|
499 |
+
|
500 |
+
Image.register_save(BlpImageFile.format, _save)
|
501 |
+
Image.register_encoder("BLP", BLPEncoder)
|
env-my/Lib/site-packages/PIL/BmpImagePlugin.py
ADDED
@@ -0,0 +1,511 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#
|
2 |
+
# The Python Imaging Library.
|
3 |
+
# $Id$
|
4 |
+
#
|
5 |
+
# BMP file handler
|
6 |
+
#
|
7 |
+
# Windows (and OS/2) native bitmap storage format.
|
8 |
+
#
|
9 |
+
# history:
|
10 |
+
# 1995-09-01 fl Created
|
11 |
+
# 1996-04-30 fl Added save
|
12 |
+
# 1997-08-27 fl Fixed save of 1-bit images
|
13 |
+
# 1998-03-06 fl Load P images as L where possible
|
14 |
+
# 1998-07-03 fl Load P images as 1 where possible
|
15 |
+
# 1998-12-29 fl Handle small palettes
|
16 |
+
# 2002-12-30 fl Fixed load of 1-bit palette images
|
17 |
+
# 2003-04-21 fl Fixed load of 1-bit monochrome images
|
18 |
+
# 2003-04-23 fl Added limited support for BI_BITFIELDS compression
|
19 |
+
#
|
20 |
+
# Copyright (c) 1997-2003 by Secret Labs AB
|
21 |
+
# Copyright (c) 1995-2003 by Fredrik Lundh
|
22 |
+
#
|
23 |
+
# See the README file for information on usage and redistribution.
|
24 |
+
#
|
25 |
+
from __future__ import annotations
|
26 |
+
|
27 |
+
import os
|
28 |
+
from typing import IO, Any
|
29 |
+
|
30 |
+
from . import Image, ImageFile, ImagePalette
|
31 |
+
from ._binary import i16le as i16
|
32 |
+
from ._binary import i32le as i32
|
33 |
+
from ._binary import o8
|
34 |
+
from ._binary import o16le as o16
|
35 |
+
from ._binary import o32le as o32
|
36 |
+
|
37 |
+
#
|
38 |
+
# --------------------------------------------------------------------
|
39 |
+
# Read BMP file
|
40 |
+
|
41 |
+
BIT2MODE = {
|
42 |
+
# bits => mode, rawmode
|
43 |
+
1: ("P", "P;1"),
|
44 |
+
4: ("P", "P;4"),
|
45 |
+
8: ("P", "P"),
|
46 |
+
16: ("RGB", "BGR;15"),
|
47 |
+
24: ("RGB", "BGR"),
|
48 |
+
32: ("RGB", "BGRX"),
|
49 |
+
}
|
50 |
+
|
51 |
+
|
52 |
+
def _accept(prefix: bytes) -> bool:
|
53 |
+
return prefix[:2] == b"BM"
|
54 |
+
|
55 |
+
|
56 |
+
def _dib_accept(prefix: bytes) -> bool:
|
57 |
+
return i32(prefix) in [12, 40, 52, 56, 64, 108, 124]
|
58 |
+
|
59 |
+
|
60 |
+
# =============================================================================
|
61 |
+
# Image plugin for the Windows BMP format.
|
62 |
+
# =============================================================================
|
63 |
+
class BmpImageFile(ImageFile.ImageFile):
|
64 |
+
"""Image plugin for the Windows Bitmap format (BMP)"""
|
65 |
+
|
66 |
+
# ------------------------------------------------------------- Description
|
67 |
+
format_description = "Windows Bitmap"
|
68 |
+
format = "BMP"
|
69 |
+
|
70 |
+
# -------------------------------------------------- BMP Compression values
|
71 |
+
COMPRESSIONS = {"RAW": 0, "RLE8": 1, "RLE4": 2, "BITFIELDS": 3, "JPEG": 4, "PNG": 5}
|
72 |
+
for k, v in COMPRESSIONS.items():
|
73 |
+
vars()[k] = v
|
74 |
+
|
75 |
+
def _bitmap(self, header: int = 0, offset: int = 0) -> None:
|
76 |
+
"""Read relevant info about the BMP"""
|
77 |
+
read, seek = self.fp.read, self.fp.seek
|
78 |
+
if header:
|
79 |
+
seek(header)
|
80 |
+
# read bmp header size @offset 14 (this is part of the header size)
|
81 |
+
file_info: dict[str, bool | int | tuple[int, ...]] = {
|
82 |
+
"header_size": i32(read(4)),
|
83 |
+
"direction": -1,
|
84 |
+
}
|
85 |
+
|
86 |
+
# -------------------- If requested, read header at a specific position
|
87 |
+
# read the rest of the bmp header, without its size
|
88 |
+
assert isinstance(file_info["header_size"], int)
|
89 |
+
header_data = ImageFile._safe_read(self.fp, file_info["header_size"] - 4)
|
90 |
+
|
91 |
+
# ------------------------------- Windows Bitmap v2, IBM OS/2 Bitmap v1
|
92 |
+
# ----- This format has different offsets because of width/height types
|
93 |
+
# 12: BITMAPCOREHEADER/OS21XBITMAPHEADER
|
94 |
+
if file_info["header_size"] == 12:
|
95 |
+
file_info["width"] = i16(header_data, 0)
|
96 |
+
file_info["height"] = i16(header_data, 2)
|
97 |
+
file_info["planes"] = i16(header_data, 4)
|
98 |
+
file_info["bits"] = i16(header_data, 6)
|
99 |
+
file_info["compression"] = self.COMPRESSIONS["RAW"]
|
100 |
+
file_info["palette_padding"] = 3
|
101 |
+
|
102 |
+
# --------------------------------------------- Windows Bitmap v3 to v5
|
103 |
+
# 40: BITMAPINFOHEADER
|
104 |
+
# 52: BITMAPV2HEADER
|
105 |
+
# 56: BITMAPV3HEADER
|
106 |
+
# 64: BITMAPCOREHEADER2/OS22XBITMAPHEADER
|
107 |
+
# 108: BITMAPV4HEADER
|
108 |
+
# 124: BITMAPV5HEADER
|
109 |
+
elif file_info["header_size"] in (40, 52, 56, 64, 108, 124):
|
110 |
+
file_info["y_flip"] = header_data[7] == 0xFF
|
111 |
+
file_info["direction"] = 1 if file_info["y_flip"] else -1
|
112 |
+
file_info["width"] = i32(header_data, 0)
|
113 |
+
file_info["height"] = (
|
114 |
+
i32(header_data, 4)
|
115 |
+
if not file_info["y_flip"]
|
116 |
+
else 2**32 - i32(header_data, 4)
|
117 |
+
)
|
118 |
+
file_info["planes"] = i16(header_data, 8)
|
119 |
+
file_info["bits"] = i16(header_data, 10)
|
120 |
+
file_info["compression"] = i32(header_data, 12)
|
121 |
+
# byte size of pixel data
|
122 |
+
file_info["data_size"] = i32(header_data, 16)
|
123 |
+
file_info["pixels_per_meter"] = (
|
124 |
+
i32(header_data, 20),
|
125 |
+
i32(header_data, 24),
|
126 |
+
)
|
127 |
+
file_info["colors"] = i32(header_data, 28)
|
128 |
+
file_info["palette_padding"] = 4
|
129 |
+
assert isinstance(file_info["pixels_per_meter"], tuple)
|
130 |
+
self.info["dpi"] = tuple(x / 39.3701 for x in file_info["pixels_per_meter"])
|
131 |
+
if file_info["compression"] == self.COMPRESSIONS["BITFIELDS"]:
|
132 |
+
masks = ["r_mask", "g_mask", "b_mask"]
|
133 |
+
if len(header_data) >= 48:
|
134 |
+
if len(header_data) >= 52:
|
135 |
+
masks.append("a_mask")
|
136 |
+
else:
|
137 |
+
file_info["a_mask"] = 0x0
|
138 |
+
for idx, mask in enumerate(masks):
|
139 |
+
file_info[mask] = i32(header_data, 36 + idx * 4)
|
140 |
+
else:
|
141 |
+
# 40 byte headers only have the three components in the
|
142 |
+
# bitfields masks, ref:
|
143 |
+
# https://msdn.microsoft.com/en-us/library/windows/desktop/dd183376(v=vs.85).aspx
|
144 |
+
# See also
|
145 |
+
# https://github.com/python-pillow/Pillow/issues/1293
|
146 |
+
# There is a 4th component in the RGBQuad, in the alpha
|
147 |
+
# location, but it is listed as a reserved component,
|
148 |
+
# and it is not generally an alpha channel
|
149 |
+
file_info["a_mask"] = 0x0
|
150 |
+
for mask in masks:
|
151 |
+
file_info[mask] = i32(read(4))
|
152 |
+
assert isinstance(file_info["r_mask"], int)
|
153 |
+
assert isinstance(file_info["g_mask"], int)
|
154 |
+
assert isinstance(file_info["b_mask"], int)
|
155 |
+
assert isinstance(file_info["a_mask"], int)
|
156 |
+
file_info["rgb_mask"] = (
|
157 |
+
file_info["r_mask"],
|
158 |
+
file_info["g_mask"],
|
159 |
+
file_info["b_mask"],
|
160 |
+
)
|
161 |
+
file_info["rgba_mask"] = (
|
162 |
+
file_info["r_mask"],
|
163 |
+
file_info["g_mask"],
|
164 |
+
file_info["b_mask"],
|
165 |
+
file_info["a_mask"],
|
166 |
+
)
|
167 |
+
else:
|
168 |
+
msg = f"Unsupported BMP header type ({file_info['header_size']})"
|
169 |
+
raise OSError(msg)
|
170 |
+
|
171 |
+
# ------------------ Special case : header is reported 40, which
|
172 |
+
# ---------------------- is shorter than real size for bpp >= 16
|
173 |
+
assert isinstance(file_info["width"], int)
|
174 |
+
assert isinstance(file_info["height"], int)
|
175 |
+
self._size = file_info["width"], file_info["height"]
|
176 |
+
|
177 |
+
# ------- If color count was not found in the header, compute from bits
|
178 |
+
assert isinstance(file_info["bits"], int)
|
179 |
+
file_info["colors"] = (
|
180 |
+
file_info["colors"]
|
181 |
+
if file_info.get("colors", 0)
|
182 |
+
else (1 << file_info["bits"])
|
183 |
+
)
|
184 |
+
assert isinstance(file_info["colors"], int)
|
185 |
+
if offset == 14 + file_info["header_size"] and file_info["bits"] <= 8:
|
186 |
+
offset += 4 * file_info["colors"]
|
187 |
+
|
188 |
+
# ---------------------- Check bit depth for unusual unsupported values
|
189 |
+
self._mode, raw_mode = BIT2MODE.get(file_info["bits"], ("", ""))
|
190 |
+
if not self.mode:
|
191 |
+
msg = f"Unsupported BMP pixel depth ({file_info['bits']})"
|
192 |
+
raise OSError(msg)
|
193 |
+
|
194 |
+
# ---------------- Process BMP with Bitfields compression (not palette)
|
195 |
+
decoder_name = "raw"
|
196 |
+
if file_info["compression"] == self.COMPRESSIONS["BITFIELDS"]:
|
197 |
+
SUPPORTED: dict[int, list[tuple[int, ...]]] = {
|
198 |
+
32: [
|
199 |
+
(0xFF0000, 0xFF00, 0xFF, 0x0),
|
200 |
+
(0xFF000000, 0xFF0000, 0xFF00, 0x0),
|
201 |
+
(0xFF000000, 0xFF00, 0xFF, 0x0),
|
202 |
+
(0xFF000000, 0xFF0000, 0xFF00, 0xFF),
|
203 |
+
(0xFF, 0xFF00, 0xFF0000, 0xFF000000),
|
204 |
+
(0xFF0000, 0xFF00, 0xFF, 0xFF000000),
|
205 |
+
(0xFF000000, 0xFF00, 0xFF, 0xFF0000),
|
206 |
+
(0x0, 0x0, 0x0, 0x0),
|
207 |
+
],
|
208 |
+
24: [(0xFF0000, 0xFF00, 0xFF)],
|
209 |
+
16: [(0xF800, 0x7E0, 0x1F), (0x7C00, 0x3E0, 0x1F)],
|
210 |
+
}
|
211 |
+
MASK_MODES = {
|
212 |
+
(32, (0xFF0000, 0xFF00, 0xFF, 0x0)): "BGRX",
|
213 |
+
(32, (0xFF000000, 0xFF0000, 0xFF00, 0x0)): "XBGR",
|
214 |
+
(32, (0xFF000000, 0xFF00, 0xFF, 0x0)): "BGXR",
|
215 |
+
(32, (0xFF000000, 0xFF0000, 0xFF00, 0xFF)): "ABGR",
|
216 |
+
(32, (0xFF, 0xFF00, 0xFF0000, 0xFF000000)): "RGBA",
|
217 |
+
(32, (0xFF0000, 0xFF00, 0xFF, 0xFF000000)): "BGRA",
|
218 |
+
(32, (0xFF000000, 0xFF00, 0xFF, 0xFF0000)): "BGAR",
|
219 |
+
(32, (0x0, 0x0, 0x0, 0x0)): "BGRA",
|
220 |
+
(24, (0xFF0000, 0xFF00, 0xFF)): "BGR",
|
221 |
+
(16, (0xF800, 0x7E0, 0x1F)): "BGR;16",
|
222 |
+
(16, (0x7C00, 0x3E0, 0x1F)): "BGR;15",
|
223 |
+
}
|
224 |
+
if file_info["bits"] in SUPPORTED:
|
225 |
+
if (
|
226 |
+
file_info["bits"] == 32
|
227 |
+
and file_info["rgba_mask"] in SUPPORTED[file_info["bits"]]
|
228 |
+
):
|
229 |
+
assert isinstance(file_info["rgba_mask"], tuple)
|
230 |
+
raw_mode = MASK_MODES[(file_info["bits"], file_info["rgba_mask"])]
|
231 |
+
self._mode = "RGBA" if "A" in raw_mode else self.mode
|
232 |
+
elif (
|
233 |
+
file_info["bits"] in (24, 16)
|
234 |
+
and file_info["rgb_mask"] in SUPPORTED[file_info["bits"]]
|
235 |
+
):
|
236 |
+
assert isinstance(file_info["rgb_mask"], tuple)
|
237 |
+
raw_mode = MASK_MODES[(file_info["bits"], file_info["rgb_mask"])]
|
238 |
+
else:
|
239 |
+
msg = "Unsupported BMP bitfields layout"
|
240 |
+
raise OSError(msg)
|
241 |
+
else:
|
242 |
+
msg = "Unsupported BMP bitfields layout"
|
243 |
+
raise OSError(msg)
|
244 |
+
elif file_info["compression"] == self.COMPRESSIONS["RAW"]:
|
245 |
+
if file_info["bits"] == 32 and header == 22: # 32-bit .cur offset
|
246 |
+
raw_mode, self._mode = "BGRA", "RGBA"
|
247 |
+
elif file_info["compression"] in (
|
248 |
+
self.COMPRESSIONS["RLE8"],
|
249 |
+
self.COMPRESSIONS["RLE4"],
|
250 |
+
):
|
251 |
+
decoder_name = "bmp_rle"
|
252 |
+
else:
|
253 |
+
msg = f"Unsupported BMP compression ({file_info['compression']})"
|
254 |
+
raise OSError(msg)
|
255 |
+
|
256 |
+
# --------------- Once the header is processed, process the palette/LUT
|
257 |
+
if self.mode == "P": # Paletted for 1, 4 and 8 bit images
|
258 |
+
# ---------------------------------------------------- 1-bit images
|
259 |
+
if not (0 < file_info["colors"] <= 65536):
|
260 |
+
msg = f"Unsupported BMP Palette size ({file_info['colors']})"
|
261 |
+
raise OSError(msg)
|
262 |
+
else:
|
263 |
+
assert isinstance(file_info["palette_padding"], int)
|
264 |
+
padding = file_info["palette_padding"]
|
265 |
+
palette = read(padding * file_info["colors"])
|
266 |
+
grayscale = True
|
267 |
+
indices = (
|
268 |
+
(0, 255)
|
269 |
+
if file_info["colors"] == 2
|
270 |
+
else list(range(file_info["colors"]))
|
271 |
+
)
|
272 |
+
|
273 |
+
# ----------------- Check if grayscale and ignore palette if so
|
274 |
+
for ind, val in enumerate(indices):
|
275 |
+
rgb = palette[ind * padding : ind * padding + 3]
|
276 |
+
if rgb != o8(val) * 3:
|
277 |
+
grayscale = False
|
278 |
+
|
279 |
+
# ------- If all colors are gray, white or black, ditch palette
|
280 |
+
if grayscale:
|
281 |
+
self._mode = "1" if file_info["colors"] == 2 else "L"
|
282 |
+
raw_mode = self.mode
|
283 |
+
else:
|
284 |
+
self._mode = "P"
|
285 |
+
self.palette = ImagePalette.raw(
|
286 |
+
"BGRX" if padding == 4 else "BGR", palette
|
287 |
+
)
|
288 |
+
|
289 |
+
# ---------------------------- Finally set the tile data for the plugin
|
290 |
+
self.info["compression"] = file_info["compression"]
|
291 |
+
args: list[Any] = [raw_mode]
|
292 |
+
if decoder_name == "bmp_rle":
|
293 |
+
args.append(file_info["compression"] == self.COMPRESSIONS["RLE4"])
|
294 |
+
else:
|
295 |
+
assert isinstance(file_info["width"], int)
|
296 |
+
args.append(((file_info["width"] * file_info["bits"] + 31) >> 3) & (~3))
|
297 |
+
args.append(file_info["direction"])
|
298 |
+
self.tile = [
|
299 |
+
ImageFile._Tile(
|
300 |
+
decoder_name,
|
301 |
+
(0, 0, file_info["width"], file_info["height"]),
|
302 |
+
offset or self.fp.tell(),
|
303 |
+
tuple(args),
|
304 |
+
)
|
305 |
+
]
|
306 |
+
|
307 |
+
def _open(self) -> None:
|
308 |
+
"""Open file, check magic number and read header"""
|
309 |
+
# read 14 bytes: magic number, filesize, reserved, header final offset
|
310 |
+
head_data = self.fp.read(14)
|
311 |
+
# choke if the file does not have the required magic bytes
|
312 |
+
if not _accept(head_data):
|
313 |
+
msg = "Not a BMP file"
|
314 |
+
raise SyntaxError(msg)
|
315 |
+
# read the start position of the BMP image data (u32)
|
316 |
+
offset = i32(head_data, 10)
|
317 |
+
# load bitmap information (offset=raster info)
|
318 |
+
self._bitmap(offset=offset)
|
319 |
+
|
320 |
+
|
321 |
+
class BmpRleDecoder(ImageFile.PyDecoder):
|
322 |
+
_pulls_fd = True
|
323 |
+
|
324 |
+
def decode(self, buffer: bytes | Image.SupportsArrayInterface) -> tuple[int, int]:
|
325 |
+
assert self.fd is not None
|
326 |
+
rle4 = self.args[1]
|
327 |
+
data = bytearray()
|
328 |
+
x = 0
|
329 |
+
dest_length = self.state.xsize * self.state.ysize
|
330 |
+
while len(data) < dest_length:
|
331 |
+
pixels = self.fd.read(1)
|
332 |
+
byte = self.fd.read(1)
|
333 |
+
if not pixels or not byte:
|
334 |
+
break
|
335 |
+
num_pixels = pixels[0]
|
336 |
+
if num_pixels:
|
337 |
+
# encoded mode
|
338 |
+
if x + num_pixels > self.state.xsize:
|
339 |
+
# Too much data for row
|
340 |
+
num_pixels = max(0, self.state.xsize - x)
|
341 |
+
if rle4:
|
342 |
+
first_pixel = o8(byte[0] >> 4)
|
343 |
+
second_pixel = o8(byte[0] & 0x0F)
|
344 |
+
for index in range(num_pixels):
|
345 |
+
if index % 2 == 0:
|
346 |
+
data += first_pixel
|
347 |
+
else:
|
348 |
+
data += second_pixel
|
349 |
+
else:
|
350 |
+
data += byte * num_pixels
|
351 |
+
x += num_pixels
|
352 |
+
else:
|
353 |
+
if byte[0] == 0:
|
354 |
+
# end of line
|
355 |
+
while len(data) % self.state.xsize != 0:
|
356 |
+
data += b"\x00"
|
357 |
+
x = 0
|
358 |
+
elif byte[0] == 1:
|
359 |
+
# end of bitmap
|
360 |
+
break
|
361 |
+
elif byte[0] == 2:
|
362 |
+
# delta
|
363 |
+
bytes_read = self.fd.read(2)
|
364 |
+
if len(bytes_read) < 2:
|
365 |
+
break
|
366 |
+
right, up = self.fd.read(2)
|
367 |
+
data += b"\x00" * (right + up * self.state.xsize)
|
368 |
+
x = len(data) % self.state.xsize
|
369 |
+
else:
|
370 |
+
# absolute mode
|
371 |
+
if rle4:
|
372 |
+
# 2 pixels per byte
|
373 |
+
byte_count = byte[0] // 2
|
374 |
+
bytes_read = self.fd.read(byte_count)
|
375 |
+
for byte_read in bytes_read:
|
376 |
+
data += o8(byte_read >> 4)
|
377 |
+
data += o8(byte_read & 0x0F)
|
378 |
+
else:
|
379 |
+
byte_count = byte[0]
|
380 |
+
bytes_read = self.fd.read(byte_count)
|
381 |
+
data += bytes_read
|
382 |
+
if len(bytes_read) < byte_count:
|
383 |
+
break
|
384 |
+
x += byte[0]
|
385 |
+
|
386 |
+
# align to 16-bit word boundary
|
387 |
+
if self.fd.tell() % 2 != 0:
|
388 |
+
self.fd.seek(1, os.SEEK_CUR)
|
389 |
+
rawmode = "L" if self.mode == "L" else "P"
|
390 |
+
self.set_as_raw(bytes(data), rawmode, (0, self.args[-1]))
|
391 |
+
return -1, 0
|
392 |
+
|
393 |
+
|
394 |
+
# =============================================================================
|
395 |
+
# Image plugin for the DIB format (BMP alias)
|
396 |
+
# =============================================================================
|
397 |
+
class DibImageFile(BmpImageFile):
|
398 |
+
format = "DIB"
|
399 |
+
format_description = "Windows Bitmap"
|
400 |
+
|
401 |
+
def _open(self) -> None:
|
402 |
+
self._bitmap()
|
403 |
+
|
404 |
+
|
405 |
+
#
|
406 |
+
# --------------------------------------------------------------------
|
407 |
+
# Write BMP file
|
408 |
+
|
409 |
+
|
410 |
+
SAVE = {
|
411 |
+
"1": ("1", 1, 2),
|
412 |
+
"L": ("L", 8, 256),
|
413 |
+
"P": ("P", 8, 256),
|
414 |
+
"RGB": ("BGR", 24, 0),
|
415 |
+
"RGBA": ("BGRA", 32, 0),
|
416 |
+
}
|
417 |
+
|
418 |
+
|
419 |
+
def _dib_save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
|
420 |
+
_save(im, fp, filename, False)
|
421 |
+
|
422 |
+
|
423 |
+
def _save(
|
424 |
+
im: Image.Image, fp: IO[bytes], filename: str | bytes, bitmap_header: bool = True
|
425 |
+
) -> None:
|
426 |
+
try:
|
427 |
+
rawmode, bits, colors = SAVE[im.mode]
|
428 |
+
except KeyError as e:
|
429 |
+
msg = f"cannot write mode {im.mode} as BMP"
|
430 |
+
raise OSError(msg) from e
|
431 |
+
|
432 |
+
info = im.encoderinfo
|
433 |
+
|
434 |
+
dpi = info.get("dpi", (96, 96))
|
435 |
+
|
436 |
+
# 1 meter == 39.3701 inches
|
437 |
+
ppm = tuple(int(x * 39.3701 + 0.5) for x in dpi)
|
438 |
+
|
439 |
+
stride = ((im.size[0] * bits + 7) // 8 + 3) & (~3)
|
440 |
+
header = 40 # or 64 for OS/2 version 2
|
441 |
+
image = stride * im.size[1]
|
442 |
+
|
443 |
+
if im.mode == "1":
|
444 |
+
palette = b"".join(o8(i) * 4 for i in (0, 255))
|
445 |
+
elif im.mode == "L":
|
446 |
+
palette = b"".join(o8(i) * 4 for i in range(256))
|
447 |
+
elif im.mode == "P":
|
448 |
+
palette = im.im.getpalette("RGB", "BGRX")
|
449 |
+
colors = len(palette) // 4
|
450 |
+
else:
|
451 |
+
palette = None
|
452 |
+
|
453 |
+
# bitmap header
|
454 |
+
if bitmap_header:
|
455 |
+
offset = 14 + header + colors * 4
|
456 |
+
file_size = offset + image
|
457 |
+
if file_size > 2**32 - 1:
|
458 |
+
msg = "File size is too large for the BMP format"
|
459 |
+
raise ValueError(msg)
|
460 |
+
fp.write(
|
461 |
+
b"BM" # file type (magic)
|
462 |
+
+ o32(file_size) # file size
|
463 |
+
+ o32(0) # reserved
|
464 |
+
+ o32(offset) # image data offset
|
465 |
+
)
|
466 |
+
|
467 |
+
# bitmap info header
|
468 |
+
fp.write(
|
469 |
+
o32(header) # info header size
|
470 |
+
+ o32(im.size[0]) # width
|
471 |
+
+ o32(im.size[1]) # height
|
472 |
+
+ o16(1) # planes
|
473 |
+
+ o16(bits) # depth
|
474 |
+
+ o32(0) # compression (0=uncompressed)
|
475 |
+
+ o32(image) # size of bitmap
|
476 |
+
+ o32(ppm[0]) # resolution
|
477 |
+
+ o32(ppm[1]) # resolution
|
478 |
+
+ o32(colors) # colors used
|
479 |
+
+ o32(colors) # colors important
|
480 |
+
)
|
481 |
+
|
482 |
+
fp.write(b"\0" * (header - 40)) # padding (for OS/2 format)
|
483 |
+
|
484 |
+
if palette:
|
485 |
+
fp.write(palette)
|
486 |
+
|
487 |
+
ImageFile._save(
|
488 |
+
im, fp, [ImageFile._Tile("raw", (0, 0) + im.size, 0, (rawmode, stride, -1))]
|
489 |
+
)
|
490 |
+
|
491 |
+
|
492 |
+
#
|
493 |
+
# --------------------------------------------------------------------
|
494 |
+
# Registry
|
495 |
+
|
496 |
+
|
497 |
+
Image.register_open(BmpImageFile.format, BmpImageFile, _accept)
|
498 |
+
Image.register_save(BmpImageFile.format, _save)
|
499 |
+
|
500 |
+
Image.register_extension(BmpImageFile.format, ".bmp")
|
501 |
+
|
502 |
+
Image.register_mime(BmpImageFile.format, "image/bmp")
|
503 |
+
|
504 |
+
Image.register_decoder("bmp_rle", BmpRleDecoder)
|
505 |
+
|
506 |
+
Image.register_open(DibImageFile.format, DibImageFile, _dib_accept)
|
507 |
+
Image.register_save(DibImageFile.format, _dib_save)
|
508 |
+
|
509 |
+
Image.register_extension(DibImageFile.format, ".dib")
|
510 |
+
|
511 |
+
Image.register_mime(DibImageFile.format, "image/bmp")
|
env-my/Lib/site-packages/PIL/BufrStubImagePlugin.py
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#
|
2 |
+
# The Python Imaging Library
|
3 |
+
# $Id$
|
4 |
+
#
|
5 |
+
# BUFR stub adapter
|
6 |
+
#
|
7 |
+
# Copyright (c) 1996-2003 by Fredrik Lundh
|
8 |
+
#
|
9 |
+
# See the README file for information on usage and redistribution.
|
10 |
+
#
|
11 |
+
from __future__ import annotations
|
12 |
+
|
13 |
+
from typing import IO
|
14 |
+
|
15 |
+
from . import Image, ImageFile
|
16 |
+
|
17 |
+
_handler = None
|
18 |
+
|
19 |
+
|
20 |
+
def register_handler(handler: ImageFile.StubHandler | None) -> None:
|
21 |
+
"""
|
22 |
+
Install application-specific BUFR image handler.
|
23 |
+
|
24 |
+
:param handler: Handler object.
|
25 |
+
"""
|
26 |
+
global _handler
|
27 |
+
_handler = handler
|
28 |
+
|
29 |
+
|
30 |
+
# --------------------------------------------------------------------
|
31 |
+
# Image adapter
|
32 |
+
|
33 |
+
|
34 |
+
def _accept(prefix: bytes) -> bool:
|
35 |
+
return prefix[:4] == b"BUFR" or prefix[:4] == b"ZCZC"
|
36 |
+
|
37 |
+
|
38 |
+
class BufrStubImageFile(ImageFile.StubImageFile):
|
39 |
+
format = "BUFR"
|
40 |
+
format_description = "BUFR"
|
41 |
+
|
42 |
+
def _open(self) -> None:
|
43 |
+
offset = self.fp.tell()
|
44 |
+
|
45 |
+
if not _accept(self.fp.read(4)):
|
46 |
+
msg = "Not a BUFR file"
|
47 |
+
raise SyntaxError(msg)
|
48 |
+
|
49 |
+
self.fp.seek(offset)
|
50 |
+
|
51 |
+
# make something up
|
52 |
+
self._mode = "F"
|
53 |
+
self._size = 1, 1
|
54 |
+
|
55 |
+
loader = self._load()
|
56 |
+
if loader:
|
57 |
+
loader.open(self)
|
58 |
+
|
59 |
+
def _load(self) -> ImageFile.StubHandler | None:
|
60 |
+
return _handler
|
61 |
+
|
62 |
+
|
63 |
+
def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
|
64 |
+
if _handler is None or not hasattr(_handler, "save"):
|
65 |
+
msg = "BUFR save handler not installed"
|
66 |
+
raise OSError(msg)
|
67 |
+
_handler.save(im, fp, filename)
|
68 |
+
|
69 |
+
|
70 |
+
# --------------------------------------------------------------------
|
71 |
+
# Registry
|
72 |
+
|
73 |
+
Image.register_open(BufrStubImageFile.format, BufrStubImageFile, _accept)
|
74 |
+
Image.register_save(BufrStubImageFile.format, _save)
|
75 |
+
|
76 |
+
Image.register_extension(BufrStubImageFile.format, ".bufr")
|
env-my/Lib/site-packages/PIL/ContainerIO.py
ADDED
@@ -0,0 +1,173 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#
|
2 |
+
# The Python Imaging Library.
|
3 |
+
# $Id$
|
4 |
+
#
|
5 |
+
# a class to read from a container file
|
6 |
+
#
|
7 |
+
# History:
|
8 |
+
# 1995-06-18 fl Created
|
9 |
+
# 1995-09-07 fl Added readline(), readlines()
|
10 |
+
#
|
11 |
+
# Copyright (c) 1997-2001 by Secret Labs AB
|
12 |
+
# Copyright (c) 1995 by Fredrik Lundh
|
13 |
+
#
|
14 |
+
# See the README file for information on usage and redistribution.
|
15 |
+
#
|
16 |
+
from __future__ import annotations
|
17 |
+
|
18 |
+
import io
|
19 |
+
from collections.abc import Iterable
|
20 |
+
from typing import IO, AnyStr, NoReturn
|
21 |
+
|
22 |
+
|
23 |
+
class ContainerIO(IO[AnyStr]):
|
24 |
+
"""
|
25 |
+
A file object that provides read access to a part of an existing
|
26 |
+
file (for example a TAR file).
|
27 |
+
"""
|
28 |
+
|
29 |
+
def __init__(self, file: IO[AnyStr], offset: int, length: int) -> None:
|
30 |
+
"""
|
31 |
+
Create file object.
|
32 |
+
|
33 |
+
:param file: Existing file.
|
34 |
+
:param offset: Start of region, in bytes.
|
35 |
+
:param length: Size of region, in bytes.
|
36 |
+
"""
|
37 |
+
self.fh: IO[AnyStr] = file
|
38 |
+
self.pos = 0
|
39 |
+
self.offset = offset
|
40 |
+
self.length = length
|
41 |
+
self.fh.seek(offset)
|
42 |
+
|
43 |
+
##
|
44 |
+
# Always false.
|
45 |
+
|
46 |
+
def isatty(self) -> bool:
|
47 |
+
return False
|
48 |
+
|
49 |
+
def seekable(self) -> bool:
|
50 |
+
return True
|
51 |
+
|
52 |
+
def seek(self, offset: int, mode: int = io.SEEK_SET) -> int:
|
53 |
+
"""
|
54 |
+
Move file pointer.
|
55 |
+
|
56 |
+
:param offset: Offset in bytes.
|
57 |
+
:param mode: Starting position. Use 0 for beginning of region, 1
|
58 |
+
for current offset, and 2 for end of region. You cannot move
|
59 |
+
the pointer outside the defined region.
|
60 |
+
:returns: Offset from start of region, in bytes.
|
61 |
+
"""
|
62 |
+
if mode == 1:
|
63 |
+
self.pos = self.pos + offset
|
64 |
+
elif mode == 2:
|
65 |
+
self.pos = self.length + offset
|
66 |
+
else:
|
67 |
+
self.pos = offset
|
68 |
+
# clamp
|
69 |
+
self.pos = max(0, min(self.pos, self.length))
|
70 |
+
self.fh.seek(self.offset + self.pos)
|
71 |
+
return self.pos
|
72 |
+
|
73 |
+
def tell(self) -> int:
|
74 |
+
"""
|
75 |
+
Get current file pointer.
|
76 |
+
|
77 |
+
:returns: Offset from start of region, in bytes.
|
78 |
+
"""
|
79 |
+
return self.pos
|
80 |
+
|
81 |
+
def readable(self) -> bool:
|
82 |
+
return True
|
83 |
+
|
84 |
+
def read(self, n: int = -1) -> AnyStr:
|
85 |
+
"""
|
86 |
+
Read data.
|
87 |
+
|
88 |
+
:param n: Number of bytes to read. If omitted, zero or negative,
|
89 |
+
read until end of region.
|
90 |
+
:returns: An 8-bit string.
|
91 |
+
"""
|
92 |
+
if n > 0:
|
93 |
+
n = min(n, self.length - self.pos)
|
94 |
+
else:
|
95 |
+
n = self.length - self.pos
|
96 |
+
if n <= 0: # EOF
|
97 |
+
return b"" if "b" in self.fh.mode else "" # type: ignore[return-value]
|
98 |
+
self.pos = self.pos + n
|
99 |
+
return self.fh.read(n)
|
100 |
+
|
101 |
+
def readline(self, n: int = -1) -> AnyStr:
|
102 |
+
"""
|
103 |
+
Read a line of text.
|
104 |
+
|
105 |
+
:param n: Number of bytes to read. If omitted, zero or negative,
|
106 |
+
read until end of line.
|
107 |
+
:returns: An 8-bit string.
|
108 |
+
"""
|
109 |
+
s: AnyStr = b"" if "b" in self.fh.mode else "" # type: ignore[assignment]
|
110 |
+
newline_character = b"\n" if "b" in self.fh.mode else "\n"
|
111 |
+
while True:
|
112 |
+
c = self.read(1)
|
113 |
+
if not c:
|
114 |
+
break
|
115 |
+
s = s + c
|
116 |
+
if c == newline_character or len(s) == n:
|
117 |
+
break
|
118 |
+
return s
|
119 |
+
|
120 |
+
def readlines(self, n: int | None = -1) -> list[AnyStr]:
|
121 |
+
"""
|
122 |
+
Read multiple lines of text.
|
123 |
+
|
124 |
+
:param n: Number of lines to read. If omitted, zero, negative or None,
|
125 |
+
read until end of region.
|
126 |
+
:returns: A list of 8-bit strings.
|
127 |
+
"""
|
128 |
+
lines = []
|
129 |
+
while True:
|
130 |
+
s = self.readline()
|
131 |
+
if not s:
|
132 |
+
break
|
133 |
+
lines.append(s)
|
134 |
+
if len(lines) == n:
|
135 |
+
break
|
136 |
+
return lines
|
137 |
+
|
138 |
+
def writable(self) -> bool:
|
139 |
+
return False
|
140 |
+
|
141 |
+
def write(self, b: AnyStr) -> NoReturn:
|
142 |
+
raise NotImplementedError()
|
143 |
+
|
144 |
+
def writelines(self, lines: Iterable[AnyStr]) -> NoReturn:
|
145 |
+
raise NotImplementedError()
|
146 |
+
|
147 |
+
def truncate(self, size: int | None = None) -> int:
|
148 |
+
raise NotImplementedError()
|
149 |
+
|
150 |
+
def __enter__(self) -> ContainerIO[AnyStr]:
|
151 |
+
return self
|
152 |
+
|
153 |
+
def __exit__(self, *args: object) -> None:
|
154 |
+
self.close()
|
155 |
+
|
156 |
+
def __iter__(self) -> ContainerIO[AnyStr]:
|
157 |
+
return self
|
158 |
+
|
159 |
+
def __next__(self) -> AnyStr:
|
160 |
+
line = self.readline()
|
161 |
+
if not line:
|
162 |
+
msg = "end of region"
|
163 |
+
raise StopIteration(msg)
|
164 |
+
return line
|
165 |
+
|
166 |
+
def fileno(self) -> int:
|
167 |
+
return self.fh.fileno()
|
168 |
+
|
169 |
+
def flush(self) -> None:
|
170 |
+
self.fh.flush()
|
171 |
+
|
172 |
+
def close(self) -> None:
|
173 |
+
self.fh.close()
|
env-my/Lib/site-packages/PIL/CurImagePlugin.py
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#
|
2 |
+
# The Python Imaging Library.
|
3 |
+
# $Id$
|
4 |
+
#
|
5 |
+
# Windows Cursor support for PIL
|
6 |
+
#
|
7 |
+
# notes:
|
8 |
+
# uses BmpImagePlugin.py to read the bitmap data.
|
9 |
+
#
|
10 |
+
# history:
|
11 |
+
# 96-05-27 fl Created
|
12 |
+
#
|
13 |
+
# Copyright (c) Secret Labs AB 1997.
|
14 |
+
# Copyright (c) Fredrik Lundh 1996.
|
15 |
+
#
|
16 |
+
# See the README file for information on usage and redistribution.
|
17 |
+
#
|
18 |
+
from __future__ import annotations
|
19 |
+
|
20 |
+
from . import BmpImagePlugin, Image, ImageFile
|
21 |
+
from ._binary import i16le as i16
|
22 |
+
from ._binary import i32le as i32
|
23 |
+
|
24 |
+
#
|
25 |
+
# --------------------------------------------------------------------
|
26 |
+
|
27 |
+
|
28 |
+
def _accept(prefix: bytes) -> bool:
|
29 |
+
return prefix[:4] == b"\0\0\2\0"
|
30 |
+
|
31 |
+
|
32 |
+
##
|
33 |
+
# Image plugin for Windows Cursor files.
|
34 |
+
|
35 |
+
|
36 |
+
class CurImageFile(BmpImagePlugin.BmpImageFile):
|
37 |
+
format = "CUR"
|
38 |
+
format_description = "Windows Cursor"
|
39 |
+
|
40 |
+
def _open(self) -> None:
|
41 |
+
offset = self.fp.tell()
|
42 |
+
|
43 |
+
# check magic
|
44 |
+
s = self.fp.read(6)
|
45 |
+
if not _accept(s):
|
46 |
+
msg = "not a CUR file"
|
47 |
+
raise SyntaxError(msg)
|
48 |
+
|
49 |
+
# pick the largest cursor in the file
|
50 |
+
m = b""
|
51 |
+
for i in range(i16(s, 4)):
|
52 |
+
s = self.fp.read(16)
|
53 |
+
if not m:
|
54 |
+
m = s
|
55 |
+
elif s[0] > m[0] and s[1] > m[1]:
|
56 |
+
m = s
|
57 |
+
if not m:
|
58 |
+
msg = "No cursors were found"
|
59 |
+
raise TypeError(msg)
|
60 |
+
|
61 |
+
# load as bitmap
|
62 |
+
self._bitmap(i32(m, 12) + offset)
|
63 |
+
|
64 |
+
# patch up the bitmap height
|
65 |
+
self._size = self.size[0], self.size[1] // 2
|
66 |
+
d, e, o, a = self.tile[0]
|
67 |
+
self.tile[0] = ImageFile._Tile(d, (0, 0) + self.size, o, a)
|
68 |
+
|
69 |
+
|
70 |
+
#
|
71 |
+
# --------------------------------------------------------------------
|
72 |
+
|
73 |
+
Image.register_open(CurImageFile.format, CurImageFile, _accept)
|
74 |
+
|
75 |
+
Image.register_extension(CurImageFile.format, ".cur")
|
env-my/Lib/site-packages/PIL/DcxImagePlugin.py
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#
|
2 |
+
# The Python Imaging Library.
|
3 |
+
# $Id$
|
4 |
+
#
|
5 |
+
# DCX file handling
|
6 |
+
#
|
7 |
+
# DCX is a container file format defined by Intel, commonly used
|
8 |
+
# for fax applications. Each DCX file consists of a directory
|
9 |
+
# (a list of file offsets) followed by a set of (usually 1-bit)
|
10 |
+
# PCX files.
|
11 |
+
#
|
12 |
+
# History:
|
13 |
+
# 1995-09-09 fl Created
|
14 |
+
# 1996-03-20 fl Properly derived from PcxImageFile.
|
15 |
+
# 1998-07-15 fl Renamed offset attribute to avoid name clash
|
16 |
+
# 2002-07-30 fl Fixed file handling
|
17 |
+
#
|
18 |
+
# Copyright (c) 1997-98 by Secret Labs AB.
|
19 |
+
# Copyright (c) 1995-96 by Fredrik Lundh.
|
20 |
+
#
|
21 |
+
# See the README file for information on usage and redistribution.
|
22 |
+
#
|
23 |
+
from __future__ import annotations
|
24 |
+
|
25 |
+
from . import Image
|
26 |
+
from ._binary import i32le as i32
|
27 |
+
from .PcxImagePlugin import PcxImageFile
|
28 |
+
|
29 |
+
MAGIC = 0x3ADE68B1 # QUIZ: what's this value, then?
|
30 |
+
|
31 |
+
|
32 |
+
def _accept(prefix: bytes) -> bool:
|
33 |
+
return len(prefix) >= 4 and i32(prefix) == MAGIC
|
34 |
+
|
35 |
+
|
36 |
+
##
|
37 |
+
# Image plugin for the Intel DCX format.
|
38 |
+
|
39 |
+
|
40 |
+
class DcxImageFile(PcxImageFile):
|
41 |
+
format = "DCX"
|
42 |
+
format_description = "Intel DCX"
|
43 |
+
_close_exclusive_fp_after_loading = False
|
44 |
+
|
45 |
+
def _open(self) -> None:
|
46 |
+
# Header
|
47 |
+
s = self.fp.read(4)
|
48 |
+
if not _accept(s):
|
49 |
+
msg = "not a DCX file"
|
50 |
+
raise SyntaxError(msg)
|
51 |
+
|
52 |
+
# Component directory
|
53 |
+
self._offset = []
|
54 |
+
for i in range(1024):
|
55 |
+
offset = i32(self.fp.read(4))
|
56 |
+
if not offset:
|
57 |
+
break
|
58 |
+
self._offset.append(offset)
|
59 |
+
|
60 |
+
self._fp = self.fp
|
61 |
+
self.frame = -1
|
62 |
+
self.n_frames = len(self._offset)
|
63 |
+
self.is_animated = self.n_frames > 1
|
64 |
+
self.seek(0)
|
65 |
+
|
66 |
+
def seek(self, frame: int) -> None:
|
67 |
+
if not self._seek_check(frame):
|
68 |
+
return
|
69 |
+
self.frame = frame
|
70 |
+
self.fp = self._fp
|
71 |
+
self.fp.seek(self._offset[frame])
|
72 |
+
PcxImageFile._open(self)
|
73 |
+
|
74 |
+
def tell(self) -> int:
|
75 |
+
return self.frame
|
76 |
+
|
77 |
+
|
78 |
+
Image.register_open(DcxImageFile.format, DcxImageFile, _accept)
|
79 |
+
|
80 |
+
Image.register_extension(DcxImageFile.format, ".dcx")
|
env-my/Lib/site-packages/PIL/DdsImagePlugin.py
ADDED
@@ -0,0 +1,573 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
A Pillow loader for .dds files (S3TC-compressed aka DXTC)
|
3 |
+
Jerome Leclanche <[email protected]>
|
4 |
+
|
5 |
+
Documentation:
|
6 |
+
https://web.archive.org/web/20170802060935/http://oss.sgi.com/projects/ogl-sample/registry/EXT/texture_compression_s3tc.txt
|
7 |
+
|
8 |
+
The contents of this file are hereby released in the public domain (CC0)
|
9 |
+
Full text of the CC0 license:
|
10 |
+
https://creativecommons.org/publicdomain/zero/1.0/
|
11 |
+
"""
|
12 |
+
|
13 |
+
from __future__ import annotations
|
14 |
+
|
15 |
+
import io
|
16 |
+
import struct
|
17 |
+
import sys
|
18 |
+
from enum import IntEnum, IntFlag
|
19 |
+
from typing import IO
|
20 |
+
|
21 |
+
from . import Image, ImageFile, ImagePalette
|
22 |
+
from ._binary import i32le as i32
|
23 |
+
from ._binary import o8
|
24 |
+
from ._binary import o32le as o32
|
25 |
+
|
26 |
+
# Magic ("DDS ")
|
27 |
+
DDS_MAGIC = 0x20534444
|
28 |
+
|
29 |
+
|
30 |
+
# DDS flags
|
31 |
+
class DDSD(IntFlag):
|
32 |
+
CAPS = 0x1
|
33 |
+
HEIGHT = 0x2
|
34 |
+
WIDTH = 0x4
|
35 |
+
PITCH = 0x8
|
36 |
+
PIXELFORMAT = 0x1000
|
37 |
+
MIPMAPCOUNT = 0x20000
|
38 |
+
LINEARSIZE = 0x80000
|
39 |
+
DEPTH = 0x800000
|
40 |
+
|
41 |
+
|
42 |
+
# DDS caps
|
43 |
+
class DDSCAPS(IntFlag):
|
44 |
+
COMPLEX = 0x8
|
45 |
+
TEXTURE = 0x1000
|
46 |
+
MIPMAP = 0x400000
|
47 |
+
|
48 |
+
|
49 |
+
class DDSCAPS2(IntFlag):
|
50 |
+
CUBEMAP = 0x200
|
51 |
+
CUBEMAP_POSITIVEX = 0x400
|
52 |
+
CUBEMAP_NEGATIVEX = 0x800
|
53 |
+
CUBEMAP_POSITIVEY = 0x1000
|
54 |
+
CUBEMAP_NEGATIVEY = 0x2000
|
55 |
+
CUBEMAP_POSITIVEZ = 0x4000
|
56 |
+
CUBEMAP_NEGATIVEZ = 0x8000
|
57 |
+
VOLUME = 0x200000
|
58 |
+
|
59 |
+
|
60 |
+
# Pixel Format
|
61 |
+
class DDPF(IntFlag):
|
62 |
+
ALPHAPIXELS = 0x1
|
63 |
+
ALPHA = 0x2
|
64 |
+
FOURCC = 0x4
|
65 |
+
PALETTEINDEXED8 = 0x20
|
66 |
+
RGB = 0x40
|
67 |
+
LUMINANCE = 0x20000
|
68 |
+
|
69 |
+
|
70 |
+
# dxgiformat.h
|
71 |
+
class DXGI_FORMAT(IntEnum):
|
72 |
+
UNKNOWN = 0
|
73 |
+
R32G32B32A32_TYPELESS = 1
|
74 |
+
R32G32B32A32_FLOAT = 2
|
75 |
+
R32G32B32A32_UINT = 3
|
76 |
+
R32G32B32A32_SINT = 4
|
77 |
+
R32G32B32_TYPELESS = 5
|
78 |
+
R32G32B32_FLOAT = 6
|
79 |
+
R32G32B32_UINT = 7
|
80 |
+
R32G32B32_SINT = 8
|
81 |
+
R16G16B16A16_TYPELESS = 9
|
82 |
+
R16G16B16A16_FLOAT = 10
|
83 |
+
R16G16B16A16_UNORM = 11
|
84 |
+
R16G16B16A16_UINT = 12
|
85 |
+
R16G16B16A16_SNORM = 13
|
86 |
+
R16G16B16A16_SINT = 14
|
87 |
+
R32G32_TYPELESS = 15
|
88 |
+
R32G32_FLOAT = 16
|
89 |
+
R32G32_UINT = 17
|
90 |
+
R32G32_SINT = 18
|
91 |
+
R32G8X24_TYPELESS = 19
|
92 |
+
D32_FLOAT_S8X24_UINT = 20
|
93 |
+
R32_FLOAT_X8X24_TYPELESS = 21
|
94 |
+
X32_TYPELESS_G8X24_UINT = 22
|
95 |
+
R10G10B10A2_TYPELESS = 23
|
96 |
+
R10G10B10A2_UNORM = 24
|
97 |
+
R10G10B10A2_UINT = 25
|
98 |
+
R11G11B10_FLOAT = 26
|
99 |
+
R8G8B8A8_TYPELESS = 27
|
100 |
+
R8G8B8A8_UNORM = 28
|
101 |
+
R8G8B8A8_UNORM_SRGB = 29
|
102 |
+
R8G8B8A8_UINT = 30
|
103 |
+
R8G8B8A8_SNORM = 31
|
104 |
+
R8G8B8A8_SINT = 32
|
105 |
+
R16G16_TYPELESS = 33
|
106 |
+
R16G16_FLOAT = 34
|
107 |
+
R16G16_UNORM = 35
|
108 |
+
R16G16_UINT = 36
|
109 |
+
R16G16_SNORM = 37
|
110 |
+
R16G16_SINT = 38
|
111 |
+
R32_TYPELESS = 39
|
112 |
+
D32_FLOAT = 40
|
113 |
+
R32_FLOAT = 41
|
114 |
+
R32_UINT = 42
|
115 |
+
R32_SINT = 43
|
116 |
+
R24G8_TYPELESS = 44
|
117 |
+
D24_UNORM_S8_UINT = 45
|
118 |
+
R24_UNORM_X8_TYPELESS = 46
|
119 |
+
X24_TYPELESS_G8_UINT = 47
|
120 |
+
R8G8_TYPELESS = 48
|
121 |
+
R8G8_UNORM = 49
|
122 |
+
R8G8_UINT = 50
|
123 |
+
R8G8_SNORM = 51
|
124 |
+
R8G8_SINT = 52
|
125 |
+
R16_TYPELESS = 53
|
126 |
+
R16_FLOAT = 54
|
127 |
+
D16_UNORM = 55
|
128 |
+
R16_UNORM = 56
|
129 |
+
R16_UINT = 57
|
130 |
+
R16_SNORM = 58
|
131 |
+
R16_SINT = 59
|
132 |
+
R8_TYPELESS = 60
|
133 |
+
R8_UNORM = 61
|
134 |
+
R8_UINT = 62
|
135 |
+
R8_SNORM = 63
|
136 |
+
R8_SINT = 64
|
137 |
+
A8_UNORM = 65
|
138 |
+
R1_UNORM = 66
|
139 |
+
R9G9B9E5_SHAREDEXP = 67
|
140 |
+
R8G8_B8G8_UNORM = 68
|
141 |
+
G8R8_G8B8_UNORM = 69
|
142 |
+
BC1_TYPELESS = 70
|
143 |
+
BC1_UNORM = 71
|
144 |
+
BC1_UNORM_SRGB = 72
|
145 |
+
BC2_TYPELESS = 73
|
146 |
+
BC2_UNORM = 74
|
147 |
+
BC2_UNORM_SRGB = 75
|
148 |
+
BC3_TYPELESS = 76
|
149 |
+
BC3_UNORM = 77
|
150 |
+
BC3_UNORM_SRGB = 78
|
151 |
+
BC4_TYPELESS = 79
|
152 |
+
BC4_UNORM = 80
|
153 |
+
BC4_SNORM = 81
|
154 |
+
BC5_TYPELESS = 82
|
155 |
+
BC5_UNORM = 83
|
156 |
+
BC5_SNORM = 84
|
157 |
+
B5G6R5_UNORM = 85
|
158 |
+
B5G5R5A1_UNORM = 86
|
159 |
+
B8G8R8A8_UNORM = 87
|
160 |
+
B8G8R8X8_UNORM = 88
|
161 |
+
R10G10B10_XR_BIAS_A2_UNORM = 89
|
162 |
+
B8G8R8A8_TYPELESS = 90
|
163 |
+
B8G8R8A8_UNORM_SRGB = 91
|
164 |
+
B8G8R8X8_TYPELESS = 92
|
165 |
+
B8G8R8X8_UNORM_SRGB = 93
|
166 |
+
BC6H_TYPELESS = 94
|
167 |
+
BC6H_UF16 = 95
|
168 |
+
BC6H_SF16 = 96
|
169 |
+
BC7_TYPELESS = 97
|
170 |
+
BC7_UNORM = 98
|
171 |
+
BC7_UNORM_SRGB = 99
|
172 |
+
AYUV = 100
|
173 |
+
Y410 = 101
|
174 |
+
Y416 = 102
|
175 |
+
NV12 = 103
|
176 |
+
P010 = 104
|
177 |
+
P016 = 105
|
178 |
+
OPAQUE_420 = 106
|
179 |
+
YUY2 = 107
|
180 |
+
Y210 = 108
|
181 |
+
Y216 = 109
|
182 |
+
NV11 = 110
|
183 |
+
AI44 = 111
|
184 |
+
IA44 = 112
|
185 |
+
P8 = 113
|
186 |
+
A8P8 = 114
|
187 |
+
B4G4R4A4_UNORM = 115
|
188 |
+
P208 = 130
|
189 |
+
V208 = 131
|
190 |
+
V408 = 132
|
191 |
+
SAMPLER_FEEDBACK_MIN_MIP_OPAQUE = 189
|
192 |
+
SAMPLER_FEEDBACK_MIP_REGION_USED_OPAQUE = 190
|
193 |
+
|
194 |
+
|
195 |
+
class D3DFMT(IntEnum):
|
196 |
+
UNKNOWN = 0
|
197 |
+
R8G8B8 = 20
|
198 |
+
A8R8G8B8 = 21
|
199 |
+
X8R8G8B8 = 22
|
200 |
+
R5G6B5 = 23
|
201 |
+
X1R5G5B5 = 24
|
202 |
+
A1R5G5B5 = 25
|
203 |
+
A4R4G4B4 = 26
|
204 |
+
R3G3B2 = 27
|
205 |
+
A8 = 28
|
206 |
+
A8R3G3B2 = 29
|
207 |
+
X4R4G4B4 = 30
|
208 |
+
A2B10G10R10 = 31
|
209 |
+
A8B8G8R8 = 32
|
210 |
+
X8B8G8R8 = 33
|
211 |
+
G16R16 = 34
|
212 |
+
A2R10G10B10 = 35
|
213 |
+
A16B16G16R16 = 36
|
214 |
+
A8P8 = 40
|
215 |
+
P8 = 41
|
216 |
+
L8 = 50
|
217 |
+
A8L8 = 51
|
218 |
+
A4L4 = 52
|
219 |
+
V8U8 = 60
|
220 |
+
L6V5U5 = 61
|
221 |
+
X8L8V8U8 = 62
|
222 |
+
Q8W8V8U8 = 63
|
223 |
+
V16U16 = 64
|
224 |
+
A2W10V10U10 = 67
|
225 |
+
D16_LOCKABLE = 70
|
226 |
+
D32 = 71
|
227 |
+
D15S1 = 73
|
228 |
+
D24S8 = 75
|
229 |
+
D24X8 = 77
|
230 |
+
D24X4S4 = 79
|
231 |
+
D16 = 80
|
232 |
+
D32F_LOCKABLE = 82
|
233 |
+
D24FS8 = 83
|
234 |
+
D32_LOCKABLE = 84
|
235 |
+
S8_LOCKABLE = 85
|
236 |
+
L16 = 81
|
237 |
+
VERTEXDATA = 100
|
238 |
+
INDEX16 = 101
|
239 |
+
INDEX32 = 102
|
240 |
+
Q16W16V16U16 = 110
|
241 |
+
R16F = 111
|
242 |
+
G16R16F = 112
|
243 |
+
A16B16G16R16F = 113
|
244 |
+
R32F = 114
|
245 |
+
G32R32F = 115
|
246 |
+
A32B32G32R32F = 116
|
247 |
+
CxV8U8 = 117
|
248 |
+
A1 = 118
|
249 |
+
A2B10G10R10_XR_BIAS = 119
|
250 |
+
BINARYBUFFER = 199
|
251 |
+
|
252 |
+
UYVY = i32(b"UYVY")
|
253 |
+
R8G8_B8G8 = i32(b"RGBG")
|
254 |
+
YUY2 = i32(b"YUY2")
|
255 |
+
G8R8_G8B8 = i32(b"GRGB")
|
256 |
+
DXT1 = i32(b"DXT1")
|
257 |
+
DXT2 = i32(b"DXT2")
|
258 |
+
DXT3 = i32(b"DXT3")
|
259 |
+
DXT4 = i32(b"DXT4")
|
260 |
+
DXT5 = i32(b"DXT5")
|
261 |
+
DX10 = i32(b"DX10")
|
262 |
+
BC4S = i32(b"BC4S")
|
263 |
+
BC4U = i32(b"BC4U")
|
264 |
+
BC5S = i32(b"BC5S")
|
265 |
+
BC5U = i32(b"BC5U")
|
266 |
+
ATI1 = i32(b"ATI1")
|
267 |
+
ATI2 = i32(b"ATI2")
|
268 |
+
MULTI2_ARGB8 = i32(b"MET1")
|
269 |
+
|
270 |
+
|
271 |
+
# Backward compatibility layer
|
272 |
+
module = sys.modules[__name__]
|
273 |
+
for item in DDSD:
|
274 |
+
assert item.name is not None
|
275 |
+
setattr(module, f"DDSD_{item.name}", item.value)
|
276 |
+
for item1 in DDSCAPS:
|
277 |
+
assert item1.name is not None
|
278 |
+
setattr(module, f"DDSCAPS_{item1.name}", item1.value)
|
279 |
+
for item2 in DDSCAPS2:
|
280 |
+
assert item2.name is not None
|
281 |
+
setattr(module, f"DDSCAPS2_{item2.name}", item2.value)
|
282 |
+
for item3 in DDPF:
|
283 |
+
assert item3.name is not None
|
284 |
+
setattr(module, f"DDPF_{item3.name}", item3.value)
|
285 |
+
|
286 |
+
DDS_FOURCC = DDPF.FOURCC
|
287 |
+
DDS_RGB = DDPF.RGB
|
288 |
+
DDS_RGBA = DDPF.RGB | DDPF.ALPHAPIXELS
|
289 |
+
DDS_LUMINANCE = DDPF.LUMINANCE
|
290 |
+
DDS_LUMINANCEA = DDPF.LUMINANCE | DDPF.ALPHAPIXELS
|
291 |
+
DDS_ALPHA = DDPF.ALPHA
|
292 |
+
DDS_PAL8 = DDPF.PALETTEINDEXED8
|
293 |
+
|
294 |
+
DDS_HEADER_FLAGS_TEXTURE = DDSD.CAPS | DDSD.HEIGHT | DDSD.WIDTH | DDSD.PIXELFORMAT
|
295 |
+
DDS_HEADER_FLAGS_MIPMAP = DDSD.MIPMAPCOUNT
|
296 |
+
DDS_HEADER_FLAGS_VOLUME = DDSD.DEPTH
|
297 |
+
DDS_HEADER_FLAGS_PITCH = DDSD.PITCH
|
298 |
+
DDS_HEADER_FLAGS_LINEARSIZE = DDSD.LINEARSIZE
|
299 |
+
|
300 |
+
DDS_HEIGHT = DDSD.HEIGHT
|
301 |
+
DDS_WIDTH = DDSD.WIDTH
|
302 |
+
|
303 |
+
DDS_SURFACE_FLAGS_TEXTURE = DDSCAPS.TEXTURE
|
304 |
+
DDS_SURFACE_FLAGS_MIPMAP = DDSCAPS.COMPLEX | DDSCAPS.MIPMAP
|
305 |
+
DDS_SURFACE_FLAGS_CUBEMAP = DDSCAPS.COMPLEX
|
306 |
+
|
307 |
+
DDS_CUBEMAP_POSITIVEX = DDSCAPS2.CUBEMAP | DDSCAPS2.CUBEMAP_POSITIVEX
|
308 |
+
DDS_CUBEMAP_NEGATIVEX = DDSCAPS2.CUBEMAP | DDSCAPS2.CUBEMAP_NEGATIVEX
|
309 |
+
DDS_CUBEMAP_POSITIVEY = DDSCAPS2.CUBEMAP | DDSCAPS2.CUBEMAP_POSITIVEY
|
310 |
+
DDS_CUBEMAP_NEGATIVEY = DDSCAPS2.CUBEMAP | DDSCAPS2.CUBEMAP_NEGATIVEY
|
311 |
+
DDS_CUBEMAP_POSITIVEZ = DDSCAPS2.CUBEMAP | DDSCAPS2.CUBEMAP_POSITIVEZ
|
312 |
+
DDS_CUBEMAP_NEGATIVEZ = DDSCAPS2.CUBEMAP | DDSCAPS2.CUBEMAP_NEGATIVEZ
|
313 |
+
|
314 |
+
DXT1_FOURCC = D3DFMT.DXT1
|
315 |
+
DXT3_FOURCC = D3DFMT.DXT3
|
316 |
+
DXT5_FOURCC = D3DFMT.DXT5
|
317 |
+
|
318 |
+
DXGI_FORMAT_R8G8B8A8_TYPELESS = DXGI_FORMAT.R8G8B8A8_TYPELESS
|
319 |
+
DXGI_FORMAT_R8G8B8A8_UNORM = DXGI_FORMAT.R8G8B8A8_UNORM
|
320 |
+
DXGI_FORMAT_R8G8B8A8_UNORM_SRGB = DXGI_FORMAT.R8G8B8A8_UNORM_SRGB
|
321 |
+
DXGI_FORMAT_BC5_TYPELESS = DXGI_FORMAT.BC5_TYPELESS
|
322 |
+
DXGI_FORMAT_BC5_UNORM = DXGI_FORMAT.BC5_UNORM
|
323 |
+
DXGI_FORMAT_BC5_SNORM = DXGI_FORMAT.BC5_SNORM
|
324 |
+
DXGI_FORMAT_BC6H_UF16 = DXGI_FORMAT.BC6H_UF16
|
325 |
+
DXGI_FORMAT_BC6H_SF16 = DXGI_FORMAT.BC6H_SF16
|
326 |
+
DXGI_FORMAT_BC7_TYPELESS = DXGI_FORMAT.BC7_TYPELESS
|
327 |
+
DXGI_FORMAT_BC7_UNORM = DXGI_FORMAT.BC7_UNORM
|
328 |
+
DXGI_FORMAT_BC7_UNORM_SRGB = DXGI_FORMAT.BC7_UNORM_SRGB
|
329 |
+
|
330 |
+
|
331 |
+
class DdsImageFile(ImageFile.ImageFile):
|
332 |
+
format = "DDS"
|
333 |
+
format_description = "DirectDraw Surface"
|
334 |
+
|
335 |
+
def _open(self) -> None:
|
336 |
+
if not _accept(self.fp.read(4)):
|
337 |
+
msg = "not a DDS file"
|
338 |
+
raise SyntaxError(msg)
|
339 |
+
(header_size,) = struct.unpack("<I", self.fp.read(4))
|
340 |
+
if header_size != 124:
|
341 |
+
msg = f"Unsupported header size {repr(header_size)}"
|
342 |
+
raise OSError(msg)
|
343 |
+
header_bytes = self.fp.read(header_size - 4)
|
344 |
+
if len(header_bytes) != 120:
|
345 |
+
msg = f"Incomplete header: {len(header_bytes)} bytes"
|
346 |
+
raise OSError(msg)
|
347 |
+
header = io.BytesIO(header_bytes)
|
348 |
+
|
349 |
+
flags, height, width = struct.unpack("<3I", header.read(12))
|
350 |
+
self._size = (width, height)
|
351 |
+
extents = (0, 0) + self.size
|
352 |
+
|
353 |
+
pitch, depth, mipmaps = struct.unpack("<3I", header.read(12))
|
354 |
+
struct.unpack("<11I", header.read(44)) # reserved
|
355 |
+
|
356 |
+
# pixel format
|
357 |
+
pfsize, pfflags, fourcc, bitcount = struct.unpack("<4I", header.read(16))
|
358 |
+
n = 0
|
359 |
+
rawmode = None
|
360 |
+
if pfflags & DDPF.RGB:
|
361 |
+
# Texture contains uncompressed RGB data
|
362 |
+
if pfflags & DDPF.ALPHAPIXELS:
|
363 |
+
self._mode = "RGBA"
|
364 |
+
mask_count = 4
|
365 |
+
else:
|
366 |
+
self._mode = "RGB"
|
367 |
+
mask_count = 3
|
368 |
+
|
369 |
+
masks = struct.unpack(f"<{mask_count}I", header.read(mask_count * 4))
|
370 |
+
self.tile = [ImageFile._Tile("dds_rgb", extents, 0, (bitcount, masks))]
|
371 |
+
return
|
372 |
+
elif pfflags & DDPF.LUMINANCE:
|
373 |
+
if bitcount == 8:
|
374 |
+
self._mode = "L"
|
375 |
+
elif bitcount == 16 and pfflags & DDPF.ALPHAPIXELS:
|
376 |
+
self._mode = "LA"
|
377 |
+
else:
|
378 |
+
msg = f"Unsupported bitcount {bitcount} for {pfflags}"
|
379 |
+
raise OSError(msg)
|
380 |
+
elif pfflags & DDPF.PALETTEINDEXED8:
|
381 |
+
self._mode = "P"
|
382 |
+
self.palette = ImagePalette.raw("RGBA", self.fp.read(1024))
|
383 |
+
self.palette.mode = "RGBA"
|
384 |
+
elif pfflags & DDPF.FOURCC:
|
385 |
+
offset = header_size + 4
|
386 |
+
if fourcc == D3DFMT.DXT1:
|
387 |
+
self._mode = "RGBA"
|
388 |
+
self.pixel_format = "DXT1"
|
389 |
+
n = 1
|
390 |
+
elif fourcc == D3DFMT.DXT3:
|
391 |
+
self._mode = "RGBA"
|
392 |
+
self.pixel_format = "DXT3"
|
393 |
+
n = 2
|
394 |
+
elif fourcc == D3DFMT.DXT5:
|
395 |
+
self._mode = "RGBA"
|
396 |
+
self.pixel_format = "DXT5"
|
397 |
+
n = 3
|
398 |
+
elif fourcc in (D3DFMT.BC4U, D3DFMT.ATI1):
|
399 |
+
self._mode = "L"
|
400 |
+
self.pixel_format = "BC4"
|
401 |
+
n = 4
|
402 |
+
elif fourcc == D3DFMT.BC5S:
|
403 |
+
self._mode = "RGB"
|
404 |
+
self.pixel_format = "BC5S"
|
405 |
+
n = 5
|
406 |
+
elif fourcc in (D3DFMT.BC5U, D3DFMT.ATI2):
|
407 |
+
self._mode = "RGB"
|
408 |
+
self.pixel_format = "BC5"
|
409 |
+
n = 5
|
410 |
+
elif fourcc == D3DFMT.DX10:
|
411 |
+
offset += 20
|
412 |
+
# ignoring flags which pertain to volume textures and cubemaps
|
413 |
+
(dxgi_format,) = struct.unpack("<I", self.fp.read(4))
|
414 |
+
self.fp.read(16)
|
415 |
+
if dxgi_format in (
|
416 |
+
DXGI_FORMAT.BC1_UNORM,
|
417 |
+
DXGI_FORMAT.BC1_TYPELESS,
|
418 |
+
):
|
419 |
+
self._mode = "RGBA"
|
420 |
+
self.pixel_format = "BC1"
|
421 |
+
n = 1
|
422 |
+
elif dxgi_format in (DXGI_FORMAT.BC4_TYPELESS, DXGI_FORMAT.BC4_UNORM):
|
423 |
+
self._mode = "L"
|
424 |
+
self.pixel_format = "BC4"
|
425 |
+
n = 4
|
426 |
+
elif dxgi_format in (DXGI_FORMAT.BC5_TYPELESS, DXGI_FORMAT.BC5_UNORM):
|
427 |
+
self._mode = "RGB"
|
428 |
+
self.pixel_format = "BC5"
|
429 |
+
n = 5
|
430 |
+
elif dxgi_format == DXGI_FORMAT.BC5_SNORM:
|
431 |
+
self._mode = "RGB"
|
432 |
+
self.pixel_format = "BC5S"
|
433 |
+
n = 5
|
434 |
+
elif dxgi_format == DXGI_FORMAT.BC6H_UF16:
|
435 |
+
self._mode = "RGB"
|
436 |
+
self.pixel_format = "BC6H"
|
437 |
+
n = 6
|
438 |
+
elif dxgi_format == DXGI_FORMAT.BC6H_SF16:
|
439 |
+
self._mode = "RGB"
|
440 |
+
self.pixel_format = "BC6HS"
|
441 |
+
n = 6
|
442 |
+
elif dxgi_format in (
|
443 |
+
DXGI_FORMAT.BC7_TYPELESS,
|
444 |
+
DXGI_FORMAT.BC7_UNORM,
|
445 |
+
DXGI_FORMAT.BC7_UNORM_SRGB,
|
446 |
+
):
|
447 |
+
self._mode = "RGBA"
|
448 |
+
self.pixel_format = "BC7"
|
449 |
+
n = 7
|
450 |
+
if dxgi_format == DXGI_FORMAT.BC7_UNORM_SRGB:
|
451 |
+
self.info["gamma"] = 1 / 2.2
|
452 |
+
elif dxgi_format in (
|
453 |
+
DXGI_FORMAT.R8G8B8A8_TYPELESS,
|
454 |
+
DXGI_FORMAT.R8G8B8A8_UNORM,
|
455 |
+
DXGI_FORMAT.R8G8B8A8_UNORM_SRGB,
|
456 |
+
):
|
457 |
+
self._mode = "RGBA"
|
458 |
+
if dxgi_format == DXGI_FORMAT.R8G8B8A8_UNORM_SRGB:
|
459 |
+
self.info["gamma"] = 1 / 2.2
|
460 |
+
else:
|
461 |
+
msg = f"Unimplemented DXGI format {dxgi_format}"
|
462 |
+
raise NotImplementedError(msg)
|
463 |
+
else:
|
464 |
+
msg = f"Unimplemented pixel format {repr(fourcc)}"
|
465 |
+
raise NotImplementedError(msg)
|
466 |
+
else:
|
467 |
+
msg = f"Unknown pixel format flags {pfflags}"
|
468 |
+
raise NotImplementedError(msg)
|
469 |
+
|
470 |
+
if n:
|
471 |
+
self.tile = [
|
472 |
+
ImageFile._Tile("bcn", extents, offset, (n, self.pixel_format))
|
473 |
+
]
|
474 |
+
else:
|
475 |
+
self.tile = [ImageFile._Tile("raw", extents, 0, rawmode or self.mode)]
|
476 |
+
|
477 |
+
def load_seek(self, pos: int) -> None:
|
478 |
+
pass
|
479 |
+
|
480 |
+
|
481 |
+
class DdsRgbDecoder(ImageFile.PyDecoder):
|
482 |
+
_pulls_fd = True
|
483 |
+
|
484 |
+
def decode(self, buffer: bytes | Image.SupportsArrayInterface) -> tuple[int, int]:
|
485 |
+
assert self.fd is not None
|
486 |
+
bitcount, masks = self.args
|
487 |
+
|
488 |
+
# Some masks will be padded with zeros, e.g. R 0b11 G 0b1100
|
489 |
+
# Calculate how many zeros each mask is padded with
|
490 |
+
mask_offsets = []
|
491 |
+
# And the maximum value of each channel without the padding
|
492 |
+
mask_totals = []
|
493 |
+
for mask in masks:
|
494 |
+
offset = 0
|
495 |
+
if mask != 0:
|
496 |
+
while mask >> (offset + 1) << (offset + 1) == mask:
|
497 |
+
offset += 1
|
498 |
+
mask_offsets.append(offset)
|
499 |
+
mask_totals.append(mask >> offset)
|
500 |
+
|
501 |
+
data = bytearray()
|
502 |
+
bytecount = bitcount // 8
|
503 |
+
dest_length = self.state.xsize * self.state.ysize * len(masks)
|
504 |
+
while len(data) < dest_length:
|
505 |
+
value = int.from_bytes(self.fd.read(bytecount), "little")
|
506 |
+
for i, mask in enumerate(masks):
|
507 |
+
masked_value = value & mask
|
508 |
+
# Remove the zero padding, and scale it to 8 bits
|
509 |
+
data += o8(
|
510 |
+
int(((masked_value >> mask_offsets[i]) / mask_totals[i]) * 255)
|
511 |
+
)
|
512 |
+
self.set_as_raw(data)
|
513 |
+
return -1, 0
|
514 |
+
|
515 |
+
|
516 |
+
def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
|
517 |
+
if im.mode not in ("RGB", "RGBA", "L", "LA"):
|
518 |
+
msg = f"cannot write mode {im.mode} as DDS"
|
519 |
+
raise OSError(msg)
|
520 |
+
|
521 |
+
alpha = im.mode[-1] == "A"
|
522 |
+
if im.mode[0] == "L":
|
523 |
+
pixel_flags = DDPF.LUMINANCE
|
524 |
+
rawmode = im.mode
|
525 |
+
if alpha:
|
526 |
+
rgba_mask = [0x000000FF, 0x000000FF, 0x000000FF]
|
527 |
+
else:
|
528 |
+
rgba_mask = [0xFF000000, 0xFF000000, 0xFF000000]
|
529 |
+
else:
|
530 |
+
pixel_flags = DDPF.RGB
|
531 |
+
rawmode = im.mode[::-1]
|
532 |
+
rgba_mask = [0x00FF0000, 0x0000FF00, 0x000000FF]
|
533 |
+
|
534 |
+
if alpha:
|
535 |
+
r, g, b, a = im.split()
|
536 |
+
im = Image.merge("RGBA", (a, r, g, b))
|
537 |
+
if alpha:
|
538 |
+
pixel_flags |= DDPF.ALPHAPIXELS
|
539 |
+
rgba_mask.append(0xFF000000 if alpha else 0)
|
540 |
+
|
541 |
+
flags = DDSD.CAPS | DDSD.HEIGHT | DDSD.WIDTH | DDSD.PITCH | DDSD.PIXELFORMAT
|
542 |
+
bitcount = len(im.getbands()) * 8
|
543 |
+
pitch = (im.width * bitcount + 7) // 8
|
544 |
+
|
545 |
+
fp.write(
|
546 |
+
o32(DDS_MAGIC)
|
547 |
+
+ struct.pack(
|
548 |
+
"<7I",
|
549 |
+
124, # header size
|
550 |
+
flags, # flags
|
551 |
+
im.height,
|
552 |
+
im.width,
|
553 |
+
pitch,
|
554 |
+
0, # depth
|
555 |
+
0, # mipmaps
|
556 |
+
)
|
557 |
+
+ struct.pack("11I", *((0,) * 11)) # reserved
|
558 |
+
# pfsize, pfflags, fourcc, bitcount
|
559 |
+
+ struct.pack("<4I", 32, pixel_flags, 0, bitcount)
|
560 |
+
+ struct.pack("<4I", *rgba_mask) # dwRGBABitMask
|
561 |
+
+ struct.pack("<5I", DDSCAPS.TEXTURE, 0, 0, 0, 0)
|
562 |
+
)
|
563 |
+
ImageFile._save(im, fp, [ImageFile._Tile("raw", (0, 0) + im.size, 0, rawmode)])
|
564 |
+
|
565 |
+
|
566 |
+
def _accept(prefix: bytes) -> bool:
|
567 |
+
return prefix[:4] == b"DDS "
|
568 |
+
|
569 |
+
|
570 |
+
Image.register_open(DdsImageFile.format, DdsImageFile, _accept)
|
571 |
+
Image.register_decoder("dds_rgb", DdsRgbDecoder)
|
572 |
+
Image.register_save(DdsImageFile.format, _save)
|
573 |
+
Image.register_extension(DdsImageFile.format, ".dds")
|
env-my/Lib/site-packages/PIL/EpsImagePlugin.py
ADDED
@@ -0,0 +1,474 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#
|
2 |
+
# The Python Imaging Library.
|
3 |
+
# $Id$
|
4 |
+
#
|
5 |
+
# EPS file handling
|
6 |
+
#
|
7 |
+
# History:
|
8 |
+
# 1995-09-01 fl Created (0.1)
|
9 |
+
# 1996-05-18 fl Don't choke on "atend" fields, Ghostscript interface (0.2)
|
10 |
+
# 1996-08-22 fl Don't choke on floating point BoundingBox values
|
11 |
+
# 1996-08-23 fl Handle files from Macintosh (0.3)
|
12 |
+
# 2001-02-17 fl Use 're' instead of 'regex' (Python 2.1) (0.4)
|
13 |
+
# 2003-09-07 fl Check gs.close status (from Federico Di Gregorio) (0.5)
|
14 |
+
# 2014-05-07 e Handling of EPS with binary preview and fixed resolution
|
15 |
+
# resizing
|
16 |
+
#
|
17 |
+
# Copyright (c) 1997-2003 by Secret Labs AB.
|
18 |
+
# Copyright (c) 1995-2003 by Fredrik Lundh
|
19 |
+
#
|
20 |
+
# See the README file for information on usage and redistribution.
|
21 |
+
#
|
22 |
+
from __future__ import annotations
|
23 |
+
|
24 |
+
import io
|
25 |
+
import os
|
26 |
+
import re
|
27 |
+
import subprocess
|
28 |
+
import sys
|
29 |
+
import tempfile
|
30 |
+
from typing import IO
|
31 |
+
|
32 |
+
from . import Image, ImageFile
|
33 |
+
from ._binary import i32le as i32
|
34 |
+
|
35 |
+
# --------------------------------------------------------------------
|
36 |
+
|
37 |
+
|
38 |
+
split = re.compile(r"^%%([^:]*):[ \t]*(.*)[ \t]*$")
|
39 |
+
field = re.compile(r"^%[%!\w]([^:]*)[ \t]*$")
|
40 |
+
|
41 |
+
gs_binary: str | bool | None = None
|
42 |
+
gs_windows_binary = None
|
43 |
+
|
44 |
+
|
45 |
+
def has_ghostscript() -> bool:
|
46 |
+
global gs_binary, gs_windows_binary
|
47 |
+
if gs_binary is None:
|
48 |
+
if sys.platform.startswith("win"):
|
49 |
+
if gs_windows_binary is None:
|
50 |
+
import shutil
|
51 |
+
|
52 |
+
for binary in ("gswin32c", "gswin64c", "gs"):
|
53 |
+
if shutil.which(binary) is not None:
|
54 |
+
gs_windows_binary = binary
|
55 |
+
break
|
56 |
+
else:
|
57 |
+
gs_windows_binary = False
|
58 |
+
gs_binary = gs_windows_binary
|
59 |
+
else:
|
60 |
+
try:
|
61 |
+
subprocess.check_call(["gs", "--version"], stdout=subprocess.DEVNULL)
|
62 |
+
gs_binary = "gs"
|
63 |
+
except OSError:
|
64 |
+
gs_binary = False
|
65 |
+
return gs_binary is not False
|
66 |
+
|
67 |
+
|
68 |
+
def Ghostscript(
|
69 |
+
tile: list[ImageFile._Tile],
|
70 |
+
size: tuple[int, int],
|
71 |
+
fp: IO[bytes],
|
72 |
+
scale: int = 1,
|
73 |
+
transparency: bool = False,
|
74 |
+
) -> Image.core.ImagingCore:
|
75 |
+
"""Render an image using Ghostscript"""
|
76 |
+
global gs_binary
|
77 |
+
if not has_ghostscript():
|
78 |
+
msg = "Unable to locate Ghostscript on paths"
|
79 |
+
raise OSError(msg)
|
80 |
+
assert isinstance(gs_binary, str)
|
81 |
+
|
82 |
+
# Unpack decoder tile
|
83 |
+
args = tile[0].args
|
84 |
+
assert isinstance(args, tuple)
|
85 |
+
length, bbox = args
|
86 |
+
|
87 |
+
# Hack to support hi-res rendering
|
88 |
+
scale = int(scale) or 1
|
89 |
+
width = size[0] * scale
|
90 |
+
height = size[1] * scale
|
91 |
+
# resolution is dependent on bbox and size
|
92 |
+
res_x = 72.0 * width / (bbox[2] - bbox[0])
|
93 |
+
res_y = 72.0 * height / (bbox[3] - bbox[1])
|
94 |
+
|
95 |
+
out_fd, outfile = tempfile.mkstemp()
|
96 |
+
os.close(out_fd)
|
97 |
+
|
98 |
+
infile_temp = None
|
99 |
+
if hasattr(fp, "name") and os.path.exists(fp.name):
|
100 |
+
infile = fp.name
|
101 |
+
else:
|
102 |
+
in_fd, infile_temp = tempfile.mkstemp()
|
103 |
+
os.close(in_fd)
|
104 |
+
infile = infile_temp
|
105 |
+
|
106 |
+
# Ignore length and offset!
|
107 |
+
# Ghostscript can read it
|
108 |
+
# Copy whole file to read in Ghostscript
|
109 |
+
with open(infile_temp, "wb") as f:
|
110 |
+
# fetch length of fp
|
111 |
+
fp.seek(0, io.SEEK_END)
|
112 |
+
fsize = fp.tell()
|
113 |
+
# ensure start position
|
114 |
+
# go back
|
115 |
+
fp.seek(0)
|
116 |
+
lengthfile = fsize
|
117 |
+
while lengthfile > 0:
|
118 |
+
s = fp.read(min(lengthfile, 100 * 1024))
|
119 |
+
if not s:
|
120 |
+
break
|
121 |
+
lengthfile -= len(s)
|
122 |
+
f.write(s)
|
123 |
+
|
124 |
+
if transparency:
|
125 |
+
# "RGBA"
|
126 |
+
device = "pngalpha"
|
127 |
+
else:
|
128 |
+
# "pnmraw" automatically chooses between
|
129 |
+
# PBM ("1"), PGM ("L"), and PPM ("RGB").
|
130 |
+
device = "pnmraw"
|
131 |
+
|
132 |
+
# Build Ghostscript command
|
133 |
+
command = [
|
134 |
+
gs_binary,
|
135 |
+
"-q", # quiet mode
|
136 |
+
f"-g{width:d}x{height:d}", # set output geometry (pixels)
|
137 |
+
f"-r{res_x:f}x{res_y:f}", # set input DPI (dots per inch)
|
138 |
+
"-dBATCH", # exit after processing
|
139 |
+
"-dNOPAUSE", # don't pause between pages
|
140 |
+
"-dSAFER", # safe mode
|
141 |
+
f"-sDEVICE={device}",
|
142 |
+
f"-sOutputFile={outfile}", # output file
|
143 |
+
# adjust for image origin
|
144 |
+
"-c",
|
145 |
+
f"{-bbox[0]} {-bbox[1]} translate",
|
146 |
+
"-f",
|
147 |
+
infile, # input file
|
148 |
+
# showpage (see https://bugs.ghostscript.com/show_bug.cgi?id=698272)
|
149 |
+
"-c",
|
150 |
+
"showpage",
|
151 |
+
]
|
152 |
+
|
153 |
+
# push data through Ghostscript
|
154 |
+
try:
|
155 |
+
startupinfo = None
|
156 |
+
if sys.platform.startswith("win"):
|
157 |
+
startupinfo = subprocess.STARTUPINFO()
|
158 |
+
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
159 |
+
subprocess.check_call(command, startupinfo=startupinfo)
|
160 |
+
with Image.open(outfile) as out_im:
|
161 |
+
out_im.load()
|
162 |
+
return out_im.im.copy()
|
163 |
+
finally:
|
164 |
+
try:
|
165 |
+
os.unlink(outfile)
|
166 |
+
if infile_temp:
|
167 |
+
os.unlink(infile_temp)
|
168 |
+
except OSError:
|
169 |
+
pass
|
170 |
+
|
171 |
+
|
172 |
+
def _accept(prefix: bytes) -> bool:
|
173 |
+
return prefix[:4] == b"%!PS" or (len(prefix) >= 4 and i32(prefix) == 0xC6D3D0C5)
|
174 |
+
|
175 |
+
|
176 |
+
##
|
177 |
+
# Image plugin for Encapsulated PostScript. This plugin supports only
|
178 |
+
# a few variants of this format.
|
179 |
+
|
180 |
+
|
181 |
+
class EpsImageFile(ImageFile.ImageFile):
|
182 |
+
"""EPS File Parser for the Python Imaging Library"""
|
183 |
+
|
184 |
+
format = "EPS"
|
185 |
+
format_description = "Encapsulated Postscript"
|
186 |
+
|
187 |
+
mode_map = {1: "L", 2: "LAB", 3: "RGB", 4: "CMYK"}
|
188 |
+
|
189 |
+
def _open(self) -> None:
|
190 |
+
(length, offset) = self._find_offset(self.fp)
|
191 |
+
|
192 |
+
# go to offset - start of "%!PS"
|
193 |
+
self.fp.seek(offset)
|
194 |
+
|
195 |
+
self._mode = "RGB"
|
196 |
+
|
197 |
+
# When reading header comments, the first comment is used.
|
198 |
+
# When reading trailer comments, the last comment is used.
|
199 |
+
bounding_box: list[int] | None = None
|
200 |
+
imagedata_size: tuple[int, int] | None = None
|
201 |
+
|
202 |
+
byte_arr = bytearray(255)
|
203 |
+
bytes_mv = memoryview(byte_arr)
|
204 |
+
bytes_read = 0
|
205 |
+
reading_header_comments = True
|
206 |
+
reading_trailer_comments = False
|
207 |
+
trailer_reached = False
|
208 |
+
|
209 |
+
def check_required_header_comments() -> None:
|
210 |
+
"""
|
211 |
+
The EPS specification requires that some headers exist.
|
212 |
+
This should be checked when the header comments formally end,
|
213 |
+
when image data starts, or when the file ends, whichever comes first.
|
214 |
+
"""
|
215 |
+
if "PS-Adobe" not in self.info:
|
216 |
+
msg = 'EPS header missing "%!PS-Adobe" comment'
|
217 |
+
raise SyntaxError(msg)
|
218 |
+
if "BoundingBox" not in self.info:
|
219 |
+
msg = 'EPS header missing "%%BoundingBox" comment'
|
220 |
+
raise SyntaxError(msg)
|
221 |
+
|
222 |
+
def read_comment(s: str) -> bool:
|
223 |
+
nonlocal bounding_box, reading_trailer_comments
|
224 |
+
try:
|
225 |
+
m = split.match(s)
|
226 |
+
except re.error as e:
|
227 |
+
msg = "not an EPS file"
|
228 |
+
raise SyntaxError(msg) from e
|
229 |
+
|
230 |
+
if not m:
|
231 |
+
return False
|
232 |
+
|
233 |
+
k, v = m.group(1, 2)
|
234 |
+
self.info[k] = v
|
235 |
+
if k == "BoundingBox":
|
236 |
+
if v == "(atend)":
|
237 |
+
reading_trailer_comments = True
|
238 |
+
elif not bounding_box or (trailer_reached and reading_trailer_comments):
|
239 |
+
try:
|
240 |
+
# Note: The DSC spec says that BoundingBox
|
241 |
+
# fields should be integers, but some drivers
|
242 |
+
# put floating point values there anyway.
|
243 |
+
bounding_box = [int(float(i)) for i in v.split()]
|
244 |
+
except Exception:
|
245 |
+
pass
|
246 |
+
return True
|
247 |
+
|
248 |
+
while True:
|
249 |
+
byte = self.fp.read(1)
|
250 |
+
if byte == b"":
|
251 |
+
# if we didn't read a byte we must be at the end of the file
|
252 |
+
if bytes_read == 0:
|
253 |
+
if reading_header_comments:
|
254 |
+
check_required_header_comments()
|
255 |
+
break
|
256 |
+
elif byte in b"\r\n":
|
257 |
+
# if we read a line ending character, ignore it and parse what
|
258 |
+
# we have already read. if we haven't read any other characters,
|
259 |
+
# continue reading
|
260 |
+
if bytes_read == 0:
|
261 |
+
continue
|
262 |
+
else:
|
263 |
+
# ASCII/hexadecimal lines in an EPS file must not exceed
|
264 |
+
# 255 characters, not including line ending characters
|
265 |
+
if bytes_read >= 255:
|
266 |
+
# only enforce this for lines starting with a "%",
|
267 |
+
# otherwise assume it's binary data
|
268 |
+
if byte_arr[0] == ord("%"):
|
269 |
+
msg = "not an EPS file"
|
270 |
+
raise SyntaxError(msg)
|
271 |
+
else:
|
272 |
+
if reading_header_comments:
|
273 |
+
check_required_header_comments()
|
274 |
+
reading_header_comments = False
|
275 |
+
# reset bytes_read so we can keep reading
|
276 |
+
# data until the end of the line
|
277 |
+
bytes_read = 0
|
278 |
+
byte_arr[bytes_read] = byte[0]
|
279 |
+
bytes_read += 1
|
280 |
+
continue
|
281 |
+
|
282 |
+
if reading_header_comments:
|
283 |
+
# Load EPS header
|
284 |
+
|
285 |
+
# if this line doesn't start with a "%",
|
286 |
+
# or does start with "%%EndComments",
|
287 |
+
# then we've reached the end of the header/comments
|
288 |
+
if byte_arr[0] != ord("%") or bytes_mv[:13] == b"%%EndComments":
|
289 |
+
check_required_header_comments()
|
290 |
+
reading_header_comments = False
|
291 |
+
continue
|
292 |
+
|
293 |
+
s = str(bytes_mv[:bytes_read], "latin-1")
|
294 |
+
if not read_comment(s):
|
295 |
+
m = field.match(s)
|
296 |
+
if m:
|
297 |
+
k = m.group(1)
|
298 |
+
if k[:8] == "PS-Adobe":
|
299 |
+
self.info["PS-Adobe"] = k[9:]
|
300 |
+
else:
|
301 |
+
self.info[k] = ""
|
302 |
+
elif s[0] == "%":
|
303 |
+
# handle non-DSC PostScript comments that some
|
304 |
+
# tools mistakenly put in the Comments section
|
305 |
+
pass
|
306 |
+
else:
|
307 |
+
msg = "bad EPS header"
|
308 |
+
raise OSError(msg)
|
309 |
+
elif bytes_mv[:11] == b"%ImageData:":
|
310 |
+
# Check for an "ImageData" descriptor
|
311 |
+
# https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/#50577413_pgfId-1035096
|
312 |
+
|
313 |
+
# If we've already read an "ImageData" descriptor,
|
314 |
+
# don't read another one.
|
315 |
+
if imagedata_size:
|
316 |
+
bytes_read = 0
|
317 |
+
continue
|
318 |
+
|
319 |
+
# Values:
|
320 |
+
# columns
|
321 |
+
# rows
|
322 |
+
# bit depth (1 or 8)
|
323 |
+
# mode (1: L, 2: LAB, 3: RGB, 4: CMYK)
|
324 |
+
# number of padding channels
|
325 |
+
# block size (number of bytes per row per channel)
|
326 |
+
# binary/ascii (1: binary, 2: ascii)
|
327 |
+
# data start identifier (the image data follows after a single line
|
328 |
+
# consisting only of this quoted value)
|
329 |
+
image_data_values = byte_arr[11:bytes_read].split(None, 7)
|
330 |
+
columns, rows, bit_depth, mode_id = (
|
331 |
+
int(value) for value in image_data_values[:4]
|
332 |
+
)
|
333 |
+
|
334 |
+
if bit_depth == 1:
|
335 |
+
self._mode = "1"
|
336 |
+
elif bit_depth == 8:
|
337 |
+
try:
|
338 |
+
self._mode = self.mode_map[mode_id]
|
339 |
+
except ValueError:
|
340 |
+
break
|
341 |
+
else:
|
342 |
+
break
|
343 |
+
|
344 |
+
# Parse the columns and rows after checking the bit depth and mode
|
345 |
+
# in case the bit depth and/or mode are invalid.
|
346 |
+
imagedata_size = columns, rows
|
347 |
+
elif bytes_mv[:5] == b"%%EOF":
|
348 |
+
break
|
349 |
+
elif trailer_reached and reading_trailer_comments:
|
350 |
+
# Load EPS trailer
|
351 |
+
s = str(bytes_mv[:bytes_read], "latin-1")
|
352 |
+
read_comment(s)
|
353 |
+
elif bytes_mv[:9] == b"%%Trailer":
|
354 |
+
trailer_reached = True
|
355 |
+
bytes_read = 0
|
356 |
+
|
357 |
+
# A "BoundingBox" is always required,
|
358 |
+
# even if an "ImageData" descriptor size exists.
|
359 |
+
if not bounding_box:
|
360 |
+
msg = "cannot determine EPS bounding box"
|
361 |
+
raise OSError(msg)
|
362 |
+
|
363 |
+
# An "ImageData" size takes precedence over the "BoundingBox".
|
364 |
+
self._size = imagedata_size or (
|
365 |
+
bounding_box[2] - bounding_box[0],
|
366 |
+
bounding_box[3] - bounding_box[1],
|
367 |
+
)
|
368 |
+
|
369 |
+
self.tile = [
|
370 |
+
ImageFile._Tile("eps", (0, 0) + self.size, offset, (length, bounding_box))
|
371 |
+
]
|
372 |
+
|
373 |
+
def _find_offset(self, fp: IO[bytes]) -> tuple[int, int]:
|
374 |
+
s = fp.read(4)
|
375 |
+
|
376 |
+
if s == b"%!PS":
|
377 |
+
# for HEAD without binary preview
|
378 |
+
fp.seek(0, io.SEEK_END)
|
379 |
+
length = fp.tell()
|
380 |
+
offset = 0
|
381 |
+
elif i32(s) == 0xC6D3D0C5:
|
382 |
+
# FIX for: Some EPS file not handled correctly / issue #302
|
383 |
+
# EPS can contain binary data
|
384 |
+
# or start directly with latin coding
|
385 |
+
# more info see:
|
386 |
+
# https://web.archive.org/web/20160528181353/http://partners.adobe.com/public/developer/en/ps/5002.EPSF_Spec.pdf
|
387 |
+
s = fp.read(8)
|
388 |
+
offset = i32(s)
|
389 |
+
length = i32(s, 4)
|
390 |
+
else:
|
391 |
+
msg = "not an EPS file"
|
392 |
+
raise SyntaxError(msg)
|
393 |
+
|
394 |
+
return length, offset
|
395 |
+
|
396 |
+
def load(
|
397 |
+
self, scale: int = 1, transparency: bool = False
|
398 |
+
) -> Image.core.PixelAccess | None:
|
399 |
+
# Load EPS via Ghostscript
|
400 |
+
if self.tile:
|
401 |
+
self.im = Ghostscript(self.tile, self.size, self.fp, scale, transparency)
|
402 |
+
self._mode = self.im.mode
|
403 |
+
self._size = self.im.size
|
404 |
+
self.tile = []
|
405 |
+
return Image.Image.load(self)
|
406 |
+
|
407 |
+
def load_seek(self, pos: int) -> None:
|
408 |
+
# we can't incrementally load, so force ImageFile.parser to
|
409 |
+
# use our custom load method by defining this method.
|
410 |
+
pass
|
411 |
+
|
412 |
+
|
413 |
+
# --------------------------------------------------------------------
|
414 |
+
|
415 |
+
|
416 |
+
def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes, eps: int = 1) -> None:
|
417 |
+
"""EPS Writer for the Python Imaging Library."""
|
418 |
+
|
419 |
+
# make sure image data is available
|
420 |
+
im.load()
|
421 |
+
|
422 |
+
# determine PostScript image mode
|
423 |
+
if im.mode == "L":
|
424 |
+
operator = (8, 1, b"image")
|
425 |
+
elif im.mode == "RGB":
|
426 |
+
operator = (8, 3, b"false 3 colorimage")
|
427 |
+
elif im.mode == "CMYK":
|
428 |
+
operator = (8, 4, b"false 4 colorimage")
|
429 |
+
else:
|
430 |
+
msg = "image mode is not supported"
|
431 |
+
raise ValueError(msg)
|
432 |
+
|
433 |
+
if eps:
|
434 |
+
# write EPS header
|
435 |
+
fp.write(b"%!PS-Adobe-3.0 EPSF-3.0\n")
|
436 |
+
fp.write(b"%%Creator: PIL 0.1 EpsEncode\n")
|
437 |
+
# fp.write("%%CreationDate: %s"...)
|
438 |
+
fp.write(b"%%%%BoundingBox: 0 0 %d %d\n" % im.size)
|
439 |
+
fp.write(b"%%Pages: 1\n")
|
440 |
+
fp.write(b"%%EndComments\n")
|
441 |
+
fp.write(b"%%Page: 1 1\n")
|
442 |
+
fp.write(b"%%ImageData: %d %d " % im.size)
|
443 |
+
fp.write(b'%d %d 0 1 1 "%s"\n' % operator)
|
444 |
+
|
445 |
+
# image header
|
446 |
+
fp.write(b"gsave\n")
|
447 |
+
fp.write(b"10 dict begin\n")
|
448 |
+
fp.write(b"/buf %d string def\n" % (im.size[0] * operator[1]))
|
449 |
+
fp.write(b"%d %d scale\n" % im.size)
|
450 |
+
fp.write(b"%d %d 8\n" % im.size) # <= bits
|
451 |
+
fp.write(b"[%d 0 0 -%d 0 %d]\n" % (im.size[0], im.size[1], im.size[1]))
|
452 |
+
fp.write(b"{ currentfile buf readhexstring pop } bind\n")
|
453 |
+
fp.write(operator[2] + b"\n")
|
454 |
+
if hasattr(fp, "flush"):
|
455 |
+
fp.flush()
|
456 |
+
|
457 |
+
ImageFile._save(im, fp, [ImageFile._Tile("eps", (0, 0) + im.size)])
|
458 |
+
|
459 |
+
fp.write(b"\n%%%%EndBinary\n")
|
460 |
+
fp.write(b"grestore end\n")
|
461 |
+
if hasattr(fp, "flush"):
|
462 |
+
fp.flush()
|
463 |
+
|
464 |
+
|
465 |
+
# --------------------------------------------------------------------
|
466 |
+
|
467 |
+
|
468 |
+
Image.register_open(EpsImageFile.format, EpsImageFile, _accept)
|
469 |
+
|
470 |
+
Image.register_save(EpsImageFile.format, _save)
|
471 |
+
|
472 |
+
Image.register_extensions(EpsImageFile.format, [".ps", ".eps"])
|
473 |
+
|
474 |
+
Image.register_mime(EpsImageFile.format, "application/postscript")
|
env-my/Lib/site-packages/PIL/ExifTags.py
ADDED
@@ -0,0 +1,382 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#
|
2 |
+
# The Python Imaging Library.
|
3 |
+
# $Id$
|
4 |
+
#
|
5 |
+
# EXIF tags
|
6 |
+
#
|
7 |
+
# Copyright (c) 2003 by Secret Labs AB
|
8 |
+
#
|
9 |
+
# See the README file for information on usage and redistribution.
|
10 |
+
#
|
11 |
+
|
12 |
+
"""
|
13 |
+
This module provides constants and clear-text names for various
|
14 |
+
well-known EXIF tags.
|
15 |
+
"""
|
16 |
+
from __future__ import annotations
|
17 |
+
|
18 |
+
from enum import IntEnum
|
19 |
+
|
20 |
+
|
21 |
+
class Base(IntEnum):
|
22 |
+
# possibly incomplete
|
23 |
+
InteropIndex = 0x0001
|
24 |
+
ProcessingSoftware = 0x000B
|
25 |
+
NewSubfileType = 0x00FE
|
26 |
+
SubfileType = 0x00FF
|
27 |
+
ImageWidth = 0x0100
|
28 |
+
ImageLength = 0x0101
|
29 |
+
BitsPerSample = 0x0102
|
30 |
+
Compression = 0x0103
|
31 |
+
PhotometricInterpretation = 0x0106
|
32 |
+
Thresholding = 0x0107
|
33 |
+
CellWidth = 0x0108
|
34 |
+
CellLength = 0x0109
|
35 |
+
FillOrder = 0x010A
|
36 |
+
DocumentName = 0x010D
|
37 |
+
ImageDescription = 0x010E
|
38 |
+
Make = 0x010F
|
39 |
+
Model = 0x0110
|
40 |
+
StripOffsets = 0x0111
|
41 |
+
Orientation = 0x0112
|
42 |
+
SamplesPerPixel = 0x0115
|
43 |
+
RowsPerStrip = 0x0116
|
44 |
+
StripByteCounts = 0x0117
|
45 |
+
MinSampleValue = 0x0118
|
46 |
+
MaxSampleValue = 0x0119
|
47 |
+
XResolution = 0x011A
|
48 |
+
YResolution = 0x011B
|
49 |
+
PlanarConfiguration = 0x011C
|
50 |
+
PageName = 0x011D
|
51 |
+
FreeOffsets = 0x0120
|
52 |
+
FreeByteCounts = 0x0121
|
53 |
+
GrayResponseUnit = 0x0122
|
54 |
+
GrayResponseCurve = 0x0123
|
55 |
+
T4Options = 0x0124
|
56 |
+
T6Options = 0x0125
|
57 |
+
ResolutionUnit = 0x0128
|
58 |
+
PageNumber = 0x0129
|
59 |
+
TransferFunction = 0x012D
|
60 |
+
Software = 0x0131
|
61 |
+
DateTime = 0x0132
|
62 |
+
Artist = 0x013B
|
63 |
+
HostComputer = 0x013C
|
64 |
+
Predictor = 0x013D
|
65 |
+
WhitePoint = 0x013E
|
66 |
+
PrimaryChromaticities = 0x013F
|
67 |
+
ColorMap = 0x0140
|
68 |
+
HalftoneHints = 0x0141
|
69 |
+
TileWidth = 0x0142
|
70 |
+
TileLength = 0x0143
|
71 |
+
TileOffsets = 0x0144
|
72 |
+
TileByteCounts = 0x0145
|
73 |
+
SubIFDs = 0x014A
|
74 |
+
InkSet = 0x014C
|
75 |
+
InkNames = 0x014D
|
76 |
+
NumberOfInks = 0x014E
|
77 |
+
DotRange = 0x0150
|
78 |
+
TargetPrinter = 0x0151
|
79 |
+
ExtraSamples = 0x0152
|
80 |
+
SampleFormat = 0x0153
|
81 |
+
SMinSampleValue = 0x0154
|
82 |
+
SMaxSampleValue = 0x0155
|
83 |
+
TransferRange = 0x0156
|
84 |
+
ClipPath = 0x0157
|
85 |
+
XClipPathUnits = 0x0158
|
86 |
+
YClipPathUnits = 0x0159
|
87 |
+
Indexed = 0x015A
|
88 |
+
JPEGTables = 0x015B
|
89 |
+
OPIProxy = 0x015F
|
90 |
+
JPEGProc = 0x0200
|
91 |
+
JpegIFOffset = 0x0201
|
92 |
+
JpegIFByteCount = 0x0202
|
93 |
+
JpegRestartInterval = 0x0203
|
94 |
+
JpegLosslessPredictors = 0x0205
|
95 |
+
JpegPointTransforms = 0x0206
|
96 |
+
JpegQTables = 0x0207
|
97 |
+
JpegDCTables = 0x0208
|
98 |
+
JpegACTables = 0x0209
|
99 |
+
YCbCrCoefficients = 0x0211
|
100 |
+
YCbCrSubSampling = 0x0212
|
101 |
+
YCbCrPositioning = 0x0213
|
102 |
+
ReferenceBlackWhite = 0x0214
|
103 |
+
XMLPacket = 0x02BC
|
104 |
+
RelatedImageFileFormat = 0x1000
|
105 |
+
RelatedImageWidth = 0x1001
|
106 |
+
RelatedImageLength = 0x1002
|
107 |
+
Rating = 0x4746
|
108 |
+
RatingPercent = 0x4749
|
109 |
+
ImageID = 0x800D
|
110 |
+
CFARepeatPatternDim = 0x828D
|
111 |
+
BatteryLevel = 0x828F
|
112 |
+
Copyright = 0x8298
|
113 |
+
ExposureTime = 0x829A
|
114 |
+
FNumber = 0x829D
|
115 |
+
IPTCNAA = 0x83BB
|
116 |
+
ImageResources = 0x8649
|
117 |
+
ExifOffset = 0x8769
|
118 |
+
InterColorProfile = 0x8773
|
119 |
+
ExposureProgram = 0x8822
|
120 |
+
SpectralSensitivity = 0x8824
|
121 |
+
GPSInfo = 0x8825
|
122 |
+
ISOSpeedRatings = 0x8827
|
123 |
+
OECF = 0x8828
|
124 |
+
Interlace = 0x8829
|
125 |
+
TimeZoneOffset = 0x882A
|
126 |
+
SelfTimerMode = 0x882B
|
127 |
+
SensitivityType = 0x8830
|
128 |
+
StandardOutputSensitivity = 0x8831
|
129 |
+
RecommendedExposureIndex = 0x8832
|
130 |
+
ISOSpeed = 0x8833
|
131 |
+
ISOSpeedLatitudeyyy = 0x8834
|
132 |
+
ISOSpeedLatitudezzz = 0x8835
|
133 |
+
ExifVersion = 0x9000
|
134 |
+
DateTimeOriginal = 0x9003
|
135 |
+
DateTimeDigitized = 0x9004
|
136 |
+
OffsetTime = 0x9010
|
137 |
+
OffsetTimeOriginal = 0x9011
|
138 |
+
OffsetTimeDigitized = 0x9012
|
139 |
+
ComponentsConfiguration = 0x9101
|
140 |
+
CompressedBitsPerPixel = 0x9102
|
141 |
+
ShutterSpeedValue = 0x9201
|
142 |
+
ApertureValue = 0x9202
|
143 |
+
BrightnessValue = 0x9203
|
144 |
+
ExposureBiasValue = 0x9204
|
145 |
+
MaxApertureValue = 0x9205
|
146 |
+
SubjectDistance = 0x9206
|
147 |
+
MeteringMode = 0x9207
|
148 |
+
LightSource = 0x9208
|
149 |
+
Flash = 0x9209
|
150 |
+
FocalLength = 0x920A
|
151 |
+
Noise = 0x920D
|
152 |
+
ImageNumber = 0x9211
|
153 |
+
SecurityClassification = 0x9212
|
154 |
+
ImageHistory = 0x9213
|
155 |
+
TIFFEPStandardID = 0x9216
|
156 |
+
MakerNote = 0x927C
|
157 |
+
UserComment = 0x9286
|
158 |
+
SubsecTime = 0x9290
|
159 |
+
SubsecTimeOriginal = 0x9291
|
160 |
+
SubsecTimeDigitized = 0x9292
|
161 |
+
AmbientTemperature = 0x9400
|
162 |
+
Humidity = 0x9401
|
163 |
+
Pressure = 0x9402
|
164 |
+
WaterDepth = 0x9403
|
165 |
+
Acceleration = 0x9404
|
166 |
+
CameraElevationAngle = 0x9405
|
167 |
+
XPTitle = 0x9C9B
|
168 |
+
XPComment = 0x9C9C
|
169 |
+
XPAuthor = 0x9C9D
|
170 |
+
XPKeywords = 0x9C9E
|
171 |
+
XPSubject = 0x9C9F
|
172 |
+
FlashPixVersion = 0xA000
|
173 |
+
ColorSpace = 0xA001
|
174 |
+
ExifImageWidth = 0xA002
|
175 |
+
ExifImageHeight = 0xA003
|
176 |
+
RelatedSoundFile = 0xA004
|
177 |
+
ExifInteroperabilityOffset = 0xA005
|
178 |
+
FlashEnergy = 0xA20B
|
179 |
+
SpatialFrequencyResponse = 0xA20C
|
180 |
+
FocalPlaneXResolution = 0xA20E
|
181 |
+
FocalPlaneYResolution = 0xA20F
|
182 |
+
FocalPlaneResolutionUnit = 0xA210
|
183 |
+
SubjectLocation = 0xA214
|
184 |
+
ExposureIndex = 0xA215
|
185 |
+
SensingMethod = 0xA217
|
186 |
+
FileSource = 0xA300
|
187 |
+
SceneType = 0xA301
|
188 |
+
CFAPattern = 0xA302
|
189 |
+
CustomRendered = 0xA401
|
190 |
+
ExposureMode = 0xA402
|
191 |
+
WhiteBalance = 0xA403
|
192 |
+
DigitalZoomRatio = 0xA404
|
193 |
+
FocalLengthIn35mmFilm = 0xA405
|
194 |
+
SceneCaptureType = 0xA406
|
195 |
+
GainControl = 0xA407
|
196 |
+
Contrast = 0xA408
|
197 |
+
Saturation = 0xA409
|
198 |
+
Sharpness = 0xA40A
|
199 |
+
DeviceSettingDescription = 0xA40B
|
200 |
+
SubjectDistanceRange = 0xA40C
|
201 |
+
ImageUniqueID = 0xA420
|
202 |
+
CameraOwnerName = 0xA430
|
203 |
+
BodySerialNumber = 0xA431
|
204 |
+
LensSpecification = 0xA432
|
205 |
+
LensMake = 0xA433
|
206 |
+
LensModel = 0xA434
|
207 |
+
LensSerialNumber = 0xA435
|
208 |
+
CompositeImage = 0xA460
|
209 |
+
CompositeImageCount = 0xA461
|
210 |
+
CompositeImageExposureTimes = 0xA462
|
211 |
+
Gamma = 0xA500
|
212 |
+
PrintImageMatching = 0xC4A5
|
213 |
+
DNGVersion = 0xC612
|
214 |
+
DNGBackwardVersion = 0xC613
|
215 |
+
UniqueCameraModel = 0xC614
|
216 |
+
LocalizedCameraModel = 0xC615
|
217 |
+
CFAPlaneColor = 0xC616
|
218 |
+
CFALayout = 0xC617
|
219 |
+
LinearizationTable = 0xC618
|
220 |
+
BlackLevelRepeatDim = 0xC619
|
221 |
+
BlackLevel = 0xC61A
|
222 |
+
BlackLevelDeltaH = 0xC61B
|
223 |
+
BlackLevelDeltaV = 0xC61C
|
224 |
+
WhiteLevel = 0xC61D
|
225 |
+
DefaultScale = 0xC61E
|
226 |
+
DefaultCropOrigin = 0xC61F
|
227 |
+
DefaultCropSize = 0xC620
|
228 |
+
ColorMatrix1 = 0xC621
|
229 |
+
ColorMatrix2 = 0xC622
|
230 |
+
CameraCalibration1 = 0xC623
|
231 |
+
CameraCalibration2 = 0xC624
|
232 |
+
ReductionMatrix1 = 0xC625
|
233 |
+
ReductionMatrix2 = 0xC626
|
234 |
+
AnalogBalance = 0xC627
|
235 |
+
AsShotNeutral = 0xC628
|
236 |
+
AsShotWhiteXY = 0xC629
|
237 |
+
BaselineExposure = 0xC62A
|
238 |
+
BaselineNoise = 0xC62B
|
239 |
+
BaselineSharpness = 0xC62C
|
240 |
+
BayerGreenSplit = 0xC62D
|
241 |
+
LinearResponseLimit = 0xC62E
|
242 |
+
CameraSerialNumber = 0xC62F
|
243 |
+
LensInfo = 0xC630
|
244 |
+
ChromaBlurRadius = 0xC631
|
245 |
+
AntiAliasStrength = 0xC632
|
246 |
+
ShadowScale = 0xC633
|
247 |
+
DNGPrivateData = 0xC634
|
248 |
+
MakerNoteSafety = 0xC635
|
249 |
+
CalibrationIlluminant1 = 0xC65A
|
250 |
+
CalibrationIlluminant2 = 0xC65B
|
251 |
+
BestQualityScale = 0xC65C
|
252 |
+
RawDataUniqueID = 0xC65D
|
253 |
+
OriginalRawFileName = 0xC68B
|
254 |
+
OriginalRawFileData = 0xC68C
|
255 |
+
ActiveArea = 0xC68D
|
256 |
+
MaskedAreas = 0xC68E
|
257 |
+
AsShotICCProfile = 0xC68F
|
258 |
+
AsShotPreProfileMatrix = 0xC690
|
259 |
+
CurrentICCProfile = 0xC691
|
260 |
+
CurrentPreProfileMatrix = 0xC692
|
261 |
+
ColorimetricReference = 0xC6BF
|
262 |
+
CameraCalibrationSignature = 0xC6F3
|
263 |
+
ProfileCalibrationSignature = 0xC6F4
|
264 |
+
AsShotProfileName = 0xC6F6
|
265 |
+
NoiseReductionApplied = 0xC6F7
|
266 |
+
ProfileName = 0xC6F8
|
267 |
+
ProfileHueSatMapDims = 0xC6F9
|
268 |
+
ProfileHueSatMapData1 = 0xC6FA
|
269 |
+
ProfileHueSatMapData2 = 0xC6FB
|
270 |
+
ProfileToneCurve = 0xC6FC
|
271 |
+
ProfileEmbedPolicy = 0xC6FD
|
272 |
+
ProfileCopyright = 0xC6FE
|
273 |
+
ForwardMatrix1 = 0xC714
|
274 |
+
ForwardMatrix2 = 0xC715
|
275 |
+
PreviewApplicationName = 0xC716
|
276 |
+
PreviewApplicationVersion = 0xC717
|
277 |
+
PreviewSettingsName = 0xC718
|
278 |
+
PreviewSettingsDigest = 0xC719
|
279 |
+
PreviewColorSpace = 0xC71A
|
280 |
+
PreviewDateTime = 0xC71B
|
281 |
+
RawImageDigest = 0xC71C
|
282 |
+
OriginalRawFileDigest = 0xC71D
|
283 |
+
SubTileBlockSize = 0xC71E
|
284 |
+
RowInterleaveFactor = 0xC71F
|
285 |
+
ProfileLookTableDims = 0xC725
|
286 |
+
ProfileLookTableData = 0xC726
|
287 |
+
OpcodeList1 = 0xC740
|
288 |
+
OpcodeList2 = 0xC741
|
289 |
+
OpcodeList3 = 0xC74E
|
290 |
+
NoiseProfile = 0xC761
|
291 |
+
|
292 |
+
|
293 |
+
"""Maps EXIF tags to tag names."""
|
294 |
+
TAGS = {
|
295 |
+
**{i.value: i.name for i in Base},
|
296 |
+
0x920C: "SpatialFrequencyResponse",
|
297 |
+
0x9214: "SubjectLocation",
|
298 |
+
0x9215: "ExposureIndex",
|
299 |
+
0x828E: "CFAPattern",
|
300 |
+
0x920B: "FlashEnergy",
|
301 |
+
0x9216: "TIFF/EPStandardID",
|
302 |
+
}
|
303 |
+
|
304 |
+
|
305 |
+
class GPS(IntEnum):
|
306 |
+
GPSVersionID = 0x00
|
307 |
+
GPSLatitudeRef = 0x01
|
308 |
+
GPSLatitude = 0x02
|
309 |
+
GPSLongitudeRef = 0x03
|
310 |
+
GPSLongitude = 0x04
|
311 |
+
GPSAltitudeRef = 0x05
|
312 |
+
GPSAltitude = 0x06
|
313 |
+
GPSTimeStamp = 0x07
|
314 |
+
GPSSatellites = 0x08
|
315 |
+
GPSStatus = 0x09
|
316 |
+
GPSMeasureMode = 0x0A
|
317 |
+
GPSDOP = 0x0B
|
318 |
+
GPSSpeedRef = 0x0C
|
319 |
+
GPSSpeed = 0x0D
|
320 |
+
GPSTrackRef = 0x0E
|
321 |
+
GPSTrack = 0x0F
|
322 |
+
GPSImgDirectionRef = 0x10
|
323 |
+
GPSImgDirection = 0x11
|
324 |
+
GPSMapDatum = 0x12
|
325 |
+
GPSDestLatitudeRef = 0x13
|
326 |
+
GPSDestLatitude = 0x14
|
327 |
+
GPSDestLongitudeRef = 0x15
|
328 |
+
GPSDestLongitude = 0x16
|
329 |
+
GPSDestBearingRef = 0x17
|
330 |
+
GPSDestBearing = 0x18
|
331 |
+
GPSDestDistanceRef = 0x19
|
332 |
+
GPSDestDistance = 0x1A
|
333 |
+
GPSProcessingMethod = 0x1B
|
334 |
+
GPSAreaInformation = 0x1C
|
335 |
+
GPSDateStamp = 0x1D
|
336 |
+
GPSDifferential = 0x1E
|
337 |
+
GPSHPositioningError = 0x1F
|
338 |
+
|
339 |
+
|
340 |
+
"""Maps EXIF GPS tags to tag names."""
|
341 |
+
GPSTAGS = {i.value: i.name for i in GPS}
|
342 |
+
|
343 |
+
|
344 |
+
class Interop(IntEnum):
|
345 |
+
InteropIndex = 0x0001
|
346 |
+
InteropVersion = 0x0002
|
347 |
+
RelatedImageFileFormat = 0x1000
|
348 |
+
RelatedImageWidth = 0x1001
|
349 |
+
RelatedImageHeight = 0x1002
|
350 |
+
|
351 |
+
|
352 |
+
class IFD(IntEnum):
|
353 |
+
Exif = 0x8769
|
354 |
+
GPSInfo = 0x8825
|
355 |
+
MakerNote = 0x927C
|
356 |
+
Makernote = 0x927C # Deprecated
|
357 |
+
Interop = 0xA005
|
358 |
+
IFD1 = -1
|
359 |
+
|
360 |
+
|
361 |
+
class LightSource(IntEnum):
|
362 |
+
Unknown = 0x00
|
363 |
+
Daylight = 0x01
|
364 |
+
Fluorescent = 0x02
|
365 |
+
Tungsten = 0x03
|
366 |
+
Flash = 0x04
|
367 |
+
Fine = 0x09
|
368 |
+
Cloudy = 0x0A
|
369 |
+
Shade = 0x0B
|
370 |
+
DaylightFluorescent = 0x0C
|
371 |
+
DayWhiteFluorescent = 0x0D
|
372 |
+
CoolWhiteFluorescent = 0x0E
|
373 |
+
WhiteFluorescent = 0x0F
|
374 |
+
StandardLightA = 0x11
|
375 |
+
StandardLightB = 0x12
|
376 |
+
StandardLightC = 0x13
|
377 |
+
D55 = 0x14
|
378 |
+
D65 = 0x15
|
379 |
+
D75 = 0x16
|
380 |
+
D50 = 0x17
|
381 |
+
ISO = 0x18
|
382 |
+
Other = 0xFF
|
env-my/Lib/site-packages/PIL/FitsImagePlugin.py
ADDED
@@ -0,0 +1,152 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#
|
2 |
+
# The Python Imaging Library
|
3 |
+
# $Id$
|
4 |
+
#
|
5 |
+
# FITS file handling
|
6 |
+
#
|
7 |
+
# Copyright (c) 1998-2003 by Fredrik Lundh
|
8 |
+
#
|
9 |
+
# See the README file for information on usage and redistribution.
|
10 |
+
#
|
11 |
+
from __future__ import annotations
|
12 |
+
|
13 |
+
import gzip
|
14 |
+
import math
|
15 |
+
|
16 |
+
from . import Image, ImageFile
|
17 |
+
|
18 |
+
|
19 |
+
def _accept(prefix: bytes) -> bool:
|
20 |
+
return prefix[:6] == b"SIMPLE"
|
21 |
+
|
22 |
+
|
23 |
+
class FitsImageFile(ImageFile.ImageFile):
|
24 |
+
format = "FITS"
|
25 |
+
format_description = "FITS"
|
26 |
+
|
27 |
+
def _open(self) -> None:
|
28 |
+
assert self.fp is not None
|
29 |
+
|
30 |
+
headers: dict[bytes, bytes] = {}
|
31 |
+
header_in_progress = False
|
32 |
+
decoder_name = ""
|
33 |
+
while True:
|
34 |
+
header = self.fp.read(80)
|
35 |
+
if not header:
|
36 |
+
msg = "Truncated FITS file"
|
37 |
+
raise OSError(msg)
|
38 |
+
keyword = header[:8].strip()
|
39 |
+
if keyword in (b"SIMPLE", b"XTENSION"):
|
40 |
+
header_in_progress = True
|
41 |
+
elif headers and not header_in_progress:
|
42 |
+
# This is now a data unit
|
43 |
+
break
|
44 |
+
elif keyword == b"END":
|
45 |
+
# Seek to the end of the header unit
|
46 |
+
self.fp.seek(math.ceil(self.fp.tell() / 2880) * 2880)
|
47 |
+
if not decoder_name:
|
48 |
+
decoder_name, offset, args = self._parse_headers(headers)
|
49 |
+
|
50 |
+
header_in_progress = False
|
51 |
+
continue
|
52 |
+
|
53 |
+
if decoder_name:
|
54 |
+
# Keep going to read past the headers
|
55 |
+
continue
|
56 |
+
|
57 |
+
value = header[8:].split(b"/")[0].strip()
|
58 |
+
if value.startswith(b"="):
|
59 |
+
value = value[1:].strip()
|
60 |
+
if not headers and (not _accept(keyword) or value != b"T"):
|
61 |
+
msg = "Not a FITS file"
|
62 |
+
raise SyntaxError(msg)
|
63 |
+
headers[keyword] = value
|
64 |
+
|
65 |
+
if not decoder_name:
|
66 |
+
msg = "No image data"
|
67 |
+
raise ValueError(msg)
|
68 |
+
|
69 |
+
offset += self.fp.tell() - 80
|
70 |
+
self.tile = [ImageFile._Tile(decoder_name, (0, 0) + self.size, offset, args)]
|
71 |
+
|
72 |
+
def _get_size(
|
73 |
+
self, headers: dict[bytes, bytes], prefix: bytes
|
74 |
+
) -> tuple[int, int] | None:
|
75 |
+
naxis = int(headers[prefix + b"NAXIS"])
|
76 |
+
if naxis == 0:
|
77 |
+
return None
|
78 |
+
|
79 |
+
if naxis == 1:
|
80 |
+
return 1, int(headers[prefix + b"NAXIS1"])
|
81 |
+
else:
|
82 |
+
return int(headers[prefix + b"NAXIS1"]), int(headers[prefix + b"NAXIS2"])
|
83 |
+
|
84 |
+
def _parse_headers(
|
85 |
+
self, headers: dict[bytes, bytes]
|
86 |
+
) -> tuple[str, int, tuple[str | int, ...]]:
|
87 |
+
prefix = b""
|
88 |
+
decoder_name = "raw"
|
89 |
+
offset = 0
|
90 |
+
if (
|
91 |
+
headers.get(b"XTENSION") == b"'BINTABLE'"
|
92 |
+
and headers.get(b"ZIMAGE") == b"T"
|
93 |
+
and headers[b"ZCMPTYPE"] == b"'GZIP_1 '"
|
94 |
+
):
|
95 |
+
no_prefix_size = self._get_size(headers, prefix) or (0, 0)
|
96 |
+
number_of_bits = int(headers[b"BITPIX"])
|
97 |
+
offset = no_prefix_size[0] * no_prefix_size[1] * (number_of_bits // 8)
|
98 |
+
|
99 |
+
prefix = b"Z"
|
100 |
+
decoder_name = "fits_gzip"
|
101 |
+
|
102 |
+
size = self._get_size(headers, prefix)
|
103 |
+
if not size:
|
104 |
+
return "", 0, ()
|
105 |
+
|
106 |
+
self._size = size
|
107 |
+
|
108 |
+
number_of_bits = int(headers[prefix + b"BITPIX"])
|
109 |
+
if number_of_bits == 8:
|
110 |
+
self._mode = "L"
|
111 |
+
elif number_of_bits == 16:
|
112 |
+
self._mode = "I;16"
|
113 |
+
elif number_of_bits == 32:
|
114 |
+
self._mode = "I"
|
115 |
+
elif number_of_bits in (-32, -64):
|
116 |
+
self._mode = "F"
|
117 |
+
|
118 |
+
args: tuple[str | int, ...]
|
119 |
+
if decoder_name == "raw":
|
120 |
+
args = (self.mode, 0, -1)
|
121 |
+
else:
|
122 |
+
args = (number_of_bits,)
|
123 |
+
return decoder_name, offset, args
|
124 |
+
|
125 |
+
|
126 |
+
class FitsGzipDecoder(ImageFile.PyDecoder):
|
127 |
+
_pulls_fd = True
|
128 |
+
|
129 |
+
def decode(self, buffer: bytes | Image.SupportsArrayInterface) -> tuple[int, int]:
|
130 |
+
assert self.fd is not None
|
131 |
+
value = gzip.decompress(self.fd.read())
|
132 |
+
|
133 |
+
rows = []
|
134 |
+
offset = 0
|
135 |
+
number_of_bits = min(self.args[0] // 8, 4)
|
136 |
+
for y in range(self.state.ysize):
|
137 |
+
row = bytearray()
|
138 |
+
for x in range(self.state.xsize):
|
139 |
+
row += value[offset + (4 - number_of_bits) : offset + 4]
|
140 |
+
offset += 4
|
141 |
+
rows.append(row)
|
142 |
+
self.set_as_raw(bytes([pixel for row in rows[::-1] for pixel in row]))
|
143 |
+
return -1, 0
|
144 |
+
|
145 |
+
|
146 |
+
# --------------------------------------------------------------------
|
147 |
+
# Registry
|
148 |
+
|
149 |
+
Image.register_open(FitsImageFile.format, FitsImageFile, _accept)
|
150 |
+
Image.register_decoder("fits_gzip", FitsGzipDecoder)
|
151 |
+
|
152 |
+
Image.register_extensions(FitsImageFile.format, [".fit", ".fits"])
|
env-my/Lib/site-packages/PIL/FliImagePlugin.py
ADDED
@@ -0,0 +1,175 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#
|
2 |
+
# The Python Imaging Library.
|
3 |
+
# $Id$
|
4 |
+
#
|
5 |
+
# FLI/FLC file handling.
|
6 |
+
#
|
7 |
+
# History:
|
8 |
+
# 95-09-01 fl Created
|
9 |
+
# 97-01-03 fl Fixed parser, setup decoder tile
|
10 |
+
# 98-07-15 fl Renamed offset attribute to avoid name clash
|
11 |
+
#
|
12 |
+
# Copyright (c) Secret Labs AB 1997-98.
|
13 |
+
# Copyright (c) Fredrik Lundh 1995-97.
|
14 |
+
#
|
15 |
+
# See the README file for information on usage and redistribution.
|
16 |
+
#
|
17 |
+
from __future__ import annotations
|
18 |
+
|
19 |
+
import os
|
20 |
+
|
21 |
+
from . import Image, ImageFile, ImagePalette
|
22 |
+
from ._binary import i16le as i16
|
23 |
+
from ._binary import i32le as i32
|
24 |
+
from ._binary import o8
|
25 |
+
|
26 |
+
#
|
27 |
+
# decoder
|
28 |
+
|
29 |
+
|
30 |
+
def _accept(prefix: bytes) -> bool:
|
31 |
+
return (
|
32 |
+
len(prefix) >= 6
|
33 |
+
and i16(prefix, 4) in [0xAF11, 0xAF12]
|
34 |
+
and i16(prefix, 14) in [0, 3] # flags
|
35 |
+
)
|
36 |
+
|
37 |
+
|
38 |
+
##
|
39 |
+
# Image plugin for the FLI/FLC animation format. Use the <b>seek</b>
|
40 |
+
# method to load individual frames.
|
41 |
+
|
42 |
+
|
43 |
+
class FliImageFile(ImageFile.ImageFile):
|
44 |
+
format = "FLI"
|
45 |
+
format_description = "Autodesk FLI/FLC Animation"
|
46 |
+
_close_exclusive_fp_after_loading = False
|
47 |
+
|
48 |
+
def _open(self) -> None:
|
49 |
+
# HEAD
|
50 |
+
s = self.fp.read(128)
|
51 |
+
if not (_accept(s) and s[20:22] == b"\x00\x00"):
|
52 |
+
msg = "not an FLI/FLC file"
|
53 |
+
raise SyntaxError(msg)
|
54 |
+
|
55 |
+
# frames
|
56 |
+
self.n_frames = i16(s, 6)
|
57 |
+
self.is_animated = self.n_frames > 1
|
58 |
+
|
59 |
+
# image characteristics
|
60 |
+
self._mode = "P"
|
61 |
+
self._size = i16(s, 8), i16(s, 10)
|
62 |
+
|
63 |
+
# animation speed
|
64 |
+
duration = i32(s, 16)
|
65 |
+
magic = i16(s, 4)
|
66 |
+
if magic == 0xAF11:
|
67 |
+
duration = (duration * 1000) // 70
|
68 |
+
self.info["duration"] = duration
|
69 |
+
|
70 |
+
# look for palette
|
71 |
+
palette = [(a, a, a) for a in range(256)]
|
72 |
+
|
73 |
+
s = self.fp.read(16)
|
74 |
+
|
75 |
+
self.__offset = 128
|
76 |
+
|
77 |
+
if i16(s, 4) == 0xF100:
|
78 |
+
# prefix chunk; ignore it
|
79 |
+
self.__offset = self.__offset + i32(s)
|
80 |
+
self.fp.seek(self.__offset)
|
81 |
+
s = self.fp.read(16)
|
82 |
+
|
83 |
+
if i16(s, 4) == 0xF1FA:
|
84 |
+
# look for palette chunk
|
85 |
+
number_of_subchunks = i16(s, 6)
|
86 |
+
chunk_size: int | None = None
|
87 |
+
for _ in range(number_of_subchunks):
|
88 |
+
if chunk_size is not None:
|
89 |
+
self.fp.seek(chunk_size - 6, os.SEEK_CUR)
|
90 |
+
s = self.fp.read(6)
|
91 |
+
chunk_type = i16(s, 4)
|
92 |
+
if chunk_type in (4, 11):
|
93 |
+
self._palette(palette, 2 if chunk_type == 11 else 0)
|
94 |
+
break
|
95 |
+
chunk_size = i32(s)
|
96 |
+
if not chunk_size:
|
97 |
+
break
|
98 |
+
|
99 |
+
self.palette = ImagePalette.raw(
|
100 |
+
"RGB", b"".join(o8(r) + o8(g) + o8(b) for (r, g, b) in palette)
|
101 |
+
)
|
102 |
+
|
103 |
+
# set things up to decode first frame
|
104 |
+
self.__frame = -1
|
105 |
+
self._fp = self.fp
|
106 |
+
self.__rewind = self.fp.tell()
|
107 |
+
self.seek(0)
|
108 |
+
|
109 |
+
def _palette(self, palette: list[tuple[int, int, int]], shift: int) -> None:
|
110 |
+
# load palette
|
111 |
+
|
112 |
+
i = 0
|
113 |
+
for e in range(i16(self.fp.read(2))):
|
114 |
+
s = self.fp.read(2)
|
115 |
+
i = i + s[0]
|
116 |
+
n = s[1]
|
117 |
+
if n == 0:
|
118 |
+
n = 256
|
119 |
+
s = self.fp.read(n * 3)
|
120 |
+
for n in range(0, len(s), 3):
|
121 |
+
r = s[n] << shift
|
122 |
+
g = s[n + 1] << shift
|
123 |
+
b = s[n + 2] << shift
|
124 |
+
palette[i] = (r, g, b)
|
125 |
+
i += 1
|
126 |
+
|
127 |
+
def seek(self, frame: int) -> None:
|
128 |
+
if not self._seek_check(frame):
|
129 |
+
return
|
130 |
+
if frame < self.__frame:
|
131 |
+
self._seek(0)
|
132 |
+
|
133 |
+
for f in range(self.__frame + 1, frame + 1):
|
134 |
+
self._seek(f)
|
135 |
+
|
136 |
+
def _seek(self, frame: int) -> None:
|
137 |
+
if frame == 0:
|
138 |
+
self.__frame = -1
|
139 |
+
self._fp.seek(self.__rewind)
|
140 |
+
self.__offset = 128
|
141 |
+
else:
|
142 |
+
# ensure that the previous frame was loaded
|
143 |
+
self.load()
|
144 |
+
|
145 |
+
if frame != self.__frame + 1:
|
146 |
+
msg = f"cannot seek to frame {frame}"
|
147 |
+
raise ValueError(msg)
|
148 |
+
self.__frame = frame
|
149 |
+
|
150 |
+
# move to next frame
|
151 |
+
self.fp = self._fp
|
152 |
+
self.fp.seek(self.__offset)
|
153 |
+
|
154 |
+
s = self.fp.read(4)
|
155 |
+
if not s:
|
156 |
+
msg = "missing frame size"
|
157 |
+
raise EOFError(msg)
|
158 |
+
|
159 |
+
framesize = i32(s)
|
160 |
+
|
161 |
+
self.decodermaxblock = framesize
|
162 |
+
self.tile = [ImageFile._Tile("fli", (0, 0) + self.size, self.__offset)]
|
163 |
+
|
164 |
+
self.__offset += framesize
|
165 |
+
|
166 |
+
def tell(self) -> int:
|
167 |
+
return self.__frame
|
168 |
+
|
169 |
+
|
170 |
+
#
|
171 |
+
# registry
|
172 |
+
|
173 |
+
Image.register_open(FliImageFile.format, FliImageFile, _accept)
|
174 |
+
|
175 |
+
Image.register_extensions(FliImageFile.format, [".fli", ".flc"])
|
env-my/Lib/site-packages/PIL/FontFile.py
ADDED
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#
|
2 |
+
# The Python Imaging Library
|
3 |
+
# $Id$
|
4 |
+
#
|
5 |
+
# base class for raster font file parsers
|
6 |
+
#
|
7 |
+
# history:
|
8 |
+
# 1997-06-05 fl created
|
9 |
+
# 1997-08-19 fl restrict image width
|
10 |
+
#
|
11 |
+
# Copyright (c) 1997-1998 by Secret Labs AB
|
12 |
+
# Copyright (c) 1997-1998 by Fredrik Lundh
|
13 |
+
#
|
14 |
+
# See the README file for information on usage and redistribution.
|
15 |
+
#
|
16 |
+
from __future__ import annotations
|
17 |
+
|
18 |
+
import os
|
19 |
+
from typing import BinaryIO
|
20 |
+
|
21 |
+
from . import Image, _binary
|
22 |
+
|
23 |
+
WIDTH = 800
|
24 |
+
|
25 |
+
|
26 |
+
def puti16(
|
27 |
+
fp: BinaryIO, values: tuple[int, int, int, int, int, int, int, int, int, int]
|
28 |
+
) -> None:
|
29 |
+
"""Write network order (big-endian) 16-bit sequence"""
|
30 |
+
for v in values:
|
31 |
+
if v < 0:
|
32 |
+
v += 65536
|
33 |
+
fp.write(_binary.o16be(v))
|
34 |
+
|
35 |
+
|
36 |
+
class FontFile:
|
37 |
+
"""Base class for raster font file handlers."""
|
38 |
+
|
39 |
+
bitmap: Image.Image | None = None
|
40 |
+
|
41 |
+
def __init__(self) -> None:
|
42 |
+
self.info: dict[bytes, bytes | int] = {}
|
43 |
+
self.glyph: list[
|
44 |
+
tuple[
|
45 |
+
tuple[int, int],
|
46 |
+
tuple[int, int, int, int],
|
47 |
+
tuple[int, int, int, int],
|
48 |
+
Image.Image,
|
49 |
+
]
|
50 |
+
| None
|
51 |
+
] = [None] * 256
|
52 |
+
|
53 |
+
def __getitem__(self, ix: int) -> (
|
54 |
+
tuple[
|
55 |
+
tuple[int, int],
|
56 |
+
tuple[int, int, int, int],
|
57 |
+
tuple[int, int, int, int],
|
58 |
+
Image.Image,
|
59 |
+
]
|
60 |
+
| None
|
61 |
+
):
|
62 |
+
return self.glyph[ix]
|
63 |
+
|
64 |
+
def compile(self) -> None:
|
65 |
+
"""Create metrics and bitmap"""
|
66 |
+
|
67 |
+
if self.bitmap:
|
68 |
+
return
|
69 |
+
|
70 |
+
# create bitmap large enough to hold all data
|
71 |
+
h = w = maxwidth = 0
|
72 |
+
lines = 1
|
73 |
+
for glyph in self.glyph:
|
74 |
+
if glyph:
|
75 |
+
d, dst, src, im = glyph
|
76 |
+
h = max(h, src[3] - src[1])
|
77 |
+
w = w + (src[2] - src[0])
|
78 |
+
if w > WIDTH:
|
79 |
+
lines += 1
|
80 |
+
w = src[2] - src[0]
|
81 |
+
maxwidth = max(maxwidth, w)
|
82 |
+
|
83 |
+
xsize = maxwidth
|
84 |
+
ysize = lines * h
|
85 |
+
|
86 |
+
if xsize == 0 and ysize == 0:
|
87 |
+
return
|
88 |
+
|
89 |
+
self.ysize = h
|
90 |
+
|
91 |
+
# paste glyphs into bitmap
|
92 |
+
self.bitmap = Image.new("1", (xsize, ysize))
|
93 |
+
self.metrics: list[
|
94 |
+
tuple[tuple[int, int], tuple[int, int, int, int], tuple[int, int, int, int]]
|
95 |
+
| None
|
96 |
+
] = [None] * 256
|
97 |
+
x = y = 0
|
98 |
+
for i in range(256):
|
99 |
+
glyph = self[i]
|
100 |
+
if glyph:
|
101 |
+
d, dst, src, im = glyph
|
102 |
+
xx = src[2] - src[0]
|
103 |
+
x0, y0 = x, y
|
104 |
+
x = x + xx
|
105 |
+
if x > WIDTH:
|
106 |
+
x, y = 0, y + h
|
107 |
+
x0, y0 = x, y
|
108 |
+
x = xx
|
109 |
+
s = src[0] + x0, src[1] + y0, src[2] + x0, src[3] + y0
|
110 |
+
self.bitmap.paste(im.crop(src), s)
|
111 |
+
self.metrics[i] = d, dst, s
|
112 |
+
|
113 |
+
def save(self, filename: str) -> None:
|
114 |
+
"""Save font"""
|
115 |
+
|
116 |
+
self.compile()
|
117 |
+
|
118 |
+
# font data
|
119 |
+
if not self.bitmap:
|
120 |
+
msg = "No bitmap created"
|
121 |
+
raise ValueError(msg)
|
122 |
+
self.bitmap.save(os.path.splitext(filename)[0] + ".pbm", "PNG")
|
123 |
+
|
124 |
+
# font metrics
|
125 |
+
with open(os.path.splitext(filename)[0] + ".pil", "wb") as fp:
|
126 |
+
fp.write(b"PILfont\n")
|
127 |
+
fp.write(f";;;;;;{self.ysize};\n".encode("ascii")) # HACK!!!
|
128 |
+
fp.write(b"DATA\n")
|
129 |
+
for id in range(256):
|
130 |
+
m = self.metrics[id]
|
131 |
+
if not m:
|
132 |
+
puti16(fp, (0,) * 10)
|
133 |
+
else:
|
134 |
+
puti16(fp, m[0] + m[1] + m[2])
|
env-my/Lib/site-packages/PIL/FpxImagePlugin.py
ADDED
@@ -0,0 +1,257 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#
|
2 |
+
# THIS IS WORK IN PROGRESS
|
3 |
+
#
|
4 |
+
# The Python Imaging Library.
|
5 |
+
# $Id$
|
6 |
+
#
|
7 |
+
# FlashPix support for PIL
|
8 |
+
#
|
9 |
+
# History:
|
10 |
+
# 97-01-25 fl Created (reads uncompressed RGB images only)
|
11 |
+
#
|
12 |
+
# Copyright (c) Secret Labs AB 1997.
|
13 |
+
# Copyright (c) Fredrik Lundh 1997.
|
14 |
+
#
|
15 |
+
# See the README file for information on usage and redistribution.
|
16 |
+
#
|
17 |
+
from __future__ import annotations
|
18 |
+
|
19 |
+
import olefile
|
20 |
+
|
21 |
+
from . import Image, ImageFile
|
22 |
+
from ._binary import i32le as i32
|
23 |
+
|
24 |
+
# we map from colour field tuples to (mode, rawmode) descriptors
|
25 |
+
MODES = {
|
26 |
+
# opacity
|
27 |
+
(0x00007FFE,): ("A", "L"),
|
28 |
+
# monochrome
|
29 |
+
(0x00010000,): ("L", "L"),
|
30 |
+
(0x00018000, 0x00017FFE): ("RGBA", "LA"),
|
31 |
+
# photo YCC
|
32 |
+
(0x00020000, 0x00020001, 0x00020002): ("RGB", "YCC;P"),
|
33 |
+
(0x00028000, 0x00028001, 0x00028002, 0x00027FFE): ("RGBA", "YCCA;P"),
|
34 |
+
# standard RGB (NIFRGB)
|
35 |
+
(0x00030000, 0x00030001, 0x00030002): ("RGB", "RGB"),
|
36 |
+
(0x00038000, 0x00038001, 0x00038002, 0x00037FFE): ("RGBA", "RGBA"),
|
37 |
+
}
|
38 |
+
|
39 |
+
|
40 |
+
#
|
41 |
+
# --------------------------------------------------------------------
|
42 |
+
|
43 |
+
|
44 |
+
def _accept(prefix: bytes) -> bool:
|
45 |
+
return prefix[:8] == olefile.MAGIC
|
46 |
+
|
47 |
+
|
48 |
+
##
|
49 |
+
# Image plugin for the FlashPix images.
|
50 |
+
|
51 |
+
|
52 |
+
class FpxImageFile(ImageFile.ImageFile):
|
53 |
+
format = "FPX"
|
54 |
+
format_description = "FlashPix"
|
55 |
+
|
56 |
+
def _open(self) -> None:
|
57 |
+
#
|
58 |
+
# read the OLE directory and see if this is a likely
|
59 |
+
# to be a FlashPix file
|
60 |
+
|
61 |
+
try:
|
62 |
+
self.ole = olefile.OleFileIO(self.fp)
|
63 |
+
except OSError as e:
|
64 |
+
msg = "not an FPX file; invalid OLE file"
|
65 |
+
raise SyntaxError(msg) from e
|
66 |
+
|
67 |
+
root = self.ole.root
|
68 |
+
if not root or root.clsid != "56616700-C154-11CE-8553-00AA00A1F95B":
|
69 |
+
msg = "not an FPX file; bad root CLSID"
|
70 |
+
raise SyntaxError(msg)
|
71 |
+
|
72 |
+
self._open_index(1)
|
73 |
+
|
74 |
+
def _open_index(self, index: int = 1) -> None:
|
75 |
+
#
|
76 |
+
# get the Image Contents Property Set
|
77 |
+
|
78 |
+
prop = self.ole.getproperties(
|
79 |
+
[f"Data Object Store {index:06d}", "\005Image Contents"]
|
80 |
+
)
|
81 |
+
|
82 |
+
# size (highest resolution)
|
83 |
+
|
84 |
+
assert isinstance(prop[0x1000002], int)
|
85 |
+
assert isinstance(prop[0x1000003], int)
|
86 |
+
self._size = prop[0x1000002], prop[0x1000003]
|
87 |
+
|
88 |
+
size = max(self.size)
|
89 |
+
i = 1
|
90 |
+
while size > 64:
|
91 |
+
size = size // 2
|
92 |
+
i += 1
|
93 |
+
self.maxid = i - 1
|
94 |
+
|
95 |
+
# mode. instead of using a single field for this, flashpix
|
96 |
+
# requires you to specify the mode for each channel in each
|
97 |
+
# resolution subimage, and leaves it to the decoder to make
|
98 |
+
# sure that they all match. for now, we'll cheat and assume
|
99 |
+
# that this is always the case.
|
100 |
+
|
101 |
+
id = self.maxid << 16
|
102 |
+
|
103 |
+
s = prop[0x2000002 | id]
|
104 |
+
|
105 |
+
if not isinstance(s, bytes) or (bands := i32(s, 4)) > 4:
|
106 |
+
msg = "Invalid number of bands"
|
107 |
+
raise OSError(msg)
|
108 |
+
|
109 |
+
# note: for now, we ignore the "uncalibrated" flag
|
110 |
+
colors = tuple(i32(s, 8 + i * 4) & 0x7FFFFFFF for i in range(bands))
|
111 |
+
|
112 |
+
self._mode, self.rawmode = MODES[colors]
|
113 |
+
|
114 |
+
# load JPEG tables, if any
|
115 |
+
self.jpeg = {}
|
116 |
+
for i in range(256):
|
117 |
+
id = 0x3000001 | (i << 16)
|
118 |
+
if id in prop:
|
119 |
+
self.jpeg[i] = prop[id]
|
120 |
+
|
121 |
+
self._open_subimage(1, self.maxid)
|
122 |
+
|
123 |
+
def _open_subimage(self, index: int = 1, subimage: int = 0) -> None:
|
124 |
+
#
|
125 |
+
# setup tile descriptors for a given subimage
|
126 |
+
|
127 |
+
stream = [
|
128 |
+
f"Data Object Store {index:06d}",
|
129 |
+
f"Resolution {subimage:04d}",
|
130 |
+
"Subimage 0000 Header",
|
131 |
+
]
|
132 |
+
|
133 |
+
fp = self.ole.openstream(stream)
|
134 |
+
|
135 |
+
# skip prefix
|
136 |
+
fp.read(28)
|
137 |
+
|
138 |
+
# header stream
|
139 |
+
s = fp.read(36)
|
140 |
+
|
141 |
+
size = i32(s, 4), i32(s, 8)
|
142 |
+
# tilecount = i32(s, 12)
|
143 |
+
tilesize = i32(s, 16), i32(s, 20)
|
144 |
+
# channels = i32(s, 24)
|
145 |
+
offset = i32(s, 28)
|
146 |
+
length = i32(s, 32)
|
147 |
+
|
148 |
+
if size != self.size:
|
149 |
+
msg = "subimage mismatch"
|
150 |
+
raise OSError(msg)
|
151 |
+
|
152 |
+
# get tile descriptors
|
153 |
+
fp.seek(28 + offset)
|
154 |
+
s = fp.read(i32(s, 12) * length)
|
155 |
+
|
156 |
+
x = y = 0
|
157 |
+
xsize, ysize = size
|
158 |
+
xtile, ytile = tilesize
|
159 |
+
self.tile = []
|
160 |
+
|
161 |
+
for i in range(0, len(s), length):
|
162 |
+
x1 = min(xsize, x + xtile)
|
163 |
+
y1 = min(ysize, y + ytile)
|
164 |
+
|
165 |
+
compression = i32(s, i + 8)
|
166 |
+
|
167 |
+
if compression == 0:
|
168 |
+
self.tile.append(
|
169 |
+
ImageFile._Tile(
|
170 |
+
"raw",
|
171 |
+
(x, y, x1, y1),
|
172 |
+
i32(s, i) + 28,
|
173 |
+
self.rawmode,
|
174 |
+
)
|
175 |
+
)
|
176 |
+
|
177 |
+
elif compression == 1:
|
178 |
+
# FIXME: the fill decoder is not implemented
|
179 |
+
self.tile.append(
|
180 |
+
ImageFile._Tile(
|
181 |
+
"fill",
|
182 |
+
(x, y, x1, y1),
|
183 |
+
i32(s, i) + 28,
|
184 |
+
(self.rawmode, s[12:16]),
|
185 |
+
)
|
186 |
+
)
|
187 |
+
|
188 |
+
elif compression == 2:
|
189 |
+
internal_color_conversion = s[14]
|
190 |
+
jpeg_tables = s[15]
|
191 |
+
rawmode = self.rawmode
|
192 |
+
|
193 |
+
if internal_color_conversion:
|
194 |
+
# The image is stored as usual (usually YCbCr).
|
195 |
+
if rawmode == "RGBA":
|
196 |
+
# For "RGBA", data is stored as YCbCrA based on
|
197 |
+
# negative RGB. The following trick works around
|
198 |
+
# this problem :
|
199 |
+
jpegmode, rawmode = "YCbCrK", "CMYK"
|
200 |
+
else:
|
201 |
+
jpegmode = None # let the decoder decide
|
202 |
+
|
203 |
+
else:
|
204 |
+
# The image is stored as defined by rawmode
|
205 |
+
jpegmode = rawmode
|
206 |
+
|
207 |
+
self.tile.append(
|
208 |
+
ImageFile._Tile(
|
209 |
+
"jpeg",
|
210 |
+
(x, y, x1, y1),
|
211 |
+
i32(s, i) + 28,
|
212 |
+
(rawmode, jpegmode),
|
213 |
+
)
|
214 |
+
)
|
215 |
+
|
216 |
+
# FIXME: jpeg tables are tile dependent; the prefix
|
217 |
+
# data must be placed in the tile descriptor itself!
|
218 |
+
|
219 |
+
if jpeg_tables:
|
220 |
+
self.tile_prefix = self.jpeg[jpeg_tables]
|
221 |
+
|
222 |
+
else:
|
223 |
+
msg = "unknown/invalid compression"
|
224 |
+
raise OSError(msg)
|
225 |
+
|
226 |
+
x = x + xtile
|
227 |
+
if x >= xsize:
|
228 |
+
x, y = 0, y + ytile
|
229 |
+
if y >= ysize:
|
230 |
+
break # isn't really required
|
231 |
+
|
232 |
+
self.stream = stream
|
233 |
+
self._fp = self.fp
|
234 |
+
self.fp = None
|
235 |
+
|
236 |
+
def load(self) -> Image.core.PixelAccess | None:
|
237 |
+
if not self.fp:
|
238 |
+
self.fp = self.ole.openstream(self.stream[:2] + ["Subimage 0000 Data"])
|
239 |
+
|
240 |
+
return ImageFile.ImageFile.load(self)
|
241 |
+
|
242 |
+
def close(self) -> None:
|
243 |
+
self.ole.close()
|
244 |
+
super().close()
|
245 |
+
|
246 |
+
def __exit__(self, *args: object) -> None:
|
247 |
+
self.ole.close()
|
248 |
+
super().__exit__()
|
249 |
+
|
250 |
+
|
251 |
+
#
|
252 |
+
# --------------------------------------------------------------------
|
253 |
+
|
254 |
+
|
255 |
+
Image.register_open(FpxImageFile.format, FpxImageFile, _accept)
|
256 |
+
|
257 |
+
Image.register_extension(FpxImageFile.format, ".fpx")
|
env-my/Lib/site-packages/PIL/FtexImagePlugin.py
ADDED
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
A Pillow loader for .ftc and .ftu files (FTEX)
|
3 |
+
Jerome Leclanche <[email protected]>
|
4 |
+
|
5 |
+
The contents of this file are hereby released in the public domain (CC0)
|
6 |
+
Full text of the CC0 license:
|
7 |
+
https://creativecommons.org/publicdomain/zero/1.0/
|
8 |
+
|
9 |
+
Independence War 2: Edge Of Chaos - Texture File Format - 16 October 2001
|
10 |
+
|
11 |
+
The textures used for 3D objects in Independence War 2: Edge Of Chaos are in a
|
12 |
+
packed custom format called FTEX. This file format uses file extensions FTC
|
13 |
+
and FTU.
|
14 |
+
* FTC files are compressed textures (using standard texture compression).
|
15 |
+
* FTU files are not compressed.
|
16 |
+
Texture File Format
|
17 |
+
The FTC and FTU texture files both use the same format. This
|
18 |
+
has the following structure:
|
19 |
+
{header}
|
20 |
+
{format_directory}
|
21 |
+
{data}
|
22 |
+
Where:
|
23 |
+
{header} = {
|
24 |
+
u32:magic,
|
25 |
+
u32:version,
|
26 |
+
u32:width,
|
27 |
+
u32:height,
|
28 |
+
u32:mipmap_count,
|
29 |
+
u32:format_count
|
30 |
+
}
|
31 |
+
|
32 |
+
* The "magic" number is "FTEX".
|
33 |
+
* "width" and "height" are the dimensions of the texture.
|
34 |
+
* "mipmap_count" is the number of mipmaps in the texture.
|
35 |
+
* "format_count" is the number of texture formats (different versions of the
|
36 |
+
same texture) in this file.
|
37 |
+
|
38 |
+
{format_directory} = format_count * { u32:format, u32:where }
|
39 |
+
|
40 |
+
The format value is 0 for DXT1 compressed textures and 1 for 24-bit RGB
|
41 |
+
uncompressed textures.
|
42 |
+
The texture data for a format starts at the position "where" in the file.
|
43 |
+
|
44 |
+
Each set of texture data in the file has the following structure:
|
45 |
+
{data} = format_count * { u32:mipmap_size, mipmap_size * { u8 } }
|
46 |
+
* "mipmap_size" is the number of bytes in that mip level. For compressed
|
47 |
+
textures this is the size of the texture data compressed with DXT1. For 24 bit
|
48 |
+
uncompressed textures, this is 3 * width * height. Following this are the image
|
49 |
+
bytes for that mipmap level.
|
50 |
+
|
51 |
+
Note: All data is stored in little-Endian (Intel) byte order.
|
52 |
+
"""
|
53 |
+
|
54 |
+
from __future__ import annotations
|
55 |
+
|
56 |
+
import struct
|
57 |
+
from enum import IntEnum
|
58 |
+
from io import BytesIO
|
59 |
+
|
60 |
+
from . import Image, ImageFile
|
61 |
+
|
62 |
+
MAGIC = b"FTEX"
|
63 |
+
|
64 |
+
|
65 |
+
class Format(IntEnum):
|
66 |
+
DXT1 = 0
|
67 |
+
UNCOMPRESSED = 1
|
68 |
+
|
69 |
+
|
70 |
+
class FtexImageFile(ImageFile.ImageFile):
|
71 |
+
format = "FTEX"
|
72 |
+
format_description = "Texture File Format (IW2:EOC)"
|
73 |
+
|
74 |
+
def _open(self) -> None:
|
75 |
+
if not _accept(self.fp.read(4)):
|
76 |
+
msg = "not an FTEX file"
|
77 |
+
raise SyntaxError(msg)
|
78 |
+
struct.unpack("<i", self.fp.read(4)) # version
|
79 |
+
self._size = struct.unpack("<2i", self.fp.read(8))
|
80 |
+
mipmap_count, format_count = struct.unpack("<2i", self.fp.read(8))
|
81 |
+
|
82 |
+
self._mode = "RGB"
|
83 |
+
|
84 |
+
# Only support single-format files.
|
85 |
+
# I don't know of any multi-format file.
|
86 |
+
assert format_count == 1
|
87 |
+
|
88 |
+
format, where = struct.unpack("<2i", self.fp.read(8))
|
89 |
+
self.fp.seek(where)
|
90 |
+
(mipmap_size,) = struct.unpack("<i", self.fp.read(4))
|
91 |
+
|
92 |
+
data = self.fp.read(mipmap_size)
|
93 |
+
|
94 |
+
if format == Format.DXT1:
|
95 |
+
self._mode = "RGBA"
|
96 |
+
self.tile = [ImageFile._Tile("bcn", (0, 0) + self.size, 0, (1,))]
|
97 |
+
elif format == Format.UNCOMPRESSED:
|
98 |
+
self.tile = [ImageFile._Tile("raw", (0, 0) + self.size, 0, "RGB")]
|
99 |
+
else:
|
100 |
+
msg = f"Invalid texture compression format: {repr(format)}"
|
101 |
+
raise ValueError(msg)
|
102 |
+
|
103 |
+
self.fp.close()
|
104 |
+
self.fp = BytesIO(data)
|
105 |
+
|
106 |
+
def load_seek(self, pos: int) -> None:
|
107 |
+
pass
|
108 |
+
|
109 |
+
|
110 |
+
def _accept(prefix: bytes) -> bool:
|
111 |
+
return prefix[:4] == MAGIC
|
112 |
+
|
113 |
+
|
114 |
+
Image.register_open(FtexImageFile.format, FtexImageFile, _accept)
|
115 |
+
Image.register_extensions(FtexImageFile.format, [".ftc", ".ftu"])
|
env-my/Lib/site-packages/PIL/GbrImagePlugin.py
ADDED
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#
|
2 |
+
# The Python Imaging Library
|
3 |
+
#
|
4 |
+
# load a GIMP brush file
|
5 |
+
#
|
6 |
+
# History:
|
7 |
+
# 96-03-14 fl Created
|
8 |
+
# 16-01-08 es Version 2
|
9 |
+
#
|
10 |
+
# Copyright (c) Secret Labs AB 1997.
|
11 |
+
# Copyright (c) Fredrik Lundh 1996.
|
12 |
+
# Copyright (c) Eric Soroos 2016.
|
13 |
+
#
|
14 |
+
# See the README file for information on usage and redistribution.
|
15 |
+
#
|
16 |
+
#
|
17 |
+
# See https://github.com/GNOME/gimp/blob/mainline/devel-docs/gbr.txt for
|
18 |
+
# format documentation.
|
19 |
+
#
|
20 |
+
# This code Interprets version 1 and 2 .gbr files.
|
21 |
+
# Version 1 files are obsolete, and should not be used for new
|
22 |
+
# brushes.
|
23 |
+
# Version 2 files are saved by GIMP v2.8 (at least)
|
24 |
+
# Version 3 files have a format specifier of 18 for 16bit floats in
|
25 |
+
# the color depth field. This is currently unsupported by Pillow.
|
26 |
+
from __future__ import annotations
|
27 |
+
|
28 |
+
from . import Image, ImageFile
|
29 |
+
from ._binary import i32be as i32
|
30 |
+
|
31 |
+
|
32 |
+
def _accept(prefix: bytes) -> bool:
|
33 |
+
return len(prefix) >= 8 and i32(prefix, 0) >= 20 and i32(prefix, 4) in (1, 2)
|
34 |
+
|
35 |
+
|
36 |
+
##
|
37 |
+
# Image plugin for the GIMP brush format.
|
38 |
+
|
39 |
+
|
40 |
+
class GbrImageFile(ImageFile.ImageFile):
|
41 |
+
format = "GBR"
|
42 |
+
format_description = "GIMP brush file"
|
43 |
+
|
44 |
+
def _open(self) -> None:
|
45 |
+
header_size = i32(self.fp.read(4))
|
46 |
+
if header_size < 20:
|
47 |
+
msg = "not a GIMP brush"
|
48 |
+
raise SyntaxError(msg)
|
49 |
+
version = i32(self.fp.read(4))
|
50 |
+
if version not in (1, 2):
|
51 |
+
msg = f"Unsupported GIMP brush version: {version}"
|
52 |
+
raise SyntaxError(msg)
|
53 |
+
|
54 |
+
width = i32(self.fp.read(4))
|
55 |
+
height = i32(self.fp.read(4))
|
56 |
+
color_depth = i32(self.fp.read(4))
|
57 |
+
if width <= 0 or height <= 0:
|
58 |
+
msg = "not a GIMP brush"
|
59 |
+
raise SyntaxError(msg)
|
60 |
+
if color_depth not in (1, 4):
|
61 |
+
msg = f"Unsupported GIMP brush color depth: {color_depth}"
|
62 |
+
raise SyntaxError(msg)
|
63 |
+
|
64 |
+
if version == 1:
|
65 |
+
comment_length = header_size - 20
|
66 |
+
else:
|
67 |
+
comment_length = header_size - 28
|
68 |
+
magic_number = self.fp.read(4)
|
69 |
+
if magic_number != b"GIMP":
|
70 |
+
msg = "not a GIMP brush, bad magic number"
|
71 |
+
raise SyntaxError(msg)
|
72 |
+
self.info["spacing"] = i32(self.fp.read(4))
|
73 |
+
|
74 |
+
comment = self.fp.read(comment_length)[:-1]
|
75 |
+
|
76 |
+
if color_depth == 1:
|
77 |
+
self._mode = "L"
|
78 |
+
else:
|
79 |
+
self._mode = "RGBA"
|
80 |
+
|
81 |
+
self._size = width, height
|
82 |
+
|
83 |
+
self.info["comment"] = comment
|
84 |
+
|
85 |
+
# Image might not be small
|
86 |
+
Image._decompression_bomb_check(self.size)
|
87 |
+
|
88 |
+
# Data is an uncompressed block of w * h * bytes/pixel
|
89 |
+
self._data_size = width * height * color_depth
|
90 |
+
|
91 |
+
def load(self) -> Image.core.PixelAccess | None:
|
92 |
+
if self._im is None:
|
93 |
+
self.im = Image.core.new(self.mode, self.size)
|
94 |
+
self.frombytes(self.fp.read(self._data_size))
|
95 |
+
return Image.Image.load(self)
|
96 |
+
|
97 |
+
|
98 |
+
#
|
99 |
+
# registry
|
100 |
+
|
101 |
+
|
102 |
+
Image.register_open(GbrImageFile.format, GbrImageFile, _accept)
|
103 |
+
Image.register_extension(GbrImageFile.format, ".gbr")
|
env-my/Lib/site-packages/PIL/GdImageFile.py
ADDED
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#
|
2 |
+
# The Python Imaging Library.
|
3 |
+
# $Id$
|
4 |
+
#
|
5 |
+
# GD file handling
|
6 |
+
#
|
7 |
+
# History:
|
8 |
+
# 1996-04-12 fl Created
|
9 |
+
#
|
10 |
+
# Copyright (c) 1997 by Secret Labs AB.
|
11 |
+
# Copyright (c) 1996 by Fredrik Lundh.
|
12 |
+
#
|
13 |
+
# See the README file for information on usage and redistribution.
|
14 |
+
#
|
15 |
+
|
16 |
+
|
17 |
+
"""
|
18 |
+
.. note::
|
19 |
+
This format cannot be automatically recognized, so the
|
20 |
+
class is not registered for use with :py:func:`PIL.Image.open()`. To open a
|
21 |
+
gd file, use the :py:func:`PIL.GdImageFile.open()` function instead.
|
22 |
+
|
23 |
+
.. warning::
|
24 |
+
THE GD FORMAT IS NOT DESIGNED FOR DATA INTERCHANGE. This
|
25 |
+
implementation is provided for convenience and demonstrational
|
26 |
+
purposes only.
|
27 |
+
"""
|
28 |
+
from __future__ import annotations
|
29 |
+
|
30 |
+
from typing import IO
|
31 |
+
|
32 |
+
from . import ImageFile, ImagePalette, UnidentifiedImageError
|
33 |
+
from ._binary import i16be as i16
|
34 |
+
from ._binary import i32be as i32
|
35 |
+
from ._typing import StrOrBytesPath
|
36 |
+
|
37 |
+
|
38 |
+
class GdImageFile(ImageFile.ImageFile):
|
39 |
+
"""
|
40 |
+
Image plugin for the GD uncompressed format. Note that this format
|
41 |
+
is not supported by the standard :py:func:`PIL.Image.open()` function. To use
|
42 |
+
this plugin, you have to import the :py:mod:`PIL.GdImageFile` module and
|
43 |
+
use the :py:func:`PIL.GdImageFile.open()` function.
|
44 |
+
"""
|
45 |
+
|
46 |
+
format = "GD"
|
47 |
+
format_description = "GD uncompressed images"
|
48 |
+
|
49 |
+
def _open(self) -> None:
|
50 |
+
# Header
|
51 |
+
assert self.fp is not None
|
52 |
+
|
53 |
+
s = self.fp.read(1037)
|
54 |
+
|
55 |
+
if i16(s) not in [65534, 65535]:
|
56 |
+
msg = "Not a valid GD 2.x .gd file"
|
57 |
+
raise SyntaxError(msg)
|
58 |
+
|
59 |
+
self._mode = "L" # FIXME: "P"
|
60 |
+
self._size = i16(s, 2), i16(s, 4)
|
61 |
+
|
62 |
+
true_color = s[6]
|
63 |
+
true_color_offset = 2 if true_color else 0
|
64 |
+
|
65 |
+
# transparency index
|
66 |
+
tindex = i32(s, 7 + true_color_offset)
|
67 |
+
if tindex < 256:
|
68 |
+
self.info["transparency"] = tindex
|
69 |
+
|
70 |
+
self.palette = ImagePalette.raw(
|
71 |
+
"XBGR", s[7 + true_color_offset + 4 : 7 + true_color_offset + 4 + 256 * 4]
|
72 |
+
)
|
73 |
+
|
74 |
+
self.tile = [
|
75 |
+
ImageFile._Tile(
|
76 |
+
"raw",
|
77 |
+
(0, 0) + self.size,
|
78 |
+
7 + true_color_offset + 4 + 256 * 4,
|
79 |
+
"L",
|
80 |
+
)
|
81 |
+
]
|
82 |
+
|
83 |
+
|
84 |
+
def open(fp: StrOrBytesPath | IO[bytes], mode: str = "r") -> GdImageFile:
|
85 |
+
"""
|
86 |
+
Load texture from a GD image file.
|
87 |
+
|
88 |
+
:param fp: GD file name, or an opened file handle.
|
89 |
+
:param mode: Optional mode. In this version, if the mode argument
|
90 |
+
is given, it must be "r".
|
91 |
+
:returns: An image instance.
|
92 |
+
:raises OSError: If the image could not be read.
|
93 |
+
"""
|
94 |
+
if mode != "r":
|
95 |
+
msg = "bad mode"
|
96 |
+
raise ValueError(msg)
|
97 |
+
|
98 |
+
try:
|
99 |
+
return GdImageFile(fp)
|
100 |
+
except SyntaxError as e:
|
101 |
+
msg = "cannot identify this image file"
|
102 |
+
raise UnidentifiedImageError(msg) from e
|
env-my/Lib/site-packages/PIL/GifImagePlugin.py
ADDED
@@ -0,0 +1,1197 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#
|
2 |
+
# The Python Imaging Library.
|
3 |
+
# $Id$
|
4 |
+
#
|
5 |
+
# GIF file handling
|
6 |
+
#
|
7 |
+
# History:
|
8 |
+
# 1995-09-01 fl Created
|
9 |
+
# 1996-12-14 fl Added interlace support
|
10 |
+
# 1996-12-30 fl Added animation support
|
11 |
+
# 1997-01-05 fl Added write support, fixed local colour map bug
|
12 |
+
# 1997-02-23 fl Make sure to load raster data in getdata()
|
13 |
+
# 1997-07-05 fl Support external decoder (0.4)
|
14 |
+
# 1998-07-09 fl Handle all modes when saving (0.5)
|
15 |
+
# 1998-07-15 fl Renamed offset attribute to avoid name clash
|
16 |
+
# 2001-04-16 fl Added rewind support (seek to frame 0) (0.6)
|
17 |
+
# 2001-04-17 fl Added palette optimization (0.7)
|
18 |
+
# 2002-06-06 fl Added transparency support for save (0.8)
|
19 |
+
# 2004-02-24 fl Disable interlacing for small images
|
20 |
+
#
|
21 |
+
# Copyright (c) 1997-2004 by Secret Labs AB
|
22 |
+
# Copyright (c) 1995-2004 by Fredrik Lundh
|
23 |
+
#
|
24 |
+
# See the README file for information on usage and redistribution.
|
25 |
+
#
|
26 |
+
from __future__ import annotations
|
27 |
+
|
28 |
+
import itertools
|
29 |
+
import math
|
30 |
+
import os
|
31 |
+
import subprocess
|
32 |
+
from enum import IntEnum
|
33 |
+
from functools import cached_property
|
34 |
+
from typing import IO, TYPE_CHECKING, Any, Literal, NamedTuple, Union
|
35 |
+
|
36 |
+
from . import (
|
37 |
+
Image,
|
38 |
+
ImageChops,
|
39 |
+
ImageFile,
|
40 |
+
ImageMath,
|
41 |
+
ImageOps,
|
42 |
+
ImagePalette,
|
43 |
+
ImageSequence,
|
44 |
+
)
|
45 |
+
from ._binary import i16le as i16
|
46 |
+
from ._binary import o8
|
47 |
+
from ._binary import o16le as o16
|
48 |
+
|
49 |
+
if TYPE_CHECKING:
|
50 |
+
from . import _imaging
|
51 |
+
from ._typing import Buffer
|
52 |
+
|
53 |
+
|
54 |
+
class LoadingStrategy(IntEnum):
|
55 |
+
""".. versionadded:: 9.1.0"""
|
56 |
+
|
57 |
+
RGB_AFTER_FIRST = 0
|
58 |
+
RGB_AFTER_DIFFERENT_PALETTE_ONLY = 1
|
59 |
+
RGB_ALWAYS = 2
|
60 |
+
|
61 |
+
|
62 |
+
#: .. versionadded:: 9.1.0
|
63 |
+
LOADING_STRATEGY = LoadingStrategy.RGB_AFTER_FIRST
|
64 |
+
|
65 |
+
# --------------------------------------------------------------------
|
66 |
+
# Identify/read GIF files
|
67 |
+
|
68 |
+
|
69 |
+
def _accept(prefix: bytes) -> bool:
|
70 |
+
return prefix[:6] in [b"GIF87a", b"GIF89a"]
|
71 |
+
|
72 |
+
|
73 |
+
##
|
74 |
+
# Image plugin for GIF images. This plugin supports both GIF87 and
|
75 |
+
# GIF89 images.
|
76 |
+
|
77 |
+
|
78 |
+
class GifImageFile(ImageFile.ImageFile):
|
79 |
+
format = "GIF"
|
80 |
+
format_description = "Compuserve GIF"
|
81 |
+
_close_exclusive_fp_after_loading = False
|
82 |
+
|
83 |
+
global_palette = None
|
84 |
+
|
85 |
+
def data(self) -> bytes | None:
|
86 |
+
s = self.fp.read(1)
|
87 |
+
if s and s[0]:
|
88 |
+
return self.fp.read(s[0])
|
89 |
+
return None
|
90 |
+
|
91 |
+
def _is_palette_needed(self, p: bytes) -> bool:
|
92 |
+
for i in range(0, len(p), 3):
|
93 |
+
if not (i // 3 == p[i] == p[i + 1] == p[i + 2]):
|
94 |
+
return True
|
95 |
+
return False
|
96 |
+
|
97 |
+
def _open(self) -> None:
|
98 |
+
# Screen
|
99 |
+
s = self.fp.read(13)
|
100 |
+
if not _accept(s):
|
101 |
+
msg = "not a GIF file"
|
102 |
+
raise SyntaxError(msg)
|
103 |
+
|
104 |
+
self.info["version"] = s[:6]
|
105 |
+
self._size = i16(s, 6), i16(s, 8)
|
106 |
+
flags = s[10]
|
107 |
+
bits = (flags & 7) + 1
|
108 |
+
|
109 |
+
if flags & 128:
|
110 |
+
# get global palette
|
111 |
+
self.info["background"] = s[11]
|
112 |
+
# check if palette contains colour indices
|
113 |
+
p = self.fp.read(3 << bits)
|
114 |
+
if self._is_palette_needed(p):
|
115 |
+
p = ImagePalette.raw("RGB", p)
|
116 |
+
self.global_palette = self.palette = p
|
117 |
+
|
118 |
+
self._fp = self.fp # FIXME: hack
|
119 |
+
self.__rewind = self.fp.tell()
|
120 |
+
self._n_frames: int | None = None
|
121 |
+
self._seek(0) # get ready to read first frame
|
122 |
+
|
123 |
+
@property
|
124 |
+
def n_frames(self) -> int:
|
125 |
+
if self._n_frames is None:
|
126 |
+
current = self.tell()
|
127 |
+
try:
|
128 |
+
while True:
|
129 |
+
self._seek(self.tell() + 1, False)
|
130 |
+
except EOFError:
|
131 |
+
self._n_frames = self.tell() + 1
|
132 |
+
self.seek(current)
|
133 |
+
return self._n_frames
|
134 |
+
|
135 |
+
@cached_property
|
136 |
+
def is_animated(self) -> bool:
|
137 |
+
if self._n_frames is not None:
|
138 |
+
return self._n_frames != 1
|
139 |
+
|
140 |
+
current = self.tell()
|
141 |
+
if current:
|
142 |
+
return True
|
143 |
+
|
144 |
+
try:
|
145 |
+
self._seek(1, False)
|
146 |
+
is_animated = True
|
147 |
+
except EOFError:
|
148 |
+
is_animated = False
|
149 |
+
|
150 |
+
self.seek(current)
|
151 |
+
return is_animated
|
152 |
+
|
153 |
+
def seek(self, frame: int) -> None:
|
154 |
+
if not self._seek_check(frame):
|
155 |
+
return
|
156 |
+
if frame < self.__frame:
|
157 |
+
self._im = None
|
158 |
+
self._seek(0)
|
159 |
+
|
160 |
+
last_frame = self.__frame
|
161 |
+
for f in range(self.__frame + 1, frame + 1):
|
162 |
+
try:
|
163 |
+
self._seek(f)
|
164 |
+
except EOFError as e:
|
165 |
+
self.seek(last_frame)
|
166 |
+
msg = "no more images in GIF file"
|
167 |
+
raise EOFError(msg) from e
|
168 |
+
|
169 |
+
def _seek(self, frame: int, update_image: bool = True) -> None:
|
170 |
+
if frame == 0:
|
171 |
+
# rewind
|
172 |
+
self.__offset = 0
|
173 |
+
self.dispose: _imaging.ImagingCore | None = None
|
174 |
+
self.__frame = -1
|
175 |
+
self._fp.seek(self.__rewind)
|
176 |
+
self.disposal_method = 0
|
177 |
+
if "comment" in self.info:
|
178 |
+
del self.info["comment"]
|
179 |
+
else:
|
180 |
+
# ensure that the previous frame was loaded
|
181 |
+
if self.tile and update_image:
|
182 |
+
self.load()
|
183 |
+
|
184 |
+
if frame != self.__frame + 1:
|
185 |
+
msg = f"cannot seek to frame {frame}"
|
186 |
+
raise ValueError(msg)
|
187 |
+
|
188 |
+
self.fp = self._fp
|
189 |
+
if self.__offset:
|
190 |
+
# backup to last frame
|
191 |
+
self.fp.seek(self.__offset)
|
192 |
+
while self.data():
|
193 |
+
pass
|
194 |
+
self.__offset = 0
|
195 |
+
|
196 |
+
s = self.fp.read(1)
|
197 |
+
if not s or s == b";":
|
198 |
+
msg = "no more images in GIF file"
|
199 |
+
raise EOFError(msg)
|
200 |
+
|
201 |
+
palette: ImagePalette.ImagePalette | Literal[False] | None = None
|
202 |
+
|
203 |
+
info: dict[str, Any] = {}
|
204 |
+
frame_transparency = None
|
205 |
+
interlace = None
|
206 |
+
frame_dispose_extent = None
|
207 |
+
while True:
|
208 |
+
if not s:
|
209 |
+
s = self.fp.read(1)
|
210 |
+
if not s or s == b";":
|
211 |
+
break
|
212 |
+
|
213 |
+
elif s == b"!":
|
214 |
+
#
|
215 |
+
# extensions
|
216 |
+
#
|
217 |
+
s = self.fp.read(1)
|
218 |
+
block = self.data()
|
219 |
+
if s[0] == 249 and block is not None:
|
220 |
+
#
|
221 |
+
# graphic control extension
|
222 |
+
#
|
223 |
+
flags = block[0]
|
224 |
+
if flags & 1:
|
225 |
+
frame_transparency = block[3]
|
226 |
+
info["duration"] = i16(block, 1) * 10
|
227 |
+
|
228 |
+
# disposal method - find the value of bits 4 - 6
|
229 |
+
dispose_bits = 0b00011100 & flags
|
230 |
+
dispose_bits = dispose_bits >> 2
|
231 |
+
if dispose_bits:
|
232 |
+
# only set the dispose if it is not
|
233 |
+
# unspecified. I'm not sure if this is
|
234 |
+
# correct, but it seems to prevent the last
|
235 |
+
# frame from looking odd for some animations
|
236 |
+
self.disposal_method = dispose_bits
|
237 |
+
elif s[0] == 254:
|
238 |
+
#
|
239 |
+
# comment extension
|
240 |
+
#
|
241 |
+
comment = b""
|
242 |
+
|
243 |
+
# Read this comment block
|
244 |
+
while block:
|
245 |
+
comment += block
|
246 |
+
block = self.data()
|
247 |
+
|
248 |
+
if "comment" in info:
|
249 |
+
# If multiple comment blocks in frame, separate with \n
|
250 |
+
info["comment"] += b"\n" + comment
|
251 |
+
else:
|
252 |
+
info["comment"] = comment
|
253 |
+
s = None
|
254 |
+
continue
|
255 |
+
elif s[0] == 255 and frame == 0 and block is not None:
|
256 |
+
#
|
257 |
+
# application extension
|
258 |
+
#
|
259 |
+
info["extension"] = block, self.fp.tell()
|
260 |
+
if block[:11] == b"NETSCAPE2.0":
|
261 |
+
block = self.data()
|
262 |
+
if block and len(block) >= 3 and block[0] == 1:
|
263 |
+
self.info["loop"] = i16(block, 1)
|
264 |
+
while self.data():
|
265 |
+
pass
|
266 |
+
|
267 |
+
elif s == b",":
|
268 |
+
#
|
269 |
+
# local image
|
270 |
+
#
|
271 |
+
s = self.fp.read(9)
|
272 |
+
|
273 |
+
# extent
|
274 |
+
x0, y0 = i16(s, 0), i16(s, 2)
|
275 |
+
x1, y1 = x0 + i16(s, 4), y0 + i16(s, 6)
|
276 |
+
if (x1 > self.size[0] or y1 > self.size[1]) and update_image:
|
277 |
+
self._size = max(x1, self.size[0]), max(y1, self.size[1])
|
278 |
+
Image._decompression_bomb_check(self._size)
|
279 |
+
frame_dispose_extent = x0, y0, x1, y1
|
280 |
+
flags = s[8]
|
281 |
+
|
282 |
+
interlace = (flags & 64) != 0
|
283 |
+
|
284 |
+
if flags & 128:
|
285 |
+
bits = (flags & 7) + 1
|
286 |
+
p = self.fp.read(3 << bits)
|
287 |
+
if self._is_palette_needed(p):
|
288 |
+
palette = ImagePalette.raw("RGB", p)
|
289 |
+
else:
|
290 |
+
palette = False
|
291 |
+
|
292 |
+
# image data
|
293 |
+
bits = self.fp.read(1)[0]
|
294 |
+
self.__offset = self.fp.tell()
|
295 |
+
break
|
296 |
+
s = None
|
297 |
+
|
298 |
+
if interlace is None:
|
299 |
+
msg = "image not found in GIF frame"
|
300 |
+
raise EOFError(msg)
|
301 |
+
|
302 |
+
self.__frame = frame
|
303 |
+
if not update_image:
|
304 |
+
return
|
305 |
+
|
306 |
+
self.tile = []
|
307 |
+
|
308 |
+
if self.dispose:
|
309 |
+
self.im.paste(self.dispose, self.dispose_extent)
|
310 |
+
|
311 |
+
self._frame_palette = palette if palette is not None else self.global_palette
|
312 |
+
self._frame_transparency = frame_transparency
|
313 |
+
if frame == 0:
|
314 |
+
if self._frame_palette:
|
315 |
+
if LOADING_STRATEGY == LoadingStrategy.RGB_ALWAYS:
|
316 |
+
self._mode = "RGBA" if frame_transparency is not None else "RGB"
|
317 |
+
else:
|
318 |
+
self._mode = "P"
|
319 |
+
else:
|
320 |
+
self._mode = "L"
|
321 |
+
|
322 |
+
if palette:
|
323 |
+
self.palette = palette
|
324 |
+
elif self.global_palette:
|
325 |
+
from copy import copy
|
326 |
+
|
327 |
+
self.palette = copy(self.global_palette)
|
328 |
+
else:
|
329 |
+
self.palette = None
|
330 |
+
else:
|
331 |
+
if self.mode == "P":
|
332 |
+
if (
|
333 |
+
LOADING_STRATEGY != LoadingStrategy.RGB_AFTER_DIFFERENT_PALETTE_ONLY
|
334 |
+
or palette
|
335 |
+
):
|
336 |
+
if "transparency" in self.info:
|
337 |
+
self.im.putpalettealpha(self.info["transparency"], 0)
|
338 |
+
self.im = self.im.convert("RGBA", Image.Dither.FLOYDSTEINBERG)
|
339 |
+
self._mode = "RGBA"
|
340 |
+
del self.info["transparency"]
|
341 |
+
else:
|
342 |
+
self._mode = "RGB"
|
343 |
+
self.im = self.im.convert("RGB", Image.Dither.FLOYDSTEINBERG)
|
344 |
+
|
345 |
+
def _rgb(color: int) -> tuple[int, int, int]:
|
346 |
+
if self._frame_palette:
|
347 |
+
if color * 3 + 3 > len(self._frame_palette.palette):
|
348 |
+
color = 0
|
349 |
+
return tuple(self._frame_palette.palette[color * 3 : color * 3 + 3])
|
350 |
+
else:
|
351 |
+
return (color, color, color)
|
352 |
+
|
353 |
+
self.dispose = None
|
354 |
+
self.dispose_extent = frame_dispose_extent
|
355 |
+
if self.dispose_extent and self.disposal_method >= 2:
|
356 |
+
try:
|
357 |
+
if self.disposal_method == 2:
|
358 |
+
# replace with background colour
|
359 |
+
|
360 |
+
# only dispose the extent in this frame
|
361 |
+
x0, y0, x1, y1 = self.dispose_extent
|
362 |
+
dispose_size = (x1 - x0, y1 - y0)
|
363 |
+
|
364 |
+
Image._decompression_bomb_check(dispose_size)
|
365 |
+
|
366 |
+
# by convention, attempt to use transparency first
|
367 |
+
dispose_mode = "P"
|
368 |
+
color = self.info.get("transparency", frame_transparency)
|
369 |
+
if color is not None:
|
370 |
+
if self.mode in ("RGB", "RGBA"):
|
371 |
+
dispose_mode = "RGBA"
|
372 |
+
color = _rgb(color) + (0,)
|
373 |
+
else:
|
374 |
+
color = self.info.get("background", 0)
|
375 |
+
if self.mode in ("RGB", "RGBA"):
|
376 |
+
dispose_mode = "RGB"
|
377 |
+
color = _rgb(color)
|
378 |
+
self.dispose = Image.core.fill(dispose_mode, dispose_size, color)
|
379 |
+
else:
|
380 |
+
# replace with previous contents
|
381 |
+
if self._im is not None:
|
382 |
+
# only dispose the extent in this frame
|
383 |
+
self.dispose = self._crop(self.im, self.dispose_extent)
|
384 |
+
elif frame_transparency is not None:
|
385 |
+
x0, y0, x1, y1 = self.dispose_extent
|
386 |
+
dispose_size = (x1 - x0, y1 - y0)
|
387 |
+
|
388 |
+
Image._decompression_bomb_check(dispose_size)
|
389 |
+
dispose_mode = "P"
|
390 |
+
color = frame_transparency
|
391 |
+
if self.mode in ("RGB", "RGBA"):
|
392 |
+
dispose_mode = "RGBA"
|
393 |
+
color = _rgb(frame_transparency) + (0,)
|
394 |
+
self.dispose = Image.core.fill(
|
395 |
+
dispose_mode, dispose_size, color
|
396 |
+
)
|
397 |
+
except AttributeError:
|
398 |
+
pass
|
399 |
+
|
400 |
+
if interlace is not None:
|
401 |
+
transparency = -1
|
402 |
+
if frame_transparency is not None:
|
403 |
+
if frame == 0:
|
404 |
+
if LOADING_STRATEGY != LoadingStrategy.RGB_ALWAYS:
|
405 |
+
self.info["transparency"] = frame_transparency
|
406 |
+
elif self.mode not in ("RGB", "RGBA"):
|
407 |
+
transparency = frame_transparency
|
408 |
+
self.tile = [
|
409 |
+
ImageFile._Tile(
|
410 |
+
"gif",
|
411 |
+
(x0, y0, x1, y1),
|
412 |
+
self.__offset,
|
413 |
+
(bits, interlace, transparency),
|
414 |
+
)
|
415 |
+
]
|
416 |
+
|
417 |
+
if info.get("comment"):
|
418 |
+
self.info["comment"] = info["comment"]
|
419 |
+
for k in ["duration", "extension"]:
|
420 |
+
if k in info:
|
421 |
+
self.info[k] = info[k]
|
422 |
+
elif k in self.info:
|
423 |
+
del self.info[k]
|
424 |
+
|
425 |
+
def load_prepare(self) -> None:
|
426 |
+
temp_mode = "P" if self._frame_palette else "L"
|
427 |
+
self._prev_im = None
|
428 |
+
if self.__frame == 0:
|
429 |
+
if self._frame_transparency is not None:
|
430 |
+
self.im = Image.core.fill(
|
431 |
+
temp_mode, self.size, self._frame_transparency
|
432 |
+
)
|
433 |
+
elif self.mode in ("RGB", "RGBA"):
|
434 |
+
self._prev_im = self.im
|
435 |
+
if self._frame_palette:
|
436 |
+
self.im = Image.core.fill("P", self.size, self._frame_transparency or 0)
|
437 |
+
self.im.putpalette("RGB", *self._frame_palette.getdata())
|
438 |
+
else:
|
439 |
+
self._im = None
|
440 |
+
if not self._prev_im and self._im is not None and self.size != self.im.size:
|
441 |
+
expanded_im = Image.core.fill(self.im.mode, self.size)
|
442 |
+
if self._frame_palette:
|
443 |
+
expanded_im.putpalette("RGB", *self._frame_palette.getdata())
|
444 |
+
expanded_im.paste(self.im, (0, 0) + self.im.size)
|
445 |
+
|
446 |
+
self.im = expanded_im
|
447 |
+
self._mode = temp_mode
|
448 |
+
self._frame_palette = None
|
449 |
+
|
450 |
+
super().load_prepare()
|
451 |
+
|
452 |
+
def load_end(self) -> None:
|
453 |
+
if self.__frame == 0:
|
454 |
+
if self.mode == "P" and LOADING_STRATEGY == LoadingStrategy.RGB_ALWAYS:
|
455 |
+
if self._frame_transparency is not None:
|
456 |
+
self.im.putpalettealpha(self._frame_transparency, 0)
|
457 |
+
self._mode = "RGBA"
|
458 |
+
else:
|
459 |
+
self._mode = "RGB"
|
460 |
+
self.im = self.im.convert(self.mode, Image.Dither.FLOYDSTEINBERG)
|
461 |
+
return
|
462 |
+
if not self._prev_im:
|
463 |
+
return
|
464 |
+
if self.size != self._prev_im.size:
|
465 |
+
if self._frame_transparency is not None:
|
466 |
+
expanded_im = Image.core.fill("RGBA", self.size)
|
467 |
+
else:
|
468 |
+
expanded_im = Image.core.fill("P", self.size)
|
469 |
+
expanded_im.putpalette("RGB", "RGB", self.im.getpalette())
|
470 |
+
expanded_im = expanded_im.convert("RGB")
|
471 |
+
expanded_im.paste(self._prev_im, (0, 0) + self._prev_im.size)
|
472 |
+
|
473 |
+
self._prev_im = expanded_im
|
474 |
+
assert self._prev_im is not None
|
475 |
+
if self._frame_transparency is not None:
|
476 |
+
self.im.putpalettealpha(self._frame_transparency, 0)
|
477 |
+
frame_im = self.im.convert("RGBA")
|
478 |
+
else:
|
479 |
+
frame_im = self.im.convert("RGB")
|
480 |
+
|
481 |
+
assert self.dispose_extent is not None
|
482 |
+
frame_im = self._crop(frame_im, self.dispose_extent)
|
483 |
+
|
484 |
+
self.im = self._prev_im
|
485 |
+
self._mode = self.im.mode
|
486 |
+
if frame_im.mode == "RGBA":
|
487 |
+
self.im.paste(frame_im, self.dispose_extent, frame_im)
|
488 |
+
else:
|
489 |
+
self.im.paste(frame_im, self.dispose_extent)
|
490 |
+
|
491 |
+
def tell(self) -> int:
|
492 |
+
return self.__frame
|
493 |
+
|
494 |
+
|
495 |
+
# --------------------------------------------------------------------
|
496 |
+
# Write GIF files
|
497 |
+
|
498 |
+
|
499 |
+
RAWMODE = {"1": "L", "L": "L", "P": "P"}
|
500 |
+
|
501 |
+
|
502 |
+
def _normalize_mode(im: Image.Image) -> Image.Image:
|
503 |
+
"""
|
504 |
+
Takes an image (or frame), returns an image in a mode that is appropriate
|
505 |
+
for saving in a Gif.
|
506 |
+
|
507 |
+
It may return the original image, or it may return an image converted to
|
508 |
+
palette or 'L' mode.
|
509 |
+
|
510 |
+
:param im: Image object
|
511 |
+
:returns: Image object
|
512 |
+
"""
|
513 |
+
if im.mode in RAWMODE:
|
514 |
+
im.load()
|
515 |
+
return im
|
516 |
+
if Image.getmodebase(im.mode) == "RGB":
|
517 |
+
im = im.convert("P", palette=Image.Palette.ADAPTIVE)
|
518 |
+
assert im.palette is not None
|
519 |
+
if im.palette.mode == "RGBA":
|
520 |
+
for rgba in im.palette.colors:
|
521 |
+
if rgba[3] == 0:
|
522 |
+
im.info["transparency"] = im.palette.colors[rgba]
|
523 |
+
break
|
524 |
+
return im
|
525 |
+
return im.convert("L")
|
526 |
+
|
527 |
+
|
528 |
+
_Palette = Union[bytes, bytearray, list[int], ImagePalette.ImagePalette]
|
529 |
+
|
530 |
+
|
531 |
+
def _normalize_palette(
|
532 |
+
im: Image.Image, palette: _Palette | None, info: dict[str, Any]
|
533 |
+
) -> Image.Image:
|
534 |
+
"""
|
535 |
+
Normalizes the palette for image.
|
536 |
+
- Sets the palette to the incoming palette, if provided.
|
537 |
+
- Ensures that there's a palette for L mode images
|
538 |
+
- Optimizes the palette if necessary/desired.
|
539 |
+
|
540 |
+
:param im: Image object
|
541 |
+
:param palette: bytes object containing the source palette, or ....
|
542 |
+
:param info: encoderinfo
|
543 |
+
:returns: Image object
|
544 |
+
"""
|
545 |
+
source_palette = None
|
546 |
+
if palette:
|
547 |
+
# a bytes palette
|
548 |
+
if isinstance(palette, (bytes, bytearray, list)):
|
549 |
+
source_palette = bytearray(palette[:768])
|
550 |
+
if isinstance(palette, ImagePalette.ImagePalette):
|
551 |
+
source_palette = bytearray(palette.palette)
|
552 |
+
|
553 |
+
if im.mode == "P":
|
554 |
+
if not source_palette:
|
555 |
+
im_palette = im.getpalette(None)
|
556 |
+
assert im_palette is not None
|
557 |
+
source_palette = bytearray(im_palette)
|
558 |
+
else: # L-mode
|
559 |
+
if not source_palette:
|
560 |
+
source_palette = bytearray(i // 3 for i in range(768))
|
561 |
+
im.palette = ImagePalette.ImagePalette("RGB", palette=source_palette)
|
562 |
+
assert source_palette is not None
|
563 |
+
|
564 |
+
if palette:
|
565 |
+
used_palette_colors: list[int | None] = []
|
566 |
+
assert im.palette is not None
|
567 |
+
for i in range(0, len(source_palette), 3):
|
568 |
+
source_color = tuple(source_palette[i : i + 3])
|
569 |
+
index = im.palette.colors.get(source_color)
|
570 |
+
if index in used_palette_colors:
|
571 |
+
index = None
|
572 |
+
used_palette_colors.append(index)
|
573 |
+
for i, index in enumerate(used_palette_colors):
|
574 |
+
if index is None:
|
575 |
+
for j in range(len(used_palette_colors)):
|
576 |
+
if j not in used_palette_colors:
|
577 |
+
used_palette_colors[i] = j
|
578 |
+
break
|
579 |
+
dest_map: list[int] = []
|
580 |
+
for index in used_palette_colors:
|
581 |
+
assert index is not None
|
582 |
+
dest_map.append(index)
|
583 |
+
im = im.remap_palette(dest_map)
|
584 |
+
else:
|
585 |
+
optimized_palette_colors = _get_optimize(im, info)
|
586 |
+
if optimized_palette_colors is not None:
|
587 |
+
im = im.remap_palette(optimized_palette_colors, source_palette)
|
588 |
+
if "transparency" in info:
|
589 |
+
try:
|
590 |
+
info["transparency"] = optimized_palette_colors.index(
|
591 |
+
info["transparency"]
|
592 |
+
)
|
593 |
+
except ValueError:
|
594 |
+
del info["transparency"]
|
595 |
+
return im
|
596 |
+
|
597 |
+
assert im.palette is not None
|
598 |
+
im.palette.palette = source_palette
|
599 |
+
return im
|
600 |
+
|
601 |
+
|
602 |
+
def _write_single_frame(
|
603 |
+
im: Image.Image,
|
604 |
+
fp: IO[bytes],
|
605 |
+
palette: _Palette | None,
|
606 |
+
) -> None:
|
607 |
+
im_out = _normalize_mode(im)
|
608 |
+
for k, v in im_out.info.items():
|
609 |
+
if isinstance(k, str):
|
610 |
+
im.encoderinfo.setdefault(k, v)
|
611 |
+
im_out = _normalize_palette(im_out, palette, im.encoderinfo)
|
612 |
+
|
613 |
+
for s in _get_global_header(im_out, im.encoderinfo):
|
614 |
+
fp.write(s)
|
615 |
+
|
616 |
+
# local image header
|
617 |
+
flags = 0
|
618 |
+
if get_interlace(im):
|
619 |
+
flags = flags | 64
|
620 |
+
_write_local_header(fp, im, (0, 0), flags)
|
621 |
+
|
622 |
+
im_out.encoderconfig = (8, get_interlace(im))
|
623 |
+
ImageFile._save(
|
624 |
+
im_out, fp, [ImageFile._Tile("gif", (0, 0) + im.size, 0, RAWMODE[im_out.mode])]
|
625 |
+
)
|
626 |
+
|
627 |
+
fp.write(b"\0") # end of image data
|
628 |
+
|
629 |
+
|
630 |
+
def _getbbox(
|
631 |
+
base_im: Image.Image, im_frame: Image.Image
|
632 |
+
) -> tuple[Image.Image, tuple[int, int, int, int] | None]:
|
633 |
+
palette_bytes = [
|
634 |
+
bytes(im.palette.palette) if im.palette else b"" for im in (base_im, im_frame)
|
635 |
+
]
|
636 |
+
if palette_bytes[0] != palette_bytes[1]:
|
637 |
+
im_frame = im_frame.convert("RGBA")
|
638 |
+
base_im = base_im.convert("RGBA")
|
639 |
+
delta = ImageChops.subtract_modulo(im_frame, base_im)
|
640 |
+
return delta, delta.getbbox(alpha_only=False)
|
641 |
+
|
642 |
+
|
643 |
+
class _Frame(NamedTuple):
|
644 |
+
im: Image.Image
|
645 |
+
bbox: tuple[int, int, int, int] | None
|
646 |
+
encoderinfo: dict[str, Any]
|
647 |
+
|
648 |
+
|
649 |
+
def _write_multiple_frames(
|
650 |
+
im: Image.Image, fp: IO[bytes], palette: _Palette | None
|
651 |
+
) -> bool:
|
652 |
+
duration = im.encoderinfo.get("duration")
|
653 |
+
disposal = im.encoderinfo.get("disposal", im.info.get("disposal"))
|
654 |
+
|
655 |
+
im_frames: list[_Frame] = []
|
656 |
+
previous_im: Image.Image | None = None
|
657 |
+
frame_count = 0
|
658 |
+
background_im = None
|
659 |
+
for imSequence in itertools.chain([im], im.encoderinfo.get("append_images", [])):
|
660 |
+
for im_frame in ImageSequence.Iterator(imSequence):
|
661 |
+
# a copy is required here since seek can still mutate the image
|
662 |
+
im_frame = _normalize_mode(im_frame.copy())
|
663 |
+
if frame_count == 0:
|
664 |
+
for k, v in im_frame.info.items():
|
665 |
+
if k == "transparency":
|
666 |
+
continue
|
667 |
+
if isinstance(k, str):
|
668 |
+
im.encoderinfo.setdefault(k, v)
|
669 |
+
|
670 |
+
encoderinfo = im.encoderinfo.copy()
|
671 |
+
if "transparency" in im_frame.info:
|
672 |
+
encoderinfo.setdefault("transparency", im_frame.info["transparency"])
|
673 |
+
im_frame = _normalize_palette(im_frame, palette, encoderinfo)
|
674 |
+
if isinstance(duration, (list, tuple)):
|
675 |
+
encoderinfo["duration"] = duration[frame_count]
|
676 |
+
elif duration is None and "duration" in im_frame.info:
|
677 |
+
encoderinfo["duration"] = im_frame.info["duration"]
|
678 |
+
if isinstance(disposal, (list, tuple)):
|
679 |
+
encoderinfo["disposal"] = disposal[frame_count]
|
680 |
+
frame_count += 1
|
681 |
+
|
682 |
+
diff_frame = None
|
683 |
+
if im_frames and previous_im:
|
684 |
+
# delta frame
|
685 |
+
delta, bbox = _getbbox(previous_im, im_frame)
|
686 |
+
if not bbox:
|
687 |
+
# This frame is identical to the previous frame
|
688 |
+
if encoderinfo.get("duration"):
|
689 |
+
im_frames[-1].encoderinfo["duration"] += encoderinfo["duration"]
|
690 |
+
continue
|
691 |
+
if im_frames[-1].encoderinfo.get("disposal") == 2:
|
692 |
+
if background_im is None:
|
693 |
+
color = im.encoderinfo.get(
|
694 |
+
"transparency", im.info.get("transparency", (0, 0, 0))
|
695 |
+
)
|
696 |
+
background = _get_background(im_frame, color)
|
697 |
+
background_im = Image.new("P", im_frame.size, background)
|
698 |
+
first_palette = im_frames[0].im.palette
|
699 |
+
assert first_palette is not None
|
700 |
+
background_im.putpalette(first_palette, first_palette.mode)
|
701 |
+
bbox = _getbbox(background_im, im_frame)[1]
|
702 |
+
elif encoderinfo.get("optimize") and im_frame.mode != "1":
|
703 |
+
if "transparency" not in encoderinfo:
|
704 |
+
assert im_frame.palette is not None
|
705 |
+
try:
|
706 |
+
encoderinfo["transparency"] = (
|
707 |
+
im_frame.palette._new_color_index(im_frame)
|
708 |
+
)
|
709 |
+
except ValueError:
|
710 |
+
pass
|
711 |
+
if "transparency" in encoderinfo:
|
712 |
+
# When the delta is zero, fill the image with transparency
|
713 |
+
diff_frame = im_frame.copy()
|
714 |
+
fill = Image.new("P", delta.size, encoderinfo["transparency"])
|
715 |
+
if delta.mode == "RGBA":
|
716 |
+
r, g, b, a = delta.split()
|
717 |
+
mask = ImageMath.lambda_eval(
|
718 |
+
lambda args: args["convert"](
|
719 |
+
args["max"](
|
720 |
+
args["max"](
|
721 |
+
args["max"](args["r"], args["g"]), args["b"]
|
722 |
+
),
|
723 |
+
args["a"],
|
724 |
+
)
|
725 |
+
* 255,
|
726 |
+
"1",
|
727 |
+
),
|
728 |
+
r=r,
|
729 |
+
g=g,
|
730 |
+
b=b,
|
731 |
+
a=a,
|
732 |
+
)
|
733 |
+
else:
|
734 |
+
if delta.mode == "P":
|
735 |
+
# Convert to L without considering palette
|
736 |
+
delta_l = Image.new("L", delta.size)
|
737 |
+
delta_l.putdata(delta.getdata())
|
738 |
+
delta = delta_l
|
739 |
+
mask = ImageMath.lambda_eval(
|
740 |
+
lambda args: args["convert"](args["im"] * 255, "1"),
|
741 |
+
im=delta,
|
742 |
+
)
|
743 |
+
diff_frame.paste(fill, mask=ImageOps.invert(mask))
|
744 |
+
else:
|
745 |
+
bbox = None
|
746 |
+
previous_im = im_frame
|
747 |
+
im_frames.append(_Frame(diff_frame or im_frame, bbox, encoderinfo))
|
748 |
+
|
749 |
+
if len(im_frames) == 1:
|
750 |
+
if "duration" in im.encoderinfo:
|
751 |
+
# Since multiple frames will not be written, use the combined duration
|
752 |
+
im.encoderinfo["duration"] = im_frames[0].encoderinfo["duration"]
|
753 |
+
return False
|
754 |
+
|
755 |
+
for frame_data in im_frames:
|
756 |
+
im_frame = frame_data.im
|
757 |
+
if not frame_data.bbox:
|
758 |
+
# global header
|
759 |
+
for s in _get_global_header(im_frame, frame_data.encoderinfo):
|
760 |
+
fp.write(s)
|
761 |
+
offset = (0, 0)
|
762 |
+
else:
|
763 |
+
# compress difference
|
764 |
+
if not palette:
|
765 |
+
frame_data.encoderinfo["include_color_table"] = True
|
766 |
+
|
767 |
+
im_frame = im_frame.crop(frame_data.bbox)
|
768 |
+
offset = frame_data.bbox[:2]
|
769 |
+
_write_frame_data(fp, im_frame, offset, frame_data.encoderinfo)
|
770 |
+
return True
|
771 |
+
|
772 |
+
|
773 |
+
def _save_all(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
|
774 |
+
_save(im, fp, filename, save_all=True)
|
775 |
+
|
776 |
+
|
777 |
+
def _save(
|
778 |
+
im: Image.Image, fp: IO[bytes], filename: str | bytes, save_all: bool = False
|
779 |
+
) -> None:
|
780 |
+
# header
|
781 |
+
if "palette" in im.encoderinfo or "palette" in im.info:
|
782 |
+
palette = im.encoderinfo.get("palette", im.info.get("palette"))
|
783 |
+
else:
|
784 |
+
palette = None
|
785 |
+
im.encoderinfo.setdefault("optimize", True)
|
786 |
+
|
787 |
+
if not save_all or not _write_multiple_frames(im, fp, palette):
|
788 |
+
_write_single_frame(im, fp, palette)
|
789 |
+
|
790 |
+
fp.write(b";") # end of file
|
791 |
+
|
792 |
+
if hasattr(fp, "flush"):
|
793 |
+
fp.flush()
|
794 |
+
|
795 |
+
|
796 |
+
def get_interlace(im: Image.Image) -> int:
|
797 |
+
interlace = im.encoderinfo.get("interlace", 1)
|
798 |
+
|
799 |
+
# workaround for @PIL153
|
800 |
+
if min(im.size) < 16:
|
801 |
+
interlace = 0
|
802 |
+
|
803 |
+
return interlace
|
804 |
+
|
805 |
+
|
806 |
+
def _write_local_header(
|
807 |
+
fp: IO[bytes], im: Image.Image, offset: tuple[int, int], flags: int
|
808 |
+
) -> None:
|
809 |
+
try:
|
810 |
+
transparency = im.encoderinfo["transparency"]
|
811 |
+
except KeyError:
|
812 |
+
transparency = None
|
813 |
+
|
814 |
+
if "duration" in im.encoderinfo:
|
815 |
+
duration = int(im.encoderinfo["duration"] / 10)
|
816 |
+
else:
|
817 |
+
duration = 0
|
818 |
+
|
819 |
+
disposal = int(im.encoderinfo.get("disposal", 0))
|
820 |
+
|
821 |
+
if transparency is not None or duration != 0 or disposal:
|
822 |
+
packed_flag = 1 if transparency is not None else 0
|
823 |
+
packed_flag |= disposal << 2
|
824 |
+
|
825 |
+
fp.write(
|
826 |
+
b"!"
|
827 |
+
+ o8(249) # extension intro
|
828 |
+
+ o8(4) # length
|
829 |
+
+ o8(packed_flag) # packed fields
|
830 |
+
+ o16(duration) # duration
|
831 |
+
+ o8(transparency or 0) # transparency index
|
832 |
+
+ o8(0)
|
833 |
+
)
|
834 |
+
|
835 |
+
include_color_table = im.encoderinfo.get("include_color_table")
|
836 |
+
if include_color_table:
|
837 |
+
palette_bytes = _get_palette_bytes(im)
|
838 |
+
color_table_size = _get_color_table_size(palette_bytes)
|
839 |
+
if color_table_size:
|
840 |
+
flags = flags | 128 # local color table flag
|
841 |
+
flags = flags | color_table_size
|
842 |
+
|
843 |
+
fp.write(
|
844 |
+
b","
|
845 |
+
+ o16(offset[0]) # offset
|
846 |
+
+ o16(offset[1])
|
847 |
+
+ o16(im.size[0]) # size
|
848 |
+
+ o16(im.size[1])
|
849 |
+
+ o8(flags) # flags
|
850 |
+
)
|
851 |
+
if include_color_table and color_table_size:
|
852 |
+
fp.write(_get_header_palette(palette_bytes))
|
853 |
+
fp.write(o8(8)) # bits
|
854 |
+
|
855 |
+
|
856 |
+
def _save_netpbm(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
|
857 |
+
# Unused by default.
|
858 |
+
# To use, uncomment the register_save call at the end of the file.
|
859 |
+
#
|
860 |
+
# If you need real GIF compression and/or RGB quantization, you
|
861 |
+
# can use the external NETPBM/PBMPLUS utilities. See comments
|
862 |
+
# below for information on how to enable this.
|
863 |
+
tempfile = im._dump()
|
864 |
+
|
865 |
+
try:
|
866 |
+
with open(filename, "wb") as f:
|
867 |
+
if im.mode != "RGB":
|
868 |
+
subprocess.check_call(
|
869 |
+
["ppmtogif", tempfile], stdout=f, stderr=subprocess.DEVNULL
|
870 |
+
)
|
871 |
+
else:
|
872 |
+
# Pipe ppmquant output into ppmtogif
|
873 |
+
# "ppmquant 256 %s | ppmtogif > %s" % (tempfile, filename)
|
874 |
+
quant_cmd = ["ppmquant", "256", tempfile]
|
875 |
+
togif_cmd = ["ppmtogif"]
|
876 |
+
quant_proc = subprocess.Popen(
|
877 |
+
quant_cmd, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL
|
878 |
+
)
|
879 |
+
togif_proc = subprocess.Popen(
|
880 |
+
togif_cmd,
|
881 |
+
stdin=quant_proc.stdout,
|
882 |
+
stdout=f,
|
883 |
+
stderr=subprocess.DEVNULL,
|
884 |
+
)
|
885 |
+
|
886 |
+
# Allow ppmquant to receive SIGPIPE if ppmtogif exits
|
887 |
+
assert quant_proc.stdout is not None
|
888 |
+
quant_proc.stdout.close()
|
889 |
+
|
890 |
+
retcode = quant_proc.wait()
|
891 |
+
if retcode:
|
892 |
+
raise subprocess.CalledProcessError(retcode, quant_cmd)
|
893 |
+
|
894 |
+
retcode = togif_proc.wait()
|
895 |
+
if retcode:
|
896 |
+
raise subprocess.CalledProcessError(retcode, togif_cmd)
|
897 |
+
finally:
|
898 |
+
try:
|
899 |
+
os.unlink(tempfile)
|
900 |
+
except OSError:
|
901 |
+
pass
|
902 |
+
|
903 |
+
|
904 |
+
# Force optimization so that we can test performance against
|
905 |
+
# cases where it took lots of memory and time previously.
|
906 |
+
_FORCE_OPTIMIZE = False
|
907 |
+
|
908 |
+
|
909 |
+
def _get_optimize(im: Image.Image, info: dict[str, Any]) -> list[int] | None:
|
910 |
+
"""
|
911 |
+
Palette optimization is a potentially expensive operation.
|
912 |
+
|
913 |
+
This function determines if the palette should be optimized using
|
914 |
+
some heuristics, then returns the list of palette entries in use.
|
915 |
+
|
916 |
+
:param im: Image object
|
917 |
+
:param info: encoderinfo
|
918 |
+
:returns: list of indexes of palette entries in use, or None
|
919 |
+
"""
|
920 |
+
if im.mode in ("P", "L") and info and info.get("optimize"):
|
921 |
+
# Potentially expensive operation.
|
922 |
+
|
923 |
+
# The palette saves 3 bytes per color not used, but palette
|
924 |
+
# lengths are restricted to 3*(2**N) bytes. Max saving would
|
925 |
+
# be 768 -> 6 bytes if we went all the way down to 2 colors.
|
926 |
+
# * If we're over 128 colors, we can't save any space.
|
927 |
+
# * If there aren't any holes, it's not worth collapsing.
|
928 |
+
# * If we have a 'large' image, the palette is in the noise.
|
929 |
+
|
930 |
+
# create the new palette if not every color is used
|
931 |
+
optimise = _FORCE_OPTIMIZE or im.mode == "L"
|
932 |
+
if optimise or im.width * im.height < 512 * 512:
|
933 |
+
# check which colors are used
|
934 |
+
used_palette_colors = []
|
935 |
+
for i, count in enumerate(im.histogram()):
|
936 |
+
if count:
|
937 |
+
used_palette_colors.append(i)
|
938 |
+
|
939 |
+
if optimise or max(used_palette_colors) >= len(used_palette_colors):
|
940 |
+
return used_palette_colors
|
941 |
+
|
942 |
+
assert im.palette is not None
|
943 |
+
num_palette_colors = len(im.palette.palette) // Image.getmodebands(
|
944 |
+
im.palette.mode
|
945 |
+
)
|
946 |
+
current_palette_size = 1 << (num_palette_colors - 1).bit_length()
|
947 |
+
if (
|
948 |
+
# check that the palette would become smaller when saved
|
949 |
+
len(used_palette_colors) <= current_palette_size // 2
|
950 |
+
# check that the palette is not already the smallest possible size
|
951 |
+
and current_palette_size > 2
|
952 |
+
):
|
953 |
+
return used_palette_colors
|
954 |
+
return None
|
955 |
+
|
956 |
+
|
957 |
+
def _get_color_table_size(palette_bytes: bytes) -> int:
|
958 |
+
# calculate the palette size for the header
|
959 |
+
if not palette_bytes:
|
960 |
+
return 0
|
961 |
+
elif len(palette_bytes) < 9:
|
962 |
+
return 1
|
963 |
+
else:
|
964 |
+
return math.ceil(math.log(len(palette_bytes) // 3, 2)) - 1
|
965 |
+
|
966 |
+
|
967 |
+
def _get_header_palette(palette_bytes: bytes) -> bytes:
|
968 |
+
"""
|
969 |
+
Returns the palette, null padded to the next power of 2 (*3) bytes
|
970 |
+
suitable for direct inclusion in the GIF header
|
971 |
+
|
972 |
+
:param palette_bytes: Unpadded palette bytes, in RGBRGB form
|
973 |
+
:returns: Null padded palette
|
974 |
+
"""
|
975 |
+
color_table_size = _get_color_table_size(palette_bytes)
|
976 |
+
|
977 |
+
# add the missing amount of bytes
|
978 |
+
# the palette has to be 2<<n in size
|
979 |
+
actual_target_size_diff = (2 << color_table_size) - len(palette_bytes) // 3
|
980 |
+
if actual_target_size_diff > 0:
|
981 |
+
palette_bytes += o8(0) * 3 * actual_target_size_diff
|
982 |
+
return palette_bytes
|
983 |
+
|
984 |
+
|
985 |
+
def _get_palette_bytes(im: Image.Image) -> bytes:
|
986 |
+
"""
|
987 |
+
Gets the palette for inclusion in the gif header
|
988 |
+
|
989 |
+
:param im: Image object
|
990 |
+
:returns: Bytes, len<=768 suitable for inclusion in gif header
|
991 |
+
"""
|
992 |
+
if not im.palette:
|
993 |
+
return b""
|
994 |
+
|
995 |
+
palette = bytes(im.palette.palette)
|
996 |
+
if im.palette.mode == "RGBA":
|
997 |
+
palette = b"".join(palette[i * 4 : i * 4 + 3] for i in range(len(palette) // 3))
|
998 |
+
return palette
|
999 |
+
|
1000 |
+
|
1001 |
+
def _get_background(
|
1002 |
+
im: Image.Image,
|
1003 |
+
info_background: int | tuple[int, int, int] | tuple[int, int, int, int] | None,
|
1004 |
+
) -> int:
|
1005 |
+
background = 0
|
1006 |
+
if info_background:
|
1007 |
+
if isinstance(info_background, tuple):
|
1008 |
+
# WebPImagePlugin stores an RGBA value in info["background"]
|
1009 |
+
# So it must be converted to the same format as GifImagePlugin's
|
1010 |
+
# info["background"] - a global color table index
|
1011 |
+
assert im.palette is not None
|
1012 |
+
try:
|
1013 |
+
background = im.palette.getcolor(info_background, im)
|
1014 |
+
except ValueError as e:
|
1015 |
+
if str(e) not in (
|
1016 |
+
# If all 256 colors are in use,
|
1017 |
+
# then there is no need for the background color
|
1018 |
+
"cannot allocate more than 256 colors",
|
1019 |
+
# Ignore non-opaque WebP background
|
1020 |
+
"cannot add non-opaque RGBA color to RGB palette",
|
1021 |
+
):
|
1022 |
+
raise
|
1023 |
+
else:
|
1024 |
+
background = info_background
|
1025 |
+
return background
|
1026 |
+
|
1027 |
+
|
1028 |
+
def _get_global_header(im: Image.Image, info: dict[str, Any]) -> list[bytes]:
|
1029 |
+
"""Return a list of strings representing a GIF header"""
|
1030 |
+
|
1031 |
+
# Header Block
|
1032 |
+
# https://www.matthewflickinger.com/lab/whatsinagif/bits_and_bytes.asp
|
1033 |
+
|
1034 |
+
version = b"87a"
|
1035 |
+
if im.info.get("version") == b"89a" or (
|
1036 |
+
info
|
1037 |
+
and (
|
1038 |
+
"transparency" in info
|
1039 |
+
or info.get("loop") is not None
|
1040 |
+
or info.get("duration")
|
1041 |
+
or info.get("comment")
|
1042 |
+
)
|
1043 |
+
):
|
1044 |
+
version = b"89a"
|
1045 |
+
|
1046 |
+
background = _get_background(im, info.get("background"))
|
1047 |
+
|
1048 |
+
palette_bytes = _get_palette_bytes(im)
|
1049 |
+
color_table_size = _get_color_table_size(palette_bytes)
|
1050 |
+
|
1051 |
+
header = [
|
1052 |
+
b"GIF" # signature
|
1053 |
+
+ version # version
|
1054 |
+
+ o16(im.size[0]) # canvas width
|
1055 |
+
+ o16(im.size[1]), # canvas height
|
1056 |
+
# Logical Screen Descriptor
|
1057 |
+
# size of global color table + global color table flag
|
1058 |
+
o8(color_table_size + 128), # packed fields
|
1059 |
+
# background + reserved/aspect
|
1060 |
+
o8(background) + o8(0),
|
1061 |
+
# Global Color Table
|
1062 |
+
_get_header_palette(palette_bytes),
|
1063 |
+
]
|
1064 |
+
if info.get("loop") is not None:
|
1065 |
+
header.append(
|
1066 |
+
b"!"
|
1067 |
+
+ o8(255) # extension intro
|
1068 |
+
+ o8(11)
|
1069 |
+
+ b"NETSCAPE2.0"
|
1070 |
+
+ o8(3)
|
1071 |
+
+ o8(1)
|
1072 |
+
+ o16(info["loop"]) # number of loops
|
1073 |
+
+ o8(0)
|
1074 |
+
)
|
1075 |
+
if info.get("comment"):
|
1076 |
+
comment_block = b"!" + o8(254) # extension intro
|
1077 |
+
|
1078 |
+
comment = info["comment"]
|
1079 |
+
if isinstance(comment, str):
|
1080 |
+
comment = comment.encode()
|
1081 |
+
for i in range(0, len(comment), 255):
|
1082 |
+
subblock = comment[i : i + 255]
|
1083 |
+
comment_block += o8(len(subblock)) + subblock
|
1084 |
+
|
1085 |
+
comment_block += o8(0)
|
1086 |
+
header.append(comment_block)
|
1087 |
+
return header
|
1088 |
+
|
1089 |
+
|
1090 |
+
def _write_frame_data(
|
1091 |
+
fp: IO[bytes],
|
1092 |
+
im_frame: Image.Image,
|
1093 |
+
offset: tuple[int, int],
|
1094 |
+
params: dict[str, Any],
|
1095 |
+
) -> None:
|
1096 |
+
try:
|
1097 |
+
im_frame.encoderinfo = params
|
1098 |
+
|
1099 |
+
# local image header
|
1100 |
+
_write_local_header(fp, im_frame, offset, 0)
|
1101 |
+
|
1102 |
+
ImageFile._save(
|
1103 |
+
im_frame,
|
1104 |
+
fp,
|
1105 |
+
[ImageFile._Tile("gif", (0, 0) + im_frame.size, 0, RAWMODE[im_frame.mode])],
|
1106 |
+
)
|
1107 |
+
|
1108 |
+
fp.write(b"\0") # end of image data
|
1109 |
+
finally:
|
1110 |
+
del im_frame.encoderinfo
|
1111 |
+
|
1112 |
+
|
1113 |
+
# --------------------------------------------------------------------
|
1114 |
+
# Legacy GIF utilities
|
1115 |
+
|
1116 |
+
|
1117 |
+
def getheader(
|
1118 |
+
im: Image.Image, palette: _Palette | None = None, info: dict[str, Any] | None = None
|
1119 |
+
) -> tuple[list[bytes], list[int] | None]:
|
1120 |
+
"""
|
1121 |
+
Legacy Method to get Gif data from image.
|
1122 |
+
|
1123 |
+
Warning:: May modify image data.
|
1124 |
+
|
1125 |
+
:param im: Image object
|
1126 |
+
:param palette: bytes object containing the source palette, or ....
|
1127 |
+
:param info: encoderinfo
|
1128 |
+
:returns: tuple of(list of header items, optimized palette)
|
1129 |
+
|
1130 |
+
"""
|
1131 |
+
if info is None:
|
1132 |
+
info = {}
|
1133 |
+
|
1134 |
+
used_palette_colors = _get_optimize(im, info)
|
1135 |
+
|
1136 |
+
if "background" not in info and "background" in im.info:
|
1137 |
+
info["background"] = im.info["background"]
|
1138 |
+
|
1139 |
+
im_mod = _normalize_palette(im, palette, info)
|
1140 |
+
im.palette = im_mod.palette
|
1141 |
+
im.im = im_mod.im
|
1142 |
+
header = _get_global_header(im, info)
|
1143 |
+
|
1144 |
+
return header, used_palette_colors
|
1145 |
+
|
1146 |
+
|
1147 |
+
def getdata(
|
1148 |
+
im: Image.Image, offset: tuple[int, int] = (0, 0), **params: Any
|
1149 |
+
) -> list[bytes]:
|
1150 |
+
"""
|
1151 |
+
Legacy Method
|
1152 |
+
|
1153 |
+
Return a list of strings representing this image.
|
1154 |
+
The first string is a local image header, the rest contains
|
1155 |
+
encoded image data.
|
1156 |
+
|
1157 |
+
To specify duration, add the time in milliseconds,
|
1158 |
+
e.g. ``getdata(im_frame, duration=1000)``
|
1159 |
+
|
1160 |
+
:param im: Image object
|
1161 |
+
:param offset: Tuple of (x, y) pixels. Defaults to (0, 0)
|
1162 |
+
:param \\**params: e.g. duration or other encoder info parameters
|
1163 |
+
:returns: List of bytes containing GIF encoded frame data
|
1164 |
+
|
1165 |
+
"""
|
1166 |
+
from io import BytesIO
|
1167 |
+
|
1168 |
+
class Collector(BytesIO):
|
1169 |
+
data = []
|
1170 |
+
|
1171 |
+
def write(self, data: Buffer) -> int:
|
1172 |
+
self.data.append(data)
|
1173 |
+
return len(data)
|
1174 |
+
|
1175 |
+
im.load() # make sure raster data is available
|
1176 |
+
|
1177 |
+
fp = Collector()
|
1178 |
+
|
1179 |
+
_write_frame_data(fp, im, offset, params)
|
1180 |
+
|
1181 |
+
return fp.data
|
1182 |
+
|
1183 |
+
|
1184 |
+
# --------------------------------------------------------------------
|
1185 |
+
# Registry
|
1186 |
+
|
1187 |
+
Image.register_open(GifImageFile.format, GifImageFile, _accept)
|
1188 |
+
Image.register_save(GifImageFile.format, _save)
|
1189 |
+
Image.register_save_all(GifImageFile.format, _save_all)
|
1190 |
+
Image.register_extension(GifImageFile.format, ".gif")
|
1191 |
+
Image.register_mime(GifImageFile.format, "image/gif")
|
1192 |
+
|
1193 |
+
#
|
1194 |
+
# Uncomment the following line if you wish to use NETPBM/PBMPLUS
|
1195 |
+
# instead of the built-in "uncompressed" GIF encoder
|
1196 |
+
|
1197 |
+
# Image.register_save(GifImageFile.format, _save_netpbm)
|
env-my/Lib/site-packages/PIL/GimpGradientFile.py
ADDED
@@ -0,0 +1,149 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#
|
2 |
+
# Python Imaging Library
|
3 |
+
# $Id$
|
4 |
+
#
|
5 |
+
# stuff to read (and render) GIMP gradient files
|
6 |
+
#
|
7 |
+
# History:
|
8 |
+
# 97-08-23 fl Created
|
9 |
+
#
|
10 |
+
# Copyright (c) Secret Labs AB 1997.
|
11 |
+
# Copyright (c) Fredrik Lundh 1997.
|
12 |
+
#
|
13 |
+
# See the README file for information on usage and redistribution.
|
14 |
+
#
|
15 |
+
|
16 |
+
"""
|
17 |
+
Stuff to translate curve segments to palette values (derived from
|
18 |
+
the corresponding code in GIMP, written by Federico Mena Quintero.
|
19 |
+
See the GIMP distribution for more information.)
|
20 |
+
"""
|
21 |
+
from __future__ import annotations
|
22 |
+
|
23 |
+
from math import log, pi, sin, sqrt
|
24 |
+
from typing import IO, Callable
|
25 |
+
|
26 |
+
from ._binary import o8
|
27 |
+
|
28 |
+
EPSILON = 1e-10
|
29 |
+
"""""" # Enable auto-doc for data member
|
30 |
+
|
31 |
+
|
32 |
+
def linear(middle: float, pos: float) -> float:
|
33 |
+
if pos <= middle:
|
34 |
+
if middle < EPSILON:
|
35 |
+
return 0.0
|
36 |
+
else:
|
37 |
+
return 0.5 * pos / middle
|
38 |
+
else:
|
39 |
+
pos = pos - middle
|
40 |
+
middle = 1.0 - middle
|
41 |
+
if middle < EPSILON:
|
42 |
+
return 1.0
|
43 |
+
else:
|
44 |
+
return 0.5 + 0.5 * pos / middle
|
45 |
+
|
46 |
+
|
47 |
+
def curved(middle: float, pos: float) -> float:
|
48 |
+
return pos ** (log(0.5) / log(max(middle, EPSILON)))
|
49 |
+
|
50 |
+
|
51 |
+
def sine(middle: float, pos: float) -> float:
|
52 |
+
return (sin((-pi / 2.0) + pi * linear(middle, pos)) + 1.0) / 2.0
|
53 |
+
|
54 |
+
|
55 |
+
def sphere_increasing(middle: float, pos: float) -> float:
|
56 |
+
return sqrt(1.0 - (linear(middle, pos) - 1.0) ** 2)
|
57 |
+
|
58 |
+
|
59 |
+
def sphere_decreasing(middle: float, pos: float) -> float:
|
60 |
+
return 1.0 - sqrt(1.0 - linear(middle, pos) ** 2)
|
61 |
+
|
62 |
+
|
63 |
+
SEGMENTS = [linear, curved, sine, sphere_increasing, sphere_decreasing]
|
64 |
+
"""""" # Enable auto-doc for data member
|
65 |
+
|
66 |
+
|
67 |
+
class GradientFile:
|
68 |
+
gradient: (
|
69 |
+
list[
|
70 |
+
tuple[
|
71 |
+
float,
|
72 |
+
float,
|
73 |
+
float,
|
74 |
+
list[float],
|
75 |
+
list[float],
|
76 |
+
Callable[[float, float], float],
|
77 |
+
]
|
78 |
+
]
|
79 |
+
| None
|
80 |
+
) = None
|
81 |
+
|
82 |
+
def getpalette(self, entries: int = 256) -> tuple[bytes, str]:
|
83 |
+
assert self.gradient is not None
|
84 |
+
palette = []
|
85 |
+
|
86 |
+
ix = 0
|
87 |
+
x0, x1, xm, rgb0, rgb1, segment = self.gradient[ix]
|
88 |
+
|
89 |
+
for i in range(entries):
|
90 |
+
x = i / (entries - 1)
|
91 |
+
|
92 |
+
while x1 < x:
|
93 |
+
ix += 1
|
94 |
+
x0, x1, xm, rgb0, rgb1, segment = self.gradient[ix]
|
95 |
+
|
96 |
+
w = x1 - x0
|
97 |
+
|
98 |
+
if w < EPSILON:
|
99 |
+
scale = segment(0.5, 0.5)
|
100 |
+
else:
|
101 |
+
scale = segment((xm - x0) / w, (x - x0) / w)
|
102 |
+
|
103 |
+
# expand to RGBA
|
104 |
+
r = o8(int(255 * ((rgb1[0] - rgb0[0]) * scale + rgb0[0]) + 0.5))
|
105 |
+
g = o8(int(255 * ((rgb1[1] - rgb0[1]) * scale + rgb0[1]) + 0.5))
|
106 |
+
b = o8(int(255 * ((rgb1[2] - rgb0[2]) * scale + rgb0[2]) + 0.5))
|
107 |
+
a = o8(int(255 * ((rgb1[3] - rgb0[3]) * scale + rgb0[3]) + 0.5))
|
108 |
+
|
109 |
+
# add to palette
|
110 |
+
palette.append(r + g + b + a)
|
111 |
+
|
112 |
+
return b"".join(palette), "RGBA"
|
113 |
+
|
114 |
+
|
115 |
+
class GimpGradientFile(GradientFile):
|
116 |
+
"""File handler for GIMP's gradient format."""
|
117 |
+
|
118 |
+
def __init__(self, fp: IO[bytes]) -> None:
|
119 |
+
if fp.readline()[:13] != b"GIMP Gradient":
|
120 |
+
msg = "not a GIMP gradient file"
|
121 |
+
raise SyntaxError(msg)
|
122 |
+
|
123 |
+
line = fp.readline()
|
124 |
+
|
125 |
+
# GIMP 1.2 gradient files don't contain a name, but GIMP 1.3 files do
|
126 |
+
if line.startswith(b"Name: "):
|
127 |
+
line = fp.readline().strip()
|
128 |
+
|
129 |
+
count = int(line)
|
130 |
+
|
131 |
+
self.gradient = []
|
132 |
+
|
133 |
+
for i in range(count):
|
134 |
+
s = fp.readline().split()
|
135 |
+
w = [float(x) for x in s[:11]]
|
136 |
+
|
137 |
+
x0, x1 = w[0], w[2]
|
138 |
+
xm = w[1]
|
139 |
+
rgb0 = w[3:7]
|
140 |
+
rgb1 = w[7:11]
|
141 |
+
|
142 |
+
segment = SEGMENTS[int(s[11])]
|
143 |
+
cspace = int(s[12])
|
144 |
+
|
145 |
+
if cspace != 0:
|
146 |
+
msg = "cannot handle HSV colour space"
|
147 |
+
raise OSError(msg)
|
148 |
+
|
149 |
+
self.gradient.append((x0, x1, xm, rgb0, rgb1, segment))
|
env-my/Lib/site-packages/PIL/GimpPaletteFile.py
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#
|
2 |
+
# Python Imaging Library
|
3 |
+
# $Id$
|
4 |
+
#
|
5 |
+
# stuff to read GIMP palette files
|
6 |
+
#
|
7 |
+
# History:
|
8 |
+
# 1997-08-23 fl Created
|
9 |
+
# 2004-09-07 fl Support GIMP 2.0 palette files.
|
10 |
+
#
|
11 |
+
# Copyright (c) Secret Labs AB 1997-2004. All rights reserved.
|
12 |
+
# Copyright (c) Fredrik Lundh 1997-2004.
|
13 |
+
#
|
14 |
+
# See the README file for information on usage and redistribution.
|
15 |
+
#
|
16 |
+
from __future__ import annotations
|
17 |
+
|
18 |
+
import re
|
19 |
+
from typing import IO
|
20 |
+
|
21 |
+
from ._binary import o8
|
22 |
+
|
23 |
+
|
24 |
+
class GimpPaletteFile:
|
25 |
+
"""File handler for GIMP's palette format."""
|
26 |
+
|
27 |
+
rawmode = "RGB"
|
28 |
+
|
29 |
+
def __init__(self, fp: IO[bytes]) -> None:
|
30 |
+
palette = [o8(i) * 3 for i in range(256)]
|
31 |
+
|
32 |
+
if fp.readline()[:12] != b"GIMP Palette":
|
33 |
+
msg = "not a GIMP palette file"
|
34 |
+
raise SyntaxError(msg)
|
35 |
+
|
36 |
+
for i in range(256):
|
37 |
+
s = fp.readline()
|
38 |
+
if not s:
|
39 |
+
break
|
40 |
+
|
41 |
+
# skip fields and comment lines
|
42 |
+
if re.match(rb"\w+:|#", s):
|
43 |
+
continue
|
44 |
+
if len(s) > 100:
|
45 |
+
msg = "bad palette file"
|
46 |
+
raise SyntaxError(msg)
|
47 |
+
|
48 |
+
v = tuple(map(int, s.split()[:3]))
|
49 |
+
if len(v) != 3:
|
50 |
+
msg = "bad palette entry"
|
51 |
+
raise ValueError(msg)
|
52 |
+
|
53 |
+
palette[i] = o8(v[0]) + o8(v[1]) + o8(v[2])
|
54 |
+
|
55 |
+
self.palette = b"".join(palette)
|
56 |
+
|
57 |
+
def getpalette(self) -> tuple[bytes, str]:
|
58 |
+
return self.palette, self.rawmode
|
env-my/Lib/site-packages/PIL/GribStubImagePlugin.py
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#
|
2 |
+
# The Python Imaging Library
|
3 |
+
# $Id$
|
4 |
+
#
|
5 |
+
# GRIB stub adapter
|
6 |
+
#
|
7 |
+
# Copyright (c) 1996-2003 by Fredrik Lundh
|
8 |
+
#
|
9 |
+
# See the README file for information on usage and redistribution.
|
10 |
+
#
|
11 |
+
from __future__ import annotations
|
12 |
+
|
13 |
+
from typing import IO
|
14 |
+
|
15 |
+
from . import Image, ImageFile
|
16 |
+
|
17 |
+
_handler = None
|
18 |
+
|
19 |
+
|
20 |
+
def register_handler(handler: ImageFile.StubHandler | None) -> None:
|
21 |
+
"""
|
22 |
+
Install application-specific GRIB image handler.
|
23 |
+
|
24 |
+
:param handler: Handler object.
|
25 |
+
"""
|
26 |
+
global _handler
|
27 |
+
_handler = handler
|
28 |
+
|
29 |
+
|
30 |
+
# --------------------------------------------------------------------
|
31 |
+
# Image adapter
|
32 |
+
|
33 |
+
|
34 |
+
def _accept(prefix: bytes) -> bool:
|
35 |
+
return prefix[:4] == b"GRIB" and prefix[7] == 1
|
36 |
+
|
37 |
+
|
38 |
+
class GribStubImageFile(ImageFile.StubImageFile):
|
39 |
+
format = "GRIB"
|
40 |
+
format_description = "GRIB"
|
41 |
+
|
42 |
+
def _open(self) -> None:
|
43 |
+
offset = self.fp.tell()
|
44 |
+
|
45 |
+
if not _accept(self.fp.read(8)):
|
46 |
+
msg = "Not a GRIB file"
|
47 |
+
raise SyntaxError(msg)
|
48 |
+
|
49 |
+
self.fp.seek(offset)
|
50 |
+
|
51 |
+
# make something up
|
52 |
+
self._mode = "F"
|
53 |
+
self._size = 1, 1
|
54 |
+
|
55 |
+
loader = self._load()
|
56 |
+
if loader:
|
57 |
+
loader.open(self)
|
58 |
+
|
59 |
+
def _load(self) -> ImageFile.StubHandler | None:
|
60 |
+
return _handler
|
61 |
+
|
62 |
+
|
63 |
+
def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
|
64 |
+
if _handler is None or not hasattr(_handler, "save"):
|
65 |
+
msg = "GRIB save handler not installed"
|
66 |
+
raise OSError(msg)
|
67 |
+
_handler.save(im, fp, filename)
|
68 |
+
|
69 |
+
|
70 |
+
# --------------------------------------------------------------------
|
71 |
+
# Registry
|
72 |
+
|
73 |
+
Image.register_open(GribStubImageFile.format, GribStubImageFile, _accept)
|
74 |
+
Image.register_save(GribStubImageFile.format, _save)
|
75 |
+
|
76 |
+
Image.register_extension(GribStubImageFile.format, ".grib")
|
env-my/Lib/site-packages/PIL/Hdf5StubImagePlugin.py
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#
|
2 |
+
# The Python Imaging Library
|
3 |
+
# $Id$
|
4 |
+
#
|
5 |
+
# HDF5 stub adapter
|
6 |
+
#
|
7 |
+
# Copyright (c) 2000-2003 by Fredrik Lundh
|
8 |
+
#
|
9 |
+
# See the README file for information on usage and redistribution.
|
10 |
+
#
|
11 |
+
from __future__ import annotations
|
12 |
+
|
13 |
+
from typing import IO
|
14 |
+
|
15 |
+
from . import Image, ImageFile
|
16 |
+
|
17 |
+
_handler = None
|
18 |
+
|
19 |
+
|
20 |
+
def register_handler(handler: ImageFile.StubHandler | None) -> None:
|
21 |
+
"""
|
22 |
+
Install application-specific HDF5 image handler.
|
23 |
+
|
24 |
+
:param handler: Handler object.
|
25 |
+
"""
|
26 |
+
global _handler
|
27 |
+
_handler = handler
|
28 |
+
|
29 |
+
|
30 |
+
# --------------------------------------------------------------------
|
31 |
+
# Image adapter
|
32 |
+
|
33 |
+
|
34 |
+
def _accept(prefix: bytes) -> bool:
|
35 |
+
return prefix[:8] == b"\x89HDF\r\n\x1a\n"
|
36 |
+
|
37 |
+
|
38 |
+
class HDF5StubImageFile(ImageFile.StubImageFile):
|
39 |
+
format = "HDF5"
|
40 |
+
format_description = "HDF5"
|
41 |
+
|
42 |
+
def _open(self) -> None:
|
43 |
+
offset = self.fp.tell()
|
44 |
+
|
45 |
+
if not _accept(self.fp.read(8)):
|
46 |
+
msg = "Not an HDF file"
|
47 |
+
raise SyntaxError(msg)
|
48 |
+
|
49 |
+
self.fp.seek(offset)
|
50 |
+
|
51 |
+
# make something up
|
52 |
+
self._mode = "F"
|
53 |
+
self._size = 1, 1
|
54 |
+
|
55 |
+
loader = self._load()
|
56 |
+
if loader:
|
57 |
+
loader.open(self)
|
58 |
+
|
59 |
+
def _load(self) -> ImageFile.StubHandler | None:
|
60 |
+
return _handler
|
61 |
+
|
62 |
+
|
63 |
+
def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
|
64 |
+
if _handler is None or not hasattr(_handler, "save"):
|
65 |
+
msg = "HDF5 save handler not installed"
|
66 |
+
raise OSError(msg)
|
67 |
+
_handler.save(im, fp, filename)
|
68 |
+
|
69 |
+
|
70 |
+
# --------------------------------------------------------------------
|
71 |
+
# Registry
|
72 |
+
|
73 |
+
Image.register_open(HDF5StubImageFile.format, HDF5StubImageFile, _accept)
|
74 |
+
Image.register_save(HDF5StubImageFile.format, _save)
|
75 |
+
|
76 |
+
Image.register_extensions(HDF5StubImageFile.format, [".h5", ".hdf"])
|
env-my/Lib/site-packages/PIL/IcnsImagePlugin.py
ADDED
@@ -0,0 +1,412 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#
|
2 |
+
# The Python Imaging Library.
|
3 |
+
# $Id$
|
4 |
+
#
|
5 |
+
# macOS icns file decoder, based on icns.py by Bob Ippolito.
|
6 |
+
#
|
7 |
+
# history:
|
8 |
+
# 2004-10-09 fl Turned into a PIL plugin; removed 2.3 dependencies.
|
9 |
+
# 2020-04-04 Allow saving on all operating systems.
|
10 |
+
#
|
11 |
+
# Copyright (c) 2004 by Bob Ippolito.
|
12 |
+
# Copyright (c) 2004 by Secret Labs.
|
13 |
+
# Copyright (c) 2004 by Fredrik Lundh.
|
14 |
+
# Copyright (c) 2014 by Alastair Houghton.
|
15 |
+
# Copyright (c) 2020 by Pan Jing.
|
16 |
+
#
|
17 |
+
# See the README file for information on usage and redistribution.
|
18 |
+
#
|
19 |
+
from __future__ import annotations
|
20 |
+
|
21 |
+
import io
|
22 |
+
import os
|
23 |
+
import struct
|
24 |
+
import sys
|
25 |
+
from typing import IO
|
26 |
+
|
27 |
+
from . import Image, ImageFile, PngImagePlugin, features
|
28 |
+
from ._deprecate import deprecate
|
29 |
+
|
30 |
+
enable_jpeg2k = features.check_codec("jpg_2000")
|
31 |
+
if enable_jpeg2k:
|
32 |
+
from . import Jpeg2KImagePlugin
|
33 |
+
|
34 |
+
MAGIC = b"icns"
|
35 |
+
HEADERSIZE = 8
|
36 |
+
|
37 |
+
|
38 |
+
def nextheader(fobj: IO[bytes]) -> tuple[bytes, int]:
|
39 |
+
return struct.unpack(">4sI", fobj.read(HEADERSIZE))
|
40 |
+
|
41 |
+
|
42 |
+
def read_32t(
|
43 |
+
fobj: IO[bytes], start_length: tuple[int, int], size: tuple[int, int, int]
|
44 |
+
) -> dict[str, Image.Image]:
|
45 |
+
# The 128x128 icon seems to have an extra header for some reason.
|
46 |
+
(start, length) = start_length
|
47 |
+
fobj.seek(start)
|
48 |
+
sig = fobj.read(4)
|
49 |
+
if sig != b"\x00\x00\x00\x00":
|
50 |
+
msg = "Unknown signature, expecting 0x00000000"
|
51 |
+
raise SyntaxError(msg)
|
52 |
+
return read_32(fobj, (start + 4, length - 4), size)
|
53 |
+
|
54 |
+
|
55 |
+
def read_32(
|
56 |
+
fobj: IO[bytes], start_length: tuple[int, int], size: tuple[int, int, int]
|
57 |
+
) -> dict[str, Image.Image]:
|
58 |
+
"""
|
59 |
+
Read a 32bit RGB icon resource. Seems to be either uncompressed or
|
60 |
+
an RLE packbits-like scheme.
|
61 |
+
"""
|
62 |
+
(start, length) = start_length
|
63 |
+
fobj.seek(start)
|
64 |
+
pixel_size = (size[0] * size[2], size[1] * size[2])
|
65 |
+
sizesq = pixel_size[0] * pixel_size[1]
|
66 |
+
if length == sizesq * 3:
|
67 |
+
# uncompressed ("RGBRGBGB")
|
68 |
+
indata = fobj.read(length)
|
69 |
+
im = Image.frombuffer("RGB", pixel_size, indata, "raw", "RGB", 0, 1)
|
70 |
+
else:
|
71 |
+
# decode image
|
72 |
+
im = Image.new("RGB", pixel_size, None)
|
73 |
+
for band_ix in range(3):
|
74 |
+
data = []
|
75 |
+
bytesleft = sizesq
|
76 |
+
while bytesleft > 0:
|
77 |
+
byte = fobj.read(1)
|
78 |
+
if not byte:
|
79 |
+
break
|
80 |
+
byte_int = byte[0]
|
81 |
+
if byte_int & 0x80:
|
82 |
+
blocksize = byte_int - 125
|
83 |
+
byte = fobj.read(1)
|
84 |
+
for i in range(blocksize):
|
85 |
+
data.append(byte)
|
86 |
+
else:
|
87 |
+
blocksize = byte_int + 1
|
88 |
+
data.append(fobj.read(blocksize))
|
89 |
+
bytesleft -= blocksize
|
90 |
+
if bytesleft <= 0:
|
91 |
+
break
|
92 |
+
if bytesleft != 0:
|
93 |
+
msg = f"Error reading channel [{repr(bytesleft)} left]"
|
94 |
+
raise SyntaxError(msg)
|
95 |
+
band = Image.frombuffer("L", pixel_size, b"".join(data), "raw", "L", 0, 1)
|
96 |
+
im.im.putband(band.im, band_ix)
|
97 |
+
return {"RGB": im}
|
98 |
+
|
99 |
+
|
100 |
+
def read_mk(
|
101 |
+
fobj: IO[bytes], start_length: tuple[int, int], size: tuple[int, int, int]
|
102 |
+
) -> dict[str, Image.Image]:
|
103 |
+
# Alpha masks seem to be uncompressed
|
104 |
+
start = start_length[0]
|
105 |
+
fobj.seek(start)
|
106 |
+
pixel_size = (size[0] * size[2], size[1] * size[2])
|
107 |
+
sizesq = pixel_size[0] * pixel_size[1]
|
108 |
+
band = Image.frombuffer("L", pixel_size, fobj.read(sizesq), "raw", "L", 0, 1)
|
109 |
+
return {"A": band}
|
110 |
+
|
111 |
+
|
112 |
+
def read_png_or_jpeg2000(
|
113 |
+
fobj: IO[bytes], start_length: tuple[int, int], size: tuple[int, int, int]
|
114 |
+
) -> dict[str, Image.Image]:
|
115 |
+
(start, length) = start_length
|
116 |
+
fobj.seek(start)
|
117 |
+
sig = fobj.read(12)
|
118 |
+
|
119 |
+
im: Image.Image
|
120 |
+
if sig[:8] == b"\x89PNG\x0d\x0a\x1a\x0a":
|
121 |
+
fobj.seek(start)
|
122 |
+
im = PngImagePlugin.PngImageFile(fobj)
|
123 |
+
Image._decompression_bomb_check(im.size)
|
124 |
+
return {"RGBA": im}
|
125 |
+
elif (
|
126 |
+
sig[:4] == b"\xff\x4f\xff\x51"
|
127 |
+
or sig[:4] == b"\x0d\x0a\x87\x0a"
|
128 |
+
or sig == b"\x00\x00\x00\x0cjP \x0d\x0a\x87\x0a"
|
129 |
+
):
|
130 |
+
if not enable_jpeg2k:
|
131 |
+
msg = (
|
132 |
+
"Unsupported icon subimage format (rebuild PIL "
|
133 |
+
"with JPEG 2000 support to fix this)"
|
134 |
+
)
|
135 |
+
raise ValueError(msg)
|
136 |
+
# j2k, jpc or j2c
|
137 |
+
fobj.seek(start)
|
138 |
+
jp2kstream = fobj.read(length)
|
139 |
+
f = io.BytesIO(jp2kstream)
|
140 |
+
im = Jpeg2KImagePlugin.Jpeg2KImageFile(f)
|
141 |
+
Image._decompression_bomb_check(im.size)
|
142 |
+
if im.mode != "RGBA":
|
143 |
+
im = im.convert("RGBA")
|
144 |
+
return {"RGBA": im}
|
145 |
+
else:
|
146 |
+
msg = "Unsupported icon subimage format"
|
147 |
+
raise ValueError(msg)
|
148 |
+
|
149 |
+
|
150 |
+
class IcnsFile:
|
151 |
+
SIZES = {
|
152 |
+
(512, 512, 2): [(b"ic10", read_png_or_jpeg2000)],
|
153 |
+
(512, 512, 1): [(b"ic09", read_png_or_jpeg2000)],
|
154 |
+
(256, 256, 2): [(b"ic14", read_png_or_jpeg2000)],
|
155 |
+
(256, 256, 1): [(b"ic08", read_png_or_jpeg2000)],
|
156 |
+
(128, 128, 2): [(b"ic13", read_png_or_jpeg2000)],
|
157 |
+
(128, 128, 1): [
|
158 |
+
(b"ic07", read_png_or_jpeg2000),
|
159 |
+
(b"it32", read_32t),
|
160 |
+
(b"t8mk", read_mk),
|
161 |
+
],
|
162 |
+
(64, 64, 1): [(b"icp6", read_png_or_jpeg2000)],
|
163 |
+
(32, 32, 2): [(b"ic12", read_png_or_jpeg2000)],
|
164 |
+
(48, 48, 1): [(b"ih32", read_32), (b"h8mk", read_mk)],
|
165 |
+
(32, 32, 1): [
|
166 |
+
(b"icp5", read_png_or_jpeg2000),
|
167 |
+
(b"il32", read_32),
|
168 |
+
(b"l8mk", read_mk),
|
169 |
+
],
|
170 |
+
(16, 16, 2): [(b"ic11", read_png_or_jpeg2000)],
|
171 |
+
(16, 16, 1): [
|
172 |
+
(b"icp4", read_png_or_jpeg2000),
|
173 |
+
(b"is32", read_32),
|
174 |
+
(b"s8mk", read_mk),
|
175 |
+
],
|
176 |
+
}
|
177 |
+
|
178 |
+
def __init__(self, fobj: IO[bytes]) -> None:
|
179 |
+
"""
|
180 |
+
fobj is a file-like object as an icns resource
|
181 |
+
"""
|
182 |
+
# signature : (start, length)
|
183 |
+
self.dct = {}
|
184 |
+
self.fobj = fobj
|
185 |
+
sig, filesize = nextheader(fobj)
|
186 |
+
if not _accept(sig):
|
187 |
+
msg = "not an icns file"
|
188 |
+
raise SyntaxError(msg)
|
189 |
+
i = HEADERSIZE
|
190 |
+
while i < filesize:
|
191 |
+
sig, blocksize = nextheader(fobj)
|
192 |
+
if blocksize <= 0:
|
193 |
+
msg = "invalid block header"
|
194 |
+
raise SyntaxError(msg)
|
195 |
+
i += HEADERSIZE
|
196 |
+
blocksize -= HEADERSIZE
|
197 |
+
self.dct[sig] = (i, blocksize)
|
198 |
+
fobj.seek(blocksize, io.SEEK_CUR)
|
199 |
+
i += blocksize
|
200 |
+
|
201 |
+
def itersizes(self) -> list[tuple[int, int, int]]:
|
202 |
+
sizes = []
|
203 |
+
for size, fmts in self.SIZES.items():
|
204 |
+
for fmt, reader in fmts:
|
205 |
+
if fmt in self.dct:
|
206 |
+
sizes.append(size)
|
207 |
+
break
|
208 |
+
return sizes
|
209 |
+
|
210 |
+
def bestsize(self) -> tuple[int, int, int]:
|
211 |
+
sizes = self.itersizes()
|
212 |
+
if not sizes:
|
213 |
+
msg = "No 32bit icon resources found"
|
214 |
+
raise SyntaxError(msg)
|
215 |
+
return max(sizes)
|
216 |
+
|
217 |
+
def dataforsize(self, size: tuple[int, int, int]) -> dict[str, Image.Image]:
|
218 |
+
"""
|
219 |
+
Get an icon resource as {channel: array}. Note that
|
220 |
+
the arrays are bottom-up like windows bitmaps and will likely
|
221 |
+
need to be flipped or transposed in some way.
|
222 |
+
"""
|
223 |
+
dct = {}
|
224 |
+
for code, reader in self.SIZES[size]:
|
225 |
+
desc = self.dct.get(code)
|
226 |
+
if desc is not None:
|
227 |
+
dct.update(reader(self.fobj, desc, size))
|
228 |
+
return dct
|
229 |
+
|
230 |
+
def getimage(
|
231 |
+
self, size: tuple[int, int] | tuple[int, int, int] | None = None
|
232 |
+
) -> Image.Image:
|
233 |
+
if size is None:
|
234 |
+
size = self.bestsize()
|
235 |
+
elif len(size) == 2:
|
236 |
+
size = (size[0], size[1], 1)
|
237 |
+
channels = self.dataforsize(size)
|
238 |
+
|
239 |
+
im = channels.get("RGBA")
|
240 |
+
if im:
|
241 |
+
return im
|
242 |
+
|
243 |
+
im = channels["RGB"].copy()
|
244 |
+
try:
|
245 |
+
im.putalpha(channels["A"])
|
246 |
+
except KeyError:
|
247 |
+
pass
|
248 |
+
return im
|
249 |
+
|
250 |
+
|
251 |
+
##
|
252 |
+
# Image plugin for Mac OS icons.
|
253 |
+
|
254 |
+
|
255 |
+
class IcnsImageFile(ImageFile.ImageFile):
|
256 |
+
"""
|
257 |
+
PIL image support for Mac OS .icns files.
|
258 |
+
Chooses the best resolution, but will possibly load
|
259 |
+
a different size image if you mutate the size attribute
|
260 |
+
before calling 'load'.
|
261 |
+
|
262 |
+
The info dictionary has a key 'sizes' that is a list
|
263 |
+
of sizes that the icns file has.
|
264 |
+
"""
|
265 |
+
|
266 |
+
format = "ICNS"
|
267 |
+
format_description = "Mac OS icns resource"
|
268 |
+
|
269 |
+
def _open(self) -> None:
|
270 |
+
self.icns = IcnsFile(self.fp)
|
271 |
+
self._mode = "RGBA"
|
272 |
+
self.info["sizes"] = self.icns.itersizes()
|
273 |
+
self.best_size = self.icns.bestsize()
|
274 |
+
self.size = (
|
275 |
+
self.best_size[0] * self.best_size[2],
|
276 |
+
self.best_size[1] * self.best_size[2],
|
277 |
+
)
|
278 |
+
|
279 |
+
@property # type: ignore[override]
|
280 |
+
def size(self) -> tuple[int, int] | tuple[int, int, int]:
|
281 |
+
return self._size
|
282 |
+
|
283 |
+
@size.setter
|
284 |
+
def size(self, value: tuple[int, int] | tuple[int, int, int]) -> None:
|
285 |
+
if len(value) == 3:
|
286 |
+
deprecate("Setting size to (width, height, scale)", 12, "load(scale)")
|
287 |
+
if value in self.info["sizes"]:
|
288 |
+
self._size = value # type: ignore[assignment]
|
289 |
+
return
|
290 |
+
else:
|
291 |
+
# Check that a matching size exists,
|
292 |
+
# or that there is a scale that would create a size that matches
|
293 |
+
for size in self.info["sizes"]:
|
294 |
+
simple_size = size[0] * size[2], size[1] * size[2]
|
295 |
+
scale = simple_size[0] // value[0]
|
296 |
+
if simple_size[1] / value[1] == scale:
|
297 |
+
self._size = value
|
298 |
+
return
|
299 |
+
msg = "This is not one of the allowed sizes of this image"
|
300 |
+
raise ValueError(msg)
|
301 |
+
|
302 |
+
def load(self, scale: int | None = None) -> Image.core.PixelAccess | None:
|
303 |
+
if scale is not None or len(self.size) == 3:
|
304 |
+
if scale is None and len(self.size) == 3:
|
305 |
+
scale = self.size[2]
|
306 |
+
assert scale is not None
|
307 |
+
width, height = self.size[:2]
|
308 |
+
self.size = width * scale, height * scale
|
309 |
+
self.best_size = width, height, scale
|
310 |
+
|
311 |
+
px = Image.Image.load(self)
|
312 |
+
if self._im is not None and self.im.size == self.size:
|
313 |
+
# Already loaded
|
314 |
+
return px
|
315 |
+
self.load_prepare()
|
316 |
+
# This is likely NOT the best way to do it, but whatever.
|
317 |
+
im = self.icns.getimage(self.best_size)
|
318 |
+
|
319 |
+
# If this is a PNG or JPEG 2000, it won't be loaded yet
|
320 |
+
px = im.load()
|
321 |
+
|
322 |
+
self.im = im.im
|
323 |
+
self._mode = im.mode
|
324 |
+
self.size = im.size
|
325 |
+
|
326 |
+
return px
|
327 |
+
|
328 |
+
|
329 |
+
def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
|
330 |
+
"""
|
331 |
+
Saves the image as a series of PNG files,
|
332 |
+
that are then combined into a .icns file.
|
333 |
+
"""
|
334 |
+
if hasattr(fp, "flush"):
|
335 |
+
fp.flush()
|
336 |
+
|
337 |
+
sizes = {
|
338 |
+
b"ic07": 128,
|
339 |
+
b"ic08": 256,
|
340 |
+
b"ic09": 512,
|
341 |
+
b"ic10": 1024,
|
342 |
+
b"ic11": 32,
|
343 |
+
b"ic12": 64,
|
344 |
+
b"ic13": 256,
|
345 |
+
b"ic14": 512,
|
346 |
+
}
|
347 |
+
provided_images = {im.width: im for im in im.encoderinfo.get("append_images", [])}
|
348 |
+
size_streams = {}
|
349 |
+
for size in set(sizes.values()):
|
350 |
+
image = (
|
351 |
+
provided_images[size]
|
352 |
+
if size in provided_images
|
353 |
+
else im.resize((size, size))
|
354 |
+
)
|
355 |
+
|
356 |
+
temp = io.BytesIO()
|
357 |
+
image.save(temp, "png")
|
358 |
+
size_streams[size] = temp.getvalue()
|
359 |
+
|
360 |
+
entries = []
|
361 |
+
for type, size in sizes.items():
|
362 |
+
stream = size_streams[size]
|
363 |
+
entries.append((type, HEADERSIZE + len(stream), stream))
|
364 |
+
|
365 |
+
# Header
|
366 |
+
fp.write(MAGIC)
|
367 |
+
file_length = HEADERSIZE # Header
|
368 |
+
file_length += HEADERSIZE + 8 * len(entries) # TOC
|
369 |
+
file_length += sum(entry[1] for entry in entries)
|
370 |
+
fp.write(struct.pack(">i", file_length))
|
371 |
+
|
372 |
+
# TOC
|
373 |
+
fp.write(b"TOC ")
|
374 |
+
fp.write(struct.pack(">i", HEADERSIZE + len(entries) * HEADERSIZE))
|
375 |
+
for entry in entries:
|
376 |
+
fp.write(entry[0])
|
377 |
+
fp.write(struct.pack(">i", entry[1]))
|
378 |
+
|
379 |
+
# Data
|
380 |
+
for entry in entries:
|
381 |
+
fp.write(entry[0])
|
382 |
+
fp.write(struct.pack(">i", entry[1]))
|
383 |
+
fp.write(entry[2])
|
384 |
+
|
385 |
+
if hasattr(fp, "flush"):
|
386 |
+
fp.flush()
|
387 |
+
|
388 |
+
|
389 |
+
def _accept(prefix: bytes) -> bool:
|
390 |
+
return prefix[:4] == MAGIC
|
391 |
+
|
392 |
+
|
393 |
+
Image.register_open(IcnsImageFile.format, IcnsImageFile, _accept)
|
394 |
+
Image.register_extension(IcnsImageFile.format, ".icns")
|
395 |
+
|
396 |
+
Image.register_save(IcnsImageFile.format, _save)
|
397 |
+
Image.register_mime(IcnsImageFile.format, "image/icns")
|
398 |
+
|
399 |
+
if __name__ == "__main__":
|
400 |
+
if len(sys.argv) < 2:
|
401 |
+
print("Syntax: python3 IcnsImagePlugin.py [file]")
|
402 |
+
sys.exit()
|
403 |
+
|
404 |
+
with open(sys.argv[1], "rb") as fp:
|
405 |
+
imf = IcnsImageFile(fp)
|
406 |
+
for size in imf.info["sizes"]:
|
407 |
+
width, height, scale = imf.size = size
|
408 |
+
imf.save(f"out-{width}-{height}-{scale}.png")
|
409 |
+
with Image.open(sys.argv[1]) as im:
|
410 |
+
im.save("out.png")
|
411 |
+
if sys.platform == "windows":
|
412 |
+
os.startfile("out.png")
|
env-my/Lib/site-packages/PIL/IcoImagePlugin.py
ADDED
@@ -0,0 +1,381 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#
|
2 |
+
# The Python Imaging Library.
|
3 |
+
# $Id$
|
4 |
+
#
|
5 |
+
# Windows Icon support for PIL
|
6 |
+
#
|
7 |
+
# History:
|
8 |
+
# 96-05-27 fl Created
|
9 |
+
#
|
10 |
+
# Copyright (c) Secret Labs AB 1997.
|
11 |
+
# Copyright (c) Fredrik Lundh 1996.
|
12 |
+
#
|
13 |
+
# See the README file for information on usage and redistribution.
|
14 |
+
#
|
15 |
+
|
16 |
+
# This plugin is a refactored version of Win32IconImagePlugin by Bryan Davis
|
17 |
+
# <[email protected]>.
|
18 |
+
# https://code.google.com/archive/p/casadebender/wikis/Win32IconImagePlugin.wiki
|
19 |
+
#
|
20 |
+
# Icon format references:
|
21 |
+
# * https://en.wikipedia.org/wiki/ICO_(file_format)
|
22 |
+
# * https://msdn.microsoft.com/en-us/library/ms997538.aspx
|
23 |
+
from __future__ import annotations
|
24 |
+
|
25 |
+
import warnings
|
26 |
+
from io import BytesIO
|
27 |
+
from math import ceil, log
|
28 |
+
from typing import IO, NamedTuple
|
29 |
+
|
30 |
+
from . import BmpImagePlugin, Image, ImageFile, PngImagePlugin
|
31 |
+
from ._binary import i16le as i16
|
32 |
+
from ._binary import i32le as i32
|
33 |
+
from ._binary import o8
|
34 |
+
from ._binary import o16le as o16
|
35 |
+
from ._binary import o32le as o32
|
36 |
+
|
37 |
+
#
|
38 |
+
# --------------------------------------------------------------------
|
39 |
+
|
40 |
+
_MAGIC = b"\0\0\1\0"
|
41 |
+
|
42 |
+
|
43 |
+
def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
|
44 |
+
fp.write(_MAGIC) # (2+2)
|
45 |
+
bmp = im.encoderinfo.get("bitmap_format") == "bmp"
|
46 |
+
sizes = im.encoderinfo.get(
|
47 |
+
"sizes",
|
48 |
+
[(16, 16), (24, 24), (32, 32), (48, 48), (64, 64), (128, 128), (256, 256)],
|
49 |
+
)
|
50 |
+
frames = []
|
51 |
+
provided_ims = [im] + im.encoderinfo.get("append_images", [])
|
52 |
+
width, height = im.size
|
53 |
+
for size in sorted(set(sizes)):
|
54 |
+
if size[0] > width or size[1] > height or size[0] > 256 or size[1] > 256:
|
55 |
+
continue
|
56 |
+
|
57 |
+
for provided_im in provided_ims:
|
58 |
+
if provided_im.size != size:
|
59 |
+
continue
|
60 |
+
frames.append(provided_im)
|
61 |
+
if bmp:
|
62 |
+
bits = BmpImagePlugin.SAVE[provided_im.mode][1]
|
63 |
+
bits_used = [bits]
|
64 |
+
for other_im in provided_ims:
|
65 |
+
if other_im.size != size:
|
66 |
+
continue
|
67 |
+
bits = BmpImagePlugin.SAVE[other_im.mode][1]
|
68 |
+
if bits not in bits_used:
|
69 |
+
# Another image has been supplied for this size
|
70 |
+
# with a different bit depth
|
71 |
+
frames.append(other_im)
|
72 |
+
bits_used.append(bits)
|
73 |
+
break
|
74 |
+
else:
|
75 |
+
# TODO: invent a more convenient method for proportional scalings
|
76 |
+
frame = provided_im.copy()
|
77 |
+
frame.thumbnail(size, Image.Resampling.LANCZOS, reducing_gap=None)
|
78 |
+
frames.append(frame)
|
79 |
+
fp.write(o16(len(frames))) # idCount(2)
|
80 |
+
offset = fp.tell() + len(frames) * 16
|
81 |
+
for frame in frames:
|
82 |
+
width, height = frame.size
|
83 |
+
# 0 means 256
|
84 |
+
fp.write(o8(width if width < 256 else 0)) # bWidth(1)
|
85 |
+
fp.write(o8(height if height < 256 else 0)) # bHeight(1)
|
86 |
+
|
87 |
+
bits, colors = BmpImagePlugin.SAVE[frame.mode][1:] if bmp else (32, 0)
|
88 |
+
fp.write(o8(colors)) # bColorCount(1)
|
89 |
+
fp.write(b"\0") # bReserved(1)
|
90 |
+
fp.write(b"\0\0") # wPlanes(2)
|
91 |
+
fp.write(o16(bits)) # wBitCount(2)
|
92 |
+
|
93 |
+
image_io = BytesIO()
|
94 |
+
if bmp:
|
95 |
+
frame.save(image_io, "dib")
|
96 |
+
|
97 |
+
if bits != 32:
|
98 |
+
and_mask = Image.new("1", size)
|
99 |
+
ImageFile._save(
|
100 |
+
and_mask,
|
101 |
+
image_io,
|
102 |
+
[ImageFile._Tile("raw", (0, 0) + size, 0, ("1", 0, -1))],
|
103 |
+
)
|
104 |
+
else:
|
105 |
+
frame.save(image_io, "png")
|
106 |
+
image_io.seek(0)
|
107 |
+
image_bytes = image_io.read()
|
108 |
+
if bmp:
|
109 |
+
image_bytes = image_bytes[:8] + o32(height * 2) + image_bytes[12:]
|
110 |
+
bytes_len = len(image_bytes)
|
111 |
+
fp.write(o32(bytes_len)) # dwBytesInRes(4)
|
112 |
+
fp.write(o32(offset)) # dwImageOffset(4)
|
113 |
+
current = fp.tell()
|
114 |
+
fp.seek(offset)
|
115 |
+
fp.write(image_bytes)
|
116 |
+
offset = offset + bytes_len
|
117 |
+
fp.seek(current)
|
118 |
+
|
119 |
+
|
120 |
+
def _accept(prefix: bytes) -> bool:
|
121 |
+
return prefix[:4] == _MAGIC
|
122 |
+
|
123 |
+
|
124 |
+
class IconHeader(NamedTuple):
|
125 |
+
width: int
|
126 |
+
height: int
|
127 |
+
nb_color: int
|
128 |
+
reserved: int
|
129 |
+
planes: int
|
130 |
+
bpp: int
|
131 |
+
size: int
|
132 |
+
offset: int
|
133 |
+
dim: tuple[int, int]
|
134 |
+
square: int
|
135 |
+
color_depth: int
|
136 |
+
|
137 |
+
|
138 |
+
class IcoFile:
|
139 |
+
def __init__(self, buf: IO[bytes]) -> None:
|
140 |
+
"""
|
141 |
+
Parse image from file-like object containing ico file data
|
142 |
+
"""
|
143 |
+
|
144 |
+
# check magic
|
145 |
+
s = buf.read(6)
|
146 |
+
if not _accept(s):
|
147 |
+
msg = "not an ICO file"
|
148 |
+
raise SyntaxError(msg)
|
149 |
+
|
150 |
+
self.buf = buf
|
151 |
+
self.entry = []
|
152 |
+
|
153 |
+
# Number of items in file
|
154 |
+
self.nb_items = i16(s, 4)
|
155 |
+
|
156 |
+
# Get headers for each item
|
157 |
+
for i in range(self.nb_items):
|
158 |
+
s = buf.read(16)
|
159 |
+
|
160 |
+
# See Wikipedia
|
161 |
+
width = s[0] or 256
|
162 |
+
height = s[1] or 256
|
163 |
+
|
164 |
+
# No. of colors in image (0 if >=8bpp)
|
165 |
+
nb_color = s[2]
|
166 |
+
bpp = i16(s, 6)
|
167 |
+
icon_header = IconHeader(
|
168 |
+
width=width,
|
169 |
+
height=height,
|
170 |
+
nb_color=nb_color,
|
171 |
+
reserved=s[3],
|
172 |
+
planes=i16(s, 4),
|
173 |
+
bpp=i16(s, 6),
|
174 |
+
size=i32(s, 8),
|
175 |
+
offset=i32(s, 12),
|
176 |
+
dim=(width, height),
|
177 |
+
square=width * height,
|
178 |
+
# See Wikipedia notes about color depth.
|
179 |
+
# We need this just to differ images with equal sizes
|
180 |
+
color_depth=bpp or (nb_color != 0 and ceil(log(nb_color, 2))) or 256,
|
181 |
+
)
|
182 |
+
|
183 |
+
self.entry.append(icon_header)
|
184 |
+
|
185 |
+
self.entry = sorted(self.entry, key=lambda x: x.color_depth)
|
186 |
+
# ICO images are usually squares
|
187 |
+
self.entry = sorted(self.entry, key=lambda x: x.square, reverse=True)
|
188 |
+
|
189 |
+
def sizes(self) -> set[tuple[int, int]]:
|
190 |
+
"""
|
191 |
+
Get a set of all available icon sizes and color depths.
|
192 |
+
"""
|
193 |
+
return {(h.width, h.height) for h in self.entry}
|
194 |
+
|
195 |
+
def getentryindex(self, size: tuple[int, int], bpp: int | bool = False) -> int:
|
196 |
+
for i, h in enumerate(self.entry):
|
197 |
+
if size == h.dim and (bpp is False or bpp == h.color_depth):
|
198 |
+
return i
|
199 |
+
return 0
|
200 |
+
|
201 |
+
def getimage(self, size: tuple[int, int], bpp: int | bool = False) -> Image.Image:
|
202 |
+
"""
|
203 |
+
Get an image from the icon
|
204 |
+
"""
|
205 |
+
return self.frame(self.getentryindex(size, bpp))
|
206 |
+
|
207 |
+
def frame(self, idx: int) -> Image.Image:
|
208 |
+
"""
|
209 |
+
Get an image from frame idx
|
210 |
+
"""
|
211 |
+
|
212 |
+
header = self.entry[idx]
|
213 |
+
|
214 |
+
self.buf.seek(header.offset)
|
215 |
+
data = self.buf.read(8)
|
216 |
+
self.buf.seek(header.offset)
|
217 |
+
|
218 |
+
im: Image.Image
|
219 |
+
if data[:8] == PngImagePlugin._MAGIC:
|
220 |
+
# png frame
|
221 |
+
im = PngImagePlugin.PngImageFile(self.buf)
|
222 |
+
Image._decompression_bomb_check(im.size)
|
223 |
+
else:
|
224 |
+
# XOR + AND mask bmp frame
|
225 |
+
im = BmpImagePlugin.DibImageFile(self.buf)
|
226 |
+
Image._decompression_bomb_check(im.size)
|
227 |
+
|
228 |
+
# change tile dimension to only encompass XOR image
|
229 |
+
im._size = (im.size[0], int(im.size[1] / 2))
|
230 |
+
d, e, o, a = im.tile[0]
|
231 |
+
im.tile[0] = ImageFile._Tile(d, (0, 0) + im.size, o, a)
|
232 |
+
|
233 |
+
# figure out where AND mask image starts
|
234 |
+
if header.bpp == 32:
|
235 |
+
# 32-bit color depth icon image allows semitransparent areas
|
236 |
+
# PIL's DIB format ignores transparency bits, recover them.
|
237 |
+
# The DIB is packed in BGRX byte order where X is the alpha
|
238 |
+
# channel.
|
239 |
+
|
240 |
+
# Back up to start of bmp data
|
241 |
+
self.buf.seek(o)
|
242 |
+
# extract every 4th byte (eg. 3,7,11,15,...)
|
243 |
+
alpha_bytes = self.buf.read(im.size[0] * im.size[1] * 4)[3::4]
|
244 |
+
|
245 |
+
# convert to an 8bpp grayscale image
|
246 |
+
try:
|
247 |
+
mask = Image.frombuffer(
|
248 |
+
"L", # 8bpp
|
249 |
+
im.size, # (w, h)
|
250 |
+
alpha_bytes, # source chars
|
251 |
+
"raw", # raw decoder
|
252 |
+
("L", 0, -1), # 8bpp inverted, unpadded, reversed
|
253 |
+
)
|
254 |
+
except ValueError:
|
255 |
+
if ImageFile.LOAD_TRUNCATED_IMAGES:
|
256 |
+
mask = None
|
257 |
+
else:
|
258 |
+
raise
|
259 |
+
else:
|
260 |
+
# get AND image from end of bitmap
|
261 |
+
w = im.size[0]
|
262 |
+
if (w % 32) > 0:
|
263 |
+
# bitmap row data is aligned to word boundaries
|
264 |
+
w += 32 - (im.size[0] % 32)
|
265 |
+
|
266 |
+
# the total mask data is
|
267 |
+
# padded row size * height / bits per char
|
268 |
+
|
269 |
+
total_bytes = int((w * im.size[1]) / 8)
|
270 |
+
and_mask_offset = header.offset + header.size - total_bytes
|
271 |
+
|
272 |
+
self.buf.seek(and_mask_offset)
|
273 |
+
mask_data = self.buf.read(total_bytes)
|
274 |
+
|
275 |
+
# convert raw data to image
|
276 |
+
try:
|
277 |
+
mask = Image.frombuffer(
|
278 |
+
"1", # 1 bpp
|
279 |
+
im.size, # (w, h)
|
280 |
+
mask_data, # source chars
|
281 |
+
"raw", # raw decoder
|
282 |
+
("1;I", int(w / 8), -1), # 1bpp inverted, padded, reversed
|
283 |
+
)
|
284 |
+
except ValueError:
|
285 |
+
if ImageFile.LOAD_TRUNCATED_IMAGES:
|
286 |
+
mask = None
|
287 |
+
else:
|
288 |
+
raise
|
289 |
+
|
290 |
+
# now we have two images, im is XOR image and mask is AND image
|
291 |
+
|
292 |
+
# apply mask image as alpha channel
|
293 |
+
if mask:
|
294 |
+
im = im.convert("RGBA")
|
295 |
+
im.putalpha(mask)
|
296 |
+
|
297 |
+
return im
|
298 |
+
|
299 |
+
|
300 |
+
##
|
301 |
+
# Image plugin for Windows Icon files.
|
302 |
+
|
303 |
+
|
304 |
+
class IcoImageFile(ImageFile.ImageFile):
|
305 |
+
"""
|
306 |
+
PIL read-only image support for Microsoft Windows .ico files.
|
307 |
+
|
308 |
+
By default the largest resolution image in the file will be loaded. This
|
309 |
+
can be changed by altering the 'size' attribute before calling 'load'.
|
310 |
+
|
311 |
+
The info dictionary has a key 'sizes' that is a list of the sizes available
|
312 |
+
in the icon file.
|
313 |
+
|
314 |
+
Handles classic, XP and Vista icon formats.
|
315 |
+
|
316 |
+
When saving, PNG compression is used. Support for this was only added in
|
317 |
+
Windows Vista. If you are unable to view the icon in Windows, convert the
|
318 |
+
image to "RGBA" mode before saving.
|
319 |
+
|
320 |
+
This plugin is a refactored version of Win32IconImagePlugin by Bryan Davis
|
321 |
+
<[email protected]>.
|
322 |
+
https://code.google.com/archive/p/casadebender/wikis/Win32IconImagePlugin.wiki
|
323 |
+
"""
|
324 |
+
|
325 |
+
format = "ICO"
|
326 |
+
format_description = "Windows Icon"
|
327 |
+
|
328 |
+
def _open(self) -> None:
|
329 |
+
self.ico = IcoFile(self.fp)
|
330 |
+
self.info["sizes"] = self.ico.sizes()
|
331 |
+
self.size = self.ico.entry[0].dim
|
332 |
+
self.load()
|
333 |
+
|
334 |
+
@property
|
335 |
+
def size(self) -> tuple[int, int]:
|
336 |
+
return self._size
|
337 |
+
|
338 |
+
@size.setter
|
339 |
+
def size(self, value: tuple[int, int]) -> None:
|
340 |
+
if value not in self.info["sizes"]:
|
341 |
+
msg = "This is not one of the allowed sizes of this image"
|
342 |
+
raise ValueError(msg)
|
343 |
+
self._size = value
|
344 |
+
|
345 |
+
def load(self) -> Image.core.PixelAccess | None:
|
346 |
+
if self._im is not None and self.im.size == self.size:
|
347 |
+
# Already loaded
|
348 |
+
return Image.Image.load(self)
|
349 |
+
im = self.ico.getimage(self.size)
|
350 |
+
# if tile is PNG, it won't really be loaded yet
|
351 |
+
im.load()
|
352 |
+
self.im = im.im
|
353 |
+
self._mode = im.mode
|
354 |
+
if im.palette:
|
355 |
+
self.palette = im.palette
|
356 |
+
if im.size != self.size:
|
357 |
+
warnings.warn("Image was not the expected size")
|
358 |
+
|
359 |
+
index = self.ico.getentryindex(self.size)
|
360 |
+
sizes = list(self.info["sizes"])
|
361 |
+
sizes[index] = im.size
|
362 |
+
self.info["sizes"] = set(sizes)
|
363 |
+
|
364 |
+
self.size = im.size
|
365 |
+
return None
|
366 |
+
|
367 |
+
def load_seek(self, pos: int) -> None:
|
368 |
+
# Flag the ImageFile.Parser so that it
|
369 |
+
# just does all the decode at the end.
|
370 |
+
pass
|
371 |
+
|
372 |
+
|
373 |
+
#
|
374 |
+
# --------------------------------------------------------------------
|
375 |
+
|
376 |
+
|
377 |
+
Image.register_open(IcoImageFile.format, IcoImageFile, _accept)
|
378 |
+
Image.register_save(IcoImageFile.format, _save)
|
379 |
+
Image.register_extension(IcoImageFile.format, ".ico")
|
380 |
+
|
381 |
+
Image.register_mime(IcoImageFile.format, "image/x-icon")
|
env-my/Lib/site-packages/PIL/ImImagePlugin.py
ADDED
@@ -0,0 +1,386 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#
|
2 |
+
# The Python Imaging Library.
|
3 |
+
# $Id$
|
4 |
+
#
|
5 |
+
# IFUNC IM file handling for PIL
|
6 |
+
#
|
7 |
+
# history:
|
8 |
+
# 1995-09-01 fl Created.
|
9 |
+
# 1997-01-03 fl Save palette images
|
10 |
+
# 1997-01-08 fl Added sequence support
|
11 |
+
# 1997-01-23 fl Added P and RGB save support
|
12 |
+
# 1997-05-31 fl Read floating point images
|
13 |
+
# 1997-06-22 fl Save floating point images
|
14 |
+
# 1997-08-27 fl Read and save 1-bit images
|
15 |
+
# 1998-06-25 fl Added support for RGB+LUT images
|
16 |
+
# 1998-07-02 fl Added support for YCC images
|
17 |
+
# 1998-07-15 fl Renamed offset attribute to avoid name clash
|
18 |
+
# 1998-12-29 fl Added I;16 support
|
19 |
+
# 2001-02-17 fl Use 're' instead of 'regex' (Python 2.1) (0.7)
|
20 |
+
# 2003-09-26 fl Added LA/PA support
|
21 |
+
#
|
22 |
+
# Copyright (c) 1997-2003 by Secret Labs AB.
|
23 |
+
# Copyright (c) 1995-2001 by Fredrik Lundh.
|
24 |
+
#
|
25 |
+
# See the README file for information on usage and redistribution.
|
26 |
+
#
|
27 |
+
from __future__ import annotations
|
28 |
+
|
29 |
+
import os
|
30 |
+
import re
|
31 |
+
from typing import IO, Any
|
32 |
+
|
33 |
+
from . import Image, ImageFile, ImagePalette
|
34 |
+
|
35 |
+
# --------------------------------------------------------------------
|
36 |
+
# Standard tags
|
37 |
+
|
38 |
+
COMMENT = "Comment"
|
39 |
+
DATE = "Date"
|
40 |
+
EQUIPMENT = "Digitalization equipment"
|
41 |
+
FRAMES = "File size (no of images)"
|
42 |
+
LUT = "Lut"
|
43 |
+
NAME = "Name"
|
44 |
+
SCALE = "Scale (x,y)"
|
45 |
+
SIZE = "Image size (x*y)"
|
46 |
+
MODE = "Image type"
|
47 |
+
|
48 |
+
TAGS = {
|
49 |
+
COMMENT: 0,
|
50 |
+
DATE: 0,
|
51 |
+
EQUIPMENT: 0,
|
52 |
+
FRAMES: 0,
|
53 |
+
LUT: 0,
|
54 |
+
NAME: 0,
|
55 |
+
SCALE: 0,
|
56 |
+
SIZE: 0,
|
57 |
+
MODE: 0,
|
58 |
+
}
|
59 |
+
|
60 |
+
OPEN = {
|
61 |
+
# ifunc93/p3cfunc formats
|
62 |
+
"0 1 image": ("1", "1"),
|
63 |
+
"L 1 image": ("1", "1"),
|
64 |
+
"Greyscale image": ("L", "L"),
|
65 |
+
"Grayscale image": ("L", "L"),
|
66 |
+
"RGB image": ("RGB", "RGB;L"),
|
67 |
+
"RLB image": ("RGB", "RLB"),
|
68 |
+
"RYB image": ("RGB", "RLB"),
|
69 |
+
"B1 image": ("1", "1"),
|
70 |
+
"B2 image": ("P", "P;2"),
|
71 |
+
"B4 image": ("P", "P;4"),
|
72 |
+
"X 24 image": ("RGB", "RGB"),
|
73 |
+
"L 32 S image": ("I", "I;32"),
|
74 |
+
"L 32 F image": ("F", "F;32"),
|
75 |
+
# old p3cfunc formats
|
76 |
+
"RGB3 image": ("RGB", "RGB;T"),
|
77 |
+
"RYB3 image": ("RGB", "RYB;T"),
|
78 |
+
# extensions
|
79 |
+
"LA image": ("LA", "LA;L"),
|
80 |
+
"PA image": ("LA", "PA;L"),
|
81 |
+
"RGBA image": ("RGBA", "RGBA;L"),
|
82 |
+
"RGBX image": ("RGB", "RGBX;L"),
|
83 |
+
"CMYK image": ("CMYK", "CMYK;L"),
|
84 |
+
"YCC image": ("YCbCr", "YCbCr;L"),
|
85 |
+
}
|
86 |
+
|
87 |
+
# ifunc95 extensions
|
88 |
+
for i in ["8", "8S", "16", "16S", "32", "32F"]:
|
89 |
+
OPEN[f"L {i} image"] = ("F", f"F;{i}")
|
90 |
+
OPEN[f"L*{i} image"] = ("F", f"F;{i}")
|
91 |
+
for i in ["16", "16L", "16B"]:
|
92 |
+
OPEN[f"L {i} image"] = (f"I;{i}", f"I;{i}")
|
93 |
+
OPEN[f"L*{i} image"] = (f"I;{i}", f"I;{i}")
|
94 |
+
for i in ["32S"]:
|
95 |
+
OPEN[f"L {i} image"] = ("I", f"I;{i}")
|
96 |
+
OPEN[f"L*{i} image"] = ("I", f"I;{i}")
|
97 |
+
for j in range(2, 33):
|
98 |
+
OPEN[f"L*{j} image"] = ("F", f"F;{j}")
|
99 |
+
|
100 |
+
|
101 |
+
# --------------------------------------------------------------------
|
102 |
+
# Read IM directory
|
103 |
+
|
104 |
+
split = re.compile(rb"^([A-Za-z][^:]*):[ \t]*(.*)[ \t]*$")
|
105 |
+
|
106 |
+
|
107 |
+
def number(s: Any) -> float:
|
108 |
+
try:
|
109 |
+
return int(s)
|
110 |
+
except ValueError:
|
111 |
+
return float(s)
|
112 |
+
|
113 |
+
|
114 |
+
##
|
115 |
+
# Image plugin for the IFUNC IM file format.
|
116 |
+
|
117 |
+
|
118 |
+
class ImImageFile(ImageFile.ImageFile):
|
119 |
+
format = "IM"
|
120 |
+
format_description = "IFUNC Image Memory"
|
121 |
+
_close_exclusive_fp_after_loading = False
|
122 |
+
|
123 |
+
def _open(self) -> None:
|
124 |
+
# Quick rejection: if there's not an LF among the first
|
125 |
+
# 100 bytes, this is (probably) not a text header.
|
126 |
+
|
127 |
+
if b"\n" not in self.fp.read(100):
|
128 |
+
msg = "not an IM file"
|
129 |
+
raise SyntaxError(msg)
|
130 |
+
self.fp.seek(0)
|
131 |
+
|
132 |
+
n = 0
|
133 |
+
|
134 |
+
# Default values
|
135 |
+
self.info[MODE] = "L"
|
136 |
+
self.info[SIZE] = (512, 512)
|
137 |
+
self.info[FRAMES] = 1
|
138 |
+
|
139 |
+
self.rawmode = "L"
|
140 |
+
|
141 |
+
while True:
|
142 |
+
s = self.fp.read(1)
|
143 |
+
|
144 |
+
# Some versions of IFUNC uses \n\r instead of \r\n...
|
145 |
+
if s == b"\r":
|
146 |
+
continue
|
147 |
+
|
148 |
+
if not s or s == b"\0" or s == b"\x1A":
|
149 |
+
break
|
150 |
+
|
151 |
+
# FIXME: this may read whole file if not a text file
|
152 |
+
s = s + self.fp.readline()
|
153 |
+
|
154 |
+
if len(s) > 100:
|
155 |
+
msg = "not an IM file"
|
156 |
+
raise SyntaxError(msg)
|
157 |
+
|
158 |
+
if s[-2:] == b"\r\n":
|
159 |
+
s = s[:-2]
|
160 |
+
elif s[-1:] == b"\n":
|
161 |
+
s = s[:-1]
|
162 |
+
|
163 |
+
try:
|
164 |
+
m = split.match(s)
|
165 |
+
except re.error as e:
|
166 |
+
msg = "not an IM file"
|
167 |
+
raise SyntaxError(msg) from e
|
168 |
+
|
169 |
+
if m:
|
170 |
+
k, v = m.group(1, 2)
|
171 |
+
|
172 |
+
# Don't know if this is the correct encoding,
|
173 |
+
# but a decent guess (I guess)
|
174 |
+
k = k.decode("latin-1", "replace")
|
175 |
+
v = v.decode("latin-1", "replace")
|
176 |
+
|
177 |
+
# Convert value as appropriate
|
178 |
+
if k in [FRAMES, SCALE, SIZE]:
|
179 |
+
v = v.replace("*", ",")
|
180 |
+
v = tuple(map(number, v.split(",")))
|
181 |
+
if len(v) == 1:
|
182 |
+
v = v[0]
|
183 |
+
elif k == MODE and v in OPEN:
|
184 |
+
v, self.rawmode = OPEN[v]
|
185 |
+
|
186 |
+
# Add to dictionary. Note that COMMENT tags are
|
187 |
+
# combined into a list of strings.
|
188 |
+
if k == COMMENT:
|
189 |
+
if k in self.info:
|
190 |
+
self.info[k].append(v)
|
191 |
+
else:
|
192 |
+
self.info[k] = [v]
|
193 |
+
else:
|
194 |
+
self.info[k] = v
|
195 |
+
|
196 |
+
if k in TAGS:
|
197 |
+
n += 1
|
198 |
+
|
199 |
+
else:
|
200 |
+
msg = f"Syntax error in IM header: {s.decode('ascii', 'replace')}"
|
201 |
+
raise SyntaxError(msg)
|
202 |
+
|
203 |
+
if not n:
|
204 |
+
msg = "Not an IM file"
|
205 |
+
raise SyntaxError(msg)
|
206 |
+
|
207 |
+
# Basic attributes
|
208 |
+
self._size = self.info[SIZE]
|
209 |
+
self._mode = self.info[MODE]
|
210 |
+
|
211 |
+
# Skip forward to start of image data
|
212 |
+
while s and s[:1] != b"\x1A":
|
213 |
+
s = self.fp.read(1)
|
214 |
+
if not s:
|
215 |
+
msg = "File truncated"
|
216 |
+
raise SyntaxError(msg)
|
217 |
+
|
218 |
+
if LUT in self.info:
|
219 |
+
# convert lookup table to palette or lut attribute
|
220 |
+
palette = self.fp.read(768)
|
221 |
+
greyscale = 1 # greyscale palette
|
222 |
+
linear = 1 # linear greyscale palette
|
223 |
+
for i in range(256):
|
224 |
+
if palette[i] == palette[i + 256] == palette[i + 512]:
|
225 |
+
if palette[i] != i:
|
226 |
+
linear = 0
|
227 |
+
else:
|
228 |
+
greyscale = 0
|
229 |
+
if self.mode in ["L", "LA", "P", "PA"]:
|
230 |
+
if greyscale:
|
231 |
+
if not linear:
|
232 |
+
self.lut = list(palette[:256])
|
233 |
+
else:
|
234 |
+
if self.mode in ["L", "P"]:
|
235 |
+
self._mode = self.rawmode = "P"
|
236 |
+
elif self.mode in ["LA", "PA"]:
|
237 |
+
self._mode = "PA"
|
238 |
+
self.rawmode = "PA;L"
|
239 |
+
self.palette = ImagePalette.raw("RGB;L", palette)
|
240 |
+
elif self.mode == "RGB":
|
241 |
+
if not greyscale or not linear:
|
242 |
+
self.lut = list(palette)
|
243 |
+
|
244 |
+
self.frame = 0
|
245 |
+
|
246 |
+
self.__offset = offs = self.fp.tell()
|
247 |
+
|
248 |
+
self._fp = self.fp # FIXME: hack
|
249 |
+
|
250 |
+
if self.rawmode[:2] == "F;":
|
251 |
+
# ifunc95 formats
|
252 |
+
try:
|
253 |
+
# use bit decoder (if necessary)
|
254 |
+
bits = int(self.rawmode[2:])
|
255 |
+
if bits not in [8, 16, 32]:
|
256 |
+
self.tile = [
|
257 |
+
ImageFile._Tile(
|
258 |
+
"bit", (0, 0) + self.size, offs, (bits, 8, 3, 0, -1)
|
259 |
+
)
|
260 |
+
]
|
261 |
+
return
|
262 |
+
except ValueError:
|
263 |
+
pass
|
264 |
+
|
265 |
+
if self.rawmode in ["RGB;T", "RYB;T"]:
|
266 |
+
# Old LabEye/3PC files. Would be very surprised if anyone
|
267 |
+
# ever stumbled upon such a file ;-)
|
268 |
+
size = self.size[0] * self.size[1]
|
269 |
+
self.tile = [
|
270 |
+
ImageFile._Tile("raw", (0, 0) + self.size, offs, ("G", 0, -1)),
|
271 |
+
ImageFile._Tile("raw", (0, 0) + self.size, offs + size, ("R", 0, -1)),
|
272 |
+
ImageFile._Tile(
|
273 |
+
"raw", (0, 0) + self.size, offs + 2 * size, ("B", 0, -1)
|
274 |
+
),
|
275 |
+
]
|
276 |
+
else:
|
277 |
+
# LabEye/IFUNC files
|
278 |
+
self.tile = [
|
279 |
+
ImageFile._Tile("raw", (0, 0) + self.size, offs, (self.rawmode, 0, -1))
|
280 |
+
]
|
281 |
+
|
282 |
+
@property
|
283 |
+
def n_frames(self) -> int:
|
284 |
+
return self.info[FRAMES]
|
285 |
+
|
286 |
+
@property
|
287 |
+
def is_animated(self) -> bool:
|
288 |
+
return self.info[FRAMES] > 1
|
289 |
+
|
290 |
+
def seek(self, frame: int) -> None:
|
291 |
+
if not self._seek_check(frame):
|
292 |
+
return
|
293 |
+
|
294 |
+
self.frame = frame
|
295 |
+
|
296 |
+
if self.mode == "1":
|
297 |
+
bits = 1
|
298 |
+
else:
|
299 |
+
bits = 8 * len(self.mode)
|
300 |
+
|
301 |
+
size = ((self.size[0] * bits + 7) // 8) * self.size[1]
|
302 |
+
offs = self.__offset + frame * size
|
303 |
+
|
304 |
+
self.fp = self._fp
|
305 |
+
|
306 |
+
self.tile = [
|
307 |
+
ImageFile._Tile("raw", (0, 0) + self.size, offs, (self.rawmode, 0, -1))
|
308 |
+
]
|
309 |
+
|
310 |
+
def tell(self) -> int:
|
311 |
+
return self.frame
|
312 |
+
|
313 |
+
|
314 |
+
#
|
315 |
+
# --------------------------------------------------------------------
|
316 |
+
# Save IM files
|
317 |
+
|
318 |
+
|
319 |
+
SAVE = {
|
320 |
+
# mode: (im type, raw mode)
|
321 |
+
"1": ("0 1", "1"),
|
322 |
+
"L": ("Greyscale", "L"),
|
323 |
+
"LA": ("LA", "LA;L"),
|
324 |
+
"P": ("Greyscale", "P"),
|
325 |
+
"PA": ("LA", "PA;L"),
|
326 |
+
"I": ("L 32S", "I;32S"),
|
327 |
+
"I;16": ("L 16", "I;16"),
|
328 |
+
"I;16L": ("L 16L", "I;16L"),
|
329 |
+
"I;16B": ("L 16B", "I;16B"),
|
330 |
+
"F": ("L 32F", "F;32F"),
|
331 |
+
"RGB": ("RGB", "RGB;L"),
|
332 |
+
"RGBA": ("RGBA", "RGBA;L"),
|
333 |
+
"RGBX": ("RGBX", "RGBX;L"),
|
334 |
+
"CMYK": ("CMYK", "CMYK;L"),
|
335 |
+
"YCbCr": ("YCC", "YCbCr;L"),
|
336 |
+
}
|
337 |
+
|
338 |
+
|
339 |
+
def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
|
340 |
+
try:
|
341 |
+
image_type, rawmode = SAVE[im.mode]
|
342 |
+
except KeyError as e:
|
343 |
+
msg = f"Cannot save {im.mode} images as IM"
|
344 |
+
raise ValueError(msg) from e
|
345 |
+
|
346 |
+
frames = im.encoderinfo.get("frames", 1)
|
347 |
+
|
348 |
+
fp.write(f"Image type: {image_type} image\r\n".encode("ascii"))
|
349 |
+
if filename:
|
350 |
+
# Each line must be 100 characters or less,
|
351 |
+
# or: SyntaxError("not an IM file")
|
352 |
+
# 8 characters are used for "Name: " and "\r\n"
|
353 |
+
# Keep just the filename, ditch the potentially overlong path
|
354 |
+
if isinstance(filename, bytes):
|
355 |
+
filename = filename.decode("ascii")
|
356 |
+
name, ext = os.path.splitext(os.path.basename(filename))
|
357 |
+
name = "".join([name[: 92 - len(ext)], ext])
|
358 |
+
|
359 |
+
fp.write(f"Name: {name}\r\n".encode("ascii"))
|
360 |
+
fp.write(f"Image size (x*y): {im.size[0]}*{im.size[1]}\r\n".encode("ascii"))
|
361 |
+
fp.write(f"File size (no of images): {frames}\r\n".encode("ascii"))
|
362 |
+
if im.mode in ["P", "PA"]:
|
363 |
+
fp.write(b"Lut: 1\r\n")
|
364 |
+
fp.write(b"\000" * (511 - fp.tell()) + b"\032")
|
365 |
+
if im.mode in ["P", "PA"]:
|
366 |
+
im_palette = im.im.getpalette("RGB", "RGB;L")
|
367 |
+
colors = len(im_palette) // 3
|
368 |
+
palette = b""
|
369 |
+
for i in range(3):
|
370 |
+
palette += im_palette[colors * i : colors * (i + 1)]
|
371 |
+
palette += b"\x00" * (256 - colors)
|
372 |
+
fp.write(palette) # 768 bytes
|
373 |
+
ImageFile._save(
|
374 |
+
im, fp, [ImageFile._Tile("raw", (0, 0) + im.size, 0, (rawmode, 0, -1))]
|
375 |
+
)
|
376 |
+
|
377 |
+
|
378 |
+
#
|
379 |
+
# --------------------------------------------------------------------
|
380 |
+
# Registry
|
381 |
+
|
382 |
+
|
383 |
+
Image.register_open(ImImageFile.format, ImImageFile)
|
384 |
+
Image.register_save(ImImageFile.format, _save)
|
385 |
+
|
386 |
+
Image.register_extension(ImImageFile.format, ".im")
|
env-my/Lib/site-packages/PIL/Image.py
ADDED
The diff for this file is too large to render.
See raw diff
|
|