Skip to main content

os-netloc-rule

Build Status codecov PyPI - Python Version PyPI

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 cmp function when loading rules

    def 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)

Source distribution for os-netloc-rule 0.0.2
File Size Uploaded
os-netloc-rule-0.0.2.tar.gz 6.6 kB Details

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

Release history Release notifications | RSS feed

0.3

1 release file

0.2

1 release file

0.1

1 release file

This release

0.0.2 This release

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page