1
0
mirror of https://github.com/scrapy/scrapy.git synced 2025-02-26 23:23:48 +00:00

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.
This commit is contained in:
Rolando Espinoza La fuente 2013-10-27 19:10:25 -04:00
parent 343f997ed6
commit 10e22aa5fb
4 changed files with 9 additions and 4 deletions

View File

@ -6,6 +6,7 @@ See documentation in docs/topics/extensions.rst
import socket import socket
from pprint import pformat from pprint import pformat
from importlib import import_module
from twisted.internet import task from twisted.internet import task
@ -20,7 +21,8 @@ class MemoryUsage(object):
if not crawler.settings.getbool('MEMUSAGE_ENABLED'): if not crawler.settings.getbool('MEMUSAGE_ENABLED'):
raise NotConfigured raise NotConfigured
try: try:
self.resource = __import__('resource') # stdlib's resource module is only availabe on unix platforms.
self.resource = import_module('resource')
except ImportError: except ImportError:
raise NotConfigured raise NotConfigured

View File

@ -15,6 +15,7 @@ Scrapy developers, if you add a setting here remember to:
import os import os
import sys import sys
from importlib import import_module
from os.path import join, abspath, dirname from os.path import join, abspath, dirname
BOT_NAME = 'scrapybot' BOT_NAME = 'scrapybot'
@ -229,7 +230,7 @@ TEMPLATES_DIR = abspath(join(dirname(__file__), '..', 'templates'))
URLLENGTH_LIMIT = 2083 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_ENABLED = 1
TELNETCONSOLE_PORT = [6023, 6073] TELNETCONSOLE_PORT = [6023, 6073]

View File

@ -1,9 +1,10 @@
from importlib import import_module
from twisted.trial import unittest from twisted.trial import unittest
class ScrapyUtilsTest(unittest.TestCase): class ScrapyUtilsTest(unittest.TestCase):
def test_required_openssl_version(self): def test_required_openssl_version(self):
try: try:
module = __import__('OpenSSL') module = import_module('OpenSSL')
except ImportError as ex: except ImportError as ex:
raise unittest.SkipTest("OpenSSL is not available") raise unittest.SkipTest("OpenSSL is not available")

View File

@ -4,6 +4,7 @@ This module contains some assorted functions used in tests
import os import os
from importlib import import_module
from twisted.trial.unittest import SkipTest from twisted.trial.unittest import SkipTest
@ -39,7 +40,7 @@ def get_crawler(settings_dict=None):
def get_pythonpath(): def get_pythonpath():
"""Return a PYTHONPATH suitable to use in processes so that they find this """Return a PYTHONPATH suitable to use in processes so that they find this
installation of Scrapy""" 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', '') return os.path.dirname(scrapy_path) + os.pathsep + os.environ.get('PYTHONPATH', '')
def get_testenv(): def get_testenv():