Skip to content

Commit abc1437

Browse files
Drop HttpStatusError completely
1 parent b695bbd commit abc1437

File tree

2 files changed

+5
-29
lines changed

2 files changed

+5
-29
lines changed

micropip/_compat/_compat_in_pyodide.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from pyodide._package_loader import get_dynlibs
99
from pyodide.ffi import IN_BROWSER, to_js
10-
from pyodide.http import HttpStatusError, pyfetch
10+
from pyodide.http import pyfetch
1111

1212
from .compatibility_layer import CompatibilityLayer
1313

@@ -28,14 +28,6 @@
2828

2929

3030
class CompatibilityInPyodide(CompatibilityLayer):
31-
class HttpStatusError(Exception):
32-
status_code: int
33-
message: str
34-
35-
def __init__(self, status_code: int, message: str):
36-
self.status_code = status_code
37-
self.message = message
38-
super().__init__(message)
3931

4032
@staticmethod
4133
async def fetch_bytes(url: str, kwargs: dict[str, str]) -> bytes:
@@ -51,11 +43,9 @@ async def fetch_bytes(url: str, kwargs: dict[str, str]) -> bytes:
5143
async def fetch_string_and_headers(
5244
url: str, kwargs: dict[str, str]
5345
) -> tuple[str, dict[str, str]]:
54-
try:
55-
response = await pyfetch(url, **kwargs)
56-
response.raise_for_status()
57-
except HttpStatusError as e:
58-
raise CompatibilityInPyodide.HttpStatusError(e.status, str(e)) from e
46+
47+
response = await pyfetch(url, **kwargs)
48+
response.raise_for_status()
5949

6050
content = await response.string()
6151
headers: dict[str, str] = response.headers

micropip/_compat/_compat_not_in_pyodide.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import re
22
from pathlib import Path
33
from typing import IO, TYPE_CHECKING, Any
4-
from urllib.error import HTTPError
54
from urllib.request import Request, urlopen
65
from urllib.response import addinfourl
76

@@ -17,15 +16,6 @@ class CompatibilityNotInPyodide(CompatibilityLayer):
1716
# TODO: use packaging APIs here instead?
1817
_canonicalize_regex = re.compile(r"[-_.]+")
1918

20-
class HttpStatusError(Exception):
21-
status_code: int
22-
message: str
23-
24-
def __init__(self, status_code: int, message: str):
25-
self.status_code = status_code
26-
self.message = message
27-
super().__init__(message)
28-
2919
class loadedPackages(CompatibilityLayer.loadedPackages):
3020
@staticmethod
3121
def to_py():
@@ -43,11 +33,7 @@ async def fetch_bytes(url: str, kwargs: dict[str, Any]) -> bytes:
4333
async def fetch_string_and_headers(
4434
url: str, kwargs: dict[str, Any]
4535
) -> tuple[str, dict[str, str]]:
46-
try:
47-
response = CompatibilityNotInPyodide._fetch(url, kwargs=kwargs)
48-
except HTTPError as e:
49-
raise CompatibilityNotInPyodide.HttpStatusError(e.code, str(e)) from e
50-
36+
response = CompatibilityNotInPyodide._fetch(url, kwargs=kwargs)
5137
headers = {k.lower(): v for k, v in response.headers.items()}
5238
return response.read().decode(), headers
5339

0 commit comments

Comments
 (0)