Exemplo n.º 1
0
def download_url(url, host_header, filename):
    """
    Downloads a specified URL over HTTP.
    @param url: the URL of the file to download.
    @param host_header: the value for the host header.
    @param filename: location of the file to save.b
    """
    u, headers = target_get(url, host_header)
    kwargs = dict(REQUEST_DEFAULTS)
    kwargs['headers'] = headers

    factory = client.HTTPDownloader(url, filename, **kwargs)
    make_request(u, factory)

    return factory.deferred
Exemplo n.º 2
0
    def _download_cover(self):
        self.active_cover_downloads += 1
        cover_image = self._cover_queue.pop()

        def complete(result):
            self._cover_done()

        def error(failure):
            cover_image.error_loading(failure)
            self._cover_done()

        url = cover_image.url
        scheme, host, path, _, _, _ = urlparse(url)
        factory = client.HTTPDownloader(url, cover_image.get_dest_file())
        reactor.connectTCP(host, 80, factory)
        factory.deferred.addCallback(complete).addErrback(error)
Exemplo n.º 3
0
    def __call__(self):
        # Stolen cookie code since the web API is inconsistent...
        headers = {}
        l = []
        for cookie, cookval in self.cookies.items():
            l.append('%s=%s' % (cookie, cookval))
        headers['Cookie'] = '; '.join(l)

        factory = client.HTTPDownloader(self.urlin,
                                        Emitter(self.urlsout,
                                                self.transformer),
                                        headers=headers)
        reactor.connectTCP(self.host, self.port, factory)
        factory.deferred.addCallback(self.cb(factory))
        factory.deferred.addErrback(self.logError)
        return factory.deferred
Exemplo n.º 4
0
def buggy_twisted():
    o = client.HTTPDownloader('http://dummy-url/foo', None)
    client.HTTPDownloader.gotHeaders(o, {})
    if o.response_headers is None:
        return True
    return False
Exemplo n.º 5
0
 def downloadPage(self, url, file, contextFactory=None, *args, **kwargs):
     factory = client.HTTPDownloader(url, file, *args, **kwargs)
     d = self._urlget(factory, url, contextFactory)
     return d