code: def fetch_url(
      url,
      unpack,
      resource_file_name,
      expected_md5=None,
      expected_sha1=None,
      tries=10,
      writers=None,
  ):
      logging.info(
          "Downloading from url %s name %s and expected md5 %s",
          url,
          resource_file_name,
          expected_md5,
      )
      tmp_file_name = uniq_string_generator()
  
      request = urllib2.Request(
          url, headers={"User-Agent": make_user_agent()}
      )
      req = retry.retry_func(
          lambda: urllib2.urlopen(request, timeout=30),
          tries=tries,
          delay=5,
          backoff=1.57079,
      )
      logging.debug("Headers: %s", req.headers.headers)
      expected_file_size = int(req.headers.get("Content-Length", 0))
      real_md5 = hashlib.md5()
      real_sha1 = hashlib.sha1()
  
      with open(tmp_file_name, "wb") as fp:
          copy_stream(
              req.read,
              fp.write,
              real_md5.update,
              real_sha1.update,
              size_printer(resource_file_name, expected_file_size),
              *([] if writers is None else writers),
          )
  
      real_md5 = real_md5.hexdigest()
      real_file_size = os.path.getsize(tmp_file_name)
      real_sha1.update("\0")
      real_sha1.update(str(real_file_size))
      real_sha1 = real_sha1.hexdigest()
  
      if unpack:
          tmp_dir = tmp_file_name + ".dir"
          os.makedirs(tmp_dir)
          with tarfile.open(tmp_file_name, mode="r|gz") as tar:
              tar.extractall(tmp_dir)
          tmp_file_name = os.path.join(tmp_dir, resource_file_name)
          if expected_md5:
              real_md5 = md5file(tmp_file_name)
  
      logging.info(
          "File size %s (expected %s)",
          real_file_size,
          expected_file_size or "UNKNOWN",
      )
      logging.info("File md5 %s (expected %s)", real_md5, expected_md5)
      logging.info(
          "File sha1 %s (expected %s)", real_sha1, expected_sha1
      )
  
      if expected_md5 and real_md5 != expected_md5:
          report_to_snowden(
              {
                  "headers": req.headers.headers,
                  "expected_md5": expected_md5,
                  "real_md5": real_md5,
              }
          )
  
          raise BadChecksumFetchError(
              "Downloaded {}, but expected {} for {}".format(
                  real_md5,
                  expected_md5,
                  url,
              )
          )
  
      if expected_sha1 and real_sha1 != expected_sha1:
          report_to_snowden(
              {
                  "headers": req.headers.headers,
                  "expected_sha1": expected_sha1,
                  "real_sha1": real_sha1,
              }
          )
  
          raise BadChecksumFetchError(
              "Downloaded {}, but expected {} for {}".format(
                  real_sha1,
                  expected_sha1,
                  url,
              )
          )
  
      if expected_file_size and expected_file_size != real_file_size:
          report_to_snowden(
              {
                  "headers": req.headers.headers,
                  "file_size": real_file_size,
              }
          )
  
          raise IncompleteFetchError(
              "Downloaded {}, but expected {} for {}".format(
                  real_file_size,
                  expected_file_size,
                  url,
              )
          )
  
      return tmp_file_name
  
imports: import datetime
  import errno
  import hashlib
  import json
  import logging
  import os
  import platform
  import random
  import shutil
  import socket
  import string
  import sys
  import tarfile
  import urllib2
  import retry
label_desc: Use image node_id 14 for calling a global function with example usage: fetch_url(url, unpack, resource_file_name, expected_md5, expected_sha1, tries, writers) and returns: tmp_file_name