os-netloc-rule
A common library for netloc rule use case.
Netloc match is a very common and useful operation on processing URL. For example, netloc blacklist is a series rules of netloc with ALLOWED or DISALLOWED:
abc.example.com ALLOWED
.example.com DISALLOWED
You can skip processing http://www.example.com/001.html becase it match the rule .example.com DISALLOWED.
Install
pip install os-netloc-rule
Usage
-
load rule
from os_netloc_rule import Matcher rules = [ ('www.example.com', 1), ('abc.example.com', 2), ('abc.example.com:8080', 3), ] matcher = Matcher() for netloc, rule in rules: matcher.load(netloc, rule) -
match rule
matcher.match('www.example.com') matcher.match('abc.example.com:8080') -
if there are same netloc with different rule, the latter covers the former by default. But you can custom your own
cmpfunction when loading rulesdef cmp(former, latter): return former if former > latter else latter matcher.load(netloc, rule, cmp=cmp) -
dump rules
for netloc, rule in matcher.dump(): pass -
delete rule
delete, rule = matcher.delete('www.example.com')
Benchmark
Some benchmarks:
| python version | operation | memory | speed |
|---|---|---|---|
| 2.7.14 | load | 100w, 380M | 91k/s |
| 2.7.14 | match | - | 118k/s |
| 3.6.4 | load | 100w, 300M | 96k/s |
| 3.6.4 | match | - | 123k/s |
| pypy-5.7.1 | load | 100w, 251M | 283k/s |
| pypy-5.7.1 | match | - | 529k/s |
| pypy3.6-7.2.0 | load | 100w, 305M | 265k/s |
| pypy3.6-7.2.0 | match | - | 473k/s |
Unit Tests
tox
License
MIT licensed.
Metadata
Release files for os-netloc-rule 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| os-netloc-rule-0.0.2.tar.gz | 6.6 kB | Without provenance | Details for os-netloc-rule-0.0.2.tar.gz |
Release files / os-netloc-rule-0.0.2.tar.gz
| Download URL | os-netloc-rule-0.0.2.tar.gz |
|---|---|
| Size | 6.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
24bb35f51375fba6b4d93f98d2e1e42a4e6847eaf02a7a1de9228cdcee0888c3
|
|
BLAKE2b-256 checksum How to use checksums |
2a8a30dca03a8e2e24a5a0170cf5e16890adc928cf067f3c14e386b5e9457237
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/2.7.15
|
Security for os-netloc-rule 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.