pidna 0.1.0__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.
- pidna-0.1.0/.github/workflows/ci.yml +136 -0
- pidna-0.1.0/.gitignore +12 -0
- pidna-0.1.0/Cargo.lock +133 -0
- pidna-0.1.0/Cargo.toml +19 -0
- pidna-0.1.0/LICENSE +21 -0
- pidna-0.1.0/PKG-INFO +73 -0
- pidna-0.1.0/README.md +46 -0
- pidna-0.1.0/SECURITY.md +11 -0
- pidna-0.1.0/benchmarks/bench.py +97 -0
- pidna-0.1.0/pyproject.toml +60 -0
- pidna-0.1.0/python/pidna/__init__.py +50 -0
- pidna-0.1.0/python/pidna/__init__.pyi +74 -0
- pidna-0.1.0/python/pidna/_pidna.pyi +54 -0
- pidna-0.1.0/python/pidna/codec.py +114 -0
- pidna-0.1.0/python/pidna/compat.py +15 -0
- pidna-0.1.0/python/pidna/core.py +78 -0
- pidna-0.1.0/python/pidna/intranges.py +28 -0
- pidna-0.1.0/python/pidna/package_data.py +1 -0
- pidna-0.1.0/python/pidna/py.typed +0 -0
- pidna-0.1.0/src/idna_core.rs +907 -0
- pidna-0.1.0/src/lib.rs +397 -0
- pidna-0.1.0/src/punycode.rs +171 -0
- pidna-0.1.0/src/simd.rs +295 -0
- pidna-0.1.0/src/tables.rs +17768 -0
- pidna-0.1.0/src/unicode.rs +259 -0
- pidna-0.1.0/tests/test_adversarial.py +98 -0
- pidna-0.1.0/tests/test_concurrency_leak.py +50 -0
- pidna-0.1.0/tests/test_differential.py +143 -0
- pidna-0.1.0/tests/test_ecosystem.py +46 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
tags: ["v*"]
|
|
7
|
+
pull_request:
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
contents: read
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
lint-and-test-rust:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
- uses: dtolnay/rust-toolchain@stable
|
|
18
|
+
with:
|
|
19
|
+
components: rustfmt, clippy
|
|
20
|
+
- uses: Swatinem/rust-cache@v2
|
|
21
|
+
- run: cargo fmt --check
|
|
22
|
+
- run: cargo clippy --all-targets -- -D warnings
|
|
23
|
+
- run: cargo test --lib
|
|
24
|
+
|
|
25
|
+
build-wheels:
|
|
26
|
+
strategy:
|
|
27
|
+
fail-fast: false
|
|
28
|
+
matrix:
|
|
29
|
+
include:
|
|
30
|
+
- os: ubuntu-latest
|
|
31
|
+
target: x86_64
|
|
32
|
+
args: --release --compatibility manylinux2014
|
|
33
|
+
run_tests: true
|
|
34
|
+
- os: ubuntu-latest
|
|
35
|
+
target: musl-x86_64
|
|
36
|
+
args: --release --compatibility musllinux_1_2
|
|
37
|
+
run_tests: false
|
|
38
|
+
- os: ubuntu-24.04-arm
|
|
39
|
+
target: aarch64
|
|
40
|
+
args: --release --compatibility manylinux2014
|
|
41
|
+
run_tests: true
|
|
42
|
+
- os: ubuntu-24.04-arm
|
|
43
|
+
target: musl-aarch64
|
|
44
|
+
args: --release --compatibility musllinux_1_2
|
|
45
|
+
run_tests: false
|
|
46
|
+
- os: macos-15
|
|
47
|
+
target: aarch64
|
|
48
|
+
args: --release
|
|
49
|
+
run_tests: true
|
|
50
|
+
- os: macos-15
|
|
51
|
+
target: x86_64
|
|
52
|
+
args: --release --target x86_64-apple-darwin
|
|
53
|
+
run_tests: false
|
|
54
|
+
- os: windows-latest
|
|
55
|
+
target: x64
|
|
56
|
+
args: --release
|
|
57
|
+
run_tests: true
|
|
58
|
+
runs-on: ${{ matrix.os }}
|
|
59
|
+
steps:
|
|
60
|
+
- uses: actions/checkout@v4
|
|
61
|
+
- uses: actions/setup-python@v5
|
|
62
|
+
with:
|
|
63
|
+
python-version: "3.12"
|
|
64
|
+
- uses: PyO3/maturin-action@v1
|
|
65
|
+
with:
|
|
66
|
+
command: build
|
|
67
|
+
args: ${{ matrix.args }} -o dist
|
|
68
|
+
manylinux: auto
|
|
69
|
+
- name: Check wheel metadata
|
|
70
|
+
shell: bash
|
|
71
|
+
run: |
|
|
72
|
+
python -m pip install --upgrade pip twine
|
|
73
|
+
twine check dist/*.whl
|
|
74
|
+
- name: Install and test abi3 wheel
|
|
75
|
+
if: matrix.run_tests
|
|
76
|
+
shell: bash
|
|
77
|
+
run: |
|
|
78
|
+
python -m pip install pytest hypothesis idna mypy ruff abi3audit
|
|
79
|
+
python -m pip install dist/*.whl
|
|
80
|
+
pytest -v
|
|
81
|
+
- name: Static typing, stubtest, and abi3audit (Linux)
|
|
82
|
+
if: runner.os == 'Linux' && matrix.run_tests
|
|
83
|
+
run: |
|
|
84
|
+
ruff format --check python tests
|
|
85
|
+
ruff check python tests
|
|
86
|
+
mypy --strict python/pidna
|
|
87
|
+
stubtest --ignore-disjoint-base pidna
|
|
88
|
+
abi3audit --strict dist/*.whl
|
|
89
|
+
- uses: actions/upload-artifact@v4
|
|
90
|
+
with:
|
|
91
|
+
name: wheels-${{ matrix.os }}-${{ matrix.target }}
|
|
92
|
+
path: dist/*.whl
|
|
93
|
+
|
|
94
|
+
build-sdist:
|
|
95
|
+
runs-on: ubuntu-latest
|
|
96
|
+
steps:
|
|
97
|
+
- uses: actions/checkout@v4
|
|
98
|
+
- uses: PyO3/maturin-action@v1
|
|
99
|
+
with:
|
|
100
|
+
command: sdist
|
|
101
|
+
args: -o dist
|
|
102
|
+
- uses: actions/upload-artifact@v4
|
|
103
|
+
with:
|
|
104
|
+
name: sdist
|
|
105
|
+
path: dist/*.tar.gz
|
|
106
|
+
|
|
107
|
+
publish:
|
|
108
|
+
if: startsWith(github.ref, 'refs/tags/v')
|
|
109
|
+
needs: [lint-and-test-rust, build-wheels, build-sdist]
|
|
110
|
+
runs-on: ubuntu-latest
|
|
111
|
+
environment: pypi
|
|
112
|
+
permissions:
|
|
113
|
+
id-token: write
|
|
114
|
+
attestations: write
|
|
115
|
+
contents: write
|
|
116
|
+
steps:
|
|
117
|
+
- uses: actions/download-artifact@v4
|
|
118
|
+
with:
|
|
119
|
+
path: dist
|
|
120
|
+
merge-multiple: true
|
|
121
|
+
- name: Attest build provenance (SLSA)
|
|
122
|
+
uses: actions/attest-build-provenance@v2
|
|
123
|
+
with:
|
|
124
|
+
subject-path: "dist/*"
|
|
125
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
126
|
+
with:
|
|
127
|
+
packages-dir: dist/
|
|
128
|
+
- name: Generate SHA-256 checksums
|
|
129
|
+
run: (cd dist && sha256sum *.whl *.tar.gz) > SHA256SUMS.txt
|
|
130
|
+
- name: Create GitHub Release
|
|
131
|
+
uses: softprops/action-gh-release@v2
|
|
132
|
+
with:
|
|
133
|
+
generate_release_notes: true
|
|
134
|
+
files: |
|
|
135
|
+
dist/*
|
|
136
|
+
SHA256SUMS.txt
|
pidna-0.1.0/.gitignore
ADDED
pidna-0.1.0/Cargo.lock
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# This file is automatically @generated by Cargo.
|
|
2
|
+
# It is not intended for manual editing.
|
|
3
|
+
version = 4
|
|
4
|
+
|
|
5
|
+
[[package]]
|
|
6
|
+
name = "heck"
|
|
7
|
+
version = "0.5.0"
|
|
8
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
9
|
+
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
|
10
|
+
|
|
11
|
+
[[package]]
|
|
12
|
+
name = "libc"
|
|
13
|
+
version = "0.2.191"
|
|
14
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
15
|
+
checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
|
|
16
|
+
|
|
17
|
+
[[package]]
|
|
18
|
+
name = "once_cell"
|
|
19
|
+
version = "1.21.4"
|
|
20
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
21
|
+
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
|
22
|
+
|
|
23
|
+
[[package]]
|
|
24
|
+
name = "pidna"
|
|
25
|
+
version = "0.1.0"
|
|
26
|
+
dependencies = [
|
|
27
|
+
"pyo3",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[[package]]
|
|
31
|
+
name = "portable-atomic"
|
|
32
|
+
version = "1.15.0"
|
|
33
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
34
|
+
checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85"
|
|
35
|
+
|
|
36
|
+
[[package]]
|
|
37
|
+
name = "proc-macro2"
|
|
38
|
+
version = "1.0.107"
|
|
39
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
40
|
+
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
|
|
41
|
+
dependencies = [
|
|
42
|
+
"unicode-ident",
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
[[package]]
|
|
46
|
+
name = "pyo3"
|
|
47
|
+
version = "0.28.3"
|
|
48
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
49
|
+
checksum = "91fd8e38a3b50ed1167fb981cd6fd60147e091784c427b8f7183a7ee32c31c12"
|
|
50
|
+
dependencies = [
|
|
51
|
+
"libc",
|
|
52
|
+
"once_cell",
|
|
53
|
+
"portable-atomic",
|
|
54
|
+
"pyo3-build-config",
|
|
55
|
+
"pyo3-ffi",
|
|
56
|
+
"pyo3-macros",
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
[[package]]
|
|
60
|
+
name = "pyo3-build-config"
|
|
61
|
+
version = "0.28.3"
|
|
62
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
63
|
+
checksum = "e368e7ddfdeb98c9bca7f8383be1648fd84ab466bf2bc015e94008db6d35611e"
|
|
64
|
+
dependencies = [
|
|
65
|
+
"target-lexicon",
|
|
66
|
+
]
|
|
67
|
+
|
|
68
|
+
[[package]]
|
|
69
|
+
name = "pyo3-ffi"
|
|
70
|
+
version = "0.28.3"
|
|
71
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
72
|
+
checksum = "7f29e10af80b1f7ccaf7f69eace800a03ecd13e883acfacc1e5d0988605f651e"
|
|
73
|
+
dependencies = [
|
|
74
|
+
"libc",
|
|
75
|
+
"pyo3-build-config",
|
|
76
|
+
]
|
|
77
|
+
|
|
78
|
+
[[package]]
|
|
79
|
+
name = "pyo3-macros"
|
|
80
|
+
version = "0.28.3"
|
|
81
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
82
|
+
checksum = "df6e520eff47c45997d2fc7dd8214b25dd1310918bbb2642156ef66a67f29813"
|
|
83
|
+
dependencies = [
|
|
84
|
+
"proc-macro2",
|
|
85
|
+
"pyo3-macros-backend",
|
|
86
|
+
"quote",
|
|
87
|
+
"syn",
|
|
88
|
+
]
|
|
89
|
+
|
|
90
|
+
[[package]]
|
|
91
|
+
name = "pyo3-macros-backend"
|
|
92
|
+
version = "0.28.3"
|
|
93
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
94
|
+
checksum = "c4cdc218d835738f81c2338f822078af45b4afdf8b2e33cbb5916f108b813acb"
|
|
95
|
+
dependencies = [
|
|
96
|
+
"heck",
|
|
97
|
+
"proc-macro2",
|
|
98
|
+
"pyo3-build-config",
|
|
99
|
+
"quote",
|
|
100
|
+
"syn",
|
|
101
|
+
]
|
|
102
|
+
|
|
103
|
+
[[package]]
|
|
104
|
+
name = "quote"
|
|
105
|
+
version = "1.0.47"
|
|
106
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
107
|
+
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
|
|
108
|
+
dependencies = [
|
|
109
|
+
"proc-macro2",
|
|
110
|
+
]
|
|
111
|
+
|
|
112
|
+
[[package]]
|
|
113
|
+
name = "syn"
|
|
114
|
+
version = "2.0.119"
|
|
115
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
116
|
+
checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
|
|
117
|
+
dependencies = [
|
|
118
|
+
"proc-macro2",
|
|
119
|
+
"quote",
|
|
120
|
+
"unicode-ident",
|
|
121
|
+
]
|
|
122
|
+
|
|
123
|
+
[[package]]
|
|
124
|
+
name = "target-lexicon"
|
|
125
|
+
version = "0.13.6"
|
|
126
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
127
|
+
checksum = "8c447be3a2abfa84b2d91680c56600bd6b2873866de27b36ec911be705e291da"
|
|
128
|
+
|
|
129
|
+
[[package]]
|
|
130
|
+
name = "unicode-ident"
|
|
131
|
+
version = "1.0.27"
|
|
132
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
133
|
+
checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
|
pidna-0.1.0/Cargo.toml
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "pidna"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
edition = "2021"
|
|
5
|
+
license = "MIT"
|
|
6
|
+
description = "Fast drop-in replacement for idna in Python"
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
|
|
9
|
+
[lib]
|
|
10
|
+
name = "_pidna"
|
|
11
|
+
crate-type = ["cdylib", "rlib"]
|
|
12
|
+
|
|
13
|
+
[dependencies]
|
|
14
|
+
pyo3 = { version = "0.28", features = ["abi3-py39"] }
|
|
15
|
+
|
|
16
|
+
[profile.release]
|
|
17
|
+
lto = "thin"
|
|
18
|
+
codegen-units = 1
|
|
19
|
+
opt-level = 3
|
pidna-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, gatewaytofredom
|
|
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.
|
pidna-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pidna
|
|
3
|
+
Version: 0.1.0
|
|
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.9
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
15
|
+
Classifier: Programming Language :: Rust
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
17
|
+
Classifier: Typing :: Typed
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Summary: Fast drop-in replacement for idna in Python
|
|
20
|
+
Keywords: idna,uts46,punycode,dns,domain,unicode,rust
|
|
21
|
+
License-Expression: MIT
|
|
22
|
+
Requires-Python: >=3.9
|
|
23
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
24
|
+
Project-URL: Homepage, https://github.com/gatewaytofredom/pidna
|
|
25
|
+
Project-URL: Repository, https://github.com/gatewaytofredom/pidna
|
|
26
|
+
|
|
27
|
+
# pidna
|
|
28
|
+
|
|
29
|
+
[](https://github.com/gatewaytofredom/pidna/actions/workflows/ci.yml)
|
|
30
|
+
[](https://pypi.org/project/pidna/)
|
|
31
|
+
[](https://pypi.org/project/pidna/)
|
|
32
|
+
[](https://github.com/gatewaytofredom/pidna/blob/main/LICENSE)
|
|
33
|
+
|
|
34
|
+
A fast drop-in replacement for `idna` in Python. Validates and converts internationalized domain names (IDNA 2008 and UTS #46) up to 418x faster on ASCII domains and 10–16x faster on Unicode domains.
|
|
35
|
+
|
|
36
|
+
## Install
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pip install pidna
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Prebuilt wheels are included for Linux, macOS, and Windows (Python 3.9+, no Rust toolchain needed).
|
|
43
|
+
|
|
44
|
+
## Usage
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
import pidna
|
|
48
|
+
|
|
49
|
+
encoded = pidna.encode("münchen.de") # b"xn--mnchen-3ya.de"
|
|
50
|
+
decoded = pidna.decode(b"xn--mnchen-3ya.de") # "münchen.de"
|
|
51
|
+
uts46 = pidna.encode("API.GitHub.COM", uts46=True) # b"api.github.com"
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Performance
|
|
55
|
+
|
|
56
|
+
| Workload | `idna` (x86-64) | `pidna` (x86-64 AVX2) | `pidna` (Apple M4 NEON) |
|
|
57
|
+
|---|---:|---:|---:|
|
|
58
|
+
| Small ASCII (`api.github.com`, 50k) | 408.97 ms | 6.02 ms (**68.0x**) | 5.78 ms (**47.0x** vs M4 `idna`) |
|
|
59
|
+
| Medium ASCII UTS #46 (`API.GitHub.COM`, 50k) | 466.38 ms | 9.54 ms (**48.9x**) | 8.81 ms (**31.3x** vs M4 `idna`) |
|
|
60
|
+
| Long ASCII (8 labels, 20k) | 1501.13 ms | 3.59 ms (**418.1x**) | 3.45 ms (**286.2x** vs M4 `idna`) |
|
|
61
|
+
| Unicode UTS #46 (`münchen.de`, 20k) | 243.33 ms | 24.59 ms (**9.9x**) | 18.94 ms (**7.0x** vs M4 `idna`) |
|
|
62
|
+
| CJK (`例え.jp`, 20k) | 179.37 ms | 10.93 ms (**16.4x**) | 7.28 ms (**15.1x** vs M4 `idna`) |
|
|
63
|
+
|
|
64
|
+
## Under the hood
|
|
65
|
+
|
|
66
|
+
- Written in Rust (PyO3) with zero external runtime dependencies and runtime SIMD dispatch (AVX2 / SSE2 / ARM64 NEON)
|
|
67
|
+
- Compact `cp39-abi3` wheel with PEP 561 type stubs (`py.typed` + `__init__.pyi`)
|
|
68
|
+
- Verified with Hypothesis differential fuzzing against `idna`
|
|
69
|
+
|
|
70
|
+
## License
|
|
71
|
+
|
|
72
|
+
MIT
|
|
73
|
+
|
pidna-0.1.0/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# pidna
|
|
2
|
+
|
|
3
|
+
[](https://github.com/gatewaytofredom/pidna/actions/workflows/ci.yml)
|
|
4
|
+
[](https://pypi.org/project/pidna/)
|
|
5
|
+
[](https://pypi.org/project/pidna/)
|
|
6
|
+
[](https://github.com/gatewaytofredom/pidna/blob/main/LICENSE)
|
|
7
|
+
|
|
8
|
+
A fast drop-in replacement for `idna` in Python. Validates and converts internationalized domain names (IDNA 2008 and UTS #46) up to 418x faster on ASCII domains and 10–16x faster on Unicode domains.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pip install pidna
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Prebuilt wheels are included for Linux, macOS, and Windows (Python 3.9+, no Rust toolchain needed).
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
import pidna
|
|
22
|
+
|
|
23
|
+
encoded = pidna.encode("münchen.de") # b"xn--mnchen-3ya.de"
|
|
24
|
+
decoded = pidna.decode(b"xn--mnchen-3ya.de") # "münchen.de"
|
|
25
|
+
uts46 = pidna.encode("API.GitHub.COM", uts46=True) # b"api.github.com"
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Performance
|
|
29
|
+
|
|
30
|
+
| Workload | `idna` (x86-64) | `pidna` (x86-64 AVX2) | `pidna` (Apple M4 NEON) |
|
|
31
|
+
|---|---:|---:|---:|
|
|
32
|
+
| Small ASCII (`api.github.com`, 50k) | 408.97 ms | 6.02 ms (**68.0x**) | 5.78 ms (**47.0x** vs M4 `idna`) |
|
|
33
|
+
| Medium ASCII UTS #46 (`API.GitHub.COM`, 50k) | 466.38 ms | 9.54 ms (**48.9x**) | 8.81 ms (**31.3x** vs M4 `idna`) |
|
|
34
|
+
| Long ASCII (8 labels, 20k) | 1501.13 ms | 3.59 ms (**418.1x**) | 3.45 ms (**286.2x** vs M4 `idna`) |
|
|
35
|
+
| Unicode UTS #46 (`münchen.de`, 20k) | 243.33 ms | 24.59 ms (**9.9x**) | 18.94 ms (**7.0x** vs M4 `idna`) |
|
|
36
|
+
| CJK (`例え.jp`, 20k) | 179.37 ms | 10.93 ms (**16.4x**) | 7.28 ms (**15.1x** vs M4 `idna`) |
|
|
37
|
+
|
|
38
|
+
## Under the hood
|
|
39
|
+
|
|
40
|
+
- Written in Rust (PyO3) with zero external runtime dependencies and runtime SIMD dispatch (AVX2 / SSE2 / ARM64 NEON)
|
|
41
|
+
- Compact `cp39-abi3` wheel with PEP 561 type stubs (`py.typed` + `__init__.pyi`)
|
|
42
|
+
- Verified with Hypothesis differential fuzzing against `idna`
|
|
43
|
+
|
|
44
|
+
## License
|
|
45
|
+
|
|
46
|
+
MIT
|
pidna-0.1.0/SECURITY.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Reporting a Vulnerability
|
|
4
|
+
|
|
5
|
+
Please report security vulnerabilities privately using GitHub's **Private Vulnerability Reporting** feature on the **Security** tab of this repository (or email `gateway@laindex.net`).
|
|
6
|
+
|
|
7
|
+
Please include:
|
|
8
|
+
- A minimal reproducer (input bytes/string and affected version)
|
|
9
|
+
- Expected vs. observed behavior (e.g., crash, quadratic CPU / ReDoS, memory issue)
|
|
10
|
+
|
|
11
|
+
We aim to acknowledge reports within 48 hours and ship a verified fix promptly.
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import statistics
|
|
4
|
+
import time
|
|
5
|
+
|
|
6
|
+
import pidna
|
|
7
|
+
|
|
8
|
+
try:
|
|
9
|
+
import idna
|
|
10
|
+
except ImportError:
|
|
11
|
+
idna = None # type: ignore[assignment]
|
|
12
|
+
|
|
13
|
+
ASCII_SMALL = "api.github.com"
|
|
14
|
+
ASCII_MEDIUM = "us-east-1.elb.amazonaws.com"
|
|
15
|
+
ASCII_LONG = ".".join(["sub-domain-label-01"] * 8) + ".example.com"
|
|
16
|
+
UNICODE_SMALL = "münchen.de"
|
|
17
|
+
UNICODE_MIXED = "例え.jp"
|
|
18
|
+
PUNYCODE_MIXED = "xn--mnchen-3ya.de"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def bench_fn(fn: object, iterations: int) -> float:
|
|
22
|
+
assert callable(fn)
|
|
23
|
+
# Warmup
|
|
24
|
+
for _ in range(min(500, iterations // 10)):
|
|
25
|
+
fn()
|
|
26
|
+
times: list[float] = []
|
|
27
|
+
for _ in range(5):
|
|
28
|
+
t0 = time.perf_counter()
|
|
29
|
+
for _ in range(iterations):
|
|
30
|
+
fn()
|
|
31
|
+
t1 = time.perf_counter()
|
|
32
|
+
times.append(t1 - t0)
|
|
33
|
+
return statistics.median(times)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def main() -> None:
|
|
37
|
+
cases: list[tuple[str, int, object, object]] = [
|
|
38
|
+
(
|
|
39
|
+
"encode_ascii_small",
|
|
40
|
+
50_000,
|
|
41
|
+
lambda: pidna.encode(ASCII_SMALL),
|
|
42
|
+
(lambda: idna.encode(ASCII_SMALL)) if idna else None,
|
|
43
|
+
),
|
|
44
|
+
(
|
|
45
|
+
"encode_ascii_uts46",
|
|
46
|
+
50_000,
|
|
47
|
+
lambda: pidna.encode("API.GitHub.COM", uts46=True),
|
|
48
|
+
(lambda: idna.encode("API.GitHub.COM", uts46=True)) if idna else None,
|
|
49
|
+
),
|
|
50
|
+
(
|
|
51
|
+
"encode_ascii_long",
|
|
52
|
+
20_000,
|
|
53
|
+
lambda: pidna.encode(ASCII_LONG),
|
|
54
|
+
(lambda: idna.encode(ASCII_LONG)) if idna else None,
|
|
55
|
+
),
|
|
56
|
+
(
|
|
57
|
+
"encode_unicode_uts46",
|
|
58
|
+
20_000,
|
|
59
|
+
lambda: pidna.encode(UNICODE_SMALL, uts46=True),
|
|
60
|
+
(lambda: idna.encode(UNICODE_SMALL, uts46=True)) if idna else None,
|
|
61
|
+
),
|
|
62
|
+
(
|
|
63
|
+
"encode_cjk",
|
|
64
|
+
20_000,
|
|
65
|
+
lambda: pidna.encode(UNICODE_MIXED),
|
|
66
|
+
(lambda: idna.encode(UNICODE_MIXED)) if idna else None,
|
|
67
|
+
),
|
|
68
|
+
(
|
|
69
|
+
"decode_ascii_small",
|
|
70
|
+
50_000,
|
|
71
|
+
lambda: pidna.decode(ASCII_SMALL),
|
|
72
|
+
(lambda: idna.decode(ASCII_SMALL)) if idna else None,
|
|
73
|
+
),
|
|
74
|
+
(
|
|
75
|
+
"decode_punycode",
|
|
76
|
+
20_000,
|
|
77
|
+
lambda: pidna.decode(PUNYCODE_MIXED),
|
|
78
|
+
(lambda: idna.decode(PUNYCODE_MIXED)) if idna else None,
|
|
79
|
+
),
|
|
80
|
+
]
|
|
81
|
+
|
|
82
|
+
print(f"{'Benchmark':24s} {'pidna (ms)':>12s} {'idna (ms)':>12s} {'Speedup':>10s}")
|
|
83
|
+
print("-" * 62)
|
|
84
|
+
for name, iters, p_fn, i_fn in cases:
|
|
85
|
+
p_ms = bench_fn(p_fn, iters) * 1000.0
|
|
86
|
+
if i_fn is not None:
|
|
87
|
+
i_ms = bench_fn(i_fn, iters) * 1000.0
|
|
88
|
+
speedup = f"{i_ms / p_ms:.2f}x"
|
|
89
|
+
i_str = f"{i_ms:.3f}"
|
|
90
|
+
else:
|
|
91
|
+
i_str = "N/A"
|
|
92
|
+
speedup = "N/A"
|
|
93
|
+
print(f"{name:24s} {p_ms:12.3f} {i_str:>12s} {speedup:>10s}")
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
if __name__ == "__main__":
|
|
97
|
+
main()
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["maturin>=1.7,<2.0"]
|
|
3
|
+
build-backend = "maturin"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pidna"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Fast drop-in replacement for idna in Python"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
requires-python = ">=3.9"
|
|
12
|
+
keywords = [
|
|
13
|
+
"idna",
|
|
14
|
+
"uts46",
|
|
15
|
+
"punycode",
|
|
16
|
+
"dns",
|
|
17
|
+
"domain",
|
|
18
|
+
"unicode",
|
|
19
|
+
"rust",
|
|
20
|
+
]
|
|
21
|
+
classifiers = [
|
|
22
|
+
"Development Status :: 4 - Beta",
|
|
23
|
+
"Intended Audience :: Developers",
|
|
24
|
+
"License :: OSI Approved :: MIT License",
|
|
25
|
+
"Operating System :: OS Independent",
|
|
26
|
+
"Programming Language :: Python :: 3",
|
|
27
|
+
"Programming Language :: Python :: 3.9",
|
|
28
|
+
"Programming Language :: Python :: 3.10",
|
|
29
|
+
"Programming Language :: Python :: 3.11",
|
|
30
|
+
"Programming Language :: Python :: 3.12",
|
|
31
|
+
"Programming Language :: Python :: 3.13",
|
|
32
|
+
"Programming Language :: Python :: 3.14",
|
|
33
|
+
"Programming Language :: Rust",
|
|
34
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
35
|
+
"Typing :: Typed",
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
[project.urls]
|
|
39
|
+
Homepage = "https://github.com/gatewaytofredom/pidna"
|
|
40
|
+
Repository = "https://github.com/gatewaytofredom/pidna"
|
|
41
|
+
|
|
42
|
+
[tool.maturin]
|
|
43
|
+
python-source = "python"
|
|
44
|
+
module-name = "pidna._pidna"
|
|
45
|
+
features = ["pyo3/extension-module"]
|
|
46
|
+
|
|
47
|
+
[tool.ruff]
|
|
48
|
+
line-length = 120
|
|
49
|
+
target-version = "py39"
|
|
50
|
+
|
|
51
|
+
[tool.ruff.lint]
|
|
52
|
+
select = ["E", "F", "I", "UP", "B", "SIM"]
|
|
53
|
+
|
|
54
|
+
[tool.mypy]
|
|
55
|
+
python_version = "3.10"
|
|
56
|
+
strict = true
|
|
57
|
+
warn_unused_ignores = true
|
|
58
|
+
|
|
59
|
+
[tool.pytest.ini_options]
|
|
60
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pidna.core import (
|
|
4
|
+
IDNABidiError,
|
|
5
|
+
IDNAError,
|
|
6
|
+
InvalidCodepoint,
|
|
7
|
+
InvalidCodepointContext,
|
|
8
|
+
alabel,
|
|
9
|
+
check_bidi,
|
|
10
|
+
check_hyphen_ok,
|
|
11
|
+
check_initial_combiner,
|
|
12
|
+
check_label,
|
|
13
|
+
check_nfc,
|
|
14
|
+
decode,
|
|
15
|
+
encode,
|
|
16
|
+
ulabel,
|
|
17
|
+
uts46_remap,
|
|
18
|
+
valid_contextj,
|
|
19
|
+
valid_contexto,
|
|
20
|
+
valid_label_length,
|
|
21
|
+
valid_string_length,
|
|
22
|
+
)
|
|
23
|
+
from pidna.intranges import intranges_contain
|
|
24
|
+
from pidna.package_data import __version__
|
|
25
|
+
|
|
26
|
+
unicode_version = "16.0.0"
|
|
27
|
+
|
|
28
|
+
__all__ = [
|
|
29
|
+
"__version__",
|
|
30
|
+
"unicode_version",
|
|
31
|
+
"IDNABidiError",
|
|
32
|
+
"IDNAError",
|
|
33
|
+
"InvalidCodepoint",
|
|
34
|
+
"InvalidCodepointContext",
|
|
35
|
+
"alabel",
|
|
36
|
+
"check_bidi",
|
|
37
|
+
"check_hyphen_ok",
|
|
38
|
+
"check_initial_combiner",
|
|
39
|
+
"check_label",
|
|
40
|
+
"check_nfc",
|
|
41
|
+
"decode",
|
|
42
|
+
"encode",
|
|
43
|
+
"intranges_contain",
|
|
44
|
+
"ulabel",
|
|
45
|
+
"uts46_remap",
|
|
46
|
+
"valid_contextj",
|
|
47
|
+
"valid_contexto",
|
|
48
|
+
"valid_label_length",
|
|
49
|
+
"valid_string_length",
|
|
50
|
+
]
|