urlpattern 0.1.5__tar.gz → 0.1.7__tar.gz
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-0.1.5 → urlpattern-0.1.7}/.github/workflows/CI.yml +30 -26
- {urlpattern-0.1.5 → urlpattern-0.1.7}/Cargo.lock +21 -21
- {urlpattern-0.1.5 → urlpattern-0.1.7}/Cargo.toml +2 -2
- {urlpattern-0.1.5 → urlpattern-0.1.7}/PKG-INFO +24 -11
- {urlpattern-0.1.5 → urlpattern-0.1.7}/README.md +22 -9
- {urlpattern-0.1.5 → urlpattern-0.1.7}/pyproject.toml +1 -1
- {urlpattern-0.1.5 → urlpattern-0.1.7}/src/lib.rs +1 -1
- {urlpattern-0.1.5 → urlpattern-0.1.7}/tests/test_lib.py +5 -2
- {urlpattern-0.1.5 → urlpattern-0.1.7}/tests/urlpatterntestdata.json +10 -0
- {urlpattern-0.1.5 → urlpattern-0.1.7}/.devcontainer/devcontainer.json +0 -0
- {urlpattern-0.1.5 → urlpattern-0.1.7}/.github/dependabot.yml +0 -0
- {urlpattern-0.1.5 → urlpattern-0.1.7}/.gitignore +0 -0
- {urlpattern-0.1.5 → urlpattern-0.1.7}/.vscode/extensions.json +0 -0
- {urlpattern-0.1.5 → urlpattern-0.1.7}/.vscode/settings.json +0 -0
- {urlpattern-0.1.5 → urlpattern-0.1.7}/LICENSE +0 -0
- {urlpattern-0.1.5 → urlpattern-0.1.7}/tests/__init__.py +0 -0
- {urlpattern-0.1.5 → urlpattern-0.1.7}/urlpattern.pyi +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# This file is autogenerated by maturin v1.
|
|
1
|
+
# This file is autogenerated by maturin v1.11.5
|
|
2
2
|
# To update, run
|
|
3
3
|
#
|
|
4
4
|
# maturin generate-ci --pytest github
|
|
@@ -37,8 +37,8 @@ jobs:
|
|
|
37
37
|
- runner: ubuntu-22.04
|
|
38
38
|
target: ppc64le
|
|
39
39
|
steps:
|
|
40
|
-
- uses: actions/checkout@
|
|
41
|
-
- uses: actions/setup-python@
|
|
40
|
+
- uses: actions/checkout@v6
|
|
41
|
+
- uses: actions/setup-python@v6
|
|
42
42
|
with:
|
|
43
43
|
python-version: 3.x
|
|
44
44
|
- name: Build wheels
|
|
@@ -49,7 +49,7 @@ jobs:
|
|
|
49
49
|
sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
|
|
50
50
|
manylinux: auto
|
|
51
51
|
- name: Upload wheels
|
|
52
|
-
uses: actions/upload-artifact@
|
|
52
|
+
uses: actions/upload-artifact@v5
|
|
53
53
|
with:
|
|
54
54
|
name: wheels-linux-${{ matrix.platform.target }}
|
|
55
55
|
path: dist
|
|
@@ -93,8 +93,8 @@ jobs:
|
|
|
93
93
|
- runner: ubuntu-22.04
|
|
94
94
|
target: armv7
|
|
95
95
|
steps:
|
|
96
|
-
- uses: actions/checkout@
|
|
97
|
-
- uses: actions/setup-python@
|
|
96
|
+
- uses: actions/checkout@v6
|
|
97
|
+
- uses: actions/setup-python@v6
|
|
98
98
|
with:
|
|
99
99
|
python-version: 3.x
|
|
100
100
|
- name: Build wheels
|
|
@@ -105,7 +105,7 @@ jobs:
|
|
|
105
105
|
sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
|
|
106
106
|
manylinux: musllinux_1_2
|
|
107
107
|
- name: Upload wheels
|
|
108
|
-
uses: actions/upload-artifact@
|
|
108
|
+
uses: actions/upload-artifact@v5
|
|
109
109
|
with:
|
|
110
110
|
name: wheels-musllinux-${{ matrix.platform.target }}
|
|
111
111
|
path: dist
|
|
@@ -147,14 +147,19 @@ jobs:
|
|
|
147
147
|
platform:
|
|
148
148
|
- runner: windows-latest
|
|
149
149
|
target: x64
|
|
150
|
+
python_arch: x64
|
|
150
151
|
- runner: windows-latest
|
|
151
152
|
target: x86
|
|
153
|
+
python_arch: x86
|
|
154
|
+
- runner: windows-11-arm
|
|
155
|
+
target: aarch64
|
|
156
|
+
python_arch: arm64
|
|
152
157
|
steps:
|
|
153
|
-
- uses: actions/checkout@
|
|
154
|
-
- uses: actions/setup-python@
|
|
158
|
+
- uses: actions/checkout@v6
|
|
159
|
+
- uses: actions/setup-python@v6
|
|
155
160
|
with:
|
|
156
|
-
python-version: 3.
|
|
157
|
-
architecture: ${{ matrix.platform.
|
|
161
|
+
python-version: 3.13
|
|
162
|
+
architecture: ${{ matrix.platform.python_arch }}
|
|
158
163
|
- name: Build wheels
|
|
159
164
|
uses: PyO3/maturin-action@v1
|
|
160
165
|
with:
|
|
@@ -162,12 +167,11 @@ jobs:
|
|
|
162
167
|
args: --release --out dist --find-interpreter
|
|
163
168
|
sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
|
|
164
169
|
- name: Upload wheels
|
|
165
|
-
uses: actions/upload-artifact@
|
|
170
|
+
uses: actions/upload-artifact@v5
|
|
166
171
|
with:
|
|
167
172
|
name: wheels-windows-${{ matrix.platform.target }}
|
|
168
173
|
path: dist
|
|
169
174
|
- name: pytest
|
|
170
|
-
if: ${{ !startsWith(matrix.platform.target, 'aarch64') }}
|
|
171
175
|
shell: bash
|
|
172
176
|
run: |
|
|
173
177
|
set -e
|
|
@@ -182,13 +186,13 @@ jobs:
|
|
|
182
186
|
strategy:
|
|
183
187
|
matrix:
|
|
184
188
|
platform:
|
|
185
|
-
- runner: macos-
|
|
189
|
+
- runner: macos-15-intel
|
|
186
190
|
target: x86_64
|
|
187
|
-
- runner: macos-
|
|
191
|
+
- runner: macos-latest
|
|
188
192
|
target: aarch64
|
|
189
193
|
steps:
|
|
190
|
-
- uses: actions/checkout@
|
|
191
|
-
- uses: actions/setup-python@
|
|
194
|
+
- uses: actions/checkout@v6
|
|
195
|
+
- uses: actions/setup-python@v6
|
|
192
196
|
with:
|
|
193
197
|
python-version: 3.x
|
|
194
198
|
- name: Build wheels
|
|
@@ -198,7 +202,7 @@ jobs:
|
|
|
198
202
|
args: --release --out dist --find-interpreter
|
|
199
203
|
sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
|
|
200
204
|
- name: Upload wheels
|
|
201
|
-
uses: actions/upload-artifact@
|
|
205
|
+
uses: actions/upload-artifact@v5
|
|
202
206
|
with:
|
|
203
207
|
name: wheels-macos-${{ matrix.platform.target }}
|
|
204
208
|
path: dist
|
|
@@ -214,14 +218,14 @@ jobs:
|
|
|
214
218
|
sdist:
|
|
215
219
|
runs-on: ubuntu-latest
|
|
216
220
|
steps:
|
|
217
|
-
- uses: actions/checkout@
|
|
221
|
+
- uses: actions/checkout@v6
|
|
218
222
|
- name: Build sdist
|
|
219
223
|
uses: PyO3/maturin-action@v1
|
|
220
224
|
with:
|
|
221
225
|
command: sdist
|
|
222
226
|
args: --out dist
|
|
223
227
|
- name: Upload sdist
|
|
224
|
-
uses: actions/upload-artifact@
|
|
228
|
+
uses: actions/upload-artifact@v5
|
|
225
229
|
with:
|
|
226
230
|
name: wheels-sdist
|
|
227
231
|
path: dist
|
|
@@ -240,14 +244,14 @@ jobs:
|
|
|
240
244
|
# Used to generate artifact attestation
|
|
241
245
|
attestations: write
|
|
242
246
|
steps:
|
|
243
|
-
- uses: actions/download-artifact@
|
|
247
|
+
- uses: actions/download-artifact@v6
|
|
244
248
|
- name: Generate artifact attestation
|
|
245
|
-
uses: actions/attest-build-provenance@
|
|
249
|
+
uses: actions/attest-build-provenance@v3
|
|
246
250
|
with:
|
|
247
251
|
subject-path: 'wheels-*/*'
|
|
252
|
+
- name: Install uv
|
|
253
|
+
if: ${{ startsWith(github.ref, 'refs/tags/') }}
|
|
254
|
+
uses: astral-sh/setup-uv@v7
|
|
248
255
|
- name: Publish to PyPI
|
|
249
256
|
if: ${{ startsWith(github.ref, 'refs/tags/') }}
|
|
250
|
-
|
|
251
|
-
with:
|
|
252
|
-
command: upload
|
|
253
|
-
args: --non-interactive --skip-existing wheels-*/*
|
|
257
|
+
run: uv publish 'wheels-*/*'
|
|
@@ -91,9 +91,9 @@ checksum = "7aedcccd01fc5fe81e6b489c15b247b8b0690feb23304303a9e560f37efc560a"
|
|
|
91
91
|
|
|
92
92
|
[[package]]
|
|
93
93
|
name = "icu_properties"
|
|
94
|
-
version = "2.1.
|
|
94
|
+
version = "2.1.2"
|
|
95
95
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
96
|
-
checksum = "
|
|
96
|
+
checksum = "020bfc02fe870ec3a66d93e677ccca0562506e5872c650f893269e08615d74ec"
|
|
97
97
|
dependencies = [
|
|
98
98
|
"icu_collections",
|
|
99
99
|
"icu_locale_core",
|
|
@@ -105,9 +105,9 @@ dependencies = [
|
|
|
105
105
|
|
|
106
106
|
[[package]]
|
|
107
107
|
name = "icu_properties_data"
|
|
108
|
-
version = "2.1.
|
|
108
|
+
version = "2.1.2"
|
|
109
109
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
110
|
-
checksum = "
|
|
110
|
+
checksum = "616c294cf8d725c6afcd8f55abc17c56464ef6211f9ed59cccffe534129c77af"
|
|
111
111
|
|
|
112
112
|
[[package]]
|
|
113
113
|
name = "icu_provider"
|
|
@@ -156,9 +156,9 @@ dependencies = [
|
|
|
156
156
|
|
|
157
157
|
[[package]]
|
|
158
158
|
name = "libc"
|
|
159
|
-
version = "0.2.
|
|
159
|
+
version = "0.2.180"
|
|
160
160
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
161
|
-
checksum = "
|
|
161
|
+
checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc"
|
|
162
162
|
|
|
163
163
|
[[package]]
|
|
164
164
|
name = "litemap"
|
|
@@ -195,9 +195,9 @@ checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"
|
|
|
195
195
|
|
|
196
196
|
[[package]]
|
|
197
197
|
name = "portable-atomic"
|
|
198
|
-
version = "1.
|
|
198
|
+
version = "1.13.0"
|
|
199
199
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
200
|
-
checksum = "
|
|
200
|
+
checksum = "f89776e4d69bb58bc6993e99ffa1d11f228b839984854c7daeb5d37f87cbe950"
|
|
201
201
|
|
|
202
202
|
[[package]]
|
|
203
203
|
name = "potential_utf"
|
|
@@ -210,9 +210,9 @@ dependencies = [
|
|
|
210
210
|
|
|
211
211
|
[[package]]
|
|
212
212
|
name = "proc-macro2"
|
|
213
|
-
version = "1.0.
|
|
213
|
+
version = "1.0.106"
|
|
214
214
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
215
|
-
checksum = "
|
|
215
|
+
checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
|
|
216
216
|
dependencies = [
|
|
217
217
|
"unicode-ident",
|
|
218
218
|
]
|
|
@@ -280,7 +280,7 @@ dependencies = [
|
|
|
280
280
|
|
|
281
281
|
[[package]]
|
|
282
282
|
name = "python-urlpattern"
|
|
283
|
-
version = "0.1.
|
|
283
|
+
version = "0.1.7"
|
|
284
284
|
dependencies = [
|
|
285
285
|
"pyo3",
|
|
286
286
|
"urlpattern",
|
|
@@ -288,9 +288,9 @@ dependencies = [
|
|
|
288
288
|
|
|
289
289
|
[[package]]
|
|
290
290
|
name = "quote"
|
|
291
|
-
version = "1.0.
|
|
291
|
+
version = "1.0.44"
|
|
292
292
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
293
|
-
checksum = "
|
|
293
|
+
checksum = "21b2ebcf727b7760c461f091f9f0f539b77b8e87f2fd88131e7f1b433b3cece4"
|
|
294
294
|
dependencies = [
|
|
295
295
|
"proc-macro2",
|
|
296
296
|
]
|
|
@@ -374,9 +374,9 @@ checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596"
|
|
|
374
374
|
|
|
375
375
|
[[package]]
|
|
376
376
|
name = "syn"
|
|
377
|
-
version = "2.0.
|
|
377
|
+
version = "2.0.114"
|
|
378
378
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
379
|
-
checksum = "
|
|
379
|
+
checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a"
|
|
380
380
|
dependencies = [
|
|
381
381
|
"proc-macro2",
|
|
382
382
|
"quote",
|
|
@@ -396,9 +396,9 @@ dependencies = [
|
|
|
396
396
|
|
|
397
397
|
[[package]]
|
|
398
398
|
name = "target-lexicon"
|
|
399
|
-
version = "0.13.
|
|
399
|
+
version = "0.13.4"
|
|
400
400
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
401
|
-
checksum = "
|
|
401
|
+
checksum = "b1dd07eb858a2067e2f3c7155d54e929265c264e6f37efe3ee7a8d1b5a1dd0ba"
|
|
402
402
|
|
|
403
403
|
[[package]]
|
|
404
404
|
name = "tinystr"
|
|
@@ -424,9 +424,9 @@ checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3"
|
|
|
424
424
|
|
|
425
425
|
[[package]]
|
|
426
426
|
name = "url"
|
|
427
|
-
version = "2.5.
|
|
427
|
+
version = "2.5.8"
|
|
428
428
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
429
|
-
checksum = "
|
|
429
|
+
checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed"
|
|
430
430
|
dependencies = [
|
|
431
431
|
"form_urlencoded",
|
|
432
432
|
"idna",
|
|
@@ -436,9 +436,9 @@ dependencies = [
|
|
|
436
436
|
|
|
437
437
|
[[package]]
|
|
438
438
|
name = "urlpattern"
|
|
439
|
-
version = "0.
|
|
439
|
+
version = "0.5.2"
|
|
440
440
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
441
|
-
checksum = "
|
|
441
|
+
checksum = "37ffe0983283c841b6c6e9f116833a0061cc690c0eb67994d65bbdfa5cd3f24e"
|
|
442
442
|
dependencies = [
|
|
443
443
|
"icu_properties",
|
|
444
444
|
"regex",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "python-urlpattern"
|
|
3
|
-
version = "0.1.
|
|
3
|
+
version = "0.1.7"
|
|
4
4
|
authors = ["방성범 (Bang Seongbeom) <bangseongbeom@gmail.com>"]
|
|
5
5
|
edition = "2024"
|
|
6
6
|
description = "An implementation of the URL Pattern Standard for Python written in Rust."
|
|
@@ -16,4 +16,4 @@ crate-type = ["cdylib"]
|
|
|
16
16
|
|
|
17
17
|
[dependencies]
|
|
18
18
|
pyo3 = "0.27.2"
|
|
19
|
-
deno_urlpattern = { package = "urlpattern", version = "0.
|
|
19
|
+
deno_urlpattern = { package = "urlpattern", version = "0.5.2" }
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: urlpattern
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.7
|
|
4
4
|
Classifier: Development Status :: 4 - Beta
|
|
5
5
|
Classifier: Intended Audience :: Developers
|
|
6
6
|
Classifier: License :: OSI Approved :: MIT License
|
|
@@ -26,8 +26,8 @@ Author-email: "방성범 (Bang Seongbeom)" <bangseongbeom@gmail.com>
|
|
|
26
26
|
Requires-Python: >=3.8
|
|
27
27
|
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
28
28
|
Project-URL: Homepage, https://github.com/urlpattern/python-urlpattern
|
|
29
|
-
Project-URL: Repository, https://github.com/urlpattern/python-urlpattern.git
|
|
30
29
|
Project-URL: Issues, https://github.com/urlpattern/python-urlpattern/issues
|
|
30
|
+
Project-URL: Repository, https://github.com/urlpattern/python-urlpattern.git
|
|
31
31
|
|
|
32
32
|
# URL Pattern
|
|
33
33
|
|
|
@@ -40,7 +40,7 @@ An implementation of [the URL Pattern Standard](https://urlpattern.spec.whatwg.o
|
|
|
40
40
|
|
|
41
41
|
## Introduction
|
|
42
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.
|
|
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 (a.k.a. routing). 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
44
|
|
|
45
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
46
|
|
|
@@ -60,11 +60,11 @@ py -m pip install urlpattern
|
|
|
60
60
|
|
|
61
61
|
## Usage
|
|
62
62
|
|
|
63
|
-
Check [urlpattern.pyi](urlpattern.pyi).
|
|
63
|
+
Check [urlpattern.pyi](https://github.com/urlpattern/python-urlpattern/blob/main/urlpattern.pyi) or the examples below.
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
For various usage examples, you can also check [Chrome for Developers](https://developer.chrome.com/docs/web-platform/urlpattern) or [MDN](https://developer.mozilla.org/en-US/docs/Web/API/URL_Pattern_API) (you need to convert JavaScript into Python).
|
|
66
66
|
|
|
67
|
-
|
|
67
|
+
## Examples
|
|
68
68
|
|
|
69
69
|
### `test`
|
|
70
70
|
|
|
@@ -103,20 +103,33 @@ print(pattern.test("https://example.com/TeST")) # output: True
|
|
|
103
103
|
### Simple WSGI app
|
|
104
104
|
|
|
105
105
|
```py
|
|
106
|
-
from urlpattern import URLPattern
|
|
107
106
|
from wsgiref.simple_server import make_server
|
|
108
107
|
|
|
108
|
+
from urlpattern import URLPattern
|
|
109
109
|
|
|
110
110
|
user_id_pattern = URLPattern({"pathname": "/users/:id"})
|
|
111
111
|
|
|
112
112
|
|
|
113
|
+
def get_user_id(environ, start_response):
|
|
114
|
+
user_id = environ["result"]["pathname"]["groups"]["id"]
|
|
115
|
+
status = "200 OK"
|
|
116
|
+
response_headers = [("Content-type", "text/plain; charset=utf-8")]
|
|
117
|
+
start_response(status, response_headers)
|
|
118
|
+
return [f"{user_id=}".encode()]
|
|
119
|
+
|
|
120
|
+
|
|
113
121
|
def app(environ, start_response):
|
|
114
122
|
path = environ["PATH_INFO"]
|
|
123
|
+
method = environ["REQUEST_METHOD"]
|
|
115
124
|
|
|
116
125
|
if result := user_id_pattern.exec({"pathname": path}):
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
126
|
+
if method == "GET":
|
|
127
|
+
return get_user_id(environ | {"result": result}, start_response)
|
|
128
|
+
|
|
129
|
+
status = "404 Not Found"
|
|
130
|
+
response_headers = [("Content-type", "text/plain; charset=utf-8")]
|
|
131
|
+
start_response(status, response_headers)
|
|
132
|
+
return [b"Not Found"]
|
|
120
133
|
|
|
121
134
|
|
|
122
135
|
with make_server("", 8000, app) as httpd:
|
|
@@ -127,5 +140,5 @@ with make_server("", 8000, app) as httpd:
|
|
|
127
140
|
|
|
128
141
|
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
142
|
|
|
130
|
-
Check
|
|
143
|
+
Check `pytest.skip` in [`tests/test_lib.py`](https://github.com/urlpattern/python-urlpattern/blob/main/tests/test_lib.py).
|
|
131
144
|
|
|
@@ -9,7 +9,7 @@ An implementation of [the URL Pattern Standard](https://urlpattern.spec.whatwg.o
|
|
|
9
9
|
|
|
10
10
|
## Introduction
|
|
11
11
|
|
|
12
|
-
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.
|
|
12
|
+
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 (a.k.a. routing). 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.
|
|
13
13
|
|
|
14
14
|
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).
|
|
15
15
|
|
|
@@ -29,11 +29,11 @@ py -m pip install urlpattern
|
|
|
29
29
|
|
|
30
30
|
## Usage
|
|
31
31
|
|
|
32
|
-
Check [urlpattern.pyi](urlpattern.pyi).
|
|
32
|
+
Check [urlpattern.pyi](https://github.com/urlpattern/python-urlpattern/blob/main/urlpattern.pyi) or the examples below.
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
For various usage examples, you can also check [Chrome for Developers](https://developer.chrome.com/docs/web-platform/urlpattern) or [MDN](https://developer.mozilla.org/en-US/docs/Web/API/URL_Pattern_API) (you need to convert JavaScript into Python).
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
## Examples
|
|
37
37
|
|
|
38
38
|
### `test`
|
|
39
39
|
|
|
@@ -72,20 +72,33 @@ print(pattern.test("https://example.com/TeST")) # output: True
|
|
|
72
72
|
### Simple WSGI app
|
|
73
73
|
|
|
74
74
|
```py
|
|
75
|
-
from urlpattern import URLPattern
|
|
76
75
|
from wsgiref.simple_server import make_server
|
|
77
76
|
|
|
77
|
+
from urlpattern import URLPattern
|
|
78
78
|
|
|
79
79
|
user_id_pattern = URLPattern({"pathname": "/users/:id"})
|
|
80
80
|
|
|
81
81
|
|
|
82
|
+
def get_user_id(environ, start_response):
|
|
83
|
+
user_id = environ["result"]["pathname"]["groups"]["id"]
|
|
84
|
+
status = "200 OK"
|
|
85
|
+
response_headers = [("Content-type", "text/plain; charset=utf-8")]
|
|
86
|
+
start_response(status, response_headers)
|
|
87
|
+
return [f"{user_id=}".encode()]
|
|
88
|
+
|
|
89
|
+
|
|
82
90
|
def app(environ, start_response):
|
|
83
91
|
path = environ["PATH_INFO"]
|
|
92
|
+
method = environ["REQUEST_METHOD"]
|
|
84
93
|
|
|
85
94
|
if result := user_id_pattern.exec({"pathname": path}):
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
95
|
+
if method == "GET":
|
|
96
|
+
return get_user_id(environ | {"result": result}, start_response)
|
|
97
|
+
|
|
98
|
+
status = "404 Not Found"
|
|
99
|
+
response_headers = [("Content-type", "text/plain; charset=utf-8")]
|
|
100
|
+
start_response(status, response_headers)
|
|
101
|
+
return [b"Not Found"]
|
|
89
102
|
|
|
90
103
|
|
|
91
104
|
with make_server("", 8000, app) as httpd:
|
|
@@ -96,4 +109,4 @@ with make_server("", 8000, app) as httpd:
|
|
|
96
109
|
|
|
97
110
|
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/).
|
|
98
111
|
|
|
99
|
-
Check
|
|
112
|
+
Check `pytest.skip` in [`tests/test_lib.py`](https://github.com/urlpattern/python-urlpattern/blob/main/tests/test_lib.py).
|
|
@@ -46,14 +46,17 @@ def test(entry):
|
|
|
46
46
|
|
|
47
47
|
if isinstance(entry.get("expected_match"), dict):
|
|
48
48
|
result = pattern.exec(*entry["inputs"])
|
|
49
|
-
assert result
|
|
50
49
|
|
|
51
50
|
for key in entry["expected_match"]:
|
|
52
51
|
assert result[key] == entry["expected_match"][key]
|
|
53
52
|
|
|
53
|
+
else:
|
|
54
|
+
result = pattern.exec(*entry["inputs"])
|
|
55
|
+
assert result is None
|
|
56
|
+
|
|
54
57
|
if "exactly_empty_components" in entry:
|
|
55
58
|
result = pattern.exec(*entry["inputs"])
|
|
56
59
|
|
|
57
60
|
for component in entry["exactly_empty_components"]:
|
|
58
61
|
if result:
|
|
59
|
-
assert result[component]["groups"] == {}
|
|
62
|
+
assert result[component]["groups"] == {}
|
|
@@ -3108,5 +3108,15 @@
|
|
|
3108
3108
|
"hostname": { "input": "www.example.com", "groups": {} },
|
|
3109
3109
|
"pathname": { "input": "/path/with/x", "groups": { "0": "path/with/x" } }
|
|
3110
3110
|
}
|
|
3111
|
+
},
|
|
3112
|
+
{
|
|
3113
|
+
"pattern": [{ "hostname": ":domain(.*)" }],
|
|
3114
|
+
"inputs": [{ "hostname": "localhost" }],
|
|
3115
|
+
"expected_obj": {
|
|
3116
|
+
"hostname": ":domain(.*)"
|
|
3117
|
+
},
|
|
3118
|
+
"expected_match": {
|
|
3119
|
+
"hostname": { "input": "localhost", "groups": { "domain" : "localhost"} }
|
|
3120
|
+
}
|
|
3111
3121
|
}
|
|
3112
3122
|
]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|