urlpattern 0.1.5__cp314-cp314-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
urlpattern/__init__.py ADDED
@@ -0,0 +1,5 @@
1
+ from .urlpattern import *
2
+
3
+ __doc__ = urlpattern.__doc__
4
+ if hasattr(urlpattern, "__all__"):
5
+ __all__ = urlpattern.__all__
@@ -0,0 +1,68 @@
1
+ from typing_extensions import TypeAlias, TypedDict, overload
2
+
3
+ URLPatternInput: TypeAlias = str | URLPatternInit
4
+
5
+ class URLPatternOptions(TypedDict, total=False):
6
+ ignoreCase: bool
7
+
8
+ class URLPattern:
9
+ @overload
10
+ def __init__(
11
+ self,
12
+ input: URLPatternInput,
13
+ baseURL: str,
14
+ options: URLPatternOptions | None = None,
15
+ ): ...
16
+ @overload
17
+ def __init__(
18
+ self, input: URLPatternInput, options: URLPatternOptions | None = None
19
+ ): ...
20
+ def test(self, input: URLPatternInput = {}, baseURL: str | None = None) -> bool: ...
21
+ def exec(
22
+ self, input: URLPatternInput = {}, baseURL: str | None = None
23
+ ) -> URLPatternResult | None: ...
24
+ @property
25
+ def protocol(self) -> str: ...
26
+ @property
27
+ def username(self) -> str: ...
28
+ @property
29
+ def password(self) -> str: ...
30
+ @property
31
+ def hostname(self) -> str: ...
32
+ @property
33
+ def port(self) -> str: ...
34
+ @property
35
+ def pathname(self) -> str: ...
36
+ @property
37
+ def search(self) -> str: ...
38
+ @property
39
+ def hash(self) -> str: ...
40
+
41
+ class URLPatternInit(TypedDict, total=False):
42
+ protocol: str
43
+ username: str
44
+ password: str
45
+ hostname: str
46
+ port: str
47
+ pathname: str
48
+ search: str
49
+ hash: str
50
+ baseURL: str
51
+
52
+ class URLPatternResult(TypedDict):
53
+ inputs: list[URLPatternInput]
54
+
55
+ protocol: URLPatternComponentResult
56
+ username: URLPatternComponentResult
57
+ password: URLPatternComponentResult
58
+ hostname: URLPatternComponentResult
59
+ port: URLPatternComponentResult
60
+ pathname: URLPatternComponentResult
61
+ search: URLPatternComponentResult
62
+ hash: URLPatternComponentResult
63
+
64
+ class URLPatternComponentResult(TypedDict):
65
+ input: str
66
+ groups: dict[str, str]
67
+
68
+ URLPatternCompatible: TypeAlias = str | URLPatternInit | URLPattern
urlpattern/py.typed ADDED
File without changes
@@ -0,0 +1,131 @@
1
+ Metadata-Version: 2.4
2
+ Name: urlpattern
3
+ Version: 0.1.5
4
+ Classifier: Development Status :: 4 - Beta
5
+ Classifier: Intended Audience :: Developers
6
+ Classifier: License :: OSI Approved :: MIT License
7
+ Classifier: Operating System :: OS Independent
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.8
10
+ Classifier: Programming Language :: Python :: 3.9
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Programming Language :: Python :: 3.14
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Programming Language :: Python :: Implementation :: CPython
18
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
19
+ Classifier: Programming Language :: Rust
20
+ Classifier: Topic :: Internet :: WWW/HTTP
21
+ Classifier: Typing :: Typed
22
+ License-File: LICENSE
23
+ Summary: An implementation of the URL Pattern Standard for Python written in Rust.
24
+ Keywords: urlpattern
25
+ Author-email: "방성범 (Bang Seongbeom)" <bangseongbeom@gmail.com>
26
+ Requires-Python: >=3.8
27
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
28
+ Project-URL: Homepage, https://github.com/urlpattern/python-urlpattern
29
+ Project-URL: Repository, https://github.com/urlpattern/python-urlpattern.git
30
+ Project-URL: Issues, https://github.com/urlpattern/python-urlpattern/issues
31
+
32
+ # URL Pattern
33
+
34
+ [![PyPI - Version](https://img.shields.io/pypi/v/urlpattern)](https://pypi.org/project/urlpattern/)
35
+ [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/urlpattern)](https://pypi.org/project/urlpattern/)
36
+ [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
37
+ [![CI](https://github.com/urlpattern/python-urlpattern/actions/workflows/CI.yml/badge.svg)](https://github.com/urlpattern/python-urlpattern/actions)
38
+
39
+ An implementation of [the URL Pattern Standard](https://urlpattern.spec.whatwg.org/) for Python written in Rust.
40
+
41
+ ## Introduction
42
+
43
+ The URL Pattern Standard is a web standard for URL pattern matching. It is useful on the server side when serving different pages based on the URL. It provides pattern matching syntax like `/users/:id`, similar to [route parameters in Express](https://expressjs.com/en/guide/routing.html#route-parameters) or [Path-to-RegExp](https://github.com/pillarjs/path-to-regexp). You can use it as a foundation to build your own web server or framework.
44
+
45
+ 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).
46
+
47
+ ## Installation
48
+
49
+ On Linux/UNIX or macOS:
50
+
51
+ ```sh
52
+ pip install urlpattern
53
+ ```
54
+
55
+ On Windows:
56
+
57
+ ```sh
58
+ py -m pip install urlpattern
59
+ ```
60
+
61
+ ## Usage
62
+
63
+ Check [urlpattern.pyi](urlpattern.pyi).
64
+
65
+ ## Examples
66
+
67
+ For various usage examples, refer to [Chrome for Developers](https://developer.chrome.com/docs/web-platform/urlpattern) or [MDN](https://developer.mozilla.org/en-US/docs/Web/API/URLPattern) (you may need to convert JavaScript into Python).
68
+
69
+ ### `test`
70
+
71
+ ```py
72
+ from urlpattern import URLPattern
73
+
74
+ pattern = URLPattern("https://example.com/admin/*")
75
+ print(pattern.test("https://example.com/admin/main/")) # output: True
76
+ print(pattern.test("https://example.com/main/")) # output: False
77
+ ```
78
+
79
+ ### `exec`
80
+
81
+ ```py
82
+ from urlpattern import URLPattern
83
+
84
+ pattern = URLPattern({"pathname": "/users/:id/"})
85
+ result = pattern.exec({"pathname": "/users/4163/"})
86
+ print(result["pathname"]["groups"]["id"]) # output: 4163
87
+ ```
88
+
89
+ ### `ignoreCase`
90
+
91
+ ```py
92
+ from urlpattern import URLPattern
93
+
94
+ pattern = URLPattern("https://example.com/test")
95
+ print(pattern.test("https://example.com/test")) # output: True
96
+ print(pattern.test("https://example.com/TeST")) # output: False
97
+
98
+ pattern = URLPattern("https://example.com/test", {"ignoreCase": True})
99
+ print(pattern.test("https://example.com/test")) # output: True
100
+ print(pattern.test("https://example.com/TeST")) # output: True
101
+ ```
102
+
103
+ ### Simple WSGI app
104
+
105
+ ```py
106
+ from urlpattern import URLPattern
107
+ from wsgiref.simple_server import make_server
108
+
109
+
110
+ user_id_pattern = URLPattern({"pathname": "/users/:id"})
111
+
112
+
113
+ def app(environ, start_response):
114
+ path = environ["PATH_INFO"]
115
+
116
+ if result := user_id_pattern.exec({"pathname": path}):
117
+ user_id = result["pathname"]["groups"]["id"]
118
+ start_response("200 OK", [("Content-Type", "text/plain; charset=utf-8")])
119
+ return [f"{user_id=}".encode()]
120
+
121
+
122
+ with make_server("", 8000, app) as httpd:
123
+ httpd.serve_forever()
124
+ ```
125
+
126
+ ## Limitations
127
+
128
+ Due to limitations in the dependency [denoland/rust-urlpattern](https://github.com/denoland/rust-urlpattern), it may not support all features specified in [the standard](https://urlpattern.spec.whatwg.org/).
129
+
130
+ Check the `pytest.skip` in [`tests/test_lib.py`](tests/test_lib.py).
131
+
@@ -0,0 +1,8 @@
1
+ urlpattern-0.1.5.dist-info/METADATA,sha256=yBvjCBMSMzXsAKM5S3iKcTxlswrBi3JYfhU0BkyP2fc,5039
2
+ urlpattern-0.1.5.dist-info/WHEEL,sha256=ZrAiv7lKoKZh206bhSq4g-n3q3ySUOJQmQ4WXAA7TE8,97
3
+ urlpattern-0.1.5.dist-info/licenses/LICENSE,sha256=_qapitbsCkJk_1XOkLpKwq-BiN5jH65q65PF4jnvJhg,1102
4
+ urlpattern/__init__.py,sha256=Yh9wWY3jN3l1xnfDMxdJFCrv7hLaidjhrUcnDS71DIU,123
5
+ urlpattern/__init__.pyi,sha256=9tMqj4QFu_P3SJuwJ--STpAsXwdHJMcZ7LTbP20U4Jg,1881
6
+ urlpattern/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ urlpattern/urlpattern.cp314-win_amd64.pyd,sha256=QkAhWEWHiBfxUEiWbcdG_STsFjokfWQkbd1e9mjgC0w,2511872
8
+ urlpattern-0.1.5.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: maturin (1.10.2)
3
+ Root-Is-Purelib: false
4
+ Tag: cp314-cp314-win_amd64
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 방성범 (Bang Seongbeom)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.