From 10e22aa5fba928f4092b4aec597f4539566dca59 Mon Sep 17 00:00:00 2001 From: Rolando Espinoza La fuente Date: Sun, 27 Oct 2013 19:10:25 -0400 Subject: [PATCH] Replaced remaning __import__(module) calls. This commit replaces the statements __import__(module) as the previous replaced the statements __import__(module, {}, {}, ['']). At first I thought leaving the single-argument calls, but perhaps it's better to be strict rather than having exceptions to the rule in this case. --- scrapy/contrib/memusage.py | 4 +++- scrapy/settings/default_settings.py | 3 ++- scrapy/tests/test_dependencies.py | 3 ++- scrapy/utils/test.py | 3 ++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/scrapy/contrib/memusage.py b/scrapy/contrib/memusage.py index 4d4aae1c9..98dd15027 100644 --- a/scrapy/contrib/memusage.py +++ b/scrapy/contrib/memusage.py @@ -6,6 +6,7 @@ See documentation in docs/topics/extensions.rst import socket from pprint import pformat +from importlib import import_module from twisted.internet import task @@ -20,7 +21,8 @@ class MemoryUsage(object): if not crawler.settings.getbool('MEMUSAGE_ENABLED'): raise NotConfigured try: - self.resource = __import__('resource') + # stdlib's resource module is only availabe on unix platforms. + self.resource = import_module('resource') except ImportError: raise NotConfigured diff --git a/scrapy/settings/default_settings.py b/scrapy/settings/default_settings.py index e7475c3d5..91b8d8b48 100644 --- a/scrapy/settings/default_settings.py +++ b/scrapy/settings/default_settings.py @@ -15,6 +15,7 @@ Scrapy developers, if you add a setting here remember to: import os import sys +from importlib import import_module from os.path import join, abspath, dirname BOT_NAME = 'scrapybot' @@ -229,7 +230,7 @@ TEMPLATES_DIR = abspath(join(dirname(__file__), '..', 'templates')) URLLENGTH_LIMIT = 2083 -USER_AGENT = 'Scrapy/%s (+http://scrapy.org)' % __import__('scrapy').__version__ +USER_AGENT = 'Scrapy/%s (+http://scrapy.org)' % import_module('scrapy').__version__ TELNETCONSOLE_ENABLED = 1 TELNETCONSOLE_PORT = [6023, 6073] diff --git a/scrapy/tests/test_dependencies.py b/scrapy/tests/test_dependencies.py index 51b9c3af3..03bf2ffcf 100644 --- a/scrapy/tests/test_dependencies.py +++ b/scrapy/tests/test_dependencies.py @@ -1,9 +1,10 @@ +from importlib import import_module from twisted.trial import unittest class ScrapyUtilsTest(unittest.TestCase): def test_required_openssl_version(self): try: - module = __import__('OpenSSL') + module = import_module('OpenSSL') except ImportError as ex: raise unittest.SkipTest("OpenSSL is not available") diff --git a/scrapy/utils/test.py b/scrapy/utils/test.py index c2d473e6f..ec9ca1c51 100644 --- a/scrapy/utils/test.py +++ b/scrapy/utils/test.py @@ -4,6 +4,7 @@ This module contains some assorted functions used in tests import os +from importlib import import_module from twisted.trial.unittest import SkipTest @@ -39,7 +40,7 @@ def get_crawler(settings_dict=None): def get_pythonpath(): """Return a PYTHONPATH suitable to use in processes so that they find this installation of Scrapy""" - scrapy_path = __import__('scrapy').__path__[0] + scrapy_path = import_module('scrapy').__path__[0] return os.path.dirname(scrapy_path) + os.pathsep + os.environ.get('PYTHONPATH', '') def get_testenv():