Skip to content

Commit

Permalink
unconflicted
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbe committed Oct 28, 2024
2 parents b490339 + 3c7a3ed commit cdc5c5d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pre-commit-detect-outdated.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
name: Detect outdated pre-commit hooks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/checkout@v4

- name: Set up Python 3.12
uses: actions/setup-python@v5
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
name: Run pre-commit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.12
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
python-version: [3.9, "3.10", 3.11, 3.12]

steps:
- uses: actions/checkout@v4.2.2
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
Expand Down
11 changes: 7 additions & 4 deletions hashin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

from __future__ import print_function
import argparse
import cgi
import difflib
from email.headerregistry import HeaderRegistry
import tempfile
import os
import re
Expand Down Expand Up @@ -52,6 +52,9 @@ def _verbose(*args):
print("* " + " ".join(args))


_header_registry = HeaderRegistry()


def _download(url, binary=False):
try:
r = urlopen(url)
Expand All @@ -64,7 +67,7 @@ def _download(url, binary=False):
# Note that urlopen will, by default, follow redirects.
status_code = r.getcode()
if 301 <= status_code < 400:
location, _ = cgi.parse_header(r.headers.get("location", ""))
location = r.headers.get("location", "")
if not location:
raise PackageError(
"No 'Location' header on {0} ({1})".format(url, status_code)
Expand All @@ -76,8 +79,8 @@ def _download(url, binary=False):
raise PackageError("Download error. {0} on {1}".format(status_code, url))
if binary:
return r.read()
_, params = cgi.parse_header(r.headers.get("Content-Type", ""))
encoding = params.get("charset", "utf-8")
content_type = _header_registry("content-type", r.headers.get("Content-Type", ""))
encoding = content_type.params.get("charset", "utf-8")
return r.read().decode(encoding)


Expand Down

0 comments on commit cdc5c5d

Please sign in to comment.