Scrapy, a fast high-level web crawling & scraping framework for Python.
Merge branch 'master' into add-black-formatter
Emmanuel Rondan12b556a3526a
diff --cc scrapy/pipelines/images.pyindex b8724a1cd,d92f24d56..cfe25f903--- a/scrapy/pipelines/images.py+++ b/scrapy/pipelines/images.py@@@ -174,24 -167,21 +174,24 @@@ class ImagesPipeline(FilesPipeline)def convert_image(self, image, size=None, response_body=None):if response_body is None:- warnings.warn(f'{self.__class__.__name__}.convert_image() method called in a deprecated way, '- 'method called without response_body argument.',- category=ScrapyDeprecationWarning, stacklevel=2)+ warnings.warn(+ f"{self.__class__.__name__}.convert_image() method called in a deprecated way, "+ "method called without response_body argument.",+ category=ScrapyDeprecationWarning,+ stacklevel=2,+ )- if image.format == "PNG" and image.mode == "RGBA":- background = self._Image.new("RGBA", image.size, (255, 255, 255))+ if image.format in ('PNG', 'WEBP') and image.mode == 'RGBA':+ background = self._Image.new('RGBA', image.size, (255, 255, 255))background.paste(image, image)- image = background.convert('RGB')- elif image.mode == 'P':+ image = background.convert("RGB")+ elif image.mode == "P":image = image.convert("RGBA")- background = self._Image.new('RGBA', image.size, (255, 255, 255))+ background = self._Image.new("RGBA", image.size, (255, 255, 255))background.paste(image, image)- image = background.convert('RGB')- elif image.mode != 'RGB':- image = image.convert('RGB')+ image = background.convert("RGB")+ elif image.mode != "RGB":+ image = image.convert("RGB")if size:image = image.copy()diff --cc scrapy/shell.pyindex 18be383c1,515b71bb6..8e79908ab--- a/scrapy/shell.py+++ b/scrapy/shell.py@@@ -71,12 -72,15 +72,16 @@@ class Shellelse: # try all by defaultshells += DEFAULT_PYTHON_SHELLS.keys()# always add standard shell as fallback- shells += ['python']- start_python_console(self.vars, shells=shells,- banner=self.vars.pop('banner', ''))+ shells += ["python"]+ start_python_console(+ self.vars, shells=shells, banner=self.vars.pop("banner", "")+ )def _schedule(self, request, spider):+ if is_asyncio_reactor_installed():+ # set the asyncio event loop for the current thread+ event_loop_path = self.crawler.settings['ASYNCIO_EVENT_LOOP']+ set_asyncio_event_loop(event_loop_path)spider = self._open_spider(request, spider)d = _request_deferred(request)d.addCallback(lambda x: (x, spider))diff --cc scrapy/utils/log.pyindex fea4deb4b,c8b4936ac..2560a421f--- a/scrapy/utils/log.py+++ b/scrapy/utils/log.py@@@ -43,19 -43,22 +43,22 @@@ class TopLevelFormatter(logging.Filter)DEFAULT_LOGGING = {- 'version': 1,- 'disable_existing_loggers': False,- 'loggers': {- 'filelock': {- 'level': 'ERROR',+ "version": 1,+ "disable_existing_loggers": False,+ "loggers": {++ "filelock": {++ "level": "ERROR",+ },- 'hpack': {- 'level': 'ERROR',+ "hpack": {+ "level": "ERROR",},- 'scrapy': {- 'level': 'DEBUG',+ "scrapy": {+ "level": "DEBUG",},- 'twisted': {- 'level': 'ERROR',+ "twisted": {+ "level": "ERROR",},- }+ },}diff --cc setup.pyindex 27581f81d,27445cad0..9ce93d964--- a/setup.py+++ b/setup.py@@@ -51,45 -49,48 +51,46 @@@ elsesetup(- name='Scrapy',+ name="Scrapy",version=version,- url='https://scrapy.org',+ url="https://scrapy.org",project_urls={- 'Documentation': 'https://docs.scrapy.org/',- 'Source': 'https://github.com/scrapy/scrapy',- 'Tracker': 'https://github.com/scrapy/scrapy/issues',+ "Documentation": "https://docs.scrapy.org/",+ "Source": "https://github.com/scrapy/scrapy",+ "Tracker": "https://github.com/scrapy/scrapy/issues",},- description="A high-level Web Crawling and Web Scraping framework",- long_description=open("README.rst", encoding="utf-8").read(),- author="Scrapy developers",- maintainer="Pablo Hoffman",- maintainer_email="[email protected]",- license="BSD",- packages=find_packages(exclude=("tests", "tests.*")),+ description='A high-level Web Crawling and Web Scraping framework',+ long_description=open('README.rst', encoding="utf-8").read(),+ author='Scrapy developers',+ author_email='[email protected]',+ maintainer='Pablo Hoffman',+ maintainer_email='[email protected]',+ license='BSD',+ packages=find_packages(exclude=('tests', 'tests.*')),include_package_data=True,zip_safe=False,- entry_points={- 'console_scripts': ['scrapy = scrapy.cmdline:execute']- },+ entry_points={"console_scripts": ["scrapy = scrapy.cmdline:execute"]},classifiers=[- 'Framework :: Scrapy',- 'Development Status :: 5 - Production/Stable',- 'Environment :: Console',- 'Intended Audience :: Developers',- 'License :: OSI Approved :: BSD License',- 'Operating System :: OS Independent',- 'Programming Language :: Python',- 'Programming Language :: Python :: 3',- 'Programming Language :: Python :: 3.7',- 'Programming Language :: Python :: 3.8',- 'Programming Language :: Python :: 3.9',- 'Programming Language :: Python :: 3.10',- 'Programming Language :: Python :: 3.11',- 'Programming Language :: Python :: Implementation :: CPython',- 'Programming Language :: Python :: Implementation :: PyPy',- 'Topic :: Internet :: WWW/HTTP',- 'Topic :: Software Development :: Libraries :: Application Frameworks',- 'Topic :: Software Development :: Libraries :: Python Modules',+ "Framework :: Scrapy",+ "Development Status :: 5 - Production/Stable",+ "Environment :: Console",+ "Intended Audience :: Developers",+ "License :: OSI Approved :: BSD License",+ "Operating System :: OS Independent",+ "Programming Language :: Python",+ "Programming Language :: Python :: 3",+ "Programming Language :: Python :: 3.7",+ "Programming Language :: Python :: 3.8",+ "Programming Language :: Python :: 3.9",+ "Programming Language :: Python :: 3.10",+ "Programming Language :: Python :: 3.11",+ "Programming Language :: Python :: Implementation :: CPython",+ "Programming Language :: Python :: Implementation :: PyPy",+ "Topic :: Internet :: WWW/HTTP",+ "Topic :: Software Development :: Libraries :: Application Frameworks",+ "Topic :: Software Development :: Libraries :: Python Modules",],- python_requires='>=3.7',+ python_requires=">=3.7",install_requires=install_requires,extras_require=extras_require,)diff --cc tests/test_command_shell.pyindex 4c4242a1b,f06a02f5f..aa5128bee--- a/tests/test_command_shell.py+++ b/tests/test_command_shell.py@@@ -122,7 -111,18 +122,18 @@@ class ShellTest(ProcessTest, SiteTest,def test_dns_failures(self):if NON_EXISTING_RESOLVABLE:raise unittest.SkipTest("Non-existing hosts are resolvable")- url = 'www.somedomainthatdoesntexi.st'- errcode, out, err = yield self.execute([url, '-c', 'item'], check_code=False)+ url = "www.somedomainthatdoesntexi.st"+ errcode, out, err = yield self.execute([url, "-c", "item"], check_code=False)self.assertEqual(errcode, 1, out or err)- self.assertIn(b"DNS lookup failed", err)+ self.assertIn(b'DNS lookup failed', err)++ @defer.inlineCallbacks+ def test_shell_fetch_async(self):+ reactor_path = "twisted.internet.asyncioreactor.AsyncioSelectorReactor"+ url = self.url('/html')+ code = f"fetch('{url}')"+ args = ["-c", code, "--set", f"TWISTED_REACTOR={reactor_path}"]+ _, _, err = yield self.execute(args, check_code=True)+ self.assertNotIn(+ b"RuntimeError: There is no current event loop in thread", err+ )diff --cc tests/test_http_response.pyindex c52fcce09,74e170ec0..6e4971400--- a/tests/test_http_response.py+++ b/tests/test_http_response.py@@@ -209,18 -182,28 +206,28 @@@ class BaseResponseTest(unittest.TestCasr = self.response_class("http://example.com")self.assertRaises(ValueError, r.follow, None)+ @mark.xfail(+ parse_version(w3lib_version) < parse_version("2.1.1"),+ reason="https://github.com/scrapy/w3lib/pull/207",+ strict=True,+ )def test_follow_whitespace_url(self):- self._assert_followed_url("foo ", "http://example.com/foo%20")-+ self._assert_followed_url('foo ',+ 'http://example.com/foo')++ @mark.xfail(+ parse_version(w3lib_version) < parse_version("2.1.1"),+ reason="https://github.com/scrapy/w3lib/pull/207",+ strict=True,+ )def test_follow_whitespace_link(self):- self._assert_followed_url(- Link("http://example.com/foo "), "http://example.com/foo%20"- )+ self._assert_followed_url(Link('http://example.com/foo '),+ 'http://example.com/foo')def test_follow_flags(self):- res = self.response_class('http://example.com/')- fol = res.follow('http://example.com/', flags=['cached', 'allowed'])- self.assertEqual(fol.flags, ['cached', 'allowed'])+ res = self.response_class("http://example.com/")+ fol = res.follow("http://example.com/", flags=["cached", "allowed"])+ self.assertEqual(fol.flags, ["cached", "allowed"])# Response.follow_all