Пример #1
0
 def download(handle, tmp_dir):
     """Fetch a module via HTTP(S), handling redirect and download headers."""
     request = urllib.request.Request(
         _append_compressed_format_query(handle))
     response = self._call_urlopen(request)
     return resolver.DownloadManager(handle).download_and_uncompress(
         response, tmp_dir)
Пример #2
0
        def download(handle, tmp_dir):
            """Fetch a module via HTTP(S), handling redirect and download headers."""
            cur_url = handle
            request = url.Request(_append_compressed_format_query(handle))

            # Look for and handle a special response header. If present, interpret it
            # as a redirect to the module download location. This allows publishers
            # (if they choose) to provide the same URL for both a module download and
            # its documentation.

            class LoggingHTTPRedirectHandler(url.HTTPRedirectHandler):
                def redirect_request(self, req, fp, code, msg, headers,
                                     newurl):
                    cur_url = newurl  # pylint:disable=unused-variable
                    return url.HTTPRedirectHandler.redirect_request(
                        self, req, fp, code, msg, headers, newurl)

            url_opener = url.build_opener(LoggingHTTPRedirectHandler)
            response = url_opener.open(request)
            return resolver.DownloadManager(cur_url).download_and_uncompress(
                response, tmp_dir)
        def download(handle, tmp_dir):
            """Fetch a module via HTTP(S), handling redirect and download headers."""
            cur_url = handle
            request = url.Request(_append_compressed_format_query(handle))

            # Look for and handle a special response header. If present, interpret it
            # as a redirect to the module download location. This allows publishers
            # (if they choose) to provide the same URL for both a module download and
            # its documentation.

            class LoggingHTTPRedirectHandler(url.HTTPRedirectHandler):
                def redirect_request(self, req, fp, code, msg, headers,
                                     newurl):
                    cur_url = newurl  # pylint:disable=unused-variable
                    return url.HTTPRedirectHandler.redirect_request(
                        self, req, fp, code, msg, headers, newurl)

            # proxy should be able to read http settings without
            # ProxyHandler({'https': 'http://localhost:3128'})
            proxy_handler = url.ProxyHandler()

            # proxy_auth_handler = url.HTTPBasicAuthHandler()
            # proxy_auth_handler.add_password('realm', 'host', '', '')

            http_handler = url.HTTPHandler()
            # Enable more logging. If you don't see any logging,
            # which means the traffic doesn't hit http yet.
            http_handler.set_http_debuglevel(1)

            # Disable SSL as a hack
            ctx = ssl.create_default_context()
            ctx.check_hostname = False
            ctx.verify_mode = ssl.CERT_NONE
            https_handler = url.HTTPSHandler(context=ctx)
            https_handler.set_http_debuglevel(1)

            url_opener = url.build_opener(proxy_handler, https_handler)
            response = url_opener.open(request)
            return resolver.DownloadManager(cur_url).download_and_uncompress(
                response, tmp_dir)
Пример #4
0
 def download(handle, tmp_dir):
     return resolver.DownloadManager(handle).download_and_uncompress(
         tf.gfile.GFile(handle, "r"), tmp_dir)