Skip to content
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

Fix cgi and importlib_resources deprecations #185

Merged
merged 5 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions gidgethub/sansio.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
when working with GitHub's API (e.g. validating webhook events or specifying the
API version you want your request to work against).
"""
import cgi
import datetime
from email.message import Message
import hmac
import http
import json
Expand Down Expand Up @@ -40,8 +40,10 @@ def _parse_content_type(content_type: Optional[str]) -> Tuple[Optional[str], str
if not content_type:
return None, "utf-8"
else:
type_, parameters = cgi.parse_header(content_type)
encoding = parameters.get("charset", "utf-8")
m = Message()
m["content-type"] = content_type
type_ = m.get_content_type()
encoding = m.get_param("charset") or "utf-8"
return type_, encoding


Expand Down
4 changes: 3 additions & 1 deletion tests/test_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,9 @@ class TestGraphQL:
"""Test gidgethub.abc.GitHubAPI.graphql()."""

def gh_and_response(self, payload_filename):
payload = importlib_resources.read_binary(graphql_samples, payload_filename)
payload = (
importlib_resources.files(graphql_samples) / payload_filename
).read_bytes()
status_code_match = re.match(r"^.+-(\d+)\.json$", payload_filename)
status_code = int(status_code_match.group(1))
return (
Expand Down
8 changes: 6 additions & 2 deletions tests/test_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ def test_get_jwt(self, time_mock):
time_mock.return_value = 1587069751.5588422

# test file copied from https://github.com/jpadilla/pyjwt/blob/master/tests/keys/testkey_rsa
private_key = importlib_resources.read_binary(rsa_key_samples, "test_rsa_key")
private_key = (
importlib_resources.files(rsa_key_samples) / "test_rsa_key"
).read_bytes()

result = apps.get_jwt(app_id=app_id, private_key=private_key)
expected_payload = {
Expand All @@ -38,7 +40,9 @@ async def test_get_installation_access_token(self):
installation_id = 6789
app_id = 12345

private_key = importlib_resources.read_binary(rsa_key_samples, "test_rsa_key")
private_key = (
importlib_resources.files(rsa_key_samples) / "test_rsa_key"
).read_bytes()

await apps.get_installation_access_token(
gh, installation_id=installation_id, app_id=app_id, private_key=private_key
Expand Down