mirror of https://github.com/scrapy/scrapy.git
Added test to make sure custom mime.types shipped with Scrapy is loaded, and made Scrapy more egg-friendly by using pkutil.get_data()
This commit is contained in:
parent
87aa63da2b
commit
fff22c269a
|
|
@ -6,12 +6,16 @@ based on different criterias.
|
|||
|
||||
from os.path import abspath, dirname, join
|
||||
from mimetypes import MimeTypes
|
||||
from cStringIO import StringIO
|
||||
|
||||
from scrapy.http import Response
|
||||
from scrapy.utils.misc import load_object
|
||||
from scrapy.utils.python import isbinarytext
|
||||
from scrapy.utils.py26 import get_data
|
||||
from scrapy.conf import settings
|
||||
|
||||
__package__ = 'scrapy.core.downloader.responsetypes' # required for python 2.5
|
||||
|
||||
class ResponseTypes(object):
|
||||
|
||||
CLASSES = {
|
||||
|
|
@ -31,8 +35,9 @@ class ResponseTypes(object):
|
|||
def __init__(self):
|
||||
self.CLASSES.update(settings.get('RESPONSE_CLASSES', {}))
|
||||
self.classes = {}
|
||||
mimefile = join(abspath(dirname(__file__)), 'mime.types')
|
||||
self.mimetypes = MimeTypes([mimefile])
|
||||
self.mimetypes = MimeTypes()
|
||||
mimedata = get_data(__package__, 'mime.types')
|
||||
self.mimetypes.readfp(StringIO(mimedata))
|
||||
for mimetype, cls in self.CLASSES.iteritems():
|
||||
self.classes[mimetype] = load_object(cls)
|
||||
|
||||
|
|
|
|||
|
|
@ -746,3 +746,5 @@ x-conference/x-cooltalk ice
|
|||
|
||||
x-epoc/x-sisx-app sisx
|
||||
x-world/x-vrml vrm vrml wrl
|
||||
|
||||
x-scrapy/test scrapytest
|
||||
|
|
|
|||
|
|
@ -75,5 +75,9 @@ class ResponseTypesTest(unittest.TestCase):
|
|||
retcls = responsetypes.from_args(**source)
|
||||
assert retcls is cls, "%s ==> %s != %s" % (source, retcls, cls)
|
||||
|
||||
def test_custom_mime_types_loaded(self):
|
||||
# check that mime.types files shipped with scrapy are loaded
|
||||
self.assertEqual(responsetypes.mimetypes.guess_type('x.scrapytest')[0], 'x-scrapy/test')
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Reference in New Issue