Skip to content

Commit

Permalink
Add url.set_psl to allow users to set custom PSLs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Lecocq committed Aug 26, 2016
1 parent 568c6dc commit 4d36209
Show file tree
Hide file tree
Showing 5 changed files with 790 additions and 673 deletions.
23 changes: 22 additions & 1 deletion test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import url
import pkgutil
import unittest

from nose.tools import assert_equal, assert_not_equal, assert_raises

import url


def test_bad_port():
def test(example):
Expand Down Expand Up @@ -642,3 +644,22 @@ def test(example):
]
for example in examples:
yield test, example

def test_set_psl():
'''Can set the PSL to use.'''

def test(rules, example, pld, tld):
try:
url.set_psl(rules)
assert_equal(url.parse(example).pld, pld)
assert_equal(url.parse(example).tld, tld)
finally:
url.set_psl(pkgutil.get_data('url', 'psl/2016-08-16.psl'))

examples = [
('uk', 'http://foo.co.uk/', 'co.uk', 'uk' ),
('co.uk', 'http://foo.co.uk/', 'foo.co.uk', 'co.uk')
]

for rules, example, pld, tld in examples:
yield test, rules, example, pld, tld
2 changes: 1 addition & 1 deletion url/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
'''This is a module for dealing with urls. In particular, sanitizing them.'''


from .url import URL
from .url import URL, set_psl

def parse(url, encoding='utf-8'):
'''Parse the provided url string and return an URL object'''
Expand Down
Loading

0 comments on commit 4d36209

Please sign in to comment.