bro
This commit is contained in:
1 parent
de41a02749
commit
9af09cebd3
764 files changed
+54218
-78859
No files matched your search
@@ -104,6 +104,7 @@ Modifications
|
||||
* ``requests`` has been modified to import its other dependencies from
|
||||
``pip._vendor`` and to *not* load ``simplejson`` (all platforms) and
|
||||
``pyopenssl`` (Windows).
|
||||
* ``rich`` has been modified to load Unicode tables from its vendored namespace.
|
||||
* ``platformdirs`` has been modified to import its submodules from ``pip._vendor.platformdirs``.
|
||||
|
||||
Automatic Vendoring
|
||||
@@ -118,12 +119,10 @@ Tool configuration is done via ``pyproject.toml``.
|
||||
To update the vendored library versions, we have a session defined in ``nox``.
|
||||
The command to upgrade everything is::
|
||||
|
||||
nox -s vendoring -- --upgrade-all --skip urllib3 --skip setuptools
|
||||
nox -s vendoring -- --upgrade-all --skip setuptools
|
||||
|
||||
At the time of writing (April 2025) we do not upgrade ``urllib3`` because the
|
||||
next version is a major upgrade and will be handled as an independent PR. We also
|
||||
do not upgrade ``setuptools``, because we only rely on ``pkg_resources``, and
|
||||
tracking every ``setuptools`` change is unnecessary for our needs.
|
||||
We do not upgrade ``setuptools``, because we only rely on ``pkg_resources``,
|
||||
and tracking every ``setuptools`` change is unnecessary for our needs.
|
||||
|
||||
|
||||
Managing Local Patches
|
||||
|
||||
@@ -69,6 +69,7 @@ if DEBUNDLED:
|
||||
vendored("pkg_resources")
|
||||
vendored("platformdirs")
|
||||
vendored("progress")
|
||||
vendored("pygments")
|
||||
vendored("pyproject_hooks")
|
||||
vendored("requests")
|
||||
vendored("requests.exceptions")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from .core import contents, where
|
||||
|
||||
__all__ = ["contents", "where"]
|
||||
__version__ = "2026.01.04"
|
||||
__version__ = "2026.10.23"
|
||||
@@ -1,316 +1,4 @@
|
||||
|
||||
# Issuer: CN=QuoVadis Root CA 2 O=QuoVadis Limited
|
||||
# Subject: CN=QuoVadis Root CA 2 O=QuoVadis Limited
|
||||
# Label: "QuoVadis Root CA 2"
|
||||
# Serial: 1289
|
||||
# MD5 Fingerprint: 5e:39:7b:dd:f8:ba:ec:82:e9:ac:62:ba:0c:54:00:2b
|
||||
# SHA1 Fingerprint: ca:3a:fb:cf:12:40:36:4b:44:b2:16:20:88:80:48:39:19:93:7c:f7
|
||||
# SHA256 Fingerprint: 85:a0:dd:7d:d7:20:ad:b7:ff:05:f8:3d:54:2b:20:9d:c7:ff:45:28:f7:d6:77:b1:83:89:fe:a5:e5:c4:9e:86
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIFtzCCA5+gAwIBAgICBQkwDQYJKoZIhvcNAQEFBQAwRTELMAkGA1UEBhMCQk0x
|
||||
GTAXBgNVBAoTEFF1b1ZhZGlzIExpbWl0ZWQxGzAZBgNVBAMTElF1b1ZhZGlzIFJv
|
||||
b3QgQ0EgMjAeFw0wNjExMjQxODI3MDBaFw0zMTExMjQxODIzMzNaMEUxCzAJBgNV
|
||||
BAYTAkJNMRkwFwYDVQQKExBRdW9WYWRpcyBMaW1pdGVkMRswGQYDVQQDExJRdW9W
|
||||
YWRpcyBSb290IENBIDIwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQCa
|
||||
GMpLlA0ALa8DKYrwD4HIrkwZhR0In6spRIXzL4GtMh6QRr+jhiYaHv5+HBg6XJxg
|
||||
Fyo6dIMzMH1hVBHL7avg5tKifvVrbxi3Cgst/ek+7wrGsxDp3MJGF/hd/aTa/55J
|
||||
WpzmM+Yklvc/ulsrHHo1wtZn/qtmUIttKGAr79dgw8eTvI02kfN/+NsRE8Scd3bB
|
||||
rrcCaoF6qUWD4gXmuVbBlDePSHFjIuwXZQeVikvfj8ZaCuWw419eaxGrDPmF60Tp
|
||||
+ARz8un+XJiM9XOva7R+zdRcAitMOeGylZUtQofX1bOQQ7dsE/He3fbE+Ik/0XX1
|
||||
ksOR1YqI0JDs3G3eicJlcZaLDQP9nL9bFqyS2+r+eXyt66/3FsvbzSUr5R/7mp/i
|
||||
Ucw6UwxI5g69ybR2BlLmEROFcmMDBOAENisgGQLodKcftslWZvB1JdxnwQ5hYIiz
|
||||
PtGo/KPaHbDRsSNU30R2be1B2MGyIrZTHN81Hdyhdyox5C315eXbyOD/5YDXC2Og
|
||||
/zOhD7osFRXql7PSorW+8oyWHhqPHWykYTe5hnMz15eWniN9gqRMgeKh0bpnX5UH
|
||||
oycR7hYQe7xFSkyyBNKr79X9DFHOUGoIMfmR2gyPZFwDwzqLID9ujWc9Otb+fVuI
|
||||
yV77zGHcizN300QyNQliBJIWENieJ0f7OyHj+OsdWwIDAQABo4GwMIGtMA8GA1Ud
|
||||
EwEB/wQFMAMBAf8wCwYDVR0PBAQDAgEGMB0GA1UdDgQWBBQahGK8SEwzJQTU7tD2
|
||||
A8QZRtGUazBuBgNVHSMEZzBlgBQahGK8SEwzJQTU7tD2A8QZRtGUa6FJpEcwRTEL
|
||||
MAkGA1UEBhMCQk0xGTAXBgNVBAoTEFF1b1ZhZGlzIExpbWl0ZWQxGzAZBgNVBAMT
|
||||
ElF1b1ZhZGlzIFJvb3QgQ0EgMoICBQkwDQYJKoZIhvcNAQEFBQADggIBAD4KFk2f
|
||||
BluornFdLwUvZ+YTRYPENvbzwCYMDbVHZF34tHLJRqUDGCdViXh9duqWNIAXINzn
|
||||
g/iN/Ae42l9NLmeyhP3ZRPx3UIHmfLTJDQtyU/h2BwdBR5YM++CCJpNVjP4iH2Bl
|
||||
fF/nJrP3MpCYUNQ3cVX2kiF495V5+vgtJodmVjB3pjd4M1IQWK4/YY7yarHvGH5K
|
||||
WWPKjaJW1acvvFYfzznB4vsKqBUsfU16Y8Zsl0Q80m/DShcK+JDSV6IZUaUtl0Ha
|
||||
B0+pUNqQjZRG4T7wlP0QADj1O+hA4bRuVhogzG9Yje0uRY/W6ZM/57Es3zrWIozc
|
||||
hLsib9D45MY56QSIPMO661V6bYCZJPVsAfv4l7CUW+v90m/xd2gNNWQjrLhVoQPR
|
||||
TUIZ3Ph1WVaj+ahJefivDrkRoHy3au000LYmYjgahwz46P0u05B/B5EqHdZ+XIWD
|
||||
mbA4CD/pXvk1B+TJYm5Xf6dQlfe6yJvmjqIBxdZmv3lh8zwc4bmCXF2gw+nYSL0Z
|
||||
ohEUGW6yhhtoPkg3Goi3XZZenMfvJ2II4pEZXNLxId26F0KCl3GBUzGpn/Z9Yr9y
|
||||
4aOTHcyKJloJONDO1w2AFrR4pTqHTI2KpdVGl/IsELm8VCLAAVBpQ570su9t+Oza
|
||||
8eOx79+Rj1QqCyXBJhnEUhAFZdWCEOrCMc0u
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
# Issuer: CN=QuoVadis Root CA 3 O=QuoVadis Limited
|
||||
# Subject: CN=QuoVadis Root CA 3 O=QuoVadis Limited
|
||||
# Label: "QuoVadis Root CA 3"
|
||||
# Serial: 1478
|
||||
# MD5 Fingerprint: 31:85:3c:62:94:97:63:b9:aa:fd:89:4e:af:6f:e0:cf
|
||||
# SHA1 Fingerprint: 1f:49:14:f7:d8:74:95:1d:dd:ae:02:c0:be:fd:3a:2d:82:75:51:85
|
||||
# SHA256 Fingerprint: 18:f1:fc:7f:20:5d:f8:ad:dd:eb:7f:e0:07:dd:57:e3:af:37:5a:9c:4d:8d:73:54:6b:f4:f1:fe:d1:e1:8d:35
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIGnTCCBIWgAwIBAgICBcYwDQYJKoZIhvcNAQEFBQAwRTELMAkGA1UEBhMCQk0x
|
||||
GTAXBgNVBAoTEFF1b1ZhZGlzIExpbWl0ZWQxGzAZBgNVBAMTElF1b1ZhZGlzIFJv
|
||||
b3QgQ0EgMzAeFw0wNjExMjQxOTExMjNaFw0zMTExMjQxOTA2NDRaMEUxCzAJBgNV
|
||||
BAYTAkJNMRkwFwYDVQQKExBRdW9WYWRpcyBMaW1pdGVkMRswGQYDVQQDExJRdW9W
|
||||
YWRpcyBSb290IENBIDMwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQDM
|
||||
V0IWVJzmmNPTTe7+7cefQzlKZbPoFog02w1ZkXTPkrgEQK0CSzGrvI2RaNggDhoB
|
||||
4hp7Thdd4oq3P5kazethq8Jlph+3t723j/z9cI8LoGe+AaJZz3HmDyl2/7FWeUUr
|
||||
H556VOijKTVopAFPD6QuN+8bv+OPEKhyq1hX51SGyMnzW9os2l2ObjyjPtr7guXd
|
||||
8lyyBTNvijbO0BNO/79KDDRMpsMhvVAEVeuxu537RR5kFd5VAYwCdrXLoT9Cabwv
|
||||
vWhDFlaJKjdhkf2mrk7AyxRllDdLkgbvBNDInIjbC3uBr7E9KsRlOni27tyAsdLT
|
||||
mZw67mtaa7ONt9XOnMK+pUsvFrGeaDsGb659n/je7Mwpp5ijJUMv7/FfJuGITfhe
|
||||
btfZFG4ZM2mnO4SJk8RTVROhUXhA+LjJou57ulJCg54U7QVSWllWp5f8nT8KKdjc
|
||||
T5EOE7zelaTfi5m+rJsziO+1ga8bxiJTyPbH7pcUsMV8eFLI8M5ud2CEpukqdiDt
|
||||
WAEXMJPpGovgc2PZapKUSU60rUqFxKMiMPwJ7Wgic6aIDFUhWMXhOp8q3crhkODZ
|
||||
c6tsgLjoC2SToJyMGf+z0gzskSaHirOi4XCPLArlzW1oUevaPwV/izLmE1xr/l9A
|
||||
4iLItLRkT9a6fUg+qGkM17uGcclzuD87nSVL2v9A6wIDAQABo4IBlTCCAZEwDwYD
|
||||
VR0TAQH/BAUwAwEB/zCB4QYDVR0gBIHZMIHWMIHTBgkrBgEEAb5YAAMwgcUwgZMG
|
||||
CCsGAQUFBwICMIGGGoGDQW55IHVzZSBvZiB0aGlzIENlcnRpZmljYXRlIGNvbnN0
|
||||
aXR1dGVzIGFjY2VwdGFuY2Ugb2YgdGhlIFF1b1ZhZGlzIFJvb3QgQ0EgMyBDZXJ0
|
||||
aWZpY2F0ZSBQb2xpY3kgLyBDZXJ0aWZpY2F0aW9uIFByYWN0aWNlIFN0YXRlbWVu
|
||||
dC4wLQYIKwYBBQUHAgEWIWh0dHA6Ly93d3cucXVvdmFkaXNnbG9iYWwuY29tL2Nw
|
||||
czALBgNVHQ8EBAMCAQYwHQYDVR0OBBYEFPLAE+CCQz777i9nMpY1XNu4ywLQMG4G
|
||||
A1UdIwRnMGWAFPLAE+CCQz777i9nMpY1XNu4ywLQoUmkRzBFMQswCQYDVQQGEwJC
|
||||
TTEZMBcGA1UEChMQUXVvVmFkaXMgTGltaXRlZDEbMBkGA1UEAxMSUXVvVmFkaXMg
|
||||
Um9vdCBDQSAzggIFxjANBgkqhkiG9w0BAQUFAAOCAgEAT62gLEz6wPJv92ZVqyM0
|
||||
7ucp2sNbtrCD2dDQ4iH782CnO11gUyeim/YIIirnv6By5ZwkajGxkHon24QRiSem
|
||||
d1o417+shvzuXYO8BsbRd2sPbSQvS3pspweWyuOEn62Iix2rFo1bZhfZFvSLgNLd
|
||||
+LJ2w/w4E6oM3kJpK27zPOuAJ9v1pkQNn1pVWQvVDVJIxa6f8i+AxeoyUDUSly7B
|
||||
4f/xI4hROJ/yZlZ25w9Rl6VSDE1JUZU2Pb+iSwwQHYaZTKrzchGT5Or2m9qoXadN
|
||||
t54CrnMAyNojA+j56hl0YgCUyyIgvpSnWbWCar6ZeXqp8kokUvd0/bpO5qgdAm6x
|
||||
DYBEwa7TIzdfu4V8K5Iu6H6li92Z4b8nby1dqnuH/grdS/yO9SbkbnBCbjPsMZ57
|
||||
k8HkyWkaPcBrTiJt7qtYTcbQQcEr6k8Sh17rRdhs9ZgC06DYVYoGmRmioHfRMJ6s
|
||||
zHXug/WwYjnPbFfiTNKRCw51KBuav/0aQ/HKd/s7j2G4aSgWQgRecCocIdiP4b0j
|
||||
Wy10QJLZYxkNc91pvGJHvOB0K7Lrfb5BG7XARsWhIstfTsEokt4YutUqKLsRixeT
|
||||
mJlglFwjz1onl14LBQaTNx47aTbrqZ5hHY8y2o4M1nQ+ewkk2gF3R8Q7zTSMmfXK
|
||||
4SVhM7JZG+Ju1zdXtg2pEto=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
# Issuer: CN=DigiCert Assured ID Root CA O=DigiCert Inc OU=www.digicert.com
|
||||
# Subject: CN=DigiCert Assured ID Root CA O=DigiCert Inc OU=www.digicert.com
|
||||
# Label: "DigiCert Assured ID Root CA"
|
||||
# Serial: 17154717934120587862167794914071425081
|
||||
# MD5 Fingerprint: 87:ce:0b:7b:2a:0e:49:00:e1:58:71:9b:37:a8:93:72
|
||||
# SHA1 Fingerprint: 05:63:b8:63:0d:62:d7:5a:bb:c8:ab:1e:4b:df:b5:a8:99:b2:4d:43
|
||||
# SHA256 Fingerprint: 3e:90:99:b5:01:5e:8f:48:6c:00:bc:ea:9d:11:1e:e7:21:fa:ba:35:5a:89:bc:f1:df:69:56:1e:3d:c6:32:5c
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDtzCCAp+gAwIBAgIQDOfg5RfYRv6P5WD8G/AwOTANBgkqhkiG9w0BAQUFADBl
|
||||
MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
|
||||
d3cuZGlnaWNlcnQuY29tMSQwIgYDVQQDExtEaWdpQ2VydCBBc3N1cmVkIElEIFJv
|
||||
b3QgQ0EwHhcNMDYxMTEwMDAwMDAwWhcNMzExMTEwMDAwMDAwWjBlMQswCQYDVQQG
|
||||
EwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3d3cuZGlnaWNl
|
||||
cnQuY29tMSQwIgYDVQQDExtEaWdpQ2VydCBBc3N1cmVkIElEIFJvb3QgQ0EwggEi
|
||||
MA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCtDhXO5EOAXLGH87dg+XESpa7c
|
||||
JpSIqvTO9SA5KFhgDPiA2qkVlTJhPLWxKISKityfCgyDF3qPkKyK53lTXDGEKvYP
|
||||
mDI2dsze3Tyoou9q+yHyUmHfnyDXH+Kx2f4YZNISW1/5WBg1vEfNoTb5a3/UsDg+
|
||||
wRvDjDPZ2C8Y/igPs6eD1sNuRMBhNZYW/lmci3Zt1/GiSw0r/wty2p5g0I6QNcZ4
|
||||
VYcgoc/lbQrISXwxmDNsIumH0DJaoroTghHtORedmTpyoeb6pNnVFzF1roV9Iq4/
|
||||
AUaG9ih5yLHa5FcXxH4cDrC0kqZWs72yl+2qp/C3xag/lRbQ/6GW6whfGHdPAgMB
|
||||
AAGjYzBhMA4GA1UdDwEB/wQEAwIBhjAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQW
|
||||
BBRF66Kv9JLLgjEtUYunpyGd823IDzAfBgNVHSMEGDAWgBRF66Kv9JLLgjEtUYun
|
||||
pyGd823IDzANBgkqhkiG9w0BAQUFAAOCAQEAog683+Lt8ONyc3pklL/3cmbYMuRC
|
||||
dWKuh+vy1dneVrOfzM4UKLkNl2BcEkxY5NM9g0lFWJc1aRqoR+pWxnmrEthngYTf
|
||||
fwk8lOa4JiwgvT2zKIn3X/8i4peEH+ll74fg38FnSbNd67IJKusm7Xi+fT8r87cm
|
||||
NW1fiQG2SVufAQWbqz0lwcy2f8Lxb4bG+mRo64EtlOtCt/qMHt1i8b5QZ7dsvfPx
|
||||
H2sMNgcWfzd8qVttevESRmCD1ycEvkvOl77DZypoEd+A5wwzZr8TDRRu838fYxAe
|
||||
+o0bJW1sj6W3YQGx0qMmoRBxna3iw/nDmVG3KwcIzi7mULKn+gpFL6Lw8g==
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
# Issuer: CN=DigiCert Global Root CA O=DigiCert Inc OU=www.digicert.com
|
||||
# Subject: CN=DigiCert Global Root CA O=DigiCert Inc OU=www.digicert.com
|
||||
# Label: "DigiCert Global Root CA"
|
||||
# Serial: 10944719598952040374951832963794454346
|
||||
# MD5 Fingerprint: 79:e4:a9:84:0d:7d:3a:96:d7:c0:4f:e2:43:4c:89:2e
|
||||
# SHA1 Fingerprint: a8:98:5d:3a:65:e5:e5:c4:b2:d7:d6:6d:40:c6:dd:2f:b1:9c:54:36
|
||||
# SHA256 Fingerprint: 43:48:a0:e9:44:4c:78:cb:26:5e:05:8d:5e:89:44:b4:d8:4f:96:62:bd:26:db:25:7f:89:34:a4:43:c7:01:61
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDrzCCApegAwIBAgIQCDvgVpBCRrGhdWrJWZHHSjANBgkqhkiG9w0BAQUFADBh
|
||||
MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
|
||||
d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD
|
||||
QTAeFw0wNjExMTAwMDAwMDBaFw0zMTExMTAwMDAwMDBaMGExCzAJBgNVBAYTAlVT
|
||||
MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j
|
||||
b20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IENBMIIBIjANBgkqhkiG
|
||||
9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4jvhEXLeqKTTo1eqUKKPC3eQyaKl7hLOllsB
|
||||
CSDMAZOnTjC3U/dDxGkAV53ijSLdhwZAAIEJzs4bg7/fzTtxRuLWZscFs3YnFo97
|
||||
nh6Vfe63SKMI2tavegw5BmV/Sl0fvBf4q77uKNd0f3p4mVmFaG5cIzJLv07A6Fpt
|
||||
43C/dxC//AH2hdmoRBBYMql1GNXRor5H4idq9Joz+EkIYIvUX7Q6hL+hqkpMfT7P
|
||||
T19sdl6gSzeRntwi5m3OFBqOasv+zbMUZBfHWymeMr/y7vrTC0LUq7dBMtoM1O/4
|
||||
gdW7jVg/tRvoSSiicNoxBN33shbyTApOB6jtSj1etX+jkMOvJwIDAQABo2MwYTAO
|
||||
BgNVHQ8BAf8EBAMCAYYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUA95QNVbR
|
||||
TLtm8KPiGxvDl7I90VUwHwYDVR0jBBgwFoAUA95QNVbRTLtm8KPiGxvDl7I90VUw
|
||||
DQYJKoZIhvcNAQEFBQADggEBAMucN6pIExIK+t1EnE9SsPTfrgT1eXkIoyQY/Esr
|
||||
hMAtudXH/vTBH1jLuG2cenTnmCmrEbXjcKChzUyImZOMkXDiqw8cvpOp/2PV5Adg
|
||||
06O/nVsJ8dWO41P0jmP6P6fbtGbfYmbW0W5BjfIttep3Sp+dWOIrWcBAI+0tKIJF
|
||||
PnlUkiaY4IBIqDfv8NZ5YBberOgOzW6sRBc4L0na4UU+Krk2U886UAb3LujEV0ls
|
||||
YSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk
|
||||
CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
# Issuer: CN=DigiCert High Assurance EV Root CA O=DigiCert Inc OU=www.digicert.com
|
||||
# Subject: CN=DigiCert High Assurance EV Root CA O=DigiCert Inc OU=www.digicert.com
|
||||
# Label: "DigiCert High Assurance EV Root CA"
|
||||
# Serial: 3553400076410547919724730734378100087
|
||||
# MD5 Fingerprint: d4:74:de:57:5c:39:b2:d3:9c:85:83:c5:c0:65:49:8a
|
||||
# SHA1 Fingerprint: 5f:b7:ee:06:33:e2:59:db:ad:0c:4c:9a:e6:d3:8f:1a:61:c7:dc:25
|
||||
# SHA256 Fingerprint: 74:31:e5:f4:c3:c1:ce:46:90:77:4f:0b:61:e0:54:40:88:3b:a9:a0:1e:d0:0b:a6:ab:d7:80:6e:d3:b1:18:cf
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDxTCCAq2gAwIBAgIQAqxcJmoLQJuPC3nyrkYldzANBgkqhkiG9w0BAQUFADBs
|
||||
MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
|
||||
d3cuZGlnaWNlcnQuY29tMSswKQYDVQQDEyJEaWdpQ2VydCBIaWdoIEFzc3VyYW5j
|
||||
ZSBFViBSb290IENBMB4XDTA2MTExMDAwMDAwMFoXDTMxMTExMDAwMDAwMFowbDEL
|
||||
MAkGA1UEBhMCVVMxFTATBgNVBAoTDERpZ2lDZXJ0IEluYzEZMBcGA1UECxMQd3d3
|
||||
LmRpZ2ljZXJ0LmNvbTErMCkGA1UEAxMiRGlnaUNlcnQgSGlnaCBBc3N1cmFuY2Ug
|
||||
RVYgUm9vdCBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMbM5XPm
|
||||
+9S75S0tMqbf5YE/yc0lSbZxKsPVlDRnogocsF9ppkCxxLeyj9CYpKlBWTrT3JTW
|
||||
PNt0OKRKzE0lgvdKpVMSOO7zSW1xkX5jtqumX8OkhPhPYlG++MXs2ziS4wblCJEM
|
||||
xChBVfvLWokVfnHoNb9Ncgk9vjo4UFt3MRuNs8ckRZqnrG0AFFoEt7oT61EKmEFB
|
||||
Ik5lYYeBQVCmeVyJ3hlKV9Uu5l0cUyx+mM0aBhakaHPQNAQTXKFx01p8VdteZOE3
|
||||
hzBWBOURtCmAEvF5OYiiAhF8J2a3iLd48soKqDirCmTCv2ZdlYTBoSUeh10aUAsg
|
||||
EsxBu24LUTi4S8sCAwEAAaNjMGEwDgYDVR0PAQH/BAQDAgGGMA8GA1UdEwEB/wQF
|
||||
MAMBAf8wHQYDVR0OBBYEFLE+w2kD+L9HAdSYJhoIAu9jZCvDMB8GA1UdIwQYMBaA
|
||||
FLE+w2kD+L9HAdSYJhoIAu9jZCvDMA0GCSqGSIb3DQEBBQUAA4IBAQAcGgaX3Nec
|
||||
nzyIZgYIVyHbIUf4KmeqvxgydkAQV8GK83rZEWWONfqe/EW1ntlMMUu4kehDLI6z
|
||||
eM7b41N5cdblIZQB2lWHmiRk9opmzN6cN82oNLFpmyPInngiK3BD41VHMWEZ71jF
|
||||
hS9OMPagMRYjyOfiZRYzy78aG6A9+MpeizGLYAiJLQwGXFK3xPkKmNEVX58Svnw2
|
||||
Yzi9RKR/5CYrCsSXaQ3pjOLAEFe4yHYSkVXySGnYvCoCWw9E1CAx2/S6cCZdkGCe
|
||||
vEsXCS+0yx5DaMkHJ8HSXPfqIbloEpw8nL+e/IBcm2PN7EeqJSdnoDfzAIJ9VNep
|
||||
+OkuE6N36B9K
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
# Issuer: CN=SwissSign Gold CA - G2 O=SwissSign AG
|
||||
# Subject: CN=SwissSign Gold CA - G2 O=SwissSign AG
|
||||
# Label: "SwissSign Gold CA - G2"
|
||||
# Serial: 13492815561806991280
|
||||
# MD5 Fingerprint: 24:77:d9:a8:91:d1:3b:fa:88:2d:c2:ff:f8:cd:33:93
|
||||
# SHA1 Fingerprint: d8:c5:38:8a:b7:30:1b:1b:6e:d4:7a:e6:45:25:3a:6f:9f:1a:27:61
|
||||
# SHA256 Fingerprint: 62:dd:0b:e9:b9:f5:0a:16:3e:a0:f8:e7:5c:05:3b:1e:ca:57:ea:55:c8:68:8f:64:7c:68:81:f2:c8:35:7b:95
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIFujCCA6KgAwIBAgIJALtAHEP1Xk+wMA0GCSqGSIb3DQEBBQUAMEUxCzAJBgNV
|
||||
BAYTAkNIMRUwEwYDVQQKEwxTd2lzc1NpZ24gQUcxHzAdBgNVBAMTFlN3aXNzU2ln
|
||||
biBHb2xkIENBIC0gRzIwHhcNMDYxMDI1MDgzMDM1WhcNMzYxMDI1MDgzMDM1WjBF
|
||||
MQswCQYDVQQGEwJDSDEVMBMGA1UEChMMU3dpc3NTaWduIEFHMR8wHQYDVQQDExZT
|
||||
d2lzc1NpZ24gR29sZCBDQSAtIEcyMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIIC
|
||||
CgKCAgEAr+TufoskDhJuqVAtFkQ7kpJcyrhdhJJCEyq8ZVeCQD5XJM1QiyUqt2/8
|
||||
76LQwB8CJEoTlo8jE+YoWACjR8cGp4QjK7u9lit/VcyLwVcfDmJlD909Vopz2q5+
|
||||
bbqBHH5CjCA12UNNhPqE21Is8w4ndwtrvxEvcnifLtg+5hg3Wipy+dpikJKVyh+c
|
||||
6bM8K8vzARO/Ws/BtQpgvd21mWRTuKCWs2/iJneRjOBiEAKfNA+k1ZIzUd6+jbqE
|
||||
emA8atufK+ze3gE/bk3lUIbLtK/tREDFylqM2tIrfKjuvqblCqoOpd8FUrdVxyJd
|
||||
MmqXl2MT28nbeTZ7hTpKxVKJ+STnnXepgv9VHKVxaSvRAiTysybUa9oEVeXBCsdt
|
||||
MDeQKuSeFDNeFhdVxVu1yzSJkvGdJo+hB9TGsnhQ2wwMC3wLjEHXuendjIj3o02y
|
||||
MszYF9rNt85mndT9Xv+9lz4pded+p2JYryU0pUHHPbwNUMoDAw8IWh+Vc3hiv69y
|
||||
FGkOpeUDDniOJihC8AcLYiAQZzlG+qkDzAQ4embvIIO1jEpWjpEA/I5cgt6IoMPi
|
||||
aG59je883WX0XaxR7ySArqpWl2/5rX3aYT+YdzylkbYcjCbaZaIJbcHiVOO5ykxM
|
||||
gI93e2CaHt+28kgeDrpOVG2Y4OGiGqJ3UM/EY5LsRxmd6+ZrzsECAwEAAaOBrDCB
|
||||
qTAOBgNVHQ8BAf8EBAMCAQYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUWyV7
|
||||
lqRlUX64OfPAeGZe6Drn8O4wHwYDVR0jBBgwFoAUWyV7lqRlUX64OfPAeGZe6Drn
|
||||
8O4wRgYDVR0gBD8wPTA7BglghXQBWQECAQEwLjAsBggrBgEFBQcCARYgaHR0cDov
|
||||
L3JlcG9zaXRvcnkuc3dpc3NzaWduLmNvbS8wDQYJKoZIhvcNAQEFBQADggIBACe6
|
||||
45R88a7A3hfm5djV9VSwg/S7zV4Fe0+fdWavPOhWfvxyeDgD2StiGwC5+OlgzczO
|
||||
UYrHUDFu4Up+GC9pWbY9ZIEr44OE5iKHjn3g7gKZYbge9LgriBIWhMIxkziWMaa5
|
||||
O1M/wySTVltpkuzFwbs4AOPsF6m43Md8AYOfMke6UiI0HTJ6CVanfCU2qT1L2sCC
|
||||
bwq7EsiHSycR+R4tx5M/nttfJmtS2S6K8RTGRI0Vqbe/vd6mGu6uLftIdxf+u+yv
|
||||
GPUqUfA5hJeVbG4bwyvEdGB5JbAKJ9/fXtI5z0V9QkvfsywexcZdylU6oJxpmo/a
|
||||
77KwPJ+HbBIrZXAVUjEaJM9vMSNQH4xPjyPDdEFjHFWoFN0+4FFQz/EbMFYOkrCC
|
||||
hdiDyyJkvC24JdVUorgG6q2SpCSgwYa1ShNqR88uC1aVVMvOmttqtKay20EIhid3
|
||||
92qgQmwLOM7XdVAyksLfKzAiSNDVQTglXaTpXZ/GlHXQRf0wl0OPkKsKx4ZzYEpp
|
||||
Ld6leNcG2mqeSz53OiATIgHQv2ieY2BrNU0LbbqhPcCT4H8js1WtciVORvnSFu+w
|
||||
ZMEBnunKoGqYDs/YYPIvSbjkQuE4NRb0yG5P94FW6LqjviOvrv1vA+ACOzB2+htt
|
||||
Qc8Bsem4yWb02ybzOqR08kkkW8mw0FfB+j564ZfJ
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
# Issuer: CN=SecureTrust CA O=SecureTrust Corporation
|
||||
# Subject: CN=SecureTrust CA O=SecureTrust Corporation
|
||||
# Label: "SecureTrust CA"
|
||||
# Serial: 17199774589125277788362757014266862032
|
||||
# MD5 Fingerprint: dc:32:c3:a7:6d:25:57:c7:68:09:9d:ea:2d:a9:a2:d1
|
||||
# SHA1 Fingerprint: 87:82:c6:c3:04:35:3b:cf:d2:96:92:d2:59:3e:7d:44:d9:34:ff:11
|
||||
# SHA256 Fingerprint: f1:c1:b5:0a:e5:a2:0d:d8:03:0e:c9:f6:bc:24:82:3d:d3:67:b5:25:57:59:b4:e7:1b:61:fc:e9:f7:37:5d:73
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDuDCCAqCgAwIBAgIQDPCOXAgWpa1Cf/DrJxhZ0DANBgkqhkiG9w0BAQUFADBI
|
||||
MQswCQYDVQQGEwJVUzEgMB4GA1UEChMXU2VjdXJlVHJ1c3QgQ29ycG9yYXRpb24x
|
||||
FzAVBgNVBAMTDlNlY3VyZVRydXN0IENBMB4XDTA2MTEwNzE5MzExOFoXDTI5MTIz
|
||||
MTE5NDA1NVowSDELMAkGA1UEBhMCVVMxIDAeBgNVBAoTF1NlY3VyZVRydXN0IENv
|
||||
cnBvcmF0aW9uMRcwFQYDVQQDEw5TZWN1cmVUcnVzdCBDQTCCASIwDQYJKoZIhvcN
|
||||
AQEBBQADggEPADCCAQoCggEBAKukgeWVzfX2FI7CT8rU4niVWJxB4Q2ZQCQXOZEz
|
||||
Zum+4YOvYlyJ0fwkW2Gz4BERQRwdbvC4u/jep4G6pkjGnx29vo6pQT64lO0pGtSO
|
||||
0gMdA+9tDWccV9cGrcrI9f4Or2YlSASWC12juhbDCE/RRvgUXPLIXgGZbf2IzIao
|
||||
wW8xQmxSPmjL8xk037uHGFaAJsTQ3MBv396gwpEWoGQRS0S8Hvbn+mPeZqx2pHGj
|
||||
7DaUaHp3pLHnDi+BeuK1cobvomuL8A/b01k/unK8RCSc43Oz969XL0Imnal0ugBS
|
||||
8kvNU3xHCzaFDmapCJcWNFfBZveA4+1wVMeT4C4oFVmHursCAwEAAaOBnTCBmjAT
|
||||
BgkrBgEEAYI3FAIEBh4EAEMAQTALBgNVHQ8EBAMCAYYwDwYDVR0TAQH/BAUwAwEB
|
||||
/zAdBgNVHQ4EFgQUQjK2FvoE/f5dS3rD/fdMQB1aQ68wNAYDVR0fBC0wKzApoCeg
|
||||
JYYjaHR0cDovL2NybC5zZWN1cmV0cnVzdC5jb20vU1RDQS5jcmwwEAYJKwYBBAGC
|
||||
NxUBBAMCAQAwDQYJKoZIhvcNAQEFBQADggEBADDtT0rhWDpSclu1pqNlGKa7UTt3
|
||||
6Z3q059c4EVlew3KW+JwULKUBRSuSceNQQcSc5R+DCMh/bwQf2AQWnL1mA6s7Ll/
|
||||
3XpvXdMc9P+IBWlCqQVxyLesJugutIxq/3HcuLHfmbx8IVQr5Fiiu1cprp6poxkm
|
||||
D5kuCLDv/WnPmRoJjeOnnyvJNjR7JLN4TJUXpAYmHrZkUjZfYGfZnMUFdAvnZyPS
|
||||
CPyI6a6Lf+Ew9Dd+/cYy2i2eRDAwbO4H3tI0/NL/QPZL9GZGBlSm8jIKYyYwa5vR
|
||||
3ItHuuG51WLQoqD0ZwV4KWMabwTW+MZMo5qxN7SN5ShLHZ4swrhovO0C7jE=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
# Issuer: CN=Secure Global CA O=SecureTrust Corporation
|
||||
# Subject: CN=Secure Global CA O=SecureTrust Corporation
|
||||
# Label: "Secure Global CA"
|
||||
# Serial: 9751836167731051554232119481456978597
|
||||
# MD5 Fingerprint: cf:f4:27:0d:d4:ed:dc:65:16:49:6d:3d:da:bf:6e:de
|
||||
# SHA1 Fingerprint: 3a:44:73:5a:e5:81:90:1f:24:86:61:46:1e:3b:9c:c4:5f:f5:3a:1b
|
||||
# SHA256 Fingerprint: 42:00:f5:04:3a:c8:59:0e:bb:52:7d:20:9e:d1:50:30:29:fb:cb:d4:1c:a1:b5:06:ec:27:f1:5a:de:7d:ac:69
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDvDCCAqSgAwIBAgIQB1YipOjUiolN9BPI8PjqpTANBgkqhkiG9w0BAQUFADBK
|
||||
MQswCQYDVQQGEwJVUzEgMB4GA1UEChMXU2VjdXJlVHJ1c3QgQ29ycG9yYXRpb24x
|
||||
GTAXBgNVBAMTEFNlY3VyZSBHbG9iYWwgQ0EwHhcNMDYxMTA3MTk0MjI4WhcNMjkx
|
||||
MjMxMTk1MjA2WjBKMQswCQYDVQQGEwJVUzEgMB4GA1UEChMXU2VjdXJlVHJ1c3Qg
|
||||
Q29ycG9yYXRpb24xGTAXBgNVBAMTEFNlY3VyZSBHbG9iYWwgQ0EwggEiMA0GCSqG
|
||||
SIb3DQEBAQUAA4IBDwAwggEKAoIBAQCvNS7YrGxVaQZx5RNoJLNP2MwhR/jxYDiJ
|
||||
iQPpvepeRlMJ3Fz1Wuj3RSoC6zFh1ykzTM7HfAo3fg+6MpjhHZevj8fcyTiW89sa
|
||||
/FHtaMbQbqR8JNGuQsiWUGMu4P51/pinX0kuleM5M2SOHqRfkNJnPLLZ/kG5VacJ
|
||||
jnIFHovdRIWCQtBJwB1g8NEXLJXr9qXBkqPFwqcIYA1gBBCWeZ4WNOaptvolRTnI
|
||||
HmX5k/Wq8VLcmZg9pYYaDDUz+kulBAYVHDGA76oYa8J719rO+TMg1fW9ajMtgQT7
|
||||
sFzUnKPiXB3jqUJ1XnvUd+85VLrJChgbEplJL4hL/VBi0XPnj3pDAgMBAAGjgZ0w
|
||||
gZowEwYJKwYBBAGCNxQCBAYeBABDAEEwCwYDVR0PBAQDAgGGMA8GA1UdEwEB/wQF
|
||||
MAMBAf8wHQYDVR0OBBYEFK9EBMJBfkiD2045AuzshHrmzsmkMDQGA1UdHwQtMCsw
|
||||
KaAnoCWGI2h0dHA6Ly9jcmwuc2VjdXJldHJ1c3QuY29tL1NHQ0EuY3JsMBAGCSsG
|
||||
AQQBgjcVAQQDAgEAMA0GCSqGSIb3DQEBBQUAA4IBAQBjGghAfaReUw132HquHw0L
|
||||
URYD7xh8yOOvaliTFGCRsoTciE6+OYo68+aCiV0BN7OrJKQVDpI1WkpEXk5X+nXO
|
||||
H0jOZvQ8QCaSmGwb7iRGDBezUqXbpZGRzzfTb+cnCDpOGR86p1hcF895P4vkp9Mm
|
||||
I50mD1hp/Ed+stCNi5O/KU9DaXR2Z0vPB4zmAve14bRDtUstFJ/53CYNv6ZHdAbY
|
||||
iNE6KTCEztI5gGIbqMdXSbxqVVFnFUq+NQfk1XWYN3kwFNspnWzFacxHVaIw98xc
|
||||
f8LDmBxrThaA63p4ZUWiABqvDA1VZDRIuJK58bRQKfJPIx/abKwfROHdI3hRW8cW
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
# Issuer: CN=COMODO Certification Authority O=COMODO CA Limited
|
||||
# Subject: CN=COMODO Certification Authority O=COMODO CA Limited
|
||||
# Label: "COMODO Certification Authority"
|
||||
# Serial: 104350513648249232941998508985834464573
|
||||
# MD5 Fingerprint: 5c:48:dc:f7:42:72:ec:56:94:6d:1c:cc:71:35:80:75
|
||||
# SHA1 Fingerprint: 66:31:bf:9e:f7:4f:9e:b6:c9:d5:a6:0c:ba:6a:be:d1:f7:bd:ef:7b
|
||||
# SHA256 Fingerprint: 0c:2c:d6:3d:f7:80:6f:a3:99:ed:e8:09:11:6b:57:5b:f8:79:89:f0:65:18:f9:80:8c:86:05:03:17:8b:af:66
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIEHTCCAwWgAwIBAgIQToEtioJl4AsC7j41AkblPTANBgkqhkiG9w0BAQUFADCB
|
||||
gTELMAkGA1UEBhMCR0IxGzAZBgNVBAgTEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4G
|
||||
A1UEBxMHU2FsZm9yZDEaMBgGA1UEChMRQ09NT0RPIENBIExpbWl0ZWQxJzAlBgNV
|
||||
BAMTHkNPTU9ETyBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw0wNjEyMDEwMDAw
|
||||
MDBaFw0yOTEyMzEyMzU5NTlaMIGBMQswCQYDVQQGEwJHQjEbMBkGA1UECBMSR3Jl
|
||||
YXRlciBNYW5jaGVzdGVyMRAwDgYDVQQHEwdTYWxmb3JkMRowGAYDVQQKExFDT01P
|
||||
RE8gQ0EgTGltaXRlZDEnMCUGA1UEAxMeQ09NT0RPIENlcnRpZmljYXRpb24gQXV0
|
||||
aG9yaXR5MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0ECLi3LjkRv3
|
||||
UcEbVASY06m/weaKXTuH+7uIzg3jLz8GlvCiKVCZrts7oVewdFFxze1CkU1B/qnI
|
||||
2GqGd0S7WWaXUF601CxwRM/aN5VCaTwwxHGzUvAhTaHYujl8HJ6jJJ3ygxaYqhZ8
|
||||
Q5sVW7euNJH+1GImGEaaP+vB+fGQV+useg2L23IwambV4EajcNxo2f8ESIl33rXp
|
||||
+2dtQem8Ob0y2WIC8bGoPW43nOIv4tOiJovGuFVDiOEjPqXSJDlqR6sA1KGzqSX+
|
||||
DT+nHbrTUcELpNqsOO9VUCQFZUaTNE8tja3G1CEZ0o7KBWFxB3NH5YoZEr0ETc5O
|
||||
nKVIrLsm9wIDAQABo4GOMIGLMB0GA1UdDgQWBBQLWOWLxkwVN6RAqTCpIb5HNlpW
|
||||
/zAOBgNVHQ8BAf8EBAMCAQYwDwYDVR0TAQH/BAUwAwEB/zBJBgNVHR8EQjBAMD6g
|
||||
PKA6hjhodHRwOi8vY3JsLmNvbW9kb2NhLmNvbS9DT01PRE9DZXJ0aWZpY2F0aW9u
|
||||
QXV0aG9yaXR5LmNybDANBgkqhkiG9w0BAQUFAAOCAQEAPpiem/Yb6dc5t3iuHXIY
|
||||
SdOH5EOC6z/JqvWote9VfCFSZfnVDeFs9D6Mk3ORLgLETgdxb8CPOGEIqB6BCsAv
|
||||
IC9Bi5HcSEW88cbeunZrM8gALTFGTO3nnc+IlP8zwFboJIYmuNg4ON8qa90SzMc/
|
||||
RxdMosIGlgnW2/4/PEZB31jiVg88O8EckzXZOFKs7sjsLjBOlDW0JB9LeGna8gI4
|
||||
zJVSk/BwJVmcIGfE7vmLV2H0knZ9P4SNVbfo5azV8fUZVqZa+5Acr5Pr5RzUZ5dd
|
||||
BA6+C4OmF4O5MBKgxTMVBbkN+8cFduPYSo38NBejxiEovjBFMR7HeL5YYTisO+IB
|
||||
ZQ==
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
# Issuer: CN=COMODO ECC Certification Authority O=COMODO CA Limited
|
||||
# Subject: CN=COMODO ECC Certification Authority O=COMODO CA Limited
|
||||
# Label: "COMODO ECC Certification Authority"
|
||||
@@ -335,105 +23,6 @@ fQjGGoe9GKhzvSbKYAydzpmfz1wPMOG+FDHqAjAU9JM8SaczepBGR7NjfRObTrdv
|
||||
GDeAU/7dIOA1mjbRxwG55tzd8/8dLDoWV9mSOdY=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
# Issuer: CN=Certigna O=Dhimyotis
|
||||
# Subject: CN=Certigna O=Dhimyotis
|
||||
# Label: "Certigna"
|
||||
# Serial: 18364802974209362175
|
||||
# MD5 Fingerprint: ab:57:a6:5b:7d:42:82:19:b5:d8:58:26:28:5e:fd:ff
|
||||
# SHA1 Fingerprint: b1:2e:13:63:45:86:a4:6f:1a:b2:60:68:37:58:2d:c4:ac:fd:94:97
|
||||
# SHA256 Fingerprint: e3:b6:a2:db:2e:d7:ce:48:84:2f:7a:c5:32:41:c7:b7:1d:54:14:4b:fb:40:c1:1f:3f:1d:0b:42:f5:ee:a1:2d
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDqDCCApCgAwIBAgIJAP7c4wEPyUj/MA0GCSqGSIb3DQEBBQUAMDQxCzAJBgNV
|
||||
BAYTAkZSMRIwEAYDVQQKDAlEaGlteW90aXMxETAPBgNVBAMMCENlcnRpZ25hMB4X
|
||||
DTA3MDYyOTE1MTMwNVoXDTI3MDYyOTE1MTMwNVowNDELMAkGA1UEBhMCRlIxEjAQ
|
||||
BgNVBAoMCURoaW15b3RpczERMA8GA1UEAwwIQ2VydGlnbmEwggEiMA0GCSqGSIb3
|
||||
DQEBAQUAA4IBDwAwggEKAoIBAQDIaPHJ1tazNHUmgh7stL7qXOEm7RFHYeGifBZ4
|
||||
QCHkYJ5ayGPhxLGWkv8YbWkj4Sti993iNi+RB7lIzw7sebYs5zRLcAglozyHGxny
|
||||
gQcPOJAZ0xH+hrTy0V4eHpbNgGzOOzGTtvKg0KmVEn2lmsxryIRWijOp5yIVUxbw
|
||||
zBfsV1/pogqYCd7jX5xv3EjjhQsVWqa6n6xI4wmy9/Qy3l40vhx4XUJbzg4ij02Q
|
||||
130yGLMLLGq/jj8UEYkgDncUtT2UCIf3JR7VsmAA7G8qKCVuKj4YYxclPz5EIBb2
|
||||
JsglrgVKtOdjLPOMFlN+XPsRGgjBRmKfIrjxwo1p3Po6WAbfAgMBAAGjgbwwgbkw
|
||||
DwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUGu3+QTmQtCRZvgHyUtVF9lo53BEw
|
||||
ZAYDVR0jBF0wW4AUGu3+QTmQtCRZvgHyUtVF9lo53BGhOKQ2MDQxCzAJBgNVBAYT
|
||||
AkZSMRIwEAYDVQQKDAlEaGlteW90aXMxETAPBgNVBAMMCENlcnRpZ25hggkA/tzj
|
||||
AQ/JSP8wDgYDVR0PAQH/BAQDAgEGMBEGCWCGSAGG+EIBAQQEAwIABzANBgkqhkiG
|
||||
9w0BAQUFAAOCAQEAhQMeknH2Qq/ho2Ge6/PAD/Kl1NqV5ta+aDY9fm4fTIrv0Q8h
|
||||
bV6lUmPOEvjvKtpv6zf+EwLHyzs+ImvaYS5/1HI93TDhHkxAGYwP15zRgzB7mFnc
|
||||
fca5DClMoTOi62c6ZYTTluLtdkVwj7Ur3vkj1kluPBS1xp81HlDQwY9qcEQCYsuu
|
||||
HWhBp6pX6FOqB9IG9tUUBguRA3UsbHK1YZWaDYu5Def131TN3ubY1gkIl2PlwS6w
|
||||
t0QmwCbAr1UwnjvVNioZBPRcHv/PLLf/0P2HQBHVESO7SMAhqaQoLf0V+LBOK/Qw
|
||||
WyH8EZE0vkHve52Xdf+XlcCWWC/qu0bXu+TZLg==
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
# Issuer: O=Chunghwa Telecom Co., Ltd. OU=ePKI Root Certification Authority
|
||||
# Subject: O=Chunghwa Telecom Co., Ltd. OU=ePKI Root Certification Authority
|
||||
# Label: "ePKI Root Certification Authority"
|
||||
# Serial: 28956088682735189655030529057352760477
|
||||
# MD5 Fingerprint: 1b:2e:00:ca:26:06:90:3d:ad:fe:6f:15:68:d3:6b:b3
|
||||
# SHA1 Fingerprint: 67:65:0d:f1:7e:8e:7e:5b:82:40:a4:f4:56:4b:cf:e2:3d:69:c6:f0
|
||||
# SHA256 Fingerprint: c0:a6:f4:dc:63:a2:4b:fd:cf:54:ef:2a:6a:08:2a:0a:72:de:35:80:3e:2f:f5:ff:52:7a:e5:d8:72:06:df:d5
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIFsDCCA5igAwIBAgIQFci9ZUdcr7iXAF7kBtK8nTANBgkqhkiG9w0BAQUFADBe
|
||||
MQswCQYDVQQGEwJUVzEjMCEGA1UECgwaQ2h1bmdod2EgVGVsZWNvbSBDby4sIEx0
|
||||
ZC4xKjAoBgNVBAsMIWVQS0kgUm9vdCBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAe
|
||||
Fw0wNDEyMjAwMjMxMjdaFw0zNDEyMjAwMjMxMjdaMF4xCzAJBgNVBAYTAlRXMSMw
|
||||
IQYDVQQKDBpDaHVuZ2h3YSBUZWxlY29tIENvLiwgTHRkLjEqMCgGA1UECwwhZVBL
|
||||
SSBSb290IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MIICIjANBgkqhkiG9w0BAQEF
|
||||
AAOCAg8AMIICCgKCAgEA4SUP7o3biDN1Z82tH306Tm2d0y8U82N0ywEhajfqhFAH
|
||||
SyZbCUNsIZ5qyNUD9WBpj8zwIuQf5/dqIjG3LBXy4P4AakP/h2XGtRrBp0xtInAh
|
||||
ijHyl3SJCRImHJ7K2RKilTza6We/CKBk49ZCt0Xvl/T29de1ShUCWH2YWEtgvM3X
|
||||
DZoTM1PRYfl61dd4s5oz9wCGzh1NlDivqOx4UXCKXBCDUSH3ET00hl7lSM2XgYI1
|
||||
TBnsZfZrxQWh7kcT1rMhJ5QQCtkkO7q+RBNGMD+XPNjX12ruOzjjK9SXDrkb5wdJ
|
||||
fzcq+Xd4z1TtW0ado4AOkUPB1ltfFLqfpo0kR0BZv3I4sjZsN/+Z0V0OWQqraffA
|
||||
sgRFelQArr5T9rXn4fg8ozHSqf4hUmTFpmfwdQcGlBSBVcYn5AGPF8Fqcde+S/uU
|
||||
WH1+ETOxQvdibBjWzwloPn9s9h6PYq2lY9sJpx8iQkEeb5mKPtf5P0B6ebClAZLS
|
||||
nT0IFaUQAS2zMnaolQ2zepr7BxB4EW/hj8e6DyUadCrlHJhBmd8hh+iVBmoKs2pH
|
||||
dmX2Os+PYhcZewoozRrSgx4hxyy/vv9haLdnG7t4TY3OZ+XkwY63I2binZB1NJip
|
||||
NiuKmpS5nezMirH4JYlcWrYvjB9teSSnUmjDhDXiZo1jDiVN1Rmy5nk3pyKdVDEC
|
||||
AwEAAaNqMGgwHQYDVR0OBBYEFB4M97Zn8uGSJglFwFU5Lnc/QkqiMAwGA1UdEwQF
|
||||
MAMBAf8wOQYEZyoHAAQxMC8wLQIBADAJBgUrDgMCGgUAMAcGBWcqAwAABBRFsMLH
|
||||
ClZ87lt4DJX5GFPBphzYEDANBgkqhkiG9w0BAQUFAAOCAgEACbODU1kBPpVJufGB
|
||||
uvl2ICO1J2B01GqZNF5sAFPZn/KmsSQHRGoqxqWOeBLoR9lYGxMqXnmbnwoqZ6Yl
|
||||
PwZpVnPDimZI+ymBV3QGypzqKOg4ZyYr8dW1P2WT+DZdjo2NQCCHGervJ8A9tDkP
|
||||
JXtoUHRVnAxZfVo9QZQlUgjgRywVMRnVvwdVxrsStZf0X4OFunHB2WyBEXYKCrC/
|
||||
gpf36j36+uwtqSiUO1bd0lEursC9CBWMd1I0ltabrNMdjmEPNXubrjlpC2JgQCA2
|
||||
j6/7Nu4tCEoduL+bXPjqpRugc6bY+G7gMwRfaKonh+3ZwZCc7b3jajWvY9+rGNm6
|
||||
5ulK6lCKD2GTHuItGeIwlDWSXQ62B68ZgI9HkFFLLk3dheLSClIKF5r8GrBQAuUB
|
||||
o2M3IUxExJtRmREOc5wGj1QupyheRDmHVi03vYVElOEMSyycw5KFNGHLD7ibSkNS
|
||||
/jQ6fbjpKdx2qcgw+BRxgMYeNkh0IkFch4LoGHGLQYlE535YW6i4jRPpp2zDR+2z
|
||||
Gp1iro2C6pSe3VkQw63d4k3jMdXH7OjysP6SHhYKGvzZ8/gntsm+HbRsZJB/9OTE
|
||||
W9c3rkIO3aQab3yIVMUWbuF6aC74Or8NpDyJO3inTmODBCEIZ43ygknQW/2xzQ+D
|
||||
hNQ+IIX3Sj0rnP0qCglN6oH4EZw=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
# Issuer: O=certSIGN OU=certSIGN ROOT CA
|
||||
# Subject: O=certSIGN OU=certSIGN ROOT CA
|
||||
# Label: "certSIGN ROOT CA"
|
||||
# Serial: 35210227249154
|
||||
# MD5 Fingerprint: 18:98:c0:d6:e9:3a:fc:f9:b0:f5:0c:f7:4b:01:44:17
|
||||
# SHA1 Fingerprint: fa:b7:ee:36:97:26:62:fb:2d:b0:2a:f6:bf:03:fd:e8:7c:4b:2f:9b
|
||||
# SHA256 Fingerprint: ea:a9:62:c4:fa:4a:6b:af:eb:e4:15:19:6d:35:1c:cd:88:8d:4f:53:f3:fa:8a:e6:d7:c4:66:a9:4e:60:42:bb
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDODCCAiCgAwIBAgIGIAYFFnACMA0GCSqGSIb3DQEBBQUAMDsxCzAJBgNVBAYT
|
||||
AlJPMREwDwYDVQQKEwhjZXJ0U0lHTjEZMBcGA1UECxMQY2VydFNJR04gUk9PVCBD
|
||||
QTAeFw0wNjA3MDQxNzIwMDRaFw0zMTA3MDQxNzIwMDRaMDsxCzAJBgNVBAYTAlJP
|
||||
MREwDwYDVQQKEwhjZXJ0U0lHTjEZMBcGA1UECxMQY2VydFNJR04gUk9PVCBDQTCC
|
||||
ASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALczuX7IJUqOtdu0KBuqV5Do
|
||||
0SLTZLrTk+jUrIZhQGpgV2hUhE28alQCBf/fm5oqrl0Hj0rDKH/v+yv6efHHrfAQ
|
||||
UySQi2bJqIirr1qjAOm+ukbuW3N7LBeCgV5iLKECZbO9xSsAfsT8AzNXDe3i+s5d
|
||||
RdY4zTW2ssHQnIFKquSyAVwdj1+ZxLGt24gh65AIgoDzMKND5pCCrlUoSe1b16kQ
|
||||
OA7+j0xbm0bqQfWwCHTD0IgztnzXdN/chNFDDnU5oSVAKOp4yw4sLjmdjItuFhwv
|
||||
JoIQ4uNllAoEwF73XVv4EOLQunpL+943AAAaWyjj0pxzPjKHmKHJUS/X3qwzs08C
|
||||
AwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAcYwHQYDVR0O
|
||||
BBYEFOCMm9slSbPxfIbWskKHC9BroNnkMA0GCSqGSIb3DQEBBQUAA4IBAQA+0hyJ
|
||||
LjX8+HXd5n9liPRyTMks1zJO890ZeUe9jjtbkw9QSSQTaxQGcu8J06Gh40CEyecY
|
||||
MnQ8SG4Pn0vU9x7Tk4ZkVJdjclDVVc/6IJMCopvDI5NOFlV2oHB5bc0hH88vLbwZ
|
||||
44gx+FkagQnIl6Z0x2DEW8xXjrJ1/RsCCdtZb3KTafcxQdaIOL+Hsr0Wefmq5L6I
|
||||
Jd1hJyMctTEHBDa0GpC9oHRxUIltvBTjD4au8as+x6AJzKNI0eDbZOeStc+vckNw
|
||||
i/nDhDwTqn6Sm1dTk/pwwpEOMfmbZ13pljheX7NzTogVZ96edhBiIL5VaZVDADlN
|
||||
9u6wWk5JRFRYX0KD
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
# Issuer: CN=NetLock Arany (Class Gold) F\u0151tan\xfas\xedtv\xe1ny O=NetLock Kft. OU=Tan\xfas\xedtv\xe1nykiad\xf3k (Certification Services)
|
||||
# Subject: CN=NetLock Arany (Class Gold) F\u0151tan\xfas\xedtv\xe1ny O=NetLock Kft. OU=Tan\xfas\xedtv\xe1nykiad\xf3k (Certification Services)
|
||||
# Label: "NetLock Arany (Class Gold) F\u0151tan\xfas\xedtv\xe1ny"
|
||||
@@ -1097,44 +686,6 @@ aGHQRiapIVJpLesux+t3zqY6tQMzT3bR51xUAV3LePTJDL/PEo4XLSNolOer/qmy
|
||||
KwbQBM0=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
# Issuer: CN=TeliaSonera Root CA v1 O=TeliaSonera
|
||||
# Subject: CN=TeliaSonera Root CA v1 O=TeliaSonera
|
||||
# Label: "TeliaSonera Root CA v1"
|
||||
# Serial: 199041966741090107964904287217786801558
|
||||
# MD5 Fingerprint: 37:41:49:1b:18:56:9a:26:f5:ad:c2:66:fb:40:a5:4c
|
||||
# SHA1 Fingerprint: 43:13:bb:96:f1:d5:86:9b:c1:4e:6a:92:f6:cf:f6:34:69:87:82:37
|
||||
# SHA256 Fingerprint: dd:69:36:fe:21:f8:f0:77:c1:23:a1:a5:21:c1:22:24:f7:22:55:b7:3e:03:a7:26:06:93:e8:a2:4b:0f:a3:89
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIFODCCAyCgAwIBAgIRAJW+FqD3LkbxezmCcvqLzZYwDQYJKoZIhvcNAQEFBQAw
|
||||
NzEUMBIGA1UECgwLVGVsaWFTb25lcmExHzAdBgNVBAMMFlRlbGlhU29uZXJhIFJv
|
||||
b3QgQ0EgdjEwHhcNMDcxMDE4MTIwMDUwWhcNMzIxMDE4MTIwMDUwWjA3MRQwEgYD
|
||||
VQQKDAtUZWxpYVNvbmVyYTEfMB0GA1UEAwwWVGVsaWFTb25lcmEgUm9vdCBDQSB2
|
||||
MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAMK+6yfwIaPzaSZVfp3F
|
||||
VRaRXP3vIb9TgHot0pGMYzHw7CTww6XScnwQbfQ3t+XmfHnqjLWCi65ItqwA3GV1
|
||||
7CpNX8GH9SBlK4GoRz6JI5UwFpB/6FcHSOcZrr9FZ7E3GwYq/t75rH2D+1665I+X
|
||||
Z75Ljo1kB1c4VWk0Nj0TSO9P4tNmHqTPGrdeNjPUtAa9GAH9d4RQAEX1jF3oI7x+
|
||||
/jXh7VB7qTCNGdMJjmhnXb88lxhTuylixcpecsHHltTbLaC0H2kD7OriUPEMPPCs
|
||||
81Mt8Bz17Ww5OXOAFshSsCPN4D7c3TxHoLs1iuKYaIu+5b9y7tL6pe0S7fyYGKkm
|
||||
dtwoSxAgHNN/Fnct7W+A90m7UwW7XWjH1Mh1Fj+JWov3F0fUTPHSiXk+TT2YqGHe
|
||||
Oh7S+F4D4MHJHIzTjU3TlTazN19jY5szFPAtJmtTfImMMsJu7D0hADnJoWjiUIMu
|
||||
sDor8zagrC/kb2HCUQk5PotTubtn2txTuXZZNp1D5SDgPTJghSJRt8czu90VL6R4
|
||||
pgd7gUY2BIbdeTXHlSw7sKMXNeVzH7RcWe/a6hBle3rQf5+ztCo3O3CLm1u5K7fs
|
||||
slESl1MpWtTwEhDcTwK7EpIvYtQ/aUN8Ddb8WHUBiJ1YFkveupD/RwGJBmr2X7KQ
|
||||
arMCpgKIv7NHfirZ1fpoeDVNAgMBAAGjPzA9MA8GA1UdEwEB/wQFMAMBAf8wCwYD
|
||||
VR0PBAQDAgEGMB0GA1UdDgQWBBTwj1k4ALP1j5qWDNXr+nuqF+gTEjANBgkqhkiG
|
||||
9w0BAQUFAAOCAgEAvuRcYk4k9AwI//DTDGjkk0kiP0Qnb7tt3oNmzqjMDfz1mgbl
|
||||
dxSR651Be5kqhOX//CHBXfDkH1e3damhXwIm/9fH907eT/j3HEbAek9ALCI18Bmx
|
||||
0GtnLLCo4MBANzX2hFxc469CeP6nyQ1Q6g2EdvZR74NTxnr/DlZJLo961gzmJ1Tj
|
||||
TQpgcmLNkQfWpb/ImWvtxBnmq0wROMVvMeJuScg/doAmAyYp4Db29iBT4xdwNBed
|
||||
Y2gea+zDTYa4EzAvXUYNR0PVG6pZDrlcjQZIrXSHX8f8MVRBE+LHIQ6e4B4N4cB7
|
||||
Q4WQxYpYxmUKeFfyxiMPAdkgS94P+5KFdSpcc41teyWRyu5FrgZLAMzTsVlQ2jqI
|
||||
OylDRl6XK1TOU2+NSueW+r9xDkKLfP0ooNBIytrEgUy7onOTJsjrDNYmiLbAJM+7
|
||||
vVvrdX3pCI6GMyx5dwlppYn8s3CQh3aP0yK7Qs69cwsgJirQmz1wHiRszYd2qReW
|
||||
t88NkvuOGKmYSdGe/mBEciG5Ge3C9THxOUiIkCR1VBatzvT4aRRkOfujuLpwQMcn
|
||||
HL/EVlP6Y2XQ8xwOFvVrhlhNGNTkDY6lnVuR3HYkUD/GKvvZt5y11ubQ2egZixVx
|
||||
SK236thZiNSQvxaz2emsWWFUyBy6ysHK4bkgTI86k4mloMy/0/Z1pHWWbVY=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
# Issuer: CN=T-TeleSec GlobalRoot Class 2 O=T-Systems Enterprise Services GmbH OU=T-Systems Trust Center
|
||||
# Subject: CN=T-TeleSec GlobalRoot Class 2 O=T-Systems Enterprise Services GmbH OU=T-Systems Trust Center
|
||||
# Label: "T-TeleSec GlobalRoot Class 2"
|
||||
@@ -1166,35 +717,6 @@ g1XqfMIpiRvpb7PO4gWEyS8+eIVibslfwXhjdFjASBgMmTnrpMwatXlajRWc2BQN
|
||||
BSeOE6Fuwg==
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
# Issuer: CN=Atos TrustedRoot 2011 O=Atos
|
||||
# Subject: CN=Atos TrustedRoot 2011 O=Atos
|
||||
# Label: "Atos TrustedRoot 2011"
|
||||
# Serial: 6643877497813316402
|
||||
# MD5 Fingerprint: ae:b9:c4:32:4b:ac:7f:5d:66:cc:77:94:bb:2a:77:56
|
||||
# SHA1 Fingerprint: 2b:b1:f5:3e:55:0c:1d:c5:f1:d4:e6:b7:6a:46:4b:55:06:02:ac:21
|
||||
# SHA256 Fingerprint: f3:56:be:a2:44:b7:a9:1e:b3:5d:53:ca:9a:d7:86:4a:ce:01:8e:2d:35:d5:f8:f9:6d:df:68:a6:f4:1a:a4:74
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDdzCCAl+gAwIBAgIIXDPLYixfszIwDQYJKoZIhvcNAQELBQAwPDEeMBwGA1UE
|
||||
AwwVQXRvcyBUcnVzdGVkUm9vdCAyMDExMQ0wCwYDVQQKDARBdG9zMQswCQYDVQQG
|
||||
EwJERTAeFw0xMTA3MDcxNDU4MzBaFw0zMDEyMzEyMzU5NTlaMDwxHjAcBgNVBAMM
|
||||
FUF0b3MgVHJ1c3RlZFJvb3QgMjAxMTENMAsGA1UECgwEQXRvczELMAkGA1UEBhMC
|
||||
REUwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCVhTuXbyo7LjvPpvMp
|
||||
Nb7PGKw+qtn4TaA+Gke5vJrf8v7MPkfoepbCJI419KkM/IL9bcFyYie96mvr54rM
|
||||
VD6QUM+A1JX76LWC1BTFtqlVJVfbsVD2sGBkWXppzwO3bw2+yj5vdHLqqjAqc2K+
|
||||
SZFhyBH+DgMq92og3AIVDV4VavzjgsG1xZ1kCWyjWZgHJ8cblithdHFsQ/H3NYkQ
|
||||
4J7sVaE3IqKHBAUsR320HLliKWYoyrfhk/WklAOZuXCFteZI6o1Q/NnezG8HDt0L
|
||||
cp2AMBYHlT8oDv3FdU9T1nSatCQujgKRz3bFmx5VdJx4IbHwLfELn8LVlhgf8FQi
|
||||
eowHAgMBAAGjfTB7MB0GA1UdDgQWBBSnpQaxLKYJYO7Rl+lwrrw7GWzbITAPBgNV
|
||||
HRMBAf8EBTADAQH/MB8GA1UdIwQYMBaAFKelBrEspglg7tGX6XCuvDsZbNshMBgG
|
||||
A1UdIAQRMA8wDQYLKwYBBAGwLQMEAQEwDgYDVR0PAQH/BAQDAgGGMA0GCSqGSIb3
|
||||
DQEBCwUAA4IBAQAmdzTblEiGKkGdLD4GkGDEjKwLVLgfuXvTBznk+j57sj1O7Z8j
|
||||
vZfza1zv7v1Apt+hk6EKhqzvINB5Ab149xnYJDE0BAGmuhWawyfc2E8PzBhj/5kP
|
||||
DpFrdRbhIfzYJsdHt6bPWHJxfrrhTZVHO8mvbaG0weyJ9rQPOLXiZNwlz6bb65pc
|
||||
maHFCN795trV1lpFDMS3wrUU77QR/w4VtfX128a961qn8FYiqTxlVMYVqL2Gns2D
|
||||
lmh6cYGJ4Qvh6hEbaAjMaZ7snkGeRDImeuKHCnE96+RapNLbxc3G3mB/ufNPRJLv
|
||||
KrcYPqcZ2Qt9sTdBQrC6YB3y/gkRsPCHe6ed
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
# Issuer: CN=QuoVadis Root CA 1 G3 O=QuoVadis Limited
|
||||
# Subject: CN=QuoVadis Root CA 1 G3 O=QuoVadis Limited
|
||||
# Label: "QuoVadis Root CA 1 G3"
|
||||
@@ -2483,80 +2005,6 @@ RQuQ+q7hv53yrlc8pa6yVvSLZUDp/TGBLPQ5Cdjua6e0ph0VpZj3AYHYhX3zUVxx
|
||||
iN66zB+Afko=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
# Issuer: CN=emSign ECC Root CA - G3 O=eMudhra Technologies Limited OU=emSign PKI
|
||||
# Subject: CN=emSign ECC Root CA - G3 O=eMudhra Technologies Limited OU=emSign PKI
|
||||
# Label: "emSign ECC Root CA - G3"
|
||||
# Serial: 287880440101571086945156
|
||||
# MD5 Fingerprint: ce:0b:72:d1:9f:88:8e:d0:50:03:e8:e3:b8:8b:67:40
|
||||
# SHA1 Fingerprint: 30:43:fa:4f:f2:57:dc:a0:c3:80:ee:2e:58:ea:78:b2:3f:e6:bb:c1
|
||||
# SHA256 Fingerprint: 86:a1:ec:ba:08:9c:4a:8d:3b:be:27:34:c6:12:ba:34:1d:81:3e:04:3c:f9:e8:a8:62:cd:5c:57:a3:6b:be:6b
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICTjCCAdOgAwIBAgIKPPYHqWhwDtqLhDAKBggqhkjOPQQDAzBrMQswCQYDVQQG
|
||||
EwJJTjETMBEGA1UECxMKZW1TaWduIFBLSTElMCMGA1UEChMcZU11ZGhyYSBUZWNo
|
||||
bm9sb2dpZXMgTGltaXRlZDEgMB4GA1UEAxMXZW1TaWduIEVDQyBSb290IENBIC0g
|
||||
RzMwHhcNMTgwMjE4MTgzMDAwWhcNNDMwMjE4MTgzMDAwWjBrMQswCQYDVQQGEwJJ
|
||||
TjETMBEGA1UECxMKZW1TaWduIFBLSTElMCMGA1UEChMcZU11ZGhyYSBUZWNobm9s
|
||||
b2dpZXMgTGltaXRlZDEgMB4GA1UEAxMXZW1TaWduIEVDQyBSb290IENBIC0gRzMw
|
||||
djAQBgcqhkjOPQIBBgUrgQQAIgNiAAQjpQy4LRL1KPOxst3iAhKAnjlfSU2fySU0
|
||||
WXTsuwYc58Byr+iuL+FBVIcUqEqy6HyC5ltqtdyzdc6LBtCGI79G1Y4PPwT01xyS
|
||||
fvalY8L1X44uT6EYGQIrMgqCZH0Wk9GjQjBAMB0GA1UdDgQWBBR8XQKEE9TMipuB
|
||||
zhccLikenEhjQjAOBgNVHQ8BAf8EBAMCAQYwDwYDVR0TAQH/BAUwAwEB/zAKBggq
|
||||
hkjOPQQDAwNpADBmAjEAvvNhzwIQHWSVB7gYboiFBS+DCBeQyh+KTOgNG3qxrdWB
|
||||
CUfvO6wIBHxcmbHtRwfSAjEAnbpV/KlK6O3t5nYBQnvI+GDZjVGLVTv7jHvrZQnD
|
||||
+JbNR6iC8hZVdyR+EhCVBCyj
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
# Issuer: CN=emSign Root CA - C1 O=eMudhra Inc OU=emSign PKI
|
||||
# Subject: CN=emSign Root CA - C1 O=eMudhra Inc OU=emSign PKI
|
||||
# Label: "emSign Root CA - C1"
|
||||
# Serial: 825510296613316004955058
|
||||
# MD5 Fingerprint: d8:e3:5d:01:21:fa:78:5a:b0:df:ba:d2:ee:2a:5f:68
|
||||
# SHA1 Fingerprint: e7:2e:f1:df:fc:b2:09:28:cf:5d:d4:d5:67:37:b1:51:cb:86:4f:01
|
||||
# SHA256 Fingerprint: 12:56:09:aa:30:1d:a0:a2:49:b9:7a:82:39:cb:6a:34:21:6f:44:dc:ac:9f:39:54:b1:42:92:f2:e8:c8:60:8f
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDczCCAlugAwIBAgILAK7PALrEzzL4Q7IwDQYJKoZIhvcNAQELBQAwVjELMAkG
|
||||
A1UEBhMCVVMxEzARBgNVBAsTCmVtU2lnbiBQS0kxFDASBgNVBAoTC2VNdWRocmEg
|
||||
SW5jMRwwGgYDVQQDExNlbVNpZ24gUm9vdCBDQSAtIEMxMB4XDTE4MDIxODE4MzAw
|
||||
MFoXDTQzMDIxODE4MzAwMFowVjELMAkGA1UEBhMCVVMxEzARBgNVBAsTCmVtU2ln
|
||||
biBQS0kxFDASBgNVBAoTC2VNdWRocmEgSW5jMRwwGgYDVQQDExNlbVNpZ24gUm9v
|
||||
dCBDQSAtIEMxMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAz+upufGZ
|
||||
BczYKCFK83M0UYRWEPWgTywS4/oTmifQz/l5GnRfHXk5/Fv4cI7gklL35CX5VIPZ
|
||||
HdPIWoU/Xse2B+4+wM6ar6xWQio5JXDWv7V7Nq2s9nPczdcdioOl+yuQFTdrHCZH
|
||||
3DspVpNqs8FqOp099cGXOFgFixwR4+S0uF2FHYP+eF8LRWgYSKVGczQ7/g/IdrvH
|
||||
GPMF0Ybzhe3nudkyrVWIzqa2kbBPrH4VI5b2P/AgNBbeCsbEBEV5f6f9vtKppa+c
|
||||
xSMq9zwhbL2vj07FOrLzNBL834AaSaTUqZX3noleoomslMuoaJuvimUnzYnu3Yy1
|
||||
aylwQ6BpC+S5DwIDAQABo0IwQDAdBgNVHQ4EFgQU/qHgcB4qAzlSWkK+XJGFehiq
|
||||
TbUwDgYDVR0PAQH/BAQDAgEGMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQEL
|
||||
BQADggEBAMJKVvoVIXsoounlHfv4LcQ5lkFMOycsxGwYFYDGrK9HWS8mC+M2sO87
|
||||
/kOXSTKZEhVb3xEp/6tT+LvBeA+snFOvV71ojD1pM/CjoCNjO2RnIkSt1XHLVip4
|
||||
kqNPEjE2NuLe/gDEo2APJ62gsIq1NnpSob0n9CAnYuhNlCQT5AoE6TyrLshDCUrG
|
||||
YQTlSTR+08TI9Q/Aqum6VF7zYytPT1DU/rl7mYw9wC68AivTxEDkigcxHpvOJpkT
|
||||
+xHqmiIMERnHXhuBUDDIlhJu58tBf5E7oke3VIAb3ADMmpDqw8NQBmIMMMAVSKeo
|
||||
WXzhriKi4gp6D/piq1JM4fHfyr6DDUI=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
# Issuer: CN=emSign ECC Root CA - C3 O=eMudhra Inc OU=emSign PKI
|
||||
# Subject: CN=emSign ECC Root CA - C3 O=eMudhra Inc OU=emSign PKI
|
||||
# Label: "emSign ECC Root CA - C3"
|
||||
# Serial: 582948710642506000014504
|
||||
# MD5 Fingerprint: 3e:53:b3:a3:81:ee:d7:10:f8:d3:b0:1d:17:92:f5:d5
|
||||
# SHA1 Fingerprint: b6:af:43:c2:9b:81:53:7d:f6:ef:6b:c3:1f:1f:60:15:0c:ee:48:66
|
||||
# SHA256 Fingerprint: bc:4d:80:9b:15:18:9d:78:db:3e:1d:8c:f4:f9:72:6a:79:5d:a1:64:3c:a5:f1:35:8e:1d:db:0e:dc:0d:7e:b3
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICKzCCAbGgAwIBAgIKe3G2gla4EnycqDAKBggqhkjOPQQDAzBaMQswCQYDVQQG
|
||||
EwJVUzETMBEGA1UECxMKZW1TaWduIFBLSTEUMBIGA1UEChMLZU11ZGhyYSBJbmMx
|
||||
IDAeBgNVBAMTF2VtU2lnbiBFQ0MgUm9vdCBDQSAtIEMzMB4XDTE4MDIxODE4MzAw
|
||||
MFoXDTQzMDIxODE4MzAwMFowWjELMAkGA1UEBhMCVVMxEzARBgNVBAsTCmVtU2ln
|
||||
biBQS0kxFDASBgNVBAoTC2VNdWRocmEgSW5jMSAwHgYDVQQDExdlbVNpZ24gRUND
|
||||
IFJvb3QgQ0EgLSBDMzB2MBAGByqGSM49AgEGBSuBBAAiA2IABP2lYa57JhAd6bci
|
||||
MK4G9IGzsUJxlTm801Ljr6/58pc1kjZGDoeVjbk5Wum739D+yAdBPLtVb4Ojavti
|
||||
sIGJAnB9SMVK4+kiVCJNk7tCDK93nCOmfddhEc5lx/h//vXyqaNCMEAwHQYDVR0O
|
||||
BBYEFPtaSNCAIEDyqOkAB2kZd6fmw/TPMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMB
|
||||
Af8EBTADAQH/MAoGCCqGSM49BAMDA2gAMGUCMQC02C8Cif22TGK6Q04ThHK1rt0c
|
||||
3ta13FaPWEBaLd4gTCKDypOofu4SQMfWh0/434UCMBwUZOR8loMRnLDRWmFLpg9J
|
||||
0wD8ofzkpf9/rdcw0Md3f76BB1UwUCAU9Vc4CqgxUQ==
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
# Issuer: CN=Hongkong Post Root CA 3 O=Hongkong Post
|
||||
# Subject: CN=Hongkong Post Root CA 3 O=Hongkong Post
|
||||
# Label: "Hongkong Post Root CA 3"
|
||||
@@ -2725,96 +2173,6 @@ PuXaTH4MNMn5X7azKFGnpyuqSfqNZSlO42sTp5SjLVFteAxEy9/eCG/Oo2Sr05WE
|
||||
QRBdJ3NghVdJIgc=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
# Issuer: CN=Trustwave Global Certification Authority O=Trustwave Holdings, Inc.
|
||||
# Subject: CN=Trustwave Global Certification Authority O=Trustwave Holdings, Inc.
|
||||
# Label: "Trustwave Global Certification Authority"
|
||||
# Serial: 1846098327275375458322922162
|
||||
# MD5 Fingerprint: f8:1c:18:2d:2f:ba:5f:6d:a1:6c:bc:c7:ab:91:c7:0e
|
||||
# SHA1 Fingerprint: 2f:8f:36:4f:e1:58:97:44:21:59:87:a5:2a:9a:d0:69:95:26:7f:b5
|
||||
# SHA256 Fingerprint: 97:55:20:15:f5:dd:fc:3c:87:88:c0:06:94:45:55:40:88:94:45:00:84:f1:00:86:70:86:bc:1a:2b:b5:8d:c8
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIF2jCCA8KgAwIBAgIMBfcOhtpJ80Y1LrqyMA0GCSqGSIb3DQEBCwUAMIGIMQsw
|
||||
CQYDVQQGEwJVUzERMA8GA1UECAwISWxsaW5vaXMxEDAOBgNVBAcMB0NoaWNhZ28x
|
||||
ITAfBgNVBAoMGFRydXN0d2F2ZSBIb2xkaW5ncywgSW5jLjExMC8GA1UEAwwoVHJ1
|
||||
c3R3YXZlIEdsb2JhbCBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw0xNzA4MjMx
|
||||
OTM0MTJaFw00MjA4MjMxOTM0MTJaMIGIMQswCQYDVQQGEwJVUzERMA8GA1UECAwI
|
||||
SWxsaW5vaXMxEDAOBgNVBAcMB0NoaWNhZ28xITAfBgNVBAoMGFRydXN0d2F2ZSBI
|
||||
b2xkaW5ncywgSW5jLjExMC8GA1UEAwwoVHJ1c3R3YXZlIEdsb2JhbCBDZXJ0aWZp
|
||||
Y2F0aW9uIEF1dGhvcml0eTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIB
|
||||
ALldUShLPDeS0YLOvR29zd24q88KPuFd5dyqCblXAj7mY2Hf8g+CY66j96xz0Xzn
|
||||
swuvCAAJWX/NKSqIk4cXGIDtiLK0thAfLdZfVaITXdHG6wZWiYj+rDKd/VzDBcdu
|
||||
7oaJuogDnXIhhpCujwOl3J+IKMujkkkP7NAP4m1ET4BqstTnoApTAbqOl5F2brz8
|
||||
1Ws25kCI1nsvXwXoLG0R8+eyvpJETNKXpP7ScoFDB5zpET71ixpZfR9oWN0EACyW
|
||||
80OzfpgZdNmcc9kYvkHHNHnZ9GLCQ7mzJ7Aiy/k9UscwR7PJPrhq4ufogXBeQotP
|
||||
JqX+OsIgbrv4Fo7NDKm0G2x2EOFYeUY+VM6AqFcJNykbmROPDMjWLBz7BegIlT1l
|
||||
RtzuzWniTY+HKE40Cz7PFNm73bZQmq131BnW2hqIyE4bJ3XYsgjxroMwuREOzYfw
|
||||
hI0Vcnyh78zyiGG69Gm7DIwLdVcEuE4qFC49DxweMqZiNu5m4iK4BUBjECLzMx10
|
||||
coos9TkpoNPnG4CELcU9402x/RpvumUHO1jsQkUm+9jaJXLE9gCxInm943xZYkqc
|
||||
BW89zubWR2OZxiRvchLIrH+QtAuRcOi35hYQcRfO3gZPSEF9NUqjifLJS3tBEW1n
|
||||
twiYTOURGa5CgNz7kAXU+FDKvuStx8KU1xad5hePrzb7AgMBAAGjQjBAMA8GA1Ud
|
||||
EwEB/wQFMAMBAf8wHQYDVR0OBBYEFJngGWcNYtt2s9o9uFvo/ULSMQ6HMA4GA1Ud
|
||||
DwEB/wQEAwIBBjANBgkqhkiG9w0BAQsFAAOCAgEAmHNw4rDT7TnsTGDZqRKGFx6W
|
||||
0OhUKDtkLSGm+J1WE2pIPU/HPinbbViDVD2HfSMF1OQc3Og4ZYbFdada2zUFvXfe
|
||||
uyk3QAUHw5RSn8pk3fEbK9xGChACMf1KaA0HZJDmHvUqoai7PF35owgLEQzxPy0Q
|
||||
lG/+4jSHg9bP5Rs1bdID4bANqKCqRieCNqcVtgimQlRXtpla4gt5kNdXElE1GYhB
|
||||
aCXUNxeEFfsBctyV3lImIJgm4nb1J2/6ADtKYdkNy1GTKv0WBpanI5ojSP5RvbbE
|
||||
sLFUzt5sQa0WZ37b/TjNuThOssFgy50X31ieemKyJo90lZvkWx3SD92YHJtZuSPT
|
||||
MaCm/zjdzyBP6VhWOmfD0faZmZ26NraAL4hHT4a/RDqA5Dccprrql5gR0IRiR2Qe
|
||||
qu5AvzSxnI9O4fKSTx+O856X3vOmeWqJcU9LJxdI/uz0UA9PSX3MReO9ekDFQdxh
|
||||
VicGaeVyQYHTtgGJoC86cnn+OjC/QezHYj6RS8fZMXZC+fc8Y+wmjHMMfRod6qh8
|
||||
h6jCJ3zhM0EPz8/8AKAigJ5Kp28AsEFFtyLKaEjFQqKu3R3y4G5OBVixwJAWKqQ9
|
||||
EEC+j2Jjg6mcgn0tAumDMHzLJ8n9HmYAsC7TIS+OMxZsmO0QqAfWzJPP29FpHOTK
|
||||
yeC2nOnOcXHebD8WpHk=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
# Issuer: CN=Trustwave Global ECC P256 Certification Authority O=Trustwave Holdings, Inc.
|
||||
# Subject: CN=Trustwave Global ECC P256 Certification Authority O=Trustwave Holdings, Inc.
|
||||
# Label: "Trustwave Global ECC P256 Certification Authority"
|
||||
# Serial: 4151900041497450638097112925
|
||||
# MD5 Fingerprint: 5b:44:e3:8d:5d:36:86:26:e8:0d:05:d2:59:a7:83:54
|
||||
# SHA1 Fingerprint: b4:90:82:dd:45:0c:be:8b:5b:b1:66:d3:e2:a4:08:26:cd:ed:42:cf
|
||||
# SHA256 Fingerprint: 94:5b:bc:82:5e:a5:54:f4:89:d1:fd:51:a7:3d:df:2e:a6:24:ac:70:19:a0:52:05:22:5c:22:a7:8c:cf:a8:b4
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICYDCCAgegAwIBAgIMDWpfCD8oXD5Rld9dMAoGCCqGSM49BAMCMIGRMQswCQYD
|
||||
VQQGEwJVUzERMA8GA1UECBMISWxsaW5vaXMxEDAOBgNVBAcTB0NoaWNhZ28xITAf
|
||||
BgNVBAoTGFRydXN0d2F2ZSBIb2xkaW5ncywgSW5jLjE6MDgGA1UEAxMxVHJ1c3R3
|
||||
YXZlIEdsb2JhbCBFQ0MgUDI1NiBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw0x
|
||||
NzA4MjMxOTM1MTBaFw00MjA4MjMxOTM1MTBaMIGRMQswCQYDVQQGEwJVUzERMA8G
|
||||
A1UECBMISWxsaW5vaXMxEDAOBgNVBAcTB0NoaWNhZ28xITAfBgNVBAoTGFRydXN0
|
||||
d2F2ZSBIb2xkaW5ncywgSW5jLjE6MDgGA1UEAxMxVHJ1c3R3YXZlIEdsb2JhbCBF
|
||||
Q0MgUDI1NiBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTBZMBMGByqGSM49AgEGCCqG
|
||||
SM49AwEHA0IABH77bOYj43MyCMpg5lOcunSNGLB4kFKA3TjASh3RqMyTpJcGOMoN
|
||||
FWLGjgEqZZ2q3zSRLoHB5DOSMcT9CTqmP62jQzBBMA8GA1UdEwEB/wQFMAMBAf8w
|
||||
DwYDVR0PAQH/BAUDAwcGADAdBgNVHQ4EFgQUo0EGrJBt0UrrdaVKEJmzsaGLSvcw
|
||||
CgYIKoZIzj0EAwIDRwAwRAIgB+ZU2g6gWrKuEZ+Hxbb/ad4lvvigtwjzRM4q3wgh
|
||||
DDcCIC0mA6AFvWvR9lz4ZcyGbbOcNEhjhAnFjXca4syc4XR7
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
# Issuer: CN=Trustwave Global ECC P384 Certification Authority O=Trustwave Holdings, Inc.
|
||||
# Subject: CN=Trustwave Global ECC P384 Certification Authority O=Trustwave Holdings, Inc.
|
||||
# Label: "Trustwave Global ECC P384 Certification Authority"
|
||||
# Serial: 2704997926503831671788816187
|
||||
# MD5 Fingerprint: ea:cf:60:c4:3b:b9:15:29:40:a1:97:ed:78:27:93:d6
|
||||
# SHA1 Fingerprint: e7:f3:a3:c8:cf:6f:c3:04:2e:6d:0e:67:32:c5:9e:68:95:0d:5e:d2
|
||||
# SHA256 Fingerprint: 55:90:38:59:c8:c0:c3:eb:b8:75:9e:ce:4e:25:57:22:5f:f5:75:8b:bd:38:eb:d4:82:76:60:1e:1b:d5:80:97
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICnTCCAiSgAwIBAgIMCL2Fl2yZJ6SAaEc7MAoGCCqGSM49BAMDMIGRMQswCQYD
|
||||
VQQGEwJVUzERMA8GA1UECBMISWxsaW5vaXMxEDAOBgNVBAcTB0NoaWNhZ28xITAf
|
||||
BgNVBAoTGFRydXN0d2F2ZSBIb2xkaW5ncywgSW5jLjE6MDgGA1UEAxMxVHJ1c3R3
|
||||
YXZlIEdsb2JhbCBFQ0MgUDM4NCBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw0x
|
||||
NzA4MjMxOTM2NDNaFw00MjA4MjMxOTM2NDNaMIGRMQswCQYDVQQGEwJVUzERMA8G
|
||||
A1UECBMISWxsaW5vaXMxEDAOBgNVBAcTB0NoaWNhZ28xITAfBgNVBAoTGFRydXN0
|
||||
d2F2ZSBIb2xkaW5ncywgSW5jLjE6MDgGA1UEAxMxVHJ1c3R3YXZlIEdsb2JhbCBF
|
||||
Q0MgUDM4NCBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTB2MBAGByqGSM49AgEGBSuB
|
||||
BAAiA2IABGvaDXU1CDFHBa5FmVXxERMuSvgQMSOjfoPTfygIOiYaOs+Xgh+AtycJ
|
||||
j9GOMMQKmw6sWASr9zZ9lCOkmwqKi6vr/TklZvFe/oyujUF5nQlgziip04pt89ZF
|
||||
1PKYhDhloKNDMEEwDwYDVR0TAQH/BAUwAwEB/zAPBgNVHQ8BAf8EBQMDBwYAMB0G
|
||||
A1UdDgQWBBRVqYSJ0sEyvRjLbKYHTsjnnb6CkDAKBggqhkjOPQQDAwNnADBkAjA3
|
||||
AZKXRRJ+oPM+rRk6ct30UJMDEr5E0k9BpIycnR+j9sKS50gU/k6bpZFXrsY3crsC
|
||||
MGclCrEMXu6pY5Jv5ZAL/mYiykf9ijH3g/56vxC+GCsej/YpHpRZ744hN8tRmKVu
|
||||
Sw==
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
# Issuer: CN=NAVER Global Root Certification Authority O=NAVER BUSINESS PLATFORM Corp.
|
||||
# Subject: CN=NAVER Global Root Certification Authority O=NAVER BUSINESS PLATFORM Corp.
|
||||
# Label: "NAVER Global Root Certification Authority"
|
||||
@@ -3375,45 +2733,6 @@ Z6tGn6D/Qqc6f1zLXbBwHSs09dR2CQzreExZBfMzQsNhFRAbd03OIozUhfJFfbdT
|
||||
bP6MvPJwNQzcmRk13NfIRmPVNnGuV/u3gm3c
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
# Issuer: CN=GTS Root R2 O=Google Trust Services LLC
|
||||
# Subject: CN=GTS Root R2 O=Google Trust Services LLC
|
||||
# Label: "GTS Root R2"
|
||||
# Serial: 159662449406622349769042896298
|
||||
# MD5 Fingerprint: 1e:39:c0:53:e6:1e:29:82:0b:ca:52:55:36:5d:57:dc
|
||||
# SHA1 Fingerprint: 9a:44:49:76:32:db:de:fa:d0:bc:fb:5a:7b:17:bd:9e:56:09:24:94
|
||||
# SHA256 Fingerprint: 8d:25:cd:97:22:9d:bf:70:35:6b:da:4e:b3:cc:73:40:31:e2:4c:f0:0f:af:cf:d3:2d:c7:6e:b5:84:1c:7e:a8
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIFVzCCAz+gAwIBAgINAgPlrsWNBCUaqxElqjANBgkqhkiG9w0BAQwFADBHMQsw
|
||||
CQYDVQQGEwJVUzEiMCAGA1UEChMZR29vZ2xlIFRydXN0IFNlcnZpY2VzIExMQzEU
|
||||
MBIGA1UEAxMLR1RTIFJvb3QgUjIwHhcNMTYwNjIyMDAwMDAwWhcNMzYwNjIyMDAw
|
||||
MDAwWjBHMQswCQYDVQQGEwJVUzEiMCAGA1UEChMZR29vZ2xlIFRydXN0IFNlcnZp
|
||||
Y2VzIExMQzEUMBIGA1UEAxMLR1RTIFJvb3QgUjIwggIiMA0GCSqGSIb3DQEBAQUA
|
||||
A4ICDwAwggIKAoICAQDO3v2m++zsFDQ8BwZabFn3GTXd98GdVarTzTukk3LvCvpt
|
||||
nfbwhYBboUhSnznFt+4orO/LdmgUud+tAWyZH8QiHZ/+cnfgLFuv5AS/T3KgGjSY
|
||||
6Dlo7JUle3ah5mm5hRm9iYz+re026nO8/4Piy33B0s5Ks40FnotJk9/BW9BuXvAu
|
||||
MC6C/Pq8tBcKSOWIm8Wba96wyrQD8Nr0kLhlZPdcTK3ofmZemde4wj7I0BOdre7k
|
||||
RXuJVfeKH2JShBKzwkCX44ofR5GmdFrS+LFjKBC4swm4VndAoiaYecb+3yXuPuWg
|
||||
f9RhD1FLPD+M2uFwdNjCaKH5wQzpoeJ/u1U8dgbuak7MkogwTZq9TwtImoS1mKPV
|
||||
+3PBV2HdKFZ1E66HjucMUQkQdYhMvI35ezzUIkgfKtzra7tEscszcTJGr61K8Yzo
|
||||
dDqs5xoic4DSMPclQsciOzsSrZYuxsN2B6ogtzVJV+mSSeh2FnIxZyuWfoqjx5RW
|
||||
Ir9qS34BIbIjMt/kmkRtWVtd9QCgHJvGeJeNkP+byKq0rxFROV7Z+2et1VsRnTKa
|
||||
G73VululycslaVNVJ1zgyjbLiGH7HrfQy+4W+9OmTN6SpdTi3/UGVN4unUu0kzCq
|
||||
gc7dGtxRcw1PcOnlthYhGXmy5okLdWTK1au8CcEYof/UVKGFPP0UJAOyh9OktwID
|
||||
AQABo0IwQDAOBgNVHQ8BAf8EBAMCAYYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4E
|
||||
FgQUu//KjiOfT5nK2+JopqUVJxce2Q4wDQYJKoZIhvcNAQEMBQADggIBAB/Kzt3H
|
||||
vqGf2SdMC9wXmBFqiN495nFWcrKeGk6c1SuYJF2ba3uwM4IJvd8lRuqYnrYb/oM8
|
||||
0mJhwQTtzuDFycgTE1XnqGOtjHsB/ncw4c5omwX4Eu55MaBBRTUoCnGkJE+M3DyC
|
||||
B19m3H0Q/gxhswWV7uGugQ+o+MePTagjAiZrHYNSVc61LwDKgEDg4XSsYPWHgJ2u
|
||||
NmSRXbBoGOqKYcl3qJfEycel/FVL8/B/uWU9J2jQzGv6U53hkRrJXRqWbTKH7QMg
|
||||
yALOWr7Z6v2yTcQvG99fevX4i8buMTolUVVnjWQye+mew4K6Ki3pHrTgSAai/Gev
|
||||
HyICc/sgCq+dVEuhzf9gR7A/Xe8bVr2XIZYtCtFenTgCR2y59PYjJbigapordwj6
|
||||
xLEokCZYCDzifqrXPW+6MYgKBesntaFJ7qBFVHvmJ2WZICGoo7z7GJa7Um8M7YNR
|
||||
TOlZ4iBgxcJlkoKM8xAfDoqXvneCbT+PHV28SSe9zE8P4c52hgQjxcCMElv924Sg
|
||||
JPFI/2R80L5cFtHvma3AH/vLrrw4IgYmZNralw4/KBVEqE8AyvCazM90arQ+POuV
|
||||
7LXTWtiBmelDGDfrs7vRWGJB82bSj6p4lVQgw1oudCvV0b4YacCs1aTPObpRhANl
|
||||
6WLAYv7YTVWW4tAR+kg0Eeye7QUd5MjWHYbL
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
# Issuer: CN=GTS Root R3 O=Google Trust Services LLC
|
||||
# Subject: CN=GTS Root R3 O=Google Trust Services LLC
|
||||
# Label: "GTS Root R3"
|
||||
@@ -4066,30 +3385,6 @@ ntOoUAw3gi/q4Iqd4Sw5/7W0cwDk90imc6y/st53BIe0o82bNSQ3+pCTE4FCxpgm
|
||||
dTdmQRCsu/WU48IxK63nI1bMNSWSs1A=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
# Issuer: CN=FIRMAPROFESIONAL CA ROOT-A WEB O=Firmaprofesional SA
|
||||
# Subject: CN=FIRMAPROFESIONAL CA ROOT-A WEB O=Firmaprofesional SA
|
||||
# Label: "FIRMAPROFESIONAL CA ROOT-A WEB"
|
||||
# Serial: 65916896770016886708751106294915943533
|
||||
# MD5 Fingerprint: 82:b2:ad:45:00:82:b0:66:63:f8:5f:c3:67:4e:ce:a3
|
||||
# SHA1 Fingerprint: a8:31:11:74:a6:14:15:0d:ca:77:dd:0e:e4:0c:5d:58:fc:a0:72:a5
|
||||
# SHA256 Fingerprint: be:f2:56:da:f2:6e:9c:69:bd:ec:16:02:35:97:98:f3:ca:f7:18:21:a0:3e:01:82:57:c5:3c:65:61:7f:3d:4a
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICejCCAgCgAwIBAgIQMZch7a+JQn81QYehZ1ZMbTAKBggqhkjOPQQDAzBuMQsw
|
||||
CQYDVQQGEwJFUzEcMBoGA1UECgwTRmlybWFwcm9mZXNpb25hbCBTQTEYMBYGA1UE
|
||||
YQwPVkFURVMtQTYyNjM0MDY4MScwJQYDVQQDDB5GSVJNQVBST0ZFU0lPTkFMIENB
|
||||
IFJPT1QtQSBXRUIwHhcNMjIwNDA2MDkwMTM2WhcNNDcwMzMxMDkwMTM2WjBuMQsw
|
||||
CQYDVQQGEwJFUzEcMBoGA1UECgwTRmlybWFwcm9mZXNpb25hbCBTQTEYMBYGA1UE
|
||||
YQwPVkFURVMtQTYyNjM0MDY4MScwJQYDVQQDDB5GSVJNQVBST0ZFU0lPTkFMIENB
|
||||
IFJPT1QtQSBXRUIwdjAQBgcqhkjOPQIBBgUrgQQAIgNiAARHU+osEaR3xyrq89Zf
|
||||
e9MEkVz6iMYiuYMQYneEMy3pA4jU4DP37XcsSmDq5G+tbbT4TIqk5B/K6k84Si6C
|
||||
cyvHZpsKjECcfIr28jlgst7L7Ljkb+qbXbdTkBgyVcUgt5SjYzBhMA8GA1UdEwEB
|
||||
/wQFMAMBAf8wHwYDVR0jBBgwFoAUk+FDY1w8ndYn81LsF7Kpryz3dvgwHQYDVR0O
|
||||
BBYEFJPhQ2NcPJ3WJ/NS7Beyqa8s93b4MA4GA1UdDwEB/wQEAwIBBjAKBggqhkjO
|
||||
PQQDAwNoADBlAjAdfKR7w4l1M+E7qUW/Runpod3JIha3RxEL2Jq68cgLcFBTApFw
|
||||
hVmpHqTm6iMxoAACMQD94vizrxa5HnPEluPBMBnYfubDl94cT7iJLzPrSA8Z94dG
|
||||
XSaQpYXFuXqUPoeovQA=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
# Issuer: CN=TWCA CYBER Root CA O=TAIWAN-CA OU=Root CA
|
||||
# Subject: CN=TWCA CYBER Root CA O=TAIWAN-CA OU=Root CA
|
||||
# Label: "TWCA CYBER Root CA"
|
||||
@@ -4130,35 +3425,6 @@ xeSDwWrruoBa3lwtcHb4yOWHh8qgnaHlIhInD0Q9HWzq1MKLL295q39QpsQZp6F6
|
||||
t5b5wR9iWqJDB0BeJsas7a5wFsWqynKKTbDPAYsDP27X
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
# Issuer: CN=SecureSign Root CA12 O=Cybertrust Japan Co., Ltd.
|
||||
# Subject: CN=SecureSign Root CA12 O=Cybertrust Japan Co., Ltd.
|
||||
# Label: "SecureSign Root CA12"
|
||||
# Serial: 587887345431707215246142177076162061960426065942
|
||||
# MD5 Fingerprint: c6:89:ca:64:42:9b:62:08:49:0b:1e:7f:e9:07:3d:e8
|
||||
# SHA1 Fingerprint: 7a:22:1e:3d:de:1b:06:ac:9e:c8:47:70:16:8e:3c:e5:f7:6b:06:f4
|
||||
# SHA256 Fingerprint: 3f:03:4b:b5:70:4d:44:b2:d0:85:45:a0:20:57:de:93:eb:f3:90:5f:ce:72:1a:cb:c7:30:c0:6d:da:ee:90:4e
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDcjCCAlqgAwIBAgIUZvnHwa/swlG07VOX5uaCwysckBYwDQYJKoZIhvcNAQEL
|
||||
BQAwUTELMAkGA1UEBhMCSlAxIzAhBgNVBAoTGkN5YmVydHJ1c3QgSmFwYW4gQ28u
|
||||
LCBMdGQuMR0wGwYDVQQDExRTZWN1cmVTaWduIFJvb3QgQ0ExMjAeFw0yMDA0MDgw
|
||||
NTM2NDZaFw00MDA0MDgwNTM2NDZaMFExCzAJBgNVBAYTAkpQMSMwIQYDVQQKExpD
|
||||
eWJlcnRydXN0IEphcGFuIENvLiwgTHRkLjEdMBsGA1UEAxMUU2VjdXJlU2lnbiBS
|
||||
b290IENBMTIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC6OcE3emhF
|
||||
KxS06+QT61d1I02PJC0W6K6OyX2kVzsqdiUzg2zqMoqUm048luT9Ub+ZyZN+v/mt
|
||||
p7JIKwccJ/VMvHASd6SFVLX9kHrko+RRWAPNEHl57muTH2SOa2SroxPjcf59q5zd
|
||||
J1M3s6oYwlkm7Fsf0uZlfO+TvdhYXAvA42VvPMfKWeP+bl+sg779XSVOKik71gur
|
||||
FzJ4pOE+lEa+Ym6b3kaosRbnhW70CEBFEaCeVESE99g2zvVQR9wsMJvuwPWW0v4J
|
||||
hscGWa5Pro4RmHvzC1KqYiaqId+OJTN5lxZJjfU+1UefNzFJM3IFTQy2VYzxV4+K
|
||||
h9GtxRESOaCtAgMBAAGjQjBAMA8GA1UdEwEB/wQFMAMBAf8wDgYDVR0PAQH/BAQD
|
||||
AgEGMB0GA1UdDgQWBBRXNPN0zwRL1SXm8UC2LEzZLemgrTANBgkqhkiG9w0BAQsF
|
||||
AAOCAQEAPrvbFxbS8hQBICw4g0utvsqFepq2m2um4fylOqyttCg6r9cBg0krY6Ld
|
||||
mmQOmFxv3Y67ilQiLUoT865AQ9tPkbeGGuwAtEGBpE/6aouIs3YIcipJQMPTw4WJ
|
||||
mBClnW8Zt7vPemVV2zfrPIpyMpcemik+rY3moxtt9XUa5rBouVui7mlHJzWhhpmA
|
||||
8zNL4WukJsPvdFlseqJkth5Ew1DgDzk9qTPxpfPSvWKErI4cqc1avTc7bgoitPQV
|
||||
55FYxTpE05Uo2cBl6XLK0A+9H7MV2anjpEcJnuDLN/v9vZfVvhgaaaI5gdka9at/
|
||||
yOPiZwud9AzqVN/Ssq+xIvEg37xEHA==
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
# Issuer: CN=SecureSign Root CA14 O=Cybertrust Japan Co., Ltd.
|
||||
# Subject: CN=SecureSign Root CA14 O=Cybertrust Japan Co., Ltd.
|
||||
# Label: "SecureSign Root CA14"
|
||||
@@ -4429,7 +3695,7 @@ YmH5LVerVrkR3SW+ak5KGoJr3M/TvEqzPNcum9v4KGm8ay3sMaE641c=
|
||||
|
||||
# Issuer: CN=OISTE Server Root RSA G1 O=OISTE Foundation
|
||||
# Subject: CN=OISTE Server Root RSA G1 O=OISTE Foundation
|
||||
# Label: " OISTE Server Root RSA G1"
|
||||
# Label: "OISTE Server Root RSA G1"
|
||||
# Serial: 113845518112613905024960613408179309848
|
||||
# MD5 Fingerprint: 23:a7:9e:d4:70:b8:b9:14:57:41:8a:7e:44:59:e2:68
|
||||
# SHA1 Fingerprint: f7:00:34:25:94:88:68:31:e4:34:87:3f:70:fe:86:b3:86:9f:f0:6e
|
||||
@@ -4466,3 +3732,154 @@ J8tRd/iWkx7P8nd9H0aTolkelUTFLXVksNb54Dxp6gS1HAviRkRNQzuXSXERvSS2
|
||||
wq1yVAb+axj5d9spLFKebXd7Yv0PTY6YMjAwcRLWJTXjn/hvnLXrahut6hDTlhZy
|
||||
BiElxky8j3C7DOReIoMt0r7+hVu05L0=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
# Issuer: CN=e-Szigno TLS Root CA 2023 O=Microsec Ltd.
|
||||
# Subject: CN=e-Szigno TLS Root CA 2023 O=Microsec Ltd.
|
||||
# Label: "e-Szigno TLS Root CA 2023"
|
||||
# Serial: 71934828665710877219916191754
|
||||
# MD5 Fingerprint: 6a:e9:99:74:a5:da:5e:f1:d9:2e:f2:c8:d1:86:8b:71
|
||||
# SHA1 Fingerprint: 6f:9a:d5:d5:df:e8:2c:eb:be:37:07:ee:4f:4f:52:58:29:41:d1:fe
|
||||
# SHA256 Fingerprint: b4:91:41:50:2d:00:66:3d:74:0f:2e:7e:c3:40:c5:28:00:96:26:66:12:1a:36:d0:9c:f7:dd:2b:90:38:4f:b4
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICzzCCAjGgAwIBAgINAOhvGHvWOWuYSkmYCjAKBggqhkjOPQQDBDB1MQswCQYD
|
||||
VQQGEwJIVTERMA8GA1UEBwwIQnVkYXBlc3QxFjAUBgNVBAoMDU1pY3Jvc2VjIEx0
|
||||
ZC4xFzAVBgNVBGEMDlZBVEhVLTIzNTg0NDk3MSIwIAYDVQQDDBllLVN6aWdubyBU
|
||||
TFMgUm9vdCBDQSAyMDIzMB4XDTIzMDcxNzE0MDAwMFoXDTM4MDcxNzE0MDAwMFow
|
||||
dTELMAkGA1UEBhMCSFUxETAPBgNVBAcMCEJ1ZGFwZXN0MRYwFAYDVQQKDA1NaWNy
|
||||
b3NlYyBMdGQuMRcwFQYDVQRhDA5WQVRIVS0yMzU4NDQ5NzEiMCAGA1UEAwwZZS1T
|
||||
emlnbm8gVExTIFJvb3QgQ0EgMjAyMzCBmzAQBgcqhkjOPQIBBgUrgQQAIwOBhgAE
|
||||
AGgP36J8PKp0iGEKjcJMpQEiFNT3YHdCnAo4YKGMZz6zY+n6kbCLS+Y53wLCMAFS
|
||||
AL/fjO1ZrTJlqwlZULUZwmgcAOAFX9pQJhzDrAQixTpN7+lXWDajwRlTEArRzT/v
|
||||
SzUaQ49CE0y5LBqcvjC2xN7cS53kpDzLLtmt3999Cd8ukv+ho2MwYTAPBgNVHRMB
|
||||
Af8EBTADAQH/MA4GA1UdDwEB/wQEAwIBBjAdBgNVHQ4EFgQUWYQCYlpGePVd3I8K
|
||||
ECgj3NXW+0UwHwYDVR0jBBgwFoAUWYQCYlpGePVd3I8KECgj3NXW+0UwCgYIKoZI
|
||||
zj0EAwQDgYsAMIGHAkIBLdqu9S54tma4n7Zwf2Z0z+yOfP7AAXmazlIC58PRDHpt
|
||||
y7Ve7hekm9sEdu4pKeiv+62sUvTXK9Z3hBC9xdIoaDQCQTV2WnXzkoYI9bIeCvZl
|
||||
C9p2x1L/Cx6AcCIwwzPbGO2E14vs7dOoY4G1VnxHx1YwlGhza9IuqbnZLBwpvQy6
|
||||
uWWL
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
# Issuer: CN=SECOM TLS RSA Root CA 2024 O=SECOM Trust Systems Co., Ltd.
|
||||
# Subject: CN=SECOM TLS RSA Root CA 2024 O=SECOM Trust Systems Co., Ltd.
|
||||
# Label: "SECOM TLS RSA Root CA 2024"
|
||||
# Serial: 17188327524208271538
|
||||
# MD5 Fingerprint: d0:a4:db:32:eb:44:98:d2:62:0b:3e:bc:4d:7c:5c:e9
|
||||
# SHA1 Fingerprint: fb:97:96:7c:ef:8d:98:63:06:c0:3b:b6:11:f8:e0:13:97:a2:98:d3
|
||||
# SHA256 Fingerprint: 14:35:f2:25:c5:d2:52:d7:a2:19:48:cc:3c:e6:2a:ec:fa:88:00:1e:3d:d7:2d:1c:c3:55:51:00:eb:37:2f:93
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIFmjCCA4KgAwIBAgIJAO6JNNDLgOCyMA0GCSqGSIb3DQEBDAUAMFoxCzAJBgNV
|
||||
BAYTAkpQMSYwJAYDVQQKEx1TRUNPTSBUcnVzdCBTeXN0ZW1zIENvLiwgTHRkLjEj
|
||||
MCEGA1UEAxMaU0VDT00gVExTIFJTQSBSb290IENBIDIwMjQwHhcNMjQwMTMxMDUx
|
||||
MTU1WhcNNDkwMTE0MDUxMTU1WjBaMQswCQYDVQQGEwJKUDEmMCQGA1UEChMdU0VD
|
||||
T00gVHJ1c3QgU3lzdGVtcyBDby4sIEx0ZC4xIzAhBgNVBAMTGlNFQ09NIFRMUyBS
|
||||
U0EgUm9vdCBDQSAyMDI0MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA
|
||||
4TjizUwzxbInq8Tx11gaFYNk5fO+34y7TyM4neh0UgL5JIZbJNLTz2x//L/B71+5
|
||||
m6X6nGIr7d4lFJBGtjO677hXOz93zkcWaUTm3VbOAjBlt4YWxlcccBHXuZ7o3Q+4
|
||||
R+ormrBdHeJ1CTUEG8ttQbKIl3G7OZYbnH8/pP8cjPub/0kDVNuMzp7xsVRROOis
|
||||
Qt53fMoJLlYgoebbuMphOqMCtjkJ7R6efEMfLp8UAVi9ZaLRn76ET/CJkk925ndu
|
||||
uufC4BatS4mnXFmxN0vUXb0ij9B8O/D8gixQEsVSD4GK8FWRPh3bVd/6bzdkHGJj
|
||||
y21XI0yejVomZUbRrOfNuz0boPGV1pt18fFC39IHQEth3OFqb5NDO3L+A9bNqTgA
|
||||
yUgRmIn4ucgDc/Ri/Km3V51ueZjy1/yk0qwJVadAVVrCt56iNeXOyEvzJADGgDQ8
|
||||
E1Pdaqct8Cynz/47ReQM62vFYO08wcQkrjmX/tesiko1V1yyaf6EfPzUFzmaGy9x
|
||||
vkCwdbm15EdTolOjE0H2Vb5/APDOyCFEokiYGmXTLdAUl0wKZ4IyjkHGzy0jhpaX
|
||||
EXE/GJcEvI6VzEchjaBL03EJ0h9pG4OqeIOycKvAo3A+TbetyfsrgYyHzU0a7/qU
|
||||
jGat1AAq1nVljMpKqpinPTsf/d9H39FTUeJL7TpzzjUCAwEAAaNjMGEwHQYDVR0O
|
||||
BBYEFCzrchKOWHdkNRVWNQFXB6l9DTbmMB8GA1UdIwQYMBaAFCzrchKOWHdkNRVW
|
||||
NQFXB6l9DTbmMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMBAf8EBTADAQH/MA0GCSqG
|
||||
SIb3DQEBDAUAA4ICAQAVwsvluSafaez5tFPR/hRTBzRxEyMMQF3XJXCVi3yegZyK
|
||||
oec7hmE6jx2ZM8KgM1kn2yJRwFXHX8zUW9nBLEDWc4wuE8LrlZqhGZM9pJQXGmGz
|
||||
ResDJV6JgRBna+j4sA1M7yIdlvL0sAfFXFCTRaWTD4E1V99RLrFzWfTcC+e180hD
|
||||
uNMpqOEo46+lMeW/Wvh7ifOQs+kiK0O2gHxQDNxslSavnCs4V7l8HRDJ2La10o70
|
||||
Bo7VLzf1W8MBvv0VTnxB+NjT5qTAbhGFh9Gvp4BaJpmdUf0C5CEP6dbQlfgxWfzY
|
||||
r69yVT6dPQB+GFEaY03IMY+AcBCs+om1fNxrQXt9zoofMBNFbLhvpNH/JsXWdGUz
|
||||
fNbO12uswTa5wah8LB18FTQN2/zPHYmvBEoLuyUgZ09VNLJo5YA0kXItVYkLjMe2
|
||||
SixzK4scUHv81IK99I91DWx7FwMVKw2xgFp+ZLYB2dnpQQrqwlW64glHUcK2N9BD
|
||||
snjLSxeZ+UPECh9RxH4WAcKiZW+cqaKMmhP2WBfR4IcR7NOL32ml11ds87hhV1CZ
|
||||
WWFCJAcCidYZz6CZa8exzHojP9SB5RH0/v1KdHAisqhSjtJl/UIAHIQ48elOn8wr
|
||||
TdFap4Yb5aHglmMeNx+fAIhDluWVfxTO7H4dTPU+SFVRMLAh+wwKZfqb94nMeQ==
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
# Issuer: CN=SECOM TLS ECC Root CA 2024 O=SECOM Trust Systems Co., Ltd.
|
||||
# Subject: CN=SECOM TLS ECC Root CA 2024 O=SECOM Trust Systems Co., Ltd.
|
||||
# Label: "SECOM TLS ECC Root CA 2024"
|
||||
# Serial: 9329818985461676612
|
||||
# MD5 Fingerprint: 99:d3:9d:e4:d2:b1:2d:f0:2a:04:67:85:f3:df:46:d6
|
||||
# SHA1 Fingerprint: 7a:1f:22:2d:72:b2:c3:19:87:44:db:61:69:e8:a6:4b:d7:0d:44:0e
|
||||
# SHA256 Fingerprint: 6a:b2:ab:75:f5:1c:b4:f4:f0:15:62:03:fb:f6:f6:46:23:2f:51:4b:e0:59:f6:28:33:30:8b:82:b4:d7:2d:b1
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICTDCCAdGgAwIBAgIJAIF6LO+PI3pEMAoGCCqGSM49BAMDMFoxCzAJBgNVBAYT
|
||||
AkpQMSYwJAYDVQQKEx1TRUNPTSBUcnVzdCBTeXN0ZW1zIENvLiwgTHRkLjEjMCEG
|
||||
A1UEAxMaU0VDT00gVExTIEVDQyBSb290IENBIDIwMjQwHhcNMjQwMTMxMDU1MjM0
|
||||
WhcNNDkwMTE0MDU1MjM0WjBaMQswCQYDVQQGEwJKUDEmMCQGA1UEChMdU0VDT00g
|
||||
VHJ1c3QgU3lzdGVtcyBDby4sIEx0ZC4xIzAhBgNVBAMTGlNFQ09NIFRMUyBFQ0Mg
|
||||
Um9vdCBDQSAyMDI0MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE7NzFMtu9dzQXSNC1
|
||||
2fabk0+GlC5finB3R7XaZonRUd20aFiWObtuNBCLUZSfk6QXAE55BjEXsXQ/NG8y
|
||||
UqicXjsu9ksDK3JZBgCwLOVh6+nwJXTvso/dEj/GUYH5mBdoo2MwYTAdBgNVHQ4E
|
||||
FgQUO3YReyl04k4GTFaCQNAhL3qzydUwHwYDVR0jBBgwFoAUO3YReyl04k4GTFaC
|
||||
QNAhL3qzydUwDgYDVR0PAQH/BAQDAgEGMA8GA1UdEwEB/wQFMAMBAf8wCgYIKoZI
|
||||
zj0EAwMDaQAwZgIxAN3ib8fi1pMYtAPjMilB5e5/H+t5CL0xPL+cZ5oTTZuSCjpA
|
||||
n1v7F/VAr8bFxQXAowIxAKsBVO1ACFp7skwzPvdv1EUY5a897WGLT4lb+bjxFAWy
|
||||
l8wDcZJdwGZ/pAHxt1AJ1g==
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
# Issuer: CN=Telia EC TLS Root CA v3 O=Telia Company AB
|
||||
# Subject: CN=Telia EC TLS Root CA v3 O=Telia Company AB
|
||||
# Label: "Telia EC TLS Root CA v3"
|
||||
# Serial: 8028200332079443110287896228123317
|
||||
# MD5 Fingerprint: b6:fa:6a:5c:42:fb:c5:67:72:c0:e0:2f:72:fb:5a:44
|
||||
# SHA1 Fingerprint: b4:d6:07:c2:a5:95:bc:5b:f4:67:4d:c9:dc:6f:6f:0a:00:7a:a5:35
|
||||
# SHA256 Fingerprint: 09:8e:08:a9:1d:bb:f7:74:78:b9:6c:ce:b8:9b:14:13:a5:da:37:b7:c8:62:60:6a:95:5d:eb:07:17:9f:43:26
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICMjCCAbegAwIBAgIPAYvSIlRjTQSLbOVHH9K1MAoGCCqGSM49BAMDMEoxCzAJ
|
||||
BgNVBAYTAlNFMRkwFwYDVQQKDBBUZWxpYSBDb21wYW55IEFCMSAwHgYDVQQDDBdU
|
||||
ZWxpYSBFQyBUTFMgUm9vdCBDQSB2MzAeFw0yMzExMTUwODU1MjZaFw00ODA1MjMx
|
||||
MTAwMDBaMEoxCzAJBgNVBAYTAlNFMRkwFwYDVQQKDBBUZWxpYSBDb21wYW55IEFC
|
||||
MSAwHgYDVQQDDBdUZWxpYSBFQyBUTFMgUm9vdCBDQSB2MzB2MBAGByqGSM49AgEG
|
||||
BSuBBAAiA2IABMHIlhVDLbmFKUpW0iK4dpryT6emYOeS31JPwWnWPmkWRrAkTbPX
|
||||
40sQfHI9mpR7Rbktu3ngg6W+BBSXSechtMCnBmWXj/EaVlmV5cY1jD2HoTfhBQ3A
|
||||
acpCNMLJK4NpZaNjMGEwHwYDVR0jBBgwFoAU1GToQ4g6cy/QGnGCNgtehd7H3kMw
|
||||
HQYDVR0OBBYEFNRk6EOIOnMv0BpxgjYLXoXex95DMA4GA1UdDwEB/wQEAwIBBjAP
|
||||
BgNVHRMBAf8EBTADAQH/MAoGCCqGSM49BAMDA2kAMGYCMQCXAUdS/9bbJ8A1JYaG
|
||||
f/bWt/s7Ta0ot5Ulno8OjSNYRWQIlS4tVWldvTAVA7heOFgCMQCvKr8+Z2Rn+OBr
|
||||
5UHzlgBObpad1LuwNTRcdNgUJxIWadcki+UBLEi1/AURKV5md2M=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
# Issuer: CN=Telia RSA TLS Root CA v3 O=Telia Company AB
|
||||
# Subject: CN=Telia RSA TLS Root CA v3 O=Telia Company AB
|
||||
# Label: "Telia RSA TLS Root CA v3"
|
||||
# Serial: 8028214673410753541795188766939845
|
||||
# MD5 Fingerprint: f4:8b:9c:f3:f8:63:cf:dc:25:8f:b4:bb:a2:e9:9d:e2
|
||||
# SHA1 Fingerprint: b5:2e:88:4e:40:c1:11:fb:50:c7:e2:4f:ac:18:2b:bd:68:15:d2:34
|
||||
# SHA256 Fingerprint: d1:3d:b1:29:4c:45:eb:c6:fc:86:c6:bb:f6:9f:a2:9b:df:e6:92:df:f7:c7:13:c2:43:c7:a9:56:c6:a2:28:4c
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIFgjCCA2qgAwIBAgIPAYvSUKtCVSxHWr2h3BrFMA0GCSqGSIb3DQEBDAUAMEsx
|
||||
CzAJBgNVBAYTAlNFMRkwFwYDVQQKDBBUZWxpYSBDb21wYW55IEFCMSEwHwYDVQQD
|
||||
DBhUZWxpYSBSU0EgVExTIFJvb3QgQ0EgdjMwHhcNMjMxMTE1MDk0NzQyWhcNNDgw
|
||||
NTIzMTEwMDAwWjBLMQswCQYDVQQGEwJTRTEZMBcGA1UECgwQVGVsaWEgQ29tcGFu
|
||||
eSBBQjEhMB8GA1UEAwwYVGVsaWEgUlNBIFRMUyBSb290IENBIHYzMIICIjANBgkq
|
||||
hkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAsV89KG19hCf4S1Fvk8D3TyDERhmcvx8F
|
||||
7Kmb4WATx3ije1id3KHxRE0TKmcNCbAQ57bvHFEYa4hR2l20VjVadExqOW+2ld99
|
||||
MbEiO+jRVOz+BbxLxJnmGwCqI+BfuTjjVReDxsxjQvjgBsClaO/sm5i70nlZcWGR
|
||||
tIkvWDK3NNkT5RtwXc/O8NTFVpbUqT6cRjIj3olAblR+lRf4Ffy5o+Q9fabjYn9Z
|
||||
9S4itruElcEFf9Ljk7fwdTycT/rvJW9w/B3G2a3r0f/zXNOVruIBcqE6pkSospAC
|
||||
U2bG42fYKrbM/GWnp7u+p9Frz4jaNwpb4YHuEeS8BratNcP8X62jXIvvKHxlsMDJ
|
||||
Cnb4U8JzFOLsU6mohVY58BdZrvi0Gk9UOuqmgoG6dskHoksjZTlK61D/InzmEoA1
|
||||
yAYJFDVysjRxDUOu9cAwANbqmq77WIFL6BpnZgVqPtMfG6wN8BrTKdapvilVsYR5
|
||||
9BFgIsAVBMxrGh+W+QcvmJafUpASvlArKvVG2FI4i6PiLjSBT0+6F6EQLrYqefOQ
|
||||
F/fBNEXb+njUQ0SUVrAqtH4Y+OjCI/a4/JJQppxeemZcQ0SUShgiI5AM5xHO5iya
|
||||
UrTjYH4zxUz9j+1FEbDH/xpstr1gXBykspup+hRTaJcbA+UbpJqtWZndAPddJmt6
|
||||
YJQ+dU3pDu8CAwEAAaNjMGEwHwYDVR0jBBgwFoAUsMep0t2yKFZzBJSMFFxIbzdS
|
||||
kqgwHQYDVR0OBBYEFLDHqdLdsihWcwSUjBRcSG83UpKoMA4GA1UdDwEB/wQEAwIB
|
||||
BjAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBDAUAA4ICAQBdYzFsNGDRk7bR
|
||||
/AgRKq+5637YuOW+w6uhpoS0VnKMUpyHCwku86hEvqivakPtfmlm4bFwt++sb/8O
|
||||
XsWBqtfbXMaBNDTZl8XRMJuLWOW2JrbKkRzgG0eBUcvsadG1rrhbmZqYvFXaAZO7
|
||||
o4TdOZzxhBB5GOAWWXB3IeraNP4J63zyo9n8Gqw3sJBG44em5hoYjBffP+npibys
|
||||
lnslRi4L6xHsCYj/Pab+OlqbMCB6v+sTCLeEIukRVzoR9aQ45pEK7Z1QBnSsbAKQ
|
||||
tss0JKD9d/mX143H1xePjPhTXlv5JCkhrcj+SShz0P9+EHoWe6m9lyUEOIVn0rp+
|
||||
yVJWNbmyDv3VkwFxHC1ApSQsgSimjGQ4wtr6cSmordYxkV+Ro8lOIIhRksXPyDk2
|
||||
7gW6IjUXCkZKpxFjkL3jiBSc8SkxnwCWtXg8xwNwdFVNBGLCCuJnsneYXjJNqzRq
|
||||
UcoGwzsvF3Qi/ZnHUNvISdevlgIAXL4Wvrxaqvoa01wB+GCfs57RTGE4TvAGhKNK
|
||||
us8K3hRT1BSpigzMIRzSxtAOrqPN6j//QSmW9f8Jcncri4j2ihSpVrFU0NdNkMhZ
|
||||
eAKidTFPsxCVFuW4Aniz7jqiw5sWtjbQrlW035izIEU4sYwQoC1Nx0Svy+mMTRai
|
||||
50LqFQ+A1/Hq6xHHDNx7CI83d23Erw==
|
||||
-----END CERTIFICATE-----
|
||||
@@ -1,9 +0,0 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024-present Stephen Rosen <sirosen0@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
@@ -1,13 +0,0 @@
|
||||
from ._implementation import (
|
||||
CyclicDependencyError,
|
||||
DependencyGroupInclude,
|
||||
DependencyGroupResolver,
|
||||
resolve,
|
||||
)
|
||||
|
||||
__all__ = (
|
||||
"CyclicDependencyError",
|
||||
"DependencyGroupInclude",
|
||||
"DependencyGroupResolver",
|
||||
"resolve",
|
||||
)
|
||||
@@ -1,65 +0,0 @@
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
from ._implementation import resolve
|
||||
from ._toml_compat import tomllib
|
||||
|
||||
|
||||
def main() -> None:
|
||||
if tomllib is None:
|
||||
print(
|
||||
"Usage error: dependency-groups CLI requires tomli or Python 3.11+",
|
||||
file=sys.stderr,
|
||||
)
|
||||
raise SystemExit(2)
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description=(
|
||||
"A dependency-groups CLI. Prints out a resolved group, newline-delimited."
|
||||
)
|
||||
)
|
||||
parser.add_argument(
|
||||
"GROUP_NAME", nargs="*", help="The dependency group(s) to resolve."
|
||||
)
|
||||
parser.add_argument(
|
||||
"-f",
|
||||
"--pyproject-file",
|
||||
default="pyproject.toml",
|
||||
help="The pyproject.toml file. Defaults to trying in the current directory.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-o",
|
||||
"--output",
|
||||
help="An output file. Defaults to stdout.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-l",
|
||||
"--list",
|
||||
action="store_true",
|
||||
help="List the available dependency groups",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
with open(args.pyproject_file, "rb") as fp:
|
||||
pyproject = tomllib.load(fp)
|
||||
|
||||
dependency_groups_raw = pyproject.get("dependency-groups", {})
|
||||
|
||||
if args.list:
|
||||
print(*dependency_groups_raw.keys())
|
||||
return
|
||||
if not args.GROUP_NAME:
|
||||
print("A GROUP_NAME is required", file=sys.stderr)
|
||||
raise SystemExit(3)
|
||||
|
||||
content = "\n".join(resolve(dependency_groups_raw, *args.GROUP_NAME))
|
||||
|
||||
if args.output is None or args.output == "-":
|
||||
print(content)
|
||||
else:
|
||||
with open(args.output, "w", encoding="utf-8") as fp:
|
||||
print(content, file=fp)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,209 +0,0 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import dataclasses
|
||||
import re
|
||||
from collections.abc import Mapping
|
||||
|
||||
from pip._vendor.packaging.requirements import Requirement
|
||||
|
||||
|
||||
def _normalize_name(name: str) -> str:
|
||||
return re.sub(r"[-_.]+", "-", name).lower()
|
||||
|
||||
|
||||
def _normalize_group_names(
|
||||
dependency_groups: Mapping[str, str | Mapping[str, str]],
|
||||
) -> Mapping[str, str | Mapping[str, str]]:
|
||||
original_names: dict[str, list[str]] = {}
|
||||
normalized_groups = {}
|
||||
|
||||
for group_name, value in dependency_groups.items():
|
||||
normed_group_name = _normalize_name(group_name)
|
||||
original_names.setdefault(normed_group_name, []).append(group_name)
|
||||
normalized_groups[normed_group_name] = value
|
||||
|
||||
errors = []
|
||||
for normed_name, names in original_names.items():
|
||||
if len(names) > 1:
|
||||
errors.append(f"{normed_name} ({', '.join(names)})")
|
||||
if errors:
|
||||
raise ValueError(f"Duplicate dependency group names: {', '.join(errors)}")
|
||||
|
||||
return normalized_groups
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class DependencyGroupInclude:
|
||||
include_group: str
|
||||
|
||||
|
||||
class CyclicDependencyError(ValueError):
|
||||
"""
|
||||
An error representing the detection of a cycle.
|
||||
"""
|
||||
|
||||
def __init__(self, requested_group: str, group: str, include_group: str) -> None:
|
||||
self.requested_group = requested_group
|
||||
self.group = group
|
||||
self.include_group = include_group
|
||||
|
||||
if include_group == group:
|
||||
reason = f"{group} includes itself"
|
||||
else:
|
||||
reason = f"{include_group} -> {group}, {group} -> {include_group}"
|
||||
super().__init__(
|
||||
"Cyclic dependency group include while resolving "
|
||||
f"{requested_group}: {reason}"
|
||||
)
|
||||
|
||||
|
||||
class DependencyGroupResolver:
|
||||
"""
|
||||
A resolver for Dependency Group data.
|
||||
|
||||
This class handles caching, name normalization, cycle detection, and other
|
||||
parsing requirements. There are only two public methods for exploring the data:
|
||||
``lookup()`` and ``resolve()``.
|
||||
|
||||
:param dependency_groups: A mapping, as provided via pyproject
|
||||
``[dependency-groups]``.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
dependency_groups: Mapping[str, str | Mapping[str, str]],
|
||||
) -> None:
|
||||
if not isinstance(dependency_groups, Mapping):
|
||||
raise TypeError("Dependency Groups table is not a mapping")
|
||||
self.dependency_groups = _normalize_group_names(dependency_groups)
|
||||
# a map of group names to parsed data
|
||||
self._parsed_groups: dict[
|
||||
str, tuple[Requirement | DependencyGroupInclude, ...]
|
||||
] = {}
|
||||
# a map of group names to their ancestors, used for cycle detection
|
||||
self._include_graph_ancestors: dict[str, tuple[str, ...]] = {}
|
||||
# a cache of completed resolutions to Requirement lists
|
||||
self._resolve_cache: dict[str, tuple[Requirement, ...]] = {}
|
||||
|
||||
def lookup(self, group: str) -> tuple[Requirement | DependencyGroupInclude, ...]:
|
||||
"""
|
||||
Lookup a group name, returning the parsed dependency data for that group.
|
||||
This will not resolve includes.
|
||||
|
||||
:param group: the name of the group to lookup
|
||||
|
||||
:raises ValueError: if the data does not appear to be valid dependency group
|
||||
data
|
||||
:raises TypeError: if the data is not a string
|
||||
:raises LookupError: if group name is absent
|
||||
:raises packaging.requirements.InvalidRequirement: if a specifier is not valid
|
||||
"""
|
||||
if not isinstance(group, str):
|
||||
raise TypeError("Dependency group name is not a str")
|
||||
group = _normalize_name(group)
|
||||
return self._parse_group(group)
|
||||
|
||||
def resolve(self, group: str) -> tuple[Requirement, ...]:
|
||||
"""
|
||||
Resolve a dependency group to a list of requirements.
|
||||
|
||||
:param group: the name of the group to resolve
|
||||
|
||||
:raises TypeError: if the inputs appear to be the wrong types
|
||||
:raises ValueError: if the data does not appear to be valid dependency group
|
||||
data
|
||||
:raises LookupError: if group name is absent
|
||||
:raises packaging.requirements.InvalidRequirement: if a specifier is not valid
|
||||
"""
|
||||
if not isinstance(group, str):
|
||||
raise TypeError("Dependency group name is not a str")
|
||||
group = _normalize_name(group)
|
||||
return self._resolve(group, group)
|
||||
|
||||
def _parse_group(
|
||||
self, group: str
|
||||
) -> tuple[Requirement | DependencyGroupInclude, ...]:
|
||||
# short circuit -- never do the work twice
|
||||
if group in self._parsed_groups:
|
||||
return self._parsed_groups[group]
|
||||
|
||||
if group not in self.dependency_groups:
|
||||
raise LookupError(f"Dependency group '{group}' not found")
|
||||
|
||||
raw_group = self.dependency_groups[group]
|
||||
if not isinstance(raw_group, list):
|
||||
raise TypeError(f"Dependency group '{group}' is not a list")
|
||||
|
||||
elements: list[Requirement | DependencyGroupInclude] = []
|
||||
for item in raw_group:
|
||||
if isinstance(item, str):
|
||||
# packaging.requirements.Requirement parsing ensures that this is a
|
||||
# valid PEP 508 Dependency Specifier
|
||||
# raises InvalidRequirement on failure
|
||||
elements.append(Requirement(item))
|
||||
elif isinstance(item, dict):
|
||||
if tuple(item.keys()) != ("include-group",):
|
||||
raise ValueError(f"Invalid dependency group item: {item}")
|
||||
|
||||
include_group = next(iter(item.values()))
|
||||
elements.append(DependencyGroupInclude(include_group=include_group))
|
||||
else:
|
||||
raise ValueError(f"Invalid dependency group item: {item}")
|
||||
|
||||
self._parsed_groups[group] = tuple(elements)
|
||||
return self._parsed_groups[group]
|
||||
|
||||
def _resolve(self, group: str, requested_group: str) -> tuple[Requirement, ...]:
|
||||
"""
|
||||
This is a helper for cached resolution to strings.
|
||||
|
||||
:param group: The name of the group to resolve.
|
||||
:param requested_group: The group which was used in the original, user-facing
|
||||
request.
|
||||
"""
|
||||
if group in self._resolve_cache:
|
||||
return self._resolve_cache[group]
|
||||
|
||||
parsed = self._parse_group(group)
|
||||
|
||||
resolved_group = []
|
||||
for item in parsed:
|
||||
if isinstance(item, Requirement):
|
||||
resolved_group.append(item)
|
||||
elif isinstance(item, DependencyGroupInclude):
|
||||
include_group = _normalize_name(item.include_group)
|
||||
if include_group in self._include_graph_ancestors.get(group, ()):
|
||||
raise CyclicDependencyError(
|
||||
requested_group, group, item.include_group
|
||||
)
|
||||
self._include_graph_ancestors[include_group] = (
|
||||
*self._include_graph_ancestors.get(group, ()),
|
||||
group,
|
||||
)
|
||||
resolved_group.extend(self._resolve(include_group, requested_group))
|
||||
else: # unreachable
|
||||
raise NotImplementedError(
|
||||
f"Invalid dependency group item after parse: {item}"
|
||||
)
|
||||
|
||||
self._resolve_cache[group] = tuple(resolved_group)
|
||||
return self._resolve_cache[group]
|
||||
|
||||
|
||||
def resolve(
|
||||
dependency_groups: Mapping[str, str | Mapping[str, str]], /, *groups: str
|
||||
) -> tuple[str, ...]:
|
||||
"""
|
||||
Resolve a dependency group to a tuple of requirements, as strings.
|
||||
|
||||
:param dependency_groups: the parsed contents of the ``[dependency-groups]`` table
|
||||
from ``pyproject.toml``
|
||||
:param groups: the name of the group(s) to resolve
|
||||
|
||||
:raises TypeError: if the inputs appear to be the wrong types
|
||||
:raises ValueError: if the data does not appear to be valid dependency group data
|
||||
:raises LookupError: if group name is absent
|
||||
:raises packaging.requirements.InvalidRequirement: if a specifier is not valid
|
||||
"""
|
||||
resolver = DependencyGroupResolver(dependency_groups)
|
||||
return tuple(str(r) for group in groups for r in resolver.resolve(group))
|
||||
-59
@@ -1,59 +0,0 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
from ._implementation import DependencyGroupResolver
|
||||
from ._toml_compat import tomllib
|
||||
|
||||
|
||||
def main(*, argv: list[str] | None = None) -> None:
|
||||
if tomllib is None:
|
||||
print(
|
||||
"Usage error: dependency-groups CLI requires tomli or Python 3.11+",
|
||||
file=sys.stderr,
|
||||
)
|
||||
raise SystemExit(2)
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description=(
|
||||
"Lint Dependency Groups for validity. "
|
||||
"This will eagerly load and check all of your Dependency Groups."
|
||||
)
|
||||
)
|
||||
parser.add_argument(
|
||||
"-f",
|
||||
"--pyproject-file",
|
||||
default="pyproject.toml",
|
||||
help="The pyproject.toml file. Defaults to trying in the current directory.",
|
||||
)
|
||||
args = parser.parse_args(argv if argv is not None else sys.argv[1:])
|
||||
|
||||
with open(args.pyproject_file, "rb") as fp:
|
||||
pyproject = tomllib.load(fp)
|
||||
dependency_groups_raw = pyproject.get("dependency-groups", {})
|
||||
|
||||
errors: list[str] = []
|
||||
try:
|
||||
resolver = DependencyGroupResolver(dependency_groups_raw)
|
||||
except (ValueError, TypeError) as e:
|
||||
errors.append(f"{type(e).__name__}: {e}")
|
||||
else:
|
||||
for groupname in resolver.dependency_groups:
|
||||
try:
|
||||
resolver.resolve(groupname)
|
||||
except (LookupError, ValueError, TypeError) as e:
|
||||
errors.append(f"{type(e).__name__}: {e}")
|
||||
|
||||
if errors:
|
||||
print("errors encountered while examining dependency groups:")
|
||||
for msg in errors:
|
||||
print(f" {msg}")
|
||||
sys.exit(1)
|
||||
else:
|
||||
print("ok")
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,62 +0,0 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
from ._implementation import DependencyGroupResolver
|
||||
from ._toml_compat import tomllib
|
||||
|
||||
|
||||
def _invoke_pip(deps: list[str]) -> None:
|
||||
subprocess.check_call([sys.executable, "-m", "pip", "install", *deps])
|
||||
|
||||
|
||||
def main(*, argv: list[str] | None = None) -> None:
|
||||
if tomllib is None:
|
||||
print(
|
||||
"Usage error: dependency-groups CLI requires tomli or Python 3.11+",
|
||||
file=sys.stderr,
|
||||
)
|
||||
raise SystemExit(2)
|
||||
|
||||
parser = argparse.ArgumentParser(description="Install Dependency Groups.")
|
||||
parser.add_argument(
|
||||
"DEPENDENCY_GROUP", nargs="+", help="The dependency groups to install."
|
||||
)
|
||||
parser.add_argument(
|
||||
"-f",
|
||||
"--pyproject-file",
|
||||
default="pyproject.toml",
|
||||
help="The pyproject.toml file. Defaults to trying in the current directory.",
|
||||
)
|
||||
args = parser.parse_args(argv if argv is not None else sys.argv[1:])
|
||||
|
||||
with open(args.pyproject_file, "rb") as fp:
|
||||
pyproject = tomllib.load(fp)
|
||||
dependency_groups_raw = pyproject.get("dependency-groups", {})
|
||||
|
||||
errors: list[str] = []
|
||||
resolved: list[str] = []
|
||||
try:
|
||||
resolver = DependencyGroupResolver(dependency_groups_raw)
|
||||
except (ValueError, TypeError) as e:
|
||||
errors.append(f"{type(e).__name__}: {e}")
|
||||
else:
|
||||
for groupname in args.DEPENDENCY_GROUP:
|
||||
try:
|
||||
resolved.extend(str(r) for r in resolver.resolve(groupname))
|
||||
except (LookupError, ValueError, TypeError) as e:
|
||||
errors.append(f"{type(e).__name__}: {e}")
|
||||
|
||||
if errors:
|
||||
print("errors encountered while examining dependency groups:")
|
||||
for msg in errors:
|
||||
print(f" {msg}")
|
||||
sys.exit(1)
|
||||
|
||||
_invoke_pip(resolved)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,9 +0,0 @@
|
||||
try:
|
||||
import tomllib
|
||||
except ImportError:
|
||||
try:
|
||||
from pip._vendor import tomli as tomllib # type: ignore[no-redef, unused-ignore]
|
||||
except ModuleNotFoundError: # pragma: no cover
|
||||
tomllib = None # type: ignore[assignment, unused-ignore]
|
||||
|
||||
__all__ = ("tomllib",)
|
||||
Whitespace-only changes.
@@ -1,12 +1,12 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2012-2024 Vinay Sajip.
|
||||
# Copyright (C) 2012-2026 Vinay Sajip.
|
||||
# Licensed to the Python Software Foundation under a contributor agreement.
|
||||
# See LICENSE.txt and CONTRIBUTORS.txt.
|
||||
#
|
||||
import logging
|
||||
|
||||
__version__ = '0.4.0'
|
||||
__version__ = '0.4.4'
|
||||
|
||||
|
||||
class DistlibException(Exception):
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013-2017 Vinay Sajip.
|
||||
# Copyright (C) 2013-2026 Vinay Sajip.
|
||||
# Licensed to the Python Software Foundation under a contributor agreement.
|
||||
# See LICENSE.txt and CONTRIBUTORS.txt.
|
||||
#
|
||||
@@ -24,8 +24,8 @@ if sys.version_info[0] < 3: # pragma: no cover
|
||||
import __builtin__ as builtins
|
||||
import ConfigParser as configparser
|
||||
from urlparse import urlparse, urlunparse, urljoin, urlsplit, urlunsplit
|
||||
from urllib import (urlretrieve, quote as _quote, unquote, url2pathname,
|
||||
pathname2url, ContentTooShortError, splittype)
|
||||
from urllib import (urlretrieve, quote as _quote, unquote, url2pathname, pathname2url, ContentTooShortError,
|
||||
splittype)
|
||||
|
||||
def quote(s):
|
||||
if isinstance(s, unicode):
|
||||
@@ -33,8 +33,7 @@ if sys.version_info[0] < 3: # pragma: no cover
|
||||
return _quote(s)
|
||||
|
||||
import urllib2
|
||||
from urllib2 import (Request, urlopen, URLError, HTTPError,
|
||||
HTTPBasicAuthHandler, HTTPPasswordMgr, HTTPHandler,
|
||||
from urllib2 import (Request, urlopen, URLError, HTTPError, HTTPBasicAuthHandler, HTTPPasswordMgr, HTTPHandler,
|
||||
HTTPRedirectHandler, build_opener)
|
||||
if ssl:
|
||||
from urllib2 import HTTPSHandler
|
||||
@@ -67,12 +66,9 @@ else: # pragma: no cover
|
||||
from io import TextIOWrapper as file_type
|
||||
import builtins
|
||||
import configparser
|
||||
from urllib.parse import (urlparse, urlunparse, urljoin, quote, unquote,
|
||||
urlsplit, urlunsplit, splittype)
|
||||
from urllib.request import (urlopen, urlretrieve, Request, url2pathname,
|
||||
pathname2url, HTTPBasicAuthHandler,
|
||||
HTTPPasswordMgr, HTTPHandler,
|
||||
HTTPRedirectHandler, build_opener)
|
||||
from urllib.parse import (urlparse, urlunparse, urljoin, quote, unquote, urlsplit, urlunsplit, splittype)
|
||||
from urllib.request import (urlopen, urlretrieve, Request, url2pathname, pathname2url, HTTPBasicAuthHandler,
|
||||
HTTPPasswordMgr, HTTPHandler, HTTPRedirectHandler, build_opener)
|
||||
if ssl:
|
||||
from urllib.request import HTTPSHandler
|
||||
from urllib.error import HTTPError, URLError, ContentTooShortError
|
||||
@@ -111,8 +107,7 @@ except ImportError: # pragma: no cover
|
||||
# than one wildcard per fragment. A survey of established
|
||||
# policy among SSL implementations showed it to be a
|
||||
# reasonable choice.
|
||||
raise CertificateError(
|
||||
"too many wildcards in certificate DNS name: " + repr(dn))
|
||||
raise CertificateError('Too many wildcards in certificate DNS name: %r' % dn)
|
||||
|
||||
# speed up common case w/o wildcards
|
||||
if not wildcards:
|
||||
@@ -174,12 +169,10 @@ except ImportError: # pragma: no cover
|
||||
dnsnames.append(value)
|
||||
if len(dnsnames) > 1:
|
||||
raise CertificateError("hostname %r "
|
||||
"doesn't match either of %s" %
|
||||
(hostname, ', '.join(map(repr, dnsnames))))
|
||||
"doesn't match either of %s" % (hostname, ', '.join(map(repr, dnsnames))))
|
||||
elif len(dnsnames) == 1:
|
||||
raise CertificateError("hostname %r "
|
||||
"doesn't match %r" %
|
||||
(hostname, dnsnames[0]))
|
||||
"doesn't match %r" % (hostname, dnsnames[0]))
|
||||
else:
|
||||
raise CertificateError("no appropriate commonName or "
|
||||
"subjectAltName fields were found")
|
||||
@@ -348,8 +341,7 @@ except AttributeError: # pragma: no cover
|
||||
elif isinstance(filename, text_type):
|
||||
return filename.encode(_fsencoding, _fserrors)
|
||||
else:
|
||||
raise TypeError("expect bytes or str, not %s" %
|
||||
type(filename).__name__)
|
||||
raise TypeError("expect bytes or str, not %s" % type(filename).__name__)
|
||||
|
||||
def fsdecode(filename):
|
||||
if isinstance(filename, text_type):
|
||||
@@ -357,8 +349,7 @@ except AttributeError: # pragma: no cover
|
||||
elif isinstance(filename, bytes):
|
||||
return filename.decode(_fsencoding, _fserrors)
|
||||
else:
|
||||
raise TypeError("expect bytes or str, not %s" %
|
||||
type(filename).__name__)
|
||||
raise TypeError("expect bytes or str, not %s" % type(filename).__name__)
|
||||
|
||||
|
||||
try:
|
||||
@@ -433,18 +424,16 @@ except ImportError: # pragma: no cover
|
||||
if filename is None:
|
||||
msg = "unknown encoding: " + encoding
|
||||
else:
|
||||
msg = "unknown encoding for {!r}: {}".format(
|
||||
filename, encoding)
|
||||
msg = "unknown encoding for {!r}: {}".format(filename, encoding)
|
||||
raise SyntaxError(msg)
|
||||
|
||||
if bom_found:
|
||||
if codec.name != 'utf-8':
|
||||
# This behaviour mimics the Python interpreter
|
||||
if filename is None:
|
||||
msg = 'encoding problem: utf-8'
|
||||
msg = 'Encoding problem: utf-8'
|
||||
else:
|
||||
msg = 'encoding problem for {!r}: utf-8'.format(
|
||||
filename)
|
||||
msg = 'Encoding problem for %r: utf-8' % filename
|
||||
raise SyntaxError(msg)
|
||||
encoding += '-sig'
|
||||
return encoding
|
||||
@@ -482,15 +471,40 @@ if sys.version_info[:2] < (3, 4):
|
||||
else:
|
||||
from html import unescape
|
||||
|
||||
_get_ident = None
|
||||
|
||||
|
||||
def _thread_get_ident():
|
||||
global _get_ident
|
||||
if _get_ident is None:
|
||||
try:
|
||||
# Python 2
|
||||
from thread import get_ident as _get_ident
|
||||
except ImportError:
|
||||
try:
|
||||
from dummy_thread import get_ident as _get_ident
|
||||
except ImportError:
|
||||
# Python >= 3
|
||||
try:
|
||||
from _thread import get_ident as _get_ident
|
||||
except ImportError:
|
||||
from _dummy_thread import get_ident as _get_ident
|
||||
return _get_ident
|
||||
|
||||
|
||||
try:
|
||||
# Python >= 3.3
|
||||
from collections import ChainMap
|
||||
except ImportError: # pragma: no cover
|
||||
from collections import MutableMapping
|
||||
|
||||
try:
|
||||
# Python >= 3.2
|
||||
from reprlib import recursive_repr as _recursive_repr
|
||||
except ImportError:
|
||||
|
||||
_get_ident = _thread_get_ident()
|
||||
|
||||
def _recursive_repr(fillvalue='...'):
|
||||
'''
|
||||
Decorator to make a repr function return fillvalue for a recursive
|
||||
@@ -501,7 +515,7 @@ except ImportError: # pragma: no cover
|
||||
repr_running = set()
|
||||
|
||||
def wrapper(self):
|
||||
key = id(self), get_ident()
|
||||
key = id(self), _get_ident()
|
||||
if key in repr_running:
|
||||
return fillvalue
|
||||
repr_running.add(key)
|
||||
@@ -515,8 +529,7 @@ except ImportError: # pragma: no cover
|
||||
wrapper.__module__ = getattr(user_function, '__module__')
|
||||
wrapper.__doc__ = getattr(user_function, '__doc__')
|
||||
wrapper.__name__ = getattr(user_function, '__name__')
|
||||
wrapper.__annotations__ = getattr(user_function,
|
||||
'__annotations__', {})
|
||||
wrapper.__annotations__ = getattr(user_function, '__annotations__', {})
|
||||
return wrapper
|
||||
|
||||
return decorating_function
|
||||
@@ -547,19 +560,16 @@ except ImportError: # pragma: no cover
|
||||
def __getitem__(self, key):
|
||||
for mapping in self.maps:
|
||||
try:
|
||||
return mapping[
|
||||
key] # can't use 'key in mapping' with defaultdict
|
||||
return mapping[key] # can't use 'key in mapping' with defaultdict
|
||||
except KeyError:
|
||||
pass
|
||||
return self.__missing__(
|
||||
key) # support subclasses that define __missing__
|
||||
return self.__missing__(key) # support subclasses that define __missing__
|
||||
|
||||
def get(self, key, default=None):
|
||||
return self[key] if key in self else default
|
||||
|
||||
def __len__(self):
|
||||
return len(set().union(
|
||||
*self.maps)) # reuses stored hash values if possible
|
||||
return len(set().union(*self.maps)) # reuses stored hash values if possible
|
||||
|
||||
def __iter__(self):
|
||||
return iter(set().union(*self.maps))
|
||||
@@ -572,8 +582,7 @@ except ImportError: # pragma: no cover
|
||||
|
||||
@_recursive_repr()
|
||||
def __repr__(self):
|
||||
return '{0.__class__.__name__}({1})'.format(
|
||||
self, ', '.join(map(repr, self.maps)))
|
||||
return '{0.__class__.__name__}({1})'.format(self, ', '.join(map(repr, self.maps)))
|
||||
|
||||
@classmethod
|
||||
def fromkeys(cls, iterable, *args):
|
||||
@@ -602,8 +611,7 @@ except ImportError: # pragma: no cover
|
||||
try:
|
||||
del self.maps[0][key]
|
||||
except KeyError:
|
||||
raise KeyError(
|
||||
'Key not found in the first mapping: {!r}'.format(key))
|
||||
raise KeyError('Key not found in the first mapping: {!r}'.format(key))
|
||||
|
||||
def popitem(self):
|
||||
'Remove and return an item pair from maps[0]. Raise KeyError is maps[0] is empty.'
|
||||
@@ -617,8 +625,7 @@ except ImportError: # pragma: no cover
|
||||
try:
|
||||
return self.maps[0].pop(key, *args)
|
||||
except KeyError:
|
||||
raise KeyError(
|
||||
'Key not found in the first mapping: {!r}'.format(key))
|
||||
raise KeyError('Key not found in the first mapping: {!r}'.format(key))
|
||||
|
||||
def clear(self):
|
||||
'Clear maps[0], leaving maps[1:] intact.'
|
||||
@@ -629,7 +636,7 @@ try:
|
||||
from importlib.util import cache_from_source # Python >= 3.4
|
||||
except ImportError: # pragma: no cover
|
||||
|
||||
def cache_from_source(path, debug_override=None):
|
||||
def cache_from_source(path, debug_override=None, optimization=None):
|
||||
assert path.endswith('.py')
|
||||
if debug_override is None:
|
||||
debug_override = __debug__
|
||||
@@ -641,15 +648,13 @@ except ImportError: # pragma: no cover
|
||||
|
||||
|
||||
try:
|
||||
# Python >= 3.1
|
||||
from collections import OrderedDict
|
||||
except ImportError: # pragma: no cover
|
||||
# {{{ http://code.activestate.com/recipes/576693/ (r9)
|
||||
# Backport of OrderedDict() class that runs on Python 2.4, 2.5, 2.6, 2.7 and pypy.
|
||||
# Passes Python2.7's test suite and incorporates all the latest updates.
|
||||
try:
|
||||
from thread import get_ident as _get_ident
|
||||
except ImportError:
|
||||
from dummy_thread import get_ident as _get_ident
|
||||
_get_ident = _thread_get_ident()
|
||||
|
||||
try:
|
||||
from _abcoll import KeysView, ValuesView, ItemsView
|
||||
@@ -676,8 +681,7 @@ except ImportError: # pragma: no cover
|
||||
|
||||
'''
|
||||
if len(args) > 1:
|
||||
raise TypeError('expected at most 1 arguments, got %d' %
|
||||
len(args))
|
||||
raise TypeError('expected at most 1 arguments, got %d' % len(args))
|
||||
try:
|
||||
self.__root
|
||||
except AttributeError:
|
||||
@@ -885,8 +889,7 @@ except ImportError: # pragma: no cover
|
||||
|
||||
'''
|
||||
if isinstance(other, OrderedDict):
|
||||
return len(self) == len(
|
||||
other) and self.items() == other.items()
|
||||
return len(self) == len(other) and self.items() == other.items()
|
||||
return dict.__eq__(self, other)
|
||||
|
||||
def __ne__(self, other):
|
||||
@@ -936,8 +939,7 @@ except ImportError: # pragma: no cover
|
||||
# If the converted value is different, save for next time
|
||||
if value is not result:
|
||||
self[key] = result
|
||||
if type(result) in (ConvertingDict, ConvertingList,
|
||||
ConvertingTuple):
|
||||
if type(result) in (ConvertingDict, ConvertingList, ConvertingTuple):
|
||||
result.parent = self
|
||||
result.key = key
|
||||
return result
|
||||
@@ -948,8 +950,7 @@ except ImportError: # pragma: no cover
|
||||
# If the converted value is different, save for next time
|
||||
if value is not result:
|
||||
self[key] = result
|
||||
if type(result) in (ConvertingDict, ConvertingList,
|
||||
ConvertingTuple):
|
||||
if type(result) in (ConvertingDict, ConvertingList, ConvertingTuple):
|
||||
result.parent = self
|
||||
result.key = key
|
||||
return result
|
||||
@@ -958,8 +959,7 @@ except ImportError: # pragma: no cover
|
||||
value = dict.pop(self, key, default)
|
||||
result = self.configurator.convert(value)
|
||||
if value is not result:
|
||||
if type(result) in (ConvertingDict, ConvertingList,
|
||||
ConvertingTuple):
|
||||
if type(result) in (ConvertingDict, ConvertingList, ConvertingTuple):
|
||||
result.parent = self
|
||||
result.key = key
|
||||
return result
|
||||
@@ -973,8 +973,7 @@ except ImportError: # pragma: no cover
|
||||
# If the converted value is different, save for next time
|
||||
if value is not result:
|
||||
self[key] = result
|
||||
if type(result) in (ConvertingDict, ConvertingList,
|
||||
ConvertingTuple):
|
||||
if type(result) in (ConvertingDict, ConvertingList, ConvertingTuple):
|
||||
result.parent = self
|
||||
result.key = key
|
||||
return result
|
||||
@@ -983,8 +982,7 @@ except ImportError: # pragma: no cover
|
||||
value = list.pop(self, idx)
|
||||
result = self.configurator.convert(value)
|
||||
if value is not result:
|
||||
if type(result) in (ConvertingDict, ConvertingList,
|
||||
ConvertingTuple):
|
||||
if type(result) in (ConvertingDict, ConvertingList, ConvertingTuple):
|
||||
result.parent = self
|
||||
return result
|
||||
|
||||
@@ -995,8 +993,7 @@ except ImportError: # pragma: no cover
|
||||
value = tuple.__getitem__(self, key)
|
||||
result = self.configurator.convert(value)
|
||||
if value is not result:
|
||||
if type(result) in (ConvertingDict, ConvertingList,
|
||||
ConvertingTuple):
|
||||
if type(result) in (ConvertingDict, ConvertingList, ConvertingTuple):
|
||||
result.parent = self
|
||||
result.key = key
|
||||
return result
|
||||
@@ -1073,9 +1070,7 @@ except ImportError: # pragma: no cover
|
||||
d = d[idx]
|
||||
else:
|
||||
try:
|
||||
n = int(
|
||||
idx
|
||||
) # try as number first (most likely)
|
||||
n = int(idx) # try as number first (most likely)
|
||||
d = d[n]
|
||||
except TypeError:
|
||||
d = d[idx]
|
||||
@@ -1093,12 +1088,10 @@ except ImportError: # pragma: no cover
|
||||
replaced by their converting alternatives. Strings are checked to
|
||||
see if they have a conversion format and are converted if they do.
|
||||
"""
|
||||
if not isinstance(value, ConvertingDict) and isinstance(
|
||||
value, dict):
|
||||
if not isinstance(value, ConvertingDict) and isinstance(value, dict):
|
||||
value = ConvertingDict(value)
|
||||
value.configurator = self
|
||||
elif not isinstance(value, ConvertingList) and isinstance(
|
||||
value, list):
|
||||
elif not isinstance(value, ConvertingList) and isinstance(value, list):
|
||||
value = ConvertingList(value)
|
||||
value.configurator = self
|
||||
elif not isinstance(value, ConvertingTuple) and isinstance(value, tuple):
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013-2017 Vinay Sajip.
|
||||
# Copyright (C) 2013-2026 Vinay Sajip.
|
||||
# Licensed to the Python Software Foundation under a contributor agreement.
|
||||
# See LICENSE.txt and CONTRIBUTORS.txt.
|
||||
#
|
||||
@@ -20,11 +20,11 @@ from .util import cached_property, get_cache_base, Cache
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
cache = None # created when needed
|
||||
cache = None # created when needed
|
||||
|
||||
|
||||
class ResourceCache(Cache):
|
||||
|
||||
def __init__(self, base=None):
|
||||
if base is None:
|
||||
# Use native string to avoid issues on 2.x: see Python #20140.
|
||||
@@ -69,6 +69,7 @@ class ResourceCache(Cache):
|
||||
|
||||
|
||||
class ResourceBase(object):
|
||||
|
||||
def __init__(self, finder, name):
|
||||
self.finder = finder
|
||||
self.name = name
|
||||
@@ -80,7 +81,7 @@ class Resource(ResourceBase):
|
||||
not normally instantiated by user code, but rather by a
|
||||
:class:`ResourceFinder` which manages the resource.
|
||||
"""
|
||||
is_container = False # Backwards compatibility
|
||||
is_container = False # Backwards compatibility
|
||||
|
||||
def as_stream(self):
|
||||
"""
|
||||
@@ -108,7 +109,7 @@ class Resource(ResourceBase):
|
||||
|
||||
|
||||
class ResourceContainer(ResourceBase):
|
||||
is_container = True # Backwards compatibility
|
||||
is_container = True # Backwards compatibility
|
||||
|
||||
@cached_property
|
||||
def resources(self):
|
||||
@@ -133,17 +134,33 @@ class ResourceFinder(object):
|
||||
def _adjust_path(self, path):
|
||||
return os.path.realpath(path)
|
||||
|
||||
def _is_in_base(self, path):
|
||||
base = self._adjust_path(self.base)
|
||||
if path == base:
|
||||
return True
|
||||
if not base.endswith(os.sep):
|
||||
base = base + os.sep
|
||||
return path.startswith(base)
|
||||
|
||||
def _make_path(self, resource_name):
|
||||
# Issue #50: need to preserve type of path on Python 2.x
|
||||
# like os.path._get_sep
|
||||
if isinstance(resource_name, bytes): # should only happen on 2.x
|
||||
if isinstance(resource_name, bytes): # should only happen on 2.x
|
||||
sep = b'/'
|
||||
else:
|
||||
sep = '/'
|
||||
parts = resource_name.split(sep)
|
||||
parts.insert(0, self.base)
|
||||
result = os.path.join(*parts)
|
||||
return self._adjust_path(result)
|
||||
result = self._adjust_path(result)
|
||||
# See issue 263: code below commented out as it proved to be
|
||||
# too aggressively cautious, causing problems in valid use case scenarios.
|
||||
# Confine the resolved resource to the package base so a resource
|
||||
# name containing '..' cannot read files outside the package.
|
||||
# if not self._is_in_base(result):
|
||||
# raise DistlibException('Resource name escapes package: '
|
||||
# '%r' % resource_name)
|
||||
return result
|
||||
|
||||
def _find(self, path):
|
||||
return os.path.exists(path)
|
||||
@@ -174,9 +191,10 @@ class ResourceFinder(object):
|
||||
return os.path.getsize(resource.path)
|
||||
|
||||
def get_resources(self, resource):
|
||||
|
||||
def allowed(f):
|
||||
return (f != '__pycache__' and not
|
||||
f.endswith(self.skipped_extensions))
|
||||
return (f != '__pycache__' and not f.endswith(self.skipped_extensions))
|
||||
|
||||
return set([f for f in os.listdir(resource.path) if allowed(f)])
|
||||
|
||||
def is_container(self, resource):
|
||||
@@ -209,6 +227,7 @@ class ZipResourceFinder(ResourceFinder):
|
||||
"""
|
||||
Resource finder for resources in .zip files.
|
||||
"""
|
||||
|
||||
def __init__(self, module):
|
||||
super(ZipResourceFinder, self).__init__(module)
|
||||
archive = self.loader.archive
|
||||
@@ -267,7 +286,7 @@ class ZipResourceFinder(ResourceFinder):
|
||||
if not self.index[i].startswith(path):
|
||||
break
|
||||
s = self.index[i][plen:]
|
||||
result.add(s.split(os.sep, 1)[0]) # only immediate children
|
||||
result.add(s.split(os.sep, 1)[0]) # only immediate children
|
||||
i += 1
|
||||
return result
|
||||
|
||||
@@ -283,10 +302,7 @@ class ZipResourceFinder(ResourceFinder):
|
||||
return result
|
||||
|
||||
|
||||
_finder_registry = {
|
||||
type(None): ResourceFinder,
|
||||
zipimport.zipimporter: ZipResourceFinder
|
||||
}
|
||||
_finder_registry = {type(None): ResourceFinder, zipimport.zipimporter: ZipResourceFinder}
|
||||
|
||||
try:
|
||||
# In Python 3.6, _frozen_importlib -> _frozen_importlib_external
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2013-2023 Vinay Sajip.
|
||||
# Copyright (C) 2013-2026 Vinay Sajip.
|
||||
# Licensed to the Python Software Foundation under a contributor agreement.
|
||||
# See LICENSE.txt and CONTRIBUTORS.txt.
|
||||
#
|
||||
@@ -13,9 +13,11 @@ import sys
|
||||
import time
|
||||
from zipfile import ZipInfo
|
||||
|
||||
from . import DistlibException
|
||||
from .compat import sysconfig, detect_encoding, ZipFile
|
||||
from .resources import finder
|
||||
from .util import (FileOperator, get_export_entry, convert_path, get_executable, get_platform, in_venv)
|
||||
from .util import (FileOperator, get_export_entry, convert_path, get_executable, get_platform, in_venv,
|
||||
is_in_directory)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -118,19 +120,19 @@ class ScriptMaker(object):
|
||||
executable = os.path.join(dn, fn)
|
||||
return executable
|
||||
|
||||
if sys.platform.startswith('java'): # pragma: no cover
|
||||
def _is_shell(self, executable):
|
||||
"""
|
||||
Determine if the specified executable is a script
|
||||
(contains a #! line)
|
||||
"""
|
||||
try:
|
||||
with open(executable, 'rb') as fp:
|
||||
return fp.read(2) == b'#!'
|
||||
except (OSError, IOError):
|
||||
logger.warning('Failed to open %s', executable)
|
||||
return False
|
||||
|
||||
def _is_shell(self, executable):
|
||||
"""
|
||||
Determine if the specified executable is a script
|
||||
(contains a #! line)
|
||||
"""
|
||||
try:
|
||||
with open(executable) as fp:
|
||||
return fp.read(2) == '#!'
|
||||
except (OSError, IOError):
|
||||
logger.warning('Failed to open %s', executable)
|
||||
return False
|
||||
if sys.platform.startswith('java'): # pragma: no cover
|
||||
|
||||
def _fix_jython_executable(self, executable):
|
||||
if self._is_shell(executable):
|
||||
@@ -170,7 +172,9 @@ class ScriptMaker(object):
|
||||
max_shebang_length = 512
|
||||
else:
|
||||
max_shebang_length = 127
|
||||
simple_shebang = ((b' ' not in executable) and (shebang_length <= max_shebang_length))
|
||||
simple_shebang = ((b' ' not in executable) and
|
||||
(shebang_length <= max_shebang_length) and
|
||||
not self._is_shell(executable.decode('utf-8')))
|
||||
|
||||
if simple_shebang:
|
||||
result = b'#!' + executable + post_interp + b'\n'
|
||||
@@ -277,7 +281,9 @@ class ScriptMaker(object):
|
||||
zip_data = stream.getvalue()
|
||||
script_bytes = launcher + shebang + zip_data
|
||||
for name in names:
|
||||
outname = os.path.join(self.target_dir, name)
|
||||
outname = os.path.abspath(os.path.join(self.target_dir, name))
|
||||
if not is_in_directory(outname, self.target_dir):
|
||||
raise DistlibException('Attempt to escape script directory')
|
||||
if use_launcher: # pragma: no cover
|
||||
n, e = os.path.splitext(outname)
|
||||
if e.startswith('.py'):
|
||||
@@ -286,6 +292,10 @@ class ScriptMaker(object):
|
||||
try:
|
||||
self._fileop.write_binary_file(outname, script_bytes)
|
||||
except Exception:
|
||||
if not os.path.exists(outname):
|
||||
# Nothing to move aside, so the original error
|
||||
# (e.g. no write permission) is the real one.
|
||||
raise
|
||||
# Failed writing an executable - it might be in use.
|
||||
logger.warning('Failed to write executable - trying to '
|
||||
'use .deleteme logic')
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (C) 2012-2023 The Python Software Foundation.
|
||||
# Copyright (C) 2012-2026 The Python Software Foundation.
|
||||
# See LICENSE.txt and CONTRIBUTORS.txt.
|
||||
#
|
||||
import codecs
|
||||
@@ -589,7 +589,11 @@ class FileOperator(object):
|
||||
self.dirs_created.add(path)
|
||||
|
||||
def byte_compile(self, path, optimize=False, force=False, prefix=None, hashed_invalidation=False):
|
||||
dpath = cache_from_source(path, not optimize)
|
||||
if not optimize:
|
||||
optimization = ''
|
||||
else:
|
||||
optimization = '1'
|
||||
dpath = cache_from_source(path, optimization=optimization)
|
||||
logger.info('Byte-compiling %s to %s', path, dpath)
|
||||
if not self.dry_run:
|
||||
if force or self.newer(path, dpath):
|
||||
@@ -703,8 +707,8 @@ class ExportEntry(object):
|
||||
if not isinstance(other, ExportEntry):
|
||||
result = False
|
||||
else:
|
||||
result = (self.name == other.name and self.prefix == other.prefix and self.suffix == other.suffix and
|
||||
self.flags == other.flags)
|
||||
result = (self.name == other.name and self.prefix == other.prefix and self.suffix == other.suffix
|
||||
and self.flags == other.flags)
|
||||
return result
|
||||
|
||||
__hash__ = object.__hash__
|
||||
@@ -716,9 +720,35 @@ ENTRY_RE = re.compile(
|
||||
\s*(\[\s*(?P<flags>[\w-]+(=\w+)?(,\s*\w+(=\w+)?)*)\s*\])?
|
||||
''', re.VERBOSE)
|
||||
|
||||
# ENTRY_RE, but only starting at the first or last character of a whitespace
|
||||
# run. See _search_export_entry.
|
||||
_ENTRY_RE_AT_SPACE = re.compile(r'(?:(?<!\s)(?=\s)|(?=\s\S))' +
|
||||
ENTRY_RE.pattern, re.VERBOSE)
|
||||
|
||||
|
||||
def _search_export_entry(specification):
|
||||
"""
|
||||
Return ENTRY_RE.search(specification), in linear rather than quadratic
|
||||
time.
|
||||
|
||||
search() tries every start position, and each attempt can rescan the rest
|
||||
of a long name. Most positions cannot hold the leftmost match: a match that
|
||||
starts inside a run of non-space characters implies one starting earlier in
|
||||
the run (or at the whitespace just before it, since a name may start with
|
||||
whitespace), and a match starting inside a whitespace run, other than at
|
||||
its last character, implies one at its first. So the leftmost match starts
|
||||
at the first character that is not '[' (a name cannot start with '['), or
|
||||
at the first or last character of a whitespace run.
|
||||
"""
|
||||
start = len(specification) - len(specification.lstrip('['))
|
||||
m = ENTRY_RE.match(specification, start)
|
||||
if not m:
|
||||
m = _ENTRY_RE_AT_SPACE.search(specification, start)
|
||||
return m
|
||||
|
||||
|
||||
def get_export_entry(specification):
|
||||
m = ENTRY_RE.search(specification)
|
||||
m = _search_export_entry(specification)
|
||||
if not m:
|
||||
result = None
|
||||
if '[' in specification or ']' in specification:
|
||||
@@ -1223,15 +1253,52 @@ ARCHIVE_EXTENSIONS = ('.tar.gz', '.tar.bz2', '.tar', '.zip', '.tgz', '.tbz', '.w
|
||||
|
||||
def unarchive(archive_filename, dest_dir, format=None, check=True):
|
||||
|
||||
def check_path(path):
|
||||
# Symlinks seen so far in the archive, mapping the link's resolved path
|
||||
# to its resolved target. Earlier members don't exist on disk while we
|
||||
# check, so later member paths are resolved through this map lexically.
|
||||
links = {}
|
||||
|
||||
def resolve(path):
|
||||
cur = dest_dir
|
||||
if not (path == dest_dir or path.startswith(dest_dir + os.sep)):
|
||||
return os.path.realpath(path)
|
||||
for part in path[len(dest_dir):].split(os.sep):
|
||||
if part in ('', '.'):
|
||||
continue
|
||||
if part == '..':
|
||||
cur = os.path.dirname(cur)
|
||||
else:
|
||||
cur = links.get(os.path.join(cur, part), os.path.join(cur, part))
|
||||
return os.path.realpath(cur)
|
||||
|
||||
def check_path(path, base=None):
|
||||
if not isinstance(path, text_type):
|
||||
path = path.decode('utf-8')
|
||||
p = os.path.abspath(os.path.join(dest_dir, path))
|
||||
if not p.startswith(dest_dir) or p[plen] != os.sep:
|
||||
if base is None:
|
||||
base = dest_dir
|
||||
p = resolve(os.path.join(base, path))
|
||||
if not (p == dest_dir or p.startswith(dest_dir + os.sep)):
|
||||
raise ValueError('path outside destination: %r' % p)
|
||||
return p
|
||||
|
||||
dest_dir = os.path.abspath(dest_dir)
|
||||
plen = len(dest_dir)
|
||||
def check_link(member):
|
||||
# A symlink/hardlink member's name is validated like any other
|
||||
# member, but its target (linkname) is not covered by extractall's
|
||||
# name-based handling. An unchecked target lets a later member be
|
||||
# written through the link to a location outside dest_dir. Validate
|
||||
# the resolved target stays within dest_dir. Symlink targets are
|
||||
# relative to the member's own directory; hardlink targets are
|
||||
# relative to the archive root (i.e. dest_dir).
|
||||
if not (member.issym() or member.islnk()):
|
||||
return
|
||||
if member.islnk():
|
||||
check_path(member.linkname)
|
||||
return
|
||||
name = member.name.rstrip('/')
|
||||
parent = check_path(os.path.dirname(name) or '.')
|
||||
links[os.path.join(parent, os.path.basename(name))] = check_path(member.linkname, base=parent)
|
||||
|
||||
dest_dir = os.path.realpath(dest_dir)
|
||||
archive = None
|
||||
if format is None:
|
||||
if archive_filename.endswith(('.zip', '.whl')):
|
||||
@@ -1257,9 +1324,9 @@ def unarchive(archive_filename, dest_dir, format=None, check=True):
|
||||
else:
|
||||
archive = tarfile.open(archive_filename, mode)
|
||||
if check:
|
||||
names = archive.getnames()
|
||||
for name in names:
|
||||
check_path(name)
|
||||
for member in archive.getmembers():
|
||||
check_path(member.name)
|
||||
check_link(member)
|
||||
if format != 'zip' and sys.version_info[0] < 3:
|
||||
# See Python issue 17153. If the dest path contains Unicode,
|
||||
# tarfile extraction fails on Python 2.x if a member path name
|
||||
@@ -1272,11 +1339,13 @@ def unarchive(archive_filename, dest_dir, format=None, check=True):
|
||||
# Limit extraction of dangerous items, if this Python
|
||||
# allows it easily. If not, just trust the input.
|
||||
# See: https://docs.python.org/3/library/tarfile.html#extraction-filters
|
||||
# data_filter is the stdlib default from Python 3.14 onwards; using the
|
||||
# laxer tar_filter here would downgrade that secure default.
|
||||
def extraction_filter(member, path):
|
||||
"""Run tarfile.tar_filter, but raise the expected ValueError"""
|
||||
"""Run tarfile.data_filter, but raise the expected ValueError"""
|
||||
# This is only called if the current Python has tarfile filters
|
||||
try:
|
||||
return tarfile.tar_filter(member, path)
|
||||
return tarfile.data_filter(member, path)
|
||||
except tarfile.FilterError as exc:
|
||||
raise ValueError(str(exc))
|
||||
|
||||
@@ -1455,6 +1524,7 @@ if ssl:
|
||||
# HTTPSConnection which verifies certificates/matches domains
|
||||
#
|
||||
|
||||
|
||||
class HTTPSConnection(httplib.HTTPSConnection):
|
||||
ca_certs = None # set this to the path to the certs file (.pem)
|
||||
check_domain = True # only used if ca_certs is not None
|
||||
@@ -1776,8 +1846,13 @@ class SubprocessMixin(object):
|
||||
|
||||
def normalize_name(name):
|
||||
"""Normalize a python package name a la PEP 503"""
|
||||
# https://www.python.org/dev/peps/pep-0503/#normalized-names
|
||||
return re.sub('[-_.]+', '-', name).lower()
|
||||
# https://peps.python.org/pep-0503/#normalized-names
|
||||
# Emulates re.sub(r"[-_.]+", "-", name).lower()
|
||||
# Much faster than re, and even faster than str.translate
|
||||
value = name.lower().replace("_", "-").replace(".", "-")
|
||||
while "--" in value:
|
||||
value = value.replace("--", "-")
|
||||
return value
|
||||
|
||||
|
||||
# def _get_pypirc_command():
|
||||
@@ -1982,3 +2057,12 @@ def get_platform():
|
||||
if cross_compilation_target not in _TARGET_TO_PLAT:
|
||||
return get_host_platform()
|
||||
return _TARGET_TO_PLAT[cross_compilation_target]
|
||||
|
||||
|
||||
def is_in_directory(path, target):
|
||||
"""
|
||||
Check if a path is inside a target directory. This doesn't check case (might be an issue on Windows)
|
||||
"""
|
||||
path = os.path.abspath(path)
|
||||
target = os.path.abspath(target)
|
||||
return path == target or path.startswith(target + os.sep)
|
||||
@@ -1,6 +1,6 @@
|
||||
BSD 3-Clause License
|
||||
|
||||
Copyright (c) 2013-2025, Kim Davies and contributors.
|
||||
Copyright (c) 2013-2026, Kim Davies and contributors.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
|
||||
@@ -18,11 +18,13 @@ from .core import (
|
||||
valid_label_length,
|
||||
valid_string_length,
|
||||
)
|
||||
from .idnadata import __version__ as unicode_version
|
||||
from .intranges import intranges_contain
|
||||
from .package_data import __version__
|
||||
|
||||
__all__ = [
|
||||
"__version__",
|
||||
"unicode_version",
|
||||
"IDNABidiError",
|
||||
"IDNAError",
|
||||
"InvalidCodepoint",
|
||||
|
||||
@@ -1,25 +1,34 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import codecs
|
||||
import re
|
||||
from typing import Any, Optional, Tuple
|
||||
from typing import Any
|
||||
|
||||
from .core import IDNAError, alabel, decode, encode, ulabel
|
||||
|
||||
_unicode_dots_re = re.compile("[\u002e\u3002\uff0e\uff61]")
|
||||
from .core import IDNAError, _max_domain_length, _unicode_dots_re, alabel, decode, encode, ulabel
|
||||
|
||||
|
||||
class Codec(codecs.Codec):
|
||||
def encode(self, data: str, errors: str = "strict") -> Tuple[bytes, int]:
|
||||
"""Stateless IDNA 2008 codec.
|
||||
|
||||
Implements the :class:`codecs.Codec` protocol so that the whole-domain
|
||||
encoder (:func:`idna.encode`) and decoder (:func:`idna.decode`) are
|
||||
accessible through the standard codec machinery as ``"idna2008"``.
|
||||
|
||||
Only the ``"strict"`` error handler is supported; any other handler
|
||||
raises :exc:`~idna.IDNAError`.
|
||||
"""
|
||||
|
||||
def encode(self, data: str, errors: str = "strict") -> tuple[bytes, int]: # ty: ignore[invalid-method-override]
|
||||
if errors != "strict":
|
||||
raise IDNAError('Unsupported error handling "{}"'.format(errors))
|
||||
raise IDNAError(f'Unsupported error handling "{errors}"', code="unsupported_errors")
|
||||
|
||||
if not data:
|
||||
return b"", 0
|
||||
|
||||
return encode(data), len(data)
|
||||
|
||||
def decode(self, data: bytes, errors: str = "strict") -> Tuple[str, int]:
|
||||
def decode(self, data: bytes, errors: str = "strict") -> tuple[str, int]: # ty: ignore[invalid-method-override]
|
||||
if errors != "strict":
|
||||
raise IDNAError('Unsupported error handling "{}"'.format(errors))
|
||||
raise IDNAError(f'Unsupported error handling "{errors}"', code="unsupported_errors")
|
||||
|
||||
if not data:
|
||||
return "", 0
|
||||
@@ -28,49 +37,132 @@ class Codec(codecs.Codec):
|
||||
|
||||
|
||||
class IncrementalEncoder(codecs.BufferedIncrementalEncoder):
|
||||
def _buffer_encode(self, data: str, errors: str, final: bool) -> Tuple[bytes, int]:
|
||||
"""Incremental IDNA 2008 encoder.
|
||||
|
||||
Buffers a partial trailing label across calls until either the next
|
||||
label separator is seen or ``final=True``, so that streamed input is
|
||||
encoded one whole label at a time. Any of the four Unicode label
|
||||
separators (``U+002E``, ``U+3002``, ``U+FF0E``, ``U+FF61``) ends a
|
||||
label; the result always uses ``U+002E`` as the separator.
|
||||
|
||||
The 253-octet domain length limit (254 with a trailing dot) that
|
||||
:func:`idna.encode` enforces is applied to the accumulated output, so
|
||||
that streaming a name and encoding it in one shot either both succeed
|
||||
with the same result or both raise :exc:`~idna.IDNAError`.
|
||||
|
||||
Only the ``"strict"`` error handler is supported.
|
||||
"""
|
||||
|
||||
def __init__(self, errors: str = "strict") -> None:
|
||||
super().__init__(errors)
|
||||
self._emitted = 0 # octets returned so far
|
||||
self._trailing_dot = False # whether the output so far ends with "."
|
||||
|
||||
def reset(self) -> None:
|
||||
super().reset()
|
||||
self._emitted = 0
|
||||
self._trailing_dot = False
|
||||
|
||||
def getstate(self) -> Any:
|
||||
if not self.buffer and not self._emitted:
|
||||
return 0
|
||||
return (self.buffer, self._emitted, self._trailing_dot)
|
||||
|
||||
def setstate(self, state: Any) -> None:
|
||||
if state:
|
||||
self.buffer, self._emitted, self._trailing_dot = state
|
||||
else:
|
||||
self.reset()
|
||||
|
||||
def _buffer_encode(self, data: str, errors: str, final: bool) -> tuple[bytes, int]: # ty: ignore[invalid-method-override]
|
||||
if errors != "strict":
|
||||
raise IDNAError('Unsupported error handling "{}"'.format(errors))
|
||||
raise IDNAError(f'Unsupported error handling "{errors}"', code="unsupported_errors")
|
||||
|
||||
if not data:
|
||||
return b"", 0
|
||||
|
||||
labels = _unicode_dots_re.split(data)
|
||||
trailing_dot = b""
|
||||
if labels:
|
||||
if not labels[-1]:
|
||||
trailing_dot = b"."
|
||||
del labels[-1]
|
||||
elif not final:
|
||||
# Keep potentially unfinished label until the next call
|
||||
del labels[-1]
|
||||
if labels:
|
||||
trailing_dot = b"."
|
||||
|
||||
result = []
|
||||
result_bytes = b""
|
||||
size = 0
|
||||
for label in labels:
|
||||
result.append(alabel(label))
|
||||
if size:
|
||||
size += 1
|
||||
size += len(label)
|
||||
if data:
|
||||
labels = _unicode_dots_re.split(data)
|
||||
trailing_dot = b""
|
||||
if labels:
|
||||
if not labels[-1]:
|
||||
trailing_dot = b"."
|
||||
del labels[-1]
|
||||
elif not final:
|
||||
# Keep potentially unfinished label until the next call
|
||||
del labels[-1]
|
||||
if labels:
|
||||
trailing_dot = b"."
|
||||
|
||||
# Join with U+002E
|
||||
result_bytes = b".".join(result) + trailing_dot
|
||||
size += len(trailing_dot)
|
||||
result = []
|
||||
for label in labels:
|
||||
result.append(alabel(label))
|
||||
if size:
|
||||
size += 1
|
||||
size += len(label)
|
||||
|
||||
result_bytes = b".".join(result) + trailing_dot
|
||||
size += len(trailing_dot)
|
||||
|
||||
# Mirror encode(): the whole name may not exceed 253 octets, or 254
|
||||
# when it ends with a dot. Until the input is final a trailing dot
|
||||
# may still arrive, so only the 254-octet ceiling applies before then.
|
||||
self._emitted += len(result_bytes)
|
||||
if result_bytes:
|
||||
self._trailing_dot = result_bytes.endswith(b".")
|
||||
may_end_with_dot = self._trailing_dot or not final
|
||||
if self._emitted > _max_domain_length + may_end_with_dot:
|
||||
raise IDNAError("Domain too long", code="domain_too_long")
|
||||
return result_bytes, size
|
||||
|
||||
|
||||
class IncrementalDecoder(codecs.BufferedIncrementalDecoder):
|
||||
def _buffer_decode(self, data: Any, errors: str, final: bool) -> Tuple[str, int]:
|
||||
"""Incremental IDNA 2008 decoder.
|
||||
|
||||
Buffers a partial trailing label across calls until either the next
|
||||
label separator is seen or ``final=True``, so that streamed input is
|
||||
decoded one whole label at a time.
|
||||
|
||||
The 254-octet input length limit that :func:`idna.decode` enforces is
|
||||
applied to the accumulated input, so that streaming a name and decoding
|
||||
it in one shot either both succeed with the same result or both raise
|
||||
:exc:`~idna.IDNAError`.
|
||||
|
||||
Only the ``"strict"`` error handler is supported.
|
||||
"""
|
||||
|
||||
def __init__(self, errors: str = "strict") -> None:
|
||||
super().__init__(errors)
|
||||
self._consumed = 0 # input octets consumed so far
|
||||
|
||||
def reset(self) -> None:
|
||||
super().reset()
|
||||
self._consumed = 0
|
||||
|
||||
def getstate(self) -> tuple[bytes, int]:
|
||||
return (self.buffer, self._consumed)
|
||||
|
||||
def setstate(self, state: tuple[bytes, int]) -> None:
|
||||
self.buffer, self._consumed = state
|
||||
|
||||
def _buffer_decode(self, data: Any, errors: str, final: bool) -> tuple[str, int]: # ty: ignore[invalid-method-override]
|
||||
if errors != "strict":
|
||||
raise IDNAError('Unsupported error handling "{}"'.format(errors))
|
||||
raise IDNAError(f'Unsupported error handling "{errors}"', code="unsupported_errors")
|
||||
|
||||
if not data:
|
||||
return ("", 0)
|
||||
|
||||
if not isinstance(data, str):
|
||||
data = str(data, "ascii")
|
||||
try:
|
||||
data = str(data, "ascii")
|
||||
except UnicodeDecodeError as err:
|
||||
raise IDNAError("Invalid ASCII in A-label", code="invalid_ascii") from err
|
||||
|
||||
# Mirror decode(), which rejects input longer than 254 characters
|
||||
# (253 plus a possible trailing dot) before looking at any label.
|
||||
# ``data`` is the unconsumed buffer plus the new input, so this is
|
||||
# the total seen so far.
|
||||
if self._consumed + len(data) > _max_domain_length + 1:
|
||||
raise IDNAError("Domain too long", code="domain_too_long")
|
||||
|
||||
labels = _unicode_dots_re.split(data)
|
||||
trailing_dot = ""
|
||||
@@ -94,6 +186,7 @@ class IncrementalDecoder(codecs.BufferedIncrementalDecoder):
|
||||
|
||||
result_str = ".".join(result) + trailing_dot
|
||||
size += len(trailing_dot)
|
||||
self._consumed += size
|
||||
return (result_str, size)
|
||||
|
||||
|
||||
@@ -105,7 +198,17 @@ class StreamReader(Codec, codecs.StreamReader):
|
||||
pass
|
||||
|
||||
|
||||
def search_function(name: str) -> Optional[codecs.CodecInfo]:
|
||||
def search_function(name: str) -> codecs.CodecInfo | None:
|
||||
"""Codec search function registered with :mod:`codecs`.
|
||||
|
||||
Returns a :class:`codecs.CodecInfo` for the ``"idna2008"`` codec name
|
||||
so that ``str.encode("idna2008")`` and ``bytes.decode("idna2008")``
|
||||
invoke the IDNA 2008 codec defined in this module.
|
||||
|
||||
:param name: The codec name being looked up.
|
||||
:returns: A :class:`codecs.CodecInfo` instance if ``name`` is
|
||||
``"idna2008"``, otherwise ``None``.
|
||||
"""
|
||||
if name != "idna2008":
|
||||
return None
|
||||
return codecs.CodecInfo(
|
||||
|
||||
@@ -1,15 +1,43 @@
|
||||
from typing import Any, Union
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from .core import decode, encode
|
||||
|
||||
|
||||
def ToASCII(label: str) -> bytes:
|
||||
"""Compatibility shim for :rfc:`3490` ``ToASCII``.
|
||||
|
||||
Delegates to :func:`idna.encode` (IDNA 2008). Provided to ease porting
|
||||
of code written against the legacy :mod:`encodings.idna` API; new code
|
||||
should call :func:`idna.encode` directly.
|
||||
|
||||
:param label: The label or domain to encode.
|
||||
:returns: The encoded form as ASCII :class:`bytes`.
|
||||
"""
|
||||
return encode(label)
|
||||
|
||||
|
||||
def ToUnicode(label: Union[bytes, bytearray]) -> str:
|
||||
def ToUnicode(label: bytes | bytearray) -> str:
|
||||
"""Compatibility shim for :rfc:`3490` ``ToUnicode``.
|
||||
|
||||
Delegates to :func:`idna.decode` (IDNA 2008). Provided to ease porting
|
||||
of code written against the legacy :mod:`encodings.idna` API; new code
|
||||
should call :func:`idna.decode` directly.
|
||||
|
||||
:param label: The label or domain to decode.
|
||||
:returns: The decoded Unicode form.
|
||||
"""
|
||||
return decode(label)
|
||||
|
||||
|
||||
def nameprep(s: Any) -> None:
|
||||
"""Stub for :rfc:`3491` Nameprep, which is not used by IDNA 2008.
|
||||
|
||||
IDNA 2008 (:rfc:`5891`) replaces Nameprep with the per-codepoint
|
||||
validity classes from :rfc:`5892`; this function exists only to
|
||||
return a clear error if legacy code attempts to call it.
|
||||
|
||||
:raises NotImplementedError: Always.
|
||||
"""
|
||||
raise NotImplementedError("IDNA 2008 does not utilise nameprep protocol")
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -6,10 +6,9 @@ in the original list?" in time O(log(# runs)).
|
||||
"""
|
||||
|
||||
import bisect
|
||||
from typing import List, Tuple
|
||||
|
||||
|
||||
def intranges_from_list(list_: List[int]) -> Tuple[int, ...]:
|
||||
def intranges_from_list(list_: list[int]) -> tuple[int, ...]:
|
||||
"""Represent a list of integers as a sequence of ranges:
|
||||
((start_0, end_0), (start_1, end_1), ...), such that the original
|
||||
integers are exactly those x such that start_i <= x < end_i for some i.
|
||||
@@ -21,9 +20,8 @@ def intranges_from_list(list_: List[int]) -> Tuple[int, ...]:
|
||||
ranges = []
|
||||
last_write = -1
|
||||
for i in range(len(sorted_list)):
|
||||
if i + 1 < len(sorted_list):
|
||||
if sorted_list[i] == sorted_list[i + 1] - 1:
|
||||
continue
|
||||
if i + 1 < len(sorted_list) and sorted_list[i] == sorted_list[i + 1] - 1:
|
||||
continue
|
||||
current_range = sorted_list[last_write + 1 : i + 1]
|
||||
ranges.append(_encode_range(current_range[0], current_range[-1] + 1))
|
||||
last_write = i
|
||||
@@ -35,11 +33,11 @@ def _encode_range(start: int, end: int) -> int:
|
||||
return (start << 32) | end
|
||||
|
||||
|
||||
def _decode_range(r: int) -> Tuple[int, int]:
|
||||
def _decode_range(r: int) -> tuple[int, int]:
|
||||
return (r >> 32), (r & ((1 << 32) - 1))
|
||||
|
||||
|
||||
def intranges_contain(int_: int, ranges: Tuple[int, ...]) -> bool:
|
||||
def intranges_contain(int_: int, ranges: tuple[int, ...]) -> bool:
|
||||
"""Determine if `int_` falls into one of the ranges in `ranges`."""
|
||||
tuple_ = _encode_range(int_, 0)
|
||||
pos = bisect.bisect_left(ranges, tuple_)
|
||||
|
||||
@@ -1 +1 @@
|
||||
__version__ = "3.11"
|
||||
__version__ = "3.20"
|
||||
File diff suppressed because it is too large.
Load diff
@@ -4,8 +4,8 @@ import os
|
||||
from .exceptions import * # noqa: F403
|
||||
from .ext import ExtType, Timestamp
|
||||
|
||||
version = (1, 1, 2)
|
||||
__version__ = "1.1.2"
|
||||
version = (1, 2, 4)
|
||||
__version__ = "1.2.4"
|
||||
|
||||
|
||||
if os.environ.get("MSGPACK_PUREPYTHON"):
|
||||
|
||||
@@ -2,6 +2,8 @@ import datetime
|
||||
import struct
|
||||
from collections import namedtuple
|
||||
|
||||
_EPOCH = datetime.datetime(1970, 1, 1, tzinfo=datetime.timezone.utc)
|
||||
|
||||
|
||||
class ExtType(namedtuple("ExtType", "code data")):
|
||||
"""ExtType represents ext type in msgpack."""
|
||||
@@ -156,8 +158,7 @@ class Timestamp:
|
||||
|
||||
:rtype: `datetime.datetime`
|
||||
"""
|
||||
utc = datetime.timezone.utc
|
||||
return datetime.datetime.fromtimestamp(0, utc) + datetime.timedelta(
|
||||
return _EPOCH + datetime.timedelta(
|
||||
seconds=self.seconds, microseconds=self.nanoseconds // 1000
|
||||
)
|
||||
|
||||
@@ -167,4 +168,17 @@ class Timestamp:
|
||||
|
||||
:rtype: Timestamp
|
||||
"""
|
||||
return Timestamp(seconds=int(dt.timestamp()), nanoseconds=dt.microsecond * 1000)
|
||||
# Use integer timedelta arithmetic (like the Cython packer) rather than
|
||||
# ``int(dt.timestamp() // 1)``. ``datetime.timestamp()`` returns a float
|
||||
# that cannot hold microsecond precision for datetimes far from the epoch,
|
||||
# so it may round the whole-second part up while the exact ``microsecond``
|
||||
# is still used for the nanoseconds -- producing a Timestamp one second in
|
||||
# the future (and OverflowError near datetime.max).
|
||||
if dt.tzinfo is None:
|
||||
# Match datetime.timestamp(): a naive datetime is treated as local time.
|
||||
dt = dt.astimezone()
|
||||
delta = dt - _EPOCH
|
||||
return Timestamp(
|
||||
seconds=delta.days * 86400 + delta.seconds,
|
||||
nanoseconds=delta.microseconds * 1000,
|
||||
)
|
||||
@@ -37,6 +37,17 @@ else:
|
||||
return []
|
||||
|
||||
|
||||
# frozendict is a builtin type added in Python 3.15 (PEP 814).
|
||||
if sys.version_info >= (3, 15):
|
||||
import builtins
|
||||
|
||||
frozendict = builtins.frozendict
|
||||
else:
|
||||
|
||||
class frozendict:
|
||||
pass
|
||||
|
||||
|
||||
from .exceptions import BufferFull, ExtraData, FormatError, OutOfData, StackError
|
||||
from .ext import ExtType, Timestamp
|
||||
|
||||
@@ -52,7 +63,7 @@ TYPE_RAW = 3
|
||||
TYPE_BIN = 4
|
||||
TYPE_EXT = 5
|
||||
|
||||
DEFAULT_RECURSE_LIMIT = 511
|
||||
DEFAULT_RECURSE_LIMIT = 1024
|
||||
|
||||
|
||||
def _check_type_strict(obj, t, type=type, tuple=tuple):
|
||||
@@ -137,7 +148,7 @@ class Unpacker:
|
||||
If specified, unpacker reads serialized data from it and `.feed()` is not usable.
|
||||
|
||||
:param int read_size:
|
||||
Used as `file_like.read(read_size)`. (default: `min(16*1024, max_buffer_size)`)
|
||||
Used as `file_like.read(read_size)`. Must be equal to or smaller than *max_buffer_size*.
|
||||
|
||||
:param bool use_list:
|
||||
If true, unpack msgpack array to Python list.
|
||||
@@ -328,7 +339,7 @@ class Unpacker:
|
||||
self._buf_checkpoint = 0
|
||||
|
||||
# Use extend here: INPLACE_ADD += doesn't reliably typecast memoryview in jython
|
||||
self._buffer.extend(view)
|
||||
self._buffer.extend(view if view.contiguous else view.tobytes())
|
||||
view.release()
|
||||
|
||||
def _consume(self):
|
||||
@@ -345,7 +356,8 @@ class Unpacker:
|
||||
def read_bytes(self, n):
|
||||
ret = self._read(n, raise_outofdata=False)
|
||||
self._consume()
|
||||
return ret
|
||||
# The C extension returns bytes. A bytearray slice cannot be a dict key.
|
||||
return bytes(ret)
|
||||
|
||||
def _read(self, n, raise_outofdata=True):
|
||||
# (int) -> bytearray
|
||||
@@ -490,10 +502,13 @@ class Unpacker:
|
||||
|
||||
if execute == EX_READ_ARRAY_HEADER:
|
||||
if typ != TYPE_ARRAY:
|
||||
# Leave the object unread, as the C extension does.
|
||||
self._buff_i = self._buf_checkpoint
|
||||
raise ValueError("Expected array")
|
||||
return n
|
||||
if execute == EX_READ_MAP_HEADER:
|
||||
if typ != TYPE_MAP:
|
||||
self._buff_i = self._buf_checkpoint
|
||||
raise ValueError("Expected map")
|
||||
return n
|
||||
# TODO should we eliminate the recursion?
|
||||
@@ -503,7 +518,7 @@ class Unpacker:
|
||||
# TODO check whether we need to call `list_hook`
|
||||
self._unpack(EX_SKIP)
|
||||
return
|
||||
ret = newlist_hint(n)
|
||||
ret = newlist_hint(min(n, 10000))
|
||||
for i in range(n):
|
||||
ret.append(self._unpack(EX_CONSTRUCT))
|
||||
if self._list_hook is not None:
|
||||
@@ -518,9 +533,15 @@ class Unpacker:
|
||||
self._unpack(EX_SKIP)
|
||||
return
|
||||
if self._object_pairs_hook is not None:
|
||||
ret = self._object_pairs_hook(
|
||||
(self._unpack(EX_CONSTRUCT), self._unpack(EX_CONSTRUCT)) for _ in range(n)
|
||||
)
|
||||
# Pass a list, as the C extension does, so the whole map is
|
||||
# consumed even if the hook does not iterate it.
|
||||
pairs = []
|
||||
for _ in range(n):
|
||||
key = self._unpack(EX_CONSTRUCT)
|
||||
if self._strict_map_key and type(key) not in (str, bytes):
|
||||
raise ValueError("%s is not allowed for map key" % str(type(key)))
|
||||
pairs.append((key, self._unpack(EX_CONSTRUCT)))
|
||||
ret = self._object_pairs_hook(pairs)
|
||||
else:
|
||||
ret = {}
|
||||
for _ in range(n):
|
||||
@@ -576,7 +597,10 @@ class Unpacker:
|
||||
next = __next__
|
||||
|
||||
def skip(self):
|
||||
self._unpack(EX_SKIP)
|
||||
try:
|
||||
self._unpack(EX_SKIP)
|
||||
except RecursionError:
|
||||
raise StackError
|
||||
self._consume()
|
||||
|
||||
def unpack(self):
|
||||
@@ -686,6 +710,7 @@ class Packer:
|
||||
list_types = list
|
||||
else:
|
||||
list_types = (list, tuple)
|
||||
dict_types = (dict, frozendict)
|
||||
while True:
|
||||
if nest_limit < 0:
|
||||
raise ValueError("recursion limit exceeded")
|
||||
@@ -779,7 +804,7 @@ class Packer:
|
||||
for i in range(n):
|
||||
self._pack(obj[i], nest_limit - 1)
|
||||
return
|
||||
if check(obj, dict):
|
||||
if check(obj, dict_types):
|
||||
return self._pack_map_pairs(len(obj), obj.items(), nest_limit - 1)
|
||||
|
||||
if self._datetime and check(obj, _DateTime) and obj.tzinfo is not None:
|
||||
@@ -816,6 +841,8 @@ class Packer:
|
||||
return ret
|
||||
|
||||
def pack_array_header(self, n):
|
||||
if n < 0:
|
||||
raise ValueError("array size must be non-negative")
|
||||
if n >= 2**32:
|
||||
raise ValueError
|
||||
self._pack_array_header(n)
|
||||
@@ -825,6 +852,8 @@ class Packer:
|
||||
return ret
|
||||
|
||||
def pack_map_header(self, n):
|
||||
if n < 0:
|
||||
raise ValueError("map size must be non-negative")
|
||||
if n >= 2**32:
|
||||
raise ValueError
|
||||
self._pack_map_header(n)
|
||||
@@ -861,6 +890,10 @@ class Packer:
|
||||
self._buffer.write(b"\xc9" + struct.pack(">I", L))
|
||||
self._buffer.write(struct.pack("B", typecode))
|
||||
self._buffer.write(data)
|
||||
if self._autoreset:
|
||||
ret = self._buffer.getvalue()
|
||||
self._buffer = BytesIO()
|
||||
return ret
|
||||
|
||||
def _pack_array_header(self, n):
|
||||
if n <= 0x0F:
|
||||
|
||||
@@ -6,7 +6,7 @@ __title__ = "packaging"
|
||||
__summary__ = "Core utilities for Python packages"
|
||||
__uri__ = "https://github.com/pypa/packaging"
|
||||
|
||||
__version__ = "26.0"
|
||||
__version__ = "26.3"
|
||||
|
||||
__author__ = "Donald Stufft and individual contributors"
|
||||
__email__ = "donald@stufft.io"
|
||||
|
||||
@@ -34,7 +34,7 @@ class EMachine(enum.IntEnum):
|
||||
S390 = 22
|
||||
Arm = 40
|
||||
X8664 = 62
|
||||
AArc64 = 183
|
||||
AArch64 = 183
|
||||
|
||||
|
||||
class ELFFile:
|
||||
@@ -57,8 +57,8 @@ class ELFFile:
|
||||
self.encoding = ident[5] # Data structure encoding (endianness).
|
||||
|
||||
try:
|
||||
# e_fmt: Format for program header.
|
||||
# p_fmt: Format for section header.
|
||||
# e_fmt: Format for the ELF header.
|
||||
# p_fmt: Format for a program header.
|
||||
# p_idx: Indexes to find p_type, p_offset, and p_filesz.
|
||||
e_fmt, self._p_fmt, self._p_idx = {
|
||||
(1, 1): ("<HHIIIIIHHH", "<IIIIIIII", (0, 1, 4)), # 32-bit LSB.
|
||||
@@ -81,8 +81,8 @@ class ELFFile:
|
||||
_,
|
||||
self.flags, # Processor-specific flags.
|
||||
_,
|
||||
self._e_phentsize, # Size of section.
|
||||
self._e_phnum, # Number of sections.
|
||||
self._e_phentsize, # Size of a program header entry.
|
||||
self._e_phnum, # Number of program headers.
|
||||
) = self._read(e_fmt)
|
||||
except struct.error as e:
|
||||
raise ELFInvalid("unable to parse machine and section information") from e
|
||||
|
||||
@@ -7,10 +7,14 @@ import os
|
||||
import re
|
||||
import sys
|
||||
import warnings
|
||||
from typing import Generator, Iterator, NamedTuple, Sequence
|
||||
from typing import TYPE_CHECKING, NamedTuple
|
||||
|
||||
from ._elffile import EIClass, EIData, ELFFile, EMachine
|
||||
|
||||
if TYPE_CHECKING:
|
||||
import types
|
||||
from collections.abc import Generator, Iterator, Sequence
|
||||
|
||||
EF_ARM_ABIMASK = 0xFF000000
|
||||
EF_ARM_ABI_VER5 = 0x05000000
|
||||
EF_ARM_ABI_FLOAT_HARD = 0x00000400
|
||||
@@ -26,8 +30,6 @@ _ALLOWED_ARCHS = {
|
||||
}
|
||||
|
||||
|
||||
# `os.PathLike` not a generic type until Python 3.9, so sticking with `str`
|
||||
# as the type for `path` until then.
|
||||
@contextlib.contextmanager
|
||||
def _parse_elf(path: str) -> Generator[ELFFile | None, None, None]:
|
||||
try:
|
||||
@@ -136,11 +138,11 @@ def _glibc_version_string_ctypes() -> str | None:
|
||||
# glibc.
|
||||
return None
|
||||
|
||||
# Call gnu_get_libc_version, which returns a string like "2.5"
|
||||
# Call gnu_get_libc_version, which returns a string like "2.5".
|
||||
gnu_get_libc_version.restype = ctypes.c_char_p
|
||||
version_str: str = gnu_get_libc_version()
|
||||
# py2 / py3 compatibility:
|
||||
if not isinstance(version_str, str):
|
||||
# A c_char_p restype comes back as bytes, so decode to text.
|
||||
version_str: str | bytes = gnu_get_libc_version()
|
||||
if isinstance(version_str, bytes):
|
||||
version_str = version_str.decode("ascii")
|
||||
|
||||
return version_str
|
||||
@@ -179,30 +181,44 @@ def _get_glibc_version() -> _GLibCVersion:
|
||||
|
||||
|
||||
# From PEP 513, PEP 600
|
||||
@functools.lru_cache(maxsize=1)
|
||||
def _get_manylinux_module() -> types.ModuleType | None:
|
||||
"""Return the ``_manylinux`` C extension module, or None if unavailable.
|
||||
|
||||
The result is cached for the lifetime of the process, since the presence
|
||||
of the module does not change while running.
|
||||
"""
|
||||
try:
|
||||
return __import__("_manylinux")
|
||||
except ImportError:
|
||||
return None
|
||||
|
||||
|
||||
def _is_compatible(arch: str, version: _GLibCVersion) -> bool:
|
||||
sys_glibc = _get_glibc_version()
|
||||
if sys_glibc < version:
|
||||
return False
|
||||
# Check for presence of _manylinux module.
|
||||
try:
|
||||
import _manylinux # noqa: PLC0415
|
||||
except ImportError:
|
||||
manylinux_mod = _get_manylinux_module()
|
||||
if manylinux_mod is None:
|
||||
return True
|
||||
if hasattr(_manylinux, "manylinux_compatible"):
|
||||
result = _manylinux.manylinux_compatible(version[0], version[1], arch)
|
||||
if hasattr(manylinux_mod, "manylinux_compatible"):
|
||||
result = manylinux_mod.manylinux_compatible(version[0], version[1], arch)
|
||||
if result is not None:
|
||||
return bool(result)
|
||||
return True
|
||||
if version == _GLibCVersion(2, 5) and hasattr(_manylinux, "manylinux1_compatible"):
|
||||
return bool(_manylinux.manylinux1_compatible)
|
||||
if version == _GLibCVersion(2, 5) and hasattr(
|
||||
manylinux_mod, "manylinux1_compatible"
|
||||
):
|
||||
return bool(manylinux_mod.manylinux1_compatible)
|
||||
if version == _GLibCVersion(2, 12) and hasattr(
|
||||
_manylinux, "manylinux2010_compatible"
|
||||
manylinux_mod, "manylinux2010_compatible"
|
||||
):
|
||||
return bool(_manylinux.manylinux2010_compatible)
|
||||
return bool(manylinux_mod.manylinux2010_compatible)
|
||||
if version == _GLibCVersion(2, 17) and hasattr(
|
||||
_manylinux, "manylinux2014_compatible"
|
||||
manylinux_mod, "manylinux2014_compatible"
|
||||
):
|
||||
return bool(_manylinux.manylinux2014_compatible)
|
||||
return bool(manylinux_mod.manylinux2014_compatible)
|
||||
return True
|
||||
|
||||
|
||||
|
||||
@@ -10,10 +10,13 @@ import functools
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
from typing import Iterator, NamedTuple, Sequence
|
||||
from typing import TYPE_CHECKING, NamedTuple
|
||||
|
||||
from ._elffile import ELFFile
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import Iterator, Sequence
|
||||
|
||||
|
||||
class _MuslVersion(NamedTuple):
|
||||
major: int
|
||||
@@ -81,5 +84,5 @@ if __name__ == "__main__": # pragma: no cover
|
||||
print("plat:", plat)
|
||||
print("musl:", _get_musl_version(sys.executable))
|
||||
print("tags:", end=" ")
|
||||
for t in platform_tags(re.sub(r"[.-]", "_", plat.split("-", 1)[-1])):
|
||||
for t in platform_tags([re.sub(r"[.-]", "_", plat.split("-", 1)[-1])]):
|
||||
print(t, end="\n ")
|
||||
@@ -7,9 +7,10 @@ the implementation.
|
||||
from __future__ import annotations
|
||||
|
||||
import ast
|
||||
from typing import List, Literal, NamedTuple, Sequence, Tuple, Union
|
||||
from collections.abc import Sequence
|
||||
from typing import Literal, NamedTuple, Union
|
||||
|
||||
from ._tokenizer import DEFAULT_RULES, Tokenizer
|
||||
from ._tokenizer import DEFAULT_RULES, ParserSyntaxError, Tokenizer
|
||||
|
||||
|
||||
class Node:
|
||||
@@ -27,6 +28,34 @@ class Node:
|
||||
def serialize(self) -> str:
|
||||
raise NotImplementedError
|
||||
|
||||
def __getstate__(self) -> str:
|
||||
# Return just the value string for compactness and stability.
|
||||
return self.value
|
||||
|
||||
def _restore_value(self, value: object) -> None:
|
||||
if not isinstance(value, str):
|
||||
raise TypeError(
|
||||
f"Cannot restore {self.__class__.__name__} value from {value!r}"
|
||||
)
|
||||
self.value = value
|
||||
|
||||
def __setstate__(self, state: object) -> None:
|
||||
if isinstance(state, str):
|
||||
# New format (26.2+): just the value string.
|
||||
self._restore_value(state)
|
||||
return
|
||||
if isinstance(state, tuple) and len(state) == 2:
|
||||
# Old format (packaging <= 26.0, __slots__): (None, {slot: value}).
|
||||
_, slot_dict = state
|
||||
if isinstance(slot_dict, dict) and "value" in slot_dict:
|
||||
self._restore_value(slot_dict["value"])
|
||||
return
|
||||
if isinstance(state, dict) and "value" in state:
|
||||
# Old format (packaging <= 25.0, no __slots__): plain __dict__.
|
||||
self._restore_value(state["value"])
|
||||
return
|
||||
raise TypeError(f"Cannot restore {self.__class__.__name__} from {state!r}")
|
||||
|
||||
|
||||
class Variable(Node):
|
||||
__slots__ = ()
|
||||
@@ -39,7 +68,14 @@ class Value(Node):
|
||||
__slots__ = ()
|
||||
|
||||
def serialize(self) -> str:
|
||||
return f'"{self}"'
|
||||
value = str(self)
|
||||
if '"' not in value:
|
||||
return f'"{value}"'
|
||||
if "'" not in value:
|
||||
return f"'{value}'"
|
||||
raise ValueError(
|
||||
"Cannot serialize marker value containing both quote characters"
|
||||
)
|
||||
|
||||
|
||||
class Op(Node):
|
||||
@@ -51,9 +87,9 @@ class Op(Node):
|
||||
|
||||
MarkerLogical = Literal["and", "or"]
|
||||
MarkerVar = Union[Variable, Value]
|
||||
MarkerItem = Tuple[MarkerVar, Op, MarkerVar]
|
||||
MarkerItem = tuple[MarkerVar, Op, MarkerVar]
|
||||
MarkerAtom = Union[MarkerItem, Sequence["MarkerAtom"]]
|
||||
MarkerList = List[Union["MarkerList", MarkerAtom, MarkerLogical]]
|
||||
MarkerList = list[Union["MarkerList", MarkerAtom, MarkerLogical]]
|
||||
|
||||
|
||||
class ParsedRequirement(NamedTuple):
|
||||
@@ -236,10 +272,19 @@ def _parse_version_many(tokenizer: Tokenizer) -> str:
|
||||
parsed_specifiers = ""
|
||||
while tokenizer.check("SPECIFIER"):
|
||||
span_start = tokenizer.position
|
||||
parsed_specifiers += tokenizer.read().text
|
||||
specifier = tokenizer.read().text
|
||||
parsed_specifiers += specifier
|
||||
if tokenizer.check("VERSION_PREFIX_TRAIL", peek=True):
|
||||
message = ".* suffix can only be used with `==` or `!=` operators"
|
||||
if specifier.startswith("!=") or (
|
||||
specifier.startswith("==") and not specifier.startswith("===")
|
||||
):
|
||||
message = (
|
||||
".* suffix cannot be used with pre-release, post-release, "
|
||||
"dev or local versions"
|
||||
)
|
||||
tokenizer.raise_syntax_error(
|
||||
".* suffix can only be used with `==` or `!=` operators",
|
||||
message,
|
||||
span_start=span_start,
|
||||
span_end=tokenizer.position + 1,
|
||||
)
|
||||
@@ -326,7 +371,15 @@ def _parse_marker_var(tokenizer: Tokenizer) -> MarkerVar: # noqa: RET503
|
||||
if tokenizer.check("VARIABLE"):
|
||||
return process_env_var(tokenizer.read().text.replace(".", "_"))
|
||||
elif tokenizer.check("QUOTED_STRING"):
|
||||
return process_python_str(tokenizer.read().text)
|
||||
token = tokenizer.read()
|
||||
try:
|
||||
return process_python_str(token.text)
|
||||
except (SyntaxError, ValueError) as exc:
|
||||
raise ParserSyntaxError(
|
||||
"Invalid quoted string",
|
||||
source=tokenizer.source,
|
||||
span=(token.position, token.position + len(token.text)),
|
||||
) from exc
|
||||
else:
|
||||
tokenizer.raise_syntax_error(
|
||||
message="Expected a marker variable or quoted string"
|
||||
|
||||
@@ -2,68 +2,32 @@
|
||||
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
|
||||
# for complete details.
|
||||
|
||||
import typing
|
||||
"""Backward-compatibility shim for unpickling Version objects serialized before
|
||||
packaging 26.1.
|
||||
|
||||
Old pickles reference ``packaging._structures.InfinityType`` and
|
||||
``packaging._structures.NegativeInfinityType``. This module provides minimal
|
||||
stand-in classes so that ``pickle.loads()`` can resolve those references.
|
||||
The deserialized objects are not used for comparisons — ``Version.__setstate__``
|
||||
discards the stale ``_key`` cache and recomputes it from the core version fields.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
|
||||
@typing.final
|
||||
class InfinityType:
|
||||
__slots__ = ()
|
||||
"""Stand-in for the removed ``InfinityType`` used in old comparison keys."""
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return "Infinity"
|
||||
|
||||
def __hash__(self) -> int:
|
||||
return hash(repr(self))
|
||||
|
||||
def __lt__(self, other: object) -> bool:
|
||||
return False
|
||||
|
||||
def __le__(self, other: object) -> bool:
|
||||
return False
|
||||
|
||||
def __eq__(self, other: object) -> bool:
|
||||
return isinstance(other, self.__class__)
|
||||
|
||||
def __gt__(self, other: object) -> bool:
|
||||
return True
|
||||
|
||||
def __ge__(self, other: object) -> bool:
|
||||
return True
|
||||
|
||||
def __neg__(self: object) -> "NegativeInfinityType":
|
||||
return NegativeInfinity
|
||||
|
||||
|
||||
Infinity = InfinityType()
|
||||
|
||||
|
||||
@typing.final
|
||||
class NegativeInfinityType:
|
||||
__slots__ = ()
|
||||
"""Stand-in for the removed ``NegativeInfinityType`` used in old comparison keys."""
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return "-Infinity"
|
||||
|
||||
def __hash__(self) -> int:
|
||||
return hash(repr(self))
|
||||
|
||||
def __lt__(self, other: object) -> bool:
|
||||
return True
|
||||
|
||||
def __le__(self, other: object) -> bool:
|
||||
return True
|
||||
|
||||
def __eq__(self, other: object) -> bool:
|
||||
return isinstance(other, self.__class__)
|
||||
|
||||
def __gt__(self, other: object) -> bool:
|
||||
return False
|
||||
|
||||
def __ge__(self, other: object) -> bool:
|
||||
return False
|
||||
|
||||
def __neg__(self: object) -> InfinityType:
|
||||
return Infinity
|
||||
|
||||
|
||||
Infinity = InfinityType()
|
||||
NegativeInfinity = NegativeInfinityType()
|
||||
@@ -3,13 +3,18 @@ from __future__ import annotations
|
||||
import contextlib
|
||||
import re
|
||||
from dataclasses import dataclass
|
||||
from typing import Generator, Mapping, NoReturn
|
||||
from typing import TYPE_CHECKING, NoReturn
|
||||
|
||||
from .specifiers import Specifier
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import Generator, Mapping
|
||||
|
||||
|
||||
@dataclass
|
||||
class Token:
|
||||
__slots__ = ("name", "position", "text")
|
||||
|
||||
name: str
|
||||
text: str
|
||||
position: int
|
||||
@@ -75,7 +80,7 @@ DEFAULT_RULES: dict[str, re.Pattern[str]] = {
|
||||
re.VERBOSE,
|
||||
),
|
||||
"SPECIFIER": re.compile(
|
||||
Specifier._operator_regex_str + Specifier._version_regex_str,
|
||||
Specifier._specifier_regex_str,
|
||||
re.VERBOSE | re.IGNORECASE,
|
||||
),
|
||||
"AT": re.compile(r"\@"),
|
||||
@@ -84,7 +89,7 @@ DEFAULT_RULES: dict[str, re.Pattern[str]] = {
|
||||
"VERSION_PREFIX_TRAIL": re.compile(r"\.\*"),
|
||||
"VERSION_LOCAL_LABEL_TRAIL": re.compile(r"\+[a-z0-9]+(?:[-_\.][a-z0-9]+)*"),
|
||||
"WS": re.compile(r"[ \t]+"),
|
||||
"END": re.compile(r"$"),
|
||||
"END": re.compile(r"\Z"),
|
||||
}
|
||||
|
||||
|
||||
@@ -95,6 +100,8 @@ class Tokenizer:
|
||||
matches.
|
||||
"""
|
||||
|
||||
__slots__ = ("next_token", "position", "rules", "source")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
source: str,
|
||||
@@ -135,7 +142,7 @@ class Tokenizer:
|
||||
def expect(self, name: str, *, expected: str) -> Token:
|
||||
"""Expect a certain token name next, failing with a syntax error otherwise.
|
||||
|
||||
The token is *not* read.
|
||||
The token is read and returned.
|
||||
"""
|
||||
if not self.check(name):
|
||||
raise self.raise_syntax_error(f"Expected {expected}")
|
||||
|
||||
@@ -42,24 +42,63 @@ __all__ = [
|
||||
"canonicalize_license_expression",
|
||||
]
|
||||
|
||||
license_ref_allowed = re.compile("^[A-Za-z0-9.-]*$")
|
||||
|
||||
# Simple __dir__ implementation since there are no public submodules
|
||||
def __dir__() -> list[str]:
|
||||
return __all__
|
||||
|
||||
|
||||
license_ref_allowed = re.compile("^[A-Za-z0-9.-]+$")
|
||||
|
||||
NormalizedLicenseExpression = NewType("NormalizedLicenseExpression", str)
|
||||
"""
|
||||
A :class:`typing.NewType` of :class:`str`, representing a normalized
|
||||
License-Expression.
|
||||
"""
|
||||
|
||||
|
||||
class InvalidLicenseExpression(ValueError):
|
||||
"""Raised when a license-expression string is invalid
|
||||
|
||||
>>> from packaging.licenses import canonicalize_license_expression
|
||||
>>> canonicalize_license_expression("invalid")
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
packaging.licenses.InvalidLicenseExpression: Invalid license expression: 'invalid'
|
||||
packaging.licenses.InvalidLicenseExpression: Unknown license: 'invalid'
|
||||
"""
|
||||
|
||||
|
||||
def canonicalize_license_expression(
|
||||
raw_license_expression: str,
|
||||
) -> NormalizedLicenseExpression:
|
||||
"""
|
||||
This function takes a valid License-Expression, and returns the normalized
|
||||
form of it.
|
||||
|
||||
The return type is typed as :class:`NormalizedLicenseExpression`. This
|
||||
allows type checkers to help require that a string has passed through this
|
||||
function before use.
|
||||
|
||||
:param str raw_license_expression: The License-Expression to canonicalize.
|
||||
:raises InvalidLicenseExpression: If the License-Expression is invalid due to an
|
||||
invalid/unknown license identifier or invalid syntax.
|
||||
|
||||
.. doctest::
|
||||
|
||||
>>> from packaging.licenses import canonicalize_license_expression
|
||||
>>> canonicalize_license_expression("mit")
|
||||
'MIT'
|
||||
>>> canonicalize_license_expression("mit and (apache-2.0 or bsd-2-clause)")
|
||||
'MIT AND (Apache-2.0 OR BSD-2-Clause)'
|
||||
>>> canonicalize_license_expression("(mit")
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
InvalidLicenseExpression: Invalid license expression: '(mit'
|
||||
>>> canonicalize_license_expression("Use-it-after-midnight")
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
InvalidLicenseExpression: Unknown license: 'Use-it-after-midnight'
|
||||
"""
|
||||
if not raw_license_expression:
|
||||
message = f"Invalid license expression: {raw_license_expression!r}"
|
||||
raise InvalidLicenseExpression(message)
|
||||
@@ -109,9 +148,18 @@ def canonicalize_license_expression(
|
||||
|
||||
# Take a final pass to check for unknown licenses/exceptions.
|
||||
normalized_tokens = []
|
||||
for token in tokens:
|
||||
last_license_start = False
|
||||
for index, token in enumerate(tokens):
|
||||
if token in {"or", "and", "with", "(", ")"}:
|
||||
if token == "with" and (
|
||||
not last_license_start
|
||||
or index + 1 == len(tokens)
|
||||
or tokens[index + 1] in {"or", "and", "with", "(", ")"}
|
||||
):
|
||||
message = f"Invalid license expression: {raw_license_expression!r}"
|
||||
raise InvalidLicenseExpression(message)
|
||||
normalized_tokens.append(token.upper())
|
||||
last_license_start = False
|
||||
continue
|
||||
|
||||
if normalized_tokens and normalized_tokens[-1] == "WITH":
|
||||
@@ -120,6 +168,7 @@ def canonicalize_license_expression(
|
||||
raise InvalidLicenseExpression(message)
|
||||
|
||||
normalized_tokens.append(EXCEPTIONS[token]["id"])
|
||||
last_license_start = False
|
||||
else:
|
||||
if token.endswith("+"):
|
||||
final_token = token[:-1]
|
||||
@@ -129,15 +178,17 @@ def canonicalize_license_expression(
|
||||
suffix = ""
|
||||
|
||||
if final_token.startswith("licenseref-"):
|
||||
if not license_ref_allowed.match(final_token):
|
||||
message = f"Invalid licenseref: {final_token!r}"
|
||||
license_ref_id = final_token[len("licenseref-") :]
|
||||
if suffix or not license_ref_allowed.match(license_ref_id):
|
||||
message = f"Invalid licenseref: {token!r}"
|
||||
raise InvalidLicenseExpression(message)
|
||||
normalized_tokens.append(license_refs[final_token] + suffix)
|
||||
normalized_tokens.append(license_refs[final_token])
|
||||
else:
|
||||
if final_token not in LICENSES:
|
||||
message = f"Unknown license: {final_token!r}"
|
||||
raise InvalidLicenseExpression(message)
|
||||
normalized_tokens.append(LICENSES[final_token]["id"] + suffix)
|
||||
last_license_start = True
|
||||
|
||||
normalized_expression = " ".join(normalized_tokens)
|
||||
|
||||
|
||||
@@ -4,11 +4,13 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import functools
|
||||
import operator
|
||||
import os
|
||||
import platform
|
||||
import sys
|
||||
from typing import AbstractSet, Callable, Literal, Mapping, TypedDict, Union, cast
|
||||
from collections.abc import Set as AbstractSet
|
||||
from typing import TYPE_CHECKING, Callable, Literal, TypedDict, Union, cast
|
||||
|
||||
from ._parser import MarkerAtom, MarkerList, Op, Value, Variable
|
||||
from ._parser import parse_marker as _parse_marker
|
||||
@@ -16,6 +18,9 @@ from ._tokenizer import ParserSyntaxError
|
||||
from .specifiers import InvalidSpecifier, Specifier
|
||||
from .utils import canonicalize_name
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import Mapping
|
||||
|
||||
__all__ = [
|
||||
"Environment",
|
||||
"EvaluateContext",
|
||||
@@ -26,8 +31,24 @@ __all__ = [
|
||||
"default_environment",
|
||||
]
|
||||
|
||||
|
||||
def __dir__() -> list[str]:
|
||||
return __all__
|
||||
|
||||
|
||||
Operator = Callable[[str, Union[str, AbstractSet[str]]], bool]
|
||||
EvaluateContext = Literal["metadata", "lock_file", "requirement"]
|
||||
"""A ``typing.Literal`` enumerating valid marker evaluation contexts.
|
||||
|
||||
Valid values for the ``context`` passed to :meth:`Marker.evaluate` are:
|
||||
|
||||
* ``"metadata"`` (for core metadata; default)
|
||||
* ``"lock_file"`` (for lock files)
|
||||
* ``"requirement"`` (i.e. all other situations)
|
||||
|
||||
.. versionadded:: 25.0
|
||||
"""
|
||||
|
||||
MARKERS_ALLOWING_SET = {"extras", "dependency_groups"}
|
||||
MARKERS_REQUIRING_VERSION = {
|
||||
"implementation_version",
|
||||
@@ -38,25 +59,41 @@ MARKERS_REQUIRING_VERSION = {
|
||||
|
||||
|
||||
class InvalidMarker(ValueError):
|
||||
"""
|
||||
An invalid marker was found, users should refer to PEP 508.
|
||||
"""Raised when attempting to create a :class:`Marker` from invalid input.
|
||||
|
||||
This error indicates that the given marker string does not conform to the
|
||||
:ref:`specification of dependency specifiers <pypug:dependency-specifiers>`.
|
||||
"""
|
||||
|
||||
|
||||
class UndefinedComparison(ValueError):
|
||||
"""
|
||||
An invalid operation was attempted on a value that doesn't support it.
|
||||
"""Raised when evaluating an unsupported marker comparison.
|
||||
|
||||
This can happen when marker values are compared as versions but do not
|
||||
conform to the :ref:`specification of version specifiers
|
||||
<pypug:version-specifiers>`.
|
||||
"""
|
||||
|
||||
|
||||
class UndefinedEnvironmentName(ValueError):
|
||||
"""
|
||||
A name was attempted to be used that does not exist inside of the
|
||||
environment.
|
||||
class UndefinedEnvironmentName(KeyError):
|
||||
"""Raised when evaluating a marker that references a missing environment key.
|
||||
|
||||
Subclasses :class:`KeyError` so that code catching the bare ``KeyError`` that
|
||||
a missing environment lookup historically produced keeps working.
|
||||
|
||||
.. versionchanged:: 26.3
|
||||
Now subclasses :class:`KeyError` (was :class:`ValueError`) and is raised by
|
||||
:meth:`Marker.evaluate` for missing environment keys, where a bare
|
||||
``KeyError`` was raised before.
|
||||
"""
|
||||
|
||||
|
||||
class Environment(TypedDict):
|
||||
"""
|
||||
A dictionary that represents a Python environment as captured by
|
||||
:func:`default_environment`. All fields are required.
|
||||
"""
|
||||
|
||||
implementation_name: str
|
||||
"""The implementation's identifier, e.g. ``'cpython'``."""
|
||||
|
||||
@@ -131,16 +168,30 @@ class Environment(TypedDict):
|
||||
def _normalize_extras(
|
||||
result: MarkerList | MarkerAtom | str,
|
||||
) -> MarkerList | MarkerAtom | str:
|
||||
if isinstance(result, list):
|
||||
return [_normalize_extras(r) for r in result]
|
||||
if not isinstance(result, tuple):
|
||||
return result
|
||||
|
||||
lhs, op, rhs = result
|
||||
if isinstance(lhs, Variable) and lhs.value == "extra":
|
||||
if isinstance(lhs, Variable) and lhs.value == "extra" and isinstance(rhs, Value):
|
||||
normalized_extra = canonicalize_name(rhs.value)
|
||||
rhs = Value(normalized_extra)
|
||||
elif isinstance(rhs, Variable) and rhs.value == "extra":
|
||||
elif isinstance(rhs, Variable) and rhs.value == "extra" and isinstance(lhs, Value):
|
||||
normalized_extra = canonicalize_name(lhs.value)
|
||||
lhs = Value(normalized_extra)
|
||||
elif (
|
||||
isinstance(rhs, Variable)
|
||||
and rhs.value in MARKERS_ALLOWING_SET
|
||||
and isinstance(lhs, Value)
|
||||
):
|
||||
# PEP 685 (extras) / PEP 735 (dependency_groups): the set-valued membership
|
||||
# literal must also be normalized. evaluate() already canonicalizes both
|
||||
# operands for these keys (see _normalize), so normalizing the literal at
|
||||
# parse time keeps __str__/__eq__/__hash__ consistent with evaluate() -- e.g.
|
||||
# Marker('"Foo" in extras') and Marker('"foo" in extras') must compare and
|
||||
# hash equal (the membership variable is always the right-hand operand).
|
||||
lhs = Value(canonicalize_name(lhs.value))
|
||||
return lhs, op, rhs
|
||||
|
||||
|
||||
@@ -157,16 +208,14 @@ def _format_marker(
|
||||
) -> str:
|
||||
assert isinstance(marker, (list, tuple, str))
|
||||
|
||||
# Sometimes we have a structure like [[...]] which is a single item list
|
||||
# where the single item is itself it's own list. In that case we want skip
|
||||
# the rest of this function so that we don't get extraneous () on the
|
||||
# outside.
|
||||
# Unwrap a redundant [[...]] wrapper, but keep the nesting context so a
|
||||
# nested group keeps the parentheses its and/or precedence needs.
|
||||
if (
|
||||
isinstance(marker, list)
|
||||
and len(marker) == 1
|
||||
and isinstance(marker[0], (list, tuple))
|
||||
):
|
||||
return _format_marker(marker[0])
|
||||
return _format_marker(marker[0], first=first)
|
||||
|
||||
if isinstance(marker, list):
|
||||
inner = (_format_marker(m, first=False) for m in marker)
|
||||
@@ -230,6 +279,15 @@ def _normalize(
|
||||
return lhs, rhs
|
||||
|
||||
|
||||
def _lookup_environment(
|
||||
environment: dict[str, str | AbstractSet[str]], key: str
|
||||
) -> str | AbstractSet[str]:
|
||||
try:
|
||||
return environment[key]
|
||||
except KeyError:
|
||||
raise UndefinedEnvironmentName(key) from None
|
||||
|
||||
|
||||
def _evaluate_markers(
|
||||
markers: MarkerList, environment: dict[str, str | AbstractSet[str]]
|
||||
) -> bool:
|
||||
@@ -243,14 +301,20 @@ def _evaluate_markers(
|
||||
|
||||
if isinstance(lhs, Variable):
|
||||
environment_key = lhs.value
|
||||
lhs_value = environment[environment_key]
|
||||
lhs_value = _lookup_environment(environment, environment_key)
|
||||
rhs_value = rhs.value
|
||||
else:
|
||||
lhs_value = lhs.value
|
||||
environment_key = rhs.value
|
||||
rhs_value = environment[environment_key]
|
||||
rhs_value = _lookup_environment(environment, environment_key)
|
||||
|
||||
assert isinstance(lhs_value, str), "lhs must be a string"
|
||||
if not isinstance(lhs_value, str):
|
||||
raise UndefinedComparison(
|
||||
f"Set-valued marker {environment_key!r} can only be used "
|
||||
f'with the membership form (e.g. "<name>" in '
|
||||
f"{environment_key}); it cannot appear on the left-hand "
|
||||
f"side of {op.serialize()!r}."
|
||||
)
|
||||
lhs_value, rhs_value = _normalize(lhs_value, rhs_value, key=environment_key)
|
||||
groups[-1].append(_eval_op(lhs_value, op, rhs_value, key=environment_key))
|
||||
elif marker == "or":
|
||||
@@ -263,7 +327,7 @@ def _evaluate_markers(
|
||||
return any(all(item) for item in groups)
|
||||
|
||||
|
||||
def format_full_version(info: sys._version_info) -> str:
|
||||
def _format_full_version(info: sys._version_info) -> str:
|
||||
version = f"{info.major}.{info.minor}.{info.micro}"
|
||||
kind = info.releaselevel
|
||||
if kind != "final":
|
||||
@@ -271,8 +335,16 @@ def format_full_version(info: sys._version_info) -> str:
|
||||
return version
|
||||
|
||||
|
||||
def default_environment() -> Environment:
|
||||
iver = format_full_version(sys.implementation.version)
|
||||
@functools.cache
|
||||
def _cached_default_environment() -> Environment:
|
||||
"""Build the default marker environment for the current Python process.
|
||||
|
||||
The values are derived from process-constant data (the running interpreter
|
||||
and the host platform), so this is cached and built only once. The result is
|
||||
shared between callers and must never be mutated; :func:`default_environment`
|
||||
returns a fresh copy.
|
||||
"""
|
||||
iver = _format_full_version(sys.implementation.version)
|
||||
implementation_name = sys.implementation.name
|
||||
return {
|
||||
"implementation_name": implementation_name,
|
||||
@@ -289,7 +361,44 @@ def default_environment() -> Environment:
|
||||
}
|
||||
|
||||
|
||||
def default_environment() -> Environment:
|
||||
"""Return the default marker environment for the current Python process.
|
||||
|
||||
This is the base environment used by :meth:`Marker.evaluate`. A fresh copy
|
||||
is returned on every call so callers may freely mutate the result; a shallow
|
||||
copy suffices because all values are immutable strings.
|
||||
|
||||
.. versionchanged:: 26.3
|
||||
The environment is computed once per process and cached, since it is
|
||||
derived from process-constant data. Patching ``platform``/``sys``/``os``
|
||||
after the first call has no effect; pass an explicit ``environment`` to
|
||||
:meth:`Marker.evaluate` to evaluate against different values.
|
||||
"""
|
||||
return cast("Environment", dict(_cached_default_environment()))
|
||||
|
||||
|
||||
class Marker:
|
||||
"""Represents a parsed dependency marker expression.
|
||||
|
||||
Marker expressions are parsed according to the
|
||||
:ref:`specification of dependency specifiers <pypug:dependency-specifiers>`.
|
||||
|
||||
:param marker: The string representation of a marker expression.
|
||||
:raises InvalidMarker: If ``marker`` cannot be parsed.
|
||||
|
||||
Instances are safe to serialize with :mod:`pickle`. They use a stable
|
||||
format so the same pickle can be loaded in future packaging releases.
|
||||
|
||||
.. versionchanged:: 26.2
|
||||
|
||||
Added a stable pickle format. Pickles created with packaging 26.2+ can
|
||||
be unpickled with future releases. Backward compatibility with pickles
|
||||
from pip._vendor.packaging < 26.2 is supported but may be removed in a future
|
||||
release.
|
||||
"""
|
||||
|
||||
__slots__ = ("_markers",)
|
||||
|
||||
def __init__(self, marker: str) -> None:
|
||||
# Note: We create a Marker object without calling this constructor in
|
||||
# packaging.requirements.Requirement. If any additional logic is
|
||||
@@ -320,11 +429,21 @@ class Marker:
|
||||
except ParserSyntaxError as e:
|
||||
raise InvalidMarker(str(e)) from e
|
||||
|
||||
@classmethod
|
||||
def _from_markers(cls, markers: MarkerList) -> Marker:
|
||||
"""Create a Marker instance from a pre-parsed marker tree.
|
||||
|
||||
This avoids re-parsing serialised marker strings when combining markers.
|
||||
"""
|
||||
new = cls.__new__(cls)
|
||||
new._markers = markers
|
||||
return new
|
||||
|
||||
def __str__(self) -> str:
|
||||
return _format_marker(self._markers)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<{self.__class__.__name__}('{self}')>"
|
||||
return f"<{self.__class__.__name__}({str(self)!r})>"
|
||||
|
||||
def __hash__(self) -> int:
|
||||
return hash(str(self))
|
||||
@@ -335,6 +454,53 @@ class Marker:
|
||||
|
||||
return str(self) == str(other)
|
||||
|
||||
def __getstate__(self) -> str:
|
||||
# Return the marker expression string for compactness and stability.
|
||||
# Internal Node objects are excluded; the string is re-parsed on load.
|
||||
return str(self)
|
||||
|
||||
def __setstate__(self, state: object) -> None:
|
||||
if isinstance(state, str):
|
||||
# New format (26.2+): just the marker expression string.
|
||||
try:
|
||||
self._markers = _normalize_extra_values(_parse_marker(state))
|
||||
except ParserSyntaxError as exc:
|
||||
raise TypeError(f"Cannot restore Marker from {state!r}") from exc
|
||||
return
|
||||
if isinstance(state, dict) and "_markers" in state:
|
||||
# Old format (packaging <= 26.1, no __slots__): plain __dict__.
|
||||
markers = state["_markers"]
|
||||
if isinstance(markers, list):
|
||||
self._markers = markers
|
||||
return
|
||||
if isinstance(state, tuple) and len(state) == 2:
|
||||
# Old format (packaging <= 26.1, __slots__): (None, {slot: value}).
|
||||
_, slot_dict = state
|
||||
if isinstance(slot_dict, dict) and "_markers" in slot_dict:
|
||||
markers = slot_dict["_markers"]
|
||||
if isinstance(markers, list):
|
||||
self._markers = markers
|
||||
return
|
||||
raise TypeError(f"Cannot restore Marker from {state!r}")
|
||||
|
||||
def __and__(self, other: Marker) -> Marker:
|
||||
"""Combine this marker with another using ``and``.
|
||||
|
||||
.. versionadded:: 26.1
|
||||
"""
|
||||
if not isinstance(other, Marker):
|
||||
return NotImplemented
|
||||
return self._from_markers([self._markers, "and", other._markers])
|
||||
|
||||
def __or__(self, other: Marker) -> Marker:
|
||||
"""Combine this marker with another using ``or``.
|
||||
|
||||
.. versionadded:: 26.1
|
||||
"""
|
||||
if not isinstance(other, Marker):
|
||||
return NotImplemented
|
||||
return self._from_markers([self._markers, "or", other._markers])
|
||||
|
||||
def evaluate(
|
||||
self,
|
||||
environment: Mapping[str, str | AbstractSet[str]] | None = None,
|
||||
@@ -342,27 +508,40 @@ class Marker:
|
||||
) -> bool:
|
||||
"""Evaluate a marker.
|
||||
|
||||
Return the boolean from evaluating the given marker against the
|
||||
environment. environment is an optional argument to override all or
|
||||
part of the determined environment. The *context* parameter specifies what
|
||||
context the markers are being evaluated for, which influences what markers
|
||||
are considered valid. Acceptable values are "metadata" (for core metadata;
|
||||
default), "lock_file", and "requirement" (i.e. all other situations).
|
||||
Return the boolean from evaluating this marker against the environment.
|
||||
The environment is determined from the current Python process unless
|
||||
passed in explicitly.
|
||||
|
||||
The environment is determined from the current Python process.
|
||||
:param environment: Mapping containing keys and values to override the
|
||||
detected environment.
|
||||
:param EvaluateContext context: The context in which the marker is
|
||||
evaluated, which influences what marker names are considered valid.
|
||||
Accepted values are ``"metadata"`` (for core metadata; default),
|
||||
``"lock_file"``, and ``"requirement"`` (i.e. all other situations).
|
||||
:raises UndefinedComparison: If the marker uses a comparison on values
|
||||
that are not valid versions per the :ref:`specification of version
|
||||
specifiers <pypug:version-specifiers>`.
|
||||
:raises UndefinedEnvironmentName: If the marker references a value that
|
||||
is missing from the evaluation environment.
|
||||
:returns: ``True`` if the marker matches, otherwise ``False``.
|
||||
|
||||
.. versionchanged:: 25.0
|
||||
Added the ``context`` parameter, which influences which marker names
|
||||
are considered valid.
|
||||
"""
|
||||
current_environment = cast(
|
||||
"dict[str, str | AbstractSet[str]]", default_environment()
|
||||
)
|
||||
if context == "lock_file":
|
||||
current_environment.update(
|
||||
extras=frozenset(), dependency_groups=frozenset()
|
||||
)
|
||||
current_environment |= {
|
||||
"extras": frozenset(),
|
||||
"dependency_groups": frozenset(),
|
||||
}
|
||||
elif context == "metadata":
|
||||
current_environment["extra"] = ""
|
||||
|
||||
if environment is not None:
|
||||
current_environment.update(environment)
|
||||
current_environment |= environment
|
||||
if "extra" in current_environment:
|
||||
# The API used to allow setting extra to None. We need to handle
|
||||
# this case for backwards compatibility. Also skip running
|
||||
@@ -375,6 +554,16 @@ class Marker:
|
||||
)
|
||||
|
||||
|
||||
def _pep440_python_full_version(python_full_version: str) -> str:
|
||||
"""
|
||||
Work around platform.python_version() returning something that is not PEP 440
|
||||
compliant for non-tagged Python builds.
|
||||
"""
|
||||
if python_full_version.endswith("+"):
|
||||
return f"{python_full_version}local"
|
||||
return python_full_version
|
||||
|
||||
|
||||
def _repair_python_full_version(
|
||||
env: dict[str, str | AbstractSet[str]],
|
||||
) -> dict[str, str | AbstractSet[str]]:
|
||||
@@ -383,6 +572,5 @@ def _repair_python_full_version(
|
||||
compliant for non-tagged Python builds.
|
||||
"""
|
||||
python_full_version = cast("str", env["python_full_version"])
|
||||
if python_full_version.endswith("+"):
|
||||
env["python_full_version"] = f"{python_full_version}local"
|
||||
env["python_full_version"] = _pep440_python_full_version(python_full_version)
|
||||
return env
|
||||
@@ -1,13 +1,12 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import email.feedparser
|
||||
import email.header
|
||||
import email.message
|
||||
import email.parser
|
||||
import email.policy
|
||||
import keyword
|
||||
import pathlib
|
||||
import sys
|
||||
import re
|
||||
import typing
|
||||
from typing import (
|
||||
Any,
|
||||
@@ -20,37 +19,35 @@ from typing import (
|
||||
|
||||
from . import licenses, requirements, specifiers, utils
|
||||
from . import version as version_module
|
||||
from .errors import ExceptionGroup, _ErrorCollector
|
||||
|
||||
if typing.TYPE_CHECKING:
|
||||
from .licenses import NormalizedLicenseExpression
|
||||
from .version import Version
|
||||
|
||||
T = typing.TypeVar("T")
|
||||
|
||||
|
||||
if sys.version_info >= (3, 11): # pragma: no cover
|
||||
ExceptionGroup = ExceptionGroup # noqa: F821
|
||||
else: # pragma: no cover
|
||||
__all__ = [
|
||||
"ExceptionGroup", # Keep this for a bit (makes mypy happy w/ 26.0 compat)
|
||||
"InvalidMetadata",
|
||||
"Metadata",
|
||||
"RFC822Message",
|
||||
"RFC822Policy",
|
||||
"RawMetadata",
|
||||
"parse_email",
|
||||
]
|
||||
|
||||
class ExceptionGroup(Exception):
|
||||
"""A minimal implementation of :external:exc:`ExceptionGroup` from Python 3.11.
|
||||
|
||||
If :external:exc:`ExceptionGroup` is already defined by Python itself,
|
||||
that version is used instead.
|
||||
"""
|
||||
|
||||
message: str
|
||||
exceptions: list[Exception]
|
||||
|
||||
def __init__(self, message: str, exceptions: list[Exception]) -> None:
|
||||
self.message = message
|
||||
self.exceptions = exceptions
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"{self.__class__.__name__}({self.message!r}, {self.exceptions!r})"
|
||||
def __dir__() -> list[str]:
|
||||
return __all__
|
||||
|
||||
|
||||
class InvalidMetadata(ValueError):
|
||||
"""A metadata field contains invalid data."""
|
||||
"""A metadata field contains invalid data.
|
||||
|
||||
.. versionadded:: 23.2
|
||||
"""
|
||||
|
||||
field: str
|
||||
"""The name of the field that contains invalid data."""
|
||||
@@ -59,6 +56,10 @@ class InvalidMetadata(ValueError):
|
||||
self.field = field
|
||||
super().__init__(message)
|
||||
|
||||
# Support pickling; ``args`` does not match ``__init__``'s signature.
|
||||
def __reduce__(self) -> tuple[type[InvalidMetadata], tuple[str, str]]:
|
||||
return (self.__class__, (self.field, self.args[0]))
|
||||
|
||||
|
||||
# The RawMetadata class attempts to make as few assumptions about the underlying
|
||||
# serialization formats as possible. The idea is that as long as a serialization
|
||||
@@ -76,8 +77,8 @@ class RawMetadata(TypedDict, total=False):
|
||||
|
||||
Core metadata fields that can be specified multiple times are stored as a
|
||||
list or dict depending on which is appropriate for the field. Any fields
|
||||
which hold multiple values in a single field are stored as a list.
|
||||
|
||||
which hold multiple values in a single field are stored as a list. All fields
|
||||
are considered optional.
|
||||
"""
|
||||
|
||||
# Metadata 1.0 - PEP 241
|
||||
@@ -133,11 +134,17 @@ class RawMetadata(TypedDict, total=False):
|
||||
|
||||
# Metadata 2.4 - PEP 639
|
||||
license_expression: str
|
||||
""".. versionadded:: 24.2"""
|
||||
license_files: list[str]
|
||||
""".. versionadded:: 24.2"""
|
||||
|
||||
# Metadata 2.5 - PEP 794
|
||||
import_names: list[str]
|
||||
""".. versionadded:: 26.0"""
|
||||
import_namespaces: list[str]
|
||||
""".. versionadded:: 26.0"""
|
||||
|
||||
# Metadata 2.6 - PEP 808 (no new fields, behavior change for Dynamic)
|
||||
|
||||
|
||||
# 'keywords' is special as it's a string in the core metadata spec, but we
|
||||
@@ -233,13 +240,19 @@ def _get_payload(msg: email.message.Message, source: bytes | str) -> str:
|
||||
# and we don't need to deal with it.
|
||||
if isinstance(source, str):
|
||||
payload = msg.get_payload()
|
||||
assert isinstance(payload, str)
|
||||
# A multipart payload makes get_payload() return a list of messages
|
||||
# rather than a str; route it to ``unparsed``.
|
||||
if not isinstance(payload, str):
|
||||
raise ValueError("payload is not a string") # noqa: TRY004
|
||||
return payload
|
||||
# If our source is a bytes, then we're managing the encoding and we need
|
||||
# to deal with it.
|
||||
else:
|
||||
bpayload = msg.get_payload(decode=True)
|
||||
assert isinstance(bpayload, bytes)
|
||||
# A multipart payload makes get_payload(decode=True) return None;
|
||||
# route it to ``unparsed``.
|
||||
if not isinstance(bpayload, bytes):
|
||||
raise ValueError("payload in an invalid encoding") # noqa: TRY004
|
||||
try:
|
||||
return bpayload.decode("utf8", "strict")
|
||||
except UnicodeDecodeError as exc:
|
||||
@@ -295,11 +308,19 @@ _EMAIL_TO_RAW_MAPPING = {
|
||||
_RAW_TO_EMAIL_MAPPING = {raw: email for email, raw in _EMAIL_TO_RAW_MAPPING.items()}
|
||||
|
||||
|
||||
# A bare "\r" makes the email generator raise ``HeaderWriteError``, and on
|
||||
# CPython releases without the CVE-2024-6923 fix any ``str.splitlines``
|
||||
# boundary ends the header line, so fold all of them, not just "\n".
|
||||
_LINE_BOUNDARY_RE = re.compile(r"\r\n|[\n\r\v\f\x1c\x1d\x1e\x85\u2028\u2029]")
|
||||
|
||||
|
||||
# This class is for writing RFC822 messages
|
||||
class RFC822Policy(email.policy.EmailPolicy):
|
||||
"""
|
||||
This is :class:`email.policy.EmailPolicy`, but with a simple ``header_store_parse``
|
||||
implementation that handles multi-line values, and some nice defaults.
|
||||
|
||||
.. versionadded:: 26.0
|
||||
"""
|
||||
|
||||
utf8 = True
|
||||
@@ -308,7 +329,7 @@ class RFC822Policy(email.policy.EmailPolicy):
|
||||
|
||||
def header_store_parse(self, name: str, value: str) -> tuple[str, str]:
|
||||
size = len(name) + 2
|
||||
value = value.replace("\n", "\n" + " " * size)
|
||||
value = _LINE_BOUNDARY_RE.sub("\n" + " " * size, value)
|
||||
return (name, value)
|
||||
|
||||
|
||||
@@ -318,6 +339,8 @@ class RFC822Message(email.message.EmailMessage):
|
||||
This is :class:`email.message.EmailMessage` with two small changes: it defaults to
|
||||
our `RFC822Policy`, and it correctly writes unicode when being called
|
||||
with `bytes()`.
|
||||
|
||||
.. versionadded:: 26.0
|
||||
"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
@@ -519,8 +542,20 @@ _NOT_FOUND = object()
|
||||
|
||||
|
||||
# Keep the two values in sync.
|
||||
_VALID_METADATA_VERSIONS = ["1.0", "1.1", "1.2", "2.1", "2.2", "2.3", "2.4", "2.5"]
|
||||
_MetadataVersion = Literal["1.0", "1.1", "1.2", "2.1", "2.2", "2.3", "2.4", "2.5"]
|
||||
_VALID_METADATA_VERSIONS = [
|
||||
"1.0",
|
||||
"1.1",
|
||||
"1.2",
|
||||
"2.1",
|
||||
"2.2",
|
||||
"2.3",
|
||||
"2.4",
|
||||
"2.5",
|
||||
"2.6",
|
||||
]
|
||||
_MetadataVersion = Literal[
|
||||
"1.0", "1.1", "1.2", "2.1", "2.2", "2.3", "2.4", "2.5", "2.6"
|
||||
]
|
||||
|
||||
_REQUIRED_ATTRS = frozenset(["metadata_version", "name", "version"])
|
||||
|
||||
@@ -580,9 +615,7 @@ class _Validator(Generic[T]):
|
||||
def _invalid_metadata(
|
||||
self, msg: str, cause: Exception | None = None
|
||||
) -> InvalidMetadata:
|
||||
exc = InvalidMetadata(
|
||||
self.raw_name, msg.format_map({"field": repr(self.raw_name)})
|
||||
)
|
||||
exc = InvalidMetadata(self.raw_name, msg)
|
||||
exc.__cause__ = cause
|
||||
return exc
|
||||
|
||||
@@ -594,67 +627,82 @@ class _Validator(Generic[T]):
|
||||
|
||||
def _process_name(self, value: str) -> str:
|
||||
if not value:
|
||||
raise self._invalid_metadata("{field} is a required field")
|
||||
raise self._invalid_metadata(f"{self.raw_name!r} is a required field")
|
||||
# Validate the name as a side-effect.
|
||||
try:
|
||||
utils.canonicalize_name(value, validate=True)
|
||||
except utils.InvalidName as exc:
|
||||
raise self._invalid_metadata(
|
||||
f"{value!r} is invalid for {{field}}", cause=exc
|
||||
f"{value!r} is invalid for {self.raw_name!r}", cause=exc
|
||||
) from exc
|
||||
else:
|
||||
return value
|
||||
|
||||
def _process_version(self, value: str) -> version_module.Version:
|
||||
def _process_version(self, value: str) -> Version:
|
||||
if not value:
|
||||
raise self._invalid_metadata("{field} is a required field")
|
||||
raise self._invalid_metadata(f"{self.raw_name!r} is a required field")
|
||||
try:
|
||||
return version_module.parse(value)
|
||||
except version_module.InvalidVersion as exc:
|
||||
raise self._invalid_metadata(
|
||||
f"{value!r} is invalid for {{field}}", cause=exc
|
||||
f"{value!r} is invalid for {self.raw_name!r}", cause=exc
|
||||
) from exc
|
||||
|
||||
def _process_summary(self, value: str) -> str:
|
||||
"""Check the field contains no newlines."""
|
||||
if "\n" in value:
|
||||
raise self._invalid_metadata("{field} must be a single line")
|
||||
"""Check the field contains no line breaks."""
|
||||
if _LINE_BOUNDARY_RE.search(value):
|
||||
raise self._invalid_metadata(f"{self.raw_name!r} must be a single line")
|
||||
return value
|
||||
|
||||
def _process_description_content_type(self, value: str) -> str:
|
||||
content_types = {"text/plain", "text/x-rst", "text/markdown"}
|
||||
invalid_msg = (
|
||||
f"{self.raw_name!r} must be one of {list(content_types)}, not {value!r}"
|
||||
)
|
||||
message = email.message.EmailMessage()
|
||||
message["content-type"] = value
|
||||
try:
|
||||
message["content-type"] = value
|
||||
# The email parser can raise IndexError on malformed RFC 2231
|
||||
# parameters such as "text/plain; x*".
|
||||
except (ValueError, IndexError) as exc:
|
||||
msg = f"{value!r} is not a valid content type for {self.raw_name!r}"
|
||||
raise self._invalid_metadata(msg, cause=exc) from exc
|
||||
content_type_header = message["content-type"]
|
||||
if content_type_header.defects:
|
||||
defect = content_type_header.defects[0]
|
||||
msg = (
|
||||
f"{value!r} is not a valid content type for {self.raw_name!r}: {defect}"
|
||||
)
|
||||
raise self._invalid_metadata(msg, cause=defect) from defect
|
||||
|
||||
content_type, parameters = (
|
||||
# Defaults to `text/plain` if parsing failed.
|
||||
message.get_content_type().lower(),
|
||||
message["content-type"].params,
|
||||
content_type_header.params,
|
||||
)
|
||||
# Check if content-type is valid or defaulted to `text/plain` and thus was
|
||||
# not parseable.
|
||||
if content_type not in content_types or content_type not in value.lower():
|
||||
raise self._invalid_metadata(
|
||||
f"{{field}} must be one of {list(content_types)}, not {value!r}"
|
||||
)
|
||||
raise self._invalid_metadata(invalid_msg)
|
||||
|
||||
charset = parameters.get("charset", "UTF-8")
|
||||
if charset != "UTF-8":
|
||||
if charset.lower() != "utf-8":
|
||||
raise self._invalid_metadata(
|
||||
f"{{field}} can only specify the UTF-8 charset, not {list(charset)}"
|
||||
f"{self.raw_name!r} can only specify the UTF-8 charset, not {charset!r}"
|
||||
)
|
||||
|
||||
markdown_variants = {"GFM", "CommonMark"}
|
||||
variant = parameters.get("variant", "GFM") # Use an acceptable default.
|
||||
if content_type == "text/markdown" and variant not in markdown_variants:
|
||||
raise self._invalid_metadata(
|
||||
f"valid Markdown variants for {{field}} are {list(markdown_variants)}, "
|
||||
f"not {variant!r}",
|
||||
f"valid Markdown variants for {self.raw_name!r} are "
|
||||
f"{list(markdown_variants)}, not {variant!r}",
|
||||
)
|
||||
return value
|
||||
|
||||
def _process_dynamic(self, value: list[str]) -> list[str]:
|
||||
for dynamic_field in map(str.lower, value):
|
||||
dynamic_fields = list(map(str.lower, value))
|
||||
for dynamic_field in dynamic_fields:
|
||||
if dynamic_field in {"name", "version", "metadata-version"}:
|
||||
raise self._invalid_metadata(
|
||||
f"{dynamic_field!r} is not allowed as a dynamic field"
|
||||
@@ -663,7 +711,7 @@ class _Validator(Generic[T]):
|
||||
raise self._invalid_metadata(
|
||||
f"{dynamic_field!r} is not a valid dynamic field"
|
||||
)
|
||||
return list(map(str.lower, value))
|
||||
return dynamic_fields
|
||||
|
||||
def _process_provides_extra(
|
||||
self,
|
||||
@@ -675,7 +723,7 @@ class _Validator(Generic[T]):
|
||||
normalized_names.append(utils.canonicalize_name(name, validate=True))
|
||||
except utils.InvalidName as exc:
|
||||
raise self._invalid_metadata(
|
||||
f"{name!r} is invalid for {{field}}", cause=exc
|
||||
f"{name!r} is invalid for {self.raw_name!r}", cause=exc
|
||||
) from exc
|
||||
else:
|
||||
return normalized_names
|
||||
@@ -685,7 +733,7 @@ class _Validator(Generic[T]):
|
||||
return specifiers.SpecifierSet(value)
|
||||
except specifiers.InvalidSpecifier as exc:
|
||||
raise self._invalid_metadata(
|
||||
f"{value!r} is invalid for {{field}}", cause=exc
|
||||
f"{value!r} is invalid for {self.raw_name!r}", cause=exc
|
||||
) from exc
|
||||
|
||||
def _process_requires_dist(
|
||||
@@ -698,7 +746,7 @@ class _Validator(Generic[T]):
|
||||
reqs.append(requirements.Requirement(req))
|
||||
except requirements.InvalidRequirement as exc:
|
||||
raise self._invalid_metadata(
|
||||
f"{req!r} is invalid for {{field}}", cause=exc
|
||||
f"{req!r} is invalid for {self.raw_name!r}", cause=exc
|
||||
) from exc
|
||||
else:
|
||||
return reqs
|
||||
@@ -708,7 +756,7 @@ class _Validator(Generic[T]):
|
||||
return licenses.canonicalize_license_expression(value)
|
||||
except ValueError as exc:
|
||||
raise self._invalid_metadata(
|
||||
f"{value!r} is invalid for {{field}}", cause=exc
|
||||
f"{value!r} is invalid for {self.raw_name!r}", cause=exc
|
||||
) from exc
|
||||
|
||||
def _process_license_files(self, value: list[str]) -> list[str]:
|
||||
@@ -716,23 +764,24 @@ class _Validator(Generic[T]):
|
||||
for path in value:
|
||||
if ".." in path:
|
||||
raise self._invalid_metadata(
|
||||
f"{path!r} is invalid for {{field}}, "
|
||||
f"{path!r} is invalid for {self.raw_name!r}, "
|
||||
"parent directory indicators are not allowed"
|
||||
)
|
||||
if "*" in path:
|
||||
raise self._invalid_metadata(
|
||||
f"{path!r} is invalid for {{field}}, paths must be resolved"
|
||||
f"{path!r} is invalid for {self.raw_name!r}, paths must be resolved"
|
||||
)
|
||||
if (
|
||||
pathlib.PurePosixPath(path).is_absolute()
|
||||
or pathlib.PureWindowsPath(path).is_absolute()
|
||||
):
|
||||
raise self._invalid_metadata(
|
||||
f"{path!r} is invalid for {{field}}, paths must be relative"
|
||||
f"{path!r} is invalid for {self.raw_name!r}, paths must be relative"
|
||||
)
|
||||
if pathlib.PureWindowsPath(path).as_posix() != path:
|
||||
raise self._invalid_metadata(
|
||||
f"{path!r} is invalid for {{field}}, paths must use '/' delimiter"
|
||||
f"{path!r} is invalid for {self.raw_name!r}, "
|
||||
"paths must use '/' delimiter"
|
||||
)
|
||||
paths.append(path)
|
||||
return paths
|
||||
@@ -744,17 +793,17 @@ class _Validator(Generic[T]):
|
||||
for identifier in name.split("."):
|
||||
if not identifier.isidentifier():
|
||||
raise self._invalid_metadata(
|
||||
f"{name!r} is invalid for {{field}}; "
|
||||
f"{name!r} is invalid for {self.raw_name!r}; "
|
||||
f"{identifier!r} is not a valid identifier"
|
||||
)
|
||||
elif keyword.iskeyword(identifier):
|
||||
raise self._invalid_metadata(
|
||||
f"{name!r} is invalid for {{field}}; "
|
||||
f"{name!r} is invalid for {self.raw_name!r}; "
|
||||
f"{identifier!r} is a keyword"
|
||||
)
|
||||
if semicolon and private.lstrip() != "private":
|
||||
raise self._invalid_metadata(
|
||||
f"{import_name!r} is invalid for {{field}}; "
|
||||
f"{import_name!r} is invalid for {self.raw_name!r}; "
|
||||
"the only valid option is 'private'"
|
||||
)
|
||||
return value
|
||||
@@ -769,6 +818,12 @@ class Metadata:
|
||||
metadata fields instead of only using built-in types. Any invalid metadata
|
||||
will cause :exc:`InvalidMetadata` to be raised (with a
|
||||
:py:attr:`~BaseException.__cause__` attribute as appropriate).
|
||||
|
||||
.. versionadded:: 23.2
|
||||
|
||||
.. versionchanged:: 24.0
|
||||
Optional attributes now return None when the field is absent instead of
|
||||
raising.
|
||||
"""
|
||||
|
||||
_raw: RawMetadata
|
||||
@@ -777,20 +832,19 @@ class Metadata:
|
||||
def from_raw(cls, data: RawMetadata, *, validate: bool = True) -> Metadata:
|
||||
"""Create an instance from :class:`RawMetadata`.
|
||||
|
||||
If *validate* is true, all metadata will be validated. All exceptions
|
||||
related to validation will be gathered and raised as an :class:`ExceptionGroup`.
|
||||
If *validate* is true, all metadata will be validated and all related
|
||||
exceptions will be gathered and raised as an :class:`ExceptionGroup`;
|
||||
otherwise, validation happens per attribute when it is accessed.
|
||||
"""
|
||||
ins = cls()
|
||||
ins._raw = data.copy() # Mutations occur due to caching enriched values.
|
||||
|
||||
if validate:
|
||||
exceptions: list[Exception] = []
|
||||
try:
|
||||
collector = _ErrorCollector()
|
||||
metadata_version = None
|
||||
with collector.collect(InvalidMetadata):
|
||||
metadata_version = ins.metadata_version
|
||||
metadata_age = _VALID_METADATA_VERSIONS.index(metadata_version)
|
||||
except InvalidMetadata as metadata_version_exc:
|
||||
exceptions.append(metadata_version_exc)
|
||||
metadata_version = None
|
||||
|
||||
# Make sure to check for the fields that are present, the required
|
||||
# fields (so their absence can be reported).
|
||||
@@ -807,7 +861,7 @@ class Metadata:
|
||||
field_metadata_version = cls.__dict__[key].added
|
||||
except KeyError:
|
||||
exc = InvalidMetadata(key, f"unrecognized field: {key!r}")
|
||||
exceptions.append(exc)
|
||||
collector.error(exc)
|
||||
continue
|
||||
field_age = _VALID_METADATA_VERSIONS.index(
|
||||
field_metadata_version
|
||||
@@ -819,14 +873,13 @@ class Metadata:
|
||||
f"{field} introduced in metadata version "
|
||||
f"{field_metadata_version}, not {metadata_version}",
|
||||
)
|
||||
exceptions.append(exc)
|
||||
collector.error(exc)
|
||||
continue
|
||||
getattr(ins, key)
|
||||
except InvalidMetadata as exc:
|
||||
exceptions.append(exc)
|
||||
collector.error(exc)
|
||||
|
||||
if exceptions:
|
||||
raise ExceptionGroup("invalid metadata", exceptions)
|
||||
collector.finalize("invalid metadata")
|
||||
|
||||
return ins
|
||||
|
||||
@@ -840,23 +893,32 @@ class Metadata:
|
||||
raw, unparsed = parse_email(data)
|
||||
|
||||
if validate:
|
||||
exceptions: list[Exception] = []
|
||||
for unparsed_key in unparsed:
|
||||
if unparsed_key in _EMAIL_TO_RAW_MAPPING:
|
||||
message = f"{unparsed_key!r} has invalid data"
|
||||
with _ErrorCollector().on_exit("invalid or unparsed metadata") as collector:
|
||||
for unparsed_key in unparsed:
|
||||
if unparsed_key in _EMAIL_TO_RAW_MAPPING:
|
||||
message = f"{unparsed_key!r} has invalid data"
|
||||
else:
|
||||
message = f"unrecognized field: {unparsed_key!r}"
|
||||
collector.error(InvalidMetadata(unparsed_key, message))
|
||||
try:
|
||||
validated = cls.from_raw(raw, validate=validate)
|
||||
except ExceptionGroup as exc_group:
|
||||
# The no-branch pragmas cover arcs only seen by Python 3.9.
|
||||
for exc in exc_group.exceptions: # pragma: no branch
|
||||
# A required field reported above as unparsed is absent
|
||||
# from `raw`, so skip from_raw's duplicate "missing"
|
||||
# complaint.
|
||||
if not (
|
||||
isinstance(exc, InvalidMetadata)
|
||||
and exc.field in unparsed
|
||||
and _EMAIL_TO_RAW_MAPPING.get(exc.field) not in raw
|
||||
):
|
||||
collector.error(exc)
|
||||
else:
|
||||
message = f"unrecognized field: {unparsed_key!r}"
|
||||
exceptions.append(InvalidMetadata(unparsed_key, message))
|
||||
if not collector.errors: # pragma: no branch
|
||||
return validated
|
||||
|
||||
if exceptions:
|
||||
raise ExceptionGroup("unparsed", exceptions)
|
||||
|
||||
try:
|
||||
return cls.from_raw(raw, validate=validate)
|
||||
except ExceptionGroup as exc_group:
|
||||
raise ExceptionGroup(
|
||||
"invalid or unparsed metadata", exc_group.exceptions
|
||||
) from None
|
||||
return cls.from_raw(raw, validate=validate)
|
||||
|
||||
metadata_version: _Validator[_MetadataVersion] = _Validator()
|
||||
""":external:ref:`core-metadata-metadata-version`
|
||||
@@ -867,7 +929,7 @@ class Metadata:
|
||||
""":external:ref:`core-metadata-name`
|
||||
(required; validated using :func:`~packaging.utils.canonicalize_name` and its
|
||||
*validate* parameter)"""
|
||||
version: _Validator[version_module.Version] = _Validator()
|
||||
version: _Validator[Version] = _Validator()
|
||||
""":external:ref:`core-metadata-version` (required)"""
|
||||
dynamic: _Validator[list[str] | None] = _Validator(
|
||||
added="2.2",
|
||||
@@ -903,9 +965,15 @@ class Metadata:
|
||||
license_expression: _Validator[NormalizedLicenseExpression | None] = _Validator(
|
||||
added="2.4"
|
||||
)
|
||||
""":external:ref:`core-metadata-license-expression`"""
|
||||
""":external:ref:`core-metadata-license-expression`
|
||||
|
||||
.. versionadded:: 24.2
|
||||
"""
|
||||
license_files: _Validator[list[str] | None] = _Validator(added="2.4")
|
||||
""":external:ref:`core-metadata-license-file`"""
|
||||
""":external:ref:`core-metadata-license-file`
|
||||
|
||||
.. versionadded:: 24.2
|
||||
"""
|
||||
classifiers: _Validator[list[str] | None] = _Validator(added="1.1")
|
||||
""":external:ref:`core-metadata-classifier`"""
|
||||
requires_dist: _Validator[list[requirements.Requirement] | None] = _Validator(
|
||||
@@ -933,9 +1001,15 @@ class Metadata:
|
||||
obsoletes_dist: _Validator[list[str] | None] = _Validator(added="1.2")
|
||||
""":external:ref:`core-metadata-obsoletes-dist`"""
|
||||
import_names: _Validator[list[str] | None] = _Validator(added="2.5")
|
||||
""":external:ref:`core-metadata-import-name`"""
|
||||
""":external:ref:`core-metadata-import-name`
|
||||
|
||||
.. versionadded:: 26.0
|
||||
"""
|
||||
import_namespaces: _Validator[list[str] | None] = _Validator(added="2.5")
|
||||
""":external:ref:`core-metadata-import-namespace`"""
|
||||
""":external:ref:`core-metadata-import-namespace`
|
||||
|
||||
.. versionadded:: 26.0
|
||||
"""
|
||||
requires: _Validator[list[str] | None] = _Validator(added="1.1")
|
||||
"""``Requires`` (deprecated)"""
|
||||
provides: _Validator[list[str] | None] = _Validator(added="1.1")
|
||||
@@ -946,6 +1020,8 @@ class Metadata:
|
||||
def as_rfc822(self) -> RFC822Message:
|
||||
"""
|
||||
Return an RFC822 message with the metadata.
|
||||
|
||||
.. versionadded:: 26.0
|
||||
"""
|
||||
message = RFC822Message()
|
||||
self._write_metadata(message)
|
||||
|
||||
@@ -12,18 +12,34 @@ from typing import (
|
||||
Callable,
|
||||
Protocol,
|
||||
TypeVar,
|
||||
cast,
|
||||
)
|
||||
from urllib.parse import unquote, urlparse
|
||||
|
||||
from .markers import Marker
|
||||
from .markers import (
|
||||
Environment,
|
||||
Marker,
|
||||
_pep440_python_full_version,
|
||||
default_environment,
|
||||
)
|
||||
from .specifiers import SpecifierSet
|
||||
from .utils import NormalizedName, is_normalized_name
|
||||
from .tags import create_compatible_tags_selector, sys_tags
|
||||
from .utils import (
|
||||
NormalizedName,
|
||||
is_normalized_name,
|
||||
parse_sdist_filename,
|
||||
parse_wheel_filename,
|
||||
)
|
||||
from .version import Version
|
||||
|
||||
if TYPE_CHECKING: # pragma: no cover
|
||||
from collections.abc import Collection, Iterator
|
||||
from pathlib import Path
|
||||
|
||||
from typing_extensions import Self
|
||||
|
||||
from .tags import Tag
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
__all__ = [
|
||||
@@ -34,11 +50,17 @@ __all__ = [
|
||||
"PackageVcs",
|
||||
"PackageWheel",
|
||||
"Pylock",
|
||||
"PylockSelectError",
|
||||
"PylockUnsupportedVersionError",
|
||||
"PylockValidationError",
|
||||
"is_valid_pylock_path",
|
||||
]
|
||||
|
||||
|
||||
def __dir__() -> list[str]:
|
||||
return __all__
|
||||
|
||||
|
||||
_T = TypeVar("_T")
|
||||
_T2 = TypeVar("_T2")
|
||||
|
||||
@@ -83,7 +105,10 @@ def _get(d: Mapping[str, Any], expected_type: type[_T], key: str) -> _T | None:
|
||||
"""Get a value from the dictionary and verify it's the expected type."""
|
||||
if (value := d.get(key)) is None:
|
||||
return None
|
||||
if not isinstance(value, expected_type):
|
||||
if not isinstance(value, expected_type) or (
|
||||
# Special case: bool is a subclass of int, but TOML distinguishes the two
|
||||
expected_type is int and isinstance(value, bool)
|
||||
):
|
||||
raise PylockValidationError(
|
||||
f"Unexpected type {type(value).__name__} "
|
||||
f"(expected {expected_type.__name__})",
|
||||
@@ -222,6 +247,27 @@ def _validate_path_url(path: str | None, url: str | None) -> None:
|
||||
raise PylockValidationError("path or url must be provided")
|
||||
|
||||
|
||||
def _path_name(path: str | None) -> str | None:
|
||||
if not path:
|
||||
return None
|
||||
# If the path is relative it MAY use POSIX-style path separators explicitly
|
||||
# for portability
|
||||
if "/" in path:
|
||||
return path.rsplit("/", 1)[-1]
|
||||
elif "\\" in path:
|
||||
return path.rsplit("\\", 1)[-1]
|
||||
else:
|
||||
return path
|
||||
|
||||
|
||||
def _url_name(url: str | None) -> str | None:
|
||||
if not url:
|
||||
return None
|
||||
url_path = urlparse(url).path
|
||||
# The last path component is percent-encoded, so decode it to the file name
|
||||
return unquote(url_path.rsplit("/", 1)[-1])
|
||||
|
||||
|
||||
def _validate_hashes(hashes: Mapping[str, Any]) -> Mapping[str, Any]:
|
||||
if not hashes:
|
||||
raise PylockValidationError("At least one hash must be provided")
|
||||
@@ -269,6 +315,13 @@ class PylockUnsupportedVersionError(PylockValidationError):
|
||||
"""Raised when encountering an unsupported `lock_version`."""
|
||||
|
||||
|
||||
class PylockSelectError(Exception):
|
||||
"""Base exception for errors raised by :meth:`Pylock.select`.
|
||||
|
||||
.. versionadded:: 26.1
|
||||
"""
|
||||
|
||||
|
||||
@dataclass(frozen=True, init=False)
|
||||
class PackageVcs:
|
||||
type: str
|
||||
@@ -418,6 +471,17 @@ class PackageSdist:
|
||||
_validate_path_url(package_sdist.path, package_sdist.url)
|
||||
return package_sdist
|
||||
|
||||
@property
|
||||
def filename(self) -> str:
|
||||
"""Get the filename of the sdist.
|
||||
|
||||
.. versionadded:: 26.1
|
||||
"""
|
||||
filename = self.name or _path_name(self.path) or _url_name(self.url)
|
||||
if not filename:
|
||||
raise PylockValidationError("Cannot determine sdist filename")
|
||||
return filename
|
||||
|
||||
|
||||
@dataclass(frozen=True, init=False)
|
||||
class PackageWheel:
|
||||
@@ -459,6 +523,14 @@ class PackageWheel:
|
||||
_validate_path_url(package_wheel.path, package_wheel.url)
|
||||
return package_wheel
|
||||
|
||||
@property
|
||||
def filename(self) -> str:
|
||||
"""Get the filename of the wheel."""
|
||||
filename = self.name or _path_name(self.path) or _url_name(self.url)
|
||||
if not filename:
|
||||
raise PylockValidationError("Cannot determine wheel filename")
|
||||
return filename
|
||||
|
||||
|
||||
@dataclass(frozen=True, init=False)
|
||||
class Package:
|
||||
@@ -538,6 +610,46 @@ class Package:
|
||||
"Exactly one of vcs, directory, archive must be set "
|
||||
"if sdist and wheels are not set"
|
||||
)
|
||||
for i, wheel in enumerate(package.wheels or []):
|
||||
try:
|
||||
(name, version, _, _) = parse_wheel_filename(wheel.filename)
|
||||
except Exception as e:
|
||||
raise PylockValidationError(
|
||||
f"Invalid wheel filename {wheel.filename!r}",
|
||||
context=f"wheels[{i}]",
|
||||
) from e
|
||||
if name != package.name:
|
||||
raise PylockValidationError(
|
||||
f"Name in {wheel.filename!r} is not consistent with "
|
||||
f"package name {package.name!r}",
|
||||
context=f"wheels[{i}]",
|
||||
)
|
||||
if package.version and version != package.version:
|
||||
raise PylockValidationError(
|
||||
f"Version in {wheel.filename!r} is not consistent with "
|
||||
f"package version {str(package.version)!r}",
|
||||
context=f"wheels[{i}]",
|
||||
)
|
||||
if package.sdist:
|
||||
try:
|
||||
name, version = parse_sdist_filename(package.sdist.filename)
|
||||
except Exception as e:
|
||||
raise PylockValidationError(
|
||||
f"Invalid sdist filename {package.sdist.filename!r}",
|
||||
context="sdist",
|
||||
) from e
|
||||
if name != package.name:
|
||||
raise PylockValidationError(
|
||||
f"Name in {package.sdist.filename!r} is not consistent with "
|
||||
f"package name {package.name!r}",
|
||||
context="sdist",
|
||||
)
|
||||
if package.version and version != package.version:
|
||||
raise PylockValidationError(
|
||||
f"Version in {package.sdist.filename!r} is not consistent with "
|
||||
f"package version {str(package.version)!r}",
|
||||
context="sdist",
|
||||
)
|
||||
try:
|
||||
for i, attestation_identity in enumerate( # noqa: B007
|
||||
package.attestation_identities or []
|
||||
@@ -633,3 +745,199 @@ class Pylock:
|
||||
|
||||
Raises :class:`PylockValidationError` otherwise."""
|
||||
self.from_dict(self.to_dict())
|
||||
|
||||
def select(
|
||||
self,
|
||||
*,
|
||||
environment: Environment | None = None,
|
||||
tags: Sequence[Tag] | None = None,
|
||||
extras: Collection[str] | None = None,
|
||||
dependency_groups: Collection[str] | None = None,
|
||||
prefer_sdist_predicate: Callable[[NormalizedName], bool] | None = None,
|
||||
) -> Iterator[
|
||||
tuple[
|
||||
Package,
|
||||
PackageVcs
|
||||
| PackageDirectory
|
||||
| PackageArchive
|
||||
| PackageWheel
|
||||
| PackageSdist,
|
||||
]
|
||||
]:
|
||||
"""Select what to install from the lock file.
|
||||
|
||||
The *environment* and *tags* parameters represent the environment being
|
||||
selected for. If unspecified, ``packaging.markers.default_environment()`` and
|
||||
``packaging.tags.sys_tags()`` are used.
|
||||
|
||||
The *extras* parameter represents the extras to install.
|
||||
|
||||
The *dependency_groups* parameter represents the groups to install. If
|
||||
unspecified, the default groups are used.
|
||||
|
||||
The *prefer_sdist_predicate* parameter is called for packages with a source
|
||||
distribution. If it returns ``True``, the source distribution is selected
|
||||
before attempting wheel compatibility. If no source distribution is
|
||||
available, wheel selection proceeds as usual without calling the predicate.
|
||||
|
||||
This method must be used on valid Pylock instances (i.e. one obtained
|
||||
from :meth:`Pylock.from_dict` or if constructed manually, after calling
|
||||
:meth:`Pylock.validate`).
|
||||
|
||||
.. versionadded:: 26.1
|
||||
|
||||
.. versionchanged:: 26.3
|
||||
Added the *prefer_sdist_predicate* parameter.
|
||||
"""
|
||||
compatible_tags_selector = create_compatible_tags_selector(
|
||||
tags if tags is not None else sys_tags()
|
||||
)
|
||||
|
||||
# #. Gather the extras and dependency groups to install and set ``extras`` and
|
||||
# ``dependency_groups`` for marker evaluation, respectively.
|
||||
#
|
||||
# #. ``extras`` SHOULD be set to the empty set by default.
|
||||
# #. ``dependency_groups`` SHOULD be the set created from
|
||||
# :ref:`pylock-default-groups` by default.
|
||||
env = cast(
|
||||
"dict[str, str | frozenset[str]]",
|
||||
dict(
|
||||
environment or {}, # Marker.evaluate will fill-up
|
||||
extras=frozenset(extras or []),
|
||||
dependency_groups=frozenset(
|
||||
(self.default_groups or [])
|
||||
if dependency_groups is None # to allow selecting no group
|
||||
else dependency_groups
|
||||
),
|
||||
),
|
||||
)
|
||||
env_python_full_version = _pep440_python_full_version(
|
||||
environment["python_full_version"]
|
||||
if environment
|
||||
else default_environment()["python_full_version"]
|
||||
)
|
||||
|
||||
# #. Check if the metadata version specified by :ref:`pylock-lock-version` is
|
||||
# supported; an error or warning MUST be raised as appropriate.
|
||||
# Covered by lock.validate() which is a precondition for this method.
|
||||
|
||||
# #. If :ref:`pylock-requires-python` is specified, check that the environment
|
||||
# being installed for meets the requirement; an error MUST be raised if it is
|
||||
# not met.
|
||||
if self.requires_python and not self.requires_python.contains(
|
||||
env_python_full_version,
|
||||
):
|
||||
raise PylockSelectError(
|
||||
f"python_full_version {env_python_full_version!r} "
|
||||
f"in provided environment does not satisfy the Python version "
|
||||
f"requirement {str(self.requires_python)!r}"
|
||||
)
|
||||
|
||||
# #. If :ref:`pylock-environments` is specified, check that at least one of the
|
||||
# environment marker expressions is satisfied; an error MUST be raised if no
|
||||
# expression is satisfied.
|
||||
if self.environments:
|
||||
for env_marker in self.environments:
|
||||
if env_marker.evaluate(
|
||||
cast("dict[str, str]", environment or {}), context="requirement"
|
||||
):
|
||||
break
|
||||
else:
|
||||
raise PylockSelectError(
|
||||
"Provided environment does not satisfy any of the "
|
||||
"environments specified in the lock file"
|
||||
)
|
||||
|
||||
# #. For each package listed in :ref:`pylock-packages`:
|
||||
selected_packages_by_name: dict[str, tuple[int, Package]] = {}
|
||||
for package_index, package in enumerate(self.packages):
|
||||
# #. If :ref:`pylock-packages-marker` is specified, check if it is
|
||||
# satisfied;if it isn't, skip to the next package.
|
||||
if package.marker and not package.marker.evaluate(env, context="lock_file"):
|
||||
continue
|
||||
|
||||
# #. If :ref:`pylock-packages-requires-python` is specified, check if it is
|
||||
# satisfied; an error MUST be raised if it isn't.
|
||||
if package.requires_python and not package.requires_python.contains(
|
||||
env_python_full_version,
|
||||
):
|
||||
raise PylockSelectError(
|
||||
f"python_full_version {env_python_full_version!r} "
|
||||
f"in provided environment does not satisfy the Python version "
|
||||
f"requirement {str(package.requires_python)!r} for package "
|
||||
f"{package.name!r} at packages[{package_index}]"
|
||||
)
|
||||
|
||||
# #. Check that no other conflicting instance of the package has been slated
|
||||
# to be installed; an error about the ambiguity MUST be raised otherwise.
|
||||
if package.name in selected_packages_by_name:
|
||||
raise PylockSelectError(
|
||||
f"Multiple packages with the name {package.name!r} are "
|
||||
f"selected at packages[{package_index}] and "
|
||||
f"packages[{selected_packages_by_name[package.name][0]}]"
|
||||
)
|
||||
|
||||
# #. Check that the source of the package is specified appropriately (i.e.
|
||||
# there are no conflicting sources in the package entry);
|
||||
# an error MUST be raised if any issues are found.
|
||||
# Covered by lock.validate() which is a precondition for this method.
|
||||
|
||||
# #. Add the package to the set of packages to install.
|
||||
selected_packages_by_name[package.name] = (package_index, package)
|
||||
|
||||
# #. For each package to be installed:
|
||||
for package_index, package in selected_packages_by_name.values():
|
||||
# - If :ref:`pylock-packages-vcs` is set:
|
||||
if package.vcs is not None:
|
||||
yield package, package.vcs
|
||||
|
||||
# - Else if :ref:`pylock-packages-directory` is set:
|
||||
elif package.directory is not None:
|
||||
yield package, package.directory
|
||||
|
||||
# - Else if :ref:`pylock-packages-archive` is set:
|
||||
elif package.archive is not None:
|
||||
yield package, package.archive
|
||||
|
||||
# - Else if source preference selects an available
|
||||
# :ref:`pylock-packages-sdist`:
|
||||
elif (
|
||||
package.sdist is not None
|
||||
and prefer_sdist_predicate is not None
|
||||
and prefer_sdist_predicate(package.name)
|
||||
):
|
||||
yield package, package.sdist
|
||||
|
||||
# - Else if there are entries for :ref:`pylock-packages-wheels`:
|
||||
elif package.wheels:
|
||||
# #. Look for the appropriate wheel file based on
|
||||
# :ref:`pylock-packages-wheels-name`; if one is not found then move
|
||||
# on to :ref:`pylock-packages-sdist` or an error MUST be raised about
|
||||
# a lack of source for the project.
|
||||
best_wheel = next(
|
||||
compatible_tags_selector(
|
||||
(wheel, parse_wheel_filename(wheel.filename)[-1])
|
||||
for wheel in package.wheels
|
||||
),
|
||||
None,
|
||||
)
|
||||
if best_wheel:
|
||||
yield package, best_wheel
|
||||
elif package.sdist is not None:
|
||||
yield package, package.sdist
|
||||
else:
|
||||
raise PylockSelectError(
|
||||
f"No wheel found matching the provided tags "
|
||||
f"for package {package.name!r} "
|
||||
f"at packages[{package_index}], "
|
||||
f"and no sdist available as a fallback"
|
||||
)
|
||||
|
||||
# - Else if no :ref:`pylock-packages-wheels` file is found or
|
||||
# :ref:`pylock-packages-sdist` is solely set:
|
||||
elif package.sdist is not None:
|
||||
yield package, package.sdist
|
||||
|
||||
else:
|
||||
# Covered by lock.validate() which is a precondition for this method.
|
||||
raise NotImplementedError # pragma: no cover
|
||||
@@ -3,18 +3,32 @@
|
||||
# for complete details.
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Iterator
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from ._parser import parse_requirement as _parse_requirement
|
||||
from ._tokenizer import ParserSyntaxError
|
||||
from .markers import Marker, _normalize_extra_values
|
||||
from .specifiers import SpecifierSet
|
||||
from .specifiers import InvalidSpecifier, SpecifierSet
|
||||
from .utils import canonicalize_name
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import Iterator
|
||||
|
||||
__all__ = [
|
||||
"InvalidRequirement",
|
||||
"Requirement",
|
||||
]
|
||||
|
||||
|
||||
def __dir__() -> list[str]:
|
||||
return __all__
|
||||
|
||||
|
||||
class InvalidRequirement(ValueError):
|
||||
"""
|
||||
An invalid requirement was found, users should refer to PEP 508.
|
||||
|
||||
.. versionadded:: 16.1
|
||||
"""
|
||||
|
||||
|
||||
@@ -24,6 +38,38 @@ class Requirement:
|
||||
Parse a given requirement string into its parts, such as name, specifier,
|
||||
URL, and extras. Raises InvalidRequirement on a badly-formed requirement
|
||||
string.
|
||||
|
||||
.. versionadded:: 16.1
|
||||
|
||||
.. versionchanged:: 22.0
|
||||
Added equality (``__eq__``) and hashing (``__hash__``) so requirements
|
||||
can be compared and stored in sets / dicts.
|
||||
|
||||
.. versionchanged:: 23.2
|
||||
Equality and hashing began canonicalizing requirement names, so
|
||||
requirements whose names differ only by normalization (e.g.
|
||||
``Requirement("Foo")`` vs ``Requirement("foo")``) now compare and hash
|
||||
equal.
|
||||
|
||||
Instances are safe to serialize with :mod:`pickle`. They use a stable
|
||||
format so the same pickle can be loaded in future packaging releases.
|
||||
|
||||
.. versionchanged:: 26.2
|
||||
|
||||
Added a stable pickle format. Pickles created with packaging 26.2+ can
|
||||
be unpickled with future releases. Backward compatibility with pickles
|
||||
from pip._vendor.packaging < 26.2 is supported but may be removed in a future
|
||||
release.
|
||||
|
||||
.. versionchanged:: 26.3
|
||||
|
||||
The dedicated pickle support introduced in 26.2 did not preserve the
|
||||
specifier's explicit :attr:`~packaging.specifiers.SpecifierSet.prereleases`
|
||||
override; it is now included again.
|
||||
|
||||
Equality and hashing normalize requirement names, extras, and
|
||||
equivalent specifiers. The string representation still preserves the
|
||||
parsed name and extras spelling.
|
||||
"""
|
||||
|
||||
# TODO: Can we test whether something is contained within a requirement?
|
||||
@@ -31,6 +77,8 @@ class Requirement:
|
||||
# the thing as well as the version? What about the markers?
|
||||
# TODO: Can we normalize the name and extra name?
|
||||
|
||||
__slots__ = ("extras", "marker", "name", "specifier", "url")
|
||||
|
||||
def __init__(self, requirement_string: str) -> None:
|
||||
try:
|
||||
parsed = _parse_requirement(requirement_string)
|
||||
@@ -39,8 +87,11 @@ class Requirement:
|
||||
|
||||
self.name: str = parsed.name
|
||||
self.url: str | None = parsed.url or None
|
||||
self.extras: set[str] = set(parsed.extras or [])
|
||||
self.specifier: SpecifierSet = SpecifierSet(parsed.specifier)
|
||||
self.extras: set[str] = set(parsed.extras)
|
||||
try:
|
||||
self.specifier: SpecifierSet = SpecifierSet(parsed.specifier)
|
||||
except InvalidSpecifier as e:
|
||||
raise InvalidRequirement(str(e)) from e
|
||||
self.marker: Marker | None = None
|
||||
if parsed.marker is not None:
|
||||
self.marker = Marker.__new__(Marker)
|
||||
@@ -64,22 +115,77 @@ class Requirement:
|
||||
if self.marker:
|
||||
yield f"; {self.marker}"
|
||||
|
||||
def __getstate__(self) -> tuple[str, bool | None]:
|
||||
# Return the requirement string for compactness and stability, paired
|
||||
# with the specifier's explicit prereleases override, which is not
|
||||
# captured by the string form. Re-parsed on load to reconstruct all
|
||||
# other fields.
|
||||
return (str(self), self.specifier._prereleases)
|
||||
|
||||
def __setstate__(self, state: object) -> None:
|
||||
if isinstance(state, str):
|
||||
# Format (26.2): just the requirement string.
|
||||
requirement_string: str = state
|
||||
prereleases: bool | None = None
|
||||
elif (
|
||||
isinstance(state, tuple)
|
||||
and len(state) == 2
|
||||
and isinstance(state[0], str)
|
||||
and (state[1] is None or isinstance(state[1], bool))
|
||||
):
|
||||
# New format (26.3+): (requirement string, specifier prereleases).
|
||||
requirement_string, prereleases = state
|
||||
elif isinstance(state, dict) and state.keys() >= set(self.__slots__):
|
||||
# Old format (packaging <= 26.1, no __slots__): plain __dict__.
|
||||
for key in self.__slots__:
|
||||
setattr(self, key, state[key])
|
||||
return
|
||||
else:
|
||||
raise TypeError(f"Cannot restore Requirement from {state!r}")
|
||||
|
||||
try:
|
||||
tmp = Requirement(requirement_string)
|
||||
except InvalidRequirement as exc:
|
||||
raise TypeError(f"Cannot restore Requirement from {state!r}") from exc
|
||||
self.name = tmp.name
|
||||
self.url = tmp.url
|
||||
self.extras = tmp.extras
|
||||
self.specifier = tmp.specifier
|
||||
self.specifier._prereleases = prereleases
|
||||
self.marker = tmp.marker
|
||||
|
||||
def __str__(self) -> str:
|
||||
return "".join(self._iter_parts(self.name))
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<{self.__class__.__name__}('{self}')>"
|
||||
return f"<{self.__class__.__name__}({str(self)!r})>"
|
||||
|
||||
def __hash__(self) -> int:
|
||||
return hash(tuple(self._iter_parts(canonicalize_name(self.name))))
|
||||
# Mirror __eq__ by hashing the canonical specifier object rather than
|
||||
# its raw string. ``_iter_parts`` yields ``str(self.specifier)``, which
|
||||
# is non-canonical, so trailing-zero-equivalent requirements such as
|
||||
# ``foo==1.0.0`` and ``foo==1.0.0.0`` (which compare equal) would
|
||||
# otherwise hash differently, breaking the hash/__eq__ invariant.
|
||||
return hash(
|
||||
(
|
||||
canonicalize_name(self.name),
|
||||
frozenset(canonicalize_name(e) for e in self.extras),
|
||||
self.specifier,
|
||||
self.url,
|
||||
self.marker,
|
||||
)
|
||||
)
|
||||
|
||||
def __eq__(self, other: object) -> bool:
|
||||
if not isinstance(other, Requirement):
|
||||
return NotImplemented
|
||||
|
||||
# Extras must be normalized before comparison as per PEP 685.
|
||||
self_extras = frozenset(canonicalize_name(e) for e in self.extras)
|
||||
other_extras = frozenset(canonicalize_name(e) for e in other.extras)
|
||||
return (
|
||||
canonicalize_name(self.name) == canonicalize_name(other.name)
|
||||
and self.extras == other.extras
|
||||
and self_extras == other_extras
|
||||
and self.specifier == other.specifier
|
||||
and self.url == other.url
|
||||
and self.marker == other.marker
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -5,28 +5,72 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import operator
|
||||
import platform
|
||||
import re
|
||||
import struct
|
||||
import subprocess
|
||||
import sys
|
||||
import sysconfig
|
||||
from collections.abc import Iterable, Iterator, Sequence
|
||||
from importlib.machinery import EXTENSION_SUFFIXES
|
||||
from typing import (
|
||||
Any,
|
||||
Iterable,
|
||||
Iterator,
|
||||
Sequence,
|
||||
Tuple,
|
||||
TYPE_CHECKING,
|
||||
TypeVar,
|
||||
cast,
|
||||
)
|
||||
|
||||
from . import _manylinux, _musllinux
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import Callable
|
||||
from collections.abc import Set as AbstractSet
|
||||
|
||||
|
||||
__all__ = [
|
||||
"INTERPRETER_SHORT_NAMES",
|
||||
"AppleVersion",
|
||||
"InvalidTag",
|
||||
"PythonVersion",
|
||||
"Tag",
|
||||
"TooManyTagsError",
|
||||
"UnsortedTagsError",
|
||||
"android_platforms",
|
||||
"compatible_tags",
|
||||
"cpython_tags",
|
||||
"create_compatible_tags_selector",
|
||||
"generic_tags",
|
||||
"interpreter_name",
|
||||
"interpreter_version",
|
||||
"ios_platforms",
|
||||
"mac_platforms",
|
||||
"parse_tag",
|
||||
"platform_tags",
|
||||
"pure_python_tags",
|
||||
"sys_tags",
|
||||
]
|
||||
|
||||
|
||||
def __dir__() -> list[str]:
|
||||
return __all__
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
PythonVersion = Sequence[int]
|
||||
AppleVersion = Tuple[int, int]
|
||||
"""
|
||||
A sequence of integers describing a Python version, e.g. ``(3, 13)``.
|
||||
|
||||
.. versionadded:: 20.0
|
||||
"""
|
||||
|
||||
AppleVersion = tuple[int, int]
|
||||
"""
|
||||
A ``(major, minor)`` integer pair describing an Apple OS version.
|
||||
|
||||
.. versionadded:: 24.2
|
||||
"""
|
||||
_T = TypeVar("_T")
|
||||
|
||||
INTERPRETER_SHORT_NAMES: dict[str, str] = {
|
||||
"python": "py", # Generic.
|
||||
@@ -37,7 +81,38 @@ INTERPRETER_SHORT_NAMES: dict[str, str] = {
|
||||
}
|
||||
|
||||
|
||||
_32_BIT_INTERPRETER = struct.calcsize("P") == 4
|
||||
# This function can be unit tested without reloading the module
|
||||
# (Unlike _32_BIT_INTERPRETER)
|
||||
def _compute_32_bit_interpreter() -> bool:
|
||||
return struct.calcsize("P") == 4
|
||||
|
||||
|
||||
_32_BIT_INTERPRETER = _compute_32_bit_interpreter()
|
||||
|
||||
|
||||
class UnsortedTagsError(ValueError):
|
||||
"""
|
||||
Raised when a tag component is not in sorted order per PEP 425.
|
||||
|
||||
.. versionadded:: 26.1
|
||||
"""
|
||||
|
||||
|
||||
class InvalidTag(ValueError):
|
||||
"""
|
||||
Raised when an interpreter component is not an identifier, a tag component
|
||||
is empty, or a tag does not have exactly three components.
|
||||
|
||||
.. versionadded:: 26.3
|
||||
"""
|
||||
|
||||
|
||||
class TooManyTagsError(ValueError):
|
||||
"""
|
||||
Raised when a compressed tag set exceeds the configured limit.
|
||||
|
||||
.. versionadded:: 26.3
|
||||
"""
|
||||
|
||||
|
||||
class Tag:
|
||||
@@ -46,11 +121,29 @@ class Tag:
|
||||
|
||||
Instances are considered immutable and thus are hashable. Equality checking
|
||||
is also supported.
|
||||
|
||||
Instances are safe to serialize with :mod:`pickle`. They use a stable
|
||||
format so the same pickle can be loaded in future packaging releases.
|
||||
|
||||
.. versionchanged:: 26.2
|
||||
|
||||
Added a stable pickle format. Pickles created with packaging 26.2+ can
|
||||
be unpickled with future releases. Backward compatibility with pickles
|
||||
from pip._vendor.packaging < 26.2 is supported but may be removed in a future
|
||||
release.
|
||||
"""
|
||||
|
||||
__slots__ = ["_abi", "_hash", "_interpreter", "_platform"]
|
||||
|
||||
def __init__(self, interpreter: str, abi: str, platform: str) -> None:
|
||||
"""
|
||||
:param str interpreter: The interpreter name, e.g. ``"py"``
|
||||
(see :attr:`INTERPRETER_SHORT_NAMES` for mapping
|
||||
well-known interpreter names to their short names).
|
||||
:param str abi: The ABI that a wheel supports, e.g. ``"cp37m"``.
|
||||
:param str platform: The OS/platform the wheel supports,
|
||||
e.g. ``"win_amd64"``.
|
||||
"""
|
||||
self._interpreter = interpreter.lower()
|
||||
self._abi = abi.lower()
|
||||
self._platform = platform.lower()
|
||||
@@ -63,14 +156,25 @@ class Tag:
|
||||
|
||||
@property
|
||||
def interpreter(self) -> str:
|
||||
"""
|
||||
The interpreter name, e.g. ``"py"`` (see
|
||||
:attr:`INTERPRETER_SHORT_NAMES` for mapping well-known interpreter
|
||||
names to their short names).
|
||||
"""
|
||||
return self._interpreter
|
||||
|
||||
@property
|
||||
def abi(self) -> str:
|
||||
"""
|
||||
The supported ABI.
|
||||
"""
|
||||
return self._abi
|
||||
|
||||
@property
|
||||
def platform(self) -> str:
|
||||
"""
|
||||
The OS/platform.
|
||||
"""
|
||||
return self._platform
|
||||
|
||||
def __eq__(self, other: object) -> bool:
|
||||
@@ -93,28 +197,117 @@ class Tag:
|
||||
def __repr__(self) -> str:
|
||||
return f"<{self} @ {id(self)}>"
|
||||
|
||||
def __setstate__(self, state: tuple[None, dict[str, Any]]) -> None:
|
||||
# The cached _hash is wrong when unpickling.
|
||||
_, slots = state
|
||||
for k, v in slots.items():
|
||||
setattr(self, k, v)
|
||||
self._hash = hash((self._interpreter, self._abi, self._platform))
|
||||
def __getstate__(self) -> tuple[str, str, str]:
|
||||
# Return state as a 3-item tuple: (interpreter, abi, platform).
|
||||
# Cache member _hash is excluded and will be recomputed.
|
||||
return (self._interpreter, self._abi, self._platform)
|
||||
|
||||
def __setstate__(self, state: object) -> None:
|
||||
if isinstance(state, tuple):
|
||||
if len(state) == 3 and all(isinstance(s, str) for s in state):
|
||||
# New format (26.2+): (interpreter, abi, platform)
|
||||
self._interpreter, self._abi, self._platform = state
|
||||
self._hash = hash((self._interpreter, self._abi, self._platform))
|
||||
return
|
||||
if len(state) == 2 and isinstance(state[1], dict):
|
||||
# Old format (packaging <= 26.1, __slots__): (None, {slot: value}).
|
||||
_, slots = state
|
||||
try:
|
||||
interpreter = slots["_interpreter"]
|
||||
abi = slots["_abi"]
|
||||
platform = slots["_platform"]
|
||||
except KeyError:
|
||||
raise TypeError(f"Cannot restore Tag from {state!r}") from None
|
||||
if not all(
|
||||
isinstance(value, str) for value in (interpreter, abi, platform)
|
||||
):
|
||||
raise TypeError(f"Cannot restore Tag from {state!r}")
|
||||
self._interpreter = interpreter.lower()
|
||||
self._abi = abi.lower()
|
||||
self._platform = platform.lower()
|
||||
self._hash = hash((self._interpreter, self._abi, self._platform))
|
||||
return
|
||||
raise TypeError(f"Cannot restore Tag from {state!r}")
|
||||
|
||||
|
||||
def parse_tag(tag: str) -> frozenset[Tag]:
|
||||
def parse_tag(
|
||||
tag: str, *, validate_order: bool = False, limit: int | None = None
|
||||
) -> frozenset[Tag]:
|
||||
"""
|
||||
Parses the provided tag (e.g. `py3-none-any`) into a frozenset of Tag instances.
|
||||
Parses the provided tag (e.g. `py3-none-any`) into a frozenset of
|
||||
:class:`Tag` instances.
|
||||
|
||||
Returning a set is required due to the possibility that the tag is a
|
||||
compressed tag set.
|
||||
`compressed tag set`_, e.g. ``"py2.py3-none-any"`` which supports both
|
||||
Python 2 and Python 3.
|
||||
|
||||
If **validate_order** is true, compressed tag set components are checked
|
||||
to be in sorted order as required by PEP 425.
|
||||
|
||||
If **limit** is not ``None``, the compressed tag set can generate at most
|
||||
that many tags.
|
||||
|
||||
:param str tag: The tag to parse, e.g. ``"py3-none-any"``.
|
||||
:param bool validate_order: Check whether compressed tag set components
|
||||
are in sorted order.
|
||||
:param int | None limit: The maximum number of tags to parse.
|
||||
:raises UnsortedTagsError: If **validate_order** is true and any compressed tag
|
||||
set component is not in sorted order.
|
||||
:raises InvalidTag: If the interpreter field is not an identifier; if the
|
||||
interpreter, ABI, or platform field (or any member of a compressed tag
|
||||
set) is empty; or if the tag does not have exactly three components.
|
||||
:raises TooManyTagsError: If **limit** is not ``None`` and the compressed tag
|
||||
set would generate more than **limit** tags.
|
||||
:raises ValueError: If **limit** is negative.
|
||||
|
||||
.. versionadded:: 26.1
|
||||
The *validate_order* parameter.
|
||||
|
||||
.. versionadded:: 26.3
|
||||
Raises :class:`InvalidTag` when an interpreter component is not an
|
||||
identifier, a tag component is empty, or a tag does not have exactly
|
||||
three components.
|
||||
Added the *limit* parameter. Raises :class:`TooManyTagsError` if the compressed
|
||||
tag set would generate more than *limit* tags.
|
||||
"""
|
||||
tags = set()
|
||||
interpreters, abis, platforms = tag.split("-")
|
||||
for interpreter in interpreters.split("."):
|
||||
for abi in abis.split("."):
|
||||
for platform_ in platforms.split("."):
|
||||
tags.add(Tag(interpreter, abi, platform_))
|
||||
return frozenset(tags)
|
||||
|
||||
if limit is not None and limit < 0:
|
||||
raise ValueError("limit must be non-negative")
|
||||
|
||||
component_parts = [component.split(".") for component in tag.split("-")]
|
||||
for parts in component_parts:
|
||||
if "" in parts:
|
||||
component = ".".join(parts)
|
||||
raise InvalidTag(f"Tag {tag!r} has an empty component: {component!r}")
|
||||
if validate_order and parts != sorted(parts):
|
||||
component = ".".join(parts)
|
||||
raise UnsortedTagsError(
|
||||
f"Tag component {component!r} is not in sorted order per PEP 425"
|
||||
)
|
||||
|
||||
tag_count = 1
|
||||
for parts in component_parts:
|
||||
tag_count *= len(parts)
|
||||
|
||||
if limit is not None and tag_count > limit:
|
||||
raise TooManyTagsError(
|
||||
f"Compressed tag set would generate {tag_count} tags, exceeding "
|
||||
f"limit {limit}"
|
||||
)
|
||||
|
||||
try:
|
||||
interpreters, abis, platforms = component_parts
|
||||
except ValueError as exc:
|
||||
raise InvalidTag(f"Tag {tag!r} must have exactly three components") from exc
|
||||
for interpreter in interpreters:
|
||||
if not interpreter.isidentifier():
|
||||
raise InvalidTag(f"Tag {tag!r} has an invalid interpreter: {interpreter!r}")
|
||||
return frozenset(
|
||||
Tag(interpreter, abi, platform_)
|
||||
for interpreter in interpreters
|
||||
for abi in abis
|
||||
for platform_ in platforms
|
||||
)
|
||||
|
||||
|
||||
def _get_config_var(name: str, warn: bool = False) -> int | str | None:
|
||||
@@ -150,12 +343,25 @@ def _abi3_applies(python_version: PythonVersion, threading: bool) -> bool:
|
||||
"""
|
||||
Determine if the Python version supports abi3.
|
||||
|
||||
PEP 384 was first implemented in Python 3.2. The threaded (`--disable-gil`)
|
||||
PEP 384 was first implemented in Python 3.2. The free-threaded
|
||||
builds do not support abi3.
|
||||
"""
|
||||
return len(python_version) > 1 and tuple(python_version) >= (3, 2) and not threading
|
||||
|
||||
|
||||
def _abi3t_applies(python_version: PythonVersion, threading: bool) -> bool:
|
||||
"""
|
||||
Determine if the Python version supports abi3t.
|
||||
|
||||
PEP 803 was first implemented in Python 3.15 but, per PEP 803, this
|
||||
returns tags going back to Python 3.2 to mirror the abi3
|
||||
implementation and leave open the possibility of abi3t wheels
|
||||
supporting older Python versions.
|
||||
|
||||
"""
|
||||
return len(python_version) > 1 and tuple(python_version) >= (3, 2) and threading
|
||||
|
||||
|
||||
def _cpython_abis(py_version: PythonVersion, warn: bool = False) -> list[str]:
|
||||
py_version = tuple(py_version) # To allow for version comparison.
|
||||
abis = []
|
||||
@@ -197,19 +403,33 @@ def cpython_tags(
|
||||
warn: bool = False,
|
||||
) -> Iterator[Tag]:
|
||||
"""
|
||||
Yields the tags for a CPython interpreter.
|
||||
Yields the tags for the CPython interpreter.
|
||||
|
||||
The tags consist of:
|
||||
- cp<python_version>-<abi>-<platform>
|
||||
- cp<python_version>-abi3-<platform>
|
||||
- cp<python_version>-none-<platform>
|
||||
- cp<less than python_version>-abi3-<platform> # Older Python versions down to 3.2.
|
||||
The specific tags generated are:
|
||||
|
||||
If python_version only specifies a major version then user-provided ABIs and
|
||||
the 'none' ABItag will be used.
|
||||
- ``cp<python_version>-<abi>-<platform>``
|
||||
- ``cp<python_version>-<stable_abi>-<platform>``
|
||||
- ``cp<python_version>-none-<platform>``
|
||||
- ``cp<older version>-<stable_abi>-<platform>`` where "older version" is all older
|
||||
minor versions down to Python 3.2 (when ``abi3`` was introduced)
|
||||
|
||||
If 'abi3' or 'none' are specified in 'abis' then they will be yielded at
|
||||
their normal position and not at the beginning.
|
||||
If ``python_version`` only provides a major-only version then only
|
||||
user-provided ABIs via ``abis`` and the ``none`` ABI will be used.
|
||||
|
||||
The ``stable_abi`` will be either ``abi3`` or ``abi3t`` if `abi` is a
|
||||
GIL-enabled ABI like `"cp315"` or a free-threaded ABI like `"cp315t"`,
|
||||
respectively.
|
||||
|
||||
:param Sequence python_version: A one- or two-item sequence representing the
|
||||
targeted Python version. Defaults to
|
||||
``sys.version_info[:2]``.
|
||||
:param Iterable abis: Iterable of compatible ABIs. Defaults to the ABIs
|
||||
compatible with the current system.
|
||||
:param Iterable platforms: Iterable of compatible platforms. Defaults to the
|
||||
platforms compatible with the current system.
|
||||
:param bool warn: Whether warnings should be logged. Defaults to ``False``.
|
||||
|
||||
.. versionadded:: 20.0
|
||||
"""
|
||||
if not python_version:
|
||||
python_version = sys.version_info[:2]
|
||||
@@ -219,8 +439,10 @@ def cpython_tags(
|
||||
if abis is None:
|
||||
abis = _cpython_abis(python_version, warn) if len(python_version) > 1 else []
|
||||
abis = list(abis)
|
||||
# 'abi3' and 'none' are explicitly handled later.
|
||||
for explicit_abi in ("abi3", "none"):
|
||||
threading = _is_threaded_cpython(abis)
|
||||
# Stable ABIs and 'none' are explicitly handled later.
|
||||
explicit_abis = ("abi3", "abi3t", "none") if threading else ("abi3", "none")
|
||||
for explicit_abi in explicit_abis:
|
||||
try:
|
||||
abis.remove(explicit_abi)
|
||||
except ValueError: # noqa: PERF203
|
||||
@@ -231,18 +453,27 @@ def cpython_tags(
|
||||
for platform_ in platforms:
|
||||
yield Tag(interpreter, abi, platform_)
|
||||
|
||||
threading = _is_threaded_cpython(abis)
|
||||
use_abi3 = _abi3_applies(python_version, threading)
|
||||
use_abi3t = _abi3t_applies(python_version, threading)
|
||||
if use_abi3:
|
||||
yield from (Tag(interpreter, "abi3", platform_) for platform_ in platforms)
|
||||
if use_abi3t:
|
||||
yield from (Tag(interpreter, "abi3t", platform_) for platform_ in platforms)
|
||||
|
||||
yield from (Tag(interpreter, "none", platform_) for platform_ in platforms)
|
||||
|
||||
if use_abi3:
|
||||
if use_abi3 or use_abi3t:
|
||||
for minor_version in range(python_version[1] - 1, 1, -1):
|
||||
for platform_ in platforms:
|
||||
version = _version_nodot((python_version[0], minor_version))
|
||||
interpreter = f"cp{version}"
|
||||
yield Tag(interpreter, "abi3", platform_)
|
||||
if use_abi3:
|
||||
yield Tag(interpreter, "abi3", platform_)
|
||||
if use_abi3t:
|
||||
# Support for abi3t was introduced in Python 3.15, but in
|
||||
# principle abi3t wheels are possible for older limited API
|
||||
# versions, so allow things like ("cp37", "abi3t", "platform")
|
||||
yield Tag(interpreter, "abi3t", platform_)
|
||||
|
||||
|
||||
def _generic_abi() -> list[str]:
|
||||
@@ -261,7 +492,7 @@ def _generic_abi() -> list[str]:
|
||||
# => graalpy_38_native
|
||||
|
||||
ext_suffix = _get_config_var("EXT_SUFFIX", warn=True)
|
||||
if not isinstance(ext_suffix, str) or ext_suffix[0] != ".":
|
||||
if not isinstance(ext_suffix, str) or not ext_suffix.startswith("."):
|
||||
raise SystemError("invalid sysconfig.get_config_var('EXT_SUFFIX')")
|
||||
parts = ext_suffix.split(".")
|
||||
if len(parts) < 3:
|
||||
@@ -270,7 +501,10 @@ def _generic_abi() -> list[str]:
|
||||
soabi = parts[1]
|
||||
if soabi.startswith("cpython"):
|
||||
# non-windows
|
||||
abi = "cp" + soabi.split("-")[1]
|
||||
cpython_parts = soabi.split("-")
|
||||
if len(cpython_parts) < 2 or not cpython_parts[1]:
|
||||
raise SystemError("invalid sysconfig.get_config_var('EXT_SUFFIX')")
|
||||
abi = "cp" + cpython_parts[1]
|
||||
elif soabi.startswith("cp"):
|
||||
# windows
|
||||
abi = soabi.split("-")[0]
|
||||
@@ -294,12 +528,27 @@ def generic_tags(
|
||||
warn: bool = False,
|
||||
) -> Iterator[Tag]:
|
||||
"""
|
||||
Yields the tags for a generic interpreter.
|
||||
Yields the tags for an interpreter which requires no specialization.
|
||||
|
||||
The tags consist of:
|
||||
- <interpreter>-<abi>-<platform>
|
||||
This function should be used if one of the other interpreter-specific
|
||||
functions provided by this module is not appropriate (i.e. not calculating
|
||||
tags for a CPython interpreter).
|
||||
|
||||
The "none" ABI will be added if it was not explicitly provided.
|
||||
The specific tags generated are:
|
||||
|
||||
- ``<interpreter>-<abi>-<platform>``
|
||||
|
||||
The ``"none"`` ABI will be added if it was not explicitly provided.
|
||||
|
||||
:param str interpreter: The name of the interpreter. Defaults to being
|
||||
calculated.
|
||||
:param Iterable abis: Iterable of compatible ABIs. Defaults to the ABIs
|
||||
compatible with the current system.
|
||||
:param Iterable platforms: Iterable of compatible platforms. Defaults to the
|
||||
platforms compatible with the current system.
|
||||
:param bool warn: Whether warnings should be logged. Defaults to ``False``.
|
||||
|
||||
.. versionadded:: 20.0
|
||||
"""
|
||||
if not interpreter:
|
||||
interp_name = interpreter_name()
|
||||
@@ -329,18 +578,54 @@ def _py_interpreter_range(py_version: PythonVersion) -> Iterator[str]:
|
||||
yield f"py{_version_nodot((py_version[0], minor))}"
|
||||
|
||||
|
||||
def pure_python_tags(
|
||||
python_version: PythonVersion | None = None,
|
||||
) -> Iterator[Tag]:
|
||||
"""
|
||||
Yields the pure-Python tags compatible with ``python_version``.
|
||||
|
||||
The tags use the ``"none"`` ABI and ``"any"`` platform, so their
|
||||
generation does not depend on the running platform.
|
||||
|
||||
.. versionadded:: 26.3
|
||||
|
||||
:param Sequence python_version: A one- or two-item sequence representing the
|
||||
compatible version of Python. Defaults to
|
||||
``sys.version_info[:2]``.
|
||||
:raises ValueError: If ``python_version`` is an empty sequence.
|
||||
"""
|
||||
if python_version is None:
|
||||
python_version = sys.version_info[:2]
|
||||
elif not python_version:
|
||||
raise ValueError("python_version must contain at least one item")
|
||||
for version in _py_interpreter_range(python_version):
|
||||
yield Tag(version, "none", "any")
|
||||
|
||||
|
||||
def compatible_tags(
|
||||
python_version: PythonVersion | None = None,
|
||||
interpreter: str | None = None,
|
||||
platforms: Iterable[str] | None = None,
|
||||
) -> Iterator[Tag]:
|
||||
"""
|
||||
Yields the sequence of tags that are compatible with a specific version of Python.
|
||||
Yields the tags for an interpreter compatible with the Python version
|
||||
specified by ``python_version``.
|
||||
|
||||
The tags consist of:
|
||||
- py*-none-<platform>
|
||||
- <interpreter>-none-any # ... if `interpreter` is provided.
|
||||
- py*-none-any
|
||||
The specific tags generated are:
|
||||
|
||||
- ``py*-none-<platform>``
|
||||
- ``<interpreter>-none-any`` if ``interpreter`` is provided
|
||||
- ``py*-none-any``
|
||||
|
||||
:param Sequence python_version: A one- or two-item sequence representing the
|
||||
compatible version of Python. Defaults to
|
||||
``sys.version_info[:2]``.
|
||||
:param str interpreter: The name of the interpreter (if known), e.g.
|
||||
``"cp38"``. Defaults to the current interpreter.
|
||||
:param Iterable platforms: Iterable of compatible platforms. Defaults to the
|
||||
platforms compatible with the current system.
|
||||
|
||||
.. versionadded:: 20.0
|
||||
"""
|
||||
if not python_version:
|
||||
python_version = sys.version_info[:2]
|
||||
@@ -350,8 +635,7 @@ def compatible_tags(
|
||||
yield Tag(version, "none", platform_)
|
||||
if interpreter:
|
||||
yield Tag(interpreter, "none", "any")
|
||||
for version in _py_interpreter_range(python_version):
|
||||
yield Tag(version, "none", "any")
|
||||
yield from pure_python_tags(python_version)
|
||||
|
||||
|
||||
def _mac_arch(arch: str, is_32bit: bool = _32_BIT_INTERPRETER) -> str:
|
||||
@@ -369,12 +653,12 @@ def _mac_binary_formats(version: AppleVersion, cpu_arch: str) -> list[str]:
|
||||
if cpu_arch == "x86_64":
|
||||
if version < (10, 4):
|
||||
return []
|
||||
formats.extend(["intel", "fat64", "fat32"])
|
||||
formats.extend(["intel", "fat64", "fat3"])
|
||||
|
||||
elif cpu_arch == "i386":
|
||||
if version < (10, 4):
|
||||
return []
|
||||
formats.extend(["intel", "fat32", "fat"])
|
||||
formats.extend(["intel", "fat3", "fat"])
|
||||
|
||||
elif cpu_arch == "ppc64":
|
||||
# TODO: Need to care about 32-bit PPC for ppc64 through 10.2?
|
||||
@@ -385,7 +669,7 @@ def _mac_binary_formats(version: AppleVersion, cpu_arch: str) -> list[str]:
|
||||
elif cpu_arch == "ppc":
|
||||
if version > (10, 6):
|
||||
return []
|
||||
formats.extend(["fat32", "fat"])
|
||||
formats.extend(["fat3", "fat"])
|
||||
|
||||
if cpu_arch in {"arm64", "x86_64"}:
|
||||
formats.append("universal2")
|
||||
@@ -400,35 +684,52 @@ def mac_platforms(
|
||||
version: AppleVersion | None = None, arch: str | None = None
|
||||
) -> Iterator[str]:
|
||||
"""
|
||||
Yields the platform tags for a macOS system.
|
||||
Yields the :attr:`~Tag.platform` tags for macOS.
|
||||
|
||||
The `version` parameter is a two-item tuple specifying the macOS version to
|
||||
generate platform tags for. The `arch` parameter is the CPU architecture to
|
||||
generate platform tags for. Both parameters default to the appropriate value
|
||||
for the current system.
|
||||
"""
|
||||
version_str, _, cpu_arch = platform.mac_ver()
|
||||
if version is None:
|
||||
version = cast("AppleVersion", tuple(map(int, version_str.split(".")[:2])))
|
||||
if version == (10, 16):
|
||||
# When built against an older macOS SDK, Python will report macOS 10.16
|
||||
# instead of the real version.
|
||||
version_str = subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
"-sS",
|
||||
"-c",
|
||||
"import platform; print(platform.mac_ver()[0])",
|
||||
],
|
||||
check=True,
|
||||
env={"SYSTEM_VERSION_COMPAT": "0"},
|
||||
stdout=subprocess.PIPE,
|
||||
text=True,
|
||||
).stdout
|
||||
version = cast("AppleVersion", tuple(map(int, version_str.split(".")[:2])))
|
||||
|
||||
if arch is None:
|
||||
arch = _mac_arch(cpu_arch)
|
||||
:param tuple version: A two-item tuple representing the version of macOS.
|
||||
Defaults to the current system's version.
|
||||
:param str arch: The CPU architecture. Defaults to the architecture of the
|
||||
current system, e.g. ``"x86_64"``.
|
||||
|
||||
.. note::
|
||||
Equivalent support for the other major platforms is purposefully not
|
||||
provided:
|
||||
|
||||
- On Windows, platform compatibility is statically specified
|
||||
- On Linux, code must be run on the system itself to determine
|
||||
compatibility
|
||||
|
||||
.. versionadded:: 20.0
|
||||
"""
|
||||
if version is None or arch is None:
|
||||
version_str, _, cpu_arch = platform.mac_ver()
|
||||
if version is None:
|
||||
version = cast("AppleVersion", tuple(map(int, version_str.split(".")[:2])))
|
||||
if version == (10, 16):
|
||||
# When built against an older macOS SDK, Python will report macOS 10.16
|
||||
# instead of the real version.
|
||||
version_str = subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
"-sS",
|
||||
"-c",
|
||||
"import platform; print(platform.mac_ver()[0])",
|
||||
],
|
||||
check=True,
|
||||
env={"SYSTEM_VERSION_COMPAT": "0"},
|
||||
stdout=subprocess.PIPE,
|
||||
text=True,
|
||||
).stdout
|
||||
version = cast(
|
||||
"AppleVersion", tuple(map(int, version_str.split(".")[:2]))
|
||||
)
|
||||
if arch is None:
|
||||
arch = _mac_arch(cpu_arch)
|
||||
|
||||
if (10, 0) <= version < (11, 0):
|
||||
# Prior to Mac OS 11, each yearly release of Mac OS bumped the
|
||||
@@ -450,7 +751,6 @@ def mac_platforms(
|
||||
for binary_format in binary_formats:
|
||||
yield f"macosx_{major_version}_{minor_version}_{binary_format}"
|
||||
|
||||
if version >= (11, 0):
|
||||
# Mac OS 11 on x86_64 is compatible with binaries from previous releases.
|
||||
# Arm64 support was introduced in 11.0, so no Arm binaries from previous
|
||||
# releases exist.
|
||||
@@ -476,14 +776,21 @@ def ios_platforms(
|
||||
version: AppleVersion | None = None, multiarch: str | None = None
|
||||
) -> Iterator[str]:
|
||||
"""
|
||||
Yields the platform tags for an iOS system.
|
||||
|
||||
:param version: A two-item tuple specifying the iOS version to generate
|
||||
platform tags for. Defaults to the current iOS version.
|
||||
:param multiarch: The CPU architecture+ABI to generate platform tags for -
|
||||
(the value used by `sys.implementation._multiarch` e.g.,
|
||||
`arm64_iphoneos` or `x84_64_iphonesimulator`). Defaults to the current
|
||||
multiarch value.
|
||||
Yields the :attr:`~Tag.platform` tags for iOS.
|
||||
|
||||
:param tuple version: A two-item tuple representing the version of iOS.
|
||||
Defaults to the current system's version.
|
||||
:param str multiarch: The CPU architecture+ABI to be used. This should be in
|
||||
the format by ``sys.implementation._multiarch`` (e.g.,
|
||||
``arm64_iphoneos`` or ``x86_64_iphonesimulator``).
|
||||
Defaults to the current system's multiarch value.
|
||||
|
||||
.. note::
|
||||
Behavior of this method is undefined if invoked on non-iOS platforms
|
||||
without providing explicit version and multiarch arguments.
|
||||
|
||||
.. versionadded:: 24.2
|
||||
"""
|
||||
if version is None:
|
||||
# if iOS is the current platform, ios_ver *must* be defined. However,
|
||||
@@ -543,6 +850,8 @@ def android_platforms(
|
||||
e.g. ``arm64_v8a``. Defaults to the current system's ABI , as returned by
|
||||
``sysconfig.get_platform``. Hyphens and periods will be replaced with
|
||||
underscores.
|
||||
|
||||
.. versionadded:: 25.0
|
||||
"""
|
||||
if platform.system() != "Android" and (api_level is None or abi is None):
|
||||
raise TypeError(
|
||||
@@ -579,10 +888,19 @@ def _linux_platforms(is_32bit: bool = _32_BIT_INTERPRETER) -> Iterator[str]:
|
||||
linux = "linux_armv8l"
|
||||
_, arch = linux.split("_", 1)
|
||||
archs = {"armv8l": ["armv8l", "armv7l"]}.get(arch, [arch])
|
||||
yield from _manylinux.platform_tags(archs)
|
||||
yield from _musllinux.platform_tags(archs)
|
||||
for arch in archs:
|
||||
yield f"linux_{arch}"
|
||||
yield from _manylinux.platform_tags(archs)
|
||||
yield from _musllinux.platform_tags(archs)
|
||||
|
||||
|
||||
def _emscripten_platforms() -> Iterator[str]:
|
||||
pyemscripten_platform_version = sysconfig.get_config_var(
|
||||
"PYEMSCRIPTEN_PLATFORM_VERSION"
|
||||
)
|
||||
if pyemscripten_platform_version:
|
||||
yield f"pyemscripten_{pyemscripten_platform_version}_wasm32"
|
||||
yield from _generic_platforms()
|
||||
|
||||
|
||||
def _generic_platforms() -> Iterator[str]:
|
||||
@@ -591,7 +909,9 @@ def _generic_platforms() -> Iterator[str]:
|
||||
|
||||
def platform_tags() -> Iterator[str]:
|
||||
"""
|
||||
Provides the platform tags for this installation.
|
||||
Yields the :attr:`~Tag.platform` tags for the running interpreter.
|
||||
|
||||
.. versionadded:: 21.1
|
||||
"""
|
||||
if platform.system() == "Darwin":
|
||||
return mac_platforms()
|
||||
@@ -601,6 +921,8 @@ def platform_tags() -> Iterator[str]:
|
||||
return android_platforms()
|
||||
elif platform.system() == "Linux":
|
||||
return _linux_platforms()
|
||||
elif platform.system() == "Emscripten":
|
||||
return _emscripten_platforms()
|
||||
else:
|
||||
return _generic_platforms()
|
||||
|
||||
@@ -611,6 +933,10 @@ def interpreter_name() -> str:
|
||||
|
||||
Some implementations have a reserved, two-letter abbreviation which will
|
||||
be returned when appropriate.
|
||||
|
||||
This typically acts as the prefix to the :attr:`~Tag.interpreter` tag.
|
||||
|
||||
.. versionadded:: 20.0
|
||||
"""
|
||||
name = sys.implementation.name
|
||||
return INTERPRETER_SHORT_NAMES.get(name) or name
|
||||
@@ -618,7 +944,13 @@ def interpreter_name() -> str:
|
||||
|
||||
def interpreter_version(*, warn: bool = False) -> str:
|
||||
"""
|
||||
Returns the version of the running interpreter.
|
||||
Returns the running interpreter's version.
|
||||
|
||||
This typically acts as the suffix to the :attr:`~Tag.interpreter` tag.
|
||||
|
||||
:param bool warn: Whether warnings should be logged. Defaults to ``False``.
|
||||
|
||||
.. versionadded:: 20.0
|
||||
"""
|
||||
version = _get_config_var("py_version_nodot", warn=warn)
|
||||
return str(version) if version else _version_nodot(sys.version_info[:2])
|
||||
@@ -630,17 +962,41 @@ def _version_nodot(version: PythonVersion) -> str:
|
||||
|
||||
def sys_tags(*, warn: bool = False) -> Iterator[Tag]:
|
||||
"""
|
||||
Returns the sequence of tag triples for the running interpreter.
|
||||
Yields the sequence of tag triples that the running interpreter supports.
|
||||
|
||||
The order of the sequence corresponds to priority order for the
|
||||
interpreter, from most to least important.
|
||||
The iterable is ordered so that the best-matching tag is first in the
|
||||
sequence. The exact preferential order to tags is interpreter-specific, but
|
||||
in general the tag importance is in the order of:
|
||||
|
||||
1. Interpreter
|
||||
2. Platform
|
||||
3. ABI
|
||||
|
||||
This order is due to the fact that an ABI is inherently tied to the
|
||||
platform, but platform-specific code is not necessarily tied to the ABI. The
|
||||
interpreter is the most important tag as it dictates basic support for any
|
||||
wheel.
|
||||
|
||||
The function returns an iterable in order to allow for the possible
|
||||
short-circuiting of tag generation if the entire sequence is not necessary
|
||||
and tag calculation happens to be expensive.
|
||||
|
||||
:param bool warn: Whether warnings should be logged. Defaults to ``False``.
|
||||
|
||||
.. versionchanged:: 21.3
|
||||
Added the `pp3-none-any` tag (:issue:`311`).
|
||||
.. versionchanged:: 26.1
|
||||
Added the `abi3t` tag (:issue:`1099`).
|
||||
.. versionchanged:: 26.3
|
||||
Native ``linux_*`` platform tags are now ordered before ``manylinux``
|
||||
and ``musllinux`` tags (:issue:`160`).
|
||||
"""
|
||||
|
||||
interp_name = interpreter_name()
|
||||
if interp_name == "cp":
|
||||
yield from cpython_tags(warn=warn)
|
||||
else:
|
||||
yield from generic_tags()
|
||||
yield from generic_tags(warn=warn)
|
||||
|
||||
if interp_name == "pp":
|
||||
interp = "pp3"
|
||||
@@ -649,3 +1005,49 @@ def sys_tags(*, warn: bool = False) -> Iterator[Tag]:
|
||||
else:
|
||||
interp = None
|
||||
yield from compatible_tags(interpreter=interp)
|
||||
|
||||
|
||||
def create_compatible_tags_selector(
|
||||
tags: Iterable[Tag],
|
||||
) -> Callable[[Iterable[tuple[_T, AbstractSet[Tag]]]], Iterator[_T]]:
|
||||
"""Create a callable to select things compatible with supported tags.
|
||||
|
||||
This function accepts an ordered sequence of tags, with the preferred
|
||||
tags first.
|
||||
|
||||
The returned callable accepts an iterable of tuples (thing, set[Tag]),
|
||||
and returns an iterator of things, with the things with the best
|
||||
matching tags first.
|
||||
|
||||
Example to select compatible wheel filenames:
|
||||
|
||||
>>> from packaging import tags
|
||||
>>> from packaging.utils import parse_wheel_filename
|
||||
>>> selector = tags.create_compatible_tags_selector(tags.sys_tags())
|
||||
>>> filenames = ["foo-1.0-py3-none-any.whl", "foo-1.0-py2-none-any.whl"]
|
||||
>>> list(selector([
|
||||
... (filename, parse_wheel_filename(filename)[-1]) for filename in filenames
|
||||
... ]))
|
||||
['foo-1.0-py3-none-any.whl']
|
||||
|
||||
.. versionadded:: 26.1
|
||||
"""
|
||||
tag_ranks: dict[Tag, int] = {}
|
||||
for rank, tag in enumerate(tags):
|
||||
tag_ranks.setdefault(tag, rank) # ignore duplicate tags, keep first
|
||||
supported_tags = tag_ranks.keys()
|
||||
|
||||
def selector(
|
||||
tagged_things: Iterable[tuple[_T, AbstractSet[Tag]]],
|
||||
) -> Iterator[_T]:
|
||||
ranked_things: list[tuple[_T, int]] = []
|
||||
for thing, thing_tags in tagged_things:
|
||||
supported_thing_tags = thing_tags & supported_tags
|
||||
if supported_thing_tags:
|
||||
thing_rank = min(tag_ranks[t] for t in supported_thing_tags)
|
||||
ranked_things.append((thing, thing_rank))
|
||||
return iter(
|
||||
thing for thing, _ in sorted(ranked_things, key=operator.itemgetter(1))
|
||||
)
|
||||
|
||||
return selector
|
||||
@@ -5,41 +5,113 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from typing import NewType, Tuple, Union, cast
|
||||
from typing import NewType, Union, cast
|
||||
|
||||
from .tags import Tag, parse_tag
|
||||
from .tags import InvalidTag, Tag, UnsortedTagsError, parse_tag
|
||||
from .version import InvalidVersion, Version, _TrimmedRelease
|
||||
|
||||
BuildTag = Union[Tuple[()], Tuple[int, str]]
|
||||
__all__ = [
|
||||
"BuildTag",
|
||||
"InvalidName",
|
||||
"InvalidSdistFilename",
|
||||
"InvalidWheelFilename",
|
||||
"NormalizedName",
|
||||
"canonicalize_name",
|
||||
"canonicalize_version",
|
||||
"is_normalized_name",
|
||||
"parse_sdist_filename",
|
||||
"parse_wheel_filename",
|
||||
]
|
||||
|
||||
|
||||
def __dir__() -> list[str]:
|
||||
return __all__
|
||||
|
||||
|
||||
BuildTag = Union[tuple[()], tuple[int, str]]
|
||||
"""
|
||||
A wheel build tag: an empty tuple, or a ``(build number, build tag suffix)`` pair.
|
||||
|
||||
.. versionadded:: 20.9
|
||||
"""
|
||||
|
||||
NormalizedName = NewType("NormalizedName", str)
|
||||
"""
|
||||
A :class:`typing.NewType` of :class:`str`, representing a normalized name.
|
||||
|
||||
.. versionadded:: 20.4
|
||||
"""
|
||||
|
||||
|
||||
class InvalidName(ValueError):
|
||||
"""
|
||||
An invalid distribution name; users should refer to the packaging user guide.
|
||||
|
||||
.. versionadded:: 23.2
|
||||
"""
|
||||
|
||||
|
||||
class InvalidWheelFilename(ValueError):
|
||||
"""
|
||||
An invalid wheel filename was found, users should refer to PEP 427.
|
||||
|
||||
.. versionadded:: 20.9
|
||||
"""
|
||||
|
||||
|
||||
class InvalidSdistFilename(ValueError):
|
||||
"""
|
||||
An invalid sdist filename was found, users should refer to the packaging user guide.
|
||||
|
||||
.. versionadded:: 20.9
|
||||
"""
|
||||
|
||||
|
||||
# Core metadata spec for `Name`
|
||||
_validate_regex = re.compile(r"[A-Z0-9]|[A-Z0-9][A-Z0-9._-]*[A-Z0-9]", re.IGNORECASE)
|
||||
_normalized_regex = re.compile(r"[a-z0-9]|[a-z0-9]([a-z0-9-](?!--))*[a-z0-9]")
|
||||
_validate_regex = re.compile(
|
||||
r"[a-z0-9]|[a-z0-9][a-z0-9._-]*[a-z0-9]", re.IGNORECASE | re.ASCII
|
||||
)
|
||||
_normalized_regex = re.compile(r"[a-z0-9]+(?:-[a-z0-9]+)*", re.ASCII)
|
||||
# PEP 427: The build number must start with a digit.
|
||||
_build_tag_regex = re.compile(r"(\d+)(.*)")
|
||||
_build_tag_regex = re.compile(r"(\d+)(.*)", re.ASCII)
|
||||
# PEP 427: Valid characters for an escaped project name in a wheel filename.
|
||||
# Requires at least one character so an empty project name is rejected.
|
||||
_wheel_name_regex = re.compile(r"^[\w._]+\Z", re.UNICODE)
|
||||
|
||||
|
||||
def canonicalize_name(name: str, *, validate: bool = False) -> NormalizedName:
|
||||
"""
|
||||
This function takes a valid Python package or extra name, and returns the
|
||||
normalized form of it.
|
||||
|
||||
The return type is typed as :class:`NormalizedName`. This allows type
|
||||
checkers to help require that a string has passed through this function
|
||||
before use.
|
||||
|
||||
If **validate** is true, then the function will check if **name** is a valid
|
||||
distribution name before normalizing.
|
||||
|
||||
:param str name: The name to normalize.
|
||||
:param bool validate: Check whether the name is a valid distribution name.
|
||||
:raises InvalidName: If **validate** is true and the name is not an
|
||||
acceptable distribution name.
|
||||
|
||||
>>> from packaging.utils import canonicalize_name
|
||||
>>> canonicalize_name("Django")
|
||||
'django'
|
||||
>>> canonicalize_name("oslo.concurrency")
|
||||
'oslo-concurrency'
|
||||
>>> canonicalize_name("requests")
|
||||
'requests'
|
||||
|
||||
.. versionadded:: 16.2
|
||||
|
||||
.. versionchanged:: 20.4
|
||||
The return type was changed to :class:`NormalizedName`.
|
||||
|
||||
.. versionchanged:: 23.2
|
||||
Added the *validate* keyword parameter.
|
||||
"""
|
||||
if validate and not _validate_regex.fullmatch(name):
|
||||
raise InvalidName(f"name is invalid: {name!r}")
|
||||
# Ensure all ``.`` and ``_`` are ``-``
|
||||
@@ -53,15 +125,43 @@ def canonicalize_name(name: str, *, validate: bool = False) -> NormalizedName:
|
||||
|
||||
|
||||
def is_normalized_name(name: str) -> bool:
|
||||
"""
|
||||
Check if a name is a normalized project name (i.e. a valid name that
|
||||
:func:`canonicalize_name` would roundtrip to the same value).
|
||||
|
||||
The roundtrip only characterizes normalized names for *valid* names. A name
|
||||
must start and end with an ASCII letter or digit, which
|
||||
:func:`canonicalize_name` does not enforce: it leaves a leading or trailing
|
||||
hyphen in place, so such a name roundtrips without being normalized.
|
||||
|
||||
:param str name: The name to check.
|
||||
|
||||
>>> from packaging.utils import canonicalize_name, is_normalized_name
|
||||
>>> is_normalized_name("requests")
|
||||
True
|
||||
>>> is_normalized_name("Django")
|
||||
False
|
||||
>>> canonicalize_name("_not_legal")
|
||||
'-not-legal'
|
||||
>>> is_normalized_name("-not-legal") # roundtrips, but not a valid name
|
||||
False
|
||||
|
||||
.. versionadded:: 23.2
|
||||
"""
|
||||
return _normalized_regex.fullmatch(name) is not None
|
||||
|
||||
|
||||
def canonicalize_version(
|
||||
version: Version | str, *, strip_trailing_zero: bool = True
|
||||
) -> str:
|
||||
"""
|
||||
Return a canonical form of a version as a string.
|
||||
"""Return a canonical form of a version as a string.
|
||||
|
||||
This function takes a string representing a package version (or a
|
||||
:class:`~packaging.version.Version` instance), and returns the
|
||||
normalized form of it. By default, it strips trailing zeros from
|
||||
the release segment.
|
||||
|
||||
>>> from packaging.utils import canonicalize_version
|
||||
>>> canonicalize_version('1.0.1')
|
||||
'1.0.1'
|
||||
|
||||
@@ -77,6 +177,17 @@ def canonicalize_version(
|
||||
|
||||
>>> canonicalize_version('foo bar baz')
|
||||
'foo bar baz'
|
||||
|
||||
>>> canonicalize_version('1.4.0.0.0')
|
||||
'1.4'
|
||||
|
||||
.. versionadded:: 17.1
|
||||
|
||||
.. versionchanged:: 21.0
|
||||
The return type was narrowed to :class:`str`.
|
||||
|
||||
.. versionchanged:: 22.0
|
||||
Added the *strip_trailing_zero* keyword parameter.
|
||||
"""
|
||||
if isinstance(version, str):
|
||||
try:
|
||||
@@ -88,7 +199,59 @@ def canonicalize_version(
|
||||
|
||||
def parse_wheel_filename(
|
||||
filename: str,
|
||||
*,
|
||||
validate_order: bool = False,
|
||||
) -> tuple[NormalizedName, Version, BuildTag, frozenset[Tag]]:
|
||||
"""
|
||||
This function takes the filename of a wheel file, and parses it,
|
||||
returning a tuple of name, version, build number, and tags.
|
||||
|
||||
The name part of the tuple is normalized and typed as
|
||||
:class:`NormalizedName`. The version portion is an instance of
|
||||
:class:`~packaging.version.Version`. The build number is ``()`` if
|
||||
there is no build number in the wheel filename, otherwise a
|
||||
two-item tuple of an integer for the leading digits and
|
||||
a string for the rest of the build number. The tags portion is a
|
||||
frozen set of :class:`~packaging.tags.Tag` instances (as the tag
|
||||
string format allows multiple tags to be combined into a single
|
||||
string).
|
||||
|
||||
If **validate_order** is true, compressed tag set components are
|
||||
checked to be in sorted order as required by PEP 425.
|
||||
|
||||
:param str filename: The name of the wheel file.
|
||||
:param bool validate_order: Check whether compressed tag set components
|
||||
are in sorted order.
|
||||
:raises InvalidWheelFilename: If the filename in question
|
||||
does not follow the :ref:`wheel specification
|
||||
<pypug:binary-distribution-format>`.
|
||||
|
||||
>>> from packaging.utils import parse_wheel_filename
|
||||
>>> from packaging.tags import Tag
|
||||
>>> from packaging.version import Version
|
||||
>>> name, ver, build, tags = parse_wheel_filename("foo-1.0-py3-none-any.whl")
|
||||
>>> name
|
||||
'foo'
|
||||
>>> ver == Version('1.0')
|
||||
True
|
||||
>>> tags == {Tag("py3", "none", "any")}
|
||||
True
|
||||
>>> not build
|
||||
True
|
||||
|
||||
.. versionadded:: 20.9
|
||||
|
||||
.. versionchanged:: 23.2
|
||||
Raises :class:`InvalidWheelFilename` when the version component is invalid.
|
||||
|
||||
.. versionadded:: 26.1
|
||||
The *validate_order* parameter.
|
||||
|
||||
.. versionchanged:: 26.3
|
||||
Raises :class:`InvalidWheelFilename` when an interpreter component is
|
||||
not an identifier, a tag set component is empty, or the project name is
|
||||
empty.
|
||||
"""
|
||||
if not filename.endswith(".whl"):
|
||||
raise InvalidWheelFilename(
|
||||
f"Invalid wheel filename (extension must be '.whl'): {filename!r}"
|
||||
@@ -104,7 +267,7 @@ def parse_wheel_filename(
|
||||
parts = filename.split("-", dashes - 2)
|
||||
name_part = parts[0]
|
||||
# See PEP 427 for the rules on escaping the project name.
|
||||
if "__" in name_part or re.match(r"^[\w\d._]*$", name_part, re.UNICODE) is None:
|
||||
if "__" in name_part or _wheel_name_regex.match(name_part) is None:
|
||||
raise InvalidWheelFilename(f"Invalid project name: {filename!r}")
|
||||
name = canonicalize_name(name_part)
|
||||
|
||||
@@ -125,11 +288,56 @@ def parse_wheel_filename(
|
||||
build = cast("BuildTag", (int(build_match.group(1)), build_match.group(2)))
|
||||
else:
|
||||
build = ()
|
||||
tags = parse_tag(parts[-1])
|
||||
tag_str = parts[-1]
|
||||
try:
|
||||
tags = parse_tag(tag_str, validate_order=validate_order)
|
||||
except UnsortedTagsError:
|
||||
raise InvalidWheelFilename(
|
||||
f"Invalid wheel filename (compressed tag set components must be in "
|
||||
f"sorted order per PEP 425): {filename!r}"
|
||||
) from None
|
||||
except InvalidTag:
|
||||
raise InvalidWheelFilename(
|
||||
f"Invalid wheel filename (invalid tag component): {filename!r}"
|
||||
) from None
|
||||
return (name, version, build, tags)
|
||||
|
||||
|
||||
def parse_sdist_filename(filename: str) -> tuple[NormalizedName, Version]:
|
||||
"""
|
||||
This function takes the filename of a sdist file (as specified
|
||||
in the `Source distribution format`_ documentation), and parses
|
||||
it, returning a tuple of the normalized name and version as
|
||||
represented by an instance of :class:`~packaging.version.Version`.
|
||||
|
||||
:param str filename: The name of the sdist file.
|
||||
:raises InvalidSdistFilename: If the filename does not end
|
||||
with an sdist extension (``.zip`` or ``.tar.gz``), if it does not
|
||||
contain a dash separating the name and the version of the distribution,
|
||||
if the project name is empty, or if the version portion is not a valid
|
||||
version.
|
||||
|
||||
>>> from packaging.utils import parse_sdist_filename
|
||||
>>> from packaging.version import Version
|
||||
>>> name, ver = parse_sdist_filename("foo-1.0.tar.gz")
|
||||
>>> name
|
||||
'foo'
|
||||
>>> ver == Version('1.0')
|
||||
True
|
||||
|
||||
.. versionadded:: 20.9
|
||||
|
||||
.. versionchanged:: 21.0
|
||||
Added support for ``.zip`` source distributions.
|
||||
|
||||
.. versionchanged:: 23.2
|
||||
Raises :class:`InvalidSdistFilename` when the version component is invalid.
|
||||
|
||||
.. versionchanged:: 26.3
|
||||
Raises :class:`InvalidSdistFilename` on an empty project name.
|
||||
|
||||
.. _Source distribution format: https://packaging.python.org/specifications/source-distribution-format/#source-distribution-file-name
|
||||
"""
|
||||
if filename.endswith(".tar.gz"):
|
||||
file_stem = filename[: -len(".tar.gz")]
|
||||
elif filename.endswith(".zip"):
|
||||
@@ -145,6 +353,10 @@ def parse_sdist_filename(filename: str) -> tuple[NormalizedName, Version]:
|
||||
name_part, sep, version_part = file_stem.rpartition("-")
|
||||
if not sep:
|
||||
raise InvalidSdistFilename(f"Invalid sdist filename: {filename!r}")
|
||||
if not name_part:
|
||||
raise InvalidSdistFilename(
|
||||
f"Invalid sdist filename (empty project name): {filename!r}"
|
||||
)
|
||||
|
||||
name = canonicalize_name(name_part)
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"""
|
||||
.. testsetup::
|
||||
|
||||
from pip._vendor.packaging.version import parse, Version
|
||||
from pip._vendor.packaging.version import parse, normalize_pre, Version, _cmpkey
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -18,13 +18,10 @@ from typing import (
|
||||
Literal,
|
||||
NamedTuple,
|
||||
SupportsInt,
|
||||
Tuple,
|
||||
TypedDict,
|
||||
Union,
|
||||
)
|
||||
|
||||
from ._structures import Infinity, InfinityType, NegativeInfinity, NegativeInfinityType
|
||||
|
||||
if typing.TYPE_CHECKING:
|
||||
from typing_extensions import Self, Unpack
|
||||
|
||||
@@ -37,7 +34,7 @@ else: # pragma: no cover
|
||||
import warnings
|
||||
|
||||
def _deprecated(message: str) -> object:
|
||||
def decorator(func: object) -> object:
|
||||
def decorator(func: Callable[[...], object]) -> object:
|
||||
@functools.wraps(func)
|
||||
def wrapper(*args: object, **kwargs: object) -> object:
|
||||
warnings.warn(
|
||||
@@ -62,22 +59,20 @@ _LETTER_NORMALIZATION = {
|
||||
"r": "post",
|
||||
}
|
||||
|
||||
__all__ = ["VERSION_PATTERN", "InvalidVersion", "Version", "parse"]
|
||||
__all__ = ["VERSION_PATTERN", "InvalidVersion", "Version", "normalize_pre", "parse"]
|
||||
|
||||
LocalType = Tuple[Union[int, str], ...]
|
||||
|
||||
CmpPrePostDevType = Union[InfinityType, NegativeInfinityType, Tuple[str, int]]
|
||||
CmpLocalType = Union[
|
||||
NegativeInfinityType,
|
||||
Tuple[Union[Tuple[int, str], Tuple[NegativeInfinityType, Union[int, str]]], ...],
|
||||
]
|
||||
CmpKey = Tuple[
|
||||
int,
|
||||
Tuple[int, ...],
|
||||
CmpPrePostDevType,
|
||||
CmpPrePostDevType,
|
||||
CmpPrePostDevType,
|
||||
CmpLocalType,
|
||||
def __dir__() -> list[str]:
|
||||
return __all__
|
||||
|
||||
|
||||
LocalType = tuple[Union[int, str], ...]
|
||||
|
||||
CmpLocalType = tuple[tuple[int, str], ...]
|
||||
CmpSuffix = tuple[int, int, int, int, int, int]
|
||||
CmpKey = Union[
|
||||
tuple[int, tuple[int, ...], CmpSuffix],
|
||||
tuple[int, tuple[int, ...], CmpSuffix, CmpLocalType],
|
||||
]
|
||||
VersionComparisonMethod = Callable[[CmpKey, CmpKey], bool]
|
||||
|
||||
@@ -85,15 +80,38 @@ VersionComparisonMethod = Callable[[CmpKey, CmpKey], bool]
|
||||
class _VersionReplace(TypedDict, total=False):
|
||||
epoch: int | None
|
||||
release: tuple[int, ...] | None
|
||||
pre: tuple[Literal["a", "b", "rc"], int] | None
|
||||
pre: tuple[str, int] | None
|
||||
post: int | None
|
||||
dev: int | None
|
||||
local: str | None
|
||||
|
||||
|
||||
def normalize_pre(letter: str, /) -> str:
|
||||
"""Normalize the pre-release segment of a version string.
|
||||
|
||||
Returns a lowercase version of the string if not a known pre-release
|
||||
identifier.
|
||||
|
||||
>>> normalize_pre('alpha')
|
||||
'a'
|
||||
>>> normalize_pre('BETA')
|
||||
'b'
|
||||
>>> normalize_pre('rc')
|
||||
'rc'
|
||||
|
||||
:param letter:
|
||||
|
||||
.. versionadded:: 26.1
|
||||
"""
|
||||
letter = letter.lower()
|
||||
return _LETTER_NORMALIZATION.get(letter, letter)
|
||||
|
||||
|
||||
def parse(version: str) -> Version:
|
||||
"""Parse the given version string.
|
||||
|
||||
This is identical to the :class:`Version` constructor.
|
||||
|
||||
>>> parse('1.0.dev1')
|
||||
<Version('1.0.dev1')>
|
||||
|
||||
@@ -173,7 +191,7 @@ class _BaseVersion:
|
||||
# Note that ++ doesn't behave identically on CPython and PyPy, so not using it here
|
||||
_VERSION_PATTERN = r"""
|
||||
v?+ # optional leading v
|
||||
(?:
|
||||
(?a:
|
||||
(?:(?P<epoch>[0-9]+)!)?+ # epoch
|
||||
(?P<release>[0-9]+(?:\.[0-9]+)*+) # release segment
|
||||
(?P<pre> # pre-release
|
||||
@@ -199,7 +217,7 @@ _VERSION_PATTERN = r"""
|
||||
(?P<dev_n>[0-9]+)?
|
||||
)?+
|
||||
)
|
||||
(?:\+
|
||||
(?a:\+
|
||||
(?P<local> # local version
|
||||
[a-z0-9]+
|
||||
(?:[._-][a-z0-9]+)*+
|
||||
@@ -227,12 +245,21 @@ expressions (for example, matching a version number as part of a file name). The
|
||||
regular expression should be compiled with the ``re.VERBOSE`` and ``re.IGNORECASE``
|
||||
flags set.
|
||||
|
||||
.. versionchanged:: 26.0
|
||||
|
||||
The regex now uses possessive qualifiers on Python 3.11 if they are
|
||||
supported (CPython 3.11.5+, PyPy 3.11.13+).
|
||||
|
||||
:meta hide-value:
|
||||
"""
|
||||
|
||||
|
||||
# Validation pattern for local version in replace()
|
||||
_LOCAL_PATTERN = re.compile(r"[a-z0-9]+(?:[._-][a-z0-9]+)*", re.IGNORECASE)
|
||||
_LOCAL_PATTERN = re.compile(r"[a-z0-9]+(?:[._-][a-z0-9]+)*", re.IGNORECASE | re.ASCII)
|
||||
|
||||
# Fast path: If a version has only digits and dots then we
|
||||
# can skip the regex and parse it as a release segment
|
||||
_SIMPLE_VERSION_INDICATORS = frozenset(".0123456789")
|
||||
|
||||
|
||||
def _validate_epoch(value: object, /) -> int:
|
||||
@@ -258,14 +285,17 @@ def _validate_release(value: object, /) -> tuple[int, ...]:
|
||||
def _validate_pre(value: object, /) -> tuple[Literal["a", "b", "rc"], int] | None:
|
||||
if value is None:
|
||||
return value
|
||||
if (
|
||||
isinstance(value, tuple)
|
||||
and len(value) == 2
|
||||
and value[0] in ("a", "b", "rc")
|
||||
and isinstance(value[1], int)
|
||||
and value[1] >= 0
|
||||
):
|
||||
return value
|
||||
if isinstance(value, tuple) and len(value) == 2:
|
||||
letter, number = value
|
||||
# The letter must be a string before it can be normalized.
|
||||
if (
|
||||
isinstance(letter, str)
|
||||
and (normalized := normalize_pre(letter)) in {"a", "b", "rc"}
|
||||
and isinstance(number, int)
|
||||
and number >= 0
|
||||
):
|
||||
# type checkers can't infer the Literal type here on letter
|
||||
return (normalized, number) # type: ignore[return-value]
|
||||
msg = f"pre must be a tuple of ('a'|'b'|'rc', non-negative int), got {value}"
|
||||
raise InvalidVersion(msg)
|
||||
|
||||
@@ -301,9 +331,9 @@ def _validate_local(value: object, /) -> LocalType | None:
|
||||
class _Version(NamedTuple):
|
||||
epoch: int
|
||||
release: tuple[int, ...]
|
||||
dev: tuple[str, int] | None
|
||||
pre: tuple[str, int] | None
|
||||
post: tuple[str, int] | None
|
||||
dev: tuple[Literal["dev"], int] | None
|
||||
pre: tuple[Literal["a", "b", "rc"], int] | None
|
||||
post: tuple[Literal["post"], int] | None
|
||||
local: LocalType | None
|
||||
|
||||
|
||||
@@ -329,20 +359,50 @@ class Version(_BaseVersion):
|
||||
False
|
||||
>>> v1 <= v2
|
||||
True
|
||||
|
||||
:class:`Version` is immutable; use :meth:`__replace__` to change
|
||||
part of a version.
|
||||
|
||||
Instances are safe to serialize with :mod:`pickle`. They use a stable
|
||||
format so the same pickle can be loaded in future packaging releases.
|
||||
|
||||
.. versionchanged:: 26.2
|
||||
|
||||
Added a stable pickle format. Pickles created with packaging 26.2+ can
|
||||
be unpickled with future releases. Backward compatibility with pickles
|
||||
from pip._vendor.packaging < 26.2 is supported but may be removed in a future
|
||||
release.
|
||||
"""
|
||||
|
||||
__slots__ = ("_dev", "_epoch", "_key_cache", "_local", "_post", "_pre", "_release")
|
||||
__slots__ = (
|
||||
"_dev",
|
||||
"_epoch",
|
||||
"_hash_cache",
|
||||
"_key_cache",
|
||||
"_local",
|
||||
"_post",
|
||||
"_pre",
|
||||
"_release",
|
||||
)
|
||||
__match_args__ = ("_str",)
|
||||
"""
|
||||
Pattern matching is supported on Python 3.10+.
|
||||
|
||||
.. versionadded:: 26.0
|
||||
|
||||
:meta hide-value:
|
||||
"""
|
||||
|
||||
_regex = re.compile(r"\s*" + VERSION_PATTERN + r"\s*", re.VERBOSE | re.IGNORECASE)
|
||||
|
||||
_epoch: int
|
||||
_release: tuple[int, ...]
|
||||
_dev: tuple[str, int] | None
|
||||
_pre: tuple[str, int] | None
|
||||
_post: tuple[str, int] | None
|
||||
_dev: tuple[Literal["dev"], int] | None
|
||||
_pre: tuple[Literal["a", "b", "rc"], int] | None
|
||||
_post: tuple[Literal["post"], int] | None
|
||||
_local: LocalType | None
|
||||
|
||||
_hash_cache: int | None
|
||||
_key_cache: CmpKey | None
|
||||
|
||||
def __init__(self, version: str) -> None:
|
||||
@@ -355,23 +415,128 @@ class Version(_BaseVersion):
|
||||
If the ``version`` does not conform to PEP 440 in any way then this
|
||||
exception will be raised.
|
||||
"""
|
||||
try:
|
||||
is_simple = _SIMPLE_VERSION_INDICATORS.issuperset(version)
|
||||
except TypeError:
|
||||
raise InvalidVersion(f"Invalid version: {version!r}") from None
|
||||
|
||||
if is_simple:
|
||||
try:
|
||||
self._release = tuple(map(int, version.split(".")))
|
||||
except AttributeError:
|
||||
raise InvalidVersion(f"Invalid version: {version!r}") from None
|
||||
except ValueError:
|
||||
# Empty parts (from "1..2", ".1", etc.) are invalid versions.
|
||||
# Any other ValueError (e.g. int str-digits limit) should
|
||||
# propagate to the caller.
|
||||
if "" in version.split("."):
|
||||
raise InvalidVersion(f"Invalid version: {version!r}") from None
|
||||
# TODO: remove "no cover" when Python 3.9 is dropped.
|
||||
raise # pragma: no cover
|
||||
|
||||
self._epoch = 0
|
||||
self._pre = None
|
||||
self._post = None
|
||||
self._dev = None
|
||||
self._local = None
|
||||
self._key_cache = None
|
||||
self._hash_cache = None
|
||||
return
|
||||
|
||||
# Validate the version and parse it into pieces
|
||||
match = self._regex.fullmatch(version)
|
||||
try:
|
||||
match = self._regex.fullmatch(version)
|
||||
except TypeError:
|
||||
raise InvalidVersion(f"Invalid version: {version!r}") from None
|
||||
if not match:
|
||||
raise InvalidVersion(f"Invalid version: {version!r}")
|
||||
self._epoch = int(match.group("epoch")) if match.group("epoch") else 0
|
||||
self._release = tuple(map(int, match.group("release").split(".")))
|
||||
self._pre = _parse_letter_version(match.group("pre_l"), match.group("pre_n"))
|
||||
self._post = _parse_letter_version(
|
||||
# We can type ignore the assignments below because the regex guarantees
|
||||
# the correct strings
|
||||
self._pre = _parse_letter_version(match.group("pre_l"), match.group("pre_n")) # type: ignore[assignment]
|
||||
self._post = _parse_letter_version( # type: ignore[assignment]
|
||||
match.group("post_l"), match.group("post_n1") or match.group("post_n2")
|
||||
)
|
||||
self._dev = _parse_letter_version(match.group("dev_l"), match.group("dev_n"))
|
||||
self._dev = _parse_letter_version(match.group("dev_l"), match.group("dev_n")) # type: ignore[assignment]
|
||||
self._local = _parse_local_version(match.group("local"))
|
||||
|
||||
# Key which will be used for sorting
|
||||
self._key_cache = None
|
||||
self._hash_cache = None
|
||||
|
||||
@classmethod
|
||||
def from_parts(
|
||||
cls,
|
||||
*,
|
||||
epoch: int = 0,
|
||||
release: tuple[int, ...],
|
||||
pre: tuple[str, int] | None = None,
|
||||
post: int | None = None,
|
||||
dev: int | None = None,
|
||||
local: str | None = None,
|
||||
) -> Self:
|
||||
"""
|
||||
Return a new version composed of the various parts.
|
||||
|
||||
This allows you to build a version without going though a string and
|
||||
running a regular expression. It normalizes pre-release strings. The
|
||||
``release=`` keyword argument is required.
|
||||
|
||||
>>> Version.from_parts(release=(1,2,3))
|
||||
<Version('1.2.3')>
|
||||
>>> Version.from_parts(release=(0,1,0), pre=("b", 1))
|
||||
<Version('0.1.0b1')>
|
||||
|
||||
:param epoch:
|
||||
:param release: This version tuple is required
|
||||
|
||||
.. versionadded:: 26.1
|
||||
"""
|
||||
_epoch = _validate_epoch(epoch)
|
||||
_release = _validate_release(release)
|
||||
_pre = _validate_pre(pre) if pre is not None else None
|
||||
_post = _validate_post(post) if post is not None else None
|
||||
_dev = _validate_dev(dev) if dev is not None else None
|
||||
_local = _validate_local(local) if local is not None else None
|
||||
|
||||
new_version = cls.__new__(cls)
|
||||
new_version._key_cache = None
|
||||
new_version._hash_cache = None
|
||||
new_version._epoch = _epoch
|
||||
new_version._release = _release
|
||||
new_version._pre = _pre
|
||||
new_version._post = _post
|
||||
new_version._dev = _dev
|
||||
new_version._local = _local
|
||||
|
||||
return new_version
|
||||
|
||||
def __replace__(self, **kwargs: Unpack[_VersionReplace]) -> Self:
|
||||
"""
|
||||
__replace__(*, epoch=..., release=..., pre=..., post=..., dev=..., local=...)
|
||||
|
||||
Return a new version with parts replaced.
|
||||
|
||||
This returns a new version (unless no parts were changed). The
|
||||
pre-release is normalized. Setting a value to ``None`` clears it.
|
||||
|
||||
>>> v = Version("1.2.3")
|
||||
>>> v.__replace__(pre=("a", 1))
|
||||
<Version('1.2.3a1')>
|
||||
|
||||
:param int | None epoch:
|
||||
:param tuple[int, ...] | None release:
|
||||
:param tuple[str, int] | None pre:
|
||||
:param int | None post:
|
||||
:param int | None dev:
|
||||
:param str | None local:
|
||||
|
||||
.. versionadded:: 26.0
|
||||
.. versionchanged:: 26.1
|
||||
|
||||
The pre-release portion is now normalized.
|
||||
"""
|
||||
epoch = _validate_epoch(kwargs["epoch"]) if "epoch" in kwargs else self._epoch
|
||||
release = (
|
||||
_validate_release(kwargs["release"])
|
||||
@@ -395,6 +560,7 @@ class Version(_BaseVersion):
|
||||
|
||||
new_version = self.__class__.__new__(self.__class__)
|
||||
new_version._key_cache = None
|
||||
new_version._hash_cache = None
|
||||
new_version._epoch = epoch
|
||||
new_version._release = release
|
||||
new_version._pre = pre
|
||||
@@ -417,6 +583,255 @@ class Version(_BaseVersion):
|
||||
)
|
||||
return self._key_cache
|
||||
|
||||
# __hash__ must be defined when __eq__ is overridden,
|
||||
# otherwise Python sets __hash__ to None.
|
||||
def __hash__(self) -> int:
|
||||
if (cached_hash := self._hash_cache) is not None:
|
||||
return cached_hash
|
||||
|
||||
if (key := self._key_cache) is None:
|
||||
self._key_cache = key = _cmpkey(
|
||||
self._epoch,
|
||||
self._release,
|
||||
self._pre,
|
||||
self._post,
|
||||
self._dev,
|
||||
self._local,
|
||||
)
|
||||
self._hash_cache = cached_hash = hash(key)
|
||||
return cached_hash
|
||||
|
||||
# Override comparison methods to use direct _key_cache access
|
||||
# This is faster than property access, especially before Python 3.12
|
||||
def __lt__(self, other: _BaseVersion) -> bool:
|
||||
if isinstance(other, Version):
|
||||
if self._key_cache is None:
|
||||
self._key_cache = _cmpkey(
|
||||
self._epoch,
|
||||
self._release,
|
||||
self._pre,
|
||||
self._post,
|
||||
self._dev,
|
||||
self._local,
|
||||
)
|
||||
if other._key_cache is None:
|
||||
other._key_cache = _cmpkey(
|
||||
other._epoch,
|
||||
other._release,
|
||||
other._pre,
|
||||
other._post,
|
||||
other._dev,
|
||||
other._local,
|
||||
)
|
||||
return self._key_cache < other._key_cache
|
||||
|
||||
if not isinstance(other, _BaseVersion):
|
||||
return NotImplemented
|
||||
|
||||
return super().__lt__(other)
|
||||
|
||||
def __le__(self, other: _BaseVersion) -> bool:
|
||||
if isinstance(other, Version):
|
||||
if self._key_cache is None:
|
||||
self._key_cache = _cmpkey(
|
||||
self._epoch,
|
||||
self._release,
|
||||
self._pre,
|
||||
self._post,
|
||||
self._dev,
|
||||
self._local,
|
||||
)
|
||||
if other._key_cache is None:
|
||||
other._key_cache = _cmpkey(
|
||||
other._epoch,
|
||||
other._release,
|
||||
other._pre,
|
||||
other._post,
|
||||
other._dev,
|
||||
other._local,
|
||||
)
|
||||
return self._key_cache <= other._key_cache
|
||||
|
||||
if not isinstance(other, _BaseVersion):
|
||||
return NotImplemented
|
||||
|
||||
return super().__le__(other)
|
||||
|
||||
def __eq__(self, other: object) -> bool:
|
||||
if isinstance(other, Version):
|
||||
if self._key_cache is None:
|
||||
self._key_cache = _cmpkey(
|
||||
self._epoch,
|
||||
self._release,
|
||||
self._pre,
|
||||
self._post,
|
||||
self._dev,
|
||||
self._local,
|
||||
)
|
||||
if other._key_cache is None:
|
||||
other._key_cache = _cmpkey(
|
||||
other._epoch,
|
||||
other._release,
|
||||
other._pre,
|
||||
other._post,
|
||||
other._dev,
|
||||
other._local,
|
||||
)
|
||||
return self._key_cache == other._key_cache
|
||||
|
||||
if not isinstance(other, _BaseVersion):
|
||||
return NotImplemented
|
||||
|
||||
return super().__eq__(other)
|
||||
|
||||
def __ge__(self, other: _BaseVersion) -> bool:
|
||||
if isinstance(other, Version):
|
||||
if self._key_cache is None:
|
||||
self._key_cache = _cmpkey(
|
||||
self._epoch,
|
||||
self._release,
|
||||
self._pre,
|
||||
self._post,
|
||||
self._dev,
|
||||
self._local,
|
||||
)
|
||||
if other._key_cache is None:
|
||||
other._key_cache = _cmpkey(
|
||||
other._epoch,
|
||||
other._release,
|
||||
other._pre,
|
||||
other._post,
|
||||
other._dev,
|
||||
other._local,
|
||||
)
|
||||
return self._key_cache >= other._key_cache
|
||||
|
||||
if not isinstance(other, _BaseVersion):
|
||||
return NotImplemented
|
||||
|
||||
return super().__ge__(other)
|
||||
|
||||
def __gt__(self, other: _BaseVersion) -> bool:
|
||||
if isinstance(other, Version):
|
||||
if self._key_cache is None:
|
||||
self._key_cache = _cmpkey(
|
||||
self._epoch,
|
||||
self._release,
|
||||
self._pre,
|
||||
self._post,
|
||||
self._dev,
|
||||
self._local,
|
||||
)
|
||||
if other._key_cache is None:
|
||||
other._key_cache = _cmpkey(
|
||||
other._epoch,
|
||||
other._release,
|
||||
other._pre,
|
||||
other._post,
|
||||
other._dev,
|
||||
other._local,
|
||||
)
|
||||
return self._key_cache > other._key_cache
|
||||
|
||||
if not isinstance(other, _BaseVersion):
|
||||
return NotImplemented
|
||||
|
||||
return super().__gt__(other)
|
||||
|
||||
def __ne__(self, other: object) -> bool:
|
||||
if isinstance(other, Version):
|
||||
if self._key_cache is None:
|
||||
self._key_cache = _cmpkey(
|
||||
self._epoch,
|
||||
self._release,
|
||||
self._pre,
|
||||
self._post,
|
||||
self._dev,
|
||||
self._local,
|
||||
)
|
||||
if other._key_cache is None:
|
||||
other._key_cache = _cmpkey(
|
||||
other._epoch,
|
||||
other._release,
|
||||
other._pre,
|
||||
other._post,
|
||||
other._dev,
|
||||
other._local,
|
||||
)
|
||||
return self._key_cache != other._key_cache
|
||||
|
||||
if not isinstance(other, _BaseVersion):
|
||||
return NotImplemented
|
||||
|
||||
return super().__ne__(other)
|
||||
|
||||
def __getstate__(
|
||||
self,
|
||||
) -> tuple[
|
||||
int,
|
||||
tuple[int, ...],
|
||||
tuple[str, int] | None,
|
||||
tuple[str, int] | None,
|
||||
tuple[str, int] | None,
|
||||
LocalType | None,
|
||||
]:
|
||||
# Return state as a 6-item tuple for compactness:
|
||||
# (epoch, release, pre, post, dev, local)
|
||||
# Cache members are excluded and will be recomputed on demand
|
||||
return (
|
||||
self._epoch,
|
||||
self._release,
|
||||
self._pre,
|
||||
self._post,
|
||||
self._dev,
|
||||
self._local,
|
||||
)
|
||||
|
||||
def __setstate__(self, state: object) -> None:
|
||||
# Always discard cached values — they may contain stale references
|
||||
# (e.g. packaging._structures.InfinityType from pre-26.1 pickles)
|
||||
# and will be recomputed on demand from the core fields above.
|
||||
self._key_cache = None
|
||||
self._hash_cache = None
|
||||
|
||||
if isinstance(state, tuple):
|
||||
if len(state) == 6:
|
||||
# New format (26.2+): (epoch, release, pre, post, dev, local)
|
||||
(
|
||||
self._epoch,
|
||||
self._release,
|
||||
self._pre,
|
||||
self._post,
|
||||
self._dev,
|
||||
self._local,
|
||||
) = state
|
||||
return
|
||||
if len(state) == 2:
|
||||
# Format (packaging 26.0-26.1): (None, {slot: value}).
|
||||
_, slot_dict = state
|
||||
if isinstance(slot_dict, dict):
|
||||
self._epoch = slot_dict["_epoch"]
|
||||
self._release = slot_dict["_release"]
|
||||
self._pre = slot_dict.get("_pre")
|
||||
self._post = slot_dict.get("_post")
|
||||
self._dev = slot_dict.get("_dev")
|
||||
self._local = slot_dict.get("_local")
|
||||
return
|
||||
if isinstance(state, dict):
|
||||
# Old format (packaging <= 25.x, no __slots__): state is a plain
|
||||
# dict with "_version" (_Version NamedTuple) and "_key" entries.
|
||||
version_nt = state.get("_version")
|
||||
if version_nt is not None:
|
||||
self._epoch = version_nt.epoch
|
||||
self._release = version_nt.release
|
||||
self._pre = version_nt.pre
|
||||
self._post = version_nt.post
|
||||
self._dev = version_nt.dev
|
||||
self._local = version_nt.local
|
||||
return
|
||||
|
||||
raise TypeError(f"Cannot restore Version from {state!r}")
|
||||
|
||||
@property
|
||||
@_deprecated("Version._version is private and will be removed soon")
|
||||
def _version(self) -> _Version:
|
||||
@@ -434,6 +849,7 @@ class Version(_BaseVersion):
|
||||
self._post = value.post
|
||||
self._local = value.local
|
||||
self._key_cache = None
|
||||
self._hash_cache = None
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""A representation of the Version that shows all internal state.
|
||||
@@ -441,7 +857,7 @@ class Version(_BaseVersion):
|
||||
>>> Version('1.0.0')
|
||||
<Version('1.0.0')>
|
||||
"""
|
||||
return f"<Version('{self}')>"
|
||||
return f"<{self.__class__.__name__}({str(self)!r})>"
|
||||
|
||||
def __str__(self) -> str:
|
||||
"""A string representation of the version that can be round-tripped.
|
||||
@@ -507,7 +923,7 @@ class Version(_BaseVersion):
|
||||
return self._release
|
||||
|
||||
@property
|
||||
def pre(self) -> tuple[str, int] | None:
|
||||
def pre(self) -> tuple[Literal["a", "b", "rc"], int] | None:
|
||||
"""The pre-release segment of the version.
|
||||
|
||||
>>> print(Version("1.2.3").pre)
|
||||
@@ -561,6 +977,9 @@ class Version(_BaseVersion):
|
||||
def public(self) -> str:
|
||||
"""The public portion of the version.
|
||||
|
||||
This returns a string. If you want a :class:`Version` again and care
|
||||
about performance, use ``v.__replace__(local=None)`` instead.
|
||||
|
||||
>>> Version("1.2.3").public
|
||||
'1.2.3'
|
||||
>>> Version("1.2.3+abc").public
|
||||
@@ -574,6 +993,10 @@ class Version(_BaseVersion):
|
||||
def base_version(self) -> str:
|
||||
"""The "base version" of the version.
|
||||
|
||||
This returns a string. If you want a :class:`Version` again and care
|
||||
about performance, use
|
||||
``v.__replace__(pre=None, post=None, dev=None, local=None)`` instead.
|
||||
|
||||
>>> Version("1.2.3").base_version
|
||||
'1.2.3'
|
||||
>>> Version("1.2.3+abc").base_version
|
||||
@@ -632,6 +1055,8 @@ class Version(_BaseVersion):
|
||||
|
||||
>>> Version("1.2.3").major
|
||||
1
|
||||
|
||||
.. versionadded:: 20.0
|
||||
"""
|
||||
return self.release[0] if len(self.release) >= 1 else 0
|
||||
|
||||
@@ -643,6 +1068,8 @@ class Version(_BaseVersion):
|
||||
2
|
||||
>>> Version("1").minor
|
||||
0
|
||||
|
||||
.. versionadded:: 20.0
|
||||
"""
|
||||
return self.release[1] if len(self.release) >= 2 else 0
|
||||
|
||||
@@ -654,6 +1081,8 @@ class Version(_BaseVersion):
|
||||
3
|
||||
>>> Version("1").micro
|
||||
0
|
||||
|
||||
.. versionadded:: 20.0
|
||||
"""
|
||||
return self.release[2] if len(self.release) >= 3 else 0
|
||||
|
||||
@@ -670,6 +1099,7 @@ class _TrimmedRelease(Version):
|
||||
self._post = version._post
|
||||
self._local = version._local
|
||||
self._key_cache = version._key_cache
|
||||
self._hash_cache = version._hash_cache
|
||||
return
|
||||
super().__init__(version) # pragma: no cover
|
||||
|
||||
@@ -721,7 +1151,8 @@ _local_version_separators = re.compile(r"[\._-]")
|
||||
|
||||
def _parse_local_version(local: str | None) -> LocalType | None:
|
||||
"""
|
||||
Takes a string like abc.1.twelve and turns it into ("abc", 1, "twelve").
|
||||
Takes a string like ``"abc.1.twelve"`` and turns it into
|
||||
``("abc", 1, "twelve")``.
|
||||
"""
|
||||
if local is not None:
|
||||
return tuple(
|
||||
@@ -731,6 +1162,19 @@ def _parse_local_version(local: str | None) -> LocalType | None:
|
||||
return None
|
||||
|
||||
|
||||
# Sort ranks for pre-release: dev-only < a < b < rc < stable (no pre-release).
|
||||
_PRE_RANK = {"a": 0, "b": 1, "rc": 2}
|
||||
_PRE_RANK_DEV_ONLY = -1 # sorts before a(0)
|
||||
_PRE_RANK_STABLE = 3 # sorts after rc(2)
|
||||
|
||||
# In local version segments, strings sort before ints per PEP 440.
|
||||
_LOCAL_STR_RANK = -1 # sorts before all non-negative ints
|
||||
|
||||
# Pre-computed suffix for stable releases (no pre, post, or dev segments).
|
||||
# See _cmpkey() for the suffix layout.
|
||||
_STABLE_SUFFIX = (_PRE_RANK_STABLE, 0, 0, 0, 1, 0)
|
||||
|
||||
|
||||
def _cmpkey(
|
||||
epoch: int,
|
||||
release: tuple[int, ...],
|
||||
@@ -739,54 +1183,70 @@ def _cmpkey(
|
||||
dev: tuple[str, int] | None,
|
||||
local: LocalType | None,
|
||||
) -> CmpKey:
|
||||
# When we compare a release version, we want to compare it with all of the
|
||||
# trailing zeros removed. We will use this for our sorting key.
|
||||
"""Build a comparison key for PEP 440 ordering.
|
||||
|
||||
Returns ``(epoch, release, suffix)`` or
|
||||
``(epoch, release, suffix, local)`` so that plain tuple
|
||||
comparison gives the correct order.
|
||||
|
||||
Trailing zeros are stripped from the release so that ``1.0.0 == 1``.
|
||||
|
||||
The suffix is a flat 6-int tuple that encodes pre/post/dev:
|
||||
``(pre_rank, pre_n, post_rank, post_n, dev_rank, dev_n)``
|
||||
|
||||
pre_rank: dev-only=-1, a=0, b=1, rc=2, no-pre=3
|
||||
Dev-only releases (no pre or post) get -1 so they sort before
|
||||
any alpha/beta/rc. Releases without a pre-release tag get 3
|
||||
so they sort after rc.
|
||||
post_rank: no-post=0, post=1
|
||||
Releases without a post segment sort before those with one.
|
||||
dev_rank: dev=0, no-dev=1
|
||||
Releases without a dev segment sort after those with one.
|
||||
|
||||
Local segments use ``(n, "")`` for ints and ``(-1, s)`` for strings,
|
||||
following PEP 440: strings sort before ints, strings compare
|
||||
lexicographically, ints compare numerically, and shorter segments
|
||||
sort before longer when prefixes match. Versions without a local
|
||||
segment sort before those with one (3-tuple < 4-tuple).
|
||||
|
||||
>>> _cmpkey(0, (1, 0, 0), None, None, None, None)
|
||||
(0, (1,), (3, 0, 0, 0, 1, 0))
|
||||
>>> _cmpkey(0, (1,), ("a", 1), None, None, None)
|
||||
(0, (1,), (0, 1, 0, 0, 1, 0))
|
||||
>>> _cmpkey(0, (1,), None, None, None, ("ubuntu", 1))
|
||||
(0, (1,), (3, 0, 0, 0, 1, 0), ((-1, 'ubuntu'), (1, '')))
|
||||
"""
|
||||
# Strip trailing zeros: 1.0.0 compares equal to 1.
|
||||
len_release = len(release)
|
||||
i = len_release
|
||||
while i and release[i - 1] == 0:
|
||||
i -= 1
|
||||
_release = release if i == len_release else release[:i]
|
||||
trimmed = release if i == len_release else release[:i]
|
||||
|
||||
# Fast path: stable release with no local segment.
|
||||
if pre is None and post is None and dev is None and local is None:
|
||||
return epoch, trimmed, _STABLE_SUFFIX
|
||||
|
||||
# We need to "trick" the sorting algorithm to put 1.0.dev0 before 1.0a0.
|
||||
# We'll do this by abusing the pre segment, but we _only_ want to do this
|
||||
# if there is not a pre or a post segment. If we have one of those then
|
||||
# the normal sorting rules will handle this case correctly.
|
||||
if pre is None and post is None and dev is not None:
|
||||
_pre: CmpPrePostDevType = NegativeInfinity
|
||||
# Versions without a pre-release (except as noted above) should sort after
|
||||
# those with one.
|
||||
# dev-only (e.g. 1.0.dev1) sorts before all pre-releases.
|
||||
pre_rank, pre_n = _PRE_RANK_DEV_ONLY, 0
|
||||
elif pre is None:
|
||||
_pre = Infinity
|
||||
pre_rank, pre_n = _PRE_RANK_STABLE, 0
|
||||
else:
|
||||
_pre = pre
|
||||
pre_rank, pre_n = _PRE_RANK[pre[0]], pre[1]
|
||||
|
||||
# Versions without a post segment should sort before those with one.
|
||||
if post is None:
|
||||
_post: CmpPrePostDevType = NegativeInfinity
|
||||
post_rank = 0 if post is None else 1
|
||||
post_n = 0 if post is None else post[1]
|
||||
|
||||
else:
|
||||
_post = post
|
||||
dev_rank = 1 if dev is None else 0
|
||||
dev_n = 0 if dev is None else dev[1]
|
||||
|
||||
# Versions without a development segment should sort after those with one.
|
||||
if dev is None:
|
||||
_dev: CmpPrePostDevType = Infinity
|
||||
|
||||
else:
|
||||
_dev = dev
|
||||
suffix = (pre_rank, pre_n, post_rank, post_n, dev_rank, dev_n)
|
||||
|
||||
if local is None:
|
||||
# Versions without a local segment should sort before those with one.
|
||||
_local: CmpLocalType = NegativeInfinity
|
||||
else:
|
||||
# Versions with a local segment need that segment parsed to implement
|
||||
# the sorting rules in PEP440.
|
||||
# - Alpha numeric segments sort before numeric segments
|
||||
# - Alpha numeric segments sort lexicographically
|
||||
# - Numeric segments sort numerically
|
||||
# - Shorter versions sort before longer versions when the prefixes
|
||||
# match exactly
|
||||
_local = tuple(
|
||||
(i, "") if isinstance(i, int) else (NegativeInfinity, i) for i in local
|
||||
)
|
||||
return epoch, trimmed, suffix
|
||||
|
||||
return epoch, _release, _pre, _post, _dev, _local
|
||||
cmp_local: CmpLocalType = tuple(
|
||||
(seg, "") if isinstance(seg, int) else (_LOCAL_STR_RANK, seg) for seg in local
|
||||
)
|
||||
return epoch, trimmed, suffix, cmp_local
|
||||
File diff suppressed because it is too large.
Load diff
@@ -2,8 +2,13 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from pip._vendor.platformdirs import PlatformDirs, __version__
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from pip._vendor.platformdirs.api import PlatformDirsABC
|
||||
|
||||
PROPS = (
|
||||
"user_data_dir",
|
||||
"user_config_dir",
|
||||
@@ -15,10 +20,22 @@ PROPS = (
|
||||
"user_pictures_dir",
|
||||
"user_videos_dir",
|
||||
"user_music_dir",
|
||||
"user_desktop_dir",
|
||||
"user_projects_dir",
|
||||
"user_publicshare_dir",
|
||||
"user_templates_dir",
|
||||
"user_fonts_dir",
|
||||
"user_preference_dir",
|
||||
"user_bin_dir",
|
||||
"site_bin_dir",
|
||||
"user_applications_dir",
|
||||
"user_runtime_dir",
|
||||
"site_data_dir",
|
||||
"site_config_dir",
|
||||
"site_cache_dir",
|
||||
"site_state_dir",
|
||||
"site_log_dir",
|
||||
"site_applications_dir",
|
||||
"site_runtime_dir",
|
||||
)
|
||||
|
||||
@@ -28,27 +45,32 @@ def main() -> None:
|
||||
app_name = "MyApp"
|
||||
app_author = "MyCompany"
|
||||
|
||||
print(f"-- platformdirs {__version__} --") # noqa: T201
|
||||
print(f"-- platformdirs {__version__} --") # ruff:ignore[print]
|
||||
|
||||
print("-- app dirs (with optional 'version')") # noqa: T201
|
||||
dirs = PlatformDirs(app_name, app_author, version="1.0")
|
||||
for prop in PROPS:
|
||||
print(f"{prop}: {getattr(dirs, prop)}") # noqa: T201
|
||||
print("-- app dirs (with optional 'version')") # ruff:ignore[print]
|
||||
_print_dirs(PlatformDirs(app_name, app_author, version="1.0"))
|
||||
|
||||
print("\n-- app dirs (without optional 'version')") # noqa: T201
|
||||
dirs = PlatformDirs(app_name, app_author)
|
||||
for prop in PROPS:
|
||||
print(f"{prop}: {getattr(dirs, prop)}") # noqa: T201
|
||||
print("\n-- app dirs (without optional 'version')") # ruff:ignore[print]
|
||||
_print_dirs(PlatformDirs(app_name, app_author))
|
||||
|
||||
print("\n-- app dirs (without optional 'appauthor')") # noqa: T201
|
||||
dirs = PlatformDirs(app_name)
|
||||
for prop in PROPS:
|
||||
print(f"{prop}: {getattr(dirs, prop)}") # noqa: T201
|
||||
print("\n-- app dirs (without optional 'appauthor')") # ruff:ignore[print]
|
||||
_print_dirs(PlatformDirs(app_name))
|
||||
|
||||
print("\n-- app dirs (with disabled 'appauthor')") # noqa: T201
|
||||
dirs = PlatformDirs(app_name, appauthor=False)
|
||||
print("\n-- app dirs (with disabled 'appauthor')") # ruff:ignore[print]
|
||||
_print_dirs(PlatformDirs(app_name, appauthor=False))
|
||||
|
||||
|
||||
def _print_dirs(dirs: PlatformDirsABC) -> None:
|
||||
for prop in PROPS:
|
||||
print(f"{prop}: {getattr(dirs, prop)}") # noqa: T201
|
||||
print(f"{prop}: {_dir_or_error(dirs, prop)}") # ruff:ignore[print]
|
||||
|
||||
|
||||
def _dir_or_error(dirs: PlatformDirsABC, prop: str) -> str:
|
||||
# user_runtime_dir raises when its temporary fallback is not a directory the user owns.
|
||||
try:
|
||||
return getattr(dirs, prop)
|
||||
except PermissionError as error:
|
||||
return str(error)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -5,243 +5,260 @@ from __future__ import annotations
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
from functools import lru_cache
|
||||
from typing import TYPE_CHECKING, cast
|
||||
from contextlib import suppress
|
||||
from functools import cache, lru_cache
|
||||
from typing import Final
|
||||
|
||||
from .api import PlatformDirsABC
|
||||
|
||||
|
||||
class Android(PlatformDirsABC):
|
||||
"""
|
||||
Follows the guidance `from here <https://android.stackexchange.com/a/216132>`_.
|
||||
class Android(PlatformDirsABC): # ruff:ignore[too-many-public-methods]
|
||||
"""Platform directories for Android.
|
||||
|
||||
Follows the guidance `from here <https://android.stackexchange.com/a/216132>`_. Directories are typically located
|
||||
under the app's private storage (``/data/user/<userid>/<packagename>/``).
|
||||
|
||||
Makes use of the `appname <platformdirs.api.PlatformDirsABC.appname>`, `version
|
||||
<platformdirs.api.PlatformDirsABC.version>`, `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
|
||||
<platformdirs.api.PlatformDirsABC.version>`, `opinion <platformdirs.api.PlatformDirsABC.opinion>`, `ensure_exists
|
||||
<platformdirs.api.PlatformDirsABC.ensure_exists>`.
|
||||
|
||||
"""
|
||||
|
||||
@property
|
||||
def user_data_dir(self) -> str:
|
||||
""":return: data directory tied to the user, e.g. ``/data/user/<userid>/<packagename>/files/<AppName>``"""
|
||||
return self._append_app_name_and_version(cast("str", _android_folder()), "files")
|
||||
"""Data directory tied to the user, e.g. ``/data/user/<userid>/<packagename>/files/<AppName>``."""
|
||||
return self._append_app_name_and_version(_require_android_folder(), "files", private=True)
|
||||
|
||||
@property
|
||||
def site_data_dir(self) -> str:
|
||||
""":return: data directory shared by users, same as `user_data_dir`"""
|
||||
"""Data directory shared by users, same as `user_data_dir`."""
|
||||
return self.user_data_dir
|
||||
|
||||
@property
|
||||
def user_config_dir(self) -> str:
|
||||
"""
|
||||
:return: config directory tied to the user, e.g. \
|
||||
``/data/user/<userid>/<packagename>/shared_prefs/<AppName>``
|
||||
"""
|
||||
return self._append_app_name_and_version(cast("str", _android_folder()), "shared_prefs")
|
||||
"""Config directory tied to the user, e.g. ``/data/user/<userid>/<packagename>/shared_prefs/<AppName>``."""
|
||||
return self._append_app_name_and_version(_require_android_folder(), "shared_prefs", private=True)
|
||||
|
||||
@property
|
||||
def site_config_dir(self) -> str:
|
||||
""":return: config directory shared by the users, same as `user_config_dir`"""
|
||||
"""Config directory shared by users, same as `user_config_dir`."""
|
||||
return self.user_config_dir
|
||||
|
||||
@property
|
||||
def user_cache_dir(self) -> str:
|
||||
""":return: cache directory tied to the user, e.g.,``/data/user/<userid>/<packagename>/cache/<AppName>``"""
|
||||
return self._append_app_name_and_version(cast("str", _android_folder()), "cache")
|
||||
"""Cache directory tied to the user, e.g.,``/data/user/<userid>/<packagename>/cache/<AppName>``."""
|
||||
return self._append_app_name_and_version(_require_android_folder(), "cache", private=True)
|
||||
|
||||
@property
|
||||
def site_cache_dir(self) -> str:
|
||||
""":return: cache directory shared by users, same as `user_cache_dir`"""
|
||||
"""Cache directory shared by users, same as `user_cache_dir`."""
|
||||
return self.user_cache_dir
|
||||
|
||||
@property
|
||||
def user_state_dir(self) -> str:
|
||||
""":return: state directory tied to the user, same as `user_data_dir`"""
|
||||
"""State directory tied to the user, same as `user_data_dir`."""
|
||||
return self.user_data_dir
|
||||
|
||||
@property
|
||||
def site_state_dir(self) -> str:
|
||||
"""State directory shared by users, same as `user_state_dir`."""
|
||||
return self.user_state_dir
|
||||
|
||||
@property
|
||||
def user_log_dir(self) -> str:
|
||||
"""
|
||||
:return: log directory tied to the user, same as `user_cache_dir` if not opinionated else ``log`` in it,
|
||||
e.g. ``/data/user/<userid>/<packagename>/cache/<AppName>/log``
|
||||
"""
|
||||
"""Log directory tied to the user, same as `user_cache_dir` if not opinionated else ``log`` in it, e.g. ``/data/user/<userid>/<packagename>/cache/<AppName>/log``."""
|
||||
path = self.user_cache_dir
|
||||
if self.opinion:
|
||||
path = os.path.join(path, "log") # noqa: PTH118
|
||||
path = os.path.join(path, "log") # ruff:ignore[os-path-join]
|
||||
self._optionally_create_directory(path, private=True)
|
||||
return path
|
||||
|
||||
@property
|
||||
def site_log_dir(self) -> str:
|
||||
"""Log directory shared by users, same as `user_log_dir`."""
|
||||
return self.user_log_dir
|
||||
|
||||
@property
|
||||
def user_documents_dir(self) -> str:
|
||||
""":return: documents directory tied to the user e.g. ``/storage/emulated/0/Documents``"""
|
||||
return _android_documents_folder()
|
||||
"""Documents directory tied to the user e.g. ``/storage/emulated/0/Documents``."""
|
||||
return _android_public_folder("Documents")
|
||||
|
||||
@property
|
||||
def user_downloads_dir(self) -> str:
|
||||
""":return: downloads directory tied to the user e.g. ``/storage/emulated/0/Downloads``"""
|
||||
return _android_downloads_folder()
|
||||
"""Downloads directory tied to the user e.g. ``/storage/emulated/0/Download``."""
|
||||
return _android_public_folder("Download")
|
||||
|
||||
@property
|
||||
def user_pictures_dir(self) -> str:
|
||||
""":return: pictures directory tied to the user e.g. ``/storage/emulated/0/Pictures``"""
|
||||
return _android_pictures_folder()
|
||||
"""Pictures directory tied to the user e.g. ``/storage/emulated/0/Pictures``."""
|
||||
return _android_public_folder("Pictures")
|
||||
|
||||
@property
|
||||
def user_videos_dir(self) -> str:
|
||||
""":return: videos directory tied to the user e.g. ``/storage/emulated/0/DCIM/Camera``"""
|
||||
return _android_videos_folder()
|
||||
"""Videos directory tied to the user e.g. ``/storage/emulated/0/Movies``."""
|
||||
return _android_public_folder("Movies")
|
||||
|
||||
@property
|
||||
def user_music_dir(self) -> str:
|
||||
""":return: music directory tied to the user e.g. ``/storage/emulated/0/Music``"""
|
||||
return _android_music_folder()
|
||||
"""Music directory tied to the user e.g. ``/storage/emulated/0/Music``."""
|
||||
return _android_public_folder("Music")
|
||||
|
||||
# Android lets apps create top-level shared folders only from its standard list, so these live in Documents.
|
||||
@property
|
||||
def user_desktop_dir(self) -> str:
|
||||
""":return: desktop directory tied to the user e.g. ``/storage/emulated/0/Desktop``"""
|
||||
return "/storage/emulated/0/Desktop"
|
||||
"""Desktop directory tied to the user e.g. ``/storage/emulated/0/Documents/Desktop``."""
|
||||
return f"{_shared_storage()}/Documents/Desktop"
|
||||
|
||||
@property
|
||||
def user_projects_dir(self) -> str:
|
||||
"""Projects directory tied to the user e.g. ``/storage/emulated/0/Documents/Projects``."""
|
||||
return f"{_shared_storage()}/Documents/Projects"
|
||||
|
||||
@property
|
||||
def user_publicshare_dir(self) -> str:
|
||||
"""Public share directory tied to the user e.g. ``/storage/emulated/0/Documents/Public``."""
|
||||
return f"{_shared_storage()}/Documents/Public"
|
||||
|
||||
@property
|
||||
def user_templates_dir(self) -> str:
|
||||
"""Templates directory tied to the user e.g. ``/storage/emulated/0/Documents/Templates``."""
|
||||
return f"{_shared_storage()}/Documents/Templates"
|
||||
|
||||
@property
|
||||
def user_fonts_dir(self) -> str:
|
||||
"""Fonts directory tied to the user e.g. ``/storage/emulated/0/Documents/fonts``."""
|
||||
return f"{_shared_storage()}/Documents/fonts"
|
||||
|
||||
@property
|
||||
def user_preference_dir(self) -> str:
|
||||
"""Preference directory tied to the user, same as ``user_config_dir``."""
|
||||
return self.user_config_dir
|
||||
|
||||
@property
|
||||
def user_bin_dir(self) -> str:
|
||||
"""Bin directory tied to the user, e.g. ``/data/user/<userid>/<packagename>/files/bin``."""
|
||||
return os.path.join(_require_android_folder(), "files", "bin") # ruff:ignore[os-path-join]
|
||||
|
||||
@property
|
||||
def site_bin_dir(self) -> str:
|
||||
"""Bin directory shared by users, same as `user_bin_dir`."""
|
||||
return self.user_bin_dir
|
||||
|
||||
@property
|
||||
def user_applications_dir(self) -> str:
|
||||
"""Applications directory tied to the user, same as `user_data_dir`."""
|
||||
return self.user_data_dir
|
||||
|
||||
@property
|
||||
def site_applications_dir(self) -> str:
|
||||
"""Applications directory shared by users, same as `user_applications_dir`."""
|
||||
return self.user_applications_dir
|
||||
|
||||
@property
|
||||
def user_runtime_dir(self) -> str:
|
||||
"""
|
||||
:return: runtime directory tied to the user, same as `user_cache_dir` if not opinionated else ``tmp`` in it,
|
||||
e.g. ``/data/user/<userid>/<packagename>/cache/<AppName>/tmp``
|
||||
"""
|
||||
"""Runtime directory tied to the user, same as `user_cache_dir` if not opinionated else ``tmp`` in it, e.g. ``/data/user/<userid>/<packagename>/cache/<AppName>/tmp``."""
|
||||
path = self.user_cache_dir
|
||||
if self.opinion:
|
||||
path = os.path.join(path, "tmp") # noqa: PTH118
|
||||
path = os.path.join(path, "tmp") # ruff:ignore[os-path-join]
|
||||
self._optionally_create_directory(path, private=True)
|
||||
return path
|
||||
|
||||
@property
|
||||
def site_runtime_dir(self) -> str:
|
||||
""":return: runtime directory shared by users, same as `user_runtime_dir`"""
|
||||
"""Runtime directory shared by users, same as `user_runtime_dir`."""
|
||||
return self.user_runtime_dir
|
||||
|
||||
|
||||
def _require_android_folder() -> str:
|
||||
if (folder := _android_folder()) is None:
|
||||
msg = "cannot find the Android app folder: python4android and pyjnius failed and no app folder is on sys.path"
|
||||
raise RuntimeError(msg)
|
||||
return folder
|
||||
|
||||
|
||||
@lru_cache(maxsize=1)
|
||||
def _android_folder() -> str | None: # noqa: C901
|
||||
""":return: base folder for the Android OS or None if it cannot be found"""
|
||||
result: str | None = None
|
||||
# type checker isn't happy with our "import android", just don't do this when type checking see
|
||||
# https://stackoverflow.com/a/61394121
|
||||
if not TYPE_CHECKING:
|
||||
try:
|
||||
# First try to get a path to android app using python4android (if available)...
|
||||
from android import mActivity # noqa: PLC0415
|
||||
|
||||
context = cast("android.content.Context", mActivity.getApplicationContext()) # noqa: F821
|
||||
result = context.getFilesDir().getParentFile().getAbsolutePath()
|
||||
except Exception: # noqa: BLE001
|
||||
result = None
|
||||
if result is None:
|
||||
try:
|
||||
# ...and fall back to using plain pyjnius, if python4android isn't available or doesn't deliver any useful
|
||||
# result...
|
||||
from jnius import autoclass # noqa: PLC0415
|
||||
|
||||
context = autoclass("android.content.Context")
|
||||
result = context.getFilesDir().getParentFile().getAbsolutePath()
|
||||
except Exception: # noqa: BLE001
|
||||
result = None
|
||||
def _android_folder() -> str | None:
|
||||
""":returns: base folder for the Android OS or None if it cannot be found"""
|
||||
result = _python_for_android_folder()
|
||||
if result is None:
|
||||
# and if that fails, too, find an android folder looking at path on the sys.path
|
||||
# warning: only works for apps installed under /data, not adopted storage etc.
|
||||
pattern = re.compile(r"/data/(data|user/\d+)/(.+)/files")
|
||||
pattern = re.compile(
|
||||
r"""
|
||||
(?P<folder>
|
||||
/data/(?:data|user/\d+) # internal storage of the primary user or of user N
|
||||
/[^/]+ # package name, one path segment
|
||||
)
|
||||
/files # the files directory the interpreter runs from
|
||||
""",
|
||||
re.VERBOSE,
|
||||
)
|
||||
for path in sys.path:
|
||||
if pattern.match(path):
|
||||
result = path.split("/files")[0]
|
||||
if match := pattern.match(path):
|
||||
result = match["folder"]
|
||||
break
|
||||
else:
|
||||
result = None
|
||||
if result is None:
|
||||
# one last try: find an android folder looking at path on the sys.path taking adopted storage paths into
|
||||
# account
|
||||
pattern = re.compile(r"/mnt/expand/[a-fA-F0-9-]{36}/(data|user/\d+)/(.+)/files")
|
||||
pattern = re.compile(
|
||||
r"""
|
||||
(?P<folder>
|
||||
/mnt/expand/[a-fA-F0-9-]{36} # adopted storage volume, named by its UUID
|
||||
/(?:data|user/\d+) # the primary user or user N
|
||||
/[^/]+ # package name, one path segment
|
||||
)
|
||||
/files # the files directory the interpreter runs from
|
||||
""",
|
||||
re.VERBOSE,
|
||||
)
|
||||
for path in sys.path:
|
||||
if pattern.match(path):
|
||||
result = path.split("/files")[0]
|
||||
if match := pattern.match(path):
|
||||
result = match["folder"]
|
||||
break
|
||||
else:
|
||||
result = None
|
||||
return result
|
||||
|
||||
|
||||
@lru_cache(maxsize=1)
|
||||
def _android_documents_folder() -> str:
|
||||
""":return: documents folder for the Android OS"""
|
||||
# Get directories with pyjnius
|
||||
try:
|
||||
from jnius import autoclass # noqa: PLC0415
|
||||
|
||||
context = autoclass("android.content.Context")
|
||||
environment = autoclass("android.os.Environment")
|
||||
documents_dir: str = context.getExternalFilesDir(environment.DIRECTORY_DOCUMENTS).getAbsolutePath()
|
||||
except Exception: # noqa: BLE001
|
||||
documents_dir = "/storage/emulated/0/Documents"
|
||||
|
||||
return documents_dir
|
||||
_USER_ID: Final = re.compile(
|
||||
r"""
|
||||
/user/ # the per-user data root, under /data or an adopted /mnt/expand volume
|
||||
(?P<user>\d+) # the Android user id
|
||||
/ # followed by the package folder
|
||||
""",
|
||||
re.VERBOSE,
|
||||
)
|
||||
|
||||
|
||||
@lru_cache(maxsize=1)
|
||||
def _android_downloads_folder() -> str:
|
||||
""":return: downloads folder for the Android OS"""
|
||||
# Get directories with pyjnius
|
||||
try:
|
||||
from jnius import autoclass # noqa: PLC0415
|
||||
|
||||
context = autoclass("android.content.Context")
|
||||
environment = autoclass("android.os.Environment")
|
||||
downloads_dir: str = context.getExternalFilesDir(environment.DIRECTORY_DOWNLOADS).getAbsolutePath()
|
||||
except Exception: # noqa: BLE001
|
||||
downloads_dir = "/storage/emulated/0/Downloads"
|
||||
|
||||
return downloads_dir
|
||||
def _shared_storage() -> str:
|
||||
# Android mounts each user's shared storage at /storage/emulated/<user id>, and an app sees only its own user's.
|
||||
user = match["user"] if (match := _USER_ID.search(_android_folder() or "")) else "0"
|
||||
return f"/storage/emulated/{user}"
|
||||
|
||||
|
||||
@lru_cache(maxsize=1)
|
||||
def _android_pictures_folder() -> str:
|
||||
""":return: pictures folder for the Android OS"""
|
||||
# Get directories with pyjnius
|
||||
try:
|
||||
from jnius import autoclass # noqa: PLC0415
|
||||
def _python_for_android_folder() -> str | None:
|
||||
with suppress(ImportError):
|
||||
from jnius import JavaException, autoclass # ruff:ignore[import-outside-top-level] # ty: ignore[unresolved-import]
|
||||
|
||||
context = autoclass("android.content.Context")
|
||||
environment = autoclass("android.os.Environment")
|
||||
pictures_dir: str = context.getExternalFilesDir(environment.DIRECTORY_PICTURES).getAbsolutePath()
|
||||
except Exception: # noqa: BLE001
|
||||
pictures_dir = "/storage/emulated/0/Pictures"
|
||||
|
||||
return pictures_dir
|
||||
with suppress(JavaException):
|
||||
# A python-for-android service runs in its own process, where the activity is null.
|
||||
if (context := autoclass("org.kivy.android.PythonActivity").mActivity) is None:
|
||||
context = autoclass("org.kivy.android.PythonService").mService
|
||||
if context is not None:
|
||||
return context.getFilesDir().getParentFile().getAbsolutePath()
|
||||
return None
|
||||
|
||||
|
||||
@lru_cache(maxsize=1)
|
||||
def _android_videos_folder() -> str:
|
||||
""":return: videos folder for the Android OS"""
|
||||
# Get directories with pyjnius
|
||||
try:
|
||||
from jnius import autoclass # noqa: PLC0415
|
||||
@cache
|
||||
def _android_public_folder(name: str) -> str:
|
||||
with suppress(ImportError):
|
||||
from jnius import JavaException, autoclass # ruff:ignore[import-outside-top-level] # ty: ignore[unresolved-import]
|
||||
|
||||
context = autoclass("android.content.Context")
|
||||
environment = autoclass("android.os.Environment")
|
||||
videos_dir: str = context.getExternalFilesDir(environment.DIRECTORY_DCIM).getAbsolutePath()
|
||||
except Exception: # noqa: BLE001
|
||||
videos_dir = "/storage/emulated/0/DCIM/Camera"
|
||||
|
||||
return videos_dir
|
||||
|
||||
|
||||
@lru_cache(maxsize=1)
|
||||
def _android_music_folder() -> str:
|
||||
""":return: music folder for the Android OS"""
|
||||
# Get directories with pyjnius
|
||||
try:
|
||||
from jnius import autoclass # noqa: PLC0415
|
||||
|
||||
context = autoclass("android.content.Context")
|
||||
environment = autoclass("android.os.Environment")
|
||||
music_dir: str = context.getExternalFilesDir(environment.DIRECTORY_MUSIC).getAbsolutePath()
|
||||
except Exception: # noqa: BLE001
|
||||
music_dir = "/storage/emulated/0/Music"
|
||||
|
||||
return music_dir
|
||||
with suppress(JavaException):
|
||||
return autoclass("android.os.Environment").getExternalStoragePublicDirectory(name).getAbsolutePath()
|
||||
return f"{_shared_storage()}/{name}"
|
||||
|
||||
|
||||
__all__ = [
|
||||
|
||||
@@ -4,29 +4,37 @@ from __future__ import annotations
|
||||
|
||||
import os
|
||||
from abc import ABC, abstractmethod
|
||||
from contextlib import suppress
|
||||
from copy import copy
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import Iterator
|
||||
from collections.abc import Callable, Iterable, Iterator
|
||||
from typing import Literal
|
||||
|
||||
|
||||
class PlatformDirsABC(ABC): # noqa: PLR0904
|
||||
"""Abstract base class for platform directories."""
|
||||
class PlatformDirsABC(ABC): # ruff:ignore[too-many-public-methods]
|
||||
"""Abstract base class defining all platform directory properties, their :class:`~pathlib.Path` variants, and iterators.
|
||||
|
||||
def __init__( # noqa: PLR0913, PLR0917
|
||||
Platform-specific subclasses (e.g. :class:`~platformdirs.windows.Windows`, :class:`~platformdirs.macos.MacOS`,
|
||||
:class:`~platformdirs.unix.Unix`) implement the abstract properties to return the appropriate paths for each
|
||||
operating system.
|
||||
|
||||
"""
|
||||
|
||||
def __init__( # ruff:ignore[too-many-arguments, too-many-positional-arguments]
|
||||
self,
|
||||
appname: str | None = None,
|
||||
appauthor: str | Literal[False] | None = None,
|
||||
version: str | None = None,
|
||||
roaming: bool = False, # noqa: FBT001, FBT002
|
||||
multipath: bool = False, # noqa: FBT001, FBT002
|
||||
opinion: bool = True, # noqa: FBT001, FBT002
|
||||
ensure_exists: bool = False, # noqa: FBT001, FBT002
|
||||
roaming: bool = False, # ruff:ignore[boolean-type-hint-positional-argument, boolean-default-value-positional-argument]
|
||||
multipath: bool = False, # ruff:ignore[boolean-type-hint-positional-argument, boolean-default-value-positional-argument]
|
||||
opinion: bool = True, # ruff:ignore[boolean-type-hint-positional-argument, boolean-default-value-positional-argument]
|
||||
ensure_exists: bool = False, # ruff:ignore[boolean-type-hint-positional-argument, boolean-default-value-positional-argument]
|
||||
use_site_for_root: bool = False, # ruff:ignore[boolean-type-hint-positional-argument, boolean-default-value-positional-argument]
|
||||
) -> None:
|
||||
"""
|
||||
Create a new platform directory.
|
||||
"""Create a new platform directory.
|
||||
|
||||
:param appname: See `appname`.
|
||||
:param appauthor: See `appauthor`.
|
||||
@@ -35,248 +43,486 @@ class PlatformDirsABC(ABC): # noqa: PLR0904
|
||||
:param multipath: See `multipath`.
|
||||
:param opinion: See `opinion`.
|
||||
:param ensure_exists: See `ensure_exists`.
|
||||
:param use_site_for_root: See `use_site_for_root`.
|
||||
|
||||
"""
|
||||
self.appname = appname #: The name of application.
|
||||
self.appname = appname
|
||||
self.appauthor = appauthor
|
||||
self.version = version
|
||||
self.roaming = roaming
|
||||
"""Whether to use the roaming appdata directory on Windows.
|
||||
|
||||
That means that for users on a Windows network setup for roaming profiles, this user data will be synced on
|
||||
login (see `here <https://technet.microsoft.com/en-us/library/cc766489(WS.10).aspx>`_).
|
||||
|
||||
"""
|
||||
The name of the app author or distributing body for this application.
|
||||
self.multipath = multipath
|
||||
"""An optional parameter which indicates that the entire list of data dirs should be returned.
|
||||
|
||||
When ``False``, only the first item is returned. Affects ``site_data_dir``, ``site_config_dir`` and
|
||||
``site_applications_dir`` on Unix and macOS, and ``site_cache_dir`` on macOS under Homebrew.
|
||||
|
||||
"""
|
||||
self.opinion = opinion
|
||||
"""Whether to use opinionated values.
|
||||
|
||||
When enabled, appends an additional subdirectory for certain directories: e.g. ``Cache`` for cache and ``Logs``
|
||||
for logs on Windows, ``log`` for logs on Unix.
|
||||
|
||||
"""
|
||||
self.ensure_exists = ensure_exists
|
||||
"""Create the directory a property returns, with missing parents, each time the property is read.
|
||||
|
||||
Media directories qualify only when the user set them through XDG. platformdirs never creates fonts, bin,
|
||||
applications or default media directories. Off by default.
|
||||
|
||||
"""
|
||||
self.use_site_for_root = use_site_for_root
|
||||
"""Whether to redirect ``user_*_dir`` calls to their ``site_*_dir`` equivalents when running as root (uid 0).
|
||||
|
||||
Only has an effect on Unix. Disabled by default for backwards compatibility. When enabled, XDG user environment
|
||||
variables (e.g. ``XDG_DATA_HOME``) are bypassed for the redirected directories.
|
||||
|
||||
"""
|
||||
|
||||
@property
|
||||
def appname(self) -> str | None:
|
||||
"""The name of the application."""
|
||||
return self._appname
|
||||
|
||||
@appname.setter
|
||||
def appname(self, value: str | None) -> None:
|
||||
_ensure_inside_base("appname", value)
|
||||
self._appname = value
|
||||
|
||||
@property
|
||||
def appauthor(self) -> str | Literal[False] | None:
|
||||
"""The name of the app author or distributing body for this application.
|
||||
|
||||
Typically, it is the owning company name. Defaults to `appname`. You may pass ``False`` to disable it.
|
||||
|
||||
.. note::
|
||||
|
||||
On Windows, the directory structure is ``<base>/<appauthor>/<appname>``. When ``appauthor`` is ``None`` (the
|
||||
default), it falls back to ``appname``, resulting in ``<base>/<appname>/<appname>`` (e.g.
|
||||
``AppData/Local/myapp/myapp``). Pass ``appauthor=False`` to omit the author directory entirely and get
|
||||
``<base>/<appname>``.
|
||||
|
||||
"""
|
||||
self.version = version
|
||||
"""
|
||||
An optional version path element to append to the path.
|
||||
return self._appauthor
|
||||
|
||||
@appauthor.setter
|
||||
def appauthor(self, value: str | Literal[False] | None) -> None:
|
||||
_ensure_inside_base("appauthor", value)
|
||||
self._appauthor = value
|
||||
|
||||
@property
|
||||
def version(self) -> str | None:
|
||||
"""An optional version path element to append to the path.
|
||||
|
||||
You might want to use this if you want multiple versions of your app to be able to run independently. If used,
|
||||
this would typically be ``<major>.<minor>``.
|
||||
|
||||
"""
|
||||
self.roaming = roaming
|
||||
"""
|
||||
Whether to use the roaming appdata directory on Windows.
|
||||
return self._version
|
||||
|
||||
That means that for users on a Windows network setup for roaming profiles, this user data will be synced on
|
||||
login (see
|
||||
`here <https://technet.microsoft.com/en-us/library/cc766489(WS.10).aspx>`_).
|
||||
@version.setter
|
||||
def version(self, value: str | None) -> None:
|
||||
_ensure_inside_base("version", value)
|
||||
self._version = value
|
||||
|
||||
"""
|
||||
self.multipath = multipath
|
||||
"""
|
||||
An optional parameter which indicates that the entire list of data dirs should be returned.
|
||||
def _append_app_name_and_version(self, *base: str, private: bool) -> str:
|
||||
path = self._join_app_name_and_version(*base)
|
||||
self._optionally_create_directory(path, private=private)
|
||||
return path
|
||||
|
||||
By default, the first item would only be returned.
|
||||
|
||||
"""
|
||||
self.opinion = opinion #: A flag to indicating to use opinionated values.
|
||||
self.ensure_exists = ensure_exists
|
||||
"""
|
||||
Optionally create the directory (and any missing parents) upon access if it does not exist.
|
||||
|
||||
By default, no directories are created.
|
||||
|
||||
"""
|
||||
|
||||
def _append_app_name_and_version(self, *base: str) -> str:
|
||||
def _join_app_name_and_version(self, *base: str) -> str:
|
||||
params = list(base[1:])
|
||||
if self.appname:
|
||||
params.append(self.appname)
|
||||
if self.version:
|
||||
params.append(self.version)
|
||||
path = os.path.join(base[0], *params) # noqa: PTH118
|
||||
self._optionally_create_directory(path)
|
||||
return path
|
||||
return os.path.join(base[0], *params) # ruff:ignore[os-path-join]
|
||||
|
||||
def _optionally_create_directory(self, path: str) -> None:
|
||||
if self.ensure_exists:
|
||||
def _optionally_create_directory(self, path: str, *, private: bool) -> None:
|
||||
if not self.ensure_exists:
|
||||
return
|
||||
_ensure_home_known(path)
|
||||
if private:
|
||||
_make_private_directories(Path(path))
|
||||
else:
|
||||
Path(path).mkdir(parents=True, exist_ok=True)
|
||||
|
||||
def _first_item_as_path_if_multipath(self, directory: str) -> Path:
|
||||
if self.multipath:
|
||||
# If multipath is True, the first path is returned.
|
||||
directory = directory.partition(os.pathsep)[0]
|
||||
return Path(directory)
|
||||
def _optionally_create_media_directory(self, path: str) -> None:
|
||||
# Only called for a media directory the user configured. Media directories are often symlinks to removable or
|
||||
# network storage, so a dangling link is returned as-is, like before ensure_exists covered them.
|
||||
with suppress(FileExistsError):
|
||||
self._optionally_create_directory(path, private=False)
|
||||
|
||||
def _select_site_dirs(self, dirs: list[str]) -> str:
|
||||
# Site lists are built without touching the disk, so ensure_exists only creates what the caller gets back.
|
||||
selected = dirs if self.multipath else dirs[:1]
|
||||
for path in selected:
|
||||
self._optionally_create_directory(path, private=False)
|
||||
return os.pathsep.join(selected)
|
||||
|
||||
def _create_as_yielded(self, dirs: Iterable[str]) -> Iterator[str]:
|
||||
for path in dirs:
|
||||
self._optionally_create_directory(path, private=False)
|
||||
yield path
|
||||
|
||||
def _first_site_dir_as_path(self, dirs: list[str]) -> Path:
|
||||
# A *_path property always returns the first entry, regardless of multipath, so only that entry is created.
|
||||
path = dirs[0]
|
||||
self._optionally_create_directory(path, private=False)
|
||||
return Path(path)
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def user_data_dir(self) -> str:
|
||||
""":return: data directory tied to the user"""
|
||||
"""Data directory tied to the user."""
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def site_data_dir(self) -> str:
|
||||
""":return: data directory shared by users"""
|
||||
"""Data directory shared by users."""
|
||||
|
||||
@property
|
||||
def _site_data_dirs(self) -> list[str]:
|
||||
return [self.site_data_dir]
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def user_config_dir(self) -> str:
|
||||
""":return: config directory tied to the user"""
|
||||
"""Config directory tied to the user."""
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def site_config_dir(self) -> str:
|
||||
""":return: config directory shared by the users"""
|
||||
"""Config directory shared by users."""
|
||||
|
||||
@property
|
||||
def _site_config_dirs(self) -> list[str]:
|
||||
return [self.site_config_dir]
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def user_cache_dir(self) -> str:
|
||||
""":return: cache directory tied to the user"""
|
||||
"""Cache directory tied to the user."""
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def site_cache_dir(self) -> str:
|
||||
""":return: cache directory shared by users"""
|
||||
"""Cache directory shared by users."""
|
||||
|
||||
@property
|
||||
def _site_cache_dirs(self) -> list[str]:
|
||||
return [self.site_cache_dir]
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def user_state_dir(self) -> str:
|
||||
""":return: state directory tied to the user"""
|
||||
"""State directory tied to the user."""
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def site_state_dir(self) -> str:
|
||||
"""State directory shared by users."""
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def user_log_dir(self) -> str:
|
||||
""":return: log directory tied to the user"""
|
||||
"""Log directory tied to the user."""
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def site_log_dir(self) -> str:
|
||||
"""Log directory shared by users."""
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def user_documents_dir(self) -> str:
|
||||
""":return: documents directory tied to the user"""
|
||||
"""Documents directory tied to the user."""
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def user_downloads_dir(self) -> str:
|
||||
""":return: downloads directory tied to the user"""
|
||||
"""Downloads directory tied to the user."""
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def user_pictures_dir(self) -> str:
|
||||
""":return: pictures directory tied to the user"""
|
||||
"""Pictures directory tied to the user."""
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def user_videos_dir(self) -> str:
|
||||
""":return: videos directory tied to the user"""
|
||||
"""Videos directory tied to the user."""
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def user_music_dir(self) -> str:
|
||||
""":return: music directory tied to the user"""
|
||||
"""Music directory tied to the user."""
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def user_desktop_dir(self) -> str:
|
||||
""":return: desktop directory tied to the user"""
|
||||
"""Desktop directory tied to the user."""
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def user_projects_dir(self) -> str:
|
||||
"""Projects directory tied to the user."""
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def user_publicshare_dir(self) -> str:
|
||||
"""Public share directory tied to the user."""
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def user_templates_dir(self) -> str:
|
||||
"""Templates directory tied to the user."""
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def user_fonts_dir(self) -> str:
|
||||
"""Fonts directory tied to the user."""
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def user_preference_dir(self) -> str:
|
||||
"""Preference directory tied to the user."""
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def user_bin_dir(self) -> str:
|
||||
"""Bin directory tied to the user."""
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def site_bin_dir(self) -> str:
|
||||
"""Bin directory shared by users."""
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def user_applications_dir(self) -> str:
|
||||
"""Applications directory tied to the user."""
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def site_applications_dir(self) -> str:
|
||||
"""Applications directory shared by users."""
|
||||
|
||||
@property
|
||||
def _site_applications_dirs(self) -> list[str]:
|
||||
return [self.site_applications_dir]
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def user_runtime_dir(self) -> str:
|
||||
""":return: runtime directory tied to the user"""
|
||||
"""Runtime directory tied to the user."""
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def site_runtime_dir(self) -> str:
|
||||
""":return: runtime directory shared by users"""
|
||||
"""Runtime directory shared by users."""
|
||||
|
||||
@property
|
||||
def user_data_path(self) -> Path:
|
||||
""":return: data path tied to the user"""
|
||||
"""Data path tied to the user."""
|
||||
return Path(self.user_data_dir)
|
||||
|
||||
@property
|
||||
def site_data_path(self) -> Path:
|
||||
""":return: data path shared by users"""
|
||||
return Path(self.site_data_dir)
|
||||
"""Data path shared by users. Only return the first item, even if ``multipath`` is set to ``True``."""
|
||||
return self._first_site_dir_as_path(self._site_data_dirs)
|
||||
|
||||
@property
|
||||
def user_config_path(self) -> Path:
|
||||
""":return: config path tied to the user"""
|
||||
"""Config path tied to the user."""
|
||||
return Path(self.user_config_dir)
|
||||
|
||||
@property
|
||||
def site_config_path(self) -> Path:
|
||||
""":return: config path shared by the users"""
|
||||
return Path(self.site_config_dir)
|
||||
"""Config path shared by users. Only return the first item, even if ``multipath`` is set to ``True``."""
|
||||
return self._first_site_dir_as_path(self._site_config_dirs)
|
||||
|
||||
@property
|
||||
def user_cache_path(self) -> Path:
|
||||
""":return: cache path tied to the user"""
|
||||
"""Cache path tied to the user."""
|
||||
return Path(self.user_cache_dir)
|
||||
|
||||
@property
|
||||
def site_cache_path(self) -> Path:
|
||||
""":return: cache path shared by users"""
|
||||
return Path(self.site_cache_dir)
|
||||
"""Cache path shared by users. Only return the first item, even if ``multipath`` is set to ``True``."""
|
||||
return self._first_site_dir_as_path(self._site_cache_dirs)
|
||||
|
||||
@property
|
||||
def user_state_path(self) -> Path:
|
||||
""":return: state path tied to the user"""
|
||||
"""State path tied to the user."""
|
||||
return Path(self.user_state_dir)
|
||||
|
||||
@property
|
||||
def site_state_path(self) -> Path:
|
||||
"""State path shared by users."""
|
||||
return Path(self.site_state_dir)
|
||||
|
||||
@property
|
||||
def user_log_path(self) -> Path:
|
||||
""":return: log path tied to the user"""
|
||||
"""Log path tied to the user."""
|
||||
return Path(self.user_log_dir)
|
||||
|
||||
@property
|
||||
def site_log_path(self) -> Path:
|
||||
"""Log path shared by users."""
|
||||
return Path(self.site_log_dir)
|
||||
|
||||
@property
|
||||
def user_documents_path(self) -> Path:
|
||||
""":return: documents a path tied to the user"""
|
||||
"""Documents path tied to the user."""
|
||||
return Path(self.user_documents_dir)
|
||||
|
||||
@property
|
||||
def user_downloads_path(self) -> Path:
|
||||
""":return: downloads path tied to the user"""
|
||||
"""Downloads path tied to the user."""
|
||||
return Path(self.user_downloads_dir)
|
||||
|
||||
@property
|
||||
def user_pictures_path(self) -> Path:
|
||||
""":return: pictures path tied to the user"""
|
||||
"""Pictures path tied to the user."""
|
||||
return Path(self.user_pictures_dir)
|
||||
|
||||
@property
|
||||
def user_videos_path(self) -> Path:
|
||||
""":return: videos path tied to the user"""
|
||||
"""Videos path tied to the user."""
|
||||
return Path(self.user_videos_dir)
|
||||
|
||||
@property
|
||||
def user_music_path(self) -> Path:
|
||||
""":return: music path tied to the user"""
|
||||
"""Music path tied to the user."""
|
||||
return Path(self.user_music_dir)
|
||||
|
||||
@property
|
||||
def user_desktop_path(self) -> Path:
|
||||
""":return: desktop path tied to the user"""
|
||||
"""Desktop path tied to the user."""
|
||||
return Path(self.user_desktop_dir)
|
||||
|
||||
@property
|
||||
def user_projects_path(self) -> Path:
|
||||
"""Projects path tied to the user."""
|
||||
return Path(self.user_projects_dir)
|
||||
|
||||
@property
|
||||
def user_publicshare_path(self) -> Path:
|
||||
"""Public share path tied to the user."""
|
||||
return Path(self.user_publicshare_dir)
|
||||
|
||||
@property
|
||||
def user_templates_path(self) -> Path:
|
||||
"""Templates path tied to the user."""
|
||||
return Path(self.user_templates_dir)
|
||||
|
||||
@property
|
||||
def user_fonts_path(self) -> Path:
|
||||
"""Fonts path tied to the user."""
|
||||
return Path(self.user_fonts_dir)
|
||||
|
||||
@property
|
||||
def user_preference_path(self) -> Path:
|
||||
"""Preference path tied to the user."""
|
||||
return Path(self.user_preference_dir)
|
||||
|
||||
@property
|
||||
def user_bin_path(self) -> Path:
|
||||
"""Bin path tied to the user."""
|
||||
return Path(self.user_bin_dir)
|
||||
|
||||
@property
|
||||
def site_bin_path(self) -> Path:
|
||||
"""Bin path shared by users."""
|
||||
return Path(self.site_bin_dir)
|
||||
|
||||
@property
|
||||
def user_applications_path(self) -> Path:
|
||||
"""Applications path tied to the user."""
|
||||
return Path(self.user_applications_dir)
|
||||
|
||||
@property
|
||||
def site_applications_path(self) -> Path:
|
||||
"""Applications path shared by users. Only return the first item, even if ``multipath`` is set to ``True``."""
|
||||
return Path(self._site_applications_dirs[0])
|
||||
|
||||
@property
|
||||
def user_runtime_path(self) -> Path:
|
||||
""":return: runtime path tied to the user"""
|
||||
"""Runtime path tied to the user."""
|
||||
return Path(self.user_runtime_dir)
|
||||
|
||||
@property
|
||||
def site_runtime_path(self) -> Path:
|
||||
""":return: runtime path shared by users"""
|
||||
"""Runtime path shared by users."""
|
||||
return Path(self.site_runtime_dir)
|
||||
|
||||
def iter_config_dirs(self) -> Iterator[str]:
|
||||
""":yield: all user and site configuration directories."""
|
||||
yield self.user_config_dir
|
||||
yield self.site_config_dir
|
||||
yield from _unique(self._iter_config_dirs())
|
||||
|
||||
def _iter_config_dirs(self) -> Iterator[str]:
|
||||
if not self._use_site:
|
||||
yield self.user_config_dir
|
||||
yield from self._create_as_yielded(self._site_config_dirs)
|
||||
|
||||
def iter_data_dirs(self) -> Iterator[str]:
|
||||
""":yield: all user and site data directories."""
|
||||
yield self.user_data_dir
|
||||
yield self.site_data_dir
|
||||
yield from _unique(self._iter_data_dirs())
|
||||
|
||||
def _iter_data_dirs(self) -> Iterator[str]:
|
||||
if not self._use_site:
|
||||
yield self.user_data_dir
|
||||
yield from self._create_as_yielded(self._site_data_dirs)
|
||||
|
||||
def iter_cache_dirs(self) -> Iterator[str]:
|
||||
""":yield: all user and site cache directories."""
|
||||
yield self.user_cache_dir
|
||||
yield self.site_cache_dir
|
||||
yield from _unique(self._iter_cache_dirs())
|
||||
|
||||
def _iter_cache_dirs(self) -> Iterator[str]:
|
||||
if not self._use_site:
|
||||
yield self.user_cache_dir
|
||||
yield from self._create_as_yielded(self._site_cache_dirs)
|
||||
|
||||
def iter_state_dirs(self) -> Iterator[str]:
|
||||
""":yield: all user and site state directories."""
|
||||
yield from _unique(self._iter_state_dirs())
|
||||
|
||||
def _iter_state_dirs(self) -> Iterator[str]:
|
||||
if not self._use_site:
|
||||
yield self.user_state_dir
|
||||
yield self.site_state_dir
|
||||
|
||||
def iter_log_dirs(self) -> Iterator[str]:
|
||||
""":yield: all user and site log directories."""
|
||||
yield from _unique(self._iter_log_dirs())
|
||||
|
||||
def _iter_log_dirs(self) -> Iterator[str]:
|
||||
if not self._use_site:
|
||||
yield self.user_log_dir
|
||||
yield self.site_log_dir
|
||||
|
||||
def iter_runtime_dirs(self) -> Iterator[str]:
|
||||
""":yield: all user and site runtime directories."""
|
||||
yield from _unique(self._iter_runtime_dirs())
|
||||
|
||||
def _iter_runtime_dirs(self) -> Iterator[str]:
|
||||
yield self.user_runtime_dir
|
||||
yield self.site_runtime_dir
|
||||
# Root's user runtime dir is already the site one; site_runtime_dir reads the invoking user's XDG_RUNTIME_DIR.
|
||||
if not self._use_site:
|
||||
yield self.site_runtime_dir
|
||||
|
||||
@property
|
||||
def _use_site(self) -> bool:
|
||||
# Only Unix redirects root's user dirs to the site ones. The iterators then skip the user dir, since under
|
||||
# multipath it is the joined site string that _unique cannot match against any single entry.
|
||||
return False
|
||||
|
||||
def iter_config_paths(self) -> Iterator[Path]:
|
||||
""":yield: all user and site configuration paths."""
|
||||
@@ -293,7 +539,187 @@ class PlatformDirsABC(ABC): # noqa: PLR0904
|
||||
for path in self.iter_cache_dirs():
|
||||
yield Path(path)
|
||||
|
||||
def iter_state_paths(self) -> Iterator[Path]:
|
||||
""":yield: all user and site state paths."""
|
||||
for path in self.iter_state_dirs():
|
||||
yield Path(path)
|
||||
|
||||
def iter_log_paths(self) -> Iterator[Path]:
|
||||
""":yield: all user and site log paths."""
|
||||
for path in self.iter_log_dirs():
|
||||
yield Path(path)
|
||||
|
||||
def iter_runtime_paths(self) -> Iterator[Path]:
|
||||
""":yield: all user and site runtime paths."""
|
||||
for path in self.iter_runtime_dirs():
|
||||
yield Path(path)
|
||||
|
||||
def place_config_file(self, name: str | os.PathLike[str]) -> Path:
|
||||
"""Return the path of ``name`` under `user_config_path`, creating the missing directories on the way.
|
||||
|
||||
Each directory it creates, including the user directory itself, gets mode ``0o700`` whether or not
|
||||
`ensure_exists` is set; directories that already exist keep their mode. On Unix, root with `use_site_for_root`
|
||||
places the file under the site directory instead and creates the missing directories with the default mode, so
|
||||
other users can read them. It does not create the file.
|
||||
|
||||
:param name: file path relative to the user directory, e.g. ``"sub/app.toml"``.
|
||||
|
||||
:raises ValueError: if ``name`` is empty, absolute, has a drive or climbs out through ``..``.
|
||||
:raises RuntimeError: if the user directory starts with ``~`` because the home directory is unknown.
|
||||
|
||||
"""
|
||||
return self._place_file(lambda dirs: dirs.user_config_path, name)
|
||||
|
||||
def place_data_file(self, name: str | os.PathLike[str]) -> Path:
|
||||
"""Like `place_config_file`, under `user_data_path`."""
|
||||
return self._place_file(lambda dirs: dirs.user_data_path, name)
|
||||
|
||||
def place_cache_file(self, name: str | os.PathLike[str]) -> Path:
|
||||
"""Like `place_config_file`, under `user_cache_path`."""
|
||||
return self._place_file(lambda dirs: dirs.user_cache_path, name)
|
||||
|
||||
def place_state_file(self, name: str | os.PathLike[str]) -> Path:
|
||||
"""Like `place_config_file`, under `user_state_path`."""
|
||||
return self._place_file(lambda dirs: dirs.user_state_path, name)
|
||||
|
||||
def place_log_file(self, name: str | os.PathLike[str]) -> Path:
|
||||
"""Like `place_config_file`, under `user_log_path`."""
|
||||
return self._place_file(lambda dirs: dirs.user_log_path, name)
|
||||
|
||||
def place_runtime_file(self, name: str | os.PathLike[str]) -> Path:
|
||||
"""Like `place_config_file`, under `user_runtime_path`.
|
||||
|
||||
:raises PermissionError: on Unix, if another user owns the temporary fallback directory.
|
||||
|
||||
"""
|
||||
return self._place_file(lambda dirs: dirs.user_runtime_path, name)
|
||||
|
||||
def _place_file(self, user_path: Callable[[PlatformDirsABC], Path], name: str | os.PathLike[str]) -> Path:
|
||||
_ensure_inside_base("name", relative := os.fspath(name))
|
||||
if not Path(relative).parts:
|
||||
msg = f"name must point to a file, got {relative!r}"
|
||||
raise ValueError(msg)
|
||||
# Under ensure_exists the lookup itself would create the user directory with the default mode, not 0o700.
|
||||
(lookup := copy(self)).ensure_exists = False
|
||||
# Under multipath *_dir joins the site directories with os.pathsep, so place under the single *_path.
|
||||
_ensure_home_known(str(directory := user_path(lookup)))
|
||||
path = directory / relative
|
||||
if self._use_site:
|
||||
# Site directories keep the default mode, as under ensure_exists, so other users can still read them.
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
else:
|
||||
_make_private_directories(path.parent)
|
||||
return path
|
||||
|
||||
def find_config_file(self, name: str | os.PathLike[str]) -> Path | None:
|
||||
"""Find the first ``name`` file in :meth:`iter_config_paths` order, without creating any directory.
|
||||
|
||||
:param name: path relative to each directory, may contain subdirectories.
|
||||
|
||||
:returns: the file, or ``None`` when no directory holds one.
|
||||
|
||||
:raises ValueError: if ``name`` is absolute, has a drive or climbs out with ``..``.
|
||||
|
||||
"""
|
||||
return next(self._find_files(PlatformDirsABC.iter_config_paths, name), None)
|
||||
|
||||
def find_config_files(self, name: str | os.PathLike[str]) -> list[Path]:
|
||||
"""Find every ``name`` file in :meth:`iter_config_paths` order, without creating any directory.
|
||||
|
||||
:param name: see :meth:`find_config_file`.
|
||||
|
||||
:returns: the files, user directory first.
|
||||
|
||||
:raises ValueError: see :meth:`find_config_file`.
|
||||
|
||||
"""
|
||||
return list(self._find_files(PlatformDirsABC.iter_config_paths, name))
|
||||
|
||||
def find_data_file(self, name: str | os.PathLike[str]) -> Path | None:
|
||||
"""Like :meth:`find_config_file`, searching :meth:`iter_data_paths`."""
|
||||
return next(self._find_files(PlatformDirsABC.iter_data_paths, name), None)
|
||||
|
||||
def find_data_files(self, name: str | os.PathLike[str]) -> list[Path]:
|
||||
"""Like :meth:`find_config_files`, searching :meth:`iter_data_paths`."""
|
||||
return list(self._find_files(PlatformDirsABC.iter_data_paths, name))
|
||||
|
||||
def find_cache_file(self, name: str | os.PathLike[str]) -> Path | None:
|
||||
"""Like :meth:`find_config_file`, searching :meth:`iter_cache_paths`."""
|
||||
return next(self._find_files(PlatformDirsABC.iter_cache_paths, name), None)
|
||||
|
||||
def find_cache_files(self, name: str | os.PathLike[str]) -> list[Path]:
|
||||
"""Like :meth:`find_config_files`, searching :meth:`iter_cache_paths`."""
|
||||
return list(self._find_files(PlatformDirsABC.iter_cache_paths, name))
|
||||
|
||||
def find_state_file(self, name: str | os.PathLike[str]) -> Path | None:
|
||||
"""Like :meth:`find_config_file`, searching :meth:`iter_state_paths`."""
|
||||
return next(self._find_files(PlatformDirsABC.iter_state_paths, name), None)
|
||||
|
||||
def find_state_files(self, name: str | os.PathLike[str]) -> list[Path]:
|
||||
"""Like :meth:`find_config_files`, searching :meth:`iter_state_paths`."""
|
||||
return list(self._find_files(PlatformDirsABC.iter_state_paths, name))
|
||||
|
||||
def find_log_file(self, name: str | os.PathLike[str]) -> Path | None:
|
||||
"""Like :meth:`find_config_file`, searching :meth:`iter_log_paths`."""
|
||||
return next(self._find_files(PlatformDirsABC.iter_log_paths, name), None)
|
||||
|
||||
def find_log_files(self, name: str | os.PathLike[str]) -> list[Path]:
|
||||
"""Like :meth:`find_config_files`, searching :meth:`iter_log_paths`."""
|
||||
return list(self._find_files(PlatformDirsABC.iter_log_paths, name))
|
||||
|
||||
def find_runtime_file(self, name: str | os.PathLike[str]) -> Path | None:
|
||||
"""Like :meth:`find_config_file`, searching :meth:`iter_runtime_paths`."""
|
||||
return next(self._find_files(PlatformDirsABC.iter_runtime_paths, name), None)
|
||||
|
||||
def find_runtime_files(self, name: str | os.PathLike[str]) -> list[Path]:
|
||||
"""Like :meth:`find_config_files`, searching :meth:`iter_runtime_paths`."""
|
||||
return list(self._find_files(PlatformDirsABC.iter_runtime_paths, name))
|
||||
|
||||
def _find_files(
|
||||
self, iter_paths: Callable[[PlatformDirsABC], Iterator[Path]], name: str | os.PathLike[str]
|
||||
) -> Iterator[Path]:
|
||||
_ensure_inside_base("name", relative := os.fspath(name))
|
||||
# The iterators create each directory they yield under ensure_exists, and a lookup must only read the disk.
|
||||
(lookup := copy(self)).ensure_exists = False
|
||||
return (path for directory in iter_paths(lookup) if (path := directory / relative).is_file())
|
||||
|
||||
|
||||
def _ensure_inside_base(name: str, value: str | Literal[False] | None) -> None:
|
||||
if not value:
|
||||
return
|
||||
# os.path.join discards the base when a later component has a root or a drive, and ``..`` climbs out of it.
|
||||
drive, tail = os.path.splitdrive(value)
|
||||
if drive or tail.startswith(("/", "\\")) or ".." in tail.replace("\\", "/").split("/"):
|
||||
msg = f"{name} must stay inside the base directory, got {value!r}"
|
||||
raise ValueError(msg)
|
||||
|
||||
|
||||
def _ensure_home_known(path: str) -> None:
|
||||
# expanduser leaves "~" when the home is unknown, and creating it would make a "~" directory in the cwd.
|
||||
if path.startswith("~"):
|
||||
msg = f"could not determine the home directory, refusing to create {path!r}"
|
||||
raise RuntimeError(msg)
|
||||
|
||||
|
||||
def _unique(dirs: Iterable[str]) -> Iterator[str]:
|
||||
""":yield: ``dirs`` in order, skipping any directory already yielded."""
|
||||
# Lazy on purpose: under ensure_exists reading a site_*_dir creates it, so draining ``dirs`` up front would
|
||||
# create directories for a caller that stops after the first entry.
|
||||
seen: set[str] = set()
|
||||
for path in dirs:
|
||||
if path not in seen:
|
||||
seen.add(path)
|
||||
yield path
|
||||
|
||||
|
||||
def _make_private_directories(path: Path) -> None:
|
||||
# XDG asks for 0o700 on each directory created on the way, while Path.mkdir(parents=True) applies it to the last.
|
||||
try:
|
||||
path.mkdir(mode=0o700, exist_ok=True)
|
||||
except FileNotFoundError:
|
||||
_make_private_directories(path.parent)
|
||||
path.mkdir(mode=0o700, exist_ok=True)
|
||||
|
||||
|
||||
class RuntimeDirWarning(UserWarning):
|
||||
"""Emitted when the Unix :attr:`~platformdirs.unix.Unix.user_runtime_dir` cannot use ``$XDG_RUNTIME_DIR``."""
|
||||
@@ -2,145 +2,203 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os.path
|
||||
import re
|
||||
import sys
|
||||
from typing import TYPE_CHECKING
|
||||
from typing import Final
|
||||
|
||||
from ._xdg import XDGMixin, _expand_user
|
||||
from .api import PlatformDirsABC
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from pathlib import Path
|
||||
|
||||
class _MacOSDefaults(PlatformDirsABC): # ruff:ignore[too-many-public-methods]
|
||||
"""Default platform directories for macOS without XDG environment variable overrides.
|
||||
|
||||
class MacOS(PlatformDirsABC):
|
||||
"""
|
||||
Platform directories for the macOS operating system.
|
||||
|
||||
Follows the guidance from
|
||||
`Apple documentation <https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/MacOSXDirectories/MacOSXDirectories.html>`_.
|
||||
Makes use of the `appname <platformdirs.api.PlatformDirsABC.appname>`,
|
||||
`version <platformdirs.api.PlatformDirsABC.version>`,
|
||||
`ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
|
||||
Follows the guidance from `Apple's File System Programming Guide
|
||||
<https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/MacOSXDirectories/MacOSXDirectories.html>`_.
|
||||
The XDG env var handling is in :class:`~platformdirs._xdg.XDGMixin`.
|
||||
|
||||
"""
|
||||
|
||||
def _base_user_app_support_dir(self) -> str:
|
||||
return self._append_app_name_and_version(_expand_user("~/Library/Application Support"), private=True)
|
||||
|
||||
def _base_site_dirs(self) -> list[str]:
|
||||
path_list = [self._join_app_name_and_version(f"{prefix}/share")] if (prefix := _homebrew_prefix()) else []
|
||||
path_list.append(self._join_app_name_and_version("/Library/Application Support"))
|
||||
return path_list
|
||||
|
||||
@property
|
||||
def user_data_dir(self) -> str:
|
||||
""":return: data directory tied to the user, e.g. ``~/Library/Application Support/$appname/$version``"""
|
||||
return self._append_app_name_and_version(os.path.expanduser("~/Library/Application Support")) # noqa: PTH111
|
||||
"""Data directory tied to the user, e.g. ``~/Library/Application Support/$appname/$version``."""
|
||||
return self._base_user_app_support_dir()
|
||||
|
||||
@property
|
||||
def site_data_dir(self) -> str:
|
||||
"""
|
||||
:return: data directory shared by users, e.g. ``/Library/Application Support/$appname/$version``.
|
||||
If we're using a Python binary managed by `Homebrew <https://brew.sh>`_, the directory
|
||||
will be under the Homebrew prefix, e.g. ``$homebrew_prefix/share/$appname/$version``.
|
||||
If `multipath <platformdirs.api.PlatformDirsABC.multipath>` is enabled, and we're in Homebrew,
|
||||
the response is a multi-path string separated by ":", e.g.
|
||||
``$homebrew_prefix/share/$appname/$version:/Library/Application Support/$appname/$version``
|
||||
"""
|
||||
is_homebrew = "/opt/python" in sys.prefix
|
||||
homebrew_prefix = sys.prefix.split("/opt/python")[0] if is_homebrew else ""
|
||||
path_list = [self._append_app_name_and_version(f"{homebrew_prefix}/share")] if is_homebrew else []
|
||||
path_list.append(self._append_app_name_and_version("/Library/Application Support"))
|
||||
if self.multipath:
|
||||
return os.pathsep.join(path_list)
|
||||
return path_list[0]
|
||||
|
||||
@property
|
||||
def site_data_path(self) -> Path:
|
||||
""":return: data path shared by users. Only return the first item, even if ``multipath`` is set to ``True``"""
|
||||
return self._first_item_as_path_if_multipath(self.site_data_dir)
|
||||
def _site_data_dirs(self) -> list[str]:
|
||||
return self._base_site_dirs()
|
||||
|
||||
@property
|
||||
def user_config_dir(self) -> str:
|
||||
""":return: config directory tied to the user, same as `user_data_dir`"""
|
||||
return self.user_data_dir
|
||||
"""Config directory tied to the user, same as `user_data_dir`."""
|
||||
return self._base_user_app_support_dir()
|
||||
|
||||
@property
|
||||
def site_config_dir(self) -> str:
|
||||
""":return: config directory shared by the users, same as `site_data_dir`"""
|
||||
return self.site_data_dir
|
||||
def _site_config_dirs(self) -> list[str]:
|
||||
return self._base_site_dirs()
|
||||
|
||||
@property
|
||||
def user_cache_dir(self) -> str:
|
||||
""":return: cache directory tied to the user, e.g. ``~/Library/Caches/$appname/$version``"""
|
||||
return self._append_app_name_and_version(os.path.expanduser("~/Library/Caches")) # noqa: PTH111
|
||||
"""Cache directory tied to the user, e.g. ``~/Library/Caches/$appname/$version``."""
|
||||
return self._append_app_name_and_version(_expand_user("~/Library/Caches"), private=True)
|
||||
|
||||
@property
|
||||
def _site_cache_dirs(self) -> list[str]:
|
||||
path_list = [self._join_app_name_and_version(f"{prefix}/var/cache")] if (prefix := _homebrew_prefix()) else []
|
||||
path_list.append(self._join_app_name_and_version("/Library/Caches"))
|
||||
return path_list
|
||||
|
||||
@property
|
||||
def site_cache_dir(self) -> str:
|
||||
"""
|
||||
:return: cache directory shared by users, e.g. ``/Library/Caches/$appname/$version``.
|
||||
If we're using a Python binary managed by `Homebrew <https://brew.sh>`_, the directory
|
||||
will be under the Homebrew prefix, e.g. ``$homebrew_prefix/var/cache/$appname/$version``.
|
||||
If `multipath <platformdirs.api.PlatformDirsABC.multipath>` is enabled, and we're in Homebrew,
|
||||
the response is a multi-path string separated by ":", e.g.
|
||||
``$homebrew_prefix/var/cache/$appname/$version:/Library/Caches/$appname/$version``
|
||||
"""
|
||||
is_homebrew = "/opt/python" in sys.prefix
|
||||
homebrew_prefix = sys.prefix.split("/opt/python")[0] if is_homebrew else ""
|
||||
path_list = [self._append_app_name_and_version(f"{homebrew_prefix}/var/cache")] if is_homebrew else []
|
||||
path_list.append(self._append_app_name_and_version("/Library/Caches"))
|
||||
if self.multipath:
|
||||
return os.pathsep.join(path_list)
|
||||
return path_list[0]
|
||||
|
||||
@property
|
||||
def site_cache_path(self) -> Path:
|
||||
""":return: cache path shared by users. Only return the first item, even if ``multipath`` is set to ``True``"""
|
||||
return self._first_item_as_path_if_multipath(self.site_cache_dir)
|
||||
"""Cache directory shared by users, e.g. ``/Library/Caches/$appname/$version``. If we're using a Python binary managed by `Homebrew <https://brew.sh>`_, the directory will be under the Homebrew prefix, e.g. ``$homebrew_prefix/var/cache/$appname/$version``. If `multipath <platformdirs.api.PlatformDirsABC.multipath>` is enabled, and we're in Homebrew, the response is a multi-path string separated by ":", e.g. ``$homebrew_prefix/var/cache/$appname/$version:/Library/Caches/$appname/$version``."""
|
||||
return self._select_site_dirs(self._site_cache_dirs)
|
||||
|
||||
@property
|
||||
def user_state_dir(self) -> str:
|
||||
""":return: state directory tied to the user, same as `user_data_dir`"""
|
||||
return self.user_data_dir
|
||||
"""State directory tied to the user, same as `user_data_dir` without ``$XDG_DATA_HOME``, e.g. ``~/Library/Application Support/$appname/$version``."""
|
||||
return self._base_user_app_support_dir()
|
||||
|
||||
@property
|
||||
def site_state_dir(self) -> str:
|
||||
"""State directory shared by users, the first entry of `site_data_dir` without ``$XDG_DATA_DIRS``, ignoring `multipath <platformdirs.api.PlatformDirsABC.multipath>`."""
|
||||
path = self._base_site_dirs()[0]
|
||||
self._optionally_create_directory(path, private=False)
|
||||
return path
|
||||
|
||||
@property
|
||||
def user_log_dir(self) -> str:
|
||||
""":return: log directory tied to the user, e.g. ``~/Library/Logs/$appname/$version``"""
|
||||
return self._append_app_name_and_version(os.path.expanduser("~/Library/Logs")) # noqa: PTH111
|
||||
"""Log directory tied to the user, e.g. ``~/Library/Logs/$appname/$version``."""
|
||||
return self._append_app_name_and_version(_expand_user("~/Library/Logs"), private=True)
|
||||
|
||||
@property
|
||||
def site_log_dir(self) -> str:
|
||||
"""Log directory shared by users, e.g. ``/Library/Logs/$appname/$version``."""
|
||||
return self._append_app_name_and_version("/Library/Logs", private=False)
|
||||
|
||||
@property
|
||||
def user_documents_dir(self) -> str:
|
||||
""":return: documents directory tied to the user, e.g. ``~/Documents``"""
|
||||
return os.path.expanduser("~/Documents") # noqa: PTH111
|
||||
"""Documents directory tied to the user, e.g. ``~/Documents``."""
|
||||
return _expand_user("~/Documents")
|
||||
|
||||
@property
|
||||
def user_downloads_dir(self) -> str:
|
||||
""":return: downloads directory tied to the user, e.g. ``~/Downloads``"""
|
||||
return os.path.expanduser("~/Downloads") # noqa: PTH111
|
||||
"""Downloads directory tied to the user, e.g. ``~/Downloads``."""
|
||||
return _expand_user("~/Downloads")
|
||||
|
||||
@property
|
||||
def user_pictures_dir(self) -> str:
|
||||
""":return: pictures directory tied to the user, e.g. ``~/Pictures``"""
|
||||
return os.path.expanduser("~/Pictures") # noqa: PTH111
|
||||
"""Pictures directory tied to the user, e.g. ``~/Pictures``."""
|
||||
return _expand_user("~/Pictures")
|
||||
|
||||
@property
|
||||
def user_videos_dir(self) -> str:
|
||||
""":return: videos directory tied to the user, e.g. ``~/Movies``"""
|
||||
return os.path.expanduser("~/Movies") # noqa: PTH111
|
||||
"""Videos directory tied to the user, e.g. ``~/Movies``."""
|
||||
return _expand_user("~/Movies")
|
||||
|
||||
@property
|
||||
def user_music_dir(self) -> str:
|
||||
""":return: music directory tied to the user, e.g. ``~/Music``"""
|
||||
return os.path.expanduser("~/Music") # noqa: PTH111
|
||||
"""Music directory tied to the user, e.g. ``~/Music``."""
|
||||
return _expand_user("~/Music")
|
||||
|
||||
@property
|
||||
def user_desktop_dir(self) -> str:
|
||||
""":return: desktop directory tied to the user, e.g. ``~/Desktop``"""
|
||||
return os.path.expanduser("~/Desktop") # noqa: PTH111
|
||||
"""Desktop directory tied to the user, e.g. ``~/Desktop``."""
|
||||
return _expand_user("~/Desktop")
|
||||
|
||||
@property
|
||||
def user_projects_dir(self) -> str:
|
||||
"""Projects directory tied to the user, e.g. ``~/Projects``."""
|
||||
return _expand_user("~/Projects")
|
||||
|
||||
@property
|
||||
def user_publicshare_dir(self) -> str:
|
||||
"""Public share directory tied to the user, e.g. ``~/Public``."""
|
||||
return _expand_user("~/Public")
|
||||
|
||||
@property
|
||||
def user_templates_dir(self) -> str:
|
||||
"""Templates directory tied to the user, e.g. ``~/Templates``."""
|
||||
return _expand_user("~/Templates")
|
||||
|
||||
@property
|
||||
def user_fonts_dir(self) -> str:
|
||||
"""Fonts directory tied to the user, e.g. ``~/Library/Fonts``."""
|
||||
return _expand_user("~/Library/Fonts")
|
||||
|
||||
@property
|
||||
def user_preference_dir(self) -> str:
|
||||
"""Preference directory tied to the user, e.g. ``~/Library/Preferences/AppName``."""
|
||||
return self._append_app_name_and_version(_expand_user("~/Library/Preferences"), private=True)
|
||||
|
||||
@property
|
||||
def user_bin_dir(self) -> str:
|
||||
"""Bin directory tied to the user, e.g. ``~/.local/bin``."""
|
||||
return _expand_user("~/.local/bin")
|
||||
|
||||
@property
|
||||
def site_bin_dir(self) -> str:
|
||||
"""Bin directory shared by users, e.g. ``/usr/local/bin``."""
|
||||
return "/usr/local/bin"
|
||||
|
||||
@property
|
||||
def user_applications_dir(self) -> str:
|
||||
"""Applications directory tied to the user, e.g. ``~/Applications``."""
|
||||
return _expand_user("~/Applications")
|
||||
|
||||
@property
|
||||
def _site_applications_dirs(self) -> list[str]:
|
||||
return ["/Applications"]
|
||||
|
||||
@property
|
||||
def user_runtime_dir(self) -> str:
|
||||
""":return: runtime directory tied to the user, e.g. ``~/Library/Caches/TemporaryItems/$appname/$version``"""
|
||||
return self._append_app_name_and_version(os.path.expanduser("~/Library/Caches/TemporaryItems")) # noqa: PTH111
|
||||
"""Runtime directory tied to the user, e.g. ``~/Library/Caches/TemporaryItems/$appname/$version``."""
|
||||
return self._append_app_name_and_version(_expand_user("~/Library/Caches/TemporaryItems"), private=True)
|
||||
|
||||
@property
|
||||
def site_runtime_dir(self) -> str:
|
||||
""":return: runtime directory shared by users, same as `user_runtime_dir`"""
|
||||
"""Runtime directory shared by users, same as `user_runtime_dir`."""
|
||||
return self.user_runtime_dir
|
||||
|
||||
|
||||
class MacOS(XDGMixin, _MacOSDefaults):
|
||||
"""Platform directories for the macOS operating system.
|
||||
|
||||
Follows the guidance from `Apple documentation
|
||||
<https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/MacOSXDirectories/MacOSXDirectories.html>`_.
|
||||
Makes use of the `appname <platformdirs.api.PlatformDirsABC.appname>`, `version
|
||||
<platformdirs.api.PlatformDirsABC.version>`, `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
|
||||
|
||||
XDG environment variables (e.g. ``$XDG_DATA_HOME``) are supported and take precedence over macOS defaults.
|
||||
|
||||
"""
|
||||
|
||||
|
||||
# Homebrew links each Python formula as a framework build, and a virtual environment keeps it as sys.base_prefix.
|
||||
_HOMEBREW_PYTHON: Final = re.compile(
|
||||
r"""
|
||||
(?P<prefix>.+) # $HOMEBREW_PREFIX, such as /opt/homebrew or /usr/local
|
||||
/opt/python[^/]* # formula link: python, python3 or python@3.13
|
||||
/Frameworks/Python\.framework # framework build
|
||||
/Versions/[^/]+ # interpreter version, such as 3.13
|
||||
""",
|
||||
re.VERBOSE,
|
||||
)
|
||||
|
||||
|
||||
def _homebrew_prefix() -> str | None:
|
||||
if match := _HOMEBREW_PYTHON.fullmatch(sys.base_prefix):
|
||||
return match["prefix"]
|
||||
return None
|
||||
|
||||
|
||||
__all__ = [
|
||||
"MacOS",
|
||||
]
|
||||
@@ -3,15 +3,17 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import re
|
||||
import stat
|
||||
import sys
|
||||
from configparser import ConfigParser
|
||||
import warnings
|
||||
from contextlib import suppress
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, NoReturn
|
||||
from tempfile import gettempdir
|
||||
from typing import Final, NoReturn
|
||||
|
||||
from .api import PlatformDirsABC
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import Iterator
|
||||
from ._xdg import XDGMixin, _expand_user, _xdg_dir
|
||||
from .api import PlatformDirsABC, RuntimeDirWarning
|
||||
|
||||
if sys.platform == "win32":
|
||||
|
||||
@@ -23,10 +25,197 @@ else:
|
||||
from os import getuid
|
||||
|
||||
|
||||
class Unix(PlatformDirsABC): # noqa: PLR0904
|
||||
class _UnixDefaults(PlatformDirsABC): # ruff:ignore[too-many-public-methods]
|
||||
"""Default directories for Unix/Linux without XDG environment variable overrides.
|
||||
|
||||
The XDG env var handling is in :class:`~platformdirs._xdg.XDGMixin`.
|
||||
|
||||
"""
|
||||
On Unix/Linux, we follow the `XDG Basedir Spec <https://specifications.freedesktop.org/basedir-spec/basedir-spec-
|
||||
latest.html>`_.
|
||||
|
||||
@property
|
||||
def _use_site(self) -> bool:
|
||||
return self.use_site_for_root and getuid() == 0
|
||||
|
||||
@property
|
||||
def user_data_dir(self) -> str:
|
||||
"""Data directory tied to the user, e.g. ``~/.local/share/$appname/$version`` or ``$XDG_DATA_HOME/$appname/$version``."""
|
||||
return self._append_app_name_and_version(_expand_user("~/.local/share"), private=True)
|
||||
|
||||
@property
|
||||
def _site_data_dirs(self) -> list[str]:
|
||||
return [self._join_app_name_and_version("/usr/local/share"), self._join_app_name_and_version("/usr/share")]
|
||||
|
||||
@property
|
||||
def user_config_dir(self) -> str:
|
||||
"""Config directory tied to the user, e.g. ``~/.config/$appname/$version`` or ``$XDG_CONFIG_HOME/$appname/$version``."""
|
||||
return self._append_app_name_and_version(_expand_user("~/.config"), private=True)
|
||||
|
||||
@property
|
||||
def _site_config_dirs(self) -> list[str]:
|
||||
return [self._join_app_name_and_version("/etc/xdg")]
|
||||
|
||||
@property
|
||||
def user_cache_dir(self) -> str:
|
||||
"""Cache directory tied to the user, e.g. ``~/.cache/$appname/$version`` or ``$XDG_CACHE_HOME/$appname/$version``."""
|
||||
return self._append_app_name_and_version(_expand_user("~/.cache"), private=True)
|
||||
|
||||
@property
|
||||
def site_cache_dir(self) -> str:
|
||||
"""Cache directory shared by users, e.g. ``/var/cache/$appname/$version``."""
|
||||
return self._append_app_name_and_version("/var/cache", private=False)
|
||||
|
||||
@property
|
||||
def user_state_dir(self) -> str:
|
||||
"""State directory tied to the user, e.g. ``~/.local/state/$appname/$version`` or ``$XDG_STATE_HOME/$appname/$version``."""
|
||||
return self._append_app_name_and_version(_expand_user("~/.local/state"), private=True)
|
||||
|
||||
@property
|
||||
def site_state_dir(self) -> str:
|
||||
"""State directory shared by users, e.g. ``/var/lib/$appname/$version``."""
|
||||
return self._append_app_name_and_version("/var/lib", private=False)
|
||||
|
||||
@property
|
||||
def user_log_dir(self) -> str:
|
||||
"""Log directory tied to the user, same as `user_state_dir` if not opinionated else ``log`` in it."""
|
||||
path = self.user_state_dir
|
||||
if self.opinion:
|
||||
path = os.path.join(path, "log") # ruff:ignore[os-path-join]
|
||||
self._optionally_create_directory(path, private=True)
|
||||
return path
|
||||
|
||||
@property
|
||||
def site_log_dir(self) -> str:
|
||||
"""Log directory shared by users, e.g. ``/var/log/$appname/$version``.
|
||||
|
||||
Unlike `user_log_dir`, ``opinion`` has no effect since ``/var/log`` is inherently a log directory.
|
||||
|
||||
"""
|
||||
return self._append_app_name_and_version("/var/log", private=False)
|
||||
|
||||
@property
|
||||
def user_documents_dir(self) -> str:
|
||||
"""Documents directory tied to the user, e.g. ``~/Documents``."""
|
||||
return self._user_media_dir("XDG_DOCUMENTS_DIR", "~/Documents")
|
||||
|
||||
@property
|
||||
def user_downloads_dir(self) -> str:
|
||||
"""Downloads directory tied to the user, e.g. ``~/Downloads``."""
|
||||
return self._user_media_dir("XDG_DOWNLOAD_DIR", "~/Downloads")
|
||||
|
||||
@property
|
||||
def user_pictures_dir(self) -> str:
|
||||
"""Pictures directory tied to the user, e.g. ``~/Pictures``."""
|
||||
return self._user_media_dir("XDG_PICTURES_DIR", "~/Pictures")
|
||||
|
||||
@property
|
||||
def user_videos_dir(self) -> str:
|
||||
"""Videos directory tied to the user, e.g. ``~/Videos``."""
|
||||
return self._user_media_dir("XDG_VIDEOS_DIR", "~/Videos")
|
||||
|
||||
@property
|
||||
def user_music_dir(self) -> str:
|
||||
"""Music directory tied to the user, e.g. ``~/Music``."""
|
||||
return self._user_media_dir("XDG_MUSIC_DIR", "~/Music")
|
||||
|
||||
@property
|
||||
def user_desktop_dir(self) -> str:
|
||||
"""Desktop directory tied to the user, e.g. ``~/Desktop``."""
|
||||
return self._user_media_dir("XDG_DESKTOP_DIR", "~/Desktop")
|
||||
|
||||
@property
|
||||
def user_projects_dir(self) -> str:
|
||||
"""Projects directory tied to the user, e.g. ``~/Projects``."""
|
||||
return self._user_media_dir("XDG_PROJECTS_DIR", "~/Projects")
|
||||
|
||||
@property
|
||||
def user_publicshare_dir(self) -> str:
|
||||
"""Public share directory tied to the user, e.g. ``~/Public``."""
|
||||
return self._user_media_dir("XDG_PUBLICSHARE_DIR", "~/Public")
|
||||
|
||||
@property
|
||||
def user_templates_dir(self) -> str:
|
||||
"""Templates directory tied to the user, e.g. ``~/Templates``."""
|
||||
return self._user_media_dir("XDG_TEMPLATES_DIR", "~/Templates")
|
||||
|
||||
def _user_media_dir(self, key: str, default: str) -> str:
|
||||
if path := _get_user_dirs_folder(key):
|
||||
self._optionally_create_media_directory(path)
|
||||
return path
|
||||
return _expand_user(default)
|
||||
|
||||
@property
|
||||
def user_fonts_dir(self) -> str:
|
||||
"""Fonts directory tied to the user, e.g. ``~/.local/share/fonts``."""
|
||||
return f"{_expand_user('~/.local/share')}/fonts"
|
||||
|
||||
@property
|
||||
def user_preference_dir(self) -> str:
|
||||
"""Preference directory tied to the user, same as ``user_config_dir``."""
|
||||
return self.user_config_dir
|
||||
|
||||
@property
|
||||
def user_bin_dir(self) -> str:
|
||||
"""Bin directory tied to the user, e.g. ``~/.local/bin``."""
|
||||
return _expand_user("~/.local/bin")
|
||||
|
||||
@property
|
||||
def site_bin_dir(self) -> str:
|
||||
"""Bin directory shared by users, e.g. ``/usr/local/bin``."""
|
||||
return "/usr/local/bin"
|
||||
|
||||
@property
|
||||
def user_applications_dir(self) -> str:
|
||||
"""Applications directory tied to the user, e.g. ``~/.local/share/applications``."""
|
||||
return f"{_expand_user('~/.local/share')}{os.sep}applications"
|
||||
|
||||
@property
|
||||
def _site_applications_dirs(self) -> list[str]:
|
||||
return [os.path.join(p, "applications") for p in ["/usr/local/share", "/usr/share"]] # ruff:ignore[os-path-join]
|
||||
|
||||
def _default_runtime_dir(self) -> str:
|
||||
if sys.platform.startswith("openbsd"):
|
||||
path = f"/tmp/run/user/{getuid()}" # ruff:ignore[hardcoded-temp-file]
|
||||
elif sys.platform.startswith(("freebsd", "netbsd")):
|
||||
path = f"/var/run/user/{getuid()}"
|
||||
else:
|
||||
path = f"/run/user/{getuid()}"
|
||||
return path if os.path.lexists(path) and not _runtime_dir_problem(path) else self._temp_runtime_dir()
|
||||
|
||||
def _temp_runtime_dir(self) -> str:
|
||||
# Another user can pre-create this predictable name, and XDG requires an owned runtime dir with mode 0700.
|
||||
path = f"{gettempdir()}/runtime-{getuid()}"
|
||||
with suppress(FileExistsError):
|
||||
self._optionally_create_directory(path, private=True)
|
||||
if problem := _runtime_dir_problem(path, check_mode=False):
|
||||
msg = f"runtime directory {problem}; set XDG_RUNTIME_DIR instead"
|
||||
raise PermissionError(msg)
|
||||
# Earlier releases created this directory with the default 0755.
|
||||
if self.ensure_exists:
|
||||
Path(path).chmod(_RUNTIME_DIR_MODE)
|
||||
return path
|
||||
|
||||
@property
|
||||
def site_runtime_dir(self) -> str:
|
||||
"""Runtime directory shared by users, e.g. ``/run/$appname/$version`` or ``$XDG_RUNTIME_DIR/$appname/$version``.
|
||||
|
||||
Note that this behaves almost exactly like `user_runtime_dir` if ``$XDG_RUNTIME_DIR`` is set, but will fall back
|
||||
to paths associated to the root user instead of a regular logged-in user if it's not set.
|
||||
|
||||
If you wish to ensure that a logged-in root user path is returned e.g. ``/run/user/0``, use `user_runtime_dir`
|
||||
instead.
|
||||
|
||||
For FreeBSD/OpenBSD/NetBSD, it would return ``/var/run/$appname/$version`` if ``$XDG_RUNTIME_DIR`` is not set.
|
||||
|
||||
"""
|
||||
if sys.platform.startswith(("freebsd", "openbsd", "netbsd")):
|
||||
path = "/var/run"
|
||||
else:
|
||||
path = "/run"
|
||||
return self._append_app_name_and_version(path, private=False)
|
||||
|
||||
|
||||
class Unix(XDGMixin, _UnixDefaults):
|
||||
"""On Unix/Linux, we follow the `XDG Basedir Spec <https://specifications.freedesktop.org/basedir/latest/>`_.
|
||||
|
||||
The spec allows overriding directories with environment variables. The examples shown are the default values,
|
||||
alongside the name of the environment variable that overrides them. Makes use of the `appname
|
||||
@@ -38,233 +227,164 @@ class Unix(PlatformDirsABC): # noqa: PLR0904
|
||||
|
||||
@property
|
||||
def user_data_dir(self) -> str:
|
||||
"""
|
||||
:return: data directory tied to the user, e.g. ``~/.local/share/$appname/$version`` or
|
||||
``$XDG_DATA_HOME/$appname/$version``
|
||||
"""
|
||||
path = os.environ.get("XDG_DATA_HOME", "")
|
||||
if not path.strip():
|
||||
path = os.path.expanduser("~/.local/share") # noqa: PTH111
|
||||
return self._append_app_name_and_version(path)
|
||||
|
||||
@property
|
||||
def _site_data_dirs(self) -> list[str]:
|
||||
path = os.environ.get("XDG_DATA_DIRS", "")
|
||||
if not path.strip():
|
||||
path = f"/usr/local/share{os.pathsep}/usr/share"
|
||||
return [self._append_app_name_and_version(p) for p in path.split(os.pathsep)]
|
||||
|
||||
@property
|
||||
def site_data_dir(self) -> str:
|
||||
"""
|
||||
:return: data directories shared by users (if `multipath <platformdirs.api.PlatformDirsABC.multipath>` is
|
||||
enabled and ``XDG_DATA_DIRS`` is set and a multi path the response is also a multi path separated by the
|
||||
OS path separator), e.g. ``/usr/local/share/$appname/$version`` or ``/usr/share/$appname/$version``
|
||||
"""
|
||||
# XDG default for $XDG_DATA_DIRS; only first, if multipath is False
|
||||
dirs = self._site_data_dirs
|
||||
if not self.multipath:
|
||||
return dirs[0]
|
||||
return os.pathsep.join(dirs)
|
||||
"""Data directory tied to the user, or site equivalent when root with ``use_site_for_root``."""
|
||||
return self.site_data_dir if self._use_site else super().user_data_dir
|
||||
|
||||
@property
|
||||
def user_config_dir(self) -> str:
|
||||
"""
|
||||
:return: config directory tied to the user, e.g. ``~/.config/$appname/$version`` or
|
||||
``$XDG_CONFIG_HOME/$appname/$version``
|
||||
"""
|
||||
path = os.environ.get("XDG_CONFIG_HOME", "")
|
||||
if not path.strip():
|
||||
path = os.path.expanduser("~/.config") # noqa: PTH111
|
||||
return self._append_app_name_and_version(path)
|
||||
|
||||
@property
|
||||
def _site_config_dirs(self) -> list[str]:
|
||||
path = os.environ.get("XDG_CONFIG_DIRS", "")
|
||||
if not path.strip():
|
||||
path = "/etc/xdg"
|
||||
return [self._append_app_name_and_version(p) for p in path.split(os.pathsep)]
|
||||
|
||||
@property
|
||||
def site_config_dir(self) -> str:
|
||||
"""
|
||||
:return: config directories shared by users (if `multipath <platformdirs.api.PlatformDirsABC.multipath>`
|
||||
is enabled and ``XDG_CONFIG_DIRS`` is set and a multi path the response is also a multi path separated by
|
||||
the OS path separator), e.g. ``/etc/xdg/$appname/$version``
|
||||
"""
|
||||
# XDG default for $XDG_CONFIG_DIRS only first, if multipath is False
|
||||
dirs = self._site_config_dirs
|
||||
if not self.multipath:
|
||||
return dirs[0]
|
||||
return os.pathsep.join(dirs)
|
||||
"""Config directory tied to the user, or site equivalent when root with ``use_site_for_root``."""
|
||||
return self.site_config_dir if self._use_site else super().user_config_dir
|
||||
|
||||
@property
|
||||
def user_cache_dir(self) -> str:
|
||||
"""
|
||||
:return: cache directory tied to the user, e.g. ``~/.cache/$appname/$version`` or
|
||||
``~/$XDG_CACHE_HOME/$appname/$version``
|
||||
"""
|
||||
path = os.environ.get("XDG_CACHE_HOME", "")
|
||||
if not path.strip():
|
||||
path = os.path.expanduser("~/.cache") # noqa: PTH111
|
||||
return self._append_app_name_and_version(path)
|
||||
|
||||
@property
|
||||
def site_cache_dir(self) -> str:
|
||||
""":return: cache directory shared by users, e.g. ``/var/cache/$appname/$version``"""
|
||||
return self._append_app_name_and_version("/var/cache")
|
||||
"""Cache directory tied to the user, or site equivalent when root with ``use_site_for_root``."""
|
||||
return self.site_cache_dir if self._use_site else super().user_cache_dir
|
||||
|
||||
@property
|
||||
def user_state_dir(self) -> str:
|
||||
"""
|
||||
:return: state directory tied to the user, e.g. ``~/.local/state/$appname/$version`` or
|
||||
``$XDG_STATE_HOME/$appname/$version``
|
||||
"""
|
||||
path = os.environ.get("XDG_STATE_HOME", "")
|
||||
if not path.strip():
|
||||
path = os.path.expanduser("~/.local/state") # noqa: PTH111
|
||||
return self._append_app_name_and_version(path)
|
||||
"""State directory tied to the user, or site equivalent when root with ``use_site_for_root``."""
|
||||
return self.site_state_dir if self._use_site else super().user_state_dir
|
||||
|
||||
@property
|
||||
def user_log_dir(self) -> str:
|
||||
""":return: log directory tied to the user, same as `user_state_dir` if not opinionated else ``log`` in it"""
|
||||
path = self.user_state_dir
|
||||
if self.opinion:
|
||||
path = os.path.join(path, "log") # noqa: PTH118
|
||||
self._optionally_create_directory(path)
|
||||
return path
|
||||
"""Log directory tied to the user, or site equivalent when root with ``use_site_for_root``."""
|
||||
return self.site_log_dir if self._use_site else super().user_log_dir
|
||||
|
||||
@property
|
||||
def user_documents_dir(self) -> str:
|
||||
""":return: documents directory tied to the user, e.g. ``~/Documents``"""
|
||||
return _get_user_media_dir("XDG_DOCUMENTS_DIR", "~/Documents")
|
||||
|
||||
@property
|
||||
def user_downloads_dir(self) -> str:
|
||||
""":return: downloads directory tied to the user, e.g. ``~/Downloads``"""
|
||||
return _get_user_media_dir("XDG_DOWNLOAD_DIR", "~/Downloads")
|
||||
|
||||
@property
|
||||
def user_pictures_dir(self) -> str:
|
||||
""":return: pictures directory tied to the user, e.g. ``~/Pictures``"""
|
||||
return _get_user_media_dir("XDG_PICTURES_DIR", "~/Pictures")
|
||||
|
||||
@property
|
||||
def user_videos_dir(self) -> str:
|
||||
""":return: videos directory tied to the user, e.g. ``~/Videos``"""
|
||||
return _get_user_media_dir("XDG_VIDEOS_DIR", "~/Videos")
|
||||
|
||||
@property
|
||||
def user_music_dir(self) -> str:
|
||||
""":return: music directory tied to the user, e.g. ``~/Music``"""
|
||||
return _get_user_media_dir("XDG_MUSIC_DIR", "~/Music")
|
||||
|
||||
@property
|
||||
def user_desktop_dir(self) -> str:
|
||||
""":return: desktop directory tied to the user, e.g. ``~/Desktop``"""
|
||||
return _get_user_media_dir("XDG_DESKTOP_DIR", "~/Desktop")
|
||||
def user_applications_dir(self) -> str:
|
||||
"""Applications directory tied to the user, or site equivalent when root with ``use_site_for_root``."""
|
||||
return self.site_applications_dir if self._use_site else super().user_applications_dir
|
||||
|
||||
@property
|
||||
def user_runtime_dir(self) -> str:
|
||||
"""
|
||||
:return: runtime directory tied to the user, e.g. ``/run/user/$(id -u)/$appname/$version`` or
|
||||
``$XDG_RUNTIME_DIR/$appname/$version``.
|
||||
"""Runtime directory tied to the user, e.g. ``$XDG_RUNTIME_DIR/$appname/$version``.
|
||||
|
||||
Accepts ``$XDG_RUNTIME_DIR`` only as a directory, not a symlink, that the user owns with mode ``0700``, as the
|
||||
XDG spec requires, and creates a missing one that way under ``ensure_exists``. When the variable is unset or
|
||||
fails that check, emits one :class:`~platformdirs.RuntimeDirWarning` per cause and falls back to the platform
|
||||
default (``/tmp/run/user/<uid>`` on OpenBSD, ``/var/run/user/<uid>`` on FreeBSD/NetBSD, ``/run/user/<uid>``
|
||||
elsewhere) if it passes the same check, else to ``runtime-<uid>`` in the temporary directory. Root with
|
||||
``use_site_for_root`` gets the site equivalent.
|
||||
|
||||
:raises PermissionError: if the temporary fallback is a symlink, not a directory, or owned by another user.
|
||||
|
||||
For FreeBSD/OpenBSD/NetBSD, it would return ``/var/run/user/$(id -u)/$appname/$version`` if
|
||||
exists, otherwise ``/tmp/runtime-$(id -u)/$appname/$version``, if``$XDG_RUNTIME_DIR``
|
||||
is not set.
|
||||
"""
|
||||
path = os.environ.get("XDG_RUNTIME_DIR", "")
|
||||
if not path.strip():
|
||||
if sys.platform.startswith(("freebsd", "openbsd", "netbsd")):
|
||||
path = f"/var/run/user/{getuid()}"
|
||||
if not Path(path).exists():
|
||||
path = f"/tmp/runtime-{getuid()}" # noqa: S108
|
||||
else:
|
||||
path = f"/run/user/{getuid()}"
|
||||
return self._append_app_name_and_version(path)
|
||||
if self._use_site:
|
||||
# XDGMixin.site_runtime_dir reads $XDG_RUNTIME_DIR, which belongs to the user who started the root process.
|
||||
return super(XDGMixin, self).site_runtime_dir
|
||||
if not (path := _xdg_dir("XDG_RUNTIME_DIR")):
|
||||
reason = "XDG_RUNTIME_DIR is not set"
|
||||
else:
|
||||
with suppress(OSError):
|
||||
self._optionally_create_directory(path, private=True)
|
||||
if not (problem := _runtime_dir_problem(path)):
|
||||
return self._append_app_name_and_version(path, private=True)
|
||||
reason = f"XDG_RUNTIME_DIR {problem}"
|
||||
_warn_once(f"{reason}, falling back to {(fallback := self._default_runtime_dir())}")
|
||||
return self._append_app_name_and_version(fallback, private=True)
|
||||
|
||||
@property
|
||||
def site_runtime_dir(self) -> str:
|
||||
"""
|
||||
:return: runtime directory shared by users, e.g. ``/run/$appname/$version`` or \
|
||||
``$XDG_RUNTIME_DIR/$appname/$version``.
|
||||
|
||||
Note that this behaves almost exactly like `user_runtime_dir` if ``$XDG_RUNTIME_DIR`` is set, but will
|
||||
fall back to paths associated to the root user instead of a regular logged-in user if it's not set.
|
||||
|
||||
If you wish to ensure that a logged-in root user path is returned e.g. ``/run/user/0``, use `user_runtime_dir`
|
||||
instead.
|
||||
|
||||
For FreeBSD/OpenBSD/NetBSD, it would return ``/var/run/$appname/$version`` if ``$XDG_RUNTIME_DIR`` is not set.
|
||||
"""
|
||||
path = os.environ.get("XDG_RUNTIME_DIR", "")
|
||||
if not path.strip():
|
||||
if sys.platform.startswith(("freebsd", "openbsd", "netbsd")):
|
||||
path = "/var/run"
|
||||
else:
|
||||
path = "/run"
|
||||
return self._append_app_name_and_version(path)
|
||||
def user_bin_dir(self) -> str:
|
||||
"""Bin directory tied to the user, or site equivalent when root with ``use_site_for_root``."""
|
||||
return self.site_bin_dir if self._use_site else super().user_bin_dir
|
||||
|
||||
@property
|
||||
def site_data_path(self) -> Path:
|
||||
""":return: data path shared by users. Only return the first item, even if ``multipath`` is set to ``True``"""
|
||||
return self._first_item_as_path_if_multipath(self.site_data_dir)
|
||||
def user_data_path(self) -> Path:
|
||||
"""Data path tied to the user, or the first site entry when root with ``use_site_for_root``."""
|
||||
return self.site_data_path if self._use_site else super().user_data_path
|
||||
|
||||
@property
|
||||
def site_config_path(self) -> Path:
|
||||
""":return: config path shared by the users, returns the first item, even if ``multipath`` is set to ``True``"""
|
||||
return self._first_item_as_path_if_multipath(self.site_config_dir)
|
||||
def user_config_path(self) -> Path:
|
||||
"""Config path tied to the user, or the first site entry when root with ``use_site_for_root``."""
|
||||
return self.site_config_path if self._use_site else super().user_config_path
|
||||
|
||||
@property
|
||||
def site_cache_path(self) -> Path:
|
||||
""":return: cache path shared by users. Only return the first item, even if ``multipath`` is set to ``True``"""
|
||||
return self._first_item_as_path_if_multipath(self.site_cache_dir)
|
||||
def user_preference_path(self) -> Path:
|
||||
"""Preference path tied to the user, or the first site config entry when root with ``use_site_for_root``."""
|
||||
return self.site_config_path if self._use_site else super().user_preference_path
|
||||
|
||||
def iter_config_dirs(self) -> Iterator[str]:
|
||||
""":yield: all user and site configuration directories."""
|
||||
yield self.user_config_dir
|
||||
yield from self._site_config_dirs
|
||||
|
||||
def iter_data_dirs(self) -> Iterator[str]:
|
||||
""":yield: all user and site data directories."""
|
||||
yield self.user_data_dir
|
||||
yield from self._site_data_dirs
|
||||
@property
|
||||
def user_applications_path(self) -> Path:
|
||||
"""Applications path tied to the user, or the first site entry when root with ``use_site_for_root``."""
|
||||
return self.site_applications_path if self._use_site else super().user_applications_path
|
||||
|
||||
|
||||
def _get_user_media_dir(env_var: str, fallback_tilde_path: str) -> str:
|
||||
media_dir = _get_user_dirs_folder(env_var)
|
||||
if media_dir is None:
|
||||
media_dir = os.environ.get(env_var, "").strip()
|
||||
if not media_dir:
|
||||
media_dir = os.path.expanduser(fallback_tilde_path) # noqa: PTH111
|
||||
|
||||
return media_dir
|
||||
_USER_DIRS_LINE: Final = re.compile(
|
||||
r"""
|
||||
[ \t]*(?P<key>\w+)[ \t]*=[ \t]* # KEY=, blanks allowed around the key and after the =
|
||||
(?:
|
||||
"(?P<quoted>(?:[^"\\]|\\.)*)" # a double-quoted value with backslash escapes, text after it ignored
|
||||
|(?P<bare>[^"\s].*?) # or an unquoted value, up to
|
||||
(?:[ \t]+\#.*|[ \t]*)$ # a comment, which sh starts at a word-initial #, or the line end
|
||||
)
|
||||
""",
|
||||
re.VERBOSE,
|
||||
)
|
||||
|
||||
|
||||
def _get_user_dirs_folder(key: str) -> str | None:
|
||||
"""
|
||||
Return directory from user-dirs.dirs config file.
|
||||
"""Return directory from user-dirs.dirs config file.
|
||||
|
||||
``xdg-user-dirs-update`` writes shell assignments, so match each line like ``xdg-user-dir`` does and keep the last
|
||||
valid assignment to ``key``.
|
||||
|
||||
See https://freedesktop.org/wiki/Software/xdg-user-dirs/.
|
||||
|
||||
"""
|
||||
user_dirs_config_path = Path(Unix().user_config_dir) / "user-dirs.dirs"
|
||||
if user_dirs_config_path.exists():
|
||||
parser = ConfigParser()
|
||||
config_home = _xdg_dir("XDG_CONFIG_HOME") or _expand_user("~/.config")
|
||||
user_dirs_config_path = Path(config_home) / "user-dirs.dirs"
|
||||
if not user_dirs_config_path.exists():
|
||||
return None
|
||||
folder = None
|
||||
# the file holds raw path bytes, and surrogateescape round-trips undecodable ones like os.fsdecode
|
||||
with user_dirs_config_path.open(encoding=sys.getfilesystemencoding(), errors="surrogateescape") as stream:
|
||||
for line in stream:
|
||||
if (entry := _USER_DIRS_LINE.match(line)) and entry["key"] == key:
|
||||
folder = _resolve_user_dirs_value(entry) or folder
|
||||
return folder
|
||||
|
||||
with user_dirs_config_path.open() as stream:
|
||||
# Add fake section header, so ConfigParser doesn't complain
|
||||
parser.read_string(f"[top]\n{stream.read()}")
|
||||
|
||||
if key not in parser["top"]:
|
||||
return None
|
||||
def _resolve_user_dirs_value(entry: re.Match[str]) -> str | None:
|
||||
value = entry["bare"] if entry["quoted"] is None else entry["quoted"]
|
||||
if value == "$HOME" or value.startswith("$HOME/"):
|
||||
prefix, value = _expand_user("~"), value.removeprefix("$HOME")
|
||||
elif value.startswith("/"):
|
||||
prefix = ""
|
||||
else:
|
||||
return None
|
||||
if entry["quoted"] is not None:
|
||||
# xdg-user-dirs-update backslash-escapes $, `, " and \ inside the quotes.
|
||||
value = re.sub(r"\\(.)", r"\1", value)
|
||||
return prefix + value
|
||||
|
||||
path = parser["top"][key].strip('"')
|
||||
# Handle relative home paths
|
||||
return path.replace("$HOME", os.path.expanduser("~")) # noqa: PTH111
|
||||
|
||||
return None
|
||||
def _runtime_dir_problem(path: str, *, check_mode: bool = True) -> str | None:
|
||||
"""Return why ``path`` fails the checks of Qt's ``checkXdgRuntimeDir``, or ``None`` if it passes or is missing."""
|
||||
try:
|
||||
info = os.lstat(path)
|
||||
except FileNotFoundError:
|
||||
return None
|
||||
except OSError as error:
|
||||
return f"{path} cannot be checked: {error.strerror}"
|
||||
mode = info.st_mode & 0o777
|
||||
checks = (
|
||||
(stat.S_ISLNK(info.st_mode), "is a symlink"),
|
||||
(not stat.S_ISDIR(info.st_mode), "is not a directory"),
|
||||
(info.st_uid != (uid := getuid()), f"is owned by uid {info.st_uid}, not {uid}"),
|
||||
(check_mode and mode != _RUNTIME_DIR_MODE, f"has mode {mode:04o}, not {_RUNTIME_DIR_MODE:04o}"),
|
||||
)
|
||||
return next((f"{path} {problem}" for failed, problem in checks if failed), None)
|
||||
|
||||
|
||||
def _warn_once(message: str) -> None:
|
||||
# Each read of user_runtime_dir repeats the check, so a warning per read would flood long-running programs.
|
||||
if message not in _WARNED:
|
||||
_WARNED.add(message)
|
||||
warnings.warn(message, RuntimeDirWarning, stacklevel=3)
|
||||
|
||||
|
||||
_WARNED: Final[set[str]] = set()
|
||||
_RUNTIME_DIR_MODE: Final = 0o700
|
||||
|
||||
|
||||
__all__ = [
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# file generated by setuptools-scm
|
||||
# file generated by vcs-versioning
|
||||
# don't change, don't track in version control
|
||||
from __future__ import annotations
|
||||
|
||||
__all__ = [
|
||||
"__version__",
|
||||
@@ -10,25 +11,14 @@ __all__ = [
|
||||
"commit_id",
|
||||
]
|
||||
|
||||
TYPE_CHECKING = False
|
||||
if TYPE_CHECKING:
|
||||
from typing import Tuple
|
||||
from typing import Union
|
||||
|
||||
VERSION_TUPLE = Tuple[Union[int, str], ...]
|
||||
COMMIT_ID = Union[str, None]
|
||||
else:
|
||||
VERSION_TUPLE = object
|
||||
COMMIT_ID = object
|
||||
|
||||
version: str
|
||||
__version__: str
|
||||
__version_tuple__: VERSION_TUPLE
|
||||
version_tuple: VERSION_TUPLE
|
||||
commit_id: COMMIT_ID
|
||||
__commit_id__: COMMIT_ID
|
||||
__version_tuple__: tuple[int | str, ...]
|
||||
version_tuple: tuple[int | str, ...]
|
||||
commit_id: str | None
|
||||
__commit_id__: str | None
|
||||
|
||||
__version__ = version = '4.5.1'
|
||||
__version_tuple__ = version_tuple = (4, 5, 1)
|
||||
__version__ = version = '4.12.4'
|
||||
__version_tuple__ = version_tuple = (4, 12, 4)
|
||||
|
||||
__commit_id__ = commit_id = None
|
||||
@@ -2,20 +2,24 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import ntpath
|
||||
import os
|
||||
import sys
|
||||
from functools import lru_cache
|
||||
from typing import TYPE_CHECKING
|
||||
from functools import cache
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Final
|
||||
|
||||
from .api import PlatformDirsABC
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import Callable
|
||||
|
||||
# Not exposed by CPython; defined in the Windows SDK (shlobj_core.h)
|
||||
_KF_FLAG_DONT_VERIFY: Final[int] = 0x00004000
|
||||
|
||||
class Windows(PlatformDirsABC):
|
||||
"""
|
||||
`MSDN on where to store app data files <https://learn.microsoft.com/en-us/windows/win32/shell/knownfolderid>`_.
|
||||
|
||||
class Windows(PlatformDirsABC): # ruff:ignore[too-many-public-methods]
|
||||
"""`MSDN on where to store app data files <https://learn.microsoft.com/en-us/windows/win32/shell/knownfolderid>`_.
|
||||
|
||||
Makes use of the `appname <platformdirs.api.PlatformDirsABC.appname>`, `appauthor
|
||||
<platformdirs.api.PlatformDirsABC.appauthor>`, `version <platformdirs.api.PlatformDirsABC.version>`, `roaming
|
||||
@@ -26,11 +30,7 @@ class Windows(PlatformDirsABC):
|
||||
|
||||
@property
|
||||
def user_data_dir(self) -> str:
|
||||
"""
|
||||
:return: data directory tied to the user, e.g.
|
||||
``%USERPROFILE%\\AppData\\Local\\$appauthor\\$appname`` (not roaming) or
|
||||
``%USERPROFILE%\\AppData\\Roaming\\$appauthor\\$appname`` (roaming)
|
||||
"""
|
||||
r"""Data directory tied to the user, e.g. ``%USERPROFILE%\AppData\Local\$appauthor\$appname`` (not roaming) or ``%USERPROFILE%\AppData\Roaming\$appauthor\$appname`` (roaming)."""
|
||||
const = "CSIDL_APPDATA" if self.roaming else "CSIDL_LOCAL_APPDATA"
|
||||
path = os.path.normpath(get_win_folder(const))
|
||||
return self._append_parts(path)
|
||||
@@ -46,97 +46,150 @@ class Windows(PlatformDirsABC):
|
||||
params.append(opinion_value)
|
||||
if self.version:
|
||||
params.append(self.version)
|
||||
path = os.path.join(path, *params) # noqa: PTH118
|
||||
self._optionally_create_directory(path)
|
||||
path = os.path.join(path, *params) # ruff:ignore[os-path-join]
|
||||
self._optionally_create_directory(path, private=False)
|
||||
return path
|
||||
|
||||
@property
|
||||
def site_data_dir(self) -> str:
|
||||
""":return: data directory shared by users, e.g. ``C:\\ProgramData\\$appauthor\\$appname``"""
|
||||
r"""Data directory shared by users, e.g. ``C:\ProgramData\$appauthor\$appname``."""
|
||||
path = os.path.normpath(get_win_folder("CSIDL_COMMON_APPDATA"))
|
||||
return self._append_parts(path)
|
||||
|
||||
@property
|
||||
def user_config_dir(self) -> str:
|
||||
""":return: config directory tied to the user, same as `user_data_dir`"""
|
||||
"""Config directory tied to the user, same as `user_data_dir`."""
|
||||
return self.user_data_dir
|
||||
|
||||
@property
|
||||
def site_config_dir(self) -> str:
|
||||
""":return: config directory shared by the users, same as `site_data_dir`"""
|
||||
"""Config directory shared by users, same as `site_data_dir`."""
|
||||
return self.site_data_dir
|
||||
|
||||
@property
|
||||
def user_cache_dir(self) -> str:
|
||||
"""
|
||||
:return: cache directory tied to the user (if opinionated with ``Cache`` folder within ``$appname``) e.g.
|
||||
``%USERPROFILE%\\AppData\\Local\\$appauthor\\$appname\\Cache\\$version``
|
||||
"""
|
||||
r"""Cache directory tied to the user (if opinionated with ``Cache`` folder within ``$appname``) e.g. ``%USERPROFILE%\AppData\Local\$appauthor\$appname\Cache\$version``."""
|
||||
path = os.path.normpath(get_win_folder("CSIDL_LOCAL_APPDATA"))
|
||||
return self._append_parts(path, opinion_value="Cache")
|
||||
|
||||
@property
|
||||
def site_cache_dir(self) -> str:
|
||||
""":return: cache directory shared by users, e.g. ``C:\\ProgramData\\$appauthor\\$appname\\Cache\\$version``"""
|
||||
r"""Cache directory shared by users, e.g. ``C:\ProgramData\$appauthor\$appname\Cache\$version``."""
|
||||
path = os.path.normpath(get_win_folder("CSIDL_COMMON_APPDATA"))
|
||||
return self._append_parts(path, opinion_value="Cache")
|
||||
|
||||
@property
|
||||
def user_state_dir(self) -> str:
|
||||
""":return: state directory tied to the user, same as `user_data_dir`"""
|
||||
"""State directory tied to the user, same as `user_data_dir`."""
|
||||
return self.user_data_dir
|
||||
|
||||
@property
|
||||
def site_state_dir(self) -> str:
|
||||
"""State directory shared by users, same as `site_data_dir`."""
|
||||
return self.site_data_dir
|
||||
|
||||
@property
|
||||
def user_log_dir(self) -> str:
|
||||
""":return: log directory tied to the user, same as `user_data_dir` if not opinionated else ``Logs`` in it"""
|
||||
"""Log directory tied to the user, same as `user_data_dir` if not opinionated else ``Logs`` in it."""
|
||||
path = self.user_data_dir
|
||||
if self.opinion:
|
||||
path = os.path.join(path, "Logs") # noqa: PTH118
|
||||
self._optionally_create_directory(path)
|
||||
path = os.path.join(path, "Logs") # ruff:ignore[os-path-join]
|
||||
self._optionally_create_directory(path, private=False)
|
||||
return path
|
||||
|
||||
@property
|
||||
def site_log_dir(self) -> str:
|
||||
"""Log directory shared by users, same as `site_data_dir` if not opinionated else ``Logs`` in it."""
|
||||
path = self.site_data_dir
|
||||
if self.opinion:
|
||||
path = os.path.join(path, "Logs") # ruff:ignore[os-path-join]
|
||||
self._optionally_create_directory(path, private=False)
|
||||
return path
|
||||
|
||||
@property
|
||||
def user_documents_dir(self) -> str:
|
||||
""":return: documents directory tied to the user e.g. ``%USERPROFILE%\\Documents``"""
|
||||
r"""Documents directory tied to the user e.g. ``%USERPROFILE%\Documents``."""
|
||||
return os.path.normpath(get_win_folder("CSIDL_PERSONAL"))
|
||||
|
||||
@property
|
||||
def user_downloads_dir(self) -> str:
|
||||
""":return: downloads directory tied to the user e.g. ``%USERPROFILE%\\Downloads``"""
|
||||
r"""Downloads directory tied to the user e.g. ``%USERPROFILE%\Downloads``."""
|
||||
return os.path.normpath(get_win_folder("CSIDL_DOWNLOADS"))
|
||||
|
||||
@property
|
||||
def user_pictures_dir(self) -> str:
|
||||
""":return: pictures directory tied to the user e.g. ``%USERPROFILE%\\Pictures``"""
|
||||
r"""Pictures directory tied to the user e.g. ``%USERPROFILE%\Pictures``."""
|
||||
return os.path.normpath(get_win_folder("CSIDL_MYPICTURES"))
|
||||
|
||||
@property
|
||||
def user_videos_dir(self) -> str:
|
||||
""":return: videos directory tied to the user e.g. ``%USERPROFILE%\\Videos``"""
|
||||
r"""Videos directory tied to the user e.g. ``%USERPROFILE%\Videos``."""
|
||||
return os.path.normpath(get_win_folder("CSIDL_MYVIDEO"))
|
||||
|
||||
@property
|
||||
def user_music_dir(self) -> str:
|
||||
""":return: music directory tied to the user e.g. ``%USERPROFILE%\\Music``"""
|
||||
r"""Music directory tied to the user e.g. ``%USERPROFILE%\Music``."""
|
||||
return os.path.normpath(get_win_folder("CSIDL_MYMUSIC"))
|
||||
|
||||
@property
|
||||
def user_desktop_dir(self) -> str:
|
||||
""":return: desktop directory tied to the user, e.g. ``%USERPROFILE%\\Desktop``"""
|
||||
r"""Desktop directory tied to the user, e.g. ``%USERPROFILE%\Desktop``."""
|
||||
return os.path.normpath(get_win_folder("CSIDL_DESKTOPDIRECTORY"))
|
||||
|
||||
@property
|
||||
def user_projects_dir(self) -> str:
|
||||
r"""Projects directory tied to the user, e.g. ``%USERPROFILE%\Projects``."""
|
||||
return os.path.normpath(os.path.expanduser("~/Projects")) # ruff:ignore[os-path-expanduser]
|
||||
|
||||
@property
|
||||
def user_publicshare_dir(self) -> str:
|
||||
r"""Public share directory e.g. ``C:\Users\Public``."""
|
||||
return os.path.normpath(get_win_folder("CSIDL_PUBLIC"))
|
||||
|
||||
@property
|
||||
def user_templates_dir(self) -> str:
|
||||
r"""Templates directory tied to the user e.g. ``%APPDATA%\Microsoft\Windows\Templates``."""
|
||||
return os.path.normpath(get_win_folder("CSIDL_TEMPLATES"))
|
||||
|
||||
@property
|
||||
def user_fonts_dir(self) -> str:
|
||||
r"""Fonts directory tied to the user e.g. ``%LOCALAPPDATA%\Microsoft\Windows\Fonts``."""
|
||||
return os.path.normpath(str(Path(get_win_folder("CSIDL_LOCAL_APPDATA")) / "Microsoft" / "Windows" / "Fonts"))
|
||||
|
||||
@property
|
||||
def user_preference_dir(self) -> str:
|
||||
r"""Preference directory tied to the user, same as ``user_config_dir``."""
|
||||
return self.user_config_dir
|
||||
|
||||
@property
|
||||
def user_bin_dir(self) -> str:
|
||||
r"""Bin directory tied to the user, e.g. ``%LOCALAPPDATA%\Programs``."""
|
||||
return os.path.normpath(get_win_folder("CSIDL_USER_PROGRAM_FILES"))
|
||||
|
||||
@property
|
||||
def site_bin_dir(self) -> str:
|
||||
r"""Bin directory shared by users, e.g. ``C:\ProgramData\bin``."""
|
||||
return os.path.normpath(os.path.join(get_win_folder("CSIDL_COMMON_APPDATA"), "bin")) # ruff:ignore[os-path-join]
|
||||
|
||||
@property
|
||||
def user_applications_dir(self) -> str:
|
||||
r"""Applications directory tied to the user, e.g. ``Start Menu\Programs``."""
|
||||
return os.path.normpath(get_win_folder("CSIDL_PROGRAMS"))
|
||||
|
||||
@property
|
||||
def site_applications_dir(self) -> str:
|
||||
r"""Applications directory shared by users, e.g. ``C:\ProgramData\Microsoft\Windows\Start Menu\Programs``."""
|
||||
return os.path.normpath(get_win_folder("CSIDL_COMMON_PROGRAMS"))
|
||||
|
||||
@property
|
||||
def user_runtime_dir(self) -> str:
|
||||
"""
|
||||
:return: runtime directory tied to the user, e.g.
|
||||
``%USERPROFILE%\\AppData\\Local\\Temp\\$appauthor\\$appname``
|
||||
"""
|
||||
path = os.path.normpath(os.path.join(get_win_folder("CSIDL_LOCAL_APPDATA"), "Temp")) # noqa: PTH118
|
||||
r"""Runtime directory tied to the user, e.g. ``%USERPROFILE%\AppData\Local\Temp\$appauthor\$appname``."""
|
||||
path = os.path.normpath(os.path.join(get_win_folder("CSIDL_LOCAL_APPDATA"), "Temp")) # ruff:ignore[os-path-join]
|
||||
return self._append_parts(path)
|
||||
|
||||
@property
|
||||
def site_runtime_dir(self) -> str:
|
||||
""":return: runtime directory shared by users, same as `user_runtime_dir`"""
|
||||
"""Runtime directory shared by users, same as `user_runtime_dir`."""
|
||||
return self.user_runtime_dir
|
||||
|
||||
|
||||
@@ -154,8 +207,7 @@ def get_win_folder_from_env_vars(csidl_name: str) -> str:
|
||||
if env_var_name is None:
|
||||
msg = f"Unknown CSIDL name: {csidl_name}"
|
||||
raise ValueError(msg)
|
||||
result = os.environ.get(env_var_name)
|
||||
if result is None:
|
||||
if not (result := os.environ.get(env_var_name)):
|
||||
msg = f"Unset environment variable: {env_var_name}"
|
||||
raise ValueError(msg)
|
||||
return result
|
||||
@@ -163,26 +215,45 @@ def get_win_folder_from_env_vars(csidl_name: str) -> str:
|
||||
|
||||
def get_win_folder_if_csidl_name_not_env_var(csidl_name: str) -> str | None:
|
||||
"""Get a folder for a CSIDL name that does not exist as an environment variable."""
|
||||
if csidl_name == "CSIDL_PERSONAL":
|
||||
return os.path.join(os.path.normpath(os.environ["USERPROFILE"]), "Documents") # noqa: PTH118
|
||||
if (env_var_and_parts := _ENV_VAR_SUBFOLDERS.get(csidl_name)) is not None:
|
||||
env_var, *parts = env_var_and_parts
|
||||
return os.path.join(os.path.normpath(_non_empty_env(env_var)), *parts) # ruff:ignore[os-path-join]
|
||||
|
||||
if csidl_name == "CSIDL_DOWNLOADS":
|
||||
return os.path.join(os.path.normpath(os.environ["USERPROFILE"]), "Downloads") # noqa: PTH118
|
||||
if csidl_name == "CSIDL_PUBLIC":
|
||||
return os.environ.get("PUBLIC") or str(Path("~").expanduser().parent / "Public")
|
||||
|
||||
if csidl_name == "CSIDL_MYPICTURES":
|
||||
return os.path.join(os.path.normpath(os.environ["USERPROFILE"]), "Pictures") # noqa: PTH118
|
||||
|
||||
if csidl_name == "CSIDL_MYVIDEO":
|
||||
return os.path.join(os.path.normpath(os.environ["USERPROFILE"]), "Videos") # noqa: PTH118
|
||||
|
||||
if csidl_name == "CSIDL_MYMUSIC":
|
||||
return os.path.join(os.path.normpath(os.environ["USERPROFILE"]), "Music") # noqa: PTH118
|
||||
if csidl_name == "CSIDL_COMMON_PROGRAMS":
|
||||
return os.path.join( # ruff:ignore[os-path-join]
|
||||
os.path.normpath(os.environ.get("PROGRAMDATA") or os.environ.get("ALLUSERSPROFILE") or "C:\\ProgramData"),
|
||||
"Microsoft",
|
||||
"Windows",
|
||||
"Start Menu",
|
||||
"Programs",
|
||||
)
|
||||
return None
|
||||
|
||||
|
||||
_ENV_VAR_SUBFOLDERS: Final[dict[str, tuple[str, ...]]] = {
|
||||
"CSIDL_PERSONAL": ("USERPROFILE", "Documents"),
|
||||
"CSIDL_DOWNLOADS": ("USERPROFILE", "Downloads"),
|
||||
"CSIDL_MYPICTURES": ("USERPROFILE", "Pictures"),
|
||||
"CSIDL_MYVIDEO": ("USERPROFILE", "Videos"),
|
||||
"CSIDL_MYMUSIC": ("USERPROFILE", "Music"),
|
||||
"CSIDL_DESKTOPDIRECTORY": ("USERPROFILE", "Desktop"),
|
||||
"CSIDL_PROGRAMS": ("APPDATA", "Microsoft", "Windows", "Start Menu", "Programs"),
|
||||
"CSIDL_TEMPLATES": ("APPDATA", "Microsoft", "Windows", "Templates"),
|
||||
"CSIDL_USER_PROGRAM_FILES": ("LOCALAPPDATA", "Programs"),
|
||||
}
|
||||
|
||||
|
||||
def _non_empty_env(name: str) -> str:
|
||||
if value := os.environ.get(name):
|
||||
return value
|
||||
raise KeyError(name) # same error os.environ[name] gives for an unset variable
|
||||
|
||||
|
||||
def get_win_folder_from_registry(csidl_name: str) -> str:
|
||||
"""
|
||||
Get folder from the registry.
|
||||
"""Get folder from the registry.
|
||||
|
||||
This is a fallback technique at best. I'm not sure if using the registry for these guarantees us the correct answer
|
||||
for all CSIDL_* names.
|
||||
@@ -190,6 +261,7 @@ def get_win_folder_from_registry(csidl_name: str) -> str:
|
||||
"""
|
||||
machine_names = {
|
||||
"CSIDL_COMMON_APPDATA",
|
||||
"CSIDL_COMMON_PROGRAMS",
|
||||
}
|
||||
shell_folder_name = {
|
||||
"CSIDL_APPDATA": "AppData",
|
||||
@@ -200,78 +272,147 @@ def get_win_folder_from_registry(csidl_name: str) -> str:
|
||||
"CSIDL_MYPICTURES": "My Pictures",
|
||||
"CSIDL_MYVIDEO": "My Video",
|
||||
"CSIDL_MYMUSIC": "My Music",
|
||||
"CSIDL_DESKTOPDIRECTORY": "Desktop",
|
||||
"CSIDL_PROGRAMS": "Programs",
|
||||
"CSIDL_COMMON_PROGRAMS": "Common Programs",
|
||||
"CSIDL_TEMPLATES": "Templates",
|
||||
}.get(csidl_name)
|
||||
if shell_folder_name is None:
|
||||
msg = f"Unknown CSIDL name: {csidl_name}"
|
||||
raise ValueError(msg)
|
||||
return get_win_folder_from_env_vars(csidl_name)
|
||||
if sys.platform != "win32": # only needed for mypy type checker to know that this code runs only on Windows
|
||||
raise NotImplementedError
|
||||
import winreg # noqa: PLC0415
|
||||
import winreg # ruff:ignore[import-outside-top-level]
|
||||
|
||||
# Use HKEY_LOCAL_MACHINE for system-wide folders, HKEY_CURRENT_USER for user-specific folders
|
||||
hkey = winreg.HKEY_LOCAL_MACHINE if csidl_name in machine_names else winreg.HKEY_CURRENT_USER
|
||||
|
||||
key = winreg.OpenKey(hkey, r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders")
|
||||
directory, _ = winreg.QueryValueEx(key, shell_folder_name)
|
||||
with winreg.OpenKey(hkey, r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders") as key:
|
||||
directory, _ = winreg.QueryValueEx(key, shell_folder_name)
|
||||
return str(directory)
|
||||
|
||||
|
||||
_KNOWN_FOLDER_GUIDS: dict[str, str] = {
|
||||
"CSIDL_APPDATA": "{3EB685DB-65F9-4CF6-A03A-E3EF65729F3D}",
|
||||
"CSIDL_COMMON_APPDATA": "{62AB5D82-FDC1-4DC3-A9DD-070D1D495D97}",
|
||||
"CSIDL_LOCAL_APPDATA": "{F1B32785-6FBA-4FCF-9D55-7B8E7F157091}",
|
||||
"CSIDL_PERSONAL": "{FDD39AD0-238F-46AF-ADB4-6C85480369C7}",
|
||||
"CSIDL_MYPICTURES": "{33E28130-4E1E-4676-835A-98395C3BC3BB}",
|
||||
"CSIDL_MYVIDEO": "{18989B1D-99B5-455B-841C-AB7C74E4DDFC}",
|
||||
"CSIDL_MYMUSIC": "{4BD8D571-6D19-48D3-BE97-422220080E43}",
|
||||
"CSIDL_DOWNLOADS": "{374DE290-123F-4565-9164-39C4925E467B}",
|
||||
"CSIDL_DESKTOPDIRECTORY": "{B4BFCC3A-DB2C-424C-B029-7FE99A87C641}",
|
||||
"CSIDL_PROGRAMS": "{A77F5D77-2E2B-44C3-A6A2-ABA601054A51}",
|
||||
"CSIDL_COMMON_PROGRAMS": "{0139D44E-6AFE-49F2-8690-3DAFCAE6FFB8}",
|
||||
"CSIDL_TEMPLATES": "{A63293E8-664E-48DB-A079-DF759E0509F7}",
|
||||
"CSIDL_PUBLIC": "{DFDF76A2-C82A-4D63-906A-5644AC457385}",
|
||||
"CSIDL_USER_PROGRAM_FILES": "{5CD7AEE2-2219-4A67-B85D-6C9CE15660CB}",
|
||||
}
|
||||
|
||||
|
||||
@cache
|
||||
def _build_get_win_folder_via_ctypes() -> Callable[[str], str]:
|
||||
"""Build the resolver once; a fresh ``_GUID`` per call leaks ctypes pointer types.
|
||||
|
||||
See https://github.com/tox-dev/platformdirs/issues/501.
|
||||
|
||||
"""
|
||||
if sys.platform != "win32": # only needed for type checker to know that this code runs only on Windows
|
||||
raise NotImplementedError
|
||||
from ctypes import ( # ruff:ignore[import-outside-top-level]
|
||||
HRESULT,
|
||||
POINTER,
|
||||
Structure,
|
||||
WinDLL,
|
||||
byref,
|
||||
wintypes,
|
||||
)
|
||||
|
||||
class _GUID(Structure):
|
||||
_fields_ = [
|
||||
("Data1", wintypes.DWORD),
|
||||
("Data2", wintypes.WORD),
|
||||
("Data3", wintypes.WORD),
|
||||
("Data4", wintypes.BYTE * 8),
|
||||
]
|
||||
|
||||
ole32 = WinDLL("ole32")
|
||||
ole32.CLSIDFromString.restype = HRESULT
|
||||
ole32.CLSIDFromString.argtypes = [wintypes.LPCOLESTR, POINTER(_GUID)]
|
||||
ole32.CoTaskMemFree.restype = None
|
||||
ole32.CoTaskMemFree.argtypes = [wintypes.LPVOID]
|
||||
|
||||
shell32 = WinDLL("shell32")
|
||||
shell32.SHGetKnownFolderPath.restype = HRESULT
|
||||
shell32.SHGetKnownFolderPath.argtypes = [POINTER(_GUID), wintypes.DWORD, wintypes.HANDLE, POINTER(wintypes.LPWSTR)]
|
||||
|
||||
def resolve(csidl_name: str) -> str:
|
||||
folder_guid = _KNOWN_FOLDER_GUIDS.get(csidl_name)
|
||||
if folder_guid is None:
|
||||
msg = f"Unknown CSIDL name: {csidl_name}"
|
||||
raise ValueError(msg)
|
||||
|
||||
guid = _GUID()
|
||||
ole32.CLSIDFromString(folder_guid, byref(guid))
|
||||
|
||||
path_ptr = wintypes.LPWSTR()
|
||||
shell32.SHGetKnownFolderPath(byref(guid), _KF_FLAG_DONT_VERIFY, None, byref(path_ptr))
|
||||
result = path_ptr.value
|
||||
ole32.CoTaskMemFree(path_ptr)
|
||||
|
||||
if result is None:
|
||||
msg = f"SHGetKnownFolderPath returned NULL for {csidl_name}"
|
||||
raise ValueError(msg)
|
||||
|
||||
return result
|
||||
|
||||
return resolve
|
||||
|
||||
|
||||
def get_win_folder_via_ctypes(csidl_name: str) -> str:
|
||||
"""Get folder with ctypes."""
|
||||
# There is no 'CSIDL_DOWNLOADS'.
|
||||
# Use 'CSIDL_PROFILE' (40) and append the default folder 'Downloads' instead.
|
||||
# https://learn.microsoft.com/en-us/windows/win32/shell/knownfolderid
|
||||
"""Get folder via :func:`SHGetKnownFolderPath`.
|
||||
|
||||
import ctypes # noqa: PLC0415
|
||||
See https://learn.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shgetknownfolderpath.
|
||||
|
||||
csidl_const = {
|
||||
"CSIDL_APPDATA": 26,
|
||||
"CSIDL_COMMON_APPDATA": 35,
|
||||
"CSIDL_LOCAL_APPDATA": 28,
|
||||
"CSIDL_PERSONAL": 5,
|
||||
"CSIDL_MYPICTURES": 39,
|
||||
"CSIDL_MYVIDEO": 14,
|
||||
"CSIDL_MYMUSIC": 13,
|
||||
"CSIDL_DOWNLOADS": 40,
|
||||
"CSIDL_DESKTOPDIRECTORY": 16,
|
||||
}.get(csidl_name)
|
||||
if csidl_const is None:
|
||||
msg = f"Unknown CSIDL name: {csidl_name}"
|
||||
raise ValueError(msg)
|
||||
|
||||
buf = ctypes.create_unicode_buffer(1024)
|
||||
windll = getattr(ctypes, "windll") # noqa: B009 # using getattr to avoid false positive with mypy type checker
|
||||
windll.shell32.SHGetFolderPathW(None, csidl_const, None, 0, buf)
|
||||
|
||||
# Downgrade to short path name if it has high-bit chars.
|
||||
if any(ord(c) > 255 for c in buf): # noqa: PLR2004
|
||||
buf2 = ctypes.create_unicode_buffer(1024)
|
||||
if windll.kernel32.GetShortPathNameW(buf.value, buf2, 1024):
|
||||
buf = buf2
|
||||
|
||||
if csidl_name == "CSIDL_DOWNLOADS":
|
||||
return os.path.join(buf.value, "Downloads") # noqa: PTH118
|
||||
|
||||
return buf.value
|
||||
"""
|
||||
return _build_get_win_folder_via_ctypes()(csidl_name)
|
||||
|
||||
|
||||
def _pick_get_win_folder() -> Callable[[str], str]:
|
||||
"""Select the best method to resolve Windows folder paths: ctypes, then registry, then environment variables."""
|
||||
try:
|
||||
import ctypes # noqa: PLC0415
|
||||
import ctypes # ruff:ignore[import-outside-top-level, unused-import]
|
||||
except ImportError:
|
||||
pass
|
||||
else:
|
||||
if hasattr(ctypes, "windll"):
|
||||
return get_win_folder_via_ctypes
|
||||
return get_win_folder_via_ctypes
|
||||
try:
|
||||
import winreg # noqa: PLC0415, F401
|
||||
import winreg # ruff:ignore[import-outside-top-level, unused-import]
|
||||
except ImportError:
|
||||
return get_win_folder_from_env_vars
|
||||
else:
|
||||
return get_win_folder_from_registry
|
||||
|
||||
|
||||
get_win_folder = lru_cache(maxsize=None)(_pick_get_win_folder())
|
||||
_resolve_win_folder = _pick_get_win_folder()
|
||||
|
||||
|
||||
def get_win_folder(csidl_name: str) -> str:
|
||||
"""Get a Windows folder path, checking for ``WIN_PD_OVERRIDE_*`` environment variable overrides first.
|
||||
|
||||
For example, ``CSIDL_LOCAL_APPDATA`` can be overridden by setting ``WIN_PD_OVERRIDE_LOCAL_APPDATA``.
|
||||
|
||||
"""
|
||||
env_var = f"WIN_PD_OVERRIDE_{csidl_name.removeprefix('CSIDL_')}"
|
||||
if _is_fully_qualified(override := os.environ.get(env_var, "").strip()):
|
||||
return override
|
||||
return _resolve_win_folder(csidl_name)
|
||||
|
||||
|
||||
def _is_fully_qualified(path: str) -> bool:
|
||||
# ntpath.isabs changed for rooted paths without a drive in 3.13 and for a bare UNC share in 3.11
|
||||
drive, tail = ntpath.splitdrive(path)
|
||||
return drive.startswith(("\\", "/")) or (bool(drive) and tail.startswith(("\\", "/")))
|
||||
|
||||
|
||||
__all__ = [
|
||||
"Windows",
|
||||
|
||||
@@ -21,12 +21,12 @@
|
||||
.. _Pygments master branch:
|
||||
https://github.com/pygments/pygments/archive/master.zip#egg=Pygments-dev
|
||||
|
||||
:copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
from io import StringIO, BytesIO
|
||||
|
||||
__version__ = '2.19.2'
|
||||
__version__ = '2.21.0'
|
||||
__docformat__ = 'restructuredtext'
|
||||
|
||||
__all__ = ['lex', 'format', 'highlight']
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
Main entry point for ``python -m pygments``.
|
||||
|
||||
:copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
Format colored console output.
|
||||
|
||||
:copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
Module that implements the default filter.
|
||||
|
||||
:copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
Module containing filter lookup functions and default
|
||||
filters.
|
||||
|
||||
:copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
@@ -95,8 +95,10 @@ class CodeTagFilter(Filter):
|
||||
|
||||
|
||||
class SymbolFilter(Filter):
|
||||
"""Convert mathematical symbols such as \\<longrightarrow> in Isabelle
|
||||
or \\longrightarrow in LaTeX into Unicode characters.
|
||||
"""Convert mathematical symbols into Unicode characters.
|
||||
|
||||
Examples are ``\\<longrightarrow>`` in Isabelle or
|
||||
``\\longrightarrow`` in LaTeX.
|
||||
|
||||
This is mostly useful for HTML or console output when you want to
|
||||
approximate the source rendering you'd see in an IDE.
|
||||
@@ -685,8 +687,9 @@ class SymbolFilter(Filter):
|
||||
|
||||
|
||||
class KeywordCaseFilter(Filter):
|
||||
"""Convert keywords to lowercase or uppercase or capitalize them, which
|
||||
means first letter uppercase, rest lowercase.
|
||||
"""Convert keywords to lowercase or uppercase or capitalize them.
|
||||
|
||||
This means first letter uppercase, rest lowercase.
|
||||
|
||||
This can be useful e.g. if you highlight Pascal code and want to adapt the
|
||||
code to your styleguide.
|
||||
@@ -866,7 +869,7 @@ class VisibleWhitespaceFilter(Filter):
|
||||
|
||||
|
||||
class GobbleFilter(Filter):
|
||||
"""Gobbles source code lines (eats initial characters).
|
||||
"""Gobble source code lines (eats initial characters).
|
||||
|
||||
This filter drops the first ``n`` characters off every line of code. This
|
||||
may be useful when the source code fed to the lexer is indented by a fixed
|
||||
@@ -905,8 +908,7 @@ class GobbleFilter(Filter):
|
||||
|
||||
|
||||
class TokenMergeFilter(Filter):
|
||||
"""Merges consecutive tokens with the same token type in the output
|
||||
stream of a lexer.
|
||||
"""Merge consecutive tokens with the same token type in the output stream.
|
||||
|
||||
.. versionadded:: 1.2
|
||||
"""
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
Base formatter class.
|
||||
|
||||
:copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
Pygments formatters.
|
||||
|
||||
:copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
Base lexer classes.
|
||||
|
||||
:copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
@@ -336,7 +336,7 @@ class include(str): # pylint: disable=invalid-name
|
||||
|
||||
class _inherit:
|
||||
"""
|
||||
Indicates the a state should inherit from its superclass.
|
||||
Indicates that a state should inherit from its superclass.
|
||||
"""
|
||||
def __repr__(self):
|
||||
return 'inherit'
|
||||
@@ -446,8 +446,9 @@ def using(_other, **kwargs):
|
||||
# function has to create a new lexer instance
|
||||
if kwargs:
|
||||
# XXX: cache that somehow
|
||||
kwargs.update(lexer.options)
|
||||
lx = lexer.__class__(**kwargs)
|
||||
d = dict(lexer.options)
|
||||
d.update(kwargs)
|
||||
lx = lexer.__class__(**d)
|
||||
else:
|
||||
lx = lexer
|
||||
s = match.start()
|
||||
@@ -458,8 +459,9 @@ def using(_other, **kwargs):
|
||||
else:
|
||||
def callback(lexer, match, ctx=None):
|
||||
# XXX: cache that somehow
|
||||
kwargs.update(lexer.options)
|
||||
lx = _other(**kwargs)
|
||||
d = dict(lexer.options)
|
||||
d.update(kwargs)
|
||||
lx = _other(**d)
|
||||
|
||||
s = match.start()
|
||||
for i, t, v in lx.get_tokens_unprocessed(match.group(), **gt_kwargs):
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
Pygments lexers.
|
||||
|
||||
:copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@ LEXERS = {
|
||||
'BefungeLexer': ('pip._vendor.pygments.lexers.esoteric', 'Befunge', ('befunge',), ('*.befunge',), ('application/x-befunge',)),
|
||||
'BerryLexer': ('pip._vendor.pygments.lexers.berry', 'Berry', ('berry', 'be'), ('*.be',), ('text/x-berry', 'application/x-berry')),
|
||||
'BibTeXLexer': ('pip._vendor.pygments.lexers.bibtex', 'BibTeX', ('bibtex', 'bib'), ('*.bib',), ('text/x-bibtex',)),
|
||||
'BitBakeLexer': ('pip._vendor.pygments.lexers.bitbake', 'BitBake', ('bitbake',), ('*.bbclass', '*.bbappend'), ('text/x-bitbake',)),
|
||||
'BlitzBasicLexer': ('pip._vendor.pygments.lexers.basic', 'BlitzBasic', ('blitzbasic', 'b3d', 'bplus'), ('*.bb', '*.decls'), ('text/x-bb',)),
|
||||
'BlitzMaxLexer': ('pip._vendor.pygments.lexers.basic', 'BlitzMax', ('blitzmax', 'bmax'), ('*.bmx',), ('text/x-bmx',)),
|
||||
'BlueprintLexer': ('pip._vendor.pygments.lexers.blueprint', 'Blueprint', ('blueprint',), ('*.blp',), ('text/x-blueprint',)),
|
||||
@@ -63,6 +64,7 @@ LEXERS = {
|
||||
'BrainfuckLexer': ('pip._vendor.pygments.lexers.esoteric', 'Brainfuck', ('brainfuck', 'bf'), ('*.bf', '*.b'), ('application/x-brainfuck',)),
|
||||
'BugsLexer': ('pip._vendor.pygments.lexers.modeling', 'BUGS', ('bugs', 'winbugs', 'openbugs'), ('*.bug',), ()),
|
||||
'CAmkESLexer': ('pip._vendor.pygments.lexers.esoteric', 'CAmkES', ('camkes', 'idl4'), ('*.camkes', '*.idl4'), ()),
|
||||
'CELLexer': ('pip._vendor.pygments.lexers.cel', 'CEL', ('cel',), ('*.cel',), ()),
|
||||
'CLexer': ('pip._vendor.pygments.lexers.c_cpp', 'C', ('c',), ('*.c', '*.h', '*.idc', '*.x[bp]m'), ('text/x-chdr', 'text/x-csrc', 'image/x-xbitmap', 'image/x-xpixmap')),
|
||||
'CMakeLexer': ('pip._vendor.pygments.lexers.make', 'CMake', ('cmake',), ('*.cmake', 'CMakeLists.txt'), ('text/x-cmake',)),
|
||||
'CObjdumpLexer': ('pip._vendor.pygments.lexers.asm', 'c-objdump', ('c-objdump',), ('*.c-objdump',), ('text/x-c-objdump',)),
|
||||
@@ -71,6 +73,7 @@ LEXERS = {
|
||||
'CSharpAspxLexer': ('pip._vendor.pygments.lexers.dotnet', 'aspx-cs', ('aspx-cs',), ('*.aspx', '*.asax', '*.ascx', '*.ashx', '*.asmx', '*.axd'), ()),
|
||||
'CSharpLexer': ('pip._vendor.pygments.lexers.dotnet', 'C#', ('csharp', 'c#', 'cs'), ('*.cs',), ('text/x-csharp',)),
|
||||
'Ca65Lexer': ('pip._vendor.pygments.lexers.asm', 'ca65 assembler', ('ca65',), ('*.s',), ()),
|
||||
'CaddyfileLexer': ('pip._vendor.pygments.lexers.configs', 'Caddyfile', ('caddyfile', 'caddy'), ('Caddyfile',), ()),
|
||||
'CadlLexer': ('pip._vendor.pygments.lexers.archetype', 'cADL', ('cadl',), ('*.cadl',), ()),
|
||||
'CapDLLexer': ('pip._vendor.pygments.lexers.esoteric', 'CapDL', ('capdl',), ('*.cdl',), ()),
|
||||
'CapnProtoLexer': ('pip._vendor.pygments.lexers.capnproto', "Cap'n Proto", ('capnp',), ('*.capnp',), ()),
|
||||
@@ -101,9 +104,8 @@ LEXERS = {
|
||||
'Comal80Lexer': ('pip._vendor.pygments.lexers.comal', 'COMAL-80', ('comal', 'comal80'), ('*.cml', '*.comal'), ()),
|
||||
'CommonLispLexer': ('pip._vendor.pygments.lexers.lisp', 'Common Lisp', ('common-lisp', 'cl', 'lisp'), ('*.cl', '*.lisp'), ('text/x-common-lisp',)),
|
||||
'ComponentPascalLexer': ('pip._vendor.pygments.lexers.oberon', 'Component Pascal', ('componentpascal', 'cp'), ('*.cp', '*.cps'), ('text/x-component-pascal',)),
|
||||
'CoqLexer': ('pip._vendor.pygments.lexers.theorem', 'Coq', ('coq',), ('*.v',), ('text/x-coq',)),
|
||||
'CplintLexer': ('pip._vendor.pygments.lexers.cplint', 'cplint', ('cplint',), ('*.ecl', '*.prolog', '*.pro', '*.pl', '*.P', '*.lpad', '*.cpl'), ('text/x-cplint',)),
|
||||
'CppLexer': ('pip._vendor.pygments.lexers.c_cpp', 'C++', ('cpp', 'c++'), ('*.cpp', '*.hpp', '*.c++', '*.h++', '*.cc', '*.hh', '*.cxx', '*.hxx', '*.C', '*.H', '*.cp', '*.CPP', '*.tpp'), ('text/x-c++hdr', 'text/x-c++src')),
|
||||
'CppLexer': ('pip._vendor.pygments.lexers.c_cpp', 'C++', ('cpp', 'c++'), ('*.cpp', '*.hpp', '*.c++', '*.h++', '*.cc', '*.hh', '*.cxx', '*.hxx', '*.C', '*.H', '*.cp', '*.CPP', '*.tpp', '*.cppm', '*.ixx', '*.mxx', '*.ipp'), ('text/x-c++hdr', 'text/x-c++src')),
|
||||
'CppObjdumpLexer': ('pip._vendor.pygments.lexers.asm', 'cpp-objdump', ('cpp-objdump', 'c++-objdumb', 'cxx-objdump'), ('*.cpp-objdump', '*.c++-objdump', '*.cxx-objdump'), ('text/x-cpp-objdump',)),
|
||||
'CrmshLexer': ('pip._vendor.pygments.lexers.dsls', 'Crmsh', ('crmsh', 'pcmk'), ('*.crmsh', '*.pcmk'), ()),
|
||||
'CrocLexer': ('pip._vendor.pygments.lexers.d', 'Croc', ('croc',), ('*.croc',), ('text/x-crocsrc',)),
|
||||
@@ -168,7 +170,7 @@ LEXERS = {
|
||||
'FancyLexer': ('pip._vendor.pygments.lexers.ruby', 'Fancy', ('fancy', 'fy'), ('*.fy', '*.fancypack'), ('text/x-fancysrc',)),
|
||||
'FantomLexer': ('pip._vendor.pygments.lexers.fantom', 'Fantom', ('fan',), ('*.fan',), ('application/x-fantom',)),
|
||||
'FelixLexer': ('pip._vendor.pygments.lexers.felix', 'Felix', ('felix', 'flx'), ('*.flx', '*.flxh'), ('text/x-felix',)),
|
||||
'FennelLexer': ('pip._vendor.pygments.lexers.lisp', 'Fennel', ('fennel', 'fnl'), ('*.fnl',), ()),
|
||||
'FennelLexer': ('pip._vendor.pygments.lexers.lisp', 'Fennel', ('fennel', 'fnl'), ('*.fnl', '*.fnlm'), ('text/x-fennel',)),
|
||||
'FiftLexer': ('pip._vendor.pygments.lexers.fift', 'Fift', ('fift', 'fif'), ('*.fif',), ()),
|
||||
'FishShellLexer': ('pip._vendor.pygments.lexers.shell', 'Fish', ('fish', 'fishshell'), ('*.fish', '*.load'), ('application/x-fish',)),
|
||||
'FlatlineLexer': ('pip._vendor.pygments.lexers.dsls', 'Flatline', ('flatline',), (), ('text/x-flatline',)),
|
||||
@@ -254,7 +256,7 @@ LEXERS = {
|
||||
'Json5Lexer': ('pip._vendor.pygments.lexers.json5', 'JSON5', ('json5',), ('*.json5',), ()),
|
||||
'JsonBareObjectLexer': ('pip._vendor.pygments.lexers.data', 'JSONBareObject', (), (), ()),
|
||||
'JsonLdLexer': ('pip._vendor.pygments.lexers.data', 'JSON-LD', ('jsonld', 'json-ld'), ('*.jsonld',), ('application/ld+json',)),
|
||||
'JsonLexer': ('pip._vendor.pygments.lexers.data', 'JSON', ('json', 'json-object'), ('*.json', '*.jsonl', '*.ndjson', 'Pipfile.lock'), ('application/json', 'application/json-object', 'application/x-ndjson', 'application/jsonl', 'application/json-seq')),
|
||||
'JsonLexer': ('pip._vendor.pygments.lexers.data', 'JSON', ('json', 'json-object'), ('*.json', '*.jsonl', '*.ndjson', 'Pipfile.lock', '*.module', '*.xc'), ('application/json', 'application/json-object', 'application/x-ndjson', 'application/jsonl', 'application/json-seq')),
|
||||
'JsonnetLexer': ('pip._vendor.pygments.lexers.jsonnet', 'Jsonnet', ('jsonnet',), ('*.jsonnet', '*.libsonnet'), ()),
|
||||
'JspLexer': ('pip._vendor.pygments.lexers.templates', 'Java Server Page', ('jsp',), ('*.jsp',), ('application/x-jsp',)),
|
||||
'JsxLexer': ('pip._vendor.pygments.lexers.jsx', 'JSX', ('jsx', 'react'), ('*.jsx', '*.react'), ('text/jsx', 'text/typescript-jsx')),
|
||||
@@ -314,11 +316,11 @@ LEXERS = {
|
||||
'MarkdownLexer': ('pip._vendor.pygments.lexers.markup', 'Markdown', ('markdown', 'md'), ('*.md', '*.markdown'), ('text/x-markdown',)),
|
||||
'MaskLexer': ('pip._vendor.pygments.lexers.javascript', 'Mask', ('mask',), ('*.mask',), ('text/x-mask',)),
|
||||
'MasonLexer': ('pip._vendor.pygments.lexers.templates', 'Mason', ('mason',), ('*.m', '*.mhtml', '*.mc', '*.mi', 'autohandler', 'dhandler'), ('application/x-mason',)),
|
||||
'MathematicaLexer': ('pip._vendor.pygments.lexers.algebra', 'Mathematica', ('mathematica', 'mma', 'nb'), ('*.nb', '*.cdf', '*.nbp', '*.ma'), ('application/mathematica', 'application/vnd.wolfram.mathematica', 'application/vnd.wolfram.mathematica.package', 'application/vnd.wolfram.cdf')),
|
||||
'MathematicaLexer': ('pip._vendor.pygments.lexers.algebra', 'Mathematica', ('mathematica', 'mma', 'nb', 'wl', 'wolfram'), ('*.nb', '*.cdf', '*.nbp', '*.ma', '*.wl', '*.wls'), ('application/mathematica', 'application/vnd.wolfram.mathematica', 'application/vnd.wolfram.mathematica.package', 'application/vnd.wolfram.cdf', 'application/vnd.wolfram.wl')),
|
||||
'MatlabLexer': ('pip._vendor.pygments.lexers.matlab', 'Matlab', ('matlab',), ('*.m',), ('text/matlab',)),
|
||||
'MatlabSessionLexer': ('pip._vendor.pygments.lexers.matlab', 'Matlab session', ('matlabsession',), (), ()),
|
||||
'MaximaLexer': ('pip._vendor.pygments.lexers.maxima', 'Maxima', ('maxima', 'macsyma'), ('*.mac', '*.max'), ()),
|
||||
'MesonLexer': ('pip._vendor.pygments.lexers.meson', 'Meson', ('meson', 'meson.build'), ('meson.build', 'meson_options.txt'), ('text/x-meson',)),
|
||||
'MesonLexer': ('pip._vendor.pygments.lexers.meson', 'Meson', ('meson', 'meson.build'), ('meson.build', 'meson.options', 'meson_options.txt'), ('text/x-meson',)),
|
||||
'MiniDLexer': ('pip._vendor.pygments.lexers.d', 'MiniD', ('minid',), (), ('text/x-minidsrc',)),
|
||||
'MiniScriptLexer': ('pip._vendor.pygments.lexers.scripting', 'MiniScript', ('miniscript', 'ms'), ('*.ms',), ('text/x-minicript', 'application/x-miniscript')),
|
||||
'ModelicaLexer': ('pip._vendor.pygments.lexers.modeling', 'Modelica', ('modelica',), ('*.mo',), ('text/x-modelica',)),
|
||||
@@ -412,11 +414,12 @@ LEXERS = {
|
||||
'PtxLexer': ('pip._vendor.pygments.lexers.ptx', 'PTX', ('ptx',), ('*.ptx',), ('text/x-ptx',)),
|
||||
'PugLexer': ('pip._vendor.pygments.lexers.html', 'Pug', ('pug', 'jade'), ('*.pug', '*.jade'), ('text/x-pug', 'text/x-jade')),
|
||||
'PuppetLexer': ('pip._vendor.pygments.lexers.dsls', 'Puppet', ('puppet',), ('*.pp',), ()),
|
||||
'PureScriptLexer': ('pip._vendor.pygments.lexers.purescript', 'PureScript', ('purescript', 'purs'), ('*.purs',), ('text/x-purescript',)),
|
||||
'PyPyLogLexer': ('pip._vendor.pygments.lexers.console', 'PyPy Log', ('pypylog', 'pypy'), ('*.pypylog',), ('application/x-pypylog',)),
|
||||
'Python2Lexer': ('pip._vendor.pygments.lexers.python', 'Python 2.x', ('python2', 'py2'), (), ('text/x-python2', 'application/x-python2')),
|
||||
'Python2TracebackLexer': ('pip._vendor.pygments.lexers.python', 'Python 2.x Traceback', ('py2tb',), ('*.py2tb',), ('text/x-python2-traceback',)),
|
||||
'PythonConsoleLexer': ('pip._vendor.pygments.lexers.python', 'Python console session', ('pycon', 'python-console'), (), ('text/x-python-doctest',)),
|
||||
'PythonLexer': ('pip._vendor.pygments.lexers.python', 'Python', ('python', 'py', 'sage', 'python3', 'py3', 'bazel', 'starlark', 'pyi'), ('*.py', '*.pyw', '*.pyi', '*.jy', '*.sage', '*.sc', 'SConstruct', 'SConscript', '*.bzl', 'BUCK', 'BUILD', 'BUILD.bazel', 'WORKSPACE', '*.tac'), ('text/x-python', 'application/x-python', 'text/x-python3', 'application/x-python3')),
|
||||
'PythonLexer': ('pip._vendor.pygments.lexers.python', 'Python', ('python', 'py', 'sage', 'python3', 'py3', 'bazel', 'starlark', 'pyi'), ('*.py', '*.pyw', '*.pyi', '*.jy', '*.sage', '*.sc', 'SConstruct', 'SConscript', '*.bzl', 'BUCK', 'BUILD', 'BUILD.bazel', 'WORKSPACE', '*.tac', '*.pye'), ('text/x-python', 'application/x-python', 'text/x-python3', 'application/x-python3')),
|
||||
'PythonTracebackLexer': ('pip._vendor.pygments.lexers.python', 'Python Traceback', ('pytb', 'py3tb'), ('*.pytb', '*.py3tb'), ('text/x-python-traceback', 'text/x-python3-traceback')),
|
||||
'PythonUL4Lexer': ('pip._vendor.pygments.lexers.ul4', 'Python+UL4', ('py+ul4',), ('*.pyul4',), ()),
|
||||
'QBasicLexer': ('pip._vendor.pygments.lexers.basic', 'QBasic', ('qbasic', 'basic'), ('*.BAS', '*.bas'), ('text/basic',)),
|
||||
@@ -444,6 +447,7 @@ LEXERS = {
|
||||
'RedcodeLexer': ('pip._vendor.pygments.lexers.esoteric', 'Redcode', ('redcode',), ('*.cw',), ()),
|
||||
'RegeditLexer': ('pip._vendor.pygments.lexers.configs', 'reg', ('registry',), ('*.reg',), ('text/x-windows-registry',)),
|
||||
'RegoLexer': ('pip._vendor.pygments.lexers.rego', 'Rego', ('rego',), ('*.rego',), ('text/x-rego',)),
|
||||
'RellLexer': ('pip._vendor.pygments.lexers.rell', 'Rell', ('rell',), ('*.rell',), ('text/x-rell',)),
|
||||
'ResourceLexer': ('pip._vendor.pygments.lexers.resource', 'ResourceBundle', ('resourcebundle', 'resource'), (), ()),
|
||||
'RexxLexer': ('pip._vendor.pygments.lexers.scripting', 'Rexx', ('rexx', 'arexx'), ('*.rexx', '*.rex', '*.rx', '*.arexx'), ('text/x-rexx',)),
|
||||
'RhtmlLexer': ('pip._vendor.pygments.lexers.templates', 'RHTML', ('rhtml', 'html+erb', 'html+ruby'), ('*.rhtml',), ('text/html+ruby',)),
|
||||
@@ -452,6 +456,7 @@ LEXERS = {
|
||||
'RoboconfGraphLexer': ('pip._vendor.pygments.lexers.roboconf', 'Roboconf Graph', ('roboconf-graph',), ('*.graph',), ()),
|
||||
'RoboconfInstancesLexer': ('pip._vendor.pygments.lexers.roboconf', 'Roboconf Instances', ('roboconf-instances',), ('*.instances',), ()),
|
||||
'RobotFrameworkLexer': ('pip._vendor.pygments.lexers.robotframework', 'RobotFramework', ('robotframework',), ('*.robot', '*.resource'), ('text/x-robotframework',)),
|
||||
'RocqLexer': ('pip._vendor.pygments.lexers.theorem', 'Rocq Prover', ('coq', 'rocq', 'rocq-prover'), ('*.v',), ('text/x-coq', 'text/x-rocq')),
|
||||
'RqlLexer': ('pip._vendor.pygments.lexers.sql', 'RQL', ('rql',), ('*.rql',), ('text/x-rql',)),
|
||||
'RslLexer': ('pip._vendor.pygments.lexers.dsls', 'RSL', ('rsl',), ('*.rsl',), ('text/rsl',)),
|
||||
'RstLexer': ('pip._vendor.pygments.lexers.markup', 'reStructuredText', ('restructuredtext', 'rst', 'rest'), ('*.rst', '*.rest'), ('text/x-rst', 'text/prs.fallenstein.rst')),
|
||||
@@ -583,7 +588,7 @@ LEXERS = {
|
||||
'XQueryLexer': ('pip._vendor.pygments.lexers.webmisc', 'XQuery', ('xquery', 'xqy', 'xq', 'xql', 'xqm'), ('*.xqy', '*.xquery', '*.xq', '*.xql', '*.xqm'), ('text/xquery', 'application/xquery')),
|
||||
'XmlDjangoLexer': ('pip._vendor.pygments.lexers.templates', 'XML+Django/Jinja', ('xml+django', 'xml+jinja'), ('*.xml.j2', '*.xml.jinja2'), ('application/xml+django', 'application/xml+jinja')),
|
||||
'XmlErbLexer': ('pip._vendor.pygments.lexers.templates', 'XML+Ruby', ('xml+ruby', 'xml+erb'), (), ('application/xml+ruby',)),
|
||||
'XmlLexer': ('pip._vendor.pygments.lexers.html', 'XML', ('xml',), ('*.xml', '*.xsl', '*.rss', '*.xslt', '*.xsd', '*.wsdl', '*.wsf'), ('text/xml', 'application/xml', 'image/svg+xml', 'application/rss+xml', 'application/atom+xml')),
|
||||
'XmlLexer': ('pip._vendor.pygments.lexers.html', 'XML', ('xml',), ('*.xml', '*.xsl', '*.rss', '*.xslt', '*.xsd', '*.wsdl', '*.wsf', '*.xbrl', '*.pom', '*.svg'), ('text/xml', 'application/xml', 'image/svg+xml', 'application/rss+xml', 'application/atom+xml')),
|
||||
'XmlPhpLexer': ('pip._vendor.pygments.lexers.templates', 'XML+PHP', ('xml+php',), (), ('application/xml+php',)),
|
||||
'XmlSmartyLexer': ('pip._vendor.pygments.lexers.templates', 'XML+Smarty', ('xml+smarty',), (), ('application/xml+smarty',)),
|
||||
'XorgLexer': ('pip._vendor.pygments.lexers.xorg', 'Xorg', ('xorg.conf',), ('xorg.conf',), ()),
|
||||
@@ -592,7 +597,7 @@ LEXERS = {
|
||||
'XtendLexer': ('pip._vendor.pygments.lexers.jvm', 'Xtend', ('xtend',), ('*.xtend',), ('text/x-xtend',)),
|
||||
'XtlangLexer': ('pip._vendor.pygments.lexers.lisp', 'xtlang', ('extempore',), ('*.xtm',), ()),
|
||||
'YamlJinjaLexer': ('pip._vendor.pygments.lexers.templates', 'YAML+Jinja', ('yaml+jinja', 'salt', 'sls'), ('*.sls', '*.yaml.j2', '*.yml.j2', '*.yaml.jinja2', '*.yml.jinja2'), ('text/x-yaml+jinja', 'text/x-sls')),
|
||||
'YamlLexer': ('pip._vendor.pygments.lexers.data', 'YAML', ('yaml',), ('*.yaml', '*.yml'), ('text/x-yaml',)),
|
||||
'YamlLexer': ('pip._vendor.pygments.lexers.data', 'YAML', ('yaml', 'yml'), ('*.yaml', '*.yml'), ('text/x-yaml',)),
|
||||
'YangLexer': ('pip._vendor.pygments.lexers.yang', 'YANG', ('yang',), ('*.yang',), ('application/yang',)),
|
||||
'YaraLexer': ('pip._vendor.pygments.lexers.yara', 'YARA', ('yara', 'yar'), ('*.yar',), ('text/x-yara',)),
|
||||
'ZeekLexer': ('pip._vendor.pygments.lexers.dsls', 'Zeek', ('zeek', 'bro'), ('*.zeek', '*.bro'), ()),
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
Lexers for Python and related languages.
|
||||
|
||||
:copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
@@ -55,6 +55,8 @@ class PythonLexer(RegexLexer):
|
||||
'WORKSPACE',
|
||||
# Twisted Application infrastructure
|
||||
'*.tac',
|
||||
# Execubot level format
|
||||
'*.pye',
|
||||
]
|
||||
mimetypes = ['text/x-python', 'application/x-python',
|
||||
'text/x-python3', 'application/x-python3']
|
||||
@@ -99,9 +101,9 @@ class PythonLexer(RegexLexer):
|
||||
tokens = {
|
||||
'root': [
|
||||
(r'\n', Whitespace),
|
||||
(r'^(\s*)([rRuUbB]{,2})("""(?:.|\n)*?""")',
|
||||
(r'^(\s*)([rRuUbB]{,2})("""[\s\S]*?""")',
|
||||
bygroups(Whitespace, String.Affix, String.Doc)),
|
||||
(r"^(\s*)([rRuUbB]{,2})('''(?:.|\n)*?''')",
|
||||
(r"^(\s*)([rRuUbB]{,2})('''[\s\S]*?''')",
|
||||
bygroups(Whitespace, String.Affix, String.Doc)),
|
||||
(r'\A#!.+$', Comment.Hashbang),
|
||||
(r'#.*$', Comment.Single),
|
||||
@@ -111,6 +113,12 @@ class PythonLexer(RegexLexer):
|
||||
include('soft-keywords'),
|
||||
(r'(def)((?:\s|\\\s)+)', bygroups(Keyword, Whitespace), 'funcname'),
|
||||
(r'(class)((?:\s|\\\s)+)', bygroups(Keyword, Whitespace), 'classname'),
|
||||
(r'^(lazy)((?:\s|\\\s)+)(from)((?:\s|\\\s)+)',
|
||||
bygroups(Keyword.Namespace, Whitespace, Keyword.Namespace, Whitespace),
|
||||
'fromimport'),
|
||||
(r'^(lazy)((?:\s|\\\s)+)(import)((?:\s|\\\s)+)',
|
||||
bygroups(Keyword.Namespace, Whitespace, Keyword.Namespace, Whitespace),
|
||||
'import'),
|
||||
(r'(from)((?:\s|\\\s)+)', bygroups(Keyword.Namespace, Whitespace),
|
||||
'fromimport'),
|
||||
(r'(import)((?:\s|\\\s)+)', bygroups(Keyword.Namespace, Whitespace),
|
||||
@@ -118,27 +126,27 @@ class PythonLexer(RegexLexer):
|
||||
include('expr'),
|
||||
],
|
||||
'expr': [
|
||||
# raw f-strings
|
||||
('(?i)(rf|fr)(""")',
|
||||
# raw f-strings and t-strings
|
||||
('(?i)(r[ft]|[ft]r)(""")',
|
||||
bygroups(String.Affix, String.Double),
|
||||
combined('rfstringescape', 'tdqf')),
|
||||
("(?i)(rf|fr)(''')",
|
||||
("(?i)(r[ft]|[ft]r)(''')",
|
||||
bygroups(String.Affix, String.Single),
|
||||
combined('rfstringescape', 'tsqf')),
|
||||
('(?i)(rf|fr)(")',
|
||||
('(?i)(r[ft]|[ft]r)(")',
|
||||
bygroups(String.Affix, String.Double),
|
||||
combined('rfstringescape', 'dqf')),
|
||||
("(?i)(rf|fr)(')",
|
||||
("(?i)(r[ft]|[ft]r)(')",
|
||||
bygroups(String.Affix, String.Single),
|
||||
combined('rfstringescape', 'sqf')),
|
||||
# non-raw f-strings
|
||||
('([fF])(""")', bygroups(String.Affix, String.Double),
|
||||
# non-raw f-strings and t-strings
|
||||
('([fFtT])(""")', bygroups(String.Affix, String.Double),
|
||||
combined('fstringescape', 'tdqf')),
|
||||
("([fF])(''')", bygroups(String.Affix, String.Single),
|
||||
("([fFtT])(''')", bygroups(String.Affix, String.Single),
|
||||
combined('fstringescape', 'tsqf')),
|
||||
('([fF])(")', bygroups(String.Affix, String.Double),
|
||||
('([fFtT])(")', bygroups(String.Affix, String.Double),
|
||||
combined('fstringescape', 'dqf')),
|
||||
("([fF])(')", bygroups(String.Affix, String.Single),
|
||||
("([fFtT])(')", bygroups(String.Affix, String.Single),
|
||||
combined('fstringescape', 'sqf')),
|
||||
# raw bytes and strings
|
||||
('(?i)(rb|br|r)(""")',
|
||||
@@ -236,13 +244,14 @@ class PythonLexer(RegexLexer):
|
||||
'__import__', 'abs', 'aiter', 'all', 'any', 'bin', 'bool', 'bytearray',
|
||||
'breakpoint', 'bytes', 'callable', 'chr', 'classmethod', 'compile',
|
||||
'complex', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval',
|
||||
'filter', 'float', 'format', 'frozenset', 'getattr', 'globals',
|
||||
'hasattr', 'hash', 'hex', 'id', 'input', 'int', 'isinstance',
|
||||
'issubclass', 'iter', 'len', 'list', 'locals', 'map', 'max',
|
||||
'memoryview', 'min', 'next', 'object', 'oct', 'open', 'ord', 'pow',
|
||||
'print', 'property', 'range', 'repr', 'reversed', 'round', 'set',
|
||||
'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super',
|
||||
'tuple', 'type', 'vars', 'zip'), prefix=r'(?<!\.)', suffix=r'\b'),
|
||||
'filter', 'float', 'format', 'frozendict', 'frozenset', 'getattr',
|
||||
'globals', 'hasattr', 'hash', 'hex', 'id', 'input', 'int',
|
||||
'isinstance', 'issubclass', 'iter', 'len', 'list', 'locals', 'map',
|
||||
'max', 'memoryview', 'min', 'next', 'object', 'oct', 'open', 'ord',
|
||||
'pow', 'print', 'property', 'range', 'repr', 'reversed', 'round',
|
||||
'sentinel', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str',
|
||||
'sum', 'super', 'tuple', 'type', 'vars', 'zip'), prefix=r'(?<!\.)',
|
||||
suffix=r'\b'),
|
||||
Name.Builtin),
|
||||
(r'(?<!\.)(self|Ellipsis|NotImplemented|cls)\b', Name.Builtin.Pseudo),
|
||||
(words((
|
||||
@@ -446,9 +455,9 @@ class Python2Lexer(RegexLexer):
|
||||
tokens = {
|
||||
'root': [
|
||||
(r'\n', Whitespace),
|
||||
(r'^(\s*)([rRuUbB]{,2})("""(?:.|\n)*?""")',
|
||||
(r'^(\s*)([rRuUbB]{,2})("""[\s\S]*?""")',
|
||||
bygroups(Whitespace, String.Affix, String.Doc)),
|
||||
(r"^(\s*)([rRuUbB]{,2})('''(?:.|\n)*?''')",
|
||||
(r"^(\s*)([rRuUbB]{,2})('''[\s\S]*?''')",
|
||||
bygroups(Whitespace, String.Affix, String.Doc)),
|
||||
(r'[^\S\n]+', Text),
|
||||
(r'\A#!.+$', Comment.Hashbang),
|
||||
@@ -842,8 +851,8 @@ class CythonLexer(RegexLexer):
|
||||
tokens = {
|
||||
'root': [
|
||||
(r'\n', Whitespace),
|
||||
(r'^(\s*)("""(?:.|\n)*?""")', bygroups(Whitespace, String.Doc)),
|
||||
(r"^(\s*)('''(?:.|\n)*?''')", bygroups(Whitespace, String.Doc)),
|
||||
(r'^(\s*)("""[\s\S]*?""")', bygroups(Whitespace, String.Doc)),
|
||||
(r"^(\s*)('''[\s\S]*?''')", bygroups(Whitespace, String.Doc)),
|
||||
(r'[^\S\n]+', Text),
|
||||
(r'#.*$', Comment),
|
||||
(r'[]{}:(),;[]', Punctuation),
|
||||
@@ -861,7 +870,7 @@ class CythonLexer(RegexLexer):
|
||||
(r'(cp?def)(\s+)', bygroups(Keyword, Whitespace), 'cdef'),
|
||||
# (should actually start a block with only cdefs)
|
||||
(r'(cdef)(:)', bygroups(Keyword, Punctuation)),
|
||||
(r'(class|struct)(\s+)', bygroups(Keyword, Whitespace), 'classname'),
|
||||
(r'(class|cppclass|struct)(\s+)', bygroups(Keyword, Whitespace), 'classname'),
|
||||
(r'(from)(\s+)', bygroups(Keyword, Whitespace), 'fromimport'),
|
||||
(r'(c?import)(\s+)', bygroups(Keyword, Whitespace), 'import'),
|
||||
include('builtins'),
|
||||
@@ -879,37 +888,38 @@ class CythonLexer(RegexLexer):
|
||||
],
|
||||
'keywords': [
|
||||
(words((
|
||||
'assert', 'async', 'await', 'break', 'by', 'continue', 'ctypedef', 'del', 'elif',
|
||||
'else', 'except', 'except?', 'exec', 'finally', 'for', 'fused', 'gil',
|
||||
'global', 'if', 'include', 'lambda', 'nogil', 'pass', 'print',
|
||||
'raise', 'return', 'try', 'while', 'yield', 'as', 'with'), suffix=r'\b'),
|
||||
'assert', 'async', 'await', 'break', 'by', 'continue', 'ctypedef', 'del',
|
||||
'elif', 'else', 'except', 'except?', 'exec', 'finally', 'for', 'fused', 'gil',
|
||||
'global', 'if', 'include', 'lambda', 'namespace', 'new', 'noexcept','nogil',
|
||||
'pass', 'print', 'raise', 'return', 'try', 'while', 'yield', 'as', 'with'),
|
||||
suffix=r'\b'),
|
||||
Keyword),
|
||||
(words(('True', 'False', 'None', 'NULL'), suffix=r'\b'), Keyword.Constant),
|
||||
(r'(DEF|IF|ELIF|ELSE)\b', Comment.Preproc),
|
||||
],
|
||||
'builtins': [
|
||||
(words((
|
||||
'__import__', 'abs', 'all', 'any', 'apply', 'basestring', 'bin', 'bint',
|
||||
'bool', 'buffer', 'bytearray', 'bytes', 'callable', 'chr',
|
||||
'bool', 'buffer', 'bytearray', 'bytes', 'callable', 'char', 'chr',
|
||||
'classmethod', 'cmp', 'coerce', 'compile', 'complex', 'delattr',
|
||||
'dict', 'dir', 'divmod', 'enumerate', 'eval', 'execfile', 'exit',
|
||||
'dict', 'dir', 'divmod', 'double', 'enumerate', 'eval', 'execfile', 'exit',
|
||||
'file', 'filter', 'float', 'frozenset', 'getattr', 'globals',
|
||||
'hasattr', 'hash', 'hex', 'id', 'input', 'int', 'intern', 'isinstance',
|
||||
'issubclass', 'iter', 'len', 'list', 'locals', 'long', 'map', 'max',
|
||||
'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'property', 'Py_ssize_t',
|
||||
'range', 'raw_input', 'reduce', 'reload', 'repr', 'reversed',
|
||||
'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod',
|
||||
'str', 'sum', 'super', 'tuple', 'type', 'unichr', 'unicode', 'unsigned',
|
||||
'vars', 'xrange', 'zip'), prefix=r'(?<!\.)', suffix=r'\b'),
|
||||
'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'property',
|
||||
'Py_ssize_t', 'range', 'raw_input', 'reduce', 'reload', 'repr', 'reversed',
|
||||
'round', 'set', 'setattr', 'size_t', 'slice', 'sorted', 'staticmethod',
|
||||
'ssize_t', 'str', 'sum', 'super', 'tuple', 'type', 'unichr', 'unicode',
|
||||
'unsigned', 'vars', 'xrange', 'zip'), prefix=r'(?<!\.)', suffix=r'\b'),
|
||||
Name.Builtin),
|
||||
(r'(?<!\.)(self|None|Ellipsis|NotImplemented|False|True|NULL'
|
||||
r')\b', Name.Builtin.Pseudo),
|
||||
(r'(?<!\.)(self|cls|Ellipsis|NotImplemented)\b', Name.Builtin.Pseudo),
|
||||
(words((
|
||||
'ArithmeticError', 'AssertionError', 'AttributeError',
|
||||
'BaseException', 'DeprecationWarning', 'EOFError', 'EnvironmentError',
|
||||
'Exception', 'FloatingPointError', 'FutureWarning', 'GeneratorExit',
|
||||
'IOError', 'ImportError', 'ImportWarning', 'IndentationError',
|
||||
'IndexError', 'KeyError', 'KeyboardInterrupt', 'LookupError',
|
||||
'MemoryError', 'NameError', 'NotImplemented', 'NotImplementedError',
|
||||
'MemoryError', 'NameError', 'NotImplementedError',
|
||||
'OSError', 'OverflowError', 'OverflowWarning',
|
||||
'PendingDeprecationWarning', 'ReferenceError', 'RuntimeError',
|
||||
'RuntimeWarning', 'StandardError', 'StopIteration', 'SyntaxError',
|
||||
@@ -938,12 +948,12 @@ class CythonLexer(RegexLexer):
|
||||
(r'[a-zA-Z_]\w*', Name.Function, '#pop')
|
||||
],
|
||||
'cdef': [
|
||||
(r'(public|readonly|extern|api|inline)\b', Keyword.Reserved),
|
||||
(r'(struct|enum|union|class)\b', Keyword),
|
||||
(r'([a-zA-Z_]\w*)(\s*)(?=[(:#=]|$)',
|
||||
bygroups(Name.Function, Whitespace), '#pop'),
|
||||
(r'([a-zA-Z_]\w*)(\s*)(,)',
|
||||
bygroups(Name.Function, Whitespace, Punctuation)),
|
||||
(r"(public|readonly|extern|api|inline|packed)\b", Keyword.Reserved),
|
||||
(r"(struct|enum|union|class|cppclass)\b(\s+)([a-zA-Z_]\w*)",
|
||||
bygroups(Keyword, Whitespace, Name.Class), "#pop",),
|
||||
(r"([a-zA-Z_]\w*)(\s*)(?=\()", bygroups(Name.Function, Whitespace), "#pop"),
|
||||
(r"([a-zA-Z_]\w*)(\s*)(?=[:,=#\n]|$)", bygroups(Name.Variable, Whitespace), "#pop"),
|
||||
(r"([a-zA-Z_]\w*)(\s*)(,)", bygroups(Name.Variable, Whitespace, Punctuation)),
|
||||
(r'from\b', Keyword, '#pop'),
|
||||
(r'as\b', Keyword),
|
||||
(r':', Punctuation, '#pop'),
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
A simple modeline parser (based on pymodeline).
|
||||
|
||||
:copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
|
||||
@@ -29,10 +29,10 @@
|
||||
yourfilter = yourfilter:YourFilter
|
||||
|
||||
|
||||
:copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
from importlib.metadata import entry_points
|
||||
import functools
|
||||
|
||||
LEXER_ENTRY_POINT = 'pygments.lexers'
|
||||
FORMATTER_ENTRY_POINT = 'pygments.formatters'
|
||||
@@ -40,7 +40,10 @@ STYLE_ENTRY_POINT = 'pygments.styles'
|
||||
FILTER_ENTRY_POINT = 'pygments.filters'
|
||||
|
||||
|
||||
@functools.cache
|
||||
def iter_entry_points(group_name):
|
||||
from importlib.metadata import entry_points
|
||||
|
||||
groups = entry_points()
|
||||
if hasattr(groups, 'select'):
|
||||
# New interface in Python 3.10 and newer versions of the
|
||||
|
||||
@@ -5,13 +5,12 @@
|
||||
An algorithm that generates optimized regexes for matching long lists of
|
||||
literal strings.
|
||||
|
||||
:copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
import re
|
||||
from re import escape
|
||||
from os.path import commonprefix
|
||||
from itertools import groupby
|
||||
from operator import itemgetter
|
||||
|
||||
@@ -19,6 +18,18 @@ CS_ESCAPE = re.compile(r'[\[\^\\\-\]]')
|
||||
FIRST_ELEMENT = itemgetter(0)
|
||||
|
||||
|
||||
def commonprefix(m):
|
||||
"""Given an iterable of strings, returns the longest common leading substring"""
|
||||
if not m:
|
||||
return ""
|
||||
s1 = min(m)
|
||||
s2 = max(m)
|
||||
for i, c in enumerate(s1):
|
||||
if c != s2[i]:
|
||||
return s1[:i]
|
||||
return s1
|
||||
|
||||
|
||||
def make_charset(letters):
|
||||
return '[' + CS_ESCAPE.sub(lambda m: '\\' + m.group(), ''.join(letters)) + ']'
|
||||
|
||||
@@ -87,5 +98,5 @@ def regex_opt(strings, prefix='', suffix=''):
|
||||
|
||||
*prefix* and *suffix* are pre- and appended to the final regex.
|
||||
"""
|
||||
strings = sorted(strings)
|
||||
strings = sorted(set(strings))
|
||||
return prefix + regex_opt_inner(strings, '(') + suffix
|
||||
@@ -11,7 +11,7 @@
|
||||
Have a look at the `DelphiLexer` to get an idea of how to use
|
||||
this scanner.
|
||||
|
||||
:copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
import re
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
Sphinx extension to generate automatic documentation of lexers,
|
||||
formatters and filters.
|
||||
|
||||
:copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
Basic style object.
|
||||
|
||||
:copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
@@ -74,6 +74,8 @@ class StyleMeta(type):
|
||||
return col[0] * 2 + col[1] * 2 + col[2] * 2
|
||||
elif text == '':
|
||||
return ''
|
||||
elif text == 'transparent':
|
||||
return text
|
||||
elif text.startswith('var') or text.startswith('calc'):
|
||||
return text
|
||||
assert False, f"wrong color format {text!r}"
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
Contains built-in styles.
|
||||
|
||||
:copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ STYLES = {
|
||||
'MonokaiStyle': ('pygments.styles.monokai', 'monokai', ()),
|
||||
'MurphyStyle': ('pygments.styles.murphy', 'murphy', ()),
|
||||
'NativeStyle': ('pygments.styles.native', 'native', ()),
|
||||
'NightOwlStyle': ('pygments.styles.night_owl', 'night-owl', ()),
|
||||
'NordDarkerStyle': ('pygments.styles.nord', 'nord-darker', ()),
|
||||
'NordStyle': ('pygments.styles.nord', 'nord', ()),
|
||||
'OneDarkStyle': ('pygments.styles.onedark', 'one-dark', ()),
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
Basic token types and the standard tokens.
|
||||
|
||||
:copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
Inspired by chartypes_create.py from the MoinMoin project.
|
||||
|
||||
:copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
|
||||
@@ -4,12 +4,13 @@
|
||||
|
||||
Utility functions.
|
||||
|
||||
:copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
|
||||
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
import re
|
||||
from io import TextIOWrapper
|
||||
import html
|
||||
|
||||
|
||||
split_path_re = re.compile(r'[/\\ ]')
|
||||
@@ -22,7 +23,7 @@ doctype_lookup_re = re.compile(r'''
|
||||
)
|
||||
[^>]*>
|
||||
''', re.DOTALL | re.MULTILINE | re.VERBOSE)
|
||||
tag_re = re.compile(r'<(.+?)(\s.*?)?>.*?</.+?>',
|
||||
tag_re = re.compile(r'<([a-zA-Z][a-zA-Z0-9._:-]*)(\s[^>]*)?>.*?</\1\s*>',
|
||||
re.IGNORECASE | re.DOTALL | re.MULTILINE)
|
||||
xml_decl_re = re.compile(r'\s*<\?xml[^>]*\?>', re.I)
|
||||
|
||||
@@ -286,7 +287,7 @@ def guess_decode(text):
|
||||
try:
|
||||
import locale
|
||||
prefencoding = locale.getpreferredencoding()
|
||||
text = text.decode()
|
||||
text = text.decode(prefencoding)
|
||||
return text, prefencoding
|
||||
except (UnicodeDecodeError, LookupError):
|
||||
text = text.decode('latin1')
|
||||
@@ -322,3 +323,22 @@ class UnclosingTextIOWrapper(TextIOWrapper):
|
||||
# Don't close underlying buffer on destruction.
|
||||
def close(self):
|
||||
self.flush()
|
||||
|
||||
|
||||
def html_escape(string, quote=True) -> str:
|
||||
"""Return a safe version of the passed `string`,
|
||||
and an empty string if `None`.
|
||||
|
||||
`NoneType` is not supported by `html.escape`, as `html.escape`
|
||||
uses the built-in `replace` function on `string`, so we need to
|
||||
check for it first.
|
||||
|
||||
Optional flag quote is true by default, which also escapes
|
||||
double and single quotes.
|
||||
See https://docs.python.org/3/library/html.html#html.escape for more details.
|
||||
"""
|
||||
if string is not None:
|
||||
# TODO: Eventually, check that string is a str, and if not, print a
|
||||
# warning or error here.
|
||||
return html.escape(str(string), quote=quote)
|
||||
return ''
|
||||
@@ -4,6 +4,7 @@
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from ._impl import (
|
||||
BuildBackendWarning,
|
||||
BackendUnavailable,
|
||||
BuildBackendHookCaller,
|
||||
HookMissing,
|
||||
@@ -12,8 +13,9 @@ from ._impl import (
|
||||
quiet_subprocess_runner,
|
||||
)
|
||||
|
||||
__version__ = "1.2.0"
|
||||
__version__ = "1.3.3"
|
||||
__all__ = [
|
||||
"BuildBackendWarning",
|
||||
"BackendUnavailable",
|
||||
"BackendInvalid",
|
||||
"HookMissing",
|
||||
|
||||
@@ -2,11 +2,12 @@ import json
|
||||
import os
|
||||
import sys
|
||||
import tempfile
|
||||
import subprocess
|
||||
from contextlib import contextmanager
|
||||
from os.path import abspath
|
||||
from os.path import join as pjoin
|
||||
from subprocess import STDOUT, check_call, check_output
|
||||
from typing import TYPE_CHECKING, Any, Iterator, Mapping, Optional, Sequence
|
||||
import warnings
|
||||
|
||||
from ._in_process import _in_proc_script_path
|
||||
|
||||
@@ -35,6 +36,10 @@ def read_json(path: str) -> Mapping[str, Any]:
|
||||
return json.load(f)
|
||||
|
||||
|
||||
class BuildBackendWarning(UserWarning):
|
||||
"""Will be emitted for every UserWarning emitted by the hook process."""
|
||||
|
||||
|
||||
class BackendUnavailable(Exception):
|
||||
"""Will be raised if the backend cannot be imported in the hook process."""
|
||||
|
||||
@@ -48,8 +53,11 @@ class BackendUnavailable(Exception):
|
||||
# Preserving arg order for the sake of API backward compatibility.
|
||||
self.backend_name = backend_name
|
||||
self.backend_path = backend_path
|
||||
self.traceback = traceback
|
||||
super().__init__(message or "Error while importing backend")
|
||||
self.traceback = traceback or ""
|
||||
super().__init__(
|
||||
f"{message or 'Error while importing backend'}"
|
||||
+ (f"\n\nTraceback:\n{self.traceback}" if self.traceback else "")
|
||||
)
|
||||
|
||||
|
||||
class HookMissing(Exception):
|
||||
@@ -74,13 +82,13 @@ def default_subprocess_runner(
|
||||
) -> None:
|
||||
"""The default method of calling the wrapper subprocess.
|
||||
|
||||
This uses :func:`subprocess.check_call` under the hood.
|
||||
This uses :func:`subprocess.run` under the hood.
|
||||
"""
|
||||
env = os.environ.copy()
|
||||
if extra_environ:
|
||||
env.update(extra_environ)
|
||||
|
||||
check_call(cmd, cwd=cwd, env=env)
|
||||
subprocess.run(cmd, cwd=cwd, env=env, check=True)
|
||||
|
||||
|
||||
def quiet_subprocess_runner(
|
||||
@@ -90,13 +98,21 @@ def quiet_subprocess_runner(
|
||||
) -> None:
|
||||
"""Call the subprocess while suppressing output.
|
||||
|
||||
This uses :func:`subprocess.check_output` under the hood.
|
||||
This uses :func:`subprocess.run` with `stdout=PIPE, stderr=STDOUT` under the hood.
|
||||
"""
|
||||
env = os.environ.copy()
|
||||
if extra_environ:
|
||||
env.update(extra_environ)
|
||||
|
||||
check_output(cmd, cwd=cwd, env=env, stderr=STDOUT)
|
||||
# Capturing output in case it fails (available on the exception object)
|
||||
subprocess.run(
|
||||
cmd,
|
||||
cwd=cwd,
|
||||
env=env,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
check=True,
|
||||
)
|
||||
|
||||
|
||||
def norm_and_check(source_tree: str, requested: str) -> str:
|
||||
@@ -112,12 +128,9 @@ def norm_and_check(source_tree: str, requested: str) -> str:
|
||||
|
||||
abs_source = os.path.abspath(source_tree)
|
||||
abs_requested = os.path.normpath(os.path.join(abs_source, requested))
|
||||
# We have to use commonprefix for Python 2.7 compatibility. So we
|
||||
# normalise case to avoid problems because commonprefix is a character
|
||||
# based comparison :-(
|
||||
norm_source = os.path.normcase(abs_source)
|
||||
norm_requested = os.path.normcase(abs_requested)
|
||||
if os.path.commonprefix([norm_source, norm_requested]) != norm_source:
|
||||
if os.path.commonpath([norm_source, norm_requested]) != norm_source:
|
||||
raise ValueError("paths must be inside source tree")
|
||||
|
||||
return abs_requested
|
||||
@@ -162,6 +175,13 @@ class BuildBackendHookCaller:
|
||||
|
||||
:param runner: The new subprocess runner to use within the context.
|
||||
|
||||
.. warning::
|
||||
|
||||
This context manager temporarily mutates the hook caller instance and
|
||||
is not thread-safe. Callers that need to run hooks concurrently
|
||||
should create separate :class:`BuildBackendHookCaller` instances, or
|
||||
provide the subprocess runner when constructing the caller.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
hook_caller = BuildBackendHookCaller(...)
|
||||
@@ -285,7 +305,7 @@ class BuildBackendHookCaller:
|
||||
metadata_directory: str,
|
||||
config_settings: Optional[Mapping[str, Any]] = None,
|
||||
_allow_fallback: bool = True,
|
||||
) -> Optional[str]:
|
||||
) -> str:
|
||||
"""Prepare a ``*.dist-info`` folder with metadata for this project.
|
||||
|
||||
:param metadata_directory: The directory to write the metadata to
|
||||
@@ -365,7 +385,7 @@ class BuildBackendHookCaller:
|
||||
"""Build an sdist from this project.
|
||||
|
||||
:returns:
|
||||
The name of the newly created sdist within ``wheel_directory``.
|
||||
The name of the newly created sdist within ``sdist_directory``.
|
||||
"""
|
||||
return self._call_hook(
|
||||
"build_sdist",
|
||||
@@ -379,8 +399,9 @@ class BuildBackendHookCaller:
|
||||
extra_environ = {"_PYPROJECT_HOOKS_BUILD_BACKEND": self.build_backend}
|
||||
|
||||
if self.backend_path:
|
||||
backend_path = os.pathsep.join(self.backend_path)
|
||||
extra_environ["_PYPROJECT_HOOKS_BACKEND_PATH"] = backend_path
|
||||
extra_environ["_PYPROJECT_HOOKS_BACKEND_PATH_JSON"] = json.dumps(
|
||||
self.backend_path
|
||||
)
|
||||
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
hook_input = {"kwargs": kwargs}
|
||||
@@ -407,4 +428,12 @@ class BuildBackendHookCaller:
|
||||
)
|
||||
if data.get("hook_missing"):
|
||||
raise HookMissing(data.get("missing_hook_name") or hook_name)
|
||||
|
||||
for w in data.get("warnings", []):
|
||||
warnings.warn_explicit(
|
||||
message=w["message"],
|
||||
category=BuildBackendWarning,
|
||||
filename=w["filename"],
|
||||
lineno=w["lineno"],
|
||||
)
|
||||
return data["return_val"]
|
||||
+38
-21
@@ -4,7 +4,7 @@ It expects:
|
||||
- Command line args: hook_name, control_dir
|
||||
- Environment variables:
|
||||
_PYPROJECT_HOOKS_BUILD_BACKEND=entry.point:spec
|
||||
_PYPROJECT_HOOKS_BACKEND_PATH=paths (separated with os.pathsep)
|
||||
_PYPROJECT_HOOKS_BACKEND_PATH_JSON=paths (JSON encoded)
|
||||
- control_dir/input.json:
|
||||
- {"kwargs": {...}}
|
||||
|
||||
@@ -23,6 +23,7 @@ from glob import glob
|
||||
from importlib import import_module
|
||||
from importlib.machinery import PathFinder
|
||||
from os.path import join as pjoin
|
||||
import warnings
|
||||
|
||||
# This file is run as a script, and `import wrappers` is not zip-safe, so we
|
||||
# include write_json() and read_json() from wrappers.py.
|
||||
@@ -57,13 +58,17 @@ class HookMissing(Exception):
|
||||
|
||||
def _build_backend():
|
||||
"""Find and load the build backend"""
|
||||
backend_path = os.environ.get("_PYPROJECT_HOOKS_BACKEND_PATH")
|
||||
backend_path_json = os.environ.get("_PYPROJECT_HOOKS_BACKEND_PATH_JSON")
|
||||
ep = os.environ["_PYPROJECT_HOOKS_BUILD_BACKEND"]
|
||||
mod_path, _, obj_path = ep.partition(":")
|
||||
|
||||
if backend_path:
|
||||
if backend_path_json:
|
||||
extra_pathitems = json.loads(backend_path_json)
|
||||
else:
|
||||
extra_pathitems = []
|
||||
|
||||
if extra_pathitems:
|
||||
# Ensure in-tree backend directories have the highest priority when importing.
|
||||
extra_pathitems = backend_path.split(os.pathsep)
|
||||
sys.meta_path.insert(0, _BackendPathFinder(extra_pathitems, mod_path))
|
||||
|
||||
try:
|
||||
@@ -112,7 +117,8 @@ class _BackendPathFinder:
|
||||
# Delayed import: Python 3.7 does not contain importlib.metadata
|
||||
from importlib.metadata import DistributionFinder, MetadataPathFinder
|
||||
|
||||
context = DistributionFinder.Context(path=self.backend_path)
|
||||
name = context.name if context else None
|
||||
context = DistributionFinder.Context(name=name, path=self.backend_path)
|
||||
return MetadataPathFinder.find_distributions(context=context)
|
||||
|
||||
|
||||
@@ -360,28 +366,39 @@ def main():
|
||||
|
||||
# Remove the parent directory from sys.path to avoid polluting the backend
|
||||
# import namespace with this directory.
|
||||
here = os.path.dirname(__file__)
|
||||
if here in sys.path:
|
||||
sys.path.remove(here)
|
||||
here = os.path.normcase(os.path.realpath(os.path.dirname(__file__)))
|
||||
sys.path[:] = [
|
||||
path for path in sys.path if os.path.normcase(os.path.realpath(path)) != here
|
||||
]
|
||||
|
||||
hook = globals()[hook_name]
|
||||
|
||||
hook_input = read_json(pjoin(control_dir, "input.json"))
|
||||
|
||||
json_out = {"unsupported": False, "return_val": None}
|
||||
try:
|
||||
json_out["return_val"] = hook(**hook_input["kwargs"])
|
||||
except BackendUnavailable as e:
|
||||
json_out["no_backend"] = True
|
||||
json_out["traceback"] = e.traceback
|
||||
json_out["backend_error"] = e.message
|
||||
except GotUnsupportedOperation as e:
|
||||
json_out["unsupported"] = True
|
||||
json_out["traceback"] = e.traceback
|
||||
except HookMissing as e:
|
||||
json_out["hook_missing"] = True
|
||||
json_out["missing_hook_name"] = e.hook_name or hook_name
|
||||
with warnings.catch_warnings(record=True) as captured_warnings:
|
||||
json_out = {"unsupported": False, "return_val": None}
|
||||
try:
|
||||
json_out["return_val"] = hook(**hook_input["kwargs"])
|
||||
except BackendUnavailable as e:
|
||||
json_out["no_backend"] = True
|
||||
json_out["traceback"] = e.traceback
|
||||
json_out["backend_error"] = e.message
|
||||
except GotUnsupportedOperation as e:
|
||||
json_out["unsupported"] = True
|
||||
json_out["traceback"] = e.traceback
|
||||
except HookMissing as e:
|
||||
json_out["hook_missing"] = True
|
||||
json_out["missing_hook_name"] = e.hook_name or hook_name
|
||||
|
||||
json_out["warnings"] = [
|
||||
{
|
||||
"message": str(w.message),
|
||||
"filename": w.filename,
|
||||
"lineno": w.lineno,
|
||||
}
|
||||
for w in captured_warnings
|
||||
if isinstance(w.category, type) and issubclass(w.category, UserWarning)
|
||||
]
|
||||
write_json(json_out, pjoin(control_dir, "output.json"), indent=2)
|
||||
|
||||
|
||||
|
||||
@@ -38,6 +38,8 @@ is at <https://requests.readthedocs.io>.
|
||||
:license: Apache 2.0, see LICENSE for more details.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import warnings
|
||||
|
||||
from pip._vendor import urllib3
|
||||
@@ -48,16 +50,20 @@ charset_normalizer_version = None
|
||||
chardet_version = None
|
||||
|
||||
|
||||
def check_compatibility(urllib3_version, chardet_version, charset_normalizer_version):
|
||||
urllib3_version = urllib3_version.split(".")
|
||||
assert urllib3_version != ["dev"] # Verify urllib3 isn't installed from git.
|
||||
def check_compatibility(
|
||||
urllib3_version: str,
|
||||
chardet_version: str | None,
|
||||
charset_normalizer_version: str | None,
|
||||
) -> None:
|
||||
urllib3_version_list = urllib3_version.split(".")[:3]
|
||||
assert urllib3_version_list != ["dev"] # Verify urllib3 isn't installed from git.
|
||||
|
||||
# Sometimes, urllib3 only reports its version as 16.1.
|
||||
if len(urllib3_version) == 2:
|
||||
urllib3_version.append("0")
|
||||
if len(urllib3_version_list) == 2:
|
||||
urllib3_version_list.append("0")
|
||||
|
||||
# Check urllib3 for compatibility.
|
||||
major, minor, patch = urllib3_version # noqa: F811
|
||||
major, minor, patch = urllib3_version_list # noqa: F811
|
||||
major, minor, patch = int(major), int(minor), int(patch)
|
||||
# urllib3 >= 1.21.1
|
||||
assert major >= 1
|
||||
@@ -68,8 +74,8 @@ def check_compatibility(urllib3_version, chardet_version, charset_normalizer_ver
|
||||
if chardet_version:
|
||||
major, minor, patch = chardet_version.split(".")[:3]
|
||||
major, minor, patch = int(major), int(minor), int(patch)
|
||||
# chardet_version >= 3.0.2, < 6.0.0
|
||||
assert (3, 0, 2) <= (major, minor, patch) < (6, 0, 0)
|
||||
# chardet_version >= 3.0.2, < 8.0.0
|
||||
assert (3, 0, 2) <= (major, minor, patch) < (8, 0, 0)
|
||||
elif charset_normalizer_version:
|
||||
major, minor, patch = charset_normalizer_version.split(".")[:3]
|
||||
major, minor, patch = int(major), int(minor), int(patch)
|
||||
@@ -80,31 +86,30 @@ def check_compatibility(urllib3_version, chardet_version, charset_normalizer_ver
|
||||
pass
|
||||
|
||||
|
||||
def _check_cryptography(cryptography_version):
|
||||
def _check_cryptography(cryptography_version: str) -> None:
|
||||
# cryptography < 1.3.4
|
||||
try:
|
||||
cryptography_version = list(map(int, cryptography_version.split(".")))
|
||||
cryptography_version_list = list(map(int, cryptography_version.split(".")))
|
||||
except ValueError:
|
||||
return
|
||||
|
||||
if cryptography_version < [1, 3, 4]:
|
||||
warning = "Old version of cryptography ({}) may cause slowdown.".format(
|
||||
cryptography_version
|
||||
)
|
||||
if cryptography_version_list < [1, 3, 4]:
|
||||
warning = f"Old version of cryptography ({cryptography_version_list}) may cause slowdown."
|
||||
warnings.warn(warning, RequestsDependencyWarning)
|
||||
|
||||
|
||||
# Check imported dependencies for compatibility.
|
||||
try:
|
||||
check_compatibility(
|
||||
urllib3.__version__, chardet_version, charset_normalizer_version
|
||||
urllib3.__version__, # type: ignore[reportPrivateImportUsage]
|
||||
chardet_version, # type: ignore[reportUnknownArgumentType]
|
||||
charset_normalizer_version,
|
||||
)
|
||||
except (AssertionError, ValueError):
|
||||
warnings.warn(
|
||||
"urllib3 ({}) or chardet ({})/charset_normalizer ({}) doesn't match a supported "
|
||||
"version!".format(
|
||||
urllib3.__version__, chardet_version, charset_normalizer_version
|
||||
),
|
||||
f"urllib3 ({urllib3.__version__}) or chardet " # type: ignore[reportPrivateImportUsage]
|
||||
f"({chardet_version})/charset_normalizer ({charset_normalizer_version}) "
|
||||
"doesn't match a supported version!",
|
||||
RequestsDependencyWarning,
|
||||
)
|
||||
|
||||
@@ -115,7 +120,7 @@ try:
|
||||
# Note: This logic prevents upgrading cryptography on Windows, if imported
|
||||
# as part of pip.
|
||||
from pip._internal.utils.compat import WINDOWS
|
||||
if not WINDOWS:
|
||||
if WINDOWS:
|
||||
raise ImportError("pip internals: don't import cryptography on Windows")
|
||||
try:
|
||||
import ssl
|
||||
@@ -128,9 +133,11 @@ try:
|
||||
pyopenssl.inject_into_urllib3()
|
||||
|
||||
# Check cryptography version
|
||||
from cryptography import __version__ as cryptography_version
|
||||
from cryptography import ( # type: ignore[reportMissingImports]
|
||||
__version__ as cryptography_version, # type: ignore[reportUnknownVariableType]
|
||||
)
|
||||
|
||||
_check_cryptography(cryptography_version)
|
||||
_check_cryptography(cryptography_version) # type: ignore[reportUnknownArgumentType]
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
@@ -173,6 +180,34 @@ from .models import PreparedRequest, Request, Response
|
||||
from .sessions import Session, session
|
||||
from .status_codes import codes
|
||||
|
||||
__all__ = (
|
||||
"ConnectionError",
|
||||
"ConnectTimeout",
|
||||
"HTTPError",
|
||||
"JSONDecodeError",
|
||||
"PreparedRequest",
|
||||
"ReadTimeout",
|
||||
"Request",
|
||||
"RequestException",
|
||||
"Response",
|
||||
"Session",
|
||||
"Timeout",
|
||||
"TooManyRedirects",
|
||||
"URLRequired",
|
||||
"codes",
|
||||
"delete",
|
||||
"get",
|
||||
"head",
|
||||
"options",
|
||||
"packages",
|
||||
"patch",
|
||||
"post",
|
||||
"put",
|
||||
"request",
|
||||
"session",
|
||||
"utils",
|
||||
)
|
||||
|
||||
logging.getLogger(__name__).addHandler(NullHandler())
|
||||
|
||||
# FileModeWarnings go off per the default.
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
__title__ = "requests"
|
||||
__description__ = "Python HTTP for Humans."
|
||||
__url__ = "https://requests.readthedocs.io"
|
||||
__version__ = "2.32.5"
|
||||
__build__ = 0x023205
|
||||
__version__ = "2.34.2"
|
||||
__build__ = 0x023402
|
||||
__author__ = "Kenneth Reitz"
|
||||
__author_email__ = "me@kennethreitz.org"
|
||||
__license__ = "Apache-2.0"
|
||||
|
||||
@@ -5,14 +5,15 @@ requests._internal_utils
|
||||
Provides utility functions that are consumed internally by Requests
|
||||
which depend on extremely few external helpers (such as compat)
|
||||
"""
|
||||
|
||||
import re
|
||||
|
||||
from .compat import builtin_str
|
||||
|
||||
_VALID_HEADER_NAME_RE_BYTE = re.compile(rb"^[^:\s][^:\r\n]*$")
|
||||
_VALID_HEADER_NAME_RE_STR = re.compile(r"^[^:\s][^:\r\n]*$")
|
||||
_VALID_HEADER_VALUE_RE_BYTE = re.compile(rb"^\S[^\r\n]*$|^$")
|
||||
_VALID_HEADER_VALUE_RE_STR = re.compile(r"^\S[^\r\n]*$|^$")
|
||||
_VALID_HEADER_NAME_RE_BYTE = re.compile(rb"^[^:\s][^:\r\n]*\Z")
|
||||
_VALID_HEADER_NAME_RE_STR = re.compile(r"^[^:\s][^:\r\n]*\Z")
|
||||
_VALID_HEADER_VALUE_RE_BYTE = re.compile(rb"^\S[^\r\n]*\Z|^\Z")
|
||||
_VALID_HEADER_VALUE_RE_STR = re.compile(r"^\S[^\r\n]*\Z|^\Z")
|
||||
|
||||
_HEADER_VALIDATORS_STR = (_VALID_HEADER_NAME_RE_STR, _VALID_HEADER_VALUE_RE_STR)
|
||||
_HEADER_VALIDATORS_BYTE = (_VALID_HEADER_NAME_RE_BYTE, _VALID_HEADER_VALUE_RE_BYTE)
|
||||
@@ -22,7 +23,7 @@ HEADER_VALIDATORS = {
|
||||
}
|
||||
|
||||
|
||||
def to_native_string(string, encoding="ascii"):
|
||||
def to_native_string(string: str | bytes, encoding: str = "ascii") -> str:
|
||||
"""Given a string object, regardless of type, returns a representation of
|
||||
that string in the native string type, encoding and decoding where
|
||||
necessary. This assumes ASCII unless told otherwise.
|
||||
@@ -35,7 +36,7 @@ def to_native_string(string, encoding="ascii"):
|
||||
return out
|
||||
|
||||
|
||||
def unicode_is_ascii(u_string):
|
||||
def unicode_is_ascii(u_string: str) -> bool:
|
||||
"""Determine if unicode string only contains ASCII characters.
|
||||
|
||||
:param str u_string: unicode string to check. Must be unicode
|
||||
|
||||
@@ -6,29 +6,34 @@ This module contains the transport adapters that Requests uses to define
|
||||
and maintain connections.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os.path
|
||||
import socket # noqa: F401
|
||||
import socket # noqa: F401 # type: ignore[reportUnusedImport]
|
||||
import typing
|
||||
import warnings
|
||||
from typing import Any
|
||||
|
||||
from pip._vendor.urllib3.exceptions import ClosedPoolError, ConnectTimeoutError
|
||||
from pip._vendor.urllib3.exceptions import HTTPError as _HTTPError
|
||||
from pip._vendor.urllib3.exceptions import InvalidHeader as _InvalidHeader
|
||||
from pip._vendor.urllib3.exceptions import (
|
||||
ClosedPoolError,
|
||||
ConnectTimeoutError,
|
||||
LocationValueError,
|
||||
MaxRetryError,
|
||||
NewConnectionError,
|
||||
ProtocolError,
|
||||
ReadTimeoutError,
|
||||
ResponseError,
|
||||
)
|
||||
from pip._vendor.urllib3.exceptions import HTTPError as _HTTPError
|
||||
from pip._vendor.urllib3.exceptions import InvalidHeader as _InvalidHeader
|
||||
from pip._vendor.urllib3.exceptions import ProxyError as _ProxyError
|
||||
from pip._vendor.urllib3.exceptions import ReadTimeoutError, ResponseError
|
||||
from pip._vendor.urllib3.exceptions import SSLError as _SSLError
|
||||
from pip._vendor.urllib3.poolmanager import PoolManager, proxy_from_url
|
||||
from pip._vendor.urllib3.util import Timeout as TimeoutSauce
|
||||
from pip._vendor.urllib3.util import parse_url
|
||||
from pip._vendor.urllib3.util.retry import Retry
|
||||
|
||||
from .auth import _basic_auth_str
|
||||
from .auth import _basic_auth_str # type: ignore[reportPrivateUsage]
|
||||
from .compat import basestring, urlparse
|
||||
from .cookies import extract_cookies_to_jar
|
||||
from .exceptions import (
|
||||
@@ -47,7 +52,6 @@ from .models import Response
|
||||
from .structures import CaseInsensitiveDict
|
||||
from .utils import (
|
||||
DEFAULT_CA_BUNDLE_PATH,
|
||||
extract_zipped_paths,
|
||||
get_auth_from_url,
|
||||
get_encoding_from_headers,
|
||||
prepend_scheme_if_needed,
|
||||
@@ -56,16 +60,21 @@ from .utils import (
|
||||
)
|
||||
|
||||
try:
|
||||
from pip._vendor.urllib3.contrib.socks import SOCKSProxyManager
|
||||
from pip._vendor.urllib3.contrib.socks import SOCKSProxyManager # type: ignore[assignment]
|
||||
except ImportError:
|
||||
|
||||
def SOCKSProxyManager(*args, **kwargs):
|
||||
def SOCKSProxyManager(*args: Any, **kwargs: Any) -> None:
|
||||
raise InvalidSchema("Missing dependencies for SOCKS support.")
|
||||
|
||||
|
||||
if typing.TYPE_CHECKING:
|
||||
from pip._vendor.urllib3.connectionpool import HTTPConnectionPool
|
||||
from pip._vendor.urllib3.poolmanager import PoolManager as _PoolManager
|
||||
|
||||
from . import _types as _t
|
||||
from .models import PreparedRequest
|
||||
|
||||
from ._types import is_prepared as _is_prepared
|
||||
|
||||
DEFAULT_POOLBLOCK = False
|
||||
DEFAULT_POOLSIZE = 10
|
||||
@@ -74,13 +83,13 @@ DEFAULT_POOL_TIMEOUT = None
|
||||
|
||||
|
||||
def _urllib3_request_context(
|
||||
request: "PreparedRequest",
|
||||
verify: "bool | str | None",
|
||||
client_cert: "typing.Tuple[str, str] | str | None",
|
||||
poolmanager: "PoolManager",
|
||||
) -> "(typing.Dict[str, typing.Any], typing.Dict[str, typing.Any])":
|
||||
host_params = {}
|
||||
pool_kwargs = {}
|
||||
request: PreparedRequest,
|
||||
verify: bool | str | None,
|
||||
client_cert: tuple[str, str] | str | None,
|
||||
poolmanager: PoolManager,
|
||||
) -> tuple[dict[str, Any], dict[str, Any]]:
|
||||
host_params: dict[str, Any] = {}
|
||||
pool_kwargs: dict[str, Any] = {}
|
||||
parsed_request_url = urlparse(request.url)
|
||||
scheme = parsed_request_url.scheme.lower()
|
||||
port = parsed_request_url.port
|
||||
@@ -113,12 +122,18 @@ def _urllib3_request_context(
|
||||
class BaseAdapter:
|
||||
"""The Base Transport Adapter"""
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
def send(
|
||||
self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None
|
||||
):
|
||||
self,
|
||||
request: PreparedRequest,
|
||||
stream: bool = False,
|
||||
timeout: _t.TimeoutType = None,
|
||||
verify: _t.VerifyType = True,
|
||||
cert: _t.CertType = None,
|
||||
proxies: dict[str, str] | None = None,
|
||||
) -> Response:
|
||||
"""Sends PreparedRequest object. Returns Response object.
|
||||
|
||||
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
|
||||
@@ -135,7 +150,7 @@ class BaseAdapter:
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def close(self):
|
||||
def close(self) -> None:
|
||||
"""Cleans up adapter specific items."""
|
||||
raise NotImplementedError
|
||||
|
||||
@@ -167,7 +182,7 @@ class HTTPAdapter(BaseAdapter):
|
||||
>>> s.mount('http://', a)
|
||||
"""
|
||||
|
||||
__attrs__ = [
|
||||
__attrs__: list[str] = [
|
||||
"max_retries",
|
||||
"config",
|
||||
"_pool_connections",
|
||||
@@ -175,13 +190,21 @@ class HTTPAdapter(BaseAdapter):
|
||||
"_pool_block",
|
||||
]
|
||||
|
||||
max_retries: Retry
|
||||
config: dict[str, Any]
|
||||
proxy_manager: dict[str, Any]
|
||||
_pool_connections: int
|
||||
_pool_maxsize: int
|
||||
_pool_block: bool
|
||||
poolmanager: _PoolManager
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
pool_connections=DEFAULT_POOLSIZE,
|
||||
pool_maxsize=DEFAULT_POOLSIZE,
|
||||
max_retries=DEFAULT_RETRIES,
|
||||
pool_block=DEFAULT_POOLBLOCK,
|
||||
):
|
||||
pool_connections: int = DEFAULT_POOLSIZE,
|
||||
pool_maxsize: int = DEFAULT_POOLSIZE,
|
||||
max_retries: int | Retry = DEFAULT_RETRIES,
|
||||
pool_block: bool = DEFAULT_POOLBLOCK,
|
||||
) -> None:
|
||||
if max_retries == DEFAULT_RETRIES:
|
||||
self.max_retries = Retry(0, read=False)
|
||||
else:
|
||||
@@ -197,10 +220,10 @@ class HTTPAdapter(BaseAdapter):
|
||||
|
||||
self.init_poolmanager(pool_connections, pool_maxsize, block=pool_block)
|
||||
|
||||
def __getstate__(self):
|
||||
def __getstate__(self) -> dict[str, Any]:
|
||||
return {attr: getattr(self, attr, None) for attr in self.__attrs__}
|
||||
|
||||
def __setstate__(self, state):
|
||||
def __setstate__(self, state: dict[str, Any]) -> None:
|
||||
# Can't handle by adding 'proxy_manager' to self.__attrs__ because
|
||||
# self.poolmanager uses a lambda function, which isn't pickleable.
|
||||
self.proxy_manager = {}
|
||||
@@ -214,8 +237,12 @@ class HTTPAdapter(BaseAdapter):
|
||||
)
|
||||
|
||||
def init_poolmanager(
|
||||
self, connections, maxsize, block=DEFAULT_POOLBLOCK, **pool_kwargs
|
||||
):
|
||||
self,
|
||||
connections: int,
|
||||
maxsize: int,
|
||||
block: bool = DEFAULT_POOLBLOCK,
|
||||
**pool_kwargs: Any,
|
||||
) -> None:
|
||||
"""Initializes a urllib3 PoolManager.
|
||||
|
||||
This method should not be called from user code, and is only
|
||||
@@ -239,7 +266,7 @@ class HTTPAdapter(BaseAdapter):
|
||||
**pool_kwargs,
|
||||
)
|
||||
|
||||
def proxy_manager_for(self, proxy, **proxy_kwargs):
|
||||
def proxy_manager_for(self, proxy: str, **proxy_kwargs: Any) -> Any:
|
||||
"""Return urllib3 ProxyManager for the given proxy.
|
||||
|
||||
This method should not be called from user code, and is only
|
||||
@@ -277,7 +304,9 @@ class HTTPAdapter(BaseAdapter):
|
||||
|
||||
return manager
|
||||
|
||||
def cert_verify(self, conn, url, verify, cert):
|
||||
def cert_verify(
|
||||
self, conn: Any, url: str, verify: _t.VerifyType, cert: _t.CertType
|
||||
) -> None:
|
||||
"""Verify a SSL certificate. This method should not be called from user
|
||||
code, and is only exposed for use when subclassing the
|
||||
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
|
||||
@@ -297,7 +326,7 @@ class HTTPAdapter(BaseAdapter):
|
||||
cert_loc = verify
|
||||
|
||||
if not cert_loc:
|
||||
cert_loc = extract_zipped_paths(DEFAULT_CA_BUNDLE_PATH)
|
||||
cert_loc = DEFAULT_CA_BUNDLE_PATH
|
||||
|
||||
if not cert_loc or not os.path.exists(cert_loc):
|
||||
raise OSError(
|
||||
@@ -333,7 +362,7 @@ class HTTPAdapter(BaseAdapter):
|
||||
f"Could not find the TLS key file, invalid path: {conn.key_file}"
|
||||
)
|
||||
|
||||
def build_response(self, req, resp):
|
||||
def build_response(self, req: PreparedRequest, resp: Any) -> Response:
|
||||
"""Builds a :class:`Response <requests.Response>` object from a urllib3
|
||||
response. This should not be called from user code, and is only exposed
|
||||
for use when subclassing the
|
||||
@@ -343,10 +372,11 @@ class HTTPAdapter(BaseAdapter):
|
||||
:param resp: The urllib3 response object.
|
||||
:rtype: requests.Response
|
||||
"""
|
||||
assert _is_prepared(req)
|
||||
response = Response()
|
||||
|
||||
# Fallback to None if there's no status_code, for whatever reason.
|
||||
response.status_code = getattr(resp, "status", None)
|
||||
response.status_code = getattr(resp, "status", None) # type: ignore[assignment]
|
||||
|
||||
# Make headers case-insensitive.
|
||||
response.headers = CaseInsensitiveDict(getattr(resp, "headers", {}))
|
||||
@@ -370,7 +400,9 @@ class HTTPAdapter(BaseAdapter):
|
||||
|
||||
return response
|
||||
|
||||
def build_connection_pool_key_attributes(self, request, verify, cert=None):
|
||||
def build_connection_pool_key_attributes(
|
||||
self, request: PreparedRequest, verify: _t.VerifyType, cert: _t.CertType = None
|
||||
) -> tuple[dict[str, Any], dict[str, Any]]:
|
||||
"""Build the PoolKey attributes used by urllib3 to return a connection.
|
||||
|
||||
This looks at the PreparedRequest, the user-specified verify value,
|
||||
@@ -400,7 +432,7 @@ class HTTPAdapter(BaseAdapter):
|
||||
alter the other keys to ensure the desired behaviour.
|
||||
|
||||
:param request:
|
||||
The PreparedReqest being sent over the connection.
|
||||
The PreparedRequest being sent over the connection.
|
||||
:type request:
|
||||
:class:`~requests.models.PreparedRequest`
|
||||
:param verify:
|
||||
@@ -420,7 +452,13 @@ class HTTPAdapter(BaseAdapter):
|
||||
"""
|
||||
return _urllib3_request_context(request, verify, cert, self.poolmanager)
|
||||
|
||||
def get_connection_with_tls_context(self, request, verify, proxies=None, cert=None):
|
||||
def get_connection_with_tls_context(
|
||||
self,
|
||||
request: PreparedRequest,
|
||||
verify: _t.VerifyType,
|
||||
proxies: dict[str, str] | None = None,
|
||||
cert: _t.CertType = None,
|
||||
) -> HTTPConnectionPool:
|
||||
"""Returns a urllib3 connection for the given request and TLS settings.
|
||||
This should not be called from user code, and is only exposed for use
|
||||
when subclassing the :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
|
||||
@@ -438,8 +476,10 @@ class HTTPAdapter(BaseAdapter):
|
||||
(optional) Any user-provided SSL certificate to be used for client
|
||||
authentication (a.k.a., mTLS).
|
||||
:rtype:
|
||||
urllib3.ConnectionPool
|
||||
urllib3.HTTPConnectionPool
|
||||
"""
|
||||
assert _is_prepared(request)
|
||||
|
||||
proxy = select_proxy(request.url, proxies)
|
||||
try:
|
||||
host_params, pool_kwargs = self.build_connection_pool_key_attributes(
|
||||
@@ -469,7 +509,9 @@ class HTTPAdapter(BaseAdapter):
|
||||
|
||||
return conn
|
||||
|
||||
def get_connection(self, url, proxies=None):
|
||||
def get_connection(
|
||||
self, url: str, proxies: dict[str, str] | None = None
|
||||
) -> HTTPConnectionPool:
|
||||
"""DEPRECATED: Users should move to `get_connection_with_tls_context`
|
||||
for all subclasses of HTTPAdapter using Requests>=2.32.2.
|
||||
|
||||
@@ -479,7 +521,7 @@ class HTTPAdapter(BaseAdapter):
|
||||
|
||||
:param url: The URL to connect to.
|
||||
:param proxies: (optional) A Requests-style dictionary of proxies used on this request.
|
||||
:rtype: urllib3.ConnectionPool
|
||||
:rtype: urllib3.HTTPConnectionPool
|
||||
"""
|
||||
warnings.warn(
|
||||
(
|
||||
@@ -510,7 +552,7 @@ class HTTPAdapter(BaseAdapter):
|
||||
|
||||
return conn
|
||||
|
||||
def close(self):
|
||||
def close(self) -> None:
|
||||
"""Disposes of any internal state.
|
||||
|
||||
Currently, this closes the PoolManager and any active ProxyManager,
|
||||
@@ -520,7 +562,9 @@ class HTTPAdapter(BaseAdapter):
|
||||
for proxy in self.proxy_manager.values():
|
||||
proxy.clear()
|
||||
|
||||
def request_url(self, request, proxies):
|
||||
def request_url(
|
||||
self, request: PreparedRequest, proxies: dict[str, str] | None
|
||||
) -> str:
|
||||
"""Obtain the url to use when making the final request.
|
||||
|
||||
If the message is being sent through a HTTP proxy, the full URL has to
|
||||
@@ -534,6 +578,8 @@ class HTTPAdapter(BaseAdapter):
|
||||
:param proxies: A dictionary of schemes or schemes and hosts to proxy URLs.
|
||||
:rtype: str
|
||||
"""
|
||||
assert _is_prepared(request)
|
||||
|
||||
proxy = select_proxy(request.url, proxies)
|
||||
scheme = urlparse(request.url).scheme
|
||||
|
||||
@@ -544,15 +590,13 @@ class HTTPAdapter(BaseAdapter):
|
||||
using_socks_proxy = proxy_scheme.startswith("socks")
|
||||
|
||||
url = request.path_url
|
||||
if url.startswith("//"): # Don't confuse urllib3
|
||||
url = f"/{url.lstrip('/')}"
|
||||
|
||||
if is_proxied_http_request and not using_socks_proxy:
|
||||
url = urldefragauth(request.url)
|
||||
|
||||
return url
|
||||
|
||||
def add_headers(self, request, **kwargs):
|
||||
def add_headers(self, request: PreparedRequest, **kwargs: Any) -> None:
|
||||
"""Add any headers needed by the connection. As of v2.0 this does
|
||||
nothing by default, but is left for overriding by users that subclass
|
||||
the :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
|
||||
@@ -566,7 +610,7 @@ class HTTPAdapter(BaseAdapter):
|
||||
"""
|
||||
pass
|
||||
|
||||
def proxy_headers(self, proxy):
|
||||
def proxy_headers(self, proxy: str) -> dict[str, str]:
|
||||
"""Returns a dictionary of the headers to add to any request sent
|
||||
through a proxy. This works with urllib3 magic to ensure that they are
|
||||
correctly sent to the proxy, rather than in a tunnelled request if
|
||||
@@ -579,7 +623,7 @@ class HTTPAdapter(BaseAdapter):
|
||||
:param proxy: The url of the proxy being used for this request.
|
||||
:rtype: dict
|
||||
"""
|
||||
headers = {}
|
||||
headers: dict[str, str] = {}
|
||||
username, password = get_auth_from_url(proxy)
|
||||
|
||||
if username:
|
||||
@@ -588,8 +632,14 @@ class HTTPAdapter(BaseAdapter):
|
||||
return headers
|
||||
|
||||
def send(
|
||||
self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None
|
||||
):
|
||||
self,
|
||||
request: PreparedRequest,
|
||||
stream: bool = False,
|
||||
timeout: _t.TimeoutType = None,
|
||||
verify: _t.VerifyType = True,
|
||||
cert: _t.CertType = None,
|
||||
proxies: dict[str, str] | None = None,
|
||||
) -> Response:
|
||||
"""Sends PreparedRequest object. Returns Response object.
|
||||
|
||||
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
|
||||
@@ -606,6 +656,8 @@ class HTTPAdapter(BaseAdapter):
|
||||
:rtype: requests.Response
|
||||
"""
|
||||
|
||||
assert _is_prepared(request)
|
||||
|
||||
try:
|
||||
conn = self.get_connection_with_tls_context(
|
||||
request, verify, proxies=proxies, cert=cert
|
||||
@@ -629,29 +681,29 @@ class HTTPAdapter(BaseAdapter):
|
||||
if isinstance(timeout, tuple):
|
||||
try:
|
||||
connect, read = timeout
|
||||
timeout = TimeoutSauce(connect=connect, read=read)
|
||||
resolved_timeout = TimeoutSauce(connect=connect, read=read)
|
||||
except ValueError:
|
||||
raise ValueError(
|
||||
f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, "
|
||||
f"or a single float to set both timeouts to the same value."
|
||||
)
|
||||
elif isinstance(timeout, TimeoutSauce):
|
||||
pass
|
||||
resolved_timeout = timeout
|
||||
else:
|
||||
timeout = TimeoutSauce(connect=timeout, read=timeout)
|
||||
resolved_timeout = TimeoutSauce(connect=timeout, read=timeout)
|
||||
|
||||
try:
|
||||
resp = conn.urlopen(
|
||||
method=request.method,
|
||||
url=url,
|
||||
body=request.body,
|
||||
headers=request.headers,
|
||||
body=request.body, # type: ignore[arg-type] # urllib3 stubs don't accept Iterable[bytes | str]
|
||||
headers=request.headers, # type: ignore[arg-type] # urllib3#3072
|
||||
redirect=False,
|
||||
assert_same_host=False,
|
||||
preload_content=False,
|
||||
decode_content=False,
|
||||
retries=self.max_retries,
|
||||
timeout=timeout,
|
||||
timeout=resolved_timeout,
|
||||
chunked=chunked,
|
||||
)
|
||||
|
||||
|
||||
@@ -8,10 +8,22 @@ This module implements the Requests API.
|
||||
:license: Apache2, see LICENSE for more details.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from . import sessions
|
||||
from .models import Response
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing_extensions import Unpack
|
||||
|
||||
from . import _types as _t
|
||||
|
||||
|
||||
def request(method, url, **kwargs):
|
||||
def request(
|
||||
method: str, url: _t.UriType, **kwargs: Unpack[_t.RequestKwargs]
|
||||
) -> Response:
|
||||
"""Constructs and sends a :class:`Request <Request>`.
|
||||
|
||||
:param method: method for the new :class:`Request` object: ``GET``, ``OPTIONS``, ``HEAD``, ``POST``, ``PUT``, ``PATCH``, or ``DELETE``.
|
||||
@@ -59,7 +71,9 @@ def request(method, url, **kwargs):
|
||||
return session.request(method=method, url=url, **kwargs)
|
||||
|
||||
|
||||
def get(url, params=None, **kwargs):
|
||||
def get(
|
||||
url: _t.UriType, params: _t.ParamsType = None, **kwargs: Unpack[_t.GetKwargs]
|
||||
) -> Response:
|
||||
r"""Sends a GET request.
|
||||
|
||||
:param url: URL for the new :class:`Request` object.
|
||||
@@ -73,7 +87,7 @@ def get(url, params=None, **kwargs):
|
||||
return request("get", url, params=params, **kwargs)
|
||||
|
||||
|
||||
def options(url, **kwargs):
|
||||
def options(url: _t.UriType, **kwargs: Unpack[_t.RequestKwargs]) -> Response:
|
||||
r"""Sends an OPTIONS request.
|
||||
|
||||
:param url: URL for the new :class:`Request` object.
|
||||
@@ -85,7 +99,7 @@ def options(url, **kwargs):
|
||||
return request("options", url, **kwargs)
|
||||
|
||||
|
||||
def head(url, **kwargs):
|
||||
def head(url: _t.UriType, **kwargs: Unpack[_t.RequestKwargs]) -> Response:
|
||||
r"""Sends a HEAD request.
|
||||
|
||||
:param url: URL for the new :class:`Request` object.
|
||||
@@ -100,7 +114,12 @@ def head(url, **kwargs):
|
||||
return request("head", url, **kwargs)
|
||||
|
||||
|
||||
def post(url, data=None, json=None, **kwargs):
|
||||
def post(
|
||||
url: _t.UriType,
|
||||
data: _t.DataType = None,
|
||||
json: _t.JsonType = None,
|
||||
**kwargs: Unpack[_t.PostKwargs],
|
||||
) -> Response:
|
||||
r"""Sends a POST request.
|
||||
|
||||
:param url: URL for the new :class:`Request` object.
|
||||
@@ -115,7 +134,9 @@ def post(url, data=None, json=None, **kwargs):
|
||||
return request("post", url, data=data, json=json, **kwargs)
|
||||
|
||||
|
||||
def put(url, data=None, **kwargs):
|
||||
def put(
|
||||
url: _t.UriType, data: _t.DataType = None, **kwargs: Unpack[_t.DataKwargs]
|
||||
) -> Response:
|
||||
r"""Sends a PUT request.
|
||||
|
||||
:param url: URL for the new :class:`Request` object.
|
||||
@@ -130,7 +151,9 @@ def put(url, data=None, **kwargs):
|
||||
return request("put", url, data=data, **kwargs)
|
||||
|
||||
|
||||
def patch(url, data=None, **kwargs):
|
||||
def patch(
|
||||
url: _t.UriType, data: _t.DataType = None, **kwargs: Unpack[_t.DataKwargs]
|
||||
) -> Response:
|
||||
r"""Sends a PATCH request.
|
||||
|
||||
:param url: URL for the new :class:`Request` object.
|
||||
@@ -145,7 +168,7 @@ def patch(url, data=None, **kwargs):
|
||||
return request("patch", url, data=data, **kwargs)
|
||||
|
||||
|
||||
def delete(url, **kwargs):
|
||||
def delete(url: _t.UriType, **kwargs: Unpack[_t.RequestKwargs]) -> Response:
|
||||
r"""Sends a DELETE request.
|
||||
|
||||
:param url: URL for the new :class:`Request` object.
|
||||
|
||||
@@ -5,6 +5,8 @@ requests.auth
|
||||
This module contains the authentication handlers for Requests.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
import os
|
||||
import re
|
||||
@@ -12,17 +14,24 @@ import threading
|
||||
import time
|
||||
import warnings
|
||||
from base64 import b64encode
|
||||
from typing import TYPE_CHECKING, Any, Final, cast, overload
|
||||
|
||||
from ._internal_utils import to_native_string
|
||||
from .compat import basestring, str, urlparse
|
||||
from .cookies import extract_cookies_to_jar
|
||||
from .utils import parse_dict_header
|
||||
|
||||
CONTENT_TYPE_FORM_URLENCODED = "application/x-www-form-urlencoded"
|
||||
CONTENT_TYPE_MULTI_PART = "multipart/form-data"
|
||||
if TYPE_CHECKING:
|
||||
from http.cookiejar import CookieJar
|
||||
from typing import Any
|
||||
|
||||
from .models import PreparedRequest, Response
|
||||
|
||||
CONTENT_TYPE_FORM_URLENCODED: Final = "application/x-www-form-urlencoded"
|
||||
CONTENT_TYPE_MULTI_PART: Final = "multipart/form-data"
|
||||
|
||||
|
||||
def _basic_auth_str(username, password):
|
||||
def _basic_auth_str(username: bytes | str, password: bytes | str) -> str:
|
||||
"""Returns a Basic Auth string."""
|
||||
|
||||
# "I want us to put a big-ol' comment on top of it that
|
||||
@@ -32,22 +41,22 @@ def _basic_auth_str(username, password):
|
||||
#
|
||||
# These are here solely to maintain backwards compatibility
|
||||
# for things like ints. This will be removed in 3.0.0.
|
||||
if not isinstance(username, basestring):
|
||||
if not isinstance(username, basestring): # type: ignore[reportUnnecessaryIsInstance] # runtime guard for non-str/bytes
|
||||
warnings.warn(
|
||||
"Non-string usernames will no longer be supported in Requests "
|
||||
"3.0.0. Please convert the object you've passed in ({!r}) to "
|
||||
f"3.0.0. Please convert the object you've passed in ({username!r}) to "
|
||||
"a string or bytes object in the near future to avoid "
|
||||
"problems.".format(username),
|
||||
"problems.",
|
||||
category=DeprecationWarning,
|
||||
)
|
||||
username = str(username)
|
||||
|
||||
if not isinstance(password, basestring):
|
||||
if not isinstance(password, basestring): # type: ignore[reportUnnecessaryIsInstance] # runtime guard for non-str/bytes
|
||||
warnings.warn(
|
||||
"Non-string passwords will no longer be supported in Requests "
|
||||
"3.0.0. Please convert the object you've passed in ({!r}) to "
|
||||
f"3.0.0. Please convert the object you've passed in ({type(password)!r}) to "
|
||||
"a string or bytes object in the near future to avoid "
|
||||
"problems.".format(type(password)),
|
||||
"problems.",
|
||||
category=DeprecationWarning,
|
||||
)
|
||||
password = str(password)
|
||||
@@ -69,18 +78,26 @@ def _basic_auth_str(username, password):
|
||||
class AuthBase:
|
||||
"""Base class that all auth implementations derive from"""
|
||||
|
||||
def __call__(self, r):
|
||||
def __call__(self, r: PreparedRequest) -> PreparedRequest:
|
||||
raise NotImplementedError("Auth hooks must be callable.")
|
||||
|
||||
|
||||
class HTTPBasicAuth(AuthBase):
|
||||
"""Attaches HTTP Basic Authentication to the given Request object."""
|
||||
|
||||
def __init__(self, username, password):
|
||||
username: bytes | str
|
||||
password: bytes | str
|
||||
|
||||
@overload
|
||||
def __init__(self, username: str, password: str) -> None: ...
|
||||
@overload
|
||||
def __init__(self, username: bytes, password: bytes) -> None: ...
|
||||
|
||||
def __init__(self, username: bytes | str, password: bytes | str) -> None:
|
||||
self.username = username
|
||||
self.password = password
|
||||
|
||||
def __eq__(self, other):
|
||||
def __eq__(self, other: object) -> bool:
|
||||
return all(
|
||||
[
|
||||
self.username == getattr(other, "username", None),
|
||||
@@ -88,10 +105,10 @@ class HTTPBasicAuth(AuthBase):
|
||||
]
|
||||
)
|
||||
|
||||
def __ne__(self, other):
|
||||
def __ne__(self, other: Any) -> bool:
|
||||
return not self == other
|
||||
|
||||
def __call__(self, r):
|
||||
def __call__(self, r: PreparedRequest) -> PreparedRequest:
|
||||
r.headers["Authorization"] = _basic_auth_str(self.username, self.password)
|
||||
return r
|
||||
|
||||
@@ -99,7 +116,7 @@ class HTTPBasicAuth(AuthBase):
|
||||
class HTTPProxyAuth(HTTPBasicAuth):
|
||||
"""Attaches HTTP Proxy Authentication to a given Request object."""
|
||||
|
||||
def __call__(self, r):
|
||||
def __call__(self, r: PreparedRequest) -> PreparedRequest:
|
||||
r.headers["Proxy-Authorization"] = _basic_auth_str(self.username, self.password)
|
||||
return r
|
||||
|
||||
@@ -107,13 +124,27 @@ class HTTPProxyAuth(HTTPBasicAuth):
|
||||
class HTTPDigestAuth(AuthBase):
|
||||
"""Attaches HTTP Digest Authentication to the given Request object."""
|
||||
|
||||
def __init__(self, username, password):
|
||||
username: bytes | str
|
||||
password: bytes | str
|
||||
_thread_local: threading.local
|
||||
last_nonce: str
|
||||
nonce_count: int
|
||||
chal: dict[str, str]
|
||||
pos: int | None
|
||||
num_401_calls: int | None
|
||||
|
||||
@overload
|
||||
def __init__(self, username: str, password: str) -> None: ...
|
||||
@overload
|
||||
def __init__(self, username: bytes, password: bytes) -> None: ...
|
||||
|
||||
def __init__(self, username: bytes | str, password: bytes | str) -> None:
|
||||
self.username = username
|
||||
self.password = password
|
||||
# Keep state in per-thread local storage
|
||||
self._thread_local = threading.local()
|
||||
|
||||
def init_per_thread_state(self):
|
||||
def init_per_thread_state(self) -> None:
|
||||
# Ensure state is initialized just once per-thread
|
||||
if not hasattr(self._thread_local, "init"):
|
||||
self._thread_local.init = True
|
||||
@@ -123,7 +154,7 @@ class HTTPDigestAuth(AuthBase):
|
||||
self._thread_local.pos = None
|
||||
self._thread_local.num_401_calls = None
|
||||
|
||||
def build_digest_header(self, method, url):
|
||||
def build_digest_header(self, method: str, url: str) -> str | None:
|
||||
"""
|
||||
:rtype: str
|
||||
"""
|
||||
@@ -142,42 +173,43 @@ class HTTPDigestAuth(AuthBase):
|
||||
# lambdas assume digest modules are imported at the top level
|
||||
if _algorithm == "MD5" or _algorithm == "MD5-SESS":
|
||||
|
||||
def md5_utf8(x):
|
||||
def md5_utf8(x: str | bytes) -> str:
|
||||
if isinstance(x, str):
|
||||
x = x.encode("utf-8")
|
||||
return hashlib.md5(x).hexdigest()
|
||||
return hashlib.md5(x, usedforsecurity=False).hexdigest()
|
||||
|
||||
hash_utf8 = md5_utf8
|
||||
elif _algorithm == "SHA":
|
||||
|
||||
def sha_utf8(x):
|
||||
def sha_utf8(x: str | bytes) -> str:
|
||||
if isinstance(x, str):
|
||||
x = x.encode("utf-8")
|
||||
return hashlib.sha1(x).hexdigest()
|
||||
return hashlib.sha1(x, usedforsecurity=False).hexdigest()
|
||||
|
||||
hash_utf8 = sha_utf8
|
||||
elif _algorithm == "SHA-256":
|
||||
|
||||
def sha256_utf8(x):
|
||||
def sha256_utf8(x: str | bytes) -> str:
|
||||
if isinstance(x, str):
|
||||
x = x.encode("utf-8")
|
||||
return hashlib.sha256(x).hexdigest()
|
||||
return hashlib.sha256(x, usedforsecurity=False).hexdigest()
|
||||
|
||||
hash_utf8 = sha256_utf8
|
||||
elif _algorithm == "SHA-512":
|
||||
|
||||
def sha512_utf8(x):
|
||||
def sha512_utf8(x: str | bytes) -> str:
|
||||
if isinstance(x, str):
|
||||
x = x.encode("utf-8")
|
||||
return hashlib.sha512(x).hexdigest()
|
||||
return hashlib.sha512(x, usedforsecurity=False).hexdigest()
|
||||
|
||||
hash_utf8 = sha512_utf8
|
||||
|
||||
KD = lambda s, d: hash_utf8(f"{s}:{d}") # noqa:E731
|
||||
|
||||
if hash_utf8 is None:
|
||||
return None
|
||||
|
||||
def KD(s: str, d: str) -> str:
|
||||
return hash_utf8(f"{s}:{d}")
|
||||
|
||||
# XXX not implemented yet
|
||||
entdig = None
|
||||
p_parsed = urlparse(url)
|
||||
@@ -202,9 +234,9 @@ class HTTPDigestAuth(AuthBase):
|
||||
s += time.ctime().encode("utf-8")
|
||||
s += os.urandom(8)
|
||||
|
||||
cnonce = hashlib.sha1(s).hexdigest()[:16]
|
||||
cnonce = hashlib.sha1(s, usedforsecurity=False).hexdigest()[:16]
|
||||
if _algorithm == "MD5-SESS":
|
||||
HA1 = hash_utf8(f"{HA1}:{nonce}:{cnonce}")
|
||||
HA1 = hash_utf8(f"{HA1}:{nonce}:{cnonce}") # type: ignore[reportConstantRedefinition] # RFC 2617 terminology
|
||||
|
||||
if not qop:
|
||||
respdig = KD(HA1, f"{nonce}:{HA2}")
|
||||
@@ -233,12 +265,12 @@ class HTTPDigestAuth(AuthBase):
|
||||
|
||||
return f"Digest {base}"
|
||||
|
||||
def handle_redirect(self, r, **kwargs):
|
||||
def handle_redirect(self, r: Response, **kwargs: Any) -> None:
|
||||
"""Reset num_401_calls counter on redirects."""
|
||||
if r.is_redirect:
|
||||
self._thread_local.num_401_calls = 1
|
||||
|
||||
def handle_401(self, r, **kwargs):
|
||||
def handle_401(self, r: Response, **kwargs: Any) -> Response:
|
||||
"""
|
||||
Takes the given response and tries digest-auth, if needed.
|
||||
|
||||
@@ -254,7 +286,8 @@ class HTTPDigestAuth(AuthBase):
|
||||
if self._thread_local.pos is not None:
|
||||
# Rewind the file position indicator of the body to where
|
||||
# it was to resend the request.
|
||||
r.request.body.seek(self._thread_local.pos)
|
||||
if (seek := getattr(r.request.body, "seek", None)) is not None:
|
||||
seek(self._thread_local.pos)
|
||||
s_auth = r.headers.get("www-authenticate", "")
|
||||
|
||||
if "digest" in s_auth.lower() and self._thread_local.num_401_calls < 2:
|
||||
@@ -267,12 +300,15 @@ class HTTPDigestAuth(AuthBase):
|
||||
r.content
|
||||
r.close()
|
||||
prep = r.request.copy()
|
||||
extract_cookies_to_jar(prep._cookies, r.request, r.raw)
|
||||
prep.prepare_cookies(prep._cookies)
|
||||
cookie_jar = cast("CookieJar", prep._cookies) # type: ignore[reportPrivateUsage]
|
||||
extract_cookies_to_jar(cookie_jar, r.request, r.raw)
|
||||
prep.prepare_cookies(cookie_jar)
|
||||
|
||||
prep.headers["Authorization"] = self.build_digest_header(
|
||||
prep.method, prep.url
|
||||
_digest_auth = self.build_digest_header(
|
||||
cast(str, prep.method), cast(str, prep.url)
|
||||
)
|
||||
if _digest_auth:
|
||||
prep.headers["Authorization"] = _digest_auth
|
||||
_r = r.connection.send(prep, **kwargs)
|
||||
_r.history.append(r)
|
||||
_r.request = prep
|
||||
@@ -282,15 +318,19 @@ class HTTPDigestAuth(AuthBase):
|
||||
self._thread_local.num_401_calls = 1
|
||||
return r
|
||||
|
||||
def __call__(self, r):
|
||||
def __call__(self, r: PreparedRequest) -> PreparedRequest:
|
||||
# Initialize per-thread state, if needed
|
||||
self.init_per_thread_state()
|
||||
# If we have a saved nonce, skip the 401
|
||||
if self._thread_local.last_nonce:
|
||||
r.headers["Authorization"] = self.build_digest_header(r.method, r.url)
|
||||
try:
|
||||
self._thread_local.pos = r.body.tell()
|
||||
except AttributeError:
|
||||
_digest_auth = self.build_digest_header(
|
||||
cast(str, r.method), cast(str, r.url)
|
||||
)
|
||||
if _digest_auth:
|
||||
r.headers["Authorization"] = _digest_auth
|
||||
if (tell := getattr(r.body, "tell", None)) is not None:
|
||||
self._thread_local.pos = tell()
|
||||
else:
|
||||
# In the case of HTTPDigestAuth being reused and the body of
|
||||
# the previous request was a file-like object, pos has the
|
||||
# file position of the previous body. Ensure it's set to
|
||||
@@ -302,7 +342,7 @@ class HTTPDigestAuth(AuthBase):
|
||||
|
||||
return r
|
||||
|
||||
def __eq__(self, other):
|
||||
def __eq__(self, other: object) -> bool:
|
||||
return all(
|
||||
[
|
||||
self.username == getattr(other, "username", None),
|
||||
@@ -310,5 +350,5 @@ class HTTPDigestAuth(AuthBase):
|
||||
]
|
||||
)
|
||||
|
||||
def __ne__(self, other):
|
||||
def __ne__(self, other: Any) -> bool:
|
||||
return not self == other
|
||||
@@ -11,6 +11,7 @@ If you are packaging Requests, e.g., for a Linux distribution or a managed
|
||||
environment, you can change the definition of where() to return a separately
|
||||
packaged CA bundle.
|
||||
"""
|
||||
|
||||
from pip._vendor.certifi import where
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -7,12 +7,18 @@ between Python 2 and Python 3. It remains for backwards
|
||||
compatibility until the next major version.
|
||||
"""
|
||||
|
||||
# pyright: reportUnusedImport=false
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
|
||||
# -------
|
||||
# urllib3
|
||||
# -------
|
||||
from pip._vendor.urllib3 import __version__ as urllib3_version
|
||||
from pip._vendor.urllib3 import (
|
||||
__version__ as urllib3_version, # type: ignore[reportPrivateImportUsage]
|
||||
)
|
||||
|
||||
# Detect which major version of urllib3 is being used.
|
||||
try:
|
||||
@@ -26,7 +32,7 @@ except (TypeError, AttributeError):
|
||||
# -------------------
|
||||
|
||||
|
||||
def _resolve_char_detection():
|
||||
def _resolve_char_detection() -> None:
|
||||
"""Find supported character detection libraries."""
|
||||
chardet = None
|
||||
return chardet
|
||||
@@ -79,7 +85,7 @@ from urllib.request import (
|
||||
getproxies_environment,
|
||||
parse_http_list,
|
||||
proxy_bypass,
|
||||
proxy_bypass_environment,
|
||||
proxy_bypass_environment, # type: ignore[attr-defined] # https://github.com/python/cpython/issues/145331
|
||||
)
|
||||
|
||||
builtin_str = str
|
||||
|
||||
@@ -7,21 +7,29 @@ Compatibility code to be able to use `http.cookiejar.CookieJar` with requests.
|
||||
requests.utils imports from here, so be careful with imports.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import calendar
|
||||
import copy
|
||||
import time
|
||||
from collections.abc import Iterator, MutableMapping
|
||||
from http.cookiejar import Cookie, CookieJar, CookiePolicy
|
||||
from typing import TYPE_CHECKING, Any, TypeVar, overload
|
||||
|
||||
from ._internal_utils import to_native_string
|
||||
from .compat import Morsel, MutableMapping, cookielib, urlparse, urlunparse
|
||||
from ._types import is_prepared as _is_prepared
|
||||
from .compat import Morsel, cookielib, urlparse, urlunparse
|
||||
|
||||
try:
|
||||
import threading
|
||||
except ImportError:
|
||||
import dummy_threading as threading
|
||||
if TYPE_CHECKING:
|
||||
from _typeshed import SupportsKeysAndGetItem
|
||||
|
||||
from .models import PreparedRequest
|
||||
|
||||
import threading
|
||||
|
||||
|
||||
class MockRequest:
|
||||
"""Wraps a `requests.Request` to mimic a `urllib2.Request`.
|
||||
"""Wraps a `requests.PreparedRequest` to mimic a `urllib2.Request`.
|
||||
|
||||
The code in `http.cookiejar.CookieJar` expects this interface in order to correctly
|
||||
manage cookie policies, i.e., determine whether a cookie can be set, given the
|
||||
@@ -32,21 +40,24 @@ class MockRequest:
|
||||
probably want `get_cookie_header`, defined below.
|
||||
"""
|
||||
|
||||
def __init__(self, request):
|
||||
type: str
|
||||
|
||||
def __init__(self, request: PreparedRequest) -> None:
|
||||
assert _is_prepared(request)
|
||||
self._r = request
|
||||
self._new_headers = {}
|
||||
self._new_headers: dict[str, str] = {}
|
||||
self.type = urlparse(self._r.url).scheme
|
||||
|
||||
def get_type(self):
|
||||
def get_type(self) -> str:
|
||||
return self.type
|
||||
|
||||
def get_host(self):
|
||||
def get_host(self) -> str:
|
||||
return urlparse(self._r.url).netloc
|
||||
|
||||
def get_origin_req_host(self):
|
||||
def get_origin_req_host(self) -> str:
|
||||
return self.get_host()
|
||||
|
||||
def get_full_url(self):
|
||||
def get_full_url(self) -> str:
|
||||
# Only return the response's URL if the user hadn't set the Host
|
||||
# header
|
||||
if not self._r.headers.get("Host"):
|
||||
@@ -66,37 +77,37 @@ class MockRequest:
|
||||
]
|
||||
)
|
||||
|
||||
def is_unverifiable(self):
|
||||
def is_unverifiable(self) -> bool:
|
||||
return True
|
||||
|
||||
def has_header(self, name):
|
||||
def has_header(self, name: str) -> bool:
|
||||
return name in self._r.headers or name in self._new_headers
|
||||
|
||||
def get_header(self, name, default=None):
|
||||
return self._r.headers.get(name, self._new_headers.get(name, default))
|
||||
def get_header(self, name: str, default: str | None = None) -> str | None:
|
||||
return self._r.headers.get(name, self._new_headers.get(name, default)) # type: ignore[return-value]
|
||||
|
||||
def add_header(self, key, val):
|
||||
def add_header(self, key: str, val: str) -> None:
|
||||
"""cookiejar has no legitimate use for this method; add it back if you find one."""
|
||||
raise NotImplementedError(
|
||||
"Cookie headers should be added with add_unredirected_header()"
|
||||
)
|
||||
|
||||
def add_unredirected_header(self, name, value):
|
||||
def add_unredirected_header(self, name: str, value: str) -> None:
|
||||
self._new_headers[name] = value
|
||||
|
||||
def get_new_headers(self):
|
||||
def get_new_headers(self) -> dict[str, str]:
|
||||
return self._new_headers
|
||||
|
||||
@property
|
||||
def unverifiable(self):
|
||||
def unverifiable(self) -> bool:
|
||||
return self.is_unverifiable()
|
||||
|
||||
@property
|
||||
def origin_req_host(self):
|
||||
def origin_req_host(self) -> str:
|
||||
return self.get_origin_req_host()
|
||||
|
||||
@property
|
||||
def host(self):
|
||||
def host(self) -> str:
|
||||
return self.get_host()
|
||||
|
||||
|
||||
@@ -107,21 +118,23 @@ class MockResponse:
|
||||
the way `http.cookiejar` expects to see them.
|
||||
"""
|
||||
|
||||
def __init__(self, headers):
|
||||
def __init__(self, headers: Any) -> None:
|
||||
"""Make a MockResponse for `cookiejar` to read.
|
||||
|
||||
:param headers: a httplib.HTTPMessage or analogous carrying the headers
|
||||
"""
|
||||
self._headers = headers
|
||||
|
||||
def info(self):
|
||||
def info(self) -> Any:
|
||||
return self._headers
|
||||
|
||||
def getheaders(self, name):
|
||||
def getheaders(self, name: str) -> Any:
|
||||
self._headers.getheaders(name)
|
||||
|
||||
|
||||
def extract_cookies_to_jar(jar, request, response):
|
||||
def extract_cookies_to_jar(
|
||||
jar: CookieJar, request: PreparedRequest, response: Any
|
||||
) -> None:
|
||||
"""Extract the cookies from the response into a CookieJar.
|
||||
|
||||
:param jar: http.cookiejar.CookieJar (not necessarily a RequestsCookieJar)
|
||||
@@ -134,26 +147,28 @@ def extract_cookies_to_jar(jar, request, response):
|
||||
req = MockRequest(request)
|
||||
# pull out the HTTPMessage with the headers and put it in the mock:
|
||||
res = MockResponse(response._original_response.msg)
|
||||
jar.extract_cookies(res, req)
|
||||
jar.extract_cookies(res, req) # type: ignore[arg-type]
|
||||
|
||||
|
||||
def get_cookie_header(jar, request):
|
||||
def get_cookie_header(jar: CookieJar, request: PreparedRequest) -> str | None:
|
||||
"""
|
||||
Produce an appropriate Cookie header string to be sent with `request`, or None.
|
||||
|
||||
:rtype: str
|
||||
"""
|
||||
r = MockRequest(request)
|
||||
jar.add_cookie_header(r)
|
||||
jar.add_cookie_header(r) # type: ignore[arg-type]
|
||||
return r.get_new_headers().get("Cookie")
|
||||
|
||||
|
||||
def remove_cookie_by_name(cookiejar, name, domain=None, path=None):
|
||||
def remove_cookie_by_name(
|
||||
cookiejar: CookieJar, name: str, domain: str | None = None, path: str | None = None
|
||||
) -> None:
|
||||
"""Unsets a cookie by name, by default over all domains and paths.
|
||||
|
||||
Wraps CookieJar.clear(), is O(n).
|
||||
"""
|
||||
clearables = []
|
||||
clearables: list[tuple[str, str, str]] = []
|
||||
for cookie in cookiejar:
|
||||
if cookie.name != name:
|
||||
continue
|
||||
@@ -173,7 +188,7 @@ class CookieConflictError(RuntimeError):
|
||||
"""
|
||||
|
||||
|
||||
class RequestsCookieJar(cookielib.CookieJar, MutableMapping):
|
||||
class RequestsCookieJar(CookieJar, MutableMapping[str, str | None]): # type: ignore[misc]
|
||||
"""Compatibility class; is a http.cookiejar.CookieJar, but exposes a dict
|
||||
interface.
|
||||
|
||||
@@ -191,7 +206,15 @@ class RequestsCookieJar(cookielib.CookieJar, MutableMapping):
|
||||
.. warning:: dictionary operations that are normally O(1) may be O(n).
|
||||
"""
|
||||
|
||||
def get(self, name, default=None, domain=None, path=None):
|
||||
_policy: CookiePolicy
|
||||
|
||||
def get( # type: ignore[override]
|
||||
self,
|
||||
name: str,
|
||||
default: str | None = None,
|
||||
domain: str | None = None,
|
||||
path: str | None = None,
|
||||
) -> str | None:
|
||||
"""Dict-like get() that also supports optional domain and path args in
|
||||
order to resolve naming collisions from using one cookie jar over
|
||||
multiple domains.
|
||||
@@ -203,7 +226,9 @@ class RequestsCookieJar(cookielib.CookieJar, MutableMapping):
|
||||
except KeyError:
|
||||
return default
|
||||
|
||||
def set(self, name, value, **kwargs):
|
||||
def set(
|
||||
self, name: str, value: str | Morsel[dict[str, str]] | None, **kwargs: Any
|
||||
) -> Cookie | None:
|
||||
"""Dict-like set() that also supports optional domain and path args in
|
||||
order to resolve naming collisions from using one cookie jar over
|
||||
multiple domains.
|
||||
@@ -222,7 +247,7 @@ class RequestsCookieJar(cookielib.CookieJar, MutableMapping):
|
||||
self.set_cookie(c)
|
||||
return c
|
||||
|
||||
def iterkeys(self):
|
||||
def iterkeys(self) -> Iterator[str]:
|
||||
"""Dict-like iterkeys() that returns an iterator of names of cookies
|
||||
from the jar.
|
||||
|
||||
@@ -231,7 +256,7 @@ class RequestsCookieJar(cookielib.CookieJar, MutableMapping):
|
||||
for cookie in iter(self):
|
||||
yield cookie.name
|
||||
|
||||
def keys(self):
|
||||
def keys(self) -> list[str]: # type: ignore[override]
|
||||
"""Dict-like keys() that returns a list of names of cookies from the
|
||||
jar.
|
||||
|
||||
@@ -239,7 +264,7 @@ class RequestsCookieJar(cookielib.CookieJar, MutableMapping):
|
||||
"""
|
||||
return list(self.iterkeys())
|
||||
|
||||
def itervalues(self):
|
||||
def itervalues(self) -> Iterator[str | None]:
|
||||
"""Dict-like itervalues() that returns an iterator of values of cookies
|
||||
from the jar.
|
||||
|
||||
@@ -248,7 +273,7 @@ class RequestsCookieJar(cookielib.CookieJar, MutableMapping):
|
||||
for cookie in iter(self):
|
||||
yield cookie.value
|
||||
|
||||
def values(self):
|
||||
def values(self) -> list[str | None]: # type: ignore[override]
|
||||
"""Dict-like values() that returns a list of values of cookies from the
|
||||
jar.
|
||||
|
||||
@@ -256,7 +281,7 @@ class RequestsCookieJar(cookielib.CookieJar, MutableMapping):
|
||||
"""
|
||||
return list(self.itervalues())
|
||||
|
||||
def iteritems(self):
|
||||
def iteritems(self) -> Iterator[tuple[str, str | None]]:
|
||||
"""Dict-like iteritems() that returns an iterator of name-value tuples
|
||||
from the jar.
|
||||
|
||||
@@ -265,7 +290,7 @@ class RequestsCookieJar(cookielib.CookieJar, MutableMapping):
|
||||
for cookie in iter(self):
|
||||
yield cookie.name, cookie.value
|
||||
|
||||
def items(self):
|
||||
def items(self) -> list[tuple[str, str | None]]: # type: ignore[override]
|
||||
"""Dict-like items() that returns a list of name-value tuples from the
|
||||
jar. Allows client-code to call ``dict(RequestsCookieJar)`` and get a
|
||||
vanilla python dict of key value pairs.
|
||||
@@ -274,43 +299,45 @@ class RequestsCookieJar(cookielib.CookieJar, MutableMapping):
|
||||
"""
|
||||
return list(self.iteritems())
|
||||
|
||||
def list_domains(self):
|
||||
def list_domains(self) -> list[str]:
|
||||
"""Utility method to list all the domains in the jar."""
|
||||
domains = []
|
||||
domains: list[str] = []
|
||||
for cookie in iter(self):
|
||||
if cookie.domain not in domains:
|
||||
domains.append(cookie.domain)
|
||||
return domains
|
||||
|
||||
def list_paths(self):
|
||||
def list_paths(self) -> list[str]:
|
||||
"""Utility method to list all the paths in the jar."""
|
||||
paths = []
|
||||
paths: list[str] = []
|
||||
for cookie in iter(self):
|
||||
if cookie.path not in paths:
|
||||
paths.append(cookie.path)
|
||||
return paths
|
||||
|
||||
def multiple_domains(self):
|
||||
def multiple_domains(self) -> bool:
|
||||
"""Returns True if there are multiple domains in the jar.
|
||||
Returns False otherwise.
|
||||
|
||||
:rtype: bool
|
||||
"""
|
||||
domains = []
|
||||
domains: list[str] = []
|
||||
for cookie in iter(self):
|
||||
if cookie.domain is not None and cookie.domain in domains:
|
||||
if cookie.domain is not None and cookie.domain in domains: # type: ignore[reportUnnecessaryComparison] # defensive check
|
||||
return True
|
||||
domains.append(cookie.domain)
|
||||
return False # there is only one domain in jar
|
||||
|
||||
def get_dict(self, domain=None, path=None):
|
||||
def get_dict(
|
||||
self, domain: str | None = None, path: str | None = None
|
||||
) -> dict[str, str | None]:
|
||||
"""Takes as an argument an optional domain and path and returns a plain
|
||||
old Python dict of name-value pairs of cookies that meet the
|
||||
requirements.
|
||||
|
||||
:rtype: dict
|
||||
"""
|
||||
dictionary = {}
|
||||
dictionary: dict[str, str | None] = {}
|
||||
for cookie in iter(self):
|
||||
if (domain is None or cookie.domain == domain) and (
|
||||
path is None or cookie.path == path
|
||||
@@ -318,13 +345,17 @@ class RequestsCookieJar(cookielib.CookieJar, MutableMapping):
|
||||
dictionary[cookie.name] = cookie.value
|
||||
return dictionary
|
||||
|
||||
def __contains__(self, name):
|
||||
def __iter__(self) -> Iterator[Cookie]: # type: ignore[override]
|
||||
"""RequestCookieJar's __iter__ comes from CookieJar not MutableMapping."""
|
||||
return super().__iter__()
|
||||
|
||||
def __contains__(self, name: object) -> bool:
|
||||
try:
|
||||
return super().__contains__(name)
|
||||
except CookieConflictError:
|
||||
return True
|
||||
|
||||
def __getitem__(self, name):
|
||||
def __getitem__(self, name: str) -> str | None:
|
||||
"""Dict-like __getitem__() for compatibility with client code. Throws
|
||||
exception if there are more than one cookie with name. In that case,
|
||||
use the more explicit get() method instead.
|
||||
@@ -333,29 +364,33 @@ class RequestsCookieJar(cookielib.CookieJar, MutableMapping):
|
||||
"""
|
||||
return self._find_no_duplicates(name)
|
||||
|
||||
def __setitem__(self, name, value):
|
||||
def __setitem__(
|
||||
self, name: str, value: str | Morsel[dict[str, str]] | None
|
||||
) -> None:
|
||||
"""Dict-like __setitem__ for compatibility with client code. Throws
|
||||
exception if there is already a cookie of that name in the jar. In that
|
||||
case, use the more explicit set() method instead.
|
||||
"""
|
||||
self.set(name, value)
|
||||
|
||||
def __delitem__(self, name):
|
||||
def __delitem__(self, name: str) -> None:
|
||||
"""Deletes a cookie given a name. Wraps ``http.cookiejar.CookieJar``'s
|
||||
``remove_cookie_by_name()``.
|
||||
"""
|
||||
remove_cookie_by_name(self, name)
|
||||
|
||||
def set_cookie(self, cookie, *args, **kwargs):
|
||||
def set_cookie(self, cookie: Cookie, *args: Any, **kwargs: Any) -> None:
|
||||
if (
|
||||
hasattr(cookie.value, "startswith")
|
||||
and cookie.value.startswith('"')
|
||||
and cookie.value.endswith('"')
|
||||
(value := cookie.value) is not None
|
||||
and value.startswith('"')
|
||||
and value.endswith('"')
|
||||
):
|
||||
cookie.value = cookie.value.replace('\\"', "")
|
||||
cookie.value = value.replace('\\"', "")
|
||||
return super().set_cookie(cookie, *args, **kwargs)
|
||||
|
||||
def update(self, other):
|
||||
def update( # type: ignore[override]
|
||||
self, other: CookieJar | SupportsKeysAndGetItem[str, str]
|
||||
) -> None:
|
||||
"""Updates this jar with cookies from another CookieJar or dict-like"""
|
||||
if isinstance(other, cookielib.CookieJar):
|
||||
for cookie in other:
|
||||
@@ -363,7 +398,9 @@ class RequestsCookieJar(cookielib.CookieJar, MutableMapping):
|
||||
else:
|
||||
super().update(other)
|
||||
|
||||
def _find(self, name, domain=None, path=None):
|
||||
def _find(
|
||||
self, name: str, domain: str | None = None, path: str | None = None
|
||||
) -> str | None:
|
||||
"""Requests uses this method internally to get cookie values.
|
||||
|
||||
If there are conflicting cookies, _find arbitrarily chooses one.
|
||||
@@ -383,7 +420,9 @@ class RequestsCookieJar(cookielib.CookieJar, MutableMapping):
|
||||
|
||||
raise KeyError(f"name={name!r}, domain={domain!r}, path={path!r}")
|
||||
|
||||
def _find_no_duplicates(self, name, domain=None, path=None):
|
||||
def _find_no_duplicates(
|
||||
self, name: str, domain: str | None = None, path: str | None = None
|
||||
) -> str:
|
||||
"""Both ``__get_item__`` and ``get`` call this function: it's never
|
||||
used elsewhere in Requests.
|
||||
|
||||
@@ -408,42 +447,42 @@ class RequestsCookieJar(cookielib.CookieJar, MutableMapping):
|
||||
# we will eventually return this as long as no cookie conflict
|
||||
toReturn = cookie.value
|
||||
|
||||
if toReturn:
|
||||
if toReturn is not None:
|
||||
return toReturn
|
||||
raise KeyError(f"name={name!r}, domain={domain!r}, path={path!r}")
|
||||
|
||||
def __getstate__(self):
|
||||
def __getstate__(self) -> dict[str, Any]:
|
||||
"""Unlike a normal CookieJar, this class is pickleable."""
|
||||
state = self.__dict__.copy()
|
||||
# remove the unpickleable RLock object
|
||||
state.pop("_cookies_lock")
|
||||
return state
|
||||
|
||||
def __setstate__(self, state):
|
||||
def __setstate__(self, state: dict[str, Any]) -> None:
|
||||
"""Unlike a normal CookieJar, this class is pickleable."""
|
||||
self.__dict__.update(state)
|
||||
if "_cookies_lock" not in self.__dict__:
|
||||
self._cookies_lock = threading.RLock()
|
||||
|
||||
def copy(self):
|
||||
def copy(self) -> RequestsCookieJar:
|
||||
"""Return a copy of this RequestsCookieJar."""
|
||||
new_cj = RequestsCookieJar()
|
||||
new_cj.set_policy(self.get_policy())
|
||||
new_cj.update(self)
|
||||
return new_cj
|
||||
|
||||
def get_policy(self):
|
||||
def get_policy(self) -> CookiePolicy:
|
||||
"""Return the CookiePolicy instance used."""
|
||||
return self._policy
|
||||
|
||||
|
||||
def _copy_cookie_jar(jar):
|
||||
def _copy_cookie_jar(jar: CookieJar | None) -> CookieJar | None: # type: ignore[reportUnusedFunction] # cross-module usage in models.py
|
||||
if jar is None:
|
||||
return None
|
||||
|
||||
if hasattr(jar, "copy"):
|
||||
if copy_method := getattr(jar, "copy", None):
|
||||
# We're dealing with an instance of RequestsCookieJar
|
||||
return jar.copy()
|
||||
return copy_method()
|
||||
# We're dealing with a generic CookieJar instance
|
||||
new_jar = copy.copy(jar)
|
||||
new_jar.clear()
|
||||
@@ -452,13 +491,13 @@ def _copy_cookie_jar(jar):
|
||||
return new_jar
|
||||
|
||||
|
||||
def create_cookie(name, value, **kwargs):
|
||||
def create_cookie(name: str, value: str, **kwargs: Any) -> Cookie:
|
||||
"""Make a cookie from underspecified parameters.
|
||||
|
||||
By default, the pair of `name` and `value` will be set for the domain ''
|
||||
and sent on every request (this is sometimes called a "supercookie").
|
||||
"""
|
||||
result = {
|
||||
result: dict[str, Any] = {
|
||||
"version": 0,
|
||||
"name": name,
|
||||
"value": value,
|
||||
@@ -489,10 +528,10 @@ def create_cookie(name, value, **kwargs):
|
||||
return cookielib.Cookie(**result)
|
||||
|
||||
|
||||
def morsel_to_cookie(morsel):
|
||||
def morsel_to_cookie(morsel: Morsel[Any]) -> Cookie:
|
||||
"""Convert a Morsel object into a Cookie containing the one k/v pair."""
|
||||
|
||||
expires = None
|
||||
expires: int | None = None
|
||||
if morsel["max-age"]:
|
||||
try:
|
||||
expires = int(time.time() + int(morsel["max-age"]))
|
||||
@@ -518,7 +557,30 @@ def morsel_to_cookie(morsel):
|
||||
)
|
||||
|
||||
|
||||
def cookiejar_from_dict(cookie_dict, cookiejar=None, overwrite=True):
|
||||
_CookieJarT = TypeVar("_CookieJarT", bound=CookieJar)
|
||||
|
||||
|
||||
@overload
|
||||
def cookiejar_from_dict(
|
||||
cookie_dict: dict[str, str] | None,
|
||||
cookiejar: None = None,
|
||||
overwrite: bool = True,
|
||||
) -> RequestsCookieJar: ...
|
||||
|
||||
|
||||
@overload
|
||||
def cookiejar_from_dict(
|
||||
cookie_dict: dict[str, str] | None,
|
||||
cookiejar: _CookieJarT,
|
||||
overwrite: bool = True,
|
||||
) -> _CookieJarT: ...
|
||||
|
||||
|
||||
def cookiejar_from_dict(
|
||||
cookie_dict: dict[str, str] | None,
|
||||
cookiejar: CookieJar | None = None,
|
||||
overwrite: bool = True,
|
||||
) -> CookieJar:
|
||||
"""Returns a CookieJar from a key/value dictionary.
|
||||
|
||||
:param cookie_dict: Dict of key/values to insert into CookieJar.
|
||||
@@ -539,22 +601,24 @@ def cookiejar_from_dict(cookie_dict, cookiejar=None, overwrite=True):
|
||||
return cookiejar
|
||||
|
||||
|
||||
def merge_cookies(cookiejar, cookies):
|
||||
def merge_cookies(
|
||||
cookiejar: CookieJar, cookies: dict[str, str] | CookieJar | None
|
||||
) -> CookieJar:
|
||||
"""Add cookies to cookiejar and returns a merged CookieJar.
|
||||
|
||||
:param cookiejar: CookieJar object to add the cookies to.
|
||||
:param cookies: Dictionary or CookieJar object to be added.
|
||||
:rtype: CookieJar
|
||||
"""
|
||||
if not isinstance(cookiejar, cookielib.CookieJar):
|
||||
if not isinstance(cookiejar, cookielib.CookieJar): # type: ignore[reportUnnecessaryIsInstance] # runtime guard
|
||||
raise ValueError("You can only merge into CookieJar")
|
||||
|
||||
if isinstance(cookies, dict):
|
||||
cookiejar = cookiejar_from_dict(cookies, cookiejar=cookiejar, overwrite=False)
|
||||
elif isinstance(cookies, cookielib.CookieJar):
|
||||
try:
|
||||
cookiejar.update(cookies)
|
||||
except AttributeError:
|
||||
if update_method := getattr(cookiejar, "update", None):
|
||||
update_method(cookies)
|
||||
else:
|
||||
for cookie_in_jar in cookies:
|
||||
cookiejar.set_cookie(cookie_in_jar)
|
||||
|
||||
|
||||
@@ -4,23 +4,34 @@ requests.exceptions
|
||||
|
||||
This module contains the set of Requests' exceptions.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from pip._vendor.urllib3.exceptions import HTTPError as BaseHTTPError
|
||||
|
||||
from .compat import JSONDecodeError as CompatJSONDecodeError
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .models import PreparedRequest, Request, Response
|
||||
|
||||
|
||||
class RequestException(IOError):
|
||||
"""There was an ambiguous exception that occurred while handling your
|
||||
request.
|
||||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
response: Response | None
|
||||
request: Request | PreparedRequest | None
|
||||
|
||||
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
||||
"""Initialize RequestException with `request` and `response` objects."""
|
||||
response = kwargs.pop("response", None)
|
||||
response: Response | None = kwargs.pop("response", None)
|
||||
self.response = response
|
||||
self.request = kwargs.pop("request", None)
|
||||
if response is not None and not self.request and hasattr(response, "request"):
|
||||
self.request = self.response.request
|
||||
self.request = response.request
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
|
||||
@@ -31,7 +42,7 @@ class InvalidJSONError(RequestException):
|
||||
class JSONDecodeError(InvalidJSONError, CompatJSONDecodeError):
|
||||
"""Couldn't decode the text into json"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
||||
"""
|
||||
Construct the JSONDecodeError instance first with all
|
||||
args. Then use it's args to construct the IOError so that
|
||||
@@ -41,7 +52,7 @@ class JSONDecodeError(InvalidJSONError, CompatJSONDecodeError):
|
||||
CompatJSONDecodeError.__init__(self, *args)
|
||||
InvalidJSONError.__init__(self, *self.args, **kwargs)
|
||||
|
||||
def __reduce__(self):
|
||||
def __reduce__(self) -> tuple[Any, ...] | str:
|
||||
"""
|
||||
The __reduce__ method called when pickling the object must
|
||||
be the one from the JSONDecodeError (be it json/simplejson)
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
"""Module containing bug report helper(s)."""
|
||||
|
||||
# pyright: reportUnknownMemberType=false
|
||||
|
||||
import json
|
||||
import platform
|
||||
import ssl
|
||||
import sys
|
||||
from typing import Any
|
||||
|
||||
from pip._vendor import idna
|
||||
from pip._vendor import urllib3
|
||||
@@ -20,8 +23,8 @@ except ImportError:
|
||||
OpenSSL = None
|
||||
cryptography = None
|
||||
else:
|
||||
import cryptography
|
||||
import OpenSSL
|
||||
import cryptography # type: ignore[import-not-found]
|
||||
import OpenSSL # type: ignore[import-not-found]
|
||||
|
||||
|
||||
def _implementation():
|
||||
@@ -40,14 +43,11 @@ def _implementation():
|
||||
if implementation == "CPython":
|
||||
implementation_version = platform.python_version()
|
||||
elif implementation == "PyPy":
|
||||
implementation_version = "{}.{}.{}".format(
|
||||
sys.pypy_version_info.major,
|
||||
sys.pypy_version_info.minor,
|
||||
sys.pypy_version_info.micro,
|
||||
)
|
||||
if sys.pypy_version_info.releaselevel != "final":
|
||||
pypy = sys.pypy_version_info # type: ignore[attr-defined]
|
||||
implementation_version = f"{pypy.major}.{pypy.minor}.{pypy.micro}"
|
||||
if sys.pypy_version_info.releaselevel != "final": # type: ignore[attr-defined]
|
||||
implementation_version = "".join(
|
||||
[implementation_version, sys.pypy_version_info.releaselevel]
|
||||
[implementation_version, sys.pypy_version_info.releaselevel] # type: ignore[attr-defined]
|
||||
)
|
||||
elif implementation == "Jython":
|
||||
implementation_version = platform.python_version() # Complete Guess
|
||||
@@ -59,7 +59,7 @@ def _implementation():
|
||||
return {"name": implementation, "version": implementation_version}
|
||||
|
||||
|
||||
def info():
|
||||
def info() -> dict[str, Any]:
|
||||
"""Generate information for a bug report."""
|
||||
try:
|
||||
platform_info = {
|
||||
@@ -73,15 +73,15 @@ def info():
|
||||
}
|
||||
|
||||
implementation_info = _implementation()
|
||||
urllib3_info = {"version": urllib3.__version__}
|
||||
urllib3_info = {"version": urllib3.__version__} # type: ignore[reportPrivateImportUsage]
|
||||
charset_normalizer_info = {"version": None}
|
||||
chardet_info = {"version": None}
|
||||
chardet_info: dict[str, str | None] = {"version": None}
|
||||
if charset_normalizer:
|
||||
charset_normalizer_info = {"version": charset_normalizer.__version__}
|
||||
if chardet:
|
||||
chardet_info = {"version": chardet.__version__}
|
||||
|
||||
pyopenssl_info = {
|
||||
pyopenssl_info: dict[str, str | None] = {
|
||||
"version": None,
|
||||
"openssl_version": "",
|
||||
}
|
||||
@@ -98,7 +98,7 @@ def info():
|
||||
}
|
||||
|
||||
system_ssl = ssl.OPENSSL_VERSION_NUMBER
|
||||
system_ssl_info = {"version": f"{system_ssl:x}" if system_ssl is not None else ""}
|
||||
system_ssl_info = {"version": f"{system_ssl:x}" if system_ssl is not None else ""} # type: ignore[reportUnnecessaryComparison]
|
||||
|
||||
return {
|
||||
"platform": platform_info,
|
||||
|
||||
@@ -9,24 +9,39 @@ Available hooks:
|
||||
``response``:
|
||||
The response generated from a Request.
|
||||
"""
|
||||
HOOKS = ["response"]
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable, Iterable
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from . import _types as _t
|
||||
from .models import Response
|
||||
|
||||
HOOKS: list[str] = ["response"]
|
||||
|
||||
|
||||
def default_hooks():
|
||||
def default_hooks() -> dict[str, list[_t.HookType]]:
|
||||
return {event: [] for event in HOOKS}
|
||||
|
||||
|
||||
# TODO: response is the only one
|
||||
|
||||
|
||||
def dispatch_hook(key, hooks, hook_data, **kwargs):
|
||||
def dispatch_hook(
|
||||
key: str,
|
||||
hooks: _t.HooksInputType | None,
|
||||
hook_data: Response,
|
||||
**kwargs: Any,
|
||||
) -> Response:
|
||||
"""Dispatches a hook dictionary on a given piece of data."""
|
||||
hooks = hooks or {}
|
||||
hooks = hooks.get(key)
|
||||
if hooks:
|
||||
if hasattr(hooks, "__call__"):
|
||||
hooks = [hooks]
|
||||
for hook in hooks:
|
||||
hooks_dict = hooks or {}
|
||||
hook_list: Iterable[_t.HookType] | _t.HookType | None = hooks_dict.get(key)
|
||||
if hook_list:
|
||||
if isinstance(hook_list, Callable):
|
||||
hook_list = [hook_list]
|
||||
for hook in hook_list:
|
||||
_hook_data = hook(hook_data, **kwargs)
|
||||
if _hook_data is not None:
|
||||
hook_data = _hook_data
|
||||
|
||||
@@ -5,13 +5,24 @@ requests.models
|
||||
This module contains the primary objects that power Requests.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
|
||||
# Import encoding now, to avoid implicit import later.
|
||||
# Implicit import within threads may cause LookupError when standard library is in a ZIP,
|
||||
# such as in Embedded Python. See https://github.com/psf/requests/issues/3578.
|
||||
import encodings.idna # noqa: F401
|
||||
import encodings.idna # noqa: F401 # type: ignore[reportUnusedImport]
|
||||
from collections.abc import Callable, Generator, Iterable, Iterator, Mapping
|
||||
from io import UnsupportedOperation
|
||||
from typing import (
|
||||
TYPE_CHECKING,
|
||||
Any,
|
||||
Final,
|
||||
Literal,
|
||||
cast,
|
||||
overload,
|
||||
)
|
||||
|
||||
from pip._vendor.urllib3.exceptions import (
|
||||
DecodeError,
|
||||
@@ -25,19 +36,24 @@ from pip._vendor.urllib3.filepost import encode_multipart_formdata
|
||||
from pip._vendor.urllib3.util import parse_url
|
||||
|
||||
from ._internal_utils import to_native_string, unicode_is_ascii
|
||||
from ._types import SupportsRead as _SupportsRead
|
||||
from .auth import HTTPBasicAuth
|
||||
from .compat import (
|
||||
Callable,
|
||||
JSONDecodeError,
|
||||
Mapping,
|
||||
basestring,
|
||||
builtin_str,
|
||||
chardet,
|
||||
cookielib,
|
||||
urlencode,
|
||||
urlsplit,
|
||||
urlunparse,
|
||||
)
|
||||
from .compat import json as complexjson
|
||||
from .compat import urlencode, urlsplit, urlunparse
|
||||
from .cookies import _copy_cookie_jar, cookiejar_from_dict, get_cookie_header
|
||||
from .cookies import (
|
||||
_copy_cookie_jar, # type: ignore[reportPrivateUsage]
|
||||
cookiejar_from_dict,
|
||||
get_cookie_header,
|
||||
)
|
||||
from .exceptions import (
|
||||
ChunkedEncodingError,
|
||||
ConnectionError,
|
||||
@@ -45,11 +61,11 @@ from .exceptions import (
|
||||
HTTPError,
|
||||
InvalidJSONError,
|
||||
InvalidURL,
|
||||
MissingSchema,
|
||||
StreamConsumedError,
|
||||
)
|
||||
from .exceptions import JSONDecodeError as RequestsJSONDecodeError
|
||||
from .exceptions import MissingSchema
|
||||
from .exceptions import SSLError as RequestsSSLError
|
||||
from .exceptions import StreamConsumedError
|
||||
from .hooks import default_hooks
|
||||
from .status_codes import codes
|
||||
from .structures import CaseInsensitiveDict
|
||||
@@ -66,9 +82,18 @@ from .utils import (
|
||||
to_key_val_list,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from http.cookiejar import CookieJar
|
||||
|
||||
from typing_extensions import Self
|
||||
|
||||
from . import _types as _t
|
||||
from .adapters import HTTPAdapter
|
||||
from .cookies import RequestsCookieJar
|
||||
|
||||
#: The set of HTTP status codes that indicate an automatically
|
||||
#: processable redirect.
|
||||
REDIRECT_STATI = (
|
||||
REDIRECT_STATI: Final[tuple[int, ...]] = ( # type: ignore[assignment]
|
||||
codes.moved, # 301
|
||||
codes.found, # 302
|
||||
codes.other, # 303
|
||||
@@ -76,19 +101,21 @@ REDIRECT_STATI = (
|
||||
codes.permanent_redirect, # 308
|
||||
)
|
||||
|
||||
DEFAULT_REDIRECT_LIMIT = 30
|
||||
CONTENT_CHUNK_SIZE = 10 * 1024
|
||||
ITER_CHUNK_SIZE = 512
|
||||
DEFAULT_REDIRECT_LIMIT: int = 30
|
||||
CONTENT_CHUNK_SIZE: int = 10 * 1024
|
||||
ITER_CHUNK_SIZE: int = 512
|
||||
|
||||
|
||||
class RequestEncodingMixin:
|
||||
url: str | None
|
||||
|
||||
@property
|
||||
def path_url(self):
|
||||
def path_url(self) -> str:
|
||||
"""Build the path URL to use."""
|
||||
|
||||
url = []
|
||||
url: list[str] = []
|
||||
|
||||
p = urlsplit(self.url)
|
||||
p = urlsplit(cast(str, self.url))
|
||||
|
||||
path = p.path
|
||||
if not path:
|
||||
@@ -103,8 +130,28 @@ class RequestEncodingMixin:
|
||||
|
||||
return "".join(url)
|
||||
|
||||
@overload
|
||||
@staticmethod
|
||||
def _encode_params(data):
|
||||
def _encode_params(data: str) -> str: ...
|
||||
|
||||
@overload
|
||||
@staticmethod
|
||||
def _encode_params(data: bytes) -> bytes: ...
|
||||
|
||||
@overload
|
||||
@staticmethod
|
||||
def _encode_params(
|
||||
data: _t.SupportsRead[str | bytes],
|
||||
) -> _t.SupportsRead[str | bytes]: ...
|
||||
|
||||
@overload
|
||||
@staticmethod
|
||||
def _encode_params(data: _t.KVDataType) -> str: ...
|
||||
|
||||
@staticmethod
|
||||
def _encode_params(
|
||||
data: _t.EncodableDataType,
|
||||
) -> str | bytes | _t.SupportsRead[str | bytes]:
|
||||
"""Encode parameters in a piece of data.
|
||||
|
||||
Will successfully encode parameters when passed as a dict or a list of
|
||||
@@ -114,10 +161,10 @@ class RequestEncodingMixin:
|
||||
|
||||
if isinstance(data, (str, bytes)):
|
||||
return data
|
||||
elif hasattr(data, "read"):
|
||||
elif isinstance(data, _SupportsRead):
|
||||
return data
|
||||
elif hasattr(data, "__iter__"):
|
||||
result = []
|
||||
result: list[tuple[bytes, bytes]] = []
|
||||
for k, vs in to_key_val_list(data):
|
||||
if isinstance(vs, basestring) or not hasattr(vs, "__iter__"):
|
||||
vs = [vs]
|
||||
@@ -131,10 +178,12 @@ class RequestEncodingMixin:
|
||||
)
|
||||
return urlencode(result, doseq=True)
|
||||
else:
|
||||
return data
|
||||
return data # type: ignore[return-value] # unreachable for valid _t.DataType
|
||||
|
||||
@staticmethod
|
||||
def _encode_files(files, data):
|
||||
def _encode_files(
|
||||
files: _t.FilesType, data: _t.RawDataType | None
|
||||
) -> tuple[bytes, str]:
|
||||
"""Build the body for a multipart/form-data request.
|
||||
|
||||
Will successfully encode files when passed as a dict or a list of
|
||||
@@ -148,7 +197,7 @@ class RequestEncodingMixin:
|
||||
elif isinstance(data, basestring):
|
||||
raise ValueError("Data must not be a string.")
|
||||
|
||||
new_fields = []
|
||||
new_fields: list[RequestField | tuple[str, bytes]] = []
|
||||
fields = to_key_val_list(data or {})
|
||||
files = to_key_val_list(files or {})
|
||||
|
||||
@@ -187,9 +236,9 @@ class RequestEncodingMixin:
|
||||
|
||||
if isinstance(fp, (str, bytes, bytearray)):
|
||||
fdata = fp
|
||||
elif hasattr(fp, "read"):
|
||||
elif isinstance(fp, _SupportsRead): # type: ignore[reportUnnecessaryIsInstance] # defensive check for untyped callers
|
||||
fdata = fp.read()
|
||||
elif fp is None:
|
||||
elif fp is None: # type: ignore[reportUnnecessaryComparison] # defensive check for untyped callers
|
||||
continue
|
||||
else:
|
||||
fdata = fp
|
||||
@@ -204,7 +253,11 @@ class RequestEncodingMixin:
|
||||
|
||||
|
||||
class RequestHooksMixin:
|
||||
def register_hook(self, event, hook):
|
||||
hooks: dict[str, list[_t.HookType]]
|
||||
|
||||
def register_hook(
|
||||
self, event: str, hook: Iterable[_t.HookType] | _t.HookType
|
||||
) -> None:
|
||||
"""Properly register a hook."""
|
||||
|
||||
if event not in self.hooks:
|
||||
@@ -213,9 +266,9 @@ class RequestHooksMixin:
|
||||
if isinstance(hook, Callable):
|
||||
self.hooks[event].append(hook)
|
||||
elif hasattr(hook, "__iter__"):
|
||||
self.hooks[event].extend(h for h in hook if isinstance(h, Callable))
|
||||
self.hooks[event].extend(h for h in hook if isinstance(h, Callable)) # type: ignore[reportUnnecessaryIsInstance] # defensive runtime filter
|
||||
|
||||
def deregister_hook(self, event, hook):
|
||||
def deregister_hook(self, event: str, hook: _t.HookType) -> bool:
|
||||
"""Deregister a previously registered hook.
|
||||
Returns True if the hook existed, False if not.
|
||||
"""
|
||||
@@ -255,19 +308,29 @@ class Request(RequestHooksMixin):
|
||||
<PreparedRequest [GET]>
|
||||
"""
|
||||
|
||||
method: str | None
|
||||
url: _t.UriType | None
|
||||
headers: Mapping[str, str | bytes]
|
||||
files: _t.FilesType
|
||||
data: _t.DataType
|
||||
json: _t.JsonType
|
||||
params: _t.ParamsType
|
||||
auth: _t.AuthType
|
||||
cookies: RequestsCookieJar | CookieJar | dict[str, str] | None
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
method=None,
|
||||
url=None,
|
||||
headers=None,
|
||||
files=None,
|
||||
data=None,
|
||||
params=None,
|
||||
auth=None,
|
||||
cookies=None,
|
||||
hooks=None,
|
||||
json=None,
|
||||
):
|
||||
method: str | None = None,
|
||||
url: _t.UriType | None = None,
|
||||
headers: _t.HeadersType = None,
|
||||
files: _t.FilesType = None,
|
||||
data: _t.DataType = None,
|
||||
params: _t.ParamsType = None,
|
||||
auth: _t.AuthType = None,
|
||||
cookies: RequestsCookieJar | CookieJar | dict[str, str] | None = None,
|
||||
hooks: _t.HooksInputType | None = None,
|
||||
json: _t.JsonType = None,
|
||||
) -> None:
|
||||
# Default empty dicts for dict params.
|
||||
data = [] if data is None else data
|
||||
files = [] if files is None else files
|
||||
@@ -289,10 +352,10 @@ class Request(RequestHooksMixin):
|
||||
self.auth = auth
|
||||
self.cookies = cookies
|
||||
|
||||
def __repr__(self):
|
||||
def __repr__(self) -> str:
|
||||
return f"<Request [{self.method}]>"
|
||||
|
||||
def prepare(self):
|
||||
def prepare(self) -> PreparedRequest:
|
||||
"""Constructs a :class:`PreparedRequest <PreparedRequest>` for transmission and returns it."""
|
||||
p = PreparedRequest()
|
||||
p.prepare(
|
||||
@@ -331,13 +394,21 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
|
||||
<Response [200]>
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
method: str | None
|
||||
url: str | None
|
||||
headers: CaseInsensitiveDict[str | bytes]
|
||||
_cookies: RequestsCookieJar | CookieJar | None
|
||||
body: _t.BodyType
|
||||
hooks: dict[str, list[_t.HookType]]
|
||||
_body_position: int | object | None
|
||||
|
||||
def __init__(self) -> None:
|
||||
#: HTTP verb to send to the server.
|
||||
self.method = None
|
||||
#: HTTP URL to send the request to.
|
||||
self.url = None
|
||||
#: dictionary of HTTP headers.
|
||||
self.headers = None
|
||||
self.headers = None # type: ignore[assignment]
|
||||
# The `CookieJar` used to create the Cookie header will be stored here
|
||||
# after prepare_cookies is called
|
||||
self._cookies = None
|
||||
@@ -350,19 +421,20 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
|
||||
|
||||
def prepare(
|
||||
self,
|
||||
method=None,
|
||||
url=None,
|
||||
headers=None,
|
||||
files=None,
|
||||
data=None,
|
||||
params=None,
|
||||
auth=None,
|
||||
cookies=None,
|
||||
hooks=None,
|
||||
json=None,
|
||||
):
|
||||
method: str | None = None,
|
||||
url: _t.UriType | None = None,
|
||||
headers: Mapping[str, str | bytes] | None = None,
|
||||
files: _t.FilesType = None,
|
||||
data: _t.DataType = None,
|
||||
params: _t.ParamsType = None,
|
||||
auth: _t.AuthType = None,
|
||||
cookies: RequestsCookieJar | CookieJar | dict[str, str] | None = None,
|
||||
hooks: _t.HooksInputType | None = None,
|
||||
json: _t.JsonType = None,
|
||||
) -> None:
|
||||
"""Prepares the entire request with the given parameters."""
|
||||
|
||||
url = cast("_t.UriType", url)
|
||||
self.prepare_method(method)
|
||||
self.prepare_url(url, params)
|
||||
self.prepare_headers(headers)
|
||||
@@ -376,28 +448,28 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
|
||||
# This MUST go after prepare_auth. Authenticators could add a hook
|
||||
self.prepare_hooks(hooks)
|
||||
|
||||
def __repr__(self):
|
||||
def __repr__(self) -> str:
|
||||
return f"<PreparedRequest [{self.method}]>"
|
||||
|
||||
def copy(self):
|
||||
def copy(self) -> PreparedRequest:
|
||||
p = PreparedRequest()
|
||||
p.method = self.method
|
||||
p.url = self.url
|
||||
p.headers = self.headers.copy() if self.headers is not None else None
|
||||
p.headers = self.headers.copy() if self.headers is not None else None # type: ignore[assignment]
|
||||
p._cookies = _copy_cookie_jar(self._cookies)
|
||||
p.body = self.body
|
||||
p.hooks = self.hooks
|
||||
p._body_position = self._body_position
|
||||
return p
|
||||
|
||||
def prepare_method(self, method):
|
||||
def prepare_method(self, method: str | None) -> None:
|
||||
"""Prepares the given HTTP method."""
|
||||
self.method = method
|
||||
if self.method is not None:
|
||||
self.method = to_native_string(self.method.upper())
|
||||
|
||||
@staticmethod
|
||||
def _get_idna_encoded_host(host):
|
||||
def _get_idna_encoded_host(host: str) -> str:
|
||||
from pip._vendor import idna
|
||||
|
||||
try:
|
||||
@@ -406,7 +478,11 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
|
||||
raise UnicodeError
|
||||
return host
|
||||
|
||||
def prepare_url(self, url, params):
|
||||
def prepare_url(
|
||||
self,
|
||||
url: _t.UriType,
|
||||
params: _t.ParamsType,
|
||||
) -> None:
|
||||
"""Prepares the given HTTP URL."""
|
||||
#: Accept objects that have string representations.
|
||||
#: We're unable to blindly call unicode/str functions
|
||||
@@ -470,17 +546,21 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
|
||||
if isinstance(params, (str, bytes)):
|
||||
params = to_native_string(params)
|
||||
|
||||
enc_params = self._encode_params(params)
|
||||
if params is not None:
|
||||
enc_params = self._encode_params(params)
|
||||
else:
|
||||
enc_params = ""
|
||||
|
||||
if enc_params:
|
||||
if query:
|
||||
query = f"{query}&{enc_params}"
|
||||
else:
|
||||
query = enc_params
|
||||
|
||||
url = requote_uri(urlunparse([scheme, netloc, path, None, query, fragment]))
|
||||
url = requote_uri(urlunparse((scheme, netloc, path, "", query, fragment)))
|
||||
self.url = url
|
||||
|
||||
def prepare_headers(self, headers):
|
||||
def prepare_headers(self, headers: Mapping[str, str | bytes] | None) -> None:
|
||||
"""Prepares the given HTTP headers."""
|
||||
|
||||
self.headers = CaseInsensitiveDict()
|
||||
@@ -491,7 +571,9 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
|
||||
name, value = header
|
||||
self.headers[to_native_string(name)] = value
|
||||
|
||||
def prepare_body(self, data, files, json=None):
|
||||
def prepare_body(
|
||||
self, data: _t.DataType, files: _t.FilesType, json: _t.JsonType = None
|
||||
) -> None:
|
||||
"""Prepares the given HTTP body data."""
|
||||
|
||||
# Check if file, fo, generator, iterator.
|
||||
@@ -514,14 +596,9 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
|
||||
if not isinstance(body, bytes):
|
||||
body = body.encode("utf-8")
|
||||
|
||||
is_stream = all(
|
||||
[
|
||||
hasattr(data, "__iter__"),
|
||||
not isinstance(data, (basestring, list, tuple, Mapping)),
|
||||
]
|
||||
)
|
||||
|
||||
if is_stream:
|
||||
# data that proxies attributes to underlying objects needs hasattr
|
||||
is_iterable = isinstance(data, Iterable) or hasattr(data, "__iter__")
|
||||
if is_iterable and not isinstance(data, (str, bytes, list, tuple, Mapping)):
|
||||
try:
|
||||
length = super_len(data)
|
||||
except (TypeError, AttributeError, UnsupportedOperation):
|
||||
@@ -534,7 +611,7 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
|
||||
# This will allow us to rewind a file in the event
|
||||
# of a redirect.
|
||||
try:
|
||||
self._body_position = body.tell()
|
||||
self._body_position = body.tell() # type: ignore[union-attr] # guarded by getattr check
|
||||
except OSError:
|
||||
# This differentiates from None, allowing us to catch
|
||||
# a failed `tell()` later when trying to rewind the body
|
||||
@@ -550,13 +627,16 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
|
||||
else:
|
||||
self.headers["Transfer-Encoding"] = "chunked"
|
||||
else:
|
||||
# After is_stream filtering, remaining data is raw (not streamed)
|
||||
raw_data = cast("_t.RawDataType | None", data)
|
||||
|
||||
# Multi-part file uploads.
|
||||
if files:
|
||||
(body, content_type) = self._encode_files(files, data)
|
||||
(body, content_type) = self._encode_files(files, raw_data)
|
||||
else:
|
||||
if data:
|
||||
body = self._encode_params(data)
|
||||
if isinstance(data, basestring) or hasattr(data, "read"):
|
||||
if raw_data:
|
||||
body = self._encode_params(raw_data)
|
||||
if isinstance(data, basestring) or isinstance(data, _SupportsRead):
|
||||
content_type = None
|
||||
else:
|
||||
content_type = "application/x-www-form-urlencoded"
|
||||
@@ -567,9 +647,9 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
|
||||
if content_type and ("content-type" not in self.headers):
|
||||
self.headers["Content-Type"] = content_type
|
||||
|
||||
self.body = body
|
||||
self.body = body # type: ignore[assignment] # body transforms from DataType to BodyType
|
||||
|
||||
def prepare_content_length(self, body):
|
||||
def prepare_content_length(self, body: _t.BodyType) -> None:
|
||||
"""Prepare Content-Length header based on request method and body"""
|
||||
if body is not None:
|
||||
length = super_len(body)
|
||||
@@ -585,21 +665,28 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
|
||||
# but don't provide one. (i.e. not GET or HEAD)
|
||||
self.headers["Content-Length"] = "0"
|
||||
|
||||
def prepare_auth(self, auth, url=""):
|
||||
def prepare_auth(
|
||||
self,
|
||||
auth: _t.AuthType,
|
||||
url: _t.UriType = "",
|
||||
) -> None:
|
||||
"""Prepares the given HTTP auth data."""
|
||||
|
||||
# If no Auth is explicitly provided, extract it from the URL first.
|
||||
if auth is None:
|
||||
url_auth = get_auth_from_url(self.url)
|
||||
url_auth = get_auth_from_url(cast(str, self.url))
|
||||
auth = url_auth if any(url_auth) else None
|
||||
|
||||
if auth:
|
||||
if isinstance(auth, tuple) and len(auth) == 2:
|
||||
if isinstance(auth, tuple) and len(auth) == 2: # type: ignore[arg-type] # pyright widens tuple from Callable in AuthType
|
||||
# special-case basic HTTP auth
|
||||
auth = HTTPBasicAuth(*auth)
|
||||
auth_handler = HTTPBasicAuth(*auth) # type: ignore[arg-type] # pyright widens tuple from Callable in AuthType
|
||||
else:
|
||||
# TODO: can be fixed by flipping the conditionals
|
||||
auth_handler = cast("Callable[..., PreparedRequest]", auth)
|
||||
|
||||
# Allow auth to make its changes.
|
||||
r = auth(self)
|
||||
r = auth_handler(self)
|
||||
|
||||
# Update self to reflect the auth changes.
|
||||
self.__dict__.update(r.__dict__)
|
||||
@@ -607,7 +694,9 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
|
||||
# Recompute Content-Length
|
||||
self.prepare_content_length(self.body)
|
||||
|
||||
def prepare_cookies(self, cookies):
|
||||
def prepare_cookies(
|
||||
self, cookies: RequestsCookieJar | CookieJar | dict[str, str] | None
|
||||
) -> None:
|
||||
"""Prepares the given HTTP cookie data.
|
||||
|
||||
This function eventually generates a ``Cookie`` header from the
|
||||
@@ -623,16 +712,17 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
|
||||
else:
|
||||
self._cookies = cookiejar_from_dict(cookies)
|
||||
|
||||
cookie_header = get_cookie_header(self._cookies, self)
|
||||
cookies_jar = cast("CookieJar", self._cookies)
|
||||
cookie_header = get_cookie_header(cookies_jar, self)
|
||||
if cookie_header is not None:
|
||||
self.headers["Cookie"] = cookie_header
|
||||
|
||||
def prepare_hooks(self, hooks):
|
||||
def prepare_hooks(self, hooks: _t.HooksInputType | None) -> None:
|
||||
"""Prepares the given hooks."""
|
||||
# hooks can be passed as None to the prepare method and to this
|
||||
# method. To prevent iterating over None, simply use an empty list
|
||||
# if hooks is False-y
|
||||
hooks = hooks or []
|
||||
hooks = hooks or {}
|
||||
for event in hooks:
|
||||
self.register_hook(event, hooks[event])
|
||||
|
||||
@@ -642,7 +732,22 @@ class Response:
|
||||
server's response to an HTTP request.
|
||||
"""
|
||||
|
||||
__attrs__ = [
|
||||
_content: bytes | Literal[False] | None
|
||||
_content_consumed: bool
|
||||
_next: PreparedRequest | None
|
||||
status_code: int
|
||||
headers: CaseInsensitiveDict[str]
|
||||
raw: Any
|
||||
url: str
|
||||
encoding: str | None
|
||||
history: list[Response]
|
||||
reason: str
|
||||
cookies: RequestsCookieJar
|
||||
elapsed: datetime.timedelta
|
||||
request: PreparedRequest
|
||||
connection: HTTPAdapter
|
||||
|
||||
__attrs__: list[str] = [
|
||||
"_content",
|
||||
"status_code",
|
||||
"headers",
|
||||
@@ -655,13 +760,13 @@ class Response:
|
||||
"request",
|
||||
]
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self) -> None:
|
||||
self._content = False
|
||||
self._content_consumed = False
|
||||
self._next = None
|
||||
|
||||
#: Integer Code of responded HTTP Status, e.g. 404 or 200.
|
||||
self.status_code = None
|
||||
self.status_code = None # type: ignore[assignment]
|
||||
|
||||
#: Case-insensitive Dictionary of Response Headers.
|
||||
#: For example, ``headers['content-encoding']`` will return the
|
||||
@@ -674,7 +779,7 @@ class Response:
|
||||
self.raw = None
|
||||
|
||||
#: Final URL location of Response.
|
||||
self.url = None
|
||||
self.url = None # type: ignore[assignment]
|
||||
|
||||
#: Encoding to decode with when accessing r.text.
|
||||
self.encoding = None
|
||||
@@ -685,7 +790,7 @@ class Response:
|
||||
self.history = []
|
||||
|
||||
#: Textual reason of responded HTTP Status, e.g. "Not Found" or "OK".
|
||||
self.reason = None
|
||||
self.reason = None # type: ignore[assignment]
|
||||
|
||||
#: A CookieJar of Cookies the server sent back.
|
||||
self.cookies = cookiejar_from_dict({})
|
||||
@@ -700,15 +805,15 @@ class Response:
|
||||
|
||||
#: The :class:`PreparedRequest <PreparedRequest>` object to which this
|
||||
#: is a response.
|
||||
self.request = None
|
||||
self.request = None # type: ignore[assignment]
|
||||
|
||||
def __enter__(self):
|
||||
def __enter__(self) -> Self:
|
||||
return self
|
||||
|
||||
def __exit__(self, *args):
|
||||
def __exit__(self, *args: Any) -> None:
|
||||
self.close()
|
||||
|
||||
def __getstate__(self):
|
||||
def __getstate__(self) -> dict[str, Any]:
|
||||
# Consume everything; accessing the content attribute makes
|
||||
# sure the content has been fully read.
|
||||
if not self._content_consumed:
|
||||
@@ -716,7 +821,7 @@ class Response:
|
||||
|
||||
return {attr: getattr(self, attr, None) for attr in self.__attrs__}
|
||||
|
||||
def __setstate__(self, state):
|
||||
def __setstate__(self, state: dict[str, Any]) -> None:
|
||||
for name, value in state.items():
|
||||
setattr(self, name, value)
|
||||
|
||||
@@ -724,10 +829,10 @@ class Response:
|
||||
setattr(self, "_content_consumed", True)
|
||||
setattr(self, "raw", None)
|
||||
|
||||
def __repr__(self):
|
||||
def __repr__(self) -> str:
|
||||
return f"<Response [{self.status_code}]>"
|
||||
|
||||
def __bool__(self):
|
||||
def __bool__(self) -> bool:
|
||||
"""Returns True if :attr:`status_code` is less than 400.
|
||||
|
||||
This attribute checks if the status code of the response is between
|
||||
@@ -737,7 +842,7 @@ class Response:
|
||||
"""
|
||||
return self.ok
|
||||
|
||||
def __nonzero__(self):
|
||||
def __nonzero__(self) -> bool:
|
||||
"""Returns True if :attr:`status_code` is less than 400.
|
||||
|
||||
This attribute checks if the status code of the response is between
|
||||
@@ -747,12 +852,12 @@ class Response:
|
||||
"""
|
||||
return self.ok
|
||||
|
||||
def __iter__(self):
|
||||
def __iter__(self) -> Iterator[bytes]:
|
||||
"""Allows you to use a response as an iterator."""
|
||||
return self.iter_content(128)
|
||||
|
||||
@property
|
||||
def ok(self):
|
||||
def ok(self) -> bool:
|
||||
"""Returns True if :attr:`status_code` is less than 400, False if not.
|
||||
|
||||
This attribute checks if the status code of the response is between
|
||||
@@ -767,14 +872,14 @@ class Response:
|
||||
return True
|
||||
|
||||
@property
|
||||
def is_redirect(self):
|
||||
def is_redirect(self) -> bool:
|
||||
"""True if this Response is a well-formed HTTP redirect that could have
|
||||
been processed automatically (by :meth:`Session.resolve_redirects`).
|
||||
"""
|
||||
return "location" in self.headers and self.status_code in REDIRECT_STATI
|
||||
|
||||
@property
|
||||
def is_permanent_redirect(self):
|
||||
def is_permanent_redirect(self) -> bool:
|
||||
"""True if this Response one of the permanent versions of redirect."""
|
||||
return "location" in self.headers and self.status_code in (
|
||||
codes.moved_permanently,
|
||||
@@ -782,12 +887,12 @@ class Response:
|
||||
)
|
||||
|
||||
@property
|
||||
def next(self):
|
||||
def next(self) -> PreparedRequest | None:
|
||||
"""Returns a PreparedRequest for the next request in a redirect chain, if there is one."""
|
||||
return self._next
|
||||
|
||||
@property
|
||||
def apparent_encoding(self):
|
||||
def apparent_encoding(self) -> str | None:
|
||||
"""The apparent encoding, provided by the charset_normalizer or chardet libraries."""
|
||||
if chardet is not None:
|
||||
return chardet.detect(self.content)["encoding"]
|
||||
@@ -796,7 +901,17 @@ class Response:
|
||||
# to a standard Python utf-8 str.
|
||||
return "utf-8"
|
||||
|
||||
def iter_content(self, chunk_size=1, decode_unicode=False):
|
||||
@overload
|
||||
def iter_content(
|
||||
self, chunk_size: int | None = 1, decode_unicode: Literal[False] = False
|
||||
) -> Iterator[bytes]: ...
|
||||
@overload
|
||||
def iter_content(
|
||||
self, chunk_size: int | None = 1, *, decode_unicode: Literal[True]
|
||||
) -> Iterator[str | bytes]: ...
|
||||
def iter_content(
|
||||
self, chunk_size: int | None = 1, decode_unicode: bool = False
|
||||
) -> Iterator[str | bytes]:
|
||||
"""Iterates over the response data. When stream=True is set on the
|
||||
request, this avoids reading the content at once into memory for
|
||||
large responses. The chunk size is the number of bytes it should
|
||||
@@ -809,11 +924,13 @@ class Response:
|
||||
chunks are received. If stream=False, data is returned as
|
||||
a single chunk.
|
||||
|
||||
If decode_unicode is True, content will be decoded using the best
|
||||
available encoding based on the response.
|
||||
If decode_unicode is True, content will be decoded using encoding
|
||||
information from the response. If no encoding information is available,
|
||||
bytes will be returned. This can be bypassed by manually setting
|
||||
`encoding` on the response.
|
||||
"""
|
||||
|
||||
def generate():
|
||||
def generate() -> Generator[bytes, None, None]:
|
||||
# Special case for urllib3.
|
||||
if hasattr(self.raw, "stream"):
|
||||
try:
|
||||
@@ -838,42 +955,65 @@ class Response:
|
||||
|
||||
if self._content_consumed and isinstance(self._content, bool):
|
||||
raise StreamConsumedError()
|
||||
elif chunk_size is not None and not isinstance(chunk_size, int):
|
||||
elif chunk_size is not None and not isinstance(chunk_size, int): # type: ignore[reportUnnecessaryIsInstance] # runtime guard for untyped callers
|
||||
raise TypeError(
|
||||
f"chunk_size must be an int, it is instead a {type(chunk_size)}."
|
||||
)
|
||||
# simulate reading small chunks of the content
|
||||
reused_chunks = iter_slices(self._content, chunk_size)
|
||||
|
||||
stream_chunks = generate()
|
||||
|
||||
chunks = reused_chunks if self._content_consumed else stream_chunks
|
||||
if self._content_consumed:
|
||||
# simulate reading small chunks of the content
|
||||
content = cast(bytes, self._content)
|
||||
chunks = iter_slices(content, chunk_size)
|
||||
else:
|
||||
chunks = generate()
|
||||
|
||||
if decode_unicode:
|
||||
chunks = stream_decode_response_unicode(chunks, self)
|
||||
|
||||
return chunks
|
||||
|
||||
@overload
|
||||
def iter_lines(
|
||||
self, chunk_size=ITER_CHUNK_SIZE, decode_unicode=False, delimiter=None
|
||||
):
|
||||
self,
|
||||
chunk_size: int = ITER_CHUNK_SIZE,
|
||||
decode_unicode: Literal[False] = False,
|
||||
delimiter: bytes | None = None,
|
||||
) -> Iterator[bytes]: ...
|
||||
@overload
|
||||
def iter_lines(
|
||||
self,
|
||||
chunk_size: int = ITER_CHUNK_SIZE,
|
||||
*,
|
||||
decode_unicode: Literal[True],
|
||||
delimiter: str | bytes | None = None,
|
||||
) -> Iterator[str | bytes]: ...
|
||||
def iter_lines(
|
||||
self,
|
||||
chunk_size: int = ITER_CHUNK_SIZE,
|
||||
decode_unicode: bool = False,
|
||||
delimiter: str | bytes | None = None,
|
||||
) -> Iterator[str | bytes]:
|
||||
"""Iterates over the response data, one line at a time. When
|
||||
stream=True is set on the request, this avoids reading the
|
||||
content at once into memory for large responses.
|
||||
|
||||
The decode_unicode param works the same as in `iter_content`, with the
|
||||
same caveats.
|
||||
|
||||
.. note:: This method is not reentrant safe.
|
||||
"""
|
||||
|
||||
pending = None
|
||||
pending: str | bytes | None = None
|
||||
|
||||
for chunk in self.iter_content(
|
||||
chunk_size=chunk_size, decode_unicode=decode_unicode
|
||||
):
|
||||
if pending is not None:
|
||||
chunk = pending + chunk
|
||||
# TODO: remove cast after iter_lines rewrite
|
||||
chunk = cast("str | bytes", pending + chunk) # type: ignore[operator]
|
||||
|
||||
if delimiter:
|
||||
lines = chunk.split(delimiter)
|
||||
lines = chunk.split(delimiter) # type: ignore[arg-type]
|
||||
else:
|
||||
lines = chunk.splitlines()
|
||||
|
||||
@@ -888,7 +1028,7 @@ class Response:
|
||||
yield pending
|
||||
|
||||
@property
|
||||
def content(self):
|
||||
def content(self) -> bytes:
|
||||
"""Content of the response, in bytes."""
|
||||
|
||||
if self._content is False:
|
||||
@@ -904,10 +1044,10 @@ class Response:
|
||||
self._content_consumed = True
|
||||
# don't need to release the connection; that's been handled by urllib3
|
||||
# since we exhausted the data.
|
||||
return self._content
|
||||
return self._content # type: ignore[return-value]
|
||||
|
||||
@property
|
||||
def text(self):
|
||||
def text(self) -> str:
|
||||
"""Content of the response, in unicode.
|
||||
|
||||
If Response.encoding is None, encoding will be guessed using
|
||||
@@ -932,7 +1072,7 @@ class Response:
|
||||
|
||||
# Decode unicode from given encoding.
|
||||
try:
|
||||
content = str(self.content, encoding, errors="replace")
|
||||
content = str(self.content, encoding or "utf-8", errors="replace")
|
||||
except (LookupError, TypeError):
|
||||
# A LookupError is raised if the encoding was not found which could
|
||||
# indicate a misspelling or similar mistake.
|
||||
@@ -944,7 +1084,7 @@ class Response:
|
||||
|
||||
return content
|
||||
|
||||
def json(self, **kwargs):
|
||||
def json(self, **kwargs: Any) -> Any:
|
||||
r"""Decodes the JSON response body (if any) as a Python object.
|
||||
|
||||
This may return a dictionary, list, etc. depending on what is in the response.
|
||||
@@ -980,23 +1120,24 @@ class Response:
|
||||
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
|
||||
|
||||
@property
|
||||
def links(self):
|
||||
def links(self) -> dict[str, dict[str, str]]:
|
||||
"""Returns the parsed header links of the response, if any."""
|
||||
|
||||
header = self.headers.get("link")
|
||||
|
||||
resolved_links = {}
|
||||
resolved_links: dict[str, dict[str, str]] = {}
|
||||
|
||||
if header:
|
||||
links = parse_header_links(header)
|
||||
|
||||
for link in links:
|
||||
key = link.get("rel") or link.get("url")
|
||||
resolved_links[key] = link
|
||||
if key is not None:
|
||||
resolved_links[key] = link
|
||||
|
||||
return resolved_links
|
||||
|
||||
def raise_for_status(self):
|
||||
def raise_for_status(self) -> None:
|
||||
"""Raises :class:`HTTPError`, if one occurred."""
|
||||
|
||||
http_error_msg = ""
|
||||
@@ -1025,7 +1166,7 @@ class Response:
|
||||
if http_error_msg:
|
||||
raise HTTPError(http_error_msg, response=self)
|
||||
|
||||
def close(self):
|
||||
def close(self) -> None:
|
||||
"""Releases the connection back to the pool. Once this method has been
|
||||
called the underlying ``raw`` object must not be accessed again.
|
||||
|
||||
|
||||
@@ -5,16 +5,22 @@ requests.sessions
|
||||
This module provides a Session object to manage and persist settings across
|
||||
requests (cookies, auth, proxies).
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
from collections import OrderedDict
|
||||
from collections.abc import Generator, Mapping, MutableMapping
|
||||
from datetime import timedelta
|
||||
from typing import TYPE_CHECKING, Any, cast
|
||||
|
||||
from ._internal_utils import to_native_string
|
||||
from ._types import is_prepared as _is_prepared
|
||||
from .adapters import HTTPAdapter
|
||||
from .auth import _basic_auth_str
|
||||
from .compat import Mapping, cookielib, urljoin, urlparse
|
||||
from .auth import _basic_auth_str # type: ignore[reportPrivateUsage]
|
||||
from .compat import cookielib, urljoin, urlparse
|
||||
from .cookies import (
|
||||
RequestsCookieJar,
|
||||
cookiejar_from_dict,
|
||||
@@ -32,9 +38,10 @@ from .hooks import default_hooks, dispatch_hook
|
||||
# formerly defined here, reexposed here for backward compatibility
|
||||
from .models import ( # noqa: F401
|
||||
DEFAULT_REDIRECT_LIMIT,
|
||||
REDIRECT_STATI,
|
||||
REDIRECT_STATI, # type: ignore[reportUnusedImport]
|
||||
PreparedRequest,
|
||||
Request,
|
||||
Response,
|
||||
)
|
||||
from .status_codes import codes
|
||||
from .structures import CaseInsensitiveDict
|
||||
@@ -47,10 +54,18 @@ from .utils import ( # noqa: F401
|
||||
requote_uri,
|
||||
resolve_proxies,
|
||||
rewind_body,
|
||||
should_bypass_proxies,
|
||||
should_bypass_proxies, # type: ignore[reportUnusedImport] # re-export for external consumers
|
||||
to_key_val_list,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from http.cookiejar import CookieJar
|
||||
|
||||
from typing_extensions import Self, Unpack
|
||||
|
||||
from . import _types as _t
|
||||
from .adapters import BaseAdapter
|
||||
|
||||
# Preferred clock, based on which one is more accurate on a given system.
|
||||
if sys.platform == "win32":
|
||||
preferred_clock = time.perf_counter
|
||||
@@ -58,7 +73,9 @@ else:
|
||||
preferred_clock = time.time
|
||||
|
||||
|
||||
def merge_setting(request_setting, session_setting, dict_class=OrderedDict):
|
||||
def merge_setting(
|
||||
request_setting: Any, session_setting: Any, dict_class: type = OrderedDict
|
||||
) -> Any:
|
||||
"""Determines appropriate setting for a given request, taking into account
|
||||
the explicit setting on that request, and the setting in the session. If a
|
||||
setting is a dictionary, they will be merged together using `dict_class`
|
||||
@@ -76,8 +93,8 @@ def merge_setting(request_setting, session_setting, dict_class=OrderedDict):
|
||||
):
|
||||
return request_setting
|
||||
|
||||
merged_setting = dict_class(to_key_val_list(session_setting))
|
||||
merged_setting.update(to_key_val_list(request_setting))
|
||||
merged_setting = dict_class(to_key_val_list(session_setting)) # type: ignore[arg-type] # isinstance narrows Any to Mapping[Unknown]
|
||||
merged_setting.update(to_key_val_list(request_setting)) # type: ignore[arg-type]
|
||||
|
||||
# Remove keys that are set to None. Extract keys first to avoid altering
|
||||
# the dictionary during iteration.
|
||||
@@ -88,7 +105,11 @@ def merge_setting(request_setting, session_setting, dict_class=OrderedDict):
|
||||
return merged_setting
|
||||
|
||||
|
||||
def merge_hooks(request_hooks, session_hooks, dict_class=OrderedDict):
|
||||
def merge_hooks(
|
||||
request_hooks: _t.HooksType,
|
||||
session_hooks: _t.HooksType,
|
||||
dict_class: type = OrderedDict,
|
||||
) -> _t.HooksType:
|
||||
"""Properly merges both requests and session hooks.
|
||||
|
||||
This is necessary because when request_hooks == {'response': []}, the
|
||||
@@ -104,7 +125,13 @@ def merge_hooks(request_hooks, session_hooks, dict_class=OrderedDict):
|
||||
|
||||
|
||||
class SessionRedirectMixin:
|
||||
def get_redirect_target(self, resp):
|
||||
max_redirects: int
|
||||
trust_env: bool
|
||||
cookies: RequestsCookieJar
|
||||
|
||||
def send(self, request: PreparedRequest, **kwargs: Any) -> Response: ...
|
||||
|
||||
def get_redirect_target(self, resp: Response) -> str | None:
|
||||
"""Receives a Response. Returns a redirect URI or ``None``"""
|
||||
# Due to the nature of how requests processes redirects this method will
|
||||
# be called at least once upon the original response and at least twice
|
||||
@@ -124,7 +151,7 @@ class SessionRedirectMixin:
|
||||
return to_native_string(location, "utf8")
|
||||
return None
|
||||
|
||||
def should_strip_auth(self, old_url, new_url):
|
||||
def should_strip_auth(self, old_url: str, new_url: str) -> bool:
|
||||
"""Decide whether Authorization header should be removed when redirecting"""
|
||||
old_parsed = urlparse(old_url)
|
||||
new_parsed = urlparse(new_url)
|
||||
@@ -158,19 +185,19 @@ class SessionRedirectMixin:
|
||||
|
||||
def resolve_redirects(
|
||||
self,
|
||||
resp,
|
||||
req,
|
||||
stream=False,
|
||||
timeout=None,
|
||||
verify=True,
|
||||
cert=None,
|
||||
proxies=None,
|
||||
yield_requests=False,
|
||||
**adapter_kwargs,
|
||||
):
|
||||
resp: Response,
|
||||
req: PreparedRequest,
|
||||
stream: bool = False,
|
||||
timeout: _t.TimeoutType = None,
|
||||
verify: _t.VerifyType = True,
|
||||
cert: _t.CertType = None,
|
||||
proxies: dict[str, str] | None = None,
|
||||
yield_requests: bool = False,
|
||||
**adapter_kwargs: Any,
|
||||
) -> Generator[Response, None, None]:
|
||||
"""Receives a Response. Returns a generator of Responses or Requests."""
|
||||
|
||||
hist = [] # keep track of history
|
||||
hist: list[Response] = [] # keep track of history
|
||||
|
||||
url = self.get_redirect_target(resp)
|
||||
previous_fragment = urlparse(req.url).fragment
|
||||
@@ -178,9 +205,8 @@ class SessionRedirectMixin:
|
||||
prepared_request = req.copy()
|
||||
|
||||
# Update history and keep track of redirects.
|
||||
# resp.history must ignore the original request in this loop
|
||||
resp.history = hist[:]
|
||||
hist.append(resp)
|
||||
resp.history = hist[1:]
|
||||
|
||||
try:
|
||||
resp.content # Consume socket so it can be released
|
||||
@@ -237,9 +263,10 @@ class SessionRedirectMixin:
|
||||
# Extract any cookies sent on the response to the cookiejar
|
||||
# in the new request. Because we've mutated our copied prepared
|
||||
# request, use the old one that we haven't yet touched.
|
||||
extract_cookies_to_jar(prepared_request._cookies, req, resp.raw)
|
||||
merge_cookies(prepared_request._cookies, self.cookies)
|
||||
prepared_request.prepare_cookies(prepared_request._cookies)
|
||||
cookie_jar = cast("CookieJar", prepared_request._cookies) # type: ignore[reportPrivateUsage]
|
||||
extract_cookies_to_jar(cookie_jar, req, resp.raw)
|
||||
merge_cookies(cookie_jar, self.cookies)
|
||||
prepared_request.prepare_cookies(cookie_jar)
|
||||
|
||||
# Rebuild auth and proxy information.
|
||||
proxies = self.rebuild_proxies(prepared_request, proxies)
|
||||
@@ -248,7 +275,7 @@ class SessionRedirectMixin:
|
||||
# A failed tell() sets `_body_position` to `object()`. This non-None
|
||||
# value ensures `rewindable` will be True, allowing us to raise an
|
||||
# UnrewindableBodyError, instead of hanging the connection.
|
||||
rewindable = prepared_request._body_position is not None and (
|
||||
rewindable = prepared_request._body_position is not None and ( # type: ignore[reportPrivateUsage]
|
||||
"Content-Length" in headers or "Transfer-Encoding" in headers
|
||||
)
|
||||
|
||||
@@ -260,7 +287,7 @@ class SessionRedirectMixin:
|
||||
req = prepared_request
|
||||
|
||||
if yield_requests:
|
||||
yield req
|
||||
yield req # type: ignore[misc] # Internal use only, returns PreparedRequest
|
||||
else:
|
||||
resp = self.send(
|
||||
req,
|
||||
@@ -279,17 +306,22 @@ class SessionRedirectMixin:
|
||||
url = self.get_redirect_target(resp)
|
||||
yield resp
|
||||
|
||||
def rebuild_auth(self, prepared_request, response):
|
||||
def rebuild_auth(
|
||||
self, prepared_request: PreparedRequest, response: Response
|
||||
) -> None:
|
||||
"""When being redirected we may want to strip authentication from the
|
||||
request to avoid leaking credentials. This method intelligently removes
|
||||
and reapplies authentication where possible to avoid credential loss.
|
||||
"""
|
||||
original_request = response.request
|
||||
assert _is_prepared(original_request)
|
||||
assert _is_prepared(prepared_request)
|
||||
|
||||
headers = prepared_request.headers
|
||||
original_url = original_request.url
|
||||
url = prepared_request.url
|
||||
|
||||
if "Authorization" in headers and self.should_strip_auth(
|
||||
response.request.url, url
|
||||
):
|
||||
if "Authorization" in headers and self.should_strip_auth(original_url, url):
|
||||
# If we get redirected to a new host, we should strip out any
|
||||
# authentication headers.
|
||||
del headers["Authorization"]
|
||||
@@ -299,7 +331,11 @@ class SessionRedirectMixin:
|
||||
if new_auth is not None:
|
||||
prepared_request.prepare_auth(new_auth)
|
||||
|
||||
def rebuild_proxies(self, prepared_request, proxies):
|
||||
def rebuild_proxies(
|
||||
self,
|
||||
prepared_request: PreparedRequest,
|
||||
proxies: dict[str, str] | None,
|
||||
) -> dict[str, str]:
|
||||
"""This method re-evaluates the proxy configuration by considering the
|
||||
environment variables. If we are redirected to a URL covered by
|
||||
NO_PROXY, we strip the proxy configuration. Otherwise, we set missing
|
||||
@@ -311,6 +347,7 @@ class SessionRedirectMixin:
|
||||
|
||||
:rtype: dict
|
||||
"""
|
||||
assert _is_prepared(prepared_request)
|
||||
headers = prepared_request.headers
|
||||
scheme = urlparse(prepared_request.url).scheme
|
||||
new_proxies = resolve_proxies(prepared_request, proxies, self.trust_env)
|
||||
@@ -330,7 +367,9 @@ class SessionRedirectMixin:
|
||||
|
||||
return new_proxies
|
||||
|
||||
def rebuild_method(self, prepared_request, response):
|
||||
def rebuild_method(
|
||||
self, prepared_request: PreparedRequest, response: Response
|
||||
) -> None:
|
||||
"""When being redirected we may want to change the method of the request
|
||||
based on certain specs or browser behavior.
|
||||
"""
|
||||
@@ -372,7 +411,20 @@ class Session(SessionRedirectMixin):
|
||||
<Response [200]>
|
||||
"""
|
||||
|
||||
__attrs__ = [
|
||||
headers: CaseInsensitiveDict[str]
|
||||
auth: _t.AuthType
|
||||
proxies: dict[str, str]
|
||||
hooks: dict[str, list[_t.HookType]]
|
||||
params: MutableMapping[str, Any]
|
||||
stream: bool
|
||||
verify: _t.VerifyType
|
||||
cert: _t.CertType
|
||||
max_redirects: int
|
||||
trust_env: bool
|
||||
cookies: RequestsCookieJar
|
||||
adapters: MutableMapping[str, BaseAdapter]
|
||||
|
||||
__attrs__: list[str] = [
|
||||
"headers",
|
||||
"cookies",
|
||||
"auth",
|
||||
@@ -387,7 +439,7 @@ class Session(SessionRedirectMixin):
|
||||
"max_redirects",
|
||||
]
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self) -> None:
|
||||
#: A case-insensitive dictionary of headers to be sent on each
|
||||
#: :class:`Request <Request>` sent from this
|
||||
#: :class:`Session <Session>`.
|
||||
@@ -421,6 +473,8 @@ class Session(SessionRedirectMixin):
|
||||
#: expired certificates, which will make your application vulnerable to
|
||||
#: man-in-the-middle (MitM) attacks.
|
||||
#: Only set this to `False` for testing.
|
||||
#: If verify is set to a string, it must be the path to a CA bundle file
|
||||
#: that will be used to verify the TLS certificate.
|
||||
self.verify = True
|
||||
|
||||
#: SSL client certificate default, if String, path to ssl client
|
||||
@@ -448,13 +502,13 @@ class Session(SessionRedirectMixin):
|
||||
self.mount("https://", HTTPAdapter())
|
||||
self.mount("http://", HTTPAdapter())
|
||||
|
||||
def __enter__(self):
|
||||
def __enter__(self) -> Self:
|
||||
return self
|
||||
|
||||
def __exit__(self, *args):
|
||||
def __exit__(self, *args: Any) -> None:
|
||||
self.close()
|
||||
|
||||
def prepare_request(self, request):
|
||||
def prepare_request(self, request: Request) -> PreparedRequest:
|
||||
"""Constructs a :class:`PreparedRequest <PreparedRequest>` for
|
||||
transmission and returns it. The :class:`PreparedRequest` has settings
|
||||
merged from the :class:`Request <Request>` instance and those of the
|
||||
@@ -464,6 +518,9 @@ class Session(SessionRedirectMixin):
|
||||
session's settings.
|
||||
:rtype: requests.PreparedRequest
|
||||
"""
|
||||
url = cast("_t.UriType", request.url)
|
||||
method = cast(str, request.method)
|
||||
|
||||
cookies = request.cookies or {}
|
||||
|
||||
# Bootstrap CookieJar.
|
||||
@@ -478,12 +535,12 @@ class Session(SessionRedirectMixin):
|
||||
# Set environment's basic authentication if not explicitly set.
|
||||
auth = request.auth
|
||||
if self.trust_env and not auth and not self.auth:
|
||||
auth = get_netrc_auth(request.url)
|
||||
auth = get_netrc_auth(url)
|
||||
|
||||
p = PreparedRequest()
|
||||
p.prepare(
|
||||
method=request.method.upper(),
|
||||
url=request.url,
|
||||
method=method.upper(),
|
||||
url=url,
|
||||
files=request.files,
|
||||
data=request.data,
|
||||
json=request.json,
|
||||
@@ -499,23 +556,23 @@ class Session(SessionRedirectMixin):
|
||||
|
||||
def request(
|
||||
self,
|
||||
method,
|
||||
url,
|
||||
params=None,
|
||||
data=None,
|
||||
headers=None,
|
||||
cookies=None,
|
||||
files=None,
|
||||
auth=None,
|
||||
timeout=None,
|
||||
allow_redirects=True,
|
||||
proxies=None,
|
||||
hooks=None,
|
||||
stream=None,
|
||||
verify=None,
|
||||
cert=None,
|
||||
json=None,
|
||||
):
|
||||
method: str,
|
||||
url: _t.UriType,
|
||||
params: _t.ParamsType = None,
|
||||
data: _t.DataType = None,
|
||||
headers: _t.HeadersType = None,
|
||||
cookies: RequestsCookieJar | CookieJar | dict[str, str] | None = None,
|
||||
files: _t.FilesType = None,
|
||||
auth: _t.AuthType = None,
|
||||
timeout: _t.TimeoutType = None,
|
||||
allow_redirects: bool = True,
|
||||
proxies: dict[str, str] | None = None,
|
||||
hooks: _t.HooksInputType | None = None,
|
||||
stream: bool | None = None,
|
||||
verify: _t.VerifyType | None = None,
|
||||
cert: _t.CertType = None,
|
||||
json: _t.JsonType = None,
|
||||
) -> Response:
|
||||
"""Constructs a :class:`Request <Request>`, prepares it and sends it.
|
||||
Returns :class:`Response <Response>` object.
|
||||
|
||||
@@ -559,6 +616,9 @@ class Session(SessionRedirectMixin):
|
||||
If Tuple, ('cert', 'key') pair.
|
||||
:rtype: requests.Response
|
||||
"""
|
||||
if isinstance(url, bytes):
|
||||
url = url.decode("utf-8")
|
||||
|
||||
# Create the Request.
|
||||
req = Request(
|
||||
method=method.upper(),
|
||||
@@ -574,6 +634,8 @@ class Session(SessionRedirectMixin):
|
||||
)
|
||||
prep = self.prepare_request(req)
|
||||
|
||||
assert _is_prepared(prep)
|
||||
|
||||
proxies = proxies or {}
|
||||
|
||||
settings = self.merge_environment_settings(
|
||||
@@ -590,18 +652,25 @@ class Session(SessionRedirectMixin):
|
||||
|
||||
return resp
|
||||
|
||||
def get(self, url, **kwargs):
|
||||
def get(
|
||||
self,
|
||||
url: _t.UriType,
|
||||
params: _t.ParamsType = None,
|
||||
**kwargs: Unpack[_t.GetKwargs],
|
||||
) -> Response:
|
||||
r"""Sends a GET request. Returns :class:`Response` object.
|
||||
|
||||
:param url: URL for the new :class:`Request` object.
|
||||
:param params: (optional) Dictionary, list of tuples or bytes to send
|
||||
in the query string for the :class:`Request`.
|
||||
:param \*\*kwargs: Optional arguments that ``request`` takes.
|
||||
:rtype: requests.Response
|
||||
"""
|
||||
|
||||
kwargs.setdefault("allow_redirects", True)
|
||||
return self.request("GET", url, **kwargs)
|
||||
return self.request("GET", url, params=params, **kwargs)
|
||||
|
||||
def options(self, url, **kwargs):
|
||||
def options(self, url: _t.UriType, **kwargs: Unpack[_t.RequestKwargs]) -> Response:
|
||||
r"""Sends a OPTIONS request. Returns :class:`Response` object.
|
||||
|
||||
:param url: URL for the new :class:`Request` object.
|
||||
@@ -612,7 +681,7 @@ class Session(SessionRedirectMixin):
|
||||
kwargs.setdefault("allow_redirects", True)
|
||||
return self.request("OPTIONS", url, **kwargs)
|
||||
|
||||
def head(self, url, **kwargs):
|
||||
def head(self, url: _t.UriType, **kwargs: Unpack[_t.RequestKwargs]) -> Response:
|
||||
r"""Sends a HEAD request. Returns :class:`Response` object.
|
||||
|
||||
:param url: URL for the new :class:`Request` object.
|
||||
@@ -623,7 +692,13 @@ class Session(SessionRedirectMixin):
|
||||
kwargs.setdefault("allow_redirects", False)
|
||||
return self.request("HEAD", url, **kwargs)
|
||||
|
||||
def post(self, url, data=None, json=None, **kwargs):
|
||||
def post(
|
||||
self,
|
||||
url: _t.UriType,
|
||||
data: _t.DataType = None,
|
||||
json: _t.JsonType = None,
|
||||
**kwargs: Unpack[_t.PostKwargs],
|
||||
) -> Response:
|
||||
r"""Sends a POST request. Returns :class:`Response` object.
|
||||
|
||||
:param url: URL for the new :class:`Request` object.
|
||||
@@ -636,7 +711,9 @@ class Session(SessionRedirectMixin):
|
||||
|
||||
return self.request("POST", url, data=data, json=json, **kwargs)
|
||||
|
||||
def put(self, url, data=None, **kwargs):
|
||||
def put(
|
||||
self, url: _t.UriType, data: _t.DataType = None, **kwargs: Unpack[_t.DataKwargs]
|
||||
) -> Response:
|
||||
r"""Sends a PUT request. Returns :class:`Response` object.
|
||||
|
||||
:param url: URL for the new :class:`Request` object.
|
||||
@@ -648,7 +725,9 @@ class Session(SessionRedirectMixin):
|
||||
|
||||
return self.request("PUT", url, data=data, **kwargs)
|
||||
|
||||
def patch(self, url, data=None, **kwargs):
|
||||
def patch(
|
||||
self, url: _t.UriType, data: _t.DataType = None, **kwargs: Unpack[_t.DataKwargs]
|
||||
) -> Response:
|
||||
r"""Sends a PATCH request. Returns :class:`Response` object.
|
||||
|
||||
:param url: URL for the new :class:`Request` object.
|
||||
@@ -660,7 +739,7 @@ class Session(SessionRedirectMixin):
|
||||
|
||||
return self.request("PATCH", url, data=data, **kwargs)
|
||||
|
||||
def delete(self, url, **kwargs):
|
||||
def delete(self, url: _t.UriType, **kwargs: Unpack[_t.RequestKwargs]) -> Response:
|
||||
r"""Sends a DELETE request. Returns :class:`Response` object.
|
||||
|
||||
:param url: URL for the new :class:`Request` object.
|
||||
@@ -670,7 +749,7 @@ class Session(SessionRedirectMixin):
|
||||
|
||||
return self.request("DELETE", url, **kwargs)
|
||||
|
||||
def send(self, request, **kwargs):
|
||||
def send(self, request: PreparedRequest, **kwargs: Any) -> Response:
|
||||
"""Send a given PreparedRequest.
|
||||
|
||||
:rtype: requests.Response
|
||||
@@ -688,6 +767,8 @@ class Session(SessionRedirectMixin):
|
||||
if isinstance(request, Request):
|
||||
raise ValueError("You can only send PreparedRequests.")
|
||||
|
||||
assert _is_prepared(request)
|
||||
|
||||
# Set up variables needed for resolve_redirects and dispatching of hooks
|
||||
allow_redirects = kwargs.pop("allow_redirects", True)
|
||||
stream = kwargs.get("stream")
|
||||
@@ -736,7 +817,7 @@ class Session(SessionRedirectMixin):
|
||||
# If redirects aren't being followed, store the response on the Request for Response.next().
|
||||
if not allow_redirects:
|
||||
try:
|
||||
r._next = next(
|
||||
r._next = next( # type: ignore[assignment] # yield_requests=True returns PreparedRequest
|
||||
self.resolve_redirects(r, request, yield_requests=True, **kwargs)
|
||||
)
|
||||
except StopIteration:
|
||||
@@ -747,7 +828,14 @@ class Session(SessionRedirectMixin):
|
||||
|
||||
return r
|
||||
|
||||
def merge_environment_settings(self, url, proxies, stream, verify, cert):
|
||||
def merge_environment_settings(
|
||||
self,
|
||||
url: str,
|
||||
proxies: dict[str, str] | None,
|
||||
stream: bool | None,
|
||||
verify: _t.VerifyType | None,
|
||||
cert: _t.CertType,
|
||||
) -> dict[str, Any]:
|
||||
"""
|
||||
Check the environment and merge it with some settings.
|
||||
|
||||
@@ -758,8 +846,9 @@ class Session(SessionRedirectMixin):
|
||||
# Set environment's proxies.
|
||||
no_proxy = proxies.get("no_proxy") if proxies is not None else None
|
||||
env_proxies = get_environ_proxies(url, no_proxy=no_proxy)
|
||||
for k, v in env_proxies.items():
|
||||
proxies.setdefault(k, v)
|
||||
if proxies is not None:
|
||||
for k, v in env_proxies.items():
|
||||
proxies.setdefault(k, v)
|
||||
|
||||
# Look for requests environment configuration
|
||||
# and be compatible with cURL.
|
||||
@@ -778,7 +867,7 @@ class Session(SessionRedirectMixin):
|
||||
|
||||
return {"proxies": proxies, "stream": stream, "verify": verify, "cert": cert}
|
||||
|
||||
def get_adapter(self, url):
|
||||
def get_adapter(self, url: str) -> BaseAdapter:
|
||||
"""
|
||||
Returns the appropriate connection adapter for the given URL.
|
||||
|
||||
@@ -791,12 +880,12 @@ class Session(SessionRedirectMixin):
|
||||
# Nothing matches :-/
|
||||
raise InvalidSchema(f"No connection adapters were found for {url!r}")
|
||||
|
||||
def close(self):
|
||||
def close(self) -> None:
|
||||
"""Closes all adapters and as such the session"""
|
||||
for v in self.adapters.values():
|
||||
v.close()
|
||||
|
||||
def mount(self, prefix, adapter):
|
||||
def mount(self, prefix: str, adapter: BaseAdapter) -> None:
|
||||
"""Registers a connection adapter to a prefix.
|
||||
|
||||
Adapters are sorted in descending order by prefix length.
|
||||
@@ -807,16 +896,16 @@ class Session(SessionRedirectMixin):
|
||||
for key in keys_to_move:
|
||||
self.adapters[key] = self.adapters.pop(key)
|
||||
|
||||
def __getstate__(self):
|
||||
def __getstate__(self) -> dict[str, Any]:
|
||||
state = {attr: getattr(self, attr, None) for attr in self.__attrs__}
|
||||
return state
|
||||
|
||||
def __setstate__(self, state):
|
||||
def __setstate__(self, state: dict[str, Any]) -> None:
|
||||
for attr, value in state.items():
|
||||
setattr(self, attr, value)
|
||||
|
||||
|
||||
def session():
|
||||
def session() -> Session:
|
||||
"""
|
||||
Returns a :class:`Session` for context-management.
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ _codes = {
|
||||
511: ("network_authentication_required", "network_auth", "network_authentication"),
|
||||
}
|
||||
|
||||
codes = LookupDict(name="status_codes")
|
||||
codes: LookupDict[int] = LookupDict(name="status_codes")
|
||||
|
||||
|
||||
def _init():
|
||||
@@ -113,7 +113,7 @@ def _init():
|
||||
if not title.startswith(("\\", "/")):
|
||||
setattr(codes, title.upper(), code)
|
||||
|
||||
def doc(code):
|
||||
def doc(code: int) -> str:
|
||||
names = ", ".join(f"``{n}``" for n in _codes[code])
|
||||
return "* %d: %s" % (code, names)
|
||||
|
||||
|
||||
@@ -5,12 +5,19 @@ requests.structures
|
||||
Data structures that power Requests.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections import OrderedDict
|
||||
from collections.abc import Iterable, Iterator, Mapping
|
||||
from typing import Any, Generic, TypeVar, overload
|
||||
|
||||
from .compat import Mapping, MutableMapping
|
||||
from .compat import MutableMapping
|
||||
|
||||
_VT = TypeVar("_VT")
|
||||
_D = TypeVar("_D")
|
||||
|
||||
|
||||
class CaseInsensitiveDict(MutableMapping):
|
||||
class CaseInsensitiveDict(MutableMapping[str, _VT], Generic[_VT]):
|
||||
"""A case-insensitive ``dict``-like object.
|
||||
|
||||
Implements all methods and operations of
|
||||
@@ -37,63 +44,87 @@ class CaseInsensitiveDict(MutableMapping):
|
||||
behavior is undefined.
|
||||
"""
|
||||
|
||||
def __init__(self, data=None, **kwargs):
|
||||
_store: OrderedDict[str, tuple[str, _VT]]
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
data: Mapping[str, _VT] | Iterable[tuple[str, _VT]] | None = None,
|
||||
**kwargs: _VT,
|
||||
) -> None:
|
||||
self._store = OrderedDict()
|
||||
if data is None:
|
||||
data = {}
|
||||
self.update(data, **kwargs)
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
def __setitem__(self, key: str, value: _VT) -> None:
|
||||
# Use the lowercased key for lookups, but store the actual
|
||||
# key alongside the value.
|
||||
self._store[key.lower()] = (key, value)
|
||||
|
||||
def __getitem__(self, key):
|
||||
def __getitem__(self, key: str) -> _VT:
|
||||
return self._store[key.lower()][1]
|
||||
|
||||
def __delitem__(self, key):
|
||||
def __delitem__(self, key: str) -> None:
|
||||
del self._store[key.lower()]
|
||||
|
||||
def __iter__(self):
|
||||
return (casedkey for casedkey, mappedvalue in self._store.values())
|
||||
def __iter__(self) -> Iterator[str]:
|
||||
return (casedkey for casedkey, _ in self._store.values())
|
||||
|
||||
def __len__(self):
|
||||
def __len__(self) -> int:
|
||||
return len(self._store)
|
||||
|
||||
def lower_items(self):
|
||||
def lower_items(self) -> Iterator[tuple[str, _VT]]:
|
||||
"""Like iteritems(), but with all lowercase keys."""
|
||||
return ((lowerkey, keyval[1]) for (lowerkey, keyval) in self._store.items())
|
||||
|
||||
def __eq__(self, other):
|
||||
def __eq__(self, other: object) -> bool:
|
||||
if isinstance(other, Mapping):
|
||||
other = CaseInsensitiveDict(other)
|
||||
other_dict: CaseInsensitiveDict[Any] = CaseInsensitiveDict(other) # type: ignore[reportUnknownArgumentType]
|
||||
else:
|
||||
return NotImplemented
|
||||
# Compare insensitively
|
||||
return dict(self.lower_items()) == dict(other.lower_items())
|
||||
return dict(self.lower_items()) == dict(other_dict.lower_items())
|
||||
|
||||
# Copy is required
|
||||
def copy(self):
|
||||
def copy(self) -> CaseInsensitiveDict[_VT]:
|
||||
return CaseInsensitiveDict(self._store.values())
|
||||
|
||||
def __repr__(self):
|
||||
def __repr__(self) -> str:
|
||||
return str(dict(self.items()))
|
||||
|
||||
|
||||
class LookupDict(dict):
|
||||
class LookupDict(dict[str, _VT]):
|
||||
"""Dictionary lookup object."""
|
||||
|
||||
def __init__(self, name=None):
|
||||
name: Any
|
||||
|
||||
def __init__(self, name: Any = None) -> None:
|
||||
self.name = name
|
||||
super().__init__()
|
||||
|
||||
def __repr__(self):
|
||||
def __repr__(self) -> str:
|
||||
return f"<lookup '{self.name}'>"
|
||||
|
||||
def __getitem__(self, key):
|
||||
def __getattr__(self, key: str) -> _VT | None:
|
||||
# We need this for type checkers to infer typing
|
||||
# on attribute access with status_codes.py
|
||||
if key in self.__dict__:
|
||||
return self.__dict__[key]
|
||||
else:
|
||||
raise AttributeError(
|
||||
f"'{type(self).__name__}' object has no attribute '{key}'"
|
||||
)
|
||||
|
||||
def __getitem__(self, key: str) -> _VT | None: # type: ignore[override]
|
||||
# We allow fall-through here, so values default to None
|
||||
|
||||
return self.__dict__.get(key, None)
|
||||
|
||||
def get(self, key, default=None):
|
||||
@overload
|
||||
def get(self, key: str, default: None = None) -> _VT | None: ...
|
||||
|
||||
@overload
|
||||
def get(self, key: str, default: _D | _VT) -> _D | _VT: ...
|
||||
|
||||
def get(self, key: str, default: _D | None = None) -> _VT | _D | None:
|
||||
return self.__dict__.get(key, default)
|
||||
@@ -6,6 +6,8 @@ This module provides utility functions that are used within Requests
|
||||
that are also useful for external consumption.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import codecs
|
||||
import contextlib
|
||||
import io
|
||||
@@ -18,6 +20,15 @@ import tempfile
|
||||
import warnings
|
||||
import zipfile
|
||||
from collections import OrderedDict
|
||||
from collections.abc import Generator, Iterable
|
||||
from typing import (
|
||||
TYPE_CHECKING,
|
||||
Any,
|
||||
Final,
|
||||
TypeVar,
|
||||
cast,
|
||||
overload,
|
||||
)
|
||||
|
||||
from pip._vendor.urllib3.util import make_headers, parse_url
|
||||
|
||||
@@ -26,30 +37,28 @@ from .__version__ import __version__
|
||||
|
||||
# to_native_string is unused here, but imported here for backwards compatibility
|
||||
from ._internal_utils import ( # noqa: F401
|
||||
_HEADER_VALIDATORS_BYTE,
|
||||
_HEADER_VALIDATORS_STR,
|
||||
HEADER_VALIDATORS,
|
||||
to_native_string,
|
||||
_HEADER_VALIDATORS_BYTE, # type: ignore[reportPrivateUsage]
|
||||
_HEADER_VALIDATORS_STR, # type: ignore[reportPrivateUsage]
|
||||
HEADER_VALIDATORS, # type: ignore[reportUnusedImport]
|
||||
to_native_string, # type: ignore[reportUnusedImport]
|
||||
)
|
||||
from ._types import SupportsItems as _SupportsItems
|
||||
from .compat import (
|
||||
Mapping,
|
||||
basestring,
|
||||
bytes,
|
||||
getproxies,
|
||||
getproxies_environment,
|
||||
integer_types,
|
||||
is_urllib3_1,
|
||||
)
|
||||
from .compat import parse_http_list as _parse_list_header
|
||||
from .compat import (
|
||||
proxy_bypass,
|
||||
proxy_bypass_environment,
|
||||
proxy_bypass_environment, # type: ignore[attr-defined] # https://github.com/python/cpython/issues/145331
|
||||
quote,
|
||||
str,
|
||||
unquote,
|
||||
urlparse,
|
||||
urlunparse,
|
||||
)
|
||||
from .compat import parse_http_list as _parse_list_header
|
||||
from .cookies import cookiejar_from_dict
|
||||
from .exceptions import (
|
||||
FileModeWarning,
|
||||
@@ -59,14 +68,27 @@ from .exceptions import (
|
||||
)
|
||||
from .structures import CaseInsensitiveDict
|
||||
|
||||
NETRC_FILES = (".netrc", "_netrc")
|
||||
if TYPE_CHECKING:
|
||||
from http.cookiejar import CookieJar
|
||||
from io import BufferedWriter
|
||||
|
||||
DEFAULT_CA_BUNDLE_PATH = certs.where()
|
||||
from . import _types as _t
|
||||
from .models import PreparedRequest, Request, Response
|
||||
|
||||
DEFAULT_PORTS = {"http": 80, "https": 443}
|
||||
NETRC_FILES: Final = (".netrc", "_netrc")
|
||||
|
||||
|
||||
# Certificate is extracted by certifi when needed.
|
||||
DEFAULT_CA_BUNDLE_PATH: str = certs.where()
|
||||
|
||||
|
||||
DEFAULT_PORTS: Final = {"http": 80, "https": 443}
|
||||
|
||||
_KT = TypeVar("_KT")
|
||||
_VT = TypeVar("_VT")
|
||||
|
||||
# Ensure that ', ' is used to preserve previous delimiter behavior.
|
||||
DEFAULT_ACCEPT_ENCODING = ", ".join(
|
||||
DEFAULT_ACCEPT_ENCODING: Final = ", ".join(
|
||||
re.split(r",\s*", make_headers(accept_encoding=True)["accept-encoding"])
|
||||
)
|
||||
|
||||
@@ -74,7 +96,7 @@ DEFAULT_ACCEPT_ENCODING = ", ".join(
|
||||
if sys.platform == "win32":
|
||||
# provide a proxy_bypass version on Windows without DNS lookups
|
||||
|
||||
def proxy_bypass_registry(host):
|
||||
def proxy_bypass_registry(host: str) -> bool:
|
||||
try:
|
||||
import winreg
|
||||
except ImportError:
|
||||
@@ -112,7 +134,7 @@ if sys.platform == "win32":
|
||||
return True
|
||||
return False
|
||||
|
||||
def proxy_bypass(host): # noqa
|
||||
def proxy_bypass(host: str) -> bool: # noqa
|
||||
"""Return True, if the host should be bypassed.
|
||||
|
||||
Checks proxy settings gathered from the environment, if specified,
|
||||
@@ -124,16 +146,18 @@ if sys.platform == "win32":
|
||||
return proxy_bypass_registry(host)
|
||||
|
||||
|
||||
def dict_to_sequence(d):
|
||||
def dict_to_sequence(
|
||||
d: _t.SupportsItems[Any, Any] | Iterable[tuple[Any, Any]],
|
||||
) -> Iterable[tuple[Any, Any]]:
|
||||
"""Returns an internal sequence dictionary update."""
|
||||
|
||||
if hasattr(d, "items"):
|
||||
d = d.items()
|
||||
if isinstance(d, _SupportsItems):
|
||||
return d.items()
|
||||
|
||||
return d
|
||||
|
||||
|
||||
def super_len(o):
|
||||
def super_len(o: Any) -> int:
|
||||
total_length = None
|
||||
current_position = 0
|
||||
|
||||
@@ -204,9 +228,14 @@ def super_len(o):
|
||||
return max(0, total_length - current_position)
|
||||
|
||||
|
||||
def get_netrc_auth(url, raise_errors=False):
|
||||
def get_netrc_auth(
|
||||
url: _t.UriType, raise_errors: bool = False
|
||||
) -> tuple[str, str] | None:
|
||||
"""Returns the Requests tuple auth for a given url from netrc."""
|
||||
|
||||
if isinstance(url, bytes):
|
||||
url = url.decode("utf-8")
|
||||
|
||||
netrc_file = os.environ.get("NETRC")
|
||||
if netrc_file is not None:
|
||||
netrc_locations = (netrc_file,)
|
||||
@@ -231,12 +260,15 @@ def get_netrc_auth(url, raise_errors=False):
|
||||
ri = urlparse(url)
|
||||
host = ri.hostname
|
||||
|
||||
if host is None:
|
||||
return
|
||||
|
||||
try:
|
||||
_netrc = netrc(netrc_path).authenticators(host)
|
||||
if _netrc:
|
||||
if _netrc and any(_netrc):
|
||||
# Return with login / password
|
||||
login_i = 0 if _netrc[0] else 1
|
||||
return (_netrc[login_i], _netrc[2])
|
||||
return (_netrc[login_i] or "", _netrc[2] or "")
|
||||
except (NetrcParseError, OSError):
|
||||
# If there was a parsing error or a permissions issue reading the file,
|
||||
# we'll just skip netrc auth unless explicitly asked to raise errors.
|
||||
@@ -248,14 +280,14 @@ def get_netrc_auth(url, raise_errors=False):
|
||||
pass
|
||||
|
||||
|
||||
def guess_filename(obj):
|
||||
def guess_filename(obj: Any) -> str | None:
|
||||
"""Tries to guess the filename of the given object."""
|
||||
name = getattr(obj, "name", None)
|
||||
if name and isinstance(name, basestring) and name[0] != "<" and name[-1] != ">":
|
||||
return os.path.basename(name)
|
||||
if name and isinstance(name, (str, bytes)) and name[0] != "<" and name[-1] != ">":
|
||||
return os.path.basename(name) # type: ignore[return-value] # urllib3 accepts bytes but types str only
|
||||
|
||||
|
||||
def extract_zipped_paths(path):
|
||||
def extract_zipped_paths(path: str) -> str:
|
||||
"""Replace nonexistent paths that look like they refer to a member of a zip
|
||||
archive with the location of an extracted copy of the target, or else
|
||||
just return the provided path unchanged.
|
||||
@@ -283,17 +315,18 @@ def extract_zipped_paths(path):
|
||||
return path
|
||||
|
||||
# we have a valid zip archive and a valid member of that archive
|
||||
tmp = tempfile.gettempdir()
|
||||
extracted_path = os.path.join(tmp, member.split("/")[-1])
|
||||
if not os.path.exists(extracted_path):
|
||||
# use read + write to avoid the creating nested folders, we only want the file, avoids mkdir racing condition
|
||||
with atomic_open(extracted_path) as file_handler:
|
||||
file_handler.write(zip_file.read(member))
|
||||
suffix = os.path.splitext(member.split("/")[-1])[-1]
|
||||
fd, extracted_path = tempfile.mkstemp(suffix=suffix)
|
||||
try:
|
||||
os.write(fd, zip_file.read(member))
|
||||
finally:
|
||||
os.close(fd)
|
||||
|
||||
return extracted_path
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def atomic_open(filename):
|
||||
def atomic_open(filename: str) -> Generator[BufferedWriter, None, None]:
|
||||
"""Write a file to the disk in an atomic fashion"""
|
||||
tmp_descriptor, tmp_name = tempfile.mkstemp(dir=os.path.dirname(filename))
|
||||
try:
|
||||
@@ -305,7 +338,9 @@ def atomic_open(filename):
|
||||
raise
|
||||
|
||||
|
||||
def from_key_val_list(value):
|
||||
def from_key_val_list(
|
||||
value: Mapping[Any, Any] | Iterable[tuple[Any, Any]] | None,
|
||||
) -> dict[Any, Any] | None:
|
||||
"""Take an object and test to see if it can be represented as a
|
||||
dictionary. Unless it can not be represented as such, return an
|
||||
OrderedDict, e.g.,
|
||||
@@ -332,7 +367,15 @@ def from_key_val_list(value):
|
||||
return OrderedDict(value)
|
||||
|
||||
|
||||
def to_key_val_list(value):
|
||||
@overload
|
||||
def to_key_val_list(value: None) -> None: ...
|
||||
@overload
|
||||
def to_key_val_list(
|
||||
value: _t.SupportsItems[_KT, _VT] | Iterable[tuple[_KT, _VT]],
|
||||
) -> list[tuple[_KT, _VT]]: ...
|
||||
def to_key_val_list(
|
||||
value: _t.SupportsItems[_KT, _VT] | Iterable[tuple[_KT, _VT]] | None,
|
||||
) -> list[tuple[_KT, _VT]] | None:
|
||||
"""Take an object and test to see if it can be represented as a
|
||||
dictionary. If it can be, return a list of tuples, e.g.,
|
||||
|
||||
@@ -355,14 +398,14 @@ def to_key_val_list(value):
|
||||
if isinstance(value, (str, bytes, bool, int)):
|
||||
raise ValueError("cannot encode objects that are not 2-tuples")
|
||||
|
||||
if isinstance(value, Mapping):
|
||||
value = value.items()
|
||||
if isinstance(value, _SupportsItems):
|
||||
return list(value.items())
|
||||
|
||||
return list(value)
|
||||
|
||||
|
||||
# From mitsuhiko/werkzeug (used with permission).
|
||||
def parse_list_header(value):
|
||||
def parse_list_header(value: str) -> list[str]:
|
||||
"""Parse lists as described by RFC 2068 Section 2.
|
||||
|
||||
In particular, parse comma-separated lists where the elements of
|
||||
@@ -385,7 +428,7 @@ def parse_list_header(value):
|
||||
:return: :class:`list`
|
||||
:rtype: list
|
||||
"""
|
||||
result = []
|
||||
result: list[str] = []
|
||||
for item in _parse_list_header(value):
|
||||
if item[:1] == item[-1:] == '"':
|
||||
item = unquote_header_value(item[1:-1])
|
||||
@@ -394,7 +437,7 @@ def parse_list_header(value):
|
||||
|
||||
|
||||
# From mitsuhiko/werkzeug (used with permission).
|
||||
def parse_dict_header(value):
|
||||
def parse_dict_header(value: str) -> dict[str, str | None]:
|
||||
"""Parse lists of key, value pairs as described by RFC 2068 Section 2 and
|
||||
convert them into a python dict:
|
||||
|
||||
@@ -416,7 +459,7 @@ def parse_dict_header(value):
|
||||
:return: :class:`dict`
|
||||
:rtype: dict
|
||||
"""
|
||||
result = {}
|
||||
result: dict[str, str | None] = {}
|
||||
for item in _parse_list_header(value):
|
||||
if "=" not in item:
|
||||
result[item] = None
|
||||
@@ -429,7 +472,7 @@ def parse_dict_header(value):
|
||||
|
||||
|
||||
# From mitsuhiko/werkzeug (used with permission).
|
||||
def unquote_header_value(value, is_filename=False):
|
||||
def unquote_header_value(value: str, is_filename: bool = False) -> str:
|
||||
r"""Unquotes a header value. (Reversal of :func:`quote_header_value`).
|
||||
This does not use the real unquoting but what browsers are actually
|
||||
using for quoting.
|
||||
@@ -454,7 +497,7 @@ def unquote_header_value(value, is_filename=False):
|
||||
return value
|
||||
|
||||
|
||||
def dict_from_cookiejar(cj):
|
||||
def dict_from_cookiejar(cj: CookieJar) -> dict[str, str | None]:
|
||||
"""Returns a key/value dictionary from a CookieJar.
|
||||
|
||||
:param cj: CookieJar object to extract cookies from.
|
||||
@@ -465,7 +508,7 @@ def dict_from_cookiejar(cj):
|
||||
return cookie_dict
|
||||
|
||||
|
||||
def add_dict_to_cookiejar(cj, cookie_dict):
|
||||
def add_dict_to_cookiejar(cj: CookieJar, cookie_dict: dict[str, str]) -> CookieJar:
|
||||
"""Returns a CookieJar from a key/value dictionary.
|
||||
|
||||
:param cj: CookieJar to insert cookies into.
|
||||
@@ -476,7 +519,7 @@ def add_dict_to_cookiejar(cj, cookie_dict):
|
||||
return cookiejar_from_dict(cookie_dict, cj)
|
||||
|
||||
|
||||
def get_encodings_from_content(content):
|
||||
def get_encodings_from_content(content: str) -> list[str]:
|
||||
"""Returns encodings from given content string.
|
||||
|
||||
:param content: bytestring to extract encodings from.
|
||||
@@ -501,32 +544,29 @@ def get_encodings_from_content(content):
|
||||
)
|
||||
|
||||
|
||||
def _parse_content_type_header(header):
|
||||
"""Returns content type and parameters from given header
|
||||
def _parse_content_type_header(header: str) -> tuple[str, dict[str, Any]]:
|
||||
"""Returns content type and parameters from given header.
|
||||
|
||||
:param header: string
|
||||
:return: tuple containing content type and dictionary of
|
||||
parameters
|
||||
parameters.
|
||||
"""
|
||||
|
||||
tokens = header.split(";")
|
||||
content_type, params = tokens[0].strip(), tokens[1:]
|
||||
params_dict = {}
|
||||
items_to_strip = "\"' "
|
||||
params_dict: dict[str, str | bool] = {}
|
||||
strip_chars = "\"' "
|
||||
|
||||
for param in params:
|
||||
param = param.strip()
|
||||
if param:
|
||||
key, value = param, True
|
||||
index_of_equals = param.find("=")
|
||||
if index_of_equals != -1:
|
||||
key = param[:index_of_equals].strip(items_to_strip)
|
||||
value = param[index_of_equals + 1 :].strip(items_to_strip)
|
||||
if param and (idx := param.find("=")) != -1:
|
||||
key = param[:idx].strip(strip_chars)
|
||||
value = param[idx + 1 :].strip(strip_chars)
|
||||
params_dict[key.lower()] = value
|
||||
return content_type, params_dict
|
||||
|
||||
|
||||
def get_encoding_from_headers(headers):
|
||||
def get_encoding_from_headers(headers: CaseInsensitiveDict[str]) -> str | None:
|
||||
"""Returns encodings from given HTTP Header Dict.
|
||||
|
||||
:param headers: dictionary to extract encoding from.
|
||||
@@ -551,7 +591,9 @@ def get_encoding_from_headers(headers):
|
||||
return "utf-8"
|
||||
|
||||
|
||||
def stream_decode_response_unicode(iterator, r):
|
||||
def stream_decode_response_unicode(
|
||||
iterator: Iterable[bytes], r: Response
|
||||
) -> Generator[str | bytes, None, None]:
|
||||
"""Stream decodes an iterator."""
|
||||
|
||||
if r.encoding is None:
|
||||
@@ -568,7 +610,17 @@ def stream_decode_response_unicode(iterator, r):
|
||||
yield rv
|
||||
|
||||
|
||||
def iter_slices(string, slice_length):
|
||||
@overload
|
||||
def iter_slices(
|
||||
string: bytes, slice_length: int | None
|
||||
) -> Generator[bytes, None, None]: ...
|
||||
@overload
|
||||
def iter_slices(
|
||||
string: str, slice_length: int | None
|
||||
) -> Generator[str, None, None]: ...
|
||||
def iter_slices(
|
||||
string: bytes | str, slice_length: int | None
|
||||
) -> Generator[bytes | str, None, None]:
|
||||
"""Iterate over slices of a string."""
|
||||
pos = 0
|
||||
if slice_length is None or slice_length <= 0:
|
||||
@@ -578,7 +630,7 @@ def iter_slices(string, slice_length):
|
||||
pos += slice_length
|
||||
|
||||
|
||||
def get_unicode_from_response(r):
|
||||
def get_unicode_from_response(r: Response) -> str | bytes | None:
|
||||
"""Returns the requested content back in unicode.
|
||||
|
||||
:param r: Response object to get unicode content from.
|
||||
@@ -598,8 +650,10 @@ def get_unicode_from_response(r):
|
||||
),
|
||||
DeprecationWarning,
|
||||
)
|
||||
if r.content is None: # type: ignore[reportUnnecessaryComparison]
|
||||
return None
|
||||
|
||||
tried_encodings = []
|
||||
tried_encodings: list[str] = []
|
||||
|
||||
# Try charset from content-type
|
||||
encoding = get_encoding_from_headers(r.headers)
|
||||
@@ -612,18 +666,18 @@ def get_unicode_from_response(r):
|
||||
|
||||
# Fall back:
|
||||
try:
|
||||
return str(r.content, encoding, errors="replace")
|
||||
return str(r.content, encoding or "utf-8", errors="replace")
|
||||
except TypeError:
|
||||
return r.content
|
||||
|
||||
|
||||
# The unreserved URI characters (RFC 3986)
|
||||
UNRESERVED_SET = frozenset(
|
||||
UNRESERVED_SET: Final = frozenset(
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" + "0123456789-._~"
|
||||
)
|
||||
|
||||
|
||||
def unquote_unreserved(uri):
|
||||
def unquote_unreserved(uri: str) -> str:
|
||||
"""Un-escape any percent-escape sequences in a URI that are unreserved
|
||||
characters. This leaves all reserved, illegal and non-ASCII bytes encoded.
|
||||
|
||||
@@ -647,7 +701,7 @@ def unquote_unreserved(uri):
|
||||
return "".join(parts)
|
||||
|
||||
|
||||
def requote_uri(uri):
|
||||
def requote_uri(uri: str) -> str:
|
||||
"""Re-quote the given URI.
|
||||
|
||||
This function passes the given URI through an unquote/quote cycle to
|
||||
@@ -669,7 +723,7 @@ def requote_uri(uri):
|
||||
return quote(uri, safe=safe_without_percent)
|
||||
|
||||
|
||||
def address_in_network(ip, net):
|
||||
def address_in_network(ip: str, net: str) -> bool:
|
||||
"""This function allows you to check if an IP belongs to a network subnet
|
||||
|
||||
Example: returns True if ip = 192.168.1.1 and net = 192.168.1.0/24
|
||||
@@ -684,7 +738,7 @@ def address_in_network(ip, net):
|
||||
return (ipaddr & netmask) == (network & netmask)
|
||||
|
||||
|
||||
def dotted_netmask(mask):
|
||||
def dotted_netmask(mask: int) -> str:
|
||||
"""Converts mask from /xx format to xxx.xxx.xxx.xxx
|
||||
|
||||
Example: if mask is 24 function returns 255.255.255.0
|
||||
@@ -695,7 +749,7 @@ def dotted_netmask(mask):
|
||||
return socket.inet_ntoa(struct.pack(">I", bits))
|
||||
|
||||
|
||||
def is_ipv4_address(string_ip):
|
||||
def is_ipv4_address(string_ip: str) -> bool:
|
||||
"""
|
||||
:rtype: bool
|
||||
"""
|
||||
@@ -706,7 +760,7 @@ def is_ipv4_address(string_ip):
|
||||
return True
|
||||
|
||||
|
||||
def is_valid_cidr(string_network):
|
||||
def is_valid_cidr(string_network: str) -> bool:
|
||||
"""
|
||||
Very simple check of the cidr format in no_proxy variable.
|
||||
|
||||
@@ -731,7 +785,7 @@ def is_valid_cidr(string_network):
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def set_environ(env_name, value):
|
||||
def set_environ(env_name: str, value: str | None) -> Generator[None, None, None]:
|
||||
"""Set the environment variable 'env_name' to 'value'
|
||||
|
||||
Save previous value, yield, and then restore the previous value stored in
|
||||
@@ -739,6 +793,7 @@ def set_environ(env_name, value):
|
||||
|
||||
If 'value' is None, do nothing"""
|
||||
value_changed = value is not None
|
||||
old_value: str | None = None
|
||||
if value_changed:
|
||||
old_value = os.environ.get(env_name)
|
||||
os.environ[env_name] = value
|
||||
@@ -752,7 +807,7 @@ def set_environ(env_name, value):
|
||||
os.environ[env_name] = old_value
|
||||
|
||||
|
||||
def should_bypass_proxies(url, no_proxy):
|
||||
def should_bypass_proxies(url: str, no_proxy: str | None) -> bool:
|
||||
"""
|
||||
Returns whether we should bypass proxies or not.
|
||||
|
||||
@@ -761,7 +816,7 @@ def should_bypass_proxies(url, no_proxy):
|
||||
|
||||
# Prioritize lowercase environment variables over uppercase
|
||||
# to keep a consistent behaviour with other http projects (curl, wget).
|
||||
def get_proxy(key):
|
||||
def get_proxy(key: str) -> str | None:
|
||||
return os.environ.get(key) or os.environ.get(key.upper())
|
||||
|
||||
# First check whether no_proxy is defined. If it is, check that the URL
|
||||
@@ -770,40 +825,42 @@ def should_bypass_proxies(url, no_proxy):
|
||||
if no_proxy is None:
|
||||
no_proxy = get_proxy("no_proxy")
|
||||
parsed = urlparse(url)
|
||||
hostname = parsed.hostname
|
||||
|
||||
if parsed.hostname is None:
|
||||
if hostname is None:
|
||||
# URLs don't always have hostnames, e.g. file:/// urls.
|
||||
return True
|
||||
|
||||
if no_proxy:
|
||||
# We need to check whether we match here. We need to see if we match
|
||||
# the end of the hostname, both with and without the port.
|
||||
no_proxy = (host for host in no_proxy.replace(" ", "").split(",") if host)
|
||||
no_proxy_hosts = (host for host in no_proxy.replace(" ", "").split(",") if host)
|
||||
|
||||
if is_ipv4_address(parsed.hostname):
|
||||
for proxy_ip in no_proxy:
|
||||
if is_ipv4_address(hostname):
|
||||
for proxy_ip in no_proxy_hosts:
|
||||
if is_valid_cidr(proxy_ip):
|
||||
if address_in_network(parsed.hostname, proxy_ip):
|
||||
if address_in_network(hostname, proxy_ip):
|
||||
return True
|
||||
elif parsed.hostname == proxy_ip:
|
||||
elif hostname == proxy_ip:
|
||||
# If no_proxy ip was defined in plain IP notation instead of cidr notation &
|
||||
# matches the IP of the index
|
||||
return True
|
||||
else:
|
||||
host_with_port = parsed.hostname
|
||||
host_with_port = hostname
|
||||
if parsed.port:
|
||||
host_with_port += f":{parsed.port}"
|
||||
|
||||
for host in no_proxy:
|
||||
if parsed.hostname.endswith(host) or host_with_port.endswith(host):
|
||||
# The URL does match something in no_proxy, so we don't want
|
||||
# to apply the proxies on this URL.
|
||||
for host in no_proxy_hosts:
|
||||
host = host.lstrip(".")
|
||||
if hostname == host or host_with_port == host:
|
||||
return True
|
||||
host = "." + host
|
||||
if hostname.endswith(host) or host_with_port.endswith(host):
|
||||
return True
|
||||
|
||||
with set_environ("no_proxy", no_proxy_arg):
|
||||
# parsed.hostname can be `None` in cases such as a file URI.
|
||||
try:
|
||||
bypass = proxy_bypass(parsed.hostname)
|
||||
bypass = proxy_bypass(hostname)
|
||||
except (TypeError, socket.gaierror):
|
||||
bypass = False
|
||||
|
||||
@@ -813,7 +870,7 @@ def should_bypass_proxies(url, no_proxy):
|
||||
return False
|
||||
|
||||
|
||||
def get_environ_proxies(url, no_proxy=None):
|
||||
def get_environ_proxies(url: str, no_proxy: str | None = None) -> dict[str, str]:
|
||||
"""
|
||||
Return a dict of environment proxies.
|
||||
|
||||
@@ -825,7 +882,7 @@ def get_environ_proxies(url, no_proxy=None):
|
||||
return getproxies()
|
||||
|
||||
|
||||
def select_proxy(url, proxies):
|
||||
def select_proxy(url: str, proxies: dict[str, str] | None) -> str | None:
|
||||
"""Select a proxy for the url, if applicable.
|
||||
|
||||
:param url: The url being for the request
|
||||
@@ -851,7 +908,11 @@ def select_proxy(url, proxies):
|
||||
return proxy
|
||||
|
||||
|
||||
def resolve_proxies(request, proxies, trust_env=True):
|
||||
def resolve_proxies(
|
||||
request: Request | PreparedRequest,
|
||||
proxies: dict[str, str] | None,
|
||||
trust_env: bool = True,
|
||||
) -> dict[str, str]:
|
||||
"""This method takes proxy information from a request and configuration
|
||||
input to resolve a mapping of target proxies. This will consider settings
|
||||
such as NO_PROXY to strip proxy configurations.
|
||||
@@ -863,7 +924,7 @@ def resolve_proxies(request, proxies, trust_env=True):
|
||||
:rtype: dict
|
||||
"""
|
||||
proxies = proxies if proxies is not None else {}
|
||||
url = request.url
|
||||
url = cast(str, request.url)
|
||||
scheme = urlparse(url).scheme
|
||||
no_proxy = proxies.get("no_proxy")
|
||||
new_proxies = proxies.copy()
|
||||
@@ -878,7 +939,7 @@ def resolve_proxies(request, proxies, trust_env=True):
|
||||
return new_proxies
|
||||
|
||||
|
||||
def default_user_agent(name="python-requests"):
|
||||
def default_user_agent(name: str = "python-requests") -> str:
|
||||
"""
|
||||
Return a string representing the default user agent.
|
||||
|
||||
@@ -887,7 +948,7 @@ def default_user_agent(name="python-requests"):
|
||||
return f"{name}/{__version__}"
|
||||
|
||||
|
||||
def default_headers():
|
||||
def default_headers() -> CaseInsensitiveDict[str]:
|
||||
"""
|
||||
:rtype: requests.structures.CaseInsensitiveDict
|
||||
"""
|
||||
@@ -901,7 +962,7 @@ def default_headers():
|
||||
)
|
||||
|
||||
|
||||
def parse_header_links(value):
|
||||
def parse_header_links(value: str) -> list[dict[str, str]]:
|
||||
"""Return a list of parsed link headers proxies.
|
||||
|
||||
i.e. Link: <http:/.../front.jpeg>; rel=front; type="image/jpeg",<http://.../back.jpeg>; rel=back;type="image/jpeg"
|
||||
@@ -909,7 +970,7 @@ def parse_header_links(value):
|
||||
:rtype: list
|
||||
"""
|
||||
|
||||
links = []
|
||||
links: list[dict[str, str]] = []
|
||||
|
||||
replace_chars = " '\""
|
||||
|
||||
@@ -923,7 +984,7 @@ def parse_header_links(value):
|
||||
except ValueError:
|
||||
url, params = val, ""
|
||||
|
||||
link = {"url": url.strip("<> '\"")}
|
||||
link: dict[str, str] = {"url": url.strip("<> '\"")}
|
||||
|
||||
for param in params.split(";"):
|
||||
try:
|
||||
@@ -944,7 +1005,7 @@ _null2 = _null * 2
|
||||
_null3 = _null * 3
|
||||
|
||||
|
||||
def guess_json_utf(data):
|
||||
def guess_json_utf(data: bytes) -> str | None:
|
||||
"""
|
||||
:rtype: str
|
||||
"""
|
||||
@@ -976,14 +1037,14 @@ def guess_json_utf(data):
|
||||
return None
|
||||
|
||||
|
||||
def prepend_scheme_if_needed(url, new_scheme):
|
||||
def prepend_scheme_if_needed(url: str, new_scheme: str) -> str:
|
||||
"""Given a URL that may or may not have a scheme, prepend the given scheme.
|
||||
Does not replace a present scheme with the one provided as an argument.
|
||||
|
||||
:rtype: str
|
||||
"""
|
||||
parsed = parse_url(url)
|
||||
scheme, auth, host, port, path, query, fragment = parsed
|
||||
scheme, auth, _host, _port, path, query, fragment = parsed
|
||||
|
||||
# A defect in urlparse determines that there isn't a netloc present in some
|
||||
# urls. We previously assumed parsing was overly cautious, and swapped the
|
||||
@@ -996,6 +1057,7 @@ def prepend_scheme_if_needed(url, new_scheme):
|
||||
if auth:
|
||||
# parse_url doesn't provide the netloc with auth
|
||||
# so we'll add it ourselves.
|
||||
netloc = cast(str, netloc)
|
||||
netloc = "@".join([auth, netloc])
|
||||
if scheme is None:
|
||||
scheme = new_scheme
|
||||
@@ -1005,7 +1067,7 @@ def prepend_scheme_if_needed(url, new_scheme):
|
||||
return urlunparse((scheme, netloc, path, "", query, fragment))
|
||||
|
||||
|
||||
def get_auth_from_url(url):
|
||||
def get_auth_from_url(url: str) -> tuple[str, str]:
|
||||
"""Given a url with authentication components, extract them into a tuple of
|
||||
username,password.
|
||||
|
||||
@@ -1014,14 +1076,15 @@ def get_auth_from_url(url):
|
||||
parsed = urlparse(url)
|
||||
|
||||
try:
|
||||
auth = (unquote(parsed.username), unquote(parsed.password))
|
||||
# except handles parsed.username/password being None
|
||||
auth = (unquote(parsed.username), unquote(parsed.password)) # type: ignore[arg-type]
|
||||
except (AttributeError, TypeError):
|
||||
auth = ("", "")
|
||||
|
||||
return auth
|
||||
|
||||
|
||||
def check_header_validity(header):
|
||||
def check_header_validity(header: tuple[str | bytes, str | bytes]) -> None:
|
||||
"""Verifies that header parts don't contain leading whitespace
|
||||
reserved characters, or return characters.
|
||||
|
||||
@@ -1032,10 +1095,15 @@ def check_header_validity(header):
|
||||
_validate_header_part(header, value, 1)
|
||||
|
||||
|
||||
def _validate_header_part(header, header_part, header_validator_index):
|
||||
def _validate_header_part(
|
||||
header: tuple[str | bytes, str | bytes],
|
||||
header_part: str | bytes,
|
||||
header_validator_index: int,
|
||||
) -> None:
|
||||
if isinstance(header_part, str):
|
||||
validator = _HEADER_VALIDATORS_STR[header_validator_index]
|
||||
elif isinstance(header_part, bytes):
|
||||
elif isinstance(header_part, bytes): # type: ignore[reportUnnecessaryIsInstance]
|
||||
# runtime guard for non-str/bytes input
|
||||
validator = _HEADER_VALIDATORS_BYTE[header_validator_index]
|
||||
else:
|
||||
raise InvalidHeader(
|
||||
@@ -1043,7 +1111,7 @@ def _validate_header_part(header, header_part, header_validator_index):
|
||||
f"must be of type str or bytes, not {type(header_part)}"
|
||||
)
|
||||
|
||||
if not validator.match(header_part):
|
||||
if not validator.match(header_part): # type: ignore[arg-type]
|
||||
header_kind = "name" if header_validator_index == 0 else "value"
|
||||
raise InvalidHeader(
|
||||
f"Invalid leading whitespace, reserved character(s), or return "
|
||||
@@ -1051,13 +1119,13 @@ def _validate_header_part(header, header_part, header_validator_index):
|
||||
)
|
||||
|
||||
|
||||
def urldefragauth(url):
|
||||
def urldefragauth(url: str) -> str:
|
||||
"""
|
||||
Given a url remove the fragment and the authentication part.
|
||||
|
||||
:rtype: str
|
||||
"""
|
||||
scheme, netloc, path, params, query, fragment = urlparse(url)
|
||||
scheme, netloc, path, params, query, _fragment = urlparse(url)
|
||||
|
||||
# see func:`prepend_scheme_if_needed`
|
||||
if not netloc:
|
||||
@@ -1068,16 +1136,17 @@ def urldefragauth(url):
|
||||
return urlunparse((scheme, netloc, path, params, query, ""))
|
||||
|
||||
|
||||
def rewind_body(prepared_request):
|
||||
def rewind_body(prepared_request: PreparedRequest) -> None:
|
||||
"""Move file pointer back to its recorded starting position
|
||||
so it can be read again on redirect.
|
||||
"""
|
||||
body_seek = getattr(prepared_request.body, "seek", None)
|
||||
if body_seek is not None and isinstance(
|
||||
prepared_request._body_position, integer_types
|
||||
prepared_request._body_position, # type: ignore[reportPrivateUsage]
|
||||
integer_types,
|
||||
):
|
||||
try:
|
||||
body_seek(prepared_request._body_position)
|
||||
body_seek(prepared_request._body_position) # type: ignore[reportPrivateUsage]
|
||||
except OSError:
|
||||
raise UnrewindableBodyError(
|
||||
"An error occurred when rewinding request body for redirect."
|
||||
|
||||
@@ -148,7 +148,7 @@ def inspect(
|
||||
docs (bool, optional): Also render doc strings. Defaults to True.
|
||||
private (bool, optional): Show private attributes (beginning with underscore). Defaults to False.
|
||||
dunder (bool, optional): Show attributes starting with double underscore. Defaults to False.
|
||||
sort (bool, optional): Sort attributes alphabetically. Defaults to True.
|
||||
sort (bool, optional): Sort attributes alphabetically, callables at the top, leading and trailing underscores ignored. Defaults to True.
|
||||
all (bool, optional): Show all attributes. Defaults to False.
|
||||
value (bool, optional): Pretty print value. Defaults to True.
|
||||
"""
|
||||
|
||||
@@ -234,12 +234,12 @@ if __name__ == "__main__": # pragma: no cover
|
||||
console.print(f"[dim]rendered in [not dim]{taken}ms[/] (warm cache)")
|
||||
console.print()
|
||||
console.print(
|
||||
Panel.fit(
|
||||
Panel(
|
||||
"[b magenta]Hope you enjoy using Rich![/]\n\n"
|
||||
"Please consider sponsoring me if you get value from my work.\n\n"
|
||||
"Even the price of a ☕ can brighten my day!\n\n"
|
||||
"https://github.com/sponsors/willmcgugan",
|
||||
border_style="red",
|
||||
"Consider sponsoring to ensure this project is maintained.\n\n"
|
||||
"[cyan]https://github.com/sponsors/willmcgugan[/cyan]",
|
||||
border_style="green",
|
||||
title="Help ensure Rich is maintained",
|
||||
padding=(1, 2),
|
||||
)
|
||||
)
|
||||
@@ -1,454 +0,0 @@
|
||||
# Auto generated by make_terminal_widths.py
|
||||
|
||||
CELL_WIDTHS = [
|
||||
(0, 0, 0),
|
||||
(1, 31, -1),
|
||||
(127, 159, -1),
|
||||
(173, 173, 0),
|
||||
(768, 879, 0),
|
||||
(1155, 1161, 0),
|
||||
(1425, 1469, 0),
|
||||
(1471, 1471, 0),
|
||||
(1473, 1474, 0),
|
||||
(1476, 1477, 0),
|
||||
(1479, 1479, 0),
|
||||
(1536, 1541, 0),
|
||||
(1552, 1562, 0),
|
||||
(1564, 1564, 0),
|
||||
(1611, 1631, 0),
|
||||
(1648, 1648, 0),
|
||||
(1750, 1757, 0),
|
||||
(1759, 1764, 0),
|
||||
(1767, 1768, 0),
|
||||
(1770, 1773, 0),
|
||||
(1807, 1807, 0),
|
||||
(1809, 1809, 0),
|
||||
(1840, 1866, 0),
|
||||
(1958, 1968, 0),
|
||||
(2027, 2035, 0),
|
||||
(2045, 2045, 0),
|
||||
(2070, 2073, 0),
|
||||
(2075, 2083, 0),
|
||||
(2085, 2087, 0),
|
||||
(2089, 2093, 0),
|
||||
(2137, 2139, 0),
|
||||
(2192, 2193, 0),
|
||||
(2200, 2207, 0),
|
||||
(2250, 2307, 0),
|
||||
(2362, 2364, 0),
|
||||
(2366, 2383, 0),
|
||||
(2385, 2391, 0),
|
||||
(2402, 2403, 0),
|
||||
(2433, 2435, 0),
|
||||
(2492, 2492, 0),
|
||||
(2494, 2500, 0),
|
||||
(2503, 2504, 0),
|
||||
(2507, 2509, 0),
|
||||
(2519, 2519, 0),
|
||||
(2530, 2531, 0),
|
||||
(2558, 2558, 0),
|
||||
(2561, 2563, 0),
|
||||
(2620, 2620, 0),
|
||||
(2622, 2626, 0),
|
||||
(2631, 2632, 0),
|
||||
(2635, 2637, 0),
|
||||
(2641, 2641, 0),
|
||||
(2672, 2673, 0),
|
||||
(2677, 2677, 0),
|
||||
(2689, 2691, 0),
|
||||
(2748, 2748, 0),
|
||||
(2750, 2757, 0),
|
||||
(2759, 2761, 0),
|
||||
(2763, 2765, 0),
|
||||
(2786, 2787, 0),
|
||||
(2810, 2815, 0),
|
||||
(2817, 2819, 0),
|
||||
(2876, 2876, 0),
|
||||
(2878, 2884, 0),
|
||||
(2887, 2888, 0),
|
||||
(2891, 2893, 0),
|
||||
(2901, 2903, 0),
|
||||
(2914, 2915, 0),
|
||||
(2946, 2946, 0),
|
||||
(3006, 3010, 0),
|
||||
(3014, 3016, 0),
|
||||
(3018, 3021, 0),
|
||||
(3031, 3031, 0),
|
||||
(3072, 3076, 0),
|
||||
(3132, 3132, 0),
|
||||
(3134, 3140, 0),
|
||||
(3142, 3144, 0),
|
||||
(3146, 3149, 0),
|
||||
(3157, 3158, 0),
|
||||
(3170, 3171, 0),
|
||||
(3201, 3203, 0),
|
||||
(3260, 3260, 0),
|
||||
(3262, 3268, 0),
|
||||
(3270, 3272, 0),
|
||||
(3274, 3277, 0),
|
||||
(3285, 3286, 0),
|
||||
(3298, 3299, 0),
|
||||
(3315, 3315, 0),
|
||||
(3328, 3331, 0),
|
||||
(3387, 3388, 0),
|
||||
(3390, 3396, 0),
|
||||
(3398, 3400, 0),
|
||||
(3402, 3405, 0),
|
||||
(3415, 3415, 0),
|
||||
(3426, 3427, 0),
|
||||
(3457, 3459, 0),
|
||||
(3530, 3530, 0),
|
||||
(3535, 3540, 0),
|
||||
(3542, 3542, 0),
|
||||
(3544, 3551, 0),
|
||||
(3570, 3571, 0),
|
||||
(3633, 3633, 0),
|
||||
(3636, 3642, 0),
|
||||
(3655, 3662, 0),
|
||||
(3761, 3761, 0),
|
||||
(3764, 3772, 0),
|
||||
(3784, 3790, 0),
|
||||
(3864, 3865, 0),
|
||||
(3893, 3893, 0),
|
||||
(3895, 3895, 0),
|
||||
(3897, 3897, 0),
|
||||
(3902, 3903, 0),
|
||||
(3953, 3972, 0),
|
||||
(3974, 3975, 0),
|
||||
(3981, 3991, 0),
|
||||
(3993, 4028, 0),
|
||||
(4038, 4038, 0),
|
||||
(4139, 4158, 0),
|
||||
(4182, 4185, 0),
|
||||
(4190, 4192, 0),
|
||||
(4194, 4196, 0),
|
||||
(4199, 4205, 0),
|
||||
(4209, 4212, 0),
|
||||
(4226, 4237, 0),
|
||||
(4239, 4239, 0),
|
||||
(4250, 4253, 0),
|
||||
(4352, 4447, 2),
|
||||
(4448, 4607, 0),
|
||||
(4957, 4959, 0),
|
||||
(5906, 5909, 0),
|
||||
(5938, 5940, 0),
|
||||
(5970, 5971, 0),
|
||||
(6002, 6003, 0),
|
||||
(6068, 6099, 0),
|
||||
(6109, 6109, 0),
|
||||
(6155, 6159, 0),
|
||||
(6277, 6278, 0),
|
||||
(6313, 6313, 0),
|
||||
(6432, 6443, 0),
|
||||
(6448, 6459, 0),
|
||||
(6679, 6683, 0),
|
||||
(6741, 6750, 0),
|
||||
(6752, 6780, 0),
|
||||
(6783, 6783, 0),
|
||||
(6832, 6862, 0),
|
||||
(6912, 6916, 0),
|
||||
(6964, 6980, 0),
|
||||
(7019, 7027, 0),
|
||||
(7040, 7042, 0),
|
||||
(7073, 7085, 0),
|
||||
(7142, 7155, 0),
|
||||
(7204, 7223, 0),
|
||||
(7376, 7378, 0),
|
||||
(7380, 7400, 0),
|
||||
(7405, 7405, 0),
|
||||
(7412, 7412, 0),
|
||||
(7415, 7417, 0),
|
||||
(7616, 7679, 0),
|
||||
(8203, 8207, 0),
|
||||
(8232, 8238, 0),
|
||||
(8288, 8292, 0),
|
||||
(8294, 8303, 0),
|
||||
(8400, 8432, 0),
|
||||
(8986, 8987, 2),
|
||||
(9001, 9002, 2),
|
||||
(9193, 9196, 2),
|
||||
(9200, 9200, 2),
|
||||
(9203, 9203, 2),
|
||||
(9725, 9726, 2),
|
||||
(9748, 9749, 2),
|
||||
(9800, 9811, 2),
|
||||
(9855, 9855, 2),
|
||||
(9875, 9875, 2),
|
||||
(9889, 9889, 2),
|
||||
(9898, 9899, 2),
|
||||
(9917, 9918, 2),
|
||||
(9924, 9925, 2),
|
||||
(9934, 9934, 2),
|
||||
(9940, 9940, 2),
|
||||
(9962, 9962, 2),
|
||||
(9970, 9971, 2),
|
||||
(9973, 9973, 2),
|
||||
(9978, 9978, 2),
|
||||
(9981, 9981, 2),
|
||||
(9989, 9989, 2),
|
||||
(9994, 9995, 2),
|
||||
(10024, 10024, 2),
|
||||
(10060, 10060, 2),
|
||||
(10062, 10062, 2),
|
||||
(10067, 10069, 2),
|
||||
(10071, 10071, 2),
|
||||
(10133, 10135, 2),
|
||||
(10160, 10160, 2),
|
||||
(10175, 10175, 2),
|
||||
(11035, 11036, 2),
|
||||
(11088, 11088, 2),
|
||||
(11093, 11093, 2),
|
||||
(11503, 11505, 0),
|
||||
(11647, 11647, 0),
|
||||
(11744, 11775, 0),
|
||||
(11904, 11929, 2),
|
||||
(11931, 12019, 2),
|
||||
(12032, 12245, 2),
|
||||
(12272, 12329, 2),
|
||||
(12330, 12335, 0),
|
||||
(12336, 12350, 2),
|
||||
(12353, 12438, 2),
|
||||
(12441, 12442, 0),
|
||||
(12443, 12543, 2),
|
||||
(12549, 12591, 2),
|
||||
(12593, 12686, 2),
|
||||
(12688, 12771, 2),
|
||||
(12783, 12830, 2),
|
||||
(12832, 12871, 2),
|
||||
(12880, 19903, 2),
|
||||
(19968, 42124, 2),
|
||||
(42128, 42182, 2),
|
||||
(42607, 42610, 0),
|
||||
(42612, 42621, 0),
|
||||
(42654, 42655, 0),
|
||||
(42736, 42737, 0),
|
||||
(43010, 43010, 0),
|
||||
(43014, 43014, 0),
|
||||
(43019, 43019, 0),
|
||||
(43043, 43047, 0),
|
||||
(43052, 43052, 0),
|
||||
(43136, 43137, 0),
|
||||
(43188, 43205, 0),
|
||||
(43232, 43249, 0),
|
||||
(43263, 43263, 0),
|
||||
(43302, 43309, 0),
|
||||
(43335, 43347, 0),
|
||||
(43360, 43388, 2),
|
||||
(43392, 43395, 0),
|
||||
(43443, 43456, 0),
|
||||
(43493, 43493, 0),
|
||||
(43561, 43574, 0),
|
||||
(43587, 43587, 0),
|
||||
(43596, 43597, 0),
|
||||
(43643, 43645, 0),
|
||||
(43696, 43696, 0),
|
||||
(43698, 43700, 0),
|
||||
(43703, 43704, 0),
|
||||
(43710, 43711, 0),
|
||||
(43713, 43713, 0),
|
||||
(43755, 43759, 0),
|
||||
(43765, 43766, 0),
|
||||
(44003, 44010, 0),
|
||||
(44012, 44013, 0),
|
||||
(44032, 55203, 2),
|
||||
(55216, 55295, 0),
|
||||
(63744, 64255, 2),
|
||||
(64286, 64286, 0),
|
||||
(65024, 65039, 0),
|
||||
(65040, 65049, 2),
|
||||
(65056, 65071, 0),
|
||||
(65072, 65106, 2),
|
||||
(65108, 65126, 2),
|
||||
(65128, 65131, 2),
|
||||
(65279, 65279, 0),
|
||||
(65281, 65376, 2),
|
||||
(65504, 65510, 2),
|
||||
(65529, 65531, 0),
|
||||
(66045, 66045, 0),
|
||||
(66272, 66272, 0),
|
||||
(66422, 66426, 0),
|
||||
(68097, 68099, 0),
|
||||
(68101, 68102, 0),
|
||||
(68108, 68111, 0),
|
||||
(68152, 68154, 0),
|
||||
(68159, 68159, 0),
|
||||
(68325, 68326, 0),
|
||||
(68900, 68903, 0),
|
||||
(69291, 69292, 0),
|
||||
(69373, 69375, 0),
|
||||
(69446, 69456, 0),
|
||||
(69506, 69509, 0),
|
||||
(69632, 69634, 0),
|
||||
(69688, 69702, 0),
|
||||
(69744, 69744, 0),
|
||||
(69747, 69748, 0),
|
||||
(69759, 69762, 0),
|
||||
(69808, 69818, 0),
|
||||
(69821, 69821, 0),
|
||||
(69826, 69826, 0),
|
||||
(69837, 69837, 0),
|
||||
(69888, 69890, 0),
|
||||
(69927, 69940, 0),
|
||||
(69957, 69958, 0),
|
||||
(70003, 70003, 0),
|
||||
(70016, 70018, 0),
|
||||
(70067, 70080, 0),
|
||||
(70089, 70092, 0),
|
||||
(70094, 70095, 0),
|
||||
(70188, 70199, 0),
|
||||
(70206, 70206, 0),
|
||||
(70209, 70209, 0),
|
||||
(70367, 70378, 0),
|
||||
(70400, 70403, 0),
|
||||
(70459, 70460, 0),
|
||||
(70462, 70468, 0),
|
||||
(70471, 70472, 0),
|
||||
(70475, 70477, 0),
|
||||
(70487, 70487, 0),
|
||||
(70498, 70499, 0),
|
||||
(70502, 70508, 0),
|
||||
(70512, 70516, 0),
|
||||
(70709, 70726, 0),
|
||||
(70750, 70750, 0),
|
||||
(70832, 70851, 0),
|
||||
(71087, 71093, 0),
|
||||
(71096, 71104, 0),
|
||||
(71132, 71133, 0),
|
||||
(71216, 71232, 0),
|
||||
(71339, 71351, 0),
|
||||
(71453, 71467, 0),
|
||||
(71724, 71738, 0),
|
||||
(71984, 71989, 0),
|
||||
(71991, 71992, 0),
|
||||
(71995, 71998, 0),
|
||||
(72000, 72000, 0),
|
||||
(72002, 72003, 0),
|
||||
(72145, 72151, 0),
|
||||
(72154, 72160, 0),
|
||||
(72164, 72164, 0),
|
||||
(72193, 72202, 0),
|
||||
(72243, 72249, 0),
|
||||
(72251, 72254, 0),
|
||||
(72263, 72263, 0),
|
||||
(72273, 72283, 0),
|
||||
(72330, 72345, 0),
|
||||
(72751, 72758, 0),
|
||||
(72760, 72767, 0),
|
||||
(72850, 72871, 0),
|
||||
(72873, 72886, 0),
|
||||
(73009, 73014, 0),
|
||||
(73018, 73018, 0),
|
||||
(73020, 73021, 0),
|
||||
(73023, 73029, 0),
|
||||
(73031, 73031, 0),
|
||||
(73098, 73102, 0),
|
||||
(73104, 73105, 0),
|
||||
(73107, 73111, 0),
|
||||
(73459, 73462, 0),
|
||||
(73472, 73473, 0),
|
||||
(73475, 73475, 0),
|
||||
(73524, 73530, 0),
|
||||
(73534, 73538, 0),
|
||||
(78896, 78912, 0),
|
||||
(78919, 78933, 0),
|
||||
(92912, 92916, 0),
|
||||
(92976, 92982, 0),
|
||||
(94031, 94031, 0),
|
||||
(94033, 94087, 0),
|
||||
(94095, 94098, 0),
|
||||
(94176, 94179, 2),
|
||||
(94180, 94180, 0),
|
||||
(94192, 94193, 0),
|
||||
(94208, 100343, 2),
|
||||
(100352, 101589, 2),
|
||||
(101632, 101640, 2),
|
||||
(110576, 110579, 2),
|
||||
(110581, 110587, 2),
|
||||
(110589, 110590, 2),
|
||||
(110592, 110882, 2),
|
||||
(110898, 110898, 2),
|
||||
(110928, 110930, 2),
|
||||
(110933, 110933, 2),
|
||||
(110948, 110951, 2),
|
||||
(110960, 111355, 2),
|
||||
(113821, 113822, 0),
|
||||
(113824, 113827, 0),
|
||||
(118528, 118573, 0),
|
||||
(118576, 118598, 0),
|
||||
(119141, 119145, 0),
|
||||
(119149, 119170, 0),
|
||||
(119173, 119179, 0),
|
||||
(119210, 119213, 0),
|
||||
(119362, 119364, 0),
|
||||
(121344, 121398, 0),
|
||||
(121403, 121452, 0),
|
||||
(121461, 121461, 0),
|
||||
(121476, 121476, 0),
|
||||
(121499, 121503, 0),
|
||||
(121505, 121519, 0),
|
||||
(122880, 122886, 0),
|
||||
(122888, 122904, 0),
|
||||
(122907, 122913, 0),
|
||||
(122915, 122916, 0),
|
||||
(122918, 122922, 0),
|
||||
(123023, 123023, 0),
|
||||
(123184, 123190, 0),
|
||||
(123566, 123566, 0),
|
||||
(123628, 123631, 0),
|
||||
(124140, 124143, 0),
|
||||
(125136, 125142, 0),
|
||||
(125252, 125258, 0),
|
||||
(126980, 126980, 2),
|
||||
(127183, 127183, 2),
|
||||
(127374, 127374, 2),
|
||||
(127377, 127386, 2),
|
||||
(127488, 127490, 2),
|
||||
(127504, 127547, 2),
|
||||
(127552, 127560, 2),
|
||||
(127568, 127569, 2),
|
||||
(127584, 127589, 2),
|
||||
(127744, 127776, 2),
|
||||
(127789, 127797, 2),
|
||||
(127799, 127868, 2),
|
||||
(127870, 127891, 2),
|
||||
(127904, 127946, 2),
|
||||
(127951, 127955, 2),
|
||||
(127968, 127984, 2),
|
||||
(127988, 127988, 2),
|
||||
(127992, 127994, 2),
|
||||
(127995, 127999, 0),
|
||||
(128000, 128062, 2),
|
||||
(128064, 128064, 2),
|
||||
(128066, 128252, 2),
|
||||
(128255, 128317, 2),
|
||||
(128331, 128334, 2),
|
||||
(128336, 128359, 2),
|
||||
(128378, 128378, 2),
|
||||
(128405, 128406, 2),
|
||||
(128420, 128420, 2),
|
||||
(128507, 128591, 2),
|
||||
(128640, 128709, 2),
|
||||
(128716, 128716, 2),
|
||||
(128720, 128722, 2),
|
||||
(128725, 128727, 2),
|
||||
(128732, 128735, 2),
|
||||
(128747, 128748, 2),
|
||||
(128756, 128764, 2),
|
||||
(128992, 129003, 2),
|
||||
(129008, 129008, 2),
|
||||
(129292, 129338, 2),
|
||||
(129340, 129349, 2),
|
||||
(129351, 129535, 2),
|
||||
(129648, 129660, 2),
|
||||
(129664, 129672, 2),
|
||||
(129680, 129725, 2),
|
||||
(129727, 129733, 2),
|
||||
(129742, 129755, 2),
|
||||
(129760, 129768, 2),
|
||||
(129776, 129784, 2),
|
||||
(131072, 196605, 2),
|
||||
(196608, 262141, 2),
|
||||
(917505, 917505, 0),
|
||||
(917536, 917631, 0),
|
||||
(917760, 917999, 0),
|
||||
]
|
||||
@@ -1,8 +1,5 @@
|
||||
from typing import Callable, Match, Optional
|
||||
import re
|
||||
|
||||
from ._emoji_codes import EMOJI
|
||||
|
||||
from typing import Callable, Match, Optional
|
||||
|
||||
_ReStringMatch = Match[str] # regex match object
|
||||
_ReSubCallable = Callable[[_ReStringMatch], str] # Callable invoked by re.sub
|
||||
@@ -15,8 +12,10 @@ def _emoji_replace(
|
||||
_emoji_sub: _EmojiSubMethod = re.compile(r"(:(\S*?)(?:(?:\-)(emoji|text))?:)").sub,
|
||||
) -> str:
|
||||
"""Replace emoji code in text."""
|
||||
from ._emoji_codes import EMOJI
|
||||
|
||||
get_emoji = EMOJI.__getitem__
|
||||
variants = {"text": "\uFE0E", "emoji": "\uFE0F"}
|
||||
variants = {"text": "\ufe0e", "emoji": "\ufe0f"}
|
||||
get_variant = variants.get
|
||||
default_variant_code = variants.get(default_variant, "") if default_variant else ""
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ class Inspect(JupyterMixin):
|
||||
docs (bool, optional): Also render doc strings. Defaults to True.
|
||||
private (bool, optional): Show private attributes (beginning with underscore). Defaults to False.
|
||||
dunder (bool, optional): Show attributes starting with double underscore. Defaults to False.
|
||||
sort (bool, optional): Sort attributes alphabetically. Defaults to True.
|
||||
sort (bool, optional): Sort attributes alphabetically, callables at the top, leading and trailing underscores ignored. Defaults to True.
|
||||
all (bool, optional): Show all attributes. Defaults to False.
|
||||
value (bool, optional): Pretty print value of object. Defaults to True.
|
||||
"""
|
||||
@@ -101,6 +101,10 @@ class Inspect(JupyterMixin):
|
||||
signature_text = self.highlighter(_signature)
|
||||
|
||||
qualname = name or getattr(obj, "__qualname__", name)
|
||||
if not isinstance(qualname, str):
|
||||
qualname = getattr(obj, "__name__", name)
|
||||
if not isinstance(qualname, str):
|
||||
qualname = name
|
||||
|
||||
# If obj is a module, there may be classes (which are callable) to display
|
||||
if inspect.isclass(obj):
|
||||
|
||||
Loaded 100 of 764 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user