-
Notifications
You must be signed in to change notification settings - Fork 204
SG-19308 bundle certifi #235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c111a6e
Bundles certifi to give a more consistent certificate behaviour.
pscadding b963d89
Working on the tests
pscadding 0ae9cde
Now manually finds cert file rather than using where()
pscadding 7fbef4c
Adds another test condition and adds method descriptions.
pscadding 51e39a7
fix for broken test and updated the requirements file.
pscadding 1aa24b3
Removed the rimu tests, as this site is no longer hosted.
pscadding File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .core import contents, where | ||
|
||
__version__ = "2020.06.20" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import argparse | ||
|
||
from certifi import contents, where | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument("-c", "--contents", action="store_true") | ||
args = parser.parse_args() | ||
|
||
if args.contents: | ||
print(contents()) | ||
else: | ||
print(where()) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
certifi.py | ||
~~~~~~~~~~ | ||
This module returns the installation location of cacert.pem or its contents. | ||
""" | ||
import os | ||
|
||
try: | ||
from importlib.resources import path as get_path, read_text | ||
|
||
_CACERT_CTX = None | ||
_CACERT_PATH = None | ||
|
||
def where(): | ||
# This is slightly terrible, but we want to delay extracting the file | ||
# in cases where we're inside of a zipimport situation until someone | ||
# actually calls where(), but we don't want to re-extract the file | ||
# on every call of where(), so we'll do it once then store it in a | ||
# global variable. | ||
global _CACERT_CTX | ||
global _CACERT_PATH | ||
if _CACERT_PATH is None: | ||
# This is slightly janky, the importlib.resources API wants you to | ||
# manage the cleanup of this file, so it doesn't actually return a | ||
# path, it returns a context manager that will give you the path | ||
# when you enter it and will do any cleanup when you leave it. In | ||
# the common case of not needing a temporary file, it will just | ||
# return the file system location and the __exit__() is a no-op. | ||
# | ||
# We also have to hold onto the actual context manager, because | ||
# it will do the cleanup whenever it gets garbage collected, so | ||
# we will also store that at the global level as well. | ||
_CACERT_CTX = get_path("certifi", "cacert.pem") | ||
_CACERT_PATH = str(_CACERT_CTX.__enter__()) | ||
|
||
return _CACERT_PATH | ||
|
||
|
||
except ImportError: | ||
# This fallback will work for Python versions prior to 3.7 that lack the | ||
# importlib.resources module but relies on the existing `where` function | ||
# so won't address issues with environments like PyOxidizer that don't set | ||
# __file__ on modules. | ||
def read_text(_module, _path, encoding="ascii"): | ||
with open(where(), "r", encoding=encoding) as data: | ||
return data.read() | ||
|
||
# If we don't have importlib.resources, then we will just do the old logic | ||
# of assuming we're on the filesystem and munge the path directly. | ||
def where(): | ||
f = os.path.dirname(__file__) | ||
|
||
return os.path.join(f, "cacert.pem") | ||
|
||
|
||
def contents(): | ||
return read_text("certifi", "cacert.pem", encoding="ascii") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'.core.contents' imported but unused
'.core.where' imported but unused