Skip to content

Commit 47fb7ab

Browse files
hugovkadamchainzAA-Turner
authored
Fix deprecation warning on Python 3.11 (#199)
* Fix deprecation warning on Python 3.11 Fixes #192. * Retain support for Python 3.6 Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> * Bump actions versions * Use same 'where' for 3.6 and 3.7-3.10 Co-authored-by: Adam Johnson <me@adamj.eu> Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
1 parent b0b48e0 commit 47fb7ab

File tree

3 files changed

+63
-16
lines changed

3 files changed

+63
-16
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ jobs:
1010
runs-on: ubuntu-latest
1111

1212
steps:
13-
- uses: actions/checkout@v2
13+
- uses: actions/checkout@v3
1414
- name: Set up Python
15-
uses: actions/setup-python@v2
15+
uses: actions/setup-python@v4
1616
- name: Install dependencies
1717
run: pip install mypy
1818
- name: Run mypy
@@ -22,12 +22,17 @@ jobs:
2222
runs-on: ubuntu-latest
2323
strategy:
2424
matrix:
25-
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
26-
25+
python-version:
26+
- "3.6"
27+
- "3.7"
28+
- "3.8"
29+
- "3.9"
30+
- "3.10"
31+
- "3.11-dev"
2732
steps:
28-
- uses: actions/checkout@v2
33+
- uses: actions/checkout@v3
2934
- name: Set up Python ${{ matrix.python-version }}
30-
uses: actions/setup-python@v2
35+
uses: actions/setup-python@v4
3136
with:
3237
python-version: ${{ matrix.python-version }}
3338
- name: Install test dependencies
@@ -36,4 +41,4 @@ jobs:
3641
python -m pip install pytest
3742
- name: Test with pytest
3843
run: |
39-
pytest
44+
python -W error -m pytest

certifi/core.py

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
55
This module returns the installation location of cacert.pem or its contents.
66
"""
7-
import os
8-
import types
9-
from typing import Union
7+
import sys
108

11-
try:
12-
from importlib.resources import path as get_path, read_text
9+
10+
if sys.version_info >= (3, 9):
11+
12+
from importlib.resources import as_file, files
1313

1414
_CACERT_CTX = None
1515
_CACERT_PATH = None
@@ -33,13 +33,54 @@ def where() -> str:
3333
# We also have to hold onto the actual context manager, because
3434
# it will do the cleanup whenever it gets garbage collected, so
3535
# we will also store that at the global level as well.
36+
_CACERT_CTX = as_file(files("certifi").joinpath("cacert.pem"))
37+
_CACERT_PATH = str(_CACERT_CTX.__enter__())
38+
39+
return _CACERT_PATH
40+
41+
def contents() -> str:
42+
return files("certifi").joinpath("cacert.pem").read_text(encoding="ascii")
43+
44+
elif sys.version_info >= (3, 7):
45+
46+
from importlib.resources import path as get_path, read_text
47+
48+
_CACERT_CTX = None
49+
_CACERT_PATH = None
50+
51+
def where() -> str:
52+
# This is slightly terrible, but we want to delay extracting the
53+
# file in cases where we're inside of a zipimport situation until
54+
# someone actually calls where(), but we don't want to re-extract
55+
# the file on every call of where(), so we'll do it once then store
56+
# it in a global variable.
57+
global _CACERT_CTX
58+
global _CACERT_PATH
59+
if _CACERT_PATH is None:
60+
# This is slightly janky, the importlib.resources API wants you
61+
# to manage the cleanup of this file, so it doesn't actually
62+
# return a path, it returns a context manager that will give
63+
# you the path when you enter it and will do any cleanup when
64+
# you leave it. In the common case of not needing a temporary
65+
# file, it will just return the file system location and the
66+
# __exit__() is a no-op.
67+
#
68+
# We also have to hold onto the actual context manager, because
69+
# it will do the cleanup whenever it gets garbage collected, so
70+
# we will also store that at the global level as well.
3671
_CACERT_CTX = get_path("certifi", "cacert.pem")
3772
_CACERT_PATH = str(_CACERT_CTX.__enter__())
3873

3974
return _CACERT_PATH
4075

76+
def contents() -> str:
77+
return read_text("certifi", "cacert.pem", encoding="ascii")
78+
79+
else:
80+
import os
81+
import types
82+
from typing import Union
4183

42-
except ImportError:
4384
Package = Union[types.ModuleType, str]
4485
Resource = Union[str, "os.PathLike"]
4586

@@ -63,6 +104,5 @@ def where() -> str:
63104

64105
return os.path.join(f, "cacert.pem")
65106

66-
67-
def contents() -> str:
68-
return read_text("certifi", "cacert.pem", encoding="ascii")
107+
def contents() -> str:
108+
return read_text("certifi", "cacert.pem", encoding="ascii")

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@
5454
'Natural Language :: English',
5555
'Programming Language :: Python',
5656
'Programming Language :: Python :: 3',
57+
'Programming Language :: Python :: 3 :: Only',
5758
'Programming Language :: Python :: 3.6',
5859
'Programming Language :: Python :: 3.7',
5960
'Programming Language :: Python :: 3.8',
6061
'Programming Language :: Python :: 3.9',
6162
'Programming Language :: Python :: 3.10',
63+
'Programming Language :: Python :: 3.11',
6264
],
6365
project_urls={
6466
'Source': 'https://github.com/certifi/python-certifi',

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy