|
12 | 12 | the *-nouser* option. |
13 | 13 | """ |
14 | 14 | # |
15 | | -# (C) Pywikibot team, 2007-2024 |
| 15 | +# (C) Pywikibot team, 2007-2025 |
16 | 16 | # |
17 | 17 | # Distributed under the terms of the MIT license. |
18 | 18 | # |
19 | 19 | from __future__ import annotations |
20 | 20 |
|
21 | | -import codecs |
22 | 21 | import os |
23 | 22 | import sys |
| 23 | +from pathlib import Path |
24 | 24 |
|
25 | 25 | import pywikibot |
26 | 26 | from pywikibot.version import getversion |
@@ -75,17 +75,20 @@ def main(*args: str) -> None: |
75 | 75 | or not hasattr(requests.certs, 'where') |
76 | 76 | or not callable(requests.certs.where)): |
77 | 77 | pywikibot.info(' cacerts: not defined') |
78 | | - elif not os.path.isfile(requests.certs.where()): |
79 | | - pywikibot.info(f' cacerts: {requests.certs.where()} (missing)') |
80 | 78 | else: |
81 | | - pywikibot.info(' cacerts: ' + requests.certs.where()) |
82 | | - |
83 | | - with codecs.open(requests.certs.where(), 'r', 'utf-8') as cert_file: |
84 | | - text = cert_file.read() |
| 79 | + cert = Path(requests.certs.where()) |
| 80 | + # is_symlink() required for Python 3.12 and below. |
| 81 | + # Otherwise follow_symlinks=True could be used in is_file(). |
| 82 | + if not cert.is_file() or cert.is_symlink(): |
| 83 | + pywikibot.info(f' cacerts: {cert.name} (missing)') |
| 84 | + else: |
| 85 | + pywikibot.info(f' cacerts: {cert}') |
| 86 | + text = cert.read_text(encoding='utf-8') |
85 | 87 | if WMF_CACERT in text: |
86 | 88 | has_wikimedia_cert = True |
87 | | - pywikibot.info(' certificate test: {}' |
88 | | - .format('ok' if has_wikimedia_cert else 'not ok')) |
| 89 | + pywikibot.info(' certificate test: {}' |
| 90 | + .format('ok' if has_wikimedia_cert else 'not ok')) |
| 91 | + |
89 | 92 | if not has_wikimedia_cert: |
90 | 93 | pywikibot.info(' Please reinstall requests!') |
91 | 94 |
|
|
0 commit comments