Scrapy, a fast high-level web crawling & scraping framework for Python.
Added test to make sure custom mime.types shipped with Scrapy is loaded, and made Scrapy more egg-friendly by using pkutil.get_data()
Pablo Hoffmanfff22c269a92
diff --git a/scrapy/core/downloader/responsetypes/__init__.py b/scrapy/core/downloader/responsetypes/__init__.pyindex 8b5c14258..99ee291b6 100644--- a/scrapy/core/downloader/responsetypes/__init__.py+++ b/scrapy/core/downloader/responsetypes/__init__.py@@ -6,12 +6,16 @@ based on different criterias.from os.path import abspath, dirname, joinfrom mimetypes import MimeTypes+from cStringIO import StringIOfrom scrapy.http import Responsefrom scrapy.utils.misc import load_objectfrom scrapy.utils.python import isbinarytext+from scrapy.utils.py26 import get_datafrom 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)diff --git a/scrapy/core/downloader/responsetypes/mime.types b/scrapy/core/downloader/responsetypes/mime.typesindex 36c2b8875..14d982595 100644--- a/scrapy/core/downloader/responsetypes/mime.types+++ b/scrapy/core/downloader/responsetypes/mime.types@@ -746,3 +746,5 @@ x-conference/x-cooltalk icex-epoc/x-sisx-app sisxx-world/x-vrml vrm vrml wrl++x-scrapy/test scrapytestdiff --git a/scrapy/tests/test_responsetypes.py b/scrapy/tests/test_responsetypes.pyindex 8e4e1643a..ae74c514a 100644--- a/scrapy/tests/test_responsetypes.py+++ b/scrapy/tests/test_responsetypes.py@@ -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()