publicsuffixlist implement
Project description
publicsuffixlist
Public Suffix List parser implementation for Python 2.5+/3.x.
Support IDN (unicode or punycoded).
Compliant with TEST DATA
Support Python2.5+ and Python 3.x
Install
publicsuffixlist can be installed via pip or pip3.
$ sudo pip install publicsuffixlist
Usage
from publicsuffixlist import PublicSuffixList
psl = PublicSuffixList()
# uses built-in PSL file
psl.publicsuffix("www.example.com") # "com"
# longest public suffix part
psl.privatesuffix("www.example.com") # "example.com"
# shortest domain assigned for a registrant
psl.privatesuffix("com") # None
# None if no private (non-public) part found
psl.publicsuffix("www.example.unknownnewtld") # "unkownnewtld"
# new TLDs are valid public suffix by default
psl.publicsuffix(u"www.example.香港") # u"香港"
# accept unicode
psl.publicsuffix("www.example.xn--j6w193g") # "xn--j6w193g"
# accept punycoded IDNs by default
Latest PSL can be passed as a file like line-iterable object.
with open("latest_psl.dat", "rb") as f:
psl = PublicSuffixList(f)
Works with both Python 2.x and 3.x.
$ python -m publicsuffixlist.test ............... ---------------------------------------------------------------------- Ran 15 tests in 2.898s OK $ python3 -m publicsuffixlist.test ............... ---------------------------------------------------------------------- Ran 15 tests in 2.562s OK
Drop-in compat code to replace publicsuffix
# from publicsuffix import PublicSuffixList
from publicsuffixlist.compat import PublicSuffixList
psl = PublicSuffixList()
psl.suffix("www.example.com") # return "example.com"
psl.suffix("com") # return ""
License
This module is licensed under Mozilla Public License 2.0.
Public Suffix List maintained by Mozilla Foundation is licensed under Mozilla Public License 2.0.
PSL testcase dataset is public domain (CC0).
Source / Link
Git repository on GitHub (https://github.com/ko-zu/psl)
PyPI (https://pypi.python.org/pypi?name=publicsuffixlist&:action=display)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for publicsuffixlist-0.2.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94868c7653d5124cfcea1e48976a52a332384e098b0b986efde1c5dd9a915efe |
|
MD5 | 8970837445b329e4382214ba71d4eeb3 |
|
BLAKE2b-256 | 9606862d7af8b2a2053b58bbcbdecb0d95ec76c34e2738ef04b193a32cad25d5 |