Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update README, and make default initialiser use data file in module

  • Loading branch information...
commit a34004bbd907c6a6068dca767ddaf2344bedd13d 1 parent 602b245
@rboulton authored
Showing with 21 additions and 15 deletions.
  1. +13 −12 README.rst
  2. +6 −1 fastpublicsuffix/publicsuffix.py
  3. +2 −2 test.py
View
25 README.rst
@@ -1,31 +1,32 @@
-============
+================
fastpublicsuffix
-============
+================
This module provides a Python interface to the `Public Suffix List`_.
-The Public Suffix List (PSL) is a set of rules describing
-"effective top-level domains" and can be used to determine the registered
-domain for a given host name.
+The Public Suffix List (PSL) is a set of rules describing "effective top-level
+domains" and can be used to determine the registered domain for a given host
+name.
-This branch is maintained by `MixRank`_, we reimplemented it using a different data structure (a prefix tree)
-in order to improve performance.
+This module is maintained by Richard Boulton, based on a fork of a module from
+`MixRank`.
Usage
-----
-You will need to download the `list`_ yourself.
+You can download the `list` yourself, or use the version distributed along with
+the module.
-Call the ``init_suffix_tree`` function with the location of the list. Then call
+Call the ``init_suffix_tree`` function. Then call
`get_root_domain` to find the registered domain. This branch does not support asking
for the (E)TLD.
Find the registered domain::
- >>> publicsuffix.init_suffix_tree('names.dat')
- >>> publicsuffix.domain('www.python.org')
+ >>> fastpublicsuffix.init_suffix_tree()
+ >>> fastpublicsuffix.domain('www.python.org')
u'python.org'
.. _`Public Suffix List`: http://publicsuffix.org/
.. _`list`: http://mxr.mozilla.org/mozilla-central/source/netwerk/dns/effective_tld_names.dat?raw=1
-.. _`MixRank`: http://mixrank.com
+.. _`MixRank`: http://mixrank.com
View
7 fastpublicsuffix/publicsuffix.py
@@ -16,6 +16,9 @@
# limitations under the License.
+import os.path
+
+
EFFECTIVE_TLD_NAMES = 'http://mxr.mozilla.org/mozilla-central/source/netwerk/dns/effective_tld_names.dat?raw=1'
@@ -163,8 +166,10 @@ def _is_ip(address):
suffixtree = None
-def init_suffix_tree(tld_file):
+def init_suffix_tree(tld_file=None):
"""Call this first to initialize the suffix tree"""
+ if tld_file is None:
+ tld_file = os.path.join(os.path.dirname(__file__), 'public_suffix_list.txt')
fp = open(tld_file)
suffix_lines = fp.readlines()
suffix_rules = _tokenize(suffix_lines)
View
4 test.py
@@ -1,4 +1,4 @@
-from publicsuffix import init_suffix_tree, get_root_domain
+from fastpublicsuffix import init_suffix_tree, get_root_domain
def test(domain, expected):
result = get_root_domain(domain)
@@ -9,7 +9,7 @@ def test(domain, expected):
if __name__ == "__main__":
- init_suffix_tree('names.dat')
+ init_suffix_tree()
# The first set of tests here are derived from
# http://publicsuffix.org/list/test.txt
Please sign in to comment.
Something went wrong with that request. Please try again.