-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from scrapinghub/load-tldextract-lazily
Import tldextract lazily
- Loading branch information
Showing
10 changed files
with
116 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import unittest | ||
from frontera.contrib.middlewares.domain import DomainMiddleware | ||
from frontera.core.manager import FrontierManager | ||
from frontera.core.models import Request | ||
|
||
|
||
class FakeManager(object): | ||
settings = {} | ||
test_mode = False | ||
|
||
|
||
class DomainMiddlewareTest(unittest.TestCase): | ||
def setUp(self): | ||
self.fake_manager = FakeManager() | ||
|
||
def test_create(self): | ||
DomainMiddleware(self.fake_manager) | ||
|
||
def test_should_parse_domain_info(self): | ||
seeds = [ | ||
Request('http://example.com'), | ||
Request('https://www.google.com'), | ||
] | ||
|
||
mware = DomainMiddleware(self.fake_manager) | ||
result = mware.add_seeds(seeds) | ||
|
||
self.assertEquals(len(result), len(seeds)) | ||
|
||
for r in result: | ||
self.assertIn('domain', r.meta, 'Missing domain info for %r' % r) | ||
|
||
expected = [ | ||
{'name': 'example.com', 'netloc': 'example.com', 'scheme': 'http', | ||
'sld': '', 'subdomain': '', 'tld': ''}, | ||
{'name': 'www.google.com', 'netloc': 'www.google.com', 'scheme': 'https', | ||
'sld': '', 'subdomain': '', 'tld': ''}, | ||
] | ||
self.assertEquals(expected, [r.meta['domain'] for r in result]) | ||
|
||
def test_should_parse_tldextract_extra_domain_info(self): | ||
seeds = [ | ||
Request('http://example.com'), | ||
Request('https://www.google.com'), | ||
] | ||
|
||
self.fake_manager.settings = {'TLDEXTRACT_DOMAIN_INFO': True} | ||
|
||
mware = DomainMiddleware(self.fake_manager) | ||
result = mware.add_seeds(seeds) | ||
|
||
self.assertEquals(len(result), len(seeds)) | ||
|
||
for r in result: | ||
self.assertIn('domain', r.meta, 'Missing domain info for %r' % r) | ||
|
||
expected = [ | ||
{'name': 'example.com', 'netloc': 'example.com', 'scheme': 'http', | ||
'sld': 'example', 'subdomain': '', 'tld': 'com'}, | ||
{'name': 'google.com', 'netloc': 'www.google.com', 'scheme': 'https', | ||
'sld': 'google', 'subdomain': 'www', 'tld': 'com'}, | ||
] | ||
self.assertEquals(expected, [r.meta['domain'] for r in result]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
six>=1.8.0 | ||
w3lib>=1.10.0 | ||
tldextract>=1.5.1 | ||
SQLAlchemy>=0.9.8 | ||
SQLAlchemy>=0.9.8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ MySQL-python>=1.2.5 | |
PyMySQL>=0.6.3 | ||
psycopg2>=2.5.4 | ||
scrapy>=0.24 | ||
-r tldextract.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
tldextract>=1.5.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters