diff --git a/Cargo.lock b/Cargo.lock index 2b0a624..95c208f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -280,7 +280,7 @@ dependencies = [ [[package]] name = "python-urlpattern" -version = "0.1.7" +version = "0.1.8" dependencies = [ "pyo3", "urlpattern", diff --git a/Cargo.toml b/Cargo.toml index 3d3a647..bafa905 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "python-urlpattern" -version = "0.1.7" +version = "0.1.8" authors = ["방성범 (Bang Seongbeom) "] edition = "2024" description = "An implementation of the URL Pattern Standard for Python written in Rust." diff --git a/README.md b/README.md index 58cefd4..6616e5b 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,8 @@ The URL Pattern Standard is a web standard for URL pattern matching. It is usefu It's a thin wrapper of [denoland/rust-urlpattern](https://github.com/denoland/rust-urlpattern) with [PyO3](https://github.com/PyO3/pyo3) + [Maturin](https://github.com/PyO3/maturin). +The naming conventions follow [the standard](https://urlpattern.spec.whatwg.org/) as closely as possible, similar to [xml.dom](https://docs.python.org/3/library/xml.dom.html). + ## Installation On Linux/UNIX or macOS: @@ -55,6 +57,16 @@ result = pattern.exec({"pathname": "/users/4163/"}) print(result["pathname"]["groups"]["id"]) # output: 4163 ``` +### `baseURL` + +```py +from urlpattern import URLPattern + +pattern = URLPattern({"pathname": "/admin/*"}, "https://example.com") +print(pattern.test({"pathname": "/admin/main/"}, "https://example.com")) # output: True +print(pattern.test("/admin/main/", "https://example.com")) # output: True +``` + ### `ignoreCase` ```py @@ -69,7 +81,7 @@ print(pattern.test("https://example.com/test")) # output: True print(pattern.test("https://example.com/TeST")) # output: True ``` -### Simple WSGI app +### A simple WSGI app ```py from wsgiref.simple_server import make_server diff --git a/pyproject.toml b/pyproject.toml index 2f818e6..ce28e98 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,6 +15,7 @@ classifiers = [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3 :: Only", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", @@ -22,7 +23,7 @@ classifiers = [ "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", "Programming Language :: Python :: 3.14", - "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: Free Threading", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Programming Language :: Rust", @@ -35,6 +36,3 @@ dynamic = ["version"] Homepage = "https://github.com/urlpattern/python-urlpattern" Repository = "https://github.com/urlpattern/python-urlpattern.git" Issues = "https://github.com/urlpattern/python-urlpattern/issues" - -[tool.maturin] -features = ["pyo3/extension-module"] diff --git a/urlpattern.pyi b/urlpattern.pyi index 1e2e266..73fb90e 100644 --- a/urlpattern.pyi +++ b/urlpattern.pyi @@ -1,6 +1,8 @@ -from typing_extensions import TypeAlias, TypedDict, overload +from typing import Optional, TypedDict, Union, overload -URLPatternInput: TypeAlias = str | URLPatternInit +from typing_extensions import TypeAlias + +URLPatternInput: TypeAlias = Union[str, URLPatternInit] class URLPatternOptions(TypedDict, total=False): ignoreCase: bool @@ -9,18 +11,55 @@ class URLPattern: @overload def __init__( self, - input: URLPatternInput, + input: str, + baseURL: str, + options: URLPatternOptions = {}, + ) -> None: ... + @overload + def __init__( + self, + input: str, baseURL: str, - options: URLPatternOptions | None = None, - ): ... + options: None, + ) -> None: ... @overload def __init__( - self, input: URLPatternInput, options: URLPatternOptions | None = None - ): ... - def test(self, input: URLPatternInput = {}, baseURL: str | None = None) -> bool: ... + self, + input: URLPatternInit, + baseURL: str, + options: URLPatternOptions = {}, + ) -> None: ... + @overload + def __init__( + self, + input: URLPatternInit, + baseURL: str, + options: None, + ) -> None: ... + @overload + def __init__(self, input: str, options: URLPatternOptions = {}) -> None: ... + @overload + def __init__(self, input: str, options: None) -> None: ... + @overload + def __init__( + self, input: URLPatternInit = {}, options: URLPatternOptions = {} + ) -> None: ... + @overload + def __init__(self, input: URLPatternInit, options: None) -> None: ... + @overload + def test(self, input: str, baseURL: Optional[str] = None) -> bool: ... + @overload + def test( + self, input: URLPatternInit = {}, baseURL: Optional[str] = None + ) -> bool: ... + @overload + def exec( + self, input: str, baseURL: Optional[str] = None + ) -> Optional[URLPatternResult]: ... + @overload def exec( - self, input: URLPatternInput = {}, baseURL: str | None = None - ) -> URLPatternResult | None: ... + self, input: URLPatternInit = {}, baseURL: Optional[str] = None + ) -> Optional[URLPatternResult]: ... @property def protocol(self) -> str: ... @property @@ -65,4 +104,4 @@ class URLPatternComponentResult(TypedDict): input: str groups: dict[str, str] -URLPatternCompatible: TypeAlias = str | URLPatternInit | URLPattern +URLPatternCompatible: TypeAlias = Union[str, URLPatternInit, URLPattern]