Spaces:
Configuration error
Configuration error
Upload folder using huggingface_hub (part 20)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +1 -0
- .venv/lib/python3.13/site-packages/reportlab-5.0.0.dist-info/INSTALLER +1 -0
- .venv/lib/python3.13/site-packages/reportlab-5.0.0.dist-info/METADATA +45 -0
- .venv/lib/python3.13/site-packages/reportlab-5.0.0.dist-info/RECORD +357 -0
- .venv/lib/python3.13/site-packages/reportlab-5.0.0.dist-info/REQUESTED +0 -0
- .venv/lib/python3.13/site-packages/reportlab-5.0.0.dist-info/WHEEL +5 -0
- .venv/lib/python3.13/site-packages/reportlab-5.0.0.dist-info/licenses/LICENSE +29 -0
- .venv/lib/python3.13/site-packages/reportlab-5.0.0.dist-info/top_level.txt +1 -0
- .venv/lib/python3.13/site-packages/reportlab/platypus/paragraph.py +0 -0
- .venv/lib/python3.13/site-packages/reportlab/platypus/paraparser.py +0 -0
- .venv/lib/python3.13/site-packages/reportlab/platypus/tableofcontents.py +559 -0
- .venv/lib/python3.13/site-packages/reportlab/platypus/tables.py +0 -0
- .venv/lib/python3.13/site-packages/reportlab/platypus/xpreformatted.py +345 -0
- .venv/lib/python3.13/site-packages/reportlab/rl_config.py +150 -0
- .venv/lib/python3.13/site-packages/reportlab/rl_settings.py +282 -0
- .venv/lib/python3.13/site-packages/six-1.17.0.dist-info/INSTALLER +1 -0
- .venv/lib/python3.13/site-packages/six-1.17.0.dist-info/LICENSE +18 -0
- .venv/lib/python3.13/site-packages/six-1.17.0.dist-info/METADATA +43 -0
- .venv/lib/python3.13/site-packages/six-1.17.0.dist-info/RECORD +8 -0
- .venv/lib/python3.13/site-packages/six-1.17.0.dist-info/WHEEL +6 -0
- .venv/lib/python3.13/site-packages/six-1.17.0.dist-info/top_level.txt +1 -0
- .venv/lib/python3.13/site-packages/six.py +1003 -0
- .venv/lib/python3.13/site-packages/soupsieve-2.9.2.dist-info/INSTALLER +1 -0
- .venv/lib/python3.13/site-packages/soupsieve-2.9.2.dist-info/METADATA +114 -0
- .venv/lib/python3.13/site-packages/soupsieve-2.9.2.dist-info/RECORD +20 -0
- .venv/lib/python3.13/site-packages/soupsieve-2.9.2.dist-info/WHEEL +4 -0
- .venv/lib/python3.13/site-packages/soupsieve-2.9.2.dist-info/licenses/LICENSE.md +21 -0
- .venv/lib/python3.13/site-packages/soupsieve/__init__.py +168 -0
- .venv/lib/python3.13/site-packages/soupsieve/__meta__.py +197 -0
- .venv/lib/python3.13/site-packages/soupsieve/css_match.py +1628 -0
- .venv/lib/python3.13/site-packages/soupsieve/css_parser.py +1359 -0
- .venv/lib/python3.13/site-packages/soupsieve/css_types.py +410 -0
- .venv/lib/python3.13/site-packages/soupsieve/pretty.py +148 -0
- .venv/lib/python3.13/site-packages/soupsieve/py.typed +0 -0
- .venv/lib/python3.13/site-packages/soupsieve/util.py +117 -0
- .venv/lib/python3.13/site-packages/tqdm-4.70.0.dist-info/INSTALLER +1 -0
- .venv/lib/python3.13/site-packages/tqdm-4.70.0.dist-info/METADATA +1600 -0
- .venv/lib/python3.13/site-packages/tqdm-4.70.0.dist-info/RECORD +72 -0
- .venv/lib/python3.13/site-packages/tqdm-4.70.0.dist-info/WHEEL +5 -0
- .venv/lib/python3.13/site-packages/tqdm-4.70.0.dist-info/entry_points.txt +2 -0
- .venv/lib/python3.13/site-packages/tqdm-4.70.0.dist-info/licenses/LICENCE +49 -0
- .venv/lib/python3.13/site-packages/tqdm-4.70.0.dist-info/top_level.txt +1 -0
- .venv/lib/python3.13/site-packages/tqdm/__init__.py +38 -0
- .venv/lib/python3.13/site-packages/tqdm/__main__.py +3 -0
- .venv/lib/python3.13/site-packages/tqdm/_main.py +9 -0
- .venv/lib/python3.13/site-packages/tqdm/_monitor.py +104 -0
- .venv/lib/python3.13/site-packages/tqdm/_tqdm.py +9 -0
- .venv/lib/python3.13/site-packages/tqdm/_tqdm_gui.py +9 -0
- .venv/lib/python3.13/site-packages/tqdm/_tqdm_notebook.py +9 -0
- .venv/lib/python3.13/site-packages/tqdm/_tqdm_pandas.py +24 -0
.gitattributes
CHANGED
|
@@ -124,3 +124,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 124 |
.venv/lib/python3.13/site-packages/pillow.libs/libxcb-ad31f5a3.so.1.1.0 filter=lfs diff=lfs merge=lfs -text
|
| 125 |
.venv/lib/python3.13/site-packages/pillow.libs/libzstd-44be1190.so.1.5.7 filter=lfs diff=lfs merge=lfs -text
|
| 126 |
.venv/lib/python3.13/site-packages/pydantic_core/_pydantic_core.cpython-313-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 124 |
.venv/lib/python3.13/site-packages/pillow.libs/libxcb-ad31f5a3.so.1.1.0 filter=lfs diff=lfs merge=lfs -text
|
| 125 |
.venv/lib/python3.13/site-packages/pillow.libs/libzstd-44be1190.so.1.5.7 filter=lfs diff=lfs merge=lfs -text
|
| 126 |
.venv/lib/python3.13/site-packages/pydantic_core/_pydantic_core.cpython-313-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 127 |
+
.venv/lib/python3.13/site-packages/yaml/_yaml.cpython-313-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
.venv/lib/python3.13/site-packages/reportlab-5.0.0.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pip
|
.venv/lib/python3.13/site-packages/reportlab-5.0.0.dist-info/METADATA
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.4
|
| 2 |
+
Name: reportlab
|
| 3 |
+
Version: 5.0.0
|
| 4 |
+
Summary: The Reportlab Toolkit
|
| 5 |
+
Home-page: https://www.reportlab.com/
|
| 6 |
+
Author: Andy Robinson, Robin Becker, the ReportLab team and the community
|
| 7 |
+
Author-email: reportlab-users@lists2.reportlab.com
|
| 8 |
+
License: BSD license (see license.txt for details), Copyright (c) 2000-2025, ReportLab Inc.
|
| 9 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 10 |
+
Classifier: Intended Audience :: Developers
|
| 11 |
+
Classifier: License :: OSI Approved :: BSD License
|
| 12 |
+
Classifier: Topic :: Printing
|
| 13 |
+
Classifier: Topic :: Text Processing :: Markup
|
| 14 |
+
Classifier: Programming Language :: Python :: 3
|
| 15 |
+
Classifier: Programming Language :: Python :: 3.10
|
| 16 |
+
Classifier: Programming Language :: Python :: 3.11
|
| 17 |
+
Classifier: Programming Language :: Python :: 3.12
|
| 18 |
+
Classifier: Programming Language :: Python :: 3.13
|
| 19 |
+
Classifier: Programming Language :: Python :: 3.14
|
| 20 |
+
Requires-Python: >=3.9,<4
|
| 21 |
+
License-File: LICENSE
|
| 22 |
+
Requires-Dist: pillow>=9.0.0
|
| 23 |
+
Requires-Dist: charset-normalizer
|
| 24 |
+
Provides-Extra: accel
|
| 25 |
+
Requires-Dist: rl_accel<1.1,>=0.9.0; extra == "accel"
|
| 26 |
+
Provides-Extra: pycairo
|
| 27 |
+
Requires-Dist: rlPyCairo<1,>=0.2.0; extra == "pycairo"
|
| 28 |
+
Requires-Dist: freetype-py<2.4,>=2.3.0; extra == "pycairo"
|
| 29 |
+
Provides-Extra: bidi
|
| 30 |
+
Requires-Dist: rlbidi; extra == "bidi"
|
| 31 |
+
Provides-Extra: shaping
|
| 32 |
+
Requires-Dist: uharfbuzz; extra == "shaping"
|
| 33 |
+
Dynamic: author
|
| 34 |
+
Dynamic: author-email
|
| 35 |
+
Dynamic: classifier
|
| 36 |
+
Dynamic: description
|
| 37 |
+
Dynamic: home-page
|
| 38 |
+
Dynamic: license
|
| 39 |
+
Dynamic: license-file
|
| 40 |
+
Dynamic: provides-extra
|
| 41 |
+
Dynamic: requires-dist
|
| 42 |
+
Dynamic: requires-python
|
| 43 |
+
Dynamic: summary
|
| 44 |
+
|
| 45 |
+
The ReportLab Toolkit. An Open Source Python library for generating PDFs and graphics.
|
.venv/lib/python3.13/site-packages/reportlab-5.0.0.dist-info/RECORD
ADDED
|
@@ -0,0 +1,357 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
reportlab-5.0.0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
| 2 |
+
reportlab-5.0.0.dist-info/METADATA,sha256=vbx-HrS4GQHYDvOdxHYtXa4ru9Vb4ISdooJRZxIfTYs,1638
|
| 3 |
+
reportlab-5.0.0.dist-info/RECORD,,
|
| 4 |
+
reportlab-5.0.0.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 5 |
+
reportlab-5.0.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
| 6 |
+
reportlab-5.0.0.dist-info/licenses/LICENSE,sha256=74MXYWRjE5ITdfwsuIjo7q99ohPQuShSwQxC86C00Tg,1707
|
| 7 |
+
reportlab-5.0.0.dist-info/top_level.txt,sha256=Qysh6iUiTF45gwXoIXNubNhOYRrEv4TwLpzdYBmEwqQ,10
|
| 8 |
+
reportlab/__init__.py,sha256=wMtvKyu1z_TZEfZ_7LDSvuIytZJAKMLb8it3DbraNsA,1481
|
| 9 |
+
reportlab/__pycache__/__init__.cpython-313.pyc,,
|
| 10 |
+
reportlab/__pycache__/rl_config.cpython-313.pyc,,
|
| 11 |
+
reportlab/__pycache__/rl_settings.cpython-313.pyc,,
|
| 12 |
+
reportlab/fonts/00readme.txt,sha256=VC0Ms0GpMyJ2b5FwNmheECoHY7EX-DILN5FZFyO6XpE,318
|
| 13 |
+
reportlab/fonts/DarkGarden-changelog.txt,sha256=27Cf8zHRWXEl91TZQmu4zvePuVY5d5DeRCaduMCp5U0,504
|
| 14 |
+
reportlab/fonts/DarkGarden-copying-gpl.txt,sha256=GypWfyifZqFDxWNT57PU-lhiUUpePFz9-LAu5eWqqVM,17976
|
| 15 |
+
reportlab/fonts/DarkGarden-copying.txt,sha256=PNECBRDvp_azFmpaJ0D5K9ZkppXqF54L2kQudM0O86Q,1318
|
| 16 |
+
reportlab/fonts/DarkGarden-readme.txt,sha256=syeWP88NiDM9KTdR3QsRPIwC811hRA9XihRoGo6nNKA,4122
|
| 17 |
+
reportlab/fonts/DarkGarden.sfd,sha256=f_Z8ntoC_HUfXKBDlBCcOLLXI-EFUG5YFB_JNjZi1ro,519634
|
| 18 |
+
reportlab/fonts/DarkGardenMK.afm,sha256=kyuxrMCDWNh_Mm6JG3jN6efvYL_U-3Sc-0irniov5us,10351
|
| 19 |
+
reportlab/fonts/DarkGardenMK.pfb,sha256=NjPVrtXA_D7JMC7mmV0LuHopJnk-3lu2VCh9nLiW7JU,79824
|
| 20 |
+
reportlab/fonts/Vera.ttf,sha256=xMRWkLNFQ1ssulLsq-J18F5Js4mzn-aK0Dr7tVEojT0,65932
|
| 21 |
+
reportlab/fonts/VeraBI.ttf,sha256=_KDU7qwc7X514bInTIaaNR0tg7XtH2HSSee8xHfDPr4,63208
|
| 22 |
+
reportlab/fonts/VeraBd.ttf,sha256=zANzheTVW_3omxPgMJHuk79AwMUt3Tkf8DGrJ28TuOk,58716
|
| 23 |
+
reportlab/fonts/VeraIt.ttf,sha256=KtxoTVGPRSMsStH1ZSL1qCppBMMZQDc-G3Awvu4g-zo,63684
|
| 24 |
+
reportlab/fonts/_a______.pfb,sha256=YS6IlG_yLOzdbjRaUKsdbCWjLvS_bnjwEapN4tdUj00,32084
|
| 25 |
+
reportlab/fonts/_ab_____.pfb,sha256=boLrtCFxvrgF-9REkjLkJsR3RW34skEFIR5hmfvGujs,31966
|
| 26 |
+
reportlab/fonts/_abi____.pfb,sha256=qXr9-DdsqmsWAw6KbRo_Z-YAc1kOnzYKOx8tdUq51f8,32019
|
| 27 |
+
reportlab/fonts/_ai_____.pfb,sha256=dOK-ebH9ejDw6pDtmricM63knjJl1QoJpuh9UcW6FYM,32115
|
| 28 |
+
reportlab/fonts/_eb_____.pfb,sha256=rbG_7Z6GZXdYPZNzXPFsqNM1fCpxeE7hO02Shymbslg,35377
|
| 29 |
+
reportlab/fonts/_ebi____.pfb,sha256=BOY0W-xL1vssZLMVZdwUp38OTNiy_coWufj0_ClYLNE,38543
|
| 30 |
+
reportlab/fonts/_ei_____.pfb,sha256=M6uppiquW5bT54JV4bBlLcFq4waGBEvX_oAbYkNGp7Y,37518
|
| 31 |
+
reportlab/fonts/_er_____.pfb,sha256=2cu80hEwD9-sUxdFCDLW7OVCr72hAV_vnfQOijUKUCk,35380
|
| 32 |
+
reportlab/fonts/bitstream-vera-license.txt,sha256=M2HQVHWaL8aGosBYvoLer5wub-VJvpAE15NabBc2MV0,5954
|
| 33 |
+
reportlab/fonts/callig15.afm,sha256=v_n043-haIWG55w1CX1opfY4wpsnxvDUrByOuFlmihc,8318
|
| 34 |
+
reportlab/fonts/callig15.pfb,sha256=jTbbZrLw3tT4TLPNnV1MfKS2kmSMgFOb-b2DrxTuGiI,59663
|
| 35 |
+
reportlab/fonts/cob_____.pfb,sha256=_Vs0rXxj0QJ4slpudjlo-w_elpmFQZ9AQgX6Jnonxow,35500
|
| 36 |
+
reportlab/fonts/cobo____.pfb,sha256=0Sj8SseEuyg4PhafljhimwYHipCtvBuNfk6fRNiT9vE,50532
|
| 37 |
+
reportlab/fonts/com_____.pfb,sha256=HeWH8Mp53u-Zpzj594ddBi-F71EDtlJs7aU6R5Ya6hM,34585
|
| 38 |
+
reportlab/fonts/coo_____.pfb,sha256=Z23l5uHDAodSGMczwzupqbgoOw3q-5K1-UxfC-JNT3c,48468
|
| 39 |
+
reportlab/fonts/hb-test.ttf,sha256=TfiEDsg4LvosBr2gHjHhpal1zUbhP3wLC-aWqFQvG6A,3284
|
| 40 |
+
reportlab/fonts/sy______.pfb,sha256=sEgMb5zua7h8GuFZqJqKnR_6RuCrcEYf3y_CkeLJS0o,34705
|
| 41 |
+
reportlab/fonts/zd______.pfb,sha256=2XEMrdH9iVVjYB2_0zkpHu_3IZnrXpP2VNzHI1JpeQs,49593
|
| 42 |
+
reportlab/fonts/zx______.pfb,sha256=uo85lvrTLAQr8fR0oIt0UvJSBgiC3E3lqX7DiSCeIwE,75573
|
| 43 |
+
reportlab/fonts/zy______.pfb,sha256=EYL8wvuIdxP7lUqAT4P640F8J7aSnssHxQNNrCRYbos,96418
|
| 44 |
+
reportlab/graphics/__init__.py,sha256=2nCXSpcFhbbEgDSg1MTDwZRg4EDJGMn61NFfISCpzdE,274
|
| 45 |
+
reportlab/graphics/__pycache__/__init__.cpython-313.pyc,,
|
| 46 |
+
reportlab/graphics/__pycache__/renderPDF.cpython-313.pyc,,
|
| 47 |
+
reportlab/graphics/__pycache__/renderPM.cpython-313.pyc,,
|
| 48 |
+
reportlab/graphics/__pycache__/renderPS.cpython-313.pyc,,
|
| 49 |
+
reportlab/graphics/__pycache__/renderSVG.cpython-313.pyc,,
|
| 50 |
+
reportlab/graphics/__pycache__/renderbase.cpython-313.pyc,,
|
| 51 |
+
reportlab/graphics/__pycache__/shapes.cpython-313.pyc,,
|
| 52 |
+
reportlab/graphics/__pycache__/svgpath.cpython-313.pyc,,
|
| 53 |
+
reportlab/graphics/__pycache__/testdrawings.cpython-313.pyc,,
|
| 54 |
+
reportlab/graphics/__pycache__/testshapes.cpython-313.pyc,,
|
| 55 |
+
reportlab/graphics/__pycache__/transform.cpython-313.pyc,,
|
| 56 |
+
reportlab/graphics/__pycache__/utils.cpython-313.pyc,,
|
| 57 |
+
reportlab/graphics/__pycache__/widgetbase.cpython-313.pyc,,
|
| 58 |
+
reportlab/graphics/barcode/__init__.py,sha256=SsaLCj0VvzrdfP9ZIPq9MCsEJYB8RF8-ZchITDOgZfk,5886
|
| 59 |
+
reportlab/graphics/barcode/__pycache__/__init__.cpython-313.pyc,,
|
| 60 |
+
reportlab/graphics/barcode/__pycache__/code128.cpython-313.pyc,,
|
| 61 |
+
reportlab/graphics/barcode/__pycache__/code39.cpython-313.pyc,,
|
| 62 |
+
reportlab/graphics/barcode/__pycache__/code93.cpython-313.pyc,,
|
| 63 |
+
reportlab/graphics/barcode/__pycache__/common.cpython-313.pyc,,
|
| 64 |
+
reportlab/graphics/barcode/__pycache__/dmtx.cpython-313.pyc,,
|
| 65 |
+
reportlab/graphics/barcode/__pycache__/eanbc.cpython-313.pyc,,
|
| 66 |
+
reportlab/graphics/barcode/__pycache__/ecc200datamatrix.cpython-313.pyc,,
|
| 67 |
+
reportlab/graphics/barcode/__pycache__/fourstate.cpython-313.pyc,,
|
| 68 |
+
reportlab/graphics/barcode/__pycache__/lto.cpython-313.pyc,,
|
| 69 |
+
reportlab/graphics/barcode/__pycache__/qr.cpython-313.pyc,,
|
| 70 |
+
reportlab/graphics/barcode/__pycache__/qrencoder.cpython-313.pyc,,
|
| 71 |
+
reportlab/graphics/barcode/__pycache__/test.cpython-313.pyc,,
|
| 72 |
+
reportlab/graphics/barcode/__pycache__/usps.cpython-313.pyc,,
|
| 73 |
+
reportlab/graphics/barcode/__pycache__/usps4s.cpython-313.pyc,,
|
| 74 |
+
reportlab/graphics/barcode/__pycache__/widgets.cpython-313.pyc,,
|
| 75 |
+
reportlab/graphics/barcode/code128.py,sha256=LySVAC3p8XDjBHji7koo6ri95pqT-8Z91I_6aehvepc,18451
|
| 76 |
+
reportlab/graphics/barcode/code39.py,sha256=wEYlchv9wIW3Ve69mYI7nQvB_95TTGFNtJBfiCNTnOA,9799
|
| 77 |
+
reportlab/graphics/barcode/code93.py,sha256=rFFR7FBLKretxUl4zVdrEq_zn_P26nFLc5YEX0wpXaY,9077
|
| 78 |
+
reportlab/graphics/barcode/common.py,sha256=dSLXhaQ9u455C5LJN2Tt7ldvkSC2564GYe5SGYxXl_4,24425
|
| 79 |
+
reportlab/graphics/barcode/dmtx.py,sha256=oCQr4YMOLlxBRX8r1jb0EV9wH9LHKT05wngBVMzcEmk,7872
|
| 80 |
+
reportlab/graphics/barcode/eanbc.py,sha256=r7eWWqqSSwuTxDdgJBHwUgmPHM5w4UKhb_5idxoxiOQ,18922
|
| 81 |
+
reportlab/graphics/barcode/ecc200datamatrix.py,sha256=WZQv9wWwyn-ovEUrudk3aMnHIx2K4prp3JjsFsYi7BM,17884
|
| 82 |
+
reportlab/graphics/barcode/fourstate.py,sha256=kjb3H9kxBhBKqOMXDTJi9NJzcJjbBHq-9X8KFWnTOTw,3746
|
| 83 |
+
reportlab/graphics/barcode/lto.py,sha256=_AiYcrN2Jb601uiqTQnGDESb-f1PhutvjPXClNyGL4g,7377
|
| 84 |
+
reportlab/graphics/barcode/qr.py,sha256=92kwjcOpuSd9JwnMV9Xmpc6idPRzQfmJGKoG274EDRY,6266
|
| 85 |
+
reportlab/graphics/barcode/qrencoder.py,sha256=1gTy0TUlYtSlhXul5U7lY1Nkw7PS-PKyamtrYM8Mapk,34117
|
| 86 |
+
reportlab/graphics/barcode/test.py,sha256=Leojm2uG2yHHMCUu2jZkRJcRTeP3Ps3MOEAJv-DTRew,11973
|
| 87 |
+
reportlab/graphics/barcode/usps.py,sha256=X0Dk5jpLImxFnYhLXVajYyKQrxGNZDoGjeCRjeKc4qM,8076
|
| 88 |
+
reportlab/graphics/barcode/usps4s.py,sha256=oAXbpvvwM_D8A5FlZ5h6fWf4mejsBr76TT3cufNgz6k,15681
|
| 89 |
+
reportlab/graphics/barcode/widgets.py,sha256=aewNZjNzvUY_S2o4Py0xR2cLLV7yFC3qt12N9MwVHsk,17499
|
| 90 |
+
reportlab/graphics/charts/__init__.py,sha256=m7Ihp3XLlUArWj8rGanx1ZIcEwO6LZrGrtn0sXyzgJY,234
|
| 91 |
+
reportlab/graphics/charts/__pycache__/__init__.cpython-313.pyc,,
|
| 92 |
+
reportlab/graphics/charts/__pycache__/areas.cpython-313.pyc,,
|
| 93 |
+
reportlab/graphics/charts/__pycache__/axes.cpython-313.pyc,,
|
| 94 |
+
reportlab/graphics/charts/__pycache__/barcharts.cpython-313.pyc,,
|
| 95 |
+
reportlab/graphics/charts/__pycache__/dotbox.cpython-313.pyc,,
|
| 96 |
+
reportlab/graphics/charts/__pycache__/doughnut.cpython-313.pyc,,
|
| 97 |
+
reportlab/graphics/charts/__pycache__/legends.cpython-313.pyc,,
|
| 98 |
+
reportlab/graphics/charts/__pycache__/linecharts.cpython-313.pyc,,
|
| 99 |
+
reportlab/graphics/charts/__pycache__/lineplots.cpython-313.pyc,,
|
| 100 |
+
reportlab/graphics/charts/__pycache__/markers.cpython-313.pyc,,
|
| 101 |
+
reportlab/graphics/charts/__pycache__/piecharts.cpython-313.pyc,,
|
| 102 |
+
reportlab/graphics/charts/__pycache__/slidebox.cpython-313.pyc,,
|
| 103 |
+
reportlab/graphics/charts/__pycache__/spider.cpython-313.pyc,,
|
| 104 |
+
reportlab/graphics/charts/__pycache__/textlabels.cpython-313.pyc,,
|
| 105 |
+
reportlab/graphics/charts/__pycache__/utils.cpython-313.pyc,,
|
| 106 |
+
reportlab/graphics/charts/__pycache__/utils3d.cpython-313.pyc,,
|
| 107 |
+
reportlab/graphics/charts/areas.py,sha256=9E6GvYmD2GL8rvD_8wJGTbDRY_QACf1VdPcaTGlydrw,4405
|
| 108 |
+
reportlab/graphics/charts/axes.py,sha256=AAJ50IIiVbXA18NqLl92AvMNuWDh22oq0dOB8JlAGKo,92513
|
| 109 |
+
reportlab/graphics/charts/barcharts.py,sha256=i-5GTFS9S_T5zIpsyb9r-Nhsw85aBd01fDVOkniOSIs,72361
|
| 110 |
+
reportlab/graphics/charts/dotbox.py,sha256=FLiZeWoz25zCZVAQXsY1TCnVhfNthWQsOM6D6y2N56c,6628
|
| 111 |
+
reportlab/graphics/charts/doughnut.py,sha256=Gq6_UaGAx5mBjkeOUSMqR2APzDz8aH_NyG42gb2HJMw,19530
|
| 112 |
+
reportlab/graphics/charts/legends.py,sha256=NrPS_K24GJiW7hCjhO8ulF5Vj2c_iu3NQp8MdM2sBfM,25687
|
| 113 |
+
reportlab/graphics/charts/linecharts.py,sha256=D1k51H3-TeelnfBK47CP452E4U1W-r-qQemajZ8Kws0,28675
|
| 114 |
+
reportlab/graphics/charts/lineplots.py,sha256=emXwLGRCxpeJDHqnVc-V2lBLPtTrR56sM0xaQd3Y0bY,51189
|
| 115 |
+
reportlab/graphics/charts/markers.py,sha256=Of-DS7LZvC56eYMhnfAH2XEIabYzdgmA2E3Muji0_F8,1739
|
| 116 |
+
reportlab/graphics/charts/piecharts.py,sha256=ttkbMo2zZihl-4tCWME9sTFT6lN4cdxgM-5fdi0koUE,67461
|
| 117 |
+
reportlab/graphics/charts/slidebox.py,sha256=M0DoetSGAUq51uLyI8FZzpLBE54FHeZzQfcU-1CSg90,8548
|
| 118 |
+
reportlab/graphics/charts/spider.py,sha256=fYb6-DsFjIg9R4LpGXsaZdRjSgWt33yGDKi_ZqVwA6g,16132
|
| 119 |
+
reportlab/graphics/charts/textlabels.py,sha256=7ry2z4owljp07NWX7hp982dpvFP5CGYPPOZPUO7LXBo,23839
|
| 120 |
+
reportlab/graphics/charts/utils.py,sha256=9ubFHdQaL53CZ2XzmRX_8lidjTNyAgosVFKt7RsicEc,14564
|
| 121 |
+
reportlab/graphics/charts/utils3d.py,sha256=5JGiFEbFclXLZIUQaPIekebpZHQHpwU4xcEr-m9OoHU,7194
|
| 122 |
+
reportlab/graphics/renderPDF.py,sha256=zyINcwiJIF1nRv4FDRSK7UvEo6yk1s5Ki_JDCmMKy9A,15285
|
| 123 |
+
reportlab/graphics/renderPM.py,sha256=tiWc5F19Bc7NvLX6ByTAsDmEbUVGkjHOH3JPp7TgCnc,30616
|
| 124 |
+
reportlab/graphics/renderPS.py,sha256=MKVjgKYnYTyFs-xYRXhyasZLWtJWDAbvXrLAeXDr4U8,37937
|
| 125 |
+
reportlab/graphics/renderSVG.py,sha256=9oQD8vMFmNTD9r6P4iORktITRvKGk1E4lXsI0ytUCzY,38094
|
| 126 |
+
reportlab/graphics/renderbase.py,sha256=CK2i9tn9KR3shmd2q8bp9QqhdiU_n1dlRs_K7q7gEsA,13206
|
| 127 |
+
reportlab/graphics/samples/__init__.py,sha256=vAo-GLoQtBFW49nbMy-K4Q7eGMvsLt8mjbA25fNsN38,69
|
| 128 |
+
reportlab/graphics/samples/__pycache__/__init__.cpython-313.pyc,,
|
| 129 |
+
reportlab/graphics/samples/__pycache__/bubble.cpython-313.pyc,,
|
| 130 |
+
reportlab/graphics/samples/__pycache__/clustered_bar.cpython-313.pyc,,
|
| 131 |
+
reportlab/graphics/samples/__pycache__/clustered_column.cpython-313.pyc,,
|
| 132 |
+
reportlab/graphics/samples/__pycache__/excelcolors.cpython-313.pyc,,
|
| 133 |
+
reportlab/graphics/samples/__pycache__/exploded_pie.cpython-313.pyc,,
|
| 134 |
+
reportlab/graphics/samples/__pycache__/filled_radar.cpython-313.pyc,,
|
| 135 |
+
reportlab/graphics/samples/__pycache__/line_chart.cpython-313.pyc,,
|
| 136 |
+
reportlab/graphics/samples/__pycache__/linechart_with_markers.cpython-313.pyc,,
|
| 137 |
+
reportlab/graphics/samples/__pycache__/radar.cpython-313.pyc,,
|
| 138 |
+
reportlab/graphics/samples/__pycache__/runall.cpython-313.pyc,,
|
| 139 |
+
reportlab/graphics/samples/__pycache__/scatter.cpython-313.pyc,,
|
| 140 |
+
reportlab/graphics/samples/__pycache__/scatter_lines.cpython-313.pyc,,
|
| 141 |
+
reportlab/graphics/samples/__pycache__/scatter_lines_markers.cpython-313.pyc,,
|
| 142 |
+
reportlab/graphics/samples/__pycache__/simple_pie.cpython-313.pyc,,
|
| 143 |
+
reportlab/graphics/samples/__pycache__/stacked_bar.cpython-313.pyc,,
|
| 144 |
+
reportlab/graphics/samples/__pycache__/stacked_column.cpython-313.pyc,,
|
| 145 |
+
reportlab/graphics/samples/bubble.py,sha256=uCOywUXxIrr6Yzs5tRaI8N-3zcfiq9Xx4gwuEJR8mtI,3584
|
| 146 |
+
reportlab/graphics/samples/clustered_bar.py,sha256=HSBxqgAKGJLq0P3F_0BP_urxc8co7GdhTJ5LkL2w7h8,4241
|
| 147 |
+
reportlab/graphics/samples/clustered_column.py,sha256=vonAiY02Ar5rSEuaxD5AVlS6oVIfJHQKag_GUVWe7o8,4188
|
| 148 |
+
reportlab/graphics/samples/excelcolors.py,sha256=k2ZP7N61KX7HnLV1zl1fL1Dj3jhVu9UmTHZ8AbHcIB0,1947
|
| 149 |
+
reportlab/graphics/samples/exploded_pie.py,sha256=MSk48ddoJQLF3j--w9nToEn8Qleb_TiNAMSfdM9Kk8Y,3126
|
| 150 |
+
reportlab/graphics/samples/filled_radar.py,sha256=swxAKfzyf2A9jDrVpRXGhensC8GotX-2Egdj030qIzs,2691
|
| 151 |
+
reportlab/graphics/samples/line_chart.py,sha256=yuaoiE4I8KZWWtsnh5bYEKPUkH49ZYgzI2N3QNIG3VU,4267
|
| 152 |
+
reportlab/graphics/samples/linechart_with_markers.py,sha256=qeQrY13Ojp4fv3BfqWnMEHwujrF2HOpCesEptU2tZdE,5007
|
| 153 |
+
reportlab/graphics/samples/radar.py,sha256=OidkbQIB26RToqDqBEdQI-LIUOFYvYyxFz8orFq9Ot0,3244
|
| 154 |
+
reportlab/graphics/samples/runall.py,sha256=q0ZVqFWX7Kv3x497rEhTA0sTa0hC4-JoLDxYSAMriWs,1957
|
| 155 |
+
reportlab/graphics/samples/scatter.py,sha256=dEZtld2lWNGpdtH_kUjC4uFfCE7yq-R3nfGnME-ukC4,3566
|
| 156 |
+
reportlab/graphics/samples/scatter_lines.py,sha256=6OpZ33WsgmaYCJUJuW9yVxhu2xpK5BegOM0V_aTCCR8,4164
|
| 157 |
+
reportlab/graphics/samples/scatter_lines_markers.py,sha256=a0m7t1YBD4QKccCa9RriLZk-Thq_1D19iR2B09rr8Mc,3766
|
| 158 |
+
reportlab/graphics/samples/simple_pie.py,sha256=__Gjp5lNCaQ_sgJ9KQ9U36lDwSQSPPLWwv_oMmk15aw,2933
|
| 159 |
+
reportlab/graphics/samples/stacked_bar.py,sha256=SBFYdBCbsNqX1hIEiMjFmiCs8wkTo1Mp-hqplmHQET0,4284
|
| 160 |
+
reportlab/graphics/samples/stacked_column.py,sha256=TUG9fdq3ht-NETlrkoC2bJaQva5BhyPVLZKkLWNMUDM,4230
|
| 161 |
+
reportlab/graphics/shapes.py,sha256=N-zicatr6I-MZ0CbEl6gIzzIzEqEFiIPBsOJmvTvb9I,59205
|
| 162 |
+
reportlab/graphics/svgpath.py,sha256=z07KVZ3wYoyfqbvexH6nMVv2ruRLF5aK2mMOcIuV-g8,16116
|
| 163 |
+
reportlab/graphics/testdrawings.py,sha256=zsfGP5mfBq_ddavsWLXBeu0iIo18-WD-HgGGE20-QXM,9433
|
| 164 |
+
reportlab/graphics/testshapes.py,sha256=Xdnd1lbqkG0UHMnYgYURXAgtpSFuAhYotMof4AaLhYE,17237
|
| 165 |
+
reportlab/graphics/transform.py,sha256=uuNozPxzjzY6VhPSs6W6gy_l8Uq4xtw_n54nmiPjIqs,2634
|
| 166 |
+
reportlab/graphics/utils.py,sha256=GVaT_XDIvZBAUyujmadOuA2JZtrzSJmisFWV6WYjZ2M,9951
|
| 167 |
+
reportlab/graphics/widgetbase.py,sha256=QNN_tqlOn7OfydlyiS1ivklYzmgjcw658SSe2NyCOpM,25552
|
| 168 |
+
reportlab/graphics/widgets/__init__.py,sha256=PPJaG_eT9TQjOp5_XGc4BOqZpWLUZtu5P5nfC2U4iko,242
|
| 169 |
+
reportlab/graphics/widgets/__pycache__/__init__.cpython-313.pyc,,
|
| 170 |
+
reportlab/graphics/widgets/__pycache__/adjustableArrow.cpython-313.pyc,,
|
| 171 |
+
reportlab/graphics/widgets/__pycache__/eventcal.cpython-313.pyc,,
|
| 172 |
+
reportlab/graphics/widgets/__pycache__/flags.cpython-313.pyc,,
|
| 173 |
+
reportlab/graphics/widgets/__pycache__/grids.cpython-313.pyc,,
|
| 174 |
+
reportlab/graphics/widgets/__pycache__/markers.cpython-313.pyc,,
|
| 175 |
+
reportlab/graphics/widgets/__pycache__/signsandsymbols.cpython-313.pyc,,
|
| 176 |
+
reportlab/graphics/widgets/__pycache__/table.cpython-313.pyc,,
|
| 177 |
+
reportlab/graphics/widgets/adjustableArrow.py,sha256=IcqhIZfOyBR3k1qtsELLT4O1jZp0VFjjCRtYvi4GktE,3920
|
| 178 |
+
reportlab/graphics/widgets/eventcal.py,sha256=iuhpSniAQGiqQn34Y-jrz9qZiYkY3O8A_NTIj5jpR9k,13073
|
| 179 |
+
reportlab/graphics/widgets/flags.py,sha256=FDeT85o2z6y1gHM60MglWPUtl5S1bdLG67Mn1TdlH1g,30233
|
| 180 |
+
reportlab/graphics/widgets/grids.py,sha256=IZSubxWIqeXI4byoE4RZW--kHRsH1DLVfdyKllthi9E,18797
|
| 181 |
+
reportlab/graphics/widgets/markers.py,sha256=Y4kBgwCLJeloYuRj8cf5Vi0UTNJONCQaJBSXRLqGICk,8424
|
| 182 |
+
reportlab/graphics/widgets/signsandsymbols.py,sha256=Ub4U-Bh8Ggx5mw10DpieSePAicWmeMl2rxSc_zKn4cE,31655
|
| 183 |
+
reportlab/graphics/widgets/table.py,sha256=SttXvXHTdPWNEyykvsynpB63XZsq5cNKE97X_1bJLJw,6932
|
| 184 |
+
reportlab/lib/PyFontify.py,sha256=LXyOtYaLsmKOeR7cvVWP3Zg8INO2CL9yXexFfaR2Q_g,4972
|
| 185 |
+
reportlab/lib/__init__.py,sha256=cg52FA2GlrygOBsgzXMmFylBjRSSsBRD7W79ZJgqdBA,256
|
| 186 |
+
reportlab/lib/__pycache__/PyFontify.cpython-313.pyc,,
|
| 187 |
+
reportlab/lib/__pycache__/__init__.cpython-313.pyc,,
|
| 188 |
+
reportlab/lib/__pycache__/abag.cpython-313.pyc,,
|
| 189 |
+
reportlab/lib/__pycache__/arciv.cpython-313.pyc,,
|
| 190 |
+
reportlab/lib/__pycache__/attrmap.cpython-313.pyc,,
|
| 191 |
+
reportlab/lib/__pycache__/boxstuff.cpython-313.pyc,,
|
| 192 |
+
reportlab/lib/__pycache__/codecharts.cpython-313.pyc,,
|
| 193 |
+
reportlab/lib/__pycache__/colors.cpython-313.pyc,,
|
| 194 |
+
reportlab/lib/__pycache__/corp.cpython-313.pyc,,
|
| 195 |
+
reportlab/lib/__pycache__/enums.cpython-313.pyc,,
|
| 196 |
+
reportlab/lib/__pycache__/extformat.cpython-313.pyc,,
|
| 197 |
+
reportlab/lib/__pycache__/fontfinder.cpython-313.pyc,,
|
| 198 |
+
reportlab/lib/__pycache__/fonts.cpython-313.pyc,,
|
| 199 |
+
reportlab/lib/__pycache__/formatters.cpython-313.pyc,,
|
| 200 |
+
reportlab/lib/__pycache__/geomutils.cpython-313.pyc,,
|
| 201 |
+
reportlab/lib/__pycache__/logger.cpython-313.pyc,,
|
| 202 |
+
reportlab/lib/__pycache__/normalDate.cpython-313.pyc,,
|
| 203 |
+
reportlab/lib/__pycache__/pagesizes.cpython-313.pyc,,
|
| 204 |
+
reportlab/lib/__pycache__/pdfencrypt.cpython-313.pyc,,
|
| 205 |
+
reportlab/lib/__pycache__/pygments2xpre.cpython-313.pyc,,
|
| 206 |
+
reportlab/lib/__pycache__/randomtext.cpython-313.pyc,,
|
| 207 |
+
reportlab/lib/__pycache__/rl_accel.cpython-313.pyc,,
|
| 208 |
+
reportlab/lib/__pycache__/rl_safe_eval.cpython-313.pyc,,
|
| 209 |
+
reportlab/lib/__pycache__/rltempfile.cpython-313.pyc,,
|
| 210 |
+
reportlab/lib/__pycache__/rparsexml.cpython-313.pyc,,
|
| 211 |
+
reportlab/lib/__pycache__/sequencer.cpython-313.pyc,,
|
| 212 |
+
reportlab/lib/__pycache__/styles.cpython-313.pyc,,
|
| 213 |
+
reportlab/lib/__pycache__/testutils.cpython-313.pyc,,
|
| 214 |
+
reportlab/lib/__pycache__/textsplit.cpython-313.pyc,,
|
| 215 |
+
reportlab/lib/__pycache__/units.cpython-313.pyc,,
|
| 216 |
+
reportlab/lib/__pycache__/utils.cpython-313.pyc,,
|
| 217 |
+
reportlab/lib/__pycache__/validators.cpython-313.pyc,,
|
| 218 |
+
reportlab/lib/__pycache__/yaml.cpython-313.pyc,,
|
| 219 |
+
reportlab/lib/abag.py,sha256=Qrzbgwo3E--9tfTH17AIJXRbYdkoC3grBlEO-utimaM,1122
|
| 220 |
+
reportlab/lib/arciv.py,sha256=sNGHdM5iIGjuDuGJh27v4tXLwGLDDc-M7GpuLEiPwLg,7272
|
| 221 |
+
reportlab/lib/attrmap.py,sha256=wLffQAMOibcH4xKH6qyB9fgmiLj1ywm7QDGfnfZl6PY,6419
|
| 222 |
+
reportlab/lib/boxstuff.py,sha256=uMRY3lx8Xf0D2yBKlsMJ9eG8OYmnCsOgMvWB7KYUglY,2927
|
| 223 |
+
reportlab/lib/codecharts.py,sha256=LORGKfsn5KvUyRAp16NyxyFHBszTE5Us71_dG8azklM,13051
|
| 224 |
+
reportlab/lib/colors.py,sha256=E5drAie9DgU61KoOVnFX6yUna2ZWTQPGQm_hUMIIfjc,41176
|
| 225 |
+
reportlab/lib/corp.py,sha256=mHUKaM7rtev1ZH2ffZ6xk33ekeYbJonCRNmPEnzUWe8,27141
|
| 226 |
+
reportlab/lib/enums.py,sha256=TdhZCc07WdI9v3HwsxrPmmekrU9iEm_G-YlOSo85-6Y,296
|
| 227 |
+
reportlab/lib/extformat.py,sha256=1ZMde1pZxacFr6ptPI838mmAV4mTwXCU7oMK2NDXAPs,2226
|
| 228 |
+
reportlab/lib/fontfinder.py,sha256=77r1EB6dd3rnWBLbMHpU4QAvJOXH88IqMcUxYdICxTI,13391
|
| 229 |
+
reportlab/lib/fonts.py,sha256=kjPJ4sh5PTDnevIsc3Uf1rB8v31BGwhCT7WPZWC6tWY,3503
|
| 230 |
+
reportlab/lib/formatters.py,sha256=xDl4mDHXwu51voJqZ65tVR5EwgkS0S56xN2CcT6SyBU,3804
|
| 231 |
+
reportlab/lib/geomutils.py,sha256=kLm6saSTEN1TuA7nXdlEpZ8ORXfKkiGrVuMJTaT_wvw,1163
|
| 232 |
+
reportlab/lib/logger.py,sha256=ePBOOJJfSWW0twNq2y0QBX04JAycjGf3D3MZsXnJHxM,1747
|
| 233 |
+
reportlab/lib/normalDate.py,sha256=lGn3qwYw56JxUk365iyBDRovIWKr4w0vdK6zNJ3KZoM,22017
|
| 234 |
+
reportlab/lib/pagesizes.py,sha256=2FtLuzNdkJjPwIgF-nK-iepmEYCppEliHAFosngy3do,2001
|
| 235 |
+
reportlab/lib/pdfencrypt.py,sha256=rXsRyz-KgHpPA6g80vmICzGB4B6akEJaAcXjYiAMdqA,30767
|
| 236 |
+
reportlab/lib/pygments2xpre.py,sha256=FDQe9xM5LLD9ib0do9Zja0WHQ5B-wRpBGSXu5tmlXZk,2509
|
| 237 |
+
reportlab/lib/randomtext.py,sha256=BnNmW64bZxGuXz_W72koAEes41J75q5GJejisx_b-so,19572
|
| 238 |
+
reportlab/lib/rl_accel.py,sha256=MeT0qbjW6jRDMRgD18x5RTsS0HqI7z7h8VMElS7ekfg,13564
|
| 239 |
+
reportlab/lib/rl_safe_eval.py,sha256=HSVtEvKomN1zl5bbqOGQTP8EoLoAyLBqteGqUKNo7b8,40110
|
| 240 |
+
reportlab/lib/rltempfile.py,sha256=O1_qqEEl3bM9YMcOYI3dBIUNyRHqmhTL7Xb6YaF9PY0,1121
|
| 241 |
+
reportlab/lib/rparsexml.py,sha256=kwCXXUEJH_Aplaczz3b7TaFf7CNt-WKou4X-9r1zuyU,17282
|
| 242 |
+
reportlab/lib/sequencer.py,sha256=6xjMFLvHxyJ0AcqMdsezjNt_qfvhMQB02bCuf1oqQC4,9647
|
| 243 |
+
reportlab/lib/styles.py,sha256=WJQdm35JzJUiyd3RykWagwWUoiCOeMrzRv5wIC3uvAA,17349
|
| 244 |
+
reportlab/lib/testutils.py,sha256=vWGpp9GwNqeo1ZtFQ11khqdjZmBsUa1qUHxSL2m_MjQ,13556
|
| 245 |
+
reportlab/lib/textsplit.py,sha256=xYSTyGhHznxADy1biDkX7sCtxj2sWvY0yuNInpjJsqY,9723
|
| 246 |
+
reportlab/lib/units.py,sha256=C1IIiVKPCyKU4QlyvzSNT0vy6wCrygCqr1NiJXmXnnA,917
|
| 247 |
+
reportlab/lib/utils.py,sha256=Vpu7k8d6Jmn9UtYqi1ozcQQqzOOhWfLCyllpsMvK_oA,45567
|
| 248 |
+
reportlab/lib/validators.py,sha256=oVYs5yfSx7BsMbe9XQrNNVJWbW1u0Jj034UqhAMY-uw,11333
|
| 249 |
+
reportlab/lib/yaml.py,sha256=6I6OgXFyfhwSVgVFslpYXQMcS9Rjj-Rvj7sYr93SbI8,5717
|
| 250 |
+
reportlab/pdfbase/__init__.py,sha256=oiUC2mJqpwZNnCvtb1rxckUBGx99a2wlgX_4VtAYWIs,275
|
| 251 |
+
reportlab/pdfbase/__pycache__/__init__.cpython-313.pyc,,
|
| 252 |
+
reportlab/pdfbase/__pycache__/_can_cmap_data.cpython-313.pyc,,
|
| 253 |
+
reportlab/pdfbase/__pycache__/_cidfontdata.cpython-313.pyc,,
|
| 254 |
+
reportlab/pdfbase/__pycache__/_fontdata.cpython-313.pyc,,
|
| 255 |
+
reportlab/pdfbase/__pycache__/_fontdata_enc_macexpert.cpython-313.pyc,,
|
| 256 |
+
reportlab/pdfbase/__pycache__/_fontdata_enc_macroman.cpython-313.pyc,,
|
| 257 |
+
reportlab/pdfbase/__pycache__/_fontdata_enc_pdfdoc.cpython-313.pyc,,
|
| 258 |
+
reportlab/pdfbase/__pycache__/_fontdata_enc_standard.cpython-313.pyc,,
|
| 259 |
+
reportlab/pdfbase/__pycache__/_fontdata_enc_symbol.cpython-313.pyc,,
|
| 260 |
+
reportlab/pdfbase/__pycache__/_fontdata_enc_winansi.cpython-313.pyc,,
|
| 261 |
+
reportlab/pdfbase/__pycache__/_fontdata_enc_zapfdingbats.cpython-313.pyc,,
|
| 262 |
+
reportlab/pdfbase/__pycache__/_fontdata_widths_courier.cpython-313.pyc,,
|
| 263 |
+
reportlab/pdfbase/__pycache__/_fontdata_widths_courierbold.cpython-313.pyc,,
|
| 264 |
+
reportlab/pdfbase/__pycache__/_fontdata_widths_courierboldoblique.cpython-313.pyc,,
|
| 265 |
+
reportlab/pdfbase/__pycache__/_fontdata_widths_courieroblique.cpython-313.pyc,,
|
| 266 |
+
reportlab/pdfbase/__pycache__/_fontdata_widths_helvetica.cpython-313.pyc,,
|
| 267 |
+
reportlab/pdfbase/__pycache__/_fontdata_widths_helveticabold.cpython-313.pyc,,
|
| 268 |
+
reportlab/pdfbase/__pycache__/_fontdata_widths_helveticaboldoblique.cpython-313.pyc,,
|
| 269 |
+
reportlab/pdfbase/__pycache__/_fontdata_widths_helveticaoblique.cpython-313.pyc,,
|
| 270 |
+
reportlab/pdfbase/__pycache__/_fontdata_widths_symbol.cpython-313.pyc,,
|
| 271 |
+
reportlab/pdfbase/__pycache__/_fontdata_widths_timesbold.cpython-313.pyc,,
|
| 272 |
+
reportlab/pdfbase/__pycache__/_fontdata_widths_timesbolditalic.cpython-313.pyc,,
|
| 273 |
+
reportlab/pdfbase/__pycache__/_fontdata_widths_timesitalic.cpython-313.pyc,,
|
| 274 |
+
reportlab/pdfbase/__pycache__/_fontdata_widths_timesroman.cpython-313.pyc,,
|
| 275 |
+
reportlab/pdfbase/__pycache__/_fontdata_widths_zapfdingbats.cpython-313.pyc,,
|
| 276 |
+
reportlab/pdfbase/__pycache__/_glyphlist.cpython-313.pyc,,
|
| 277 |
+
reportlab/pdfbase/__pycache__/acroform.cpython-313.pyc,,
|
| 278 |
+
reportlab/pdfbase/__pycache__/cidfonts.cpython-313.pyc,,
|
| 279 |
+
reportlab/pdfbase/__pycache__/pdfdoc.cpython-313.pyc,,
|
| 280 |
+
reportlab/pdfbase/__pycache__/pdfform.cpython-313.pyc,,
|
| 281 |
+
reportlab/pdfbase/__pycache__/pdfmetrics.cpython-313.pyc,,
|
| 282 |
+
reportlab/pdfbase/__pycache__/pdfpattern.cpython-313.pyc,,
|
| 283 |
+
reportlab/pdfbase/__pycache__/pdfutils.cpython-313.pyc,,
|
| 284 |
+
reportlab/pdfbase/__pycache__/rl_codecs.cpython-313.pyc,,
|
| 285 |
+
reportlab/pdfbase/__pycache__/ttfonts.cpython-313.pyc,,
|
| 286 |
+
reportlab/pdfbase/_can_cmap_data.py,sha256=eLgtLlMO4ua_gYrK7Dsqjf04nIy82XemKnrSBnsjwuQ,1794
|
| 287 |
+
reportlab/pdfbase/_cidfontdata.py,sha256=lMoQEyVvNRDNUr-nPtxlxCmYdu7XaYZKpkiNp9nhGJc,32044
|
| 288 |
+
reportlab/pdfbase/_fontdata.py,sha256=O9ryuHZNPmHOylKV8H6SOK3Sy9TZ_-Jcn5rnq42tIbI,10141
|
| 289 |
+
reportlab/pdfbase/_fontdata_enc_macexpert.py,sha256=ClfNd-MT3BGr1phH_gzcSw2H5bgXMsolE_3OP-IkUO8,3058
|
| 290 |
+
reportlab/pdfbase/_fontdata_enc_macroman.py,sha256=I1zD-Hr2DU2gCcwSUNZQj_aXhjVe6ECCsMUhnfND3jM,2934
|
| 291 |
+
reportlab/pdfbase/_fontdata_enc_pdfdoc.py,sha256=q2nUHX7tkPGK3dVd1kePqa-VkWqd1R9uyg097EJSiAo,2308
|
| 292 |
+
reportlab/pdfbase/_fontdata_enc_standard.py,sha256=9HcDnKlKOL2Fx2L6SoWtPDTbsB4t8HVxXCD1hoIAIo4,1829
|
| 293 |
+
reportlab/pdfbase/_fontdata_enc_symbol.py,sha256=kzNVNuDFxtgN1ZlNBQ8zlA6OH8OoKMv7oTthAWFss3I,3187
|
| 294 |
+
reportlab/pdfbase/_fontdata_enc_winansi.py,sha256=57XRvkA1GhkzPcF0FXO9joAUw2O0qEXI3mNpPqfGKaI,3003
|
| 295 |
+
reportlab/pdfbase/_fontdata_enc_zapfdingbats.py,sha256=k5j8j09O5fYGfH0X3KkNO1V4fnlrl_NipRu8lFm4qEo,2222
|
| 296 |
+
reportlab/pdfbase/_fontdata_widths_courier.py,sha256=w4fRJIRgrp-MDWymwqDbbw_QuwFr2aYLvSUOhhQf-5g,3664
|
| 297 |
+
reportlab/pdfbase/_fontdata_widths_courierbold.py,sha256=w4fRJIRgrp-MDWymwqDbbw_QuwFr2aYLvSUOhhQf-5g,3664
|
| 298 |
+
reportlab/pdfbase/_fontdata_widths_courierboldoblique.py,sha256=w4fRJIRgrp-MDWymwqDbbw_QuwFr2aYLvSUOhhQf-5g,3664
|
| 299 |
+
reportlab/pdfbase/_fontdata_widths_courieroblique.py,sha256=w4fRJIRgrp-MDWymwqDbbw_QuwFr2aYLvSUOhhQf-5g,3664
|
| 300 |
+
reportlab/pdfbase/_fontdata_widths_helvetica.py,sha256=EBCzwP-JeztGe7iTUAvopvqU8Vw0_csW64PIxXc_khE,3671
|
| 301 |
+
reportlab/pdfbase/_fontdata_widths_helveticabold.py,sha256=YbMPWo67kjlx5RYOqF_WdpufHOO2aJ-v58cCNUpekyg,3670
|
| 302 |
+
reportlab/pdfbase/_fontdata_widths_helveticaboldoblique.py,sha256=YbMPWo67kjlx5RYOqF_WdpufHOO2aJ-v58cCNUpekyg,3670
|
| 303 |
+
reportlab/pdfbase/_fontdata_widths_helveticaoblique.py,sha256=EBCzwP-JeztGe7iTUAvopvqU8Vw0_csW64PIxXc_khE,3671
|
| 304 |
+
reportlab/pdfbase/_fontdata_widths_symbol.py,sha256=qQxY2G61Q5acFLbp9GsiuMs9aCOplTF5J12CVDL17TE,3367
|
| 305 |
+
reportlab/pdfbase/_fontdata_widths_timesbold.py,sha256=90Q7bOblwYi6uqZHPzi1tGw0hInYgvDnfh1kPIYpaOw,3672
|
| 306 |
+
reportlab/pdfbase/_fontdata_widths_timesbolditalic.py,sha256=h2MrmjURm9kv8HizZmDI-jjf0ynvnvSsliOm9C-lSzo,3668
|
| 307 |
+
reportlab/pdfbase/_fontdata_widths_timesitalic.py,sha256=GodVy_FKoKtPoMwJL_zsRoOfAZRakwe84EaelWukNx8,3665
|
| 308 |
+
reportlab/pdfbase/_fontdata_widths_timesroman.py,sha256=GDKPJYaQVavphIeq39Lj2-dqsmhJtpO4Fl8A3L5nnxQ,3667
|
| 309 |
+
reportlab/pdfbase/_fontdata_widths_zapfdingbats.py,sha256=jbGCbd3tyy4VwxyuUlzVl68iLgvRafyHIJz8s24ZlgI,2732
|
| 310 |
+
reportlab/pdfbase/_glyphlist.py,sha256=9vOqPQpXQ_QZn48s8uHCiwWJQLYtB3c4GNyNiLhCnjc,108467
|
| 311 |
+
reportlab/pdfbase/acroform.py,sha256=ona97xS_ffmKsy_kaOXIJ-QtLhVNmTGfg8T4EtJHJiY,49786
|
| 312 |
+
reportlab/pdfbase/cidfonts.py,sha256=ZizaaFc-jqZTiY6DYHSwDuX4qdX1092lkgLPREVB2Vc,18789
|
| 313 |
+
reportlab/pdfbase/pdfdoc.py,sha256=IgGaX65VHztDC2ZuVo5boNGZN2tZR0Z1-WplnejNCoY,91182
|
| 314 |
+
reportlab/pdfbase/pdfform.py,sha256=CMHW_jqwtoqxgESVOX212-C5kEEKj3p35H_Zo3ap-Qc,15704
|
| 315 |
+
reportlab/pdfbase/pdfmetrics.py,sha256=0879b8dW0hNLd8FNxhzrkB1XoPIfD1-L0P5-sA5Qt_s,29956
|
| 316 |
+
reportlab/pdfbase/pdfpattern.py,sha256=O7Kr7iieqfk0MH6JpFO6ToCGMqJbZ0dMvcmZfcDuAlE,3763
|
| 317 |
+
reportlab/pdfbase/pdfutils.py,sha256=WU7jGfHWhfpJsobZlWvfJpVzCdr5f8tgc1cL52UD3Ps,10135
|
| 318 |
+
reportlab/pdfbase/rl_codecs.py,sha256=Moo6kC2FkBTxqtOz7T62Q8qpTpvVe17Yw3UPBeCrshE,56426
|
| 319 |
+
reportlab/pdfbase/ttfonts.py,sha256=nfnSSDLjao24VAiEVVj-JQhYDYVl87BEcDPBHwqzosc,62605
|
| 320 |
+
reportlab/pdfgen/__init__.py,sha256=YIULQ7o_r2neGvTaz6aok41YW5U7A6DtMIZVxOt8TI0,270
|
| 321 |
+
reportlab/pdfgen/__pycache__/__init__.cpython-313.pyc,,
|
| 322 |
+
reportlab/pdfgen/__pycache__/canvas.cpython-313.pyc,,
|
| 323 |
+
reportlab/pdfgen/__pycache__/pathobject.cpython-313.pyc,,
|
| 324 |
+
reportlab/pdfgen/__pycache__/pdfgeom.cpython-313.pyc,,
|
| 325 |
+
reportlab/pdfgen/__pycache__/pdfimages.cpython-313.pyc,,
|
| 326 |
+
reportlab/pdfgen/__pycache__/textobject.cpython-313.pyc,,
|
| 327 |
+
reportlab/pdfgen/canvas.py,sha256=jkJW28pwlW3VEdxvLzHntpCLy2B8blYz0oXCMlY7YmI,83283
|
| 328 |
+
reportlab/pdfgen/pathobject.py,sha256=HbhBllc5vhh8hRM9Mlo_oTqdOdWWxaXLe6aNbe-E84g,5737
|
| 329 |
+
reportlab/pdfgen/pdfgeom.py,sha256=BBK4mv_p6Ih67aFunZ2kyCtPzMsCmWlYJR3KenFkK54,2980
|
| 330 |
+
reportlab/pdfgen/pdfimages.py,sha256=zdNadQAuU-Ifl4eGjLZHsX5Gfn6PTyfC0Wac62EXDBM,8422
|
| 331 |
+
reportlab/pdfgen/textobject.py,sha256=uCaP4pOD01hfSX9m4wdxgGEDnDIDly3T0IYh-fLcbX4,32403
|
| 332 |
+
reportlab/platypus/__init__.py,sha256=aZkzft7oR6A4JyeUzq-CZBaW91a3WzFcZ-isJzRgmtk,502
|
| 333 |
+
reportlab/platypus/__pycache__/__init__.cpython-313.pyc,,
|
| 334 |
+
reportlab/platypus/__pycache__/doctemplate.cpython-313.pyc,,
|
| 335 |
+
reportlab/platypus/__pycache__/figures.cpython-313.pyc,,
|
| 336 |
+
reportlab/platypus/__pycache__/flowables.cpython-313.pyc,,
|
| 337 |
+
reportlab/platypus/__pycache__/frames.cpython-313.pyc,,
|
| 338 |
+
reportlab/platypus/__pycache__/multicol.cpython-313.pyc,,
|
| 339 |
+
reportlab/platypus/__pycache__/para.cpython-313.pyc,,
|
| 340 |
+
reportlab/platypus/__pycache__/paragraph.cpython-313.pyc,,
|
| 341 |
+
reportlab/platypus/__pycache__/paraparser.cpython-313.pyc,,
|
| 342 |
+
reportlab/platypus/__pycache__/tableofcontents.cpython-313.pyc,,
|
| 343 |
+
reportlab/platypus/__pycache__/tables.cpython-313.pyc,,
|
| 344 |
+
reportlab/platypus/__pycache__/xpreformatted.cpython-313.pyc,,
|
| 345 |
+
reportlab/platypus/doctemplate.py,sha256=FdZYW-bG4m6Nsz6N8YNgY-ZDx8vVPFogp9GisQoF1xc,54975
|
| 346 |
+
reportlab/platypus/figures.py,sha256=y5CuWsihvjDg9PZv40ujZNzCy9rdNRgrPT8bkqNQzNA,18313
|
| 347 |
+
reportlab/platypus/flowables.py,sha256=sIYOvGk-JDX94-kTFkND46Z-bezcfttItKD_8snuKxo,98789
|
| 348 |
+
reportlab/platypus/frames.py,sha256=YaBsHyD6lVDFvXyHusk1znU5yR-CcZbsuUzT0k-N2JU,10144
|
| 349 |
+
reportlab/platypus/multicol.py,sha256=h5kuceNlx1cSMbKHjYMlNGY7QRc9xWt72-pQHjnS9-s,2753
|
| 350 |
+
reportlab/platypus/para.py,sha256=tDcb_WU3H9vRwXNwPqnaxcu1qHZPfKcv7FJQhRUoC0g,93001
|
| 351 |
+
reportlab/platypus/paragraph.py,sha256=yfSkCgXbqYeLUvnSUjHqouUfxNtL6Vx0KtqnfcHpHOg,122871
|
| 352 |
+
reportlab/platypus/paraparser.py,sha256=YOwHCE4hf7HW3VsgKCpnUTZBCAht8kGvtIbS3ocTkjw,213967
|
| 353 |
+
reportlab/platypus/tableofcontents.py,sha256=MHIUapk6xP6Ud7nSsbzhjyogzZwfPFQOfLw_lCF_R3o,21482
|
| 354 |
+
reportlab/platypus/tables.py,sha256=wqdpnLnW2YSkL6VuUhGar5_a5zN-b1ZJdUECklBVt8s,120579
|
| 355 |
+
reportlab/platypus/xpreformatted.py,sha256=atuGq80R1TD-qqjHQH7tdj8ofmMby3H8TxIQ6hS8l5I,12947
|
| 356 |
+
reportlab/rl_config.py,sha256=oerXWINlNE4dz5S7NX2EH5yu6nS9M0uk3XjoYlv7DY4,5115
|
| 357 |
+
reportlab/rl_settings.py,sha256=6Ix64tPM61ECU5QsAonPGvGs46UKBnD0K6m0sNwTVKE,15630
|
.venv/lib/python3.13/site-packages/reportlab-5.0.0.dist-info/REQUESTED
ADDED
|
File without changes
|
.venv/lib/python3.13/site-packages/reportlab-5.0.0.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: setuptools (82.0.1)
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: py3-none-any
|
| 5 |
+
|
.venv/lib/python3.13/site-packages/reportlab-5.0.0.dist-info/licenses/LICENSE
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#####################################################################################
|
| 2 |
+
#
|
| 3 |
+
# Copyright (c) 2000-2024, ReportLab Inc.
|
| 4 |
+
# All rights reserved.
|
| 5 |
+
#
|
| 6 |
+
# Redistribution and use in source and binary forms, with or without modification,
|
| 7 |
+
# are permitted provided that the following conditions are met:
|
| 8 |
+
#
|
| 9 |
+
# * Redistributions of source code must retain the above copyright notice,
|
| 10 |
+
# this list of conditions and the following disclaimer.
|
| 11 |
+
# * Redistributions in binary form must reproduce the above copyright notice,
|
| 12 |
+
# this list of conditions and the following disclaimer in the documentation
|
| 13 |
+
# and/or other materials provided with the distribution.
|
| 14 |
+
# * Neither the name of the company nor the names of its contributors may be
|
| 15 |
+
# used to endorse or promote products derived from this software without
|
| 16 |
+
# specific prior written permission.
|
| 17 |
+
#
|
| 18 |
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
| 19 |
+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
| 20 |
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
| 21 |
+
# IN NO EVENT SHALL THE OFFICERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
| 22 |
+
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
| 23 |
+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
| 24 |
+
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
| 25 |
+
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
| 26 |
+
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
| 27 |
+
# SUCH DAMAGE.
|
| 28 |
+
#
|
| 29 |
+
#####################################################################################
|
.venv/lib/python3.13/site-packages/reportlab-5.0.0.dist-info/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
reportlab
|
.venv/lib/python3.13/site-packages/reportlab/platypus/paragraph.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
.venv/lib/python3.13/site-packages/reportlab/platypus/paraparser.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
.venv/lib/python3.13/site-packages/reportlab/platypus/tableofcontents.py
ADDED
|
@@ -0,0 +1,559 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#Copyright ReportLab Europe Ltd. 2000-2017
|
| 2 |
+
#see license.txt for license details
|
| 3 |
+
#history https://hg.reportlab.com/hg-public/reportlab/log/tip/src/reportlab/platypus/tableofcontents.py
|
| 4 |
+
|
| 5 |
+
__version__='4.2.1.1'
|
| 6 |
+
__doc__="""Experimental class to generate Tables of Contents easily
|
| 7 |
+
|
| 8 |
+
This module defines a single TableOfContents() class that can be used to
|
| 9 |
+
create automatically a table of tontents for Platypus documents like
|
| 10 |
+
this:
|
| 11 |
+
|
| 12 |
+
story = []
|
| 13 |
+
toc = TableOfContents()
|
| 14 |
+
story.append(toc)
|
| 15 |
+
# some heading paragraphs here...
|
| 16 |
+
doc = MyTemplate(path)
|
| 17 |
+
doc.multiBuild(story)
|
| 18 |
+
|
| 19 |
+
The data needed to create the table is a list of (level, text, pageNum)
|
| 20 |
+
triplets, plus some paragraph styles for each level of the table itself.
|
| 21 |
+
The triplets will usually be created in a document template's method
|
| 22 |
+
like afterFlowable(), making notification calls using the notify()
|
| 23 |
+
method with appropriate data like this:
|
| 24 |
+
|
| 25 |
+
(level, text, pageNum) = ...
|
| 26 |
+
self.notify('TOCEntry', (level, text, pageNum))
|
| 27 |
+
|
| 28 |
+
Optionally the list can contain four items in which case the last item
|
| 29 |
+
is a destination key which the entry should point to. A bookmark
|
| 30 |
+
with this key needs to be created first like this:
|
| 31 |
+
|
| 32 |
+
key = 'ch%s' % self.seq.nextf('chapter')
|
| 33 |
+
self.canv.bookmarkPage(key)
|
| 34 |
+
self.notify('TOCEntry', (level, text, pageNum, key))
|
| 35 |
+
|
| 36 |
+
As the table of contents need at least two passes over the Platypus
|
| 37 |
+
story which is why the multiBuild() method must be called.
|
| 38 |
+
|
| 39 |
+
The level<NUMBER>ParaStyle variables are the paragraph styles used
|
| 40 |
+
to format the entries in the table of contents. Their indentation
|
| 41 |
+
is calculated like this: each entry starts at a multiple of some
|
| 42 |
+
constant named delta. If one entry spans more than one line, all
|
| 43 |
+
lines after the first are indented by the same constant named
|
| 44 |
+
epsilon.
|
| 45 |
+
"""
|
| 46 |
+
|
| 47 |
+
from reportlab.lib.units import cm
|
| 48 |
+
from reportlab.lib.utils import commasplit, escapeOnce, encode_label, decode_label, strTypes, asUnicode, asNative
|
| 49 |
+
from reportlab.lib.styles import ParagraphStyle, _baseFontName
|
| 50 |
+
from reportlab.lib import sequencer as rl_sequencer
|
| 51 |
+
from reportlab.platypus.paragraph import Paragraph
|
| 52 |
+
from reportlab.platypus.doctemplate import IndexingFlowable
|
| 53 |
+
from reportlab.platypus.tables import TableStyle, Table
|
| 54 |
+
from reportlab.platypus.flowables import Spacer
|
| 55 |
+
from reportlab.pdfbase.pdfmetrics import stringWidth
|
| 56 |
+
from reportlab.pdfgen import canvas
|
| 57 |
+
import unicodedata
|
| 58 |
+
from ast import literal_eval
|
| 59 |
+
|
| 60 |
+
def unquote(txt):
|
| 61 |
+
from xml.sax.saxutils import unescape
|
| 62 |
+
return unescape(txt, {"'": "'", """: '"'})
|
| 63 |
+
|
| 64 |
+
try:
|
| 65 |
+
set
|
| 66 |
+
except:
|
| 67 |
+
class set(list):
|
| 68 |
+
def add(self,x):
|
| 69 |
+
if x not in self:
|
| 70 |
+
list.append(self,x)
|
| 71 |
+
|
| 72 |
+
def drawPageNumbers(canvas, style, pages, availWidth, availHeight, dot=' . ', formatter=None):
|
| 73 |
+
'''
|
| 74 |
+
Draws pagestr on the canvas using the given style.
|
| 75 |
+
If dot is None, pagestr is drawn at the current position in the canvas.
|
| 76 |
+
If dot is a string, pagestr is drawn right-aligned. If the string is not empty,
|
| 77 |
+
the gap is filled with it.
|
| 78 |
+
'''
|
| 79 |
+
pagestr = ', '.join([str(p) for p, _ in pages])
|
| 80 |
+
x, y = canvas._curr_tx_info['cur_x'], canvas._curr_tx_info['cur_y']
|
| 81 |
+
|
| 82 |
+
fontSize = style.fontSize
|
| 83 |
+
pagestrw = stringWidth(pagestr, style.fontName, fontSize)
|
| 84 |
+
|
| 85 |
+
#if it's too long to fit, we need to shrink to fit in 10% increments.
|
| 86 |
+
#it would be very hard to output multiline entries.
|
| 87 |
+
#however, we impose a minimum size of 1 point as we don't want an
|
| 88 |
+
#infinite loop. Ultimately we should allow a TOC entry to spill
|
| 89 |
+
#over onto a second line if needed.
|
| 90 |
+
freeWidth = availWidth-x
|
| 91 |
+
while pagestrw > freeWidth and fontSize >= 1.0:
|
| 92 |
+
fontSize = 0.9 * fontSize
|
| 93 |
+
pagestrw = stringWidth(pagestr, style.fontName, fontSize)
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
if isinstance(dot, strTypes):
|
| 97 |
+
if dot:
|
| 98 |
+
dotw = stringWidth(dot, style.fontName, fontSize)
|
| 99 |
+
dotsn = int((availWidth-x-pagestrw)/dotw)
|
| 100 |
+
else:
|
| 101 |
+
dotsn = dotw = 0
|
| 102 |
+
text = '%s%s' % (dotsn * dot, pagestr)
|
| 103 |
+
newx = availWidth - dotsn*dotw - pagestrw
|
| 104 |
+
pagex = availWidth - pagestrw
|
| 105 |
+
elif dot is None:
|
| 106 |
+
text = ', ' + pagestr
|
| 107 |
+
newx = x
|
| 108 |
+
pagex = newx
|
| 109 |
+
else:
|
| 110 |
+
raise TypeError('Argument dot should either be None or an instance of basestring.')
|
| 111 |
+
|
| 112 |
+
tx = canvas.beginText(newx, y)
|
| 113 |
+
tx.setFont(style.fontName, fontSize)
|
| 114 |
+
tx.setFillColor(style.textColor)
|
| 115 |
+
tx.textLine(text)
|
| 116 |
+
canvas.drawText(tx)
|
| 117 |
+
|
| 118 |
+
commaw = stringWidth(', ', style.fontName, fontSize)
|
| 119 |
+
for p, key in pages:
|
| 120 |
+
if not key:
|
| 121 |
+
continue
|
| 122 |
+
w = stringWidth(str(p), style.fontName, fontSize)
|
| 123 |
+
canvas.linkRect('', key, (pagex, y, pagex+w, y+style.leading), relative=1)
|
| 124 |
+
pagex += w + commaw
|
| 125 |
+
|
| 126 |
+
# Default paragraph styles for tables of contents.
|
| 127 |
+
# (This could also be generated automatically or even
|
| 128 |
+
# on-demand if it is not known how many levels the
|
| 129 |
+
# TOC will finally need to display...)
|
| 130 |
+
|
| 131 |
+
delta = 1*cm
|
| 132 |
+
epsilon = 0.5*cm
|
| 133 |
+
|
| 134 |
+
defaultLevelStyles = [
|
| 135 |
+
ParagraphStyle(
|
| 136 |
+
name='Level 0',
|
| 137 |
+
fontName=_baseFontName,
|
| 138 |
+
fontSize=10,
|
| 139 |
+
leading=11,
|
| 140 |
+
firstLineIndent = 0,
|
| 141 |
+
leftIndent = epsilon)]
|
| 142 |
+
|
| 143 |
+
defaultTableStyle = \
|
| 144 |
+
TableStyle([
|
| 145 |
+
('VALIGN', (0,0), (-1,-1), 'TOP'),
|
| 146 |
+
('RIGHTPADDING', (0,0), (-1,-1), 0),
|
| 147 |
+
('LEFTPADDING', (0,0), (-1,-1), 0),
|
| 148 |
+
])
|
| 149 |
+
|
| 150 |
+
class TableOfContents(IndexingFlowable):
|
| 151 |
+
"""This creates a formatted table of contents.
|
| 152 |
+
|
| 153 |
+
It presumes a correct block of data is passed in.
|
| 154 |
+
The data block contains a list of (level, text, pageNumber)
|
| 155 |
+
triplets. You can supply a paragraph style for each level
|
| 156 |
+
(starting at zero).
|
| 157 |
+
Set dotsMinLevel to determine from which level on a line of
|
| 158 |
+
dots should be drawn between the text and the page number.
|
| 159 |
+
If dotsMinLevel is set to a negative value, no dotted lines are drawn.
|
| 160 |
+
"""
|
| 161 |
+
|
| 162 |
+
def __init__(self,**kwds):
|
| 163 |
+
self.rightColumnWidth = kwds.pop('rightColumnWidth',72)
|
| 164 |
+
self.levelStyles = kwds.pop('levelStyles',defaultLevelStyles)
|
| 165 |
+
self.tableStyle = kwds.pop('tableStyle',defaultTableStyle)
|
| 166 |
+
self.dotsMinLevel = kwds.pop('dotsMinLevel',1)
|
| 167 |
+
self.formatter = kwds.pop('formatter',None)
|
| 168 |
+
self._notifyKind = kwds.pop('notifyKind','TOCEntry')
|
| 169 |
+
if kwds: raise ValueError('unexpected keyword arguments %s' % ', '.join(kwds.keys()))
|
| 170 |
+
self._table = None
|
| 171 |
+
self._entries = []
|
| 172 |
+
self._lastEntries = []
|
| 173 |
+
|
| 174 |
+
def beforeBuild(self):
|
| 175 |
+
# keep track of the last run
|
| 176 |
+
self._lastEntries = self._entries[:]
|
| 177 |
+
self.clearEntries()
|
| 178 |
+
|
| 179 |
+
def isIndexing(self):
|
| 180 |
+
return 1
|
| 181 |
+
|
| 182 |
+
def isSatisfied(self):
|
| 183 |
+
return (self._entries == self._lastEntries)
|
| 184 |
+
|
| 185 |
+
def notify(self, kind, stuff):
|
| 186 |
+
"""The notification hook called to register all kinds of events.
|
| 187 |
+
|
| 188 |
+
Here we are interested in self._notifyKind (default TOCEntry) events only.
|
| 189 |
+
"""
|
| 190 |
+
if kind == self._notifyKind:
|
| 191 |
+
self.addEntry(*stuff)
|
| 192 |
+
|
| 193 |
+
def clearEntries(self):
|
| 194 |
+
self._entries = []
|
| 195 |
+
|
| 196 |
+
def getLevelStyle(self, n):
|
| 197 |
+
'''Returns the style for level n, generating and caching styles on demand if not present.'''
|
| 198 |
+
try:
|
| 199 |
+
return self.levelStyles[n]
|
| 200 |
+
except IndexError:
|
| 201 |
+
prevstyle = self.getLevelStyle(n-1)
|
| 202 |
+
self.levelStyles.append(ParagraphStyle(
|
| 203 |
+
name='%s-%d-indented' % (prevstyle.name, n),
|
| 204 |
+
parent=prevstyle,
|
| 205 |
+
firstLineIndent = prevstyle.firstLineIndent+delta,
|
| 206 |
+
leftIndent = prevstyle.leftIndent+delta))
|
| 207 |
+
return self.levelStyles[n]
|
| 208 |
+
|
| 209 |
+
def addEntry(self, level, text, pageNum, key=None):
|
| 210 |
+
"""Adds one entry to the table of contents.
|
| 211 |
+
|
| 212 |
+
This allows incremental buildup by a doctemplate.
|
| 213 |
+
Requires that enough styles are defined."""
|
| 214 |
+
|
| 215 |
+
assert type(level) == type(1), "Level must be an integer"
|
| 216 |
+
self._entries.append((level, text, pageNum, key))
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
def addEntries(self, listOfEntries):
|
| 220 |
+
"""Bulk creation of entries in the table of contents.
|
| 221 |
+
|
| 222 |
+
If you knew the titles but not the page numbers, you could
|
| 223 |
+
supply them to get sensible output on the first run."""
|
| 224 |
+
|
| 225 |
+
for entryargs in listOfEntries:
|
| 226 |
+
self.addEntry(*entryargs)
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
def wrap(self, availWidth, availHeight):
|
| 230 |
+
"All table properties should be known by now."
|
| 231 |
+
|
| 232 |
+
# makes an internal table which does all the work.
|
| 233 |
+
# we draw the LAST RUN's entries! If there are
|
| 234 |
+
# none, we make some dummy data to keep the table
|
| 235 |
+
# from complaining
|
| 236 |
+
if len(self._lastEntries) == 0:
|
| 237 |
+
_tempEntries = [(0,'Placeholder for table of contents',0,None)]
|
| 238 |
+
else:
|
| 239 |
+
_tempEntries = self._lastEntries
|
| 240 |
+
|
| 241 |
+
def drawTOCEntryEnd(canvas, kind, label):
|
| 242 |
+
'''Callback to draw dots and page numbers after each entry.'''
|
| 243 |
+
label = label.split(',')
|
| 244 |
+
page, level, key = int(label[0]), int(label[1]), literal_eval(label[2])
|
| 245 |
+
style = self.getLevelStyle(level)
|
| 246 |
+
if self.dotsMinLevel >= 0 and level >= self.dotsMinLevel:
|
| 247 |
+
dot = ' . '
|
| 248 |
+
else:
|
| 249 |
+
dot = ''
|
| 250 |
+
if self.formatter: page = self.formatter(page)
|
| 251 |
+
drawPageNumbers(canvas, style, [(page, key)], availWidth, availHeight, dot)
|
| 252 |
+
self.canv.setNamedCB('drawTOCEntryEnd',drawTOCEntryEnd)
|
| 253 |
+
|
| 254 |
+
tableData = []
|
| 255 |
+
for (level, text, pageNum, key) in _tempEntries:
|
| 256 |
+
style = self.getLevelStyle(level)
|
| 257 |
+
if key:
|
| 258 |
+
text = '<a href="#%s">%s</a>' % (key, text)
|
| 259 |
+
keyVal = repr(key).replace(',','\\x2c').replace('"','\\x2c')
|
| 260 |
+
else:
|
| 261 |
+
keyVal = None
|
| 262 |
+
para = Paragraph('%s<onDraw name="drawTOCEntryEnd" label="%d,%d,%s"/>' % (text, pageNum, level, keyVal), style)
|
| 263 |
+
if style.spaceBefore:
|
| 264 |
+
tableData.append([Spacer(1, style.spaceBefore),])
|
| 265 |
+
tableData.append([para,])
|
| 266 |
+
|
| 267 |
+
self._table = Table(tableData, colWidths=(availWidth,), style=self.tableStyle)
|
| 268 |
+
|
| 269 |
+
self.width, self.height = self._table.wrapOn(self.canv,availWidth, availHeight)
|
| 270 |
+
return (self.width, self.height)
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
def split(self, availWidth, availHeight):
|
| 274 |
+
"""At this stage we do not care about splitting the entries,
|
| 275 |
+
we will just return a list of platypus tables. Presumably the
|
| 276 |
+
calling app has a pointer to the original TableOfContents object;
|
| 277 |
+
Platypus just sees tables.
|
| 278 |
+
"""
|
| 279 |
+
return self._table.splitOn(self.canv,availWidth, availHeight)
|
| 280 |
+
|
| 281 |
+
|
| 282 |
+
def drawOn(self, canvas, x, y, _sW=0):
|
| 283 |
+
"""Don't do this at home! The standard calls for implementing
|
| 284 |
+
draw(); we are hooking this in order to delegate ALL the drawing
|
| 285 |
+
work to the embedded table object.
|
| 286 |
+
"""
|
| 287 |
+
self._table.drawOn(canvas, x, y, _sW)
|
| 288 |
+
|
| 289 |
+
def makeTuple(x):
|
| 290 |
+
if isinstance(x,(list,tuple)):
|
| 291 |
+
return tuple(x)
|
| 292 |
+
return (x,)
|
| 293 |
+
|
| 294 |
+
class SimpleIndex(IndexingFlowable):
|
| 295 |
+
"""Creates multi level indexes.
|
| 296 |
+
The styling can be cutomized and alphabetic headers turned on and off.
|
| 297 |
+
"""
|
| 298 |
+
|
| 299 |
+
def __init__(self, **kwargs):
|
| 300 |
+
"""
|
| 301 |
+
Constructor of SimpleIndex.
|
| 302 |
+
Accepts the same arguments as the setup method.
|
| 303 |
+
"""
|
| 304 |
+
#keep stuff in a dictionary while building
|
| 305 |
+
self._entries = {}
|
| 306 |
+
self._lastEntries = {}
|
| 307 |
+
self._flowable = None
|
| 308 |
+
self._notifyKind = kwargs.pop('notifyKind','IndexEntry')
|
| 309 |
+
self.setup(**kwargs)
|
| 310 |
+
|
| 311 |
+
def getFormatFunc(self,formatName):
|
| 312 |
+
try:
|
| 313 |
+
return getattr(rl_sequencer,'_format_%s' % formatName)
|
| 314 |
+
except ImportError:
|
| 315 |
+
raise ValueError('Unknown sequencer format %r' % formatName)
|
| 316 |
+
|
| 317 |
+
def setup(self, style=None, dot=None, tableStyle=None, headers=True, name=None, format='123', offset=0):
|
| 318 |
+
"""
|
| 319 |
+
This method makes it possible to change styling and other parameters on an existing object.
|
| 320 |
+
|
| 321 |
+
style is the paragraph style to use for index entries.
|
| 322 |
+
dot can either be None or a string. If it's None, entries are immediatly followed by their
|
| 323 |
+
corresponding page numbers. If it's a string, page numbers are aligned on the right side
|
| 324 |
+
of the document and the gap filled with a repeating sequence of the string.
|
| 325 |
+
tableStyle is the style used by the table which the index uses to draw itself. Use this to
|
| 326 |
+
change properties like spacing between elements.
|
| 327 |
+
headers is a boolean. If it is True, alphabetic headers are displayed in the Index when the first
|
| 328 |
+
letter changes. If False, we just output some extra space before the next item
|
| 329 |
+
name makes it possible to use several indexes in one document. If you want this use this
|
| 330 |
+
parameter to give each index a unique name. You can then index a term by refering to the
|
| 331 |
+
name of the index which it should appear in:
|
| 332 |
+
|
| 333 |
+
<index item="term" name="myindex" />
|
| 334 |
+
|
| 335 |
+
format can be 'I', 'i', '123', 'ABC', 'abc'
|
| 336 |
+
"""
|
| 337 |
+
|
| 338 |
+
if style is None:
|
| 339 |
+
style = ParagraphStyle(name='index',
|
| 340 |
+
fontName=_baseFontName,
|
| 341 |
+
fontSize=11)
|
| 342 |
+
self.textStyle = style
|
| 343 |
+
self.tableStyle = tableStyle or defaultTableStyle
|
| 344 |
+
self.dot = dot
|
| 345 |
+
self.headers = headers
|
| 346 |
+
if name is None:
|
| 347 |
+
from reportlab.platypus.paraparser import DEFAULT_INDEX_NAME as name
|
| 348 |
+
self.name = name
|
| 349 |
+
self.formatFunc = self.getFormatFunc(format)
|
| 350 |
+
self.offset = offset
|
| 351 |
+
|
| 352 |
+
def __call__(self,canv,kind,label):
|
| 353 |
+
label = asNative(label,'latin1')
|
| 354 |
+
try:
|
| 355 |
+
terms, format, offset = decode_label(label)
|
| 356 |
+
except:
|
| 357 |
+
terms = label
|
| 358 |
+
format = offset = None
|
| 359 |
+
if format is None:
|
| 360 |
+
formatFunc = self.formatFunc
|
| 361 |
+
else:
|
| 362 |
+
formatFunc = self.getFormatFunc(format)
|
| 363 |
+
if offset is None:
|
| 364 |
+
offset = self.offset
|
| 365 |
+
|
| 366 |
+
terms = commasplit(terms)
|
| 367 |
+
cPN = canv.getPageNumber()
|
| 368 |
+
pns = formatFunc(cPN-offset)
|
| 369 |
+
key = 'ix_%s_%s_p_%s' % (self.name, label, pns)
|
| 370 |
+
|
| 371 |
+
info = canv._curr_tx_info
|
| 372 |
+
canv.bookmarkHorizontal(key, info['cur_x'], info['cur_y'] + info['leading'])
|
| 373 |
+
self.addEntry(terms, (cPN,pns), key)
|
| 374 |
+
|
| 375 |
+
def getCanvasMaker(self, canvasmaker=canvas.Canvas):
|
| 376 |
+
|
| 377 |
+
def newcanvasmaker(*args, **kwargs):
|
| 378 |
+
from reportlab.pdfgen import canvas
|
| 379 |
+
c = canvasmaker(*args, **kwargs)
|
| 380 |
+
c.setNamedCB(self.name,self)
|
| 381 |
+
return c
|
| 382 |
+
|
| 383 |
+
return newcanvasmaker
|
| 384 |
+
|
| 385 |
+
def isIndexing(self):
|
| 386 |
+
return 1
|
| 387 |
+
|
| 388 |
+
def isSatisfied(self):
|
| 389 |
+
return (self._entries == self._lastEntries)
|
| 390 |
+
|
| 391 |
+
def beforeBuild(self):
|
| 392 |
+
# keep track of the last run
|
| 393 |
+
self._lastEntries = self._entries.copy()
|
| 394 |
+
self.clearEntries()
|
| 395 |
+
|
| 396 |
+
def clearEntries(self):
|
| 397 |
+
self._entries = {}
|
| 398 |
+
|
| 399 |
+
def notify(self, kind, stuff):
|
| 400 |
+
"""The notification hook called to register all kinds of events.
|
| 401 |
+
|
| 402 |
+
Here we are interested in self._notifyKind (default IndexEntry) events only.
|
| 403 |
+
"""
|
| 404 |
+
if kind == self._notifyKind:
|
| 405 |
+
text, pageNum = stuff
|
| 406 |
+
self.addEntry(text, (self._canv.getPageNumber(),pageNum))
|
| 407 |
+
|
| 408 |
+
def addEntry(self, text, pageNum, key=None):
|
| 409 |
+
"""Allows incremental buildup"""
|
| 410 |
+
self._entries.setdefault(makeTuple(text),set([])).add((pageNum, key))
|
| 411 |
+
|
| 412 |
+
def split(self, availWidth, availHeight):
|
| 413 |
+
"""At this stage we do not care about splitting the entries,
|
| 414 |
+
we will just return a list of platypus tables. Presumably the
|
| 415 |
+
calling app has a pointer to the original TableOfContents object;
|
| 416 |
+
Platypus just sees tables.
|
| 417 |
+
"""
|
| 418 |
+
return self._flowable.splitOn(self.canv,availWidth, availHeight)
|
| 419 |
+
|
| 420 |
+
def _getlastEntries(self, dummy=[(['Placeholder for index'],enumerate((None,)*3))]):
|
| 421 |
+
'''Return the last run's entries! If there are none, returns dummy.'''
|
| 422 |
+
lE = self._lastEntries or self._entries
|
| 423 |
+
if not lE:
|
| 424 |
+
return dummy
|
| 425 |
+
return list(sorted(lE.items()))
|
| 426 |
+
|
| 427 |
+
def _build(self,availWidth,availHeight):
|
| 428 |
+
_tempEntries = [(tuple(asUnicode(t) for t in texts),pageNumbers)
|
| 429 |
+
for texts, pageNumbers in self._getlastEntries()]
|
| 430 |
+
def getkey(seq):
|
| 431 |
+
return [''.join((c for c in unicodedata.normalize('NFD', x.upper()) if unicodedata.category(c) != 'Mn')) for x in seq[0]]
|
| 432 |
+
_tempEntries.sort(key=getkey)
|
| 433 |
+
leveloffset = self.headers and 1 or 0
|
| 434 |
+
|
| 435 |
+
def drawIndexEntryEnd(canvas, kind, label):
|
| 436 |
+
'''Callback to draw dots and page numbers after each entry.'''
|
| 437 |
+
style = self.getLevelStyle(leveloffset)
|
| 438 |
+
pages = [(p[1],k) for p,k in sorted(decode_label(label))]
|
| 439 |
+
drawPageNumbers(canvas, style, pages, availWidth, availHeight, self.dot)
|
| 440 |
+
self.canv.setNamedCB('drawIndexEntryEnd',drawIndexEntryEnd)
|
| 441 |
+
|
| 442 |
+
alpha = ''
|
| 443 |
+
tableData = []
|
| 444 |
+
lastTexts = []
|
| 445 |
+
alphaStyle = self.getLevelStyle(0)
|
| 446 |
+
for texts, pageNumbers in _tempEntries:
|
| 447 |
+
texts = list(texts)
|
| 448 |
+
#track when the first character changes; either output some extra
|
| 449 |
+
#space, or the first letter on a row of its own. We cannot do
|
| 450 |
+
#widow/orphan control, sadly.
|
| 451 |
+
nalpha = ''.join((c for c in unicodedata.normalize('NFD', texts[0][0].upper()) if unicodedata.category(c) != 'Mn'))
|
| 452 |
+
if alpha != nalpha:
|
| 453 |
+
alpha = nalpha
|
| 454 |
+
if self.headers:
|
| 455 |
+
header = alpha
|
| 456 |
+
else:
|
| 457 |
+
header = ' '
|
| 458 |
+
tableData.append([Spacer(1, alphaStyle.spaceBefore),])
|
| 459 |
+
tableData.append([Paragraph(header, alphaStyle),])
|
| 460 |
+
tableData.append([Spacer(1, alphaStyle.spaceAfter),])
|
| 461 |
+
|
| 462 |
+
|
| 463 |
+
i, diff = listdiff(lastTexts, texts)
|
| 464 |
+
if diff:
|
| 465 |
+
lastTexts = texts
|
| 466 |
+
texts = texts[i:]
|
| 467 |
+
label = encode_label(list(pageNumbers))
|
| 468 |
+
texts[-1] = '%s<onDraw name="drawIndexEntryEnd" label="%s"/>' % (texts[-1], label)
|
| 469 |
+
for text in texts:
|
| 470 |
+
#Platypus and RML differ on how parsed XML attributes are escaped.
|
| 471 |
+
#e.g. <index item="M&S"/>. The only place this seems to bite us is in
|
| 472 |
+
#the index entries so work around it here.
|
| 473 |
+
text = escapeOnce(text)
|
| 474 |
+
|
| 475 |
+
style = self.getLevelStyle(i+leveloffset)
|
| 476 |
+
para = Paragraph(text, style)
|
| 477 |
+
if style.spaceBefore:
|
| 478 |
+
tableData.append([Spacer(1, style.spaceBefore),])
|
| 479 |
+
tableData.append([para,])
|
| 480 |
+
i += 1
|
| 481 |
+
|
| 482 |
+
self._flowable = Table(tableData, colWidths=[availWidth], style=self.tableStyle)
|
| 483 |
+
|
| 484 |
+
def wrap(self, availWidth, availHeight):
|
| 485 |
+
"All table properties should be known by now."
|
| 486 |
+
self._build(availWidth,availHeight)
|
| 487 |
+
self.width, self.height = self._flowable.wrapOn(self.canv,availWidth, availHeight)
|
| 488 |
+
return self.width, self.height
|
| 489 |
+
|
| 490 |
+
def drawOn(self, canvas, x, y, _sW=0):
|
| 491 |
+
"""Don't do this at home! The standard calls for implementing
|
| 492 |
+
draw(); we are hooking this in order to delegate ALL the drawing
|
| 493 |
+
work to the embedded table object.
|
| 494 |
+
"""
|
| 495 |
+
self._flowable.drawOn(canvas, x, y, _sW)
|
| 496 |
+
|
| 497 |
+
def draw(self):
|
| 498 |
+
t = self._flowable
|
| 499 |
+
ocanv = getattr(t,'canv',None)
|
| 500 |
+
if not ocanv:
|
| 501 |
+
t.canv = self.canv
|
| 502 |
+
try:
|
| 503 |
+
t.draw()
|
| 504 |
+
finally:
|
| 505 |
+
if not ocanv:
|
| 506 |
+
del t.canv
|
| 507 |
+
|
| 508 |
+
def getLevelStyle(self, n):
|
| 509 |
+
'''Returns the style for level n, generating and caching styles on demand if not present.'''
|
| 510 |
+
if not hasattr(self.textStyle, '__iter__'):
|
| 511 |
+
self.textStyle = [self.textStyle]
|
| 512 |
+
try:
|
| 513 |
+
return self.textStyle[n]
|
| 514 |
+
except IndexError:
|
| 515 |
+
self.textStyle = list(self.textStyle)
|
| 516 |
+
prevstyle = self.getLevelStyle(n-1)
|
| 517 |
+
self.textStyle.append(ParagraphStyle(
|
| 518 |
+
name='%s-%d-indented' % (prevstyle.name, n),
|
| 519 |
+
parent=prevstyle,
|
| 520 |
+
firstLineIndent = prevstyle.firstLineIndent+.2*cm,
|
| 521 |
+
leftIndent = prevstyle.leftIndent+.2*cm))
|
| 522 |
+
return self.textStyle[n]
|
| 523 |
+
|
| 524 |
+
AlphabeticIndex = SimpleIndex
|
| 525 |
+
|
| 526 |
+
def listdiff(l1, l2):
|
| 527 |
+
m = min(len(l1), len(l2))
|
| 528 |
+
for i in range(m):
|
| 529 |
+
if l1[i] != l2[i]:
|
| 530 |
+
return i, l2[i:]
|
| 531 |
+
return m, l2[m:]
|
| 532 |
+
|
| 533 |
+
class ReferenceText(IndexingFlowable):
|
| 534 |
+
"""Fakery to illustrate how a reference would work if we could
|
| 535 |
+
put it in a paragraph."""
|
| 536 |
+
def __init__(self, textPattern, targetKey):
|
| 537 |
+
self.textPattern = textPattern
|
| 538 |
+
self.target = targetKey
|
| 539 |
+
self.paraStyle = ParagraphStyle('tmp')
|
| 540 |
+
self._lastPageNum = None
|
| 541 |
+
self._pageNum = -999
|
| 542 |
+
self._para = None
|
| 543 |
+
|
| 544 |
+
def beforeBuild(self):
|
| 545 |
+
self._lastPageNum = self._pageNum
|
| 546 |
+
|
| 547 |
+
def notify(self, kind, stuff):
|
| 548 |
+
if kind == 'Target':
|
| 549 |
+
(key, pageNum) = stuff
|
| 550 |
+
if key == self.target:
|
| 551 |
+
self._pageNum = pageNum
|
| 552 |
+
|
| 553 |
+
def wrap(self, availWidth, availHeight):
|
| 554 |
+
text = self.textPattern % self._lastPageNum
|
| 555 |
+
self._para = Paragraph(text, self.paraStyle)
|
| 556 |
+
return self._para.wrap(availWidth, availHeight)
|
| 557 |
+
|
| 558 |
+
def drawOn(self, canvas, x, y, _sW=0):
|
| 559 |
+
self._para.drawOn(canvas, x, y, _sW)
|
.venv/lib/python3.13/site-packages/reportlab/platypus/tables.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
.venv/lib/python3.13/site-packages/reportlab/platypus/xpreformatted.py
ADDED
|
@@ -0,0 +1,345 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#Copyright ReportLab Europe Ltd. 2000-2017
|
| 2 |
+
#see license.txt for license details
|
| 3 |
+
#history https://hg.reportlab.com/hg-public/reportlab/log/tip/src/reportlab/platypus/xpreformatted.py
|
| 4 |
+
__all__ = (
|
| 5 |
+
'XPreformatted',
|
| 6 |
+
'PythonPreformatted',
|
| 7 |
+
)
|
| 8 |
+
__version__='3.5.20'
|
| 9 |
+
__doc__='''A 'rich preformatted text' widget allowing internal markup'''
|
| 10 |
+
from reportlab.lib import PyFontify
|
| 11 |
+
from reportlab.platypus.paragraph import Paragraph, _handleBulletWidth, \
|
| 12 |
+
ParaLines, _getFragWords, stringWidth, getAscentDescent, imgVRange, imgNormV
|
| 13 |
+
from reportlab.lib.utils import isSeq
|
| 14 |
+
from reportlab.platypus.flowables import _dedenter
|
| 15 |
+
|
| 16 |
+
def _getFragLines(frags):
|
| 17 |
+
lines = []
|
| 18 |
+
cline = []
|
| 19 |
+
W = frags[:]
|
| 20 |
+
while W != []:
|
| 21 |
+
w = W[0]
|
| 22 |
+
t = w.text
|
| 23 |
+
del W[0]
|
| 24 |
+
i = t.find('\n')
|
| 25 |
+
if i>=0:
|
| 26 |
+
tleft = t[i+1:]
|
| 27 |
+
cline.append(w.clone(text=t[:i]))
|
| 28 |
+
lines.append(cline)
|
| 29 |
+
cline = []
|
| 30 |
+
if tleft!='':
|
| 31 |
+
W.insert(0,w.clone(text=tleft))
|
| 32 |
+
else:
|
| 33 |
+
cline.append(w)
|
| 34 |
+
if cline!=[]:
|
| 35 |
+
lines.append(cline)
|
| 36 |
+
return lines
|
| 37 |
+
|
| 38 |
+
def _split_blPara(blPara,start,stop):
|
| 39 |
+
f = blPara.clone()
|
| 40 |
+
for a in ('lines', 'text'):
|
| 41 |
+
if hasattr(f,a): delattr(f,a)
|
| 42 |
+
f.lines = blPara.lines[start:stop]
|
| 43 |
+
return [f]
|
| 44 |
+
|
| 45 |
+
# Will be removed shortly.
|
| 46 |
+
def _countSpaces(text):
|
| 47 |
+
return text.count(' ')
|
| 48 |
+
## i = 0
|
| 49 |
+
## s = 0
|
| 50 |
+
## while 1:
|
| 51 |
+
## j = text.find(' ',i)
|
| 52 |
+
## if j<0: return s
|
| 53 |
+
## s = s + 1
|
| 54 |
+
## i = j + 1
|
| 55 |
+
|
| 56 |
+
def _getFragWord(frags,maxWidth):
|
| 57 |
+
''' given a fragment list return a list of lists
|
| 58 |
+
[size, spaces, (f00,w00), ..., (f0n,w0n)]
|
| 59 |
+
each pair f,w represents a style and some string
|
| 60 |
+
'''
|
| 61 |
+
W = []
|
| 62 |
+
n = 0
|
| 63 |
+
s = 0
|
| 64 |
+
for f in frags:
|
| 65 |
+
text = f.text[:]
|
| 66 |
+
W.append((f,text))
|
| 67 |
+
cb = getattr(f,'cbDefn',None)
|
| 68 |
+
if cb:
|
| 69 |
+
_w = getattr(cb,'width',0)
|
| 70 |
+
if hasattr(_w,'normalizedValue'):
|
| 71 |
+
_w._normalizer = maxWidth
|
| 72 |
+
n += stringWidth(text, f.fontName, f.fontSize)
|
| 73 |
+
|
| 74 |
+
#s = s + _countSpaces(text)
|
| 75 |
+
s += text.count(' ') # much faster for many blanks
|
| 76 |
+
|
| 77 |
+
#del f.text # we can't do this until we sort out splitting
|
| 78 |
+
# of paragraphs
|
| 79 |
+
return n, s, W
|
| 80 |
+
|
| 81 |
+
class XPreformatted(Paragraph):
|
| 82 |
+
def __init__(self, text, style, bulletText = None, frags=None, caseSensitive=1, dedent=0):
|
| 83 |
+
self.caseSensitive = caseSensitive
|
| 84 |
+
cleaner = lambda text, dedent=dedent: '\n'.join(_dedenter(text or '',dedent))
|
| 85 |
+
self._setup(text, style, bulletText, frags, cleaner)
|
| 86 |
+
|
| 87 |
+
def breakLines(self, width):
|
| 88 |
+
"""
|
| 89 |
+
Returns a broken line structure. There are two cases
|
| 90 |
+
|
| 91 |
+
A) For the simple case of a single formatting input fragment the output is
|
| 92 |
+
A fragment specifier with
|
| 93 |
+
- kind = 0
|
| 94 |
+
- fontName, fontSize, leading, textColor
|
| 95 |
+
- lines= A list of lines
|
| 96 |
+
|
| 97 |
+
Each line has two items:
|
| 98 |
+
|
| 99 |
+
1. unused width in points
|
| 100 |
+
2. a list of words
|
| 101 |
+
|
| 102 |
+
B) When there is more than one input formatting fragment the out put is
|
| 103 |
+
A fragment specifier with
|
| 104 |
+
- kind = 1
|
| 105 |
+
- lines = A list of fragments each having fields:
|
| 106 |
+
|
| 107 |
+
- extraspace (needed for justified)
|
| 108 |
+
- fontSize
|
| 109 |
+
- words=word list
|
| 110 |
+
- each word is itself a fragment with
|
| 111 |
+
- various settings
|
| 112 |
+
|
| 113 |
+
This structure can be used to easily draw paragraphs with the various alignments.
|
| 114 |
+
You can supply either a single width or a list of widths; the latter will have its
|
| 115 |
+
last item repeated until necessary. A 2-element list is useful when there is a
|
| 116 |
+
different first line indent; a longer list could be created to facilitate custom wraps
|
| 117 |
+
around irregular objects."""
|
| 118 |
+
|
| 119 |
+
self._width_max = 0
|
| 120 |
+
if not isSeq(width): maxWidths = [width]
|
| 121 |
+
else: maxWidths = width
|
| 122 |
+
lines = []
|
| 123 |
+
lineno = 0
|
| 124 |
+
maxWidth = maxWidths[lineno]
|
| 125 |
+
style = self.style
|
| 126 |
+
fFontSize = float(style.fontSize)
|
| 127 |
+
requiredWidth = 0
|
| 128 |
+
|
| 129 |
+
#for bullets, work out width and ensure we wrap the right amount onto line one
|
| 130 |
+
_handleBulletWidth(self.bulletText,style,maxWidths)
|
| 131 |
+
|
| 132 |
+
self.height = 0
|
| 133 |
+
autoLeading = getattr(self,'autoLeading',getattr(style,'autoLeading',''))
|
| 134 |
+
calcBounds = autoLeading not in ('','off')
|
| 135 |
+
frags = self.frags
|
| 136 |
+
nFrags= len(frags)
|
| 137 |
+
if nFrags==1:
|
| 138 |
+
f = frags[0]
|
| 139 |
+
if hasattr(f,'text'):
|
| 140 |
+
fontSize = f.fontSize
|
| 141 |
+
fontName = f.fontName
|
| 142 |
+
ascent, descent = getAscentDescent(fontName,fontSize)
|
| 143 |
+
kind = 0
|
| 144 |
+
L=f.text.split('\n')
|
| 145 |
+
for l in L:
|
| 146 |
+
currentWidth = stringWidth(l,fontName,fontSize)
|
| 147 |
+
if currentWidth > self._width_max: self._width_max = currentWidth
|
| 148 |
+
requiredWidth = max(currentWidth,requiredWidth)
|
| 149 |
+
extraSpace = maxWidth-currentWidth
|
| 150 |
+
lines.append((extraSpace,l.split(' '),currentWidth))
|
| 151 |
+
lineno = lineno+1
|
| 152 |
+
maxWidth = lineno<len(maxWidths) and maxWidths[lineno] or maxWidths[-1]
|
| 153 |
+
blPara = f.clone(kind=kind, lines=lines,ascent=ascent,descent=descent,fontSize=fontSize)
|
| 154 |
+
else:
|
| 155 |
+
kind = f.kind
|
| 156 |
+
lines = f.lines
|
| 157 |
+
for L in lines:
|
| 158 |
+
if kind==0:
|
| 159 |
+
currentWidth = L[2]
|
| 160 |
+
else:
|
| 161 |
+
currentWidth = L.currentWidth
|
| 162 |
+
requiredWidth = max(currentWidth,requiredWidth)
|
| 163 |
+
blPara = f.clone(kind=kind, lines=lines)
|
| 164 |
+
|
| 165 |
+
self.width = max(self.width,requiredWidth)
|
| 166 |
+
return blPara
|
| 167 |
+
elif nFrags<=0:
|
| 168 |
+
return ParaLines(kind=0, fontSize=style.fontSize, fontName=style.fontName,
|
| 169 |
+
textColor=style.textColor, ascent=style.fontSize,descent=-0.2*style.fontSize,
|
| 170 |
+
lines=[])
|
| 171 |
+
else:
|
| 172 |
+
for L in _getFragLines(frags):
|
| 173 |
+
currentWidth, n, w = _getFragWord(L,maxWidth)
|
| 174 |
+
f = w[0][0]
|
| 175 |
+
maxSize = f.fontSize
|
| 176 |
+
maxAscent, minDescent = getAscentDescent(f.fontName,maxSize)
|
| 177 |
+
words = [f.clone()]
|
| 178 |
+
words[-1].text = w[0][1]
|
| 179 |
+
for i in w[1:]:
|
| 180 |
+
f = i[0].clone()
|
| 181 |
+
f.text=i[1]
|
| 182 |
+
words.append(f)
|
| 183 |
+
fontSize = f.fontSize
|
| 184 |
+
fontName = f.fontName
|
| 185 |
+
if calcBounds:
|
| 186 |
+
cbDefn = getattr(f,'cbDefn',None)
|
| 187 |
+
if getattr(cbDefn,'width',0):
|
| 188 |
+
descent,ascent = imgVRange(imgNormV(cbDefn.height,fontSize),cbDefn.valign,fontSize)
|
| 189 |
+
else:
|
| 190 |
+
ascent, descent = getAscentDescent(fontName,fontSize)
|
| 191 |
+
else:
|
| 192 |
+
ascent, descent = getAscentDescent(fontName,fontSize)
|
| 193 |
+
maxSize = max(maxSize,fontSize)
|
| 194 |
+
maxAscent = max(maxAscent,ascent)
|
| 195 |
+
minDescent = min(minDescent,descent)
|
| 196 |
+
|
| 197 |
+
lineno += 1
|
| 198 |
+
maxWidth = lineno<len(maxWidths) and maxWidths[lineno] or maxWidths[-1]
|
| 199 |
+
requiredWidth = max(currentWidth,requiredWidth)
|
| 200 |
+
extraSpace = maxWidth - currentWidth
|
| 201 |
+
if currentWidth > self._width_max: self._width_max = currentWidth
|
| 202 |
+
lines.append(ParaLines(extraSpace=extraSpace,wordCount=n, words=words, fontSize=maxSize, ascent=maxAscent,descent=minDescent,currentWidth=currentWidth,preformatted=True))
|
| 203 |
+
|
| 204 |
+
self.width = max(self.width,requiredWidth)
|
| 205 |
+
return ParaLines(kind=1, lines=lines)
|
| 206 |
+
|
| 207 |
+
return lines
|
| 208 |
+
|
| 209 |
+
breakLinesCJK = breakLines #TODO fixme fixme fixme
|
| 210 |
+
|
| 211 |
+
# we need this her to get the right splitter
|
| 212 |
+
def _get_split_blParaFunc(self):
|
| 213 |
+
return _split_blPara
|
| 214 |
+
|
| 215 |
+
class PythonPreformatted(XPreformatted):
|
| 216 |
+
"""Used for syntax-colored Python code, otherwise like XPreformatted.
|
| 217 |
+
"""
|
| 218 |
+
formats = {
|
| 219 |
+
'rest' : ('', ''),
|
| 220 |
+
'comment' : ('<font color="green">', '</font>'),
|
| 221 |
+
'keyword' : ('<font color="blue"><b>', '</b></font>'),
|
| 222 |
+
'parameter' : ('<font color="black">', '</font>'),
|
| 223 |
+
'identifier' : ('<font color="red">', '</font>'),
|
| 224 |
+
'string' : ('<font color="gray">', '</font>') }
|
| 225 |
+
|
| 226 |
+
def __init__(self, text, style, bulletText = None, dedent=0, frags=None):
|
| 227 |
+
if text:
|
| 228 |
+
text = self.fontify(self.escapeHtml(text))
|
| 229 |
+
XPreformatted.__init__(self, text, style,bulletText=bulletText,dedent=dedent,frags=frags)
|
| 230 |
+
|
| 231 |
+
def escapeHtml(self, text):
|
| 232 |
+
s = text.replace('&', '&')
|
| 233 |
+
s = s.replace('<', '<')
|
| 234 |
+
s = s.replace('>', '>')
|
| 235 |
+
return s
|
| 236 |
+
|
| 237 |
+
def fontify(self, code):
|
| 238 |
+
"Return a fontified version of some Python code."
|
| 239 |
+
|
| 240 |
+
if code[0] == '\n':
|
| 241 |
+
code = code[1:]
|
| 242 |
+
|
| 243 |
+
tags = PyFontify.fontify(code)
|
| 244 |
+
fontifiedCode = ''
|
| 245 |
+
pos = 0
|
| 246 |
+
for k, i, j, dummy in tags:
|
| 247 |
+
fontifiedCode = fontifiedCode + code[pos:i]
|
| 248 |
+
s, e = self.formats[k]
|
| 249 |
+
fontifiedCode = fontifiedCode + s + code[i:j] + e
|
| 250 |
+
pos = j
|
| 251 |
+
|
| 252 |
+
fontifiedCode = fontifiedCode + code[pos:]
|
| 253 |
+
|
| 254 |
+
return fontifiedCode
|
| 255 |
+
|
| 256 |
+
if __name__=='__main__': #NORUNTESTS
|
| 257 |
+
import sys
|
| 258 |
+
def dumpXPreformattedLines(P):
|
| 259 |
+
print('\n############dumpXPreforemattedLines(%s)' % str(P))
|
| 260 |
+
lines = P.blPara.lines
|
| 261 |
+
n =len(lines)
|
| 262 |
+
outw=sys.stdout.write
|
| 263 |
+
for l in range(n):
|
| 264 |
+
line = lines[l]
|
| 265 |
+
words = line.words
|
| 266 |
+
nwords = len(words)
|
| 267 |
+
outw('line%d: %d(%d)\n ' % (l,nwords,line.wordCount))
|
| 268 |
+
for w in range(nwords):
|
| 269 |
+
outw(" %d:'%s'"%(w,words[w].text))
|
| 270 |
+
print()
|
| 271 |
+
|
| 272 |
+
def dumpXPreformattedFrags(P):
|
| 273 |
+
print('\n############dumpXPreforemattedFrags(%s)' % str(P))
|
| 274 |
+
frags = P.frags
|
| 275 |
+
n =len(frags)
|
| 276 |
+
for l in range(n):
|
| 277 |
+
print("frag%d: '%s'" % (l, frags[l].text))
|
| 278 |
+
|
| 279 |
+
outw=sys.stdout.write
|
| 280 |
+
l = 0
|
| 281 |
+
for L in _getFragLines(frags):
|
| 282 |
+
n=0
|
| 283 |
+
for W in _getFragWords(L,360):
|
| 284 |
+
outw("frag%d.%d: size=%d" % (l, n, W[0]))
|
| 285 |
+
n = n + 1
|
| 286 |
+
for w in W[1:]:
|
| 287 |
+
outw(" '%s'" % w[1])
|
| 288 |
+
print()
|
| 289 |
+
l = l + 1
|
| 290 |
+
|
| 291 |
+
def try_it(text,style,dedent,aW,aH):
|
| 292 |
+
P=XPreformatted(text,style,dedent=dedent)
|
| 293 |
+
dumpXPreformattedFrags(P)
|
| 294 |
+
w,h = P.wrap(aW, aH)
|
| 295 |
+
dumpXPreformattedLines(P)
|
| 296 |
+
S = P.split(aW,aH)
|
| 297 |
+
dumpXPreformattedLines(P)
|
| 298 |
+
for s in S:
|
| 299 |
+
s.wrap(aW,aH)
|
| 300 |
+
dumpXPreformattedLines(s)
|
| 301 |
+
aH = 500
|
| 302 |
+
|
| 303 |
+
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
|
| 304 |
+
styleSheet = getSampleStyleSheet()
|
| 305 |
+
B = styleSheet['BodyText']
|
| 306 |
+
DTstyle = ParagraphStyle("discussiontext", parent=B)
|
| 307 |
+
DTstyle.fontName= 'Helvetica'
|
| 308 |
+
for (text,dedent,style, aW, aH, active) in [('''
|
| 309 |
+
|
| 310 |
+
|
| 311 |
+
The <font name=courier color=green>CMYK</font> or subtractive
|
| 312 |
+
|
| 313 |
+
method follows the way a printer
|
| 314 |
+
mixes three pigments (cyan, magenta, and yellow) to form colors.
|
| 315 |
+
Because mixing chemicals is more difficult than combining light there
|
| 316 |
+
is a fourth parameter for darkness. For example a chemical
|
| 317 |
+
combination of the <font name=courier color=green>CMY</font> pigments generally never makes a perfect
|
| 318 |
+
|
| 319 |
+
black -- instead producing a muddy color -- so, to get black printers
|
| 320 |
+
don't use the <font name=courier color=green>CMY</font> pigments but use a direct black ink. Because
|
| 321 |
+
<font name=courier color=green>CMYK</font> maps more directly to the way printer hardware works it may
|
| 322 |
+
be the case that &| & | colors specified in <font name=courier color=green>CMYK</font> will provide better fidelity
|
| 323 |
+
and better control when printed.
|
| 324 |
+
|
| 325 |
+
|
| 326 |
+
''',0,DTstyle, 456.0, 42.8, 0),
|
| 327 |
+
('''
|
| 328 |
+
|
| 329 |
+
This is a non rearranging form of the <b>Paragraph</b> class;
|
| 330 |
+
<b><font color=red>XML</font></b> tags are allowed in <i>text</i> and have the same
|
| 331 |
+
|
| 332 |
+
meanings as for the <b>Paragraph</b> class.
|
| 333 |
+
As for <b>Preformatted</b>, if dedent is non zero <font color=red size=+1>dedent</font>
|
| 334 |
+
common leading spaces will be removed from the
|
| 335 |
+
front of each line.
|
| 336 |
+
|
| 337 |
+
''',3, DTstyle, 456.0, 42.8, 0),
|
| 338 |
+
("""\
|
| 339 |
+
<font color=blue>class </font><font color=red>FastXMLParser</font>:
|
| 340 |
+
# Nonsense method
|
| 341 |
+
def nonsense(self):
|
| 342 |
+
self.foo = 'bar'
|
| 343 |
+
""",0, styleSheet['Code'], 456.0, 4.8, 1),
|
| 344 |
+
]:
|
| 345 |
+
if active: try_it(text,style,dedent,aW,aH)
|
.venv/lib/python3.13/site-packages/reportlab/rl_config.py
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''module that aggregates config information'''
|
| 2 |
+
__all__=('_reset','register_reset')
|
| 3 |
+
|
| 4 |
+
def _defaults_init():
|
| 5 |
+
'''
|
| 6 |
+
create & return defaults for all reportlab settings from
|
| 7 |
+
reportlab.rl_settings.py
|
| 8 |
+
reportlab.local_rl_settings.py
|
| 9 |
+
reportlab_settings.py or ~/.reportlab_settings
|
| 10 |
+
|
| 11 |
+
latter values override earlier
|
| 12 |
+
'''
|
| 13 |
+
from reportlab.lib.utils import rl_exec
|
| 14 |
+
import os
|
| 15 |
+
|
| 16 |
+
_DEFAULTS={}
|
| 17 |
+
rl_exec('from reportlab.rl_settings import *',_DEFAULTS)
|
| 18 |
+
|
| 19 |
+
_overrides=_DEFAULTS.copy()
|
| 20 |
+
try:
|
| 21 |
+
rl_exec('from reportlab.local_rl_settings import *',_overrides)
|
| 22 |
+
_DEFAULTS.update(_overrides)
|
| 23 |
+
except ImportError:
|
| 24 |
+
pass
|
| 25 |
+
|
| 26 |
+
_overrides=_DEFAULTS.copy()
|
| 27 |
+
try:
|
| 28 |
+
rl_exec('from reportlab_settings import *',_overrides)
|
| 29 |
+
_DEFAULTS.update(_overrides)
|
| 30 |
+
except ImportError:
|
| 31 |
+
_overrides=_DEFAULTS.copy()
|
| 32 |
+
try:
|
| 33 |
+
try:
|
| 34 |
+
fn = os.path.expanduser(os.path.join('~','.reportlab_settings')) #appengine fails with KeyError/ImportError (dev/live)
|
| 35 |
+
except (KeyError, ImportError):
|
| 36 |
+
fn = None
|
| 37 |
+
if fn:
|
| 38 |
+
with open(fn,'rb') as f:
|
| 39 |
+
rl_exec(f.read(),_overrides)
|
| 40 |
+
_DEFAULTS.update(_overrides)
|
| 41 |
+
except:
|
| 42 |
+
pass
|
| 43 |
+
return _DEFAULTS
|
| 44 |
+
|
| 45 |
+
_DEFAULTS=_defaults_init()
|
| 46 |
+
|
| 47 |
+
_SAVED = {}
|
| 48 |
+
sys_version=None
|
| 49 |
+
|
| 50 |
+
def _enumChk(name,value,allowed=()):
|
| 51 |
+
if value not in allowed:
|
| 52 |
+
raise ValueError(f'invalid value {value!r} for rl_config.{name}\nneed one of {allowed}')
|
| 53 |
+
|
| 54 |
+
from functools import partial
|
| 55 |
+
_rlChecks=dict(
|
| 56 |
+
renderPMBackend = partial(_enumChk,allowed=('rlPyCairo',)),
|
| 57 |
+
xmlParser = partial(_enumChk,allowed=('lxml',)),
|
| 58 |
+
textPaths = partial(_enumChk,allowed=('freetype','backend')),
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
#this is used to set the options from
|
| 62 |
+
def _setOpt(name, value, conv=None, chk=None):
|
| 63 |
+
'''set a module level value from environ/default'''
|
| 64 |
+
from os import environ
|
| 65 |
+
ename = 'RL_'+name
|
| 66 |
+
if ename in environ:
|
| 67 |
+
value = environ[ename]
|
| 68 |
+
if conv: value = conv(value)
|
| 69 |
+
chk = _rlChecks.get(name,None)
|
| 70 |
+
if chk: chk(name,value)
|
| 71 |
+
globals()[name] = value
|
| 72 |
+
|
| 73 |
+
def _startUp():
|
| 74 |
+
'''This function allows easy resetting to the global defaults
|
| 75 |
+
If the environment contains 'RL_xxx' then we use the value
|
| 76 |
+
else we use the given default'''
|
| 77 |
+
import os, sys
|
| 78 |
+
global sys_version, _unset_
|
| 79 |
+
sys_version = sys.version.split()[0] #strip off the other garbage
|
| 80 |
+
from reportlab.lib import pagesizes
|
| 81 |
+
from reportlab.lib.utils import rl_isdir
|
| 82 |
+
|
| 83 |
+
if _SAVED=={}:
|
| 84 |
+
_unset_ = getattr(sys,'_rl_config__unset_',None)
|
| 85 |
+
if _unset_ is None:
|
| 86 |
+
class _unset_: pass
|
| 87 |
+
sys._rl_config__unset_ = _unset_ = _unset_()
|
| 88 |
+
global __all__
|
| 89 |
+
A = list(__all__)
|
| 90 |
+
for k,v in _DEFAULTS.items():
|
| 91 |
+
_SAVED[k] = globals()[k] = v
|
| 92 |
+
if k not in __all__:
|
| 93 |
+
A.append(k)
|
| 94 |
+
__all__ = tuple(A)
|
| 95 |
+
|
| 96 |
+
#places to search for Type 1 Font files
|
| 97 |
+
import reportlab
|
| 98 |
+
D = {'REPORTLAB_DIR': os.path.abspath(os.path.dirname(reportlab.__file__)),
|
| 99 |
+
'CWD': os.getcwd(),
|
| 100 |
+
'disk': os.getcwd().split(':')[0],
|
| 101 |
+
'sys_version': sys_version,
|
| 102 |
+
'XDG_DATA_HOME': os.environ.get('XDG_DATA_HOME','~/.local/share'),
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
for k in _SAVED:
|
| 106 |
+
if k.endswith('SearchPath'):
|
| 107 |
+
P=[]
|
| 108 |
+
for p in _SAVED[k]:
|
| 109 |
+
d = (p % D).replace('/',os.sep)
|
| 110 |
+
if '~' in d:
|
| 111 |
+
try:
|
| 112 |
+
d = os.path.expanduser(d) #appengine fails with KeyError/ImportError (dev/live)
|
| 113 |
+
except (KeyError, ImportError):
|
| 114 |
+
continue
|
| 115 |
+
if rl_isdir(d): P.append(d)
|
| 116 |
+
_setOpt(k,os.pathsep.join(P),lambda x:x.split(os.pathsep))
|
| 117 |
+
globals()[k] = list(filter(rl_isdir,globals()[k]))
|
| 118 |
+
else:
|
| 119 |
+
v = _SAVED[k]
|
| 120 |
+
if isinstance(v,(int,float)):
|
| 121 |
+
conv = type(v)
|
| 122 |
+
elif k=='defaultPageSize':
|
| 123 |
+
conv = lambda v,M=pagesizes: getattr(M,v)
|
| 124 |
+
elif k in ('trustedHosts','trustedSchemes'):
|
| 125 |
+
conv = lambda v: None if v is None else [y for y in [x.strip() for x in v.split(',')] if y] if isinstance(v,str) else v
|
| 126 |
+
elif k.endswith('Glob'):
|
| 127 |
+
conv = lambda v: list(filter(None,(_.strip() for _ in v.split()))) if v else []
|
| 128 |
+
else: conv = None
|
| 129 |
+
_setOpt(k,v,conv)
|
| 130 |
+
|
| 131 |
+
_registered_resets=[]
|
| 132 |
+
def register_reset(func, callback=None):
|
| 133 |
+
'''register a function to be called by rl_config._reset'''
|
| 134 |
+
_registered_resets[:] = [x for x in _registered_resets if x()]
|
| 135 |
+
L = [x for x in _registered_resets if x() is func]
|
| 136 |
+
if L: return
|
| 137 |
+
from weakref import ref, WeakMethod
|
| 138 |
+
_registered_resets.append((WeakMethod if hasattr(func,'__self__') else ref)(func,callback))
|
| 139 |
+
|
| 140 |
+
def _reset():
|
| 141 |
+
'''attempt to reset reportlab and friends'''
|
| 142 |
+
_startUp() #our reset
|
| 143 |
+
for f in _registered_resets[:]:
|
| 144 |
+
c = f()
|
| 145 |
+
if c:
|
| 146 |
+
c()
|
| 147 |
+
else:
|
| 148 |
+
_registered_resets.remove(f)
|
| 149 |
+
|
| 150 |
+
_startUp()
|
.venv/lib/python3.13/site-packages/reportlab/rl_settings.py
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#Copyright ReportLab Europe Ltd. 2000-2017
|
| 2 |
+
#see license.txt for license details
|
| 3 |
+
'''default settings for reportlab
|
| 4 |
+
|
| 5 |
+
to override these drop a module local_rl_settings.py parallel to this file or
|
| 6 |
+
anywhere on the path.
|
| 7 |
+
'''
|
| 8 |
+
import os, sys
|
| 9 |
+
__version__='3.3.0'
|
| 10 |
+
__all__=tuple('''allowTableBoundsErrors
|
| 11 |
+
shapeChecking
|
| 12 |
+
defaultEncoding
|
| 13 |
+
defaultGraphicsFontName
|
| 14 |
+
pageCompression
|
| 15 |
+
useA85
|
| 16 |
+
defaultPageSize
|
| 17 |
+
defaultImageCaching
|
| 18 |
+
warnOnMissingFontGlyphs
|
| 19 |
+
verbose
|
| 20 |
+
showBoundary
|
| 21 |
+
emptyTableAction
|
| 22 |
+
invariant
|
| 23 |
+
eps_preview_transparent
|
| 24 |
+
eps_preview
|
| 25 |
+
eps_ttf_embed
|
| 26 |
+
eps_ttf_embed_uid
|
| 27 |
+
overlapAttachedSpace
|
| 28 |
+
longTableOptimize
|
| 29 |
+
autoConvertEncoding
|
| 30 |
+
_FUZZ
|
| 31 |
+
wrapA85
|
| 32 |
+
fsEncodings
|
| 33 |
+
odbc_driver
|
| 34 |
+
platypus_link_underline
|
| 35 |
+
canvas_basefontname
|
| 36 |
+
allowShortTableRows
|
| 37 |
+
imageReaderFlags
|
| 38 |
+
paraFontSizeHeightOffset
|
| 39 |
+
canvas_baseColor
|
| 40 |
+
ignoreContainerActions
|
| 41 |
+
ttfAsciiReadable
|
| 42 |
+
pdfMultiLine
|
| 43 |
+
pdfComments
|
| 44 |
+
debug
|
| 45 |
+
listWrapOnFakeWidth
|
| 46 |
+
T1SearchPath
|
| 47 |
+
TTFSearchPath
|
| 48 |
+
CMapSearchPath
|
| 49 |
+
decimalSymbol
|
| 50 |
+
errorOnDuplicatePageLabelPage
|
| 51 |
+
autoGenerateMissingTTFName
|
| 52 |
+
allowTTFSubsetting
|
| 53 |
+
spaceShrinkage
|
| 54 |
+
underlineWidth
|
| 55 |
+
underlineOffset
|
| 56 |
+
underlineGap
|
| 57 |
+
strikeWidth
|
| 58 |
+
strikeOffset
|
| 59 |
+
strikeGap
|
| 60 |
+
hyphenationLang
|
| 61 |
+
uriWasteReduce
|
| 62 |
+
embeddedHyphenation
|
| 63 |
+
hyphenationMinWordLength
|
| 64 |
+
reserveTTFNotdef
|
| 65 |
+
documentLang
|
| 66 |
+
encryptionStrength
|
| 67 |
+
trustedHosts
|
| 68 |
+
trustedSchemes
|
| 69 |
+
renderPMBackend
|
| 70 |
+
xmlParser
|
| 71 |
+
textPaths
|
| 72 |
+
toColorCanUse
|
| 73 |
+
defCWRF
|
| 74 |
+
unShapedFontGlob'''.split())
|
| 75 |
+
|
| 76 |
+
allowTableBoundsErrors = 1 # bit 0 --> ignore overall width excession
|
| 77 |
+
# bit 1 --> ignore negative available width
|
| 78 |
+
# bit 2 --> turn bit 0 to a warning
|
| 79 |
+
# bit 3 --> turn bit 1 into a warning
|
| 80 |
+
# (recommend 1 for production use)
|
| 81 |
+
shapeChecking = 1
|
| 82 |
+
defaultEncoding = 'WinAnsiEncoding' # 'WinAnsi' or 'MacRoman'
|
| 83 |
+
defaultGraphicsFontName= 'Times-Roman' #initializer for STATE_DEFAULTS in shapes.py
|
| 84 |
+
pageCompression = 1 # default page compression mode
|
| 85 |
+
useA85 = 1 #set to 0 to disable Ascii Base 85 stream filters
|
| 86 |
+
defaultPageSize = 'A4' #default page size
|
| 87 |
+
defaultImageCaching = 0 #set to zero to remove those annoying cached images
|
| 88 |
+
warnOnMissingFontGlyphs = 0 #if 1, warns of each missing glyph
|
| 89 |
+
verbose = 0
|
| 90 |
+
showBoundary = 0 # turns on and off boundary behaviour in Drawing
|
| 91 |
+
emptyTableAction= 'error' # one of 'error', 'indicate', 'ignore'
|
| 92 |
+
invariant= 0 #produces repeatable,identical PDFs with same timestamp info (for regression testing)
|
| 93 |
+
eps_preview_transparent= None #set to white etc
|
| 94 |
+
eps_preview= 1 #set to False to disable
|
| 95 |
+
eps_ttf_embed= 1 #set to False to disable
|
| 96 |
+
eps_ttf_embed_uid= 0 #set to 1 to enable
|
| 97 |
+
overlapAttachedSpace= 1 #if set non false then adajacent flowable space after
|
| 98 |
+
#and space before are merged (max space is used).
|
| 99 |
+
longTableOptimize = 1 #default do use Henning von Bargen's long table optimizations
|
| 100 |
+
autoConvertEncoding = 0 #convert internally as needed (experimental)
|
| 101 |
+
_FUZZ= 1e-6 #fuzz for layout arithmetic
|
| 102 |
+
wrapA85= 0 #set to 1 to get old wrapped line behaviour
|
| 103 |
+
fsEncodings=('utf8','cp1252','cp430') #encodings to attempt utf8 conversion with
|
| 104 |
+
odbc_driver= 'odbc' #default odbc driver
|
| 105 |
+
platypus_link_underline= 0 #paragraph links etc underlined if true
|
| 106 |
+
canvas_basefontname= 'Helvetica' #this is used to initialize the canvas; if you override to make
|
| 107 |
+
#something else you are responsible for ensuring the font is registered etc etc
|
| 108 |
+
#this will be used everywhere and the font family connections will be made
|
| 109 |
+
#if the bold/italic/bold italic fonts are also registered and defined as a family.
|
| 110 |
+
|
| 111 |
+
allowShortTableRows=1 #allows some rows in a table to be short
|
| 112 |
+
imageReaderFlags=0 #no longer in use
|
| 113 |
+
paraFontSizeHeightOffset= 1 #if true paragraphs start at height-fontSize
|
| 114 |
+
canvas_baseColor= None #initialize the canvas fill and stroke colors if this is set
|
| 115 |
+
ignoreContainerActions= 1 #if true then action flowables in flowable _Containers will be ignored
|
| 116 |
+
ttfAsciiReadable= 1 #smaller subsets when set to 0
|
| 117 |
+
pdfMultiLine= 0 #use more lines in pdf etc
|
| 118 |
+
pdfComments= 0 #put in pdf comments
|
| 119 |
+
debug= 0 #for debugging code
|
| 120 |
+
listWrapOnFakeWidth= 1 #set to 0/False to force platypus.flowables._listWrapOn to report correct widths
|
| 121 |
+
#else it reports minimum(required,available) width
|
| 122 |
+
|
| 123 |
+
underlineWidth= '' #empty to use canvas strokeWidth or a distance or number*<letter>
|
| 124 |
+
# num * <letter> make value proportional to a font size
|
| 125 |
+
# P paragraph font size
|
| 126 |
+
# L line max font size
|
| 127 |
+
# f first use font size
|
| 128 |
+
# F max fontsize in the tag
|
| 129 |
+
|
| 130 |
+
underlineOffset= '-0.125*F' #fraction of fontSize from baseline to draw underlines at.
|
| 131 |
+
underlineGap= '1' #gap for double/triple underline
|
| 132 |
+
|
| 133 |
+
strikeWidth= ''
|
| 134 |
+
strikeOffset= '0.25*F' #fraction of fontSize from baseline to draw strike through at.
|
| 135 |
+
strikeGap= '1' #gap for double/triple strike
|
| 136 |
+
|
| 137 |
+
#by default typical value 0.05. may be overridden on a parastyle.
|
| 138 |
+
decimalSymbol= '.' #what we use to align floats numerically
|
| 139 |
+
errorOnDuplicatePageLabelPage= 0 #if True will cause repeated PageLabel page numbers to raise an error.
|
| 140 |
+
autoGenerateMissingTTFName=0 #if true we try to auto generate any missing TTF font name
|
| 141 |
+
|
| 142 |
+
allowTTFSubsetting= [] #list of font file names that will be subsetted even when they
|
| 143 |
+
#have the no subsetting flag set. These should be fonts for which
|
| 144 |
+
#the user has explicit permission from the rights holder(s).
|
| 145 |
+
#This flag could already be overcome by hacking the code.
|
| 146 |
+
#ReportLab takes no responsibility for the use of this setting.
|
| 147 |
+
|
| 148 |
+
spaceShrinkage=0.05 #allowable space shrinkage to make lines fit
|
| 149 |
+
hyphenationLang='' #if pyphen installed set this to the language of your choice
|
| 150 |
+
#eg 'en_GB'
|
| 151 |
+
|
| 152 |
+
uriWasteReduce=0 #split URI if we would waste 0.3 of a line or if the URI#
|
| 153 |
+
#would not fit on the next line; if zero then no splitting
|
| 154 |
+
#is attempted. suggested value = 0.3
|
| 155 |
+
embeddedHyphenation=0 #if true attempt hypenation of words with embedded hyphens
|
| 156 |
+
hyphenationMinWordLength=5 #minimum length of words that can be hyphenated
|
| 157 |
+
reserveTTFNotdef=1 #if true force subset element 0 to be zero(.notdef)
|
| 158 |
+
#helps to fix bug in edge; this is now ignored in code
|
| 159 |
+
#PDFUA forbids index 0(.notdef) in strings
|
| 160 |
+
documentLang=None #pdf document catalog Lang value xx-xx not ee_xx
|
| 161 |
+
encryptionStrength=40 #the bits for standard encryption 40, 128 or 256 (AES)
|
| 162 |
+
trustedHosts=None #set to a list of trusted for access hosts
|
| 163 |
+
#glob patterns eg *.reportlab.com are
|
| 164 |
+
#allowed. In environment use a comma separated string.
|
| 165 |
+
#to use data: or file: schemes trustedHosts must contain localhost
|
| 166 |
+
#None or other false value means no hosts are trusted
|
| 167 |
+
trustedSchemes=['file', 'rml', 'data', 'https', #these url schemes are trusted
|
| 168 |
+
'http', 'ftp']
|
| 169 |
+
renderPMBackend='rlPyCairo' #rl_renderPM is gone
|
| 170 |
+
xmlParser='lxml' #pyRXP is gone
|
| 171 |
+
textPaths='freetype' #freetype or backend, rl_renderPM is gone
|
| 172 |
+
#determines what code is used to create Paths from str
|
| 173 |
+
#see reportlab/graphics/utils.py for full horror
|
| 174 |
+
toColorCanUse='rl_extended_literal_eval' #change to None or 'rl_safe_eval' depending on trust
|
| 175 |
+
defCWRF=0.02 #fraction we can reduce defined column widths for overcommitted
|
| 176 |
+
#undefined widths
|
| 177 |
+
unShapedFontGlob=None #None or space list of glob patterns that force off shaping
|
| 178 |
+
|
| 179 |
+
# places to look for T1Font information
|
| 180 |
+
T1SearchPath = (
|
| 181 |
+
'c:/Program Files/Adobe/Acrobat 9.0/Resource/Font',
|
| 182 |
+
'c:/Program Files/Adobe/Acrobat 8.0/Resource/Font',
|
| 183 |
+
'c:/Program Files/Adobe/Acrobat 7.0/Resource/Font',
|
| 184 |
+
'c:/Program Files/Adobe/Acrobat 6.0/Resource/Font', #Win32, Acrobat 6
|
| 185 |
+
'c:/Program Files/Adobe/Acrobat 5.0/Resource/Font', #Win32, Acrobat 5
|
| 186 |
+
'c:/Program Files/Adobe/Acrobat 4.0/Resource/Font', #Win32, Acrobat 4
|
| 187 |
+
'%(disk)s/Applications/Python %(sys_version)s/reportlab/fonts', #Mac?
|
| 188 |
+
'/usr/lib/Acrobat9/Resource/Font', #Linux, Acrobat 5?
|
| 189 |
+
'/usr/lib/Acrobat8/Resource/Font', #Linux, Acrobat 5?
|
| 190 |
+
'/usr/lib/Acrobat7/Resource/Font', #Linux, Acrobat 5?
|
| 191 |
+
'/usr/lib/Acrobat6/Resource/Font', #Linux, Acrobat 5?
|
| 192 |
+
'/usr/lib/Acrobat5/Resource/Font', #Linux, Acrobat 5?
|
| 193 |
+
'/usr/lib/Acrobat4/Resource/Font', #Linux, Acrobat 4
|
| 194 |
+
'/usr/local/Acrobat9/Resource/Font', #Linux, Acrobat 5?
|
| 195 |
+
'/usr/local/Acrobat8/Resource/Font', #Linux, Acrobat 5?
|
| 196 |
+
'/usr/local/Acrobat7/Resource/Font', #Linux, Acrobat 5?
|
| 197 |
+
'/usr/local/Acrobat6/Resource/Font', #Linux, Acrobat 5?
|
| 198 |
+
'/usr/local/Acrobat5/Resource/Font', #Linux, Acrobat 5?
|
| 199 |
+
'/usr/local/Acrobat4/Resource/Font', #Linux, Acrobat 4
|
| 200 |
+
'/usr/share/fonts/default/Type1', #Linux, Fedora
|
| 201 |
+
'%(REPORTLAB_DIR)s/fonts', #special
|
| 202 |
+
'%(REPORTLAB_DIR)s/../fonts', #special
|
| 203 |
+
'%(REPORTLAB_DIR)s/../../fonts', #special
|
| 204 |
+
'%(CWD)s/fonts', #special
|
| 205 |
+
'~/fonts',
|
| 206 |
+
'~/.fonts',
|
| 207 |
+
'%(XDG_DATA_HOME)s/fonts',
|
| 208 |
+
'~/.local/share/fonts',
|
| 209 |
+
)
|
| 210 |
+
|
| 211 |
+
# places to look for TT Font information
|
| 212 |
+
TTFSearchPath = (
|
| 213 |
+
'c:/winnt/fonts',
|
| 214 |
+
'c:/windows/fonts',
|
| 215 |
+
'/usr/lib/X11/fonts/TrueType/',
|
| 216 |
+
'/usr/share/fonts/truetype',
|
| 217 |
+
'/usr/share/fonts', #Linux, Fedora
|
| 218 |
+
'/usr/share/fonts/dejavu', #Linux, Fedora
|
| 219 |
+
'%(REPORTLAB_DIR)s/fonts', #special
|
| 220 |
+
'%(REPORTLAB_DIR)s/../fonts', #special
|
| 221 |
+
'%(REPORTLAB_DIR)s/../../fonts',#special
|
| 222 |
+
'%(CWD)s/fonts', #special
|
| 223 |
+
'~/fonts',
|
| 224 |
+
'~/.fonts',
|
| 225 |
+
'%(XDG_DATA_HOME)s/fonts',
|
| 226 |
+
'~/.local/share/fonts',
|
| 227 |
+
#mac os X - from
|
| 228 |
+
#http://developer.apple.com/technotes/tn/tn2024.html
|
| 229 |
+
'~/Library/Fonts',
|
| 230 |
+
'/Library/Fonts',
|
| 231 |
+
'/Network/Library/Fonts',
|
| 232 |
+
'/System/Library/Fonts',
|
| 233 |
+
)
|
| 234 |
+
|
| 235 |
+
# places to look for CMap files - should ideally merge with above
|
| 236 |
+
CMapSearchPath = (
|
| 237 |
+
'/usr/lib/Acrobat9/Resource/CMap',
|
| 238 |
+
'/usr/lib/Acrobat8/Resource/CMap',
|
| 239 |
+
'/usr/lib/Acrobat7/Resource/CMap',
|
| 240 |
+
'/usr/lib/Acrobat6/Resource/CMap',
|
| 241 |
+
'/usr/lib/Acrobat5/Resource/CMap',
|
| 242 |
+
'/usr/lib/Acrobat4/Resource/CMap',
|
| 243 |
+
'/usr/local/Acrobat9/Resource/CMap',
|
| 244 |
+
'/usr/local/Acrobat8/Resource/CMap',
|
| 245 |
+
'/usr/local/Acrobat7/Resource/CMap',
|
| 246 |
+
'/usr/local/Acrobat6/Resource/CMap',
|
| 247 |
+
'/usr/local/Acrobat5/Resource/CMap',
|
| 248 |
+
'/usr/local/Acrobat4/Resource/CMap',
|
| 249 |
+
'C:\\Program Files\\Adobe\\Acrobat\\Resource\\CMap',
|
| 250 |
+
'C:\\Program Files\\Adobe\\Acrobat 9.0\\Resource\\CMap',
|
| 251 |
+
'C:\\Program Files\\Adobe\\Acrobat 8.0\\Resource\\CMap',
|
| 252 |
+
'C:\\Program Files\\Adobe\\Acrobat 7.0\\Resource\\CMap',
|
| 253 |
+
'C:\\Program Files\\Adobe\\Acrobat 6.0\\Resource\\CMap',
|
| 254 |
+
'C:\\Program Files\\Adobe\\Acrobat 5.0\\Resource\\CMap',
|
| 255 |
+
'C:\\Program Files\\Adobe\\Acrobat 4.0\\Resource\\CMap',
|
| 256 |
+
'%(REPORTLAB_DIR)s/fonts/CMap', #special
|
| 257 |
+
'%(REPORTLAB_DIR)s/../fonts/CMap', #special
|
| 258 |
+
'%(REPORTLAB_DIR)s/../../fonts/CMap', #special
|
| 259 |
+
'%(CWD)s/fonts/CMap', #special
|
| 260 |
+
'%(CWD)s/fonts', #special
|
| 261 |
+
'~/fonts/CMap',
|
| 262 |
+
'~/.fonts/CMap',
|
| 263 |
+
'%(XDG_DATA_HOME)s/fonts/CMap',
|
| 264 |
+
'~/.local/share/fonts/CMap',
|
| 265 |
+
)
|
| 266 |
+
|
| 267 |
+
if sys.platform.startswith('linux'):
|
| 268 |
+
def _findFontDirs(*ROOTS):
|
| 269 |
+
R = [].append
|
| 270 |
+
for rootd in ROOTS:
|
| 271 |
+
for root, dirs, files in os.walk(rootd):
|
| 272 |
+
if not files: continue
|
| 273 |
+
R(root)
|
| 274 |
+
return tuple(R.__self__)
|
| 275 |
+
T1SearchPath = T1SearchPath + _findFontDirs(
|
| 276 |
+
'/usr/share/fonts/type1',
|
| 277 |
+
'/usr/share/fonts/Type1',
|
| 278 |
+
)
|
| 279 |
+
TTFSearchPath = TTFSearchPath + _findFontDirs(
|
| 280 |
+
'/usr/share/fonts/truetype',
|
| 281 |
+
'/usr/share/fonts/TTF',
|
| 282 |
+
)
|
.venv/lib/python3.13/site-packages/six-1.17.0.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pip
|
.venv/lib/python3.13/site-packages/six-1.17.0.dist-info/LICENSE
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright (c) 2010-2024 Benjamin Peterson
|
| 2 |
+
|
| 3 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
| 4 |
+
this software and associated documentation files (the "Software"), to deal in
|
| 5 |
+
the Software without restriction, including without limitation the rights to
|
| 6 |
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
| 7 |
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
| 8 |
+
subject to the following conditions:
|
| 9 |
+
|
| 10 |
+
The above copyright notice and this permission notice shall be included in all
|
| 11 |
+
copies or substantial portions of the Software.
|
| 12 |
+
|
| 13 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 14 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
| 15 |
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
| 16 |
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
| 17 |
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
| 18 |
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
.venv/lib/python3.13/site-packages/six-1.17.0.dist-info/METADATA
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.1
|
| 2 |
+
Name: six
|
| 3 |
+
Version: 1.17.0
|
| 4 |
+
Summary: Python 2 and 3 compatibility utilities
|
| 5 |
+
Home-page: https://github.com/benjaminp/six
|
| 6 |
+
Author: Benjamin Peterson
|
| 7 |
+
Author-email: benjamin@python.org
|
| 8 |
+
License: MIT
|
| 9 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 10 |
+
Classifier: Programming Language :: Python :: 2
|
| 11 |
+
Classifier: Programming Language :: Python :: 3
|
| 12 |
+
Classifier: Intended Audience :: Developers
|
| 13 |
+
Classifier: License :: OSI Approved :: MIT License
|
| 14 |
+
Classifier: Topic :: Software Development :: Libraries
|
| 15 |
+
Classifier: Topic :: Utilities
|
| 16 |
+
Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*
|
| 17 |
+
License-File: LICENSE
|
| 18 |
+
|
| 19 |
+
.. image:: https://img.shields.io/pypi/v/six.svg
|
| 20 |
+
:target: https://pypi.org/project/six/
|
| 21 |
+
:alt: six on PyPI
|
| 22 |
+
|
| 23 |
+
.. image:: https://readthedocs.org/projects/six/badge/?version=latest
|
| 24 |
+
:target: https://six.readthedocs.io/
|
| 25 |
+
:alt: six's documentation on Read the Docs
|
| 26 |
+
|
| 27 |
+
.. image:: https://img.shields.io/badge/license-MIT-green.svg
|
| 28 |
+
:target: https://github.com/benjaminp/six/blob/master/LICENSE
|
| 29 |
+
:alt: MIT License badge
|
| 30 |
+
|
| 31 |
+
Six is a Python 2 and 3 compatibility library. It provides utility functions
|
| 32 |
+
for smoothing over the differences between the Python versions with the goal of
|
| 33 |
+
writing Python code that is compatible on both Python versions. See the
|
| 34 |
+
documentation for more information on what is provided.
|
| 35 |
+
|
| 36 |
+
Six supports Python 2.7 and 3.3+. It is contained in only one Python
|
| 37 |
+
file, so it can be easily copied into your project. (The copyright and license
|
| 38 |
+
notice must be retained.)
|
| 39 |
+
|
| 40 |
+
Online documentation is at https://six.readthedocs.io/.
|
| 41 |
+
|
| 42 |
+
Bugs can be reported to https://github.com/benjaminp/six. The code can also
|
| 43 |
+
be found there.
|
.venv/lib/python3.13/site-packages/six-1.17.0.dist-info/RECORD
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__pycache__/six.cpython-313.pyc,,
|
| 2 |
+
six-1.17.0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
| 3 |
+
six-1.17.0.dist-info/LICENSE,sha256=Q3W6IOK5xsTnytKUCmKP2Q6VzD1Q7pKq51VxXYuh-9A,1066
|
| 4 |
+
six-1.17.0.dist-info/METADATA,sha256=ViBCB4wnUlSfbYp8htvF3XCAiKe-bYBnLsewcQC3JGg,1658
|
| 5 |
+
six-1.17.0.dist-info/RECORD,,
|
| 6 |
+
six-1.17.0.dist-info/WHEEL,sha256=pxeNX5JdtCe58PUSYP9upmc7jdRPgvT0Gm9kb1SHlVw,109
|
| 7 |
+
six-1.17.0.dist-info/top_level.txt,sha256=_iVH_iYEtEXnD8nYGQYpYFUvkUW9sEO1GYbkeKSAais,4
|
| 8 |
+
six.py,sha256=xRyR9wPT1LNpbJI8tf7CE-BeddkhU5O--sfy-mo5BN8,34703
|
.venv/lib/python3.13/site-packages/six-1.17.0.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: setuptools (75.6.0)
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: py2-none-any
|
| 5 |
+
Tag: py3-none-any
|
| 6 |
+
|
.venv/lib/python3.13/site-packages/six-1.17.0.dist-info/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
six
|
.venv/lib/python3.13/site-packages/six.py
ADDED
|
@@ -0,0 +1,1003 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2010-2024 Benjamin Peterson
|
| 2 |
+
#
|
| 3 |
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 4 |
+
# of this software and associated documentation files (the "Software"), to deal
|
| 5 |
+
# in the Software without restriction, including without limitation the rights
|
| 6 |
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 7 |
+
# copies of the Software, and to permit persons to whom the Software is
|
| 8 |
+
# furnished to do so, subject to the following conditions:
|
| 9 |
+
#
|
| 10 |
+
# The above copyright notice and this permission notice shall be included in all
|
| 11 |
+
# copies or substantial portions of the Software.
|
| 12 |
+
#
|
| 13 |
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 14 |
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 15 |
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 16 |
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 17 |
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 18 |
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 19 |
+
# SOFTWARE.
|
| 20 |
+
|
| 21 |
+
"""Utilities for writing code that runs on Python 2 and 3"""
|
| 22 |
+
|
| 23 |
+
from __future__ import absolute_import
|
| 24 |
+
|
| 25 |
+
import functools
|
| 26 |
+
import itertools
|
| 27 |
+
import operator
|
| 28 |
+
import sys
|
| 29 |
+
import types
|
| 30 |
+
|
| 31 |
+
__author__ = "Benjamin Peterson <benjamin@python.org>"
|
| 32 |
+
__version__ = "1.17.0"
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
# Useful for very coarse version differentiation.
|
| 36 |
+
PY2 = sys.version_info[0] == 2
|
| 37 |
+
PY3 = sys.version_info[0] == 3
|
| 38 |
+
PY34 = sys.version_info[0:2] >= (3, 4)
|
| 39 |
+
|
| 40 |
+
if PY3:
|
| 41 |
+
string_types = str,
|
| 42 |
+
integer_types = int,
|
| 43 |
+
class_types = type,
|
| 44 |
+
text_type = str
|
| 45 |
+
binary_type = bytes
|
| 46 |
+
|
| 47 |
+
MAXSIZE = sys.maxsize
|
| 48 |
+
else:
|
| 49 |
+
string_types = basestring,
|
| 50 |
+
integer_types = (int, long)
|
| 51 |
+
class_types = (type, types.ClassType)
|
| 52 |
+
text_type = unicode
|
| 53 |
+
binary_type = str
|
| 54 |
+
|
| 55 |
+
if sys.platform.startswith("java"):
|
| 56 |
+
# Jython always uses 32 bits.
|
| 57 |
+
MAXSIZE = int((1 << 31) - 1)
|
| 58 |
+
else:
|
| 59 |
+
# It's possible to have sizeof(long) != sizeof(Py_ssize_t).
|
| 60 |
+
class X(object):
|
| 61 |
+
|
| 62 |
+
def __len__(self):
|
| 63 |
+
return 1 << 31
|
| 64 |
+
try:
|
| 65 |
+
len(X())
|
| 66 |
+
except OverflowError:
|
| 67 |
+
# 32-bit
|
| 68 |
+
MAXSIZE = int((1 << 31) - 1)
|
| 69 |
+
else:
|
| 70 |
+
# 64-bit
|
| 71 |
+
MAXSIZE = int((1 << 63) - 1)
|
| 72 |
+
del X
|
| 73 |
+
|
| 74 |
+
if PY34:
|
| 75 |
+
from importlib.util import spec_from_loader
|
| 76 |
+
else:
|
| 77 |
+
spec_from_loader = None
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def _add_doc(func, doc):
|
| 81 |
+
"""Add documentation to a function."""
|
| 82 |
+
func.__doc__ = doc
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def _import_module(name):
|
| 86 |
+
"""Import module, returning the module after the last dot."""
|
| 87 |
+
__import__(name)
|
| 88 |
+
return sys.modules[name]
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
class _LazyDescr(object):
|
| 92 |
+
|
| 93 |
+
def __init__(self, name):
|
| 94 |
+
self.name = name
|
| 95 |
+
|
| 96 |
+
def __get__(self, obj, tp):
|
| 97 |
+
result = self._resolve()
|
| 98 |
+
setattr(obj, self.name, result) # Invokes __set__.
|
| 99 |
+
try:
|
| 100 |
+
# This is a bit ugly, but it avoids running this again by
|
| 101 |
+
# removing this descriptor.
|
| 102 |
+
delattr(obj.__class__, self.name)
|
| 103 |
+
except AttributeError:
|
| 104 |
+
pass
|
| 105 |
+
return result
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
class MovedModule(_LazyDescr):
|
| 109 |
+
|
| 110 |
+
def __init__(self, name, old, new=None):
|
| 111 |
+
super(MovedModule, self).__init__(name)
|
| 112 |
+
if PY3:
|
| 113 |
+
if new is None:
|
| 114 |
+
new = name
|
| 115 |
+
self.mod = new
|
| 116 |
+
else:
|
| 117 |
+
self.mod = old
|
| 118 |
+
|
| 119 |
+
def _resolve(self):
|
| 120 |
+
return _import_module(self.mod)
|
| 121 |
+
|
| 122 |
+
def __getattr__(self, attr):
|
| 123 |
+
_module = self._resolve()
|
| 124 |
+
value = getattr(_module, attr)
|
| 125 |
+
setattr(self, attr, value)
|
| 126 |
+
return value
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
class _LazyModule(types.ModuleType):
|
| 130 |
+
|
| 131 |
+
def __init__(self, name):
|
| 132 |
+
super(_LazyModule, self).__init__(name)
|
| 133 |
+
self.__doc__ = self.__class__.__doc__
|
| 134 |
+
|
| 135 |
+
def __dir__(self):
|
| 136 |
+
attrs = ["__doc__", "__name__"]
|
| 137 |
+
attrs += [attr.name for attr in self._moved_attributes]
|
| 138 |
+
return attrs
|
| 139 |
+
|
| 140 |
+
# Subclasses should override this
|
| 141 |
+
_moved_attributes = []
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
class MovedAttribute(_LazyDescr):
|
| 145 |
+
|
| 146 |
+
def __init__(self, name, old_mod, new_mod, old_attr=None, new_attr=None):
|
| 147 |
+
super(MovedAttribute, self).__init__(name)
|
| 148 |
+
if PY3:
|
| 149 |
+
if new_mod is None:
|
| 150 |
+
new_mod = name
|
| 151 |
+
self.mod = new_mod
|
| 152 |
+
if new_attr is None:
|
| 153 |
+
if old_attr is None:
|
| 154 |
+
new_attr = name
|
| 155 |
+
else:
|
| 156 |
+
new_attr = old_attr
|
| 157 |
+
self.attr = new_attr
|
| 158 |
+
else:
|
| 159 |
+
self.mod = old_mod
|
| 160 |
+
if old_attr is None:
|
| 161 |
+
old_attr = name
|
| 162 |
+
self.attr = old_attr
|
| 163 |
+
|
| 164 |
+
def _resolve(self):
|
| 165 |
+
module = _import_module(self.mod)
|
| 166 |
+
return getattr(module, self.attr)
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
class _SixMetaPathImporter(object):
|
| 170 |
+
|
| 171 |
+
"""
|
| 172 |
+
A meta path importer to import six.moves and its submodules.
|
| 173 |
+
|
| 174 |
+
This class implements a PEP302 finder and loader. It should be compatible
|
| 175 |
+
with Python 2.5 and all existing versions of Python3
|
| 176 |
+
"""
|
| 177 |
+
|
| 178 |
+
def __init__(self, six_module_name):
|
| 179 |
+
self.name = six_module_name
|
| 180 |
+
self.known_modules = {}
|
| 181 |
+
|
| 182 |
+
def _add_module(self, mod, *fullnames):
|
| 183 |
+
for fullname in fullnames:
|
| 184 |
+
self.known_modules[self.name + "." + fullname] = mod
|
| 185 |
+
|
| 186 |
+
def _get_module(self, fullname):
|
| 187 |
+
return self.known_modules[self.name + "." + fullname]
|
| 188 |
+
|
| 189 |
+
def find_module(self, fullname, path=None):
|
| 190 |
+
if fullname in self.known_modules:
|
| 191 |
+
return self
|
| 192 |
+
return None
|
| 193 |
+
|
| 194 |
+
def find_spec(self, fullname, path, target=None):
|
| 195 |
+
if fullname in self.known_modules:
|
| 196 |
+
return spec_from_loader(fullname, self)
|
| 197 |
+
return None
|
| 198 |
+
|
| 199 |
+
def __get_module(self, fullname):
|
| 200 |
+
try:
|
| 201 |
+
return self.known_modules[fullname]
|
| 202 |
+
except KeyError:
|
| 203 |
+
raise ImportError("This loader does not know module " + fullname)
|
| 204 |
+
|
| 205 |
+
def load_module(self, fullname):
|
| 206 |
+
try:
|
| 207 |
+
# in case of a reload
|
| 208 |
+
return sys.modules[fullname]
|
| 209 |
+
except KeyError:
|
| 210 |
+
pass
|
| 211 |
+
mod = self.__get_module(fullname)
|
| 212 |
+
if isinstance(mod, MovedModule):
|
| 213 |
+
mod = mod._resolve()
|
| 214 |
+
else:
|
| 215 |
+
mod.__loader__ = self
|
| 216 |
+
sys.modules[fullname] = mod
|
| 217 |
+
return mod
|
| 218 |
+
|
| 219 |
+
def is_package(self, fullname):
|
| 220 |
+
"""
|
| 221 |
+
Return true, if the named module is a package.
|
| 222 |
+
|
| 223 |
+
We need this method to get correct spec objects with
|
| 224 |
+
Python 3.4 (see PEP451)
|
| 225 |
+
"""
|
| 226 |
+
return hasattr(self.__get_module(fullname), "__path__")
|
| 227 |
+
|
| 228 |
+
def get_code(self, fullname):
|
| 229 |
+
"""Return None
|
| 230 |
+
|
| 231 |
+
Required, if is_package is implemented"""
|
| 232 |
+
self.__get_module(fullname) # eventually raises ImportError
|
| 233 |
+
return None
|
| 234 |
+
get_source = get_code # same as get_code
|
| 235 |
+
|
| 236 |
+
def create_module(self, spec):
|
| 237 |
+
return self.load_module(spec.name)
|
| 238 |
+
|
| 239 |
+
def exec_module(self, module):
|
| 240 |
+
pass
|
| 241 |
+
|
| 242 |
+
_importer = _SixMetaPathImporter(__name__)
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
class _MovedItems(_LazyModule):
|
| 246 |
+
|
| 247 |
+
"""Lazy loading of moved objects"""
|
| 248 |
+
__path__ = [] # mark as package
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
_moved_attributes = [
|
| 252 |
+
MovedAttribute("cStringIO", "cStringIO", "io", "StringIO"),
|
| 253 |
+
MovedAttribute("filter", "itertools", "builtins", "ifilter", "filter"),
|
| 254 |
+
MovedAttribute("filterfalse", "itertools", "itertools", "ifilterfalse", "filterfalse"),
|
| 255 |
+
MovedAttribute("input", "__builtin__", "builtins", "raw_input", "input"),
|
| 256 |
+
MovedAttribute("intern", "__builtin__", "sys"),
|
| 257 |
+
MovedAttribute("map", "itertools", "builtins", "imap", "map"),
|
| 258 |
+
MovedAttribute("getcwd", "os", "os", "getcwdu", "getcwd"),
|
| 259 |
+
MovedAttribute("getcwdb", "os", "os", "getcwd", "getcwdb"),
|
| 260 |
+
MovedAttribute("getoutput", "commands", "subprocess"),
|
| 261 |
+
MovedAttribute("range", "__builtin__", "builtins", "xrange", "range"),
|
| 262 |
+
MovedAttribute("reload_module", "__builtin__", "importlib" if PY34 else "imp", "reload"),
|
| 263 |
+
MovedAttribute("reduce", "__builtin__", "functools"),
|
| 264 |
+
MovedAttribute("shlex_quote", "pipes", "shlex", "quote"),
|
| 265 |
+
MovedAttribute("StringIO", "StringIO", "io"),
|
| 266 |
+
MovedAttribute("UserDict", "UserDict", "collections", "IterableUserDict", "UserDict"),
|
| 267 |
+
MovedAttribute("UserList", "UserList", "collections"),
|
| 268 |
+
MovedAttribute("UserString", "UserString", "collections"),
|
| 269 |
+
MovedAttribute("xrange", "__builtin__", "builtins", "xrange", "range"),
|
| 270 |
+
MovedAttribute("zip", "itertools", "builtins", "izip", "zip"),
|
| 271 |
+
MovedAttribute("zip_longest", "itertools", "itertools", "izip_longest", "zip_longest"),
|
| 272 |
+
MovedModule("builtins", "__builtin__"),
|
| 273 |
+
MovedModule("configparser", "ConfigParser"),
|
| 274 |
+
MovedModule("collections_abc", "collections", "collections.abc" if sys.version_info >= (3, 3) else "collections"),
|
| 275 |
+
MovedModule("copyreg", "copy_reg"),
|
| 276 |
+
MovedModule("dbm_gnu", "gdbm", "dbm.gnu"),
|
| 277 |
+
MovedModule("dbm_ndbm", "dbm", "dbm.ndbm"),
|
| 278 |
+
MovedModule("_dummy_thread", "dummy_thread", "_dummy_thread" if sys.version_info < (3, 9) else "_thread"),
|
| 279 |
+
MovedModule("http_cookiejar", "cookielib", "http.cookiejar"),
|
| 280 |
+
MovedModule("http_cookies", "Cookie", "http.cookies"),
|
| 281 |
+
MovedModule("html_entities", "htmlentitydefs", "html.entities"),
|
| 282 |
+
MovedModule("html_parser", "HTMLParser", "html.parser"),
|
| 283 |
+
MovedModule("http_client", "httplib", "http.client"),
|
| 284 |
+
MovedModule("email_mime_base", "email.MIMEBase", "email.mime.base"),
|
| 285 |
+
MovedModule("email_mime_image", "email.MIMEImage", "email.mime.image"),
|
| 286 |
+
MovedModule("email_mime_multipart", "email.MIMEMultipart", "email.mime.multipart"),
|
| 287 |
+
MovedModule("email_mime_nonmultipart", "email.MIMENonMultipart", "email.mime.nonmultipart"),
|
| 288 |
+
MovedModule("email_mime_text", "email.MIMEText", "email.mime.text"),
|
| 289 |
+
MovedModule("BaseHTTPServer", "BaseHTTPServer", "http.server"),
|
| 290 |
+
MovedModule("CGIHTTPServer", "CGIHTTPServer", "http.server"),
|
| 291 |
+
MovedModule("SimpleHTTPServer", "SimpleHTTPServer", "http.server"),
|
| 292 |
+
MovedModule("cPickle", "cPickle", "pickle"),
|
| 293 |
+
MovedModule("queue", "Queue"),
|
| 294 |
+
MovedModule("reprlib", "repr"),
|
| 295 |
+
MovedModule("socketserver", "SocketServer"),
|
| 296 |
+
MovedModule("_thread", "thread", "_thread"),
|
| 297 |
+
MovedModule("tkinter", "Tkinter"),
|
| 298 |
+
MovedModule("tkinter_dialog", "Dialog", "tkinter.dialog"),
|
| 299 |
+
MovedModule("tkinter_filedialog", "FileDialog", "tkinter.filedialog"),
|
| 300 |
+
MovedModule("tkinter_scrolledtext", "ScrolledText", "tkinter.scrolledtext"),
|
| 301 |
+
MovedModule("tkinter_simpledialog", "SimpleDialog", "tkinter.simpledialog"),
|
| 302 |
+
MovedModule("tkinter_tix", "Tix", "tkinter.tix"),
|
| 303 |
+
MovedModule("tkinter_ttk", "ttk", "tkinter.ttk"),
|
| 304 |
+
MovedModule("tkinter_constants", "Tkconstants", "tkinter.constants"),
|
| 305 |
+
MovedModule("tkinter_dnd", "Tkdnd", "tkinter.dnd"),
|
| 306 |
+
MovedModule("tkinter_colorchooser", "tkColorChooser",
|
| 307 |
+
"tkinter.colorchooser"),
|
| 308 |
+
MovedModule("tkinter_commondialog", "tkCommonDialog",
|
| 309 |
+
"tkinter.commondialog"),
|
| 310 |
+
MovedModule("tkinter_tkfiledialog", "tkFileDialog", "tkinter.filedialog"),
|
| 311 |
+
MovedModule("tkinter_font", "tkFont", "tkinter.font"),
|
| 312 |
+
MovedModule("tkinter_messagebox", "tkMessageBox", "tkinter.messagebox"),
|
| 313 |
+
MovedModule("tkinter_tksimpledialog", "tkSimpleDialog",
|
| 314 |
+
"tkinter.simpledialog"),
|
| 315 |
+
MovedModule("urllib_parse", __name__ + ".moves.urllib_parse", "urllib.parse"),
|
| 316 |
+
MovedModule("urllib_error", __name__ + ".moves.urllib_error", "urllib.error"),
|
| 317 |
+
MovedModule("urllib", __name__ + ".moves.urllib", __name__ + ".moves.urllib"),
|
| 318 |
+
MovedModule("urllib_robotparser", "robotparser", "urllib.robotparser"),
|
| 319 |
+
MovedModule("xmlrpc_client", "xmlrpclib", "xmlrpc.client"),
|
| 320 |
+
MovedModule("xmlrpc_server", "SimpleXMLRPCServer", "xmlrpc.server"),
|
| 321 |
+
]
|
| 322 |
+
# Add windows specific modules.
|
| 323 |
+
if sys.platform == "win32":
|
| 324 |
+
_moved_attributes += [
|
| 325 |
+
MovedModule("winreg", "_winreg"),
|
| 326 |
+
]
|
| 327 |
+
|
| 328 |
+
for attr in _moved_attributes:
|
| 329 |
+
setattr(_MovedItems, attr.name, attr)
|
| 330 |
+
if isinstance(attr, MovedModule):
|
| 331 |
+
_importer._add_module(attr, "moves." + attr.name)
|
| 332 |
+
del attr
|
| 333 |
+
|
| 334 |
+
_MovedItems._moved_attributes = _moved_attributes
|
| 335 |
+
|
| 336 |
+
moves = _MovedItems(__name__ + ".moves")
|
| 337 |
+
_importer._add_module(moves, "moves")
|
| 338 |
+
|
| 339 |
+
|
| 340 |
+
class Module_six_moves_urllib_parse(_LazyModule):
|
| 341 |
+
|
| 342 |
+
"""Lazy loading of moved objects in six.moves.urllib_parse"""
|
| 343 |
+
|
| 344 |
+
|
| 345 |
+
_urllib_parse_moved_attributes = [
|
| 346 |
+
MovedAttribute("ParseResult", "urlparse", "urllib.parse"),
|
| 347 |
+
MovedAttribute("SplitResult", "urlparse", "urllib.parse"),
|
| 348 |
+
MovedAttribute("parse_qs", "urlparse", "urllib.parse"),
|
| 349 |
+
MovedAttribute("parse_qsl", "urlparse", "urllib.parse"),
|
| 350 |
+
MovedAttribute("urldefrag", "urlparse", "urllib.parse"),
|
| 351 |
+
MovedAttribute("urljoin", "urlparse", "urllib.parse"),
|
| 352 |
+
MovedAttribute("urlparse", "urlparse", "urllib.parse"),
|
| 353 |
+
MovedAttribute("urlsplit", "urlparse", "urllib.parse"),
|
| 354 |
+
MovedAttribute("urlunparse", "urlparse", "urllib.parse"),
|
| 355 |
+
MovedAttribute("urlunsplit", "urlparse", "urllib.parse"),
|
| 356 |
+
MovedAttribute("quote", "urllib", "urllib.parse"),
|
| 357 |
+
MovedAttribute("quote_plus", "urllib", "urllib.parse"),
|
| 358 |
+
MovedAttribute("unquote", "urllib", "urllib.parse"),
|
| 359 |
+
MovedAttribute("unquote_plus", "urllib", "urllib.parse"),
|
| 360 |
+
MovedAttribute("unquote_to_bytes", "urllib", "urllib.parse", "unquote", "unquote_to_bytes"),
|
| 361 |
+
MovedAttribute("urlencode", "urllib", "urllib.parse"),
|
| 362 |
+
MovedAttribute("splitquery", "urllib", "urllib.parse"),
|
| 363 |
+
MovedAttribute("splittag", "urllib", "urllib.parse"),
|
| 364 |
+
MovedAttribute("splituser", "urllib", "urllib.parse"),
|
| 365 |
+
MovedAttribute("splitvalue", "urllib", "urllib.parse"),
|
| 366 |
+
MovedAttribute("uses_fragment", "urlparse", "urllib.parse"),
|
| 367 |
+
MovedAttribute("uses_netloc", "urlparse", "urllib.parse"),
|
| 368 |
+
MovedAttribute("uses_params", "urlparse", "urllib.parse"),
|
| 369 |
+
MovedAttribute("uses_query", "urlparse", "urllib.parse"),
|
| 370 |
+
MovedAttribute("uses_relative", "urlparse", "urllib.parse"),
|
| 371 |
+
]
|
| 372 |
+
for attr in _urllib_parse_moved_attributes:
|
| 373 |
+
setattr(Module_six_moves_urllib_parse, attr.name, attr)
|
| 374 |
+
del attr
|
| 375 |
+
|
| 376 |
+
Module_six_moves_urllib_parse._moved_attributes = _urllib_parse_moved_attributes
|
| 377 |
+
|
| 378 |
+
_importer._add_module(Module_six_moves_urllib_parse(__name__ + ".moves.urllib_parse"),
|
| 379 |
+
"moves.urllib_parse", "moves.urllib.parse")
|
| 380 |
+
|
| 381 |
+
|
| 382 |
+
class Module_six_moves_urllib_error(_LazyModule):
|
| 383 |
+
|
| 384 |
+
"""Lazy loading of moved objects in six.moves.urllib_error"""
|
| 385 |
+
|
| 386 |
+
|
| 387 |
+
_urllib_error_moved_attributes = [
|
| 388 |
+
MovedAttribute("URLError", "urllib2", "urllib.error"),
|
| 389 |
+
MovedAttribute("HTTPError", "urllib2", "urllib.error"),
|
| 390 |
+
MovedAttribute("ContentTooShortError", "urllib", "urllib.error"),
|
| 391 |
+
]
|
| 392 |
+
for attr in _urllib_error_moved_attributes:
|
| 393 |
+
setattr(Module_six_moves_urllib_error, attr.name, attr)
|
| 394 |
+
del attr
|
| 395 |
+
|
| 396 |
+
Module_six_moves_urllib_error._moved_attributes = _urllib_error_moved_attributes
|
| 397 |
+
|
| 398 |
+
_importer._add_module(Module_six_moves_urllib_error(__name__ + ".moves.urllib.error"),
|
| 399 |
+
"moves.urllib_error", "moves.urllib.error")
|
| 400 |
+
|
| 401 |
+
|
| 402 |
+
class Module_six_moves_urllib_request(_LazyModule):
|
| 403 |
+
|
| 404 |
+
"""Lazy loading of moved objects in six.moves.urllib_request"""
|
| 405 |
+
|
| 406 |
+
|
| 407 |
+
_urllib_request_moved_attributes = [
|
| 408 |
+
MovedAttribute("urlopen", "urllib2", "urllib.request"),
|
| 409 |
+
MovedAttribute("install_opener", "urllib2", "urllib.request"),
|
| 410 |
+
MovedAttribute("build_opener", "urllib2", "urllib.request"),
|
| 411 |
+
MovedAttribute("pathname2url", "urllib", "urllib.request"),
|
| 412 |
+
MovedAttribute("url2pathname", "urllib", "urllib.request"),
|
| 413 |
+
MovedAttribute("getproxies", "urllib", "urllib.request"),
|
| 414 |
+
MovedAttribute("Request", "urllib2", "urllib.request"),
|
| 415 |
+
MovedAttribute("OpenerDirector", "urllib2", "urllib.request"),
|
| 416 |
+
MovedAttribute("HTTPDefaultErrorHandler", "urllib2", "urllib.request"),
|
| 417 |
+
MovedAttribute("HTTPRedirectHandler", "urllib2", "urllib.request"),
|
| 418 |
+
MovedAttribute("HTTPCookieProcessor", "urllib2", "urllib.request"),
|
| 419 |
+
MovedAttribute("ProxyHandler", "urllib2", "urllib.request"),
|
| 420 |
+
MovedAttribute("BaseHandler", "urllib2", "urllib.request"),
|
| 421 |
+
MovedAttribute("HTTPPasswordMgr", "urllib2", "urllib.request"),
|
| 422 |
+
MovedAttribute("HTTPPasswordMgrWithDefaultRealm", "urllib2", "urllib.request"),
|
| 423 |
+
MovedAttribute("AbstractBasicAuthHandler", "urllib2", "urllib.request"),
|
| 424 |
+
MovedAttribute("HTTPBasicAuthHandler", "urllib2", "urllib.request"),
|
| 425 |
+
MovedAttribute("ProxyBasicAuthHandler", "urllib2", "urllib.request"),
|
| 426 |
+
MovedAttribute("AbstractDigestAuthHandler", "urllib2", "urllib.request"),
|
| 427 |
+
MovedAttribute("HTTPDigestAuthHandler", "urllib2", "urllib.request"),
|
| 428 |
+
MovedAttribute("ProxyDigestAuthHandler", "urllib2", "urllib.request"),
|
| 429 |
+
MovedAttribute("HTTPHandler", "urllib2", "urllib.request"),
|
| 430 |
+
MovedAttribute("HTTPSHandler", "urllib2", "urllib.request"),
|
| 431 |
+
MovedAttribute("FileHandler", "urllib2", "urllib.request"),
|
| 432 |
+
MovedAttribute("FTPHandler", "urllib2", "urllib.request"),
|
| 433 |
+
MovedAttribute("CacheFTPHandler", "urllib2", "urllib.request"),
|
| 434 |
+
MovedAttribute("UnknownHandler", "urllib2", "urllib.request"),
|
| 435 |
+
MovedAttribute("HTTPErrorProcessor", "urllib2", "urllib.request"),
|
| 436 |
+
MovedAttribute("urlretrieve", "urllib", "urllib.request"),
|
| 437 |
+
MovedAttribute("urlcleanup", "urllib", "urllib.request"),
|
| 438 |
+
MovedAttribute("proxy_bypass", "urllib", "urllib.request"),
|
| 439 |
+
MovedAttribute("parse_http_list", "urllib2", "urllib.request"),
|
| 440 |
+
MovedAttribute("parse_keqv_list", "urllib2", "urllib.request"),
|
| 441 |
+
]
|
| 442 |
+
if sys.version_info[:2] < (3, 14):
|
| 443 |
+
_urllib_request_moved_attributes.extend(
|
| 444 |
+
[
|
| 445 |
+
MovedAttribute("URLopener", "urllib", "urllib.request"),
|
| 446 |
+
MovedAttribute("FancyURLopener", "urllib", "urllib.request"),
|
| 447 |
+
]
|
| 448 |
+
)
|
| 449 |
+
for attr in _urllib_request_moved_attributes:
|
| 450 |
+
setattr(Module_six_moves_urllib_request, attr.name, attr)
|
| 451 |
+
del attr
|
| 452 |
+
|
| 453 |
+
Module_six_moves_urllib_request._moved_attributes = _urllib_request_moved_attributes
|
| 454 |
+
|
| 455 |
+
_importer._add_module(Module_six_moves_urllib_request(__name__ + ".moves.urllib.request"),
|
| 456 |
+
"moves.urllib_request", "moves.urllib.request")
|
| 457 |
+
|
| 458 |
+
|
| 459 |
+
class Module_six_moves_urllib_response(_LazyModule):
|
| 460 |
+
|
| 461 |
+
"""Lazy loading of moved objects in six.moves.urllib_response"""
|
| 462 |
+
|
| 463 |
+
|
| 464 |
+
_urllib_response_moved_attributes = [
|
| 465 |
+
MovedAttribute("addbase", "urllib", "urllib.response"),
|
| 466 |
+
MovedAttribute("addclosehook", "urllib", "urllib.response"),
|
| 467 |
+
MovedAttribute("addinfo", "urllib", "urllib.response"),
|
| 468 |
+
MovedAttribute("addinfourl", "urllib", "urllib.response"),
|
| 469 |
+
]
|
| 470 |
+
for attr in _urllib_response_moved_attributes:
|
| 471 |
+
setattr(Module_six_moves_urllib_response, attr.name, attr)
|
| 472 |
+
del attr
|
| 473 |
+
|
| 474 |
+
Module_six_moves_urllib_response._moved_attributes = _urllib_response_moved_attributes
|
| 475 |
+
|
| 476 |
+
_importer._add_module(Module_six_moves_urllib_response(__name__ + ".moves.urllib.response"),
|
| 477 |
+
"moves.urllib_response", "moves.urllib.response")
|
| 478 |
+
|
| 479 |
+
|
| 480 |
+
class Module_six_moves_urllib_robotparser(_LazyModule):
|
| 481 |
+
|
| 482 |
+
"""Lazy loading of moved objects in six.moves.urllib_robotparser"""
|
| 483 |
+
|
| 484 |
+
|
| 485 |
+
_urllib_robotparser_moved_attributes = [
|
| 486 |
+
MovedAttribute("RobotFileParser", "robotparser", "urllib.robotparser"),
|
| 487 |
+
]
|
| 488 |
+
for attr in _urllib_robotparser_moved_attributes:
|
| 489 |
+
setattr(Module_six_moves_urllib_robotparser, attr.name, attr)
|
| 490 |
+
del attr
|
| 491 |
+
|
| 492 |
+
Module_six_moves_urllib_robotparser._moved_attributes = _urllib_robotparser_moved_attributes
|
| 493 |
+
|
| 494 |
+
_importer._add_module(Module_six_moves_urllib_robotparser(__name__ + ".moves.urllib.robotparser"),
|
| 495 |
+
"moves.urllib_robotparser", "moves.urllib.robotparser")
|
| 496 |
+
|
| 497 |
+
|
| 498 |
+
class Module_six_moves_urllib(types.ModuleType):
|
| 499 |
+
|
| 500 |
+
"""Create a six.moves.urllib namespace that resembles the Python 3 namespace"""
|
| 501 |
+
__path__ = [] # mark as package
|
| 502 |
+
parse = _importer._get_module("moves.urllib_parse")
|
| 503 |
+
error = _importer._get_module("moves.urllib_error")
|
| 504 |
+
request = _importer._get_module("moves.urllib_request")
|
| 505 |
+
response = _importer._get_module("moves.urllib_response")
|
| 506 |
+
robotparser = _importer._get_module("moves.urllib_robotparser")
|
| 507 |
+
|
| 508 |
+
def __dir__(self):
|
| 509 |
+
return ['parse', 'error', 'request', 'response', 'robotparser']
|
| 510 |
+
|
| 511 |
+
_importer._add_module(Module_six_moves_urllib(__name__ + ".moves.urllib"),
|
| 512 |
+
"moves.urllib")
|
| 513 |
+
|
| 514 |
+
|
| 515 |
+
def add_move(move):
|
| 516 |
+
"""Add an item to six.moves."""
|
| 517 |
+
setattr(_MovedItems, move.name, move)
|
| 518 |
+
|
| 519 |
+
|
| 520 |
+
def remove_move(name):
|
| 521 |
+
"""Remove item from six.moves."""
|
| 522 |
+
try:
|
| 523 |
+
delattr(_MovedItems, name)
|
| 524 |
+
except AttributeError:
|
| 525 |
+
try:
|
| 526 |
+
del moves.__dict__[name]
|
| 527 |
+
except KeyError:
|
| 528 |
+
raise AttributeError("no such move, %r" % (name,))
|
| 529 |
+
|
| 530 |
+
|
| 531 |
+
if PY3:
|
| 532 |
+
_meth_func = "__func__"
|
| 533 |
+
_meth_self = "__self__"
|
| 534 |
+
|
| 535 |
+
_func_closure = "__closure__"
|
| 536 |
+
_func_code = "__code__"
|
| 537 |
+
_func_defaults = "__defaults__"
|
| 538 |
+
_func_globals = "__globals__"
|
| 539 |
+
else:
|
| 540 |
+
_meth_func = "im_func"
|
| 541 |
+
_meth_self = "im_self"
|
| 542 |
+
|
| 543 |
+
_func_closure = "func_closure"
|
| 544 |
+
_func_code = "func_code"
|
| 545 |
+
_func_defaults = "func_defaults"
|
| 546 |
+
_func_globals = "func_globals"
|
| 547 |
+
|
| 548 |
+
|
| 549 |
+
try:
|
| 550 |
+
advance_iterator = next
|
| 551 |
+
except NameError:
|
| 552 |
+
def advance_iterator(it):
|
| 553 |
+
return it.next()
|
| 554 |
+
next = advance_iterator
|
| 555 |
+
|
| 556 |
+
|
| 557 |
+
try:
|
| 558 |
+
callable = callable
|
| 559 |
+
except NameError:
|
| 560 |
+
def callable(obj):
|
| 561 |
+
return any("__call__" in klass.__dict__ for klass in type(obj).__mro__)
|
| 562 |
+
|
| 563 |
+
|
| 564 |
+
if PY3:
|
| 565 |
+
def get_unbound_function(unbound):
|
| 566 |
+
return unbound
|
| 567 |
+
|
| 568 |
+
create_bound_method = types.MethodType
|
| 569 |
+
|
| 570 |
+
def create_unbound_method(func, cls):
|
| 571 |
+
return func
|
| 572 |
+
|
| 573 |
+
Iterator = object
|
| 574 |
+
else:
|
| 575 |
+
def get_unbound_function(unbound):
|
| 576 |
+
return unbound.im_func
|
| 577 |
+
|
| 578 |
+
def create_bound_method(func, obj):
|
| 579 |
+
return types.MethodType(func, obj, obj.__class__)
|
| 580 |
+
|
| 581 |
+
def create_unbound_method(func, cls):
|
| 582 |
+
return types.MethodType(func, None, cls)
|
| 583 |
+
|
| 584 |
+
class Iterator(object):
|
| 585 |
+
|
| 586 |
+
def next(self):
|
| 587 |
+
return type(self).__next__(self)
|
| 588 |
+
|
| 589 |
+
callable = callable
|
| 590 |
+
_add_doc(get_unbound_function,
|
| 591 |
+
"""Get the function out of a possibly unbound function""")
|
| 592 |
+
|
| 593 |
+
|
| 594 |
+
get_method_function = operator.attrgetter(_meth_func)
|
| 595 |
+
get_method_self = operator.attrgetter(_meth_self)
|
| 596 |
+
get_function_closure = operator.attrgetter(_func_closure)
|
| 597 |
+
get_function_code = operator.attrgetter(_func_code)
|
| 598 |
+
get_function_defaults = operator.attrgetter(_func_defaults)
|
| 599 |
+
get_function_globals = operator.attrgetter(_func_globals)
|
| 600 |
+
|
| 601 |
+
|
| 602 |
+
if PY3:
|
| 603 |
+
def iterkeys(d, **kw):
|
| 604 |
+
return iter(d.keys(**kw))
|
| 605 |
+
|
| 606 |
+
def itervalues(d, **kw):
|
| 607 |
+
return iter(d.values(**kw))
|
| 608 |
+
|
| 609 |
+
def iteritems(d, **kw):
|
| 610 |
+
return iter(d.items(**kw))
|
| 611 |
+
|
| 612 |
+
def iterlists(d, **kw):
|
| 613 |
+
return iter(d.lists(**kw))
|
| 614 |
+
|
| 615 |
+
viewkeys = operator.methodcaller("keys")
|
| 616 |
+
|
| 617 |
+
viewvalues = operator.methodcaller("values")
|
| 618 |
+
|
| 619 |
+
viewitems = operator.methodcaller("items")
|
| 620 |
+
else:
|
| 621 |
+
def iterkeys(d, **kw):
|
| 622 |
+
return d.iterkeys(**kw)
|
| 623 |
+
|
| 624 |
+
def itervalues(d, **kw):
|
| 625 |
+
return d.itervalues(**kw)
|
| 626 |
+
|
| 627 |
+
def iteritems(d, **kw):
|
| 628 |
+
return d.iteritems(**kw)
|
| 629 |
+
|
| 630 |
+
def iterlists(d, **kw):
|
| 631 |
+
return d.iterlists(**kw)
|
| 632 |
+
|
| 633 |
+
viewkeys = operator.methodcaller("viewkeys")
|
| 634 |
+
|
| 635 |
+
viewvalues = operator.methodcaller("viewvalues")
|
| 636 |
+
|
| 637 |
+
viewitems = operator.methodcaller("viewitems")
|
| 638 |
+
|
| 639 |
+
_add_doc(iterkeys, "Return an iterator over the keys of a dictionary.")
|
| 640 |
+
_add_doc(itervalues, "Return an iterator over the values of a dictionary.")
|
| 641 |
+
_add_doc(iteritems,
|
| 642 |
+
"Return an iterator over the (key, value) pairs of a dictionary.")
|
| 643 |
+
_add_doc(iterlists,
|
| 644 |
+
"Return an iterator over the (key, [values]) pairs of a dictionary.")
|
| 645 |
+
|
| 646 |
+
|
| 647 |
+
if PY3:
|
| 648 |
+
def b(s):
|
| 649 |
+
return s.encode("latin-1")
|
| 650 |
+
|
| 651 |
+
def u(s):
|
| 652 |
+
return s
|
| 653 |
+
unichr = chr
|
| 654 |
+
import struct
|
| 655 |
+
int2byte = struct.Struct(">B").pack
|
| 656 |
+
del struct
|
| 657 |
+
byte2int = operator.itemgetter(0)
|
| 658 |
+
indexbytes = operator.getitem
|
| 659 |
+
iterbytes = iter
|
| 660 |
+
import io
|
| 661 |
+
StringIO = io.StringIO
|
| 662 |
+
BytesIO = io.BytesIO
|
| 663 |
+
del io
|
| 664 |
+
_assertCountEqual = "assertCountEqual"
|
| 665 |
+
if sys.version_info[1] <= 1:
|
| 666 |
+
_assertRaisesRegex = "assertRaisesRegexp"
|
| 667 |
+
_assertRegex = "assertRegexpMatches"
|
| 668 |
+
_assertNotRegex = "assertNotRegexpMatches"
|
| 669 |
+
else:
|
| 670 |
+
_assertRaisesRegex = "assertRaisesRegex"
|
| 671 |
+
_assertRegex = "assertRegex"
|
| 672 |
+
_assertNotRegex = "assertNotRegex"
|
| 673 |
+
else:
|
| 674 |
+
def b(s):
|
| 675 |
+
return s
|
| 676 |
+
# Workaround for standalone backslash
|
| 677 |
+
|
| 678 |
+
def u(s):
|
| 679 |
+
return unicode(s.replace(r'\\', r'\\\\'), "unicode_escape")
|
| 680 |
+
unichr = unichr
|
| 681 |
+
int2byte = chr
|
| 682 |
+
|
| 683 |
+
def byte2int(bs):
|
| 684 |
+
return ord(bs[0])
|
| 685 |
+
|
| 686 |
+
def indexbytes(buf, i):
|
| 687 |
+
return ord(buf[i])
|
| 688 |
+
iterbytes = functools.partial(itertools.imap, ord)
|
| 689 |
+
import StringIO
|
| 690 |
+
StringIO = BytesIO = StringIO.StringIO
|
| 691 |
+
_assertCountEqual = "assertItemsEqual"
|
| 692 |
+
_assertRaisesRegex = "assertRaisesRegexp"
|
| 693 |
+
_assertRegex = "assertRegexpMatches"
|
| 694 |
+
_assertNotRegex = "assertNotRegexpMatches"
|
| 695 |
+
_add_doc(b, """Byte literal""")
|
| 696 |
+
_add_doc(u, """Text literal""")
|
| 697 |
+
|
| 698 |
+
|
| 699 |
+
def assertCountEqual(self, *args, **kwargs):
|
| 700 |
+
return getattr(self, _assertCountEqual)(*args, **kwargs)
|
| 701 |
+
|
| 702 |
+
|
| 703 |
+
def assertRaisesRegex(self, *args, **kwargs):
|
| 704 |
+
return getattr(self, _assertRaisesRegex)(*args, **kwargs)
|
| 705 |
+
|
| 706 |
+
|
| 707 |
+
def assertRegex(self, *args, **kwargs):
|
| 708 |
+
return getattr(self, _assertRegex)(*args, **kwargs)
|
| 709 |
+
|
| 710 |
+
|
| 711 |
+
def assertNotRegex(self, *args, **kwargs):
|
| 712 |
+
return getattr(self, _assertNotRegex)(*args, **kwargs)
|
| 713 |
+
|
| 714 |
+
|
| 715 |
+
if PY3:
|
| 716 |
+
exec_ = getattr(moves.builtins, "exec")
|
| 717 |
+
|
| 718 |
+
def reraise(tp, value, tb=None):
|
| 719 |
+
try:
|
| 720 |
+
if value is None:
|
| 721 |
+
value = tp()
|
| 722 |
+
if value.__traceback__ is not tb:
|
| 723 |
+
raise value.with_traceback(tb)
|
| 724 |
+
raise value
|
| 725 |
+
finally:
|
| 726 |
+
value = None
|
| 727 |
+
tb = None
|
| 728 |
+
|
| 729 |
+
else:
|
| 730 |
+
def exec_(_code_, _globs_=None, _locs_=None):
|
| 731 |
+
"""Execute code in a namespace."""
|
| 732 |
+
if _globs_ is None:
|
| 733 |
+
frame = sys._getframe(1)
|
| 734 |
+
_globs_ = frame.f_globals
|
| 735 |
+
if _locs_ is None:
|
| 736 |
+
_locs_ = frame.f_locals
|
| 737 |
+
del frame
|
| 738 |
+
elif _locs_ is None:
|
| 739 |
+
_locs_ = _globs_
|
| 740 |
+
exec("""exec _code_ in _globs_, _locs_""")
|
| 741 |
+
|
| 742 |
+
exec_("""def reraise(tp, value, tb=None):
|
| 743 |
+
try:
|
| 744 |
+
raise tp, value, tb
|
| 745 |
+
finally:
|
| 746 |
+
tb = None
|
| 747 |
+
""")
|
| 748 |
+
|
| 749 |
+
|
| 750 |
+
if sys.version_info[:2] > (3,):
|
| 751 |
+
exec_("""def raise_from(value, from_value):
|
| 752 |
+
try:
|
| 753 |
+
raise value from from_value
|
| 754 |
+
finally:
|
| 755 |
+
value = None
|
| 756 |
+
""")
|
| 757 |
+
else:
|
| 758 |
+
def raise_from(value, from_value):
|
| 759 |
+
raise value
|
| 760 |
+
|
| 761 |
+
|
| 762 |
+
print_ = getattr(moves.builtins, "print", None)
|
| 763 |
+
if print_ is None:
|
| 764 |
+
def print_(*args, **kwargs):
|
| 765 |
+
"""The new-style print function for Python 2.4 and 2.5."""
|
| 766 |
+
fp = kwargs.pop("file", sys.stdout)
|
| 767 |
+
if fp is None:
|
| 768 |
+
return
|
| 769 |
+
|
| 770 |
+
def write(data):
|
| 771 |
+
if not isinstance(data, basestring):
|
| 772 |
+
data = str(data)
|
| 773 |
+
# If the file has an encoding, encode unicode with it.
|
| 774 |
+
if (isinstance(fp, file) and
|
| 775 |
+
isinstance(data, unicode) and
|
| 776 |
+
fp.encoding is not None):
|
| 777 |
+
errors = getattr(fp, "errors", None)
|
| 778 |
+
if errors is None:
|
| 779 |
+
errors = "strict"
|
| 780 |
+
data = data.encode(fp.encoding, errors)
|
| 781 |
+
fp.write(data)
|
| 782 |
+
want_unicode = False
|
| 783 |
+
sep = kwargs.pop("sep", None)
|
| 784 |
+
if sep is not None:
|
| 785 |
+
if isinstance(sep, unicode):
|
| 786 |
+
want_unicode = True
|
| 787 |
+
elif not isinstance(sep, str):
|
| 788 |
+
raise TypeError("sep must be None or a string")
|
| 789 |
+
end = kwargs.pop("end", None)
|
| 790 |
+
if end is not None:
|
| 791 |
+
if isinstance(end, unicode):
|
| 792 |
+
want_unicode = True
|
| 793 |
+
elif not isinstance(end, str):
|
| 794 |
+
raise TypeError("end must be None or a string")
|
| 795 |
+
if kwargs:
|
| 796 |
+
raise TypeError("invalid keyword arguments to print()")
|
| 797 |
+
if not want_unicode:
|
| 798 |
+
for arg in args:
|
| 799 |
+
if isinstance(arg, unicode):
|
| 800 |
+
want_unicode = True
|
| 801 |
+
break
|
| 802 |
+
if want_unicode:
|
| 803 |
+
newline = unicode("\n")
|
| 804 |
+
space = unicode(" ")
|
| 805 |
+
else:
|
| 806 |
+
newline = "\n"
|
| 807 |
+
space = " "
|
| 808 |
+
if sep is None:
|
| 809 |
+
sep = space
|
| 810 |
+
if end is None:
|
| 811 |
+
end = newline
|
| 812 |
+
for i, arg in enumerate(args):
|
| 813 |
+
if i:
|
| 814 |
+
write(sep)
|
| 815 |
+
write(arg)
|
| 816 |
+
write(end)
|
| 817 |
+
if sys.version_info[:2] < (3, 3):
|
| 818 |
+
_print = print_
|
| 819 |
+
|
| 820 |
+
def print_(*args, **kwargs):
|
| 821 |
+
fp = kwargs.get("file", sys.stdout)
|
| 822 |
+
flush = kwargs.pop("flush", False)
|
| 823 |
+
_print(*args, **kwargs)
|
| 824 |
+
if flush and fp is not None:
|
| 825 |
+
fp.flush()
|
| 826 |
+
|
| 827 |
+
_add_doc(reraise, """Reraise an exception.""")
|
| 828 |
+
|
| 829 |
+
if sys.version_info[0:2] < (3, 4):
|
| 830 |
+
# This does exactly the same what the :func:`py3:functools.update_wrapper`
|
| 831 |
+
# function does on Python versions after 3.2. It sets the ``__wrapped__``
|
| 832 |
+
# attribute on ``wrapper`` object and it doesn't raise an error if any of
|
| 833 |
+
# the attributes mentioned in ``assigned`` and ``updated`` are missing on
|
| 834 |
+
# ``wrapped`` object.
|
| 835 |
+
def _update_wrapper(wrapper, wrapped,
|
| 836 |
+
assigned=functools.WRAPPER_ASSIGNMENTS,
|
| 837 |
+
updated=functools.WRAPPER_UPDATES):
|
| 838 |
+
for attr in assigned:
|
| 839 |
+
try:
|
| 840 |
+
value = getattr(wrapped, attr)
|
| 841 |
+
except AttributeError:
|
| 842 |
+
continue
|
| 843 |
+
else:
|
| 844 |
+
setattr(wrapper, attr, value)
|
| 845 |
+
for attr in updated:
|
| 846 |
+
getattr(wrapper, attr).update(getattr(wrapped, attr, {}))
|
| 847 |
+
wrapper.__wrapped__ = wrapped
|
| 848 |
+
return wrapper
|
| 849 |
+
_update_wrapper.__doc__ = functools.update_wrapper.__doc__
|
| 850 |
+
|
| 851 |
+
def wraps(wrapped, assigned=functools.WRAPPER_ASSIGNMENTS,
|
| 852 |
+
updated=functools.WRAPPER_UPDATES):
|
| 853 |
+
return functools.partial(_update_wrapper, wrapped=wrapped,
|
| 854 |
+
assigned=assigned, updated=updated)
|
| 855 |
+
wraps.__doc__ = functools.wraps.__doc__
|
| 856 |
+
|
| 857 |
+
else:
|
| 858 |
+
wraps = functools.wraps
|
| 859 |
+
|
| 860 |
+
|
| 861 |
+
def with_metaclass(meta, *bases):
|
| 862 |
+
"""Create a base class with a metaclass."""
|
| 863 |
+
# This requires a bit of explanation: the basic idea is to make a dummy
|
| 864 |
+
# metaclass for one level of class instantiation that replaces itself with
|
| 865 |
+
# the actual metaclass.
|
| 866 |
+
class metaclass(type):
|
| 867 |
+
|
| 868 |
+
def __new__(cls, name, this_bases, d):
|
| 869 |
+
if sys.version_info[:2] >= (3, 7):
|
| 870 |
+
# This version introduced PEP 560 that requires a bit
|
| 871 |
+
# of extra care (we mimic what is done by __build_class__).
|
| 872 |
+
resolved_bases = types.resolve_bases(bases)
|
| 873 |
+
if resolved_bases is not bases:
|
| 874 |
+
d['__orig_bases__'] = bases
|
| 875 |
+
else:
|
| 876 |
+
resolved_bases = bases
|
| 877 |
+
return meta(name, resolved_bases, d)
|
| 878 |
+
|
| 879 |
+
@classmethod
|
| 880 |
+
def __prepare__(cls, name, this_bases):
|
| 881 |
+
return meta.__prepare__(name, bases)
|
| 882 |
+
return type.__new__(metaclass, 'temporary_class', (), {})
|
| 883 |
+
|
| 884 |
+
|
| 885 |
+
def add_metaclass(metaclass):
|
| 886 |
+
"""Class decorator for creating a class with a metaclass."""
|
| 887 |
+
def wrapper(cls):
|
| 888 |
+
orig_vars = cls.__dict__.copy()
|
| 889 |
+
slots = orig_vars.get('__slots__')
|
| 890 |
+
if slots is not None:
|
| 891 |
+
if isinstance(slots, str):
|
| 892 |
+
slots = [slots]
|
| 893 |
+
for slots_var in slots:
|
| 894 |
+
orig_vars.pop(slots_var)
|
| 895 |
+
orig_vars.pop('__dict__', None)
|
| 896 |
+
orig_vars.pop('__weakref__', None)
|
| 897 |
+
if hasattr(cls, '__qualname__'):
|
| 898 |
+
orig_vars['__qualname__'] = cls.__qualname__
|
| 899 |
+
return metaclass(cls.__name__, cls.__bases__, orig_vars)
|
| 900 |
+
return wrapper
|
| 901 |
+
|
| 902 |
+
|
| 903 |
+
def ensure_binary(s, encoding='utf-8', errors='strict'):
|
| 904 |
+
"""Coerce **s** to six.binary_type.
|
| 905 |
+
|
| 906 |
+
For Python 2:
|
| 907 |
+
- `unicode` -> encoded to `str`
|
| 908 |
+
- `str` -> `str`
|
| 909 |
+
|
| 910 |
+
For Python 3:
|
| 911 |
+
- `str` -> encoded to `bytes`
|
| 912 |
+
- `bytes` -> `bytes`
|
| 913 |
+
"""
|
| 914 |
+
if isinstance(s, binary_type):
|
| 915 |
+
return s
|
| 916 |
+
if isinstance(s, text_type):
|
| 917 |
+
return s.encode(encoding, errors)
|
| 918 |
+
raise TypeError("not expecting type '%s'" % type(s))
|
| 919 |
+
|
| 920 |
+
|
| 921 |
+
def ensure_str(s, encoding='utf-8', errors='strict'):
|
| 922 |
+
"""Coerce *s* to `str`.
|
| 923 |
+
|
| 924 |
+
For Python 2:
|
| 925 |
+
- `unicode` -> encoded to `str`
|
| 926 |
+
- `str` -> `str`
|
| 927 |
+
|
| 928 |
+
For Python 3:
|
| 929 |
+
- `str` -> `str`
|
| 930 |
+
- `bytes` -> decoded to `str`
|
| 931 |
+
"""
|
| 932 |
+
# Optimization: Fast return for the common case.
|
| 933 |
+
if type(s) is str:
|
| 934 |
+
return s
|
| 935 |
+
if PY2 and isinstance(s, text_type):
|
| 936 |
+
return s.encode(encoding, errors)
|
| 937 |
+
elif PY3 and isinstance(s, binary_type):
|
| 938 |
+
return s.decode(encoding, errors)
|
| 939 |
+
elif not isinstance(s, (text_type, binary_type)):
|
| 940 |
+
raise TypeError("not expecting type '%s'" % type(s))
|
| 941 |
+
return s
|
| 942 |
+
|
| 943 |
+
|
| 944 |
+
def ensure_text(s, encoding='utf-8', errors='strict'):
|
| 945 |
+
"""Coerce *s* to six.text_type.
|
| 946 |
+
|
| 947 |
+
For Python 2:
|
| 948 |
+
- `unicode` -> `unicode`
|
| 949 |
+
- `str` -> `unicode`
|
| 950 |
+
|
| 951 |
+
For Python 3:
|
| 952 |
+
- `str` -> `str`
|
| 953 |
+
- `bytes` -> decoded to `str`
|
| 954 |
+
"""
|
| 955 |
+
if isinstance(s, binary_type):
|
| 956 |
+
return s.decode(encoding, errors)
|
| 957 |
+
elif isinstance(s, text_type):
|
| 958 |
+
return s
|
| 959 |
+
else:
|
| 960 |
+
raise TypeError("not expecting type '%s'" % type(s))
|
| 961 |
+
|
| 962 |
+
|
| 963 |
+
def python_2_unicode_compatible(klass):
|
| 964 |
+
"""
|
| 965 |
+
A class decorator that defines __unicode__ and __str__ methods under Python 2.
|
| 966 |
+
Under Python 3 it does nothing.
|
| 967 |
+
|
| 968 |
+
To support Python 2 and 3 with a single code base, define a __str__ method
|
| 969 |
+
returning text and apply this decorator to the class.
|
| 970 |
+
"""
|
| 971 |
+
if PY2:
|
| 972 |
+
if '__str__' not in klass.__dict__:
|
| 973 |
+
raise ValueError("@python_2_unicode_compatible cannot be applied "
|
| 974 |
+
"to %s because it doesn't define __str__()." %
|
| 975 |
+
klass.__name__)
|
| 976 |
+
klass.__unicode__ = klass.__str__
|
| 977 |
+
klass.__str__ = lambda self: self.__unicode__().encode('utf-8')
|
| 978 |
+
return klass
|
| 979 |
+
|
| 980 |
+
|
| 981 |
+
# Complete the moves implementation.
|
| 982 |
+
# This code is at the end of this module to speed up module loading.
|
| 983 |
+
# Turn this module into a package.
|
| 984 |
+
__path__ = [] # required for PEP 302 and PEP 451
|
| 985 |
+
__package__ = __name__ # see PEP 366 @ReservedAssignment
|
| 986 |
+
if globals().get("__spec__") is not None:
|
| 987 |
+
__spec__.submodule_search_locations = [] # PEP 451 @UndefinedVariable
|
| 988 |
+
# Remove other six meta path importers, since they cause problems. This can
|
| 989 |
+
# happen if six is removed from sys.modules and then reloaded. (Setuptools does
|
| 990 |
+
# this for some reason.)
|
| 991 |
+
if sys.meta_path:
|
| 992 |
+
for i, importer in enumerate(sys.meta_path):
|
| 993 |
+
# Here's some real nastiness: Another "instance" of the six module might
|
| 994 |
+
# be floating around. Therefore, we can't use isinstance() to check for
|
| 995 |
+
# the six meta path importer, since the other six instance will have
|
| 996 |
+
# inserted an importer with different class.
|
| 997 |
+
if (type(importer).__name__ == "_SixMetaPathImporter" and
|
| 998 |
+
importer.name == __name__):
|
| 999 |
+
del sys.meta_path[i]
|
| 1000 |
+
break
|
| 1001 |
+
del i, importer
|
| 1002 |
+
# Finally, add the importer to the meta path import hook.
|
| 1003 |
+
sys.meta_path.append(_importer)
|
.venv/lib/python3.13/site-packages/soupsieve-2.9.2.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pip
|
.venv/lib/python3.13/site-packages/soupsieve-2.9.2.dist-info/METADATA
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.4
|
| 2 |
+
Name: soupsieve
|
| 3 |
+
Version: 2.9.2
|
| 4 |
+
Summary: A modern CSS selector implementation for Beautiful Soup.
|
| 5 |
+
Project-URL: Homepage, https://github.com/facelessuser/soupsieve
|
| 6 |
+
Author-email: Isaac Muse <Isaac.Muse@gmail.com>
|
| 7 |
+
License-Expression: MIT
|
| 8 |
+
License-File: LICENSE.md
|
| 9 |
+
Keywords: CSS,HTML,XML,filter,query,selector,soup
|
| 10 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 11 |
+
Classifier: Environment :: Console
|
| 12 |
+
Classifier: Intended Audience :: Developers
|
| 13 |
+
Classifier: License :: OSI Approved :: MIT License
|
| 14 |
+
Classifier: Operating System :: OS Independent
|
| 15 |
+
Classifier: Programming Language :: Python :: 3
|
| 16 |
+
Classifier: Programming Language :: Python :: 3.10
|
| 17 |
+
Classifier: Programming Language :: Python :: 3.11
|
| 18 |
+
Classifier: Programming Language :: Python :: 3.12
|
| 19 |
+
Classifier: Programming Language :: Python :: 3.13
|
| 20 |
+
Classifier: Programming Language :: Python :: 3.14
|
| 21 |
+
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
|
| 22 |
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
| 23 |
+
Classifier: Typing :: Typed
|
| 24 |
+
Requires-Python: >=3.10
|
| 25 |
+
Description-Content-Type: text/markdown
|
| 26 |
+
|
| 27 |
+
[![Donate via PayPal][donate-image]][donate-link]
|
| 28 |
+
[![Build][github-ci-image]][github-ci-link]
|
| 29 |
+
[![Coverage Status][codecov-image]][codecov-link]
|
| 30 |
+
[![PyPI Version][pypi-image]][pypi-link]
|
| 31 |
+
[![PyPI Downloads][pypi-down]][pypi-link]
|
| 32 |
+
[![PyPI - Python Version][python-image]][pypi-link]
|
| 33 |
+
[![License][license-image-mit]][license-link]
|
| 34 |
+
|
| 35 |
+
# Soup Sieve
|
| 36 |
+
|
| 37 |
+
## Overview
|
| 38 |
+
|
| 39 |
+
Soup Sieve is a CSS selector library designed to be used with [Beautiful Soup 4][bs4]. It aims to provide selecting,
|
| 40 |
+
matching, and filtering using modern CSS selectors. Soup Sieve currently provides selectors from the CSS level 1
|
| 41 |
+
specifications up through the latest CSS level 4 drafts and beyond (though some are not yet implemented).
|
| 42 |
+
|
| 43 |
+
Soup Sieve was written with the intent to replace Beautiful Soup's builtin select feature, and as of Beautiful Soup
|
| 44 |
+
version 4.7.0, it now is :confetti_ball:. Soup Sieve can also be imported in order to use its API directly for
|
| 45 |
+
more controlled, specialized parsing.
|
| 46 |
+
|
| 47 |
+
Soup Sieve has implemented most of the CSS selectors up through the latest CSS draft specifications, though there are a
|
| 48 |
+
number that don't make sense in a non-browser environment. Selectors that cannot provide meaningful functionality simply
|
| 49 |
+
do not match anything. Some of the supported selectors are:
|
| 50 |
+
|
| 51 |
+
- `.classes`
|
| 52 |
+
- `#ids`
|
| 53 |
+
- `[attributes=value]`
|
| 54 |
+
- `parent child`
|
| 55 |
+
- `parent > child`
|
| 56 |
+
- `sibling ~ sibling`
|
| 57 |
+
- `sibling + sibling`
|
| 58 |
+
- `:not(element.class, element2.class)`
|
| 59 |
+
- `:is(element.class, element2.class)`
|
| 60 |
+
- `parent:has(> child)`
|
| 61 |
+
- and [many more](https://facelessuser.github.io/soupsieve/selectors/)
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
## Installation
|
| 65 |
+
|
| 66 |
+
You must have Beautiful Soup already installed:
|
| 67 |
+
|
| 68 |
+
```
|
| 69 |
+
pip install beautifulsoup4
|
| 70 |
+
```
|
| 71 |
+
|
| 72 |
+
In most cases, assuming you've installed version 4.7.0, that should be all you need to do, but if you've installed via
|
| 73 |
+
some alternative method, and Soup Sieve is not automatically installed, you can install it directly:
|
| 74 |
+
|
| 75 |
+
```
|
| 76 |
+
pip install soupsieve
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
If you want to manually install it from source, first ensure that [`build`](https://pypi.org/project/build/) is
|
| 80 |
+
installed:
|
| 81 |
+
|
| 82 |
+
```
|
| 83 |
+
pip install build
|
| 84 |
+
```
|
| 85 |
+
|
| 86 |
+
Then navigate to the root of the project and build the wheel and install (replacing `<ver>` with the current version):
|
| 87 |
+
|
| 88 |
+
```
|
| 89 |
+
python -m build -w
|
| 90 |
+
pip install dist/soupsieve-<ver>-py3-none-any.whl
|
| 91 |
+
```
|
| 92 |
+
|
| 93 |
+
## Documentation
|
| 94 |
+
|
| 95 |
+
Documentation is found here: https://facelessuser.github.io/soupsieve/.
|
| 96 |
+
|
| 97 |
+
## License
|
| 98 |
+
|
| 99 |
+
MIT
|
| 100 |
+
|
| 101 |
+
[bs4]: https://beautiful-soup-4.readthedocs.io/en/latest/#
|
| 102 |
+
|
| 103 |
+
[github-ci-image]: https://github.com/facelessuser/soupsieve/workflows/build/badge.svg
|
| 104 |
+
[github-ci-link]: https://github.com/facelessuser/soupsieve/actions?query=workflow%3Abuild+branch%3Amain
|
| 105 |
+
[codecov-image]: https://img.shields.io/codecov/c/github/facelessuser/soupsieve/master.svg?logo=codecov&logoColor=aaaaaa&labelColor=333333
|
| 106 |
+
[codecov-link]: https://codecov.io/github/facelessuser/soupsieve
|
| 107 |
+
[pypi-image]: https://img.shields.io/pypi/v/soupsieve.svg?logo=pypi&logoColor=aaaaaa&labelColor=333333
|
| 108 |
+
[pypi-down]: https://img.shields.io/pypi/dm/soupsieve.svg?logo=pypi&logoColor=aaaaaa&labelColor=333333
|
| 109 |
+
[pypi-link]: https://pypi.python.org/pypi/soupsieve
|
| 110 |
+
[python-image]: https://img.shields.io/pypi/pyversions/soupsieve?logo=python&logoColor=aaaaaa&labelColor=333333
|
| 111 |
+
[license-image-mit]: https://img.shields.io/badge/license-MIT-blue.svg?labelColor=333333
|
| 112 |
+
[license-link]: https://github.com/facelessuser/soupsieve/blob/main/LICENSE.md
|
| 113 |
+
[donate-image]: https://img.shields.io/badge/Donate-PayPal-3fabd1?logo=paypal
|
| 114 |
+
[donate-link]: https://www.paypal.me/facelessuser
|
.venv/lib/python3.13/site-packages/soupsieve-2.9.2.dist-info/RECORD
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
soupsieve-2.9.2.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
| 2 |
+
soupsieve-2.9.2.dist-info/METADATA,sha256=Ja3mWAgXOBZXpCt8GKqpAyI-tpZAG-PuqYUNPUoa8YI,4586
|
| 3 |
+
soupsieve-2.9.2.dist-info/RECORD,,
|
| 4 |
+
soupsieve-2.9.2.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
|
| 5 |
+
soupsieve-2.9.2.dist-info/licenses/LICENSE.md,sha256=dqCs25jDpjaB4gtvCWaZ74ytX7NdVu74OH4Ppx15epo,1096
|
| 6 |
+
soupsieve/__init__.py,sha256=FV4Ol2FRldy7rG94nQHNHoJTZIdQbUJdZkGhXkI3tiE,4581
|
| 7 |
+
soupsieve/__meta__.py,sha256=GWNjSuOoU3r23v6D1P38tEs-pavnOjiVpqEyOfDsMBk,6766
|
| 8 |
+
soupsieve/__pycache__/__init__.cpython-313.pyc,,
|
| 9 |
+
soupsieve/__pycache__/__meta__.cpython-313.pyc,,
|
| 10 |
+
soupsieve/__pycache__/css_match.cpython-313.pyc,,
|
| 11 |
+
soupsieve/__pycache__/css_parser.cpython-313.pyc,,
|
| 12 |
+
soupsieve/__pycache__/css_types.cpython-313.pyc,,
|
| 13 |
+
soupsieve/__pycache__/pretty.cpython-313.pyc,,
|
| 14 |
+
soupsieve/__pycache__/util.cpython-313.pyc,,
|
| 15 |
+
soupsieve/css_match.py,sha256=UmCH_ltakWVIDyyfKBs619ttpyw9nANbNVdkl3Z65TM,60276
|
| 16 |
+
soupsieve/css_parser.py,sha256=kqwBKDzFgxxHn_prd93D8oTaw00SkRtxdUf7jItTRas,48182
|
| 17 |
+
soupsieve/css_types.py,sha256=OxTs1p2bZK4nvPjJu-TVgPYVrMXnQwQ7RGq0cfzZwC0,10014
|
| 18 |
+
soupsieve/pretty.py,sha256=iSM-NKCzruJQCwEriQT72LrF4slxsib7TB552H2bsqA,4362
|
| 19 |
+
soupsieve/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 20 |
+
soupsieve/util.py,sha256=Q0MVH77cUBXMtKV0D2f8Syf90remPe0EfLqe6-msAeI,3352
|
.venv/lib/python3.13/site-packages/soupsieve-2.9.2.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: hatchling 1.31.0
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: py3-none-any
|
.venv/lib/python3.13/site-packages/soupsieve-2.9.2.dist-info/licenses/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2018 - 2026 Isaac Muse <isaacmuse@gmail.com>
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
.venv/lib/python3.13/site-packages/soupsieve/__init__.py
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Soup Sieve.
|
| 3 |
+
|
| 4 |
+
A CSS selector filter for BeautifulSoup4.
|
| 5 |
+
|
| 6 |
+
MIT License
|
| 7 |
+
|
| 8 |
+
Copyright (c) 2018 Isaac Muse
|
| 9 |
+
|
| 10 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 11 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 12 |
+
in the Software without restriction, including without limitation the rights
|
| 13 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 14 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 15 |
+
furnished to do so, subject to the following conditions:
|
| 16 |
+
|
| 17 |
+
The above copyright notice and this permission notice shall be included in all
|
| 18 |
+
copies or substantial portions of the Software.
|
| 19 |
+
|
| 20 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 21 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 22 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 23 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 24 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 25 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 26 |
+
SOFTWARE.
|
| 27 |
+
"""
|
| 28 |
+
from __future__ import annotations
|
| 29 |
+
from .__meta__ import __version__, __version_info__ # noqa: F401
|
| 30 |
+
from . import css_parser as cp
|
| 31 |
+
from . import css_match as cm
|
| 32 |
+
from . import css_types as ct
|
| 33 |
+
from .util import DEBUG, SelectorSyntaxError # noqa: F401
|
| 34 |
+
import bs4
|
| 35 |
+
from typing import Any, Iterator, Iterable
|
| 36 |
+
|
| 37 |
+
__all__ = (
|
| 38 |
+
'DEBUG', 'SelectorSyntaxError', 'SoupSieve',
|
| 39 |
+
'closest', 'compile', 'filter', 'iselect',
|
| 40 |
+
'match', 'select', 'select_one'
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
SoupSieve = cm.SoupSieve
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def compile( # noqa: A001
|
| 47 |
+
pattern: str,
|
| 48 |
+
namespaces: dict[str, str] | None = None,
|
| 49 |
+
flags: int = 0,
|
| 50 |
+
*,
|
| 51 |
+
custom: dict[str, str] | None = None,
|
| 52 |
+
**kwargs: Any
|
| 53 |
+
) -> cm.SoupSieve:
|
| 54 |
+
"""Compile CSS pattern."""
|
| 55 |
+
|
| 56 |
+
if isinstance(pattern, SoupSieve):
|
| 57 |
+
if flags:
|
| 58 |
+
raise ValueError("Cannot process 'flags' argument on a compiled selector list")
|
| 59 |
+
elif namespaces is not None:
|
| 60 |
+
raise ValueError("Cannot process 'namespaces' argument on a compiled selector list")
|
| 61 |
+
elif custom is not None:
|
| 62 |
+
raise ValueError("Cannot process 'custom' argument on a compiled selector list")
|
| 63 |
+
return pattern
|
| 64 |
+
|
| 65 |
+
return cp._cached_css_compile(
|
| 66 |
+
pattern,
|
| 67 |
+
ct.Namespaces(namespaces) if namespaces is not None else namespaces,
|
| 68 |
+
ct.CustomSelectors(custom) if custom is not None else custom,
|
| 69 |
+
flags
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def purge() -> None:
|
| 74 |
+
"""Purge cached patterns."""
|
| 75 |
+
|
| 76 |
+
cp._purge_cache()
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def closest(
|
| 80 |
+
select: str,
|
| 81 |
+
tag: bs4.Tag,
|
| 82 |
+
namespaces: dict[str, str] | None = None,
|
| 83 |
+
flags: int = 0,
|
| 84 |
+
*,
|
| 85 |
+
custom: dict[str, str] | None = None,
|
| 86 |
+
**kwargs: Any
|
| 87 |
+
) -> bs4.Tag | None:
|
| 88 |
+
"""Match closest ancestor."""
|
| 89 |
+
|
| 90 |
+
return compile(select, namespaces, flags, **kwargs).closest(tag)
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def match(
|
| 94 |
+
select: str,
|
| 95 |
+
tag: bs4.Tag,
|
| 96 |
+
namespaces: dict[str, str] | None = None,
|
| 97 |
+
flags: int = 0,
|
| 98 |
+
*,
|
| 99 |
+
custom: dict[str, str] | None = None,
|
| 100 |
+
**kwargs: Any
|
| 101 |
+
) -> bool:
|
| 102 |
+
"""Match node."""
|
| 103 |
+
|
| 104 |
+
return compile(select, namespaces, flags, **kwargs).match(tag)
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def filter( # noqa: A001
|
| 108 |
+
select: str,
|
| 109 |
+
iterable: Iterable[bs4.Tag],
|
| 110 |
+
namespaces: dict[str, str] | None = None,
|
| 111 |
+
flags: int = 0,
|
| 112 |
+
*,
|
| 113 |
+
custom: dict[str, str] | None = None,
|
| 114 |
+
**kwargs: Any
|
| 115 |
+
) -> list[bs4.Tag]:
|
| 116 |
+
"""Filter list of nodes."""
|
| 117 |
+
|
| 118 |
+
return compile(select, namespaces, flags, **kwargs).filter(iterable)
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
def select_one(
|
| 122 |
+
select: str,
|
| 123 |
+
tag: bs4.Tag,
|
| 124 |
+
namespaces: dict[str, str] | None = None,
|
| 125 |
+
flags: int = 0,
|
| 126 |
+
*,
|
| 127 |
+
custom: dict[str, str] | None = None,
|
| 128 |
+
**kwargs: Any
|
| 129 |
+
) -> bs4.Tag | None:
|
| 130 |
+
"""Select a single tag."""
|
| 131 |
+
|
| 132 |
+
return compile(select, namespaces, flags, **kwargs).select_one(tag)
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def select(
|
| 136 |
+
select: str,
|
| 137 |
+
tag: bs4.Tag,
|
| 138 |
+
namespaces: dict[str, str] | None = None,
|
| 139 |
+
limit: int = 0,
|
| 140 |
+
flags: int = 0,
|
| 141 |
+
*,
|
| 142 |
+
custom: dict[str, str] | None = None,
|
| 143 |
+
**kwargs: Any
|
| 144 |
+
) -> list[bs4.Tag]:
|
| 145 |
+
"""Select the specified tags."""
|
| 146 |
+
|
| 147 |
+
return compile(select, namespaces, flags, **kwargs).select(tag, limit)
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
def iselect(
|
| 151 |
+
select: str,
|
| 152 |
+
tag: bs4.Tag,
|
| 153 |
+
namespaces: dict[str, str] | None = None,
|
| 154 |
+
limit: int = 0,
|
| 155 |
+
flags: int = 0,
|
| 156 |
+
*,
|
| 157 |
+
custom: dict[str, str] | None = None,
|
| 158 |
+
**kwargs: Any
|
| 159 |
+
) -> Iterator[bs4.Tag]:
|
| 160 |
+
"""Iterate the specified tags."""
|
| 161 |
+
|
| 162 |
+
yield from compile(select, namespaces, flags, **kwargs).iselect(tag, limit)
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
def escape(ident: str) -> str:
|
| 166 |
+
"""Escape identifier."""
|
| 167 |
+
|
| 168 |
+
return cp.escape(ident)
|
.venv/lib/python3.13/site-packages/soupsieve/__meta__.py
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Meta related things."""
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
from collections import namedtuple
|
| 4 |
+
import re
|
| 5 |
+
|
| 6 |
+
RE_VER = re.compile(
|
| 7 |
+
r'''(?x)
|
| 8 |
+
(?P<major>\d+)(?:\.(?P<minor>\d+))?(?:\.(?P<micro>\d+))?
|
| 9 |
+
(?:(?P<type>a|b|rc)(?P<pre>\d+))?
|
| 10 |
+
(?:\.post(?P<post>\d+))?
|
| 11 |
+
(?:\.dev(?P<dev>\d+))?
|
| 12 |
+
'''
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
REL_MAP = {
|
| 16 |
+
".dev": "",
|
| 17 |
+
".dev-alpha": "a",
|
| 18 |
+
".dev-beta": "b",
|
| 19 |
+
".dev-candidate": "rc",
|
| 20 |
+
"alpha": "a",
|
| 21 |
+
"beta": "b",
|
| 22 |
+
"candidate": "rc",
|
| 23 |
+
"final": ""
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
DEV_STATUS = {
|
| 27 |
+
".dev": "2 - Pre-Alpha",
|
| 28 |
+
".dev-alpha": "2 - Pre-Alpha",
|
| 29 |
+
".dev-beta": "2 - Pre-Alpha",
|
| 30 |
+
".dev-candidate": "2 - Pre-Alpha",
|
| 31 |
+
"alpha": "3 - Alpha",
|
| 32 |
+
"beta": "4 - Beta",
|
| 33 |
+
"candidate": "4 - Beta",
|
| 34 |
+
"final": "5 - Production/Stable"
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
PRE_REL_MAP = {"a": 'alpha', "b": 'beta', "rc": 'candidate'}
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
class Version(namedtuple("Version", ["major", "minor", "micro", "release", "pre", "post", "dev"])):
|
| 41 |
+
"""
|
| 42 |
+
Get the version (PEP 440).
|
| 43 |
+
|
| 44 |
+
A biased approach to the PEP 440 semantic version.
|
| 45 |
+
|
| 46 |
+
Provides a tuple structure which is sorted for comparisons `v1 > v2` etc.
|
| 47 |
+
(major, minor, micro, release type, pre-release build, post-release build, development release build)
|
| 48 |
+
Release types are named in is such a way they are comparable with ease.
|
| 49 |
+
Accessors to check if a development, pre-release, or post-release build. Also provides accessor to get
|
| 50 |
+
development status for setup files.
|
| 51 |
+
|
| 52 |
+
How it works (currently):
|
| 53 |
+
|
| 54 |
+
- You must specify a release type as either `final`, `alpha`, `beta`, or `candidate`.
|
| 55 |
+
- To define a development release, you can use either `.dev`, `.dev-alpha`, `.dev-beta`, or `.dev-candidate`.
|
| 56 |
+
The dot is used to ensure all development specifiers are sorted before `alpha`.
|
| 57 |
+
You can specify a `dev` number for development builds, but do not have to as implicit development releases
|
| 58 |
+
are allowed.
|
| 59 |
+
- You must specify a `pre` value greater than zero if using a prerelease as this project (not PEP 440) does not
|
| 60 |
+
allow implicit prereleases.
|
| 61 |
+
- You can optionally set `post` to a value greater than zero to make the build a post release. While post releases
|
| 62 |
+
are technically allowed in prereleases, it is strongly discouraged, so we are rejecting them. It should be
|
| 63 |
+
noted that we do not allow `post0` even though PEP 440 does not restrict this. This project specifically
|
| 64 |
+
does not allow implicit post releases.
|
| 65 |
+
- It should be noted that we do not support epochs `1!` or local versions `+some-custom.version-1`.
|
| 66 |
+
|
| 67 |
+
Acceptable version releases:
|
| 68 |
+
|
| 69 |
+
```
|
| 70 |
+
Version(1, 0, 0, "final") 1.0
|
| 71 |
+
Version(1, 2, 0, "final") 1.2
|
| 72 |
+
Version(1, 2, 3, "final") 1.2.3
|
| 73 |
+
Version(1, 2, 0, ".dev-alpha", pre=4) 1.2a4
|
| 74 |
+
Version(1, 2, 0, ".dev-beta", pre=4) 1.2b4
|
| 75 |
+
Version(1, 2, 0, ".dev-candidate", pre=4) 1.2rc4
|
| 76 |
+
Version(1, 2, 0, "final", post=1) 1.2.post1
|
| 77 |
+
Version(1, 2, 3, ".dev") 1.2.3.dev0
|
| 78 |
+
Version(1, 2, 3, ".dev", dev=1) 1.2.3.dev1
|
| 79 |
+
```
|
| 80 |
+
|
| 81 |
+
"""
|
| 82 |
+
|
| 83 |
+
def __new__(
|
| 84 |
+
cls,
|
| 85 |
+
major: int, minor: int, micro: int, release: str = "final",
|
| 86 |
+
pre: int = 0, post: int = 0, dev: int = 0
|
| 87 |
+
) -> Version:
|
| 88 |
+
"""Validate version info."""
|
| 89 |
+
|
| 90 |
+
# Ensure all parts are positive integers.
|
| 91 |
+
for value in (major, minor, micro, pre, post):
|
| 92 |
+
if not (isinstance(value, int) and value >= 0):
|
| 93 |
+
raise ValueError("All version parts except 'release' should be integers.")
|
| 94 |
+
|
| 95 |
+
if release not in REL_MAP:
|
| 96 |
+
raise ValueError(f"'{release}' is not a valid release type.")
|
| 97 |
+
|
| 98 |
+
# Ensure valid pre-release (we do not allow implicit pre-releases).
|
| 99 |
+
if ".dev-candidate" < release < "final":
|
| 100 |
+
if pre == 0:
|
| 101 |
+
raise ValueError("Implicit pre-releases not allowed.")
|
| 102 |
+
elif dev:
|
| 103 |
+
raise ValueError("Version is not a development release.")
|
| 104 |
+
elif post:
|
| 105 |
+
raise ValueError("Post-releases are not allowed with pre-releases.")
|
| 106 |
+
|
| 107 |
+
# Ensure valid development or development/pre release
|
| 108 |
+
elif release < "alpha":
|
| 109 |
+
if release > ".dev" and pre == 0:
|
| 110 |
+
raise ValueError("Implicit pre-release not allowed.")
|
| 111 |
+
elif post:
|
| 112 |
+
raise ValueError("Post-releases are not allowed with pre-releases.")
|
| 113 |
+
|
| 114 |
+
# Ensure a valid normal release
|
| 115 |
+
else:
|
| 116 |
+
if pre:
|
| 117 |
+
raise ValueError("Version is not a pre-release.")
|
| 118 |
+
elif dev:
|
| 119 |
+
raise ValueError("Version is not a development release.")
|
| 120 |
+
|
| 121 |
+
return super().__new__(cls, major, minor, micro, release, pre, post, dev)
|
| 122 |
+
|
| 123 |
+
def _is_pre(self) -> bool:
|
| 124 |
+
"""Is prerelease."""
|
| 125 |
+
|
| 126 |
+
return bool(self.pre > 0)
|
| 127 |
+
|
| 128 |
+
def _is_dev(self) -> bool:
|
| 129 |
+
"""Is development."""
|
| 130 |
+
|
| 131 |
+
return bool(self.release < "alpha")
|
| 132 |
+
|
| 133 |
+
def _is_post(self) -> bool:
|
| 134 |
+
"""Is post."""
|
| 135 |
+
|
| 136 |
+
return bool(self.post > 0)
|
| 137 |
+
|
| 138 |
+
def _get_dev_status(self) -> str: # pragma: no cover
|
| 139 |
+
"""Get development status string."""
|
| 140 |
+
|
| 141 |
+
return DEV_STATUS[self.release]
|
| 142 |
+
|
| 143 |
+
def _get_canonical(self) -> str:
|
| 144 |
+
"""Get the canonical output string."""
|
| 145 |
+
|
| 146 |
+
# Assemble major, minor, micro version and append `pre`, `post`, or `dev` if needed..
|
| 147 |
+
if self.micro == 0:
|
| 148 |
+
ver = f"{self.major}.{self.minor}"
|
| 149 |
+
else:
|
| 150 |
+
ver = f"{self.major}.{self.minor}.{self.micro}"
|
| 151 |
+
if self._is_pre():
|
| 152 |
+
ver += f'{REL_MAP[self.release]}{self.pre}'
|
| 153 |
+
if self._is_post():
|
| 154 |
+
ver += f".post{self.post}"
|
| 155 |
+
if self._is_dev():
|
| 156 |
+
ver += f".dev{self.dev}"
|
| 157 |
+
|
| 158 |
+
return ver
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
def parse_version(ver: str) -> Version:
|
| 162 |
+
"""Parse version into a comparable Version tuple."""
|
| 163 |
+
|
| 164 |
+
m = RE_VER.match(ver)
|
| 165 |
+
|
| 166 |
+
if m is None:
|
| 167 |
+
raise ValueError(f"'{ver}' is not a valid version")
|
| 168 |
+
|
| 169 |
+
# Handle major, minor, micro
|
| 170 |
+
major = int(m.group('major'))
|
| 171 |
+
minor = int(m.group('minor')) if m.group('minor') else 0
|
| 172 |
+
micro = int(m.group('micro')) if m.group('micro') else 0
|
| 173 |
+
|
| 174 |
+
# Handle pre releases
|
| 175 |
+
if m.group('type'):
|
| 176 |
+
release = PRE_REL_MAP[m.group('type')]
|
| 177 |
+
pre = int(m.group('pre'))
|
| 178 |
+
else:
|
| 179 |
+
release = "final"
|
| 180 |
+
pre = 0
|
| 181 |
+
|
| 182 |
+
# Handle development releases
|
| 183 |
+
dev = m.group('dev') if m.group('dev') else 0
|
| 184 |
+
if m.group('dev'):
|
| 185 |
+
dev = int(m.group('dev'))
|
| 186 |
+
release = '.dev-' + release if pre else '.dev'
|
| 187 |
+
else:
|
| 188 |
+
dev = 0
|
| 189 |
+
|
| 190 |
+
# Handle post
|
| 191 |
+
post = int(m.group('post')) if m.group('post') else 0
|
| 192 |
+
|
| 193 |
+
return Version(major, minor, micro, release, pre, post, dev)
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
__version_info__ = Version(2, 9, 2, "final")
|
| 197 |
+
__version__ = __version_info__._get_canonical()
|
.venv/lib/python3.13/site-packages/soupsieve/css_match.py
ADDED
|
@@ -0,0 +1,1628 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""CSS matcher."""
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
from datetime import datetime
|
| 4 |
+
from . import util
|
| 5 |
+
import re
|
| 6 |
+
from . import css_types as ct
|
| 7 |
+
import unicodedata
|
| 8 |
+
import bs4
|
| 9 |
+
from typing import Iterator, Iterable, Any, Callable, Sequence, Any, cast # noqa: F401, F811
|
| 10 |
+
|
| 11 |
+
# Empty tag pattern (whitespace okay)
|
| 12 |
+
RE_NOT_EMPTY = re.compile('[^ \t\r\n\f]')
|
| 13 |
+
|
| 14 |
+
RE_NOT_WS = re.compile('[^ \t\r\n\f]+')
|
| 15 |
+
|
| 16 |
+
# Relationships
|
| 17 |
+
REL_PARENT = ' '
|
| 18 |
+
REL_CLOSE_PARENT = '>'
|
| 19 |
+
REL_SIBLING = '~'
|
| 20 |
+
REL_CLOSE_SIBLING = '+'
|
| 21 |
+
|
| 22 |
+
# Relationships for :has() (forward looking)
|
| 23 |
+
REL_HAS_PARENT = ': '
|
| 24 |
+
REL_HAS_CLOSE_PARENT = ':>'
|
| 25 |
+
REL_HAS_SIBLING = ':~'
|
| 26 |
+
REL_HAS_CLOSE_SIBLING = ':+'
|
| 27 |
+
|
| 28 |
+
NS_XHTML = 'http://www.w3.org/1999/xhtml'
|
| 29 |
+
NS_XML = 'http://www.w3.org/XML/1998/namespace'
|
| 30 |
+
|
| 31 |
+
DIR_FLAGS = ct.SEL_DIR_LTR | ct.SEL_DIR_RTL
|
| 32 |
+
RANGES = ct.SEL_IN_RANGE | ct.SEL_OUT_OF_RANGE
|
| 33 |
+
|
| 34 |
+
DIR_MAP = {
|
| 35 |
+
'ltr': ct.SEL_DIR_LTR,
|
| 36 |
+
'rtl': ct.SEL_DIR_RTL,
|
| 37 |
+
'auto': 0
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
RE_NUM = re.compile(r"^(?P<value>-?(?:[0-9]{1,}(\.[0-9]+)?|\.[0-9]+))$")
|
| 41 |
+
RE_TIME = re.compile(r'^(?P<hour>[0-9]{2}):(?P<minutes>[0-9]{2})$')
|
| 42 |
+
RE_MONTH = re.compile(r'^(?P<year>[0-9]{4,})-(?P<month>[0-9]{2})$')
|
| 43 |
+
RE_WEEK = re.compile(r'^(?P<year>[0-9]{4,})-W(?P<week>[0-9]{2})$')
|
| 44 |
+
RE_DATE = re.compile(r'^(?P<year>[0-9]{4,})-(?P<month>[0-9]{2})-(?P<day>[0-9]{2})$')
|
| 45 |
+
RE_DATETIME = re.compile(
|
| 46 |
+
r'^(?P<year>[0-9]{4,})-(?P<month>[0-9]{2})-(?P<day>[0-9]{2})T(?P<hour>[0-9]{2}):(?P<minutes>[0-9]{2})$'
|
| 47 |
+
)
|
| 48 |
+
RE_WILD_STRIP = re.compile(r'(?:(?:-\*-)(?:\*(?:-|$))*|-\*$)')
|
| 49 |
+
|
| 50 |
+
MONTHS_30 = (4, 6, 9, 11) # April, June, September, and November
|
| 51 |
+
FEB = 2
|
| 52 |
+
SHORT_MONTH = 30
|
| 53 |
+
LONG_MONTH = 31
|
| 54 |
+
FEB_MONTH = 28
|
| 55 |
+
FEB_LEAP_MONTH = 29
|
| 56 |
+
DAYS_IN_WEEK = 7
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
class _FakeParent:
|
| 60 |
+
"""
|
| 61 |
+
Fake parent class.
|
| 62 |
+
|
| 63 |
+
When we have a fragment with no `BeautifulSoup` document object,
|
| 64 |
+
we can't evaluate `nth` selectors properly. Create a temporary
|
| 65 |
+
fake parent so we can traverse the root element as a child.
|
| 66 |
+
"""
|
| 67 |
+
|
| 68 |
+
def __init__(self, element: bs4.Tag) -> None:
|
| 69 |
+
"""Initialize."""
|
| 70 |
+
|
| 71 |
+
self.contents = [element]
|
| 72 |
+
|
| 73 |
+
def __len__(self) -> int:
|
| 74 |
+
"""Length."""
|
| 75 |
+
|
| 76 |
+
return len(self.contents)
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
class _DocumentNav:
|
| 80 |
+
"""Navigate a Beautiful Soup document."""
|
| 81 |
+
|
| 82 |
+
@classmethod
|
| 83 |
+
def assert_valid_input(cls, tag: Any) -> None:
|
| 84 |
+
"""Check if valid input tag or document."""
|
| 85 |
+
|
| 86 |
+
# Fail on unexpected types.
|
| 87 |
+
if not cls.is_tag(tag):
|
| 88 |
+
raise TypeError(f"Expected a BeautifulSoup 'Tag', but instead received type {type(tag)}")
|
| 89 |
+
|
| 90 |
+
@staticmethod
|
| 91 |
+
def is_doc(obj: bs4.element.PageElement | None) -> bool:
|
| 92 |
+
"""Is `BeautifulSoup` object."""
|
| 93 |
+
return isinstance(obj, bs4.BeautifulSoup)
|
| 94 |
+
|
| 95 |
+
@staticmethod
|
| 96 |
+
def is_tag(obj: bs4.element.PageElement | None) -> bool:
|
| 97 |
+
"""Is tag."""
|
| 98 |
+
return isinstance(obj, bs4.Tag)
|
| 99 |
+
|
| 100 |
+
@staticmethod
|
| 101 |
+
def is_declaration(obj: bs4.element.PageElement | None) -> bool: # pragma: no cover
|
| 102 |
+
"""Is declaration."""
|
| 103 |
+
return isinstance(obj, bs4.Declaration)
|
| 104 |
+
|
| 105 |
+
@staticmethod
|
| 106 |
+
def is_cdata(obj: bs4.element.PageElement | None) -> bool:
|
| 107 |
+
"""Is CDATA."""
|
| 108 |
+
return isinstance(obj, bs4.CData)
|
| 109 |
+
|
| 110 |
+
@staticmethod
|
| 111 |
+
def is_processing_instruction(obj: bs4.element.PageElement | None) -> bool: # pragma: no cover
|
| 112 |
+
"""Is processing instruction."""
|
| 113 |
+
return isinstance(obj, bs4.ProcessingInstruction)
|
| 114 |
+
|
| 115 |
+
@staticmethod
|
| 116 |
+
def is_navigable_string(obj: bs4.element.PageElement | None) -> bool:
|
| 117 |
+
"""Is navigable string."""
|
| 118 |
+
return isinstance(obj, bs4.element.NavigableString)
|
| 119 |
+
|
| 120 |
+
@staticmethod
|
| 121 |
+
def is_special_string(obj: bs4.element.PageElement | None) -> bool:
|
| 122 |
+
"""Is special string."""
|
| 123 |
+
return isinstance(obj, (bs4.Comment, bs4.Declaration, bs4.CData, bs4.ProcessingInstruction, bs4.Doctype))
|
| 124 |
+
|
| 125 |
+
@classmethod
|
| 126 |
+
def is_content_string(cls, obj: bs4.element.PageElement | None) -> bool:
|
| 127 |
+
"""Check if node is content string."""
|
| 128 |
+
|
| 129 |
+
return cls.is_navigable_string(obj) and not cls.is_special_string(obj)
|
| 130 |
+
|
| 131 |
+
@staticmethod
|
| 132 |
+
def create_fake_parent(el: bs4.Tag) -> _FakeParent:
|
| 133 |
+
"""Create fake parent for a given element."""
|
| 134 |
+
|
| 135 |
+
return _FakeParent(el)
|
| 136 |
+
|
| 137 |
+
@staticmethod
|
| 138 |
+
def is_xml_tree(el: bs4.Tag | None) -> bool:
|
| 139 |
+
"""Check if element (or document) is from a XML tree."""
|
| 140 |
+
|
| 141 |
+
return el is not None and bool(el._is_xml)
|
| 142 |
+
|
| 143 |
+
def is_iframe(self, el: bs4.Tag | None) -> bool:
|
| 144 |
+
"""Check if element is an `iframe`."""
|
| 145 |
+
|
| 146 |
+
if el is None: # pragma: no cover
|
| 147 |
+
return False
|
| 148 |
+
|
| 149 |
+
return bool(
|
| 150 |
+
((el.name if self.is_xml_tree(el) else util.lower(el.name)) == 'iframe') and
|
| 151 |
+
self.is_html_tag(el) # type: ignore[attr-defined]
|
| 152 |
+
)
|
| 153 |
+
|
| 154 |
+
def is_root(self, el: bs4.Tag) -> bool:
|
| 155 |
+
"""
|
| 156 |
+
Return whether element is a root element.
|
| 157 |
+
|
| 158 |
+
We check that the element is the root of the tree (which we have already pre-calculated),
|
| 159 |
+
and we check if it is the root element under an `iframe`.
|
| 160 |
+
"""
|
| 161 |
+
|
| 162 |
+
root = self.root and self.root is el # type: ignore[attr-defined]
|
| 163 |
+
if not root:
|
| 164 |
+
parent = self.get_parent(el)
|
| 165 |
+
root = parent is not None and self.is_html and self.is_iframe(parent) # type: ignore[attr-defined]
|
| 166 |
+
return root
|
| 167 |
+
|
| 168 |
+
def get_contents(self, el: bs4.Tag | None, no_iframe: bool = False) -> Iterator[bs4.element.PageElement]:
|
| 169 |
+
"""Get contents or contents in reverse."""
|
| 170 |
+
|
| 171 |
+
if el is not None:
|
| 172 |
+
if not no_iframe or not self.is_iframe(el):
|
| 173 |
+
yield from el.contents
|
| 174 |
+
|
| 175 |
+
def get_tag_children(
|
| 176 |
+
self,
|
| 177 |
+
el: bs4.Tag | None,
|
| 178 |
+
start: int | None = None,
|
| 179 |
+
reverse: bool = False,
|
| 180 |
+
no_iframe: bool = False
|
| 181 |
+
) -> Iterator[bs4.Tag]:
|
| 182 |
+
"""Get tag children."""
|
| 183 |
+
|
| 184 |
+
return self.get_children(el, start, reverse, True, no_iframe) # type: ignore[return-value]
|
| 185 |
+
|
| 186 |
+
def get_children(
|
| 187 |
+
self,
|
| 188 |
+
el: bs4.Tag | None,
|
| 189 |
+
start: int | None = None,
|
| 190 |
+
reverse: bool = False,
|
| 191 |
+
tags: bool = False,
|
| 192 |
+
no_iframe: bool = False
|
| 193 |
+
) -> Iterator[bs4.element.PageElement]:
|
| 194 |
+
"""Get children."""
|
| 195 |
+
|
| 196 |
+
if el is not None and (not no_iframe or not self.is_iframe(el)):
|
| 197 |
+
last = len(el.contents) - 1
|
| 198 |
+
if start is None:
|
| 199 |
+
index = last if reverse else 0
|
| 200 |
+
else:
|
| 201 |
+
index = start
|
| 202 |
+
end = -1 if reverse else last + 1
|
| 203 |
+
incr = -1 if reverse else 1
|
| 204 |
+
|
| 205 |
+
if 0 <= index <= last:
|
| 206 |
+
while index != end:
|
| 207 |
+
node = el.contents[index]
|
| 208 |
+
index += incr
|
| 209 |
+
if not tags or self.is_tag(node):
|
| 210 |
+
yield node
|
| 211 |
+
|
| 212 |
+
def get_tag_descendants(
|
| 213 |
+
self,
|
| 214 |
+
el: bs4.Tag | None,
|
| 215 |
+
no_iframe: bool = False
|
| 216 |
+
) -> Iterator[bs4.Tag]:
|
| 217 |
+
"""Specifically get tag descendants."""
|
| 218 |
+
|
| 219 |
+
yield from self.get_descendants(el, tags=True, no_iframe=no_iframe) # type: ignore[misc]
|
| 220 |
+
|
| 221 |
+
def get_descendants(
|
| 222 |
+
self,
|
| 223 |
+
el: bs4.Tag | None,
|
| 224 |
+
tags: bool = False,
|
| 225 |
+
no_iframe: bool = False
|
| 226 |
+
) -> Iterator[bs4.element.PageElement]:
|
| 227 |
+
"""Get descendants."""
|
| 228 |
+
|
| 229 |
+
if el is not None and (not no_iframe or not self.is_iframe(el)):
|
| 230 |
+
next_good = None
|
| 231 |
+
for child in el.descendants:
|
| 232 |
+
|
| 233 |
+
if next_good is not None:
|
| 234 |
+
if child is not next_good:
|
| 235 |
+
continue
|
| 236 |
+
next_good = None
|
| 237 |
+
|
| 238 |
+
if isinstance(child, bs4.Tag):
|
| 239 |
+
if no_iframe and self.is_iframe(child):
|
| 240 |
+
if child.next_sibling is not None:
|
| 241 |
+
next_good = child.next_sibling
|
| 242 |
+
else:
|
| 243 |
+
last_child = child # type: bs4.element.PageElement
|
| 244 |
+
while isinstance(last_child, bs4.Tag) and last_child.contents:
|
| 245 |
+
last_child = last_child.contents[-1]
|
| 246 |
+
next_good = last_child.next_element
|
| 247 |
+
yield child
|
| 248 |
+
if next_good is None:
|
| 249 |
+
break
|
| 250 |
+
# Coverage isn't seeing this even though it's executed
|
| 251 |
+
continue # pragma: no cover
|
| 252 |
+
yield child
|
| 253 |
+
|
| 254 |
+
elif not tags:
|
| 255 |
+
yield child
|
| 256 |
+
|
| 257 |
+
def get_parent(self, el: bs4.Tag | None, no_iframe: bool = False) -> bs4.Tag | None:
|
| 258 |
+
"""Get parent."""
|
| 259 |
+
|
| 260 |
+
parent = el.parent if el is not None else None
|
| 261 |
+
if no_iframe and parent is not None and self.is_iframe(parent): # pragma: no cover
|
| 262 |
+
parent = None
|
| 263 |
+
return parent
|
| 264 |
+
|
| 265 |
+
@staticmethod
|
| 266 |
+
def get_tag_name(el: bs4.Tag | None) -> str | None:
|
| 267 |
+
"""Get tag."""
|
| 268 |
+
|
| 269 |
+
return el.name if el is not None else None
|
| 270 |
+
|
| 271 |
+
@staticmethod
|
| 272 |
+
def get_prefix_name(el: bs4.Tag) -> str | None:
|
| 273 |
+
"""Get prefix."""
|
| 274 |
+
|
| 275 |
+
return el.prefix
|
| 276 |
+
|
| 277 |
+
@staticmethod
|
| 278 |
+
def get_uri(el: bs4.Tag | None) -> str | None:
|
| 279 |
+
"""Get namespace `URI`."""
|
| 280 |
+
|
| 281 |
+
return el.namespace if el is not None else None
|
| 282 |
+
|
| 283 |
+
@classmethod
|
| 284 |
+
def get_next_tag(cls, el: bs4.Tag) -> bs4.Tag | None:
|
| 285 |
+
"""Get next sibling tag."""
|
| 286 |
+
|
| 287 |
+
return cls.get_next(el, tags=True) # type: ignore[return-value]
|
| 288 |
+
|
| 289 |
+
@classmethod
|
| 290 |
+
def get_next(cls, el: bs4.Tag, tags: bool = False) -> bs4.element.PageElement | None:
|
| 291 |
+
"""Get next sibling tag."""
|
| 292 |
+
|
| 293 |
+
sibling = el.next_sibling
|
| 294 |
+
while tags and not isinstance(sibling, bs4.Tag) and sibling is not None:
|
| 295 |
+
sibling = sibling.next_sibling
|
| 296 |
+
|
| 297 |
+
if tags and not isinstance(sibling, bs4.Tag):
|
| 298 |
+
sibling = None
|
| 299 |
+
|
| 300 |
+
return sibling
|
| 301 |
+
|
| 302 |
+
@classmethod
|
| 303 |
+
def get_previous_tag(cls, el: bs4.Tag, tags: bool = True) -> bs4.Tag | None:
|
| 304 |
+
"""Get previous sibling tag."""
|
| 305 |
+
|
| 306 |
+
return cls.get_previous(el, True) # type: ignore[return-value]
|
| 307 |
+
|
| 308 |
+
@classmethod
|
| 309 |
+
def get_previous(cls, el: bs4.Tag, tags: bool = False) -> bs4.element.PageElement | None:
|
| 310 |
+
"""Get previous sibling tag."""
|
| 311 |
+
|
| 312 |
+
sibling = el.previous_sibling
|
| 313 |
+
while tags and not isinstance(sibling, bs4.Tag) and sibling is not None:
|
| 314 |
+
sibling = sibling.previous_sibling
|
| 315 |
+
|
| 316 |
+
if tags and not isinstance(sibling, bs4.Tag):
|
| 317 |
+
sibling = None
|
| 318 |
+
|
| 319 |
+
return sibling
|
| 320 |
+
|
| 321 |
+
@staticmethod
|
| 322 |
+
def has_html_ns(el: bs4.Tag | None) -> bool:
|
| 323 |
+
"""
|
| 324 |
+
Check if element has an HTML namespace.
|
| 325 |
+
|
| 326 |
+
This is a bit different than whether a element is treated as having an HTML namespace,
|
| 327 |
+
like we do in the case of `is_html_tag`.
|
| 328 |
+
"""
|
| 329 |
+
|
| 330 |
+
ns = getattr(el, 'namespace') if el is not None else None # noqa: B009
|
| 331 |
+
return bool(ns and ns == NS_XHTML)
|
| 332 |
+
|
| 333 |
+
@staticmethod
|
| 334 |
+
def split_namespace(el: bs4.Tag | None, attr_name: str) -> tuple[str | None, str | None]:
|
| 335 |
+
"""Return namespace and attribute name without the prefix."""
|
| 336 |
+
|
| 337 |
+
if el is None: # pragma: no cover
|
| 338 |
+
return None, None
|
| 339 |
+
|
| 340 |
+
return getattr(attr_name, 'namespace', None), getattr(attr_name, 'name', None)
|
| 341 |
+
|
| 342 |
+
@classmethod
|
| 343 |
+
def normalize_value(cls, value: Any) -> str | Sequence[str]:
|
| 344 |
+
"""Normalize the value to be a string or list of strings."""
|
| 345 |
+
|
| 346 |
+
# Treat `None` as empty string.
|
| 347 |
+
if value is None:
|
| 348 |
+
return ''
|
| 349 |
+
|
| 350 |
+
# Pass through strings
|
| 351 |
+
if (isinstance(value, str)):
|
| 352 |
+
return value
|
| 353 |
+
|
| 354 |
+
# If it's a byte string, convert it to Unicode, treating it as UTF-8.
|
| 355 |
+
if isinstance(value, bytes):
|
| 356 |
+
return value.decode("utf8")
|
| 357 |
+
|
| 358 |
+
# BeautifulSoup supports sequences of attribute values, so make sure the children are strings.
|
| 359 |
+
if isinstance(value, Sequence):
|
| 360 |
+
new_value = []
|
| 361 |
+
for v in value:
|
| 362 |
+
if not isinstance(v, (str, bytes)) and isinstance(v, Sequence):
|
| 363 |
+
# This is most certainly a user error and will crash and burn later.
|
| 364 |
+
# To keep things working, we'll do what we do with all objects,
|
| 365 |
+
# And convert them to strings.
|
| 366 |
+
new_value.append(str(v))
|
| 367 |
+
else:
|
| 368 |
+
# Convert the child to a string
|
| 369 |
+
new_value.append(cast(str, cls.normalize_value(v)))
|
| 370 |
+
return new_value
|
| 371 |
+
|
| 372 |
+
# Try and make anything else a string
|
| 373 |
+
return str(value)
|
| 374 |
+
|
| 375 |
+
@classmethod
|
| 376 |
+
def get_attribute_by_name(
|
| 377 |
+
cls,
|
| 378 |
+
el: bs4.Tag,
|
| 379 |
+
name: str,
|
| 380 |
+
default: str | Sequence[str] | None = None
|
| 381 |
+
) -> str | Sequence[str] | None:
|
| 382 |
+
"""Get attribute by name."""
|
| 383 |
+
|
| 384 |
+
value = default
|
| 385 |
+
if el._is_xml:
|
| 386 |
+
try:
|
| 387 |
+
value = cls.normalize_value(el.attrs[name])
|
| 388 |
+
except KeyError:
|
| 389 |
+
pass
|
| 390 |
+
else:
|
| 391 |
+
for k, v in el.attrs.items():
|
| 392 |
+
if util.lower(k) == name:
|
| 393 |
+
value = cls.normalize_value(v)
|
| 394 |
+
break
|
| 395 |
+
return value
|
| 396 |
+
|
| 397 |
+
@classmethod
|
| 398 |
+
def iter_attributes(cls, el: bs4.Tag | None) -> Iterator[tuple[str, str | Sequence[str] | None]]:
|
| 399 |
+
"""Iterate attributes."""
|
| 400 |
+
|
| 401 |
+
if el is not None:
|
| 402 |
+
for k, v in el.attrs.items():
|
| 403 |
+
yield k, cls.normalize_value(v)
|
| 404 |
+
|
| 405 |
+
@classmethod
|
| 406 |
+
def get_classes(cls, el: bs4.Tag) -> Sequence[str]:
|
| 407 |
+
"""Get classes."""
|
| 408 |
+
|
| 409 |
+
classes = cls.get_attribute_by_name(el, 'class', [])
|
| 410 |
+
if isinstance(classes, str):
|
| 411 |
+
classes = RE_NOT_WS.findall(classes)
|
| 412 |
+
return cast(Sequence[str], classes)
|
| 413 |
+
|
| 414 |
+
def get_text(self, el: bs4.Tag, no_iframe: bool = False) -> str:
|
| 415 |
+
"""Get text."""
|
| 416 |
+
|
| 417 |
+
return ''.join(
|
| 418 |
+
[
|
| 419 |
+
node for node in self.get_descendants(el, no_iframe=no_iframe) # type: ignore[misc]
|
| 420 |
+
if self.is_content_string(node)
|
| 421 |
+
]
|
| 422 |
+
)
|
| 423 |
+
|
| 424 |
+
def get_own_text(self, el: bs4.Tag, no_iframe: bool = False) -> list[str]:
|
| 425 |
+
"""Get Own Text."""
|
| 426 |
+
|
| 427 |
+
return [
|
| 428 |
+
node for node in self.get_contents(el, no_iframe=no_iframe) if self.is_content_string(node) # type: ignore[misc]
|
| 429 |
+
]
|
| 430 |
+
|
| 431 |
+
|
| 432 |
+
class Inputs:
|
| 433 |
+
"""Class for parsing and validating input items."""
|
| 434 |
+
|
| 435 |
+
@staticmethod
|
| 436 |
+
def validate_day(year: int, month: int, day: int) -> bool:
|
| 437 |
+
"""Validate day."""
|
| 438 |
+
|
| 439 |
+
max_days = LONG_MONTH
|
| 440 |
+
if month == FEB:
|
| 441 |
+
max_days = FEB_LEAP_MONTH if ((year % 4 == 0) and (year % 100 != 0)) or (year % 400 == 0) else FEB_MONTH
|
| 442 |
+
elif month in MONTHS_30:
|
| 443 |
+
max_days = SHORT_MONTH
|
| 444 |
+
return 1 <= day <= max_days
|
| 445 |
+
|
| 446 |
+
@staticmethod
|
| 447 |
+
def validate_week(year: int, week: int) -> bool:
|
| 448 |
+
"""Validate week."""
|
| 449 |
+
|
| 450 |
+
# Validate an ISO week number for `year`.
|
| 451 |
+
#
|
| 452 |
+
# Per ISO 8601 rules, the last ISO week of a year is the week
|
| 453 |
+
# containing Dec 28. Using Dec 28 guarantees we obtain the
|
| 454 |
+
# correct ISO week-number for the final week of `year`, even in
|
| 455 |
+
# years where Dec 31 falls in ISO week 01 of the following year.
|
| 456 |
+
#
|
| 457 |
+
# Example: if Dec 31 is a Thursday the year's last ISO week will
|
| 458 |
+
# be week 53; if Dec 31 is a Monday and that week is counted as
|
| 459 |
+
# week 1 of the next year, Dec 28 still belongs to the final
|
| 460 |
+
# week of the current ISO year and yields the correct max week.
|
| 461 |
+
max_week = datetime(year, 12, 28).isocalendar()[1]
|
| 462 |
+
return 1 <= week <= max_week
|
| 463 |
+
|
| 464 |
+
@staticmethod
|
| 465 |
+
def validate_month(month: int) -> bool:
|
| 466 |
+
"""Validate month."""
|
| 467 |
+
|
| 468 |
+
return 1 <= month <= 12
|
| 469 |
+
|
| 470 |
+
@staticmethod
|
| 471 |
+
def validate_year(year: int) -> bool:
|
| 472 |
+
"""Validate year."""
|
| 473 |
+
|
| 474 |
+
return 1 <= year
|
| 475 |
+
|
| 476 |
+
@staticmethod
|
| 477 |
+
def validate_hour(hour: int) -> bool:
|
| 478 |
+
"""Validate hour."""
|
| 479 |
+
|
| 480 |
+
return 0 <= hour <= 23
|
| 481 |
+
|
| 482 |
+
@staticmethod
|
| 483 |
+
def validate_minutes(minutes: int) -> bool:
|
| 484 |
+
"""Validate minutes."""
|
| 485 |
+
|
| 486 |
+
return 0 <= minutes <= 59
|
| 487 |
+
|
| 488 |
+
@classmethod
|
| 489 |
+
def parse_value(cls, itype: str, value: str | None) -> tuple[float, ...] | None:
|
| 490 |
+
"""Parse the input value."""
|
| 491 |
+
|
| 492 |
+
parsed = None # type: tuple[float, ...] | None
|
| 493 |
+
if value is None:
|
| 494 |
+
return value
|
| 495 |
+
if itype == "date":
|
| 496 |
+
m = RE_DATE.match(value)
|
| 497 |
+
if m:
|
| 498 |
+
year = int(m.group('year'), 10)
|
| 499 |
+
month = int(m.group('month'), 10)
|
| 500 |
+
day = int(m.group('day'), 10)
|
| 501 |
+
if cls.validate_year(year) and cls.validate_month(month) and cls.validate_day(year, month, day):
|
| 502 |
+
parsed = (year, month, day)
|
| 503 |
+
elif itype == "month":
|
| 504 |
+
m = RE_MONTH.match(value)
|
| 505 |
+
if m:
|
| 506 |
+
year = int(m.group('year'), 10)
|
| 507 |
+
month = int(m.group('month'), 10)
|
| 508 |
+
if cls.validate_year(year) and cls.validate_month(month):
|
| 509 |
+
parsed = (year, month)
|
| 510 |
+
elif itype == "week":
|
| 511 |
+
m = RE_WEEK.match(value)
|
| 512 |
+
if m:
|
| 513 |
+
year = int(m.group('year'), 10)
|
| 514 |
+
week = int(m.group('week'), 10)
|
| 515 |
+
if cls.validate_year(year) and cls.validate_week(year, week):
|
| 516 |
+
parsed = (year, week)
|
| 517 |
+
elif itype == "time":
|
| 518 |
+
m = RE_TIME.match(value)
|
| 519 |
+
if m:
|
| 520 |
+
hour = int(m.group('hour'), 10)
|
| 521 |
+
minutes = int(m.group('minutes'), 10)
|
| 522 |
+
if cls.validate_hour(hour) and cls.validate_minutes(minutes):
|
| 523 |
+
parsed = (hour, minutes)
|
| 524 |
+
elif itype == "datetime-local":
|
| 525 |
+
m = RE_DATETIME.match(value)
|
| 526 |
+
if m:
|
| 527 |
+
year = int(m.group('year'), 10)
|
| 528 |
+
month = int(m.group('month'), 10)
|
| 529 |
+
day = int(m.group('day'), 10)
|
| 530 |
+
hour = int(m.group('hour'), 10)
|
| 531 |
+
minutes = int(m.group('minutes'), 10)
|
| 532 |
+
if (
|
| 533 |
+
cls.validate_year(year) and cls.validate_month(month) and cls.validate_day(year, month, day) and
|
| 534 |
+
cls.validate_hour(hour) and cls.validate_minutes(minutes)
|
| 535 |
+
):
|
| 536 |
+
parsed = (year, month, day, hour, minutes)
|
| 537 |
+
elif itype in ("number", "range"):
|
| 538 |
+
m = RE_NUM.match(value)
|
| 539 |
+
if m:
|
| 540 |
+
parsed = (float(m.group('value')),)
|
| 541 |
+
return parsed
|
| 542 |
+
|
| 543 |
+
|
| 544 |
+
class CSSMatch(_DocumentNav):
|
| 545 |
+
"""Perform CSS matching."""
|
| 546 |
+
|
| 547 |
+
def __init__(
|
| 548 |
+
self,
|
| 549 |
+
selectors: ct.SelectorList,
|
| 550 |
+
scope: bs4.Tag | None,
|
| 551 |
+
namespaces: ct.Namespaces | None,
|
| 552 |
+
flags: int
|
| 553 |
+
) -> None:
|
| 554 |
+
"""Initialize."""
|
| 555 |
+
|
| 556 |
+
self.assert_valid_input(scope)
|
| 557 |
+
self.tag = scope
|
| 558 |
+
self.cached_meta_lang = [] # type: list[tuple[str, str]]
|
| 559 |
+
self.cached_default_forms = [] # type: list[tuple[bs4.Tag, bs4.Tag]]
|
| 560 |
+
self.cached_indeterminate_forms = [] # type: list[tuple[bs4.Tag, str, bool]]
|
| 561 |
+
self.selectors = selectors
|
| 562 |
+
self.namespaces = {} if namespaces is None else namespaces # type: ct.Namespaces | dict[str, str]
|
| 563 |
+
self.flags = flags
|
| 564 |
+
self.iframe_restrict = False
|
| 565 |
+
|
| 566 |
+
# Find the root element for the whole tree
|
| 567 |
+
doc = scope
|
| 568 |
+
parent = self.get_parent(doc)
|
| 569 |
+
while parent:
|
| 570 |
+
doc = parent
|
| 571 |
+
parent = self.get_parent(doc)
|
| 572 |
+
root = None # type: bs4.Tag | None
|
| 573 |
+
if not self.is_doc(doc):
|
| 574 |
+
root = doc
|
| 575 |
+
else:
|
| 576 |
+
for child in self.get_tag_children(doc):
|
| 577 |
+
root = child
|
| 578 |
+
break
|
| 579 |
+
|
| 580 |
+
self.root = root
|
| 581 |
+
self.scope = scope if scope is not doc else root
|
| 582 |
+
self.has_html_namespace = self.has_html_ns(root)
|
| 583 |
+
|
| 584 |
+
# A document can be both XML and HTML (XHTML)
|
| 585 |
+
self.is_xml = self.is_xml_tree(doc)
|
| 586 |
+
self.is_html = not self.is_xml or self.has_html_namespace
|
| 587 |
+
|
| 588 |
+
def supports_namespaces(self) -> bool:
|
| 589 |
+
"""Check if namespaces are supported in the HTML type."""
|
| 590 |
+
|
| 591 |
+
return self.is_xml or self.has_html_namespace
|
| 592 |
+
|
| 593 |
+
def get_tag_ns(self, el: bs4.Tag | None) -> str:
|
| 594 |
+
"""Get tag namespace."""
|
| 595 |
+
|
| 596 |
+
namespace = ''
|
| 597 |
+
if el is None: # pragma: no cover
|
| 598 |
+
return namespace
|
| 599 |
+
|
| 600 |
+
if self.supports_namespaces():
|
| 601 |
+
ns = self.get_uri(el)
|
| 602 |
+
if ns:
|
| 603 |
+
namespace = ns
|
| 604 |
+
else:
|
| 605 |
+
namespace = NS_XHTML
|
| 606 |
+
return namespace
|
| 607 |
+
|
| 608 |
+
def is_html_tag(self, el: bs4.Tag | None) -> bool:
|
| 609 |
+
"""Check if tag is in HTML namespace."""
|
| 610 |
+
|
| 611 |
+
return self.get_tag_ns(el) == NS_XHTML
|
| 612 |
+
|
| 613 |
+
def get_tag(self, el: bs4.Tag | None) -> str | None:
|
| 614 |
+
"""Get tag."""
|
| 615 |
+
|
| 616 |
+
name = self.get_tag_name(el)
|
| 617 |
+
return util.lower(name) if name is not None and not self.is_xml else name
|
| 618 |
+
|
| 619 |
+
def get_prefix(self, el: bs4.Tag) -> str | None:
|
| 620 |
+
"""Get prefix."""
|
| 621 |
+
|
| 622 |
+
prefix = self.get_prefix_name(el)
|
| 623 |
+
return util.lower(prefix) if prefix is not None and not self.is_xml else prefix
|
| 624 |
+
|
| 625 |
+
def find_bidi(self, el: bs4.Tag) -> int | None:
|
| 626 |
+
"""Get directionality from element text."""
|
| 627 |
+
|
| 628 |
+
for node in self.get_children(el):
|
| 629 |
+
|
| 630 |
+
# Analyze child text nodes
|
| 631 |
+
if self.is_tag(node):
|
| 632 |
+
|
| 633 |
+
# Avoid analyzing certain elements specified in the specification.
|
| 634 |
+
direction = DIR_MAP.get(util.lower(self.get_attribute_by_name(node, 'dir', '')), None) # type: ignore[arg-type]
|
| 635 |
+
name = self.get_tag(node) # type: ignore[arg-type]
|
| 636 |
+
if (
|
| 637 |
+
(name and name in ('bdi', 'script', 'style', 'textarea', 'iframe')) or
|
| 638 |
+
not self.is_html_tag(node) or # type: ignore[arg-type]
|
| 639 |
+
direction is not None
|
| 640 |
+
):
|
| 641 |
+
continue # pragma: no cover
|
| 642 |
+
|
| 643 |
+
# Check directionality of this node's text
|
| 644 |
+
value = self.find_bidi(node) # type: ignore[arg-type]
|
| 645 |
+
if value is not None:
|
| 646 |
+
return value
|
| 647 |
+
|
| 648 |
+
# Direction could not be determined
|
| 649 |
+
continue # pragma: no cover
|
| 650 |
+
|
| 651 |
+
# Skip `doctype` comments, etc.
|
| 652 |
+
if self.is_special_string(node):
|
| 653 |
+
continue
|
| 654 |
+
|
| 655 |
+
# Analyze text nodes for directionality.
|
| 656 |
+
for c in node: # type: ignore[attr-defined]
|
| 657 |
+
bidi = unicodedata.bidirectional(c)
|
| 658 |
+
if bidi in ('AL', 'R', 'L'):
|
| 659 |
+
return ct.SEL_DIR_LTR if bidi == 'L' else ct.SEL_DIR_RTL
|
| 660 |
+
return None
|
| 661 |
+
|
| 662 |
+
def extended_language_filter(self, lang_range: str, lang_tag: str) -> bool:
|
| 663 |
+
"""Filter the language tags."""
|
| 664 |
+
|
| 665 |
+
match = True
|
| 666 |
+
lang_range = RE_WILD_STRIP.sub('-', lang_range).lower()
|
| 667 |
+
ranges = lang_range.split('-')
|
| 668 |
+
subtags = lang_tag.lower().split('-')
|
| 669 |
+
length = len(ranges)
|
| 670 |
+
slength = len(subtags)
|
| 671 |
+
rindex = 0
|
| 672 |
+
sindex = 0
|
| 673 |
+
r = ranges[rindex]
|
| 674 |
+
s = subtags[sindex]
|
| 675 |
+
|
| 676 |
+
# Empty specified language should match unspecified language attributes
|
| 677 |
+
if length == 1 and slength == 1 and not r and r == s:
|
| 678 |
+
return True
|
| 679 |
+
|
| 680 |
+
# Primary tag needs to match
|
| 681 |
+
if (r != '*' and r != s) or (r == '*' and slength == 1 and not s):
|
| 682 |
+
match = False
|
| 683 |
+
|
| 684 |
+
rindex += 1
|
| 685 |
+
sindex += 1
|
| 686 |
+
|
| 687 |
+
# Match until we run out of ranges
|
| 688 |
+
while match and rindex < length:
|
| 689 |
+
r = ranges[rindex]
|
| 690 |
+
try:
|
| 691 |
+
s = subtags[sindex]
|
| 692 |
+
except IndexError:
|
| 693 |
+
# Ran out of subtags,
|
| 694 |
+
# but we still have ranges
|
| 695 |
+
match = False
|
| 696 |
+
continue
|
| 697 |
+
|
| 698 |
+
# Empty range
|
| 699 |
+
if not r:
|
| 700 |
+
match = False
|
| 701 |
+
continue
|
| 702 |
+
|
| 703 |
+
# Matched range
|
| 704 |
+
elif s == r:
|
| 705 |
+
rindex += 1
|
| 706 |
+
|
| 707 |
+
# Implicit wildcard cannot match
|
| 708 |
+
# singletons
|
| 709 |
+
elif len(s) == 1:
|
| 710 |
+
match = False
|
| 711 |
+
continue
|
| 712 |
+
|
| 713 |
+
# Implicitly matched, so grab next subtag
|
| 714 |
+
sindex += 1
|
| 715 |
+
|
| 716 |
+
return match
|
| 717 |
+
|
| 718 |
+
def match_attribute_name(
|
| 719 |
+
self,
|
| 720 |
+
el: bs4.Tag,
|
| 721 |
+
attr: str,
|
| 722 |
+
prefix: str | None
|
| 723 |
+
) -> str | Sequence[str] | None:
|
| 724 |
+
"""Match attribute name and return value if it exists."""
|
| 725 |
+
|
| 726 |
+
value = None
|
| 727 |
+
if self.supports_namespaces():
|
| 728 |
+
value = None
|
| 729 |
+
# If we have not defined namespaces, we can't very well find them, so don't bother trying.
|
| 730 |
+
if prefix:
|
| 731 |
+
ns = self.namespaces.get(prefix)
|
| 732 |
+
if ns is None and prefix != '*':
|
| 733 |
+
return None
|
| 734 |
+
else:
|
| 735 |
+
ns = None
|
| 736 |
+
|
| 737 |
+
for k, v in self.iter_attributes(el):
|
| 738 |
+
|
| 739 |
+
# Get attribute parts
|
| 740 |
+
namespace, name = self.split_namespace(el, k)
|
| 741 |
+
|
| 742 |
+
# Can't match a prefix attribute as we haven't specified one to match
|
| 743 |
+
# Try to match it normally as a whole `p:a` as selector may be trying `p\:a`.
|
| 744 |
+
if ns is None:
|
| 745 |
+
if (self.is_xml and attr == k) or (not self.is_xml and util.lower(attr) == util.lower(k)):
|
| 746 |
+
value = v
|
| 747 |
+
break
|
| 748 |
+
# Coverage is not finding this even though it is executed.
|
| 749 |
+
# Adding a print statement before this (and erasing coverage) causes coverage to find the line.
|
| 750 |
+
# Ignore the false positive message.
|
| 751 |
+
continue # pragma: no cover
|
| 752 |
+
|
| 753 |
+
# We can't match our desired prefix attribute as the attribute doesn't have a prefix
|
| 754 |
+
if namespace is None or (ns != namespace and prefix != '*'):
|
| 755 |
+
continue
|
| 756 |
+
|
| 757 |
+
# The attribute doesn't match.
|
| 758 |
+
if (util.lower(attr) != util.lower(name)) if not self.is_xml else (attr != name):
|
| 759 |
+
continue
|
| 760 |
+
|
| 761 |
+
value = v
|
| 762 |
+
break
|
| 763 |
+
else:
|
| 764 |
+
for k, v in self.iter_attributes(el):
|
| 765 |
+
if util.lower(attr) != util.lower(k):
|
| 766 |
+
continue
|
| 767 |
+
value = v
|
| 768 |
+
break
|
| 769 |
+
return value
|
| 770 |
+
|
| 771 |
+
def match_namespace(self, el: bs4.Tag, tag: ct.SelectorTag) -> bool:
|
| 772 |
+
"""Match the namespace of the element."""
|
| 773 |
+
|
| 774 |
+
match = True
|
| 775 |
+
namespace = self.get_tag_ns(el)
|
| 776 |
+
default_namespace = self.namespaces.get('')
|
| 777 |
+
tag_ns = '' if tag.prefix is None else self.namespaces.get(tag.prefix)
|
| 778 |
+
# We must match the default namespace if one is not provided
|
| 779 |
+
if tag.prefix is None and (default_namespace is not None and namespace != default_namespace):
|
| 780 |
+
match = False
|
| 781 |
+
# If we specified `|tag`, we must not have a namespace.
|
| 782 |
+
elif (tag.prefix is not None and tag.prefix == '' and namespace):
|
| 783 |
+
match = False
|
| 784 |
+
# Verify prefix matches
|
| 785 |
+
elif (
|
| 786 |
+
tag.prefix and
|
| 787 |
+
tag.prefix != '*' and (tag_ns is None or namespace != tag_ns)
|
| 788 |
+
):
|
| 789 |
+
match = False
|
| 790 |
+
return match
|
| 791 |
+
|
| 792 |
+
def match_attributes(self, el: bs4.Tag, attributes: tuple[ct.SelectorAttribute, ...]) -> bool:
|
| 793 |
+
"""Match attributes."""
|
| 794 |
+
|
| 795 |
+
match = True
|
| 796 |
+
if attributes:
|
| 797 |
+
for a in attributes:
|
| 798 |
+
temp = self.match_attribute_name(el, a.attribute, a.prefix)
|
| 799 |
+
pattern = a.xml_type_pattern if self.is_xml and a.xml_type_pattern else a.pattern
|
| 800 |
+
if temp is None:
|
| 801 |
+
match = False
|
| 802 |
+
break
|
| 803 |
+
value = temp if isinstance(temp, str) else ' '.join(temp)
|
| 804 |
+
if pattern is None:
|
| 805 |
+
continue
|
| 806 |
+
elif pattern.match(value) is None:
|
| 807 |
+
match = False
|
| 808 |
+
break
|
| 809 |
+
return match
|
| 810 |
+
|
| 811 |
+
def match_tagname(self, el: bs4.Tag, tag: ct.SelectorTag) -> bool:
|
| 812 |
+
"""Match tag name."""
|
| 813 |
+
|
| 814 |
+
name = (util.lower(tag.name) if not self.is_xml and tag.name is not None else tag.name)
|
| 815 |
+
return not (
|
| 816 |
+
name is not None and
|
| 817 |
+
name not in (self.get_tag(el), '*')
|
| 818 |
+
)
|
| 819 |
+
|
| 820 |
+
def match_tag(self, el: bs4.Tag, tag: ct.SelectorTag | None) -> bool:
|
| 821 |
+
"""Match the tag."""
|
| 822 |
+
|
| 823 |
+
match = True
|
| 824 |
+
if tag is not None:
|
| 825 |
+
# Verify namespace
|
| 826 |
+
if not self.match_namespace(el, tag):
|
| 827 |
+
match = False
|
| 828 |
+
if not self.match_tagname(el, tag):
|
| 829 |
+
match = False
|
| 830 |
+
return match
|
| 831 |
+
|
| 832 |
+
def match_past_relations(self, el: bs4.Tag, relation: ct.SelectorList) -> bool:
|
| 833 |
+
"""Match past relationship."""
|
| 834 |
+
|
| 835 |
+
found = False
|
| 836 |
+
# I don't think this can ever happen, but it makes `mypy` happy
|
| 837 |
+
if isinstance(relation[0], ct.SelectorNull): # pragma: no cover
|
| 838 |
+
return found
|
| 839 |
+
|
| 840 |
+
if relation[0].rel_type == REL_PARENT:
|
| 841 |
+
parent = self.get_parent(el, no_iframe=self.iframe_restrict)
|
| 842 |
+
while not found and parent:
|
| 843 |
+
found = self.match_selectors(parent, relation)
|
| 844 |
+
parent = self.get_parent(parent, no_iframe=self.iframe_restrict)
|
| 845 |
+
elif relation[0].rel_type == REL_CLOSE_PARENT:
|
| 846 |
+
parent = self.get_parent(el, no_iframe=self.iframe_restrict)
|
| 847 |
+
if parent:
|
| 848 |
+
found = self.match_selectors(parent, relation)
|
| 849 |
+
elif relation[0].rel_type == REL_SIBLING:
|
| 850 |
+
sibling = self.get_previous_tag(el)
|
| 851 |
+
while not found and sibling:
|
| 852 |
+
found = self.match_selectors(sibling, relation)
|
| 853 |
+
sibling = self.get_previous_tag(sibling)
|
| 854 |
+
elif relation[0].rel_type == REL_CLOSE_SIBLING:
|
| 855 |
+
sibling = self.get_previous_tag(el)
|
| 856 |
+
if sibling and self.is_tag(sibling):
|
| 857 |
+
found = self.match_selectors(sibling, relation)
|
| 858 |
+
return found
|
| 859 |
+
|
| 860 |
+
def match_future_child(self, parent: bs4.Tag, relation: ct.SelectorList, recursive: bool = False) -> bool:
|
| 861 |
+
"""Match future child."""
|
| 862 |
+
|
| 863 |
+
match = False
|
| 864 |
+
if recursive:
|
| 865 |
+
children = self.get_tag_descendants # type: Callable[..., Iterator[bs4.Tag]]
|
| 866 |
+
else:
|
| 867 |
+
children = self.get_tag_children
|
| 868 |
+
for child in children(parent, no_iframe=self.iframe_restrict):
|
| 869 |
+
match = self.match_selectors(child, relation)
|
| 870 |
+
if match:
|
| 871 |
+
break
|
| 872 |
+
return match
|
| 873 |
+
|
| 874 |
+
def match_future_relations(self, el: bs4.Tag, relation: ct.SelectorList) -> bool:
|
| 875 |
+
"""Match future relationship."""
|
| 876 |
+
|
| 877 |
+
found = False
|
| 878 |
+
# I don't think this can ever happen, but it makes `mypy` happy
|
| 879 |
+
if isinstance(relation[0], ct.SelectorNull): # pragma: no cover
|
| 880 |
+
return found
|
| 881 |
+
|
| 882 |
+
if relation[0].rel_type == REL_HAS_PARENT:
|
| 883 |
+
found = self.match_future_child(el, relation, True)
|
| 884 |
+
elif relation[0].rel_type == REL_HAS_CLOSE_PARENT:
|
| 885 |
+
found = self.match_future_child(el, relation)
|
| 886 |
+
elif relation[0].rel_type == REL_HAS_SIBLING:
|
| 887 |
+
sibling = self.get_next_tag(el)
|
| 888 |
+
while not found and sibling:
|
| 889 |
+
found = self.match_selectors(sibling, relation)
|
| 890 |
+
sibling = self.get_next_tag(sibling)
|
| 891 |
+
elif relation[0].rel_type == REL_HAS_CLOSE_SIBLING:
|
| 892 |
+
sibling = self.get_next_tag(el)
|
| 893 |
+
if sibling and self.is_tag(sibling):
|
| 894 |
+
found = self.match_selectors(sibling, relation)
|
| 895 |
+
return found
|
| 896 |
+
|
| 897 |
+
def match_relations(self, el: bs4.Tag, relation: ct.SelectorList) -> bool:
|
| 898 |
+
"""Match relationship to other elements."""
|
| 899 |
+
|
| 900 |
+
found = False
|
| 901 |
+
|
| 902 |
+
if isinstance(relation[0], ct.SelectorNull) or relation[0].rel_type is None:
|
| 903 |
+
return found
|
| 904 |
+
|
| 905 |
+
if relation[0].rel_type.startswith(':'):
|
| 906 |
+
found = self.match_future_relations(el, relation)
|
| 907 |
+
else:
|
| 908 |
+
found = self.match_past_relations(el, relation)
|
| 909 |
+
|
| 910 |
+
return found
|
| 911 |
+
|
| 912 |
+
def match_id(self, el: bs4.Tag, ids: tuple[str, ...]) -> bool:
|
| 913 |
+
"""Match element's ID."""
|
| 914 |
+
|
| 915 |
+
found = True
|
| 916 |
+
for i in ids:
|
| 917 |
+
if i != self.get_attribute_by_name(el, 'id', ''):
|
| 918 |
+
found = False
|
| 919 |
+
break
|
| 920 |
+
return found
|
| 921 |
+
|
| 922 |
+
def match_classes(self, el: bs4.Tag, classes: tuple[str, ...]) -> bool:
|
| 923 |
+
"""Match element's classes."""
|
| 924 |
+
|
| 925 |
+
current_classes = self.get_classes(el)
|
| 926 |
+
found = True
|
| 927 |
+
for c in classes:
|
| 928 |
+
if c not in current_classes:
|
| 929 |
+
found = False
|
| 930 |
+
break
|
| 931 |
+
return found
|
| 932 |
+
|
| 933 |
+
def match_root(self, el: bs4.Tag) -> bool:
|
| 934 |
+
"""Match element as root."""
|
| 935 |
+
|
| 936 |
+
is_root = self.is_root(el)
|
| 937 |
+
if is_root:
|
| 938 |
+
sibling = self.get_previous(el) # type: Any
|
| 939 |
+
while is_root and sibling is not None:
|
| 940 |
+
if (
|
| 941 |
+
self.is_tag(sibling) or (self.is_content_string(sibling) and sibling.strip()) or
|
| 942 |
+
self.is_cdata(sibling)
|
| 943 |
+
):
|
| 944 |
+
is_root = False
|
| 945 |
+
else:
|
| 946 |
+
sibling = self.get_previous(sibling)
|
| 947 |
+
if is_root:
|
| 948 |
+
sibling = self.get_next(el)
|
| 949 |
+
while is_root and sibling is not None:
|
| 950 |
+
if (
|
| 951 |
+
self.is_tag(sibling) or (self.is_content_string(sibling) and sibling.strip()) or
|
| 952 |
+
self.is_cdata(sibling)
|
| 953 |
+
):
|
| 954 |
+
is_root = False
|
| 955 |
+
else:
|
| 956 |
+
sibling = self.get_next(sibling)
|
| 957 |
+
return is_root
|
| 958 |
+
|
| 959 |
+
def match_scope(self, el: bs4.Tag) -> bool:
|
| 960 |
+
"""Match element as scope."""
|
| 961 |
+
|
| 962 |
+
return self.scope is el
|
| 963 |
+
|
| 964 |
+
def match_nth_tag_type(self, el: bs4.Tag, child: bs4.Tag) -> bool:
|
| 965 |
+
"""Match tag type for `nth` matches."""
|
| 966 |
+
|
| 967 |
+
return (
|
| 968 |
+
(self.get_tag(child) == self.get_tag(el)) and
|
| 969 |
+
(self.get_tag_ns(child) == self.get_tag_ns(el))
|
| 970 |
+
)
|
| 971 |
+
|
| 972 |
+
def match_nth(self, el: bs4.Tag, nth: tuple[ct.SelectorNth, ...]) -> bool:
|
| 973 |
+
"""Match `nth` elements."""
|
| 974 |
+
|
| 975 |
+
matched = True
|
| 976 |
+
|
| 977 |
+
for n in nth:
|
| 978 |
+
matched = False
|
| 979 |
+
if n.selectors and not self.match_selectors(el, n.selectors):
|
| 980 |
+
break
|
| 981 |
+
parent = self.get_parent(el) # type: bs4.Tag | None
|
| 982 |
+
if parent is None:
|
| 983 |
+
parent = cast('bs4.Tag', self.create_fake_parent(el))
|
| 984 |
+
last = n.last
|
| 985 |
+
last_index = len(parent) - 1
|
| 986 |
+
index = last_index if last else 0
|
| 987 |
+
relative_index = 0
|
| 988 |
+
a = n.a
|
| 989 |
+
b = n.b
|
| 990 |
+
var = n.n
|
| 991 |
+
count = 0
|
| 992 |
+
count_incr = 1
|
| 993 |
+
factor = -1 if last else 1
|
| 994 |
+
idx = last_idx = a * count + b if var else a
|
| 995 |
+
|
| 996 |
+
# We can only adjust bounds within a variable index
|
| 997 |
+
if var:
|
| 998 |
+
# Find the count `n` that yields the smallest in-bounds index
|
| 999 |
+
# (>= 1), then set the increment direction so that the index
|
| 1000 |
+
# ascends from there as the evaluation loop below walks children.
|
| 1001 |
+
if a > 0:
|
| 1002 |
+
# Ascending sequence: smallest n with a * n + b >= 1.
|
| 1003 |
+
count = 0 if b >= 1 else -(-(1 - b) // a)
|
| 1004 |
+
elif a < 0:
|
| 1005 |
+
# Descending sequence: largest n with a * n + b >= 1, then
|
| 1006 |
+
# walk n back down so the index increases.
|
| 1007 |
+
count = (b - 1) // -a if b >= 1 else 0
|
| 1008 |
+
count_incr = -1
|
| 1009 |
+
idx = last_idx = a * count + b
|
| 1010 |
+
|
| 1011 |
+
# Evaluate elements while our calculated nth index is still in range
|
| 1012 |
+
while 1 <= idx <= last_index + 1:
|
| 1013 |
+
child = None # type: bs4.element.PageElement | None
|
| 1014 |
+
# Evaluate while our child index is still in range.
|
| 1015 |
+
for child in self.get_children(parent, start=index, reverse=factor < 0):
|
| 1016 |
+
index += factor
|
| 1017 |
+
if not isinstance(child, bs4.Tag):
|
| 1018 |
+
continue
|
| 1019 |
+
# Handle `of S` in `nth-child`
|
| 1020 |
+
if n.selectors and not self.match_selectors(child, n.selectors):
|
| 1021 |
+
continue
|
| 1022 |
+
# Handle `of-type`
|
| 1023 |
+
if n.of_type and not self.match_nth_tag_type(el, child):
|
| 1024 |
+
continue
|
| 1025 |
+
relative_index += 1
|
| 1026 |
+
if relative_index == idx:
|
| 1027 |
+
if child is el:
|
| 1028 |
+
matched = True
|
| 1029 |
+
else:
|
| 1030 |
+
break
|
| 1031 |
+
if child is el:
|
| 1032 |
+
break
|
| 1033 |
+
if child is el:
|
| 1034 |
+
break
|
| 1035 |
+
last_idx = idx
|
| 1036 |
+
count += count_incr
|
| 1037 |
+
if count < 0:
|
| 1038 |
+
# Count is counting down and has now ventured into invalid territory.
|
| 1039 |
+
break
|
| 1040 |
+
idx = a * count + b if var else a
|
| 1041 |
+
if last_idx == idx:
|
| 1042 |
+
break
|
| 1043 |
+
if not matched:
|
| 1044 |
+
break
|
| 1045 |
+
return matched
|
| 1046 |
+
|
| 1047 |
+
def match_empty(self, el: bs4.Tag) -> bool:
|
| 1048 |
+
"""Check if element is empty (if requested)."""
|
| 1049 |
+
|
| 1050 |
+
is_empty = True
|
| 1051 |
+
for child in self.get_children(el):
|
| 1052 |
+
if self.is_tag(child):
|
| 1053 |
+
is_empty = False
|
| 1054 |
+
break
|
| 1055 |
+
elif self.is_content_string(child) and RE_NOT_EMPTY.search(child): # type: ignore[call-overload]
|
| 1056 |
+
is_empty = False
|
| 1057 |
+
break
|
| 1058 |
+
return is_empty
|
| 1059 |
+
|
| 1060 |
+
def match_subselectors(self, el: bs4.Tag, selectors: tuple[ct.SelectorList, ...]) -> bool:
|
| 1061 |
+
"""Match selectors."""
|
| 1062 |
+
|
| 1063 |
+
match = True
|
| 1064 |
+
for sel in selectors:
|
| 1065 |
+
if not self.match_selectors(el, sel):
|
| 1066 |
+
match = False
|
| 1067 |
+
return match
|
| 1068 |
+
|
| 1069 |
+
def match_contains(self, el: bs4.Tag, contains: tuple[ct.SelectorContains, ...]) -> bool:
|
| 1070 |
+
"""Match element if it contains text."""
|
| 1071 |
+
|
| 1072 |
+
match = True
|
| 1073 |
+
content = None # type: str | Sequence[str] | None
|
| 1074 |
+
for contain_list in contains:
|
| 1075 |
+
if content is None:
|
| 1076 |
+
if contain_list.own:
|
| 1077 |
+
content = self.get_own_text(el, no_iframe=self.is_html)
|
| 1078 |
+
else:
|
| 1079 |
+
content = self.get_text(el, no_iframe=self.is_html)
|
| 1080 |
+
found = False
|
| 1081 |
+
for text in contain_list.text:
|
| 1082 |
+
if contain_list.own:
|
| 1083 |
+
for c in content:
|
| 1084 |
+
if text in c:
|
| 1085 |
+
found = True
|
| 1086 |
+
break
|
| 1087 |
+
if found:
|
| 1088 |
+
break
|
| 1089 |
+
else:
|
| 1090 |
+
if text in content:
|
| 1091 |
+
found = True
|
| 1092 |
+
break
|
| 1093 |
+
if not found:
|
| 1094 |
+
match = False
|
| 1095 |
+
return match
|
| 1096 |
+
|
| 1097 |
+
def match_default(self, el: bs4.Tag) -> bool:
|
| 1098 |
+
"""Match default."""
|
| 1099 |
+
|
| 1100 |
+
match = False
|
| 1101 |
+
|
| 1102 |
+
# Find this input's form
|
| 1103 |
+
form = None # type: bs4.Tag | None
|
| 1104 |
+
parent = self.get_parent(el, no_iframe=True)
|
| 1105 |
+
while parent and form is None:
|
| 1106 |
+
if self.get_tag(parent) == 'form' and self.is_html_tag(parent):
|
| 1107 |
+
form = parent
|
| 1108 |
+
else:
|
| 1109 |
+
parent = self.get_parent(parent, no_iframe=True)
|
| 1110 |
+
|
| 1111 |
+
if form is not None:
|
| 1112 |
+
# Look in form cache to see if we've already located its default button
|
| 1113 |
+
found_form = False
|
| 1114 |
+
for f, t in self.cached_default_forms:
|
| 1115 |
+
if f is form:
|
| 1116 |
+
found_form = True
|
| 1117 |
+
if t is el:
|
| 1118 |
+
match = True
|
| 1119 |
+
break
|
| 1120 |
+
|
| 1121 |
+
# We didn't have the form cached, so look for its default button
|
| 1122 |
+
if not found_form:
|
| 1123 |
+
for child in self.get_tag_descendants(form, no_iframe=True):
|
| 1124 |
+
name = self.get_tag(child)
|
| 1125 |
+
# Can't do nested forms (haven't figured out why we never hit this)
|
| 1126 |
+
if name == 'form': # pragma: no cover
|
| 1127 |
+
break
|
| 1128 |
+
if name in ('input', 'button'):
|
| 1129 |
+
v = self.get_attribute_by_name(child, 'type', '')
|
| 1130 |
+
if v and util.lower(v) == 'submit':
|
| 1131 |
+
self.cached_default_forms.append((form, child))
|
| 1132 |
+
if el is child:
|
| 1133 |
+
match = True
|
| 1134 |
+
break
|
| 1135 |
+
return match
|
| 1136 |
+
|
| 1137 |
+
def match_indeterminate(self, el: bs4.Tag) -> bool:
|
| 1138 |
+
"""Match default."""
|
| 1139 |
+
|
| 1140 |
+
match = False
|
| 1141 |
+
name = cast(str, self.get_attribute_by_name(el, 'name'))
|
| 1142 |
+
|
| 1143 |
+
def get_parent_form(el: bs4.Tag) -> bs4.Tag | None:
|
| 1144 |
+
"""Find this input's form."""
|
| 1145 |
+
form = None
|
| 1146 |
+
parent = self.get_parent(el, no_iframe=True)
|
| 1147 |
+
while form is None:
|
| 1148 |
+
if self.get_tag(parent) == 'form' and self.is_html_tag(parent):
|
| 1149 |
+
form = parent
|
| 1150 |
+
break
|
| 1151 |
+
last_parent = parent
|
| 1152 |
+
parent = self.get_parent(parent, no_iframe=True)
|
| 1153 |
+
if parent is None:
|
| 1154 |
+
form = last_parent
|
| 1155 |
+
break
|
| 1156 |
+
return form
|
| 1157 |
+
|
| 1158 |
+
form = get_parent_form(el)
|
| 1159 |
+
|
| 1160 |
+
# Look in form cache to see if we've already evaluated that its fellow radio buttons are indeterminate
|
| 1161 |
+
if form is not None:
|
| 1162 |
+
found_form = False
|
| 1163 |
+
for f, n, i in self.cached_indeterminate_forms:
|
| 1164 |
+
if f is form and n == name:
|
| 1165 |
+
found_form = True
|
| 1166 |
+
if i is True:
|
| 1167 |
+
match = True
|
| 1168 |
+
break
|
| 1169 |
+
|
| 1170 |
+
# We didn't have the form cached, so validate that the radio button is indeterminate
|
| 1171 |
+
if not found_form:
|
| 1172 |
+
checked = False
|
| 1173 |
+
for child in self.get_tag_descendants(form, no_iframe=True):
|
| 1174 |
+
if child is el:
|
| 1175 |
+
continue
|
| 1176 |
+
tag_name = self.get_tag(child)
|
| 1177 |
+
if tag_name == 'input':
|
| 1178 |
+
is_radio = False
|
| 1179 |
+
check = False
|
| 1180 |
+
has_name = False
|
| 1181 |
+
for k, v in self.iter_attributes(child):
|
| 1182 |
+
if util.lower(k) == 'type' and util.lower(v) == 'radio':
|
| 1183 |
+
is_radio = True
|
| 1184 |
+
elif util.lower(k) == 'name' and v == name:
|
| 1185 |
+
has_name = True
|
| 1186 |
+
elif util.lower(k) == 'checked':
|
| 1187 |
+
check = True
|
| 1188 |
+
if is_radio and check and has_name and get_parent_form(child) is form:
|
| 1189 |
+
checked = True
|
| 1190 |
+
break
|
| 1191 |
+
if checked:
|
| 1192 |
+
break
|
| 1193 |
+
if not checked:
|
| 1194 |
+
match = True
|
| 1195 |
+
self.cached_indeterminate_forms.append((form, name, match))
|
| 1196 |
+
|
| 1197 |
+
return match
|
| 1198 |
+
|
| 1199 |
+
def match_lang(self, el: bs4.Tag, langs: tuple[ct.SelectorLang, ...]) -> bool:
|
| 1200 |
+
"""Match languages."""
|
| 1201 |
+
|
| 1202 |
+
match = False
|
| 1203 |
+
has_ns = self.supports_namespaces()
|
| 1204 |
+
root = self.root
|
| 1205 |
+
has_html_namespace = self.has_html_namespace
|
| 1206 |
+
|
| 1207 |
+
# Walk parents looking for `lang` (HTML) or `xml:lang` XML property.
|
| 1208 |
+
parent = el # type: bs4.Tag | None
|
| 1209 |
+
found_lang = None
|
| 1210 |
+
last = None
|
| 1211 |
+
while not found_lang:
|
| 1212 |
+
has_html_ns = self.has_html_ns(parent)
|
| 1213 |
+
for k, v in self.iter_attributes(parent):
|
| 1214 |
+
attr_ns, attr = self.split_namespace(parent, k)
|
| 1215 |
+
if (
|
| 1216 |
+
((not has_ns or has_html_ns) and (util.lower(k) if not self.is_xml else k) == 'lang') or
|
| 1217 |
+
(
|
| 1218 |
+
has_ns and not has_html_ns and attr_ns == NS_XML and
|
| 1219 |
+
(util.lower(attr) if not self.is_xml and attr is not None else attr) == 'lang'
|
| 1220 |
+
)
|
| 1221 |
+
):
|
| 1222 |
+
found_lang = v
|
| 1223 |
+
break
|
| 1224 |
+
last = parent
|
| 1225 |
+
parent = self.get_parent(parent, no_iframe=self.is_html)
|
| 1226 |
+
|
| 1227 |
+
if parent is None:
|
| 1228 |
+
root = last
|
| 1229 |
+
has_html_namespace = self.has_html_ns(root)
|
| 1230 |
+
parent = last
|
| 1231 |
+
break
|
| 1232 |
+
|
| 1233 |
+
# Use cached meta language.
|
| 1234 |
+
if found_lang is None and self.cached_meta_lang:
|
| 1235 |
+
for cache in self.cached_meta_lang:
|
| 1236 |
+
if root is not None and cast(str, root) is cache[0]:
|
| 1237 |
+
found_lang = cache[1]
|
| 1238 |
+
|
| 1239 |
+
# If we couldn't find a language, and the document is HTML, look to meta to determine language.
|
| 1240 |
+
if found_lang is None and (not self.is_xml or (has_html_namespace and root and root.name == 'html')):
|
| 1241 |
+
# Find head
|
| 1242 |
+
found = False
|
| 1243 |
+
for tag in ('html', 'head'):
|
| 1244 |
+
found = False
|
| 1245 |
+
for child in self.get_tag_children(parent, no_iframe=self.is_html):
|
| 1246 |
+
if self.get_tag(child) == tag and self.is_html_tag(child):
|
| 1247 |
+
found = True
|
| 1248 |
+
parent = child
|
| 1249 |
+
break
|
| 1250 |
+
if not found: # pragma: no cover
|
| 1251 |
+
break
|
| 1252 |
+
|
| 1253 |
+
# Search meta tags
|
| 1254 |
+
if found and parent is not None:
|
| 1255 |
+
for child2 in parent:
|
| 1256 |
+
if isinstance(child2, bs4.Tag) and self.get_tag(child2) == 'meta' and self.is_html_tag(parent):
|
| 1257 |
+
c_lang = False
|
| 1258 |
+
content = None
|
| 1259 |
+
for k, v in self.iter_attributes(child2):
|
| 1260 |
+
if util.lower(k) == 'http-equiv' and util.lower(v) == 'content-language':
|
| 1261 |
+
c_lang = True
|
| 1262 |
+
if util.lower(k) == 'content':
|
| 1263 |
+
content = v
|
| 1264 |
+
if c_lang and content:
|
| 1265 |
+
found_lang = content
|
| 1266 |
+
self.cached_meta_lang.append((cast(str, root), cast(str, found_lang)))
|
| 1267 |
+
break
|
| 1268 |
+
if found_lang is not None:
|
| 1269 |
+
break
|
| 1270 |
+
if found_lang is None:
|
| 1271 |
+
self.cached_meta_lang.append((cast(str, root), ''))
|
| 1272 |
+
|
| 1273 |
+
# If we determined a language, compare.
|
| 1274 |
+
if found_lang is not None:
|
| 1275 |
+
for patterns in langs:
|
| 1276 |
+
match = False
|
| 1277 |
+
for pattern in patterns:
|
| 1278 |
+
if self.extended_language_filter(pattern, cast(str, found_lang)):
|
| 1279 |
+
match = True
|
| 1280 |
+
if not match:
|
| 1281 |
+
break
|
| 1282 |
+
|
| 1283 |
+
return match
|
| 1284 |
+
|
| 1285 |
+
def match_dir(self, el: bs4.Tag | None, directionality: int) -> bool:
|
| 1286 |
+
"""Check directionality."""
|
| 1287 |
+
|
| 1288 |
+
# If we have to match both left and right, we can't match either.
|
| 1289 |
+
if directionality & ct.SEL_DIR_LTR and directionality & ct.SEL_DIR_RTL:
|
| 1290 |
+
return False
|
| 1291 |
+
|
| 1292 |
+
if el is None or not self.is_html_tag(el):
|
| 1293 |
+
return False
|
| 1294 |
+
|
| 1295 |
+
# Element has defined direction of left to right or right to left
|
| 1296 |
+
direction = DIR_MAP.get(util.lower(self.get_attribute_by_name(el, 'dir', '')), None)
|
| 1297 |
+
if direction not in (None, 0):
|
| 1298 |
+
return direction == directionality
|
| 1299 |
+
|
| 1300 |
+
# Element is the document element (the root) and no direction assigned, assume left to right.
|
| 1301 |
+
is_root = self.is_root(el)
|
| 1302 |
+
if is_root and direction is None:
|
| 1303 |
+
return ct.SEL_DIR_LTR == directionality
|
| 1304 |
+
|
| 1305 |
+
# If `input[type=telephone]` and no direction is assigned, assume left to right.
|
| 1306 |
+
name = self.get_tag(el)
|
| 1307 |
+
is_input = name == 'input'
|
| 1308 |
+
is_textarea = name == 'textarea'
|
| 1309 |
+
is_bdi = name == 'bdi'
|
| 1310 |
+
itype = util.lower(self.get_attribute_by_name(el, 'type', '')) if is_input else ''
|
| 1311 |
+
if is_input and itype == 'tel' and direction is None:
|
| 1312 |
+
return ct.SEL_DIR_LTR == directionality
|
| 1313 |
+
|
| 1314 |
+
# Auto handling for text inputs
|
| 1315 |
+
if ((is_input and itype in ('text', 'search', 'tel', 'url', 'email')) or is_textarea) and direction == 0:
|
| 1316 |
+
if is_textarea:
|
| 1317 |
+
value = ''.join(node for node in self.get_contents(el, no_iframe=True) if self.is_content_string(node)) # type: ignore[misc]
|
| 1318 |
+
else:
|
| 1319 |
+
value = cast(str, self.get_attribute_by_name(el, 'value', ''))
|
| 1320 |
+
if value:
|
| 1321 |
+
for c in value:
|
| 1322 |
+
bidi = unicodedata.bidirectional(c)
|
| 1323 |
+
if bidi in ('AL', 'R', 'L'):
|
| 1324 |
+
direction = ct.SEL_DIR_LTR if bidi == 'L' else ct.SEL_DIR_RTL
|
| 1325 |
+
return direction == directionality
|
| 1326 |
+
# Assume left to right
|
| 1327 |
+
return ct.SEL_DIR_LTR == directionality
|
| 1328 |
+
elif is_root:
|
| 1329 |
+
return ct.SEL_DIR_LTR == directionality
|
| 1330 |
+
return self.match_dir(self.get_parent(el, no_iframe=True), directionality)
|
| 1331 |
+
|
| 1332 |
+
# Auto handling for `bdi` and other non text inputs.
|
| 1333 |
+
if (is_bdi and direction is None) or direction == 0:
|
| 1334 |
+
direction = self.find_bidi(el)
|
| 1335 |
+
if direction is not None:
|
| 1336 |
+
return direction == directionality
|
| 1337 |
+
elif is_root:
|
| 1338 |
+
return ct.SEL_DIR_LTR == directionality
|
| 1339 |
+
return self.match_dir(self.get_parent(el, no_iframe=True), directionality)
|
| 1340 |
+
|
| 1341 |
+
# Match parents direction
|
| 1342 |
+
return self.match_dir(self.get_parent(el, no_iframe=True), directionality)
|
| 1343 |
+
|
| 1344 |
+
def match_range(self, el: bs4.Tag, condition: int) -> bool:
|
| 1345 |
+
"""
|
| 1346 |
+
Match range.
|
| 1347 |
+
|
| 1348 |
+
Behavior is modeled after what we see in browsers. Browsers seem to evaluate
|
| 1349 |
+
if the value is out of range, and if not, it is in range. So a missing value
|
| 1350 |
+
will not evaluate out of range; therefore, value is in range. Personally, I
|
| 1351 |
+
feel like this should evaluate as neither in or out of range.
|
| 1352 |
+
"""
|
| 1353 |
+
|
| 1354 |
+
out_of_range = False
|
| 1355 |
+
|
| 1356 |
+
itype = util.lower(self.get_attribute_by_name(el, 'type'))
|
| 1357 |
+
mn = Inputs.parse_value(itype, cast(str, self.get_attribute_by_name(el, 'min', None)))
|
| 1358 |
+
mx = Inputs.parse_value(itype, cast(str, self.get_attribute_by_name(el, 'max', None)))
|
| 1359 |
+
|
| 1360 |
+
# There is no valid min or max, so we cannot evaluate a range
|
| 1361 |
+
if mn is None and mx is None:
|
| 1362 |
+
return False
|
| 1363 |
+
|
| 1364 |
+
value = Inputs.parse_value(itype, cast(str, self.get_attribute_by_name(el, 'value', None)))
|
| 1365 |
+
if value is not None:
|
| 1366 |
+
if itype in ("date", "datetime-local", "month", "week", "number", "range"):
|
| 1367 |
+
if mn is not None and value < mn:
|
| 1368 |
+
out_of_range = True
|
| 1369 |
+
if not out_of_range and mx is not None and value > mx:
|
| 1370 |
+
out_of_range = True
|
| 1371 |
+
elif itype == "time":
|
| 1372 |
+
if mn is not None and mx is not None and mn > mx:
|
| 1373 |
+
# Time is periodic, so this is a reversed/discontinuous range
|
| 1374 |
+
if value < mn and value > mx:
|
| 1375 |
+
out_of_range = True
|
| 1376 |
+
else:
|
| 1377 |
+
if mn is not None and value < mn:
|
| 1378 |
+
out_of_range = True
|
| 1379 |
+
if not out_of_range and mx is not None and value > mx:
|
| 1380 |
+
out_of_range = True
|
| 1381 |
+
|
| 1382 |
+
return not out_of_range if condition & ct.SEL_IN_RANGE else out_of_range
|
| 1383 |
+
|
| 1384 |
+
def match_defined(self, el: bs4.Tag) -> bool:
|
| 1385 |
+
"""
|
| 1386 |
+
Match defined.
|
| 1387 |
+
|
| 1388 |
+
`:defined` is related to custom elements in a browser.
|
| 1389 |
+
|
| 1390 |
+
- If the document is XML (not XHTML), all tags will match.
|
| 1391 |
+
- Tags that are not custom (don't have a hyphen) are marked defined.
|
| 1392 |
+
- If the tag has a prefix (without or without a namespace), it will not match.
|
| 1393 |
+
|
| 1394 |
+
This is of course requires the parser to provide us with the proper prefix and namespace info,
|
| 1395 |
+
if it doesn't, there is nothing we can do.
|
| 1396 |
+
"""
|
| 1397 |
+
|
| 1398 |
+
name = self.get_tag(el)
|
| 1399 |
+
return (
|
| 1400 |
+
name is not None and (
|
| 1401 |
+
name.find('-') == -1 or
|
| 1402 |
+
name.find(':') != -1 or
|
| 1403 |
+
self.get_prefix(el) is not None
|
| 1404 |
+
)
|
| 1405 |
+
)
|
| 1406 |
+
|
| 1407 |
+
def match_placeholder_shown(self, el: bs4.Tag) -> bool:
|
| 1408 |
+
"""
|
| 1409 |
+
Match placeholder shown according to HTML spec.
|
| 1410 |
+
|
| 1411 |
+
- text area should be checked if they have content. A single newline does not count as content.
|
| 1412 |
+
|
| 1413 |
+
"""
|
| 1414 |
+
|
| 1415 |
+
match = False
|
| 1416 |
+
content = self.get_text(el)
|
| 1417 |
+
if content in ('', '\n'):
|
| 1418 |
+
match = True
|
| 1419 |
+
|
| 1420 |
+
return match
|
| 1421 |
+
|
| 1422 |
+
def match_selectors(self, el: bs4.Tag, selectors: ct.SelectorList) -> bool:
|
| 1423 |
+
"""Check if element matches one of the selectors."""
|
| 1424 |
+
|
| 1425 |
+
match = False
|
| 1426 |
+
is_not = selectors.is_not
|
| 1427 |
+
is_html = selectors.is_html
|
| 1428 |
+
|
| 1429 |
+
# Internal selector lists that use the HTML flag, will automatically get the `html` namespace.
|
| 1430 |
+
if is_html:
|
| 1431 |
+
namespaces = self.namespaces
|
| 1432 |
+
iframe_restrict = self.iframe_restrict
|
| 1433 |
+
self.namespaces = {'html': NS_XHTML}
|
| 1434 |
+
self.iframe_restrict = True
|
| 1435 |
+
|
| 1436 |
+
if not is_html or self.is_html:
|
| 1437 |
+
for selector in selectors:
|
| 1438 |
+
match = is_not
|
| 1439 |
+
# We have a un-matchable situation (like `:focus` as you can focus an element in this environment)
|
| 1440 |
+
if isinstance(selector, ct.SelectorNull):
|
| 1441 |
+
continue
|
| 1442 |
+
# Verify tag matches
|
| 1443 |
+
if not self.match_tag(el, selector.tag):
|
| 1444 |
+
continue
|
| 1445 |
+
# Verify tag is defined
|
| 1446 |
+
if selector.flags & ct.SEL_DEFINED and not self.match_defined(el):
|
| 1447 |
+
continue
|
| 1448 |
+
# Verify element is root
|
| 1449 |
+
if selector.flags & ct.SEL_ROOT and not self.match_root(el):
|
| 1450 |
+
continue
|
| 1451 |
+
# Verify element is scope
|
| 1452 |
+
if selector.flags & ct.SEL_SCOPE and not self.match_scope(el):
|
| 1453 |
+
continue
|
| 1454 |
+
# Verify element has placeholder shown
|
| 1455 |
+
if selector.flags & ct.SEL_PLACEHOLDER_SHOWN and not self.match_placeholder_shown(el):
|
| 1456 |
+
continue
|
| 1457 |
+
# Verify `nth` matches
|
| 1458 |
+
if not self.match_nth(el, selector.nth):
|
| 1459 |
+
continue
|
| 1460 |
+
if selector.flags & ct.SEL_EMPTY and not self.match_empty(el):
|
| 1461 |
+
continue
|
| 1462 |
+
# Verify id matches
|
| 1463 |
+
if selector.ids and not self.match_id(el, selector.ids):
|
| 1464 |
+
continue
|
| 1465 |
+
# Verify classes match
|
| 1466 |
+
if selector.classes and not self.match_classes(el, selector.classes):
|
| 1467 |
+
continue
|
| 1468 |
+
# Verify attribute(s) match
|
| 1469 |
+
if not self.match_attributes(el, selector.attributes):
|
| 1470 |
+
continue
|
| 1471 |
+
# Verify ranges
|
| 1472 |
+
if selector.flags & RANGES and not self.match_range(el, selector.flags & RANGES):
|
| 1473 |
+
continue
|
| 1474 |
+
# Verify language patterns
|
| 1475 |
+
if selector.lang and not self.match_lang(el, selector.lang):
|
| 1476 |
+
continue
|
| 1477 |
+
# Verify pseudo selector patterns
|
| 1478 |
+
if selector.selectors and not self.match_subselectors(el, selector.selectors):
|
| 1479 |
+
continue
|
| 1480 |
+
# Verify relationship selectors
|
| 1481 |
+
if selector.relation and not self.match_relations(el, selector.relation):
|
| 1482 |
+
continue
|
| 1483 |
+
# Validate that the current default selector match corresponds to the first submit button in the form
|
| 1484 |
+
if selector.flags & ct.SEL_DEFAULT and not self.match_default(el):
|
| 1485 |
+
continue
|
| 1486 |
+
# Validate that the unset radio button is among radio buttons with the same name in a form that are
|
| 1487 |
+
# also not set.
|
| 1488 |
+
if selector.flags & ct.SEL_INDETERMINATE and not self.match_indeterminate(el):
|
| 1489 |
+
continue
|
| 1490 |
+
# Validate element directionality
|
| 1491 |
+
if selector.flags & DIR_FLAGS and not self.match_dir(el, selector.flags & DIR_FLAGS):
|
| 1492 |
+
continue
|
| 1493 |
+
# Validate that the tag contains the specified text.
|
| 1494 |
+
if selector.contains and not self.match_contains(el, selector.contains):
|
| 1495 |
+
continue
|
| 1496 |
+
match = not is_not
|
| 1497 |
+
break
|
| 1498 |
+
|
| 1499 |
+
# Restore actual namespaces being used for external selector lists
|
| 1500 |
+
if is_html:
|
| 1501 |
+
self.namespaces = namespaces
|
| 1502 |
+
self.iframe_restrict = iframe_restrict
|
| 1503 |
+
|
| 1504 |
+
return match
|
| 1505 |
+
|
| 1506 |
+
def select(self, limit: int = 0) -> Iterator[bs4.Tag]:
|
| 1507 |
+
"""Match all tags under the targeted tag."""
|
| 1508 |
+
|
| 1509 |
+
lim = None if limit < 1 else limit
|
| 1510 |
+
|
| 1511 |
+
for child in self.get_tag_descendants(self.tag):
|
| 1512 |
+
if self.match(child):
|
| 1513 |
+
yield child
|
| 1514 |
+
if lim is not None:
|
| 1515 |
+
lim -= 1
|
| 1516 |
+
if lim < 1:
|
| 1517 |
+
break
|
| 1518 |
+
|
| 1519 |
+
def closest(self) -> bs4.Tag | None:
|
| 1520 |
+
"""Match closest ancestor."""
|
| 1521 |
+
|
| 1522 |
+
current = self.tag # type: bs4.Tag | None
|
| 1523 |
+
closest = None
|
| 1524 |
+
while closest is None and current is not None:
|
| 1525 |
+
if self.match(current):
|
| 1526 |
+
closest = current
|
| 1527 |
+
else:
|
| 1528 |
+
current = self.get_parent(current)
|
| 1529 |
+
return closest
|
| 1530 |
+
|
| 1531 |
+
def filter(self) -> list[bs4.Tag]: # noqa A001
|
| 1532 |
+
"""Filter tag's children."""
|
| 1533 |
+
|
| 1534 |
+
return [
|
| 1535 |
+
tag for tag in self.get_contents(self.tag)
|
| 1536 |
+
if isinstance(tag, bs4.Tag) and self.match(tag)
|
| 1537 |
+
]
|
| 1538 |
+
|
| 1539 |
+
def match(self, el: bs4.Tag) -> bool:
|
| 1540 |
+
"""Match."""
|
| 1541 |
+
|
| 1542 |
+
return not self.is_doc(el) and self.is_tag(el) and self.match_selectors(el, self.selectors)
|
| 1543 |
+
|
| 1544 |
+
|
| 1545 |
+
class SoupSieve(ct.Immutable):
|
| 1546 |
+
"""Compiled Soup Sieve selector matching object."""
|
| 1547 |
+
|
| 1548 |
+
pattern: str
|
| 1549 |
+
selectors: ct.SelectorList
|
| 1550 |
+
namespaces: ct.Namespaces | None
|
| 1551 |
+
custom: dict[str, str]
|
| 1552 |
+
flags: int
|
| 1553 |
+
|
| 1554 |
+
__slots__ = ("pattern", "selectors", "namespaces", "custom", "flags", "_hash")
|
| 1555 |
+
|
| 1556 |
+
def __init__(
|
| 1557 |
+
self,
|
| 1558 |
+
pattern: str,
|
| 1559 |
+
selectors: ct.SelectorList,
|
| 1560 |
+
namespaces: ct.Namespaces | None,
|
| 1561 |
+
custom: ct.CustomSelectors | None,
|
| 1562 |
+
flags: int
|
| 1563 |
+
):
|
| 1564 |
+
"""Initialize."""
|
| 1565 |
+
|
| 1566 |
+
super().__init__(
|
| 1567 |
+
pattern=pattern,
|
| 1568 |
+
selectors=selectors,
|
| 1569 |
+
namespaces=namespaces,
|
| 1570 |
+
custom=custom,
|
| 1571 |
+
flags=flags
|
| 1572 |
+
)
|
| 1573 |
+
|
| 1574 |
+
def match(self, tag: bs4.Tag) -> bool:
|
| 1575 |
+
"""Match."""
|
| 1576 |
+
|
| 1577 |
+
return CSSMatch(self.selectors, tag, self.namespaces, self.flags).match(tag)
|
| 1578 |
+
|
| 1579 |
+
def closest(self, tag: bs4.Tag) -> bs4.Tag | None:
|
| 1580 |
+
"""Match closest ancestor."""
|
| 1581 |
+
|
| 1582 |
+
return CSSMatch(self.selectors, tag, self.namespaces, self.flags).closest()
|
| 1583 |
+
|
| 1584 |
+
def filter(self, iterable: Iterable[bs4.Tag]) -> list[bs4.Tag]: # noqa A001
|
| 1585 |
+
"""
|
| 1586 |
+
Filter.
|
| 1587 |
+
|
| 1588 |
+
`CSSMatch` can cache certain searches for tags of the same document,
|
| 1589 |
+
so if we are given a tag, all tags are from the same document,
|
| 1590 |
+
and we can take advantage of the optimization.
|
| 1591 |
+
|
| 1592 |
+
Any other kind of iterable could have tags from different documents or detached tags,
|
| 1593 |
+
so for those, we use a new `CSSMatch` for each item in the iterable.
|
| 1594 |
+
"""
|
| 1595 |
+
|
| 1596 |
+
if isinstance(iterable, bs4.Tag):
|
| 1597 |
+
return CSSMatch(self.selectors, iterable, self.namespaces, self.flags).filter()
|
| 1598 |
+
else:
|
| 1599 |
+
return [node for node in iterable if not CSSMatch.is_navigable_string(node) and self.match(node)]
|
| 1600 |
+
|
| 1601 |
+
def select_one(self, tag: bs4.Tag) -> bs4.Tag | None:
|
| 1602 |
+
"""Select a single tag."""
|
| 1603 |
+
|
| 1604 |
+
tags = self.select(tag, limit=1)
|
| 1605 |
+
return tags[0] if tags else None
|
| 1606 |
+
|
| 1607 |
+
def select(self, tag: bs4.Tag, limit: int = 0) -> list[bs4.Tag]:
|
| 1608 |
+
"""Select the specified tags."""
|
| 1609 |
+
|
| 1610 |
+
return list(self.iselect(tag, limit))
|
| 1611 |
+
|
| 1612 |
+
def iselect(self, tag: bs4.Tag, limit: int = 0) -> Iterator[bs4.Tag]:
|
| 1613 |
+
"""Iterate the specified tags."""
|
| 1614 |
+
|
| 1615 |
+
yield from CSSMatch(self.selectors, tag, self.namespaces, self.flags).select(limit)
|
| 1616 |
+
|
| 1617 |
+
def __repr__(self) -> str: # pragma: no cover
|
| 1618 |
+
"""Representation."""
|
| 1619 |
+
|
| 1620 |
+
return (
|
| 1621 |
+
f"SoupSieve(pattern={self.pattern!r}, namespaces={self.namespaces!r}, "
|
| 1622 |
+
f"custom={self.custom!r}, flags={self.flags!r})"
|
| 1623 |
+
)
|
| 1624 |
+
|
| 1625 |
+
__str__ = __repr__
|
| 1626 |
+
|
| 1627 |
+
|
| 1628 |
+
ct.pickle_register(SoupSieve)
|
.venv/lib/python3.13/site-packages/soupsieve/css_parser.py
ADDED
|
@@ -0,0 +1,1359 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
from . import css_match as cm
|
| 7 |
+
from . import css_types as ct
|
| 8 |
+
from .util import SelectorSyntaxError
|
| 9 |
+
import warnings
|
| 10 |
+
from typing import Match, Any, Iterator, cast
|
| 11 |
+
from dataclasses import dataclass
|
| 12 |
+
from collections import UserDict
|
| 13 |
+
import threading
|
| 14 |
+
|
| 15 |
+
RE_LOCK = threading.Lock()
|
| 16 |
+
SEL_LOCK = threading.RLock()
|
| 17 |
+
|
| 18 |
+
UNICODE_REPLACEMENT_CHAR = 0xFFFD
|
| 19 |
+
|
| 20 |
+
SELECTOR_LIMIT = 8192
|
| 21 |
+
|
| 22 |
+
# Simple pseudo classes that take no parameters
|
| 23 |
+
PSEUDO_SIMPLE = {
|
| 24 |
+
":any-link",
|
| 25 |
+
":empty",
|
| 26 |
+
":first-child",
|
| 27 |
+
":first-of-type",
|
| 28 |
+
":in-range",
|
| 29 |
+
":open",
|
| 30 |
+
":out-of-range",
|
| 31 |
+
":last-child",
|
| 32 |
+
":last-of-type",
|
| 33 |
+
":link",
|
| 34 |
+
":only-child",
|
| 35 |
+
":only-of-type",
|
| 36 |
+
":root",
|
| 37 |
+
':checked',
|
| 38 |
+
':default',
|
| 39 |
+
':disabled',
|
| 40 |
+
':enabled',
|
| 41 |
+
':indeterminate',
|
| 42 |
+
':optional',
|
| 43 |
+
':placeholder-shown',
|
| 44 |
+
':read-only',
|
| 45 |
+
':read-write',
|
| 46 |
+
':required',
|
| 47 |
+
':scope',
|
| 48 |
+
':defined',
|
| 49 |
+
':muted'
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
# Supported, simple pseudo classes that match nothing in the Soup Sieve environment
|
| 53 |
+
PSEUDO_SIMPLE_NO_MATCH = {
|
| 54 |
+
':active',
|
| 55 |
+
':autofill',
|
| 56 |
+
':buffering',
|
| 57 |
+
':current',
|
| 58 |
+
':focus',
|
| 59 |
+
':focus-visible',
|
| 60 |
+
':focus-within',
|
| 61 |
+
':fullscreen',
|
| 62 |
+
':future',
|
| 63 |
+
':host',
|
| 64 |
+
':hover',
|
| 65 |
+
':local-link',
|
| 66 |
+
':past',
|
| 67 |
+
':paused',
|
| 68 |
+
':picture-in-picture',
|
| 69 |
+
':playing',
|
| 70 |
+
':popover-open',
|
| 71 |
+
':seeking',
|
| 72 |
+
':stalled',
|
| 73 |
+
':target',
|
| 74 |
+
':target-within',
|
| 75 |
+
':user-invalid',
|
| 76 |
+
':volume-locked',
|
| 77 |
+
':visited'
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
# Complex pseudo classes that take selector lists
|
| 81 |
+
PSEUDO_COMPLEX = {
|
| 82 |
+
':contains',
|
| 83 |
+
':-soup-contains',
|
| 84 |
+
':-soup-contains-own',
|
| 85 |
+
':has',
|
| 86 |
+
':is',
|
| 87 |
+
':matches',
|
| 88 |
+
':not',
|
| 89 |
+
':where'
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
PSEUDO_COMPLEX_NO_MATCH = {
|
| 93 |
+
':current',
|
| 94 |
+
':host',
|
| 95 |
+
':host-context'
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
# Complex pseudo classes that take very specific parameters and are handled special
|
| 99 |
+
PSEUDO_SPECIAL = {
|
| 100 |
+
':dir',
|
| 101 |
+
':lang',
|
| 102 |
+
':nth-child',
|
| 103 |
+
':nth-last-child',
|
| 104 |
+
':nth-last-of-type',
|
| 105 |
+
':nth-of-type'
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
PSEUDO_SUPPORTED = PSEUDO_SIMPLE | PSEUDO_SIMPLE_NO_MATCH | PSEUDO_COMPLEX | PSEUDO_COMPLEX_NO_MATCH | PSEUDO_SPECIAL
|
| 109 |
+
|
| 110 |
+
# Sub-patterns parts
|
| 111 |
+
# Whitespace
|
| 112 |
+
NEWLINE = r'(?:\r\n|(?!\r\n)[\n\f\r])'
|
| 113 |
+
WS = fr'(?:[ \t]|{NEWLINE})'
|
| 114 |
+
# Comments
|
| 115 |
+
COMMENTS = r'(?:/\*(?:[^*]|\*(?!/))*\*/)'
|
| 116 |
+
# Whitespace with comments included
|
| 117 |
+
WSC = fr'(?:{WS}|{COMMENTS})'
|
| 118 |
+
# CSS escapes
|
| 119 |
+
CSS_ESCAPES = fr'(?:\\(?:[a-f0-9]{{1,6}}{WS}?|[^\r\n\f]|$))'
|
| 120 |
+
CSS_STRING_ESCAPES = fr'(?:\\(?:[a-f0-9]{{1,6}}{WS}?|[^\r\n\f]|$|{NEWLINE}))'
|
| 121 |
+
# CSS Identifier
|
| 122 |
+
IDENTIFIER = fr'''
|
| 123 |
+
(?:(?:--|-?(?:[^\x00-\x2f\x30-\x40\x5B-\x5E\x60\x7B-\x9f]|{CSS_ESCAPES}))
|
| 124 |
+
(?:[^\x00-\x2c\x2e\x2f\x3A-\x40\x5B-\x5E\x60\x7B-\x9f]|{CSS_ESCAPES})*)
|
| 125 |
+
'''
|
| 126 |
+
# `nth` content
|
| 127 |
+
NTH = fr'(?:[-+])?(?:[0-9]+n?|n)(?:(?<=n){WSC}*(?:[-+]){WSC}*(?:[0-9]+))?'
|
| 128 |
+
# Value: quoted string or identifier
|
| 129 |
+
VALUE = fr'''(?:"(?:\\(?:.|{NEWLINE})|[^\\"\r\n\f])*?"|'(?:\\(?:.|{NEWLINE})|[^\\'\r\n\f])*?'|{IDENTIFIER})'''
|
| 130 |
+
# Attribute value comparison. `!=` is handled special as it is non-standard.
|
| 131 |
+
ATTR = fr'(?:{WSC}*(?P<cmp>[!~^|*$]?=){WSC}*(?P<value>{VALUE})(?:{WSC}*(?P<case>[is]))?)?{WSC}*'
|
| 132 |
+
|
| 133 |
+
# Selector patterns
|
| 134 |
+
# IDs (`#id`)
|
| 135 |
+
PAT_ID = fr'\#{IDENTIFIER}'
|
| 136 |
+
# Classes (`.class`)
|
| 137 |
+
PAT_CLASS = fr'\.{IDENTIFIER}'
|
| 138 |
+
# Prefix:Tag (`prefix|tag`)
|
| 139 |
+
PAT_TAG = fr'(?P<tag_ns>(?:{IDENTIFIER}|\*)?\|)?(?P<tag_name>{IDENTIFIER}|\*)'
|
| 140 |
+
# Attributes (`[attr]`, `[attr=value]`, etc.)
|
| 141 |
+
PAT_ATTR = fr'\[{WSC}*(?P<attr_ns>(?:{IDENTIFIER}|\*)?\|)?(?P<attr_name>{IDENTIFIER}){ATTR}\]'
|
| 142 |
+
# Pseudo class (`:pseudo-class`, `:pseudo-class(`)
|
| 143 |
+
PAT_PSEUDO_CLASS = fr'(?P<name>:{IDENTIFIER})(?P<open>\({WSC}*)?'
|
| 144 |
+
# Pseudo class special patterns. Matches `:pseudo-class(` for special case pseudo classes.
|
| 145 |
+
PAT_PSEUDO_CLASS_SPECIAL = fr'(?P<name>:{IDENTIFIER})(?P<open>\({WSC}*)'
|
| 146 |
+
# Custom pseudo class (`:--custom-pseudo`)
|
| 147 |
+
PAT_PSEUDO_CLASS_CUSTOM = fr'(?P<name>:(?=--){IDENTIFIER})'
|
| 148 |
+
# Nesting ampersand selector. Matches `&`
|
| 149 |
+
PAT_AMP = r'&'
|
| 150 |
+
# Closing pseudo group (`)`)
|
| 151 |
+
PAT_PSEUDO_CLOSE = fr'{WSC}*\)'
|
| 152 |
+
# Pseudo element (`::pseudo-element`)
|
| 153 |
+
PAT_PSEUDO_ELEMENT = fr':{PAT_PSEUDO_CLASS}'
|
| 154 |
+
# At rule (`@page`, etc.) (not supported)
|
| 155 |
+
PAT_AT_RULE = fr'@P{IDENTIFIER}'
|
| 156 |
+
# Pseudo class `nth-child` (`:nth-child(an+b [of S]?)`, `:first-child`, etc.)
|
| 157 |
+
PAT_PSEUDO_NTH_CHILD = fr'''
|
| 158 |
+
(?P<pseudo_nth_child>{PAT_PSEUDO_CLASS_SPECIAL}
|
| 159 |
+
(?P<nth_child>{NTH}|even|odd))(?:{WSC}*\)|(?P<of>{COMMENTS}*{WS}{WSC}*of{COMMENTS}*{WS}{WSC}*))
|
| 160 |
+
'''
|
| 161 |
+
# Pseudo class `nth-of-type` (`:nth-of-type(an+b)`, `:first-of-type`, etc.)
|
| 162 |
+
PAT_PSEUDO_NTH_TYPE = fr'''
|
| 163 |
+
(?P<pseudo_nth_type>{PAT_PSEUDO_CLASS_SPECIAL}
|
| 164 |
+
(?P<nth_type>{NTH}|even|odd)){WSC}*\)
|
| 165 |
+
'''
|
| 166 |
+
# Pseudo class language (`:lang("*-de", en)`)
|
| 167 |
+
PAT_PSEUDO_LANG = fr'{PAT_PSEUDO_CLASS_SPECIAL}(?P<values>{VALUE}(?:{WSC}*,{WSC}*{VALUE})*){WSC}*\)'
|
| 168 |
+
# Pseudo class direction (`:dir(ltr)`)
|
| 169 |
+
PAT_PSEUDO_DIR = fr'{PAT_PSEUDO_CLASS_SPECIAL}(?P<dir>ltr|rtl){WSC}*\)'
|
| 170 |
+
# Combining characters (`>`, `~`, ` `, `+`, `,`)
|
| 171 |
+
PAT_COMBINE = fr'{WSC}*?(?P<relation>[,+>~]|{WS}(?![,+>~])){WSC}*'
|
| 172 |
+
# Extra: Contains (`:contains(text)`)
|
| 173 |
+
PAT_PSEUDO_CONTAINS = fr'{PAT_PSEUDO_CLASS_SPECIAL}(?P<values>{VALUE}(?:{WSC}*,{WSC}*{VALUE})*){WSC}*\)'
|
| 174 |
+
|
| 175 |
+
# Regular expressions
|
| 176 |
+
# CSS escape pattern
|
| 177 |
+
RE_CSS_ESC = re.compile(fr'(?:(\\[a-f0-9]{{1,6}}{WSC}?)|(\\[^\r\n\f])|(\\$))', re.I)
|
| 178 |
+
RE_CSS_STR_ESC = re.compile(fr'(?:(\\[a-f0-9]{{1,6}}{WS}?)|(\\[^\r\n\f])|(\\$)|(\\{NEWLINE}))', re.I)
|
| 179 |
+
# Pattern to break up `nth` specifiers
|
| 180 |
+
RE_NTH = re.compile(fr'(?P<s1>[-+])?(?P<a>[0-9]+n?|n)(?:(?<=n){WSC}*(?P<s2>[-+]){WSC}*(?P<b>[0-9]+))?', re.I)
|
| 181 |
+
# Pattern to iterate multiple values.
|
| 182 |
+
RE_VALUES = re.compile(fr'(?:(?P<value>{VALUE})|(?P<split>{WSC}*,{WSC}*))', re.X)
|
| 183 |
+
# Whitespace checks
|
| 184 |
+
RE_WS = re.compile(WS)
|
| 185 |
+
RE_WS_BEGIN = re.compile(fr'^{WSC}*')
|
| 186 |
+
RE_WS_END = re.compile(fr'^(?:[ \t]|(?:\n\r|(?!\n\r)[\n\f\r])|{COMMENTS})*')
|
| 187 |
+
RE_CUSTOM = re.compile(fr'^{PAT_PSEUDO_CLASS_CUSTOM}$', re.X)
|
| 188 |
+
RE_PSEUDO_CLASS_SPECIAL = re.compile(PAT_PSEUDO_CLASS_SPECIAL, re.I | re.X | re.U)
|
| 189 |
+
|
| 190 |
+
QUOTED = ("'", '"')
|
| 191 |
+
|
| 192 |
+
# Constants
|
| 193 |
+
# List split token
|
| 194 |
+
COMMA_COMBINATOR = ','
|
| 195 |
+
# Relation token for descendant
|
| 196 |
+
WS_COMBINATOR = " "
|
| 197 |
+
|
| 198 |
+
# Parse flags
|
| 199 |
+
FLG_PSEUDO = 0x01
|
| 200 |
+
FLG_NOT = 0x02
|
| 201 |
+
FLG_RELATIVE = 0x04
|
| 202 |
+
FLG_DEFAULT = 0x08
|
| 203 |
+
FLG_HTML = 0x10
|
| 204 |
+
FLG_INDETERMINATE = 0x20
|
| 205 |
+
FLG_OPEN = 0x40
|
| 206 |
+
FLG_IN_RANGE = 0x80
|
| 207 |
+
FLG_OUT_OF_RANGE = 0x100
|
| 208 |
+
FLG_PLACEHOLDER_SHOWN = 0x200
|
| 209 |
+
FLG_FORGIVE = 0x400
|
| 210 |
+
|
| 211 |
+
# Maximum cached patterns to store
|
| 212 |
+
_MAXCACHE = 500
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
@lru_cache(maxsize=_MAXCACHE)
|
| 216 |
+
def _cached_css_compile(
|
| 217 |
+
pattern: str,
|
| 218 |
+
namespaces: ct.Namespaces | None,
|
| 219 |
+
custom: ct.CustomSelectors | None,
|
| 220 |
+
flags: int
|
| 221 |
+
) -> cm.SoupSieve:
|
| 222 |
+
"""Cached CSS compile."""
|
| 223 |
+
|
| 224 |
+
custom_selectors = process_custom(custom)
|
| 225 |
+
return cm.SoupSieve(
|
| 226 |
+
pattern,
|
| 227 |
+
CSSParser(
|
| 228 |
+
pattern,
|
| 229 |
+
custom=custom_selectors,
|
| 230 |
+
flags=flags
|
| 231 |
+
).process_selectors(),
|
| 232 |
+
namespaces,
|
| 233 |
+
custom,
|
| 234 |
+
flags
|
| 235 |
+
)
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
def _purge_cache() -> None:
|
| 239 |
+
"""Purge the cache."""
|
| 240 |
+
|
| 241 |
+
_cached_css_compile.cache_clear()
|
| 242 |
+
|
| 243 |
+
|
| 244 |
+
def process_custom(custom: ct.CustomSelectors | None) -> dict[str, str | ct.SelectorList]:
|
| 245 |
+
"""Process custom."""
|
| 246 |
+
|
| 247 |
+
custom_selectors = {}
|
| 248 |
+
if custom is not None:
|
| 249 |
+
for key, value in custom.items():
|
| 250 |
+
name = util.lower(key)
|
| 251 |
+
if RE_CUSTOM.match(name) is None:
|
| 252 |
+
raise SelectorSyntaxError(f"The name '{name}' is not a valid custom pseudo-class name")
|
| 253 |
+
if name in custom_selectors:
|
| 254 |
+
raise KeyError(f"The custom selector '{name}' has already been registered")
|
| 255 |
+
custom_selectors[css_unescape(name)] = value
|
| 256 |
+
return custom_selectors
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
def css_unescape(content: str) -> str:
|
| 260 |
+
"""
|
| 261 |
+
Unescape CSS value.
|
| 262 |
+
|
| 263 |
+
Strings allow for spanning the value on multiple strings by escaping a new line.
|
| 264 |
+
"""
|
| 265 |
+
|
| 266 |
+
def replace(m: Match[str]) -> str:
|
| 267 |
+
"""Replace with the appropriate substitute."""
|
| 268 |
+
|
| 269 |
+
if m.group(1):
|
| 270 |
+
codepoint = int(m.group(1)[1:], 16)
|
| 271 |
+
if codepoint == 0:
|
| 272 |
+
codepoint = UNICODE_REPLACEMENT_CHAR
|
| 273 |
+
value = chr(codepoint)
|
| 274 |
+
elif m.group(2):
|
| 275 |
+
value = m.group(2)[1:]
|
| 276 |
+
elif m.group(3):
|
| 277 |
+
value = '\ufffd'
|
| 278 |
+
else:
|
| 279 |
+
value = ''
|
| 280 |
+
|
| 281 |
+
return value
|
| 282 |
+
|
| 283 |
+
quoted = content.startswith(QUOTED)
|
| 284 |
+
return (RE_CSS_STR_ESC if quoted else RE_CSS_ESC).sub(
|
| 285 |
+
replace,
|
| 286 |
+
content[1:-1] if quoted else content
|
| 287 |
+
)
|
| 288 |
+
|
| 289 |
+
|
| 290 |
+
def escape(ident: str) -> str:
|
| 291 |
+
"""Escape identifier."""
|
| 292 |
+
|
| 293 |
+
string = []
|
| 294 |
+
length = len(ident)
|
| 295 |
+
start_dash = length > 0 and ident[0] == '-'
|
| 296 |
+
if length == 1 and start_dash:
|
| 297 |
+
# Need to escape identifier that is a single `-` with no other characters
|
| 298 |
+
string.append(f'\\{ident}')
|
| 299 |
+
else:
|
| 300 |
+
for index, c in enumerate(ident):
|
| 301 |
+
codepoint = ord(c)
|
| 302 |
+
if codepoint == 0x00:
|
| 303 |
+
string.append('\ufffd')
|
| 304 |
+
elif (0x01 <= codepoint <= 0x1F) or codepoint == 0x7F:
|
| 305 |
+
string.append(f'\\{codepoint:x} ')
|
| 306 |
+
elif (index == 0 or (start_dash and index == 1)) and (0x30 <= codepoint <= 0x39):
|
| 307 |
+
string.append(f'\\{codepoint:x} ')
|
| 308 |
+
elif (
|
| 309 |
+
codepoint in (0x2D, 0x5F) or codepoint >= 0x80 or (0x30 <= codepoint <= 0x39) or
|
| 310 |
+
(0x30 <= codepoint <= 0x39) or (0x41 <= codepoint <= 0x5A) or (0x61 <= codepoint <= 0x7A)
|
| 311 |
+
):
|
| 312 |
+
string.append(c)
|
| 313 |
+
else:
|
| 314 |
+
string.append(f'\\{c}')
|
| 315 |
+
return ''.join(string)
|
| 316 |
+
|
| 317 |
+
|
| 318 |
+
class SelectorPattern:
|
| 319 |
+
"""Selector pattern."""
|
| 320 |
+
|
| 321 |
+
def __init__(self, name: str, pattern: str) -> None:
|
| 322 |
+
"""Initialize."""
|
| 323 |
+
|
| 324 |
+
self.name = name
|
| 325 |
+
self.pattern = pattern
|
| 326 |
+
self._re_pattern: re.Pattern[str] | None = None
|
| 327 |
+
|
| 328 |
+
@property
|
| 329 |
+
def re_pattern(self) -> re.Pattern[str]:
|
| 330 |
+
"""Retrieve the compiled regular expression pattern."""
|
| 331 |
+
|
| 332 |
+
with RE_LOCK:
|
| 333 |
+
if self._re_pattern is None:
|
| 334 |
+
self._re_pattern = re.compile(self.pattern, re.I | re.X | re.U)
|
| 335 |
+
return self._re_pattern
|
| 336 |
+
|
| 337 |
+
def get_name(self) -> str:
|
| 338 |
+
"""Get name."""
|
| 339 |
+
|
| 340 |
+
return self.name
|
| 341 |
+
|
| 342 |
+
def match(self, selector: str, index: int, flags: int) -> Match[str] | None:
|
| 343 |
+
"""Match the selector."""
|
| 344 |
+
|
| 345 |
+
return self.re_pattern.match(selector, index)
|
| 346 |
+
|
| 347 |
+
|
| 348 |
+
class SpecialPseudoPattern(SelectorPattern):
|
| 349 |
+
"""Selector pattern."""
|
| 350 |
+
|
| 351 |
+
def __init__(self, patterns: tuple[tuple[str, tuple[str, ...], str, type[SelectorPattern]], ...]) -> None:
|
| 352 |
+
"""Initialize."""
|
| 353 |
+
|
| 354 |
+
self.patterns = {}
|
| 355 |
+
for p in patterns:
|
| 356 |
+
name = p[0]
|
| 357 |
+
pattern = p[3](name, p[2])
|
| 358 |
+
for pseudo in p[1]:
|
| 359 |
+
self.patterns[pseudo] = pattern
|
| 360 |
+
|
| 361 |
+
self.matched_name = None # type: SelectorPattern | None
|
| 362 |
+
|
| 363 |
+
def get_name(self) -> str:
|
| 364 |
+
"""Get name."""
|
| 365 |
+
|
| 366 |
+
return '' if self.matched_name is None else self.matched_name.get_name()
|
| 367 |
+
|
| 368 |
+
def match(self, selector: str, index: int, flags: int) -> Match[str] | None:
|
| 369 |
+
"""Match the selector."""
|
| 370 |
+
|
| 371 |
+
pseudo = None
|
| 372 |
+
m = RE_PSEUDO_CLASS_SPECIAL.match(selector, index)
|
| 373 |
+
if m:
|
| 374 |
+
name = util.lower(css_unescape(m.group('name')))
|
| 375 |
+
pattern = self.patterns.get(name)
|
| 376 |
+
if pattern:
|
| 377 |
+
pseudo = pattern.match(selector, index, flags)
|
| 378 |
+
if pseudo:
|
| 379 |
+
self.matched_name = pattern
|
| 380 |
+
|
| 381 |
+
return pseudo
|
| 382 |
+
|
| 383 |
+
|
| 384 |
+
class _Selector:
|
| 385 |
+
"""
|
| 386 |
+
Intermediate selector class.
|
| 387 |
+
|
| 388 |
+
This stores selector data for a compound selector as we are acquiring them.
|
| 389 |
+
Once we are done collecting the data for a compound selector, we freeze
|
| 390 |
+
the data in an object that can be pickled and hashed.
|
| 391 |
+
"""
|
| 392 |
+
|
| 393 |
+
def __init__(self, **kwargs: Any) -> None:
|
| 394 |
+
"""Initialize."""
|
| 395 |
+
|
| 396 |
+
self.tag = kwargs.get('tag', None) # type: ct.SelectorTag | None
|
| 397 |
+
self.ids = kwargs.get('ids', []) # type: list[str]
|
| 398 |
+
self.classes = kwargs.get('classes', []) # type: list[str]
|
| 399 |
+
self.attributes = kwargs.get('attributes', []) # type: list[ct.SelectorAttribute]
|
| 400 |
+
self.nth = kwargs.get('nth', []) # type: list[ct.SelectorNth]
|
| 401 |
+
self.selectors = kwargs.get('selectors', []) # type: list[ct.SelectorList]
|
| 402 |
+
self.relations = kwargs.get('relations', []) # type: list[_Selector]
|
| 403 |
+
self.rel_type = kwargs.get('rel_type', None) # type: str | None
|
| 404 |
+
self.contains = kwargs.get('contains', []) # type: list[ct.SelectorContains]
|
| 405 |
+
self.lang = kwargs.get('lang', []) # type: list[ct.SelectorLang]
|
| 406 |
+
self.flags = kwargs.get('flags', 0) # type: int
|
| 407 |
+
self.no_match = kwargs.get('no_match', False) # type: bool
|
| 408 |
+
|
| 409 |
+
def _freeze_relations(self, relations: list[_Selector]) -> ct.SelectorList:
|
| 410 |
+
"""Freeze relation."""
|
| 411 |
+
|
| 412 |
+
if relations:
|
| 413 |
+
sel = relations[0]
|
| 414 |
+
sel.relations.extend(relations[1:])
|
| 415 |
+
return ct.SelectorList([sel.freeze()])
|
| 416 |
+
else:
|
| 417 |
+
return ct.SelectorList()
|
| 418 |
+
|
| 419 |
+
def freeze(self) -> ct.Selector | ct.SelectorNull:
|
| 420 |
+
"""Freeze self."""
|
| 421 |
+
|
| 422 |
+
if self.no_match:
|
| 423 |
+
return ct.SelectorNull()
|
| 424 |
+
else:
|
| 425 |
+
return ct.Selector(
|
| 426 |
+
self.tag,
|
| 427 |
+
tuple(self.ids),
|
| 428 |
+
tuple(self.classes),
|
| 429 |
+
tuple(self.attributes),
|
| 430 |
+
tuple(self.nth),
|
| 431 |
+
tuple(self.selectors),
|
| 432 |
+
self._freeze_relations(self.relations),
|
| 433 |
+
self.rel_type,
|
| 434 |
+
tuple(self.contains),
|
| 435 |
+
tuple(self.lang),
|
| 436 |
+
self.flags
|
| 437 |
+
)
|
| 438 |
+
|
| 439 |
+
def __str__(self) -> str: # pragma: no cover
|
| 440 |
+
"""String representation."""
|
| 441 |
+
|
| 442 |
+
return (
|
| 443 |
+
f'_Selector(tag={self.tag!r}, ids={self.ids!r}, classes={self.classes!r}, attributes={self.attributes!r}, '
|
| 444 |
+
f'nth={self.nth!r}, selectors={self.selectors!r}, relations={self.relations!r}, '
|
| 445 |
+
f'rel_type={self.rel_type!r}, contains={self.contains!r}, lang={self.lang!r}, flags={self.flags!r}, '
|
| 446 |
+
f'no_match={self.no_match!r})'
|
| 447 |
+
)
|
| 448 |
+
|
| 449 |
+
__repr__ = __str__
|
| 450 |
+
|
| 451 |
+
|
| 452 |
+
@dataclass
|
| 453 |
+
class CSSPattern:
|
| 454 |
+
"""A CSS pattern that hasn't been processed by `CSSParser` yet."""
|
| 455 |
+
|
| 456 |
+
selector: str
|
| 457 |
+
flags: int
|
| 458 |
+
|
| 459 |
+
|
| 460 |
+
class PseudoSelectorMap(UserDict[str, CSSPattern | ct.SelectorList]):
|
| 461 |
+
"""Pseudo selector map."""
|
| 462 |
+
|
| 463 |
+
def __setitem__(self, key: str, value: CSSPattern | ct.SelectorList) -> None:
|
| 464 |
+
"""Set item."""
|
| 465 |
+
|
| 466 |
+
self.data[key] = value
|
| 467 |
+
|
| 468 |
+
def __getitem__(self, key: str) -> ct.SelectorList:
|
| 469 |
+
"""Get item."""
|
| 470 |
+
|
| 471 |
+
with SEL_LOCK:
|
| 472 |
+
value = self.data[key]
|
| 473 |
+
if isinstance(value, CSSPattern):
|
| 474 |
+
value = CSSParser(value.selector).process_selectors(flags=value.flags)
|
| 475 |
+
self.data[key] = value
|
| 476 |
+
|
| 477 |
+
return value
|
| 478 |
+
|
| 479 |
+
|
| 480 |
+
# CSS pattern for `:link` and `:any-link`
|
| 481 |
+
CSS_LINK = CSSPattern('html|*:is(a, area)[href]', FLG_PSEUDO | FLG_HTML)
|
| 482 |
+
# CSS pattern for `:checked`
|
| 483 |
+
CSS_CHECKED = CSSPattern(
|
| 484 |
+
'''
|
| 485 |
+
html|*:is(input[type=checkbox], input[type=radio])[checked], html|option[selected]
|
| 486 |
+
''',
|
| 487 |
+
FLG_PSEUDO | FLG_HTML
|
| 488 |
+
)
|
| 489 |
+
# CSS pattern for `:default` (must compile CSS_CHECKED first)
|
| 490 |
+
CSS_DEFAULT = CSSPattern(
|
| 491 |
+
'''
|
| 492 |
+
:checked,
|
| 493 |
+
|
| 494 |
+
/*
|
| 495 |
+
This pattern must be at the end.
|
| 496 |
+
Special logic is applied to the last selector.
|
| 497 |
+
*/
|
| 498 |
+
html|form html|*:is(button, input)[type="submit"]
|
| 499 |
+
''',
|
| 500 |
+
FLG_PSEUDO | FLG_HTML | FLG_DEFAULT
|
| 501 |
+
)
|
| 502 |
+
# CSS pattern for `:indeterminate`
|
| 503 |
+
CSS_INDETERMINATE = CSSPattern(
|
| 504 |
+
'''
|
| 505 |
+
html|input[type="checkbox"][indeterminate],
|
| 506 |
+
html|input[type="radio"]:is(:not([name]), [name=""]):not([checked]),
|
| 507 |
+
html|progress:not([value]),
|
| 508 |
+
|
| 509 |
+
/*
|
| 510 |
+
This pattern must be at the end.
|
| 511 |
+
Special logic is applied to the last selector.
|
| 512 |
+
*/
|
| 513 |
+
html|input[type="radio"][name]:not([name='']):not([checked])
|
| 514 |
+
''',
|
| 515 |
+
FLG_PSEUDO | FLG_HTML | FLG_INDETERMINATE
|
| 516 |
+
)
|
| 517 |
+
# CSS pattern for `:disabled`
|
| 518 |
+
CSS_DISABLED = CSSPattern(
|
| 519 |
+
'''
|
| 520 |
+
html|*:is(input:not([type=hidden]), button, select, textarea, fieldset, optgroup, option, fieldset)[disabled],
|
| 521 |
+
html|optgroup[disabled] > html|option,
|
| 522 |
+
html|fieldset[disabled] > html|*:is(input:not([type=hidden]), button, select, textarea, fieldset),
|
| 523 |
+
html|fieldset[disabled] >
|
| 524 |
+
html|*:not(legend:nth-of-type(1)) html|*:is(input:not([type=hidden]), button, select, textarea, fieldset)
|
| 525 |
+
''',
|
| 526 |
+
FLG_PSEUDO | FLG_HTML
|
| 527 |
+
)
|
| 528 |
+
# CSS pattern for `:enabled`
|
| 529 |
+
CSS_ENABLED = CSSPattern(
|
| 530 |
+
'''
|
| 531 |
+
html|*:is(input:not([type=hidden]), button, select, textarea, fieldset, optgroup, option, fieldset):not(:disabled)
|
| 532 |
+
''',
|
| 533 |
+
FLG_PSEUDO | FLG_HTML
|
| 534 |
+
)
|
| 535 |
+
# CSS pattern for `:required`
|
| 536 |
+
CSS_REQUIRED = CSSPattern('html|*:is(input, textarea, select)[required]', FLG_PSEUDO | FLG_HTML)
|
| 537 |
+
# CSS pattern for `:optional`
|
| 538 |
+
CSS_OPTIONAL = CSSPattern('html|*:is(input, textarea, select):not([required])', FLG_PSEUDO | FLG_HTML)
|
| 539 |
+
# CSS pattern for `:placeholder-shown`
|
| 540 |
+
CSS_PLACEHOLDER_SHOWN = CSSPattern(
|
| 541 |
+
'''
|
| 542 |
+
html|input:is(
|
| 543 |
+
:not([type]),
|
| 544 |
+
[type=""],
|
| 545 |
+
[type=text],
|
| 546 |
+
[type=search],
|
| 547 |
+
[type=url],
|
| 548 |
+
[type=tel],
|
| 549 |
+
[type=email],
|
| 550 |
+
[type=password],
|
| 551 |
+
[type=number]
|
| 552 |
+
)[placeholder]:not([placeholder='']):is(:not([value]), [value=""]),
|
| 553 |
+
html|textarea[placeholder]:not([placeholder=''])
|
| 554 |
+
''',
|
| 555 |
+
FLG_PSEUDO | FLG_HTML | FLG_PLACEHOLDER_SHOWN
|
| 556 |
+
)
|
| 557 |
+
# CSS pattern for `:read-write` (CSS_DISABLED must be compiled first)
|
| 558 |
+
CSS_READ_WRITE = CSSPattern(
|
| 559 |
+
'''
|
| 560 |
+
html|*:is(
|
| 561 |
+
textarea,
|
| 562 |
+
input:is(
|
| 563 |
+
:not([type]),
|
| 564 |
+
[type=""],
|
| 565 |
+
[type=text],
|
| 566 |
+
[type=search],
|
| 567 |
+
[type=url],
|
| 568 |
+
[type=tel],
|
| 569 |
+
[type=email],
|
| 570 |
+
[type=number],
|
| 571 |
+
[type=password],
|
| 572 |
+
[type=date],
|
| 573 |
+
[type=datetime-local],
|
| 574 |
+
[type=month],
|
| 575 |
+
[type=time],
|
| 576 |
+
[type=week]
|
| 577 |
+
)
|
| 578 |
+
):not([readonly], :disabled),
|
| 579 |
+
html|*:is([contenteditable=""], [contenteditable="true" i])
|
| 580 |
+
''',
|
| 581 |
+
FLG_PSEUDO | FLG_HTML
|
| 582 |
+
)
|
| 583 |
+
# CSS pattern for `:read-only`
|
| 584 |
+
CSS_READ_ONLY = CSSPattern('html|*:not(:read-write)', FLG_PSEUDO | FLG_HTML)
|
| 585 |
+
# CSS pattern for `:in-range`
|
| 586 |
+
CSS_IN_RANGE = CSSPattern(
|
| 587 |
+
'''
|
| 588 |
+
html|input:is(
|
| 589 |
+
[type="date"],
|
| 590 |
+
[type="month"],
|
| 591 |
+
[type="week"],
|
| 592 |
+
[type="time"],
|
| 593 |
+
[type="datetime-local"],
|
| 594 |
+
[type="number"],
|
| 595 |
+
[type="range"]
|
| 596 |
+
):is(
|
| 597 |
+
[min],
|
| 598 |
+
[max]
|
| 599 |
+
)
|
| 600 |
+
''',
|
| 601 |
+
FLG_PSEUDO | FLG_HTML | FLG_IN_RANGE
|
| 602 |
+
)
|
| 603 |
+
# CSS pattern for `:out-of-range`
|
| 604 |
+
CSS_OUT_OF_RANGE = CSSPattern(
|
| 605 |
+
'''
|
| 606 |
+
html|input:is(
|
| 607 |
+
[type="date"],
|
| 608 |
+
[type="month"],
|
| 609 |
+
[type="week"],
|
| 610 |
+
[type="time"],
|
| 611 |
+
[type="datetime-local"],
|
| 612 |
+
[type="number"],
|
| 613 |
+
[type="range"]
|
| 614 |
+
):is(
|
| 615 |
+
[min],
|
| 616 |
+
[max]
|
| 617 |
+
)
|
| 618 |
+
''',
|
| 619 |
+
FLG_PSEUDO | FLG_HTML | FLG_OUT_OF_RANGE
|
| 620 |
+
)
|
| 621 |
+
# CSS pattern for :open
|
| 622 |
+
CSS_OPEN = CSSPattern('html|*:is(details, dialog)[open]', FLG_PSEUDO | FLG_HTML)
|
| 623 |
+
# CSS pattern for :muted
|
| 624 |
+
CSS_MUTED = CSSPattern('html|*:is(video, audio)[muted]', FLG_PSEUDO | FLG_HTML)
|
| 625 |
+
# CSS pattern default for `:nth-child` "of S" feature
|
| 626 |
+
CSS_NTH_OF_S_DEFAULT = CSSPattern("*|*", FLG_PSEUDO)
|
| 627 |
+
|
| 628 |
+
|
| 629 |
+
class CSSParser:
|
| 630 |
+
"""Parse CSS selectors."""
|
| 631 |
+
|
| 632 |
+
CSS_TOKENS = (
|
| 633 |
+
SelectorPattern("pseudo_close", PAT_PSEUDO_CLOSE),
|
| 634 |
+
SpecialPseudoPattern(
|
| 635 |
+
(
|
| 636 |
+
(
|
| 637 |
+
"pseudo_contains",
|
| 638 |
+
(':contains', ':-soup-contains', ':-soup-contains-own'),
|
| 639 |
+
PAT_PSEUDO_CONTAINS,
|
| 640 |
+
SelectorPattern
|
| 641 |
+
),
|
| 642 |
+
("pseudo_nth_child", (':nth-child', ':nth-last-child'), PAT_PSEUDO_NTH_CHILD, SelectorPattern),
|
| 643 |
+
("pseudo_nth_type", (':nth-of-type', ':nth-last-of-type'), PAT_PSEUDO_NTH_TYPE, SelectorPattern),
|
| 644 |
+
("pseudo_lang", (':lang',), PAT_PSEUDO_LANG, SelectorPattern),
|
| 645 |
+
("pseudo_dir", (':dir',), PAT_PSEUDO_DIR, SelectorPattern)
|
| 646 |
+
)
|
| 647 |
+
),
|
| 648 |
+
SelectorPattern("pseudo_class_custom", PAT_PSEUDO_CLASS_CUSTOM),
|
| 649 |
+
SelectorPattern("pseudo_class", PAT_PSEUDO_CLASS),
|
| 650 |
+
SelectorPattern("pseudo_element", PAT_PSEUDO_ELEMENT),
|
| 651 |
+
SelectorPattern("amp", PAT_AMP),
|
| 652 |
+
SelectorPattern("at_rule", PAT_AT_RULE),
|
| 653 |
+
SelectorPattern("id", PAT_ID),
|
| 654 |
+
SelectorPattern("class", PAT_CLASS),
|
| 655 |
+
SelectorPattern("tag", PAT_TAG),
|
| 656 |
+
SelectorPattern("attribute", PAT_ATTR),
|
| 657 |
+
SelectorPattern("combine", PAT_COMBINE)
|
| 658 |
+
)
|
| 659 |
+
|
| 660 |
+
# Pseudos that expand to selectors
|
| 661 |
+
PSEUDO_SELECTORS = PseudoSelectorMap(
|
| 662 |
+
{
|
| 663 |
+
':link': CSS_LINK,
|
| 664 |
+
':any-link': CSS_LINK,
|
| 665 |
+
':checked': CSS_CHECKED,
|
| 666 |
+
':default': CSS_DEFAULT,
|
| 667 |
+
':indeterminate': CSS_INDETERMINATE,
|
| 668 |
+
':disabled': CSS_DISABLED,
|
| 669 |
+
':enabled': CSS_ENABLED,
|
| 670 |
+
':required': CSS_REQUIRED,
|
| 671 |
+
':muted': CSS_MUTED,
|
| 672 |
+
':open': CSS_OPEN,
|
| 673 |
+
':optional': CSS_OPTIONAL,
|
| 674 |
+
':read-only': CSS_READ_ONLY,
|
| 675 |
+
':read-write': CSS_READ_WRITE,
|
| 676 |
+
':in-range': CSS_IN_RANGE,
|
| 677 |
+
':out-of-range': CSS_OUT_OF_RANGE,
|
| 678 |
+
':placeholder-shown': CSS_PLACEHOLDER_SHOWN,
|
| 679 |
+
'<nth-of-s>': CSS_NTH_OF_S_DEFAULT
|
| 680 |
+
}
|
| 681 |
+
)
|
| 682 |
+
|
| 683 |
+
def __init__(
|
| 684 |
+
self,
|
| 685 |
+
selector: str,
|
| 686 |
+
custom: dict[str, str | ct.SelectorList] | None = None,
|
| 687 |
+
flags: int = 0
|
| 688 |
+
) -> None:
|
| 689 |
+
"""Initialize."""
|
| 690 |
+
|
| 691 |
+
self.pattern = selector.replace('\x00', '\ufffd')
|
| 692 |
+
self.flags = flags
|
| 693 |
+
self.debug = self.flags & util.DEBUG
|
| 694 |
+
self.custom = {} if custom is None else custom
|
| 695 |
+
self.count = 0
|
| 696 |
+
|
| 697 |
+
def increment_count(self, increment: int = 1) -> None:
|
| 698 |
+
"""Check the current selector count."""
|
| 699 |
+
|
| 700 |
+
self.count += increment
|
| 701 |
+
if self.count > SELECTOR_LIMIT:
|
| 702 |
+
raise ValueError(f'Selector exceeds pseudo-class nesting limit of {SELECTOR_LIMIT}')
|
| 703 |
+
|
| 704 |
+
def parse_attribute_selector(self, sel: _Selector, m: Match[str], has_selector: bool) -> bool:
|
| 705 |
+
"""Create attribute selector from the returned regex match."""
|
| 706 |
+
|
| 707 |
+
inverse = False
|
| 708 |
+
op = m.group('cmp')
|
| 709 |
+
case = util.lower(m.group('case')) if m.group('case') else None
|
| 710 |
+
ns = css_unescape(m.group('attr_ns')[:-1]) if m.group('attr_ns') else ''
|
| 711 |
+
attr = css_unescape(m.group('attr_name'))
|
| 712 |
+
is_type = False
|
| 713 |
+
pattern2 = None
|
| 714 |
+
value = ''
|
| 715 |
+
|
| 716 |
+
if case:
|
| 717 |
+
flags = (re.I if case == 'i' else 0) | re.DOTALL
|
| 718 |
+
elif util.lower(attr) == 'type':
|
| 719 |
+
flags = re.I | re.DOTALL
|
| 720 |
+
is_type = True
|
| 721 |
+
else:
|
| 722 |
+
flags = re.DOTALL
|
| 723 |
+
|
| 724 |
+
if op:
|
| 725 |
+
value = css_unescape(m.group('value'))
|
| 726 |
+
|
| 727 |
+
if not op:
|
| 728 |
+
# Attribute name
|
| 729 |
+
pattern = None
|
| 730 |
+
elif op.startswith('^'):
|
| 731 |
+
# Value start with
|
| 732 |
+
# `^=` should match nothing if the value is empty, so use `(?!)` which cannot be matched.
|
| 733 |
+
value = r'(?!)' if not value else re.escape(value)
|
| 734 |
+
pattern = re.compile(r'^%s.*' % value, flags)
|
| 735 |
+
elif op.startswith('$'):
|
| 736 |
+
# Value ends with
|
| 737 |
+
# `$=` should match nothing if the value is empty, so use `(?!)` which cannot be matched.
|
| 738 |
+
value = r'(?!)' if not value else re.escape(value)
|
| 739 |
+
pattern = re.compile(r'.*?%s$' % value, flags)
|
| 740 |
+
elif op.startswith('*'):
|
| 741 |
+
# Value contains
|
| 742 |
+
# `*=` should match nothing if the value is empty, so use `(?!)` which cannot be matched.
|
| 743 |
+
value = r'(?!)' if not value else re.escape(value)
|
| 744 |
+
pattern = re.compile(r'.*?%s.*' % value, flags)
|
| 745 |
+
elif op.startswith('~'):
|
| 746 |
+
# Value contains word within space separated list
|
| 747 |
+
# `*~` should match nothing if the value is empty, so use `(?!)` which cannot be matched.
|
| 748 |
+
value = r'(?!)' if not value or RE_WS.search(value) else re.escape(value)
|
| 749 |
+
pattern = re.compile(r'.*?(?:(?<=^)|(?<=[ \t\r\n\f]))%s(?=(?:[ \t\r\n\f]|$)).*' % value, flags)
|
| 750 |
+
elif op.startswith('|'):
|
| 751 |
+
# Value starts with word in dash separated list
|
| 752 |
+
pattern = re.compile(r'^%s(?:-.*)?$' % re.escape(value), flags)
|
| 753 |
+
else:
|
| 754 |
+
# Value matches
|
| 755 |
+
pattern = re.compile(r'^%s$' % re.escape(value), flags)
|
| 756 |
+
if op.startswith('!'):
|
| 757 |
+
# Equivalent to `:not([attr=value])`
|
| 758 |
+
inverse = True
|
| 759 |
+
if is_type and pattern:
|
| 760 |
+
pattern2 = re.compile(pattern.pattern)
|
| 761 |
+
|
| 762 |
+
# Append the attribute selector
|
| 763 |
+
sel_attr = ct.SelectorAttribute(attr, ns, pattern, pattern2)
|
| 764 |
+
if inverse:
|
| 765 |
+
# If we are using `!=`, we need to nest the pattern under a `:not()`.
|
| 766 |
+
sub_sel = _Selector()
|
| 767 |
+
sub_sel.attributes.append(sel_attr)
|
| 768 |
+
not_list = ct.SelectorList([sub_sel.freeze()], True, False)
|
| 769 |
+
sel.selectors.append(not_list)
|
| 770 |
+
else:
|
| 771 |
+
sel.attributes.append(sel_attr)
|
| 772 |
+
|
| 773 |
+
has_selector = True
|
| 774 |
+
return has_selector
|
| 775 |
+
|
| 776 |
+
def parse_tag_pattern(self, sel: _Selector, m: Match[str], has_selector: bool) -> bool:
|
| 777 |
+
"""Parse tag pattern from regex match."""
|
| 778 |
+
|
| 779 |
+
prefix = css_unescape(m.group('tag_ns')[:-1]) if m.group('tag_ns') else None
|
| 780 |
+
tag = css_unescape(m.group('tag_name'))
|
| 781 |
+
sel.tag = ct.SelectorTag(tag, prefix)
|
| 782 |
+
has_selector = True
|
| 783 |
+
return has_selector
|
| 784 |
+
|
| 785 |
+
def parse_pseudo_class_custom(self, sel: _Selector, m: Match[str], has_selector: bool) -> bool:
|
| 786 |
+
"""
|
| 787 |
+
Parse custom pseudo class alias.
|
| 788 |
+
|
| 789 |
+
Compile custom selectors as we need them. When compiling a custom selector,
|
| 790 |
+
set it to `None` in the dictionary so we can avoid an infinite loop.
|
| 791 |
+
"""
|
| 792 |
+
|
| 793 |
+
pseudo = util.lower(css_unescape(m.group('name')))
|
| 794 |
+
selector = self.custom.get(pseudo)
|
| 795 |
+
if selector is None:
|
| 796 |
+
raise SelectorSyntaxError(
|
| 797 |
+
f"Undefined custom selector '{pseudo}' found at position {m.end(0)}",
|
| 798 |
+
self.pattern,
|
| 799 |
+
m.end(0)
|
| 800 |
+
)
|
| 801 |
+
|
| 802 |
+
if not isinstance(selector, ct.SelectorList):
|
| 803 |
+
del self.custom[pseudo]
|
| 804 |
+
selector = CSSParser(
|
| 805 |
+
selector, custom=self.custom, flags=self.flags
|
| 806 |
+
).process_selectors(flags=FLG_PSEUDO)
|
| 807 |
+
self.custom[pseudo] = selector
|
| 808 |
+
|
| 809 |
+
self.increment_count(selector.count)
|
| 810 |
+
sel.selectors.append(selector)
|
| 811 |
+
has_selector = True
|
| 812 |
+
return has_selector
|
| 813 |
+
|
| 814 |
+
def parse_pseudo_class(
|
| 815 |
+
self,
|
| 816 |
+
sel: _Selector,
|
| 817 |
+
m: Match[str],
|
| 818 |
+
has_selector: bool,
|
| 819 |
+
iselector: Iterator[tuple[str, Match[str]]],
|
| 820 |
+
is_html: bool
|
| 821 |
+
) -> tuple[bool, bool]:
|
| 822 |
+
"""Parse pseudo class."""
|
| 823 |
+
|
| 824 |
+
complex_pseudo = False
|
| 825 |
+
pseudo = util.lower(css_unescape(m.group('name')))
|
| 826 |
+
if m.group('open'):
|
| 827 |
+
complex_pseudo = True
|
| 828 |
+
if complex_pseudo and pseudo in PSEUDO_COMPLEX:
|
| 829 |
+
has_selector = self.parse_pseudo_open(sel, pseudo, has_selector, iselector, m.end(0))
|
| 830 |
+
elif not complex_pseudo and pseudo in PSEUDO_SIMPLE:
|
| 831 |
+
if pseudo == ':root':
|
| 832 |
+
sel.flags |= ct.SEL_ROOT
|
| 833 |
+
elif pseudo == ':defined':
|
| 834 |
+
sel.flags |= ct.SEL_DEFINED
|
| 835 |
+
is_html = True
|
| 836 |
+
elif pseudo == ':scope':
|
| 837 |
+
sel.flags |= ct.SEL_SCOPE
|
| 838 |
+
elif pseudo == ':empty':
|
| 839 |
+
sel.flags |= ct.SEL_EMPTY
|
| 840 |
+
elif pseudo in self.PSEUDO_SELECTORS:
|
| 841 |
+
pseudo_selector = self.PSEUDO_SELECTORS[pseudo]
|
| 842 |
+
self.increment_count(pseudo_selector.count)
|
| 843 |
+
sel.selectors.append(pseudo_selector)
|
| 844 |
+
elif pseudo == ':first-child':
|
| 845 |
+
sel.nth.append(ct.SelectorNth(1, False, 0, False, False, ct.SelectorList()))
|
| 846 |
+
elif pseudo == ':last-child':
|
| 847 |
+
sel.nth.append(ct.SelectorNth(1, False, 0, False, True, ct.SelectorList()))
|
| 848 |
+
elif pseudo == ':first-of-type':
|
| 849 |
+
sel.nth.append(ct.SelectorNth(1, False, 0, True, False, ct.SelectorList()))
|
| 850 |
+
elif pseudo == ':last-of-type':
|
| 851 |
+
sel.nth.append(ct.SelectorNth(1, False, 0, True, True, ct.SelectorList()))
|
| 852 |
+
elif pseudo == ':only-child':
|
| 853 |
+
sel.nth.extend(
|
| 854 |
+
[
|
| 855 |
+
ct.SelectorNth(1, False, 0, False, False, ct.SelectorList()),
|
| 856 |
+
ct.SelectorNth(1, False, 0, False, True, ct.SelectorList())
|
| 857 |
+
]
|
| 858 |
+
)
|
| 859 |
+
elif pseudo == ':only-of-type':
|
| 860 |
+
sel.nth.extend(
|
| 861 |
+
[
|
| 862 |
+
ct.SelectorNth(1, False, 0, True, False, ct.SelectorList()),
|
| 863 |
+
ct.SelectorNth(1, False, 0, True, True, ct.SelectorList())
|
| 864 |
+
]
|
| 865 |
+
)
|
| 866 |
+
has_selector = True
|
| 867 |
+
elif complex_pseudo and pseudo in PSEUDO_COMPLEX_NO_MATCH:
|
| 868 |
+
self.parse_selectors(iselector, m.end(0), FLG_PSEUDO | FLG_OPEN)
|
| 869 |
+
sel.no_match = True
|
| 870 |
+
has_selector = True
|
| 871 |
+
elif not complex_pseudo and pseudo in PSEUDO_SIMPLE_NO_MATCH:
|
| 872 |
+
sel.no_match = True
|
| 873 |
+
has_selector = True
|
| 874 |
+
elif pseudo in PSEUDO_SUPPORTED:
|
| 875 |
+
raise SelectorSyntaxError(
|
| 876 |
+
f"Invalid syntax for pseudo class '{pseudo}'",
|
| 877 |
+
self.pattern,
|
| 878 |
+
m.start(0)
|
| 879 |
+
)
|
| 880 |
+
else:
|
| 881 |
+
raise SelectorSyntaxError(
|
| 882 |
+
f"'{pseudo}' was detected as a pseudo-class and is either unsupported or invalid. "
|
| 883 |
+
"If the syntax was not intended to be recognized as a pseudo-class, please escape the colon.",
|
| 884 |
+
self.pattern,
|
| 885 |
+
m.start(0)
|
| 886 |
+
)
|
| 887 |
+
|
| 888 |
+
return has_selector, is_html
|
| 889 |
+
|
| 890 |
+
def parse_pseudo_nth(
|
| 891 |
+
self,
|
| 892 |
+
sel: _Selector,
|
| 893 |
+
m: Match[str],
|
| 894 |
+
has_selector: bool,
|
| 895 |
+
iselector: Iterator[tuple[str, Match[str]]]
|
| 896 |
+
) -> bool:
|
| 897 |
+
"""Parse `nth` pseudo."""
|
| 898 |
+
|
| 899 |
+
mdict = m.groupdict()
|
| 900 |
+
if mdict.get('pseudo_nth_child'):
|
| 901 |
+
postfix = '_child'
|
| 902 |
+
else:
|
| 903 |
+
postfix = '_type'
|
| 904 |
+
mdict['name'] = util.lower(css_unescape(mdict['name']))
|
| 905 |
+
content = util.lower(mdict.get('nth' + postfix))
|
| 906 |
+
if content == 'even':
|
| 907 |
+
# 2n
|
| 908 |
+
s1 = 2
|
| 909 |
+
s2 = 0
|
| 910 |
+
var = True
|
| 911 |
+
elif content == 'odd':
|
| 912 |
+
# 2n+1
|
| 913 |
+
s1 = 2
|
| 914 |
+
s2 = 1
|
| 915 |
+
var = True
|
| 916 |
+
else:
|
| 917 |
+
nth_parts = cast(Match[str], RE_NTH.match(content))
|
| 918 |
+
_s1 = '-' if nth_parts.group('s1') and nth_parts.group('s1') == '-' else ''
|
| 919 |
+
a = nth_parts.group('a')
|
| 920 |
+
var = a.endswith('n')
|
| 921 |
+
if a.startswith('n'):
|
| 922 |
+
_s1 += '1'
|
| 923 |
+
elif var:
|
| 924 |
+
_s1 += a[:-1]
|
| 925 |
+
else:
|
| 926 |
+
_s1 += a
|
| 927 |
+
_s2 = '-' if nth_parts.group('s2') and nth_parts.group('s2') == '-' else ''
|
| 928 |
+
if nth_parts.group('b'):
|
| 929 |
+
_s2 += nth_parts.group('b')
|
| 930 |
+
else:
|
| 931 |
+
_s2 = '0'
|
| 932 |
+
s1 = int(_s1, 10)
|
| 933 |
+
s2 = int(_s2, 10)
|
| 934 |
+
|
| 935 |
+
pseudo_sel = mdict['name']
|
| 936 |
+
if postfix == '_child':
|
| 937 |
+
if m.group('of'):
|
| 938 |
+
# Parse the rest of `of S`.
|
| 939 |
+
nth_sel = self.parse_selectors(iselector, m.end(0), FLG_PSEUDO | FLG_OPEN)
|
| 940 |
+
else:
|
| 941 |
+
# Use default `*|*` for `of S`.
|
| 942 |
+
nth_sel = self.PSEUDO_SELECTORS['<nth-of-s>']
|
| 943 |
+
self.increment_count(nth_sel.count)
|
| 944 |
+
if pseudo_sel == ':nth-child':
|
| 945 |
+
sel.nth.append(ct.SelectorNth(s1, var, s2, False, False, nth_sel))
|
| 946 |
+
elif pseudo_sel == ':nth-last-child':
|
| 947 |
+
sel.nth.append(ct.SelectorNth(s1, var, s2, False, True, nth_sel))
|
| 948 |
+
else:
|
| 949 |
+
if pseudo_sel == ':nth-of-type':
|
| 950 |
+
sel.nth.append(ct.SelectorNth(s1, var, s2, True, False, ct.SelectorList()))
|
| 951 |
+
elif pseudo_sel == ':nth-last-of-type':
|
| 952 |
+
sel.nth.append(ct.SelectorNth(s1, var, s2, True, True, ct.SelectorList()))
|
| 953 |
+
has_selector = True
|
| 954 |
+
return has_selector
|
| 955 |
+
|
| 956 |
+
def parse_pseudo_open(
|
| 957 |
+
self,
|
| 958 |
+
sel: _Selector,
|
| 959 |
+
name: str,
|
| 960 |
+
has_selector: bool,
|
| 961 |
+
iselector: Iterator[tuple[str, Match[str]]],
|
| 962 |
+
index: int
|
| 963 |
+
) -> bool:
|
| 964 |
+
"""Parse pseudo with opening bracket."""
|
| 965 |
+
|
| 966 |
+
flags = FLG_PSEUDO | FLG_OPEN
|
| 967 |
+
if name == ':not':
|
| 968 |
+
flags |= FLG_NOT
|
| 969 |
+
elif name == ':has':
|
| 970 |
+
flags |= FLG_RELATIVE
|
| 971 |
+
elif name in (':where', ':is'):
|
| 972 |
+
flags |= FLG_FORGIVE
|
| 973 |
+
|
| 974 |
+
sel.selectors.append(self.parse_selectors(iselector, index, flags))
|
| 975 |
+
has_selector = True
|
| 976 |
+
|
| 977 |
+
return has_selector
|
| 978 |
+
|
| 979 |
+
def parse_has_combinator(
|
| 980 |
+
self,
|
| 981 |
+
sel: _Selector,
|
| 982 |
+
m: Match[str],
|
| 983 |
+
has_selector: bool,
|
| 984 |
+
selectors: list[_Selector],
|
| 985 |
+
rel_type: str,
|
| 986 |
+
index: int
|
| 987 |
+
) -> tuple[bool, _Selector, str]:
|
| 988 |
+
"""Parse combinator tokens."""
|
| 989 |
+
|
| 990 |
+
combinator = m.group('relation').strip()
|
| 991 |
+
if not combinator:
|
| 992 |
+
combinator = WS_COMBINATOR
|
| 993 |
+
if combinator == COMMA_COMBINATOR:
|
| 994 |
+
if not has_selector:
|
| 995 |
+
raise SelectorSyntaxError(
|
| 996 |
+
f"The combinator '{combinator}' at position {index}, must have a selector before it",
|
| 997 |
+
self.pattern,
|
| 998 |
+
index
|
| 999 |
+
)
|
| 1000 |
+
sel.rel_type = rel_type
|
| 1001 |
+
selectors[-1].relations.append(sel)
|
| 1002 |
+
rel_type = ":" + WS_COMBINATOR
|
| 1003 |
+
selectors.append(_Selector())
|
| 1004 |
+
else:
|
| 1005 |
+
if has_selector:
|
| 1006 |
+
# End the current selector and associate the leading combinator with this selector.
|
| 1007 |
+
sel.rel_type = rel_type
|
| 1008 |
+
selectors[-1].relations.append(sel)
|
| 1009 |
+
elif rel_type[1:] != WS_COMBINATOR:
|
| 1010 |
+
# It's impossible to have two whitespace combinators after each other as the patterns
|
| 1011 |
+
# will gobble up trailing whitespace. It is also impossible to have a whitespace
|
| 1012 |
+
# combinator after any other kind for the same reason. But we could have
|
| 1013 |
+
# multiple non-whitespace combinators. So if the current combinator is not a whitespace,
|
| 1014 |
+
# then we've hit the multiple combinator case, so we should fail.
|
| 1015 |
+
raise SelectorSyntaxError(
|
| 1016 |
+
f'The multiple combinators at position {index}',
|
| 1017 |
+
self.pattern,
|
| 1018 |
+
index
|
| 1019 |
+
)
|
| 1020 |
+
|
| 1021 |
+
# Set the leading combinator for the next selector.
|
| 1022 |
+
rel_type = ':' + combinator
|
| 1023 |
+
|
| 1024 |
+
sel = _Selector()
|
| 1025 |
+
has_selector = False
|
| 1026 |
+
return has_selector, sel, rel_type
|
| 1027 |
+
|
| 1028 |
+
def parse_combinator(
|
| 1029 |
+
self,
|
| 1030 |
+
sel: _Selector,
|
| 1031 |
+
m: Match[str],
|
| 1032 |
+
has_selector: bool,
|
| 1033 |
+
selectors: list[_Selector],
|
| 1034 |
+
relations: list[_Selector],
|
| 1035 |
+
is_pseudo: bool,
|
| 1036 |
+
is_forgive: bool,
|
| 1037 |
+
index: int
|
| 1038 |
+
) -> tuple[bool, _Selector]:
|
| 1039 |
+
"""Parse combinator tokens."""
|
| 1040 |
+
|
| 1041 |
+
combinator = m.group('relation').strip()
|
| 1042 |
+
if not combinator:
|
| 1043 |
+
combinator = WS_COMBINATOR
|
| 1044 |
+
if not has_selector:
|
| 1045 |
+
if not is_forgive or combinator != COMMA_COMBINATOR:
|
| 1046 |
+
raise SelectorSyntaxError(
|
| 1047 |
+
f"The combinator '{combinator}' at position {index}, must have a selector before it",
|
| 1048 |
+
self.pattern,
|
| 1049 |
+
index
|
| 1050 |
+
)
|
| 1051 |
+
|
| 1052 |
+
# If we are in a forgiving pseudo class, just make the selector a "no match"
|
| 1053 |
+
if combinator == COMMA_COMBINATOR:
|
| 1054 |
+
self.increment_count()
|
| 1055 |
+
del relations[:]
|
| 1056 |
+
else:
|
| 1057 |
+
if combinator == COMMA_COMBINATOR:
|
| 1058 |
+
if not sel.tag and not is_pseudo:
|
| 1059 |
+
# Implied `*`
|
| 1060 |
+
sel.tag = ct.SelectorTag('*', None)
|
| 1061 |
+
sel.relations.extend(relations)
|
| 1062 |
+
selectors.append(sel)
|
| 1063 |
+
del relations[:]
|
| 1064 |
+
else:
|
| 1065 |
+
sel.relations.extend(relations)
|
| 1066 |
+
sel.rel_type = combinator
|
| 1067 |
+
del relations[:]
|
| 1068 |
+
relations.append(sel)
|
| 1069 |
+
|
| 1070 |
+
sel = _Selector()
|
| 1071 |
+
has_selector = False
|
| 1072 |
+
|
| 1073 |
+
return has_selector, sel
|
| 1074 |
+
|
| 1075 |
+
def parse_class_id(self, sel: _Selector, m: Match[str], has_selector: bool) -> bool:
|
| 1076 |
+
"""Parse HTML classes and ids."""
|
| 1077 |
+
|
| 1078 |
+
selector = m.group(0)
|
| 1079 |
+
if selector.startswith('.'):
|
| 1080 |
+
sel.classes.append(css_unescape(selector[1:]))
|
| 1081 |
+
else:
|
| 1082 |
+
sel.ids.append(css_unescape(selector[1:]))
|
| 1083 |
+
has_selector = True
|
| 1084 |
+
return has_selector
|
| 1085 |
+
|
| 1086 |
+
def parse_pseudo_contains(self, sel: _Selector, m: Match[str], has_selector: bool) -> bool:
|
| 1087 |
+
"""Parse contains."""
|
| 1088 |
+
|
| 1089 |
+
pseudo = util.lower(css_unescape(m.group('name')))
|
| 1090 |
+
if pseudo == ":contains":
|
| 1091 |
+
warnings.warn( # noqa: B028
|
| 1092 |
+
"The pseudo class ':contains' is deprecated, ':-soup-contains' should be used moving forward.",
|
| 1093 |
+
FutureWarning
|
| 1094 |
+
)
|
| 1095 |
+
contains_own = pseudo == ":-soup-contains-own"
|
| 1096 |
+
patterns = [
|
| 1097 |
+
css_unescape(token.group('value'))
|
| 1098 |
+
for token in RE_VALUES.finditer(m.group('values'))
|
| 1099 |
+
if not token.group('split')
|
| 1100 |
+
]
|
| 1101 |
+
sel.contains.append(ct.SelectorContains(patterns, contains_own))
|
| 1102 |
+
has_selector = True
|
| 1103 |
+
return has_selector
|
| 1104 |
+
|
| 1105 |
+
def parse_pseudo_lang(self, sel: _Selector, m: Match[str], has_selector: bool) -> bool:
|
| 1106 |
+
"""Parse pseudo language."""
|
| 1107 |
+
|
| 1108 |
+
patterns = [
|
| 1109 |
+
css_unescape(token.group('value'))
|
| 1110 |
+
for token in RE_VALUES.finditer(m.group('values'))
|
| 1111 |
+
if not token.group('split')
|
| 1112 |
+
]
|
| 1113 |
+
sel.lang.append(ct.SelectorLang(patterns))
|
| 1114 |
+
has_selector = True
|
| 1115 |
+
|
| 1116 |
+
return has_selector
|
| 1117 |
+
|
| 1118 |
+
def parse_pseudo_dir(self, sel: _Selector, m: Match[str], has_selector: bool) -> bool:
|
| 1119 |
+
"""Parse pseudo direction."""
|
| 1120 |
+
|
| 1121 |
+
value = ct.SEL_DIR_LTR if util.lower(m.group('dir')) == 'ltr' else ct.SEL_DIR_RTL
|
| 1122 |
+
sel.flags |= value
|
| 1123 |
+
has_selector = True
|
| 1124 |
+
return has_selector
|
| 1125 |
+
|
| 1126 |
+
def parse_selectors(
|
| 1127 |
+
self,
|
| 1128 |
+
iselector: Iterator[tuple[str, Match[str]]],
|
| 1129 |
+
index: int = 0,
|
| 1130 |
+
flags: int = 0
|
| 1131 |
+
) -> ct.SelectorList:
|
| 1132 |
+
"""Parse selectors."""
|
| 1133 |
+
|
| 1134 |
+
# Initialize important variables
|
| 1135 |
+
sel = _Selector()
|
| 1136 |
+
selectors = []
|
| 1137 |
+
has_selector = False
|
| 1138 |
+
closed = False
|
| 1139 |
+
relations = [] # type: list[_Selector]
|
| 1140 |
+
rel_type = ":" + WS_COMBINATOR
|
| 1141 |
+
count = self.count
|
| 1142 |
+
|
| 1143 |
+
# Setup various flags
|
| 1144 |
+
is_open = bool(flags & FLG_OPEN)
|
| 1145 |
+
is_pseudo = bool(flags & FLG_PSEUDO)
|
| 1146 |
+
is_relative = bool(flags & FLG_RELATIVE)
|
| 1147 |
+
is_not = bool(flags & FLG_NOT)
|
| 1148 |
+
is_html = bool(flags & FLG_HTML)
|
| 1149 |
+
is_default = bool(flags & FLG_DEFAULT)
|
| 1150 |
+
is_indeterminate = bool(flags & FLG_INDETERMINATE)
|
| 1151 |
+
is_in_range = bool(flags & FLG_IN_RANGE)
|
| 1152 |
+
is_out_of_range = bool(flags & FLG_OUT_OF_RANGE)
|
| 1153 |
+
is_placeholder_shown = bool(flags & FLG_PLACEHOLDER_SHOWN)
|
| 1154 |
+
is_forgive = bool(flags & FLG_FORGIVE)
|
| 1155 |
+
|
| 1156 |
+
# Print out useful debug stuff
|
| 1157 |
+
if self.debug: # pragma: no cover
|
| 1158 |
+
if is_pseudo:
|
| 1159 |
+
print(' is_pseudo: True')
|
| 1160 |
+
if is_open:
|
| 1161 |
+
print(' is_open: True')
|
| 1162 |
+
if is_relative:
|
| 1163 |
+
print(' is_relative: True')
|
| 1164 |
+
if is_not:
|
| 1165 |
+
print(' is_not: True')
|
| 1166 |
+
if is_html:
|
| 1167 |
+
print(' is_html: True')
|
| 1168 |
+
if is_default:
|
| 1169 |
+
print(' is_default: True')
|
| 1170 |
+
if is_indeterminate:
|
| 1171 |
+
print(' is_indeterminate: True')
|
| 1172 |
+
if is_in_range:
|
| 1173 |
+
print(' is_in_range: True')
|
| 1174 |
+
if is_out_of_range:
|
| 1175 |
+
print(' is_out_of_range: True')
|
| 1176 |
+
if is_placeholder_shown:
|
| 1177 |
+
print(' is_placeholder_shown: True')
|
| 1178 |
+
if is_forgive:
|
| 1179 |
+
print(' is_forgive: True')
|
| 1180 |
+
|
| 1181 |
+
# The algorithm for relative selectors require an initial selector in the selector list
|
| 1182 |
+
if is_relative:
|
| 1183 |
+
selectors.append(_Selector())
|
| 1184 |
+
|
| 1185 |
+
try:
|
| 1186 |
+
while True:
|
| 1187 |
+
key, m = next(iselector)
|
| 1188 |
+
|
| 1189 |
+
if key not in ('combine', 'pseudo_close'):
|
| 1190 |
+
self.increment_count()
|
| 1191 |
+
|
| 1192 |
+
# Handle parts
|
| 1193 |
+
if key == "at_rule":
|
| 1194 |
+
raise NotImplementedError(f"At-rules found at position {m.start(0)}")
|
| 1195 |
+
elif key == "amp":
|
| 1196 |
+
sel.flags |= ct.SEL_SCOPE
|
| 1197 |
+
has_selector = True
|
| 1198 |
+
elif key == 'pseudo_class_custom':
|
| 1199 |
+
has_selector = self.parse_pseudo_class_custom(sel, m, has_selector)
|
| 1200 |
+
elif key == 'pseudo_class':
|
| 1201 |
+
has_selector, is_html = self.parse_pseudo_class(sel, m, has_selector, iselector, is_html)
|
| 1202 |
+
elif key == 'pseudo_element':
|
| 1203 |
+
raise NotImplementedError(f"Pseudo-element found at position {m.start(0)}")
|
| 1204 |
+
elif key == 'pseudo_contains':
|
| 1205 |
+
has_selector = self.parse_pseudo_contains(sel, m, has_selector)
|
| 1206 |
+
elif key in ('pseudo_nth_type', 'pseudo_nth_child'):
|
| 1207 |
+
has_selector = self.parse_pseudo_nth(sel, m, has_selector, iselector)
|
| 1208 |
+
elif key == 'pseudo_lang':
|
| 1209 |
+
has_selector = self.parse_pseudo_lang(sel, m, has_selector)
|
| 1210 |
+
elif key == 'pseudo_dir':
|
| 1211 |
+
has_selector = self.parse_pseudo_dir(sel, m, has_selector)
|
| 1212 |
+
# Currently only supports HTML
|
| 1213 |
+
is_html = True
|
| 1214 |
+
elif key == 'pseudo_close':
|
| 1215 |
+
if not has_selector:
|
| 1216 |
+
if not is_forgive:
|
| 1217 |
+
raise SelectorSyntaxError(
|
| 1218 |
+
f"Expected a selector at position {m.start(0)}",
|
| 1219 |
+
self.pattern,
|
| 1220 |
+
m.start(0)
|
| 1221 |
+
)
|
| 1222 |
+
sel.no_match = True
|
| 1223 |
+
if is_open:
|
| 1224 |
+
closed = True
|
| 1225 |
+
break
|
| 1226 |
+
else:
|
| 1227 |
+
raise SelectorSyntaxError(
|
| 1228 |
+
f"Unmatched pseudo-class close at position {m.start(0)}",
|
| 1229 |
+
self.pattern,
|
| 1230 |
+
m.start(0)
|
| 1231 |
+
)
|
| 1232 |
+
elif key == 'combine':
|
| 1233 |
+
if is_relative:
|
| 1234 |
+
has_selector, sel, rel_type = self.parse_has_combinator(
|
| 1235 |
+
sel, m, has_selector, selectors, rel_type, index
|
| 1236 |
+
)
|
| 1237 |
+
else:
|
| 1238 |
+
has_selector, sel = self.parse_combinator(
|
| 1239 |
+
sel, m, has_selector, selectors, relations, is_pseudo, is_forgive, index
|
| 1240 |
+
)
|
| 1241 |
+
elif key == 'attribute':
|
| 1242 |
+
has_selector = self.parse_attribute_selector(sel, m, has_selector)
|
| 1243 |
+
elif key == 'tag':
|
| 1244 |
+
if has_selector:
|
| 1245 |
+
raise SelectorSyntaxError(
|
| 1246 |
+
f"Tag name found at position {m.start(0)} instead of at the start",
|
| 1247 |
+
self.pattern,
|
| 1248 |
+
m.start(0)
|
| 1249 |
+
)
|
| 1250 |
+
has_selector = self.parse_tag_pattern(sel, m, has_selector)
|
| 1251 |
+
elif key in ('class', 'id'):
|
| 1252 |
+
has_selector = self.parse_class_id(sel, m, has_selector)
|
| 1253 |
+
|
| 1254 |
+
index = m.end(0)
|
| 1255 |
+
except StopIteration:
|
| 1256 |
+
pass
|
| 1257 |
+
|
| 1258 |
+
# Handle selectors that are not closed
|
| 1259 |
+
if is_open and not closed:
|
| 1260 |
+
raise SelectorSyntaxError(
|
| 1261 |
+
f"Unclosed pseudo-class at position {index}",
|
| 1262 |
+
self.pattern,
|
| 1263 |
+
index
|
| 1264 |
+
)
|
| 1265 |
+
|
| 1266 |
+
# Cleanup completed selector piece
|
| 1267 |
+
if has_selector:
|
| 1268 |
+
if not sel.tag and not is_pseudo:
|
| 1269 |
+
# Implied `*`
|
| 1270 |
+
sel.tag = ct.SelectorTag('*', None)
|
| 1271 |
+
if is_relative:
|
| 1272 |
+
sel.rel_type = rel_type
|
| 1273 |
+
selectors[-1].relations.append(sel)
|
| 1274 |
+
else:
|
| 1275 |
+
sel.relations.extend(relations)
|
| 1276 |
+
del relations[:]
|
| 1277 |
+
selectors.append(sel)
|
| 1278 |
+
|
| 1279 |
+
# Forgive empty slots in pseudo-classes that have lists (and are forgiving)
|
| 1280 |
+
elif is_forgive and (not selectors or not relations):
|
| 1281 |
+
# Handle normal pseudo-classes with empty slots like `:is()` etc.
|
| 1282 |
+
self.increment_count()
|
| 1283 |
+
sel.no_match = True
|
| 1284 |
+
del relations[:]
|
| 1285 |
+
selectors.append(sel)
|
| 1286 |
+
has_selector = True
|
| 1287 |
+
|
| 1288 |
+
if not has_selector:
|
| 1289 |
+
# We will always need to finish a selector when `:has()` is used as it leads with combining.
|
| 1290 |
+
# May apply to others as well.
|
| 1291 |
+
raise SelectorSyntaxError(
|
| 1292 |
+
f'Expected a selector at position {index}',
|
| 1293 |
+
self.pattern,
|
| 1294 |
+
index
|
| 1295 |
+
)
|
| 1296 |
+
|
| 1297 |
+
# Some patterns require additional logic, such as default. We try to make these the
|
| 1298 |
+
# last pattern, and append the appropriate flag to that selector which communicates
|
| 1299 |
+
# to the matcher what additional logic is required.
|
| 1300 |
+
if is_default:
|
| 1301 |
+
selectors[-1].flags = ct.SEL_DEFAULT
|
| 1302 |
+
if is_indeterminate:
|
| 1303 |
+
selectors[-1].flags = ct.SEL_INDETERMINATE
|
| 1304 |
+
if is_in_range:
|
| 1305 |
+
selectors[-1].flags = ct.SEL_IN_RANGE
|
| 1306 |
+
if is_out_of_range:
|
| 1307 |
+
selectors[-1].flags = ct.SEL_OUT_OF_RANGE
|
| 1308 |
+
if is_placeholder_shown:
|
| 1309 |
+
selectors[-1].flags = ct.SEL_PLACEHOLDER_SHOWN
|
| 1310 |
+
|
| 1311 |
+
# Return selector list
|
| 1312 |
+
return ct.SelectorList([s.freeze() for s in selectors], is_not, is_html, self.count - count)
|
| 1313 |
+
|
| 1314 |
+
def selector_iter(self, pattern: str) -> Iterator[tuple[str, Match[str]]]:
|
| 1315 |
+
"""Iterate selector tokens."""
|
| 1316 |
+
|
| 1317 |
+
# Ignore whitespace and comments at start and end of pattern
|
| 1318 |
+
m = RE_WS_BEGIN.search(pattern)
|
| 1319 |
+
index = m.end(0) if m else 0
|
| 1320 |
+
m = RE_WS_END.search(pattern[::-1])
|
| 1321 |
+
offset = m.end(0) if m else 0
|
| 1322 |
+
end = len(pattern) - (1 + offset)
|
| 1323 |
+
|
| 1324 |
+
if self.debug: # pragma: no cover
|
| 1325 |
+
print(f'## PARSING: {pattern!r}')
|
| 1326 |
+
while index <= end:
|
| 1327 |
+
m = None
|
| 1328 |
+
for v in self.CSS_TOKENS:
|
| 1329 |
+
m = v.match(pattern, index, self.flags)
|
| 1330 |
+
if m:
|
| 1331 |
+
name = v.get_name()
|
| 1332 |
+
if self.debug: # pragma: no cover
|
| 1333 |
+
print(f"TOKEN: '{name}' --> {m.group(0)!r} at position {m.start(0)}")
|
| 1334 |
+
index = m.end(0)
|
| 1335 |
+
yield name, m
|
| 1336 |
+
break
|
| 1337 |
+
if m is None:
|
| 1338 |
+
c = pattern[index]
|
| 1339 |
+
# If the character represents the start of one of the known selector types,
|
| 1340 |
+
# throw an exception mentioning that the known selector type is in error;
|
| 1341 |
+
# otherwise, report the invalid character.
|
| 1342 |
+
if c == '[':
|
| 1343 |
+
msg = f"Malformed attribute selector at position {index}"
|
| 1344 |
+
elif c == '.':
|
| 1345 |
+
msg = f"Malformed class selector at position {index}"
|
| 1346 |
+
elif c == '#':
|
| 1347 |
+
msg = f"Malformed id selector at position {index}"
|
| 1348 |
+
elif c == ':':
|
| 1349 |
+
msg = f"Malformed pseudo-class selector at position {index}"
|
| 1350 |
+
else:
|
| 1351 |
+
msg = f"Invalid character {c!r} position {index}"
|
| 1352 |
+
raise SelectorSyntaxError(msg, self.pattern, index)
|
| 1353 |
+
if self.debug: # pragma: no cover
|
| 1354 |
+
print('## END PARSING')
|
| 1355 |
+
|
| 1356 |
+
def process_selectors(self, index: int = 0, flags: int = 0) -> ct.SelectorList:
|
| 1357 |
+
"""Process selectors."""
|
| 1358 |
+
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""CSS selector structure items."""
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
import copyreg
|
| 4 |
+
from .pretty import pretty
|
| 5 |
+
from typing import Any, Iterator, Hashable, Pattern, Iterable, Mapping
|
| 6 |
+
|
| 7 |
+
__all__ = (
|
| 8 |
+
'Selector',
|
| 9 |
+
'SelectorNull',
|
| 10 |
+
'SelectorTag',
|
| 11 |
+
'SelectorAttribute',
|
| 12 |
+
'SelectorContains',
|
| 13 |
+
'SelectorNth',
|
| 14 |
+
'SelectorLang',
|
| 15 |
+
'SelectorList',
|
| 16 |
+
'Namespaces',
|
| 17 |
+
'CustomSelectors'
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
SEL_EMPTY = 0x1
|
| 22 |
+
SEL_ROOT = 0x2
|
| 23 |
+
SEL_DEFAULT = 0x4
|
| 24 |
+
SEL_INDETERMINATE = 0x8
|
| 25 |
+
SEL_SCOPE = 0x10
|
| 26 |
+
SEL_DIR_LTR = 0x20
|
| 27 |
+
SEL_DIR_RTL = 0x40
|
| 28 |
+
SEL_IN_RANGE = 0x80
|
| 29 |
+
SEL_OUT_OF_RANGE = 0x100
|
| 30 |
+
SEL_DEFINED = 0x200
|
| 31 |
+
SEL_PLACEHOLDER_SHOWN = 0x400
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class Immutable:
|
| 35 |
+
"""Immutable."""
|
| 36 |
+
|
| 37 |
+
__slots__: tuple[str, ...] = ('_hash',)
|
| 38 |
+
|
| 39 |
+
_hash: int
|
| 40 |
+
|
| 41 |
+
def __init__(self, **kwargs: Any) -> None:
|
| 42 |
+
"""Initialize."""
|
| 43 |
+
|
| 44 |
+
temp = []
|
| 45 |
+
for k, v in kwargs.items():
|
| 46 |
+
temp.append(type(v))
|
| 47 |
+
temp.append(v)
|
| 48 |
+
super().__setattr__(k, v)
|
| 49 |
+
super().__setattr__('_hash', hash(tuple(temp)))
|
| 50 |
+
|
| 51 |
+
@classmethod
|
| 52 |
+
def __base__(cls) -> type[Immutable]:
|
| 53 |
+
"""Get base class."""
|
| 54 |
+
|
| 55 |
+
return cls
|
| 56 |
+
|
| 57 |
+
def __eq__(self, other: Any) -> bool:
|
| 58 |
+
"""Equal."""
|
| 59 |
+
|
| 60 |
+
return (
|
| 61 |
+
isinstance(other, self.__base__()) and
|
| 62 |
+
all(getattr(other, key) == getattr(self, key) for key in self.__slots__ if key != '_hash')
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
+
def __ne__(self, other: Any) -> bool:
|
| 66 |
+
"""Equal."""
|
| 67 |
+
|
| 68 |
+
return (
|
| 69 |
+
not isinstance(other, self.__base__()) or
|
| 70 |
+
any(getattr(other, key) != getattr(self, key) for key in self.__slots__ if key != '_hash')
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
def __hash__(self) -> int:
|
| 74 |
+
"""Hash."""
|
| 75 |
+
|
| 76 |
+
return self._hash
|
| 77 |
+
|
| 78 |
+
def __setattr__(self, name: str, value: Any) -> None:
|
| 79 |
+
"""Prevent mutability."""
|
| 80 |
+
|
| 81 |
+
raise AttributeError(f"'{self.__class__.__name__}' is immutable")
|
| 82 |
+
|
| 83 |
+
def __repr__(self) -> str: # pragma: no cover
|
| 84 |
+
"""Representation."""
|
| 85 |
+
|
| 86 |
+
r = ', '.join([f"{k}={getattr(self, k)!r}" for k in self.__slots__[:-1]])
|
| 87 |
+
return f"{self.__class__.__name__}({r})"
|
| 88 |
+
|
| 89 |
+
__str__ = __repr__
|
| 90 |
+
|
| 91 |
+
def pretty(self) -> None: # pragma: no cover
|
| 92 |
+
"""Pretty print."""
|
| 93 |
+
|
| 94 |
+
print(pretty(self))
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
class ImmutableDict(Mapping[Any, Any]):
|
| 98 |
+
"""Hashable, immutable dictionary."""
|
| 99 |
+
|
| 100 |
+
def __init__(
|
| 101 |
+
self,
|
| 102 |
+
arg: dict[Any, Any] | Iterable[tuple[Any, Any]]
|
| 103 |
+
) -> None:
|
| 104 |
+
"""Initialize."""
|
| 105 |
+
|
| 106 |
+
self._validate(arg)
|
| 107 |
+
self._d = dict(arg)
|
| 108 |
+
self._hash = hash(tuple([(type(x), x, type(y), y) for x, y in sorted(self._d.items())]))
|
| 109 |
+
|
| 110 |
+
def _validate(self, arg: dict[Any, Any] | Iterable[tuple[Any, Any]]) -> None:
|
| 111 |
+
"""Validate arguments."""
|
| 112 |
+
|
| 113 |
+
if isinstance(arg, dict):
|
| 114 |
+
if not all(isinstance(v, Hashable) for v in arg.values()):
|
| 115 |
+
raise TypeError(f'{self.__class__.__name__} values must be hashable')
|
| 116 |
+
elif not all(isinstance(k, Hashable) and isinstance(v, Hashable) for k, v in arg):
|
| 117 |
+
raise TypeError(f'{self.__class__.__name__} values must be hashable')
|
| 118 |
+
|
| 119 |
+
def __iter__(self) -> Iterator[Any]:
|
| 120 |
+
"""Iterator."""
|
| 121 |
+
|
| 122 |
+
return iter(self._d)
|
| 123 |
+
|
| 124 |
+
def __len__(self) -> int:
|
| 125 |
+
"""Length."""
|
| 126 |
+
|
| 127 |
+
return len(self._d)
|
| 128 |
+
|
| 129 |
+
def __getitem__(self, key: Any) -> Any:
|
| 130 |
+
"""Get item: `namespace['key']`."""
|
| 131 |
+
|
| 132 |
+
return self._d[key]
|
| 133 |
+
|
| 134 |
+
def __hash__(self) -> int:
|
| 135 |
+
"""Hash."""
|
| 136 |
+
|
| 137 |
+
return self._hash
|
| 138 |
+
|
| 139 |
+
def __repr__(self) -> str: # pragma: no cover
|
| 140 |
+
"""Representation."""
|
| 141 |
+
|
| 142 |
+
return f"{self._d!r}"
|
| 143 |
+
|
| 144 |
+
__str__ = __repr__
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
class Namespaces(ImmutableDict):
|
| 148 |
+
"""Namespaces."""
|
| 149 |
+
|
| 150 |
+
def __init__(self, arg: dict[str, str] | Iterable[tuple[str, str]]) -> None:
|
| 151 |
+
"""Initialize."""
|
| 152 |
+
|
| 153 |
+
super().__init__(arg)
|
| 154 |
+
|
| 155 |
+
def _validate(self, arg: dict[str, str] | Iterable[tuple[str, str]]) -> None:
|
| 156 |
+
"""Validate arguments."""
|
| 157 |
+
|
| 158 |
+
if not all(
|
| 159 |
+
isinstance(k, str) and isinstance(v, str)
|
| 160 |
+
for k, v in (arg.items() if isinstance(arg, dict) else arg)
|
| 161 |
+
):
|
| 162 |
+
raise TypeError(f'{self.__class__.__name__} values must be hashable')
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
class CustomSelectors(ImmutableDict):
|
| 166 |
+
"""Custom selectors."""
|
| 167 |
+
|
| 168 |
+
def __init__(self, arg: dict[str, str] | Iterable[tuple[str, str]]) -> None:
|
| 169 |
+
"""Initialize."""
|
| 170 |
+
|
| 171 |
+
super().__init__(arg)
|
| 172 |
+
|
| 173 |
+
def _validate(self, arg: dict[str, str] | Iterable[tuple[str, str]]) -> None:
|
| 174 |
+
"""Validate arguments."""
|
| 175 |
+
|
| 176 |
+
if not all(
|
| 177 |
+
isinstance(k, str) and isinstance(v, str)
|
| 178 |
+
for k, v in (arg.items() if isinstance(arg, dict) else arg)
|
| 179 |
+
):
|
| 180 |
+
raise TypeError(f'{self.__class__.__name__} values must be hashable')
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
class Selector(Immutable):
|
| 184 |
+
"""Selector."""
|
| 185 |
+
|
| 186 |
+
__slots__ = (
|
| 187 |
+
'tag', 'ids', 'classes', 'attributes', 'nth', 'selectors',
|
| 188 |
+
'relation', 'rel_type', 'contains', 'lang', 'flags', '_hash'
|
| 189 |
+
)
|
| 190 |
+
|
| 191 |
+
tag: SelectorTag | None
|
| 192 |
+
ids: tuple[str, ...]
|
| 193 |
+
classes: tuple[str, ...]
|
| 194 |
+
attributes: tuple[SelectorAttribute, ...]
|
| 195 |
+
nth: tuple[SelectorNth, ...]
|
| 196 |
+
selectors: tuple[SelectorList, ...]
|
| 197 |
+
relation: SelectorList
|
| 198 |
+
rel_type: str | None
|
| 199 |
+
contains: tuple[SelectorContains, ...]
|
| 200 |
+
lang: tuple[SelectorLang, ...]
|
| 201 |
+
flags: int
|
| 202 |
+
|
| 203 |
+
def __init__(
|
| 204 |
+
self,
|
| 205 |
+
tag: SelectorTag | None,
|
| 206 |
+
ids: tuple[str, ...],
|
| 207 |
+
classes: tuple[str, ...],
|
| 208 |
+
attributes: tuple[SelectorAttribute, ...],
|
| 209 |
+
nth: tuple[SelectorNth, ...],
|
| 210 |
+
selectors: tuple[SelectorList, ...],
|
| 211 |
+
relation: SelectorList,
|
| 212 |
+
rel_type: str | None,
|
| 213 |
+
contains: tuple[SelectorContains, ...],
|
| 214 |
+
lang: tuple[SelectorLang, ...],
|
| 215 |
+
flags: int
|
| 216 |
+
):
|
| 217 |
+
"""Initialize."""
|
| 218 |
+
|
| 219 |
+
super().__init__(
|
| 220 |
+
tag=tag,
|
| 221 |
+
ids=ids,
|
| 222 |
+
classes=classes,
|
| 223 |
+
attributes=attributes,
|
| 224 |
+
nth=nth,
|
| 225 |
+
selectors=selectors,
|
| 226 |
+
relation=relation,
|
| 227 |
+
rel_type=rel_type,
|
| 228 |
+
contains=contains,
|
| 229 |
+
lang=lang,
|
| 230 |
+
flags=flags
|
| 231 |
+
)
|
| 232 |
+
|
| 233 |
+
|
| 234 |
+
class SelectorNull(Immutable):
|
| 235 |
+
"""Null Selector."""
|
| 236 |
+
|
| 237 |
+
def __init__(self) -> None:
|
| 238 |
+
"""Initialize."""
|
| 239 |
+
|
| 240 |
+
super().__init__()
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
class SelectorTag(Immutable):
|
| 244 |
+
"""Selector tag."""
|
| 245 |
+
|
| 246 |
+
__slots__ = ("name", "prefix", "_hash")
|
| 247 |
+
|
| 248 |
+
name: str
|
| 249 |
+
prefix: str | None
|
| 250 |
+
|
| 251 |
+
def __init__(self, name: str, prefix: str | None) -> None:
|
| 252 |
+
"""Initialize."""
|
| 253 |
+
|
| 254 |
+
super().__init__(name=name, prefix=prefix)
|
| 255 |
+
|
| 256 |
+
|
| 257 |
+
class SelectorAttribute(Immutable):
|
| 258 |
+
"""Selector attribute rule."""
|
| 259 |
+
|
| 260 |
+
__slots__ = ("attribute", "prefix", "pattern", "xml_type_pattern", "_hash")
|
| 261 |
+
|
| 262 |
+
attribute: str
|
| 263 |
+
prefix: str
|
| 264 |
+
pattern: Pattern[str] | None
|
| 265 |
+
xml_type_pattern: Pattern[str] | None
|
| 266 |
+
|
| 267 |
+
def __init__(
|
| 268 |
+
self,
|
| 269 |
+
attribute: str,
|
| 270 |
+
prefix: str,
|
| 271 |
+
pattern: Pattern[str] | None,
|
| 272 |
+
xml_type_pattern: Pattern[str] | None
|
| 273 |
+
) -> None:
|
| 274 |
+
"""Initialize."""
|
| 275 |
+
|
| 276 |
+
super().__init__(
|
| 277 |
+
attribute=attribute,
|
| 278 |
+
prefix=prefix,
|
| 279 |
+
pattern=pattern,
|
| 280 |
+
xml_type_pattern=xml_type_pattern
|
| 281 |
+
)
|
| 282 |
+
|
| 283 |
+
|
| 284 |
+
class SelectorContains(Immutable):
|
| 285 |
+
"""Selector contains rule."""
|
| 286 |
+
|
| 287 |
+
__slots__ = ("text", "own", "_hash")
|
| 288 |
+
|
| 289 |
+
text: tuple[str, ...]
|
| 290 |
+
own: bool
|
| 291 |
+
|
| 292 |
+
def __init__(self, text: Iterable[str], own: bool) -> None:
|
| 293 |
+
"""Initialize."""
|
| 294 |
+
|
| 295 |
+
super().__init__(text=tuple(text), own=own)
|
| 296 |
+
|
| 297 |
+
|
| 298 |
+
class SelectorNth(Immutable):
|
| 299 |
+
"""Selector nth type."""
|
| 300 |
+
|
| 301 |
+
__slots__ = ("a", "n", "b", "of_type", "last", "selectors", "_hash")
|
| 302 |
+
|
| 303 |
+
a: int
|
| 304 |
+
n: bool
|
| 305 |
+
b: int
|
| 306 |
+
of_type: bool
|
| 307 |
+
last: bool
|
| 308 |
+
selectors: SelectorList
|
| 309 |
+
|
| 310 |
+
def __init__(self, a: int, n: bool, b: int, of_type: bool, last: bool, selectors: SelectorList) -> None:
|
| 311 |
+
"""Initialize."""
|
| 312 |
+
|
| 313 |
+
super().__init__(
|
| 314 |
+
a=a,
|
| 315 |
+
n=n,
|
| 316 |
+
b=b,
|
| 317 |
+
of_type=of_type,
|
| 318 |
+
last=last,
|
| 319 |
+
selectors=selectors
|
| 320 |
+
)
|
| 321 |
+
|
| 322 |
+
|
| 323 |
+
class SelectorLang(Immutable):
|
| 324 |
+
"""Selector language rules."""
|
| 325 |
+
|
| 326 |
+
__slots__ = ("languages", "_hash",)
|
| 327 |
+
|
| 328 |
+
languages: tuple[str, ...]
|
| 329 |
+
|
| 330 |
+
def __init__(self, languages: Iterable[str]):
|
| 331 |
+
"""Initialize."""
|
| 332 |
+
|
| 333 |
+
super().__init__(languages=tuple(languages))
|
| 334 |
+
|
| 335 |
+
def __iter__(self) -> Iterator[str]:
|
| 336 |
+
"""Iterator."""
|
| 337 |
+
|
| 338 |
+
return iter(self.languages)
|
| 339 |
+
|
| 340 |
+
def __len__(self) -> int: # pragma: no cover
|
| 341 |
+
"""Length."""
|
| 342 |
+
|
| 343 |
+
return len(self.languages)
|
| 344 |
+
|
| 345 |
+
def __getitem__(self, index: int) -> str: # pragma: no cover
|
| 346 |
+
"""Get item."""
|
| 347 |
+
|
| 348 |
+
return self.languages[index]
|
| 349 |
+
|
| 350 |
+
|
| 351 |
+
class SelectorList(Immutable):
|
| 352 |
+
"""Selector list."""
|
| 353 |
+
|
| 354 |
+
__slots__ = ("selectors", "is_not", "is_html", "count", "_hash")
|
| 355 |
+
|
| 356 |
+
selectors: tuple[Selector | SelectorNull, ...]
|
| 357 |
+
is_not: bool
|
| 358 |
+
is_html: bool
|
| 359 |
+
count: int
|
| 360 |
+
|
| 361 |
+
def __init__(
|
| 362 |
+
self,
|
| 363 |
+
selectors: Iterable[Selector | SelectorNull] | None = None,
|
| 364 |
+
is_not: bool = False,
|
| 365 |
+
is_html: bool = False,
|
| 366 |
+
count: int = 0,
|
| 367 |
+
) -> None:
|
| 368 |
+
"""Initialize."""
|
| 369 |
+
|
| 370 |
+
super().__init__(
|
| 371 |
+
selectors=tuple(selectors) if selectors is not None else (),
|
| 372 |
+
is_not=is_not,
|
| 373 |
+
is_html=is_html,
|
| 374 |
+
count=count
|
| 375 |
+
)
|
| 376 |
+
|
| 377 |
+
def __iter__(self) -> Iterator[Selector | SelectorNull]:
|
| 378 |
+
"""Iterator."""
|
| 379 |
+
|
| 380 |
+
return iter(self.selectors)
|
| 381 |
+
|
| 382 |
+
def __len__(self) -> int:
|
| 383 |
+
"""Length."""
|
| 384 |
+
|
| 385 |
+
return len(self.selectors)
|
| 386 |
+
|
| 387 |
+
def __getitem__(self, index: int) -> Selector | SelectorNull:
|
| 388 |
+
"""Get item."""
|
| 389 |
+
|
| 390 |
+
return self.selectors[index]
|
| 391 |
+
|
| 392 |
+
|
| 393 |
+
def _pickle(p: Any) -> Any:
|
| 394 |
+
return p.__base__(), tuple([getattr(p, s) for s in p.__slots__[:-1]])
|
| 395 |
+
|
| 396 |
+
|
| 397 |
+
def pickle_register(obj: Any) -> None:
|
| 398 |
+
"""Allow object to be pickled."""
|
| 399 |
+
|
| 400 |
+
copyreg.pickle(obj, _pickle)
|
| 401 |
+
|
| 402 |
+
|
| 403 |
+
pickle_register(Selector)
|
| 404 |
+
pickle_register(SelectorNull)
|
| 405 |
+
pickle_register(SelectorTag)
|
| 406 |
+
pickle_register(SelectorAttribute)
|
| 407 |
+
pickle_register(SelectorContains)
|
| 408 |
+
pickle_register(SelectorNth)
|
| 409 |
+
pickle_register(SelectorLang)
|
| 410 |
+
pickle_register(SelectorList)
|
.venv/lib/python3.13/site-packages/soupsieve/pretty.py
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Format a pretty string of a `SoupSieve` object for easy debugging.
|
| 3 |
+
|
| 4 |
+
This won't necessarily support all types and such, and definitely
|
| 5 |
+
not support custom outputs.
|
| 6 |
+
|
| 7 |
+
It is mainly geared towards our types as the `SelectorList`
|
| 8 |
+
object is a beast to look at without some indentation and newlines.
|
| 9 |
+
The format and various output types is fairly known (though it
|
| 10 |
+
hasn't been tested extensively to make sure we aren't missing corners).
|
| 11 |
+
|
| 12 |
+
Example:
|
| 13 |
+
-------
|
| 14 |
+
```
|
| 15 |
+
>>> import soupsieve as sv
|
| 16 |
+
>>> sv.compile('this > that.class[name=value]').selectors.pretty()
|
| 17 |
+
SelectorList(
|
| 18 |
+
selectors=(
|
| 19 |
+
Selector(
|
| 20 |
+
tag=SelectorTag(
|
| 21 |
+
name='that',
|
| 22 |
+
prefix=None),
|
| 23 |
+
ids=(),
|
| 24 |
+
classes=(
|
| 25 |
+
'class',
|
| 26 |
+
),
|
| 27 |
+
attributes=(
|
| 28 |
+
SelectorAttribute(
|
| 29 |
+
attribute='name',
|
| 30 |
+
prefix='',
|
| 31 |
+
pattern=re.compile(
|
| 32 |
+
'^value$'),
|
| 33 |
+
xml_type_pattern=None),
|
| 34 |
+
),
|
| 35 |
+
nth=(),
|
| 36 |
+
selectors=(),
|
| 37 |
+
relation=SelectorList(
|
| 38 |
+
selectors=(
|
| 39 |
+
Selector(
|
| 40 |
+
tag=SelectorTag(
|
| 41 |
+
name='this',
|
| 42 |
+
prefix=None),
|
| 43 |
+
ids=(),
|
| 44 |
+
classes=(),
|
| 45 |
+
attributes=(),
|
| 46 |
+
nth=(),
|
| 47 |
+
selectors=(),
|
| 48 |
+
relation=SelectorList(
|
| 49 |
+
selectors=(),
|
| 50 |
+
is_not=False,
|
| 51 |
+
is_html=False),
|
| 52 |
+
rel_type='>',
|
| 53 |
+
contains=(),
|
| 54 |
+
lang=(),
|
| 55 |
+
flags=0),
|
| 56 |
+
),
|
| 57 |
+
is_not=False,
|
| 58 |
+
is_html=False),
|
| 59 |
+
rel_type=None,
|
| 60 |
+
contains=(),
|
| 61 |
+
lang=(),
|
| 62 |
+
flags=0),
|
| 63 |
+
),
|
| 64 |
+
is_not=False,
|
| 65 |
+
is_html=False)
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
"""
|
| 69 |
+
from __future__ import annotations
|
| 70 |
+
import re
|
| 71 |
+
from typing import Any
|
| 72 |
+
|
| 73 |
+
RE_CLASS = re.compile(r'(?i)[a-z_][_a-z\d.]+\(')
|
| 74 |
+
RE_PARAM = re.compile(r'(?i)[_a-z][_a-z\d]+=')
|
| 75 |
+
RE_EMPTY = re.compile(r'\(\)|\[\]|\{\}')
|
| 76 |
+
RE_LSTRT = re.compile(r'\[')
|
| 77 |
+
RE_DSTRT = re.compile(r'\{')
|
| 78 |
+
RE_TSTRT = re.compile(r'\(')
|
| 79 |
+
RE_LEND = re.compile(r'\]')
|
| 80 |
+
RE_DEND = re.compile(r'\}')
|
| 81 |
+
RE_TEND = re.compile(r'\)')
|
| 82 |
+
RE_INT = re.compile(r'\d+')
|
| 83 |
+
RE_KWORD = re.compile(r'(?i)[_a-z][_a-z\d.]+')
|
| 84 |
+
RE_DQSTR = re.compile(r'"(?:\\.|[^"\\])*"')
|
| 85 |
+
RE_SQSTR = re.compile(r"'(?:\\.|[^'\\])*'")
|
| 86 |
+
RE_SEP = re.compile(r'\s*(,)\s*')
|
| 87 |
+
RE_DSEP = re.compile(r'\s*(:)\s*')
|
| 88 |
+
RE_PSEP = re.compile(r'\s*(\|)\s*')
|
| 89 |
+
|
| 90 |
+
TOKENS = {
|
| 91 |
+
'class': RE_CLASS,
|
| 92 |
+
'param': RE_PARAM,
|
| 93 |
+
'empty': RE_EMPTY,
|
| 94 |
+
'lstrt': RE_LSTRT,
|
| 95 |
+
'dstrt': RE_DSTRT,
|
| 96 |
+
'tstrt': RE_TSTRT,
|
| 97 |
+
'lend': RE_LEND,
|
| 98 |
+
'dend': RE_DEND,
|
| 99 |
+
'tend': RE_TEND,
|
| 100 |
+
'sqstr': RE_SQSTR,
|
| 101 |
+
'sep': RE_SEP,
|
| 102 |
+
'dsep': RE_DSEP,
|
| 103 |
+
'psep': RE_PSEP,
|
| 104 |
+
'int': RE_INT,
|
| 105 |
+
'kword': RE_KWORD,
|
| 106 |
+
'dqstr': RE_DQSTR
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
def pretty(obj: Any) -> str: # pragma: no cover
|
| 111 |
+
"""Make the object output string pretty."""
|
| 112 |
+
|
| 113 |
+
sel = str(obj)
|
| 114 |
+
index = 0
|
| 115 |
+
end = len(sel) - 1
|
| 116 |
+
indent = 0
|
| 117 |
+
output = []
|
| 118 |
+
|
| 119 |
+
while index <= end:
|
| 120 |
+
m = None
|
| 121 |
+
for k, v in TOKENS.items():
|
| 122 |
+
m = v.match(sel, index)
|
| 123 |
+
|
| 124 |
+
if m:
|
| 125 |
+
name = k
|
| 126 |
+
index = m.end(0)
|
| 127 |
+
if name in ('class', 'lstrt', 'dstrt', 'tstrt'):
|
| 128 |
+
indent += 4
|
| 129 |
+
output.append(f'{m.group(0)}\n{" " * indent}')
|
| 130 |
+
elif name in ('param', 'int', 'kword', 'sqstr', 'dqstr', 'empty'):
|
| 131 |
+
output.append(m.group(0))
|
| 132 |
+
elif name in ('lend', 'dend', 'tend'):
|
| 133 |
+
indent -= 4
|
| 134 |
+
output.append(m.group(0))
|
| 135 |
+
elif name in ('sep',):
|
| 136 |
+
output.append(f'{m.group(1)}\n{" " * indent}')
|
| 137 |
+
elif name in ('dsep',):
|
| 138 |
+
output.append(f'{m.group(1)} ')
|
| 139 |
+
elif name in ('psep'):
|
| 140 |
+
output.append(f' {m.group(1)} ')
|
| 141 |
+
break
|
| 142 |
+
|
| 143 |
+
# We shouldn't hit this, but if we do, store unrecognized character
|
| 144 |
+
if m is None: # pragma: no cover
|
| 145 |
+
output.append(sel[index])
|
| 146 |
+
index += 1
|
| 147 |
+
|
| 148 |
+
return ''.join(output)
|
.venv/lib/python3.13/site-packages/soupsieve/py.typed
ADDED
|
File without changes
|
.venv/lib/python3.13/site-packages/soupsieve/util.py
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Utility."""
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
from functools import wraps, lru_cache
|
| 4 |
+
import warnings
|
| 5 |
+
import re
|
| 6 |
+
from typing import Callable, Any
|
| 7 |
+
|
| 8 |
+
DEBUG = 0x00001
|
| 9 |
+
|
| 10 |
+
RE_PATTERN_LINE_SPLIT = re.compile(r'(?:\r\n|(?!\r\n)[\n\r])|$')
|
| 11 |
+
|
| 12 |
+
UC_A = ord('A')
|
| 13 |
+
UC_Z = ord('Z')
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
@lru_cache(maxsize=512)
|
| 17 |
+
def lower(string: str) -> str:
|
| 18 |
+
"""Lower."""
|
| 19 |
+
|
| 20 |
+
new_string = []
|
| 21 |
+
for c in string:
|
| 22 |
+
o = ord(c)
|
| 23 |
+
new_string.append(chr(o + 32) if UC_A <= o <= UC_Z else c)
|
| 24 |
+
return ''.join(new_string)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class SelectorSyntaxError(Exception):
|
| 28 |
+
"""Syntax error in a CSS selector."""
|
| 29 |
+
|
| 30 |
+
def __init__(self, msg: str, pattern: str | None = None, index: int | None = None) -> None:
|
| 31 |
+
"""Initialize."""
|
| 32 |
+
|
| 33 |
+
self.line = None
|
| 34 |
+
self.col = None
|
| 35 |
+
self.context = None
|
| 36 |
+
|
| 37 |
+
if pattern is not None and index is not None:
|
| 38 |
+
# Format pattern to show line and column position
|
| 39 |
+
self.context, self.line, self.col = get_pattern_context(pattern, index)
|
| 40 |
+
msg = f'{msg}\n line {self.line}:\n{self.context}'
|
| 41 |
+
|
| 42 |
+
super().__init__(msg)
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def deprecated(message: str, stacklevel: int = 2) -> Callable[..., Any]: # pragma: no cover
|
| 46 |
+
"""
|
| 47 |
+
Raise a `DeprecationWarning` when wrapped function/method is called.
|
| 48 |
+
|
| 49 |
+
Usage:
|
| 50 |
+
|
| 51 |
+
@deprecated("This method will be removed in version X; use Y instead.")
|
| 52 |
+
def some_method()"
|
| 53 |
+
pass
|
| 54 |
+
"""
|
| 55 |
+
|
| 56 |
+
def _wrapper(func: Callable[..., Any]) -> Callable[..., Any]:
|
| 57 |
+
@wraps(func)
|
| 58 |
+
def _deprecated_func(*args: Any, **kwargs: Any) -> Any:
|
| 59 |
+
warnings.warn(
|
| 60 |
+
f"'{func.__name__}' is deprecated. {message}",
|
| 61 |
+
category=DeprecationWarning,
|
| 62 |
+
stacklevel=stacklevel
|
| 63 |
+
)
|
| 64 |
+
return func(*args, **kwargs)
|
| 65 |
+
return _deprecated_func
|
| 66 |
+
return _wrapper
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def warn_deprecated(message: str, stacklevel: int = 2) -> None: # pragma: no cover
|
| 70 |
+
"""Warn deprecated."""
|
| 71 |
+
|
| 72 |
+
warnings.warn(
|
| 73 |
+
message,
|
| 74 |
+
category=DeprecationWarning,
|
| 75 |
+
stacklevel=stacklevel
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def get_pattern_context(pattern: str, index: int) -> tuple[str, int, int]:
|
| 80 |
+
"""Get the pattern context."""
|
| 81 |
+
|
| 82 |
+
last = 0
|
| 83 |
+
current_line = 1
|
| 84 |
+
col = 1
|
| 85 |
+
text = [] # type: list[str]
|
| 86 |
+
line = 1
|
| 87 |
+
offset = None # type: int | None
|
| 88 |
+
|
| 89 |
+
# Split pattern by newline and handle the text before the newline
|
| 90 |
+
for m in RE_PATTERN_LINE_SPLIT.finditer(pattern):
|
| 91 |
+
linetext = pattern[last:m.start(0)]
|
| 92 |
+
if not len(m.group(0)) and not len(text):
|
| 93 |
+
indent = ''
|
| 94 |
+
offset = -1
|
| 95 |
+
col = index - last + 1
|
| 96 |
+
elif last <= index < m.end(0):
|
| 97 |
+
indent = '--> '
|
| 98 |
+
offset = (-1 if index > m.start(0) else 0) + 3
|
| 99 |
+
col = index - last + 1
|
| 100 |
+
else:
|
| 101 |
+
indent = ' '
|
| 102 |
+
offset = None
|
| 103 |
+
if len(text):
|
| 104 |
+
# Regardless of whether we are presented with `\r\n`, `\r`, or `\n`,
|
| 105 |
+
# we will render the output with just `\n`. We will still log the column
|
| 106 |
+
# correctly though.
|
| 107 |
+
text.append('\n')
|
| 108 |
+
text.append(f'{indent}{linetext}')
|
| 109 |
+
if offset is not None:
|
| 110 |
+
text.append('\n')
|
| 111 |
+
text.append(' ' * (col + offset) + '^')
|
| 112 |
+
line = current_line
|
| 113 |
+
|
| 114 |
+
current_line += 1
|
| 115 |
+
last = m.end(0)
|
| 116 |
+
|
| 117 |
+
return ''.join(text), line, col
|
.venv/lib/python3.13/site-packages/tqdm-4.70.0.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pip
|
.venv/lib/python3.13/site-packages/tqdm-4.70.0.dist-info/METADATA
ADDED
|
@@ -0,0 +1,1600 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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 |
+
Maintainer-email: tqdm developers <devs@tqdm.ml>
|
| 6 |
+
License: MPL-2.0 AND MIT
|
| 7 |
+
Project-URL: homepage, https://tqdm.github.io
|
| 8 |
+
Project-URL: repository, https://github.com/tqdm/tqdm
|
| 9 |
+
Project-URL: changelog, https://tqdm.github.io/releases
|
| 10 |
+
Project-URL: wiki, https://github.com/tqdm/tqdm/wiki
|
| 11 |
+
Keywords: progressbar,progressmeter,progress,bar,meter,rate,eta,console,terminal,time
|
| 12 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 13 |
+
Classifier: Environment :: Console
|
| 14 |
+
Classifier: Environment :: MacOS X
|
| 15 |
+
Classifier: Environment :: Other Environment
|
| 16 |
+
Classifier: Environment :: Win32 (MS Windows)
|
| 17 |
+
Classifier: Environment :: X11 Applications
|
| 18 |
+
Classifier: Framework :: IPython
|
| 19 |
+
Classifier: Framework :: Jupyter
|
| 20 |
+
Classifier: Intended Audience :: Developers
|
| 21 |
+
Classifier: Intended Audience :: Education
|
| 22 |
+
Classifier: Intended Audience :: End Users/Desktop
|
| 23 |
+
Classifier: Intended Audience :: Other Audience
|
| 24 |
+
Classifier: Intended Audience :: System Administrators
|
| 25 |
+
Classifier: Operating System :: MacOS
|
| 26 |
+
Classifier: Operating System :: MacOS :: MacOS X
|
| 27 |
+
Classifier: Operating System :: Microsoft
|
| 28 |
+
Classifier: Operating System :: Microsoft :: MS-DOS
|
| 29 |
+
Classifier: Operating System :: Microsoft :: Windows
|
| 30 |
+
Classifier: Operating System :: POSIX
|
| 31 |
+
Classifier: Operating System :: POSIX :: BSD
|
| 32 |
+
Classifier: Operating System :: POSIX :: BSD :: FreeBSD
|
| 33 |
+
Classifier: Operating System :: POSIX :: Linux
|
| 34 |
+
Classifier: Operating System :: POSIX :: SunOS/Solaris
|
| 35 |
+
Classifier: Operating System :: Unix
|
| 36 |
+
Classifier: Programming Language :: Python
|
| 37 |
+
Classifier: Programming Language :: Python :: 3
|
| 38 |
+
Classifier: Programming Language :: Python :: 3.8
|
| 39 |
+
Classifier: Programming Language :: Python :: 3.9
|
| 40 |
+
Classifier: Programming Language :: Python :: 3.10
|
| 41 |
+
Classifier: Programming Language :: Python :: 3.11
|
| 42 |
+
Classifier: Programming Language :: Python :: 3.12
|
| 43 |
+
Classifier: Programming Language :: Python :: 3.13
|
| 44 |
+
Classifier: Programming Language :: Python :: 3.14
|
| 45 |
+
Classifier: Programming Language :: Python :: 3 :: Only
|
| 46 |
+
Classifier: Programming Language :: Python :: Implementation
|
| 47 |
+
Classifier: Programming Language :: Python :: Implementation :: IronPython
|
| 48 |
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
| 49 |
+
Classifier: Programming Language :: Unix Shell
|
| 50 |
+
Classifier: Topic :: Desktop Environment
|
| 51 |
+
Classifier: Topic :: Education :: Computer Aided Instruction (CAI)
|
| 52 |
+
Classifier: Topic :: Education :: Testing
|
| 53 |
+
Classifier: Topic :: Office/Business
|
| 54 |
+
Classifier: Topic :: Other/Nonlisted Topic
|
| 55 |
+
Classifier: Topic :: Software Development :: Build Tools
|
| 56 |
+
Classifier: Topic :: Software Development :: Libraries
|
| 57 |
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
| 58 |
+
Classifier: Topic :: Software Development :: Pre-processors
|
| 59 |
+
Classifier: Topic :: Software Development :: User Interfaces
|
| 60 |
+
Classifier: Topic :: System :: Installation/Setup
|
| 61 |
+
Classifier: Topic :: System :: Logging
|
| 62 |
+
Classifier: Topic :: System :: Monitoring
|
| 63 |
+
Classifier: Topic :: System :: Shells
|
| 64 |
+
Classifier: Topic :: Terminals
|
| 65 |
+
Classifier: Topic :: Utilities
|
| 66 |
+
Requires-Python: >=3.8
|
| 67 |
+
Description-Content-Type: text/x-rst
|
| 68 |
+
License-File: LICENCE
|
| 69 |
+
Requires-Dist: colorama; platform_system == "Windows"
|
| 70 |
+
Provides-Extra: discord
|
| 71 |
+
Requires-Dist: requests; extra == "discord"
|
| 72 |
+
Requires-Dist: envwrap; extra == "discord"
|
| 73 |
+
Provides-Extra: slack
|
| 74 |
+
Requires-Dist: slack-sdk; extra == "slack"
|
| 75 |
+
Requires-Dist: envwrap; extra == "slack"
|
| 76 |
+
Provides-Extra: telegram
|
| 77 |
+
Requires-Dist: requests; extra == "telegram"
|
| 78 |
+
Requires-Dist: envwrap; extra == "telegram"
|
| 79 |
+
Provides-Extra: notebook
|
| 80 |
+
Requires-Dist: ipywidgets>=6; extra == "notebook"
|
| 81 |
+
Dynamic: license-file
|
| 82 |
+
|
| 83 |
+
|Logo|
|
| 84 |
+
|
| 85 |
+
tqdm
|
| 86 |
+
====
|
| 87 |
+
|
| 88 |
+
|Py-Versions| |Versions| |Conda-Forge-Status| |Docker| |Snapcraft|
|
| 89 |
+
|
| 90 |
+
|Build-Status| |Coverage-Status| |Branch-Coverage-Status| |Codacy-Grade| |Libraries-Rank| |PyPI-Downloads|
|
| 91 |
+
|
| 92 |
+
|LICENCE| |OpenHub-Status| |colab-demo| |binder-demo| |awesome-python|
|
| 93 |
+
|
| 94 |
+
``tqdm`` derives from the Arabic word *taqaddum* (تقدّم) which can mean "progress,"
|
| 95 |
+
and is an abbreviation for "I love you so much" in Spanish (*te quiero demasiado*).
|
| 96 |
+
|
| 97 |
+
Instantly make your loops show a smart progress meter - just wrap any
|
| 98 |
+
iterable with ``tqdm(iterable)``, and you're done!
|
| 99 |
+
|
| 100 |
+
.. code:: python
|
| 101 |
+
|
| 102 |
+
from tqdm import tqdm
|
| 103 |
+
for i in tqdm(range(10000)):
|
| 104 |
+
...
|
| 105 |
+
|
| 106 |
+
``76%|████████████████████████ | 7568/10000 [00:33<00:10, 229.00it/s]``
|
| 107 |
+
|
| 108 |
+
``trange(N)`` can also be used as a convenient shortcut for
|
| 109 |
+
``tqdm(range(N))``.
|
| 110 |
+
|
| 111 |
+
|Screenshot|
|
| 112 |
+
|Video| |Slides| |Merch|
|
| 113 |
+
|
| 114 |
+
It can also be executed as a module with pipes:
|
| 115 |
+
|
| 116 |
+
.. code:: sh
|
| 117 |
+
|
| 118 |
+
$ seq 9999999 | tqdm --bytes | wc -l
|
| 119 |
+
75.2MB [00:00, 217MB/s]
|
| 120 |
+
9999999
|
| 121 |
+
|
| 122 |
+
$ tar -zcf - docs/ | tqdm --bytes --total `du -sb docs/ | cut -f1` \
|
| 123 |
+
> backup.tgz
|
| 124 |
+
32%|██████████▍ | 8.89G/27.9G [00:42<01:31, 223MB/s]
|
| 125 |
+
|
| 126 |
+
Overhead is low -- about 60ns per iteration (80ns with ``tqdm.gui``), and is
|
| 127 |
+
unit tested against performance regression.
|
| 128 |
+
By comparison, the well-established
|
| 129 |
+
`ProgressBar <https://github.com/niltonvolpato/python-progressbar>`__ has
|
| 130 |
+
an 800ns/iter overhead.
|
| 131 |
+
|
| 132 |
+
In addition to its low overhead, ``tqdm`` uses smart algorithms to predict
|
| 133 |
+
the remaining time and to skip unnecessary iteration displays, which allows
|
| 134 |
+
for a negligible overhead in most cases.
|
| 135 |
+
|
| 136 |
+
``tqdm`` works on any platform
|
| 137 |
+
(Linux, Windows, Mac, FreeBSD, NetBSD, Solaris/SunOS),
|
| 138 |
+
in any console or in a GUI, and is also friendly with IPython/Jupyter notebooks.
|
| 139 |
+
|
| 140 |
+
``tqdm`` does not require any dependencies (not even ``curses``!), just
|
| 141 |
+
Python and an environment supporting ``carriage return \r`` and
|
| 142 |
+
``line feed \n`` control characters.
|
| 143 |
+
|
| 144 |
+
**Featured Sponsors**
|
| 145 |
+
|
| 146 |
+
======== ================================================
|
| 147 |
+
|OpenAI| Your Logo Here
|
| 148 |
+
======== ================================================
|
| 149 |
+
OpenAI `Sponsors <https://github.com/sponsors/tqdm>`__
|
| 150 |
+
======== ================================================
|
| 151 |
+
|
| 152 |
+
.. |OpenAI| image:: https://avatars.githubusercontent.com/u/14957082?s=96
|
| 153 |
+
:target: https://openai.com
|
| 154 |
+
|
| 155 |
+
------------------------------------------
|
| 156 |
+
|
| 157 |
+
.. contents:: Table of contents
|
| 158 |
+
:backlinks: top
|
| 159 |
+
:local:
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
Installation
|
| 163 |
+
------------
|
| 164 |
+
|
| 165 |
+
Latest PyPI stable release
|
| 166 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 167 |
+
|
| 168 |
+
|Versions| |PyPI-Downloads| |Libraries-Dependents|
|
| 169 |
+
|
| 170 |
+
.. code:: sh
|
| 171 |
+
|
| 172 |
+
pip install tqdm
|
| 173 |
+
|
| 174 |
+
Latest development release on GitHub
|
| 175 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 176 |
+
|
| 177 |
+
|GitHub-Status| |GitHub-Stars| |GitHub-Commits| |GitHub-Forks| |GitHub-Updated|
|
| 178 |
+
|
| 179 |
+
Pull and install pre-release ``devel`` branch:
|
| 180 |
+
|
| 181 |
+
.. code:: sh
|
| 182 |
+
|
| 183 |
+
pip install "git+https://github.com/tqdm/tqdm.git@devel#egg=tqdm"
|
| 184 |
+
|
| 185 |
+
Latest Conda release
|
| 186 |
+
~~~~~~~~~~~~~~~~~~~~
|
| 187 |
+
|
| 188 |
+
|Conda-Forge-Status|
|
| 189 |
+
|
| 190 |
+
.. code:: sh
|
| 191 |
+
|
| 192 |
+
conda install -c conda-forge tqdm
|
| 193 |
+
|
| 194 |
+
Latest Snapcraft release
|
| 195 |
+
~~~~~~~~~~~~~~~~~~~~~~~~
|
| 196 |
+
|
| 197 |
+
|Snapcraft|
|
| 198 |
+
|
| 199 |
+
There are 3 channels to choose from:
|
| 200 |
+
|
| 201 |
+
.. code:: sh
|
| 202 |
+
|
| 203 |
+
snap install tqdm # implies --stable, i.e. latest tagged release
|
| 204 |
+
snap install tqdm --candidate # master branch
|
| 205 |
+
snap install tqdm --edge # devel branch
|
| 206 |
+
|
| 207 |
+
Note that ``snap`` binaries are purely for CLI use (not ``import``-able), and
|
| 208 |
+
automatically set up ``bash`` tab-completion.
|
| 209 |
+
|
| 210 |
+
Latest Docker release
|
| 211 |
+
~~~~~~~~~~~~~~~~~~~~~
|
| 212 |
+
|
| 213 |
+
|Docker|
|
| 214 |
+
|
| 215 |
+
.. code:: sh
|
| 216 |
+
|
| 217 |
+
docker pull tqdm/tqdm
|
| 218 |
+
docker run -i --rm tqdm/tqdm --help
|
| 219 |
+
|
| 220 |
+
Other
|
| 221 |
+
~~~~~
|
| 222 |
+
|
| 223 |
+
There are other (unofficial) places where ``tqdm`` may be downloaded, particularly for CLI use:
|
| 224 |
+
|
| 225 |
+
|Repology|
|
| 226 |
+
|
| 227 |
+
.. |Repology| image:: https://repology.org/badge/tiny-repos/python:tqdm.svg
|
| 228 |
+
:target: https://repology.org/project/python:tqdm/versions
|
| 229 |
+
|
| 230 |
+
Changelog
|
| 231 |
+
---------
|
| 232 |
+
|
| 233 |
+
The list of all changes is available either on GitHub's Releases:
|
| 234 |
+
|GitHub-Status|, on the
|
| 235 |
+
`wiki <https://github.com/tqdm/tqdm/wiki/Releases>`__, or on the
|
| 236 |
+
`website <https://tqdm.github.io/releases>`__.
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
Usage
|
| 240 |
+
-----
|
| 241 |
+
|
| 242 |
+
``tqdm`` is very versatile and can be used in a number of ways.
|
| 243 |
+
The three main ones are given below.
|
| 244 |
+
|
| 245 |
+
Iterable-based
|
| 246 |
+
~~~~~~~~~~~~~~
|
| 247 |
+
|
| 248 |
+
Wrap ``tqdm()`` around any iterable:
|
| 249 |
+
|
| 250 |
+
.. code:: python
|
| 251 |
+
|
| 252 |
+
from tqdm import tqdm
|
| 253 |
+
from time import sleep
|
| 254 |
+
|
| 255 |
+
text = ""
|
| 256 |
+
for char in tqdm(["a", "b", "c", "d"]):
|
| 257 |
+
sleep(0.25)
|
| 258 |
+
text = text + char
|
| 259 |
+
|
| 260 |
+
``trange(i)`` is a special optimised instance of ``tqdm(range(i))``:
|
| 261 |
+
|
| 262 |
+
.. code:: python
|
| 263 |
+
|
| 264 |
+
from tqdm import trange
|
| 265 |
+
|
| 266 |
+
for i in trange(100):
|
| 267 |
+
sleep(0.01)
|
| 268 |
+
|
| 269 |
+
Instantiation outside of the loop allows for manual control over ``tqdm()``:
|
| 270 |
+
|
| 271 |
+
.. code:: python
|
| 272 |
+
|
| 273 |
+
pbar = tqdm(["a", "b", "c", "d"])
|
| 274 |
+
for char in pbar:
|
| 275 |
+
sleep(0.25)
|
| 276 |
+
pbar.set_description("Processing %s" % char)
|
| 277 |
+
|
| 278 |
+
Manual
|
| 279 |
+
~~~~~~
|
| 280 |
+
|
| 281 |
+
Manual control of ``tqdm()`` updates using a ``with`` statement:
|
| 282 |
+
|
| 283 |
+
.. code:: python
|
| 284 |
+
|
| 285 |
+
with tqdm(total=100) as pbar:
|
| 286 |
+
for i in range(10):
|
| 287 |
+
sleep(0.1)
|
| 288 |
+
pbar.update(10)
|
| 289 |
+
|
| 290 |
+
If the optional variable ``total`` (or an iterable with ``len()``) is
|
| 291 |
+
provided, predictive stats are displayed.
|
| 292 |
+
|
| 293 |
+
``with`` is also optional (you can just assign ``tqdm()`` to a variable,
|
| 294 |
+
but in this case don't forget to ``del`` or ``close()`` at the end:
|
| 295 |
+
|
| 296 |
+
.. code:: python
|
| 297 |
+
|
| 298 |
+
pbar = tqdm(total=100)
|
| 299 |
+
for i in range(10):
|
| 300 |
+
sleep(0.1)
|
| 301 |
+
pbar.update(10)
|
| 302 |
+
pbar.close()
|
| 303 |
+
|
| 304 |
+
Module
|
| 305 |
+
~~~~~~
|
| 306 |
+
|
| 307 |
+
Perhaps the most wonderful use of ``tqdm`` is in a script or on the command
|
| 308 |
+
line. Simply inserting ``tqdm`` (or ``python -m tqdm``) between pipes will pass
|
| 309 |
+
through all ``stdin`` to ``stdout`` while printing progress to ``stderr``.
|
| 310 |
+
|
| 311 |
+
The example below demonstrate counting the number of lines in all Python files
|
| 312 |
+
in the current directory, with timing information included.
|
| 313 |
+
|
| 314 |
+
.. code:: sh
|
| 315 |
+
|
| 316 |
+
$ time find . -name '*.py' -type f -exec cat \{} \; | wc -l
|
| 317 |
+
857365
|
| 318 |
+
|
| 319 |
+
real 0m3.458s
|
| 320 |
+
user 0m0.274s
|
| 321 |
+
sys 0m3.325s
|
| 322 |
+
|
| 323 |
+
$ time find . -name '*.py' -type f -exec cat \{} \; | tqdm | wc -l
|
| 324 |
+
857366it [00:03, 246471.31it/s]
|
| 325 |
+
857365
|
| 326 |
+
|
| 327 |
+
real 0m3.585s
|
| 328 |
+
user 0m0.862s
|
| 329 |
+
sys 0m3.358s
|
| 330 |
+
|
| 331 |
+
Note that the usual arguments for ``tqdm`` can also be specified.
|
| 332 |
+
|
| 333 |
+
.. code:: sh
|
| 334 |
+
|
| 335 |
+
$ find . -name '*.py' -type f -exec cat \{} \; |
|
| 336 |
+
tqdm --unit loc --unit_scale --total 857366 >> /dev/null
|
| 337 |
+
100%|█████████████████████████████████| 857K/857K [00:04<00:00, 246Kloc/s]
|
| 338 |
+
|
| 339 |
+
Backing up a large directory?
|
| 340 |
+
|
| 341 |
+
.. code:: sh
|
| 342 |
+
|
| 343 |
+
$ tar -zcf - docs/ | tqdm --bytes --total `du -sb docs/ | cut -f1` \
|
| 344 |
+
> backup.tgz
|
| 345 |
+
44%|██████████████▊ | 153M/352M [00:14<00:18, 11.0MB/s]
|
| 346 |
+
|
| 347 |
+
This can be beautified further:
|
| 348 |
+
|
| 349 |
+
.. code:: sh
|
| 350 |
+
|
| 351 |
+
$ BYTES=$(du -sb docs/ | cut -f1)
|
| 352 |
+
$ tar -cf - docs/ \
|
| 353 |
+
| tqdm --bytes --total "$BYTES" --desc Processing | gzip \
|
| 354 |
+
| tqdm --bytes --total "$BYTES" --desc Compressed --position 1 \
|
| 355 |
+
> ~/backup.tgz
|
| 356 |
+
Processing: 100%|██████████████████████| 352M/352M [00:14<00:00, 30.2MB/s]
|
| 357 |
+
Compressed: 42%|█████████▎ | 148M/352M [00:14<00:19, 10.9MB/s]
|
| 358 |
+
|
| 359 |
+
Or done on a file level using 7-zip:
|
| 360 |
+
|
| 361 |
+
.. code:: sh
|
| 362 |
+
|
| 363 |
+
$ 7z a -bd -r backup.7z docs/ | grep Compressing \
|
| 364 |
+
| tqdm --total $(find docs/ -type f | wc -l) --unit files \
|
| 365 |
+
| grep -v Compressing
|
| 366 |
+
100%|██████████████████████████▉| 15327/15327 [01:00<00:00, 712.96files/s]
|
| 367 |
+
|
| 368 |
+
Pre-existing CLI programs already outputting basic progress information will
|
| 369 |
+
benefit from ``tqdm``'s ``--update`` and ``--update_to`` flags:
|
| 370 |
+
|
| 371 |
+
.. code:: sh
|
| 372 |
+
|
| 373 |
+
$ seq 3 0.1 5 | tqdm --total 5 --update_to --null
|
| 374 |
+
100%|████████████████████████████████████| 5.0/5 [00:00<00:00, 9673.21it/s]
|
| 375 |
+
$ seq 10 | tqdm --update --null # 1 + 2 + ... + 10 = 55 iterations
|
| 376 |
+
55it [00:00, 90006.52it/s]
|
| 377 |
+
|
| 378 |
+
FAQ and Known Issues
|
| 379 |
+
--------------------
|
| 380 |
+
|
| 381 |
+
|GitHub-Issues|
|
| 382 |
+
|
| 383 |
+
The most common issues relate to excessive output on multiple lines, instead
|
| 384 |
+
of a neat one-line progress bar.
|
| 385 |
+
|
| 386 |
+
- Consoles in general: require support for carriage return (``CR``, ``\r``).
|
| 387 |
+
|
| 388 |
+
* Some cloud logging consoles which don't support ``\r`` properly
|
| 389 |
+
(`cloudwatch <https://github.com/tqdm/tqdm/issues/966>`__,
|
| 390 |
+
`K8s <https://github.com/tqdm/tqdm/issues/1319>`__) may benefit from
|
| 391 |
+
``export TQDM_POSITION=-1``.
|
| 392 |
+
|
| 393 |
+
- Nested progress bars:
|
| 394 |
+
|
| 395 |
+
* Consoles in general: require support for moving cursors up to the
|
| 396 |
+
previous line. For example,
|
| 397 |
+
`IDLE <https://github.com/tqdm/tqdm/issues/191#issuecomment-230168030>`__,
|
| 398 |
+
`ConEmu <https://github.com/tqdm/tqdm/issues/254>`__ and
|
| 399 |
+
`PyCharm <https://github.com/tqdm/tqdm/issues/203>`__ (also
|
| 400 |
+
`here <https://github.com/tqdm/tqdm/issues/208>`__,
|
| 401 |
+
`here <https://github.com/tqdm/tqdm/issues/307>`__, and
|
| 402 |
+
`here <https://github.com/tqdm/tqdm/issues/454#issuecomment-335416815>`__)
|
| 403 |
+
lack full support.
|
| 404 |
+
* Windows: additionally may require the Python module ``colorama``
|
| 405 |
+
to ensure nested bars stay within their respective lines.
|
| 406 |
+
|
| 407 |
+
- Unicode:
|
| 408 |
+
|
| 409 |
+
* Environments which report that they support unicode will have solid smooth
|
| 410 |
+
progress bars. The fallback is an ``ascii``-only bar.
|
| 411 |
+
* Windows consoles often only partially support unicode and thus
|
| 412 |
+
`often require explicit ascii=True <https://github.com/tqdm/tqdm/issues/454#issuecomment-335416815>`__
|
| 413 |
+
(also `here <https://github.com/tqdm/tqdm/issues/499>`__). This is due to
|
| 414 |
+
either normal-width unicode characters being incorrectly displayed as
|
| 415 |
+
"wide", or some unicode characters not rendering.
|
| 416 |
+
|
| 417 |
+
- Wrapping generators:
|
| 418 |
+
|
| 419 |
+
* Generator wrapper functions tend to hide the length of iterables.
|
| 420 |
+
``tqdm`` does not.
|
| 421 |
+
* Replace ``tqdm(enumerate(...))`` with ``enumerate(tqdm(...))`` or
|
| 422 |
+
``tqdm(enumerate(x), total=len(x), ...)``.
|
| 423 |
+
The same applies to ``numpy.ndenumerate``.
|
| 424 |
+
* Replace ``tqdm(zip(a, b))`` with ``zip(tqdm(a), b)`` or even
|
| 425 |
+
``zip(tqdm(a), tqdm(b))``.
|
| 426 |
+
* The same applies to ``itertools``.
|
| 427 |
+
* Some useful convenience functions can be found under ``tqdm.contrib``.
|
| 428 |
+
|
| 429 |
+
- `No intermediate output in docker-compose <https://github.com/tqdm/tqdm/issues/771>`__:
|
| 430 |
+
use ``docker-compose run`` instead of ``docker-compose up`` and ``tty: true``.
|
| 431 |
+
|
| 432 |
+
- Overriding defaults via environment variables:
|
| 433 |
+
e.g. in CI/cloud jobs, ``export TQDM_MININTERVAL=5`` to avoid log spam.
|
| 434 |
+
This override logic is handled by the ``tqdm.utils.envwrap`` decorator
|
| 435 |
+
(useful independent of ``tqdm``).
|
| 436 |
+
|
| 437 |
+
If you come across any other difficulties, browse and file |GitHub-Issues|.
|
| 438 |
+
|
| 439 |
+
Documentation
|
| 440 |
+
-------------
|
| 441 |
+
|
| 442 |
+
|Py-Versions| |README-Hits| (Since 19 May 2016)
|
| 443 |
+
|
| 444 |
+
.. code:: python
|
| 445 |
+
|
| 446 |
+
class tqdm():
|
| 447 |
+
"""
|
| 448 |
+
Decorate an iterable object, returning an iterator which acts exactly
|
| 449 |
+
like the original iterable, but prints a dynamically updating
|
| 450 |
+
progress bar every time a value is requested.
|
| 451 |
+
"""
|
| 452 |
+
|
| 453 |
+
@envwrap("tqdm") # override defaults via env vars
|
| 454 |
+
def __init__(self, iterable=None, desc=None, total=None, leave=True,
|
| 455 |
+
file=None, ncols=None, mininterval=0.1,
|
| 456 |
+
maxinterval=10.0, miniters=None, ascii=None, disable=False,
|
| 457 |
+
unit='it', unit_scale=False, dynamic_ncols=False,
|
| 458 |
+
smoothing=0.3, bar_format=None, initial=0, position=None,
|
| 459 |
+
postfix=None, unit_divisor=1000, write_bytes=False,
|
| 460 |
+
lock_args=None, nrows=None, colour=None, delay=0):
|
| 461 |
+
|
| 462 |
+
Parameters
|
| 463 |
+
~~~~~~~~~~
|
| 464 |
+
|
| 465 |
+
* iterable : iterable, optional
|
| 466 |
+
Iterable to decorate with a progress bar.
|
| 467 |
+
Leave blank to manually manage the updates.
|
| 468 |
+
* desc : str, optional
|
| 469 |
+
Prefix for the progress bar.
|
| 470 |
+
* total : int or float, optional
|
| 471 |
+
The number of expected iterations. If unspecified,
|
| 472 |
+
len(iterable) is used if possible. If float("inf") or as a last
|
| 473 |
+
resort, only basic progress statistics are displayed
|
| 474 |
+
(no ETA, no progress bar).
|
| 475 |
+
If ``gui`` is True and this parameter needs subsequent updating,
|
| 476 |
+
specify an initial arbitrary large positive number,
|
| 477 |
+
e.g. 9e9.
|
| 478 |
+
* leave : bool, optional
|
| 479 |
+
If [default: True], keeps all traces of the progress bar
|
| 480 |
+
upon termination of iteration.
|
| 481 |
+
If ``None``, will leave only if ``position`` is ``0``.
|
| 482 |
+
* file : ``io.TextIOWrapper`` or ``io.StringIO``, optional
|
| 483 |
+
Specifies where to output the progress messages
|
| 484 |
+
(default: sys.stderr). Uses ``file.write(str)`` and ``file.flush()``
|
| 485 |
+
methods. For encoding, see ``write_bytes``.
|
| 486 |
+
* ncols : int, optional
|
| 487 |
+
The width of the entire output message. If specified,
|
| 488 |
+
dynamically resizes the progress bar to stay within this bound.
|
| 489 |
+
If unspecified, attempts to use environment width. The
|
| 490 |
+
fallback is a meter width of 10 and no limit for the counter and
|
| 491 |
+
statistics. If 0, will not print any meter (only stats).
|
| 492 |
+
* mininterval : float, optional
|
| 493 |
+
Minimum progress display update interval [default: 0.1] seconds.
|
| 494 |
+
* maxinterval : float, optional
|
| 495 |
+
Maximum progress display update interval [default: 10] seconds.
|
| 496 |
+
Automatically adjusts ``miniters`` to correspond to ``mininterval``
|
| 497 |
+
after long display update lag. Only works if ``dynamic_miniters``
|
| 498 |
+
or monitor thread is enabled.
|
| 499 |
+
* miniters : int or float, optional
|
| 500 |
+
Minimum progress display update interval, in iterations.
|
| 501 |
+
If 0 and ``dynamic_miniters``, will automatically adjust to equal
|
| 502 |
+
``mininterval`` (more CPU efficient, good for tight loops).
|
| 503 |
+
If > 0, will skip display of specified number of iterations.
|
| 504 |
+
Tweak this and ``mininterval`` to get very efficient loops.
|
| 505 |
+
If your progress is erratic with both fast and slow iterations
|
| 506 |
+
(network, skipping items, etc) you should set miniters=1.
|
| 507 |
+
* ascii : bool or str, optional
|
| 508 |
+
If unspecified or False, use unicode (smooth blocks) to fill
|
| 509 |
+
the meter. The fallback is to use ASCII characters " 123456789#".
|
| 510 |
+
* disable : bool, optional
|
| 511 |
+
Whether to disable the entire progress bar wrapper
|
| 512 |
+
[default: False]. If set to None, disable on non-TTY.
|
| 513 |
+
* unit : str, optional
|
| 514 |
+
String that will be used to define the unit of each iteration
|
| 515 |
+
[default: it].
|
| 516 |
+
* unit_scale : bool or int or float, optional
|
| 517 |
+
If 1 or True, the number of iterations will be reduced/scaled
|
| 518 |
+
automatically and a metric prefix following the
|
| 519 |
+
International System of Units standard will be added
|
| 520 |
+
(kilo, mega, etc.) [default: False]. If any other non-zero
|
| 521 |
+
number, will scale ``total`` and ``n``.
|
| 522 |
+
* dynamic_ncols : bool, optional
|
| 523 |
+
If set, constantly alters ``ncols`` and ``nrows`` to the
|
| 524 |
+
environment (allowing for window resizes) [default: False].
|
| 525 |
+
* smoothing : float, optional
|
| 526 |
+
Exponential moving average smoothing factor for speed estimates
|
| 527 |
+
(ignored in GUI mode). Ranges from 0 (average speed) to 1
|
| 528 |
+
(current/instantaneous speed) [default: 0.3].
|
| 529 |
+
* bar_format : str, optional
|
| 530 |
+
Specify a custom bar string formatting. May impact performance.
|
| 531 |
+
[default: '{l_bar}{bar}{r_bar}'], where
|
| 532 |
+
l_bar='{desc}: {percentage:3.0f}%|' and
|
| 533 |
+
r_bar='| {n_fmt}/{total_fmt} [{elapsed}<{remaining}, '
|
| 534 |
+
'{rate_fmt}{postfix}]'
|
| 535 |
+
Possible vars: l_bar, bar, r_bar, n, n_fmt, total, total_fmt,
|
| 536 |
+
percentage, elapsed, elapsed_s, ncols, nrows, desc, unit,
|
| 537 |
+
rate, rate_fmt, rate_noinv, rate_noinv_fmt,
|
| 538 |
+
rate_inv, rate_inv_fmt, postfix, unit_divisor,
|
| 539 |
+
remaining, remaining_s, eta.
|
| 540 |
+
Note that a trailing ": " is automatically removed after {desc}
|
| 541 |
+
if the latter is empty.
|
| 542 |
+
* initial : int or float, optional
|
| 543 |
+
The initial counter value. Useful when restarting a progress
|
| 544 |
+
bar [default: 0]. If using float, consider specifying ``{n:.3f}``
|
| 545 |
+
or similar in ``bar_format``, or specifying ``unit_scale``.
|
| 546 |
+
* position : int, optional
|
| 547 |
+
Specify the line offset to print this bar (starting from 0)
|
| 548 |
+
Automatic if unspecified.
|
| 549 |
+
Useful to manage multiple bars at once (eg, from threads).
|
| 550 |
+
* postfix : dict or ``*``, optional
|
| 551 |
+
Specify additional stats to display at the end of the bar.
|
| 552 |
+
Calls ``set_postfix(**postfix)`` if possible (dict).
|
| 553 |
+
* unit_divisor : float, optional
|
| 554 |
+
[default: 1000], ignored unless ``unit_scale`` is True.
|
| 555 |
+
* write_bytes : bool, optional
|
| 556 |
+
Whether to write bytes. If (default: False) will write unicode.
|
| 557 |
+
* lock_args : tuple, optional
|
| 558 |
+
Passed to ``refresh`` for intermediate output
|
| 559 |
+
(initialisation, iterating, and updating).
|
| 560 |
+
* nrows : int, optional
|
| 561 |
+
The screen height. If specified, hides nested bars outside this
|
| 562 |
+
bound. If unspecified, attempts to use environment height.
|
| 563 |
+
The fallback is 20.
|
| 564 |
+
* colour : str, optional
|
| 565 |
+
Bar colour (e.g. 'green', '#00ff00').
|
| 566 |
+
* delay : float, optional
|
| 567 |
+
Don't display until [default: 0] seconds have elapsed.
|
| 568 |
+
|
| 569 |
+
Extra CLI Options
|
| 570 |
+
~~~~~~~~~~~~~~~~~
|
| 571 |
+
|
| 572 |
+
* delim : chr, optional
|
| 573 |
+
Delimiting character [default: '\n']. Use '\0' for null.
|
| 574 |
+
N.B.: on Windows systems, Python converts '\n' to '\r\n'.
|
| 575 |
+
* buf_size : int, optional
|
| 576 |
+
String buffer size in bytes [default: 256]
|
| 577 |
+
used when ``delim`` is specified.
|
| 578 |
+
* bytes : bool, optional
|
| 579 |
+
If true, will count bytes, ignore ``delim``, and default
|
| 580 |
+
``unit_scale`` to True, ``unit_divisor`` to 1024, and ``unit`` to 'B'.
|
| 581 |
+
* tee : bool, optional
|
| 582 |
+
If true, passes ``stdin`` to both ``stderr`` and ``stdout``.
|
| 583 |
+
* update : bool, optional
|
| 584 |
+
If true, will treat input as newly elapsed iterations,
|
| 585 |
+
i.e. numbers to pass to ``update()``. Note that this is slow
|
| 586 |
+
(~2e5 it/s) since every input must be decoded as a number.
|
| 587 |
+
* update_to : bool, optional
|
| 588 |
+
If true, will treat input as total elapsed iterations,
|
| 589 |
+
i.e. numbers to assign to ``self.n``. Note that this is slow
|
| 590 |
+
(~2e5 it/s) since every input must be decoded as a number.
|
| 591 |
+
* null : bool, optional
|
| 592 |
+
If true, will discard input (no stdout).
|
| 593 |
+
* manpath : str, optional
|
| 594 |
+
Directory in which to install tqdm man pages.
|
| 595 |
+
* comppath : str, optional
|
| 596 |
+
Directory in which to place tqdm completion.
|
| 597 |
+
* log : str, optional
|
| 598 |
+
CRITICAL|FATAL|ERROR|WARN(ING)|[default: 'INFO']|DEBUG|NOTSET.
|
| 599 |
+
|
| 600 |
+
Returns
|
| 601 |
+
~~~~~~~
|
| 602 |
+
|
| 603 |
+
* out : decorated iterator.
|
| 604 |
+
|
| 605 |
+
.. code:: python
|
| 606 |
+
|
| 607 |
+
class tqdm():
|
| 608 |
+
def update(self, n=1):
|
| 609 |
+
"""
|
| 610 |
+
Manually update the progress bar, useful for streams
|
| 611 |
+
such as reading files.
|
| 612 |
+
E.g.:
|
| 613 |
+
>>> t = tqdm(total=filesize) # Initialise
|
| 614 |
+
>>> for current_buffer in stream:
|
| 615 |
+
... ...
|
| 616 |
+
... t.update(len(current_buffer))
|
| 617 |
+
>>> t.close()
|
| 618 |
+
The last line is highly recommended, but possibly not necessary if
|
| 619 |
+
`t.update()` will be called in such a way that `filesize` will be
|
| 620 |
+
exactly reached and printed.
|
| 621 |
+
|
| 622 |
+
Parameters
|
| 623 |
+
----------
|
| 624 |
+
n : int or float, optional
|
| 625 |
+
Increment to add to the internal counter of iterations
|
| 626 |
+
[default: 1]. If using float, consider specifying `{n:.3f}`
|
| 627 |
+
or similar in `bar_format`, or specifying `unit_scale`.
|
| 628 |
+
|
| 629 |
+
Returns
|
| 630 |
+
-------
|
| 631 |
+
out : bool or None
|
| 632 |
+
True if a `display()` was triggered.
|
| 633 |
+
"""
|
| 634 |
+
|
| 635 |
+
def close(self):
|
| 636 |
+
"""Cleanup and (if leave=False) close the progress bar."""
|
| 637 |
+
|
| 638 |
+
def clear(self, nomove=False):
|
| 639 |
+
"""Clear current bar display."""
|
| 640 |
+
|
| 641 |
+
def refresh(self):
|
| 642 |
+
"""
|
| 643 |
+
Force refresh the display of this bar.
|
| 644 |
+
|
| 645 |
+
Parameters
|
| 646 |
+
----------
|
| 647 |
+
nolock : bool, optional
|
| 648 |
+
If `True`, does not lock.
|
| 649 |
+
If [default: `False`]: calls `acquire()` on internal lock.
|
| 650 |
+
lock_args : tuple, optional
|
| 651 |
+
Passed to internal lock's `acquire()`.
|
| 652 |
+
If specified, will only `display()` if `acquire()` returns `True`.
|
| 653 |
+
"""
|
| 654 |
+
|
| 655 |
+
def unpause(self):
|
| 656 |
+
"""Restart tqdm timer from last print time."""
|
| 657 |
+
|
| 658 |
+
def reset(self, total=None):
|
| 659 |
+
"""
|
| 660 |
+
Resets to 0 iterations for repeated use.
|
| 661 |
+
|
| 662 |
+
Consider combining with `leave=True`.
|
| 663 |
+
|
| 664 |
+
Parameters
|
| 665 |
+
----------
|
| 666 |
+
total : int or float, optional. Total to use for the new bar.
|
| 667 |
+
"""
|
| 668 |
+
|
| 669 |
+
def set_description(self, desc=None, refresh=True):
|
| 670 |
+
"""
|
| 671 |
+
Set/modify description of the progress bar.
|
| 672 |
+
|
| 673 |
+
Parameters
|
| 674 |
+
----------
|
| 675 |
+
desc : str, optional
|
| 676 |
+
refresh : bool, optional
|
| 677 |
+
Forces refresh [default: True].
|
| 678 |
+
"""
|
| 679 |
+
|
| 680 |
+
def set_postfix(self, ordered_dict=None, refresh=True, **tqdm_kwargs):
|
| 681 |
+
"""
|
| 682 |
+
Set/modify postfix (additional stats)
|
| 683 |
+
with automatic formatting based on datatype.
|
| 684 |
+
|
| 685 |
+
Parameters
|
| 686 |
+
----------
|
| 687 |
+
ordered_dict : dict or OrderedDict, optional
|
| 688 |
+
refresh : bool, optional
|
| 689 |
+
Forces refresh [default: True].
|
| 690 |
+
kwargs : dict, optional
|
| 691 |
+
"""
|
| 692 |
+
|
| 693 |
+
@classmethod
|
| 694 |
+
def write(cls, s, file=sys.stdout, end="\n"):
|
| 695 |
+
"""Print a message via tqdm (without overlap with bars)."""
|
| 696 |
+
|
| 697 |
+
@property
|
| 698 |
+
def format_dict(self):
|
| 699 |
+
"""Public API for read-only member access."""
|
| 700 |
+
|
| 701 |
+
def display(self, msg=None, pos=None):
|
| 702 |
+
"""
|
| 703 |
+
Use `self.sp` to display `msg` in the specified `pos`.
|
| 704 |
+
|
| 705 |
+
Consider overloading this function when inheriting to use e.g.:
|
| 706 |
+
`self.some_frontend(**self.format_dict)` instead of `self.sp`.
|
| 707 |
+
|
| 708 |
+
Parameters
|
| 709 |
+
----------
|
| 710 |
+
msg : str, optional. What to display (default: `repr(self)`).
|
| 711 |
+
pos : int, optional. Position to `moveto`
|
| 712 |
+
(default: `abs(self.pos)`).
|
| 713 |
+
"""
|
| 714 |
+
|
| 715 |
+
@classmethod
|
| 716 |
+
@contextmanager
|
| 717 |
+
def wrapattr(cls, stream, method, total=None, bytes=True, **tqdm_kwargs):
|
| 718 |
+
"""
|
| 719 |
+
stream : file-like object.
|
| 720 |
+
method : str, "read" or "write". The result of `read()` and
|
| 721 |
+
the first argument of `write()` should have a `len()`.
|
| 722 |
+
|
| 723 |
+
>>> with tqdm.wrapattr(file_obj, "read", total=file_obj.size) as fobj:
|
| 724 |
+
... while True:
|
| 725 |
+
... chunk = fobj.read(chunk_size)
|
| 726 |
+
... if not chunk:
|
| 727 |
+
... break
|
| 728 |
+
"""
|
| 729 |
+
|
| 730 |
+
@classmethod
|
| 731 |
+
def pandas(cls, *targs, **tqdm_kwargs):
|
| 732 |
+
"""Registers the current `tqdm` class with `pandas`."""
|
| 733 |
+
|
| 734 |
+
def trange(*args, **tqdm_kwargs):
|
| 735 |
+
"""Shortcut for `tqdm(range(*args), **tqdm_kwargs)`."""
|
| 736 |
+
|
| 737 |
+
Convenience Functions
|
| 738 |
+
~~~~~~~~~~~~~~~~~~~~~
|
| 739 |
+
|
| 740 |
+
.. code:: python
|
| 741 |
+
|
| 742 |
+
def tqdm.contrib.tenumerate(iterable, start=0, total=None,
|
| 743 |
+
tqdm_class=tqdm.auto.tqdm, **tqdm_kwargs):
|
| 744 |
+
"""Equivalent of `numpy.ndenumerate` or builtin `enumerate`."""
|
| 745 |
+
|
| 746 |
+
def tqdm.contrib.tzip(iter1, *iter2plus, **tqdm_kwargs):
|
| 747 |
+
"""Equivalent of builtin `zip`."""
|
| 748 |
+
|
| 749 |
+
def tqdm.contrib.tmap(function, *sequences, **tqdm_kwargs):
|
| 750 |
+
"""Equivalent of builtin `map`."""
|
| 751 |
+
|
| 752 |
+
Submodules
|
| 753 |
+
~~~~~~~~~~
|
| 754 |
+
|
| 755 |
+
.. code:: python
|
| 756 |
+
|
| 757 |
+
class tqdm.notebook.tqdm(tqdm.tqdm):
|
| 758 |
+
"""IPython/Jupyter Notebook widget."""
|
| 759 |
+
|
| 760 |
+
class tqdm.auto.tqdm(tqdm.tqdm):
|
| 761 |
+
"""Automatically chooses between `tqdm.notebook` and `tqdm.tqdm`."""
|
| 762 |
+
|
| 763 |
+
class tqdm.asyncio.tqdm(tqdm.tqdm):
|
| 764 |
+
"""Asynchronous version."""
|
| 765 |
+
@classmethod
|
| 766 |
+
def as_completed(cls, fs, *, loop=None, timeout=None, total=None,
|
| 767 |
+
**tqdm_kwargs):
|
| 768 |
+
"""Wrapper for `asyncio.as_completed`."""
|
| 769 |
+
|
| 770 |
+
class tqdm.gui.tqdm(tqdm.tqdm):
|
| 771 |
+
"""Matplotlib GUI version."""
|
| 772 |
+
|
| 773 |
+
class tqdm.tk.tqdm(tqdm.tqdm):
|
| 774 |
+
"""Tkinter GUI version."""
|
| 775 |
+
|
| 776 |
+
class tqdm.rich.tqdm(tqdm.tqdm):
|
| 777 |
+
"""`rich.progress` version."""
|
| 778 |
+
|
| 779 |
+
class tqdm.keras.TqdmCallback(keras.callbacks.Callback):
|
| 780 |
+
"""Keras callback for epoch and batch progress."""
|
| 781 |
+
|
| 782 |
+
class tqdm.dask.TqdmCallback(dask.callbacks.Callback):
|
| 783 |
+
"""Dask callback for task progress."""
|
| 784 |
+
|
| 785 |
+
|
| 786 |
+
``contrib``
|
| 787 |
+
+++++++++++
|
| 788 |
+
|
| 789 |
+
The ``tqdm.contrib`` package also contains experimental modules:
|
| 790 |
+
|
| 791 |
+
- `tqdm.contrib.itertools <https://tqdm.github.io/docs/contrib.itertools/>`_: Thin wrappers around ``itertools``
|
| 792 |
+
- `tqdm.contrib.concurrent <https://tqdm.github.io/docs/contrib.concurrent/>`_: Thin wrappers around ``concurrent.futures``
|
| 793 |
+
- `tqdm.contrib.slack <https://tqdm.github.io/docs/contrib.slack/>`_: Posts to `Slack <https://slack.com>`__ bots
|
| 794 |
+
- `tqdm.contrib.discord <https://tqdm.github.io/docs/contrib.discord/>`_: Posts to `Discord <https://discord.com>`__ bots
|
| 795 |
+
- `tqdm.contrib.telegram <https://tqdm.github.io/docs/contrib.telegram/>`_: Posts to `Telegram <https://telegram.org>`__ bots
|
| 796 |
+
- `tqdm.contrib.bells <https://tqdm.github.io/docs/shortcuts/>`_: Automagically enables all optional features
|
| 797 |
+
|
| 798 |
+
* ``auto``, ``pandas``, ``slack``, ``discord``, ``telegram``
|
| 799 |
+
|
| 800 |
+
.. image:: https://tqdm.github.io/img/screenshot-discord.png
|
| 801 |
+
:alt: Screenshot of `tqdm.contrib.discord` in action
|
| 802 |
+
|
| 803 |
+
Examples and Advanced Usage
|
| 804 |
+
---------------------------
|
| 805 |
+
|
| 806 |
+
- See the `examples <https://github.com/tqdm/tqdm/tree/master/examples>`__
|
| 807 |
+
folder;
|
| 808 |
+
- import the module and run ``help()``;
|
| 809 |
+
- consult the `wiki <https://github.com/tqdm/tqdm/wiki>`__;
|
| 810 |
+
|
| 811 |
+
* this has an
|
| 812 |
+
`excellent article <https://github.com/tqdm/tqdm/wiki/How-to-make-a-great-Progress-Bar>`__
|
| 813 |
+
on how to make a **great** progress bar;
|
| 814 |
+
|
| 815 |
+
- check out the `slides from PyData London <https://tqdm.github.io/PyData2019/slides.html>`__, or
|
| 816 |
+
- run the |binder-demo|.
|
| 817 |
+
|
| 818 |
+
Description and additional stats
|
| 819 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 820 |
+
|
| 821 |
+
Custom information can be displayed and updated dynamically on ``tqdm`` bars
|
| 822 |
+
with the ``desc`` and ``postfix`` arguments:
|
| 823 |
+
|
| 824 |
+
.. code:: python
|
| 825 |
+
|
| 826 |
+
from tqdm import tqdm, trange
|
| 827 |
+
from random import random, randint
|
| 828 |
+
from time import sleep
|
| 829 |
+
|
| 830 |
+
with trange(10) as t:
|
| 831 |
+
for i in t:
|
| 832 |
+
# Description will be displayed on the left
|
| 833 |
+
t.set_description('GEN %i' % i)
|
| 834 |
+
# Postfix will be displayed on the right,
|
| 835 |
+
# formatted automatically based on argument's datatype
|
| 836 |
+
t.set_postfix(loss=random(), gen=randint(1,999), str='h',
|
| 837 |
+
lst=[1, 2])
|
| 838 |
+
sleep(0.1)
|
| 839 |
+
|
| 840 |
+
with tqdm(total=10, bar_format="{postfix[0]} {postfix[1][value]:>8.2g}",
|
| 841 |
+
postfix=["Batch", {"value": 0}]) as t:
|
| 842 |
+
for i in range(10):
|
| 843 |
+
sleep(0.1)
|
| 844 |
+
t.postfix[1]["value"] = i / 2
|
| 845 |
+
t.update()
|
| 846 |
+
|
| 847 |
+
Points to remember when using ``{postfix[...]}`` in the ``bar_format`` string:
|
| 848 |
+
|
| 849 |
+
- ``postfix`` also needs to be passed as an initial argument in a compatible
|
| 850 |
+
format, and
|
| 851 |
+
- ``postfix`` will be auto-converted to a string if it is a ``dict``-like
|
| 852 |
+
object. To prevent this behaviour, insert an extra item into the dictionary
|
| 853 |
+
where the key is not a string.
|
| 854 |
+
|
| 855 |
+
Additional ``bar_format`` parameters may also be defined by overriding
|
| 856 |
+
``format_dict``, and the bar itself may be modified using ``ascii``:
|
| 857 |
+
|
| 858 |
+
.. code:: python
|
| 859 |
+
|
| 860 |
+
from tqdm import tqdm
|
| 861 |
+
class TqdmExtraFormat(tqdm):
|
| 862 |
+
"""Provides a `total_time` format parameter"""
|
| 863 |
+
@property
|
| 864 |
+
def format_dict(self):
|
| 865 |
+
d = super().format_dict
|
| 866 |
+
total_time = d["elapsed"] * (d["total"] or 0) / max(d["n"], 1)
|
| 867 |
+
d.update(total_time=self.format_interval(total_time) + " in total")
|
| 868 |
+
return d
|
| 869 |
+
|
| 870 |
+
for i in TqdmExtraFormat(
|
| 871 |
+
range(9), ascii=" .oO0",
|
| 872 |
+
bar_format="{total_time}: {percentage:.0f}%|{bar}{r_bar}"):
|
| 873 |
+
if i == 4:
|
| 874 |
+
break
|
| 875 |
+
|
| 876 |
+
.. code::
|
| 877 |
+
|
| 878 |
+
00:00 in total: 44%|0000. | 4/9 [00:00<00:00, 962.93it/s]
|
| 879 |
+
|
| 880 |
+
Note that ``{bar}`` also supports a format specifier ``[width][type]``.
|
| 881 |
+
|
| 882 |
+
- ``width``
|
| 883 |
+
|
| 884 |
+
* unspecified (default): automatic to fill ``ncols``
|
| 885 |
+
* ``int >= 0``: fixed width overriding ``ncols`` logic
|
| 886 |
+
* ``int < 0``: subtract from the automatic default
|
| 887 |
+
|
| 888 |
+
- ``type``
|
| 889 |
+
|
| 890 |
+
* ``a``: ascii (``ascii=True`` override)
|
| 891 |
+
* ``u``: unicode (``ascii=False`` override)
|
| 892 |
+
* ``b``: blank (``ascii=" "`` override)
|
| 893 |
+
|
| 894 |
+
This means a fixed bar with right-justified text may be created by using:
|
| 895 |
+
``bar_format="{l_bar}{bar:10}|{bar:-10b}right-justified"``
|
| 896 |
+
|
| 897 |
+
Nested progress bars
|
| 898 |
+
~~~~~~~~~~~~~~~~~~~~
|
| 899 |
+
|
| 900 |
+
``tqdm`` supports nested progress bars. Here's an example:
|
| 901 |
+
|
| 902 |
+
.. code:: python
|
| 903 |
+
|
| 904 |
+
from tqdm.auto import trange
|
| 905 |
+
from time import sleep
|
| 906 |
+
|
| 907 |
+
for i in trange(4, desc='1st loop'):
|
| 908 |
+
for j in trange(5, desc='2nd loop'):
|
| 909 |
+
for k in trange(50, desc='3rd loop', leave=False):
|
| 910 |
+
sleep(0.01)
|
| 911 |
+
|
| 912 |
+
For manual control over positioning (e.g. for multi-processing use),
|
| 913 |
+
you may specify ``position=n`` where ``n=0`` for the outermost bar,
|
| 914 |
+
``n=1`` for the next, and so on.
|
| 915 |
+
However, it's best to check if ``tqdm`` can work without manual ``position``
|
| 916 |
+
first.
|
| 917 |
+
|
| 918 |
+
.. code:: python
|
| 919 |
+
|
| 920 |
+
from time import sleep
|
| 921 |
+
from tqdm import trange, tqdm
|
| 922 |
+
from multiprocessing import Pool, RLock, freeze_support
|
| 923 |
+
|
| 924 |
+
L = list(range(9))
|
| 925 |
+
|
| 926 |
+
def progresser(n):
|
| 927 |
+
interval = 0.001 / (n + 2)
|
| 928 |
+
total = 5000
|
| 929 |
+
text = f"#{n}, est. {interval * total:<04.2}s"
|
| 930 |
+
for _ in trange(total, desc=text, position=n):
|
| 931 |
+
sleep(interval)
|
| 932 |
+
|
| 933 |
+
if __name__ == '__main__':
|
| 934 |
+
freeze_support() # for Windows support
|
| 935 |
+
tqdm.set_lock(RLock()) # for managing output contention
|
| 936 |
+
p = Pool(initializer=tqdm.set_lock, initargs=(tqdm.get_lock(),))
|
| 937 |
+
p.map(progresser, L)
|
| 938 |
+
|
| 939 |
+
Note that in Python 3, ``tqdm.write`` is thread-safe:
|
| 940 |
+
|
| 941 |
+
.. code:: python
|
| 942 |
+
|
| 943 |
+
from time import sleep
|
| 944 |
+
from tqdm import tqdm, trange
|
| 945 |
+
from concurrent.futures import ThreadPoolExecutor
|
| 946 |
+
|
| 947 |
+
L = list(range(9))
|
| 948 |
+
|
| 949 |
+
def progresser(n):
|
| 950 |
+
interval = 0.001 / (n + 2)
|
| 951 |
+
total = 5000
|
| 952 |
+
text = f"#{n}, est. {interval * total:<04.2}s"
|
| 953 |
+
for _ in trange(total, desc=text):
|
| 954 |
+
sleep(interval)
|
| 955 |
+
if n == 6:
|
| 956 |
+
tqdm.write("n == 6 completed.")
|
| 957 |
+
tqdm.write("`tqdm.write()` is thread-safe in py3!")
|
| 958 |
+
|
| 959 |
+
if __name__ == '__main__':
|
| 960 |
+
with ThreadPoolExecutor() as p:
|
| 961 |
+
p.map(progresser, L)
|
| 962 |
+
|
| 963 |
+
Hooks and callbacks
|
| 964 |
+
~~~~~~~~~~~~~~~~~~~
|
| 965 |
+
|
| 966 |
+
``tqdm`` can easily support callbacks/hooks and manual updates.
|
| 967 |
+
Here's an example with ``urllib``:
|
| 968 |
+
|
| 969 |
+
**``urllib.urlretrieve`` documentation**
|
| 970 |
+
|
| 971 |
+
| [...]
|
| 972 |
+
| If present, the hook function will be called once
|
| 973 |
+
| on establishment of the network connection and once after each block read
|
| 974 |
+
| thereafter. The hook will be passed three arguments; a count of blocks
|
| 975 |
+
| transferred so far, a block size in bytes, and the total size of the file.
|
| 976 |
+
| [...]
|
| 977 |
+
|
| 978 |
+
.. code:: python
|
| 979 |
+
|
| 980 |
+
import urllib, os
|
| 981 |
+
from tqdm import tqdm
|
| 982 |
+
urllib = getattr(urllib, 'request', urllib)
|
| 983 |
+
|
| 984 |
+
class TqdmUpTo(tqdm):
|
| 985 |
+
"""Provides `update_to(n)` which uses `tqdm.update(delta_n)`."""
|
| 986 |
+
def update_to(self, b=1, bsize=1, tsize=None):
|
| 987 |
+
"""
|
| 988 |
+
b : int, optional
|
| 989 |
+
Number of blocks transferred so far [default: 1].
|
| 990 |
+
bsize : int, optional
|
| 991 |
+
Size of each block (in tqdm units) [default: 1].
|
| 992 |
+
tsize : int, optional
|
| 993 |
+
Total size (in tqdm units). If [default: None] remains unchanged.
|
| 994 |
+
"""
|
| 995 |
+
if tsize is not None:
|
| 996 |
+
self.total = tsize
|
| 997 |
+
return self.update(b * bsize - self.n) # also sets self.n = b * bsize
|
| 998 |
+
|
| 999 |
+
eg_link = "https://cgi.cdcl.ml/matryoshka.zip"
|
| 1000 |
+
with TqdmUpTo(unit='B', unit_scale=True, unit_divisor=1024, miniters=1,
|
| 1001 |
+
desc=eg_link.split('/')[-1]) as t: # all optional kwargs
|
| 1002 |
+
urllib.urlretrieve(eg_link, filename=os.devnull,
|
| 1003 |
+
reporthook=t.update_to, data=None)
|
| 1004 |
+
t.total = t.n
|
| 1005 |
+
|
| 1006 |
+
Inspired by `twine#242 <https://github.com/pypa/twine/pull/242>`__.
|
| 1007 |
+
Functional alternative in
|
| 1008 |
+
`examples/tqdm_wget.py <https://github.com/tqdm/tqdm/blob/master/examples/tqdm_wget.py>`__.
|
| 1009 |
+
|
| 1010 |
+
It is recommend to use ``miniters=1`` whenever there is potentially
|
| 1011 |
+
large differences in iteration speed (e.g. downloading a file over
|
| 1012 |
+
a patchy connection).
|
| 1013 |
+
|
| 1014 |
+
**Wrapping read/write methods**
|
| 1015 |
+
|
| 1016 |
+
To measure throughput through a file-like object's ``read`` or ``write``
|
| 1017 |
+
methods, use ``CallbackIOWrapper``:
|
| 1018 |
+
|
| 1019 |
+
.. code:: python
|
| 1020 |
+
|
| 1021 |
+
from tqdm.auto import tqdm
|
| 1022 |
+
from tqdm.utils import CallbackIOWrapper
|
| 1023 |
+
|
| 1024 |
+
with tqdm(total=file_obj.size,
|
| 1025 |
+
unit='B', unit_scale=True, unit_divisor=1024) as t:
|
| 1026 |
+
fobj = CallbackIOWrapper(t.update, file_obj, "read")
|
| 1027 |
+
while True:
|
| 1028 |
+
chunk = fobj.read(chunk_size)
|
| 1029 |
+
if not chunk:
|
| 1030 |
+
break
|
| 1031 |
+
t.reset()
|
| 1032 |
+
# ... continue to use `t` for something else
|
| 1033 |
+
|
| 1034 |
+
Alternatively, use the even simpler ``wrapattr`` convenience function,
|
| 1035 |
+
which would condense both the ``urllib`` and ``CallbackIOWrapper`` examples
|
| 1036 |
+
down to:
|
| 1037 |
+
|
| 1038 |
+
.. code:: python
|
| 1039 |
+
|
| 1040 |
+
import urllib, os
|
| 1041 |
+
from tqdm import tqdm
|
| 1042 |
+
|
| 1043 |
+
eg_link = "https://cgi.cdcl.ml/matryoshka.zip"
|
| 1044 |
+
response = getattr(urllib, 'request', urllib).urlopen(eg_link)
|
| 1045 |
+
with tqdm.wrapattr(open(os.devnull, "wb"), "write",
|
| 1046 |
+
miniters=1, desc=eg_link.split('/')[-1],
|
| 1047 |
+
total=getattr(response, 'length', None)) as fout:
|
| 1048 |
+
for chunk in response:
|
| 1049 |
+
fout.write(chunk)
|
| 1050 |
+
|
| 1051 |
+
The ``requests`` equivalent is nearly identical:
|
| 1052 |
+
|
| 1053 |
+
.. code:: python
|
| 1054 |
+
|
| 1055 |
+
import requests, os
|
| 1056 |
+
from tqdm import tqdm
|
| 1057 |
+
|
| 1058 |
+
eg_link = "https://cgi.cdcl.ml/matryoshka.zip"
|
| 1059 |
+
response = requests.get(eg_link, stream=True)
|
| 1060 |
+
with tqdm.wrapattr(open(os.devnull, "wb"), "write",
|
| 1061 |
+
miniters=1, desc=eg_link.split('/')[-1],
|
| 1062 |
+
total=int(response.headers.get('content-length', 0))) as fout:
|
| 1063 |
+
for chunk in response.iter_content(chunk_size=4096):
|
| 1064 |
+
fout.write(chunk)
|
| 1065 |
+
|
| 1066 |
+
**Custom callback**
|
| 1067 |
+
|
| 1068 |
+
``tqdm`` is known for intelligently skipping unnecessary displays. To make a
|
| 1069 |
+
custom callback take advantage of this, simply use the return value of
|
| 1070 |
+
``update()``. This is set to ``True`` if a ``display()`` was triggered.
|
| 1071 |
+
|
| 1072 |
+
.. code:: python
|
| 1073 |
+
|
| 1074 |
+
from tqdm.auto import tqdm as std_tqdm
|
| 1075 |
+
|
| 1076 |
+
def external_callback(*args, **kwargs):
|
| 1077 |
+
...
|
| 1078 |
+
|
| 1079 |
+
class TqdmExt(std_tqdm):
|
| 1080 |
+
def update(self, n=1):
|
| 1081 |
+
displayed = super().update(n)
|
| 1082 |
+
if displayed:
|
| 1083 |
+
external_callback(**self.format_dict)
|
| 1084 |
+
return displayed
|
| 1085 |
+
|
| 1086 |
+
``asyncio``
|
| 1087 |
+
~~~~~~~~~~~
|
| 1088 |
+
|
| 1089 |
+
Note that ``break`` isn't currently caught by asynchronous iterators.
|
| 1090 |
+
This means that ``tqdm`` cannot clean up after itself in this case:
|
| 1091 |
+
|
| 1092 |
+
.. code:: python
|
| 1093 |
+
|
| 1094 |
+
from tqdm.asyncio import tqdm
|
| 1095 |
+
|
| 1096 |
+
async for i in tqdm(range(9)):
|
| 1097 |
+
if i == 2:
|
| 1098 |
+
break
|
| 1099 |
+
|
| 1100 |
+
Instead, either call ``pbar.close()`` manually or use the context manager syntax:
|
| 1101 |
+
|
| 1102 |
+
.. code:: python
|
| 1103 |
+
|
| 1104 |
+
from tqdm.asyncio import tqdm
|
| 1105 |
+
|
| 1106 |
+
with tqdm(range(9)) as pbar:
|
| 1107 |
+
async for i in pbar:
|
| 1108 |
+
if i == 2:
|
| 1109 |
+
break
|
| 1110 |
+
|
| 1111 |
+
Pandas Integration
|
| 1112 |
+
~~~~~~~~~~~~~~~~~~
|
| 1113 |
+
|
| 1114 |
+
Due to popular demand we've added support for ``pandas`` -- here's an example
|
| 1115 |
+
for ``DataFrame.progress_apply`` and ``DataFrameGroupBy.progress_apply``:
|
| 1116 |
+
|
| 1117 |
+
.. code:: python
|
| 1118 |
+
|
| 1119 |
+
import pandas as pd
|
| 1120 |
+
import numpy as np
|
| 1121 |
+
from tqdm import tqdm
|
| 1122 |
+
|
| 1123 |
+
df = pd.DataFrame(np.random.randint(0, 100, (100000, 6)))
|
| 1124 |
+
|
| 1125 |
+
# Register `pandas.progress_apply` and `pandas.Series.map_apply` with `tqdm`
|
| 1126 |
+
# (can use `tqdm.gui.tqdm`, `tqdm.notebook.tqdm`, optional kwargs, etc.)
|
| 1127 |
+
tqdm.pandas(desc="my bar!")
|
| 1128 |
+
|
| 1129 |
+
# Now you can use `progress_apply` instead of `apply`
|
| 1130 |
+
# and `progress_map` instead of `map`
|
| 1131 |
+
df.progress_apply(lambda x: x**2)
|
| 1132 |
+
# can also groupby:
|
| 1133 |
+
# df.groupby(0).progress_apply(lambda x: x**2)
|
| 1134 |
+
|
| 1135 |
+
In case you're interested in how this works (and how to modify it for your
|
| 1136 |
+
own callbacks), see the
|
| 1137 |
+
`examples <https://github.com/tqdm/tqdm/tree/master/examples>`__
|
| 1138 |
+
folder or import the module and run ``help()``.
|
| 1139 |
+
|
| 1140 |
+
Keras Integration
|
| 1141 |
+
~~~~~~~~~~~~~~~~~
|
| 1142 |
+
|
| 1143 |
+
A ``keras`` callback is also available:
|
| 1144 |
+
|
| 1145 |
+
.. code:: python
|
| 1146 |
+
|
| 1147 |
+
from tqdm.keras import TqdmCallback
|
| 1148 |
+
|
| 1149 |
+
...
|
| 1150 |
+
|
| 1151 |
+
model.fit(..., verbose=0, callbacks=[TqdmCallback()])
|
| 1152 |
+
|
| 1153 |
+
Dask Integration
|
| 1154 |
+
~~~~~~~~~~~~~~~~
|
| 1155 |
+
|
| 1156 |
+
A ``dask`` callback is also available:
|
| 1157 |
+
|
| 1158 |
+
.. code:: python
|
| 1159 |
+
|
| 1160 |
+
from tqdm.dask import TqdmCallback
|
| 1161 |
+
|
| 1162 |
+
with TqdmCallback(desc="compute"):
|
| 1163 |
+
...
|
| 1164 |
+
arr.compute()
|
| 1165 |
+
|
| 1166 |
+
# or use callback globally
|
| 1167 |
+
cb = TqdmCallback(desc="global")
|
| 1168 |
+
cb.register()
|
| 1169 |
+
arr.compute()
|
| 1170 |
+
|
| 1171 |
+
IPython/Jupyter Integration
|
| 1172 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 1173 |
+
|
| 1174 |
+
IPython/Jupyter is supported via the ``tqdm.notebook`` submodule:
|
| 1175 |
+
|
| 1176 |
+
.. code:: python
|
| 1177 |
+
|
| 1178 |
+
from tqdm.notebook import trange, tqdm
|
| 1179 |
+
from time import sleep
|
| 1180 |
+
|
| 1181 |
+
for i in trange(3, desc='1st loop'):
|
| 1182 |
+
for j in tqdm(range(100), desc='2nd loop'):
|
| 1183 |
+
sleep(0.01)
|
| 1184 |
+
|
| 1185 |
+
In addition to ``tqdm`` features, the submodule provides a native Jupyter
|
| 1186 |
+
widget (compatible with IPython v1-v4 and Jupyter), fully working nested bars
|
| 1187 |
+
and colour hints (blue: normal, green: completed, red: error/interrupt,
|
| 1188 |
+
light blue: no ETA); as demonstrated below.
|
| 1189 |
+
|
| 1190 |
+
|Screenshot-Jupyter1|
|
| 1191 |
+
|Screenshot-Jupyter2|
|
| 1192 |
+
|Screenshot-Jupyter3|
|
| 1193 |
+
|
| 1194 |
+
The ``notebook`` version supports percentage or pixels for overall width
|
| 1195 |
+
(e.g.: ``ncols='100%'`` or ``ncols='480px'``).
|
| 1196 |
+
|
| 1197 |
+
It is also possible to let ``tqdm`` automatically choose between
|
| 1198 |
+
console or notebook versions by using the ``autonotebook`` submodule:
|
| 1199 |
+
|
| 1200 |
+
.. code:: python
|
| 1201 |
+
|
| 1202 |
+
from tqdm.autonotebook import tqdm
|
| 1203 |
+
tqdm.pandas()
|
| 1204 |
+
|
| 1205 |
+
Note that this will issue a ``TqdmExperimentalWarning`` if run in a notebook
|
| 1206 |
+
since it is not meant to be possible to distinguish between ``jupyter notebook``
|
| 1207 |
+
and ``jupyter console``. Use ``auto`` instead of ``autonotebook`` to suppress
|
| 1208 |
+
this warning.
|
| 1209 |
+
|
| 1210 |
+
Note that notebooks will display the bar in the cell where it was created.
|
| 1211 |
+
This may be a different cell from the one where it is used.
|
| 1212 |
+
If this is not desired, either
|
| 1213 |
+
|
| 1214 |
+
- delay the creation of the bar to the cell where it must be displayed, or
|
| 1215 |
+
- create the bar with ``display=False``, and in a later cell call
|
| 1216 |
+
``display(bar.container)``:
|
| 1217 |
+
|
| 1218 |
+
.. code:: python
|
| 1219 |
+
|
| 1220 |
+
from tqdm.notebook import tqdm
|
| 1221 |
+
pbar = tqdm(..., display=False)
|
| 1222 |
+
|
| 1223 |
+
.. code:: python
|
| 1224 |
+
|
| 1225 |
+
# different cell
|
| 1226 |
+
display(pbar.container)
|
| 1227 |
+
|
| 1228 |
+
The ``keras`` callback has a ``display()`` method which can be used likewise:
|
| 1229 |
+
|
| 1230 |
+
.. code:: python
|
| 1231 |
+
|
| 1232 |
+
from tqdm.keras import TqdmCallback
|
| 1233 |
+
cbk = TqdmCallback(display=False)
|
| 1234 |
+
|
| 1235 |
+
.. code:: python
|
| 1236 |
+
|
| 1237 |
+
# different cell
|
| 1238 |
+
cbk.display()
|
| 1239 |
+
model.fit(..., verbose=0, callbacks=[cbk])
|
| 1240 |
+
|
| 1241 |
+
Another possibility is to have a single bar (near the top of the notebook)
|
| 1242 |
+
which is constantly re-used (using ``reset()`` rather than ``close()``).
|
| 1243 |
+
For this reason, the notebook version (unlike the CLI version) does not
|
| 1244 |
+
automatically call ``close()`` upon ``Exception``.
|
| 1245 |
+
|
| 1246 |
+
.. code:: python
|
| 1247 |
+
|
| 1248 |
+
from tqdm.notebook import tqdm
|
| 1249 |
+
pbar = tqdm()
|
| 1250 |
+
|
| 1251 |
+
.. code:: python
|
| 1252 |
+
|
| 1253 |
+
# different cell
|
| 1254 |
+
iterable = range(100)
|
| 1255 |
+
pbar.reset(total=len(iterable)) # initialise with new `total`
|
| 1256 |
+
for i in iterable:
|
| 1257 |
+
pbar.update()
|
| 1258 |
+
pbar.refresh() # force print final status but don't `close()`
|
| 1259 |
+
|
| 1260 |
+
Custom Integration
|
| 1261 |
+
~~~~~~~~~~~~~~~~~~
|
| 1262 |
+
|
| 1263 |
+
To change the default arguments (such as making ``dynamic_ncols=True``),
|
| 1264 |
+
simply use built-in Python magic:
|
| 1265 |
+
|
| 1266 |
+
.. code:: python
|
| 1267 |
+
|
| 1268 |
+
from functools import partial
|
| 1269 |
+
from tqdm import tqdm as std_tqdm
|
| 1270 |
+
tqdm = partial(std_tqdm, dynamic_ncols=True)
|
| 1271 |
+
|
| 1272 |
+
For further customisation,
|
| 1273 |
+
``tqdm`` may be inherited from to create custom callbacks (as with the
|
| 1274 |
+
``TqdmUpTo`` example `above <#hooks-and-callbacks>`__) or for custom frontends
|
| 1275 |
+
(e.g. GUIs such as notebook or plotting packages). In the latter case:
|
| 1276 |
+
|
| 1277 |
+
1. ``def __init__()`` to call ``super().__init__(..., gui=True)`` to disable
|
| 1278 |
+
terminal ``status_printer`` creation.
|
| 1279 |
+
2. Redefine: ``close()``, ``clear()``, ``display()``.
|
| 1280 |
+
|
| 1281 |
+
Consider overloading ``display()`` to use e.g.
|
| 1282 |
+
``self.frontend(**self.format_dict)`` instead of ``self.sp(repr(self))``.
|
| 1283 |
+
|
| 1284 |
+
Some submodule examples of inheritance:
|
| 1285 |
+
|
| 1286 |
+
- `tqdm/notebook.py <https://github.com/tqdm/tqdm/blob/master/tqdm/notebook.py>`__
|
| 1287 |
+
- `tqdm/gui.py <https://github.com/tqdm/tqdm/blob/master/tqdm/gui.py>`__
|
| 1288 |
+
- `tqdm/tk.py <https://github.com/tqdm/tqdm/blob/master/tqdm/tk.py>`__
|
| 1289 |
+
- `tqdm/contrib/slack.py <https://github.com/tqdm/tqdm/blob/master/tqdm/contrib/slack.py>`__
|
| 1290 |
+
- `tqdm/contrib/discord.py <https://github.com/tqdm/tqdm/blob/master/tqdm/contrib/discord.py>`__
|
| 1291 |
+
- `tqdm/contrib/telegram.py <https://github.com/tqdm/tqdm/blob/master/tqdm/contrib/telegram.py>`__
|
| 1292 |
+
|
| 1293 |
+
Dynamic Monitor/Meter
|
| 1294 |
+
~~~~~~~~~~~~~~~~~~~~~
|
| 1295 |
+
|
| 1296 |
+
You can use a ``tqdm`` as a meter which is not monotonically increasing.
|
| 1297 |
+
This could be because ``n`` decreases (e.g. a CPU usage monitor) or ``total``
|
| 1298 |
+
changes.
|
| 1299 |
+
|
| 1300 |
+
One example would be recursively searching for files. The ``total`` is the
|
| 1301 |
+
number of objects found so far, while ``n`` is the number of those objects which
|
| 1302 |
+
are files (rather than folders):
|
| 1303 |
+
|
| 1304 |
+
.. code:: python
|
| 1305 |
+
|
| 1306 |
+
from tqdm import tqdm
|
| 1307 |
+
import os.path
|
| 1308 |
+
|
| 1309 |
+
def find_files_recursively(path, show_progress=True):
|
| 1310 |
+
files = []
|
| 1311 |
+
# total=1 assumes `path` is a file
|
| 1312 |
+
t = tqdm(total=1, unit="file", disable=not show_progress)
|
| 1313 |
+
if not os.path.exists(path):
|
| 1314 |
+
raise IOError("Cannot find:" + path)
|
| 1315 |
+
|
| 1316 |
+
def append_found_file(f):
|
| 1317 |
+
files.append(f)
|
| 1318 |
+
t.update()
|
| 1319 |
+
|
| 1320 |
+
def list_found_dir(path):
|
| 1321 |
+
"""returns os.listdir(path) assuming os.path.isdir(path)"""
|
| 1322 |
+
listing = os.listdir(path)
|
| 1323 |
+
# subtract 1 since a "file" we found was actually this directory
|
| 1324 |
+
t.total += len(listing) - 1
|
| 1325 |
+
# fancy way to give info without forcing a refresh
|
| 1326 |
+
t.set_postfix(dir=path[-10:], refresh=False)
|
| 1327 |
+
t.update(0) # may trigger a refresh
|
| 1328 |
+
return listing
|
| 1329 |
+
|
| 1330 |
+
def recursively_search(path):
|
| 1331 |
+
if os.path.isdir(path):
|
| 1332 |
+
for f in list_found_dir(path):
|
| 1333 |
+
recursively_search(os.path.join(path, f))
|
| 1334 |
+
else:
|
| 1335 |
+
append_found_file(path)
|
| 1336 |
+
|
| 1337 |
+
recursively_search(path)
|
| 1338 |
+
t.set_postfix(dir=path)
|
| 1339 |
+
t.close()
|
| 1340 |
+
return files
|
| 1341 |
+
|
| 1342 |
+
Using ``update(0)`` is a handy way to let ``tqdm`` decide when to trigger a
|
| 1343 |
+
display refresh to avoid console spamming.
|
| 1344 |
+
|
| 1345 |
+
Writing messages
|
| 1346 |
+
~~~~~~~~~~~~~~~~
|
| 1347 |
+
|
| 1348 |
+
This is a work in progress (see
|
| 1349 |
+
`#737 <https://github.com/tqdm/tqdm/issues/737>`__).
|
| 1350 |
+
|
| 1351 |
+
Since ``tqdm`` uses a simple printing mechanism to display progress bars,
|
| 1352 |
+
you should not write any message in the terminal using ``print()`` while
|
| 1353 |
+
a progress bar is open.
|
| 1354 |
+
|
| 1355 |
+
To write messages in the terminal without any collision with ``tqdm`` bar
|
| 1356 |
+
display, a ``.write()`` method is provided:
|
| 1357 |
+
|
| 1358 |
+
.. code:: python
|
| 1359 |
+
|
| 1360 |
+
from tqdm.auto import tqdm, trange
|
| 1361 |
+
from time import sleep
|
| 1362 |
+
|
| 1363 |
+
bar = trange(10)
|
| 1364 |
+
for i in bar:
|
| 1365 |
+
# Print using tqdm class method .write()
|
| 1366 |
+
sleep(0.1)
|
| 1367 |
+
if not (i % 3):
|
| 1368 |
+
tqdm.write("Done task %i" % i)
|
| 1369 |
+
# Can also use bar.write()
|
| 1370 |
+
|
| 1371 |
+
By default, this will print to standard output ``sys.stdout``. but you can
|
| 1372 |
+
specify any file-like object using the ``file`` argument. For example, this
|
| 1373 |
+
can be used to redirect the messages writing to a log file or class.
|
| 1374 |
+
|
| 1375 |
+
Redirecting writing
|
| 1376 |
+
~~~~~~~~~~~~~~~~~~~
|
| 1377 |
+
|
| 1378 |
+
If using a library that can print messages to the console, editing the library
|
| 1379 |
+
by replacing ``print()`` with ``tqdm.write()`` may not be desirable.
|
| 1380 |
+
In that case, redirecting ``sys.stdout`` to ``tqdm.write()`` is an option.
|
| 1381 |
+
|
| 1382 |
+
To redirect ``sys.stdout``, create a file-like class that will write
|
| 1383 |
+
any input string to ``tqdm.write()``, and supply the arguments
|
| 1384 |
+
``file=sys.stdout, dynamic_ncols=True``.
|
| 1385 |
+
|
| 1386 |
+
A reusable canonical example is given below:
|
| 1387 |
+
|
| 1388 |
+
.. code:: python
|
| 1389 |
+
|
| 1390 |
+
from time import sleep
|
| 1391 |
+
import contextlib
|
| 1392 |
+
import sys
|
| 1393 |
+
from tqdm import tqdm
|
| 1394 |
+
from tqdm.contrib import DummyTqdmFile
|
| 1395 |
+
|
| 1396 |
+
|
| 1397 |
+
@contextlib.contextmanager
|
| 1398 |
+
def std_out_err_redirect_tqdm():
|
| 1399 |
+
orig_out_err = sys.stdout, sys.stderr
|
| 1400 |
+
try:
|
| 1401 |
+
sys.stdout, sys.stderr = map(DummyTqdmFile, orig_out_err)
|
| 1402 |
+
yield orig_out_err[0]
|
| 1403 |
+
# Relay exceptions
|
| 1404 |
+
except Exception as exc:
|
| 1405 |
+
raise exc
|
| 1406 |
+
# Always restore sys.stdout/err if necessary
|
| 1407 |
+
finally:
|
| 1408 |
+
sys.stdout, sys.stderr = orig_out_err
|
| 1409 |
+
|
| 1410 |
+
def some_fun(i):
|
| 1411 |
+
print("Fee, fi, fo,".split()[i])
|
| 1412 |
+
|
| 1413 |
+
# Redirect stdout to tqdm.write() (don't forget the `as save_stdout`)
|
| 1414 |
+
with std_out_err_redirect_tqdm() as orig_stdout:
|
| 1415 |
+
# tqdm needs the original stdout
|
| 1416 |
+
# and dynamic_ncols=True to autodetect console width
|
| 1417 |
+
for i in tqdm(range(3), file=orig_stdout, dynamic_ncols=True):
|
| 1418 |
+
sleep(.5)
|
| 1419 |
+
some_fun(i)
|
| 1420 |
+
|
| 1421 |
+
# After the `with`, printing is restored
|
| 1422 |
+
print("Done!")
|
| 1423 |
+
|
| 1424 |
+
Redirecting ``logging``
|
| 1425 |
+
~~~~~~~~~~~~~~~~~~~~~~~
|
| 1426 |
+
|
| 1427 |
+
Similar to ``sys.stdout``/``sys.stderr`` as detailed above, console ``logging``
|
| 1428 |
+
may also be redirected to ``tqdm.write()``.
|
| 1429 |
+
|
| 1430 |
+
Warning: if also redirecting ``sys.stdout``/``sys.stderr``, make sure to
|
| 1431 |
+
redirect ``logging`` first if needed.
|
| 1432 |
+
|
| 1433 |
+
Helper methods are available in ``tqdm.contrib.logging``. For example:
|
| 1434 |
+
|
| 1435 |
+
.. code:: python
|
| 1436 |
+
|
| 1437 |
+
import logging
|
| 1438 |
+
from tqdm import trange
|
| 1439 |
+
from tqdm.contrib.logging import logging_redirect_tqdm
|
| 1440 |
+
|
| 1441 |
+
LOG = logging.getLogger(__name__)
|
| 1442 |
+
|
| 1443 |
+
if __name__ == '__main__':
|
| 1444 |
+
logging.basicConfig(level=logging.INFO)
|
| 1445 |
+
with logging_redirect_tqdm():
|
| 1446 |
+
for i in trange(9):
|
| 1447 |
+
if i == 4:
|
| 1448 |
+
LOG.info("console logging redirected to `tqdm.write()`")
|
| 1449 |
+
# logging restored
|
| 1450 |
+
|
| 1451 |
+
Monitoring thread, intervals and miniters
|
| 1452 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 1453 |
+
|
| 1454 |
+
``tqdm`` implements a few tricks to increase efficiency and reduce overhead.
|
| 1455 |
+
|
| 1456 |
+
- Avoid unnecessary frequent bar refreshing: ``mininterval`` defines how long
|
| 1457 |
+
to wait between each refresh. ``tqdm`` always gets updated in the background,
|
| 1458 |
+
but it will display only every ``mininterval``.
|
| 1459 |
+
- Reduce number of calls to check system clock/time.
|
| 1460 |
+
- ``mininterval`` is more intuitive to configure than ``miniters``.
|
| 1461 |
+
A clever adjustment system ``dynamic_miniters`` will automatically adjust
|
| 1462 |
+
``miniters`` to the amount of iterations that fit into time ``mininterval``.
|
| 1463 |
+
Essentially, ``tqdm`` will check if it's time to print without actually
|
| 1464 |
+
checking time. This behaviour can be still be bypassed by manually setting
|
| 1465 |
+
``miniters``.
|
| 1466 |
+
|
| 1467 |
+
However, consider a case with a combination of fast and slow iterations.
|
| 1468 |
+
After a few fast iterations, ``dynamic_miniters`` will set ``miniters`` to a
|
| 1469 |
+
large number. When iteration rate subsequently slows, ``miniters`` will
|
| 1470 |
+
remain large and thus reduce display update frequency. To address this:
|
| 1471 |
+
|
| 1472 |
+
- ``maxinterval`` defines the maximum time between display refreshes.
|
| 1473 |
+
A concurrent monitoring thread checks for overdue updates and forces one
|
| 1474 |
+
where necessary.
|
| 1475 |
+
|
| 1476 |
+
The monitoring thread should not have a noticeable overhead, and guarantees
|
| 1477 |
+
updates at least every 10 seconds by default.
|
| 1478 |
+
This value can be directly changed by setting the ``monitor_interval`` of
|
| 1479 |
+
any ``tqdm`` instance (i.e. ``t = tqdm.tqdm(...); t.monitor_interval = 2``).
|
| 1480 |
+
The monitor thread may be disabled application-wide by setting
|
| 1481 |
+
``tqdm.tqdm.monitor_interval = 0`` before instantiation of any ``tqdm`` bar.
|
| 1482 |
+
|
| 1483 |
+
|
| 1484 |
+
Merch
|
| 1485 |
+
-----
|
| 1486 |
+
|
| 1487 |
+
You can buy `tqdm branded merch <https://tqdm.github.io/merch>`__ now!
|
| 1488 |
+
|
| 1489 |
+
Contributions
|
| 1490 |
+
-------------
|
| 1491 |
+
|
| 1492 |
+
|GitHub-Commits| |GitHub-Issues| |GitHub-PRs| |OpenHub-Status| |GitHub-Contributions| |CII Best Practices|
|
| 1493 |
+
|
| 1494 |
+
All source code is hosted on `GitHub <https://github.com/tqdm/tqdm>`__.
|
| 1495 |
+
Contributions are welcome.
|
| 1496 |
+
|
| 1497 |
+
See the
|
| 1498 |
+
`CONTRIBUTING <https://github.com/tqdm/tqdm/blob/master/CONTRIBUTING.md>`__
|
| 1499 |
+
file for more information.
|
| 1500 |
+
|
| 1501 |
+
Developers who have contributed more that 5 *loc* (surviving lines of code):
|
| 1502 |
+
|
| 1503 |
+
|git-fame|
|
| 1504 |
+
|
| 1505 |
+
Honourable mentions:
|
| 1506 |
+
|
| 1507 |
+
- Casper da Costa-Luis `casperdcl <https://github.com/casperdcl>`__ primary maintainer |Gift-Casper|
|
| 1508 |
+
- Stephen Larroque `lrq3000 <https://github.com/lrq3000>`__ maintainer
|
| 1509 |
+
- Hadrien Mary `hadim <https://github.com/hadim>`__ maintainer
|
| 1510 |
+
- Mikhail Korobov `kmike <https://github.com/kmike>`__ maintainer
|
| 1511 |
+
- Noam Yorav-Raphael `noamraph <https://github.com/noamraph>`__ original author
|
| 1512 |
+
|
| 1513 |
+
Ports to Other Languages
|
| 1514 |
+
~~~~~~~~~~~~~~~~~~~~~~~~
|
| 1515 |
+
|
| 1516 |
+
A list is available on
|
| 1517 |
+
`this wiki page <https://github.com/tqdm/tqdm/wiki/tqdm-ports>`__.
|
| 1518 |
+
|
| 1519 |
+
|
| 1520 |
+
LICENCE
|
| 1521 |
+
-------
|
| 1522 |
+
|
| 1523 |
+
Open Source (OSI approved): |LICENCE|
|
| 1524 |
+
|
| 1525 |
+
Citation information: |DOI|
|
| 1526 |
+
|
| 1527 |
+
|README-Hits| (Since 19 May 2016)
|
| 1528 |
+
|
| 1529 |
+
.. |Logo| image:: https://tqdm.github.io/img/logo.gif
|
| 1530 |
+
.. |Screenshot| image:: https://tqdm.github.io/img/tqdm.gif
|
| 1531 |
+
.. |Video| image:: https://tqdm.github.io/img/video.jpg
|
| 1532 |
+
:target: https://tqdm.github.io/video
|
| 1533 |
+
.. |Slides| image:: https://tqdm.github.io/img/slides.jpg
|
| 1534 |
+
:target: https://tqdm.github.io/PyData2019/slides.html
|
| 1535 |
+
.. |Merch| image:: https://tqdm.github.io/img/merch.jpg
|
| 1536 |
+
:target: https://tqdm.github.io/merch
|
| 1537 |
+
.. |Build-Status| image:: https://img.shields.io/github/actions/workflow/status/tqdm/tqdm/test.yml?branch=master&label=tqdm&logo=GitHub
|
| 1538 |
+
:target: https://github.com/tqdm/tqdm/actions/workflows/test.yml
|
| 1539 |
+
.. |Coverage-Status| image:: https://img.shields.io/coveralls/github/tqdm/tqdm/master?logo=coveralls
|
| 1540 |
+
:target: https://coveralls.io/github/tqdm/tqdm
|
| 1541 |
+
.. |Branch-Coverage-Status| image:: https://codecov.io/gh/tqdm/tqdm/branch/master/graph/badge.svg
|
| 1542 |
+
:target: https://codecov.io/gh/tqdm/tqdm
|
| 1543 |
+
.. |Codacy-Grade| image:: https://app.codacy.com/project/badge/Grade/3f965571598f44549c7818f29cdcf177
|
| 1544 |
+
:target: https://app.codacy.com/gh/tqdm/tqdm/dashboard
|
| 1545 |
+
.. |CII Best Practices| image:: https://bestpractices.coreinfrastructure.org/projects/3264/badge
|
| 1546 |
+
:target: https://bestpractices.coreinfrastructure.org/projects/3264
|
| 1547 |
+
.. |GitHub-Status| image:: https://img.shields.io/github/tag/tqdm/tqdm.svg?maxAge=86400&logo=github&logoColor=white
|
| 1548 |
+
:target: https://github.com/tqdm/tqdm/releases
|
| 1549 |
+
.. |GitHub-Forks| image:: https://img.shields.io/github/forks/tqdm/tqdm.svg?logo=github&logoColor=white
|
| 1550 |
+
:target: https://github.com/tqdm/tqdm/network
|
| 1551 |
+
.. |GitHub-Stars| image:: https://img.shields.io/github/stars/tqdm/tqdm.svg?logo=github&logoColor=white
|
| 1552 |
+
:target: https://github.com/tqdm/tqdm/stargazers
|
| 1553 |
+
.. |GitHub-Commits| image:: https://img.shields.io/github/commit-activity/y/tqdm/tqdm.svg?logo=git&logoColor=white
|
| 1554 |
+
:target: https://github.com/tqdm/tqdm/graphs/commit-activity
|
| 1555 |
+
.. |GitHub-Issues| image:: https://img.shields.io/github/issues-closed/tqdm/tqdm.svg?logo=github&logoColor=white
|
| 1556 |
+
:target: https://github.com/tqdm/tqdm/issues?q=
|
| 1557 |
+
.. |GitHub-PRs| image:: https://img.shields.io/github/issues-pr-closed/tqdm/tqdm.svg?logo=github&logoColor=white
|
| 1558 |
+
:target: https://github.com/tqdm/tqdm/pulls
|
| 1559 |
+
.. |GitHub-Contributions| image:: https://img.shields.io/github/contributors/tqdm/tqdm.svg?logo=github&logoColor=white
|
| 1560 |
+
:target: https://github.com/tqdm/tqdm/graphs/contributors
|
| 1561 |
+
.. |GitHub-Updated| image:: https://img.shields.io/github/last-commit/tqdm/tqdm/master.svg?logo=github&logoColor=white&label=pushed
|
| 1562 |
+
:target: https://github.com/tqdm/tqdm/pulse
|
| 1563 |
+
.. |git-fame| image:: https://git-fame.cdcl.ml/gh/tqdm/tqdm?min=5&w=1&M=1&C=1&excl=(png|gif|jpg)$&enum=1
|
| 1564 |
+
:alt: git-fame.cdcl.ml/gh/tqdm/tqdm
|
| 1565 |
+
:target: https://git-fame.cdcl.ml/gh/tqdm/tqdm?w=1&M=1&C=1&excl=(png|gif|jpg)$&enum=1
|
| 1566 |
+
.. |Gift-Casper| image:: https://img.shields.io/badge/sponsor-casper-ff69b4.svg
|
| 1567 |
+
:target: https://cdcl.ml/sponsor
|
| 1568 |
+
.. |Versions| image:: https://img.shields.io/pypi/v/tqdm.svg
|
| 1569 |
+
:target: https://tqdm.github.io/releases
|
| 1570 |
+
.. |PyPI-Downloads| image:: https://static.pepy.tech/personalized-badge/tqdm?left_text=downloads%2Fmonth
|
| 1571 |
+
:target: https://pepy.tech/project/tqdm
|
| 1572 |
+
.. |Py-Versions| image:: https://img.shields.io/pypi/pyversions/tqdm.svg?logo=python&logoColor=white
|
| 1573 |
+
:target: https://pypi.org/project/tqdm
|
| 1574 |
+
.. |Conda-Forge-Status| image:: https://img.shields.io/conda/v/conda-forge/tqdm.svg?label=conda-forge&logo=conda-forge
|
| 1575 |
+
:target: https://anaconda.org/conda-forge/tqdm
|
| 1576 |
+
.. |Snapcraft| image:: https://img.shields.io/badge/snap-install-82BEA0.svg?logo=snapcraft
|
| 1577 |
+
:target: https://snapcraft.io/tqdm
|
| 1578 |
+
.. |Docker| image:: https://img.shields.io/badge/docker-pull-blue.svg?logo=docker&logoColor=white
|
| 1579 |
+
:target: https://hub.docker.com/r/tqdm/tqdm
|
| 1580 |
+
.. |Libraries-Rank| image:: https://img.shields.io/librariesio/sourcerank/pypi/tqdm.svg?logo=koding&logoColor=white
|
| 1581 |
+
:target: https://libraries.io/pypi/tqdm
|
| 1582 |
+
.. |Libraries-Dependents| image:: https://img.shields.io/librariesio/dependent-repos/pypi/tqdm.svg?logo=koding&logoColor=white
|
| 1583 |
+
:target: https://github.com/tqdm/tqdm/network/dependents
|
| 1584 |
+
.. |OpenHub-Status| image:: https://www.openhub.net/p/tqdm/widgets/project_thin_badge?format=gif
|
| 1585 |
+
:target: https://www.openhub.net/p/tqdm?ref=Thin+badge
|
| 1586 |
+
.. |awesome-python| image:: https://awesome.re/mentioned-badge.svg
|
| 1587 |
+
:target: https://github.com/vinta/awesome-python
|
| 1588 |
+
.. |LICENCE| image:: https://img.shields.io/pypi/l/tqdm.svg
|
| 1589 |
+
:target: https://raw.githubusercontent.com/tqdm/tqdm/master/LICENCE
|
| 1590 |
+
.. |DOI| image:: https://img.shields.io/badge/DOI-10.5281/zenodo.595120-blue.svg
|
| 1591 |
+
:target: https://doi.org/10.5281/zenodo.595120
|
| 1592 |
+
.. |colab-demo| image:: https://colab.research.google.com/assets/colab-badge.svg
|
| 1593 |
+
:target: https://colab.research.google.com/github/tqdm/tqdm/blob/master/DEMO.ipynb
|
| 1594 |
+
.. |binder-demo| image:: https://mybinder.org/badge_logo.svg
|
| 1595 |
+
:target: https://mybinder.org/v2/gh/tqdm/tqdm/master?filepath=DEMO.ipynb
|
| 1596 |
+
.. |Screenshot-Jupyter1| image:: https://tqdm.github.io/img/jupyter-1.gif
|
| 1597 |
+
.. |Screenshot-Jupyter2| image:: https://tqdm.github.io/img/jupyter-2.gif
|
| 1598 |
+
.. |Screenshot-Jupyter3| image:: https://tqdm.github.io/img/jupyter-3.gif
|
| 1599 |
+
.. |README-Hits| image:: https://cgi.cdcl.ml/hits?q=tqdm&style=social&r=https://github.com/tqdm/tqdm&l=https://tqdm.github.io/img/favicon.png&f=https://tqdm.github.io/img/logo.gif
|
| 1600 |
+
:target: https://cgi.cdcl.ml/hits?q=tqdm&a=plot&r=https://github.com/tqdm/tqdm&l=https://tqdm.github.io/img/favicon.png&f=https://tqdm.github.io/img/logo.gif&style=social
|
.venv/lib/python3.13/site-packages/tqdm-4.70.0.dist-info/RECORD
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
../../../bin/tqdm,sha256=oGK3Vd9kfKRtl3EPSX3jE2bWjfjzSKSvtSX1n0y6Ams,259
|
| 2 |
+
tqdm-4.70.0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
| 3 |
+
tqdm-4.70.0.dist-info/METADATA,sha256=DZW4W5BCj4d2r8SpKxfFCU947pjRULMlWsvN9OnVeUE,57344
|
| 4 |
+
tqdm-4.70.0.dist-info/RECORD,,
|
| 5 |
+
tqdm-4.70.0.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
|
| 6 |
+
tqdm-4.70.0.dist-info/entry_points.txt,sha256=ReJCH7Ui3Zyh6M16E4OhsZ1oU7WtMXCfbtoyBhGO29Y,39
|
| 7 |
+
tqdm-4.70.0.dist-info/licenses/LICENCE,sha256=_P-Hw6R86AKKhRKqGC1PzwrRyQVE7nXPmzQ2hMrBlN4,1985
|
| 8 |
+
tqdm-4.70.0.dist-info/top_level.txt,sha256=NLiUJNfmc9At15s7JURiwvqMEjUi9G5PMGRrmMYzNSM,5
|
| 9 |
+
tqdm/__init__.py,sha256=9mQNYSSqP99JasubEC1POJLMmhkkBH6cJZxPIR5G2pQ,1572
|
| 10 |
+
tqdm/__main__.py,sha256=bYt9eEaoRQWdejEHFD8REx9jxVEdZptECFsV7F49Ink,30
|
| 11 |
+
tqdm/__pycache__/__init__.cpython-313.pyc,,
|
| 12 |
+
tqdm/__pycache__/__main__.cpython-313.pyc,,
|
| 13 |
+
tqdm/__pycache__/_main.cpython-313.pyc,,
|
| 14 |
+
tqdm/__pycache__/_monitor.cpython-313.pyc,,
|
| 15 |
+
tqdm/__pycache__/_tqdm.cpython-313.pyc,,
|
| 16 |
+
tqdm/__pycache__/_tqdm_gui.cpython-313.pyc,,
|
| 17 |
+
tqdm/__pycache__/_tqdm_notebook.cpython-313.pyc,,
|
| 18 |
+
tqdm/__pycache__/_tqdm_pandas.cpython-313.pyc,,
|
| 19 |
+
tqdm/__pycache__/_utils.cpython-313.pyc,,
|
| 20 |
+
tqdm/__pycache__/asyncio.cpython-313.pyc,,
|
| 21 |
+
tqdm/__pycache__/auto.cpython-313.pyc,,
|
| 22 |
+
tqdm/__pycache__/autonotebook.cpython-313.pyc,,
|
| 23 |
+
tqdm/__pycache__/cli.cpython-313.pyc,,
|
| 24 |
+
tqdm/__pycache__/dask.cpython-313.pyc,,
|
| 25 |
+
tqdm/__pycache__/gui.cpython-313.pyc,,
|
| 26 |
+
tqdm/__pycache__/keras.cpython-313.pyc,,
|
| 27 |
+
tqdm/__pycache__/notebook.cpython-313.pyc,,
|
| 28 |
+
tqdm/__pycache__/rich.cpython-313.pyc,,
|
| 29 |
+
tqdm/__pycache__/std.cpython-313.pyc,,
|
| 30 |
+
tqdm/__pycache__/tk.cpython-313.pyc,,
|
| 31 |
+
tqdm/__pycache__/utils.cpython-313.pyc,,
|
| 32 |
+
tqdm/__pycache__/version.cpython-313.pyc,,
|
| 33 |
+
tqdm/_main.py,sha256=9ySvgmi_2Sw4CAo5UDW0Q2dxfTryboEWGHohfCJz0sA,283
|
| 34 |
+
tqdm/_monitor.py,sha256=1VcavuotYSN6K-1jbpNuy6HYtr3mwo5Nh_jZMQ-jg3A,4013
|
| 35 |
+
tqdm/_tqdm.py,sha256=LfLCuJ6bpsVo9xilmtBXyEm1vGnUCFrliW85j3J-nD4,283
|
| 36 |
+
tqdm/_tqdm_gui.py,sha256=03Hc8KayxJveieI5-0-2NGiDpLvw9jZekofJUV7CCwk,287
|
| 37 |
+
tqdm/_tqdm_notebook.py,sha256=BuHiLuxu6uEfZFaPJW3RPpPaxaVctEQA3kdSJSDL1hw,307
|
| 38 |
+
tqdm/_tqdm_pandas.py,sha256=c9jptUgigN6axRDhRd4Rif98Tmxeopc1nFNFhIpbFUE,888
|
| 39 |
+
tqdm/_utils.py,sha256=CfLztxFY-QRiNfxQCqAb2N8E13uauIM95RSQiFlaEuE,559
|
| 40 |
+
tqdm/asyncio.py,sha256=IpcGo6ZFwc6KKHYj5s7h4kaRiogcabJ6PcqHj6jdy0I,3196
|
| 41 |
+
tqdm/auto.py,sha256=nDZflj6p2zKkjBCNBourrhS81zYfZy1_dQvbckrdW8o,871
|
| 42 |
+
tqdm/autonotebook.py,sha256=2pNgGCJDsesNNyYnmSve8BNQLiGSgo97SsPoMXCrNRQ,1440
|
| 43 |
+
tqdm/cli.py,sha256=t1j_PqI0SuMyhJGoBxMPCXY-UTbfjciaAQYxAU_f_V0,11011
|
| 44 |
+
tqdm/completion.sh,sha256=j79KbSmpIj_E11jfTfBXrGnUTzKXVpQ1vGVQvsyDRl4,946
|
| 45 |
+
tqdm/contrib/__init__.py,sha256=1GMYYE866WCvlHg5MdmzOvPsQj4ZuMlXzz8xcRcJD60,2479
|
| 46 |
+
tqdm/contrib/__pycache__/__init__.cpython-313.pyc,,
|
| 47 |
+
tqdm/contrib/__pycache__/bells.cpython-313.pyc,,
|
| 48 |
+
tqdm/contrib/__pycache__/concurrent.cpython-313.pyc,,
|
| 49 |
+
tqdm/contrib/__pycache__/discord.cpython-313.pyc,,
|
| 50 |
+
tqdm/contrib/__pycache__/itertools.cpython-313.pyc,,
|
| 51 |
+
tqdm/contrib/__pycache__/logging.cpython-313.pyc,,
|
| 52 |
+
tqdm/contrib/__pycache__/slack.cpython-313.pyc,,
|
| 53 |
+
tqdm/contrib/__pycache__/telegram.cpython-313.pyc,,
|
| 54 |
+
tqdm/contrib/__pycache__/utils_worker.cpython-313.pyc,,
|
| 55 |
+
tqdm/contrib/bells.py,sha256=IaxC2YW57xHDinxdUDQHvSego0HSTdDTExQQENvSB_k,921
|
| 56 |
+
tqdm/contrib/concurrent.py,sha256=XAgKYE2of1XIOEsD-gtrK82xQzDA1PEwvIpP_jcEuTs,9849
|
| 57 |
+
tqdm/contrib/discord.py,sha256=LPjxDbmfiYtw3OAm_WhtwbX9BVYDlPc8lJ96aY3YZDE,5337
|
| 58 |
+
tqdm/contrib/itertools.py,sha256=MA9-Jvb3ToseppInvev2iF4bokN7GQy4Q4LgjUyYdA4,2949
|
| 59 |
+
tqdm/contrib/logging.py,sha256=0nFn2C7qUUiKPB19qTGuS9Lfja8aiFW0u9kybRdG0hU,3902
|
| 60 |
+
tqdm/contrib/slack.py,sha256=sC182v7xBkfGftnDeUmQALMOfwQzU3ZiNf1Q_XA1DjI,4049
|
| 61 |
+
tqdm/contrib/telegram.py,sha256=ybTraGjUQx5m443TsX6pJ7Uxrpsh1m4a43BTWVl_4e4,5081
|
| 62 |
+
tqdm/contrib/utils_worker.py,sha256=vaxyJyagYwOCQXLUMd86bCbI4sPqZysuMGbDSGmvEWo,1199
|
| 63 |
+
tqdm/dask.py,sha256=9Ei58eVqTossRLhAfWyUFCduXYKjmLmwkaXIy-CHYfs,1319
|
| 64 |
+
tqdm/gui.py,sha256=maQ7jgB5leWHwxMlbBv08hpe5lytvmH0hEARu22GRdU,5481
|
| 65 |
+
tqdm/keras.py,sha256=ugd80-xCxMqnrbx_DEOpmj6c2Sh1xoVtQ8V9-bw29eo,4396
|
| 66 |
+
tqdm/notebook.py,sha256=6xkUTcYRsFxN4_BSUYYZ51kAgI7ycnT0HLpP9HukEqg,10888
|
| 67 |
+
tqdm/rich.py,sha256=J04yq6y2Ur9012zC7PkczA1t7cDjet88hmBkrAv-s2s,5255
|
| 68 |
+
tqdm/std.py,sha256=t-7qDtaeZoxAw9_K7JWxYe7Wbn1c_GRsO4HEkluaYB0,58074
|
| 69 |
+
tqdm/tk.py,sha256=3VsB1MDAkCItaWu7CmMb2CoTLMiqmDiEgNi3yiqQ5GY,6702
|
| 70 |
+
tqdm/tqdm.1,sha256=MLg9qjeHThZpPEQbWVrf5P5gOXMKHE_X606FSOBI9eU,7538
|
| 71 |
+
tqdm/utils.py,sha256=o_f0V32H_wrn0XmRno3j9pJ9xlp5xL0fHT3gtqL-k58,9746
|
| 72 |
+
tqdm/version.py,sha256=0uH4TLe8I8H71x29dlmtEZBObLT3b5IW-nytF3V0IVw,233
|
.venv/lib/python3.13/site-packages/tqdm-4.70.0.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: setuptools (83.0.0)
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: py3-none-any
|
| 5 |
+
|
.venv/lib/python3.13/site-packages/tqdm-4.70.0.dist-info/entry_points.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[console_scripts]
|
| 2 |
+
tqdm = tqdm.cli:main
|
.venv/lib/python3.13/site-packages/tqdm-4.70.0.dist-info/licenses/LICENCE
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
`tqdm` is a product of collaborative work.
|
| 2 |
+
Unless otherwise stated, all authors (see commit logs) retain copyright
|
| 3 |
+
for their respective work, and release the work under the MIT licence
|
| 4 |
+
(text below).
|
| 5 |
+
|
| 6 |
+
Exceptions or notable authors are listed below
|
| 7 |
+
in reverse chronological order:
|
| 8 |
+
|
| 9 |
+
* files: *
|
| 10 |
+
MPL-2.0 2015-2026 (c) Casper da Costa-Luis
|
| 11 |
+
[casperdcl](https://github.com/casperdcl).
|
| 12 |
+
* files: tqdm/_tqdm.py
|
| 13 |
+
MIT 2016 (c) [PR #96] on behalf of Google Inc.
|
| 14 |
+
* files: tqdm/_tqdm.py README.rst .gitignore
|
| 15 |
+
MIT 2013 (c) Noam Yorav-Raphael, original author.
|
| 16 |
+
|
| 17 |
+
[PR #96]: https://github.com/tqdm/tqdm/pull/96
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
Mozilla Public Licence (MPL) v. 2.0 - Exhibit A
|
| 21 |
+
-----------------------------------------------
|
| 22 |
+
|
| 23 |
+
This Source Code Form is subject to the terms of the
|
| 24 |
+
Mozilla Public License, v. 2.0.
|
| 25 |
+
If a copy of the MPL was not distributed with this project,
|
| 26 |
+
You can obtain one at https://mozilla.org/MPL/2.0/.
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
MIT License (MIT)
|
| 30 |
+
-----------------
|
| 31 |
+
|
| 32 |
+
Copyright (c) 2013 noamraph
|
| 33 |
+
|
| 34 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
| 35 |
+
this software and associated documentation files (the "Software"), to deal in
|
| 36 |
+
the Software without restriction, including without limitation the rights to
|
| 37 |
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
| 38 |
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
| 39 |
+
subject to the following conditions:
|
| 40 |
+
|
| 41 |
+
The above copyright notice and this permission notice shall be included in all
|
| 42 |
+
copies or substantial portions of the Software.
|
| 43 |
+
|
| 44 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 45 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
| 46 |
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
| 47 |
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
| 48 |
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
| 49 |
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
.venv/lib/python3.13/site-packages/tqdm-4.70.0.dist-info/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
tqdm
|
.venv/lib/python3.13/site-packages/tqdm/__init__.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from ._monitor import TMonitor, TqdmSynchronisationWarning
|
| 2 |
+
from ._tqdm_pandas import tqdm_pandas
|
| 3 |
+
from .cli import main # TODO: remove in v5.0.0
|
| 4 |
+
from .gui import tqdm as tqdm_gui # TODO: remove in v5.0.0
|
| 5 |
+
from .gui import trange as tgrange # TODO: remove in v5.0.0
|
| 6 |
+
from .std import (
|
| 7 |
+
TqdmDeprecationWarning, TqdmExperimentalWarning, TqdmKeyError, TqdmMonitorWarning,
|
| 8 |
+
TqdmTypeError, TqdmWarning, tqdm, trange)
|
| 9 |
+
from .version import __version__
|
| 10 |
+
|
| 11 |
+
__all__ = ['tqdm', 'tqdm_gui', 'trange', 'tgrange', 'tqdm_pandas',
|
| 12 |
+
'tqdm_notebook', 'tnrange', 'main', 'TMonitor',
|
| 13 |
+
'TqdmTypeError', 'TqdmKeyError',
|
| 14 |
+
'TqdmWarning', 'TqdmDeprecationWarning',
|
| 15 |
+
'TqdmExperimentalWarning',
|
| 16 |
+
'TqdmMonitorWarning', 'TqdmSynchronisationWarning',
|
| 17 |
+
'__version__']
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def tqdm_notebook(*args, **kwargs): # pragma: no cover
|
| 21 |
+
"""See tqdm.notebook.tqdm for full documentation"""
|
| 22 |
+
from warnings import warn
|
| 23 |
+
|
| 24 |
+
from .notebook import tqdm as _tqdm_notebook
|
| 25 |
+
warn("This function will be removed in tqdm==5.0.0\n"
|
| 26 |
+
"Please use `tqdm.notebook.tqdm` instead of `tqdm.tqdm_notebook`",
|
| 27 |
+
TqdmDeprecationWarning, stacklevel=2)
|
| 28 |
+
return _tqdm_notebook(*args, **kwargs)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def tnrange(*args, **kwargs): # pragma: no cover
|
| 32 |
+
"""Shortcut for `tqdm.notebook.tqdm(range(*args), **kwargs)`."""
|
| 33 |
+
from warnings import warn
|
| 34 |
+
|
| 35 |
+
from .notebook import trange as _tnrange
|
| 36 |
+
warn("Please use `tqdm.notebook.trange` instead of `tqdm.tnrange`",
|
| 37 |
+
TqdmDeprecationWarning, stacklevel=2)
|
| 38 |
+
return _tnrange(*args, **kwargs)
|
.venv/lib/python3.13/site-packages/tqdm/__main__.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .cli import main
|
| 2 |
+
|
| 3 |
+
main()
|
.venv/lib/python3.13/site-packages/tqdm/_main.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from warnings import warn
|
| 2 |
+
|
| 3 |
+
from .cli import * # NOQA
|
| 4 |
+
from .cli import __all__ # NOQA
|
| 5 |
+
from .std import TqdmDeprecationWarning
|
| 6 |
+
|
| 7 |
+
warn("This function will be removed in tqdm==5.0.0\n"
|
| 8 |
+
"Please use `tqdm.cli.*` instead of `tqdm._main.*`",
|
| 9 |
+
TqdmDeprecationWarning, stacklevel=2)
|
.venv/lib/python3.13/site-packages/tqdm/_monitor.py
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import atexit
|
| 2 |
+
from threading import Event, Thread, current_thread
|
| 3 |
+
from time import time
|
| 4 |
+
from warnings import warn
|
| 5 |
+
|
| 6 |
+
__all__ = ["TMonitor", "TqdmSynchronisationWarning"]
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class TqdmSynchronisationWarning(RuntimeWarning):
|
| 10 |
+
"""
|
| 11 |
+
tqdm multi-thread/-process errors which may cause incorrect nesting
|
| 12 |
+
but otherwise no adverse effects
|
| 13 |
+
"""
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class TMonitor(Thread):
|
| 17 |
+
"""
|
| 18 |
+
Monitoring thread for tqdm bars.
|
| 19 |
+
Monitors if tqdm bars are taking too much time to display
|
| 20 |
+
and readjusts miniters automatically if necessary.
|
| 21 |
+
|
| 22 |
+
Parameters
|
| 23 |
+
----------
|
| 24 |
+
tqdm_cls : class
|
| 25 |
+
tqdm class to use (can be core tqdm or a submodule).
|
| 26 |
+
sleep_interval : float
|
| 27 |
+
Time to sleep between monitoring checks.
|
| 28 |
+
"""
|
| 29 |
+
_test = {} # internal vars for unit testing
|
| 30 |
+
|
| 31 |
+
def __init__(self, tqdm_cls, sleep_interval):
|
| 32 |
+
Thread.__init__(self, name="tqdm_monitor")
|
| 33 |
+
self.daemon = True # kill thread when main killed (KeyboardInterrupt)
|
| 34 |
+
self.woken = 0 # last time woken up, to sync with monitor
|
| 35 |
+
self.tqdm_cls = tqdm_cls
|
| 36 |
+
self.sleep_interval = sleep_interval
|
| 37 |
+
self._time = self._test.get("time", time)
|
| 38 |
+
self.was_killed = self._test.get("Event", Event)()
|
| 39 |
+
atexit.register(self._atexit_signal)
|
| 40 |
+
self.start()
|
| 41 |
+
|
| 42 |
+
def _atexit_signal(self):
|
| 43 |
+
"""
|
| 44 |
+
Non-joining shutdown signal.
|
| 45 |
+
Avoids deadlocks at interpreter exit from other threads, dead forks, etc.
|
| 46 |
+
This daemon thread is auto-reaped on shutdown without needing a join.
|
| 47 |
+
"""
|
| 48 |
+
self.was_killed.set()
|
| 49 |
+
|
| 50 |
+
def exit(self):
|
| 51 |
+
self.was_killed.set()
|
| 52 |
+
if self is not current_thread():
|
| 53 |
+
self.join()
|
| 54 |
+
return self.report()
|
| 55 |
+
|
| 56 |
+
def get_instances(self):
|
| 57 |
+
# returns a copy of started `tqdm_cls` instances
|
| 58 |
+
return [i for i in self.tqdm_cls._instances.copy()
|
| 59 |
+
# Avoid race by checking that the instance started
|
| 60 |
+
if hasattr(i, 'start_t')]
|
| 61 |
+
|
| 62 |
+
def run(self):
|
| 63 |
+
cur_t = self._time()
|
| 64 |
+
while True:
|
| 65 |
+
# After processing and before sleeping, notify that we woke
|
| 66 |
+
# Need to be done just before sleeping
|
| 67 |
+
self.woken = cur_t
|
| 68 |
+
# Sleep some time...
|
| 69 |
+
self.was_killed.wait(self.sleep_interval)
|
| 70 |
+
# Quit if killed
|
| 71 |
+
if self.was_killed.is_set():
|
| 72 |
+
return
|
| 73 |
+
# Then monitor!
|
| 74 |
+
# Acquire lock (to access _instances)
|
| 75 |
+
with self.tqdm_cls.get_lock():
|
| 76 |
+
cur_t = self._time()
|
| 77 |
+
# Check tqdm instances are waiting too long to print
|
| 78 |
+
instances = self.get_instances()
|
| 79 |
+
for instance in instances:
|
| 80 |
+
# Check event in loop to reduce blocking time on exit
|
| 81 |
+
if self.was_killed.is_set():
|
| 82 |
+
return
|
| 83 |
+
# Only if mininterval > 1 (else iterations are just slow)
|
| 84 |
+
# and last refresh exceeded maxinterval
|
| 85 |
+
if (
|
| 86 |
+
instance.miniters > 1
|
| 87 |
+
and (cur_t - instance.last_print_t) >= instance.maxinterval
|
| 88 |
+
):
|
| 89 |
+
# force bypassing miniters on next iteration
|
| 90 |
+
# (dynamic_miniters adjusts mininterval automatically)
|
| 91 |
+
instance.miniters = 1
|
| 92 |
+
# Refresh now! (works only for manual tqdm)
|
| 93 |
+
instance.refresh(nolock=True)
|
| 94 |
+
# Remove accidental long-lived strong reference
|
| 95 |
+
del instance
|
| 96 |
+
if instances != self.get_instances(): # pragma: nocover
|
| 97 |
+
warn("Set changed size during iteration" +
|
| 98 |
+
" (see https://github.com/tqdm/tqdm/issues/481)",
|
| 99 |
+
TqdmSynchronisationWarning, stacklevel=2)
|
| 100 |
+
# Remove accidental long-lived strong references
|
| 101 |
+
del instances
|
| 102 |
+
|
| 103 |
+
def report(self):
|
| 104 |
+
return not self.was_killed.is_set()
|
.venv/lib/python3.13/site-packages/tqdm/_tqdm.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from warnings import warn
|
| 2 |
+
|
| 3 |
+
from .std import * # NOQA
|
| 4 |
+
from .std import __all__ # NOQA
|
| 5 |
+
from .std import TqdmDeprecationWarning
|
| 6 |
+
|
| 7 |
+
warn("This function will be removed in tqdm==5.0.0\n"
|
| 8 |
+
"Please use `tqdm.std.*` instead of `tqdm._tqdm.*`",
|
| 9 |
+
TqdmDeprecationWarning, stacklevel=2)
|
.venv/lib/python3.13/site-packages/tqdm/_tqdm_gui.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from warnings import warn
|
| 2 |
+
|
| 3 |
+
from .gui import * # NOQA
|
| 4 |
+
from .gui import __all__ # NOQA
|
| 5 |
+
from .std import TqdmDeprecationWarning
|
| 6 |
+
|
| 7 |
+
warn("This function will be removed in tqdm==5.0.0\n"
|
| 8 |
+
"Please use `tqdm.gui.*` instead of `tqdm._tqdm_gui.*`",
|
| 9 |
+
TqdmDeprecationWarning, stacklevel=2)
|
.venv/lib/python3.13/site-packages/tqdm/_tqdm_notebook.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from warnings import warn
|
| 2 |
+
|
| 3 |
+
from .notebook import * # NOQA
|
| 4 |
+
from .notebook import __all__ # NOQA
|
| 5 |
+
from .std import TqdmDeprecationWarning
|
| 6 |
+
|
| 7 |
+
warn("This function will be removed in tqdm==5.0.0\n"
|
| 8 |
+
"Please use `tqdm.notebook.*` instead of `tqdm._tqdm_notebook.*`",
|
| 9 |
+
TqdmDeprecationWarning, stacklevel=2)
|
.venv/lib/python3.13/site-packages/tqdm/_tqdm_pandas.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
|
| 3 |
+
__author__ = "github.com/casperdcl"
|
| 4 |
+
__all__ = ['tqdm_pandas']
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def tqdm_pandas(tclass, **tqdm_kwargs):
|
| 8 |
+
"""
|
| 9 |
+
Registers the given `tqdm` instance with
|
| 10 |
+
`pandas.core.groupby.DataFrameGroupBy.progress_apply`.
|
| 11 |
+
"""
|
| 12 |
+
from tqdm import TqdmDeprecationWarning
|
| 13 |
+
|
| 14 |
+
if isinstance(tclass, type) or (getattr(tclass, '__name__', '').startswith(
|
| 15 |
+
'tqdm_')): # delayed adapter case
|
| 16 |
+
TqdmDeprecationWarning(
|
| 17 |
+
"Please use `tqdm.pandas(...)` instead of `tqdm_pandas(tqdm, ...)`.",
|
| 18 |
+
fp_write=getattr(tqdm_kwargs.get('file', None), 'write', sys.stderr.write))
|
| 19 |
+
tclass.pandas(**tqdm_kwargs)
|
| 20 |
+
else:
|
| 21 |
+
TqdmDeprecationWarning(
|
| 22 |
+
"Please use `tqdm.pandas(...)` instead of `tqdm_pandas(tqdm(...))`.",
|
| 23 |
+
fp_write=getattr(tclass.fp, 'write', sys.stderr.write))
|
| 24 |
+
type(tclass).pandas(deprecated_t=tclass)
|