mirror of https://github.com/scrapy/scrapy.git
Add basic top-level shortcuts
This commit is contained in:
parent
9a643d689c
commit
62c7daf785
|
|
@ -2,7 +2,8 @@
|
|||
Scrapy - a screen scraping framework written in Python
|
||||
"""
|
||||
|
||||
__all__ = ['__version__', 'version_info', 'optional_features', 'twisted_version']
|
||||
__all__ = ['__version__', 'version_info', 'optional_features', 'twisted_version',
|
||||
'Spider', 'Request', 'FormRequest', 'Selector', 'Item', 'Field']
|
||||
|
||||
# Scrapy version
|
||||
import pkgutil
|
||||
|
|
@ -49,3 +50,9 @@ from twisted import version as _txv
|
|||
twisted_version = (_txv.major, _txv.minor, _txv.micro)
|
||||
if twisted_version >= (11, 1, 0):
|
||||
optional_features.add('http11')
|
||||
|
||||
# Declare top-level shortcuts
|
||||
from scrapy.spider import Spider
|
||||
from scrapy.http import Request, FormRequest
|
||||
from scrapy.selector import Selector
|
||||
from scrapy.item import Item, Field
|
||||
|
|
|
|||
|
|
@ -14,3 +14,21 @@ class ToplevelTestCase(TestCase):
|
|||
def test_optional_features(self):
|
||||
self.assertIs(type(scrapy.optional_features), set)
|
||||
self.assertIn('ssl', scrapy.optional_features)
|
||||
|
||||
def test_request_shortcut(self):
|
||||
from scrapy.http import Request, FormRequest
|
||||
self.assertIs(scrapy.Request, Request)
|
||||
self.assertIs(scrapy.FormRequest, FormRequest)
|
||||
|
||||
def test_spider_shortcut(self):
|
||||
from scrapy.spider import Spider
|
||||
self.assertIs(scrapy.Spider, Spider)
|
||||
|
||||
def test_selector_shortcut(self):
|
||||
from scrapy.selector import Selector
|
||||
self.assertIs(scrapy.Selector, Selector)
|
||||
|
||||
def test_item_shortcut(self):
|
||||
from scrapy.item import Item, Field
|
||||
self.assertIs(scrapy.Item, Item)
|
||||
self.assertIs(scrapy.Field, Field)
|
||||
|
|
|
|||
Loading…
Reference in New Issue