コード例 #1
0
 def test_custom_headers(self):
     remote = Remote.objects.create(
         url="http://example.org/", headers=[{"Connection": "keep-alive"}], name="foo"
     )
     factory = DownloaderFactory(remote)
     downloader = factory.build(remote.url)
     self.assertEqual(downloader.session.headers["Connection"], "keep-alive")
コード例 #2
0
 def test_user_agent_header(self):
     remote = Remote.objects.create(url="http://example.org/", name="foo")
     factory = DownloaderFactory(remote)
     downloader = factory.build(remote.url)
     default_user_agent = DownloaderFactory.user_agent()
     self.assertEqual(downloader.session.headers["User-Agent"], default_user_agent)
     remote.delete()
コード例 #3
0
 def test_custom_user_agent_header(self):
     remote = Remote.objects.create(
         url="http://example.org/", headers=[{"User-Agent": "foo"}], name="foo"
     )
     factory = DownloaderFactory(remote)
     downloader = factory.build(remote.url)
     default_user_agent = DownloaderFactory.user_agent()
     expected_user_agent = f"{default_user_agent}, foo"
     self.assertEqual(downloader.session.headers["User-Agent"], expected_user_agent)
     remote.delete()
コード例 #4
0
    def download_factory(self):
        """
        Return the DownloaderFactory which can be used to generate asyncio capable downloaders.

        Upon first access, the DownloaderFactory is instantiated and saved internally.

        Plugin writers are expected to override when additional configuration of the
        DownloaderFactory is needed.

        Returns:
            DownloadFactory: The instantiated DownloaderFactory to be used by
                get_downloader().
        """
        try:
            return self._download_factory
        except AttributeError:
            self._download_factory = DownloaderFactory(self)
            return self._download_factory