Skip to content

Commit

Permalink
keep REPO_API_REGEX
Browse files Browse the repository at this point in the history
  • Loading branch information
cjfghk5697 committed Aug 20, 2024
1 parent 1dd1a5f commit d298e4f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
5 changes: 1 addition & 4 deletions src/huggingface_hub/file_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,10 @@
from dataclasses import dataclass
from pathlib import Path
from typing import Any, BinaryIO, Dict, Literal, NoReturn, Optional, Tuple, Union
from .errors import FileMetadataError

from urllib.parse import quote, urlparse

import requests

from .errors import FileMetadataError

from . import __version__ # noqa: F401 # for backward compatibility
from ._local_folder import (
get_local_download_paths,
Expand Down Expand Up @@ -51,6 +47,7 @@
)
from .errors import (
EntryNotFoundError,
FileMetadataError,
GatedRepoError,
LocalEntryNotFoundError,
RepositoryNotFoundError,
Expand Down
18 changes: 17 additions & 1 deletion src/huggingface_hub/utils/_errors.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import re
from typing import Optional

from requests import HTTPError, Response

from ..errors import (
REPO_API_REGEX,
BadRequestError,
DisabledRepoError,
EntryNotFoundError,
Expand All @@ -14,6 +14,22 @@
)


REPO_API_REGEX = re.compile(
r"""
# staging or production endpoint
^https://[^/]+
(
# on /api/repo_type/repo_id
/api/(models|datasets|spaces)/(.+)
|
# or /repo_id/resolve/revision/...
/(.+)/resolve/(.+)
)
""",
flags=re.VERBOSE,
)


def hf_raise_for_status(response: Response, endpoint_name: Optional[str] = None) -> None:
"""
Internal version of `response.raise_for_status()` that will refine a
Expand Down
3 changes: 1 addition & 2 deletions tests/test_utils_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
from requests.models import PreparedRequest, Response

from huggingface_hub.errors import (
REPO_API_REGEX,
BadRequestError,
DisabledRepoError,
EntryNotFoundError,
HfHubHTTPError,
RepositoryNotFoundError,
RevisionNotFoundError,
)
from huggingface_hub.utils._errors import hf_raise_for_status
from huggingface_hub.utils._errors import REPO_API_REGEX, hf_raise_for_status


class TestErrorUtils(unittest.TestCase):
Expand Down

0 comments on commit d298e4f

Please sign in to comment.